winlin

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

... ... @@ -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();
}
}
... ...
... ... @@ -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();
};
/**
... ...