How to stream pcap file to RTP/RTCP stream?

Swaminathan picture Swaminathan · May 20, 2011 · Viewed 22.3k times · Source

I have captured three different stream as pcap file with meta datas. How can I stream back to RTP/RTCP stream?

Answer

continuousqa picture continuousqa · Apr 30, 2013

If I understand correctly, you have the pcaps, but you want to get the RTP from them?

Wireshark UI

You could use Wireshark's UI to easily take the RTP from the pcap via the Menu: Telephony/RTP/ then show all streams... click a stream it lists, and then 'analyize.'

However, if you want to automate this, and avoid the UI... you can use tshark. I found several tutorials online and used them to build a test harness that automatically rebuilds the audio/rtp on a pcap, then makes a wav and transcribes the audio on that wav to text.

Automated with Tshark

I was making a test call, and wanted to convert the pcap recorded to audio. To do this, I stripped the RTP out of the pcap, then converted the rtp file to raw audio, and then to a wav.

I do this all via the command line so it can be automated. So really I have a shell script that does this:

tshark -a duration:20 -w /jenkins/userContent/sip_1call.pcap

The above records a packet capture for 20 seconds (the duration of the call going on at the same time) and outputs the packets as sip_1call.pcap

ssrc=$(tshark -n -r /jenkins/userContent/sip_1call.pcap -R rtp -T fields -e rtp.ssrc -Eseparator=, | sort -u | awk 'FNR ==1 {print}')

I'm setting the variable ssrc to this action of using tshark to pull out the rtp ssrc value. What the ssrc is is, is an identifier of a RTP stream. If you have one stream, you'd have one RTP ssrc value. You would need to capture all the RTP.ssrc's and output them to a file and that can easily become raw audio again.

sudo tshark -n -r /jenkins/userContent/sip_1call.pcap -R rtp -R "rtp.ssrc == $ssrc" -T fields -e rtp.payload | tee payloads

At this point of my shell script, I'm running tshark again on the recorded pcap and taking that ssrc value and saying "find all of them as 'payload'"

for payload in `cat payloads`; do IFS=:; for byte in $payload; do printf "\\x$byte" >> /jenkins/userContent/sip_1call.raw; done; done

Now the script is setting those RTP.ssrc's to a output file, i'm calling sip_1call.raw

For my purpose I also wanted to convert that raw file to a wav, so I used sox:

sox -t raw -r 8000 -v 4 -c 1 -U /jenkins/userContent/sip_1call.raw /jenkins/userContent/sip_1call.wav

I did some more stuff in my automation framework (like transcribe the audio to text and compare against a known string)... but that's outside the scope of your question.

I hope that helps...

More on SSRc: http://en.wikipedia.org/wiki/Real-time_Transport_Protocol

More details on the full shell script I'm using: http://www.continuous-qa.com/2013/04/automated-verification-of-voip-audio.html