diff --git a/trunk/src/rtmp/srs_protocol_amf0.cpp b/trunk/src/rtmp/srs_protocol_amf0.cpp index 7938af033..91289ce01 100644 --- a/trunk/src/rtmp/srs_protocol_amf0.cpp +++ b/trunk/src/rtmp/srs_protocol_amf0.cpp @@ -625,6 +625,68 @@ SrsAmf0Any* SrsAmf0EcmaArray::ensure_property_string(std::string name) return properties.ensure_property_string(name); } +int SrsAmf0Size::utf8(string value) +{ + return 2 + value.length(); +} + +int SrsAmf0Size::str(string value) +{ + return 1 + SrsAmf0Size::utf8(value); +} + +int SrsAmf0Size::number() +{ + return 1 + 8; +} + +int SrsAmf0Size::null() +{ + return 1; +} + +int SrsAmf0Size::undefined() +{ + return 1; +} + +int SrsAmf0Size::boolean() +{ + return 1 + 1; +} + +int SrsAmf0Size::object(SrsAmf0Object* obj) +{ + if (!obj) { + return 0; + } + + return obj->size(); +} + +int SrsAmf0Size::object_eof() +{ + return 2 + 1; +} + +int SrsAmf0Size::array(SrsAmf0EcmaArray* arr) +{ + if (!arr) { + return 0; + } + + return arr->size(); +} + +int SrsAmf0Size::any(SrsAmf0Any* o) +{ + if (!o) { + return 0; + } + + return o->size(); +} + int srs_amf0_read_utf8(SrsStream* stream, std::string& value) { int ret = ERROR_SUCCESS; @@ -1194,65 +1256,3 @@ int srs_amf0_write_ecma_array(SrsStream* stream, SrsAmf0EcmaArray* value) { return value->write(stream); } - -int SrsAmf0Size::utf8(string value) -{ - return 2 + value.length(); -} - -int SrsAmf0Size::str(string value) -{ - return 1 + SrsAmf0Size::utf8(value); -} - -int SrsAmf0Size::number() -{ - return 1 + 8; -} - -int SrsAmf0Size::null() -{ - return 1; -} - -int SrsAmf0Size::undefined() -{ - return 1; -} - -int SrsAmf0Size::boolean() -{ - return 1 + 1; -} - -int SrsAmf0Size::object(SrsAmf0Object* obj) -{ - if (!obj) { - return 0; - } - - return obj->size(); -} - -int SrsAmf0Size::object_eof() -{ - return 2 + 1; -} - -int SrsAmf0Size::array(SrsAmf0EcmaArray* arr) -{ - if (!arr) { - return 0; - } - - return arr->size(); -} - -int SrsAmf0Size::any(SrsAmf0Any* o) -{ - if (!o) { - return 0; - } - - return o->size(); -} diff --git a/trunk/src/rtmp/srs_protocol_amf0.hpp b/trunk/src/rtmp/srs_protocol_amf0.hpp index 93d098e30..368602194 100644 --- a/trunk/src/rtmp/srs_protocol_amf0.hpp +++ b/trunk/src/rtmp/srs_protocol_amf0.hpp @@ -34,7 +34,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include class SrsStream; -class SrsAmf0Object; /** * any amf0 value. @@ -44,8 +43,9 @@ class SrsAmf0Object; * | strict-array-type | date-type | long-string-type | xml-document-type * | typed-object-type */ -struct SrsAmf0Any +class SrsAmf0Any { +public: char marker; SrsAmf0Any(); @@ -69,8 +69,9 @@ struct SrsAmf0Any * string-type = string-marker UTF-8 * @return default value is empty string. */ -struct SrsAmf0String : public SrsAmf0Any +class SrsAmf0String : public SrsAmf0Any { +public: std::string value; SrsAmf0String(const char* _value = NULL); @@ -86,8 +87,9 @@ struct SrsAmf0String : public SrsAmf0Any * 0 is false, <> 0 is true * @return default value is false. */ -struct SrsAmf0Boolean : public SrsAmf0Any +class SrsAmf0Boolean : public SrsAmf0Any { +public: bool value; SrsAmf0Boolean(bool _value = false); @@ -102,8 +104,9 @@ struct SrsAmf0Boolean : public SrsAmf0Any * number-type = number-marker DOUBLE * @return default value is 0. */ -struct SrsAmf0Number : public SrsAmf0Any +class SrsAmf0Number : public SrsAmf0Any { +public: double value; SrsAmf0Number(double _value = 0.0); @@ -117,8 +120,9 @@ struct SrsAmf0Number : public SrsAmf0Any * 2.7 null Type * null-type = null-marker */ -struct SrsAmf0Null : public SrsAmf0Any +class SrsAmf0Null : public SrsAmf0Any { +public: SrsAmf0Null(); virtual ~SrsAmf0Null(); @@ -130,8 +134,9 @@ struct SrsAmf0Null : public SrsAmf0Any * 2.8 undefined Type * undefined-type = undefined-marker */ -struct SrsAmf0Undefined : public SrsAmf0Any +class SrsAmf0Undefined : public SrsAmf0Any { +public: SrsAmf0Undefined(); virtual ~SrsAmf0Undefined(); @@ -143,8 +148,9 @@ struct SrsAmf0Undefined : public SrsAmf0Any * object-end-type = UTF-8-empty object-end-marker * 0x00 0x00 0x09 */ -struct SrsAmf0ObjectEOF : public SrsAmf0Any +class SrsAmf0ObjectEOF : public SrsAmf0Any { +public: int16_t utf8_empty; SrsAmf0ObjectEOF(); @@ -159,7 +165,7 @@ struct SrsAmf0ObjectEOF : public SrsAmf0Any * if ordered in map, the string compare order, the FMLE will creash when * get the response of connect app. */ -struct SrsUnSortedHashtable +class SrsUnSortedHashtable { private: typedef std::pair SrsObjectPropertyType; @@ -184,7 +190,7 @@ public: * anonymous-object-type = object-marker *(object-property) * object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker) */ -struct SrsAmf0Object : public SrsAmf0Any +class SrsAmf0Object : public SrsAmf0Any { private: SrsUnSortedHashtable properties; @@ -213,7 +219,7 @@ public: * associative-count = U32 * object-property = (UTF-8 value-type) | (UTF-8-empty object-end-marker) */ -struct SrsAmf0EcmaArray : public SrsAmf0Any +class SrsAmf0EcmaArray : public SrsAmf0Any { private: SrsUnSortedHashtable properties; @@ -237,6 +243,24 @@ public: virtual SrsAmf0Any* ensure_property_string(std::string name); }; +/** +* the class to get amf0 object size +*/ +class SrsAmf0Size +{ +public: + static int utf8(std::string value); + static int str(std::string value); + static int number(); + static int null(); + static int undefined(); + static int boolean(); + static int object(SrsAmf0Object* obj); + static int object_eof(); + static int array(SrsAmf0EcmaArray* arr); + static int any(SrsAmf0Any* o); +}; + /** * read amf0 utf8 string from stream. * 1.3.1 Strings and UTF-8 @@ -310,24 +334,6 @@ extern int srs_amf0_write_object(SrsStream* stream, SrsAmf0Object* value); extern int srs_amf0_read_ecma_array(SrsStream* stream, SrsAmf0EcmaArray*& value); extern int srs_amf0_write_ecma_array(SrsStream* stream, SrsAmf0EcmaArray* value); -/** -* the class to get amf0 object size -*/ -class SrsAmf0Size -{ -public: - static int utf8(std::string value); - static int str(std::string value); - static int number(); - static int null(); - static int undefined(); - static int boolean(); - static int object(SrsAmf0Object* obj); - static int object_eof(); - static int array(SrsAmf0EcmaArray* arr); - static int any(SrsAmf0Any* o); -}; - /** * convert the any to specified object. * @return T*, the converted object. never NULL.