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 const AudioParameters& input_params) { |
| 53 static const int kDefaultOutputBufferSize = 512; |
| 54 |
| 55 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 56 int sample_rate = kDefaultSampleRate; |
| 57 int buffer_size = kDefaultOutputBufferSize; |
| 58 int bits_per_sample = 16; |
| 59 int input_channels = 0; |
| 60 if (input_params.IsValid()) { |
| 61 sample_rate = input_params.sample_rate(); |
| 62 bits_per_sample = input_params.bits_per_sample(); |
| 63 channel_layout = input_params.channel_layout(); |
| 64 input_channels = input_params.input_channels(); |
| 65 buffer_size = std::min(buffer_size, input_params.frames_per_buffer()); |
| 66 } |
| 67 |
| 68 return AudioParameters( |
| 69 AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels, |
| 70 sample_rate, bits_per_sample, buffer_size); |
| 71 } |
| 72 |
| 73 AudioParameters AudioManagerOpenBSD::GetInputStreamParameters( |
| 74 const std::string& device_id) { |
| 75 static const int kDefaultInputBufferSize = 1024; |
| 76 |
| 77 return AudioParameters( |
| 78 AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO, |
| 79 kDefaultSampleRate, 16, kDefaultInputBufferSize); |
| 80 } |
| 81 |
46 AudioManagerOpenBSD::AudioManagerOpenBSD() { | 82 AudioManagerOpenBSD::AudioManagerOpenBSD() { |
47 SetMaxOutputStreamsAllowed(kMaxOutputStreams); | 83 SetMaxOutputStreamsAllowed(kMaxOutputStreams); |
48 } | 84 } |
49 | 85 |
50 AudioManagerOpenBSD::~AudioManagerOpenBSD() { | 86 AudioManagerOpenBSD::~AudioManagerOpenBSD() { |
51 Shutdown(); | 87 Shutdown(); |
52 } | 88 } |
53 | 89 |
54 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( | 90 AudioOutputStream* AudioManagerOpenBSD::MakeLinearOutputStream( |
55 const AudioParameters& params) { | 91 const AudioParameters& params) { |
(...skipping 26 matching lines...) Expand all Loading... |
82 #if defined(USE_PULSEAUDIO) | 118 #if defined(USE_PULSEAUDIO) |
83 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { | 119 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUsePulseAudio)) { |
84 return new PulseAudioOutputStream(params, this); | 120 return new PulseAudioOutputStream(params, this); |
85 } | 121 } |
86 #endif | 122 #endif |
87 | 123 |
88 NOTIMPLEMENTED(); | 124 NOTIMPLEMENTED(); |
89 return NULL; | 125 return NULL; |
90 } | 126 } |
91 | 127 |
| 128 // TODO(xians): Merge AudioManagerOpenBSD with AudioManagerPulse; |
92 // static | 129 // static |
93 AudioManager* CreateAudioManager() { | 130 AudioManager* CreateAudioManager() { |
94 return new AudioManagerOpenBSD(); | 131 return new AudioManagerOpenBSD(); |
95 } | 132 } |
96 | 133 |
97 } // namespace media | 134 } // namespace media |
OLD | NEW |