How to stream pcap file to RTP/RTCP stream?
I have captured three different 开发者_如何学Cstream as pcap file with meta datas. How can I stream back to RTP/RTCP stream?
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
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)
You can replay all of your captured packets (including RTP) with this simple, free tool.
PlayCap - Playback for Wireshark Captures
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.
If you just want to replay/listen the audio you can save the RTP payload in a raw audio file using wireshark, then you can resend it (or listen to it using an audio editor), but if you want to reproduce the exact RTP/RTCP stream it's more complicated
How can i stream back to RTP/RTCP stream.
To achive your goal there is a specific tool (free) named rtpplay: http://www.cs.columbia.edu/irt/software/rtptools/
I banged my head on a wall for some time with this as well... But, I got a solution. So first, make sure you can correctly get your call to a softphone/phone... if you can make that connection fine, the rest isn't so bad.
Here's my command line:
sudo sipp -s [my phone number] [ip of my proxy/softswitch] -sf /home/sipp-3.3/uac_pcap_g711.xml -m 2000 -mi [ip of my computer sending the load] -d 1200 -trace_rtt -trace_err -stat_delimiter ,
So I'm using my own scenario file, but the above params should work fine for you. here's what I'm doing with SIPP:
sudo: Why sudo? If you don't sudo this, it can't create the socket needed to send the audio/media.
mi: mi specifies your IP for sending media... I didn't need to specify the port.
d: I added 1200 ms to the pause
trace_rtt and trace_err: I output the log files and performance report
stat_delimiter: i change the default ; to ,
Anyway this worked for me.
Edit:
Also, note that I have this for 2000 calls, at the default rate (10CPS)... you might want to make that -m 1 for now so that you can verify it works. It should play the pcap audio, and then send a DTMF.
After I got this working, I imported this all in Jenkins CI and call sipp via Jenkins jobs, and convert the csv output to visual graphs, and also do some tshark captures during the load... all via Jenkins... if you're interested, check out my blog (mentioned in my profile) for details on how to set that stuff up.
精彩评论