mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
fix #408:Queue丢视频时,不应该丢弃SequenceHeader
This commit is contained in:
parent
7e04975b8d
commit
4864e796d6
1 changed files with 32 additions and 35 deletions
67
trunk/src/app/srs_app_source.cpp
Normal file → Executable file
67
trunk/src/app/srs_app_source.cpp
Normal file → Executable file
|
@ -357,52 +357,49 @@ int SrsMessageQueue::dump_packets(SrsConsumer* consumer, bool atc, int tba, int
|
||||||
|
|
||||||
void SrsMessageQueue::shrink()
|
void SrsMessageQueue::shrink()
|
||||||
{
|
{
|
||||||
int iframe_index = -1;
|
SrsSharedPtrMessage* video_sh = NULL;
|
||||||
|
SrsSharedPtrMessage* audio_sh = NULL;
|
||||||
|
int msgs_size = (int)msgs.size();
|
||||||
|
|
||||||
// issue the first iframe.
|
// remove all msg
|
||||||
// skip the first frame, whatever the type of it,
|
// igone the sequence header
|
||||||
// for when we shrinked, the first is the iframe,
|
for (int i = 0; i < (int)msgs.size(); i++) {
|
||||||
// we will directly remove the gop next time.
|
|
||||||
for (int i = 1; i < (int)msgs.size(); i++) {
|
|
||||||
SrsSharedPtrMessage* msg = msgs.at(i);
|
SrsSharedPtrMessage* msg = msgs.at(i);
|
||||||
|
|
||||||
if (msg->is_video()) {
|
if (msg->is_video() && SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) {
|
||||||
if (SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) {
|
srs_freep(video_sh);
|
||||||
// the max frame index to remove.
|
video_sh = msg;
|
||||||
iframe_index = i;
|
continue;
|
||||||
|
|
||||||
// set the start time, we will remove until this frame.
|
|
||||||
av_start_time = msg->timestamp;
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
else if (msg->is_audio() && SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) {
|
||||||
|
srs_freep(audio_sh);
|
||||||
|
audio_sh = msg;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
srs_freep(msg);
|
||||||
}
|
}
|
||||||
|
msgs.clear();
|
||||||
// no iframe, for audio, clear the queue.
|
|
||||||
// it is ok to clear for audio, for the shrink tell us the queue is full.
|
// update av_start_time
|
||||||
// for video, we clear util the I-Frame, for the decoding must start from I-frame,
|
av_start_time = av_end_time;
|
||||||
// for audio, it's ok to clear any data, also we can clear the whole queue.
|
//push_back secquence header and update timestamp
|
||||||
// @see: https://github.com/simple-rtmp-server/srs/issues/134
|
if (video_sh) {
|
||||||
if (iframe_index < 0) {
|
video_sh->timestamp = av_end_time;
|
||||||
clear();
|
msgs.push_back(video_sh);
|
||||||
return;
|
}
|
||||||
|
if (audio_sh) {
|
||||||
|
audio_sh->timestamp = av_end_time;
|
||||||
|
msgs.push_back(audio_sh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_ignore_shrink) {
|
if (_ignore_shrink) {
|
||||||
srs_info("shrink the cache queue, size=%d, removed=%d, max=%.2f",
|
srs_info("shrink the cache queue, size=%d, removed=%d, max=%.2f",
|
||||||
(int)msgs.size(), iframe_index, queue_size_ms / 1000.0);
|
(int)msgs.size(), msgs_size - (int)msgs.size(), queue_size_ms / 1000.0);
|
||||||
} else {
|
} else {
|
||||||
srs_trace("shrink the cache queue, size=%d, removed=%d, max=%.2f",
|
srs_trace("shrink the cache queue, size=%d, removed=%d, max=%.2f",
|
||||||
(int)msgs.size(), iframe_index, queue_size_ms / 1000.0);
|
(int)msgs.size(), msgs_size - (int)msgs.size(), queue_size_ms / 1000.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the first gop from the front
|
|
||||||
for (int i = 0; i < iframe_index; i++) {
|
|
||||||
SrsSharedPtrMessage* msg = msgs.at(i);
|
|
||||||
srs_freep(msg);
|
|
||||||
}
|
|
||||||
msgs.erase(msgs.begin(), msgs.begin() + iframe_index);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsMessageQueue::clear()
|
void SrsMessageQueue::clear()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue