2012-11-22 03:10:41 +00: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 18:49:37 +00:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2013-06-20 23:16:55 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
#include "MediaPluginHost.h"
|
|
|
|
#endif
|
2013-03-04 15:24:44 +00:00
|
|
|
|
2013-03-05 14:56:34 +00:00
|
|
|
#include "OggDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "OggReader.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
#include "WaveDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "WaveReader.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
#include "WebMDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "WebMReader.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_RAW
|
|
|
|
#include "RawDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "RawReader.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
#include "GStreamerDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "GStreamerReader.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
#include "MediaPluginHost.h"
|
|
|
|
#include "MediaPluginDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "MediaPluginReader.h"
|
|
|
|
#include "MediaPluginHost.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
2013-05-02 21:21:22 +00:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-03-05 14:56:34 +00:00
|
|
|
#include "MediaOmxDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "MediaOmxReader.h"
|
2013-03-22 02:56:22 +00:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
2013-11-11 22:52:33 +00:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 09:53:36 +00:00
|
|
|
#include "RtspOmxDecoder.h"
|
|
|
|
#include "RtspOmxReader.h"
|
|
|
|
#endif
|
2013-03-05 14:56:34 +00:00
|
|
|
#ifdef MOZ_WMF
|
|
|
|
#include "WMFDecoder.h"
|
2013-03-05 14:56:35 +00:00
|
|
|
#include "WMFReader.h"
|
2013-03-05 14:56:34 +00:00
|
|
|
#endif
|
2013-08-13 04:49:25 +00:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
#include "DirectShowDecoder.h"
|
|
|
|
#include "DirectShowReader.h"
|
|
|
|
#endif
|
2013-09-14 01:14:42 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
#include "AppleDecoder.h"
|
|
|
|
#include "AppleMP3Reader.h"
|
|
|
|
#endif
|
2013-11-20 21:04:33 +00:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
#include "MP4Reader.h"
|
|
|
|
#include "MP4Decoder.h"
|
|
|
|
#endif
|
2013-03-05 14:56:34 +00:00
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
namespace mozilla
|
|
|
|
{
|
|
|
|
|
2012-11-22 19:08:57 +00:00
|
|
|
template <class String>
|
2012-11-22 18:49:37 +00:00
|
|
|
static bool
|
2012-11-22 19:08:57 +00:00
|
|
|
CodecListContains(char const *const * aCodecs, const String& aCodec)
|
2012-11-22 18:49:37 +00:00
|
|
|
{
|
|
|
|
for (int32_t i = 0; aCodecs[i]; ++i) {
|
|
|
|
if (aCodec.EqualsASCII(aCodecs[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
#ifdef MOZ_RAW
|
2012-11-22 19:08:57 +00:00
|
|
|
static const char* gRawTypes[3] = {
|
2012-11-22 03:10:41 +00:00
|
|
|
"video/x-raw",
|
2012-11-22 19:08:57 +00:00
|
|
|
"video/x-raw-yuv",
|
|
|
|
nullptr
|
2012-11-22 03:10:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char* gRawCodecs[1] = {
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsRawType(const nsACString& aType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsRawEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 19:08:57 +00:00
|
|
|
return CodecListContains(gRawTypes, aType);
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
|
|
|
|
// of Ogg media types and codec types
|
2012-11-22 19:08:57 +00:00
|
|
|
static const char* const gOggTypes[4] = {
|
2012-11-22 03:10:41 +00:00
|
|
|
"video/ogg",
|
|
|
|
"audio/ogg",
|
2012-11-22 19:08:57 +00:00
|
|
|
"application/ogg",
|
|
|
|
nullptr
|
2012-11-22 03:10:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gOggCodecs[3] = {
|
|
|
|
"vorbis",
|
|
|
|
"theora",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gOggCodecsWithOpus[4] = {
|
|
|
|
"vorbis",
|
|
|
|
"opus",
|
|
|
|
"theora",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsOggType(const nsACString& aType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsOggEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 19:08:57 +00:00
|
|
|
return CodecListContains(gOggTypes, aType);
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#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 19:08:57 +00:00
|
|
|
static const char* const gWaveTypes[5] = {
|
2012-11-22 03:10:41 +00:00
|
|
|
"audio/x-wav",
|
|
|
|
"audio/wav",
|
|
|
|
"audio/wave",
|
2012-11-22 19:08:57 +00:00
|
|
|
"audio/x-pn-wav",
|
|
|
|
nullptr
|
2012-11-22 03:10:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char const *const gWaveCodecs[2] = {
|
|
|
|
"1", // Microsoft PCM Format
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsWaveType(const nsACString& aType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsWaveEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 19:08:57 +00:00
|
|
|
return CodecListContains(gWaveTypes, aType);
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WEBM
|
2012-11-22 19:08:57 +00:00
|
|
|
static const char* const gWebMTypes[3] = {
|
2012-11-22 03:10:41 +00:00
|
|
|
"video/webm",
|
2012-11-22 19:08:57 +00:00
|
|
|
"audio/webm",
|
|
|
|
nullptr
|
2012-11-22 03:10:41 +00:00
|
|
|
};
|
|
|
|
|
2013-12-04 00:21:00 +00:00
|
|
|
static char const *const gWebMCodecs[7] = {
|
2012-11-22 03:10:41 +00:00
|
|
|
"vp8",
|
|
|
|
"vp8.0",
|
2013-12-04 00:21:00 +00:00
|
|
|
"vp9",
|
|
|
|
"vp9.0",
|
2012-11-22 03:10:41 +00:00
|
|
|
"vorbis",
|
2013-11-22 22:07:00 +00:00
|
|
|
"opus",
|
2012-11-22 03:10:41 +00:00
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsWebMType(const nsACString& aType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsWebMEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 19:08:57 +00:00
|
|
|
return CodecListContains(gWebMTypes, aType);
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_GSTREAMER
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsGStreamerSupportedType(const nsACString& aMimeType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsGStreamerEnabled())
|
|
|
|
return false;
|
2013-03-13 20:10:47 +00:00
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
#ifdef MOZ_WEBM
|
2013-03-13 20:10:47 +00:00
|
|
|
if (IsWebMType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
|
|
|
|
return false;
|
2012-11-22 03:10:41 +00:00
|
|
|
#endif
|
2013-03-13 20:10:47 +00:00
|
|
|
if (IsOggType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return GStreamerDecoder::CanHandleMediaType(aMimeType, nullptr);
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-05-02 21:21:22 +00:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2014-05-07 10:05:29 +00:00
|
|
|
static const char* const gOmxTypes[] = {
|
2012-11-22 03:10:41 +00:00
|
|
|
"audio/mpeg",
|
|
|
|
"audio/mp4",
|
2013-03-22 02:56:22 +00:00
|
|
|
"audio/amr",
|
2012-11-22 03:10:41 +00:00
|
|
|
"video/mp4",
|
|
|
|
"video/3gpp",
|
2014-06-05 21:22:15 +00:00
|
|
|
"video/3gpp2",
|
2012-11-22 03:10:41 +00:00
|
|
|
"video/quicktime",
|
2014-05-07 10:05:29 +00:00
|
|
|
#ifdef MOZ_OMX_WEBM_DECODER
|
|
|
|
"video/webm",
|
|
|
|
"audio/webm",
|
|
|
|
#endif
|
2012-11-22 19:08:57 +00:00
|
|
|
nullptr
|
2012-11-22 03:10:41 +00:00
|
|
|
};
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsOmxSupportedType(const nsACString& aType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsOmxEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 19:08:57 +00:00
|
|
|
return CodecListContains(gOmxTypes, aType);
|
2012-11-22 03:10:41 +00: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
|
|
|
|
};
|
2013-06-20 20:49:35 +00:00
|
|
|
|
|
|
|
static char const *const gMpegAudioCodecs[2] = {
|
|
|
|
"mp3", // MP3
|
|
|
|
nullptr
|
|
|
|
};
|
2014-05-07 10:05:29 +00:00
|
|
|
|
|
|
|
#ifdef MOZ_OMX_WEBM_DECODER
|
|
|
|
static char const *const gOMXWebMCodecs[4] = {
|
|
|
|
"vorbis",
|
|
|
|
"vp8",
|
|
|
|
"vp8.0",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
#endif //MOZ_OMX_WEBM_DECODER
|
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
#endif
|
|
|
|
|
2013-11-11 22:52:33 +00:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 09:53:36 +00:00
|
|
|
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) {
|
2013-11-11 22:52:33 +00:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 09:53:36 +00:00
|
|
|
return CodecListContains(gRtspTypes, aMimeType);
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsMediaPluginsType(const nsACString& aType)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsMediaPluginsEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* supportedTypes[] = {
|
2012-11-22 19:08:57 +00:00
|
|
|
"audio/mpeg", "audio/mp4", "video/mp4", nullptr
|
2012-11-22 03:10:41 +00:00
|
|
|
};
|
2012-11-22 19:08:57 +00:00
|
|
|
return CodecListContains(supportedTypes, aType);
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-12-18 08:49:58 +00:00
|
|
|
#ifdef MOZ_WMF
|
2013-03-05 14:56:35 +00:00
|
|
|
static bool
|
|
|
|
IsWMFSupportedType(const nsACString& aType)
|
2012-12-18 08:49:58 +00:00
|
|
|
{
|
2013-11-17 22:29:55 +00:00
|
|
|
return WMFDecoder::CanPlayType(aType, NS_LITERAL_STRING(""));
|
2012-12-18 08:49:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-13 04:49:25 +00:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
static bool
|
|
|
|
IsDirectShowSupportedType(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
static bool
|
|
|
|
IsMP4SupportedType(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return Preferences::GetBool("media.fragmented-mp4.exposed", false) &&
|
|
|
|
MP4Decoder::GetSupportedCodecs(aType, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-14 01:14:42 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
static const char * const gAppleMP3Types[] = {
|
|
|
|
"audio/mp3",
|
|
|
|
"audio/mpeg",
|
|
|
|
nullptr,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const gAppleMP3Codecs[] = {
|
|
|
|
"mp3",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsAppleMediaSupportedType(const nsACString& aType,
|
|
|
|
const char * const ** aCodecs = nullptr)
|
|
|
|
{
|
|
|
|
if (MediaDecoder::IsAppleMP3Enabled()
|
|
|
|
&& CodecListContains(gAppleMP3Types, aType)) {
|
|
|
|
|
|
|
|
if (aCodecs) {
|
|
|
|
*aCodecs = gAppleMP3Codecs;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO MP4
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-22 03:10:41 +00:00
|
|
|
/* static */
|
|
|
|
bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType)
|
|
|
|
{
|
2012-11-22 20:15:47 +00: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-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
2012-11-22 20:15:47 +00:00
|
|
|
return CanHandleMediaType(aMIMEType, false, EmptyString()) != CANPLAY_NO;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
CanPlayStatus
|
|
|
|
DecoderTraits::CanHandleMediaType(const char* aMIMEType,
|
2012-11-22 18:49:37 +00:00
|
|
|
bool aHaveRequestedCodecs,
|
|
|
|
const nsAString& aRequestedCodecs)
|
2012-11-22 03:10:41 +00:00
|
|
|
{
|
2012-11-22 18:49:37 +00:00
|
|
|
char const* const* codecList = nullptr;
|
|
|
|
CanPlayStatus result = CANPLAY_NO;
|
2012-11-22 03:10:41 +00:00
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(nsDependentCString(aMIMEType))) {
|
2012-11-22 18:49:37 +00:00
|
|
|
codecList = gRawCodecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (IsOggType(nsDependentCString(aMIMEType))) {
|
2012-11-22 18:49:37 +00:00
|
|
|
codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(nsDependentCString(aMIMEType))) {
|
2012-11-22 18:49:37 +00:00
|
|
|
codecList = gWaveCodecs;
|
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-05-07 10:05:29 +00:00
|
|
|
#if defined(MOZ_WEBM) && !defined(MOZ_OMX_WEBM_DECODER)
|
2012-11-22 03:10:41 +00:00
|
|
|
if (IsWebMType(nsDependentCString(aMIMEType))) {
|
2012-11-22 18:49:37 +00:00
|
|
|
codecList = gWebMCodecs;
|
2013-12-03 13:50:30 +00:00
|
|
|
result = CANPLAY_MAYBE;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GSTREAMER
|
2013-03-13 20:10:47 +00:00
|
|
|
if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType),
|
|
|
|
aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) {
|
|
|
|
if (aHaveRequestedCodecs)
|
|
|
|
return CANPLAY_YES;
|
|
|
|
return CANPLAY_MAYBE;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-05-02 21:21:22 +00:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2012-11-22 03:10:41 +00:00
|
|
|
if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
|
2012-11-22 18:49:37 +00:00
|
|
|
result = CANPLAY_MAYBE;
|
2013-06-20 20:49:35 +00:00
|
|
|
if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
|
|
|
|
codecList = gMpegAudioCodecs;
|
2014-05-07 10:05:29 +00:00
|
|
|
#ifdef MOZ_OMX_WEBM_DECODER
|
|
|
|
} else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") ||
|
|
|
|
nsDependentCString(aMIMEType).EqualsASCII("video/webm")) {
|
|
|
|
codecList = gOMXWebMCodecs;
|
|
|
|
#endif
|
2013-06-20 20:49:35 +00:00
|
|
|
} else {
|
|
|
|
codecList = gH264Codecs;
|
|
|
|
}
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
#endif
|
2014-04-03 21:39:42 +00:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
// Note: DirectShow should come before WMF, so that we prefer DirectShow's
|
|
|
|
// MP3 support over WMF's.
|
|
|
|
if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
|
|
|
|
result = CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
2012-12-18 08:49:58 +00:00
|
|
|
#ifdef MOZ_WMF
|
2013-11-17 22:29:55 +00:00
|
|
|
if (IsWMFSupportedType(nsDependentCString(aMIMEType))) {
|
|
|
|
if (!aHaveRequestedCodecs) {
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
return WMFDecoder::CanPlayType(nsDependentCString(aMIMEType),
|
|
|
|
aRequestedCodecs)
|
|
|
|
? CANPLAY_YES : CANPLAY_NO;
|
2012-12-18 08:49:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-09-14 01:14:42 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) {
|
|
|
|
result = CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-22 03:10:41 +00:00
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
2012-11-22 18:49:37 +00:00
|
|
|
if (MediaDecoder::IsMediaPluginsEnabled() &&
|
|
|
|
GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList))
|
|
|
|
result = CANPLAY_MAYBE;
|
2014-01-20 10:54:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
|
|
|
if (IsRtspSupportedType(nsDependentCString(aMIMEType))) {
|
|
|
|
result = CANPLAY_MAYBE;
|
|
|
|
}
|
2012-11-22 03:10:41 +00:00
|
|
|
#endif
|
2013-03-13 20:10:47 +00:00
|
|
|
if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) {
|
2012-11-22 18:49:37 +00: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;
|
|
|
|
}
|
2013-09-17 12:52:39 +00:00
|
|
|
expectMoreTokens = tokenizer.separatorAfterCurrentToken();
|
2012-11-22 18:49:37 +00:00
|
|
|
}
|
|
|
|
if (expectMoreTokens) {
|
|
|
|
// Last codec name was empty
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
return CANPLAY_YES;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
2013-11-20 21:04:33 +00:00
|
|
|
// Instantiates but does not initialize decoder.
|
|
|
|
static
|
2013-03-05 14:56:34 +00:00
|
|
|
already_AddRefed<MediaDecoder>
|
2013-11-20 21:04:33 +00:00
|
|
|
InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
|
2013-03-05 14:56:34 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<MediaDecoder> decoder;
|
|
|
|
|
2014-06-16 22:32:18 +00:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
if (IsMP4SupportedType(aType)) {
|
|
|
|
decoder = new MP4Decoder();
|
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-05 14:56:34 +00:00
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
if (IsGStreamerSupportedType(aType)) {
|
|
|
|
decoder = new GStreamerDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(aType)) {
|
|
|
|
decoder = new RawDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (IsOggType(aType)) {
|
|
|
|
decoder = new OggDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(aType)) {
|
|
|
|
decoder = new WaveDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-05-02 21:21:22 +00:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-03-05 14:56:34 +00:00
|
|
|
if (IsOmxSupportedType(aType)) {
|
2013-03-22 02:56:22 +00: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.
|
2013-05-30 17:52:58 +00:00
|
|
|
if (aType.EqualsASCII("audio/amr")) {
|
2013-11-18 04:22:47 +00:00
|
|
|
dom::HTMLMediaElement* element = aOwner->GetMediaElement();
|
2013-03-22 02:56:22 +00:00
|
|
|
if (!element) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIPrincipal* principal = element->NodePrincipal();
|
|
|
|
if (!principal) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2013-03-05 14:56:34 +00:00
|
|
|
decoder = new MediaOmxDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-11-11 22:52:33 +00:00
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
2013-09-23 09:53:36 +00:00
|
|
|
if (IsRtspSupportedType(aType)) {
|
|
|
|
decoder = new RtspOmxDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-09-23 09:53:36 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-03-05 14:56:34 +00:00
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
2013-10-23 20:34:10 +00:00
|
|
|
if (MediaDecoder::IsMediaPluginsEnabled() &&
|
|
|
|
GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
|
2013-03-05 14:56:34 +00:00
|
|
|
decoder = new MediaPluginDecoder(aType);
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
if (IsWebMType(aType)) {
|
|
|
|
decoder = new WebMDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-08-13 04:49:25 +00:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
2014-04-03 21:39:42 +00:00
|
|
|
// Note: DirectShow should come before WMF, so that we prefer DirectShow's
|
|
|
|
// MP3 support over WMF's.
|
2013-08-13 04:49:25 +00:00
|
|
|
if (IsDirectShowSupportedType(aType)) {
|
|
|
|
decoder = new DirectShowDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-05 14:56:34 +00:00
|
|
|
#ifdef MOZ_WMF
|
|
|
|
if (IsWMFSupportedType(aType)) {
|
|
|
|
decoder = new WMFDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-03-05 14:56:34 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-09-14 01:14:42 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
if (IsAppleMediaSupportedType(aType)) {
|
|
|
|
decoder = new AppleDecoder();
|
2013-11-20 21:04:33 +00:00
|
|
|
return decoder.forget();
|
2013-09-14 01:14:42 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-03-05 14:56:34 +00:00
|
|
|
|
|
|
|
NS_ENSURE_TRUE(decoder != nullptr, nullptr);
|
|
|
|
NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
|
2013-11-20 21:04:33 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<MediaDecoder>
|
|
|
|
DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
|
|
|
|
{
|
|
|
|
nsRefPtr<MediaDecoder> decoder(InstantiateDecoder(aType, aOwner));
|
|
|
|
NS_ENSURE_TRUE(decoder != nullptr, nullptr);
|
|
|
|
NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
|
2013-03-05 14:56:34 +00:00
|
|
|
|
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
/* static */
|
|
|
|
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
|
|
|
|
{
|
|
|
|
MediaDecoderReader* decoderReader = nullptr;
|
|
|
|
|
2014-06-16 22:32:18 +00:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
if (IsMP4SupportedType(aType)) {
|
|
|
|
decoderReader = new MP4Reader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
2013-03-05 14:56:35 +00:00
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
if (IsGStreamerSupportedType(aType)) {
|
|
|
|
decoderReader = new GStreamerReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_RAW
|
|
|
|
if (IsRawType(aType)) {
|
|
|
|
decoderReader = new RawReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
if (IsOggType(aType)) {
|
|
|
|
decoderReader = new OggReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#ifdef MOZ_WAVE
|
|
|
|
if (IsWaveType(aType)) {
|
|
|
|
decoderReader = new WaveReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
2013-05-02 21:21:22 +00:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-03-05 14:56:35 +00:00
|
|
|
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
|
2013-08-13 04:49:25 +00:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
// Note: DirectShowReader is preferred for MP3, but if it's disabled we
|
|
|
|
// fallback to the WMFReader.
|
|
|
|
if (IsDirectShowSupportedType(aType)) {
|
|
|
|
decoderReader = new DirectShowReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
2013-03-05 14:56:35 +00:00
|
|
|
#ifdef MOZ_WMF
|
|
|
|
if (IsWMFSupportedType(aType)) {
|
|
|
|
decoderReader = new WMFReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
2013-09-14 01:14:42 +00:00
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
if (IsAppleMediaSupportedType(aType)) {
|
|
|
|
decoderReader = new AppleMP3Reader(aDecoder);
|
|
|
|
} else
|
2013-03-05 14:56:35 +00:00
|
|
|
#endif
|
|
|
|
if (false) {} // dummy if to take care of the dangling else
|
|
|
|
|
|
|
|
return decoderReader;
|
|
|
|
}
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
/* static */
|
|
|
|
bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
IsOggType(aType) ||
|
2013-05-02 21:21:22 +00:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-07-01 13:30:48 +00:00
|
|
|
// We support amr inside WebApps on firefoxOS but not in general web content.
|
|
|
|
// Ensure we dont create a VideoDocument when accessing amr URLs directly.
|
|
|
|
(IsOmxSupportedType(aType) && !aType.EqualsASCII("audio/amr")) ||
|
2013-03-05 14:56:35 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_WEBM
|
|
|
|
IsWebMType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_GSTREAMER
|
|
|
|
IsGStreamerSupportedType(aType) ||
|
|
|
|
#endif
|
|
|
|
#ifdef MOZ_MEDIA_PLUGINS
|
|
|
|
(MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) ||
|
|
|
|
#endif
|
2013-11-20 21:04:33 +00:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
IsMP4SupportedType(aType) ||
|
|
|
|
#endif
|
2013-03-05 14:56:35 +00:00
|
|
|
#ifdef MOZ_WMF
|
2013-06-20 23:16:55 +00:00
|
|
|
(IsWMFSupportedType(aType) &&
|
|
|
|
Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true)) ||
|
2013-08-13 04:49:25 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
IsDirectShowSupportedType(aType) ||
|
2013-09-14 01:14:42 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MOZ_APPLEMEDIA
|
|
|
|
IsAppleMediaSupportedType(aType) ||
|
2014-01-20 10:54:33 +00:00
|
|
|
#endif
|
|
|
|
#ifdef NECKO_PROTOCOL_rtsp
|
|
|
|
IsRtspSupportedType(aType) ||
|
2013-03-05 14:56:35 +00:00
|
|
|
#endif
|
|
|
|
false;
|
2012-11-22 03:10:41 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 14:56:35 +00:00
|
|
|
}
|