业务中涉及到Miracast,为了知其所以然,这里简单记录下大概流程的认识。
1 tcpdump 抓包
前提:手机需要有root权限
命令:
adb shell tcpdump -i p2p0 -s 0 -w /sdcard/capture.pcap
# "-i any": listen on any network interface 指定p2p0
# "-s 0": capture the entire packet
# "-w": write packets to a file (rather than printing to stdout)
2 Wireshark 基础使用
了解:界面使用、过滤器设置等
参考:wireshark抓包新手使用教程
3 Miracast 流程分析
安利一篇Miracast技术分析系列:
Miracast技术详解-codezjx
3.1 Android WiFi Display
Andorid 源码中DisplayManager封装了Miracast的能力。(注意:一般手机厂商有能力调用这些接口。此接口有的为hide接口,有的内部会校验caller pid是否系统应用,有的有权限要求)
这里通过上面的接口能实现调用MIracast能力。
3.2 RTSP协议
这里先抓包MIracast的投屏流程,导入Wireshark 分析。
根据Miracast技术详解(二):RTSP协议过一遍协议。
3.3 RTP & MPEG2-TS
3.3.1 协议部分
参考:Miracast技术详解(三):RTP & MPEG2-TS
3.3.2 从码流中分离音视频裸流
这里网上主要有两种方法:rtp_h264_extractor.lua 和 mpeg_packets_dump.lua。
搜到的主要是第一种方式,但是实测第二种是ok的。
-
rtp_h264_extractor.lua
使用这种方式解析出来的播放异常。
参考:
使用Wireshark在RTP流中提取中264数据(针对udp)
h264extractor-github -
mpeg_packets_dump.lua
能正常解析,使用VLC或者potplayer
参考:
Extract Mpeg TS from Wireshark
mpeg_dump.lua-Wireshark
4 参考和推荐
Android多屏互动-安卓端WiFiDisplay原理以及流媒体相关
Miracast技术详解 -协议部分