# 1
I find the solution :
It's a mixe between the link upside, com.ibm.media.codec.alaw.JavaDecoder, com.ibm.media.codec.ulaw.JavaDecoder and http://java.sun.com/products/java-media/jmf/2.1.1/solutions/PcmDepacketizer.java
class AlawRtpDecoder.java
import javax.media.Buffer;
import javax.media.Control;
import javax.media.Format;
import javax.media.format.AudioFormat;
import com.sun.media.controls.SilenceSuppressionAdapter;
/**
* Mu-Law to PCM java decoder
*
* @Author Shay Ben-David bendavid@haifa.vnet.ibm.com
*/
public class AlawRtpDecoder extends com.ibm.media.codec.audio.AudioCodec {
// //////////////////////////////////////////////////////////////////////////
// Variables
// //////////////////////////////////////////////////////////////////////////
static private final byte[] lutTableL = new byte[256];
static private final byte[] lutTableH = new byte[256];
static String PLUGIN_NAME = "ALAW_RTP DePacketizer";
static String CUSTOM_PCM = "alaw/rtp";
static int DEFAULT_RATE = 8000;
static int DEFAULT_SIZE = 16;
static int DEFAULT_CHNLS = 1;
// //////////////////////////////////////////////////////////////////////////
// Methods
////////////////////////////////////////////////////////////////////////////
public AlawRtpDecoder() {
supportedInputFormats = new AudioFormat[] { new AudioFormat(CUSTOM_PCM) };
// We have to assume some defaults for the output
// format. Otherwise, the data flow graph cannot
// be initialized.
supportedOutputFormats = new AudioFormat[] { new AudioFormat(
AudioFormat.LINEAR, DEFAULT_RATE, DEFAULT_SIZE, DEFAULT_CHNLS) };
}
protected Format[] getMatchingOutputFormats(Format in) {
AudioFormat af = (AudioFormat) in;
supportedOutputFormats = new AudioFormat[] { new AudioFormat(
AudioFormat.LINEAR, af.getSampleRate(), 16, af.getChannels(),
AudioFormat.LITTLE_ENDIAN, // isBigEndian(),
AudioFormat.SIGNED // isSigned());
) };
return supportedOutputFormats;
}
/** Initializes the codec. * */
public void open() {
initTables();
}
public String getName() {
return PLUGIN_NAME;
}
static public boolean matche(Format input, Format supported[]) {
for (int i = 0; i < supported.length; i++) {
if (input.matches(supported[i]))
return true;
}
return false;
}
public Format[] getSupportedOutputFormats(Format input) {
if (input == null || matche(input, supportedInputFormats)) {
return supportedOutputFormats;
}
return new Format[0];
}
public Format setInputFormat(Format format) {
if (!matche(format, supportedInputFormats))
return null;
inputFormat = (AudioFormat) format;
return format;
}
public Format setOutputFormat(Format format) {
if (!matche(format, supportedOutputFormats))
return null;
outputFormat = (AudioFormat) format;
return format;
}
public Format[] getSupportedInputFormats() {
return supportedInputFormats;
}
protected Format getInputFormat() {
return inputFormat;
}
protected Format getOutputFormat() {
return outputFormat;
}
public void close() {
}
/** decode the buffer * */
public int process(Buffer inputBuffer, Buffer outputBuffer) {
if (!checkInputBuffer(inputBuffer)) {
return BUFFER_PROCESSED_FAILED;
}
if (isEOM(inputBuffer)) {
propagateEOM(outputBuffer);
return BUFFER_PROCESSED_OK;
}
byte[] inData = (byte[]) inputBuffer.getData();
byte[] outData = validateByteArraySize(outputBuffer, inData.length * 2);
int inpLength = inputBuffer.getLength();
int outLength = 2 * inpLength;
int inOffset = inputBuffer.getOffset();
int outOffset = outputBuffer.getOffset();
for (int i = 0; i < inpLength; i++) {
int temp = inData[inOffset++] & 0xff;
outData[outOffset++] = lutTableL[temp];
outData[outOffset++] = lutTableH[temp];
}
updateOutput(outputBuffer, outputFormat, outLength, outputBuffer.getOffset());
return BUFFER_PROCESSED_OK;
}
private void initTables (){
for (int i=0;i<256;i++) {
int input= i ^ 0x55;
int mantissa = (input & 0xf ) << 4;
int segment= (input & 0x70) >> 4;
int value= mantissa+8;
if (segment>=1)
value+=0x100;
if (segment>1)
value <<= (segment - 1);
if ( (input & 0x80)==0 )
value = -value;
lutTableL[i]=(byte)value;
lutTableH[i]=(byte)(value>>8);
}
}
public java.lang.Object[] getControls() {
if (controls == null) {
controls = new Control[1];
controls[0] = new SilenceSuppressionAdapter(this, false, false);
}
return (Object[]) controls;
}
}
for use this juste add the following codec in your main program
RTPManager manager = RTPManager.newInstance();
AlawRtpDecoder alawRtpDepktizer = null;
try
{
alawRtpDepktizer = new AlawRtpDecoder();
PlugInManager.addPlugIn(alawRtpDepktizer.getClass().getName(),
alawRtpDepktizer.getSupportedInputFormats(),
alawRtpDepktizer.getSupportedOutputFormats(null),
PlugInManager.CODEC);
Format AlawRtpFormat =(alawRtpDepktizer.getSupportedInputFormats())[0];
manager.addFormat(AlawRtpFormat, 8);
}
null