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

Side by Side Diff: chromecast/media/cma/backend/audio_video_pipeline_device_unittest.cc

Issue 1257013003: Load CMA backend from shared library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/files/memory_mapped_file.h" 11 #include "base/files/memory_mapped_file.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/path_service.h" 17 #include "base/path_service.h"
18 #include "base/single_thread_task_runner.h" 18 #include "base/single_thread_task_runner.h"
19 #include "base/thread_task_runner_handle.h" 19 #include "base/thread_task_runner_handle.h"
20 #include "base/threading/thread.h" 20 #include "base/threading/thread.h"
21 #include "base/time/time.h" 21 #include "base/time/time.h"
22 #include "chromecast/media/base/decrypt_context.h" 22 #include "chromecast/base/task_runner_impl.h"
23 #include "chromecast/media/cma/backend/audio_pipeline_device.h"
24 #include "chromecast/media/cma/backend/media_clock_device.h"
25 #include "chromecast/media/cma/backend/media_pipeline_device.h"
26 #include "chromecast/media/cma/backend/media_pipeline_device_factory.h"
27 #include "chromecast/media/cma/backend/media_pipeline_device_params.h"
28 #include "chromecast/media/cma/backend/video_pipeline_device.h"
29 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" 23 #include "chromecast/media/cma/base/decoder_buffer_adapter.h"
30 #include "chromecast/media/cma/base/decoder_buffer_base.h"
31 #include "chromecast/media/cma/base/decoder_config_adapter.h" 24 #include "chromecast/media/cma/base/decoder_config_adapter.h"
32 #include "chromecast/media/cma/test/frame_segmenter_for_test.h" 25 #include "chromecast/media/cma/test/frame_segmenter_for_test.h"
33 #include "chromecast/media/cma/test/media_component_device_feeder_for_test.h" 26 #include "chromecast/media/cma/test/media_component_device_feeder_for_test.h"
34 #include "chromecast/public/cast_media_shlib.h" 27 #include "chromecast/public/cast_media_shlib.h"
28 #include "chromecast/public/media/audio_pipeline_device.h"
29 #include "chromecast/public/media/cast_decoder_buffer.h"
35 #include "chromecast/public/media/decoder_config.h" 30 #include "chromecast/public/media/decoder_config.h"
31 #include "chromecast/public/media/media_clock_device.h"
32 #include "chromecast/public/media/media_pipeline_backend.h"
33 #include "chromecast/public/media/media_pipeline_device_params.h"
34 #include "chromecast/public/media/video_pipeline_device.h"
36 #include "media/base/audio_decoder_config.h" 35 #include "media/base/audio_decoder_config.h"
37 #include "media/base/buffers.h" 36 #include "media/base/buffers.h"
38 #include "media/base/decoder_buffer.h" 37 #include "media/base/decoder_buffer.h"
39 #include "media/base/video_decoder_config.h" 38 #include "media/base/video_decoder_config.h"
40 #include "testing/gtest/include/gtest/gtest.h" 39 #include "testing/gtest/include/gtest/gtest.h"
41 40
42 namespace chromecast { 41 namespace chromecast {
43 namespace media { 42 namespace media {
44 43
45 namespace { 44 namespace {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 102
104 void LoadAudioStream(std::string filename); 103 void LoadAudioStream(std::string filename);
105 void LoadVideoStream(std::string filename, bool raw_h264); 104 void LoadVideoStream(std::string filename, bool raw_h264);
106 105
107 void MonitorLoop(); 106 void MonitorLoop();
108 107
109 void OnPauseCompleted(); 108 void OnPauseCompleted();
110 109
111 void OnEos(MediaComponentDeviceFeederForTest* device_feeder); 110 void OnEos(MediaComponentDeviceFeederForTest* device_feeder);
112 111
113 scoped_ptr<MediaPipelineDevice> media_pipeline_device_; 112 scoped_ptr<TaskRunnerImpl> task_runner_;
113 scoped_ptr<MediaPipelineBackend> backend_;
114 MediaClockDevice* media_clock_device_; 114 MediaClockDevice* media_clock_device_;
115 115
116 // Devices to feed 116 // Devices to feed
117 ScopedVector<MediaComponentDeviceFeederForTest> 117 ScopedVector<MediaComponentDeviceFeederForTest>
118 component_device_feeders_; 118 component_device_feeders_;
119 119
120 // Current media time. 120 // Current media time.
121 base::TimeDelta pause_time_; 121 base::TimeDelta pause_time_;
122 122
123 // Pause settings 123 // Pause settings
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 Initialize(); 159 Initialize();
160 LoadVideoStream(filename, false /* raw_h264 */); 160 LoadVideoStream(filename, false /* raw_h264 */);
161 LoadAudioStream(filename); 161 LoadAudioStream(filename);
162 } 162 }
163 163
164 void AudioVideoPipelineDeviceTest::LoadAudioStream(std::string filename) { 164 void AudioVideoPipelineDeviceTest::LoadAudioStream(std::string filename) {
165 base::FilePath file_path = GetTestDataFilePath(filename); 165 base::FilePath file_path = GetTestDataFilePath(filename);
166 DemuxResult demux_result = FFmpegDemuxForTest(file_path, true /* audio */); 166 DemuxResult demux_result = FFmpegDemuxForTest(file_path, true /* audio */);
167 BufferList frames = demux_result.frames; 167 BufferList frames = demux_result.frames;
168 168
169 AudioPipelineDevice* audio_pipeline_device = 169 AudioPipelineDevice* audio_pipeline_device = backend_->GetAudio();
170 media_pipeline_device_->GetAudioPipelineDevice();
171 170
172 bool success = audio_pipeline_device->SetConfig( 171 bool success = audio_pipeline_device->SetConfig(
173 DecoderConfigAdapter::ToCastAudioConfig(kPrimary, 172 DecoderConfigAdapter::ToCastAudioConfig(kPrimary,
174 demux_result.audio_config)); 173 demux_result.audio_config));
175 ASSERT_TRUE(success); 174 ASSERT_TRUE(success);
176 175
177 VLOG(2) << "Got " << frames.size() << " audio input frames"; 176 VLOG(2) << "Got " << frames.size() << " audio input frames";
178 177
179 frames.push_back( 178 frames.push_back(
180 scoped_refptr<DecoderBufferBase>( 179 scoped_refptr<DecoderBufferBase>(
(...skipping 26 matching lines...) Expand all
207 video_config.is_encrypted = false; 206 video_config.is_encrypted = false;
208 } else { 207 } else {
209 base::FilePath file_path = GetTestDataFilePath(filename); 208 base::FilePath file_path = GetTestDataFilePath(filename);
210 DemuxResult demux_result = FFmpegDemuxForTest(file_path, 209 DemuxResult demux_result = FFmpegDemuxForTest(file_path,
211 /*audio*/ false); 210 /*audio*/ false);
212 frames = demux_result.frames; 211 frames = demux_result.frames;
213 video_config = DecoderConfigAdapter::ToCastVideoConfig( 212 video_config = DecoderConfigAdapter::ToCastVideoConfig(
214 kPrimary, demux_result.video_config); 213 kPrimary, demux_result.video_config);
215 } 214 }
216 215
217 VideoPipelineDevice* video_pipeline_device = 216 VideoPipelineDevice* video_pipeline_device = backend_->GetVideo();
218 media_pipeline_device_->GetVideoPipelineDevice();
219 217
220 // Set configuration. 218 // Set configuration.
221 bool success = video_pipeline_device->SetConfig(video_config); 219 bool success = video_pipeline_device->SetConfig(video_config);
222 ASSERT_TRUE(success); 220 ASSERT_TRUE(success);
223 221
224 VLOG(2) << "Got " << frames.size() << " video input frames"; 222 VLOG(2) << "Got " << frames.size() << " video input frames";
225 223
226 frames.push_back( 224 frames.push_back(
227 scoped_refptr<DecoderBufferBase>(new DecoderBufferAdapter( 225 scoped_refptr<DecoderBufferBase>(new DecoderBufferAdapter(
228 ::media::DecoderBuffer::CreateEOSBuffer()))); 226 ::media::DecoderBuffer::CreateEOSBuffer())));
(...skipping 17 matching lines...) Expand all
246 } 244 }
247 245
248 media_clock_device_->SetState(MediaClockDevice::kStateRunning); 246 media_clock_device_->SetState(MediaClockDevice::kStateRunning);
249 247
250 base::ThreadTaskRunnerHandle::Get()->PostTask( 248 base::ThreadTaskRunnerHandle::Get()->PostTask(
251 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop, 249 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop,
252 base::Unretained(this))); 250 base::Unretained(this)));
253 } 251 }
254 252
255 void AudioVideoPipelineDeviceTest::MonitorLoop() { 253 void AudioVideoPipelineDeviceTest::MonitorLoop() {
256 base::TimeDelta media_time = media_clock_device_->GetTime(); 254 base::TimeDelta media_time = base::TimeDelta::FromMicroseconds(
255 media_clock_device_->GetTimeMicroseconds());
257 256
258 if (!pause_pattern_.empty() && 257 if (!pause_pattern_.empty() &&
259 pause_pattern_[pause_pattern_idx_].delay >= base::TimeDelta() && 258 pause_pattern_[pause_pattern_idx_].delay >= base::TimeDelta() &&
260 media_time >= pause_time_ + pause_pattern_[pause_pattern_idx_].delay) { 259 media_time >= pause_time_ + pause_pattern_[pause_pattern_idx_].delay) {
261 // Do Pause 260 // Do Pause
262 media_clock_device_->SetRate(0.0); 261 media_clock_device_->SetRate(0.0);
263 pause_time_ = media_clock_device_->GetTime(); 262 pause_time_ = base::TimeDelta::FromMicroseconds(
263 media_clock_device_->GetTimeMicroseconds());
264 264
265 VLOG(2) << "Pausing at " << pause_time_.InMilliseconds() << "ms for " << 265 VLOG(2) << "Pausing at " << pause_time_.InMilliseconds() << "ms for " <<
266 pause_pattern_[pause_pattern_idx_].length.InMilliseconds() << "ms"; 266 pause_pattern_[pause_pattern_idx_].length.InMilliseconds() << "ms";
267 267
268 // Wait for pause finish 268 // Wait for pause finish
269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
270 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::OnPauseCompleted, 270 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::OnPauseCompleted,
271 base::Unretained(this)), 271 base::Unretained(this)),
272 pause_pattern_[pause_pattern_idx_].length); 272 pause_pattern_[pause_pattern_idx_].length);
273 return; 273 return;
274 } 274 }
275 275
276 // Check state again in a little while 276 // Check state again in a little while
277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
278 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop, 278 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop,
279 base::Unretained(this)), 279 base::Unretained(this)),
280 kMonitorLoopDelay); 280 kMonitorLoopDelay);
281 } 281 }
282 282
283 void AudioVideoPipelineDeviceTest::OnPauseCompleted() { 283 void AudioVideoPipelineDeviceTest::OnPauseCompleted() {
284 // Make sure the media time didn't move during that time. 284 // Make sure the media time didn't move during that time.
285 base::TimeDelta media_time = media_clock_device_->GetTime(); 285 base::TimeDelta media_time = base::TimeDelta::FromMicroseconds(
286 media_clock_device_->GetTimeMicroseconds());
286 287
287 // TODO(damienv): 288 // TODO(damienv):
288 // Should be: 289 // Should be:
289 // EXPECT_EQ(media_time, media_time_); 290 // EXPECT_EQ(media_time, media_time_);
290 // However, some backends, when rendering the first frame while in paused 291 // However, some backends, when rendering the first frame while in paused
291 // mode moves the time forward. 292 // mode moves the time forward.
292 // This behaviour is not intended. 293 // This behaviour is not intended.
293 EXPECT_GE(media_time, pause_time_); 294 EXPECT_GE(media_time, pause_time_);
294 EXPECT_LE(media_time, pause_time_ + base::TimeDelta::FromMilliseconds(50)); 295 EXPECT_LE(media_time, pause_time_ + base::TimeDelta::FromMilliseconds(50));
295 296
(...skipping 19 matching lines...) Expand all
315 } 316 }
316 } 317 }
317 318
318 // Check if all streams finished 319 // Check if all streams finished
319 if (component_device_feeders_.empty()) 320 if (component_device_feeders_.empty())
320 base::MessageLoop::current()->QuitWhenIdle(); 321 base::MessageLoop::current()->QuitWhenIdle();
321 } 322 }
322 323
323 void AudioVideoPipelineDeviceTest::Initialize() { 324 void AudioVideoPipelineDeviceTest::Initialize() {
324 // Create the media device. 325 // Create the media device.
325 MediaPipelineDeviceParams params; 326 task_runner_.reset(new TaskRunnerImpl());
326 scoped_ptr<MediaPipelineDeviceFactory> device_factory = 327 MediaPipelineDeviceParams params(task_runner_.get());
327 GetMediaPipelineDeviceFactory(params); 328 backend_.reset(CastMediaShlib::CreateMediaPipelineBackend(params));
328 media_pipeline_device_.reset(new MediaPipelineDevice(device_factory.Pass())); 329 media_clock_device_ = backend_->GetClock();
329 media_clock_device_ = media_pipeline_device_->GetMediaClockDevice();
330 330
331 // Clock initialization and configuration. 331 // Clock initialization and configuration.
332 bool success = 332 bool success =
333 media_clock_device_->SetState(MediaClockDevice::kStateIdle); 333 media_clock_device_->SetState(MediaClockDevice::kStateIdle);
334 ASSERT_TRUE(success); 334 ASSERT_TRUE(success);
335 success = media_clock_device_->ResetTimeline(base::TimeDelta()); 335 success = media_clock_device_->ResetTimeline(0);
336 ASSERT_TRUE(success); 336 ASSERT_TRUE(success);
337 media_clock_device_->SetRate(1.0); 337 media_clock_device_->SetRate(1.0);
338 } 338 }
339 339
340 TEST_F(AudioVideoPipelineDeviceTest, Mp3Playback) { 340 TEST_F(AudioVideoPipelineDeviceTest, Mp3Playback) {
341 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); 341 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop());
342 342
343 ConfigureForAudioOnly("sfx.mp3"); 343 ConfigureForAudioOnly("sfx.mp3");
344 Start(); 344 Start();
345 message_loop->Run(); 345 message_loop->Run();
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 TEST_F(AudioVideoPipelineDeviceTest, WebmPlayback) { 384 TEST_F(AudioVideoPipelineDeviceTest, WebmPlayback) {
385 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); 385 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop());
386 386
387 ConfigureForFile("bear-640x360.webm"); 387 ConfigureForFile("bear-640x360.webm");
388 Start(); 388 Start();
389 message_loop->Run(); 389 message_loop->Run();
390 } 390 }
391 391
392 } // namespace media 392 } // namespace media
393 } // namespace chromecast 393 } // namespace chromecast
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698