OSDN Git Service

Allow headset plug/unplug in the emulator
authorJim Kaye <jameskaye@google.com>
Sat, 21 Jan 2017 01:22:32 +0000 (17:22 -0800)
committerJim Kaye <jameskaye@google.com>
Wed, 25 Jan 2017 18:27:49 +0000 (10:27 -0800)
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
audio_policy.conf
overlay/frameworks/base/core/res/res/values/config.xml [new file with mode: 0644]

index cab9aad..14d82da 100644 (file)
@@ -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;
index 38b4e49..0945c25 100644 (file)
@@ -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 (file)
index 0000000..bab2237
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2017, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+**     http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+    <!-- Make this 'true' to allow the Emulator to control
+         the state of the headphone/microphone jack -->
+    <bool name="config_useDevInputEventForAudioJack">true</bool>
+</resources>