Index: media/filters/fake_video_decoder_unittest.cc |
diff --git a/media/filters/fake_video_decoder_unittest.cc b/media/filters/fake_video_decoder_unittest.cc |
index d05a31f980bab78b160393712f09436714098ca6..12188166add9116277dbe540dd4bae7369f9f0ac 100644 |
--- a/media/filters/fake_video_decoder_unittest.cc |
+++ b/media/filters/fake_video_decoder_unittest.cc |
@@ -14,18 +14,27 @@ |
namespace media { |
-static const int kDecodingDelay = 9; |
static const int kTotalBuffers = 12; |
static const int kDurationMs = 30; |
-class FakeVideoDecoderTest : public testing::Test, |
- public testing::WithParamInterface<int> { |
+struct FakeVideoDecoderTestParams { |
+ FakeVideoDecoderTestParams(int decoding_delay, int max_decode_requests) |
+ : decoding_delay(decoding_delay), |
+ max_decode_requests(max_decode_requests) {} |
+ int decoding_delay; |
+ int max_decode_requests; |
+}; |
+ |
+class FakeVideoDecoderTest |
+ : public testing::Test, |
+ public testing::WithParamInterface<FakeVideoDecoderTestParams> { |
public: |
FakeVideoDecoderTest() |
- : decoder_(new FakeVideoDecoder(kDecodingDelay, false, GetParam())), |
+ : decoder_(new FakeVideoDecoder(GetParam().decoding_delay, |
+ GetParam().max_decode_requests)), |
num_input_buffers_(0), |
num_decoded_frames_(0), |
- last_decode_status_(VideoDecoder::kNotEnoughData), |
+ last_decode_status_(VideoDecoder::kOk), |
pending_decode_requests_(0), |
is_reset_pending_(false) {} |
@@ -34,7 +43,9 @@ class FakeVideoDecoderTest : public testing::Test, |
} |
void InitializeWithConfig(const VideoDecoderConfig& config) { |
- decoder_->Initialize(config, false, NewExpectedStatusCB(PIPELINE_OK)); |
+ decoder_->Initialize( |
+ config, false, NewExpectedStatusCB(PIPELINE_OK), |
+ base::Bind(&FakeVideoDecoderTest::FrameReady, base::Unretained(this))); |
message_loop_.RunUntilIdle(); |
current_config_ = config; |
} |
@@ -53,16 +64,16 @@ class FakeVideoDecoderTest : public testing::Test, |
message_loop_.RunUntilIdle(); |
} |
- // Callback for VideoDecoder::Read(). |
- void FrameReady(VideoDecoder::Status status, |
- const scoped_refptr<VideoFrame>& frame) { |
+ // Callback for VideoDecoder::Decode(). |
+ void DecodeDone(VideoDecoder::Status status) { |
DCHECK_GT(pending_decode_requests_, 0); |
- |
--pending_decode_requests_; |
last_decode_status_ = status; |
- last_decoded_frame_ = frame; |
+ } |
- if (frame && !frame->end_of_stream()) |
+ void FrameReady(const scoped_refptr<VideoFrame>& frame) { |
+ last_decoded_frame_ = frame; |
+ if (!frame->end_of_stream()) |
num_decoded_frames_++; |
} |
@@ -87,7 +98,7 @@ class FakeVideoDecoderTest : public testing::Test, |
break; |
case NOT_ENOUGH_DATA: |
EXPECT_EQ(0, pending_decode_requests_); |
- ASSERT_EQ(VideoDecoder::kNotEnoughData, last_decode_status_); |
+ ASSERT_EQ(VideoDecoder::kOk, last_decode_status_); |
ASSERT_FALSE(last_decoded_frame_); |
break; |
case ABORTED: |
@@ -121,15 +132,15 @@ class FakeVideoDecoderTest : public testing::Test, |
decoder_->Decode( |
buffer, |
- base::Bind(&FakeVideoDecoderTest::FrameReady, base::Unretained(this))); |
+ base::Bind(&FakeVideoDecoderTest::DecodeDone, base::Unretained(this))); |
message_loop_.RunUntilIdle(); |
} |
void ReadOneFrame() { |
+ last_decoded_frame_ = NULL; |
do { |
Decode(); |
- } while (last_decode_status_ == VideoDecoder::kNotEnoughData && |
- pending_decode_requests_ == 0); |
+ } while (!last_decoded_frame_ && pending_decode_requests_ == 0); |
} |
void ReadUntilEOS() { |
@@ -146,14 +157,14 @@ class FakeVideoDecoderTest : public testing::Test, |
ExpectReadResult(PENDING); |
} |
- void SatisfyReadAndExpect(CallbackResult result) { |
+ void SatisfyDecodeAndExpect(CallbackResult result) { |
decoder_->SatisfyDecode(); |
message_loop_.RunUntilIdle(); |
ExpectReadResult(result); |
} |
void SatisfyRead() { |
- SatisfyReadAndExpect(OK); |
+ SatisfyDecodeAndExpect(OK); |
} |
// Callback for VideoDecoder::Reset(). |
@@ -223,10 +234,12 @@ class FakeVideoDecoderTest : public testing::Test, |
INSTANTIATE_TEST_CASE_P(NoParallelDecode, |
FakeVideoDecoderTest, |
- ::testing::Values(1)); |
+ ::testing::Values(FakeVideoDecoderTestParams(9, 1), |
+ FakeVideoDecoderTestParams(0, 1))); |
INSTANTIATE_TEST_CASE_P(ParallelDecode, |
FakeVideoDecoderTest, |
- ::testing::Values(3)); |
+ ::testing::Values(FakeVideoDecoderTestParams(9, 3), |
+ FakeVideoDecoderTestParams(0, 3))); |
TEST_P(FakeVideoDecoderTest, Initialize) { |
Initialize(); |
@@ -243,12 +256,13 @@ TEST_P(FakeVideoDecoderTest, Read_DecodingDelay) { |
while (num_input_buffers_ < kTotalBuffers) { |
ReadOneFrame(); |
- EXPECT_EQ(num_input_buffers_, num_decoded_frames_ + kDecodingDelay); |
+ EXPECT_EQ(num_input_buffers_, |
+ num_decoded_frames_ + GetParam().decoding_delay); |
} |
} |
TEST_P(FakeVideoDecoderTest, Read_ZeroDelay) { |
- decoder_.reset(new FakeVideoDecoder(0, false, 1)); |
+ decoder_.reset(new FakeVideoDecoder(0, 1)); |
Initialize(); |
while (num_input_buffers_ < kTotalBuffers) { |
@@ -258,34 +272,40 @@ TEST_P(FakeVideoDecoderTest, Read_ZeroDelay) { |
} |
TEST_P(FakeVideoDecoderTest, Read_Pending_NotEnoughData) { |
+ if (GetParam().decoding_delay < 1) |
+ return; |
+ |
Initialize(); |
decoder_->HoldDecode(); |
ReadOneFrame(); |
ExpectReadResult(PENDING); |
- SatisfyReadAndExpect(NOT_ENOUGH_DATA); |
+ SatisfyDecodeAndExpect(NOT_ENOUGH_DATA); |
+ |
+ // Verify that FrameReady() hasn't been called. |
+ EXPECT_FALSE(last_decoded_frame_); |
} |
TEST_P(FakeVideoDecoderTest, Read_Pending_OK) { |
Initialize(); |
- ReadOneFrame(); |
EnterPendingReadState(); |
- SatisfyReadAndExpect(OK); |
+ SatisfyDecodeAndExpect(OK); |
} |
TEST_P(FakeVideoDecoderTest, Read_Parallel) { |
- int max_decode_requests = GetParam(); |
- if (max_decode_requests < 2) |
+ if (GetParam().max_decode_requests < 2) |
return; |
Initialize(); |
- ReadOneFrame(); |
decoder_->HoldDecode(); |
- for (int i = 0; i < max_decode_requests; ++i) { |
+ for (int i = 0; i < GetParam().max_decode_requests; ++i) { |
ReadOneFrame(); |
ExpectReadResult(PENDING); |
} |
- EXPECT_EQ(max_decode_requests, pending_decode_requests_); |
- SatisfyReadAndExpect(OK); |
+ EXPECT_EQ(GetParam().max_decode_requests, pending_decode_requests_); |
+ SatisfyDecodeAndExpect( |
+ GetParam().max_decode_requests > GetParam().decoding_delay |
+ ? OK |
+ : NOT_ENOUGH_DATA); |
} |
TEST_P(FakeVideoDecoderTest, ReadWithHold_DecodingDelay) { |
@@ -303,7 +323,7 @@ TEST_P(FakeVideoDecoderTest, ReadWithHold_DecodingDelay) { |
} |
DCHECK_EQ(num_decoded_frames_, 1); |
- DCHECK_EQ(num_decodes_satisfied, kDecodingDelay + 1); |
+ DCHECK_EQ(num_decodes_satisfied, GetParam().decoding_delay + 1); |
} |
TEST_P(FakeVideoDecoderTest, Reinitialize) { |
@@ -316,6 +336,9 @@ TEST_P(FakeVideoDecoderTest, Reinitialize) { |
// Reinitializing the decoder during the middle of the decoding process can |
// cause dropped frames. |
TEST_P(FakeVideoDecoderTest, Reinitialize_FrameDropped) { |
+ if (GetParam().decoding_delay < 1) |
+ return; |
+ |
Initialize(); |
ReadOneFrame(); |
Initialize(); |
@@ -333,7 +356,7 @@ TEST_P(FakeVideoDecoderTest, Reset_DuringPendingRead) { |
Initialize(); |
EnterPendingReadState(); |
ResetAndExpect(PENDING); |
- SatisfyReadAndExpect(ABORTED); |
+ SatisfyDecodeAndExpect(ABORTED); |
} |
TEST_P(FakeVideoDecoderTest, Reset_Pending) { |
@@ -346,7 +369,7 @@ TEST_P(FakeVideoDecoderTest, Reset_PendingDuringPendingRead) { |
Initialize(); |
EnterPendingReadState(); |
EnterPendingResetState(); |
- SatisfyReadAndExpect(ABORTED); |
+ SatisfyDecodeAndExpect(ABORTED); |
SatisfyReset(); |
} |
@@ -381,16 +404,4 @@ TEST_P(FakeVideoDecoderTest, Stop_DuringPendingReadAndPendingReset) { |
Stop(); |
} |
-TEST_P(FakeVideoDecoderTest, GetDecodeOutput) { |
- decoder_.reset(new FakeVideoDecoder(kDecodingDelay, true, 1)); |
- Initialize(); |
- |
- while (num_input_buffers_ < kTotalBuffers) { |
- ReadOneFrame(); |
- while (decoder_->GetDecodeOutput()) |
- ++num_decoded_frames_; |
- EXPECT_EQ(num_input_buffers_, num_decoded_frames_); |
- } |
-} |
- |
} // namespace media |