2025-04-30 16:12:22 +08:00
|
|
|
import 'dart:typed_data';
|
|
|
|
|
|
|
|
|
|
/// SPS/PPS/I帧依赖关系管理器
|
|
|
|
|
class FrameDependencyManager {
|
|
|
|
|
Uint8List? _sps;
|
|
|
|
|
Uint8List? _pps;
|
2025-04-30 16:56:30 +08:00
|
|
|
final int windowSize = 30;
|
|
|
|
|
final List<int> _iFrameSeqWindow = [];
|
2025-04-30 16:12:22 +08:00
|
|
|
|
|
|
|
|
/// 更新SPS缓存
|
2025-05-07 15:07:36 +08:00
|
|
|
void updateSps(Uint8List? sps) {
|
2025-04-30 16:12:22 +08:00
|
|
|
_sps = sps;
|
|
|
|
|
}
|
|
|
|
|
/// 更新PPS缓存
|
2025-05-07 15:07:36 +08:00
|
|
|
void updatePps(Uint8List? pps) {
|
2025-04-30 16:12:22 +08:00
|
|
|
_pps = pps;
|
|
|
|
|
}
|
|
|
|
|
Uint8List? get sps => _sps;
|
|
|
|
|
Uint8List? get pps => _pps;
|
|
|
|
|
|
|
|
|
|
/// 判断是否有可用I帧
|
2025-04-30 16:56:30 +08:00
|
|
|
bool get hasIFrame => _iFrameSeqWindow.isNotEmpty;
|
|
|
|
|
int? get lastIFrameSeq => _iFrameSeqWindow.isNotEmpty ? _iFrameSeqWindow.last : null;
|
2025-04-30 16:12:22 +08:00
|
|
|
void updateIFrameSeq(int seq) {
|
2025-04-30 16:56:30 +08:00
|
|
|
_iFrameSeqWindow.add(seq);
|
|
|
|
|
if (_iFrameSeqWindow.length > windowSize) {
|
|
|
|
|
_iFrameSeqWindow.removeAt(0);
|
|
|
|
|
}
|
2025-04-30 16:12:22 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-30 16:56:30 +08:00
|
|
|
/// 判断指定I帧序号是否在滑动窗口内
|
2025-04-30 16:12:22 +08:00
|
|
|
bool isIFrameDecoded(int? seq) {
|
2025-04-30 16:56:30 +08:00
|
|
|
return seq != null && _iFrameSeqWindow.contains(seq);
|
2025-04-30 16:12:22 +08:00
|
|
|
}
|
|
|
|
|
}
|