diff --git a/dom/media/AudioStream.h b/dom/media/AudioStream.h index dc84feaf63bd..f9dce5fb6a6a 100644 --- a/dom/media/AudioStream.h +++ b/dom/media/AudioStream.h @@ -88,7 +88,7 @@ public: void SetCapacity(uint32_t aCapacity) { MOZ_ASSERT(!mBuffer, "Buffer allocated."); mCapacity = aCapacity; - mBuffer = new uint8_t[mCapacity]; + mBuffer = MakeUnique(mCapacity); } uint32_t Length() { @@ -137,12 +137,12 @@ public: size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const { size_t amount = 0; - amount += mBuffer.SizeOfExcludingThis(aMallocSizeOf); + amount += aMallocSizeOf(mBuffer.get()); return amount; } private: - nsAutoArrayPtr mBuffer; + UniquePtr mBuffer; uint32_t mCapacity; uint32_t mStart; uint32_t mCount; diff --git a/dom/media/FileBlockCache.h b/dom/media/FileBlockCache.h index e16fa7592fa0..a32bfb638a2d 100644 --- a/dom/media/FileBlockCache.h +++ b/dom/media/FileBlockCache.h @@ -9,6 +9,7 @@ #include "mozilla/Attributes.h" #include "mozilla/Monitor.h" +#include "mozilla/UniquePtr.h" #include "nsTArray.h" #include "MediaCache.h" #include "nsDeque.h" @@ -96,7 +97,7 @@ public: explicit BlockChange(const uint8_t* aData) : mSourceBlockIndex(-1) { - mData = new uint8_t[BLOCK_SIZE]; + mData = MakeUnique(BLOCK_SIZE); memcpy(mData.get(), aData, BLOCK_SIZE); } @@ -105,7 +106,7 @@ public: explicit BlockChange(int32_t aSourceBlockIndex) : mSourceBlockIndex(aSourceBlockIndex) {} - nsAutoArrayPtr mData; + UniquePtr mData; const int32_t mSourceBlockIndex; bool IsMove() const { diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index e42a236f8cd5..a9c76e7621b5 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -379,7 +379,7 @@ MediaCacheStream::MediaCacheStream(ChannelMediaResource* aClient) mPinCount(0), mCurrentMode(MODE_PLAYBACK), mMetadataInPartialBlockBuffer(false), - mPartialBlockBuffer(new int64_t[BLOCK_SIZE/sizeof(int64_t)]) + mPartialBlockBuffer(MakeUnique(BLOCK_SIZE/sizeof(int64_t))) { } @@ -393,7 +393,7 @@ size_t MediaCacheStream::SizeOfExcludingThis( size += mReadaheadBlocks.SizeOfExcludingThis(aMallocSizeOf); size += mMetadataBlocks.SizeOfExcludingThis(aMallocSizeOf); size += mPlayedBlocks.SizeOfExcludingThis(aMallocSizeOf); - size += mPartialBlockBuffer.SizeOfExcludingThis(aMallocSizeOf); + size += aMallocSizeOf(mPartialBlockBuffer.get()); return size; } @@ -1842,7 +1842,7 @@ MediaCacheStream::FlushPartialBlockInternal(bool aNotifyAll, // Write back the partial block memset(reinterpret_cast(mPartialBlockBuffer.get()) + blockOffset, 0, BLOCK_SIZE - blockOffset); - gMediaCache->AllocateAndWriteBlock(this, mPartialBlockBuffer, + gMediaCache->AllocateAndWriteBlock(this, mPartialBlockBuffer.get(), mMetadataInPartialBlockBuffer ? MODE_METADATA : MODE_PLAYBACK); } diff --git a/dom/media/MediaCache.h b/dom/media/MediaCache.h index 0c49986f39e8..68a82f1caf78 100644 --- a/dom/media/MediaCache.h +++ b/dom/media/MediaCache.h @@ -12,6 +12,7 @@ #include "nsHashKeys.h" #include "nsTHashtable.h" #include "Intervals.h" +#include "mozilla/UniquePtr.h" class nsIPrincipal; @@ -510,7 +511,7 @@ private: // Use int64_t so that the data is well-aligned. // Heap allocate this buffer since the exact power-of-2 will cause allocation // slop when combined with the rest of the object members. - nsAutoArrayPtr mPartialBlockBuffer; + UniquePtr mPartialBlockBuffer; }; } // namespace mozilla diff --git a/dom/media/MediaData.cpp b/dom/media/MediaData.cpp index 9635190f6e26..d2f9cc06e283 100644 --- a/dom/media/MediaData.cpp +++ b/dom/media/MediaData.cpp @@ -12,6 +12,7 @@ #endif #include "VideoUtils.h" #include "ImageContainer.h" +#include "mozilla/UniquePtrExtensions.h" #ifdef MOZ_WIDGET_GONK #include @@ -533,8 +534,7 @@ MediaRawData::EnsureCapacity(size_t aSize) if (mData && mCapacity >= sizeNeeded) { return true; } - nsAutoArrayPtr newBuffer; - newBuffer = new (fallible) uint8_t[sizeNeeded]; + auto newBuffer = MakeUniqueFallible(sizeNeeded); if (!newBuffer) { return false; } @@ -546,7 +546,7 @@ MediaRawData::EnsureCapacity(size_t aSize) MOZ_ASSERT(uintptr_t(newData) % (RAW_DATA_ALIGNMENT+1) == 0); memcpy(newData, mData, mSize); - mBuffer = newBuffer.forget(); + mBuffer = Move(newBuffer); mCapacity = sizeNeeded; mData = newData; diff --git a/dom/media/MediaData.h b/dom/media/MediaData.h index 6dc4f2ef61d7..50f67418494a 100644 --- a/dom/media/MediaData.h +++ b/dom/media/MediaData.h @@ -425,7 +425,7 @@ private: bool EnsureCapacity(size_t aSize); uint8_t* mData; size_t mSize; - nsAutoArrayPtr mBuffer; + UniquePtr mBuffer; uint32_t mCapacity; CryptoSample mCryptoInternal; MediaRawData(const MediaRawData&); // Not implemented diff --git a/dom/media/RtspMediaResource.cpp b/dom/media/RtspMediaResource.cpp index 0c6eddae9d34..18f48f2262e6 100644 --- a/dom/media/RtspMediaResource.cpp +++ b/dom/media/RtspMediaResource.cpp @@ -12,6 +12,7 @@ #include "mozilla/dom/HTMLMediaElement.h" #include "mozilla/Monitor.h" #include "mozilla/Preferences.h" +#include "mozilla/UniquePtr.h" #include "nsIScriptSecurityManager.h" #include "nsIStreamingProtocolService.h" #include "nsServiceManagerUtils.h" @@ -72,7 +73,7 @@ public: MOZ_COUNT_CTOR(RtspTrackBuffer); mTrackIdx = aTrackIdx; MOZ_ASSERT(mSlotSize < UINT32_MAX / BUFFER_SLOT_NUM); - mRingBuffer = new uint8_t[mTotalBufferSize]; + mRingBuffer = MakeUnique(mTotalBufferSize); Reset(); }; ~RtspTrackBuffer() { @@ -85,7 +86,7 @@ public: size_t size = aMallocSizeOf(this); // excluding this - size += mRingBuffer.SizeOfExcludingThis(aMallocSizeOf); + size += aMallocSizeOf(mRingBuffer.get()); return size; } @@ -179,7 +180,7 @@ private: BufferSlotData mBufferSlotData[BUFFER_SLOT_NUM]; // The ring buffer pointer. - nsAutoArrayPtr mRingBuffer; + UniquePtr mRingBuffer; // Each slot's size. uint32_t mSlotSize; // Total mRingBuffer's total size. diff --git a/dom/media/VideoSegment.cpp b/dom/media/VideoSegment.cpp index 1d97cefa75ca..551ecf7a9ca6 100644 --- a/dom/media/VideoSegment.cpp +++ b/dom/media/VideoSegment.cpp @@ -68,7 +68,7 @@ VideoFrame::CreateBlackImage(const gfx::IntSize& aSize) data.mYSize = gfx::IntSize(aSize.width, aSize.height); data.mYStride = (int32_t) (aSize.width * lumaBpp / 8.0); data.mCbCrStride = (int32_t) (aSize.width * chromaBpp / 8.0); - data.mCbChannel = frame.rwget() + aSize.height * data.mYStride; + data.mCbChannel = frame.get() + aSize.height * data.mYStride; data.mCrChannel = data.mCbChannel + aSize.height * data.mCbCrStride / 2; data.mCbCrSize = gfx::IntSize(aSize.width / 2, aSize.height / 2); data.mPicX = 0; diff --git a/dom/media/android/AndroidMediaResourceServer.cpp b/dom/media/android/AndroidMediaResourceServer.cpp index dd4f0a70f671..209844c0e82b 100644 --- a/dom/media/android/AndroidMediaResourceServer.cpp +++ b/dom/media/android/AndroidMediaResourceServer.cpp @@ -6,6 +6,7 @@ #include "mozilla/Assertions.h" #include "mozilla/Base64.h" #include "mozilla/IntegerPrintfMacros.h" +#include "mozilla/UniquePtr.h" #include "nsThreadUtils.h" #include "nsIServiceManager.h" #include "nsISocketTransport.h" @@ -263,7 +264,7 @@ ServeResourceEvent::Run() { // HTTP response headers sent below. A static_assert ensures // this where the buffer is used. const int buffer_size = 32768; - nsAutoArrayPtr b(new char[buffer_size]); + auto b = MakeUnique(buffer_size); // If we know the length of the resource, send a Content-Length header. int64_t contentlength = resource->GetLength() - start; @@ -271,8 +272,8 @@ ServeResourceEvent::Run() { static_assert (buffer_size > 1024, "buffer_size must be large enough " "to hold response headers"); - snprintf(b, buffer_size, "Content-Length: %" PRId64 "\r\n", contentlength); - rv = WriteAll(b, strlen(b)); + snprintf(b.get(), buffer_size, "Content-Length: %" PRId64 "\r\n", contentlength); + rv = WriteAll(b.get(), strlen(b.get())); if (NS_FAILED(rv)) { Shutdown(); return NS_OK; } } @@ -282,10 +283,10 @@ ServeResourceEvent::Run() { static_assert (buffer_size > 1024, "buffer_size must be large enough " "to hold response headers"); - snprintf(b, buffer_size, "Content-Range: " + snprintf(b.get(), buffer_size, "Content-Range: " "bytes %" PRId64 "-%" PRId64 "/%" PRId64 "\r\n", start, resource->GetLength() - 1, resource->GetLength()); - rv = WriteAll(b, strlen(b)); + rv = WriteAll(b.get(), strlen(b.get())); if (NS_FAILED(rv)) { Shutdown(); return NS_OK; } } @@ -297,7 +298,7 @@ ServeResourceEvent::Run() { // Read data from media resource uint32_t bytesRead = 0; // Number of bytes read/written to streams - rv = resource->ReadAt(start, b, buffer_size, &bytesRead); + rv = resource->ReadAt(start, b.get(), buffer_size, &bytesRead); while (NS_SUCCEEDED(rv) && bytesRead != 0) { // Keep track of what we think the starting position for the next read // is. This is used in subsequent ReadAt calls to ensure we are reading @@ -306,10 +307,10 @@ ServeResourceEvent::Run() { start += bytesRead; // Write data obtained from media resource to output stream - rv = WriteAll(b, bytesRead); + rv = WriteAll(b.get(), bytesRead); if (NS_FAILED (rv)) break; - rv = resource->ReadAt(start, b, 32768, &bytesRead); + rv = resource->ReadAt(start, b.get(), 32768, &bytesRead); } Shutdown(); diff --git a/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.cpp b/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.cpp index 79ad83caae21..cf3f36b40377 100644 --- a/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.cpp +++ b/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.cpp @@ -127,7 +127,7 @@ TrackRunBox::fillSampleTable() return 0; } uint32_t len = frames.Length(); - sample_info_table = new tbl[len]; + sample_info_table = MakeUnique(len); // Create sample table according to 14496-12 8.8.8.2. for (uint32_t i = 0; i < len; i++) { // Sample size. diff --git a/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.h b/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.h index 635f7b6d3101..a6dc1b0468d4 100644 --- a/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.h +++ b/dom/media/encoder/fmp4_muxer/ISOMediaBoxes.h @@ -11,6 +11,7 @@ #include "nsTArray.h" #include "nsAutoPtr.h" #include "MuxerOperation.h" +#include "mozilla/UniquePtr.h" #define WRITE_FULLBOX(_compositor, _size) \ BoxSizeChecker checker(_compositor, _size); \ @@ -262,7 +263,7 @@ public: // the following are optional fields uint32_t data_offset; // data offset exists when audio/video are present in file. uint32_t first_sample_flags; - nsAutoArrayPtr sample_info_table; + UniquePtr sample_info_table; // MuxerOperation methods nsresult Generate(uint32_t* aBoxSize) override; @@ -404,7 +405,7 @@ public: } tbl; uint32_t entry_count; - nsAutoArrayPtr sample_tbl; + UniquePtr sample_tbl; // MuxerOperation methods nsresult Generate(uint32_t* aBoxSize) override; @@ -430,7 +431,7 @@ public: } tbl; uint32_t entry_count; - nsAutoArrayPtr sample_tbl; + UniquePtr sample_tbl; // MuxerOperation methods nsresult Generate(uint32_t* aBoxSize) override; @@ -455,7 +456,7 @@ public: } tbl; uint32_t entry_count; - nsAutoArrayPtr sample_tbl; + UniquePtr sample_tbl; // MuxerOperation methods nsresult Generate(uint32_t* aBoxSize) override; diff --git a/dom/media/fmp4/MP4Stream.cpp b/dom/media/fmp4/MP4Stream.cpp index 20c0c6af8b2a..615a7dc01529 100644 --- a/dom/media/fmp4/MP4Stream.cpp +++ b/dom/media/fmp4/MP4Stream.cpp @@ -44,7 +44,7 @@ MP4Stream::BlockingReadIntoCache(int64_t aOffset, size_t aCount, Monitor* aToUnl MOZ_ASSERT(block.mCount >= bytesRead); block.mCount = bytesRead; - mCache.AppendElement(block); + mCache.AppendElement(Move(block)); return true; } diff --git a/dom/media/fmp4/MP4Stream.h b/dom/media/fmp4/MP4Stream.h index b5d0f562a889..22a7faf89acd 100644 --- a/dom/media/fmp4/MP4Stream.h +++ b/dom/media/fmp4/MP4Stream.h @@ -13,6 +13,7 @@ #include "mozilla/Maybe.h" #include "mozilla/Monitor.h" +#include "mozilla/UniquePtrExtensions.h" namespace mozilla { @@ -74,9 +75,15 @@ private: int64_t mOffset; size_t mCount; + CacheBlock(CacheBlock&& aOther) + : mOffset(aOther.mOffset) + , mCount(aOther.mCount) + , mBuffer(Move(aOther.mBuffer)) + {} + bool Init() { - mBuffer = new (fallible) char[mCount]; + mBuffer = MakeUniqueFallible(mCount); return !!mBuffer; } @@ -87,7 +94,10 @@ private: } private: - nsAutoArrayPtr mBuffer; + CacheBlock(const CacheBlock&) = delete; + CacheBlock& operator=(const CacheBlock&) = delete; + + UniquePtr mBuffer; }; nsTArray mCache; }; diff --git a/dom/media/gmp/GMPLoader.cpp b/dom/media/gmp/GMPLoader.cpp index 99282ba23634..c6a93a7a4c94 100644 --- a/dom/media/gmp/GMPLoader.cpp +++ b/dom/media/gmp/GMPLoader.cpp @@ -7,6 +7,7 @@ #include "GMPLoader.h" #include #include "mozilla/Attributes.h" +#include "mozilla/UniquePtr.h" #include "gmp-entrypoints.h" #include "prlink.h" #include "prenv.h" @@ -247,12 +248,12 @@ GMPLoaderImpl::Load(const char* aUTF8LibPath, return false; } - nsAutoArrayPtr widePath(new wchar_t[pathLen]); - if (MultiByteToWideChar(CP_UTF8, 0, aUTF8LibPath, -1, widePath, pathLen) == 0) { + auto widePath = MakeUnique(pathLen); + if (MultiByteToWideChar(CP_UTF8, 0, aUTF8LibPath, -1, widePath.get(), pathLen) == 0) { return false; } - libSpec.value.pathname_u = widePath; + libSpec.value.pathname_u = widePath.get(); libSpec.type = PR_LibSpec_PathnameU; #else libSpec.value.pathname = aUTF8LibPath; diff --git a/dom/media/platforms/agnostic/BlankDecoderModule.cpp b/dom/media/platforms/agnostic/BlankDecoderModule.cpp index 51323ec2506f..ed5d0d13ae3e 100644 --- a/dom/media/platforms/agnostic/BlankDecoderModule.cpp +++ b/dom/media/platforms/agnostic/BlankDecoderModule.cpp @@ -11,6 +11,7 @@ #include "mozilla/mozalloc.h" // for operator new, and new (fallible) #include "mozilla/RefPtr.h" #include "mozilla/TaskQueue.h" +#include "mozilla/UniquePtr.h" #include "nsRect.h" #include "PlatformDecoderModule.h" #include "TimeUnits.h" @@ -118,12 +119,12 @@ public: // with a U and V plane that are half the size of the Y plane, i.e 8 bit, // 2x2 subsampled. Have the data pointers of each frame point to the // first plane, they'll always be zero'd memory anyway. - nsAutoArrayPtr frame(new uint8_t[mFrameWidth * mFrameHeight]); - memset(frame, 0, mFrameWidth * mFrameHeight); + auto frame = MakeUnique(mFrameWidth * mFrameHeight); + memset(frame.get(), 0, mFrameWidth * mFrameHeight); VideoData::YCbCrBuffer buffer; // Y plane. - buffer.mPlanes[0].mData = frame; + buffer.mPlanes[0].mData = frame.get(); buffer.mPlanes[0].mStride = mFrameWidth; buffer.mPlanes[0].mHeight = mFrameHeight; buffer.mPlanes[0].mWidth = mFrameWidth; @@ -131,7 +132,7 @@ public: buffer.mPlanes[0].mSkip = 0; // Cb plane. - buffer.mPlanes[1].mData = frame; + buffer.mPlanes[1].mData = frame.get(); buffer.mPlanes[1].mStride = mFrameWidth / 2; buffer.mPlanes[1].mHeight = mFrameHeight / 2; buffer.mPlanes[1].mWidth = mFrameWidth / 2; @@ -139,7 +140,7 @@ public: buffer.mPlanes[1].mSkip = 0; // Cr plane. - buffer.mPlanes[2].mData = frame; + buffer.mPlanes[2].mData = frame.get(); buffer.mPlanes[2].mStride = mFrameWidth / 2; buffer.mPlanes[2].mHeight = mFrameHeight / 2; buffer.mPlanes[2].mWidth = mFrameWidth / 2; diff --git a/dom/media/platforms/apple/AppleATDecoder.cpp b/dom/media/platforms/apple/AppleATDecoder.cpp index fd8078208d67..1257af507d44 100644 --- a/dom/media/platforms/apple/AppleATDecoder.cpp +++ b/dom/media/platforms/apple/AppleATDecoder.cpp @@ -10,6 +10,7 @@ #include "MediaInfo.h" #include "AppleATDecoder.h" #include "mozilla/Logging.h" +#include "mozilla/UniquePtr.h" extern mozilla::LogModule* GetPDMLog(); #define LOG(...) MOZ_LOG(GetPDMLog(), mozilla::LogLevel::Debug, (__VA_ARGS__)) @@ -211,8 +212,7 @@ AppleATDecoder::DecodeSample(MediaRawData* aSample) const uint32_t maxDecodedSamples = MAX_AUDIO_FRAMES * channels; // Descriptions for _decompressed_ audio packets. ignored. - nsAutoArrayPtr - packets(new AudioStreamPacketDescription[MAX_AUDIO_FRAMES]); + auto packets = MakeUnique(MAX_AUDIO_FRAMES); // This API insists on having packets spoon-fed to it from a callback. // This structure exists only to pass our state. @@ -220,7 +220,7 @@ AppleATDecoder::DecodeSample(MediaRawData* aSample) { channels, (UInt32)aSample->Size(), aSample->Data() }; // Decompressed audio buffer - nsAutoArrayPtr decoded(new AudioDataValue[maxDecodedSamples]); + auto decoded = MakeUnique(maxDecodedSamples); do { AudioBufferList decBuffer; @@ -328,14 +328,13 @@ AppleATDecoder::GetInputAudioDescription(AudioStreamBasicDescription& aDesc, return NS_OK; } size_t listCount = formatListSize / sizeof(AudioFormatListItem); - nsAutoArrayPtr formatList( - new AudioFormatListItem[listCount]); + auto formatList = MakeUnique(listCount); rv = AudioFormatGetProperty(kAudioFormatProperty_FormatList, sizeof(formatInfo), &formatInfo, &formatListSize, - formatList); + formatList.get()); if (rv) { return NS_OK; } @@ -348,7 +347,7 @@ AppleATDecoder::GetInputAudioDescription(AudioStreamBasicDescription& aDesc, UInt32 indexSize = sizeof(itemIndex); rv = AudioFormatGetProperty(kAudioFormatProperty_FirstPlayableFormatFromList, formatListSize, - formatList, + formatList.get(), &indexSize, &itemIndex); if (rv) { @@ -438,9 +437,9 @@ _MetadataCallback(void* aAppleATDecoder, decoder->mFileStreamError = true; return; } - nsAutoArrayPtr data(new uint8_t[size]); + auto data = MakeUnique(size); rv = AudioFileStreamGetProperty(aStream, aProperty, - &size, data); + &size, data.get()); if (rv) { LOG("Couldn't get property '%s' (%s)", FourCC2Str(aProperty), FourCC2Str(rv)); diff --git a/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp b/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp index 43e1a479b4d2..60e5fc558552 100644 --- a/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp +++ b/dom/media/platforms/gonk/GonkVideoDecoderManager.cpp @@ -669,8 +669,7 @@ GonkVideoDecoderManager::GetColorConverterBuffer(int32_t aWidth, int32_t aHeight size_t yuv420p_v_size = yuv420p_u_size; size_t yuv420p_size = yuv420p_y_size + yuv420p_u_size + yuv420p_v_size; if (mColorConverterBufferSize != yuv420p_size) { - mColorConverterBuffer = nullptr; // release the previous buffer first - mColorConverterBuffer = new uint8_t[yuv420p_size]; + mColorConverterBuffer = MakeUnique(yuv420p_size); mColorConverterBufferSize = yuv420p_size; } return mColorConverterBuffer.get(); diff --git a/dom/media/platforms/gonk/GonkVideoDecoderManager.h b/dom/media/platforms/gonk/GonkVideoDecoderManager.h index 496b6f5da0ca..1e3b3139b6ba 100644 --- a/dom/media/platforms/gonk/GonkVideoDecoderManager.h +++ b/dom/media/platforms/gonk/GonkVideoDecoderManager.h @@ -15,6 +15,7 @@ #include "GonkNativeWindow.h" #include "GonkNativeWindowClient.h" #include "mozilla/layers/FenceUtils.h" +#include "mozilla/UniquePtr.h" #include using namespace android; @@ -112,7 +113,7 @@ private: // color converter android::I420ColorConverterHelper mColorConverter; - nsAutoArrayPtr mColorConverterBuffer; + UniquePtr mColorConverterBuffer; size_t mColorConverterBufferSize; android::sp mNativeWindow; diff --git a/dom/media/raw/RawReader.cpp b/dom/media/raw/RawReader.cpp index 1185cfc598e9..cfe775c1a9cd 100644 --- a/dom/media/raw/RawReader.cpp +++ b/dom/media/raw/RawReader.cpp @@ -10,6 +10,7 @@ #include "VideoUtils.h" #include "nsISeekableStream.h" #include "gfx2DGlue.h" +#include "mozilla/UniquePtr.h" using namespace mozilla; using namespace mozilla::media; @@ -138,7 +139,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip, int64_t currentFrameTime = USECS_PER_S * mCurrentFrame / mFrameRate; uint32_t length = mFrameSize - sizeof(RawPacketHeader); - nsAutoArrayPtr buffer(new uint8_t[length]); + auto buffer = MakeUnique(length); // We're always decoding one frame when called while(true) { @@ -151,7 +152,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip, return false; } - if (!ReadFromResource(buffer, length)) { + if (!ReadFromResource(buffer.get(), length)) { return false; } @@ -165,7 +166,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip, } VideoData::YCbCrBuffer b; - b.mPlanes[0].mData = buffer; + b.mPlanes[0].mData = buffer.get(); b.mPlanes[0].mStride = mMetadata.frameWidth * mMetadata.lumaChannelBpp / 8.0; b.mPlanes[0].mHeight = mMetadata.frameHeight; b.mPlanes[0].mWidth = mMetadata.frameWidth; @@ -173,7 +174,7 @@ bool RawReader::DecodeVideoFrame(bool &aKeyframeSkip, uint32_t cbcrStride = mMetadata.frameWidth * mMetadata.chromaChannelBpp / 8.0; - b.mPlanes[1].mData = buffer + mMetadata.frameHeight * b.mPlanes[0].mStride; + b.mPlanes[1].mData = buffer.get() + mMetadata.frameHeight * b.mPlanes[0].mStride; b.mPlanes[1].mStride = cbcrStride; b.mPlanes[1].mHeight = mMetadata.frameHeight / 2; b.mPlanes[1].mWidth = mMetadata.frameWidth / 2; diff --git a/dom/media/wave/WaveReader.cpp b/dom/media/wave/WaveReader.cpp index bb58fc41d5d8..3c53e3e6901b 100644 --- a/dom/media/wave/WaveReader.cpp +++ b/dom/media/wave/WaveReader.cpp @@ -14,6 +14,7 @@ #include "mozilla/ArrayUtils.h" #include "mozilla/CheckedInt.h" #include "mozilla/Endian.h" +#include "mozilla/UniquePtr.h" #include using namespace mozilla::media; @@ -191,9 +192,9 @@ bool WaveReader::DecodeAudioData() static_assert(uint64_t(BLOCK_SIZE) < UINT_MAX / sizeof(char), "BLOCK_SIZE too large for enumerator."); - nsAutoArrayPtr dataBuffer(new char[static_cast(readSize)]); + auto dataBuffer = MakeUnique(static_cast(readSize)); - if (!ReadAll(dataBuffer, readSize)) { + if (!ReadAll(dataBuffer.get(), readSize)) { return false; } @@ -406,7 +407,7 @@ WaveReader::LoadFormatChunk(uint32_t aChunkSize) if (extra > 0) { static_assert(UINT16_MAX + (UINT16_MAX % 2) < UINT_MAX / sizeof(char), "chunkExtension array too large for iterator."); - nsAutoArrayPtr chunkExtension(new char[extra]); + auto chunkExtension = MakeUnique(extra); if (!ReadAll(chunkExtension.get(), extra)) { return false; } @@ -528,7 +529,7 @@ WaveReader::LoadListChunk(uint32_t aChunkSize, return false; } - nsAutoArrayPtr chunk(new char[aChunkSize]); + auto chunk = MakeUnique(aChunkSize); if (!ReadAll(chunk.get(), aChunkSize)) { return false; } @@ -652,7 +653,7 @@ WaveReader::LoadAllChunks(nsAutoPtr &aTags) static const int64_t MAX_CHUNK_SIZE = 1 << 16; static_assert(uint64_t(MAX_CHUNK_SIZE) < UINT_MAX / sizeof(char), "MAX_CHUNK_SIZE too large for enumerator."); - nsAutoArrayPtr chunk(new char[MAX_CHUNK_SIZE]); + auto chunk = MakeUnique(MAX_CHUNK_SIZE); while (forward.value() > 0) { int64_t size = std::min(forward.value(), MAX_CHUNK_SIZE); if (!ReadAll(chunk.get(), size)) { diff --git a/dom/media/webaudio/BiquadFilterNode.cpp b/dom/media/webaudio/BiquadFilterNode.cpp index d87ff706f5c0..c89ebd5cfa88 100644 --- a/dom/media/webaudio/BiquadFilterNode.cpp +++ b/dom/media/webaudio/BiquadFilterNode.cpp @@ -12,6 +12,7 @@ #include "WebAudioUtils.h" #include "blink/Biquad.h" #include "mozilla/Preferences.h" +#include "mozilla/UniquePtr.h" #include "AudioParamTimeline.h" namespace mozilla { @@ -316,7 +317,7 @@ BiquadFilterNode::GetFrequencyResponse(const Float32Array& aFrequencyHz, return; } - nsAutoArrayPtr frequencies(new float[length]); + auto frequencies = MakeUnique(length); float* frequencyHz = aFrequencyHz.Data(); const double nyquist = Context()->SampleRate() * 0.5; @@ -338,7 +339,7 @@ BiquadFilterNode::GetFrequencyResponse(const Float32Array& aFrequencyHz, WebCore::Biquad biquad; SetParamsOnBiquad(biquad, Context()->SampleRate(), mType, freq, q, gain, detune); - biquad.getFrequencyResponse(int(length), frequencies, aMagResponse.Data(), aPhaseResponse.Data()); + biquad.getFrequencyResponse(int(length), frequencies.get(), aMagResponse.Data(), aPhaseResponse.Data()); } } // namespace dom diff --git a/dom/media/webaudio/blink/DynamicsCompressor.cpp b/dom/media/webaudio/blink/DynamicsCompressor.cpp index 10a285180a8f..57d511294ff3 100644 --- a/dom/media/webaudio/blink/DynamicsCompressor.cpp +++ b/dom/media/webaudio/blink/DynamicsCompressor.cpp @@ -69,8 +69,8 @@ size_t DynamicsCompressor::sizeOfIncludingThis(mozilla::MallocSizeOf aMallocSize } } - amount += m_sourceChannels.SizeOfExcludingThis(aMallocSizeOf); - amount += m_destinationChannels.SizeOfExcludingThis(aMallocSizeOf); + amount += aMallocSizeOf(m_sourceChannels.get()); + amount += aMallocSizeOf(m_destinationChannels.get()); amount += m_compressor.sizeOfExcludingThis(aMallocSizeOf); return amount; } @@ -308,8 +308,8 @@ void DynamicsCompressor::setNumberOfChannels(unsigned numberOfChannels) m_postFilterPacks.AppendElement(new ZeroPoleFilterPack4()); } - m_sourceChannels = new const float* [numberOfChannels]; - m_destinationChannels = new float* [numberOfChannels]; + m_sourceChannels = mozilla::MakeUnique(numberOfChannels); + m_destinationChannels = mozilla::MakeUnique(numberOfChannels); m_compressor.setNumberOfChannels(numberOfChannels); m_numberOfChannels = numberOfChannels; diff --git a/dom/media/webaudio/blink/DynamicsCompressor.h b/dom/media/webaudio/blink/DynamicsCompressor.h index d0eac82f20d2..f460836b4957 100644 --- a/dom/media/webaudio/blink/DynamicsCompressor.h +++ b/dom/media/webaudio/blink/DynamicsCompressor.h @@ -35,6 +35,7 @@ #include "nsTArray.h" #include "nsAutoPtr.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/UniquePtr.h" namespace mozilla { class AudioBlock; @@ -115,8 +116,8 @@ protected: nsTArray > m_preFilterPacks; nsTArray > m_postFilterPacks; - nsAutoArrayPtr m_sourceChannels; - nsAutoArrayPtr m_destinationChannels; + mozilla::UniquePtr m_sourceChannels; + mozilla::UniquePtr m_destinationChannels; void setEmphasisStageParameters(unsigned stageIndex, float gain, float normalizedFrequency /* 0 -> 1 */); void setEmphasisParameters(float gain, float anchorFreq, float filterStageRatio); diff --git a/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp b/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp index eec04528caf3..4812c9a546b1 100644 --- a/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp +++ b/dom/media/webaudio/blink/DynamicsCompressorKernel.cpp @@ -40,6 +40,7 @@ using namespace std; using namespace mozilla::dom; // for WebAudioUtils using mozilla::IsInfinite; using mozilla::IsNaN; +using mozilla::MakeUnique; namespace WebCore { @@ -78,7 +79,7 @@ size_t DynamicsCompressorKernel::sizeOfExcludingThis(mozilla::MallocSizeOf aMall size_t amount = 0; amount += m_preDelayBuffers.ShallowSizeOfExcludingThis(aMallocSizeOf); for (size_t i = 0; i < m_preDelayBuffers.Length(); i++) { - amount += m_preDelayBuffers[i].SizeOfExcludingThis(aMallocSizeOf); + amount += aMallocSizeOf(m_preDelayBuffers[i].get()); } return amount; @@ -91,7 +92,7 @@ void DynamicsCompressorKernel::setNumberOfChannels(unsigned numberOfChannels) m_preDelayBuffers.Clear(); for (unsigned i = 0; i < numberOfChannels; ++i) - m_preDelayBuffers.AppendElement(new float[MaxPreDelayFrames]); + m_preDelayBuffers.AppendElement(MakeUnique(MaxPreDelayFrames)); } void DynamicsCompressorKernel::setPreDelayTime(float preDelayTime) @@ -104,7 +105,7 @@ void DynamicsCompressorKernel::setPreDelayTime(float preDelayTime) if (m_lastPreDelayFrames != preDelayFrames) { m_lastPreDelayFrames = preDelayFrames; for (unsigned i = 0; i < m_preDelayBuffers.Length(); ++i) - memset(m_preDelayBuffers[i], 0, sizeof(float) * MaxPreDelayFrames); + memset(m_preDelayBuffers[i].get(), 0, sizeof(float) * MaxPreDelayFrames); m_preDelayReadIndex = 0; m_preDelayWriteIndex = preDelayFrames; @@ -387,7 +388,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[], // Predelay signal, computing compression amount from un-delayed version. for (unsigned i = 0; i < numberOfChannels; ++i) { - float* delayBuffer = m_preDelayBuffers[i]; + float* delayBuffer = m_preDelayBuffers[i].get(); float undelayedSource = sourceChannels[i][frameIndex]; delayBuffer[preDelayWriteIndex] = undelayedSource; @@ -453,7 +454,7 @@ void DynamicsCompressorKernel::process(float* sourceChannels[], // Apply final gain. for (unsigned i = 0; i < numberOfChannels; ++i) { - float* delayBuffer = m_preDelayBuffers[i]; + float* delayBuffer = m_preDelayBuffers[i].get(); destinationChannels[i][frameIndex] = delayBuffer[preDelayReadIndex] * totalGain; } @@ -479,7 +480,7 @@ void DynamicsCompressorKernel::reset() // Predelay section. for (unsigned i = 0; i < m_preDelayBuffers.Length(); ++i) - memset(m_preDelayBuffers[i], 0, sizeof(float) * MaxPreDelayFrames); + memset(m_preDelayBuffers[i].get(), 0, sizeof(float) * MaxPreDelayFrames); m_preDelayReadIndex = 0; m_preDelayWriteIndex = DefaultPreDelayFrames; diff --git a/dom/media/webaudio/blink/DynamicsCompressorKernel.h b/dom/media/webaudio/blink/DynamicsCompressorKernel.h index b9453dc54ace..3ba69c243aca 100644 --- a/dom/media/webaudio/blink/DynamicsCompressorKernel.h +++ b/dom/media/webaudio/blink/DynamicsCompressorKernel.h @@ -32,6 +32,7 @@ #include "nsTArray.h" #include "nsAutoPtr.h" #include "mozilla/MemoryReporting.h" +#include "mozilla/UniquePtr.h" namespace WebCore { @@ -89,7 +90,7 @@ protected: unsigned m_lastPreDelayFrames; void setPreDelayTime(float); - nsTArray > m_preDelayBuffers; + nsTArray> m_preDelayBuffers; int m_preDelayReadIndex; int m_preDelayWriteIndex; diff --git a/dom/media/webm/EbmlComposer.cpp b/dom/media/webm/EbmlComposer.cpp index a5dbecaa2cbf..1bda401e09c3 100644 --- a/dom/media/webm/EbmlComposer.cpp +++ b/dom/media/webm/EbmlComposer.cpp @@ -21,8 +21,8 @@ void EbmlComposer::GenerateHeader() // Write the EBML header. EbmlGlobal ebml; // The WEbM header default size usually smaller than 1k. - nsAutoArrayPtr buffer(new uint8_t[DEFAULT_HEADER_SIZE + - mCodecPrivateData.Length()]); + auto buffer = MakeUnique(DEFAULT_HEADER_SIZE + + mCodecPrivateData.Length()); ebml.buf = buffer.get(); ebml.offset = 0; writeHeader(&ebml); diff --git a/dom/media/webrtc/MediaEngineDefault.cpp b/dom/media/webrtc/MediaEngineDefault.cpp index a7c4715b04b8..9f7d272b87bc 100644 --- a/dom/media/webrtc/MediaEngineDefault.cpp +++ b/dom/media/webrtc/MediaEngineDefault.cpp @@ -6,6 +6,7 @@ #include "nsCOMPtr.h" #include "mozilla/dom/File.h" +#include "mozilla/UniquePtr.h" #include "nsILocalFile.h" #include "Layers.h" #include "ImageContainer.h" @@ -314,7 +315,7 @@ public: // If we allow arbitrary frequencies, there's no guarantee we won't get rounded here // We could include an error term and adjust for it in generation; not worth the trouble //MOZ_ASSERT(mTotalLength * aFrequency == aSampleRate); - mAudioBuffer = new int16_t[mTotalLength]; + mAudioBuffer = MakeUnique(mTotalLength); for (int i = 0; i < mTotalLength; i++) { // Set volume to -20db. It's from 32768.0 * 10^(-20/20) = 3276.8 mAudioBuffer[i] = (3276.8f * sin(2 * M_PI * i / mTotalLength)); @@ -333,7 +334,7 @@ public: } else { processSamples = mTotalLength - mReadLength; } - memcpy(aBuffer, mAudioBuffer + mReadLength, processSamples * bytesPerSample); + memcpy(aBuffer, &mAudioBuffer[mReadLength], processSamples * bytesPerSample); aBuffer += processSamples; mReadLength += processSamples; remaining -= processSamples; @@ -344,7 +345,7 @@ public: } private: - nsAutoArrayPtr mAudioBuffer; + UniquePtr mAudioBuffer; int16_t mTotalLength; int16_t mReadLength; }; diff --git a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp index 2f9507203a3d..0b72a4af5b7b 100644 --- a/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp +++ b/dom/media/webspeech/synth/test/nsFakeSynthServices.cpp @@ -152,8 +152,8 @@ FakeDirectAudioSynth::Speak(const nsAString& aText, const nsAString& aUri, // Just an arbitrary multiplier. Pretend that each character is // synthesized to 40 frames. uint32_t frames_length = 40 * mText.Length(); - nsAutoArrayPtr frames(new int16_t[frames_length]()); - mTask->SendAudioNative(frames, frames_length); + auto frames = MakeUnique(frames_length); + mTask->SendAudioNative(frames.get(), frames_length); mTask->SendAudioNative(nullptr, 0);