Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: webrtc/modules/video_coding/rtp_frame_reference_finder.cc

Issue 2051453002: Padding is now used to check for continuity in the packet sequence. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Nit fix. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 stashed_padding_.lower_bound(seq_num - kMaxPaddingAge);
58 stashed_padding_.erase(stashed_padding_.begin(), clean_padding_to);
59 stashed_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;
72
73 // Calculate the next contiuous sequence number and search for it in
74 // the padding packets we have stashed.
75 uint16_t next_seq_num_with_padding = gop_seq_num_it->second.second + 1;
76 auto padding_seq_num_it =
77 stashed_padding_.lower_bound(next_seq_num_with_padding);
78
79 // While there still are padding packets and those padding packets are
80 // continuous, then advance the "last-picture-id-with-padding" and remove
81 // the stashed padding packet.
82 while (padding_seq_num_it != stashed_padding_.end() &&
83 *padding_seq_num_it == next_seq_num_with_padding) {
84 gop_seq_num_it->second.second = next_seq_num_with_padding;
85 ++next_seq_num_with_padding;
86 padding_seq_num_it = stashed_padding_.erase(padding_seq_num_it);
87 }
88 }
89
54 void RtpFrameReferenceFinder::RetryStashedFrames() { 90 void RtpFrameReferenceFinder::RetryStashedFrames() {
55 size_t num_stashed_frames = stashed_frames_.size(); 91 size_t num_stashed_frames = stashed_frames_.size();
56 92
57 // Clean up stashed frames if there are too many. 93 // Clean up stashed frames if there are too many.
58 while (stashed_frames_.size() > kMaxStashedFrames) 94 while (stashed_frames_.size() > kMaxStashedFrames)
59 stashed_frames_.pop(); 95 stashed_frames_.pop();
60 96
61 // Since frames are stashed if there is not enough data to determine their 97 // 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 98 // frame references we should at most check |stashed_frames_.size()| in
63 // order to not pop and push frames in and endless loop. 99 // order to not pop and push frames in and endless loop.
(...skipping 13 matching lines...) Expand all
77 if (last_unwrap_ == -1) 113 if (last_unwrap_ == -1)
78 last_unwrap_ = picture_id; 114 last_unwrap_ = picture_id;
79 115
80 frame->picture_id = UnwrapPictureId(picture_id % kPicIdLength); 116 frame->picture_id = UnwrapPictureId(picture_id % kPicIdLength);
81 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; 117 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1;
82 frame->references[0] = frame->picture_id - 1; 118 frame->references[0] = frame->picture_id - 1;
83 frame_callback_->OnCompleteFrame(std::move(frame)); 119 frame_callback_->OnCompleteFrame(std::move(frame));
84 return; 120 return;
85 } 121 }
86 122
87 if (frame->frame_type() == kVideoFrameKey) 123 if (frame->frame_type() == kVideoFrameKey) {
88 last_seq_num_gop_[frame->last_seq_num()] = frame->last_seq_num(); 124 last_seq_num_gop_.insert(std::make_pair(
125 frame->last_seq_num(),
126 std::make_pair(frame->last_seq_num(), frame->last_seq_num())));
127 }
89 128
90 // We have received a frame but not yet a keyframe, stash this frame. 129 // We have received a frame but not yet a keyframe, stash this frame.
91 if (last_seq_num_gop_.empty()) { 130 if (last_seq_num_gop_.empty()) {
92 stashed_frames_.emplace(std::move(frame)); 131 stashed_frames_.emplace(std::move(frame));
93 return; 132 return;
94 } 133 }
95 134
96 // Clean up info for old keyframes but make sure to keep info 135 // Clean up info for old keyframes but make sure to keep info
97 // for the last keyframe. 136 // for the last keyframe.
98 auto clean_to = last_seq_num_gop_.lower_bound(frame->last_seq_num() - 100); 137 auto clean_to = last_seq_num_gop_.lower_bound(frame->last_seq_num() - 100);
99 if (clean_to != last_seq_num_gop_.end()) 138 if (clean_to != last_seq_num_gop_.end())
100 last_seq_num_gop_.erase(last_seq_num_gop_.begin(), clean_to); 139 last_seq_num_gop_.erase(last_seq_num_gop_.begin(), clean_to);
101 140
102 // Find the last sequence number of the last frame for the keyframe 141 // Find the last sequence number of the last frame for the keyframe
103 // that this frame indirectly references. 142 // that this frame indirectly references.
104 auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num()); 143 auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num());
144 if (seq_num_it == last_seq_num_gop_.begin()) {
145 LOG(LS_WARNING) << "Generic frame with packet range ["
146 << frame->first_seq_num() << ", " << frame->last_seq_num()
147 << "] has no Gop, dropping frame.";
148 return;
149 }
105 seq_num_it--; 150 seq_num_it--;
106 151
107 // Make sure the packet sequence numbers are continuous, otherwise stash 152 // Make sure the packet sequence numbers are continuous, otherwise stash
108 // this frame. 153 // this frame.
154 uint16_t last_picture_id_gop = seq_num_it->second.first;
155 uint16_t last_picture_id_with_padding_gop = seq_num_it->second.second;
109 if (frame->frame_type() == kVideoFrameDelta) { 156 if (frame->frame_type() == kVideoFrameDelta) {
110 if (seq_num_it->second != 157 uint16_t prev_seq_num = frame->first_seq_num() - 1;
111 static_cast<uint16_t>(frame->first_seq_num() - 1)) { 158 if (prev_seq_num != last_picture_id_with_padding_gop) {
112 stashed_frames_.emplace(std::move(frame)); 159 stashed_frames_.emplace(std::move(frame));
113 return; 160 return;
114 } 161 }
115 } 162 }
116 163
117 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); 164 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first));
118 165
119 // Since keyframes can cause reordering we can't simply assign the 166 // Since keyframes can cause reordering we can't simply assign the
120 // picture id according to some incrementing counter. 167 // picture id according to some incrementing counter.
121 frame->picture_id = frame->last_seq_num(); 168 frame->picture_id = frame->last_seq_num();
122 frame->num_references = frame->frame_type() == kVideoFrameDelta; 169 frame->num_references = frame->frame_type() == kVideoFrameDelta;
123 frame->references[0] = seq_num_it->second; 170 frame->references[0] = last_picture_id_gop;
124 seq_num_it->second = frame->picture_id; 171 if (AheadOf(frame->picture_id, last_picture_id_gop)) {
172 seq_num_it->second.first = frame->picture_id;
173 seq_num_it->second.second = frame->picture_id;
174 }
125 175
126 last_picture_id_ = frame->picture_id; 176 last_picture_id_ = frame->picture_id;
177 UpdateLastPictureIdWithPadding(frame->picture_id);
127 frame_callback_->OnCompleteFrame(std::move(frame)); 178 frame_callback_->OnCompleteFrame(std::move(frame));
128 RetryStashedFrames(); 179 RetryStashedFrames();
129 } 180 }
130 181
131 void RtpFrameReferenceFinder::ManageFrameVp8( 182 void RtpFrameReferenceFinder::ManageFrameVp8(
132 std::unique_ptr<RtpFrameObject> frame) { 183 std::unique_ptr<RtpFrameObject> frame) {
133 RTPVideoTypeHeader* rtp_codec_header = frame->GetCodecHeader(); 184 RTPVideoTypeHeader* rtp_codec_header = frame->GetCodecHeader();
134 if (!rtp_codec_header) 185 if (!rtp_codec_header)
135 return; 186 return;
136 187
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated)) 543 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated))
493 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff); 544 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff);
494 else 545 else
495 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff); 546 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff);
496 547
497 return last_unwrap_; 548 return last_unwrap_;
498 } 549 }
499 550
500 } // namespace video_coding 551 } // namespace video_coding
501 } // namespace webrtc 552 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/video_coding/rtp_frame_reference_finder.h ('k') | webrtc/modules/video_coding/video_packet_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698