change stream HRTF map to use a vector

This commit is contained in:
Stephen Birarda 2018-08-03 17:07:55 -07:00
parent bcba2a1cf1
commit c992150c10
2 changed files with 29 additions and 4 deletions

View file

@ -226,11 +226,31 @@ AvatarAudioStream* AudioMixerClientData::getAvatarAudioStream() {
return NULL;
}
AudioHRTF& AudioMixerClientData::hrtfForStream(Node::LocalID nodeID, const QUuid& streamID) {
auto& hrtfVector = _nodeSourcesHRTFMap[nodeID];
auto streamIt = std::find_if(hrtfVector.begin(), hrtfVector.end(), [&streamID](IdentifiedHRTF& identifiedHRTF){
return identifiedHRTF.streamIdentifier == streamID;
});
if (streamIt == hrtfVector.end()) {
hrtfVector.push_back({ streamID, std::unique_ptr<AudioHRTF>(new AudioHRTF) });
return *hrtfVector.back().hrtf;
} else {
return *streamIt->hrtf;
}
}
void AudioMixerClientData::removeHRTFForStream(Node::LocalID nodeID, const QUuid& streamID) {
auto it = _nodeSourcesHRTFMap.find(nodeID);
if (it != _nodeSourcesHRTFMap.end()) {
auto streamIt = std::find_if(it->second.begin(), it->second.end(), [&streamID](IdentifiedHRTF& identifiedHRTF){
return identifiedHRTF.streamIdentifier == streamID;
});
// erase the stream with the given ID from the given node
it->second.erase(streamID);
it->second.erase(streamIt);
// is the map for this node now empty?
// if so we can remove it

View file

@ -50,7 +50,7 @@ public:
// they are not thread-safe
// returns a new or existing HRTF object for the given stream from the given node
AudioHRTF& hrtfForStream(Node::LocalID nodeID, const QUuid& streamID = QUuid()) { return _nodeSourcesHRTFMap[nodeID][streamID]; }
AudioHRTF& hrtfForStream(Node::LocalID nodeID, const QUuid& streamID = QUuid());
// removes an AudioHRTF object for a given stream
void removeHRTFForStream(Node::LocalID nodeID, const QUuid& streamID = QUuid());
@ -152,8 +152,13 @@ private:
};
IgnoreZoneMemo _ignoreZone;
using HRTFMap = std::unordered_map<QUuid, AudioHRTF>;
using NodeSourcesHRTFMap = std::unordered_map<Node::LocalID, HRTFMap>;
struct IdentifiedHRTF {
QUuid streamIdentifier;
std::unique_ptr<AudioHRTF> hrtf;
};
using HRTFVector = std::vector<IdentifiedHRTF>;
using NodeSourcesHRTFMap = std::unordered_map<Node::LocalID, HRTFVector>;
NodeSourcesHRTFMap _nodeSourcesHRTFMap;
quint16 _outgoingMixedAudioSequenceNumber;