[RK3288][Android7.1]强制使用默认声卡播放声音

[RK3288][Android7.1]强制使用默认声卡播放声音

Platform: Rockchip
OS: Android 7.1.2
Kernel: 4.4

问题分析
当插上USB录音设备开机时,由于USB声卡被优先挂载,导致系统声卡不出声音,因此需要将系统声卡固定成默认播放声卡
解决方案
1、使用cat proc/asound/cards命令打印出系统声卡的名字。
2、在系统中强制使用系统声卡做为默认声卡

--- a/hardware/rockchip/audio/tinyalsa_hal/alsa_route.c
+++ b/hardware/rockchip/audio/tinyalsa_hal/alsa_route.c
@@ -58,26 +58,26 @@ struct mixer* mMixerCapture;
  */
 int route_init(void)
 {
-    char soundCardID[20] = "";
+    char soundCardID[20] = "rockchipes8316c";
     static FILE * fp;
     unsigned i, config_count = sizeof(sound_card_config_list) / sizeof(struct alsa_sound_card_config);
-    size_t read_size;
+    size_t read_size=15;
 
     ALOGV("route_init()");
 
-    fp = fopen("/proc/asound/card0/id", "rt");
-    if (!fp) {
-        ALOGE("Open sound card0 id error!");
-    } else {
-        read_size = fread(soundCardID, sizeof(char), sizeof(soundCardID), fp);
-        fclose(fp);
+    //fp = fopen("/proc/asound/card0/id", "rt");
+    //if (!fp) {
+    //    ALOGE("Open sound card0 id error!");
+    //} else {
+    //    read_size = fread(soundCardID, sizeof(char), sizeof(soundCardID), fp);
+    //    fclose(fp);
 
         if (soundCardID[read_size - 1] == '\n') {
             read_size--;
             soundCardID[read_size] = '\0';
         }
 
-        ALOGV("Sound card0 is %s", soundCardID);
+        ALOGD("Sound card0 is %s", soundCardID);
 
         for (i = 0; i < config_count; i++) {
             if (!(sound_card_config_list + i) || !sound_card_config_list[i].sound_card_name ||
@@ -90,7 +90,7 @@ int route_init(void)
                 ALOGD("Get route table for sound card0 %s", soundCardID);
             }
         }
-    }
+    //}
 
     if (!route_table) {
         route_table = &default_config_table;
diff --git a/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c b/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c
index 0a35b80..652a5e7 100755
--- a/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c
+++ b/hardware/rockchip/audio/tinyalsa_hal/audio_hw.c
@@ -472,8 +472,14 @@ static int read_snd_card_info(void)
         PCM_CARD =1;
     }else if(strstr(buf0,"rockchiprt5640c")){
         PCM_CARD_HDMI = 0;
-               PCM_CARD = 0;
-       }
+        PCM_CARD = 0;
+    }else if(strstr(buf1,"rockchipes8316c")){
+        PCM_CARD_HDMI = 1;
+        PCM_CARD = 1;
+    }else if(strstr(buf2,"rockchipes8316c")){
+        PCM_CARD_HDMI = 2;
+        PCM_CARD = 2;
+    }

你可能感兴趣的:(Rockchip)