2012-11-21 19:10:41 -08:00
|
|
|
/* -*- 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 "MediaDecoder.h"
|
2012-11-22 10:49:37 -08:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
|
2012-11-21 19:10:41 -08:00
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
#include "MediaPluginHost.h"
|
|
|
|
#endif
|
2013-03-04 07:24:44 -08:00
|
|
|
|
2013-03-05 06:56:34 -08:00
|
|
|
#ifdef MOZ_OGG
|
|
|
|
#include "OggDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "OggReader.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
#include "WaveDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "WaveReader.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
#include "WebMDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "WebMReader.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_RAW
|
|
|
|
#include "RawDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "RawReader.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GSTREAMER
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#include "GStreamerDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "GStreamerReader.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
#include "MediaPluginHost.h"
|
|
|
|
#include "MediaPluginDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "MediaPluginReader.h"
|
|
|
|
#include "MediaPluginHost.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include "MediaOmxDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "MediaOmxReader.h"
|
2013-03-21 19:56:22 -07:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_DASH
|
|
|
|
#include "DASHDecoder.h"
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WMF
|
|
|
|
#include "WMFDecoder.h"
|
2013-03-05 06:56:35 -08:00
|
|
|
#include "WMFReader.h"
|
2013-03-05 06:56:34 -08:00
|
|
|
#endif
|
|
|
|
|
2012-11-21 19:10:41 -08:00
|
|
|
namespace mozilla
|
|
|
|
{
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
template <class String>
|
2012-11-22 10:49:37 -08:00
|
|
|
static bool
|
2012-11-22 11:08:57 -08:00
|
|
|
CodecListContains(char const *const * aCodecs, const String& aCodec)
|
2012-11-22 10:49:37 -08:00
|
|
|
{
|
|
|
|
for (int32_t i = 0; aCodecs[i]; ++i) {
|
|
|
|
if (aCodec.EqualsASCII(aCodecs[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-21 19:10:41 -08:00
|
|
|
#ifdef MOZ_RAW
|
2012-11-22 11:08:57 -08:00
|
|
|
static const char* gRawTypes[3] = {
|
2012-11-21 19:10:41 -08:00
|
|
|
"video/x-raw",
|
2012-11-22 11:08:57 -08:00
|
|
|
"video/x-raw-yuv",
|
|
|
|
nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char* gRawCodecs[1] = {
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsRawType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsRawEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(gRawTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_OGG
|
|
|
|
// See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
|
|
|
|
// of Ogg media types and codec types
|
2012-11-22 11:08:57 -08:00
|
|
|
static const char* const gOggTypes[4] = {
|
2012-11-21 19:10:41 -08:00
|
|
|
"video/ogg",
|
|
|
|
"audio/ogg",
|
2012-11-22 11:08:57 -08:00
|
|
|
"application/ogg",
|
|
|
|
nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gOggCodecs[3] = {
|
|
|
|
"vorbis",
|
|
|
|
"theora",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gOggCodecsWithOpus[4] = {
|
|
|
|
"vorbis",
|
|
|
|
"opus",
|
|
|
|
"theora",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsOggType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsOggEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(gOggTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
// See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
|
|
|
|
// of WAVE media types and codec types. However, the audio/vnd.wave
|
|
|
|
// MIME type described there is not used.
|
2012-11-22 11:08:57 -08:00
|
|
|
static const char* const gWaveTypes[5] = {
|
2012-11-21 19:10:41 -08:00
|
|
|
"audio/x-wav",
|
|
|
|
"audio/wav",
|
|
|
|
"audio/wave",
|
2012-11-22 11:08:57 -08:00
|
|
|
"audio/x-pn-wav",
|
|
|
|
nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gWaveCodecs[2] = {
|
|
|
|
"1", // Microsoft PCM Format
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsWaveType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsWaveEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(gWaveTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WEBM
|
2012-11-22 11:08:57 -08:00
|
|
|
static const char* const gWebMTypes[3] = {
|
2012-11-21 19:10:41 -08:00
|
|
|
"video/webm",
|
2012-11-22 11:08:57 -08:00
|
|
|
"audio/webm",
|
|
|
|
nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gWebMCodecs[4] = {
|
|
|
|
"vp8",
|
|
|
|
"vp8.0",
|
|
|
|
"vorbis",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsWebMType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsWebMEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(gWebMTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_GSTREAMER
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsGStreamerSupportedType(const nsACString& aMimeType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsGStreamerEnabled())
|
|
|
|
return false;
|
2013-03-13 13:10:47 -07:00
|
|
|
|
2012-11-21 19:10:41 -08:00
|
|
|
#ifdef MOZ_WEBM
|
2013-03-13 13:10:47 -07:00
|
|
|
if (IsWebMType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
|
|
|
|
return false;
|
2012-11-21 19:10:41 -08:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_OGG
|
2013-03-13 13:10:47 -07:00
|
|
|
if (IsOggType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
|
|
|
|
return false;
|
2012-11-21 19:10:41 -08:00
|
|
|
#endif
|
2013-03-13 13:10:47 -07:00
|
|
|
|
|
|
|
return GStreamerDecoder::CanHandleMediaType(aMimeType, nullptr);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
2013-03-21 19:56:22 -07:00
|
|
|
static const char* const gOmxTypes[7] = {
|
2012-11-21 19:10:41 -08:00
|
|
|
"audio/mpeg",
|
|
|
|
"audio/mp4",
|
2013-03-21 19:56:22 -07:00
|
|
|
"audio/amr",
|
2012-11-21 19:10:41 -08:00
|
|
|
"video/mp4",
|
|
|
|
"video/3gpp",
|
|
|
|
"video/quicktime",
|
2012-11-22 11:08:57 -08:00
|
|
|
nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsOmxSupportedType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsOmxEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(gOmxTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static char const *const gH264Codecs[9] = {
|
|
|
|
"avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0
|
|
|
|
"avc1.42001E", // H.264 Baseline Profile Level 3.0
|
|
|
|
"avc1.58A01E", // H.264 Extended Profile Level 3.0
|
|
|
|
"avc1.4D401E", // H.264 Main Profile Level 3.0
|
|
|
|
"avc1.64001E", // H.264 High Profile Level 3.0
|
|
|
|
"avc1.64001F", // H.264 High Profile Level 3.1
|
|
|
|
"mp4v.20.3", // 3GPP
|
|
|
|
"mp4a.40.2", // AAC-LC
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsMediaPluginsType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsMediaPluginsEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* supportedTypes[] = {
|
2012-11-22 11:08:57 -08:00
|
|
|
"audio/mpeg", "audio/mp4", "video/mp4", nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(supportedTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_DASH
|
|
|
|
/* static */
|
2012-11-22 11:08:57 -08:00
|
|
|
static const char* const gDASHMPDTypes[2] = {
|
|
|
|
"application/dash+xml",
|
|
|
|
nullptr
|
2012-11-21 19:10:41 -08:00
|
|
|
};
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsDASHMPDType(const nsACString& aType)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsDASHEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 11:08:57 -08:00
|
|
|
return CodecListContains(gDASHMPDTypes, aType);
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-18 00:49:58 -08:00
|
|
|
#ifdef MOZ_WMF
|
2013-03-05 06:56:35 -08:00
|
|
|
static bool
|
|
|
|
IsWMFSupportedType(const nsACString& aType)
|
2012-12-18 00:49:58 -08:00
|
|
|
{
|
|
|
|
return WMFDecoder::GetSupportedCodecs(aType, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-21 19:10:41 -08:00
|
|
|
/* static */
|
|
|
|
bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType)
|
|
|
|
{
|
2012-11-22 12:15:47 -08:00
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(nsDependentCString(aMIMEType))) {
|
|
|
|
// We should not return true for Wave types, since there are some
|
|
|
|
// Wave codecs actually in use in the wild that we don't support, and
|
|
|
|
// we should allow those to be handled by plugins or helper apps.
|
|
|
|
// Furthermore people can play Wave files on most platforms by other
|
|
|
|
// means.
|
|
|
|
return false;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
2012-11-22 12:15:47 -08:00
|
|
|
return CanHandleMediaType(aMIMEType, false, EmptyString()) != CANPLAY_NO;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
CanPlayStatus
|
|
|
|
DecoderTraits::CanHandleMediaType(const char* aMIMEType,
|
2012-11-22 10:49:37 -08:00
|
|
|
bool aHaveRequestedCodecs,
|
|
|
|
const nsAString& aRequestedCodecs)
|
2012-11-21 19:10:41 -08:00
|
|
|
{
|
2012-11-22 10:49:37 -08:00
|
|
|
char const* const* codecList = nullptr;
|
|
|
|
CanPlayStatus result = CANPLAY_NO;
|
2012-11-21 19:10:41 -08:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(nsDependentCString(aMIMEType))) {
|
2012-11-22 10:49:37 -08:00
|
|
|
codecList = gRawCodecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_OGG
|
|
|
|
if (IsOggType(nsDependentCString(aMIMEType))) {
|
2012-11-22 10:49:37 -08:00
|
|
|
codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(nsDependentCString(aMIMEType))) {
|
2012-11-22 10:49:37 -08:00
|
|
|
codecList = gWaveCodecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(nsDependentCString(aMIMEType))) {
|
2012-11-22 10:49:37 -08:00
|
|
|
codecList = gWebMCodecs;
|
|
|
|
result = CANPLAY_YES;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_DASH
|
|
|
|
if (IsDASHMPDType(nsDependentCString(aMIMEType))) {
|
|
|
|
// DASH manifest uses WebM codecs only.
|
2012-11-22 10:49:37 -08:00
|
|
|
codecList = gWebMCodecs;
|
|
|
|
result = CANPLAY_YES;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GSTREAMER
|
2013-03-13 13:10:47 -07:00
|
|
|
if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType),
|
|
|
|
aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) {
|
|
|
|
if (aHaveRequestedCodecs)
|
|
|
|
return CANPLAY_YES;
|
|
|
|
return CANPLAY_MAYBE;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
|
2012-11-22 10:49:37 -08:00
|
|
|
codecList = gH264Codecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
#endif
|
2012-12-18 00:49:58 -08:00
|
|
|
#ifdef MOZ_WMF
|
|
|
|
if (WMFDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
|
|
|
|
result = CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-21 19:10:41 -08:00
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
2012-11-22 10:49:37 -08:00
|
|
|
if (MediaDecoder::IsMediaPluginsEnabled() &&
|
|
|
|
GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList))
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-21 19:10:41 -08:00
|
|
|
#endif
|
2013-03-13 13:10:47 -07:00
|
|
|
if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) {
|
2012-11-22 10:49:37 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
|
|
|
|
// of the 'codecs' parameter
|
|
|
|
nsCharSeparatedTokenizer tokenizer(aRequestedCodecs, ',');
|
|
|
|
bool expectMoreTokens = false;
|
|
|
|
while (tokenizer.hasMoreTokens()) {
|
|
|
|
const nsSubstring& token = tokenizer.nextToken();
|
|
|
|
|
|
|
|
if (!CodecListContains(codecList, token)) {
|
|
|
|
// Totally unsupported codec
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
expectMoreTokens = tokenizer.lastTokenEndedWithSeparator();
|
|
|
|
}
|
|
|
|
if (expectMoreTokens) {
|
|
|
|
// Last codec name was empty
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
return CANPLAY_YES;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
|
2013-03-05 06:56:34 -08:00
|
|
|
/* static */
|
|
|
|
already_AddRefed<MediaDecoder>
|
|
|
|
DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
|
|
|
|
{
|
|
|
|
nsRefPtr<MediaDecoder> decoder;
|
|
|
|
|
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
if (IsGStreamerSupportedType(aType)) {
|
|
|
|
decoder = new GStreamerDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(aType)) {
|
|
|
|
decoder = new RawDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_OGG
|
|
|
|
if (IsOggType(aType)) {
|
|
|
|
decoder = new OggDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(aType)) {
|
|
|
|
decoder = new WaveDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (IsOmxSupportedType(aType)) {
|
2013-03-21 19:56:22 -07:00
|
|
|
// AMR audio is enabled for MMS, but we are discouraging Web and App
|
|
|
|
// developers from using AMR, thus we only allow AMR to be played on WebApps.
|
|
|
|
if (aType.EqualsASCII("audio/amr") || aType.EqualsASCII("video/3gpp")) {
|
|
|
|
HTMLMediaElement* element = aOwner->GetMediaElement();
|
|
|
|
if (!element) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIPrincipal* principal = element->NodePrincipal();
|
|
|
|
if (!principal) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 06:56:34 -08:00
|
|
|
decoder = new MediaOmxDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) {
|
|
|
|
decoder = new MediaPluginDecoder(aType);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(aType)) {
|
|
|
|
decoder = new WebMDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_DASH
|
|
|
|
if (IsDASHMPDType(aType)) {
|
|
|
|
decoder = new DASHDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WMF
|
|
|
|
if (IsWMFSupportedType(aType)) {
|
|
|
|
decoder = new WMFDecoder();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(decoder != nullptr, nullptr);
|
|
|
|
NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
|
|
|
|
|
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
/* static */
|
|
|
|
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
|
|
|
|
{
|
|
|
|
MediaDecoderReader* decoderReader = nullptr;
|
|
|
|
|
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
if (IsGStreamerSupportedType(aType)) {
|
|
|
|
decoderReader = new GStreamerReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(aType)) {
|
|
|
|
decoderReader = new RawReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_OGG
|
|
|
|
if (IsOggType(aType)) {
|
|
|
|
decoderReader = new OggReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(aType)) {
|
|
|
|
decoderReader = new WaveReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
if (IsOmxSupportedType(aType)) {
|
|
|
|
decoderReader = new MediaOmxReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
if (MediaDecoder::IsMediaPluginsEnabled() &&
|
|
|
|
GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
|
|
|
|
decoderReader = new MediaPluginReader(aDecoder, aType);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(aType)) {
|
|
|
|
decoderReader = new WebMReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WMF
|
|
|
|
if (IsWMFSupportedType(aType)) {
|
|
|
|
decoderReader = new WMFReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_DASH
|
|
|
|
// The DASH decoder is not supported.
|
|
|
|
#endif
|
|
|
|
if (false) {} // dummy if to take care of the dangling else
|
|
|
|
|
|
|
|
return decoderReader;
|
|
|
|
}
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
/* static */
|
|
|
|
bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
#ifdef MOZ_OGG
|
|
|
|
IsOggType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
IsOmxSupportedType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
IsWebMType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_DASH
|
|
|
|
IsDASHMPDType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
IsGStreamerSupportedType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
(MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WMF
|
|
|
|
IsWMFSupportedType(aType) ||
|
|
|
|
#endif
|
|
|
|
false;
|
2012-11-21 19:10:41 -08:00
|
|
|
}
|
|
|
|
|
2013-03-05 06:56:35 -08:00
|
|
|
}
|