{"id":5761,"date":"2026-05-24T18:36:17","date_gmt":"2026-05-24T09:36:17","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5761"},"modified":"2026-05-24T18:41:15","modified_gmt":"2026-05-24T09:41:15","slug":"mediaserve-rmini_mediaserver_1-code-description-read_message_header1-4","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/05\/24\/mediaserve-rmini_mediaserver_1-code-description-read_message_header1-4\/","title":{"rendered":"[Mediaserver]mini_Mediaserver_1-\ucf54\ub4dc\uc124\uba85\/code description-read_message_header()(1-4)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc5ec\uae30\ub294 void RtmpSession::read_message_header(uint8_t fmt, uint32_t cs_id) { } \uc774 \ud568\uc218\uc5d0 \ub300\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.<br>Here is the description for the function void RtmpSession::read_message_header(uint8_t fmt, uint32_t cs_id) { }.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb OBS\uac00 \ubcf4\ub0b8 chunk\uc5d0\uc11c fmt 0\u223c3\uc5d0 \ub530\ub77c \uac00\ubcc0 \ud5e4\ub354\ub97c \uc77d\uace0, \ud604\uc7ac \uba54\uc2dc\uc9c0\uc758 timestamp, length, type, stream_id\ub97c \uac31\uc2e0\ud569\ub2c8\ub2e4.<br>Read variable headers according to fmt 0~3 from the chunk sent by OBS, and update the timestamp, length, type, and stream_id of the current message.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uac31\uc2e0\uc774\ub780 \uc758\ubbf8\ub294 &#8220;\uba64\ubc84\ubcc0\uc218 4\uac1c\ub97c \ub2e4\uc74c chunk \ud5e4\ub354\uc5d0\uc11c \uc77d\uc740 \uac12\uc73c\ub85c \ubc14\uafb8\uac70\ub098, delta(\ubcc0\ud654\uac12)\ub97c \ub354\ud574\uc11c \ub2e4\uc74c \uba54\uc2dc\uc9c0\ub97c \uc870\ub9bd\ud560 \uc900\ube44\ub97c \ud55c\ub2e4&#8221;\ub294 \ub73b\uc785\ub2c8\ub2e4.<br>Update means &#8220;prepare to assemble the next message by changing the four member variables to the values \u200b\u200bread from the next chunk header or adding delta(change value).&#8221;<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb 2\ube44\ud2b8\ub85c \ud45c\ud604 \uac00\ub2a5\ud55c \uac12 =&nbsp;<code>00, 01, 10, 11<\/code>&nbsp;= 10\uc9c4\uc218\ub85c 0, 1, 2, 3. \uae4c\uc9c0 \uac00\ub2a5\ud569\ub2c8\ub2e4.<br>Values \u200b\u200bthat can be represented by 2 bits = 00, 01, 10, 11 = up to 0, 1, 2, 3 in decimal.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ub124\ud2b8\uc6cc\ud06c\ub85c \ub370\uc774\ud130 \ubcf4\ub0b4\uae30(0x12345678)<br>Send data over network (0x12345678)<\/p>\n\n\n\n<p>\u2714\ufe0f 1\ubc14\uc774\ud2b8\uc529 \ubcf4\ub0bc \ub54c <br>When sending 1 byte at a time<\/p>\n\n\n\n<p>&#8212; \ub124\ud2b8\uc6cc\ud06c\ub85c \ubcf4\ub0bc \ub550 \ubb34\uc870\uac74&nbsp;<code>uint8_t<\/code>&nbsp;\ubc30\uc5f4, \uc989 \ubc14\uc774\ud2b8 \ub2e8\uc704\ub85c \ubcf4\ub0b4\uc57c \ud569\ub2c8\ub2e4.<br>When sending over a network, you must always send it as a uint8_t array, that is, in byte units.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uint8_t buf&#91;4] = {0x12, 0x34, 0x56, 0x78};\nsend(socket, buf, 4); \/\/ 1\ubc14\uc774\ud2b8\uc529 4\ubc88 \uc804\uc1a1\ub428 \/ Transmitted 4 times, 1 byte at a time<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f 2\ubc14\uc774\ud2b8\uc529 \ubcf4\ub0bc\ub54c(\ucd94\ucc9c\ud558\uc9c0 \uc54a\uc74c)<br>When sending 2 bytes at a time (not recommended)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uint16_t buf&#91;2] = {htons(0x1234), htons(0x5678)};\nsend(socket, buf, 4); \/\/ 12 34 56 78<\/code><\/pre>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb1\ubc14\uc774\ud2b8\ub97c \uc77d\ub294 \ub2e4\ub294 \uc758\ubbf8\ub294 \uc18c\ucf13 \ubc84\ud37c\uc5d0 \ub4e4\uc5b4\uc628 \uc2e4\uc81c \ub370\uc774\ud130(\uc22b\uc790)\ub97c \uc77d\ub294 \ub2e4\ub294 \ub73b\uc785\ub2c8\ub2e4.(\ud3ec\uc778\ud130 \uc8fc\uc18c\ub791 \uad00\ub828 \uc5c6\uc74c)<br>Reading 1 byte means reading the actual data (number) that has entered the socket buffer. (It is not related to pointer addresses.)<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb fmt \uac12\uc5d0 \ub530\ub978 \ud5e4\ub4dc\ud06c\uae30 \uc124\uc815 \uc815\ubcf4\ub294 \ub2e4\uc74c\uacfc \uac19\uc2b5\ub2c8\ub2e4.<br>The head size setting information based on the fmt value is as follows.<\/p>\n\n\n\n<p>\u2714\ufe0f \ud5e4\ub354 \ud06c\uae30, \ubcf4\ub0b4\ub294 \uc815\ubcf4<br>Header size, information being sent<\/p>\n\n\n\n<p>&#8212; msg_len\uc740 \uc2e4\uc81c\ub85c \ubcf4\ub0b4\uc9c0\ub294 \ub3d9\uc601\uc0c1 \ub370\uc774\ud130 \ud06c\uae30 \uc785\ub2c8\ub2e4.<br>msg_len is the actual size of the video data being sent.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>fmt<\/th><th>\uc774\ub984<br>name<\/th><th>\ud5e4\ub354 \ud06c\uae30header size<\/th><th>\uc0ac\uc6a9\ud560\ub54c<br>When to use<\/th><th>\ubcf4\ub0b4\ub294 \uc815\ubcf4<br>Sending information<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td>Type 0<\/td><td>11 byte<\/td><td>\uc0c8 \uba54\uc2dc\uc9c0 \uc2dc\uc791<br>Start a new message<\/td><td>timestamp 3Byte <br>+ msg_len 3B<br>+ msg_type 1B <br>+ stream_id 4B<\/td><\/tr><tr><td>1<\/td><td>Type 1<\/td><td>7 byte<\/td><td>\uac19\uc740 stream_id, \ud0c0\uc785\ub9cc \uc774\uc5b4\uc11c \ubcf4\ub0bc \ub54c<br>When concatenating only stream_id and type<\/td><td>timestamp_delta(\ucc28\uc774\uac12\/difference value) 3B <br>+ msg_len 3B + msg_type 1B<\/td><\/tr><tr><td>2<\/td><td>Type 2<\/td><td>3 byte<\/td><td>msg_len, type \ub2e4 \uac19\uace0 \uc2dc\uac04\ub9cc \ubc14\ub014 \ub54c<br>When msg_len and type are the same and only the time changes<\/td><td>timestamp_delta(\ucc28\uc774\uac12\/diffrence value) 3B<\/td><\/tr><tr><td>3<\/td><td>Type 3<\/td><td>0 byte<\/td><td>\ud5e4\ub354 \uc804\ubd80 \uc774\uc804\uc774\ub791 \uac19\uc744 \ub54c<br>When all headers are the same as before<\/td><td>\uc544\ubb34\uac83\ub3c4 \uc5c6\uc74c<br>nothing<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2714\ufe0f \ud5e4\ub354 \ubc30\uc5f4 \/ header array<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>fmt<\/th><th>\ud5e4\ub354 \ubc14\uc774\ud2b8 \ubc30\uc5f4 \/ header byte array<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td><code>[TS0][TS1][TS2][Len0][Len1][Len2][Type][StreamID0\u223c3]<\/code>&nbsp;= 11B<\/td><\/tr><tr><td>1<\/td><td><code>[TS0][TS1][TS2][Len0][Len1][Len2][Type]<\/code>&nbsp;= 7B<\/td><\/tr><tr><td>2<\/td><td><code>[TS0][TS1][TS2]<\/code>&nbsp;= 3B<\/td><\/tr><tr><td>3<\/td><td>\uc5c6\uc74c<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u2714\ufe0f \ud328\ud0b7\uc5d0\uc11c \uac12\uc744 \ud655\uc778 \ud560\ub54c \ud5e4\ub354\ub2e4\uc74c\uc5d0 \ubcf8\ubb38(payload)\uc774 \uc635\ub2c8\ub2e4. \ubcf8\ubb38\uc758 \uacbd\uacc4\ub97c \ud655\uc778\ud558\uae30 \uc704\ud574\uc11c \ud5e4\ub354\uc758 \ud06c\uae30\ub97c \uc54c\uc544\uc57c\ud560 \ud544\uc694\uac00 \uc788\uc2b5\ub2c8\ub2e4.<br>When checking values \u200b\u200bin a packet, the body (payload) follows the header. To check the boundaries of the body, it is necessary to know the size of the header.<\/p>\n\n\n\n<p>\u2714\ufe0f \ud5e4\ub354\uc0ac\uc774\uc988\uac00 0\uc774\uba74 read_chunk_data()\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>If header size is 0, execute read_chunk_data().<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    size_t header_size = (fmt == 0)? 11 : (fmt == 1)? 7 : (fmt == 2)? 3 : 0;\n    if (header_size == 0) {\n        read_chunk_data();\n        return;\n    }<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ud5e4\ub354\uc5d0 \ubcc0\ud654\uac00 \uc788\ub294 \uacbd\uc6b0,\ud0c0\uc784\uc2a4\ud0ec\ud504 \uc870\ub9bd<br>If there is a change in the header, timestamp assembly<\/p>\n\n\n\n<p>&#8212; \uadf8\ub0e5 [0],[1],[2]\ub294 \uc790\ub9bf\uc218\uac00 \uacb9\uce58\uc9c0 \uc54a\uc73c\ubbc0\ub85c or \uc5f0\uc0b0\ud558\uba74 \uadf8\ub300\ub85c \ub0b4\ub824\uc635\ub2c8\ub2e4.<br>Since [0], [1], and [2] do not have overlapping digits, they come down as they are when performing an OR operation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     if (fmt &lt;= 2) {\n         \/\/ | \ub294 or\uc5f0\uc0b0 \ub458\uc911 \ud558\ub098\ub77c\ub3c4 1\uc774\uba74 1,\uc544\ub798\ub294 \uc14b\uc911 \ud558\ub098\ub77c\ub3c4 1\uc774\uba74 1\n         \/\/ | is the OR operation; if at least one of the pairs is 1, the result is 1. The one below is 1 if at least one of the three is 1.\n         timestamp = (msg_header_buf_&#91;0] &lt;&lt; 16) | \n                     (msg_header_buf_&#91;1] &lt;&lt; 8) |  \n                      msg_header_buf_&#91;2];          \n                                                         \n     }<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># 01 E2 40 3\ubc14\uc774\ud2b8\uac00 \ub4e4\uc5b4\uc654\uc744 \uacbd\uc6b0\n# 01 E2 40 If 3 bytes are received\n\nmsg_header_buf_&#91;0] = 0x01 = 00000001 = 1\nmsg_header_buf_&#91;1] = 0xE2 = 11100010 = 226\nmsg_header_buf_&#91;2] = 0x40 = 01000000 = 64\n\n# \uc67c\ucabd\uc73c\ub85c 16\ube44\ud2b8 \ubc00\uae30\n# Shift 16 bits to the left\n(0x01 &lt;&lt; 16) = 0x010000 = 00000001 00000000\n\n# \uc67c\ucabd\uc73c\ub85c 8\ube44\ud2b8 \ubc00\uae30\n# Shift 8 bits to the left\n(0xE2 &lt;&lt; 8) = 0x00E200 = 00000000 11100010 00000000\n\n# \ube44\ud2b8\ubc00\uae30 \uc5c6\uc74c\n# No beet milling\n 0x40 = 0x000040 = 00000000 00000000 01000000\n\n-------------------------------- OR \uc5f0\uc0b0 \/ OR operation\n               0x01E240 = 00000001 11100010 01000000 = 123456<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc0c8 \ub9e4\uc138\uc9c0 \uc2dc\uc791,\ud655\uc7a5 \ud0c0\uc784\uc2a4\ud15c\ud504 \uc0ac\uc6a9,\ub3d9\uc601\uc0c1 \ud06c\uae30<br>Start new message, use extended timestamp, video size<\/p>\n\n\n\n<p>&#8212; 0xFFFFFF = 16,777,215 3\ubc14\uc774\ud2b8\ub85c \ud45c\ud604 \uac00\ub2a5\ud55c \ucd5c\ub300\uac12\uc73c\ub85c \ud655\uc7a5 \ud0c0\uc784\uc2a4\ud0ed\ud504\ub97c \uc0ac\uc6a9\ud574\uc57c\ud568\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4.<br>0xFFFFFF = 16,777,215, the maximum value that can be represented by 3 bytes, meaning that an extended timestamp must be used.<\/p>\n\n\n\n<p>&#8212; \uc0c8 \uba54\uc138\uc9c0 \ud5e4\ub354 \/New message header:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>timestamp 3(0~2)Byte + msg_len 3(3~5)B + msg_type 1(6)B + extended timestamp 4(7~10)B + stream_id 4B<\/code><\/pre>\n\n\n\n<p>&#8212; msg_len\uc740 \uc774\ubc88\uc5d0 \ubcf4\ub0bc FLV tag\/Video frame\/Audio packet \uc804\uccb4 \ud06c\uae30\uc785\ub2c8\ub2e4.<br>msg_len is the total size of the FLV tag\/Video frame\/Audio packet to be sent this time.<\/p>\n\n\n\n<p>&#8212; cur_msg_stream_ \ub294 stream_id\ub85c little endian\uc73c\ub85c \ubcc0\ud658\ud569\ub2c8\ub2e4.<br>cur_msg_stream_ converts to little endian with stream_id.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> if (fmt == 0) {\n\n     cur_msg_timestamp_ = timestamp;\n     \/\/ 0xFFFFFF = 16,777,215 3\ubc14\uc774\ud2b8\ub85c\ud45c\ud604\uac00\ub2a5\ud55c \ucd5c\ub300\uac12,\n     \/\/ 0xFFFFFF = 16,777,215, the maximum value that can be represented by 3 bytes\n     \/\/ \ud655\uc7a5\ud544\ub4dc \/ extended field\n     if (timestamp == 0xFFFFFF &amp;&amp; header_size &gt;= 11) {\n        \/\/ use extended timestamp\n        cur_msg_timestamp_ = (msg_header_buf_&#91;7] &lt;&lt; 24) |\n                             (msg_header_buf_&#91;8] &lt;&lt; 16) |\n                             (msg_header_buf_&#91;9] &lt;&lt; 8) |\n                              msg_header_buf_&#91;10];\n      }\n     \/\/ msg_len\n     cur_msg_len_ = (msg_header_buf_&#91;3] &lt;&lt; 16) | \n                    (msg_header_buf_&#91;4] &lt;&lt; 8) | msg_header_buf_&#91;5];\n     \/\/ msg_type\n     cur_msg_type_ = msg_header_buf_&#91;6];\n     \/\/ stream_id \n     \/\/ little endian\uc73c\ub85c \ubcc0\ud658\n     cur_msg_stream_ = msg_header_buf_&#91;7] | \n                       (msg_header_buf_&#91;8] &lt;&lt; 8) |\n                       (msg_header_buf_&#91;9] &lt;&lt; 16) | \n                       (msg_header_buf_&#91;10] &lt;&lt; 24);\n     payload_buf_.clear();\n     payload_bytes_read_ = 0;<\/code><\/pre>\n\n\n\n<p>&#8212; stream_id\uac00 \ub3d9\uc77c\ud55c \uacbd\uc6b0,timestamp \ub204\uc801,\uae30\uc874 \uac12\uc740 \ub3d9\uc77c\ud569\ub2c8\ub2e4.<br>If stream_id is the same, timestamps accumulate, and existing values \u200b\u200bare identical.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>} else if (fmt == 1) {\n           \/\/ timestamp \ub204\uc801\n           \/\/ timestamp cumulative\n           cur_msg_timestamp_ += timestamp;\n\n           \/\/ msg_len\n           cur_msg_len_ = (msg_header_buf_&#91;3] &lt;&lt; 16) | \n                          (msg_header_buf_&#91;4] &lt;&lt; 8) | msg_header_buf_&#91;5];\n           \/\/ msg_type\n           cur_msg_type_ = msg_header_buf_&#91;6];\n           payload_buf_.clear();\n           payload_bytes_read_ = 0;\n\n           \/\/ \ub098\uba38\uc9c0\ub3d9\uc77c\ud558\uace0 \uc2dc\uac04\ub9cc \ubc14\ub00c\ub294 \uacbd\uc6b0\n           \/\/ Cases where everything else is the same and only the time changes\n} else if (fmt == 2) {\n            cur_msg_timestamp_ += timestamp;\n}<\/code><\/pre>\n\n\n\n<p>&#8212; read_chunk_data();\ub97c \uc2e4\ud589\ud569\ub2c8\ub2e4.<br>Execute read_chunk_data();<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Execute read_chunk_data();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc5ec\uae30\ub294 void RtmpSession::read_message_header(uint8_t fmt, uint32_t cs_id) { } \uc774 \ud568\uc218\uc5d0 \ub300\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.Here is the description for the function void RtmpSession::read_message_header(uint8_t fmt, uint32_t cs_id) { }. \ud83d\udc49\ud83c\udffb OBS\uac00 \ubcf4\ub0b8 chunk\uc5d0\uc11c fmt 0\u223c3\uc5d0 \ub530\ub77c \uac00\ubcc0 \ud5e4\ub354\ub97c \uc77d\uace0, \ud604\uc7ac \uba54\uc2dc\uc9c0\uc758 timestamp, length, type, stream_id\ub97c \uac31\uc2e0\ud569\ub2c8\ub2e4.Read variable headers according to fmt 0~3 from the chunk sent by OBS, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,1],"tags":[],"class_list":["post-5761","post","type-post","status-publish","format-standard","hentry","category-cpp","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5761","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=5761"}],"version-history":[{"count":3,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5761\/revisions"}],"predecessor-version":[{"id":5763,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5761\/revisions\/5763"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}