From b028b845f4536af9fe9153f2a148e737b51b1999 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 19 Aug 2014 17:22:05 -0700 Subject: [PATCH] Fox audio recording not being triggerred from JS --- interface/src/Recorder.cpp | 2 ++ interface/src/avatar/MyAvatar.cpp | 48 +++++++++++++++++++++++++++++-- interface/src/avatar/MyAvatar.h | 4 +-- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/interface/src/Recorder.cpp b/interface/src/Recorder.cpp index 52d183332d..d471a021f1 100644 --- a/interface/src/Recorder.cpp +++ b/interface/src/Recorder.cpp @@ -63,6 +63,7 @@ void Recording::addFrame(int timestamp, RecordingFrame &frame) { void Recording::addAudioPacket(QByteArray byteArray) { if (!_audio) { + qDebug() << "Current thread: " << QThread::currentThread(); _audio = new Sound(byteArray); } _audio->append(byteArray); @@ -441,6 +442,7 @@ void writeRecordingToFile(RecordingPointer recording, QString filename) { fileStream << buffer; } + qDebug() << QThread::currentThread(); fileStream << recording->_audio->getByteArray(); qDebug() << "Wrote " << file.size() << " bytes in " << timer.elapsed(); diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index d5dfc4fd50..8e15be8ebe 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -508,34 +508,65 @@ bool MyAvatar::setJointReferential(int id, int jointIndex) { } } QString recordingFile = "recording.rec"; -bool MyAvatar::isRecording() const { +bool MyAvatar::isRecording() { + if (QThread::currentThread() != thread()) { + bool result; + QMetaObject::invokeMethod(this, "isRecording", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, result)); + return result; + } return _recorder && _recorder->isRecording(); } void MyAvatar::startRecording() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "startRecording", Qt::BlockingQueuedConnection); + return; + } if (!_recorder) { _recorder = RecorderPointer(new Recorder(this)); } + Application::getInstance()->getAudio()->setRecorder(_recorder); _recorder->startRecording(); } void MyAvatar::stopRecording() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "stopRecording", Qt::BlockingQueuedConnection); + return; + } if (_recorder) { _recorder->stopRecording(); } } void MyAvatar::saveRecording(QString filename) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "saveRecording", Qt::BlockingQueuedConnection, + Q_ARG(QString, filename)); + return; + } if (_recorder) { _recorder->saveToFile(filename); } } -bool MyAvatar::isPlaying() const { +bool MyAvatar::isPlaying() { + if (QThread::currentThread() != thread()) { + bool result; + QMetaObject::invokeMethod(this, "isPlaying", Qt::BlockingQueuedConnection, + Q_RETURN_ARG(bool, result)); + return result; + } return _player && _player->isPlaying(); } void MyAvatar::loadRecording(QString filename) { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection, + Q_ARG(QString, filename)); + return; + } if (!_player) { _player = PlayerPointer(new Player(this)); } @@ -544,6 +575,10 @@ void MyAvatar::loadRecording(QString filename) { } void MyAvatar::loadLastRecording() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection); + return; + } if (!_recorder) { return; } @@ -555,14 +590,23 @@ void MyAvatar::loadLastRecording() { } void MyAvatar::startPlaying() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection); + return; + } if (!_player) { _player = PlayerPointer(new Player(this)); } + Application::getInstance()->getAudio()->setPlayer(_player); _player->startPlaying(); } void MyAvatar::stopPlaying() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection); + return; + } if (_player) { _player->stopPlaying(); } diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index a298e02229..0af105725b 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -161,12 +161,12 @@ public slots: bool setModelReferential(int id); bool setJointReferential(int id, int jointIndex); - bool isRecording() const; + bool isRecording(); void startRecording(); void stopRecording(); void saveRecording(QString filename); - bool isPlaying() const; + bool isPlaying(); void loadRecording(QString filename); void loadLastRecording(); void startPlaying();