Chromium Code Reviews| Index: webrtc/modules/video_coding/rtp_frame_reference_finder.cc |
| diff --git a/webrtc/modules/video_coding/rtp_frame_reference_finder.cc b/webrtc/modules/video_coding/rtp_frame_reference_finder.cc |
| index 7e87d3812bd8fefe3de5d7bbc31c9c7f9edda26d..70a1454e20cd811088a0705da5f8c360d494e372 100644 |
| --- a/webrtc/modules/video_coding/rtp_frame_reference_finder.cc |
| +++ b/webrtc/modules/video_coding/rtp_frame_reference_finder.cc |
| @@ -51,6 +51,38 @@ void RtpFrameReferenceFinder::ManageFrame( |
| } |
| } |
| +void RtpFrameReferenceFinder::PaddingReceived(uint16_t seq_num) { |
| + rtc::CritScope lock(&crit_); |
| + auto clean_padding_to = |
| + received_padding_.lower_bound(seq_num - kMaxPaddingAge); |
| + received_padding_.erase(received_padding_.begin(), clean_padding_to); |
| + received_padding_.insert(seq_num); |
| + UpdateLastPictureIdWithPadding(seq_num); |
| + RetryStashedFrames(); |
| +} |
| + |
| +void RtpFrameReferenceFinder::UpdateLastPictureIdWithPadding(uint16_t seq_num) { |
| + auto gop_seq_num_it = last_seq_num_gop_.upper_bound(seq_num); |
| + |
| + // If this padding packet "belongs" to a group of pictures that we don't track |
| + // anymore, do nothing. |
| + if (gop_seq_num_it == last_seq_num_gop_.begin()) |
| + return; |
| + gop_seq_num_it--; |
|
stefan-webrtc
2016/07/05 08:00:40
--gop_seq_num_it;
philipel
2016/07/05 08:41:00
Done.
|
| + |
| + // Find the relevant group of pictures and update its "last-picture-id-with |
| + // padding" sequence number. |
|
stefan-webrtc
2016/07/05 08:00:40
I think you should describe what the "last picture
philipel
2016/07/05 08:41:00
Added more comments to clarify.
stefan-webrtc
2016/07/05 08:47:54
Thanks, a lot better!
|
| + uint16_t next_picture_id_with_padding = gop_seq_num_it->second.second + 1; |
| + auto padding_seq_num_it = |
| + received_padding_.lower_bound(next_picture_id_with_padding); |
| + while (padding_seq_num_it != received_padding_.end() && |
|
stefan-webrtc
2016/07/05 08:00:40
What does this loop do? Add a comment.
philipel
2016/07/05 08:41:00
Done.
|
| + *padding_seq_num_it == next_picture_id_with_padding) { |
| + gop_seq_num_it->second.second = next_picture_id_with_padding; |
| + ++next_picture_id_with_padding; |
| + padding_seq_num_it = received_padding_.erase(padding_seq_num_it); |
| + } |
| +} |
| + |
| void RtpFrameReferenceFinder::RetryStashedFrames() { |
| size_t num_stashed_frames = stashed_frames_.size(); |
| @@ -85,7 +117,9 @@ void RtpFrameReferenceFinder::ManageFrameGeneric( |
| } |
| if (frame->frame_type() == kVideoFrameKey) |
|
stefan-webrtc
2016/07/05 08:00:40
{}
philipel
2016/07/05 08:41:01
Done.
|
| - last_seq_num_gop_[frame->last_seq_num()] = frame->last_seq_num(); |
| + last_seq_num_gop_.insert(std::make_pair( |
| + frame->last_seq_num(), |
| + std::make_pair(frame->last_seq_num(), frame->last_seq_num()))); |
| // We have received a frame but not yet a keyframe, stash this frame. |
| if (last_seq_num_gop_.empty()) { |
| @@ -102,13 +136,21 @@ void RtpFrameReferenceFinder::ManageFrameGeneric( |
| // Find the last sequence number of the last frame for the keyframe |
| // that this frame indirectly references. |
| auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num()); |
| + if (seq_num_it == last_seq_num_gop_.begin()) { |
| + LOG(LS_WARNING) << "Generic frame with packet range [" |
| + << frame->first_seq_num() << ", " << frame->last_seq_num() |
| + << "] has no Gop, dropping frame."; |
| + return; |
| + } |
| seq_num_it--; |
| // Make sure the packet sequence numbers are continuous, otherwise stash |
| // this frame. |
| + uint16_t last_picture_id_gop = seq_num_it->second.first; |
| + uint16_t last_picture_id_with_padding_gop = seq_num_it->second.second; |
| if (frame->frame_type() == kVideoFrameDelta) { |
| - if (seq_num_it->second != |
| - static_cast<uint16_t>(frame->first_seq_num() - 1)) { |
| + uint16_t prev_seq_num = frame->first_seq_num() - 1; |
| + if (prev_seq_num != last_picture_id_with_padding_gop) { |
| stashed_frames_.emplace(std::move(frame)); |
| return; |
| } |
| @@ -120,10 +162,14 @@ void RtpFrameReferenceFinder::ManageFrameGeneric( |
| // picture id according to some incrementing counter. |
| frame->picture_id = frame->last_seq_num(); |
| frame->num_references = frame->frame_type() == kVideoFrameDelta; |
| - frame->references[0] = seq_num_it->second; |
| - seq_num_it->second = frame->picture_id; |
| + frame->references[0] = last_picture_id_gop; |
| + if (AheadOf(frame->picture_id, last_picture_id_gop)) { |
| + seq_num_it->second.first = frame->picture_id; |
| + seq_num_it->second.second = frame->picture_id; |
| + } |
| last_picture_id_ = frame->picture_id; |
| + UpdateLastPictureIdWithPadding(frame->picture_id); |
| frame_callback_->OnCompleteFrame(std::move(frame)); |
| RetryStashedFrames(); |
| } |