| 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 "media/mojo/services/test_mojo_media_client.h" | 5 #include "media/mojo/services/test_mojo_media_client.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "media/audio/audio_device_description.h" | 11 #include "media/audio/audio_device_description.h" |
| 12 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
| 13 #include "media/audio/audio_output_stream_sink.h" | 13 #include "media/audio/audio_output_stream_sink.h" |
| 14 #include "media/base/cdm_factory.h" | 14 #include "media/base/cdm_factory.h" |
| 15 #include "media/base/media.h" | 15 #include "media/base/media.h" |
| 16 #include "media/base/media_log.h" | 16 #include "media/base/media_log.h" |
| 17 #include "media/base/null_video_sink.h" | 17 #include "media/base/null_video_sink.h" |
| 18 #include "media/base/renderer_factory.h" | 18 #include "media/base/renderer_factory.h" |
| 19 #include "media/cdm/default_cdm_factory.h" | 19 #include "media/cdm/default_cdm_factory.h" |
| 20 #include "media/renderers/default_renderer_factory.h" | 20 #include "media/renderers/default_renderer_factory.h" |
| 21 #include "media/renderers/gpu_video_accelerator_factories.h" | 21 #include "media/renderers/gpu_video_accelerator_factories.h" |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 TestMojoMediaClient::TestMojoMediaClient() {} | 25 TestMojoMediaClient::TestMojoMediaClient() {} |
| 26 | 26 |
| 27 TestMojoMediaClient::~TestMojoMediaClient() {} | 27 TestMojoMediaClient::~TestMojoMediaClient() { |
| 28 DVLOG(1) << __FUNCTION__; |
| 29 // AudioManager destructor requires MessageLoop. |
| 30 // Destroy it before the message loop goes away. |
| 31 audio_manager_.reset(); |
| 32 // Flush the message loop to ensure that the audio manager is destroyed. |
| 33 base::RunLoop().RunUntilIdle(); |
| 34 } |
| 28 | 35 |
| 29 void TestMojoMediaClient::Initialize() { | 36 void TestMojoMediaClient::Initialize() { |
| 30 InitializeMediaLibrary(); | 37 InitializeMediaLibrary(); |
| 31 // TODO(dalecurtis): We should find a single owner per process for the audio | 38 // TODO(dalecurtis): We should find a single owner per process for the audio |
| 32 // manager or make it a lazy instance. It's not safe to call Get()/Create() | 39 // manager or make it a lazy instance. It's not safe to call Get()/Create() |
| 33 // across multiple threads... | 40 // across multiple threads... |
| 34 AudioManager* audio_manager = AudioManager::Get(); | 41 AudioManager* audio_manager = AudioManager::Get(); |
| 35 if (!audio_manager) { | 42 if (!audio_manager) { |
| 36 audio_manager_ = media::AudioManager::CreateForTesting( | 43 audio_manager_ = media::AudioManager::CreateForTesting( |
| 37 base::ThreadTaskRunnerHandle::Get()); | 44 base::ThreadTaskRunnerHandle::Get()); |
| 38 audio_manager = audio_manager_.get(); | 45 audio_manager = audio_manager_.get(); |
| 39 // Flush the message loop to ensure that the audio manager is initialized. | 46 // Flush the message loop to ensure that the audio manager is initialized. |
| 40 base::RunLoop().RunUntilIdle(); | 47 base::RunLoop().RunUntilIdle(); |
| 41 } | 48 } |
| 42 | |
| 43 } | |
| 44 | |
| 45 void TestMojoMediaClient::WillQuit() { | |
| 46 DVLOG(1) << __FUNCTION__; | |
| 47 // AudioManager destructor requires MessageLoop. | |
| 48 // Destroy it before the message loop goes away. | |
| 49 audio_manager_.reset(); | |
| 50 // Flush the message loop to ensure that the audio manager is destroyed. | |
| 51 base::RunLoop().RunUntilIdle(); | |
| 52 } | 49 } |
| 53 | 50 |
| 54 scoped_refptr<AudioRendererSink> TestMojoMediaClient::CreateAudioRendererSink( | 51 scoped_refptr<AudioRendererSink> TestMojoMediaClient::CreateAudioRendererSink( |
| 55 const std::string& /* audio_device_id */) { | 52 const std::string& /* audio_device_id */) { |
| 56 return new AudioOutputStreamSink(); | 53 return new AudioOutputStreamSink(); |
| 57 } | 54 } |
| 58 | 55 |
| 59 std::unique_ptr<VideoRendererSink> TestMojoMediaClient::CreateVideoRendererSink( | 56 std::unique_ptr<VideoRendererSink> TestMojoMediaClient::CreateVideoRendererSink( |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 57 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 61 return base::MakeUnique<NullVideoSink>( | 58 return base::MakeUnique<NullVideoSink>( |
| 62 false, base::TimeDelta::FromSecondsD(1.0 / 60), | 59 false, base::TimeDelta::FromSecondsD(1.0 / 60), |
| 63 NullVideoSink::NewFrameCB(), task_runner); | 60 NullVideoSink::NewFrameCB(), task_runner); |
| 64 } | 61 } |
| 65 | 62 |
| 66 std::unique_ptr<RendererFactory> TestMojoMediaClient::CreateRendererFactory( | 63 std::unique_ptr<RendererFactory> TestMojoMediaClient::CreateRendererFactory( |
| 67 const scoped_refptr<MediaLog>& media_log) { | 64 const scoped_refptr<MediaLog>& media_log) { |
| 68 return base::MakeUnique<DefaultRendererFactory>( | 65 return base::MakeUnique<DefaultRendererFactory>( |
| 69 std::move(media_log), nullptr, | 66 std::move(media_log), nullptr, |
| 70 DefaultRendererFactory::GetGpuFactoriesCB()); | 67 DefaultRendererFactory::GetGpuFactoriesCB()); |
| 71 } | 68 } |
| 72 | 69 |
| 73 std::unique_ptr<CdmFactory> TestMojoMediaClient::CreateCdmFactory( | 70 std::unique_ptr<CdmFactory> TestMojoMediaClient::CreateCdmFactory( |
| 74 shell::mojom::InterfaceProvider* /* interface_provider */) { | 71 shell::mojom::InterfaceProvider* /* interface_provider */) { |
| 75 DVLOG(1) << __FUNCTION__; | 72 DVLOG(1) << __FUNCTION__; |
| 76 return base::MakeUnique<DefaultCdmFactory>(); | 73 return base::MakeUnique<DefaultCdmFactory>(); |
| 77 } | 74 } |
| 78 | 75 |
| 79 } // namespace media | 76 } // namespace media |
| OLD | NEW |