Class BaseRTMPClientHandler

  • All Implemented Interfaces:
    IRTMPClient, org.red5.server.net.rtmp.IRTMPHandler, org.red5.server.net.rtmp.message.Constants, org.red5.server.net.rtmp.status.StatusCodes
    Direct Known Subclasses:
    RTMPClient, RTMPTClient

    public abstract class BaseRTMPClientHandler
    extends org.red5.server.net.rtmp.BaseRTMPHandler
    implements IRTMPClient
    Base class for clients (RTMP and RTMPT)
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.red5.server.net.rtmp.message.Constants

        org.red5.server.net.rtmp.message.Constants.DataType
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected boolean bandwidthCheckDone
      Whether or not the bandwidth done has been invoked
      protected org.red5.server.net.rtmp.RTMPConnection conn
      Associated RTMP connection
      protected Map<String,​Object> connectionParams
      Connection parameters
      protected ScheduledExecutorService executor
      For handling threading / scheduling in the clients.
      protected String protocol
      Connection scheme / protocol
      protected boolean subscribed
      Whether or not the client is subscribed
      • 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
      • Fields inherited from interface org.red5.server.net.rtmp.status.StatusCodes

        APP_GC, APP_RESOURCE_LOWMEMORY, APP_SCRIPT_ERROR, APP_SCRIPT_WARNING, APP_SHUTDOWN, NC_CALL_BADVERSION, NC_CALL_FAILED, NC_CONNECT_APPSHUTDOWN, NC_CONNECT_CLOSED, NC_CONNECT_FAILED, NC_CONNECT_INVALID_APPLICATION, NC_CONNECT_REJECTED, NC_CONNECT_SUCCESS, NS_BUFFER_EMPTY, NS_CLEAR_FAILED, NS_CLEAR_SUCCESS, NS_DATA_START, NS_FAILED, NS_INVALID_ARGUMENT, NS_PAUSE_NOTIFY, NS_PLAY_COMPLETE, NS_PLAY_FAILED, NS_PLAY_FILE_STRUCTURE_INVALID, NS_PLAY_INSUFFICIENT_BW, NS_PLAY_NO_SUPPORTED_TRACK_FOUND, NS_PLAY_PUBLISHNOTIFY, NS_PLAY_RESET, NS_PLAY_START, NS_PLAY_STOP, NS_PLAY_STREAMNOTFOUND, NS_PLAY_SWITCH, NS_PLAY_TRANSITION, NS_PLAY_TRANSITION_COMPLETE, NS_PLAY_UNPUBLISHNOTIFY, NS_PUBLISH_BADNAME, NS_PUBLISH_START, NS_RECORD_FAILED, NS_RECORD_NOACCESS, NS_RECORD_START, NS_RECORD_STOP, NS_SEEK_FAILED, NS_SEEK_NOTIFY, NS_TRANSITION_FORCED, NS_TRANSITION_SUCCESS, NS_UNPAUSE_NOTIFY, NS_UNPUBLISHED_SUCCESS, SO_CREATION_FAILED, SO_NO_READ_ACCESS, SO_NO_WRITE_ACCESS, SO_PERSISTENCE_MISMATCH
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void connect​(String server, int port, String application)
      Connect RTMP client to server's application via given port
      void connect​(String server, int port, String application, org.red5.server.api.service.IPendingServiceCallback connectCallback)
      Connect RTMP client to server's application via given port with given connection callback
      void connect​(String server, int port, Map<String,​Object> connectionParams)
      Connect RTMP client to server via given port and with given connection parameters
      void connect​(String server, int port, Map<String,​Object> connectionParams, org.red5.server.api.service.IPendingServiceCallback connectCallback)
      Connect RTMP client to server's application via given port
      void connect​(String server, int port, Map<String,​Object> connectionParams, org.red5.server.api.service.IPendingServiceCallback connectCallback, Object[] connectCallArguments)
      Connect RTMP client to server's application via given port
      void connectionClosed​(org.red5.server.net.rtmp.RTMPConnection conn)  
      void connectionOpened​(org.red5.server.net.rtmp.RTMPConnection conn)
      void createStream​(org.red5.server.api.service.IPendingServiceCallback callback)  
      void deleteStream​(org.red5.server.api.service.IPendingServiceCallback callback)  
      void disconnect()
      Disconnect the first connection in the connection map
      protected int getChannelForStreamId​(Number streamId)
      Returns a channel based on the given stream id.
      org.red5.server.net.rtmp.RTMPConnection getConnection()
      Returns the connection associated with this client.
      Map<String,​Object> getConnectionParams()  
      org.red5.server.api.so.IClientSharedObject getSharedObject​(String name, boolean persistent)
      Connect to client shared object.
      void handleException​(Throwable throwable)
      Handle any exceptions that occur.
      void invoke​(String method, Object[] params, org.red5.server.api.service.IPendingServiceCallback callback)
      Invoke a method on the server and pass parameters.
      void invoke​(String method, org.red5.server.api.service.IPendingServiceCallback callback)
      Invoke a method on the server.
      boolean isBandwidthCheckDone()
      Returns true if bandwidth done has been invoked
      boolean isSubscribed()
      Returns true if this client is subscribed
      boolean isSwfVerification()
      Returns true if swf verification is enabled
      Map<String,​Object> makeDefaultConnectionParams​(String server, int port, String application)
      Creates the default connection parameters collection.
      void onBWCheck()
      Called when negotiating bandwidth.
      void onBWCheck​(Object params)
      Called when negotiating bandwidth.
      void onBWDone()
      Called when bandwidth has been configured.
      void onBWDone​(Object params)
      Called when bandwidth has been configured.
      protected void onChunkSize​(org.red5.server.net.rtmp.RTMPConnection conn, org.red5.server.net.rtmp.Channel channel, org.red5.server.net.rtmp.message.Header source, org.red5.server.net.rtmp.event.ChunkSize chunkSize)
      protected void onClientBandwidth​(org.red5.server.net.rtmp.RTMPConnection conn, org.red5.server.net.rtmp.Channel channel, org.red5.server.net.rtmp.event.ClientBW message)
      protected void onCommand​(org.red5.server.net.rtmp.RTMPConnection conn, org.red5.server.net.rtmp.Channel channel, org.red5.server.net.rtmp.message.Header source, org.red5.server.net.ICommand command)
      protected void onPing​(org.red5.server.net.rtmp.RTMPConnection conn, org.red5.server.net.rtmp.Channel channel, org.red5.server.net.rtmp.message.Header source, org.red5.server.net.rtmp.event.Ping ping)
      protected void onServerBandwidth​(org.red5.server.net.rtmp.RTMPConnection conn, org.red5.server.net.rtmp.Channel channel, org.red5.server.net.rtmp.event.ServerBW message)
      protected void onSharedObject​(org.red5.server.net.rtmp.RTMPConnection conn, org.red5.server.net.rtmp.Channel channel, org.red5.server.net.rtmp.message.Header source, org.red5.server.so.SharedObjectMessage object)
      void ping​(short pingType, Number streamId, int param)
      Sends a ping.
      void play​(Number streamId, String name, int start, int length)  
      void play2​(Number streamId, Map<String,​?> playOptions)
      Dynamic streaming play method.
      void publish​(Number streamId, String name, String mode, INetStreamEventHandler handler)  
      void publishStreamData​(Number streamId, org.red5.server.messaging.IMessage message)  
      void releaseStream​(org.red5.server.api.service.IPendingServiceCallback callback, Object[] params)  
      void setConnection​(org.red5.server.net.rtmp.RTMPConnection conn)
      Sets a reference to the connection associated with this client handler.
      void setConnectionClosedHandler​(Runnable connectionClosedHandler)
      Sets a handler for connection close.
      void setExceptionHandler​(ClientExceptionHandler exceptionHandler)
      Sets a handler for exceptions.
      void setProtocol​(String protocol)
      Sets the protocol.
      void setServiceProvider​(Object serviceProvider)
      Register object that provides methods that can be called by the server.
      void setStreamEventDispatcher​(org.red5.server.api.event.IEventDispatcher streamEventDispatcher)
      Setter for stream event dispatcher (useful for saving playing stream to file)
      void setStreamEventHandler​(INetStreamEventHandler streamEventHandler)
      Setter for the stream event handler.
      void setSwfVerification​(boolean enabled)
      Enables or disables SWF verification.
      protected abstract void startConnector​(String server, int port)
      Start network connection to server
      void subscribe​(org.red5.server.api.service.IPendingServiceCallback callback, Object[] params)  
      void unpublish​(Number streamId)  
      • Methods inherited from class org.red5.server.net.rtmp.BaseRTMPHandler

        getHostname, handlePendingCallResult, messageReceived, messageSent, onStreamBytesRead
    • Field Detail

      • protocol

        protected String protocol
        Connection scheme / protocol
      • connectionParams

        protected Map<String,​Object> connectionParams
        Connection parameters
      • conn

        protected volatile org.red5.server.net.rtmp.RTMPConnection conn
        Associated RTMP connection
      • bandwidthCheckDone

        protected boolean bandwidthCheckDone
        Whether or not the bandwidth done has been invoked
      • subscribed

        protected boolean subscribed
        Whether or not the client is subscribed
    • Constructor Detail

      • BaseRTMPClientHandler

        protected BaseRTMPClientHandler()
    • Method Detail

      • startConnector

        protected abstract void startConnector​(String server,
                                               int port)
        Start network connection to server
        Parameters:
        server - Server
        port - Connection port
      • connect

        public void connect​(String server,
                            int port,
                            String application)
        Connect RTMP client to server's application via given port
        Specified by:
        connect in interface IRTMPClient
        Parameters:
        server - Server
        port - Connection port
        application - Application at that server
      • connect

        public void connect​(String server,
                            int port,
                            String application,
                            org.red5.server.api.service.IPendingServiceCallback connectCallback)
        Connect RTMP client to server's application via given port with given connection callback
        Specified by:
        connect in interface IRTMPClient
        Parameters:
        server - Server
        port - Connection port
        application - Application at that server
        connectCallback - Connection callback
      • makeDefaultConnectionParams

        public Map<String,​Object> makeDefaultConnectionParams​(String server,
                                                                    int port,
                                                                    String application)
        Creates the default connection parameters collection. Many implementations of this handler will create a tcUrl if not found, it is created with the current server url.
        Specified by:
        makeDefaultConnectionParams in interface IRTMPClient
        Parameters:
        server - the server location
        port - the port for the protocol
        application - the application name at the given server
        Returns:
        connection parameters map
      • connect

        public void connect​(String server,
                            int port,
                            Map<String,​Object> connectionParams)
        Connect RTMP client to server via given port and with given connection parameters
        Specified by:
        connect in interface IRTMPClient
        Parameters:
        server - Server
        port - Connection port
        connectionParams - Connection parameters
      • connect

        public void connect​(String server,
                            int port,
                            Map<String,​Object> connectionParams,
                            org.red5.server.api.service.IPendingServiceCallback connectCallback)
        Connect RTMP client to server's application via given port
        Specified by:
        connect in interface IRTMPClient
        Parameters:
        server - Server
        port - Connection port
        connectionParams - Connection parameters
        connectCallback - Connection callback
      • connect

        public void connect​(String server,
                            int port,
                            Map<String,​Object> connectionParams,
                            org.red5.server.api.service.IPendingServiceCallback connectCallback,
                            Object[] connectCallArguments)
        Connect RTMP client to server's application via given port
        Specified by:
        connect in interface IRTMPClient
        Parameters:
        server - Server
        port - Connection port
        connectionParams - Connection parameters
        connectCallback - Connection callback
        connectCallArguments - Arguments for 'connect' call
      • setServiceProvider

        public void setServiceProvider​(Object serviceProvider)
        Register object that provides methods that can be called by the server.
        Specified by:
        setServiceProvider in interface IRTMPClient
        Parameters:
        serviceProvider - Service provider
      • setConnectionClosedHandler

        public void setConnectionClosedHandler​(Runnable connectionClosedHandler)
        Sets a handler for connection close.
        Specified by:
        setConnectionClosedHandler in interface IRTMPClient
        Parameters:
        connectionClosedHandler - close handler
      • getSharedObject

        public org.red5.server.api.so.IClientSharedObject getSharedObject​(String name,
                                                                          boolean persistent)
        Connect to client shared object.
        Specified by:
        getSharedObject in interface IRTMPClient
        Parameters:
        name - Client shared object name
        persistent - SO persistence flag
        Returns:
        Client shared object instance
      • onChunkSize

        protected void onChunkSize​(org.red5.server.net.rtmp.RTMPConnection conn,
                                   org.red5.server.net.rtmp.Channel channel,
                                   org.red5.server.net.rtmp.message.Header source,
                                   org.red5.server.net.rtmp.event.ChunkSize chunkSize)
        Specified by:
        onChunkSize in class org.red5.server.net.rtmp.BaseRTMPHandler
      • onPing

        protected void onPing​(org.red5.server.net.rtmp.RTMPConnection conn,
                              org.red5.server.net.rtmp.Channel channel,
                              org.red5.server.net.rtmp.message.Header source,
                              org.red5.server.net.rtmp.event.Ping ping)
        Specified by:
        onPing in class org.red5.server.net.rtmp.BaseRTMPHandler
      • onServerBandwidth

        protected void onServerBandwidth​(org.red5.server.net.rtmp.RTMPConnection conn,
                                         org.red5.server.net.rtmp.Channel channel,
                                         org.red5.server.net.rtmp.event.ServerBW message)
        Overrides:
        onServerBandwidth in class org.red5.server.net.rtmp.BaseRTMPHandler
      • onClientBandwidth

        protected void onClientBandwidth​(org.red5.server.net.rtmp.RTMPConnection conn,
                                         org.red5.server.net.rtmp.Channel channel,
                                         org.red5.server.net.rtmp.event.ClientBW message)
        Overrides:
        onClientBandwidth in class org.red5.server.net.rtmp.BaseRTMPHandler
      • onSharedObject

        protected void onSharedObject​(org.red5.server.net.rtmp.RTMPConnection conn,
                                      org.red5.server.net.rtmp.Channel channel,
                                      org.red5.server.net.rtmp.message.Header source,
                                      org.red5.server.so.SharedObjectMessage object)
        Specified by:
        onSharedObject in class org.red5.server.net.rtmp.BaseRTMPHandler
      • onBWCheck

        public void onBWCheck()
        Called when negotiating bandwidth.
      • onBWCheck

        public void onBWCheck​(Object params)
        Called when negotiating bandwidth.
        Parameters:
        params - bw parameters
      • onBWDone

        public void onBWDone​(Object params)
        Called when bandwidth has been configured.
        Parameters:
        params - bw parameters
      • onBWDone

        public void onBWDone()
        Called when bandwidth has been configured.
      • invoke

        public void invoke​(String method,
                           org.red5.server.api.service.IPendingServiceCallback callback)
        Invoke a method on the server.
        Specified by:
        invoke in interface IRTMPClient
        Parameters:
        method - Method name
        callback - Callback handler
      • invoke

        public void invoke​(String method,
                           Object[] params,
                           org.red5.server.api.service.IPendingServiceCallback callback)
        Invoke a method on the server and pass parameters.
        Specified by:
        invoke in interface IRTMPClient
        Parameters:
        method - Method
        params - Method call parameters
        callback - Callback object
      • disconnect

        public void disconnect()
        Disconnect the first connection in the connection map
        Specified by:
        disconnect in interface IRTMPClient
      • createStream

        public void createStream​(org.red5.server.api.service.IPendingServiceCallback callback)
        Specified by:
        createStream in interface IRTMPClient
      • releaseStream

        public void releaseStream​(org.red5.server.api.service.IPendingServiceCallback callback,
                                  Object[] params)
      • deleteStream

        public void deleteStream​(org.red5.server.api.service.IPendingServiceCallback callback)
      • subscribe

        public void subscribe​(org.red5.server.api.service.IPendingServiceCallback callback,
                              Object[] params)
      • publishStreamData

        public void publishStreamData​(Number streamId,
                                      org.red5.server.messaging.IMessage message)
        Specified by:
        publishStreamData in interface IRTMPClient
      • play2

        public void play2​(Number streamId,
                          Map<String,​?> playOptions)
        Dynamic streaming play method. The following properties are supported on the play options:
                 streamName: String. The name of the stream to play or the new stream to switch to.
                 oldStreamName: String. The name of the initial stream that needs to be switched out. This is not needed and ignored 
                                when play2 is used for just playing the stream and not switching to a new stream.
                 start: Number. The start time of the new stream to play, just as supported by the existing play API. and it has the 
                                same defaults. This is ignored when the method is called for switching (in other words, the transition 
                                is either NetStreamPlayTransition.SWITCH or NetStreamPlayTransitions.SWAP)
                 len: Number. The duration of the playback, just as supported by the existing play API and has the same defaults.
                 transition: String. The transition mode for the playback command. It could be one of the following:
                                     NetStreamPlayTransitions.RESET
                                     NetStreamPlayTransitions.APPEND
                                     NetStreamPlayTransitions.SWITCH
                                     NetStreamPlayTransitions.SWAP
         
        NetStreamPlayTransitions:
                     APPEND : String = "append" - Adds the stream to a playlist and begins playback with the first stream.
                     APPEND_AND_WAIT : String = "appendAndWait" - Builds a playlist without starting to play it from the first stream.
                     RESET : String = "reset" - Clears any previous play calls and plays the specified stream immediately.
                     RESUME : String = "resume" - Requests data from the new connection starting from the point at which the previous connection ended.
                     STOP : String = "stop" - Stops playing the streams in a playlist.
                     SWAP : String = "swap" - Replaces a content stream with a different content stream and maintains the rest of the playlist.
                     SWITCH : String = "switch" - Switches from playing one stream to another stream, typically with streams of the same content.
         
        Specified by:
        play2 in interface IRTMPClient
        See Also:
        ActionScript guide to dynamic streaming, NetStreamPlayTransitions
      • ping

        public void ping​(short pingType,
                         Number streamId,
                         int param)
        Sends a ping.
        Parameters:
        pingType - the type of ping
        streamId - streams id
        param - ping parameter
      • connectionOpened

        public void connectionOpened​(org.red5.server.net.rtmp.RTMPConnection conn)
        Specified by:
        connectionOpened in interface org.red5.server.net.rtmp.IRTMPHandler
        Overrides:
        connectionOpened in class org.red5.server.net.rtmp.BaseRTMPHandler
      • connectionClosed

        public void connectionClosed​(org.red5.server.net.rtmp.RTMPConnection conn)
        Specified by:
        connectionClosed in interface org.red5.server.net.rtmp.IRTMPHandler
        Overrides:
        connectionClosed in class org.red5.server.net.rtmp.BaseRTMPHandler
      • onCommand

        protected void onCommand​(org.red5.server.net.rtmp.RTMPConnection conn,
                                 org.red5.server.net.rtmp.Channel channel,
                                 org.red5.server.net.rtmp.message.Header source,
                                 org.red5.server.net.ICommand command)
        Specified by:
        onCommand in class org.red5.server.net.rtmp.BaseRTMPHandler
      • handleException

        public void handleException​(Throwable throwable)
        Handle any exceptions that occur.
        Parameters:
        throwable - Exception thrown
      • getChannelForStreamId

        protected int getChannelForStreamId​(Number streamId)
        Returns a channel based on the given stream id.
        Parameters:
        streamId - stream id
        Returns:
        the channel for this stream id
      • setProtocol

        public void setProtocol​(String protocol)
                         throws Exception
        Sets the protocol.
        Parameters:
        protocol - the data protocol to use.
        Throws:
        Exception - thrown
      • setConnection

        public void setConnection​(org.red5.server.net.rtmp.RTMPConnection conn)
        Sets a reference to the connection associated with this client handler.
        Parameters:
        conn - connection
      • getConnection

        public org.red5.server.net.rtmp.RTMPConnection getConnection()
        Returns the connection associated with this client.
        Specified by:
        getConnection in interface IRTMPClient
        Returns:
        conn connection
      • setSwfVerification

        public void setSwfVerification​(boolean enabled)
        Enables or disables SWF verification.
        Parameters:
        enabled - state of SWF verification
      • isSwfVerification

        public boolean isSwfVerification()
        Returns true if swf verification is enabled
        Returns:
        the swfVerification
      • isBandwidthCheckDone

        public boolean isBandwidthCheckDone()
        Returns true if bandwidth done has been invoked
        Returns:
        the bandwidthCheckDone
      • isSubscribed

        public boolean isSubscribed()
        Returns true if this client is subscribed
        Returns:
        subscribed state
      • getConnectionParams

        public Map<String,​Object> getConnectionParams()
        Returns:
        the connectionParams
      • setStreamEventDispatcher

        public void setStreamEventDispatcher​(org.red5.server.api.event.IEventDispatcher streamEventDispatcher)
        Setter for stream event dispatcher (useful for saving playing stream to file)
        Specified by:
        setStreamEventDispatcher in interface IRTMPClient
        Parameters:
        streamEventDispatcher - event dispatcher
      • setStreamEventHandler

        public void setStreamEventHandler​(INetStreamEventHandler streamEventHandler)
        Setter for the stream event handler.
        Parameters:
        streamEventHandler - event handler