Android Bluetooth stack:bluedroid (v): The analysis of A2DP Source

Source: Internet
Author: User

1. A2DP Introduction

The Advanced Audio distribution Profiles (A2DP) defines the protocols and procedures that realize distribution of audio con Tent 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 is specific foraudio streaming, including audio codec, SDP param Eters. It's the pre-condition of analyzing A2DP Source implementation to familiar with the both SPECS:AVDTP and A2DP. The block diagrams of sending/receiving audio streaming and created packet format is shown in the diagram below. In the analysis, I have focus on MP and Media Pl. AVDTP Spec describes MP, while A2DP Spec describes Media Pl. This profiles support a mandatory CODEC:SBC, 3 optional codecs:mpeg-1,2 Audio, mpeg-2,4 AAC and ATRAC family, and the Ven Dor specific A2DP codecs, eg. AptX. I'll only talk on the mandatory CODEC:SBC in the article.


Block diagram of Audio streaming procedures and the Packet Format

The following roles is 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's 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 to the same piconet, eg. A Bluetooth headset which receives audio stream.

In Bluedroid, only the source role was implemented, so I an analysis of the implementation of A2DP source in Bluedroid. (but both of source and sink is implemented in Bluez)

2. Code Analysis

I won't list very detailed function callings (the best understand the code was reading the code by yourself), whil E just describe the process. So you'll not be 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/hard Ware/bt_av.h.
  • BTIF/SRC/BTIF_MEDIA_TASK.C 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 the Audio/video call-out function implementation for btif.
  • Bta/av/bta_av_ci.c This was the implementation for advanced Audio/video call-in functions which was called F Rom BTIF.
  • Bta/av/bta_av_api.c the implementation of the API for the Advanced Audio/video (AV) subsystem of BTA. This interface was 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 was the stream state machine for the BTA advanced Audio/video.
  • Bta/av/bta_av_aact.c This file contains the action functions for the advanced Audio/video stream.
  • BTA/AV/BTA_AV_SBC.C This module contains utility functions for dealing with SBC data frames and codec Capabili Ties.
  • Stack/a2dp/a2d_api.c 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 a ND 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 are A2DP Media task for SBC Encoder. The task is created when Bluetooth was 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 have a PCM data buffer ready t  o 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 mor E encoded SBC frames.

2.3 Implement Audio HAL for A2DP audio device

(To be continued)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.