fix:增加视频分辨率判断

This commit is contained in:
liyi 2025-05-13 10:05:05 +08:00
parent f887bd37c4
commit 06fc544f1a
3 changed files with 120 additions and 51 deletions

View File

@ -43,7 +43,9 @@ class UdpTalkExpectHandler extends ScpMessageBaseHandle
startChartManage.stopCallRequestMessageTimer();
// talkViewState.rotateAngle.value = talkExpectResp.rotate ?? 0;
startChartManage.rotateAngle = talkExpectResp.rotate;
AppLog.log('视频画面需要旋转:${talkExpectResp.rotate}');
startChartManage.videoWidth = talkExpectResp.width;
startChartManage.videoHeight = talkExpectResp.height;
AppLog.log('视频画面需要旋转:${talkExpectResp.rotate},画面宽高:${talkExpectResp.width}-${talkExpectResp.height}');
//
// x秒内没有收到通话保持则执行的操作;
talkePingOverTimeTimerManager.start();

View File

@ -114,6 +114,8 @@ class StartChartManage {
final int _maxPayloadSize = 8 * 1024; //
int rotateAngle = 0; //
int videoWidth = 0; //
int videoHeight = 0; //
//
TalkExpectReq _defaultTalkExpect = TalkConstant.H264Expect;

View File

@ -98,56 +98,55 @@ class _TalkViewPageState extends State<TalkViewPage>
child: Stack(
alignment: Alignment.center,
children: <Widget>[
Obx(
() {
final double screenWidth = MediaQuery.of(context).size.width;
final double screenHeight = MediaQuery.of(context).size.height;
final double logicalWidth = MediaQuery.of(context).size.width;
final double logicalHeight = MediaQuery.of(context).size.height;
final double devicePixelRatio =
MediaQuery.of(context).devicePixelRatio;
//
final double physicalWidth = logicalWidth * devicePixelRatio;
final double physicalHeight = logicalHeight * devicePixelRatio;
//
const int rotatedImageWidth = 480; //
const int rotatedImageHeight = 864; //
//
final double scaleWidth = physicalWidth / rotatedImageWidth;
final double scaleHeight = physicalHeight / rotatedImageHeight;
max(scaleWidth, scaleHeight); //
return state.listData.value.isEmpty
? Image.asset(
'images/main/monitorBg.png',
width: screenWidth,
height: screenHeight,
fit: BoxFit.cover,
)
: PopScope(
canPop: false,
child: RepaintBoundary(
key: state.globalKey,
child: SizedBox.expand(
child: RotatedBox(
quarterTurns: startChartManage.rotateAngle ~/ 90,
child: RawImage(
image: state.currentImage.value,
width: ScreenUtil().scaleWidth,
height: ScreenUtil().scaleHeight,
fit: BoxFit.cover,
filterQuality: FilterQuality.high,
),
),
),
),
);
},
),
//
Obx(() {
if (state.listData.value.isEmpty) {
return SizedBox.expand(
child: Image.asset(
'images/main/monitorBg.png',
fit: BoxFit.cover,
),
);
}
final int videoW = startChartManage.videoWidth;
final int videoH = startChartManage.videoHeight;
if (videoW == 320 && videoH == 240) {
return SizedBox.expand(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFF232526),
Color(0xFF414345),
],
),
),
),
);
}
return const SizedBox.shrink();
}),
//
Obx(() {
if (state.listData.value.isEmpty) {
return const SizedBox.shrink();
}
final int videoW = startChartManage.videoWidth;
final int videoH = startChartManage.videoHeight;
if (videoW == 320 && videoH == 240) {
return Positioned(
top: 150.h,
left: 0,
right: 0,
child: _buildVideoWidget(),
);
} else {
//
return _buildVideoWidget();
}
}),
Obx(() => state.listData.value.isEmpty
? Positioned(
bottom: 310.h,
@ -183,6 +182,8 @@ class _TalkViewPageState extends State<TalkViewPage>
),
)
: Container()),
///
Positioned(
bottom: 10.w,
child: Container(
@ -614,4 +615,68 @@ class _TalkViewPageState extends State<TalkViewPage>
// UdpTalkDataHandler().resetDataRates();
super.dispose();
}
Widget _buildVideoWidget() {
//
double barWidth = 1.sw - 30.w * 2;
int videoW = startChartManage.videoWidth;
int videoH = startChartManage.videoHeight;
int quarterTurns = startChartManage.rotateAngle ~/ 90;
bool isRotated = quarterTurns % 2 == 1;
//
double videoAspect = isRotated ? videoW / videoH : videoH / videoW;
double containerHeight =
barWidth * (isRotated ? videoW / videoH : videoH / videoW);
if (videoW == 320 && videoH == 240) {
return Center(
child: ClipRRect(
borderRadius: BorderRadius.circular(20.h),
child: Container(
width: barWidth,
height: containerHeight,
decoration: const BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFF232526),
Color(0xFF414345),
],
),
),
child: RotatedBox(
quarterTurns: quarterTurns,
child: RawImage(
image: state.currentImage.value,
fit: BoxFit.contain,
filterQuality: FilterQuality.high,
width: barWidth,
height: containerHeight,
),
),
),
),
);
} else {
return PopScope(
canPop: false,
child: RepaintBoundary(
key: state.globalKey,
child: SizedBox.expand(
child: RotatedBox(
quarterTurns: startChartManage.rotateAngle ~/ 90,
child: RawImage(
image: state.currentImage.value,
width: ScreenUtil().scaleWidth,
height: ScreenUtil().scaleHeight,
fit: BoxFit.cover,
filterQuality: FilterQuality.high,
),
),
),
),
);
}
}
}