Bug 1580695 - Revert bug 1533129. r=alwu,bryce

This  change was a workaround a Youtube bug that expected a particular behaviour from old TV and that we were exploiting. It was adding support for unsupported, unofficial code.

MediaCapabilities is how things should be done.

Making this code to work conditionally is too much effort. Reverting it entirely is easier.

Differential Revision: https://phabricator.services.mozilla.com/D49515

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2019-10-24 22:50:35 +00:00
parent e064323a59
commit af3748243a
6 changed files with 6 additions and 246 deletions

View File

@ -117,7 +117,7 @@ static int32_t GetParameterAsNumber(const nsContentTypeParser& aParser,
MediaExtendedMIMEType::MediaExtendedMIMEType(
const nsACString& aOriginalString, const nsACString& aMIMEType,
bool aHaveCodecs, const nsAString& aCodecs, int32_t aWidth, int32_t aHeight,
double aFramerate, int32_t aBitrate, EOTF aEOTF, int32_t aChannels)
double aFramerate, int32_t aBitrate)
: mOriginalString(aOriginalString),
mMIMEType(aMIMEType),
mHaveCodecs(aHaveCodecs),
@ -125,8 +125,6 @@ MediaExtendedMIMEType::MediaExtendedMIMEType(
mWidth(aWidth),
mHeight(aHeight),
mFramerate(aFramerate),
mEOTF(aEOTF),
mChannels(aChannels),
mBitrate(aBitrate) {}
MediaExtendedMIMEType::MediaExtendedMIMEType(
@ -184,18 +182,6 @@ Maybe<double> MediaExtendedMIMEType::ComputeFractionalString(
return Some(result);
}
static EOTF GetParameterAsEOTF(const nsContentTypeParser& aParser) {
nsAutoString eotf;
nsresult rv = aParser.GetParameter("eotf", eotf);
if (NS_FAILED_impl(rv)) {
return EOTF::UNSPECIFIED;
}
if (eotf.LowerCaseEqualsASCII("bt709")) {
return EOTF::BT709;
}
return EOTF::NOT_SUPPORTED;
}
Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsAString& aType) {
nsContentTypeParser parser(aType);
nsAutoString mime;
@ -217,12 +203,10 @@ Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(const nsAString& aType) {
int32_t height = GetParameterAsNumber(parser, "height", -1);
double framerate = GetParameterAsNumber(parser, "framerate", -1);
int32_t bitrate = GetParameterAsNumber(parser, "bitrate", -1);
EOTF eotf = GetParameterAsEOTF(parser);
int32_t channels = GetParameterAsNumber(parser, "channels", -1);
return Some(MediaExtendedMIMEType(NS_ConvertUTF16toUTF8(aType), mime8,
haveCodecs, codecs, width, height,
framerate, bitrate, eotf, channels));
framerate, bitrate));
}
Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(
@ -252,10 +236,9 @@ Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(
return Nothing();
}
return Some(MediaExtendedMIMEType(NS_ConvertUTF16toUTF8(aConfig.mContentType),
mime8, haveCodecs, codecs, aConfig.mWidth,
aConfig.mHeight, framerate.ref(),
aConfig.mBitrate, EOTF::UNSPECIFIED));
return Some(MediaExtendedMIMEType(
NS_ConvertUTF16toUTF8(aConfig.mContentType), mime8, haveCodecs, codecs,
aConfig.mWidth, aConfig.mHeight, framerate.ref(), aConfig.mBitrate));
}
Maybe<MediaExtendedMIMEType> MakeMediaExtendedMIMEType(

View File

@ -143,13 +143,6 @@ class MediaCodecs {
nsString mCodecs;
};
// Electro-Optical Transfer Functions
enum class EOTF {
UNSPECIFIED = -1,
NOT_SUPPORTED = 0,
BT709 = 1,
};
// Class containing pre-parsed media MIME type parameters, e.g.:
// MIME type/subtype, optional codecs, etc.
class MediaExtendedMIMEType {
@ -172,9 +165,6 @@ class MediaExtendedMIMEType {
Maybe<int32_t> GetBitrate() const { return GetMaybeNumber(mBitrate); }
Maybe<int32_t> GetChannels() const { return GetMaybeNumber(mChannels); }
Maybe<int32_t> GetSamplerate() const { return GetMaybeNumber(mSamplerate); }
Maybe<EOTF> GetEOTF() const {
return (mEOTF == EOTF::UNSPECIFIED) ? Nothing() : Some(mEOTF);
}
// Original string. Note that "type/subtype" may not be lowercase,
// use Type().AsString() instead to get the normalized "type/subtype".
@ -197,8 +187,7 @@ class MediaExtendedMIMEType {
MediaExtendedMIMEType(const nsACString& aOriginalString,
const nsACString& aMIMEType, bool aHaveCodecs,
const nsAString& aCodecs, int32_t aWidth,
int32_t aHeight, double aFramerate, int32_t aBitrate,
EOTF aEOTF = EOTF::UNSPECIFIED, int32_t aChannels = -1);
int32_t aHeight, double aFramerate, int32_t aBitrate);
MediaExtendedMIMEType(const nsACString& aOriginalString,
const nsACString& aMIMEType, bool aHaveCodecs,
const nsAString& aCodecs, int32_t aChannels,
@ -217,7 +206,6 @@ class MediaExtendedMIMEType {
int32_t mWidth = -1; // -1 if not provided.
int32_t mHeight = -1; // -1 if not provided.
double mFramerate = -1; // -1 if not provided.
EOTF mEOTF = EOTF::UNSPECIFIED;
// For audio
int32_t mChannels = -1; // -1 if not provided.
int32_t mSamplerate = -1; // -1 if not provided.

View File

@ -360,62 +360,12 @@ void MediaSource::EndOfStream(const MediaResult& aError) {
mDecoder->DecodeError(aError);
}
static bool AreExtraParametersSane(const nsAString& aType) {
Maybe<MediaContainerType> containerType = MakeMediaContainerType(aType);
if (!containerType) {
return false;
}
auto extendedType = containerType->ExtendedType();
auto bitrate = extendedType.GetBitrate();
if (bitrate && *bitrate > 10000000) {
return false;
}
if (containerType->Type().HasVideoMajorType()) {
auto width = extendedType.GetWidth();
if (width && *width > MAX_VIDEO_WIDTH) {
return false;
}
auto height = extendedType.GetHeight();
if (height && *height > MAX_VIDEO_HEIGHT) {
return false;
}
auto framerate = extendedType.GetFramerate();
if (framerate && *framerate > 1000) {
return false;
}
auto eotf = extendedType.GetEOTF();
if (eotf && *eotf == EOTF::NOT_SUPPORTED) {
return false;
}
} else if (containerType->Type().HasAudioMajorType()) {
auto channels = extendedType.GetChannels();
if (channels && *channels > 6) {
return false;
}
auto samplerate = extendedType.GetSamplerate();
if (samplerate && *samplerate > 192000) {
return false;
}
}
return true;
}
static bool IsYouTube(const GlobalObject& aOwner) {
nsCString domain;
return aOwner.GetSubjectPrincipal() &&
NS_SUCCEEDED(aOwner.GetSubjectPrincipal()->GetBaseDomain(domain)) &&
domain.EqualsLiteral("youtube.com");
}
/* static */
bool MediaSource::IsTypeSupported(const GlobalObject& aOwner,
const nsAString& aType) {
MOZ_ASSERT(NS_IsMainThread());
DecoderDoctorDiagnostics diagnostics;
nsresult rv = IsTypeSupported(aType, &diagnostics);
if (NS_SUCCEEDED(rv) && IsYouTube(aOwner) && !AreExtraParametersSane(aType)) {
rv = NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
nsCOMPtr<nsPIDOMWindowInner> window =
do_QueryInterface(aOwner.GetAsSupports());
diagnostics.StoreFormatDiagnostics(window ? window->GetExtantDoc() : nullptr,

View File

@ -1,17 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>MSE: isTypeSupported extended mime extensions</title>
</head>
<body>
<script>
window.addEventListener("message", (e) => {
const result = MediaSource.isTypeSupported(e.data);
const w = window.opener || window.parent;
w.postMessage(result, "*");
});
const w = window.opener || window.parent;
w.postMessage("ready", "*");
</script>
</body>
</html>

View File

@ -49,7 +49,6 @@ support-files =
tags_before_cluster.webm
tags_before_cluster.webm^header^
1516754.webm 1516754.webm^headers^
file_isTypeSupported.html
[test_AbortAfterPartialMediaSegment.html]
[test_AppendPartialInitSegment.html]
@ -85,8 +84,6 @@ skip-if = toolkit == 'android' # Not supported on android
skip-if = toolkit == 'android' # bug 1341519, bug 1401090
[test_FrameSelection_mp4.html]
skip-if = toolkit == 'android' || os == 'win' || (os == 'mac' && os_version == '10.14') # Not supported on android, # bug 1487973, mac due to bug 1487973
[test_isTypeSupportedExtensions.html]
skip-if = android_version >= 28 # bug 1543669 ; cross origins broken on our Android 8.0 emulators?
[test_HaveMetadataUnbufferedSeek.html]
[test_HaveMetadataUnbufferedSeek_mp4.html]
skip-if = toolkit == 'android' # Not supported on android

View File

@ -1,141 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>MSE: isTypeSupported extended mime extensions</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
// Returns a promise that resolves with the next message received on
// our window.
function nextMessage() {
return new Promise((resolve, reject) => {
const f = (event) => {
window.removeEventListener("message", f);
resolve(event);
};
window.addEventListener("message", f);
});
}
// Tests YouTube's MIME type extensions. Runs through the list of cases
// and checks that the MIME extensions are only supported on a YouTube
// origin, where supported means we check the invalid cases and reject
// them.
async function runTest() {
const supportedCases = [
'video/mp4; codecs="avc1.42001E"',
'audio/mp4; codecs="mp4a.40.2"',
'video/webm; codecs="vp09.02.51.10.01.09.16.09"',
'audio/webm; codecs="opus"',
'audio/webm; codecs="opus"; channels=2',
'video/webm; codecs="vp9"',
'video/webm; codecs="vp9"; width=640',
'video/webm; codecs="vp9"',
'video/webm; codecs="vp9"; height=360',
'video/webm; codecs="vp9"',
'video/webm; codecs="vp9"; framerate=30',
'video/webm; codecs="vp9"; width=3840; height=2160; bitrate=2000000',
'video/mp4; codecs="avc1.4d4015"; width=426; height=240; framerate=24',
'video/mp4; codecs="avc1.4d401e"; width=640; height=360; framerate=24',
'video/mp4; codecs="avc1.4d401e"; width=854; height=480; framerate=24',
'video/mp4; codecs="avc1.4d401f"; width=1280; height=720; framerate=24',
'video/mp4; codecs="avc1.640028"; width=1920; height=1080; framerate=24',
'audio/mp4; codecs="mp4a.40.2"; channels=2',
'video/mp4; codecs="avc1.4d400c"; width=256; height=144; framerate=24',
'audio/webm; codecs="vorbis"; channels=2',
'video/webm; codecs="vp9"',
'video/webm; codecs="vp9"; eotf=bt709',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=426; height=240; framerate=24',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=640; height=360; framerate=24',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=854; height=480; framerate=24',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=1280; height=720; framerate=24',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=1920; height=1080; framerate=24',
'audio/webm; codecs="opus"; channels=2',
'audio/webm; codecs="opus"; channels=2',
'audio/webm; codecs="opus"; channels=2',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=2560; height=1440; framerate=24',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=3840; height=2160; framerate=24',
'video/mp4; codecs="av01.0.05M.08"; width=256; height=144; framerate=24',
'video/mp4; codecs="av01.0.05M.08"; width=426; height=240; framerate=24',
'video/mp4; codecs="av01.0.05M.08"; width=640; height=360; framerate=24',
'video/mp4; codecs="av01.0.05M.08"; width=854; height=480; framerate=24',
'video/mp4; codecs="av01.0.05M.08"; width=1280; height=720; framerate=24',
'video/mp4; codecs="avc1.4d4015"; width=426; height=240; framerate=25',
'video/mp4; codecs="avc1.4d401e"; width=640; height=360; framerate=25',
'video/mp4; codecs="avc1.4d401e"; width=854; height=480; framerate=25',
'video/mp4; codecs="avc1.4d401f"; width=1280; height=720; framerate=25',
'video/mp4; codecs="avc1.640028"; width=1920; height=1080; framerate=25',
'audio/mp4; codecs="mp4a.40.2"; channels=2',
'video/mp4; codecs="avc1.4d400c"; width=256; height=144; framerate=25',
'audio/webm; codecs="vorbis"; channels=2',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=426; height=240; framerate=25',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=640; height=360; framerate=25',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=854; height=480; framerate=25',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=1280; height=720; framerate=25',
'video/webm; codecs="vp09.00.51.08.01.01.01.01"; width=1920; height=1080; framerate=25',
'audio/webm; codecs="opus"; channels=2',
'audio/webm; codecs="opus"; channels=2',
'audio/webm; codecs="opus"; channels=2',
];
const unsupportedOnYTCases = [
'audio/webm; codecs="opus"; channels=99',
'video/webm; codecs="vp9"; width=99999',
'video/webm; codecs="vp9"; height=99999',
'video/webm; codecs="vp9"; framerate=9999',
'video/webm; codecs="vp9"; width=3840; height=2160; bitrate=20000000',
'video/webm; codecs="vp9"; eotf=catavision',
];
const unsupportedCases = [
'video/webm; codecs="vp09.02.51.10.01.09.99.99"',
];
const frame = document.getElementById("frame");
const supportedOnYT = async (t) => {
// Sends a message to the YouTube iframe, which runs the check there.
const m = nextMessage();
frame.contentWindow.postMessage(t, "*");
const result = await m;
return result.data;
};
for (const t of supportedCases) {
ok(MediaSource.isTypeSupported(t), "Case '" + t + "' supported in non-YouTube origin");
is(await supportedOnYT(t), true, "Case '" + t + "' supported in YouTube origin");
}
for (const t of unsupportedOnYTCases) {
ok(MediaSource.isTypeSupported(t), "Case '" + t + "' supported in non-YouTube origin");
is(await supportedOnYT(t), false, "Case '" + t + "' *not* supported in YouTube origin");
}
for (const t of unsupportedCases) {
ok(!MediaSource.isTypeSupported(t), "Case '" + t + "' *not* supported in non-YouTube origin");
is(await supportedOnYT(t), false, "Case '" + t + "' *not* supported in YouTube origin");
}
SimpleTest.finish();
}
// Start the test once the child fake YouTube origin frame has signaled
// it's ready to receive requests.
nextMessage().then(runTest);
const f = document.createElement("iframe");
f.id = "frame";
f.src = "http://mochitest.youtube.com:443/tests/dom/media/mediasource/test/file_isTypeSupported.html";
document.getElementById("test").appendChild(f);
</script>
</pre>
</body>
</html>