modify
This commit is contained in:
parent
6542f27437
commit
9219168df5
@ -93,34 +93,32 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
|||||||
Future<void> _initVideoDecoder() async {
|
Future<void> _initVideoDecoder() async {
|
||||||
try {
|
try {
|
||||||
state.isLoading.value = true;
|
state.isLoading.value = true;
|
||||||
|
|
||||||
// ios第一次点击监控没画面
|
|
||||||
// 等待视频参数就绪,设置超时时间
|
|
||||||
int width = StartChartManage().videoWidth;
|
int width = StartChartManage().videoWidth;
|
||||||
int height = StartChartManage().videoHeight;
|
int height = StartChartManage().videoHeight;
|
||||||
|
|
||||||
// 如果视频参数未就绪,等待一段时间直到参数就绪或超时
|
if(Platform.isIOS){
|
||||||
if (width == 0 || height == 0) {
|
// ios第一次点击监控没画面
|
||||||
int attempts = 0;
|
|
||||||
const maxAttempts = 20; // 最多等待2秒 (20 * 100ms)
|
|
||||||
|
|
||||||
while ((width == 0 || height == 0) && attempts < maxAttempts) {
|
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
|
||||||
width = StartChartManage().videoWidth;
|
|
||||||
height = StartChartManage().videoHeight;
|
|
||||||
attempts++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果仍然没有获取到参数,使用默认值
|
|
||||||
if (width == 0 || height == 0) {
|
if (width == 0 || height == 0) {
|
||||||
width = 864;
|
int attempts = 0;
|
||||||
height = 480;
|
const maxAttempts = 20; // 最多等待2秒 (20 * 100ms)
|
||||||
AppLog.log('使用默认视频参数: ${width}x$height');
|
|
||||||
} else {
|
while ((width == 0 || height == 0) && attempts < maxAttempts) {
|
||||||
AppLog.log('获取到视频参数: ${width}x$height');
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
width = StartChartManage().videoWidth;
|
||||||
|
height = StartChartManage().videoHeight;
|
||||||
|
attempts++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果仍然没有获取到参数,使用默认值
|
||||||
|
if (width == 0 || height == 0) {
|
||||||
|
width = 864;
|
||||||
|
height = 480;
|
||||||
|
AppLog.log('使用默认视频参数: ${width}x$height');
|
||||||
|
} else {
|
||||||
|
AppLog.log('获取到视频参数: ${width}x$height');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 创建解码器配置
|
// 创建解码器配置
|
||||||
final config = VideoDecoderConfig(
|
final config = VideoDecoderConfig(
|
||||||
width: width,
|
width: width,
|
||||||
@ -128,7 +126,6 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
|||||||
height: height,
|
height: height,
|
||||||
codecType: 'h264',
|
codecType: 'h264',
|
||||||
);
|
);
|
||||||
AppLog.log('解码器配置的宽高为:${config.width}x${config.height}');
|
|
||||||
// 初始化解码器并获取textureId
|
// 初始化解码器并获取textureId
|
||||||
final textureId = await VideoDecodePlugin.initDecoder(config);
|
final textureId = await VideoDecodePlugin.initDecoder(config);
|
||||||
if (textureId != null) {
|
if (textureId != null) {
|
||||||
@ -272,7 +269,8 @@ class TalkViewNativeDecodeLogic extends BaseGetXController {
|
|||||||
// 取消已有定时器
|
// 取消已有定时器
|
||||||
state.frameProcessTimer?.cancel();
|
state.frameProcessTimer?.cancel();
|
||||||
|
|
||||||
// 使用配置的间隔时间
|
// 计算定时器间隔,确保以目标帧率处理帧
|
||||||
|
// final int intervalMs = (1000 / state.targetFps).round();
|
||||||
final int intervalMs = state.frameProcessIntervalMs;
|
final int intervalMs = state.frameProcessIntervalMs;
|
||||||
|
|
||||||
// 创建新定时器
|
// 创建新定时器
|
||||||
|
|||||||
@ -41,7 +41,7 @@ class TalkViewLogic extends BaseGetXController {
|
|||||||
|
|
||||||
final LockDetailState lockDetailState = Get.put(LockDetailLogic()).state;
|
final LockDetailState lockDetailState = Get.put(LockDetailLogic()).state;
|
||||||
|
|
||||||
int bufferSize = 3; // 增大缓冲区,满时才渲染
|
int bufferSize = 8; // 增大缓冲区,满时才渲染
|
||||||
|
|
||||||
int audioBufferSize = 2; // 音频默认缓冲2帧
|
int audioBufferSize = 2; // 音频默认缓冲2帧
|
||||||
bool _isFirstAudioFrame = true; // 是否是第一帧
|
bool _isFirstAudioFrame = true; // 是否是第一帧
|
||||||
|
|||||||
@ -504,25 +504,6 @@ class H264WebViewLogic extends BaseGetXController {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 添加音频降噪处理方法
|
|
||||||
List<int> _applyDenoise(List<int> pcmData) {
|
|
||||||
// 使用简单的噪声门限处理
|
|
||||||
const int noiseThreshold = 150; // 设定噪音阈值
|
|
||||||
|
|
||||||
List<int> result = List<int>.filled(pcmData.length, 0);
|
|
||||||
|
|
||||||
for (int i = 0; i < pcmData.length; i++) {
|
|
||||||
// 如果样本值小于噪音阈值,则将其设为0
|
|
||||||
if (pcmData[i].abs() < noiseThreshold) {
|
|
||||||
result[i] = 0;
|
|
||||||
} else {
|
|
||||||
result[i] = pcmData[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 挂断
|
/// 挂断
|
||||||
void udpHangUpAction() async {
|
void udpHangUpAction() async {
|
||||||
if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
|
if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user