winlin

refine amf0, rename internal classes

... ... @@ -116,28 +116,28 @@ bool SrsAmf0Any::is_complex_object()
string SrsAmf0Any::to_str()
{
__SrsAmf0String* p = dynamic_cast<__SrsAmf0String*>(this);
SrsAmf0String* p = dynamic_cast<SrsAmf0String*>(this);
srs_assert(p != NULL);
return p->value;
}
const char* SrsAmf0Any::to_str_raw()
{
__SrsAmf0String* p = dynamic_cast<__SrsAmf0String*>(this);
SrsAmf0String* p = dynamic_cast<SrsAmf0String*>(this);
srs_assert(p != NULL);
return p->value.data();
}
bool SrsAmf0Any::to_boolean()
{
__SrsAmf0Boolean* p = dynamic_cast<__SrsAmf0Boolean*>(this);
SrsAmf0Boolean* p = dynamic_cast<SrsAmf0Boolean*>(this);
srs_assert(p != NULL);
return p->value;
}
double SrsAmf0Any::to_number()
{
__SrsAmf0Number* p = dynamic_cast<__SrsAmf0Number*>(this);
SrsAmf0Number* p = dynamic_cast<SrsAmf0Number*>(this);
srs_assert(p != NULL);
return p->value;
}
... ... @@ -165,7 +165,7 @@ SrsAmf0StrictArray* SrsAmf0Any::to_strict_array()
void SrsAmf0Any::set_number(double value)
{
__SrsAmf0Number* p = dynamic_cast<__SrsAmf0Number*>(this);
SrsAmf0Number* p = dynamic_cast<SrsAmf0Number*>(this);
srs_assert(p != NULL);
p->value = value;
}
... ... @@ -261,27 +261,27 @@ char* SrsAmf0Any::human_print(char** pdata, int* psize)
SrsAmf0Any* SrsAmf0Any::str(const char* value)
{
return new __SrsAmf0String(value);
return new SrsAmf0String(value);
}
SrsAmf0Any* SrsAmf0Any::boolean(bool value)
{
return new __SrsAmf0Boolean(value);
return new SrsAmf0Boolean(value);
}
SrsAmf0Any* SrsAmf0Any::number(double value)
{
return new __SrsAmf0Number(value);
return new SrsAmf0Number(value);
}
SrsAmf0Any* SrsAmf0Any::null()
{
return new __SrsAmf0Null();
return new SrsAmf0Null();
}
SrsAmf0Any* SrsAmf0Any::undefined()
{
return new __SrsAmf0Undefined();
return new SrsAmf0Undefined();
}
SrsAmf0Object* SrsAmf0Any::object()
... ... @@ -291,7 +291,7 @@ SrsAmf0Object* SrsAmf0Any::object()
SrsAmf0Any* SrsAmf0Any::object_eof()
{
return new __SrsAmf0ObjectEOF();
return new SrsAmf0ObjectEOF();
}
SrsAmf0EcmaArray* SrsAmf0Any::ecma_array()
... ... @@ -310,7 +310,7 @@ int SrsAmf0Any::discovery(SrsStream* stream, SrsAmf0Any** ppvalue)
// detect the object-eof specially
if (srs_amf0_is_object_eof(stream)) {
*ppvalue = new __SrsAmf0ObjectEOF();
*ppvalue = new SrsAmf0ObjectEOF();
return ret;
}
... ... @@ -371,21 +371,21 @@ int SrsAmf0Any::discovery(SrsStream* stream, SrsAmf0Any** ppvalue)
return ret;
}
__SrsUnSortedHashtable::__SrsUnSortedHashtable()
SrsUnSortedHashtable::SrsUnSortedHashtable()
{
}
__SrsUnSortedHashtable::~__SrsUnSortedHashtable()
SrsUnSortedHashtable::~SrsUnSortedHashtable()
{
clear();
}
int __SrsUnSortedHashtable::count()
int SrsUnSortedHashtable::count()
{
return (int)properties.size();
}
void __SrsUnSortedHashtable::clear()
void SrsUnSortedHashtable::clear()
{
std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = properties.begin(); it != properties.end(); ++it) {
... ... @@ -396,28 +396,28 @@ void __SrsUnSortedHashtable::clear()
properties.clear();
}
string __SrsUnSortedHashtable::key_at(int index)
string SrsUnSortedHashtable::key_at(int index)
{
srs_assert(index < count());
SrsAmf0ObjectPropertyType& elem = properties[index];
return elem.first;
}
const char* __SrsUnSortedHashtable::key_raw_at(int index)
const char* SrsUnSortedHashtable::key_raw_at(int index)
{
srs_assert(index < count());
SrsAmf0ObjectPropertyType& elem = properties[index];
return elem.first.data();
}
SrsAmf0Any* __SrsUnSortedHashtable::value_at(int index)
SrsAmf0Any* SrsUnSortedHashtable::value_at(int index)
{
srs_assert(index < count());
SrsAmf0ObjectPropertyType& elem = properties[index];
return elem.second;
}
void __SrsUnSortedHashtable::set(string key, SrsAmf0Any* value)
void SrsUnSortedHashtable::set(string key, SrsAmf0Any* value)
{
if (!value) {
srs_warn("add a NULL propertity %s", key.c_str());
... ... @@ -441,7 +441,7 @@ void __SrsUnSortedHashtable::set(string key, SrsAmf0Any* value)
properties.push_back(std::make_pair(key, value));
}
SrsAmf0Any* __SrsUnSortedHashtable::get_property(string name)
SrsAmf0Any* SrsUnSortedHashtable::get_property(string name)
{
std::vector<SrsAmf0ObjectPropertyType>::iterator it;
... ... @@ -457,7 +457,7 @@ SrsAmf0Any* __SrsUnSortedHashtable::get_property(string name)
return NULL;
}
SrsAmf0Any* __SrsUnSortedHashtable::ensure_property_string(string name)
SrsAmf0Any* SrsUnSortedHashtable::ensure_property_string(string name)
{
SrsAmf0Any* prop = get_property(name);
... ... @@ -472,7 +472,7 @@ SrsAmf0Any* __SrsUnSortedHashtable::ensure_property_string(string name)
return prop;
}
SrsAmf0Any* __SrsUnSortedHashtable::ensure_property_number(string name)
SrsAmf0Any* SrsUnSortedHashtable::ensure_property_number(string name)
{
SrsAmf0Any* prop = get_property(name);
... ... @@ -487,7 +487,7 @@ SrsAmf0Any* __SrsUnSortedHashtable::ensure_property_number(string name)
return prop;
}
void __SrsUnSortedHashtable::copy(__SrsUnSortedHashtable* src)
void SrsUnSortedHashtable::copy(SrsUnSortedHashtable* src)
{
std::vector<SrsAmf0ObjectPropertyType>::iterator it;
for (it = src->properties.begin(); it != src->properties.end(); ++it) {
... ... @@ -498,22 +498,22 @@ void __SrsUnSortedHashtable::copy(__SrsUnSortedHashtable* src)
}
}
__SrsAmf0ObjectEOF::__SrsAmf0ObjectEOF()
SrsAmf0ObjectEOF::SrsAmf0ObjectEOF()
{
marker = RTMP_AMF0_ObjectEnd;
utf8_empty = 0x00;
}
__SrsAmf0ObjectEOF::~__SrsAmf0ObjectEOF()
SrsAmf0ObjectEOF::~SrsAmf0ObjectEOF()
{
}
int __SrsAmf0ObjectEOF::total_size()
int SrsAmf0ObjectEOF::total_size()
{
return SrsAmf0Size::object_eof();
}
int __SrsAmf0ObjectEOF::read(SrsStream* stream)
int SrsAmf0ObjectEOF::read(SrsStream* stream)
{
int ret = ERROR_SUCCESS;
... ... @@ -551,7 +551,7 @@ int __SrsAmf0ObjectEOF::read(SrsStream* stream)
return ret;
}
int __SrsAmf0ObjectEOF::write(SrsStream* stream)
int SrsAmf0ObjectEOF::write(SrsStream* stream)
{
int ret = ERROR_SUCCESS;
... ... @@ -578,15 +578,15 @@ int __SrsAmf0ObjectEOF::write(SrsStream* stream)
return ret;
}
SrsAmf0Any* __SrsAmf0ObjectEOF::copy()
SrsAmf0Any* SrsAmf0ObjectEOF::copy()
{
return new __SrsAmf0ObjectEOF();
return new SrsAmf0ObjectEOF();
}
SrsAmf0Object::SrsAmf0Object()
{
properties = new __SrsUnSortedHashtable();
eof = new __SrsAmf0ObjectEOF();
properties = new SrsUnSortedHashtable();
eof = new SrsAmf0ObjectEOF();
marker = RTMP_AMF0_Object;
}
... ... @@ -637,7 +637,7 @@ int SrsAmf0Object::read(SrsStream* stream)
while (!stream->empty()) {
// detect whether is eof.
if (srs_amf0_is_object_eof(stream)) {
__SrsAmf0ObjectEOF pbj_eof;
SrsAmf0ObjectEOF pbj_eof;
if ((ret = pbj_eof.read(stream)) != ERROR_SUCCESS) {
srs_error("amf0 object read eof failed. ret=%d", ret);
return ret;
... ... @@ -765,8 +765,8 @@ SrsAmf0Any* SrsAmf0Object::ensure_property_number(string name)
SrsAmf0EcmaArray::SrsAmf0EcmaArray()
{
_count = 0;
properties = new __SrsUnSortedHashtable();
eof = new __SrsAmf0ObjectEOF();
properties = new SrsUnSortedHashtable();
eof = new SrsAmf0ObjectEOF();
marker = RTMP_AMF0_EcmaArray;
}
... ... @@ -829,7 +829,7 @@ int SrsAmf0EcmaArray::read(SrsStream* stream)
while (!stream->empty()) {
// detect whether is eof.
if (srs_amf0_is_object_eof(stream)) {
__SrsAmf0ObjectEOF pbj_eof;
SrsAmf0ObjectEOF pbj_eof;
if ((ret = pbj_eof.read(stream)) != ERROR_SUCCESS) {
srs_error("amf0 ecma_array read eof failed. ret=%d", ret);
return ret;
... ... @@ -1186,7 +1186,7 @@ int SrsAmf0Size::any(SrsAmf0Any* o)
return o->total_size();
}
__SrsAmf0String::__SrsAmf0String(const char* _value)
SrsAmf0String::SrsAmf0String(const char* _value)
{
marker = RTMP_AMF0_String;
if (_value) {
... ... @@ -1194,150 +1194,150 @@ __SrsAmf0String::__SrsAmf0String(const char* _value)
}
}
__SrsAmf0String::~__SrsAmf0String()
SrsAmf0String::~SrsAmf0String()
{
}
int __SrsAmf0String::total_size()
int SrsAmf0String::total_size()
{
return SrsAmf0Size::str(value);
}
int __SrsAmf0String::read(SrsStream* stream)
int SrsAmf0String::read(SrsStream* stream)
{
return srs_amf0_read_string(stream, value);
}
int __SrsAmf0String::write(SrsStream* stream)
int SrsAmf0String::write(SrsStream* stream)
{
return srs_amf0_write_string(stream, value);
}
SrsAmf0Any* __SrsAmf0String::copy()
SrsAmf0Any* SrsAmf0String::copy()
{
__SrsAmf0String* copy = new __SrsAmf0String(value.c_str());
SrsAmf0String* copy = new SrsAmf0String(value.c_str());
return copy;
}
__SrsAmf0Boolean::__SrsAmf0Boolean(bool _value)
SrsAmf0Boolean::SrsAmf0Boolean(bool _value)
{
marker = RTMP_AMF0_Boolean;
value = _value;
}
__SrsAmf0Boolean::~__SrsAmf0Boolean()
SrsAmf0Boolean::~SrsAmf0Boolean()
{
}
int __SrsAmf0Boolean::total_size()
int SrsAmf0Boolean::total_size()
{
return SrsAmf0Size::boolean();
}
int __SrsAmf0Boolean::read(SrsStream* stream)
int SrsAmf0Boolean::read(SrsStream* stream)
{
return srs_amf0_read_boolean(stream, value);
}
int __SrsAmf0Boolean::write(SrsStream* stream)
int SrsAmf0Boolean::write(SrsStream* stream)
{
return srs_amf0_write_boolean(stream, value);
}
SrsAmf0Any* __SrsAmf0Boolean::copy()
SrsAmf0Any* SrsAmf0Boolean::copy()
{
__SrsAmf0Boolean* copy = new __SrsAmf0Boolean(value);
SrsAmf0Boolean* copy = new SrsAmf0Boolean(value);
return copy;
}
__SrsAmf0Number::__SrsAmf0Number(double _value)
SrsAmf0Number::SrsAmf0Number(double _value)
{
marker = RTMP_AMF0_Number;
value = _value;
}
__SrsAmf0Number::~__SrsAmf0Number()
SrsAmf0Number::~SrsAmf0Number()
{
}
int __SrsAmf0Number::total_size()
int SrsAmf0Number::total_size()
{
return SrsAmf0Size::number();
}
int __SrsAmf0Number::read(SrsStream* stream)
int SrsAmf0Number::read(SrsStream* stream)
{
return srs_amf0_read_number(stream, value);
}
int __SrsAmf0Number::write(SrsStream* stream)
int SrsAmf0Number::write(SrsStream* stream)
{
return srs_amf0_write_number(stream, value);
}
SrsAmf0Any* __SrsAmf0Number::copy()
SrsAmf0Any* SrsAmf0Number::copy()
{
__SrsAmf0Number* copy = new __SrsAmf0Number(value);
SrsAmf0Number* copy = new SrsAmf0Number(value);
return copy;
}
__SrsAmf0Null::__SrsAmf0Null()
SrsAmf0Null::SrsAmf0Null()
{
marker = RTMP_AMF0_Null;
}
__SrsAmf0Null::~__SrsAmf0Null()
SrsAmf0Null::~SrsAmf0Null()
{
}
int __SrsAmf0Null::total_size()
int SrsAmf0Null::total_size()
{
return SrsAmf0Size::null();
}
int __SrsAmf0Null::read(SrsStream* stream)
int SrsAmf0Null::read(SrsStream* stream)
{
return srs_amf0_read_null(stream);
}
int __SrsAmf0Null::write(SrsStream* stream)
int SrsAmf0Null::write(SrsStream* stream)
{
return srs_amf0_write_null(stream);
}
SrsAmf0Any* __SrsAmf0Null::copy()
SrsAmf0Any* SrsAmf0Null::copy()
{
__SrsAmf0Null* copy = new __SrsAmf0Null();
SrsAmf0Null* copy = new SrsAmf0Null();
return copy;
}
__SrsAmf0Undefined::__SrsAmf0Undefined()
SrsAmf0Undefined::SrsAmf0Undefined()
{
marker = RTMP_AMF0_Undefined;
}
__SrsAmf0Undefined::~__SrsAmf0Undefined()
SrsAmf0Undefined::~SrsAmf0Undefined()
{
}
int __SrsAmf0Undefined::total_size()
int SrsAmf0Undefined::total_size()
{
return SrsAmf0Size::undefined();
}
int __SrsAmf0Undefined::read(SrsStream* stream)
int SrsAmf0Undefined::read(SrsStream* stream)
{
return srs_amf0_read_undefined(stream);
}
int __SrsAmf0Undefined::write(SrsStream* stream)
int SrsAmf0Undefined::write(SrsStream* stream)
{
return srs_amf0_write_undefined(stream);
}
SrsAmf0Any* __SrsAmf0Undefined::copy()
SrsAmf0Any* SrsAmf0Undefined::copy()
{
__SrsAmf0Undefined* copy = new __SrsAmf0Undefined();
SrsAmf0Undefined* copy = new SrsAmf0Undefined();
return copy;
}
... ... @@ -1703,7 +1703,7 @@ namespace _srs_internal
return false;
}
int srs_amf0_write_object_eof(SrsStream* stream, __SrsAmf0ObjectEOF* value)
int srs_amf0_write_object_eof(SrsStream* stream, SrsAmf0ObjectEOF* value)
{
int ret = ERROR_SUCCESS;
... ...
... ... @@ -41,8 +41,8 @@ class SrsAmf0StrictArray;
// internal objects, user should never use it.
namespace _srs_internal
{
class __SrsUnSortedHashtable;
class __SrsAmf0ObjectEOF;
class SrsUnSortedHashtable;
class SrsAmf0ObjectEOF;
}
/*
... ... @@ -317,8 +317,8 @@ public:
class SrsAmf0Object : public SrsAmf0Any
{
private:
_srs_internal::__SrsUnSortedHashtable* properties;
_srs_internal::__SrsAmf0ObjectEOF* eof;
_srs_internal::SrsUnSortedHashtable* properties;
_srs_internal::SrsAmf0ObjectEOF* eof;
private:
friend class SrsAmf0Any;
/**
... ... @@ -399,8 +399,8 @@ public:
class SrsAmf0EcmaArray : public SrsAmf0Any
{
private:
_srs_internal::__SrsUnSortedHashtable* properties;
_srs_internal::__SrsAmf0ObjectEOF* eof;
_srs_internal::SrsUnSortedHashtable* properties;
_srs_internal::SrsAmf0ObjectEOF* eof;
int32_t _count;
private:
friend class SrsAmf0Any;
... ... @@ -600,13 +600,19 @@ namespace _srs_internal
* @return default value is empty string.
* @remark: use SrsAmf0Any::str() to create it.
*/
class __SrsAmf0String : public SrsAmf0Any
class SrsAmf0String : public SrsAmf0Any
{
public:
std::string value;
private:
friend class SrsAmf0Any;
/**
* make amf0 string to private,
* use should never declare it, use SrsAmf0Any::str() to create it.
*/
SrsAmf0String(const char* _value);
public:
__SrsAmf0String(const char* _value);
virtual ~__SrsAmf0String();
virtual ~SrsAmf0String();
public:
virtual int total_size();
virtual int read(SrsStream* stream);
... ... @@ -621,13 +627,19 @@ namespace _srs_internal
* 0 is false, <> 0 is true
* @return default value is false.
*/
class __SrsAmf0Boolean : public SrsAmf0Any
class SrsAmf0Boolean : public SrsAmf0Any
{
public:
bool value;
private:
friend class SrsAmf0Any;
/**
* make amf0 boolean to private,
* use should never declare it, use SrsAmf0Any::boolean() to create it.
*/
SrsAmf0Boolean(bool _value);
public:
__SrsAmf0Boolean(bool _value);
virtual ~__SrsAmf0Boolean();
virtual ~SrsAmf0Boolean();
public:
virtual int total_size();
virtual int read(SrsStream* stream);
... ... @@ -641,13 +653,19 @@ namespace _srs_internal
* number-type = number-marker DOUBLE
* @return default value is 0.
*/
class __SrsAmf0Number : public SrsAmf0Any
class SrsAmf0Number : public SrsAmf0Any
{
public:
double value;
private:
friend class SrsAmf0Any;
/**
* make amf0 number to private,
* use should never declare it, use SrsAmf0Any::number() to create it.
*/
SrsAmf0Number(double _value);
public:
__SrsAmf0Number(double _value);
virtual ~__SrsAmf0Number();
virtual ~SrsAmf0Number();
public:
virtual int total_size();
virtual int read(SrsStream* stream);
... ... @@ -660,11 +678,17 @@ namespace _srs_internal
* 2.7 null Type
* null-type = null-marker
*/
class __SrsAmf0Null : public SrsAmf0Any
class SrsAmf0Null : public SrsAmf0Any
{
private:
friend class SrsAmf0Any;
/**
* make amf0 null to private,
* use should never declare it, use SrsAmf0Any::null() to create it.
*/
SrsAmf0Null();
public:
__SrsAmf0Null();
virtual ~__SrsAmf0Null();
virtual ~SrsAmf0Null();
public:
virtual int total_size();
virtual int read(SrsStream* stream);
... ... @@ -677,11 +701,17 @@ namespace _srs_internal
* 2.8 undefined Type
* undefined-type = undefined-marker
*/
class __SrsAmf0Undefined : public SrsAmf0Any
class SrsAmf0Undefined : public SrsAmf0Any
{
private:
friend class SrsAmf0Any;
/**
* make amf0 undefined to private,
* use should never declare it, use SrsAmf0Any::undefined() to create it.
*/
SrsAmf0Undefined();
public:
__SrsAmf0Undefined();
virtual ~__SrsAmf0Undefined();
virtual ~SrsAmf0Undefined();
public:
virtual int total_size();
virtual int read(SrsStream* stream);
... ... @@ -695,14 +725,14 @@ namespace _srs_internal
* if ordered in map, the string compare order, the FMLE will creash when
* get the response of connect app.
*/
class __SrsUnSortedHashtable
class SrsUnSortedHashtable
{
private:
typedef std::pair<std::string, SrsAmf0Any*> SrsAmf0ObjectPropertyType;
std::vector<SrsAmf0ObjectPropertyType> properties;
public:
__SrsUnSortedHashtable();
virtual ~__SrsUnSortedHashtable();
SrsUnSortedHashtable();
virtual ~SrsUnSortedHashtable();
public:
virtual int count();
virtual void clear();
... ... @@ -715,7 +745,7 @@ namespace _srs_internal
virtual SrsAmf0Any* ensure_property_string(std::string name);
virtual SrsAmf0Any* ensure_property_number(std::string name);
public:
virtual void copy(__SrsUnSortedHashtable* src);
virtual void copy(SrsUnSortedHashtable* src);
};
/**
... ... @@ -723,14 +753,14 @@ namespace _srs_internal
* object-end-type = UTF-8-empty object-end-marker
* 0x00 0x00 0x09
*/
class __SrsAmf0ObjectEOF : public SrsAmf0Any
class SrsAmf0ObjectEOF : public SrsAmf0Any
{
public:
int16_t utf8_empty;
__SrsAmf0ObjectEOF();
virtual ~__SrsAmf0ObjectEOF();
public:
SrsAmf0ObjectEOF();
virtual ~SrsAmf0ObjectEOF();
public:
virtual int total_size();
virtual int read(SrsStream* stream);
virtual int write(SrsStream* stream);
... ... @@ -749,7 +779,7 @@ namespace _srs_internal
extern int srs_amf0_write_utf8(SrsStream* stream, std::string value);
extern bool srs_amf0_is_object_eof(SrsStream* stream);
extern int srs_amf0_write_object_eof(SrsStream* stream, __SrsAmf0ObjectEOF* value);
extern int srs_amf0_write_object_eof(SrsStream* stream, SrsAmf0ObjectEOF* value);
extern int srs_amf0_write_any(SrsStream* stream, SrsAmf0Any* value);
};
... ...