Skip to content

Commit 5a3558c

Browse files
pgorszkowski-igaliaeocanha
authored andcommitted
[GStreamer] refactor video decoder limit customization
https://bugs.webkit.org/show_bug.cgi?id=248961 Reviewed by Philippe Normand. Moved the same functionality to one place - from MediaPlayerPrivateGStreamerMSE::supportsType to GStreamerRegistryScanner::isContentTypeSupported. * Source/WebCore/platform/GStreamer.cmake: * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (videoDecoderLimitsDefaults): (WebCore::GStreamerRegistryScanner::isContentTypeSupported const): * Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp: (WebCore::MediaPlayerPrivateGStreamerMSE::supportsType): (videoDecoderLimitsDefaults): Deleted. Canonical link: https://commits.webkit.org/263408@main
1 parent 8e51f23 commit 5a3558c

3 files changed

Lines changed: 90 additions & 107 deletions

File tree

Source/WebCore/platform/GStreamer.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ if (ENABLE_VIDEO OR ENABLE_WEB_AUDIO)
170170

171171
if (VIDEO_DECODING_LIMIT)
172172
# Specify video decoding limits.
173-
set_source_files_properties(platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp PROPERTIES COMPILE_DEFINITIONS VIDEO_DECODING_LIMIT="${VIDEO_DECODING_LIMIT}")
173+
set_source_files_properties(platform/graphics/gstreamer/GStreamerRegistryScanner.cpp PROPERTIES COMPILE_DEFINITIONS VIDEO_DECODING_LIMIT="${VIDEO_DECODING_LIMIT}")
174174
endif ()
175175
endif ()
176176

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

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,63 @@
4141
#include "VideoEncoderPrivateGStreamer.h"
4242
#endif
4343

44+
namespace {
45+
struct VideoDecodingLimits {
46+
unsigned mediaMaxWidth = 0;
47+
unsigned mediaMaxHeight = 0;
48+
unsigned mediaMaxFrameRate = 0;
49+
VideoDecodingLimits(unsigned mediaMaxWidth, unsigned mediaMaxHeight, unsigned mediaMaxFrameRate)
50+
: mediaMaxWidth(mediaMaxWidth)
51+
, mediaMaxHeight(mediaMaxHeight)
52+
, mediaMaxFrameRate(mediaMaxFrameRate)
53+
{
54+
}
55+
};
56+
}
57+
58+
#ifdef VIDEO_DECODING_LIMIT
59+
static std::optional<VideoDecodingLimits> videoDecoderLimitsDefaults()
60+
{
61+
// VIDEO_DECODING_LIMIT should be in format: WIDTHxHEIGHT@FRAMERATE.
62+
String videoDecodingLimit(String::fromUTF8(VIDEO_DECODING_LIMIT));
63+
64+
if (videoDecodingLimit.isEmpty())
65+
return { };
66+
67+
Vector<String> entries;
68+
69+
// Extract frame rate part from the VIDEO_DECODING_LIMIT: WIDTHxHEIGHT@FRAMERATE.
70+
videoDecodingLimit.split('@', [&entries](StringView item) {
71+
entries.append(item.toString());
72+
});
73+
74+
if (entries.size() != 2)
75+
return { };
76+
77+
auto frameRate = parseIntegerAllowingTrailingJunk<unsigned>(entries[1]);
78+
79+
if (!frameRate.has_value())
80+
return { };
81+
82+
const auto widthAndHeight = entries[0].split('x');
83+
84+
if (widthAndHeight.size() != 2)
85+
return { };
86+
87+
const auto width = parseIntegerAllowingTrailingJunk<unsigned>(widthAndHeight[0]);
88+
89+
if (!width.has_value())
90+
return { };
91+
92+
const auto height = parseIntegerAllowingTrailingJunk<unsigned>(widthAndHeight[1]);
93+
94+
if (!height.has_value())
95+
return { };
96+
97+
return { VideoDecodingLimits(width.value(), height.value(), frameRate.value()) };
98+
}
99+
#endif
100+
44101
namespace WebCore {
45102

46103
GST_DEBUG_CATEGORY_STATIC(webkit_media_gst_registry_scanner_debug);
@@ -50,11 +107,6 @@ GST_DEBUG_CATEGORY_STATIC(webkit_media_gst_registry_scanner_debug);
50107
// AAC supports up to 96 channels.
51108
#define MEDIA_MAX_AAC_CHANNELS 96
52109

53-
// Assume hardware video decoding acceleration up to 8K@60fps for the generic case. Some embedded platforms might want to tune this.
54-
#define MEDIA_MAX_WIDTH 7680.0f
55-
#define MEDIA_MAX_HEIGHT 4320.0f
56-
#define MEDIA_MAX_FRAMERATE 60.0f
57-
58110
static bool singletonInitialized = false;
59111

60112
bool GStreamerRegistryScanner::singletonWasInitialized()
@@ -705,6 +757,21 @@ bool GStreamerRegistryScanner::supportsFeatures(const String& features) const
705757

706758
MediaPlayerEnums::SupportsType GStreamerRegistryScanner::isContentTypeSupported(Configuration configuration, const ContentType& contentType, const Vector<ContentType>& contentTypesRequiringHardwareSupport) const
707759
{
760+
static std::optional<VideoDecodingLimits> videoDecodingLimits;
761+
#ifdef VIDEO_DECODING_LIMIT
762+
static std::once_flag onceFlag;
763+
if (configuration == Configuration::Decoding) {
764+
std::call_once(onceFlag, [] {
765+
videoDecodingLimits = videoDecoderLimitsDefaults();
766+
if (!videoDecodingLimits) {
767+
GST_WARNING("Parsing VIDEO_DECODING_LIMIT failed");
768+
ASSERT_NOT_REACHED();
769+
return;
770+
}
771+
});
772+
}
773+
#endif
774+
708775
using SupportsType = MediaPlayerEnums::SupportsType;
709776

710777
const auto& containerType = contentType.containerType().convertToASCIILowercase();
@@ -714,10 +781,23 @@ MediaPlayerEnums::SupportsType GStreamerRegistryScanner::isContentTypeSupported(
714781
int channels = parseInteger<int>(contentType.parameter("channels"_s)).value_or(1);
715782
String features = contentType.parameter("features"_s);
716783
if (channels > MEDIA_MAX_AAC_CHANNELS || channels <= 0
717-
|| !(features.isEmpty() || supportsFeatures(features))
718-
|| parseInteger<unsigned>(contentType.parameter("width"_s)).value_or(0) > MEDIA_MAX_WIDTH
719-
|| parseInteger<unsigned>(contentType.parameter("height"_s)).value_or(0) > MEDIA_MAX_HEIGHT
720-
|| parseInteger<unsigned>(contentType.parameter("framerate"_s)).value_or(0) > MEDIA_MAX_FRAMERATE)
784+
|| !(features.isEmpty() || supportsFeatures(features)))
785+
return SupportsType::IsNotSupported;
786+
787+
bool ok;
788+
float width = contentType.parameter("width"_s).toFloat(&ok);
789+
if (!ok)
790+
width = 0;
791+
float height = contentType.parameter("height"_s).toFloat(&ok);
792+
if (!ok)
793+
height = 0;
794+
795+
if (videoDecodingLimits && (width > videoDecodingLimits->mediaMaxWidth || height > videoDecodingLimits->mediaMaxHeight))
796+
return SupportsType::IsNotSupported;
797+
798+
float frameRate = contentType.parameter("framerate"_s).toFloat(&ok);
799+
// Limit frameRate only in case of highest supported resolution.
800+
if (ok && videoDecodingLimits && width == videoDecodingLimits->mediaMaxWidth && height == videoDecodingLimits->mediaMaxHeight && frameRate > videoDecodingLimits->mediaMaxFrameRate)
721801
return SupportsType::IsNotSupported;
722802

723803
const auto& codecs = contentType.codecs();

Source/WebCore/platform/graphics/gstreamer/mse/MediaPlayerPrivateGStreamerMSE.cpp

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -56,73 +56,6 @@
5656
#include <wtf/text/AtomStringHash.h>
5757
#include <wtf/text/StringToIntegerConversion.h>
5858

59-
namespace {
60-
struct VideoDecodingLimits {
61-
unsigned mediaMaxWidth = 0;
62-
unsigned mediaMaxHeight = 0;
63-
unsigned mediaMaxFrameRate = 0;
64-
VideoDecodingLimits(unsigned mediaMaxWidth, unsigned mediaMaxHeight, unsigned mediaMaxFrameRate)
65-
: mediaMaxWidth(mediaMaxWidth)
66-
, mediaMaxHeight(mediaMaxHeight)
67-
, mediaMaxFrameRate(mediaMaxFrameRate)
68-
{
69-
}
70-
};
71-
}
72-
73-
#ifdef VIDEO_DECODING_LIMIT
74-
static std::optional<VideoDecodingLimits> videoDecoderLimitsDefaults()
75-
{
76-
// VIDEO_DECODING_LIMIT should be in format: WIDTHxHEIGHT@FRAMERATE.
77-
String videoDecodingLimit(String::fromUTF8(VIDEO_DECODING_LIMIT));
78-
79-
if (videoDecodingLimit.isEmpty())
80-
return { };
81-
82-
Vector<String> entries;
83-
84-
// Extract frame rate part from the VIDEO_DECODING_LIMIT: WIDTHxHEIGHT@FRAMERATE.
85-
videoDecodingLimit.split('@', [&entries](StringView item) {
86-
entries.append(item.toString());
87-
});
88-
89-
if (entries.size() != 2)
90-
return { };
91-
92-
auto frameRate = parseIntegerAllowingTrailingJunk<unsigned>(entries[1]);
93-
94-
if (!frameRate.has_value())
95-
return { };
96-
97-
String widthAndHeight = entries[0];
98-
entries.clear();
99-
100-
// Extract WIDTH and HEIGHT from: WIDTHxHEIGHT.
101-
widthAndHeight.split('x', [&entries](StringView item) {
102-
entries.append(item.toString());
103-
});
104-
105-
if (entries.size() != 2)
106-
return { };
107-
108-
auto width = parseIntegerAllowingTrailingJunk<unsigned>(entries[0]);
109-
110-
if (!width.has_value())
111-
return { };
112-
113-
auto height = parseIntegerAllowingTrailingJunk<unsigned>(entries[1]);
114-
115-
if (!height.has_value())
116-
return { };
117-
118-
return { VideoDecodingLimits(width.value(), height.value(), frameRate.value()) };
119-
}
120-
#endif
121-
122-
// We shouldn't accept media that the player can't actually play.
123-
// AAC supports up to 96 channels.
124-
#define MEDIA_MAX_AAC_CHANNELS 96
125-
12659
static const char* dumpReadyState(WebCore::MediaPlayer::ReadyState readyState)
12760
{
12861
switch (readyState) {
@@ -521,36 +454,6 @@ MediaPlayer::SupportsType MediaPlayerPrivateGStreamerMSE::supportsType(const Med
521454
return result;
522455
}
523456

524-
unsigned channels = parseIntegerAllowingTrailingJunk<unsigned>(parameters.type.parameter("channels"_s)).value_or(0);
525-
if (channels > MEDIA_MAX_AAC_CHANNELS)
526-
return result;
527-
528-
bool ok;
529-
float width = parameters.type.parameter("width"_s).toFloat(&ok);
530-
if (!ok)
531-
width = 0;
532-
float height = parameters.type.parameter("height"_s).toFloat(&ok);
533-
if (!ok)
534-
height = 0;
535-
536-
static std::optional<VideoDecodingLimits> videoDecodingLimits;
537-
#ifdef VIDEO_DECODING_LIMIT
538-
static std::once_flag onceFlag;
539-
std::call_once(onceFlag, [] {
540-
videoDecodingLimits = videoDecoderLimitsDefaults();
541-
if (!videoDecodingLimits)
542-
GST_WARNING("Parsing VIDEO_DECODING_LIMIT failed");
543-
});
544-
#endif
545-
546-
if (videoDecodingLimits && (width > videoDecodingLimits->mediaMaxWidth || height > videoDecodingLimits->mediaMaxHeight))
547-
return result;
548-
549-
float frameRate = parameters.type.parameter("framerate"_s).toFloat(&ok);
550-
// Limit frameRate only in case of highest supported resolution.
551-
if (ok && videoDecodingLimits && width == videoDecodingLimits->mediaMaxWidth && height == videoDecodingLimits->mediaMaxHeight && frameRate > videoDecodingLimits->mediaMaxFrameRate)
552-
return result;
553-
554457
registerWebKitGStreamerElements();
555458

556459
GST_DEBUG("Checking mime-type \"%s\"", parameters.type.raw().utf8().data());

0 commit comments

Comments
 (0)