Verified Commit 3ac27d2d authored by Alastor Wu's avatar Alastor Wu Committed by ma1
Browse files

Bug 2045281 - Use the decoded frame format for ffmpeg video chroma plane...

Bug 2045281 - Use the decoded frame format for ffmpeg video chroma plane geometry.  a=RyanVM DONTBUILD

Original Revision: https://phabricator.services.mozilla.com/D305741

Differential Revision: https://phabricator.services.mozilla.com/D306247
parent 54969f84
Loading
Loading
Loading
Loading
+3 −49
Changes for dom/media/platforms/ffmpeg/FFmpegVideoDecoder.cpp: 3 added lines, 49 removed lines.
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@

#include "FFmpegLog.h"
#include "FFmpegUtils.h"
#include "FFmpegVideoUtils.h"
#include "ImageContainer.h"
#include "MP4Decoder.h"
#include "MediaInfo.h"
@@ -1534,55 +1535,8 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImage(

  b.mPlanes[0].mWidth = mFrame->width;
  b.mPlanes[0].mHeight = mFrame->height;
  if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV444P ||
      mCodecContext->pix_fmt == AV_PIX_FMT_YUV444P10LE ||
      mCodecContext->pix_fmt == AV_PIX_FMT_GBRP ||
      mCodecContext->pix_fmt == AV_PIX_FMT_GBRP10LE
#if LIBAVCODEC_VERSION_MAJOR >= 57
      || mCodecContext->pix_fmt == AV_PIX_FMT_YUV444P12LE
#endif
  ) {
    b.mPlanes[1].mWidth = b.mPlanes[2].mWidth = mFrame->width;
    b.mPlanes[1].mHeight = b.mPlanes[2].mHeight = mFrame->height;
    if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV444P10LE ||
        mCodecContext->pix_fmt == AV_PIX_FMT_GBRP10LE) {
      b.mColorDepth = gfx::ColorDepth::COLOR_10;
    }
#if LIBAVCODEC_VERSION_MAJOR >= 57
    else if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV444P12LE) {
      b.mColorDepth = gfx::ColorDepth::COLOR_12;
    }
#endif
  } else if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV422P ||
             mCodecContext->pix_fmt == AV_PIX_FMT_YUV422P10LE
#if LIBAVCODEC_VERSION_MAJOR >= 57
             || mCodecContext->pix_fmt == AV_PIX_FMT_YUV422P12LE
#endif
  ) {
    b.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH;
    b.mPlanes[1].mWidth = b.mPlanes[2].mWidth = (mFrame->width + 1) >> 1;
    b.mPlanes[1].mHeight = b.mPlanes[2].mHeight = mFrame->height;
    if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV422P10LE) {
      b.mColorDepth = gfx::ColorDepth::COLOR_10;
    }
#if LIBAVCODEC_VERSION_MAJOR >= 57
    else if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV422P12LE) {
      b.mColorDepth = gfx::ColorDepth::COLOR_12;
    }
#endif
  } else {
    b.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
    b.mPlanes[1].mWidth = b.mPlanes[2].mWidth = (mFrame->width + 1) >> 1;
    b.mPlanes[1].mHeight = b.mPlanes[2].mHeight = (mFrame->height + 1) >> 1;
    if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV420P10LE) {
      b.mColorDepth = gfx::ColorDepth::COLOR_10;
    }
#if LIBAVCODEC_VERSION_MAJOR >= 57
    else if (mCodecContext->pix_fmt == AV_PIX_FMT_YUV420P12LE) {
      b.mColorDepth = gfx::ColorDepth::COLOR_12;
    }
#endif
  }
  SetChromaPlaneGeometryFromAVFormat(b, static_cast<int>(mFrame->format),
                                     mFrame->width, mFrame->height);
  b.mYUVColorSpace = GetFrameColorSpace();
  b.mColorRange = GetFrameColorRange();

+95 −0
Changes for dom/media/platforms/ffmpeg/FFmpegVideoUtils.h: 95 added lines, 0 removed lines.
Original line number Diff line number Diff line
/* 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 DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGVIDEOUTILS_H_
#define DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGVIDEOUTILS_H_

#include "MediaData.h"
#include "libavcodec/version.h"
#include "libavutil/pixfmt.h"

#if LIBAVCODEC_VERSION_MAJOR < 54
#  ifndef AV_PIX_FMT_YUV420P10LE
#    define AV_PIX_FMT_YUV420P10LE PIX_FMT_YUV420P10LE
#  endif
#  ifndef AV_PIX_FMT_YUV422P
#    define AV_PIX_FMT_YUV422P PIX_FMT_YUV422P
#  endif
#  ifndef AV_PIX_FMT_YUV422P10LE
#    define AV_PIX_FMT_YUV422P10LE PIX_FMT_YUV422P10LE
#  endif
#  ifndef AV_PIX_FMT_YUV444P
#    define AV_PIX_FMT_YUV444P PIX_FMT_YUV444P
#  endif
#  ifndef AV_PIX_FMT_YUV444P10LE
#    define AV_PIX_FMT_YUV444P10LE PIX_FMT_YUV444P10LE
#  endif
#  ifndef AV_PIX_FMT_GBRP
#    define AV_PIX_FMT_GBRP PIX_FMT_GBRP
#  endif
#  ifndef AV_PIX_FMT_GBRP10LE
#    define AV_PIX_FMT_GBRP10LE PIX_FMT_GBRP10LE
#  endif
#endif

namespace mozilla {

// Fills the chroma plane geometry (Cb/Cr dimensions, chroma subsampling and
// colour depth) of aBuffer from aFormat, an AVPixelFormat value, and the luma
// dimensions aWidth and aHeight. The luma plane (index 0) must already be
// populated by the caller.
inline void SetChromaPlaneGeometryFromAVFormat(VideoData::YCbCrBuffer& aBuffer,
                                               int aFormat, int aWidth,
                                               int aHeight) {
  if (aFormat == AV_PIX_FMT_YUV444P || aFormat == AV_PIX_FMT_YUV444P10LE ||
      aFormat == AV_PIX_FMT_GBRP || aFormat == AV_PIX_FMT_GBRP10LE
#if LIBAVCODEC_VERSION_MAJOR >= 57
      || aFormat == AV_PIX_FMT_YUV444P12LE
#endif
  ) {
    aBuffer.mPlanes[1].mWidth = aBuffer.mPlanes[2].mWidth = aWidth;
    aBuffer.mPlanes[1].mHeight = aBuffer.mPlanes[2].mHeight = aHeight;
    if (aFormat == AV_PIX_FMT_YUV444P10LE || aFormat == AV_PIX_FMT_GBRP10LE) {
      aBuffer.mColorDepth = gfx::ColorDepth::COLOR_10;
    }
#if LIBAVCODEC_VERSION_MAJOR >= 57
    else if (aFormat == AV_PIX_FMT_YUV444P12LE) {
      aBuffer.mColorDepth = gfx::ColorDepth::COLOR_12;
    }
#endif
  } else if (aFormat == AV_PIX_FMT_YUV422P || aFormat == AV_PIX_FMT_YUV422P10LE
#if LIBAVCODEC_VERSION_MAJOR >= 57
             || aFormat == AV_PIX_FMT_YUV422P12LE
#endif
  ) {
    aBuffer.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH;
    aBuffer.mPlanes[1].mWidth = aBuffer.mPlanes[2].mWidth = (aWidth + 1) >> 1;
    aBuffer.mPlanes[1].mHeight = aBuffer.mPlanes[2].mHeight = aHeight;
    if (aFormat == AV_PIX_FMT_YUV422P10LE) {
      aBuffer.mColorDepth = gfx::ColorDepth::COLOR_10;
    }
#if LIBAVCODEC_VERSION_MAJOR >= 57
    else if (aFormat == AV_PIX_FMT_YUV422P12LE) {
      aBuffer.mColorDepth = gfx::ColorDepth::COLOR_12;
    }
#endif
  } else {
    aBuffer.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
    aBuffer.mPlanes[1].mWidth = aBuffer.mPlanes[2].mWidth = (aWidth + 1) >> 1;
    aBuffer.mPlanes[1].mHeight = aBuffer.mPlanes[2].mHeight =
        (aHeight + 1) >> 1;
    if (aFormat == AV_PIX_FMT_YUV420P10LE) {
      aBuffer.mColorDepth = gfx::ColorDepth::COLOR_10;
    }
#if LIBAVCODEC_VERSION_MAJOR >= 57
    else if (aFormat == AV_PIX_FMT_YUV420P12LE) {
      aBuffer.mColorDepth = gfx::ColorDepth::COLOR_12;
    }
#endif
  }
}

}  // namespace mozilla

#endif  // DOM_MEDIA_PLATFORMS_FFMPEG_FFMPEGVIDEOUTILS_H_