Merge "audio: increase max limit of Audio Port elements"
diff --git a/alsa_utils/alsa_device_proxy.c b/alsa_utils/alsa_device_proxy.c
index 73e4375..9236a9b 100644
--- a/alsa_utils/alsa_device_proxy.c
+++ b/alsa_utils/alsa_device_proxy.c
@@ -92,6 +92,14 @@
     } else {
         proxy->frame_size = 1;
     }
+
+    // let's check to make sure we can ACTUALLY use the maximum rate (with the channel count)
+    // Note that profile->sample_rates is sorted highest to lowest, so the scan will get
+    // us the highest working rate
+    int max_rate_index = proxy_scan_rates(proxy, profile->sample_rates);
+    if (max_rate_index >= 0) {
+        proxy->alsa_config.rate = profile->sample_rates[max_rate_index];
+    }
 }
 
 int proxy_open(alsa_device_proxy * proxy)
@@ -111,7 +119,7 @@
     }
 
     if (!pcm_is_ready(proxy->pcm)) {
-        ALOGE("  proxy_open() pcm_open() failed: %s", pcm_get_error(proxy->pcm));
+        ALOGE("  proxy_open() pcm_is_ready() failed: %s", pcm_get_error(proxy->pcm));
 #if defined(LOG_PCM_PARAMS)
         log_pcm_config(&proxy->alsa_config, "config");
 #endif
@@ -231,3 +239,33 @@
         dprintf(fd, "  format: %d\n", proxy->alsa_config.format);
     }
 }
+
+int proxy_scan_rates(alsa_device_proxy * proxy, unsigned sample_rates[]) {
+    alsa_device_profile* profile = proxy->profile;
+    if (profile->card < 0 || profile->device < 0) {
+        return -EINVAL;
+    }
+
+    struct pcm_config alsa_config;
+    memcpy(&alsa_config, &proxy->alsa_config, sizeof(alsa_config));
+
+    struct pcm * alsa_pcm;
+    int rate_index = 0;
+    while (sample_rates[rate_index] != 0) {
+        alsa_config.rate = sample_rates[rate_index];
+        alsa_pcm = pcm_open(profile->card, profile->device,
+                profile->direction | PCM_MONOTONIC, &alsa_config);
+        if (alsa_pcm != NULL) {
+            if (pcm_is_ready(alsa_pcm)) {
+                pcm_close(alsa_pcm);
+                return rate_index;
+            }
+
+            pcm_close(alsa_pcm);
+        }
+
+        rate_index++;
+    }
+
+    return -EINVAL;
+}
diff --git a/alsa_utils/include/alsa_device_profile.h b/alsa_utils/include/alsa_device_profile.h
index e056d70..8307d0a 100644
--- a/alsa_utils/include/alsa_device_profile.h
+++ b/alsa_utils/include/alsa_device_profile.h
@@ -42,6 +42,7 @@
 
     enum pcm_format formats[MAX_PROFILE_FORMATS];
 
+    /* note that this list is sorted highest rate to lowest */
     unsigned sample_rates[MAX_PROFILE_SAMPLE_RATES];
 
     unsigned channel_counts[MAX_PROFILE_CHANNEL_COUNTS];
diff --git a/alsa_utils/include/alsa_device_proxy.h b/alsa_utils/include/alsa_device_proxy.h
index 0bc0731..212ae4f 100644
--- a/alsa_utils/include/alsa_device_proxy.h
+++ b/alsa_utils/include/alsa_device_proxy.h
@@ -48,6 +48,14 @@
 unsigned int proxy_get_period_size(const alsa_device_proxy * proxy);
 unsigned proxy_get_latency(const alsa_device_proxy * proxy);
 
+/*
+ * Scans the provided list of sample rates and finds the first one that works.
+ *
+ * returns the index of the first rate for which the ALSA device can be opened.
+ * return negative value if none work or an error occurs.
+ */
+int proxy_scan_rates(alsa_device_proxy * proxy, unsigned sample_rates[]);
+
 /* I/O */
 int proxy_write(alsa_device_proxy * proxy, const void *data, unsigned int count);
 int proxy_read(const alsa_device_proxy * proxy, void *data, unsigned int count);
diff --git a/audio/include/system/audio-base.h b/audio/include/system/audio-base.h
index b541f96..606dd83 100644
--- a/audio/include/system/audio-base.h
+++ b/audio/include/system/audio-base.h
@@ -323,7 +323,7 @@
     AUDIO_OUTPUT_FLAG_IEC958_NONAUDIO = 1024, // 0x400
     AUDIO_OUTPUT_FLAG_DIRECT_PCM = 8192, // 0x2000
     AUDIO_OUTPUT_FLAG_MMAP_NOIRQ = 16384, // 0x4000
-    AUDIO_OUTPUT_FLAG_VOIP_CALL_RX = 32768, // 0x8000
+    AUDIO_OUTPUT_FLAG_VOIP_RX = 32768, // 0x8000
 } audio_output_flags_t;
 
 typedef enum {
@@ -333,7 +333,7 @@
     AUDIO_INPUT_FLAG_RAW = 4, // 0x4
     AUDIO_INPUT_FLAG_SYNC = 8, // 0x8
     AUDIO_INPUT_FLAG_MMAP_NOIRQ = 16, // 0x10
-    AUDIO_INPUT_FLAG_VOIP_CALL_TX = 32, // 0x20
+    AUDIO_INPUT_FLAG_VOIP_TX = 32, // 0x20
 } audio_input_flags_t;
 
 typedef enum {