From 13b092704d87254ca2d6d04a27b8ec3b5819d219 Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 8 Oct 2014 14:28:09 +0800 Subject: [PATCH] refine code for bug #151, refine the source functions, add comments. --- trunk/src/app/srs_app_source.cpp | 17 +++++++++-------- trunk/src/app/srs_app_source.hpp | 21 ++++++++++++++++++--- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 4f6997545..ea4f27d2a 100644 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -363,7 +363,7 @@ SrsGopCache::SrsGopCache() { cached_video_count = 0; enable_gop_cache = true; - audio_count_after_last_video = 0; + audio_after_last_video_count = 0; } SrsGopCache::~SrsGopCache() @@ -396,7 +396,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) // got video, update the video count if acceptable if (msg->header.is_video()) { cached_video_count++; - audio_count_after_last_video = 0; + audio_after_last_video_count = 0; } // no acceptable video or pure audio, disable the cache. @@ -407,11 +407,11 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) // ok, gop cache enabled, and got an audio. if (msg->header.is_audio()) { - audio_count_after_last_video++; + audio_after_last_video_count++; } // clear gop cache when pure audio count overflow - if (audio_count_after_last_video > __SRS_PURE_AUDIO_GUESS_COUNT) { + if (audio_after_last_video_count > __SRS_PURE_AUDIO_GUESS_COUNT) { srs_warn("clear gop cache for guess pure audio overflow"); clear(); return ret; @@ -444,6 +444,7 @@ void SrsGopCache::clear() gop_cache.clear(); cached_video_count = 0; + audio_after_last_video_count = 0; } int SrsGopCache::dump(SrsConsumer* consumer, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm) @@ -469,7 +470,7 @@ bool SrsGopCache::empty() return gop_cache.empty(); } -int64_t SrsGopCache::get_start_time() +int64_t SrsGopCache::start_time() { if (empty()) { return 0; @@ -1457,13 +1458,13 @@ void SrsSource::on_unpublish() // if atc, update the sequence header to gop cache time. if (atc && !gop_cache->empty()) { if (cache_metadata) { - cache_metadata->header.timestamp = gop_cache->get_start_time(); + cache_metadata->header.timestamp = gop_cache->start_time(); } if (cache_sh_video) { - cache_sh_video->header.timestamp = gop_cache->get_start_time(); + cache_sh_video->header.timestamp = gop_cache->start_time(); } if (cache_sh_audio) { - cache_sh_audio->header.timestamp = gop_cache->get_start_time(); + cache_sh_audio->header.timestamp = gop_cache->start_time(); } } diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 40000cee2..fc6241e28 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -224,7 +224,7 @@ private: * gop cache is disabled for pure audio stream. * @see: https://github.com/winlinvip/simple-rtmp-server/issues/124 */ - int audio_count_after_last_video; + int audio_after_last_video_count; /** * cached gop. */ @@ -233,6 +233,9 @@ public: SrsGopCache(); virtual ~SrsGopCache(); public: + /** + * to enable or disable the gop cache. + */ virtual void set(bool enabled); /** * only for h264 codec @@ -240,14 +243,26 @@ public: * 2. clear gop when got keyframe. */ virtual int cache(SrsSharedPtrMessage* msg); + /** + * clear the gop cache. + */ virtual void clear(); - virtual int dump(SrsConsumer* consumer, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm); + /** + * dump the cached gop to consumer. + */ + virtual int dump(SrsConsumer* consumer, + bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm + ); /** * used for atc to get the time of gop cache, * the atc will adjust the sequence header timestamp to gop cache. */ virtual bool empty(); - virtual int64_t get_start_time(); + /** + * get the start time of gop cache, in ms. + * @return 0 if no packets. + */ + virtual int64_t start_time(); }; /**