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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 // While there still are padding packets and those padding packets are | 106 // While there still are padding packets and those padding packets are |
107 // continuous, then advance the "last-picture-id-with-padding" and remove | 107 // continuous, then advance the "last-picture-id-with-padding" and remove |
108 // the stashed padding packet. | 108 // the stashed padding packet. |
109 while (padding_seq_num_it != stashed_padding_.end() && | 109 while (padding_seq_num_it != stashed_padding_.end() && |
110 *padding_seq_num_it == next_seq_num_with_padding) { | 110 *padding_seq_num_it == next_seq_num_with_padding) { |
111 gop_seq_num_it->second.second = next_seq_num_with_padding; | 111 gop_seq_num_it->second.second = next_seq_num_with_padding; |
112 ++next_seq_num_with_padding; | 112 ++next_seq_num_with_padding; |
113 padding_seq_num_it = stashed_padding_.erase(padding_seq_num_it); | 113 padding_seq_num_it = stashed_padding_.erase(padding_seq_num_it); |
114 } | 114 } |
| 115 |
| 116 // In the case where the stream has been continuous without any new keyframes |
| 117 // for a while there is a risk that new frames will appear to be older than |
| 118 // the keyframe they belong to due to wrapping sequence number. In order |
| 119 // to prevent this we advance the picture id of the keyframe every so often. |
| 120 if (ForwardDiff(gop_seq_num_it->first, seq_num) > 10000) { |
| 121 RTC_DCHECK_EQ(1ul, last_seq_num_gop_.size()); |
| 122 last_seq_num_gop_[seq_num] = gop_seq_num_it->second; |
| 123 last_seq_num_gop_.erase(gop_seq_num_it); |
| 124 } |
115 } | 125 } |
116 | 126 |
117 void RtpFrameReferenceFinder::RetryStashedFrames() { | 127 void RtpFrameReferenceFinder::RetryStashedFrames() { |
118 size_t num_stashed_frames = stashed_frames_.size(); | 128 size_t num_stashed_frames = stashed_frames_.size(); |
119 | 129 |
120 // Clean up stashed frames if there are too many. | 130 // Clean up stashed frames if there are too many. |
121 while (stashed_frames_.size() > kMaxStashedFrames) | 131 while (stashed_frames_.size() > kMaxStashedFrames) |
122 stashed_frames_.pop_front(); | 132 stashed_frames_.pop_front(); |
123 | 133 |
124 // Since frames are stashed if there is not enough data to determine their | 134 // Since frames are stashed if there is not enough data to determine their |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 | 167 |
158 // We have received a frame but not yet a keyframe, stash this frame. | 168 // We have received a frame but not yet a keyframe, stash this frame. |
159 if (last_seq_num_gop_.empty()) { | 169 if (last_seq_num_gop_.empty()) { |
160 stashed_frames_.push_back(std::move(frame)); | 170 stashed_frames_.push_back(std::move(frame)); |
161 return; | 171 return; |
162 } | 172 } |
163 | 173 |
164 // Clean up info for old keyframes but make sure to keep info | 174 // Clean up info for old keyframes but make sure to keep info |
165 // for the last keyframe. | 175 // for the last keyframe. |
166 auto clean_to = last_seq_num_gop_.lower_bound(frame->last_seq_num() - 100); | 176 auto clean_to = last_seq_num_gop_.lower_bound(frame->last_seq_num() - 100); |
167 if (clean_to != last_seq_num_gop_.end()) | 177 for (auto it = last_seq_num_gop_.begin(); |
168 last_seq_num_gop_.erase(last_seq_num_gop_.begin(), clean_to); | 178 it != clean_to && last_seq_num_gop_.size() > 1;) { |
| 179 it = last_seq_num_gop_.erase(it); |
| 180 } |
169 | 181 |
170 // Find the last sequence number of the last frame for the keyframe | 182 // Find the last sequence number of the last frame for the keyframe |
171 // that this frame indirectly references. | 183 // that this frame indirectly references. |
172 auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num()); | 184 auto seq_num_it = last_seq_num_gop_.upper_bound(frame->last_seq_num()); |
173 if (seq_num_it == last_seq_num_gop_.begin()) { | 185 if (seq_num_it == last_seq_num_gop_.begin()) { |
174 LOG(LS_WARNING) << "Generic frame with packet range [" | 186 LOG(LS_WARNING) << "Generic frame with packet range [" |
175 << frame->first_seq_num() << ", " << frame->last_seq_num() | 187 << frame->first_seq_num() << ", " << frame->last_seq_num() |
176 << "] has no Gop, dropping frame."; | 188 << "] has no GoP, dropping frame."; |
177 return; | 189 return; |
178 } | 190 } |
179 seq_num_it--; | 191 seq_num_it--; |
180 | 192 |
181 // Make sure the packet sequence numbers are continuous, otherwise stash | 193 // Make sure the packet sequence numbers are continuous, otherwise stash |
182 // this frame. | 194 // this frame. |
183 uint16_t last_picture_id_gop = seq_num_it->second.first; | 195 uint16_t last_picture_id_gop = seq_num_it->second.first; |
184 uint16_t last_picture_id_with_padding_gop = seq_num_it->second.second; | 196 uint16_t last_picture_id_with_padding_gop = seq_num_it->second.second; |
185 if (frame->frame_type() == kVideoFrameDelta) { | 197 if (frame->frame_type() == kVideoFrameDelta) { |
186 uint16_t prev_seq_num = frame->first_seq_num() - 1; | 198 uint16_t prev_seq_num = frame->first_seq_num() - 1; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 if (!gof_info_.empty() && | 741 if (!gof_info_.empty() && |
730 AheadOf<uint8_t>(gof_info_.begin()->first, fixed_tl0)) { | 742 AheadOf<uint8_t>(gof_info_.begin()->first, fixed_tl0)) { |
731 return true; | 743 return true; |
732 } | 744 } |
733 } | 745 } |
734 return false; | 746 return false; |
735 } | 747 } |
736 | 748 |
737 } // namespace video_coding | 749 } // namespace video_coding |
738 } // namespace webrtc | 750 } // namespace webrtc |
OLD | NEW |