Bug 1176218 - p9. Pass MediaContentType to MP4Decoder::CanHandleMediaType - r=jya
Just passing the new MediaContentType struct, with no processing changes (yet).
MozReview-Commit-ID: KZ4xkCihPb1
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -249,21 +249,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 contentType{aType};
+ return IsMP4SupportedType(contentType, aDiagnostics);
}
#endif
/* static */ bool
DecoderTraits::IsMP4TypeAndEnabled(const nsACString& aType,
DecoderDoctorDiagnostics* aDiagnostics)
{
#ifdef MOZ_FMP4
@@ -335,17 +341,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.GetMIMEType(), aDiagnostics)) {
- if (IsMP4SupportedType(aType.GetMIMEType(), aDiagnostics, aType.GetCodecs())) {
+ 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,24 +1,24 @@
/* -*- 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"
-#include "nsContentTypeParser.h"
#include "VideoUtils.h"
#ifdef XP_WIN
#include "mozilla/WindowsVersion.h"
#endif
#ifdef MOZ_WIDGET_ANDROID
#include "nsIGfxInfo.h"
#endif
@@ -74,56 +74,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.GetMIMEType().EqualsASCII("audio/mp4") ||
+ aType.GetMIMEType().EqualsASCII("audio/x-m4a") ||
+ aType.GetMIMEType().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.GetMIMEType().EqualsASCII(VIDEO_3GPP) ||
#endif
- aMIMETypeExcludingCodecs.EqualsASCII("video/mp4") ||
- aMIMETypeExcludingCodecs.EqualsASCII("video/quicktime") ||
- aMIMETypeExcludingCodecs.EqualsASCII("video/x-m4v");
+ aType.GetMIMEType().EqualsASCII("video/mp4") ||
+ aType.GetMIMEType().EqualsASCII("video/quicktime") ||
+ aType.GetMIMEType().EqualsASCII("video/x-m4v");
if (!isMP4Audio && !isMP4Video) {
return false;
}
nsTArray<nsCString> codecMimes;
- if (aCodecs.IsEmpty()) {
+ if (aType.GetCodecs().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.GetCodecs(), 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 +146,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.