| 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 | |
| 23 // Implementation of AudioManager. | 7 // 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 | |
| 38 bool AudioManagerOpenBSD::HasAudioOutputDevices() { | 8 bool AudioManagerOpenBSD::HasAudioOutputDevices() { |
| 39 return HasAudioHardware(); | 9 NOTIMPLEMENTED(); |
| 10 return false; |
| 40 } | 11 } |
| 41 | 12 |
| 42 bool AudioManagerOpenBSD::HasAudioInputDevices() { | 13 bool AudioManagerOpenBSD::HasAudioInputDevices() { |
| 43 return HasAudioHardware(); | 14 NOTIMPLEMENTED(); |
| 15 return false; |
| 44 } | 16 } |
| 45 | 17 |
| 46 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( | 18 AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( |
| 47 const AudioParameters& params) { | 19 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 | |
| 72 NOTIMPLEMENTED(); | 20 NOTIMPLEMENTED(); |
| 73 return NULL; | 21 return NULL; |
| 74 } | 22 } |
| 75 | 23 |
| 76 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( | 24 AudioInputStream* AudioManagerOpenBSD::MakeAudioInputStream( |
| 77 const AudioParameters& params) { | 25 const AudioParameters& params) { |
| 78 NOTIMPLEMENTED(); | 26 NOTIMPLEMENTED(); |
| 79 return NULL; | 27 return NULL; |
| 80 } | 28 } |
| 81 | 29 |
| 82 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 30 AudioManagerOpenBSD::AudioManagerOpenBSD() { |
| 83 } | 31 } |
| 84 | 32 |
| 85 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 33 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(); | |
| 103 } | 34 } |
| 104 | 35 |
| 105 void AudioManagerOpenBSD::MuteAll() { | 36 void AudioManagerOpenBSD::MuteAll() { |
| 106 NOTIMPLEMENTED(); | 37 NOTIMPLEMENTED(); |
| 107 } | 38 } |
| 108 | 39 |
| 109 void AudioManagerOpenBSD::UnMuteAll() { | 40 void AudioManagerOpenBSD::UnMuteAll() { |
| 110 NOTIMPLEMENTED(); | 41 NOTIMPLEMENTED(); |
| 111 } | 42 } |
| 112 | 43 |
| 113 void AudioManagerOpenBSD::ReleaseOutputStream(AudioOutputStream* stream) { | 44 bool AudioManagerOpenBSD::IsRecordingInProgress() { |
| 114 if (stream) { | 45 NOTIMPLEMENTED(); |
| 115 active_streams_.erase(stream); | 46 return false; |
| 116 delete stream; | |
| 117 } | |
| 118 } | 47 } |
| 119 | 48 |
| 120 // static | 49 // static |
| 121 AudioManager* AudioManager::CreateAudioManager() { | 50 AudioManager* AudioManager::CreateAudioManager() { |
| 122 return new AudioManagerOpenBSD(); | 51 return new AudioManagerOpenBSD(); |
| 123 } | 52 } |
| OLD | NEW |