AI: Move some app files to kernel. v7.0.86 (#4486)

Co-authored-by: OSSRS-AI <winlinam@gmail.com>
This commit is contained in:
Winlin 2025-09-13 10:26:47 -04:00 committed by GitHub
parent 2384f3fb06
commit d4d1d5d8b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
127 changed files with 2518 additions and 2273 deletions

View File

@ -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:

26
trunk/configure vendored
View File

@ -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

View File

@ -7,6 +7,7 @@ The changelog for SRS.
<a name="v7-changes"></a>
## 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)

View File

@ -41,7 +41,7 @@ public:
class SrsAsyncCallWorker : public ISrsCoroutineHandler
{
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
protected:
std::vector<ISrsAsyncCallTask *> tasks_;

View File

@ -11,7 +11,6 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_st.hpp>
#include <srs_app_utility.hpp>
@ -19,6 +18,7 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_rtmp_stack.hpp>

View File

@ -24,11 +24,11 @@ class SrsTcpClient;
class SrsSimpleRtmpClient;
class SrsAppCasterFlv;
#include <srs_app_conn.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_listener.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_file.hpp>
#include <srs_protocol_conn.hpp>
// A TCP listener, for flv stream server.
class SrsHttpFlvListener : public ISrsTcpHandler, public ISrsListener

View File

@ -7,9 +7,9 @@
#include <srs_app_circuit_breaker.hpp>
#include <srs_app_config.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_server.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_utility.hpp>

View File

@ -9,7 +9,7 @@
#include <srs_core.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_kernel_hourglass.hpp>
// Interface for circuit breaker functionality to protect server in high load conditions.
// The circuit breaker monitors CPU usage and enables different levels of protection:

View File

@ -26,7 +26,7 @@
using namespace std;
#include <srs_app_http_hooks.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>

View File

@ -18,6 +18,7 @@
#include <srs_app_async_call.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_factory.hpp>
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

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@
#include <srs_app_dash.hpp>
#include <srs_app_config.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_codec.hpp>

View File

@ -30,7 +30,7 @@ class SrsFormat;
#include <srs_app_async_call.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
// The segmenter for DVR, to write a segment file in flv/mp4.
class SrsDvrSegmenter : public ISrsReloadHandler

View File

@ -16,10 +16,10 @@ using namespace std;
#include <srs_app_caster_flv.hpp>
#include <srs_app_config.hpp>
#include <srs_app_http_client.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
@ -27,11 +27,11 @@ using namespace std;
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_http_client.hpp>
#include <srs_protocol_io.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_protocol_rtmp_msg_array.hpp>
#include <srs_protocol_rtmp_stack.hpp>
#include <srs_protocol_utility.hpp>

View File

@ -154,7 +154,7 @@ private:
private:
SrsPlayEdge *edge_;
ISrsRequest *req_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
ISrsLbRoundRobin *lb_;
SrsEdgeUpstream *upstream_;
@ -189,7 +189,7 @@ private:
private:
SrsPublishEdge *edge_;
ISrsRequest *req_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
SrsSimpleRtmpClient *sdk_;
ISrsLbRoundRobin *lb_;
// we must ensure one thread one fd principle,

View File

@ -1,7 +0,0 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_app_empty.hpp>

View File

@ -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 <srs_core.hpp>
#endif

View File

@ -11,10 +11,10 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_ffmpeg.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_rtmp_stack.hpp>

View File

@ -28,7 +28,7 @@ private:
std::vector<SrsFFMPEG *> ffmpegs_;
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
SrsPithyPrint *pprint_;
public:

View File

@ -0,0 +1,70 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_app_factory.hpp>
#include <srs_app_config.hpp>
#include <srs_app_st.hpp>
#include <srs_protocol_st.hpp>
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);
}

View File

@ -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 <srs_core.hpp>
#include <srs_kernel_factory.hpp>
// 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

View File

@ -14,18 +14,18 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_st.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_codec.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_protocol_rtmp_msg_array.hpp>
#include <srs_protocol_rtmp_stack.hpp>
#include <srs_protocol_utility.hpp>

View File

@ -38,7 +38,7 @@ private:
SrsContextId source_cid_;
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
private:
SrsOriginHub *hub_;

View File

@ -7,23 +7,23 @@
#include <srs_app_gb28181.hpp>
#include <srs_app_config.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_listener.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtc_sdp.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_server.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_ps.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_http_conn.hpp>
#include <srs_protocol_json.hpp>
#include <srs_protocol_raw_avc.hpp>
#include <srs_protocol_sdp.hpp>
#include <srs_protocol_utility.hpp>
#include <sstream>

View File

@ -9,7 +9,6 @@
#include <srs_core.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_listener.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_ps.hpp>
@ -22,7 +21,7 @@ class SrsConfDirective;
class SrsTcpListener;
class SrsResourceManager;
class SrsTcpConnection;
class SrsCoroutine;
class ISrsCoroutine;
class SrsPackContext;
class SrsBuffer;

View File

@ -20,14 +20,14 @@ using namespace std;
#include <openssl/rand.h>
#include <srs_app_config.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_codec.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_mp4.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>

View File

@ -16,8 +16,8 @@ using namespace std;
#include <srs_app_coworkers.hpp>
#include <srs_app_dvr.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_utility.hpp>

View File

@ -22,10 +22,10 @@ class SrsHttpConn;
#include <string>
#include <srs_app_conn.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_st.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_http_stack.hpp>
extern srs_error_t srs_api_response(ISrsHttpResponseWriter *w, ISrsHttpMessage *r, std::string json);
@ -238,7 +238,7 @@ public:
class SrsGoApiValgrind : public ISrsHttpHandler, public ISrsCoroutineHandler
{
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
std::string task_;
public:

View File

@ -19,9 +19,8 @@ using namespace std;
#include <srs_app_http_hooks.hpp>
#include <srs_app_http_static.hpp>
#include <srs_app_http_stream.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_utility.hpp>
@ -32,6 +31,7 @@ using namespace std;
#include <srs_kernel_flv.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>

View File

@ -13,11 +13,11 @@
#include <string>
#include <vector>
#include <srs_app_conn.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_file.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_http_conn.hpp>
class SrsServer;
@ -73,7 +73,7 @@ protected:
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_;

View File

@ -15,11 +15,9 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>
#include <srs_core_autofree.hpp>
@ -27,8 +25,10 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_log.hpp>

View File

@ -20,10 +20,9 @@ using namespace std;
#include <srs_app_async_call.hpp>
#include <srs_app_config.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_recv_thread.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>
#include <srs_core_autofree.hpp>
@ -33,6 +32,7 @@ using namespace std;
#include <srs_kernel_flv.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_mp3.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_rtmp_msg_array.hpp>

View File

@ -30,7 +30,7 @@ private:
private:
SrsMessageQueue *queue_;
ISrsRequest *req_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
public:
SrsBufferCache(SrsServer *s, ISrsRequest *r);

View File

@ -11,10 +11,10 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_ffmpeg.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_utility.hpp>

View File

@ -58,7 +58,7 @@ private:
std::vector<SrsIngesterFFMPEG *> ingesters_;
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
SrsPithyPrint *pprint_;
// Whether the ingesters are expired, for example, the listen port changed,
// all ingesters must be restart.

View File

@ -12,7 +12,6 @@
#include <srs_app_statistic.hpp>
#include <srs_app_utility.hpp>
#include <srs_app_uuid.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>

View File

@ -20,7 +20,7 @@
class SrsLatestVersion : public ISrsCoroutineHandler
{
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
std::string server_id_;
std::string session_id_;

View File

@ -17,16 +17,16 @@
#include <unistd.h>
using namespace std;
#include <srs_app_pithy_print.hpp>
#include <srs_app_server.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_kernel_kbps.hpp>
SrsPps *_srs_pps_rpkts = NULL;
SrsPps *_srs_pps_addrs = NULL;

View File

@ -82,7 +82,7 @@ class SrsUdpListener : public ISrsCoroutineHandler
protected:
std::string label_;
srs_netfd_t lfd_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
protected:
char *buf_;
@ -125,7 +125,7 @@ class SrsTcpListener : public ISrsCoroutineHandler, public ISrsListener
private:
std::string label_;
srs_netfd_t lfd_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
private:
ISrsTcpHandler *handler_;
@ -229,7 +229,7 @@ class SrsUdpMuxListener : public ISrsCoroutineHandler
{
private:
srs_netfd_t lfd_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
SrsContextId cid_;
private:

View File

@ -15,14 +15,6 @@
#include <srs_app_reload.hpp>
#include <srs_protocol_log.hpp>
// For log TAGs.
#define TAG_MAIN "MAIN"
#define TAG_MAYBE "MAYBE"
#define TAG_DTLS_ALERT "DTLS_ALERT"
#define TAG_DTLS_HANG "DTLS_HANG"
#define TAG_RESOURCE_UNSUB "RESOURCE_UNSUB"
#define TAG_LARGE_TIMER "LARGE_TIMER"
// Use memory/disk cache and donot flush when write log.
// it's ok to use it without config, which will log to console, and default trace level.
// when you want to use different level, override this classs, set the protected _level.

View File

@ -14,7 +14,6 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_st.hpp>
#include <srs_app_utility.hpp>
@ -23,6 +22,7 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_kernel_utility.hpp>

View File

@ -10,12 +10,12 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_process.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_consts.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_rtmp_stack.hpp>
#include <srs_protocol_utility.hpp>

View File

@ -24,7 +24,7 @@ class SrsProcess;
class SrsNgExec : public ISrsCoroutineHandler
{
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
SrsPithyPrint *pprint_;
std::string input_stream_name_;
std::vector<SrsProcess *> exec_publishs_;

View File

@ -9,7 +9,7 @@
#include <srs_app_config.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_statistic.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_performance.hpp>

View File

@ -64,7 +64,7 @@ public:
class SrsRecvThread : public ISrsCoroutineHandler
{
protected:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
ISrsMessagePumper *pumper_;
SrsRtmpServer *rtmp_;
SrsContextId _parent_cid;
@ -206,7 +206,7 @@ class SrsHttpRecvThread : public ISrsCoroutineHandler
{
private:
SrsHttpxConn *conn_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
public:
SrsHttpRecvThread(SrsHttpxConn *c);

View File

@ -21,17 +21,14 @@ using namespace std;
#include <srs_app_circuit_breaker.hpp>
#include <srs_app_config.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_log.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtc_network.hpp>
#include <srs_app_rtc_queue.hpp>
#include <srs_app_rtc_server.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_srt_source.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_stream_token.hpp>
@ -39,11 +36,13 @@ using namespace std;
#include <srs_core_autofree.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_rtc_queue.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_protocol_http_stack.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_protocol_log.hpp>
#include <srs_protocol_rtc_stun.hpp>
#include <srs_protocol_rtmp_msg_array.hpp>
@ -2335,8 +2334,13 @@ void SrsRtcConnection::check_send_nacks(SrsRtpNackForReceiver *nack, uint32_t ss
SrsRtcpNack rtcpNack(ssrc);
rtcpNack.set_media_ssrc(ssrc);
nack->get_nack_seqs(rtcpNack, timeout_nacks);
// If circuit-breaker is enabled, disable nack.
if (_srs_circuit_breaker->hybrid_high_water_level()) {
++_srs_pps_snack4->sugar_;
} else {
rtcpNack.set_media_ssrc(ssrc);
nack->get_nack_seqs(rtcpNack, timeout_nacks);
}
if (rtcpNack.empty()) {
return;

View File

@ -8,21 +8,20 @@
#define SRS_APP_RTC_CONN_HPP
#include <srs_app_async_call.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_listener.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_rtc_dtls.hpp>
#include <srs_app_rtc_queue.hpp>
#include <srs_app_rtc_sdp.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_core.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_rtc_queue.hpp>
#include <srs_kernel_rtc_rtcp.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_rtmp_stack.hpp>
#include <srs_protocol_sdp.hpp>
#include <srs_protocol_st.hpp>
#include <map>
@ -185,7 +184,7 @@ public:
class SrsRtcPLIWorker : public ISrsCoroutineHandler
{
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
srs_cond_t wait_;
ISrsRtcPLIWorkerHandler *handler_;

View File

@ -141,7 +141,7 @@ class SrsDtlsClientImpl : public SrsDtlsImpl, public ISrsCoroutineHandler
private:
// ARQ thread, for role active(DTLS client).
// @note If passive(DTLS server), the ARQ is driven by DTLS client.
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
// The DTLS-client state to drive the ARQ thread.
SrsDtlsState state_;
// The max ARQ retry.

View File

@ -10,7 +10,6 @@
using namespace std;
#include <srs_app_http_static.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtc_conn.hpp>
#include <srs_app_rtc_server.hpp>
#include <srs_app_st.hpp>
@ -20,6 +19,7 @@ using namespace std;
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_json.hpp>
#include <srs_protocol_rtc_stun.hpp>

View File

@ -18,7 +18,7 @@
#include <srs_protocol_conn.hpp>
class ISrsResourceManager;
class SrsCoroutine;
class ISrsCoroutine;
class SrsNetworkDelta;
class SrsTcpConnection;
class ISrsKbpsDelta;

View File

@ -12,9 +12,7 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtc_api.hpp>
#include <srs_app_rtc_conn.hpp>
#include <srs_app_rtc_dtls.hpp>
@ -27,7 +25,9 @@ using namespace std;
#include <srs_core_autofree.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_http_stack.hpp>
#include <srs_protocol_log.hpp>
#include <srs_protocol_rtc_stun.hpp>

View File

@ -10,12 +10,12 @@
#include <srs_core.hpp>
#include <srs_app_async_call.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_listener.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_rtc_conn.hpp>
#include <srs_app_rtc_sdp.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_protocol_sdp.hpp>
#include <set>
#include <string>

View File

@ -11,22 +11,22 @@
#include <srs_app_circuit_breaker.hpp>
#include <srs_app_config.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_log.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtc_conn.hpp>
#include <srs_app_rtc_queue.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_statistic.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_deprecated.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_codec.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_rtc_queue.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_format.hpp>
#include <srs_protocol_json.hpp>
#include <srs_protocol_rtmp_msg_array.hpp>
@ -37,7 +37,7 @@
#include <srs_app_rtc_codec.hpp>
#endif
#include <srs_protocol_kbps.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_protocol_raw_avc.hpp>
#include <srs_protocol_rtp.hpp>
@ -3182,11 +3182,18 @@ srs_error_t SrsRtcRecvTrack::on_nack(SrsRtpPacket **ppkt)
srs_warn("NACK: too old seq %u, range [%u, %u]", seq, rtp_queue_->begin_,
rtp_queue_->end_);
}
if (srs_rtp_seq_distance(nack_first, nack_last) > 0) {
srs_trace("NACK: update seq=%u, nack range [%u, %u]", seq, nack_first,
nack_last);
nack_receiver_->insert(nack_first, nack_last);
nack_receiver_->check_queue_size();
// If circuit-breaker is enabled, disable nack.
if (_srs_circuit_breaker->hybrid_high_water_level()) {
++_srs_pps_snack4->sugar_;
} else {
srs_trace("NACK: update seq=%u, nack range [%u, %u]", seq, nack_first,
nack_last);
nack_receiver_->insert(nack_first, nack_last);
nack_receiver_->check_queue_size();
}
}
}

View File

@ -14,12 +14,13 @@
#include <string>
#include <vector>
#include <srs_app_hourglass.hpp>
#include <srs_app_rtc_sdp.hpp>
#include <srs_app_stream_bridge.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_protocol_format.hpp>
#include <srs_protocol_sdp.hpp>
#include <srs_protocol_st.hpp>
class ISrsRequest;

View File

@ -18,17 +18,17 @@ using namespace std;
#include <srs_app_edge.hpp>
#include <srs_app_hls.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_recv_thread.hpp>
#include <srs_app_refer.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_security.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_srt_source.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_stream_token.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>

View File

@ -11,10 +11,10 @@
#include <string>
#include <srs_app_conn.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_st.hpp>
#include <srs_core_autofree.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_rtmp_conn.hpp>
#include <srs_protocol_rtmp_stack.hpp>
@ -157,7 +157,7 @@ private:
SrsRtmpTransport *transport_;
// Each connection start a green thread,
// when thread stop, the connection will be delete by server.
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
// The manager object to manage the connection.
ISrsResourceManager *manager_;
// The ip and port of client.

View File

@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT
//
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <algorithm>
#include <sstream>
@ -1007,10 +1007,10 @@ srs_error_t SrsOriginHub::on_audio(SrsMediaPacket *shared_audio)
}
#ifdef SRS_HDS
if ((err = hds->on_audio(msg)) != srs_success) {
if ((err = hds_->on_audio(msg)) != srs_success) {
srs_warn("hds: ignore audio error %s", srs_error_desc(err).c_str());
srs_error_reset(err);
hds->on_unpublish();
hds_->on_unpublish();
}
#endif
@ -1098,10 +1098,10 @@ srs_error_t SrsOriginHub::on_video(SrsMediaPacket *shared_video, bool is_sequenc
}
#ifdef SRS_HDS
if ((err = hds->on_video(msg)) != srs_success) {
if ((err = hds_->on_video(msg)) != srs_success) {
srs_warn("hds: ignore video error %s", srs_error_desc(err).c_str());
srs_error_reset(err);
hds->on_unpublish();
hds_->on_unpublish();
}
#endif

View File

@ -4,8 +4,8 @@
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_SOURCE_HPP
#define SRS_APP_SOURCE_HPP
#ifndef SRS_APP_RTMP_SOURCE_HPP
#define SRS_APP_RTMP_SOURCE_HPP
#include <srs_core.hpp>
@ -13,12 +13,12 @@
#include <string>
#include <vector>
#include <srs_app_hourglass.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_st.hpp>
#include <srs_app_stream_bridge.hpp>
#include <srs_core_autofree.hpp>
#include <srs_core_performance.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_protocol_st.hpp>
class SrsFormat;

View File

@ -14,9 +14,9 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtsp_source.hpp>
#include <srs_app_security.hpp>
#include <srs_app_st.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_utility.hpp>
#include <srs_core_autofree.hpp>
@ -24,8 +24,8 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_protocol_rtsp_stack.hpp>
#include <srs_protocol_st.hpp>
#include <srs_protocol_utility.hpp>

View File

@ -7,7 +7,6 @@
#ifndef SRS_APP_RTSP_CONN_HPP
#define SRS_APP_RTSP_CONN_HPP
#include <srs_app_conn.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_core.hpp>
#include <srs_core_autofree.hpp>
@ -38,7 +37,7 @@ class SrsRtspPlayStream : public ISrsCoroutineHandler, public ISrsRtcSourceChang
{
private:
SrsContextId cid_;
SrsFastCoroutine *trd_;
ISrsCoroutine *trd_;
SrsRtspConnection *session_;
private:
@ -106,7 +105,7 @@ private:
ISrsResourceManager *manager_;
// 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_;

View File

@ -10,7 +10,7 @@
#include <srs_core.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <map>

View File

@ -21,10 +21,8 @@ using namespace std;
#include <srs_app_caster_flv.hpp>
#include <srs_app_circuit_breaker.hpp>
#include <srs_app_config.hpp>
#include <srs_app_conn.hpp>
#include <srs_app_coworkers.hpp>
#include <srs_app_heartbeat.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_http_api.hpp>
#include <srs_app_http_conn.hpp>
#include <srs_app_http_hooks.hpp>
@ -32,26 +30,28 @@ using namespace std;
#include <srs_app_latest_version.hpp>
#include <srs_app_log.hpp>
#include <srs_app_mpegts_udp.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_rtc_api.hpp>
#include <srs_app_rtc_dtls.hpp>
#include <srs_app_rtc_network.hpp>
#include <srs_app_rtc_sdp.hpp>
#include <srs_app_rtc_server.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_app_rtmp_conn.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_statistic.hpp>
#include <srs_app_stream_token.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_consts.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_log.hpp>
#include <srs_protocol_rtc_stun.hpp>
#include <srs_protocol_sdp.hpp>
#ifdef SRS_GB28181
#include <srs_app_gb28181.hpp>
#endif

View File

@ -12,15 +12,15 @@
#include <string>
#include <vector>
#include <srs_app_conn.hpp>
#include <srs_app_hls.hpp>
#include <srs_app_hourglass.hpp>
#include <srs_app_listener.hpp>
#include <srs_app_reload.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_srt_listener.hpp>
#include <srs_app_srt_server.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_srt.hpp>
#include <srs_protocol_st.hpp>
@ -269,7 +269,7 @@ private:
private:
SrsServer *server_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
public:
SrsSignalManager(SrsServer *s);
@ -296,7 +296,7 @@ class SrsInotifyWorker : public ISrsCoroutineHandler
{
private:
SrsServer *server_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
srs_netfd_t inotify_fd_;
public:

View File

@ -10,9 +10,8 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_http_hooks.hpp>
#include <srs_app_pithy_print.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_srt_server.hpp>
#include <srs_app_srt_source.hpp>
#include <srs_app_statistic.hpp>
@ -20,6 +19,7 @@ using namespace std;
#include <srs_core_autofree.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_rtmp_stack.hpp>

View File

@ -12,11 +12,11 @@
#include <string>
#include <vector>
#include <srs_app_conn.hpp>
#include <srs_app_security.hpp>
#include <srs_app_srt_utility.hpp>
#include <srs_app_st.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_srt.hpp>
#include <srs_protocol_utility.hpp>
class SrsBuffer;
class SrsLiveSource;
@ -73,7 +73,7 @@ public:
private:
SrsSrtConnection *srt_conn_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
srs_error_t recv_err_;
};
@ -132,7 +132,7 @@ private:
SrsNetworkKbps *kbps_;
std::string ip_;
int port_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
ISrsRequest *req_;
SrsSharedPtr<SrsSrtSource> srt_source_;

View File

@ -31,7 +31,7 @@ class SrsSrtListener : public ISrsCoroutineHandler
private:
srs_srt_t lfd_;
SrsSrtSocket *srt_skt_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
private:
ISrsSrtHandler *handler_;

View File

@ -9,8 +9,8 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_server.hpp>
#include <srs_app_source.hpp>
#include <srs_app_srt_conn.hpp>
#include <srs_app_statistic.hpp>
#include <srs_kernel_log.hpp>

View File

@ -71,7 +71,7 @@ public:
private:
ISrsSrtPoller *srt_poller_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
};
// SrsSrtEventLoop is global singleton instance.

View File

@ -9,12 +9,12 @@
#include <algorithm>
using namespace std;
#include <srs_app_pithy_print.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_app_statistic.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_flv.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_raw_avc.hpp>

View File

@ -12,9 +12,9 @@
#include <map>
#include <vector>
#include <srs_app_hourglass.hpp>
#include <srs_app_stream_bridge.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_hourglass.hpp>
#include <srs_kernel_ts.hpp>
#include <srs_protocol_st.hpp>

View File

@ -1,147 +0,0 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_app_srt_utility.hpp>
using namespace std;
#include <srs_app_config.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_rtmp_stack.hpp>
#include <srs_protocol_utility.hpp>
// See streamid of https://github.com/ossrs/srs/issues/2893
// TODO: FIMXE: We should parse SRT streamid to URL object, rather than a HTTP url subpath.
bool srs_srt_streamid_info(const std::string &streamid, SrtMode &mode, std::string &vhost, std::string &url_subpath)
{
mode = SrtModePull;
size_t pos = streamid.find("#!::");
if (pos != 0) {
pos = streamid.find("/");
if (pos == streamid.npos) {
url_subpath = _srs_config->get_default_app_name() + "/" + streamid;
return true;
}
url_subpath = streamid;
return true;
}
// SRT url supports multiple QueryStrings, which are passed to RTMP to realize authentication and other capabilities
//@see https://github.com/ossrs/srs/issues/2893
std::string params;
std::string real_streamid;
real_streamid = streamid.substr(4);
// Compatible with previous auth querystring, like this one:
// srt://127.0.0.1:10080?streamid=#!::h=live/livestream?secret=xxx,m=publish
real_streamid = srs_strings_replace(real_streamid, "?", ",");
std::map<std::string, std::string> query;
srs_net_url_parse_query(real_streamid, query);
for (std::map<std::string, std::string>::iterator it = query.begin(); it != query.end(); ++it) {
if (it->first == "h") {
std::string host = it->second;
size_t r0 = host.find("/");
size_t r1 = host.rfind("/");
if (r0 != std::string::npos && r0 != std::string::npos) {
// Compatible with previous style, see https://github.com/ossrs/srs/issues/2893#compatible
// srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=publish
// srt://127.0.0.1:10080?streamid=#!::h=live/livestream,m=request
// srt://127.0.0.1:10080?streamid=#!::h=srs.srt.com.cn/live/livestream,m=publish
if (r0 != r1) {
// We got vhost in host.
url_subpath = host.substr(r0 + 1);
host = host.substr(0, r0);
params.append("vhost=");
params.append(host);
params.append("&");
vhost = host;
} else {
// Only stream in host.
url_subpath = host;
}
} else {
// New URL style, see https://github.com/ossrs/srs/issues/2893#solution
// srt://host.com:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2
// srt://1.2.3.4:10080?streamid=#!::h=host.com,r=app/stream,key1=value1,key2=value2
// srt://1.2.3.4:10080?streamid=#!::r=app/stream,key1=value1,key2=value2
params.append("vhost=");
params.append(host);
params.append("&");
vhost = host;
}
} else if (it->first == "r") {
url_subpath = it->second;
} else if (it->first == "m") {
std::string mode_str = it->second; // support m=publish or m=request
std::transform(it->second.begin(), it->second.end(), mode_str.begin(), ::tolower);
if (mode_str == "publish") {
mode = SrtModePush;
} else if (mode_str == "request") {
mode = SrtModePull;
} else {
srs_warn("unknown mode_str:%s", mode_str.c_str());
return false;
}
} else {
params.append(it->first);
params.append("=");
params.append(it->second);
params.append("&");
}
}
if (url_subpath.empty()) {
return false;
}
if (!params.empty()) {
url_subpath.append("?");
url_subpath.append(params);
url_subpath = url_subpath.substr(0, url_subpath.length() - 1); // remove last '&'
}
return true;
}
bool srs_srt_streamid_to_request(const std::string &streamid, SrtMode &mode, ISrsRequest *request)
{
string url_subpath = "";
bool ret = srs_srt_streamid_info(streamid, mode, request->vhost_, url_subpath);
if (!ret) {
return ret;
}
size_t pos = url_subpath.find("/");
string stream_with_params = "";
if (pos == string::npos) {
request->app_ = _srs_config->get_default_app_name();
stream_with_params = url_subpath;
} else {
request->app_ = url_subpath.substr(0, pos);
stream_with_params = url_subpath.substr(pos + 1);
}
pos = stream_with_params.find("?");
if (pos == string::npos) {
request->stream_ = stream_with_params;
} else {
request->stream_ = stream_with_params.substr(0, pos);
request->param_ = stream_with_params.substr(pos + 1);
}
request->host_ = srs_get_public_internet_address();
if (request->vhost_.empty())
request->vhost_ = request->host_;
request->tcUrl_ = srs_net_url_encode_tcurl("srt", request->host_, request->vhost_, request->app_, request->port_);
return ret;
}

View File

@ -1,31 +0,0 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_SRT_UTILITY_HPP
#define SRS_APP_SRT_UTILITY_HPP
#include <srs_core.hpp>
#include <string>
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_utility.hpp>
class ISrsRequest;
enum SrtMode {
SrtModePull = 1,
SrtModePush = 2,
};
// Get SRT streamid info.
extern bool srs_srt_streamid_info(const std::string &streamid, SrtMode &mode, std::string &vhost, std::string &url_subpath);
// SRT streamid to request.
extern bool srs_srt_streamid_to_request(const std::string &streamid, SrtMode &mode, ISrsRequest *request);
#endif

View File

@ -14,54 +14,6 @@ using namespace std;
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
ISrsCoroutineHandler::ISrsCoroutineHandler()
{
}
ISrsCoroutineHandler::~ISrsCoroutineHandler()
{
}
ISrsStartable::ISrsStartable()
{
}
ISrsStartable::~ISrsStartable()
{
}
ISrsInterruptable::ISrsInterruptable()
{
}
ISrsInterruptable::~ISrsInterruptable()
{
}
ISrsContextIdSetter::ISrsContextIdSetter()
{
}
ISrsContextIdSetter::~ISrsContextIdSetter()
{
}
ISrsContextIdGetter::ISrsContextIdGetter()
{
}
ISrsContextIdGetter::~ISrsContextIdGetter()
{
}
SrsCoroutine::SrsCoroutine()
{
}
SrsCoroutine::~SrsCoroutine()
{
}
SrsDummyCoroutine::SrsDummyCoroutine()
{
}

View File

@ -13,6 +13,7 @@
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_st.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_io.hpp>
#include <srs_protocol_st.hpp>
@ -20,102 +21,9 @@
class SrsFastCoroutine;
class SrsExecutorCoroutine;
// Each ST-coroutine must implements this interface,
// to do the cycle job and handle some events.
//
// Thread do a job then terminated normally, it's a SrsOneCycleThread:
// class SrsOneCycleThread : public ISrsCoroutineHandler {
// public: SrsCoroutine trd;
// public: virtual srs_error_t cycle() {
// // Do something, then return this cycle and thread terminated normally.
// }
// };
//
// Thread has its inside loop, such as the RTMP receive thread:
// class SrsReceiveThread : public ISrsCoroutineHandler {
// public: SrsCoroutine* trd;
// public: virtual srs_error_t cycle() {
// while (true) {
// // Check whether thread interrupted.
// if ((err = trd->pull()) != srs_success) {
// return err;
// }
// // Do something, such as st_read() packets, it'll be wakeup
// // when user stop or interrupt the thread.
// }
// }
// };
class ISrsCoroutineHandler
{
public:
ISrsCoroutineHandler();
virtual ~ISrsCoroutineHandler();
public:
// Do the work. The ST-coroutine will terminated normally if it returned.
// @remark If the cycle has its own loop, it must check the thread pull.
virtual srs_error_t cycle() = 0;
};
// Start the object, generally a coroutine.
class ISrsStartable
{
public:
ISrsStartable();
virtual ~ISrsStartable();
public:
virtual srs_error_t start() = 0;
};
// Allow user to interrupt the coroutine, for example, to stop it.
class ISrsInterruptable
{
public:
ISrsInterruptable();
virtual ~ISrsInterruptable();
public:
virtual void interrupt() = 0;
virtual srs_error_t pull() = 0;
};
// Get the context id.
class ISrsContextIdSetter
{
public:
ISrsContextIdSetter();
virtual ~ISrsContextIdSetter();
public:
virtual void set_cid(const SrsContextId &cid) = 0;
};
// Set the context id.
class ISrsContextIdGetter
{
public:
ISrsContextIdGetter();
virtual ~ISrsContextIdGetter();
public:
virtual const SrsContextId &cid() = 0;
};
// The coroutine object.
class SrsCoroutine : public ISrsStartable, public ISrsInterruptable, public ISrsContextIdSetter, public ISrsContextIdGetter
{
public:
SrsCoroutine();
virtual ~SrsCoroutine();
public:
virtual void stop() = 0;
};
// An empty coroutine, user can default to this object before create any real coroutine.
// @see https://github.com/ossrs/srs/pull/908
class SrsDummyCoroutine : public SrsCoroutine
class SrsDummyCoroutine : public ISrsCoroutine
{
private:
SrsContextId cid_;
@ -145,7 +53,7 @@ public:
// https://github.com/ossrs/state-threads/blob/st-1.9/README#L115
// @remark We always create joinable thread, so we must join it or memory leak,
// Please read https://github.com/ossrs/srs/issues/78
class SrsSTCoroutine : public SrsCoroutine
class SrsSTCoroutine : public ISrsCoroutine
{
private:
SrsFastCoroutine *impl_;
@ -186,7 +94,7 @@ public:
};
// High performance coroutine.
class SrsFastCoroutine
class SrsFastCoroutine : public ISrsCoroutine
{
private:
std::string name_;
@ -297,7 +205,7 @@ private:
ISrsExecutorHandler *callback_;
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
public:
SrsExecutorCoroutine(ISrsResourceManager *m, ISrsResource *r, ISrsCoroutineHandler *h, ISrsExecutorHandler *cb);

View File

@ -11,14 +11,13 @@
using namespace std;
#include <srs_app_config.hpp>
#include <srs_app_conn.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_json.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_protocol_rtmp_stack.hpp>
#include <srs_protocol_utility.hpp>

View File

@ -8,7 +8,7 @@
#include <srs_app_config.hpp>
#include <srs_app_rtc_source.hpp>
#include <srs_app_source.hpp>
#include <srs_app_rtmp_source.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_protocol_format.hpp>

View File

@ -26,11 +26,11 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_kernel_buffer.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_amf0.hpp>
#include <srs_protocol_json.hpp>
#include <srs_protocol_kbps.hpp>
// the longest time to wait for a process to quit.
#define SRS_PROCESS_QUIT_TIMEOUT_MS 1000

View File

@ -14,3 +14,11 @@ srs_utime_t srs_time_since(srs_utime_t start, srs_utime_t end)
return end - start;
}
ISrsTime::ISrsTime()
{
}
ISrsTime::~ISrsTime()
{
}

View File

@ -43,4 +43,15 @@ extern srs_utime_t srs_time_since_startup();
// A daemon st-thread updates it.
extern srs_utime_t srs_time_now_realtime();
// The time interface.
class ISrsTime
{
public:
ISrsTime();
virtual ~ISrsTime();
public:
virtual void usleep(srs_utime_t duration) = 0;
};
#endif

View File

@ -9,6 +9,6 @@
#define VERSION_MAJOR 7
#define VERSION_MINOR 0
#define VERSION_REVISION 85
#define VERSION_REVISION 86
#endif

View File

@ -0,0 +1,23 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_kernel_factory.hpp>
ISrsConfig::ISrsConfig()
{
}
ISrsConfig::~ISrsConfig()
{
}
ISrsKernelFactory::ISrsKernelFactory()
{
}
ISrsKernelFactory::~ISrsKernelFactory()
{
}

View File

@ -0,0 +1,45 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#ifndef SRS_KERNEL_FACTORY_HPP
#define SRS_KERNEL_FACTORY_HPP
#include <srs_core.hpp>
#include <srs_core_time.hpp>
#include <srs_kernel_st.hpp>
#include <string>
// The config for kernel and protocol objects.
class ISrsConfig
{
public:
ISrsConfig();
virtual ~ISrsConfig();
public:
virtual srs_utime_t get_pithy_print() = 0;
virtual std::string get_default_app_name() = 0;
};
// The factory to create kernel objects.
class ISrsKernelFactory
{
public:
ISrsKernelFactory();
virtual ~ISrsKernelFactory();
public:
virtual ISrsCoroutine *create_coroutine(const std::string &name, ISrsCoroutineHandler *handler, SrsContextId cid) = 0;
virtual ISrsTime *create_time() = 0;
virtual ISrsConfig *create_config() = 0;
virtual ISrsCond *create_cond() = 0;
};
extern ISrsKernelFactory *_srs_kernel_factory;
#endif

View File

@ -4,17 +4,18 @@
// SPDX-License-Identifier: MIT
//
#include <srs_app_hourglass.hpp>
#include <srs_kernel_hourglass.hpp>
#include <algorithm>
using namespace std;
#include <srs_core_time.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_factory.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_kbps.hpp>
SrsPps *_srs_pps_timer = NULL;
SrsPps *_srs_pps_conn = NULL;
SrsPps *_srs_pps_pub = NULL;
@ -43,12 +44,14 @@ SrsHourGlass::SrsHourGlass(string label, ISrsHourGlass *h, srs_utime_t resolutio
handler_ = h;
resolution_ = resolution;
total_elapse_ = 0;
trd_ = new SrsSTCoroutine("timer-" + label, this, _srs_context->get_id());
trd_ = _srs_kernel_factory->create_coroutine("timer-" + label, this, _srs_context->get_id());
time_ = _srs_kernel_factory->create_time();
}
SrsHourGlass::~SrsHourGlass()
{
srs_freep(trd_);
srs_freep(time_);
}
srs_error_t SrsHourGlass::start()
@ -119,7 +122,7 @@ srs_error_t SrsHourGlass::cycle()
// TODO: FIXME: Maybe we should use wallclock.
total_elapse_ += resolution_;
srs_usleep(resolution_);
time_->usleep(resolution_);
}
return err;
@ -136,12 +139,14 @@ ISrsFastTimer::~ISrsFastTimer()
SrsFastTimer::SrsFastTimer(std::string label, srs_utime_t interval)
{
interval_ = interval;
trd_ = new SrsSTCoroutine(label, this, _srs_context->get_id());
trd_ = _srs_kernel_factory->create_coroutine(label, this, _srs_context->get_id());
time_ = _srs_kernel_factory->create_time();
}
SrsFastTimer::~SrsFastTimer()
{
srs_freep(trd_);
srs_freep(time_);
}
srs_error_t SrsFastTimer::start()
@ -189,7 +194,7 @@ srs_error_t SrsFastTimer::cycle()
}
}
srs_usleep(interval_);
time_->usleep(interval_);
}
return err;
@ -197,10 +202,12 @@ srs_error_t SrsFastTimer::cycle()
SrsClockWallMonitor::SrsClockWallMonitor()
{
time_ = _srs_kernel_factory->create_time();
}
SrsClockWallMonitor::~SrsClockWallMonitor()
{
srs_freep(time_);
}
srs_error_t SrsClockWallMonitor::on_timer(srs_utime_t interval)

View File

@ -4,18 +4,18 @@
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_HOURGLASS_HPP
#define SRS_APP_HOURGLASS_HPP
#ifndef SRS_KERNEL_HOURGLASS_HPP
#define SRS_KERNEL_HOURGLASS_HPP
#include <srs_core.hpp>
#include <srs_app_st.hpp>
#include <srs_kernel_st.hpp>
#include <map>
#include <string>
#include <vector>
class SrsCoroutine;
class ISrsCoroutine;
// The handler for the tick.
class ISrsHourGlass
@ -57,9 +57,10 @@ class SrsHourGlass : public ISrsCoroutineHandler
{
private:
std::string label_;
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
ISrsHourGlass *handler_;
srs_utime_t resolution_;
ISrsTime *time_;
// The ticks:
// key: the event of tick.
// value: the interval of tick.
@ -112,9 +113,10 @@ public:
class SrsFastTimer : public ISrsCoroutineHandler
{
private:
SrsCoroutine *trd_;
ISrsCoroutine *trd_;
srs_utime_t interval_;
std::vector<ISrsFastTimer *> handlers_;
ISrsTime *time_;
public:
SrsFastTimer(std::string label, srs_utime_t interval);
@ -136,6 +138,9 @@ private:
// To monitor the system wall clock timer deviation.
class SrsClockWallMonitor : public ISrsFastTimer
{
private:
ISrsTime *time_;
public:
SrsClockWallMonitor();
virtual ~SrsClockWallMonitor();

View File

@ -61,3 +61,11 @@ ISrsWriteSeeker::ISrsWriteSeeker()
ISrsWriteSeeker::~ISrsWriteSeeker()
{
}
ISrsProtocolStatistic::ISrsProtocolStatistic()
{
}
ISrsProtocolStatistic::~ISrsProtocolStatistic()
{
}

View File

@ -119,4 +119,20 @@ public:
virtual ~ISrsWriteSeeker();
};
/**
* Get the statistic of channel.
*/
class ISrsProtocolStatistic
{
public:
ISrsProtocolStatistic();
virtual ~ISrsProtocolStatistic();
// For protocol
public:
// Get the total recv bytes over underlay fd.
virtual int64_t get_recv_bytes() = 0;
// Get the total send bytes over underlay fd.
virtual int64_t get_send_bytes() = 0;
};
#endif

View File

@ -7,6 +7,7 @@
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_io.hpp>
#include <srs_kernel_utility.hpp>
#include <cstdio>
@ -546,3 +547,282 @@ void srs_global_rtc_update(SrsKbsRtcStats *stats)
fid_desc = buf;
}
}
SrsKbpsSlice::SrsKbpsSlice(SrsWallClock *c)
{
clk_ = c;
starttime_ = 0;
bytes_ = 0;
}
SrsKbpsSlice::~SrsKbpsSlice()
{
}
void SrsKbpsSlice::sample()
{
srs_utime_t now = clk_->now();
if (sample_30s_.time_ < 0) {
sample_30s_.update(bytes_, now, 0);
}
if (sample_1m_.time_ < 0) {
sample_1m_.update(bytes_, now, 0);
}
if (sample_5m_.time_ < 0) {
sample_5m_.update(bytes_, now, 0);
}
if (sample_60m_.time_ < 0) {
sample_60m_.update(bytes_, now, 0);
}
if (now - sample_30s_.time_ >= 30 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes_ - sample_30s_.total_) * 8 / srsu2ms(now - sample_30s_.time_));
sample_30s_.update(bytes_, now, kbps);
}
if (now - sample_1m_.time_ >= 60 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes_ - sample_1m_.total_) * 8 / srsu2ms(now - sample_1m_.time_));
sample_1m_.update(bytes_, now, kbps);
}
if (now - sample_5m_.time_ >= 300 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes_ - sample_5m_.total_) * 8 / srsu2ms(now - sample_5m_.time_));
sample_5m_.update(bytes_, now, kbps);
}
if (now - sample_60m_.time_ >= 3600 * SRS_UTIME_SECONDS) {
int kbps = (int)((bytes_ - sample_60m_.total_) * 8 / srsu2ms(now - sample_60m_.time_));
sample_60m_.update(bytes_, now, kbps);
}
}
ISrsKbpsDelta::ISrsKbpsDelta()
{
}
ISrsKbpsDelta::~ISrsKbpsDelta()
{
}
SrsEphemeralDelta::SrsEphemeralDelta()
{
in_ = out_ = 0;
}
SrsEphemeralDelta::~SrsEphemeralDelta()
{
}
void SrsEphemeralDelta::add_delta(int64_t in, int64_t out)
{
in_ += in;
out_ += out;
}
void SrsEphemeralDelta::remark(int64_t *in, int64_t *out)
{
if (in)
*in = in_;
if (out)
*out = out_;
in_ = out_ = 0;
}
SrsNetworkDelta::SrsNetworkDelta()
{
in_ = out_ = NULL;
in_base_ = in_delta_ = 0;
out_base_ = out_delta_ = 0;
}
SrsNetworkDelta::~SrsNetworkDelta()
{
}
void SrsNetworkDelta::set_io(ISrsProtocolStatistic *in, ISrsProtocolStatistic *out)
{
if (in_) {
in_delta_ += in_->get_recv_bytes() - in_base_;
}
if (in) {
in_base_ = in->get_recv_bytes();
in_delta_ += in_base_;
}
in_ = in;
if (out_) {
out_delta_ += out_->get_send_bytes() - out_base_;
}
if (out) {
out_base_ = out->get_send_bytes();
out_delta_ += out_base_;
}
out_ = out;
}
void SrsNetworkDelta::remark(int64_t *in, int64_t *out)
{
if (in_) {
in_delta_ += in_->get_recv_bytes() - in_base_;
in_base_ = in_->get_recv_bytes();
}
if (out_) {
out_delta_ += out_->get_send_bytes() - out_base_;
out_base_ = out_->get_send_bytes();
}
*in = in_delta_;
*out = out_delta_;
in_delta_ = out_delta_ = 0;
}
SrsKbps::SrsKbps(SrsWallClock *c)
{
clk_ = c ? c : _srs_clock;
is_ = new SrsKbpsSlice(clk_);
os_ = new SrsKbpsSlice(clk_);
}
SrsKbps::~SrsKbps()
{
srs_freep(is_);
srs_freep(os_);
}
int SrsKbps::get_send_kbps()
{
int duration = srsu2ms(clk_->now() - is_->starttime_);
if (duration <= 0) {
return 0;
}
int64_t bytes = get_send_bytes();
return (int)(bytes * 8 / duration);
}
int SrsKbps::get_recv_kbps()
{
int duration = srsu2ms(clk_->now() - os_->starttime_);
if (duration <= 0) {
return 0;
}
int64_t bytes = get_recv_bytes();
return (int)(bytes * 8 / duration);
}
int SrsKbps::get_send_kbps_30s()
{
return os_->sample_30s_.rate_;
}
int SrsKbps::get_recv_kbps_30s()
{
return is_->sample_30s_.rate_;
}
int SrsKbps::get_send_kbps_5m()
{
return os_->sample_5m_.rate_;
}
int SrsKbps::get_recv_kbps_5m()
{
return is_->sample_5m_.rate_;
}
void SrsKbps::add_delta(ISrsKbpsDelta *delta)
{
if (!delta)
return;
int64_t in, out;
delta->remark(&in, &out);
add_delta(in, out);
}
void SrsKbps::add_delta(int64_t in, int64_t out)
{
// update the total bytes
is_->bytes_ += in;
os_->bytes_ += out;
// we donot sample, please use sample() to do resample.
}
void SrsKbps::sample()
{
is_->sample();
os_->sample();
}
int64_t SrsKbps::get_send_bytes()
{
return os_->bytes_;
}
int64_t SrsKbps::get_recv_bytes()
{
return is_->bytes_;
}
SrsNetworkKbps::SrsNetworkKbps(SrsWallClock *clock)
{
delta_ = new SrsNetworkDelta();
kbps_ = new SrsKbps(clock);
}
SrsNetworkKbps::~SrsNetworkKbps()
{
srs_freep(kbps_);
srs_freep(delta_);
}
void SrsNetworkKbps::set_io(ISrsProtocolStatistic *in, ISrsProtocolStatistic *out)
{
delta_->set_io(in, out);
}
void SrsNetworkKbps::sample()
{
kbps_->add_delta(delta_);
kbps_->sample();
}
int SrsNetworkKbps::get_send_kbps()
{
return kbps_->get_send_kbps();
}
int SrsNetworkKbps::get_recv_kbps()
{
return kbps_->get_recv_kbps();
}
int SrsNetworkKbps::get_send_kbps_30s()
{
return kbps_->get_send_kbps_30s();
}
int SrsNetworkKbps::get_recv_kbps_30s()
{
return kbps_->get_recv_kbps_30s();
}
int SrsNetworkKbps::get_send_kbps_5m()
{
return kbps_->get_send_kbps_5m();
}
int SrsNetworkKbps::get_recv_kbps_5m()
{
return kbps_->get_recv_kbps_5m();
}
int64_t SrsNetworkKbps::get_send_bytes()
{
return kbps_->get_send_bytes();
}
int64_t SrsNetworkKbps::get_recv_bytes()
{
return kbps_->get_recv_bytes();
}

View File

@ -14,6 +14,7 @@
#include <string>
class SrsWallClock;
class ISrsProtocolStatistic;
// A sample for rate-based stat, such as kbps or kps.
class SrsRateSample
@ -230,4 +231,171 @@ public:
// Update the global rtc statistics variables
void srs_global_rtc_update(SrsKbsRtcStats *stats);
/**
* The slice of kbps statistic, for input or output.
*/
class SrsKbpsSlice
{
private:
SrsWallClock *clk_;
public:
// session startup bytes
// @remark, use total_bytes() to get the total bytes of slice.
int64_t bytes_;
// slice starttime, the first time to record bytes.
srs_utime_t starttime_;
// samples
SrsRateSample sample_30s_;
SrsRateSample sample_1m_;
SrsRateSample sample_5m_;
SrsRateSample sample_60m_;
public:
SrsKbpsSlice(SrsWallClock *c);
virtual ~SrsKbpsSlice();
public:
// Resample the slice to calculate the kbps.
virtual void sample();
};
/**
* The interface which provices delta of bytes. For example, we got a delta from a TCP client:
* ISrsKbpsDelta* delta = ...;
* Now, we can add delta simple to a kbps:
* kbps->add_delta(delta);
* Or by multiple kbps:
* int64_t in, out;
* delta->remark(&in, &out);
* kbps1->add_delta(in, out);
* kbpsN->add_delta(in, out);
* Then you're able to use the kbps object.
*/
class ISrsKbpsDelta
{
public:
ISrsKbpsDelta();
virtual ~ISrsKbpsDelta();
public:
// Resample to get the value of delta bytes.
// @remark If no delta bytes, both in and out will be set to 0.
virtual void remark(int64_t *in, int64_t *out) = 0;
};
// A delta data source for SrsKbps, used in ephemeral case, for example, UDP server to increase stat when received or
// sent out each UDP packet.
class SrsEphemeralDelta : public ISrsKbpsDelta
{
private:
uint64_t in_;
uint64_t out_;
public:
SrsEphemeralDelta();
virtual ~SrsEphemeralDelta();
public:
virtual void add_delta(int64_t in, int64_t out);
// Interface ISrsKbpsDelta.
public:
virtual void remark(int64_t *in, int64_t *out);
};
// A network delta data source for SrsKbps.
class SrsNetworkDelta : public ISrsKbpsDelta
{
private:
ISrsProtocolStatistic *in_;
ISrsProtocolStatistic *out_;
uint64_t in_base_;
uint64_t in_delta_;
uint64_t out_base_;
uint64_t out_delta_;
public:
SrsNetworkDelta();
virtual ~SrsNetworkDelta();
public:
// Switch the under-layer network io, we use the bytes as a fresh delta.
virtual void set_io(ISrsProtocolStatistic *in, ISrsProtocolStatistic *out);
// Interface ISrsKbpsDelta.
public:
virtual void remark(int64_t *in, int64_t *out);
};
/**
* To statistic the kbps. For example, we got a set of connections and add the total delta:
* SrsKbps* kbps = ...;
* for conn in connections:
* kbps->add_delta(conn->delta()) // Which return an ISrsKbpsDelta object.
* Then we sample and got the total kbps:
* kbps->sample()
* kbps->get_xxx_kbps().
*/
class SrsKbps
{
private:
SrsKbpsSlice *is_;
SrsKbpsSlice *os_;
SrsWallClock *clk_;
public:
// Note that we won't free the clock c.
SrsKbps(SrsWallClock *c = NULL);
virtual ~SrsKbps();
public:
// Get total average kbps.
virtual int get_send_kbps();
virtual int get_recv_kbps();
// Get the average kbps in 30s.
virtual int get_send_kbps_30s();
virtual int get_recv_kbps_30s();
// Get the average kbps in 5m or 300s.
virtual int get_send_kbps_5m();
virtual int get_recv_kbps_5m();
public:
// Add delta to kbps. Please call sample() after all deltas are added to kbps.
virtual void add_delta(int64_t in, int64_t out);
virtual void add_delta(ISrsKbpsDelta *delta);
// Sample the kbps to get the kbps in N seconds.
virtual void sample();
public:
virtual int64_t get_send_bytes();
virtual int64_t get_recv_bytes();
};
// A sugar to use SrsNetworkDelta and SrsKbps.
class SrsNetworkKbps
{
private:
SrsNetworkDelta *delta_;
SrsKbps *kbps_;
public:
SrsNetworkKbps(SrsWallClock *c = NULL);
virtual ~SrsNetworkKbps();
public:
virtual void set_io(ISrsProtocolStatistic *in, ISrsProtocolStatistic *out);
virtual void sample();
public:
virtual int get_send_kbps();
virtual int get_recv_kbps();
virtual int get_send_kbps_30s();
virtual int get_recv_kbps_30s();
virtual int get_send_kbps_5m();
virtual int get_recv_kbps_5m();
public:
virtual int64_t get_send_bytes();
virtual int64_t get_recv_bytes();
};
#endif

View File

@ -101,6 +101,16 @@ ISrsContext::~ISrsContext()
{
}
impl_SrsContextRestore::impl_SrsContextRestore(SrsContextId cid)
{
cid_ = cid;
}
impl_SrsContextRestore::~impl_SrsContextRestore()
{
_srs_context->set_id(cid_);
}
void srs_logger_impl(SrsLogLevel level, const char *tag, const SrsContextId &context_id, const char *fmt, ...)
{
if (!_srs_log)

View File

@ -18,6 +18,14 @@
#include <srs_kernel_consts.hpp>
// For log TAGs.
#define TAG_MAIN "MAIN"
#define TAG_MAYBE "MAYBE"
#define TAG_DTLS_ALERT "DTLS_ALERT"
#define TAG_DTLS_HANG "DTLS_HANG"
#define TAG_RESOURCE_UNSUB "RESOURCE_UNSUB"
#define TAG_LARGE_TIMER "LARGE_TIMER"
// The log level, see https://github.com/apache/logging-log4j2/blob/release-2.x/log4j-api/src/main/java/org/apache/logging/log4j/Level.java
// Please note that the enum name might not be the string, to keep compatible with previous definition.
enum SrsLogLevel {
@ -80,6 +88,20 @@ public:
virtual const SrsContextId &set_id(const SrsContextId &v) = 0;
};
// The context restore stores the context and restore it when done.
// Usage:
// SrsContextRestore(_srs_context->get_id());
#define SrsContextRestore(cid) impl_SrsContextRestore _context_restore_instance(cid)
class impl_SrsContextRestore
{
private:
SrsContextId cid_;
public:
impl_SrsContextRestore(SrsContextId cid);
virtual ~impl_SrsContextRestore();
};
// @global User must implements the LogContext and define a global instance.
extern ISrsContext *_srs_context;

View File

@ -4,13 +4,13 @@
// SPDX-License-Identifier: MIT
//
#include <srs_app_pithy_print.hpp>
#include <srs_kernel_pithy_print.hpp>
#include <stdlib.h>
using namespace std;
#include <srs_app_config.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_factory.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_utility.hpp>
@ -21,20 +21,19 @@ SrsStageInfo::SrsStageInfo(int _stage_id, double ratio)
age_ = 0;
nn_count_ = 0;
interval_ratio_ = ratio;
config_ = _srs_kernel_factory->create_config();
update_print_time();
_srs_config->subscribe(this);
}
SrsStageInfo::~SrsStageInfo()
{
_srs_config->unsubscribe(this);
srs_freep(config_);
}
void SrsStageInfo::update_print_time()
{
interval_ = _srs_config->get_pithy_print();
interval_ = config_->get_pithy_print();
}
void SrsStageInfo::elapse(srs_utime_t diff)

View File

@ -4,17 +4,17 @@
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_PITHY_PRINT_HPP
#define SRS_APP_PITHY_PRINT_HPP
#ifndef SRS_KERNEL_PITHY_PRINT_HPP
#define SRS_KERNEL_PITHY_PRINT_HPP
#include <srs_core.hpp>
#include <map>
#include <srs_app_reload.hpp>
class ISrsConfig;
// The stage info to calc the age.
class SrsStageInfo : public ISrsReloadHandler
class SrsStageInfo
{
public:
int stage_id_;
@ -24,6 +24,7 @@ public:
uint32_t nn_count_;
// The ratio for interval, 1.0 means no change.
double interval_ratio_;
ISrsConfig *config_;
public:
srs_utime_t age_;
@ -158,4 +159,7 @@ public:
virtual srs_utime_t age();
};
// Global stage manager for pithy print, multiple stages.
extern SrsStageManager *_srs_stages;
#endif

View File

@ -0,0 +1,430 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_kernel_resource.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_factory.hpp>
#include <srs_kernel_kbps.hpp>
#include <srs_kernel_log.hpp>
#include <algorithm>
using namespace std;
SrsPps *_srs_pps_ids = NULL;
SrsPps *_srs_pps_fids = NULL;
SrsPps *_srs_pps_fids_level0 = NULL;
SrsPps *_srs_pps_dispose = NULL;
SrsResourceManager *_srs_conn_manager = NULL;
ISrsDisposingHandler::ISrsDisposingHandler()
{
}
ISrsDisposingHandler::~ISrsDisposingHandler()
{
}
ISrsResource::ISrsResource()
{
}
ISrsResource::~ISrsResource()
{
}
std::string ISrsResource::desc()
{
return "Resource";
}
ISrsResourceManager::ISrsResourceManager()
{
}
ISrsResourceManager::~ISrsResourceManager()
{
}
SrsResourceManager::SrsResourceManager(const std::string &label, bool verbose)
{
verbose_ = verbose;
label_ = label;
cond_ = _srs_kernel_factory->create_cond();
trd_ = NULL;
p_disposing_ = NULL;
removing_ = false;
nn_level0_cache_ = 100000;
conns_level0_cache_ = new SrsResourceFastIdItem[nn_level0_cache_];
}
SrsResourceManager::~SrsResourceManager()
{
if (trd_) {
cond_->signal();
trd_->stop();
srs_freep(trd_);
}
srs_freep(cond_);
clear();
// Free all objects not in zombies.
std::vector<ISrsResource *>::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_ = _srs_kernel_factory->create_coroutine("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();
}
cond_->wait();
}
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<string, ISrsResource *>::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<uint64_t, ISrsResource *>::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<string, ISrsResource *>::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<ISrsDisposingHandler *>::iterator it;
if ((it = std::find(unsubs_.begin(), unsubs_.end(), h)) != unsubs_.end()) {
it = unsubs_.erase(it);
}
}
void SrsResourceManager::unsubscribe(ISrsDisposingHandler *h)
{
vector<ISrsDisposingHandler *>::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<ISrsDisposingHandler *> 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.
cond_->signal();
}
void SrsResourceManager::check_remove(ISrsResource *c, bool &in_zombie, bool &in_disposing)
{
// Only notify when not removed(in zombies_).
vector<ISrsResource *>::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<ISrsDisposingHandler *>().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<ISrsResource *> copy;
copy.swap(zombies_);
p_disposing_ = &copy;
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<string, ISrsResource *>::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<string, ISrsResource *>::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<uint64_t, ISrsResource *>::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<ISrsResource *>::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<ISrsDisposingHandler *> 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);
}
}

View File

@ -4,26 +4,20 @@
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_CONN_HPP
#define SRS_APP_CONN_HPP
#ifndef SRS_KERNEL_RESOURCE_HPP
#define SRS_KERNEL_RESOURCE_HPP
#include <srs_core.hpp>
#include <srs_core_autofree.hpp>
#include <srs_kernel_st.hpp>
#include <map>
#include <string>
#include <vector>
#include <openssl/err.h>
#include <openssl/ssl.h>
#include <srs_app_reload.hpp>
#include <srs_app_st.hpp>
#include <srs_core_autofree.hpp>
#include <srs_protocol_conn.hpp>
#include <srs_protocol_kbps.hpp>
class SrsWallClock;
class SrsBuffer;
class ISrsResource;
class ISrsCond;
// Hooks for connection manager, to handle the event when disposing connections.
class ISrsDisposingHandler
@ -65,6 +59,36 @@ public:
}
};
// The resource managed by ISrsResourceManager.
class ISrsResource
{
public:
ISrsResource();
virtual ~ISrsResource();
public:
// Get the context id of connection.
virtual const SrsContextId &get_id() = 0;
public:
// The resource description, optional.
virtual std::string desc();
};
// The manager for resource.
class ISrsResourceManager
{
public:
ISrsResourceManager();
virtual ~ISrsResourceManager();
public:
// Remove then free the specified connection. Note that the manager always free c resource,
// in the same coroutine or another coroutine. Some manager may support add c to a map, it
// should always free it even if it's in the map.
virtual void remove(ISrsResource *c) = 0;
};
// The resource manager remove resource and delete it asynchronously.
class SrsResourceManager : public ISrsCoroutineHandler, public ISrsResourceManager
{
@ -74,8 +98,8 @@ private:
bool verbose_;
private:
SrsCoroutine *trd_;
srs_cond_t cond_;
ISrsCoroutine *trd_;
ISrsCond *cond_;
// Callback handlers.
std::vector<ISrsDisposingHandler *> handlers_;
// Unsubscribing handlers, skip it for notifying.
@ -212,122 +236,6 @@ public:
}
};
// If a connection is able be expired, user can use HTTP-API to kick-off it.
class ISrsExpire
{
public:
ISrsExpire();
virtual ~ISrsExpire();
public:
// Set connection to expired to kick-off it.
virtual void expire() = 0;
};
// The basic connection of SRS, for TCP based protocols,
// all connections accept from listener must extends from this base class,
// server will add the connection to manager, and delete it when remove.
class SrsTcpConnection : public ISrsProtocolReadWriter
{
private:
// The underlayer st fd handler.
srs_netfd_t stfd_;
// The underlayer socket.
SrsStSocket *skt_;
public:
SrsTcpConnection(srs_netfd_t c);
virtual ~SrsTcpConnection();
public:
// Set socket option TCP_NODELAY.
virtual srs_error_t set_tcp_nodelay(bool v);
// Set socket option SO_SNDBUF in srs_utime_t.
virtual srs_error_t set_socket_buffer(srs_utime_t buffer_v);
// Interface ISrsProtocolReadWriter
public:
virtual void set_recv_timeout(srs_utime_t tm);
virtual srs_utime_t get_recv_timeout();
virtual srs_error_t read_fully(void *buf, size_t size, ssize_t *nread);
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
virtual srs_error_t read(void *buf, size_t size, ssize_t *nread);
virtual void set_send_timeout(srs_utime_t tm);
virtual srs_utime_t get_send_timeout();
virtual srs_error_t write(void *buf, size_t size, ssize_t *nwrite);
virtual srs_error_t writev(const iovec *iov, int iov_size, ssize_t *nwrite);
};
// With a small fast read buffer, to support peek for protocol detecting. Note that directly write to io without any
// cache or buffer.
class SrsBufferedReadWriter : public ISrsProtocolReadWriter
{
private:
// The under-layer transport.
ISrsProtocolReadWriter *io_;
// Fixed, small and fast buffer. Note that it must be very small piece of cache, make sure matches all protocols,
// because we will full fill it when peeking.
char cache_[16];
// Current reading position.
SrsBuffer *buf_;
public:
SrsBufferedReadWriter(ISrsProtocolReadWriter *io);
virtual ~SrsBufferedReadWriter();
public:
// Peek the head of cache to buf in size of bytes.
srs_error_t peek(char *buf, int *size);
private:
srs_error_t reload_buffer();
// Interface ISrsProtocolReadWriter
public:
virtual srs_error_t read(void *buf, size_t size, ssize_t *nread);
virtual srs_error_t read_fully(void *buf, size_t size, ssize_t *nread);
virtual void set_recv_timeout(srs_utime_t tm);
virtual srs_utime_t get_recv_timeout();
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
virtual void set_send_timeout(srs_utime_t tm);
virtual srs_utime_t get_send_timeout();
virtual srs_error_t write(void *buf, size_t size, ssize_t *nwrite);
virtual srs_error_t writev(const iovec *iov, int iov_size, ssize_t *nwrite);
};
// The SSL connection over TCP transport, in server mode.
class SrsSslConnection : public ISrsProtocolReadWriter
{
private:
// The under-layer plaintext transport.
ISrsProtocolReadWriter *transport_;
private:
SSL_CTX *ssl_ctx_;
SSL *ssl_;
BIO *bio_in_;
BIO *bio_out_;
public:
SrsSslConnection(ISrsProtocolReadWriter *c);
virtual ~SrsSslConnection();
public:
virtual srs_error_t handshake(std::string key_file, std::string crt_file);
// Interface ISrsProtocolReadWriter
public:
virtual void set_recv_timeout(srs_utime_t tm);
virtual srs_utime_t get_recv_timeout();
virtual srs_error_t read_fully(void *buf, size_t size, ssize_t *nread);
virtual int64_t get_recv_bytes();
virtual int64_t get_send_bytes();
virtual srs_error_t read(void *buf, size_t size, ssize_t *nread);
virtual void set_send_timeout(srs_utime_t tm);
virtual srs_utime_t get_send_timeout();
virtual srs_error_t write(void *buf, size_t size, ssize_t *nwrite);
virtual srs_error_t writev(const iovec *iov, int iov_size, ssize_t *nwrite);
};
// Manager for RTC connections.
extern SrsResourceManager *_srs_conn_manager;

View File

@ -4,7 +4,7 @@
// SPDX-License-Identifier: MIT
//
#include <srs_app_rtc_queue.hpp>
#include <srs_kernel_rtc_queue.hpp>
#include <sstream>
#include <string.h>
@ -12,13 +12,12 @@
using namespace std;
#include <srs_app_circuit_breaker.hpp>
#include <srs_app_utility.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_log.hpp>
#include <srs_kernel_rtc_rtp.hpp>
#include <srs_kernel_utility.hpp>
#include <srs_protocol_kbps.hpp>
#include <srs_kernel_kbps.hpp>
extern SrsPps *_srs_pps_snack3;
extern SrsPps *_srs_pps_snack4;
@ -215,12 +214,6 @@ SrsRtpNackForReceiver::~SrsRtpNackForReceiver()
void SrsRtpNackForReceiver::insert(uint16_t first, uint16_t last)
{
// If circuit-breaker is enabled, disable nack.
if (_srs_circuit_breaker->hybrid_high_water_level()) {
++_srs_pps_snack4->sugar_;
return;
}
for (uint16_t s = first; s != last; ++s) {
queue_[s] = SrsRtpNackInfo();
}
@ -252,13 +245,6 @@ void SrsRtpNackForReceiver::check_queue_size()
void SrsRtpNackForReceiver::get_nack_seqs(SrsRtcpNack &seqs, uint32_t &timeout_nacks)
{
// If circuit-breaker is enabled, disable nack.
if (_srs_circuit_breaker->hybrid_high_water_level()) {
queue_.clear();
++_srs_pps_snack4->sugar_;
return;
}
srs_utime_t now = srs_time_now_cached();
srs_utime_t interval = now - pre_check_time_;

View File

@ -4,8 +4,8 @@
// SPDX-License-Identifier: MIT
//
#ifndef SRS_APP_RTC_QUEUE_HPP
#define SRS_APP_RTC_QUEUE_HPP
#ifndef SRS_KERNEL_RTC_QUEUE_HPP
#define SRS_KERNEL_RTC_QUEUE_HPP
#include <srs_core.hpp>

View File

@ -0,0 +1,71 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#include <srs_kernel_st.hpp>
ISrsCoroutineHandler::ISrsCoroutineHandler()
{
}
ISrsCoroutineHandler::~ISrsCoroutineHandler()
{
}
ISrsStartable::ISrsStartable()
{
}
ISrsStartable::~ISrsStartable()
{
}
ISrsInterruptable::ISrsInterruptable()
{
}
ISrsInterruptable::~ISrsInterruptable()
{
}
ISrsContextIdSetter::ISrsContextIdSetter()
{
}
ISrsContextIdSetter::~ISrsContextIdSetter()
{
}
ISrsContextIdGetter::ISrsContextIdGetter()
{
}
ISrsContextIdGetter::~ISrsContextIdGetter()
{
}
ISrsStoppable::ISrsStoppable()
{
}
ISrsStoppable::~ISrsStoppable()
{
}
ISrsCoroutine::ISrsCoroutine()
{
}
ISrsCoroutine::~ISrsCoroutine()
{
}
ISrsCond::ISrsCond()
{
}
ISrsCond::~ISrsCond()
{
}

View File

@ -0,0 +1,127 @@
//
// Copyright (c) 2013-2025 The SRS Authors
//
// SPDX-License-Identifier: MIT
//
#ifndef SRS_KERNEL_ST_HPP
#define SRS_KERNEL_ST_HPP
#include <srs_core.hpp>
// Each ST-coroutine must implements this interface,
// to do the cycle job and handle some events.
//
// Thread do a job then terminated normally, it's a SrsOneCycleThread:
// class SrsOneCycleThread : public ISrsCoroutineHandler {
// public: ISrsCoroutine trd;
// public: virtual srs_error_t cycle() {
// // Do something, then return this cycle and thread terminated normally.
// }
// };
//
// Thread has its inside loop, such as the RTMP receive thread:
// class SrsReceiveThread : public ISrsCoroutineHandler {
// public: ISrsCoroutine* trd;
// public: virtual srs_error_t cycle() {
// while (true) {
// // Check whether thread interrupted.
// if ((err = trd->pull()) != srs_success) {
// return err;
// }
// // Do something, such as st_read() packets, it'll be wakeup
// // when user stop or interrupt the thread.
// }
// }
// };
class ISrsCoroutineHandler
{
public:
ISrsCoroutineHandler();
virtual ~ISrsCoroutineHandler();
public:
// Do the work. The ST-coroutine will terminated normally if it returned.
// @remark If the cycle has its own loop, it must check the thread pull.
virtual srs_error_t cycle() = 0;
};
// Start the object, generally a coroutine.
class ISrsStartable
{
public:
ISrsStartable();
virtual ~ISrsStartable();
public:
virtual srs_error_t start() = 0;
};
// Allow user to interrupt the coroutine, for example, to stop it.
class ISrsInterruptable
{
public:
ISrsInterruptable();
virtual ~ISrsInterruptable();
public:
virtual void interrupt() = 0;
virtual srs_error_t pull() = 0;
};
// Get the context id.
class ISrsContextIdSetter
{
public:
ISrsContextIdSetter();
virtual ~ISrsContextIdSetter();
public:
virtual void set_cid(const SrsContextId &cid) = 0;
};
// Set the context id.
class ISrsContextIdGetter
{
public:
ISrsContextIdGetter();
virtual ~ISrsContextIdGetter();
public:
virtual const SrsContextId &cid() = 0;
};
// Stop the object, generally a coroutine.
class ISrsStoppable
{
public:
ISrsStoppable();
virtual ~ISrsStoppable();
public:
virtual void stop() = 0;
};
// The coroutine object.
class ISrsCoroutine : public ISrsStoppable, public ISrsStartable, public ISrsInterruptable, public ISrsContextIdSetter, public ISrsContextIdGetter
{
public:
ISrsCoroutine();
virtual ~ISrsCoroutine();
};
// The condition variable interface.
class ISrsCond
{
public:
ISrsCond();
virtual ~ISrsCond();
public:
virtual int wait() = 0;
virtual int timedwait(srs_utime_t timeout) = 0;
virtual int signal() = 0;
virtual int broadcast() = 0;
};
#endif

View File

@ -4,7 +4,7 @@
// SPDX-License-Identifier: BSD-3-Clause
//
#include <srs_app_uuid.hpp>
#include <srs_kernel_uuid.hpp>
#include <stdio.h>
#include <sys/file.h>
@ -125,18 +125,18 @@
#ifndef min
#define min(x, y) ({ \
__typeof__(x) _min1 = (x); \
__typeof__(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
__typeof__(x) _min1 = (x); \
__typeof__(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#endif
#ifndef max
#define max(x, y) ({ \
__typeof__(x) _max1 = (x); \
__typeof__(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
__typeof__(x) _max1 = (x); \
__typeof__(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#endif
#ifndef offsetof
@ -145,8 +145,8 @@
#ifndef container_of
#define container_of(ptr, type, member) ({ \
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) ); })
const __typeof__( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) ); })
#endif
#if 0
@ -604,6 +604,33 @@ static int flock(int fd, int op)
#endif /* LOCK_EX */
#if defined(HAVE_UUIDD) && defined(HAVE_SYS_UN_H)
// Helper function for reading all bytes
static ssize_t read_all(int fd, char *buf, size_t count)
{
ssize_t ret;
ssize_t c = 0;
int tries = 0;
memset(buf, 0, count);
while (count > 0) {
ret = read(fd, buf, count);
if (ret <= 0) {
if ((errno == EAGAIN || errno == EINTR) && (tries++ < 5))
continue;
return c ? c : -1;
}
if (ret > 0) {
tries = 0;
count -= ret;
buf += ret;
c += ret;
}
}
return c;
}
#endif
/*
* Get the ethernet hardware address, if we can find it...
*

Some files were not shown because too many files have changed in this diff Show More