add packet queue to AudioMixerClientData

This commit is contained in:
Zach Pomerantz 2017-02-13 19:56:30 -05:00
parent 442e8d68ef
commit 2f457ae891
4 changed files with 32 additions and 7 deletions

View file

@ -323,6 +323,7 @@ void AudioMixer::sendStatsPacket() {
addTiming(_prepareTiming, "prepare");
addTiming(_mixTiming, "mix");
addTiming(_eventsTiming, "events");
addTiming(_packetsTiming, "packets");
#ifdef HIFI_AUDIO_MIXER_DEBUG
timingStats["ns_per_mix"] = (_stats.totalMixes > 0) ? (float)(_stats.mixTime / _stats.totalMixes) : 0;
@ -452,18 +453,27 @@ void AudioMixer::start() {
++frame;
++_numStatFrames;
// play nice with qt event-looping
// process queued events (networking, &c.)
{
auto eventsTimer = _eventsTiming.timer();
// since we're a while loop we need to yield to qt's event processing
QCoreApplication::processEvents();
}
if (_isFinished) {
// alert qt eventing that this is finished
QCoreApplication::sendPostedEvents(this, QEvent::DeferredDelete);
break;
}
// process audio packets
{
auto packetsTimer = _packetsTiming.timer();
nodeList->eachNode([&](SharedNodePointer& node) {
AudioMixerClientData* data = getOrCreateClientData(node.data());
data->processPackets();
});
}
if (_isFinished) {
// alert qt eventing that this is finished
QCoreApplication::sendPostedEvents(this, QEvent::DeferredDelete);
break;
}
}
}

View file

@ -124,6 +124,7 @@ private:
Timer _prepareTiming;
Timer _mixTiming;
Timer _eventsTiming;
Timer _packetsTiming;
static int _numStaticJitterFrames; // -1 denotes dynamic jitter buffering
static float _noiseMutingThreshold;

View file

@ -47,6 +47,14 @@ AudioMixerClientData::~AudioMixerClientData() {
}
}
void AudioMixerClientData::queuePacket(QSharedPointer<ReceivedMessage> packet) {
_queuedPackets.push(packet);
}
void AudioMixerClientData::processPackets() {
// TODO: process the queue
assert(_queuedPackets.empty());
}
AvatarAudioStream* AudioMixerClientData::getAvatarAudioStream() {
QReadLocker readLocker { &_streamsLock };

View file

@ -12,6 +12,8 @@
#ifndef hifi_AudioMixerClientData_h
#define hifi_AudioMixerClientData_h
#include <queue>
#include <QtCore/QJsonObject>
#include <AABox.h>
@ -34,6 +36,9 @@ public:
using SharedStreamPointer = std::shared_ptr<PositionalAudioStream>;
using AudioStreamMap = std::unordered_map<QUuid, SharedStreamPointer>;
void queuePacket(QSharedPointer<ReceivedMessage> packet);
void processPackets();
// locks the mutex to make a copy
AudioStreamMap getAudioStreams() { QReadLocker readLock { &_streamsLock }; return _audioStreams; }
AvatarAudioStream* getAvatarAudioStream();
@ -105,11 +110,12 @@ public slots:
void sendSelectAudioFormat(SharedNodePointer node, const QString& selectedCodecName);
private:
using IgnoreZone = AABox;
std::queue<QSharedPointer<ReceivedMessage>> _queuedPackets;
QReadWriteLock _streamsLock;
AudioStreamMap _audioStreams; // microphone stream from avatar is stored under key of null UUID
using IgnoreZone = AABox;
class IgnoreZoneMemo {
public:
IgnoreZoneMemo(AudioMixerClientData& data) : _data(data) {}