Package org.red5.server.net.rtmp.codec
Class RTMPProtocolEncoder
- java.lang.Object
-
- org.red5.server.net.rtmp.codec.RTMPProtocolEncoder
-
- All Implemented Interfaces:
IEventEncoder
,Constants
- Direct Known Subclasses:
RTMPTProtocolEncoder
public class RTMPProtocolEncoder extends Object implements Constants, IEventEncoder
RTMP protocol encoder encodes RTMP messages and packets to byte buffers.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.red5.server.net.rtmp.message.Constants
Constants.DataType
-
-
Field Summary
Fields Modifier and Type Field Description protected org.slf4j.Logger
log
-
Fields inherited from interface org.red5.server.net.rtmp.message.Constants
HANDSHAKE_SIZE, HEADER_CONTINUE, HEADER_NEW, HEADER_SAME_SOURCE, HEADER_TIMER_CHANGE, MEDIUM_INT_MAX, SO_CLIENT_CLEAR_DATA, SO_CLIENT_DELETE_DATA, SO_CLIENT_INITIAL_DATA, SO_CLIENT_SEND_MESSAGE, SO_CLIENT_STATUS, SO_CLIENT_UPDATE_ATTRIBUTE, SO_CLIENT_UPDATE_DATA, SO_CONNECT, SO_DELETE_ATTRIBUTE, SO_DISCONNECT, SO_SEND_MESSAGE, SO_SET_ATTRIBUTE, SOURCE_TYPE_LIVE, SOURCE_TYPE_VOD, TYPE_ABORT, TYPE_AGGREGATE, TYPE_AUDIO_DATA, TYPE_BYTES_READ, TYPE_CHUNK_SIZE, TYPE_CLIENT_BANDWIDTH, TYPE_EDGE_ORIGIN, TYPE_FLEX_MESSAGE, TYPE_FLEX_SHARED_OBJECT, TYPE_FLEX_STREAM_SEND, TYPE_INVOKE, TYPE_NOTIFY, TYPE_PING, TYPE_SERVER_BANDWIDTH, TYPE_SHARED_OBJECT, TYPE_STREAM_METADATA, TYPE_VIDEO_DATA
-
-
Constructor Summary
Constructors Constructor Description RTMPProtocolEncoder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
dropMessage(int channelId, IRTMPEvent message)
Determine if this message should be dropped.org.apache.mina.core.buffer.IoBuffer
encode(Object message)
Encodes object with given protocol state to byte bufferorg.apache.mina.core.buffer.IoBuffer
encodeAggregate(Aggregate aggregate)
Encodes Aggregate event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeAudioData(AudioData audioData)
Encodes AudioData event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeBytesRead(BytesRead bytesRead)
Encodes BytesRead event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeChunkSize(ChunkSize chunkSize)
Encodes ChunkSize event to byte buffer.protected void
encodeCommand(org.apache.mina.core.buffer.IoBuffer out, ICommand command)
Encode command event and fill given byte buffer.protected org.apache.mina.core.buffer.IoBuffer
encodeCommand(Notify invoke)
Encode notification event.org.apache.mina.core.buffer.IoBuffer
encodeFlexMessage(FlexMessage msg)
Encodes Flex message event.org.apache.mina.core.buffer.IoBuffer
encodeFlexSharedObject(ISharedObjectMessage so)
Encodes SharedObjectMessage event to byte buffer using AMF3 encoding.org.apache.mina.core.buffer.IoBuffer
encodeFlexStreamSend(FlexStreamSend msg)
org.apache.mina.core.buffer.IoBuffer
encodeHeader(Header header, Header lastHeader)
Encode RTMP header.void
encodeHeader(Header header, Header lastHeader, org.apache.mina.core.buffer.IoBuffer buf)
Encode RTMP header into given IoBuffer.org.apache.mina.core.buffer.IoBuffer
encodeInvoke(Invoke invoke)
Encodes Invoke event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeMessage(Header header, IRTMPEvent message)
Encode message.org.apache.mina.core.buffer.IoBuffer
encodeNotify(Notify notify)
Encodes Notify event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodePacket(Packet packet)
Encode packet.org.apache.mina.core.buffer.IoBuffer
encodePing(Ping ping)
Encodes Ping event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeSharedObject(ISharedObjectMessage so)
Encodes SharedObjectMessage event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeStreamMetadata(Notify metaData)
org.apache.mina.core.buffer.IoBuffer
encodeUnknown(Unknown unknown)
Encodes Unknown event to byte buffer.org.apache.mina.core.buffer.IoBuffer
encodeVideoData(VideoData videoData)
Encodes VideoData event to byte buffer.protected StatusObject
generateErrorResult(String code, Throwable error)
Generate error object to return for given exception.long
getBaseTolerance()
void
setBaseTolerance(long baseTolerance)
void
setDropEncoded(boolean dropEncoded)
void
setDropLiveFuture(boolean dropLiveFuture)
Setter for dropLiveFuture
-
-
-
Method Detail
-
encode
public org.apache.mina.core.buffer.IoBuffer encode(Object message) throws Exception
Encodes object with given protocol state to byte buffer- Parameters:
message
- Object to encode- Returns:
- IoBuffer with encoded data
- Throws:
Exception
- Any decoding exception
-
encodePacket
public org.apache.mina.core.buffer.IoBuffer encodePacket(Packet packet)
Encode packet.- Parameters:
packet
- RTMP packet- Returns:
- Encoded data
-
dropMessage
protected boolean dropMessage(int channelId, IRTMPEvent message)
Determine if this message should be dropped. If the traffic from server to client is congested, then drop LIVE messages to help alleviate congestion. - determine latency between server and client using ping - ping timestamp is unsigned int (4 bytes) and is set from value on sender 1st drop disposable frames - lowest mark 2nd drop interframes - middle 3rd drop key frames - high mark- Parameters:
channelId
- the channel IDmessage
- the message- Returns:
- true to drop; false to send
-
encodeHeader
public org.apache.mina.core.buffer.IoBuffer encodeHeader(Header header, Header lastHeader)
Encode RTMP header.- Parameters:
header
- RTMP message headerlastHeader
- Previous header- Returns:
- Encoded header data
-
encodeHeader
public void encodeHeader(Header header, Header lastHeader, org.apache.mina.core.buffer.IoBuffer buf)
Encode RTMP header into given IoBuffer.- Parameters:
header
- RTMP message headerlastHeader
- Previous headerbuf
- Buffer for writing encoded header into
-
encodeMessage
public org.apache.mina.core.buffer.IoBuffer encodeMessage(Header header, IRTMPEvent message)
Encode message.- Parameters:
header
- RTMP message headermessage
- RTMP message (event)- Returns:
- Encoded message data
-
encodeChunkSize
public org.apache.mina.core.buffer.IoBuffer encodeChunkSize(ChunkSize chunkSize)
Encodes ChunkSize event to byte buffer.- Specified by:
encodeChunkSize
in interfaceIEventEncoder
- Parameters:
chunkSize
- ChunkSize event- Returns:
- Byte buffer
-
encodeFlexSharedObject
public org.apache.mina.core.buffer.IoBuffer encodeFlexSharedObject(ISharedObjectMessage so)
Encodes SharedObjectMessage event to byte buffer using AMF3 encoding.- Specified by:
encodeFlexSharedObject
in interfaceIEventEncoder
- Parameters:
so
- ISharedObjectMessage event- Returns:
- Byte buffer
-
encodeSharedObject
public org.apache.mina.core.buffer.IoBuffer encodeSharedObject(ISharedObjectMessage so)
Encodes SharedObjectMessage event to byte buffer.- Specified by:
encodeSharedObject
in interfaceIEventEncoder
- Parameters:
so
- ISharedObjectMessage event- Returns:
- Byte buffer
-
encodeNotify
public org.apache.mina.core.buffer.IoBuffer encodeNotify(Notify notify)
Encodes Notify event to byte buffer.- Specified by:
encodeNotify
in interfaceIEventEncoder
- Parameters:
notify
- Notify event- Returns:
- Byte buffer
-
encodeInvoke
public org.apache.mina.core.buffer.IoBuffer encodeInvoke(Invoke invoke)
Encodes Invoke event to byte buffer.- Specified by:
encodeInvoke
in interfaceIEventEncoder
- Parameters:
invoke
- Invoke event- Returns:
- Byte buffer
-
encodeCommand
protected org.apache.mina.core.buffer.IoBuffer encodeCommand(Notify invoke)
Encode notification event.- Parameters:
invoke
- Notification event- Returns:
- Encoded event data
-
encodeCommand
protected void encodeCommand(org.apache.mina.core.buffer.IoBuffer out, ICommand command)
Encode command event and fill given byte buffer.- Parameters:
out
- Buffer to fillcommand
- Command event
-
encodePing
public org.apache.mina.core.buffer.IoBuffer encodePing(Ping ping)
Encodes Ping event to byte buffer.- Specified by:
encodePing
in interfaceIEventEncoder
- Parameters:
ping
- Ping event- Returns:
- Byte buffer
-
encodeBytesRead
public org.apache.mina.core.buffer.IoBuffer encodeBytesRead(BytesRead bytesRead)
Encodes BytesRead event to byte buffer.- Specified by:
encodeBytesRead
in interfaceIEventEncoder
- Parameters:
bytesRead
- BytesRead event- Returns:
- Byte buffer
-
encodeAggregate
public org.apache.mina.core.buffer.IoBuffer encodeAggregate(Aggregate aggregate)
Encodes Aggregate event to byte buffer.- Specified by:
encodeAggregate
in interfaceIEventEncoder
- Parameters:
aggregate
- Aggregate event- Returns:
- Byte buffer
-
encodeAudioData
public org.apache.mina.core.buffer.IoBuffer encodeAudioData(AudioData audioData)
Encodes AudioData event to byte buffer.- Specified by:
encodeAudioData
in interfaceIEventEncoder
- Parameters:
audioData
- AudioData event- Returns:
- Byte buffer
-
encodeVideoData
public org.apache.mina.core.buffer.IoBuffer encodeVideoData(VideoData videoData)
Encodes VideoData event to byte buffer.- Specified by:
encodeVideoData
in interfaceIEventEncoder
- Parameters:
videoData
- VideoData event- Returns:
- Byte buffer
-
encodeUnknown
public org.apache.mina.core.buffer.IoBuffer encodeUnknown(Unknown unknown)
Encodes Unknown event to byte buffer.- Specified by:
encodeUnknown
in interfaceIEventEncoder
- Parameters:
unknown
- Unknown event- Returns:
- Byte buffer
-
encodeStreamMetadata
public org.apache.mina.core.buffer.IoBuffer encodeStreamMetadata(Notify metaData)
-
generateErrorResult
protected StatusObject generateErrorResult(String code, Throwable error)
Generate error object to return for given exception.- Parameters:
code
- callerror
- error- Returns:
- status object
-
encodeFlexMessage
public org.apache.mina.core.buffer.IoBuffer encodeFlexMessage(FlexMessage msg)
Encodes Flex message event.- Parameters:
msg
- Flex message event- Returns:
- Encoded data
-
encodeFlexStreamSend
public org.apache.mina.core.buffer.IoBuffer encodeFlexStreamSend(FlexStreamSend msg)
-
setBaseTolerance
public void setBaseTolerance(long baseTolerance)
-
setDropLiveFuture
public void setDropLiveFuture(boolean dropLiveFuture)
Setter for dropLiveFuture- Parameters:
dropLiveFuture
- drop live data with future times
-
setDropEncoded
public void setDropEncoded(boolean dropEncoded)
-
getBaseTolerance
public long getBaseTolerance()
-
-