This commit is contained in:
sky_min 2025-12-13 10:34:38 +08:00
parent ebe5b8a756
commit e9f59c223f
2 changed files with 77 additions and 32 deletions

View File

@ -726,9 +726,13 @@ class LockDetailLogic extends BaseGetXController {
// WiFi锁
final network = currentKeyInfo.network;
if (network != null && (network.peerId != null && network.peerId!.isNotEmpty)){
showToast('wifi锁进行蓝牙透传开锁'.tr);
//
await _sendUnlockViaBluetooth();
} else {
}
//
if (state.keyInfos.value.hasGateway == 1) {
showToast('网关锁进行远程开锁api开锁'.tr);
// API
final LoginEntity entity = await ApiRepository.to.remoteOpenLock(lockId: lockId.toString(), timeOut: 60);
if (entity.errorCode!.codeIsSuccessful) {

View File

@ -398,8 +398,6 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
} else if (bufferLength > 40) {
//
_dropOldPFrame();
} else if (bufferLength > 30) {
_dropSomeBFrame();
}
}
void _dropOldFramesAggressively() {
@ -423,50 +421,63 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
_invalidateFrameIndex();
}
}
void _dropSomeBFrame() {
// B帧B帧
final bFrameIndex = state.h264FrameBuffer.indexWhere((frame) =>
frame['frameType'] == TalkDataH264Frame_FrameTypeE.I &&
frame['frameSeq'] < (_lastFrameSeq ?? 0) - 30);
if (bFrameIndex != -1) {
state.h264FrameBuffer.removeAt(bFrameIndex);
/// I帧和最近的P帧
void _keepOnlyKeyFrames() {
final List<Map<String, dynamic>> keyFrames = [];
int lastPFrameIndex = -1;
//
for (int i = state.h264FrameBuffer.length - 1; i >= 0; i--) {
final frame = state.h264FrameBuffer[i];
final frameType = frame['frameType'];
if (frameType == TalkDataH264Frame_FrameTypeE.I) {
keyFrames.add(frame);
break; // I帧后停止
} else if (frameType == TalkDataH264Frame_FrameTypeE.P && lastPFrameIndex == -1) {
keyFrames.add(frame);
lastPFrameIndex = i;
}
}
if (keyFrames.isNotEmpty) {
// 使
state.h264FrameBuffer.clear();
state.h264FrameBuffer.addAll(keyFrames.reversed);
_invalidateFrameIndex();
}
}
///
/// -
void _startFrameProcessTimer() {
//
_stopFrameProcessTimer();
//
// iOS平台使用更精确的定时器间隔
final int intervalMs = Platform.isIOS
//
int baseIntervalMs = Platform.isIOS
? max(16, min(33, (1000 / state.targetFps).round())) // iOS使用更严格的范围
: max(16, min(40, (1000 / state.targetFps).round()));
//
state.frameProcessTimer = Timer.periodic(Duration(milliseconds: intervalMs), (timer) {
state.frameProcessTimer = Timer.periodic(Duration(milliseconds: baseIntervalMs), (timer) {
_processNextFrameFromBuffer();
});
AppLog.log('启动帧处理定时器,目标帧率: ${state.targetFps}fps间隔: ${intervalMs}ms');
AppLog.log('启动帧处理定时器,目标帧率: ${state.targetFps}fps初始间隔: ${baseIntervalMs}ms');
}
///
void _clearFrameBufferQuickly() {
//
if (state.h264FrameBuffer.length > 3) {
// 3
state.h264FrameBuffer.removeRange(0, state.h264FrameBuffer.length - 3);
}
//
state.h264FrameBuffer.clear();
//
_lastFrameSeq = null;
lastDecodedIFrameSeq = null;
_decodedIFrames.clear();
state.isProcessingFrame = false;
_frameIndexDirty = true;
_frameIndexCache.clear();
}
///
@ -575,8 +586,8 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
return state.h264FrameBuffer.isNotEmpty ? 0 : -1;
}
///
void _processNextFrameFromBuffer() async {
/// -
Future<void> _processNextFrameFromBuffer() async {
final stopwatch = Stopwatch()..start();
_monitorFrameProcessingPerformance();
final startTime = DateTime.now().microsecondsSinceEpoch;
@ -600,12 +611,23 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
try {
state.isProcessingFrame = true;
//
_implementSmartFrameDropping();
//
final bufferLength = state.h264FrameBuffer.length;
if (bufferLength > 50) {
// 20
final newBuffer = state.h264FrameBuffer.sublist(max(0, bufferLength - 20));
state.h264FrameBuffer.clear();
state.h264FrameBuffer.addAll(newBuffer);
_invalidateFrameIndex();
} else if (bufferLength > 30 && Platform.isAndroid) {
// Android平台缓冲区较大时I帧和关键P帧
_keepOnlyKeyFrames();
} else {
//
_implementSmartFrameDropping();
}
//
final bufferLength = state.h264FrameBuffer.length;
//
// iOS平台优化
if (Platform.isIOS) {
@ -1306,7 +1328,7 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
AppLog.log(error.message!);
}
//
//
void onQualityChanged(String quality) async {
state.currentQuality.value = quality;
TalkExpectReq talkExpectReq = StartChartManage().getDefaultTalkExpect();
@ -1335,8 +1357,27 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
///
StartChartManage().changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(talkExpect: talkExpectReq);
// loadingframeSeq回绕检测
// frameSeq回绕检测标志
//
// 1.
_stopFrameProcessTimer();
// 2.
_clearFrameBufferQuickly();
// 3.
StartChartManage().videoWidth = width;
StartChartManage().videoHeight = height;
// 4.
await _resetDecoderForNewStream(width, height);
// 5.
_startFrameProcessTimer();
// 6.
Future.microtask(() => state.isLoading.value = true);
// 7.
_pendingStreamReset = false;
_pendingResetWidth = width;
_pendingResetHeight = height;