The material of the article is taken from my
Using TShark to parse RTP packets
In the past
In this article, we continue to study the transmission of an audio signal using the RTP protocol. First, let's split our test application into a transmitter and a receiver and learn how to examine an RTP stream using a network traffic analyzer.
So, in order for us to see more clearly which elements of the program are responsible for transmitting RTP and which for receiving, we divide our mstest6.c file into two independent transmitter and receiver programs, we will put the common functions that use both of them in the third file , which we will call mstest_common.c, it will be connected by the transmitter and receiver using the include directive:
/* Π€Π°ΠΉΠ» mstest_common.c ΠΠ±ΡΠΈΠ΅ ΡΡΠ½ΠΊΡΠΈΠΈ Π΄Π»Ρ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡΠΈΠΊΠ° ΠΈ ΠΏΡΠΈΠ΅ΠΌΠ½ΠΈΠΊΠ°. */
#include <mediastreamer2/msfilter.h>
#include <mediastreamer2/msticker.h>
#include <mediastreamer2/msrtp.h>
#include <ortp/rtpsession.h>
#include <ortp/payloadtype.h>
define PCMU 0
/*---------------------------------------------------------*/
/* Π€ΡΠ½ΠΊΡΠΈΡ ΡΠ΅Π³ΠΈΡΡΡΠ°ΡΠΈΠΈ ΡΠΈΠΏΠΎΠ² ΠΏΠΎΠ»Π΅Π·Π½ΡΡ
Π½Π°Π³ΡΡΠ·ΠΎΠΊ. */
void register_payloads(void)
{
/* Π Π΅Π³ΠΈΡΡΡΠΈΡΡΠ΅ΠΌ ΡΠΈΠΏΡ Π½Π°Π³ΡΡΠ·ΠΎΠΊ Π² ΡΠ°Π±Π»ΠΈΡΠ΅ ΠΏΡΠΎΡΠΈΠ»Π΅ΠΉ. ΠΠΎΠ·Π΄Π½Π΅Π΅, ΠΏΠΎ ΠΈΠ½Π΄Π΅ΠΊΡΡ Π²Π·ΡΡΠΎΠΌΡ
ΠΈΠ· Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΊΠ° RTP-ΠΏΠ°ΠΊΠ΅ΡΠ° ΠΈΠ· ΡΡΠΎΠΉ ΡΠ°Π±Π»ΠΈΡΡ Π±ΡΠ΄ΡΡ ΠΈΠ·Π²Π»Π΅ΠΊΠ°ΡΡΡΡ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΡ
Π½Π°Π³ΡΡΠ·ΠΊΠΈ, Π½Π΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΡΠ΅ Π΄Π»Ρ Π΄Π΅ΠΊΠΎΠ΄ΠΈΡΠΎΠ²Π°Π½ΠΈΡ Π΄Π°Π½Π½ΡΡ
ΠΏΠ°ΠΊΠ΅ΡΠ°. */
rtp_profile_set_payload (&av_profile, PCMU, &payload_type_pcm8000);
}
/*---------------------------------------------------------*/
/* ΠΡΠ° ΡΡΠ½ΠΊΡΠΈΡ ΡΠΎΠ·Π΄Π°Π½Π° ΠΈΠ· ΡΡΠ½ΠΊΡΠΈΠΈ create_duplex_rtpsession() Π² audiostream.c ΠΌΠ΅Π΄ΠΈΠ°ΡΡΡΠΈΠΌΠ΅ΡΠ°2. */
static RtpSession *create_rtpsession (int loc_rtp_port, int loc_rtcp_port, bool_t ipv6, RtpSessionMode mode)
{
RtpSession *rtpr; rtpr = rtp_session_new ((int) mode);
rtp_session_set_scheduling_mode (rtpr, 0);
rtp_session_set_blocking_mode (rtpr, 0);
rtp_session_enable_adaptive_jitter_compensation (rtpr, TRUE);
rtp_session_set_symmetric_rtp (rtpr, TRUE);
rtp_session_set_local_addr (rtpr, ipv6 ? "::" : "0.0.0.0", loc_rtp_port, loc_rtcp_port);
rtp_session_signal_connect (rtpr, "timestamp_jump", (RtpCallback) rtp_session_resync, 0);
rtp_session_signal_connect (rtpr, "ssrc_changed", (RtpCallback) rtp_session_resync, 0);
rtp_session_set_ssrc_changed_threshold (rtpr, 0);
rtp_session_set_send_payload_type(rtpr, PCMU);
/* ΠΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ Π²ΡΠΊΠ»ΡΡΠ°Π΅ΠΌ RTCP-ΡΠ΅ΡΡΠΈΡ, ΡΠ°ΠΊ ΠΊΠ°ΠΊ Π½Π°Ρ ΠΏΡΠ»ΡΡ Π½Π΅ Π±ΡΠ΄Π΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ
Π΅Ρ. */
rtp_session_enable_rtcp (rtpr, FALSE);
return rtpr;
}
Now the detached transmitter file:
/* Π€Π°ΠΉΠ» mstest6.c ΠΠΌΠΈΡΠ°ΡΠΎΡ ΠΏΡΠ»ΡΡΠ° ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ (ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡΠΈΠΊΠ°). */
#include <mediastreamer2/dtmfgen.h>
#include <mediastreamer2/msrtp.h>
#include "mstest_common.c"
/*----------------------------------------------------------*/
int main()
{
ms_init();
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡΡ ΡΠΈΠ»ΡΡΡΠΎΠ². */
MSFilter *voidsource = ms_filter_new(MS_VOID_SOURCE_ID);
MSFilter *dtmfgen = ms_filter_new(MS_DTMF_GEN_ID);
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΡΠΈΠ»ΡΡΡ ΠΊΠΎΠ΄Π΅ΡΠ°. */
MSFilter *encoder = ms_filter_create_encoder("PCMU");
/* Π Π΅Π³ΠΈΡΡΡΠΈΡΡΠ΅ΠΌ ΡΠΈΠΏΡ Π½Π°Π³ΡΡΠ·ΠΊΠΈ. */
register_payloads();
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ RTP-ΡΠ΅ΡΡΠΈΡ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡΠΈΠΊΠ°. */
RtpSession *tx_rtp_session = create_rtpsession (8010, 8011, FALSE, RTP_SESSION_SENDONLY);
rtp_session_set_remote_addr_and_port(tx_rtp_session,"127.0.0.1", 7010, 7011);
rtp_session_set_send_payload_type(tx_rtp_session, PCMU);
MSFilter *rtpsend = ms_filter_new(MS_RTP_SEND_ID);
ms_filter_call_method(rtpsend, MS_RTP_SEND_SET_SESSION, tx_rtp_session);
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΈΡΡΠΎΡΠ½ΠΈΠΊ ΡΠ°ΠΊΡΠΎΠ² - ΡΠΈΠΊΠ΅Ρ. */
MSTicker *ticker_tx = ms_ticker_new();
/* Π‘ΠΎΠ΅Π΄ΠΈΠ½ΡΠ΅ΠΌ ΡΠΈΠ»ΡΡΡΡ ΠΏΠ΅ΡΠ΅Π΄Π°ΡΡΠΈΠΊΠ°. */
ms_filter_link(voidsource, 0, dtmfgen, 0);
ms_filter_link(dtmfgen, 0, encoder, 0);
ms_filter_link(encoder, 0, rtpsend, 0);
/* ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ ΠΈΡΡΠΎΡΠ½ΠΈΠΊ ΡΠ°ΠΊΡΠΎΠ². */
ms_ticker_attach(ticker_tx, voidsource);
/* ΠΠ°ΡΡΡΠ°ΠΈΠ²Π°Π΅ΠΌ ΡΡΡΡΠΊΡΡΡΡ, ΡΠΏΡΠ°Π²Π»ΡΡΡΡΡ Π²ΡΡ
ΠΎΠ΄Π½ΡΠΌ ΡΠΈΠ³Π½Π°Π»ΠΎΠΌ Π³Π΅Π½Π΅ΡΠ°ΡΠΎΡΠ°. */
MSDtmfGenCustomTone dtmf_cfg;
dtmf_cfg.tone_name[0] = 0;
dtmf_cfg.duration = 1000;
dtmf_cfg.frequencies[0] = 440;
/* ΠΡΠ΄Π΅ΠΌ Π³Π΅Π½Π΅ΡΠΈΡΠΎΠ²Π°ΡΡ ΠΎΠ΄ΠΈΠ½ ΡΠΎΠ½, ΡΠ°ΡΡΠΎΡΡ Π²ΡΠΎΡΠΎΠ³ΠΎ ΡΠΎΠ½Π° ΡΡΡΠ°Π½ΠΎΠ²ΠΈΠΌ Π² 0. */
dtmf_cfg.frequencies[1] = 0;
dtmf_cfg.amplitude = 1.0;
dtmf_cfg.interval = 0.;
dtmf_cfg.repeat_count = 0.;
/* ΠΡΠ³Π°Π½ΠΈΠ·ΡΠ΅ΠΌ ΡΠΈΠΊΠ» ΡΠΊΠ°Π½ΠΈΡΠΎΠ²Π°Π½ΠΈΡ Π½Π°ΠΆΠ°ΡΡΡ
ΠΊΠ»Π°Π²ΠΈΡ. ΠΠ²ΠΎΠ΄ Π½ΡΠ»Ρ Π·Π°Π²Π΅ΡΡΠ°Π΅Ρ
* ΡΠΈΠΊΠ» ΠΈ ΡΠ°Π±ΠΎΡΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ. */
char key='9';
printf("ΠΠ°ΠΆΠΌΠΈΡΠ΅ ΠΊΠ»Π°Π²ΠΈΡΡ ΠΊΠΎΠΌΠ°Π½Π΄Ρ, Π·Π°ΡΠ΅ΠΌ Π²Π²ΠΎΠ΄.n"
"ΠΠ»Ρ Π·Π°Π²Π΅ΡΡΠ΅Π½ΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ Π²Π²Π΅Π΄ΠΈΡΠ΅ 0.n");
while(key != '0')
{
key = getchar();
if ((key >= 49) && (key <= 54))
{
printf("ΠΡΠΏΡΠ°Π²Π»Π΅Π½Π° ΠΊΠΎΠΌΠ°Π½Π΄Π°: %cn", key);
/* Π£ΡΡΠ°Π½Π°Π²Π»ΠΈΠ²Π°Π΅ΠΌ ΡΠ°ΡΡΠΎΡΡ Π³Π΅Π½Π΅ΡΠ°ΡΠΎΡΠ° Π² ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΠΈΠΈ Ρ
* ΠΊΠΎΠ΄ΠΎΠΌ Π½Π°ΠΆΠ°ΡΠΎΠΉ ΠΊΠ»Π°Π²ΠΈΡΠΈ. */
dtmf_cfg.frequencies[0] = 440 + 100*(key-49);
/* ΠΠΊΠ»ΡΡΠ°Π΅ΠΌ Π·Π²ΡΠΊΠΎΠ²ΠΎΠΉ Π³Π΅Π½Π΅ΡΠ°ΡΠΎΡ c ΠΎΠ±Π½ΠΎΠ²Π»Π΅Π½Π½ΠΎΠΉ ΡΠ°ΡΡΠΎΡΠΎΠΉ. */
ms_filter_call_method(dtmfgen, MS_DTMF_GEN_PLAY_CUSTOM, (void*)&dtmf_cfg);
}
/* Π£ΠΊΠ»Π°Π΄ΡΠ²Π°Π΅ΠΌ ΡΡΠ΅Π΄ Π² ΡΠΏΡΡΠΊΡ Π½Π° 20ΠΌΡ, ΡΡΠΎΠ±Ρ Π΄ΡΡΠ³ΠΈΠ΅ ΡΡΠ΅Π΄Ρ
* ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΏΠΎΠ»ΡΡΠΈΠ»ΠΈ Π²ΡΠ΅ΠΌΡ Π½Π° ΡΠ°Π±ΠΎΡΡ. */
ms_usleep(20000);
}
}
And finally, the receiver file:
/* Π€Π°ΠΉΠ» mstest7.c ΠΠΌΠΈΡΠ°ΡΠΎΡ ΠΏΡΠΈΠ΅ΠΌΠ½ΠΈΠΊΠ°. */
include <mediastreamer2/mssndcard.h>
include <mediastreamer2/mstonedetector.h>
include <mediastreamer2/msrtp.h>
/* ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ Π·Π°Π³ΠΎΠ»ΠΎΠ²ΠΎΡΠ½ΡΠΉ ΡΠ°ΠΉΠ» Ρ ΡΡΠ½ΠΊΡΠΈΡΠΌΠΈ ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ ΡΠΎΠ±ΡΡΠΈΡΠΌΠΈ ΠΌΠ΅Π΄ΠΈΠ°ΡΡΡΠΈΠΌΠ΅ΡΠ°.*/
include <mediastreamer2/mseventqueue.h>
/* ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ ΡΠ°ΠΉΠ» ΠΎΠ±ΡΠΈΡ
ΡΡΠ½ΠΊΡΠΈΠΉ. */
include "mstest_common.c"
/* Π€ΡΠ½ΠΊΡΠΈΡ ΠΎΠ±ΡΠ°ΡΠ½ΠΎΠ³ΠΎ Π²ΡΠ·ΠΎΠ²Π°, ΠΎΠ½Π° Π±ΡΠ΄Π΅Ρ Π²ΡΠ·Π²Π°Π½Π° ΡΠΈΠ»ΡΡΡΠΎΠΌ, ΠΊΠ°ΠΊ ΡΠΎΠ»ΡΠΊΠΎ ΠΎΠ½ ΠΎΠ±Π½Π°ΡΡΠΆΠΈΡ ΡΠΎΠ²ΠΏΠ°Π΄Π΅Π½ΠΈΠ΅ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊ Π²Ρ
ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΡΠΈΠ³Π½Π°Π»Π° Ρ Π·Π°Π΄Π°Π½Π½ΡΠΌΠΈ. */
static void tone_detected_cb(void *data, MSFilter *f, unsigned int event_id,MSToneDetectorEvent *ev)
{
printf("ΠΡΠΈΠ½ΡΡΠ° ΠΊΠΎΠΌΠ°Π½Π΄Π°: %sn", ev->tone_name);
}
/*----------------------------------------------------------*/
int main()
{
ms_init();
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΡΠΊΠ·Π΅ΠΌΠΏΠ»ΡΡΡ ΡΠΈΠ»ΡΡΡΠΎΠ². */
MSSndCard *card_playback = ms_snd_card_manager_get_default_card(ms_snd_card_manager_get());
MSFilter *snd_card_write = ms_snd_card_create_writer(card_playback);
MSFilter *detector = ms_filter_new(MS_TONE_DETECTOR_ID);
/* ΠΡΠΈΡΠ°Π΅ΠΌ ΠΌΠ°ΡΡΠΈΠ² Π½Π°Ρ
ΠΎΠ΄ΡΡΠΈΠΉΡΡ Π²Π½ΡΡΡΠΈ Π΄Π΅ΡΠ΅ΠΊΡΠΎΡΠ° ΡΠΎΠ½ΠΎΠ², ΠΎΠ½ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ
* ΠΎΡΠΎΠ±ΡΠ΅ ΠΏΡΠΈΠΌΠ΅ΡΡ ΡΠ°Π·ΡΡΠΊΠΈΠ²Π°Π΅ΠΌΡΡ
ΡΠΈΠ³Π½Π°Π»ΠΎΠ².*/
ms_filter_call_method(detector, MS_TONE_DETECTOR_CLEAR_SCANS, 0);
/* ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ ΠΊ ΡΠΈΠ»ΡΡΡΡ ΡΡΠ½ΠΊΡΠΈΡ ΠΎΠ±ΡΠ°ΡΠ½ΠΎΠ³ΠΎ Π²ΡΠ·ΠΎΠ²Π°. */
ms_filter_set_notify_callback(detector, (MSFilterNotifyFunc)tone_detected_cb, NULL);
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΌΠ°ΡΡΠΈΠ², ΠΊΠ°ΠΆΠ΄ΡΠΉ ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΠΊΠΎΡΠΎΡΠΎΠ³ΠΎ ΠΎΠΏΠΈΡΡΠ²Π°Π΅Ρ Ρ
Π°ΡΠ°ΠΊΡΠ΅ΡΠΈΡΡΠΈΠΊΡ
* ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΈΠ· ΡΠΎΠ½ΠΎΠ², ΠΊΠΎΡΠΎΡΡΠΉ ΡΡΠ΅Π±ΡΠ΅ΡΡΡ ΠΎΠ±Π½Π°ΡΡΠΆΠΈΠ²Π°ΡΡ:
Π’Π΅ΠΊΡΡΠΎΠ²ΠΎΠ΅ ΠΈΠΌΡ
* Π΄Π°Π½Π½ΠΎΠ³ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ°, ΡΠ°ΡΡΠΎΡΠ° Π² Π³Π΅ΡΡΠ°Ρ
, Π΄Π»ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ Π² ΠΌΠΈΠ»Π»ΠΈΡΠ΅ΠΊΡΠ½Π΄Π°Ρ
,
* ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΡΠΉ ΡΡΠΎΠ²Π΅Π½Ρ ΠΎΡΠ½ΠΎΡΠΈΡΠ΅Π»ΡΠ½ΠΎ 0,775Π. */
MSToneDetectorDef scan[6]=
{
{"V+",440, 100, 0.1}, /* ΠΠΎΠΌΠ°Π½Π΄Π° "Π£Π²Π΅Π»ΠΈΡΠΈΡΡ Π³ΡΠΎΠΌΠΊΠΎΡΡΡ". */
{"V-",540, 100, 0.1}, /* ΠΠΎΠΌΠ°Π½Π΄Π° "Π£ΠΌΠ΅Π½ΡΡΠΈΡΡ Π³ΡΠΎΠΌΠΊΠΎΡΡΡ". */
{"C+",640, 100, 0.1}, /* ΠΠΎΠΌΠ°Π½Π΄Π° "Π£Π²Π΅Π»ΠΈΡΠΈΡΡ Π½ΠΎΠΌΠ΅Ρ ΠΊΠ°Π½Π°Π»Π°". */
{"C-",740, 100, 0.1}, /* ΠΠΎΠΌΠ°Π½Π΄Π° "Π£ΠΌΠ΅Π½ΡΡΠΈΡΡ Π½ΠΎΠΌΠ΅Ρ ΠΊΠ°Π½Π°Π»Π°". */
{"ON",840, 100, 0.1}, /* ΠΠΎΠΌΠ°Π½Π΄Π° "ΠΠΊΠ»ΡΡΠΈΡΡ ΡΠ΅Π»Π΅Π²ΠΈΠ·ΠΎΡ". */
{"OFF", 940, 100, 0.1}/* ΠΠΎΠΌΠ°Π½Π΄Π° "ΠΡΠΊΠ»ΡΡΠΈΡΡ ΡΠ΅Π»Π΅Π²ΠΈΠ·ΠΎΡ". */
};
/* ΠΠ΅ΡΠ΅Π΄Π°Π΅ΠΌ "ΠΏΡΠΈΠΌΠ΅ΡΡ" ΡΠΈΠ³Π½Π°Π»ΠΎΠ² Π΄Π΅ΡΠ΅ΠΊΡΠΎΡ ΡΠΎΠ½ΠΎΠ². */
int i;
for (i = 0; i < 6; i++)
{
ms_filter_call_method(detector, MS_TONE_DETECTOR_ADD_SCAN, &scan[i]);
}
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΡΠΈΠ»ΡΡΡ Π΄Π΅ΠΊΠΎΠ΄Π΅ΡΠ° */
MSFilter *decoder=ms_filter_create_decoder("PCMU");
/* Π Π΅Π³ΠΈΡΡΡΠΈΡΡΠ΅ΠΌ ΡΠΈΠΏΡ Π½Π°Π³ΡΡΠ·ΠΊΠΈ. */
register_payloads();
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ RTP-ΡΠ΅ΡΡΠΈΡ ΠΏΡΠΈΠ΅ΠΌΠ½ΠΈΠΊΠ°. */
MSFilter *rtprecv = ms_filter_new(MS_RTP_RECV_ID);
RtpSession *rx_rtp_session = create_rtpsession (7010, 7011, FALSE, RTP_SESSION_RECVONLY);
ms_filter_call_method(rtprecv, MS_RTP_RECV_SET_SESSION, rx_rtp_session);
/* Π‘ΠΎΠ·Π΄Π°Π΅ΠΌ ΠΈΡΡΠΎΡΠ½ΠΈΠΊ ΡΠ°ΠΊΡΠΎΠ² - ΡΠΈΠΊΠ΅Ρ. */
MSTicker *ticker_rx = ms_ticker_new();
/* Π‘ΠΎΠ΅Π΄ΠΈΠ½ΡΠ΅ΠΌ ΡΠΈΠ»ΡΡΡΡ ΠΏΡΠΈΡΠΌΠ½ΠΈΠΊΠ°. */
ms_filter_link(rtprecv, 0, decoder, 0);
ms_filter_link(decoder, 0, detector, 0);
ms_filter_link(detector, 0, snd_card_write, 0);
/* ΠΠΎΠ΄ΠΊΠ»ΡΡΠ°Π΅ΠΌ ΠΈΡΡΠΎΡΠ½ΠΈΠΊ ΡΠ°ΠΊΡΠΎΠ². */
ms_ticker_attach(ticker_rx, rtprecv);
char key='9';
printf( "ΠΠ»Ρ Π·Π°Π²Π΅ΡΡΠ΅Π½ΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ Π²Π²Π΅Π΄ΠΈΡΠ΅ 0.n");
while(key != '0')
{
key = getchar();
/* Π£ΠΊΠ»Π°Π΄ΡΠ²Π°Π΅ΠΌ ΡΡΠ΅Π΄ Π² ΡΠΏΡΡΠΊΡ Π½Π° 20ΠΌΡ, ΡΡΠΎΠ±Ρ Π΄ΡΡΠ³ΠΈΠ΅ ΡΡΠ΅Π΄Ρ * ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΏΠΎΠ»ΡΡΠΈΠ»ΠΈ Π²ΡΠ΅ΠΌΡ Π½Π° ΡΠ°Π±ΠΎΡΡ. */
ms_usleep(20000);
}
}
We compile the transmitter and receiver, then run each in its own console. Further, it should work as before - only we must enter numbers from 1 to 6 in the transmitter console, and the response to them should appear in the receiver console. Tones should be heard in the speaker. If everything is so, then we have established a connection between the receiver and the transmitter - there is a continuous transmission of RTP packets from the transmitter to the receiver.
Now is the time to install the traffic analyzer, for this we will install the console version of the excellent Wireshark program - it is called TShark. I have chosen TShark for further presentation in order to make it easier to describe the control of the program. With Wireshark, I would need a sea of ββscreenshots, which can quickly become outdated with the release of a new version of Wireshark.
If you know how to use Wireshark, you can use it to study our examples. But in this case, I recommend that you master TShark, as it will help you automate the testing of your VoIP applications, as well as remotely capture.
Install TShark with the command:
$ sudo apt-get install tshark
Traditionally, we check the installation result by asking for the version of the program:
$ tshark --version
If an adequate response is received, continue on.
Since our packets only circulate inside the computer so far, we can tell tshark to only show such packets. To do this, select capture packets from the interface loopback (loopback) by passing the TShark option -ilo:
$ sudo tshark -i lo
Messages about the packets sent by our transmitter will immediately begin to pour into the console (continuously, regardless of whether we pressed the button on the remote control or not). Perhaps there are programs on your computer that also send packets through a local loop, in which case we will get a mixture of ours and other people's packets. To make sure that we see only packets sent by our remote in the list, we will add a filter by port number. By pressing Ctrl-C we stop the analyzer and enter a filter for the port number that it uses on the console as the destination port for its transmission (8010): -f "udp port 8010". Now our command line will look like this:
$ sudo tshark -i lo -f "udp port 8010"
The following output will appear in the console (first 10 lines):
1 0.000000000 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
2 0.020059705 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
3 0.040044409 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
4 0.060057104 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
5 0.080082311 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
6 0.100597153 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
7 0.120122668 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
8 0.140204789 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
9 0.160719008 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
10 0.180673685 127.0.0.1 β 127.0.0.1 UDP 214 8010 β 7010 Len=172
So far, these are not packets, but a numbered list of events, where each line is a message about the next packet that was seen on the interface. Since we have already taken care of packet filtering, we see in the listing only messages about the packets of our transmitter. Next, we decipher this table by column numbers:
Event number.
The time of its occurrence.
The packet's source IP address and the packet's destination IP address.
Packet protocol shown as UDP because RTP packets are carried as payload inside UDP packets.
Packet size in bytes.
The port number of the packet's source and the port number of the packet's destination.
The payload size of the packet, from here we can conclude that our transmitter generates RTP packets of 172 bytes in size, which, like a duck in a chest, is inside a UDP packet of 214 bytes.
Now it's time to look inside the UDP packets, for this we will start TShark with the augmented set of keys:
sudo tshark -i lo -f "udp port 8010" -P -V -O rtp -o rtp.heuristic_rtp:TRUE -x
As a result, the output of the program will be enriched - a decoding of the internal contents of the package that caused it will be added to each event. To get a better view of the output, you can either stop TShark by pressing Ctrl-C, or duplicate its output to a file by adding a pipeline to the tee program with the filename, tee <filename>, to the run command:
$ sudo tshark -i lo -f "udp port 8010" -P -V -O rtp -o rtp.heuristic_rtp:TRUE -x | tee log.txt
Now let's look at what we got in the file, here is the first package from it:
1 0.000000000 127.0.0.1 β 127.0.0.1 RTP 214 PT=ITU-T G.711 PCMU, SSRC=0x6B8B4567, Seq=58366, Time=355368720
Frame 1: 214 bytes on wire (1712 bits), 214 bytes captured (1712 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1, Dst: 127.0.0.1User Datagram Protocol, Src Port: 8010, Dst Port: 7010
Real-Time Transport Protocol [Stream setup by HEUR RT (frame 1)]
[Setup frame: 1]
[Setup Method: HEUR RT]
10.. .... = Version: RFC 1889 Version (2)
..0. .... = Padding: False
...0 .... = Extension: False
.... 0000 = Contributing source identifiers count: 0
0... .... = Marker: False
Payload type: ITU-T G.711 PCMU (0)
Sequence number: 58366 [Extended sequence number: 58366]
Timestamp: 355368720
Synchronization Source identifier: 0x6b8b4567 (1804289383)
Payload: ffffffffffffffffffffffffffffffffffffffffffffffff...
0000 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 ..............E.
0010 00 c8 3c 69 40 00 40 11 ff b9 7f 00 00 01 7f 00 ..<i@.@.........
0020 00 01 1f 4a 1b 62 00 b4 fe c7 80 00 e3 fe 15 2e ...J.b..........
0030 7f 10 6b 8b 45 67 ff ff ff ff ff ff ff ff ff ff ..k.Eg..........
0040 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0080 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
0090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
00a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
00b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
00c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
00d0 ff ff ff ff ff ff ......
We will devote the next article to the analysis of the information contained in this listing and, inevitably, we will talk about the internal structure of the RTP package.
Source: habr.com