A
Aakansha
The code given below is not sending RTP packets using JMF.
can any one suggest how can i enable below code for sending RTP
Packets.
import javax.media.*;
import javax.media.control.*;
import javax.media.datasink.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.control.TrackControl;
import jmapps.util.StateHelper;
import javax.media.rtp.*;
import javax.media.rtp.rtcp.*;
import javax.media.rtp.event.*;
import com.sun.media.rtp.*;
import com.sun.media.ui.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.net.InetAddress;
import java.applet.*;
public class RTPSender extends Applet{
public void init() {
doSendProcessor();
}
private void doSendProcessor(){
CaptureDeviceInfo di = null;
Processor processor = null;
di = getDeviceInfo();
// create a processor for this capturedevice and exit if we
cann't create it
try{
processor =
Manager.createProcessor(di.getLocator());
}catch(IOException ioEX){
ioEX.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
//configure the processor
processor.configure();
while(processor.getState()!=processor.Configured){
//System.out.println(processor.getState()+" state
"+processor.Configured);
}
processor.setContentDescriptor(new
ContentDescriptor(ContentDescriptor.RAW));
TrackControl track[] = processor.getTrackControls();
//value of encodingOK determine we can send GSM data or not
//if value of encodingOK is true means we can send GSM data
boolean encodingOK = false;
//go through the tracks and try to program one of them to
//output GSM Data
for(int i=0;i<track.length;i++){
//System.out.println("track:-> "+track);
if(!encodingOK && track instanceof FormatControl){
boolean abc = track instanceof FormatControl;
//System.out.println("track instanceof
FormatControl:-> "+abc);
if((track).setFormat(new
AudioFormat(AudioFormat.GSM_RTP,8000,8,1))==null){
track.setEnabled(false);
}else{
encodingOK = true;
}
}else{
track.setEnabled(false);
}
}
//System.out.println("encodingOK:-> "+encodingOK);
//realize the processor
if(encodingOK){
processor.realize();
while(processor.getState()!=Processor.Realized){
//System.out.println(processor.getState()+" real
"+processor.Configured);
}
}
// get the output datasource of the processor and exit if we
fail
DataSource ds = null;
try{
ds = processor.getDataOutput();
}catch(NotRealizedError e){
e.printStackTrace();
}
// use datasource fot creating an RTP datasink
//our RTP datasink will multicast the audio.
/*
try{
String url = "rtp://192.168.1.7:5000/audio/1";
MediaLocator m = new MediaLocator(url);
DataSink d = Manager.createDataSink(ds,m);
d.open();
d.start();
processor.start();
}catch(Exception e){
System.out.println("");
e.printStackTrace();
}
*/
//create a SessionManager and hand over the
//datasource for SendStream creation
try{
SessionManager rtpsm = new RTPSessionMgr();
SessionAddress localaddr = new SessionAddress();
InetAddress destaddr =
InetAddress.getByName("192.168.1.2");
SessionAddress sessaddr = new SessionAddress(destaddr,
5000,destaddr,5000+1);
//ask RTPSM to generetion the local participant CName
String cname = rtpsm.generateCNAME();
SourceDescription[] userdesclist = new SourceDescription[]
{new
SourceDescription(SourceDescription.SOURCE_DESC_EMAIL,"(e-mail address removed)",
1,false) ,new
SourceDescription(SourceDescription.SOURCE_DESC_CNAME,cname,
1,false),new SourceDescription(SourceDescription.SOURCE_DESC_TOOL,"JMF
RTP Player v2.0",1,false)};
// the session manager then needs to be initialized and
started:
rtpsm.initSession(localaddr,userdesclist,0.05,0.25);
rtpsm.startSession(sessaddr,1,null);
SendStream sendStream = rtpsm.createSendStream(ds, 0);
sendStream.start();
}catch(IOException io){
//System.out.println("");
io.printStackTrace();
}catch(UnsupportedFormatException e){
//System.out.println("");
e.printStackTrace();
}catch(Exception e){
//System.out.println("");
e.printStackTrace();
}
}
private CaptureDeviceInfo getDeviceInfo(){
CaptureDeviceInfo di = null;
AudioFormat a = new AudioFormat (AudioFormat.LINEAR, 8000, 16,
1);
Vector deviceList =
CaptureDeviceManager.getDeviceList(a);
if(deviceList!=null){
if(deviceList.size()>0)
di = (CaptureDeviceInfo) deviceList.elementAt(0);
else
System.out.println("no device is captured");
}else{
//g.drawString("Vector not Initialized",50,25);
System.out.println("Vector not Initialized");
}
return di;
}
}
can any one suggest how can i enable below code for sending RTP
Packets.
import javax.media.*;
import javax.media.control.*;
import javax.media.datasink.*;
import javax.media.format.*;
import javax.media.protocol.*;
import javax.media.control.TrackControl;
import jmapps.util.StateHelper;
import javax.media.rtp.*;
import javax.media.rtp.rtcp.*;
import javax.media.rtp.event.*;
import com.sun.media.rtp.*;
import com.sun.media.ui.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.net.InetAddress;
import java.applet.*;
public class RTPSender extends Applet{
public void init() {
doSendProcessor();
}
private void doSendProcessor(){
CaptureDeviceInfo di = null;
Processor processor = null;
di = getDeviceInfo();
// create a processor for this capturedevice and exit if we
cann't create it
try{
processor =
Manager.createProcessor(di.getLocator());
}catch(IOException ioEX){
ioEX.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
//configure the processor
processor.configure();
while(processor.getState()!=processor.Configured){
//System.out.println(processor.getState()+" state
"+processor.Configured);
}
processor.setContentDescriptor(new
ContentDescriptor(ContentDescriptor.RAW));
TrackControl track[] = processor.getTrackControls();
//value of encodingOK determine we can send GSM data or not
//if value of encodingOK is true means we can send GSM data
boolean encodingOK = false;
//go through the tracks and try to program one of them to
//output GSM Data
for(int i=0;i<track.length;i++){
//System.out.println("track:-> "+track);
if(!encodingOK && track instanceof FormatControl){
boolean abc = track instanceof FormatControl;
//System.out.println("track instanceof
FormatControl:-> "+abc);
if((track).setFormat(new
AudioFormat(AudioFormat.GSM_RTP,8000,8,1))==null){
track.setEnabled(false);
}else{
encodingOK = true;
}
}else{
track.setEnabled(false);
}
}
//System.out.println("encodingOK:-> "+encodingOK);
//realize the processor
if(encodingOK){
processor.realize();
while(processor.getState()!=Processor.Realized){
//System.out.println(processor.getState()+" real
"+processor.Configured);
}
}
// get the output datasource of the processor and exit if we
fail
DataSource ds = null;
try{
ds = processor.getDataOutput();
}catch(NotRealizedError e){
e.printStackTrace();
}
// use datasource fot creating an RTP datasink
//our RTP datasink will multicast the audio.
/*
try{
String url = "rtp://192.168.1.7:5000/audio/1";
MediaLocator m = new MediaLocator(url);
DataSink d = Manager.createDataSink(ds,m);
d.open();
d.start();
processor.start();
}catch(Exception e){
System.out.println("");
e.printStackTrace();
}
*/
//create a SessionManager and hand over the
//datasource for SendStream creation
try{
SessionManager rtpsm = new RTPSessionMgr();
SessionAddress localaddr = new SessionAddress();
InetAddress destaddr =
InetAddress.getByName("192.168.1.2");
SessionAddress sessaddr = new SessionAddress(destaddr,
5000,destaddr,5000+1);
//ask RTPSM to generetion the local participant CName
String cname = rtpsm.generateCNAME();
SourceDescription[] userdesclist = new SourceDescription[]
{new
SourceDescription(SourceDescription.SOURCE_DESC_EMAIL,"(e-mail address removed)",
1,false) ,new
SourceDescription(SourceDescription.SOURCE_DESC_CNAME,cname,
1,false),new SourceDescription(SourceDescription.SOURCE_DESC_TOOL,"JMF
RTP Player v2.0",1,false)};
// the session manager then needs to be initialized and
started:
rtpsm.initSession(localaddr,userdesclist,0.05,0.25);
rtpsm.startSession(sessaddr,1,null);
SendStream sendStream = rtpsm.createSendStream(ds, 0);
sendStream.start();
}catch(IOException io){
//System.out.println("");
io.printStackTrace();
}catch(UnsupportedFormatException e){
//System.out.println("");
e.printStackTrace();
}catch(Exception e){
//System.out.println("");
e.printStackTrace();
}
}
private CaptureDeviceInfo getDeviceInfo(){
CaptureDeviceInfo di = null;
AudioFormat a = new AudioFormat (AudioFormat.LINEAR, 8000, 16,
1);
Vector deviceList =
CaptureDeviceManager.getDeviceList(a);
if(deviceList!=null){
if(deviceList.size()>0)
di = (CaptureDeviceInfo) deviceList.elementAt(0);
else
System.out.println("no device is captured");
}else{
//g.drawString("Vector not Initialized",50,25);
System.out.println("Vector not Initialized");
}
return di;
}
}