Provide fake audio parameters when devices don't exist.

These methods should always return valid parameters, even if a device
doesn't exist.

Output code will automatically fall back to a fake path at a later time
if those parameters are used to open a stream.

Input code will fail because no input devices can be enumerated.

BUG=331675
TEST=no more crashes.

Review URL: https://codereview.chromium.org/127363002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243704 0039d316-1c4b-4281-b951-d872f2087c98
parent c7c0c92c
......@@ -401,16 +401,12 @@ void AudioManagerMac::GetAudioOutputDeviceNames(
AudioParameters AudioManagerMac::GetInputStreamParameters(
const std::string& device_id) {
// Due to the sharing of the input and output buffer sizes, we need to choose
// the input buffer size based on the output sample rate. See
// http://crbug.com/154352.
const int buffer_size = ChooseBufferSize(
AUAudioOutputStream::HardwareSampleRate());
AudioDeviceID device = GetAudioDeviceIdByUId(true, device_id);
if (device == kAudioObjectUnknown) {
DLOG(ERROR) << "Invalid device " << device_id;
return AudioParameters();
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate));
}
int channels = 0;
......@@ -427,6 +423,11 @@ AudioParameters AudioManagerMac::GetInputStreamParameters(
if (!sample_rate)
sample_rate = kFallbackSampleRate;
// Due to the sharing of the input and output buffer sizes, we need to choose
// the input buffer size based on the output sample rate. See
// http://crbug.com/154352.
const int buffer_size = ChooseBufferSize(sample_rate);
// TODO(xians): query the native channel layout for the specific device.
return AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout,
......@@ -646,7 +647,9 @@ AudioParameters AudioManagerMac::GetPreferredOutputStreamParameters(
AudioDeviceID device = GetAudioDeviceIdByUId(false, output_device_id);
if (device == kAudioObjectUnknown) {
DLOG(ERROR) << "Invalid output device " << output_device_id;
return AudioParameters();
return input_params.IsValid() ? input_params : AudioParameters(
AudioParameters::AUDIO_PCM_LOW_LATENCY, CHANNEL_LAYOUT_STEREO,
kFallbackSampleRate, 16, ChooseBufferSize(kFallbackSampleRate));
}
int hardware_channels = 2;
......
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