bug 1172979 use AutoTArray for AudioChunk::mChannelData to reduce allocations r?padenot
MozReview-Commit-ID: wabk0WlLv5
--- a/dom/media/AudioSegment.h
+++ b/dom/media/AudioSegment.h
@@ -12,16 +12,21 @@
#include "SharedBuffer.h"
#include "WebAudioUtils.h"
#ifdef MOZILLA_INTERNAL_API
#include "mozilla/TimeStamp.h"
#endif
#include <float.h>
namespace mozilla {
+ struct AudioChunk;
+}
+DECLARE_USE_COPY_CONSTRUCTORS(mozilla::AudioChunk)
+
+namespace mozilla {
template<typename T>
class SharedChannelArrayBuffer : public ThreadSharedObject {
public:
explicit SharedChannelArrayBuffer(nsTArray<nsTArray<T> >* aBuffers)
{
mBuffers.SwapElements(*aBuffers);
}
@@ -219,24 +224,26 @@ struct AudioChunk {
amount += mChannelData.ShallowSizeOfExcludingThis(aMallocSizeOf);
return amount;
}
template<typename T>
const nsTArray<const T*>& ChannelData() const
{
MOZ_ASSERT(AudioSampleTypeToFormat<T>::Format == mBufferFormat);
- return *reinterpret_cast<const nsTArray<const T*>*>(&mChannelData);
+ return *reinterpret_cast<const AutoTArray<const T*,GUESS_AUDIO_CHANNELS>*>
+ (&mChannelData);
}
PrincipalHandle GetPrincipalHandle() const { return mPrincipalHandle; }
StreamTime mDuration; // in frames within the buffer
RefPtr<ThreadSharedObject> mBuffer; // the buffer object whose lifetime is managed; null means data is all zeroes
- nsTArray<const void*> mChannelData; // one pointer per channel; empty if and only if mBuffer is null
+ // one pointer per channel; empty if and only if mBuffer is null
+ AutoTArray<const void*,GUESS_AUDIO_CHANNELS> mChannelData;
float mVolume; // volume multiplier to apply (1.0f if mBuffer is nonnull)
SampleFormat mBufferFormat; // format of frames in mBuffer (only meaningful if mBuffer is nonnull)
#ifdef MOZILLA_INTERNAL_API
mozilla::TimeStamp mTimeStamp; // time at which this has been fetched from the MediaEngine
#endif
// principalHandle for the data in this chunk.
// This can be compared to an nsIPrincipal* when back on main thread.
PrincipalHandle mPrincipalHandle;
--- a/dom/media/webaudio/AudioBlock.h
+++ b/dom/media/webaudio/AudioBlock.h
@@ -128,9 +128,11 @@ private:
// reference does not prevent the upstream node from re-using the buffer next
// iteration and modifying its contents. The AudioBlockBuffer is also
// notified when mBuffer releases this reference.
bool mBufferIsDownstreamRef = false;
};
} // namespace mozilla
+DECLARE_USE_COPY_CONSTRUCTORS(mozilla::AudioBlock)
+
#endif // MOZILLA_AUDIOBLOCK_H_