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

相关推荐
Cao_Shixin攻城狮37 分钟前
Flutter运行Android项目时显示java版本不兼容(Unsupported class file major version 65)的处理
android·java·flutter
呼啦啦呼啦啦啦啦啦啦4 小时前
利用pdfjs实现的pdf预览简单demo(包含翻页功能)
android·javascript·pdf
idjl5 小时前
Mysql测试题
android·adb
@大迁世界6 小时前
前端:优秀架构的坟墓
前端·架构
?ccc?7 小时前
Kubernetes 架构原理与集群环境部署
容器·架构·kubernetes
游戏开发爱好者88 小时前
iOS App 电池消耗管理与优化 提升用户体验的完整指南
android·ios·小程序·https·uni-app·iphone·webview
人生游戏牛马NPC1号8 小时前
学习 Flutter (四):玩安卓项目实战 - 中
android·学习·flutter
秋千码途9 小时前
小架构step系列17:getter-setter-toString
java·开发语言·架构
Ashlee_code9 小时前
美联储降息趋缓叠加能源需求下调,泰国证券交易所新一代交易系统架构方案——高合规、强韧性、本地化的跨境金融基础设施解决方案
java·算法·金融·架构·系统架构·区块链·需求分析
星辰也为你祝福h10 小时前
Android原生Dialog
android