## org.red5.server.net.rtmp
Class RTMPConnection

    java.lang.Object
      org.red5.server.AttributeStore
          org.red5.server.BaseConnection
              org.red5.server.net.rtmp.RTMPConnection

All Implemented Interfaces:
  AttributeStoreMBean, ConnectionMBean, IEventDispatcher, IEventHandler, IEventListener, IAttributeStore, ICastingAttributeStore, IConnection, ICoreObject, IServiceCapableConnection, IStreamCapableConnection

Direct Known Subclasses:
  BaseRTMPTConnection, RTMPMinaConnection, RTMPOriginConnection

    public abstract class RTMPConnection

extends BaseConnection
implements IStreamCapableConnection, IServiceCapableConnection

RTMP connection. Stores information about client streams, data transfer channels, pending RPC calls, bandwidth configuration, used encoding (AMF0/AMF3), connection state (is alive, last ping time and ping result) and session.

Nested Class Summary

Nested classes/interfaces inherited from interface org.red5.server.api.IConnection
`IConnection.Encoding`

Field Summary
`protected int` `bytesReadInterval` Data read interval
`protected int` `clientId`
`protected int` `nextBytesRead` Number of bytes to read next.
`static String` `RTMP_CONNECTION_KEY`
`static byte` `RTMP_ENCRYPTED` Marker byte for encrypted RTMP data.
`static String` `RTMP_HANDSHAKE`
`static byte` `RTMP_NON_ENCRYPTED` Marker byte for standard or non-encrypted RTMP data.
`protected RTMP` `state` protocol state

Fields inherited from class org.red5.server.BaseConnection
`basicScopes, client, closed, droppedMessages, host, params, path, readMessages, remoteAddress, remoteAddresses, remotePort, scope, sessionId, type, writtenMessages`

Fields inherited from class org.red5.server.AttributeStore
`attributes`

Fields inherited from interface org.red5.server.api.IConnection
`PERSISTENT, POLLING, TRANSIENT`

Constructor Summary
`RTMPConnection(String type)` Creates anonymous RTMP connection without scope.

Method Summary
`void` `addClientStream(IClientStream stream)`
`void` `close()` Closes connection
`void` `closeChannel(int channelId)` Closes channel.
`boolean` `connect(IScope newScope, Object[] params)` Connect to another scope on server with given parameters
`OutputStream` `createOutputStream(int streamId)` Creates output stream object from stream id.
`protected String` `createStreamName()` Generates new stream name.
`void` `deleteStreamById(int streamId)` Deletes the stream with the given id.
`Channel` `getChannel(int channelId)` Return channel by id.
`long` `getClientBytesRead()` Get number of bytes the client reported to have received.
`IConnection.Encoding` `getEncoding()` Return AMF protocol encoding used by this connection.
`int` `getId()`
`int` `getInvokeId()` Generate next invoke id.
`int` `getLastPingTime()` Return roundtrip time of last ping command.
`int` `getNextAvailableChannelId()` Getter for next available channel id.
`protected IPendingServiceCall` `getPendingCall(int invokeId)` Get pending call service by id.
`long` `getPendingVideoMessages(int streamId)` Total number of video messages that are pending to be sent to a stream.
`long` `getReadBytes()` Total number of bytes read from the connection.
`RTMP` `getState()`
`byte` `getStateCode()`
`IClientStream` `getStreamByChannelId(int channelId)` Return stream by given channel id.
`IClientStream` `getStreamById(int id)` Get a stream by its id.
`int` `getStreamIdForChannel(int channelId)` Return stream id for given channel id.
`protected Collection<IClientStream>` `getStreams()` Getter for client streams.
`protected int` `getUsedStreamCount()` Getter for used stream count.
`long` `getWrittenBytes()` Total number of bytes written to the connection.
`void` `invoke(IServiceCall call)` Invokes service using remoting call object
`void` `invoke(IServiceCall call, int channel)` Invoke service using call and channel
`void` `invoke(String method)` Invoke method by name
`void` `invoke(String method, IPendingServiceCallback callback)` Invoke method by name with callback
`void` `invoke(String method, Object[] params)` Invoke method with parameters
`void` `invoke(String method, Object[] params, IPendingServiceCallback callback)`
`boolean` `isChannelUsed(int channelId)` Checks whether channel is used.
`protected void` `messageDropped()` Increases number of dropped messages.
`protected void` `messageReceived()` Increases number of read messages by one.
`protected void` `messageSent(Packet message)` Mark message as sent.
`IClientBroadcastStream` `newBroadcastStream(int streamId)` Create a broadcast stream.
`IPlaylistSubscriberStream` `newPlaylistSubscriberStream(int streamId)` Create a stream that can play a list.
`ISingleItemSubscriberStream` `newSingleItemSubscriberStream(int streamId)` Create a stream that can play only one item.
`void` `notify(IServiceCall call)`
`void` `notify(IServiceCall call, int channel)`
`void` `notify(String method)`
`void` `notify(String method, Object[] params)`
`protected abstract void` `onInactive()` Inactive state event handler.
`void` `ping()` Start measuring the roundtrip time for a packet on the connection.
`void` `ping(Ping ping)` Handler for ping event.
`protected void` `pingReceived(Ping pong)` Marks that ping back was received.
`abstract void` `rawWrite(IoBuffer out)` Write raw byte buffer.
`void` `receivedBytesRead(int bytes)` Read number of received bytes.
`protected void` `registerDeferredResult(DeferredResult result)` Registers deferred result.
`void` `registerPendingCall(int invokeId, IPendingServiceCall call)` Register pending call (remote function call that is yet to finish).
`protected void` `rememberStreamBufferDuration(int streamId, int bufferDuration)`
`void` `removeClientStream(int streamId)`
`int` `reserveStreamId()` Return a reserved stream id for use.
`protected IPendingServiceCall` `retrievePendingCall(int invokeId)` Retrieve pending call service by id.
`void` `setId(int clientId)`
`void` `setMaxHandshakeTimeout(int maxHandshakeTimeout)` Set maximum time to wait for valid handshake in milliseconds.
`void` `setMaxInactivity(int maxInactivity)` Setter for maximum inactivity.
`void` `setPingInterval(int pingInterval)` Setter for ping interval.
`void` `setSchedulingService(ISchedulingService schedulingService)` Sets the scheduling service.
`void` `setState(RTMP state)`
`void` `setStateCode(byte code)`
`void` `setup(String host, String path, String sessionId, Map<String,Object> params)` Initialize connection.
`void` `startRoundTripMeasurement()` Starts measurement.
`protected void` `startWaitForHandshake(ISchedulingService service)` Start waiting for a valid handshake.
`String` `toString()`
`protected void` `unregisterDeferredResult(DeferredResult result)` Unregister deferred result
`void` `unreserveStreamId(int streamId)` Unreserve this id for future use.
`protected void` `updateBytesRead()` Update number of bytes to read next value.
`abstract void` `write(Packet out)` Write packet.
`protected void` `writingMessage(Packet message)` Mark message as being written.

Methods inherited from class org.red5.server.BaseConnection
`connect, dispatchEvent, getBasicScopes, getClient, getConnectParams, getDroppedMessages, getHost, getPath, getPendingMessages, getReadLock, getReadMessages, getRemoteAddress, getRemoteAddresses, getRemotePort, getScope, getSessionId, getType, getWriteLock, getWrittenMessages, handleEvent, initialize, isConnected, notifyEvent, registerBasicScope, unregisterBasicScope`

Methods inherited from class org.red5.server.AttributeStore
`filterNull, getAttribute, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.red5.server.api.IConnection
`connect, getBasicScopes, getClient, getConnectParams, getDroppedMessages, getHost, getPath, getPendingMessages, getReadMessages, getRemoteAddress, getRemoteAddresses, getRemotePort, getScope, getSessionId, getType, getWrittenMessages, initialize, isConnected`

Methods inherited from interface org.red5.server.api.ICastingAttributeStore
`getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute`

Methods inherited from interface org.red5.server.api.IAttributeStore
`getAttribute, getAttribute, getAttributeNames, getAttributes, hasAttribute, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes`

Methods inherited from interface org.red5.server.api.event.IEventDispatcher
`dispatchEvent`

Methods inherited from interface org.red5.server.api.event.IEventHandler
`handleEvent`

Methods inherited from interface org.red5.server.api.event.IEventListener
`notifyEvent`

Field Detail

### RTMP_CONNECTION_KEY

    public static final String RTMP_CONNECTION_KEY

See Also:
  Constant Field Values

### RTMP_HANDSHAKE

    public static final String RTMP_HANDSHAKE

See Also:
  Constant Field Values

### RTMP_NON_ENCRYPTED

    public static final byte RTMP_NON_ENCRYPTED

  Marker byte for standard or non-encrypted RTMP data.

  See Also:
    Constant Field Values

### RTMP_ENCRYPTED

    public static final byte RTMP_ENCRYPTED

  Marker byte for encrypted RTMP data.

  See Also:
    Constant Field Values

### bytesReadInterval

    protected int bytesReadInterval

  Data read interval

### nextBytesRead

    protected int nextBytesRead

  Number of bytes to read next.

### clientId

    protected volatile int clientId

### state

    protected volatile RTMP state

  protocol state

Constructor Detail

### RTMPConnection

    public RTMPConnection(String type)

  Creates anonymous RTMP connection without scope.

  Parameters:
    `type` - Connection type

Method Detail

### getId

    public int getId()

### setId

    public void setId(int clientId)

### getState

    public RTMP getState()

### getStateCode

    public byte getStateCode()

### setStateCode

    public void setStateCode(byte code)

### setState

    public void setState(RTMP state)

### connect

    public boolean connect(IScope newScope,
                           Object[] params)

  Description copied from class: `BaseConnection`
  Connect to another scope on server with given parameters

  Specified by:
    `connect` in interface `ConnectionMBean`
  Specified by:
    `connect` in interface `IConnection`
  Overrides:
    `connect` in class `BaseConnection`
  Parameters:
    `newScope` - New scope
    `params` - Parameters to connect with
  Returns:
    true on success, false otherwise

### setup

    public void setup(String host,
                      String path,
                      String sessionId,
                      Map<String,Object> params)

  Initialize connection.

  Parameters:
    `host` - Connection host
    `path` - Connection path
    `sessionId` - Connection session id
    `params` - Params passed from client

### getEncoding

    public IConnection.Encoding getEncoding()

  Return AMF protocol encoding used by this connection.

  Specified by:
    `getEncoding` in interface `IConnection`
  Returns:
    AMF encoding used by connection

### getNextAvailableChannelId

    public int getNextAvailableChannelId()

  Getter for next available channel id.

  Returns:
    Next available channel id

### isChannelUsed

    public boolean isChannelUsed(int channelId)

  Checks whether channel is used.

  Parameters:
    `channelId` - Channel id
  Returns:
    `true` if channel is in use, `false` otherwise

### getChannel

    public Channel getChannel(int channelId)

  Return channel by id.

  Parameters:
    `channelId` - Channel id
  Returns:
    Channel by id

### closeChannel

    public void closeChannel(int channelId)

  Closes channel.

  Parameters:
    `channelId` - Channel id

### getStreams

    protected Collection<IClientStream> getStreams()

  Getter for client streams.

  Returns:
    Client streams as array

### reserveStreamId

    public int reserveStreamId()

  Return a reserved stream id for use. According to FCS/FMS regulation, the base is 1.

  Specified by:
    `reserveStreamId` in interface `IStreamCapableConnection`
  Returns:
    Reserved stream id

### createOutputStream

    public OutputStream createOutputStream(int streamId)

  Creates output stream object from stream id. Output stream consists of audio, data and video channels.

  Parameters:
    `streamId` - Stream id
  Returns:
    Output stream object
  See Also:
    `OutputStream`

### newBroadcastStream

    public IClientBroadcastStream newBroadcastStream(int streamId)

  Create a broadcast stream.

  Specified by:
    `newBroadcastStream` in interface `IStreamCapableConnection`
  Parameters:
    `streamId` - Stream id
  Returns:
    New broadcast stream

### newSingleItemSubscriberStream

    public ISingleItemSubscriberStream newSingleItemSubscriberStream(int streamId)

  Create a stream that can play only one item. To be implemented.

  Specified by:
    `newSingleItemSubscriberStream` in interface `IStreamCapableConnection`
  Parameters:
    `streamId` - Stream id
  Returns:
    New subscriber stream that can play only one item

### newPlaylistSubscriberStream

    public IPlaylistSubscriberStream newPlaylistSubscriberStream(int streamId)

  Create a stream that can play a list.

  Specified by:
    `newPlaylistSubscriberStream` in interface `IStreamCapableConnection`
  Parameters:
    `streamId` - Stream id
  Returns:
    New stream that can play sequence of items

### addClientStream

    public void addClientStream(IClientStream stream)

### removeClientStream

    public void removeClientStream(int streamId)

### getUsedStreamCount

    protected int getUsedStreamCount()

  Getter for used stream count.

  Returns:
    Value for property 'usedStreamCount'.

### getStreamById

    public IClientStream getStreamById(int id)

  Get a stream by its id.

  Specified by:
    `getStreamById` in interface `IStreamCapableConnection`
  Parameters:
    `id` - Stream id
  Returns:
    Stream with given id

### getStreamIdForChannel

    public int getStreamIdForChannel(int channelId)

  Return stream id for given channel id.

  Parameters:
    `channelId` - Channel id
  Returns:
    ID of stream that channel belongs to

### getStreamByChannelId

    public IClientStream getStreamByChannelId(int channelId)

  Return stream by given channel id.

  Parameters:
    `channelId` - Channel id
  Returns:
    Stream that channel belongs to

### close

    public void close()

  Closes connection

  Specified by:
    `close` in interface `ConnectionMBean`
  Specified by:
    `close` in interface `IConnection`
  Overrides:
    `close` in class `BaseConnection`

### unreserveStreamId

    public void unreserveStreamId(int streamId)

  Unreserve this id for future use.

  Specified by:
    `unreserveStreamId` in interface `IStreamCapableConnection`
  Parameters:
    `streamId` - ID of stream to unreserve

### deleteStreamById

    public void deleteStreamById(int streamId)

  Deletes the stream with the given id.

  Specified by:
    `deleteStreamById` in interface `IStreamCapableConnection`
  Parameters:
    `streamId` - ID of stream to delete

### ping

    public void ping(Ping ping)

  Handler for ping event.

  Parameters:
    `ping` - Ping event context

### rawWrite

    public abstract void rawWrite(IoBuffer out)

  Write raw byte buffer.

  Parameters:
    `out` - IoBuffer

### write

    public abstract void write(Packet out)

  Write packet.

  Parameters:
    `out` - Packet

### updateBytesRead

    protected void updateBytesRead()

  Update number of bytes to read next value.

### receivedBytesRead

    public void receivedBytesRead(int bytes)

  Read number of received bytes.

  Parameters:
    `bytes` - Number of bytes

### getClientBytesRead

    public long getClientBytesRead()

  Get number of bytes the client reported to have received.

  Specified by:
    `getClientBytesRead` in interface `IConnection`
  Overrides:
    `getClientBytesRead` in class `BaseConnection`
  Returns:
    Number of bytes
  See Also:
    `BytesRead`

### invoke

    public void invoke(IServiceCall call)

  Invokes service using remoting call object

  Specified by:
    `invoke` in interface `IServiceCapableConnection`
  Parameters:
    `call` - Service call object

### getInvokeId

    public int getInvokeId()

  Generate next invoke id.

  Returns:
    Next invoke id for RPC

### registerPendingCall

    public void registerPendingCall(int invokeId,
                                    IPendingServiceCall call)

  Register pending call (remote function call that is yet to finish).

  Parameters:
    `invokeId` - Deferred operation id
    `call` - Call service

### invoke

    public void invoke(IServiceCall call,
                       int channel)

  Invoke service using call and channel

  Specified by:
    `invoke` in interface `IServiceCapableConnection`
  Parameters:
    `call` - Service call
    `channel` - Channel used

### invoke

    public void invoke(String method)

  Invoke method by name

  Specified by:
    `invoke` in interface `IServiceCapableConnection`
  Parameters:
    `method` - Called method name

### invoke

    public void invoke(String method,
                       Object[] params)

  Invoke method with parameters

  Specified by:
    `invoke` in interface `IServiceCapableConnection`
  Parameters:
    `method` - Method name
    `params` - Invocation parameters passed to method

### invoke

    public void invoke(String method,
                       IPendingServiceCallback callback)

  Invoke method by name with callback

  Specified by:
    `invoke` in interface `IServiceCapableConnection`
  Parameters:
    `method` - Called method name
    `callback` - Callback

### invoke

    public void invoke(String method,
                       Object[] params,
                       IPendingServiceCallback callback)

  Specified by:
    `invoke` in interface `IServiceCapableConnection`

### notify

    public void notify(IServiceCall call)

  Specified by:
    `notify` in interface `IServiceCapableConnection`

### notify

    public void notify(IServiceCall call,
                       int channel)

  Specified by:
    `notify` in interface `IServiceCapableConnection`

### notify

    public void notify(String method)

  Specified by:
    `notify` in interface `IServiceCapableConnection`

### notify

    public void notify(String method,
                       Object[] params)

  Specified by:
    `notify` in interface `IServiceCapableConnection`

### getReadBytes

    public long getReadBytes()

  Total number of bytes read from the connection.

  Specified by:
    `getReadBytes` in interface `ConnectionMBean`
  Specified by:
    `getReadBytes` in interface `IConnection`
  Specified by:
    `getReadBytes` in class `BaseConnection`
  Returns:
    bytes read

### getWrittenBytes

    public long getWrittenBytes()

  Total number of bytes written to the connection.

  Specified by:
    `getWrittenBytes` in interface `ConnectionMBean`
  Specified by:
    `getWrittenBytes` in interface `IConnection`
  Specified by:
    `getWrittenBytes` in class `BaseConnection`
  Returns:
    bytes written

### getPendingCall

    protected IPendingServiceCall getPendingCall(int invokeId)

  Get pending call service by id.

  Parameters:
    `invokeId` - Pending call service id
  Returns:
    Pending call service object

### retrievePendingCall

    protected IPendingServiceCall retrievePendingCall(int invokeId)

  Retrieve pending call service by id. The call will be removed afterwards.

  Parameters:
    `invokeId` - Pending call service id
  Returns:
    Pending call service object

### createStreamName

    protected String createStreamName()

  Generates new stream name.

  Returns:
    New stream name

### writingMessage

    protected void writingMessage(Packet message)

  Mark message as being written.

  Parameters:
    `message` - Message to mark

### messageReceived

    protected void messageReceived()

  Increases number of read messages by one. Updates number of bytes read.

### messageSent

    protected void messageSent(Packet message)

  Mark message as sent.

  Parameters:
    `message` - Message to mark

### messageDropped

    protected void messageDropped()

  Increases number of dropped messages.

### getPendingVideoMessages

    public long getPendingVideoMessages(int streamId)

  Total number of video messages that are pending to be sent to a stream.

  Specified by:
    `getPendingVideoMessages` in interface `IStreamCapableConnection`
  Overrides:
    `getPendingVideoMessages` in class `BaseConnection`
  Parameters:
    `streamId` - the id you want to know about
  Returns:
    pending messages for this streamId

### ping

    public void ping()

  Start measuring the roundtrip time for a packet on the connection.

  Specified by:
    `ping` in interface `ConnectionMBean`
  Specified by:
    `ping` in interface `IConnection`

### pingReceived

    protected void pingReceived(Ping pong)

  Marks that ping back was received.

  Parameters:
    `pong` - Ping object

### getLastPingTime

    public int getLastPingTime()

  Return roundtrip time of last ping command.

  Specified by:
    `getLastPingTime` in interface `ConnectionMBean`
  Specified by:
    `getLastPingTime` in interface `IConnection`
  Returns:
    roundtrip time in milliseconds

### setPingInterval

    public void setPingInterval(int pingInterval)

  Setter for ping interval.

  Parameters:
    `pingInterval` - Interval in ms to ping clients. Set to `0` to disable ghost detection code.

### setMaxInactivity

    public void setMaxInactivity(int maxInactivity)

  Setter for maximum inactivity.

  Parameters:
    `maxInactivity` - Maximum time in ms after which a client is disconnected in case of inactivity.

### startRoundTripMeasurement

    public void startRoundTripMeasurement()

  Starts measurement.

### setSchedulingService

    public void setSchedulingService(ISchedulingService schedulingService)

  Sets the scheduling service.

  Parameters:
    `schedulingService` - scheduling service

### onInactive

    protected abstract void onInactive()

  Inactive state event handler.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### registerDeferredResult

    protected void registerDeferredResult(DeferredResult result)

  Registers deferred result.

  Parameters:
    `result` - Result to register

### unregisterDeferredResult

    protected void unregisterDeferredResult(DeferredResult result)

  Unregister deferred result

  Parameters:
    `result` - Result to unregister

### rememberStreamBufferDuration

    protected void rememberStreamBufferDuration(int streamId,
                                                int bufferDuration)

### setMaxHandshakeTimeout

    public void setMaxHandshakeTimeout(int maxHandshakeTimeout)

  Set maximum time to wait for valid handshake in milliseconds.

  Parameters:
    `maxHandshakeTimeout` - Maximum time in milliseconds

### startWaitForHandshake

    protected void startWaitForHandshake(ISchedulingService service)

  Start waiting for a valid handshake.

  Parameters:
    `service` - The scheduling service to use

Copyright © 2006-2010 The Red5 Project