diff --git a/README.md b/README.md
index 3b44ac7c6a2..dc62dccfcbe 100755
--- a/README.md
+++ b/README.md
@@ -29,10 +29,10 @@ or [Chinese](https://ossrs.net/lts/zh-cn/docs/v5/doc/getting-started). We highly
```bash
docker run --rm -it -p 1935:1935 -p 1985:1985 -p 8080:8080 \
- -p 8000:8000/udp -p 10080:10080/udp ossrs/srs:5
+ -p 8000:8000/udp -p 10080:10080/udp ossrs/srs:6
```
-> Tips: If you're in China, use this image `registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5` for faster speed.
+> Tips: If you're in China, use this image `registry.cn-hangzhou.aliyuncs.com/ossrs/srs:6` for faster speed.
Open [http://localhost:8080/](http://localhost:8080/) to verify, and then stream using the following
[FFmpeg](https://ffmpeg.org/download.html) command:
diff --git a/trunk/configure b/trunk/configure
index 6bfc4c2faa7..b8cd215e4aa 100755
--- a/trunk/configure
+++ b/trunk/configure
@@ -250,7 +250,9 @@ MODULE_FILES=("srs_kernel_error" "srs_kernel_log" "srs_kernel_buffer"
"srs_kernel_utility" "srs_kernel_flv" "srs_kernel_codec" "srs_kernel_io"
"srs_kernel_consts" "srs_kernel_aac" "srs_kernel_mp3" "srs_kernel_ts" "srs_kernel_ps"
"srs_kernel_stream" "srs_kernel_balance" "srs_kernel_mp4" "srs_kernel_file"
- "srs_kernel_kbps" "srs_kernel_rtc_rtp" "srs_kernel_rtc_rtcp" "srs_kernel_packet")
+ "srs_kernel_kbps" "srs_kernel_rtc_rtp" "srs_kernel_rtc_rtcp" "srs_kernel_packet"
+ "srs_kernel_uuid" "srs_kernel_st" "srs_kernel_factory" "srs_kernel_hourglass"
+ "srs_kernel_pithy_print" "srs_kernel_rtc_queue" "srs_kernel_resource")
KERNEL_INCS="src/kernel"; MODULE_DIR=${KERNEL_INCS} . $SRS_WORKDIR/auto/modules.sh
KERNEL_OBJS="${MODULE_OBJS[@]}"
#
@@ -260,7 +262,7 @@ MODULE_DEPENDS=("CORE" "KERNEL")
ModuleLibIncs=(${SRS_OBJS} ${LibSTRoot} ${LibSSLRoot})
MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_conn" "srs_protocol_rtmp_handshake"
"srs_protocol_rtmp_stack" "srs_protocol_utility" "srs_protocol_rtmp_msg_array" "srs_protocol_stream"
- "srs_protocol_raw_avc" "srs_protocol_http_stack" "srs_protocol_kbps" "srs_protocol_json"
+ "srs_protocol_raw_avc" "srs_protocol_http_stack" "srs_protocol_json"
"srs_protocol_format" "srs_protocol_log" "srs_protocol_st" "srs_protocol_http_client"
"srs_protocol_http_conn" "srs_protocol_rtmp_conn" "srs_protocol_protobuf"
"srs_protocol_http_stack_llhttp" "srs_protocol_http_stack_llhttpapi"
@@ -268,7 +270,7 @@ MODULE_FILES=("srs_protocol_amf0" "srs_protocol_io" "srs_protocol_conn" "srs_pro
# Always include SRT protocol
MODULE_FILES+=("srs_protocol_srt")
ModuleLibIncs+=(${LibSRTRoot})
-MODULE_FILES+=("srs_protocol_rtc_stun" "srs_protocol_rtp")
+MODULE_FILES+=("srs_protocol_rtc_stun" "srs_protocol_rtp" "srs_protocol_sdp")
if [[ $SRS_RTSP == YES ]]; then
MODULE_FILES+=("srs_protocol_rtsp_stack")
fi
@@ -286,22 +288,22 @@ fi
if [[ $SRS_FFMPEG_FIT == YES ]]; then
ModuleLibIncs+=("${LibFfmpegRoot[*]}")
fi
-MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_source"
+MODULE_FILES=("srs_app_server" "srs_app_rtmp_conn" "srs_app_rtmp_source"
"srs_app_refer" "srs_app_hls" "srs_app_forward" "srs_app_encoder" "srs_app_http_stream"
"srs_app_st" "srs_app_log" "srs_app_config" "srs_app_stream_bridge"
- "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
+ "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks"
"srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_edge"
- "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" "srs_app_http_static"
+ "srs_app_heartbeat" "srs_app_http_client" "srs_app_http_static"
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic" "srs_app_hds"
"srs_app_mpegts_udp" "srs_app_listener" "srs_app_async_call"
- "srs_app_caster_flv" "srs_app_latest_version" "srs_app_uuid" "srs_app_process" "srs_app_ng_exec"
- "srs_app_hourglass" "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
- "srs_app_coworkers" "srs_app_circuit_breaker"
+ "srs_app_caster_flv" "srs_app_latest_version" "srs_app_process" "srs_app_ng_exec"
+ "srs_app_dash" "srs_app_fragment" "srs_app_dvr"
+ "srs_app_coworkers" "srs_app_circuit_breaker" "srs_app_factory"
"srs_app_stream_token")
# Always include SRT app modules
-MODULE_FILES+=("srs_app_srt_server" "srs_app_srt_listener" "srs_app_srt_conn" "srs_app_srt_utility" "srs_app_srt_source")
-MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_sdp" "srs_app_rtc_network"
- "srs_app_rtc_queue" "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")
+MODULE_FILES+=("srs_app_srt_server" "srs_app_srt_listener" "srs_app_srt_conn" "srs_app_srt_source")
+MODULE_FILES+=("srs_app_rtc_conn" "srs_app_rtc_dtls" "srs_app_rtc_network"
+ "srs_app_rtc_server" "srs_app_rtc_source" "srs_app_rtc_api")
if [[ $SRS_RTSP == YES ]]; then
MODULE_FILES+=("srs_app_rtsp_source" "srs_app_rtsp_conn")
fi
diff --git a/trunk/doc/CHANGELOG.md b/trunk/doc/CHANGELOG.md
index 2f08bca9ed4..83a79afd28a 100644
--- a/trunk/doc/CHANGELOG.md
+++ b/trunk/doc/CHANGELOG.md
@@ -7,6 +7,7 @@ The changelog for SRS.
## SRS 7.0 Changelog
+* v7.0, 2025-09-13, Merge [#4486](https://github.com/ossrs/srs/pull/4486): Move some app files to kernel. v7.0.86 (#4486)
* v7.0, 2025-09-12, Merge [#4485](https://github.com/ossrs/srs/pull/4485): AI: Fix naming problem for app module. v7.0.85 (#4485)
* v7.0, 2025-09-09, Merge [#4446](https://github.com/ossrs/srs/pull/4446): SRT2RTMP: fix srt bridge hevc to rtmp error. v7.0.84 (#4446)
* v7.0, 2025-09-09, Merge [#4482](https://github.com/ossrs/srs/pull/4482): AI: Fix naming issue for protocol module. v7.0.83 (#4482)
diff --git a/trunk/src/app/srs_app_async_call.hpp b/trunk/src/app/srs_app_async_call.hpp
index 602632cc231..7f6c04fae3f 100644
--- a/trunk/src/app/srs_app_async_call.hpp
+++ b/trunk/src/app/srs_app_async_call.hpp
@@ -41,7 +41,7 @@ class ISrsAsyncCallTask
class SrsAsyncCallWorker : public ISrsCoroutineHandler
{
private:
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
protected:
std::vector tasks_;
diff --git a/trunk/src/app/srs_app_caster_flv.cpp b/trunk/src/app/srs_app_caster_flv.cpp
index 4c81b1967d3..a6d27415ce7 100644
--- a/trunk/src/app/srs_app_caster_flv.cpp
+++ b/trunk/src/app/srs_app_caster_flv.cpp
@@ -11,7 +11,6 @@ using namespace std;
#include
#include
-#include
#include
#include
#include
@@ -19,6 +18,7 @@ using namespace std;
#include
#include
#include
+#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_caster_flv.hpp b/trunk/src/app/srs_app_caster_flv.hpp
index 00b42ff3ed0..3745c2cd485 100644
--- a/trunk/src/app/srs_app_caster_flv.hpp
+++ b/trunk/src/app/srs_app_caster_flv.hpp
@@ -24,11 +24,11 @@ class SrsTcpClient;
class SrsSimpleRtmpClient;
class SrsAppCasterFlv;
-#include
#include
#include
#include
#include
+#include
// A TCP listener, for flv stream server.
class SrsHttpFlvListener : public ISrsTcpHandler, public ISrsListener
diff --git a/trunk/src/app/srs_app_circuit_breaker.cpp b/trunk/src/app/srs_app_circuit_breaker.cpp
index db81ea38a41..d83bc3931b5 100644
--- a/trunk/src/app/srs_app_circuit_breaker.cpp
+++ b/trunk/src/app/srs_app_circuit_breaker.cpp
@@ -7,9 +7,9 @@
#include
#include
-#include
#include
#include
+#include
#include
#include
diff --git a/trunk/src/app/srs_app_circuit_breaker.hpp b/trunk/src/app/srs_app_circuit_breaker.hpp
index a7aa6634a6d..031b141487d 100644
--- a/trunk/src/app/srs_app_circuit_breaker.hpp
+++ b/trunk/src/app/srs_app_circuit_breaker.hpp
@@ -9,7 +9,7 @@
#include
-#include
+#include
// Interface for circuit breaker functionality to protect server in high load conditions.
// The circuit breaker monitors CPU usage and enables different levels of protection:
diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp
index c130d85ff78..6fbd4430e56 100644
--- a/trunk/src/app/srs_app_config.cpp
+++ b/trunk/src/app/srs_app_config.cpp
@@ -26,7 +26,7 @@
using namespace std;
#include
-#include
+#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp
index c2405bcce58..e637e38ca6d 100644
--- a/trunk/src/app/srs_app_config.hpp
+++ b/trunk/src/app/srs_app_config.hpp
@@ -18,6 +18,7 @@
#include
#include
#include
+#include
class ISrsRequest;
class SrsFileWriter;
@@ -278,7 +279,7 @@ enum SrsReloadState {
// that is, never save the SrsConfDirective* get by any api of config,
// For it maybe free in the reload st-thread cycle.
// You could keep it before st-thread switch, or simply never keep it.
-class SrsConfig
+class SrsConfig : public ISrsConfig
{
friend class SrsConfDirective;
// user command
diff --git a/trunk/src/app/srs_app_conn.cpp b/trunk/src/app/srs_app_conn.cpp
deleted file mode 100644
index 6d679640751..00000000000
--- a/trunk/src/app/srs_app_conn.cpp
+++ /dev/null
@@ -1,1009 +0,0 @@
-//
-// Copyright (c) 2013-2025 The SRS Authors
-//
-// SPDX-License-Identifier: MIT
-//
-
-#include
-
-#include
-#include
-using namespace std;
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-SrsPps *_srs_pps_ids = NULL;
-SrsPps *_srs_pps_fids = NULL;
-SrsPps *_srs_pps_fids_level0 = NULL;
-SrsPps *_srs_pps_dispose = NULL;
-
-ISrsDisposingHandler::ISrsDisposingHandler()
-{
-}
-
-ISrsDisposingHandler::~ISrsDisposingHandler()
-{
-}
-
-SrsResourceManager::SrsResourceManager(const std::string &label, bool verbose)
-{
- verbose_ = verbose;
- label_ = label;
- cond_ = srs_cond_new();
- trd_ = NULL;
- p_disposing_ = NULL;
- removing_ = false;
-
- nn_level0_cache_ = 100000;
- conns_level0_cache_ = new SrsResourceFastIdItem[nn_level0_cache_];
-}
-
-SrsResourceManager::~SrsResourceManager()
-{
- if (trd_) {
- srs_cond_signal(cond_);
- trd_->stop();
-
- srs_freep(trd_);
- }
- srs_cond_destroy(cond_);
-
- clear();
-
- // Free all objects not in zombies.
- std::vector::iterator it;
- for (it = conns_.begin(); it != conns_.end(); ++it) {
- ISrsResource *resource = *it;
- srs_freep(resource);
- }
-
- srs_freepa(conns_level0_cache_);
-}
-
-srs_error_t SrsResourceManager::start()
-{
- srs_error_t err = srs_success;
-
- cid_ = _srs_context->generate_id();
- trd_ = new SrsSTCoroutine("manager", this, cid_);
-
- if ((err = trd_->start()) != srs_success) {
- return srs_error_wrap(err, "conn manager");
- }
-
- return err;
-}
-
-bool SrsResourceManager::empty()
-{
- return conns_.empty();
-}
-
-size_t SrsResourceManager::size()
-{
- return conns_.size();
-}
-
-srs_error_t SrsResourceManager::cycle()
-{
- srs_error_t err = srs_success;
-
- srs_trace("%s: connection manager run, conns=%d", label_.c_str(), (int)conns_.size());
-
- while (true) {
- if ((err = trd_->pull()) != srs_success) {
- return srs_error_wrap(err, "conn manager");
- }
-
- // Clear all zombies, because we may switch context and lost signal
- // when we clear zombie connection.
- while (!zombies_.empty()) {
- clear();
- }
-
- srs_cond_wait(cond_);
- }
-
- return err;
-}
-
-void SrsResourceManager::add(ISrsResource *conn, bool *exists)
-{
- if (std::find(conns_.begin(), conns_.end(), conn) == conns_.end()) {
- conns_.push_back(conn);
- } else {
- if (exists) {
- *exists = true;
- }
- }
-}
-
-void SrsResourceManager::add_with_id(const std::string &id, ISrsResource *conn)
-{
- add(conn);
- conns_id_[id] = conn;
-}
-
-void SrsResourceManager::add_with_fast_id(uint64_t id, ISrsResource *conn)
-{
- bool exists = false;
- add(conn, &exists);
- conns_fast_id_[id] = conn;
-
- if (exists) {
- return;
- }
-
- // For new resource, build the level-0 cache for fast-id.
- SrsResourceFastIdItem *item = &conns_level0_cache_[(id | id >> 32) % nn_level0_cache_];
-
- // Ignore if exits item.
- if (item->fast_id_ && item->fast_id_ == id) {
- return;
- }
-
- // Fresh one, create the item.
- if (!item->fast_id_) {
- item->fast_id_ = id;
- item->impl_ = conn;
- item->nn_collisions_ = 1;
- item->available_ = true;
- }
-
- // Collision, increase the collisions.
- if (item->fast_id_ != id) {
- item->nn_collisions_++;
- item->available_ = false;
- }
-}
-
-void SrsResourceManager::add_with_name(const std::string &name, ISrsResource *conn)
-{
- add(conn);
- conns_name_[name] = conn;
-}
-
-ISrsResource *SrsResourceManager::at(int index)
-{
- return (index < (int)conns_.size()) ? conns_.at(index) : NULL;
-}
-
-ISrsResource *SrsResourceManager::find_by_id(std::string id)
-{
- ++_srs_pps_ids->sugar_;
- map::iterator it = conns_id_.find(id);
- return (it != conns_id_.end()) ? it->second : NULL;
-}
-
-ISrsResource *SrsResourceManager::find_by_fast_id(uint64_t id)
-{
- SrsResourceFastIdItem *item = &conns_level0_cache_[(id | id >> 32) % nn_level0_cache_];
- if (item->available_ && item->fast_id_ == id) {
- ++_srs_pps_fids_level0->sugar_;
- return item->impl_;
- }
-
- ++_srs_pps_fids->sugar_;
- map::iterator it = conns_fast_id_.find(id);
- return (it != conns_fast_id_.end()) ? it->second : NULL;
-}
-
-ISrsResource *SrsResourceManager::find_by_name(std::string name)
-{
- ++_srs_pps_ids->sugar_;
- map::iterator it = conns_name_.find(name);
- return (it != conns_name_.end()) ? it->second : NULL;
-}
-
-void SrsResourceManager::subscribe(ISrsDisposingHandler *h)
-{
- if (std::find(handlers_.begin(), handlers_.end(), h) == handlers_.end()) {
- handlers_.push_back(h);
- }
-
- // Restore the handler from unsubscribing handlers.
- vector::iterator it;
- if ((it = std::find(unsubs_.begin(), unsubs_.end(), h)) != unsubs_.end()) {
- it = unsubs_.erase(it);
- }
-}
-
-void SrsResourceManager::unsubscribe(ISrsDisposingHandler *h)
-{
- vector::iterator it = find(handlers_.begin(), handlers_.end(), h);
- if (it != handlers_.end()) {
- it = handlers_.erase(it);
- }
-
- // Put it to the unsubscribing handlers.
- if (std::find(unsubs_.begin(), unsubs_.end(), h) == unsubs_.end()) {
- unsubs_.push_back(h);
- }
-}
-
-void SrsResourceManager::remove(ISrsResource *c)
-{
- SrsContextRestore(_srs_context->get_id());
-
- removing_ = true;
- do_remove(c);
- removing_ = false;
-}
-
-void SrsResourceManager::do_remove(ISrsResource *c)
-{
- bool in_zombie = false;
- bool in_disposing = false;
- check_remove(c, in_zombie, in_disposing);
- bool ignored = in_zombie || in_disposing;
-
- if (verbose_) {
- _srs_context->set_id(c->get_id());
- srs_trace("%s: before dispose resource(%s)(%p), conns=%d, zombies=%d, ign=%d, inz=%d, ind=%d",
- label_.c_str(), c->desc().c_str(), c, (int)conns_.size(), (int)zombies_.size(), ignored,
- in_zombie, in_disposing);
- }
- if (ignored) {
- return;
- }
-
- // Push to zombies, we will free it in another coroutine.
- zombies_.push_back(c);
-
- // We should copy all handlers, because it may change during callback.
- vector handlers = handlers_;
-
- // Notify other handlers to handle the before-dispose event.
- for (int i = 0; i < (int)handlers.size(); i++) {
- ISrsDisposingHandler *h = handlers.at(i);
-
- // Ignore if handler is unsubscribing.
- if (!unsubs_.empty() && std::find(unsubs_.begin(), unsubs_.end(), h) != unsubs_.end()) {
- srs_warn2(TAG_RESOURCE_UNSUB, "%s: ignore before-dispose resource(%s)(%p) for %p, conns=%d",
- label_.c_str(), c->desc().c_str(), c, h, (int)conns_.size());
- continue;
- }
-
- h->on_before_dispose(c);
- }
-
- // Notify the coroutine to free it.
- srs_cond_signal(cond_);
-}
-
-void SrsResourceManager::check_remove(ISrsResource *c, bool &in_zombie, bool &in_disposing)
-{
- // Only notify when not removed(in zombies_).
- vector::iterator it = std::find(zombies_.begin(), zombies_.end(), c);
- if (it != zombies_.end()) {
- in_zombie = true;
- }
-
- // Also ignore when we are disposing it.
- if (p_disposing_) {
- it = std::find(p_disposing_->begin(), p_disposing_->end(), c);
- if (it != p_disposing_->end()) {
- in_disposing = true;
- }
- }
-}
-
-void SrsResourceManager::clear()
-{
- if (zombies_.empty()) {
- return;
- }
-
- SrsContextRestore(cid_);
- if (verbose_) {
- srs_trace("%s: clear zombies=%d resources, conns=%d, removing=%d, unsubs=%d",
- label_.c_str(), (int)zombies_.size(), (int)conns_.size(), removing_, (int)unsubs_.size());
- }
-
- // Clear all unsubscribing handlers, if not removing any resource.
- if (!removing_ && !unsubs_.empty()) {
- vector().swap(unsubs_);
- }
-
- do_clear();
-}
-
-void SrsResourceManager::do_clear()
-{
- // To prevent thread switch when delete connection,
- // we copy all connections then free one by one.
- vector copy;
- copy.swap(zombies_);
- p_disposing_ = ©
-
- for (int i = 0; i < (int)copy.size(); i++) {
- ISrsResource *conn = copy.at(i);
-
- if (verbose_) {
- _srs_context->set_id(conn->get_id());
- srs_trace("%s: disposing #%d resource(%s)(%p), conns=%d, disposing=%d, zombies=%d", label_.c_str(),
- i, conn->desc().c_str(), conn, (int)conns_.size(), (int)copy.size(), (int)zombies_.size());
- }
-
- ++_srs_pps_dispose->sugar_;
-
- dispose(conn);
- }
-
- // Reset it for it points to a local object.
- // @remark We must set the disposing to NULL to avoid reusing address,
- // because the context might switch.
- p_disposing_ = NULL;
-
- // We should free the resources when finished all disposing callbacks,
- // which might cause context switch and reuse the freed addresses.
- for (int i = 0; i < (int)copy.size(); i++) {
- ISrsResource *conn = copy.at(i);
- srs_freep(conn);
- }
-}
-
-void SrsResourceManager::dispose(ISrsResource *c)
-{
- for (map::iterator it = conns_name_.begin(); it != conns_name_.end();) {
- if (c != it->second) {
- ++it;
- } else {
- // Use C++98 style: https://stackoverflow.com/a/4636230
- conns_name_.erase(it++);
- }
- }
-
- for (map::iterator it = conns_id_.begin(); it != conns_id_.end();) {
- if (c != it->second) {
- ++it;
- } else {
- // Use C++98 style: https://stackoverflow.com/a/4636230
- conns_id_.erase(it++);
- }
- }
-
- for (map::iterator it = conns_fast_id_.begin(); it != conns_fast_id_.end();) {
- if (c != it->second) {
- ++it;
- } else {
- // Update the level-0 cache for fast-id.
- uint64_t id = it->first;
- SrsResourceFastIdItem *item = &conns_level0_cache_[(id | id >> 32) % nn_level0_cache_];
- item->nn_collisions_--;
- if (!item->nn_collisions_) {
- item->fast_id_ = 0;
- item->available_ = false;
- }
-
- // Use C++98 style: https://stackoverflow.com/a/4636230
- conns_fast_id_.erase(it++);
- }
- }
-
- vector::iterator it = std::find(conns_.begin(), conns_.end(), c);
- if (it != conns_.end()) {
- it = conns_.erase(it);
- }
-
- // We should copy all handlers, because it may change during callback.
- vector handlers = handlers_;
-
- // Notify other handlers to handle the disposing event.
- for (int i = 0; i < (int)handlers.size(); i++) {
- ISrsDisposingHandler *h = handlers.at(i);
-
- // Ignore if handler is unsubscribing.
- if (!unsubs_.empty() && std::find(unsubs_.begin(), unsubs_.end(), h) != unsubs_.end()) {
- srs_warn2(TAG_RESOURCE_UNSUB, "%s: ignore disposing resource(%s)(%p) for %p, conns=%d",
- label_.c_str(), c->desc().c_str(), c, h, (int)conns_.size());
- continue;
- }
-
- h->on_disposing(c);
- }
-}
-
-ISrsExpire::ISrsExpire()
-{
-}
-
-ISrsExpire::~ISrsExpire()
-{
-}
-
-SrsTcpConnection::SrsTcpConnection(srs_netfd_t c)
-{
- stfd_ = c;
- skt_ = new SrsStSocket(c);
-}
-
-SrsTcpConnection::~SrsTcpConnection()
-{
- srs_freep(skt_);
- srs_close_stfd(stfd_);
-}
-
-srs_error_t SrsTcpConnection::set_tcp_nodelay(bool v)
-{
- srs_error_t err = srs_success;
-
- int r0 = 0;
- socklen_t nb_v = sizeof(int);
- int fd = srs_netfd_fileno(stfd_);
-
- int ov = 0;
- if ((r0 = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &ov, &nb_v)) != 0) {
- return srs_error_new(ERROR_SOCKET_NO_NODELAY, "getsockopt fd=%d, r0=%d", fd, r0);
- }
-
-#ifndef SRS_PERF_TCP_NODELAY
- srs_warn("ignore TCP_NODELAY, fd=%d, ov=%d", fd, ov);
- return err;
-#endif
-
- int iv = (v ? 1 : 0);
- if ((r0 = setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &iv, nb_v)) != 0) {
- return srs_error_new(ERROR_SOCKET_NO_NODELAY, "setsockopt fd=%d, r0=%d", fd, r0);
- }
- if ((r0 = getsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &iv, &nb_v)) != 0) {
- return srs_error_new(ERROR_SOCKET_NO_NODELAY, "getsockopt fd=%d, r0=%d", fd, r0);
- }
-
- srs_trace("set fd=%d TCP_NODELAY %d=>%d", fd, ov, iv);
-
- return err;
-}
-
-srs_error_t SrsTcpConnection::set_socket_buffer(srs_utime_t buffer_v)
-{
- srs_error_t err = srs_success;
-
- int r0 = 0;
- int fd = srs_netfd_fileno(stfd_);
- socklen_t nb_v = sizeof(int);
-
- int ov = 0;
- if ((r0 = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &ov, &nb_v)) != 0) {
- return srs_error_new(ERROR_SOCKET_SNDBUF, "getsockopt fd=%d, r0=%d", fd, r0);
- }
-
-#ifndef SRS_PERF_MW_SO_SNDBUF
- srs_warn("ignore SO_SNDBUF, fd=%d, ov=%d", fd, ov);
- return err;
-#endif
-
- // the bytes:
- // 4KB=4096, 8KB=8192, 16KB=16384, 32KB=32768, 64KB=65536,
- // 128KB=131072, 256KB=262144, 512KB=524288
- // the buffer should set to sleep*kbps/8,
- // for example, your system delivery stream in 1000kbps,
- // sleep 800ms for small bytes, the buffer should set to:
- // 800*1000/8=100000B(about 128KB).
- // other examples:
- // 2000*3000/8=750000B(about 732KB).
- // 2000*5000/8=1250000B(about 1220KB).
- int kbps = 4000;
- int iv = srsu2ms(buffer_v) * kbps / 8;
-
- // socket send buffer, system will double it.
- iv = iv / 2;
-
- // override the send buffer by macro.
-#ifdef SRS_PERF_SO_SNDBUF_SIZE
- iv = SRS_PERF_SO_SNDBUF_SIZE / 2;
-#endif
-
- // set the socket send buffer when required larger buffer
- if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &iv, nb_v) < 0) {
- return srs_error_new(ERROR_SOCKET_SNDBUF, "setsockopt fd=%d, r0=%d", fd, r0);
- }
- if ((r0 = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &iv, &nb_v)) != 0) {
- return srs_error_new(ERROR_SOCKET_SNDBUF, "getsockopt fd=%d, r0=%d", fd, r0);
- }
-
- srs_trace("set fd=%d, SO_SNDBUF=%d=>%d, buffer=%dms", fd, ov, iv, srsu2ms(buffer_v));
-
- return err;
-}
-
-void SrsTcpConnection::set_recv_timeout(srs_utime_t tm)
-{
- skt_->set_recv_timeout(tm);
-}
-
-srs_utime_t SrsTcpConnection::get_recv_timeout()
-{
- return skt_->get_recv_timeout();
-}
-
-srs_error_t SrsTcpConnection::read_fully(void *buf, size_t size, ssize_t *nread)
-{
- return skt_->read_fully(buf, size, nread);
-}
-
-int64_t SrsTcpConnection::get_recv_bytes()
-{
- return skt_->get_recv_bytes();
-}
-
-int64_t SrsTcpConnection::get_send_bytes()
-{
- return skt_->get_send_bytes();
-}
-
-srs_error_t SrsTcpConnection::read(void *buf, size_t size, ssize_t *nread)
-{
- return skt_->read(buf, size, nread);
-}
-
-void SrsTcpConnection::set_send_timeout(srs_utime_t tm)
-{
- skt_->set_send_timeout(tm);
-}
-
-srs_utime_t SrsTcpConnection::get_send_timeout()
-{
- return skt_->get_send_timeout();
-}
-
-srs_error_t SrsTcpConnection::write(void *buf, size_t size, ssize_t *nwrite)
-{
- return skt_->write(buf, size, nwrite);
-}
-
-srs_error_t SrsTcpConnection::writev(const iovec *iov, int iov_size, ssize_t *nwrite)
-{
- return skt_->writev(iov, iov_size, nwrite);
-}
-
-SrsBufferedReadWriter::SrsBufferedReadWriter(ISrsProtocolReadWriter *io)
-{
- io_ = io;
- buf_ = NULL;
-}
-
-SrsBufferedReadWriter::~SrsBufferedReadWriter()
-{
- srs_freep(buf_);
-}
-
-srs_error_t SrsBufferedReadWriter::peek(char *buf, int *size)
-{
- srs_error_t err = srs_success;
-
- if ((err = reload_buffer()) != srs_success) {
- return srs_error_wrap(err, "reload buffer");
- }
-
- int nn = srs_min(buf_->left(), *size);
- *size = nn;
-
- if (nn) {
- memcpy(buf, buf_->head(), nn);
- }
-
- return err;
-}
-
-srs_error_t SrsBufferedReadWriter::reload_buffer()
-{
- srs_error_t err = srs_success;
-
- if (buf_ && !buf_->empty()) {
- return err;
- }
-
- // We use read_fully to always full fill the cache, to avoid peeking failed.
- ssize_t nread = 0;
- if ((err = io_->read_fully(cache_, sizeof(cache_), &nread)) != srs_success) {
- return srs_error_wrap(err, "read");
- }
-
- srs_freep(buf_);
- buf_ = new SrsBuffer(cache_, nread);
-
- return err;
-}
-
-srs_error_t SrsBufferedReadWriter::read(void *buf, size_t size, ssize_t *nread)
-{
- if (!buf_ || buf_->empty()) {
- return io_->read(buf, size, nread);
- }
-
- int nn = srs_min(buf_->left(), (int)size);
- *nread = nn;
-
- if (nn) {
- buf_->read_bytes((char *)buf, nn);
- }
- return srs_success;
-}
-
-srs_error_t SrsBufferedReadWriter::read_fully(void *buf, size_t size, ssize_t *nread)
-{
- if (!buf_ || buf_->empty()) {
- return io_->read_fully(buf, size, nread);
- }
-
- int nn = srs_min(buf_->left(), (int)size);
- if (nn) {
- buf_->read_bytes((char *)buf, nn);
- }
-
- int left = size - nn;
- *nread = size;
-
- if (left) {
- return io_->read_fully((char *)buf + nn, left, NULL);
- }
- return srs_success;
-}
-
-void SrsBufferedReadWriter::set_recv_timeout(srs_utime_t tm)
-{
- return io_->set_recv_timeout(tm);
-}
-
-srs_utime_t SrsBufferedReadWriter::get_recv_timeout()
-{
- return io_->get_recv_timeout();
-}
-
-int64_t SrsBufferedReadWriter::get_recv_bytes()
-{
- return io_->get_recv_bytes();
-}
-
-int64_t SrsBufferedReadWriter::get_send_bytes()
-{
- return io_->get_send_bytes();
-}
-
-void SrsBufferedReadWriter::set_send_timeout(srs_utime_t tm)
-{
- return io_->set_send_timeout(tm);
-}
-
-srs_utime_t SrsBufferedReadWriter::get_send_timeout()
-{
- return io_->get_send_timeout();
-}
-
-srs_error_t SrsBufferedReadWriter::write(void *buf, size_t size, ssize_t *nwrite)
-{
- return io_->write(buf, size, nwrite);
-}
-
-srs_error_t SrsBufferedReadWriter::writev(const iovec *iov, int iov_size, ssize_t *nwrite)
-{
- return io_->writev(iov, iov_size, nwrite);
-}
-
-SrsSslConnection::SrsSslConnection(ISrsProtocolReadWriter *c)
-{
- transport_ = c;
- ssl_ctx_ = NULL;
- ssl_ = NULL;
-}
-
-SrsSslConnection::~SrsSslConnection()
-{
- if (ssl_) {
- // this function will free bio_in_ and bio_out_
- SSL_free(ssl_);
- ssl_ = NULL;
- }
-
- if (ssl_ctx_) {
- SSL_CTX_free(ssl_ctx_);
- ssl_ctx_ = NULL;
- }
-}
-
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
-srs_error_t SrsSslConnection::handshake(string key_file, string crt_file)
-{
- srs_error_t err = srs_success;
-
- // For HTTPS, try to connect over security transport.
-#if (OPENSSL_VERSION_NUMBER < 0x10002000L) // v1.0.2
- ssl_ctx_ = SSL_CTX_new(TLS_method());
-#else
- ssl_ctx_ = SSL_CTX_new(TLSv1_2_method());
-#endif
- SSL_CTX_set_verify(ssl_ctx_, SSL_VERIFY_NONE, NULL);
- srs_assert(SSL_CTX_set_cipher_list(ssl_ctx_, "ALL") == 1);
-
- // TODO: Setup callback, see SSL_set_ex_data and SSL_set_info_callback
- if ((ssl_ = SSL_new(ssl_ctx_)) == NULL) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "SSL_new ssl");
- }
-
- if ((bio_in_ = BIO_new(BIO_s_mem())) == NULL) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_new in");
- }
-
- if ((bio_out_ = BIO_new(BIO_s_mem())) == NULL) {
- BIO_free(bio_in_);
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_new out");
- }
-
- SSL_set_bio(ssl_, bio_in_, bio_out_);
-
- // SSL setup active, as server role.
- SSL_set_accept_state(ssl_);
- SSL_set_mode(ssl_, SSL_MODE_ENABLE_PARTIAL_WRITE);
-
- uint8_t *data = NULL;
- int r0, r1, size;
-
- // Setup the key and cert file for server.
- if ((r0 = SSL_use_certificate_chain_file(ssl_, crt_file.c_str())) != 1) {
- return srs_error_new(ERROR_TLS_KEY_CRT, "use cert %s", crt_file.c_str());
- }
-
- if ((r0 = SSL_use_RSAPrivateKey_file(ssl_, key_file.c_str(), SSL_FILETYPE_PEM)) != 1) {
- return srs_error_new(ERROR_TLS_KEY_CRT, "use key %s", key_file.c_str());
- }
-
- if ((r0 = SSL_check_private_key(ssl_)) != 1) {
- return srs_error_new(ERROR_TLS_KEY_CRT, "check key %s with cert %s",
- key_file.c_str(), crt_file.c_str());
- }
- srs_info("ssl: use key %s and cert %s", key_file.c_str(), crt_file.c_str());
-
- // Receive ClientHello
- while (true) {
- char buf[1024];
- ssize_t nn = 0;
- if ((err = transport_->read(buf, sizeof(buf), &nn)) != srs_success) {
- return srs_error_wrap(err, "handshake: read");
- }
-
- if ((r0 = BIO_write(bio_in_, buf, nn)) <= 0) {
- // TODO: 0 or -1 maybe block, use BIO_should_retry to check.
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
- }
-
- r0 = SSL_do_handshake(ssl_);
- r1 = SSL_get_error(ssl_, r0);
- ERR_clear_error();
- if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
- }
-
- if ((size = BIO_get_mem_data(bio_out_, &data)) > 0) {
- // OK, reset it for the next write.
- if ((r0 = BIO_reset(bio_in_)) != 1) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
- }
- break;
- }
- }
-
- srs_info("tls: ClientHello done");
-
- // Send ServerHello, Certificate, Server Key Exchange, Server Hello Done
- size = BIO_get_mem_data(bio_out_, &data);
- if (!data || size <= 0) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake data=%p, size=%d", data, size);
- }
- if ((err = transport_->write(data, size, NULL)) != srs_success) {
- return srs_error_wrap(err, "handshake: write data=%p, size=%d", data, size);
- }
- if ((r0 = BIO_reset(bio_out_)) != 1) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
- }
-
- srs_info("tls: ServerHello done");
-
- // Receive Client Key Exchange, Change Cipher Spec, Encrypted Handshake Message
- while (true) {
- char buf[1024];
- ssize_t nn = 0;
- if ((err = transport_->read(buf, sizeof(buf), &nn)) != srs_success) {
- return srs_error_wrap(err, "handshake: read");
- }
-
- if ((r0 = BIO_write(bio_in_, buf, nn)) <= 0) {
- // TODO: 0 or -1 maybe block, use BIO_should_retry to check.
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_write r0=%d, data=%p, size=%d", r0, buf, nn);
- }
-
- r0 = SSL_do_handshake(ssl_);
- r1 = SSL_get_error(ssl_, r0);
- ERR_clear_error();
- if (r0 == 1 && r1 == SSL_ERROR_NONE) {
- break;
- }
-
- if (r0 != -1 || r1 != SSL_ERROR_WANT_READ) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake r0=%d, r1=%d", r0, r1);
- }
-
- if ((size = BIO_get_mem_data(bio_out_, &data)) > 0) {
- // OK, reset it for the next write.
- if ((r0 = BIO_reset(bio_in_)) != 1) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
- }
- break;
- }
- }
-
- srs_info("tls: Client done");
-
- // Send New Session Ticket, Change Cipher Spec, Encrypted Handshake Message
- size = BIO_get_mem_data(bio_out_, &data);
- if (!data || size <= 0) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "handshake data=%p, size=%d", data, size);
- }
- if ((err = transport_->write(data, size, NULL)) != srs_success) {
- return srs_error_wrap(err, "handshake: write data=%p, size=%d", data, size);
- }
- if ((r0 = BIO_reset(bio_out_)) != 1) {
- return srs_error_new(ERROR_TLS_HANDSHAKE, "BIO_reset r0=%d", r0);
- }
-
- srs_info("tls: Server done");
-
- return err;
-}
-#pragma GCC diagnostic pop
-
-void SrsSslConnection::set_recv_timeout(srs_utime_t tm)
-{
- transport_->set_recv_timeout(tm);
-}
-
-srs_utime_t SrsSslConnection::get_recv_timeout()
-{
- return transport_->get_recv_timeout();
-}
-
-srs_error_t SrsSslConnection::read_fully(void *buf, size_t size, ssize_t *nread)
-{
- srs_error_t err = srs_success;
- ssize_t nb = 0;
- void *p = buf;
- while ((size_t)nb < size) {
- ssize_t once_nb = 0;
- if ((err = read((char *)p + nb, size - nb, &once_nb)) != srs_success) {
- return srs_error_wrap(err, "tls: read");
- }
- nb += once_nb;
- }
-
- if (nread) {
- *nread = nb;
- }
-
- return err;
-}
-
-int64_t SrsSslConnection::get_recv_bytes()
-{
- return transport_->get_recv_bytes();
-}
-
-int64_t SrsSslConnection::get_send_bytes()
-{
- return transport_->get_send_bytes();
-}
-
-srs_error_t SrsSslConnection::read(void *plaintext, size_t nn_plaintext, ssize_t *nread)
-{
- srs_error_t err = srs_success;
-
- while (true) {
- int r0 = SSL_read(ssl_, plaintext, nn_plaintext);
- int r1 = SSL_get_error(ssl_, r0);
- ERR_clear_error();
- int r2 = BIO_ctrl_pending(bio_in_);
- int r3 = SSL_is_init_finished(ssl_);
-
- // OK, got data.
- if (r0 > 0) {
- srs_assert(r0 <= (int)nn_plaintext);
- if (nread) {
- *nread = r0;
- }
- return err;
- }
-
- // Need to read more data to feed SSL.
- if (r0 == -1 && r1 == SSL_ERROR_WANT_READ) {
- // TODO: Can we avoid copy?
- int nn_cipher = nn_plaintext;
- SrsUniquePtr cipher(new char[nn_cipher]);
-
- // Read the cipher from SSL.
- ssize_t nn = 0;
- if ((err = transport_->read(cipher.get(), nn_cipher, &nn)) != srs_success) {
- return srs_error_wrap(err, "tls: read");
- }
-
- int r0 = BIO_write(bio_in_, cipher.get(), nn);
- if (r0 <= 0) {
- // TODO: 0 or -1 maybe block, use BIO_should_retry to check.
- return srs_error_new(ERROR_TLS_READ, "BIO_write r0=%d, cipher=%p, size=%d", r0, cipher.get(), nn);
- }
- continue;
- }
-
- // Fail for error.
- if (r0 <= 0) {
- return srs_error_new(ERROR_TLS_READ, "SSL_read r0=%d, r1=%d, r2=%d, r3=%d",
- r0, r1, r2, r3);
- }
- }
-}
-
-void SrsSslConnection::set_send_timeout(srs_utime_t tm)
-{
- transport_->set_send_timeout(tm);
-}
-
-srs_utime_t SrsSslConnection::get_send_timeout()
-{
- return transport_->get_send_timeout();
-}
-
-srs_error_t SrsSslConnection::write(void *plaintext, size_t nn_plaintext, ssize_t *nwrite)
-{
- srs_error_t err = srs_success;
-
- for (char *p = (char *)plaintext; p < (char *)plaintext + nn_plaintext;) {
- int left = (int)nn_plaintext - (p - (char *)plaintext);
- int r0 = SSL_write(ssl_, (const void *)p, left);
- int r1 = SSL_get_error(ssl_, r0);
- ERR_clear_error();
- if (r0 <= 0) {
- return srs_error_new(ERROR_TLS_WRITE, "tls: write data=%p, size=%d, r0=%d, r1=%d", p, left, r0, r1);
- }
-
- // Move p to the next writing position.
- p += r0;
- if (nwrite) {
- *nwrite += (ssize_t)r0;
- }
-
- uint8_t *data = NULL;
- int size = BIO_get_mem_data(bio_out_, &data);
- if ((err = transport_->write(data, size, NULL)) != srs_success) {
- return srs_error_wrap(err, "tls: write data=%p, size=%d", data, size);
- }
- if ((r0 = BIO_reset(bio_out_)) != 1) {
- return srs_error_new(ERROR_TLS_WRITE, "BIO_reset r0=%d", r0);
- }
- }
-
- return err;
-}
-
-srs_error_t SrsSslConnection::writev(const iovec *iov, int iov_size, ssize_t *nwrite)
-{
- srs_error_t err = srs_success;
-
- for (int i = 0; i < iov_size; i++) {
- const iovec *p = iov + i;
- if ((err = write((void *)p->iov_base, (size_t)p->iov_len, nwrite)) != srs_success) {
- return srs_error_wrap(err, "write iov #%d base=%p, size=%d", i, p->iov_base, p->iov_len);
- }
- }
-
- return err;
-}
-
-SrsResourceManager *_srs_conn_manager = NULL;
diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp
index f9be06cf284..0a3a0190748 100644
--- a/trunk/src/app/srs_app_dash.cpp
+++ b/trunk/src/app/srs_app_dash.cpp
@@ -7,7 +7,7 @@
#include
#include
-#include
+#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_dvr.hpp b/trunk/src/app/srs_app_dvr.hpp
index d05bc2c235a..d95915afb07 100644
--- a/trunk/src/app/srs_app_dvr.hpp
+++ b/trunk/src/app/srs_app_dvr.hpp
@@ -30,7 +30,7 @@ class SrsFormat;
#include
#include
-#include
+#include
// The segmenter for DVR, to write a segment file in flv/mp4.
class SrsDvrSegmenter : public ISrsReloadHandler
diff --git a/trunk/src/app/srs_app_edge.cpp b/trunk/src/app/srs_app_edge.cpp
index c0e4a162d3b..4d1da1c7f48 100644
--- a/trunk/src/app/srs_app_edge.cpp
+++ b/trunk/src/app/srs_app_edge.cpp
@@ -16,10 +16,10 @@ using namespace std;
#include
#include
#include
-#include
#include
-#include
+#include
#include
+#include
#include
#include
@@ -27,11 +27,11 @@ using namespace std;
#include
#include
#include
+#include
#include
#include
#include
#include
-#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_edge.hpp b/trunk/src/app/srs_app_edge.hpp
index 5998158a1d2..9a090aa98ae 100644
--- a/trunk/src/app/srs_app_edge.hpp
+++ b/trunk/src/app/srs_app_edge.hpp
@@ -154,7 +154,7 @@ class SrsEdgeIngester : public ISrsCoroutineHandler
private:
SrsPlayEdge *edge_;
ISrsRequest *req_;
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
ISrsLbRoundRobin *lb_;
SrsEdgeUpstream *upstream_;
@@ -189,7 +189,7 @@ class SrsEdgeForwarder : public ISrsCoroutineHandler
private:
SrsPublishEdge *edge_;
ISrsRequest *req_;
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
SrsSimpleRtmpClient *sdk_;
ISrsLbRoundRobin *lb_;
// we must ensure one thread one fd principle,
diff --git a/trunk/src/app/srs_app_empty.cpp b/trunk/src/app/srs_app_empty.cpp
deleted file mode 100644
index 939fda5dafc..00000000000
--- a/trunk/src/app/srs_app_empty.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-//
-// Copyright (c) 2013-2025 The SRS Authors
-//
-// SPDX-License-Identifier: MIT
-//
-
-#include
diff --git a/trunk/src/app/srs_app_empty.hpp b/trunk/src/app/srs_app_empty.hpp
deleted file mode 100644
index 9a5198304ee..00000000000
--- a/trunk/src/app/srs_app_empty.hpp
+++ /dev/null
@@ -1,12 +0,0 @@
-//
-// Copyright (c) 2013-2025 The SRS Authors
-//
-// SPDX-License-Identifier: MIT
-//
-
-#ifndef SRS_APP_EMPTY_HPP
-#define SRS_APP_EMPTY_HPP
-
-#include
-
-#endif
diff --git a/trunk/src/app/srs_app_encoder.cpp b/trunk/src/app/srs_app_encoder.cpp
index 4a4c0bd471e..157c588f0fc 100644
--- a/trunk/src/app/srs_app_encoder.cpp
+++ b/trunk/src/app/srs_app_encoder.cpp
@@ -11,10 +11,10 @@ using namespace std;
#include
#include
-#include
#include
#include
#include
+#include
#include
#include
diff --git a/trunk/src/app/srs_app_encoder.hpp b/trunk/src/app/srs_app_encoder.hpp
index da3ebc34172..0c9b24c1247 100644
--- a/trunk/src/app/srs_app_encoder.hpp
+++ b/trunk/src/app/srs_app_encoder.hpp
@@ -28,7 +28,7 @@ class SrsEncoder : public ISrsCoroutineHandler
std::vector ffmpegs_;
private:
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
SrsPithyPrint *pprint_;
public:
diff --git a/trunk/src/app/srs_app_factory.cpp b/trunk/src/app/srs_app_factory.cpp
new file mode 100644
index 00000000000..05699cba7c7
--- /dev/null
+++ b/trunk/src/app/srs_app_factory.cpp
@@ -0,0 +1,70 @@
+//
+// Copyright (c) 2013-2025 The SRS Authors
+//
+// SPDX-License-Identifier: MIT
+//
+
+#include
+
+#include
+#include
+#include
+
+SrsFinalFactory::SrsFinalFactory()
+{
+}
+
+SrsFinalFactory::~SrsFinalFactory()
+{
+}
+
+ISrsCoroutine *SrsFinalFactory::create_coroutine(const std::string &name, ISrsCoroutineHandler *handler, SrsContextId cid)
+{
+ return new SrsSTCoroutine(name, handler, cid);
+}
+
+ISrsTime *SrsFinalFactory::create_time()
+{
+ return new SrsTrueTime();
+}
+
+ISrsConfig *SrsFinalFactory::create_config()
+{
+ return new SrsConfigProxy();
+}
+
+ISrsCond *SrsFinalFactory::create_cond()
+{
+ return new SrsCond();
+}
+
+SrsConfigProxy::SrsConfigProxy()
+{
+}
+
+SrsConfigProxy::~SrsConfigProxy()
+{
+}
+
+srs_utime_t SrsConfigProxy::get_pithy_print()
+{
+ return _srs_config->get_pithy_print();
+}
+
+std::string SrsConfigProxy::get_default_app_name()
+{
+ return _srs_config->get_default_app_name();
+}
+
+SrsTrueTime::SrsTrueTime()
+{
+}
+
+SrsTrueTime::~SrsTrueTime()
+{
+}
+
+void SrsTrueTime::usleep(srs_utime_t duration)
+{
+ srs_usleep(duration);
+}
diff --git a/trunk/src/app/srs_app_factory.hpp b/trunk/src/app/srs_app_factory.hpp
new file mode 100644
index 00000000000..7b8e057c215
--- /dev/null
+++ b/trunk/src/app/srs_app_factory.hpp
@@ -0,0 +1,51 @@
+//
+// Copyright (c) 2013-2025 The SRS Authors
+//
+// SPDX-License-Identifier: MIT
+//
+
+#ifndef SRS_APP_FACTORY_HPP
+#define SRS_APP_FACTORY_HPP
+
+#include
+
+#include
+
+// The factory to create kernel objects.
+class SrsFinalFactory : public ISrsKernelFactory
+{
+public:
+ SrsFinalFactory();
+ virtual ~SrsFinalFactory();
+
+public:
+ virtual ISrsCoroutine *create_coroutine(const std::string &name, ISrsCoroutineHandler *handler, SrsContextId cid);
+ virtual ISrsTime *create_time();
+ virtual ISrsConfig *create_config();
+ virtual ISrsCond *create_cond();
+};
+
+// The proxy for config.
+class SrsConfigProxy : public ISrsConfig
+{
+public:
+ SrsConfigProxy();
+ virtual ~SrsConfigProxy();
+
+public:
+ virtual srs_utime_t get_pithy_print();
+ virtual std::string get_default_app_name();
+};
+
+// The time to use system time.
+class SrsTrueTime : public ISrsTime
+{
+public:
+ SrsTrueTime();
+ virtual ~SrsTrueTime();
+
+public:
+ virtual void usleep(srs_utime_t duration);
+};
+
+#endif
diff --git a/trunk/src/app/srs_app_forward.cpp b/trunk/src/app/srs_app_forward.cpp
index 527e9d6ac74..98facfb584a 100644
--- a/trunk/src/app/srs_app_forward.cpp
+++ b/trunk/src/app/srs_app_forward.cpp
@@ -14,18 +14,18 @@
using namespace std;
#include
-#include
#include
-#include
+#include
#include
#include
#include
#include
#include
+#include
#include
+#include
#include
#include
-#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_forward.hpp b/trunk/src/app/srs_app_forward.hpp
index b3c50bf528a..3a22208e1ac 100644
--- a/trunk/src/app/srs_app_forward.hpp
+++ b/trunk/src/app/srs_app_forward.hpp
@@ -38,7 +38,7 @@ class SrsForwarder : public ISrsCoroutineHandler
SrsContextId source_cid_;
private:
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
private:
SrsOriginHub *hub_;
diff --git a/trunk/src/app/srs_app_gb28181.cpp b/trunk/src/app/srs_app_gb28181.cpp
index 40fe5f65bb0..4a178065bc7 100644
--- a/trunk/src/app/srs_app_gb28181.cpp
+++ b/trunk/src/app/srs_app_gb28181.cpp
@@ -7,23 +7,23 @@
#include
#include
-#include
#include
#include
-#include
-#include
#include
#include
#include
#include
#include
+#include
#include
#include
#include
#include
+#include
#include
#include
#include
+#include
#include
#include
diff --git a/trunk/src/app/srs_app_gb28181.hpp b/trunk/src/app/srs_app_gb28181.hpp
index 21eab1c15cf..b44cd26610c 100644
--- a/trunk/src/app/srs_app_gb28181.hpp
+++ b/trunk/src/app/srs_app_gb28181.hpp
@@ -9,7 +9,6 @@
#include
-#include
#include
#include
#include
@@ -22,7 +21,7 @@ class SrsConfDirective;
class SrsTcpListener;
class SrsResourceManager;
class SrsTcpConnection;
-class SrsCoroutine;
+class ISrsCoroutine;
class SrsPackContext;
class SrsBuffer;
diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp
index 14d5960a32e..5b3d8e3e778 100644
--- a/trunk/src/app/srs_app_hls.cpp
+++ b/trunk/src/app/srs_app_hls.cpp
@@ -20,14 +20,14 @@ using namespace std;
#include
#include
#include
-#include
-#include
+#include
#include
#include
#include
#include
#include
#include
+#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp
index 9b4575a9a95..d94f7ebcff7 100644
--- a/trunk/src/app/srs_app_http_api.cpp
+++ b/trunk/src/app/srs_app_http_api.cpp
@@ -16,8 +16,8 @@ using namespace std;
#include
#include
#include
+#include
#include
-#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_http_api.hpp b/trunk/src/app/srs_app_http_api.hpp
index 2ebed90a835..d0acea1f514 100644
--- a/trunk/src/app/srs_app_http_api.hpp
+++ b/trunk/src/app/srs_app_http_api.hpp
@@ -22,10 +22,10 @@ class SrsHttpConn;
#include
-#include
#include
#include
#include
+#include
#include
extern srs_error_t srs_api_response(ISrsHttpResponseWriter *w, ISrsHttpMessage *r, std::string json);
@@ -238,7 +238,7 @@ class SrsGoApiTcmalloc : public ISrsHttpHandler
class SrsGoApiValgrind : public ISrsHttpHandler, public ISrsCoroutineHandler
{
private:
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
std::string task_;
public:
diff --git a/trunk/src/app/srs_app_http_conn.cpp b/trunk/src/app/srs_app_http_conn.cpp
index 90a1f7ce6bd..df47a335fdf 100644
--- a/trunk/src/app/srs_app_http_conn.cpp
+++ b/trunk/src/app/srs_app_http_conn.cpp
@@ -19,9 +19,8 @@ using namespace std;
#include
#include
#include
-#include
+#include
#include
-#include
#include
#include
#include
@@ -32,6 +31,7 @@ using namespace std;
#include
#include
#include
+#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp
index e40494159ad..365ee800c04 100644
--- a/trunk/src/app/srs_app_http_conn.hpp
+++ b/trunk/src/app/srs_app_http_conn.hpp
@@ -13,11 +13,11 @@
#include
#include
-#include
#include
-#include
+#include
#include
#include
+#include
#include
class SrsServer;
@@ -73,7 +73,7 @@ class SrsHttpConn : public ISrsConnection, public ISrsStartable, public ISrsCoro
ISrsProtocolReadWriter *skt_;
// Each connection start a green thread,
// when thread stop, the connection will be delete by server.
- SrsCoroutine *trd_;
+ ISrsCoroutine *trd_;
// The ip and port of client.
std::string ip_;
int port_;
diff --git a/trunk/src/app/srs_app_http_static.cpp b/trunk/src/app/srs_app_http_static.cpp
index 8eabbfcf652..a863e5f4da5 100644
--- a/trunk/src/app/srs_app_http_static.cpp
+++ b/trunk/src/app/srs_app_http_static.cpp
@@ -15,11 +15,9 @@
using namespace std;
#include
-#include
#include
-#include
+#include
#include
-#include
#include
#include
#include
@@ -27,8 +25,10 @@ using namespace std;
#include
#include
#include
+#include
#include
#include
+#include
#include
#include
#include
diff --git a/trunk/src/app/srs_app_http_stream.cpp b/trunk/src/app/srs_app_http_stream.cpp
index 6ff84b60ebc..2452a864720 100644
--- a/trunk/src/app/srs_app_http_stream.cpp
+++ b/trunk/src/app/srs_app_http_stream.cpp
@@ -20,10 +20,9 @@ using namespace std;
#include
#include
#include
-#include
#include
+#include