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(); startChartManage.stopCallRequestMessageTimer();
// talkViewState.rotateAngle.value = talkExpectResp.rotate ?? 0; // talkViewState.rotateAngle.value = talkExpectResp.rotate ?? 0;
startChartManage.rotateAngle = talkExpectResp.rotate; 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秒内没有收到通话保持则执行的操作; // x秒内没有收到通话保持则执行的操作;
talkePingOverTimeTimerManager.start(); talkePingOverTimeTimerManager.start();

View File

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

View File

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