FileDocCategorySizeDatePackage
DataSource.javaAPI DocJMF 2.1.1e6918Mon May 12 12:20:54 BST 2003com.sun.media.protocol.rtp

DataSource

public class DataSource extends BasicPushBufferDataSource implements Streamable, RTPSource

Fields Summary
static int
SSRC_UNDEFINED
private RTPSourceStream[]
srcStreams
private boolean
stopped
Player
streamplayer
RTPSessionMgr
mgr
RTPControl
rtpcontrol
DataSource
childsrc
int
ssrc
Constructors Summary
public DataSource()

	srcStreams = new RTPSourceStream[1];
	rtpcontrol = new MyRTPControl();
	//setContentType(ContentDescriptor.RAW);
	setContentType("rtp");
    
Methods Summary
public voidconnect()
Opens a connection to the source described by the URL.

Connect initiates communmication with the source.

exception
IOException thrown if the connect has IO trouble.

	// start the RTPSessionManager by calling startSession()
	// this will throw an IOException if there is any problem
	/*
	if (mgr != null){
	    mgr.startSession();
	}
	*/
	if (srcStreams != null){
	  for (int i = 0; i < srcStreams.length; i++){
	    if (srcStreams[i] != null)
	      ((com.sun.media.rtp.RTPSourceStream)srcStreams[i]).connect();
	  }
	}
	connected = true;
    
public voiddisconnect()
Close the connection to the source described by the URL.

Disconnect frees resources used to maintain a connection to the source. If no resources are in use, disconnect is ignored. Implies a stop, if stop hasn't already been called.

	// once we have disconnected, set boolean to false
	// If this datasource was created by using the RTPAPI and not
	// via Manager, we dont want to disconnect this source i.e. we
	// dont want to closeSession() on RTPSM. In this case, the
	// datasource will not have a manager set to it. In this case,
	// the datasource cannot really be disconnected until the
	// session manager is closed by using the RTPAPI
	if (srcStreams != null){
	    for (int i = 0; i < srcStreams.length; i++)
		((com.sun.media.rtp.RTPSourceStream)srcStreams[i]).close();
	}
	/*
	if (mgr != null){
	    // close the RTPSourceStream
	    mgr.removeDataSource(this);
	    mgr.closeSession();
	    mgr = null;
	     // to fix bug 4174773, multiple stream problem 9/18/98
            started = false;
	    connected = false;
	    return;
	}
	*/
    
public voidflush()
A method to flush the data buffers int the DataSource.

	srcStreams[0].reset();
    
public java.lang.StringgetCNAME()

	if (mgr == null)
	    return null;
	SSRCInfo info = mgr.getSSRCInfo(ssrc);
	if (info != null)
	    return info.getCNAME();
	return null;
    
public java.lang.ObjectgetControl(java.lang.String type)
Returns null because no controls are implemented.

return
null.

	Class cls;
	try {
	    cls = Class.forName(type);
	} catch (ClassNotFoundException e) {
	    return null;
	}
	Object cs[] = getControls();
	for (int i = 0; i < cs.length; i++) {
	    if (cls.isInstance(cs[i]))
		return cs[i];
	}
	return null;
    
public java.lang.Object[]getControls()
Returns an zero length array because no controls are supported.

return
a zero length Object array.

	// return a one element array of rtpcontrol object
	RTPControl[] controls = new RTPControl[1];
	controls[0] = rtpcontrol;
	return controls;	    
    
public com.sun.media.rtp.RTPSessionMgrgetMgr()

	return mgr;
    
public javax.media.PlayergetPlayer()

	return streamplayer;
    
public intgetSSRC()

	return ssrc;
    
public javax.media.protocol.PushBufferStream[]getStreams()
Obtain the collection of streams that this source manages. The collection of streams is entirely content dependent. The mime-type of this DataSource provides the only indication of what streams can be available on this connection.

return
collection of streams for this source.

 	if (!connected)
 	    return null;
 	return srcStreams;
    
public booleanisPrefetchable()

	return false;
    
public booleanisStarted()

	return started;
    
public voidprebuffer()

	started = true;
	srcStreams[0].prebuffer();
    
public voidsetBufferListener(com.sun.media.protocol.BufferListener listener)

	srcStreams[0].setBufferListener(listener);
    
public voidsetBufferWhenStopped(boolean flag)

	srcStreams[0].setBufferWhenStopped(flag);
    
public voidsetChild(com.sun.media.protocol.rtp.DataSource source)

	childsrc = source;
    
public voidsetContentType(java.lang.String contentType)

	this.contentType = contentType;
    
public voidsetControl(java.lang.Object control)

	rtpcontrol = (RTPControl)control;
    
public voidsetLocator(javax.media.MediaLocator mrl)

	super.setLocator(mrl);
    
public voidsetMgr(com.sun.media.rtp.RTPSessionMgr mgr)

    
    
       
	//System.out.println("manager being set to " + mgr);
	this.mgr = mgr;
    
public voidsetPlayer(javax.media.Player player)

	streamplayer = player;
    
public voidsetSSRC(int ssrc)

	this.ssrc = ssrc;
    
public voidsetSourceStream(com.sun.media.rtp.RTPSourceStream stream)

	if (srcStreams != null)
	    srcStreams[0] = stream;
    
public voidstart()
Initiates data-transfer. Start must be called before data is available. Connect must be called before start.

exception
IOException thrown if the source has IO trouble at startup time.

	super.start();
	if (childsrc != null)
	    childsrc.start();
	if (srcStreams != null){
	    for (int i = 0; i < srcStreams.length; i++)
		((com.sun.media.rtp.RTPSourceStream)srcStreams[i]).start();
	}
    
public voidstop()
Stops data-transfer. If the source has not already been connected and started, stop does nothing.

	super.stop();
	// stop your child source as well
	if (childsrc != null)
	    childsrc.stop();
	if (srcStreams != null){
	    for (int i = 0; i < srcStreams.length; i++)
		((com.sun.media.rtp.RTPSourceStream)srcStreams[i]).stop();
	}