Ejemplo n.º 1
0
            private void ReadSpecialForm(BitSplitter bs)
            {
                byte[] data = bs.RemainingBytes();
                if (data.Length < PacketLength)
                {
                    throw new DemuxException("Invalid PES: packet shorter than described");
                }
                MemoryStream ms = new MemoryStream(data, 0, PacketLength);

                FrameData = ms.ToArray();
            }
Ejemplo n.º 2
0
            /// <summary>Digest data into structured packet</summary>
            public Packet(byte[] RawPacket)
            {
                if (RawPacket[0] != 0x47)
                {
                    throw new DemuxException("Sync byte missing");
                }

                PCR = -1; TableId = -1; PayloadIs_PES = false;

                BitSplitter bs = new BitSplitter(RawPacket);

                ReadTransportHeader(bs);

                if (PID == 0x1FFF)
                {
                    return;                                // null packet
                }
                CheckAdaptionField(bs);

                payload = bs.RemainingBytes();

                CheckPayloadType(bs);
            }
Ejemplo n.º 3
0
            private void DecodeElementaryStream(BitSplitter bs)
            {
                int marker = (int)bs.GetInteger(2);

                if (marker != 2)
                {
                    throw new DemuxException("Invalid PES: first marker missing");
                }
                ReadFlags(bs);
                if (bs.BitOffset != 0)
                {
                    throw new DemuxException("Alignment problem in PES (internal)");
                }
                HeaderLength = (int)bs.GetInteger(8);

                int head_start = bs.ByteOffset;

                if (HasPTS && HasDTS)
                {
                    ReadDTS_PTS(bs);
                }
                else if (HasPTS)
                {
                    ReadPTS(bs);
                }

                if (HasESCR)
                {
                    bs.SkipBytes(6);                          // not currently used.
                }
                if (HasEsRate)
                {
                    bs.SkipBits(24);                            // not currently used.
                }
                if (UsesTrickMode)
                {
                    bs.SkipBytes(1);                                // ignored
                }
                if (MoreCopyright)
                {
                    bs.SkipBytes(1);                                // ignored
                }
                if (HasPesCRC)
                {
                    bs.SkipBytes(2);                            // ignored
                }
                if (HasPesExtension)
                {
                    ReadExtendedHeader(bs);
                }

                // skip anything that's left
                int head_end = bs.ByteOffset;
                int to_skip  = HeaderLength - (head_end - head_start);

                if (to_skip < 0)
                {
                    throw new DemuxException("Invalid PES: declared header length did not match measured length");
                }
                bs.SkipBytes(to_skip);

                // Now, the remaining bytes are data and padding
                int data_length = PacketLength - (HeaderLength + to_skip);

                if (data_length > 3)
                {
                    data_length -= 3;                                  // no idea where the '3' is coming from...
                }
                byte[] data = bs.RemainingBytes();

                if (PacketLength == 0)                   // video is allowed to not specify
                {
                    data_length = data.Length;
                }

#if DEBUG
                if (data.Length < data_length)
                {
                    throw new DemuxException("Invalid PES: packet shorter than described");
                }

                if (data_length < 0)
                {
                    throw new DemuxException("Invalid PES: Negative packet length");
                }
#else
                if (data.Length < data_length || data_length < 0)
                {
                    data_length = 0;
                }
#endif

                MemoryStream ms = new MemoryStream(data, 0, data_length);
                FrameData = ms.ToArray();
            }