summaryrefslogtreecommitdiffstats
path: root/media/audio/openbsd
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 22:49:39 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-17 22:49:39 +0000
commita1ced36bfe270857f9e73c19338817be40d86720 (patch)
treeb46ef6b018746a8ad2f6e4a501c1f4657fe239dd /media/audio/openbsd
parent3ab4c0af18aa95289f7d97da690e112a0cba8c77 (diff)
downloadchromium_src-a1ced36bfe270857f9e73c19338817be40d86720.zip
chromium_src-a1ced36bfe270857f9e73c19338817be40d86720.tar.gz
chromium_src-a1ced36bfe270857f9e73c19338817be40d86720.tar.bz2
Make pulseaudio available for all posix platforms and add support on OpenBSD.
Patch by robert.nagy@gmail.com: http://codereview.chromium.org/8499029/ git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110584 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/openbsd')
-rw-r--r--media/audio/openbsd/audio_manager_openbsd.cc85
-rw-r--r--media/audio/openbsd/audio_manager_openbsd.h22
2 files changed, 94 insertions, 13 deletions
diff --git a/media/audio/openbsd/audio_manager_openbsd.cc b/media/audio/openbsd/audio_manager_openbsd.cc
index cb18768..02ce592 100644
--- a/media/audio/openbsd/audio_manager_openbsd.cc
+++ b/media/audio/openbsd/audio_manager_openbsd.cc
@@ -4,19 +4,71 @@
#include "media/audio/openbsd/audio_manager_openbsd.h"
+#include "base/command_line.h"
+#include "base/stl_util.h"
+#include "media/audio/audio_output_dispatcher.h"
+#include "media/audio/fake_audio_input_stream.h"
+#include "media/audio/fake_audio_output_stream.h"
+#if defined(USE_PULSEAUDIO)
+#include "media/audio/pulse/pulse_output.h"
+#endif
+#include "media/base/limits.h"
+#include "media/base/media_switches.h"
+
+#include <fcntl.h>
+
+// Maximum number of output streams that can be open simultaneously.
+static const size_t kMaxOutputStreams = 50;
+
// Implementation of AudioManager.
+static bool HasAudioHardware() {
+ int fd;
+ const char *file;
+
+ if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0')
+ file = "/dev/audioctl";
+
+ if ((fd = open(file, O_RDONLY)) < 0)
+ return false;
+
+ close(fd);
+ return true;
+}
+
bool AudioManagerOpenBSD::HasAudioOutputDevices() {
- NOTIMPLEMENTED();
- return false;
+ return HasAudioHardware();
}
bool AudioManagerOpenBSD::HasAudioInputDevices() {
- NOTIMPLEMENTED();
- return false;
+ return HasAudioHardware();
}
AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream(
const AudioParameters& params) {
+ // Early return for testing hook. Do this before checking for
+ // |initialized_|.
+ if (params.format == AudioParameters::AUDIO_MOCK) {
+ return FakeAudioOutputStream::MakeFakeStream(params);
+ }
+
+ if (!initialized()) {
+ return NULL;
+ }
+
+ // Don't allow opening more than |kMaxOutputStreams| streams.
+ if (active_streams_.size() >= kMaxOutputStreams) {
+ return NULL;
+ }
+
+ AudioOutputStream* stream;
+#if defined(USE_PULSEAUDIO)
+ if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
+ stream = new PulseAudioOutputStream(params, this, GetMessageLoop());
+ active_streams_.insert(stream);
+ return stream;
+ }
+#endif
+
NOTIMPLEMENTED();
return NULL;
}
@@ -31,6 +83,23 @@ AudioManagerOpenBSD::AudioManagerOpenBSD() {
}
AudioManagerOpenBSD::~AudioManagerOpenBSD() {
+ // Make sure we stop the thread first. If we allow the default destructor to
+ // destroy the members, we may destroy audio streams before stopping the
+ // thread, resulting an unexpected behavior.
+ // This way we make sure activities of the audio streams are all stopped
+ // before we destroy them.
+ audio_thread_.Stop();
+
+ // Free output dispatchers, closing all remaining open streams.
+ output_dispatchers_.clear();
+
+ // Delete all the streams. Have to do it manually, we don't have ScopedSet<>,
+ // and we are not using ScopedVector<> because search there is slow.
+ STLDeleteElements(&active_streams_);
+}
+
+void AudioManagerOpenBSD::Init() {
+ AudioManagerBase::Init();
}
void AudioManagerOpenBSD::MuteAll() {
@@ -41,9 +110,11 @@ void AudioManagerOpenBSD::UnMuteAll() {
NOTIMPLEMENTED();
}
-bool AudioManagerOpenBSD::IsRecordingInProgress() {
- NOTIMPLEMENTED();
- return false;
+void AudioManagerOpenBSD::ReleaseOutputStream(AudioOutputStream* stream) {
+ if (stream) {
+ active_streams_.erase(stream);
+ delete stream;
+ }
}
// static
diff --git a/media/audio/openbsd/audio_manager_openbsd.h b/media/audio/openbsd/audio_manager_openbsd.h
index b9f19c6..e768524 100644
--- a/media/audio/openbsd/audio_manager_openbsd.h
+++ b/media/audio/openbsd/audio_manager_openbsd.h
@@ -5,27 +5,37 @@
#ifndef MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
#define MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_
-#include "base/basictypes.h"
+#include <set>
+
+#include "base/compiler_specific.h"
#include "media/audio/audio_manager_base.h"
-class AudioManagerOpenBSD : public AudioManagerBase {
+class MEDIA_EXPORT AudioManagerOpenBSD : public AudioManagerBase {
public:
AudioManagerOpenBSD();
+ // Call before using a newly created AudioManagerOpenBSD instance.
+ virtual void Init() OVERRIDE;
+
// Implementation of AudioManager.
virtual bool HasAudioOutputDevices() OVERRIDE;
virtual bool HasAudioInputDevices() OVERRIDE;
virtual AudioOutputStream* MakeAudioOutputStream(
const AudioParameters& params) OVERRIDE;
- virtual AudioInputStream* MakeAudioInputStream(
- const AudioParameters& params) OVERRIDE;
- virtual bool IsRecordingInProgress() OVERRIDE;
+ virtual AudioInputStream* MakeAudioInputStream(const AudioParameters& params)
+ OVERRIDE;
+
virtual void MuteAll() OVERRIDE;
virtual void UnMuteAll() OVERRIDE;
- private:
+ virtual void ReleaseOutputStream(AudioOutputStream* stream);
+
+ protected:
virtual ~AudioManagerOpenBSD();
+ private:
+ std::set<AudioOutputStream*> active_streams_;
+
DISALLOW_COPY_AND_ASSIGN(AudioManagerOpenBSD);
};