Packet.cs

简介: using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.
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
    { }
}
目录
相关文章
|
9月前
|
存储 机器学习/深度学习 人工智能
AllData数据中台核心菜单十二:数据同步平台
杭州奥零数据科技有限公司成立于2023年,专注于数据中台业务,维护开源项目AllData并提供商业版解决方案。AllData提供数据集成、存储、开发、治理及BI展示等一站式服务,支持AI大模型应用,助力企业高效利用数据价值。
AllData数据中台核心菜单十二:数据同步平台
|
安全 程序员 C语言
探索C语言库函数:字符串拷贝函数strcpy
探索C语言库函数:字符串拷贝函数strcpy
157 0
|
11月前
|
前端开发 中间件 程序员
如何尽可能快地上手一个业务or项目
本文简单讲述作者对于“怎么尽可能快地上手一个新业务/项目?”这个问题的个人理解。
177 16
|
缓存 算法 C语言
【C++ 标准查找算法 】C++标准库查找算法深入解析(In-depth Analysis of C++ Standard Library Search Algorithms)
【C++ 标准查找算法 】C++标准库查找算法深入解析(In-depth Analysis of C++ Standard Library Search Algorithms)
289 0
|
芯片
stm32f407探索者开发板(十二)——Systick滴答定时器-延时函数讲解
stm32f407探索者开发板(十二)——Systick滴答定时器-延时函数讲解
1309 0
|
C++
SDL基础使用02(加载bmp图片、纹理和渲染)
这篇文章介绍了如何使用SDL库在C++中加载和显示BMP图片,以及如何使用纹理和渲染器进行更高级的图形处理。
201 2
|
搜索推荐 算法
数据结构与算法学习十四:常用排序算法总结和对比
关于常用排序算法的总结和对比,包括稳定性、内排序、外排序、时间复杂度和空间复杂度等术语的解释。
159 0
数据结构与算法学习十四:常用排序算法总结和对比
|
算法 数据可视化 调度
基于PSO粒子群优化的车间调度问题求解matlab仿真,输出甘特图
基于PSO粒子群优化的MATLAB仿真解决车间调度问题,输入机器与工作完成时间,输出甘特图与收敛图,实现多机器多任务最优并行调度。使用MATLAB 2022a版本运行,通过模拟鸟群觅食行为,不断更新粒子速度与位置寻找最优解,采用工序编码,总加工时间为适应度函数,实现快速收敛并可视化调度结果。
473 16
|
存储 缓存 关系型数据库
深度解密 MySQL 的 Buffer Pool
深度解密 MySQL 的 Buffer Pool
254 0
|
存储 Docker 容器
Docker工作目录迁移
Docker工作目录迁移