Bug 1176218 - p3. Add DecoderTraits::CanHandleContentType - r=jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Mon, 26 Sep 2016 16:43:16 +1000
changeset 421995 85b8e852f004b2728b06831c43b33ee4e7aebe52
parent 421994 823717a46e698342dce0f9e0b5bbfab21281297d
child 421996 11bcd26aaf0fd74fb02416b1d0c9b4c2b5d73345
push id31653
push usergsquelart@mozilla.com
push dateFri, 07 Oct 2016 06:47:50 +0000
reviewersjya
bugs1176218
milestone52.0a1
Bug 1176218 - p3. Add DecoderTraits::CanHandleContentType - r=jya Instead of taking MIME&codecs strings, CanHandleContentType takes an MediaContentType, which can be used to access these and other parameters. MozReview-Commit-ID: 14Cg6JoQS0g
dom/media/DecoderTraits.cpp
dom/media/DecoderTraits.h
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.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 "DecoderTraits.h"
+#include "MediaContentType.h"
 #include "MediaDecoder.h"
 #include "nsCharSeparatedTokenizer.h"
 #include "nsMimeTypes.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Telemetry.h"
 
 #include "OggDecoder.h"
 #include "OggReader.h"
@@ -487,16 +488,31 @@ DecoderTraits::CanHandleMediaType(const 
   if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
       EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), nullptr)) {
     return CANPLAY_MAYBE;
   }
 #endif
   return CANPLAY_NO;
 }
 
+/* static */
+CanPlayStatus
+DecoderTraits::CanHandleContentType(const MediaContentType& aContentType,
+                                    DecoderDoctorDiagnostics* aDiagnostics)
+{
+  if (!aContentType.IsValid()) {
+    return CANPLAY_NO;
+  }
+
+  return CanHandleMediaType(aContentType.GetMIMEType().Data(),
+                            aContentType.HaveCodecs(),
+                            aContentType.GetCodecs(),
+                            aDiagnostics);
+}
+
 // Instantiates but does not initialize decoder.
 static
 already_AddRefed<MediaDecoder>
 InstantiateDecoder(const nsACString& aType,
                    MediaDecoderOwner* aOwner,
                    DecoderDoctorDiagnostics* aDiagnostics)
 {
   MOZ_ASSERT(NS_IsMainThread());
--- a/dom/media/DecoderTraits.h
+++ b/dom/media/DecoderTraits.h
@@ -11,28 +11,33 @@
 
 class nsAString;
 class nsACString;
 
 namespace mozilla {
 
 class AbstractMediaDecoder;
 class DecoderDoctorDiagnostics;
+class MediaContentType;
 class MediaDecoder;
 class MediaDecoderOwner;
 class MediaDecoderReader;
 
 enum CanPlayStatus {
   CANPLAY_NO,
   CANPLAY_MAYBE,
   CANPLAY_YES
 };
 
 class DecoderTraits {
 public:
+  // Returns the CanPlayStatus indicating if we can handle this content type.
+  static CanPlayStatus CanHandleContentType(const MediaContentType& aContentType,
+                                            DecoderDoctorDiagnostics* aDiagnostics);
+
   // Returns the CanPlayStatus indicating if we can handle this
   // MIME type. The MIME type should not include the codecs parameter.
   // That parameter should be passed in aRequestedCodecs, and will only be
   // used if whether a given MIME type being handled depends on the
   // codec that will be used.  If the codecs parameter has not been
   // specified, pass false in aHaveRequestedCodecs.
   static CanPlayStatus CanHandleMediaType(const char* aMIMEType,
                                           bool aHaveRequestedCodecs,