{"id":87043,"date":"2020-07-02T19:42:04","date_gmt":"2020-07-02T17:42:04","guid":{"rendered":"https:\/\/prohoster.info\/blog\/administrirovanie\/izuchaem-voip-dvizhok-mediastreamer2-chast-8"},"modified":"2020-07-02T19:42:04","modified_gmt":"2020-07-02T17:42:04","slug":"izuchaem-voip-dvizhok-mediastreamer2-chast-8","status":"publish","type":"post","link":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/izuchaem-voip-dvizhok-mediastreamer2-chast-8","title":{"rendered":"Exploring the VoIP Engine Mediastreamer2. Part 8","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<p>The article material is taken from my <noindex><a rel=\"nofollow\" href=\"https:\/\/zen.yandex.ru\/id\/5e3f8e0751f5346faab4fc7a\">Zen channel<\/a><\/noindex>.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Exploring the VoIP Engine Mediastreamer2. Part 8\" src=\"\/wp-content\/uploads\/2020\/07\/ddc5dba3a090dec9927b46a82dda760f.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><\/p>\n<h2 id=\"struktura-rtp-paketa\">Structure of the RTP Packet<\/h2>\n<p><\/p>\n<p>Previously <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/496490\/\">article<\/a><\/noindex> Using <em>TShark<\/em> we captured the RTP packets exchanged between our receiver and transmitter. In this section, we will color the elements of the packet and discuss their purpose. <\/p>\n<p><\/p>\n<p>Let\u2019s take a look at the same packet, but now with highlighted fields and explanatory notes:<br \/>\n<img decoding=\"async\" alt=\"Exploring the VoIP Engine Mediastreamer2. Part 8\" src=\"\/wp-content\/uploads\/2020\/07\/a2ee8fb10bc6daa48dcd0bc9a8596fd7.png\" style=\"display:block;margin: 0 auto;\" \/><\/p>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/p>\n<p>In the lower part of the listing, the bytes that make up the RTP packet are highlighted, which in turn is the payload of the UDP packet (its header is outlined in black). The colored backgrounds indicate the bytes of the RTP header, while the data block containing the RTP packet's payload is highlighted in green. The data is presented in hexadecimal format. In this case, it's audio signal compressed using u-law, i.e., one sample is 1 byte. Since we used the default sampling rate of 8000 Hz, at a packet rate of 50 Hz, each RTP packet should contain 160 bytes of payload. This is what we will see when counting the bytes in the green area; there should be 10 lines. <\/p>\n<p><\/p>\n<p>According to the standard, the amount of data in the payload must be a multiple of four, meaning it must contain a whole number of four-byte words. If your payload does not comply with this rule, you need to add bytes with zero values at the end of the payload and set the Padding bit. This bit is located in the first byte of the RTP header and is highlighted in turquoise. Note that all payload bytes have a value of 0xFF \u2014 this is what silence looks like in u-law format.<\/p>\n<p><\/p>\n<p>The RTP packet header consists of 12 mandatory bytes, but it can be longer in two cases:<\/p>\n<p><\/p>\n<ul>\n<li>\n<p>When the packet carries an audio signal obtained by mixing signals from several sources (RTP streams), a table listing the identifiers of the sources whose payloads were used to create this packet's payload is placed after the first 12 bytes of the header. In this case, the lower four bits of the first byte of the header (the field <em>Contributing source identifiers count<\/em>) specifies the number of sources. The field size is 4 bits, so the table can contain up to 15 source identifiers, each occupying 4 bytes. This table is used when organizing conference calls.<\/p>\n<p>\n<\/li>\n<li>\n<p>When the header has an extension. In this case, a bit is set in the first byte of the header. <strong>X<\/strong>In the extended header, after the participant table (if there are any), there is an extension header of one word size, followed by extension words. An extension is a set of bytes that you can use to transmit additional data. The standard does not specify the format of this data\u2014it can be anything. For example, it can include some additional settings for the device receiving RTP packets. However, some applications have developed standards for the extended header, such as for communication tools in the standard <em>ED-137 (Interoperability Standards for VoIP ATM Components)<\/em>. <\/p>\n<p>\n<\/li>\n<\/ul>\n<p><\/p>\n<p>Now let's look at the header fields in more detail. Below is a canonical picture showing the structure of the RTP header, which I couldn't resist coloring in the same colors.<\/p>\n<p><\/p>\n<p><img decoding=\"async\" alt=\"Exploring the VoIP Engine Mediastreamer2. Part 8\" src=\"\/wp-content\/uploads\/2020\/07\/b8839a56fbe4ee484c9d6b19714b541e.png\" style=\"display:block;margin: 0 auto;\" \/><br \/>\n<strong>VER<\/strong> \u2014 version number of the protocol (current version is 2);<\/p>\n<p><\/p>\n<p><strong>P<\/strong> \u2014 a flag set in cases where the RTP packet is padded with empty bytes at the end;<\/p>\n<p><\/p>\n<p><strong>X<\/strong> \u2014 a flag indicating that the header is extended;<\/p>\n<p><\/p>\n<p><strong>CC<\/strong> \u2014 contains the number of CSRC identifiers following the fixed header (after the words 1..3), the table is not shown in the illustration;<\/p>\n<p><\/p>\n<p><strong>M<\/strong> \u2014 marker indicating the start of frame or presence of speech in the channel (if a speech pause detector is used). If the receiver doesn't have a speech pause detector, this bit should be constantly set;<\/p>\n<p><\/p>\n<p><strong>PTYPE<\/strong> \u2014 indicates the payload format;<\/p>\n<p><\/p>\n<p><strong>Sequence number<\/strong> \u2014 packet number, used for reconstructing the playback order of packets, as it can happen that packets reach the receiver in a different order than they were sent. The initial value should be random to complicate any potential decryption of the RTP stream. This field also helps detect packet losses;<\/p>\n<p><\/p>\n<p><strong>Timestamp<\/strong> \u2014 timestamp. Time is measured in signal samples, meaning if a packet contains 160 samples, the timestamp of the next packet will be increased by 160. The initial timestamp value should be random;<\/p>\n<p><\/p>\n<p><strong>SSRC<\/strong> \u2014 the identifier of the packet source, it must be unique. It\u2019s best generated randomly before starting the RTP stream.<\/p>\n<p><\/p>\n<p>If you are developing your own RTP packet transmitter or receiver, you will often need to inspect your packets to improve performance. I recommend mastering the use of packet filtering in TShark; it allows you to capture only those packets that are of interest to you. In environments where dozens of RTP devices are operating on the network, this is very valuable. In the TShark command line, filtering parameters are set using the option \"-f\". We used this option when we wanted to capture packets from port 8010:<br \/>\n<code>-f \"udp port 8010\"<\/code><br \/>\nFiltering parameters are essentially a set of criteria that the \"captured\" packet must meet. The condition can check the address, port, or the value of a specific byte in the packet. Conditions can be combined using logical operations such as \"AND\", \"OR\", etc. It is a very powerful tool.<\/p>\n<p><\/p>\n<p>If you want to view the dynamics of field changes in packets, you will need to duplicate the output <em>TShark<\/em> to a file, as shown in the previous article, by sending the output <em>TShark<\/em> to the input <em>tee<\/em>. Then, by opening the log file with <em>less, vim<\/em> or another tool capable of quickly working with large text files and performing string searches, you can uncover all the nuances of packet field behavior in the RTP stream.<\/p>\n<p><\/p>\n<p>If you need to listen to the signal transmitted by the RTP stream, you should use the version <em>TShark<\/em> with a visual interface <em>Wireshark<\/em>. With some simple mouse manipulations, you can listen to it and see the waveform of the signal. But under one condition \u2014 if it\u2019s encoded in u-law or a-law format.<\/p>\n<p><\/p>\n<p>In the next <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/496874\/\">article<\/a><\/noindex> we will create a duplex intercom together. Gather a pair of headsets and one conversation partner.<\/p>\n<p>Source: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/496666\/\">habr.com<\/a> <\/p>","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<p>\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0437\u044f\u0442 \u0441 \u043c\u043e\u0435\u0433\u043e \u0434\u0437\u0435\u043d-\u043a\u0430\u043d\u0430\u043b\u0430. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 RTP-\u043f\u0430\u043a\u0435\u0442\u0430 \u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e TShark \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043b\u0438 \u0437\u0430\u0445\u0432\u0430\u0442 RTP-\u043f\u0430\u043a\u0435\u0442\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u043d\u0430\u0448\u0438 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a \u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u0447\u0438\u043a. \u041d\u0443 \u0430 \u0432 \u044d\u0442\u043e\u0439 \u043c\u044b \u0440\u0430\u0441\u043a\u0440\u0430\u0441\u0438\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043f\u0430\u043a\u0435\u0442\u0430 \u0432 \u0440\u0430\u0437\u043d\u044b\u0435 \u0446\u0432\u0435\u0442\u0430 \u0438 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u0438\u0445 \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438. \u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0442\u043e\u0442 \u0436\u0435 \u043f\u0430\u043a\u0435\u0442, \u043d\u043e \u0443\u0436\u0435 \u0441 \u043f\u043e\u0434\u043a\u0440\u0430\u0448\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u043b\u044f\u043c\u0438 \u0438 \u0441 \u043f\u043e\u044f\u0441\u043d\u044f\u044e\u0449\u0438\u043c\u0438 \u043d\u0430\u0434\u043f\u0438\u0441\u044f\u043c\u0438: \u0412 [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":87044,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-87043","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.2 - aioseo.com -->\n\t<meta name=\"description\" content=\"\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0437\u044f\u0442 \u0441 \u043c\u043e\u0435\u0433\u043e \u0434\u0437\u0435\u043d-\u043a\u0430\u043d\u0430\u043b\u0430.\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/izuchaem-voip-dvizhok-mediastreamer2-chast-8\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.2\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47\u0418\u0437\u0443\u0447\u0430\u0435\u043c VoIP-\u0434\u0432\u0438\u0436\u043e\u043a Mediastreamer2. \u0427\u0430\u0441\u0442\u044c 8 | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0437\u044f\u0442 \u0441 \u043c\u043e\u0435\u0433\u043e \u0434\u0437\u0435\u043d-\u043a\u0430\u043d\u0430\u043b\u0430.\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/izuchaem-voip-dvizhok-mediastreamer2-chast-8\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-07-02T17:42:04+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-07-02T17:42:04+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47 Exploring the VoIP engine Mediastreamer2. Part 8 | ProHoster","description":"The content of the article is taken from my Zen channel.","canonical_url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/izuchaem-voip-dvizhok-mediastreamer2-chast-8","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"en_US","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47\u0418\u0437\u0443\u0447\u0430\u0435\u043c VoIP-\u0434\u0432\u0438\u0436\u043e\u043a Mediastreamer2. \u0427\u0430\u0441\u0442\u044c 8 | ProHoster","og:description":"\u041c\u0430\u0442\u0435\u0440\u0438\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 \u0432\u0437\u044f\u0442 \u0441 \u043c\u043e\u0435\u0433\u043e \u0434\u0437\u0435\u043d-\u043a\u0430\u043d\u0430\u043b\u0430.","og:url":"https:\/\/prohoster.info\/en\/blog\/administrirovanie\/izuchaem-voip-dvizhok-mediastreamer2-chast-8","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2020-07-02T17:42:04+00:00","article:modified_time":"2020-07-02T17:42:04+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"87043","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 13:59:56","updated":"2022-10-07 20:48:50","focus_keyword":null,"additional_keywords":null,"truseo_locale":null},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/87043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/comments?post=87043"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/posts\/87043\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media\/87044"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/media?parent=87043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/categories?post=87043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/en\/wp-json\/wp\/v2\/tags?post=87043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}