Bug 1330284 - Use MediaContentType in DecoderTraits/InstantiateDecoder - r=jya
authorGerald Squelart <gsquelart@mozilla.com>
Sun, 01 Jan 2017 12:01:32 +1100
changeset 374465 93c96992037764a3d8dcec38dda60ab941e8f204
parent 374464 426109521b9a0fa5bdac77ce9c21da19b1c51b95
child 374466 45673c5c9e207343e9cb41a93350665c38261d04
push id6996
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 20:48:21 +0000
treeherdermozilla-beta@d89512dab048 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1330284
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1330284 - Use MediaContentType in DecoderTraits/InstantiateDecoder - r=jya MozReview-Commit-ID: ArFTeoGvWOl
dom/media/DecoderTraits.cpp
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -358,118 +358,123 @@ DecoderTraits::CanHandleContentType(cons
 {
   return CanHandleMediaType(aContentType, aDiagnostics);
 }
 
 /* static */
 bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType,
                                           DecoderDoctorDiagnostics* aDiagnostics)
 {
-  if (IsWaveSupportedType(nsDependentCString(aMIMEType))) {
+  Maybe<MediaContentType> contentType = MakeMediaContentType(aMIMEType);
+  if (!contentType) {
+    return false;
+  }
+
+  if (IsWaveSupportedType(contentType->Type().AsString())) {
     // We should not return true for Wave types, since there are some
     // Wave codecs actually in use in the wild that we don't support, and
     // we should allow those to be handled by plugins or helper apps.
     // Furthermore people can play Wave files on most platforms by other
     // means.
     return false;
   }
 
   // If an external plugin which can handle quicktime video is available
   // (and not disabled), prefer it over native playback as there several
   // codecs found in the wild that we do not handle.
-  if (nsDependentCString(aMIMEType).EqualsASCII("video/quicktime")) {
+  if (contentType->Type() == MEDIAMIMETYPE("video/quicktime")) {
     RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
     if (pluginHost &&
-        pluginHost->HavePluginForType(nsDependentCString(aMIMEType))) {
+        pluginHost->HavePluginForType(contentType->Type().AsString())) {
       return false;
     }
   }
 
-  Maybe<MediaContentType> parsed = MakeMediaContentType(aMIMEType);
-  if (!parsed) {
-    return false;
-  }
-  return CanHandleMediaType(*parsed, aDiagnostics)
-         != CANPLAY_NO;
+  return CanHandleMediaType(*contentType, aDiagnostics) != CANPLAY_NO;
 }
 
 // Instantiates but does not initialize decoder.
 static
 already_AddRefed<MediaDecoder>
-InstantiateDecoder(const nsACString& aType,
+InstantiateDecoder(const MediaContentType& aType,
                    MediaDecoderOwner* aOwner,
                    DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
   RefPtr<MediaDecoder> decoder;
 
 #ifdef MOZ_FMP4
-  if (IsMP4SupportedType(aType, aDiagnostics)) {
+  if (IsMP4SupportedType(aType.Type().AsString(), aDiagnostics)) {
     decoder = new MP4Decoder(aOwner);
     return decoder.forget();
   }
 #endif
-  if (IsMP3SupportedType(aType)) {
+  if (IsMP3SupportedType(aType.Type().AsString())) {
     decoder = new MP3Decoder(aOwner);
     return decoder.forget();
   }
-  if (IsAACSupportedType(aType)) {
+  if (IsAACSupportedType(aType.Type().AsString())) {
     decoder = new ADTSDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsOggSupportedType(aType)) {
+  if (IsOggSupportedType(aType.Type().AsString())) {
     decoder = new OggDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsWaveSupportedType(aType)) {
+  if (IsWaveSupportedType(aType.Type().AsString())) {
     decoder = new WaveDecoder(aOwner);
     return decoder.forget();
   }
-  if (IsFlacSupportedType(aType)) {
+  if (IsFlacSupportedType(aType.Type().AsString())) {
     decoder = new FlacDecoder(aOwner);
     return decoder.forget();
   }
 #ifdef MOZ_ANDROID_OMX
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
-      EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
-    decoder = new AndroidMediaDecoder(aOwner, aType);
+      EnsureAndroidMediaPluginHost()->FindDecoder(aType.Type().AsString(),
+                                                  nullptr)) {
+    decoder = new AndroidMediaDecoder(aOwner, aType.Type().AsString());
     return decoder.forget();
   }
 #endif
 
-  if (IsWebMSupportedType(aType)) {
+  if (IsWebMSupportedType(aType.Type().AsString())) {
     decoder = new WebMDecoder(aOwner);
     return decoder.forget();
   }
 
 #ifdef MOZ_DIRECTSHOW
   // Note: DirectShow should come before WMF, so that we prefer DirectShow's
   // MP3 support over WMF's.
-  if (IsDirectShowSupportedType(aType)) {
+  if (IsDirectShowSupportedType(aType.Type().AsString())) {
     decoder = new DirectShowDecoder(aOwner);
     return decoder.forget();
   }
 #endif
 
-  if (IsHttpLiveStreamingType(aType)) {
+  if (IsHttpLiveStreamingType(aType.Type().AsString())) {
     // We don't have an HLS decoder.
     Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
   }
 
   return nullptr;
 }
 
 /* static */
 already_AddRefed<MediaDecoder>
 DecoderTraits::CreateDecoder(const nsACString& aType,
                              MediaDecoderOwner* aOwner,
                              DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  return InstantiateDecoder(aType, aOwner, aDiagnostics);
+  Maybe<MediaContentType> type = MakeMediaContentType(aType);
+  if (!type) {
+    return nullptr;
+  }
+  return InstantiateDecoder(*type, aOwner, aDiagnostics);
 }
 
 /* static */
 MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MediaDecoderReader* decoderReader = nullptr;