1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

rename rtmp_stack to stack. remove the global templte function to member function.

This commit is contained in:
winlin 2014-07-12 08:47:47 +08:00
parent f7922e3823
commit 88c94193a3
19 changed files with 212 additions and 108 deletions

2
trunk/configure vendored
View file

@ -455,7 +455,7 @@ KERNEL_OBJS="${MODULE_OBJS[@]}"
MODULE_ID="RTMP" MODULE_ID="RTMP"
MODULE_DEPENDS=("CORE" "KERNEL") MODULE_DEPENDS=("CORE" "KERNEL")
ModuleLibIncs=(${SRS_OBJS} ${LibSSLRoot}) 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") "srs_protocol_handshake" "srs_protocol_utility" "srs_protocol_msg_array")
RTMP_INCS="src/rtmp"; MODULE_DIR=${RTMP_INCS} . auto/modules.sh RTMP_INCS="src/rtmp"; MODULE_DIR=${RTMP_INCS} . auto/modules.sh
RTMP_OBJS="${MODULE_OBJS[@]}" RTMP_OBJS="${MODULE_OBJS[@]}"

View file

@ -31,7 +31,7 @@ using namespace std;
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
@ -100,8 +100,6 @@ int SrsBandwidth::do_bandwidth_check()
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
SrsProtocol* protocol = rtmp->get_protocol();
int play_duration_ms = 3000; int play_duration_ms = 3000;
int play_interval_ms = 0; int play_interval_ms = 0;
int play_actual_duration_ms = 0; int play_actual_duration_ms = 0;
@ -160,7 +158,7 @@ int SrsBandwidth::do_bandwidth_check()
while (true) { while (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
// info level to ignore and return success. // info level to ignore and return success.
srs_info("expect final message failed. ret=%d", ret); srs_info("expect final message failed. ret=%d", ret);
return ERROR_SUCCESS; return ERROR_SUCCESS;
@ -186,8 +184,6 @@ int SrsBandwidth::check_play(
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
SrsProtocol* protocol = rtmp->get_protocol();
if (true) { if (true) {
// send start play command to client // send start play command to client
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play(); SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_play();
@ -206,7 +202,7 @@ int SrsBandwidth::check_play(
// recv client's starting play response // recv client's starting play response
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect bandwidth message failed. ret=%d", ret); srs_error("expect bandwidth message failed. ret=%d", ret);
return ret; return ret;
} }
@ -287,7 +283,7 @@ int SrsBandwidth::check_play(
// recv client's stop play response. // recv client's stop play response.
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect bandwidth message failed. ret=%d", ret); srs_error("expect bandwidth message failed. ret=%d", ret);
return ret; return ret;
} }
@ -310,8 +306,6 @@ int SrsBandwidth::check_publish(
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
SrsProtocol* protocol = rtmp->get_protocol();
if (true) { if (true) {
// notify client to start publish // notify client to start publish
SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_publish(); SrsBandwidthPacket* pkt = SrsBandwidthPacket::create_start_publish();
@ -330,7 +324,7 @@ int SrsBandwidth::check_publish(
// read client's notification of starting publish // read client's notification of starting publish
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect bandwidth message failed. ret=%d", ret); srs_error("expect bandwidth message failed. ret=%d", ret);
return ret; return ret;
} }
@ -398,7 +392,7 @@ int SrsBandwidth::check_publish(
// recv client's stop publish response. // recv client's stop publish response.
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = rtmp->expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect bandwidth message failed. ret=%d", ret); srs_error("expect bandwidth message failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -32,7 +32,7 @@ using namespace std;
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_app_source.hpp> #include <srs_app_source.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_kernel_stream.hpp> #include <srs_kernel_stream.hpp>

View file

@ -37,7 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_app_socket.hpp> #include <srs_app_socket.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_app_source.hpp> #include <srs_app_source.hpp>
#include <srs_app_pithy_print.hpp> #include <srs_app_pithy_print.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>

View file

@ -31,7 +31,7 @@ using namespace std;
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_app_pithy_print.hpp> #include <srs_app_pithy_print.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_app_ffmpeg.hpp> #include <srs_app_ffmpeg.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>

View file

@ -37,7 +37,7 @@ using namespace std;
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_app_pithy_print.hpp> #include <srs_app_pithy_print.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#ifdef SRS_AUTO_FFMPEG #ifdef SRS_AUTO_FFMPEG

View file

@ -36,7 +36,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_app_pithy_print.hpp> #include <srs_app_pithy_print.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_app_kbps.hpp> #include <srs_app_kbps.hpp>

View file

@ -37,7 +37,7 @@ using namespace std;
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_kernel_codec.hpp> #include <srs_kernel_codec.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_app_config.hpp> #include <srs_app_config.hpp>
#include <srs_app_source.hpp> #include <srs_app_source.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>

View file

@ -33,7 +33,7 @@ using namespace std;
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp> #include <srs_kernel_log.hpp>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_app_source.hpp> #include <srs_app_source.hpp>
#include <srs_app_server.hpp> #include <srs_app_server.hpp>

View file

@ -28,7 +28,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
using namespace std; using namespace std;
#include <srs_kernel_log.hpp> #include <srs_kernel_log.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_kernel_codec.hpp> #include <srs_kernel_codec.hpp>

View file

@ -35,7 +35,7 @@ using namespace std;
#include <srs_kernel_log.hpp> #include <srs_kernel_log.hpp>
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
#include <srs_kernel_stream.hpp> #include <srs_kernel_stream.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>

View file

@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <stdlib.h> #include <stdlib.h>
#include <srs_protocol_rtmp.hpp> #include <srs_protocol_rtmp.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_kernel_error.hpp> #include <srs_kernel_error.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
@ -345,7 +345,7 @@ int SrsBandCheckClient::expect_start_play()
// expect connect _result // expect connect _result
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect bandcheck start play message failed. ret=%d", ret); srs_error("expect bandcheck start play message failed. ret=%d", ret);
return ret; return ret;
} }
@ -382,7 +382,7 @@ int SrsBandCheckClient::expect_stop_play()
while (true) { while (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect stop play message failed. ret=%d", ret); srs_error("expect stop play message failed. ret=%d", ret);
return ret; return ret;
} }
@ -419,7 +419,7 @@ int SrsBandCheckClient::expect_start_pub()
while (true) { while (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect start pub message failed. ret=%d", ret); srs_error("expect start pub message failed. ret=%d", ret);
return ret; return ret;
} }
@ -489,7 +489,7 @@ int SrsBandCheckClient::expect_stop_pub()
SrsMessage* msg; SrsMessage* msg;
SrsBandwidthPacket* pkt; SrsBandwidthPacket* pkt;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(this->protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
return ret; return ret;
} }
SrsAutoFree(SrsMessage, msg); SrsAutoFree(SrsMessage, msg);
@ -508,7 +508,7 @@ int SrsBandCheckClient::expect_finished()
while (true) { while (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsBandwidthPacket* pkt = NULL; SrsBandwidthPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsBandwidthPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsBandwidthPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect finished message failed. ret=%d", ret); srs_error("expect finished message failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_msg_array.hpp> #include <srs_protocol_msg_array.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
SrsSharedPtrMessageArray::SrsSharedPtrMessageArray(int _size) SrsSharedPtrMessageArray::SrsSharedPtrMessageArray(int _size)
{ {

View file

@ -29,7 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_io.hpp> #include <srs_protocol_io.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_protocol_handshake.hpp> #include <srs_protocol_handshake.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#include <srs_kernel_stream.hpp> #include <srs_kernel_stream.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
@ -140,6 +140,7 @@ string SrsRequest::get_stream_url()
void SrsRequest::strip() void SrsRequest::strip()
{ {
// remove the unsupported chars in names. // remove the unsupported chars in names.
host = srs_string_remove(host, "/ \n\r\t");
vhost = srs_string_remove(vhost, "/ \n\r\t"); vhost = srs_string_remove(vhost, "/ \n\r\t");
app = srs_string_remove(app, " \n\r\t"); app = srs_string_remove(app, " \n\r\t");
stream = srs_string_remove(stream, " \n\r\t"); stream = srs_string_remove(stream, " \n\r\t");
@ -338,11 +339,6 @@ SrsRtmpClient::~SrsRtmpClient()
srs_freep(hs_bytes); srs_freep(hs_bytes);
} }
SrsProtocol* SrsRtmpClient::get_protocol()
{
return protocol;
}
void SrsRtmpClient::set_recv_timeout(int64_t timeout_us) void SrsRtmpClient::set_recv_timeout(int64_t timeout_us)
{ {
protocol->set_recv_timeout(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 // expect connect _result
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsConnectAppResPacket* pkt = NULL; SrsConnectAppResPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsConnectAppResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsConnectAppResPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect connect app response message failed. ret=%d", ret); srs_error("expect connect app response message failed. ret=%d", ret);
return ret; return ret;
} }
@ -540,7 +536,7 @@ int SrsRtmpClient::create_stream(int& stream_id)
if (true) { if (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsCreateStreamResPacket* pkt = NULL; SrsCreateStreamResPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsCreateStreamResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsCreateStreamResPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect create stream response message failed. ret=%d", ret); srs_error("expect create stream response message failed. ret=%d", ret);
return ret; return ret;
} }
@ -674,7 +670,7 @@ int SrsRtmpClient::fmle_publish(string stream, int& stream_id)
if (true) { if (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsCreateStreamResPacket* pkt = NULL; SrsCreateStreamResPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsCreateStreamResPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsCreateStreamResPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect create stream response message failed. ret=%d", ret); srs_error("expect create stream response message failed. ret=%d", ret);
return ret; return ret;
} }
@ -795,7 +791,7 @@ int SrsRtmpServer::connect_app(SrsRequest* req)
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsConnectAppPacket* pkt = NULL; SrsConnectAppPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsConnectAppPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsConnectAppPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("expect connect app message failed. ret=%d", ret); srs_error("expect connect app message failed. ret=%d", ret);
return ret; return ret;
} }
@ -1189,7 +1185,7 @@ int SrsRtmpServer::start_fmle_publish(int stream_id)
if (true) { if (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsFMLEStartPacket* pkt = NULL; SrsFMLEStartPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsFMLEStartPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsFMLEStartPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("recv FCPublish message failed. ret=%d", ret); srs_error("recv FCPublish message failed. ret=%d", ret);
return ret; return ret;
} }
@ -1215,7 +1211,7 @@ int SrsRtmpServer::start_fmle_publish(int stream_id)
if (true) { if (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsCreateStreamPacket* pkt = NULL; SrsCreateStreamPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsCreateStreamPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsCreateStreamPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("recv createStream message failed. ret=%d", ret); srs_error("recv createStream message failed. ret=%d", ret);
return ret; return ret;
} }
@ -1240,7 +1236,7 @@ int SrsRtmpServer::start_fmle_publish(int stream_id)
if (true) { if (true) {
SrsMessage* msg = NULL; SrsMessage* msg = NULL;
SrsPublishPacket* pkt = NULL; SrsPublishPacket* pkt = NULL;
if ((ret = srs_rtmp_expect_message<SrsPublishPacket>(protocol, &msg, &pkt)) != ERROR_SUCCESS) { if ((ret = expect_message<SrsPublishPacket>(&msg, &pkt)) != ERROR_SUCCESS) {
srs_error("recv publish message failed. ret=%d", ret); srs_error("recv publish message failed. ret=%d", ret);
return ret; return ret;
} }

View file

@ -32,6 +32,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string> #include <string>
#include <srs_protocol_stack.hpp>
class SrsProtocol; class SrsProtocol;
class ISrsProtocolReaderWriter; class ISrsProtocolReaderWriter;
class ISrsMessage; class ISrsMessage;
@ -171,7 +173,6 @@ public:
SrsRtmpClient(ISrsProtocolReaderWriter* skt); SrsRtmpClient(ISrsProtocolReaderWriter* skt);
virtual ~SrsRtmpClient(); virtual ~SrsRtmpClient();
public: public:
virtual SrsProtocol* get_protocol();
virtual void set_recv_timeout(int64_t timeout_us); virtual void set_recv_timeout(int64_t timeout_us);
virtual void set_send_timeout(int64_t timeout_us); virtual void set_send_timeout(int64_t timeout_us);
virtual int64_t get_recv_bytes(); virtual int64_t get_recv_bytes();
@ -199,6 +200,27 @@ public:
// FMLE publish schema: // FMLE publish schema:
// connect-app => FMLE publish // connect-app => FMLE publish
virtual int fmle_publish(std::string stream, int& stream_id); 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<SrsConnectAppResPacket>(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<class T>
int expect_message(SrsMessage** pmsg, T** ppacket)
{
return protocol->expect_message<T>(pmsg, ppacket);
}
}; };
/** /**
@ -206,7 +228,6 @@ public:
* a high level protocol, media stream oriented services, * a high level protocol, media stream oriented services,
* such as connect to vhost/app, play stream, get audio/video data. * such as connect to vhost/app, play stream, get audio/video data.
*/ */
// TODO: FIXME: rename to SrsRtmpServer
class SrsRtmpServer class SrsRtmpServer
{ {
private: private:
@ -294,6 +315,27 @@ public:
* onStatus(NetStream.Publish.Start) * onStatus(NetStream.Publish.Start)
*/ */
virtual int start_flash_publish(int stream_id); 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<SrsConnectAppResPacket>(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<class T>
int expect_message(SrsMessage** pmsg, T** ppacket)
{
return protocol->expect_message<T>(pmsg, ppacket);
}
private: private:
virtual int identify_create_stream_client(SrsCreateStreamPacket* req, int stream_id, SrsRtmpConnType& type, std::string& stream_name, double& duration); 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); virtual int identify_fmle_publish_client(SrsFMLEStartPacket* req, SrsRtmpConnType& type, std::string& stream_name);

View file

@ -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. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_kernel_log.hpp> #include <srs_kernel_log.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>

View file

@ -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. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef SRS_RTMP_PROTOCOL_RTMP_STACK_HPP #ifndef SRS_RTMP_PROTOCOL_STACK_HPP
#define SRS_RTMP_PROTOCOL_RTMP_STACK_HPP #define SRS_RTMP_PROTOCOL_STACK_HPP
/* /*
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
*/ */
#include <srs_core.hpp> #include <srs_core.hpp>
@ -196,6 +196,63 @@ public:
* @param stream_id, the stream id of packet to send over, 0 for control message. * @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); 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<SrsConnectAppResPacket>(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<class T>
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<T*>(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: private:
/** /**
* send out the message, donot free it, the caller must free the param msg. * 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); 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<SrsConnectAppResPacket>(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<class T>
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<T*>(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 #endif

View file

@ -42,8 +42,8 @@ file
..\rtmp\srs_protocol_msg_array.cpp, ..\rtmp\srs_protocol_msg_array.cpp,
..\rtmp\srs_protocol_rtmp.hpp, ..\rtmp\srs_protocol_rtmp.hpp,
..\rtmp\srs_protocol_rtmp.cpp, ..\rtmp\srs_protocol_rtmp.cpp,
..\rtmp\srs_protocol_rtmp_stack.hpp, ..\rtmp\srs_protocol_stack.hpp,
..\rtmp\srs_protocol_rtmp_stack.cpp, ..\rtmp\srs_protocol_stack.cpp,
..\rtmp\srs_protocol_utility.hpp, ..\rtmp\srs_protocol_utility.hpp,
..\rtmp\srs_protocol_utility.cpp, ..\rtmp\srs_protocol_utility.cpp,
app readonly separator, app readonly separator,

View file

@ -28,10 +28,11 @@ using namespace std;
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
#include <srs_protocol_utility.hpp> #include <srs_protocol_utility.hpp>
#include <srs_protocol_msg_array.hpp> #include <srs_protocol_msg_array.hpp>
#include <srs_protocol_rtmp_stack.hpp> #include <srs_protocol_stack.hpp>
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
#include <srs_app_st.hpp> #include <srs_app_st.hpp>
#include <srs_protocol_amf0.hpp> #include <srs_protocol_amf0.hpp>
#include <srs_protocol_rtmp.hpp>
MockEmptyIO::MockEmptyIO() MockEmptyIO::MockEmptyIO()
{ {
@ -5316,3 +5317,74 @@ VOID TEST(ProtocolStackTest, ProtocolPingFlow)
EXPECT_TRUE(0x3456 == spkt->event_data); 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);
}