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 #if defined(OS_LINUX) |
| 13 #include "services/media/audio/platform/linux/alsa_output.h" |
| 14 #endif |
12 | 15 |
13 namespace mojo { | 16 namespace mojo { |
14 namespace media { | 17 namespace media { |
15 namespace audio { | 18 namespace audio { |
16 | 19 |
17 static constexpr size_t THREAD_POOL_SZ = 2; | 20 static constexpr size_t THREAD_POOL_SZ = 2; |
18 static const std::string THREAD_PREFIX("AudioMixer"); | 21 static const std::string THREAD_PREFIX("AudioMixer"); |
19 | 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 |
| 33 void AudioOutputManager::CreateAlsaOutputs() { |
| 34 #if defined(OS_LINUX) |
| 35 // TODO(johngro): Do better than this. If we really want to support |
| 36 // Linux/ALSA as a platform, we should be creating one output for each |
| 37 // physical output in the system, matching our configuration to the physical |
| 38 // output's configuration, and disabling resampling at the ALSA level. |
| 39 // |
| 40 // If we could own the output entirely and bypass the mixer to achieve lower |
| 41 // latency, that would be even better. |
| 42 AudioOutputPtr audio_out(audio::AlsaOutput::New(this)); |
| 43 if (!audio_out) { return; } |
| 44 |
| 45 AlsaOutput* alsa_out = static_cast<AlsaOutput*>(audio_out.get()); |
| 46 DCHECK(alsa_out); |
| 47 |
| 48 LpcmMediaTypeDetailsPtr config(LpcmMediaTypeDetails::New()); |
| 49 config->frames_per_second = 48000; |
| 50 config->samples_per_frame = 2; |
| 51 config->sample_format = LpcmSampleFormat::SIGNED_16; |
| 52 |
| 53 if (alsa_out->Configure(config.Pass()) != MediaResult::OK) { |
| 54 return; |
| 55 } |
| 56 |
| 57 outputs_.emplace(audio_out); |
| 58 #endif |
| 59 } |
| 60 |
30 MediaResult AudioOutputManager::Init() { | 61 MediaResult AudioOutputManager::Init() { |
31 // Step #1: Initialize the mixing thread pool. | 62 // Step #1: Initialize the mixing thread pool. |
32 // | 63 // |
33 // TODO(johngro): make the thread pool size proportional to the maximum | 64 // TODO(johngro): make the thread pool size proportional to the maximum |
34 // number of cores available in the system. | 65 // number of cores available in the system. |
35 // | 66 // |
36 // TODO(johngro): make sure that the threads are executed at an elevated | 67 // TODO(johngro): make sure that the threads are executed at an elevated |
37 // priority, not the default priority. | 68 // priority, not the default priority. |
38 thread_pool_ = new base::SequencedWorkerPool(THREAD_POOL_SZ, THREAD_PREFIX); | 69 thread_pool_ = new base::SequencedWorkerPool(THREAD_POOL_SZ, THREAD_PREFIX); |
39 | 70 |
40 // Step #2: Instantiate all of the built-in audio output devices. | 71 // Step #2: Instantiate all of the built-in audio output devices. |
41 // | 72 // |
42 // TODO(johngro): Come up with a better way of doing this based on our | 73 // 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 | 74 // platform. Right now, we just create some hardcoded default outputs and |
44 // leave it at that. | 75 // leave it at that. |
45 outputs_.emplace(audio::ThrottleOutput::New(this)); | 76 outputs_.emplace(audio::ThrottleOutput::New(this)); |
| 77 CreateAlsaOutputs(); |
46 | 78 |
47 // Step #3: Being monitoring for plug/unplug events for pluggable audio | 79 // Step #3: Being monitoring for plug/unplug events for pluggable audio |
48 // output devices. | 80 // output devices. |
49 // | 81 // |
50 // TODO(johngro): Implement step #3. Right now, the details are behind | 82 // TODO(johngro): Implement step #3. Right now, the details are behind |
51 // hot-plug monitoring are TBD, so the feature is not implemented. | 83 // hot-plug monitoring are TBD, so the feature is not implemented. |
52 | 84 |
53 // Step #4: Attempt to initialize each of the audio outputs we have created, | 85 // Step #4: Attempt to initialize each of the audio outputs we have created, |
54 // then kick off the callback engine for each of them. | 86 // then kick off the callback engine for each of them. |
55 for (auto iter = outputs_.begin(); iter != outputs_.end(); ) { | 87 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( | 173 void AudioOutputManager::ScheduleMessageLoopTask( |
142 const tracked_objects::Location& from_here, | 174 const tracked_objects::Location& from_here, |
143 const base::Closure& task) { | 175 const base::Closure& task) { |
144 DCHECK(server_); | 176 DCHECK(server_); |
145 server_->ScheduleMessageLoopTask(from_here, task); | 177 server_->ScheduleMessageLoopTask(from_here, task); |
146 } | 178 } |
147 | 179 |
148 } // namespace audio | 180 } // namespace audio |
149 } // namespace media | 181 } // namespace media |
150 } // namespace mojo | 182 } // namespace mojo |
OLD | NEW |