Files
palemoon27/dom/media/DecoderTraits.cpp
T
roytam1 605fde2bb1 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1236120: [ffmpeg] Use demuxed dimensions to determine picture size and offset. r=gerald (f336c84d0d)
- Bug 851530: Part 1 - Added support for decoding uLaw and aLaw enconded wave files. r=jya (72683b69f2)
- Bug 851530: Part 2 - Added test cases for uLaw and aLaw wave files. r=jya (ddf431bd28)
- Bug 524109 - Added support for 24 bit wav files. r=cpearce (ebfac16a20)
- Bug 864780 - Changed handling of the format chunk to skip any extension. r=cpearce (40903839a8)
- Bug 1229742: P1. Only clear EOS flag if we have new data. r=gerald (83e69375e4)
- Bug 1229742: P2. Don't reject data promise if new data is pending. r=gerald (89d8222809)
- Bug 1237809: P2. Detect change of display size. r=cpearce (ec529e2732)
- Bug 1237809: [h264] P1. Ensure correct video dimensions are passed to the decoder. r=cpearce (eb241cad10)
- Bug 1237809: P3. Ensure element dimensions are up to date. r=jwwang (541e6e74d7)
- Bug 1244639: P1. Don't assume MP3 decoding always starts at 0. r=cpearce (b62c27bd04)
- Bug 1244639: P2. Don't clamp audio time to seek time if there's no video track. r=cpearce (4720bacc24)
- Bug 1205927 - Part 1: [MediaEncoder] Support *.3g2 with EVRC audio format. r=ayang (bbd8aff9d9)
- Bug 1205927 - Part 2: Add audio-capture:3gpp2 perimission for certificated and privileged application. r=ayang (63b337e2ab)
- Bug 1198157 - Call |NotifyEndOfStream| if the encoder can't been initialized after 30 seconds. r=jwwang (2c21203d36)
- minor NL (14d757753b)
- Bug 1182426 - Add some asserts to VP8TrackEncoder for sanity. r=roc (79ff4869ca)
- Bug 1154213 - Handle timestamps of video/webm vorbis track encoding. r=mreavy, r=rjesup (a9897e4873)
- Bug 1137151: Marked destructor of |MuxerOperation| as protected, r=sotaro (94fdcf6457)
- Bug 1210232 - Let MP4Decoder handle 3GPP files on B2G. r=cpearce (95a77023ad)
- Bug 1227790 - Update GMP API to include new MediaKeyStatus types. r=jwwang (1a6933f2df)
- bits of Bug 1186375 - Add GMP EME (6b99660146)
- Bug 1221825: Fix logging arguments. r=cpearce (5261e34713)
- Bug 1244442 - Warn about Proxy.create and Proxy.createFunction. r=Waldo (718aa94f5b)
- fix spaces (720e2114f7)
- re-apply Bug 1231224 part 7 - Fix some more places to handle OOM. r=jonco (a4af46894b)
- Bug 1246122 - Don't crash in InvokeInterruptCallback if there are no JS scripts on the stack. r=shu (9702df89bc)
- Bug 1246607: Recover from OOM in AddClearDefiniteGetterSetterForPrototypeChain; r=jandem (d83c6c6c9b)
- Bug 1236546 - Don't deoptimize in ObjectGroup::defaultNewGroup when we have a null proto. r=bhackett (1c2ecc3d09)
- Bug 1249588 - Remove unnecessary type information from RegExpObject. r=jandem (9126e17d94)
- Bug 1245965 - Fix an OOM in ObjectGroup::newPlainObject; r=till (5192c25b53)
- Bug 1240527: Fix tracing of RegExpStaticsObject; r=nbp (b37f2167a5)
- Bug 1248094 - Followup to fix a typo; r=fitzgen (8afec429d9)
- Bug 1248726 - Simplify PCLocationMap even further; r=fitzgen (39f0b54a04)
- Bug 1241311 - Pre-tenure SavedFrame objects. r=terrence (b703f3d78e)
- Bug 1241249 - Add an SPS pseudo entry for JS stack capturing; r=shu (c2ae4ee5c2)
- Bug 1247299 - Force SavedFrame columns to be 0 in JS_MORE_DETERMINISTIC builds; r=sfink (09b9038448)
- Bug 1241701 - Add about:memory reporting for js::SavedStacks::pcLocationMap. r=njn (b663d911fc)
- Bug 1166234 - Throw on accessing optimized out values when using Debugger.Frame.prototype.eval. (r=jimb) (19b43b137b)
- Bug 1232655 - Fix DebugScopeProxy::has to not lookup .this on non-function scopes. r=shu (3959e98752)
- Bug 1216261 - Fix OOM handling of DebugScopes. (r=jonco) (0f8b856ee6)
- reorder after mispatch (c292050275)
- Bug 1235656 - Followup: Allow extended functions with guessed atoms in self-hosted code. (rs=arai) (a67286cd52)
- Bug 1245048: Check call to GetPrototype; r=till (35dbbdc025)
- Bug 1132630 - Renumber steps in Function.prototype.bind. r=till (9f11a5a086)
- Bug 1246131 - Provide 'dbg(msg)' debug printing utility function for self-hosted code. r=jandem (f436eeb481)
- Bug 1246131 - Part 2: Let opt builds compile again, even on a CLOSED TREE. r=bustage (8483b77541)
- Bug 1247934 - Handle receiving unboxed exports array from self hosted module code r=shu (fb9c296909)
- Bug 1246134 - Fix loading of external self-hosted JS using MOZ_SELFHOSTEDJS. r=efaust (c96059b40a)
- Bug 1220502 - ignore not visible text nodes for tree update, r=tbsaunde, roc (eed078abc6)
- Bug 1242989 - keep content insertions in a hash, r=tbsaunde (d58fc948a6)
- bug 1228400 - null check tabChild before notifying the parent process about new child documents r=davidb (09512e6287)
- Bug 1239051 - Labels should expose labeled controllers action. r=tbsaunde (c0d4d801a9)
- bug 1243077 - make xpcAccessible::GetFirstChild() work with proxies r=davidb (f539fafe93)
- bug 1243077 - make xpcAccessible::GetLastChild() work with proxied accessibles r=davidb (13716f7cc0)
- bug 1243077 - implement xpcAccessible::GetChildCount() for proxied accessibles (b8f4598834)
- bug 1243077 - make xpcAccessible::GetChildAt() work with proxied accessibles r=davidb (cce0924f7b)
- bug 1243077 - make xpcAccessible::GetChildren() work with proxied accessibles r=davidb (a9ec2b1588)
- bug 1243077 - remove an unnecessary AddRef() from xpcAccessible::GetChildren() (89a58ac2e0)
- bug 1243077 - support proxied accessibles in xpcAccessible::GetRole() r=davidb (2d2a2926c7)
- Bug 1246768 - part 1: argument conversion for Atomics.isLockFree in runtime. r=bbouvier (17f3498b84)
- Bug 1246750 - fix argument ordering to futexWakeOrRequeue + test cases. r=bbouvier (31825e7096)
- Bug 1238911 - initialize canWait with false from constructor, avoid using the variable without initialization. r=lhansen (f4657b3950)
- Bug 1235373 - Add an assert to check validity of pointers: mElement->GetPrimaryFrame() and frame. r=surkov (18023f9238)
- Bug 1241534 - Use TraceRoot for InterpreterFrame fields. r=terrence (98996dc497)
- Bug 1246112 - Fix a bogus assert in InterpreterFrame::initExecuteFrame. r=su (2093ba8a44)
- Bug 1243241 - Make RDTSC monotonic. r=jandem (1450a97a94)
- Bug 1243242 - Don't make structured cloning O(n**2) in the size of the transferables array. r=sfink (aa38dee282)
2023-12-04 22:00:13 +08:00

711 lines
17 KiB
C++

/* -*- 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"
#include "nsCharSeparatedTokenizer.h"
#include "nsMimeTypes.h"
#include "mozilla/Preferences.h"
#include "OggDecoder.h"
#include "OggReader.h"
#include "WebMDecoder.h"
#include "WebMDemuxer.h"
#ifdef MOZ_RAW
#include "RawDecoder.h"
#include "RawReader.h"
#endif
#include "ADTSDecoder.h"
#include "ADTSDemuxer.h"
#ifdef MOZ_ANDROID_OMX
#include "AndroidMediaDecoder.h"
#include "AndroidMediaReader.h"
#include "AndroidMediaPluginHost.h"
#endif
#ifdef MOZ_OMX_DECODER
#include "MediaOmxDecoder.h"
#include "MediaOmxReader.h"
#include "nsIPrincipal.h"
#include "mozilla/dom/HTMLMediaElement.h"
#endif
#ifdef NECKO_PROTOCOL_rtsp
#include "RtspOmxDecoder.h"
#include "RtspOmxReader.h"
#endif
#ifdef MOZ_DIRECTSHOW
#include "DirectShowDecoder.h"
#include "DirectShowReader.h"
#endif
#ifdef MOZ_FMP4
#include "MP4Decoder.h"
#include "MP4Demuxer.h"
#endif
#include "MediaFormatReader.h"
#include "MP3Decoder.h"
#include "MP3Demuxer.h"
#include "WaveDecoder.h"
#include "WaveDemuxer.h"
#include "WaveReader.h"
#include "ADTSDecoder.h"
#include "ADTSDemuxer.h"
namespace mozilla
{
template <class String>
static bool
CodecListContains(char const *const * aCodecs, const String& aCodec)
{
for (int32_t i = 0; aCodecs[i]; ++i) {
if (aCodec.EqualsASCII(aCodecs[i]))
return true;
}
return false;
}
#ifdef MOZ_RAW
static const char* gRawTypes[3] = {
"video/x-raw",
"video/x-raw-yuv",
nullptr
};
static const char* gRawCodecs[1] = {
nullptr
};
static bool
IsRawType(const nsACString& aType)
{
if (!MediaDecoder::IsRawEnabled()) {
return false;
}
return CodecListContains(gRawTypes, aType);
}
#endif
// See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
// of Ogg media types and codec types
static const char* const gOggTypes[4] = {
"video/ogg",
"audio/ogg",
"application/ogg",
nullptr
};
static char const *const gOggCodecs[3] = {
"vorbis",
"theora",
nullptr
};
static char const *const gOggCodecsWithOpus[4] = {
"vorbis",
"opus",
"theora",
nullptr
};
static bool
IsOggType(const nsACString& aType)
{
if (!MediaDecoder::IsOggEnabled()) {
return false;
}
return CodecListContains(gOggTypes, aType);
}
// 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.
static const char* const gWaveTypes[5] = {
"audio/x-wav",
"audio/wav",
"audio/wave",
"audio/x-pn-wav",
nullptr
};
static char const *const gWaveCodecs[4] = {
"1", // Microsoft PCM Format
"6", // aLaw Encoding
"7", // uLaw Encoding
nullptr
};
static bool
IsWaveType(const nsACString& aType)
{
if (!MediaDecoder::IsWaveEnabled()) {
return false;
}
return CodecListContains(gWaveTypes, aType);
}
static bool
IsWebMSupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
return WebMDecoder::CanHandleMediaType(aType, aCodecs);
}
/* static */ bool
DecoderTraits::IsWebMTypeAndEnabled(const nsACString& aType)
{
return IsWebMSupportedType(aType);
}
/* static */ bool
DecoderTraits::IsWebMAudioType(const nsACString& aType)
{
return aType.EqualsASCII("audio/webm");
}
#ifdef MOZ_OMX_DECODER
static const char* const gOmxTypes[] = {
"audio/mpeg",
"audio/mp4",
"audio/amr",
"audio/3gpp",
"audio/flac",
"video/mp4",
"video/x-m4v",
"video/3gpp",
"video/3gpp2",
"video/quicktime",
#ifdef MOZ_OMX_WEBM_DECODER
"video/webm",
"audio/webm",
#endif
"audio/x-matroska",
"video/mp2t",
"video/avi",
"video/x-matroska",
nullptr
};
static const char* const gB2GOnlyTypes[] = {
"audio/3gpp",
"audio/amr",
"audio/x-matroska",
"video/mp2t",
"video/avi",
"video/x-matroska",
nullptr
};
static bool
IsOmxSupportedType(const nsACString& aType)
{
if (!MediaDecoder::IsOmxEnabled()) {
return false;
}
return CodecListContains(gOmxTypes, aType);
}
static bool
IsB2GSupportOnlyType(const nsACString& aType)
{
return CodecListContains(gB2GOnlyTypes, aType);
}
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
};
static char const *const gMpegAudioCodecs[2] = {
"mp3", // MP3
nullptr
};
#ifdef MOZ_OMX_WEBM_DECODER
static char const *const gOMXWebMCodecs[] = {
"vorbis",
"vp8",
"vp8.0",
// Since Android KK, VP9 SW decoder is supported.
// http://developer.android.com/guide/appendix/media-formats.html
#if ANDROID_VERSION > 18
"vp9",
"vp9.0",
#endif
nullptr
};
#endif //MOZ_OMX_WEBM_DECODER
#endif
#ifdef NECKO_PROTOCOL_rtsp
static const char* const gRtspTypes[2] = {
"RTSP",
nullptr
};
static bool
IsRtspSupportedType(const nsACString& aMimeType)
{
return MediaDecoder::IsRtspEnabled() &&
CodecListContains(gRtspTypes, aMimeType);
}
#endif
/* static */
bool DecoderTraits::DecoderWaitsForOnConnected(const nsACString& aMimeType) {
#ifdef NECKO_PROTOCOL_rtsp
return CodecListContains(gRtspTypes, aMimeType);
#else
return false;
#endif
}
#ifdef MOZ_ANDROID_OMX
static bool
IsAndroidMediaType(const nsACString& aType)
{
if (!MediaDecoder::IsAndroidMediaEnabled()) {
return false;
}
static const char* supportedTypes[] = {
"audio/mpeg", "audio/mp4", "video/mp4", "video/x-m4v", nullptr
};
return CodecListContains(supportedTypes, aType);
}
#endif
#ifdef MOZ_DIRECTSHOW
static bool
IsDirectShowSupportedType(const nsACString& aType)
{
return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
}
#endif
#ifdef MOZ_FMP4
static bool
IsMP4SupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
return MP4Decoder::CanHandleMediaType(aType, aCodecs);
}
#endif
/* static */ bool
DecoderTraits::IsMP4TypeAndEnabled(const nsACString& aType)
{
#ifdef MOZ_FMP4
return IsMP4SupportedType(aType);
#endif
return false;
}
static bool
IsMP3SupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
#ifdef MOZ_OMX_DECODER
return false;
#endif
return MP3Decoder::CanHandleMediaType(aType, aCodecs);
}
static bool
IsAACSupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
return ADTSDecoder::CanHandleMediaType(aType, aCodecs);
}
static bool
IsWAVSupportedType(const nsACString& aType,
const nsAString& aCodecs = EmptyString())
{
return WaveDecoder::CanHandleMediaType(aType, aCodecs);
}
/* static */
bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType)
{
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;
}
return CanHandleMediaType(aMIMEType, false, EmptyString()) != CANPLAY_NO;
}
/* static */
CanPlayStatus
DecoderTraits::CanHandleCodecsType(const char* aMIMEType,
const nsAString& aRequestedCodecs)
{
char const* const* codecList = nullptr;
#ifdef MOZ_RAW
if (IsRawType(nsDependentCString(aMIMEType))) {
codecList = gRawCodecs;
}
#endif
if (IsOggType(nsDependentCString(aMIMEType))) {
codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
}
if (IsWaveType(nsDependentCString(aMIMEType))) {
codecList = gWaveCodecs;
}
#if !defined(MOZ_OMX_WEBM_DECODER)
if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) {
if (IsWebMSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
return CANPLAY_YES;
} else {
// 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 (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType))) {
if (IsMP4SupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
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(nsDependentCString(aMIMEType), aRequestedCodecs)) {
return CANPLAY_YES;
}
if (IsAACSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
return CANPLAY_YES;
}
#ifdef MOZ_OMX_DECODER
if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
codecList = gMpegAudioCodecs;
#ifdef MOZ_OMX_WEBM_DECODER
} else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") ||
nsDependentCString(aMIMEType).EqualsASCII("video/webm")) {
codecList = gOMXWebMCodecs;
#endif
} else {
codecList = gH264Codecs;
}
}
#endif
#ifdef MOZ_DIRECTSHOW
DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList);
#endif
#ifdef MOZ_ANDROID_OMX
if (MediaDecoder::IsAndroidMediaEnabled()) {
EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList);
}
#endif
if (!codecList) {
return CANPLAY_MAYBE;
}
// 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.separatorAfterCurrentToken();
}
if (expectMoreTokens) {
// Last codec name was empty
return CANPLAY_NO;
}
return CANPLAY_YES;
}
/* static */
CanPlayStatus
DecoderTraits::CanHandleMediaType(const char* aMIMEType,
bool aHaveRequestedCodecs,
const nsAString& aRequestedCodecs)
{
MOZ_ASSERT(NS_IsMainThread());
if (aHaveRequestedCodecs) {
CanPlayStatus result = CanHandleCodecsType(aMIMEType, aRequestedCodecs);
if (result == CANPLAY_NO || result == CANPLAY_YES) {
return result;
}
}
#ifdef MOZ_RAW
if (IsRawType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
#endif
if (IsOggType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
if (IsWaveType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
if (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
#if !defined(MOZ_OMX_WEBM_DECODER)
if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
#endif
if (IsMP3SupportedType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
if (IsAACSupportedType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
#ifdef MOZ_OMX_DECODER
if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
#endif
#ifdef MOZ_DIRECTSHOW
if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), nullptr)) {
return CANPLAY_MAYBE;
}
#endif
#ifdef MOZ_ANDROID_OMX
if (MediaDecoder::IsAndroidMediaEnabled() &&
EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), nullptr)) {
return CANPLAY_MAYBE;
}
#endif
#ifdef NECKO_PROTOCOL_rtsp
if (IsRtspSupportedType(nsDependentCString(aMIMEType))) {
return CANPLAY_MAYBE;
}
#endif
return CANPLAY_NO;
}
// Instantiates but does not initialize decoder.
static
already_AddRefed<MediaDecoder>
InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
{
MOZ_ASSERT(NS_IsMainThread());
RefPtr<MediaDecoder> decoder;
#ifdef MOZ_FMP4
if (IsMP4SupportedType(aType)) {
decoder = new MP4Decoder(aOwner);
return decoder.forget();
}
#endif
if (IsMP3SupportedType(aType)) {
decoder = new MP3Decoder(aOwner);
return decoder.forget();
}
if (IsAACSupportedType(aType)) {
decoder = new ADTSDecoder(aOwner);
return decoder.forget();
}
#ifdef MOZ_RAW
if (IsRawType(aType)) {
decoder = new RawDecoder(aOwner);
return decoder.forget();
}
#endif
if (IsOggType(aType)) {
decoder = new OggDecoder(aOwner);
return decoder.forget();
}
if (IsWaveType(aType)) {
decoder = new WaveDecoder(aOwner);
return decoder.forget();
}
#ifdef MOZ_OMX_DECODER
if (IsOmxSupportedType(aType)) {
// we are discouraging Web and App developers from using those formats in
// gB2GOnlyTypes, thus we only allow them to be played on WebApps.
if (IsB2GSupportOnlyType(aType)) {
dom::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;
}
}
decoder = new MediaOmxDecoder(aOwner);
return decoder.forget();
}
#endif
#ifdef NECKO_PROTOCOL_rtsp
if (IsRtspSupportedType(aType)) {
decoder = new RtspOmxDecoder(aOwner);
return decoder.forget();
}
#endif
#ifdef MOZ_ANDROID_OMX
if (MediaDecoder::IsAndroidMediaEnabled() &&
EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
decoder = new AndroidMediaDecoder(aOwner, aType);
return decoder.forget();
}
#endif
if (IsWebMSupportedType(aType)) {
decoder = new WebMDecoder(aOwner);
return decoder.forget();
}
#ifdef MOZ_DIRECTSHOW
// Note: DirectShow should come before WMF, so that we prefer DirectShow's
// MP3 support over WMF's.
if (IsDirectShowSupportedType(aType)) {
decoder = new DirectShowDecoder(aOwner);
return decoder.forget();
}
#endif
return nullptr;
}
/* static */
already_AddRefed<MediaDecoder>
DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
{
MOZ_ASSERT(NS_IsMainThread());
return InstantiateDecoder(aType, aOwner);
}
/* static */
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
{
MOZ_ASSERT(NS_IsMainThread());
MediaDecoderReader* decoderReader = nullptr;
if (!aDecoder) {
return decoderReader;
}
#ifdef MOZ_FMP4
if (IsMP4SupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource()));
} else
#endif
if (IsMP3SupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
} else
if (IsAACSupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
} else
if (IsWAVSupportedType(aType)) {
decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
} else
#ifdef MOZ_RAW
if (IsRawType(aType)) {
decoderReader = new RawReader(aDecoder);
} else
#endif
if (IsOggType(aType)) {
decoderReader = new OggReader(aDecoder);
} else
if (IsWaveType(aType)) {
decoderReader = new WaveReader(aDecoder);
} else
#ifdef MOZ_OMX_DECODER
if (IsOmxSupportedType(aType)) {
decoderReader = new MediaOmxReader(aDecoder);
} else
#endif
#ifdef MOZ_ANDROID_OMX
if (MediaDecoder::IsAndroidMediaEnabled() &&
EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
decoderReader = new AndroidMediaReader(aDecoder, aType);
} else
#endif
if (IsWebMSupportedType(aType)) {
decoderReader =
new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource()));
} else
#ifdef MOZ_DIRECTSHOW
if (IsDirectShowSupportedType(aType)) {
decoderReader = new DirectShowReader(aDecoder);
} else
#endif
if (false) {} // dummy if to take care of the dangling else
return decoderReader;
}
/* static */
bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
{
// Forbid playing media in video documents if the user has opted
// not to, using either the legacy WMF specific pref, or the newer
// catch-all pref.
if (!Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true) ||
!Preferences::GetBool("media.play-stand-alone", true)) {
return false;
}
return
IsOggType(aType) ||
#ifdef MOZ_OMX_DECODER
// We support the formats in gB2GOnlyTypes only inside WebApps on firefoxOS
// but not in general web content. Ensure we dont create a VideoDocument
// when accessing those format URLs directly.
(IsOmxSupportedType(aType) &&
!IsB2GSupportOnlyType(aType)) ||
#endif
IsWebMSupportedType(aType) ||
#ifdef MOZ_ANDROID_OMX
(MediaDecoder::IsAndroidMediaEnabled() && IsAndroidMediaType(aType)) ||
#endif
#ifdef MOZ_FMP4
IsMP4SupportedType(aType) ||
#endif
IsMP3SupportedType(aType) ||
IsAACSupportedType(aType) ||
#ifdef MOZ_DIRECTSHOW
IsDirectShowSupportedType(aType) ||
#endif
#ifdef NECKO_PROTOCOL_rtsp
IsRtspSupportedType(aType) ||
#endif
false;
}
} // namespace mozilla