mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #319, move gop_cache and queue_length to play
This commit is contained in:
parent
06ae74dd3f
commit
f7c893d907
10 changed files with 105 additions and 151 deletions
|
@ -28,7 +28,7 @@ vhost __defaultVhost__ {
|
|||
dir ./objs/nginx/html/hls;
|
||||
}
|
||||
|
||||
# for SRS2.
|
||||
# for SRS1.
|
||||
refer github.com github.io;
|
||||
refer_publish github.com github.io;
|
||||
refer_play github.com github.io;
|
||||
|
@ -43,7 +43,7 @@ vhost __defaultVhost__ {
|
|||
latency 350;
|
||||
}
|
||||
|
||||
# for SRS2
|
||||
# for SRS1
|
||||
mode remote;
|
||||
origin 127.0.0.1:1935 localhost:1935;
|
||||
|
||||
|
@ -52,21 +52,27 @@ vhost __defaultVhost__ {
|
|||
|
||||
debug_srs_upnode off;
|
||||
|
||||
# for SRS2
|
||||
# for SRS1
|
||||
forward 127.0.0.1:1936 127.0.0.1:1937;
|
||||
|
||||
# for SRS2
|
||||
# for SRS1
|
||||
time_jitter full;
|
||||
|
||||
# for SRS2
|
||||
mix_correct off;
|
||||
|
||||
#for SRS1
|
||||
atc on;
|
||||
atc_auto on;
|
||||
|
||||
|
||||
# for SRS2
|
||||
mw_latency 100;
|
||||
|
||||
# for SRS1
|
||||
gop_cache off;
|
||||
queue_length 10;
|
||||
|
||||
# for SRS2
|
||||
send_min_interval 10.0;
|
||||
reduce_sequence_header on;
|
||||
}
|
||||
|
|
|
@ -378,6 +378,21 @@ vhost play.srs.com {
|
|||
# for play client, both RTMP and other stream clients,
|
||||
# for instance, the HTTP FLV stream clients.
|
||||
play {
|
||||
# whether cache the last gop.
|
||||
# if on, cache the last gop and dispatch to client,
|
||||
# to enabled fast startup for client, client play immediately.
|
||||
# if off, send the latest media data to client,
|
||||
# client need to wait for the next Iframe to decode and show the video.
|
||||
# set to off if requires min delay;
|
||||
# set to on if requires client fast startup.
|
||||
# default: on
|
||||
gop_cache off;
|
||||
# the max live queue length in seconds.
|
||||
# if the messages in the queue exceed the max length,
|
||||
# drop the old whole gop.
|
||||
# default: 30
|
||||
queue_length 10;
|
||||
|
||||
# about the stream monotonically increasing:
|
||||
# 1. video timestamp is monotonically increasing,
|
||||
# 2. audio timestamp is monotonically increasing,
|
||||
|
@ -466,24 +481,11 @@ vhost min.delay.com {
|
|||
# @see scope.vhost.srs.com
|
||||
tcp_nodelay on;
|
||||
|
||||
# whether cache the last gop.
|
||||
# if on, cache the last gop and dispatch to client,
|
||||
# to enabled fast startup for client, client play immediately.
|
||||
# if off, send the latest media data to client,
|
||||
# client need to wait for the next Iframe to decode and show the video.
|
||||
# set to off if requires min delay;
|
||||
# set to on if requires client fast startup.
|
||||
# default: on
|
||||
gop_cache off;
|
||||
# the max live queue length in seconds.
|
||||
# if the messages in the queue exceed the max length,
|
||||
# drop the old whole gop.
|
||||
# default: 30
|
||||
queue_length 10;
|
||||
|
||||
# @see play.srs.com
|
||||
play {
|
||||
mw_latency 100;
|
||||
gop_cache off;
|
||||
queue_length 10;
|
||||
}
|
||||
|
||||
# @see publish.srs.com
|
||||
|
@ -499,8 +501,6 @@ vhost stream.control.com {
|
|||
# @see scope.vhost.srs.com
|
||||
tcp_nodelay on;
|
||||
|
||||
# @see vhost min.delay.com
|
||||
queue_length 10;
|
||||
# the minimal packets send interval in ms,
|
||||
# used to control the ndiff of stream by srs_rtmp_dump,
|
||||
# for example, some device can only accept some stream which
|
||||
|
@ -519,6 +519,7 @@ vhost stream.control.com {
|
|||
# @see play.srs.com
|
||||
play {
|
||||
mw_latency 100;
|
||||
queue_length 10;
|
||||
}
|
||||
|
||||
# @see publish.srs.com
|
||||
|
|
|
@ -76,10 +76,10 @@ vhost vhost.srs.com {
|
|||
|
||||
mw_latency 100;
|
||||
|
||||
# TODO
|
||||
gop_cache off;
|
||||
queue_length 10;
|
||||
|
||||
|
||||
# TODO
|
||||
send_min_interval 10.0;
|
||||
reduce_sequence_header on;
|
||||
}
|
||||
|
|
|
@ -732,30 +732,6 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
srs_trace("vhost %s reload min_latency success.", vhost.c_str());
|
||||
}
|
||||
|
||||
// gop_cache, only one per vhost
|
||||
if (!srs_directive_equals(new_vhost->get("gop_cache"), old_vhost->get("gop_cache"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_vhost_gop_cache(vhost)) != ERROR_SUCCESS) {
|
||||
srs_error("vhost %s notify subscribes gop_cache failed. ret=%d", vhost.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("vhost %s reload gop_cache success.", vhost.c_str());
|
||||
}
|
||||
|
||||
// queue_length, only one per vhost
|
||||
if (!srs_directive_equals(new_vhost->get("queue_length"), old_vhost->get("queue_length"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_vhost_queue_length(vhost)) != ERROR_SUCCESS) {
|
||||
srs_error("vhost %s notify subscribes queue_length failed. ret=%d", vhost.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("vhost %s reload queue_length success.", vhost.c_str());
|
||||
}
|
||||
|
||||
// play, only one per vhost
|
||||
if (!srs_directive_equals(new_vhost->get("play"), old_vhost->get("play"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
|
@ -1723,14 +1699,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
|
|||
obj->set("debug_srs_upnode", dir->dumps_arg0_to_boolean());
|
||||
}
|
||||
|
||||
// realtime latency
|
||||
if ((dir = vhost->get("gop_cache")) != NULL) {
|
||||
obj->set("gop_cache", dir->dumps_arg0_to_boolean());
|
||||
}
|
||||
if ((dir = vhost->get("queue_length")) != NULL) {
|
||||
obj->set("queue_length", dir->dumps_arg0_to_number());
|
||||
}
|
||||
|
||||
// stream control
|
||||
if ((dir = vhost->get("send_min_interval")) != NULL) {
|
||||
obj->set("send_min_interval", dir->dumps_arg0_to_number());
|
||||
|
@ -1757,6 +1725,10 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
|
|||
play->set("atc_auto", sdir->dumps_arg0_to_boolean());
|
||||
} else if (sdir->name == "mw_latency") {
|
||||
play->set("mw_latency", sdir->dumps_arg0_to_number());
|
||||
} else if (sdir->name == "gop_cache") {
|
||||
play->set("gop_cache", sdir->dumps_arg0_to_boolean());
|
||||
} else if (sdir->name == "queue_length") {
|
||||
play->set("queue_length", sdir->dumps_arg0_to_number());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2637,7 +2609,6 @@ int SrsConfig::check_config()
|
|||
if (n != "enabled" && n != "chunk_size" && n != "min_latency" && n != "tcp_nodelay"
|
||||
&& n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost"
|
||||
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
|
||||
&& n != "gop_cache" && n != "queue_length"
|
||||
&& n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
|
||||
&& n != "debug_srs_upnode" && n != "play" && n != "publish"
|
||||
&& n != "send_min_interval" && n != "reduce_sequence_header"
|
||||
|
@ -2681,7 +2652,9 @@ int SrsConfig::check_config()
|
|||
} else if (n == "play") {
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name.c_str();
|
||||
if (m != "time_jitter" && m != "mix_correct" && m != "atc" && m != "atc_auto" && m != "mw_latency") {
|
||||
if (m != "time_jitter" && m != "mix_correct" && m != "atc" && m != "atc_auto"
|
||||
&& m != "mw_latency" && m != "gop_cache" && m != "queue_length"
|
||||
) {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported vhost play directive %s, ret=%d", m.c_str(), ret);
|
||||
return ret;
|
||||
|
@ -3197,6 +3170,11 @@ bool SrsConfig::get_gop_cache(string vhost)
|
|||
return SRS_PERF_GOP_CACHE;
|
||||
}
|
||||
|
||||
conf = conf->get("play");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return SRS_PERF_GOP_CACHE;
|
||||
}
|
||||
|
||||
conf = conf->get("gop_cache");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return SRS_PERF_GOP_CACHE;
|
||||
|
@ -3317,6 +3295,11 @@ double SrsConfig::get_queue_length(string vhost)
|
|||
return SRS_PERF_PLAY_QUEUE;
|
||||
}
|
||||
|
||||
conf = conf->get("play");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return SRS_PERF_GOP_CACHE;
|
||||
}
|
||||
|
||||
conf = conf->get("queue_length");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return SRS_PERF_PLAY_QUEUE;
|
||||
|
@ -5779,12 +5762,14 @@ int srs_config_transform_vhost(SrsConfDirective* root)
|
|||
}
|
||||
|
||||
// SRS3.0, change the folowing like a shadow:
|
||||
// time_jitter, mix_correct, atc, atc_auto, mw_latency
|
||||
// time_jitter, mix_correct, atc, atc_auto, mw_latency, gop_cache, queue_length
|
||||
// SRS1/2:
|
||||
// vhost { shadow; }
|
||||
// SRS3+:
|
||||
// vhost { play { shadow; } }
|
||||
if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto" || n == "mw_latency") {
|
||||
if (n == "time_jitter" || n == "mix_correct" || n == "atc" || n == "atc_auto"
|
||||
|| n == "mw_latency" || n == "gop_cache" || n == "queue_length"
|
||||
) {
|
||||
it = dir->directives.erase(it);
|
||||
|
||||
SrsConfDirective* play = dir->get_or_create("play");
|
||||
|
|
|
@ -125,16 +125,6 @@ int ISrsReloadHandler::on_reload_vhost_removed(string /*vhost*/)
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_gop_cache(string /*vhost*/)
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_queue_length(string /*vhost*/)
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_play(string /*vhost*/)
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
|
|
|
@ -64,8 +64,6 @@ public:
|
|||
virtual int on_reload_vhost_http_remux_updated(std::string vhost);
|
||||
virtual int on_reload_vhost_added(std::string vhost);
|
||||
virtual int on_reload_vhost_removed(std::string vhost);
|
||||
virtual int on_reload_vhost_gop_cache(std::string vhost);
|
||||
virtual int on_reload_vhost_queue_length(std::string vhost);
|
||||
virtual int on_reload_vhost_play(std::string vhost);
|
||||
virtual int on_reload_vhost_forward(std::string vhost);
|
||||
virtual int on_reload_vhost_hls(std::string vhost);
|
||||
|
|
|
@ -594,11 +594,11 @@ void SrsGopCache::dispose()
|
|||
clear();
|
||||
}
|
||||
|
||||
void SrsGopCache::set(bool enabled)
|
||||
void SrsGopCache::set(bool v)
|
||||
{
|
||||
enable_gop_cache = enabled;
|
||||
enable_gop_cache = v;
|
||||
|
||||
if (!enabled) {
|
||||
if (!v) {
|
||||
srs_info("disable gop cache, clear %d packets.", (int)gop_cache.size());
|
||||
clear();
|
||||
return;
|
||||
|
@ -607,6 +607,11 @@ void SrsGopCache::set(bool enabled)
|
|||
srs_info("enable gop cache");
|
||||
}
|
||||
|
||||
bool SrsGopCache::enabled()
|
||||
{
|
||||
return enable_gop_cache;
|
||||
}
|
||||
|
||||
int SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -1043,65 +1048,6 @@ int SrsSource::initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* h
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsSource::on_reload_vhost_gop_cache(string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if (_req->vhost != vhost) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// gop cache changed.
|
||||
bool enabled_cache = _srs_config->get_gop_cache(vhost);
|
||||
|
||||
srs_trace("vhost %s gop_cache changed to %d, source url=%s",
|
||||
vhost.c_str(), enabled_cache, _req->get_stream_url().c_str());
|
||||
|
||||
set_cache(enabled_cache);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsSource::on_reload_vhost_queue_length(string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
if (_req->vhost != vhost) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
double queue_size = _srs_config->get_queue_length(_req->vhost);
|
||||
|
||||
if (true) {
|
||||
std::vector<SrsConsumer*>::iterator it;
|
||||
|
||||
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
||||
SrsConsumer* consumer = *it;
|
||||
consumer->set_queue_size(queue_size);
|
||||
}
|
||||
|
||||
srs_trace("consumers reload queue size success.");
|
||||
}
|
||||
|
||||
if (true) {
|
||||
std::vector<SrsForwarder*>::iterator it;
|
||||
|
||||
for (it = forwarders.begin(); it != forwarders.end(); ++it) {
|
||||
SrsForwarder* forwarder = *it;
|
||||
forwarder->set_queue_size(queue_size);
|
||||
}
|
||||
|
||||
srs_trace("forwarders reload queue size success.");
|
||||
}
|
||||
|
||||
if (true) {
|
||||
publish_edge->set_queue_size(queue_size);
|
||||
srs_trace("publish_edge reload queue size success.");
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsSource::on_reload_vhost_play(string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -1135,6 +1081,49 @@ int SrsSource::on_reload_vhost_play(string vhost)
|
|||
atc = v;
|
||||
}
|
||||
|
||||
// gop cache changed.
|
||||
if (true) {
|
||||
bool v = _srs_config->get_gop_cache(vhost);
|
||||
|
||||
if (v != gop_cache->enabled()) {
|
||||
string url = _req->get_stream_url();
|
||||
srs_trace("vhost %s gop_cache changed to %d, source url=%s", vhost.c_str(), v, url.c_str());
|
||||
gop_cache->set(v);
|
||||
}
|
||||
}
|
||||
|
||||
// queue length
|
||||
if (true) {
|
||||
double v = _srs_config->get_queue_length(_req->vhost);
|
||||
|
||||
if (true) {
|
||||
std::vector<SrsConsumer*>::iterator it;
|
||||
|
||||
for (it = consumers.begin(); it != consumers.end(); ++it) {
|
||||
SrsConsumer* consumer = *it;
|
||||
consumer->set_queue_size(v);
|
||||
}
|
||||
|
||||
srs_trace("consumers reload queue size success.");
|
||||
}
|
||||
|
||||
if (true) {
|
||||
std::vector<SrsForwarder*>::iterator it;
|
||||
|
||||
for (it = forwarders.begin(); it != forwarders.end(); ++it) {
|
||||
SrsForwarder* forwarder = *it;
|
||||
forwarder->set_queue_size(v);
|
||||
}
|
||||
|
||||
srs_trace("forwarders reload queue size success.");
|
||||
}
|
||||
|
||||
if (true) {
|
||||
publish_edge->set_queue_size(v);
|
||||
srs_trace("publish_edge reload queue size success.");
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -331,7 +331,8 @@ public:
|
|||
/**
|
||||
* to enable or disable the gop cache.
|
||||
*/
|
||||
virtual void set(bool enabled);
|
||||
virtual void set(bool v);
|
||||
virtual bool enabled();
|
||||
/**
|
||||
* only for h264 codec
|
||||
* 1. cache the gop when got h264 video packet.
|
||||
|
@ -520,8 +521,6 @@ public:
|
|||
virtual int initialize(SrsRequest* r, ISrsSourceHandler* h, ISrsHlsHandler* hh);
|
||||
// interface ISrsReloadHandler
|
||||
public:
|
||||
virtual int on_reload_vhost_gop_cache(std::string vhost);
|
||||
virtual int on_reload_vhost_queue_length(std::string vhost);
|
||||
virtual int on_reload_vhost_play(std::string vhost);
|
||||
virtual int on_reload_vhost_forward(std::string vhost);
|
||||
virtual int on_reload_vhost_hls(std::string vhost);
|
||||
|
|
|
@ -230,18 +230,6 @@ int MockReloadHandler::on_reload_vhost_removed(string /*vhost*/)
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int MockReloadHandler::on_reload_vhost_gop_cache(string /*vhost*/)
|
||||
{
|
||||
vhost_gop_cache_reloaded = true;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int MockReloadHandler::on_reload_vhost_queue_length(string /*vhost*/)
|
||||
{
|
||||
vhost_queue_length_reloaded = true;
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int MockReloadHandler::on_reload_vhost_play(string /*vhost*/)
|
||||
{
|
||||
vhost_time_jitter_reloaded = true;
|
||||
|
|
|
@ -85,8 +85,6 @@ public:
|
|||
virtual int on_reload_vhost_http_updated();
|
||||
virtual int on_reload_vhost_added(std::string vhost);
|
||||
virtual int on_reload_vhost_removed(std::string vhost);
|
||||
virtual int on_reload_vhost_gop_cache(std::string vhost);
|
||||
virtual int on_reload_vhost_queue_length(std::string vhost);
|
||||
virtual int on_reload_vhost_play(std::string vhost);
|
||||
virtual int on_reload_vhost_forward(std::string vhost);
|
||||
virtual int on_reload_vhost_hls(std::string vhost);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue