1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
From 9460989561df7c3418efc92fc423a54576eb9d21 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Wed, 11 Nov 2026 10:10:48 +0200
Subject: [PATCH] [MSE] Key the isTypeSupported() cache by the settings it
depends on
MediaSource.isTypeSupported() caches its answer per web process by the
raw type alone, but the answer depends on the document's
media-content-types-requiring-hardware-support and allowed media type
settings. An answer computed under one setting is reused after the
setting changes and by documents with other settings. The cache key now
carries the type together with those settings.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
.../Modules/mediasource/MediaSource.cpp | 33 +++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
--- a/Source/WebCore/Modules/mediasource/MediaSource.cpp
+++ b/Source/WebCore/Modules/mediasource/MediaSource.cpp
@@ -76,6 +76,7 @@
#include <wtf/Scope.h>
#include <wtf/TZoneMallocInlines.h>
#include <wtf/text/MakeString.h>
+#include <wtf/text/StringBuilder.h>
namespace WebCore {
@@ -986,6 +987,33 @@ void MediaSource::removeSourceBufferWith
notifyElementUpdateMediaState();
}
+// The answer depends on the settings that fill the parameters as much as on the type.
+static String mediaSourceTypeCacheKey(const MediaEngineSupportParameters& parameters)
+{
+ StringBuilder key;
+ key.append(parameters.type.raw());
+ for (auto& contentType : parameters.contentTypesRequiringHardwareSupport)
+ key.append("\nhardware "_s, contentType.raw());
+
+ if (parameters.allowedMediaContainerTypes) {
+ key.append("\ncontainers"_s);
+ for (auto& containerType : *parameters.allowedMediaContainerTypes)
+ key.append(' ', containerType);
+ }
+
+ auto appendFourCCs = [&](ASCIILiteral label, const std::optional<Vector<FourCC>>& fourCCs) {
+ if (!fourCCs)
+ return;
+ key.append(label);
+ for (auto fourCC : *fourCCs)
+ key.append(' ', fourCC.value);
+ };
+ appendFourCCs("\nvideo"_s, parameters.allowedMediaVideoCodecIDs);
+ appendFourCCs("\naudio"_s, parameters.allowedMediaAudioCodecIDs);
+ appendFourCCs("\ncaptions"_s, parameters.allowedMediaCaptionFormatTypes);
+ return key.toString();
+}
+
bool MediaSource::isTypeSupported(ScriptExecutionContext& context, const String& type)
{
Vector<ContentType> mediaContentTypesRequiringHardwareSupport;
@@ -1035,7 +1063,8 @@ bool MediaSource::isTypeSupported(Script
}
auto& cache = MediaSourceTypeSupportedCache::singleton();
- if (auto cached = cache.lookup(contentType.raw()))
+ auto cacheKey = mediaSourceTypeCacheKey(parameters);
+ if (auto cached = cache.lookup(cacheKey))
return *cached;
MediaPlayer::SupportsType supported;
@@ -1049,7 +1078,7 @@ bool MediaSource::isTypeSupported(Script
else
isSupported = supported == MediaPlayer::SupportsType::IsSupported;
- cache.store(contentType.raw(), isSupported);
+ cache.store(cacheKey, isSupported);
return isSupported;
}
|