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)
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.
I list the important files for A2DP from the upper layer to lower layger.
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.
2.3 Implement Audio HAL for A2DP audio device
(To be continued)
Android Bluetooth Stack: Bluedroid(五):The analysis of A2DP Source,布布扣,bubuko.com
Android Bluetooth Stack: Bluedroid(五):The analysis of A2DP Source
原文地址:http://blog.csdn.net/wendell_gong/article/details/29841967