use safer domain settings request in audio-mixer

This commit is contained in:
Stephen Birarda 2015-11-18 15:13:21 -08:00
parent 1a066abb26
commit f2ecce6043
7 changed files with 101 additions and 79 deletions

View file

@ -645,39 +645,40 @@ void AudioMixer::sendStatsPacket() {
void AudioMixer::run() {
qDebug() << "Waiting for connection to domain to request settings from domain-server.";
ThreadedAssignment::commonInit(AUDIO_MIXER_LOGGING_TARGET_NAME, NodeType::AudioMixer);
auto nodeList = DependencyManager::get<NodeList>();
// wait until we have the domain-server settings, otherwise we bail
DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
connect(&domainHandler, &DomainHandler::settingsReceived, this, &AudioMixer::domainSettingsRequestComplete);
connect(&domainHandler, &DomainHandler::settingsReceiveFail, this, &AudioMixer::domainSettingsRequestFailed);
}
void AudioMixer::domainSettingsRequestComplete() {
auto nodeList = DependencyManager::get<NodeList>();
nodeList->addNodeTypeToInterestSet(NodeType::Agent);
nodeList->linkedDataCreateCallback = [](Node* node) {
node->setLinkedData(new AudioMixerClientData());
};
// wait until we have the domain-server settings, otherwise we bail
DomainHandler& domainHandler = nodeList->getDomainHandler();
qDebug() << "Waiting for domain settings from domain-server.";
// block until we get the settingsRequestComplete signal
QEventLoop loop;
connect(&domainHandler, &DomainHandler::settingsReceived, &loop, &QEventLoop::quit);
connect(&domainHandler, &DomainHandler::settingsReceiveFail, &loop, &QEventLoop::quit);
domainHandler.requestDomainSettings();
loop.exec();
if (domainHandler.getSettingsObject().isEmpty()) {
qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment.";
setFinished(true);
return;
}
const QJsonObject& settingsObject = domainHandler.getSettingsObject();
// check the settings object to see if we have anything we can parse out
parseSettingsObject(settingsObject);
// queue up a connection to start broadcasting mixes now that we're ready to go
QMetaObject::invokeMethod(this, "broadcastMixes", Qt::QueuedConnection);
}
void AudioMixer::broadcastMixes() {
auto nodeList = DependencyManager::get<NodeList>();
int nextFrame = 0;
QElapsedTimer timer;
timer.start();

View file

@ -40,10 +40,13 @@ public slots:
static const InboundAudioStream::Settings& getStreamSettings() { return _streamSettings; }
private slots:
void broadcastMixes();
void handleNodeAudioPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
void handleMuteEnvironmentPacket(QSharedPointer<NLPacket> packet, SharedNodePointer sendingNode);
private:
void domainSettingsRequestComplete();
/// adds one stream to the mix for a listening node
int addStreamToMixForListeningNodeWithStream(AudioMixerClientData* listenerNodeData,
const QUuid& streamUUID,

View file

@ -537,7 +537,6 @@ void AvatarMixer::run() {
qDebug() << "Waiting for domain settings from domain-server.";
// block until we get the settingsRequestComplete signal
QEventLoop loop;
connect(&domainHandler, &DomainHandler::settingsReceived, &loop, &QEventLoop::quit);
connect(&domainHandler, &DomainHandler::settingsReceiveFail, &loop, &QEventLoop::quit);

View file

@ -38,12 +38,17 @@ DomainHandler::DomainHandler(QObject* parent) :
_icePeer(this),
_isConnected(false),
_settingsObject(),
_failedSettingsRequests(0)
_settingsTimer(this)
{
_sockAddr.setObjectName("DomainServer");
// if we get a socket that make sure our NetworkPeer ping timer stops
connect(this, &DomainHandler::completedSocketDiscovery, &_icePeer, &NetworkPeer::stopPingTimer);
// setup a timeout for failure on settings requests
static const int DOMAIN_SETTINGS_TIMEOUT_MS = 5000;
_settingsTimer.setInterval(DOMAIN_SETTINGS_TIMEOUT_MS);
connect(&_settingsTimer, &QTimer::timeout, this, &DomainHandler::settingsReceiveFail);
}
void DomainHandler::disconnect() {
@ -80,13 +85,16 @@ void DomainHandler::sendDisconnectPacket() {
void DomainHandler::clearSettings() {
_settingsObject = QJsonObject();
_failedSettingsRequests = 0;
}
void DomainHandler::softReset() {
qCDebug(networking) << "Resetting current domain connection information.";
disconnect();
clearSettings();
// cancel the failure timeout for any pending requests for settings
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::AutoConnection);
}
void DomainHandler::hardReset() {
@ -254,29 +262,29 @@ void DomainHandler::requestDomainSettings() {
_settingsObject = QJsonObject();
emit settingsReceived(_settingsObject);
} else {
if (_settingsObject.isEmpty()) {
qCDebug(networking) << "Requesting settings from domain server";
qCDebug(networking) << "Requesting settings from domain server";
Assignment::Type assignmentType = Assignment::typeForNodeType(DependencyManager::get<NodeList>()->getOwnerType());
Assignment::Type assignmentType = Assignment::typeForNodeType(DependencyManager::get<NodeList>()->getOwnerType());
auto packet = NLPacket::create(PacketType::DomainSettingsRequest, sizeof(assignmentType), true, false);
packet->writePrimitive(assignmentType);
auto packet = NLPacket::create(PacketType::DomainSettingsRequest, sizeof(assignmentType), true, false);
packet->writePrimitive(assignmentType);
auto nodeList = DependencyManager::get<LimitedNodeList>();
nodeList->sendPacket(std::move(packet), _sockAddr);
}
auto nodeList = DependencyManager::get<LimitedNodeList>();
nodeList->sendPacket(std::move(packet), _sockAddr);
_settingsTimer.start();
}
}
void DomainHandler::processSettingsPacketList(QSharedPointer<NLPacketList> packetList) {
// stop our settings timer since we successfully requested the settings we need
_settingsTimer.stop();
auto data = packetList->getMessage();
_settingsObject = QJsonDocument::fromJson(data).object();
qCDebug(networking) << "Received domain settings: \n" << QString(data);
// reset failed settings requests to 0, we got them
_failedSettingsRequests = 0;
qCDebug(networking) << "Received domain settings: \n" << qPrintable(data);
emit settingsReceived(_settingsObject);
}

View file

@ -127,8 +127,8 @@ private:
NetworkPeer _icePeer;
bool _isConnected;
QJsonObject _settingsObject;
int _failedSettingsRequests;
QString _pendingPath;
QTimer _settingsTimer;
};
#endif // hifi_DomainHandler_h

View file

@ -77,6 +77,9 @@ void ThreadedAssignment::commonInit(const QString& targetName, NodeType_t nodeTy
connect(_domainServerTimer, SIGNAL(timeout()), this, SLOT(checkInWithDomainServerOrExit()));
_domainServerTimer->start(DOMAIN_SERVER_CHECK_IN_MSECS);
// send a domain-server check in immediately
checkInWithDomainServerOrExit();
// move the domain server time to the NL so check-ins fire from there
_domainServerTimer->moveToThread(nodeList->thread());
@ -130,3 +133,8 @@ void ThreadedAssignment::checkInWithDomainServerOrExit() {
DependencyManager::get<NodeList>()->sendDomainServerCheckIn();
}
}
void ThreadedAssignment::domainSettingsRequestFailed() {
qDebug() << "Failed to retreive settings object from domain-server. Bailing on assignment.";
setFinished(true);
}

View file

@ -41,6 +41,9 @@ protected:
QTimer* _domainServerTimer = nullptr;
QTimer* _statsTimer = nullptr;
protected slots:
void domainSettingsRequestFailed();
private slots:
void startSendingStats();
void stopSendingStats();