Skip to content

Commit 0c2e1d0

Browse files
asurdej-comcasteocanha
authored andcommitted
[GStreamer] Expose VIDEO_DECODING_LIMIT through an environment variable
https://bugs.webkit.org/show_bug.cgi?id=308969 Reviewed by Alicia Boya Garcia and Xabier Rodriguez-Calvar. The RDK-E downstream platform would like to have a single unified build for many kind of devices. For that reason, the platform compile-time VIDEO_DECODING_LIMIT restriction aren't appropriate anymore, since the same build can be used for devices with different runtime limits. A way to specify the decoding limit ar runtime would be desirable. An environment variable looks like a better way to do it than a runtime setting, since the limit is unlikely to change at runtime and likely to change per device (with a value consistent on every execution). Moreover, having a setting would mean extra changes in the dependent packages that embed WebKit, while having en environmente variable would be less intrusive and would only mean a change in the (easier to maintain) startup scripts. This change adds WEBKIT_GST_VIDEO_DECODING_LIMIT env on top of VIDEO_DECODING_LIMIT compile time option to limit video decoding capabilities. WEBKIT_GST_VIDEO_DECODING_LIMIT can now be set in runtime and it takes precedence over compile time definition VIDEO_DECODING_LIMIT. See: #1625 #1626 Original author: Andrzej Surdej <Andrzej_Surdej@comcast.com> * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (videoDecoderLimitsDefaults): Deleted. * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::parseVideoDecodingLimit): Use a StringView to prevent extra copies. (WebCore::resolveVideoDecodingLimits): Decide the right decoding limits considering the build time option and the environment variable value. (WebCore::GStreamerRegistryScanner::isContentTypeSupported const): Parse env var and only require the build ifdefs when strictly needed. (videoDecoderLimitsDefaults): Deleted. Canonical link: https://commits.webkit.org/308552@main
1 parent 28d39a4 commit 0c2e1d0

1 file changed

Lines changed: 49 additions & 31 deletions

File tree

Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp

Lines changed: 49 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@
4141
#include "VideoEncoderPrivateGStreamer.h"
4242
#endif
4343

44-
namespace {
44+
#if PLATFORM(WPE)
45+
#include "PlatformScreen.h"
46+
#include "ScreenProperties.h"
47+
#endif // PLATFORM(WPE)
48+
49+
namespace WebCore {
50+
51+
GST_DEBUG_CATEGORY_STATIC(webkit_media_gst_registry_scanner_debug);
52+
#define GST_CAT_DEFAULT webkit_media_gst_registry_scanner_debug
53+
4554
struct VideoDecodingLimits {
4655
unsigned mediaMaxWidth = 0;
4756
unsigned mediaMaxHeight = 0;
@@ -53,22 +62,18 @@ struct VideoDecodingLimits {
5362
{
5463
}
5564
};
56-
}
5765

58-
#ifdef VIDEO_DECODING_LIMIT
59-
static std::optional<VideoDecodingLimits> videoDecoderLimitsDefaults()
66+
// Parses a video decoding limit string in format WIDTHxHEIGHT@FRAMERATE.
67+
static std::optional<VideoDecodingLimits> parseVideoDecodingLimit(const StringView& videoDecodingLimit)
6068
{
61-
// VIDEO_DECODING_LIMIT should be in format: WIDTHxHEIGHT@FRAMERATE.
62-
String videoDecodingLimit(String::fromUTF8(VIDEO_DECODING_LIMIT));
63-
6469
if (videoDecodingLimit.isEmpty())
6570
return { };
6671

6772
Vector<String> entries;
6873

69-
// Extract frame rate part from the VIDEO_DECODING_LIMIT: WIDTHxHEIGHT@FRAMERATE.
70-
videoDecodingLimit.split('@', [&entries](StringView item) {
71-
entries.append(item.toString());
74+
// Extract frame rate part: WIDTHxHEIGHT@FRAMERATE.
75+
videoDecodingLimit.toStringWithoutCopying().split('@', [&entries](StringView item) {
76+
entries.append(item.toStringWithoutCopying());
7277
});
7378

7479
if (entries.size() != 2)
@@ -96,12 +101,39 @@ static std::optional<VideoDecodingLimits> videoDecoderLimitsDefaults()
96101

97102
return { VideoDecodingLimits(width.value(), height.value(), frameRate.value()) };
98103
}
99-
#endif
100-
101-
namespace WebCore {
102104

103-
GST_DEBUG_CATEGORY_STATIC(webkit_media_gst_registry_scanner_debug);
104-
#define GST_CAT_DEFAULT webkit_media_gst_registry_scanner_debug
105+
// Returns the active VideoDecodingLimits, resolved once at first call.
106+
// WEBKIT_GST_VIDEO_DECODING_LIMIT env var takes precedence over the compile-time VIDEO_DECODING_LIMIT.
107+
// Format for both: WIDTHxHEIGHT@FRAMERATE (e.g. "1920x1080@30").
108+
static VideoDecodingLimits* resolveVideoDecodingLimits()
109+
{
110+
static std::optional<VideoDecodingLimits> limits;
111+
static std::once_flag onceFlag;
112+
std::call_once(onceFlag, [] {
113+
if (const char* envLimit = g_getenv("WEBKIT_GST_VIDEO_DECODING_LIMIT")) {
114+
GST_DEBUG("WEBKIT_GST_VIDEO_DECODING_LIMIT env var is set: %s", envLimit);
115+
limits = parseVideoDecodingLimit(StringView::fromLatin1(envLimit));
116+
if (!limits)
117+
GST_WARNING("Parsing WEBKIT_GST_VIDEO_DECODING_LIMIT env var failed: %s", envLimit);
118+
}
119+
#ifdef VIDEO_DECODING_LIMIT
120+
if (!limits) {
121+
GST_DEBUG("VIDEO_DECODING_LIMIT compile-time definition is set: %s", VIDEO_DECODING_LIMIT);
122+
limits = parseVideoDecodingLimit(String::fromLatin1(VIDEO_DECODING_LIMIT));
123+
if (!limits) {
124+
GST_WARNING("Parsing VIDEO_DECODING_LIMIT failed: %s", VIDEO_DECODING_LIMIT);
125+
ASSERT_NOT_REACHED();
126+
return;
127+
}
128+
}
129+
#endif
130+
if (limits) {
131+
GST_DEBUG("Video decoding limits: max width=%u, max height=%u, max frame rate=%u",
132+
limits->mediaMaxWidth, limits->mediaMaxHeight, limits->mediaMaxFrameRate);
133+
}
134+
});
135+
return limits ? &*limits : nullptr;
136+
}
105137

106138
// We shouldn't accept media that the player can't actually play.
107139
// AAC supports up to 96 channels.
@@ -758,22 +790,8 @@ bool GStreamerRegistryScanner::supportsFeatures(const String& features) const
758790
MediaPlayerEnums::SupportsType GStreamerRegistryScanner::isContentTypeSupported(Configuration configuration, const ContentType& contentType, const Vector<ContentType>& contentTypesRequiringHardwareSupport) const
759791
{
760792
VideoDecodingLimits* videoDecodingLimits = nullptr;
761-
#ifdef VIDEO_DECODING_LIMIT
762-
static std::optional<VideoDecodingLimits> videoDecodingLimitsDefaults;
763-
static std::once_flag onceFlag;
764-
if (configuration == Configuration::Decoding) {
765-
std::call_once(onceFlag, [] {
766-
videoDecodingLimitsDefaults = videoDecoderLimitsDefaults();
767-
if (!videoDecodingLimitsDefaults) {
768-
GST_WARNING("Parsing VIDEO_DECODING_LIMIT failed");
769-
ASSERT_NOT_REACHED();
770-
return;
771-
}
772-
});
773-
if (videoDecodingLimitsDefaults)
774-
videoDecodingLimits = &*videoDecodingLimitsDefaults;
775-
}
776-
#endif
793+
if (configuration == Configuration::Decoding)
794+
videoDecodingLimits = resolveVideoDecodingLimits();
777795

778796
using SupportsType = MediaPlayerEnums::SupportsType;
779797

0 commit comments

Comments
 (0)