名词解释
VAAPI = Video Acceleration API
https://en.wikipedia.org/wiki/Video_Acceleration_API
https://chromium.googlesource.com/chromium/src/+/master/docs/gpu/vaapi.md
下载和编译
chrome:
https://chromium.googlesource.com/chromium/src/+/main/docs/linux/build_instructions.md
去掉不需要的,加快编译速度
enable_nacl=false
blink_symbol_level=0
dcheck_always_on = false
use_vaapi被设置成true之后,在media/BUILD.gn中,USE_CHROMEOS_MEDIA_ACCELERATION也同样被设置了。
打开vaapi还需要做以下修改
// media/base/media_switches.cc
media/base/media_switches.cc
// 这个如前面所说已经被设置过了
#if BUILDFLAG(USE_CHROMEOS_MEDIA_ACCELERATION)
// Enable the hardware-accelerated direct video decoder instead of the one
// needing the VdaVideoDecoder adapter. This flag is used mainly as a
// chrome:flag for developers debugging issues as well as to be able to
// experiment with direct VideoDecoder path on Linux Desktop.
// TODO(b/159825227): remove when the direct video decoder is fully launched.
const base::Feature kUseChromeOSDirectVideoDecoder{
"UseChromeOSDirectVideoDecoder", base::FEATURE_ENABLED_BY_DEFAULT}; //改下这行,改成这
然后启动浏览器的时候需要带参数
/usr/bin/bytedance-vulcan \
--enable-features=VaapiVideoDecoder,VaapiVideoEncoder \
--disable-features=UseChromeOSDirectVideoDecoder \
--ignore-gpu-blocklist \
--use-gl=egl \
--enable-zero-copy \
还有就是需要
安装最新的intel vaapi版本deb包
暂时无法在飞书文档外展示此内容
不然会出现如下错误(chrome://gpu中就可以看到打印),说明当前vaapi版本太低(vainfo可以看到vaapi版本)
Log Messages
[13767:13767:1130/160938.161248:VERBOSE1:vaapi_wrapper.cc(704)] : InitializeVaDriver_Locked(): The system version 1.10 should be greater than or equal to 1.12
[13767:13767:1130/160938.163106:ERROR:gl_surface_egl.cc(837)] : EGL Driver message (Error) eglQueryDeviceAttribEXT: eglQueryDeviceStringEXT
[13767:13767:1130/160938.163191:ERROR:gl_angle_util_vulkan.cc(189)] : Failed to retrieve vkGetInstanceProcAddr
安装上述deb包
- 进入libva-utils文件夹,执行sudo dpkg -i *.deb。安装完之后vainfo才会可用
- 进入libva文件夹,执行sudo dpkg -i *.deb。此时再执行vainfo之后,版本号已经变为1.16。此时再按照之前的步骤运行chromium,即可启用硬解播放视频。
u_7158715363469819907@ocean:~$ vainfo
libva info: VA-API version 1.16.0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
libva info: Found init function __vaDriverInit_1_10
libva info: va_openDriver() returns 0
vainfo: VA-API version: 1.16 (libva 2.17.0.pre1)
vainfo: Driver version: Intel iHD driver for Intel(R) Gen Graphics - 21.1.1 ()
vainfo: Supported profile and entrypoints
VAProfileNone : VAEntrypointVideoProc
VAProfileNone : VAEntrypointStats
VAProfileMPEG2Simple : VAEntrypointVLD
VAProfileMPEG2Simple : VAEntrypointEncSlice
VAProfileMPEG2Main : VAEntrypointVLD
VAProfileMPEG2Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointVLD
VAProfileH264Main : VAEntrypointEncSlice
VAProfileH264Main : VAEntrypointFEI
VAProfileH264Main : VAEntrypointEncSliceLP
VAProfileH264High : VAEntrypointVLD
VAProfileH264High : VAEntrypointEncSlice
VAProfileH264High : VAEntrypointFEI
VAProfileH264High : VAEntrypointEncSliceLP
VAProfileVC1Simple : VAEntrypointVLD
VAProfileVC1Main : VAEntrypointVLD
VAProfileVC1Advanced : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointVLD
VAProfileJPEGBaseline : VAEntrypointEncPicture
VAProfileH264ConstrainedBaseline: VAEntrypointVLD
VAProfileH264ConstrainedBaseline: VAEntrypointEncSlice
VAProfileH264ConstrainedBaseline: VAEntrypointFEI
VAProfileH264ConstrainedBaseline: VAEntrypointEncSliceLP
VAProfileVP8Version0_3 : VAEntrypointVLD
VAProfileVP8Version0_3 : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointVLD
VAProfileHEVCMain : VAEntrypointEncSlice
VAProfileHEVCMain : VAEntrypointFEI
VAProfileHEVCMain10 : VAEntrypointVLD
VAProfileHEVCMain10 : VAEntrypointEncSlice
VAProfileVP9Profile0 : VAEntrypointVLD
VAProfileVP9Profile2 : VAEntrypointVLD
怎么在debian11的环境下开启chromium的硬解码
chromium按照前面的操作实验完,dell 3630上没法启动硬解!但是vlc可以!
经过各种尝试,终于在3630 debian11上使用chromium成功启用硬件解码!使用的启动参数如下(当然也包括了前面args.gn和代码的修改)
out/Default/chrome \
--enable-features=VaapiVideoDecoder,VaapiVideoEncoder \
--disable-features=UseChromeOSDirectVideoDecoder \
--ignore-gpu-blocklist \
--use-gl=egl \
--enable-zero-copy \
#这个设置很关键,debian11是x11架构(但是在setting里看是wayland!啥情况)
#但是,debian11上跑vulcan的时候不能加下面两个,不然就没法开启硬解
--enable-features=UseOzonePlatform \
--ozone-platform=x11 \
打包命令
ninja -C out/Release “chrome/installer/linux:unstable_deb”
Debug
https://chromium.googlesource.com/chromium/src/+/main/docs/linux/debugging.md
https://chromium.googlesource.com/chromium/src/+/master/docs/gpu/vaapi.md
在线看源码/快速搜索源码
https://source.chromium.org/
视频播放测试
http://storage.googleapis.com/watk/v
查看chrome视频播放调试信息
For Intel GPU, use intel-gpu-tools and run intel_gpu_top as root to monitor the GPU activity during video playback for example. The video bar being above 0% indicates GPU video decoder/encoder usage.
chrome://media-internals
或者 浏览器inpect中的media中可以看
另外intel gpu可以使用如下命令查看占用情况
intel_gpu_top(apt install intel-gpu-tools)
//这个也可以看到
chrome://gpu/
...
Graphics Feature Status
Canvas: Hardware accelerated
Canvas out-of-process rasterization: Disabled
Direct Rendering Display Compositor: Disabled
Compositing: Hardware accelerated
Multiple Raster Threads: Enabled
OpenGL: Enabled
Rasterization: Hardware accelerated
Raw Draw: Disabled
Video Decode: Hardware accelerated
Video Encode: Software only. Hardware acceleration disabled
Vulkan: Disabled
WebGL: Hardware accelerated
WebGL2: Hardware accelerated
WebGPU: Disabled
...
To verify that a given video is being played back using the accelerated video decoding backend:
- Navigate to a url that causes a video to be played. Leave it playing.
- Navigate to the chrome://media-internals tab.
- Find the entry associated to the video-playing tab.
- Scroll down to “Player Properties” and check the “video_decoder” entry: it should say “GpuVideoDecoder”.
这里,如果kVideoDecoderName显示“VDAVideoDecoder”应该也是硬解码,前面这个解释可能已经是过时的
软解的时候显示"FFmpegVideoDecoder"
参考:
https://bbs.archlinux.org/viewtopic.php?id=244031&p=21
VDA = VideoDecodeAccelerator
打印log
https://www.chromium.org/for-testers/enable-logging/
–enable-logging=stderr --v=1 # Output will be printed to standard error (eg. printed in the console) and to the debugger
–enable-logging=stderr --v=1 > log.txt 2>&1 # Capture stderr and stdout to a log file gdb调试 gdb -tui -ex=r --args out/Default/chrome
–single-process --disable-seccomp-sandbox \http://www.youtube.com
// 如果要调试vaapi,硬解
gdb -tui -ex=r --args out/Default/chrome --single-process --disable-seccomp-sandbox --enable-features=VaapiVideoDecoder,VaapiVideoEncoder --disable-features=UseChromeOSDirectVideoDecoder --ignore-gpu-blocklist --use-gl=egl --enable-zero-copy --enable-features=UseOzonePlatform --ozone-platform=x11 \http://www.youtube.com
// 直接这样吧
gdb -tui -ex=r --args out/debug_vulcan/chrome --disable-seccomp-sandbox --enable-features=VaapiVideoDecoder,VaapiVideoEncoder --disable-features=UseChromeOSDirectVideoDecoder --ignore-gpu-blocklist --use-gl=egl --enable-zero-copy \http://www.ixigua.com
要加上–single-processs,不然断点怎么下都没法命中
chrome起来,打开页面之后,ctrl+c可以回到输入gdb指令模式
//打个断点
(gdb) b FFmpegVideoDecoder::ConfigureDecoder
Breakpoint 1 at 0x555567e05fb4
//查看当前断点情况
(gdb) info b
Num Type Disp Enb Address What
1 breakpoint keep y 0x0000555567e05fb4 <media::FFmpegVideoDecoder::ConfigureDecoder(media::VideoDecoderCon
fig const&, bool)+4>
//continue继续运行
(gdb) c
// 其他常用gdb命令
list/l 行号:显示binFile源代码,接着上次的位置往下列,每次列10行。
list/l 函数名:列出某个函数的源代码。
r 或 run:运行程序。
n 或 next:单条执行。
s或step:进入函数调用。
break(b) 行号:在某一行设置断点。
break 函数名:在某个函数开头设置断点。
info break :查看断点信息。
finish:执行到当前函数返回,然后挺下来等待命令。
print(p):打印表达式的值,通过表达式可以修改变量的值或者调用函数。
p 变量:打印变量值。
set var:修改变量的值。
continue(或c):从当前位置开始连续而非单步执行程序。
run(或r):从开始连续而非单步执行程序。
delete breakpoints:删除所有断点。
delete breakpoints n:删除序号为n的断点。
disable breakpoints:禁用断点。
enable breakpoints:启用断点。
info(或i) breakpoints:参看当前设置了哪些断点。
display 变量名:跟踪查看一个变量,每次停下来都显示它的值。
undisplay:取消对先前设置的那些变量的跟踪。
until X行号:跳至X行。
breaktrace(或bt):查看各级函数调用及参数。
info(i) locals:查看当前栈帧局部变量的值。
quit:退出gdb。
Trace
如下代码所示,很强大的trace功能
void MojoVideoDecoderService::Construct(
mojo::PendingAssociatedRemote<mojom::VideoDecoderClient> client,
mojo::PendingRemote<mojom::MediaLog> media_log,
mojo::PendingReceiver<mojom::VideoFrameHandleReleaser>
video_frame_handle_releaser_receiver,
mojo::ScopedDataPipeConsumerHandle decoder_buffer_pipe,
mojom::CommandBufferIdPtr command_buffer_id,
const gfx::ColorSpace& target_color_space) {
DVLOG(1) << __func__;
TRACE_EVENT0("media", "MojoVideoDecoderService::Construct");
然后通过下面的方式,就可以抓取到trace
https://www.chromium.org/developers/how-tos/trace-event-profiling-tool/recording-tracing-runs/
文件长下面这样
然后在我们日常使用的release版本的chrome中即可打开分析
绝对是另外一个调试利器!