[MediaRouter] Update MR-2-Extension's PostMessage to return boolean.
[chromium-blink-merge.git] / chromecast / media / cma / test / demuxer_stream_for_test.cc
blob145e5d4605f304956ed9ef741d37a9236659d871
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.
5 #include "base/threading/thread.h"
6 #include "chromecast/media/cma/test/demuxer_stream_for_test.h"
8 namespace chromecast {
9 namespace media {
11 DemuxerStreamForTest::DemuxerStreamForTest(int total_frames,
12 int cycle_count,
13 int delayed_frame_count,
14 const std::list<int>& config_idx)
15 : total_frame_count_(total_frames),
16 cycle_count_(cycle_count),
17 delayed_frame_count_(delayed_frame_count),
18 config_idx_(config_idx),
19 frame_count_(0),
20 has_pending_read_(false) {
21 DCHECK_LE(delayed_frame_count, cycle_count);
24 DemuxerStreamForTest::~DemuxerStreamForTest() {
27 void DemuxerStreamForTest::Read(const ReadCB& read_cb) {
28 has_pending_read_ = true;
29 if (!config_idx_.empty() && config_idx_.front() == frame_count_) {
30 config_idx_.pop_front();
31 has_pending_read_ = false;
32 read_cb.Run(kConfigChanged, scoped_refptr<::media::DecoderBuffer>());
33 return;
36 if ((frame_count_ % cycle_count_) < delayed_frame_count_) {
37 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
38 FROM_HERE, base::Bind(&DemuxerStreamForTest::DoRead,
39 base::Unretained(this), read_cb),
40 base::TimeDelta::FromMilliseconds(20));
41 return;
43 DoRead(read_cb);
46 ::media::AudioDecoderConfig DemuxerStreamForTest::audio_decoder_config() {
47 NOTREACHED() << "DemuxerStreamForTest is a video DemuxerStream";
48 return ::media::AudioDecoderConfig();
51 ::media::VideoDecoderConfig DemuxerStreamForTest::video_decoder_config() {
52 gfx::Size coded_size(640, 480);
53 gfx::Rect visible_rect(640, 480);
54 gfx::Size natural_size(640, 480);
55 return ::media::VideoDecoderConfig(
56 ::media::kCodecH264, ::media::VIDEO_CODEC_PROFILE_UNKNOWN,
57 ::media::VideoFrame::YV12, coded_size, visible_rect, natural_size, NULL,
58 0, false);
61 ::media::DemuxerStream::Type DemuxerStreamForTest::type() const {
62 return VIDEO;
65 bool DemuxerStreamForTest::SupportsConfigChanges() {
66 return true;
69 ::media::VideoRotation DemuxerStreamForTest::video_rotation() {
70 return ::media::VIDEO_ROTATION_0;
73 void DemuxerStreamForTest::DoRead(const ReadCB& read_cb) {
74 has_pending_read_ = false;
76 if (total_frame_count_ != -1 && frame_count_ >= total_frame_count_) {
77 // End of stream
78 read_cb.Run(kOk, ::media::DecoderBuffer::CreateEOSBuffer());
79 return;
82 scoped_refptr<::media::DecoderBuffer> buffer(new ::media::DecoderBuffer(16));
83 buffer->set_timestamp(frame_count_ * base::TimeDelta::FromMilliseconds(
84 kDemuxerStreamForTestFrameDuration));
85 frame_count_++;
86 read_cb.Run(kOk, buffer);
89 } // namespace media
90 } // namespace chromecast