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/message_loop/message_loop_proxy.h"
10 #include "base/time/time.h"
11 #include "chromecast/media/cma/base/decoder_buffer_base.h"
12 #include "chromecast/media/cma/test/frame_generator_for_test.h"
13 #include "media/base/audio_decoder_config.h"
14 #include "media/base/decoder_buffer.h"
15 #include "media/base/video_decoder_config.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h"
20 namespace chromecast
{
23 MockFrameProvider::MockFrameProvider() {
26 MockFrameProvider::~MockFrameProvider() {
29 void MockFrameProvider::Configure(
30 const std::vector
<bool>& delayed_task_pattern
,
31 scoped_ptr
<FrameGeneratorForTest
> frame_generator
) {
32 delayed_task_pattern_
= delayed_task_pattern
;
35 frame_generator_
.reset(frame_generator
.release());
38 void MockFrameProvider::Read(const ReadCB
& read_cb
) {
39 bool delayed
= delayed_task_pattern_
[pattern_idx_
];
40 pattern_idx_
= (pattern_idx_
+ 1) % delayed_task_pattern_
.size();
43 base::MessageLoopProxy::current()->PostDelayedTask(
45 base::Bind(&MockFrameProvider::DoRead
,
46 base::Unretained(this), read_cb
),
47 base::TimeDelta::FromMilliseconds(1));
49 base::MessageLoopProxy::current()->PostTask(
51 base::Bind(&MockFrameProvider::DoRead
,
52 base::Unretained(this), read_cb
));
56 void MockFrameProvider::Flush(const base::Closure
& flush_cb
) {
60 void MockFrameProvider::DoRead(const ReadCB
& read_cb
) {
61 bool has_config
= frame_generator_
->HasDecoderConfig();
63 scoped_refptr
<DecoderBufferBase
> buffer(frame_generator_
->Generate());
64 ASSERT_TRUE(buffer
.get());
66 ::media::AudioDecoderConfig audio_config
;
67 ::media::VideoDecoderConfig video_config
;
69 gfx::Size
coded_size(640, 480);
70 gfx::Rect
visible_rect(640, 480);
71 gfx::Size
natural_size(640, 480);
72 video_config
= ::media::VideoDecoderConfig(
74 ::media::VIDEO_CODEC_PROFILE_UNKNOWN
,
75 ::media::VideoFrame::YV12
,
82 audio_config
= ::media::AudioDecoderConfig(
84 ::media::kSampleFormatS16
,
85 ::media::CHANNEL_LAYOUT_STEREO
,
91 read_cb
.Run(buffer
, audio_config
, video_config
);
95 } // namespace chromecast