Bug 1124021 - Fix dangerous UniquePtr usage pattern in GMP. r=cpearce

This commit is contained in:
Matthew Gregan 2015-01-20 18:39:00 +13:00
Родитель 8e86d1cba8
Коммит f29aff15e4
12 изменённых файлов: 45 добавлений и 60 удалений

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

@ -312,7 +312,7 @@ EMEH264Decoder::GmpInput(MP4Sample* aSample)
return NS_ERROR_FAILURE;
}
UniquePtr<gmp::GMPVideoEncodedFrameImpl> frame(static_cast<gmp::GMPVideoEncodedFrameImpl*>(ftmp));
GMPUniquePtr<gmp::GMPVideoEncodedFrameImpl> frame(static_cast<gmp::GMPVideoEncodedFrameImpl*>(ftmp));
err = frame->CreateEmptyFrame(sample->size);
if (GMP_FAILED(err)) {
mCallback->Error();
@ -333,7 +333,7 @@ EMEH264Decoder::GmpInput(MP4Sample* aSample)
frame->SetBufferType(GMP_BufferLength32);
nsTArray<uint8_t> info; // No codec specific per-frame info to pass.
nsresult rv = mGMP->Decode(UniquePtr<GMPVideoEncodedFrame>(frame.release()), false, info, 0);
nsresult rv = mGMP->Decode(GMPUniquePtr<GMPVideoEncodedFrame>(frame.release()), false, info, 0);
if (NS_FAILED(rv)) {
mCallback->Error();
return rv;

26
dom/media/gmp/GMPUtils.h Normal file
Просмотреть файл

@ -0,0 +1,26 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef GMPUtils_h_
#define GMPUtils_h_
#include "mozilla/UniquePtr.h"
namespace mozilla {
template<typename T>
struct DestroyPolicy
{
void operator()(T* aGMPObject) const {
aGMPObject->Destroy();
}
};
template<typename T>
using GMPUniquePtr = mozilla::UniquePtr<T, DestroyPolicy<T>>;
} // namespace mozilla
#endif

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

@ -8,6 +8,7 @@
#include "mozilla/unused.h"
#include "nsAutoRef.h"
#include "nsThreadUtils.h"
#include "GMPUtils.h"
#include "GMPVideoEncodedFrameImpl.h"
#include "GMPVideoi420FrameImpl.h"
#include "GMPParent.h"
@ -108,7 +109,7 @@ GMPVideoDecoderParent::InitDecode(const GMPVideoCodec& aCodecSettings,
}
nsresult
GMPVideoDecoderParent::Decode(UniquePtr<GMPVideoEncodedFrame> aInputFrame,
GMPVideoDecoderParent::Decode(GMPUniquePtr<GMPVideoEncodedFrame> aInputFrame,
bool aMissingFrames,
const nsTArray<uint8_t>& aCodecSpecificInfo,
int64_t aRenderTimeMs)
@ -120,7 +121,7 @@ GMPVideoDecoderParent::Decode(UniquePtr<GMPVideoEncodedFrame> aInputFrame,
MOZ_ASSERT(mPlugin->GMPThread() == NS_GetCurrentThread());
UniquePtr<GMPVideoEncodedFrameImpl> inputFrameImpl(
GMPUniquePtr<GMPVideoEncodedFrameImpl> inputFrameImpl(
static_cast<GMPVideoEncodedFrameImpl*>(aInputFrame.release()));
// Very rough kill-switch if the plugin stops processing. If it's merely

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

@ -11,6 +11,7 @@
#include "mozilla/gmp/PGMPVideoDecoderParent.h"
#include "GMPMessageUtils.h"
#include "GMPSharedMemManager.h"
#include "GMPUtils.h"
#include "GMPVideoHost.h"
#include "GMPVideoDecoderProxy.h"
@ -37,7 +38,7 @@ public:
const nsTArray<uint8_t>& aCodecSpecific,
GMPVideoDecoderCallbackProxy* aCallback,
int32_t aCoreCount) MOZ_OVERRIDE;
virtual nsresult Decode(UniquePtr<GMPVideoEncodedFrame> aInputFrame,
virtual nsresult Decode(GMPUniquePtr<GMPVideoEncodedFrame> aInputFrame,
bool aMissingFrames,
const nsTArray<uint8_t>& aCodecSpecificInfo,
int64_t aRenderTimeMs = -1) MOZ_OVERRIDE;

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

@ -12,7 +12,7 @@
#include "gmp-video-frame-encoded.h"
#include "GMPCallbackBase.h"
#include "mozilla/UniquePtr.h"
#include "GMPUtils.h"
class GMPVideoDecoderCallbackProxy : public GMPCallbackBase,
public GMPVideoDecoderCallback
@ -38,7 +38,7 @@ public:
const nsTArray<uint8_t>& aCodecSpecific,
GMPVideoDecoderCallbackProxy* aCallback,
int32_t aCoreCount) = 0;
virtual nsresult Decode(mozilla::UniquePtr<GMPVideoEncodedFrame> aInputFrame,
virtual nsresult Decode(mozilla::GMPUniquePtr<GMPVideoEncodedFrame> aInputFrame,
bool aMissingFrames,
const nsTArray<uint8_t>& aCodecSpecificInfo,
int64_t aRenderTimeMs = -1) = 0;
@ -51,17 +51,4 @@ public:
virtual void Close() = 0;
};
namespace mozilla {
template<>
struct DefaultDelete<GMPVideoEncodedFrame>
{
void operator()(GMPVideoEncodedFrame* aFrame) const
{
aFrame->Destroy();
}
};
} // namespace mozilla
#endif

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

@ -35,7 +35,6 @@
#include "gmp-video-frame.h"
#include "gmp-video-frame-encoded.h"
#include "gmp-decryption.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/ipc/Shmem.h"
#include "mp4_demuxer/DecoderData.h"
@ -116,15 +115,6 @@ private:
} // namespace gmp
template<>
struct DefaultDelete<mozilla::gmp::GMPVideoEncodedFrameImpl>
{
void operator()(mozilla::gmp::GMPVideoEncodedFrameImpl* aFrame) const
{
aFrame->Destroy();
}
};
} // namespace mozilla
#endif // GMPVideoEncodedFrameImpl_h_

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

@ -15,6 +15,7 @@
#include "nsThread.h"
#include "nsThreadUtils.h"
#include "runnable_utils.h"
#include "GMPUtils.h"
namespace mozilla {
@ -125,7 +126,7 @@ GMPVideoEncoderParent::InitEncode(const GMPVideoCodec& aCodecSettings,
}
GMPErr
GMPVideoEncoderParent::Encode(UniquePtr<GMPVideoi420Frame> aInputFrame,
GMPVideoEncoderParent::Encode(GMPUniquePtr<GMPVideoi420Frame> aInputFrame,
const nsTArray<uint8_t>& aCodecSpecificInfo,
const nsTArray<GMPVideoFrameType>& aFrameTypes)
{
@ -136,7 +137,7 @@ GMPVideoEncoderParent::Encode(UniquePtr<GMPVideoi420Frame> aInputFrame,
MOZ_ASSERT(mPlugin->GMPThread() == NS_GetCurrentThread());
UniquePtr<GMPVideoi420FrameImpl> inputFrameImpl(
GMPUniquePtr<GMPVideoi420FrameImpl> inputFrameImpl(
static_cast<GMPVideoi420FrameImpl*>(aInputFrame.release()));
// Very rough kill-switch if the plugin stops processing. If it's merely

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

@ -11,6 +11,7 @@
#include "mozilla/gmp/PGMPVideoEncoderParent.h"
#include "GMPMessageUtils.h"
#include "GMPSharedMemManager.h"
#include "GMPUtils.h"
#include "GMPVideoHost.h"
#include "GMPVideoEncoderProxy.h"
@ -38,7 +39,7 @@ public:
GMPVideoEncoderCallbackProxy* aCallback,
int32_t aNumberOfCores,
uint32_t aMaxPayloadSize) MOZ_OVERRIDE;
virtual GMPErr Encode(UniquePtr<GMPVideoi420Frame> aInputFrame,
virtual GMPErr Encode(GMPUniquePtr<GMPVideoi420Frame> aInputFrame,
const nsTArray<uint8_t>& aCodecSpecificInfo,
const nsTArray<GMPVideoFrameType>& aFrameTypes) MOZ_OVERRIDE;
virtual GMPErr SetChannelParameters(uint32_t aPacketLoss, uint32_t aRTT) MOZ_OVERRIDE;

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

@ -12,7 +12,7 @@
#include "gmp-video-frame-encoded.h"
#include "GMPCallbackBase.h"
#include "mozilla/UniquePtr.h"
#include "GMPUtils.h"
class GMPVideoEncoderCallbackProxy : public GMPCallbackBase {
public:
@ -40,7 +40,7 @@ public:
GMPVideoEncoderCallbackProxy* aCallback,
int32_t aNumberOfCores,
uint32_t aMaxPayloadSize) = 0;
virtual GMPErr Encode(mozilla::UniquePtr<GMPVideoi420Frame> aInputFrame,
virtual GMPErr Encode(mozilla::GMPUniquePtr<GMPVideoi420Frame> aInputFrame,
const nsTArray<uint8_t>& aCodecSpecificInfo,
const nsTArray<GMPVideoFrameType>& aFrameTypes) = 0;
virtual GMPErr SetChannelParameters(uint32_t aPacketLoss, uint32_t aRTT) = 0;
@ -53,17 +53,4 @@ public:
virtual void Close() = 0;
};
namespace mozilla {
template<>
struct DefaultDelete<GMPVideoi420Frame>
{
void operator()(GMPVideoi420Frame* aFrame) const
{
aFrame->Destroy();
}
};
} // namespace mozilla
#endif // GMPVideoEncoderProxy_h_

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

@ -7,7 +7,6 @@
#define GMPVideoi420FrameImpl_h_
#include "gmp-video-frame-i420.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/ipc/Shmem.h"
#include "GMPVideoPlaneImpl.h"
@ -80,15 +79,6 @@ private:
} // namespace gmp
template<>
struct DefaultDelete<mozilla::gmp::GMPVideoi420FrameImpl>
{
void operator()(mozilla::gmp::GMPVideoi420FrameImpl* aFrame) const
{
aFrame->Destroy();
}
};
} // namespace mozilla
#endif // GMPVideoi420FrameImpl_h_

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

@ -51,6 +51,7 @@ EXPORTS += [
'GMPStorageParent.h',
'GMPTimerChild.h',
'GMPTimerParent.h',
'GMPUtils.h',
'GMPVideoDecoderChild.h',
'GMPVideoDecoderParent.h',
'GMPVideoDecoderProxy.h',

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

@ -279,7 +279,7 @@ WebrtcGmpVideoEncoder::Encode_g(const webrtc::I420VideoFrame* aInputImage,
if (err != GMPNoErr) {
return WEBRTC_VIDEO_CODEC_ERROR;
}
UniquePtr<GMPVideoi420Frame> frame(static_cast<GMPVideoi420Frame*>(ftmp));
GMPUniquePtr<GMPVideoi420Frame> frame(static_cast<GMPVideoi420Frame*>(ftmp));
err = frame->CreateFrame(aInputImage->allocated_size(webrtc::kYPlane),
aInputImage->buffer(webrtc::kYPlane),
@ -635,7 +635,7 @@ WebrtcGmpVideoDecoder::Decode_g(const webrtc::EncodedImage& aInputImage,
return WEBRTC_VIDEO_CODEC_ERROR;
}
UniquePtr<GMPVideoEncodedFrame> frame(static_cast<GMPVideoEncodedFrame*>(ftmp));
GMPUniquePtr<GMPVideoEncodedFrame> frame(static_cast<GMPVideoEncodedFrame*>(ftmp));
err = frame->CreateEmptyFrame(aInputImage._length);
if (err != GMPNoErr) {
return WEBRTC_VIDEO_CODEC_ERROR;