Flutter在OrangePi 5 Plus上视频播放锁死问题

错误:程序直接卡死,用gdb调试发现是锁死

termial 复制代码
(gdb) bt #0 futex_wait (private=0, expected=2, futex_word=0xaaaaf5c81b10) at ../sysdeps/nptl/futex-internal.h:146 #1 __GI___lll_lock_wait (futex=futex@entry=0xaaaaf5c81b10, private=private@entry=0) at ./nptl/lowlevellock.c:49 #2 0x0000ffffa7188c74 in lll_mutex_lock_optimized (mutex=0xaaaaf5c81b10) at ./nptl/pthread_mutex_lock.c:48 #3 ___pthread_mutex_lock (mutex=0xaaaaf5c81b10) at ./nptl/pthread_mutex_lock.c:93 #4 0x0000ffff73dffcf4 in ??? () at /usr/lib/aarch64-linux-gnu/dri/rockchip_dri.so #5 0x0000ffff73debea4 in ??? () at /usr/lib/aarch64-linux-gnu/dri/rockchip_dri.so #6 0x0000ffff73d05634 in ??? () at /usr/lib/aarch64-linux-gnu/dri/rockchip_dri.so #7 0x0000ffff7348487c in ??? () at /usr/lib/aarch64-linux-gnu/dri/rockchip_dri.so #8 0x0000ffff7348e254 in ??? () at /usr/lib/aarch64-linux-gnu/dri/rockchip_dri.so #9 0x0000ffff733e0bcc in ??? () at /usr/lib/aarch64-linux-gnu/dri/rockchip_dri.so #10 0x0000ffff847ead14 in ??? () at /lib/aarch64-linux-gnu/libEGL_mesa.so.0 #11 0x0000ffff847e2a3c in ??? () at /lib/aarch64-linux-gnu/libEGL_mesa.so.0 #12 0x0000ffffb4108a18 in ??? () at /lib/aarch64-linux-gnu/libgdk-3.so.0 #13 0x0000ffffb39b6874 in g_object_unref () at /lib/aarch64-linux-gnu/libgobject-2.0.so.0 #14 0x0000ffffb5884290 in video_output_dispose(_GObject*) () at /home/holomotion/local/bin/ntsports/client_versions/lib/libmedia_kit_video_plugin.so

卡死点非常清晰: media_kit_video_plugin.sovideo_output_dispose() 里做销毁(#14),往下进入g_object_unred->libEGL_mesa.sp->rockchip_dri.so,最终卡在pthread_metex_lock(futex_wait)。 这说明正在销毁EGL/GL相关资源时,驱动里还有渲染中的帧/上下文在用,典型"还在画,先被拆"情形。

GL :提供一套图形渲染API,允许开发者用软件控制GPU绘制三维或二维的图形。开发者可以用GL来创建顶点、纹理、光照、着色器(shander)等。

EGL:负责图形上下文管理和显示系统交互。在OpenGL ES中,你需要一个EGL上下文才能开始渲染。它负责把GL渲染的内容输出到屏幕(framebuffer、窗口、离屏缓冲等)。

  1. 创建渲染上下文(EGLContext)
  2. 创建渲染表面(EGLSurface),例如屏幕窗口、离屏纹理;
  3. 绑定上下文和表面,使GL的命令能渲染到目标;
  4. 同步和交换缓冲区(swap buffers)

根据卡死原因,本人排查了所有实现video播放的逻辑。 发现主要有两个原因: 1、关闭硬件解码,资源暴涨; 2、短时间可能销毁、创建、静默多个video,资源占用。

开启硬件解码

dart 复制代码
Video(
  controller: VideoController(widget.player,
      configuration: VideoControllerConfiguration(
        enableHardwareAcceleration:
            Config.instance.enableHardwareAcceleration,
        hwdec: 'no',
      )),
  fill: widget.fill,
  fit: widget.fit,
  controls: media_kit_video_controls.NoVideoControls,
);

hwdec:'no'代表强制禁用了硬件解码,这会导致高分辨率视频用软件解码把CPU卡死。 在Linux桌面上,如果视频是1080p/4K,高码率的话,CPU很容易跑满,Flutter UI就会卡死。 直接去掉。

创建全局单例 Player

dart 复制代码
class GlobalVideoPlayer {
  GlobalVideoPlayer._internal() {
    player = Player();
  }

  late final Player player;

  static final GlobalVideoPlayer instance = GlobalVideoPlayer._internal();
}

class ReusableVideo extends StatefulWidget {
  const ReusableVideo({
    super.key,
    this.fit = BoxFit.contain,
    this.fill = Colors.white,
  });
  final BoxFit fit;
  final Color fill;
  @override
  State<ReusableVideo> createState() => _ReusableVideoState();
}

class _ReusableVideoState extends State<ReusableVideo> {
  late final Player _player;

  @override
  void initState() {
    super.initState();
    _player = GloablVideoPlayer.instance.player;
    _closeVolume();
  }

  Future<void> _closeVolume() async {
    await _player.setVolume(0);
  }

  @override
  Widget build(BuildContext context) {
    return Video(
      controller: VideoController(_player,
          configuration: VideoControllerConfiguration(
              enableHardwareAcceleration:
                  Config.instance.enableHardwareAcceleration)),
      fill: widget.fill,
      fit: widget.fit,
      controls: media_kit_video_controls.NoVideoControls,
    );
  }
}

直接调用就好了。

效果实现了,程序还在测试中...

相关推荐
wyzqhhhh24 分钟前
less和sass
前端·less·sass
Nan_Shu_6142 小时前
学习:uniapp全栈微信小程序vue3后台-额外/精彩报错篇
前端·学习·微信小程序·小程序·uni-app·notepad++
excel3 小时前
Vue3 中的双向链表依赖管理详解与示例
前端
前端小白从0开始3 小时前
Chrome DevTools高级用法:性能面板内存泄漏排查
前端·chrome·chrome devtools
EveryPossible3 小时前
带有渐变光晕
前端·javascript·css
jojo是只猫4 小时前
Vue 3 开发的 HLS 视频流播放组件+异常处理
前端·javascript·vue.js
卓码软件测评4 小时前
第三方软件登记测试机构:【软件登记测试机构HTML5测试技术】
前端·功能测试·测试工具·html·测试用例·html5
CS Beginner4 小时前
【html】canvas实现一个时钟
前端·html
林烈涛4 小时前
js判断变量是数组还是对象
开发语言·前端·javascript
Komorebi_99995 小时前
Unocss
开发语言·前端