{"id":5766,"date":"2026-05-25T13:30:00","date_gmt":"2026-05-25T04:30:00","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=5766"},"modified":"2026-05-25T13:48:54","modified_gmt":"2026-05-25T04:48:54","slug":"mediaservermini_mediaserver_1-code-description-read_chunk_data1-5","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/05\/25\/mediaservermini_mediaserver_1-code-description-read_chunk_data1-5\/","title":{"rendered":"[Mediaserver]mini_Mediaserver_1-\ucf54\ub4dc\uc124\uba85\/code description-read_chunk_data()(1-5)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb msg_len\ub9cc\ud07c \ub2e4 \ubc1b\uc544\uc11c \uc644\uc131\ub41c RTMP \uba54\uc2dc\uc9c0 \ud558\ub098\ub97c msg_type\ubcc4\ub85c \ubd84\uae30 \ucc98\ub9ac\ud558\ub294 \ud568\uc218 \uc785\ub2c8\ub2e4.<br>This is a function that receives msg_len and processes a completed RTMP message by branching according to msg_type.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \uc804\uccb4 \ub370\uc774\ud130 \ud750\ub984 \uc694\uc57d (\ubc29\uc1a1\/\uc2a4\ud2b8\ub9ac\ubc0d \uad00\uc810)<br>Summary of Overall Data Flow (Broadcast\/Streaming Perspective)<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-left\" data-align=\"left\">\ub2e8\uacc4\/Stage<\/th><th class=\"has-text-align-left\" data-align=\"left\">\uc8fc\uccb4\/Subject<\/th><th class=\"has-text-align-left\" data-align=\"left\">\uc77c\uc5b4\ub098\ub294 \uc77c (\uac1c\ub150) \/ <br>Things that happen (concept)<\/th><th class=\"has-text-align-left\" data-align=\"left\">\uae30\uc220\uc801 \ud45c\ud604 (\ub370\uc774\ud130 \uc0c1\ud0dc) \/ <br>Technical representation (data state)<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-left\" data-align=\"left\">1. \ucea1\ucc98 \ubc0f \ubcc0\ud658 (Capture and Transform)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uce74\uba54\ub77c\/\ub9c8\uc774\ud06c(Camera\/Microphone)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uc544\ub0a0\ub85c\uadf8 \uc2e0\ud638(\uc2e4\uc81c \ube5b\/\uc18c\ub9ac)\ub97c \ub514\uc9c0\ud138 \ub370\uc774\ud130(\uc22b\uc790)\ub85c \ubcc0\ud658\ud569\ub2c8\ub2e4.(Converts analog signals (actual light\/sound) into digital data (numbers).)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ub514\uc9c0\ud138 \ube44\ud2b8(Digital Bits)<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">2. \uc555\ucd95 (Encoding)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uc778\ucf54\ub354 (Encoder)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uc0ac\ub78c\uc774 \uac10\uc9c0\ud558\uae30 \uc5b4\ub824\uc6b4 \uc911\ubcf5 \uc815\ubcf4(\uc608: \uc5f0\uc18d\ub41c \ubc30\uacbd \uc0c9\uc0c1)\ub97c \uc81c\uac70\ud558\uc5ec \ub370\uc774\ud130 \ud06c\uae30\ub97c \ud68d\uae30\uc801\uc73c\ub85c \uc904\uc785\ub2c8\ub2e4.(Significantly reduces data size by removing redundant information that is difficult for humans to detect (e.g., continuous background colors).)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uc2a4\ud2b8\ub9bc \ub370\uc774\ud130 (Stream Data)<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">3. \uc804\uc1a1 \ubc0f \ud3ec\uc7a5(Transport and Packaging)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ud504\ub85c\ud1a0\ucf5c\/\ub124\ud2b8\uc6cc\ud06c<br>(Protocol\/Network)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uc774 \uc555\ucd95\ub41c \ub370\uc774\ud130\ub97c \uc2dc\uac04 \uc21c\uc11c\ub300\ub85c \ucabc\uac1c\uace0, \uc190\uc2e4\ub418\uac70\ub098 \uc21c\uc11c\uac00 \uaf2c\uc774\ub294 \uac83\uc744 \ub9c9\uae30 \uc704\ud574 &#8216;\ubd09\ud22c(\ud328\ud0b7)&#8217;\uc5d0 \ub123\uc5b4 \uc804\uc1a1\ud569\ub2c8\ub2e4.(This compressed data is split into chronological chunks and sent in &#8216;envelopes (packets)&#8217; to prevent loss or out-of-order transmission.)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ud328\ud0b7(Packet)<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">4. \uc218\uc2e0 \ubc0f \uc5ed\uc555\ucd95<br>(Reception and inverse compression)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ub514\ucf54\ub354 (Decoder)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ub3c4\ucc29\ud55c \ud328\ud0b7\ub4e4\uc744 \ubaa8\uc73c\uace0, \uc21c\uc11c\ub97c \ub9de\ucd94\uba70, \uc555\ucd95\uc744 \ud480\uc5b4 \uc6d0\ub798\uc758 \ub370\uc774\ud130\ub97c \ubcf5\uc6d0\ud569\ub2c8\ub2e4.(It collects incoming packets, rearranges them, and decompresses them to restore the original data.)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ub514\uc9c0\ud138 \ube44\ud2b8 \ubcf5\uc6d0(digital bit restoration)<\/td><\/tr><tr><td class=\"has-text-align-left\" data-align=\"left\">5. \ub514\uc2a4\ud50c\ub808\uc774(display)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ubaa8\ub2c8\ud130\/\uc2a4\ud53c\ucee4(Monitor\/Speaker)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\ub514\uc9c0\ud138 \ube44\ud2b8\ub97c \uc804\uae30\uc801 \uc544\ub0a0\ub85c\uadf8 \uc2e0\ud638\ub85c \ub2e4\uc2dc \ubcc0\ud658\ud558\uc5ec \uc2dc\uac01\uc801, \uccad\uac01\uc801 \uacb0\uacfc\ubb3c\ub85c \ucd9c\ub825\ud569\ub2c8\ub2e4.<br>(It converts digital bits back into electrical analog signals and outputs them as visual and auditory results.)<\/td><td class=\"has-text-align-left\" data-align=\"left\">\uc544\ub0a0\ub85c\uadf8 \uc2e0\ud638(analog signal)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ucf54\ub4dc\uc124\uba85 \/ Code Description<\/p>\n\n\n\n<p>\u2714\ufe0f \uc774 \ud568\uc218\uac00 \ubc18\ubcf5\ud574\uc11c \ud568\uc218\uac00 \uc2e4\ud589\ub420 \ub54c \ub354 \ubc1b\uc544\uc57c\ud560 \ub370\uc774\ud130\uc591 \uacc4\uc0b0\ud558\uae30<br>Calculate the amount of additional data to receive when this function is executed repeatedly<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    \/\/ \uc544\uc9c1 \ub354 \ubc1b\uc544\uc57c\ud560 \ub370\uc774\ud130 \uc591,payload_bytes_read_ += to_read;\n    uint32_t remaining = cur_msg_len_ - payload_bytes_read_;\n    \/\/ \uc774 \ubc88\uc5d0 \uc694\uccad\ud55c \ub370\uc774\ud130 \uc591\n    \/\/ The amount of data requested this time\n    uint32_t to_read = std::min(remaining, chunk_size_in_);<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc601\uc0c1 \ud504\ub808\uc784\ud558\ub098 \ub2e4 \ubc1b\uc740 \uacbd\uc6b0<br>In the case where an entire video frame has been received<\/p>\n\n\n\n<p>&#8212; \ubc1b\uc544\uc57c\ud560 \ub370\uc774\ud130\uc591\uc774 0\uc778\uacbd\uc6b0<br>When the amount of data to be received is 0<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (to_read == 0) {\n   \/\/ msg_type\ubcc4\ub85c \ubd84\uae30 \ucc98\ub9ac\ud558\ub294 \ud568\uc218\n   \/\/ Function to handle branching based on msg_type\n   process_complete_message();\n\n   \/\/fmt,cs_id \ucd94\ucd9c,\ub370\uc774\ud130 \ubc1b\uae30 \ub2e4\uc2dc \uc2e4\ud589\n   \/\/ Extract fmt, cs_id, retrieve data, run again\n   read_chunk_header(); \n   return;\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f read_chunk_data() \ud568\uc218\uc5d0\uc11c payload_buf_\uc5d0 \ub370\uc774\ud130 \uc804\ub2ec\ub429\ub2c8\ub2e4.<br>Data is passed to payload_buf_ in the read_chunk_data() function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    asio::async_read(socket_, asio::buffer(<strong>payload_buf_<\/strong>.data() + offset, to_read),\n        \/\/bytes_read\ub294 asio\uac00 \ucf5c\ubc31 \ubd80\ub97c \ub54c \ucc44\uc6cc\uc8fc\ub294 \uac12,asio\uac00 \uc804\ub2ec\ud558\ub294 \uc778\uc790.\n        \/\/bytes_read is the value that asio fills when calling the callback, an argument passed by asio.\n        &#91;this, self, to_read](std::error_code ec, std::size_t bytes_read) { ...}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \uc124\uc815\ub41c \ub370\uc774\ud130 5MB\ub97c \ub2e4 \ubc1b\uc740 \uacbd\uc6b0 ack\ubcf4\ub0b4\uae30<br>Send ack when all 5MB of configured data has been received<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (bytes_received_ - last_ack_sent_ &gt;= ack_window_size_) {\n    \/\/ obs\uc5d0 \ubc1b\uc751 \uc6a9\ub7c9 \uc815\ubcf4 \uc804\uc1a1\n    \/\/ Send received capacity information to OBS\n    send_acknowledgement();\n}<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ub370\uc774\ud130\ud06c\uae30 \ub9cc\ud07c \ub370\uc774\ud130\ub97c \ub2e4 \ubc1b\uc558\ub2e4\uba74 \ubb34\ube44 \ud30c\uc77c\ub85c \ud30c\uc2f1\ud558\uae30<br>If you have received all the data up to the data size, parse it into a movie file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> if (payload_bytes_read_ &gt;= cur_msg_len_) {\n    \/\/ FLV \uc4f0\uac70\ub098 AMF \ud30c\uc2f1\n    \/\/ Use FLV or parse AMF\n    process_complete_message();\n }<\/code><\/pre>\n\n\n\n<p>\u2714\ufe0f \ub354 \ubc1b\uc544\uc57c\ud560\ub370\uc774\ud130\uac00 \uc788\ub2e4\uba74 \ub2e4\uc2dc \ubc18\ubcf5\ud574\uc11c \uc2e4\ud589<br>If there is more data to receive, repeat the execution.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>read_chunk_data();<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb msg_len\ub9cc\ud07c \ub2e4 \ubc1b\uc544\uc11c \uc644\uc131\ub41c RTMP \uba54\uc2dc\uc9c0 \ud558\ub098\ub97c msg_type\ubcc4\ub85c \ubd84\uae30 \ucc98\ub9ac\ud558\ub294 \ud568\uc218 \uc785\ub2c8\ub2e4.This is a function that receives msg_len and processes a completed RTMP message by branching according to msg_type. \ud83d\udc49\ud83c\udffb \uc804\uccb4 \ub370\uc774\ud130 \ud750\ub984 \uc694\uc57d (\ubc29\uc1a1\/\uc2a4\ud2b8\ub9ac\ubc0d \uad00\uc810)Summary of Overall Data Flow (Broadcast\/Streaming Perspective) \ub2e8\uacc4\/Stage \uc8fc\uccb4\/Subject \uc77c\uc5b4\ub098\ub294 \uc77c (\uac1c\ub150) \/ Things that happen (concept) \uae30\uc220\uc801 \ud45c\ud604 [&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-5766","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\/5766","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=5766"}],"version-history":[{"count":5,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5766\/revisions"}],"predecessor-version":[{"id":5772,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/5766\/revisions\/5772"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=5766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=5766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=5766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}