Remove use of inter_layer_predicted in FrameBuffer2.

Now that RtpVp9RefFinder sets an additional reference on the frame instead of marking it as inter_layer_predicted it is no longer used.

Bug: webrtc:12206
Change-Id: I10e0930336eafc32dc86feb2f690cb131e55be2c
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/196740
Commit-Queue: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32814}
This commit is contained in:
philipel
2020-12-10 10:49:20 +01:00
committed by Commit Bot
parent b95d90b78a
commit cb327d9162
3 changed files with 97 additions and 132 deletions

View File

@ -79,6 +79,7 @@ class EncodedFrame : public webrtc::VCMEncodedFrame {
// many |references|. // many |references|.
size_t num_references = 0; size_t num_references = 0;
int64_t references[kMaxFrameReferences]; int64_t references[kMaxFrameReferences];
// TODO(bugs.webrtc.org/12206) Remove after downstream has been updated.
bool inter_layer_predicted = false; bool inter_layer_predicted = false;
// Is this subframe the last one in the superframe (In RTP stream that would // Is this subframe the last one in the superframe (In RTP stream that would
// mean that the last packet has a marker bit set). // mean that the last packet has a marker bit set).

View File

@ -171,23 +171,19 @@ int64_t FrameBuffer::FindNextFrame(int64_t now_ms) {
} }
if (next_frame_it->second.num_missing_decodable > 0) { if (next_frame_it->second.num_missing_decodable > 0) {
// For now VP9 uses the inter_layer_predicted to signal a dependency bool has_inter_layer_dependency = false;
// instead of adding it as a reference. for (size_t i = 0; i < EncodedFrame::kMaxFrameReferences &&
// TODO(webrtc:12206): Stop using inter_layer_predicted for VP9.
bool has_inter_layer_dependency =
next_frame_it->second.frame->inter_layer_predicted;
for (size_t i = 0; !has_inter_layer_dependency &&
i < EncodedFrame::kMaxFrameReferences &&
i < next_frame_it->second.frame->num_references; i < next_frame_it->second.frame->num_references;
++i) { ++i) {
if (next_frame_it->second.frame->references[i] >= if (next_frame_it->second.frame->references[i] >=
frame_it->first.picture_id) { frame_it->first.picture_id) {
has_inter_layer_dependency = true; has_inter_layer_dependency = true;
break;
} }
} }
// If the frame has an undecoded dependency that is not within the same // If the frame has an undecoded dependency that is not within the same
// temporal unit then this frame is not ready to be decoded yet. If it // temporal unit then this frame is not yet ready to be decoded. If it
// is within the same temporal unit then the not yet decoded dependency // is within the same temporal unit then the not yet decoded dependency
// is just a lower spatial frame, which is ok. // is just a lower spatial frame, which is ok.
if (!has_inter_layer_dependency || if (!has_inter_layer_dependency ||
@ -380,9 +376,6 @@ bool FrameBuffer::ValidReferences(const EncodedFrame& frame) const {
} }
} }
if (frame.inter_layer_predicted && frame.id.spatial_layer == 0)
return false;
return true; return true;
} }
@ -607,23 +600,6 @@ bool FrameBuffer::UpdateFrameInfoWithIncomingFrame(const EncodedFrame& frame,
} }
} }
// Does |frame| depend on the lower spatial layer?
if (frame.inter_layer_predicted) {
VideoLayerFrameId ref_key(frame.id.picture_id, frame.id.spatial_layer - 1);
auto ref_info = frames_.find(ref_key);
bool lower_layer_decoded =
last_decoded_frame && *last_decoded_frame == ref_key;
bool lower_layer_continuous =
lower_layer_decoded ||
(ref_info != frames_.end() && ref_info->second.continuous);
if (!lower_layer_continuous || !lower_layer_decoded) {
not_yet_fulfilled_dependencies.push_back(
{ref_key, lower_layer_continuous});
}
}
info->second.num_missing_continuous = not_yet_fulfilled_dependencies.size(); info->second.num_missing_continuous = not_yet_fulfilled_dependencies.size();
info->second.num_missing_decodable = not_yet_fulfilled_dependencies.size(); info->second.num_missing_decodable = not_yet_fulfilled_dependencies.size();

View File

@ -155,7 +155,6 @@ class TestFrameBuffer2 : public ::testing::Test {
std::unique_ptr<FrameObjectFake> CreateFrame(uint16_t picture_id, std::unique_ptr<FrameObjectFake> CreateFrame(uint16_t picture_id,
uint8_t spatial_layer, uint8_t spatial_layer,
int64_t ts_ms, int64_t ts_ms,
bool inter_layer_predicted,
bool last_spatial_layer, bool last_spatial_layer,
size_t frame_size_bytes, size_t frame_size_bytes,
T... refs) { T... refs) {
@ -166,11 +165,9 @@ class TestFrameBuffer2 : public ::testing::Test {
auto frame = std::make_unique<FrameObjectFake>(); auto frame = std::make_unique<FrameObjectFake>();
frame->id.picture_id = picture_id; frame->id.picture_id = picture_id;
frame->id.spatial_layer = spatial_layer;
frame->SetSpatialIndex(spatial_layer); frame->SetSpatialIndex(spatial_layer);
frame->SetTimestamp(ts_ms * 90); frame->SetTimestamp(ts_ms * 90);
frame->num_references = references.size(); frame->num_references = references.size();
frame->inter_layer_predicted = inter_layer_predicted;
frame->is_last_spatial_layer = last_spatial_layer; frame->is_last_spatial_layer = last_spatial_layer;
// Add some data to buffer. // Add some data to buffer.
frame->SetEncodedData(EncodedImageBuffer::Create(frame_size_bytes)); frame->SetEncodedData(EncodedImageBuffer::Create(frame_size_bytes));
@ -183,18 +180,17 @@ class TestFrameBuffer2 : public ::testing::Test {
int InsertFrame(uint16_t picture_id, int InsertFrame(uint16_t picture_id,
uint8_t spatial_layer, uint8_t spatial_layer,
int64_t ts_ms, int64_t ts_ms,
bool inter_layer_predicted,
bool last_spatial_layer, bool last_spatial_layer,
size_t frame_size_bytes, size_t frame_size_bytes,
T... refs) { T... refs) {
return buffer_->InsertFrame( return buffer_->InsertFrame(CreateFrame(picture_id, spatial_layer, ts_ms,
CreateFrame(picture_id, spatial_layer, ts_ms, inter_layer_predicted, last_spatial_layer,
last_spatial_layer, frame_size_bytes, refs...)); frame_size_bytes, refs...));
} }
int InsertNackedFrame(uint16_t picture_id, int64_t ts_ms) { int InsertNackedFrame(uint16_t picture_id, int64_t ts_ms) {
std::unique_ptr<FrameObjectFake> frame = std::unique_ptr<FrameObjectFake> frame =
CreateFrame(picture_id, 0, ts_ms, false, true, kFrameSize); CreateFrame(picture_id, 0, ts_ms, true, kFrameSize);
frame->set_delayed_by_retransmission(true); frame->set_delayed_by_retransmission(true);
return buffer_->InsertFrame(std::move(frame)); return buffer_->InsertFrame(std::move(frame));
} }
@ -219,7 +215,7 @@ class TestFrameBuffer2 : public ::testing::Test {
ASSERT_LT(index, frames_.size()); ASSERT_LT(index, frames_.size());
ASSERT_TRUE(frames_[index]); ASSERT_TRUE(frames_[index]);
ASSERT_EQ(picture_id, frames_[index]->id.picture_id); ASSERT_EQ(picture_id, frames_[index]->id.picture_id);
ASSERT_EQ(spatial_layer, frames_[index]->id.spatial_layer); ASSERT_EQ(spatial_layer, frames_[index]->SpatialIndex().value_or(0));
} }
void CheckFrameSize(size_t index, size_t size) { void CheckFrameSize(size_t index, size_t size) {
@ -260,7 +256,7 @@ TEST_F(TestFrameBuffer2, WaitForFrame) {
uint32_t ts = Rand(); uint32_t ts = Rand();
ExtractFrame(50); ExtractFrame(50);
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
time_controller_.AdvanceTime(TimeDelta::Millis(50)); time_controller_.AdvanceTime(TimeDelta::Millis(50));
CheckFrame(0, pid, 0); CheckFrame(0, pid, 0);
} }
@ -269,8 +265,8 @@ TEST_F(TestFrameBuffer2, OneSuperFrame) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, false, kFrameSize); InsertFrame(pid, 0, ts, false, kFrameSize);
InsertFrame(pid, 1, ts, true, true, kFrameSize); InsertFrame(pid + 1, 1, ts, true, kFrameSize);
ExtractFrame(); ExtractFrame();
CheckFrame(0, pid, 1); CheckFrame(0, pid, 1);
@ -296,8 +292,8 @@ TEST_F(TestFrameBuffer2, DISABLED_OneUnorderedSuperFrame) {
uint32_t ts = Rand(); uint32_t ts = Rand();
ExtractFrame(50); ExtractFrame(50);
InsertFrame(pid, 1, ts, true, true, kFrameSize); InsertFrame(pid, 1, ts, true, kFrameSize);
InsertFrame(pid, 0, ts, false, false, kFrameSize); InsertFrame(pid, 0, ts, false, kFrameSize);
time_controller_.AdvanceTime(TimeDelta::Millis(0)); time_controller_.AdvanceTime(TimeDelta::Millis(0));
CheckFrame(0, pid, 0); CheckFrame(0, pid, 0);
@ -313,11 +309,10 @@ TEST_F(TestFrameBuffer2, DISABLED_OneLayerStreamReordered) {
CheckFrame(0, pid, 0); CheckFrame(0, pid, 0);
for (int i = 1; i < 10; i += 2) { for (int i = 1; i < 10; i += 2) {
ExtractFrame(50); ExtractFrame(50);
InsertFrame(pid + i + 1, 0, ts + (i + 1) * kFps10, false, true, kFrameSize, InsertFrame(pid + i + 1, 0, ts + (i + 1) * kFps10, true, kFrameSize,
pid + i); pid + i);
time_controller_.AdvanceTime(TimeDelta::Millis(kFps10)); time_controller_.AdvanceTime(TimeDelta::Millis(kFps10));
InsertFrame(pid + i, 0, ts + i * kFps10, false, true, kFrameSize, InsertFrame(pid + i, 0, ts + i * kFps10, true, kFrameSize, pid + i - 1);
pid + i - 1);
time_controller_.AdvanceTime(TimeDelta::Millis(kFps10)); time_controller_.AdvanceTime(TimeDelta::Millis(kFps10));
ExtractFrame(); ExtractFrame();
CheckFrame(i, pid + i, 0); CheckFrame(i, pid + i, 0);
@ -334,9 +329,9 @@ TEST_F(TestFrameBuffer2, MissingFrame) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
InsertFrame(pid + 2, 0, ts, false, true, kFrameSize, pid); InsertFrame(pid + 2, 0, ts, true, kFrameSize, pid);
InsertFrame(pid + 3, 0, ts, false, true, kFrameSize, pid + 1, pid + 2); InsertFrame(pid + 3, 0, ts, true, kFrameSize, pid + 1, pid + 2);
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
@ -350,12 +345,11 @@ TEST_F(TestFrameBuffer2, OneLayerStream) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
ExtractFrame(); ExtractFrame();
CheckFrame(0, pid, 0); CheckFrame(0, pid, 0);
for (int i = 1; i < 10; ++i) { for (int i = 1; i < 10; ++i) {
InsertFrame(pid + i, 0, ts + i * kFps10, false, true, kFrameSize, InsertFrame(pid + i, 0, ts + i * kFps10, true, kFrameSize, pid + i - 1);
pid + i - 1);
ExtractFrame(); ExtractFrame();
time_controller_.AdvanceTime(TimeDelta::Millis(kFps10)); time_controller_.AdvanceTime(TimeDelta::Millis(kFps10));
CheckFrame(i, pid + i, 0); CheckFrame(i, pid + i, 0);
@ -366,13 +360,13 @@ TEST_F(TestFrameBuffer2, DropTemporalLayerSlowDecoder) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
InsertFrame(pid + 1, 0, ts + kFps20, false, true, kFrameSize, pid); InsertFrame(pid + 1, 0, ts + kFps20, true, kFrameSize, pid);
for (int i = 2; i < 10; i += 2) { for (int i = 2; i < 10; i += 2) {
uint32_t ts_tl0 = ts + i / 2 * kFps10; uint32_t ts_tl0 = ts + i / 2 * kFps10;
InsertFrame(pid + i, 0, ts_tl0, false, true, kFrameSize, pid + i - 2); InsertFrame(pid + i, 0, ts_tl0, true, kFrameSize, pid + i - 2);
InsertFrame(pid + i + 1, 0, ts_tl0 + kFps20, false, true, kFrameSize, InsertFrame(pid + i + 1, 0, ts_tl0 + kFps20, true, kFrameSize, pid + i,
pid + i, pid + i - 1); pid + i - 1);
} }
EXPECT_CALL(stats_callback_, OnDroppedFrames(1)).Times(3); EXPECT_CALL(stats_callback_, OnDroppedFrames(1)).Times(3);
@ -398,10 +392,10 @@ TEST_F(TestFrameBuffer2, DropFramesIfSystemIsStalled) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
InsertFrame(pid + 1, 0, ts + 1 * kFps10, false, true, kFrameSize, pid); InsertFrame(pid + 1, 0, ts + 1 * kFps10, true, kFrameSize, pid);
InsertFrame(pid + 2, 0, ts + 2 * kFps10, false, true, kFrameSize, pid + 1); InsertFrame(pid + 2, 0, ts + 2 * kFps10, true, kFrameSize, pid + 1);
InsertFrame(pid + 3, 0, ts + 3 * kFps10, false, true, kFrameSize); InsertFrame(pid + 3, 0, ts + 3 * kFps10, true, kFrameSize);
ExtractFrame(); ExtractFrame();
// Jump forward in time, simulating the system being stalled for some reason. // Jump forward in time, simulating the system being stalled for some reason.
@ -418,10 +412,9 @@ TEST_F(TestFrameBuffer2, DroppedFramesCountedOnClear) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
for (int i = 1; i < 5; ++i) { for (int i = 1; i < 5; ++i) {
InsertFrame(pid + i, 0, ts + i * kFps10, false, true, kFrameSize, InsertFrame(pid + i, 0, ts + i * kFps10, true, kFrameSize, pid + i - 1);
pid + i - 1);
} }
// All frames should be dropped when Clear is called. // All frames should be dropped when Clear is called.
@ -433,11 +426,11 @@ TEST_F(TestFrameBuffer2, InsertLateFrame) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, true, kFrameSize); InsertFrame(pid, 0, ts, true, kFrameSize);
ExtractFrame(); ExtractFrame();
InsertFrame(pid + 2, 0, ts, false, true, kFrameSize); InsertFrame(pid + 2, 0, ts, true, kFrameSize);
ExtractFrame(); ExtractFrame();
InsertFrame(pid + 1, 0, ts, false, true, kFrameSize, pid); InsertFrame(pid + 1, 0, ts, true, kFrameSize, pid);
ExtractFrame(); ExtractFrame();
CheckFrame(0, pid, 0); CheckFrame(0, pid, 0);
@ -456,7 +449,7 @@ TEST_F(TestFrameBuffer2, ProtectionModeNackFEC) {
InsertNackedFrame(pid, ts); InsertNackedFrame(pid, ts);
InsertNackedFrame(pid + 1, ts + 100); InsertNackedFrame(pid + 1, ts + 100);
InsertNackedFrame(pid + 2, ts + 200); InsertNackedFrame(pid + 2, ts + 200);
InsertFrame(pid + 3, 0, ts + 300, false, true, kFrameSize); InsertFrame(pid + 3, 0, ts + 300, true, kFrameSize);
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
@ -477,7 +470,7 @@ TEST_F(TestFrameBuffer2, ProtectionModeNack) {
InsertNackedFrame(pid, ts); InsertNackedFrame(pid, ts);
InsertNackedFrame(pid + 1, ts + 100); InsertNackedFrame(pid + 1, ts + 100);
InsertNackedFrame(pid + 2, ts + 200); InsertNackedFrame(pid + 2, ts + 200);
InsertFrame(pid + 3, 0, ts + 300, false, true, kFrameSize); InsertFrame(pid + 3, 0, ts + 300, true, kFrameSize);
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
@ -491,51 +484,48 @@ TEST_F(TestFrameBuffer2, NoContinuousFrame) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
EXPECT_EQ(-1, InsertFrame(pid + 1, 0, ts, false, true, kFrameSize, pid)); EXPECT_EQ(-1, InsertFrame(pid + 1, 0, ts, true, kFrameSize, pid));
} }
TEST_F(TestFrameBuffer2, LastContinuousFrameSingleLayer) { TEST_F(TestFrameBuffer2, LastContinuousFrameSingleLayer) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false, true, kFrameSize)); EXPECT_EQ(pid, InsertFrame(pid, 0, ts, true, kFrameSize));
EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, false, true, kFrameSize, pid + 1)); EXPECT_EQ(pid, InsertFrame(pid + 2, 0, ts, true, kFrameSize, pid + 1));
EXPECT_EQ(pid + 2, InsertFrame(pid + 1, 0, ts, false, true, kFrameSize, pid)); EXPECT_EQ(pid + 2, InsertFrame(pid + 1, 0, ts, true, kFrameSize, pid));
EXPECT_EQ(pid + 2, EXPECT_EQ(pid + 2, InsertFrame(pid + 4, 0, ts, true, kFrameSize, pid + 3));
InsertFrame(pid + 4, 0, ts, false, true, kFrameSize, pid + 3)); EXPECT_EQ(pid + 5, InsertFrame(pid + 5, 0, ts, true, kFrameSize));
EXPECT_EQ(pid + 5, InsertFrame(pid + 5, 0, ts, false, true, kFrameSize));
} }
TEST_F(TestFrameBuffer2, LastContinuousFrameTwoLayers) { TEST_F(TestFrameBuffer2, LastContinuousFrameTwoLayers) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false, false, kFrameSize)); EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false, kFrameSize));
EXPECT_EQ(pid, InsertFrame(pid, 1, ts, true, true, kFrameSize)); EXPECT_EQ(pid + 1, InsertFrame(pid + 1, 1, ts, true, kFrameSize));
EXPECT_EQ(pid, InsertFrame(pid + 1, 1, ts, true, true, kFrameSize, pid)); EXPECT_EQ(pid + 1,
EXPECT_EQ(pid, InsertFrame(pid + 3, 1, ts, true, kFrameSize, pid + 1, pid + 2));
InsertFrame(pid + 2, 0, ts, false, false, kFrameSize, pid + 1)); EXPECT_EQ(pid + 1, InsertFrame(pid + 4, 0, ts, false, kFrameSize, pid + 2));
EXPECT_EQ(pid, InsertFrame(pid + 2, 1, ts, true, true, kFrameSize, pid + 1)); EXPECT_EQ(pid + 1,
EXPECT_EQ(pid, InsertFrame(pid + 5, 1, ts, true, kFrameSize, pid + 3, pid + 4));
InsertFrame(pid + 3, 0, ts, false, false, kFrameSize, pid + 2)); EXPECT_EQ(pid + 1, InsertFrame(pid + 6, 0, ts, false, kFrameSize, pid + 4));
EXPECT_EQ(pid + 3, EXPECT_EQ(pid + 6, InsertFrame(pid + 2, 0, ts, false, kFrameSize, pid));
InsertFrame(pid + 1, 0, ts, false, false, kFrameSize, pid)); EXPECT_EQ(pid + 7,
EXPECT_EQ(pid + 3, InsertFrame(pid + 7, 1, ts, true, kFrameSize, pid + 5, pid + 6));
InsertFrame(pid + 3, 1, ts, true, true, kFrameSize, pid + 2));
} }
TEST_F(TestFrameBuffer2, PictureIdJumpBack) { TEST_F(TestFrameBuffer2, PictureIdJumpBack) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
EXPECT_EQ(pid, InsertFrame(pid, 0, ts, false, true, kFrameSize)); EXPECT_EQ(pid, InsertFrame(pid, 0, ts, true, kFrameSize));
EXPECT_EQ(pid + 1, EXPECT_EQ(pid + 1, InsertFrame(pid + 1, 0, ts + 1, true, kFrameSize, pid));
InsertFrame(pid + 1, 0, ts + 1, false, true, kFrameSize, pid));
ExtractFrame(); ExtractFrame();
CheckFrame(0, pid, 0); CheckFrame(0, pid, 0);
// Jump back in pid but increase ts. // Jump back in pid but increase ts.
EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, false, true, kFrameSize)); EXPECT_EQ(pid - 1, InsertFrame(pid - 1, 0, ts + 2, true, kFrameSize));
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
CheckFrame(1, pid - 1, 0); CheckFrame(1, pid - 1, 0);
@ -555,10 +545,8 @@ TEST_F(TestFrameBuffer2, StatsCallback) {
std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake()); std::unique_ptr<FrameObjectFake> frame(new FrameObjectFake());
frame->SetEncodedData(EncodedImageBuffer::Create(kFrameSize)); frame->SetEncodedData(EncodedImageBuffer::Create(kFrameSize));
frame->id.picture_id = pid; frame->id.picture_id = pid;
frame->id.spatial_layer = 0;
frame->SetTimestamp(ts); frame->SetTimestamp(ts);
frame->num_references = 0; frame->num_references = 0;
frame->inter_layer_predicted = false;
EXPECT_EQ(buffer_->InsertFrame(std::move(frame)), pid); EXPECT_EQ(buffer_->InsertFrame(std::move(frame)), pid);
} }
@ -568,42 +556,42 @@ TEST_F(TestFrameBuffer2, StatsCallback) {
} }
TEST_F(TestFrameBuffer2, ForwardJumps) { TEST_F(TestFrameBuffer2, ForwardJumps) {
EXPECT_EQ(5453, InsertFrame(5453, 0, 1, false, true, kFrameSize)); EXPECT_EQ(5453, InsertFrame(5453, 0, 1, true, kFrameSize));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(5454, InsertFrame(5454, 0, 1, false, true, kFrameSize, 5453)); EXPECT_EQ(5454, InsertFrame(5454, 0, 1, true, kFrameSize, 5453));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(15670, InsertFrame(15670, 0, 1, false, true, kFrameSize)); EXPECT_EQ(15670, InsertFrame(15670, 0, 1, true, kFrameSize));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(29804, InsertFrame(29804, 0, 1, false, true, kFrameSize)); EXPECT_EQ(29804, InsertFrame(29804, 0, 1, true, kFrameSize));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(29805, InsertFrame(29805, 0, 1, false, true, kFrameSize, 29804)); EXPECT_EQ(29805, InsertFrame(29805, 0, 1, true, kFrameSize, 29804));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(29806, InsertFrame(29806, 0, 1, false, true, kFrameSize, 29805)); EXPECT_EQ(29806, InsertFrame(29806, 0, 1, true, kFrameSize, 29805));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(33819, InsertFrame(33819, 0, 1, false, true, kFrameSize)); EXPECT_EQ(33819, InsertFrame(33819, 0, 1, true, kFrameSize));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(41248, InsertFrame(41248, 0, 1, false, true, kFrameSize)); EXPECT_EQ(41248, InsertFrame(41248, 0, 1, true, kFrameSize));
ExtractFrame(); ExtractFrame();
} }
TEST_F(TestFrameBuffer2, DuplicateFrames) { TEST_F(TestFrameBuffer2, DuplicateFrames) {
EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false, true, kFrameSize)); EXPECT_EQ(22256, InsertFrame(22256, 0, 1, true, kFrameSize));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(22256, InsertFrame(22256, 0, 1, false, true, kFrameSize)); EXPECT_EQ(22256, InsertFrame(22256, 0, 1, true, kFrameSize));
} }
// TODO(philipel): implement more unittests related to invalid references. // TODO(philipel): implement more unittests related to invalid references.
TEST_F(TestFrameBuffer2, InvalidReferences) { TEST_F(TestFrameBuffer2, InvalidReferences) {
EXPECT_EQ(-1, InsertFrame(0, 0, 1000, false, true, kFrameSize, 2)); EXPECT_EQ(-1, InsertFrame(0, 0, 1000, true, kFrameSize, 2));
EXPECT_EQ(1, InsertFrame(1, 0, 2000, false, true, kFrameSize)); EXPECT_EQ(1, InsertFrame(1, 0, 2000, true, kFrameSize));
ExtractFrame(); ExtractFrame();
EXPECT_EQ(2, InsertFrame(2, 0, 3000, false, true, kFrameSize, 1)); EXPECT_EQ(2, InsertFrame(2, 0, 3000, true, kFrameSize, 1));
} }
TEST_F(TestFrameBuffer2, KeyframeRequired) { TEST_F(TestFrameBuffer2, KeyframeRequired) {
EXPECT_EQ(1, InsertFrame(1, 0, 1000, false, true, kFrameSize)); EXPECT_EQ(1, InsertFrame(1, 0, 1000, true, kFrameSize));
EXPECT_EQ(2, InsertFrame(2, 0, 2000, false, true, kFrameSize, 1)); EXPECT_EQ(2, InsertFrame(2, 0, 2000, true, kFrameSize, 1));
EXPECT_EQ(3, InsertFrame(3, 0, 3000, false, true, kFrameSize)); EXPECT_EQ(3, InsertFrame(3, 0, 3000, true, kFrameSize));
ExtractFrame(); ExtractFrame();
ExtractFrame(0, true); ExtractFrame(0, true);
ExtractFrame(); ExtractFrame();
@ -617,38 +605,38 @@ TEST_F(TestFrameBuffer2, KeyframeClearsFullBuffer) {
const int kMaxBufferSize = 600; const int kMaxBufferSize = 600;
for (int i = 1; i <= kMaxBufferSize; ++i) for (int i = 1; i <= kMaxBufferSize; ++i)
EXPECT_EQ(-1, InsertFrame(i, 0, i * 1000, false, true, kFrameSize, i - 1)); EXPECT_EQ(-1, InsertFrame(i, 0, i * 1000, true, kFrameSize, i - 1));
ExtractFrame(); ExtractFrame();
CheckNoFrame(0); CheckNoFrame(0);
EXPECT_EQ(kMaxBufferSize + 1, EXPECT_EQ(kMaxBufferSize + 1,
InsertFrame(kMaxBufferSize + 1, 0, (kMaxBufferSize + 1) * 1000, InsertFrame(kMaxBufferSize + 1, 0, (kMaxBufferSize + 1) * 1000,
false, true, kFrameSize)); true, kFrameSize));
ExtractFrame(); ExtractFrame();
CheckFrame(1, kMaxBufferSize + 1, 0); CheckFrame(1, kMaxBufferSize + 1, 0);
} }
TEST_F(TestFrameBuffer2, DontUpdateOnUndecodableFrame) { TEST_F(TestFrameBuffer2, DontUpdateOnUndecodableFrame) {
InsertFrame(1, 0, 0, false, true, kFrameSize); InsertFrame(1, 0, 0, true, kFrameSize);
ExtractFrame(0, true); ExtractFrame(0, true);
InsertFrame(3, 0, 0, false, true, kFrameSize, 2, 0); InsertFrame(3, 0, 0, true, kFrameSize, 2, 0);
InsertFrame(3, 0, 0, false, true, kFrameSize, 0); InsertFrame(3, 0, 0, true, kFrameSize, 0);
InsertFrame(2, 0, 0, false, true, kFrameSize); InsertFrame(2, 0, 0, true, kFrameSize);
ExtractFrame(0, true); ExtractFrame(0, true);
ExtractFrame(0, true); ExtractFrame(0, true);
} }
TEST_F(TestFrameBuffer2, DontDecodeOlderTimestamp) { TEST_F(TestFrameBuffer2, DontDecodeOlderTimestamp) {
InsertFrame(2, 0, 1, false, true, kFrameSize); InsertFrame(2, 0, 1, true, kFrameSize);
InsertFrame(1, 0, 2, false, true, InsertFrame(1, 0, 2, true,
kFrameSize); // Older picture id but newer timestamp. kFrameSize); // Older picture id but newer timestamp.
ExtractFrame(0); ExtractFrame(0);
ExtractFrame(0); ExtractFrame(0);
CheckFrame(0, 1, 0); CheckFrame(0, 1, 0);
CheckNoFrame(1); CheckNoFrame(1);
InsertFrame(3, 0, 4, false, true, kFrameSize); InsertFrame(3, 0, 4, true, kFrameSize);
InsertFrame(4, 0, 3, false, true, InsertFrame(4, 0, 3, true,
kFrameSize); // Newer picture id but older timestamp. kFrameSize); // Newer picture id but older timestamp.
ExtractFrame(0); ExtractFrame(0);
ExtractFrame(0); ExtractFrame(0);
@ -660,8 +648,8 @@ TEST_F(TestFrameBuffer2, CombineFramesToSuperframe) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, false, kFrameSize); InsertFrame(pid, 0, ts, false, kFrameSize);
InsertFrame(pid, 1, ts, true, true, 2 * kFrameSize); InsertFrame(pid + 1, 1, ts, true, 2 * kFrameSize, pid);
ExtractFrame(0); ExtractFrame(0);
ExtractFrame(0); ExtractFrame(0);
CheckFrame(0, pid, 1); CheckFrame(0, pid, 1);
@ -678,25 +666,25 @@ TEST_F(TestFrameBuffer2, HigherSpatialLayerNonDecodable) {
uint16_t pid = Rand(); uint16_t pid = Rand();
uint32_t ts = Rand(); uint32_t ts = Rand();
InsertFrame(pid, 0, ts, false, false, kFrameSize); InsertFrame(pid, 0, ts, false, kFrameSize);
InsertFrame(pid, 1, ts, true, true, kFrameSize); InsertFrame(pid + 1, 1, ts, true, kFrameSize, pid);
ExtractFrame(0); ExtractFrame(0);
CheckFrame(0, pid, 1); CheckFrame(0, pid, 1);
InsertFrame(pid + 1, 1, ts + kFps20, false, true, kFrameSize, pid); InsertFrame(pid + 3, 1, ts + kFps20, true, kFrameSize, pid);
InsertFrame(pid + 2, 0, ts + kFps10, false, false, kFrameSize, pid); InsertFrame(pid + 4, 0, ts + kFps10, false, kFrameSize, pid);
InsertFrame(pid + 2, 1, ts + kFps10, true, true, kFrameSize, pid + 1); InsertFrame(pid + 5, 1, ts + kFps10, true, kFrameSize, pid + 3, pid + 4);
time_controller_.AdvanceTime(TimeDelta::Millis(1000)); time_controller_.AdvanceTime(TimeDelta::Millis(1000));
// Frame pid+1 is decodable but too late. // Frame pid+3 is decodable but too late.
// In superframe pid+2 frame sid=0 is decodable, but frame sid=1 is not. // In superframe pid+4 is decodable, but frame pid+5 is not.
// Incorrect implementation might skip pid+1 frame and output undecodable // Incorrect implementation might skip pid+2 frame and output undecodable
// pid+2 instead. // pid+5 instead.
ExtractFrame(); ExtractFrame();
ExtractFrame(); ExtractFrame();
CheckFrame(1, pid + 1, 1); CheckFrame(1, pid + 3, 1);
CheckFrame(2, pid + 2, 1); CheckFrame(2, pid + 4, 1);
} }
} // namespace video_coding } // namespace video_coding