audio: set cached volume before starting voice call

Apply cached voice volume before starting voice call.

Change-Id: I6a86d5f104b6a19c13bffbdeafa7a7f325d5ad3b
Bug: 10516515
diff --git a/hal/audio_hw.c b/hal/audio_hw.c
index 404f17c..2ad5c88 100644
--- a/hal/audio_hw.c
+++ b/hal/audio_hw.c
@@ -125,6 +125,8 @@
     STRING_TO_ENUM(AUDIO_CHANNEL_OUT_7POINT1),
 };
 
+static int set_voice_volume_l(struct audio_device *adev, float volume);
+
 static bool is_supported_format(audio_format_t format)
 {
     if (format == AUDIO_FORMAT_MP3 /*||
@@ -963,6 +965,10 @@
         ret = -EIO;
         goto error_start_voice;
     }
+
+    /* set cached volume */
+    set_voice_volume_l(adev, adev->voice_volume);
+
     pcm_start(adev->voice_call_rx);
     pcm_start(adev->voice_call_tx);
 
@@ -971,7 +977,6 @@
         ALOGE("%s: platform_start_voice_call error %d\n", __func__, ret);
         goto error_start_voice;
     }
-
     adev->in_call = true;
     return 0;
 
@@ -1963,13 +1968,11 @@
     return 0;
 }
 
-static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
+/* always called with adev lock held */
+static int set_voice_volume_l(struct audio_device *adev, float volume)
 {
-    struct audio_device *adev = (struct audio_device *)dev;
     int vol, err = 0;
 
-    pthread_mutex_lock(&adev->lock);
-    adev->voice_volume = volume;
     if (adev->mode == AUDIO_MODE_IN_CALL) {
         if (volume < 0.0) {
             volume = 0.0;
@@ -1986,10 +1989,21 @@
 
         err = platform_set_voice_volume(adev->platform, vol);
     }
-    pthread_mutex_unlock(&adev->lock);
     return err;
 }
 
+static int adev_set_voice_volume(struct audio_hw_device *dev, float volume)
+{
+    int ret;
+    struct audio_device *adev = (struct audio_device *)dev;
+    pthread_mutex_lock(&adev->lock);
+    /* cache volume */
+    adev->voice_volume = volume;
+    ret = set_voice_volume_l(adev, adev->voice_volume);
+    pthread_mutex_unlock(&adev->lock);
+    return ret;
+}
+
 static int adev_set_master_volume(struct audio_hw_device *dev, float volume)
 {
     return -ENOSYS;