LINEAR to DVI_RTP encoding
Hi,
I am trying to encode from microphone LINEAR to DVI_RTP. Please, could anyone point me what I am doing wrong?
Or could anyone point me to any example? (I do not need to use RTP/RTCP. I need just plain RTP data that will be sent by my own RTP/RTCP protocol)
Any help would be really appreciated.
Here is output:
############## SUPPORTED INPUT
0:LINEAR, Unknown Sample Rate, 16-bit, Mono, LittleEndian, Signed
############## SUPPORTED OUTPUT
0:dvi/rtp, 8000.0 Hz, 4-bit, Mono
-
############## SELECTED INPUT:LINEAR, 8000.0 Hz, 16-bit, Mono
############## SELECTED OUTPUT:dvi/rtp, 8000.0 Hz, 4-bit, Mono
-
INPUT LENGTH:20000
-
Exception in thread"main" java.lang.NullPointerException
at java.lang.System.arraycopy(Native Method)
at com.ibm.media.codec.audio.AudioPacketizer.process(AudioPacketizer.java:62)
at com.ibm.media.codec.audio.dvi.JavaEncoder.process(JavaEncoder.java:116)
at EncInfo.main(EncInfo.java:53)
Here is my code:
import javax.media.Buffer;
import javax.media.Format;
import javax.media.format.AudioFormat;
import com.ibm.media.codec.audio.dvi.JavaEncoder;
import com.sun.media.BasicCodec;
publicclass EncInfo{
publicstaticvoid main(String[] args){
int frameSize = 2000;
byte[] arr =newbyte[frameSize];
JavaEncoder enc =new JavaEncoder();
Format f[] = enc.getSupportedInputFormats();
printFormats("SUPPORTED INPUT", f);
AudioFormat frmt =new AudioFormat(AudioFormat.LINEAR, 8000f, 16, 1);
Format f2[] = enc.getSupportedOutputFormats(frmt);
printFormats("SUPPORTED OUTPUT", f2);
System.out.println("-");
printFormats("SELECTED INPUT ", frmt);
enc.setInputFormat(frmt);
printFormats("SELECTED OUTPUT", f2[0]);
enc.setOutputFormat(f2[0]);
System.out.println("-");
int inBuffLen = 20000;
byte buffer2[] =newbyte[inBuffLen];
byte buffer3[] =newbyte[inBuffLen];
System.out.println("INPUT LENGTH:" + inBuffLen);
System.out.println("-");
// preparing buffers
Buffer inRawBuffer =new Buffer();
inRawBuffer.setData(arr);
inRawBuffer.setLength(2000);
Buffer dviBuffer =new Buffer();
dviBuffer.setData(buffer2);
Buffer outRawBuffer =new Buffer();
outRawBuffer.setData(buffer3);
// ENCODE
int res = BasicCodec.BUFFER_PROCESSED_FAILED;
int counter = 0;
do{
res = enc.process(inRawBuffer, outRawBuffer);
counter++;
}while (res == BasicCodec.INPUT_BUFFER_NOT_CONSUMED);
System.out.println("COUNTER: " + counter);
}
publicstaticvoid printFormats(String str, Format f[]){
System.out.println();
System.out.println("############## " + str);
for (int i = 0; i < f.length; i++){
System.out.println("" + i +":" + f[i]);
}
}
publicstaticvoid printFormats(String str, Format f){
System.out.print("############## " + str +"");
System.out.println(":" + f);
}
// sound frame sample 8000 Hz, 16 bits/sample = 2000
byte arr[] ={ 0, 0, 0, 0, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1, -2, -1,
-6, -1, -6, -1, -28, -1, -28, -1, 48, -1, 48, -1, 44, -1, 44, -1,
54, -1, 54, -1, 84, -1, 84, -1, -44, -1, -44, -1, 118, 1, 118, 1,
-58, -9, -58, -9, -2, -7, -2, -7, -34, -6, -34, -6, 72, -5, 72, -5,
-104, -5, -104, -5, -64, -5, -64, -5, -26, -5, -26, -5, 2, -4, 2,
-4, 20, -4, 20, -4, 44, -4, 44, -4, 72, -4, 72, -4, 94, -4, 94, -4,
118, -4, 118, -4, 122, -4, 122, -4, 114, -4, 114, -4, 116, -4, 116,
-4, 110, -4, 110, -4, 94, -4, 94, -4, 78, -4, 78, -4, 62, -4, 62,
-4, 40, -4, 40, -4, 22, -4, 22, -4, 2, -4, 2, -4, -2, -5, -2, -5,
-10, -5, -10, -5, -10, -5, -10, -5, -4, -5, -4, -5, 6, -4, 6, -4,
14, -4, 14, -4, 26, -4, 26, -4, 34, -4, 34, -4, 32, -4, 32, -4, 26,
-4, 26, -4, 22, -4, 22, -4, 14, -4, 14, -4, 14, -4, 14, -4, 18, -4,
18, -4, 22, -4, 22, -4, 38, -4, 38, -4, 52, -4, 52, -4, 84, -4, 84,
-4, 104, -4, 104, -4, 120, -4, 120, -4, -116, -4, -116, -4, -100,
-4, -100, -4, -88, -4, -88, -4, -78, -4, -78, -4, -78, -4, -78, -4,
-78, -4, -78, -4, -82, -4, -82, -4, -86, -4, -86, -4, -94, -4, -94,
-4, -104, -4, -104, -4, -104, -4, -104, -4, -114, -4, -114, -4,
-126, -4, -126, -4, -128, -4, -128, -4, 118, -4, 118, -4, 108, -4,
108, -4, 94, -4, 94, -4, 82, -4, 82, -4, 66, -4, 66, -4, 50, -4,
50, -4, 40, -4, 40, -4, 28, -4, 28, -4, 14, -4, 14, -4, -4, -5, -4,
-5, -20, -5, -20, -5, -32, -5, -32, -5, -46, -5, -46, -5, -54, -5,
-54, -5, -64, -5, -64, -5, -76, -5, -76, -5, -86, -5, -106, -5,
-106, -5, -124, -5, -124, -5, 112, -5, 112, -5, 92, -5, 92, -5, 74,
-5, 74, -5, 26, -5, 26, -5, -22, -6, -22, -6, -62, -6, -62, -6,
-90, -6, -90, -6, -120, -6, -120, -6, 96, -6, 96, -6, 72, -6, 72,
-6, 76, -6, 76, -6, 78, -6, 78, -6, 80, -6, 80, -6, 80, -6, 80, -6,
82, -6, 82, -6, 82, -6, 82, -6, 82, -6, 82, -6, 84, -6, 84, -6, 86,
-6, 86, -6, 88, -6, 88, -6, 88, -6, 88, -6, 92, -6, 92, -6, 92, -6,
92, -6, 92, -6, 92, -6, 92, -6, 92, -6, 94, -6, 94, -6, 96, -6, 96,
-6, 98, -6, 98, -6, 98, -6, 98, -6, 100, -6, 100, -6, 102, -6, 102,
-6, 102, -6, 102, -6, 104, -6, 104, -6, 104, -6, 104, -6, 106, -6,
106, -6, 108, -6, 108, -6, 110, -6, 110, -6, 112, -6, 112, -6, 112,
-6, 112, -6, 114, -6, 114, -6, 114, -6, 116, -6, 116, -6, 116, -6,
116, -6, 118, -6, 118, -6, 118, -6, 118, -6, 120, -6, 120, -6,
-128, -6, -128, -6, 124, -6, 124, -6, 40, -6, 40, -6, 30, -6, 30,
-6, 36, 0, 36, 0, -54, -2, -54, -2, 50, -2, 50, -2, -68, -3, -68,
-3, 102, -3, 102, -3, 56, -3, 56, -3, 12, -3, 12, -3, -6, -4, -6,
-4, -20, -4, -20, -4, -26, -4, -26, -4, -36, -4, -36, -4, -36, -4,
-36, -4, -46, -4, -46, -4, -40, -4, -40, -4, -24, -4, -24, -4, -16,
-4, -16, -4, -6, -4, -6, -4, -6, -4, -6, -4, 10, -3, 10, -3, 14,
-3, 14, -3, 28, -3, 28, -3, 44, -3, 44, -3, 50, -3, 50, -3, 64, -3,
64, -3, 86, -3, 86, -3, 90, -3, 90, -3, 76, -3, 76, -3, 70, -3, 70,
-3, 82, -3, 82, -3, 74, -3, 74, -3, 72, -3, 72, -3, 86, -3, 86, -3,
94, -3, 94, -3, 94, -3, 94, -3, 100, -3, 100, -3, 92, -3, 92, -3,
88, -3, 88, -3, 92, -3, 92, -3, 80, -3, 80, -3, 40, -2, 40, -2, 72,
-2, 72, -2, 68, -2, 68, -2, 74, -2, 74, -2, 60, -2, 60, -2, 46, -2,
46, -2, 28, -2, 28, -2, 14, -2, 14, -2, 10, -2, 10, -2, 8, -2, 8,
-2, 6, -2, 6, -2, 12, -2, 12, -2, 16, -2, 16, -2, 32, -2, 32, -2,
46, -2, 46, -2, 50, -2, 50, -2, 66, -2, 66, -2, 74, -2, 74, -2, 78,
-2, 78, -2, 78, -2, 78, -2, 92, -2, 92, -2, 104, -2, 104, -2, 112,
-2, 112, -2, -116, -2, -116, -2, -90, -2, -90, -2, -88, -2, -88,
-2, -90, -2, -90, -2, -76, -2, -76, -2, -50, -2, -50, -2, -40, -2,
-40, -2, -28, -2, -28, -2, -6, -2, -6, -2, 16, -1, 16, -1, 32, -1,
32, -1, 40, -1, 40, -1, 58, -1, 58, -1, 76, -1, 76, -1, 88, -1, 88,
-1, 104, -1, 104, -1, -128, -1, -128, -1, -108, -1, -108, -1, -76,
-1, -76, -1, -56, -1, -56, -1, -34, -1, -34, -1, -2, -1, -2, -1,
48, 0, 48, 0, 30, 0, 30, 0, 28, 0, 28, 0, 28, 0, 28, 0, 28, 0, 28,
0, 28, 0, 28, 0, 32, 0, 32, 0, 34, 0, 34, 0, 38, 0, 38, 0, 36, 0,
36, 0, 34, 0, 34, 0, 36, 0, 36, 0, 34, 0, 34, 0, 26, 0, 26, 0, 22,
0, 22, 0, 22, 0, 22, 0, 10, 0, 10, 0, 18, 0, 18, 0, 32, 0, 32, 0,
30, 0, 30, 0, 16, 0, 16, 0, 18, 0, 18, 0, 28, 0, 28, 0, 24, 0, 24,
0, 20, 0, 20, 0, 30, 0, 30, 0, 34, 0, 34, 0, 24, 0, 24, 0, 20, 0,
20, 0, 22, 0, 22, 0, 36, 0, 36, 0, 32, 0, 32, 0, 28, 0, 28, 0, 26,
0, 26, 0, 30, 0, 30, 0, 28, 0, 28, 0, 26, 0, 26, 0, 24, 0, 24, 0,
26, 0, 26, 0, 30, 0, 30, 0, 48, 0, 48, 0, -62, 0, -62, 0, -58, 0,
-58, 0, -52, 0, -52, 0, -54, 0, -54, 0, -58, 0, -58, 0, -52, 0,
-52, 0, -48, 0, -48, 0, -52, 0, -52, 0, -58, 0, -58, 0, -56, 0,
-56, 0, -60, 0, -60, 0, -64, 0, -64, 0, -70, 0, -70, 0, -72, 0,
-72, 0, -80, 0, -80, 0, -78, 0, -78, 0, -64, 0, -64, 0, -60, 0,
-60, 0, -70, 0, -70, 0, -74, 0, -74, 0, -70, 0, -70, 0, -66, 0,
-66, 0, -76, 0, -76, 0, -72, 0, -72, 0, -62, 0, -62, 0, -70, 0,
-70, 0, -74, 0, -74, 0, -72, 0, -72, 0, -70, 0, -70, 0, -58, 0,
-58, 0, -66, 0, -66, 0, -68, 0, -68, 0, -74, 0, -74, 0, -72, 0,
-72, 0, -70, 0, -70, 0, -70, 0, -70, 0, -76, 0, -76, 0, -70, 0,
-70, 0, -70, 0, -70, 0, -70, 0, -70, 0, -70, 0, -70, 0, -72, 0,
-72, 0, -72, 0, -72, 0, -72, 0, -72, 0, -68, 0, -68, 0, -66, 0,
-66, 0, -68, 0, -68, 0, -68, 0, -68, 0, -70, 0, -70, 0, -68, 0,
-68, 0, -78, 0, -78, 0, -80, 0, -80, 0, -84, 0, -84, 0, -92, 0,
-92, 0, -84, 0, -84, 0, -68, 0, -68, 0, -68, 0, -68, 0, -82, 0,
-82, 0, -80, 0, -80, 0, -72, 0, -72, 0, -82, 0, -82, 0, -82, 0,
-82, 0, -76, 0, -76, 0, -72, 0, -72, 0, -76, 0, -76, 0, -84, 0,
-84, 0, -84, 0, -84, 0, -68, 0, -68, 0, -64, 0, -64, 0, -76, 0,
-76, 0, -78, 0, -78, 0, -78, 0, -78, 0, -78, 0, -78, 0, -80, 0,
-80, 0, -84, 0, -84, 0, -82, 0, -82, 0, -82, 0, -82, 0, -82, 0,
-82, 0, -76, 0, -76, 0, -78, 0, -78, 0, -78, 0, -74, 0, -74, 0,
-76, 0, -76, 0, -72, 0, -72, 0, -74, 0, -74, 0, -76, 0, -76, 0,
-76, 0, -76, 0, -74, 0, -74, 0, -78, 0, -78, 0, -90, 0, -90, 0,
-92, 0, -92, 0, -92, 0, -92, 0, -102, 0, -102, 0, -90, 0, -90, 0,
-80, 0, -80, 0, -76, 0, -76, 0, -90, 0, -90, 0, -92, 0, -92, 0,
-86, 0, -86, 0, -90, 0, -90, 0, -92, 0, -92, 0, -86, 0, -86, 0,
-80, 0, -80, 0, -82, 0, -82, 0, -90, 0, -90, 0, -90, 0, -90, 0,
-80, 0, -80, 0, -78, 0, -78, 0, -82, 0, -82, 0, -84, 0, -84, 0,
-84, 0, -84, 0, -84, 0, -84, 0, -86, 0, -86, 0, -84, 0, -84, 0,
-84, 0, -84, 0, -84, 0, -84, 0, -86, 0, -86, 0, -82, 0, -82, 0,
-82, 0, -82, 0, -76, 0, -76, 0, -78, 0, -78, 0, -80, 0, -80, 0,
-76, 0, -78, 0, -78, 0, -74, 0, -74, 0, -76, 0, -76, 0, -80, 0,
-80, 0, -80, 0, -80, 0, -82, 0, -82, 0, -88, 0, -88, 0, -92, 0,
-92, 0, -98, 0, -98, 0, -100, 0, -100, 0, -88, 0, -88, 0, -80, 0,
-80, 0, -88, 0, -88, 0, -98, 0, -98, 0, -94, 0, -94, 0, -84, 0,
-84, 0, -88, 0, -88, 0, -96, 0, -96, 0, -94, 0, -94, 0, -90, 0,
-90, 0, -96, 0, -96, 0, -96, 0, -96, 0, -98, 0, -98, 0, -90, 0,
-90, 0, -84, 0, -84, 0, -86, 0, -86, 0, -94, 0, -94, 0, -94, 0,
-94, 0, -92, 0, -92, 0, -88, 0, -88, 0, -96, 0, -96, 0, -98, 0,
-98, 0, -96, 0, -96, 0, -90, 0, -90, 0, -92, 0, -92, 0, -86, 0,
-86, 0, -86, 0, -86, 0, -90, 0, -90, 0, -90, 0, -90, 0, -86, 0,
-86, 0, -86, 0, -86, 0, -88, 0, -88, 0, -88, 0, -88, 0, -90, 0,
-90, 0, -88, 0, -88, 0, -96, 0, -96, 0, -96, 0, -96, 0, -104, 0,
-104, 0, -110, 0, -110, 0, -100, 0, -100, 0, -86, 0, -86, 0, -96,
0, -96, 0, -108, 0, -108, 0, -100, 0, -100, 0, -96, 0, -96, 0, -98,
0, -98, 0, -106, 0, -106, 0, -96, 0, -96, 0, -90, 0, -90, 0, -98,
0, -98, 0, -104, 0, -104, 0, -98, 0, -98, 0, -94, 0, -94, 0, -94,
0, -94, 0, -96, 0, -96, 0, -104, 0, -104, 0, -98, 0, -98, 0, -92,
0, -92, 0, -102, 0, -102, 0, -100, 0, -100, 0, -98, 0, -98, 0, -98,
0, -98, 0, -102, 0, -102, 0, -98, 0, -98, 0, -94, 0, -94, 0, -92,
0, -92, 0, -92, 0, -92, 0, -90, 0, -90, 0, -90, 0, -90, 0, -88, 0,
-88, 0, -94, 0, -94, 0, -92, 0, -92, 0, -96, 0, -96, 0, -98, 0,
-98, 0, -106, 0, -106, 0, -106, 0, -106, 0, -114, 0, -114, 0, -116,
0, -116, 0, -100, 0, -100, 0, -92, 0, -92, 0, -106, 0, -106, 0,
-114, 0, -114, 0, -104, 0, -104, 0, -102, 0, -102, 0, -106, 0,
-106, 0, -110, 0, -110, 0, -98, 0, -98, 0, -96, 0, -96, 0, -106, 0,
-106, 0, -108, 0, -108, 0, -104, 0, -104, 0, -96, 0, -96, 0, -94,
0, -94, 0, -100, 0, -100, 0, -100, 0, -100, 0, -102, 0, -102, 0,
-102, 0, -102, 0, -104, 0, -104, 0, -102, 0, -102, 0, -106, 0,
-106, 0, -104, 0, -104, 0, -104, 0, -104, 0, -104, 0, -104, 0,
-102, 0, -102, 0, -100, 0, -100, 0, -96, 0, -96, 0};
}

