对讲相关代码提交

This commit is contained in:
Daisy 2023-12-11 10:43:41 +08:00
parent 3103071653
commit 7dc163318f
13 changed files with 14477 additions and 102 deletions

View File

@ -1,10 +1,12 @@
import 'package:aliyun_push/aliyun_push.dart';
import 'package:audioplayers/audioplayers.dart';
// import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:star_lock/talk/call/callTalk.dart';
import 'package:star_lock/tools/app_manager.dart';
import 'package:star_lock/tools/bindings/app_binding.dart';
import 'package:star_lock/tools/device_info_service.dart';
@ -124,6 +126,12 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
WidgetsBinding.instance?.addObserver(this);
initAliyunPush();
// playLocalAudio();
Uint8List uint8List = Uint8List.fromList([]);
CallTalk talkClass = CallTalk();
talkClass.getAVData(uint8List, 90);
}
//
@ -185,16 +193,8 @@ Future _setCommonServices() async {
}
//
// void playAudio() async {
// const String audioPath = "assets/ring1.mp3";
// AudioPlayer audioPlayer = AudioPlayer();
// // int result = await audioPlayer.play(audioPath, isLocal: true);
// if (result == 1) {
// //
// print("Audio playback successful!");
// } else {
// //
// print("Error playing audio");
// }
// }
void playLocalAudio() async {
final audioPlayer = AudioPlayer();
audioPlayer.setReleaseMode(ReleaseMode.loop);
await audioPlayer.play(AssetSource('ring1.mp3'));
}

View File

@ -1,4 +1,3 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
@ -7,7 +6,6 @@ import '../../../../appRouters.dart';
import '../../../../app_settings/app_colors.dart';
import 'lockMonitoring_logic.dart';
class LockMonitoringPage extends StatefulWidget {
const LockMonitoringPage({Key? key}) : super(key: key);
@ -21,7 +19,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
@override
Widget build(BuildContext context) {
return Container(
return Container(
width: 1.sw,
height: 1.sh,
color: Colors.white,
@ -30,37 +28,44 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
Stack(
// alignment: Alignment.bottomCenter,
children: [
Image.asset("images/icon_test20231113.png", width: 1.sw, height: 1.sh, fit: BoxFit.cover),
// Image.asset("images/icon_test20231113.png", width: 1.sw, height: 1.sh, fit: BoxFit.cover),
Image.memory(
state.imageData,
width: 1.sw,
height: 1.sh,
fit: BoxFit.cover,
),
Positioned(
top: ScreenUtil().statusBarHeight + 30.h,
child: Row(
children: [
SizedBox(width: 30.w),
GestureDetector(
onTap: () {
Get.back();
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30.h)
),
padding: EdgeInsets.all(10.w),
child: Image(width: 40.w, height: 40.w, image: const AssetImage("images/icon_left_black.png"),),
),
child: Row(children: [
SizedBox(width: 30.w),
GestureDetector(
onTap: () {
Get.back();
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30.h)),
padding: EdgeInsets.all(10.w),
child: Image(
width: 40.w,
height: 40.w,
image: const AssetImage("images/icon_left_black.png"),
),
),
),
]),
),
Positioned(
bottom: 10.w,
child: Container(
width: 1.sw - 30.w*2,
width: 1.sw - 30.w * 2,
// height: 300.h,
margin: EdgeInsets.all(30.w),
decoration: BoxDecoration(
color: const Color(0xC83C3F41),
borderRadius: BorderRadius.circular(20.h)
),
borderRadius: BorderRadius.circular(20.h)),
child: Column(
children: [
SizedBox(height: 20.h),
@ -70,7 +75,7 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
SizedBox(height: 20.h),
],
),
))
))
],
),
],
@ -78,76 +83,80 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
);
}
Widget bottomTopBtnWidget(){
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
//
GestureDetector(
onTap: () {
state.isOpenVoice.value = !state.isOpenVoice.value;
},
child: Container(
width: 50.w,
height: 50.w,
padding: EdgeInsets.all(5.w),
child: Obx(() => Image(
width: 40.w,
height: 40.w,
image: state.isOpenVoice.value
? const AssetImage("images/main/icon_lockDetail_monitoringCloseVoice.png")
: const AssetImage("images/main/icon_lockDetail_monitoringOpenVoice.png")
)),
),
),
SizedBox(width: 60.w),
//
GestureDetector(
onTap: () {
// Get.toNamed(Routers.monitoringRealTimeScreenPage);
},
child: Container(
width: 50.w,
height: 50.w,
padding: EdgeInsets.all(5.w),
child: Image(width: 40.w, height: 40.w, image: const AssetImage("images/main/icon_lockDetail_monitoringScreenshot.png")),
),
),
SizedBox(width: 60.w),
//
GestureDetector(
onTap: () {
// Get.toNamed(Routers.monitoringRealTimeScreenPage);
},
child: Container(
width: 50.w,
height: 50.w,
padding: EdgeInsets.all(5.w),
child: Image(width: 40.w, height: 40.w, image: const AssetImage("images/main/icon_lockDetail_monitoringScreenRecording.png")),
),
),
]);
Widget bottomTopBtnWidget() {
return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
//
GestureDetector(
onTap: () {
state.isOpenVoice.value = !state.isOpenVoice.value;
},
child: Container(
width: 50.w,
height: 50.w,
padding: EdgeInsets.all(5.w),
child: Obx(() => Image(
width: 40.w,
height: 40.w,
image: state.isOpenVoice.value
? const AssetImage(
"images/main/icon_lockDetail_monitoringCloseVoice.png")
: const AssetImage(
"images/main/icon_lockDetail_monitoringOpenVoice.png"))),
),
),
SizedBox(width: 60.w),
//
GestureDetector(
onTap: () {
// Get.toNamed(Routers.monitoringRealTimeScreenPage);
},
child: Container(
width: 50.w,
height: 50.w,
padding: EdgeInsets.all(5.w),
child: Image(
width: 40.w,
height: 40.w,
image: const AssetImage(
"images/main/icon_lockDetail_monitoringScreenshot.png")),
),
),
SizedBox(width: 60.w),
//
GestureDetector(
onTap: () {
// Get.toNamed(Routers.monitoringRealTimeScreenPage);
},
child: Container(
width: 50.w,
height: 50.w,
padding: EdgeInsets.all(5.w),
child: Image(
width: 40.w,
height: 40.w,
image: const AssetImage(
"images/main/icon_lockDetail_monitoringScreenRecording.png")),
),
),
]);
}
Widget bottomBottomBtnWidget(){
return Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringTalkback.png", "点击对讲", Colors.white,(){
}),
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png", "长按开锁", AppColors.mainColor,(){
})
]);
Widget bottomBottomBtnWidget() {
return Row(mainAxisAlignment: MainAxisAlignment.spaceAround, children: [
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringTalkback.png",
"点击对讲", Colors.white, () {}),
bottomBtnItemWidget("images/main/icon_lockDetail_monitoringUnlock.png",
"长按开锁", AppColors.mainColor, () {})
]);
}
Widget bottomBtnItemWidget(String iconUrl, String name, Color backgroundColor, Function() onClick) {
Widget bottomBtnItemWidget(
String iconUrl, String name, Color backgroundColor, Function() onClick) {
var wh = 80.w;
return GestureDetector(
onTap: onClick,
child: SizedBox(
height: 140.h,
height: 140.h,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
@ -156,13 +165,15 @@ class _LockMonitoringPageState extends State<LockMonitoringPage> {
height: wh,
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: BorderRadius.circular((wh+ 10.w*2)/2)
),
borderRadius: BorderRadius.circular((wh + 10.w * 2) / 2)),
padding: EdgeInsets.all(20.w),
child: Image.asset(iconUrl, fit: BoxFit.fitWidth),
),
SizedBox(height: 20.w),
Expanded(child: Text(name, style: TextStyle(fontSize: 20.sp, color: Colors.white), textAlign: TextAlign.center))
Expanded(
child: Text(name,
style: TextStyle(fontSize: 20.sp, color: Colors.white),
textAlign: TextAlign.center))
],
)),
);

View File

@ -0,0 +1,111 @@
import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:flutter_sound/flutter_sound.dart';
// import 'package:just_audio/just_audio.dart';
import 'package:star_lock/main/lockDetail/monitoring/monitoring/lockMonitoring_page.dart';
import 'package:star_lock/talk/call/g711Decoder.dart';
import 'package:star_lock/talk/call/iFrameInfo.dart';
class CallTalk {
static int POS_iframe_index = 63;
static int POS_alen = 65;
static int POS_blen = 73;
static int POS_bag_index = 71;
static int POS_bag_num = 69;
static int POS_data = 77;
static int ABUF_NUM = 100;
static int FIRSTINDEX = 1;
int status = 0; //
IframeInfo iframe = IframeInfo(); //
LockMonitoringPage callOut = const LockMonitoringPage();
late FlutterSoundPlayer _player;
Future<void> getAVData(Uint8List bb, int len) async {
//
// String hexData =
// '5858584349449601075439415f396333613730323264346364a5a5a5a5c0a809a3503138363832313530323337000000000000000030303030420e000002000000b33300001f000100b301b301ffd8ffe000114a4649460001010000';
// Uint8List bb = Uint8List.fromList(hex.decode(hexData));
//
String hexData =
'5858584349449601075439415f396333613730323264346364a5a5a5a5c0a809a3503138363832313530323337000000000000000030303030e02900000100050080020000010001004001b30145444444444444444445454444444444444444444444434343434443434344444444444544454545444444444444454545454545454545454445444545454545454545444444444343434344444443434344444444444343434343434343434443434343434343424343434343434242424242424242424243434343434242424242424343434342424343434242424242434243434343434344454344444444444444444444444444454545454544444444444444444445454545454545454545454545454546454545454545454545454545454545454646464646464645454545464646454545454545454545454545454544444444444444444443434343434343434343434343434343434343434242424242424242424242424242424343434242434343434343434343434343434343434343434444444343434343430000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024001d044000000000001d080001000000001d18c03000000000';
Uint8List bb = Uint8List.fromList(hex.decode(hexData));
//
if (bb[61] == 1) {
//
_player = FlutterSoundPlayer();
_initPlayer();
//
Uint8List g711Data = G711Decoder().decodeG711uLaw(bb);
await _playAudio(g711Data);
}
//
else {
int bagLen = getShortFromByte(bb, POS_blen + 2);
int getIframeIndex = getShortFromByte(bb, POS_iframe_index);
int alen = getShortFromByte(bb, POS_alen);
int blen = getShortFromByte(bb, POS_blen);
int getBagIndex = bb[POS_bag_index] & 0xff;
int getBagNum = bb[POS_bag_num] & 0xff;
if (getIframeIndex != iframe.iframeIndex) {
iframe = IframeInfo();
iframe.iframeIndex = getIframeIndex;
iframe.bagNum = getBagNum;
iframe.cur_len = alen;
iframe.bb = Uint8List(alen);
}
iframe.bagReceive++;
int start = bagLen * (getBagIndex - FIRSTINDEX);
int end = start + blen;
// iframe!.bb null
if (iframe.bb == null || iframe.bb!.length < end) {
iframe.bb = Uint8List(end);
}
copyBytes(iframe!.bb!, start, bb, POS_data, blen);
//
print('Copied Bytes: ${iframe.bb}');
Uint8List data = iframe.bb!.sublist(0, iframe.cur_len);
//
print(iframe.bb);
}
}
int getShortFromByte(Uint8List bb, int pos) {
ByteData byteData = ByteData.sublistView(bb, pos, pos + 2);
return byteData.getInt16(0, Endian.little);
}
void copyBytes(Uint8List destination, int destStart, Uint8List source,
int sourceStart, int length) {
if (destination.length < destStart + length ||
source.length < sourceStart + length) {
//
print('Error: Index out of range');
return;
}
for (int i = 0; i < length; i++) {
destination[destStart + i] = source[sourceStart + i];
}
}
Future<void> _initPlayer() async {
await _player.openPlayer();
}
Future<void> _playAudio(Uint8List audioData) async {
await _player.startPlayer(
fromDataBuffer: audioData,
codec: Codec.pcm16WAV,
);
}
}

View File

@ -0,0 +1,44 @@
import 'dart:typed_data';
class G711Decoder {
// G.711 µ-law解码
Uint8List decodeG711uLaw(Uint8List data) {
List<int> decodedData = [];
for (int i = 0; i < data.length; i++) {
int sample = _decodeG711uLawSample(data[i]);
decodedData.add(sample);
}
return Uint8List.fromList(decodedData);
}
// G.711 µ-law样本解码
int _decodeG711uLawSample(int uLawByte) {
const int bias = 0x84;
const int mask = 0x7F;
uLawByte = ~uLawByte;
int sign = uLawByte & 0x80;
int exponent = (uLawByte & 0x70) >> 4;
int mantissa = uLawByte & 0x0F;
int sample = ((bias << exponent) + mantissa) * (sign == 0 ? 1 : -1);
return sample & mask; //
}
}
void main() {
G711Decoder g711Decoder = G711Decoder();
// g711Data G.711 µ-law编码的数据
Uint8List g711Data =
Uint8List.fromList([/* your G.711 µ-law encoded data */]);
//
List<int> decodedData = g711Decoder.decodeG711uLaw(g711Data);
//
print(decodedData);
}

View File

@ -0,0 +1,22 @@
import 'dart:typed_data';
class IframeInfo {
int iframeIndex = -1;
int iframeTime = 0;
int bagNum = 0;
int bagReceive = 0;
bool isFull = false;
int cur_len = 0;
int bb_len = 0;
Uint8List? bb;
int codecMode = 0;
IframeInfo() {
iframeIndex = -1;
bagNum = 0;
bagReceive = 0;
isFull = false;
cur_len = 0;
bb = Uint8List(512);
}
}

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"
#include <aj_captcha_flutter/aj_captcha_flutter_plugin.h>
#include <audioplayers_linux/audioplayers_linux_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
@ -14,6 +15,9 @@ void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) aj_captcha_flutter_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AjCaptchaFlutterPlugin");
aj_captcha_flutter_plugin_register_with_registrar(aj_captcha_flutter_registrar);
g_autoptr(FlPluginRegistrar) audioplayers_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "AudioplayersLinuxPlugin");
audioplayers_linux_plugin_register_with_registrar(audioplayers_linux_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
aj_captcha_flutter
audioplayers_linux
file_selector_linux
url_launcher_linux
)

View File

@ -6,8 +6,11 @@ import FlutterMacOS
import Foundation
import aj_captcha_flutter
import audio_session
import audioplayers_darwin
import device_info_plus
import file_selector_macos
import just_audio
import network_info_plus
import package_info_plus
import path_provider_foundation
@ -17,8 +20,11 @@ import url_launcher_macos
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
AjCaptchaFlutterPlugin.register(with: registry.registrar(forPlugin: "AjCaptchaFlutterPlugin"))
AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin"))
AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin"))
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin"))
NetworkInfoPlusPlugin.register(with: registry.registrar(forPlugin: "NetworkInfoPlusPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))

View File

@ -117,6 +117,14 @@ dependencies:
video_player: ^2.7.2
#控制横竖屏控件
auto_orientation: ^2.3.1
audioplayers: ^5.2.1
g711_flutter: ^2.0.0
ffi: ^2.1.0
flutter_mjpeg: ^2.0.4
image_gallery_saver: ^2.0.3
convert: ^3.1.1
just_audio: ^0.9.36
flutter_sound: ^9.2.13
dev_dependencies:
flutter_test:
@ -148,6 +156,7 @@ flutter:
- images/lan/
- images/mine/
- images/lockType/
- assets/
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware

View File

@ -7,6 +7,7 @@
#include "generated_plugin_registrant.h"
#include <aj_captcha_flutter/aj_captcha_flutter_plugin_c_api.h>
#include <audioplayers_windows/audioplayers_windows_plugin.h>
#include <file_selector_windows/file_selector_windows.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
@ -14,6 +15,8 @@
void RegisterPlugins(flutter::PluginRegistry* registry) {
AjCaptchaFlutterPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AjCaptchaFlutterPluginCApi"));
AudioplayersWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
PermissionHandlerWindowsPluginRegisterWithRegistrar(

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
aj_captcha_flutter
audioplayers_windows
file_selector_windows
permission_handler_windows
url_launcher_windows