Skip to content

Commit

Permalink
Threads-Hybrid: Merge api to master thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 26, 2021
1 parent 50f03ad commit c8f2ff0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 44 deletions.
39 changes: 13 additions & 26 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,18 @@ srs_error_t SrsApiServer::initialize()
return srs_error_wrap(err, "listen api");
}

if ((err = listen_http_api()) != srs_success) {
return srs_error_wrap(err, "http api listen");
}

if ((err = listen_https_api()) != srs_success) {
return srs_error_wrap(err, "https api listen");
}

if ((err = conn_manager_->start()) != srs_success) {
return srs_error_wrap(err, "connection manager");
}

return err;
}

Expand Down Expand Up @@ -2005,30 +2017,5 @@ srs_error_t SrsApiServer::create_session(
return err;
}

srs_error_t SrsApiServer::start(void* arg)
{
SrsApiServer* api = (SrsApiServer*)arg;
return api->do_start();
}

srs_error_t SrsApiServer::do_start()
{
srs_error_t err = srs_success;

if ((err = listen_http_api()) != srs_success) {
return srs_error_wrap(err, "http api listen");
}

if ((err = listen_https_api()) != srs_success) {
return srs_error_wrap(err, "https api listen");
}

if ((err = conn_manager_->start()) != srs_success) {
return srs_error_wrap(err, "connection manager");
}

srs_usleep(SRS_UTIME_NO_TIMEOUT);

return err;
}
SrsApiServer* _srs_api = new SrsApiServer();

7 changes: 3 additions & 4 deletions trunk/src/app/srs_app_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,11 @@ class SrsApiServer : public ISrsTcpMuxHandler, public ISrsResourceManager, publi
bool publish, bool dtls, bool srtp,
SrsRtcConnection** psession
);
public:
static srs_error_t start(void* arg);
private:
srs_error_t do_start();
};

// It's only used in master/srs thread.
extern SrsApiServer* _srs_api;

// The RTC create session information.
struct SrsThreadMessageRtcCreateSession
{
Expand Down
7 changes: 6 additions & 1 deletion trunk/src/app/srs_app_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_app_server.hpp>

#include <unistd.h>
#include <fcntl.h>
Expand Down Expand Up @@ -755,6 +756,10 @@ srs_error_t SrsThreadPool::initialize()
return srs_error_wrap(err, "acquire pid file");
}

if ((err = _srs_api->initialize()) != srs_success) {
return srs_error_wrap(err, "init api server");
}

// Initialize the master primordial thread.
SrsThreadEntry* entry = (SrsThreadEntry*)entry_;
#ifndef SRS_OSX
Expand Down Expand Up @@ -976,7 +981,7 @@ srs_error_t SrsThreadPool::run()
}
}

sleep(1);
srs_usleep(1 * SRS_UTIME_SECONDS);
}

// In normal state, gather status and log it.
Expand Down
13 changes: 0 additions & 13 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,14 +484,6 @@ srs_error_t run_in_thread_pool()
return srs_error_wrap(err, "init thread pool");
}

// Create and initialize the API server.
SrsApiServer* api = new SrsApiServer();
SrsAutoFree(SrsApiServer, api);

if ((err = api->initialize()) != srs_success) {
return srs_error_wrap(err, "init api server");
}

// After all init(log, async log manager, thread pool), now we can start to
// run the log manager thread.
if ((err = _srs_thread_pool->execute("log", SrsAsyncLogManager::start, _srs_async_log)) != srs_success) {
Expand Down Expand Up @@ -522,11 +514,6 @@ srs_error_t run_in_thread_pool()
}
}

// Start the api server thread, for server stat and RTC api, etc.
if ((err = _srs_thread_pool->execute("api", SrsApiServer::start, api)) != srs_success) {
return srs_error_wrap(err, "start api server thread");
}

// Start a number of hybrid service threads.
int hybrids = _srs_config->get_threads_hybrids();
for (int stream_index = 0; stream_index < hybrids; stream_index++) {
Expand Down

0 comments on commit c8f2ff0

Please sign in to comment.