Exemplo n.º 1
0
        public static byte[] GetPMTPATData(bool isOnlyVideo = false)
        {
            if (_pmt_pat_tsdata == null)
            {
                var             msOutput = new MemoryStream();
                TSProgramManage ts_pm    = new TSProgramManage();

                TS_PAT pat      = new TS_PAT();
                var    pat_data = pat.GetBytes();

                TSPacket pack_pat = new TSPacket()
                {
                    sync_byte = 0x47,
                    transport_error_indicator    = 0,
                    payload_unit_start_indicator = 1,
                    transport_priority           = 0,
                    PID = 0,
                    transport_scrambling_control = 0,
                    adaptation_field_control     = 1,
                    continuity_counter           = ts_pm.GetCounter(0),
                    data = pat_data,
                };
                var pack_pat_data = pack_pat.GetBytes();
                var pack_pat_tmp  = new TSPacket()
                {
                    ProgramManage = ts_pm,
                };
                msOutput.Write(pack_pat_data, 0, pack_pat_data.Length);

                //pack_pat_tmp.SetBytes(pack_pat_data);
                //pack_pat_tmp.Decode();


                TS_PMT   pmt      = new TS_PMT();
                var      pmt_data = isOnlyVideo ? pmt.GetVideoBytes() : pmt.GetBytes();
                TSPacket pack_pmt = new TSPacket()
                {
                    sync_byte = 0x47,
                    transport_error_indicator    = 0,
                    payload_unit_start_indicator = 1,
                    transport_priority           = 0,
                    PID = 256,//PMT_PID
                    transport_scrambling_control = 0,
                    adaptation_field_control     = 1,
                    continuity_counter           = ts_pm.GetCounter(256),
                    data = pmt_data,
                };
                var pack_pmt_data = pack_pmt.GetBytes();
                var pack_pmt_tmp  = new TSPacket()
                {
                    ProgramManage = ts_pm,
                };
                msOutput.Write(pack_pmt_data, 0, pack_pmt_data.Length);

                //pack_pmt_tmp.SetBytes(pack_pmt_data);
                //pack_pmt_tmp.Decode();

                var _out = msOutput.ToArray();
                _pmt_pat_tsdata = _out;
            }
            return(_pmt_pat_tsdata);
        }
Exemplo n.º 2
0
        public void Decode()
        {
            //以下是整个程序的逻辑主要是以解析为主,实际应用可能要优化下方式以提高性能
            var buffer = SrcBuffer;
            int skip   = 4;

            switch (adaptation_field_control)
            {
            case 0x0:                                        // reserved for future use by ISO/IEC
                throw new Exception();

            case 0x1:        // 无调整字段,仅含有效负载
                skip = 4 + payload_unit_start_indicator;
                skip = 4;    //
                break;

            case 0x2:                                         // 仅含调整字段,无有效负载
                skip = SrcBuffer.Length;
                break;

            case 0x3:     // 调整字段后含有效负载
                AdaptationField = new AdaptationInfo();
                AdaptationField.SetBytes(SrcBuffer);
                skip = 4 + AdaptationField.adaptation_field_length + 1;
                break;

            default:
                break;
            }

            data = new byte[SrcBuffer.Length - skip];
            if (data.Length > 0)
            {
                Array.Copy(SrcBuffer, skip, data, 0, data.Length);
            }
            if (PID == 0x00)
            {
                PacketType = TSPacketType.PAT;
                var pat = new TS_PAT();
                pat.SetBytes(data);
                foreach (var p in pat.PATProgramList)
                {
                    ProgramManage.AddProgram(p);
                }
                _pat = pat;
            }
            else
            {
                if (ProgramManage.IsPMT_PID(PID))
                {
                    //PMT
                    PacketType = TSPacketType.PMT;
                    var pmt = new TS_PMT();
                    pmt.SetBytes(data);
                    foreach (var p in pmt.PMTStreamList)
                    {
                        ProgramManage.AddStream(p);
                    }
                    _pmt = pmt;
                }
                else if (ProgramManage.IsTSTable(PID))
                {
                    PacketType = TSPacketType.OTHER;
                    //其他表示,这里先不作处理
                }
                else if (ProgramManage.IsData(PID))
                {
                    //这里一般为 媒体数据
                    PacketType = TSPacketType.DATA;
                }
            }
        }