上篇的分析到audio_route,现在接个力,也算是7月的作业,再不交这个月就落下了。
audio_route_apply_and_update_path分两个过程,从函数名字都能看出来,一个是apply,一个是updata:
audio_route_apply_path
/* Apply an audio route path by name */
int audio_route_apply_path(struct audio_route *ar, const char *name)
{
struct mixer_path *path;
...
path = path_get_by_name(ar, name);
...
path_apply(ar, path);
return 0;
}
path是一个struct:
struct mixer_path {
char *name;
unsigned int size;
unsigned int length;
struct mixer_setting *setting;
};
内含struct mixer_setting:
struct mixer_setting {
unsigned int ctl_index;
unsigned int num_values;
unsigned int type;
union ctl_values value;
};
好吧,还套了个ctl_values:
union ctl_values {
int *enumerated;
long *integer;
void *ptr;
unsigned char *bytes;
};
背景知识先来这么多,先继续看代码
path_get_by_name(ar, name)这个调用返回了一个mixer_path指针。
static struct mixer_path *path_get_by_name(struct audio_route *ar,
const char *name)
{
unsigned int i;
for (i = 0; i < ar->num_mixer_paths; i++)
if (strcmp(ar->mixer_path[i].name, name) == 0)
return &ar->mixer_path[i];
return NULL;
}
看到代码简单,老夫长舒一口气!
无论怎么样我们还是需要去查证两个参数,ar和name.
name简单一些:
//audio_hw.c
strlcpy(mixer_path, use_case_table[usecase->id], MIXER_PATH_MAX_LENGTH);
...
audio_route_apply_and_update_path(adev->audio_route, mixer_path);//name的源头
mixer_path来自use_case_table[usecase->id],列举几个常见的(我常见的<(__)>):
const char * const use_case_table[AUDIO_USECASE_MAX] = {
...
[USECASE_AUDIO_PLAYBACK_DEEP_BUFFER] = "deep-buffer-playback",
[USECASE_AUDIO_PLAYBACK_LOW_LATENCY] = "low-latency-playback",
[USECASE_AUDIO_RECORD] = "audio-record",
[USECASE_AUDIO_PLAYBACK_FM] = "play-fm",
[USECASE_AUDIO_HFP_SCO_UPLINK] = "hfp-sco",
[USECASE_VOICE_CALL] = "voice-call",
...
}
播放录音,电话,