BT 協議——A2DP


轉自:https://blog.csdn.net/yuanzhangmei1/article/details/25073417

 

1.概述

    A2DP(Advanced Audio Distribution Profile)是藍牙的音頻傳輸協議,典型應用為藍牙耳機。A2DP協議的音頻數據在ACL Link上傳輸,這與SCO上傳輸的語音數據要區別。A2DP不包括遠程控制的功能,遠程控制的功能參考協議AVRCP。AVDTP則定義了藍牙設備之間數據流句柄的參數協商,建立和傳輸過程以及相互交換的信令實體形式,該協議是A2DP框架的基礎協議。A2DP與相關協議的附屬關系如下圖:
A2DP協議筆記

A2DP在協議棧中的位置如下圖所示:
A2DP協議筆記
注意下數據包裝的過程。
2.A2DP的一些定義
GAVDP定義了兩種角色:
Initiator (INT) – This is the device that initiates a signaling procedure.【發起signaling的】
Acceptor (ACP) – This is the device that shall respond to an incoming request from the INT.【響應signaling的】
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.【輸出音頻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.【接受音頻stream的】
這里需要注意的是:一般在A2DP中Source和Sink的角色是固定的,而GAVDP的這兩個角色是可以互換的,只要是發起signaling的一方就為initiator。
一個Source和Sink的實例:
A2DP協議筆記

3.A2DP協議的限制
(1)不支持synchronized point-to-multipoint distribution。
(2)在Source和Sink端存在延遲。
(3)音頻數據的速率必須足夠小於藍牙的傳輸速率。
(4)不提供任何數據保護的方法
 
4.編碼
    傳輸音頻數據必須在Source端編碼,在Sink端解碼。A2DP規定了下面幾種編碼類型:
A2DP協議筆記

SBC是強制支持的(Mandatory Codec),其余三種可選(Optional Codec),除了這些外,也可以有廠家自己的編碼形式(Vendor Specific A2DP Codecs)。
 
5.SBC編碼格式
   SBC是A2DP規定的強制支持的編碼格式,這里我們具體只討論這一種編碼格式:
A2DP協議筆記
參數Sampling Frequency:
 
A2DP協議筆記  A2DP協議筆記
Sink端必須支持44100和48000這兩種frequency,Source端支持一種就行。
 
參數Channel Mode:
A2DP協議筆記

參數Block Length:
A2DP協議筆記
  
參數Subbands:
A2DP協議筆記

參數Allocation Method:
A2DP協議筆記
 
參數Minimum / Maximum Bitpool Value:
A2DP協議筆記

6.Media Packet Header與Media payload:
    在第一部分數據的包裝中可以看出,在每一個Media payload上都會加上Media packrt header。主要包括以下幾個部分:
Timestamp (TS),Payload Type (PT),Marker (M) bit【置為全0】,Extension (X) bit【不使用,置為全0】。具體在AVDTP協議中定義,這里不詳述。
Media payload的格式如下:
A2DP協議筆記
其中Media Payload的Header部分的格式如下:
A2DP協議筆記
F bit – Set to 1 if the SBC frame is fragmented, otherwise set to 0.
S bit – Set to 1 for the starting packet of a fragmented SBC frame, otherwise set to 0.
L bit – Set to 1 for the last packet of a fragmented SBC frame, otherwise set to 0
RFA – 置為0.
Number of frames (4 bits) – If the F bit is set to 0, this field indicates the number of
frames contained in this packet. If the F bit is set to 1, this field indicates the number
of remaining fragments, including the current fragment. Thus the last counter value
shall be one. For example, if there are three fragments then the counter has value 3,
2 and 1 for subsequent fragments. This field is expressed by 4 bit UiMsbf.
 
7.A2DP的通信過程
A2DP規定Sink個Source端有三種狀態:IDLE、OPEN和STREAM,通過下圖的流程進行狀態轉換:
A2DP協議筆記
Connection Establishment:
A2DP協議筆記
前提是L2CAP首先建立signaling Channel.
Start Streaming:
A2DP協議筆記

OPEN狀態下經過Start Stream 過程就轉換到STREAMING狀態。
Connection Release:
A2DP協議筆記

在OPEN和STREAMING狀態下都可以通過Stream Release過程變為IDLE狀態。
Suspend:
A2DP協議筆記

只能從STREAMING狀態通過Stream Suspend過程變為OPEN。
Change Parameters:
A2DP協議筆記


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM