android audio arch

来源:互联网 发布:环境一号卫星数据下载 编辑:程序博客网 时间:2024/05/20 13:15

原址

ALSA System on Chip(ASoC)

ASoC 驱动将一个audio子系统分成四个部分:

Machine driver, Platform driver, CPU driver以及Codec driver。

Machine 驱动

  • 将平台,CPU以及codec驱动绑定在一块
  • 实现在kernel/sound/soc/msm/<chipset.c>
  • 定义前端FE和后端BE,DAI(digital audio interface) links

platform 驱动

  • 包括了平台相关的音频数据流的传输和路由的控制
  • 被区分成FE和BE两个平台驱动

FE

  • Audio -例化PCM播放和采集,将播放的pcm数据从用户空间传递给DSP,采集是逆过程,高通使用ASM接口,实现于kernel/sound/soc/msm-pcm-q6.c
  • Voice-初始化和销毁语音电话建立,实现与kernel/sound/soc/msm-pcm-voice-v2.c
  • VoIP-初始化和销毁MVS接口在DSP和用户空间互传数据。kernel/sound/soc/msm-pcm-voip-v2.c
  • Compress offload-Compress offload 播放数据传输到DSP。kernel/sound/soc/msm-compress-q6-v2.c

BE

  • Routing-audio 通路选择,kernel/sound/soc/msm-pcm-routing-v2.c

CPU driver

分为FE和BE CPU驱动

FE

  • 提供了ALSA SoC framework需要的FE PCM设备信息,由平台驱动提供的ASoC framework和音频路由表可以指示PCM 播放/采集。
  • FE CPU DAI实现于kernel/sound/soc/msm/msm-dai-fe.c

BE

  • 根据初始化的PCM播放和采集配置DSP AFE模块对应的audio 音频端口
  • 定义了BE CPU DAI实现于kernel/sound/soc/msm/qdsp6v2/msm-dai-q6-v2.c

Codec 驱动

UserSpcace Moudles

  • Audio Hardware Abstraction Layer(AHAL)-使用tinyalsa将AudioFlinger调用映射到ASoC驱动
  • tinyalsa-kernel ASoC驱动接口,AHAL使用,提供了stream和设备管理需要的基本PCM和Mixer控制API
  • Audio Route-该模块从XML文件读取ALSA mixer 控制器,并根据AHAL设置mixer控制器。
  • Multimedia framework-StageFright  1)使用标准音频格式的播放和采集;2)和编解码库以及OpenMAX IL组件通信,实现音频编解码
  • Audio service  1)运行时服务,由system server启动,service manager 管理;2)注册intents,当接收到来自不同应用(HDMI,Bluetooth)的信息后通知Audio系统
  • Audio Flinger  1)通过libaudio, 蓝牙A2DP管理所有音频输入/输出设备, 2)将多个audio stream合成单一PCM,混合的output输出源被路由给输出设备  3) music stream播放的音量控制
  • Audio Policy Manager(APM)--1)定义了多个音频源并发的管理策略  2)设置场景(电话,音乐,系统音,通知)  3)定义了音频类型(语音,播放,ring)在何种设备上播放(Bluetooth, speaker, headset) 
  • APM的职责如下  1)管理各种输入/输出设备接口  2)管理各种输入/输出设备,mic/speaker/headphone/headset/A2DP以及Bluetooth SCO, 3)基于stream模式选择和定义合适的路由策略 4)管理每一个stream的音量

Audio Output Stream and Volume Control

  • 缺省的音频输出(primary output)使用AudioFlinger中的Mixer线程,音量和音效将在Flinger中使用
  • Lowlatency输出使用AudioFlinger中的快速mixer,音量控制在Flinger中
  • Compress offload播放使用Audio Flinger中的compress offload 线程,音量和音效在DSP中。
  • VoIP播放在AudioFlinger中的mixerThread,Volume和echo cancelation由DSP完成。

设备和流管理

Frontend DAI

  • 对用户空间作为PCM设备可见
  • 可以将Audio路由到多个BE DAI
  • Routing由用户空间mixer控制
  • PCM由ALSA直接控制
  • 定义与msm-dai-fe.c
    [cpp] view plain copy
    1. static struct snd_soc_dai_driver msm_fe_dais[]={  
    2.   .playback = {  
    3.      .stream_name = "Multimedia1 Playback",  
    4.      .aif_name = "MM_DL1",  
    5.      .rates  
    6. ...  
    7.   }  
    8.   
    9. }  

当front DAI使能时,AIF将会被使能。

代码分布

用户空间和audio相关的代码

用于调试和定制化:

[plain] view plain copy
  1. <APSS_BUILD>/hardware/qcom/audio/hal/msm8974 – Contains the audio Hardware Abstraction Layer (HAL)-related code  
  2.   
  3. <APSS_BUILD>/external/tinyalsa/ – Contains the code related to tinymix, tinyplay, and tinycap  
  4.   
  5. <APSS_BUILD>/hardware/qcom/audio/mm-audio – Contains the implementation of QTI OMX components for the audio encoder and decoders  
  6.   
  7. <APSS_BUILD>/frameworks/av/media/libstagefright/ – Contains the source code for Google’s Stagefright implementation  
  8.   
  9. <APSS_BUILD>/frameworks/av/media/libmediaplayerservice/nuplayer - Contains the source code for Google’s nuplayer implementation  
  10.   
  11. <APSS_BUILD>/frameworks/av/services/audioflinger/ – Contains the source code for AudioFlinger that manages audio streams from the user space  
  12.   
  13. <APSS_BUILD>/vendor/qcom/proprietary/mm-audio/ – Contains the code related to the Audio Calibration Database (ACDB) driver, parsers for DTS and AC3, surround sound, SVA, etc.  
  14.   
  15. <APSS_BUILD>/external/bluetooth/bluedroid/ – Contains the code related to Bluetooth® (BT) A2DP used in a QTI platform  
  16.   
  17. <APSS_BUILD>/external/bluetooth/bluedroid/audio_a2dp_hw/ – Contains the A2DP audio HAL implementation  
  18.   
  19. <APSS_BUILD>/hardware/libhardware/modules/usbaudio/ – Contains the USB HAL implementation for a USB dock use case  
  20.   
  21. <APSS_BUILD>/hardware/qcom/audio/hal/audio_extn/:  
  22.   
  23. audio_extn.c – Implements the wrapper function for audio extension features, such as FM, Dolby, Compress capture, HFP, SVA (listen), speaker protection, SSR, USB audio over headset  
  24.   
  25. usb.c – Contains the HAL implementation for USB playback and record over the headset  
  26.   
  27. compress_capture.c – Contains the HAL implementation for Compress capture  
  28.   
  29. dolby.c – Contains the HAL implementation for the Dolby postprocessing feature  
  30.   
  31. fm.c – Contains the HAL implementation for the FM playback and recording feature  
  32.   
  33. hfp.c – Contains the HAL implementation for the hands-free profile feature where the MSM™ chipset can be used as as a BT headset device  
  34.   
  35. listen.c – Contains the HAL implementation for the Snapdragon™ Voice Activation (SVA) feature  
  36.   
  37. spkr_protection.c – Contains the HAL implementation for the speaker protection feature  
  38.   
  39. ssr.c – Contains the HAL implementation for the surround sound recording feature  
  40.   
  41. <APSS_BUILD>/vendor/qcom/proprietary/wfd/mm/source/framework/src/ – Contains the Wi-Fi Display (WFD) frameworks-related code; WFDMMSourceAudioSource.cpp configures the RT Proxy port via ALSA APIs and gets the PCM data from the audio layer  
  42.   
  43. <APSS_BUILD>/system/core/include/system/ – Contains audio.h and audio_policy.h that contain enum definitions and inline functions used all over the code for audio in the user space  
  44.   
  45. <APSS_BUILD>/frameworks/base/media/java/android/media/ – Contains .java files for audio that expose APIs that can be called by Android™ applications written in Java  

内核空间代码

[plain] view plain copy
  1. <APSS_BUILD>/kernel/sound/soc/msm/ – Contains the msm8994.c machine driver  
  2.   
  3. <APSS_BUILD>/kernel/sound/soc/msm/qdsp6v2 – Contains the source code for the platform drivers, Frontend (FE), and Backend (BE) DAI driver, QDSP drivers for AFE, ADM, and ASM, voice driver, etc.  
  4.   
  5. <APSS_BUILD>/kernel/sound/soc/soc-*.c – All the soc-*.c files provide information on the ALSA SOC framework  
  6.   
  7. <APSS_BUILD>/kernel/drivers/slimbus/ – Contains the source for the SLIMbus driver  
  8.   
  9. <APSS_BUILD>/kernel/arch/arm/mach-msm/qdsp6v2/ – Contains the drivers for DSP-based encoders and decoders, code for the ADSP loader, APR driver, Ion memory driver, and other utility files  
  10.   
  11. <APSS_BUILD>//LINUX/android/kernel/arch/arm/boot/dts – Contains msm8994-*.dtsi files that contain MSM8994-specific information;board-specific information on the MSM8994;GPIO management ; audio-related customization is available in files such as msm8994.dtsi, msm8994-mtp.dtsi, and msm8994-cdp.dtsi  
  12.   
  13. <APSS_BUILD>/LINUX/android//kernel/sound/soc/codecs/ – Contains the source code for the codec driver for WCD9330; codec driver-related source files are wcd9330.c, wcd9xxx-mbhc.c, wcd9xxx-resmgr.c, wcd9xxx-common.c, etc.  
  14.   
  15. <APSS_BUILD>//LINUX/android/kernel/drivers/mfd/ – Contains the source code for the codec driver; wcd9xxx-core.c, wcd9xxx-slimslave.c, and wcd9xxx-irq.c are the codec driver-related files