/// <summary> /// Encode RTMP header into given ByteBuffer /// </summary> /// <param name="header">RTMP message header</param> /// <param name="lastHeader">Previous header</param> /// <param name="buffer">Buffer to write encoded header to</param> /// <returns>Encoded header data</returns> public static ByteBuffer EncodeHeader(RtmpHeader header, RtmpHeader lastHeader, ByteBuffer buffer) { HeaderType headerType = GetHeaderType(header, lastHeader); EncodeHeaderByte(buffer, (byte)headerType, header.ChannelId); switch (headerType) { case HeaderType.HeaderNew: if (header.Timer < 0xffffff) buffer.WriteMediumInt(header.Timer); else buffer.WriteMediumInt(0xffffff); buffer.WriteMediumInt(header.Size); buffer.Put((byte)header.DataType); buffer.WriteReverseInt(header.StreamId); break; case HeaderType.HeaderSameSource: if (header.Timer < 0xffffff) buffer.WriteMediumInt(header.Timer); else buffer.WriteMediumInt(0xffffff); buffer.WriteMediumInt(header.Size); buffer.Put((byte)header.DataType); break; case HeaderType.HeaderTimerChange: if (header.Timer < 0xffffff) buffer.WriteMediumInt(header.Timer); else buffer.WriteMediumInt(0xffffff); break; case HeaderType.HeaderContinue: break; } if (header.Timer >= 0xffffff) buffer.PutInt(header.Timer); return buffer; }