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回调的信息,执行对应的逻辑;

相关推荐
sc.溯琛6 小时前
MySQL 高级实战:触发器、事务与数据库备份恢复全攻略
android·adb
踏浪无痕6 小时前
JobFlow已开源:面向业务中台的轻量级分布式调度引擎 — 支持动态分片与延时队列
后端·架构·开源
zhuzewennamoamtf7 小时前
Linux SPI设备驱动
android·linux·运维
踏浪无痕7 小时前
JobFlow 实战:无锁调度是怎么做到的
后端·面试·架构
再睡一夏就好8 小时前
深入Linux线程:从轻量级进程到双TCB架构
linux·运维·服务器·c++·学习·架构·线程
墨香幽梦客8 小时前
HA高可用架构选型:确保企业系统稳定运行的基石
架构
SmartBrain9 小时前
洞察:阿里通义DeepResearch 技术
大数据·人工智能·语言模型·架构
玖日大大9 小时前
LangGraph 深度解析:构建强大智能体的新一代框架
人工智能·语言模型·架构·langchain
studytosky9 小时前
Linux系统编程:深度解析 Linux 进程,从底层架构到内存模型
linux·运维·服务器·开发语言·架构·vim
雨声不在10 小时前
gradle编译missing_rules报错处理
android·gradle·agp8