[RK3288][Android6.0] Audio录音HAL层的数据读取流程分析

Platform: Rockchip
OS: Android 6.0
Kernel: 3.10.92

用原生SoundRecorder apk为例,以sample rate, channel及buffer size这些参数为线索来跟踪,,流程如下:
openRecord_l ->
    AudioSystem::getInputForAttr ->
        aps->getInputForAttr ->
            AudioPolicyManager::getInputForAttr ->
                getInputProfile ->    根据上apk给的profileSamplingRate, profileFormat以及profileChannelMask找到对应的profile
                mpClientInterface->openInput -> 上层的录音参数传递给HAL.
                    AudioFlinger::openInput_l ->
                        inHwHal->open_input_stream ->
                        adev_open_input_stream ->    audio_hw.c
static int adev_open_input_stream(struct audio_hw_device *dev,
                                  audio_io_handle_t handle,
                                  audio_devices_t devices,
                                  struct audio_config *config,    
                                  struct audio_stream_in **stream_in,    //传进来是新的
                                  audio_input_flags_t flags,
                                  const char *address __unused,
                                  audio_source_t source __unused)
{
    struct audio_device *adev = (struct audio_device *)dev;
    struct stream_in *in;
    int ret;

    *stream_in = NULL;
    //不管它传进来是哪种,直接定死为双声道.
    config->channel_mask = AUDIO_CHANNEL_IN_STEREO;
#ifdef ALSA_IN_DEBUG
    //用来调试抓取pcm数据
    in_debug = fopen("/data/debug.pcm","wb");//please touch /data/debug.pcm first
#endif

......
    in = (struct stream_in *)calloc(1, sizeof(struct stream_in));
    if (!in)
        return -ENOMEM;
......
    //SoundRecorder apk使用的是8kHz的采样率.
    in->requested_rate = config->sample_rate;
......
    //上面定死为双通道.
    in->channel_mask = config->channel_mask;
......
    //默认用的是pcm_config_in
    //struct pcm_config pcm_config_in = {
    //.channels = 2,
    //.rate = 44100,
    //.period_size = 16,
    //.period_count = 128,
    //.format = PCM_FORMAT_S16_LE,
    //};
    struct pcm_config *pcm_config = flags & AUDIO_INPUT_FLAG_FAST ?
            &pcm_config_in_low_latency : &pcm_config_in;
    in->config = pcm_config;
    //用
  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 33
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值