bug 1199561 delay offline buffer allocation until non-null input is received r=padenot

The avoids the allocation and copying altogether when the output buffer
is silent.

--HG--
extra : rebase_source : f225628dc9bb2ea0cd0ec414a2212e39da92405f
This commit is contained in:
Karl Tomlinson 2015-08-24 19:34:15 +12:00
Родитель b8ba84787a
Коммит 605cd07259
1 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -54,18 +54,26 @@ public:
// will not go anywhere.
*aOutput = aInput;
// The output buffer is allocated lazily, on the rendering thread.
if (!mBufferAllocated) {
// The output buffer is allocated lazily, on the rendering thread, when
// non-null input is received.
if (!mBufferAllocated && !aInput.IsNull()) {
// These allocations might fail if content provides a huge number of
// channels or size, but it's OK since we'll deal with the failure
// gracefully.
mBuffer = ThreadSharedFloatArrayBufferList::
Create(mNumberOfChannels, mLength, fallible);
if (mBuffer && mWriteIndex) {
// Zero leading for any null chunks that were skipped.
for (uint32_t i = 0; i < mNumberOfChannels; ++i) {
float* channelData = mBuffer->GetDataForWrite(i);
PodZero(channelData, mWriteIndex);
}
}
mBufferAllocated = true;
}
// Handle the case of allocation failure in the input buffer
// Skip copying if there is no buffer.
uint32_t outputChannelCount = mBuffer ? mNumberOfChannels : 0;
// Record our input buffer