From 2731afc1614c75a2b35252344843eb0937535862 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 20 Nov 2019 14:08:53 +0800 Subject: [PATCH] Cover protocol stack RTMP. 3.0.63 --- trunk/src/protocol/srs_rtmp_stack.cpp | 15 +- trunk/src/utest/srs_utest_protostack.cpp | 169 +++++++++++++++++++++++ 2 files changed, 175 insertions(+), 9 deletions(-) diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index 5d2387aef..0099d5791 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -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; diff --git a/trunk/src/utest/srs_utest_protostack.cpp b/trunk/src/utest/srs_utest_protostack.cpp index a636d2707..0f0b8021a 100644 --- a/trunk/src/utest/srs_utest_protostack.cpp +++ b/trunk/src/utest/srs_utest_protostack.cpp @@ -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(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)); + } +} +