UE4.26.2使用像素流:Player 101找不到问题的解决方法

1.进入如下已打包的UE4项目路径:

E:\WindowsNoEditor\Engine\Source\Programs\PixelStreaming\WebServers\SignallingWebServer

2.打开文件:cirrus

3.在第376行后加入如下代码:

_RemoveExtmapAllowMixed(msg);// 替换sdp协议内新内容

此块整体代码如下:

playerServer.on('connection', function (ws, req) {
	// Reject connection if streamer is not connected
	if (!streamer || streamer.readyState != 1 /* OPEN */) {
		ws.close(1013 /* Try again later */, 'Streamer is not connected');
		return;
	}

	let playerId = ++nextPlayerId;
	console.log(`player ${playerId} (${req.connection.remoteAddress}) connected`);
	players.set(playerId, { ws: ws, id: playerId });

	function sendPlayersCount() {
		let playerCountMsg = JSON.stringify({ type: 'playerCount', count: players.size });
		for (let p of players.values()) {
			p.ws.send(playerCountMsg);
		}
	}
	
	ws.on('message', function (msg) {
		console.logColor(logging.Blue, `<- player ${playerId}: ${msg}`);

		try {
			msg = JSON.parse(msg);
		} catch (err) {
			console.error(`Cannot parse player ${playerId} message: ${err}`);
			ws.close(1008, 'Cannot parse');
			return;
		}

		if (msg.type == 'offer') {
		    console.log(`<- player ${playerId}: offer`);
		    _RemoveExtmapAllowMixed(msg);// 替换sdp协议内新内容
			msg.playerId = playerId;
			streamer.send(JSON.stringify(msg));
		} else if (msg.type == 'iceCandidate') {
			console.log(`<- player ${playerId}: iceCandidate`);
			msg.playerId = playerId;
			streamer.send(JSON.stringify(msg));
		} else if (msg.type == 'stats') {
			console.log(`<- player ${playerId}: stats\n${msg.data}`);
		} else if (msg.type == 'kick') {
			let playersCopy = new Map(players);
			for (let p of playersCopy.values()) {
				if (p.id != playerId) {
					console.log(`kicking player ${p.id}`)
					p.ws.close(4000, 'kicked');
				}
			}
		} else {
			console.error(`<- player ${playerId}: unsupported message type: ${msg.type}`);
			ws.close(1008, 'Unsupported message type');
			return;
		}
	});

	function onPlayerDisconnected() {
		players.delete(playerId);
		streamer.send(JSON.stringify({type: 'playerDisconnected', playerId: playerId}));
		sendPlayerDisconnectedToFrontend();
		sendPlayerDisconnectedToMatchmaker();
		sendPlayersCount();
	}

	ws.on('close', function(code, reason) {
		console.logColor(logging.Yellow, `player ${playerId} connection closed: ${code} - ${reason}`);
		onPlayerDisconnected();
	});

	ws.on('error', function(error) {
		console.error(`player ${playerId} connection error: ${error}`);
		ws.close(1006 /* abnormal closure */, error);
		onPlayerDisconnected();
	});

	sendPlayerConnectedToFrontend();
	sendPlayerConnectedToMatchmaker();

	ws.send(JSON.stringify(clientConfig));

	sendPlayersCount();
});

4.在文件末尾追加如下代码

/**
 * sdp协议更新的方法
 * @param desc offer内容
 * @returns {string}
 */
function _RemoveExtmapAllowMixed(desc) {
    if (desc.sdp.indexOf('\na=extmap-allow-mixed') !== -1) {
        const sdp = desc.sdp.split('\n').filter((line) => {
            return line.trim() !== 'a=extmap-allow-mixed';
        }).join('\n');
        desc.sdp = sdp;
        return sdp;
    }
}

  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
要将MATLAB脚本与UE4.26.2进行联合仿真,可以按照以下步骤使用UE4.26.2中的MATLAB Function插件: 1. 安装MATLAB Engine API for C++。这是一个MATLAB Engine API的C++接口,可以让你在C++代码中嵌入MATLAB代码并执行。你可以从MathWorks官网下载并安装此API。 2. 在UE4.26.2中启用MATLAB Function插件。打开UE4.26.2编辑器,选择Edit > Plugins,在Plugins窗口中选择Scripting,然后启用MATLAB Function插件。 3. 创建一个新的MATLAB Function。在UE4.26.2中创建一个新的Blueprint Class,选择Actor,并为其命名。在该Actor的Details窗口中,选择Add Component > MATLAB Function。在这个MATLAB Function组件的Details窗口中,选择New MATLAB Function。 4. 将MATLAB脚本嵌入到UE4.26.2。在新的MATLAB Function窗口中,将MATLAB脚本复制并粘贴到Script窗口中。在Function Name窗口中为MATLAB函数命名。在Output Arguments窗口中指定MATLAB函数的输出参数。在Input Arguments窗口中指定MATLAB函数的输入参数。 5. 在UE4.26.2中调用MATLAB函数。在你的UE4.26.2蓝图类中,添加一个MATLAB Function组件的引用。在你的蓝图中,使用MATLAB Function组件的Execute函数来调用你的MATLAB函数。在调用MATLAB函数之前,你需要将输入参数设置为正确的值。调用完成后,你可以在Output Arguments窗口中获取MATLAB函数的输出参数。 通过这些步骤,你就可以在UE4.26.2中嵌入和执行MATLAB脚本了。这使得你可以创建更加复杂的仿真系统,其中包含了MATLAB和UE4.26.2之间的相互作用。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值