Chromium Code Reviews| Index: media/audio/audio_system_impl.cc |
| diff --git a/media/audio/audio_system_impl.cc b/media/audio/audio_system_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..35558bb165ece4af789a38e7cb4b11b1eb810560 |
| --- /dev/null |
| +++ b/media/audio/audio_system_impl.cc |
| @@ -0,0 +1,70 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "media/audio/audio_system_impl.h" |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/task_runner_util.h" |
| +#include "media/audio/audio_manager.h" |
| + |
| +// Using base::Unretained for |audio_manager_| is safe since it is deleted after |
| +// its task runner, and AudioSystemImpl is deleted on the UI thread after the IO |
| +// thread has been stopped and before |audio_manager_| deletion is scheduled. |
| +namespace media { |
| + |
| +namespace { |
| + |
| +AudioParameters GetInputParametersOnDeviceThread(AudioManager* audio_manager, |
| + const std::string& device_id) { |
| + DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); |
| + |
| + // TODO(olka) : remove this when AudioManager::GetInputStreamParameters() |
|
tommi (sloooow) - chröme
2017/02/05 20:14:54
nit: TODO(foo):
o1ka
2017/02/06 12:06:08
Done.
|
| + // works this way on all the platforms. |
| + if (!audio_manager->HasAudioInputDevices()) |
| + return AudioParameters(); |
| + |
| + return audio_manager->GetInputStreamParameters(device_id); |
| +} |
| + |
| +} // namespace |
| + |
| +AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager) |
| + : audio_manager_(audio_manager) { |
| + DCHECK(audio_manager_); |
| +} |
| + |
| +AudioSystemImpl::~AudioSystemImpl() {} |
| + |
| +// static |
| +std::unique_ptr<AudioSystem> AudioSystemImpl::Create( |
| + AudioManager* audio_manager) { |
| + return base::WrapUnique(new AudioSystemImpl(audio_manager)); |
| +} |
| + |
| +base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { |
| + return audio_manager_->GetTaskRunner(); |
| +} |
| + |
| +void AudioSystemImpl::GetInputStreamParameters( |
|
tommi (sloooow) - chröme
2017/02/05 20:14:54
is it the intent that this method can be called on
o1ka
2017/02/06 12:06:08
Yes, it can be called from UI and IO threads, and
|
| + const std::string& device_id, |
| + OnAudioParamsCallback on_params_cb) { |
| + if (GetTaskRunner()->BelongsToCurrentThread()) { |
| + GetTaskRunner()->PostTask( |
| + FROM_HERE, base::Bind(on_params_cb, GetInputParametersOnDeviceThread( |
| + audio_manager_, device_id))); |
| + return; |
| + } |
| + base::PostTaskAndReplyWithResult( |
| + GetTaskRunner(), FROM_HERE, |
| + base::Bind(&GetInputParametersOnDeviceThread, |
| + base::Unretained(audio_manager_), device_id), |
| + std::move(on_params_cb)); |
| +} |
| + |
| +AudioManager* AudioSystemImpl::GetAudioManager() { |
| + return audio_manager_; |
| +} |
| + |
| +} // namespace media |