kopia lustrzana https://gitlab.com/eliggett/wfview
Clear audio buffer if too many packets are delayed
rodzic
317cbd640a
commit
94a89dea33
|
@ -439,13 +439,13 @@ qint64 audioHandler::readData(char* buffer, qint64 nBytes)
|
||||||
if (!isReady) {
|
if (!isReady) {
|
||||||
isReady = true;
|
isReady = true;
|
||||||
}
|
}
|
||||||
|
audioPacket packet;
|
||||||
if (ringBuf->size()>0)
|
if (ringBuf->size()>0)
|
||||||
{
|
{
|
||||||
// Output buffer is ALWAYS 16 bit.
|
// Output buffer is ALWAYS 16 bit.
|
||||||
//qDebug(logAudio()) << "Read: nFrames" << nFrames << "nBytes" << nBytes;
|
//qDebug(logAudio()) << "Read: nFrames" << nFrames << "nBytes" << nBytes;
|
||||||
while (sentlen < nBytes)
|
while (sentlen < nBytes)
|
||||||
{
|
{
|
||||||
audioPacket packet;
|
|
||||||
if (!ringBuf->try_read(packet))
|
if (!ringBuf->try_read(packet))
|
||||||
{
|
{
|
||||||
qDebug(logAudio()) << "No more data available but buffer is not full! sentlen:" << sentlen << " nBytes:" << nBytes ;
|
qDebug(logAudio()) << "No more data available but buffer is not full! sentlen:" << sentlen << " nBytes:" << nBytes ;
|
||||||
|
@ -479,6 +479,7 @@ qint64 audioHandler::readData(char* buffer, qint64 nBytes)
|
||||||
}
|
}
|
||||||
currentLatency = packet.time.msecsTo(QTime::currentTime());
|
currentLatency = packet.time.msecsTo(QTime::currentTime());
|
||||||
}
|
}
|
||||||
|
delayedPackets++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int send = qMin((int)nBytes - sentlen, packet.data.length());
|
int send = qMin((int)nBytes - sentlen, packet.data.length());
|
||||||
|
@ -510,6 +511,12 @@ qint64 audioHandler::readData(char* buffer, qint64 nBytes)
|
||||||
if (nBytes > sentlen) {
|
if (nBytes > sentlen) {
|
||||||
memset(buffer+sentlen,0,nBytes-sentlen);
|
memset(buffer+sentlen,0,nBytes-sentlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (delayedPackets > 10) {
|
||||||
|
while (ringBuf->try_read(packet)); // Empty buffer
|
||||||
|
delayedPackets = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(RTAUDIO)
|
#if defined(RTAUDIO)
|
||||||
return 0;
|
return 0;
|
||||||
#elif defined(PORTAUDIO)
|
#elif defined(PORTAUDIO)
|
||||||
|
@ -751,6 +758,7 @@ void audioHandler::getNextAudioChunk(QByteArray& ret)
|
||||||
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Packet " << hex << packet.seq <<
|
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "Packet " << hex << packet.seq <<
|
||||||
" arrived too late (increase latency!) " <<
|
" arrived too late (increase latency!) " <<
|
||||||
dec << packet.time.msecsTo(QTime::currentTime()) << "ms";
|
dec << packet.time.msecsTo(QTime::currentTime()) << "ms";
|
||||||
|
delayedPackets++;
|
||||||
// if (!ringBuf->try_read(packet))
|
// if (!ringBuf->try_read(packet))
|
||||||
// break;
|
// break;
|
||||||
// currentLatency = packet.time.msecsTo(QTime::currentTime());
|
// currentLatency = packet.time.msecsTo(QTime::currentTime());
|
||||||
|
@ -851,6 +859,11 @@ void audioHandler::getNextAudioChunk(QByteArray& ret)
|
||||||
|
|
||||||
ret = packet.data;
|
ret = packet.data;
|
||||||
//qDebug(logAudio()) << "Now radio format, length" << packet.data.length();
|
//qDebug(logAudio()) << "Now radio format, length" << packet.data.length();
|
||||||
|
if (delayedPackets > 10) {
|
||||||
|
while (ringBuf->try_read(packet)); // Empty buffer
|
||||||
|
delayedPackets = 0;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,8 @@ private:
|
||||||
quint8 radioSampleBits;
|
quint8 radioSampleBits;
|
||||||
quint8 radioChannels;
|
quint8 radioChannels;
|
||||||
|
|
||||||
|
int delayedPackets=0;
|
||||||
|
|
||||||
QMap<quint32, audioPacket>audioBuffer;
|
QMap<quint32, audioPacket>audioBuffer;
|
||||||
|
|
||||||
double resampleRatio;
|
double resampleRatio;
|
||||||
|
|
Ładowanie…
Reference in New Issue