代码语言:javascript复制
using System;
using System.Collections.Generic;
using System.Text;
using Bit;
namespace Packet
{
class Packet_TS
{
BitOperation bitOperarion = new BitOperation();
public Packet_TS(Byte[] bytes)
{
_TSBytes = bytes;
_list_data_bytes = new List<byte>();
for (int i = 5; i < bytes.Length ; i ) //把data字节数组填充为0
{
_list_data_bytes.Add(bytes[i]);
}
}
private Byte[] _TSBytes;
///////////////////TS Header/////////////////////
private Byte _sync_byte;
private Byte _transport_error_indicator;
private Byte _payload_unit_start_indicator;
private Byte _transport_priority;
private UInt16 _PID;
private Byte _transport_scrambling_control;
private Byte _adaption_field_control;
private Byte _continuity_counter;
///////////////////Data//////////////////////////
private Byte _position_indicator;
private List<Byte> _list_data_bytes;
///////////////////get set方法///////////////////
public Byte[] TSBytes
{
get
{
return this._TSBytes;
}
set
{
this._TSBytes = value;
}
}
public Byte Sync_Byte
{
get
{
this._sync_byte = Convert.ToByte(_TSBytes[0]);
return this._sync_byte;
}
set
{
this._sync_byte = value;
this._TSBytes[0] = value;
}
}
public Byte Transport_Error_Indicator
{
get
{
this._transport_error_indicator = Convert.ToByte(_TSBytes[1] >> 7);
return this._transport_error_indicator;
}
set
{
this._transport_error_indicator = value;
this._TSBytes[1] = bitOperarion.setBit(_TSBytes[1], 0, value);
}
}
public Byte Payload_Unit_Start_Indicator
{
get
{
this._payload_unit_start_indicator = Convert.ToByte((_TSBytes[1] >> 6) & 0x01);
return this._payload_unit_start_indicator;
}
set
{
this._payload_unit_start_indicator = value;
this._TSBytes[1] = bitOperarion.setBit(_TSBytes[1], 1, value);
}
}
public Byte Transport_Priority
{
get
{
this._transport_priority = Convert.ToByte((_TSBytes[1] >> 5) & 0x01);
return this._transport_priority;
}
set
{
this._transport_priority = value;
this._TSBytes[1] = bitOperarion.setBit(_TSBytes[1], 2, value);
}
}
public UInt16 Pid
{
get
{
UInt16 high = Convert.ToUInt16((_TSBytes[1] & 0x1F) << 8);
UInt16 low = Convert.ToUInt16(_TSBytes[2]);
this._PID = Convert.ToUInt16(high | low);
return this._PID;
}
set
{
this._PID = value;
Byte high = Convert.ToByte(value >> 8);
Byte low = Convert.ToByte(value & 0x00ff);
for (int i = 3; i < 8; i )
{
int temp = bitOperarion.getBit(high, i);
this._TSBytes[1] = bitOperarion.setBit(this._TSBytes[1], i, temp);
}
this._TSBytes[2] = low;
}
}
public Byte Transport_Scrambling_Control
{
get
{
this._transport_scrambling_control = Convert.ToByte((_TSBytes[3] >> 6) & 0x03);
return this._transport_scrambling_control;
}
set
{
this._transport_scrambling_control = value;
this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 0, (value >> 1) & 0x01 );
this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 1, (value & 0x01) );
}
}
public Byte Adaption_Field_Control
{
get
{
this._continuity_counter = Convert.ToByte((_TSBytes[3] >> 4) & 0x03);
return this._continuity_counter;
}
set
{
this._continuity_counter = value;
this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 2, (value >> 1) & 0x01 );
this._TSBytes[3] = bitOperarion.setBit( _TSBytes[3], 3, (value & 0x01) );
}
}
public Byte Continuity_Counter
{
get
{
this._adaption_field_control = Convert.ToByte(_TSBytes[3] & 0x0f);
return this._adaption_field_control;
}
set
{
this._adaption_field_control = value;
for (int i = 4; i < 8; i )
{
int temp = bitOperarion.getBit(value, i);
this._TSBytes[3] = bitOperarion.setBit(this._TSBytes[3], i, temp);
}
}
}
public Byte Position_Indicator
{
get
{
this._position_indicator = Convert.ToByte(_TSBytes[4]);
return this._position_indicator;
}
set
{
this._position_indicator = value;
this._TSBytes[4] = value;
}
}
public List<Byte> List_Data_Bytes
{
get
{
return this._list_data_bytes;
}
set
{
this._list_data_bytes = value;
}
}
///////////////////字节中的比特位操作///////////////////
}
}