mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 22:36:39 +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 positionOptionOffset = -1;
|
||||||
static int volumeOptionOffset = -1;
|
static int volumeOptionOffset = -1;
|
||||||
static int audioDataOffset = -1;
|
static int audioDataOffset = -1;
|
||||||
static quint16 outgoingInjectedAudioSequenceNumber = 0;
|
|
||||||
static int nextFrame = 0;
|
|
||||||
static QElapsedTimer frameTimer;
|
|
||||||
|
|
||||||
if (!_currentPacket) {
|
if (!_currentPacket) {
|
||||||
if (_currentSendOffset < 0 ||
|
if (_currentSendOffset < 0 ||
|
||||||
|
@ -178,8 +175,14 @@ uint64_t AudioInjector::injectNextFrame() {
|
||||||
// make sure we actually have samples downloaded to inject
|
// make sure we actually have samples downloaded to inject
|
||||||
if (_audioData.size()) {
|
if (_audioData.size()) {
|
||||||
|
|
||||||
nextFrame = 0;
|
_outgoingSequenceNumber = 0;
|
||||||
frameTimer.restart();
|
_nextFrame = 0;
|
||||||
|
|
||||||
|
if (!_frameTimer) {
|
||||||
|
_frameTimer = std::unique_ptr<QElapsedTimer>(new QElapsedTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
_frameTimer->restart();
|
||||||
|
|
||||||
_currentPacket = NLPacket::create(PacketType::InjectAudio);
|
_currentPacket = NLPacket::create(PacketType::InjectAudio);
|
||||||
|
|
||||||
|
@ -242,7 +245,7 @@ uint64_t AudioInjector::injectNextFrame() {
|
||||||
_currentPacket->seek(0);
|
_currentPacket->seek(0);
|
||||||
|
|
||||||
// pack the sequence number
|
// pack the sequence number
|
||||||
_currentPacket->writePrimitive(outgoingInjectedAudioSequenceNumber);
|
_currentPacket->writePrimitive(_outgoingSequenceNumber);
|
||||||
|
|
||||||
_currentPacket->seek(positionOptionOffset);
|
_currentPacket->seek(positionOptionOffset);
|
||||||
_currentPacket->writePrimitive(_options.position);
|
_currentPacket->writePrimitive(_options.position);
|
||||||
|
@ -267,7 +270,7 @@ uint64_t AudioInjector::injectNextFrame() {
|
||||||
if (audioMixer) {
|
if (audioMixer) {
|
||||||
// send off this audio packet
|
// send off this audio packet
|
||||||
nodeList->sendUnreliablePacket(*_currentPacket, *audioMixer);
|
nodeList->sendUnreliablePacket(*_currentPacket, *audioMixer);
|
||||||
outgoingInjectedAudioSequenceNumber++;
|
_outgoingSequenceNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
_currentSendOffset += bytesToCopy;
|
_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
|
// immediately send the first two frames so the mixer can start using the audio right away
|
||||||
return NEXT_FRAME_DELTA_IMMEDIATELY;
|
return NEXT_FRAME_DELTA_IMMEDIATELY;
|
||||||
} else {
|
} 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 <atomic>
|
||||||
|
|
||||||
|
#include <QtCore/QElapsedTimer>
|
||||||
#include <QtCore/QObject>
|
#include <QtCore/QObject>
|
||||||
#include <QtCore/QSharedPointer>
|
#include <QtCore/QSharedPointer>
|
||||||
#include <QtCore/QThread>
|
#include <QtCore/QThread>
|
||||||
|
@ -95,6 +96,10 @@ private:
|
||||||
AbstractAudioInterface* _localAudioInterface { nullptr };
|
AbstractAudioInterface* _localAudioInterface { nullptr };
|
||||||
AudioInjectorLocalBuffer* _localBuffer { nullptr };
|
AudioInjectorLocalBuffer* _localBuffer { nullptr };
|
||||||
|
|
||||||
|
int _nextFrame { 0 };
|
||||||
|
std::unique_ptr<QElapsedTimer> _frameTimer { nullptr };
|
||||||
|
quint16 _outgoingSequenceNumber { 0 };
|
||||||
|
|
||||||
friend class AudioInjectorManager;
|
friend class AudioInjectorManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,9 @@ void AudioInjectorManager::run() {
|
||||||
_injectorReady.wait(lock);
|
_injectorReady.wait(lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// unlock the lock in case something in process events needs to modify the queue
|
||||||
|
lock.unlock();
|
||||||
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue