refine code for bug #151, refine the source functions, add comments.
正在显示
2 个修改的文件
包含
27 行增加
和
11 行删除
| @@ -363,7 +363,7 @@ SrsGopCache::SrsGopCache() | @@ -363,7 +363,7 @@ SrsGopCache::SrsGopCache() | ||
| 363 | { | 363 | { |
| 364 | cached_video_count = 0; | 364 | cached_video_count = 0; |
| 365 | enable_gop_cache = true; | 365 | enable_gop_cache = true; |
| 366 | - audio_count_after_last_video = 0; | 366 | + audio_after_last_video_count = 0; |
| 367 | } | 367 | } |
| 368 | 368 | ||
| 369 | SrsGopCache::~SrsGopCache() | 369 | SrsGopCache::~SrsGopCache() |
| @@ -396,7 +396,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | @@ -396,7 +396,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | ||
| 396 | // got video, update the video count if acceptable | 396 | // got video, update the video count if acceptable |
| 397 | if (msg->header.is_video()) { | 397 | if (msg->header.is_video()) { |
| 398 | cached_video_count++; | 398 | cached_video_count++; |
| 399 | - audio_count_after_last_video = 0; | 399 | + audio_after_last_video_count = 0; |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | // no acceptable video or pure audio, disable the cache. | 402 | // no acceptable video or pure audio, disable the cache. |
| @@ -407,11 +407,11 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | @@ -407,11 +407,11 @@ int SrsGopCache::cache(SrsSharedPtrMessage* msg) | ||
| 407 | 407 | ||
| 408 | // ok, gop cache enabled, and got an audio. | 408 | // ok, gop cache enabled, and got an audio. |
| 409 | if (msg->header.is_audio()) { | 409 | if (msg->header.is_audio()) { |
| 410 | - audio_count_after_last_video++; | 410 | + audio_after_last_video_count++; |
| 411 | } | 411 | } |
| 412 | 412 | ||
| 413 | // clear gop cache when pure audio count overflow | 413 | // clear gop cache when pure audio count overflow |
| 414 | - if (audio_count_after_last_video > __SRS_PURE_AUDIO_GUESS_COUNT) { | 414 | + if (audio_after_last_video_count > __SRS_PURE_AUDIO_GUESS_COUNT) { |
| 415 | srs_warn("clear gop cache for guess pure audio overflow"); | 415 | srs_warn("clear gop cache for guess pure audio overflow"); |
| 416 | clear(); | 416 | clear(); |
| 417 | return ret; | 417 | return ret; |
| @@ -444,6 +444,7 @@ void SrsGopCache::clear() | @@ -444,6 +444,7 @@ void SrsGopCache::clear() | ||
| 444 | gop_cache.clear(); | 444 | gop_cache.clear(); |
| 445 | 445 | ||
| 446 | cached_video_count = 0; | 446 | cached_video_count = 0; |
| 447 | + audio_after_last_video_count = 0; | ||
| 447 | } | 448 | } |
| 448 | 449 | ||
| 449 | int SrsGopCache::dump(SrsConsumer* consumer, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm) | 450 | int SrsGopCache::dump(SrsConsumer* consumer, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm) |
| @@ -469,7 +470,7 @@ bool SrsGopCache::empty() | @@ -469,7 +470,7 @@ bool SrsGopCache::empty() | ||
| 469 | return gop_cache.empty(); | 470 | return gop_cache.empty(); |
| 470 | } | 471 | } |
| 471 | 472 | ||
| 472 | -int64_t SrsGopCache::get_start_time() | 473 | +int64_t SrsGopCache::start_time() |
| 473 | { | 474 | { |
| 474 | if (empty()) { | 475 | if (empty()) { |
| 475 | return 0; | 476 | return 0; |
| @@ -1457,13 +1458,13 @@ void SrsSource::on_unpublish() | @@ -1457,13 +1458,13 @@ void SrsSource::on_unpublish() | ||
| 1457 | // if atc, update the sequence header to gop cache time. | 1458 | // if atc, update the sequence header to gop cache time. |
| 1458 | if (atc && !gop_cache->empty()) { | 1459 | if (atc && !gop_cache->empty()) { |
| 1459 | if (cache_metadata) { | 1460 | if (cache_metadata) { |
| 1460 | - cache_metadata->header.timestamp = gop_cache->get_start_time(); | 1461 | + cache_metadata->header.timestamp = gop_cache->start_time(); |
| 1461 | } | 1462 | } |
| 1462 | if (cache_sh_video) { | 1463 | if (cache_sh_video) { |
| 1463 | - cache_sh_video->header.timestamp = gop_cache->get_start_time(); | 1464 | + cache_sh_video->header.timestamp = gop_cache->start_time(); |
| 1464 | } | 1465 | } |
| 1465 | if (cache_sh_audio) { | 1466 | if (cache_sh_audio) { |
| 1466 | - cache_sh_audio->header.timestamp = gop_cache->get_start_time(); | 1467 | + cache_sh_audio->header.timestamp = gop_cache->start_time(); |
| 1467 | } | 1468 | } |
| 1468 | } | 1469 | } |
| 1469 | 1470 |
| @@ -224,7 +224,7 @@ private: | @@ -224,7 +224,7 @@ private: | ||
| 224 | * gop cache is disabled for pure audio stream. | 224 | * gop cache is disabled for pure audio stream. |
| 225 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/124 | 225 | * @see: https://github.com/winlinvip/simple-rtmp-server/issues/124 |
| 226 | */ | 226 | */ |
| 227 | - int audio_count_after_last_video; | 227 | + int audio_after_last_video_count; |
| 228 | /** | 228 | /** |
| 229 | * cached gop. | 229 | * cached gop. |
| 230 | */ | 230 | */ |
| @@ -233,6 +233,9 @@ public: | @@ -233,6 +233,9 @@ public: | ||
| 233 | SrsGopCache(); | 233 | SrsGopCache(); |
| 234 | virtual ~SrsGopCache(); | 234 | virtual ~SrsGopCache(); |
| 235 | public: | 235 | public: |
| 236 | + /** | ||
| 237 | + * to enable or disable the gop cache. | ||
| 238 | + */ | ||
| 236 | virtual void set(bool enabled); | 239 | virtual void set(bool enabled); |
| 237 | /** | 240 | /** |
| 238 | * only for h264 codec | 241 | * only for h264 codec |
| @@ -240,14 +243,26 @@ public: | @@ -240,14 +243,26 @@ public: | ||
| 240 | * 2. clear gop when got keyframe. | 243 | * 2. clear gop when got keyframe. |
| 241 | */ | 244 | */ |
| 242 | virtual int cache(SrsSharedPtrMessage* msg); | 245 | virtual int cache(SrsSharedPtrMessage* msg); |
| 246 | + /** | ||
| 247 | + * clear the gop cache. | ||
| 248 | + */ | ||
| 243 | virtual void clear(); | 249 | virtual void clear(); |
| 244 | - virtual int dump(SrsConsumer* consumer, bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm); | 250 | + /** |
| 251 | + * dump the cached gop to consumer. | ||
| 252 | + */ | ||
| 253 | + virtual int dump(SrsConsumer* consumer, | ||
| 254 | + bool atc, int tba, int tbv, SrsRtmpJitterAlgorithm jitter_algorithm | ||
| 255 | + ); | ||
| 245 | /** | 256 | /** |
| 246 | * used for atc to get the time of gop cache, | 257 | * used for atc to get the time of gop cache, |
| 247 | * the atc will adjust the sequence header timestamp to gop cache. | 258 | * the atc will adjust the sequence header timestamp to gop cache. |
| 248 | */ | 259 | */ |
| 249 | virtual bool empty(); | 260 | virtual bool empty(); |
| 250 | - virtual int64_t get_start_time(); | 261 | + /** |
| 262 | + * get the start time of gop cache, in ms. | ||
| 263 | + * @return 0 if no packets. | ||
| 264 | + */ | ||
| 265 | + virtual int64_t start_time(); | ||
| 251 | }; | 266 | }; |
| 252 | 267 | ||
| 253 | /** | 268 | /** |
-
请 注册 或 登录 后发表评论