audio: Allow targets to override the deep buffer device

Change-Id: I539403661e40e5be7eb5cc130a4b8ad8331d2a4a
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index fc91929..5aaaeb2 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -72,6 +72,24 @@
                AUDIO_DEVICE_OUT_SPEAKER,
 };
 
+static struct pcm_device_profile pcm_device_deep_buffer = {
+    .config = {
+        .channels = PLAYBACK_DEFAULT_CHANNEL_COUNT,
+        .rate = DEEP_BUFFER_OUTPUT_SAMPLING_RATE,
+        .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE,
+        .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT,
+        .format = PCM_FORMAT_S16_LE,
+        .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
+        .stop_threshold = INT_MAX,
+        .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
+    },
+    .card = SOUND_CARD,
+    .id = SOUND_DEEP_BUFFER_DEVICE,
+    .type = PCM_PLAYBACK,
+    .devices = AUDIO_DEVICE_OUT_WIRED_HEADSET|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|
+               AUDIO_DEVICE_OUT_SPEAKER,
+};
+
 static struct pcm_device_profile pcm_device_capture = {
     .config = {
         .channels = CAPTURE_DEFAULT_CHANNEL_COUNT,
@@ -215,17 +233,6 @@
 
 static unsigned int audio_device_ref_count;
 
-static struct pcm_config pcm_config_deep_buffer = {
-    .channels = 2,
-    .rate = DEEP_BUFFER_OUTPUT_SAMPLING_RATE,
-    .period_size = DEEP_BUFFER_OUTPUT_PERIOD_SIZE,
-    .period_count = DEEP_BUFFER_OUTPUT_PERIOD_COUNT,
-    .format = PCM_FORMAT_S16_LE,
-    .start_threshold = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
-    .stop_threshold = INT_MAX,
-    .avail_min = DEEP_BUFFER_OUTPUT_PERIOD_SIZE / 4,
-};
-
 struct string_to_enum {
     const char *name;
     uint32_t value;
@@ -2191,13 +2198,21 @@
     struct pcm_device *pcm_device;
     struct listnode *node;
     int ret = 0;
+    int pcm_device_card;
+    int pcm_device_id;
 
     list_for_each(node, &out->pcm_dev_list) {
         pcm_device = node_to_item(node, struct pcm_device, stream_list_node);
-        ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
-              __func__, pcm_device->pcm_profile->card, pcm_device->pcm_profile->id);
+        pcm_device_card = pcm_device->pcm_profile->card;
+        pcm_device_id = pcm_device->pcm_profile->id;
 
-        pcm_device->pcm = pcm_open(pcm_device->pcm_profile->card, pcm_device->pcm_profile->id,
+        if (out->flags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER)
+            pcm_device_id = pcm_device_deep_buffer.id;
+
+        ALOGV("%s: Opening PCM device card_id(%d) device_id(%d)",
+              __func__, pcm_device_card, pcm_device_id);
+
+        pcm_device->pcm = pcm_open(pcm_device_card, pcm_device_id,
                                PCM_OUT | PCM_MONOTONIC, &pcm_device->pcm_profile->config);
 
         if (pcm_device->pcm && !pcm_is_ready(pcm_device->pcm)) {
@@ -2213,7 +2228,7 @@
         if (out->sample_rate != pcm_device->pcm_profile->config.rate) {
             ALOGV("%s: create_resampler(), pcm_device_card(%d), pcm_device_id(%d), \
                     out_rate(%d), device_rate(%d)",__func__,
-                    pcm_device->pcm_profile->card, pcm_device->pcm_profile->id,
+                    pcm_device_card, pcm_device_id,
                     out->sample_rate, pcm_device->pcm_profile->config.rate);
             ret = create_resampler(out->sample_rate,
                     pcm_device->pcm_profile->config.rate,
@@ -3586,7 +3601,7 @@
                 config->offload_info.bit_rate);
     } else if (out->flags & (AUDIO_OUTPUT_FLAG_DEEP_BUFFER)) {
         out->usecase = USECASE_AUDIO_PLAYBACK_DEEP_BUFFER;
-        out->config = pcm_config_deep_buffer;
+        out->config = pcm_device_deep_buffer.config;
         out->sample_rate = out->config.rate;
         ALOGV("%s: use AUDIO_PLAYBACK_DEEP_BUFFER",__func__);
     } else {
diff --git a/audio/include/samsung_audio.h b/audio/include/samsung_audio.h
index 89b3a41..6aaf4df 100644
--- a/audio/include/samsung_audio.h
+++ b/audio/include/samsung_audio.h
@@ -31,6 +31,7 @@
 #define SOUND_CARD 0
 
 /* Playback */
+#define SOUND_DEEP_BUFFER_DEVICE 3
 #define SOUND_PLAYBACK_DEVICE 4
 #define SOUND_PLAYBACK_SCO_DEVICE 2