2012-11-22 07:10:41 +04: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"
|
2016-09-26 09:43:16 +03:00
|
|
|
#include "MediaContentType.h"
|
2012-11-22 07:10:41 +04:00
|
|
|
#include "MediaDecoder.h"
|
2012-11-22 22:49:37 +04:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2014-09-16 12:07:15 +04:00
|
|
|
#include "nsMimeTypes.h"
|
2013-06-21 03:16:55 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-04-12 00:13:43 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-03-05 18:56:35 +04:00
|
|
|
|
2013-03-05 18:56:34 +04:00
|
|
|
#include "OggDecoder.h"
|
2013-03-05 18:56:35 +04:00
|
|
|
#include "OggReader.h"
|
2016-07-21 04:34:42 +03:00
|
|
|
#include "OggDemuxer.h"
|
2015-12-18 11:51:16 +03:00
|
|
|
|
2013-03-05 18:56:34 +04:00
|
|
|
#include "WebMDecoder.h"
|
2015-06-18 16:59:43 +03:00
|
|
|
#include "WebMDemuxer.h"
|
2015-12-12 21:49:07 +03:00
|
|
|
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
|
|
|
#include "AndroidMediaDecoder.h"
|
|
|
|
#include "AndroidMediaReader.h"
|
|
|
|
#include "AndroidMediaPluginHost.h"
|
2013-03-05 18:56:34 +04:00
|
|
|
#endif
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-03-05 18:56:34 +04:00
|
|
|
#include "MediaOmxDecoder.h"
|
2013-03-05 18:56:35 +04:00
|
|
|
#include "MediaOmxReader.h"
|
2013-03-22 06:56:22 +04:00
|
|
|
#include "nsIPrincipal.h"
|
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-03-05 18:56:34 +04:00
|
|
|
#endif
|
2013-08-13 08:49:25 +04:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
#include "DirectShowDecoder.h"
|
|
|
|
#include "DirectShowReader.h"
|
|
|
|
#endif
|
2013-11-21 01:04:33 +04:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
#include "MP4Decoder.h"
|
2015-05-16 15:35:22 +03:00
|
|
|
#include "MP4Demuxer.h"
|
2013-11-21 01:04:33 +04:00
|
|
|
#endif
|
2015-05-16 15:35:22 +03:00
|
|
|
#include "MediaFormatReader.h"
|
2013-03-05 18:56:34 +04:00
|
|
|
|
2015-06-05 16:53:31 +03:00
|
|
|
#include "MP3Decoder.h"
|
|
|
|
#include "MP3Demuxer.h"
|
|
|
|
|
2016-02-12 04:40:36 +03:00
|
|
|
#include "WaveDecoder.h"
|
|
|
|
#include "WaveDemuxer.h"
|
|
|
|
#include "WaveReader.h"
|
|
|
|
|
2015-11-27 07:40:36 +03:00
|
|
|
#include "ADTSDecoder.h"
|
|
|
|
#include "ADTSDemuxer.h"
|
|
|
|
|
2016-08-17 08:45:06 +03:00
|
|
|
#include "FlacDecoder.h"
|
|
|
|
#include "FlacDemuxer.h"
|
|
|
|
|
2016-03-11 14:42:02 +03:00
|
|
|
#include "nsPluginHost.h"
|
2016-08-04 10:14:28 +03:00
|
|
|
#include "MediaPrefs.h"
|
2016-03-11 14:42:02 +03:00
|
|
|
|
2012-11-22 07:10:41 +04:00
|
|
|
namespace mozilla
|
|
|
|
{
|
|
|
|
|
2012-11-22 23:08:57 +04:00
|
|
|
template <class String>
|
2012-11-22 22:49:37 +04:00
|
|
|
static bool
|
2012-11-22 23:08:57 +04:00
|
|
|
CodecListContains(char const *const * aCodecs, const String& aCodec)
|
2012-11-22 22:49:37 +04:00
|
|
|
{
|
|
|
|
for (int32_t i = 0; aCodecs[i]; ++i) {
|
|
|
|
if (aCodec.EqualsASCII(aCodecs[i]))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-04 10:14:28 +03:00
|
|
|
static bool
|
2016-08-04 10:14:28 +03:00
|
|
|
IsOggSupportedType(const nsACString& aType,
|
|
|
|
const nsAString& aCodecs = EmptyString())
|
2016-08-04 10:14:28 +03:00
|
|
|
{
|
2016-08-04 10:14:28 +03:00
|
|
|
return OggDecoder::CanHandleMediaType(aType, aCodecs);
|
|
|
|
}
|
2016-08-22 20:07:25 +03:00
|
|
|
|
2016-08-04 10:14:28 +03:00
|
|
|
static bool
|
|
|
|
IsOggTypeAndEnabled(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return IsOggSupportedType(aType);
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 23:08:57 +04:00
|
|
|
static const char* const gWaveTypes[5] = {
|
2012-11-22 07:10:41 +04:00
|
|
|
"audio/x-wav",
|
|
|
|
"audio/wav",
|
|
|
|
"audio/wave",
|
2012-11-22 23:08:57 +04:00
|
|
|
"audio/x-pn-wav",
|
|
|
|
nullptr
|
2012-11-22 07:10:41 +04:00
|
|
|
};
|
|
|
|
|
2016-02-12 04:45:28 +03:00
|
|
|
static char const *const gWaveCodecs[4] = {
|
2012-11-22 07:10:41 +04:00
|
|
|
"1", // Microsoft PCM Format
|
2016-02-12 04:45:28 +03:00
|
|
|
"6", // aLaw Encoding
|
|
|
|
"7", // uLaw Encoding
|
2012-11-22 07:10:41 +04:00
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
static bool
|
|
|
|
IsWaveType(const nsACString& aType)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsWaveEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:08:57 +04:00
|
|
|
return CodecListContains(gWaveTypes, aType);
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
2015-12-03 09:36:36 +03:00
|
|
|
static bool
|
|
|
|
IsWebMSupportedType(const nsACString& aType,
|
|
|
|
const nsAString& aCodecs = EmptyString())
|
|
|
|
{
|
|
|
|
return WebMDecoder::CanHandleMediaType(aType, aCodecs);
|
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
|
2015-06-10 02:04:19 +03:00
|
|
|
/* static */ bool
|
2015-10-27 04:35:16 +03:00
|
|
|
DecoderTraits::IsWebMTypeAndEnabled(const nsACString& aType)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
2015-12-03 09:36:36 +03:00
|
|
|
return IsWebMSupportedType(aType);
|
2015-07-21 07:01:07 +03:00
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
|
2015-12-03 11:57:13 +03:00
|
|
|
/* static */ bool
|
|
|
|
DecoderTraits::IsWebMAudioType(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return aType.EqualsASCII("audio/webm");
|
|
|
|
}
|
|
|
|
|
2016-04-12 00:13:43 +03:00
|
|
|
static char const *const gHttpLiveStreamingTypes[] = {
|
|
|
|
// For m3u8.
|
|
|
|
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
|
|
|
|
"application/vnd.apple.mpegurl",
|
|
|
|
// Some sites serve these as the informal m3u type.
|
2016-05-12 00:23:11 +03:00
|
|
|
"application/x-mpegurl",
|
2016-04-12 00:13:43 +03:00
|
|
|
"audio/x-mpegurl",
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
static bool
|
|
|
|
IsHttpLiveStreamingType(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return CodecListContains(gHttpLiveStreamingTypes, aType);
|
|
|
|
}
|
|
|
|
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2014-05-07 14:05:29 +04:00
|
|
|
static const char* const gOmxTypes[] = {
|
2012-11-22 07:10:41 +04:00
|
|
|
"audio/mpeg",
|
|
|
|
"audio/mp4",
|
2013-03-22 06:56:22 +04:00
|
|
|
"audio/amr",
|
2014-09-16 12:07:15 +04:00
|
|
|
"audio/3gpp",
|
2014-12-03 00:37:00 +03:00
|
|
|
"audio/flac",
|
2012-11-22 07:10:41 +04:00
|
|
|
"video/mp4",
|
2015-08-21 21:52:19 +03:00
|
|
|
"video/x-m4v",
|
2012-11-22 07:10:41 +04:00
|
|
|
"video/3gpp",
|
2014-06-06 01:22:15 +04:00
|
|
|
"video/3gpp2",
|
2012-11-22 07:10:41 +04:00
|
|
|
"video/quicktime",
|
2014-05-07 14:05:29 +04:00
|
|
|
#ifdef MOZ_OMX_WEBM_DECODER
|
|
|
|
"video/webm",
|
|
|
|
"audio/webm",
|
|
|
|
#endif
|
2014-12-23 05:20:25 +03:00
|
|
|
"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",
|
2012-11-22 23:08:57 +04:00
|
|
|
nullptr
|
2012-11-22 07:10:41 +04:00
|
|
|
};
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
static bool
|
|
|
|
IsOmxSupportedType(const nsACString& aType)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
|
|
|
if (!MediaDecoder::IsOmxEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:08:57 +04:00
|
|
|
return CodecListContains(gOmxTypes, aType);
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
2014-12-23 05:20:25 +03:00
|
|
|
static bool
|
|
|
|
IsB2GSupportOnlyType(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return CodecListContains(gB2GOnlyTypes, aType);
|
|
|
|
}
|
|
|
|
|
2012-11-22 07:10:41 +04: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-21 00:49:35 +04:00
|
|
|
|
|
|
|
static char const *const gMpegAudioCodecs[2] = {
|
|
|
|
"mp3", // MP3
|
|
|
|
nullptr
|
|
|
|
};
|
2014-05-07 14:05:29 +04:00
|
|
|
|
|
|
|
#ifdef MOZ_OMX_WEBM_DECODER
|
2015-07-06 13:02:50 +03:00
|
|
|
static char const *const gOMXWebMCodecs[] = {
|
2014-05-07 14:05:29 +04:00
|
|
|
"vorbis",
|
|
|
|
"vp8",
|
|
|
|
"vp8.0",
|
2015-07-06 13:02:50 +03:00
|
|
|
// 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
|
2014-05-07 14:05:29 +04:00
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
#endif //MOZ_OMX_WEBM_DECODER
|
|
|
|
|
2012-11-22 07:10:41 +04:00
|
|
|
#endif
|
|
|
|
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2013-03-05 18:56:35 +04:00
|
|
|
static bool
|
2014-07-17 05:32:56 +04:00
|
|
|
IsAndroidMediaType(const nsACString& aType)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
2016-03-10 01:45:27 +03:00
|
|
|
if (!MediaDecoder::IsAndroidMediaPluginEnabled()) {
|
2012-11-22 07:10:41 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* supportedTypes[] = {
|
2015-08-21 21:52:19 +03:00
|
|
|
"audio/mpeg", "audio/mp4", "video/mp4", "video/x-m4v", nullptr
|
2012-11-22 07:10:41 +04:00
|
|
|
};
|
2012-11-22 23:08:57 +04:00
|
|
|
return CodecListContains(supportedTypes, aType);
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-08-13 08:49:25 +04:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
static bool
|
|
|
|
IsDirectShowSupportedType(const nsACString& aType)
|
|
|
|
{
|
|
|
|
return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-11-21 01:04:33 +04:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
static bool
|
2014-09-01 09:32:47 +04:00
|
|
|
IsMP4SupportedType(const nsACString& aType,
|
2016-04-19 10:36:19 +03:00
|
|
|
DecoderDoctorDiagnostics* aDiagnostics,
|
2014-09-01 09:32:47 +04:00
|
|
|
const nsAString& aCodecs = EmptyString())
|
2013-11-21 01:04:33 +04:00
|
|
|
{
|
2016-04-19 10:36:19 +03:00
|
|
|
return MP4Decoder::CanHandleMediaType(aType, aCodecs, aDiagnostics);
|
2013-11-21 01:04:33 +04:00
|
|
|
}
|
|
|
|
#endif
|
2015-07-21 07:01:07 +03:00
|
|
|
|
|
|
|
/* static */ bool
|
2016-04-19 10:36:19 +03:00
|
|
|
DecoderTraits::IsMP4TypeAndEnabled(const nsACString& aType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-07-21 07:01:07 +03:00
|
|
|
{
|
|
|
|
#ifdef MOZ_FMP4
|
2016-04-19 10:36:19 +03:00
|
|
|
return IsMP4SupportedType(aType, aDiagnostics);
|
2015-12-28 10:11:26 +03:00
|
|
|
#else
|
2015-07-21 07:01:07 +03:00
|
|
|
return false;
|
2015-12-28 10:11:26 +03:00
|
|
|
#endif
|
2015-07-21 07:01:07 +03:00
|
|
|
}
|
|
|
|
|
2015-06-05 16:53:31 +03:00
|
|
|
static bool
|
|
|
|
IsMP3SupportedType(const nsACString& aType,
|
|
|
|
const nsAString& aCodecs = EmptyString())
|
|
|
|
{
|
2015-10-23 12:48:28 +03:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
|
|
|
return false;
|
2015-12-28 10:11:26 +03:00
|
|
|
#else
|
2015-10-02 05:24:37 +03:00
|
|
|
return MP3Decoder::CanHandleMediaType(aType, aCodecs);
|
2015-12-28 10:11:26 +03:00
|
|
|
#endif
|
2015-06-05 16:53:31 +03:00
|
|
|
}
|
2013-11-21 01:04:33 +04:00
|
|
|
|
2015-11-27 07:40:36 +03:00
|
|
|
static bool
|
|
|
|
IsAACSupportedType(const nsACString& aType,
|
|
|
|
const nsAString& aCodecs = EmptyString())
|
|
|
|
{
|
|
|
|
return ADTSDecoder::CanHandleMediaType(aType, aCodecs);
|
|
|
|
}
|
|
|
|
|
2016-02-12 04:40:36 +03:00
|
|
|
static bool
|
|
|
|
IsWAVSupportedType(const nsACString& aType,
|
|
|
|
const nsAString& aCodecs = EmptyString())
|
|
|
|
{
|
|
|
|
return WaveDecoder::CanHandleMediaType(aType, aCodecs);
|
|
|
|
}
|
|
|
|
|
2016-08-17 08:45:06 +03:00
|
|
|
static bool
|
|
|
|
IsFlacSupportedType(const nsACString& aType,
|
|
|
|
const nsAString& aCodecs = EmptyString())
|
|
|
|
{
|
|
|
|
return FlacDecoder::CanHandleMediaType(aType, aCodecs);
|
|
|
|
}
|
|
|
|
|
2012-11-22 07:10:41 +04:00
|
|
|
/* static */
|
2016-04-19 10:36:19 +03:00
|
|
|
bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
2016-02-17 08:09:51 +03:00
|
|
|
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;
|
|
|
|
}
|
2016-03-11 14:42:02 +03:00
|
|
|
|
|
|
|
// If an external plugin which can handle quicktime video is available
|
|
|
|
// (and not disabled), prefer it over native playback as there several
|
|
|
|
// codecs found in the wild that we do not handle.
|
|
|
|
if (nsDependentCString(aMIMEType).EqualsASCII("video/quicktime")) {
|
|
|
|
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
|
|
|
if (pluginHost &&
|
|
|
|
pluginHost->HavePluginForType(nsDependentCString(aMIMEType))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-19 10:36:19 +03:00
|
|
|
return CanHandleMediaType(aMIMEType, false, EmptyString(), aDiagnostics)
|
|
|
|
!= CANPLAY_NO;
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
CanPlayStatus
|
2015-07-21 07:01:07 +03:00
|
|
|
DecoderTraits::CanHandleCodecsType(const char* aMIMEType,
|
2016-04-19 10:36:19 +03:00
|
|
|
const nsAString& aRequestedCodecs,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
2012-11-22 22:49:37 +04:00
|
|
|
char const* const* codecList = nullptr;
|
2016-08-04 10:14:28 +03:00
|
|
|
if (IsOggTypeAndEnabled(nsDependentCString(aMIMEType))) {
|
|
|
|
if (IsOggSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
|
|
|
|
return CANPLAY_YES;
|
|
|
|
} else {
|
|
|
|
// We can only reach this position if a particular codec was requested,
|
|
|
|
// ogg is supported and working: the codec must be invalid.
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
if (IsWaveType(nsDependentCString(aMIMEType))) {
|
2012-11-22 22:49:37 +04:00
|
|
|
codecList = gWaveCodecs;
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
2015-07-21 07:01:07 +03:00
|
|
|
#if !defined(MOZ_OMX_WEBM_DECODER)
|
2015-10-27 04:35:16 +03:00
|
|
|
if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) {
|
2015-12-03 09:36:36 +03:00
|
|
|
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;
|
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-07-04 12:31:19 +04:00
|
|
|
#ifdef MOZ_FMP4
|
2016-04-19 10:36:19 +03:00
|
|
|
if (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType), aDiagnostics)) {
|
|
|
|
if (IsMP4SupportedType(nsDependentCString(aMIMEType), aDiagnostics, aRequestedCodecs)) {
|
2013-03-14 00:10:47 +04:00
|
|
|
return CANPLAY_YES;
|
2015-07-21 07:01:07 +03:00
|
|
|
} 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;
|
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
2015-07-21 07:01:07 +03:00
|
|
|
if (IsMP3SupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
|
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2015-11-27 07:40:36 +03:00
|
|
|
if (IsAACSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
|
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2016-08-17 08:45:06 +03:00
|
|
|
if (IsFlacSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) {
|
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2012-11-22 07:10:41 +04:00
|
|
|
if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
|
2013-06-21 00:49:35 +04:00
|
|
|
if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
|
|
|
|
codecList = gMpegAudioCodecs;
|
2014-05-07 14:05:29 +04:00
|
|
|
#ifdef MOZ_OMX_WEBM_DECODER
|
|
|
|
} else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") ||
|
|
|
|
nsDependentCString(aMIMEType).EqualsASCII("video/webm")) {
|
|
|
|
codecList = gOMXWebMCodecs;
|
|
|
|
#endif
|
2013-06-21 00:49:35 +04:00
|
|
|
} else {
|
|
|
|
codecList = gH264Codecs;
|
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-04-04 01:39:42 +04:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
2015-07-21 07:01:07 +03:00
|
|
|
DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList);
|
2014-04-04 01:39:42 +04:00
|
|
|
#endif
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled()) {
|
2015-07-21 07:01:07 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList);
|
2014-01-20 14:54:33 +04:00
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
#endif
|
2015-07-21 07:01:07 +03:00
|
|
|
if (!codecList) {
|
|
|
|
return CANPLAY_MAYBE;
|
2012-11-22 22:49:37 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 16:52:39 +04:00
|
|
|
expectMoreTokens = tokenizer.separatorAfterCurrentToken();
|
2012-11-22 22:49:37 +04:00
|
|
|
}
|
|
|
|
if (expectMoreTokens) {
|
|
|
|
// Last codec name was empty
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
2015-07-21 07:01:07 +03:00
|
|
|
|
2012-11-22 22:49:37 +04:00
|
|
|
return CANPLAY_YES;
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
2015-07-21 07:01:07 +03:00
|
|
|
/* static */
|
|
|
|
CanPlayStatus
|
|
|
|
DecoderTraits::CanHandleMediaType(const char* aMIMEType,
|
|
|
|
bool aHaveRequestedCodecs,
|
2016-04-19 10:36:19 +03:00
|
|
|
const nsAString& aRequestedCodecs,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-07-21 07:01:07 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2016-04-12 00:13:43 +03:00
|
|
|
if (IsHttpLiveStreamingType(nsDependentCString(aMIMEType))) {
|
|
|
|
Telemetry::Accumulate(Telemetry::MEDIA_HLS_CANPLAY_REQUESTED, true);
|
|
|
|
}
|
|
|
|
|
2015-07-21 07:01:07 +03:00
|
|
|
if (aHaveRequestedCodecs) {
|
2016-04-19 10:36:19 +03:00
|
|
|
CanPlayStatus result = CanHandleCodecsType(aMIMEType,
|
|
|
|
aRequestedCodecs,
|
|
|
|
aDiagnostics);
|
2015-07-21 07:01:07 +03:00
|
|
|
if (result == CANPLAY_NO || result == CANPLAY_YES) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 10:14:28 +03:00
|
|
|
if (IsOggTypeAndEnabled(nsDependentCString(aMIMEType))) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
if (IsWaveType(nsDependentCString(aMIMEType))) {
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2016-04-19 10:36:19 +03:00
|
|
|
if (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType), aDiagnostics)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#if !defined(MOZ_OMX_WEBM_DECODER)
|
2015-10-27 04:35:16 +03:00
|
|
|
if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (IsMP3SupportedType(nsDependentCString(aMIMEType))) {
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2015-11-27 07:40:36 +03:00
|
|
|
if (IsAACSupportedType(nsDependentCString(aMIMEType))) {
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2016-08-17 08:45:06 +03:00
|
|
|
if (IsFlacSupportedType(nsDependentCString(aMIMEType))) {
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2015-07-21 07:01:07 +03:00
|
|
|
#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
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
|
2015-07-21 07:01:07 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), nullptr)) {
|
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:43:16 +03:00
|
|
|
/* static */
|
|
|
|
CanPlayStatus
|
|
|
|
DecoderTraits::CanHandleContentType(const MediaContentType& aContentType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
|
|
|
{
|
|
|
|
if (!aContentType.IsValid()) {
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CanHandleMediaType(aContentType.GetMIMEType().Data(),
|
|
|
|
aContentType.HaveCodecs(),
|
|
|
|
aContentType.GetCodecs(),
|
|
|
|
aDiagnostics);
|
|
|
|
}
|
|
|
|
|
2013-11-21 01:04:33 +04:00
|
|
|
// Instantiates but does not initialize decoder.
|
|
|
|
static
|
2013-03-05 18:56:34 +04:00
|
|
|
already_AddRefed<MediaDecoder>
|
2016-04-19 10:36:19 +03:00
|
|
|
InstantiateDecoder(const nsACString& aType,
|
|
|
|
MediaDecoderOwner* aOwner,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2013-03-05 18:56:34 +04:00
|
|
|
{
|
2015-04-24 21:22:20 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<MediaDecoder> decoder;
|
2013-03-05 18:56:34 +04:00
|
|
|
|
2014-06-17 02:32:18 +04:00
|
|
|
#ifdef MOZ_FMP4
|
2016-04-19 10:36:19 +03:00
|
|
|
if (IsMP4SupportedType(aType, aDiagnostics)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new MP4Decoder(aOwner);
|
2014-06-17 02:32:18 +04:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2015-06-05 16:53:31 +03:00
|
|
|
if (IsMP3SupportedType(aType)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new MP3Decoder(aOwner);
|
2015-06-05 16:53:31 +03:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
2015-11-27 07:40:36 +03:00
|
|
|
if (IsAACSupportedType(aType)) {
|
|
|
|
decoder = new ADTSDecoder(aOwner);
|
|
|
|
return decoder.forget();
|
|
|
|
}
|
2016-08-04 10:14:28 +03:00
|
|
|
if (IsOggSupportedType(aType)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new OggDecoder(aOwner);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
if (IsWaveType(aType)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new WaveDecoder(aOwner);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
2016-08-17 08:45:06 +03:00
|
|
|
if (IsFlacSupportedType(aType)) {
|
|
|
|
decoder = new FlacDecoder(aOwner);
|
|
|
|
return decoder.forget();
|
|
|
|
}
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-03-05 18:56:34 +04:00
|
|
|
if (IsOmxSupportedType(aType)) {
|
2014-12-23 05:20:25 +03:00
|
|
|
// 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)) {
|
2013-11-18 08:22:47 +04:00
|
|
|
dom::HTMLMediaElement* element = aOwner->GetMediaElement();
|
2013-03-22 06:56:22 +04:00
|
|
|
if (!element) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
nsIPrincipal* principal = element->NodePrincipal();
|
|
|
|
if (!principal) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new MediaOmxDecoder(aOwner);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
#endif
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
|
2015-04-24 21:22:20 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new AndroidMediaDecoder(aOwner, aType);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
#endif
|
2015-12-12 21:49:07 +03:00
|
|
|
|
2015-12-03 09:36:36 +03:00
|
|
|
if (IsWebMSupportedType(aType)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new WebMDecoder(aOwner);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
2015-12-12 21:49:07 +03:00
|
|
|
|
2013-08-13 08:49:25 +04:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
2014-04-04 01:39:42 +04:00
|
|
|
// Note: DirectShow should come before WMF, so that we prefer DirectShow's
|
|
|
|
// MP3 support over WMF's.
|
2013-08-13 08:49:25 +04:00
|
|
|
if (IsDirectShowSupportedType(aType)) {
|
2015-10-15 06:36:21 +03:00
|
|
|
decoder = new DirectShowDecoder(aOwner);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2013-03-05 18:56:34 +04:00
|
|
|
|
2016-04-12 00:13:43 +03:00
|
|
|
if (IsHttpLiveStreamingType(aType)) {
|
|
|
|
// We don't have an HLS decoder.
|
|
|
|
Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false);
|
|
|
|
}
|
|
|
|
|
2013-11-21 01:04:33 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<MediaDecoder>
|
2016-04-19 10:36:19 +03:00
|
|
|
DecoderTraits::CreateDecoder(const nsACString& aType,
|
|
|
|
MediaDecoderOwner* aOwner,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2013-11-21 01:04:33 +04:00
|
|
|
{
|
2015-04-24 21:22:20 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2016-04-19 10:36:19 +03:00
|
|
|
return InstantiateDecoder(aType, aOwner, aDiagnostics);
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
/* static */
|
|
|
|
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
|
|
|
|
{
|
2015-04-24 21:22:20 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2013-03-05 18:56:35 +04:00
|
|
|
MediaDecoderReader* decoderReader = nullptr;
|
|
|
|
|
2015-02-27 03:31:46 +03:00
|
|
|
if (!aDecoder) {
|
|
|
|
return decoderReader;
|
|
|
|
}
|
2014-06-17 02:32:18 +04:00
|
|
|
#ifdef MOZ_FMP4
|
2016-04-19 10:36:19 +03:00
|
|
|
if (IsMP4SupportedType(aType, /* DecoderDoctorDiagnostics* */ nullptr)) {
|
2015-07-21 03:48:00 +03:00
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource()));
|
2014-06-17 02:32:18 +04:00
|
|
|
} else
|
|
|
|
#endif
|
2015-06-05 16:53:31 +03:00
|
|
|
if (IsMP3SupportedType(aType)) {
|
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2015-11-27 07:40:36 +03:00
|
|
|
if (IsAACSupportedType(aType)) {
|
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-02-12 04:40:36 +03:00
|
|
|
if (IsWAVSupportedType(aType)) {
|
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-08-17 08:45:06 +03:00
|
|
|
if (IsFlacSupportedType(aType)) {
|
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-08-04 10:14:28 +03:00
|
|
|
if (IsOggSupportedType(aType)) {
|
|
|
|
decoderReader = MediaPrefs::OggFormatReader() ?
|
2016-07-21 04:34:42 +03:00
|
|
|
static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()))) :
|
|
|
|
new OggReader(aDecoder);
|
2013-03-05 18:56:35 +04:00
|
|
|
} else
|
|
|
|
if (IsWaveType(aType)) {
|
|
|
|
decoderReader = new WaveReader(aDecoder);
|
|
|
|
} else
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2013-03-05 18:56:35 +04:00
|
|
|
if (IsOmxSupportedType(aType)) {
|
|
|
|
decoderReader = new MediaOmxReader(aDecoder);
|
|
|
|
} else
|
|
|
|
#endif
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
|
2015-04-24 21:22:20 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
|
2014-07-17 05:32:56 +04:00
|
|
|
decoderReader = new AndroidMediaReader(aDecoder, aType);
|
2013-03-05 18:56:35 +04:00
|
|
|
} else
|
|
|
|
#endif
|
2015-12-03 09:36:36 +03:00
|
|
|
if (IsWebMSupportedType(aType)) {
|
2015-12-22 11:38:18 +03:00
|
|
|
decoderReader =
|
|
|
|
new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource()));
|
2013-03-05 18:56:35 +04:00
|
|
|
} else
|
2013-08-13 08:49:25 +04:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
if (IsDirectShowSupportedType(aType)) {
|
|
|
|
decoderReader = new DirectShowReader(aDecoder);
|
|
|
|
} else
|
2013-03-05 18:56:35 +04:00
|
|
|
#endif
|
|
|
|
if (false) {} // dummy if to take care of the dangling else
|
|
|
|
|
|
|
|
return decoderReader;
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
/* static */
|
|
|
|
bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
|
|
|
|
{
|
2014-08-28 07:33:14 +04:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
return
|
2016-08-04 10:14:28 +03:00
|
|
|
IsOggSupportedType(aType) ||
|
2013-05-03 01:21:22 +04:00
|
|
|
#ifdef MOZ_OMX_DECODER
|
2014-12-23 05:20:25 +03:00
|
|
|
// 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.
|
2014-09-16 12:07:15 +04:00
|
|
|
(IsOmxSupportedType(aType) &&
|
2014-12-23 05:20:25 +03:00
|
|
|
!IsB2GSupportOnlyType(aType)) ||
|
2013-03-05 18:56:35 +04:00
|
|
|
#endif
|
2015-12-03 09:36:36 +03:00
|
|
|
IsWebMSupportedType(aType) ||
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
(MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(aType)) ||
|
2013-03-05 18:56:35 +04:00
|
|
|
#endif
|
2013-11-21 01:04:33 +04:00
|
|
|
#ifdef MOZ_FMP4
|
2016-04-19 10:36:19 +03:00
|
|
|
IsMP4SupportedType(aType, /* DecoderDoctorDiagnostics* */ nullptr) ||
|
2013-11-21 01:04:33 +04:00
|
|
|
#endif
|
2015-06-05 16:53:31 +03:00
|
|
|
IsMP3SupportedType(aType) ||
|
2015-11-27 07:40:36 +03:00
|
|
|
IsAACSupportedType(aType) ||
|
2016-08-17 08:45:06 +03:00
|
|
|
IsFlacSupportedType(aType) ||
|
2013-08-13 08:49:25 +04:00
|
|
|
#ifdef MOZ_DIRECTSHOW
|
|
|
|
IsDirectShowSupportedType(aType) ||
|
2013-03-05 18:56:35 +04:00
|
|
|
#endif
|
|
|
|
false;
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|