| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "services/media/audio/audio_output.h" | 7 #include "services/media/audio/audio_output.h" |
| 8 #include "services/media/audio/audio_output_manager.h" | 8 #include "services/media/audio/audio_output_manager.h" |
| 9 #include "services/media/audio/audio_server_impl.h" | 9 #include "services/media/audio/audio_server_impl.h" |
| 10 #include "services/media/audio/audio_track_to_output_link.h" | 10 #include "services/media/audio/audio_track_to_output_link.h" |
| 11 #include "services/media/audio/platform/generic/throttle_output.h" | 11 #include "services/media/audio/platform/generic/throttle_output.h" |
| 12 | 12 |
| 13 namespace mojo { | 13 namespace mojo { |
| 14 namespace media { | 14 namespace media { |
| 15 namespace audio { | 15 namespace audio { |
| 16 | 16 |
| 17 static constexpr size_t THREAD_POOL_SZ = 2; | 17 static constexpr size_t THREAD_POOL_SZ = 2; |
| 18 static const std::string THREAD_PREFIX("AudioMixer"); | 18 static const std::string THREAD_PREFIX("AudioMixer"); |
| 19 | 19 |
| 20 // TODO(johngro): This needs to be replaced with a proper HAL |
| 21 extern AudioOutputPtr CreateDefaultAlsaOutput(AudioOutputManager* manager); |
| 22 |
| 20 AudioOutputManager::AudioOutputManager(AudioServerImpl* server) | 23 AudioOutputManager::AudioOutputManager(AudioServerImpl* server) |
| 21 : server_(server) { | 24 : server_(server) { |
| 22 } | 25 } |
| 23 | 26 |
| 24 AudioOutputManager::~AudioOutputManager() { | 27 AudioOutputManager::~AudioOutputManager() { |
| 25 Shutdown(); | 28 Shutdown(); |
| 26 DCHECK_EQ(outputs_.size(), 0u); | 29 DCHECK_EQ(outputs_.size(), 0u); |
| 27 DCHECK(!thread_pool_); | 30 DCHECK(!thread_pool_); |
| 28 } | 31 } |
| 29 | 32 |
| 30 MediaResult AudioOutputManager::Init() { | 33 MediaResult AudioOutputManager::Init() { |
| 31 // Step #1: Initialize the mixing thread pool. | 34 // Step #1: Initialize the mixing thread pool. |
| 32 // | 35 // |
| 33 // TODO(johngro): make the thread pool size proportional to the maximum | 36 // TODO(johngro): make the thread pool size proportional to the maximum |
| 34 // number of cores available in the system. | 37 // number of cores available in the system. |
| 35 // | 38 // |
| 36 // TODO(johngro): make sure that the threads are executed at an elevated | 39 // TODO(johngro): make sure that the threads are executed at an elevated |
| 37 // priority, not the default priority. | 40 // priority, not the default priority. |
| 38 thread_pool_ = new base::SequencedWorkerPool(THREAD_POOL_SZ, THREAD_PREFIX); | 41 thread_pool_ = new base::SequencedWorkerPool(THREAD_POOL_SZ, THREAD_PREFIX); |
| 39 | 42 |
| 40 // Step #2: Instantiate all of the built-in audio output devices. | 43 // Step #2: Instantiate all of the built-in audio output devices. |
| 41 // | 44 // |
| 42 // TODO(johngro): Come up with a better way of doing this based on our | 45 // TODO(johngro): Come up with a better way of doing this based on our |
| 43 // platform. Right now, we just create some hardcoded default outputs and | 46 // platform. Right now, we just create some hardcoded default outputs and |
| 44 // leave it at that. | 47 // leave it at that. |
| 45 outputs_.emplace(audio::ThrottleOutput::New(this)); | 48 outputs_.emplace(audio::ThrottleOutput::New(this)); |
| 49 { |
| 50 AudioOutputPtr alsa = CreateDefaultAlsaOutput(this); |
| 51 if (alsa) { outputs_.emplace(alsa); } |
| 52 } |
| 46 | 53 |
| 47 // Step #3: Being monitoring for plug/unplug events for pluggable audio | 54 // Step #3: Being monitoring for plug/unplug events for pluggable audio |
| 48 // output devices. | 55 // output devices. |
| 49 // | 56 // |
| 50 // TODO(johngro): Implement step #3. Right now, the details are behind | 57 // TODO(johngro): Implement step #3. Right now, the details are behind |
| 51 // hot-plug monitoring are TBD, so the feature is not implemented. | 58 // hot-plug monitoring are TBD, so the feature is not implemented. |
| 52 | 59 |
| 53 // Step #4: Attempt to initialize each of the audio outputs we have created, | 60 // Step #4: Attempt to initialize each of the audio outputs we have created, |
| 54 // then kick off the callback engine for each of them. | 61 // then kick off the callback engine for each of them. |
| 55 for (auto iter = outputs_.begin(); iter != outputs_.end(); ) { | 62 for (auto iter = outputs_.begin(); iter != outputs_.end(); ) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 void AudioOutputManager::ScheduleMessageLoopTask( | 148 void AudioOutputManager::ScheduleMessageLoopTask( |
| 142 const tracked_objects::Location& from_here, | 149 const tracked_objects::Location& from_here, |
| 143 const base::Closure& task) { | 150 const base::Closure& task) { |
| 144 DCHECK(server_); | 151 DCHECK(server_); |
| 145 server_->ScheduleMessageLoopTask(from_here, task); | 152 server_->ScheduleMessageLoopTask(from_here, task); |
| 146 } | 153 } |
| 147 | 154 |
| 148 } // namespace audio | 155 } // namespace audio |
| 149 } // namespace media | 156 } // namespace media |
| 150 } // namespace mojo | 157 } // namespace mojo |
| OLD | NEW |