Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 44 ManageFrameVp9(std::move(frame)); | 44 ManageFrameVp9(std::move(frame)); |
| 45 break; | 45 break; |
| 46 case kVideoCodecH264: | 46 case kVideoCodecH264: |
| 47 case kVideoCodecI420: | 47 case kVideoCodecI420: |
| 48 case kVideoCodecGeneric: | 48 case kVideoCodecGeneric: |
| 49 ManageFrameGeneric(std::move(frame), kNoPictureId); | 49 ManageFrameGeneric(std::move(frame), kNoPictureId); |
| 50 break; | 50 break; |
| 51 } | 51 } |
| 52 } | 52 } |
| 53 | 53 |
| 54 void RtpFrameReferenceFinder::PaddingReceived(uint16_t seq_num) { | |
| 55 rtc::CritScope lock(&crit_); | |
| 56 auto clean_padding_to = | |
| 57 received_padding_.lower_bound(seq_num - kMaxPaddingAge); | |
| 58 received_padding_.erase(received_padding_.begin(), clean_padding_to); | |
| 59 received_padding_.insert(seq_num); | |
| 60 UpdateLastPictureIdWithPadding(seq_num); | |
| 61 RetryStashedFrames(); | |
| 62 } | |
| 63 | |
| 64 void RtpFrameReferenceFinder::UpdateLastPictureIdWithPadding(uint16_t seq_num) { | |
| 65 auto gop_seq_num_it = last_seq_num_gop_.upper_bound(seq_num); | |
| 66 | |
| 67 // If this padding packet "belongs" to a group of pictures that we don't track | |
| 68 // anymore, do nothing. | |
| 69 if (gop_seq_num_it == last_seq_num_gop_.begin()) | |
| 70 return; | |
| 71 gop_seq_num_it--; | |
|
stefan-webrtc
2016/07/05 08:00:40
--gop_seq_num_it;
philipel
2016/07/05 08:41:00
Done.
| |
| 72 | |
| 73 // Find the relevant group of pictures and update its "last-picture-id-with | |
| 74 // 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!
| |
| 75 uint16_t next_picture_id_with_padding = gop_seq_num_it->second.second + 1; | |
| 76 auto padding_seq_num_it = | |
| 77 received_padding_.lower_bound(next_picture_id_with_padding); | |
| 78 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.
| |
| 79 *padding_seq_num_it == next_picture_id_with_padding) { | |
| 80 gop_seq_num_it->second.second = next_picture_id_with_padding; | |
| 81 ++next_picture_id_with_padding; | |
| 82 padding_seq_num_it = received_padding_.erase(padding_seq_num_it); | |
| 83 } | |
| 84 } | |
| 85 | |
| 54 void RtpFrameReferenceFinder::RetryStashedFrames() { | 86 void RtpFrameReferenceFinder::RetryStashedFrames() { |
| 55 size_t num_stashed_frames = stashed_frames_.size(); | 87 size_t num_stashed_frames = stashed_frames_.size(); |
| 56 | 88 |
| 57 // Clean up stashed frames if there are too many. | 89 // Clean up stashed frames if there are too many. |
| 58 while (stashed_frames_.size() > kMaxStashedFrames) | 90 while (stashed_frames_.size() > kMaxStashedFrames) |
| 59 stashed_frames_.pop(); | 91 stashed_frames_.pop(); |
| 60 | 92 |
| 61 // Since frames are stashed if there is not enough data to determine their | 93 // Since frames are stashed if there is not enough data to determine their |
| 62 // frame references we should at most check |stashed_frames_.size()| in | 94 // frame references we should at most check |stashed_frames_.size()| in |
| 63 // order to not pop and push frames in and endless loop. | 95 // order to not pop and push frames in and endless loop. |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 77 if (last_unwrap_ == -1) | 109 if (last_unwrap_ == -1) |
| 78 last_unwrap_ = picture_id; | 110 last_unwrap_ = picture_id; |
| 79 | 111 |
| 80 frame->picture_id = UnwrapPictureId(picture_id % kPicIdLength); | 112 frame->picture_id = UnwrapPictureId(picture_id % kPicIdLength); |
| 81 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; | 113 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; |
| 82 frame->references[0] = frame->picture_id - 1; | 114 frame->references[0] = frame->picture_id - 1; |
| 83 frame_callback_->OnCompleteFrame(std::move(frame)); | 115 frame_callback_->OnCompleteFrame(std::move(frame)); |
| 84 return; | 116 return; |
| 85 } | 117 } |
| 86 | 118 |
| 87 if (frame->frame_type() == kVideoFrameKey) | 119 if (frame->frame_type() == kVideoFrameKey) |
|
stefan-webrtc
2016/07/05 08:00:40
{}
philipel
2016/07/05 08:41:01
Done.
| |
| 88 last_seq_num_gop_[frame->last_seq_num()] = frame->last_seq_num(); | 120 last_seq_num_gop_.insert(std::make_pair( |
| 121 frame->last_seq_num(), | |
| 122 std::make_pair(frame->last_seq_num(), frame->last_seq_num()))); | |
| 89 | 123 |
| 90 // We have received a frame but not yet a keyframe, stash this frame. | 124 // We have received a frame but not yet a keyframe, stash this frame. |
| 91 if (last_seq_num_gop_.empty()) { | 125 if (last_seq_num_gop_.empty()) { |
| 92 stashed_frames_.emplace(std::move(frame)); | 126 stashed_frames_.emplace(std::move(frame)); |
| 93 return; | 127 return; |
| 94 } | 128 } |
| 95 | 129 |
| 96 // Clean up info for old keyframes but make sure to keep info | 130 // Clean up info for old keyframes but make sure to keep info |
| 97 // for the last keyframe. | 131 // for the last keyframe. |
| 98 auto clean_to = last_seq_num_gop_.lower_bound(frame->last_seq_num() - 100); | 132 auto clean_to = last_seq_num_gop_.lower_bound(frame->last_seq_num() - 100); |
| 99 if (clean_to != last_seq_num_gop_.end()) | 133 if (clean_to != last_seq_num_gop_.end()) |
| 100 last_seq_num_gop_.erase(last_seq_num_gop_.begin(), clean_to); | 134 last_seq_num_gop_.erase(last_seq_num_gop_.begin(), clean_to); |
| 101 | 135 |
| 102 // Find the last sequence number of the last frame for the keyframe | 136 // Find the last sequence number of the last frame for the keyframe |
| 103 // that this frame indirectly references. | 137 // that this frame indirectly references. |
| 104 auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num()); | 138 auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num()); |
| 139 if (seq_num_it == last_seq_num_gop_.begin()) { | |
| 140 LOG(LS_WARNING) << "Generic frame with packet range [" | |
| 141 << frame->first_seq_num() << ", " << frame->last_seq_num() | |
| 142 << "] has no Gop, dropping frame."; | |
| 143 return; | |
| 144 } | |
| 105 seq_num_it--; | 145 seq_num_it--; |
| 106 | 146 |
| 107 // Make sure the packet sequence numbers are continuous, otherwise stash | 147 // Make sure the packet sequence numbers are continuous, otherwise stash |
| 108 // this frame. | 148 // this frame. |
| 149 uint16_t last_picture_id_gop = seq_num_it->second.first; | |
| 150 uint16_t last_picture_id_with_padding_gop = seq_num_it->second.second; | |
| 109 if (frame->frame_type() == kVideoFrameDelta) { | 151 if (frame->frame_type() == kVideoFrameDelta) { |
| 110 if (seq_num_it->second != | 152 uint16_t prev_seq_num = frame->first_seq_num() - 1; |
| 111 static_cast<uint16_t>(frame->first_seq_num() - 1)) { | 153 if (prev_seq_num != last_picture_id_with_padding_gop) { |
| 112 stashed_frames_.emplace(std::move(frame)); | 154 stashed_frames_.emplace(std::move(frame)); |
| 113 return; | 155 return; |
| 114 } | 156 } |
| 115 } | 157 } |
| 116 | 158 |
| 117 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); | 159 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); |
| 118 | 160 |
| 119 // Since keyframes can cause reordering we can't simply assign the | 161 // Since keyframes can cause reordering we can't simply assign the |
| 120 // picture id according to some incrementing counter. | 162 // picture id according to some incrementing counter. |
| 121 frame->picture_id = frame->last_seq_num(); | 163 frame->picture_id = frame->last_seq_num(); |
| 122 frame->num_references = frame->frame_type() == kVideoFrameDelta; | 164 frame->num_references = frame->frame_type() == kVideoFrameDelta; |
| 123 frame->references[0] = seq_num_it->second; | 165 frame->references[0] = last_picture_id_gop; |
| 124 seq_num_it->second = frame->picture_id; | 166 if (AheadOf(frame->picture_id, last_picture_id_gop)) { |
| 167 seq_num_it->second.first = frame->picture_id; | |
| 168 seq_num_it->second.second = frame->picture_id; | |
| 169 } | |
| 125 | 170 |
| 126 last_picture_id_ = frame->picture_id; | 171 last_picture_id_ = frame->picture_id; |
| 172 UpdateLastPictureIdWithPadding(frame->picture_id); | |
| 127 frame_callback_->OnCompleteFrame(std::move(frame)); | 173 frame_callback_->OnCompleteFrame(std::move(frame)); |
| 128 RetryStashedFrames(); | 174 RetryStashedFrames(); |
| 129 } | 175 } |
| 130 | 176 |
| 131 void RtpFrameReferenceFinder::ManageFrameVp8( | 177 void RtpFrameReferenceFinder::ManageFrameVp8( |
| 132 std::unique_ptr<RtpFrameObject> frame) { | 178 std::unique_ptr<RtpFrameObject> frame) { |
| 133 RTPVideoTypeHeader* rtp_codec_header = frame->GetCodecHeader(); | 179 RTPVideoTypeHeader* rtp_codec_header = frame->GetCodecHeader(); |
| 134 if (!rtp_codec_header) | 180 if (!rtp_codec_header) |
| 135 return; | 181 return; |
| 136 | 182 |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated)) | 538 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated)) |
| 493 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff); | 539 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff); |
| 494 else | 540 else |
| 495 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff); | 541 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff); |
| 496 | 542 |
| 497 return last_unwrap_; | 543 return last_unwrap_; |
| 498 } | 544 } |
| 499 | 545 |
| 500 } // namespace video_coding | 546 } // namespace video_coding |
| 501 } // namespace webrtc | 547 } // namespace webrtc |
| OLD | NEW |