feat(sender): 支持把串流画面弹出为独立原生窗口

- 新增 windows/runner/video_window.{h,cpp}:Win32 顶层窗口,GDI 直接绘制解码后的 BGRA 帧,支持拖到任意显示器/最大化/双击或 F11 全屏/ESC 退出

- FrameStore 增加 Snapshot()(shared_ptr 保活),独立窗口与主窗口共享同一份帧,不重复解码、不抢 Rust 单消费者帧队列

- 独立窗口在播时跳过 MarkTextureFrameAvailable,省一次 BGRA 拷贝;主界面显示占位提示

- ttstd/video 通道新增 openWindow/closeWindow/windowOpen,stats 带 windowOpen

- VideoView 按真实码流宽高算显示比例,竖屏投屏不再被压成 16:9
This commit is contained in:
tongtong committed 2026-11-27 09:28:46 +08:00
1 parent f87ef59d98
commit 0cff2b011a
8 files changed
+419 -4

No files matched your search

+44 -1
View File
@@ -60,6 +60,8 @@ class _HomePageState extends State<HomePage> {
Map<String, dynamic> _demoStatus = const <String, dynamic>{'running': false};
Map<String, dynamic> _videoStats = const <String, dynamic>{};
int? _textureId;
/// 串流画面是否已弹出到独立原生窗口。
bool _videoWindowOpen = false;
String? _nativeError;
@override
@@ -153,14 +155,37 @@ class _HomePageState extends State<HomePage> {
final stats = await _bridge.videoStats();
if (!mounted || stats.isEmpty) return;
final id = stats['textureId'];
final windowOpen = stats['windowOpen'];
setState(() {
_videoStats = stats;
if (_textureId == null && id is int && id > 0) {
_textureId = id;
}
if (windowOpen is bool) {
_videoWindowOpen = windowOpen;
}
});
}
/// 把串流画面弹出/收回独立原生窗口(Windows)。
Future<void> _toggleVideoWindow() async {
if (_videoWindowOpen) {
await _bridge.closeVideoWindow();
if (!mounted) return;
setState(() => _videoWindowOpen = false);
return;
}
final opened = await _bridge.openVideoWindow();
if (!mounted) return;
if (!opened) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('当前平台不支持独立串流窗口')),
);
return;
}
setState(() => _videoWindowOpen = true);
}
void _writeDiagnosticLog() {
Map<String, dynamic> status;
if (_nativeCore == null) {
@@ -327,6 +352,11 @@ class _HomePageState extends State<HomePage> {
appBar: AppBar(
title: const Text('TTSTD Connect'),
actions: [
IconButton(
tooltip: _videoWindowOpen ? '收回串流窗口' : '串流独立窗口',
onPressed: _toggleVideoWindow,
icon: Icon(_videoWindowOpen ? Icons.close_fullscreen : Icons.open_in_new),
),
IconButton(
tooltip: '扫码配对',
onPressed: _showPairing,
@@ -510,6 +540,16 @@ class _HomePageState extends State<HomePage> {
String get _videoError => (_videoStats['error'] as String? ?? '').trim();
/// 按实际码流宽高算显示比例;竖屏被控端(如 1080x2400)不再被压成 16:9。
double get _videoAspectRatio {
final width = _videoStats['width'];
final height = _videoStats['height'];
if (width is int && height is int && width > 0 && height > 0) {
return width / height;
}
return 16 / 9;
}
Widget _buildStage() {
return Padding(
padding: const EdgeInsets.all(16),
@@ -517,11 +557,14 @@ class _HomePageState extends State<HomePage> {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
VideoView(
textureId: _textureId,
// 独立窗口在播时不再占用主窗口纹理。
textureId: _videoWindowOpen ? null : _textureId,
connected: _phase.isConnected,
resolution: _videoResolution,
pts: _videoPts,
error: _videoError,
standalone: _videoWindowOpen,
aspectRatio: _videoAspectRatio,
),
const SizedBox(height: 16),
ConnectBar(