1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 11:51:57 +00:00

refine code for bug #151, refine the source functions, add comments.

This commit is contained in:
winlin 2014-10-08 14:28:09 +08:00
parent f33f91c8c2
commit 13b092704d
2 changed files with 27 additions and 11 deletions

View file

@ -363,7 +363,7 @@ SrsGopCache::SrsGopCache()
{ {
cached_video_count = 0; cached_video_count = 0;
enable_gop_cache = true; enable_gop_cache = true;
audio_count_after_last_video = 0; audio_after_last_video_count = 0;
} }
SrsGopCache::~SrsGopCache() SrsGopCache::~SrsGopCache()
@ -396,7 +396,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg)
// got video, update the video count if acceptable // got video, update the video count if acceptable
if (msg->header.is_video()) { if (msg->header.is_video()) {
cached_video_count++; cached_video_count++;
audio_count_after_last_video = 0; audio_after_last_video_count = 0;
} }
// no acceptable video or pure audio, disable the cache. // 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. // ok, gop cache enabled, and got an audio.
if (msg->header.is_audio()) { if (msg->header.is_audio()) {
audio_count_after_last_video++; audio_after_last_video_count++;
} }
// clear gop cache when pure audio count overflow // 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"); srs_warn("clear gop cache for guess pure audio overflow");
clear(); clear();
return ret; return ret;
@ -444,6 +444,7 @@ void SrsGopCache::clear()
gop_cache.clear(); gop_cache.clear();
cached_video_count = 0; cached_video_count = 0;
audio_after_last_video_count = 0;
} }
int SrsGopCache::dump(SrsConsumer* consumer, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm) 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(); return gop_cache.empty();
} }
int64_t SrsGopCache::get_start_time() int64_t SrsGopCache::start_time()
{ {
if (empty()) { if (empty()) {
return 0; return 0;
@ -1457,13 +1458,13 @@ void SrsSource::on_unpublish()
// if atc, update the sequence header to gop cache time. // if atc, update the sequence header to gop cache time.
if (atc && !gop_cache->empty()) { if (atc && !gop_cache->empty()) {
if (cache_metadata) { if (cache_metadata) {
cache_metadata->header.timestamp = gop_cache->get_start_time(); cache_metadata->header.timestamp = gop_cache->start_time();
} }
if (cache_sh_video) { 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) { if (cache_sh_audio) {
cache_sh_audio->header.timestamp = gop_cache->get_start_time(); cache_sh_audio->header.timestamp = gop_cache->start_time();
} }
} }

View file

@ -224,7 +224,7 @@ private:
* gop cache is disabled for pure audio stream. * gop cache is disabled for pure audio stream.
* @see: https://github.com/winlinvip/simple-rtmp-server/issues/124 * @see: https://github.com/winlinvip/simple-rtmp-server/issues/124
*/ */
int audio_count_after_last_video; int audio_after_last_video_count;
/** /**
* cached gop. * cached gop.
*/ */
@ -233,6 +233,9 @@ public:
SrsGopCache(); SrsGopCache();
virtual ~SrsGopCache(); virtual ~SrsGopCache();
public: public:
/**
* to enable or disable the gop cache.
*/
virtual void set(bool enabled); virtual void set(bool enabled);
/** /**
* only for h264 codec * only for h264 codec
@ -240,14 +243,26 @@ public:
* 2. clear gop when got keyframe. * 2. clear gop when got keyframe.
*/ */
virtual int cache(SrsSharedPtrMessage* msg); virtual int cache(SrsSharedPtrMessage* msg);
/**
* clear the gop cache.
*/
virtual void clear(); 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, * used for atc to get the time of gop cache,
* the atc will adjust the sequence header timestamp to gop cache. * the atc will adjust the sequence header timestamp to gop cache.
*/ */
virtual bool empty(); 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();
}; };
/** /**