Title: [286358] trunk/Source/WebCore
- Revision
- 286358
- Author
- [email protected]
- Date
- 2021-12-01 02:56:22 -0800 (Wed, 01 Dec 2021)
Log Message
[MSE][WPE] Parameterize maximum buffer size using the MSE_MAX_BUFFER_SIZE env var
https://bugs.webkit.org/show_bug.cgi?id=233495
Reviewed by Xabier Rodriguez-Calvar.
The current MSE policy of SourceBuffers taking all the available system memory until the MemoryPressureHandler
complains may work fine for a typical desktop system, when caching is preferred over memory footprint. However,
memory is scarce on embedded systems and WebKit may compete with other software for memory resources. In that
scenario, the embedder may prefer to restrict the amount of memory available for each kind of SourceBuffer
(audio, video, text).
For that purpose, the MSE_MAX_BUFFER_SIZE environment variable is honored. It has the following syntax: Case
insensitive, full type (audio, video, text), compact type (a, v, t), wildcard (*), unit multipliers (M=Mb,
K=Kb, <empty>=bytes). Examples:
MSE_MAX_BUFFER_SIZE='V:50M,audio:12k,TeXT:500K'
MSE_MAX_BUFFER_SIZE='*:100M'
MSE_MAX_BUFFER_SIZE='video:90M,T:100000'
* Modules/mediasource/SourceBuffer.cpp: Honor platform imposed buffer size restrictions with higher priority (if present) than the element ones.
* platform/graphics/SourceBufferPrivate.h: Added platformMaximumBufferSize() default implementation that sets no buffer size restrictions.
* platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp: Read the MSE_MAX_BUFFER_SIZE environment variable and compute the maximum buffer
size if the size is specified in the variable for all the track types present in the SourceBufferPrivate. Otherwise, use the default size.
* platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h: Override default platformMaximumBufferSize() implementation.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (286357 => 286358)
--- trunk/Source/WebCore/ChangeLog 2021-12-01 10:53:40 UTC (rev 286357)
+++ trunk/Source/WebCore/ChangeLog 2021-12-01 10:56:22 UTC (rev 286358)
@@ -1,3 +1,30 @@
+2021-12-01 Enrique Ocaña González <[email protected]>
+
+ [MSE][WPE] Parameterize maximum buffer size using the MSE_MAX_BUFFER_SIZE env var
+ https://bugs.webkit.org/show_bug.cgi?id=233495
+
+ Reviewed by Xabier Rodriguez-Calvar.
+
+ The current MSE policy of SourceBuffers taking all the available system memory until the MemoryPressureHandler
+ complains may work fine for a typical desktop system, when caching is preferred over memory footprint. However,
+ memory is scarce on embedded systems and WebKit may compete with other software for memory resources. In that
+ scenario, the embedder may prefer to restrict the amount of memory available for each kind of SourceBuffer
+ (audio, video, text).
+
+ For that purpose, the MSE_MAX_BUFFER_SIZE environment variable is honored. It has the following syntax: Case
+ insensitive, full type (audio, video, text), compact type (a, v, t), wildcard (*), unit multipliers (M=Mb,
+ K=Kb, <empty>=bytes). Examples:
+
+ MSE_MAX_BUFFER_SIZE='V:50M,audio:12k,TeXT:500K'
+ MSE_MAX_BUFFER_SIZE='*:100M'
+ MSE_MAX_BUFFER_SIZE='video:90M,T:100000'
+
+ * Modules/mediasource/SourceBuffer.cpp: Honor platform imposed buffer size restrictions with higher priority (if present) than the element ones.
+ * platform/graphics/SourceBufferPrivate.h: Added platformMaximumBufferSize() default implementation that sets no buffer size restrictions.
+ * platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp: Read the MSE_MAX_BUFFER_SIZE environment variable and compute the maximum buffer
+ size if the size is specified in the variable for all the track types present in the SourceBufferPrivate. Otherwise, use the default size.
+ * platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h: Override default platformMaximumBufferSize() implementation.
+
2021-11-30 Simon Fraser <[email protected]>
Pass the timestamp for scrolling thread animations through all the serviceScrollAnimation() calls
Modified: trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp (286357 => 286358)
--- trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp 2021-12-01 10:53:40 UTC (rev 286357)
+++ trunk/Source/WebCore/Modules/mediasource/SourceBuffer.cpp 2021-12-01 10:56:22 UTC (rev 286358)
@@ -630,6 +630,10 @@
if (!element)
return 0;
+ size_t platformMaximumBufferSize = m_private->platformMaximumBufferSize();
+ if (platformMaximumBufferSize)
+ return platformMaximumBufferSize;
+
return element->maximumSourceBufferSize(*this);
}
Modified: trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h (286357 => 286358)
--- trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h 2021-12-01 10:53:40 UTC (rev 286357)
+++ trunk/Source/WebCore/platform/graphics/SourceBufferPrivate.h 2021-12-01 10:56:22 UTC (rev 286358)
@@ -112,6 +112,8 @@
MediaTime timestampOffset() const { return m_timestampOffset; }
+ virtual size_t platformMaximumBufferSize() const { return 0; }
+
struct TrackBuffer {
WTF_MAKE_STRUCT_FAST_ALLOCATED;
MediaTime lastDecodeTimestamp;
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp (286357 => 286358)
--- trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp 2021-12-01 10:53:40 UTC (rev 286357)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.cpp 2021-12-01 10:56:22 UTC (rev 286358)
@@ -51,6 +51,10 @@
#include "VideoTrackPrivateGStreamer.h"
#include "WebKitMediaSourceGStreamer.h"
+#if PLATFORM(WPE)
+#include <wtf/text/StringToIntegerConversion.h>
+#endif
+
GST_DEBUG_CATEGORY_EXTERN(webkit_mse_debug);
#define GST_CAT_DEFAULT webkit_mse_debug
@@ -273,5 +277,104 @@
}
#endif
+size_t SourceBufferPrivateGStreamer::platformMaximumBufferSize() const
+{
+#if PLATFORM(WPE)
+ if (!m_client)
+ return 0;
+
+ static size_t maxBufferSizeVideo = 0;
+ static size_t maxBufferSizeAudio = 0;
+ static size_t maxBufferSizeText = 0;
+
+ static std::once_flag once;
+ std::call_once(once, []() {
+ // Syntax: Case insensitive, full type (audio, video, text), compact type (a, v, t),
+ // wildcard (*), unit multipliers (M=Mb, K=Kb, <empty>=bytes).
+ // Examples: MSE_MAX_BUFFER_SIZE='V:50M,audio:12k,TeXT:500K'
+ // MSE_MAX_BUFFER_SIZE='*:100M'
+ // MSE_MAX_BUFFER_SIZE='video:90M,T:100000'
+
+ String s(std::getenv("MSE_MAX_BUFFER_SIZE"));
+ if (!s.isEmpty()) {
+ Vector<String> entries = s.split(',');
+ for (const String& entry : entries) {
+ Vector<String> keyvalue = entry.split(':');
+ if (keyvalue.size() != 2)
+ continue;
+ String key = keyvalue[0].stripWhiteSpace().convertToLowercaseWithoutLocale();
+ String value = keyvalue[1].stripWhiteSpace().convertToLowercaseWithoutLocale();
+ size_t units = 1;
+ if (value.endsWith('k'))
+ units = 1024;
+ else if (value.endsWith('m'))
+ units = 1024 * 1024;
+ if (units != 1)
+ value = value.substring(0, value.length()-1);
+ auto parsedSize = parseInteger<size_t>(value);
+ if (!parsedSize)
+ continue;
+ size_t size = *parsedSize;
+
+ if (key == "a" || key == "audio" || key == "*")
+ maxBufferSizeAudio = size * units;
+ if (key == "v" || key == "video" || key == "*")
+ maxBufferSizeVideo = size * units;
+ if (key == "t" || key == "text" || key == "*")
+ maxBufferSizeText = size * units;
+ }
+ }
+ });
+
+ // If any track type size isn't specified, we consider that it has no limit and the values from the
+ // element have to be used. Otherwise, the track limits are accumulative.
+ do {
+ bool hasVideo = false;
+ bool hasAudio = false;
+ bool hasText = false;
+ size_t bufferSize = 0;
+
+ for (auto track : m_tracks.values()) {
+ switch (track->type()) {
+ case TrackPrivateBaseGStreamer::Video:
+ hasVideo = true;
+ break;
+ case TrackPrivateBaseGStreamer::Audio:
+ hasAudio = true;
+ break;
+ case TrackPrivateBaseGStreamer::Text:
+ hasText = true;
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (hasVideo) {
+ if (maxBufferSizeVideo)
+ bufferSize += maxBufferSizeVideo;
+ else
+ break;
+ }
+ if (hasAudio) {
+ if (maxBufferSizeAudio)
+ bufferSize += maxBufferSizeAudio;
+ else
+ break;
+ }
+ if (hasText) {
+ if (maxBufferSizeText)
+ bufferSize += maxBufferSizeText;
+ else
+ break;
+ }
+ if (bufferSize)
+ return bufferSize;
+ } while (false);
+#endif
+
+ return 0;
}
+
+}
#endif
Modified: trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h (286357 => 286358)
--- trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h 2021-12-01 10:53:40 UTC (rev 286357)
+++ trunk/Source/WebCore/platform/graphics/gstreamer/mse/SourceBufferPrivateGStreamer.h 2021-12-01 10:56:22 UTC (rev 286358)
@@ -94,6 +94,8 @@
const void* sourceBufferLogIdentifier() final { return logIdentifier(); }
#endif
+ size_t platformMaximumBufferSize() const override;
+
private:
SourceBufferPrivateGStreamer(MediaSourcePrivateGStreamer*, const ContentType&, MediaPlayerPrivateGStreamerMSE&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes