FlvPacket RtmpPacketToFlvPacket(RtmpPacket rtmp_packet)
        {
            var rtmp_header = rtmp_packet.Header;
            var header      = new FlvTagHeader();

            header.StreamId  = 0;
            header.TagType   = rtmp_header.MessageType;
            header.Timestamp = rtmp_header.Timestamp;
            var packet = new FlvPacket(header);

            packet.Body = rtmp_packet.Body;
            return(packet);
        }
        void WriteTagHeader(FlvTagHeader header)
        {
            _writer.WriteByte((byte)header.TagType);
            _writer.WriteUInt24(header.DataSize);
            var timestamp = BitConverter.GetBytes(header.Timestamp);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(timestamp);
            }
            _writer.Write(timestamp, 1, 3);
            _writer.WriteByte(timestamp[0]);
            _writer.WriteUInt24(header.StreamId);
        }
        byte[] GetMessageBytes(FlvTagHeader header, RtmpMessage message)
        {
            switch (header.TagType)
            {
            case MessageType.Audio:
            case MessageType.Video:
                return(GetMessageBytes(message, (w, o) => w.WriteBytes(((ByteData)o).Data)));

            case MessageType.DataAmf0:
                return(GetMessageBytes(message, (w, o) => WriteCommandOrData(w, o, ObjectEncoding.Amf0)));

            default:
                throw new ArgumentOutOfRangeException("Unknown RTMP message type: " + (int)header.TagType);
            }
        }
示例#4
0
 public FlvPacket(FlvTagHeader header, RtmpMessage body) : this(header)
 {
     Body   = body;
     Length = header.DataSize;
 }
示例#5
0
 public FlvPacket(FlvTagHeader header)
 {
     Header = header;
     Length = header.DataSize;
     Buffer = new byte[Length];
 }