Bug 1330284 - Use MediaContentType in OggDecoder - r=jya

MozReview-Commit-ID: 5sjoy8Gwm4K

--HG--
extra : rebase_source : 0ce9eda7933c1ed01646bff2f676a60647228406
This commit is contained in:
Gerald Squelart 2017-01-01 12:08:36 +11:00
Родитель 778e0a6594
Коммит f3436a269b
3 изменённых файлов: 33 добавлений и 50 удалений

Просмотреть файл

@ -62,19 +62,6 @@ CodecListContains(char const *const * aCodecs, const String& aCodec)
return false;
}
static bool
IsOggSupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
return OggDecoder::CanHandleMediaType(aType, aCodecs);
}
static bool
IsOggTypeAndEnabled(const nsACString& aType)
{
return IsOggSupportedType(aType);
}
static bool
IsWebMSupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
@ -203,9 +190,8 @@ CanHandleCodecsType(const MediaContentType& aType,
const MediaContentType mimeType(aType.Type());
char const* const* codecList = nullptr;
if (IsOggTypeAndEnabled(mimeType.Type().AsString())) {
if (IsOggSupportedType(aType.Type().AsString(),
aType.ExtendedType().Codecs().AsString())) {
if (OggDecoder::IsSupportedType(mimeType)) {
if (OggDecoder::IsSupportedType(aType)) {
return CANPLAY_YES;
} else {
// We can only reach this position if a particular codec was requested,
@ -314,7 +300,7 @@ CanHandleMediaType(const MediaContentType& aType,
// Content type with just the MIME type/subtype, no codecs.
const MediaContentType mimeType(aType.Type());
if (IsOggTypeAndEnabled(mimeType.Type().AsString())) {
if (OggDecoder::IsSupportedType(mimeType)) {
return CANPLAY_MAYBE;
}
if (IsWaveSupportedType(mimeType.Type().AsString())) {
@ -415,7 +401,7 @@ InstantiateDecoder(const MediaContentType& aType,
decoder = new ADTSDecoder(aOwner);
return decoder.forget();
}
if (IsOggSupportedType(aType.Type().AsString())) {
if (OggDecoder::IsSupportedType(aType)) {
decoder = new OggDecoder(aOwner);
return decoder.forget();
}
@ -481,6 +467,11 @@ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, Abstrac
if (!aDecoder) {
return decoderReader;
}
Maybe<MediaContentType> type = MakeMediaContentType(aType);
if (!type) {
return decoderReader;
}
#ifdef MOZ_FMP4
if (IsMP4SupportedType(aType, /* DecoderDoctorDiagnostics* */ nullptr)) {
decoderReader = new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource()));
@ -498,7 +489,7 @@ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, Abstrac
if (IsFlacSupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
} else
if (IsOggSupportedType(aType)) {
if (OggDecoder::IsSupportedType(*type)) {
decoderReader = new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()));
} else
#ifdef MOZ_ANDROID_OMX
@ -532,8 +523,13 @@ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
return false;
}
Maybe<MediaContentType> type = MakeMediaContentType(aType);
if (!type) {
return false;
}
return
IsOggSupportedType(aType) ||
OggDecoder::IsSupportedType(*type) ||
IsWebMSupportedType(aType) ||
#ifdef MOZ_ANDROID_OMX
(MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(aType)) ||

Просмотреть файл

@ -5,6 +5,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MediaPrefs.h"
#include "MediaContentType.h"
#include "MediaDecoderStateMachine.h"
#include "MediaFormatReader.h"
#include "OggDemuxer.h"
@ -25,41 +26,28 @@ MediaDecoderStateMachine* OggDecoder::CreateStateMachine()
/* static */
bool
OggDecoder::IsEnabled()
OggDecoder::IsSupportedType(const MediaContentType& aContentType)
{
return MediaPrefs::OggEnabled();
}
/* static */
bool
OggDecoder::CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
const nsAString& aCodecs)
{
if (!IsEnabled()) {
if (!MediaPrefs::OggEnabled()) {
return false;
}
const bool isOggAudio = aMIMETypeExcludingCodecs.EqualsASCII("audio/ogg");
const bool isOggVideo =
aMIMETypeExcludingCodecs.EqualsASCII("video/ogg") ||
aMIMETypeExcludingCodecs.EqualsASCII("application/ogg");
if (!isOggAudio && !isOggVideo) {
if (aContentType.Type() != MEDIAMIMETYPE("audio/ogg") &&
aContentType.Type() != MEDIAMIMETYPE("video/ogg") &&
aContentType.Type() != MEDIAMIMETYPE("application/ogg")) {
return false;
}
nsTArray<nsCString> codecMimes;
if (aCodecs.IsEmpty()) {
const bool isOggVideo = (aContentType.Type() != MEDIAMIMETYPE("audio/ogg"));
const MediaCodecs& codecs = aContentType.ExtendedType().Codecs();
if (codecs.IsEmpty()) {
// WebM guarantees that the only codecs it contained are vp8, vp9, opus or vorbis.
return true;
}
// Verify that all the codecs specified are ones that we expect that
// we can play.
nsTArray<nsString> codecs;
if (!ParseCodecsString(aCodecs, codecs)) {
return false;
}
for (const nsString& codec : codecs) {
for (const auto& codec : codecs.Range()) {
if ((IsOpusEnabled() && codec.EqualsLiteral("opus")) ||
codec.EqualsLiteral("vorbis") ||
(MediaPrefs::FlacInOgg() && codec.EqualsLiteral("flac"))) {

Просмотреть файл

@ -10,6 +10,8 @@
namespace mozilla {
class MediaContentType;
class OggDecoder : public MediaDecoder
{
public:
@ -37,13 +39,10 @@ public:
return mShutdownBit;
}
// Returns true if aMIMEType is a type that we think we can render with the
// a platform decoder backend. If aCodecs is non emtpy, it is filled
// with a comma-delimited list of codecs to check support for.
static bool CanHandleMediaType(const nsACString& aMIMETypeExcludingCodecs,
const nsAString& aCodecs);
static bool IsEnabled();
// Returns true if aContentType is an Ogg type that we think we can render
// with an enabled platform decoder backend.
// If provided, codecs are checked for support.
static bool IsSupportedType(const MediaContentType& aContentType);
protected:
void ShutdownBitChanged() override