mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Live: Limit cached max frames by gop_cache_max_frames (#3236)
* add gop_cache_max_frames * Live: Limit cached max frames by gop_cache_max_frames. v5.0.93 Co-authored-by: wanglei <wanglei@unicloud.com> Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
parent
4ada0bc629
commit
ec76512e42
9 changed files with 75 additions and 7 deletions
|
@ -575,6 +575,7 @@ SrsGopCache::SrsGopCache()
|
|||
cached_video_count = 0;
|
||||
enable_gop_cache = true;
|
||||
audio_after_last_video_count = 0;
|
||||
gop_cache_max_frames_ = 0;
|
||||
}
|
||||
|
||||
SrsGopCache::~SrsGopCache()
|
||||
|
@ -597,6 +598,11 @@ void SrsGopCache::set(bool v)
|
|||
}
|
||||
}
|
||||
|
||||
void SrsGopCache::set_gop_cache_max_frames(int v)
|
||||
{
|
||||
gop_cache_max_frames_ = v;
|
||||
}
|
||||
|
||||
bool SrsGopCache::enabled()
|
||||
{
|
||||
return enable_gop_cache;
|
||||
|
@ -648,10 +654,17 @@ srs_error_t SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)
|
|||
// curent msg is video frame, so we set to 1.
|
||||
cached_video_count = 1;
|
||||
}
|
||||
|
||||
|
||||
// cache the frame.
|
||||
gop_cache.push_back(msg->copy());
|
||||
|
||||
|
||||
// Clear gop cache if exceed the max frames.
|
||||
if (gop_cache.size() > (size_t)gop_cache_max_frames_) {
|
||||
srs_warn("Gop cache exceed max frames=%d, total=%d, videos=%d, aalvc=%d",
|
||||
gop_cache_max_frames_, (int)gop_cache.size(), cached_video_count, audio_after_last_video_count);
|
||||
clear();
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -2086,6 +2099,7 @@ srs_error_t SrsLiveSource::on_reload_vhost_play(string vhost)
|
|||
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);
|
||||
gop_cache->set_gop_cache_max_frames(_srs_config->get_gop_cache_max_frames(vhost));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2725,6 +2739,11 @@ void SrsLiveSource::set_cache(bool enabled)
|
|||
gop_cache->set(enabled);
|
||||
}
|
||||
|
||||
void SrsLiveSource::set_gop_cache_max_frames(int v)
|
||||
{
|
||||
gop_cache->set_gop_cache_max_frames(v);
|
||||
}
|
||||
|
||||
SrsRtmpJitterAlgorithm SrsLiveSource::jitter()
|
||||
{
|
||||
return jitter_algorithm;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue