Cover protocol stack RTMP. 3.0.63

pull/1568/head
winlin 5 years ago
parent 40e60aff4d
commit 2731afc161

@ -979,18 +979,18 @@ srs_error_t SrsProtocol::read_basic_header(char& fmt, int& cid)
// 2-63, 1B chunk header
if (cid > 1) {
return err;
}
// 64-319, 2B chunk header
if (cid == 0) {
} else if (cid == 0) {
if ((err = in_buffer->grow(skt, 1)) != srs_success) {
return srs_error_wrap(err, "basic header requires 2 bytes");
}
cid = 64;
cid += (uint8_t)in_buffer->read_1byte();
// 64-65599, 3B chunk header
} else if (cid == 1) {
// 64-65599, 3B chunk header
} else {
srs_assert(cid == 1);
if ((err = in_buffer->grow(skt, 2)) != srs_success) {
return srs_error_wrap(err, "basic header requires 3 bytes");
}
@ -998,9 +998,6 @@ srs_error_t SrsProtocol::read_basic_header(char& fmt, int& cid)
cid = 64;
cid += (uint8_t)in_buffer->read_1byte();
cid += ((uint8_t)in_buffer->read_1byte()) * 256;
} else {
srs_error("invalid path, impossible basic header.");
srs_assert(false);
}
return err;

@ -1056,3 +1056,172 @@ VOID TEST(ProtoStackTest, OnDecodeMessages4)
}
}
VOID TEST(ProtoStackTest, RecvMessage)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x01, 0x00, 0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x00, 0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x00};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
}
VOID TEST(ProtoStackTest, RecvMessage2)
{
srs_error_t err;
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
p.in_chunk_size = 3;
uint8_t bytes[] = {0x03, 0,0,0, 0,0,4, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
uint8_t bytes2[] = {0x43, 0,0,0, 0,0,5, 0, 0,0,0,0, 1,2,3};
io.in_buffer.append((char*)bytes2, sizeof(bytes2));
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x03};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
if (true) {
MockBufferIO io;
SrsProtocol p(&io);
uint8_t bytes[] = {0x43, 0,0,0, 0,0,0, 0};
io.in_buffer.append((char*)bytes, sizeof(bytes));
SrsCommonMessage* msg;
SrsAutoFree(SrsCommonMessage, msg);
HELPER_EXPECT_FAILED(p.recv_message(&msg));
}
}
VOID TEST(ProtoStackTest, RecvMessage3)
{
if (true) {
SrsRequest req;
req.ip = "10.11.12.13";
SrsRequest* cp = req.copy();
EXPECT_STREQ("10.11.12.13", cp->ip.c_str());
srs_freep(cp);
}
if (true) {
SrsRequest req;
req.ip = "10.11.12.13";
SrsAmf0Object* obj = SrsAmf0Any::object();
obj->set("id", SrsAmf0Any::str("srs"));
req.args = obj;
SrsRequest* cp = req.copy();
EXPECT_STREQ("10.11.12.13", cp->ip.c_str());
SrsAmf0Object* cpa = dynamic_cast<SrsAmf0Object*>(cp->args);
SrsAmf0Any* cps = cpa->ensure_property_string("id");
EXPECT_STREQ("srs", cps->to_str().c_str());
srs_freep(cp);
}
if (true) {
SrsRequest req;
EXPECT_STREQ("//", req.get_stream_url().c_str());
}
if (true) {
SrsRequest req;
EXPECT_STREQ("", req.schema.c_str());
req.as_http();
EXPECT_STREQ("http", req.schema.c_str());
}
if (true) {
SrsResponse res;
EXPECT_EQ(1, res.stream_id);
}
if (true) {
EXPECT_STREQ("Play", srs_client_type_string(SrsRtmpConnPlay).c_str());
EXPECT_STREQ("flash-publish", srs_client_type_string(SrsRtmpConnFlashPublish).c_str());
EXPECT_STREQ("fmle-publish", srs_client_type_string(SrsRtmpConnFMLEPublish).c_str());
EXPECT_STREQ("haivision-publish", srs_client_type_string(SrsRtmpConnHaivisionPublish).c_str());
EXPECT_STREQ("Unknown", srs_client_type_string(SrsRtmpConnType(0x0f)).c_str());
EXPECT_TRUE(srs_client_type_is_publish(SrsRtmpConnFlashPublish));
EXPECT_TRUE(srs_client_type_is_publish(SrsRtmpConnFMLEPublish));
EXPECT_TRUE(srs_client_type_is_publish(SrsRtmpConnHaivisionPublish));
EXPECT_FALSE(srs_client_type_is_publish(SrsRtmpConnPlay));
}
}

Loading…
Cancel
Save