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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
169 | 169 |
170 RtpFrameReferenceFinder::FrameDecision | 170 RtpFrameReferenceFinder::FrameDecision |
171 RtpFrameReferenceFinder::ManageFrameGeneric(RtpFrameObject* frame, | 171 RtpFrameReferenceFinder::ManageFrameGeneric(RtpFrameObject* frame, |
172 int picture_id) { | 172 int picture_id) { |
173 // If |picture_id| is specified then we use that to set the frame references, | 173 // If |picture_id| is specified then we use that to set the frame references, |
174 // otherwise we use sequence number. | 174 // otherwise we use sequence number. |
175 if (picture_id != kNoPictureId) { | 175 if (picture_id != kNoPictureId) { |
176 if (last_unwrap_ == -1) | 176 if (last_unwrap_ == -1) |
177 last_unwrap_ = picture_id; | 177 last_unwrap_ = picture_id; |
178 | 178 |
179 frame->picture_id = UnwrapPictureId(picture_id % kPicIdLength); | 179 frame->picture_id = unwrapper_.Unwrap(picture_id); |
180 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; | 180 frame->num_references = frame->frame_type() == kVideoFrameKey ? 0 : 1; |
181 frame->references[0] = frame->picture_id - 1; | 181 frame->references[0] = frame->picture_id - 1; |
182 return kHandOff; | 182 return kHandOff; |
183 } | 183 } |
184 | 184 |
185 if (frame->frame_type() == kVideoFrameKey) { | 185 if (frame->frame_type() == kVideoFrameKey) { |
186 last_seq_num_gop_.insert(std::make_pair( | 186 last_seq_num_gop_.insert(std::make_pair( |
187 frame->last_seq_num(), | 187 frame->last_seq_num(), |
188 std::make_pair(frame->last_seq_num(), frame->last_seq_num()))); | 188 std::make_pair(frame->last_seq_num(), frame->last_seq_num()))); |
189 } | 189 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 if (prev_seq_num != last_picture_id_with_padding_gop) | 221 if (prev_seq_num != last_picture_id_with_padding_gop) |
222 return kStash; | 222 return kStash; |
223 } | 223 } |
224 | 224 |
225 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); | 225 RTC_DCHECK(AheadOrAt(frame->last_seq_num(), seq_num_it->first)); |
226 | 226 |
227 // Since keyframes can cause reordering we can't simply assign the | 227 // Since keyframes can cause reordering we can't simply assign the |
228 // picture id according to some incrementing counter. | 228 // picture id according to some incrementing counter. |
229 frame->picture_id = frame->last_seq_num(); | 229 frame->picture_id = frame->last_seq_num(); |
230 frame->num_references = frame->frame_type() == kVideoFrameDelta; | 230 frame->num_references = frame->frame_type() == kVideoFrameDelta; |
231 frame->references[0] = last_picture_id_gop; | 231 frame->references[0] = generic_unwrapper_.Unwrap(last_picture_id_gop); |
232 if (AheadOf(frame->picture_id, last_picture_id_gop)) { | 232 if (AheadOf<uint16_t>(frame->picture_id, last_picture_id_gop)) { |
233 seq_num_it->second.first = frame->picture_id; | 233 seq_num_it->second.first = frame->picture_id; |
234 seq_num_it->second.second = frame->picture_id; | 234 seq_num_it->second.second = frame->picture_id; |
235 } | 235 } |
236 | 236 |
237 last_picture_id_ = frame->picture_id; | 237 last_picture_id_ = frame->picture_id; |
238 UpdateLastPictureIdWithPadding(frame->picture_id); | 238 UpdateLastPictureIdWithPadding(frame->picture_id); |
239 frame->picture_id = generic_unwrapper_.Unwrap(frame->picture_id); | |
239 return kHandOff; | 240 return kHandOff; |
240 } | 241 } |
241 | 242 |
242 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp8( | 243 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp8( |
243 RtpFrameObject* frame) { | 244 RtpFrameObject* frame) { |
244 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); | 245 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); |
245 if (!rtp_codec_header) | 246 if (!rtp_codec_header) |
246 return kDrop; | 247 return kDrop; |
247 | 248 |
248 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; | 249 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
360 } | 361 } |
361 | 362 |
362 UpdateLayerInfoVp8(frame); | 363 UpdateLayerInfoVp8(frame); |
363 return kHandOff; | 364 return kHandOff; |
364 } | 365 } |
365 | 366 |
366 void RtpFrameReferenceFinder::UpdateLayerInfoVp8(RtpFrameObject* frame) { | 367 void RtpFrameReferenceFinder::UpdateLayerInfoVp8(RtpFrameObject* frame) { |
367 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); | 368 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); |
368 RTC_DCHECK(rtp_codec_header); | 369 RTC_DCHECK(rtp_codec_header); |
369 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; | 370 const RTPVideoHeaderVP8& codec_header = rtp_codec_header->VP8; |
370 | |
371 uint8_t tl0_pic_idx = codec_header.tl0PicIdx; | 371 uint8_t tl0_pic_idx = codec_header.tl0PicIdx; |
372 uint8_t temporal_index = codec_header.temporalIdx; | 372 uint8_t temporal_index = codec_header.temporalIdx; |
373 auto layer_info_it = layer_info_.find(tl0_pic_idx); | 373 auto layer_info_it = layer_info_.find(tl0_pic_idx); |
374 | 374 |
375 // Update this layer info and newer. | 375 // Update this layer info and newer. |
376 while (layer_info_it != layer_info_.end()) { | 376 while (layer_info_it != layer_info_.end()) { |
377 if (layer_info_it->second[temporal_index] != -1 && | 377 if (layer_info_it->second[temporal_index] != -1 && |
378 AheadOf<uint16_t, kPicIdLength>(layer_info_it->second[temporal_index], | 378 AheadOf<uint16_t, kPicIdLength>(layer_info_it->second[temporal_index], |
379 frame->picture_id)) { | 379 frame->picture_id)) { |
380 // The frame was not newer, then no subsequent layer info have to be | 380 // The frame was not newer, then no subsequent layer info have to be |
381 // update. | 381 // update. |
382 break; | 382 break; |
383 } | 383 } |
384 | 384 |
385 layer_info_it->second[codec_header.temporalIdx] = frame->picture_id; | 385 layer_info_it->second[codec_header.temporalIdx] = frame->picture_id; |
386 ++tl0_pic_idx; | 386 ++tl0_pic_idx; |
387 layer_info_it = layer_info_.find(tl0_pic_idx); | 387 layer_info_it = layer_info_.find(tl0_pic_idx); |
388 } | 388 } |
389 not_yet_received_frames_.erase(frame->picture_id); | 389 not_yet_received_frames_.erase(frame->picture_id); |
390 | 390 |
391 UnwrapPictureIds(frame); | 391 UnwrapPictureIds(frame); |
392 } | 392 } |
393 | 393 |
394 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9( | 394 RtpFrameReferenceFinder::FrameDecision RtpFrameReferenceFinder::ManageFrameVp9( |
395 RtpFrameObject* frame) { | 395 RtpFrameObject* frame) { |
396 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); | 396 rtc::Optional<RTPVideoTypeHeader> rtp_codec_header = frame->GetCodecHeader(); |
397 RTC_DCHECK(rtp_codec_header); | 397 if (!rtp_codec_header) |
398 return kDrop; | |
stefan-webrtc
2017/09/01 07:25:09
Log error?
philipel
2017/09/01 08:55:46
Done.
| |
398 const RTPVideoHeaderVP9& codec_header = rtp_codec_header->VP9; | 399 const RTPVideoHeaderVP9& codec_header = rtp_codec_header->VP9; |
399 | 400 |
400 if (codec_header.picture_id == kNoPictureId || | 401 if (codec_header.picture_id == kNoPictureId || |
401 codec_header.temporal_idx == kNoTemporalIdx) { | 402 codec_header.temporal_idx == kNoTemporalIdx) { |
402 return ManageFrameGeneric(std::move(frame), codec_header.picture_id); | 403 return ManageFrameGeneric(std::move(frame), codec_header.picture_id); |
403 } | 404 } |
404 | 405 |
405 frame->spatial_layer = codec_header.spatial_idx; | 406 frame->spatial_layer = codec_header.spatial_idx; |
406 frame->inter_layer_predicted = codec_header.inter_layer_predicted; | 407 frame->inter_layer_predicted = codec_header.inter_layer_predicted; |
407 frame->picture_id = codec_header.picture_id % kPicIdLength; | 408 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) { | 579 ++up_switch_it) { |
579 if (up_switch_it->second < temporal_idx) | 580 if (up_switch_it->second < temporal_idx) |
580 return true; | 581 return true; |
581 } | 582 } |
582 | 583 |
583 return false; | 584 return false; |
584 } | 585 } |
585 | 586 |
586 void RtpFrameReferenceFinder::UnwrapPictureIds(RtpFrameObject* frame) { | 587 void RtpFrameReferenceFinder::UnwrapPictureIds(RtpFrameObject* frame) { |
587 for (size_t i = 0; i < frame->num_references; ++i) | 588 for (size_t i = 0; i < frame->num_references; ++i) |
588 frame->references[i] = UnwrapPictureId(frame->references[i]); | 589 frame->references[i] = unwrapper_.Unwrap(frame->references[i]); |
589 frame->picture_id = UnwrapPictureId(frame->picture_id); | 590 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 } | 591 } |
605 | 592 |
606 } // namespace video_coding | 593 } // namespace video_coding |
607 } // namespace webrtc | 594 } // namespace webrtc |
OLD | NEW |