Merge pull request #3297 from Atlante45/record_feature

couple fixes
This commit is contained in:
Philip Rosedale 2014-08-18 21:29:05 -07:00
commit f2069ba7d7
5 changed files with 37 additions and 11 deletions

View file

@ -182,7 +182,7 @@ qint64 Player::elapsed() const {
}
glm::quat Player::getHeadRotation() {
if (computeCurrentFrame()) {
if (!computeCurrentFrame()) {
qWarning() << "Incorrect use of Player::getHeadRotation()";
return glm::quat();
}
@ -195,7 +195,7 @@ glm::quat Player::getHeadRotation() {
}
float Player::getLeanSideways() {
if (computeCurrentFrame()) {
if (!computeCurrentFrame()) {
qWarning() << "Incorrect use of Player::getLeanSideways()";
return 0.0f;
}
@ -204,7 +204,7 @@ float Player::getLeanSideways() {
}
float Player::getLeanForward() {
if (computeCurrentFrame()) {
if (!computeCurrentFrame()) {
qWarning() << "Incorrect use of Player::getLeanForward()";
return 0.0f;
}
@ -216,13 +216,16 @@ void Player::startPlaying() {
if (_recording && _recording->getFrameNumber() > 0) {
qDebug() << "Recorder::startPlaying()";
_currentFrame = 0;
// Setup audio thread
_audioThread = new QThread();
_options.setPosition(_avatar->getPosition());
_options.setOrientation(_avatar->getOrientation());
_injector.reset(new AudioInjector(_recording->getAudio(), _options));
_audioThread = new QThread();
_injector.reset(new AudioInjector(_recording->getAudio(), _options), &QObject::deleteLater);
_injector->moveToThread(_audioThread);
_audioThread->start();
QMetaObject::invokeMethod(_injector.data(), "injectAudio", Qt::QueuedConnection);
_timer.start();
}
}
@ -232,7 +235,6 @@ void Player::stopPlaying() {
return;
}
qDebug() << "Recorder::stopPlaying()";
_timer.invalidate();
_avatar->clearJointsData();
@ -242,6 +244,7 @@ void Player::stopPlaying() {
_injector.clear();
_audioThread->exit();
_audioThread->deleteLater();
qDebug() << "Recorder::stopPlaying()";
}
void Player::loadFromFile(QString file) {
@ -259,7 +262,7 @@ void Player::loadRecording(RecordingPointer recording) {
void Player::play() {
computeCurrentFrame();
if (_currentFrame < 0 || _currentFrame >= _recording->getFrameNumber()) {
if (_currentFrame < 0 || _currentFrame >= _recording->getFrameNumber() - 1) {
// If it's the end of the recording, stop playing
stopPlaying();
return;
@ -283,6 +286,10 @@ void Player::play() {
HeadData* head = const_cast<HeadData*>(_avatar->getHeadData());
head->setBlendshapeCoefficients(_recording->getFrame(_currentFrame).getBlendshapeCoefficients());
}
_options.setPosition(_avatar->getPosition());
_options.setOrientation(_avatar->getOrientation());
_injector->setOptions(_options);
}
bool Player::computeCurrentFrame() {
@ -294,7 +301,7 @@ bool Player::computeCurrentFrame() {
_currentFrame = 0;
}
while (_currentFrame < _recording->getFrameNumber() &&
while (_currentFrame < _recording->getFrameNumber() - 1 &&
_recording->getFrameTimestamp(_currentFrame) < _timer.elapsed()) {
++_currentFrame;
}

View file

@ -27,7 +27,6 @@ AudioInjector::AudioInjector(QObject* parent) :
_options(),
_shouldStop(false)
{
}
AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorOptions) :
@ -35,7 +34,10 @@ AudioInjector::AudioInjector(Sound* sound, const AudioInjectorOptions& injectorO
_options(injectorOptions),
_shouldStop(false)
{
}
void AudioInjector::setOptions(AudioInjectorOptions& options) {
_options = options;
}
const uchar MAX_INJECTOR_VOLUME = 0xFF;
@ -73,9 +75,11 @@ void AudioInjector::injectAudio() {
packetStream << loopbackFlag;
// pack the position for injected audio
int positionOptionOffset = injectAudioPacket.size();
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.getPosition()), sizeof(_options.getPosition()));
// pack our orientation for injected audio
int orientationOptionOffset = injectAudioPacket.size();
packetStream.writeRawData(reinterpret_cast<const char*>(&_options.getOrientation()), sizeof(_options.getOrientation()));
// pack zero for radius
@ -101,6 +105,12 @@ void AudioInjector::injectAudio() {
int bytesToCopy = std::min(NETWORK_BUFFER_LENGTH_BYTES_PER_CHANNEL,
soundByteArray.size() - currentSendPosition);
memcpy(injectAudioPacket.data() + positionOptionOffset,
&_options.getPosition(),
sizeof(_options.getPosition()));
memcpy(injectAudioPacket.data() + orientationOptionOffset,
&_options.getOrientation(),
sizeof(_options.getOrientation()));
// resize the QByteArray to the right size
injectAudioPacket.resize(numPreAudioDataBytes + bytesToCopy);

View file

@ -29,6 +29,7 @@ public:
public slots:
void injectAudio();
void stop() { _shouldStop = true; }
void setOptions(AudioInjectorOptions& options);
signals:
void finished();
private:

View file

@ -19,7 +19,6 @@ AudioInjectorOptions::AudioInjectorOptions(QObject* parent) :
_orientation(glm::vec3(0.0f, 0.0f, 0.0f)),
_loopbackAudioInterface(NULL)
{
}
AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
@ -29,3 +28,11 @@ AudioInjectorOptions::AudioInjectorOptions(const AudioInjectorOptions& other) {
_orientation = other._orientation;
_loopbackAudioInterface = other._loopbackAudioInterface;
}
void AudioInjectorOptions::operator=(const AudioInjectorOptions& other) {
_position = other._position;
_volume = other._volume;
_loop = other._loop;
_orientation = other._orientation;
_loopbackAudioInterface = other._loopbackAudioInterface;
}

View file

@ -30,6 +30,7 @@ class AudioInjectorOptions : public QObject {
public:
AudioInjectorOptions(QObject* parent = 0);
AudioInjectorOptions(const AudioInjectorOptions& other);
void operator=(const AudioInjectorOptions& other);
const glm::vec3& getPosition() const { return _position; }
void setPosition(const glm::vec3& position) { _position = position; }