feat(connection): 增加远程视频录制、分辨率/帧率切换及高刷适配
- 新增 VideoRecorder 基于 flutter_webrtc MediaRecorder 录制远程视频为 MP4 - 新增 ControlMessageDecoder 解析被控端上报的 REPORT_* protobuf 消息 - 连接控制器支持分辨率/帧率切换、录制状态管理与远程上报处理 - 远程控制页新增更多菜单(静音/分辨率/帧率/录制),并统一退出时断开连接 - WebRTC 编排器在 DataChannel 打开及媒体就绪后主动请求默认分辨率,解决黑屏问题 - 新增 DisplayModeUtil 在 Android 上启用最高刷新率 - 登出时失效设备相关 Provider,避免切换账号后读到旧缓存
This commit is contained in:
1 parent
41a514e9cc
commit
bfb106f1fb
13 files changed
+1267
-514
No files matched your search
@@ -137,3 +137,102 @@ class ControlMessageEncoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 被控端上报的远程视频信息(REPORT_RESOLUTION / REPORT_STREAM_MODE)。
|
||||
class ReportInfo {
|
||||
final int action;
|
||||
final int width;
|
||||
final int height;
|
||||
final int fps;
|
||||
final int streamMode;
|
||||
final List<int> supportedFps;
|
||||
|
||||
const ReportInfo({
|
||||
this.action = 0,
|
||||
this.width = 0,
|
||||
this.height = 0,
|
||||
this.fps = 0,
|
||||
this.streamMode = 0,
|
||||
this.supportedFps = const [],
|
||||
});
|
||||
}
|
||||
|
||||
/// protobuf wire format 解码器。
|
||||
///
|
||||
/// 与控制端 `com.ttstd.control.ControlMessage`(protobuf 3)字段号完全对齐,
|
||||
/// 仅解析被控端会回传的字段(action/width/height/fps/stream_mode/supported_fps)。
|
||||
class ControlMessageDecoder {
|
||||
/// 解析被控端上报的 REPORT_* 消息;无法解析返回 null。
|
||||
static ReportInfo? decode(Uint8List data) {
|
||||
int action = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int fps = 0;
|
||||
int streamMode = 0;
|
||||
final supportedFps = <int>[];
|
||||
|
||||
final reader = ByteData.sublistView(data);
|
||||
var pos = 0;
|
||||
try {
|
||||
while (pos < data.length) {
|
||||
final tag = _readVarint(reader, pos);
|
||||
pos = tag.$2;
|
||||
final field = tag.$1 >> 3;
|
||||
final wireType = tag.$1 & 0x07;
|
||||
switch (wireType) {
|
||||
case 0: // varint
|
||||
final v = _readVarint(reader, pos);
|
||||
pos = v.$2;
|
||||
final val = v.$1;
|
||||
switch (field) {
|
||||
case 1:
|
||||
action = val;
|
||||
break;
|
||||
case 12:
|
||||
width = val;
|
||||
break;
|
||||
case 13:
|
||||
height = val;
|
||||
break;
|
||||
case 14:
|
||||
fps = val;
|
||||
break;
|
||||
case 15:
|
||||
streamMode = val;
|
||||
break;
|
||||
case 16:
|
||||
supportedFps.add(val);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// 未知 wire type:跳过(解析到 known fields 前不应出现)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (_) {
|
||||
return null;
|
||||
}
|
||||
return ReportInfo(
|
||||
action: action,
|
||||
width: width,
|
||||
height: height,
|
||||
fps: fps,
|
||||
streamMode: streamMode,
|
||||
supportedFps: supportedFps,
|
||||
);
|
||||
}
|
||||
|
||||
/// 读取一个 varint,返回 (值, 新的位置)。越界抛异常。
|
||||
static (int, int) _readVarint(ByteData data, int pos) {
|
||||
var result = 0;
|
||||
var shift = 0;
|
||||
while (true) {
|
||||
final byte = data.getUint8(pos++);
|
||||
result |= (byte & 0x7F) << shift;
|
||||
if ((byte & 0x80) == 0) break;
|
||||
shift += 7;
|
||||
}
|
||||
return (result, pos);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user