Diff
Modified: trunk/Source/WebCore/ChangeLog (279984 => 279985)
--- trunk/Source/WebCore/ChangeLog 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Source/WebCore/ChangeLog 2021-07-16 15:32:31 UTC (rev 279985)
@@ -1,5 +1,35 @@
2021-07-16 Philippe Normand <pnorm...@igalia.com>
+ [GStreamer] RealtimeMediaSourceCenter and VideoEncoder are not libwebrtc-specific
+ https://bugs.webkit.org/show_bug.cgi?id=228020
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ Those two are actually not using libwebrtc-related code, so a better place for them is
+ platform/mediastream/gstreamer.
+
+ * platform/GStreamer.cmake:
+ * platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp: Renamed from Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.cpp.
+ (Encoders::singleton):
+ (Encoders::registerEncoder):
+ (Encoders::definition):
+ (webrtcVideoEncoderGetProperty):
+ (webrtcVideoEncoderSetBitrate):
+ (webrtcVideoEncoderSetEncoder):
+ (webrtcVideoEncoderSetFormat):
+ (webrtcVideoEncoderSetProperty):
+ (setBitrateKbitPerSec):
+ (setBitrateBitPerSec):
+ (webrtcVideoEncoderConstructed):
+ (webkit_webrtc_video_encoder_class_init):
+ * platform/mediastream/gstreamer/GStreamerVideoEncoder.h: Renamed from Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.h.
+ * platform/mediastream/gstreamer/RealtimeMediaSourceCenterGStreamer.cpp: Renamed from Source/WebCore/platform/mediastream/libwebrtc/gstreamer/RealtimeMediaSourceCenterLibWebRTC.cpp.
+ (WebCore::RealtimeMediaSourceCenter::defaultAudioCaptureFactory):
+ (WebCore::RealtimeMediaSourceCenter::defaultVideoCaptureFactory):
+ (WebCore::RealtimeMediaSourceCenter::defaultDisplayCaptureFactory):
+
+2021-07-16 Philippe Normand <pnorm...@igalia.com>
+
[GStreamer] LibWebRTC files should be in libwebrtc/gstreamer
https://bugs.webkit.org/show_bug.cgi?id=227991
Modified: trunk/Source/WebCore/platform/GStreamer.cmake (279984 => 279985)
--- trunk/Source/WebCore/platform/GStreamer.cmake 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Source/WebCore/platform/GStreamer.cmake 2021-07-16 15:32:31 UTC (rev 279985)
@@ -46,13 +46,11 @@
platform/mediastream/libwebrtc/gstreamer/GStreamerVideoCommon.cpp
platform/mediastream/libwebrtc/gstreamer/GStreamerVideoDecoderFactory.cpp
- platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.cpp
platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoderFactory.cpp
platform/mediastream/libwebrtc/gstreamer/GStreamerVideoFrameLibWebRTC.cpp
platform/mediastream/libwebrtc/gstreamer/LibWebRTCProviderGStreamer.cpp
platform/mediastream/libwebrtc/gstreamer/RealtimeIncomingAudioSourceLibWebRTC.cpp
platform/mediastream/libwebrtc/gstreamer/RealtimeIncomingVideoSourceLibWebRTC.cpp
- platform/mediastream/libwebrtc/gstreamer/RealtimeMediaSourceCenterLibWebRTC.cpp
platform/mediastream/libwebrtc/gstreamer/RealtimeOutgoingAudioSourceLibWebRTC.cpp
platform/mediastream/libwebrtc/gstreamer/RealtimeOutgoingVideoSourceLibWebRTC.cpp
@@ -63,8 +61,10 @@
platform/mediastream/gstreamer/GStreamerMediaStreamSource.cpp
platform/mediastream/gstreamer/GStreamerVideoCaptureSource.cpp
platform/mediastream/gstreamer/GStreamerVideoCapturer.cpp
+ platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp
platform/mediastream/gstreamer/MockRealtimeAudioSourceGStreamer.cpp
platform/mediastream/gstreamer/MockRealtimeVideoSourceGStreamer.cpp
+ platform/mediastream/gstreamer/RealtimeMediaSourceCenterGStreamer.cpp
)
list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
Copied: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp (from rev 279984, trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.cpp) (0 => 279985)
--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.cpp 2021-07-16 15:32:31 UTC (rev 279985)
@@ -0,0 +1,290 @@
+/*
+ * Copyright (C) 2018-2020 Metrological Group B.V.
+ * Copyright (C) 2018-2020 Igalia S.L. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * aint with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "GStreamerVideoEncoder.h"
+
+#if ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
+
+#include "GStreamerCommon.h"
+#include <wtf/StdMap.h>
+#include <wtf/glib/WTFGType.h>
+
+using namespace WebCore;
+
+GST_DEBUG_CATEGORY(webrtc_venc_debug);
+#define GST_CAT_DEFAULT webrtc_venc_debug
+
+#define KBIT_TO_BIT 1024
+
+static GstStaticPadTemplate sinkTemplate = GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS("video/x-raw(ANY)"));
+static GstStaticPadTemplate srcTemplate = GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS("video/x-h264"));
+
+using SetBitrateFunc = Function<void(GObject* encoder, const char* propertyName, int bitrate)>;
+using SetupFunc = Function<void(WebKitWebrtcVideoEncoder*)>;
+
+struct EncoderDefinition {
+ GRefPtr<GstCaps> caps;
+ const char* name;
+ const char* parserName;
+ GRefPtr<GstCaps> encodedFormat;
+ SetBitrateFunc setBitrate;
+ SetupFunc setupEncoder;
+ const char* bitratePropertyName;
+ const char* keyframeIntervalPropertyName;
+};
+
+enum EncoderId { None, X264, OpenH264, OmxH264 };
+
+class Encoders {
+public:
+ static StdMap<EncoderId, EncoderDefinition>& singleton()
+ {
+ static StdMap<EncoderId, EncoderDefinition> encoders;
+ return encoders;
+ }
+
+ static void registerEncoder(EncoderId id, const char* name, const char* parserName, const char* caps, const char* encodedFormat,
+ SetupFunc&& setupEncoder, const char* bitratePropertyName, SetBitrateFunc&& setBitrate, const char* keyframeIntervalPropertyName)
+ {
+ auto feature = adoptGRef(gst_registry_lookup_feature(gst_registry_get(), name));
+ if (!feature)
+ return;
+
+ singleton().emplace(std::make_pair(id, (EncoderDefinition) {
+ .caps = adoptGRef(gst_caps_from_string(caps)),
+ .name = name,
+ .parserName = parserName,
+ .encodedFormat = encodedFormat ? adoptGRef(gst_caps_from_string(encodedFormat)) : nullptr,
+ .setBitrate = WTFMove(setBitrate),
+ .setupEncoder = WTFMove(setupEncoder),
+ .bitratePropertyName = bitratePropertyName,
+ .keyframeIntervalPropertyName = keyframeIntervalPropertyName,
+ }));
+ }
+
+ static EncoderDefinition* definition(EncoderId id)
+ {
+ if (id == None)
+ return nullptr;
+ return &singleton()[id];
+ }
+};
+
+struct _WebKitWebrtcVideoEncoderPrivate {
+ EncoderId encoderId;
+ GRefPtr<GstElement> encoder;
+ GRefPtr<GstElement> parser;
+ unsigned bitrate;
+};
+
+#define webkit_webrtc_video_encoder_parent_class parent_class
+WEBKIT_DEFINE_TYPE_WITH_CODE(WebKitWebrtcVideoEncoder, webkit_webrtc_video_encoder, GST_TYPE_BIN,
+ GST_DEBUG_CATEGORY_INIT(webrtc_venc_debug, "webrtcencoder", 0, "Video encoder for WebRTC"))
+
+enum {
+ PROP_FORMAT = 1,
+ PROP_ENCODER,
+ PROP_BITRATE,
+ PROP_KEYFRAME_INTERVAL,
+ N_PROPS
+};
+
+static void webrtcVideoEncoderGetProperty(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
+{
+ auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(object);
+ auto* priv = self->priv;
+
+ switch (prop_id) {
+ case PROP_FORMAT:
+ if (priv->encoderId != None) {
+ auto encoder = Encoders::definition(priv->encoderId);
+ g_value_set_boxed(value, encoder->caps.get());
+ } else
+ g_value_set_boxed(value, nullptr);
+ break;
+ case PROP_ENCODER:
+ g_value_set_object(value, priv->encoder.get());
+ break;
+ case PROP_BITRATE:
+ g_value_set_uint(value, priv->bitrate);
+ break;
+ case PROP_KEYFRAME_INTERVAL:
+ if (priv->encoder) {
+ auto encoder = Encoders::definition(priv->encoderId);
+ g_object_get_property(G_OBJECT(priv->encoder.get()), encoder->keyframeIntervalPropertyName, value);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void webrtcVideoEncoderSetBitrate(WebKitWebrtcVideoEncoder* self, guint bitrate)
+{
+ auto* priv = self->priv;
+ priv->bitrate = bitrate;
+
+ if (priv->encoderId != None) {
+ auto encoder = Encoders::definition(priv->encoderId);
+ encoder->setBitrate(G_OBJECT(priv->encoder.get()), encoder->bitratePropertyName, priv->bitrate);
+ }
+}
+
+static void webrtcVideoEncoderSetEncoder(WebKitWebrtcVideoEncoder* self, GRefPtr<GstElement>&& encoderElement, EncoderId encoderId)
+{
+ auto* priv = self->priv;
+ priv->encoderId = encoderId;
+ priv->encoder = WTFMove(encoderElement);
+
+ auto encoder = Encoders::definition(encoderId);
+ ASSERT(encoder);
+ if (encoder->parserName)
+ priv->parser = makeGStreamerElement(encoder->parserName, nullptr);
+
+ encoder->setupEncoder(self);
+
+ gst_bin_add(GST_BIN_CAST(self), priv->encoder.get());
+
+ auto sinkPadTarget = adoptGRef(gst_element_get_static_pad(priv->encoder.get(), "sink"));
+ auto sinkPad = adoptGRef(gst_element_get_static_pad(GST_ELEMENT_CAST(self), "sink"));
+ gst_ghost_pad_set_target(GST_GHOST_PAD(sinkPad.get()), sinkPadTarget.get());
+
+ GRefPtr<GstPad> srcPadTarget;
+ if (priv->parser) {
+ gst_bin_add(GST_BIN_CAST(self), priv->parser.get());
+ gst_element_link(priv->encoder.get(), priv->parser.get());
+ srcPadTarget = adoptGRef(gst_element_get_static_pad(priv->parser.get(), "src"));
+ } else
+ srcPadTarget = adoptGRef(gst_element_get_static_pad(priv->encoder.get(), "src"));
+
+ if (encoder->encodedFormat) {
+ auto* capsfilter = gst_element_factory_make("capsfilter", nullptr);
+ g_object_set(capsfilter, "caps", encoder->encodedFormat.get(), nullptr);
+
+ gst_bin_add(GST_BIN_CAST(self), capsfilter);
+ auto sinkPad = adoptGRef(gst_element_get_static_pad(capsfilter, "sink"));
+ gst_pad_link(srcPadTarget.get(), sinkPad.get());
+ srcPadTarget = adoptGRef(gst_element_get_static_pad(capsfilter, "src"));
+ }
+
+ auto srcPad = adoptGRef(gst_element_get_static_pad(GST_ELEMENT_CAST(self), "src"));
+ gst_ghost_pad_set_target(GST_GHOST_PAD(srcPad.get()), srcPadTarget.get());
+
+ webrtcVideoEncoderSetBitrate(self, priv->bitrate);
+}
+
+static void webrtcVideoEncoderSetFormat(WebKitWebrtcVideoEncoder* self, const GstCaps* caps)
+{
+ if (!caps)
+ return;
+
+ for (const auto& pair : Encoders::singleton()) {
+ const auto& encoder = pair.second;
+ if (gst_caps_can_intersect(encoder.caps.get(), caps)) {
+ GRefPtr<GstElement> element = makeGStreamerElement(encoder.name, nullptr);
+ webrtcVideoEncoderSetEncoder(self, WTFMove(element), pair.first);
+ return;
+ }
+ }
+
+ GST_ERROR("No encoder found for format %" GST_PTR_FORMAT, caps);
+}
+
+static void webrtcVideoEncoderSetProperty(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
+{
+ auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(object);
+ auto* priv = self->priv;
+
+ switch (prop_id) {
+ case PROP_FORMAT:
+ webrtcVideoEncoderSetFormat(self, gst_value_get_caps(value));
+ break;
+ case PROP_BITRATE:
+ webrtcVideoEncoderSetBitrate(self, g_value_get_uint(value));
+ break;
+ case PROP_KEYFRAME_INTERVAL:
+ if (priv->encoder) {
+ auto encoder = Encoders::definition(priv->encoderId);
+ g_object_set(priv->encoder.get(), encoder->keyframeIntervalPropertyName, g_value_get_uint(value), nullptr);
+ }
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+ break;
+ }
+}
+
+static void setBitrateKbitPerSec(GObject* encoder, const char* propertyName, int bitrate)
+{
+ g_object_set(encoder, propertyName, bitrate, nullptr);
+}
+
+static void setBitrateBitPerSec(GObject* encoder, const char* propertyName, int bitrate)
+{
+ g_object_set(encoder, propertyName, bitrate * KBIT_TO_BIT, nullptr);
+}
+
+static void webrtcVideoEncoderConstructed(GObject* encoder)
+{
+ auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(encoder);
+ self->priv->encoderId = None;
+ gst_element_add_pad(GST_ELEMENT_CAST(self), webkitGstGhostPadFromStaticTemplate(&sinkTemplate, "sink", nullptr));
+ gst_element_add_pad(GST_ELEMENT_CAST(self), webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src", nullptr));
+}
+
+static void webkit_webrtc_video_encoder_class_init(WebKitWebrtcVideoEncoderClass* klass)
+{
+ GObjectClass* objectClass = G_OBJECT_CLASS(klass);
+ objectClass->constructed = webrtcVideoEncoderConstructed;
+ objectClass->get_property = webrtcVideoEncoderGetProperty;
+ objectClass->set_property = webrtcVideoEncoderSetProperty;
+
+ g_object_class_install_property(objectClass, PROP_FORMAT, g_param_spec_boxed("format", "Format as caps", "Set the caps of the format to be used.", GST_TYPE_CAPS, WEBKIT_PARAM_READWRITE));
+
+ g_object_class_install_property(objectClass, PROP_ENCODER, g_param_spec_object("encoder", "The actual encoder element", "The encoder element", GST_TYPE_ELEMENT, WEBKIT_PARAM_READABLE));
+
+ g_object_class_install_property(objectClass, PROP_BITRATE, g_param_spec_uint("bitrate", "Bitrate", "The bitrate in kbit per second", 0, G_MAXINT, 2048,
+ static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
+
+ g_object_class_install_property(objectClass, PROP_KEYFRAME_INTERVAL, g_param_spec_uint("keyframe-interval", "Keyframe interval", "The interval between keyframes", 0, G_MAXINT, 0,
+ static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
+
+ Encoders::registerEncoder(OmxH264, "omxh264enc", "h264parse", "video/x-h264",
+ "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
+ [](WebKitWebrtcVideoEncoder* self) {
+ gst_util_set_object_arg(G_OBJECT(self->priv->encoder.get()), "control-rate", "variable");
+ g_object_set(self->priv->parser.get(), "config-interval", 1, nullptr);
+ }, "target-bitrate", setBitrateBitPerSec, "interval-intraframes");
+ Encoders::registerEncoder(X264, "x264enc", "h264parse", "video/x-h264",
+ "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
+ [](WebKitWebrtcVideoEncoder* self) {
+ gst_util_set_object_arg(G_OBJECT(self->priv->encoder.get()), "tune", "zerolatency");
+ g_object_set(self->priv->parser.get(), "config-interval", 1, nullptr);
+ }, "bitrate", setBitrateKbitPerSec, "key-int-max");
+ Encoders::registerEncoder(OpenH264, "openh264enc", "h264parse", "video/x-h264",
+ "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
+ [](WebKitWebrtcVideoEncoder* self) {
+ g_object_set(self->priv->parser.get(), "config-interval", 1, nullptr);
+ }, "bitrate", setBitrateBitPerSec, "gop-size");
+}
+
+#endif // ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(GSTREAMER)
Copied: trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.h (from rev 279984, trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.h) (0 => 279985)
--- trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.h (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/GStreamerVideoEncoder.h 2021-07-16 15:32:31 UTC (rev 279985)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2018 Metrological Group B.V.
+ * Copyright (C) 2018 Igalia S.L. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * aint with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gst/gst.h>
+
+G_BEGIN_DECLS
+
+#define WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER (webkit_webrtc_video_encoder_get_type())
+#define WEBKIT_WEBRTC_VIDEO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER, WebKitWebrtcVideoEncoder))
+#define WEBKIT_WEBRTC_VIDEO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER, WebKitWebrtcVideoEncoderClass))
+#define WEBKIT_IS_WEBRTC_VIDEO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER))
+#define WEBKIT_IS_WEBRTC_VIDEO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER))
+
+typedef struct _WebKitWebrtcVideoEncoder WebKitWebrtcVideoEncoder;
+typedef struct _WebKitWebrtcVideoEncoderClass WebKitWebrtcVideoEncoderClass;
+typedef struct _WebKitWebrtcVideoEncoderPrivate WebKitWebrtcVideoEncoderPrivate;
+
+struct _WebKitWebrtcVideoEncoder {
+ GstBin parent;
+
+ WebKitWebrtcVideoEncoderPrivate* priv;
+};
+
+struct _WebKitWebrtcVideoEncoderClass {
+ GstBinClass parentClass;
+};
+
+GType webkit_webrtc_video_encoder_get_type(void);
+
+G_END_DECLS
Copied: trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeMediaSourceCenterGStreamer.cpp (from rev 279984, trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/RealtimeMediaSourceCenterLibWebRTC.cpp) (0 => 279985)
--- trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeMediaSourceCenterGStreamer.cpp (rev 0)
+++ trunk/Source/WebCore/platform/mediastream/gstreamer/RealtimeMediaSourceCenterGStreamer.cpp 2021-07-16 15:32:31 UTC (rev 279985)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 Metrological Group B.V.
+ * Copyright (C) 2020 Igalia S.L.
+ * Author: Thibault Saunier <tsaun...@igalia.com>
+ * Author: Alejandro G. Castro <a...@igalia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * aint with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(MEDIA_STREAM)
+#include "RealtimeMediaSourceCenter.h"
+
+#include "GStreamerAudioCaptureSource.h"
+#include "GStreamerCaptureDevice.h"
+#include "GStreamerVideoCaptureSource.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+AudioCaptureFactory& RealtimeMediaSourceCenter::defaultAudioCaptureFactory()
+{
+ return GStreamerAudioCaptureSource::factory();
+}
+
+VideoCaptureFactory& RealtimeMediaSourceCenter::defaultVideoCaptureFactory()
+{
+ return GStreamerVideoCaptureSource::factory();
+}
+
+DisplayCaptureFactory& RealtimeMediaSourceCenter::defaultDisplayCaptureFactory()
+{
+ return GStreamerVideoCaptureSource::displayFactory();
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(MEDIA_STREAM)
Deleted: trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.cpp (279984 => 279985)
--- trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.cpp 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.cpp 2021-07-16 15:32:31 UTC (rev 279985)
@@ -1,290 +0,0 @@
-/*
- * Copyright (C) 2018-2020 Metrological Group B.V.
- * Copyright (C) 2018-2020 Igalia S.L. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * aint with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-#include "GStreamerVideoEncoder.h"
-
-#if ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)
-
-#include "GStreamerCommon.h"
-#include <wtf/StdMap.h>
-#include <wtf/glib/WTFGType.h>
-
-using namespace WebCore;
-
-GST_DEBUG_CATEGORY(webrtc_venc_debug);
-#define GST_CAT_DEFAULT webrtc_venc_debug
-
-#define KBIT_TO_BIT 1024
-
-static GstStaticPadTemplate sinkTemplate = GST_STATIC_PAD_TEMPLATE("sink", GST_PAD_SINK, GST_PAD_ALWAYS, GST_STATIC_CAPS("video/x-raw(ANY)"));
-static GstStaticPadTemplate srcTemplate = GST_STATIC_PAD_TEMPLATE("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS("video/x-h264"));
-
-using SetBitrateFunc = Function<void(GObject* encoder, const char* propertyName, int bitrate)>;
-using SetupFunc = Function<void(WebKitWebrtcVideoEncoder*)>;
-
-struct EncoderDefinition {
- GRefPtr<GstCaps> caps;
- const char* name;
- const char* parserName;
- GRefPtr<GstCaps> encodedFormat;
- SetBitrateFunc setBitrate;
- SetupFunc setupEncoder;
- const char* bitratePropertyName;
- const char* keyframeIntervalPropertyName;
-};
-
-enum EncoderId { None, X264, OpenH264, OmxH264 };
-
-class Encoders {
-public:
- static StdMap<EncoderId, EncoderDefinition>& singleton()
- {
- static StdMap<EncoderId, EncoderDefinition> encoders;
- return encoders;
- }
-
- static void registerEncoder(EncoderId id, const char* name, const char* parserName, const char* caps, const char* encodedFormat,
- SetupFunc&& setupEncoder, const char* bitratePropertyName, SetBitrateFunc&& setBitrate, const char* keyframeIntervalPropertyName)
- {
- auto feature = adoptGRef(gst_registry_lookup_feature(gst_registry_get(), name));
- if (!feature)
- return;
-
- singleton().emplace(std::make_pair(id, (EncoderDefinition) {
- .caps = adoptGRef(gst_caps_from_string(caps)),
- .name = name,
- .parserName = parserName,
- .encodedFormat = encodedFormat ? adoptGRef(gst_caps_from_string(encodedFormat)) : nullptr,
- .setBitrate = WTFMove(setBitrate),
- .setupEncoder = WTFMove(setupEncoder),
- .bitratePropertyName = bitratePropertyName,
- .keyframeIntervalPropertyName = keyframeIntervalPropertyName,
- }));
- }
-
- static EncoderDefinition* definition(EncoderId id)
- {
- if (id == None)
- return nullptr;
- return &singleton()[id];
- }
-};
-
-struct _WebKitWebrtcVideoEncoderPrivate {
- EncoderId encoderId;
- GRefPtr<GstElement> encoder;
- GRefPtr<GstElement> parser;
- unsigned bitrate;
-};
-
-#define webkit_webrtc_video_encoder_parent_class parent_class
-WEBKIT_DEFINE_TYPE_WITH_CODE(WebKitWebrtcVideoEncoder, webkit_webrtc_video_encoder, GST_TYPE_BIN,
- GST_DEBUG_CATEGORY_INIT(webrtc_venc_debug, "webrtcencoder", 0, "Video encoder for WebRTC"))
-
-enum {
- PROP_FORMAT = 1,
- PROP_ENCODER,
- PROP_BITRATE,
- PROP_KEYFRAME_INTERVAL,
- N_PROPS
-};
-
-static void webrtcVideoEncoderGetProperty(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
-{
- auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(object);
- auto* priv = self->priv;
-
- switch (prop_id) {
- case PROP_FORMAT:
- if (priv->encoderId != None) {
- auto encoder = Encoders::definition(priv->encoderId);
- g_value_set_boxed(value, encoder->caps.get());
- } else
- g_value_set_boxed(value, nullptr);
- break;
- case PROP_ENCODER:
- g_value_set_object(value, priv->encoder.get());
- break;
- case PROP_BITRATE:
- g_value_set_uint(value, priv->bitrate);
- break;
- case PROP_KEYFRAME_INTERVAL:
- if (priv->encoder) {
- auto encoder = Encoders::definition(priv->encoderId);
- g_object_get_property(G_OBJECT(priv->encoder.get()), encoder->keyframeIntervalPropertyName, value);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void webrtcVideoEncoderSetBitrate(WebKitWebrtcVideoEncoder* self, guint bitrate)
-{
- auto* priv = self->priv;
- priv->bitrate = bitrate;
-
- if (priv->encoderId != None) {
- auto encoder = Encoders::definition(priv->encoderId);
- encoder->setBitrate(G_OBJECT(priv->encoder.get()), encoder->bitratePropertyName, priv->bitrate);
- }
-}
-
-static void webrtcVideoEncoderSetEncoder(WebKitWebrtcVideoEncoder* self, GRefPtr<GstElement>&& encoderElement, EncoderId encoderId)
-{
- auto* priv = self->priv;
- priv->encoderId = encoderId;
- priv->encoder = WTFMove(encoderElement);
-
- auto encoder = Encoders::definition(encoderId);
- ASSERT(encoder);
- if (encoder->parserName)
- priv->parser = makeGStreamerElement(encoder->parserName, nullptr);
-
- encoder->setupEncoder(self);
-
- gst_bin_add(GST_BIN_CAST(self), priv->encoder.get());
-
- auto sinkPadTarget = adoptGRef(gst_element_get_static_pad(priv->encoder.get(), "sink"));
- auto sinkPad = adoptGRef(gst_element_get_static_pad(GST_ELEMENT_CAST(self), "sink"));
- gst_ghost_pad_set_target(GST_GHOST_PAD(sinkPad.get()), sinkPadTarget.get());
-
- GRefPtr<GstPad> srcPadTarget;
- if (priv->parser) {
- gst_bin_add(GST_BIN_CAST(self), priv->parser.get());
- gst_element_link(priv->encoder.get(), priv->parser.get());
- srcPadTarget = adoptGRef(gst_element_get_static_pad(priv->parser.get(), "src"));
- } else
- srcPadTarget = adoptGRef(gst_element_get_static_pad(priv->encoder.get(), "src"));
-
- if (encoder->encodedFormat) {
- auto* capsfilter = gst_element_factory_make("capsfilter", nullptr);
- g_object_set(capsfilter, "caps", encoder->encodedFormat.get(), nullptr);
-
- gst_bin_add(GST_BIN_CAST(self), capsfilter);
- auto sinkPad = adoptGRef(gst_element_get_static_pad(capsfilter, "sink"));
- gst_pad_link(srcPadTarget.get(), sinkPad.get());
- srcPadTarget = adoptGRef(gst_element_get_static_pad(capsfilter, "src"));
- }
-
- auto srcPad = adoptGRef(gst_element_get_static_pad(GST_ELEMENT_CAST(self), "src"));
- gst_ghost_pad_set_target(GST_GHOST_PAD(srcPad.get()), srcPadTarget.get());
-
- webrtcVideoEncoderSetBitrate(self, priv->bitrate);
-}
-
-static void webrtcVideoEncoderSetFormat(WebKitWebrtcVideoEncoder* self, const GstCaps* caps)
-{
- if (!caps)
- return;
-
- for (const auto& pair : Encoders::singleton()) {
- const auto& encoder = pair.second;
- if (gst_caps_can_intersect(encoder.caps.get(), caps)) {
- GRefPtr<GstElement> element = makeGStreamerElement(encoder.name, nullptr);
- webrtcVideoEncoderSetEncoder(self, WTFMove(element), pair.first);
- return;
- }
- }
-
- GST_ERROR("No encoder found for format %" GST_PTR_FORMAT, caps);
-}
-
-static void webrtcVideoEncoderSetProperty(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
-{
- auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(object);
- auto* priv = self->priv;
-
- switch (prop_id) {
- case PROP_FORMAT:
- webrtcVideoEncoderSetFormat(self, gst_value_get_caps(value));
- break;
- case PROP_BITRATE:
- webrtcVideoEncoderSetBitrate(self, g_value_get_uint(value));
- break;
- case PROP_KEYFRAME_INTERVAL:
- if (priv->encoder) {
- auto encoder = Encoders::definition(priv->encoderId);
- g_object_set(priv->encoder.get(), encoder->keyframeIntervalPropertyName, g_value_get_uint(value), nullptr);
- }
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
- break;
- }
-}
-
-static void setBitrateKbitPerSec(GObject* encoder, const char* propertyName, int bitrate)
-{
- g_object_set(encoder, propertyName, bitrate, nullptr);
-}
-
-static void setBitrateBitPerSec(GObject* encoder, const char* propertyName, int bitrate)
-{
- g_object_set(encoder, propertyName, bitrate * KBIT_TO_BIT, nullptr);
-}
-
-static void webrtcVideoEncoderConstructed(GObject* encoder)
-{
- auto* self = WEBKIT_WEBRTC_VIDEO_ENCODER(encoder);
- self->priv->encoderId = None;
- gst_element_add_pad(GST_ELEMENT_CAST(self), webkitGstGhostPadFromStaticTemplate(&sinkTemplate, "sink", nullptr));
- gst_element_add_pad(GST_ELEMENT_CAST(self), webkitGstGhostPadFromStaticTemplate(&srcTemplate, "src", nullptr));
-}
-
-static void webkit_webrtc_video_encoder_class_init(WebKitWebrtcVideoEncoderClass* klass)
-{
- GObjectClass* objectClass = G_OBJECT_CLASS(klass);
- objectClass->constructed = webrtcVideoEncoderConstructed;
- objectClass->get_property = webrtcVideoEncoderGetProperty;
- objectClass->set_property = webrtcVideoEncoderSetProperty;
-
- g_object_class_install_property(objectClass, PROP_FORMAT, g_param_spec_boxed("format", "Format as caps", "Set the caps of the format to be used.", GST_TYPE_CAPS, WEBKIT_PARAM_READWRITE));
-
- g_object_class_install_property(objectClass, PROP_ENCODER, g_param_spec_object("encoder", "The actual encoder element", "The encoder element", GST_TYPE_ELEMENT, WEBKIT_PARAM_READABLE));
-
- g_object_class_install_property(objectClass, PROP_BITRATE, g_param_spec_uint("bitrate", "Bitrate", "The bitrate in kbit per second", 0, G_MAXINT, 2048,
- static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
-
- g_object_class_install_property(objectClass, PROP_KEYFRAME_INTERVAL, g_param_spec_uint("keyframe-interval", "Keyframe interval", "The interval between keyframes", 0, G_MAXINT, 0,
- static_cast<GParamFlags>(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT)));
-
- Encoders::registerEncoder(OmxH264, "omxh264enc", "h264parse", "video/x-h264",
- "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
- [](WebKitWebrtcVideoEncoder* self) {
- gst_util_set_object_arg(G_OBJECT(self->priv->encoder.get()), "control-rate", "variable");
- g_object_set(self->priv->parser.get(), "config-interval", 1, nullptr);
- }, "target-bitrate", setBitrateBitPerSec, "interval-intraframes");
- Encoders::registerEncoder(X264, "x264enc", "h264parse", "video/x-h264",
- "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
- [](WebKitWebrtcVideoEncoder* self) {
- gst_util_set_object_arg(G_OBJECT(self->priv->encoder.get()), "tune", "zerolatency");
- g_object_set(self->priv->parser.get(), "config-interval", 1, nullptr);
- }, "bitrate", setBitrateKbitPerSec, "key-int-max");
- Encoders::registerEncoder(OpenH264, "openh264enc", "h264parse", "video/x-h264",
- "video/x-h264,alignment=au,stream-format=byte-stream,profile=""
- [](WebKitWebrtcVideoEncoder* self) {
- g_object_set(self->priv->parser.get(), "config-interval", 1, nullptr);
- }, "bitrate", setBitrateBitPerSec, "gop-size");
-}
-
-#endif // ENABLE(VIDEO) && ENABLE(MEDIA_STREAM) && USE(LIBWEBRTC) && USE(GSTREAMER)
Deleted: trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.h (279984 => 279985)
--- trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.h 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/GStreamerVideoEncoder.h 2021-07-16 15:32:31 UTC (rev 279985)
@@ -1,49 +0,0 @@
-/*
- * Copyright (C) 2018 Metrological Group B.V.
- * Copyright (C) 2018 Igalia S.L. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * aint with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#pragma once
-
-#include <gst/gst.h>
-
-G_BEGIN_DECLS
-
-#define WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER (webkit_webrtc_video_encoder_get_type())
-#define WEBKIT_WEBRTC_VIDEO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER, WebKitWebrtcVideoEncoder))
-#define WEBKIT_WEBRTC_VIDEO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER, WebKitWebrtcVideoEncoderClass))
-#define WEBKIT_IS_WEBRTC_VIDEO_ENCODER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER))
-#define WEBKIT_IS_WEBRTC_VIDEO_ENCODER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_WEBRTC_VIDEO_ENCODER))
-
-typedef struct _WebKitWebrtcVideoEncoder WebKitWebrtcVideoEncoder;
-typedef struct _WebKitWebrtcVideoEncoderClass WebKitWebrtcVideoEncoderClass;
-typedef struct _WebKitWebrtcVideoEncoderPrivate WebKitWebrtcVideoEncoderPrivate;
-
-struct _WebKitWebrtcVideoEncoder {
- GstBin parent;
-
- WebKitWebrtcVideoEncoderPrivate* priv;
-};
-
-struct _WebKitWebrtcVideoEncoderClass {
- GstBinClass parentClass;
-};
-
-GType webkit_webrtc_video_encoder_get_type(void);
-
-G_END_DECLS
Deleted: trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/RealtimeMediaSourceCenterLibWebRTC.cpp (279984 => 279985)
--- trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/RealtimeMediaSourceCenterLibWebRTC.cpp 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Source/WebCore/platform/mediastream/libwebrtc/gstreamer/RealtimeMediaSourceCenterLibWebRTC.cpp 2021-07-16 15:32:31 UTC (rev 279985)
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2018 Metrological Group B.V.
- * Copyright (C) 2020 Igalia S.L.
- * Author: Thibault Saunier <tsaun...@igalia.com>
- * Author: Alejandro G. Castro <a...@igalia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public License
- * aint with this library; see the file COPYING.LIB. If not, write to
- * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301, USA.
- */
-
-#include "config.h"
-
-#if ENABLE(MEDIA_STREAM)
-#include "RealtimeMediaSourceCenter.h"
-
-#include "GStreamerAudioCaptureSource.h"
-#include "GStreamerCaptureDevice.h"
-#include "GStreamerVideoCaptureSource.h"
-#include <wtf/MainThread.h>
-
-namespace WebCore {
-
-AudioCaptureFactory& RealtimeMediaSourceCenter::defaultAudioCaptureFactory()
-{
- return GStreamerAudioCaptureSource::factory();
-}
-
-VideoCaptureFactory& RealtimeMediaSourceCenter::defaultVideoCaptureFactory()
-{
- return GStreamerVideoCaptureSource::factory();
-}
-
-DisplayCaptureFactory& RealtimeMediaSourceCenter::defaultDisplayCaptureFactory()
-{
- return GStreamerVideoCaptureSource::displayFactory();
-}
-
-} // namespace WebCore
-
-#endif // ENABLE(MEDIA_STREAM)
Modified: trunk/Tools/ChangeLog (279984 => 279985)
--- trunk/Tools/ChangeLog 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Tools/ChangeLog 2021-07-16 15:32:31 UTC (rev 279985)
@@ -1,3 +1,12 @@
+2021-07-16 Philippe Normand <pnorm...@igalia.com>
+
+ [GStreamer] RealtimeMediaSourceCenter and VideoEncoder are not libwebrtc-specific
+ https://bugs.webkit.org/show_bug.cgi?id=228020
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ * Scripts/webkitpy/style/checker.py:
+
2021-07-16 Angelos Oikonomopoulos <ange...@igalia.com>
Bundle libraries for remote execution in run-jsc-benchmarks
Modified: trunk/Tools/Scripts/webkitpy/style/checker.py (279984 => 279985)
--- trunk/Tools/Scripts/webkitpy/style/checker.py 2021-07-16 14:25:26 UTC (rev 279984)
+++ trunk/Tools/Scripts/webkitpy/style/checker.py 2021-07-16 15:32:31 UTC (rev 279985)
@@ -239,8 +239,8 @@
os.path.join('Source', 'WebCore', 'platform', 'audio', 'gstreamer', 'WebKitWebAudioSourceGStreamer.cpp'),
os.path.join('Source', 'WebCore', 'platform', 'mediastream', 'gstreamer', 'GStreamerMediaStreamSource.h'),
os.path.join('Source', 'WebCore', 'platform', 'mediastream', 'gstreamer', 'GStreamerMediaStreamSource.cpp'),
- os.path.join('Source', 'WebCore', 'platform', 'mediastream', 'libwebrtc', 'gstreamer', 'GStreamerVideoEncoder.h'),
- os.path.join('Source', 'WebCore', 'platform', 'mediastream', 'libwebrtc', 'gstreamer', 'GStreamerVideoEncoder.cpp'),
+ os.path.join('Source', 'WebCore', 'platform', 'mediastream', 'gstreamer', 'GStreamerVideoEncoder.h'),
+ os.path.join('Source', 'WebCore', 'platform', 'mediastream', 'gstreamer', 'GStreamerVideoEncoder.cpp'),
os.path.join('Source', 'WebCore', 'platform', 'network', 'soup', 'ProxyResolverSoup.cpp'),
os.path.join('Source', 'WebCore', 'platform', 'network', 'soup', 'ProxyResolverSoup.h'),
os.path.join('Source', 'WebCore', 'platform', 'network', 'soup', 'WebKitFormDataInputStream.cpp'),