Fox audio recording not being triggerred from JS

This commit is contained in:
Atlante45 2014-08-19 17:22:05 -07:00
parent b13604f968
commit b028b845f4
3 changed files with 50 additions and 4 deletions

View file

@ -63,6 +63,7 @@ void Recording::addFrame(int timestamp, RecordingFrame &frame) {
void Recording::addAudioPacket(QByteArray byteArray) { void Recording::addAudioPacket(QByteArray byteArray) {
if (!_audio) { if (!_audio) {
qDebug() << "Current thread: " << QThread::currentThread();
_audio = new Sound(byteArray); _audio = new Sound(byteArray);
} }
_audio->append(byteArray); _audio->append(byteArray);
@ -441,6 +442,7 @@ void writeRecordingToFile(RecordingPointer recording, QString filename) {
fileStream << buffer; fileStream << buffer;
} }
qDebug() << QThread::currentThread();
fileStream << recording->_audio->getByteArray(); fileStream << recording->_audio->getByteArray();
qDebug() << "Wrote " << file.size() << " bytes in " << timer.elapsed(); qDebug() << "Wrote " << file.size() << " bytes in " << timer.elapsed();

View file

@ -508,34 +508,65 @@ bool MyAvatar::setJointReferential(int id, int jointIndex) {
} }
} }
QString recordingFile = "recording.rec"; 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(); return _recorder && _recorder->isRecording();
} }
void MyAvatar::startRecording() { void MyAvatar::startRecording() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "startRecording", Qt::BlockingQueuedConnection);
return;
}
if (!_recorder) { if (!_recorder) {
_recorder = RecorderPointer(new Recorder(this)); _recorder = RecorderPointer(new Recorder(this));
} }
Application::getInstance()->getAudio()->setRecorder(_recorder);
_recorder->startRecording(); _recorder->startRecording();
} }
void MyAvatar::stopRecording() { void MyAvatar::stopRecording() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "stopRecording", Qt::BlockingQueuedConnection);
return;
}
if (_recorder) { if (_recorder) {
_recorder->stopRecording(); _recorder->stopRecording();
} }
} }
void MyAvatar::saveRecording(QString filename) { void MyAvatar::saveRecording(QString filename) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "saveRecording", Qt::BlockingQueuedConnection,
Q_ARG(QString, filename));
return;
}
if (_recorder) { if (_recorder) {
_recorder->saveToFile(filename); _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(); return _player && _player->isPlaying();
} }
void MyAvatar::loadRecording(QString filename) { void MyAvatar::loadRecording(QString filename) {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "loadRecording", Qt::BlockingQueuedConnection,
Q_ARG(QString, filename));
return;
}
if (!_player) { if (!_player) {
_player = PlayerPointer(new Player(this)); _player = PlayerPointer(new Player(this));
} }
@ -544,6 +575,10 @@ void MyAvatar::loadRecording(QString filename) {
} }
void MyAvatar::loadLastRecording() { void MyAvatar::loadLastRecording() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection);
return;
}
if (!_recorder) { if (!_recorder) {
return; return;
} }
@ -555,14 +590,23 @@ void MyAvatar::loadLastRecording() {
} }
void MyAvatar::startPlaying() { void MyAvatar::startPlaying() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "startPlaying", Qt::BlockingQueuedConnection);
return;
}
if (!_player) { if (!_player) {
_player = PlayerPointer(new Player(this)); _player = PlayerPointer(new Player(this));
} }
Application::getInstance()->getAudio()->setPlayer(_player);
_player->startPlaying(); _player->startPlaying();
} }
void MyAvatar::stopPlaying() { void MyAvatar::stopPlaying() {
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "stopPlaying", Qt::BlockingQueuedConnection);
return;
}
if (_player) { if (_player) {
_player->stopPlaying(); _player->stopPlaying();
} }

View file

@ -161,12 +161,12 @@ public slots:
bool setModelReferential(int id); bool setModelReferential(int id);
bool setJointReferential(int id, int jointIndex); bool setJointReferential(int id, int jointIndex);
bool isRecording() const; bool isRecording();
void startRecording(); void startRecording();
void stopRecording(); void stopRecording();
void saveRecording(QString filename); void saveRecording(QString filename);
bool isPlaying() const; bool isPlaying();
void loadRecording(QString filename); void loadRecording(QString filename);
void loadLastRecording(); void loadLastRecording();
void startPlaying(); void startPlaying();