diff --git a/trunk/src/app/srs_app_hybrid.cpp b/trunk/src/app/srs_app_hybrid.cpp index fdbf5a8320..659cab107c 100644 --- a/trunk/src/app/srs_app_hybrid.cpp +++ b/trunk/src/app/srs_app_hybrid.cpp @@ -246,16 +246,6 @@ void SrsHybridServer::stop() } } -SrsServerAdapter* SrsHybridServer::srs() -{ - for (vector::iterator it = servers.begin(); it != servers.end(); ++it) { - if (dynamic_cast(*it)) { - return dynamic_cast(*it); - } - } - return NULL; -} - SrsFastTimer* SrsHybridServer::timer() { return timer_; diff --git a/trunk/src/app/srs_app_hybrid.hpp b/trunk/src/app/srs_app_hybrid.hpp index 77b774b6ce..292284d3d7 100644 --- a/trunk/src/app/srs_app_hybrid.hpp +++ b/trunk/src/app/srs_app_hybrid.hpp @@ -51,6 +51,7 @@ class ISrsHybridServer // The hybrid server manager. class SrsHybridServer : public ISrsFastTimer { + friend class SrsApiServer; private: std::vector servers; SrsFastTimer* timer_; @@ -65,7 +66,6 @@ class SrsHybridServer : public ISrsFastTimer virtual srs_error_t run(); virtual void stop(); public: - virtual SrsServerAdapter* srs(); SrsFastTimer* timer(); // interface ISrsFastTimer private: diff --git a/trunk/src/app/srs_app_rtc_api.cpp b/trunk/src/app/srs_app_rtc_api.cpp index fbe278b88a..353583b805 100644 --- a/trunk/src/app/srs_app_rtc_api.cpp +++ b/trunk/src/app/srs_app_rtc_api.cpp @@ -38,7 +38,15 @@ using namespace std; uint32_t SrsGoApiRtcPlay::ssrc_num = 0; -SrsGoApiRtcPlay::SrsGoApiRtcPlay(SrsRtcServer* server) +ISrsRtcServer::ISrsRtcServer() +{ +} + +ISrsRtcServer::~ISrsRtcServer() +{ +} + +SrsGoApiRtcPlay::SrsGoApiRtcPlay(ISrsRtcServer* server) { server_ = server; } diff --git a/trunk/src/app/srs_app_rtc_api.hpp b/trunk/src/app/srs_app_rtc_api.hpp index c7bc6596ba..50f2bba95f 100644 --- a/trunk/src/app/srs_app_rtc_api.hpp +++ b/trunk/src/app/srs_app_rtc_api.hpp @@ -26,20 +26,36 @@ #include +#include + #include class SrsRtcServer; class SrsRequest; class SrsSdp; +class SrsRtcConnection; + +class ISrsRtcServer +{ +public: + ISrsRtcServer(); + virtual ~ISrsRtcServer(); +public: + virtual srs_error_t create_session( + SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, + bool publish, bool dtls, bool srtp, + SrsRtcConnection** psession + ) = 0; +}; class SrsGoApiRtcPlay : public ISrsHttpHandler { public: static uint32_t ssrc_num; private: - SrsRtcServer* server_; + ISrsRtcServer* server_; public: - SrsGoApiRtcPlay(SrsRtcServer* server); + SrsGoApiRtcPlay(ISrsRtcServer* server); virtual ~SrsGoApiRtcPlay(); public: virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); diff --git a/trunk/src/app/srs_app_rtc_server.hpp b/trunk/src/app/srs_app_rtc_server.hpp index 324f384b4a..16ea2bd890 100644 --- a/trunk/src/app/srs_app_rtc_server.hpp +++ b/trunk/src/app/srs_app_rtc_server.hpp @@ -132,6 +132,7 @@ class SrsRtcServer : public ISrsUdpMuxHandler, public ISrsFastTimer, public ISrs // The RTC server adapter. class RtcServerAdapter : public ISrsHybridServer { + friend class SrsApiServer; private: SrsRtcServer* rtc; public: diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index bbfdd22ede..002d37f587 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -55,6 +55,7 @@ using namespace std; #include #include #include +#include std::string srs_listener_type2string(SrsListenerType type) { @@ -1961,10 +1962,10 @@ srs_error_t SrsApiServer::listen_api() srs_error_t err = srs_success; // TODO: FIXME: Implements it. - //if ((err = http_api_mux_->handle("/rtc/v1/play/", new SrsGoApiRtcPlay(this))) != srs_success) { - // return srs_error_wrap(err, "handle play"); - //} - // + if ((err = http_api_mux_->handle("/rtc/v1/play/", new SrsGoApiRtcPlay(this))) != srs_success) { + return srs_error_wrap(err, "handle play"); + } + //if ((err = http_api_mux_->handle("/rtc/v1/publish/", new SrsGoApiRtcPublish(this))) != srs_success) { // return srs_error_wrap(err, "handle publish"); //} @@ -1979,6 +1980,28 @@ srs_error_t SrsApiServer::listen_api() return err; } +srs_error_t SrsApiServer::create_session( + SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, + bool publish, bool dtls, bool srtp, + SrsRtcConnection** psession +) { + srs_error_t err = srs_success; + + vector servers = _srs_hybrid->servers; + for (vector::iterator it = servers.begin(); it != servers.end(); ++it) { + RtcServerAdapter* adapter = dynamic_cast(*it); + if (!adapter) { + continue; + } + + // TODO: FIXME: Should notify thread by thread-slot. + return adapter->rtc->create_session(req, remote_sdp, local_sdp, mock_eip, + publish, dtls, srtp, psession); + } + + return err; +} + srs_error_t SrsApiServer::start(void* arg) { SrsApiServer* api = (SrsApiServer*)arg; diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 54a1411181..9afbcf1697 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -40,6 +40,7 @@ #include #include #include +#include class SrsServer; class SrsHttpServeMux; @@ -415,7 +416,7 @@ class SrsServerAdapter : public ISrsHybridServer }; // The HTTP API server. -class SrsApiServer : public ISrsTcpMuxHandler, public ISrsResourceManager +class SrsApiServer : public ISrsTcpMuxHandler, public ISrsResourceManager, public ISrsRtcServer { private: SrsBufferListener* http_; @@ -437,6 +438,12 @@ class SrsApiServer : public ISrsTcpMuxHandler, public ISrsResourceManager private: virtual srs_error_t http_handle(); srs_error_t listen_api(); +private: + virtual srs_error_t create_session( + SrsRequest* req, const SrsSdp& remote_sdp, SrsSdp& local_sdp, const std::string& mock_eip, + bool publish, bool dtls, bool srtp, + SrsRtcConnection** psession + ); public: static srs_error_t start(void* arg); private: