Bug 1594466 - Don't rewrite mimeType if fully defined. r=bryce
authorAndreas Pehrson <apehrson@mozilla.com>
Tue, 12 Nov 2019 10:30:16 +0000
changeset 501560 9e3f44e87a1a2be927c7fab135653c6b86b982c9
parent 501559 1a1b309ca7a1d7889c335e0813689988992ec446
child 501561 055e0a0e4bf094df48a577248d5999199dae9e6e
child 501991 d64119136e15458d4aea5c548b4d10d7099d78f6
push id36795
push usermalexandru@mozilla.com
push dateTue, 12 Nov 2019 21:49:46 +0000
treeherdermozilla-central@9e3f44e87a1a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce
bugs1594466
milestone72.0a1
first release with
nightly linux32
9e3f44e87a1a / 72.0a1 / 20191112214946 / files
nightly linux64
9e3f44e87a1a / 72.0a1 / 20191112214946 / files
nightly mac
9e3f44e87a1a / 72.0a1 / 20191112214946 / files
nightly win32
9e3f44e87a1a / 72.0a1 / 20191112214946 / files
nightly win64
9e3f44e87a1a / 72.0a1 / 20191112214946 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
dom/media/MediaRecorder.cpp
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -444,48 +444,66 @@ TypeSupport IsTypeSupportedImpl(const ns
 
 nsString SelectMimeType(bool aHasVideo, bool aHasAudio,
                         const nsString& aConstrainedMimeType) {
   MOZ_ASSERT(aHasVideo || 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);
       }
     }
+
+    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()));
   }
 
-  nsString result = NS_ConvertUTF8toUTF16(nsPrintfCString(
-      "%s; codecs=%s", majorType.get(), NS_ConvertUTF16toUTF8(codecs).get()));
-
   MOZ_ASSERT_IF(aHasAudio,
                 CanRecordAudioTrackWith(MakeMediaContainerType(result),
                                         result) == TypeSupport::Supported);
   MOZ_ASSERT_IF(aHasVideo,
                 CanRecordVideoTrackWith(MakeMediaContainerType(result),
                                         result) == TypeSupport::Supported);
   return result;
 }