Example #1
0
        public RTMPMessageHeader(RTMPConnection connection, BinaryReader br)
        {
            Connection = connection;

            //format
            ReadFormatAndChunkStreamID(br);
            RTMPChunkStream csinfo = Connection.GetChunkStream((int)ChunkStreamID);

            //yay code repetition ftw!
            switch (Format)
            {
            case RTMPMessageFormat.BasicHeader_1:
                Timestamp       = csinfo.Timestamp;
                MessageLength   = csinfo.MessageLength;
                MessageTypeID   = csinfo.MessageTypeID;
                MessageStreamID = csinfo.MessageStreamID;
                break;

            case RTMPMessageFormat.BasicHeaderAndTime_4:
                ReadTimestamp(br);
                ReadExtendedTimestamp(br);

                csinfo.Timestamp = Timestamp;
                MessageLength    = csinfo.MessageLength;
                MessageTypeID    = csinfo.MessageTypeID;
                MessageStreamID  = csinfo.MessageStreamID;
                break;

            case RTMPMessageFormat.NoMessageId_8:
                ReadTimestamp(br);
                ReadMessageLength(br);
                ReadMessageTypeID(br);
                ReadExtendedTimestamp(br);

                csinfo.Timestamp     = Timestamp;
                csinfo.MessageLength = MessageLength;
                csinfo.MessageTypeID = MessageTypeID;
                MessageStreamID      = csinfo.MessageStreamID;
                break;

            case RTMPMessageFormat.FullHeader_12:
                ReadTimestamp(br);
                ReadMessageLength(br);
                ReadMessageTypeID(br);
                ReadMessageStreamID(br);
                ReadExtendedTimestamp(br);

                csinfo.Timestamp       = Timestamp;
                csinfo.MessageLength   = MessageLength;
                csinfo.MessageTypeID   = MessageTypeID;
                csinfo.MessageStreamID = MessageStreamID;
                break;
            }

            /*Timestamp = info.Timestamp;
             * MessageLengthFromHeader = info.MessageLength;
             * MessageTypeID = info.MessageTypeID;
             * MessageStreamID = info.MessageStreamID;*/
        }
Example #2
0
        public RTMPMessageBody(RTMPConnection connection, RTMPMessageHeader header, RTMPLib.Internal.BinaryReader br)
        {
            Connection = connection;

            byte[] buffer = null;
            if (header.MessageLength < 0)             //this is a follow up message
            {
                RTMPChunkStream csinfo = Connection.GetChunkStream((int)header.ChunkStreamID);
                buffer = br.ReadBytes(Math.Min(csinfo.RemainingBytes, Connection.IncomingChunkSize));
            }
            else
            {
                buffer = br.ReadBytes(Math.Min(header.MessageLength, Connection.IncomingChunkSize));
            }
            ms.Write(buffer, 0, buffer.Length);

            /*int remaining = connection.IncomingChunkSize;
             *
             * while (remaining > 0)
             * {
             *      byte[] buffer = br.ReadBytes(remaining);
             *      ms.Write(buffer, 0, buffer.Length);
             *      remaining -= ParentMessage.Connection.IncomingChunkSize;
             * }
             *
             * int remaining = ParentMessage.Header.MessageLength;
             * while (remaining > 0)
             * {
             *      byte[] buffer = br.ReadBytes(Math.Min(ParentMessage.Connection.IncomingChunkSize,remaining));
             *      ms.Write(buffer,0,buffer.Length);
             *      remaining -= ParentMessage.Connection.IncomingChunkSize;
             *      if (remaining > 0)
             *      {
             *              new RTMPMessageHeader(ParentMessage, br); // read the header for the next message piece
             *      }
             * }*/
            ms.Position  = 0;
            MemoryReader = new RTMPLib.Internal.BinaryReader(ms);
        }
Example #3
0
 public RTMPChunkStream GetChunkStream(int chunkStreamID)
 {
     RTMPChunkStream cs = null;
     if (!chunkStreams.TryGetValue(chunkStreamID, out cs))
     {
         cs = new RTMPChunkStream(this);
         chunkStreams[chunkStreamID] = cs;
     }
     return cs;
 }