OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/linux/audio_manager_linux.h" | 5 #include "media/audio/linux/audio_manager_linux.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "media/audio/fake_audio_input_stream.h" | 9 #include "media/audio/fake_audio_input_stream.h" |
10 #include "media/audio/fake_audio_output_stream.h" | 10 #include "media/audio/fake_audio_output_stream.h" |
| 11 #include "media/audio/linux/alsa_input.h" |
11 #include "media/audio/linux/alsa_output.h" | 12 #include "media/audio/linux/alsa_output.h" |
12 #include "media/audio/linux/alsa_wrapper.h" | 13 #include "media/audio/linux/alsa_wrapper.h" |
| 14 #include "media/base/limits.h" |
13 #include "media/base/media_switches.h" | 15 #include "media/base/media_switches.h" |
14 | 16 |
| 17 namespace { |
| 18 |
| 19 const int kMaxInputChannels = 2; |
| 20 const int kMaxSamplesPerPacket = media::Limits::kMaxSampleRate; |
| 21 |
| 22 } // namespace |
| 23 |
15 // Implementation of AudioManager. | 24 // Implementation of AudioManager. |
16 bool AudioManagerLinux::HasAudioOutputDevices() { | 25 bool AudioManagerLinux::HasAudioOutputDevices() { |
17 // TODO(ajwong): Make this actually query audio devices. | 26 // TODO(ajwong): Make this actually query audio devices. |
18 return true; | 27 return true; |
19 } | 28 } |
20 | 29 |
21 bool AudioManagerLinux::HasAudioInputDevices() { | 30 bool AudioManagerLinux::HasAudioInputDevices() { |
22 // TODO(satish): implement. | 31 // TODO(satish): Make this actually query audio devices. |
23 return false; | 32 return true; |
24 } | 33 } |
25 | 34 |
26 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( | 35 AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( |
27 AudioParameters params) { | 36 AudioParameters params) { |
28 // Early return for testing hook. Do this before checking for | 37 // Early return for testing hook. Do this before checking for |
29 // |initialized_|. | 38 // |initialized_|. |
30 if (params.format == AudioParameters::AUDIO_MOCK) { | 39 if (params.format == AudioParameters::AUDIO_MOCK) { |
31 return FakeAudioOutputStream::MakeFakeStream(); | 40 return FakeAudioOutputStream::MakeFakeStream(); |
32 } | 41 } |
33 | 42 |
34 if (!initialized()) { | 43 if (!initialized()) { |
35 return NULL; | 44 return NULL; |
36 } | 45 } |
37 | 46 |
38 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; | 47 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
39 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaDevice)) { | 48 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 49 switches::kAlsaOutputDevice)) { |
40 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 50 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
41 switches::kAlsaDevice); | 51 switches::kAlsaOutputDevice); |
42 } | 52 } |
43 AlsaPcmOutputStream* stream = | 53 AlsaPcmOutputStream* stream = |
44 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, | 54 new AlsaPcmOutputStream(device_name, params, wrapper_.get(), this, |
45 GetMessageLoop()); | 55 GetMessageLoop()); |
46 | 56 |
47 AutoLock l(lock_); | 57 AutoLock l(lock_); |
48 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); | 58 active_streams_[stream] = scoped_refptr<AlsaPcmOutputStream>(stream); |
49 return stream; | 59 return stream; |
50 } | 60 } |
51 | 61 |
52 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( | 62 AudioInputStream* AudioManagerLinux::MakeAudioInputStream( |
53 AudioParameters params, int samples_per_packet) { | 63 AudioParameters params, int samples_per_packet) { |
| 64 if (!params.IsValid() || params.channels > kMaxInputChannels || |
| 65 samples_per_packet < 0 || samples_per_packet > kMaxSamplesPerPacket) |
| 66 return NULL; |
| 67 |
54 if (params.format == AudioParameters::AUDIO_MOCK) { | 68 if (params.format == AudioParameters::AUDIO_MOCK) { |
55 return FakeAudioInputStream::MakeFakeStream(params, samples_per_packet); | 69 return FakeAudioInputStream::MakeFakeStream(params, samples_per_packet); |
| 70 } else if (params.format != AudioParameters::AUDIO_PCM_LINEAR) { |
| 71 return NULL; |
56 } | 72 } |
57 // TODO(satish): implement. | 73 |
58 return NULL; | 74 if (!initialized()) |
| 75 return NULL; |
| 76 |
| 77 std::string device_name = AlsaPcmOutputStream::kAutoSelectDevice; |
| 78 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAlsaInputDevice)) { |
| 79 device_name = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 80 switches::kAlsaInputDevice); |
| 81 } |
| 82 |
| 83 AlsaPcmInputStream* stream = new AlsaPcmInputStream( |
| 84 device_name, params, samples_per_packet, wrapper_.get()); |
| 85 |
| 86 return stream; |
59 } | 87 } |
60 | 88 |
61 AudioManagerLinux::AudioManagerLinux() { | 89 AudioManagerLinux::AudioManagerLinux() { |
62 } | 90 } |
63 | 91 |
64 AudioManagerLinux::~AudioManagerLinux() { | 92 AudioManagerLinux::~AudioManagerLinux() { |
65 // Make sure we stop the thread first. If we let the default destructor to | 93 // Make sure we stop the thread first. If we let the default destructor to |
66 // destruct the members, we may destroy audio streams before stopping the | 94 // destruct the members, we may destroy audio streams before stopping the |
67 // thread, resulting an unexpected behavior. | 95 // thread, resulting an unexpected behavior. |
68 // This way we make sure activities of the audio streams are all stopped | 96 // This way we make sure activities of the audio streams are all stopped |
(...skipping 19 matching lines...) Expand all Loading... |
88 if (stream) { | 116 if (stream) { |
89 AutoLock l(lock_); | 117 AutoLock l(lock_); |
90 active_streams_.erase(stream); | 118 active_streams_.erase(stream); |
91 } | 119 } |
92 } | 120 } |
93 | 121 |
94 // static | 122 // static |
95 AudioManager* AudioManager::CreateAudioManager() { | 123 AudioManager* AudioManager::CreateAudioManager() { |
96 return new AudioManagerLinux(); | 124 return new AudioManagerLinux(); |
97 } | 125 } |
OLD | NEW |