aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Live Video Transmission-Help Required very urgently Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Live Video Transmission-Help Required very urgently" Watch "Live Video Transmission-Help Required very urgently" New topic
Author

Live Video Transmission-Help Required very urgently

Roshini Sridharan
Ranch Hand

Joined: Jan 16, 2001
Posts: 143
Hi All,
The following is the code i am trying to do Live Capture from Video Device [Logitech Quick Cam Pro] and transmit the Data to the Client.
I would like to get whether the syntax of executing the Code is correct
It would be of great help if somebody could solve me the problem by specifying the right java command to execute the program perfectly.
i.e. using
java RTPServer3 ClientIP CaptureDevice[MediaLocator Argument]
java RTPServer3 200.100.100.1 "javasound://44100 & vfw://1"
----------------------------------------------------------------------
Output:
DataSource created from file
Processor created
value of state: 180
value of getState: 180
B Processor Configured 180
A Processor Configured 180
Processor Configuring 140
After config
Processor Configuring 2
Before Track
Encoding ok false
Processor Realized
Going to get DataSource now
javax.media.NotRealizedError: getDataOutput cannot be called before realized
at com.sun.media.ProcessEngine.getDataOutput(ProcessEngine.java:379)
at com.sun.media.MediaProcessor.getDataOutput(MediaProcessor.java:138)
at RTPServer3.createProcessor(RTPServer3.java:205)
at RTPServer3.instantiate(RTPServer3.java:70)
at RTPServer3.<init>(RTPServer3.java:62)
at RTPServer3.main(RTPServer3.java:313)
Exception in thread "main" javax.media.NotRealizedError: getDataOutput cannot be
called before realized
at com.sun.media.ProcessEngine.getDataOutput(ProcessEngine.java:379)
at com.sun.media.MediaProcessor.getDataOutput(MediaProcessor.java:138)
at RTPServer3.createProcessor(RTPServer3.java:205)
at RTPServer3.instantiate(RTPServer3.java:70)
at RTPServer3.<init>(RTPServer3.java:62)
at RTPServer3.main(RTPServer3.java:313)
----------------------------------------------------------------------
RTPServer3 -- Source Code
----------------------------------------------------------------------
import java.awt.*;
import java.io.*;
import java.net.InetAddress;
import javax.media.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.*;
import javax.media.control.TrackControl;
import javax.media.control.QualityControl;
import javax.media.rtp.*;
import javax.media.rtp.rtcp.*;
import com.sun.media.rtp.*;
public class RTPServer3
{
MediaLocator medialocator ;
String ipAddress ;
int port ;
Processor processor = null ;
RTPManager rtpManager[] ;
DataSource dataSource = null ;
// Constructor for RTPServer
public RTPServer3( MediaLocator locator, String ipAddress,
String portNumber, Format audioFormat )
{
// Assign the values taken in from the constructor to
// those defined in the main class
this.medialocator = locator ;
this.ipAddress = ipAddress ;
Integer portValue = Integer.valueOf( portNumber ) ;
// If port can be converted from string to integer
// assign it to be the port number
if ( portValue != null )
this.port = portValue.intValue() ;
// Create a processor for this output
instantiate() ;
}
public synchronized void instantiate()
{
boolean processorOK = false ;
boolean configureOK = false ;
processorOK = createProcessor() ;
System.out.println( "processorOK = " + processorOK ) ;
if( processorOK )
configureOK = createSend() ;
System.out.println( "configureOK = " + configureOK ) ;
if( configureOK ){
processor.start() ;
System.out.println( "Processor starting..." ) ;
}
}
// Method to create a Processor and do error checking
public synchronized boolean createProcessor()
{
// DataSource source ;
// create the datasource
try {
dataSource = javax.media.Manager.createDataSource( medialocator ) ;
System.out.println( "DataSource created from file" ) ;
} catch ( Exception e ) {
System.out.println( "Error: Couldn't create Datasource" ) ;
System.exit( -1 ) ;
}
// Create the processor to process the DataSource
try {
processor = javax.media.Manager.createProcessor( dataSource ) ;
System.out.println( "Processor created" ) ;
} catch ( NoProcessorException p ) {
System.out.println( "Error: Couldn't create processor" ) ;
System.exit( -1 ) ;
} catch ( IOException i ) {
System.out.println( "Error: Error reading file" ) ;
//System.out.println( i.printStack() ) ;
System.exit( -1 ) ;
}
// Run Processor methods to configure Processor
processor.addControllerListener(new StateListener());
//int state = Processor.Configured ;
int state = processor.Configured ;
System.out.println( "value of state: " +state +"\nvalue of getState: " +Processor.Configured ) ;
if( state == processor.Configured )
{
System.out.println( "B Processor Configured " + processor.Configured ) ;
processor.configure() ;
System.out.println( "A Processor Configured " + processor.Configured ) ;
System.out.println( "Processor Configuring " + processor.Configuring ) ;
} else {
System.out.println( "Error: Could not Configure Processor" ) ;
System.exit( -1 ) ;
}
System.out.println("After config");
// Now that it has been configured, program the tracks
if ( processor.getState() == processor.Configured )
{
System.out.println("Getting Tracks") ;
} else {
System.out.println("Processor Configuring 2") ;
processor.configure() ;
}
try{Thread.sleep(100);}catch(Exception E){}
System.out.println("Before Track");
TrackControl [] track = processor.getTrackControls() ;
boolean encodingOK = false ;
// Check to see if the datasource had tracks
if ( ( track == null ) || ( track.length < 1 ) )
{
System.out.println( "Error: No tracks in Source" ) ;
System.exit( -1 ) ;
}
// Set the content type of the output data to RTP data
ContentDescriptor content = new ContentDescriptor( ContentDescriptor.RAW_RTP ) ;
processor.setContentDescriptor( content ) ;
Format supportedFormats[] ;
for ( int i = 0 ; i < track.length ; i++ )
{
// Set format to the format of TrackControl
// i.e. ContentDescriptor
Format format = track[i].getFormat() ;
if ( track[i].isEnabled() )
{
// Find formats that support RAW_RTP
supportedFormats = track[i].getSupportedFormats() ;
if ( supportedFormats.length > 0 )
{
// Encode the track with MPEG_RTP format
if( track[i].setFormat( supportedFormats[i] ) == null )
{
track[i].setEnabled( false ) ;
encodingOK = false ;
} else {
encodingOK = true ;
}
}
} // if
} // for
// Now, if encoding occured correctly, the processor is programmed and ready to be realized
int realized = Controller.Realized ;
if ( encodingOK )
{
if( realized == Processor.Realized )
{
processor.realize() ;
System.out.println( "Processor Realized" ) ;
} else {
System.out.println( "Error: Processor could not be realized" ) ;
System.exit( -1 ) ;
}
} else {
System.out.println( "Error: Encoding to MPEG format failed" ) ;
System.exit( -1 ) ;
}
// Final Steps of creating Processor:
// Link the datasource to the Processor
if( realized == Processor.Realized )
{
System.out.println( "Going to get DataSource now" ) ;
} else {
processor.realize() ;
}
dataSource = processor.getDataOutput() ;
return true ;
}

// Use the RTPManager to pass the application data to the lower network layer
public synchronized boolean createSend()
{
// Make a buffered Push Source from our data source
PushBufferDataSource bufferDatasource = ( PushBufferDataSource ) dataSource ;
// Make a buffered stream for each track in the processor
PushBufferStream bufferStream[] = bufferDatasource.getStreams() ;
// Make an RTPManager for each stream
rtpManager = new RTPManager[ bufferStream.length ] ;
// Create SessionAddresses to locate the client and server; port as well
SessionAddress serverAddress, clientAddress ;
InetAddress ipAddr ;
int portNumber ;
// Create a SendStream that will carry the output
SendStream outputStream ;
// Create the needed SDES list to identify sources
SourceDescription SDESList[] ;
// For every track, make an instance in the RTPManager
for ( int i = 0 ; i < bufferStream.length ; i++ )
{
try{
rtpManager[i] = RTPManager.newInstance() ;
// make the port, since each instance will have two ports (RTP and RTCP)
// increment the portnumber by 2 for each instance
portNumber = port + 2*i ;
// Get IP of source and destination to associate with send stream
ipAddr = InetAddress.getByName( ipAddress ) ;
serverAddress = new SessionAddress( InetAddress.getLocalHost(), portNumber ) ;
clientAddress = new SessionAddress( ipAddr, portNumber ) ;
// Now Initialze the Manager and then add the target to the RTP Manager
rtpManager[i].initialize( serverAddress ) ;
rtpManager[i].addTarget( clientAddress ) ;
System.out.println( "RTP Session #" +i +" created: " +ipAddress +" " +portNumber ) ;
// Create the sendStreams and link them to the targets just added to the RTPManager
outputStream = rtpManager[i].createSendStream( dataSource, i ) ;
outputStream.start() ;
} catch ( Exception e ) {
System.out.println( "Error: SendStream could not be created" ) ;
System.out.println( e.getMessage() ) ;
System.exit( -1 ) ;
}
}
return true ;
}

class StateListener implements ControllerListener
{
public void controllerUpdate( ControllerEvent c )
{
if( c instanceof ControllerClosedEvent )
{if( processor != null ){
processor.stop() ;
processor.close() ;
processor = null ;
for( int i = 0 ; i < rtpManager.length ; i++ )
{
rtpManager[i].removeTargets( "Sessions are done" ) ;
rtpManager[i].dispose() ;
}}
}
if( c instanceof EndOfMediaEvent )
{
processor.stop() ;
processor.close() ;
processor = null ;
for( int i = 0 ; i < rtpManager.length ; i++ )
{
rtpManager[i].removeTargets( "Sessions are done" ) ;
rtpManager[i].dispose() ;
}
System.out.println( "End of Media Stream" ) ;
}
}
}
// Main class, which instantiates the Server
public static void main ( String[] args )
{
// Path for the file to stream
// change for different files for now
// Syntax -- rtp://severip:serverport/mediatype/timetolive[TTL] -- //
// String url= "rtp://200.100.100.7:4000/audio/1";
String file = args[1];
String port = "45000";
Format format = null ;
// Session Address, supposedly supposed to be
// the IP of the receiving client
// String sessionAddress = "200.100.100.1"
String sessionAddress = args[0] ;
RTPServer3 server = new RTPServer3(new MediaLocator(file), sessionAddress, port, format) ;
try {
Thread.currentThread().sleep( 60000 ) ;
} catch ( InterruptedException e ) {}
}
}
-------------------------------------------------------------------
Regards
Roshini
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Live Video Transmission-Help Required very urgently