How does Android find the correct underlying ALSA kcontrol interface?

Source: Internet
Author: User

An snd_kcontrol was analyzed yesterday. It can be considered that the upper-layer application uses the name to identify the name to traverse the underlying snd_kcontrol linked list and find the matched kcontrol. See snd_ctl_find_id Function


[Csharp]/**
* Snd_ctl_find_id-find the control instance with the given id
* @ Card: the card instance
* @ Id: the id to search
*
* Finds the control instance with the given id from the card.
*
* Returns the pointer of the instance if found, or NULL if not.
*
* The caller must down card-> controls_rwsem before calling this function
* (If the race condition can happen ).
*/
Struct snd_kcontrol * snd_ctl_find_id (struct snd_card * card,
Struct snd_ctl_elem_id * id)
{
Struct snd_kcontrol * kctl;
 
If (snd_BUG_ON (! Card |! Id ))
Return NULL;
If (id-> numid! = 0)
Return snd_ctl_find_numid (card, id-> numid );
List_for_each_entry (kctl, & card-> controls, list ){
If (kctl-> id. iface! = Id-> iface)
Continue;
If (kctl-> id. device! = Id-> device)
Continue;
If (kctl-> id. subdevice! = Id-> subdevice)
Continue;
If (strncmp (kctl-> id. name, id-> name, sizeof (kctl-> id. name )))
Continue;
If (kctl-> id. index> id-> index)
Continue;
If (kctl-> id. index + kctl-> count <= id-> index)
Continue;
Return kctl;
}
Return NULL;
}
/**
* Snd_ctl_find_id-find the control instance with the given id
* @ Card: the card instance
* @ Id: the id to search
*
* Finds the control instance with the given id from the card.
*
* Returns the pointer of the instance if found, or NULL if not.
*
* The caller must down card-> controls_rwsem before calling this function
* (If the race condition can happen ).
*/
Struct snd_kcontrol * snd_ctl_find_id (struct snd_card * card,
Struct snd_ctl_elem_id * id)
{
Struct snd_kcontrol * kctl;

If (snd_BUG_ON (! Card |! Id ))
Return NULL;
If (id-> numid! = 0)
Return snd_ctl_find_numid (card, id-> numid );
List_for_each_entry (kctl, & card-> controls, list ){
If (kctl-> id. iface! = Id-> iface)
Continue;
If (kctl-> id. device! = Id-> device)
Continue;
If (kctl-> id. subdevice! = Id-> subdevice)
Continue;
If (strncmp (kctl-> id. name, id-> name, sizeof (kctl-> id. name )))
Continue;
If (kctl-> id. index> id-> index)
Continue;
If (kctl-> id. index + kctl-> count <= id-> index)
Continue;
Return kctl;
}
Return NULL;
}


When we continue to track the Android audio system today, we find that no matter what the connection between Android and snd_kcontrol is found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.

It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.

 


When we continue to track the Android audio system today, we find that no matter what the connection between Android and snd_kcontrol is found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.
It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.


When we continue to track the Android audio system today, we find that no matter what the connection between Android and snd_kcontrol is found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.
It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.


[Cpp] status_t AudioFlinger: setMasterVolume (float value)
{
// Check calling permissions
If (! SettingsAllowed ()){
Return PERMISSION_DENIED;
}
 
// When hw supports master volume, don't scale in sw mixer
AutoMutex lock (mHardwareLock );
MHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;
If (mAudioHardware-> setMasterVolume (value) = NO_ERROR ){
Value = 1.0f;
}
MHardwareStatus = AUDIO_HW_IDLE;
 
MMasterVolume = value;
For (uint32_t I = 0; I <mPlaybackThreads. size (); I ++)
MPlaybackThreads. valueAt (I)-> setMasterVolume (value );
 
Return NO_ERROR;
}
Status_t AudioFlinger: setMasterVolume (float value)
{
// Check calling permissions
If (! SettingsAllowed ()){
Return PERMISSION_DENIED;
}

// When hw supports master volume, don't scale in sw mixer
AutoMutex lock (mHardwareLock );
MHardwareStatus = AUDIO_HW_SET_MASTER_VOLUME;
If (mAudioHardware-> setMasterVolume (value) = NO_ERROR ){
Value = 1.0f;
}
MHardwareStatus = AUDIO_HW_IDLE;

MMasterVolume = value;
For (uint32_t I = 0; I <mPlaybackThreads. size (); I ++)
MPlaybackThreads. valueAt (I)-> setMasterVolume (value );

Return NO_ERROR;
} When I continued to track the Android audio system today, I found that no matter what the connection between Android and snd_kcontrol could be found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.

It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.


When we continue to track the Android audio system today, we find that no matter what the connection between Android and snd_kcontrol is found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.
It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.

 

Android allows developers to implement hw mixer at the HAL layer. When AudioFlinger detects the existence of hw mixer, it calls mAudioHardware-> setMasterVolume () to set the volume register, it does not scale the volume value. I have not explored how sw mixer uses the scale value in depth.

In the future, we will implement hw mixer to see the effect (EQ will also be implemented at that time). Now the volume setting is not linear and should be better controlled by hardware.

 


PS: You don't need to worry about the title. By default, Android does not look for the underlying kcontrol interface, but uses its own sw mixer.

 

 

 

When we continue to track the Android audio system today, we find that no matter what the connection between Android and snd_kcontrol is found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.
It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.

When we continue to track the Android audio system today, we find that no matter what the connection between Android and snd_kcontrol is found, whether it is the name or numid (numid printed by alsa_amixer controls, that is, the numid of the snd_kcontrol linked list element in the kernel layer. However, it can be used to adjust the volume. Later, I modified the Codec driver of the kernel, changed the kcontrol. name of the volume control to another string, and re-compiled it. Android can still control the volume.
It seems like it is controlled by numid. The article "Android audio HAL porting" mentions: "device switching requires joint debugging with the driver. For example, if the current earpiece id is 10, you can use amixer of ALSA to set the Enable and disable of earpiece and the size. The value of id must be provided by the driving colleagues ." However, it cannot be confirmed. No script file is found to save these values.

 


When I adjusted the volume, I printed the Codec register value and found that the volume register value did not change at all, but the volume actually changed. At that time, we suspected that our Android volume adjustment was not implemented by hardware, but by its own sw mixer mechanism. When I had dinner with Vic in the evening, I had a chat about it.

 

 

From xubin341719

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.