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 |
11 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h" | 11 #include "webrtc/modules/video_coding/rtp_frame_reference_finder.h" |
12 | 12 |
13 #include <algorithm> | 13 #include <algorithm> |
14 #include <limits> | 14 #include <limits> |
15 | 15 |
16 #include "webrtc/modules/video_coding/frame_object.h" | 16 #include "webrtc/modules/video_coding/frame_object.h" |
17 #include "webrtc/modules/video_coding/packet_buffer.h" | 17 #include "webrtc/modules/video_coding/packet_buffer.h" |
18 #include "webrtc/rtc_base/checks.h" | 18 #include "webrtc/rtc_base/checks.h" |
19 #include "webrtc/rtc_base/logging.h" | 19 #include "webrtc/rtc_base/logging.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 namespace video_coding { | 22 namespace video_coding { |
23 | 23 |
24 RtpFrameReferenceFinder::RtpFrameReferenceFinder( | 24 RtpFrameReferenceFinder::RtpFrameReferenceFinder( |
25 OnCompleteFrameCallback* frame_callback) | 25 OnCompleteFrameCallback* frame_callback) |
26 : last_picture_id_(-1), | 26 : last_picture_id_(-1), |
27 last_unwrap_(-1), | 27 last_unwrap_(-1), |
28 current_ss_idx_(0), | 28 current_ss_idx_(0), |
29 cleared_to_seq_num_(-1), | 29 cleared_to_seq_num_(-1), |
30 frame_callback_(frame_callback) {} | 30 frame_callback_(frame_callback), |
31 generic_unwrapper_(100000), | |
terelius
2017/08/18 11:53:16
Is this the starting point for unwrapped numbers?
philipel
2017/08/24 10:46:10
Changed the SeqNumUnwrapper default start value to
| |
32 unwrapper_(100000) {} | |
31 | 33 |
32 void RtpFrameReferenceFinder::ManageFrame( | 34 void RtpFrameReferenceFinder::ManageFrame( |
33 std::unique_ptr<RtpFrameObject> frame) { | 35 std::unique_ptr<RtpFrameObject> frame) { |
34 rtc::CritScope lock(&crit_); | 36 rtc::CritScope lock(&crit_); |
35 | 37 |
36 // If we have cleared past this frame, drop it. | 38 // If we have cleared past this frame, drop it. |
37 if (cleared_to_seq_num_ != -1 && | 39 if (cleared_to_seq_num_ != -1 && |
38 AheadOf<uint16_t>(cleared_to_seq_num_, frame->first_seq_num())) { | 40 AheadOf<uint16_t>(cleared_to_seq_num_, frame->first_seq_num())) { |
39 return; | 41 return; |
40 } | 42 } |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 | 171 |
170 RtpFrameReferenceFinder::FrameDecision | 172 RtpFrameReferenceFinder::FrameDecision |
171 RtpFrameReferenceFinder::ManageFrameGeneric(RtpFrameObject* frame, | 173 RtpFrameReferenceFinder::ManageFrameGeneric(RtpFrameObject* frame, |
172 int picture_id) { | 174 int picture_id) { |
173 // If |picture_id| is specified then we use that to set the frame references, | 175 // If |picture_id| is specified then we use that to set the frame references, |
174 // otherwise we use sequence number. | 176 // otherwise we use sequence number. |
175 if (picture_id != kNoPictureId) { | 177 if (picture_id != kNoPictureId) { |
176 if (last_unwrap_ == -1) | 178 if (last_unwrap_ == -1) |
177 last_unwrap_ = picture_id; | 179 last_unwrap_ = picture_id; |
178 | 180 |
179 frame->picture_id = UnwrapPictureId(picture_id % kPicIdLength); | 181 frame->picture_id = unwrapper_.Unwrap(picture_id); |
180 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; | 182 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; |
181 frame->references[0] = frame->picture_id - 1; | 183 frame->references[0] = frame->picture_id - 1; |
182 return kHandOff; | 184 return kHandOff; |
183 } | 185 } |
184 | 186 |
185 if (frame->frame_type() == kVideoFrameKey) { | 187 if (frame->frame_type() == kVideoFrameKey) { |
186 last_seq_num_gop_.insert(std::make_pair( | 188 last_seq_num_gop_.insert(std::make_pair( |
187 frame->last_seq_num(), | 189 frame->last_seq_num(), |
188 std::make_pair(frame->last_seq_num(), frame->last_seq_num()))); | 190 std::make_pair(frame->last_seq_num(), frame->last_seq_num()))); |
189 } | 191 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 if (prev_seq_num != last_picture_id_with_padding_gop) | 223 if (prev_seq_num != last_picture_id_with_padding_gop) |
222 return kStash; | 224 return kStash; |
223 } | 225 } |
224 | 226 |
225 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); | 227 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); |
226 | 228 |
227 // Since keyframes can cause reordering we can't simply assign the | 229 // Since keyframes can cause reordering we can't simply assign the |
228 // picture id according to some incrementing counter. | 230 // picture id according to some incrementing counter. |
229 frame->picture_id = frame->last_seq_num(); | 231 frame->picture_id = frame->last_seq_num(); |
230 frame->num_references = frame->frame_type() == kVideoFrameDelta; | 232 frame->num_references = frame->frame_type() == kVideoFrameDelta; |
231 frame->references[0] = last_picture_id_gop; | 233 frame->references[0] = generic_unwrapper_.Unwrap(last_picture_id_gop); |
232 if (AheadOf(frame->picture_id, last_picture_id_gop)) { | 234 if (AheadOf<uint16_t>(frame->picture_id, last_picture_id_gop)) { |
233 seq_num_it->second.first = frame->picture_id; | 235 seq_num_it->second.first = frame->picture_id; |
234 seq_num_it->second.second = frame->picture_id; | 236 seq_num_it->second.second = frame->picture_id; |
235 } | 237 } |
236 | 238 |
237 last_picture_id_ = frame->picture_id; | 239 last_picture_id_ = frame->picture_id; |
238 UpdateLastPictureIdWithPadding(frame->picture_id); | 240 UpdateLastPictureIdWithPadding(frame->picture_id); |
241 frame->picture_id = generic_unwrapper_.Unwrap(frame->picture_id); | |
239 return kHandOff; | 242 return kHandOff; |
240 } | 243 } |
241 | 244 |
242 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp8( | 245 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp8( |
243 RtpFrameObject* frame) { | 246 RtpFrameObject* frame) { |
244 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); | 247 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); |
245 if (!rtp_codec_header) | 248 if (!rtp_codec_header) |
246 return kDrop; | 249 return kDrop; |
247 | 250 |
248 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; | 251 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 } | 363 } |
361 | 364 |
362 UpdateLayerInfoVp8(frame); | 365 UpdateLayerInfoVp8(frame); |
363 return kHandOff; | 366 return kHandOff; |
364 } | 367 } |
365 | 368 |
366 void RtpFrameReferenceFinder::UpdateLayerInfoVp8(RtpFrameObject* frame) { | 369 void RtpFrameReferenceFinder::UpdateLayerInfoVp8(RtpFrameObject* frame) { |
367 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); | 370 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); |
368 RTC_DCHECK(rtp_codec_header); | 371 RTC_DCHECK(rtp_codec_header); |
369 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; | 372 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; |
370 | |
371 uint8_t tl0_pic_idx = codec_header.tl0PicIdx; | 373 uint8_t tl0_pic_idx = codec_header.tl0PicIdx; |
372 uint8_t temporal_index = codec_header.temporalIdx; | 374 uint8_t temporal_index = codec_header.temporalIdx; |
373 auto layer_info_it = layer_info_.find(tl0_pic_idx); | 375 auto layer_info_it = layer_info_.find(tl0_pic_idx); |
374 | 376 |
375 // Update this layer info and newer. | 377 // Update this layer info and newer. |
376 while (layer_info_it != layer_info_.end()) { | 378 while (layer_info_it != layer_info_.end()) { |
377 if (layer_info_it->second[temporal_index] != -1 && | 379 if (layer_info_it->second[temporal_index] != -1 && |
378 AheadOf<uint16_t, kPicIdLength>(layer_info_it->second[temporal_index], | 380 AheadOf<uint16_t, kPicIdLength>(layer_info_it->second[temporal_index], |
379 frame->picture_id)) { | 381 frame->picture_id)) { |
380 // The frame was not newer, then no subsequent layer info have to be | 382 // The frame was not newer, then no subsequent layer info have to be |
381 // update. | 383 // update. |
382 break; | 384 break; |
383 } | 385 } |
384 | 386 |
385 layer_info_it->second[codec_header.temporalIdx] = frame->picture_id; | 387 layer_info_it->second[codec_header.temporalIdx] = frame->picture_id; |
386 ++tl0_pic_idx; | 388 ++tl0_pic_idx; |
387 layer_info_it = layer_info_.find(tl0_pic_idx); | 389 layer_info_it = layer_info_.find(tl0_pic_idx); |
388 } | 390 } |
389 not_yet_received_frames_.erase(frame->picture_id); | 391 not_yet_received_frames_.erase(frame->picture_id); |
390 | 392 |
391 UnwrapPictureIds(frame); | 393 UnwrapPictureIds(frame); |
392 } | 394 } |
393 | 395 |
394 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9( | 396 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9( |
395 RtpFrameObject* frame) { | 397 RtpFrameObject* frame) { |
396 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); | 398 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); |
397 RTC_DCHECK(rtp_codec_header); | 399 if (!rtp_codec_header) |
400 return kDrop; | |
398 const RTPVideoHeaderVP9& codec_header = rtp_codec_header->VP9; | 401 const RTPVideoHeaderVP9& codec_header = rtp_codec_header->VP9; |
399 | 402 |
400 if (codec_header.picture_id == kNoPictureId || | 403 if (codec_header.picture_id == kNoPictureId || |
401 codec_header.temporal_idx == kNoTemporalIdx) { | 404 codec_header.temporal_idx == kNoTemporalIdx) { |
402 return ManageFrameGeneric(std::move(frame), codec_header.picture_id); | 405 return ManageFrameGeneric(std::move(frame), codec_header.picture_id); |
403 } | 406 } |
404 | 407 |
405 frame->spatial_layer = codec_header.spatial_idx; | 408 frame->spatial_layer = codec_header.spatial_idx; |
406 frame->inter_layer_predicted = codec_header.inter_layer_predicted; | 409 frame->inter_layer_predicted = codec_header.inter_layer_predicted; |
407 frame->picture_id = codec_header.picture_id % kPicIdLength; | 410 frame->picture_id = codec_header.picture_id % kPicIdLength; |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
578 ++up_switch_it) { | 581 ++up_switch_it) { |
579 if (up_switch_it->second < temporal_idx) | 582 if (up_switch_it->second < temporal_idx) |
580 return true; | 583 return true; |
581 } | 584 } |
582 | 585 |
583 return false; | 586 return false; |
584 } | 587 } |
585 | 588 |
586 void RtpFrameReferenceFinder::UnwrapPictureIds(RtpFrameObject* frame) { | 589 void RtpFrameReferenceFinder::UnwrapPictureIds(RtpFrameObject* frame) { |
587 for (size_t i = 0; i < frame->num_references; ++i) | 590 for (size_t i = 0; i < frame->num_references; ++i) |
588 frame->references[i] = UnwrapPictureId(frame->references[i]); | 591 frame->references[i] = unwrapper_.Unwrap(frame->references[i]); |
589 frame->picture_id = UnwrapPictureId(frame->picture_id); | 592 frame->picture_id = unwrapper_.Unwrap(frame->picture_id); |
590 } | |
591 | |
592 uint16_t RtpFrameReferenceFinder::UnwrapPictureId(uint16_t picture_id) { | |
593 RTC_DCHECK_NE(-1, last_unwrap_); | |
594 | |
595 uint16_t unwrap_truncated = last_unwrap_ % kPicIdLength; | |
596 uint16_t diff = MinDiff<uint16_t, kPicIdLength>(unwrap_truncated, picture_id); | |
597 | |
598 if (AheadOf<uint16_t, kPicIdLength>(picture_id, unwrap_truncated)) | |
599 last_unwrap_ = Add<1 << 16>(last_unwrap_, diff); | |
600 else | |
601 last_unwrap_ = Subtract<1 << 16>(last_unwrap_, diff); | |
602 | |
603 return last_unwrap_; | |
604 } | 593 } |
605 | 594 |
606 } // namespace video_coding | 595 } // namespace video_coding |
607 } // namespace webrtc | 596 } // namespace webrtc |
OLD | NEW |