Merge branch '2.0release' of github.com:simple-rtmp-server/srs into 2.0release
正在显示
1 个修改的文件
包含
32 行增加
和
35 行删除
trunk/src/app/srs_app_source.cpp
100644 → 100755
@@ -357,52 +357,49 @@ int SrsMessageQueue::dump_packets(SrsConsumer* consumer, bool atc, int tba, int | @@ -357,52 +357,49 @@ int SrsMessageQueue::dump_packets(SrsConsumer* consumer, bool atc, int tba, int | ||
357 | 357 | ||
358 | void SrsMessageQueue::shrink() | 358 | void SrsMessageQueue::shrink() |
359 | { | 359 | { |
360 | - int iframe_index = -1; | 360 | + SrsSharedPtrMessage* video_sh = NULL; |
361 | + SrsSharedPtrMessage* audio_sh = NULL; | ||
362 | + int msgs_size = (int)msgs.size(); | ||
361 | 363 | ||
362 | - // issue the first iframe. | ||
363 | - // skip the first frame, whatever the type of it, | ||
364 | - // for when we shrinked, the first is the iframe, | ||
365 | - // we will directly remove the gop next time. | ||
366 | - for (int i = 1; i < (int)msgs.size(); i++) { | 364 | + // remove all msg |
365 | + // igone the sequence header | ||
366 | + for (int i = 0; i < (int)msgs.size(); i++) { | ||
367 | SrsSharedPtrMessage* msg = msgs.at(i); | 367 | SrsSharedPtrMessage* msg = msgs.at(i); |
368 | - | ||
369 | - if (msg->is_video()) { | ||
370 | - if (SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) { | ||
371 | - // the max frame index to remove. | ||
372 | - iframe_index = i; | ||
373 | - | ||
374 | - // set the start time, we will remove until this frame. | ||
375 | - av_start_time = msg->timestamp; | ||
376 | - | ||
377 | - break; | ||
378 | - } | 368 | + |
369 | + if (msg->is_video() && SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) { | ||
370 | + srs_freep(video_sh); | ||
371 | + video_sh = msg; | ||
372 | + continue; | ||
373 | + } | ||
374 | + else if (msg->is_audio() && SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) { | ||
375 | + srs_freep(audio_sh); | ||
376 | + audio_sh = msg; | ||
377 | + continue; | ||
379 | } | 378 | } |
379 | + | ||
380 | + srs_freep(msg); | ||
380 | } | 381 | } |
381 | - | ||
382 | - // no iframe, for audio, clear the queue. | ||
383 | - // it is ok to clear for audio, for the shrink tell us the queue is full. | ||
384 | - // for video, we clear util the I-Frame, for the decoding must start from I-frame, | ||
385 | - // for audio, it's ok to clear any data, also we can clear the whole queue. | ||
386 | - // @see: https://github.com/simple-rtmp-server/srs/issues/134 | ||
387 | - if (iframe_index < 0) { | ||
388 | - clear(); | ||
389 | - return; | 382 | + msgs.clear(); |
383 | + | ||
384 | + // update av_start_time | ||
385 | + av_start_time = av_end_time; | ||
386 | + //push_back secquence header and update timestamp | ||
387 | + if (video_sh) { | ||
388 | + video_sh->timestamp = av_end_time; | ||
389 | + msgs.push_back(video_sh); | ||
390 | + } | ||
391 | + if (audio_sh) { | ||
392 | + audio_sh->timestamp = av_end_time; | ||
393 | + msgs.push_back(audio_sh); | ||
390 | } | 394 | } |
391 | 395 | ||
392 | if (_ignore_shrink) { | 396 | if (_ignore_shrink) { |
393 | srs_info("shrink the cache queue, size=%d, removed=%d, max=%.2f", | 397 | srs_info("shrink the cache queue, size=%d, removed=%d, max=%.2f", |
394 | - (int)msgs.size(), iframe_index, queue_size_ms / 1000.0); | 398 | + (int)msgs.size(), msgs_size - (int)msgs.size(), queue_size_ms / 1000.0); |
395 | } else { | 399 | } else { |
396 | srs_trace("shrink the cache queue, size=%d, removed=%d, max=%.2f", | 400 | srs_trace("shrink the cache queue, size=%d, removed=%d, max=%.2f", |
397 | - (int)msgs.size(), iframe_index, queue_size_ms / 1000.0); | ||
398 | - } | ||
399 | - | ||
400 | - // remove the first gop from the front | ||
401 | - for (int i = 0; i < iframe_index; i++) { | ||
402 | - SrsSharedPtrMessage* msg = msgs.at(i); | ||
403 | - srs_freep(msg); | 401 | + (int)msgs.size(), msgs_size - (int)msgs.size(), queue_size_ms / 1000.0); |
404 | } | 402 | } |
405 | - msgs.erase(msgs.begin(), msgs.begin() + iframe_index); | ||
406 | } | 403 | } |
407 | 404 | ||
408 | void SrsMessageQueue::clear() | 405 | void SrsMessageQueue::clear() |
-
请 注册 或 登录 后发表评论