Blame qtwebengine-blink-dlopen-h264.patch

a684f95
diff --git a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/BUILD.gn b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/BUILD.gn
6c9da4f
index cf6de49be..61e8879d6 100644
a684f95
--- a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/BUILD.gn
a684f95
+++ b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/BUILD.gn
a684f95
@@ -5,12 +5,23 @@
a684f95
 import("//build/buildflag_header.gni")
a684f95
 import("//third_party/blink/renderer/modules/modules.gni")
a684f95
 import("//third_party/webrtc/webrtc.gni")
a684f95
+import("//tools/generate_stubs/rules.gni")
6c9da4f
a684f95
 buildflag_header("buildflags") {
a684f95
   header = "buildflags.h"
a684f95
   flags = [ "RTC_USE_H264=$rtc_use_h264" ]
a684f95
 }
6c9da4f
a684f95
+if (rtc_use_h264 && rtc_dlopen_openh264) {
a684f95
+  # When OpenH264 is not directly linked, use stubs to allow for dlopening of
a684f95
+  # the binary.
a684f95
+  generate_stubs("openh264_stubs") {
a684f95
+    extra_header = "openh264_stub_header.fragment"
a684f95
+    output_name = "openh264_stubs"
a684f95
+    sigs = [ "openh264.sigs" ]
a684f95
+  }
a684f95
+}
a684f95
+
a684f95
 blink_modules_sources("mediarecorder") {
a684f95
   sources = [
a684f95
     "audio_track_encoder.cc",
a684f95
@@ -56,6 +67,11 @@ blink_modules_sources("mediarecorder") {
a684f95
       "h264_encoder.h",
a684f95
     ]
6c9da4f
a684f95
-    deps += [ "//third_party/openh264:encoder" ]
a684f95
+    if (rtc_dlopen_openh264) {
a684f95
+      defines = [ "BLINK_DLOPEN_OPENH264" ]
a684f95
+      deps += [ ":openh264_stubs" ]
a684f95
+    } else {
a684f95
+      deps += [ "//third_party/openh264:encoder" ]
a684f95
+    }
a684f95
   }
a684f95
 }
a684f95
diff --git a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.cc b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.cc
6c9da4f
index 4253f3280..56ea1574c 100644
a684f95
--- a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.cc
a684f95
+++ b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.cc
6c9da4f
@@ -23,9 +23,21 @@
6c9da4f
 #include "third_party/openh264/src/codec/api/wels/codec_def.h"
a684f95
 #include "ui/gfx/geometry/size.h"
a684f95
a684f95
+#if defined(BLINK_DLOPEN_OPENH264)
a684f95
+#include "third_party/blink/renderer/modules/mediarecorder/openh264_stubs.h"
a684f95
+#endif  // defined(BLINK_DLOPEN_OPENH264)
a684f95
+
a684f95
 namespace blink {
a684f95
 namespace {
a684f95
a684f95
+#if defined(BLINK_DLOPEN_OPENH264)
a684f95
+using third_party_blink_renderer_modules_mediarecorder::InitializeStubs;
a684f95
+using third_party_blink_renderer_modules_mediarecorder::kModuleOpenh264;
a684f95
+using third_party_blink_renderer_modules_mediarecorder::StubPathMap;
a684f95
+
a684f95
+static constexpr char kOpenH264Lib[] = "libopenh264.so.7";
a684f95
+#endif
a684f95
+
a684f95
 absl::optional<EProfileIdc> ToOpenH264Profile(
a684f95
     media::VideoCodecProfile profile) {
a684f95
   static const HashMap<media::VideoCodecProfile, EProfileIdc>
6c9da4f
@@ -86,6 +98,13 @@ H264Encoder::H264Encoder(
6c9da4f
     : Encoder(on_encoded_video_cb, bits_per_second),
a684f95
       codec_profile_(codec_profile) {
a684f95
   DCHECK_EQ(codec_profile_.codec_id, VideoTrackRecorder::CodecId::kH264);
a684f95
+
a684f95
+#if defined(BLINK_DLOPEN_OPENH264)
a684f95
+  StubPathMap paths;
a684f95
+  paths[kModuleOpenh264].push_back(kOpenH264Lib);
a684f95
+
a684f95
+  openh264_dlopened_ = InitializeStubs(paths);
a684f95
+#endif
a684f95
 }
a684f95
6c9da4f
 // Needs to be defined here to combat a Windows linking issue.
6c9da4f
@@ -167,6 +186,14 @@ void H264Encoder::EncodeFrame(scoped_refptr<media::VideoFrame> frame,
6c9da4f
6c9da4f
 bool H264Encoder::ConfigureEncoder(const gfx::Size& size) {
6c9da4f
   TRACE_EVENT0("media", "H264Encoder::ConfigureEncoder");
a684f95
+
a684f95
+#if defined(BLINK_DLOPEN_OPENH264)
a684f95
+  if (!openh264_dlopened_) {
a684f95
+    NOTREACHED() << "Failed to dlopen openh264";
a684f95
+    return false;
a684f95
+  }
a684f95
+#endif
a684f95
+
a684f95
   ISVCEncoder* temp_encoder = nullptr;
a684f95
   if (WelsCreateSVCEncoder(&temp_encoder) != 0) {
a684f95
     NOTREACHED() << "Failed to create OpenH264 encoder";
a684f95
diff --git a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.h b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.h
6c9da4f
index 1d9d7bc5a..a5b7eefe3 100644
a684f95
--- a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.h
a684f95
+++ b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/h264_encoder.h
6c9da4f
@@ -58,6 +58,8 @@ class MODULES_EXPORT H264Encoder final : public VideoTrackRecorder::Encoder {
6c9da4f
   // The |VideoFrame::timestamp()| of the first received frame.
a684f95
   base::TimeTicks first_frame_timestamp_;
6c9da4f
   base::WeakPtrFactory<H264Encoder> weak_factory_{this};
a684f95
+
a684f95
+  bool openh264_dlopened_ = false;
a684f95
 };
a684f95
a684f95
 }  // namespace blink
a684f95
diff --git a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/openh264.sigs b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/openh264.sigs
a684f95
new file mode 100644
6c9da4f
index 000000000..4924f8e9a
a684f95
--- /dev/null
a684f95
+++ b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/openh264.sigs
a684f95
@@ -0,0 +1,14 @@
a684f95
+// Copyright 2022 The WebRTC project authors. All rights reserved.
a684f95
+// Use of this source code is governed by a BSD-style license that can be
a684f95
+// found in the LICENSE file.
a684f95
+
a684f95
+//------------------------------------------------
a684f95
+// Functions from OpenH264.
a684f95
+//------------------------------------------------
a684f95
+int WelsCreateSVCEncoder(ISVCEncoder **ppEncoder);
a684f95
+void WelsDestroySVCEncoder(ISVCEncoder *pEncoder);
a684f95
+int WelsGetDecoderCapability(SDecoderCapability *pDecCapability);
a684f95
+long WelsCreateDecoder(ISVCDecoder **ppDecoder);
a684f95
+void WelsDestroyDecoder(ISVCDecoder *pDecoder);
a684f95
+OpenH264Version WelsGetCodecVersion(void);
a684f95
+void WelsGetCodecVersionEx(OpenH264Version *pVersion);
a684f95
diff --git a/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/openh264_stub_header.fragment b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/openh264_stub_header.fragment
a684f95
new file mode 100644
6c9da4f
index 000000000..e8a3727a0
a684f95
--- /dev/null
a684f95
+++ b/src/3rdparty/chromium/third_party/blink/renderer/modules/mediarecorder/openh264_stub_header.fragment
a684f95
@@ -0,0 +1,11 @@
a684f95
+// The extra include header needed in the generated stub file for defining
a684f95
+// various OpenH264 types.
a684f95
+
a684f95
+extern "C" {
a684f95
+
6c9da4f
+#include "third_party/openh264/src/codec/api/wels/codec_api.h"
6c9da4f
+#include "third_party/openh264/src/codec/api/wels/codec_app_def.h"
6c9da4f
+#include "third_party/openh264/src/codec/api/wels/codec_def.h"
6c9da4f
+#include "third_party/openh264/src/codec/api/wels/codec_ver.h"
a684f95
+
a684f95
+}