fix audio cleanup and close action in Application

This commit is contained in:
Stephen Birarda 2015-02-12 13:35:22 -08:00
parent ff6f8ea4a1
commit 6c25205856
5 changed files with 28 additions and 25 deletions

View file

@ -71,6 +71,10 @@ void RenderingClient::sendAvatarPacket() {
}
void RenderingClient::cleanupBeforeQuit() {
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
// destroy the AudioClient so it and it's thread will safely go down
DependencyManager::destroy<AudioClient>();
}

View file

@ -328,7 +328,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
connect(&nodeList->getNodeSocket(), SIGNAL(readyRead()), &_datagramProcessor, SLOT(processDatagrams()));
// put the audio processing on a separate thread
QThread* audioThread = new QThread(this);
QThread* audioThread = new QThread();
audioThread->setObjectName("Audio Thread");
auto audioIO = DependencyManager::get<AudioClient>();
@ -338,7 +338,9 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
audioIO->moveToThread(audioThread);
connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start);
connect(audioIO.data(), SIGNAL(muteToggled()), this, SLOT(audioMuteToggled()));
connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit);
connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
connect(audioIO.data(), &AudioClient::muteToggled, this, &Application::audioMuteToggled);
audioThread->start();
@ -516,21 +518,33 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
void Application::aboutToQuit() {
_aboutToQuit = true;
cleanupBeforeQuit();
}
Application::~Application() {
void Application::cleanupBeforeQuit() {
QMetaObject::invokeMethod(&_settingsTimer, "stop", Qt::BlockingQueuedConnection);
_settingsThread.quit();
saveSettings();
// TODO: now that this is in cleanupBeforeQuit do we really need it to stop and force
// an event loop to send the packet?
UserActivityLogger::getInstance().close();
// stop the AudioClient
QMetaObject::invokeMethod(DependencyManager::get<AudioClient>().data(),
"stop", Qt::BlockingQueuedConnection);
// destroy the AudioClient so it and its thread have a chance to go down safely
DependencyManager::destroy<AudioClient>();
}
Application::~Application() {
_entities.getTree()->setSimulation(NULL);
qInstallMessageHandler(NULL);
_window->saveGeometry();
int DELAY_TIME = 1000;
UserActivityLogger::getInstance().close(DELAY_TIME);
// make sure we don't call the idle timer any more
delete idleTimer;
@ -541,15 +555,6 @@ Application::~Application() {
_nodeThread->quit();
_nodeThread->wait();
auto audioIO = DependencyManager::get<AudioClient>();
// stop the audio process
QMetaObject::invokeMethod(audioIO.data(), "stop", Qt::BlockingQueuedConnection);
// ask the audio thread to quit and wait until it is done
audioIO->thread()->quit();
audioIO->thread()->wait();
_octreeProcessor.terminate();
_entityEditSender.terminate();

View file

@ -410,6 +410,8 @@ private:
void initDisplay();
void init();
void cleanupBeforeQuit();
void update(float deltaTime);

View file

@ -86,17 +86,9 @@ void UserActivityLogger::launch(QString applicationVersion) {
logAction(ACTION_NAME, actionDetails);
}
void UserActivityLogger::close(int delayTime) {
void UserActivityLogger::close() {
const QString ACTION_NAME = "close";
// In order to get the end of the session, we need to give the account manager enough time to send the packet.
QEventLoop loop;
QTimer timer;
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// Now we can log it
logAction(ACTION_NAME, QJsonObject());
timer.start(delayTime);
loop.exec();
}
void UserActivityLogger::changedDisplayName(QString displayName) {

View file

@ -30,7 +30,7 @@ public slots:
void logAction(QString action, QJsonObject details = QJsonObject(), JSONCallbackParameters params = JSONCallbackParameters());
void launch(QString applicationVersion);
void close(int delayTime);
void close();
void changedDisplayName(QString displayName);
void changedModel(QString typeOfModel, QString modelURL);
void changedDomain(QString domainURL);