de.humatic.dsj.src
Class AsyncSource

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

public class AsyncSource
extends NetworkSource

JNI implementation of DirectShow's IAsyncReader interface, that can be used to play mpg (mpeg1 video and mp3 audio that is), avi, mp4, wmv / asf, dv, Matroska & flv data from java input streams, including Jar- and ZipInputStreams.
This is basically a clone of the stock FileSource (Async) DirectShow filter, reading data on the java side. Do not use it for playback of local files or URLs, that DSMovie can open directly, as the JNI overhead makes this far less efficient.
The source operates in combination with DirectShow parser filters, that will issue the read requests. These requests can be seemingly random in terms of read position and read length during setup while the parser tries to determine the format of the stream. The incoming stream MUST therefore be seekable itself or be wrapable into a seekable BufferedInputStream. This class's constructor will fail when InputStream.markSupported() returns false in both cases.
The source will attempt to operate without caching data. It may however be necessary to write portions of a stream to a filecache. This will be cleaned up after the source exits.
A plain Windows DirectShow installation will bring splitter / parser filters for mpg, avi & wav streams. In order for this class to work with WindowsMedia, mp4, dv, flv, mkv and other stream formats, additional parsers are required. The dll has hardcoded defaults for
flv (Gabest's FLVSplitter),
dv (Main Concept's DV Dif Parser,
asf(Geraint Davies's GDCL WMV/WMA Parser),
mp4 (Gabest's MP4Splitter) and
mkv (Gabest's MatroskaSplitter).
These can be overwritten by xml preferences in the dsj.xml setup file, linking a file suffix with a filter CLSID. Example:
<preference name="async_splitter"><async_splitter name="flv" value="{47E792CF-0BBE-4F7A-859C-194B0768650A}"/></preference>


Field Summary
 
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
AsyncSource(java.io.InputStream in, int streamSubType, java.beans.PropertyChangeListener listener)
          Reads mpg, avi, wmv, dv and flv data from java input streams.
AsyncSource(java.net.URL url, java.beans.PropertyChangeListener listener)
          Reads mpg, avi, asf, mp4, dv, mkv, wav and flv data from an InputStream opened on the given URL, including jar URLs.
 
Method Summary
 byte[] asyncRead(int numBytes)
          Called by async sources on a DSFiltergraph internal dispatch thread.
 boolean canSeek()
           
 void closeSource(boolean terminate)
          Closes down the source.
 DSGraph createGraph(int flags)
          Creates a DSGraph object with CompressedJavaSource filters that are fed from this source.
 DSGraph createGraph(int flags, DSFilterInfo videoDecoder, DSFilterInfo audioDecoder)
          Creates a DSGraph object with CompressedJavaSource filters, fed from this source and the given video and audio decoders.
 int getAvailable()
          Returns the available number of bytes a pull source can access or 0 if unknown.
 DSMediaType[] getMediaTypes()
          Returns the media types created by this source.
 int getSubType()
           
 boolean streamSeek(int toPos)
          Instructs the Source implementation to reposition its read pointer in the incoming stream to the requested byte position.
 byte[] syncRead(int numBytes)
          Called by async sources on a native DirectShow thread during stream investigation (the MPEG splitter continues to use this method also during normal playback).
 
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, createSourceFilter_async, createSourceFilter, getBuffered, getGraph, getID, getMaxTimeLoaded, getMinBufferTime, getNumChannels, getOffsetTime, getPath, getSourceDuration, getSourceFilter, getSourceFilters, getSourceFlags, getSourceTime, getTransport, getType, isLive, notifyChannelFailure, queryParameter_int, read, sendEvent, setOffsetTime, setSourceRate, setSourceTime
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncSource

public AsyncSource(java.io.InputStream in,
                   int streamSubType,
                   java.beans.PropertyChangeListener listener)
            throws java.lang.Exception
Reads mpg, avi, wmv, dv and flv data from java input streams. The subType parameter should be DSMediaType.SST_AVI, SST_MPEG1_SYSTEM, SST_ASF, SST_MP4, SST_FLV, SST_DV, SST_WAVE, SST_MKV or VST_DVSD.
This can also be used to play movies from zip archives, given it is fed with a ZipInputStream pointing to an entry in the archive.
Example:
ZipFile zf = new ZipFile("someZippedUpAvi.zip");
ZipInputStream zis = new ZipInputStream(new FileInputStream("someZippedUpAvi.zip"));
ZipEntry ze = zis.getNextEntry();
AsyncSource as = new de.humatic.dsj.src.AsyncSource(zf.getInputStream(ze), de.humatic.dsj.DSMediaType.SST_AVI, this);

Throws:
java.lang.Exception

AsyncSource

public AsyncSource(java.net.URL url,
                   java.beans.PropertyChangeListener listener)
            throws java.lang.Exception
Reads mpg, avi, asf, mp4, dv, mkv, wav and flv data from an InputStream opened on the given URL, including jar URLs. This constructor determines the stream subtype from the file extension in the URL (.avi, .mpg ...).

Throws:
java.lang.Exception
Method Detail

createGraph

public DSGraph createGraph(int flags)
Description copied from class: Source
Creates a DSGraph object with CompressedJavaSource filters that are fed from this source.

Overrides:
createGraph in class Source

createGraph

public DSGraph createGraph(int flags,
                           DSFilterInfo videoDecoder,
                           DSFilterInfo audioDecoder)
Description copied from class: Source
Creates a DSGraph object with CompressedJavaSource filters, fed from this source and the given video and audio decoders. This is for special use cases where you know exactly what media formats to expect. Any decoder you do not want to specify may be null or DSFilterInfo.doNotRender(). Failure to put a given decoder into the graph will be announced via GRAPH_ERROR events and dsj will try to automatically pick an alternative (no exception will be thrown!).

Overrides:
createGraph in class Source

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

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

streamSeek

public boolean streamSeek(int toPos)
Description copied from class: Source
Instructs the Source implementation to reposition its read pointer in the incoming stream to the requested byte position. Called on a native DirectShow thread and usually immediately followed by the next read call.

Overrides:
streamSeek in class Source

syncRead

public byte[] syncRead(int numBytes)
Description copied from class: Source
Called by async sources on a native DirectShow thread during stream investigation (the MPEG splitter continues to use this method also during normal playback). Will attempt to read %numBytes bytes. The byte[] to be returned is allocated by the source (usually allocated once and then reused).

Overrides:
syncRead in class Source

asyncRead

public byte[] asyncRead(int numBytes)
Description copied from class: Source
Called by async sources on a DSFiltergraph internal dispatch thread. Data read by this call will be intermediately buffered by the java part of the CompressedJavaSourceFilter and then get picked up by its native counterpart. The byte[] to be returned is allocated by the source (usually allocated once and then reused).

Overrides:
asyncRead in class Source

getAvailable

public int getAvailable()
Description copied from class: Source
Returns the available number of bytes a pull source can access or 0 if unknown.

Overrides:
getAvailable in class Source

getSubType

public int getSubType()

canSeek

public boolean canSeek()
Overrides:
canSeek in class Source