mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-16 20:08:20 +02:00
remove static variables in AudioInjector.cpp
This commit is contained in:
parent
7da6ec46c4
commit
d764ff2e87
3 changed files with 19 additions and 8 deletions
|
@ -165,9 +165,6 @@ uint64_t AudioInjector::injectNextFrame() {
|
|||
static int positionOptionOffset = -1;
|
||||
static int volumeOptionOffset = -1;
|
||||
static int audioDataOffset = -1;
|
||||
static quint16 outgoingInjectedAudioSequenceNumber = 0;
|
||||
static int nextFrame = 0;
|
||||
static QElapsedTimer frameTimer;
|
||||
|
||||
if (!_currentPacket) {
|
||||
if (_currentSendOffset < 0 ||
|
||||
|
@ -178,8 +175,14 @@ uint64_t AudioInjector::injectNextFrame() {
|
|||
// make sure we actually have samples downloaded to inject
|
||||
if (_audioData.size()) {
|
||||
|
||||
nextFrame = 0;
|
||||
frameTimer.restart();
|
||||
_outgoingSequenceNumber = 0;
|
||||
_nextFrame = 0;
|
||||
|
||||
if (!_frameTimer) {
|
||||
_frameTimer = std::unique_ptr<QElapsedTimer>(new QElapsedTimer);
|
||||
}
|
||||
|
||||
_frameTimer->restart();
|
||||
|
||||
_currentPacket = NLPacket::create(PacketType::InjectAudio);
|
||||
|
||||
|
@ -242,7 +245,7 @@ uint64_t AudioInjector::injectNextFrame() {
|
|||
_currentPacket->seek(0);
|
||||
|
||||
// pack the sequence number
|
||||
_currentPacket->writePrimitive(outgoingInjectedAudioSequenceNumber);
|
||||
_currentPacket->writePrimitive(_outgoingSequenceNumber);
|
||||
|
||||
_currentPacket->seek(positionOptionOffset);
|
||||
_currentPacket->writePrimitive(_options.position);
|
||||
|
@ -267,7 +270,7 @@ uint64_t AudioInjector::injectNextFrame() {
|
|||
if (audioMixer) {
|
||||
// send off this audio packet
|
||||
nodeList->sendUnreliablePacket(*_currentPacket, *audioMixer);
|
||||
outgoingInjectedAudioSequenceNumber++;
|
||||
_outgoingSequenceNumber++;
|
||||
}
|
||||
|
||||
_currentSendOffset += bytesToCopy;
|
||||
|
@ -290,7 +293,7 @@ uint64_t AudioInjector::injectNextFrame() {
|
|||
// immediately send the first two frames so the mixer can start using the audio right away
|
||||
return NEXT_FRAME_DELTA_IMMEDIATELY;
|
||||
} else {
|
||||
return (++nextFrame * AudioConstants::NETWORK_FRAME_USECS) - frameTimer.nsecsElapsed() / 1000;
|
||||
return (++_nextFrame * AudioConstants::NETWORK_FRAME_USECS) - _frameTimer->nsecsElapsed() / 1000;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <atomic>
|
||||
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QSharedPointer>
|
||||
#include <QtCore/QThread>
|
||||
|
@ -95,6 +96,10 @@ private:
|
|||
AbstractAudioInterface* _localAudioInterface { nullptr };
|
||||
AudioInjectorLocalBuffer* _localBuffer { nullptr };
|
||||
|
||||
int _nextFrame { 0 };
|
||||
std::unique_ptr<QElapsedTimer> _frameTimer { nullptr };
|
||||
quint16 _outgoingSequenceNumber { 0 };
|
||||
|
||||
friend class AudioInjectorManager;
|
||||
};
|
||||
|
||||
|
|
|
@ -94,6 +94,9 @@ void AudioInjectorManager::run() {
|
|||
_injectorReady.wait(lock);
|
||||
}
|
||||
|
||||
// unlock the lock in case something in process events needs to modify the queue
|
||||
lock.unlock();
|
||||
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue