Skip to content

Commit cf75cea

Browse files
committed
[GStreamer] Use an explicit allowlist of AAC AOTs
https://bugs.webkit.org/show_bug.cgi?id=311347 Reviewed by NOBODY (OOPS!). Currently the GStreamer ports of WebKit report support to any codec string starting with "mp4a" if there is a decoder that supports audio/mpeg, mpegversion=4. This is too optimistic and can lead to applications choosing to use newer MPEG-4 Audio codecs not yet supported by the user's system. This patch makes WebKit play it safer and instead only report support for AOTs with widespread support. This includes reporting AOT 42 (typically used with xHE-AAC) as not supported. Ideally we would query support for it somehow and reply accordingly, but that would necessitate decoders to provide a uniform API for querying such support, which unfortunately does not exist (and would be tricky in practice as support is not always binary). An environment variable is provided to declare explicit support or lack thereof in environments where this is well-known, as well as for debugging and experimentation. See: WebPlatformForEmbedded/WPEWebKit#1641 (but note that this patch takes a different approach than the original PR). * LayoutTests/platform/glib/imported/w3c/web-platform-tests/media-source/mediasource-is-type-supported-expected.txt: * Source/WebCore/platform/graphics/gstreamer/GStreamerRegistryScanner.cpp: (WebCore::GStreamerRegistryScanner::initializeDecoders):
1 parent 1ec6b31 commit cf75cea

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

LayoutTests/platform/glib/imported/w3c/web-platform-tests/media-source/mediasource-is-type-supported-expected.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ FAIL Test invalid mismatch between MIME type and codec ID "audio/webm;codecs="mp
2222
FAIL Test invalid mismatch between MIME type and codec ID "video/mp4;codecs="vp8"" assert_equals: supported expected false but got true
2323
FAIL Test invalid mismatch between MIME type and codec ID "video/mp4;codecs="vorbis"" assert_equals: supported expected false but got true
2424
FAIL Test invalid mismatch between MIME type and codec ID "video/webm;codecs="mp4a.40.2"" assert_equals: supported expected false but got true
25-
FAIL Test invalid codec ID "audio/mp4;codecs="mp4a"" assert_equals: supported expected false but got true
26-
FAIL Test invalid codec ID "audio/mp4;codecs="mp4a.40"" assert_equals: supported expected false but got true
27-
FAIL Test invalid codec ID "audio/mp4;codecs="mp4a.40."" assert_equals: supported expected false but got true
28-
FAIL Test invalid codec ID "audio/mp4;codecs="mp4a.67.3"" assert_equals: supported expected false but got true
25+
PASS Test invalid codec ID "audio/mp4;codecs="mp4a""
26+
PASS Test invalid codec ID "audio/mp4;codecs="mp4a.40""
27+
PASS Test invalid codec ID "audio/mp4;codecs="mp4a.40.""
28+
PASS Test invalid codec ID "audio/mp4;codecs="mp4a.67.3""
2929
PASS Test valid WebM type "video/webm;codecs="vp8""
3030
PASS Test valid WebM type "video/webm;codecs="vorbis""
3131
PASS Test valid WebM type "video/webm;codecs="vp8,vorbis""

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,29 @@ void GStreamerRegistryScanner::initializeDecoders(const GStreamerRegistryScanner
468468
m_decoderMimeTypeSet.add("audio/mpeg"_s);
469469
m_decoderMimeTypeSet.add("audio/x-mpeg"_s);
470470
m_decoderCodecMap.add("mpeg"_s, result);
471-
m_decoderCodecMap.add("mp4a*"_s, result);
471+
// AAC has accumulated lots of extensions over the years.
472+
// Unfortunately, decoders don't generally provide an API for querying support level, and support is not necessarily
473+
// binary as features may be incomplete.
474+
// We'll assume support for the extensions that as of 2026 are somewhat mainstream to avoid websites serving
475+
// audio incompatible with the user decoder, which would cause errors or quality degradation depending on signalling.
476+
//
477+
// RFC 6381 3.3. ISO Base Media File Format Name Space
478+
// Syntax: "mp4a." oti [ "." aud-oti ]
479+
// oti is the ObjectTypeIndication from MPEG-4 Systems (ISO 14996-1).
480+
// For oti=40 (MPEG-4 Audio), aud-oti represents the AOT.
481+
m_decoderCodecMap.add("mp4a.67"_s, result); // MPEG-2 AAC LC
482+
m_decoderCodecMap.add("mp4a.40.2"_s, result); // MPEG-4 AAC LC
483+
m_decoderCodecMap.add("mp4a.40.02"_s, result); // MPEG-4 AAC LC
484+
m_decoderCodecMap.add("mp4a.40.5"_s, result); // MPEG-4 HE-AAC v1 (AAC LC + SBR)
485+
m_decoderCodecMap.add("mp4a.40.05"_s, result); // MPEG-4 HE-AAC v1 (AAC LC + SBR)
486+
m_decoderCodecMap.add("mp4a.40.29"_s, result); // MPEG-4 HE-AAC v2 (AAC LC + SBR + PS)
487+
// As of writing, support for Extended HE-AAC (MPEG-D USAC) and xHE-AAC (MPEG-D USAC + MPEG-D DRC) -- which uses the
488+
// USAC AOT, is not yet widely available enough to be enabled by default.
489+
auto value = CStringView::unsafeFromUTF8(g_getenv("WEBKIT_GST_CAN_PLAY_USAC"));
490+
bool canPlayUsac = value.isEmpty() ? false : (WTF::equalLettersIgnoringASCIICase(value.span(), "true"_s)
491+
|| WTF::equalLettersIgnoringASCIICase(value.span(), "1"_s));
492+
if (canPlayUsac)
493+
m_decoderCodecMap.add("mp4a.40.42"_s, result); // MPEG-4 Extended HE-AAC and xHE-AAC (USAC AOT)
472494
}
473495

474496
auto opusSupported = factories.hasElementForMediaType(ElementFactories::Type::AudioDecoder, "audio/x-opus"_s);

0 commit comments

Comments
 (0)