feat(video): 打通桌面端真实视频画面链路
- Rust: 新增 media::stream 访问单元队列与分片重组,FFI 增加 ttstd_video_next/pending/stats(ABI 2) - Windows: runner 内嵌 Media Foundation 解码纹理插件(NV12/RGB32→BGRA),开启 CODECAPI_AVLowLatencyMode 消除约 36 帧积压,按显示区域裁掉 16 对齐补齐行 - Android: 大帧按 1200 字节分片发送;csd(SPS/PPS) 随每个关键帧重发,修复先投屏后连接时只收到 P 帧导致的黑屏 - Flutter: 独立 ttstd/video 通道获取 textureId 与统计,VideoView 渲染 Texture 并显示分辨率/PTS/失败原因 - 诊断: stats 增加 format/auBytes/keyframes/submitHr;缺插件、缺 SPS/PPS 显式提示;TTSTD_DUMP_VIDEO 可抓码流配合 ffprobe 定位 - 发现与服务检查: mDNS 发现客户端、服务地址探测、设置页与连接状态卡片(启动本机监听/停止) - 工具与文档: video_feed 推流示例、一键打包脚本、DEMO 出画面排查表与实测截图
This commit is contained in:
1 parent
adaa23f895
commit
df2affa9e2
30 files changed
+2814
-134
No files matched your search
@@ -3,6 +3,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'discovery_client.dart';
|
||||
import 'local_signaling.dart';
|
||||
import 'models.dart';
|
||||
import 'native_core.dart';
|
||||
@@ -21,6 +22,9 @@ class SenderBridge {
|
||||
final NativeCore? _native;
|
||||
final LocalSignalingProcess _localSignaling = LocalSignalingProcess();
|
||||
|
||||
/// 原生视频解码纹理通道(Windows runner 内嵌插件)。
|
||||
static const MethodChannel _video = MethodChannel('ttstd/video');
|
||||
|
||||
NativeCore? get nativeCore => _native;
|
||||
|
||||
bool get isLocalSignalingRunning => _localSignaling.isRunning;
|
||||
@@ -33,23 +37,13 @@ class SenderBridge {
|
||||
.distinct();
|
||||
}
|
||||
|
||||
Future<List<DeviceInfo>> discover() async {
|
||||
Future<List<DeviceInfo>> discover({String? signalingUrl}) async {
|
||||
if (signalingUrl != null && signalingUrl.trim().isNotEmpty) {
|
||||
final discovered = await DiscoveryClient.listDevices(signalingUrl);
|
||||
if (discovered.isNotEmpty) return discovered;
|
||||
}
|
||||
if (_native != null) {
|
||||
final localIp = await _localIp();
|
||||
if (localIp == null) return const <DeviceInfo>[];
|
||||
return [
|
||||
DeviceInfo(
|
||||
id: 'local-listener',
|
||||
name: '本机监听端点',
|
||||
ip: localIp,
|
||||
mediaPort: 41000,
|
||||
controlPort: 41001,
|
||||
fingerprint: '',
|
||||
capabilities: const <String>[],
|
||||
model: '',
|
||||
resolution: '',
|
||||
),
|
||||
];
|
||||
return const <DeviceInfo>[];
|
||||
}
|
||||
try {
|
||||
final raw = await _method.invokeListMethod<dynamic>('discover');
|
||||
@@ -62,6 +56,22 @@ class SenderBridge {
|
||||
}
|
||||
}
|
||||
|
||||
Future<DeviceInfo?> localListener() async {
|
||||
final localIp = await _localIp();
|
||||
if (localIp == null) return null;
|
||||
return DeviceInfo(
|
||||
id: 'local-listener',
|
||||
name: '本机监听端点',
|
||||
ip: localIp,
|
||||
mediaPort: 41000,
|
||||
controlPort: 41001,
|
||||
fingerprint: '',
|
||||
capabilities: const <String>[],
|
||||
model: '',
|
||||
resolution: '',
|
||||
);
|
||||
}
|
||||
|
||||
static Future<String?> _localIp() async {
|
||||
try {
|
||||
final interfaces = await NetworkInterface.list(
|
||||
@@ -202,6 +212,35 @@ class SenderBridge {
|
||||
Map<String, dynamic> demoStatus() =>
|
||||
_native?.demoStatus() ?? <String, dynamic>{'running': false};
|
||||
|
||||
/// 原生视频纹理 ID;无原生实现或纹理尚未注册时返回 null。
|
||||
Future<int?> videoTextureId() async {
|
||||
try {
|
||||
final id = await _video.invokeMethod<int>('textureId');
|
||||
if (id == null || id <= 0) return null;
|
||||
return id;
|
||||
} on MissingPluginException {
|
||||
return null;
|
||||
} on PlatformException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// 原生视频解码统计:textureId/decoded/pending/received/width/height/pts/error。
|
||||
Future<Map<String, dynamic>> videoStats() async {
|
||||
try {
|
||||
final stats = await _video.invokeMapMethod<String, dynamic>('stats');
|
||||
return stats ?? const <String, dynamic>{};
|
||||
} on MissingPluginException {
|
||||
// 老构建产物(runner 里没有视频纹理插件)会走到这里,必须显式提示,
|
||||
// 否则界面只会停在「视频通道已建立」,看不出是二进制过期。
|
||||
return const <String, dynamic>{
|
||||
'error': '当前程序缺少原生视频插件(旧版构建),请重新构建/重新解压发布包',
|
||||
};
|
||||
} on PlatformException {
|
||||
return const <String, dynamic>{};
|
||||
}
|
||||
}
|
||||
|
||||
Future<String?> pairingUri() async {
|
||||
try {
|
||||
final value = await _method.invokeMethod<String>('pairingUri');
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import 'dart:io';
|
||||
|
||||
class DiagnosticLog {
|
||||
DiagnosticLog([this.fileName = 'ttstd_connect.log']);
|
||||
|
||||
final String fileName;
|
||||
File? _file;
|
||||
|
||||
String get path => _file?.path ?? '';
|
||||
|
||||
void start() {
|
||||
final directories = <Directory>[
|
||||
File(Platform.resolvedExecutable).parent,
|
||||
Directory.current,
|
||||
Directory.systemTemp,
|
||||
];
|
||||
for (final directory in directories) {
|
||||
try {
|
||||
final candidate = File(
|
||||
'${directory.path}${Platform.pathSeparator}$fileName',
|
||||
);
|
||||
candidate.writeAsStringSync(
|
||||
'=== TTSTD Connect diagnostic log ===\n'
|
||||
'started: ${DateTime.now().toIso8601String()}\n',
|
||||
mode: FileMode.write,
|
||||
flush: true,
|
||||
);
|
||||
_file = candidate;
|
||||
return;
|
||||
} on Object catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
void write(String message) {
|
||||
final file = _file;
|
||||
if (file == null) return;
|
||||
try {
|
||||
if (file.lengthSync() > 2 * 1024 * 1024) {
|
||||
file.writeAsStringSync(
|
||||
'=== log rotated: ${DateTime.now().toIso8601String()} ===\n',
|
||||
mode: FileMode.write,
|
||||
flush: true,
|
||||
);
|
||||
}
|
||||
file.writeAsStringSync(
|
||||
'${DateTime.now().toIso8601String()} $message\n',
|
||||
mode: FileMode.append,
|
||||
flush: true,
|
||||
);
|
||||
} on Object catch (_) {}
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
write('=== stopped ===');
|
||||
_file = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'models.dart';
|
||||
|
||||
class DiscoveryClient {
|
||||
static Future<List<DeviceInfo>> listDevices(
|
||||
String signalingUrl, {
|
||||
Duration timeout = const Duration(seconds: 2),
|
||||
}) async {
|
||||
final trimmed = signalingUrl.trim();
|
||||
if (trimmed.isEmpty) return const <DeviceInfo>[];
|
||||
final client = HttpClient()..connectionTimeout = timeout;
|
||||
try {
|
||||
final base = Uri.parse(trimmed);
|
||||
final path = base.path.endsWith('/')
|
||||
? '${base.path}list'
|
||||
: '${base.path}/list';
|
||||
final request = await client.getUrl(base.replace(path: path)).timeout(timeout);
|
||||
final response = await request.close().timeout(timeout);
|
||||
final body = await utf8.decoder.bind(response).join().timeout(timeout);
|
||||
if (response.statusCode != HttpStatus.ok) return const <DeviceInfo>[];
|
||||
final value = jsonDecode(body);
|
||||
if (value is! Map) return const <DeviceInfo>[];
|
||||
return DeviceInfo.listFromJson(value['devices']);
|
||||
} on Object {
|
||||
return const <DeviceInfo>[];
|
||||
} finally {
|
||||
client.close(force: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,7 +168,7 @@ class NativeCore {
|
||||
try {
|
||||
final written = _mediaDecode(packetPtr, packet.length, keyPtr, out, 256);
|
||||
_check(written, 'ttstd_media_decode');
|
||||
return jsonDecode(_copy(out, written).toString()) as Map<String, dynamic>;
|
||||
return jsonDecode(utf8.decode(_copy(out, written))) as Map<String, dynamic>;
|
||||
} finally {
|
||||
calloc.free(out);
|
||||
}
|
||||
@@ -199,11 +199,11 @@ class NativeCore {
|
||||
void stopDemoServer() => _demoStop();
|
||||
|
||||
Map<String, dynamic> demoStatus() {
|
||||
final out = calloc<Uint8>(8192);
|
||||
final out = calloc<Uint8>(65536);
|
||||
try {
|
||||
final written = _demoStatus(out, 8192);
|
||||
final written = _demoStatus(out, 65536);
|
||||
_check(written, 'ttstd_demo_status');
|
||||
return jsonDecode(_copy(out, written).toString()) as Map<String, dynamic>;
|
||||
return jsonDecode(utf8.decode(_copy(out, written))) as Map<String, dynamic>;
|
||||
} finally {
|
||||
calloc.free(out);
|
||||
}
|
||||
@@ -321,7 +321,7 @@ class SecureChannel {
|
||||
try {
|
||||
final written = _core._controlDecode(_handle, framePtr, frame.length, out, 256);
|
||||
if (written < 0) throw NativeCoreException('ttstd_control_decode', written);
|
||||
return jsonDecode(NativeCore._copy(out, written).toString()) as Map<String, dynamic>;
|
||||
return jsonDecode(utf8.decode(NativeCore._copy(out, written))) as Map<String, dynamic>;
|
||||
} finally {
|
||||
calloc.free(out);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
class ServiceCheckResult {
|
||||
const ServiceCheckResult({
|
||||
required this.nativeCoreLoaded,
|
||||
required this.localSignalingRunning,
|
||||
required this.signalingReachable,
|
||||
required this.listenerRunning,
|
||||
required this.listenerReachable,
|
||||
required this.signalingUrl,
|
||||
required this.listenerHost,
|
||||
required this.listenerPort,
|
||||
});
|
||||
|
||||
final bool nativeCoreLoaded;
|
||||
final bool localSignalingRunning;
|
||||
final bool signalingReachable;
|
||||
final bool listenerRunning;
|
||||
final bool listenerReachable;
|
||||
final String signalingUrl;
|
||||
final String listenerHost;
|
||||
final int listenerPort;
|
||||
}
|
||||
|
||||
class ServiceChecker {
|
||||
static Future<bool> checkSignaling(
|
||||
String url, {
|
||||
Duration timeout = const Duration(seconds: 2),
|
||||
}) async {
|
||||
final trimmed = url.trim();
|
||||
if (trimmed.isEmpty) return false;
|
||||
final client = HttpClient()..connectionTimeout = timeout;
|
||||
try {
|
||||
final base = Uri.parse(trimmed);
|
||||
final path = base.path.endsWith('/')
|
||||
? '${base.path}healthz'
|
||||
: '${base.path}/healthz';
|
||||
final request = await client.getUrl(base.replace(path: path)).timeout(timeout);
|
||||
final response = await request.close().timeout(timeout);
|
||||
await response.drain<void>().timeout(timeout);
|
||||
return response.statusCode == HttpStatus.ok;
|
||||
} on Object {
|
||||
return false;
|
||||
} finally {
|
||||
client.close(force: true);
|
||||
}
|
||||
}
|
||||
|
||||
static Future<bool> checkTcp(
|
||||
String host,
|
||||
int port, {
|
||||
Duration timeout = const Duration(seconds: 2),
|
||||
}) async {
|
||||
try {
|
||||
final socket = await Socket.connect(host, port, timeout: timeout);
|
||||
socket.destroy();
|
||||
return true;
|
||||
} on Object {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user