[MediaRouter] Update MR-2-Extension's PostMessage to return boolean.
[chromium-blink-merge.git] / chromecast / media / cma / test / mock_frame_provider.cc
blobf9beb0444a58d9d2cec54bd3f61e97411bd5b610
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"
7 #include "base/bind.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 {
22 namespace media {
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;
34 pattern_idx_ = 0;
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();
43 if (delayed) {
44 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
45 FROM_HERE,
46 base::Bind(&MockFrameProvider::DoRead, base::Unretained(this), read_cb),
47 base::TimeDelta::FromMilliseconds(1));
48 } else {
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) {
56 flush_cb.Run();
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;
67 if (has_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(
72 ::media::kCodecH264,
73 ::media::VIDEO_CODEC_PROFILE_UNKNOWN,
74 ::media::VideoFrame::YV12,
75 coded_size,
76 visible_rect,
77 natural_size,
78 NULL, 0,
79 false);
81 audio_config = ::media::AudioDecoderConfig(
82 ::media::kCodecAAC,
83 ::media::kSampleFormatS16,
84 ::media::CHANNEL_LAYOUT_STEREO,
85 44100,
86 NULL, 0,
87 false);
90 read_cb.Run(buffer, audio_config, video_config);
93 } // namespace media
94 } // namespace chromecast