Commit 19c6a075 authored by dalecurtis's avatar dalecurtis Committed by Commit bot

Query native channel count in preferred parameters.

w/o this, WebAudio will always think there are only two channels
available. Untested since I don't have a 5.1 setup on Linux.

BUG=646435
TEST=verified that 2 channels are reported locally.

Review-Url: https://codereview.chromium.org/2345813002
Cr-Commit-Position: refs/heads/master@{#419052}
parent 2d6dbcaa
......@@ -58,7 +58,8 @@ AudioManagerPulse::AudioManagerPulse(
input_mainloop_(NULL),
input_context_(NULL),
devices_(NULL),
native_input_sample_rate_(0) {
native_input_sample_rate_(0),
native_channel_count_(0) {
SetMaxOutputStreamsAllowed(kMaxOutputStreams);
}
......@@ -136,8 +137,9 @@ AudioParameters AudioManagerPulse::GetInputStreamParameters(
user_buffer_size : kDefaultInputBufferSize;
// TODO(xians): add support for querying native channel layout for pulse.
UpdateNativeAudioHardwareInfo();
return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY,
CHANNEL_LAYOUT_STEREO, GetNativeSampleRate(), 16,
CHANNEL_LAYOUT_STEREO, native_input_sample_rate_, 16,
buffer_size);
}
......@@ -180,10 +182,15 @@ AudioParameters AudioManagerPulse::GetPreferredOutputStreamParameters(
// TODO(tommi): Support |output_device_id|.
VLOG_IF(0, !output_device_id.empty()) << "Not implemented!";
ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO;
int buffer_size = kMinimumOutputBufferSize;
int bits_per_sample = 16;
int sample_rate = GetNativeSampleRate();
// Query native parameters where applicable; Pulse does not require these to
// be respected though, so prefer the input parameters for channel count.
UpdateNativeAudioHardwareInfo();
int sample_rate = native_input_sample_rate_;
ChannelLayout channel_layout = GuessChannelLayout(native_channel_count_);
if (input_params.IsValid()) {
bits_per_sample = input_params.bits_per_sample();
channel_layout = input_params.channel_layout();
......@@ -213,15 +220,13 @@ AudioInputStream* AudioManagerPulse::MakeInputStream(
input_mainloop_, input_context_);
}
int AudioManagerPulse::GetNativeSampleRate() {
void AudioManagerPulse::UpdateNativeAudioHardwareInfo() {
DCHECK(input_mainloop_);
DCHECK(input_context_);
AutoPulseLock auto_lock(input_mainloop_);
pa_operation* operation = pa_context_get_server_info(
input_context_, SampleRateInfoCallback, this);
input_context_, AudioHardwareInfoCallback, this);
WaitForOperationCompletion(input_mainloop_, operation);
return native_input_sample_rate_;
}
bool AudioManagerPulse::InitPulse() {
......@@ -336,12 +341,13 @@ void AudioManagerPulse::OutputDevicesInfoCallback(pa_context* context,
info->name));
}
void AudioManagerPulse::SampleRateInfoCallback(pa_context* context,
const pa_server_info* info,
void* user_data) {
void AudioManagerPulse::AudioHardwareInfoCallback(pa_context* context,
const pa_server_info* info,
void* user_data) {
AudioManagerPulse* manager = reinterpret_cast<AudioManagerPulse*>(user_data);
manager->native_input_sample_rate_ = info->sample_spec.rate;
manager->native_channel_count_ = info->sample_spec.channels;
pa_threaded_mainloop_signal(manager->input_mainloop_, 0);
}
......
......@@ -72,10 +72,10 @@ class MEDIA_EXPORT AudioManagerPulse : public AudioManagerBase {
int error, void* user_data);
// Callback to get the native sample rate of PulseAudio, used by
// GetNativeSampleRate().
static void SampleRateInfoCallback(pa_context* context,
const pa_server_info* info,
void* user_data);
// UpdateNativeAudioHardwareInfo().
static void AudioHardwareInfoCallback(pa_context* context,
const pa_server_info* info,
void* user_data);
// Called by MakeLinearOutputStream and MakeLowLatencyOutputStream.
AudioOutputStream* MakeOutputStream(const AudioParameters& params,
......@@ -85,13 +85,14 @@ class MEDIA_EXPORT AudioManagerPulse : public AudioManagerBase {
AudioInputStream* MakeInputStream(const AudioParameters& params,
const std::string& device_id);
// Gets the native sample rate of Pulse.
int GetNativeSampleRate();
// Updates |native_input_sample_rate_| and |native_channel_count_|.
void UpdateNativeAudioHardwareInfo();
pa_threaded_mainloop* input_mainloop_;
pa_context* input_context_;
AudioDeviceNames* devices_;
int native_input_sample_rate_;
int native_channel_count_;
DISALLOW_COPY_AND_ASSIGN(AudioManagerPulse);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment