FileDocCategorySizeDatePackage
DelegateDataSource.javaAPI DocJMF 2.1.1e4978Mon May 12 12:20:54 BST 2003com.sun.media.protocol

DelegateDataSource

public class DelegateDataSource extends PushBufferDataSource implements Streamable
This special DataSource is used to prebuild a streaming player before the actual streaming DataSource is not available e.g. RTP.

Fields Summary
protected String
contentType
protected PushBufferDataSource
master
protected DelegateStream[]
streams
protected boolean
started
protected boolean
connected
Constructors Summary
public DelegateDataSource(Format[] format)



       
	streams = new DelegateStream[format.length];
	for (int i = 0; i < format.length; i++) {
	    streams[i] = new DelegateStream(format[i]);
	}
	try {
	    connect();
	} catch (IOException e) {}
    
Methods Summary
public voidconnect()

	if (connected)
            return;
	if (master != null)
	    master.connect();
	connected = true;
    
public voiddisconnect()

	try{
            if (started)
                stop();
        }catch (IOException e){}
	if (master != null)
	    master.disconnect();
	connected = false;
    
public java.lang.StringgetContentType()

	if (!connected){
            System.err.println("Error: DataSource not connected");
            return null;
        }
	return contentType;
    
public java.lang.ObjectgetControl(java.lang.String controlType)

	if (master != null)
	    return master.getControl(controlType);
	return null;
    
public java.lang.Object[]getControls()

	if (master != null)
	    return master.getControls();
	return new Object[0];
    
public javax.media.TimegetDuration()

	if (master != null)
	    return master.getDuration();
	return Duration.DURATION_UNKNOWN;
    
public javax.media.MediaLocatorgetLocator()

	if (master != null)
	    return master.getLocator();
	return null;
    
public javax.media.protocol.DataSourcegetMaster()

	return master;
    
public javax.media.protocol.PushBufferStream[]getStreams()

	return streams;
    
public booleanisPrefetchable()

	return false;
    
public voidsetMaster(javax.media.protocol.PushBufferDataSource ds)

	master = ds;

	PushBufferStream mstrms[] = ds.getStreams();
	for (int i = 0; i < mstrms.length; i++) {
	    for (int j = 0; j < streams.length; j++) {
		if (streams[j].getFormat().matches(mstrms[i].getFormat()))
		    streams[j].setMaster(mstrms[i]);
	    }
	}

	for (int i = 0; i < mstrms.length; i++) {
	    if (streams[i].getMaster() == null) {
		Log.error("DelegateDataSource: cannot not find a matching track from the master with this format: " + streams[i].getFormat());
	    }
	}

	if (connected)
	    master.connect();
	if (started)
	    master.start();
    
public voidstart()

	// we need to throw error if connect() has not been called
        if (!connected)
            throw new java.lang.Error("DataSource must be connected before it can be started");
        if (started)
            return;
	if (master != null)
	    master.start();
	started = true;
    
public voidstop()

	if ((!connected) || (!started))
	    return;
	if (master != null)
	    master.stop();
	started = false;