![A2DP协议笔记 a2dp协议](http://img.aihuau.com/images/02111102/02052549t01f98d7a459888c7b0.png)
A2DP在协议栈中的位置如下图所示:
注意下数据包装的过程。2.A2DP的一些定义GAVDP定义了两种角色:Initiator (INT) – This is the device that initiates asignaling procedure.【发起signaling的】Acceptor (ACP) – This is the device that shallrespond to an incoming request fromtheINT.【响应signaling的】A2DP在此基础上具体实现了连个角色:Source (SRC) – A device is the SRC when it acts as asource of a digital audiostreamthatis delivered to the SNK of the piconet.【输出音频stream的】Sink (SNK) – A device is the SNK when it acts as asink of a digital audio streamdeliveredfrom the SRC on the same piconet.【接受音频stream的】这里需要注意的是:一般在A2DP中Source和Sink的角色是固定的,而GAVDP的这两个角色是可以互换的,只要是发起signaling的一方就为initiator。一个Source和Sink的实例:
3.A2DP协议的限制(1)不支持synchronized point-to-multipoint distribution。(2)在Source和Sink端存在延迟。(3)音频数据的速率必须足够小于蓝牙的传输速率。(4)不提供任何数据保护的方法
4.编码 传输音频数据必须在Source端编码,在Sink端解码。A2DP规定了下面几种编码类型:
SBC是强制支持的(Mandatory Codec),其余三种可选(OptionalCodec),除了这些外,也可以有厂家自己的编码形式(Vendor Specific A2DP Codecs)。
5.SBC编码格式SBC是A2DP规定的强制支持的编码格式,这里我们具体只讨论这一种编码格式:
参数Sampling Frequency:
Sink端必须支持44100和48000这两种frequency,Source端支持一种就行。
参数Channel Mode:
参数Block Length:
参数Subbands:
参数Allocation Method:
参数Minimum / Maximum BitpoolValue:
6.Media Packet Header与Mediapayload: 在第一部分数据的包装中可以看出,在每一个Media payload上都会加上Mediapackrt header。主要包括以下几个部分:Timestamp (TS),Payload Type(PT),Marker (M) bit【置为全0】,Extension (X)bit【不使用,置为全0】。具体在AVDTP协议中定义,这里不详述。Media payload的格式如下:
其中Media Payload的Header部分的格式如下:
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 SBCframe, otherwise set to 0.L bit – Set to 1 for the last packet of a fragmented SBCframe, otherwise set to 0RFA – 置为0.Number of frames (4 bits) – If the F bit is set to 0, thisfield indicates the number offrames contained in this packet. If the F bit is set to 1,this field indicates the numberof remaining fragments, including the current fragment. Thusthe last counter valueshall be one. For example, if there are three fragments thenthe counter has value 3,2 and 1 for subsequent fragments. This field is expressed by 4bit UiMsbf.
7.A2DP的通信过程A2DP规定Sink个Source端有三种状态:IDLE、OPEN和STREAM,通过下图的流程进行状态转换:
Connection Establishment:
前提是L2CAP首先建立signaling Channel.Start Streaming:
OPEN状态下经过Start Stream 过程就转换到STREAMING状态。Connection Release:
在OPEN和STREAMING状态下都可以通过Stream Release过程变为IDLE状态。Suspend:
只能从STREAMING状态通过Stream Suspend过程变为OPEN。Change Parameters: