1 // Copyright 2014 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.
5 #include "chromecast/media/cma/test/mock_frame_provider.h"
8 #include "base/location.h"
9 #include "base/single_thread_task_runner.h"
10 #include "base/thread_task_runner_handle.h"
11 #include "base/time/time.h"
12 #include "chromecast/media/cma/base/decoder_buffer_base.h"
13 #include "chromecast/media/cma/test/frame_generator_for_test.h"
14 #include "media/base/audio_decoder_config.h"
15 #include "media/base/decoder_buffer.h"
16 #include "media/base/video_decoder_config.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/size.h"
21 namespace chromecast
{
24 MockFrameProvider::MockFrameProvider() {
27 MockFrameProvider::~MockFrameProvider() {
30 void MockFrameProvider::Configure(
31 const std::vector
<bool>& delayed_task_pattern
,
32 scoped_ptr
<FrameGeneratorForTest
> frame_generator
) {
33 delayed_task_pattern_
= delayed_task_pattern
;
36 frame_generator_
.reset(frame_generator
.release());
39 void MockFrameProvider::Read(const ReadCB
& read_cb
) {
40 bool delayed
= delayed_task_pattern_
[pattern_idx_
];
41 pattern_idx_
= (pattern_idx_
+ 1) % delayed_task_pattern_
.size();
44 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
46 base::Bind(&MockFrameProvider::DoRead
, base::Unretained(this), read_cb
),
47 base::TimeDelta::FromMilliseconds(1));
49 base::ThreadTaskRunnerHandle::Get()->PostTask(
50 FROM_HERE
, base::Bind(&MockFrameProvider::DoRead
,
51 base::Unretained(this), read_cb
));
55 void MockFrameProvider::Flush(const base::Closure
& flush_cb
) {
59 void MockFrameProvider::DoRead(const ReadCB
& read_cb
) {
60 bool has_config
= frame_generator_
->HasDecoderConfig();
62 scoped_refptr
<DecoderBufferBase
> buffer(frame_generator_
->Generate());
63 ASSERT_TRUE(buffer
.get());
65 ::media::AudioDecoderConfig audio_config
;
66 ::media::VideoDecoderConfig video_config
;
68 gfx::Size
coded_size(640, 480);
69 gfx::Rect
visible_rect(640, 480);
70 gfx::Size
natural_size(640, 480);
71 video_config
= ::media::VideoDecoderConfig(
73 ::media::VIDEO_CODEC_PROFILE_UNKNOWN
,
74 ::media::VideoFrame::YV12
,
81 audio_config
= ::media::AudioDecoderConfig(
83 ::media::kSampleFormatS16
,
84 ::media::CHANNEL_LAYOUT_STEREO
,
90 read_cb
.Run(buffer
, audio_config
, video_config
);
94 } // namespace chromecast