Merge branch 'talk_flutter' of gitee.com:starlock-cn/app-starlock into talk_flutter
This commit is contained in:
commit
5a5f8ea42f
@ -41,22 +41,19 @@ class CallTalk {
|
||||
CallTalk get manager => _share();
|
||||
|
||||
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) {
|
||||
print('dinglingling音频数据来啦啦啦啦啦啦啦啦啦');
|
||||
print('dinglingling音频数据来啦啦啦啦啦啦啦啦啦$bb');
|
||||
// 用你的711音频数据替换这里的Uint8List
|
||||
Uint8List rawData = G711Decoder().decodeG711uLaw(bb);
|
||||
_playRawData(rawData);
|
||||
print('收到音频数据了');
|
||||
// Uint8List rawData = G711Decoder().decodeG711uLaw(bb);
|
||||
// 示例 G711 数据(u-law 或 a-law)
|
||||
Uint8List g711Data = bb;
|
||||
// 解码为 PCM 数据
|
||||
Uint8List pcmData = G711Decoder().g711Decode(g711Data, G711Type.uLaw);
|
||||
// 现在你可以使用 pcmData 进行播放或其他处理
|
||||
print('得到的pcmData:$pcmData');
|
||||
|
||||
_playRawData(pcmData);
|
||||
}
|
||||
// 视频数据
|
||||
else {
|
||||
|
||||
@ -1,44 +1,36 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
class G711Decoder {
|
||||
// G.711 µ-law解码
|
||||
Uint8List decodeG711uLaw(Uint8List data) {
|
||||
List<int> decodedData = [];
|
||||
enum G711Type {
|
||||
uLaw,
|
||||
aLaw,
|
||||
}
|
||||
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
int sample = _decodeG711uLawSample(data[i]);
|
||||
decodedData.add(sample);
|
||||
class G711Decoder {
|
||||
Uint8List g711Decode(Uint8List g711Data, G711Type g711Type) {
|
||||
List<int> pcmData = [];
|
||||
int sign, exponent, mantissa, sample;
|
||||
|
||||
for (int i = 0; i < g711Data.length; i++) {
|
||||
int value = g711Data[i];
|
||||
|
||||
if (g711Type == G711Type.uLaw) {
|
||||
// μ-law decoding
|
||||
value = ~value & 0xFF;
|
||||
sign = (value & 0x80) == 0 ? 1 : -1;
|
||||
exponent = (value & 0x70) >> 4;
|
||||
mantissa = ((value & 0x0F) << 4) + 0x10;
|
||||
sample = (mantissa << exponent) * sign;
|
||||
} else {
|
||||
// A-law decoding
|
||||
sign = (value & 0x80) == 0 ? 1 : -1;
|
||||
exponent = ((value & 0x70) >> 4) + 1;
|
||||
mantissa = (value & 0x0F) + 0x10;
|
||||
sample = (mantissa << exponent) * sign;
|
||||
}
|
||||
|
||||
pcmData.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; // 防止溢出
|
||||
return Uint8List.fromList(pcmData);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
36
star_lock/lib/talk/call/g711Encode.dart
Normal file
36
star_lock/lib/talk/call/g711Encode.dart
Normal file
@ -0,0 +1,36 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
enum G711Type {
|
||||
uLaw,
|
||||
aLaw,
|
||||
}
|
||||
|
||||
class G711Decoder {
|
||||
Uint8List g711Encode(Uint8List pcmData, G711Type g711Type) {
|
||||
List<int> g711Data = [];
|
||||
|
||||
for (int sample in pcmData) {
|
||||
int sign = (sample < 0) ? 0x80 : 0;
|
||||
int magnitude = (sample < 0) ? -sample : sample;
|
||||
|
||||
int exponent = 7;
|
||||
while (magnitude < (1 << exponent) && exponent > 0) {
|
||||
exponent--;
|
||||
}
|
||||
|
||||
int mantissa = (magnitude >> (exponent - 4)) & 0x0F;
|
||||
|
||||
if (g711Type == G711Type.uLaw) {
|
||||
// μ-law encoding
|
||||
int value = ~(sign | ((exponent << 4) & 0x70) | (mantissa >> 4));
|
||||
g711Data.add(value & 0xFF);
|
||||
} else {
|
||||
// A-law encoding
|
||||
int value = sign | ((exponent << 4) & 0x70) | (mantissa >> 4);
|
||||
g711Data.add(value & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
return Uint8List.fromList(g711Data);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user