fix:增加视频分辨率判断
This commit is contained in:
parent
f887bd37c4
commit
06fc544f1a
@ -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();
|
||||
|
||||
@ -114,6 +114,8 @@ class StartChartManage {
|
||||
final int _maxPayloadSize = 8 * 1024; // 分包大小
|
||||
|
||||
int rotateAngle = 0; // 视频旋转角度
|
||||
int videoWidth = 0; // 视频宽度
|
||||
int videoHeight = 0; // 视频高度
|
||||
|
||||
// 默认通话的期望数据格式
|
||||
TalkExpectReq _defaultTalkExpect = TalkConstant.H264Expect;
|
||||
|
||||
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user