Skip to content

Commit

Permalink
Threads-Hybrid: Enable RTC play API with bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 26, 2021
1 parent 9f4fbdb commit 40e59ef
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 19 deletions.
10 changes: 0 additions & 10 deletions trunk/src/app/srs_app_hybrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,6 @@ void SrsHybridServer::stop()
}
}

SrsServerAdapter* SrsHybridServer::srs()
{
for (vector<ISrsHybridServer*>::iterator it = servers.begin(); it != servers.end(); ++it) {
if (dynamic_cast<SrsServerAdapter*>(*it)) {
return dynamic_cast<SrsServerAdapter*>(*it);
}
}
return NULL;
}

SrsFastTimer* SrsHybridServer::timer()
{
return timer_;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_hybrid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ISrsHybridServer
// The hybrid server manager.
class SrsHybridServer : public ISrsFastTimer
{
friend class SrsApiServer;
private:
std::vector<ISrsHybridServer*> servers;
SrsFastTimer* timer_;
Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion trunk/src/app/srs_app_rtc_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
20 changes: 18 additions & 2 deletions trunk/src/app/srs_app_rtc_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,36 @@

#include <srs_core.hpp>

#include <string>

#include <srs_http_stack.hpp>

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);
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_rtc_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
31 changes: 27 additions & 4 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ using namespace std;
#include <srs_app_coworkers.hpp>
#include <srs_app_gb28181.hpp>
#include <srs_app_gb28181_sip.hpp>
#include <srs_app_rtc_server.hpp>

std::string srs_listener_type2string(SrsListenerType type)
{
Expand Down Expand Up @@ -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");
//}
Expand All @@ -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<ISrsHybridServer*> servers = _srs_hybrid->servers;
for (vector<ISrsHybridServer*>::iterator it = servers.begin(); it != servers.end(); ++it) {
RtcServerAdapter* adapter = dynamic_cast<RtcServerAdapter*>(*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;
Expand Down
9 changes: 8 additions & 1 deletion trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <srs_app_gb28181_sip.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_hybrid.hpp>
#include <srs_app_rtc_api.hpp>

class SrsServer;
class SrsHttpServeMux;
Expand Down Expand Up @@ -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_;
Expand All @@ -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:
Expand Down

0 comments on commit 40e59ef

Please sign in to comment.