fix:整理对讲状态、增加视频页面的旋转角度

This commit is contained in:
liyi 2025-01-02 10:28:56 +08:00
parent 4044b9b1e1
commit 87ed175fed
4 changed files with 49 additions and 66 deletions

View File

@ -12,11 +12,14 @@ import 'package:star_lock/talk/startChart/proto/gateway_reset.pb.dart';
import 'package:star_lock/talk/startChart/proto/generic.pb.dart'; import 'package:star_lock/talk/startChart/proto/generic.pb.dart';
import 'package:star_lock/talk/startChart/proto/talk_data.pb.dart'; import 'package:star_lock/talk/startChart/proto/talk_data.pb.dart';
import 'package:star_lock/talk/startChart/proto/talk_expect.pb.dart'; import 'package:star_lock/talk/startChart/proto/talk_expect.pb.dart';
import 'package:star_lock/talk/startChart/views/talkView/talk_view_state.dart';
import '../../start_chart_manage.dart'; import '../../start_chart_manage.dart';
class UdpTalkExpectHandler extends ScpMessageBaseHandle class UdpTalkExpectHandler extends ScpMessageBaseHandle
implements ScpMessageHandler { implements ScpMessageHandler {
final TalkViewState talkViewState = TalkViewState();
@override @override
void handleReq(ScpMessage scpMessage) { void handleReq(ScpMessage scpMessage) {
// //
@ -33,9 +36,12 @@ class UdpTalkExpectHandler extends ScpMessageBaseHandle
@override @override
void handleResp(ScpMessage scpMessage) { void handleResp(ScpMessage scpMessage) {
// //
final GenericResp genericResp = scpMessage.Payload; final TalkExpectResp talkExpectResp = scpMessage.Payload;
if (checkGenericRespSuccess(genericResp)) { if (talkExpectResp != null) {
print('收到预期音视频数据回复'); print('收到预期音视频数据回复');
//
startChartManage.stopTalkExpectMessageTimer();
talkViewState.rotateAngle.value = talkExpectResp.rotate ?? 0;
} }
} }
@ -56,12 +62,12 @@ class UdpTalkExpectHandler extends ScpMessageBaseHandle
int? spIndex, int? spIndex,
int? messageId}) { int? messageId}) {
if (messageType == MessageTypeConstant.Resp) { if (messageType == MessageTypeConstant.Resp) {
// final TalkExpectResp talkExpectResp = TalkExpectResp(); final TalkExpectResp talkExpectResp = TalkExpectResp();
// talkExpectResp.mergeFromBuffer(byte); talkExpectResp.mergeFromBuffer(byte);
// return talkExpectResp; return talkExpectResp;
final GenericResp genericResp = GenericResp(); // final GenericResp genericResp = GenericResp();
genericResp.mergeFromBuffer(byte); // genericResp.mergeFromBuffer(byte);
return genericResp; // return genericResp;
} else if (messageType == MessageTypeConstant.Req) { } else if (messageType == MessageTypeConstant.Req) {
final TalkExpectReq talkExpect = TalkExpectReq(); final TalkExpectReq talkExpect = TalkExpectReq();
talkExpect.mergeFromBuffer(byte); talkExpect.mergeFromBuffer(byte);

View File

@ -32,11 +32,11 @@ class TalkViewLogic extends BaseGetXController {
Timer? _syncTimer; // Timer? _syncTimer; //
int _startTime = 0; // int _startTime = 0; //
final int bufferSize = 8; // final int bufferSize = 20; //
final List<int> frameTimestamps = []; // FPS final List<int> frameTimestamps = []; // FPS
int frameIntervalMs = 45; // 4522FPS int frameIntervalMs = 45; // 4522FPS
int minFrameIntervalMs = 30; // 33 FPS int minFrameIntervalMs = 30; // 33 FPS
int maxFrameIntervalMs = 500; // 2 FPS int maxFrameIntervalMs = 500; // 1 FPS
// int maxFrameIntervalMs = 100; // 10 FPS // int maxFrameIntervalMs = 100; // 10 FPS
/// ///
@ -54,7 +54,7 @@ class TalkViewLogic extends BaseGetXController {
/// ///
void udpHangUpAction() async { void udpHangUpAction() async {
if (state.talkStatus.value == TalkStatus.duringCall) { if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
// //
StartChartManage().sendTalkHangupMessage(); StartChartManage().sendTalkHangupMessage();
} else { } else {
@ -66,31 +66,13 @@ class TalkViewLogic extends BaseGetXController {
// //
void initiateAnswerCommand() { void initiateAnswerCommand() {
StartChartManage().sendTalkAcceptMessage(); StartChartManage().startTalkAcceptTimer();
}
void _updateFps(List<int> frameTimestamps) {
final int now = DateTime.now().millisecondsSinceEpoch;
// 1
frameTimestamps.removeWhere((timestamp) => now - timestamp > 1000);
// FPS
final double fps = frameTimestamps.length.toDouble();
// FPS
state.fps.value = fps;
} }
// //
void _startListenTalkData() { void _startListenTalkData() {
state.talkDataRepository.talkDataStream.listen((TalkData talkData) { state.talkDataRepository.talkDataStream.listen((TalkData talkData) {
final contentType = talkData.contentType; final contentType = talkData.contentType;
final currentTimestamp = DateTime.now().millisecondsSinceEpoch;
///
if (state.startChartTalkStatus.status != TalkStatus.duringCall) {
return;
}
// //
switch (contentType) { switch (contentType) {
@ -105,10 +87,10 @@ class TalkViewLogic extends BaseGetXController {
if (state.videoBuffer.length < bufferSize) { if (state.videoBuffer.length < bufferSize) {
state.videoBuffer.add(talkData); state.videoBuffer.add(talkData);
} }
print('talkData durationMs-->:${talkData.durationMs}'); // print('talkData durationMs-->:${talkData.durationMs}');
/// ///
updateNetworkStatus(currentTimestamp); // updateNetworkStatus(currentTimestamp);
break; break;
} }
}); });
@ -187,10 +169,6 @@ class TalkViewLogic extends BaseGetXController {
if (state.videoBuffer.length > 1) { if (state.videoBuffer.length > 1) {
state.videoBuffer.removeAt(0); state.videoBuffer.removeAt(0);
} else { } else {
// //
// frameTimestamps.add(DateTime.now().millisecondsSinceEpoch);
// // FPS
// _updateFps(frameTimestamps);
_playVideoData(state.videoBuffer.removeAt(0)); _playVideoData(state.videoBuffer.removeAt(0));
} }
} }
@ -236,10 +214,6 @@ class TalkViewLogic extends BaseGetXController {
if (state.videoBuffer.length > 1) { if (state.videoBuffer.length > 1) {
state.videoBuffer.removeAt(0); state.videoBuffer.removeAt(0);
} else { } else {
// //
// frameTimestamps.add(DateTime.now().millisecondsSinceEpoch);
// // FPS
// _updateFps(frameTimestamps);
_playVideoData(state.videoBuffer.removeAt(0)); _playVideoData(state.videoBuffer.removeAt(0));
} }
} }
@ -371,7 +345,8 @@ class TalkViewLogic extends BaseGetXController {
} }
/// ///
StartChartManage().changeTalkExpectDataType(talkExpect: talkExpectReq); StartChartManage().changeTalkExpectDataTypeAndReStartTalkExpectMessageTimer(
talkExpect: talkExpectReq);
state.isOpenVoice.value = !state.isOpenVoice.value; state.isOpenVoice.value = !state.isOpenVoice.value;
} }

View File

@ -81,26 +81,29 @@ class _TalkViewPageState extends State<TalkViewPage>
canPop: false, canPop: false,
child: RepaintBoundary( child: RepaintBoundary(
key: state.globalKey, key: state.globalKey,
child: Image.memory( child: RotatedBox(
state.listData.value, quarterTurns: 1, // 90 1
gaplessPlayback: true, child: Image.memory(
width: 1.sw, state.listData.value,
height: 1.sh, gaplessPlayback: true,
fit: BoxFit.cover, width: 1.sw,
filterQuality: FilterQuality.high, height: 1.sh,
errorBuilder: ( fit: BoxFit.cover,
BuildContext context, filterQuality: FilterQuality.high,
Object error, errorBuilder: (
StackTrace? stackTrace, BuildContext context,
) { Object error,
return Container(color: Colors.transparent); StackTrace? stackTrace,
}, ) {
return Container(color: Colors.transparent);
},
),
), ),
), ),
), ),
), ),
), ),
Obx(() => state.talkStatus.value == TalkStatus.answeredSuccessfully Obx(() => state.listData.value.isEmpty
? Positioned( ? Positioned(
bottom: 300.h, bottom: 300.h,
child: Text( child: Text(
@ -141,7 +144,7 @@ class _TalkViewPageState extends State<TalkViewPage>
// ), // ),
// ), // ),
// ), // ),
Obx(() => state.talkStatus.value == TalkStatus.answeredSuccessfully Obx(() => state.listData.value.isEmpty
? buildRotationTransition() ? buildRotationTransition()
: Container()) : Container())
], ],
@ -154,7 +157,7 @@ class _TalkViewPageState extends State<TalkViewPage>
// //
GestureDetector( GestureDetector(
onTap: () { onTap: () {
if (state.talkStatus.value == TalkStatus.duringCall) { if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
// //
logic.updateTalkExpect(); logic.updateTalkExpect();
} }
@ -177,7 +180,7 @@ class _TalkViewPageState extends State<TalkViewPage>
// //
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
if (state.talkStatus.value == TalkStatus.duringCall) { if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
await logic.captureAndSavePng(); await logic.captureAndSavePng();
} }
}, },
@ -196,7 +199,7 @@ class _TalkViewPageState extends State<TalkViewPage>
// //
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
if (state.talkStatus.value == TalkStatus.duringCall) { if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
if (state.isRecordingScreen.value) { if (state.isRecordingScreen.value) {
await logic.stopRecording(); await logic.stopRecording();
print('停止录屏'); print('停止录屏');
@ -245,8 +248,7 @@ class _TalkViewPageState extends State<TalkViewPage>
getAnswerBtnName(), getAnswerBtnName(),
Colors.white, Colors.white,
longPress: () async { longPress: () async {
if (state.talkStatus.value == TalkStatus.answeredSuccessfully || if (state.talkStatus.value == TalkStatus.answeredSuccessfully) {
state.talkStatus.value == TalkStatus.duringCall) {
print('开始录音'); print('开始录音');
logic.startProcessingAudio(); logic.startProcessingAudio();
} }
@ -283,7 +285,6 @@ class _TalkViewPageState extends State<TalkViewPage>
case TalkStatus.waitingAnswer: case TalkStatus.waitingAnswer:
return 'images/main/icon_lockDetail_monitoringAnswerCalls.png'; return 'images/main/icon_lockDetail_monitoringAnswerCalls.png';
case TalkStatus.answeredSuccessfully: case TalkStatus.answeredSuccessfully:
case TalkStatus.duringCall:
return 'images/main/icon_lockDetail_monitoringUnTalkback.png'; return 'images/main/icon_lockDetail_monitoringUnTalkback.png';
default: default:
return 'images/main/icon_lockDetail_monitoringAnswerCalls.png'; return 'images/main/icon_lockDetail_monitoringAnswerCalls.png';
@ -295,7 +296,6 @@ class _TalkViewPageState extends State<TalkViewPage>
case TalkStatus.waitingAnswer: case TalkStatus.waitingAnswer:
return '接听'.tr; return '接听'.tr;
case TalkStatus.answeredSuccessfully: case TalkStatus.answeredSuccessfully:
case TalkStatus.duringCall:
return '长按说话'.tr; return '长按说话'.tr;
default: default:
return '接听'.tr; return '接听'.tr;

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_voice_processor/flutter_voice_processor.dart'; import 'package:flutter_voice_processor/flutter_voice_processor.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get/get_rx/get_rx.dart'; import 'package:get/get_rx/get_rx.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:network_info_plus/network_info_plus.dart'; import 'package:network_info_plus/network_info_plus.dart';
import 'package:star_lock/talk/startChart/constant/talk_status.dart'; import 'package:star_lock/talk/startChart/constant/talk_status.dart';
import 'package:star_lock/talk/startChart/handle/other/talk_data_repository.dart'; import 'package:star_lock/talk/startChart/handle/other/talk_data_repository.dart';
@ -71,11 +72,12 @@ class TalkViewState {
RxBool isRecordingScreen = false.obs; // RxBool isRecordingScreen = false.obs; //
RxBool isRecordingAudio = false.obs; // RxBool isRecordingAudio = false.obs; //
Rx<DateTime> startRecordingAudioTime = DateTime.now().obs; // Rx<DateTime> startRecordingAudioTime = DateTime.now().obs; //
Rx<DateTime> endRecordingAudioTime= DateTime.now().obs; // Rx<DateTime> endRecordingAudioTime = DateTime.now().obs; //
RxInt recordingAudioTime= 0.obs; // RxInt recordingAudioTime = 0.obs; //
RxDouble fps = 0.0.obs; // FPS RxDouble fps = 0.0.obs; // FPS
late VoiceProcessor? voiceProcessor; // late VoiceProcessor? voiceProcessor; //
final int frameLength = 320; //320 final int frameLength = 320; //320
final int sampleRate = 8000; //8000 final int sampleRate = 8000; //8000
List<List<int>> recordingAudioAllFrames = <List<int>>[]; // List<List<int>> recordingAudioAllFrames = <List<int>>[]; //
RxInt rotateAngle = 0.obs; //
} }