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. Windows 8 键盘上推自定义处理

    原文:Windows 8 键盘上推自定义处理 在Windows 8 应用程序中,当TextBox控件获得焦点时,输入面板会弹出,如果TextBox控件处于页面下半部分,则系统会将页面上推是的TextB ...

  2. 最快的方法来清除Chrome浏览器DNS高速缓存

    最快的方法是直接数据url.那么不需要清除dns高速缓存. chrome://net-internals/#dns 一般步骤,要经过下列几项. Chrome - > 扳手 - > 选项 - ...

  3. Flex入门(三)——微架构之Cairngorm

    大家都知道我们在开发后台的时候,都会使用MVC,三层等分层架构,使后台代码达到职责更为分明单一,高内聚低耦合,比如,Dao层仅仅是进行和数据库打交道,负责处理数据:Service(B层)仅仅是进行逻辑 ...

  4. 嵌入在网站上Flash播放机(2)

    然后在一个博客.这里有一个flash嵌入式播放器.这是公司内部使用的flash播放机,支持格更多款式,同时支持swf格视频播放的类型. 以下是页面嵌入代码: <link rel="st ...

  5. 读改善c#代码157个建议:建议4~6

    目录: 建议4:TryParse比Parse好 建议5:使用int?确保值类型也可以为null 建议6:区别 readonly 和 const 的用法 一.建议4:TryParse比Parse 好 T ...

  6. C#-默认显示前列-ShinePans

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  7. css整理 background-size优化

    font-size:12px; line-height:22px; font-family:Arial,Helvetica,sans-serif; /*优化*/ font:12px/22px Aria ...

  8. Android Studio中导入Android项目StepbyStep

    想把在eclipse的项目导入Android studio,有两种方法,但是我喜欢的是不改变项目文件结构的方法,因为这样可以兼容eclipse. 第一步: 导入的项目不能运行,需要配置运行环境.And ...

  9. 【Unity 3D】学习笔记29:游戏的例子——简单的小制作地图

    无论学习.只看不练是坏科学. 因此,要总结回想这怎么生产MMROPG小地图的游戏.于MMROPG游戏类,在游戏世界中行走时导致各地,通常在屏幕的右上角,将有一个区域,以显示当前的游戏场景微缩.在游戏世 ...

  10. android在当前app该文件下创建一个文件夹

    /*********************************************************************  * Author  : Samson  * Date   ...