Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Unified Diff: media/audio/linux/audio_manager_linux.cc

Issue 12316131: Moved AudioUtil static functions to AudioManager interfaces (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged GetPreferredLowLatencyOutputStreamParameters to GetDefaultOutputStreamParameters Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/audio/linux/audio_manager_linux.cc
diff --git a/media/audio/linux/audio_manager_linux.cc b/media/audio/linux/audio_manager_linux.cc
index fa8612573fe95397f905062cfd531aa20af5684b..8134350b04de3b455d6c51c1d8dcd8e6c5073200 100644
--- a/media/audio/linux/audio_manager_linux.cc
+++ b/media/audio/linux/audio_manager_linux.cc
@@ -11,7 +11,7 @@
#include "base/process_util.h"
#include "base/stl_util.h"
#include "media/audio/audio_output_dispatcher.h"
-#include "media/audio/audio_util.h"
+#include "media/audio/audio_parameters.h"
#if defined(USE_CRAS)
#include "media/audio/cras/audio_manager_cras.h"
#endif
@@ -21,6 +21,7 @@
#if defined(USE_PULSEAUDIO)
#include "media/audio/pulse/audio_manager_pulse.h"
#endif
+#include "media/base/channel_layout.h"
#include "media/base/limits.h"
#include "media/base/media_switches.h"
@@ -29,6 +30,9 @@ namespace media {
// Maximum number of output streams that can be open simultaneously.
static const int kMaxOutputStreams = 50;
+// Default sample rate for input and output streams.
+static const int kDefaultSampleRate = 48000;
+
// Since "default", "pulse" and "dmix" devices are virtual devices mapped to
// real devices, we remove them from the list to avoiding duplicate counting.
// In addition, note that we support no more than 2 channels for recording,
@@ -94,6 +98,43 @@ void AudioManagerLinux::GetAudioInputDeviceNames(
GetAlsaAudioInputDevices(device_names);
}
+AudioParameters AudioManagerLinux::GetDefaultOutputStreamParameters(
+ const AudioParameters& input_params) {
+ static const int kDefaultOutputBufferSize = 512;
+ ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
+ int sample_rate = kDefaultSampleRate;
+ int buffer_size = kDefaultOutputBufferSize;
+ int bits_per_sample = 16;
+ int input_channels = 0;
+ if (input_params.IsValid()) {
+ // Since Linux doesn't actually have a low latency path the hardware buffer
DaleCurtis 2013/03/02 01:53:56 Comment can be deleted now.
no longer working on chromium 2013/03/04 14:55:04 Delete the first comment, and I think the other is
+ // size is quite large in order to prevent glitches with general usage.
+ // Some clients, such as WebRTC, have a more limited use case and work
+ // acceptably with a smaller buffer size. The check below allows clients
+ // which want to try a smaller buffer size on Linux to do so.
+ // TODO(dalecurtis): This should include bits per channel and channel layout
+ // eventually.
+ sample_rate = input_params.sample_rate();
+ bits_per_sample = input_params.bits_per_sample();
+ channel_layout = input_params.channel_layout();
+ input_channels = input_params.input_channels();
+ buffer_size = std::min(input_params.frames_per_buffer(), buffer_size);
+ }
+
+ return AudioParameters(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, input_channels,
+ sample_rate, bits_per_sample, buffer_size);
+}
+
+AudioParameters AudioManagerLinux::GetInputStreamParameters(
+ const std::string& device_id) {
+ static const int kDefaultInputBufferSize = 1024;
+
+ return AudioParameters(
+ AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
+ kDefaultSampleRate, 16, kDefaultInputBufferSize);
+}
+
void AudioManagerLinux::GetAlsaAudioInputDevices(
media::AudioDeviceNames* device_names) {
// Constants specified by the ALSA API for device hints.
@@ -292,22 +333,4 @@ AudioManager* CreateAudioManager() {
return new AudioManagerLinux();
}
-AudioParameters AudioManagerLinux::GetPreferredLowLatencyOutputStreamParameters(
- const AudioParameters& input_params) {
- // Since Linux doesn't actually have a low latency path the hardware buffer
- // size is quite large in order to prevent glitches with general usage. Some
- // clients, such as WebRTC, have a more limited use case and work acceptably
- // with a smaller buffer size. The check below allows clients which want to
- // try a smaller buffer size on Linux to do so.
- int buffer_size = GetAudioHardwareBufferSize();
- if (input_params.frames_per_buffer() < buffer_size)
- buffer_size = input_params.frames_per_buffer();
-
- // TODO(dalecurtis): This should include bits per channel and channel layout
- // eventually.
- return AudioParameters(
- AudioParameters::AUDIO_PCM_LOW_LATENCY, input_params.channel_layout(),
- input_params.sample_rate(), 16, buffer_size);
-}
-
} // namespace media

Powered by Google App Engine
This is Rietveld 408576698