Android audio 输出设备选择过程分析(下)

上篇的分析到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",        
  ...
}

播放录音,电话,

  • 7
    点赞
  • 57
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值