音頻切換消息流
Seeker和Provider通過消息流來同步音頻切換能力,觸發連接做切換,獲取或設置音頻切換偏好,通知連接狀態等等。為此專門定義了音頻切換消息流Message Group 為0x07,Message codes如下:
MAC of Audio switch Messages
所有的從seeker發送到Provider的消息都需要加上MAC,這樣Provider應答這些消息的時候也需要帶上MAC:
- Provider應答ACK的消息流格式如下:
- Provider應答NAK的消息流格式如下:
Get capability of Audio switch
這個消息可以由audio switch provider或者seeker發送,用于查詢對方是否支持audio switch,消息流格式如下:
Notify capability of Audio switch
在收到get capability of Audio switch消息之后,Seeker或者Provider需要回復這個消息,格式如下:
這里我們主要關注一下Audio switch capability flags,只有Provider發送的時候,這兩個字節才有效。這兩個字節是標注音頻切換能力的:
-
Bit 0 (octet 6, MSB): Audio switch state
1, if Audio switch state is on 0, otherwise
-
Bit 1: multipoint configurability
1, if the device supports multipoint and it can be switched between on and off 0, otherwise (does not support multipoint or multipoint is always on)
-
Bit 2: multipoint current state
1, if multipoint is on 0, otherwise
-
Bit 3: on-head detection
1, if this device supports on-head detection (even if on-head detection is turned off now) 0, otherwise
-
Bit 4: on-head detection current state
1, if on-head detection is turned on 0, otherwise (does not support on-head detection or on-head detection is disabled)
Set multipoint state
這個是audio switch seeker用來打開或關閉Provider multipoint功能的消息,消息流格式如下:
Set switching preference
這個是audio switch seeker用來設置Provider multipoint音頻切換偏好的,消息流格式如下:
這里我們主要注意multipoint switching preference flag:
- Bit 0 (MSB): A2DP vs A2DP (default 0)
- Bit 1: HFP vs HFP (default 0)
- Bit 2: A2DP vs HFP (default 0)
- Bit 3: HFP vs A2DP (default 1)
- Bit 4 - 7: reserved
上面表示的形式是“新profile”VS"舊profiler",如果那個bit置上0,代表不能切換,如果置上1,表示可以切換。舉個例子Bit 3置上1,表示如果有HFP連接進來,那么需要從原來的A2DP切換到HFP。
Get switching preference
Seeker可以發送Get switching preference消息給Provider,主動獲取音頻切換偏好,消息流格式如下:
Notify switching preference
Switch active audio source (to connected device)
Audio switch Seekers 可以請求multipoint Provider在連接的設備中切換活躍音頻源,消息流格式如下:
這里我們主要關注Switching active audio source event flags這個字節:
- Bit 0 (MSB): 1 切換到當前設備, 0 切換到另外設備
- Bit 1: 1 在切換后恢復播放, 0 反著來。注意: 恢復播放意味著Provider需要通過AVRCP發送一個PLAY notification 給Seeker,如果seeker之前的狀態就是停播,那么Provider就要忽略這個標志。
- Bit 2: 1 在切換出去的設備拒絕SCO 連接。 0 反著來。
- Bit 3: 1 在切換出去的設備斷開藍牙連接。0 反著來.
- Bit 4 - 7: 這幾個bit保留未用.
如果Audio switch seeker已經是當前活躍音頻設備了,然后又發送了switch active audio device 消息給Provider,那么Provider需要回復NAK,理由是0x04-Redundant device action。
對于LE Audio Provider,如果是被切換出去的設備,那么需要斷開所有的協調集成員的連接。
Switch back (to disconnected device)
如果用戶想切回原來的設備,那么可以發送如下格式消息:
需要注意的是switch back event:
- 0x01:switch back,就是簡單的切回去連接上。
- 0x02:切回去然后恢復播放,這里有個前提就是斷開的設備,在被斷開前的狀態也是播放狀態才行,否則Provider會忽略這個標志。
Notify multipoint-switch event
audio switch Provider通知Seeker發生的切換事件,消息格式如下:
Get connection status
Seeker從Provider獲取當前連接狀態,消息格式如下:
Notify connection status
連接狀態的改變,除了需要修改BLE廣播,還有就是Provider需要通知當前使用共同accout key的連接的audio switch seeker。如果provider連接一個audio switch seeker和一個non-audio switch seeker,并且當前活躍設備是non-audio switch seeker,那么provider也要通知audio switch seeker。Provider發送給Seeker的連接狀態的消息,格式如下:
這里注意一下Encrypted connection status,跟之前音頻切換廣播里的connection status一樣:
encrypted_connection_status = connection_status_raw_data ^ AES(Key, IV)
其中:
clike Key = HKDF(account_key, NULL, UTF8("SASS-RRD-KEY"),16)
- IV is concat(Session_nonce, Message_nonce)
- connection_status_raw_data = concat(connection_state, custom_data, connected_devices)
Notify Audio switch initiated connection
這個是Seeker告訴Provider,此連接是audio switch發起的連接,消息格式如下:
Indicate in use account key
如果同一個Seeker上多個account key 賬戶連接著同一個Provider,那么Seeker使用如下格式消息告訴Provider當前使用哪個account key:
Provider收到消息后,通過校驗MAC能夠得知當前使用哪個account key。
Send custom data
活躍Audio switch Seeker能夠封裝音頻流信息在custom data里發送給Provider,消息格式如下:
Provider收到custom data之后,會更新廣播數據包含custom data。如果是multipoint Provider,它也需要使用相同的account key通知連接狀態的改變給另外連接的seeker。
Set drop connection target
在 multipoint headsets, 如果想要斷開的連接不是最近常用的連接,那么需要audio switch Seekers 告訴Provider需要斷開哪個設備,數據格式如下: