Bug 1330284 - Use MediaContentType in MP3Decoder - r?jya
MozReview-Commit-ID: eahpZyDfgH
--- a/dom/media/DecoderTraits.cpp
+++ b/dom/media/DecoderTraits.cpp
@@ -108,23 +108,16 @@ DecoderTraits::IsMP4SupportedType(const
#ifdef MOZ_FMP4
return MP4Decoder::IsSupportedType(aType, aDiagnostics);
#else
return false;
#endif
}
static bool
-IsMP3SupportedType(const nsACString& aType,
- const nsAString& aCodecs = EmptyString())
-{
- return MP3Decoder::CanHandleMediaType(aType, aCodecs);
-}
-
-static bool
IsAACSupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
return ADTSDecoder::CanHandleMediaType(aType, aCodecs);
}
static bool
IsWaveSupportedType(const nsACString& aType,
@@ -189,18 +182,17 @@ CanHandleCodecsType(const MediaContentTy
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
- if (IsMP3SupportedType(mimeType.Type().AsString(),
- aType.ExtendedType().Codecs().AsString())) {
+ if (MP3Decoder::IsSupportedType(aType)) {
return CANPLAY_YES;
}
if (IsAACSupportedType(mimeType.Type().AsString(),
aType.ExtendedType().Codecs().AsString())) {
return CANPLAY_YES;
}
if (IsFlacSupportedType(mimeType.Type().AsString(),
aType.ExtendedType().Codecs().AsString())) {
@@ -273,17 +265,17 @@ CanHandleMediaType(const MediaContentTyp
return CANPLAY_MAYBE;
}
#endif
#if !defined(MOZ_OMX_WEBM_DECODER)
if (WebMDecoder::IsSupportedType(mimeType)) {
return CANPLAY_MAYBE;
}
#endif
- if (IsMP3SupportedType(mimeType.Type().AsString())) {
+ if (MP3Decoder::IsSupportedType(mimeType)) {
return CANPLAY_MAYBE;
}
if (IsAACSupportedType(mimeType.Type().AsString())) {
return CANPLAY_MAYBE;
}
if (IsFlacSupportedType(mimeType.Type().AsString())) {
return CANPLAY_MAYBE;
}
@@ -352,17 +344,17 @@ InstantiateDecoder(const MediaContentTyp
RefPtr<MediaDecoder> decoder;
#ifdef MOZ_FMP4
if (MP4Decoder::IsSupportedType(aType, aDiagnostics)) {
decoder = new MP4Decoder(aOwner);
return decoder.forget();
}
#endif
- if (IsMP3SupportedType(aType.Type().AsString())) {
+ if (MP3Decoder::IsSupportedType(aType)) {
decoder = new MP3Decoder(aOwner);
return decoder.forget();
}
if (IsAACSupportedType(aType.Type().AsString())) {
decoder = new ADTSDecoder(aOwner);
return decoder.forget();
}
if (OggDecoder::IsSupportedType(aType)) {
@@ -437,17 +429,17 @@ MediaDecoderReader* DecoderTraits::Creat
}
#ifdef MOZ_FMP4
if (MP4Decoder::IsSupportedType(*type,
/* DecoderDoctorDiagnostics* */ nullptr)) {
decoderReader = new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource()));
} else
#endif
- if (IsMP3SupportedType(aType)) {
+ if (MP3Decoder::IsSupportedType(*type)) {
decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
} else
if (IsAACSupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
} else
if (IsWaveSupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
} else
@@ -497,17 +489,17 @@ bool DecoderTraits::IsSupportedInVideoDo
OggDecoder::IsSupportedType(*type) ||
WebMDecoder::IsSupportedType(*type) ||
#ifdef MOZ_ANDROID_OMX
(MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(aType)) ||
#endif
#ifdef MOZ_FMP4
MP4Decoder::IsSupportedType(*type, /* DecoderDoctorDiagnostics* */ nullptr) ||
#endif
- IsMP3SupportedType(aType) ||
+ MP3Decoder::IsSupportedType(*type) ||
IsAACSupportedType(aType) ||
IsFlacSupportedType(aType) ||
#ifdef MOZ_DIRECTSHOW
IsDirectShowSupportedType(aType) ||
#endif
false;
}
--- a/dom/media/MP3Decoder.cpp
+++ b/dom/media/MP3Decoder.cpp
@@ -1,16 +1,17 @@
/* -*- 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 "MP3Decoder.h"
+#include "MediaContentType.h"
#include "MediaDecoderStateMachine.h"
#include "MediaFormatReader.h"
#include "MP3Demuxer.h"
#include "PDMFactory.h"
namespace mozilla {
MediaDecoder*
@@ -32,19 +33,21 @@ MP3Decoder::CreateStateMachine() {
bool
MP3Decoder::IsEnabled() {
RefPtr<PDMFactory> platform = new PDMFactory();
return platform->SupportsMimeType(NS_LITERAL_CSTRING("audio/mpeg"),
/* DecoderDoctorDiagnostics* */ nullptr);
}
/* static */
-bool MP3Decoder::CanHandleMediaType(const nsACString& aType,
- const nsAString& aCodecs)
+bool MP3Decoder::IsSupportedType(const MediaContentType& aContentType)
{
- if (aType.EqualsASCII("audio/mp3") || aType.EqualsASCII("audio/mpeg")) {
- return IsEnabled() &&
- (aCodecs.IsEmpty() || aCodecs.EqualsASCII("mp3"));
+ if (aContentType.Type() == MEDIAMIMETYPE("audio/mp3")
+ || aContentType.Type() == MEDIAMIMETYPE("audio/mpeg")) {
+ return
+ IsEnabled()
+ && (aContentType.ExtendedType().Codecs().IsEmpty()
+ || aContentType.ExtendedType().Codecs().AsString().EqualsASCII("mp3"));
}
return false;
}
} // namespace mozilla
--- a/dom/media/MP3Decoder.h
+++ b/dom/media/MP3Decoder.h
@@ -5,25 +5,27 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MP3Decoder_h_
#define MP3Decoder_h_
#include "MediaDecoder.h"
namespace mozilla {
-class MP3Decoder : public MediaDecoder {
+class MediaContentType;
+
+class MP3Decoder : public MediaDecoder
+{
public:
// MediaDecoder interface.
explicit MP3Decoder(MediaDecoderOwner* aOwner) : MediaDecoder(aOwner) {}
MediaDecoder* Clone(MediaDecoderOwner* aOwner) override;
MediaDecoderStateMachine* CreateStateMachine() override;
// Returns true if the MP3 backend is preffed on, and we're running on a
// platform that is likely to have decoders for the format.
static bool IsEnabled();
- static bool CanHandleMediaType(const nsACString& aType,
- const nsAString& aCodecs);
+ static bool IsSupportedType(const MediaContentType& aContentType);
};
} // namespace mozilla
#endif