OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "media/base/decoder_buffer.h" | 8 #include "media/base/decoder_buffer.h" |
9 #include "media/base/mock_filters.h" | 9 #include "media/base/mock_filters.h" |
10 #include "media/base/test_helpers.h" | 10 #include "media/base/test_helpers.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 #include "media/filters/fake_video_decoder.h" | 12 #include "media/filters/fake_video_decoder.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 static const int kDecodingDelay = 9; | 17 static const int kDecodingDelay = 9; |
18 static const int kTotalBuffers = 12; | 18 static const int kTotalBuffers = 12; |
19 static const int kDurationMs = 30; | 19 static const int kDurationMs = 30; |
20 | 20 |
21 class FakeVideoDecoderTest : public testing::Test, | 21 class FakeVideoDecoderTest : public testing::Test, |
22 public testing::WithParamInterface<int> { | 22 public testing::WithParamInterface<int> { |
23 public: | 23 public: |
24 FakeVideoDecoderTest() | 24 FakeVideoDecoderTest() |
25 : decoder_(new FakeVideoDecoder(kDecodingDelay, false, GetParam())), | 25 : decoder_(new FakeVideoDecoder(kDecodingDelay, GetParam())), |
26 num_input_buffers_(0), | 26 num_input_buffers_(0), |
27 num_decoded_frames_(0), | 27 num_decoded_frames_(0), |
28 last_decode_status_(VideoDecoder::kNotEnoughData), | 28 last_decode_status_(VideoDecoder::kOk), |
29 pending_decode_requests_(0), | 29 pending_decode_requests_(0), |
30 is_reset_pending_(false) {} | 30 is_reset_pending_(false) {} |
31 | 31 |
32 virtual ~FakeVideoDecoderTest() { | 32 virtual ~FakeVideoDecoderTest() { |
33 Stop(); | 33 Stop(); |
34 } | 34 } |
35 | 35 |
36 void InitializeWithConfig(const VideoDecoderConfig& config) { | 36 void InitializeWithConfig(const VideoDecoderConfig& config) { |
37 decoder_->Initialize(config, false, NewExpectedStatusCB(PIPELINE_OK)); | 37 decoder_->Initialize( |
38 config, false, NewExpectedStatusCB(PIPELINE_OK), | |
39 base::Bind(&FakeVideoDecoderTest::FrameReady, base::Unretained(this))); | |
38 message_loop_.RunUntilIdle(); | 40 message_loop_.RunUntilIdle(); |
39 current_config_ = config; | 41 current_config_ = config; |
40 } | 42 } |
41 | 43 |
42 void Initialize() { | 44 void Initialize() { |
43 InitializeWithConfig(TestVideoConfig::Normal()); | 45 InitializeWithConfig(TestVideoConfig::Normal()); |
44 } | 46 } |
45 | 47 |
46 void EnterPendingInitState() { | 48 void EnterPendingInitState() { |
47 decoder_->HoldNextInit(); | 49 decoder_->HoldNextInit(); |
48 Initialize(); | 50 Initialize(); |
49 } | 51 } |
50 | 52 |
51 void SatisfyInit() { | 53 void SatisfyInit() { |
52 decoder_->SatisfyInit(); | 54 decoder_->SatisfyInit(); |
53 message_loop_.RunUntilIdle(); | 55 message_loop_.RunUntilIdle(); |
54 } | 56 } |
55 | 57 |
56 // Callback for VideoDecoder::Read(). | 58 // Callback for VideoDecoder::Decode(). |
57 void FrameReady(VideoDecoder::Status status, | 59 void DecodeDone(VideoDecoder::Status status) { |
58 const scoped_refptr<VideoFrame>& frame) { | 60 LOG(ERROR) << "DONE"; |
59 DCHECK_GT(pending_decode_requests_, 0); | 61 DCHECK_GT(pending_decode_requests_, 0); |
60 | |
61 --pending_decode_requests_; | 62 --pending_decode_requests_; |
62 last_decode_status_ = status; | 63 last_decode_status_ = status; |
64 } | |
65 | |
66 void FrameReady(const scoped_refptr<VideoFrame>& frame) { | |
63 last_decoded_frame_ = frame; | 67 last_decoded_frame_ = frame; |
64 | 68 if (!frame->end_of_stream()) |
65 if (frame && !frame->end_of_stream()) | |
66 num_decoded_frames_++; | 69 num_decoded_frames_++; |
67 } | 70 } |
68 | 71 |
69 enum CallbackResult { | 72 enum CallbackResult { |
70 PENDING, | 73 PENDING, |
71 OK, | 74 OK, |
72 NOT_ENOUGH_DATA, | 75 NOT_ENOUGH_DATA, |
73 ABORTED, | 76 ABORTED, |
74 EOS | 77 EOS |
75 }; | 78 }; |
76 | 79 |
77 void ExpectReadResult(CallbackResult result) { | 80 void ExpectReadResult(CallbackResult result) { |
78 switch (result) { | 81 switch (result) { |
79 case PENDING: | 82 case PENDING: |
80 EXPECT_GT(pending_decode_requests_, 0); | 83 EXPECT_GT(pending_decode_requests_, 0); |
81 break; | 84 break; |
82 case OK: | 85 case OK: |
83 EXPECT_EQ(0, pending_decode_requests_); | 86 EXPECT_EQ(0, pending_decode_requests_); |
84 ASSERT_EQ(VideoDecoder::kOk, last_decode_status_); | 87 ASSERT_EQ(VideoDecoder::kOk, last_decode_status_); |
85 ASSERT_TRUE(last_decoded_frame_); | 88 ASSERT_TRUE(last_decoded_frame_); |
86 EXPECT_FALSE(last_decoded_frame_->end_of_stream()); | 89 EXPECT_FALSE(last_decoded_frame_->end_of_stream()); |
87 break; | 90 break; |
88 case NOT_ENOUGH_DATA: | 91 case NOT_ENOUGH_DATA: |
89 EXPECT_EQ(0, pending_decode_requests_); | 92 EXPECT_EQ(0, pending_decode_requests_); |
90 ASSERT_EQ(VideoDecoder::kNotEnoughData, last_decode_status_); | 93 ASSERT_EQ(VideoDecoder::kOk, last_decode_status_); |
91 ASSERT_FALSE(last_decoded_frame_); | 94 ASSERT_FALSE(last_decoded_frame_); |
92 break; | 95 break; |
93 case ABORTED: | 96 case ABORTED: |
94 EXPECT_EQ(0, pending_decode_requests_); | 97 EXPECT_EQ(0, pending_decode_requests_); |
95 ASSERT_EQ(VideoDecoder::kAborted, last_decode_status_); | 98 ASSERT_EQ(VideoDecoder::kAborted, last_decode_status_); |
96 EXPECT_FALSE(last_decoded_frame_); | 99 EXPECT_FALSE(last_decoded_frame_); |
97 break; | 100 break; |
98 case EOS: | 101 case EOS: |
99 EXPECT_EQ(0, pending_decode_requests_); | 102 EXPECT_EQ(0, pending_decode_requests_); |
100 ASSERT_EQ(VideoDecoder::kOk, last_decode_status_); | 103 ASSERT_EQ(VideoDecoder::kOk, last_decode_status_); |
101 ASSERT_TRUE(last_decoded_frame_); | 104 ASSERT_TRUE(last_decoded_frame_); |
102 EXPECT_TRUE(last_decoded_frame_->end_of_stream()); | 105 EXPECT_TRUE(last_decoded_frame_->end_of_stream()); |
103 break; | 106 break; |
104 } | 107 } |
105 } | 108 } |
106 | 109 |
107 void Decode() { | 110 void Decode() { |
108 scoped_refptr<DecoderBuffer> buffer; | 111 scoped_refptr<DecoderBuffer> buffer; |
109 | 112 |
113 LOG(ERROR) << "Dec " << num_input_buffers_; | |
xhwang
2014/06/05 21:53:50
remove?
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
110 if (num_input_buffers_ < kTotalBuffers) { | 114 if (num_input_buffers_ < kTotalBuffers) { |
111 buffer = CreateFakeVideoBufferForTest( | 115 buffer = CreateFakeVideoBufferForTest( |
112 current_config_, | 116 current_config_, |
113 base::TimeDelta::FromMilliseconds(kDurationMs * num_input_buffers_), | 117 base::TimeDelta::FromMilliseconds(kDurationMs * num_input_buffers_), |
114 base::TimeDelta::FromMilliseconds(kDurationMs)); | 118 base::TimeDelta::FromMilliseconds(kDurationMs)); |
115 num_input_buffers_++; | 119 num_input_buffers_++; |
116 } else { | 120 } else { |
117 buffer = DecoderBuffer::CreateEOSBuffer(); | 121 buffer = DecoderBuffer::CreateEOSBuffer(); |
118 } | 122 } |
119 | 123 |
120 ++pending_decode_requests_; | 124 ++pending_decode_requests_; |
121 | 125 |
122 decoder_->Decode( | 126 decoder_->Decode( |
123 buffer, | 127 buffer, |
124 base::Bind(&FakeVideoDecoderTest::FrameReady, base::Unretained(this))); | 128 base::Bind(&FakeVideoDecoderTest::DecodeDone, base::Unretained(this))); |
125 message_loop_.RunUntilIdle(); | 129 message_loop_.RunUntilIdle(); |
126 } | 130 } |
127 | 131 |
128 void ReadOneFrame() { | 132 void ReadOneFrame() { |
133 last_decoded_frame_ = NULL; | |
129 do { | 134 do { |
130 Decode(); | 135 Decode(); |
131 } while (last_decode_status_ == VideoDecoder::kNotEnoughData && | 136 } while (!last_decoded_frame_ && pending_decode_requests_ == 0); |
132 pending_decode_requests_ == 0); | |
133 } | 137 } |
134 | 138 |
135 void ReadUntilEOS() { | 139 void ReadUntilEOS() { |
136 do { | 140 do { |
137 ReadOneFrame(); | 141 ReadOneFrame(); |
138 } while (last_decoded_frame_ && !last_decoded_frame_->end_of_stream()); | 142 } while (last_decoded_frame_ && !last_decoded_frame_->end_of_stream()); |
139 } | 143 } |
140 | 144 |
141 void EnterPendingReadState() { | 145 void EnterPendingReadState() { |
142 // Pass the initial NOT_ENOUGH_DATA stage. | 146 // Pass the initial NOT_ENOUGH_DATA stage. |
143 ReadOneFrame(); | 147 ReadOneFrame(); |
144 decoder_->HoldDecode(); | 148 decoder_->HoldDecode(); |
149 LOG(ERROR) << "WTF"; | |
xhwang
2014/06/05 21:53:50
remove :)
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
145 ReadOneFrame(); | 150 ReadOneFrame(); |
146 ExpectReadResult(PENDING); | 151 ExpectReadResult(PENDING); |
147 } | 152 } |
148 | 153 |
149 void SatisfyReadAndExpect(CallbackResult result) { | 154 void SatisfyReadAndExpect(CallbackResult result) { |
xhwang
2014/06/05 21:53:50
nit: this should be renamed to SatisfyDecodeAnd...
Sergey Ulanov
2014/06/06 22:49:40
Done.
| |
150 decoder_->SatisfyDecode(); | 155 decoder_->SatisfyDecode(); |
151 message_loop_.RunUntilIdle(); | 156 message_loop_.RunUntilIdle(); |
152 ExpectReadResult(result); | 157 ExpectReadResult(result); |
153 } | 158 } |
154 | 159 |
155 void SatisfyRead() { | 160 void SatisfyRead() { |
156 SatisfyReadAndExpect(OK); | 161 SatisfyReadAndExpect(OK); |
157 } | 162 } |
158 | 163 |
159 // Callback for VideoDecoder::Reset(). | 164 // Callback for VideoDecoder::Reset(). |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 TEST_P(FakeVideoDecoderTest, Read_DecodingDelay) { | 246 TEST_P(FakeVideoDecoderTest, Read_DecodingDelay) { |
242 Initialize(); | 247 Initialize(); |
243 | 248 |
244 while (num_input_buffers_ < kTotalBuffers) { | 249 while (num_input_buffers_ < kTotalBuffers) { |
245 ReadOneFrame(); | 250 ReadOneFrame(); |
246 EXPECT_EQ(num_input_buffers_, num_decoded_frames_ + kDecodingDelay); | 251 EXPECT_EQ(num_input_buffers_, num_decoded_frames_ + kDecodingDelay); |
247 } | 252 } |
248 } | 253 } |
249 | 254 |
250 TEST_P(FakeVideoDecoderTest, Read_ZeroDelay) { | 255 TEST_P(FakeVideoDecoderTest, Read_ZeroDelay) { |
251 decoder_.reset(new FakeVideoDecoder(0, false, 1)); | 256 decoder_.reset(new FakeVideoDecoder(0, 1)); |
252 Initialize(); | 257 Initialize(); |
253 | 258 |
254 while (num_input_buffers_ < kTotalBuffers) { | 259 while (num_input_buffers_ < kTotalBuffers) { |
255 ReadOneFrame(); | 260 ReadOneFrame(); |
256 EXPECT_EQ(num_input_buffers_, num_decoded_frames_); | 261 EXPECT_EQ(num_input_buffers_, num_decoded_frames_); |
257 } | 262 } |
258 } | 263 } |
259 | 264 |
260 TEST_P(FakeVideoDecoderTest, Read_Pending_NotEnoughData) { | 265 TEST_P(FakeVideoDecoderTest, Read_Pending_NotEnoughData) { |
261 Initialize(); | 266 Initialize(); |
262 decoder_->HoldDecode(); | 267 decoder_->HoldDecode(); |
263 ReadOneFrame(); | 268 ReadOneFrame(); |
264 ExpectReadResult(PENDING); | 269 ExpectReadResult(PENDING); |
265 SatisfyReadAndExpect(NOT_ENOUGH_DATA); | 270 SatisfyReadAndExpect(NOT_ENOUGH_DATA); |
271 | |
272 // Verify that FrameReady() hasn't been called. | |
273 EXPECT_FALSE(last_decoded_frame_); | |
266 } | 274 } |
267 | 275 |
268 TEST_P(FakeVideoDecoderTest, Read_Pending_OK) { | 276 TEST_P(FakeVideoDecoderTest, Read_Pending_OK) { |
269 Initialize(); | 277 Initialize(); |
270 ReadOneFrame(); | |
271 EnterPendingReadState(); | 278 EnterPendingReadState(); |
272 SatisfyReadAndExpect(OK); | 279 SatisfyReadAndExpect(OK); |
273 } | 280 } |
274 | 281 |
275 TEST_P(FakeVideoDecoderTest, Read_Parallel) { | 282 TEST_P(FakeVideoDecoderTest, Read_Parallel) { |
276 int max_decode_requests = GetParam(); | 283 int max_decode_requests = GetParam(); |
277 if (max_decode_requests < 2) | 284 if (max_decode_requests < 2) |
278 return; | 285 return; |
279 | 286 |
280 Initialize(); | 287 Initialize(); |
281 ReadOneFrame(); | |
282 decoder_->HoldDecode(); | 288 decoder_->HoldDecode(); |
283 for (int i = 0; i < max_decode_requests; ++i) { | 289 for (int i = 0; i < max_decode_requests; ++i) { |
284 ReadOneFrame(); | 290 ReadOneFrame(); |
285 ExpectReadResult(PENDING); | 291 ExpectReadResult(PENDING); |
286 } | 292 } |
287 EXPECT_EQ(max_decode_requests, pending_decode_requests_); | 293 EXPECT_EQ(max_decode_requests, pending_decode_requests_); |
288 SatisfyReadAndExpect(OK); | 294 SatisfyReadAndExpect(NOT_ENOUGH_DATA); |
xhwang
2014/06/05 21:53:50
hmm, if max_decode_requests > decoding_delay, shou
Sergey Ulanov
2014/06/06 22:49:40
Yes, but we didn't have tests with max_decode_requ
| |
289 } | 295 } |
290 | 296 |
291 TEST_P(FakeVideoDecoderTest, ReadWithHold_DecodingDelay) { | 297 TEST_P(FakeVideoDecoderTest, ReadWithHold_DecodingDelay) { |
292 Initialize(); | 298 Initialize(); |
293 | 299 |
294 // Hold all decodes and satisfy one decode at a time. | 300 // Hold all decodes and satisfy one decode at a time. |
295 decoder_->HoldDecode(); | 301 decoder_->HoldDecode(); |
296 int num_decodes_satisfied = 0; | 302 int num_decodes_satisfied = 0; |
297 while (num_decoded_frames_ == 0) { | 303 while (num_decoded_frames_ == 0) { |
298 while (pending_decode_requests_ < decoder_->GetMaxDecodeRequests()) | 304 while (pending_decode_requests_ < decoder_->GetMaxDecodeRequests()) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
374 Stop(); | 380 Stop(); |
375 } | 381 } |
376 | 382 |
377 TEST_P(FakeVideoDecoderTest, Stop_DuringPendingReadAndPendingReset) { | 383 TEST_P(FakeVideoDecoderTest, Stop_DuringPendingReadAndPendingReset) { |
378 Initialize(); | 384 Initialize(); |
379 EnterPendingReadState(); | 385 EnterPendingReadState(); |
380 EnterPendingResetState(); | 386 EnterPendingResetState(); |
381 Stop(); | 387 Stop(); |
382 } | 388 } |
383 | 389 |
384 TEST_P(FakeVideoDecoderTest, GetDecodeOutput) { | |
385 decoder_.reset(new FakeVideoDecoder(kDecodingDelay, true, 1)); | |
386 Initialize(); | |
387 | |
388 while (num_input_buffers_ < kTotalBuffers) { | |
389 ReadOneFrame(); | |
390 while (decoder_->GetDecodeOutput()) | |
391 ++num_decoded_frames_; | |
392 EXPECT_EQ(num_input_buffers_, num_decoded_frames_); | |
393 } | |
394 } | |
395 | |
396 } // namespace media | 390 } // namespace media |
OLD | NEW |