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"
11 DemuxerStreamForTest::DemuxerStreamForTest(int total_frames
,
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
),
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
>());
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));
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::PIXEL_FORMAT_YV12
, ::media::COLOR_SPACE_UNSPECIFIED
, coded_size
,
58 visible_rect
, natural_size
, NULL
, 0, false);
61 ::media::DemuxerStream::Type
DemuxerStreamForTest::type() const {
65 bool DemuxerStreamForTest::SupportsConfigChanges() {
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_
) {
78 read_cb
.Run(kOk
, ::media::DecoderBuffer::CreateEOSBuffer());
82 scoped_refptr
<::media::DecoderBuffer
> buffer(new ::media::DecoderBuffer(16));
83 buffer
->set_timestamp(frame_count_
* base::TimeDelta::FromMilliseconds(
84 kDemuxerStreamForTestFrameDuration
));
86 read_cb
.Run(kOk
, buffer
);
90 } // namespace chromecast