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:
1 parent
f87ef59d98
commit
0cff2b011a
8 files changed
+419
-4
No files matched your search
@@ -269,6 +269,29 @@ class SenderBridge {
|
||||
}
|
||||
}
|
||||
|
||||
/// 把串流画面弹出为独立原生窗口(Windows);返回是否成功。
|
||||
Future<bool> openVideoWindow() async {
|
||||
try {
|
||||
final opened = await _video.invokeMethod<bool>('openWindow');
|
||||
return opened ?? false;
|
||||
} on MissingPluginException {
|
||||
return false;
|
||||
} on PlatformException {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 关闭独立串流窗口,把画面收回主窗口。
|
||||
Future<void> closeVideoWindow() async {
|
||||
try {
|
||||
await _video.invokeMethod<bool>('closeWindow');
|
||||
} on MissingPluginException {
|
||||
// 老构建没有独立窗口能力。
|
||||
} on PlatformException {
|
||||
// 关闭失败无需打扰用户。
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> pairingUri() async {
|
||||
try {
|
||||
final value = await _method.invokeMethod<String>('pairingUri');
|
||||
|
||||
@@ -8,6 +8,8 @@ class VideoView extends StatelessWidget {
|
||||
this.resolution = '',
|
||||
this.pts,
|
||||
this.error = '',
|
||||
this.standalone = false,
|
||||
this.aspectRatio = 16 / 9,
|
||||
});
|
||||
|
||||
final int? textureId;
|
||||
@@ -18,11 +20,17 @@ class VideoView extends StatelessWidget {
|
||||
/// 原生解码链路的失败原因,为空表示没有错误。
|
||||
final String error;
|
||||
|
||||
/// 画面已弹出到独立窗口:主界面不再渲染纹理,只显示提示。
|
||||
final bool standalone;
|
||||
|
||||
/// 按实际码流宽高算出的比例(竖屏投屏时不再是 16:9)。
|
||||
final double aspectRatio;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
aspectRatio: aspectRatio > 0 ? aspectRatio : 16 / 9,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
child: DecoratedBox(
|
||||
@@ -39,7 +47,22 @@ class VideoView extends StatelessWidget {
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
if (textureId != null)
|
||||
if (standalone)
|
||||
Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.open_in_new,
|
||||
size: 72,
|
||||
color: theme.colorScheme.primary.withValues(alpha: 0.6)),
|
||||
const SizedBox(height: 12),
|
||||
Text('画面已在独立窗口播放', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 4),
|
||||
Text('把它拖到任意显示器,双击可全屏;关闭独立窗口后画面回到这里',
|
||||
style: theme.textTheme.bodySmall,
|
||||
textAlign: TextAlign.center),
|
||||
],
|
||||
)
|
||||
else if (textureId != null)
|
||||
Texture(textureId: textureId!)
|
||||
else
|
||||
Column(
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user