Skip to content

Commit

Permalink
Bug 1325707: P3. Fix coding style. r=gerald
Browse files Browse the repository at this point in the history
Fixed coding style of files encountered in P1 and P2.

MozReview-Commit-ID: LApVu9K2oto

--HG--
extra : rebase_source : e3bb296baaec9df2011ff312fec2eda19dd125e6
  • Loading branch information
Jean-Yves Avenard committed Feb 7, 2017
1 parent ec59353 commit 16bf821
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 197 deletions.
39 changes: 21 additions & 18 deletions dom/media/MediaData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ AudioData::TransferAndUpdateTimestampAndDuration(AudioData* aOther,
static bool
ValidatePlane(const VideoData::YCbCrBuffer::Plane& aPlane)
{
return aPlane.mWidth <= PlanarYCbCrImage::MAX_DIMENSION &&
aPlane.mHeight <= PlanarYCbCrImage::MAX_DIMENSION &&
aPlane.mWidth * aPlane.mHeight < MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT &&
aPlane.mStride > 0;
return aPlane.mWidth <= PlanarYCbCrImage::MAX_DIMENSION
&& aPlane.mHeight <= PlanarYCbCrImage::MAX_DIMENSION
&& aPlane.mWidth * aPlane.mHeight < MAX_VIDEO_WIDTH * MAX_VIDEO_HEIGHT
&& aPlane.mStride > 0;
}

static bool ValidateBufferAndPicture(const VideoData::YCbCrBuffer& aBuffer,
const IntRect& aPicture)
{
// The following situation should never happen unless there is a bug
// in the decoder
if (aBuffer.mPlanes[1].mWidth != aBuffer.mPlanes[2].mWidth ||
aBuffer.mPlanes[1].mHeight != aBuffer.mPlanes[2].mHeight) {
if (aBuffer.mPlanes[1].mWidth != aBuffer.mPlanes[2].mWidth
|| aBuffer.mPlanes[1].mHeight != aBuffer.mPlanes[2].mHeight) {
NS_ERROR("C planes with different sizes");
return false;
}
Expand All @@ -112,9 +112,9 @@ static bool ValidateBufferAndPicture(const VideoData::YCbCrBuffer& aBuffer,
MOZ_ASSERT(false, "Empty picture rect");
return false;
}
if (!ValidatePlane(aBuffer.mPlanes[0]) ||
!ValidatePlane(aBuffer.mPlanes[1]) ||
!ValidatePlane(aBuffer.mPlanes[2])) {
if (!ValidatePlane(aBuffer.mPlanes[0])
|| !ValidatePlane(aBuffer.mPlanes[1])
|| !ValidatePlane(aBuffer.mPlanes[2])) {
NS_WARNING("Invalid plane size");
return false;
}
Expand All @@ -123,8 +123,10 @@ static bool ValidateBufferAndPicture(const VideoData::YCbCrBuffer& aBuffer,
// the frame we've been supplied without indexing out of bounds.
CheckedUint32 xLimit = aPicture.x + CheckedUint32(aPicture.width);
CheckedUint32 yLimit = aPicture.y + CheckedUint32(aPicture.height);
if (!xLimit.isValid() || xLimit.value() > aBuffer.mPlanes[0].mStride ||
!yLimit.isValid() || yLimit.value() > aBuffer.mPlanes[0].mHeight)
if (!xLimit.isValid()
|| xLimit.value() > aBuffer.mPlanes[0].mStride
|| !yLimit.isValid()
|| yLimit.value() > aBuffer.mPlanes[0].mHeight)
{
// The specified picture dimensions can't be contained inside the video
// frame, we'll stomp memory if we try to copy it. Fail.
Expand All @@ -141,12 +143,12 @@ IsYV12Format(const VideoData::YCbCrBuffer::Plane& aYPlane,
const VideoData::YCbCrBuffer::Plane& aCrPlane)
{
return
aYPlane.mWidth % 2 == 0 &&
aYPlane.mHeight % 2 == 0 &&
aYPlane.mWidth / 2 == aCbPlane.mWidth &&
aYPlane.mHeight / 2 == aCbPlane.mHeight &&
aCbPlane.mWidth == aCrPlane.mWidth &&
aCbPlane.mHeight == aCrPlane.mHeight;
aYPlane.mWidth % 2 == 0
&& aYPlane.mHeight % 2 == 0
&& aYPlane.mWidth / 2 == aCbPlane.mWidth
&& aYPlane.mHeight / 2 == aCbPlane.mHeight
&& aCbPlane.mWidth == aCrPlane.mWidth
&& aCbPlane.mHeight == aCrPlane.mHeight;
}

static bool
Expand Down Expand Up @@ -183,7 +185,8 @@ VideoData::~VideoData()
void
VideoData::SetListener(UniquePtr<Listener> aListener)
{
MOZ_ASSERT(!mSentToCompositor, "Listener should be registered before sending data");
MOZ_ASSERT(!mSentToCompositor,
"Listener should be registered before sending data");

mListener = Move(aListener);
}
Expand Down
32 changes: 19 additions & 13 deletions dom/media/MediaData.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ class AlignedBuffer
, mLength(0)
, mBuffer(nullptr)
, mCapacity(0)
{}
{
}

explicit AlignedBuffer(size_t aLength)
: mData(nullptr)
Expand All @@ -90,7 +91,8 @@ class AlignedBuffer

AlignedBuffer(const AlignedBuffer& aOther)
: AlignedBuffer(aOther.Data(), aOther.Length())
{}
{
}

AlignedBuffer(AlignedBuffer&& aOther)
: mData(aOther.mData)
Expand Down Expand Up @@ -354,7 +356,7 @@ class MediaData
{
}

virtual ~MediaData() {}
virtual ~MediaData() { }

};

Expand All @@ -365,7 +367,8 @@ class NullData : public MediaData
public:
NullData(int64_t aOffset, int64_t aTime, int64_t aDuration)
: MediaData(NULL_DATA, aOffset, aTime, aDuration, 0)
{}
{
}

static const Type sType = NULL_DATA;
};
Expand All @@ -385,7 +388,9 @@ class AudioData : public MediaData
: MediaData(sType, aOffset, aTime, aDuration, aFrames)
, mChannels(aChannels)
, mRate(aRate)
, mAudioData(Move(aData)) {}
, mAudioData(Move(aData))
{
}

static const Type sType = AUDIO_DATA;
static const char* sTypeName;
Expand Down Expand Up @@ -464,7 +469,7 @@ class VideoData : public MediaData
{
public:
virtual void OnSentToCompositor() = 0;
virtual ~Listener() {}
virtual ~Listener() { }
};

// Constructs a VideoData object. If aImage is nullptr, creates a new Image
Expand All @@ -477,15 +482,15 @@ class VideoData : public MediaData
// problem with the input data (e.g. negative stride).


// Creates a new VideoData containing a deep copy of aBuffer. May use aContainer
// to allocate an Image to hold the copied data.
// Creates a new VideoData containing a deep copy of aBuffer. May use
// aContainer to allocate an Image to hold the copied data.
static already_AddRefed<VideoData> CreateAndCopyData(
const VideoInfo& aInfo,
ImageContainer* aContainer,
int64_t aOffset,
int64_t aTime,
int64_t aDuration,
const YCbCrBuffer &aBuffer,
const YCbCrBuffer& aBuffer,
bool aKeyframe,
int64_t aTimecode,
const IntRect& aPicture);
Expand All @@ -496,8 +501,8 @@ class VideoData : public MediaData
int64_t aOffset,
int64_t aTime,
int64_t aDuration,
const YCbCrBuffer &aBuffer,
const YCbCrBuffer::Plane &aAlphaPlane,
const YCbCrBuffer& aBuffer,
const YCbCrBuffer::Plane& aAlphaPlane,
bool aKeyframe,
int64_t aTimecode,
const IntRect& aPicture);
Expand Down Expand Up @@ -526,7 +531,7 @@ class VideoData : public MediaData
// video data is copied to PlanarYCbCrImage.
static bool SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
const VideoInfo& aInfo,
const YCbCrBuffer &aBuffer,
const YCbCrBuffer& aBuffer,
const IntRect& aPicture,
bool aCopyData);

Expand Down Expand Up @@ -688,7 +693,8 @@ class MediaRawData : public MediaData
};

// MediaByteBuffer is a ref counted infallible TArray.
class MediaByteBuffer : public nsTArray<uint8_t> {
class MediaByteBuffer : public nsTArray<uint8_t>
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaByteBuffer);
MediaByteBuffer() = default;
explicit MediaByteBuffer(size_t aCapacity) : nsTArray<uint8_t>(aCapacity) { }
Expand Down
27 changes: 16 additions & 11 deletions dom/media/gmp/widevine-adapter/WidevineVideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,22 @@ WidevineVideoDecoder::Decode(GMPVideoEncodedFrame* aInputFrame,

const GMPEncryptedBufferMetadata* crypto = aInputFrame->GetDecryptionData();
nsTArray<SubsampleEntry> subsamples;
InitInputBuffer(crypto, aInputFrame->TimeStamp(), raw->Data(), raw->Size(), sample, subsamples);
InitInputBuffer(crypto, aInputFrame->TimeStamp(), raw->Data(), raw->Size(),
sample, subsamples);

// For keyframes, ConvertSampleToAnnexB will stick the AnnexB extra data
// at the start of the input. So we need to account for that as clear data
// in the subsamples.
if (raw->mKeyframe && !subsamples.IsEmpty() && mCodecType == kGMPVideoCodecH264) {
if (raw->mKeyframe
&& !subsamples.IsEmpty()
&& mCodecType == kGMPVideoCodecH264) {
subsamples[0].clear_bytes += mAnnexB->Length();
}

WidevineVideoFrame frame;
Status rv = CDM()->DecryptAndDecodeFrame(sample, &frame);
Log("WidevineVideoDecoder::Decode(timestamp=%lld) rv=%d", sample.timestamp, rv);
Log("WidevineVideoDecoder::Decode(timestamp=%lld) rv=%d", sample.timestamp,
rv);

// Destroy frame, so that the shmem is now free to be used to return
// output to the Gecko process.
Expand Down Expand Up @@ -166,7 +170,8 @@ WidevineVideoDecoder::Decode(GMPVideoEncodedFrame* aInputFrame,
} else {
mCallback->Error(ToGMPErr(rv));
}
// Finish a drain if pending and we have no pending ReturnOutput calls on the stack.
// Finish a drain if pending and we have no pending ReturnOutput calls on the
// stack.
if (mDrainPending && mReturnOutputCallDepth == 0) {
Drain();
}
Expand Down Expand Up @@ -195,12 +200,10 @@ class CounterHelper {
// Util class to make sure GMP frames are freed. Holds a GMPVideoi420Frame*
// and will destroy it when the helper is destroyed unless the held frame
// if forgotten with ForgetFrame.
class FrameDestroyerHelper {
class FrameDestroyerHelper
{
public:
explicit FrameDestroyerHelper(GMPVideoi420Frame*& frame)
: frame(frame)
{
}
explicit FrameDestroyerHelper(GMPVideoi420Frame*& frame) : frame(frame) { }

// RAII, destroy frame if held.
~FrameDestroyerHelper()
Expand Down Expand Up @@ -267,11 +270,13 @@ WidevineVideoDecoder::ReturnOutput(WidevineVideoFrame& aCDMFrame)
yStride,
uStride,
vStride);
// Assert possible reentrant calls or resets haven't altered level unexpectedly.
// Assert possible reentrant calls or resets haven't altered level
// unexpectedly.
MOZ_ASSERT(mReturnOutputCallDepth == 1);
ENSURE_GMP_SUCCESS(err, false);

// If a reset started we need to dump the current frame and complete the reset.
// If a reset started we need to dump the current frame and complete the
// reset.
if (mResetInProgress) {
MOZ_ASSERT(mCDMWrapper);
MOZ_ASSERT(mFrameAllocationQueue.empty());
Expand Down
6 changes: 4 additions & 2 deletions dom/media/gmp/widevine-adapter/WidevineVideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

namespace mozilla {

class WidevineVideoDecoder : public GMPVideoDecoder {
class WidevineVideoDecoder : public GMPVideoDecoder
{
public:

NS_INLINE_DECL_THREADSAFE_REFCOUNTING(WidevineVideoDecoder)
Expand All @@ -45,7 +46,8 @@ class WidevineVideoDecoder : public GMPVideoDecoder {

~WidevineVideoDecoder();

cdm::ContentDecryptionModule_8* CDM() const {
cdm::ContentDecryptionModule_8* CDM() const
{
// CDM should only be accessed before 'DecodingComplete'.
MOZ_ASSERT(mCDMWrapper);
// CDMWrapper ensure the CDM is non-null, no need to check again.
Expand Down
10 changes: 6 additions & 4 deletions dom/media/ipc/VideoDecoderParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ VideoDecoderParent::VideoDecoderParent(VideoDecoderManagerParent* aParent,

mDecoder = pdm->CreateVideoDecoder(params);
#else
MOZ_ASSERT(false, "Can't use RemoteVideoDecoder on non-Windows platforms yet");
MOZ_ASSERT(false,
"Can't use RemoteVideoDecoder on non-Windows platforms yet");
#endif

*aSuccess = !!mDecoder;
Expand Down Expand Up @@ -106,7 +107,8 @@ VideoDecoderParent::RecvInit()
[self] (TrackInfo::TrackType aTrack) {
if (self->mDecoder) {
nsCString hardwareReason;
bool hardwareAccelerated = self->mDecoder->IsHardwareAccelerated(hardwareReason);
bool hardwareAccelerated =
self->mDecoder->IsHardwareAccelerated(hardwareReason);
Unused << self->SendInitComplete(hardwareAccelerated, hardwareReason);
}
},
Expand All @@ -122,8 +124,8 @@ mozilla::ipc::IPCResult
VideoDecoderParent::RecvInput(const MediaRawDataIPDL& aData)
{
MOZ_ASSERT(OnManagerThread());
// XXX: This copies the data into a buffer owned by the MediaRawData. Ideally we'd just take ownership
// of the shmem.
// XXX: This copies the data into a buffer owned by the MediaRawData. Ideally
// we'd just take ownership of the shmem.
RefPtr<MediaRawData> data = new MediaRawData(aData.buffer().get<uint8_t>(),
aData.buffer().Size<uint8_t>());
if (!data->Data()) {
Expand Down
Loading

0 comments on commit 16bf821

Please sign in to comment.