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.

### Field Summary

Fields
`protected static org.slf4j.Logger` `log`
`protected Serializer` `serializer` Serializer object.

### 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 and Description
`RTMPProtocolEncoder()`

### Method Summary

Methods
`protected boolean` `dropMessage(RTMP rtmp, int channelId, IRTMPEvent message)` Determine if this message should be dropped for lateness.
`org.apache.mina.core.buffer.IoBuffer` `encode(ProtocolState state, Object message)` Encodes object with given protocol state to byte buffer
`org.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.
`org.apache.mina.core.buffer.IoBuffer` `encodeFlexMessage(FlexMessage msg, RTMP rtmp)` Encodes Flex message event.
`org.apache.mina.core.buffer.IoBuffer` `encodeFlexSharedObject(ISharedObjectMessage so, RTMP rtmp)` 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(RTMP rtmp, Header header, Header lastHeader)` Encode RTMP header.
`void` `encodeHeader(RTMP rtmp, 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, RTMP rtmp)` Encodes Invoke event to byte buffer.
`org.apache.mina.core.buffer.IoBuffer` `encodeMessage(RTMP rtmp, Header header, IRTMPEvent message)` Encode message.
`org.apache.mina.core.buffer.IoBuffer` `encodeNotify(Notify notify, RTMP rtmp)` Encodes Notify event to byte buffer.
`protected void` `encodeNotifyOrInvoke(org.apache.mina.core.buffer.IoBuffer out, Notify invoke, RTMP rtmp)` Encode notification event and fill given byte buffer.
`protected org.apache.mina.core.buffer.IoBuffer` `encodeNotifyOrInvoke(Notify invoke, RTMP rtmp)` Encode notification event.
`org.apache.mina.core.buffer.IoBuffer` `encodePacket(RTMP rtmp, 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, RTMP rtmp)` 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` `setConnection(RTMPConnection conn)` Set the connection being used with this encoder
`void` `setDropLiveFuture(boolean dropLiveFuture)` Setter for dropLiveFuture
`void` `setSerializer(Serializer serializer)` Setter for serializer.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### log

    protected static org.slf4j.Logger log

#### serializer

    protected Serializer serializer

Serializer object.

### Constructor Detail

#### RTMPProtocolEncoder

    public RTMPProtocolEncoder()

### Method Detail

#### encode

    public org.apache.mina.core.buffer.IoBuffer encode(ProtocolState state,
                                              Object message)
                                                throws Exception

Encodes object with given protocol state to byte buffer

Parameters:
  `state` - Protocol state
  `message` - Object to encode
Returns:
  IoBuffer with encoded data
Throws:
  `Exception` - Any decoding exception

#### encodePacket

    public org.apache.mina.core.buffer.IoBuffer encodePacket(RTMP rtmp,
                                                    Packet packet)

Encode packet.

Parameters:
  `rtmp` - RTMP protocol state
  `packet` - RTMP packet
Returns:
  Encoded data

#### dropMessage

    protected boolean dropMessage(RTMP rtmp,
                      int channelId,
                      IRTMPEvent message)

Determine if this message should be dropped for lateness. Live publish data does not come through this section, only outgoing data does. - 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:
  `rtmp` - the protocol state
  `channelId` - the channel ID
  `message` - the message
Returns:
  true to drop; false to send

#### encodeHeader

    public org.apache.mina.core.buffer.IoBuffer encodeHeader(RTMP rtmp,
                                                    Header header,
                                                    Header lastHeader)

Encode RTMP header.

Parameters:
  `rtmp` - The protocol state
  `header` - RTMP message header
  `lastHeader` - Previous header
Returns:
  Encoded header data

#### encodeHeader

    public void encodeHeader(RTMP rtmp,
                    Header header,
                    Header lastHeader,
                    org.apache.mina.core.buffer.IoBuffer buf)

Encode RTMP header into given IoBuffer.

Parameters:
  `rtmp` - The protocol state
  `header` - RTMP message header
  `lastHeader` - Previous header
  `buf` - Buffer to write encoded header to

#### encodeMessage

    public org.apache.mina.core.buffer.IoBuffer encodeMessage(RTMP rtmp,
                                                     Header header,
                                                     IRTMPEvent message)

Encode message.

Parameters:
  `rtmp` - RTMP protocol state
  `header` - RTMP message header
  `message` - 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 interface `IEventEncoder`
Parameters:
  `chunkSize` - ChunkSize event
Returns:
  Byte buffer

#### encodeFlexSharedObject

    public org.apache.mina.core.buffer.IoBuffer encodeFlexSharedObject(ISharedObjectMessage so,
                                                              RTMP rtmp)

Encodes SharedObjectMessage event to byte buffer using AMF3 encoding.

Specified by:
  `encodeFlexSharedObject` in interface `IEventEncoder`
Parameters:
  `so` - ISharedObjectMessage event
  `rtmp` - RTMP protocol state
Returns:
  Byte buffer

#### encodeSharedObject

    public org.apache.mina.core.buffer.IoBuffer encodeSharedObject(ISharedObjectMessage so,
                                                          RTMP rtmp)

Encodes SharedObjectMessage event to byte buffer.

Specified by:
  `encodeSharedObject` in interface `IEventEncoder`
Parameters:
  `so` - ISharedObjectMessage event
  `rtmp` - RTMP protocol state
Returns:
  Byte buffer

#### encodeNotify

    public org.apache.mina.core.buffer.IoBuffer encodeNotify(Notify notify,
                                                    RTMP rtmp)

Encodes Notify event to byte buffer.

Specified by:
  `encodeNotify` in interface `IEventEncoder`
Parameters:
  `notify` - Notify event
  `rtmp` - RTMP protocol state
Returns:
  Byte buffer

#### encodeInvoke

    public org.apache.mina.core.buffer.IoBuffer encodeInvoke(Invoke invoke,
                                                    RTMP rtmp)

Encodes Invoke event to byte buffer.

Specified by:
  `encodeInvoke` in interface `IEventEncoder`
Parameters:
  `invoke` - Invoke event
  `rtmp` - RTMP protocol state
Returns:
  Byte buffer

#### encodeNotifyOrInvoke

    protected org.apache.mina.core.buffer.IoBuffer encodeNotifyOrInvoke(Notify invoke,
                                                            RTMP rtmp)

Encode notification event.

Parameters:
  `invoke` - Notification event
Returns:
  Encoded event data

#### encodeNotifyOrInvoke

    protected void encodeNotifyOrInvoke(org.apache.mina.core.buffer.IoBuffer out,
                            Notify invoke,
                            RTMP rtmp)

Encode notification event and fill given byte buffer.

Parameters:
  `out` - Byte buffer to fill
  `invoke` - Notification event

#### encodePing

    public org.apache.mina.core.buffer.IoBuffer encodePing(Ping ping)

Encodes Ping event to byte buffer.

Specified by:
  `encodePing` in interface `IEventEncoder`
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 interface `IEventEncoder`
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 interface `IEventEncoder`
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 interface `IEventEncoder`
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 interface `IEventEncoder`
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 interface `IEventEncoder`
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` - call
  `error` - error
Returns:
  status object

#### encodeFlexMessage

    public org.apache.mina.core.buffer.IoBuffer encodeFlexMessage(FlexMessage msg,
                                                         RTMP rtmp)

Encodes Flex message event.

Parameters:
  `msg` - Flex message event
  `rtmp` - RTMP
Returns:
  Encoded data

#### encodeFlexStreamSend

    public org.apache.mina.core.buffer.IoBuffer encodeFlexStreamSend(FlexStreamSend msg)

#### setSerializer

    public void setSerializer(Serializer serializer)

Setter for serializer.

Parameters:
  `serializer` - Serializer

#### setBaseTolerance

    public void setBaseTolerance(long baseTolerance)

#### setDropLiveFuture

    public void setDropLiveFuture(boolean dropLiveFuture)

Setter for dropLiveFuture

#### getBaseTolerance

    public long getBaseTolerance()

#### setConnection

    public void setConnection(RTMPConnection conn)

Set the connection being used with this encoder

Parameters:
  `conn` - active connection