diff --git a/README.md b/README.md index 7788883f0..a6f8b5504 100755 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ The ports used by SRS: - [x] [Experimental] Support pushing FLV over HTTP POST, please read wiki([CN][v4_CN_Streamer2], [EN][v4_EN_Streamer2]). - [x] [Experimental] Support HTTP RAW API, please read [#459][bug #459], [#470][bug #470], [#319][bug #319]. - [x] [Experimental] Support SRT server, read [#1147][bug #1147]. -- [x] [Deprecated] Support pushing RTSP, please read [bug #133][bug #133]. +- [x] [Deprecated] Support pushing RTSP, please read [bug #2304][bug #2304]. - [x] [Deprecated] Support RTMP client library: srs-librtmp([CN][v4_CN_SrsLibrtmp], [EN][v4_EN_SrsLibrtmp]) - [x] [Deprecated] Support Adobe HDS(f4m), please read wiki([CN][v4_CN_DeliveryHDS], [EN][v4_EN_DeliveryHDS]) and [#1535][bug #1535]. - [x] [Deprecated] Support bandwidth testing([CN][v4_CN_BandwidthTestTool], [EN][v4_EN_BandwidthTestTool]), please read [#1535][bug #1535]. @@ -182,6 +182,8 @@ The ports used by SRS: ## V4 changes +* v4.0, 2021-05-14, RTC: Remove [Object Cache Pool](https://github.com/ossrs/srs/commit/14bfc98122bba369572417c19ebb2a61b373fc45#commitcomment-47655008), no effect. 4.0.110 +* v4.0, 2021-05-14, Change virtual public to public. 4.0.109 * v4.0, 2021-05-14, Refine id and vid for statistic. 4.0.108 * v4.0, 2021-05-09, Refine tid for sdk and demos. 4.0.106 * v4.0, 2021-05-08, Refine shared fast timer. 4.0.105 @@ -649,7 +651,7 @@ The ports used by SRS: * v2.0, 2015-02-24, for [#304][bug #304], fix hls bug, write pts/dts error. 2.0.124 * v2.0, 2015-02-19, refine dvr, append file when dvr file exists. 2.0.122. * v2.0, 2015-02-19, refine pithy print to more easyer to use. 2.0.121. -* v2.0, 2015-02-18, fix [#133][bug #133], support push rtsp to srs. 2.0.120. +* v2.0, 2015-02-18, fix [#2304][bug #2304], support push rtsp to srs. 2.0.120. * v2.0, 2015-02-17, the join maybe failed, should use a variable to ensure thread terminated. 2.0.119. * v2.0, 2015-02-15, for [#304][bug #304], support config default acodec/vcodec. 2.0.118. * v2.0, 2015-02-15, for [#304][bug #304], rewrite hls/ts code, support h.264+mp3 for hls. 2.0.117. @@ -1921,6 +1923,7 @@ Winlin [bug #2093]: https://github.com/ossrs/srs/issues/2093 [bug #2188]: https://github.com/ossrs/srs/issues/2188 [bug #1193]: https://github.com/ossrs/srs/issues/1193 +[bug #2304]: https://github.com/ossrs/srs/issues/2304#issuecomment-826009290 [bug #yyyyyyyyyyyyy]: https://github.com/ossrs/srs/issues/yyyyyyyyyyyyy [bug #1631]: https://github.com/ossrs/srs/issues/1631 diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index ed655b423..2b8e36dc9 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -524,30 +524,6 @@ rtc_server { # TODO: FIXME: We should enable it when refined. # default: off perf_stat off; - # For RTP packet and its payload cache. - rtp_cache { - # Whether enable the RTP packet cache. - # default: on - enabled on; - # The cache size for rtp packet in MB, each object is about 300B.. - # default: 64 - pkt_size 64.0; - # The cache size for rtp payload in MB, each object is about 40B. - # default: 16 - payload_size 16.0; - } - # For RTP shared message and the large buffer cache. - rtp_msg_cache { - #Whether enable the RTP message(a large buffer) cache. - # default: on - enabled on; - # The cache size for message object in MB, each object is about 40B. - # default: 16 - msg_size 16.0; - # The cache size for message large buffer in MB, each object is about 1500B. - # default: 512 - buffer_size 512.0; - } # The black-hole to copy packet to, for debugging. # For example, when debugging Chrome publish stream, the received packets are encrypted cipher, # we can set the publisher black-hole, SRS will copy the plaintext packets to black-hole, and diff --git a/trunk/src/app/srs_app_caster_flv.hpp b/trunk/src/app/srs_app_caster_flv.hpp index 5042ebf6e..13800d17c 100644 --- a/trunk/src/app/srs_app_caster_flv.hpp +++ b/trunk/src/app/srs_app_caster_flv.hpp @@ -47,8 +47,7 @@ class SrsSimpleRtmpClient; #include // The stream caster for flv stream over HTTP POST. -class SrsAppCasterFlv : virtual public ISrsTcpHandler - , virtual public ISrsResourceManager, virtual public ISrsHttpHandler +class SrsAppCasterFlv : public ISrsTcpHandler, public ISrsResourceManager, public ISrsHttpHandler { private: std::string output; @@ -72,8 +71,7 @@ public: }; // The dynamic http connection, never drop the body. -class SrsDynamicHttpConn : virtual public ISrsStartableConneciton, virtual public ISrsHttpConnOwner - , virtual public ISrsReloadHandler +class SrsDynamicHttpConn : public ISrsStartableConneciton, public ISrsHttpConnOwner, public ISrsReloadHandler { private: // The manager object to manage the connection. diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 95b40bb40..6c9bb2d38 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -3679,7 +3679,7 @@ srs_error_t SrsConfig::check_normal_config() string n = conf->at(i)->name; if (n != "enabled" && n != "listen" && n != "dir" && n != "candidate" && n != "ecdsa" && n != "encrypt" && n != "reuseport" && n != "merge_nalus" && n != "perf_stat" && n != "black_hole" - && n != "ip_family" && n != "rtp_cache" && n != "rtp_msg_cache") { + && n != "ip_family") { return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal rtc_server.%s", n.c_str()); } } @@ -5050,138 +5050,6 @@ bool SrsConfig::get_rtc_server_perf_stat() return SRS_CONF_PERFER_FALSE(conf->arg0()); } -SrsConfDirective* SrsConfig::get_rtc_server_rtp_cache() -{ - SrsConfDirective* conf = root->get("rtc_server"); - if (!conf) { - return NULL; - } - - conf = conf->get("rtp_cache"); - if (!conf) { - return NULL; - } - - return conf; -} - -bool SrsConfig::get_rtc_server_rtp_cache_enabled() -{ - static bool DEFAULT = true; - - SrsConfDirective* conf = get_rtc_server_rtp_cache(); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("enabled"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return SRS_CONF_PERFER_TRUE(conf->arg0()); -} - -uint64_t SrsConfig::get_rtc_server_rtp_cache_pkt_size() -{ - int DEFAULT = 64 * 1024 * 1024; - - SrsConfDirective* conf = get_rtc_server_rtp_cache(); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("pkt_size"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); -} - -uint64_t SrsConfig::get_rtc_server_rtp_cache_payload_size() -{ - int DEFAULT = 16 * 1024 * 1024; - - SrsConfDirective* conf = get_rtc_server_rtp_cache(); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("payload_size"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); -} - -SrsConfDirective* SrsConfig::get_rtc_server_rtp_msg_cache() -{ - SrsConfDirective* conf = root->get("rtc_server"); - if (!conf) { - return NULL; - } - - conf = conf->get("rtp_msg_cache"); - if (!conf) { - return NULL; - } - - return conf; -} - -bool SrsConfig::get_rtc_server_rtp_msg_cache_enabled() -{ - static bool DEFAULT = true; - - SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("enabled"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return SRS_CONF_PERFER_TRUE(conf->arg0()); -} - -uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_msg_size() -{ - int DEFAULT = 16 * 1024 * 1024; - - SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("msg_size"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); -} - -uint64_t SrsConfig::get_rtc_server_rtp_msg_cache_buffer_size() -{ - int DEFAULT = 512 * 1024 * 1024; - - SrsConfDirective* conf = get_rtc_server_rtp_msg_cache(); - if (!conf) { - return DEFAULT; - } - - conf = conf->get("buffer_size"); - if (!conf || conf->arg0().empty()) { - return DEFAULT; - } - - return 1024 * (uint64_t)(1024 * ::atof(conf->arg0().c_str())); -} - bool SrsConfig::get_rtc_server_black_hole() { static bool DEFAULT = false; diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index bda02696e..13952d244 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -543,18 +543,6 @@ public: virtual int get_rtc_server_reuseport(); virtual bool get_rtc_server_merge_nalus(); virtual bool get_rtc_server_perf_stat(); -private: - SrsConfDirective* get_rtc_server_rtp_cache(); -public: - virtual bool get_rtc_server_rtp_cache_enabled(); - virtual uint64_t get_rtc_server_rtp_cache_pkt_size(); - virtual uint64_t get_rtc_server_rtp_cache_payload_size(); -private: - virtual SrsConfDirective* get_rtc_server_rtp_msg_cache(); -public: - virtual bool get_rtc_server_rtp_msg_cache_enabled(); - virtual uint64_t get_rtc_server_rtp_msg_cache_msg_size(); - virtual uint64_t get_rtc_server_rtp_msg_cache_buffer_size(); public: virtual bool get_rtc_server_black_hole(); virtual std::string get_rtc_server_black_hole_addr(); diff --git a/trunk/src/app/srs_app_conn.hpp b/trunk/src/app/srs_app_conn.hpp index c992c3fc2..dc6b30669 100644 --- a/trunk/src/app/srs_app_conn.hpp +++ b/trunk/src/app/srs_app_conn.hpp @@ -77,7 +77,7 @@ public: }; // The resource manager remove resource and delete it asynchronously. -class SrsResourceManager : virtual public ISrsCoroutineHandler, virtual public ISrsResourceManager +class SrsResourceManager : public ISrsCoroutineHandler, public ISrsResourceManager { private: std::string label_; @@ -153,8 +153,8 @@ public: }; // Interface for connection that is startable. -class ISrsStartableConneciton : virtual public ISrsConnection - , virtual public ISrsStartable, virtual public ISrsKbpsDelta +class ISrsStartableConneciton : public ISrsConnection + , public ISrsStartable, public ISrsKbpsDelta { public: ISrsStartableConneciton(); @@ -164,7 +164,7 @@ public: // 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 : virtual public ISrsProtocolReadWriter +class SrsTcpConnection : public ISrsProtocolReadWriter { private: // The underlayer st fd handler. @@ -196,7 +196,7 @@ public: }; // The SSL connection over TCP transport, in server mode. -class SrsSslConnection : virtual public ISrsProtocolReadWriter +class SrsSslConnection : public ISrsProtocolReadWriter { private: // The under-layer plaintext transport. diff --git a/trunk/src/app/srs_app_http_api.cpp b/trunk/src/app/srs_app_http_api.cpp index 1a720d0f6..2be7e670e 100644 --- a/trunk/src/app/srs_app_http_api.cpp +++ b/trunk/src/app/srs_app_http_api.cpp @@ -1303,95 +1303,6 @@ srs_error_t SrsGoApiClusters::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMess return srs_api_response(w, r, obj->dumps()); } -SrsGoApiPerf::SrsGoApiPerf() -{ -} - -SrsGoApiPerf::~SrsGoApiPerf() -{ -} - -srs_error_t SrsGoApiPerf::serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r) -{ - srs_error_t err = srs_success; - - SrsJsonObject* obj = SrsJsonAny::object(); - SrsAutoFree(SrsJsonObject, obj); - - obj->set("code", SrsJsonAny::integer(ERROR_SUCCESS)); - SrsJsonObject* data = SrsJsonAny::object(); - obj->set("data", data); - - SrsStatistic* stat = SrsStatistic::instance(); - - string target = r->query_get("target"); - string reset = r->query_get("reset"); - srs_trace("query target=%s, reset=%s, rtc_stat_enabled=%d", target.c_str(), reset.c_str(), - _srs_config->get_rtc_server_perf_stat()); - - if (true) { - SrsJsonObject* p = SrsJsonAny::object(); - data->set("query", p); - - p->set("target", SrsJsonAny::str(target.c_str())); - p->set("reset", SrsJsonAny::str(reset.c_str())); - p->set("help", SrsJsonAny::str("?target=avframes|rtc|rtp|writev_iovs|bytes")); - p->set("help2", SrsJsonAny::str("?reset=all")); - } - - if (!reset.empty()) { - stat->reset_perf(); - return srs_api_response(w, r, obj->dumps()); - } - - if (target.empty() || target == "avframes") { - SrsJsonObject* p = SrsJsonAny::object(); - data->set("avframes", p); - if ((err = stat->dumps_perf_msgs(p)) != srs_success) { - int code = srs_error_code(err); srs_error_reset(err); - return srs_api_response_code(w, r, code); - } - } - - if (target.empty() || target == "rtc") { - SrsJsonObject* p = SrsJsonAny::object(); - data->set("rtc", p); - if ((err = stat->dumps_perf_rtc_packets(p)) != srs_success) { - int code = srs_error_code(err); srs_error_reset(err); - return srs_api_response_code(w, r, code); - } - } - - if (target.empty() || target == "rtp") { - SrsJsonObject* p = SrsJsonAny::object(); - data->set("rtp", p); - if ((err = stat->dumps_perf_rtp_packets(p)) != srs_success) { - int code = srs_error_code(err); srs_error_reset(err); - return srs_api_response_code(w, r, code); - } - } - - if (target.empty() || target == "writev_iovs") { - SrsJsonObject* p = SrsJsonAny::object(); - data->set("writev_iovs", p); - if ((err = stat->dumps_perf_writev_iovs(p)) != srs_success) { - int code = srs_error_code(err); srs_error_reset(err); - return srs_api_response_code(w, r, code); - } - } - - if (target.empty() || target == "bytes") { - SrsJsonObject* p = SrsJsonAny::object(); - data->set("bytes", p); - if ((err = stat->dumps_perf_bytes(p)) != srs_success) { - int code = srs_error_code(err); srs_error_reset(err); - return srs_api_response_code(w, r, code); - } - } - - return srs_api_response(w, r, obj->dumps()); -} - SrsGoApiError::SrsGoApiError() { } diff --git a/trunk/src/app/srs_app_http_api.hpp b/trunk/src/app/srs_app_http_api.hpp index a7479e2c6..87d55d5bf 100644 --- a/trunk/src/app/srs_app_http_api.hpp +++ b/trunk/src/app/srs_app_http_api.hpp @@ -185,7 +185,7 @@ public: virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); }; -class SrsGoApiRaw : virtual public ISrsHttpHandler, virtual public ISrsReloadHandler +class SrsGoApiRaw : public ISrsHttpHandler, public ISrsReloadHandler { private: SrsServer* server; @@ -213,15 +213,6 @@ public: virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); }; -class SrsGoApiPerf : public ISrsHttpHandler -{ -public: - SrsGoApiPerf(); - virtual ~SrsGoApiPerf(); -public: - virtual srs_error_t serve_http(ISrsHttpResponseWriter* w, ISrsHttpMessage* r); -}; - class SrsGoApiError : public ISrsHttpHandler { public: @@ -256,8 +247,8 @@ public: #endif // Handle the HTTP API request. -class SrsHttpApi : virtual public ISrsStartableConneciton, virtual public ISrsHttpConnOwner - , virtual public ISrsReloadHandler +class SrsHttpApi : public ISrsStartableConneciton, public ISrsHttpConnOwner + , public ISrsReloadHandler { private: // The manager object to manage the connection. diff --git a/trunk/src/app/srs_app_http_conn.hpp b/trunk/src/app/srs_app_http_conn.hpp index b7c2b7fb3..4331fefe8 100644 --- a/trunk/src/app/srs_app_http_conn.hpp +++ b/trunk/src/app/srs_app_http_conn.hpp @@ -75,8 +75,8 @@ public: }; // The http connection which request the static or stream content. -class SrsHttpConn : virtual public ISrsStartableConneciton, virtual public ISrsCoroutineHandler - , virtual public ISrsExpire +class SrsHttpConn : public ISrsStartableConneciton, public ISrsCoroutineHandler + , public ISrsExpire { protected: SrsHttpParser* parser; @@ -143,8 +143,8 @@ public: }; // Drop body of request, only process the response. -class SrsResponseOnlyHttpConn : virtual public ISrsStartableConneciton, virtual public ISrsHttpConnOwner - , virtual public ISrsReloadHandler +class SrsResponseOnlyHttpConn : public ISrsStartableConneciton, public ISrsHttpConnOwner + , public ISrsReloadHandler { private: // The manager object to manage the connection. diff --git a/trunk/src/app/srs_app_http_static.hpp b/trunk/src/app/srs_app_http_static.hpp index 6852c6588..1595809ee 100644 --- a/trunk/src/app/srs_app_http_static.hpp +++ b/trunk/src/app/srs_app_http_static.hpp @@ -44,7 +44,7 @@ protected: // The http static server instance, // serve http static file and flv/mp4 vod stream. -class SrsHttpStaticServer : virtual public ISrsReloadHandler +class SrsHttpStaticServer : public ISrsReloadHandler { private: SrsServer* server; diff --git a/trunk/src/app/srs_app_http_stream.hpp b/trunk/src/app/srs_app_http_stream.hpp index 82d62db39..de8a25d87 100755 --- a/trunk/src/app/srs_app_http_stream.hpp +++ b/trunk/src/app/srs_app_http_stream.hpp @@ -231,8 +231,8 @@ public: // The HTTP Live Streaming Server, to serve FLV/TS/MP3/AAC stream. // TODO: Support multiple stream. -class SrsHttpStreamServer : virtual public ISrsReloadHandler -, virtual public ISrsHttpMatchHijacker +class SrsHttpStreamServer : public ISrsReloadHandler +, public ISrsHttpMatchHijacker { private: SrsServer* server; diff --git a/trunk/src/app/srs_app_hybrid.cpp b/trunk/src/app/srs_app_hybrid.cpp index b608f2cd5..764644f8a 100644 --- a/trunk/src/app/srs_app_hybrid.cpp +++ b/trunk/src/app/srs_app_hybrid.cpp @@ -374,29 +374,20 @@ srs_error_t SrsHybridServer::on_timer(srs_utime_t interval) #endif string objs_desc; - _srs_pps_objs_rtps->update(); _srs_pps_objs_rraw->update(); _srs_pps_objs_rfua->update(); _srs_pps_objs_rbuf->update(); _srs_pps_objs_msgs->update(); _srs_pps_objs_rothers->update(); _srs_pps_objs_drop->update(); - if (_srs_pps_objs_rtps->r10s() || _srs_pps_objs_rraw->r10s() || _srs_pps_objs_rfua->r10s() || _srs_pps_objs_rbuf->r10s() || _srs_pps_objs_msgs->r10s() || _srs_pps_objs_rothers->r10s() || _srs_pps_objs_drop->r10s()) { - snprintf(buf, sizeof(buf), ", objs=(pkt:%d,raw:%d,fua:%d,msg:%d,oth:%d,buf:%d,drop:%d)", + _srs_pps_objs_rtps->update(); _srs_pps_objs_rraw->update(); _srs_pps_objs_rfua->update(); _srs_pps_objs_rbuf->update(); _srs_pps_objs_msgs->update(); _srs_pps_objs_rothers->update(); + if (_srs_pps_objs_rtps->r10s() || _srs_pps_objs_rraw->r10s() || _srs_pps_objs_rfua->r10s() || _srs_pps_objs_rbuf->r10s() || _srs_pps_objs_msgs->r10s() || _srs_pps_objs_rothers->r10s()) { + snprintf(buf, sizeof(buf), ", objs=(pkt:%d,raw:%d,fua:%d,msg:%d,oth:%d,buf:%d)", _srs_pps_objs_rtps->r10s(), _srs_pps_objs_rraw->r10s(), _srs_pps_objs_rfua->r10s(), - _srs_pps_objs_msgs->r10s(), _srs_pps_objs_rothers->r10s(), _srs_pps_objs_rbuf->r10s(), _srs_pps_objs_drop->r10s()); + _srs_pps_objs_msgs->r10s(), _srs_pps_objs_rothers->r10s(), _srs_pps_objs_rbuf->r10s()); objs_desc = buf; } - string cache_desc; - if (_srs_rtp_cache->size() || _srs_rtp_raw_cache->size() || _srs_rtp_fua_cache->size() || _srs_rtp_msg_cache_buffers->size() || _srs_rtp_msg_cache_objs->size()) { - snprintf(buf, sizeof(buf), ", cache=(pkt:%d-%dw,raw:%d-%dw,fua:%d-%dw,msg:%d-%dw,buf:%d-%dw)", - _srs_rtp_cache->size(), _srs_rtp_cache->capacity()/10000, _srs_rtp_raw_cache->size(), _srs_rtp_raw_cache->capacity()/10000, - _srs_rtp_fua_cache->size(), _srs_rtp_fua_cache->capacity()/10000, _srs_rtp_msg_cache_objs->size(), _srs_rtp_msg_cache_objs->capacity()/10000, - _srs_rtp_msg_cache_buffers->size(), _srs_rtp_msg_cache_buffers->capacity()/10000); - cache_desc = buf; - } - - srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s%s%s%s%s", + srs_trace("Hybrid cpu=%.2f%%,%dMB%s%s%s%s%s%s%s%s%s%s%s", u->percent * 100, memory, cid_desc.c_str(), timer_desc.c_str(), recvfrom_desc.c_str(), io_desc.c_str(), msg_desc.c_str(), epoll_desc.c_str(), sched_desc.c_str(), clock_desc.c_str(), - thread_desc.c_str(), free_desc.c_str(), objs_desc.c_str(), cache_desc.c_str() + thread_desc.c_str(), free_desc.c_str(), objs_desc.c_str() ); return err; diff --git a/trunk/src/app/srs_app_mpegts_udp.hpp b/trunk/src/app/srs_app_mpegts_udp.hpp index c6aeaa27a..64efe84e7 100644 --- a/trunk/src/app/srs_app_mpegts_udp.hpp +++ b/trunk/src/app/srs_app_mpegts_udp.hpp @@ -67,7 +67,7 @@ public: }; // The mpegts over udp stream caster. -class SrsMpegtsOverUdp : virtual public ISrsTsHandler, virtual public ISrsUdpHandler +class SrsMpegtsOverUdp : public ISrsTsHandler, public ISrsUdpHandler { private: SrsTsContext* context; diff --git a/trunk/src/app/srs_app_recv_thread.cpp b/trunk/src/app/srs_app_recv_thread.cpp index 55046ea90..5376df700 100644 --- a/trunk/src/app/srs_app_recv_thread.cpp +++ b/trunk/src/app/srs_app_recv_thread.cpp @@ -190,9 +190,6 @@ SrsQueueRecvThread::~SrsQueueRecvThread() srs_error_t SrsQueueRecvThread::start() { srs_error_t err = srs_success; - - SrsStatistic* stat = SrsStatistic::instance(); - rtmp->set_perf(stat); if ((err = trd.start()) != srs_success) { return srs_error_wrap(err, "queue recv thread"); diff --git a/trunk/src/app/srs_app_recv_thread.hpp b/trunk/src/app/srs_app_recv_thread.hpp index d6fb7f8db..792b862c0 100644 --- a/trunk/src/app/srs_app_recv_thread.hpp +++ b/trunk/src/app/srs_app_recv_thread.hpp @@ -138,9 +138,9 @@ public: // The publish recv thread got message and callback the source method to process message. // @see: https://github.com/ossrs/srs/issues/237 -class SrsPublishRecvThread : virtual public ISrsMessagePumper, virtual public ISrsReloadHandler +class SrsPublishRecvThread : public ISrsMessagePumper, public ISrsReloadHandler #ifdef SRS_PERF_MERGED_READ - , virtual public IMergeReadHandler + , public IMergeReadHandler #endif { private: diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index 3ff7ae51e..b624e8c4d 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -460,9 +460,6 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::mapset_nack_no_copy(nack_no_copy_); } - // Update stat for session. - session_->stat_->nn_subscribers++; - return err; } @@ -615,9 +612,9 @@ srs_error_t SrsRtcPlayStream::cycle() srs_freep(err); } - // Release the packet to cache. + // Free the packet. // @remark Note that the pkt might be set to NULL. - _srs_rtp_cache->recycle(pkt); + srs_freep(pkt); } } @@ -745,8 +742,6 @@ srs_error_t SrsRtcPlayStream::on_rtcp_rr(SrsRtcpRR* rtcp) // TODO: FIXME: Implements it. - session_->stat_->nn_sr++; - return err; } @@ -756,8 +751,6 @@ srs_error_t SrsRtcPlayStream::on_rtcp_xr(SrsRtcpXr* rtcp) // TODO: FIXME: Implements it. - session_->stat_->nn_xr++; - return err; } @@ -807,8 +800,6 @@ srs_error_t SrsRtcPlayStream::on_rtcp_nack(SrsRtcpNack* rtcp) return srs_error_wrap(err, "track response nack. id:%s, ssrc=%u", target->get_track_id().c_str(), ssrc); } - session_->stat_->nn_nack++; - return err; } @@ -823,8 +814,6 @@ srs_error_t SrsRtcPlayStream::on_rtcp_ps_feedback(SrsRtcpPsfbCommon* rtcp) if (ssrc) { pli_worker_->request_keyframe(ssrc, cid_); } - - session_->stat_->nn_pli++; break; } case kSLI: { @@ -1074,9 +1063,6 @@ srs_error_t SrsRtcPublishStream::initialize(SrsRequest* r, SrsRtcStreamDescripti track->set_nack_no_copy(nack_no_copy_); } - // Update stat for session. - session_->stat_->nn_publishers++; - // Setup the publish stream in source to enable PLI as such. if ((err = _srs_rtc_sources->fetch_or_create(req, &source)) != srs_success) { return srs_error_wrap(err, "create source"); @@ -1193,8 +1179,6 @@ srs_error_t SrsRtcPublishStream::send_rtcp_rr() } } - session_->stat_->nn_rr++; - return err; } @@ -1216,8 +1200,6 @@ srs_error_t SrsRtcPublishStream::send_rtcp_xr_rrtr() } } - session_->stat_->nn_xr++; - return err; } @@ -1227,8 +1209,6 @@ srs_error_t SrsRtcPublishStream::on_twcc(uint16_t sn) { srs_utime_t now = srs_get_system_time(); err = rtcp_twcc_.recv_packet(sn, now); - session_->stat_->nn_in_twcc++; - return err; } @@ -1236,8 +1216,6 @@ srs_error_t SrsRtcPublishStream::on_rtp(char* data, int nb_data) { srs_error_t err = srs_success; - session_->stat_->nn_in_rtp++; - // For NACK simulator, drop packet. if (nn_simulate_nack_drop) { SrsBuffer b(data, nb_data); SrsRtpHeader h; h.ignore_padding(true); @@ -1309,10 +1287,7 @@ srs_error_t SrsRtcPublishStream::on_rtp_plaintext(char* plaintext, int nb_plaint } // Allocate packet form cache. - SrsRtpPacket2* pkt = _srs_rtp_cache->allocate(); - - // It's better to reset it before decode it. - pkt->reset(); + SrsRtpPacket2* pkt = new SrsRtpPacket2(); // Copy the packet body. char* p = pkt->wrap(plaintext, nb_plaintext); @@ -1323,9 +1298,9 @@ srs_error_t SrsRtcPublishStream::on_rtp_plaintext(char* plaintext, int nb_plaint // @remark Note that the pkt might be set to NULL. err = do_on_rtp_plaintext(pkt, &buf); - // Release the packet to cache. + // Free the packet. // @remark Note that the pkt might be set to NULL. - _srs_rtp_cache->recycle(pkt); + srs_freep(pkt); return err; } @@ -1586,8 +1561,6 @@ srs_error_t SrsRtcPublishStream::do_request_keyframe(uint32_t ssrc, SrsContextId srs_freep(err); } - session_->stat_->nn_pli++; - return err; } @@ -1655,51 +1628,6 @@ void SrsRtcPublishStream::update_send_report_time(uint32_t ssrc, const SrsNtp& n } } -SrsRtcConnectionStatistic::SrsRtcConnectionStatistic() -{ - dead = born = srs_get_system_time(); - nn_publishers = nn_subscribers = 0; - nn_rr = nn_xr = 0; - nn_sr = nn_nack = nn_pli = 0; - nn_in_twcc = nn_in_rtp = nn_in_audios = nn_in_videos = 0; - nn_out_twcc = nn_out_rtp = nn_out_audios = nn_out_videos = 0; -} - -SrsRtcConnectionStatistic::~SrsRtcConnectionStatistic() -{ -} - -string SrsRtcConnectionStatistic::summary() -{ - dead = srs_get_system_time(); - - stringstream ss; - - ss << "alive=" << srsu2msi(dead - born) << "ms"; - - if (nn_publishers) ss << ", npub=" << nn_publishers; - if (nn_subscribers) ss << ", nsub=" << nn_subscribers; - - if (nn_rr) ss << ", nrr=" << nn_rr; - if (nn_xr) ss << ", nxr=" << nn_xr; - - if (nn_sr) ss << ", nsr=" << nn_sr; - if (nn_nack) ss << ", nnack=" << nn_nack; - if (nn_pli) ss << ", npli=" << nn_pli; - - if (nn_in_twcc) ss << ", in_ntwcc=" << nn_in_twcc; - if (nn_in_rtp) ss << ", in_nrtp=" << nn_in_rtp; - if (nn_in_audios) ss << ", in_naudio=" << nn_in_audios; - if (nn_in_videos) ss << ", in_nvideo=" << nn_in_videos; - - if (nn_out_twcc) ss << ", out_ntwcc=" << nn_out_twcc; - if (nn_out_rtp) ss << ", out_nrtp=" << nn_out_rtp; - if (nn_out_audios) ss << ", out_naudio=" << nn_out_audios; - if (nn_out_videos) ss << ", out_nvideo=" << nn_out_videos; - - return ss.str(); -} - ISrsRtcConnectionHijacker::ISrsRtcConnectionHijacker() { } @@ -1751,7 +1679,6 @@ SrsRtcConnection::SrsRtcConnection(SrsRtcServer* s, const SrsContextId& cid) { req = NULL; cid_ = cid; - stat_ = new SrsRtcConnectionStatistic(); hijacker_ = NULL; sendonly_skt = NULL; @@ -1818,7 +1745,6 @@ SrsRtcConnection::~SrsRtcConnection() srs_freep(transport_); srs_freep(req); - srs_freep(stat_); srs_freep(pp_address_change); srs_freep(pli_epp); } @@ -2304,8 +2230,7 @@ srs_error_t SrsRtcConnection::on_dtls_alert(std::string type, std::string desc) SrsContextRestore(_srs_context->get_id()); switch_to_context(); - srs_trace("RTC: session destroy by DTLS alert, username=%s, summary: %s", - username_.c_str(), stat_->summary().c_str()); + srs_trace("RTC: session destroy by DTLS alert, username=%s", username_.c_str()); _srs_rtc_manager->remove(this); } diff --git a/trunk/src/app/srs_app_rtc_conn.hpp b/trunk/src/app/srs_app_rtc_conn.hpp index b57ef5b34..9010f87ae 100644 --- a/trunk/src/app/srs_app_rtc_conn.hpp +++ b/trunk/src/app/srs_app_rtc_conn.hpp @@ -192,7 +192,7 @@ public: }; // A worker coroutine to request the PLI. -class SrsRtcPLIWorker : virtual public ISrsCoroutineHandler +class SrsRtcPLIWorker : public ISrsCoroutineHandler { private: SrsCoroutine* trd_; @@ -394,24 +394,6 @@ private: void update_send_report_time(uint32_t ssrc, const SrsNtp& ntp); }; -// The statistics for RTC connection. -class SrsRtcConnectionStatistic -{ -public: - int nn_publishers; int nn_subscribers; - int nn_rr; int nn_xr; int nn_sr; int nn_nack; int nn_pli; - uint64_t nn_in_twcc; uint64_t nn_in_rtp; uint64_t nn_in_audios; uint64_t nn_in_videos; - uint64_t nn_out_twcc; uint64_t nn_out_rtp; uint64_t nn_out_audios; uint64_t nn_out_videos; -private: - srs_utime_t born; - srs_utime_t dead; -public: - SrsRtcConnectionStatistic(); - virtual ~SrsRtcConnectionStatistic(); -public: - std::string summary(); -}; - // Callback for RTC connection. class ISrsRtcConnectionHijacker { @@ -437,7 +419,7 @@ private: // A RTC Peer Connection, SDP level object. // -// For performance, we use non-virtual public from resource, +// For performance, we use non-public from resource, // see https://stackoverflow.com/questions/3747066/c-cannot-convert-from-base-a-to-derived-type-b-via-virtual-base-a class SrsRtcConnection : public ISrsResource, public ISrsDisposingHandler { @@ -449,7 +431,6 @@ private: SrsRtcConnectionNackTimer* timer_nack_; public: bool disposing_; - SrsRtcConnectionStatistic* stat_; ISrsRtcConnectionHijacker* hijacker_; private: SrsRtcServer* server_; diff --git a/trunk/src/app/srs_app_rtc_dtls.hpp b/trunk/src/app/srs_app_rtc_dtls.hpp index 0938f30c6..30eedb231 100644 --- a/trunk/src/app/srs_app_rtc_dtls.hpp +++ b/trunk/src/app/srs_app_rtc_dtls.hpp @@ -144,7 +144,7 @@ protected: virtual bool is_dtls_client() = 0; }; -class SrsDtlsClientImpl : virtual public SrsDtlsImpl, virtual public ISrsCoroutineHandler +class SrsDtlsClientImpl : public SrsDtlsImpl, public ISrsCoroutineHandler { private: // ARQ thread, for role active(DTLS client). diff --git a/trunk/src/app/srs_app_rtc_queue.cpp b/trunk/src/app/srs_app_rtc_queue.cpp index c398fcc5f..fe3b40a66 100644 --- a/trunk/src/app/srs_app_rtc_queue.cpp +++ b/trunk/src/app/srs_app_rtc_queue.cpp @@ -55,7 +55,7 @@ SrsRtpRingBuffer::~SrsRtpRingBuffer() { for (int i = 0; i < capacity_; ++i) { SrsRtpPacket2* pkt = queue_[i]; - _srs_rtp_cache->recycle(pkt); + srs_freep(pkt); } srs_freepa(queue_); } @@ -80,10 +80,7 @@ void SrsRtpRingBuffer::advance_to(uint16_t seq) void SrsRtpRingBuffer::set(uint16_t at, SrsRtpPacket2* pkt) { SrsRtpPacket2* p = queue_[at % capacity_]; - - if (p) { - _srs_rtp_cache->recycle(p); - } + srs_freep(p); queue_[at % capacity_] = pkt; } @@ -170,7 +167,7 @@ void SrsRtpRingBuffer::clear_histroy(uint16_t seq) for (uint16_t i = 0; i < capacity_; i++) { SrsRtpPacket2* p = queue_[i]; if (p && p->header.get_sequence() < seq) { - _srs_rtp_cache->recycle(p); + srs_freep(p); queue_[i] = NULL; } } @@ -181,7 +178,7 @@ void SrsRtpRingBuffer::clear_all_histroy() for (uint16_t i = 0; i < capacity_; i++) { SrsRtpPacket2* p = queue_[i]; if (p) { - _srs_rtp_cache->recycle(p); + srs_freep(p); queue_[i] = NULL; } } diff --git a/trunk/src/app/srs_app_rtc_server.cpp b/trunk/src/app/srs_app_rtc_server.cpp index c71e94b8f..c7a062376 100644 --- a/trunk/src/app/srs_app_rtc_server.cpp +++ b/trunk/src/app/srs_app_rtc_server.cpp @@ -289,61 +289,11 @@ srs_error_t SrsRtcServer::initialize() return srs_error_wrap(err, "black hole"); } - bool rtp_cache_enabled = _srs_config->get_rtc_server_rtp_cache_enabled(); - uint64_t rtp_cache_pkt_size = _srs_config->get_rtc_server_rtp_cache_pkt_size(); - uint64_t rtp_cache_payload_size = _srs_config->get_rtc_server_rtp_cache_payload_size(); - _srs_rtp_cache->setup(rtp_cache_enabled, rtp_cache_pkt_size); - _srs_rtp_raw_cache->setup(rtp_cache_enabled, rtp_cache_payload_size); - _srs_rtp_fua_cache->setup(rtp_cache_enabled, rtp_cache_payload_size); - - bool rtp_msg_cache_enabled = _srs_config->get_rtc_server_rtp_msg_cache_enabled(); - uint64_t rtp_msg_cache_msg_size = _srs_config->get_rtc_server_rtp_msg_cache_msg_size(); - uint64_t rtp_msg_cache_buffer_size = _srs_config->get_rtc_server_rtp_msg_cache_buffer_size(); - _srs_rtp_msg_cache_buffers->setup(rtp_msg_cache_enabled, rtp_msg_cache_buffer_size); - _srs_rtp_msg_cache_objs->setup(rtp_msg_cache_enabled, rtp_msg_cache_msg_size); - - srs_trace("RTC: Object cache init, rtp-cache=(enabled:%d,pkt:%dm-%dw,payload:%dm-%dw-%dw), msg-cache=(enabled:%d,obj:%dm-%dw,buf:%dm-%dw)", - rtp_cache_enabled, (int)(rtp_cache_pkt_size/1024/1024), _srs_rtp_cache->capacity()/10000, - (int)(rtp_cache_payload_size/1024/1024), _srs_rtp_raw_cache->capacity()/10000, _srs_rtp_fua_cache->capacity()/10000, - rtp_msg_cache_enabled, (int)(rtp_msg_cache_msg_size/1024/1024), _srs_rtp_msg_cache_objs->capacity()/10000, - (int)(rtp_msg_cache_buffer_size/1024/1024), _srs_rtp_msg_cache_buffers->capacity()/10000); - return err; } srs_error_t SrsRtcServer::on_reload_rtc_server() { - bool changed = false; - - bool rtp_cache_enabled = _srs_config->get_rtc_server_rtp_cache_enabled(); - uint64_t rtp_cache_pkt_size = _srs_config->get_rtc_server_rtp_cache_pkt_size(); - uint64_t rtp_cache_payload_size = _srs_config->get_rtc_server_rtp_cache_payload_size(); - if (_srs_rtp_cache->enabled() != rtp_cache_enabled) { - _srs_rtp_cache->setup(rtp_cache_enabled, rtp_cache_pkt_size); - _srs_rtp_raw_cache->setup(rtp_cache_enabled, rtp_cache_payload_size); - _srs_rtp_fua_cache->setup(rtp_cache_enabled, rtp_cache_payload_size); - - changed = true; - } - - bool rtp_msg_cache_enabled = _srs_config->get_rtc_server_rtp_msg_cache_enabled(); - uint64_t rtp_msg_cache_msg_size = _srs_config->get_rtc_server_rtp_msg_cache_msg_size(); - uint64_t rtp_msg_cache_buffer_size = _srs_config->get_rtc_server_rtp_msg_cache_buffer_size(); - if (_srs_rtp_msg_cache_buffers->enabled() != rtp_msg_cache_enabled) { - _srs_rtp_msg_cache_buffers->setup(rtp_msg_cache_enabled, rtp_msg_cache_buffer_size); - _srs_rtp_msg_cache_objs->setup(rtp_msg_cache_enabled, rtp_msg_cache_msg_size); - - changed = true; - } - - if (changed) { - srs_trace("RTC: Object cache reload, rtp-cache=(enabled:%d,pkt:%dm-%dw,payload:%dm-%dw-%dw), msg-cache=(enabled:%d,obj:%dm-%dw,buf:%dm-%dw)", - rtp_cache_enabled, (int)(rtp_cache_pkt_size/1024/1024), _srs_rtp_cache->capacity()/10000, - (int)(rtp_cache_payload_size/1024/1024), _srs_rtp_raw_cache->capacity()/10000, _srs_rtp_fua_cache->capacity()/10000, - rtp_msg_cache_enabled, (int)(rtp_msg_cache_msg_size/1024/1024), _srs_rtp_msg_cache_objs->capacity()/10000, - (int)(rtp_msg_cache_buffer_size/1024/1024), _srs_rtp_msg_cache_buffers->capacity()/10000); - } - return srs_success; } @@ -659,8 +609,7 @@ srs_error_t SrsRtcServer::on_timer(srs_utime_t interval) session->switch_to_context(); string username = session->username(); - srs_trace("RTC: session destroy by timeout, username=%s, summary: %s", username.c_str(), - session->stat_->summary().c_str()); + srs_trace("RTC: session destroy by timeout, username=%s", username.c_str()); // Use manager to free session and notify other objects. _srs_rtc_manager->remove(session); diff --git a/trunk/src/app/srs_app_rtc_source.cpp b/trunk/src/app/srs_app_rtc_source.cpp index 1948b4798..6b789a55f 100644 --- a/trunk/src/app/srs_app_rtc_source.cpp +++ b/trunk/src/app/srs_app_rtc_source.cpp @@ -178,7 +178,7 @@ SrsRtcConsumer::~SrsRtcConsumer() vector::iterator it; for (it = queue.begin(); it != queue.end(); ++it) { SrsRtpPacket2* pkt = *it; - _srs_rtp_cache->recycle(pkt); + srs_freep(pkt); } srs_cond_destroy(mw_wait); @@ -661,19 +661,6 @@ srs_error_t SrsRtcStream::on_timer(srs_utime_t interval) return err; } -SrsRtpPacketCacheHelper::SrsRtpPacketCacheHelper() -{ - pkt = _srs_rtp_cache->allocate(); - - // We MUST reset the packet, when got from cache. - pkt->reset(); -} - -SrsRtpPacketCacheHelper::~SrsRtpPacketCacheHelper() -{ - _srs_rtp_cache->recycle(pkt); -} - #ifdef SRS_FFMPEG_FIT SrsRtcFromRtmpBridger::SrsRtcFromRtmpBridger(SrsRtcStream* source) { @@ -844,45 +831,46 @@ srs_error_t SrsRtcFromRtmpBridger::on_audio(SrsSharedPtrMessage* msg) return err; } -srs_error_t SrsRtcFromRtmpBridger::transcode(SrsAudioFrame* pkt) +srs_error_t SrsRtcFromRtmpBridger::transcode(SrsAudioFrame* audio) { srs_error_t err = srs_success; - std::vector out_pkts; - if ((err = codec_->transcode(pkt, out_pkts)) != srs_success) { + std::vector out_audios; + if ((err = codec_->transcode(audio, out_audios)) != srs_success) { return srs_error_wrap(err, "recode error"); } // Save OPUS packets in shared message. - if (out_pkts.empty()) { + if (out_audios.empty()) { return err; } - for (std::vector::iterator it = out_pkts.begin(); it != out_pkts.end(); ++it) { - SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper(); - SrsAutoFree(SrsRtpPacketCacheHelper, helper); + for (std::vector::iterator it = out_audios.begin(); it != out_audios.end(); ++it) { + SrsAudioFrame* out_audio = *it; + + SrsRtpPacket2* pkt = new SrsRtpPacket2(); + SrsAutoFree(SrsRtpPacket2, pkt); - if ((err = package_opus(*it, helper)) != srs_success) { + if ((err = package_opus(out_audio, pkt)) != srs_success) { err = srs_error_wrap(err, "package opus"); break; } - if ((err = source_->on_rtp(helper->pkt)) != srs_success) { + if ((err = source_->on_rtp(pkt)) != srs_success) { err = srs_error_wrap(err, "consume opus"); break; } } - codec_->free_frames(out_pkts); + codec_->free_frames(out_audios); return err; } -srs_error_t SrsRtcFromRtmpBridger::package_opus(SrsAudioFrame* audio, SrsRtpPacketCacheHelper* helper) +srs_error_t SrsRtcFromRtmpBridger::package_opus(SrsAudioFrame* audio, SrsRtpPacket2* pkt) { srs_error_t err = srs_success; - SrsRtpPacket2* pkt = helper->pkt; pkt->header.set_payload_type(kAudioPayloadType); pkt->header.set_ssrc(audio_ssrc); pkt->frame_type = SrsFrameTypeAudio; @@ -890,7 +878,7 @@ srs_error_t SrsRtcFromRtmpBridger::package_opus(SrsAudioFrame* audio, SrsRtpPack pkt->header.set_sequence(audio_sequence++); pkt->header.set_timestamp(audio->dts * 48); - SrsRtpRawPayload* raw = _srs_rtp_raw_cache->allocate(); + SrsRtpRawPayload* raw = new SrsRtpRawPayload(); pkt->set_payload(raw, SrsRtpPacketPayloadTypeRaw); srs_assert(audio->nb_samples == 1); @@ -923,22 +911,22 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg) // Well, for each IDR, we append a SPS/PPS before it, which is packaged in STAP-A. if (has_idr) { - SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper(); - SrsAutoFree(SrsRtpPacketCacheHelper, helper); + SrsRtpPacket2* pkt = new SrsRtpPacket2(); + SrsAutoFree(SrsRtpPacket2, pkt); - if ((err = package_stap_a(source_, msg, helper)) != srs_success) { + if ((err = package_stap_a(source_, msg, pkt)) != srs_success) { return srs_error_wrap(err, "package stap-a"); } - if ((err = source_->on_rtp(helper->pkt)) != srs_success) { + if ((err = source_->on_rtp(pkt)) != srs_success) { return srs_error_wrap(err, "consume sps/pps"); } } // If merge Nalus, we pcakges all NALUs(samples) as one NALU, in a RTP or FUA packet. - vector helpers; + vector pkts; if (merge_nalus && nn_samples > 1) { - if ((err = package_nalus(msg, samples, helpers)) != srs_success) { + if ((err = package_nalus(msg, samples, pkts)) != srs_success) { return srs_error_wrap(err, "package nalus as one"); } } else { @@ -953,22 +941,22 @@ srs_error_t SrsRtcFromRtmpBridger::on_video(SrsSharedPtrMessage* msg) } if (sample->size <= kRtpMaxPayloadSize) { - if ((err = package_single_nalu(msg, sample, helpers)) != srs_success) { + if ((err = package_single_nalu(msg, sample, pkts)) != srs_success) { return srs_error_wrap(err, "package single nalu"); } } else { - if ((err = package_fu_a(msg, sample, kRtpMaxPayloadSize, helpers)) != srs_success) { + if ((err = package_fu_a(msg, sample, kRtpMaxPayloadSize, pkts)) != srs_success) { return srs_error_wrap(err, "package fu-a"); } } } } - if (!helpers.empty()) { - helpers.back()->pkt->header.set_marker(true); + if (!pkts.empty()) { + pkts.back()->header.set_marker(true); } - return consume_packets(helpers); + return consume_packets(pkts); } srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* format, bool& has_idr, vector& samples) @@ -1001,7 +989,7 @@ srs_error_t SrsRtcFromRtmpBridger::filter(SrsSharedPtrMessage* msg, SrsFormat* f return err; } -srs_error_t SrsRtcFromRtmpBridger::package_stap_a(SrsRtcStream* source, SrsSharedPtrMessage* msg, SrsRtpPacketCacheHelper* helper) +srs_error_t SrsRtcFromRtmpBridger::package_stap_a(SrsRtcStream* source, SrsSharedPtrMessage* msg, SrsRtpPacket2* pkt) { srs_error_t err = srs_success; @@ -1017,7 +1005,6 @@ srs_error_t SrsRtcFromRtmpBridger::package_stap_a(SrsRtcStream* source, SrsShare return srs_error_new(ERROR_RTC_RTP_MUXER, "sps/pps empty"); } - SrsRtpPacket2* pkt = helper->pkt; pkt->header.set_payload_type(kVideoPayloadType); pkt->header.set_ssrc(video_ssrc); pkt->frame_type = SrsFrameTypeVideo; @@ -1061,7 +1048,7 @@ srs_error_t SrsRtcFromRtmpBridger::package_stap_a(SrsRtcStream* source, SrsShare return err; } -srs_error_t SrsRtcFromRtmpBridger::package_nalus(SrsSharedPtrMessage* msg, const vector& samples, vector& helpers) +srs_error_t SrsRtcFromRtmpBridger::package_nalus(SrsSharedPtrMessage* msg, const vector& samples, vector& pkts) { srs_error_t err = srs_success; @@ -1097,10 +1084,9 @@ srs_error_t SrsRtcFromRtmpBridger::package_nalus(SrsSharedPtrMessage* msg, const if (nn_bytes < kRtpMaxPayloadSize) { // Package NALUs in a single RTP packet. - SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper(); - helpers.push_back(helper); + SrsRtpPacket2* pkt = new SrsRtpPacket2(); + pkts.push_back(pkt); - SrsRtpPacket2* pkt = helper->pkt; pkt->header.set_payload_type(kVideoPayloadType); pkt->header.set_ssrc(video_ssrc); pkt->frame_type = SrsFrameTypeVideo; @@ -1132,10 +1118,9 @@ srs_error_t SrsRtcFromRtmpBridger::package_nalus(SrsSharedPtrMessage* msg, const return srs_error_wrap(err, "read samples %d bytes, left %d, total %d", packet_size, nb_left, nn_bytes); } - SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper(); - helpers.push_back(helper); + SrsRtpPacket2* pkt = new SrsRtpPacket2(); + pkts.push_back(pkt); - SrsRtpPacket2* pkt = helper->pkt; pkt->header.set_payload_type(kVideoPayloadType); pkt->header.set_ssrc(video_ssrc); pkt->frame_type = SrsFrameTypeVideo; @@ -1159,21 +1144,20 @@ srs_error_t SrsRtcFromRtmpBridger::package_nalus(SrsSharedPtrMessage* msg, const } // Single NAL Unit Packet @see https://tools.ietf.org/html/rfc6184#section-5.6 -srs_error_t SrsRtcFromRtmpBridger::package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, vector& helpers) +srs_error_t SrsRtcFromRtmpBridger::package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, vector& pkts) { srs_error_t err = srs_success; - SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper(); - helpers.push_back(helper); + SrsRtpPacket2* pkt = new SrsRtpPacket2(); + pkts.push_back(pkt); - SrsRtpPacket2* pkt = helper->pkt; pkt->header.set_payload_type(kVideoPayloadType); pkt->header.set_ssrc(video_ssrc); pkt->frame_type = SrsFrameTypeVideo; pkt->header.set_sequence(video_sequence++); pkt->header.set_timestamp(msg->timestamp * 90); - SrsRtpRawPayload* raw = _srs_rtp_raw_cache->allocate(); + SrsRtpRawPayload* raw = new SrsRtpRawPayload(); pkt->set_payload(raw, SrsRtpPacketPayloadTypeRaw); raw->payload = sample->bytes; @@ -1184,7 +1168,7 @@ srs_error_t SrsRtcFromRtmpBridger::package_single_nalu(SrsSharedPtrMessage* msg, return err; } -srs_error_t SrsRtcFromRtmpBridger::package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, vector& helpers) +srs_error_t SrsRtcFromRtmpBridger::package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, vector& pkts) { srs_error_t err = srs_success; @@ -1197,17 +1181,16 @@ srs_error_t SrsRtcFromRtmpBridger::package_fu_a(SrsSharedPtrMessage* msg, SrsSam for (int i = 0; i < num_of_packet; ++i) { int packet_size = srs_min(nb_left, fu_payload_size); - SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper(); - helpers.push_back(helper); + SrsRtpPacket2* pkt = new SrsRtpPacket2(); + pkts.push_back(pkt); - SrsRtpPacket2* pkt = helper->pkt; pkt->header.set_payload_type(kVideoPayloadType); pkt->header.set_ssrc(video_ssrc); pkt->frame_type = SrsFrameTypeVideo; pkt->header.set_sequence(video_sequence++); pkt->header.set_timestamp(msg->timestamp * 90); - SrsRtpFUAPayload2* fua = _srs_rtp_fua_cache->allocate(); + SrsRtpFUAPayload2* fua = new SrsRtpFUAPayload2(); pkt->set_payload(fua, SrsRtpPacketPayloadTypeFUA2); fua->nri = (SrsAvcNaluType)header; @@ -1227,22 +1210,22 @@ srs_error_t SrsRtcFromRtmpBridger::package_fu_a(SrsSharedPtrMessage* msg, SrsSam return err; } -srs_error_t SrsRtcFromRtmpBridger::consume_packets(vector& helpers) +srs_error_t SrsRtcFromRtmpBridger::consume_packets(vector& pkts) { srs_error_t err = srs_success; // TODO: FIXME: Consume a range of packets. - for (int i = 0; i < (int)helpers.size(); i++) { - SrsRtpPacketCacheHelper* helper = helpers[i]; - if ((err = source_->on_rtp(helper->pkt)) != srs_success) { + for (int i = 0; i < (int)pkts.size(); i++) { + SrsRtpPacket2* pkt = pkts[i]; + if ((err = source_->on_rtp(pkt)) != srs_success) { err = srs_error_wrap(err, "consume sps/pps"); break; } } - for (int i = 0; i < (int)helpers.size(); i++) { - SrsRtpPacketCacheHelper* helper = helpers[i]; - srs_freep(helper); + for (int i = 0; i < (int)pkts.size(); i++) { + SrsRtpPacket2* pkt = pkts[i]; + srs_freep(pkt); } return err; @@ -2192,29 +2175,10 @@ SrsRtcTrackDescription* SrsRtcStreamDescription::find_track_description_by_ssrc( return NULL; } -SrsRtcTrackStatistic::SrsRtcTrackStatistic() -{ - packets = 0; - last_packets = 0; - bytes = 0; - last_bytes = 0; - nacks = 0; - last_nacks = 0; - padding_packets = 0; - last_padding_packets = 0; - padding_bytes = 0; - last_padding_bytes = 0; - replay_packets = 0; - last_replay_packets = 0; - replay_bytes = 0; - last_replay_bytes = 0; -} - SrsRtcRecvTrack::SrsRtcRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc, bool is_audio) { session_ = session; track_desc_ = track_desc->copy(); - statistic_ = new SrsRtcTrackStatistic(); nack_no_copy_ = false; if (is_audio) { @@ -2233,7 +2197,6 @@ SrsRtcRecvTrack::~SrsRtcRecvTrack() srs_freep(rtp_queue_); srs_freep(nack_receiver_); srs_freep(track_desc_); - srs_freep(statistic_); } bool SrsRtcRecvTrack::has_ssrc(uint32_t ssrc) @@ -2341,7 +2304,6 @@ srs_error_t SrsRtcRecvTrack::do_check_send_nacks(uint32_t& timeout_nacks) uint32_t sent_nacks = 0; session_->check_send_nacks(nack_receiver_, track_desc_->ssrc_, sent_nacks, timeout_nacks); - statistic_->nacks += sent_nacks; return err; } @@ -2362,7 +2324,7 @@ void SrsRtcAudioRecvTrack::on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffe return; } - *ppayload = _srs_rtp_raw_cache->allocate(); + *ppayload = new SrsRtpRawPayload(); *ppt = SrsRtpPacketPayloadTypeRaw; } @@ -2370,13 +2332,6 @@ srs_error_t SrsRtcAudioRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pk { srs_error_t err = srs_success; - // connection level statistic - session_->stat_->nn_in_audios++; - - // track level statistic - statistic_->packets++; - statistic_->bytes += pkt->nb_bytes(); - if ((err = source->on_rtp(pkt)) != srs_success) { return srs_error_wrap(err, "source on rtp"); } @@ -2421,10 +2376,10 @@ void SrsRtcVideoRecvTrack::on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffe *ppayload = new SrsRtpSTAPPayload(); *ppt = SrsRtpPacketPayloadTypeSTAP; } else if (v == kFuA) { - *ppayload = _srs_rtp_fua_cache->allocate(); + *ppayload = new SrsRtpFUAPayload2(); *ppt = SrsRtpPacketPayloadTypeFUA2; } else { - *ppayload = _srs_rtp_raw_cache->allocate(); + *ppayload = new SrsRtpRawPayload(); *ppt = SrsRtpPacketPayloadTypeRaw; } } @@ -2433,13 +2388,6 @@ srs_error_t SrsRtcVideoRecvTrack::on_rtp(SrsRtcStream* source, SrsRtpPacket2* pk { srs_error_t err = srs_success; - // connection level statistic - session_->stat_->nn_in_videos++; - - // track level statistic - statistic_->packets++; - statistic_->bytes += pkt->nb_bytes(); - pkt->frame_type = SrsFrameTypeVideo; if ((err = source->on_rtp(pkt)) != srs_success) { @@ -2475,7 +2423,6 @@ SrsRtcSendTrack::SrsRtcSendTrack(SrsRtcConnection* session, SrsRtcTrackDescripti { session_ = session; track_desc_ = track_desc->copy(); - statistic_ = new SrsRtcTrackStatistic(); nack_no_copy_ = false; if (is_audio) { @@ -2491,7 +2438,6 @@ SrsRtcSendTrack::~SrsRtcSendTrack() { srs_freep(rtp_queue_); srs_freep(track_desc_); - srs_freep(statistic_); srs_freep(nack_epp); } @@ -2568,10 +2514,6 @@ srs_error_t SrsRtcSendTrack::on_recv_nack(const vector& lost_seqs) ++_srs_pps_rnack2->sugar; - SrsRtcTrackStatistic* statistic = statistic_; - - statistic->nacks++; - for(int i = 0; i < (int)lost_seqs.size(); ++i) { uint16_t seq = lost_seqs.at(i); SrsRtpPacket2* pkt = fetch_rtp_packet(seq); @@ -2624,14 +2566,6 @@ srs_error_t SrsRtcAudioSendTrack::on_rtp(SrsRtpPacket2* pkt) // TODO: FIXME: Should update PT for RTX. } - // Update stats. - session_->stat_->nn_out_audios++; - - // track level statistic - // TODO: FIXME: if send packets failed, statistic is no correct. - statistic_->packets++; - statistic_->bytes += pkt->nb_bytes(); - if ((err = session_->do_send_packet(pkt)) != srs_success) { return srs_error_wrap(err, "raw send"); } @@ -2662,8 +2596,6 @@ srs_error_t SrsRtcVideoSendTrack::on_rtp(SrsRtpPacket2* pkt) if (!track_desc_->is_active_) { return err; } - - SrsRtcTrackStatistic* statistic = statistic_; pkt->header.set_ssrc(track_desc_->ssrc_); @@ -2678,14 +2610,6 @@ srs_error_t SrsRtcVideoSendTrack::on_rtp(SrsRtpPacket2* pkt) // TODO: FIXME: Should update PT for RTX. } - // Update stats. - session_->stat_->nn_out_videos++; - - // track level statistic - // TODO: FIXME: if send packets failed, statistic is no correct. - statistic->packets++; - statistic->bytes += pkt->nb_bytes(); - if ((err = session_->do_send_packet(pkt)) != srs_success) { return srs_error_wrap(err, "raw send"); } diff --git a/trunk/src/app/srs_app_rtc_source.hpp b/trunk/src/app/srs_app_rtc_source.hpp index 19172304b..7aab6896e 100644 --- a/trunk/src/app/srs_app_rtc_source.hpp +++ b/trunk/src/app/srs_app_rtc_source.hpp @@ -47,7 +47,6 @@ class SrsRtcStream; class SrsRtcFromRtmpBridger; class SrsAudioTranscoder; class SrsRtpPacket2; -class SrsRtpPacketCacheHelper; class SrsSample; class SrsRtcStreamDescription; class SrsRtcTrackDescription; @@ -259,16 +258,6 @@ private: srs_error_t on_timer(srs_utime_t interval); }; -// A helper class, to release the packet to cache. -class SrsRtpPacketCacheHelper -{ -public: - SrsRtpPacket2* pkt; -public: - SrsRtpPacketCacheHelper(); - virtual ~SrsRtpPacketCacheHelper(); -}; - #ifdef SRS_FFMPEG_FIT class SrsRtcFromRtmpBridger : public ISrsSourceBridger { @@ -298,16 +287,16 @@ public: virtual srs_error_t on_audio(SrsSharedPtrMessage* msg); private: srs_error_t transcode(SrsAudioFrame* audio); - srs_error_t package_opus(SrsAudioFrame* audio, SrsRtpPacketCacheHelper* helper); + srs_error_t package_opus(SrsAudioFrame* audio, SrsRtpPacket2* pkt); public: virtual srs_error_t on_video(SrsSharedPtrMessage* msg); private: srs_error_t filter(SrsSharedPtrMessage* msg, SrsFormat* format, bool& has_idr, std::vector& samples); - srs_error_t package_stap_a(SrsRtcStream* source, SrsSharedPtrMessage* msg, SrsRtpPacketCacheHelper* helper); - srs_error_t package_nalus(SrsSharedPtrMessage* msg, const std::vector& samples, std::vector& helpers); - srs_error_t package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, std::vector& helpers); - srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, std::vector& helpers); - srs_error_t consume_packets(std::vector& helpers); + srs_error_t package_stap_a(SrsRtcStream* source, SrsSharedPtrMessage* msg, SrsRtpPacket2* pkt); + srs_error_t package_nalus(SrsSharedPtrMessage* msg, const std::vector& samples, std::vector& pkts); + srs_error_t package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, std::vector& pkts); + srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, std::vector& pkts); + srs_error_t consume_packets(std::vector& pkts); }; class SrsRtmpFromRtcBridger : public ISrsRtcSourceBridger @@ -532,50 +521,10 @@ public: SrsRtcTrackDescription* find_track_description_by_ssrc(uint32_t ssrc); }; -class SrsRtcTrackStatistic -{ -public: - // packets received or sent. - uint32_t packets; - // packets received or sent at last statistic time. - uint32_t last_packets; - // bytes received or sent. - uint64_t bytes; - // bytes received or sent at last statistic time. - uint32_t last_bytes; - - // nacks received or sent. - uint32_t nacks; - // nacks received or sent at last statistic time. - uint32_t last_nacks; - - // padding packets received or sent. - uint32_t padding_packets; - // padding packets received or sent at last statistic time. - uint32_t last_padding_packets; - // padding bytes received or sent. - uint32_t padding_bytes; - // padding bytes received or sent at last statistic time. - uint32_t last_padding_bytes; - - // replay packets received or sent. - uint32_t replay_packets; - // replay packets received or sent at last statistic time. - uint32_t last_replay_packets; - // replay bytes received or sent. - uint64_t replay_bytes; - // replay bytes received or sent at last statistic time. - uint64_t last_replay_bytes; - -public: - SrsRtcTrackStatistic(); -}; - class SrsRtcRecvTrack { protected: SrsRtcTrackDescription* track_desc_; - SrsRtcTrackStatistic* statistic_; protected: SrsRtcConnection* session_; SrsRtpRingBuffer* rtp_queue_; @@ -613,7 +562,7 @@ protected: virtual srs_error_t do_check_send_nacks(uint32_t& timeout_nacks); }; -class SrsRtcAudioRecvTrack : virtual public SrsRtcRecvTrack, virtual public ISrsRtpPacketDecodeHandler +class SrsRtcAudioRecvTrack : public SrsRtcRecvTrack, public ISrsRtpPacketDecodeHandler { public: SrsRtcAudioRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* track_desc); @@ -625,7 +574,7 @@ public: virtual srs_error_t check_send_nacks(); }; -class SrsRtcVideoRecvTrack : virtual public SrsRtcRecvTrack, virtual public ISrsRtpPacketDecodeHandler +class SrsRtcVideoRecvTrack : public SrsRtcRecvTrack, public ISrsRtpPacketDecodeHandler { public: SrsRtcVideoRecvTrack(SrsRtcConnection* session, SrsRtcTrackDescription* stream_descs); @@ -642,7 +591,6 @@ class SrsRtcSendTrack protected: // send track description SrsRtcTrackDescription* track_desc_; - SrsRtcTrackStatistic* statistic_; protected: // The owner connection for this track. SrsRtcConnection* session_; diff --git a/trunk/src/app/srs_app_rtmp_conn.hpp b/trunk/src/app/srs_app_rtmp_conn.hpp index 495e2623c..acfc15c70 100644 --- a/trunk/src/app/srs_app_rtmp_conn.hpp +++ b/trunk/src/app/srs_app_rtmp_conn.hpp @@ -83,8 +83,8 @@ public: }; // The client provides the main logic control for RTMP clients. -class SrsRtmpConn : virtual public ISrsStartableConneciton, virtual public ISrsReloadHandler - , virtual public ISrsCoroutineHandler, virtual public ISrsExpire +class SrsRtmpConn : public ISrsStartableConneciton, public ISrsReloadHandler + , public ISrsCoroutineHandler, public ISrsExpire { // For the thread to directly access any field of connection. friend class SrsPublishRecvThread; diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index b06612a6f..a29ab106d 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -997,9 +997,6 @@ srs_error_t SrsServer::http_handle() if ((err = http_api_mux->handle("/api/v1/clusters", new SrsGoApiClusters())) != srs_success) { return srs_error_wrap(err, "handle clusters"); } - if ((err = http_api_mux->handle("/api/v1/perf", new SrsGoApiPerf())) != srs_success) { - return srs_error_wrap(err, "handle perf"); - } #ifdef SRS_GB28181 if ((err = http_api_mux->handle("/api/v1/gb28181", new SrsGoApiGb28181())) != srs_success) { return srs_error_wrap(err, "handle raw"); diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 4c3986a4e..9694debe5 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -102,7 +102,7 @@ public: }; // A buffered TCP listener. -class SrsBufferListener : virtual public SrsListener, virtual public ISrsTcpHandler +class SrsBufferListener : public SrsListener, public ISrsTcpHandler { private: SrsTcpListener* listener; @@ -117,7 +117,7 @@ public: }; // A TCP listener, for rtsp server. -class SrsRtspListener : virtual public SrsListener, virtual public ISrsTcpHandler +class SrsRtspListener : public SrsListener, public ISrsTcpHandler { private: SrsTcpListener* listener; @@ -133,7 +133,7 @@ public: }; // A TCP listener, for flv stream server. -class SrsHttpFlvListener : virtual public SrsListener, virtual public ISrsTcpHandler +class SrsHttpFlvListener : public SrsListener, public ISrsTcpHandler { private: SrsTcpListener* listener; @@ -179,7 +179,7 @@ public: virtual ~SrsGb28181Listener(); }; -class SrsGb28181TcpListener : virtual public SrsListener, virtual public ISrsTcpHandler +class SrsGb28181TcpListener : public SrsListener, public ISrsTcpHandler { private: SrsTcpListener* listener; @@ -262,9 +262,9 @@ public: // TODO: FIXME: Rename to SrsLiveServer. // SRS RTMP server, initialize and listen, start connection service thread, destroy client. -class SrsServer : virtual public ISrsReloadHandler, virtual public ISrsSourceHandler - , virtual public ISrsResourceManager, virtual public ISrsCoroutineHandler - , virtual public ISrsHourGlass +class SrsServer : public ISrsReloadHandler, public ISrsSourceHandler + , public ISrsResourceManager, public ISrsCoroutineHandler + , public ISrsHourGlass { private: // TODO: FIXME: Extract an HttpApiServer. diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 4a5905895..aad6cd9f7 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -183,7 +183,7 @@ public: }; // The consumer for SrsSource, that is a play client. -class SrsConsumer : virtual public ISrsWakable +class SrsConsumer : public ISrsWakable { private: SrsRtmpJitter* jitter; diff --git a/trunk/src/app/srs_app_statistic.cpp b/trunk/src/app/srs_app_statistic.cpp index 37dbab504..aa8ea9d5a 100644 --- a/trunk/src/app/srs_app_statistic.cpp +++ b/trunk/src/app/srs_app_statistic.cpp @@ -229,27 +229,6 @@ srs_error_t SrsStatisticClient::dumps(SrsJsonObject* obj) return err; } -SrsStatisticCategory::SrsStatisticCategory() -{ - nn = 0; - - a = 0; - b = 0; - c = 0; - d = 0; - e = 0; - - f = 0; - g = 0; - h = 0; - i = 0; - j = 0; -} - -SrsStatisticCategory::~SrsStatisticCategory() -{ -} - SrsStatistic* SrsStatistic::_instance = NULL; SrsStatistic::SrsStatistic() @@ -259,12 +238,6 @@ SrsStatistic::SrsStatistic() clk = new SrsWallClock(); kbps = new SrsKbps(clk); kbps->set_io(NULL, NULL); - - perf_iovs = new SrsStatisticCategory(); - perf_msgs = new SrsStatisticCategory(); - perf_rtp = new SrsStatisticCategory(); - perf_rtc = new SrsStatisticCategory(); - perf_bytes = new SrsStatisticCategory(); } SrsStatistic::~SrsStatistic() @@ -298,12 +271,6 @@ SrsStatistic::~SrsStatistic() rvhosts.clear(); streams.clear(); rstreams.clear(); - - srs_freep(perf_iovs); - srs_freep(perf_msgs); - srs_freep(perf_rtp); - srs_freep(perf_rtc); - srs_freep(perf_bytes); } SrsStatistic* SrsStatistic::instance() @@ -587,157 +554,6 @@ srs_error_t SrsStatistic::dumps_clients(SrsJsonArray* arr, int start, int count) return err; } -void SrsStatistic::perf_on_msgs(int nb_msgs) -{ - perf_on_packets(perf_msgs, nb_msgs); -} - -srs_error_t SrsStatistic::dumps_perf_msgs(SrsJsonObject* obj) -{ - return dumps_perf(perf_msgs, obj); -} - -void SrsStatistic::perf_on_rtc_packets(int nb_packets) -{ - perf_on_packets(perf_rtc, nb_packets); -} - -srs_error_t SrsStatistic::dumps_perf_rtc_packets(SrsJsonObject* obj) -{ - return dumps_perf(perf_rtc, obj); -} - -void SrsStatistic::perf_on_rtp_packets(int nb_packets) -{ - perf_on_packets(perf_rtp, nb_packets); -} - -srs_error_t SrsStatistic::dumps_perf_rtp_packets(SrsJsonObject* obj) -{ - return dumps_perf(perf_rtp, obj); -} - -void SrsStatistic::perf_on_writev_iovs(int nb_iovs) -{ - perf_on_packets(perf_iovs, nb_iovs); -} - -srs_error_t SrsStatistic::dumps_perf_writev_iovs(SrsJsonObject* obj) -{ - return dumps_perf(perf_iovs, obj); -} - -void SrsStatistic::perf_on_rtc_bytes(int nn_bytes, int nn_rtp_bytes, int nn_padding) -{ - // a: AVFrame bytes. - // b: RTC bytes. - // c: RTC paddings. - perf_bytes->a += nn_bytes; - perf_bytes->b += nn_rtp_bytes; - perf_bytes->c += nn_padding; - - perf_bytes->nn += nn_rtp_bytes; -} - -srs_error_t SrsStatistic::dumps_perf_bytes(SrsJsonObject* obj) -{ - obj->set("avframe_bytes", SrsJsonAny::integer(perf_bytes->a)); - obj->set("rtc_bytes", SrsJsonAny::integer(perf_bytes->b)); - obj->set("rtc_padding", SrsJsonAny::integer(perf_bytes->c)); - - obj->set("nn", SrsJsonAny::integer(perf_bytes->nn)); - - return srs_success; -} - -void SrsStatistic::reset_perf() -{ - srs_freep(perf_iovs); - srs_freep(perf_msgs); - srs_freep(perf_rtp); - srs_freep(perf_rtc); - srs_freep(perf_bytes); - - perf_iovs = new SrsStatisticCategory(); - perf_msgs = new SrsStatisticCategory(); - perf_rtp = new SrsStatisticCategory(); - perf_rtc = new SrsStatisticCategory(); - perf_bytes = new SrsStatisticCategory(); -} - -void SrsStatistic::perf_on_packets(SrsStatisticCategory* p, int nb_msgs) -{ - // The range for stat: - // 2, 3, 5, 9, 16, 32, 64, 128, 256 - // that is: - // a: <2 - // b: <3 - // c: <5 - // d: <9 - // e: <16 - // f: <32 - // g: <64 - // h: <128 - // i: <256 - // j: >=256 - if (nb_msgs < 2) { - p->a++; - } else if (nb_msgs < 3) { - p->b++; - } else if (nb_msgs < 5) { - p->c++; - } else if (nb_msgs < 9) { - p->d++; - } else if (nb_msgs < 16) { - p->e++; - } else if (nb_msgs < 32) { - p->f++; - } else if (nb_msgs < 64) { - p->g++; - } else if (nb_msgs < 128) { - p->h++; - } else if (nb_msgs < 256) { - p->i++; - } else { - p->j++; - } - - p->nn += nb_msgs; -} - -srs_error_t SrsStatistic::dumps_perf(SrsStatisticCategory* p, SrsJsonObject* obj) -{ - srs_error_t err = srs_success; - - // The range for stat: - // 2, 3, 5, 9, 16, 32, 64, 128, 256 - // that is: - // a: <2 - // b: <3 - // c: <5 - // d: <9 - // e: <16 - // f: <32 - // g: <64 - // h: <128 - // i: <256 - // j: >=256 - if (p->a) obj->set("lt_2", SrsJsonAny::integer(p->a)); - if (p->b) obj->set("lt_3", SrsJsonAny::integer(p->b)); - if (p->c) obj->set("lt_5", SrsJsonAny::integer(p->c)); - if (p->d) obj->set("lt_9", SrsJsonAny::integer(p->d)); - if (p->e) obj->set("lt_16", SrsJsonAny::integer(p->e)); - if (p->f) obj->set("lt_32", SrsJsonAny::integer(p->f)); - if (p->g) obj->set("lt_64", SrsJsonAny::integer(p->g)); - if (p->h) obj->set("lt_128", SrsJsonAny::integer(p->h)); - if (p->i) obj->set("lt_256", SrsJsonAny::integer(p->i)); - if (p->j) obj->set("gt_256", SrsJsonAny::integer(p->j)); - - obj->set("nn", SrsJsonAny::integer(p->nn)); - - return err; -} - SrsStatisticVhost* SrsStatistic::create_vhost(SrsRequest* req) { SrsStatisticVhost* vhost = NULL; diff --git a/trunk/src/app/srs_app_statistic.hpp b/trunk/src/app/srs_app_statistic.hpp index 1441cd57e..7b688b44b 100644 --- a/trunk/src/app/srs_app_statistic.hpp +++ b/trunk/src/app/srs_app_statistic.hpp @@ -124,28 +124,7 @@ public: virtual srs_error_t dumps(SrsJsonObject* obj); }; -class SrsStatisticCategory -{ -public: - uint64_t nn; -public: - uint64_t a; - uint64_t b; - uint64_t c; - uint64_t d; - uint64_t e; -public: - uint64_t f; - uint64_t g; - uint64_t h; - uint64_t i; - uint64_t j; -public: - SrsStatisticCategory(); - virtual ~SrsStatisticCategory(); -}; - -class SrsStatistic : public ISrsProtocolPerf +class SrsStatistic { private: static SrsStatistic *_instance; @@ -169,12 +148,6 @@ private: // The server total kbps. SrsKbps* kbps; SrsWallClock* clk; - // The perf stat for mw(merged write). - SrsStatisticCategory* perf_iovs; - SrsStatisticCategory* perf_msgs; - SrsStatisticCategory* perf_rtp; - SrsStatisticCategory* perf_rtc; - SrsStatisticCategory* perf_bytes; private: SrsStatistic(); virtual ~SrsStatistic(); @@ -231,35 +204,6 @@ public: // @param start the start index, from 0. // @param count the max count of clients to dump. virtual srs_error_t dumps_clients(SrsJsonArray* arr, int start, int count); -public: - // Stat for packets merged written, nb_msgs is the number of RTMP messages. - // For example, publish by FFMPEG, Audio and Video frames. - virtual void perf_on_msgs(int nb_msgs); - virtual srs_error_t dumps_perf_msgs(SrsJsonObject* obj); -public: - // Stat for packets merged written, nb_packets is the number of RTC packets. - // For example, a RTMP/AAC audio packet maybe transcoded to two RTC/opus packets. - virtual void perf_on_rtc_packets(int nb_packets); - virtual srs_error_t dumps_perf_rtc_packets(SrsJsonObject* obj); -public: - // Stat for packets merged written, nb_packets is the number of RTP packets. - // For example, a RTC/opus packet maybe package to three RTP packets. - virtual void perf_on_rtp_packets(int nb_packets); - virtual srs_error_t dumps_perf_rtp_packets(SrsJsonObject* obj); -public: - // Stat for TCP writev, nb_iovs is the total number of iovec. - virtual void perf_on_writev_iovs(int nb_iovs); - virtual srs_error_t dumps_perf_writev_iovs(SrsJsonObject* obj); -public: - // Stat for bytes, nn_bytes is the size of bytes, nb_padding is padding bytes. - virtual void perf_on_rtc_bytes(int nn_bytes, int nn_rtp_bytes, int nn_padding); - virtual srs_error_t dumps_perf_bytes(SrsJsonObject* obj); -public: - // Reset all perf stat data. - virtual void reset_perf(); -private: - virtual void perf_on_packets(SrsStatisticCategory* p, int nb_msgs); - virtual srs_error_t dumps_perf(SrsStatisticCategory* p, SrsJsonObject* obj); private: virtual SrsStatisticVhost* create_vhost(SrsRequest* req); virtual SrsStatisticStream* create_stream(SrsStatisticVhost* vhost, SrsRequest* req); diff --git a/trunk/src/app/srs_app_threads.cpp b/trunk/src/app/srs_app_threads.cpp index cc17e9cd3..a7dff9b82 100644 --- a/trunk/src/app/srs_app_threads.cpp +++ b/trunk/src/app/srs_app_threads.cpp @@ -46,13 +46,6 @@ extern SrsStageManager* _srs_stages; extern SrsRtcBlackhole* _srs_blackhole; extern SrsResourceManager* _srs_rtc_manager; -extern SrsRtpObjectCacheManager* _srs_rtp_cache; -extern SrsRtpObjectCacheManager* _srs_rtp_raw_cache; -extern SrsRtpObjectCacheManager* _srs_rtp_fua_cache; - -extern SrsRtpObjectCacheManager* _srs_rtp_msg_cache_buffers; -extern SrsRtpObjectCacheManager* _srs_rtp_msg_cache_objs; - extern SrsResourceManager* _srs_rtc_manager; extern SrsDtlsCertificate* _srs_rtc_dtls_certificate; @@ -166,7 +159,6 @@ extern SrsPps* _srs_pps_objs_rraw; extern SrsPps* _srs_pps_objs_rfua; extern SrsPps* _srs_pps_objs_rbuf; extern SrsPps* _srs_pps_objs_rothers; -extern SrsPps* _srs_pps_objs_drop; SrsCircuitBreaker::SrsCircuitBreaker() { @@ -306,13 +298,6 @@ srs_error_t srs_thread_initialize() _srs_rtc_manager = new SrsResourceManager("RTC", true); _srs_circuit_breaker = new SrsCircuitBreaker(); - _srs_rtp_cache = new SrsRtpObjectCacheManager(sizeof(SrsRtpPacket2)); - _srs_rtp_raw_cache = new SrsRtpObjectCacheManager(sizeof(SrsRtpRawPayload)); - _srs_rtp_fua_cache = new SrsRtpObjectCacheManager(sizeof(SrsRtpFUAPayload2)); - - _srs_rtp_msg_cache_buffers = new SrsRtpObjectCacheManager(sizeof(SrsSharedPtrMessage) + kRtpPacketSize); - _srs_rtp_msg_cache_objs = new SrsRtpObjectCacheManager(sizeof(SrsSharedPtrMessage)); - _srs_rtc_manager = new SrsResourceManager("RTC", true); _srs_rtc_dtls_certificate = new SrsDtlsCertificate(); @@ -416,7 +401,6 @@ srs_error_t srs_thread_initialize() _srs_pps_objs_rfua = new SrsPps(); _srs_pps_objs_rbuf = new SrsPps(); _srs_pps_objs_rothers = new SrsPps(); - _srs_pps_objs_drop = new SrsPps(); return err; } diff --git a/trunk/src/core/srs_core_version4.hpp b/trunk/src/core/srs_core_version4.hpp index 35a083367..be8eb9c81 100644 --- a/trunk/src/core/srs_core_version4.hpp +++ b/trunk/src/core/srs_core_version4.hpp @@ -26,6 +26,6 @@ #define VERSION_MAJOR 4 #define VERSION_MINOR 0 -#define VERSION_REVISION 108 +#define VERSION_REVISION 110 #endif diff --git a/trunk/src/kernel/srs_kernel_flv.cpp b/trunk/src/kernel/srs_kernel_flv.cpp index 0a34c0034..a18313994 100644 --- a/trunk/src/kernel/srs_kernel_flv.cpp +++ b/trunk/src/kernel/srs_kernel_flv.cpp @@ -229,19 +229,6 @@ SrsSharedPtrMessage::~SrsSharedPtrMessage() } } -bool SrsSharedPtrMessage::recycle() -{ - // When recycle, unwrap if not the last reference. - if (ptr && ptr->shared_count > 0) { - ptr->shared_count--; - ptr = NULL; - payload = NULL; - size = 0; - } - - return true; -} - srs_error_t SrsSharedPtrMessage::create(SrsCommonMessage* msg) { srs_error_t err = srs_success; @@ -369,7 +356,7 @@ SrsSharedPtrMessage* SrsSharedPtrMessage::copy() SrsSharedPtrMessage* SrsSharedPtrMessage::copy2() { - SrsSharedPtrMessage* copy = _srs_rtp_msg_cache_objs->allocate(); + SrsSharedPtrMessage* copy = new SrsSharedPtrMessage(); // We got an object from cache, the ptr might exists, so unwrap it. //srs_assert(!copy->ptr); diff --git a/trunk/src/kernel/srs_kernel_flv.hpp b/trunk/src/kernel/srs_kernel_flv.hpp index 4fb9400e4..55b3dfd30 100644 --- a/trunk/src/kernel/srs_kernel_flv.hpp +++ b/trunk/src/kernel/srs_kernel_flv.hpp @@ -312,8 +312,6 @@ public: SrsSharedPtrMessage(); virtual ~SrsSharedPtrMessage(); public: - // For object cache to reset and reuse it. - bool recycle(); // Create shared ptr message, // copy header, manage the payload of msg, // set the payload to NULL to prevent double free. diff --git a/trunk/src/kernel/srs_kernel_io.hpp b/trunk/src/kernel/srs_kernel_io.hpp index eaba237dc..b567c3200 100644 --- a/trunk/src/kernel/srs_kernel_io.hpp +++ b/trunk/src/kernel/srs_kernel_io.hpp @@ -71,7 +71,7 @@ public: /** * The reader and seeker. */ -class ISrsReadSeeker : virtual public ISrsReader, virtual public ISrsSeeker +class ISrsReadSeeker : public ISrsReader, public ISrsSeeker { public: ISrsReadSeeker(); @@ -115,7 +115,7 @@ public: /** * The generally writer, stream and vector writer. */ -class ISrsWriter : virtual public ISrsStreamWriter, virtual public ISrsVectorWriter +class ISrsWriter : public ISrsStreamWriter, public ISrsVectorWriter { public: ISrsWriter(); @@ -125,7 +125,7 @@ public: /** * The writer and seeker. */ -class ISrsWriteSeeker : virtual public ISrsWriter, virtual public ISrsSeeker +class ISrsWriteSeeker : public ISrsWriter, public ISrsSeeker { public: ISrsWriteSeeker(); diff --git a/trunk/src/kernel/srs_kernel_rtc_rtp.cpp b/trunk/src/kernel/srs_kernel_rtc_rtp.cpp index bbe2c6f2c..88cacc5af 100644 --- a/trunk/src/kernel/srs_kernel_rtc_rtp.cpp +++ b/trunk/src/kernel/srs_kernel_rtc_rtp.cpp @@ -41,7 +41,6 @@ SrsPps* _srs_pps_objs_rraw = NULL; SrsPps* _srs_pps_objs_rfua = NULL; SrsPps* _srs_pps_objs_rbuf = NULL; SrsPps* _srs_pps_objs_rothers = NULL; -SrsPps* _srs_pps_objs_drop = NULL; /* @see https://tools.ietf.org/html/rfc1889#section-5.1 0 1 2 3 @@ -786,89 +785,8 @@ SrsRtpPacket2::SrsRtpPacket2() SrsRtpPacket2::~SrsRtpPacket2() { - recycle_payload(); - recycle_shared_buffer(); -} - -void SrsRtpPacket2::reset() -{ - nalu_type = SrsAvcNaluTypeReserved; - frame_type = SrsFrameTypeReserved; - cached_payload_size = 0; - decode_handler = NULL; - - // It's important to reset the header. - header = SrsRtpHeader(); - - // Recyle the payload again, to ensure the packet is new one. - recycle_payload(); - recycle_shared_buffer(); -} - -void SrsRtpPacket2::recycle_payload() -{ - if (!payload_) { - return; - } - - if (payload_type_ == SrsRtpPacketPayloadTypeRaw && _srs_rtp_raw_cache->enabled()) { - _srs_rtp_raw_cache->recycle((SrsRtpRawPayload*)payload_); - goto cleanup; - } - - if (payload_type_ == SrsRtpPacketPayloadTypeFUA2 && _srs_rtp_fua_cache->enabled()) { - _srs_rtp_fua_cache->recycle((SrsRtpFUAPayload2*)payload_); - goto cleanup; - } - srs_freep(payload_); - -cleanup: - payload_ = NULL; - payload_type_ = SrsRtpPacketPayloadTypeUnknown; -} - -void SrsRtpPacket2::recycle_shared_buffer() -{ - if (!shared_buffer_) { - return; - } - - // Only recycle the message for UDP packets. - if (shared_buffer_->payload && shared_buffer_->size == kRtpPacketSize) { - if (_srs_rtp_msg_cache_objs->enabled() && shared_buffer_->count() > 0) { - // Recycle the small shared message objects. - _srs_rtp_msg_cache_objs->recycle(shared_buffer_); - goto cleanup; - } - - if (_srs_rtp_msg_cache_buffers->enabled() && shared_buffer_->count() == 0) { - // Recycle the UDP large buffer. - _srs_rtp_msg_cache_buffers->recycle(shared_buffer_); - goto cleanup; - } - } - srs_freep(shared_buffer_); - -cleanup: - shared_buffer_ = NULL; - actual_buffer_size_ = 0; -} - -bool SrsRtpPacket2::recycle() -{ - // Clear the cache size, it may change when reuse it. - cached_payload_size = 0; - // Reset the handler, for decode only. - decode_handler = NULL; - - // We only recycle the payload and shared messages, - // for header and fields, user will reset or copy it. - recycle_payload(); - recycle_shared_buffer(); - - return true; } char* SrsRtpPacket2::wrap(int size) @@ -882,29 +800,16 @@ char* SrsRtpPacket2::wrap(int size) } // Create a large enough message, with under-layer buffer. - while (true) { - srs_freep(shared_buffer_); - shared_buffer_ = _srs_rtp_msg_cache_buffers->allocate(); - - // If got a cached message(which has payload), but it's too small, - // we free it and allocate a larger one. - if (shared_buffer_->payload && shared_buffer_->size < size) { - ++_srs_pps_objs_rothers->sugar; - continue; - } - - // Create under-layer buffer for new message - if (!shared_buffer_->payload) { - // For RTC, we use larger under-layer buffer for each packet. - int nb_buffer = srs_max(size, kRtpPacketSize); - char* buf = new char[nb_buffer]; - shared_buffer_->wrap(buf, nb_buffer); + srs_freep(shared_buffer_); + shared_buffer_ = new SrsSharedPtrMessage(); - ++_srs_pps_objs_rbuf->sugar; - } + // Create under-layer buffer for new message + // For RTC, we use larger under-layer buffer for each packet. + int nb_buffer = srs_max(size, kRtpPacketSize); + char* buf = new char[nb_buffer]; + shared_buffer_->wrap(buf, nb_buffer); - break; - } + ++_srs_pps_objs_rbuf->sugar; return shared_buffer_->payload; } @@ -933,7 +838,7 @@ char* SrsRtpPacket2::wrap(SrsSharedPtrMessage* msg) SrsRtpPacket2* SrsRtpPacket2::copy() { - SrsRtpPacket2* cp = _srs_rtp_cache->allocate(); + SrsRtpPacket2* cp = new SrsRtpPacket2(); // We got packet from cache, the payload and message MUST be NULL, // because we had clear it in recycle. @@ -1043,7 +948,7 @@ srs_error_t SrsRtpPacket2::decode(SrsBuffer* buf) // By default, we always use the RAW payload. if (!payload_) { - payload_ = _srs_rtp_raw_cache->allocate(); + payload_ = new SrsRtpRawPayload(); payload_type_ = SrsRtpPacketPayloadTypeRaw; } @@ -1081,13 +986,6 @@ bool SrsRtpPacket2::is_keyframe() return false; } -SrsRtpObjectCacheManager* _srs_rtp_cache = NULL; -SrsRtpObjectCacheManager* _srs_rtp_raw_cache = NULL; -SrsRtpObjectCacheManager* _srs_rtp_fua_cache = NULL; - -SrsRtpObjectCacheManager* _srs_rtp_msg_cache_buffers = NULL; -SrsRtpObjectCacheManager* _srs_rtp_msg_cache_objs = NULL; - SrsRtpRawPayload::SrsRtpRawPayload() { payload = NULL; @@ -1100,12 +998,6 @@ SrsRtpRawPayload::~SrsRtpRawPayload() { } -bool SrsRtpRawPayload::recycle() -{ - payload=NULL; nn_payload=0; - return true; -} - uint64_t SrsRtpRawPayload::nb_bytes() { return nn_payload; @@ -1140,7 +1032,7 @@ srs_error_t SrsRtpRawPayload::decode(SrsBuffer* buf) ISrsRtpPayloader* SrsRtpRawPayload::copy() { - SrsRtpRawPayload* cp = _srs_rtp_raw_cache->allocate(); + SrsRtpRawPayload* cp = new SrsRtpRawPayload(); cp->payload = payload; cp->nn_payload = nn_payload; @@ -1566,16 +1458,6 @@ SrsRtpFUAPayload2::~SrsRtpFUAPayload2() { } -bool SrsRtpFUAPayload2::recycle() -{ - start = end = false; - nri = nalu_type = (SrsAvcNaluType)0; - - payload = NULL; - size = 0; - return true; -} - uint64_t SrsRtpFUAPayload2::nb_bytes() { return 2 + size; @@ -1643,7 +1525,7 @@ srs_error_t SrsRtpFUAPayload2::decode(SrsBuffer* buf) ISrsRtpPayloader* SrsRtpFUAPayload2::copy() { - SrsRtpFUAPayload2* cp = _srs_rtp_fua_cache->allocate(); + SrsRtpFUAPayload2* cp = new SrsRtpFUAPayload2(); cp->nri = nri; cp->start = start; diff --git a/trunk/src/kernel/srs_kernel_rtc_rtp.hpp b/trunk/src/kernel/srs_kernel_rtc_rtp.hpp index b00135e85..99589d723 100644 --- a/trunk/src/kernel/srs_kernel_rtc_rtp.hpp +++ b/trunk/src/kernel/srs_kernel_rtc_rtp.hpp @@ -315,15 +315,6 @@ public: SrsRtpPacket2(); virtual ~SrsRtpPacket2(); public: - // User MUST reset the packet if got from cache, - // except copy(we will assign the header and copy payload). - void reset(); -private: - void recycle_payload(); - void recycle_shared_buffer(); -public: - // Recycle the object to reuse it. - virtual bool recycle(); // Wrap buffer to shared_message, which is managed by us. char* wrap(int size); char* wrap(char* data, int size); @@ -357,112 +348,6 @@ public: bool is_keyframe(); }; -// For object cache manager to stat the object dropped. -#include -extern SrsPps* _srs_pps_objs_drop; - -// The RTP packet or message cache manager. -template -class SrsRtpObjectCacheManager -{ -private: - bool enabled_; - std::vector cache_objs_; - size_t capacity_; - size_t object_size_; -public: - // SrsRtpObjectCacheManager::SrsRtpObjectCacheManager - SrsRtpObjectCacheManager(size_t size_of_object) { - enabled_ = false; - capacity_ = 0; - object_size_ = size_of_object; - } - // SrsRtpObjectCacheManager::~SrsRtpObjectCacheManager - virtual ~SrsRtpObjectCacheManager() { - typedef typename std::vector::iterator iterator; - for (iterator it = cache_objs_.begin(); it != cache_objs_.end(); ++it) { - T* obj = *it; - srs_freep(obj); - } - } -public: - // Setup the object cache, shrink if capacity changed. - // SrsRtpObjectCacheManager::setup - void setup(bool v, uint64_t memory) { - enabled_ = v; - capacity_ = (size_t)(memory / object_size_); - - - if (!enabled_) { - capacity_ = 0; - } - - // Shrink the cache. - while (cache_objs_.size() > capacity_) { - T* obj = cache_objs_.back(); - cache_objs_.pop_back(); - srs_freep(obj); - } - } - // Get the status of object cache. - // SrsRtpObjectCacheManager::enabled - inline bool enabled() { - return enabled_; - } - // SrsRtpObjectCacheManager::size - int size() { - return (int)cache_objs_.size(); - } - // SrsRtpObjectCacheManager::capacity - int capacity() { - return (int)capacity_; - } - // Try to allocate from cache, create new object if no cache. - // SrsRtpObjectCacheManager::allocate - T* allocate() { - if (!enabled_ || cache_objs_.empty()) { - return new T(); - } - - T* obj = cache_objs_.back(); - cache_objs_.pop_back(); - - return obj; - } - // Recycle the object to cache. - // @remark User can directly free the packet. - // SrsRtpObjectCacheManager::recycle - void recycle(T* p) { - // The p may be NULL, because srs_freep(NULL) is ok. - if (!p) { - return; - } - - // If disabled, drop the object. - if (!enabled_) { - srs_freep(p); - return; - } - - // If recycle the object fail, drop the cached object. - if (!p->recycle()) { - srs_freep(p); - return; - } - - // If exceed the capacity, drop the object. - if (cache_objs_.size() > capacity_) { - ++_srs_pps_objs_drop->sugar; - - srs_freep(p); - return; - } - - // Recycle it. - cache_objs_.push_back(p); - } -}; - // Single payload data. class SrsRtpRawPayload : public ISrsRtpPayloader { @@ -474,8 +359,6 @@ public: public: SrsRtpRawPayload(); virtual ~SrsRtpRawPayload(); -public: - bool recycle(); // interface ISrsRtpPayloader public: virtual uint64_t nb_bytes(); @@ -574,8 +457,6 @@ public: public: SrsRtpFUAPayload2(); virtual ~SrsRtpFUAPayload2(); -public: - bool recycle(); // interface ISrsRtpPayloader public: virtual uint64_t nb_bytes(); @@ -584,15 +465,4 @@ public: virtual ISrsRtpPayloader* copy(); }; -// For RTP packets cache. -extern SrsRtpObjectCacheManager* _srs_rtp_cache; -extern SrsRtpObjectCacheManager* _srs_rtp_raw_cache; -extern SrsRtpObjectCacheManager* _srs_rtp_fua_cache; - -// For shared message cache, with payload. -extern SrsRtpObjectCacheManager* _srs_rtp_msg_cache_buffers; -// For shared message cache, without payload. -// Note that user must unwrap the shared message, before recycle it. -extern SrsRtpObjectCacheManager* _srs_rtp_msg_cache_objs; - #endif diff --git a/trunk/src/main/srs_main_ingest_hls.cpp b/trunk/src/main/srs_main_ingest_hls.cpp index 6eda7b2bd..37dcbfa08 100644 --- a/trunk/src/main/srs_main_ingest_hls.cpp +++ b/trunk/src/main/srs_main_ingest_hls.cpp @@ -646,7 +646,7 @@ int SrsIngestHlsInput::SrsTsPiece::fetch(string m3u8) } // the context to output to rtmp server -class SrsIngestHlsOutput : virtual public ISrsTsHandler, virtual public ISrsAacHandler +class SrsIngestHlsOutput : public ISrsTsHandler, public ISrsAacHandler { private: SrsHttpUri* out_rtmp; diff --git a/trunk/src/protocol/srs_protocol_io.hpp b/trunk/src/protocol/srs_protocol_io.hpp index 02204c942..38d7585d8 100644 --- a/trunk/src/protocol/srs_protocol_io.hpp +++ b/trunk/src/protocol/srs_protocol_io.hpp @@ -75,7 +75,7 @@ public: /** * the reader for the protocol to read from whatever channel. */ -class ISrsProtocolReader : virtual public ISrsReader, virtual public ISrsProtocolStatistic +class ISrsProtocolReader : public ISrsReader, virtual public ISrsProtocolStatistic { public: ISrsProtocolReader(); @@ -97,7 +97,7 @@ public: /** * the writer for the protocol to write to whatever channel. */ -class ISrsProtocolWriter : virtual public ISrsWriter, virtual public ISrsProtocolStatistic +class ISrsProtocolWriter : public ISrsWriter, virtual public ISrsProtocolStatistic { public: ISrsProtocolWriter(); @@ -114,7 +114,7 @@ public: /** * The reader and writer. */ -class ISrsProtocolReadWriter : virtual public ISrsProtocolReader, virtual public ISrsProtocolWriter +class ISrsProtocolReadWriter : public ISrsProtocolReader, public ISrsProtocolWriter { public: ISrsProtocolReadWriter(); diff --git a/trunk/src/protocol/srs_protocol_kbps.hpp b/trunk/src/protocol/srs_protocol_kbps.hpp index d473a9794..197132d83 100644 --- a/trunk/src/protocol/srs_protocol_kbps.hpp +++ b/trunk/src/protocol/srs_protocol_kbps.hpp @@ -137,7 +137,7 @@ public: * user->set_io(kbps, kbps); * the server never know how many bytes already send/recv, for the connection maybe closed. */ -class SrsKbps : virtual public ISrsProtocolStatistic, virtual public ISrsKbpsDelta +class SrsKbps : public ISrsProtocolStatistic, public ISrsKbpsDelta { private: SrsKbpsSlice is; diff --git a/trunk/src/protocol/srs_rtmp_stack.cpp b/trunk/src/protocol/srs_rtmp_stack.cpp index b3e3baa43..b2bff5ef0 100644 --- a/trunk/src/protocol/srs_rtmp_stack.cpp +++ b/trunk/src/protocol/srs_rtmp_stack.cpp @@ -217,14 +217,6 @@ srs_error_t SrsPacket::encode_packet(SrsBuffer* stream) return srs_error_new(ERROR_SYSTEM_PACKET_INVALID, "encode"); } -ISrsProtocolPerf::ISrsProtocolPerf() -{ -} - -ISrsProtocolPerf::~ISrsProtocolPerf() -{ -} - SrsProtocol::AckWindowSize::AckWindowSize() { window = 0; @@ -264,7 +256,6 @@ SrsProtocol::SrsProtocol(ISrsProtocolReadWriter* io) } out_c0c3_caches = new char[SRS_CONSTS_C0C3_HEADERS_MAX]; - perf = NULL; } SrsProtocol::~SrsProtocol() @@ -312,11 +303,6 @@ void SrsProtocol::set_auto_response(bool v) auto_response_when_recv = v; } -void SrsProtocol::set_perf(ISrsProtocolPerf* v) -{ - perf = v; -} - srs_error_t SrsProtocol::manual_response_flush() { srs_error_t err = srs_success; @@ -463,11 +449,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg int c0c3_cache_index = 0; char* c0c3_cache = out_c0c3_caches + c0c3_cache_index; - // How many messages are merged in written. - int nb_msgs_merged_written = 0; - // How many bytes of messages are merged in written. - int bytes_msgs_merged_written = 0; - // try to send use the c0c3 header cache, // if cache is consumed, try another loop. for (int i = 0; i < nb_msgs; i++) { @@ -481,10 +462,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg if (!msg->payload || msg->size <= 0) { continue; } - - // Increase the perf stat data. - nb_msgs_merged_written++; - bytes_msgs_merged_written += msg->size; // p set to current write position, // it's ok when payload is NULL and size is 0. @@ -545,13 +522,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg if ((err = do_iovs_send(out_iovs, iov_index)) != srs_success) { return srs_error_wrap(err, "send iovs"); } - - // Notify about perf stat. - if (perf) { - perf->perf_on_msgs(nb_msgs_merged_written); - perf->perf_on_writev_iovs(iov_index); - nb_msgs_merged_written = 0; bytes_msgs_merged_written = 0; - } // reset caches, while these cache ensure // atleast we can sendout a chunk. @@ -575,13 +545,6 @@ srs_error_t SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msg return srs_error_wrap(err, "send iovs"); } - // Notify about perf stat. - if (perf) { - perf->perf_on_msgs(nb_msgs_merged_written); - perf->perf_on_writev_iovs(iov_index); - nb_msgs_merged_written = 0; bytes_msgs_merged_written = 0; - } - return err; #else // try to send use the c0c3 header cache, @@ -2257,11 +2220,6 @@ void SrsRtmpServer::set_auto_response(bool v) protocol->set_auto_response(v); } -void SrsRtmpServer::set_perf(ISrsProtocolPerf* v) -{ - protocol->set_perf(v); -} - #ifdef SRS_PERF_MERGED_READ void SrsRtmpServer::set_merge_read(bool v, IMergeReadHandler* handler) { diff --git a/trunk/src/protocol/srs_rtmp_stack.hpp b/trunk/src/protocol/srs_rtmp_stack.hpp index e1fab4b61..b319bb118 100644 --- a/trunk/src/protocol/srs_rtmp_stack.hpp +++ b/trunk/src/protocol/srs_rtmp_stack.hpp @@ -147,19 +147,6 @@ protected: virtual srs_error_t encode_packet(SrsBuffer* stream); }; -// The performance statistic data collect. -class ISrsProtocolPerf -{ -public: - ISrsProtocolPerf(); - virtual ~ISrsProtocolPerf(); -public: - // Stat for packets merged written, nb_msgs is the number of RTMP messages, - virtual void perf_on_msgs(int nb_msgs) = 0; - // Stat for TCP writev, nb_iovs is the total number of iovec. - virtual void perf_on_writev_iovs(int nb_iovs) = 0; -}; - // The protocol provides the rtmp-message-protocol services, // To recv RTMP message from RTMP chunk stream, // and to send out RTMP message over RTMP chunk stream. @@ -181,8 +168,6 @@ private: private: // The underlayer socket object, send/recv bytes. ISrsProtocolReadWriter* skt; - // The performance stat handler. - ISrsProtocolPerf* perf; // The requests sent out, used to build the response. // key: transactionId // value: the request command name @@ -242,8 +227,6 @@ public: // @param v, whether auto response message when recv message. // @see: https://github.com/ossrs/srs/issues/217 virtual void set_auto_response(bool v); - // Set the performance stat handler. - virtual void set_perf(ISrsProtocolPerf* v); // Flush for manual response when the auto response is disabled // by set_auto_response(false), we default use auto response, so donot // need to call this api(the protocol sdk will auto send message). @@ -654,8 +637,6 @@ public: // @param v, whether auto response message when recv message. // @see: https://github.com/ossrs/srs/issues/217 virtual void set_auto_response(bool v); - // Set the performance stat handler. - virtual void set_perf(ISrsProtocolPerf* v); #ifdef SRS_PERF_MERGED_READ // To improve read performance, merge some packets then read, // When it on and read small bytes, we sleep to wait more data., diff --git a/trunk/src/protocol/srs_service_http_client.hpp b/trunk/src/protocol/srs_service_http_client.hpp index ad79fef73..56d65f16a 100644 --- a/trunk/src/protocol/srs_service_http_client.hpp +++ b/trunk/src/protocol/srs_service_http_client.hpp @@ -46,7 +46,7 @@ class SrsTcpClient; #define SRS_HTTP_CLIENT_TIMEOUT (30 * SRS_UTIME_SECONDS) // The SSL client over TCP transport. -class SrsSslClient : virtual public ISrsReader, virtual public ISrsStreamWriter +class SrsSslClient : public ISrsReader, public ISrsStreamWriter { private: SrsTcpClient* transport; diff --git a/trunk/src/protocol/srs_service_http_conn.hpp b/trunk/src/protocol/srs_service_http_conn.hpp index a1b3e381c..f27308113 100644 --- a/trunk/src/protocol/srs_service_http_conn.hpp +++ b/trunk/src/protocol/srs_service_http_conn.hpp @@ -257,7 +257,7 @@ public: }; // Response reader use st socket. -class SrsHttpResponseReader : virtual public ISrsHttpResponseReader +class SrsHttpResponseReader : public ISrsHttpResponseReader { private: ISrsReader* skt; diff --git a/trunk/src/utest/srs_utest_http.cpp b/trunk/src/utest/srs_utest_http.cpp index 3f53723f4..26f4a994f 100644 --- a/trunk/src/utest/srs_utest_http.cpp +++ b/trunk/src/utest/srs_utest_http.cpp @@ -174,7 +174,7 @@ public: } }; -class MockHttpHandler : virtual public ISrsHttpHandler, virtual public ISrsHttpMatchHijacker +class MockHttpHandler : public ISrsHttpHandler, public ISrsHttpMatchHijacker { public: string bytes; diff --git a/trunk/src/utest/srs_utest_http.hpp b/trunk/src/utest/srs_utest_http.hpp index 71df3aa45..f14a3ed0c 100644 --- a/trunk/src/utest/srs_utest_http.hpp +++ b/trunk/src/utest/srs_utest_http.hpp @@ -36,7 +36,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include using namespace std; -class MockResponseWriter : virtual public ISrsHttpResponseWriter, virtual public ISrsHttpHeaderFilter +class MockResponseWriter : public ISrsHttpResponseWriter, public ISrsHttpHeaderFilter { public: SrsHttpResponseWriter* w;