OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/audio_parameters.h" |
10 #if defined(USE_PULSEAUDIO) | 11 #if defined(USE_PULSEAUDIO) |
11 #include "media/audio/pulse/pulse_output.h" | 12 #include "media/audio/pulse/pulse_output.h" |
12 #endif | 13 #endif |
| 14 #include "media/base/channel_layout.h" |
13 #include "media/base/limits.h" | 15 #include "media/base/limits.h" |
14 #include "media/base/media_switches.h" | 16 #include "media/base/media_switches.h" |
15 | 17 |
16 #include <fcntl.h> | 18 #include <fcntl.h> |
17 | 19 |
18 namespace media { | 20 namespace media { |
19 | 21 |
20 // Maximum number of output streams that can be open simultaneously. | 22 // Maximum number of output streams that can be open simultaneously. |
21 static const int kMaxOutputStreams = 50; | 23 static const int kMaxOutputStreams = 50; |
22 | 24 |
| 25 // Default sample rate for input and output streams. |
| 26 static const int kDefaultSampleRate = 48000; |
| 27 |
23 // Implementation of AudioManager. | 28 // Implementation of AudioManager. |
24 static bool HasAudioHardware() { | 29 static bool HasAudioHardware() { |
25 int fd; | 30 int fd; |
26 const char *file; | 31 const char *file; |
27 | 32 |
28 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') | 33 if ((file = getenv("AUDIOCTLDEVICE")) == 0 || *file == '\0') |
29 file = "/dev/audioctl"; | 34 file = "/dev/audioctl"; |
30 | 35 |
31 if ((fd = open(file, O_RDONLY)) < 0) | 36 if ((fd = open(file, O_RDONLY)) < 0) |
32 return false; | 37 return false; |
33 | 38 |
34 close(fd); | 39 close(fd); |
35 return true; | 40 return true; |
36 } | 41 } |
37 | 42 |
38 bool AudioManagerOpenBSD::HasAudioOutputDevices() { | 43 bool AudioManagerOpenBSD::HasAudioOutputDevices() { |
39 return HasAudioHardware(); | 44 return HasAudioHardware(); |
40 } | 45 } |
41 | 46 |
42 bool AudioManagerOpenBSD::HasAudioInputDevices() { | 47 bool AudioManagerOpenBSD::HasAudioInputDevices() { |
43 return HasAudioHardware(); | 48 return HasAudioHardware(); |
44 } | 49 } |
45 | 50 |
| 51 AudioParameters AudioManagerOpenBSD::GetDefaultOutputStreamParameters() { |
| 52 static const int kDefaultOutputBufferSize = 512; |
| 53 |
| 54 return AudioParameters( |
| 55 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 56 kDefaultSampleRate, 16, kDefaultOutputBufferSize); |
| 57 } |
| 58 |
| 59 AudioParameters AudioManagerOpenBSD::GetDefaultInputStreamParameters( |
| 60 const std::string& device_id) { |
| 61 static const int kDefaultInputBufferSize = 1024; |
| 62 |
| 63 return AudioParameters( |
| 64 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 65 kDefaultSampleRate, 16, kDefaultInputBufferSize); |
| 66 } |
| 67 |
46 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 68 AudioManagerOpenBSD::AudioManagerOpenBSD() { |
47 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 69 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
48 } | 70 } |
49 | 71 |
50 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 72 AudioManagerOpenBSD::~AudioManagerOpenBSD() { |
51 Shutdown(); | 73 Shutdown(); |
52 } | 74 } |
53 | 75 |
54 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( | 76 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( |
55 const AudioParameters& params) { | 77 const AudioParameters& params) { |
(...skipping 26 matching lines...) Expand all Loading... |
82 #if defined(USE_PULSEAUDIO) | 104 #if defined(USE_PULSEAUDIO) |
83 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | 105 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { |
84 return new PulseAudioOutputStream(params, this); | 106 return new PulseAudioOutputStream(params, this); |
85 } | 107 } |
86 #endif | 108 #endif |
87 | 109 |
88 NOTIMPLEMENTED(); | 110 NOTIMPLEMENTED(); |
89 return NULL; | 111 return NULL; |
90 } | 112 } |
91 | 113 |
| 114 // TODO(xians): Merge AudioManagerOpenBSD with AudioManagerPulse; |
92 // static | 115 // static |
93 AudioManager* CreateAudioManager() { | 116 AudioManager* CreateAudioManager() { |
94 return new AudioManagerOpenBSD(); | 117 return new AudioManagerOpenBSD(); |
95 } | 118 } |
96 | 119 |
97 } // namespace media | 120 } // namespace media |
OLD | NEW |