mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
amf0 utest: add usage for amf0
This commit is contained in:
parent
34f94a1be3
commit
3691c106fa
2 changed files with 45 additions and 13 deletions
|
@ -37,6 +37,35 @@ class SrsStream;
|
||||||
class SrsAmf0Object;
|
class SrsAmf0Object;
|
||||||
class SrsAmf0EcmaArray;
|
class SrsAmf0EcmaArray;
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// amf0 codec
|
||||||
|
// 1. SrsAmf0Any: read any from stream
|
||||||
|
// SrsAmf0Any* pany = NULL;
|
||||||
|
// if ((ret = srs_amf0_read_any(stream, &pany)) != ERROR_SUCCESS) {
|
||||||
|
// return ret;
|
||||||
|
// }
|
||||||
|
// 2. SrsAmf0Any: convert to specifid type, for instance, string
|
||||||
|
// SrsAmf0Any* pany = ...
|
||||||
|
// if (pany && pany->is_string()) {
|
||||||
|
// string v = pany->to_str();
|
||||||
|
// }
|
||||||
|
// 3. SrsAmf0Any: parse specified type to any, for instance, string
|
||||||
|
// SrsAmf0Any* pany = SrsAmf0Any::str("winlin");
|
||||||
|
// 4. SrsAmf0Size: get amf0 instance size
|
||||||
|
// int size = SrsAmf0Size::str("winlin");
|
||||||
|
// 5. SrsAmf0Object: the amf0 object, directly new is ok.
|
||||||
|
// SrsAmf0Object* obj = SrsAmf0Any::object();
|
||||||
|
// SrsAmf0Object* obj = new SrsAmf0Object();
|
||||||
|
// 5. SrsAmf0EcmaArray: the amf0 ecma array, directly new is ok.
|
||||||
|
// SrsAmf0EcmaArray* arr = SrsAmf0Any::array();
|
||||||
|
// SrsAmf0EcmaArray* arr = new SrsAmf0EcmaArray();
|
||||||
|
// for detail usage, see interfaces of each object.
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* any amf0 value.
|
* any amf0 value.
|
||||||
* 2.1 Types Overview
|
* 2.1 Types Overview
|
||||||
|
|
|
@ -2624,6 +2624,7 @@ int SrsPlayPacket::decode(SrsStream* stream)
|
||||||
}
|
}
|
||||||
SrsAutoFree(SrsAmf0Any, reset_value, false);
|
SrsAutoFree(SrsAmf0Any, reset_value, false);
|
||||||
|
|
||||||
|
if (reset_value) {
|
||||||
// check if the value is bool or number
|
// check if the value is bool or number
|
||||||
// An optional Boolean value or number that specifies whether
|
// An optional Boolean value or number that specifies whether
|
||||||
// to flush any previous playlist
|
// to flush any previous playlist
|
||||||
|
@ -2636,6 +2637,7 @@ int SrsPlayPacket::decode(SrsStream* stream)
|
||||||
srs_error("amf0 invalid type=%#x, requires number or bool, ret=%d", reset_value->marker, ret);
|
srs_error("amf0 invalid type=%#x, requires number or bool, ret=%d", reset_value->marker, ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
srs_info("amf0 decode play packet success");
|
srs_info("amf0 decode play packet success");
|
||||||
|
|
||||||
|
@ -3188,7 +3190,7 @@ int SrsOnMetaDataPacket::decode(SrsStream* stream)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (any->is_object()) {
|
if (any && any->is_object()) {
|
||||||
srs_freep(metadata);
|
srs_freep(metadata);
|
||||||
metadata = dynamic_cast<SrsAmf0Object*>(any);
|
metadata = dynamic_cast<SrsAmf0Object*>(any);
|
||||||
srs_info("decode metadata object success");
|
srs_info("decode metadata object success");
|
||||||
|
@ -3199,10 +3201,11 @@ int SrsOnMetaDataPacket::decode(SrsStream* stream)
|
||||||
if (!arr) {
|
if (!arr) {
|
||||||
ret = ERROR_RTMP_AMF0_DECODE;
|
ret = ERROR_RTMP_AMF0_DECODE;
|
||||||
srs_error("decode metadata array failed. ret=%d", ret);
|
srs_error("decode metadata array failed. ret=%d", ret);
|
||||||
srs_freep(any);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if ecma array, copy to object.
|
||||||
|
SrsAutoFree(SrsAmf0EcmaArray, arr, false);
|
||||||
for (int i = 0; i < arr->size(); i++) {
|
for (int i = 0; i < arr->size(); i++) {
|
||||||
metadata->set(arr->key_at(i), arr->value_at(i));
|
metadata->set(arr->key_at(i), arr->value_at(i));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue