Click here to Skip to main content
12,253,679 members (54,339 online)
Click here to Skip to main content

Stats

105.3K views
1.6K downloads
48 bookmarked
Posted

Sample speed test for Transport Stream construction

, 13 Apr 2004
A program that emulates the TS construction from ES files for the HDTV standard.
using System;

namespace mpeg_tst
{
	public class PES
	{
		private byte[]	Packet_Start_Code_Prefix;	// 3 bytes
		private byte	Stream_ID;					// 1 byte
		private	byte[]	PES_Packet_Length;			// 2 bytes
		private byte[]	PES_Header_Flags;			// 2 bytes = "10"(2 biti) + PES_H_F(14 biti)
		private	byte	PES_Header_Length;			// 1 byte
		private	byte[]	PES_Header_Fields;			// Variable length
		private	byte[]	PES_Packet_Data;			// Variable length

		public byte[]	PES_output;		// Pachetul final asamblat
		public int data_len;				// Lungimea segmentului de date

		public PES() // Constructorul implicit
		{	
			Packet_Start_Code_Prefix=new byte[3];
			PES_Packet_Length=new byte[2];
			PES_Header_Flags=new byte[2];
		}

		public PES(int h_length) // Constructor cu marimea headerului
		{
			Packet_Start_Code_Prefix=new byte[3];
			PES_Packet_Length=new byte[2];
			PES_Header_Flags=new byte[2];			
			PES_Header_Fields=new byte[h_length];
			PES_Header_Length=Convert.ToByte(h_length);
		}

		public PES(int h_length,int p_length) // Constructor cu marimea headerului si a pachetului
		{
			Packet_Start_Code_Prefix=new byte[3];
			PES_Packet_Length=new byte[2];
			PES_Header_Flags=new byte[2];			
			PES_Header_Fields=new byte[h_length];
			data_len=p_length-3-h_length;
			PES_Packet_Data=new byte[data_len];
			PES_output=new byte[6+p_length];
			PES_Header_Length=Convert.ToByte(h_length);
			set_Packet_Length(p_length);
		}


		public void set_Packet_Length(int len) // Seteaza lungimea PES_Packet_Length
		{
			PES_Packet_Length[0]=Convert.ToByte(len%256);
			PES_Packet_Length[1]=Convert.ToByte(Convert.ToInt16(len/256));
		}

		public int get_Packet_Length() // Afla lungimea PES_Packet_Length
		{	return PES_Packet_Length[1]*256+PES_Packet_Length[0];}


		public void set_antet() // Setare a antetului cu valori de "marcare"
		{
			Packet_Start_Code_Prefix[0]=35;// "#"
			Packet_Start_Code_Prefix[1]=35;
			Packet_Start_Code_Prefix[2]=35;
			Stream_ID=36; // "$"
			PES_Header_Flags[0]=36;
			PES_Header_Flags[1]=36;
			for(int i=0;i<PES_Header_Length;i++) PES_Header_Fields[i]=36;
		}

		public void set_Packet_Data(byte[] raw_data)
		{
				int i,len;
			len=raw_data.GetLength(0);
			for(i=0;i<len;i++) PES_Packet_Data[i]=raw_data[i];
			if(len<data_len) for(i=len;i<data_len;i++) PES_Packet_Data[i]=38; // '&' stuffing
		}


		public void asemby_output()
		{int i;
			set_antet();
			PES_output[0]=Packet_Start_Code_Prefix[0];
			PES_output[1]=Packet_Start_Code_Prefix[1];
			PES_output[2]=Packet_Start_Code_Prefix[2];
			PES_output[3]=Stream_ID;
			PES_output[4]=PES_Packet_Length[0];
			PES_output[5]=PES_Packet_Length[1];
			PES_output[6]=PES_Header_Flags[0];
			PES_output[7]=PES_Header_Flags[1];
			PES_output[8]=PES_Header_Length;
			for(i=0;i<PES_Header_Length;i++) PES_output[9+i]=PES_Header_Fields[i];
			for(i=0;i<get_Packet_Length()-3-PES_Header_Length;i++)
					PES_output[9+PES_Header_Length+i]=PES_Packet_Data[i];
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

ro_angel_bv
Web Developer
Malaysia Malaysia
Dumitru Bogdan - alias Angel

Born 1980 , Brasov , Romania

Final year student at Transilvania University of Brasov , Faculty of Electrical Engineering & Computer Science , Department of Electronics & Computers

Programming : Visual C++ , Visual Fox Pro , Assembler & later , C#

Motto : "Nothing Last Forever" , and software is no exception

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160426.1 | Last Updated 14 Apr 2004
Article Copyright 2004 by ro_angel_bv
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid