| | |
converting codecs of a rtp stream
![]() |
•
•
Join Date: Apr 2005
Posts: 21
Reputation:
Solved Threads: 0
Hi every one...I am modifying an application that make the Pc speaker have acces to the rtp stream comming from a telephone. The problem is, the rtp stream could be one of G.711U or G.711A or G.729 or G.729A depending on which codec was setup and the Speaker supports PCM_UNSIGNED. i need to do the conversion. The app works but I get horrible noise and I think is because the lack of conversion. The code is:
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import com.avaya.api.media.channels.MediaSink;
public class TutorialSpeaker implements MediaSink{
// Constants for Audio Format
private static final AudioFormat.Encoding ENCODING =
AudioFormat.Encoding.PCM_UNSIGNED;
private static final int SAMPLE_SIZE_IN_BITS = 8; // 8bits per PCM sample
private static final float SAMPLE_RATE = 8000; // 8Khz sampling rate
private static final int CHANNELS = 1; // monoaural system
// sampleSizeInBytes * channels
private static final int FRAME_SIZE = CHANNELS * SAMPLE_SIZE_IN_BITS / 8;
//sampleRate/frameSize; frames per sec
private static final float FRAME_RATE = SAMPLE_RATE;
// true for network byte order
private static final boolean BIG_ENDIAN = true;
private SourceDataLine sourcedataline;
private AudioFormat audioFormat = null;
private DataLine.Info targetInfo = null;
private String codec;
private int packetSize;
public TutorialSpeaker(){
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
SAMPLE_RATE,SAMPLE_SIZE_IN_BITS,
CHANNELS,FRAME_SIZE,
FRAME_RATE,BIG_ENDIAN);
targetInfo = new DataLine.Info(SourceDataLine.class,audioFormat);
if (!AudioSystem.isLineSupported(targetInfo)) {
System.out.println("WARNING: Unsupported Source Data Line Format");
}
}
/**
* The Client Media Stack (i.e. The Audio RTP Receiver)
* uses the write method to deliver a ByteBuffer to the Speaker (MediaSink)
*/
public int write(ByteBuffer src) throws IOException {
// Start the Speaker if not already open
if((sourcedataline == null) || (!sourcedataline.isOpen())){
try {
sourcedataline =
(SourceDataLine)AudioSystem.getLine(targetInfo);
sourcedataline.open(audioFormat);
sourcedataline.start();
} catch (LineUnavailableException e) {
throw new IOException(e.getMessage());
}
}
int bytesWritten = 0;
if(sourcedataline.available() >= src.remaining()){
I NEED TO DO THE CONVERSION IN HERE!!!
bytesWritten = sourcedataline.write(src.array(),src.arrayOffset(),
src.remaining());
// System.out.println("bytes Written= " +bytesWritten);
}
return bytesWritten;
}
/**
* Closes the Speaker (and hence this MediaSink)
*/
public void close() throws IOException {
if(sourcedataline != null)
sourcedataline.close();
}
/**
* Return the status of the Speaker
*/
public boolean isOpen() {
return true;
}
/**
* Sets the Codec type and packet Size of the source.
* This is the codec and packetSize of the incoming Audio RTP
* Stream.
*/
public void setCodec(String codec, int packetSize) {
this.codec = codec;
this.packetSize = packetSize;
}
/**
* Gets the codec of the Audio RTP Stream being used
* by the Speaker.
*/
public String getCodec() {
return codec;
}
/**
* Gets the packetSize of the Audio RTP Stream being used by
* the Speaker.
*/
public int getPacketSize() {
return packetSize;
}
}
tHANKS FOR YOUR HELP!
import java.io.IOException;
import java.nio.ByteBuffer;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.DataLine;
import com.avaya.api.media.channels.MediaSink;
public class TutorialSpeaker implements MediaSink{
// Constants for Audio Format
private static final AudioFormat.Encoding ENCODING =
AudioFormat.Encoding.PCM_UNSIGNED;
private static final int SAMPLE_SIZE_IN_BITS = 8; // 8bits per PCM sample
private static final float SAMPLE_RATE = 8000; // 8Khz sampling rate
private static final int CHANNELS = 1; // monoaural system
// sampleSizeInBytes * channels
private static final int FRAME_SIZE = CHANNELS * SAMPLE_SIZE_IN_BITS / 8;
//sampleRate/frameSize; frames per sec
private static final float FRAME_RATE = SAMPLE_RATE;
// true for network byte order
private static final boolean BIG_ENDIAN = true;
private SourceDataLine sourcedataline;
private AudioFormat audioFormat = null;
private DataLine.Info targetInfo = null;
private String codec;
private int packetSize;
public TutorialSpeaker(){
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_UNSIGNED,
SAMPLE_RATE,SAMPLE_SIZE_IN_BITS,
CHANNELS,FRAME_SIZE,
FRAME_RATE,BIG_ENDIAN);
targetInfo = new DataLine.Info(SourceDataLine.class,audioFormat);
if (!AudioSystem.isLineSupported(targetInfo)) {
System.out.println("WARNING: Unsupported Source Data Line Format");
}
}
/**
* The Client Media Stack (i.e. The Audio RTP Receiver)
* uses the write method to deliver a ByteBuffer to the Speaker (MediaSink)
*/
public int write(ByteBuffer src) throws IOException {
// Start the Speaker if not already open
if((sourcedataline == null) || (!sourcedataline.isOpen())){
try {
sourcedataline =
(SourceDataLine)AudioSystem.getLine(targetInfo);
sourcedataline.open(audioFormat);
sourcedataline.start();
} catch (LineUnavailableException e) {
throw new IOException(e.getMessage());
}
}
int bytesWritten = 0;
if(sourcedataline.available() >= src.remaining()){
I NEED TO DO THE CONVERSION IN HERE!!!
bytesWritten = sourcedataline.write(src.array(),src.arrayOffset(),
src.remaining());
// System.out.println("bytes Written= " +bytesWritten);
}
return bytesWritten;
}
/**
* Closes the Speaker (and hence this MediaSink)
*/
public void close() throws IOException {
if(sourcedataline != null)
sourcedataline.close();
}
/**
* Return the status of the Speaker
*/
public boolean isOpen() {
return true;
}
/**
* Sets the Codec type and packet Size of the source.
* This is the codec and packetSize of the incoming Audio RTP
* Stream.
*/
public void setCodec(String codec, int packetSize) {
this.codec = codec;
this.packetSize = packetSize;
}
/**
* Gets the codec of the Audio RTP Stream being used
* by the Speaker.
*/
public String getCodec() {
return codec;
}
/**
* Gets the packetSize of the Audio RTP Stream being used by
* the Speaker.
*/
public int getPacketSize() {
return packetSize;
}
}
tHANKS FOR YOUR HELP!
![]() |
Similar Threads
- Video stream with ASP.NET (ASP.NET)
- fstream Tutorial (C++)
- Data stored in Records (C#)
- RTP strem in the PC speaker (Java)
- Converting from VB code to C (C)
- Zend PHP Certification (PHP)
- VC++:convert File IStream to hex and store...? (C++)
Other Threads in the Java Forum
- Previous Thread: How to make connection to database more dynamically using hibernate.
- Next Thread: Help me please.
| Thread Tools | Search this Thread |
account android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) chat class classes client code columns component database designadrawingapplicationusingjavajslider draw eclipse error errors exception expand fractal game givemetehcodez graphics gui guidancer homework html ide image inetaddress inheritance input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jlabel jme jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile mobiledevelopmentcreatejar monitoring myaggfun netbeans newbie nullpointerexception open-source plazmic print problem program programming project property recursion ria scanner search server set smart sms smsspam sort sourcelabs splash sql sqlite static string subclass support swing testautomation threads tree webservices windows






