BT_蓝牙电话数据包分析_音源切换

基于Android P版本分析

通话过程协议分析

音源切换

音源播放有两个渠道:AG侧和HF侧;

我们在分析outgoing和incoming场景的时候,分析了AT指令流程的时候,在每一次通话中,都包含了 Established Audio Connection ,这个就是用来建立eSCO链路的;

而我们知道,通话的音频数据的传输是在eSCO链路上进行的,蓝牙多媒体的音频是在ACL链路上传输的;

建立了SCO链路通道就代表了通话语音切换到了车机端播放,否则断开SCO就代表了通话语音切换到了手机上进行播放;

HF侧播放

HF侧播放时,需要建立eSCO链路;

在数据包中涉及到了3 frame:frame-607、frame-608、frame-609;

yaml 复制代码
Frame 607: 67 bytes on wire (536 bits), 67 bytes captured (536 bits)
Bluetooth
    [Source: host]
    [Destination: controller]
Bluetooth HCI H4
    [Direction: Sent (0x00)]
    HCI Packet Type: HCI Command (0x01)
Bluetooth HCI Command - Enhanced Accept Synchronous Connection Request
    Command Opcode: Enhanced Accept Synchronous Connection Request (0x043e)
        0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)
        .... ..00 0011 1110 = Opcode Command Field: Enhanced Accept Synchronous Connection Request (0x03e)
    Parameter Total Length: 63
    BD_ADDR: HuaweiDe_42:c7:dd (30:aa:e4:42:c7:dd)
    Tx Bandwidth (bytes/s): 8000
    Rx Bandwidth (bytes/s): 8000
    Transmit Coding Format
        Codec: mSBC (0x05)
        Company ID: Ericsson Technology Licensing (0x0000)
        Vendor Codec ID: 0x0000
    Receive Coding Format
        Codec: mSBC (0x05)
        Company ID: Ericsson Technology Licensing (0x0000)
        Vendor Codec ID: 0x0000
    Transmit Codec Frame Size: 60
    Receive Codec Frame Size: 60
    Input Bandwidth: 32000
    Output Bandwidth: 32000
    Input Coding Format
        Codec: Linear PCM (0x04)
        Company ID: Ericsson Technology Licensing (0x0000)
        Vendor Codec ID: 0x0000
    Output Coding Format
        Codec: Linear PCM (0x04)
        Company ID: Ericsson Technology Licensing (0x0000)
        Vendor Codec ID: 0x0000
    Input Coded Data Size: 16
    Output Coded Data Size: 16
    Input PCM Data Format: 2's complement (0x02)
    Output PCM Data Format: 2's complement (0x02)
    Input PCM Sample Payload MSB Position: 0
    Output PCM Sample Payload MSB Position: 0
    Input Data Path: Vendor Specific
    Output Data Path: Vendor Specific
    Input Transport Unit Size: 0
    Output Transport Unit Size: 0
    Max. Latency (ms): 13
    Packet Type: 0x0388, 3-EV5 may NOT be used, 2-EV5 may NOT be used, 3-EV3 may NOT be used, EV3 may be used
        0000 00.. .... .... = Reserved: 0x00
        .... ..1. .... .... = 3-EV5 may NOT be used: True
        .... ...1 .... .... = 2-EV5 may NOT be used: True
        .... .... 1... .... = 3-EV3 may NOT be used: True
        .... .... .0.. .... = 2-EV3 may NOT be used: False
        .... .... ..0. .... = EV5 may be used: False
        .... .... ...0 .... = EV4 may be used: False
        .... .... .... 1... = EV3 may be used: True
        .... .... .... .0.. = HV3 may be used: False
        .... .... .... ..0. = HV2 may be used: False
        .... .... .... ...0 = HV1 may be used: False
    Retransmission Effort: At least 1 retransmission, optimize for link quality (2)
    [Pending in frame: 608]
    [Command-Pending Delta: 0.915ms]
    [Response in frame: 609]
    [Command-Response Delta: 80.717ms]
  • HCI Packet Type:HCI Command
  • Command Opcode:Enhanced Accept Synchronous Connection Request
yaml 复制代码
Frame 608: 7 bytes on wire (56 bits), 7 bytes captured (56 bits)
Bluetooth
    [Source: controller]
    [Destination: host]
Bluetooth HCI H4
    [Direction: Rcvd (0x01)]
    HCI Packet Type: HCI Event (0x04)
Bluetooth HCI Event - Command Status
    Event Code: Command Status (0x0f)
    Parameter Total Length: 4
    Status: Pending (0x00)
    Number of Allowed Command Packets: 1
    Command Opcode: Enhanced Accept Synchronous Connection Request (0x043e)
        0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)
        .... ..00 0011 1110 = Opcode Command Field: Enhanced Accept Synchronous Connection Request (0x03e)
    [Command in frame: 607]
    [Response in frame: 609]
    [Command-Pending Delta: 0.915ms]
    [Pending-Response Delta: 79.802ms]

frame-608为等待状态;

yaml 复制代码
Frame 609: 20 bytes on wire (160 bits), 20 bytes captured (160 bits)
Bluetooth
    [Source: controller]
    [Destination: host]
Bluetooth HCI H4
    [Direction: Rcvd (0x01)]
    HCI Packet Type: HCI Event (0x04)
Bluetooth HCI Event - Synchronous Connection Complete
    Event Code: Synchronous Connection Complete (0x2c)
    Parameter Total Length: 17
    Status: Success (0x00)
    Connection Handle: 0x0004
    BD_ADDR: HuaweiDe_42:c7:dd (30:aa:e4:42:c7:dd)
    Link Type: eSCO connection (0x02)
    Transmit Interval: 12 slots (7.5 msec)
    Retransmit Window: 6 slots (3.75 msec)
    Rx Packet Length: 60
    Tx Packet Length: 60
    Air Mode: Transparent Data (3)
    [Command in frame: 607]
    [Pending in frame: 608]
    [Pending-Response Delta: 79.802ms]
    [Command-Response Delta: 80.717ms]
  • Event Code:Synchronous Connection Complete (0x2c)
  • Status:Success (0x00)
AG侧播放

在AG侧播放,本质上就是断开HF侧eSCO链路;

同样也是涉及到了3 frame数据;

yaml 复制代码
Frame 620: 7 bytes on wire (56 bits), 7 bytes captured (56 bits)
Bluetooth
    [Source: host]
    [Destination: controller]
Bluetooth HCI H4
    [Direction: Sent (0x00)]
    HCI Packet Type: HCI Command (0x01)
Bluetooth HCI Command - Disconnect
    Command Opcode: Disconnect (0x0406)
        0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)
        .... ..00 0000 0110 = Opcode Command Field: Disconnect (0x006)
    Parameter Total Length: 3
    Connection Handle: 0x0004
    Reason: Remote User Terminated Connection (0x13)
    [Pending in frame: 621]
    [Command-Pending Delta: 3.195ms]
    [Response in frame: 622]
    [Command-Response Delta: 13.029ms]
  • Command Opcode:Disconnect
  • Reason:Remote User Terminated Connection (0x13)
yaml 复制代码
Frame 621: 7 bytes on wire (56 bits), 7 bytes captured (56 bits)
Bluetooth
    [Source: controller]
    [Destination: host]
Bluetooth HCI H4
    [Direction: Rcvd (0x01)]
    HCI Packet Type: HCI Event (0x04)
Bluetooth HCI Event - Command Status
    Event Code: Command Status (0x0f)
    Parameter Total Length: 4
    Status: Pending (0x00)
    Number of Allowed Command Packets: 1
    Command Opcode: Disconnect (0x0406)
        0000 01.. .... .... = Opcode Group Field: Link Control Commands (0x01)
        .... ..00 0000 0110 = Opcode Command Field: Disconnect (0x006)
    [Command in frame: 620]
    [Response in frame: 622]
    [Command-Pending Delta: 3.195ms]
    [Pending-Response Delta: 9.834ms]
yaml 复制代码
Frame 622: 7 bytes on wire (56 bits), 7 bytes captured (56 bits)
Bluetooth
    [Source: controller]
    [Destination: host]
Bluetooth HCI H4
    [Direction: Rcvd (0x01)]
    HCI Packet Type: HCI Event (0x04)
Bluetooth HCI Event - Disconnect Complete
    Event Code: Disconnect Complete (0x05)
    Parameter Total Length: 4
    Status: Success (0x00)
    Connection Handle: 0x0004
    Reason: Connection Terminated by Local Host (0x16)
    [Command in frame: 620]
    [Pending in frame: 621]
    [Pending-Response Delta: 9.834ms]
    [Command-Response Delta: 13.029ms]
  • Event Code:Disconnect Complete (0x05)
  • Status:Success (0x00)
  • Reason:Connection Terminated by Local Host (0x16)
总结

针对音源切换,每一个connection和disconnection都会对应上层的一个onAudioStateChanged,上层根据onAudioStateChanged回调的信息,执行对应的逻辑;

相关推荐
天上掉下来个程小白41 分钟前
微服务-27.配置管理-什么是配置管理
运维·微服务·架构
雨白2 小时前
Android 自定义 View:属性动画和硬件加速
android
血手人屠喵帕斯2 小时前
腾讯云人脸库技术架构深度解析
架构·云计算·腾讯云
hellokai3 小时前
React Native新架构源码分析
android·前端·react native
真西西3 小时前
Koin:Kotlin轻量级依赖注入框架
android·kotlin
yinke小琪4 小时前
今天解析一下从代码到架构:Java后端开发的"破局"与"新生"
java·后端·架构
tongsound4 小时前
Cyber RT 调度机制(Scheduler)
架构
小猿姐4 小时前
KubeBlocks For MySQL 云原生设计分享
mysql·云原生·架构
桃酥4034 小时前
聊一聊 单体分布式 和 微服务分布式
分布式·微服务·架构
数据智能老司机4 小时前
使用 MuleSoft 构建集成——系统集成的世界
架构·devops·连续集成