mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SquashSRS4: Remove object cache and stat api
This commit is contained in:
parent
f711eb79ed
commit
6a980683f7
44 changed files with 141 additions and 1277 deletions
|
|
@ -47,8 +47,7 @@ class SrsSimpleRtmpClient;
|
|||
#include <srs_kernel_file.hpp>
|
||||
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -460,9 +460,6 @@ srs_error_t SrsRtcPlayStream::initialize(SrsRequest* req, std::map<uint32_t, Srs
|
|||
track->set_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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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_;
|
||||
|
|
|
|||
|
|
@ -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).
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -178,7 +178,7 @@ SrsRtcConsumer::~SrsRtcConsumer()
|
|||
vector<SrsRtpPacket2*>::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<SrsAudioFrame *> out_pkts;
|
||||
if ((err = codec_->transcode(pkt, out_pkts)) != srs_success) {
|
||||
std::vector<SrsAudioFrame *> 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<SrsAudioFrame *>::iterator it = out_pkts.begin(); it != out_pkts.end(); ++it) {
|
||||
SrsRtpPacketCacheHelper* helper = new SrsRtpPacketCacheHelper();
|
||||
SrsAutoFree(SrsRtpPacketCacheHelper, helper);
|
||||
for (std::vector<SrsAudioFrame*>::iterator it = out_audios.begin(); it != out_audios.end(); ++it) {
|
||||
SrsAudioFrame* out_audio = *it;
|
||||
|
||||
if ((err = package_opus(*it, helper)) != srs_success) {
|
||||
SrsRtpPacket2* pkt = new SrsRtpPacket2();
|
||||
SrsAutoFree(SrsRtpPacket2, pkt);
|
||||
|
||||
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<SrsRtpPacketCacheHelper*> helpers;
|
||||
vector<SrsRtpPacket2*> 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<SrsSample*>& 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<SrsSample*>& samples, vector<SrsRtpPacketCacheHelper*>& helpers)
|
||||
srs_error_t SrsRtcFromRtmpBridger::package_nalus(SrsSharedPtrMessage* msg, const vector<SrsSample*>& samples, vector<SrsRtpPacket2*>& 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<SrsRtpPacketCacheHelper*>& helpers)
|
||||
srs_error_t SrsRtcFromRtmpBridger::package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, vector<SrsRtpPacket2*>& 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<SrsRtpPacketCacheHelper*>& helpers)
|
||||
srs_error_t SrsRtcFromRtmpBridger::package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, vector<SrsRtpPacket2*>& 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<SrsRtpPacketCacheHelper*>& helpers)
|
||||
srs_error_t SrsRtcFromRtmpBridger::consume_packets(vector<SrsRtpPacket2*>& 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<uint16_t>& 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");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<SrsSample*>& samples);
|
||||
srs_error_t package_stap_a(SrsRtcStream* source, SrsSharedPtrMessage* msg, SrsRtpPacketCacheHelper* helper);
|
||||
srs_error_t package_nalus(SrsSharedPtrMessage* msg, const std::vector<SrsSample*>& samples, std::vector<SrsRtpPacketCacheHelper*>& helpers);
|
||||
srs_error_t package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, std::vector<SrsRtpPacketCacheHelper*>& helpers);
|
||||
srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, std::vector<SrsRtpPacketCacheHelper*>& helpers);
|
||||
srs_error_t consume_packets(std::vector<SrsRtpPacketCacheHelper*>& helpers);
|
||||
srs_error_t package_stap_a(SrsRtcStream* source, SrsSharedPtrMessage* msg, SrsRtpPacket2* pkt);
|
||||
srs_error_t package_nalus(SrsSharedPtrMessage* msg, const std::vector<SrsSample*>& samples, std::vector<SrsRtpPacket2*>& pkts);
|
||||
srs_error_t package_single_nalu(SrsSharedPtrMessage* msg, SrsSample* sample, std::vector<SrsRtpPacket2*>& pkts);
|
||||
srs_error_t package_fu_a(SrsSharedPtrMessage* msg, SrsSample* sample, int fu_payload_size, std::vector<SrsRtpPacket2*>& pkts);
|
||||
srs_error_t consume_packets(std::vector<SrsRtpPacket2*>& 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_;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -46,13 +46,6 @@ extern SrsStageManager* _srs_stages;
|
|||
extern SrsRtcBlackhole* _srs_blackhole;
|
||||
extern SrsResourceManager* _srs_rtc_manager;
|
||||
|
||||
extern SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache;
|
||||
extern SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache;
|
||||
extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;
|
||||
|
||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_buffers;
|
||||
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _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<SrsRtpPacket2>(sizeof(SrsRtpPacket2));
|
||||
_srs_rtp_raw_cache = new SrsRtpObjectCacheManager<SrsRtpRawPayload>(sizeof(SrsRtpRawPayload));
|
||||
_srs_rtp_fua_cache = new SrsRtpObjectCacheManager<SrsRtpFUAPayload2>(sizeof(SrsRtpFUAPayload2));
|
||||
|
||||
_srs_rtp_msg_cache_buffers = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>(sizeof(SrsSharedPtrMessage) + kRtpPacketSize);
|
||||
_srs_rtp_msg_cache_objs = new SrsRtpObjectCacheManager<SrsSharedPtrMessage>(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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue