- 添加对有线连接的支持,特别是 Pico 4 的有线连接 - 改进 ALVR 服务器检测和连接逻辑 - 优化 VR 帧获取和处理流程 - 增加备用帧获取功能(主摄像机视图) - 修复 VR 眼部纹理相关问题 - 优化 VR 任务管理,确保正确渲染和提交帧
264 lines
9.1 KiB
Python
264 lines
9.1 KiB
Python
#!/usr/bin/env python3
|
||
# -*- coding: utf-8 -*-
|
||
"""
|
||
VR串流测试脚本
|
||
专门用于测试和验证ALVR串流功能
|
||
"""
|
||
|
||
import sys
|
||
import os
|
||
import time
|
||
from main import MyWorld
|
||
|
||
|
||
def test_vr_streaming():
|
||
"""测试VR串流功能"""
|
||
print("=== VR串流功能测试 ===")
|
||
|
||
# 创建世界实例
|
||
world = MyWorld()
|
||
|
||
# 初始化VR系统
|
||
print("🥽 初始化VR系统...")
|
||
if not world.initializeVR():
|
||
print("✗ VR系统初始化失败")
|
||
return False
|
||
|
||
print("✓ VR系统初始化成功")
|
||
|
||
# 获取VR信息
|
||
vr_info = world.getVRInfo()
|
||
print(f"\n📊 VR系统信息:")
|
||
print(f" - 模式: {vr_info['mode']}")
|
||
print(f" - 启用状态: {vr_info['enabled']}")
|
||
print(f" - 模拟模式: {vr_info['simulation_mode']}")
|
||
print(f" - 渲染尺寸: {vr_info['render_size']}")
|
||
|
||
# 检查是否为直连模式(SteamVR已运行)
|
||
if world.alvr_streamer._is_steamvr_active():
|
||
print("\n💡 检测到SteamVR正在运行,将使用直连模式")
|
||
print(" 在直连模式下,画面将直接通过SteamVR传输到头显")
|
||
print(" 无需通过ALVR服务器进行额外的串流处理")
|
||
|
||
# 初始化ALVR串流
|
||
print("\n📡 初始化ALVR串流...")
|
||
print("💡 检测到您已连接VR设备,正在尝试连接ALVR服务器...")
|
||
alvr_success = world.initializeALVR()
|
||
|
||
if alvr_success:
|
||
print("✓ ALVR串流初始化成功")
|
||
|
||
# 设置串流质量
|
||
print("\n🎥 配置串流质量...")
|
||
quality_set = world.setALVRStreamQuality(1920, 1080, 60, 50)
|
||
if quality_set:
|
||
print(" ✓ 串流质量设置成功: 1920x1080@60fps, 50Mbps")
|
||
|
||
# 获取串流状态
|
||
status = world.getALVRStreamingStatus()
|
||
print(f"\n📊 ALVR串流初始状态:")
|
||
print(f" - 连接状态: {status['connected']}")
|
||
print(f" - 串流状态: {status['streaming']}")
|
||
print(f" - 分辨率: {status['resolution']}")
|
||
print(f" - 帧率: {status['fps']}")
|
||
print(f" - 码率: {status['bitrate']}Mbps")
|
||
|
||
# 开始串流
|
||
print(f"\n🚀 开始ALVR串流...")
|
||
if world.startALVRStreaming():
|
||
print("✓ ALVR串流已开始")
|
||
|
||
# 运行串流测试
|
||
print(f"\n📡 ALVR串流测试运行中... (10秒)")
|
||
start_time = time.time()
|
||
frame_count = 0
|
||
|
||
while time.time() - start_time < 10:
|
||
# 更新串流状态
|
||
current_status = world.getALVRStreamingStatus()
|
||
|
||
# 每2秒显示一次状态更新
|
||
if frame_count % 120 == 0: # 约每2秒
|
||
elapsed = time.time() - start_time
|
||
print(f" [{elapsed:.1f}s] FPS: {current_status['fps']}, 延迟: {current_status['latency']}ms")
|
||
|
||
if hasattr(world, 'taskMgr'):
|
||
world.taskMgr.step()
|
||
frame_count += 1
|
||
time.sleep(0.016)
|
||
|
||
# 停止串流
|
||
print("\n🛑 停止ALVR串流...")
|
||
world.stopALVRStreaming()
|
||
print("✓ ALVR串流已停止")
|
||
|
||
else:
|
||
print("⚠ ALVR串流启动失败")
|
||
print(" 可能原因:")
|
||
print(" - ALVR服务器未运行")
|
||
print(" - VR客户端未连接")
|
||
print(" - 网络连接问题")
|
||
|
||
else:
|
||
print("⚠ ALVR串流初始化失败")
|
||
print("💡 根据您提供的信息,您已经可以通过SteamVR看到画面,但串流测试无法连接到ALVR服务器")
|
||
print("\n💡 直连模式说明:")
|
||
print(" 如果您使用的是有线连接(如Pico 4通过USB-C连接)")
|
||
print(" 并且SteamVR已经可以正常显示画面,您实际上已经在使用直连模式")
|
||
print(" SteamVR会直接处理渲染并将画面传输到头显,无需额外的串流步骤")
|
||
print("\n🔧 建议操作:")
|
||
print(" 1. 确认SteamVR是否正常工作并显示画面")
|
||
print(" 2. 如果正常工作,您无需进行额外的ALVR串流设置")
|
||
print(" 3. 如果需要使用ALVR的额外功能,可以尝试:")
|
||
print(" - 关闭SteamVR")
|
||
print(" - 确保ALVR服务器正在运行")
|
||
print(" - 重新运行测试")
|
||
|
||
# 提供替代方案
|
||
print("\n🔄 替代方案:")
|
||
print(" 您可以尝试运行:")
|
||
print(" python3 vr_display_demo.py")
|
||
print(" 并选择'2. ALVR串流演示'来测试串流功能")
|
||
|
||
# 关闭系统
|
||
world.shutdownALVR()
|
||
world.shutdownVR()
|
||
print("\n✓ 所有系统已关闭")
|
||
|
||
return True
|
||
|
||
|
||
def test_vr_streaming_detailed():
|
||
"""详细测试VR串流功能"""
|
||
print("=== VR串流详细功能测试 ===")
|
||
|
||
# 创建世界实例
|
||
world = MyWorld()
|
||
|
||
# 初始化VR系统
|
||
print("🥽 初始化VR系统...")
|
||
if not world.initializeVR():
|
||
print("✗ VR系统初始化失败")
|
||
return False
|
||
|
||
print("✓ VR系统初始化成功")
|
||
|
||
# 检查VR纹理是否正确创建
|
||
print("\n🔍 检查VR纹理...")
|
||
if hasattr(world.vr_manager, 'left_eye_texture') and world.vr_manager.left_eye_texture:
|
||
print(" ✓ 左眼纹理已创建")
|
||
print(f" 纹理尺寸: {world.vr_manager.left_eye_texture.getXSize()}x{world.vr_manager.left_eye_texture.getYSize()}")
|
||
else:
|
||
print(" ✗ 左眼纹理未创建")
|
||
|
||
if hasattr(world.vr_manager, 'right_eye_texture') and world.vr_manager.right_eye_texture:
|
||
print(" ✓ 右眼纹理已创建")
|
||
print(f" 纹理尺寸: {world.vr_manager.right_eye_texture.getXSize()}x{world.vr_manager.right_eye_texture.getYSize()}")
|
||
else:
|
||
print(" ✗ 右眼纹理未创建")
|
||
|
||
# 初始化ALVR串流
|
||
print("\n📡 初始化ALVR串流...")
|
||
alvr_success = world.initializeALVR()
|
||
|
||
if alvr_success:
|
||
print("✓ ALVR串流初始化成功")
|
||
|
||
# 测试多种串流质量设置
|
||
print("\n🎥 测试多种串流质量设置:")
|
||
quality_settings = [
|
||
(1280, 720, 60, 25),
|
||
(1920, 1080, 60, 50),
|
||
(1920, 1080, 30, 25)
|
||
]
|
||
|
||
for width, height, fps, bitrate in quality_settings:
|
||
success = world.setALVRStreamQuality(width, height, fps, bitrate)
|
||
if success:
|
||
status = world.getALVRStreamingStatus()
|
||
print(f" ✓ 设置 {width}x{height}@{fps}fps, {bitrate}Mbps: 成功")
|
||
print(f" 实际分辨率: {status['resolution']}")
|
||
else:
|
||
print(f" ✗ 设置 {width}x{height}@{fps}fps, {bitrate}Mbps: 失败")
|
||
|
||
# 测试串流控制
|
||
print("\n🎮 测试串流控制:")
|
||
|
||
# 开始串流
|
||
if world.startALVRStreaming():
|
||
print(" ✓ 串流开始成功")
|
||
|
||
# 检查串流状态
|
||
status = world.getALVRStreamingStatus()
|
||
print(f" 串流状态: {status['streaming']}")
|
||
print(f" 连接状态: {status['connected']}")
|
||
|
||
# 等待2秒
|
||
time.sleep(2)
|
||
|
||
# 再次检查状态
|
||
status = world.getALVRStreamingStatus()
|
||
print(f" 2秒后状态 - FPS: {status['fps']}, 延迟: {status['latency']}ms")
|
||
|
||
# 停止串流
|
||
world.stopALVRStreaming()
|
||
status = world.getALVRStreamingStatus()
|
||
print(f" ✓ 串流停止成功")
|
||
print(f" 串流状态: {status['streaming']}")
|
||
|
||
else:
|
||
print(" ✗ 串流开始失败")
|
||
|
||
else:
|
||
print("⚠ ALVR串流初始化失败")
|
||
print("\n🔧 Pico 4连接故障排除:")
|
||
print(" 1. 确认ALVR服务器正在运行")
|
||
print(" 2. 检查USB连接是否正常")
|
||
print(" 3. 确认Pico 4上已安装并启动ALVR客户端")
|
||
print(" 4. 检查防火墙设置")
|
||
print(" 5. 确认SteamVR可以识别到头显")
|
||
|
||
# 关闭系统
|
||
world.shutdownALVR()
|
||
world.shutdownVR()
|
||
print("\n✓ 所有系统已关闭")
|
||
|
||
return True
|
||
|
||
|
||
def main():
|
||
"""主函数"""
|
||
print("🎮 VR串流测试脚本")
|
||
print("="*50)
|
||
|
||
print("\n请选择测试类型:")
|
||
print("1. 基本串流测试")
|
||
print("2. 详细串流测试")
|
||
|
||
try:
|
||
choice = input("请输入选择 (1-2): ")
|
||
|
||
if choice == "1":
|
||
success = test_vr_streaming()
|
||
elif choice == "2":
|
||
success = test_vr_streaming_detailed()
|
||
else:
|
||
print("无效的选择")
|
||
return
|
||
|
||
print("\n" + "="*50)
|
||
if success:
|
||
print("✓ 串流测试成功完成")
|
||
else:
|
||
print("✗ 串流测试遇到问题")
|
||
|
||
except KeyboardInterrupt:
|
||
print("\n用户中断测试")
|
||
except Exception as e:
|
||
print(f"测试过程中发生错误: {str(e)}")
|
||
import traceback
|
||
traceback.print_exc()
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main() |