зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1833354 - Add build options for VAAPI and V4L2. r=media-playback-reviewers,glandium,stransky
Add separate options to control whether we build VA-API and/or V4L2 hardware video decode. These options default to enabled on the platforms where these decoders are used. The downstream MOZ_WAYLAND_USE_HWDECODE build option is used within the FFmpeg platform and is only set when building against a supported version of the FFmpeg libraries (i.e. not for ffmpeg57). Differential Revision: https://phabricator.services.mozilla.com/D178945
This commit is contained in:
Родитель
ef6c673ba7
Коммит
8ab689c9e9
|
@ -14,7 +14,7 @@ extern "C" {
|
|||
#include "libavcodec/avcodec.h"
|
||||
#include "libavutil/avutil.h"
|
||||
#include "libavutil/mem.h"
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
# include "libavutil/hwcontext_vaapi.h"
|
||||
# include "libavutil/hwcontext_drm.h"
|
||||
#endif
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#if LIBAVCODEC_VERSION_MAJOR >= 58
|
||||
# include "mozilla/ProfilerMarkers.h"
|
||||
#endif
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
# include "H264.h"
|
||||
# include "mozilla/gfx/gfxVars.h"
|
||||
# include "mozilla/layers/DMABUFSurfaceImage.h"
|
||||
|
@ -63,7 +63,7 @@
|
|||
#endif
|
||||
|
||||
// Forward declare from va.h
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
typedef int VAStatus;
|
||||
# define VA_EXPORT_SURFACE_READ_ONLY 0x0001
|
||||
# define VA_EXPORT_SURFACE_SEPARATE_LAYERS 0x0004
|
||||
|
@ -85,7 +85,7 @@ typedef mozilla::layers::PlanarYCbCrImage PlanarYCbCrImage;
|
|||
|
||||
namespace mozilla {
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
nsTArray<AVCodecID> FFmpegVideoDecoder<LIBAV_VER>::mAcceleratedFormats;
|
||||
#endif
|
||||
|
||||
|
@ -146,7 +146,7 @@ static AVPixelFormat ChoosePixelFormat(AVCodecContext* aCodecContext,
|
|||
return AV_PIX_FMT_NONE;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
static AVPixelFormat ChooseVAAPIPixelFormat(AVCodecContext* aCodecContext,
|
||||
const AVPixelFormat* aFormats) {
|
||||
FFMPEG_LOG("Choosing FFmpeg pixel format for VA-API video decoding.");
|
||||
|
@ -373,7 +373,7 @@ void FFmpegVideoDecoder<LIBAV_VER>::PtsCorrectionContext::Reset() {
|
|||
mLastDts = INT64_MIN;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
void FFmpegVideoDecoder<LIBAV_VER>::InitHWDecodingPrefs() {
|
||||
if (!mEnableHardwareDecoding) {
|
||||
FFMPEG_LOG("VAAPI is disabled by parent decoder module.");
|
||||
|
@ -425,7 +425,7 @@ FFmpegVideoDecoder<LIBAV_VER>::FFmpegVideoDecoder(
|
|||
bool aLowLatency, bool aDisableHardwareDecoding,
|
||||
Maybe<TrackingId> aTrackingId)
|
||||
: FFmpegDataDecoder(aLib, GetCodecId(aConfig.mMimeType)),
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
mVAAPIDeviceContext(nullptr),
|
||||
mEnableHardwareDecoding(!aDisableHardwareDecoding),
|
||||
mDisplay(nullptr),
|
||||
|
@ -447,7 +447,7 @@ FFmpegVideoDecoder<LIBAV_VER>::FFmpegVideoDecoder(
|
|||
// initialization.
|
||||
mExtraData = new MediaByteBuffer;
|
||||
mExtraData->AppendElements(*aConfig.mExtraData);
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
InitHWDecodingPrefs();
|
||||
#endif
|
||||
}
|
||||
|
@ -462,7 +462,7 @@ FFmpegVideoDecoder<LIBAV_VER>::~FFmpegVideoDecoder() {
|
|||
RefPtr<MediaDataDecoder::InitPromise> FFmpegVideoDecoder<LIBAV_VER>::Init() {
|
||||
MediaResult rv;
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
if (mEnableHardwareDecoding) {
|
||||
rv = InitVAAPIDecoder();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
@ -821,7 +821,7 @@ nsCString FFmpegVideoDecoder<LIBAV_VER>::GetCodecName() const {
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
void FFmpegVideoDecoder<LIBAV_VER>::InitVAAPICodecContext() {
|
||||
mCodecContext->width = mInfo.mImage.width;
|
||||
mCodecContext->height = mInfo.mImage.height;
|
||||
|
@ -952,7 +952,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::DoDecode(
|
|||
return MediaResult(NS_ERROR_OUT_OF_MEMORY, __func__);
|
||||
}
|
||||
|
||||
# ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
# ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
// Release unused VA-API surfaces before avcodec_receive_frame() as
|
||||
// ffmpeg recycles VASurface for HW decoding.
|
||||
if (mVideoFramePool) {
|
||||
|
@ -981,7 +981,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::DoDecode(
|
|||
decodeStart = TimeStamp::Now();
|
||||
|
||||
MediaResult rv;
|
||||
# ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
# ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
if (IsHardwareAccelerated()) {
|
||||
if (mMissedDecodeInAverangeTime > HW_DECODE_LATE_FRAMES) {
|
||||
PROFILER_MARKER_TEXT("FFmpegVideoDecoder::DoDecode", MEDIA_PLAYBACK, {},
|
||||
|
@ -1325,7 +1325,7 @@ MediaResult FFmpegVideoDecoder<LIBAV_VER>::CreateImage(
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
bool FFmpegVideoDecoder<LIBAV_VER>::GetVAAPISurfaceDescriptor(
|
||||
VADRMPRIMESurfaceDescriptor* aVaDesc) {
|
||||
VASurfaceID surface_id = (VASurfaceID)(uintptr_t)mFrame->data[3];
|
||||
|
@ -1432,7 +1432,7 @@ AVCodecID FFmpegVideoDecoder<LIBAV_VER>::GetCodecId(
|
|||
|
||||
void FFmpegVideoDecoder<LIBAV_VER>::ProcessShutdown() {
|
||||
MOZ_ASSERT(mTaskQueue->IsOnCurrentThread());
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
mVideoFramePool = nullptr;
|
||||
if (IsHardwareAccelerated()) {
|
||||
mLib->av_buffer_unref(&mVAAPIDeviceContext);
|
||||
|
@ -1443,14 +1443,14 @@ void FFmpegVideoDecoder<LIBAV_VER>::ProcessShutdown() {
|
|||
|
||||
bool FFmpegVideoDecoder<LIBAV_VER>::IsHardwareAccelerated(
|
||||
nsACString& aFailureReason) const {
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
return !!mVAAPIDeviceContext;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
bool FFmpegVideoDecoder<LIBAV_VER>::IsFormatAccelerated(
|
||||
AVCodecID aCodecID) const {
|
||||
for (const auto& format : mAcceleratedFormats) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
#if LIBAVCODEC_VERSION_MAJOR >= 57 && LIBAVUTIL_VERSION_MAJOR >= 56
|
||||
# include "mozilla/layers/TextureClient.h"
|
||||
#endif
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
# include "FFmpegVideoFramePool.h"
|
||||
#endif
|
||||
|
||||
|
@ -123,7 +123,7 @@ class FFmpegVideoDecoder<LIBAV_VER>
|
|||
int32_t aHeight) const;
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
void InitHWDecodingPrefs();
|
||||
MediaResult InitVAAPIDecoder();
|
||||
bool CreateVAAPIDeviceContext();
|
||||
|
@ -139,7 +139,7 @@ class FFmpegVideoDecoder<LIBAV_VER>
|
|||
MediaDataDecoder::DecodedData& aResults);
|
||||
#endif
|
||||
|
||||
#ifdef MOZ_WAYLAND_USE_VAAPI
|
||||
#ifdef MOZ_WAYLAND_USE_HWDECODE
|
||||
AVBufferRef* mVAAPIDeviceContext;
|
||||
bool mEnableHardwareDecoding;
|
||||
VADisplay mDisplay;
|
||||
|
|
|
@ -28,12 +28,11 @@ if CONFIG['CC_TYPE'] == 'gcc':
|
|||
]
|
||||
if CONFIG['MOZ_WAYLAND']:
|
||||
CXXFLAGS += CONFIG['MOZ_GTK3_CFLAGS']
|
||||
DEFINES['MOZ_WAYLAND_USE_VAAPI'] = 1
|
||||
if CONFIG['MOZ_ENABLE_VAAPI'] or CONFIG['MOZ_ENABLE_V4L2']:
|
||||
UNIFIED_SOURCES += ['../FFmpegVideoFramePool.cpp']
|
||||
LOCAL_INCLUDES += ['/third_party/drm/drm/include/libdrm/']
|
||||
USE_LIBS += ['mozva']
|
||||
UNIFIED_SOURCES += [
|
||||
'../FFmpegVideoFramePool.cpp',
|
||||
]
|
||||
LOCAL_INCLUDES += ["/third_party/drm/drm/include/libdrm/"]
|
||||
DEFINES['MOZ_WAYLAND_USE_HWDECODE'] = 1
|
||||
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
|
|
|
@ -28,12 +28,11 @@ if CONFIG["CC_TYPE"] == "gcc":
|
|||
]
|
||||
if CONFIG["MOZ_WAYLAND"]:
|
||||
CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
|
||||
DEFINES["MOZ_WAYLAND_USE_VAAPI"] = 1
|
||||
USE_LIBS += ["mozva"]
|
||||
UNIFIED_SOURCES += [
|
||||
"../FFmpegVideoFramePool.cpp",
|
||||
]
|
||||
if CONFIG["MOZ_ENABLE_VAAPI"] or CONFIG["MOZ_ENABLE_V4L2"]:
|
||||
UNIFIED_SOURCES += ["../FFmpegVideoFramePool.cpp"]
|
||||
LOCAL_INCLUDES += ["/third_party/drm/drm/include/libdrm/"]
|
||||
USE_LIBS += ["mozva"]
|
||||
DEFINES["MOZ_WAYLAND_USE_HWDECODE"] = 1
|
||||
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
|
|
|
@ -28,12 +28,11 @@ if CONFIG["CC_TYPE"] == "gcc":
|
|||
]
|
||||
if CONFIG["MOZ_WAYLAND"]:
|
||||
CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
|
||||
DEFINES["MOZ_WAYLAND_USE_VAAPI"] = 1
|
||||
USE_LIBS += ["mozva"]
|
||||
UNIFIED_SOURCES += [
|
||||
"../FFmpegVideoFramePool.cpp",
|
||||
]
|
||||
if CONFIG["MOZ_ENABLE_VAAPI"] or CONFIG["MOZ_ENABLE_V4L2"]:
|
||||
UNIFIED_SOURCES += ["../FFmpegVideoFramePool.cpp"]
|
||||
LOCAL_INCLUDES += ["/third_party/drm/drm/include/libdrm/"]
|
||||
USE_LIBS += ["mozva"]
|
||||
DEFINES["MOZ_WAYLAND_USE_HWDECODE"] = 1
|
||||
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
|
|
|
@ -39,12 +39,11 @@ DEFINES["USING_MOZFFVPX"] = True
|
|||
|
||||
if CONFIG["MOZ_WAYLAND"]:
|
||||
CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
|
||||
DEFINES["MOZ_WAYLAND_USE_VAAPI"] = 1
|
||||
USE_LIBS += ["mozva"]
|
||||
UNIFIED_SOURCES += [
|
||||
"../FFmpegVideoFramePool.cpp",
|
||||
]
|
||||
if CONFIG["MOZ_ENABLE_VAAPI"] or CONFIG["MOZ_ENABLE_V4L2"]:
|
||||
UNIFIED_SOURCES += ["../FFmpegVideoFramePool.cpp"]
|
||||
LOCAL_INCLUDES += ["/third_party/drm/drm/include/libdrm/"]
|
||||
USE_LIBS += ["mozva"]
|
||||
DEFINES["MOZ_WAYLAND_USE_HWDECODE"] = 1
|
||||
|
||||
include("/ipc/chromium/chromium-config.mozbuild")
|
||||
|
||||
|
|
|
@ -505,6 +505,31 @@ def wayland_headers(wayland, toolkit_gtk, artifacts):
|
|||
set_config("MOZ_WAYLAND", depends_if(wayland_headers)(lambda _: True))
|
||||
set_define("MOZ_WAYLAND", depends_if(wayland_headers)(lambda _: True))
|
||||
|
||||
# Hardware-accelerated video decode with VAAPI and V4L2
|
||||
# ==============================================================
|
||||
|
||||
|
||||
@depends(target, wayland_headers)
|
||||
def vaapi(target, wayland_headers):
|
||||
# VAAPI is only used in Wayland. It's mostly used on x86(-64) but is
|
||||
# sometimes used on ARM/ARM64 SOCs. Wayland implies GTK and Linux.
|
||||
if target.cpu in ("arm", "aarch64", "x86", "x86_64") and wayland_headers:
|
||||
return True
|
||||
|
||||
|
||||
@depends(target, wayland_headers)
|
||||
def v4l2(target, wayland_headers):
|
||||
# V4L2 decode is only used in Wayland, and generally only appears on
|
||||
# embedded SOCs. Wayland implies GTK and Linux.
|
||||
if target.cpu in ("arm", "aarch64", "riscv64") and wayland_headers:
|
||||
return True
|
||||
|
||||
|
||||
set_config("MOZ_ENABLE_VAAPI", True, when=vaapi)
|
||||
set_config("MOZ_ENABLE_V4L2", True, when=v4l2)
|
||||
set_define("MOZ_ENABLE_VAAPI", True, when=vaapi)
|
||||
set_define("MOZ_ENABLE_V4L2", True, when=v4l2)
|
||||
|
||||
# GL Provider
|
||||
# ==============================================================
|
||||
option("--with-gl-provider", nargs=1, help="Set GL provider backend type")
|
||||
|
|
|
@ -645,7 +645,7 @@ void GfxInfo::GetDataVAAPI() {
|
|||
}
|
||||
mIsVAAPISupported = Some(false);
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
#ifdef MOZ_ENABLE_VAAPI
|
||||
char* vaapiData = nullptr;
|
||||
auto free = mozilla::MakeScopeExit([&] { g_free((void*)vaapiData); });
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче