Inheritance: ElementaryParse
Beispiel #1
0
        protected override void GetInitialValues()
        {
            GetTimestamps();
            Seek(-1);
            PatPacket pp = null;
            PmtPacket pm = null;
            bool bluray = false;
            bool validPmt = false;
            ushort pmtPid = 0;
            int i = 0;
            Dictionary<ushort, StreamInfo> streams = new Dictionary<ushort, StreamInfo>();
            while (true)
            {
                for (i = tsior.Read(tsPack, 0, 1 + stride); (i > 0) && (tsPack[stride] != Constants.SYNC_BYTE); i = tsior.Read(tsPack, stride, 1))
                    ; // ensure a good sync byte
                if (i == 0)
                    break; // end of stream
                i = tsior.Read(tsPack, stride + 1, tsPack.Length - (stride + 1));
                if (i < tsPack.Length - (stride + 1))
                    break; // end of stream
                ts.SetData(tsPack, stride);
                if (ts.PID == Constants.PAT_PID)
                {
                    pp = new PatPacket(ts.GetData());
                    ProgramInfo[] pi = pp.Programs;
                    if (null != pi && pi.Length == 2)
                    {
                        if ((pi[0].ProgramNumber == 0 && pi[0].ProgramPID == 0x001f && pi[1].ProgramNumber == 1 && pi[1].ProgramPID == 0x0100)
                            || (pi[1].ProgramNumber == 0 && pi[1].ProgramPID == 0x001f && pi[0].ProgramNumber == 1 && pi[0].ProgramPID == 0x0100))
                        {
                            bluray = true;
                        }
                    }
                    else if (null != pi && pi[0] != null && pi[0].ProgramNumber == 1)
                        pmtPid = pi[0].ProgramPID;
                }
                else if (bluray && ts.PID == 0x0100)
                {
                    if (pm == null)
                        pm = new PmtPacket(ts.GetData());
                    else if (pm.Complete == false)
                        pm.AddData(ts.Payload, 0, ts.Payload.Length);
                    if (pm.Complete)
                    {
                        sis = pm.ElementaryStreams;
                        dt = pm.DtcpInfo;
                        return;
                    }
                }
                else if (ts.PID == pmtPid)
                {
                    pm = new PmtPacket(ts.GetData());
                    sis = pm.ElementaryStreams;
                    dt = pm.DtcpInfo;
                }
                else if (streams.ContainsKey(ts.PID) == false && ts.HasPesHeader)
                {
                    byte[] payload = ts.Payload;
                    PesHeader ph = new PesHeader(ts.Payload);
                    PesPacket pes = new PesPacket(payload, 0, payload.Length, ts.PID);
                    if (ph.StreamId == Constants.PES_PRIVATE1)
                    {
                        byte[] audio = pes.GetPayload();
                        AC3Info ac3 = new AC3Info(audio, 0);
                        DtsInfo dts = new DtsInfo(audio, 0);
                        MlpInfo mlp = new MlpInfo(audio, 0);
                        if (ac3.Valid)
                        {
                            if (ac3.SyntaxType == Ac3SyntaxType.Standard || ac3.SyntaxType == Ac3SyntaxType.Alternative)
                            {
                                StreamInfo si = new StreamInfo(ElementaryStreamTypes.AUDIO_STREAM_AC3, ts.PID);
                                streams.Add(ts.PID, si);
                            }
                            else if (ac3.SyntaxType == Ac3SyntaxType.Enhanced)
                            {
                                StreamInfo si = new StreamInfo(ElementaryStreamTypes.AUDIO_STREAM_AC3_PLUS, ts.PID);
                                streams.Add(ts.PID, si);
                            }
                        }
                        else if (dts.Valid)
                        {
                            StreamInfo si = new StreamInfo(ElementaryStreamTypes.AUDIO_STREAM_DTS_HD, ts.PID);
                            streams.Add(ts.PID, si);
                        }
                        else if (mlp.Valid)
                        {
                            StreamInfo si = new StreamInfo(ElementaryStreamTypes.AUDIO_STREAM_AC3_TRUE_HD, ts.PID);
                            streams.Add(ts.PID, si);
                        }
                        else if ((pes.ExtendedId & 0xf8) == Constants.PES_PRIVATE_LPCM)
                        {
                            StreamInfo si = new StreamInfo(ElementaryStreamTypes.AUDIO_STREAM_LPCM, ts.PID);
                            streams.Add(ts.PID, si);
                        }
                    }
                    else if ((ph.StreamId & 0xe0) == Constants.PES_AUDIO_MPEG)
                    {
                        StreamInfo si = new StreamInfo(ElementaryStreamTypes.AUDIO_STREAM_MPEG2, ts.PID);
                        streams.Add(ts.PID, si);
                    }
                    else if ((ph.StreamId & 0xf0) == Constants.PES_VIDEO)
                    {
                        UInt32 format = pes.ExtendedType;
                        if ((format & 0xffff) == 0x1)
                        {
                        }
                        else if ((format & 0xffffff00) == 0x100)
                        {
                        }

                        H264Info h264 = new H264Info(payload, 0);
                        Mpeg2Info mpg2 = new Mpeg2Info(payload, 0);
                        if (h264.Valid)
                        {
                            StreamInfo si = new StreamInfo(ElementaryStreamTypes.VIDEO_STREAM_H264, ts.PID);
                            streams.Add(ts.PID, si);
                        }
                        else if (mpg2.Valid)
                        {
                            StreamInfo si = new StreamInfo(ElementaryStreamTypes.VIDEO_STREAM_MPEG2, ts.PID);
                            streams.Add(ts.PID, si);
                        }
                    }
                    else if (ph.StreamId == Constants.PES_VIDEO_VC1)
                    {
                        StreamInfo si = new StreamInfo(ElementaryStreamTypes.VIDEO_STREAM_VC1, ts.PID);
                        streams.Add(ts.PID, si);
                    }
                }
                if (sis != null)
                {
                    validPmt = true;
                    foreach (StreamInfo si in sis)
                    {
                        if (streams.ContainsKey(si.ElementaryPID) == false)
                        {
                            validPmt = false;
                            break;
                        }
                    }
                    if (validPmt)
                        return;
                }
                if (fs.Position > (Constants.DISK_BUFFER << 1))
                    break;
            }
            sis = new StreamInfo[streams.Values.Count];
            streams.Values.CopyTo(sis, 0);
        }
Beispiel #2
0
 private void ParseStream(StreamInfo si, byte[] payload)
 {
     switch (si.StreamType)
     {
         case ElementaryStreamTypes.VIDEO_STREAM_VC1:
             if ((si.ElementaryDescriptors == null) ||
                 si.FrameRate == FrameRate.Reserved ||
                 si.VideoFormat == VideoFormat.Reserved ||
                 si.AspectRatio == AspectRatio.Reserved)
             {
                 VC1SequenceInfo sq = new VC1SequenceInfo(payload, 0);
                 if (sq.Valid)
                 {
                     if (sq.AspectRatio != AspectRatio.Reserved)
                         si.AspectRatio = sq.AspectRatio;
                     if (sq.FrameRate != FrameRate.Reserved)
                         si.FrameRate = sq.FrameRate;
                     if (sq.VideoFormat != VideoFormat.Reserved)
                         si.VideoFormat = sq.VideoFormat;
                     if (si.ElementaryDescriptors == null)
                         si.ElementaryDescriptors = Constants.vc1_descriptor;
                 }
             }
             break;
         case ElementaryStreamTypes.AUDIO_STREAM_AC3:
             if ((si.ElementaryDescriptors == null) ||
                 si.AudioPresentationType == AudioPresentationType.Reserved ||
                 si.SamplingFrequency == SamplingFrequency.Reserved)
             {
                 AC3Info ac3 = new AC3Info(payload, 0);
                 if (ac3.Valid)
                 {
                     if (ac3.AudioPresentationType != AudioPresentationType.Reserved)
                         si.AudioPresentationType = ac3.AudioPresentationType;
                     if (ac3.SamplingFrequency != SamplingFrequency.Reserved)
                         si.SamplingFrequency = ac3.SamplingFrequency;
                     if (si.ElementaryDescriptors == null)
                         si.ElementaryDescriptors = ac3.ElementaryDescriptors;
                     if (ac3.SyntaxType == Ac3SyntaxType.Enhanced)
                         si.StreamType = ElementaryStreamTypes.AUDIO_STREAM_AC3_PLUS;
                 }
             }
             break;
         case ElementaryStreamTypes.AUDIO_STREAM_AC3_PLUS:
             if (si.AudioPresentationType == AudioPresentationType.Reserved ||
                 si.SamplingFrequency == SamplingFrequency.Reserved)
             {
                 AC3Info ac3 = new AC3Info(payload, 0);
                 if (ac3.Valid)
                 {
                     if (ac3.AudioPresentationType != AudioPresentationType.Reserved)
                         si.AudioPresentationType = ac3.AudioPresentationType;
                     if (ac3.SamplingFrequency != SamplingFrequency.Reserved)
                         si.SamplingFrequency = ac3.SamplingFrequency;
                     if (si.ElementaryDescriptors == null)
                         si.ElementaryDescriptors = ac3.ElementaryDescriptors;
                 }
             }
             break;
         case ElementaryStreamTypes.AUDIO_STREAM_AC3_TRUE_HD:
             if (si.AudioPresentationType == AudioPresentationType.Reserved ||
                 si.SamplingFrequency == SamplingFrequency.Reserved)
             {
                 MlpInfo ac3 = new MlpInfo(payload, 0);
                 if (ac3.Valid)
                 {
                     if (ac3.AudioPresentationType != AudioPresentationType.Reserved)
                         si.AudioPresentationType = ac3.AudioPresentationType;
                     if (ac3.SamplingFrequency != SamplingFrequency.Reserved)
                         si.SamplingFrequency = ac3.SamplingFrequency;
                     if (si.ElementaryDescriptors == null)
                         si.ElementaryDescriptors = ac3.ElementaryDescriptors;
                 }
             }
             break;
         case ElementaryStreamTypes.VIDEO_STREAM_H264:
             if ((si.ElementaryDescriptors == null) ||
                 si.FrameRate == FrameRate.Reserved ||
                 si.VideoFormat == VideoFormat.Reserved ||
                 si.AspectRatio == AspectRatio.Reserved)
             {
                 H264Info h264 = new H264Info(payload, 0);
                 if(h264.Valid)
                 {
                     if (h264.AspectRatio != AspectRatio.Reserved)
                         si.AspectRatio = h264.AspectRatio;
                     if (h264.FrameRate != FrameRate.Reserved)
                         si.FrameRate = h264.FrameRate;
                     if (h264.VideoFormat != VideoFormat.Reserved)
                         si.VideoFormat = h264.VideoFormat;
                     if (si.ElementaryDescriptors == null)
                         si.ElementaryDescriptors = h264.ElementaryDescriptors;
                 }
             }
             break;
         case ElementaryStreamTypes.AUDIO_STREAM_DTS:
         case ElementaryStreamTypes.AUDIO_STREAM_DTS_HD:
         case ElementaryStreamTypes.AUDIO_STREAM_DTS_HD_MASTER_AUDIO:
             if (si.AudioPresentationType == AudioPresentationType.Reserved ||
                 si.SamplingFrequency == SamplingFrequency.Reserved)
             {
                 DtsInfo dts = new DtsInfo(payload, 0);
                 if (dts.Valid)
                 {
                     if (dts.AudioPresentationType != AudioPresentationType.Reserved)
                         si.AudioPresentationType = dts.AudioPresentationType;
                     if (dts.SamplingFrequency != SamplingFrequency.Reserved)
                         si.SamplingFrequency = dts.SamplingFrequency;
                 }
             }
             break;
         case ElementaryStreamTypes.VIDEO_STREAM_MPEG2:
             if ((si.ElementaryDescriptors == null) ||
                 si.FrameRate == FrameRate.Reserved ||
                 si.VideoFormat == VideoFormat.Reserved ||
                 si.AspectRatio == AspectRatio.Reserved)
             {
                 Mpeg2Info mpeg2 = new Mpeg2Info(payload, 0);
                 if (mpeg2.Valid)
                 {
                     if (mpeg2.AspectRatio != AspectRatio.Reserved)
                         si.AspectRatio = mpeg2.AspectRatio;
                     if (mpeg2.FrameRate != FrameRate.Reserved)
                         si.FrameRate = mpeg2.FrameRate;
                     if (mpeg2.VideoFormat != VideoFormat.Reserved)
                         si.VideoFormat = mpeg2.VideoFormat;
                     if (si.ElementaryDescriptors == null)
                         si.ElementaryDescriptors = mpeg2.ElementaryDescriptors;
                 }
             }
             break;
     }
 }