Bug 1055114 - convert GMPVideo{Encoder,Decoder} methods to take UniquePtr arguments where appropriate; r=cpearce

This commit is contained in:
Nathan Froyd 2014-08-18 13:11:11 -04:00
Родитель 91859b4c73
Коммит 36f456593a
10 изменённых файлов: 68 добавлений и 32 удалений

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

@ -16,6 +16,7 @@
#include "prsystem.h"
#include "gfx2DGlue.h"
#include "mozilla/EMELog.h"
#include "mozilla/Move.h"
namespace mozilla {
@ -297,7 +298,7 @@ EMEH264Decoder::GmpInput(MP4Sample* aSample)
return NS_ERROR_FAILURE;
}
gmp::GMPVideoEncodedFrameImpl* frame = static_cast<gmp::GMPVideoEncodedFrameImpl*>(ftmp);
UniquePtr<gmp::GMPVideoEncodedFrameImpl> frame(static_cast<gmp::GMPVideoEncodedFrameImpl*>(ftmp));
err = frame->CreateEmptyFrame(sample->size);
if (GMP_FAILED(err)) {
mCallback->Error();
@ -318,7 +319,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(frame, false, info, 0);
nsresult rv = mGMP->Decode(UniquePtr<GMPVideoEncodedFrame>(frame.release()), false, info, 0);
if (NS_FAILED(rv)) {
mCallback->Error();
return rv;

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

@ -14,13 +14,6 @@
#include "GMPMessageUtils.h"
#include "mozilla/gmp/GMPTypes.h"
template <>
class nsAutoRefTraits<GMPVideoEncodedFrame> : public nsPointerRefTraits<GMPVideoEncodedFrame>
{
public:
static void Release(GMPVideoEncodedFrame* aFrame) { aFrame->Destroy(); }
};
namespace mozilla {
#ifdef LOG
@ -114,13 +107,11 @@ GMPVideoDecoderParent::InitDecode(const GMPVideoCodec& aCodecSettings,
}
nsresult
GMPVideoDecoderParent::Decode(GMPVideoEncodedFrame* aInputFrame,
GMPVideoDecoderParent::Decode(UniquePtr<GMPVideoEncodedFrame> aInputFrame,
bool aMissingFrames,
const nsTArray<uint8_t>& aCodecSpecificInfo,
int64_t aRenderTimeMs)
{
nsAutoRef<GMPVideoEncodedFrame> autoDestroy(aInputFrame);
if (!mIsOpen) {
NS_WARNING("Trying to use an dead GMP video decoder");
return NS_ERROR_FAILURE;
@ -128,7 +119,8 @@ GMPVideoDecoderParent::Decode(GMPVideoEncodedFrame* aInputFrame,
MOZ_ASSERT(mPlugin->GMPThread() == NS_GetCurrentThread());
auto inputFrameImpl = static_cast<GMPVideoEncodedFrameImpl*>(aInputFrame);
UniquePtr<GMPVideoEncodedFrameImpl> inputFrameImpl(
static_cast<GMPVideoEncodedFrameImpl*>(aInputFrame.release()));
// Very rough kill-switch if the plugin stops processing. If it's merely
// hung and continues, we'll come back to life eventually.

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

@ -37,7 +37,7 @@ public:
const nsTArray<uint8_t>& aCodecSpecific,
GMPVideoDecoderCallbackProxy* aCallback,
int32_t aCoreCount) MOZ_OVERRIDE;
virtual nsresult Decode(GMPVideoEncodedFrame* aInputFrame,
virtual nsresult Decode(UniquePtr<GMPVideoEncodedFrame> aInputFrame,
bool aMissingFrames,
const nsTArray<uint8_t>& aCodecSpecificInfo,
int64_t aRenderTimeMs = -1) MOZ_OVERRIDE;

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

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

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

@ -35,6 +35,7 @@
#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"
@ -114,6 +115,16 @@ private:
};
} // namespace gmp
template<>
struct DefaultDelete<mozilla::gmp::GMPVideoEncodedFrameImpl>
{
void operator()(mozilla::gmp::GMPVideoEncodedFrameImpl* aFrame) const
{
aFrame->Destroy();
}
};
} // namespace mozilla
#endif // GMPVideoEncodedFrameImpl_h_

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

@ -16,13 +16,6 @@
#include "nsThreadUtils.h"
#include "runnable_utils.h"
template <>
class nsAutoRefTraits<GMPVideoi420Frame> : public nsPointerRefTraits<GMPVideoi420Frame>
{
public:
static void Release(GMPVideoi420Frame* aFrame) { aFrame->Destroy(); }
};
namespace mozilla {
#ifdef LOG
@ -131,12 +124,10 @@ GMPVideoEncoderParent::InitEncode(const GMPVideoCodec& aCodecSettings,
}
GMPErr
GMPVideoEncoderParent::Encode(GMPVideoi420Frame* aInputFrame,
GMPVideoEncoderParent::Encode(UniquePtr<GMPVideoi420Frame> aInputFrame,
const nsTArray<uint8_t>& aCodecSpecificInfo,
const nsTArray<GMPVideoFrameType>& aFrameTypes)
{
nsAutoRef<GMPVideoi420Frame> frameRef(aInputFrame);
if (!mIsOpen) {
NS_WARNING("Trying to use an dead GMP video encoder");
return GMPGenericErr;
@ -144,7 +135,8 @@ GMPVideoEncoderParent::Encode(GMPVideoi420Frame* aInputFrame,
MOZ_ASSERT(mPlugin->GMPThread() == NS_GetCurrentThread());
auto inputFrameImpl = static_cast<GMPVideoi420FrameImpl*>(aInputFrame);
UniquePtr<GMPVideoi420FrameImpl> inputFrameImpl(
static_cast<GMPVideoi420FrameImpl*>(aInputFrame.release()));
// Very rough kill-switch if the plugin stops processing. If it's merely
// hung and continues, we'll come back to life eventually.

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

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

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

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

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

@ -7,6 +7,7 @@
#include <iostream>
#include <vector>
#include "mozilla/Move.h"
#include "mozilla/Scoped.h"
#include "mozilla/SyncRunnable.h"
#include "VideoConduit.h"
@ -249,7 +250,7 @@ WebrtcGmpVideoEncoder::Encode_g(const webrtc::I420VideoFrame* aInputImage,
if (err != GMPNoErr) {
return WEBRTC_VIDEO_CODEC_ERROR;
}
GMPVideoi420Frame* frame = static_cast<GMPVideoi420Frame*>(ftmp);
UniquePtr<GMPVideoi420Frame> frame(static_cast<GMPVideoi420Frame*>(ftmp));
err = frame->CreateFrame(aInputImage->allocated_size(webrtc::kYPlane),
aInputImage->buffer(webrtc::kYPlane),
@ -288,7 +289,7 @@ WebrtcGmpVideoEncoder::Encode_g(const webrtc::I420VideoFrame* aInputImage,
}
LOGD(("GMP Encode: %llu", (aInputImage->timestamp() * 1000ll)/90));
err = mGMP->Encode(frame, codecSpecificInfo, gmp_frame_types);
err = mGMP->Encode(Move(frame), codecSpecificInfo, gmp_frame_types);
if (err != GMPNoErr) {
return err;
}
@ -603,7 +604,7 @@ WebrtcGmpVideoDecoder::Decode_g(const webrtc::EncodedImage& aInputImage,
return WEBRTC_VIDEO_CODEC_ERROR;
}
GMPVideoEncodedFrame* frame = static_cast<GMPVideoEncodedFrame*>(ftmp);
UniquePtr<GMPVideoEncodedFrame> frame(static_cast<GMPVideoEncodedFrame*>(ftmp));
err = frame->CreateEmptyFrame(aInputImage._length);
if (err != GMPNoErr) {
return WEBRTC_VIDEO_CODEC_ERROR;
@ -637,7 +638,7 @@ WebrtcGmpVideoDecoder::Decode_g(const webrtc::EncodedImage& aInputImage,
codecSpecificInfo.AppendElements((uint8_t*)&info, sizeof(GMPCodecSpecificInfo));
LOGD(("GMP Decode: %llu, len %d", frame->TimeStamp(), aInputImage._length));
nsresult rv = mGMP->Decode(frame,
nsresult rv = mGMP->Decode(Move(frame),
aMissingFrames,
codecSpecificInfo,
aRenderTimeMs);