ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / chromecast / media / cma / test / media_component_device_feeder_for_test.cc
blob2c25bc242b599eee42085209b95f680346c30521
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/media_component_device_feeder_for_test.h"
7 #include <list>
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/bind.h"
12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/message_loop/message_loop.h"
16 #include "base/message_loop/message_loop_proxy.h"
17 #include "base/time/time.h"
18 #include "chromecast/media/base/decrypt_context.h"
19 #include "chromecast/media/cma/backend/audio_pipeline_device.h"
20 #include "chromecast/media/cma/backend/media_clock_device.h"
21 #include "chromecast/media/cma/backend/media_pipeline_device.h"
22 #include "chromecast/media/cma/backend/video_pipeline_device.h"
23 #include "chromecast/media/cma/base/decoder_buffer_adapter.h"
24 #include "chromecast/media/cma/base/decoder_buffer_base.h"
25 #include "chromecast/media/cma/test/frame_segmenter_for_test.h"
26 #include "media/base/audio_decoder_config.h"
27 #include "media/base/buffers.h"
28 #include "media/base/decoder_buffer.h"
29 #include "media/base/video_decoder_config.h"
30 #include "testing/gtest/include/gtest/gtest.h"
32 namespace chromecast {
33 namespace media {
35 MediaComponentDeviceFeederForTest::MediaComponentDeviceFeederForTest(
36 MediaComponentDevice *device,
37 const BufferList& frames)
38 : media_component_device_(device),
39 rendering_frame_idx_(1),
40 clock_frame_idx_(1),
41 feeding_completed_(false) {
42 frames_ = frames;
45 MediaComponentDeviceFeederForTest::~MediaComponentDeviceFeederForTest() {
48 void MediaComponentDeviceFeederForTest::Initialize(
49 const base::Closure& eos_cb) {
50 eos_cb_ = eos_cb;
52 MediaComponentDevice::Client client;
53 client.eos_cb =
54 base::Bind(&MediaComponentDeviceFeederForTest::OnEos,
55 base::Unretained(this));
56 media_component_device_->SetClient(client);
58 bool success =
59 media_component_device_->SetState(MediaComponentDevice::kStateIdle);
60 ASSERT_TRUE(success);
61 success = media_component_device_->SetStartPts(base::TimeDelta());
62 ASSERT_TRUE(success);
63 success =
64 media_component_device_->SetState(MediaComponentDevice::kStatePaused);
65 ASSERT_TRUE(success);
68 void MediaComponentDeviceFeederForTest::Feed() {
69 // Start rendering if needed.
70 if (rendering_frame_idx_ == 0) {
71 media_component_device_->SetState(MediaComponentDevice::kStateRunning);
72 } else {
73 rendering_frame_idx_--;
76 // Possibly feed one frame
77 DCHECK(!frames_.empty());
78 scoped_refptr<DecoderBufferBase> buffer = frames_.front();
80 MediaComponentDevice::FrameStatus status =
81 media_component_device_->PushFrame(
82 scoped_refptr<DecryptContext>(),
83 buffer,
84 base::Bind(&MediaComponentDeviceFeederForTest::OnFramePushed,
85 base::Unretained(this)));
86 EXPECT_NE(status, MediaComponentDevice::kFrameFailed);
87 frames_.pop_front();
89 // Feeding is done, just wait for the end of stream callback.
90 if (buffer->end_of_stream() || frames_.empty()) {
91 if (frames_.empty() && !buffer->end_of_stream()) {
92 LOG(WARNING) << "Stream emptied without feeding EOS frame";
95 feeding_completed_ = true;
96 return;
99 if (status == MediaComponentDevice::kFramePending)
100 return;
102 OnFramePushed(MediaComponentDevice::kFrameSuccess);
105 void MediaComponentDeviceFeederForTest::OnFramePushed(
106 MediaComponentDevice::FrameStatus status) {
107 EXPECT_NE(status, MediaComponentDevice::kFrameFailed);
108 if (feeding_completed_)
109 return;
111 base::MessageLoopProxy::current()->PostTask(
112 FROM_HERE,
113 base::Bind(&MediaComponentDeviceFeederForTest::Feed,
114 base::Unretained(this)));
117 void MediaComponentDeviceFeederForTest::OnEos() {
118 bool success = media_component_device_->SetState(
119 MediaComponentDevice::kStateIdle);
120 ASSERT_TRUE(success);
121 success = media_component_device_->SetState(
122 MediaComponentDevice::kStateUninitialized);
123 ASSERT_TRUE(success);
125 if (!eos_cb_.is_null()) {
126 eos_cb_.Run();
130 } // namespace media
131 } // namespace chromecast