OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "chromecast/media/cma/base/mock_frame_provider.h" | |
6 | |
7 #include "base/bind.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/base/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/rect.h" | |
18 #include "ui/gfx/size.h" | |
19 | |
20 namespace chromecast { | |
21 namespace media { | |
22 | |
23 MockFrameProvider::MockFrameProvider() { | |
24 } | |
25 | |
26 MockFrameProvider::~MockFrameProvider() { | |
27 } | |
28 | |
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; | |
33 pattern_idx_ = 0; | |
34 | |
35 frame_generator_.reset(frame_generator.release()); | |
36 } | |
37 | |
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(); | |
41 | |
42 if (delayed) { | |
43 base::MessageLoopProxy::current()->PostDelayedTask( | |
44 FROM_HERE, | |
45 base::Bind(&MockFrameProvider::DoRead, | |
46 base::Unretained(this), read_cb), | |
47 base::TimeDelta::FromMilliseconds(1)); | |
48 } else { | |
49 base::MessageLoopProxy::current()->PostTask( | |
50 FROM_HERE, | |
51 base::Bind(&MockFrameProvider::DoRead, | |
52 base::Unretained(this), read_cb)); | |
53 } | |
54 } | |
55 | |
56 void MockFrameProvider::Flush(const base::Closure& flush_cb) { | |
57 flush_cb.Run(); | |
58 } | |
59 | |
60 void MockFrameProvider::DoRead(const ReadCB& read_cb) { | |
61 bool has_config = frame_generator_->HasDecoderConfig(); | |
62 | |
63 scoped_refptr<DecoderBufferBase> buffer(frame_generator_->Generate()); | |
64 ASSERT_TRUE(buffer.get()); | |
65 | |
66 ::media::AudioDecoderConfig audio_config; | |
67 ::media::VideoDecoderConfig video_config; | |
68 if (has_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( | |
73 ::media::kCodecH264, | |
74 ::media::VIDEO_CODEC_PROFILE_UNKNOWN, | |
75 ::media::VideoFrame::YV12, | |
76 coded_size, | |
77 visible_rect, | |
78 natural_size, | |
79 NULL, 0, | |
80 false); | |
81 | |
82 audio_config = ::media::AudioDecoderConfig( | |
83 ::media::kCodecAAC, | |
84 ::media::kSampleFormatS16, | |
85 ::media::CHANNEL_LAYOUT_STEREO, | |
86 44100, | |
87 NULL, 0, | |
88 false); | |
89 } | |
90 | |
91 read_cb.Run(buffer, audio_config, video_config); | |
92 } | |
93 | |
94 } // namespace media | |
95 } // namespace chromecast | |
OLD | NEW |