{"id":6184,"date":"2026-07-07T12:46:17","date_gmt":"2026-07-07T03:46:17","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=6184"},"modified":"2026-07-07T13:42:20","modified_gmt":"2026-07-07T04:42:20","slug":"mediaserver-mini_mediaserver_8-code-description-amf0-cpp1-8","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/07\/07\/mediaserver-mini_mediaserver_8-code-description-amf0-cpp1-8\/","title":{"rendered":"[Mediaserver]mini_Mediaserver_1-\ucf54\ub4dc\uc124\uba85\/code description-amf0.cpp(1-8)"},"content":{"rendered":"\n<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\ub294 amf0.cpp \ud30c\uc77c\uc774 \ud568\uc218\uc5d0 \ub300\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.<br>Below is a description of the functions in the amf0.cpp file.<\/p>\n\n\n\n<p>\ud83d\udc49\ud83c\udffb \ucf54\ub4dc \uc124\uba85 \/ Code Explanation<\/p>\n\n\n\n<p>\u2714\ufe0f void Amf0::parse_object(const std::vector&amp; buf, size_t&amp; pos) { } <\/p>\n\n\n\n<p>&#8212; RTMP \ud328\ud0b7 \uc548\uc5d0 \ub4e4\uc5b4\uc788\ub294 AMF0 Object\ub97c \uc77d\uc5b4\uc11c \ubc84\ud37c \ud3ec\uc778\ud130\ub97c \ub2e4\uc74c \ud544\ub4dc\ub85c \uc62e\uae30\ub294 \uc6a9\ub3c4\uc785\ub2c8\ub2e4.<br>It is used to read an AMF0 object contained within an RTMP packet and advance the buffer pointer to the next field.<\/p>\n\n\n\n<p>&#8212; \uc608\uc2dc\ub370\uc774\ud130(\ubc84\ud37c \ud398\uc774\ub85c\ub4dc)<br>Example data (buffer payload)<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>03 | 00 03 'a' 'p' 'p' | 02 00 04 'l' 'i' 'v' 'e' | 00 05 'f' 'p' 'a' 'd' | 01 00 | 00 00 09<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>pos 0 : 03 \/\/ AMF0 Object \uc2dc\uc791 \/ AMF0 Object Start\npos 1-2: 00 03 \/\/ key \uae38\uc774 3 \/ Key length 3\npos 3-5: 61 70 70 \/\/ 'a' 'p' 'p'\npos 6 : 02 \/\/ value \ud0c0\uc785 = string \/ value type = string\npos 7-8: 00 04 \/\/ string \uae38\uc774 4 \/ String length 4\npos 9-12: 6c 69 76 65 \/\/ 'l' 'i' 'v' 'e'\npos13-14: 00 05 \/\/ key \uae38\uc774 5 \/ Key length 5\npos15-19: 66 70 61 64 \/\/ 'f' 'p' 'a' 'd'\npos20 : 01 \/\/ value \ud0c0\uc785 = boolean \/ value type = boolean\npos21 : 00 \/\/ false\npos22-23: 00 00 \/\/ key \uae38\uc774 0 \/ key length 0\npos24 : 09 \/\/ object end<\/code><\/pre>\n\n\n\n<p>&#8212; pos \uac12\uc740 0\uc778 \uacbd\uc6b0\ub85c \ud569\ub2c8\ub2e4.<br>Assume the value of &#8216;pos&#8217; is 0.<\/p>\n\n\n\n<p>&#8212; 0x03\uc73c\ub85c\uc2dc\uc791\ud558\ub294\uc9c0 \ud655\uc778<br>Check if it starts with 0x03.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (pos &gt;= buf.size() || buf&#91;pos]!= 0x03) return;<\/code><\/pre>\n\n\n\n<p>&#8212; 0x03\uc704\uce58 \ub2e4\uc74c\uc73c\ub85c \ud3ec\uc778\ud130\uc774\ub3d9,1,pos\uae30\ubcf8\uac12 = 0<br>0x03 Move pointer to position; default pos = 0.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pos++;<\/code><\/pre>\n\n\n\n<p>&#8212; while (3 &lt; 25) \uc778\uacbd\uc6b0 \uc785\ub2c8\ub2e4.<br>This is the case where <code>while (3 &lt; 25)<\/code> applies.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (pos + 2 &lt; buf.size()) { ...} <\/code><\/pre>\n\n\n\n<p>&#8212; buf[pos]\ub97c \uc0c1\uc704\ubc14\uc774\ud2b8\ub85c \uc774\ub3d9\ud558\uace0 \ud558\uc704\ub294 8\ube44\ud2b8( 1\ubc14\uc774\ud2b8 \ub85c \ucc44\uc6c1\ub2c8\ub2e4.(1\ubc14\uc774\ud2b8 \uc0ac\uc6a9\uc2dc 16\uc9c4\uc218\ub294 \ub450\uc790\ub9ac \uc0ac\uc6a9\ud569\ub2c8\ub2e4.)<br>Move <code>buf[pos]<\/code> to the high byte and fill the low byte with 8 bits (1 byte). (Two hexadecimal digits are used for a single byte.)<\/p>\n\n\n\n<p>&#8212; pos=1 : buf[1] = 0x00,pos=2 : buf[2] = 0x03,len = (0x00 &lt;&lt; 8) | 0x03 = 0x0000 | 0x0003 = 3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pos=1 : buf&#91;1] = 0x00\npos=2 : buf&#91;2] = 0x03\nlen = (0x00 &lt;&lt; 8) | 0x03 = 0x0000 | 0x0003 = 3<\/code><\/pre>\n\n\n\n<p>&#8212; \uc5ec\uae30\uc11c pos=3 \uc774 \ub429\ub2c8\ub2e4.<br>Here, pos becomes 3.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pos += 2;<\/code><\/pre>\n\n\n\n<p>&#8212; if( 3 &lt; 25 &amp;&amp; buf[3] == 0x09)\uc774\uba70 ,0x09\ub294 \ubc84\ud37c\ub05d\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4.<br>If <code>3 &lt; 25 &amp;&amp; buf[3] == 0x09<\/code> is true, then <code>0x09<\/code> signifies the end of the buffer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> if (pos &lt; buf.size() &amp;&amp; buf&#91;pos] == 0x09) { pos++; break; }<\/code><\/pre>\n\n\n\n<p>&#8212; if(3 + 3) > 25 return;\uc774 \ub429\ub2c8\ub2e4.<br>It becomes <code>if(3 + 3) > 25 return;<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (pos + len &gt; buf.size()) return;<\/code><\/pre>\n\n\n\n<p>&#8212; vector\uc5d0\uc11c \uc9c0\uc815\ud55c \uad6c\uac04\ub9cc\ud07c \uc798\ub77c\uc11c std::string\uc73c\ub85c \ubcf5\uc0ac\ud558\ub294 \uc0dd\uc131\uc790\uc785\ub2c8\ub2e4.<br>This is a constructor that extracts a specified range from a vector and copies it into an std::string.<\/p>\n\n\n\n<p>&#8212; string key(3,6)\uc774\ub418\uace0 ,6\uc55e\uae4c\uc9c0\ub9cc \uc0ac\uc6a9\ud558\ubbc0\ub85c 6\uc740 \ud3ec\ud568\ub418\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<br>The string key is (3, 6); since it is used only up to the position before 6, the value 6 is not included.<\/p>\n\n\n\n<p>&#8212; \uadf8\ub7ec\uba74 \ubc84\ud37c\uc5d0\uc11c app\uc774\ub780 \uae00\uc790\ub97c \ucd94\ucd9c\ud558\uac8c\ub429\ub2c8\ub2e4.<br>Then, the string &#8220;app&#8221; is extracted from the buffer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>std::string key(buf.begin() + pos, buf.begin() + pos + len);<\/code><\/pre>\n\n\n\n<p>&#8212; pos\uac00 3\uc774\uace0 len\uc774\ub2c8\uae4c \uacb0\uad6d pos\ub294 6\uc774 \ub429\ub2c8\ub2e4.<br>Since pos is 3 and we add len, pos ultimately becomes 6.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pos += len;<\/code><\/pre>\n\n\n\n<p>&#8212; skip_value(buf, 6) \uc774 \uc2e4\ud589\ub429\ub2c8\ub2e4.<br><code>skip_value(buf, 6)<\/code> is executed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>skip_value(buf, pos);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2714\ufe0f static void skip_value(const std::vector&amp; buf, size_t&amp; pos) { &#8230; }<\/p>\n\n\n\n<p>&#8212; parse_object\uc5d0\uc11c pos\ucd08\uae30 \uac12\uc774 0\uc778 \uacbd\uc6b0 \uc5ec\uae30\ub294 6\uc774 \ub429\ub2c8\ub2e4.<br>If the initial value of <code>pos<\/code> in <code>parse_object<\/code> is 0, it becomes 6 here.<\/p>\n\n\n\n<p>&#8212; pos 0 \u2192 03,pos 6 \u2192 02,pos 19 \u2192 01 \uc774 \uc138\uacf3\uc678\uc5d0\ub294 \ub370\uc774\ud130\ub97c \uc77d\ub294 \ubd80\ubd84\uc774 \uc5c6\uc2b5\ub2c8\ub2e4.<br>There are no data-reading points other than these three locations: pos 0 \u2192 03, pos 6 \u2192 02, and pos 19 \u2192 01.<\/p>\n\n\n\n<p>&#8212; \uc544\ub798\uc758 case\uc5d0\uc11c\ub3c4 \ub098\uba38\uc9c0\ub294 \uc801\uc6a9 \ub418\uc9c0 \uc54a\uc2b5\ub2c8\ub2e4.<br>The rest do not apply in the case below either.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    if (pos &gt;= buf.size()) return;\n    uint8_t t = buf&#91;pos];<\/code><\/pre>\n\n\n\n<p>&#8212; \uc22b\uc790\uc778 \uacbd\uc6b0\ub97c \uc758\ubbf8\ud558\uba70 \ud604\uc7ac\ub294 \ud574\ub2f9\ud558\ub294 \ubd80\ubd84\uc774 \uc5c6\uc2b5\ub2c8\ub2e4.(pos\uac00 00\ub97c \uc77d\uc744 \uc77c\uc774 \uc5c6\uc74c)<br>This refers to the case where the value is a number; currently, there is no corresponding instance (as <code>pos<\/code> never reads <code>00<\/code>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>case 0x00: pos += 9; break;<\/code><\/pre>\n\n\n\n<p>&#8212; case 0x01: boolean&lt;-pos+=2->\uc778\uac74 \uadf8\ub0e5 AMF0 \uc2a4\ud399\uc5d0 \ub530\ub77c \uc815\ud574\uc9c4\uac83 \uc785\ub2c8\ub2e4.<br>The <code>case 0x01: boolean&lt;-pos+=2-><\/code> part is simply determined by the AMF0 specification.<\/p>\n\n\n\n<p>&#8212; buf[20] \uc778\uacbd\uc6b0 pos\ub294 22\uac00\ub418\uba70 \uac12\uc740 00\uac00 \ub429\ub2c8\ub2e4.<br>If buf[20] is used, pos becomes 22 and the value becomes 00.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>case 0x01: pos += 2; break;<\/code><\/pre>\n\n\n\n<p>&#8212; buf[6], pos=6<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>case 0x02: { size_t tmp=pos; Amf0::parse_string(buf, tmp); pos=tmp; break; }<\/code><\/pre>\n\n\n\n<p>&#8212; pos = 0 \uc778\uacbd\uc6b0<br>When pos is 0<\/p>\n\n\n\n<p>&#8212; Amf0::parse_object(buf, 6); \uac12\uc774 \ub300\uc785\ub429\ub2c8\ub2e4.<br>The value <code>Amf0::parse_object(buf, 6)<\/code> is assigned.<\/p>\n\n\n\n<p>&#8212; \uc704\uc758 \ud568\uc218\ub0b4\uc5d0\uc11c std::string str(buf.begin() + pos, buf.begin() + pos + len); \uc774 \ubd80\ubd84\uc73c\ub85c \ubb38\uc790\uc5f4\uc744 \ucd94\ucd9c\ud569\ub2c8\ub2e4.<br>Within the function above, the string is extracted using this part: <code>std::string str(buf.begin() + pos, buf.begin() + pos + len);<\/code>.<\/p>\n\n\n\n<p>&#8212; std::string str(9,13); \uc774\ub807\uac8c \uac12\uc774 \ub300\uc785\ub429\ub2c8\ub2e4.<br>The value is assigned like this: <code>std::string str(9,13);<\/code>.<\/p>\n\n\n\n<p>&#8212; \uc2e4\uc81c\ub85c\ucd94\ucd9c\ub418\ub294 \ubb38\uc790\uc5f4\uc740 live\uc785\ub2c8\ub2e4.<br>The string actually extracted is &#8220;live&#8221;.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>case 0x03: { Amf0::parse_object(buf, pos); break; }<\/code><\/pre>\n\n\n\n<p>&#8212; null,undefinded\uc778 \uacbd\uc6b0 \uc785\ub2c8\ub2e4.<br>This applies to cases where the value is <code>null<\/code> or <code>undefined<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> case 0x05: case 0x06: pos += 1; break; <\/code><\/pre>\n\n\n\n<p>&#8212; ECMA array \ubd80\ubd84\uc73c\ub85c \ubc84\ud37c\uc5d0 \uac12\uc774 \uc5c6\uc2b5\ub2c8\ub2e4. \ucd94\ud6c4\uc5d0 \ucd94\uac00\ub420 \uae30\ub2a5\uc785\ub2c8\ub2e4.<br>There are no values \u200b\u200bin the buffer for the ECMA array section; this is a feature to be added later.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>while (pos + 2 &lt; buf.size()) {\n      uint16_t len = (buf&#91;pos] &lt;&lt; 8) | buf&#91;pos+1];\n      pos += 2;\n      if (len == 0 &amp;&amp; pos &lt; buf.size() &amp;&amp; buf&#91;pos] == 0x09) { pos++; break; }\n         pos += len;\n         skip_value(buf, pos);\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83d\udc49\ud83c\udffb \uc544\ub798\ub294 amf0.cpp \ud30c\uc77c\uc774 \ud568\uc218\uc5d0 \ub300\ud55c \uc124\uba85\uc785\ub2c8\ub2e4.Below is a description of the functions in the amf0.cpp file. \ud83d\udc49\ud83c\udffb \ucf54\ub4dc \uc124\uba85 \/ Code Explanation \u2714\ufe0f void Amf0::parse_object(const std::vector&amp; buf, size_t&amp; pos) { } &#8212; RTMP \ud328\ud0b7 \uc548\uc5d0 \ub4e4\uc5b4\uc788\ub294 AMF0 Object\ub97c \uc77d\uc5b4\uc11c \ubc84\ud37c \ud3ec\uc778\ud130\ub97c \ub2e4\uc74c \ud544\ub4dc\ub85c \uc62e\uae30\ub294 \uc6a9\ub3c4\uc785\ub2c8\ub2e4.It is used to read an AMF0 object contained within [&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-6184","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\/6184","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=6184"}],"version-history":[{"count":33,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6184\/revisions"}],"predecessor-version":[{"id":6217,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6184\/revisions\/6217"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=6184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=6184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=6184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}