Android10 connects USB camera and restarts the device, no sound

1. Problem description

        Connect the USB camera, plug in the speaker, and restart the device. Sometimes there is sound, sometimes not.

Two, the cause of the problem

        Reason: After plugging in the USB setup card, there are two more sound cards. After restarting, it is uncertain which sound card node is generated first. However, only the first node is opened in the hal layer, and the USB sound card does not have the playback function, so there is no playback in the node. node, so there is no sound

3. Solution

        Modify HAL to detect whether the playback sound card of each node exists, and if it exists, use that node to play the sound.
--- a/hal/platform.c
+++ b/hal/platform.c
@@ -1175,6 +1175,7 @@ int get_platform_snd_card_config(int *card, int *port,
     struct pdev_profile *profile = NULL;
     char dev_name[50];
     unsigned int i;
+    char filePath[128]={0};
 
     pdev2str(dev_name, platform_device);
 
@@ -1193,6 +1194,17 @@ int get_platform_snd_card_config(int *card, int *port,
         return -1;
     }
 
+    for(i=0;i<64;i++){
+       memset(filePath, 0, sizeof(filePath));
+       sprintf(filePath,"/dev/snd/pcmC%dD0p",i);
+       if(!access(filePath,0)){
+            break;
+       }
+    }
+    if(i != 64){
+        profile->frontend.card = i;
+    }
+    
     /* get snd_card_config */
     *card = profile->frontend.card;
     *port = profile->frontend.port;

filePathFirst, a character array named is         declared to store the file path. The size of this array is 128 bytes. Next, convert it to a string through pdev2strthe function platform_deviceand save it in dev_namean array. Then, use a loop to traverse from 0 to 63 and splice out a filePathfile path string named /dev/snd/pcmC%dD0p, where %d is the loop variable i. Then, use accessa function to check if the file at that path exists. If the file under this path exists, accessthe function will return 0 and break out of the loop. Next, check whether the loop variable i is equal to 64. If it is not equal, it means that an existing file path was found in the previous loop and assigned to it, that is, the configuration of the profile->frontend.cardsound card. Finally, assign profile->frontend.cardthe value to *card, as the return value of the function.

Guess you like

Origin blog.csdn.net/qq_53676406/article/details/132203316