Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1216)

Side by Side Diff: chromecast/media/cma/test/media_component_device_feeder_for_test.cc

Issue 622853002: Chromecast: adds interfaces for hardware layer of CMA pipeline. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cma-decrypt-context
Patch Set: updates test, addresses damien's feedback Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/test/media_component_device_feeder_for_test.h"
6
7 #include <list>
8 #include <vector>
9
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"
31
32 namespace chromecast {
33 namespace media {
34
35 MediaComponentDeviceFeederForTest::MediaComponentDeviceFeederForTest(
36 MediaComponentDevice *device,
37 const FrameList& frames,
38 base::Callback<void(MediaComponentDeviceFeederForTest *)> eos_cb)
39 : media_component_device_(device),
40 rendering_frame_idx_(1),
41 clock_frame_idx_(1),
42 eos_cb_(eos_cb),
43 feeding_completed_(false),
44 delayed_feed_pattern_() {
45 // Copy pointers over, claiming ownership on buffers
46 frames_ = frames;
47 }
48
49 MediaComponentDeviceFeederForTest::~MediaComponentDeviceFeederForTest() {
50 }
51
52 // Accessors
53 void MediaComponentDeviceFeederForTest::SetDelayedFeedPattern(
54 const std::vector<base::TimeDelta>& pattern) {
55 // Copy pattern over
56 delayed_feed_pattern_ = pattern;
57 }
58
59 void MediaComponentDeviceFeederForTest::Initialize() {
60 MediaComponentDevice::Client client;
61 client.eos_cb =
62 base::Bind(&MediaComponentDeviceFeederForTest::OnEos,
63 base::Unretained(this));
64 media_component_device_->SetClient(client);
65
66 bool success =
67 media_component_device_->SetState(MediaComponentDevice::kStateIdle);
68 ASSERT_TRUE(success);
69 success = media_component_device_->SetStartPts(base::TimeDelta());
70 ASSERT_TRUE(success);
71 success =
72 media_component_device_->SetState(MediaComponentDevice::kStatePaused);
73 ASSERT_TRUE(success);
74 }
75
76 void MediaComponentDeviceFeederForTest::Feed() {
77 // Start rendering if needed.
78 if (rendering_frame_idx_ == 0) {
79 media_component_device_->SetState(MediaComponentDevice::kStateRunning);
80 } else {
81 rendering_frame_idx_--;
82 }
83
84 // Possibly feed one frame
85 DCHECK(!frames_.empty());
86 scoped_refptr<DecoderBufferBase> buffer = frames_.front();
87
88 MediaComponentDevice::FrameStatus status =
89 media_component_device_->PushFrame(
90 scoped_refptr<DecryptContext>(),
91 buffer,
92 base::Bind(&MediaComponentDeviceFeederForTest::OnFramePushed,
93 base::Unretained(this)));
94 EXPECT_NE(status, MediaComponentDevice::kFrameFailed);
95 frames_.pop_front();
96
97 // Feeding is done, just wait for the end of stream callback.
98 if (buffer->end_of_stream() || frames_.empty()) {
99 if (frames_.empty() && !buffer->end_of_stream()) {
100 LOG(WARNING) << "Stream emptied without feeding EOS frame";
101 }
102
103 feeding_completed_ = true;
104 return;
105 }
106
107 if (status == MediaComponentDevice::kFramePending)
108 return;
109
110 OnFramePushed(MediaComponentDevice::kFrameSuccess);
111 }
112
113 void MediaComponentDeviceFeederForTest::OnFramePushed(
114 MediaComponentDevice::FrameStatus status) {
115 EXPECT_NE(status, MediaComponentDevice::kFrameFailed);
116 if (feeding_completed_)
117 return;
118
119 // Delayed feed setup
120 base::TimeDelta feed_delay = base::TimeDelta();
121 if (!delayed_feed_pattern_.empty()) {
122 feed_delay = delayed_feed_pattern_[delayed_feed_pattern_idx_];
123 delayed_feed_pattern_idx_ =
124 (delayed_feed_pattern_idx_ + 1) % delayed_feed_pattern_.size();
125 }
126
127 if (feed_delay != base::TimeDelta()) {
128 // Wait feed_delay
129 base::MessageLoopProxy::current()->PostDelayedTask(
130 FROM_HERE,
131 base::Bind(&MediaComponentDeviceFeederForTest::Feed,
132 base::Unretained(this)),
133 feed_delay);
134 } else {
135 // Wait time is 0. Append to task queue
136 base::MessageLoopProxy::current()->PostTask(
137 FROM_HERE,
138 base::Bind(&MediaComponentDeviceFeederForTest::Feed,
139 base::Unretained(this)));
140 }
141 }
142
143 void MediaComponentDeviceFeederForTest::OnEos() {
144 // Shutdown the pipeline.
145 bool success = media_component_device_->SetState(
146 MediaComponentDevice::kStateIdle);
147 ASSERT_TRUE(success);
148 success = media_component_device_->SetState(
149 MediaComponentDevice::kStateUninitialized);
150 ASSERT_TRUE(success);
151
152 if (!eos_cb_.is_null()) {
153 eos_cb_.Run(this);
154 }
155 }
156
157 } // namespace media
158 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698