mv Node out of packet queue

This commit is contained in:
Zach Pomerantz 2017-02-14 21:08:33 +00:00
parent a7386392a1
commit 06c8fba35d
3 changed files with 23 additions and 18 deletions

View file

@ -74,7 +74,7 @@ AudioMixer::AudioMixer(ReceivedMessage& message) :
PacketType::RequestsDomainListData, PacketType::RequestsDomainListData,
PacketType::PerAvatarGainSet }, PacketType::PerAvatarGainSet },
this, "queueAudioPacket"); this, "queueAudioPacket");
// packets whose consequences are global should be processed on the main thread // packets whose consequences are global should be processed on the main thread
packetReceiver.registerListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket"); packetReceiver.registerListener(PacketType::MuteEnvironment, this, "handleMuteEnvironmentPacket");
packetReceiver.registerListener(PacketType::NodeMuteRequest, this, "handleNodeMuteRequestPacket"); packetReceiver.registerListener(PacketType::NodeMuteRequest, this, "handleNodeMuteRequestPacket");

View file

@ -49,46 +49,52 @@ AudioMixerClientData::~AudioMixerClientData() {
} }
void AudioMixerClientData::queuePacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer node) { void AudioMixerClientData::queuePacket(QSharedPointer<ReceivedMessage> message, SharedNodePointer node) {
_queuedPackets.push({ message, node }); if (!_packetQueue.node) {
_packetQueue.node = node;
}
_packetQueue.push(message);
} }
void AudioMixerClientData::processPackets() { void AudioMixerClientData::processPackets() {
while (!_queuedPackets.empty()) { SharedNodePointer node = _packetQueue.node;
auto& packet = _queuedPackets.back(); assert(_packetQueue.empty() || node);
_packetQueue.node.clear();
switch (packet.message->getType()) { while (!_packetQueue.empty()) {
auto& packet = _packetQueue.back();
switch (packet->getType()) {
case PacketType::MicrophoneAudioNoEcho: case PacketType::MicrophoneAudioNoEcho:
case PacketType::MicrophoneAudioWithEcho: case PacketType::MicrophoneAudioWithEcho:
case PacketType::InjectAudio: case PacketType::InjectAudio:
case PacketType::AudioStreamStats: case PacketType::AudioStreamStats:
case PacketType::SilentAudioFrame: { case PacketType::SilentAudioFrame: {
QMutexLocker lock(&getMutex()); QMutexLocker lock(&getMutex());
parseData(*packet.message); parseData(*packet);
break; break;
} }
case PacketType::NegotiateAudioFormat: case PacketType::NegotiateAudioFormat:
negotiateAudioFormat(*packet.message, packet.node); negotiateAudioFormat(*packet, node);
break; break;
case PacketType::RequestsDomainListData: case PacketType::RequestsDomainListData:
parseRequestsDomainListData(*packet.message); parseRequestsDomainListData(*packet);
break; break;
case PacketType::PerAvatarGainSet: case PacketType::PerAvatarGainSet:
parsePerAvatarGainSet(*packet.message, packet.node); parsePerAvatarGainSet(*packet, node);
break; break;
case PacketType::NodeIgnoreRequest: case PacketType::NodeIgnoreRequest:
parseNodeIgnoreRequest(packet.message, packet.node); parseNodeIgnoreRequest(packet, node);
break; break;
case PacketType::RadiusIgnoreRequest: case PacketType::RadiusIgnoreRequest:
parseRadiusIgnoreRequest(packet.message, packet.node); parseRadiusIgnoreRequest(packet, node);
break; break;
default: default:
Q_UNREACHABLE(); Q_UNREACHABLE();
} }
_queuedPackets.pop(); _packetQueue.pop();
} }
assert(_packetQueue.empty());
assert(_queuedPackets.empty());
} }
void AudioMixerClientData::negotiateAudioFormat(ReceivedMessage& message, const SharedNodePointer& node) { void AudioMixerClientData::negotiateAudioFormat(ReceivedMessage& message, const SharedNodePointer& node) {

View file

@ -116,11 +116,10 @@ public slots:
void sendSelectAudioFormat(SharedNodePointer node, const QString& selectedCodecName); void sendSelectAudioFormat(SharedNodePointer node, const QString& selectedCodecName);
private: private:
struct Packet { struct PacketQueue : public std::queue<QSharedPointer<ReceivedMessage>> {
QSharedPointer<ReceivedMessage> message; QWeakPointer<Node> node;
SharedNodePointer node;
}; };
std::queue<Packet> _queuedPackets; PacketQueue _packetQueue;
QReadWriteLock _streamsLock; QReadWriteLock _streamsLock;
AudioStreamMap _audioStreams; // microphone stream from avatar is stored under key of null UUID AudioStreamMap _audioStreams; // microphone stream from avatar is stored under key of null UUID