首先分别介绍下几个RTP (Real-time Transport Protocol)命令行小工具的用法.
1. mediastream.exe
- mediastream --local <port> --remote <ip:port> --payload <payload type number>
- [ --fmtp <fmtpline>]
- [ --jitter <miliseconds>]
- [ --width <pixels>]
- [ --height <pixels> ]
- [ --bitrate <bits per seconds>]
- [ --ec (enable echo canceller)]
- [ --agc (enable automatic gain control)]
- [ --ng (enable noise gate)]
- [ --ng-threshold <(float) [0-1]> (noise gate threshold)]
- [ --capture-card <name>]
- [ --playback-card <name>]
- [ --infile <input wav file>] specify a wav file to be used for input, instead of soundcard
- [ --outfile <output wav file>] specify a wav file to write audio into, instead of soundcard
mediastream的作用是从声卡捕捉声音, 编码, 然后通过RTP协议发送到远端, 同时接收远端发送过来的RTP报文, 解码, 通过声卡播放.
比如,
主机A IP 192.168.1.100
主机B IP 192.168.1.200
主机A运行 mediastream.exe --local 2000 --remote 192.168.1.200:3000 --payload 110
主机B运行 mediastream.exe --local 3000 --remote 192.168.1.100:2000 --payload 110
这里payload type 110表示payload_type_speex_nb.
2. rtpdump.exe
- rtpdump [-F format] [-t duration] [-x bytes] [-f file]
- [-o outputfile] address/port
rtpdump listens on the address and port pair for RTP and RTCP packets and dumps a processed version to outputfile if specified or stdout otherwise.
rtpdump可以监听地址/端口的RTP报文, 然后输出RTP报文到一个dump文件中. 这一点类似于抓包工具.
3. rtpplay.exe
- rtpplay [-T] [-v] [-f file] [-p profile] [-s sourceport]
- [-b begin] [-e end] destination/port[/ttl]
rtpplay reads RTP session data, recorded by rtpdump -F dump from either the file or stdin, if file is not specified, sending it to network address destination and port port with a time-to-live value of ttl.
rtpplay可以读取dump文件中的RTP报文, 然后发送到某地址/端口.
上面三个工具, mediastream支持声音的捕获/播放以及RTP协议, 但不支持RTP报文的保存/读取, 而rtpdump/rtpplay支持RTP报文的保存/读取以及RTP协议, 但不支持声音的捕获/播放.
所以, 结合这三个工具就能完成下面的任务:
1. 把你的声音保存到一个dump文件中;
2. 播放一个dump文件中的声音.
这里写了2个批处理, 分别完成上面2个任务.
rtpdump_gen.bat
- @ECHO OFF
-
- START "mediastream_test" /MIN mediastream.exe --local 2000
- --remote 127.0.0.1:3000 --payload 110
- START "rtpdump_test" /MIN rtpdump.exe -F dump -o ./my.rtpdump 127.0.0.1/3000
-
- ECHO "Press Any Key to Finish the Voice Dump"
- PAUSE
- TASKKILL /F /FI "WINDOWTITLE eq mediastream_test"
- TASKKILL /F /FI "WINDOWTITLE eq rtpdump_test"
- EXIT
rtpdump_playback.bat
- @ECHO OFF
-
- START "mediastream_test" /MIN mediastream.exe --local 2000
- --remote 127.0.0.1:3000 --payload 110
- REM Delay for 2 seconds
- ping 127.0.0.1 -n 2 > nul
- rtpplay.exe -f ./my.rtpdump -s 3000 127.0.0.1/2000
-
- ECHO "Press Any Key to Finish the Voice Playback"
- PAUSE
- TASKKILL /F /FI "WINDOWTITLE eq mediastream_test"
- EXIT
(mysuperbaby) |