Merge pull request #8302 from davidkelly/dk/hotfixForAudio

Hotfix for RC-16: Audio fix for injectors and Assignment Clients
This commit is contained in:
Chris Collins 2016-07-22 19:11:56 -07:00 committed by GitHub
commit 2c3b25cfa7

View file

@ -203,8 +203,8 @@ bool AudioInjector::injectLocally() {
} }
if (!success) { if (!success) {
// we never started so we are finished, call our stop method // we never started so we are finished with local injection
stop(); finishLocalInjection();
} }
return success; return success;
@ -217,8 +217,15 @@ static const int64_t NEXT_FRAME_DELTA_IMMEDIATELY = 0;
qint64 writeStringToStream(const QString& string, QDataStream& stream) { qint64 writeStringToStream(const QString& string, QDataStream& stream) {
QByteArray data = string.toUtf8(); QByteArray data = string.toUtf8();
uint32_t length = data.length(); uint32_t length = data.length();
stream << static_cast<quint32>(length); if (length == 0) {
stream << data; stream << static_cast<quint32>(length);
} else {
// http://doc.qt.io/qt-5/datastreamformat.html
// QDataStream << QByteArray -
// If the byte array is null : 0xFFFFFFFF (quint32)
// Otherwise : the array size(quint32) followed by the array bytes, i.e.size bytes
stream << data;
}
return length + sizeof(uint32_t); return length + sizeof(uint32_t);
} }
@ -232,7 +239,7 @@ int64_t AudioInjector::injectNextFrame() {
static int positionOptionOffset = -1; static int positionOptionOffset = -1;
static int volumeOptionOffset = -1; static int volumeOptionOffset = -1;
static int audioDataOffset = -1; static int audioDataOffset = -1;
if (!_currentPacket) { if (!_currentPacket) {
if (_currentSendOffset < 0 || if (_currentSendOffset < 0 ||
_currentSendOffset >= _audioData.size()) { _currentSendOffset >= _audioData.size()) {
@ -270,7 +277,7 @@ int64_t AudioInjector::injectNextFrame() {
// current injectors don't use codecs, so pack in the unknown codec name // current injectors don't use codecs, so pack in the unknown codec name
QString noCodecForInjectors(""); QString noCodecForInjectors("");
writeStringToStream(noCodecForInjectors, audioPacketStream); writeStringToStream(noCodecForInjectors, audioPacketStream);
// pack stream identifier (a generated UUID) // pack stream identifier (a generated UUID)
audioPacketStream << QUuid::createUuid(); audioPacketStream << QUuid::createUuid();
@ -301,7 +308,6 @@ int64_t AudioInjector::injectNextFrame() {
volumeOptionOffset = _currentPacket->pos(); volumeOptionOffset = _currentPacket->pos();
quint8 volume = MAX_INJECTOR_VOLUME; quint8 volume = MAX_INJECTOR_VOLUME;
audioPacketStream << volume; audioPacketStream << volume;
audioPacketStream << _options.ignorePenumbra; audioPacketStream << _options.ignorePenumbra;
audioDataOffset = _currentPacket->pos(); audioDataOffset = _currentPacket->pos();
@ -312,7 +318,6 @@ int64_t AudioInjector::injectNextFrame() {
return NEXT_FRAME_DELTA_ERROR_OR_FINISHED; return NEXT_FRAME_DELTA_ERROR_OR_FINISHED;
} }
} }
if (!_frameTimer->isValid()) { if (!_frameTimer->isValid()) {
// in the case where we have been restarted, the frame timer will be invalid and we need to start it back over here // in the case where we have been restarted, the frame timer will be invalid and we need to start it back over here
_frameTimer->restart(); _frameTimer->restart();
@ -418,7 +423,7 @@ void AudioInjector::triggerDeleteAfterFinish() {
return; return;
} }
if (_state == AudioInjectorState::Finished) { if (stateHas(AudioInjectorState::Finished)) {
stopAndDeleteLater(); stopAndDeleteLater();
} else { } else {
_state |= AudioInjectorState::PendingDelete; _state |= AudioInjectorState::PendingDelete;
@ -484,23 +489,17 @@ AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInj
// setup parameters required for injection // setup parameters required for injection
injector->setupInjection(); injector->setupInjection();
// we always inject locally // we always inject locally, except when there is no localInterface
// injector->injectLocally();
if (!injector->injectLocally()) {
// failed, so don't bother sending to server
qDebug() << "AudioInjector::playSound failed to inject locally";
return nullptr;
}
// if localOnly, we are done, just return injector. // if localOnly, we are done, just return injector.
if (options.localOnly) { if (!options.localOnly) {
return injector;
}
// send off to server for everyone else // send off to server for everyone else
if (!injectorManager->threadInjector(injector)) { if (!injectorManager->threadInjector(injector)) {
// we failed to thread the new injector (we are at the max number of injector threads) // we failed to thread the new injector (we are at the max number of injector threads)
qDebug() << "AudioInjector::playSound failed to thread injector"; qDebug() << "AudioInjector::playSound failed to thread injector";
}
} }
return injector; return injector;
} }