summaryrefslogtreecommitdiffstats
path: root/dom/media/platforms/ffmpeg/ffvpx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /dom/media/platforms/ffmpeg/ffvpx
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/platforms/ffmpeg/ffvpx')
-rw-r--r--dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp163
-rw-r--r--dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.h42
-rw-r--r--dom/media/platforms/ffmpeg/ffvpx/moz.build56
3 files changed, 261 insertions, 0 deletions
diff --git a/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
new file mode 100644
index 0000000000..ba9ca4834e
--- /dev/null
+++ b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.cpp
@@ -0,0 +1,163 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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/. */
+
+#include "FFVPXRuntimeLinker.h"
+#include "FFmpegLibWrapper.h"
+#include "FFmpegLog.h"
+#include "BinaryPath.h"
+#include "mozilla/FileUtils.h"
+#include "nsLocalFile.h"
+#include "prmem.h"
+#include "prlink.h"
+#ifdef XP_WIN
+# include <windows.h>
+#endif
+
+namespace mozilla {
+
+template <int V>
+class FFmpegDecoderModule {
+ public:
+ static already_AddRefed<PlatformDecoderModule> Create(FFmpegLibWrapper*);
+};
+
+template <int V>
+class FFmpegEncoderModule {
+ public:
+ static already_AddRefed<PlatformEncoderModule> Create(FFmpegLibWrapper*);
+};
+
+static FFmpegLibWrapper sFFVPXLib;
+
+StaticMutex FFVPXRuntimeLinker::sMutex;
+
+FFVPXRuntimeLinker::LinkStatus FFVPXRuntimeLinker::sLinkStatus =
+ LinkStatus_INIT;
+
+static PRLibrary* MozAVLink(nsIFile* aFile) {
+ PRLibSpec lspec;
+ PathString path = aFile->NativePath();
+#ifdef XP_WIN
+ lspec.type = PR_LibSpec_PathnameU;
+ lspec.value.pathname_u = path.get();
+#else
+# if defined(XP_OPENBSD)
+ /* on OpenBSD, libmozavcodec.so and libmozavutil.so are preloaded before
+ * sandboxing so make sure only the filename is passed to
+ * PR_LoadLibraryWithFlags(), dlopen() will return the preloaded library
+ * handle instead of failing to find it due to sandboxing */
+ nsAutoCString leaf;
+ nsresult rv = aFile->GetNativeLeafName(leaf);
+ if (NS_SUCCEEDED(rv)) {
+ path = PathString(leaf);
+ }
+# endif // defined(XP_OPENBSD)
+ lspec.type = PR_LibSpec_Pathname;
+ lspec.value.pathname = path.get();
+#endif
+#ifdef MOZ_WIDGET_ANDROID
+ PRLibrary* lib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_GLOBAL);
+#else
+ PRLibrary* lib = PR_LoadLibraryWithFlags(lspec, PR_LD_NOW | PR_LD_LOCAL);
+#endif
+ if (!lib) {
+ FFMPEGV_LOG("unable to load library %s", aFile->HumanReadablePath().get());
+ }
+ return lib;
+}
+
+/* static */
+bool FFVPXRuntimeLinker::Init() {
+ // Enter critical section to set up ffvpx.
+ StaticMutexAutoLock lock(sMutex);
+
+ if (sLinkStatus) {
+ return sLinkStatus == LinkStatus_SUCCEEDED;
+ }
+
+ sLinkStatus = LinkStatus_FAILED;
+
+#ifdef MOZ_WIDGET_GTK
+ sFFVPXLib.LinkVAAPILibs();
+#endif
+
+ nsCOMPtr<nsIFile> libFile;
+ if (NS_FAILED(mozilla::BinaryPath::GetFile(getter_AddRefs(libFile)))) {
+ return false;
+ }
+
+#ifdef XP_DARWIN
+ if (!XRE_IsParentProcess() &&
+ (XRE_GetChildProcBinPathType(XRE_GetProcessType()) ==
+ BinPathType::PluginContainer)) {
+ // On macOS, PluginContainer processes have their binary in a
+ // plugin-container.app/Content/MacOS/ directory.
+ nsCOMPtr<nsIFile> parentDir1, parentDir2;
+ if (NS_FAILED(libFile->GetParent(getter_AddRefs(parentDir1)))) {
+ return false;
+ }
+ if (NS_FAILED(parentDir1->GetParent(getter_AddRefs(parentDir2)))) {
+ return false;
+ }
+ if (NS_FAILED(parentDir2->GetParent(getter_AddRefs(libFile)))) {
+ return false;
+ }
+ }
+#endif
+
+ if (NS_FAILED(libFile->SetNativeLeafName(MOZ_DLL_PREFIX
+ "mozavutil" MOZ_DLL_SUFFIX ""_ns))) {
+ return false;
+ }
+ sFFVPXLib.mAVUtilLib = MozAVLink(libFile);
+
+ if (NS_FAILED(libFile->SetNativeLeafName(
+ MOZ_DLL_PREFIX "mozavcodec" MOZ_DLL_SUFFIX ""_ns))) {
+ return false;
+ }
+ sFFVPXLib.mAVCodecLib = MozAVLink(libFile);
+ FFmpegLibWrapper::LinkResult res = sFFVPXLib.Link();
+ FFMPEGP_LOG("Link result: %s", FFmpegLibWrapper::LinkResultToString(res));
+ if (res == FFmpegLibWrapper::LinkResult::Success) {
+ sLinkStatus = LinkStatus_SUCCEEDED;
+ return true;
+ }
+ return false;
+}
+
+/* static */
+already_AddRefed<PlatformDecoderModule> FFVPXRuntimeLinker::CreateDecoder() {
+ if (!Init()) {
+ return nullptr;
+ }
+ return FFmpegDecoderModule<FFVPX_VERSION>::Create(&sFFVPXLib);
+}
+
+/* static */
+already_AddRefed<PlatformEncoderModule> FFVPXRuntimeLinker::CreateEncoder() {
+ if (!Init()) {
+ return nullptr;
+ }
+ return FFmpegEncoderModule<FFVPX_VERSION>::Create(&sFFVPXLib);
+}
+
+/* static */
+void FFVPXRuntimeLinker::GetRDFTFuncs(FFmpegRDFTFuncs* aOutFuncs) {
+ []() MOZ_NO_THREAD_SAFETY_ANALYSIS {
+ MOZ_ASSERT(sLinkStatus != LinkStatus_INIT);
+ }();
+ if (sFFVPXLib.av_rdft_init && sFFVPXLib.av_rdft_calc &&
+ sFFVPXLib.av_rdft_end) {
+ aOutFuncs->init = sFFVPXLib.av_rdft_init;
+ aOutFuncs->calc = sFFVPXLib.av_rdft_calc;
+ aOutFuncs->end = sFFVPXLib.av_rdft_end;
+ } else {
+ NS_WARNING("RDFT functions expected but not found");
+ *aOutFuncs = FFmpegRDFTFuncs(); // zero
+ }
+}
+
+} // namespace mozilla
diff --git a/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.h b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.h
new file mode 100644
index 0000000000..e52f108272
--- /dev/null
+++ b/dom/media/platforms/ffmpeg/ffvpx/FFVPXRuntimeLinker.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et cindent: */
+/* 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 __FFVPXRuntimeLinker_h__
+#define __FFVPXRuntimeLinker_h__
+
+#include "PlatformDecoderModule.h"
+#include "PlatformEncoderModule.h"
+#include "mozilla/StaticMutex.h"
+#include "mozilla/ThreadSafety.h"
+
+struct FFmpegRDFTFuncs;
+
+namespace mozilla {
+
+class FFVPXRuntimeLinker {
+ public:
+ static bool Init() MOZ_EXCLUDES(sMutex);
+ static already_AddRefed<PlatformDecoderModule> CreateDecoder();
+ static already_AddRefed<PlatformEncoderModule> CreateEncoder();
+
+ // Call (on any thread) after Init().
+ static void GetRDFTFuncs(FFmpegRDFTFuncs* aOutFuncs);
+
+ private:
+ // Provide critical-section for Init() and sLinkStatus.
+ static StaticMutex sMutex;
+
+ // Set once on the main thread and then read from other threads.
+ static enum LinkStatus {
+ LinkStatus_INIT = 0,
+ LinkStatus_FAILED,
+ LinkStatus_SUCCEEDED
+ } sLinkStatus MOZ_GUARDED_BY(sMutex);
+};
+
+} // namespace mozilla
+
+#endif /* __FFVPXRuntimeLinker_h__ */
diff --git a/dom/media/platforms/ffmpeg/ffvpx/moz.build b/dom/media/platforms/ffmpeg/ffvpx/moz.build
new file mode 100644
index 0000000000..97a224b08b
--- /dev/null
+++ b/dom/media/platforms/ffmpeg/ffvpx/moz.build
@@ -0,0 +1,56 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+LOCAL_INCLUDES += ["/xpcom/build"]
+EXPORTS += [
+ "FFVPXRuntimeLinker.h",
+]
+
+UNIFIED_SOURCES += [
+ "../FFmpegAudioDecoder.cpp",
+ "../FFmpegDataDecoder.cpp",
+ "../FFmpegDecoderModule.cpp",
+ "../FFmpegEncoderModule.cpp",
+ "../FFmpegVideoDecoder.cpp",
+ "../FFmpegVideoEncoder.cpp",
+]
+SOURCES += [
+ "FFVPXRuntimeLinker.cpp",
+]
+LOCAL_INCLUDES += [
+ "..",
+ "../ffmpeg60/include",
+ "/media/mozva",
+]
+
+CXXFLAGS += ["-Wno-deprecated-declarations"]
+if CONFIG["CC_TYPE"] == "clang":
+ CXXFLAGS += [
+ "-Wno-unknown-attributes",
+ ]
+if CONFIG["CC_TYPE"] == "gcc":
+ CXXFLAGS += [
+ "-Wno-attributes",
+ ]
+
+DEFINES["FFVPX_VERSION"] = 46465650
+DEFINES["USING_MOZFFVPX"] = True
+
+if CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
+ CXXFLAGS += CONFIG["MOZ_GTK3_CFLAGS"]
+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_USE_HWDECODE"] = 1
+
+include("/ipc/chromium/chromium-config.mozbuild")
+
+LOCAL_INCLUDES += [
+ "/media/libyuv/libyuv/include",
+]
+
+FINAL_LIBRARY = "xul"