converting codecs of a rtp stream

Reply

Join Date: Apr 2005
Posts: 21
Reputation: luisator is an unknown quantity at this point 
Solved Threads: 0
luisator luisator is offline Offline
Newbie Poster

converting codecs of a rtp stream

 
0
  #1
Jun 9th, 2005
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!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 1
Reputation: jmix90 is an unknown quantity at this point 
Solved Threads: 0
jmix90 jmix90 is offline Offline
Newbie Poster

Re: converting codecs of a rtp stream

 
0
  #2
Apr 12th, 2008
Hello,

Did you find an answer ?

I'am looking for it too ...


Bye,
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 3,584
Reputation: jasimp has a spectacular aura about jasimp has a spectacular aura about jasimp has a spectacular aura about 
Solved Threads: 52
Featured Poster
jasimp's Avatar
jasimp jasimp is online now Online
Senior Poster

Re: converting codecs of a rtp stream

 
0
  #3
Apr 12th, 2008
They probably don't even remember this place exists seeing as this thread was made almost 3 years ago and their last post was 2.5 years ago.
"Argyou not with the hand you are dealt in cards or life." ---- Wizard and Glass
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC