UE程序流转发Pixel Streaming

概述

简介

Epic Games 的 Pixel Streaming Infrastructure 是一个开源项目,旨在为基于 Unreal Engine 的应用程序提供实时、低延迟的流式传输解决方案,通过 WebRTC 技术将高质量的交互式内容从服务器或本地设备流式传输到支持 WebRTC 的浏览器或移动设备。该项目提供了运行 Pixel Streaming 应用程序所需的核心组件的参考实现,广泛应用于游戏、虚拟生产、远程协作等场景。

Pixel Streaming Infrastructure 是 Unreal Engine 的 Pixel Streaming 插件的配套基础设施,包含了服务器端和前端的参考实现,用于将 Unreal Engine 渲染的画面和音频通过 WebRTC 协议传输到客户端。它的核心目标是:

  • 跨平台访问:让用户通过任何支持 WebRTC 的现代浏览器(无需安装本地应用程序)访问高保真的 Unreal Engine 内容。
  • 模块化设计:提供可定制、可扩展的组件,开发者可以根据需求替换或修改部分实现。
  • 开源协作:托管在 GitHub 上,允许社区贡献代码、修复问题或提出新功能。

该项目最初位于 Unreal Engine 源码中的 Samples/PixelStreaming/WebServers,现已迁移到独立的 GitHub 仓库(EpicGamesExt/PixelStreamingInfrastructure),以便于社区协作和维护。

核心组件

Pixel Streaming Infrastructure 由多个模块化组件组成,它们协同工作以实现流式传输功能。

  1. 信令服务器(Signalling Web Server – Cirrus)
  • 路径:SignallingWebServer/
  • 功能:
    • 负责在 Unreal Engine 应用程序(Streamer)和客户端浏览器(Player)之间建立 WebRTC 连接。
    • 使用 WebSocket 协议处理连接协商,交换 IP 地址、端口等信息。
    • 支持 STUN/TURN 协议以穿越 NAT 和防火墙,确保网络连接的可靠性。
  1. 选择性转发单元(Selective Forwarding Unit – SFU)
  • 路径:SFU/
  • 功能:
    • 用于大规模分发流内容,优化多用户场景下的资源使用。
    • 接收来自 Unreal Engine 的单一流(支持 Simulcast 多分辨率流),并根据客户端的网络状况选择性地转发合适的流,无需重新编码,从而降低服务器负载。
  • 配置:
    • 通过js 文件配置信令服务器地址、日志级别、编解码器支持等。
    • 支持 Mediasoup 框架,允许自定义 WebRTC 传输参数。
  • 使用场景:
    • 适合需要支持大量并发用户的场景,例如在线展示或多人互动体验。
  1. 前端库(Frontend)
  • 路径:Frontend/
  • 功能:
    • 提供 WebRTC 播放器和用户输入的前端实现,用于在浏览器中显示流内容并处理用户交互。
    • 包含共享库(Common/)和多种技术实现(如 TypeScript、React/JSX)。
    • 支持自定义 HTML 播放页面,开发者可设计专属 UI 或添加交互控件。
  • 子目录:
    • /library:核心 Pixel Streaming 功能库,包含单元测试。
    • /ui-library:用户界面库,提供交互组件。
    • /implementations:不同技术栈的参考实现(如 TypeScript 示例)。
  1. 匹配服务器(Matchmaker)
  • 路径:Matchmaker/
  • 功能:
    • 用于将客户端分配到不同的 Pixel Streaming 实例,适合需要隔离用户会话的场景。
    • 帮助实现负载均衡或为每个用户提供独立的流体验。
  • 注意:
    • 从 Unreal Engine 5.5 开始,Matchmaker 已被废弃,建议开发者实现自定义解决方案。

部署

配合目前公司项目程序,使用5.3版本,且只需运行SignallingWebServer和Matchmaker。

程序下载

从Github上下载最新5.3版本程序:

wget https://github.com/EpicGamesExt/PixelStreamingInfrastructure/releases/download/UE5.3-1.0.7/UE5.3-1.0.7.tar.gz
tar zxf UE5.3-1.0.7.tar.gz -C /data/
mv /data/PixelStreamingInfrastructure-UE5.3-1.0.7/ /data/PixelStreamingInfrastructure-UE5.3

运行用户

创建用于运行服务的用户:

useradd --system -u 251 -s /sbin/nologin -c "UE Pixel Streaming" -m uepxstream

node程序运行需要在家目录创建文件,修改sudoers:

uepxstream      ALL=(ALL)       NOPASSWD: /data/PixelStreamingInfrastructure-UE5.3/*/*/*/*/*/node

配对服务Matchmaker

安装依赖:

cd /data/PixelStreamingInfrastructure-UE5.3/Matchmaker/
npm install

目前下有config.json配置文件,可根据需要修改配置文件中端口,默认监听9999。

手动启动:

./platform_scripts/bash/run.sh &

设为服务:

kill %1
chown -R uepxstream:uepxstream logs node_modules package.json package-lock.json
vim /usr/lib/systemd/system/ps-matchmaker.service
# systemd service file for PixelStreamingInfrastructure Matchmaker
[Unit]
Description=PixelStreamingInfrastructure Matchmaker Server
After=local-fs.target network.target syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=uepxstream
Group=uepxstream
WorkingDirectory=/data/PixelStreamingInfrastructure-UE5.3/Matchmaker
ExecStart=/data/PixelStreamingInfrastructure-UE5.3/Matchmaker/platform_scripts/bash/run.sh
systemctl enable --now ps-matchmaker.service
systemctl status ps-matchmaker.service

发表评论

error: Content is protected !!