Android Bluetooth Stack: Bluedroid(五岁以下儿童):The analysis of A2DP Source
1. A2DP Introduction
The Advanced Audio Distribution Profile (A2DP) defines the protocols and procedures that realize distribution of audio content of high-quality in mono or stereo on ACL channels. As indicated in the diagram of 'Protocol Model', A2DP depends on AVDTP and SDP.
Protocol Model
The AVDTP define procedures required to set up an audio streaming. The A2DP defines parameters and procedures that are specific foraudio streaming, including audio codec, SDP parameters. It's the pre-condition of analyzing
A2DP Source implementation to familiar with the two specs: AVDTP and A2DP. The block diagrams of sending/receiving audio streaming and created packet format are shown in the diagram below. In the analysis, I only focus on MP and Media PL. AVDTP spec describes
MP, while A2DP spec describes Media PL. This profile support a mandatory codec: SBC, 3 optional codecs: MPEG-1,2 Audio, MPEG-2,4 AAC and ATRAC family, and the vendor specific A2DP codecs, eg. aptX. I will only talk about the mandatory codec: SBC in the article.
Block diagram of Audio Streaming Procedures and the Packet Format
The following roles are defined for devices that implement A2DP:
Source(SRC) – A device is the SRC when it acts as a source of a digital audio stream
that is delivered to the SNK of the piconet, eg. a smartphone which sends audio stream.
Sink (SNK) – A device is the SNK when it acts as a sink of a digital audio stream
delivered from the SRC on the same piconet, eg. a Bluetooth headset which receives audio stream.
In Bluedroid, only the source role is implemented, so I analysis the implementation of A2DP source in Bluedroid.(But both of source and sink are implemented in Bluez)
2. Code Analysis
I will not list very detailed function callings(The best way to understand the code is reading the code by yourself), while just describe the process. So you will not read a lot of the boring source code.
2.1 Files Structure
I list the important files for A2DP from the upper layer to lower layger.
- btif/src/btif_av.c Bluedroid AV HAL implementation which implements the interface defined in AOSP/hardware/bt_av.h.
- btif/src/btif_media_task.c This is the multimedia module for the BTIF system. It contains task implementations AV, HS and HF profiles' audio&video processing.
- btif/co/bta_av_co.c This is the advanced audio/video call-out function implementation for BTIF.
- bta/av/bta_av_ci.c This is the implementation for advanced audio/video call-in functions which are called from BTIF.
- bta/av/bta_av_api.c This is the implementation of the API for the advanced audio/video(AV) subsystem of BTA. This interface is called from btif_av.c.
- bta/av/bta_av_mian.c This is the main implementation file for BTA advanced audio/video.
- bta/av/bta_av_ssm.c This is the stream state machine for the BTA advanced audio/video.
- bta/av/bta_av_aact.c This file contains action functions for advanced audio/video stream.
- bta/av/bta_av_sbc.c This module contains utility functions for dealing with SBC data frames and codec capabilities.
- stack/a2dp/a2d_api.c This is the implementation of the API for the Advanced Audio Distribution Profile(A2DP)
- stack/a2dp/a2d_sbc.c This file contains utility functions to help build and parse SBC codec information element and media payload.
- embdrv/sbc/sbc/encoder This folder contains the files which implement SBC decoder.
2.2 Transfer Audio data to AVDTP via A2DP
The transferring process is handle with 'btif_media_task' which is A2DP media task for SBC encoder. The task is created when Bluetooth is enabled(see btif_enable_bluetooth_evt() in btif/src/btif_core.c). A timer drives the task to encoder and transfer audio
stream. The timer is started in btif_media_task_aa_start_tx() when the 'audio_stream_out' interface has a PCM data buffer ready to write(see hardware/libhardware/include/hardware/audio.h). On receiving the timer event, the task handles all ready PCM data
buffers. If stream is started, run the SBC encoder on each chunk of PCM samples and build an output packet consisting of one or more encoded SBC frames.
The diagram is the flowchart of transferring audio data to AVDTP. The blue blocks are in 'btif', the red blocks are in 'bta/av', and the yellow blocks are in 'stack/avdt'.
- BTIF reads PCM data from audio flinger via Audio HAL.(Step 6)
- BTIF calls SBC encoder to encode PCM data to SBC frames which are put in a queue.(Step 7 and 8)
- BTIF notifies BTA that the source data is ready in the queue.(Step 9~13)
- BTA gets the SBC frames from the queue, then adds SBC Header. Media PL is constructed now.(Step 15~17)
- BTA writes Media PL to AVDTP.(Step 18)
- AVDTP adds Media Packet Header.(Step 19)
2.3 Implement Audio HAL for A2DP audio device
audio_stream_out in Audio HAL defines the abstract interface for the audio output hardware. It provides information about various properties of the audio output hardware driver. We must implement audio_stream_out for A2DP audio device to output the audio
from Audio Flinger to Bluetooth stack. The interface is defined in AOSP/hardware/libhardware/audio.h. Bluedroid implements the interface in AOSP/external/bluetooth/bluedroid/audio_a2dp_hw.
socket is used for IPC between Audio HAL and BTIF. Two sockets are defined in audio_a2dp_hw.h:
#define A2DP_CTRL_PATH "/data/misc/bluedroid/.a2dp_ctrl"
#define A2DP_DATA_PATH "/data/misc/bluedroid/.a2dp_data"
A2DP_CTRL_PATH is a command socket, while A2DP_DATA_PATH is a data socket. BTIF defines two channels which are mapped to the two sockets in UIPC_Open() in udrv/ulinux/uipc.c. The channel IDs are UIPC_CH_ID_AV_CTRL and UIPC_CH_ID_AV_AUDIO. Setp 6 in the flowchart
reads the PCM data from Audio HAL to BTIF with the channel ID: UIPC_CH_ID_AV_AUDIO.
3 Summary
Bluedroid in AOSP does not support all the features of A2DP. Source role is implemented, but Sink role is not implemented(Bluez implements both of them). SBC is supported in Bluedroid, while other codecs are not supported. The vendor can not add a new codec
plugin easily, we have to modify the code in Bluedroid. And there are many small bugs in Bluedroid. So the improvements are needed for Bluedroid.
版权声明:本文博主原创文章,博客,未经同意不得转载。
Android Bluetooth Stack: Bluedroid(五岁以下儿童):The analysis of A2DP Source的更多相关文章
- bluetooth发展(五岁以下儿童)------蓝牙功能测试(一个)
newton板已出版.下面再组织我调试的一小方面,,蓝牙功能的实现和测试: 转载请注明出处:http://blog.csdn.net/wang_zheng_kai 以下是我写的newton开发板中bl ...
- [Android] Volley源代码分析(五岁以下儿童)Q \\ u0026一个
Volley源代码分析系列那里一段时间,告诉我,有许多私人留言,同时一些问题抛出.对于一些简单的问题,我们跳,这两天被连接到朋友@smali提出的问题.告诉我你不得不赞叹查看源代码时的详细程度,大家一 ...
- (五岁以下儿童)NS3样本演示:桥模块演示样品csma-bridge.cc凝视程序
(五岁以下儿童)NS3:桥模块演示样品csma-bridge.cc凝视程序 1.Ns3 bridge模csma-bridge.cc演示示例程序的目光 // Network topology // // ...
- linux下一个Oracle11g RAC建立(五岁以下儿童)
linux下一个Oracle11g RAC建立(五岁以下儿童) 四.建立主机之间的信任关系(node1.node2) 建立节点之间oracle .grid 用户之间的信任(通过ssh 建立公钥和私钥) ...
- python学习笔记(五岁以下儿童)深深浅浅的副本复印件,文件和文件夹
python学习笔记(五岁以下儿童) 深拷贝-浅拷贝 浅拷贝就是对引用的拷贝(仅仅拷贝父对象) 深拷贝就是对对象的资源拷贝 普通的复制,仅仅是添加了一个指向同一个地址空间的"标签" ...
- PE文件结构(五岁以下儿童)基地搬迁
PE文件结构(五岁以下儿童) 參考 书:<加密与解密> 视频:小甲鱼 解密系列 视频 基址重定位 链接器生成一个PE文件时,它会如果程序被装入时使用的默认ImageBase基地址(VC默认 ...
- android网络开源框架volley(五岁以下儿童)——volley一些细节
最近的一次volley整理出下一个.我以前没有再次遭遇了一些小问题,在该记录: 1.HttpUrlConnection DELETE 信息不能加入body问题:java.net.ProtocolExc ...
- Android设计模式(五岁以下儿童)--简单工厂模式
1.面试的时候问这个问题: 在ListView 的item小程序.很多不同的显示风格.或者是,为了更好地维护,不同的样式,应该怎么做? 我一下就想到的是工厂的模式,利用project,编写ViewFa ...
- ExtJs4得知(五岁以下儿童)主要的Ext分类
Ext类是ExtJs最常见的.最基本的类,它是一个全局对象,它封装了全班.辛格尔顿和 Sencha 该方法提供了一种有用的库. 嵌套在该命名空间中一个较低的水平最用户界面组件. 但是提供了很多有用的功 ...
随机推荐
- Spring.Net控制翻转、依赖注入、面向切面编程
Spring.Net快速入门:控制翻转.依赖注入.面向切面编程 Spring.Net主要功能: 1.IoC:控制翻转(Inversion of Control) 理解成抽象工厂翻转控制:就是创建对象 ...
- 大约session_cached_cursors在不同的db在默认不同的版本号
大约session_cached_cursors的值,不同db版本号具有不同的默认值: 9i是 0 10.1 0 10.2 是20 11.1 是50 11.2 是50 12.1 是50 值值得注意的是 ...
- C# 字符串知识整理
新知识点,只是对于本人来说而已. 系统处理文本的方式 [新知识点].NET Framework .NET Framework的定义:其包含了一个公共语言运行时(Common Language Runt ...
- oracle Constraint[相似 constraint使用方法总结 I]
约束简单介绍 约束用于确保数据库数据满足特定的商业逻辑或者企业规则,假设定义了约束,而且数据不符 合约束,那么DML操作(INSERT.UPDATE.DELETE)将不能成功运行.约束包含NOT NU ...
- POJ 3207 Ikki's Story IV - Panda's Trick (2-SAT)
职务地址:id=3207">POJ 3207 找好矛盾关系.矛盾关系是(2,5)和(3,6)这两个仅仅能一个在外边,一个在里边.利用这个矛盾关系来建图. 能够用在外边和里边来当1和0, ...
- 7.oracle学习门户系列七---网络管理和配置
oracle学习门户系列七 网络管理和配置 们学习了模式和用户.包含模式定义以及模式的作用. 这篇我么来看下ORACLE数据库中的网络管理和配置.只是这篇好像和上篇没有继承啊.这怎么看? Ok,事实上 ...
- Java之旅(三)--- JSTL和EL表情
先给大家看一段JSP的代码.看看有什么感受? <% List<UsEL> usELList = pageModel.getList(); for (ItELator<Us ...
- Java它配备了一个很好的工具2
Jconsole 本机java自带的系统monitor具,它也可以连接到的本地远程连接java process,联系java process申请后可查看CPU,内存,主题.GC事件,能帮忙看看系统是否 ...
- SharePoint 2013 禁用搜索服务
原文:SharePoint 2013 禁用搜索服务 前言,在SharePoint2013中,对于硬件需求的提升,让我们虚机里安装总是一筹莫展,尤其开启了搜索服务以后,对于内存的消耗就更加严重,尤其对于 ...
- 由一道面试题想到的:Finally
找工作时,有这样一道题: try{}里面有一条return语句,那么紧跟在这个try后的finally{}里的代码会不会执行,什么时候执行,在return之前还是之后? 我没有怎么思考,根据脑子里仅有 ...