mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
support amf0 StrictArray(0x0a). 0.9.111.
This commit is contained in:
parent
c8f80414ef
commit
7f48590239
5 changed files with 272 additions and 29 deletions
|
@ -251,6 +251,16 @@ bool SrsAmf0Any::is_ecma_array()
|
|||
return marker == RTMP_AMF0_EcmaArray;
|
||||
}
|
||||
|
||||
bool SrsAmf0Any::is_strict_array()
|
||||
{
|
||||
return marker == RTMP_AMF0_StrictArray;
|
||||
}
|
||||
|
||||
bool SrsAmf0Any::is_complex_object()
|
||||
{
|
||||
return is_object() || is_object_eof() || is_ecma_array() || is_strict_array();
|
||||
}
|
||||
|
||||
string SrsAmf0Any::to_str()
|
||||
{
|
||||
__SrsAmf0String* p = dynamic_cast<__SrsAmf0String*>(this);
|
||||
|
@ -293,6 +303,13 @@ SrsAmf0EcmaArray* SrsAmf0Any::to_ecma_array()
|
|||
return p;
|
||||
}
|
||||
|
||||
SrsAmf0StrictArray* SrsAmf0Any::to_strict_array()
|
||||
{
|
||||
SrsAmf0StrictArray* p = dynamic_cast<SrsAmf0StrictArray*>(this);
|
||||
srs_assert(p != NULL);
|
||||
return p;
|
||||
}
|
||||
|
||||
bool SrsAmf0Any::is_object_eof()
|
||||
{
|
||||
return marker == RTMP_AMF0_ObjectEnd;
|
||||
|
@ -338,6 +355,11 @@ SrsAmf0EcmaArray* SrsAmf0Any::ecma_array()
|
|||
return new SrsAmf0EcmaArray();
|
||||
}
|
||||
|
||||
SrsAmf0StrictArray* SrsAmf0Any::strict_array()
|
||||
{
|
||||
return new SrsAmf0StrictArray();
|
||||
}
|
||||
|
||||
int SrsAmf0Any::discovery(SrsStream* stream, SrsAmf0Any** ppvalue)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -390,6 +412,10 @@ int SrsAmf0Any::discovery(SrsStream* stream, SrsAmf0Any** ppvalue)
|
|||
*ppvalue = SrsAmf0Any::ecma_array();
|
||||
return ret;
|
||||
}
|
||||
case RTMP_AMF0_StrictArray: {
|
||||
*ppvalue = SrsAmf0Any::strict_array();
|
||||
return ret;
|
||||
}
|
||||
case RTMP_AMF0_Invalid:
|
||||
default: {
|
||||
ret = ERROR_RTMP_AMF0_INVALID;
|
||||
|
@ -956,6 +982,137 @@ SrsAmf0Any* SrsAmf0EcmaArray::ensure_property_number(string name)
|
|||
return properties->ensure_property_number(name);
|
||||
}
|
||||
|
||||
SrsAmf0StrictArray::SrsAmf0StrictArray()
|
||||
{
|
||||
marker = RTMP_AMF0_StrictArray;
|
||||
}
|
||||
|
||||
SrsAmf0StrictArray::~SrsAmf0StrictArray()
|
||||
{
|
||||
std::vector<SrsAmf0Any*>::iterator it;
|
||||
for (it = properties.begin(); it != properties.end(); ++it) {
|
||||
SrsAmf0Any* any = *it;
|
||||
srs_freep(any);
|
||||
}
|
||||
properties.clear();
|
||||
}
|
||||
|
||||
int SrsAmf0StrictArray::total_size()
|
||||
{
|
||||
int size = 1 + 4;
|
||||
|
||||
for (int i = 0; i < (int)properties.size(); i++){
|
||||
SrsAmf0Any* any = properties[i];
|
||||
size += any->total_size();
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
int SrsAmf0StrictArray::read(SrsStream* stream)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// marker
|
||||
if (!stream->require(1)) {
|
||||
ret = ERROR_RTMP_AMF0_DECODE;
|
||||
srs_error("amf0 read strict_array marker failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char marker = stream->read_1bytes();
|
||||
if (marker != RTMP_AMF0_StrictArray) {
|
||||
ret = ERROR_RTMP_AMF0_DECODE;
|
||||
srs_error("amf0 check strict_array marker failed. "
|
||||
"marker=%#x, required=%#x, ret=%d", marker, RTMP_AMF0_Object, ret);
|
||||
return ret;
|
||||
}
|
||||
srs_verbose("amf0 read strict_array marker success");
|
||||
|
||||
// count
|
||||
if (!stream->require(4)) {
|
||||
ret = ERROR_RTMP_AMF0_DECODE;
|
||||
srs_error("amf0 read strict_array count failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t count = stream->read_4bytes();
|
||||
srs_verbose("amf0 read strict_array count success. count=%d", count);
|
||||
|
||||
// value
|
||||
this->_count = count;
|
||||
|
||||
for (int i = 0; i < count && !stream->empty(); i++) {
|
||||
// property-value: any
|
||||
SrsAmf0Any* elem = NULL;
|
||||
if ((ret = srs_amf0_read_any(stream, &elem)) != ERROR_SUCCESS) {
|
||||
srs_error("amf0 strict_array read value failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// add property
|
||||
properties.push_back(elem);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
int SrsAmf0StrictArray::write(SrsStream* stream)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// marker
|
||||
if (!stream->require(1)) {
|
||||
ret = ERROR_RTMP_AMF0_ENCODE;
|
||||
srs_error("amf0 write strict_array marker failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
stream->write_1bytes(RTMP_AMF0_StrictArray);
|
||||
srs_verbose("amf0 write strict_array marker success");
|
||||
|
||||
// count
|
||||
if (!stream->require(4)) {
|
||||
ret = ERROR_RTMP_AMF0_ENCODE;
|
||||
srs_error("amf0 write strict_array count failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
stream->write_4bytes(this->_count);
|
||||
srs_verbose("amf0 write strict_array count success. count=%d", _count);
|
||||
|
||||
// value
|
||||
for (int i = 0; i < (int)properties.size(); i++) {
|
||||
SrsAmf0Any* any = properties[i];
|
||||
|
||||
if ((ret = srs_amf0_write_any(stream, any)) != ERROR_SUCCESS) {
|
||||
srs_error("write strict_array property value failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_verbose("write amf0 property success. name=%s", name.c_str());
|
||||
}
|
||||
|
||||
srs_verbose("write strict_array object success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SrsAmf0StrictArray::clear()
|
||||
{
|
||||
properties.clear();
|
||||
}
|
||||
|
||||
int SrsAmf0StrictArray::count()
|
||||
{
|
||||
return properties.size();
|
||||
}
|
||||
|
||||
SrsAmf0Any* SrsAmf0StrictArray::at(int index)
|
||||
{
|
||||
srs_assert(index < (int)properties.size());
|
||||
return properties.at(index);
|
||||
}
|
||||
|
||||
int SrsAmf0Size::utf8(string value)
|
||||
{
|
||||
return 2 + value.length();
|
||||
|
@ -1009,6 +1166,15 @@ int SrsAmf0Size::ecma_array(SrsAmf0EcmaArray* arr)
|
|||
return arr->total_size();
|
||||
}
|
||||
|
||||
int SrsAmf0Size::strict_array(SrsAmf0StrictArray* arr)
|
||||
{
|
||||
if (!arr) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return arr->total_size();
|
||||
}
|
||||
|
||||
int SrsAmf0Size::any(SrsAmf0Any* o)
|
||||
{
|
||||
if (!o) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue