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();
}
}
============================================

