本文整理汇总了C++中SrsStream::read_4bytes方法的典型用法代码示例。如果您正苦于以下问题:C++ SrsStream::read_4bytes方法的具体用法?C++ SrsStream::read_4bytes怎么用?C++ SrsStream::read_4bytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SrsStream
的用法示例。
在下文中一共展示了SrsStream::read_4bytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEST
/**
* test the stream utility, read 4bytes
*/
VOID TEST(KernelStreamTest, StreamRead4Bytes)
{
SrsStream s;
char data[1024];
EXPECT_TRUE(ERROR_SUCCESS == s.initialize(data, 1024));
data[0] = 0x01;
data[1] = 0x02;
data[2] = 0x03;
data[3] = 0x04;
data[4] = 0x05;
data[5] = 0x06;
data[6] = 0x07;
data[7] = 0x08;
data[8] = 0x09;
data[9] = 0x0a;
EXPECT_EQ(0x01020304, s.read_4bytes());
EXPECT_EQ(0x05060708, s.read_4bytes());
s.skip(-1 * s.pos());
s.skip(5);
EXPECT_EQ(0x06070809, s.read_4bytes());
}
示例2:
int32_t __srs_stream_read_4bytes(char* pp)
{
static SrsStream stream;
int ret = stream.initialize(pp, 4);
srs_assert(ret == ERROR_SUCCESS);
return stream.read_4bytes();
}
示例3: TEST
VOID TEST(AMF0Test, ApiStrictArray)
{
SrsStream s;
char buf[1024];
memset(buf, 0, sizeof(buf));
EXPECT_EQ(ERROR_SUCCESS, s.initialize(buf, sizeof(buf)));
SrsAmf0StrictArray* o = NULL;
// append property
if (true) {
o = SrsAmf0Any::strict_array();
SrsAutoFree(SrsAmf0StrictArray, o);
o->append(SrsAmf0Any::number(100));
EXPECT_DOUBLE_EQ(100, o->at(0)->to_number());
o->append(SrsAmf0Any::number(101));
EXPECT_DOUBLE_EQ(101, o->at(1)->to_number());
o->append(SrsAmf0Any::str("winlin"));
EXPECT_STREQ("winlin", o->at(2)->to_str().c_str());
}
// count
if (true) {
o = SrsAmf0Any::strict_array();
SrsAutoFree(SrsAmf0StrictArray, o);
EXPECT_EQ(0, o->count());
o->append(SrsAmf0Any::boolean());
EXPECT_EQ(1, o->count());
o->append(SrsAmf0Any::boolean());
EXPECT_EQ(2, o->count());
o->clear();
EXPECT_EQ(0, o->count());
}
// io
if (true) {
o = SrsAmf0Any::strict_array();
SrsAutoFree(SrsAmf0StrictArray, o);
s.reset();
EXPECT_EQ(ERROR_SUCCESS, o->write(&s));
EXPECT_EQ(5, s.pos());
s.reset();
EXPECT_EQ(0x0a, s.read_1bytes());
EXPECT_EQ(0x00, s.read_4bytes());
}
if (true) {
o = SrsAmf0Any::strict_array();
SrsAutoFree(SrsAmf0StrictArray, o);
o->append(SrsAmf0Any::number(0));
s.reset();
EXPECT_EQ(ERROR_SUCCESS, o->write(&s));
EXPECT_EQ(5 + SrsAmf0Size::number(), s.pos());
}
}
示例4: on_aggregate
int SrsSource::on_aggregate(SrsMessage* msg)
{
int ret = ERROR_SUCCESS;
SrsStream* stream = aggregate_stream;
if ((ret = stream->initialize((char*)msg->payload, msg->size)) != ERROR_SUCCESS) {
return ret;
}
while (!stream->empty()) {
if (!stream->require(1)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message type. ret=%d", ret);
return ret;
}
int8_t type = stream->read_1bytes();
if (!stream->require(3)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message size. ret=%d", ret);
return ret;
}
int32_t data_size = stream->read_3bytes();
if (data_size < 0) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message size(negative). ret=%d", ret);
return ret;
}
if (!stream->require(3)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message time. ret=%d", ret);
return ret;
}
int32_t timestamp = stream->read_3bytes();
if (!stream->require(1)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message time(high). ret=%d", ret);
return ret;
}
int32_t time_h = stream->read_1bytes();
timestamp |= time_h<<24;
timestamp &= 0x7FFFFFFF;
if (!stream->require(3)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message stream_id. ret=%d", ret);
return ret;
}
int32_t stream_id = stream->read_3bytes();
if (data_size > 0 && !stream->require(data_size)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message data. ret=%d", ret);
return ret;
}
// to common message.
SrsCommonMessage __o;
SrsMessage& o = __o;
o.header.message_type = type;
o.header.payload_length = data_size;
o.header.timestamp_delta = timestamp;
o.header.timestamp = timestamp;
o.header.stream_id = stream_id;
o.header.perfer_cid = msg->header.perfer_cid;
if (data_size > 0) {
o.size = data_size;
o.payload = new char[o.size];
stream->read_bytes(o.payload, o.size);
}
if (!stream->require(4)) {
ret = ERROR_RTMP_AGGREGATE;
srs_error("invalid aggregate message previous tag size. ret=%d", ret);
return ret;
}
stream->read_4bytes();
// process parsed message
if (o.header.is_audio()) {
if ((ret = on_audio(&o)) != ERROR_SUCCESS) {
return ret;
}
} else if (o.header.is_video()) {
if ((ret = on_video(&o)) != ERROR_SUCCESS) {
return ret;
}
}
}
return ret;
}