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,
    );
  }
}

直接调用就好了。

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

相关推荐
前端不太难5 小时前
从 Navigation State 反推架构腐化
前端·架构·react
前端程序猿之路6 小时前
Next.js 入门指南 - 从 Vue 角度的理解
前端·vue.js·语言模型·ai编程·入门·next.js·deepseek
大布布将军6 小时前
⚡️ 深入数据之海:SQL 基础与 ORM 的应用
前端·数据库·经验分享·sql·程序人生·面试·改行学it
川贝枇杷膏cbppg6 小时前
Redis 的 RDB 持久化
前端·redis·bootstrap
子春一26 小时前
Flutter 2025 性能工程体系:从启动优化到帧率稳定,打造丝滑、省电、低内存的极致用户体验
flutter·ux
JIngJaneIL6 小时前
基于java+ vue农产投入线上管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
子春一26 小时前
Flutter 2025 性能工程体系:从启动优化到帧率稳定,打造丝滑如原生的用户体验
flutter·ux
天外天-亮7 小时前
v-if、v-show、display: none、visibility: hidden区别
前端·javascript·html
jump_jump7 小时前
手写一个 Askama 模板压缩工具
前端·性能优化·rust
be or not to be7 小时前
HTML入门系列:从图片到表单,再到音视频的完整实践
前端·html·音视频