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;
filePath
First, 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 throughpdev2str
the functionplatform_device
and save it indev_name
an array. Then, use a loop to traverse from 0 to 63 and splice out afilePath
file path string named/dev/snd/pcmC%dD0p
, where %d is the loop variable i. Then, useaccess
a function to check if the file at that path exists. If the file under this path exists,access
the 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 theprofile->frontend.card
sound card. Finally, assignprofile->frontend.card
the value to*card
, as the return value of the function.