OSDN Git Service

Enable audio channels and set default volume
authorJoshua Lang <joshualang@google.com>
Wed, 2 Nov 2016 21:29:21 +0000 (14:29 -0700)
committerJoshua Lang <joshualang@google.com>
Thu, 19 Jan 2017 20:46:54 +0000 (12:46 -0800)
This fixes the audio device being muted by default.

Test: Boot emulator and check audio is not muted
Change-Id: Ied6b02910dcb23fdebd3b8a1e3f8ec23d2d78ff1

audio/audio_hw.c

index 393494b..4efd67b 100644 (file)
@@ -47,6 +47,7 @@ struct generic_audio_device {
     struct audio_hw_device device; // Constant after init
     pthread_mutex_t lock;
     bool mic_mute;                 // Proteced by this->lock
+    struct mixer* mixer;           // Proteced by this->lock
 };
 
 /* If not NULL, this is a pointer to the fallback module.
@@ -977,6 +978,9 @@ static int adev_close(hw_device_t *dev)
     }
 
     if ((--audio_device_ref_count) == 0) {
+        if (adev->mixer) {
+            mixer_close(adev->mixer);
+        }
         free(adev);
     }
 
@@ -1035,6 +1039,32 @@ static int adev_open(const hw_module_t* module, const char* name,
 
     *device = &adev->device.common;
 
+    adev->mixer = mixer_open(PCM_CARD);
+    struct mixer_ctl *ctl;
+
+    // Set default mixer ctls
+    // Enable channels and set volume
+    for (int i = 0; i < (int)mixer_get_num_ctls(adev->mixer); i++) {
+        ctl = mixer_get_ctl(adev->mixer, i);
+        ALOGD("mixer %d name %s", i, mixer_ctl_get_name(ctl));
+        if (!strcmp(mixer_ctl_get_name(ctl), "Master Playback Volume") ||
+            !strcmp(mixer_ctl_get_name(ctl), "Capture Volume")) {
+            for (int z = 0; z < (int)mixer_ctl_get_num_values(ctl); z++) {
+                ALOGD("set ctl %d to %d", z, 100);
+                mixer_ctl_set_percent(ctl, z, 100);
+            }
+            continue;
+        }
+        if (!strcmp(mixer_ctl_get_name(ctl), "Master Playback Switch") ||
+            !strcmp(mixer_ctl_get_name(ctl), "Capture Switch")) {
+            for (int z = 0; z < (int)mixer_ctl_get_num_values(ctl); z++) {
+                ALOGD("set ctl %d to %d", z, 1);
+                mixer_ctl_set_value(ctl, z, 1);
+            }
+            continue;
+        }
+    }
+
     audio_device_ref_count++;
 
 unlock: