Don't recalculate Tl0PicIdx when the VP9 frame has no Tl0PicIdx.
BUG=webrtc:7362
Review-Url: https://codereview.webrtc.org/2760893002
Cr-Commit-Position: refs/heads/master@{#17311}
diff --git a/webrtc/modules/video_coding/rtp_frame_reference_finder.cc b/webrtc/modules/video_coding/rtp_frame_reference_finder.cc
index 5926c52..b0999cc 100644
--- a/webrtc/modules/video_coding/rtp_frame_reference_finder.cc
+++ b/webrtc/modules/video_coding/rtp_frame_reference_finder.cc
@@ -676,11 +676,14 @@
vp9_fix_jump_timestamp_ = frame.timestamp;
gof_info_.clear();
- vp9_fix_tl0_pic_idx_offset_ =
- ForwardDiff<uint8_t>(*tl0_pic_idx, vp9_fix_last_tl0_pic_idx_);
- vp9_fix_tl0_pic_idx_offset_ += kMaxGofSaved;
- fixed_tl0 = Add<kTl0PicIdLength>(*tl0_pic_idx, vp9_fix_tl0_pic_idx_offset_);
- vp9_fix_last_tl0_pic_idx_ = fixed_tl0;
+ if (fixed_tl0 != kNoTl0PicIdx) {
+ vp9_fix_tl0_pic_idx_offset_ =
+ ForwardDiff<uint8_t>(*tl0_pic_idx, vp9_fix_last_tl0_pic_idx_);
+ vp9_fix_tl0_pic_idx_offset_ += kMaxGofSaved;
+ fixed_tl0 =
+ Add<kTl0PicIdLength>(*tl0_pic_idx, vp9_fix_tl0_pic_idx_offset_);
+ vp9_fix_last_tl0_pic_idx_ = fixed_tl0;
+ }
}
// Update |vp9_fix_last_picture_id_| with the most recent picture id.
diff --git a/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc b/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc
index cc361ec..6ea8e02 100644
--- a/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc
+++ b/webrtc/modules/video_coding/rtp_frame_reference_finder_unittest.cc
@@ -1285,6 +1285,42 @@
// TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be
// around M59).
+TEST_F(TestRtpFrameReferenceFinder, Vp9PidFix_PidJumpsForwardNoTl0PicIdx) {
+ GofInfoVP9 ss;
+ ss.SetGofInfoVP9(kTemporalStructureMode1);
+
+ VCMPacket packet;
+ packet.timestamp = 0;
+ packet.codec = kVideoCodecVP9;
+ packet.frameType = kVideoFrameKey;
+ packet.markerBit = true;
+ packet.video_header.codecHeader.VP9.flexible_mode = false;
+ packet.video_header.codecHeader.VP9.picture_id = 0;
+ packet.video_header.codecHeader.VP9.temporal_idx = kNoTemporalIdx;
+ packet.video_header.codecHeader.VP9.spatial_idx = kNoSpatialIdx;
+ packet.video_header.codecHeader.VP9.tl0_pic_idx = kNoTl0PicIdx;
+ packet.video_header.codecHeader.VP9.temporal_up_switch = true;
+ packet.video_header.codecHeader.VP9.ss_data_available = true;
+ packet.video_header.codecHeader.VP9.gof = ss;
+
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
+
+ packet.timestamp = 1;
+ packet.video_header.codecHeader.VP9.picture_id = 5000;
+
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
+
+ ASSERT_EQ(2UL, frames_from_callback_.size());
+ CheckReferencesVp9(0, 0);
+ CheckReferencesVp9(128, 0);
+}
+
+// TODO(philipel): Remove when VP9 PID/TL0 does not jump mid-stream (should be
+// around M59).
TEST_F(TestRtpFrameReferenceFinder, Vp9PidFix_PidJumpsBackwardThenForward) {
GofInfoVP9 ss;
ss.SetGofInfoVP9(kTemporalStructureMode1);
@@ -1303,33 +1339,24 @@
packet.video_header.codecHeader.VP9.ss_data_available = true;
packet.video_header.codecHeader.VP9.gof = ss;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
// Timestamp goes forward but pid goes backwards.
packet.timestamp = 1;
packet.video_header.codecHeader.VP9.picture_id = 0;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 2;
packet.video_header.codecHeader.VP9.picture_id = 5000;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
ASSERT_EQ(3UL, frames_from_callback_.size());
CheckReferencesVp9(1, 0);
@@ -1356,45 +1383,33 @@
packet.video_header.codecHeader.VP9.temporal_up_switch = true;
packet.video_header.codecHeader.VP9.ss_data_available = true;
packet.video_header.codecHeader.VP9.gof = ss;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 1;
packet.video_header.codecHeader.VP9.picture_id = 1;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 0;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 2;
packet.frameType = kVideoFrameDelta;
packet.video_header.codecHeader.VP9.picture_id = 2;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 2;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 3;
packet.frameType = kVideoFrameKey;
packet.video_header.codecHeader.VP9.ss_data_available = true;
packet.video_header.codecHeader.VP9.picture_id = 3;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 129;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
ASSERT_EQ(4UL, frames_from_callback_.size());
CheckReferencesVp9(0, 0);
@@ -1422,42 +1437,30 @@
packet.video_header.codecHeader.VP9.temporal_up_switch = true;
packet.video_header.codecHeader.VP9.ss_data_available = true;
packet.video_header.codecHeader.VP9.gof = ss;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 1;
packet.video_header.codecHeader.VP9.picture_id = 2;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 2;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 2;
packet.video_header.codecHeader.VP9.picture_id = 3;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 2;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 2;
packet.video_header.codecHeader.VP9.picture_id = 4;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 1;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
ASSERT_EQ(4UL, frames_from_callback_.size());
CheckReferencesVp9(1, 0);
@@ -1485,32 +1488,23 @@
packet.video_header.codecHeader.VP9.temporal_up_switch = true;
packet.video_header.codecHeader.VP9.ss_data_available = true;
packet.video_header.codecHeader.VP9.gof = ss;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 1;
packet.video_header.codecHeader.VP9.picture_id = 0;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 2;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
packet.timestamp = 0;
packet.video_header.codecHeader.VP9.picture_id = 3;
packet.video_header.codecHeader.VP9.tl0_pic_idx = 2;
- {
- ref_packet_buffer_->InsertPacket(&packet);
- std::unique_ptr<RtpFrameObject> frame(
- new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0));
- reference_finder_->ManageFrame(std::move(frame));
- }
+ ref_packet_buffer_->InsertPacket(&packet);
+ reference_finder_->ManageFrame(std::unique_ptr<RtpFrameObject>(
+ new RtpFrameObject(ref_packet_buffer_, 0, 0, 0, 0, 0)));
ASSERT_EQ(2UL, frames_from_callback_.size());
CheckReferencesVp9(1, 0);