audio: implement mute on hdmi multichannel

On direct output streams the audio HAL must implement
the volume function. In the case of HDMI the only function
required is to mute audio when volume is 0 as volume
is defined as fixed on digital output streams.

Bug 8541062

Change-Id: I24c24b4807ed06b41b1172189162531d5335bb3e
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index e316e82..d425476 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -159,6 +159,7 @@
     audio_channel_mask_t channel_mask;
     /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */
     audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1];
+    bool muted;
 
     struct audio_device *dev;
 };
@@ -1101,6 +1102,14 @@
 static int out_set_volume(struct audio_stream_out *stream, float left,
                           float right)
 {
+    struct stream_out *out = (struct stream_out *)stream;
+    struct audio_device *adev = out->dev;
+
+    if (out == adev->outputs[OUTPUT_HDMI]) {
+        /* only take left channel into account: the API is for stereo anyway */
+        out->muted = (left == 0.0f);
+        return 0;
+    }
     return -ENOSYS;
 }
 
@@ -1135,6 +1144,9 @@
         goto exit;
     }
 
+    if (out->muted)
+        memset((void *)buffer, 0, bytes);
+
     /* Write to all active PCMs */
     for (i = 0; i < PCM_TOTAL; i++)
         if (out->pcm[i])
@@ -1503,6 +1515,7 @@
     config->sample_rate = out_get_sample_rate(&out->stream.common);
 
     out->standby = true;
+    /* out->muted = false; by calloc() */
 
     pthread_mutex_lock(&adev->lock);
     if (adev->outputs[type]) {