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

直接调用就好了。

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

相关推荐
灵感__idea3 小时前
Hello 算法:贪心的世界
前端·javascript·算法
GreenTea5 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
autumn20055 小时前
Flutter 框架跨平台鸿蒙开发 - 虚拟纪念馆
flutter·华为·harmonyos
不爱吃糖的程序媛6 小时前
拷贝或克隆其他 Flutter OH 项目到本地后无法运行
flutter
killerbasd6 小时前
牧苏苏传 我不装了 4/7
前端·javascript·vue.js
2301_822703206 小时前
渐变壁纸生成:基于鸿蒙Flutter的跨平台壁纸创建工具
flutter·华为·harmonyos·鸿蒙
吴声子夜歌6 小时前
ES6——二进制数组详解
前端·ecmascript·es6
码事漫谈7 小时前
手把手带你部署本地模型,让你Token自由(小白专属)
前端·后端
ZC跨境爬虫7 小时前
【爬虫实战对比】Requests vs Scrapy 笔趣阁小说爬虫,从单线程到高效并发的全方位升级
前端·爬虫·scrapy·html
爱上好庆祝7 小时前
svg图片
前端·css·学习·html·css3