Bug 1176218 - Pass MediaContentType to MP4Decoder::CanHandleMediaType - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Sat, 01 Oct 2016 18:10:18 +1000
changeset 419883 41d3cee42a88e470ac078d1a6f7baaad24ece90c
parent 419882 a2a2242d6b542a3815e24b429097ea8bd4fd8cf4
child 419884 5110f5459d30334081d47f2aa44884c033a23754
push id31034
push usergsquelart@mozilla.com
push dateSat, 01 Oct 2016 12:07:57 +0000
reviewersjya
bugs1176218
milestone52.0a1
Bug 1176218 - Pass MediaContentType to MP4Decoder::CanHandleMediaType - r?jya Just passing the new MediaContentType struct, with no processing changes (yet). MozReview-Commit-ID: KZ4xkCihPb1
dom/media/DecoderTraits.cpp
dom/media/fmp4/MP4Decoder.cpp
dom/media/fmp4/MP4Decoder.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -250,21 +250,27 @@ static bool
 IsDirectShowSupportedType(const nsACString& aType)
 {
   return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
 }
 #endif
 
 #ifdef MOZ_FMP4
 static bool
+IsMP4SupportedType(const MediaContentType& aParsedType,
+                   DecoderDoctorDiagnostics* aDiagnostics)
+{
+  return MP4Decoder::CanHandleMediaType(aParsedType, aDiagnostics);
+}
+static bool
 IsMP4SupportedType(const nsACString& aType,
-                   DecoderDoctorDiagnostics* aDiagnostics,
-                   const nsAString& aCodecs = EmptyString())
+                   DecoderDoctorDiagnostics* aDiagnostics)
 {
-  return MP4Decoder::CanHandleMediaType(aType, aCodecs, aDiagnostics);
+  MediaContentType parsed{nsDependentCString(aType.Data(), aType.Length())};
+  return IsMP4SupportedType(parsed, aDiagnostics);
 }
 #endif
 
 /* static */ bool
 DecoderTraits::IsMP4TypeAndEnabled(const nsACString& aType,
                                    DecoderDoctorDiagnostics* aDiagnostics)
 {
 #ifdef MOZ_FMP4
@@ -332,17 +338,17 @@ CanHandleCodecsType(const MediaContentTy
       // We can only reach this position if a particular codec was requested,
       // webm is supported and working: the codec must be invalid.
       return CANPLAY_NO;
     }
   }
 #endif
 #ifdef MOZ_FMP4
   if (DecoderTraits::IsMP4TypeAndEnabled(aType.MimeType(), aDiagnostics)) {
-    if (IsMP4SupportedType(aType.MimeType(), aDiagnostics, aType.Codecs())) {
+    if (IsMP4SupportedType(aType, aDiagnostics)) {
       return CANPLAY_YES;
     } else {
       // We can only reach this position if a particular codec was requested,
       // fmp4 is supported and working: the codec must be invalid.
       return CANPLAY_NO;
     }
   }
 #endif
--- a/dom/media/fmp4/MP4Decoder.cpp
+++ b/dom/media/fmp4/MP4Decoder.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "MP4Decoder.h"
+#include "MediaContentType.h"
 #include "MediaDecoderStateMachine.h"
 #include "MP4Demuxer.h"
 #include "mozilla/Preferences.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "mozilla/CDMProxy.h"
 #include "mozilla/Logging.h"
 #include "mozilla/SharedThreadPool.h"
 #include "nsMimeTypes.h"
@@ -74,56 +75,55 @@ IsWhitelistedH264Codec(const nsAString& 
          (profile == H264_PROFILE_BASE ||
           profile == H264_PROFILE_MAIN ||
           profile == H264_PROFILE_EXTENDED ||
           profile == H264_PROFILE_HIGH);
 }
 
 /* static */
 bool
-MP4Decoder::CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
-                               const nsAString& aCodecs,
+MP4Decoder::CanHandleMediaType(const MediaContentType& aType,
                                DecoderDoctorDiagnostics* aDiagnostics)
 {
   if (!IsEnabled()) {
     return false;
   }
 
   // Whitelist MP4 types, so they explicitly match what we encounter on
   // the web, as opposed to what we use internally (i.e. what our demuxers
   // etc output).
-  const bool isMP4Audio = aMIMETypeExcludingCodecs.EqualsASCII("audio/mp4") ||
-                          aMIMETypeExcludingCodecs.EqualsASCII("audio/x-m4a") ||
-                          aMIMETypeExcludingCodecs.EqualsASCII("audio/opus");
+  const bool isMP4Audio = aType.MimeType().EqualsASCII("audio/mp4") ||
+                          aType.MimeType().EqualsASCII("audio/x-m4a") ||
+                          aType.MimeType().EqualsASCII("audio/opus");
   const bool isMP4Video =
   // On B2G, treat 3GPP as MP4 when Gonk PDM is available.
 #ifdef MOZ_GONK_MEDIACODEC
-    aMIMETypeExcludingCodecs.EqualsASCII(VIDEO_3GPP) ||
+      aType.MimeType().EqualsASCII(VIDEO_3GPP) ||
 #endif
-    aMIMETypeExcludingCodecs.EqualsASCII("video/mp4") ||
-    aMIMETypeExcludingCodecs.EqualsASCII("video/quicktime") ||
-    aMIMETypeExcludingCodecs.EqualsASCII("video/x-m4v");
+      aType.MimeType().EqualsASCII("video/mp4") ||
+      aType.MimeType().EqualsASCII("video/quicktime") ||
+      aType.MimeType().EqualsASCII("video/x-m4v");
   if (!isMP4Audio && !isMP4Video) {
     return false;
   }
 
   nsTArray<nsCString> codecMimes;
-  if (aCodecs.IsEmpty()) {
+  if (aType.Codecs().IsEmpty()) {
     // No codecs specified. Assume AAC/H.264
     if (isMP4Audio) {
       codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mp4a-latm"));
     } else {
       MOZ_ASSERT(isMP4Video);
       codecMimes.AppendElement(NS_LITERAL_CSTRING("video/avc"));
     }
   } else {
     // Verify that all the codecs specified are ones that we expect that
     // we can play.
     nsTArray<nsString> codecs;
-    if (!ParseCodecsString(aCodecs, codecs)) {
+    if (!ParseCodecsString(aType.Codecs(), codecs)) {
       return false;
     }
     for (const nsString& codec : codecs) {
       if (IsAACCodecString(codec)) {
         codecMimes.AppendElement(NS_LITERAL_CSTRING("audio/mp4a-latm"));
         continue;
       }
       if (codec.EqualsLiteral("mp3")) {
@@ -147,34 +147,16 @@ MP4Decoder::CanHandleMediaType(const nsA
     if (!platform->SupportsMimeType(codecMime, aDiagnostics)) {
       return false;
     }
   }
 
   return true;
 }
 
-/* static */ bool
-MP4Decoder::CanHandleMediaType(const nsAString& aContentType,
-                               DecoderDoctorDiagnostics* aDiagnostics)
-{
-  nsContentTypeParser parser(aContentType);
-  nsAutoString mimeType;
-  nsresult rv = parser.GetType(mimeType);
-  if (NS_FAILED(rv)) {
-    return false;
-  }
-  nsString codecs;
-  parser.GetParameter("codecs", codecs);
-
-  return CanHandleMediaType(NS_ConvertUTF16toUTF8(mimeType),
-                            codecs,
-                            aDiagnostics);
-}
-
 /* static */
 bool
 MP4Decoder::IsH264(const nsACString& aMimeType)
 {
   return aMimeType.EqualsLiteral("video/mp4") ||
          aMimeType.EqualsLiteral("video/avc");
 }
 
--- a/dom/media/fmp4/MP4Decoder.h
+++ b/dom/media/fmp4/MP4Decoder.h
@@ -7,40 +7,36 @@
 #define MP4Decoder_h_
 
 #include "MediaDecoder.h"
 #include "MediaFormatReader.h"
 #include "mozilla/dom/Promise.h"
 
 namespace mozilla {
 
+class MediaContentType;
+
 // Decoder that uses a bundled MP4 demuxer and platform decoders to play MP4.
 class MP4Decoder : public MediaDecoder
 {
 public:
   explicit MP4Decoder(MediaDecoderOwner* aOwner);
 
   MediaDecoder* Clone(MediaDecoderOwner* aOwner) override {
     if (!IsEnabled()) {
       return nullptr;
     }
     return new MP4Decoder(aOwner);
   }
 
   MediaDecoderStateMachine* CreateStateMachine() override;
 
-  // Returns true if aMIMEType is a type that we think we can render with the
-  // a MP4 platform decoder backend. If aCodecs is non emtpy, it is filled
-  // with a comma-delimited list of codecs to check support for. Notes in
-  // out params wether the codecs string contains AAC or H.264.
-  static bool CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
-                                 const nsAString& aCodecs,
-                                 DecoderDoctorDiagnostics* aDiagnostics);
-
-  static bool CanHandleMediaType(const nsAString& aMIMEType,
+  // Returns true if aType is a type that we think we can render with the
+  // a MP4 platform decoder backend.
+  static bool CanHandleMediaType(const MediaContentType& aType,
                                  DecoderDoctorDiagnostics* aDiagnostics);
 
   // Return true if aMimeType is a one of the strings used by our demuxers to
   // identify H264. Does not parse general content type strings, i.e. white
   // space matters.
   static bool IsH264(const nsACString& aMimeType);
 
   // Returns true if the MP4 backend is preffed on.