Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Help with voice chat using JMF  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently doing a voice & text chat in a LAN, after connection, text able to deliver to target computer in the same LAN but no voice transsmission. Here is my source code, what I have doing wrong? Any expert out there plz help me.


// Capture and Send Audio

import java.io.*;
import java.util.Vector;
import javax.media.protocol.*;
import javax.media.*;
import javax.media.rtp.*;
import java.net.*;


public class CaptureNSend {

CaptureDeviceInfo di;
Processor process;
DataSource DSource;
SendStream sStream;
SessionManager sesManager;
SessionAddress sessionAdd;
RTPManager rtpMgr;
Processor p=null;
String IP;
MediaLocator Locate;
public CaptureNSend(String ip) {
IP = ip;
//AudioFormat format = new AudioFormat("LINEAR", 8000, 8, 1);

Vector deviceList = CaptureDeviceManager.getDeviceList(new Format("linear"));
System.out.println(deviceList.size());
if (deviceList.size() > 0) {
di = (CaptureDeviceInfo)deviceList.get(1);
System.out.println(di.getName());
di = (CaptureDeviceInfo)deviceList.get(deviceList.size() - 1);
System.out.println(di.getName());
}
else
System.exit(-1);

MediaLocator locate = di.getLocator();

Locate = locate;
try{
p = Manager.createProcessor(Locate);
p.addControllerListener(new ProcessorEventHandler());

p.configure();
}catch(Exception e){
e.printStackTrace();
}

}


public void setOutputFormat(){

p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));

System.out.println("Audio Format Set");
// transmitMedia();
}


public void setupSession () {
DSource = p.getDataOutput();
rtpMgr = RTPManager.newInstance();
System.out.println("source checked");
int port = 5000;

try {
InetAddress local=InetAddress.getLocalHost();
System.out.println("inetaddress checked");
sessionAdd = new SessionAddress(local,port);
InetAddress remote =InetAddress.getByName(IP);
SessionAddress tarAdd = new SessionAddress(remote,6638);
System.out.println(port);
System.out.println("Session address checked");

rtpMgr.initialize(sessionAdd);
rtpMgr.addTarget(tarAdd);
System.out.println("session add peer checked");
sStream = rtpMgr.createSendStream(DSource,0);
System.out.println("sending media");
sStream.start();
p.start();
} catch (Exception e) {
e.printStackTrace();
}
}


private class ProcessorEventHandler extends ControllerAdapter{

public void configureComplete(ConfigureCompleteEvent configureCompleteEvent) {

setOutputFormat();

System.out.println(" Configured");
p.realize();
}

public void realizeComplete (RealizeCompleteEvent realizeCompleteEvent) {

setupSession();
}

public void endOfMedia ( EndOfMediaEvent mediaEndEvent) {
stopTransmission();
System.out.println("Transmission completed.");
}
}

public void stopTransmission() {

}

/*public static void main(String[] args) {
CaptureNSend sCapture = new CaptureNSend();
} */

}


-------------------------------------------------------------------

// Receive and Playback Audio

import javax.media.*;
import java.util.*;

public class ReceiveMedia{
String ip = "10.10.50.171";
int port = 5000;
Player player;

public ReceiveMedia(){
String location = "rtp://" + ip + ":" + port + "/" + "audio" + "/1";
System.out.println("Setting up MediaLocator");
MediaLocator media = new MediaLocator(location);

try{
player = Manager.createPlayer(media);
player.addControllerListener(new PlayerHandlerEvent());
player.realize();
System.out.println("Player Realized");

} catch(Exception e){
e.printStackTrace();
}
}


public class PlayerHandlerEvent extends ControllerAdapter{

public void realizeComplete(RealizeCompleteEvent realizeDoneEvent){
player.prefetch();
}

public void prefetchComplete(PrefetchCompleteEvent prefetchDoneEvent){
player.start();
System.out.println("Start Playback");
} //end prefetchComplete method

public void endOfMedia(EndOfMediaEvent mediaEndEvent) {
player.setMediaTime(new Time(0));
player.stop();
}
}
}
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kee,
Try using this audio format : AudioFormat(AudioFormat.MPEG_RTP, 44100, 16, 2);
You may also want to try replacing MPEG_RTP with GSM_RTP.

Cheers
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took this code from same forum I am trying to capture and then play the audio on other Computer but it is not working can any one help me i tried different methods of format but there is no out put please help me or any one can give me any other code related to JMF of voice chat I shall be thank full
// Capture and Send Audio

import java.io.*;
import java.util.Vector;
import javax.media.protocol.*;
import javax.media.*;
import javax.media.rtp.*;
import java.net.*;
import javax.media.format.AudioFormat;


public class CaptureNSend {

CaptureDeviceInfo di;
Processor process;
DataSource DSource;
SendStream sStream;
SessionManager sesManager;
SessionAddress sessionAdd;
RTPManager rtpMgr;
Processor p=null;
String IP;
MediaLocator Locate;
public CaptureNSend(String ip) {
IP = ip;
//AudioFormat format = new AudioFormat("LINEAR", 8000, 8, 1);

//Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.MPEG_RTP, 44100, 16, 2));
//Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat(AudioFormat.GSM_RTP,44100,16,2));
//Vector deviceList = CaptureDeviceManager.getDeviceList(new Format(AudioFormat.MPEG_RTP,44100,16,2));
Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
//List list = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
System.out.println(deviceList.size());
if (deviceList.size() > 0) {
di = (CaptureDeviceInfo)deviceList.get(1);
System.out.println(di.getName());
di = (CaptureDeviceInfo)deviceList.get(deviceList.size() - 1);
System.out.println(di.getName());
}
else
System.exit(-1);

MediaLocator locate = di.getLocator();

Locate = locate;
try{
p = Manager.createProcessor(Locate);
p.addControllerListener(new ProcessorEventHandler());

p.configure();
}catch(Exception e){
e.printStackTrace();
}

}


public void setOutputFormat(){

p.setContentDescriptor(new ContentDescriptor(ContentDescriptor.RAW_RTP));

System.out.println("Audio Format Set");
// transmitMedia();
}


public void setupSession () {
DSource = p.getDataOutput();
rtpMgr = RTPManager.newInstance();
System.out.println("source checked");
int port = 5000;

try {
InetAddress local=InetAddress.getLocalHost();
System.out.println("inetaddress checked");
sessionAdd = new SessionAddress(local,port);
InetAddress remote =InetAddress.getByName(IP);
SessionAddress tarAdd = new SessionAddress(remote,6638);
System.out.println(port);
System.out.println("Session address checked");

rtpMgr.initialize(sessionAdd);
rtpMgr.addTarget(tarAdd);
System.out.println("session add peer checked");
sStream = rtpMgr.createSendStream(DSource,0);
System.out.println("sending media");
sStream.start();
p.start();
} catch (Exception e) {
e.printStackTrace();
}
}


private class ProcessorEventHandler extends ControllerAdapter{

public void configureComplete(ConfigureCompleteEvent configureCompleteEvent) {

setOutputFormat();

System.out.println(" Configured");
p.realize();
}

public void realizeComplete (RealizeCompleteEvent realizeCompleteEvent) {

setupSession();
}

public void endOfMedia ( EndOfMediaEvent mediaEndEvent) {
stopTransmission();
System.out.println("Transmission completed.");
}
}

public void stopTransmission() {

}

public static void main(String[] args) {
CaptureNSend sCapture = new CaptureNSend("192.168.1.51");
}

}
-------------------------------------------------------------------

// Receive and Playback Audio

import javax.media.*;
import java.util.*;

public class ReceiveMedia{
String ip = "10.10.50.171";
int port = 5000;
Player player;

public ReceiveMedia(){
String location = "rtp://"; + ip + ":" + port + "/" + "audio" + "/1";
System.out.println("Setting up MediaLocator");
MediaLocator media = new MediaLocator(location);

try{
player = Manager.createPlayer(media);
player.addControllerListener(new PlayerHandlerEvent());
player.realize();
System.out.println("Player Realized");

} catch(Exception e){
e.printStackTrace();
}
}


public class PlayerHandlerEvent extends ControllerAdapter{

public void realizeComplete(RealizeCompleteEvent realizeDoneEvent){
player.prefetch();
}

public void prefetchComplete(PrefetchCompleteEvent prefetchDoneEvent){
player.start();
System.out.println("Start Playback");
} //end prefetchComplete method

public void endOfMedia(EndOfMediaEvent mediaEndEvent) {
player.setMediaTime(new Time(0));
player.stop();
}
}
}
 
Sheriff
Posts: 21638
101
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!