diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp index 579119163076..fdf0c9733518 100644 --- a/dom/html/HTMLMediaElement.cpp +++ b/dom/html/HTMLMediaElement.cpp @@ -4513,6 +4513,15 @@ void HTMLMediaElement::UnbindFromTree(bool aDeep, RunInStableState(task); } +static bool +IsVP9InMP4(const MediaContainerType& aContainerType) +{ + const MediaContainerType mimeType(aContainerType.Type()); + return DecoderTraits::IsMP4SupportedType(mimeType, + /* DecoderDoctorDiagnostics* */ nullptr) + && IsVP9CodecString(aContainerType.ExtendedType().Codecs().AsString()); +} + /* static */ CanPlayStatus HTMLMediaElement::GetCanPlay(const nsAString& aType, @@ -4522,7 +4531,16 @@ HTMLMediaElement::GetCanPlay(const nsAString& aType, if (!containerType) { return CANPLAY_NO; } - return DecoderTraits::CanHandleContainerType(*containerType, aDiagnostics); + CanPlayStatus status = DecoderTraits::CanHandleContainerType(*containerType, aDiagnostics); + if (status == CANPLAY_YES && IsVP9InMP4(*containerType)) { + // We don't have a demuxer that can handle VP9 in non-fragmented MP4. + // So special-case VP9 in MP4 here, as we assume canPlayType() implies + // non-fragmented MP4 anyway. Note we report that we can play VP9 + // in MP4 in MediaSource.isTypeSupported(), as the fragmented MP4 + // demuxer can handle VP9 in fragmented MP4. + return CANPLAY_NO; + } + return status; } NS_IMETHODIMP diff --git a/dom/media/test/test_can_play_type_mpeg.html b/dom/media/test/test_can_play_type_mpeg.html index 43ff2c1a8b1b..744d2237d397 100644 --- a/dom/media/test/test_can_play_type_mpeg.html +++ b/dom/media/test/test_can_play_type_mpeg.html @@ -88,6 +88,23 @@ function check_mp4(v, enabled) { var expectedResult = IsSupportedAndroid() ? "" : "probably"; check("audio/mp4; codecs=\"flac\"", expectedResult); check("audio/mp4; codecs=flac", expectedResult); + + // VP9. + // Note: canPlayType assumes non-fragmented MP4. Once we support VP9 in + // non-fragmented MP4, we need to change this to report supported. + [ "video/mp4; codecs=vp9", + "video/mp4; codecs=\"vp9\"", + "video/mp4; codecs=\"vp9.0\"" + ].forEach((codec) => { + // canPlayType should not support VP9 in MP4... + check(codec, ""); + // But VP9 in MP4 is supported in MSE. + ok(MediaSource.isTypeSupported(codec), "VP9 in MP4 should be supported in MSE"); + }); + + check("video/mp4; codecs=vp9", ""); + check("video/mp4; codecs=\"vp9\"", ""); + check("video/mp4; codecs=\"vp9.0\"", ""); } function check_mp3(v, enabled) {