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