1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "base/logging.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "base/timer/timer.h"
9 #include "media/base/android/media_codec_audio_decoder.h"
10 #include "media/base/android/media_codec_bridge.h"
11 #include "media/base/android/media_codec_video_decoder.h"
12 #include "media/base/android/test_data_factory.h"
13 #include "media/base/android/test_statistics.h"
14 #include "media/base/buffers.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/gl/android/surface_texture.h"
20 // Helper macro to skip the test if MediaCodecBridge isn't available.
21 #define SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE() \
23 if (!MediaCodecBridge::IsAvailable()) { \
24 VLOG(0) << "Could not run test - not supported on device."; \
31 const base::TimeDelta kDefaultTimeout
= base::TimeDelta::FromMilliseconds(200);
32 const base::TimeDelta kAudioFramePeriod
=
33 base::TimeDelta::FromSecondsD(1024.0 / 44100); // 1024 samples @ 44100 Hz
34 const base::TimeDelta kVideoFramePeriod
= base::TimeDelta::FromMilliseconds(20);
36 class AudioFactory
: public TestDataFactory
{
38 AudioFactory(base::TimeDelta duration
);
39 DemuxerConfigs
GetConfigs() const override
;
42 void ModifyAccessUnit(int index_in_chunk
, AccessUnit
* unit
) override
;
45 class VideoFactory
: public TestDataFactory
{
47 VideoFactory(base::TimeDelta duration
);
48 DemuxerConfigs
GetConfigs() const override
;
51 void ModifyAccessUnit(int index_in_chunk
, AccessUnit
* unit
) override
;
54 AudioFactory::AudioFactory(base::TimeDelta duration
)
55 : TestDataFactory("aac-44100-packet-%d", duration
, kAudioFramePeriod
) {
58 DemuxerConfigs
AudioFactory::GetConfigs() const {
59 return TestDataFactory::CreateAudioConfigs(kCodecAAC
, duration_
);
62 void AudioFactory::ModifyAccessUnit(int index_in_chunk
, AccessUnit
* unit
) {
63 unit
->is_key_frame
= true;
66 VideoFactory::VideoFactory(base::TimeDelta duration
)
67 : TestDataFactory("h264-320x180-frame-%d", duration
, kVideoFramePeriod
) {
70 DemuxerConfigs
VideoFactory::GetConfigs() const {
71 return TestDataFactory::CreateVideoConfigs(kCodecH264
, duration_
,
75 void VideoFactory::ModifyAccessUnit(int index_in_chunk
, AccessUnit
* unit
) {
76 // The frames are taken from High profile and some are B-frames.
77 // The first 4 frames appear in the file in the following order:
80 // Decoding order: 0 1 2 3
81 // Presentation order: 0 2 1 4(3)
83 // I keep the last PTS to be 3 for simplicity.
85 // Swap pts for second and third frames. Make first frame a key frame.
86 switch (index_in_chunk
) {
87 case 0: // first frame
88 unit
->is_key_frame
= true;
90 case 1: // second frame
91 unit
->timestamp
+= frame_period_
;
93 case 2: // third frame
94 unit
->timestamp
-= frame_period_
;
96 case 3: // fourth frame, do not modify
104 } // namespace (anonymous)
106 // The test fixture for MediaCodecDecoder
108 class MediaCodecDecoderTest
: public testing::Test
{
110 MediaCodecDecoderTest();
111 ~MediaCodecDecoderTest() override
;
113 // Conditions we wait for.
114 bool is_prefetched() const { return is_prefetched_
; }
115 bool is_stopped() const { return is_stopped_
; }
116 bool is_starved() const { return is_starved_
; }
118 void SetPrefetched(bool value
) { is_prefetched_
= value
; }
119 void SetStopped(bool value
) { is_stopped_
= value
; }
120 void SetStarved(bool value
) { is_starved_
= value
; }
123 typedef base::Callback
<bool()> Predicate
;
125 typedef base::Callback
<void(const DemuxerData
&)> DataAvailableCallback
;
127 // Waits for condition to become true or for timeout to expire.
128 // Returns true if the condition becomes true.
129 bool WaitForCondition(const Predicate
& condition
,
130 const base::TimeDelta
& timeout
= kDefaultTimeout
);
132 void SetDataFactory(scoped_ptr
<TestDataFactory
> factory
) {
133 data_factory_
= factory
.Pass();
136 DemuxerConfigs
GetConfigs() const {
137 // ASSERT_NE does not compile here because it expects void return value.
138 EXPECT_NE(nullptr, data_factory_
.get());
139 return data_factory_
->GetConfigs();
142 void CreateAudioDecoder();
143 void CreateVideoDecoder();
144 void SetVideoSurface();
145 void SetStopRequestAtTime(const base::TimeDelta
& time
) {
146 stop_request_time_
= time
;
149 // Decoder callbacks.
150 void OnDataRequested();
151 void OnStarvation() { is_starved_
= true; }
152 void OnStopDone() { is_stopped_
= true; }
154 void OnUpdateCurrentTime(base::TimeDelta now_playing
,
155 base::TimeDelta last_buffered
) {
156 // Add the |last_buffered| value for PTS. For video it is the same as
157 // |now_playing| and is equal to PTS, for audio |last_buffered| should
159 pts_stat_
.AddValue(last_buffered
);
161 if (stop_request_time_
!= kNoTimestamp() &&
162 now_playing
>= stop_request_time_
) {
163 stop_request_time_
= kNoTimestamp();
164 decoder_
->RequestToStop();
168 void OnVideoSizeChanged(const gfx::Size
& video_size
) {}
169 void OnVideoCodecCreated() {}
171 scoped_ptr
<MediaCodecDecoder
> decoder_
;
172 scoped_ptr
<TestDataFactory
> data_factory_
;
173 Minimax
<base::TimeDelta
> pts_stat_
;
176 bool is_timeout_expired() const { return is_timeout_expired_
; }
177 void SetTimeoutExpired(bool value
) { is_timeout_expired_
= value
; }
179 base::MessageLoop message_loop_
;
180 bool is_timeout_expired_
;
185 base::TimeDelta stop_request_time_
;
187 scoped_refptr
<base::SingleThreadTaskRunner
> task_runner_
;
188 DataAvailableCallback data_available_cb_
;
189 scoped_refptr
<gfx::SurfaceTexture
> surface_texture_
;
191 DISALLOW_COPY_AND_ASSIGN(MediaCodecDecoderTest
);
194 MediaCodecDecoderTest::MediaCodecDecoderTest()
195 : is_timeout_expired_(false),
196 is_prefetched_(false),
199 stop_request_time_(kNoTimestamp()),
200 task_runner_(base::ThreadTaskRunnerHandle::Get()) {
203 MediaCodecDecoderTest::~MediaCodecDecoderTest() {}
205 bool MediaCodecDecoderTest::WaitForCondition(const Predicate
& condition
,
206 const base::TimeDelta
& timeout
) {
207 // Let the message_loop_ process events.
208 // We start the timer and RunUntilIdle() until it signals.
210 SetTimeoutExpired(false);
212 base::Timer
timer(false, false);
213 timer
.Start(FROM_HERE
, timeout
,
214 base::Bind(&MediaCodecDecoderTest::SetTimeoutExpired
,
215 base::Unretained(this), true));
218 if (condition
.Run()) {
222 message_loop_
.RunUntilIdle();
223 } while (!is_timeout_expired());
225 DCHECK(!timer
.IsRunning());
229 void MediaCodecDecoderTest::CreateAudioDecoder() {
230 decoder_
= scoped_ptr
<MediaCodecDecoder
>(new MediaCodecAudioDecoder(
231 task_runner_
, base::Bind(&MediaCodecDecoderTest::OnDataRequested
,
232 base::Unretained(this)),
233 base::Bind(&MediaCodecDecoderTest::OnStarvation
, base::Unretained(this)),
234 base::Bind(&MediaCodecDecoderTest::OnStopDone
, base::Unretained(this)),
235 base::Bind(&MediaCodecDecoderTest::OnError
, base::Unretained(this)),
236 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime
,
237 base::Unretained(this))));
239 data_available_cb_
= base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable
,
240 base::Unretained(decoder_
.get()));
243 void MediaCodecDecoderTest::CreateVideoDecoder() {
244 decoder_
= scoped_ptr
<MediaCodecDecoder
>(new MediaCodecVideoDecoder(
245 task_runner_
, base::Bind(&MediaCodecDecoderTest::OnDataRequested
,
246 base::Unretained(this)),
247 base::Bind(&MediaCodecDecoderTest::OnStarvation
, base::Unretained(this)),
248 base::Bind(&MediaCodecDecoderTest::OnStopDone
, base::Unretained(this)),
249 base::Bind(&MediaCodecDecoderTest::OnError
, base::Unretained(this)),
250 base::Bind(&MediaCodecDecoderTest::OnUpdateCurrentTime
,
251 base::Unretained(this)),
252 base::Bind(&MediaCodecDecoderTest::OnVideoSizeChanged
,
253 base::Unretained(this)),
254 base::Bind(&MediaCodecDecoderTest::OnVideoCodecCreated
,
255 base::Unretained(this))));
257 data_available_cb_
= base::Bind(&MediaCodecDecoder::OnDemuxerDataAvailable
,
258 base::Unretained(decoder_
.get()));
261 void MediaCodecDecoderTest::OnDataRequested() {
266 base::TimeDelta delay
;
267 if (!data_factory_
->CreateChunk(&data
, &delay
))
270 task_runner_
->PostDelayedTask(FROM_HERE
, base::Bind(data_available_cb_
, data
),
274 void MediaCodecDecoderTest::SetVideoSurface() {
275 surface_texture_
= gfx::SurfaceTexture::Create(0);
276 gfx::ScopedJavaSurface
surface(surface_texture_
.get());
277 ASSERT_NE(nullptr, decoder_
.get());
278 MediaCodecVideoDecoder
* video_decoder
=
279 static_cast<MediaCodecVideoDecoder
*>(decoder_
.get());
280 video_decoder
->SetVideoSurface(surface
.Pass());
283 TEST_F(MediaCodecDecoderTest
, AudioPrefetch
) {
284 CreateAudioDecoder();
286 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
287 SetDataFactory(scoped_ptr
<TestDataFactory
>(new AudioFactory(duration
)));
289 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
290 base::Unretained(this), true));
292 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
293 base::Unretained(this))));
296 TEST_F(MediaCodecDecoderTest
, VideoPrefetch
) {
297 CreateVideoDecoder();
299 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
300 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
302 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
303 base::Unretained(this), true));
305 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
306 base::Unretained(this))));
309 TEST_F(MediaCodecDecoderTest
, AudioConfigureNoParams
) {
310 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
312 CreateAudioDecoder();
314 // Cannot configure without config parameters.
315 EXPECT_EQ(MediaCodecDecoder::kConfigFailure
, decoder_
->Configure());
318 TEST_F(MediaCodecDecoderTest
, AudioConfigureValidParams
) {
319 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
321 CreateAudioDecoder();
323 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
324 scoped_ptr
<AudioFactory
> factory(new AudioFactory(duration
));
325 decoder_
->SetDemuxerConfigs(factory
->GetConfigs());
327 EXPECT_EQ(MediaCodecDecoder::kConfigOk
, decoder_
->Configure());
330 TEST_F(MediaCodecDecoderTest
, VideoConfigureNoParams
) {
331 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
333 CreateVideoDecoder();
335 // decoder_->Configure() searches back for the key frame.
336 // We have to prefetch decoder.
338 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
339 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
341 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
342 base::Unretained(this), true));
344 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
345 base::Unretained(this))));
349 // Cannot configure without config parameters.
350 EXPECT_EQ(MediaCodecDecoder::kConfigFailure
, decoder_
->Configure());
353 TEST_F(MediaCodecDecoderTest
, VideoConfigureNoSurface
) {
354 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
356 CreateVideoDecoder();
358 // decoder_->Configure() searches back for the key frame.
359 // We have to prefetch decoder.
361 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
362 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
364 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
365 base::Unretained(this), true));
367 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
368 base::Unretained(this))));
370 decoder_
->SetDemuxerConfigs(GetConfigs());
372 // Surface is not set, Configure() should fail.
374 EXPECT_EQ(MediaCodecDecoder::kConfigFailure
, decoder_
->Configure());
377 TEST_F(MediaCodecDecoderTest
, VideoConfigureInvalidSurface
) {
378 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
380 CreateVideoDecoder();
382 // decoder_->Configure() searches back for the key frame.
383 // We have to prefetch decoder.
385 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
386 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
388 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
389 base::Unretained(this), true));
391 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
392 base::Unretained(this))));
394 decoder_
->SetDemuxerConfigs(GetConfigs());
396 // Prepare the surface.
397 scoped_refptr
<gfx::SurfaceTexture
> surface_texture(
398 gfx::SurfaceTexture::Create(0));
399 gfx::ScopedJavaSurface
surface(surface_texture
.get());
401 // Release the surface texture.
402 surface_texture
= NULL
;
404 MediaCodecVideoDecoder
* video_decoder
=
405 static_cast<MediaCodecVideoDecoder
*>(decoder_
.get());
406 video_decoder
->SetVideoSurface(surface
.Pass());
408 EXPECT_EQ(MediaCodecDecoder::kConfigFailure
, decoder_
->Configure());
411 TEST_F(MediaCodecDecoderTest
, VideoConfigureValidParams
) {
412 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
414 CreateVideoDecoder();
416 // decoder_->Configure() searches back for the key frame.
417 // We have to prefetch decoder.
419 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
420 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
422 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
423 base::Unretained(this), true));
425 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
426 base::Unretained(this))));
428 decoder_
->SetDemuxerConfigs(GetConfigs());
432 // Now we can expect Configure() to succeed.
434 EXPECT_EQ(MediaCodecDecoder::kConfigOk
, decoder_
->Configure());
437 TEST_F(MediaCodecDecoderTest
, AudioStartWithoutConfigure
) {
438 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
440 CreateAudioDecoder();
442 // Decoder has to be prefetched and configured before the start.
444 // Wrong state: not prefetched
445 EXPECT_FALSE(decoder_
->Start(base::TimeDelta::FromMilliseconds(0)));
448 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
449 SetDataFactory(scoped_ptr
<AudioFactory
>(new AudioFactory(duration
)));
451 // Prefetch to avoid starvation at the beginning of playback.
452 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
453 base::Unretained(this), true));
455 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
456 base::Unretained(this))));
458 // Still, decoder is not configured.
459 EXPECT_FALSE(decoder_
->Start(base::TimeDelta::FromMilliseconds(0)));
462 TEST_F(MediaCodecDecoderTest
, AudioPlayTillCompletion
) {
463 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
465 CreateAudioDecoder();
467 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
468 base::TimeDelta timeout
= base::TimeDelta::FromMilliseconds(1500);
470 SetDataFactory(scoped_ptr
<AudioFactory
>(new AudioFactory(duration
)));
472 // Prefetch to avoid starvation at the beginning of playback.
473 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
474 base::Unretained(this), true));
476 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
477 base::Unretained(this))));
479 decoder_
->SetDemuxerConfigs(GetConfigs());
481 EXPECT_EQ(MediaCodecDecoder::kConfigOk
, decoder_
->Configure());
483 EXPECT_TRUE(decoder_
->Start(base::TimeDelta::FromMilliseconds(0)));
485 EXPECT_TRUE(WaitForCondition(
486 base::Bind(&MediaCodecDecoderTest::is_stopped
, base::Unretained(this)),
489 EXPECT_TRUE(decoder_
->IsStopped());
490 EXPECT_TRUE(decoder_
->IsCompleted());
492 // Last buffered timestamp should be no less than PTS.
493 EXPECT_EQ(22, pts_stat_
.num_values());
494 EXPECT_LE(data_factory_
->last_pts(), pts_stat_
.max());
497 TEST_F(MediaCodecDecoderTest
, VideoPlayTillCompletion
) {
498 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
500 CreateVideoDecoder();
502 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
503 // The first output frame might come out with significant delay. Apparently
504 // the codec does initial configuration at this time. We increase the timeout
505 // to leave a room of 1 second for this initial configuration.
506 base::TimeDelta timeout
= base::TimeDelta::FromMilliseconds(1500);
507 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
510 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
511 base::Unretained(this), true));
513 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
514 base::Unretained(this))));
516 decoder_
->SetDemuxerConfigs(GetConfigs());
520 EXPECT_EQ(MediaCodecDecoder::kConfigOk
, decoder_
->Configure());
522 EXPECT_TRUE(decoder_
->Start(base::TimeDelta::FromMilliseconds(0)));
524 EXPECT_TRUE(WaitForCondition(
525 base::Bind(&MediaCodecDecoderTest::is_stopped
, base::Unretained(this)),
528 EXPECT_TRUE(decoder_
->IsStopped());
529 EXPECT_TRUE(decoder_
->IsCompleted());
531 EXPECT_EQ(26, pts_stat_
.num_values());
532 EXPECT_EQ(data_factory_
->last_pts(), pts_stat_
.max());
535 TEST_F(MediaCodecDecoderTest
, VideoStopAndResume
) {
536 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
538 CreateVideoDecoder();
540 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(500);
541 base::TimeDelta stop_request_time
= base::TimeDelta::FromMilliseconds(200);
542 base::TimeDelta timeout
= base::TimeDelta::FromMilliseconds(1000);
544 SetDataFactory(scoped_ptr
<VideoFactory
>(new VideoFactory(duration
)));
547 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
548 base::Unretained(this), true));
550 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
551 base::Unretained(this))));
553 decoder_
->SetDemuxerConfigs(GetConfigs());
557 EXPECT_EQ(MediaCodecDecoder::kConfigOk
, decoder_
->Configure());
559 SetStopRequestAtTime(stop_request_time
);
561 // Start from the beginning.
562 EXPECT_TRUE(decoder_
->Start(base::TimeDelta::FromMilliseconds(0)));
564 EXPECT_TRUE(WaitForCondition(
565 base::Bind(&MediaCodecDecoderTest::is_stopped
, base::Unretained(this)),
568 EXPECT_TRUE(decoder_
->IsStopped());
569 EXPECT_FALSE(decoder_
->IsCompleted());
571 base::TimeDelta last_pts
= pts_stat_
.max();
573 EXPECT_GE(last_pts
, stop_request_time
);
575 // Resume playback from last_pts:
577 SetPrefetched(false);
581 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
582 base::Unretained(this), true));
584 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
585 base::Unretained(this))));
588 EXPECT_TRUE(decoder_
->Start(last_pts
));
590 // Wait till completion.
591 EXPECT_TRUE(WaitForCondition(
592 base::Bind(&MediaCodecDecoderTest::is_stopped
, base::Unretained(this)),
595 EXPECT_TRUE(decoder_
->IsStopped());
596 EXPECT_TRUE(decoder_
->IsCompleted());
598 // We should not skip frames in this process.
599 EXPECT_EQ(26, pts_stat_
.num_values());
600 EXPECT_EQ(data_factory_
->last_pts(), pts_stat_
.max());
603 TEST_F(MediaCodecDecoderTest
, AudioStarvationAndStop
) {
604 SKIP_TEST_IF_MEDIA_CODEC_BRIDGE_IS_NOT_AVAILABLE();
606 CreateAudioDecoder();
608 base::TimeDelta duration
= base::TimeDelta::FromMilliseconds(200);
609 base::TimeDelta timeout
= base::TimeDelta::FromMilliseconds(400);
611 AudioFactory
* factory
= new AudioFactory(duration
);
612 factory
->SetStarvationMode(true);
613 SetDataFactory(scoped_ptr
<AudioFactory
>(factory
));
616 decoder_
->Prefetch(base::Bind(&MediaCodecDecoderTest::SetPrefetched
,
617 base::Unretained(this), true));
619 EXPECT_TRUE(WaitForCondition(base::Bind(&MediaCodecDecoderTest::is_prefetched
,
620 base::Unretained(this))));
623 decoder_
->SetDemuxerConfigs(GetConfigs());
625 EXPECT_EQ(MediaCodecDecoder::kConfigOk
, decoder_
->Configure());
628 EXPECT_TRUE(decoder_
->Start(base::TimeDelta::FromMilliseconds(0)));
630 // Wait for starvation.
631 EXPECT_TRUE(WaitForCondition(
632 base::Bind(&MediaCodecDecoderTest::is_starved
, base::Unretained(this)),
635 EXPECT_FALSE(decoder_
->IsStopped());
636 EXPECT_FALSE(decoder_
->IsCompleted());
638 EXPECT_GT(pts_stat_
.num_values(), 0);
640 // After starvation we should be able to stop decoder.
641 decoder_
->RequestToStop();
643 EXPECT_TRUE(WaitForCondition(
644 base::Bind(&MediaCodecDecoderTest::is_stopped
, base::Unretained(this))));
646 EXPECT_TRUE(decoder_
->IsStopped());
647 EXPECT_FALSE(decoder_
->IsCompleted());