CSR8670的A2DP与AVRCP的应用笔记
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
版权声明:本文为博主原创文章,转载请附上博文链接!