Merge pull request #6958 from huffman/injector-timing-fixes

Fix injector looping issues when using audio that isn't a multiple of the sample size
This commit is contained in:
Stephen Birarda 2016-01-27 14:29:30 -08:00
commit f3903022f2

View file

@ -181,6 +181,15 @@ int64_t AudioInjector::injectNextFrame() {
// make sure we actually have samples downloaded to inject
if (_audioData.size()) {
int sampleSize = (_options.stereo ? 2 : 1) * sizeof(AudioConstants::AudioSample);
auto numSamples = static_cast<int>(_audioData.size() / sampleSize);
auto targetSize = numSamples * sampleSize;
if (targetSize != _audioData.size()) {
qDebug() << "Resizing audio that doesn't end at multiple of sample size, resizing from "
<< _audioData.size() << " to " << targetSize;
_audioData.resize(targetSize);
}
_outgoingSequenceNumber = 0;
_nextFrame = 0;
@ -272,7 +281,7 @@ int64_t AudioInjector::injectNextFrame() {
_currentPacket->write(_audioData.data() + _currentSendOffset, bytesToCopy);
_currentSendOffset += bytesToCopy;
totalBytesLeftToCopy -= bytesToCopy;
if (_currentSendOffset >= _audioData.size()) {
if (_options.loop && _currentSendOffset >= _audioData.size()) {
_currentSendOffset = 0;
}
}