mv shouldIgnore from AudioMixerSlave to ClientData

This commit is contained in:
Zach Pomerantz 2017-02-03 17:52:02 +00:00
parent 3c1cf504d0
commit 8a42755e8f
3 changed files with 39 additions and 38 deletions

View file

@ -59,6 +59,32 @@ AvatarAudioStream* AudioMixerClientData::getAvatarAudioStream() {
return NULL;
}
bool shouldIgnore(const SharedNodePointer self, const SharedNodePointer node, unsigned int frame) {
AudioMixerClientData* nodeData = static_cast<AudioMixerClientData*>(node->getLinkedData());
if (!nodeData) {
return false;
}
bool ignore = true;
if ( // the nodes are not ignoring each other explicitly (or are but get data regardless)
(!self->isIgnoringNodeWithID(node->getUUID()) ||
(nodeData->getRequestsDomainListData() && node->getCanKick())) &&
(!node->isIgnoringNodeWithID(self->getUUID()) ||
(getsRequestsDomainListData() && self->getCanKick()))) {
// if either node is enabling an ignore radius, check their proximity
if ((listener->isIgnoreRadiusEnabled() || node->isIgnoreRadiusEnabled())) {
auto& listenerZone = listenerData->getIgnoreZone(frame);
auto& nodeZone = nodeData->getIgnoreZone(frame);
ignore = listenerBox.touches(nodeZone);
} else {
ignore = false;
}
}
return ignore;
}
IgnoreZone& AudioMixerClientData::getIgnoreZone(unsigned int frame) {
// check for a memoized zone
if (frame != _ignoreZoneMemo.frame.load(std::memory_order_acquire) {

View file

@ -27,23 +27,22 @@
class AudioMixerClientData : public NodeData {
Q_OBJECT
using IgnoreZone = AABox;
public:
AudioMixerClientData(const QUuid& nodeID);
~AudioMixerClientData();
using SharedStreamPointer = std::shared_ptr<PositionalAudioStream>;
using AudioStreamMap = std::unordered_map<QUuid, SharedStreamPointer>;
using IgnoreZone = AABox;
// locks the mutex to make a copy
AudioStreamMap getAudioStreams() { QReadLocker readLock { &_streamsLock }; return _audioStreams; }
AvatarAudioStream* getAvatarAudioStream();
// returns an ignore zone, memoized by frame (lockless if the zone is already memoized)
// preconditions:
// - frame is monotonically increasing
// - calls are only made to getIgnoreZone(frame + 1) when there are no references left from calls to getIgnoreZone(frame)
IgnoreZone& AudioMixerClientData::getIgnoreZone(unsigned int frame);
// returns whether self (this data's node) should ignore node, memoized by frame
// preconditions: frame is monotonically increasing
bool shouldIgnore(SharedNodePointer self, SharedNodePointer node, unsigned int frame);
// the following methods should be called from the AudioMixer assignment thread ONLY
// they are not thread-safe
@ -108,6 +107,12 @@ public slots:
void sendSelectAudioFormat(SharedNodePointer node, const QString& selectedCodecName);
private:
// returns an ignore zone, memoized by frame (lockless if the zone is already memoized)
// preconditions:
// - frame is monotonically increasing
// - calls are only made to getIgnoreZone(frame + 1) when there are no references left from calls to getIgnoreZone(frame)
IgnoreZone& AudioMixerClientData::getIgnoreZone(unsigned int frame);
QReadWriteLock _streamsLock;
AudioStreamMap _audioStreams; // microphone stream from avatar is stored under key of null UUID

View file

@ -46,7 +46,6 @@ void sendMutePacket(const SharedNodePointer& node, AudioMixerClientData&);
void sendEnvironmentPacket(const SharedNodePointer& node, AudioMixerClientData& data);
// mix helpers
inline bool shouldIgnoreNode(const SharedNodePointer& listener, const SharedNodePointer& node);
inline float approximateGain(const AvatarAudioStream& listeningNodeStream, const PositionalAudioStream& streamToAdd,
const glm::vec3& relativePosition);
inline float computeGain(const AvatarAudioStream& listeningNodeStream, const PositionalAudioStream& streamToAdd,
@ -146,7 +145,7 @@ bool AudioMixerSlave::prepareMix(const SharedNodePointer& listener) {
mixStream(*listenerData, node->getUUID(), *listenerAudioStream, *nodeStream);
}
}
} else if (!shouldIgnoreNode(listener, node, _frame)) {
} else if (!listenerData->shouldIgnoreNode(listener, node, _frame)) {
if (!isThrottling) {
allStreams(node, &AudioMixerSlave::mixStream);
} else {
@ -452,36 +451,6 @@ void sendEnvironmentPacket(const SharedNodePointer& node, AudioMixerClientData&
}
}
bool shouldIgnoreNode(const SharedNodePointer& listener, const SharedNodePointer& node, unsigned int frame) {
AudioMixerClientData* listenerData = static_cast<AudioMixerClientData*>(listener->getLinkedData());
AudioMixerClientData* nodeData = static_cast<AudioMixerClientData*>(node->getLinkedData());
// when this is true, the AudioMixer will send Audio data to a client about avatars that have ignored them
bool getsAnyIgnored = listenerData->getRequestsDomainListData() && listener->getCanKick();
bool ignore = true;
if (nodeData &&
// make sure that it isn't being ignored by our listening node
(!listener->isIgnoringNodeWithID(node->getUUID()) || (nodeData->getRequestsDomainListData() && node->getCanKick())) &&
// and that it isn't ignoring our listening node
(!node->isIgnoringNodeWithID(listener->getUUID()) || getsAnyIgnored)) {
// is either node enabling the space bubble / ignore radius?
if ((listener->isIgnoreRadiusEnabled() || node->isIgnoreRadiusEnabled())) {
auto& listenerZone = listenerData->getIgnoreZone(frame);
auto& nodeZone = nodeData->getIgnoreZone(frame);
ignore = listenerBox.touches(nodeZone);
} else {
ignore = false;
}
}
return ignore;
}
static const float ATTENUATION_START_DISTANCE = 1.0f;
float approximateGain(const AvatarAudioStream& listeningNodeStream, const PositionalAudioStream& streamToAdd,
const glm::vec3& relativePosition) {
float gain = 1.0f;
@ -537,6 +506,7 @@ float computeGain(const AvatarAudioStream& listeningNodeStream, const Positional
}
// distance attenuation
const float ATTENUATION_START_DISTANCE = 1.0f;
float distance = glm::length(relativePosition);
assert(ATTENUATION_START_DISTANCE > EPSILON);
if (distance >= ATTENUATION_START_DISTANCE) {