kopia lustrzana https://gitlab.com/eliggett/wfview
Update audiohandler.cpp
rodzic
95b10ce465
commit
88ec30bb49
|
@ -295,10 +295,7 @@ void audioHandler::start()
|
|||
// Opus codec
|
||||
|
||||
encoder = opus_encoder_create(setup.samplerate, setup.radioChan, OPUS_APPLICATION_AUDIO, &err);
|
||||
opus_encoder_ctl(encoder, OPUS_SET_MAX_BANDWIDTH(setup.samplerate));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_BITRATE(OPUS_AUTO));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_FORCE_CHANNELS(setup.radioChan));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_VBR(1));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_LSB_DEPTH(16));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_INBAND_FEC(1));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_DTX(1));
|
||||
opus_encoder_ctl(encoder, OPUS_SET_PACKET_LOSS_PERC(5));
|
||||
|
@ -314,6 +311,7 @@ void audioHandler::start()
|
|||
if (setup.codec == 0x40 || setup.codec == 0x80) {
|
||||
// Opus codec
|
||||
decoder = opus_decoder_create(setup.samplerate, setup.radioChan, &err);
|
||||
opus_decoder_ctl(decoder, OPUS_SET_FORCE_CHANNELS(setup.radioChan));
|
||||
}
|
||||
}
|
||||
if (err < 0)
|
||||
|
@ -500,27 +498,28 @@ void audioHandler::incomingAudio(audioPacket inPacket)
|
|||
if (setup.codec == 0x40 || setup.codec == 0x80) {
|
||||
unsigned char* in = (unsigned char*)inPacket.data.data();
|
||||
/* Encode the frame. */
|
||||
QByteArray outPacket(this->chunkSize * 2 * setup.radioChan, (char)0xff); // Preset the output buffer size.
|
||||
QByteArray outPacket(this->chunkSize * sizeof(qint16) * setup.radioChan, (char)0xff); // Preset the output buffer size.
|
||||
qint16* out = (qint16*)outPacket.data();
|
||||
int nbBytes = 0;
|
||||
int nSamples = 0;
|
||||
|
||||
//if (lastSentSeq > 0 && lastSentSeq+1 < inPacket.seq)
|
||||
//{
|
||||
// nbBytes = opus_decode(decoder, NULL, 0, out, outPacket.size()/ 2 /setup.radioChan, 1);
|
||||
//}
|
||||
//else {
|
||||
nbBytes = opus_decode(decoder, in, inPacket.data.size(), out, this->chunkSize, 0);
|
||||
//}
|
||||
if (nbBytes < 0)
|
||||
if (lastSentSeq > 0 && lastSentSeq+1 < inPacket.seq)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decode failed:" << opus_strerror(nbBytes) << "packet size" << inPacket.data.length();
|
||||
nSamples = opus_decode(decoder, NULL, 0, out, this->chunkSize, 1);
|
||||
}
|
||||
else {
|
||||
nSamples = opus_decode(decoder, in, inPacket.data.size(), out, this->chunkSize, 0);
|
||||
}
|
||||
|
||||
if (nSamples < 0)
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decode failed:" << opus_strerror(nSamples) << "packet size" << inPacket.data.length();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (nbBytes * 2 != outPacket.size())
|
||||
if (nSamples * sizeof(qint16) != outPacket.size())
|
||||
{
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decoder mismatch: nbBytes:" << nbBytes * 2 << "outPacket:" << outPacket.size();
|
||||
outPacket.resize(nbBytes * 2);
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decoder mismatch: nBytes:" << nSamples * sizeof(qint16) << "outPacket:" << outPacket.size();
|
||||
outPacket.resize(nSamples * sizeof(qint16));
|
||||
}
|
||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Opus decoded" << inPacket.data.size() << "bytes, into" << outPacket.length() << "bytes";
|
||||
inPacket.data.clear();
|
||||
|
|
Ładowanie…
Reference in New Issue