| OLD | NEW |
| 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" | 23 #include "chromecast/base/time_conversions.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" | 24 #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" | 25 #include "chromecast/media/cma/base/decoder_config_adapter.h" |
| 32 #include "chromecast/media/cma/test/frame_segmenter_for_test.h" | 26 #include "chromecast/media/cma/test/frame_segmenter_for_test.h" |
| 33 #include "chromecast/media/cma/test/media_component_device_feeder_for_test.h" | 27 #include "chromecast/media/cma/test/media_component_device_feeder_for_test.h" |
| 34 #include "chromecast/public/cast_media_shlib.h" | 28 #include "chromecast/public/cast_media_shlib.h" |
| 29 #include "chromecast/public/media/audio_pipeline_device.h" |
| 30 #include "chromecast/public/media/decoder_buffer.h" |
| 35 #include "chromecast/public/media/decoder_config.h" | 31 #include "chromecast/public/media/decoder_config.h" |
| 32 #include "chromecast/public/media/media_clock_device.h" |
| 33 #include "chromecast/public/media/media_pipeline_backend.h" |
| 34 #include "chromecast/public/media/media_pipeline_device_params.h" |
| 35 #include "chromecast/public/media/video_pipeline_device.h" |
| 36 #include "media/base/audio_decoder_config.h" | 36 #include "media/base/audio_decoder_config.h" |
| 37 #include "media/base/buffers.h" | 37 #include "media/base/buffers.h" |
| 38 #include "media/base/decoder_buffer.h" | 38 #include "media/base/decoder_buffer.h" |
| 39 #include "media/base/video_decoder_config.h" | 39 #include "media/base/video_decoder_config.h" |
| 40 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
| 41 | 41 |
| 42 namespace chromecast { | 42 namespace chromecast { |
| 43 namespace media { | 43 namespace media { |
| 44 | 44 |
| 45 namespace { | 45 namespace { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 | 103 |
| 104 void LoadAudioStream(std::string filename); | 104 void LoadAudioStream(std::string filename); |
| 105 void LoadVideoStream(std::string filename, bool raw_h264); | 105 void LoadVideoStream(std::string filename, bool raw_h264); |
| 106 | 106 |
| 107 void MonitorLoop(); | 107 void MonitorLoop(); |
| 108 | 108 |
| 109 void OnPauseCompleted(); | 109 void OnPauseCompleted(); |
| 110 | 110 |
| 111 void OnEos(MediaComponentDeviceFeederForTest* device_feeder); | 111 void OnEos(MediaComponentDeviceFeederForTest* device_feeder); |
| 112 | 112 |
| 113 scoped_ptr<MediaPipelineDevice> media_pipeline_device_; | 113 scoped_ptr<TaskRunner> task_runner_; |
| 114 scoped_ptr<MediaPipelineBackend> backend_; |
| 114 MediaClockDevice* media_clock_device_; | 115 MediaClockDevice* media_clock_device_; |
| 115 | 116 |
| 116 // Devices to feed | 117 // Devices to feed |
| 117 ScopedVector<MediaComponentDeviceFeederForTest> | 118 ScopedVector<MediaComponentDeviceFeederForTest> |
| 118 component_device_feeders_; | 119 component_device_feeders_; |
| 119 | 120 |
| 120 // Current media time. | 121 // Current media time. |
| 121 base::TimeDelta pause_time_; | 122 base::TimeDelta pause_time_; |
| 122 | 123 |
| 123 // Pause settings | 124 // Pause settings |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 Initialize(); | 160 Initialize(); |
| 160 LoadVideoStream(filename, false /* raw_h264 */); | 161 LoadVideoStream(filename, false /* raw_h264 */); |
| 161 LoadAudioStream(filename); | 162 LoadAudioStream(filename); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void AudioVideoPipelineDeviceTest::LoadAudioStream(std::string filename) { | 165 void AudioVideoPipelineDeviceTest::LoadAudioStream(std::string filename) { |
| 165 base::FilePath file_path = GetTestDataFilePath(filename); | 166 base::FilePath file_path = GetTestDataFilePath(filename); |
| 166 DemuxResult demux_result = FFmpegDemuxForTest(file_path, true /* audio */); | 167 DemuxResult demux_result = FFmpegDemuxForTest(file_path, true /* audio */); |
| 167 BufferList frames = demux_result.frames; | 168 BufferList frames = demux_result.frames; |
| 168 | 169 |
| 169 AudioPipelineDevice* audio_pipeline_device = | 170 AudioPipelineDevice* audio_pipeline_device = backend_->GetAudio(); |
| 170 media_pipeline_device_->GetAudioPipelineDevice(); | |
| 171 | 171 |
| 172 bool success = audio_pipeline_device->SetConfig( | 172 bool success = audio_pipeline_device->SetConfig( |
| 173 DecoderConfigAdapter::ToCastAudioConfig(kPrimary, | 173 DecoderConfigAdapter::ToCastAudioConfig(kPrimary, |
| 174 demux_result.audio_config)); | 174 demux_result.audio_config)); |
| 175 ASSERT_TRUE(success); | 175 ASSERT_TRUE(success); |
| 176 | 176 |
| 177 VLOG(2) << "Got " << frames.size() << " audio input frames"; | 177 VLOG(2) << "Got " << frames.size() << " audio input frames"; |
| 178 | 178 |
| 179 frames.push_back( | 179 frames.push_back( |
| 180 scoped_refptr<DecoderBufferBase>( | 180 scoped_refptr<DecoderBufferBase>( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 207 video_config.is_encrypted = false; | 207 video_config.is_encrypted = false; |
| 208 } else { | 208 } else { |
| 209 base::FilePath file_path = GetTestDataFilePath(filename); | 209 base::FilePath file_path = GetTestDataFilePath(filename); |
| 210 DemuxResult demux_result = FFmpegDemuxForTest(file_path, | 210 DemuxResult demux_result = FFmpegDemuxForTest(file_path, |
| 211 /*audio*/ false); | 211 /*audio*/ false); |
| 212 frames = demux_result.frames; | 212 frames = demux_result.frames; |
| 213 video_config = DecoderConfigAdapter::ToCastVideoConfig( | 213 video_config = DecoderConfigAdapter::ToCastVideoConfig( |
| 214 kPrimary, demux_result.video_config); | 214 kPrimary, demux_result.video_config); |
| 215 } | 215 } |
| 216 | 216 |
| 217 VideoPipelineDevice* video_pipeline_device = | 217 VideoPipelineDevice* video_pipeline_device = backend_->GetVideo(); |
| 218 media_pipeline_device_->GetVideoPipelineDevice(); | |
| 219 | 218 |
| 220 // Set configuration. | 219 // Set configuration. |
| 221 bool success = video_pipeline_device->SetConfig(video_config); | 220 bool success = video_pipeline_device->SetConfig(video_config); |
| 222 ASSERT_TRUE(success); | 221 ASSERT_TRUE(success); |
| 223 | 222 |
| 224 VLOG(2) << "Got " << frames.size() << " video input frames"; | 223 VLOG(2) << "Got " << frames.size() << " video input frames"; |
| 225 | 224 |
| 226 frames.push_back( | 225 frames.push_back( |
| 227 scoped_refptr<DecoderBufferBase>(new DecoderBufferAdapter( | 226 scoped_refptr<DecoderBufferBase>(new DecoderBufferAdapter( |
| 228 ::media::DecoderBuffer::CreateEOSBuffer()))); | 227 ::media::DecoderBuffer::CreateEOSBuffer()))); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 246 } | 245 } |
| 247 | 246 |
| 248 media_clock_device_->SetState(MediaClockDevice::kStateRunning); | 247 media_clock_device_->SetState(MediaClockDevice::kStateRunning); |
| 249 | 248 |
| 250 base::ThreadTaskRunnerHandle::Get()->PostTask( | 249 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 251 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop, | 250 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop, |
| 252 base::Unretained(this))); | 251 base::Unretained(this))); |
| 253 } | 252 } |
| 254 | 253 |
| 255 void AudioVideoPipelineDeviceTest::MonitorLoop() { | 254 void AudioVideoPipelineDeviceTest::MonitorLoop() { |
| 256 base::TimeDelta media_time = media_clock_device_->GetTime(); | 255 base::TimeDelta media_time = ToBaseTimeDelta(media_clock_device_->GetTime()); |
| 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_ = ToBaseTimeDelta(media_clock_device_->GetTime()); |
| 264 | 263 |
| 265 VLOG(2) << "Pausing at " << pause_time_.InMilliseconds() << "ms for " << | 264 VLOG(2) << "Pausing at " << pause_time_.InMilliseconds() << "ms for " << |
| 266 pause_pattern_[pause_pattern_idx_].length.InMilliseconds() << "ms"; | 265 pause_pattern_[pause_pattern_idx_].length.InMilliseconds() << "ms"; |
| 267 | 266 |
| 268 // Wait for pause finish | 267 // Wait for pause finish |
| 269 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 268 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 270 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::OnPauseCompleted, | 269 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::OnPauseCompleted, |
| 271 base::Unretained(this)), | 270 base::Unretained(this)), |
| 272 pause_pattern_[pause_pattern_idx_].length); | 271 pause_pattern_[pause_pattern_idx_].length); |
| 273 return; | 272 return; |
| 274 } | 273 } |
| 275 | 274 |
| 276 // Check state again in a little while | 275 // Check state again in a little while |
| 277 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 276 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 278 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop, | 277 FROM_HERE, base::Bind(&AudioVideoPipelineDeviceTest::MonitorLoop, |
| 279 base::Unretained(this)), | 278 base::Unretained(this)), |
| 280 kMonitorLoopDelay); | 279 kMonitorLoopDelay); |
| 281 } | 280 } |
| 282 | 281 |
| 283 void AudioVideoPipelineDeviceTest::OnPauseCompleted() { | 282 void AudioVideoPipelineDeviceTest::OnPauseCompleted() { |
| 284 // Make sure the media time didn't move during that time. | 283 // Make sure the media time didn't move during that time. |
| 285 base::TimeDelta media_time = media_clock_device_->GetTime(); | 284 base::TimeDelta media_time = ToBaseTimeDelta(media_clock_device_->GetTime()); |
| 286 | 285 |
| 287 // TODO(damienv): | 286 // TODO(damienv): |
| 288 // Should be: | 287 // Should be: |
| 289 // EXPECT_EQ(media_time, media_time_); | 288 // EXPECT_EQ(media_time, media_time_); |
| 290 // However, some backends, when rendering the first frame while in paused | 289 // However, some backends, when rendering the first frame while in paused |
| 291 // mode moves the time forward. | 290 // mode moves the time forward. |
| 292 // This behaviour is not intended. | 291 // This behaviour is not intended. |
| 293 EXPECT_GE(media_time, pause_time_); | 292 EXPECT_GE(media_time, pause_time_); |
| 294 EXPECT_LE(media_time, pause_time_ + base::TimeDelta::FromMilliseconds(50)); | 293 EXPECT_LE(media_time, pause_time_ + base::TimeDelta::FromMilliseconds(50)); |
| 295 | 294 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 315 } | 314 } |
| 316 } | 315 } |
| 317 | 316 |
| 318 // Check if all streams finished | 317 // Check if all streams finished |
| 319 if (component_device_feeders_.empty()) | 318 if (component_device_feeders_.empty()) |
| 320 base::MessageLoop::current()->QuitWhenIdle(); | 319 base::MessageLoop::current()->QuitWhenIdle(); |
| 321 } | 320 } |
| 322 | 321 |
| 323 void AudioVideoPipelineDeviceTest::Initialize() { | 322 void AudioVideoPipelineDeviceTest::Initialize() { |
| 324 // Create the media device. | 323 // Create the media device. |
| 325 MediaPipelineDeviceParams params; | 324 task_runner_.reset(new TaskRunnerImpl()); |
| 326 scoped_ptr<MediaPipelineDeviceFactory> device_factory = | 325 MediaPipelineDeviceParams params(task_runner_.get()); |
| 327 GetMediaPipelineDeviceFactory(params); | 326 backend_.reset(CastMediaShlib::CreateMediaPipelineBackend(params)); |
| 328 media_pipeline_device_.reset(new MediaPipelineDevice(device_factory.Pass())); | 327 media_clock_device_ = backend_->GetClock(); |
| 329 media_clock_device_ = media_pipeline_device_->GetMediaClockDevice(); | |
| 330 | 328 |
| 331 // Clock initialization and configuration. | 329 // Clock initialization and configuration. |
| 332 bool success = | 330 bool success = |
| 333 media_clock_device_->SetState(MediaClockDevice::kStateIdle); | 331 media_clock_device_->SetState(MediaClockDevice::kStateIdle); |
| 334 ASSERT_TRUE(success); | 332 ASSERT_TRUE(success); |
| 335 success = media_clock_device_->ResetTimeline(base::TimeDelta()); | 333 success = media_clock_device_->ResetTimeline(TimeDelta()); |
| 336 ASSERT_TRUE(success); | 334 ASSERT_TRUE(success); |
| 337 media_clock_device_->SetRate(1.0); | 335 media_clock_device_->SetRate(1.0); |
| 338 } | 336 } |
| 339 | 337 |
| 340 TEST_F(AudioVideoPipelineDeviceTest, Mp3Playback) { | 338 TEST_F(AudioVideoPipelineDeviceTest, Mp3Playback) { |
| 341 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); | 339 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); |
| 342 | 340 |
| 343 ConfigureForAudioOnly("sfx.mp3"); | 341 ConfigureForAudioOnly("sfx.mp3"); |
| 344 Start(); | 342 Start(); |
| 345 message_loop->Run(); | 343 message_loop->Run(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 TEST_F(AudioVideoPipelineDeviceTest, WebmPlayback) { | 382 TEST_F(AudioVideoPipelineDeviceTest, WebmPlayback) { |
| 385 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); | 383 scoped_ptr<base::MessageLoop> message_loop(new base::MessageLoop()); |
| 386 | 384 |
| 387 ConfigureForFile("bear-640x360.webm"); | 385 ConfigureForFile("bear-640x360.webm"); |
| 388 Start(); | 386 Start(); |
| 389 message_loop->Run(); | 387 message_loop->Run(); |
| 390 } | 388 } |
| 391 | 389 |
| 392 } // namespace media | 390 } // namespace media |
| 393 } // namespace chromecast | 391 } // namespace chromecast |
| OLD | NEW |