Skip to content

Commit

Permalink
Live: Limit cached max frames by gop_cache_max_frames. v5.0.93
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Nov 22, 2022
1 parent 4a05839 commit 463f15c
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 22 deletions.
5 changes: 2 additions & 3 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1097,9 +1097,8 @@ vhost play.srs.com {
# default: on
gop_cache off;

# to limit the max gop cache frames
# without this limit, if ingest stream always has no IDR frame,
# it may cause srs run out of memory
# Limit the max frames in gop cache. It might cause OOM if video stream has no IDR frame, so we limit to N
# frames by default.
# default: 250
gop_cache_max_frames 250;

Expand Down
2 changes: 1 addition & 1 deletion trunk/conf/srs.conf
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ vhost __defaultVhost__ {
}

play{
gop_cache_max_frames 100;
gop_cache_max_frames 250;
}
}
1 change: 1 addition & 0 deletions trunk/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The changelog for SRS.

## SRS 5.0 Changelog

* v5.0, 2022-11-22, Merge [#3236](https://github.com/ossrs/srs/pull/3236): Live: Limit cached max frames by gop_cache_max_frames. v5.0.93
* v5.0, 2022-11-22, Asan: Check libasan and show tips. v5.0.92
* v5.0, 2022-11-21, Merge [#3264](https://github.com/ossrs/srs/pull/3264): Asan: Try to fix st_memory_leak for asan check. (#3264). v5.0.91
* v5.0, 2022-11-21, Asan: Fix global ip address leak check. v5.0.90
Expand Down
3 changes: 1 addition & 2 deletions trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,7 @@ class SrsConfig
// @return true when gop_cache is ok; otherwise, false.
// @remark, default true.
virtual bool get_gop_cache(std::string vhost);
// to set the max frames limit in gop cache
// @return gop cache frames limit
// Get the limit max frames for gop cache.
virtual int get_gop_cache_max_frames(std::string vhost);
// Whether debug_srs_upnode is enabled of vhost.
// debug_srs_upnode is very important feature for tracable log,
Expand Down
10 changes: 5 additions & 5 deletions trunk/src/app/srs_app_rtmp_conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,12 +557,12 @@ srs_error_t SrsRtmpConn::stream_service_cycle()
srs_assert(source != NULL);

bool enabled_cache = _srs_config->get_gop_cache(req->vhost);
int gcf = _srs_config->get_gop_cache_max_frames(req->vhost);

srs_trace("source url=%s, ip=%s, cache=%d, gop_cache_max_frames=%d, is_edge=%d, source_id=%s/%s",
req->get_stream_url().c_str(), ip.c_str(), enabled_cache, gcf, info->edge, source->source_id().c_str(), source->pre_source_id().c_str());
int gcmf = _srs_config->get_gop_cache_max_frames(req->vhost);
srs_trace("source url=%s, ip=%s, cache=%d/%d, is_edge=%d, source_id=%s/%s",
req->get_stream_url().c_str(), ip.c_str(), enabled_cache, gcmf, info->edge, source->source_id().c_str(),
source->pre_source_id().c_str());
source->set_cache(enabled_cache);
source->set_gop_cache_max_frames(gcf);
source->set_gop_cache_max_frames(gcmf);

switch (info->type) {
case SrsRtmpConnPlay: {
Expand Down
14 changes: 4 additions & 10 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ SrsGopCache::SrsGopCache()
cached_video_count = 0;
enable_gop_cache = true;
audio_after_last_video_count = 0;
gop_cache_max_frames_ = 250;
gop_cache_max_frames_ = 0;
}

SrsGopCache::~SrsGopCache()
Expand All @@ -598,7 +598,6 @@ void SrsGopCache::set(bool v)
}
}


void SrsGopCache::set_gop_cache_max_frames(int v)
{
gop_cache_max_frames_ = v;
Expand Down Expand Up @@ -656,16 +655,13 @@ srs_error_t SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)
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("too many frames in the gop cache, %d video frames & %d audio frames dropped, "
"audio_after_last_video_count: %d.",
cached_video_count,
(int)gop_cache.size() - cached_video_count,
audio_after_last_video_count);
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();
}

Expand Down Expand Up @@ -2103,7 +2099,6 @@ 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));
}
}
Expand Down Expand Up @@ -2749,7 +2744,6 @@ void SrsLiveSource::set_gop_cache_max_frames(int v)
gop_cache->set_gop_cache_max_frames(v);
}


SrsRtmpJitterAlgorithm SrsLiveSource::jitter()
{
return jitter_algorithm;
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core_version5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

#define VERSION_MAJOR 5
#define VERSION_MINOR 0
#define VERSION_REVISION 92
#define VERSION_REVISION 93

#endif

0 comments on commit 463f15c

Please sign in to comment.