How to stream pcap file to RTP/RTCP stream?

23,599

Solution 1

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

Solution 2

There is a tool just for this purpose, as part of the SIPp sip testing package. http://sipp.sourceforge.net/doc/reference.html#PCAP+Play

(disclaimer: I've never used it myself, though I did use SIPp itself, and was very fond of it)

Solution 3

You can replay all of your captured packets (including RTP) with this simple, free tool.

PlayCap - Playback for Wireshark Captures

PlayCap Screenshot

Solution 4

Taking a pcap and (I assume) replaying it is a non-trivial thing to do; there are no packages that I know of to do it. It can be done, but requires very good knowledge both of SIP (I assume you're using SIP) and RTP. You also have to be careful to replay the packets at the right times, not as fast as you can.

Someone who really knows what they're doing could write such a tool in 3-5 days.

Share:
23,599
Swaminathan
Author by

Swaminathan

Updated on July 09, 2022

Comments

  • Swaminathan
    Swaminathan 11 months

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

  • Swaminathan
    Swaminathan almost 12 years
    Its bit hard to stream, all the folks are saying like that only.. Any way thanks Mike