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

相关推荐
却尘37 分钟前
让 AI 不再写到一半就开始"编":SDD + OpenSpec 上手指南
架构
Ehtan_Zheng2 小时前
Android Compose 动画实践:内容切换与页面转场
android
Crystal3282 小时前
【终极指南】前端方面解决 uni-app APP 端 SSE 流式请求被缓冲拦截、无法实时渲染的问题
android·前端·ai编程
梦梦代码精2 小时前
LikeShop 二次开发扩展能力白皮书——面向业务增长的可扩展电商架构实践
java·架构·github
该昵称用户已存在2 小时前
从单体到微服务・从本地到云端:MyEMS 开源系统的架构演进与落地优势
微服务·架构·开源
IPHWT 零软网络3 小时前
OM200G-A融合通信IP-PBX:国产化架构下的高可靠政企通信解决方案
网络协议·tcp/ip·架构
陆业聪3 小时前
技术选型决策树:什么团队、什么项目该选什么框架 | 跨平台框架深度对决(4)
android·架构设计
2501_912784084 小时前
TaoCarts 反向海淘系统架构实战:1688代采与高并发缓存设计全解析
缓存·架构·系统架构·跨境电商·taocarts
zhou lily4 小时前
高可用(HA)架构的商业价值:从技术冗余到业务连续性的战略升级
架构
fuquxiaoguang4 小时前
SSA架构:国产AI推理的“换道超车“,算力消耗降低1000倍
人工智能·架构·ssa