コード例 #1
0
        public bool TryDecode()
        {
            int skip = 4;

            switch (adaptation_field_control)
            {
            case 0x0:                                        // reserved for future use by ISO/IEC
                return(false);

            case 0x1:                                        // 无调整字段,仅含有效负载
                skip = 4 + payload_unit_start_indicator;
                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;
            }
            return(true);
        }
コード例 #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;
                }
            }
        }