public abstract class RTMPConnection extends BaseConnection implements IStreamCapableConnection, IServiceCapableConnection, IReceivedMessageTaskQueueListener
IConnection.Duty, IConnection.Encoding, IConnection.Type| Modifier and Type | Field and Description |
|---|---|
protected long |
bytesReadInterval
Data read interval
|
protected ThreadPoolTaskScheduler |
deadlockGuardScheduler
Thread pool for guarding deadlocks.
|
protected Semaphore |
decoderLock |
protected RTMPDecodeState |
decoderState |
protected Semaphore |
encoderLock |
protected ThreadPoolTaskExecutor |
executor
Thread pool for message handling.
|
protected IRTMPHandler |
handler
RTMP events handler
|
protected int |
limitType
Bandwidth limit type / enforcement.
|
static double |
MAX_RESERVED_STREAMS |
protected long |
maxHandlingTimeout
Maximum time in milliseconds allowed to process received message
|
protected int |
maxInactivity
Maximum time in ms after which a client is disconnected because of inactivity.
|
protected long |
nextBytesRead
Number of bytes to read next.
|
static String |
RTMP_CONN_MANAGER |
static byte |
RTMP_ENCRYPTED
Marker byte for encrypted RTMP data.
|
static byte |
RTMP_ENCRYPTED_BLOWFISH
Marker byte for encrypted RTMP data using Blowfish.
|
static byte |
RTMP_ENCRYPTED_UNK
Unknown type 0x0a, seen on youtube
|
static byte |
RTMP_ENCRYPTED_XTEA
Marker byte for encrypted RTMP data XTEA.
|
static Object |
RTMP_HANDLER |
static String |
RTMP_HANDSHAKE |
static byte |
RTMP_NON_ENCRYPTED
Marker byte for standard or non-encrypted RTMP data.
|
static String |
RTMP_SESSION_ID |
static String |
RTMPE_CIPHER_IN
Cipher for RTMPE input
|
static String |
RTMPE_CIPHER_OUT
Cipher for RTMPE output
|
protected AtomicBoolean |
running
Keep-alive worker flag
|
protected ThreadPoolTaskScheduler |
scheduler
Scheduling service
|
protected RTMP |
state
Protocol state
|
basicScopes, client, connectionListeners, droppedMessages, duty, host, params, path, readMessages, remoteAddress, remoteAddresses, remotePort, scope, sessionId, type, writtenMessagesattributes| Constructor and Description |
|---|
RTMPConnection(String type)
Creates anonymous RTMP connection without scope.
|
| Modifier and Type | Method and Description |
|---|---|
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(Number streamId)
Creates output stream object from stream id.
|
protected String |
createStreamName()
Generates new stream name.
|
protected int |
currentQueueSize()
Returns the current received message queue size.
|
void |
deleteStreamById(Number streamId)
Deletes the stream with the given id.
|
void |
dispatchEvent(IEvent event)
Dispatches event
|
Channel |
getChannel(int channelId)
Return channel by id.
|
int |
getChannelIdForStreamId(Number streamId)
Return channel id for given stream id.
|
int |
getChannelsConcurrencyLevel() |
int |
getChannelsInitalCapacity() |
long |
getClientBytesRead()
Get number of bytes the client reported to have received.
|
ThreadPoolTaskScheduler |
getDeadlockGuardScheduler()
Thread pool for guarding deadlocks
|
Semaphore |
getDecoderLock() |
RTMPDecodeState |
getDecoderState() |
Semaphore |
getEncoderLock() |
IConnection.Encoding |
getEncoding()
Return AMF protocol encoding used by this connection.
|
ThreadPoolTaskExecutor |
getExecutor() |
IRTMPHandler |
getHandler() |
int |
getId() |
org.apache.mina.core.session.IoSession |
getIoSession() |
int |
getLastPingSentAndLastPongReceivedInterval()
Difference between when the last ping was sent and when the last pong was received.
|
int |
getLastPingTime()
Return round-trip time of last ping command.
|
long |
getMaxHandlingTimeout() |
int |
getNextAvailableChannelId()
Getter for next available channel id.
|
IPendingServiceCall |
getPendingCall(int invokeId)
Get pending call service by id.
|
int |
getPendingCallsConcurrencyLevel() |
int |
getPendingCallsInitalCapacity() |
long |
getPendingVideoMessages(Number streamId)
Count of outgoing video messages not yet written.
|
String |
getProtocol()
Returns the protocol type for this connection.
|
long |
getReadBytes()
Total number of bytes read from the connection.
|
int |
getReservedStreamsConcurrencyLevel() |
int |
getReservedStreamsInitalCapacity() |
ThreadPoolTaskScheduler |
getScheduler() |
RTMP |
getState() |
byte |
getStateCode() |
IClientStream |
getStreamByChannelId(int channelId)
Return stream by given channel id.
|
IClientStream |
getStreamById(Number streamId)
Get a stream by its id.
|
Number |
getStreamIdForChannelId(int channelId)
Return stream id for given channel id.
|
protected Collection<IClientStream> |
getStreams()
Getter for client streams.
|
int |
getStreamsConcurrencyLevel() |
int |
getStreamsInitalCapacity() |
Map<Number,IClientStream> |
getStreamsMap() |
int |
getTimer()
Returns a usable timestamp for written packets.
|
int |
getTransactionId()
Generate next invoke id.
|
protected int |
getUsedStreamCount()
Getter for used stream count.
|
long |
getWrittenBytes()
Total number of bytes written to the connection.
|
void |
handleMessageReceived(Packet packet)
Handle the incoming message.
|
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)
Invoke method with parameters.
|
boolean |
isChannelUsed(int channelId)
Checks whether channel is used.
|
boolean |
isDisconnected()
Returns whether or not the connection is disconnected.
|
boolean |
isIdle()
Returns whether or not the connection has been idle for a maximum period.
|
boolean |
isValidStreamId(Number streamId)
Returns whether or not a given stream id is valid.
|
protected void |
messageDropped()
Increases number of dropped messages.
|
void |
messageReceived()
Increases number of read messages by one.
|
void |
messageSent(Packet message)
Mark message as sent.
|
String |
messageTypeToName(byte headerDataType) |
IClientBroadcastStream |
newBroadcastStream(Number streamId)
Create a broadcast stream.
|
IPlaylistSubscriberStream |
newPlaylistSubscriberStream(Number streamId)
Create a stream that can play a list.
|
ISingleItemSubscriberStream |
newSingleItemSubscriberStream(Number streamId)
Create a stream that can play only one item.
|
void |
notify(IServiceCall call)
Notify method.
|
void |
notify(IServiceCall call,
int channel)
Notify method with channel id.
|
void |
notify(String method)
Notify method.
|
void |
notify(String method,
Object[] params)
Notify method with parameters.
|
protected abstract void |
onInactive()
Inactive state event handler.
|
void |
onTaskAdded(ReceivedMessageTaskQueue queue) |
void |
onTaskRemoved(ReceivedMessageTaskQueue queue) |
void |
open()
Opens the connection.
|
void |
ping()
Start measuring the round-trip time for a packet on the connection.
|
void |
ping(Ping ping)
Handler for ping event.
|
void |
pingReceived(Ping pong)
Marks that ping back was received.
|
void |
receivedBytesRead(int bytes)
Read number of received bytes.
|
void |
registerDeferredResult(DeferredResult result)
Registers deferred result.
|
void |
registerPendingCall(int invokeId,
IPendingServiceCall call)
Register pending call (remote function call that is yet to finish).
|
void |
rememberStreamBufferDuration(int streamId,
int bufferDuration) |
void |
removeClientStream(Number streamId) |
Number |
reserveStreamId()
Return a reserved stream id for use.
|
Number |
reserveStreamId(Number streamId)
Return a reserved stream id for use with a preference for the one supplied.
|
IPendingServiceCall |
retrievePendingCall(int invokeId)
Retrieves and removes the pending call service by id.
|
void |
sendPendingServiceCallsCloseError()
When the connection has been closed, notify any remaining pending service calls that they have failed because the connection is
broken.
|
void |
sendSharedObjectMessage(String name,
int currentVersion,
boolean persistent,
ConcurrentLinkedQueue<ISharedObjectEvent> events)
Send a shared object message.
|
void |
setBandwidth(int mbits)
Sets the bandwidth using a mbit/s value.
|
void |
setChannelsConcurrencyLevel(int channelsConcurrencyLevel) |
void |
setChannelsInitalCapacity(int channelsInitalCapacity) |
void |
setDeadlockGuardScheduler(ThreadPoolTaskScheduler deadlockGuardScheduler)
Thread pool for guarding deadlocks
|
void |
setExecutor(ThreadPoolTaskExecutor executor) |
void |
setExecutorQueueSizeToDropAudioPackets(Integer executorQueueSizeToDropAudioPackets)
Specify the size of queue that will trigger audio packet dropping, disabled if it's 0
|
void |
setHandler(IRTMPHandler handler) |
void |
setId(int clientId)
Deprecated.
|
void |
setMaxHandlingTimeout(long maxHandlingTimeout) |
void |
setMaxHandshakeTimeout(int maxHandshakeTimeout)
Set maximum time to wait for valid handshake in milliseconds.
|
void |
setMaxInactivity(int maxInactivity)
Setter for maximum inactivity.
|
void |
setPendingCallsConcurrencyLevel(int pendingCallsConcurrencyLevel) |
void |
setPendingCallsInitalCapacity(int pendingCallsInitalCapacity) |
void |
setPingInterval(int pingInterval)
Setter for ping interval.
|
void |
setReservedStreamsConcurrencyLevel(int reservedStreamsConcurrencyLevel) |
void |
setReservedStreamsInitalCapacity(int reservedStreamsInitalCapacity) |
void |
setScheduler(ThreadPoolTaskScheduler scheduler)
Sets the scheduler.
|
void |
setStateCode(byte code) |
void |
setStreamsConcurrencyLevel(int streamsConcurrencyLevel) |
void |
setStreamsInitalCapacity(int streamsInitalCapacity) |
void |
setup(String host,
String path,
Map<String,Object> params)
Initialize connection.
|
void |
startWaitForHandshake()
Start waiting for a valid handshake.
|
void |
status(Status status)
Sends a status object to the connection.
|
void |
status(Status status,
int channel)
Sends a status object to the connection on a given channel.
|
String |
toString() |
void |
unregisterDeferredResult(DeferredResult result)
Unregister deferred result
|
void |
unreserveStreamId(Number 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.
|
abstract void |
writeRaw(org.apache.mina.core.buffer.IoBuffer out)
Write raw byte buffer.
|
protected void |
writingMessage(Packet message)
Mark message as being written.
|
addListener, connect, equals, getBasicScopes, getClient, getConnectParams, getDroppedMessages, getDuty, getHost, getLock, getPath, getPendingMessages, getReadMessages, getRemoteAddress, getRemoteAddresses, getRemotePort, getScope, getSessionId, getStreamId, getType, getWrittenMessages, handleEvent, hashCode, initialize, isClosed, isConnected, isReaderIdle, isWriterIdle, notifyEvent, registerBasicScope, registerBasicScope, removeListener, setClient, setDuty, setStreamId, unregisterBasicScopefilterNull, from, getAttribute, getAttribute, getAttributeNames, getAttributes, getBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttribute, hasAttribute, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes, sizeclone, finalize, getClass, notify, notifyAll, wait, wait, waitaddListener, connect, getBasicScopes, getClient, getConnectParams, getDroppedMessages, getDuty, getHost, getPath, getPendingMessages, getReadMessages, getRemoteAddress, getRemoteAddresses, getRemotePort, getScope, getSessionId, getStreamId, getType, getWrittenMessages, initialize, isConnected, removeListener, setClient, setStreamIdhandleEventnotifyEventgetBoolAttribute, getByteAttribute, getDoubleAttribute, getIntAttribute, getListAttribute, getLongAttribute, getMapAttribute, getSetAttribute, getShortAttribute, getStringAttributegetAttribute, getAttribute, getAttributeNames, getAttributes, hasAttribute, removeAttribute, removeAttributes, setAttribute, setAttributes, setAttributes, sizepublic static final String RTMP_SESSION_ID
public static final String RTMP_HANDSHAKE
public static final String RTMP_CONN_MANAGER
public static final Object RTMP_HANDLER
public static final byte RTMP_NON_ENCRYPTED
public static final byte RTMP_ENCRYPTED
public static final byte RTMP_ENCRYPTED_XTEA
public static final byte RTMP_ENCRYPTED_BLOWFISH
public static final byte RTMP_ENCRYPTED_UNK
public static final String RTMPE_CIPHER_IN
public static final String RTMPE_CIPHER_OUT
public static final double MAX_RESERVED_STREAMS
protected transient IRTMPHandler handler
protected volatile int maxInactivity
protected long bytesReadInterval
protected long nextBytesRead
protected long maxHandlingTimeout
protected int limitType
protected RTMP state
protected transient Semaphore decoderLock
protected transient Semaphore encoderLock
protected transient RTMPDecodeState decoderState
protected transient ThreadPoolTaskScheduler scheduler
protected transient ThreadPoolTaskExecutor executor
protected transient ThreadPoolTaskScheduler deadlockGuardScheduler
protected final AtomicBoolean running
@ConstructorProperties(value="type") public RTMPConnection(String type)
type - Connection typepublic int getId()
@Deprecated public void setId(int clientId)
public void setHandler(IRTMPHandler handler)
public IRTMPHandler getHandler()
public RTMP getState()
public byte getStateCode()
public void setStateCode(byte code)
public org.apache.mina.core.session.IoSession getIoSession()
public Semaphore getDecoderLock()
public Semaphore getEncoderLock()
public RTMPDecodeState getDecoderState()
public void setBandwidth(int mbits)
setBandwidth in interface IConnectionmbits - targetpublic int getTimer()
public void open()
public boolean connect(IScope newScope, Object[] params)
BaseConnectionconnect in interface IConnectionconnect in class BaseConnectionnewScope - New scopeparams - Parameters to connect withpublic void startWaitForHandshake()
public void setup(String host, String path, Map<String,Object> params)
host - Connection hostpath - Connection pathparams - Params passed from clientpublic IConnection.Encoding getEncoding()
getEncoding in interface IConnectionpublic int getNextAvailableChannelId()
public boolean isChannelUsed(int channelId)
channelId - Channel idpublic Channel getChannel(int channelId)
channelId - Channel idpublic void closeChannel(int channelId)
channelId - Channel idprotected Collection<IClientStream> getStreams()
public Map<Number,IClientStream> getStreamsMap()
getStreamsMap in interface IStreamCapableConnectionpublic Number reserveStreamId()
reserveStreamId in interface IStreamCapableConnectionpublic Number reserveStreamId(Number streamId)
reserveStreamId in interface IStreamCapableConnectionstreamId - supplied stream idpublic boolean isValidStreamId(Number streamId)
streamId - stream idpublic boolean isIdle()
public boolean isDisconnected()
public IClientBroadcastStream newBroadcastStream(Number streamId)
newBroadcastStream in interface IStreamCapableConnectionstreamId - Stream idpublic ISingleItemSubscriberStream newSingleItemSubscriberStream(Number streamId)
newSingleItemSubscriberStream in interface IStreamCapableConnectionstreamId - Stream idpublic IPlaylistSubscriberStream newPlaylistSubscriberStream(Number streamId)
newPlaylistSubscriberStream in interface IStreamCapableConnectionstreamId - Stream idpublic void addClientStream(IClientStream stream)
public void removeClientStream(Number streamId)
protected int getUsedStreamCount()
public IClientStream getStreamById(Number streamId)
getStreamById in interface IStreamCapableConnectionstreamId - Stream idpublic Number getStreamIdForChannelId(int channelId)
channelId - Channel idpublic IClientStream getStreamByChannelId(int channelId)
channelId - Channel idpublic int getChannelIdForStreamId(Number streamId)
streamId - Stream idpublic OutputStream createOutputStream(Number streamId)
streamId - Stream idOutputStreampublic void close()
close in interface IConnectionclose in class BaseConnectionpublic void dispatchEvent(IEvent event)
dispatchEvent in interface IEventDispatcherdispatchEvent in class BaseConnectionevent - Eventpublic void sendPendingServiceCallsCloseError()
public void unreserveStreamId(Number streamId)
unreserveStreamId in interface IStreamCapableConnectionstreamId - ID of stream to unreservepublic void deleteStreamById(Number streamId)
deleteStreamById in interface IStreamCapableConnectionstreamId - ID of stream to deletepublic void ping(Ping ping)
ping - Ping event contextpublic abstract void write(Packet out)
out - Packetpublic abstract void writeRaw(org.apache.mina.core.buffer.IoBuffer out)
out - IoBufferprotected void updateBytesRead()
public void receivedBytesRead(int bytes)
bytes - Number of bytespublic long getClientBytesRead()
getClientBytesRead in interface IConnectiongetClientBytesRead in class BaseConnectionBytesReadpublic void invoke(IServiceCall call)
invoke in interface IServiceCapableConnectioncall - Service call objectpublic int getTransactionId()
public void registerPendingCall(int invokeId,
IPendingServiceCall call)
invokeId - Deferred operation idcall - Call servicepublic void invoke(IServiceCall call, int channel)
invoke in interface IServiceCapableConnectioncall - Service callchannel - Channel usedpublic void invoke(String method)
invoke in interface IServiceCapableConnectionmethod - Called method namepublic void invoke(String method, Object[] params)
invoke in interface IServiceCapableConnectionmethod - Method nameparams - Invocation parameters passed to methodpublic void invoke(String method, IPendingServiceCallback callback)
invoke in interface IServiceCapableConnectionmethod - Called method namecallback - Callbackpublic void invoke(String method, Object[] params, IPendingServiceCallback callback)
invoke in interface IServiceCapableConnectionmethod - by nameparams - method paramscallback - callbackpublic void notify(IServiceCall call)
notify in interface IServiceCapableConnectioncall - service callpublic void notify(IServiceCall call, int channel)
notify in interface IServiceCapableConnectioncall - service callchannel - channel idpublic void notify(String method)
notify in interface IServiceCapableConnectionmethod - by namepublic void notify(String method, Object[] params)
notify in interface IServiceCapableConnectionmethod - by nameparams - method paramspublic void status(Status status)
status in interface IServiceCapableConnectionstatus - Statuspublic void status(Status status, int channel)
status in interface IServiceCapableConnectionstatus - Statuschannel - channel idpublic long getReadBytes()
getReadBytes in interface IConnectiongetReadBytes in class BaseConnectionpublic long getWrittenBytes()
getWrittenBytes in interface IConnectiongetWrittenBytes in class BaseConnectionpublic IPendingServiceCall getPendingCall(int invokeId)
invokeId - Pending call service idpublic IPendingServiceCall retrievePendingCall(int invokeId)
invokeId - Pending call service idprotected String createStreamName()
protected void writingMessage(Packet message)
message - Message to markpublic void messageReceived()
public String messageTypeToName(byte headerDataType)
public void handleMessageReceived(Packet packet)
packet - incoming message packetpublic void onTaskAdded(ReceivedMessageTaskQueue queue)
onTaskAdded in interface IReceivedMessageTaskQueueListenerpublic void onTaskRemoved(ReceivedMessageTaskQueue queue)
onTaskRemoved in interface IReceivedMessageTaskQueueListenerpublic void messageSent(Packet message)
message - Message to markprotected void messageDropped()
protected int currentQueueSize()
public long getPendingVideoMessages(Number streamId)
getPendingVideoMessages in interface IStreamCapableConnectiongetPendingVideoMessages in class BaseConnectionstreamId - the id you want to know aboutpublic void sendSharedObjectMessage(String name, int currentVersion, boolean persistent, ConcurrentLinkedQueue<ISharedObjectEvent> events)
name - shared object namecurrentVersion - the current versionpersistent - toggleevents - shared object eventspublic void ping()
ping in interface IConnectionpublic void pingReceived(Ping pong)
pong - Ping objectpublic int getLastPingSentAndLastPongReceivedInterval()
public int getLastPingTime()
getLastPingTime in interface IConnectionpublic void setPingInterval(int pingInterval)
pingInterval - Interval in ms to ping clients. Set to 0 to disable ghost detection code.public void setMaxInactivity(int maxInactivity)
maxInactivity - Maximum time in ms after which a client is disconnected in case of inactivity.protected abstract void onInactive()
public void setScheduler(ThreadPoolTaskScheduler scheduler)
scheduler - scheduling service / thread executorpublic ThreadPoolTaskScheduler getScheduler()
public ThreadPoolTaskExecutor getExecutor()
public void setExecutor(ThreadPoolTaskExecutor executor)
public ThreadPoolTaskScheduler getDeadlockGuardScheduler()
public void setDeadlockGuardScheduler(ThreadPoolTaskScheduler deadlockGuardScheduler)
deadlockGuardScheduler - the deadlockGuardScheduler to setpublic void registerDeferredResult(DeferredResult result)
result - Result to registerpublic void unregisterDeferredResult(DeferredResult result)
result - Result to unregisterpublic void rememberStreamBufferDuration(int streamId,
int bufferDuration)
public void setMaxHandshakeTimeout(int maxHandshakeTimeout)
maxHandshakeTimeout - Maximum time in millisecondspublic long getMaxHandlingTimeout()
public void setMaxHandlingTimeout(long maxHandlingTimeout)
public int getChannelsInitalCapacity()
public void setChannelsInitalCapacity(int channelsInitalCapacity)
public int getChannelsConcurrencyLevel()
public void setChannelsConcurrencyLevel(int channelsConcurrencyLevel)
public int getStreamsInitalCapacity()
public void setStreamsInitalCapacity(int streamsInitalCapacity)
public int getStreamsConcurrencyLevel()
public void setStreamsConcurrencyLevel(int streamsConcurrencyLevel)
public int getPendingCallsInitalCapacity()
public void setPendingCallsInitalCapacity(int pendingCallsInitalCapacity)
public int getPendingCallsConcurrencyLevel()
public void setPendingCallsConcurrencyLevel(int pendingCallsConcurrencyLevel)
public int getReservedStreamsInitalCapacity()
public void setReservedStreamsInitalCapacity(int reservedStreamsInitalCapacity)
public int getReservedStreamsConcurrencyLevel()
public void setReservedStreamsConcurrencyLevel(int reservedStreamsConcurrencyLevel)
public void setExecutorQueueSizeToDropAudioPackets(Integer executorQueueSizeToDropAudioPackets)
executorQueueSizeToDropAudioPackets - queue sizepublic String getProtocol()
IConnectiongetProtocol in interface IConnectionCopyright © 2005–2017 Red5. All rights reserved.