From b5d4d0289188efdb149557e9b7cad7009f70051b Mon Sep 17 00:00:00 2001 From: Jim Kaye Date: Fri, 20 Jan 2017 17:22:32 -0800 Subject: [PATCH] Allow headset plug/unplug in the emulator Have the goldfish device support WIRED_HEADPHONE and WIRED_HEADSET in addition to SPEAKER. Support more audio sample rates. Set 'useDevInputEventForAudioJack' so we respond to settings from the emulator. BUG: http://b/32437768 Test: Required for and covered by CTS Verifier (cherry picked from commit e5d00ff412de76d1d0146d0aa7fc6243f6d98ffa) Change-Id: Ic35c38d7169a02bedf19b148703ff4993d1037b4 --- audio/audio_hw_legacy.c | 35 +++++++++++++++++----- audio_policy.conf | 4 +-- .../frameworks/base/core/res/res/values/config.xml | 24 +++++++++++++++ 3 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 overlay/frameworks/base/core/res/res/values/config.xml diff --git a/audio/audio_hw_legacy.c b/audio/audio_hw_legacy.c index cab9aad..14d82da 100644 --- a/audio/audio_hw_legacy.c +++ b/audio/audio_hw_legacy.c @@ -33,7 +33,6 @@ #define AUDIO_DEVICE_NAME "/dev/eac" -#define OUT_SAMPLING_RATE 44100 #define OUT_BUFFER_SIZE 4096 #define OUT_LATENCY_MS 20 #define IN_SAMPLING_RATE 8000 @@ -54,6 +53,7 @@ struct generic_stream_out { struct audio_stream_out stream; struct generic_audio_device *dev; audio_devices_t device; + uint32_t sample_rate; }; struct generic_stream_in { @@ -65,7 +65,8 @@ struct generic_stream_in { static uint32_t out_get_sample_rate(const struct audio_stream *stream) { - return OUT_SAMPLING_RATE; + struct generic_stream_out *out = (struct generic_stream_out *)stream; + return out->sample_rate; } static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate) @@ -376,6 +377,8 @@ static int adev_open_output_stream(struct audio_hw_device *dev, { struct generic_audio_device *adev = (struct generic_audio_device *)dev; struct generic_stream_out *out; + static const uint32_t sample_rates [] = { 44100, 48000 }; + static const int sample_rates_count = sizeof(sample_rates)/sizeof(sample_rates[0]); int ret = 0; pthread_mutex_lock(&adev->lock); @@ -385,17 +388,32 @@ static int adev_open_output_stream(struct audio_hw_device *dev, } if ((config->format != AUDIO_FORMAT_PCM_16_BIT) || - (config->channel_mask != AUDIO_CHANNEL_OUT_STEREO) || - (config->sample_rate != OUT_SAMPLING_RATE)) { - ALOGE("Error opening output stream format %d, channel_mask %04x, sample_rate %u", - config->format, config->channel_mask, config->sample_rate); + (config->channel_mask != AUDIO_CHANNEL_OUT_STEREO) ) { + ALOGE("Error opening output stream, format %d, channel_mask %04x", + config->format, config->channel_mask); config->format = AUDIO_FORMAT_PCM_16_BIT; config->channel_mask = AUDIO_CHANNEL_OUT_STEREO; - config->sample_rate = OUT_SAMPLING_RATE; ret = -EINVAL; - goto error; } + for (int idx = 0; idx < sample_rates_count; idx++) { + if (config->sample_rate < sample_rates[idx]) { + config->sample_rate = sample_rates[idx]; + ALOGE("Error opening output stream, sample_rate %u", config->sample_rate); + ret = -EINVAL; + break; + } else if (config->sample_rate == sample_rates[idx]) { + break; + } else if (idx == sample_rates_count-1) { + // Cap it to the highest rate we support + config->sample_rate = sample_rates[idx]; + ALOGE("Error opening output stream, sample_rate %u", config->sample_rate); + ret = -EINVAL; + } + } + + if (ret != 0) goto error; + out = (struct generic_stream_out *)calloc(1, sizeof(struct generic_stream_out)); out->stream.common.get_sample_rate = out_get_sample_rate; @@ -415,6 +433,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev, out->stream.write = out_write; out->stream.get_render_position = out_get_render_position; out->stream.get_next_write_timestamp = out_get_next_write_timestamp; + out->sample_rate = config->sample_rate; out->dev = adev; out->device = devices; diff --git a/audio_policy.conf b/audio_policy.conf index 38b4e49..0945c25 100644 --- a/audio_policy.conf +++ b/audio_policy.conf @@ -30,7 +30,7 @@ audio_hw_modules { sampling_rates 8000|11025|16000|22050|24000|44100|48000 channel_masks AUDIO_CHANNEL_OUT_MONO|AUDIO_CHANNEL_OUT_STEREO formats AUDIO_FORMAT_PCM_16_BIT - devices AUDIO_DEVICE_OUT_SPEAKER + devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_WIRED_HEADSET flags AUDIO_OUTPUT_FLAG_PRIMARY } } @@ -39,7 +39,7 @@ audio_hw_modules { sampling_rates 8000|11025|16000|22050|44100|48000 channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO formats AUDIO_FORMAT_PCM_16_BIT - devices AUDIO_DEVICE_IN_BUILTIN_MIC + devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_WIRED_HEADSET } } } diff --git a/overlay/frameworks/base/core/res/res/values/config.xml b/overlay/frameworks/base/core/res/res/values/config.xml new file mode 100644 index 0000000..bab2237 --- /dev/null +++ b/overlay/frameworks/base/core/res/res/values/config.xml @@ -0,0 +1,24 @@ + + + + + + true + -- 2.11.0