audio: Allow targets to override the deep buffer device
authorChristopher N. Hesse <raymanfx@gmail.com>
Mon, 30 Jan 2017 17:57:20 +0000 (18:57 +0100)
committerChristopher N. Hesse <raymanfx@gmail.com>
Mon, 30 Jan 2017 21:49:42 +0000 (21:49 +0000)
Change-Id: I539403661e40e5be7eb5cc130a4b8ad8331d2a4a

audio/audio_hw.c
audio/include/samsung_audio.h

index fc9192946ed176f4917ac5d63dd9e8b7ff644354..5aaaeb2b475448409bef8466f9c7055bd49f0aa9 100644 (file)
@@ -72,6 +72,24 @@ static struct pcm_device_profile pcm_device_playback = {
                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 const char * const use_case_table[AUDIO_USECASE_MAX] = {
 
 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 @@ static int out_open_pcm_devices(struct stream_out *out)
     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);
+        pcm_device_card = pcm_device->pcm_profile->card;
+        pcm_device_id = 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->pcm_profile->card, pcm_device->pcm_profile->id);
+              __func__, pcm_device_card, pcm_device_id);
 
-        pcm_device->pcm = pcm_open(pcm_device->pcm_profile->card, pcm_device->pcm_profile->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 @@ static int out_open_pcm_devices(struct stream_out *out)
         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 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
                 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 {
index 89b3a41f1d7ea6355fd6e16b03090c5a2d5d7e16..6aaf4dff666120ab819420091f9fdd204923eec3 100644 (file)
@@ -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