Search code examples
javaandroidaudiortpmjsip

Android: Send .wav to SIP-Phone via RTP (G.711 PCMU) very noisy, crackling sound based on SipDroid/MjSIP


I want to transmit(send-only) a .wav file from my android to a softphone (x-lite) so that the called person on x-lite can hear the sound of the .wav file.

The scenario is as follows: Android and x-lite are both in the same WLAN and both connected to FreeSwitch. I can call x-lite from the android phone. If the call is accepted on the x-lite the android sends the .wav file and I can see in wireshark that RTP pakets (G.711 PCMU) are send from the phone to x-lite. I can hear some sound but not the one I would expect. Instead its crackling, noisy and some beeps.

So is there a problem in the SDP I send to the x-lite?

v=0
o=sip:[email protected] 0 0 IN IP4 192.168.2.100
s=MySession
c=IN IP4 192.168.2.110
t=0 0
m=audio 8000 RTP/AVP 0 8 101
a=rtpmap:101 telephone-event/8000

Or is the problem the way I send the .wav?

DatagramSocket socket = null;
RtpStreamSender sender = null;
int port =8000;
int payload_type = 0;
int frameSize = 64;
int frameRate =32; 
socket = new DatagramSocket(port);
FileInputStream audioInput = new FileInputStream(f); //f is the .wav
sender = new RtpStreamSender(audioInput, true, payload_type, frameRate, frameSize, remoteAddress, remotePort);
sender.setSyncAdj(2);
sender.start();

If I follow UDP Stream in Wireshark the beginning looks like this:

........M...RIFF....WAVEfmt ........D...........data0...............................M..........................................................................>M..........................................................................]M..........................................................................|M..................... ....................... ..... .......................M........... ......................... .....................................M........................................................... ...............M............................................... .......+...5...8...........M...6...+.'...-...(.....#...-...+... ........................... ...........M...................................................................... ...6M......... ... ............................................................UM...........-...1...0...,...)...'...0...?...=.#.'.$. .!....................tM.............................$....................... .....&.......... ....M........................... ...................................,...........M...=...I...W...J.../.....................#...<...T...Z...B.................M.....#...5...5......................"... ..... .......5.W.L...N...........M...C...8.m.'.R...>...O...p...~...e...I...3................................M................................................... .......................M... ...5...R...L...3.../...B...Z...b......X...B...!.........{............MM.........$...2...(........................................................lM...............................-.!.R.J.].s.Z.t.U.c.b..q.v.....y...........M...h...V...Y...c...l.f.E.*.............................(...E...X...........M...J...5.H.7.5.^...~...j.................(.=.h.........F.....Q...(.........M.....E.X...{...L.2...............:.......Q.......v........... .............M.................0...S...K...7.+.B.....................&...O...]...........M...r.B.......w...8.Q...?...A...>...................).../.

So I guess its not empty. After the beginning of the signal, some signal is send from the x-lite to the android and then again some pakets from the android to x-lite... and so on

Can anyone give me a hint why I can't hear the sound?

(Other solutions are also welcome) Edit:

this is the implementation of RTPStramSender from MjSip: http://pastebin.com/xU4EdEex

Edit 2: I changed the SDP like in the RFC to:

     m=audio 54874 RTP/AVP 96 97 0 8
     a=rtpmap:96 PCMU-WB/16000
     a=rtpmap:97 PCMA-WB/16000
     a=rtpmap:0 PCMU/8000
     a=rtpmap:8 PCMA/8000

But nothing hapened. I changed framesize and framerate but the crackling only gets faster or slower

Edit 3: the implementation of RtpPacket: http://pastebin.com/tDLr5CYF


Solution

  • My suspicion is the packetizing.

    This RFC tells you how it is suppoed to be done: RFC 5391

    Turned out that this helped a little bit, but not all the way. If someone can help and it works, please accept his answer rather than mine.