1. A2DP
1.1. 基本概念
閱讀A2DP SPEC V12的1.1章,可知:
Advanced Audio Distribution Profile(A2DP)
典型應用是立體聲音樂播放器的音樂到耳機或揚聲器的播放
目的是用來傳輸高品質的單聲道或立體聲音頻,環繞聲不能用A2DP傳輸
A2DP不包括遙控功能,用戶需要同AVRCP組合使用
情景模式相互依賴關系:
1.2. 編碼格式
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. The term “advanced audio”, therefore, should be distinguished from “Bluetooth audio”, which indicates distribution of narrow band voice on SCO channels as defined in Chapter 12 of Bluetooth Baseband specification。
也就是說,A2DP的音質與bluetooth audio是有區別的。Bluetooth audio只能提供voice的音質,而A2DP能提供mono或stereo的音質。
1.2.1. Bluetooth audio
Core spec 4.2第九章:
On the air-interface, either a 64 kb/s log PCM (Pulse Code Modulation) format (A-law or μ-law) may be used, or a 64 kb/s CVSD (Continuous Variable Slope Delta Modulation) may be used. The latter format applies an adaptive delta modulation algorithm with syllabic companding.
The voice coding on the line interface is designed to have a quality equal to or better than the quality of 64 kb/s log PCM.
Table 9.1 on page 210 summarizes the voice coding schemes supported on the air interface. The appropriate voice coding scheme is selected after negotiations between the Link Managers.
1.2.2. advanced audio
A2DP音頻處理和封包過程:
支持的編碼方式如下:
其中SBC是強制支持的,其余是可選的。
A2DP也支持非A2DP編碼格式:
The device may support other codecs as Non-A2DP codecs. A user of the Non-A2DP codec (hereafter the Vendor) oneself defines parameters and any information necessary for use of the codec in A2DP.
CSR8670支持的部分編碼格式如下:
其中aptX和faststream就屬於Non-A2DP。
1.3. 協議棧
閱讀A2DP SPEC_V12:
CSR8670在TWS模式下此注冊2個SDP。在2個SDP注冊成功后,再注冊L2CAP連接。
1.3.1. AVDTP
1.3.1.1. 體系結構
閱讀AVDTP_SPEC_V12:
從上表中可以得知,signalling和media在Upper Layer層處理,時間戳信息會給到Upper Layer。
1.3.1.2. 流終端
一個設備可以支持多個流終端(SEPs),且每個SEPs在本地都對應一個流終端標識符SEID。
設備A使用Application and Transport Service Capabilities服務來獲取設備的SEP。設備A在應用層決定與設備B的哪一個SEP連接。
如果某個SEP已經被使用,其不能被另一個設備使用。
不同的編碼方式應使用不同的流終端,但多個流終端可以使用相同的編碼方式
CSR8670支持的SEP如下:
當CSR8670處在TWS模式下的source狀態,且編碼方式是SBC,其sep和capability如下:
static const sep_config_type tws_sbc_sep_src = {
SOURCE_SEID_MASK | TWS_SEID_MASK | SBC_SEID,
KALIMBA_RESOURCE_ID,
sep_media_type_audio, a2dp_source, 0, 0,
sizeof(tws_sbc_caps), tws_sbc_caps };
/*!
@brief The CSR True Wireless Stereo Codec ID for SBC.
*/
const uint8 tws_sbc_caps[26] =
{
/* Capability 1*/
AVDTP_SERVICE_MEDIA_TRANSPORT,
0,
/* Capability 2*/
AVDTP_SERVICE_MEDIA_CODEC,
16, /* Length */
AVDTP_MEDIA_TYPE_AUDIO << 2,
AVDTP_MEDIA_CODEC_NONA2DP,
(A2DP_CSR_VENDOR_ID >> 24) & 0xFF,
(A2DP_CSR_VENDOR_ID >> 16) & 0xFF,
(A2DP_CSR_VENDOR_ID >> 8) & 0xFF,
(A2DP_CSR_VENDOR_ID >> 0) & 0xFF,
(A2DP_CSR_TWS_SBC_CODEC_ID >> 8) & 0xFF,
(A2DP_CSR_TWS_SBC_CODEC_ID >> 0) & 0xFF,
/* Capability 3*/
/* Embed SBC capabilities */
AVDTP_SERVICE_MEDIA_CODEC,
6, /* Length */
AVDTP_MEDIA_TYPE_AUDIO << 2,
AVDTP_MEDIA_CODEC_SBC,
SBC_SAMPLING_FREQ_16000 | SBC_SAMPLING_FREQ_32000 | SBC_SAMPLING_FREQ_44100 | SBC_SAMPLING_FREQ_48000 |
SBC_CHANNEL_MODE_MONO | SBC_CHANNEL_MODE_DUAL_CHAN | SBC_CHANNEL_MODE_STEREO | SBC_CHANNEL_MODE_JOINT_STEREO,
SBC_BLOCK_LENGTH_4 | SBC_BLOCK_LENGTH_8 | SBC_BLOCK_LENGTH_12 | SBC_BLOCK_LENGTH_16 |
SBC_SUBBANDS_4 | SBC_SUBBANDS_8 | SBC_ALLOCATION_SNR | SBC_ALLOCATION_LOUDNESS,
SBC_BITPOOL_MIN,
SBC_BITPOOL_HIGH_QUALITY,
/* Capability 4*/
AVDTP_SERVICE_CONTENT_PROTECTION,
2,
AVDTP_CP_TYPE_SCMS_LSB,
AVDTP_CP_TYPE_SCMS_MSB,
/* Capability 5*/
AVDTP_SERVICE_DELAY_REPORTING,
0
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
capability的詳細內容參照AVDTP 8.19 Service Capability。
1.3.1.3. 信令流程
兩個設備之間最多有4個L2CAP channel,包括signalling channel, media transport channel, reporting channel, recovery channel。
CSR8670的A2DP只使用前兩個L2CAP channel。
建立signalling channel:
/* Outgoing request to a new device */
if ( (device=addDevice(&req->addr))!=NULL )
{ /* Able to support a new connection */
PanicNull( initiateSignalling( device, AVDTP_OUTGOING_CONNECTION_ID, 0 ) ); /* This should never panic */
l2capConnectRequest(CONNECT_DELAY_IMMEDIATE, device, sizeof(a2dp_conftab), (uint16 *)a2dp_conftab);
requestRemoteA2dpVersion(device);
}
1
2
3
4
5
6
7
建立media transport channel:
case avdtp_connection_connected:
/* Ok to request a media channel */
{ /* No media channel currently being setup, ok to request one */
media_channel *media = initiateMedia(device, AVDTP_OUTGOING_CONNECTION_ID, 0);
if (media != NULL)
{ /* Able to initiate a media connection */
l2capConnectRequest(CONNECT_DELAY_IMMEDIATE, device, sizeof(a2dp_conftab), (uint16*)a2dp_conftab);
}
else
{ /* Unable to initiate any more media connections */
a2dpMediaOpenCfm(device, NULL, a2dp_max_connections);
}
}
break;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
signalling channel的建立過程:
一個特別的協議/服務復用值(PSM)被L2CAP用來處理AVDTP消息的交互。
AVDTP信令和應答的傳輸過程:
流管理信令概覽:
信令命令:
狀態機概覽:
狀態轉移簡述:
設備B的AVDTP處於idle狀態。
設備A向設備B發送AVDTP_DISCOVER,獲取設備B的SEP List。
設備A向設備B發送AVDTP_GET_CAPABILITYS,設備B返回CAPABILITY。
設備A的upper layer選定SEP后,向設備B發送SET CONFIGURATION。如果SEP已被使用,則重新選定SEP並重復此過程。如果此SEP未被使用,則配置成功。此時AVDTP的狀態變成configured。
設備A向設備B發送AVDTP_OPEN,設備B進入open狀態。
設備A向設備B發送AVDTP_START,設備B進入streaming狀態。設備B也可發送同一指令給設備A,也能進入streaming狀態。
設備A向設備B發送AVDTP_SUSPEND,設備B進入open狀態。
設備A向設備B發送AVDTP_CLOSE,設備B進入closing狀態,再轉移到idle狀態。
設備B處在open狀態,設備A向設備B發送AVDTP_RECONFIGURE,重新配置成功后,設備A向設備B發送AVDTP_START,設備B進入streaming狀態。
1.3.1.4 傳輸流程
CSR8670使用了Basic Service,只用了signalling channel和media transport channel。
media transport channel是在進入AVDTP_OPEN狀態時創建的。
其它service參見AVCTP 5.4 Transport procedures。
1.3.2. SDP
1.3.2.1. 概覽
Core System Package [Host volume] Part B
The service discovery protocol (SDP) provides a means for applications to discover which services are available and to determine the characteristics of those available services.
SDP shall function while using L2CAP as its transport protocol.
1.3.2.2. Service Record
All of the information about a service that is maintained by an SDP server is contained within a single service record. The service record shall only be a list of service attributes.
一個服務屬性包括2個部分:屬性ID和屬性值
一個service record可包含多個服務屬性。
屬性ID用來指定服務種類
一個服務種類對應一個UUID,一個service record包含一個或多個服務種類。
Attribute values can contain information of various types with arbitrary complexity.
SDP defines a simple mechanism to describe the data contained within an attribute ID, attribute ID range, and attribute value. The primitive construct used is the data element.
A data element is a typed data representation. It consists of two fields: a header field and a data field.
CSR8670注冊默認Service Record:
/* Client using default library record */
if (role & A2DP_INIT_ROLE_SINK)
{
ConnectionRegisterServiceRecord(&a2dp->task, sizeof(a2dp_sink_service_record), a2dp_sink_service_record);
PRINT(("Register Sink Service Rec\n"));
a2dp->sdp_register_outstanding++;
}
if (role & A2DP_INIT_ROLE_SOURCE)
{
ConnectionRegisterServiceRecord(&a2dp->task, sizeof(a2dp_source_service_record), a2dp_source_service_record);
PRINT(("Register Source Service Rec\n"));
a2dp->sdp_register_outstanding++;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
其中a2dp_source的Service Record:
/*
SDP Service Record generated from a2dp_source.sdp by sdpgen.pl
*/
static const uint8 a2dp_source_service_record[] =
{
0x09, /* ServiceClassIDList(0x0001) */
0x00,
0x01,
0x35, /* DataElSeq 3 bytes */
0x03,
0x19, /* uuid AudioSource(0x110a) */
0x11,
0x0a,
0x09, /* ProtocolDescriptorList(0x0004) */
0x00,
0x04,
0x35, /* DataElSeq 16 bytes */
0x10,
0x35, /* DataElSeq 6 bytes */
0x06,
0x19, /* uuid L2CAP(0x0100) */
0x01,
0x00,
0x09, /* uint16 0x0019 */
0x00,
0x19,
0x35, /* DataElSeq 6 bytes */
0x06,
0x19, /* uuid AVDTP(0x0019) */
0x00,
0x19,
0x09, /* uint16 0x0102 */
0x01,
0x02,
0x09, /* BluetoothProfileDescriptorList(0x0009) */
0x00,
0x09,
0x35, /* DataElSeq 8 bytes */
0x08,
0x35, /* DataElSeq 6 bytes */
0x06,
0x19, /* uuid AdvancedAudioDistribution(0x110d) */
0x11,
0x0d,
0x09, /* uint16 0x0102 */
0x01,
0x02,
0x09, /* SupportedFeatures(0x0311) = "0x0001" */
0x03,
0x11,
0x09, /* uint16 0x0001 */
0x00,
0x01,
}; /* 48 bytes */
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
屬性定義參考Core Spec 4.2 Vol 3, Part B, Service Discovery Protocol 5 Service Attribute Definitions。
兩個Service Record注冊成功后,注冊L2CAP:
void a2dpHandleSdpRegisterCfm(const CL_SDP_REGISTER_CFM_T *cfm)
{
/* Log received cfm message */
a2dp->sdp_register_outstanding--;
if (cfm->status==success)
{
/* Register the l2cap psm if all service records have been registered */
if ( a2dp->sdp_register_outstanding==0 )
{
a2dpRegisterL2cap();
}
}
else
{
/* Send indication that the initialisation failed */
a2dpSendInitCfmToClient(a2dp_sdp_fail);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
1.3.3. L2CAP
Core Spec Vol 3, Part A, Logic Link Control and Adaptation Protocol Specification:
多個位於upper layer的控制實體可復用同一個L2CAP通道
支持分包和重組
支持單個通道的流控制
支持錯誤控制和重傳
支持音頻流
支持QoS
CSR8670實施了L2CAP自動連接系統,目的是簡少應用程序對連接過程的關注。
首先app層調用a2dpRegisterL2cap:
void a2dpRegisterL2cap(void)
{
ConnectionL2capRegisterRequest(&a2dp->task, AVDTP_PSM, 0);
}
1
2
3
4
注冊成功后,通知app層:
void a2dpHandleL2capRegisterCfm(const CL_L2CAP_REGISTER_CFM_T *cfm)
{
/* Send a confirmation message to the client regardless of the outcome */
a2dpSendInitCfmToClient((cfm->status == success) ? a2dp_success : a2dp_l2cap_fail);
}
1
2
3
4
5
收到L2CAP連接請求后,初始化信令並通知app層:
if ( (device=addDevice(&ind->bd_addr))!=NULL )
{ /* Able to support this new connection */
initiateSignalling(device, ind->connection_id, ind->identifier);
/* This must be the signalling channel, so let the app decide whether to accept this connection */
a2dpSignallingConnectInd(device);
}
1
2
3
4
5
6
7
連接成功后,L2CAP層把L2CAP連接的參數提交給app層:
sink = StreamL2capSink(cfm->cid);
/* Send connect cfm to client */
sendL2capConnectCfm(
appTask,
l2cap_connect_success,
cfm->psm_local, sink,
remote_mtu,
flush_to,
p_qos,
mode,
cfm->cid,
&addr
);
/* Associate the task with its sink */
(void) MessageSinkTask(sink, appTask);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
1.3.3.1 CID
Core Spec Vol 3, Part A, Logic Link Control and Adaptation Protocol Specification:
A channel identifier (CID) is the local name representing a logical channel endpoint on the device.
The null identifier (0x0000) shall never be used as a destination endpoint. Identifiers from 0x0001 to 0x003F are reserved for specific L2CAP functions.
The characteristics of each fixed channel are defined on a per channel basis.
設備間的通道類型有三種:
不同設備間的連接示意圖如下:
在CSR8670的TWS模式下,master與slave之間的是signalling channel和connection-oriented channel。
1.3.3.2 PSM
在使用L2CAP功能之前,應用必須注冊此通道用到的PSM。
Core Spec 4.2對PSM的描述:
Protocol/Service Multiplexer - PSM (2 octets (minimum))
The PSM field is at least two octets in length. The structure of the PSM field is based on the ISO 3309 extension mechanism for address fields. All PSM values shall be ODD, that is, the least significant bit of the least significant octet must be 1. Also, all PSM values shall have the least significant bit of the most significant octet equal to 0. This allows the PSM field to be extended beyond 16 bits.
PSM values are separated into two ranges. Valid values in the first range are assigned by the Bluetooth SIG and indicate protocols. The second range of values are dynamically allocated and used in conjunction with the Service Discovery Protocol (SDP). The dynamically assigned values may be used to support multiple implementations of a particular protocol.
在SIG中規定的部分PSM:
CSR8670中用到的部分PSM:
AVDTP_PSM——0x19
AVCTP_PSM——0x17
SWAT_SIGNALLING_PSM——0x8001
SWAT_MEDIA_PSM——0x8003
可見最后兩個PSM屬於dynamic。
1.3.3.3 mode
L2CAP channels may operate in one of five different modes as selected for each L2CAP channel.
The modes are:
Basic L2CAP Mode (equivalent to L2CAP specification in Bluetooth v1.1)
Flow Control Mode
Retransmission Mode
Enhanced Retransmission Mode
Streaming Mode
LE Credit Based Flow Control Mode
CSR8670在注冊L2CAP時的模式設置如下:
prim->mode_mask = L2CA_MODE_MASK_BASIC |
L2CA_MODE_MASK_ENHANCED_RETRANS |
L2CA_MODE_MASK_STREAMING;
1
2
3
1.3.3.4 其它配置參數
Core Spec Vol 3, Part A, 5 Configuration Parameter Options:
Maximum Transmission Unit:
This option specifies the maximum SDU size the sender of this option is capable of accepting for a channel.
MTU is not a negotiated value, it is an informational parameter that each device can specify independently.
Flush Timeout:
This option is used to inform the recipient of the Flush Timeout the sender is going to use.
The Flush Timeout option is negotiable.
Quality of Service(QOS)
This option specifies a flow specification similar to RFC 1363.
The QoS option is negotiable. If no QoS configuration parameter is negotiated the link shall assume the default parameters.
L2CAP implementations are only required to support ’Best Effort’ service, support for any other service type is optional.
1.3.4 LMP
Core Spec Vol 2, Part C, Link Manager Protocol Specification:
The Link Manager Protocol (LMP) is used to control and negotiate all aspects of the operation of the Bluetooth connection between two devices.
The Link Manager Protocol is used to communicate between the Link Managers (LM) on the two devices which are connected by the ACL logical transport.
The protocol is made up of a series of messages which shall be transferred over the ACL-C logical link on the default ACL logical transport between two devices.
CSR8670的A2DP用到了LMP的如下功能:
power control
sniff subrating
link supervision timeout changed event
role switch
2. AVRCP
2.1. 簡介
AVRCP SPEC V15:
The Audio/Video Remote Control Profile (AVRCP) defines the features and procedures required in order to ensure interoperability between Bluetooth devices with audio/video control functions in the Audio/Video distribution scenarios. This profile specifies the scope of the AV/C Digital Interface Command Set (AV/C command set, defined by the 1394 Trade Association) to be applied, and it realizes simple implementation and easy operability. This profile adopts the AV/C device model and command format for control messages, and those messages are transported by the Audio/Video Control Transport Protocol (AVCTP). Browsing functionality is provided over a second AVCTP channel, which does not use AV/C
依賴關系:
2.2 協議棧
The Baseband, LMP, and L2CAP are the OSI layer 1 and 2 Bluetooth protocols. AVCTP defines the procedures and messages to be exchanged for controlling A/V devices. SDP is the Bluetooth Service Discovery Protocol [10]. AV/C is the entity responsible for AV/C command-based device control signaling. The application is the AVRCP entity, exchanging control and browsing commands as defined in this specification.
2.2.1 AVCTP
The Audio/Video Distribution Control Protocol (hereafter referred to as AVCTP) defines the binary transactions issued between a pair of Bluetooth devices for A/V function discovery and control.
AVCTP uses point-to-point signalling over connection-oriented L2CAP channels that have first to be set up between both devices. L2CAP channels are the most suitable for the support of A/V applications, which require dedicated transport services for A/V content streaming and feature control on the same link.
A complete AVCTP transaction consists of one message containing a command addressed to the target and zero or more messages containing a response returned to the controller by the target.
In this transaction model the response message is not compelled: whether the target sends back one or more response message depends on the application not on the reliability of the transport.
Occasionally large messages need to be fragmented by AVCTP for the transport over more than one L2CAP packet.
Each AVCTP command or response message is transmitted in one or several AVCTP packets that consist of a packet header part and a variable length message information part.
In AVCTP transactions, a Profile Identifier field is used to represent the profile control mechanisms to which the transported message is referring.
CSR8670只使用了AVRCP,因此只有一種PID:
#define AVCTP1_PROFILE_AVRCP_HIGH 0x11
#define AVCTP2_PROFILE_AVRCP_REMOTECONTROL 0x0e
1
2
AVRCP的control channel,browsing channel與AVDTP的signal channel共用一個L2CAP channel,但是由於各自使用不同的PSM,L2CAP layer在向upper layer提交時不會混淆。
/* L2CAP AVCTP PSM as defined in the assigned numbers section
of the Bluetooth spec. */
#define AVCTP_PSM 0x17
#define AVCTP_BROWSING_PSM 0x1B
/* L2CAP PSM */
#define AVDTP_PSM (0x19)
1
2
3
4
5
6
7
2.3 配置和規則
The following roles are defined for devices that comply with this profile:
The controller (CT) is a device that initiates a transaction by sending a command frame to a target. Examples for CT are a personal computer, a PDA, a mobile phone, a remote controller or an AV device (such as an in car system, headphone, player/recorder, timer, tuner, monitor etc.).
The target (TG) is a device that receives a command frame and accordingly generates a response frame. Examples for TG are an audio player/recorder, a video player/recorder, a TV, a tuner, an amplifier or a headphone.
This profile ensures interoperability by classifying the A/V functions into four categories.
Category 1: Player/Recorder
Basic operations of a player or a recorder are defined, regardless of the type of media (tape, disc, solid state, etc.) or the type of contents (audio or video, etc.).
Category 2: Monitor/Amplifier
The category 2 is to define basic operations of a video monitor or an audio amplifier.
Category 3: Tuner
The category 3 defines the basic operation of a video tuner or an audio tuner.
Category 4: Menu
The basic operations for a menu function are defined in category 4. The method to display menu data is not specified. It may be a display panel of the device itself, or onscreen display (OSD) on an external monitor.
CSR8670的AVRCP的配置如下:
/* Initialise AVRCP library */
config.device_type = avrcp_target_and_controller;
config.supported_controller_features = AVRCP_CATEGORY_1; /* mainly operates as controller */
config.supported_target_features = AVRCP_CATEGORY_2; /* only target for volume commands */
#ifdef ENABLE_PEER
config.supported_target_features |= AVRCP_CATEGORY_1; /* Peer devices also a target for category 1 commands (play, pause etc) */
#endif
config.profile_extensions = AVRCP_VERSION_1_6; /* operate as AVRCP 1.6 device */
#ifdef ENABLE_AVRCP_BROWSING
config.profile_extensions |= AVRCP_BROWSING_SUPPORTED; /* indicate Browsing support */
#endif
1
2
3
4
5
6
7
8
9
10
11
12
設備被定義為既是CT又是TG。
設備被定義為同時支持種類1和種類2。在TWS會話當中,master相對於AV而言符合種類2,相對於slave而言符合種類1。
2.3.1.4 Mutual Remote Control within a Piconet
In the configuration shown in Figure 2.6 below, both the headphone and the portable disc player are capable of working as remote controllers.
For example, the portable disc player becomes a CT if it controls the volume of the headphone that becomes a TG. On the other hand, the headphone becomes a CT when it sends a command to start playback or stop playing to the portable disc as a TG.
如果設備支持種類1,TG狀態必須支持特性10、12、17、13、14,CT狀態必須支持特性13、14。如果設備支持種類2,TG和CT狀態都必須支持特性16。特性22雖然是可選的,但在CSR8670的TWS模式中被作為重點使用。
2.4 過程
2.4.1 建立連接
An L2CAP connection establishment for AVCTP control may be initiated by the CT or by the TG. An internal event or an event generated by a user, such as turning the power on, initiates the connection establishment.
Note: Only one L2CAP connection for control and one L2CAP connection for browsing (if supported by both devices) shall be established between AVCTP entities. If the connection(s) already exist(s), the CT/TG shall not initiate the connection request.
CSR8670在建立AVCTP控制連接之前已經建立了AVDTP連接,因此只需要與AVDTP共用一個L2CAP連接。
2.4.2 斷開連接
Release of an L2CAP connection for AVCTP may be initiated by the CT or by the TG. An internal event or an event generated by a user, such as turning the power off, initiates the connection release.
If a browsing channel is present it shall be released before the control channel. If the browsing channel has been released it may be re-established if required as long as the control channel is still present.
2.4.3 AV/C命令過程
Upon an internal or an event generated by a user, the CT shall initiate connection establishment if a connection has not been established by then. Once the connection is established it can send an AV/C command.
在收到VENDOR DEPENDENT命令時才會返回AV/C interim應答。
某些特殊情況下,TG不會返回應答。
可被交換的AV/C命令如下:
The UNIT INFO command is used to obtain information that pertains to the AV/C unit as a whole. The response frame includes information of the vendor ID of the TG and subunit type that best describes the unit. The information of vendor ID may be used to investigate the vendor of TG before using VENDOR DEPENDENT command.
The SUBUNIT INFO command is used to obtain information about the subunit(s) of an AV/C unit. A device with this profile may support other subunits than the panel subunit if other profiles co-exist in the device, which can be found with the SUBUNIT INFO command. With this command, a typical AV/C controller manipulates AV/C function discovery.
The VENDOR DEPENDENT command permits module vendors to specify their own set of commands and responses for AV/C units or subunits determined by the AV/C address that is contained in the AV/C frame.
這個情景模式的一個特性就是用面板子單元的PASS THROUGH命令完成遠程控制。面板子單元提供一種用戶為中心的模式以使設備動作。CT使用已確定的依賴於CT的用戶操作以控制面板子單元。用戶操作顯示器上的用戶接口或者操作按鍵,然后CT發送命令給面板子單元。為了回應這些命令,面板子單元完成一些動作。雖然在TG內有許多子單元,TG只能有一個面板子單元。不像許多其他AV/C子單元,面板子單元自己不會直接處理媒體音頻流。使用面板子單元的主要目的是將輸入的用戶動作命令翻譯成會影響其他子單元的內部的動作,且根據TG依賴性將這些動作分發給TG內部的合適的其它子單元。這個情景模式使用PASS THROUGH命令,這個命令屬於定義於面板子單元規范內的子單元命令中的一種。CT使用PASS THROUGH命令傳輸一個用戶操作給TG。
CSR8670在TWS模式下的定制命令用的就是PASS THROUGH命令。
VENDOR DEPENDENT只在傳送AVRCP_PEER_CMD_AUDIO_CONNECTION_STATUS的ack時用到一次。
2.4.4 AVRCP定制的AV/C命令過程
The procedure of AVRCP specific AV/C commands is an extension of the AV/C Digital Interface Command Set General Specification specified by 1394 Trade Association.
The extension is implemented by defining VENDOR DEPENDENT and PASS THROUGH commands within the framework of the 1394 specifications. A vendor ID for the Bluetooth SIG is used to differentiate from real vendor specific commands.
2.4.5 AVRCP瀏覽命令過程
The procedure of AVRCP Browsing commands defines commands to be used directly over AVCTP. AV/C is not used. The AVCTP Browsing Channel shall not use fragmentation. These commands enable the CT to navigate the media on the TG device, then perform operations on a specific media item.
CSR8670的avrcp lib可以支持browsing。
2.5 支持的單元命令
2.5.1 UNIT INFO命令
If the unit implements only this profile, it shall return the PANEL subunit in the response frame.
In the company_ID field of a UNIT INFO response frame, the 24-bit unique ID obtained from the IEEE Registration Authority Committee shall be inserted. If the vendor of a TG device does not have the unique ID above, the value 0xFFFFFF may be used.
CSR8670的UNIT INFO命令的應答函數:
static void handleAvrcpUnitInfoInd(AVRCP_UNITINFO_IND_T *msg)
{
/* Device is a CT and TG, so send the correct response to UnitInfo requests. */
uint32 company_id = 0xffffff; /* IEEE RAC company ID can be used here */
AvrcpUnitInfoResponse(msg->avrcp, TRUE, subunit_panel, 0, company_id);
}
1
2
3
4
5
6
2.5.2 SUBUNIT INFO命令
If the unit implements this profile, it shall return PANEL subunit in the subunit_type field, and value 0 in the max_subunit_ID field in the response frame.
CSR8670的SUBUNIT INFO命令的應答函數:
static void handleAvrcpSubUnitInfoInd(AVRCP_SUBUNITINFO_IND_T *msg)
{
/* Device is a CT and TG, so send the correct response to SubUnitInfo requests. */
uint8 page_data[4];
page_data[0] = 0x48; /* subunit_type: panel; max_subunit_ID: 0 */
page_data[1] = 0xff;
page_data[2] = 0xff;
page_data[3] = 0xff;
AvrcpSubUnitInfoResponse(msg->avrcp, TRUE, page_data);
}
1
2
3
4
5
6
7
8
9
10
2.6 支持的公共單元和子單元命令
2.6.1 VENDOR DEPENDENT命令
It is assumed that devices that do not support this metadata transfer related features shall return a response of NOT IMPLEMENTED
CSR8670不支持公共單元和子單元的VENDOR DEPENDENT命令,其應答函數如下:
static void handleAvrcpVendorDependentInd(AVRCP_VENDORDEPENDENT_IND_T *msg)
{
/*
Reject all vendor requests.
*/
AvrcpVendorDependentResponse(msg->avrcp, avctp_response_not_implemented);
}
1
2
3
4
5
6
7
2.7 支持的子單元命令
2.7.1 PASS THROUGH命令
The PASS THROUGH command of the Panel subunit is used in this profile.
Attention is particularly drawn to the state_flag which shall be used to convey button press and release and the timing requirements for button press and release. This facility is required to convey the concept of holding down a button for a period of time.
There are AVRCP specific vendor unique PASS THROUGH commands to handle group navigation capability.
CSR8670支持面板子單元的PASS THROUGH命令。
PASS THROUGH不僅可以傳遞按鍵值,還可以傳遞按鍵狀態。
CSR8670在TWS模式下同時支持種類1和種類2。
種類1、種類2設備在TG狀態下支持的操作(C1和C2都需要支持):
種類1和種類2設備在CT模式下支持的操作(C1和C2都需要支持):
CSR8670使用vendor unique實現TWS模式下特有的指令。
2.8 AVRCP特定命令
AVRCP特定命令分為AV/C VENDOR DEPENDENT命令和browsing命令。
AV/C命令通過AVCTP控制通道傳輸,browsing命令通過AVCTP browsing通道傳輸。
AVRCP定制命令有很多種,詳細內容參考AVRCP_SPEC_V15的4.5章。
個別操作使用PASS THROUGH命令傳輸。
2.9 協議概念
2.9.1 命令類型
AV/C命令:
在AV/C規范內定義的PASS THROUGH命令、UNIT命令和SUBUNIT命令。
此外,還存在一組命令,以下簡稱為AVRCP特定AV / C命令,定義為藍牙技術聯盟供應商依賴擴展。
兩者都通過AVCTP控制通道傳輸。
Browsing命令:
通過AVCTP browsing通道傳輸。
2.9.2 能力
CT應有能力獲取TG的能力,包括:
TG支持的Compand ID的列表。
TG支持的Event ID的列表。
播放器應用的定制特性的位掩碼。
2.9.3 目標播放器應用設置
Player application settings commands provide a mechanism for CT devices to query player application set.
2.9.4 當前媒體條目的元數據屬性
Metadata attributes for the currently playing media element may be retrieved by the CT using the GetElementAttributes command.
2.9.5 從目標設備來的事件通知
CT有能力訪問當前的播放狀態,除了媒體音軌持續時間和當前音軌位置。
目標設備上能被監測的事件有:
當前媒體音軌的播放狀態事件
播放、暫停、停止
快進、快退
回放位置變化
音軌改變事件
音軌改變
音軌開始、音軌結束
設備拔出事件
所有播放器應用屬性能被CT注冊為事件。當本地TG設備的對應設備設置值變化時,TG應通知CT
TG設備音量值變化
可見的播放器變化
已尋址的播放器變化
UIDs變化
正在播放文件夾的內容變化
CT設備有能力提供一個NOTIFY AV/C命令給TG,用來注冊TG上的特定事件
TG應為了每個被支持的NOTIFY AV/C命令發送一個INTERIM應答,這個包含了被注冊事件的當前狀態值的應答必須在注冊完成后的Tmtp時間內被發送。
當一個被注冊事件發生,TG設備應發送一個包含了當前狀態的CHANGED應答給CT。
按照AV/C協議,一個NOTIFY命令在提供了一個對應的CHANGED后終止。
按照AVCTP,每個AVCTP通道在任意時刻只允許有16個未完成的傳輸標簽。這就限制了能同時被注冊和等待的應答數不能超過15個。
CSR8670在TWS模式下支持的事件:
avrcp_event_playback_status_changed
avrcp_event_volume_changed
2.9.10 持續
Continuation commands provide protocol capability for sender and receiver to be able to segment and reassemble packets over AV/C.
Note that Continuation is required due to the limit of 512 octets per AV/C frame. Continuation is therefore only necessary for AV/C commands.
2.9.10 組導航
Group navigation provides the ability for CT to logically view TG media storage as a flat structure. Groups are logical blocks of media tracks defined by TG. This could be play lists, folders or any other logical structure as deemed fit by TG. By doing this CT shall be able to move to next and previous groups on TG without any knowledge on the media storage mechanism of TG.
2.9.11 絕對音量
這個特性提供了音量處理功能以允許CT顯示音量條或音量值。
兩個命令用來設置絕對音量和顯示音量變化
SetAbsoluteVolume命令用來在播放設備上設置音量值
RegisterNotification命令在Volume Changed Event中被CT用來檢測TG上發生的音量變化。
2.9.12 媒體播放器選擇
一個TG上可以有多個不同類型的媒體播放器,例如收音機、視頻播放器等。
CT能夠觀察到TG上可用的播放器,選擇其中一個控制和瀏覽媒體內容,還能在媒體播放器變得可用后收到通知。
媒體播放器選擇功能允許CT通過獲取每個媒體播放器的播放特性掩碼以獲取其所能支持的播放功能。
AV/C面板子單元將AV/C命令路由到Addressed Player。
AVRCP將有着虛擬媒體播放器文件系統或搜索的瀏覽命令路由到Browsed Player。
2.9.13 Now Playing
Many media players support the concept of a Now Playing list or Queue.
Although a media player application may not support the concept of a Now Playing list natively there are a variety of ways in which it could choose to populate the Now Playing list.
The Now Playing list may be examined using AVRCP browsing functionality.
2.9.14 UID
Media elements are identified within the virtual filesystem by an 8 octet identifier, the UID.
The UID Counter allows the CT device to detect updates on the TG device.
2.9.15 搜索
The search functionality allows the CT to locate specific media elements on the TG.
Advanced search facilities, such as search on artist are not supported. However, equivalent filtering may be possible using search within folder on folders which contain specific types of content, as folders have properties which include the type of content they hold
2.9.16 瀏覽
Browsing functionality allows a CT device to navigate and view media content on the TG.
The Media Player List contains available media players.
The Virtual Media Filesystem is a representation of the Media Elements and Folders present on the TG.
The Search folder contains the results of the last search performed by the CT.
The Now Playing folder contains the list of Media Elements that are currently scheduled to be played by the Addressed Player on the TG.
2.9.17 定時器
所有AV/C傳輸都應遵循下列時間周期,除非有明確的特定。
TG應在收到任何AV/C命令的100ms內應答。
有些AVRCP指定的AV/C控制命令不能立刻應答,此時應在既定時間內返回一個有着初始應答碼的INTERIM,其后緊跟最終應答。
TG生成1個控制命令的應答幀的時間周期是200ms。
TG生成1個通知命令的臨時應答幀和狀態命令的最終幀的時間周期是1000ms。
AVRCP特定瀏覽命令沒有定義時間周期,但TG應盡快應答。
3 總結
AVRCP和A2DP需要配合使用。
A2DP需要兩個L2CAP通道,一個作為signal channel,另一個作為media channel。
AVRCP可以和A2DP共用一個L2CAP通道作為control channel,如需支持browsing的功能需新打開一個L2CAP通道作為browsing channel。
如果有profile共用一個L2CAP通道,則packet中必須包含PSM,用以投遞給指定的profile,有點像郵箱的機制。
panel subunit的PASS THROUGH command是重要的命令,用來在CT和TG之間傳輸控制命令,例如播放、暫停等。
可使用PASS THROUGH command的operation_id=vendor unique指令來傳遞自定義的command,前提是需要從SIG申請專用的VENDOR UNIQUE ID。CSR定義的只在TWS模式下使用的AVRCP specific vendor unique command用的就是這種方式。
absolute volume功能不是所有手機都支持,試過iphone5S以上是支持的。如果手機沒有在CT端注冊avrcp_event_volume_changed,則不能使用absolute volume功能。
---------------------
作者:RyomaWang
來源:CSDN
原文:https://blog.csdn.net/wzz4420381/article/details/51097654
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!