FileDocCategorySizeDatePackage
Handler.javaAPI DocJMF 2.1.1e5024Mon May 12 12:21:00 BST 2003com.sun.media.datasink.rtp

Handler

public class Handler extends BasicDataSink

Fields Summary
private RTPMediaLocator
rtpmrl
RTPManager
rtpmanager
PushBufferDataSource
source
SendStream
rtpsendstream
Constructors Summary
Methods Summary
public voidclose()
Close the connection to the source described by the locator.

The close method frees resources used to maintain a connection to the destination described in the medialocator. If no resources are in use, close is ignored. If stop hasn't already been called, calling close implies a stop. The DataSink may no longer be used after being closed.

	if (rtpmanager != null) {
	    rtpmanager.removeTargets("DataSink closed");
	    rtpmanager.dispose();
	}
    
public java.lang.StringgetContentType()
Get a string that describes the content-type of the media that the datasink is consuming.

return
The name that describes the media content.

	return "RTP";
    
public java.lang.ObjectgetControl(java.lang.String controlType)


        
	return null;
    
public java.awt.ComponentgetControlComponent()

	return null;
    
public java.lang.Object[]getControls()

	return new Object[0];
    
public javax.media.MediaLocatorgetOutputLocator()
Get the output MediaLocator that describes where the output of this DataSink goes.

return
the output MediaLocator for this DataSink.

	return rtpmrl;
    
public voidopen()
Open a connection to the destination described by the output MediaLocator.

The open method establishes a channel with the destination as described in the medialocator.

exception
IOException Thrown if there are IO problems when open is called.
exception
SecurityException thrown if there is any security violation while attempting to access the destination as described by the medialocator

	// create, initialise and start the session manager here
	if (rtpmrl == null)
	    throw new IOException ("No Valid RTP MediaLocator");
	try {
	    String address = rtpmrl.getSessionAddress();
	    int port = rtpmrl.getSessionPort();
	    int ttl = rtpmrl.getTTL();
	    rtpmanager = RTPManager.newInstance();

	    // create our local Session Address
	    SessionAddress localaddr = new SessionAddress();
	    InetAddress destaddr = InetAddress.getByName(address);
	    SessionAddress sessaddr = new SessionAddress(destaddr, port, ttl);

	    rtpmanager.initialize(localaddr);
	    rtpmanager.addTarget(sessaddr);
	    rtpsendstream = rtpmanager.createSendStream(source,0);

	} catch (Exception  e) {
	    throw new IOException (e.getMessage());
	}
    
public voidsetOutputLocator(javax.media.MediaLocator output)
Set the output MediaLocator. This method should only be called once; an error is thrown if the locator has already been set.

param
output MediaLocator that describes where the output goes.

	if (rtpmrl == null) {
	    System.out.println("sink: setOutputLocator " + output);
	    // need to validate the RTPMedialocator
	    try{
		rtpmrl = new RTPMediaLocator(output.toString());
	    }catch (MalformedURLException e){
		rtpmrl = null;
	    }
	} else {
	    throw new Error("setOutputLocator cannot be called more than once");
	}
    
public voidsetSource(javax.media.protocol.DataSource source)

    
	if ( ! (source instanceof PushBufferDataSource) ) {
	    throw new IncompatibleSourceException("Only supports PushBufferDataSource");
	}
	this.source = (PushBufferDataSource) source;
	PushBufferStream [] streams = this.source.getStreams();
	int numStreams = streams.length;
	System.out.println("streams is " + streams + " : " + numStreams);

	if ( (streams == null) || (numStreams <= 0) )
	    throw new IOException("source " + source + " doesn't have any streams");
    
public voidstart()
Initiate data-transfer. You must call open before calling start

exception
IOException Thrown if there are IO problems with the source when start is called.

	rtpsendstream.start();
    
public voidstop()
Stop the data-transfer. If the source has not been connected and started, stop does nothing.

	rtpsendstream.stop();