zoukankan      html  css  js  c++  java
  • Packet.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Runtime.InteropServices;
    using System.Net;
    using Bit;
    
    namespace Packet
    {
        
    
        public class TSPacket
        {
            BitOperation bitOperarion = new BitOperation();
    
            public TSPacket(Byte[] bytes)
            {
                TSBytes = bytes;
                _data = new Byte[183];
                for (int i = 0; i < _data.Length; i++)  //把data字节数组填充为0
                {
                    _data[i] = 0; 
                }
            }
    
            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 Byte[] _data;
    
            ///////////////////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 Byte[] DATA
            {
                get
                {
                    return this._data;
                }
                set
                {
                    this._data = value;
                }
            }
    
            ///////////////////字节中的比特位操作///////////////////
            
        }
    
       
       
        public class PMT
        {
            //public static string table_id = "00000010";
            //public static string section_syntax_indicator = "1";
            //public static string zero = "0";
            //public static string reserved = "00";
            //public static string section_length = "111111111111";
            //public static string program_number = "0000000000000001";
            //public static string reserved2 = "00";
            //public static string version_number = "00001";
            //public static string current_next_indicator = "0";
            //public static string section_number = "00000001";
            //public static string last_section_number = "00000000";
            //public static string reserved3 = "000";
            //public static string PCR_PID = "0000000000001";
            //public static string reserved4 = "0000";
            //public static string program_info_length = "111111111111";
        }
    
        public class SDT
        { }
    
        public struct CDT
        {
            //public static string table_id = "11001000";
            //public static string section_syntax_indicator = "1";
            //public static string reserved_future_use = "0";
            //public static string reserved = "00";
            //public static string section_length = "111111111111";
            //public static string download_data_id = "0000000000000001";
            //public static string reserved2 = "00";
            //public static string vesion_number = "00001";
            //public static string current_next_indicator = "1";
            //public static string section_number = "00000001";
            //public static string last_section_number = "00000000";
            //public static string original_netword_id = "0000000000000000";
            //public static string data_type = "00000000";
            //public static string reserved_future_use2 = "0000";
            //public static string descriptors_loop_length = "000000000000";
    
            //public static string CDTTableStr = table_id + section_syntax_indicator
            //   + reserved_future_use + reserved + section_length
            //   + download_data_id + reserved2 + vesion_number + current_next_indicator
            //   + section_number + last_section_number + original_netword_id
            //   + data_type + reserved_future_use2 + descriptors_loop_length;  
        }
    
        public class SDTT
        { }
    }
    
  • 相关阅读:
    oracle 查询 当前最大时间的value的值
    Visual Studio《加载此属性页时出错》的解决办法
    (转) 关于在IE6下 无法跳转问题
    LINQ TO XML 个人的一些心得1
    CSS实现单行、多行文本溢出显示省略号(…)
    html 图像映射(一个图像多个连接)
    JS页面跳转大全
    首行负缩进达到内容对齐的目的
    HTML图片死活不显示
    JS高级. 06 缓存、分析解决递归斐波那契数列、jQuery缓存、沙箱、函数的四种调用方式、call和apply修改函数调用方法
  • 原文地址:https://www.cnblogs.com/jingmoxukong/p/2120874.html
Copyright © 2011-2022 走看看