audio_manager_openbsd.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "media/audio/openbsd/audio_manager_openbsd.h"
6
7#include "base/command_line.h"
8#include "base/stl_util.h"
9#include "media/audio/audio_output_dispatcher.h"
10#if defined(USE_PULSEAUDIO)
11#include "media/audio/pulse/pulse_output.h"
12#endif
13#include "media/base/limits.h"
14#include "media/base/media_switches.h"
15
16#include <fcntl.h>
17
18namespace media {
19
20// Maximum number of output streams that can be open simultaneously.
21static const int kMaxOutputStreams = 50;
22
23// Implementation of AudioManager.
24static 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
38bool AudioManagerOpenBSD::HasAudioOutputDevices() {
39  return HasAudioHardware();
40}
41
42bool AudioManagerOpenBSD::HasAudioInputDevices() {
43  return HasAudioHardware();
44}
45
46AudioManagerOpenBSD::AudioManagerOpenBSD() {
47  SetMaxOutputStreamsAllowed(kMaxOutputStreams);
48}
49
50AudioManagerOpenBSD::~AudioManagerOpenBSD() {
51  Shutdown();
52}
53
54AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream(
55    const AudioParameters& params) {
56  DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format);
57  return MakeOutputStream(params);
58}
59
60AudioOutputStream* AudioManagerOpenBSD::MakeLowLatencyOutputStream(
61    const AudioParameters& params) {
62  DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format);
63  return MakeOutputStream(params);
64}
65
66AudioInputStream* AudioManagerOpenBSD::MakeLinearInputStream(
67    const AudioParameters& params, const std::string& device_id) {
68  DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format);
69  NOTIMPLEMENTED();
70  return NULL;
71}
72
73AudioInputStream* AudioManagerOpenBSD::MakeLowLatencyInputStream(
74    const AudioParameters& params, const std::string& device_id) {
75  DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format);
76  NOTIMPLEMENTED();
77  return NULL;
78}
79
80AudioOutputStream* AudioManagerOpenBSD::MakeOutputStream(
81    const AudioParameters& params) {
82#if defined(USE_PULSEAUDIO)
83  if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) {
84    return new PulseAudioOutputStream(params, this);
85  }
86#endif
87
88  NOTIMPLEMENTED();
89  return NULL;
90}
91
92// static
93AudioManager* CreateAudioManager() {
94  return new AudioManagerOpenBSD();
95}
96
97}  // namespace media
98