Bug 1594466 - Don't rewrite mimeType if fully defined. r=bryce

Prior to this patch the mimetype was rewritten per the printf format
"%s; codecs=%s" also when codecs were defined in the constrained mime type.

The latter '%s' would be the codecs string from the mime type parser, which
would have dropped any quotation marks surrounding the string.
Hence 'codecs="vp8, opus"' would be considered supported (quotation marks
included), but when selecting mime type in start(), it would be rewritten
with quotation marks dropped. Thus looking like 'codecs=vp8,' which is not
supported.

This patch removes the rewrite step when the mime type is fully defined with
codecs, so that the quotation marks are left in place as given to the
constructor.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andreas Pehrson 2019-11-12 10:30:16 +00:00
Родитель f866cb76ac
Коммит e8e03f5a05
1 изменённых файлов: 43 добавлений и 25 удалений

Просмотреть файл

@ -449,37 +449,55 @@ nsString SelectMimeType(bool aHasVideo, bool aHasAudio,
Maybe<MediaContainerType> constrainedType =
MakeMediaContainerType(aConstrainedMimeType);
nsCString majorType;
{
// Select major type and container.
if (constrainedType) {
MOZ_ASSERT_IF(aHasVideo, constrainedType->Type().HasVideoMajorType());
MOZ_ASSERT(!constrainedType->Type().HasApplicationMajorType());
majorType = constrainedType->Type().AsString();
} else if (aHasVideo) {
majorType = NS_LITERAL_CSTRING(VIDEO_WEBM);
} else {
majorType = NS_LITERAL_CSTRING(AUDIO_OGG);
}
}
// If we are recording video, Start() should have rejected any non-video mime
// types.
MOZ_ASSERT_IF(constrainedType && aHasVideo,
constrainedType->Type().HasVideoMajorType());
// IsTypeSupported() rejects application mime types.
MOZ_ASSERT_IF(constrainedType,
!constrainedType->Type().HasApplicationMajorType());
nsString codecs;
{
if (constrainedType && constrainedType->ExtendedType().HaveCodecs()) {
codecs = constrainedType->ExtendedType().Codecs().AsString();
} else {
if (aHasVideo && aHasAudio) {
codecs = NS_LITERAL_STRING("\"vp8, opus\"");
nsString result;
if (constrainedType && constrainedType->ExtendedType().HaveCodecs()) {
// The constrained mime type is fully defined (it has codecs!). No need to
// select anything.
result = NS_ConvertUTF8toUTF16(constrainedType->OriginalString());
} else {
// There is no constrained mime type, or there is and it is not fully
// defined but still valid. Select what's missing, so that we have major
// type, container and codecs.
// If there is a constrained mime type it should not have codecs defined,
// because then it is fully defined and used unchanged (covered earlier).
MOZ_ASSERT_IF(constrainedType,
!constrainedType->ExtendedType().HaveCodecs());
nsCString majorType;
{
if (constrainedType) {
// There is a constrained type. It has both major type and container in
// order to be valid. Use them as is.
majorType = constrainedType->Type().AsString();
} else if (aHasVideo) {
codecs = NS_LITERAL_STRING("vp8");
majorType = NS_LITERAL_CSTRING(VIDEO_WEBM);
} else {
codecs = NS_LITERAL_STRING("opus");
majorType = NS_LITERAL_CSTRING(AUDIO_OGG);
}
}
}
nsString result = NS_ConvertUTF8toUTF16(nsPrintfCString(
"%s; codecs=%s", majorType.get(), NS_ConvertUTF16toUTF8(codecs).get()));
nsCString codecs;
{
if (aHasVideo && aHasAudio) {
codecs = NS_LITERAL_CSTRING("\"vp8, opus\"");
} else if (aHasVideo) {
codecs = NS_LITERAL_CSTRING("vp8");
} else {
codecs = NS_LITERAL_CSTRING("opus");
}
}
result = NS_ConvertUTF8toUTF16(
nsPrintfCString("%s; codecs=%s", majorType.get(), codecs.get()));
}
MOZ_ASSERT_IF(aHasAudio,
CanRecordAudioTrackWith(MakeMediaContainerType(result),