本文整理汇总了C++中SrsAmf0Any::read方法的典型用法代码示例。如果您正苦于以下问题:C++ SrsAmf0Any::read方法的具体用法?C++ SrsAmf0Any::read怎么用?C++ SrsAmf0Any::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SrsAmf0Any
的用法示例。
在下文中一共展示了SrsAmf0Any::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed)
{
int ret = ERROR_SUCCESS;
srs_amf0_t amf0 = NULL;
SrsStream stream;
if ((ret = stream.initialize(data, size)) != ERROR_SUCCESS) {
return amf0;
}
SrsAmf0Any* any = NULL;
if ((ret = SrsAmf0Any::discovery(&stream, &any)) != ERROR_SUCCESS) {
return amf0;
}
stream.reset();
if ((ret = any->read(&stream)) != ERROR_SUCCESS) {
srs_freep(any);
return amf0;
}
*nparsed = stream.pos();
amf0 = (srs_amf0_t)any;
return amf0;
}
示例2: TEST
VOID TEST(AMF0Test, ApiAnyIO)
{
SrsStream s;
SrsAmf0Any* o = NULL;
char buf[1024];
memset(buf, 0, sizeof(buf));
EXPECT_EQ(ERROR_SUCCESS, s.initialize(buf, sizeof(buf)));
// object eof
if (true) {
s.reset();
s.current()[2] = 0x09;
o = SrsAmf0Any::object_eof();
SrsAutoFree(SrsAmf0Any, o);
EXPECT_EQ(ERROR_SUCCESS, o->read(&s));
EXPECT_EQ(o->total_size(), s.pos());
EXPECT_EQ(3, s.pos());
s.reset();
s.current()[0] = 0x01;
EXPECT_NE(ERROR_SUCCESS, o->read(&s));
}
if (true) {
s.reset();
o = SrsAmf0Any::object_eof();
SrsAutoFree(SrsAmf0Any, o);
EXPECT_EQ(ERROR_SUCCESS, o->write(&s));
EXPECT_EQ(o->total_size(), s.pos());
EXPECT_EQ(3, s.pos());
s.skip(-3);
EXPECT_EQ(0x09, s.read_3bytes());
}
// string
if (true) {
s.reset();
o = SrsAmf0Any::str("winlin");
SrsAutoFree(SrsAmf0Any, o);
EXPECT_EQ(ERROR_SUCCESS, o->write(&s));
EXPECT_EQ(o->total_size(), s.pos());
s.reset();
EXPECT_EQ(2, s.read_1bytes());
EXPECT_EQ(6, s.read_2bytes());
EXPECT_EQ('w', s.current()[0]);
EXPECT_EQ('n', s.current()[5]);
s.reset();
s.current()[3] = 'x';
EXPECT_EQ(ERROR_SUCCESS, o->read(&s));
EXPECT_EQ(o->total_size(), s.pos());
EXPECT_STREQ("xinlin", o->to_str().c_str());
}
// number
if (true) {
s.reset();
o = SrsAmf0Any::number(10);
SrsAutoFree(SrsAmf0Any, o);
EXPECT_EQ(ERROR_SUCCESS, o->write(&s));
EXPECT_EQ(o->total_size(), s.pos());
s.reset();
EXPECT_EQ(0, s.read_1bytes());
s.reset();
EXPECT_EQ(ERROR_SUCCESS, o->read(&s));
EXPECT_EQ(o->total_size(), s.pos());
EXPECT_DOUBLE_EQ(10, o->to_number());
}
// boolean
if (true) {
s.reset();
o = SrsAmf0Any::boolean(true);
SrsAutoFree(SrsAmf0Any, o);
EXPECT_EQ(ERROR_SUCCESS, o->write(&s));
EXPECT_EQ(o->total_size(), s.pos());
s.reset();
EXPECT_EQ(1, s.read_1bytes());
s.reset();
EXPECT_EQ(ERROR_SUCCESS, o->read(&s));
EXPECT_EQ(o->total_size(), s.pos());
EXPECT_TRUE(o->to_boolean());
}
if (true) {
//.........这里部分代码省略.........
示例3: write_metadata
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;
}