{"id":6147,"date":"2026-07-06T15:47:04","date_gmt":"2026-07-06T06:47:04","guid":{"rendered":"https:\/\/www.freelifemakers.org\/wordpress\/?p=6147"},"modified":"2026-07-06T16:45:52","modified_gmt":"2026-07-06T07:45:52","slug":"mediaserver-mini_mediaserver_1-code-description-process_complete_message1-7","status":"publish","type":"post","link":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/2026\/07\/06\/mediaserver-mini_mediaserver_1-code-description-process_complete_message1-7\/","title":{"rendered":"[Mediaserver]mini_Mediaserver_1-\ucf54\ub4dc\uc124\uba85\/code description-amf0.cpp(1-7)"},"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\ufe0f1. std::string Amf0::parse_string(const std::vector&amp; buf, size_t&amp; pos) { &#8230; }<\/p>\n\n\n\n<p>&#8212; \uc774 \ud568\uc218\ub294 \ubc84\ud37c\uc758 \ub370\uc774\ud130\ub97c \ubb38\uc790\uc5f4\ub85c \ubcc0\ud658\ud558\ub294 \ud568\uc218 \uc785\ub2c8\ub2e4.<br>This function converts data in a buffer into a string.<\/p>\n\n\n\n<p>&#8212; \ubc84\ud37c\uc5d0 \uc544\ub798\uc758 \uc608\uc2dc \ub370\uc774\ud130\uac00 \uc788\ub2e4\uace0 \uac00\uc815\ud569\ub2c8\ub2e4.<br>Assume the buffer contains the example data shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>buf = {0x02, 0x00, 0x05, 'h', 'e', 'l', 'l', 'o', 0x00}, pos = 0<\/code><\/pre>\n\n\n\n<p>&#8212; pos\uae30\ubcf8\uac12\uc774 0\ubcf4\ub2e4 \ud06c\uac70\ub098,\ubc84\ud37c0\ubc88 \ubc30\uc5f4 \uac12\uc774 0x02\uac00 \uc544\ub2c8\ub77c\uba74 \ub9ac\ud134(\ub85c\uc9c1 \uc911\ub2e8)\ud569\ub2c8\ub2e4.<br>Return (halt the logic) if the <code>pos<\/code> default value is greater than 0 or the value at index 0 of the buffer array is not <code>0x02<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    if (pos &gt;= buf.size() || buf&#91;pos]!= 0x02) return \"\";\n    \/\/ buf&#91;0] -&gt; buf&#91;1],\ud3ec\uc778\ud130 \uc774\ub3d9\n    pos++;<\/code><\/pre>\n\n\n\n<p>&#8212; pos+1 = 2 &lt; buf.size(9)\uba74 \ud1b5\uacfc\ud569\ub2c8\ub2e4.<br>Return (halt the logic) if the <code>pos<\/code> default value is greater than 0 or the value at index 0 of the buffer array is not <code>0x02<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (pos + 1 &gt;= buf.size()) return \"\";<\/code><\/pre>\n\n\n\n<p>&#8212; buf[pos]\ub97c \uc0c1\uc704\ubc14\uc774\ud2b8\ub85c \uc774\ub3d9(8)\ud558\uace0 \ub4a4\uc5d0 00 \ubd99\uc785\ub2c8\ub2e4.(\uc608:0xAB -> 0xAB00)<br>Shift <code>buf[pos]<\/code> to the upper byte (by 8 bits) and append <code>00<\/code> (e.g., <code>0xAB<\/code> -> <code>0xAB00<\/code>).<\/p>\n\n\n\n<p>&#8212; len = 0x00 &lt;&lt; 8 | 0x05 = 5, pos+=2 \u2192 pos=3<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>uint16_t len = (buf&#91;pos] &lt;&lt; 8) | buf&#91;pos+1];<\/code><\/pre>\n\n\n\n<p>&#8212; 3 + len(5)\uc774 \ubc84\ud37c\uc0ac\uc774\uc988\ubcf4\ub2e4 \ud06c\uba74 \ub9ac\ud134(\ub85c\uc9c1\uc911\ub2e8)<br>If 3 + len(5) is greater than the buffer size, return (terminate logic).<\/p>\n\n\n\n<p>&#8212; pos(3)+len(5) = 8 &lt;= 9 \uc774\uba74 \ud1b5\uacfc\ud569\ub2c8\ub2e4.<br>It passes if pos(3) + len(5) = 8 &lt;= 9.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ pos = 3\npos += 2;\nif (pos + len &gt; buf.size()) return \"\";<\/code><\/pre>\n\n\n\n<p>&#8212; \uc2e4\uc81c \ubb38\uc790\uc5f4\ub85c \ubcc0\ud658\ud574\uc11c \ub9ac\ud134\ud569\ub2c8\ub2e4.<br>Converts it to an actual string and returns it.<\/p>\n\n\n\n<p>&#8212; buf[3]~buf[7] = &#8220;hello&#8221; \uc798\ub77c\uc11c \ub9ac\ud134\ud558\uace0, pos=8\ub85c \uc5c5\ub370\uc774\ud2b8\ud569\ub2c8\ub2e4.<br>Extract and return &#8220;hello&#8221; from buf[3] to buf[7], and update pos to 8.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    std::string str(buf.begin() + pos, buf.begin() + pos + len);\n    pos += len;\n    return str;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2714\ufe0f RTMP\uc5d0\uc11c null \uac12\uc744 \uc77d\uace0 pos\ub9cc \ud55c \uce78 \ub118\uaca8\uc8fc\ub294 \uc5ed\ud560.(0x05\uc5d0\uc11c \ub2e4\uc74c\uce78\uc73c\ub85cpos \uc774\ub3d9)<br>It reads a null value from the RTMP stream and advances the <code>pos<\/code> by one position (moving <code>pos<\/code> from 0x05 to the next position).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>void Amf0::parse_null(const std::vector&lt;uint8_t&gt;&amp; buf, size_t&amp; pos) {\n    if (pos &lt; buf.size() &amp;&amp; buf&#91;pos]==0x05) pos++;\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u2714\ufe0f 2.double Amf0::parse_number(const std::vector&amp; buf, size_t&amp; pos) {&#8230;}<\/p>\n\n\n\n<p>&#8212; \uc774 \ud568\uc218\ub294 \ubc84\ud37c\uc758 \ub370\uc774\ud130\ub97c \uc22b\uc790\ub85c \ubcc0\ud658\ud558\ub294 \ud568\uc218 \uc785\ub2c8\ub2e4.<br>This function converts data in the buffer into a number.<\/p>\n\n\n\n<p>&#8212; \ubc84\ud37c\uc5d0 \uc544\ub798\uc758 \uc608\uc2dc \ub370\uc774\ud130\uac00 \uc788\ub2e4\uace0 \uac00\uc815\ud569\ub2c8\ub2e4.<br>Assume the buffer contains the example data shown below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>buf = { 0x00, 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }\n  \ub9c8\ucee4\/Marker | ------------- 8\ubc14\uc774\ud2b8\/byte double ------------- |\npos = 0<\/code><\/pre>\n\n\n\n<p>&#8212; RTMP\uc5d0\uc11c \uc22b\uc790\u00a0<code>1.0<\/code>\uc744 \ubcf4\ub0b4\uba74 AMF0\ub85c \uc774\ub807\uac8c \uc778\ucf54\ub529 \ub429\ub2c8\ub2e4.<br>When sending the number 1.0 in RTMP, it is encoded in AMF0 like this.<\/p>\n\n\n\n<p>&#8212; 0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 \uc740 IEEE754\uc5d0\uc11c 1.0\uc744 \uc758\ubbf8\ud569\ub2c8\ub2e4.<br>0x3F, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 represents 1.0 in IEEE 754.<\/p>\n\n\n\n<p>&#8212; IEEE754\ub294 \ucef4\ud4e8\ud130\uac00 \uc2e4\uc218\ub97c \uba54\ubaa8\ub9ac\uc5d0 \uc800\uc7a5\ud558\ub294 \uad6d\uc81c \ud45c\uc900 \uaddc\uce59\uc785\ub2c8\ub2e4.<br>IEEE 754 is an international standard for how computers store real numbers in memory.<\/p>\n\n\n\n<p>&#8212; number \ub9c8\ucee4\uc778\uc9c0 \ud655\uc778\ud558\uae30<br>Check if it is a number marker.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    if (pos &gt;= buf.size() || buf&#91;pos]!= 0x00) return 0;\n    pos++; \/\/ 1\n    uint64_t val = 0;<\/code><\/pre>\n\n\n\n<p>&#8212; val\uc744 \uc0c1\uc704 \ube44\ud2b8\ub85c 8\ube44\ud2b8\uc774\ub3d9\ud558\uace0 \ub4a4\uc5d0 00\ubd99\uc785\ub2c8\ub2e4.<br>Shift <code>val<\/code> 8 bits to the left (to the upper bits) and append <code>00<\/code> at the end.<\/p>\n\n\n\n<p>&#8212; 8\ubc88 \ubc18\ubcf5\ubb38\uc744 \uc2e4\ud589\ud558\uba74 buf[1]~buf[8]\uae4c\uc9c0 \ucd1d 8\ubc14\uc774\ud2b8\uac00 \uc870\ub9bd\ub429\ub2c8\ub2e4.(\ube45\uc5d4\ub514\uc5b8 \uacfc\uc815)<br>Executing the loop eight times assembles a total of 8 bytes, from buf[1] to buf[8] (big-endian process).<\/p>\n\n\n\n<p>&#8212; \uc2e4\uc81c\ub85c \uc9c4\ud589\ub418\ub294 \uacfc\uc815\uc740 \uc544\ub798\uc758 \ud45c\uc640 \uac19\uc2b5\ub2c8\ub2e4.<br>The actual process is as shown in the table below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> for (int i = 0; i &lt; 8; i++) val = (val &lt;&lt; 8) | buf&#91;pos++];<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>i<\/th><th>pos<\/th><th>buf<\/th><th>val &lt;&lt; 8<\/th><th>OR \ud6c4 val \/ <br>Value after OR<\/th><\/tr><\/thead><tbody><tr><td>0<\/td><td>1<\/td><td>0x3F<\/td><td>0x00<\/td><td><strong>0x000000000000003F<\/strong><\/td><\/tr><tr><td>1<\/td><td>2<\/td><td>0xF0<\/td><td>0x0000000000003F00<\/td><td>0x0000000000003FF0<\/td><\/tr><tr><td>2<\/td><td>3<\/td><td>0x00<\/td><td>0x00000000003FF000<\/td><td>0x00000000003FF000<\/td><\/tr><tr><td>3<\/td><td>4<\/td><td>0x00<\/td><td>0x000000003FF00000<\/td><td>0x000000003FF00000<\/td><\/tr><tr><td>4<\/td><td>5<\/td><td>0x00<\/td><td>0x0000003FF0000000<\/td><td>0x0000003FF0000000<\/td><\/tr><tr><td>5<\/td><td>6<\/td><td>0x00<\/td><td>0x00003FF000000000<\/td><td>0x00003FF000000000<\/td><\/tr><tr><td>6<\/td><td>7<\/td><td>0x00<\/td><td>0x003FF00000000000<\/td><td>0x003FF00000000000<\/td><\/tr><tr><td>7<\/td><td>8<\/td><td>0x00<\/td><td>0x3FF0000000000000<\/td><td><strong>0x3FF0000000000000<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>&#8212; double\ud615\uc73c\ub85c \ud615\ubcc0\ud658\ud574\uc11c \ub9ac\ud134\ud569\ub2c8\ub2e4.<br>It casts the value to a double and returns it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>return *reinterpret_cast&lt;double*&gt;(&amp;val);<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>&nbsp;\u2b50\ufe0fIEEE754 double<\/p>\n\n\n\n<p>\u2714\ufe0f <strong><code>0x3F<\/code><\/strong> : <code>0011 1111<\/code> (2\uc9c4\uc218\/Binary number)<\/p>\n\n\n\n<p>\u2714\ufe0f <strong><code>0xF0<\/code><\/strong> : <code>1111 0000<\/code> (2\uc9c4\uc218\/Binary number)<\/p>\n\n\n\n<p>\u2714\ufe0f 64\ube44\ud2b8 \uc2e4\uc218\ub294 \uc774\ub807\uac8c \uc0ac\uc6a9\ud558\uc790\ub77c\uace0 \uc57d\uc18d\ub41c\uac83\uc785\ub2c8\ub2e4.<br>This is the agreed-upon way to use 64-bit floating-point numbers.<\/p>\n\n\n\n<p>\u2714\ufe0f \uad6c\uc870 : \uad6c\uc870: \ubd80\ud638 + \uc9c0\uc218 + \uac00\uc218<br>Structure: Sign + Exponent + Mantissa<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   63bit                62~52bit           51~0bit\n&#91;\ubd80\ud6381\ube44\ud2b8]             &#91;\uc9c0\uc218\ubd80 11\ube44\ud2b8]       &#91;\uac00\uc218\ubd80 52\ube44\ud2b8]\n&#91;Sign bit: 1 bit] &#91;Exponent: 11 bits] &#91;Mantissa: 52 bits]\n  S            E             M\n\uac12\/Value = (-1)^S * 1.M * 2^(E-1023)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;0x3F]    &#91;0xF0]\n00111111  11110000 ... (\uc774\ud6c4 00\uc740 \ubaa8\ub450 0 \/ After that, all 00s are 0)\n\u2502\u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2518\u2514\u2500\u252c\u2500\u2518\n\u2502     \u2502        \u2514\u2500 \uac00\uc218\ubd80(M)\uc758 \uc2dc\uc791\uc810 (\ubaa8\ub450 0) \/ Starting point of the vocal section (M) (all zeros)\n\u2502     \u2514\u2500 \uc9c0\uc218\ubd80(E): 11\ube44\ud2b8 \/ Exponent part (E): 11 bits\n\u2514\u2500 \ubd80\ud638(S): 1\ube44\ud2b8 (0 = \uc591\uc218) \/ Sign (S): 1 bit (0 = positive)\n<\/code><\/pre>\n\n\n\n<p>&#8212; <code>1.0 = (-1)^0 * 1.0 * 2^0<\/code>&nbsp;<br>&#8212; S=0, E-1023=0 \u2192 E=1023 =&nbsp;<code>0x3FF<\/code>, M=0<\/p>\n\n\n\n<p>&#8212; \uc9c0\uc218 \ubd80\ubd84\uc740 11\ube44\ud2b8 \u2192 \u00a0<code>2^11 = 2048<\/code>\uac1c \ud45c\ud604 \uac00\ub2a5\ud569\ub2c8\ub2e4.<br>The exponent part consists of 11 bits, allowing for 2^11 (2,048) possible values.<\/p>\n\n\n\n<p>&#8212; 52\ube44\ud2b8 \uac00\uc218 \u2192 \uc815\ubc00\ub3c4 15\u223c17\uc790\ub9ac \uc2ed\uc9c4\uc218\uc785\ub2c8\ub2e4.<br>A 52-bit significand corresponds to a precision of 15 to 17 decimal digits.<\/p>\n\n\n\n<p>&#8212; S\uac12\uc740 0\uc774\uba74 \uc591\uc218 -1\uc774\uba74 \uc74c\uc218\uc785\ub2c8\ub2e4.<br>An S-value of 0 indicates a positive number, while -1 indicates a negative number.<\/p>\n\n\n\n<p>&#8212; E\uac12\uc740 1023\uc774 \uae30\ubcf8 \ud560\ub2f9\ub418\uc5b4 \uc788\uc2b5\ub2c8\ub2e4.(\uc0c1\uc218) \uc774\uac83\uc744 bias\ub77c\uace0 \ud569\ub2c8\ub2e4.<br>The E-value is assigned a default value of 1023 (a constant); this is referred to as the bias.<\/p>\n\n\n\n<p>&#8212; \ucc98\uc74c\uc5d0 \uc800\uc7a5\ud560\ub584 1023\uc744 \uc800\uc7a5\ud558\uace0 \ub098\uc911\uc5d0 \uac12\uc774 \uc124\uc815\ub420\ub54c \uc774 \uac12\uc744 \ube7c\uc90d\ub2c8\ub2e4.<br>Initially, you store 1023, and later, when the value is set, you subtract this value.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bias = 2^(11-1) - 1 = 1023<\/code><\/pre>\n\n\n\n<p>&#8212; \ubc11\uc774 2\uc778 \uac70\ub4ed\uc81c\uacf1 \uc5f0\uc0b0 \ubd80\ubd84\uc774 \\(2^{0}\\)\uc774 \ub418\uba70, \ubaa8\ub4e0 \uc218\uc758 0\uc81c\uacf1\uc740 <code>1<\/code>\uc774\ub429\ub2c8\ub2e4. \uc989<br>The part involving the power of 2 becomes (2^{0}), and any number raised to the power of 0 equals 1. In other words,<\/p>\n\n\n\n<p><strong>\uc9c0\uc218\ubd80<\/strong>\/Index Section :  2^{1023 &#8211; 1023} = 2^0 = 1<\/p>\n\n\n\n<p>\ucd5c\uc885\uac12 \/ Final value = 1 \u2715 1.0 \u2715 1 = 1.0<\/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\ufe0f1. std::string Amf0::parse_string(const std::vector&amp; buf, size_t&amp; pos) { &#8230; } &#8212; \uc774 \ud568\uc218\ub294 \ubc84\ud37c\uc758 \ub370\uc774\ud130\ub97c \ubb38\uc790\uc5f4\ub85c \ubcc0\ud658\ud558\ub294 \ud568\uc218 \uc785\ub2c8\ub2e4.This function converts data in a buffer into a string. &#8212; \ubc84\ud37c\uc5d0 \uc544\ub798\uc758 \uc608\uc2dc [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6147","post","type-post","status-publish","format-standard","hentry","category-uncategorized","missing-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6147","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=6147"}],"version-history":[{"count":36,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6147\/revisions"}],"predecessor-version":[{"id":6183,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/6147\/revisions\/6183"}],"wp:attachment":[{"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=6147"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=6147"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.freelifemakers.org\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=6147"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}