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
--- 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,