コード例 #1
0
ファイル: TsDemuxer.cs プロジェクト: mcguirepr/bmff
        public void ProcessPacket(TsPacket packet)
        {
            if (packet.PacketIdentifier == (ushort)PacketIdentifier.NullPacket)
            {
                return; // null packet for padding strict muxrate streams
            }
#if DEBUG2
            var dbg = new StringBuilder();
            dbg.Append("Received packet for PID " + (PacketIdentifier)packet.PacketIdentifier + ". ");
            dbg.Append("Continuity is " + packet.ContinuityCounter + ". ");
            if (packet.AdaptationField != null)
            {
                dbg.Append("Has Adaptation Field. ");
            }
            if (packet.Payload != null)
            {
                dbg.Append("Has " + packet.Payload.Length + " byte Payload. ");
            }
            if (packet.PayloadUnitStartIndicator)
            {
                dbg.Append("First in series. ");
            }
            Debug.WriteLine(dbg.ToString());
#endif
            if (_streams.TryGetValue(packet.PacketIdentifier, out TsStream stream))
            {
                stream.ProcessInput(packet);
            }
        }
コード例 #2
0
ファイル: AacsPacket.cs プロジェクト: heksesang/bmff
        public AacsPacket(byte[] buffer, int offset)
        {
            CopyControl = (AACSCopyControl)((buffer[offset] & 0xC0) >> 6);
            Timestamp = (uint)(((buffer[offset++] << 24) & 0x3F) | (buffer[offset++] << 16) | (buffer[offset++] << 8) | buffer[offset++]);

            if (CopyControl == AACSCopyControl.Unencrypted)
            {
                TsPacket = new TsPacket(buffer, offset);
            }
            else
            {
                throw new FormatException("Encrypted content not currently supported.");
            }
        }
コード例 #3
0
        public AacsPacket(byte[] buffer, int offset)
        {
            CopyControl = (AACSCopyControl)((buffer[offset] & 0xC0) >> 6);
            Timestamp   = (uint)(((buffer[offset++] << 24) & 0x3F) | (buffer[offset++] << 16) | (buffer[offset++] << 8) | buffer[offset++]);

            if (CopyControl == AACSCopyControl.Unencrypted)
            {
                TsPacket = new TsPacket(buffer, offset);
            }
            else
            {
                throw new FormatException("Encrypted content not currently supported.");
            }
        }
コード例 #4
0
ファイル: TsDemuxer.cs プロジェクト: heksesang/bmff
        public void ProcessInput(byte[] buffer, int offset, int length)
        {
            int position = offset;
            int remainder = 0;

            if (_partialPacketLength != 0)
            {
                Debug.WriteLine("Using previous " + _partialPacketLength + " byte partial packet.");
                remainder = TsPacket.Length - _partialPacketLength;
                int len = Math.Min(remainder, length);
                Debug.WriteLine("Copying " + len + " additional bytes to partial packet.");
                Buffer.BlockCopy(buffer, 0, _partialPacket, _partialPacketLength, len);
                _partialPacketLength += len;
                position += len;

                Debug.WriteLine("Partial packet is now " + _partialPacketLength + " bytes.");
                if (_partialPacketLength >= TsPacket.Length)
                {
                    _partialPacketLength = 0;
                    try
                    {
                        var packet = new TsPacket(_partialPacket);
                        ProcessPacket(packet);
                        Debug.WriteLine("Reassembled partial packet.");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }
            }

            while ((offset + length - position) >= TsPacket.Length)
            {
                if (buffer[position] == 0x47)
                {
                    try
                    {
                        var packet = new TsPacket(buffer, position);
                        position += TsPacket.Length;
                        Debug.WriteLine("Processing packet.");
                        ProcessPacket(packet);
                    }
                    catch
                    {
                        Debug.WriteLine("Error deserializing packet.  Assuming false start code and scanning ahead for the next packet.");
                        position++;
                    }
                }
                else
                {
                    Debug.WriteLine("Skipping byte 0x" + buffer[position].ToString("X2") + " at offset " + position + ".");
                    position++;
                }
            }

            remainder = offset + length - position;
            if (remainder > 0)
            {
                Debug.WriteLine("Remainder is " + remainder + " bytes.");
                int packetStartOffset = -1;
                for (int i = 0; i < remainder; i++)
                {
                    if (buffer[position + i] == 0x47)
                    {
                        packetStartOffset = i;
                        break;
                    }
                    Debug.WriteLine("Skipping byte 0x" + buffer[position].ToString("X2") + " at offset " + (position + i) + ".");
                }
                if (packetStartOffset >= 0)
                {
                    Debug.WriteLine("Found sync byte in remainder.  Storing partial packet.");
                    _partialPacketLength = remainder - packetStartOffset;
                    Buffer.BlockCopy(buffer, position + packetStartOffset, _partialPacket, 0, _partialPacketLength);
                }
                else _partialPacketLength = 0;
            }
        }
コード例 #5
0
ファイル: TsDemuxer.cs プロジェクト: heksesang/bmff
        public void ProcessPacket(TsPacket packet)
        {
            if (packet.PacketIdentifier == (ushort) PacketIdentifier.NullPacket)
                return; // null packet for padding strict muxrate streams
#if DEBUG2
            var dbg = new StringBuilder();
            dbg.Append("Received packet for PID " + (PacketIdentifier) packet.PacketIdentifier + ". ");
            dbg.Append("Continuity is " + packet.ContinuityCounter + ". ");
            if (packet.AdaptationField != null) dbg.Append("Has Adaptation Field. ");
            if (packet.Payload != null) dbg.Append("Has " + packet.Payload.Length + " byte Payload. ");
            if (packet.PayloadUnitStartIndicator) dbg.Append("First in series. ");
            Debug.WriteLine(dbg.ToString());
#endif
            TsStream stream;
            if (_streams.TryGetValue(packet.PacketIdentifier, out stream)) stream.ProcessInput(packet);

        }
コード例 #6
0
 public abstract void ProcessInput(TsPacket packet);
コード例 #7
0
ファイル: TsStream.cs プロジェクト: heksesang/bmff
 public abstract void ProcessInput(TsPacket packet);
コード例 #8
0
ファイル: TsDemuxer.cs プロジェクト: mcguirepr/bmff
        public void ProcessInput(byte[] buffer, int offset, int length)
        {
            int position  = offset;
            int remainder = 0;

            if (_partialPacketLength != 0)
            {
                Debug.WriteLine("Using previous " + _partialPacketLength + " byte partial packet.");
                remainder = TsPacket.Length - _partialPacketLength;
                int len = Math.Min(remainder, length);
                Debug.WriteLine("Copying " + len + " additional bytes to partial packet.");
                Buffer.BlockCopy(buffer, 0, _partialPacket, _partialPacketLength, len);
                _partialPacketLength += len;
                position             += len;

                Debug.WriteLine("Partial packet is now " + _partialPacketLength + " bytes.");
                if (_partialPacketLength >= TsPacket.Length)
                {
                    _partialPacketLength = 0;
                    try
                    {
                        var packet = new TsPacket(_partialPacket);
                        ProcessPacket(packet);
                        Debug.WriteLine("Reassembled partial packet.");
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }
            }

            while ((offset + length - position) >= TsPacket.Length)
            {
                if (buffer[position] == 0x47)
                {
                    try
                    {
                        var packet = new TsPacket(buffer, position);
                        position += TsPacket.Length;
                        Debug.WriteLine("Processing packet.");
                        ProcessPacket(packet);
                    }
                    catch
                    {
                        Debug.WriteLine("Error deserializing packet.  Assuming false start code and scanning ahead for the next packet.");
                        position++;
                    }
                }
                else
                {
                    Debug.WriteLine("Skipping byte 0x" + buffer[position].ToString("X2") + " at offset " + position + ".");
                    position++;
                }
            }

            remainder = offset + length - position;
            if (remainder > 0)
            {
                Debug.WriteLine("Remainder is " + remainder + " bytes.");
                int packetStartOffset = -1;
                for (int i = 0; i < remainder; i++)
                {
                    if (buffer[position + i] == 0x47)
                    {
                        packetStartOffset = i;
                        break;
                    }
                    Debug.WriteLine("Skipping byte 0x" + buffer[position].ToString("X2") + " at offset " + (position + i) + ".");
                }
                if (packetStartOffset >= 0)
                {
                    Debug.WriteLine("Found sync byte in remainder.  Storing partial packet.");
                    _partialPacketLength = remainder - packetStartOffset;
                    Buffer.BlockCopy(buffer, position + packetStartOffset, _partialPacket, 0, _partialPacketLength);
                }
                else
                {
                    _partialPacketLength = 0;
                }
            }
        }