OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/openbsd/audio_manager_openbsd.h" | 5 #include "media/audio/openbsd/audio_manager_openbsd.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "media/audio/audio_output_dispatcher.h" | 9 #include "media/audio/audio_output_dispatcher.h" |
10 #include "media/audio/fake_audio_input_stream.h" | |
11 #include "media/audio/fake_audio_output_stream.h" | |
12 #if defined(USE_PULSEAUDIO) | 10 #if defined(USE_PULSEAUDIO) |
13 #include "media/audio/pulse/pulse_output.h" | 11 #include "media/audio/pulse/pulse_output.h" |
14 #endif | 12 #endif |
15 #include "media/base/limits.h" | 13 #include "media/base/limits.h" |
16 #include "media/base/media_switches.h" | 14 #include "media/base/media_switches.h" |
17 | 15 |
18 #include <fcntl.h> | 16 #include <fcntl.h> |
19 | 17 |
20 // Maximum number of output streams that can be open simultaneously. | 18 // Maximum number of output streams that can be open simultaneously. |
21 static const size_t kMaxOutputStreams = 50; | 19 static const int kMaxOutputStreams = 50; |
22 | 20 |
23 // Implementation of AudioManager. | 21 // Implementation of AudioManager. |
24 static bool HasAudioHardware() { | 22 static bool HasAudioHardware() { |
25 int fd; | 23 int fd; |
26 const char *file; | 24 const char *file; |
27 | 25 |
28 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') | 26 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') |
29 file = "/dev/audioctl"; | 27 file = "/dev/audioctl"; |
30 | 28 |
31 if ((fd = open(file, O_RDONLY)) < 0) | 29 if ((fd = open(file, O_RDONLY)) < 0) |
32 return false; | 30 return false; |
33 | 31 |
34 close(fd); | 32 close(fd); |
35 return true; | 33 return true; |
36 } | 34 } |
37 | 35 |
38 bool AudioManagerOpenBSD::HasAudioOutputDevices() { | 36 bool AudioManagerOpenBSD::HasAudioOutputDevices() { |
39 return HasAudioHardware(); | 37 return HasAudioHardware(); |
40 } | 38 } |
41 | 39 |
42 bool AudioManagerOpenBSD::HasAudioInputDevices() { | 40 bool AudioManagerOpenBSD::HasAudioInputDevices() { |
43 return HasAudioHardware(); | 41 return HasAudioHardware(); |
44 } | 42 } |
45 | 43 |
46 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( | |
47 const AudioParameters& params) { | |
48 // Early return for testing hook. Do this before checking for | |
49 // |initialized_|. | |
50 if (params.format == AudioParameters::AUDIO_MOCK) { | |
51 return FakeAudioOutputStream::MakeFakeStream(params); | |
52 } | |
53 | |
54 if (!initialized()) { | |
55 return NULL; | |
56 } | |
57 | |
58 // Don't allow opening more than |kMaxOutputStreams| streams. | |
59 if (active_streams_.size() >= kMaxOutputStreams) { | |
60 return NULL; | |
61 } | |
62 | |
63 AudioOutputStream* stream; | |
64 #if defined(USE_PULSEAUDIO) | |
65 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | |
66 stream = new PulseAudioOutputStream(params, this); | |
67 active_streams_.insert(stream); | |
68 return stream; | |
69 } | |
70 #endif | |
71 | |
72 NOTIMPLEMENTED(); | |
73 return NULL; | |
74 } | |
75 | |
76 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( | |
77 const AudioParameters& params, const std::string& device_id) { | |
78 NOTIMPLEMENTED(); | |
79 return NULL; | |
80 } | |
81 | |
82 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 44 AudioManagerOpenBSD::AudioManagerOpenBSD() { |
| 45 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
83 } | 46 } |
84 | 47 |
85 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 48 AudioManagerOpenBSD::~AudioManagerOpenBSD() { |
86 // Make sure we stop the thread first. If we allow the default destructor to | 49 // Make sure we stop the thread first. If we allow the default destructor to |
87 // destroy the members, we may destroy audio streams before stopping the | 50 // destroy the members, we may destroy audio streams before stopping the |
88 // thread, resulting an unexpected behavior. | 51 // thread, resulting an unexpected behavior. |
89 // This way we make sure activities of the audio streams are all stopped | 52 // This way we make sure activities of the audio streams are all stopped |
90 // before we destroy them. | 53 // before we destroy them. |
91 audio_thread_.Stop(); | 54 audio_thread_.Stop(); |
92 | 55 |
93 // Free output dispatchers, closing all remaining open streams. | 56 // Free output dispatchers, closing all remaining open streams. |
94 output_dispatchers_.clear(); | 57 output_dispatchers_.clear(); |
95 | |
96 // Delete all the streams. Have to do it manually, we don't have ScopedSet<>, | |
97 // and we are not using ScopedVector<> because search there is slow. | |
98 STLDeleteElements(&active_streams_); | |
99 } | 58 } |
100 | 59 |
101 void AudioManagerOpenBSD::Init() { | 60 void AudioManagerOpenBSD::Init() { |
102 AudioManagerBase::Init(); | 61 AudioManagerBase::Init(); |
103 } | 62 } |
104 | 63 |
105 void AudioManagerOpenBSD::MuteAll() { | 64 void AudioManagerOpenBSD::MuteAll() { |
106 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
107 } | 66 } |
108 | 67 |
109 void AudioManagerOpenBSD::UnMuteAll() { | 68 void AudioManagerOpenBSD::UnMuteAll() { |
110 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
111 } | 70 } |
112 | 71 |
113 void AudioManagerOpenBSD::ReleaseOutputStream(AudioOutputStream* stream) { | 72 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( |
114 if (stream) { | 73 const AudioParameters& params) { |
115 active_streams_.erase(stream); | 74 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format); |
116 delete stream; | 75 return MakeOutputStream(params); |
| 76 } |
| 77 |
| 78 AudioOutputStream* AudioManagerOpenBSD::MakeLowLatencyOutputStream( |
| 79 const AudioParameters& params) { |
| 80 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format); |
| 81 return MakeOutputStream(params); |
| 82 } |
| 83 |
| 84 AudioInputStream* AudioManagerOpenBSD::MakeLinearInputStream( |
| 85 const AudioParameters& params, const std::string& device_id) { |
| 86 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format); |
| 87 NOTIMPLEMENTED(); |
| 88 return NULL; |
| 89 } |
| 90 |
| 91 AudioInputStream* AudioManagerOpenBSD::MakeLowLatencyInputStream( |
| 92 const AudioParameters& params, const std::string& device_id) { |
| 93 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format); |
| 94 NOTIMPLEMENTED(); |
| 95 return NULL; |
| 96 } |
| 97 |
| 98 AudioOutputStream* AudioManagerOpenBSD::MakeOutputStream( |
| 99 const AudioParameters& params) { |
| 100 if (!initialized()) { |
| 101 return NULL; |
117 } | 102 } |
| 103 |
| 104 #if defined(USE_PULSEAUDIO) |
| 105 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { |
| 106 return new PulseAudioOutputStream(params, this); |
| 107 } |
| 108 #endif |
| 109 |
| 110 NOTIMPLEMENTED(); |
| 111 return NULL; |
118 } | 112 } |
119 | 113 |
120 // static | 114 // static |
121 AudioManager* CreateAudioManager() { | 115 AudioManager* CreateAudioManager() { |
122 return new AudioManagerOpenBSD(); | 116 return new AudioManagerOpenBSD(); |
123 } | 117 } |
OLD | NEW |