Write(Export) the RTP Stream from a SIP Call to an audio file

I am working on telephony system that need record each call to a file.

I got the RTP Stream in ReceiveStreamEvent handler and start to record

the problem is i got a file and play it but there are any sounds

when i set FileTypeDescriptor.WAVE and AudioFormat.ULAW

I try out the FileTypeDescriptor.WAVE and AudioFormat.IMA4_MS, i got a fixed size file with 60kb

if the FileTypeDescriptor.MPEG_AUDIO and AudioFormat.MPEG, the processor cannot be realize,

the thread is blocked!!

Could anyone save me? thanks in advanced!

=================================Code===================================================

public void update(ReceiveStreamEvent evt){

logger.debug("received a new incoming stream. " + evt);

RTPManager mgr = (RTPManager) evt.getSource();

Participant participant = evt.getParticipant(); // could be null.

ReceiveStream stream = evt.getReceiveStream(); // could be null.

if (evt instanceof NewReceiveStreamEvent)

{

try

{

stream = ( (NewReceiveStreamEvent) evt).getReceiveStream();

DataSource ds = stream.getDataSource();

recorder = new CallRecorderImpl(ds);

recorder.start();

}

catch (Exception e)

{

logger.error("NewReceiveStreamEvent exception ", e);

return;

}

}

========================================================================================

this is the CallRecorderImpl Class

public class CallRecorderImpl implements DataSinkListener, ControllerListener {

private Processor processor = null;

private DataSink dataSink = null;

private DataSource source = null;

private boolean bRecording = false;

FileTypeDescriptor contentType = new FileTypeDescriptor(FileTypeDescriptor.WAVE);

Format encoding = new AudioFormat(AudioFormat.IMA4_MS);

MediaLocator dest = new MediaLocator("file:/c:/bar.wav");

public CallRecorderImpl(DataSource ds) {

this.source = ds;

}

public void start() {

try {

processor = Manager.createProcessor(source);

processor.addControllerListener(this);

processor.configure();

} catch (Exception e) {

System.out.println("exception:" + e);

}

}

public void stop() {

try {

System.out.println("stopping");

this.dataSink.stop();

this.dataSink.close();

} catch (Exception ep) {

ep.printStackTrace();

}

}

public void controllerUpdate(ControllerEvent evt) {

Processor pr = (Processor) evt.getSourceController();

if (evt instanceof ConfigureCompleteEvent) {

System.out.println("ConfigureCompleteEvent");

processConfigured(pr);

}

if (evt instanceof RealizeCompleteEvent) {

System.out.println("RealizeCompleteEvent");

processRealized(pr);

}

if (evt instanceof ControllerClosedEvent) {

System.out.println("ControllerClosedEvent");

}

if (evt instanceof EndOfMediaEvent) {

System.out.println("EndOfMediaEvent");

pr.stop();

}

if (evt instanceof StopEvent) {

System.out.println("StopEvent");

pr.close();

try {

dataSink.stop();

dataSink.close();

} catch (Exception ee) {

ee.printStackTrace();

}

}

}

public void dataSinkUpdate(DataSinkEvent event) {

if (event instanceof EndOfStreamEvent) {

try {

System.out.println("EndOfStreamEvent");

dataSink.stop();

dataSink.close();

System.exit(1);

} catch (Exception e) {

}

}

}

public void processConfigured(Processor p) {

// Set the output content type

p.setContentDescriptor(this.contentType);

// Get the track control objects

TrackControl track[] = p.getTrackControls();

boolean encodingPossible = false;

// Go through the tracks and try to program one of them

// to output ima4 data.

for (int i = 0; i < track.length; i++) {

try {

track.setFormat(this.encoding);

encodingPossible = true;

} catch (Exception e) {

track.setEnabled(false);

}

}

if (!encodingPossible) {

System.out.println("cannot encode to " + this.encoding);

return;

}

p.realize();

}

public void processRealized(Processor p) {

System.out.println("Entered processRealized");

DataSource source = p.getDataOutput();

try {

dataSink = Manager.createDataSink(source, dest);

dataSink.open();

dataSink.start();

dataSink.addDataSinkListener(new DataSinkListener() {

public void dataSinkUpdate(DataSinkEvent e) {

if (e instanceof EndOfStreamEvent) {

System.out.println("EndOfStreamEvent");

dataSink.close();

}

}

});

} catch (Exception e) {

e.printStackTrace();

return;

}

p.start();

}

}

============================================

[5041 byte] By [jyc5131@hotmail.coma] at [2007-11-26 20:50:40]
# 1
Save Me, Aren't anyone here?
jyc5131@hotmail.coma at 2007-7-10 2:15:14 > top of Java-index,Security,Cryptography...
# 2

Which shows that the output stream cannot be of that particulat format and descriptor.

Look at this code

import javax.swing.*;

import javax.media.*;

import java.net.*;

import java.io.*;

import javax.media.datasink.*;

import javax.media.protocol.*;

import javax.media.format.*;

import javax.media.control.*;

class Abc implements ControllerListener

{

DataSource ds;

DataSink sink;

Processor pr;

MediaLocator mc;

public void maam() throws Exception

{

mc=new MediaLocator("file:C:/Workspace/aaaaa.mpg");

pr=Manager.createProcessor(new URL("file:G:/java files1/jmf/aa.mp3"));

pr.addControllerListener(this);

pr.configure();

}

public void controllerUpdate(ControllerEvent e)

{

if(e instanceof ConfigureCompleteEvent)

{

System.out.println ("ConfigureCompleteEvent");

Processor p = (Processor)e.getSourceController();

System.out.println ("ConfigureCompleteEvent");

processConfigured(p);

}

if(e instanceof RealizeCompleteEvent)

{

System.out.println ("RealizeCompleteEvent");

Processor p = (Processor)e.getSourceController();

processRealized(p);

}

if(e instanceof ControllerClosedEvent)

{

System.out.println ("ControllerClosedEvent");

}

if(e instanceof EndOfMediaEvent)

{

System.out.println ("EndOfMediaEvent");

Processor p = (Processor)e.getSourceController();

p.stop();

}

if(e instanceof StopEvent)

{

System.out.println ("StopEvent");

Processor p = (Processor)e.getSourceController();

p.close();

try

{

sink.stop();

sink.close();

}

catch(Exception ee)

{

}

}

}

public void processConfigured(Processor p)

{

System.out.println("Entered processConfigured");

p.setContentDescriptor (new FileTypeDescriptor (FileTypeDescriptor.MPEG_AUDIO));

/*TrackControl track[] = p.getTrackControls ();

boolean encodingPossible = false;

for (int i = 0; i < track.length; i++)

{

try

{

track[i].setFormat (new VideoFormat (VideoFormat.MPEG));

encodingPossible = true;

}

catch (Exception e)

{

track[i].setEnabled (false);

}

}*/

p.realize();

}

public void processRealized(Processor p)

{

pr=p;

System.out.println("Entered processRealized");

try

{

MediaLocator dest = new MediaLocator("file:C:/Workspace/ring1.mpg");

sink = Manager.createDataSink(p.getDataOutput(), dest);

sink.addDataSinkListener(new DataSinkListener()

{

public void dataSinkUpdate(DataSinkEvent e)

{

if(e instanceof EndOfStreamEvent)

{

System.out.println ("EndOfStreamEvent");

sink.close();

}

}

});

sink.open();

sink.start();

}

catch(Exception eX)

{

}

System.out.println("Just before start");

p.start();

}

/*public void dataSinkUpdate(DataSinkEvent event)

{

if(event instanceof EndOfStreamEvent)

{

try

{

System.out.println("EndOfStreamEvent");

dsk.stop();

dsk.close();

System.exit(1);

}

catch(Exception e)

{

}

}

}*/

}

public class JMFCapture6

{

public static void main(String args[]) throws Exception

{

Abc a=new Abc();

a.maam();

}

}

qUesT_foR_knOwLeDgea at 2007-7-10 2:15:14 > top of Java-index,Security,Cryptography...
# 3
These are the formats supported by JMF with the existing plug-ins available in it http://java.sun.com/products/java-media/jmf/2.1.1/formats.html
qUesT_foR_knOwLeDgea at 2007-7-10 2:15:15 > top of Java-index,Security,Cryptography...
# 4
Could you tell me which format can work?the RTP stream format is ULAW/RTP , and only audiowhy why why I cannot got a correct format to work
jyc5131@hotmail.coma at 2007-7-10 2:15:15 > top of Java-index,Security,Cryptography...
# 5
MPEG_AUDIO and MPEG does not work
jyc5131@hotmail.coma at 2007-7-10 2:15:15 > top of Java-index,Security,Cryptography...
# 6
I am successful when to try ULAW 8000,8,1thank you
jyc5131@hotmail.coma at 2007-7-10 2:15:15 > top of Java-index,Security,Cryptography...