Exemple #1
0
        public Result ProcessPmtSection(DataStore section, out Service service)
        {
            Result result = new Result();

            byte[] data = section.GetData();

            //PMT must at least have 8 bytes header and 4 bytes crc32.
            if (section.GetLeftBitLength() <= (12 * 8))
            {
                result.SetResult(ResultCode.INSUFFICIENT_DATA);
            }

            if (result.Fine)
            {
                //Check CRC32.
                if (0 != Utility.GetCrc32(data, 0, data.Length))
                {
                    result.SetResult(ResultCode.INVALID_DATA);//CRC error.
                }
            }

            Int64 bitoffset = 0;

            if (result.Fine)
            {
                //Skip 3 bytes header.
                result = section.SkipBits(ref bitoffset, 3 * 8);
            }

            Int64 programNumber = 0;

            if (result.Fine)
            {
                //Read program number.
                result = section.ReadBits(ref bitoffset, 16, ref programNumber);
            }

            if (result.Fine)
            {
                //Skip version_number, section_number and last_section_number and 3 bits reserved.
                result = section.SkipBits(ref bitoffset, 3 * 8 + 3);
            }

            Int64 pcrPID = 0;

            if (result.Fine)
            {
                result = section.ReadBits(ref bitoffset, 13, ref pcrPID);
            }


            if (result.Fine)
            {
                //To remove crc32.
                result = section.CutOff(32);
            }

            service = null;
            if (result.Fine)
            {
                service           = new Service();
                service.PcrPid    = (UInt16)pcrPID;
                service.ServiceId = (UInt16)programNumber;

                //Skip 4 bits reserved.
                result = section.SkipBits(ref bitoffset, 4);
            }

            Int64 programInfoLength = 0;

            if (result.Fine)
            {
                result = section.ReadBits(ref bitoffset, 12, ref programInfoLength);
            }

            if (result.Fine)
            {
                //Get all program level CA descriptors.
                result = FindAllCaDescriptor(section, ref bitoffset, service.GetCaDescriptorList(), ref programInfoLength);
            }

            if (result.Fine)
            {
                Int64 streamType    = 0;
                Int64 elementaryPid = 0;
                Int64 esInfoLength  = 0;
                while (section.GetLeftBitLength() > 0)
                {
                    result = section.ReadBits(ref bitoffset, 8, ref streamType);

                    if (result.Fine)
                    {
                        result = section.SkipBits(ref bitoffset, 3);//Skip 3 bits reserved.
                    }

                    if (result.Fine)
                    {
                        result = section.ReadBits(ref bitoffset, 13, ref elementaryPid);
                    }

                    if (result.Fine)
                    {
                        result = section.SkipBits(ref bitoffset, 4);//Skip 4 bits reserved.
                    }

                    if (result.Fine)
                    {
                        result = section.ReadBits(ref bitoffset, 12, ref esInfoLength);
                    }

                    if (result.Fine)
                    {
                        ComponentStream componentStream = new ComponentStream();

                        componentStream.StreamType    = (byte)streamType;
                        componentStream.ElementaryPid = (UInt16)elementaryPid;

                        //Get all stream level CA descriptors.
                        result = FindAllCaDescriptor(section, ref bitoffset, componentStream.GetCaDescriptorList(), ref esInfoLength);

                        if (result.Fine)
                        {
                            service.AddComponentStream(componentStream);
                        }
                    }

                    if (!result.Fine)
                    {
                        break;
                    }
                }
            }

            return(result);
        }
Exemple #2
0
 public void AddComponentStream(ComponentStream componentStream)
 {
     componentStreamList.Add(componentStream);
 }