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" |
| 8 #include "base/stl_util.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) |
| 13 #include "media/audio/pulse/pulse_output.h" |
| 14 #endif |
| 15 #include "media/base/limits.h" |
| 16 #include "media/base/media_switches.h" |
| 17 |
| 18 #include <fcntl.h> |
| 19 |
| 20 // Maximum number of output streams that can be open simultaneously. |
| 21 static const size_t kMaxOutputStreams = 50; |
| 22 |
7 // Implementation of AudioManager. | 23 // Implementation of AudioManager. |
| 24 static bool HasAudioHardware() { |
| 25 int fd; |
| 26 const char *file; |
| 27 |
| 28 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') |
| 29 file = "/dev/audioctl"; |
| 30 |
| 31 if ((fd = open(file, O_RDONLY)) < 0) |
| 32 return false; |
| 33 |
| 34 close(fd); |
| 35 return true; |
| 36 } |
| 37 |
8 bool AudioManagerOpenBSD::HasAudioOutputDevices() { | 38 bool AudioManagerOpenBSD::HasAudioOutputDevices() { |
9 NOTIMPLEMENTED(); | 39 return HasAudioHardware(); |
10 return false; | |
11 } | 40 } |
12 | 41 |
13 bool AudioManagerOpenBSD::HasAudioInputDevices() { | 42 bool AudioManagerOpenBSD::HasAudioInputDevices() { |
14 NOTIMPLEMENTED(); | 43 return HasAudioHardware(); |
15 return false; | |
16 } | 44 } |
17 | 45 |
18 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( | 46 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( |
19 const AudioParameters& params) { | 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, GetMessageLoop()); |
| 67 active_streams_.insert(stream); |
| 68 return stream; |
| 69 } |
| 70 #endif |
| 71 |
20 NOTIMPLEMENTED(); | 72 NOTIMPLEMENTED(); |
21 return NULL; | 73 return NULL; |
22 } | 74 } |
23 | 75 |
24 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( | 76 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( |
25 const AudioParameters& params) { | 77 const AudioParameters& params) { |
26 NOTIMPLEMENTED(); | 78 NOTIMPLEMENTED(); |
27 return NULL; | 79 return NULL; |
28 } | 80 } |
29 | 81 |
30 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 82 AudioManagerOpenBSD::AudioManagerOpenBSD() { |
31 } | 83 } |
32 | 84 |
33 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 85 AudioManagerOpenBSD::~AudioManagerOpenBSD() { |
| 86 // 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 |
| 88 // thread, resulting an unexpected behavior. |
| 89 // This way we make sure activities of the audio streams are all stopped |
| 90 // before we destroy them. |
| 91 audio_thread_.Stop(); |
| 92 |
| 93 // Free output dispatchers, closing all remaining open streams. |
| 94 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 } |
| 100 |
| 101 void AudioManagerOpenBSD::Init() { |
| 102 AudioManagerBase::Init(); |
34 } | 103 } |
35 | 104 |
36 void AudioManagerOpenBSD::MuteAll() { | 105 void AudioManagerOpenBSD::MuteAll() { |
37 NOTIMPLEMENTED(); | 106 NOTIMPLEMENTED(); |
38 } | 107 } |
39 | 108 |
40 void AudioManagerOpenBSD::UnMuteAll() { | 109 void AudioManagerOpenBSD::UnMuteAll() { |
41 NOTIMPLEMENTED(); | 110 NOTIMPLEMENTED(); |
42 } | 111 } |
43 | 112 |
44 bool AudioManagerOpenBSD::IsRecordingInProgress() { | 113 void AudioManagerOpenBSD::ReleaseOutputStream(AudioOutputStream* stream) { |
45 NOTIMPLEMENTED(); | 114 if (stream) { |
46 return false; | 115 active_streams_.erase(stream); |
| 116 delete stream; |
| 117 } |
47 } | 118 } |
48 | 119 |
49 // static | 120 // static |
50 AudioManager* AudioManager::CreateAudioManager() { | 121 AudioManager* AudioManager::CreateAudioManager() { |
51 return new AudioManagerOpenBSD(); | 122 return new AudioManagerOpenBSD(); |
52 } | 123 } |
OLD | NEW |