aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Help with voice chat using JMF 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 "Help with voice chat using JMF" Watch "Help with voice chat using JMF" New topic
Author

Help with voice chat using JMF

Kee Kong Sim
Greenhorn

Joined: Jan 13, 2005
Posts: 5
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();
}
}
}
Stanley George
Ranch Hand

Joined: Dec 09, 2000
Posts: 55
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
zaheer zuhrab
Greenhorn

Joined: May 09, 2009
Posts: 3
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();
}
}
}
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

http://faq.javaranch.com/java/UseCodeTags
http://faq.javaranch.com/java/DontWakeTheZombies


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with voice chat using JMF