de.humatic.dsj.src
Class RTMPSource

java.lang.Object
  extended by de.humatic.dsj.src.Source
      extended by de.humatic.dsj.src.NetworkSource
          extended by de.humatic.dsj.src.RTMPSource

public class RTMPSource
extends NetworkSource

Source to read data from a rtmp connection as used by Flash for the transport of audio, video and shared objects.
dsj 0_8_62 adds support for rtmp tunnelled via http (use a rtmpt:// path).
The source currently supports FLV1 (Sorenson Spark / H263) & FLV4 (On2 VP6) videostreams with mp3 & Nellymoser audio as well as H264 mp4 streams with AAC or mp3 audio. dsj 0_8_6 adds support for flv tagged data over rtmp as used with .f4v streams.
Please note that all these formats require decoder filters to be installed. ffdShow / libavcodec should handle all formats to be encountered and is explicitely required for Nellymoser audio. Other formats will also work with other decoders.
This class supports plain unencrypted RTMP only and may be used for receiving streaming video, audio and/or data content for display only. Intercepting RTMP streams for storage on any kind of medium as well as attempting to break copy-protection measures on RTMP delivered content is not allowed under dsj licensing terms.


Nested Class Summary
 class RTMPSource.SharedObject
          SharedObjects are both Flash's equivalent to cookies as well as a means for data persistance and data exchange between FMS clients.
 
Field Summary
static int INTERACTIVE
          Source flags
static int IS_SINK
          Source flags
static int NO_STREAM
          Source flags
static int RS_CONNECTED
          RTMP Connection states
static int RS_CREATE_STREAM
          RTMP Connection states
static int RS_GOT_STR_LENGTH
          RTMP Connection states
static int RS_HANDSHAKE_DONE
          RTMP Connection states
static int RS_QUERY_STR_LENGTH
          RTMP Connection states
static int RS_REQUEST_PLAY
          RTMP Connection states
static int RS_STREAM_CREATED
          RTMP Connection states
static java.lang.String STR_FALSE
           
static java.lang.String STR_TRUE
           
static java.lang.String STR_UNDEFINED
           
 
Fields inherited from class de.humatic.dsj.src.NetworkSource
BUFFER_OVERFLOW, CONNECTION_TIMEOUT, FASTSTART, H264_FASTSTART, H264_FORCE_INLINE_SPS, H264_OMMIT_SPS, H264_PASS_INLINE_SPS, IDLE_TIMEOUT, KF_NOTIFY, LIVE_SRC, MAX_BUFFER_TIME, MAX_DURATION, MAX_FRAME_TIME, NO_USER_PROMPT, READ_USER_DATA, RECEIVE_TIMEOUT, RTCP_RECEIVE_ERROR, SEEK_FAILURE, SOCKET_ERROR, STARVING, UDP_UNCONNECTED
 
Fields inherited from class de.humatic.dsj.src.Source
ASYNC, AUTO_GC, DIRECT, ES, FILTER_SETUP_ERROR, FLV, HTTP, HTTP_AUDIO, JAS, MJPG, MKV, MP4, PSNET, PULL, PUSH, RAW, RTMP, RTP, RTSP, SHOUTCAST, SS_CLOSED, SS_CONNECT, SS_CONNECTED, SS_DONE, SS_EOS, SS_FORMAT_READ, SS_RUNNING, SS_SEEKING, SS_SETUP, SS_STREAMS_READ, SS_TCP_ROLLOVER, TIMEOUT, TSFILE, TSNET, UNKNOWN
 
Constructor Summary
RTMPSource(java.lang.String ip, int port, java.lang.String serverApp, java.lang.String resourceName, ConnectionParameter[] connectionParams, int flags, java.beans.PropertyChangeListener listener)
          Creates a RTMPSource and connects to the given server application running on the host at %ip, requesting the given resource.
RTMPSource(java.lang.String ip, int port, java.lang.String serverApp, java.lang.String resourceName, java.beans.PropertyChangeListener listener)
          Creates a RTMPSource and connects to the given server application running on the host at %ip, requesting the given resource.
RTMPSource(java.lang.String appUrl, java.lang.String resourceName, ConnectionParameter[] connectionParams, int flags, java.beans.PropertyChangeListener listener)
          Creates a RTMPSource and connects to the server application at the given url, requesting %resource.
Extended parameters as given in %connectionParams will be passed to the NetStream.connect() method, eventually overwriting the defaults that dsj would send as a minimum requirement (flashVer, swfUrl, tcUrl, audioCodecs, videoCodecs, videoFunction and objectEncoding plus for mp4 streams fpad and capabilities).
RTMPSource(java.lang.String appUrl, java.lang.String resourceName, int flags, java.beans.PropertyChangeListener listener)
          Creates a RTMPSource and connects to the server application at the given url, requesting %resource.
 
Method Summary
 void closeSource(boolean terminate)
          Closes down the source.
 void connectionIntercept(int connectionState, java.lang.Object data)
          When set up with the INTERACTIVE flag, the source during connection will wait for a short time after issuing RTMP_STATE_CHANGED events and client code may call this method to have additional rtmp sent to the server.
%connectionState takes the current state that you react on as transferred in the value field of RTMP_STATE_CHANGED events.
%data should either be raw rtmp data in a byte array or a SharedObject.
 DSGraph createGraph(int graphFlags)
          Use this to create a filtergraph from the source.
 DSGraph createGraph(int graphFlags, DSFilterInfo videoDecoder, DSFilterInfo audioDecoder)
          Use this to create a filtergraph with the given decoders from the source.
 CompressedJavaSource createSourceFilter(int sf, DSMediaType mediaType)
          This is called by the various source implementations once they have determined, what kind of media they deal with etc.
It basically calls through to DSGraph.insertCompressedSourceFilter(...).
 int getEncoding()
           
 DSMediaType[] getMediaTypes()
          Returns the media types created by this source.
 int getMinBufferTime()
          Returns this Source's minimum buffer requirements in msec worth of data.
 RTMPSource.SharedObject getSharedObject(java.lang.String soName, java.lang.String path, int flags)
           
 int getSourceTime()
           
 void sendRTMP(byte[] msg)
           
 void sendRTMP(byte[] msg, int offset, int length)
           
 void sendRTMP(RTMPMessage msg)
           
 void setActionScriptHandler(java.lang.Object t)
          Application code can register a class as a handler for actionscript method calls from the server.
static void setClientStream(int streamID)
          Sets the client stream ID used when connecting to the server.
static void setEncoding(int amfVersion)
          Set AMF encoding (RTMP.AMF_0 or AMF_3).
static void setHandShakeData(byte[] hsd)
          Allows to set the initial 1536 bytes sent to the server during handshake.
static void setLocalPort(int port)
          Sets the local port used for connecting to the server, picked by the socket if not explicitely set.
static void setMinBufferTime(int time)
           
 void setSourceRate(float rate)
          Starts and pauses the source, application code should rather not use this method directly, but stick with DSFiltergraph methods.
 void setSourceTime(int time)
          Repositions the source, application code should rather not use this method directly, but stick with DSFiltergraph methods.
 
Methods inherited from class de.humatic.dsj.src.NetworkSource
configurePasswordDialog, getDefaultInterfaceAddress, getPasswordDialogOptions, getServerInfo, getTimeConstraint, setConnectionTimeout, setHTTPConnector, setNetworkInterface, setSocketFactory, setTimeConstraint, setUserAgent
 
Methods inherited from class de.humatic.dsj.src.Source
addSourceFilter, asyncRead, canSeek, createSourceFilter_async, getAvailable, getBuffered, getGraph, getID, getMaxTimeLoaded, getNumChannels, getOffsetTime, getPath, getSourceDuration, getSourceFilter, getSourceFilters, getSourceFlags, getTransport, getType, isLive, notifyChannelFailure, queryParameter_int, read, sendEvent, setOffsetTime, streamSeek, syncRead
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

RS_HANDSHAKE_DONE

public static final int RS_HANDSHAKE_DONE
RTMP Connection states

See Also:
Constant Field Values

RS_CONNECTED

public static final int RS_CONNECTED
RTMP Connection states

See Also:
Constant Field Values

RS_QUERY_STR_LENGTH

public static final int RS_QUERY_STR_LENGTH
RTMP Connection states

See Also:
Constant Field Values

RS_GOT_STR_LENGTH

public static final int RS_GOT_STR_LENGTH
RTMP Connection states

See Also:
Constant Field Values

RS_CREATE_STREAM

public static final int RS_CREATE_STREAM
RTMP Connection states

See Also:
Constant Field Values

RS_STREAM_CREATED

public static final int RS_STREAM_CREATED
RTMP Connection states

See Also:
Constant Field Values

RS_REQUEST_PLAY

public static final int RS_REQUEST_PLAY
RTMP Connection states

See Also:
Constant Field Values

INTERACTIVE

public static final int INTERACTIVE
Source flags

See Also:
Constant Field Values

NO_STREAM

public static final int NO_STREAM
Source flags

See Also:
Constant Field Values

IS_SINK

public static final int IS_SINK
Source flags

See Also:
Constant Field Values

STR_UNDEFINED

public static final java.lang.String STR_UNDEFINED
See Also:
Constant Field Values

STR_TRUE

public static final java.lang.String STR_TRUE
See Also:
Constant Field Values

STR_FALSE

public static final java.lang.String STR_FALSE
See Also:
Constant Field Values
Constructor Detail

RTMPSource

public RTMPSource(java.lang.String ip,
                  int port,
                  java.lang.String serverApp,
                  java.lang.String resourceName,
                  java.beans.PropertyChangeListener listener)
           throws java.lang.Exception
Creates a RTMPSource and connects to the given server application running on the host at %ip, requesting the given resource. The port argument is optional and can be <= 0, in which case the default rtmp port (1935) will be used. For example: new RTMPSource("127.0.0.1", -1, "vod", "Sample.flv") would connect to a local FlashMediaServer and ask its preinstalled "vod" application to stream "Sample".

Throws:
java.lang.Exception

RTMPSource

public RTMPSource(java.lang.String ip,
                  int port,
                  java.lang.String serverApp,
                  java.lang.String resourceName,
                  ConnectionParameter[] connectionParams,
                  int flags,
                  java.beans.PropertyChangeListener listener)
           throws java.lang.Exception
Creates a RTMPSource and connects to the given server application running on the host at %ip, requesting the given resource. The port argument is optional and can be <= 0, in which case the default rtmp port (1935) will be used. The flags parameter is not used yet.
Extended parameters as given in %connectionParams will be passed to the NetStream.connect() method, eventually overwriting the defaults that dsj would send as a minimum requirement (flashVer, swfUrl, tcUrl, audioCodecs, videoCodecs, videoFunction and objectEncoding plus for mp4 streams fpad and capabilities). To surpress sending of any of these alltogether, pass a ConnectionParameter object with the key of interest and a value of null. If you override all the defaults - regardless of evtl. null values - the Source will use the exact ordering of parameters as given in the ConnectionParameter array.
Parameters going into the main connection object should have a "flag" value of ConnectionParameter.OBJECT (0). Paramters with a flag value > 0 will be appended.
%flags may take the following (OR combineable) values:
INTERACTIVE - this will make the source call the PropertyChangeListener on the various stages of the connection process and give it the opportunity to send extra RTMP to the server.
, NO_STREAM - prevent the source from creating a NetStream. This is for RTMP chat applications that are not interested in media at all.

Throws:
java.lang.Exception

RTMPSource

public RTMPSource(java.lang.String appUrl,
                  java.lang.String resourceName,
                  int flags,
                  java.beans.PropertyChangeListener listener)
           throws java.lang.Exception
Creates a RTMPSource and connects to the server application at the given url, requesting %resource. For example: new RTMPSource("rtmp://127.0.0.1/vod", "Sample.flv") would connect to a local FlashMediaServer and ask its preinstalled "vod" application to stream "Sample". %flags may take the following (OR combineable) values:
INTERACTIVE - this will make the source call the PropertyChangeListener on the various stages of the connection process and give it the opportunity to send extra RTMP to the server.
, NO_STREAM - prevent the source from creating a NetStream. This is for RTMP chat applications that are not interested in media at all.

Throws:
java.lang.Exception

RTMPSource

public RTMPSource(java.lang.String appUrl,
                  java.lang.String resourceName,
                  ConnectionParameter[] connectionParams,
                  int flags,
                  java.beans.PropertyChangeListener listener)
           throws java.lang.Exception
Creates a RTMPSource and connects to the server application at the given url, requesting %resource.
Extended parameters as given in %connectionParams will be passed to the NetStream.connect() method, eventually overwriting the defaults that dsj would send as a minimum requirement (flashVer, swfUrl, tcUrl, audioCodecs, videoCodecs, videoFunction and objectEncoding plus for mp4 streams fpad and capabilities). To surpress sending of any of these alltogether, pass a ConnectionParameter object with the key of interest and a value of null. If you override all the defaults - regardless of evtl. null values - the Source will use the exact ordering of parameters as given in the ConnectionParameter array.
Parameters going into the main connection object should have a "flag" value of ConnectionParameter.OBJECT (0). Paramters with a flag value > 0 will be appended. %flags may take the following (OR combineable) values:
INTERACTIVE - this will make the source call the PropertyChangeListener on the various stages of the connection process and give it the opportunity to send extra RTMP to the server.
, NO_STREAM - prevent the source from creating a NetStream. This is for RTMP chat applications that are not interested in media at all.

Throws:
java.lang.Exception
Method Detail

setMinBufferTime

public static void setMinBufferTime(int time)

getMinBufferTime

public int getMinBufferTime()
Description copied from class: Source
Returns this Source's minimum buffer requirements in msec worth of data. Usually only PUSH mode network sources work with buffers.

Overrides:
getMinBufferTime in class Source

setLocalPort

public static void setLocalPort(int port)
Sets the local port used for connecting to the server, picked by the socket if not explicitely set.


setClientStream

public static void setClientStream(int streamID)
Sets the client stream ID used when connecting to the server. Only required in larger scale scenarios, needs to be called before constructing an RTMPSource instance.


setHandShakeData

public static void setHandShakeData(byte[] hsd)
Allows to set the initial 1536 bytes sent to the server during handshake. If not set, the Source will use defaults.


setEncoding

public static void setEncoding(int amfVersion)
Set AMF encoding (RTMP.AMF_0 or AMF_3).


getEncoding

public int getEncoding()

closeSource

public void closeSource(boolean terminate)
Description copied from class: Source
Closes down the source. When %terminate is true, all socket and stream resources etc. will also be freed. This method is called internally when disposing off the graph that was using this source and is not normally used by application code.

Overrides:
closeSource in class Source

getSourceTime

public int getSourceTime()
Overrides:
getSourceTime in class Source

setSourceTime

public void setSourceTime(int time)
Description copied from class: Source
Repositions the source, application code should rather not use this method directly, but stick with DSFiltergraph methods. The DSGraph created by a Source knows best when and how to interfere with the javaside data reading.

Overrides:
setSourceTime in class Source

setSourceRate

public void setSourceRate(float rate)
Description copied from class: Source
Starts and pauses the source, application code should rather not use this method directly, but stick with DSFiltergraph methods. The DSGraph created by a Source knows best when to change the state of the javaside implementation.

Overrides:
setSourceRate in class Source

createGraph

public DSGraph createGraph(int graphFlags)
                    throws DSJException
Use this to create a filtergraph from the source. This is a blocking call, that will not return before the asynchronous constructor has finished setting up the rtmp session.

Overrides:
createGraph in class Source
Throws:
DSJException

createGraph

public DSGraph createGraph(int graphFlags,
                           DSFilterInfo videoDecoder,
                           DSFilterInfo audioDecoder)
                    throws DSJException
Use this to create a filtergraph with the given decoders from the source. Please also see the superclass's documentation for further information.
This is a blocking call, that will not return before the asynchronous constructor has finished setting up the rtmp session.

Overrides:
createGraph in class Source
Throws:
DSJException

createSourceFilter

public CompressedJavaSource createSourceFilter(int sf,
                                               DSMediaType mediaType)
Description copied from class: Source
This is called by the various source implementations once they have determined, what kind of media they deal with etc.
It basically calls through to DSGraph.insertCompressedSourceFilter(...). The method is public for package design reasons and usually not called by application code.

Overrides:
createSourceFilter in class Source

getMediaTypes

public DSMediaType[] getMediaTypes()
Description copied from class: Source
Returns the media types created by this source. Depending on the time of calling, this method needs to be taken with care as during format negotiation mediatype information may not yet or only be partially available.

Overrides:
getMediaTypes in class Source

connectionIntercept

public void connectionIntercept(int connectionState,
                                java.lang.Object data)
When set up with the INTERACTIVE flag, the source during connection will wait for a short time after issuing RTMP_STATE_CHANGED events and client code may call this method to have additional rtmp sent to the server.
%connectionState takes the current state that you react on as transferred in the value field of RTMP_STATE_CHANGED events.
%data should either be raw rtmp data in a byte array or a SharedObject.


sendRTMP

public void sendRTMP(RTMPMessage msg)
              throws java.lang.Exception
Throws:
java.lang.Exception

sendRTMP

public void sendRTMP(byte[] msg)
              throws java.lang.Exception
Throws:
java.lang.Exception

sendRTMP

public void sendRTMP(byte[] msg,
                     int offset,
                     int length)
              throws java.lang.Exception
Throws:
java.lang.Exception

getSharedObject

public RTMPSource.SharedObject getSharedObject(java.lang.String soName,
                                               java.lang.String path,
                                               int flags)

setActionScriptHandler

public void setActionScriptHandler(java.lang.Object t)
Application code can register a class as a handler for actionscript method calls from the server. This class must implement the methods FMS calls. dsj will try to find and call the implementations through reflection.