Methods Summary |
---|
protected boolean | audioEnabled()
return audioEnabled;
|
private void | closeSessions()
RTPManager mgrs[]= rtspUtil.getRTPManagers();
for (int i = 0; i < mgrs.length; i++) {
if (mgrs[ i] != null) {
mgrs[ i].removeTargets( "Closing session from the RTP Handler");
mgrs[ i].dispose();
}
mgrs[ i] = null;
}
|
protected void | completeConfigure()
state = javax.media.Processor.Configured;
super.completeConfigure();
|
protected void | completeRealize()
state = Realized;
super.completeRealize();
|
protected void | doClose()
closed = true;
synchronized (dataLock) {
dataLock.notify();
}
stop();
processor.close();
closeSessions();
super.doClose();
|
protected synchronized boolean | doConfigure()
boolean configured = super.doConfigure();
if (configured) {
configured = initRtspSession();
}
return configured;
|
protected void | doDeallocate()
processor.deallocate();
synchronized (dataLock) {
dataLock.notifyAll();
}
|
protected void | doFailedConfigure()
closeSessions();
super.doFailedConfigure();
|
protected void | doFailedRealize()
closeSessions();
super.doFailedRealize();
|
protected boolean | doRealize()
return waitForRealize(processor);
|
protected void | doStart()
super.doStart();
waitForStart(processor);
|
protected void | doStop()
super.doStop();
waitForStop(processor);
|
public javax.media.protocol.ContentDescriptor | getContentDescriptor()
super.getContentDescriptor();
return processor.getContentDescriptor();
|
public javax.media.Control[] | getControls()Return the list of controls from its slave controllers plus the
ones that this player supports.
return processor.getControls();
|
public javax.media.protocol.DataSource | getDataOutput()
super.getDataOutput();
return processor.getDataOutput();
|
protected javax.media.TimeBase | getMasterTimeBase()
return new SystemTimeBase();
|
public javax.media.protocol.ContentDescriptor[] | getSupportedContentDescriptors()
super.getSupportedContentDescriptors();
return processor.getSupportedContentDescriptors();
|
public javax.media.control.TrackControl[] | getTrackControls()
super.getTrackControls();
return processor.getTrackControls();
|
public java.awt.Component | getVisualComponent()Obtain the visiual component from the media engine.
/**
* Call the superclass method to ensure that restrictions
* on player methods are enforced
*/
super.getVisualComponent();
return processor.getVisualComponent();
|
private boolean | initRtspSession()
boolean realized = false;
MediaLocator ml= (MediaLocator) locators.elementAt( 0);
rtspUtil.setUrl( ml.toString());
String ipAddress = rtspUtil.getServerIpAddress();
if (ipAddress == null) {
System.out.println( "Invalid server address.");
realized = false;
} else {
rtspUtil.setUrl( ml.toString());
realized= rtspUtil.createConnection();
if( realized) {
realized = rtspUtil.rtspSetup();
try {
InetAddress destaddr = InetAddress.getByName(ipAddress);
int server_ports[]= rtspUtil.getServerPorts();
for( int i = 0; i < rtspUtil.getNumberOfTracks(); i++) {
SessionAddress remoteAddress =
new SessionAddress(destaddr, server_ports[ i]);
rtspUtil.getRTPManager( i).addTarget( remoteAddress);
// Set 3/4 sec worth of buffering.
BufferControl bc = (BufferControl)rtspUtil.getRTPManager( i).getControl("javax.media.control.BufferControl");
String mediaType= rtspUtil.getMediaType( i);
if( mediaType.equals( "audio")) {
bc.setBufferLength(250);
bc.setMinimumThreshold(125);
} else if( mediaType.equals( "video")) {
bc.setBufferLength(1500);
bc.setMinimumThreshold(250);
}
}
} catch (Exception e) {
Log.error(e.getMessage());
return realized;
}
}
}
if (realized) {
state = REALIZED;
int size= rtspUtil.getNumberOfTracks();
data_sources = new DataSource[ size];
formats= new Format[ size];
// Start the server.
if (!rtspUtil.rtspStart()) {
if( first_pass &&
rtspUtil.getStatusCode() ==
com.sun.media.rtsp.protocol.StatusCode.SESSION_NOT_FOUND) {
first_pass= false;
return initRtspSession();
}
return false;
}
// Wait for the initial filling of the data buffers and
// the RTP players to fully realized.
waitForData();
// Now the players are all started.
// Stop the server momentarily. Rewind the media
// so the next start will start from the beginning again.
// This is sort of inefficient but will get by the initial
// buffering problem.
// rtspStop();
// startPos = 0;
// Now we need to flush the datasources to make sure
// the rewind starts from the very beginning.
// for( int i = 0; i < numberOfTracks; i++) {
// data_sources[ i].flush();
// }
}
return realized;
|
private void | invalidateComp()
controlComp = null;
controls = null;
|
private void | sendMyEvent(javax.media.ControllerEvent e)
super.sendEvent(e);
|
public javax.media.protocol.ContentDescriptor | setContentDescriptor(javax.media.protocol.ContentDescriptor ocd)
super.setContentDescriptor(ocd);
return processor.setContentDescriptor(ocd);
|
public void | setSource(javax.media.protocol.DataSource source)
super.setSource(source);
if (source instanceof com.sun.media.protocol.rtsp.DataSource){
MediaLocator ml = source.getLocator();
locators.addElement(ml);
} else {
throw new IncompatibleSourceException();
}
|
public void | setTimeBase(javax.media.TimeBase tb)
|
public void | update(javax.media.rtp.event.ReceiveStreamEvent event)
RTPManager mgr = (RTPManager)event.getSource();
int idx;
// return if the data sources have not been allocated yet.
// this may happen if data is coming in from a different
// source before the PLAY message has been issued.
if( data_sources == null) {
return;
}
RTPManager mgrs[]= rtspUtil.getRTPManagers();
for (idx = 0; idx < mgrs.length; idx++) {
if (mgrs[idx] == mgr) {
break;
}
}
if (idx >= mgrs.length) {
// Something's wrong.
System.err.println("Unknown manager: " + mgr);
return;
}
if (event instanceof RemotePayloadChangeEvent) {
Log.comment("Received an RTP PayloadChangeEvent");
Log.error("The RTP processor cannot handle mid-stream payload change.\n");
sendEvent(new ControllerErrorEvent(this, "Cannot handle mid-stream payload change."));
close();
}
if (event instanceof NewReceiveStreamEvent) {
if (data_sources[idx] != null) {
// We've already gotten a source from this session.
return;
}
ReceiveStream stream = null;
try {
// get a handle over the ReceiveStream
stream =((NewReceiveStreamEvent)event).getReceiveStream();
data_sources[idx] = stream.getDataSource();
RTPControl ctl = (RTPControl)data_sources[idx].getControl("javax.media.rtp.RTPControl");
if (ctl != null) {
formats[idx] = ctl.getFormat();
if (formats[idx] instanceof AudioFormat) {
audioEnabled = true;
}
if (formats[idx] instanceof VideoFormat) {
videoEnabled = true;
}
}
/* this can't be done
if (source instanceof RTPSocket) {
((RTPSocket)source).setChild(data_sources[idx]);
} else {
((com.sun.media.protocol.rtp.DataSource)source).
setChild((com.sun.media.protocol.rtp.DataSource)data_sources[idx]);
}
*/
for (int i = 0; i < data_sources.length; i++) {
// Return if not all sessions had yielded a source.
if (data_sources[i] == null) {
return;
}
}
// We've received all the sources, let create the processor.
DataSource mixDS;
try {
mixDS = javax.media.Manager.createMergingDataSource(data_sources);
} catch (Exception e) {
System.err.println("Cannot merge data sources.");
return;
}
try {
processor = javax.media.Manager.createProcessor(mixDS);
} catch (Exception e) {
System.err.println("Cannot create the mix processor.");
return;
}
if (!waitForConfigure(processor)) {
return;
}
// We are done generating the internal processor.
synchronized(dataLock) {
dataReady = true;
dataLock.notifyAll();
}
} catch (Exception e){
System.err.println("NewReceiveStreamEvent exception " + e.getMessage());
return;
}
}
|
public void | updateStats()
if ( processor != null) {
((BasicProcessor) processor).updateStats();
}
|
protected boolean | videoEnabled()
return videoEnabled;
|
private void | waitForClose(javax.media.Player p)
(new StateWaiter()).waitForClose(p);
|
private boolean | waitForConfigure(javax.media.Processor p)
return (new StateWaiter()).waitForConfigure(p);
|
private synchronized boolean | waitForData()
try {
synchronized (dataLock) {
while (!dataReady) {
dataLock.wait();
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
return dataReady;
|
private boolean | waitForRealize(javax.media.Processor p)
return (new StateWaiter()).waitForRealize(p);
|
private void | waitForStart(javax.media.Player p)
(new StateWaiter()).waitForStart(p, true);
|
private void | waitForStop(javax.media.Player p)
(new StateWaiter()).waitForStart(p, false);
|