本文整理汇总了C++中SrsAmf0Object类的典型用法代码示例。如果您正苦于以下问题:C++ SrsAmf0Object类的具体用法?C++ SrsAmf0Object怎么用?C++ SrsAmf0Object使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SrsAmf0Object类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: srs_amf0_object_clear
void srs_amf0_object_clear(srs_amf0_t amf0)
{
SrsAmf0Any* any = (SrsAmf0Any*)amf0;
srs_assert(any->is_object());
SrsAmf0Object* obj = (SrsAmf0Object*)amf0;
obj->clear();
}
示例2: srs_amf0_object_property
srs_amf0_t srs_amf0_object_property(srs_amf0_t amf0, const char* name)
{
SrsAmf0Any* any = (SrsAmf0Any*)amf0;
srs_assert(any->is_object());
SrsAmf0Object* obj = (SrsAmf0Object*)amf0;
return (srs_amf0_t)obj->get_property(name);
}
示例3: srs_amf0_object_property_name_at
const char* srs_amf0_object_property_name_at(srs_amf0_t amf0, int index)
{
SrsAmf0Any* any = (SrsAmf0Any*)amf0;
srs_assert(any->is_object());
SrsAmf0Object* obj = (SrsAmf0Object*)amf0;
return obj->key_raw_at(index);
}
示例4: srs_amf0_object_property_value_at
srs_amf0_t srs_amf0_object_property_value_at(srs_amf0_t amf0, int index)
{
SrsAmf0Any* any = (SrsAmf0Any*)amf0;
srs_assert(any->is_object());
SrsAmf0Object* obj = (SrsAmf0Object*)amf0;
return (srs_amf0_t)obj->value_at(index);
}
示例5: srs_amf0_object_property_count
int srs_amf0_object_property_count(srs_amf0_t amf0)
{
SrsAmf0Any* any = (SrsAmf0Any*)amf0;
srs_assert(any->is_object());
SrsAmf0Object* obj = (SrsAmf0Object*)amf0;
return obj->count();
}
示例6: srs_amf0_object_property_set
void srs_amf0_object_property_set(srs_amf0_t amf0, const char* name, srs_amf0_t value)
{
SrsAmf0Any* any = (SrsAmf0Any*)amf0;
srs_assert(any->is_object());
SrsAmf0Object* obj = (SrsAmf0Object*)amf0;
any = (SrsAmf0Any*)value;
obj->set(name, any);
}
示例7: srs_amf0_do_print
void srs_amf0_do_print(SrsAmf0Any* any, stringstream& ss, int level)
{
if (any->is_boolean()) {
ss << "Boolean " << (any->to_boolean()? "true":"false") << endl;
} else if (any->is_number()) {
ss << "Number " << std::fixed << any->to_number() << endl;
} else if (any->is_string()) {
ss << "String " << any->to_str() << endl;
} else if (any->is_date()) {
ss << "Date " << std::hex << any->to_date()
<< "/" << std::hex << any->to_date_time_zone() << endl;
} else if (any->is_null()) {
ss << "Null" << endl;
} else if (any->is_ecma_array()) {
SrsAmf0EcmaArray* obj = any->to_ecma_array();
ss << "EcmaArray " << "(" << obj->count() << " items)" << endl;
for (int i = 0; i < obj->count(); i++) {
srs_fill_level_spaces(ss, level + 1);
ss << "Elem '" << obj->key_at(i) << "' ";
if (obj->value_at(i)->is_complex_object()) {
srs_amf0_do_print(obj->value_at(i), ss, level + 1);
} else {
srs_amf0_do_print(obj->value_at(i), ss, 0);
}
}
} else if (any->is_strict_array()) {
SrsAmf0StrictArray* obj = any->to_strict_array();
ss << "StrictArray " << "(" << obj->count() << " items)" << endl;
for (int i = 0; i < obj->count(); i++) {
srs_fill_level_spaces(ss, level + 1);
ss << "Elem ";
if (obj->at(i)->is_complex_object()) {
srs_amf0_do_print(obj->at(i), ss, level + 1);
} else {
srs_amf0_do_print(obj->at(i), ss, 0);
}
}
} else if (any->is_object()) {
SrsAmf0Object* obj = any->to_object();
ss << "Object " << "(" << obj->count() << " items)" << endl;
for (int i = 0; i < obj->count(); i++) {
srs_fill_level_spaces(ss, level + 1);
ss << "Property '" << obj->key_at(i) << "' ";
if (obj->value_at(i)->is_complex_object()) {
srs_amf0_do_print(obj->value_at(i), ss, level + 1);
} else {
srs_amf0_do_print(obj->value_at(i), ss, 0);
}
}
} else {
ss << "Unknown" << endl;
}
}
示例8: TEST
VOID TEST(AMF0Test, ApiObjectProps)
{
SrsAmf0Object* o = NULL;
// get/set property
if (true) {
o = SrsAmf0Any::object();
SrsAutoFree(SrsAmf0Object, o);
EXPECT_TRUE(NULL == o->get_property("name"));
o->set("name", SrsAmf0Any::str("winlin"));
EXPECT_TRUE(NULL != o->get_property("name"));
EXPECT_TRUE(NULL == o->get_property("age"));
o->set("age", SrsAmf0Any::number(100));
EXPECT_TRUE(NULL != o->get_property("age"));
}
// index property
if (true) {
o = SrsAmf0Any::object();
SrsAutoFree(SrsAmf0Object, o);
o->set("name", SrsAmf0Any::str("winlin"));
EXPECT_STREQ("name", o->key_at(0).c_str());
ASSERT_TRUE(o->value_at(0)->is_string());
EXPECT_STREQ("winlin", o->value_at(0)->to_str().c_str());
o->set("age", SrsAmf0Any::number(100));
EXPECT_STREQ("name", o->key_at(0).c_str());
ASSERT_TRUE(o->value_at(0)->is_string());
EXPECT_STREQ("winlin", o->value_at(0)->to_str().c_str());
EXPECT_STREQ("age", o->key_at(1).c_str());
ASSERT_TRUE(o->value_at(1)->is_number());
EXPECT_DOUBLE_EQ(100, o->value_at(1)->to_number());
}
// ensure property
if (true) {
o = SrsAmf0Any::object();
SrsAutoFree(SrsAmf0Object, o);
EXPECT_TRUE(NULL == o->ensure_property_string("name"));
EXPECT_TRUE(NULL == o->ensure_property_number("age"));
o->set("name", SrsAmf0Any::str("winlin"));
EXPECT_TRUE(NULL != o->ensure_property_string("name"));
EXPECT_TRUE(NULL == o->ensure_property_number("name"));
EXPECT_TRUE(NULL == o->ensure_property_number("age"));
o->set("age", SrsAmf0Any::number(100));
EXPECT_TRUE(NULL != o->ensure_property_string("name"));
EXPECT_TRUE(NULL == o->ensure_property_number("name"));
EXPECT_TRUE(NULL != o->ensure_property_number("age"));
EXPECT_TRUE(NULL == o->ensure_property_string("age"));
}
// count
if (true) {
o = SrsAmf0Any::object();
SrsAutoFree(SrsAmf0Object, o);
EXPECT_EQ(0, o->count());
o->set("name", SrsAmf0Any::str("winlin"));
EXPECT_EQ(1, o->count());
o->set("name", SrsAmf0Any::str("winlin"));
EXPECT_EQ(1, o->count());
o->set("age", SrsAmf0Any::number(100));
EXPECT_EQ(2, o->count());
}
}
示例9: connect_app
// TODO: FIXME: refine the connect_app.
int SrsRtspConn::connect_app(string ep_server, string ep_port)
{
int ret = ERROR_SUCCESS;
// args of request takes the srs info.
if (req->args == NULL) {
req->args = SrsAmf0Any::object();
}
// notify server the edge identity,
// @see https://github.com/ossrs/srs/issues/147
SrsAmf0Object* data = req->args;
data->set("srs_sig", SrsAmf0Any::str(RTMP_SIG_SRS_KEY));
data->set("srs_server", SrsAmf0Any::str(RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")"));
data->set("srs_license", SrsAmf0Any::str(RTMP_SIG_SRS_LICENSE));
data->set("srs_role", SrsAmf0Any::str(RTMP_SIG_SRS_ROLE));
data->set("srs_url", SrsAmf0Any::str(RTMP_SIG_SRS_URL));
data->set("srs_version", SrsAmf0Any::str(RTMP_SIG_SRS_VERSION));
data->set("srs_site", SrsAmf0Any::str(RTMP_SIG_SRS_WEB));
data->set("srs_email", SrsAmf0Any::str(RTMP_SIG_SRS_EMAIL));
data->set("srs_copyright", SrsAmf0Any::str(RTMP_SIG_SRS_COPYRIGHT));
data->set("srs_primary", SrsAmf0Any::str(RTMP_SIG_SRS_PRIMARY));
data->set("srs_authors", SrsAmf0Any::str(RTMP_SIG_SRS_AUTHROS));
// for edge to directly get the id of client.
data->set("srs_pid", SrsAmf0Any::number(getpid()));
data->set("srs_id", SrsAmf0Any::number(_srs_context->get_id()));
// local ip of edge
std::vector<std::string> ips = srs_get_local_ipv4_ips();
assert(_srs_config->get_stats_network() < (int)ips.size());
std::string local_ip = ips[_srs_config->get_stats_network()];
data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str()));
// generate the tcUrl
std::string param = "";
std::string tc_url = srs_generate_tc_url(ep_server, req->vhost, req->app, ep_port, param);
// upnode server identity will show in the connect_app of client.
// @see https://github.com/ossrs/srs/issues/160
// the debug_srs_upnode is config in vhost and default to true.
bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost);
if ((ret = client->connect_app(req->app, tc_url, req, debug_srs_upnode)) != ERROR_SUCCESS) {
srs_error("rtsp: connect with server failed, tcUrl=%s, dsu=%d. ret=%d",
tc_url.c_str(), debug_srs_upnode, ret);
return ret;
}
return ret;
}
示例10: SrsAutoFree
int SrsFlvSegment::write_metadata(SrsSharedPtrMessage* metadata)
{
int ret = ERROR_SUCCESS;
if (duration_offset || filesize_offset) {
return ret;
}
SrsBuffer stream;
if ((ret = stream.initialize(metadata->payload, metadata->size)) != ERROR_SUCCESS) {
return ret;
}
SrsAmf0Any* name = SrsAmf0Any::str();
SrsAutoFree(SrsAmf0Any, name);
if ((ret = name->read(&stream)) != ERROR_SUCCESS) {
return ret;
}
SrsAmf0Object* obj = SrsAmf0Any::object();
SrsAutoFree(SrsAmf0Object, obj);
if ((ret = obj->read(&stream)) != ERROR_SUCCESS) {
return ret;
}
// remove duration and filesize.
obj->set("filesize", NULL);
obj->set("duration", NULL);
// add properties.
obj->set("service", SrsAmf0Any::str(RTMP_SIG_SRS_SERVER));
obj->set("filesize", SrsAmf0Any::number(0));
obj->set("duration", SrsAmf0Any::number(0));
int size = name->total_size() + obj->total_size();
char* payload = new char[size];
SrsAutoFreeA(char, payload);
// 11B flv header, 3B object EOF, 8B number value, 1B number flag.
duration_offset = fs->tellg() + size + 11 - SrsAmf0Size::object_eof() - SrsAmf0Size::number();
// 2B string flag, 8B number value, 8B string 'duration', 1B number flag
filesize_offset = duration_offset - SrsAmf0Size::utf8("duration") - SrsAmf0Size::number();
// convert metadata to bytes.
if ((ret = stream.initialize(payload, size)) != ERROR_SUCCESS) {
return ret;
}
if ((ret = name->write(&stream)) != ERROR_SUCCESS) {
return ret;
}
if ((ret = obj->write(&stream)) != ERROR_SUCCESS) {
return ret;
}
// to flv file.
if ((ret = enc->write_metadata(18, payload, size)) != ERROR_SUCCESS) {
return ret;
}
return ret;
}