Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/audio/audio_system_impl.h" | 5 #include "media/audio/audio_system_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "media/audio/audio_device_description.h" | |
| 10 #include "media/audio/audio_manager.h" | 11 #include "media/audio/audio_manager.h" |
| 11 | 12 |
| 12 // Using base::Unretained for |audio_manager_| is safe since it is deleted after | 13 // Using base::Unretained for |audio_manager_| is safe since it is deleted after |
| 13 // its task runner, and AudioSystemImpl is deleted on the UI thread after the IO | 14 // its task runner, and AudioSystemImpl is deleted on the UI thread after the IO |
| 14 // thread has been stopped and before |audio_manager_| deletion is scheduled. | 15 // thread has been stopped and before |audio_manager_| deletion is scheduled. |
| 15 namespace media { | 16 namespace media { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 AudioParameters GetInputParametersOnDeviceThread(AudioManager* audio_manager, | 20 AudioParameters GetInputParametersOnDeviceThread(AudioManager* audio_manager, |
| 20 const std::string& device_id) { | 21 const std::string& device_id) { |
| 21 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); | 22 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); |
| 22 | 23 |
| 23 // TODO(olka): remove this when AudioManager::GetInputStreamParameters() | 24 // TODO(olka): remove this when AudioManager::GetInputStreamParameters() |
| 24 // works this way on all the platforms. | 25 // works this way on all the platforms. |
| 25 if (!audio_manager->HasAudioInputDevices()) | 26 if (!audio_manager->HasAudioInputDevices()) |
| 26 return AudioParameters(); | 27 return AudioParameters(); |
| 27 | 28 |
| 28 return audio_manager->GetInputStreamParameters(device_id); | 29 return audio_manager->GetInputStreamParameters(device_id); |
| 29 } | 30 } |
| 30 | 31 |
| 32 AudioParameters GetOutputParametersOnDeviceThread( | |
| 33 AudioManager* audio_manager, | |
| 34 const std::string& device_id) { | |
| 35 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); | |
| 36 | |
| 37 // TODO(olka): remove this when | |
| 38 // AudioManager::Get[Default]OutputStreamParameters() works this way on all | |
| 39 // the platforms. | |
|
tommi (sloooow) - chröme
2017/02/14 12:14:26
This covers a particular set of cases but not when
o1ka
2017/02/14 15:00:49
TabAudioCapture are input devices, not output ones
tommi (sloooow) - chröme
2017/02/14 15:30:32
I am aware of that and I didn't say it was output.
o1ka
2017/02/14 15:47:12
You haven't said that you meant both Input and Out
tommi (sloooow) - chröme
2017/02/14 16:30:48
I wasn't talking specifically about either input o
| |
| 40 if (!audio_manager->HasAudioOutputDevices()) | |
| 41 return AudioParameters(); | |
| 42 | |
| 43 return media::AudioDeviceDescription::IsDefaultDevice(device_id) | |
|
o1ka
2017/02/14 11:37:03
guidou@: it seems that all the usecases make this
tommi (sloooow) - chröme
2017/02/14 12:14:26
Doesn't GetOutputStreamParameters already handle t
o1ka
2017/02/14 15:00:49
No, it does not.
One
tommi (sloooow) - chröme
2017/02/14 15:30:32
Uhm, ok, time for fact checking! :)
On Mac and Wi
o1ka
2017/02/14 15:47:12
No, it does not :) Take a look here:
AudioParamete
tommi (sloooow) - chröme
2017/02/14 16:30:48
Windows: https://cs.chromium.org/chromium/src/medi
| |
| 44 ? audio_manager->GetDefaultOutputStreamParameters() | |
| 45 : audio_manager->GetOutputStreamParameters(device_id); | |
| 46 } | |
| 47 | |
| 31 } // namespace | 48 } // namespace |
| 32 | 49 |
| 33 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager) | 50 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager) |
| 34 : audio_manager_(audio_manager) { | 51 : audio_manager_(audio_manager) { |
| 35 DCHECK(audio_manager_); | 52 DCHECK(audio_manager_); |
| 36 AudioSystem::SetInstance(this); | 53 AudioSystem::SetInstance(this); |
| 37 } | 54 } |
| 38 | 55 |
| 39 AudioSystemImpl::~AudioSystemImpl() { | 56 AudioSystemImpl::~AudioSystemImpl() { |
| 40 AudioSystem::ClearInstance(this); | 57 AudioSystem::ClearInstance(this); |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 55 audio_manager_, device_id))); | 72 audio_manager_, device_id))); |
| 56 return; | 73 return; |
| 57 } | 74 } |
| 58 base::PostTaskAndReplyWithResult( | 75 base::PostTaskAndReplyWithResult( |
| 59 GetTaskRunner(), FROM_HERE, | 76 GetTaskRunner(), FROM_HERE, |
| 60 base::Bind(&GetInputParametersOnDeviceThread, | 77 base::Bind(&GetInputParametersOnDeviceThread, |
| 61 base::Unretained(audio_manager_), device_id), | 78 base::Unretained(audio_manager_), device_id), |
| 62 std::move(on_params_cb)); | 79 std::move(on_params_cb)); |
| 63 } | 80 } |
| 64 | 81 |
| 82 void AudioSystemImpl::GetOutputStreamParameters( | |
| 83 const std::string& device_id, | |
| 84 OnAudioParamsCallback on_params_cb) const { | |
| 85 if (GetTaskRunner()->BelongsToCurrentThread()) { | |
| 86 GetTaskRunner()->PostTask( | |
| 87 FROM_HERE, base::Bind(on_params_cb, GetOutputParametersOnDeviceThread( | |
| 88 audio_manager_, device_id))); | |
| 89 return; | |
| 90 } | |
| 91 base::PostTaskAndReplyWithResult( | |
| 92 GetTaskRunner(), FROM_HERE, | |
| 93 base::Bind(&GetOutputParametersOnDeviceThread, | |
| 94 base::Unretained(audio_manager_), device_id), | |
| 95 std::move(on_params_cb)); | |
| 96 } | |
| 97 | |
| 65 void AudioSystemImpl::HasInputDevices(OnBoolCallback on_has_devices_cb) const { | 98 void AudioSystemImpl::HasInputDevices(OnBoolCallback on_has_devices_cb) const { |
| 66 if (GetTaskRunner()->BelongsToCurrentThread()) { | 99 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 67 GetTaskRunner()->PostTask( | 100 GetTaskRunner()->PostTask( |
| 68 FROM_HERE, | 101 FROM_HERE, |
| 69 base::Bind(on_has_devices_cb, audio_manager_->HasAudioInputDevices())); | 102 base::Bind(on_has_devices_cb, audio_manager_->HasAudioInputDevices())); |
| 70 return; | 103 return; |
| 71 } | 104 } |
| 72 base::PostTaskAndReplyWithResult( | 105 base::PostTaskAndReplyWithResult( |
| 73 GetTaskRunner(), FROM_HERE, | 106 GetTaskRunner(), FROM_HERE, |
| 74 base::Bind(&AudioManager::HasAudioInputDevices, | 107 base::Bind(&AudioManager::HasAudioInputDevices, |
| 75 base::Unretained(audio_manager_)), | 108 base::Unretained(audio_manager_)), |
| 76 std::move(on_has_devices_cb)); | 109 std::move(on_has_devices_cb)); |
| 77 } | 110 } |
| 78 | 111 |
| 79 AudioManager* AudioSystemImpl::GetAudioManager() const { | 112 AudioManager* AudioSystemImpl::GetAudioManager() const { |
| 80 return audio_manager_; | 113 return audio_manager_; |
| 81 } | 114 } |
| 82 | 115 |
| 83 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { | 116 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { |
| 84 return audio_manager_->GetTaskRunner(); | 117 return audio_manager_->GetTaskRunner(); |
| 85 } | 118 } |
| 86 | 119 |
| 87 } // namespace media | 120 } // namespace media |
| OLD | NEW |