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'.

  1. BTIF reads PCM data from audio flinger via Audio HAL.(Step 6)
  2. BTIF calls SBC encoder to encode PCM data to SBC frames which are put in a queue.(Step 7 and 8)
  3. BTIF notifies BTA that the source data is ready in the queue.(Step 9~13)
  4. BTA gets the SBC frames from the queue, then adds SBC Header. Media PL is constructed now.(Step 15~17)
  5. BTA writes Media PL to AVDTP.(Step 18)
  6. 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的更多相关文章

  1. bluetooth发展(五岁以下儿童)------蓝牙功能测试(一个)

    newton板已出版.下面再组织我调试的一小方面,,蓝牙功能的实现和测试: 转载请注明出处:http://blog.csdn.net/wang_zheng_kai 以下是我写的newton开发板中bl ...

  2. [Android] Volley源代码分析(五岁以下儿童)Q \\ u0026一个

    Volley源代码分析系列那里一段时间,告诉我,有许多私人留言,同时一些问题抛出.对于一些简单的问题,我们跳,这两天被连接到朋友@smali提出的问题.告诉我你不得不赞叹查看源代码时的详细程度,大家一 ...

  3. (五岁以下儿童)NS3样本演示:桥模块演示样品csma-bridge.cc凝视程序

    (五岁以下儿童)NS3:桥模块演示样品csma-bridge.cc凝视程序 1.Ns3 bridge模csma-bridge.cc演示示例程序的目光 // Network topology // // ...

  4. linux下一个Oracle11g RAC建立(五岁以下儿童)

    linux下一个Oracle11g RAC建立(五岁以下儿童) 四.建立主机之间的信任关系(node1.node2) 建立节点之间oracle .grid 用户之间的信任(通过ssh 建立公钥和私钥) ...

  5. python学习笔记(五岁以下儿童)深深浅浅的副本复印件,文件和文件夹

    python学习笔记(五岁以下儿童) 深拷贝-浅拷贝 浅拷贝就是对引用的拷贝(仅仅拷贝父对象) 深拷贝就是对对象的资源拷贝 普通的复制,仅仅是添加了一个指向同一个地址空间的"标签" ...

  6. PE文件结构(五岁以下儿童)基地搬迁

    PE文件结构(五岁以下儿童) 參考 书:<加密与解密> 视频:小甲鱼 解密系列 视频 基址重定位 链接器生成一个PE文件时,它会如果程序被装入时使用的默认ImageBase基地址(VC默认 ...

  7. android网络开源框架volley(五岁以下儿童)——volley一些细节

    最近的一次volley整理出下一个.我以前没有再次遭遇了一些小问题,在该记录: 1.HttpUrlConnection DELETE 信息不能加入body问题:java.net.ProtocolExc ...

  8. Android设计模式(五岁以下儿童)--简单工厂模式

    1.面试的时候问这个问题: 在ListView 的item小程序.很多不同的显示风格.或者是,为了更好地维护,不同的样式,应该怎么做? 我一下就想到的是工厂的模式,利用project,编写ViewFa ...

  9. ExtJs4得知(五岁以下儿童)主要的Ext分类

    Ext类是ExtJs最常见的.最基本的类,它是一个全局对象,它封装了全班.辛格尔顿和 Sencha 该方法提供了一种有用的库. 嵌套在该命名空间中一个较低的水平最用户界面组件. 但是提供了很多有用的功 ...

随机推荐

  1. 开发随笔——NOT IN vs NOT EXISTS

    原文:开发随笔--NOT IN vs NOT EXISTS 原文出处: http://blog.csdn.net/dba_huangzj/article/details/31374037  转载请引用 ...

  2. 一C++PSO(PSO)算法

    收集和变化PSO算法,它可用于参考实施: #include <cstring> #include <iostream> #include <cmath> #incl ...

  3. 分散式-ubuntu12.04安装hadoop1.2.1

    在hadoop1.2.1被预装在一份报告中安装说明java.我装了很多的版本号java以及许多的版本号hadoop,然后发现oracle-java7与hadoop1.2.1能够匹配. 一,安装详细过程 ...

  4. HDU 5012 Dice (BFS)

    事实上是非常水的一道bfs,用字符串表示每一个状态,map判重就ok了. 题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5012 #include&l ...

  5. hdu1115(重力算法的多边形中心)

    标题的含义: 给定一个n刚n顶点.这是获得n分众协调多边形. http://acm.hdu.edu.cn/showproblem.php? pid=1115 题目分析: /** *出处:http:// ...

  6. Android学习之RecyclerView

    RecyclerView是android-support-v7-21版本号中新增的一个Widget,官方介绍RecyclerView 是 ListView 的升级版本号,更加先进和灵活. 开发环境 - ...

  7. (大数据工程师学习路径)第一步 Linux 基础入门----Linux 下软件安装

    介绍 介绍 Ubuntu 下软件安装的几种方式,及 apt,dpkg 工具的使用. 一.Linux 上的软件安装 通常 Linux 上的软件安装主要有三种方式: 在线安装 从磁盘安装deb软件包 从二 ...

  8. ubuntu下安装myeclipse

    一.下载myeclipse 官网下载:http://www.myeclipseide.com/ 我使用的是myeclipse pro 2014.run,重命名为myeclipse.run 示例路径:/ ...

  9. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  10. HTTP必知必会(转)

    HTTP协议作为网络传输的基本协议,有着广泛的应用.HTTP协议的完整内容很多,但是其核心知识却又简单精炼.学习者应该掌握其基本结构,并且能够举一反三.这篇文章所列的,就是在实际开发中必须知道必须掌握 ...