diff --git a/trunk/configure b/trunk/configure index e0250254d..e30eeede9 100755 --- a/trunk/configure +++ b/trunk/configure @@ -455,7 +455,7 @@ KERNEL_OBJS="${MODULE_OBJS[@]}" MODULE_ID="RTMP" MODULE_DEPENDS=("CORE" "KERNEL") ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot}) -MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_rtmp_stack" "srs_protocol_rtmp" +MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_stack" "srs_protocol_rtmp" "srs_protocol_handshake" "srs_protocol_utility" "srs_protocol_msg_array") RTMP_INCS="src/rtmp"; MODULE_DIR=${RTMP_INCS} . auto/modules.sh RTMP_OBJS="${MODULE_OBJS[@]}" diff --git a/trunk/src/app/srs_app_bandwidth.cpp b/trunk/src/app/srs_app_bandwidth.cpp index 398f1acc3..9a9a387ff 100644 --- a/trunk/src/app/srs_app_bandwidth.cpp +++ b/trunk/src/app/srs_app_bandwidth.cpp @@ -31,7 +31,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include @@ -99,8 +99,6 @@ int SrsBandwidth::bandwidth_test(SrsRequest* _req, st_netfd_t stfd, SrsRtmpServe int SrsBandwidth::do_bandwidth_check() { int ret = ERROR_SUCCESS; - - SrsProtocol* protocol = rtmp->get_protocol(); int play_duration_ms = 3000; int play_interval_ms = 0; @@ -160,7 +158,7 @@ int SrsBandwidth::do_bandwidth_check() while (true) { SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { // info level to ignore and return success. srs_info("expect final message failed. ret=%d", ret); return ERROR_SUCCESS; @@ -185,8 +183,6 @@ int SrsBandwidth::check_play( int& play_bytes, int max_play_kbps) { int ret = ERROR_SUCCESS; - - SrsProtocol* protocol = rtmp->get_protocol(); if (true) { // send start play command to client @@ -206,7 +202,7 @@ int SrsBandwidth::check_play( // recv client's starting play response SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect bandwidth message failed. ret=%d", ret); return ret; } @@ -287,7 +283,7 @@ int SrsBandwidth::check_play( // recv client's stop play response. SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect bandwidth message failed. ret=%d", ret); return ret; } @@ -309,8 +305,6 @@ int SrsBandwidth::check_publish( int& publish_bytes, int max_pub_kbps) { int ret = ERROR_SUCCESS; - - SrsProtocol* protocol = rtmp->get_protocol(); if (true) { // notify client to start publish @@ -330,7 +324,7 @@ int SrsBandwidth::check_publish( // read client's notification of starting publish SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect bandwidth message failed. ret=%d", ret); return ret; } @@ -398,7 +392,7 @@ int SrsBandwidth::check_publish( // recv client's stop publish response. SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = rtmp->expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect bandwidth message failed. ret=%d", ret); return ret; } diff --git a/trunk/src/app/srs_app_dvr.cpp b/trunk/src/app/srs_app_dvr.cpp index 5b4660791..3e331ad00 100644 --- a/trunk/src/app/srs_app_dvr.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -32,7 +32,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp index 611f199b1..292add742 100644 --- a/trunk/src/app/srs_app_edge.cpp +++ b/trunk/src/app/srs_app_edge.cpp @@ -37,7 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp index 09d4083e4..50fe7daaf 100644 --- a/trunk/src/app/srs_app_encoder.cpp +++ b/trunk/src/app/srs_app_encoder.cpp @@ -31,7 +31,7 @@ using namespace std; #include #include #include -#include +#include #include #include diff --git a/trunk/src/app/srs_app_ffmpeg.cpp b/trunk/src/app/srs_app_ffmpeg.cpp index 50a7b883a..6e29f9d57 100644 --- a/trunk/src/app/srs_app_ffmpeg.cpp +++ b/trunk/src/app/srs_app_ffmpeg.cpp @@ -37,7 +37,7 @@ using namespace std; #include #include #include -#include +#include #ifdef SRS_AUTO_FFMPEG diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp index c6605c46f..1bd20fa97 100644 --- a/trunk/src/app/srs_app_forward.cpp +++ b/trunk/src/app/srs_app_forward.cpp @@ -36,7 +36,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index ea880999b..8100462be 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -37,7 +37,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_rtmp_conn.cpp b/trunk/src/app/srs_app_rtmp_conn.cpp index 80b9d1371..65113d416 100644 --- a/trunk/src/app/srs_app_rtmp_conn.cpp +++ b/trunk/src/app/srs_app_rtmp_conn.cpp @@ -33,7 +33,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 35152c0d6..08c239675 100644 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. using namespace std; #include -#include +#include #include #include #include diff --git a/trunk/src/libs/srs_librtmp.cpp b/trunk/src/libs/srs_librtmp.cpp index 0bc42ca15..7cbac9a7c 100644 --- a/trunk/src/libs/srs_librtmp.cpp +++ b/trunk/src/libs/srs_librtmp.cpp @@ -35,7 +35,7 @@ using namespace std; #include #include #include -#include +#include #include #include #include diff --git a/trunk/src/main/srs_main_bandcheck.cpp b/trunk/src/main/srs_main_bandcheck.cpp index b0c10689a..475ad0b49 100644 --- a/trunk/src/main/srs_main_bandcheck.cpp +++ b/trunk/src/main/srs_main_bandcheck.cpp @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include -#include +#include #include #include #include @@ -345,7 +345,7 @@ int SrsBandCheckClient::expect_start_play() // expect connect _result SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect bandcheck start play message failed. ret=%d", ret); return ret; } @@ -382,7 +382,7 @@ int SrsBandCheckClient::expect_stop_play() while (true) { SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect stop play message failed. ret=%d", ret); return ret; } @@ -419,7 +419,7 @@ int SrsBandCheckClient::expect_start_pub() while (true) { SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect start pub message failed. ret=%d", ret); return ret; } @@ -489,7 +489,7 @@ int SrsBandCheckClient::expect_stop_pub() SrsMessage* msg; SrsBandwidthPacket* pkt; - if ((ret = srs_rtmp_expect_message(this->protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { return ret; } SrsAutoFree(SrsMessage, msg); @@ -508,7 +508,7 @@ int SrsBandCheckClient::expect_finished() while (true) { SrsMessage* msg = NULL; SrsBandwidthPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect finished message failed. ret=%d", ret); return ret; } diff --git a/trunk/src/rtmp/srs_protocol_msg_array.cpp b/trunk/src/rtmp/srs_protocol_msg_array.cpp index e9dc40241..b1c90d620 100644 --- a/trunk/src/rtmp/srs_protocol_msg_array.cpp +++ b/trunk/src/rtmp/srs_protocol_msg_array.cpp @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -#include +#include SrsSharedPtrMessageArray::SrsSharedPtrMessageArray(int _size) { diff --git a/trunk/src/rtmp/srs_protocol_rtmp.cpp b/trunk/src/rtmp/srs_protocol_rtmp.cpp index 1f36efee9..6cc3be4ff 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.cpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.cpp @@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include -#include +#include #include #include #include @@ -140,6 +140,7 @@ string SrsRequest::get_stream_url() void SrsRequest::strip() { // remove the unsupported chars in names. + host = srs_string_remove(host, "/ \n\r\t"); vhost = srs_string_remove(vhost, "/ \n\r\t"); app = srs_string_remove(app, " \n\r\t"); stream = srs_string_remove(stream, " \n\r\t"); @@ -338,11 +339,6 @@ SrsRtmpClient::~SrsRtmpClient() srs_freep(hs_bytes); } -SrsProtocol* SrsRtmpClient::get_protocol() -{ - return protocol; -} - void SrsRtmpClient::set_recv_timeout(int64_t timeout_us) { protocol->set_recv_timeout(timeout_us); @@ -487,7 +483,7 @@ int SrsRtmpClient::connect_app(string app, string tc_url, SrsRequest* req) // expect connect _result SrsMessage* msg = NULL; SrsConnectAppResPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect connect app response message failed. ret=%d", ret); return ret; } @@ -540,7 +536,7 @@ int SrsRtmpClient::create_stream(int& stream_id) if (true) { SrsMessage* msg = NULL; SrsCreateStreamResPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect create stream response message failed. ret=%d", ret); return ret; } @@ -674,7 +670,7 @@ int SrsRtmpClient::fmle_publish(string stream, int& stream_id) if (true) { SrsMessage* msg = NULL; SrsCreateStreamResPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect create stream response message failed. ret=%d", ret); return ret; } @@ -795,7 +791,7 @@ int SrsRtmpServer::connect_app(SrsRequest* req) SrsMessage* msg = NULL; SrsConnectAppPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("expect connect app message failed. ret=%d", ret); return ret; } @@ -1189,7 +1185,7 @@ int SrsRtmpServer::start_fmle_publish(int stream_id) if (true) { SrsMessage* msg = NULL; SrsFMLEStartPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("recv FCPublish message failed. ret=%d", ret); return ret; } @@ -1215,7 +1211,7 @@ int SrsRtmpServer::start_fmle_publish(int stream_id) if (true) { SrsMessage* msg = NULL; SrsCreateStreamPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("recv createStream message failed. ret=%d", ret); return ret; } @@ -1240,7 +1236,7 @@ int SrsRtmpServer::start_fmle_publish(int stream_id) if (true) { SrsMessage* msg = NULL; SrsPublishPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + if ((ret = expect_message(&msg, &pkt)) != ERROR_SUCCESS) { srs_error("recv publish message failed. ret=%d", ret); return ret; } diff --git a/trunk/src/rtmp/srs_protocol_rtmp.hpp b/trunk/src/rtmp/srs_protocol_rtmp.hpp index b59896965..88d3a162f 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp.hpp +++ b/trunk/src/rtmp/srs_protocol_rtmp.hpp @@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include + class SrsProtocol; class ISrsProtocolReaderWriter; class ISrsMessage; @@ -171,7 +173,6 @@ public: SrsRtmpClient(ISrsProtocolReaderWriter* skt); virtual ~SrsRtmpClient(); public: - virtual SrsProtocol* get_protocol(); virtual void set_recv_timeout(int64_t timeout_us); virtual void set_send_timeout(int64_t timeout_us); virtual int64_t get_recv_bytes(); @@ -199,6 +200,27 @@ public: // FMLE publish schema: // connect-app => FMLE publish virtual int fmle_publish(std::string stream, int& stream_id); +public: + /** + * expect a specified message, drop others util got specified one. + * @pmsg, user must free it. NULL if not success. + * @ppacket, store in the pmsg, user must never free it. NULL if not success. + * @remark, only when success, user can use and must free the pmsg/ppacket. + * for example: + SrsCommonMessage* msg = NULL; + SrsConnectAppResPacket* pkt = NULL; + if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + return ret; + } + // use pkt + * user should never recv message and convert it, use this method instead. + * if need to set timeout, use set timeout of SrsProtocol. + */ + template + int expect_message(SrsMessage** pmsg, T** ppacket) + { + return protocol->expect_message(pmsg, ppacket); + } }; /** @@ -206,7 +228,6 @@ public: * a high level protocol, media stream oriented services, * such as connect to vhost/app, play stream, get audio/video data. */ -// TODO: FIXME: rename to SrsRtmpServer class SrsRtmpServer { private: @@ -294,6 +315,27 @@ public: * onStatus(NetStream.Publish.Start) */ virtual int start_flash_publish(int stream_id); +public: + /** + * expect a specified message, drop others util got specified one. + * @pmsg, user must free it. NULL if not success. + * @ppacket, store in the pmsg, user must never free it. NULL if not success. + * @remark, only when success, user can use and must free the pmsg/ppacket. + * for example: + SrsCommonMessage* msg = NULL; + SrsConnectAppResPacket* pkt = NULL; + if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + return ret; + } + // use pkt + * user should never recv message and convert it, use this method instead. + * if need to set timeout, use set timeout of SrsProtocol. + */ + template + int expect_message(SrsMessage** pmsg, T** ppacket) + { + return protocol->expect_message(pmsg, ppacket); + } private: virtual int identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsRtmpConnType& type, std::string& stream_name, double& duration); virtual int identify_fmle_publish_client(SrsFMLEStartPacket* req, SrsRtmpConnType& type, std::string& stream_name); diff --git a/trunk/src/rtmp/srs_protocol_rtmp_stack.cpp b/trunk/src/rtmp/srs_protocol_stack.cpp similarity index 99% rename from trunk/src/rtmp/srs_protocol_rtmp_stack.cpp rename to trunk/src/rtmp/srs_protocol_stack.cpp index b154bbf73..f4cb33fe5 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp_stack.cpp +++ b/trunk/src/rtmp/srs_protocol_stack.cpp @@ -21,7 +21,7 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include +#include #include #include diff --git a/trunk/src/rtmp/srs_protocol_rtmp_stack.hpp b/trunk/src/rtmp/srs_protocol_stack.hpp similarity index 95% rename from trunk/src/rtmp/srs_protocol_rtmp_stack.hpp rename to trunk/src/rtmp/srs_protocol_stack.hpp index 7ae8409fd..ddf55ecb7 100644 --- a/trunk/src/rtmp/srs_protocol_rtmp_stack.hpp +++ b/trunk/src/rtmp/srs_protocol_stack.hpp @@ -21,11 +21,11 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SRS_RTMP_PROTOCOL_RTMP_STACK_HPP -#define SRS_RTMP_PROTOCOL_RTMP_STACK_HPP +#ifndef SRS_RTMP_PROTOCOL_STACK_HPP +#define SRS_RTMP_PROTOCOL_STACK_HPP /* -#include +#include */ #include @@ -196,6 +196,63 @@ public: * @param stream_id, the stream id of packet to send over, 0 for control message. */ virtual int send_and_free_packet(SrsPacket* packet, int stream_id); +public: + /** + * expect a specified message, drop others util got specified one. + * @pmsg, user must free it. NULL if not success. + * @ppacket, store in the pmsg, user must never free it. NULL if not success. + * @remark, only when success, user can use and must free the pmsg/ppacket. + * for example: + SrsCommonMessage* msg = NULL; + SrsConnectAppResPacket* pkt = NULL; + if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { + return ret; + } + // use pkt + * user should never recv message and convert it, use this method instead. + * if need to set timeout, use set timeout of SrsProtocol. + */ + template + int expect_message(SrsMessage** pmsg, T** ppacket) + { + *pmsg = NULL; + *ppacket = NULL; + + int ret = ERROR_SUCCESS; + + while (true) { + SrsMessage* msg = NULL; + if ((ret = recv_message(&msg)) != ERROR_SUCCESS) { + srs_error("recv message failed. ret=%d", ret); + return ret; + } + srs_verbose("recv message success."); + + SrsPacket* packet = NULL; + if ((ret = decode_message(msg, &packet)) != ERROR_SUCCESS) { + srs_error("decode message failed. ret=%d", ret); + srs_freep(msg); + srs_freep(packet); + return ret; + } + + T* pkt = dynamic_cast(packet); + if (!pkt) { + srs_info("drop message(type=%d, size=%d, time=%"PRId64", sid=%d).", + msg->header.message_type, msg->header.payload_length, + msg->header.timestamp, msg->header.stream_id); + srs_freep(msg); + srs_freep(packet); + continue; + } + + *pmsg = msg; + *ppacket = pkt; + break; + } + + return ret; + } private: /** * send out the message, donot free it, the caller must free the param msg. @@ -1509,61 +1566,4 @@ protected: virtual int encode_packet(SrsStream* stream); }; -/** -* expect a specified message, drop others util got specified one. -* @pmsg, user must free it. NULL if not success. -* @ppacket, store in the pmsg, user must never free it. NULL if not success. -* @remark, only when success, user can use and must free the pmsg/ppacket. -* for example: - SrsCommonMessage* msg = NULL; - SrsConnectAppResPacket* pkt = NULL; - if ((ret = srs_rtmp_expect_message(protocol, &msg, &pkt)) != ERROR_SUCCESS) { - return ret; - } - // use pkt -* user should never recv message and convert it, use this method instead. -* if need to set timeout, use set timeout of SrsProtocol. -*/ -template -int srs_rtmp_expect_message(SrsProtocol* protocol, SrsMessage** pmsg, T** ppacket) -{ - *pmsg = NULL; - *ppacket = NULL; - - int ret = ERROR_SUCCESS; - - while (true) { - SrsMessage* msg = NULL; - if ((ret = protocol->recv_message(&msg)) != ERROR_SUCCESS) { - srs_error("recv message failed. ret=%d", ret); - return ret; - } - srs_verbose("recv message success."); - - SrsPacket* packet = NULL; - if ((ret = protocol->decode_message(msg, &packet)) != ERROR_SUCCESS) { - srs_error("decode message failed. ret=%d", ret); - srs_freep(msg); - srs_freep(packet); - return ret; - } - - T* pkt = dynamic_cast(packet); - if (!pkt) { - srs_info("drop message(type=%d, size=%d, time=%"PRId64", sid=%d).", - msg->header.message_type, msg->header.payload_length, - msg->header.timestamp, msg->header.stream_id); - srs_freep(msg); - srs_freep(packet); - continue; - } - - *pmsg = msg; - *ppacket = pkt; - break; - } - - return ret; -} - #endif diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index c5a245201..a759b5e10 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -42,8 +42,8 @@ file ..\rtmp\srs_protocol_msg_array.cpp, ..\rtmp\srs_protocol_rtmp.hpp, ..\rtmp\srs_protocol_rtmp.cpp, - ..\rtmp\srs_protocol_rtmp_stack.hpp, - ..\rtmp\srs_protocol_rtmp_stack.cpp, + ..\rtmp\srs_protocol_stack.hpp, + ..\rtmp\srs_protocol_stack.cpp, ..\rtmp\srs_protocol_utility.hpp, ..\rtmp\srs_protocol_utility.cpp, app readonly separator, diff --git a/trunk/src/utest/srs_utest_protocol.cpp b/trunk/src/utest/srs_utest_protocol.cpp index 4183ab77a..d522094f8 100644 --- a/trunk/src/utest/srs_utest_protocol.cpp +++ b/trunk/src/utest/srs_utest_protocol.cpp @@ -28,10 +28,11 @@ using namespace std; #include #include #include -#include +#include #include #include #include +#include MockEmptyIO::MockEmptyIO() { @@ -5316,3 +5317,74 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow) EXPECT_TRUE(0x3456 == spkt->event_data); } } + +VOID TEST(ProtocolRTMPTest, RTMPRequest) +{ + SrsRequest req; + + req.stream = "livestream"; + srs_discovery_tc_url("rtmp://std.ossrs.net/live", + req.schema, req.host, req.vhost, req.app, req.port); + req.strip(); + EXPECT_STREQ("rtmp", req.schema.c_str()); + EXPECT_STREQ("std.ossrs.net", req.host.c_str()); + EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); + EXPECT_STREQ("live", req.app.c_str()); + EXPECT_STREQ("1935", req.port.c_str()); + + req.stream = "livestream"; + srs_discovery_tc_url("rtmp://s td.os srs.n et/li v e", + req.schema, req.host, req.vhost, req.app, req.port); + req.strip(); + EXPECT_STREQ("rtmp", req.schema.c_str()); + EXPECT_STREQ("std.ossrs.net", req.host.c_str()); + EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); + EXPECT_STREQ("live", req.app.c_str()); + EXPECT_STREQ("1935", req.port.c_str()); + + req.stream = "livestream"; + srs_discovery_tc_url("rtmp://s\ntd.o\rssrs.ne\nt/li\nve", + req.schema, req.host, req.vhost, req.app, req.port); + req.strip(); + EXPECT_STREQ("rtmp", req.schema.c_str()); + EXPECT_STREQ("std.ossrs.net", req.host.c_str()); + EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); + EXPECT_STREQ("live", req.app.c_str()); + EXPECT_STREQ("1935", req.port.c_str()); + + req.stream = "livestream"; + srs_discovery_tc_url("rtmp://std.ossrs.net/live ", + req.schema, req.host, req.vhost, req.app, req.port); + req.strip(); + EXPECT_STREQ("rtmp", req.schema.c_str()); + EXPECT_STREQ("std.ossrs.net", req.host.c_str()); + EXPECT_STREQ("std.ossrs.net", req.vhost.c_str()); + EXPECT_STREQ("live", req.app.c_str()); + EXPECT_STREQ("1935", req.port.c_str()); + + EXPECT_TRUE(NULL == req.args); + SrsRequest req1; + req1.args = SrsAmf0Any::object(); + req.update_auth(&req1); + EXPECT_TRUE(NULL != req.args); + EXPECT_TRUE(req1.args != req.args); +} + +VOID TEST(ProtocolRTMPTest, RTMPHandshakeBytes) +{ + MockBufferIO bio; + SrsHandshakeBytes bytes; + + char hs[3073]; + bio.in_buffer.append(hs, sizeof(hs)); + bio.in_buffer.append(hs, sizeof(hs)); + + EXPECT_TRUE(ERROR_SUCCESS == bytes.read_c0c1(&bio)); + EXPECT_TRUE(bytes.c0c1 != NULL); + + EXPECT_TRUE(ERROR_SUCCESS == bytes.read_c2(&bio)); + EXPECT_TRUE(bytes.c2 != NULL); + + EXPECT_TRUE(ERROR_SUCCESS == bytes.read_s0s1s2(&bio)); + EXPECT_TRUE(bytes.s0s1s2 != NULL); +}