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"
|
2017-01-18 03:59:03 +03:00
|
|
|
#include "MediaContainerType.h"
|
2012-11-22 07:10:41 +04:00
|
|
|
#include "MediaDecoder.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"
|
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-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"
|
|
|
|
|
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
|
|
|
|
{
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2013-03-05 18:56:35 +04:00
|
|
|
static bool
|
2017-01-18 03:59:03 +03:00
|
|
|
IsAndroidMediaType(const MediaContainerType& 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;
|
|
|
|
}
|
|
|
|
|
2016-12-22 04:43:19 +03:00
|
|
|
return aType.Type() == MEDIAMIMETYPE("audio/mpeg")
|
|
|
|
|| aType.Type() == MEDIAMIMETYPE("audio/mp4")
|
|
|
|
|| aType.Type() == MEDIAMIMETYPE("video/mp4")
|
|
|
|
|| aType.Type() == MEDIAMIMETYPE("video/x-m4v");
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-18 09:47:55 +03:00
|
|
|
|
|
|
|
/* static */ bool
|
|
|
|
DecoderTraits::IsHttpLiveStreamingType(const MediaContainerType& aType)
|
|
|
|
{
|
|
|
|
return // For m3u8.
|
|
|
|
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-19#section-10
|
|
|
|
aType.Type() == MEDIAMIMETYPE("application/vnd.apple.mpegurl")
|
|
|
|
// Some sites serve these as the informal m3u type.
|
|
|
|
|| aType.Type() == MEDIAMIMETYPE("application/x-mpegurl")
|
|
|
|
|| aType.Type() == MEDIAMIMETYPE("audio/x-mpegurl");
|
|
|
|
}
|
|
|
|
|
2015-07-21 07:01:07 +03:00
|
|
|
/* static */ bool
|
2017-01-18 03:59:03 +03:00
|
|
|
DecoderTraits::IsMP4SupportedType(const MediaContainerType& aType,
|
2017-01-01 04:27:45 +03:00
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-07-21 07:01:07 +03:00
|
|
|
{
|
|
|
|
#ifdef MOZ_FMP4
|
2017-01-01 04:27:45 +03:00
|
|
|
return MP4Decoder::IsSupportedType(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
|
|
|
}
|
|
|
|
|
2016-09-26 09:01:59 +03:00
|
|
|
static
|
2012-11-22 07:10:41 +04:00
|
|
|
CanPlayStatus
|
2017-01-18 03:59:03 +03:00
|
|
|
CanHandleCodecsType(const MediaContainerType& aType,
|
2016-09-26 09:01:59 +03:00
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2012-11-22 07:10:41 +04:00
|
|
|
{
|
2016-10-01 11:09:50 +03:00
|
|
|
// We should have been given a codecs string, though it may be empty.
|
2017-01-01 01:24:24 +03:00
|
|
|
MOZ_ASSERT(aType.ExtendedType().HaveCodecs());
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
// Container type with the MIME type, no codecs.
|
|
|
|
const MediaContainerType mimeType(aType.Type());
|
2016-10-01 11:09:50 +03:00
|
|
|
|
2017-01-01 04:08:36 +03:00
|
|
|
if (OggDecoder::IsSupportedType(mimeType)) {
|
|
|
|
if (OggDecoder::IsSupportedType(aType)) {
|
2016-08-04 10:14:28 +03:00
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2017-02-09 12:32:18 +03:00
|
|
|
// 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
|
|
|
}
|
2017-01-18 03:59:03 +03:00
|
|
|
if (WaveDecoder::IsSupportedType(MediaContainerType(mimeType))) {
|
2016-12-20 11:09:41 +03:00
|
|
|
if (WaveDecoder::IsSupportedType(aType)) {
|
2016-11-09 05:08:56 +03:00
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2017-02-09 12:32:18 +03:00
|
|
|
// 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
|
|
|
}
|
2015-07-21 07:01:07 +03:00
|
|
|
#if !defined(MOZ_OMX_WEBM_DECODER)
|
2017-01-01 04:16:38 +03:00
|
|
|
if (WebMDecoder::IsSupportedType(mimeType)) {
|
|
|
|
if (WebMDecoder::IsSupportedType(aType)) {
|
2015-12-03 09:36:36 +03:00
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2017-02-09 12:32:18 +03:00
|
|
|
// 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
|
2017-01-01 04:27:45 +03:00
|
|
|
if (MP4Decoder::IsSupportedType(mimeType,
|
|
|
|
/* DecoderDoctorDiagnostics* */ nullptr)) {
|
|
|
|
if (MP4Decoder::IsSupportedType(aType, aDiagnostics)) {
|
2013-03-14 00:10:47 +04:00
|
|
|
return CANPLAY_YES;
|
2015-07-21 07:01:07 +03:00
|
|
|
}
|
2017-02-09 12:32:18 +03:00
|
|
|
// 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
|
2017-01-01 04:34:12 +03:00
|
|
|
if (MP3Decoder::IsSupportedType(aType)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2016-12-20 10:57:26 +03:00
|
|
|
if (ADTSDecoder::IsSupportedType(aType)) {
|
2015-11-27 07:40:36 +03:00
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2016-12-20 11:24:17 +03:00
|
|
|
if (FlacDecoder::IsSupportedType(aType)) {
|
2016-08-17 08:45:06 +03:00
|
|
|
return CANPLAY_YES;
|
|
|
|
}
|
2016-12-23 00:43:49 +03:00
|
|
|
|
|
|
|
MediaCodecs supportedCodecs;
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled()) {
|
2016-12-23 00:43:49 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(aType, &supportedCodecs);
|
2014-01-20 14:54:33 +04:00
|
|
|
}
|
2012-11-22 07:10:41 +04:00
|
|
|
#endif
|
2016-12-23 00:43:49 +03:00
|
|
|
if (supportedCodecs.IsEmpty()) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
2012-11-22 22:49:37 +04:00
|
|
|
}
|
|
|
|
|
2016-12-23 00:43:49 +03:00
|
|
|
if (!supportedCodecs.ContainsAll(aType.ExtendedType().Codecs())) {
|
|
|
|
// At least one requested codec is not supported.
|
|
|
|
return CANPLAY_NO;
|
2012-11-22 22:49:37 +04:00
|
|
|
}
|
|
|
|
return CANPLAY_YES;
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
2016-09-26 09:01:59 +03:00
|
|
|
static
|
2015-07-21 07:01:07 +03:00
|
|
|
CanPlayStatus
|
2017-01-18 03:59:03 +03:00
|
|
|
CanHandleMediaType(const MediaContainerType& aType,
|
2016-09-26 09:01:59 +03:00
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2015-07-21 07:01:07 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
2017-05-18 09:47:55 +03:00
|
|
|
if (DecoderTraits::IsHttpLiveStreamingType(aType)) {
|
2016-04-12 00:13:43 +03:00
|
|
|
Telemetry::Accumulate(Telemetry::MEDIA_HLS_CANPLAY_REQUESTED, true);
|
|
|
|
}
|
|
|
|
|
2017-01-01 01:24:24 +03:00
|
|
|
if (aType.ExtendedType().HaveCodecs()) {
|
2016-10-01 11:09:50 +03:00
|
|
|
CanPlayStatus result = CanHandleCodecsType(aType, aDiagnostics);
|
2015-07-21 07:01:07 +03:00
|
|
|
if (result == CANPLAY_NO || result == CANPLAY_YES) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2017-01-01 01:24:24 +03:00
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
// Container type with just the MIME type/subtype, no codecs.
|
|
|
|
const MediaContainerType mimeType(aType.Type());
|
2017-01-01 01:24:24 +03:00
|
|
|
|
2017-01-01 04:08:36 +03:00
|
|
|
if (OggDecoder::IsSupportedType(mimeType)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2016-12-20 11:09:41 +03:00
|
|
|
if (WaveDecoder::IsSupportedType(mimeType)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2017-01-01 04:27:45 +03:00
|
|
|
#ifdef MOZ_FMP4
|
|
|
|
if (MP4Decoder::IsSupportedType(mimeType, aDiagnostics)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2017-01-01 04:27:45 +03:00
|
|
|
#endif
|
2015-07-21 07:01:07 +03:00
|
|
|
#if !defined(MOZ_OMX_WEBM_DECODER)
|
2017-01-01 04:16:38 +03:00
|
|
|
if (WebMDecoder::IsSupportedType(mimeType)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-01 04:34:12 +03:00
|
|
|
if (MP3Decoder::IsSupportedType(mimeType)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2016-12-20 10:57:26 +03:00
|
|
|
if (ADTSDecoder::IsSupportedType(mimeType)) {
|
2015-11-27 07:40:36 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2016-12-20 11:24:17 +03:00
|
|
|
if (FlacDecoder::IsSupportedType(mimeType)) {
|
2016-08-17 08:45:06 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
2015-07-21 07:01:07 +03:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
|
2016-12-28 01:51:48 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(mimeType, nullptr)) {
|
2015-07-21 07:01:07 +03:00
|
|
|
return CANPLAY_MAYBE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return CANPLAY_NO;
|
|
|
|
}
|
|
|
|
|
2016-09-26 09:43:16 +03:00
|
|
|
/* static */
|
|
|
|
CanPlayStatus
|
2017-01-18 03:59:03 +03:00
|
|
|
DecoderTraits::CanHandleContainerType(const MediaContainerType& aContainerType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2016-09-26 09:43:16 +03:00
|
|
|
{
|
2017-01-18 03:59:03 +03:00
|
|
|
return CanHandleMediaType(aContainerType, aDiagnostics);
|
2016-09-26 09:43:16 +03:00
|
|
|
}
|
|
|
|
|
2016-09-26 09:02:59 +03:00
|
|
|
/* static */
|
|
|
|
bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType,
|
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
|
|
|
{
|
2017-01-18 03:59:03 +03:00
|
|
|
Maybe<MediaContainerType> containerType = MakeMediaContainerType(aMIMEType);
|
|
|
|
if (!containerType) {
|
2017-01-01 04:01:32 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
if (WaveDecoder::IsSupportedType(*containerType)) {
|
2016-09-26 09:02:59 +03:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2017-01-18 03:59:03 +03:00
|
|
|
if (containerType->Type() == MEDIAMIMETYPE("video/quicktime")) {
|
2016-09-26 09:02:59 +03:00
|
|
|
RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst();
|
|
|
|
if (pluginHost &&
|
2017-01-18 03:59:03 +03:00
|
|
|
pluginHost->HavePluginForType(containerType->Type().AsString())) {
|
2016-09-26 09:02:59 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
return CanHandleMediaType(*containerType, aDiagnostics) != CANPLAY_NO;
|
2016-09-26 09:02:59 +03:00
|
|
|
}
|
|
|
|
|
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>
|
2017-01-18 03:59:03 +03:00
|
|
|
InstantiateDecoder(const MediaContainerType& aType,
|
2017-06-07 07:14:11 +03:00
|
|
|
MediaDecoderInit& aInit,
|
2016-04-19 10:36:19 +03:00
|
|
|
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
|
2017-01-01 04:27:45 +03:00
|
|
|
if (MP4Decoder::IsSupportedType(aType, aDiagnostics)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new MP4Decoder(aInit);
|
2014-06-17 02:32:18 +04:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
|
|
|
#endif
|
2017-01-01 04:34:12 +03:00
|
|
|
if (MP3Decoder::IsSupportedType(aType)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new MP3Decoder(aInit);
|
2015-06-05 16:53:31 +03:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
2016-12-20 10:57:26 +03:00
|
|
|
if (ADTSDecoder::IsSupportedType(aType)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new ADTSDecoder(aInit);
|
2015-11-27 07:40:36 +03:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
2017-01-01 04:08:36 +03:00
|
|
|
if (OggDecoder::IsSupportedType(aType)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new OggDecoder(aInit);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
2016-12-20 11:09:41 +03:00
|
|
|
if (WaveDecoder::IsSupportedType(aType)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new WaveDecoder(aInit);
|
2013-11-21 01:04:33 +04:00
|
|
|
return decoder.forget();
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
2016-12-20 11:24:17 +03:00
|
|
|
if (FlacDecoder::IsSupportedType(aType)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new FlacDecoder(aInit);
|
2016-08-17 08:45:06 +03:00
|
|
|
return decoder.forget();
|
|
|
|
}
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-03-10 01:45:27 +03:00
|
|
|
if (MediaDecoder::IsAndroidMediaPluginEnabled() &&
|
2016-12-28 01:51:48 +03:00
|
|
|
EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new AndroidMediaDecoder(aInit, 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
|
|
|
|
2017-01-01 04:16:38 +03:00
|
|
|
if (WebMDecoder::IsSupportedType(aType)) {
|
2017-06-07 07:14:11 +03:00
|
|
|
decoder = new WebMDecoder(aInit);
|
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
|
|
|
|
2017-05-18 09:47:55 +03:00
|
|
|
if (DecoderTraits::IsHttpLiveStreamingType(aType)) {
|
2016-04-12 00:13:43 +03:00
|
|
|
// 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,
|
2017-06-07 07:14:11 +03:00
|
|
|
MediaDecoderInit& aInit,
|
2016-04-19 10:36:19 +03:00
|
|
|
DecoderDoctorDiagnostics* aDiagnostics)
|
2013-11-21 01:04:33 +04:00
|
|
|
{
|
2015-04-24 21:22:20 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2017-01-18 03:59:03 +03:00
|
|
|
Maybe<MediaContainerType> type = MakeMediaContainerType(aType);
|
2017-01-01 04:01:32 +03:00
|
|
|
if (!type) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-06-07 07:14:11 +03:00
|
|
|
return InstantiateDecoder(*type, aInit, aDiagnostics);
|
2013-03-05 18:56:34 +04:00
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
/* static */
|
2016-12-22 03:57:48 +03:00
|
|
|
MediaDecoderReader*
|
2017-01-18 03:59:03 +03:00
|
|
|
DecoderTraits::CreateReader(const MediaContainerType& aType,
|
2016-12-22 03:57:48 +03:00
|
|
|
AbstractMediaDecoder* aDecoder)
|
2013-03-05 18:56:35 +04:00
|
|
|
{
|
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;
|
|
|
|
}
|
2017-01-01 04:08:36 +03:00
|
|
|
|
2014-06-17 02:32:18 +04:00
|
|
|
#ifdef MOZ_FMP4
|
2016-12-22 03:57:48 +03:00
|
|
|
if (MP4Decoder::IsSupportedType(aType,
|
2017-01-01 04:27:45 +03:00
|
|
|
/* 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
|
2016-12-22 03:57:48 +03:00
|
|
|
if (MP3Decoder::IsSupportedType(aType)) {
|
2015-06-05 16:53:31 +03:00
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-12-22 03:57:48 +03:00
|
|
|
if (ADTSDecoder::IsSupportedType(aType)) {
|
2015-11-27 07:40:36 +03:00
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-12-22 03:57:48 +03:00
|
|
|
if (WaveDecoder::IsSupportedType(aType)) {
|
2016-02-12 04:40:36 +03:00
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-12-22 03:57:48 +03:00
|
|
|
if (FlacDecoder::IsSupportedType(aType)) {
|
2016-08-17 08:45:06 +03:00
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new FlacDemuxer(aDecoder->GetResource()));
|
|
|
|
} else
|
2016-12-22 03:57:48 +03:00
|
|
|
if (OggDecoder::IsSupportedType(aType)) {
|
2016-11-09 03:54:41 +03:00
|
|
|
decoderReader = new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()));
|
2013-03-05 18:56:35 +04:00
|
|
|
} else
|
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)) {
|
2016-12-22 03:57:48 +03:00
|
|
|
decoderReader = new AndroidMediaReader(aDecoder, aType);
|
2013-03-05 18:56:35 +04:00
|
|
|
} else
|
|
|
|
#endif
|
2016-12-22 03:57:48 +03:00
|
|
|
if (WebMDecoder::IsSupportedType(aType)) {
|
2015-12-22 11:38:18 +03:00
|
|
|
decoderReader =
|
|
|
|
new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource()));
|
2017-06-05 13:59:46 +03:00
|
|
|
}
|
2013-03-05 18:56:35 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-01-18 03:59:03 +03:00
|
|
|
Maybe<MediaContainerType> type = MakeMediaContainerType(aType);
|
2017-01-01 04:08:36 +03:00
|
|
|
if (!type) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 18:56:35 +04:00
|
|
|
return
|
2017-01-01 04:08:36 +03:00
|
|
|
OggDecoder::IsSupportedType(*type) ||
|
2017-01-01 04:16:38 +03:00
|
|
|
WebMDecoder::IsSupportedType(*type) ||
|
2014-07-17 05:32:56 +04:00
|
|
|
#ifdef MOZ_ANDROID_OMX
|
2016-12-22 04:43:19 +03:00
|
|
|
(MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(*type)) ||
|
2013-03-05 18:56:35 +04:00
|
|
|
#endif
|
2013-11-21 01:04:33 +04:00
|
|
|
#ifdef MOZ_FMP4
|
2017-01-01 04:27:45 +03:00
|
|
|
MP4Decoder::IsSupportedType(*type, /* DecoderDoctorDiagnostics* */ nullptr) ||
|
2013-11-21 01:04:33 +04:00
|
|
|
#endif
|
2017-01-01 04:34:12 +03:00
|
|
|
MP3Decoder::IsSupportedType(*type) ||
|
2016-12-20 10:57:26 +03:00
|
|
|
ADTSDecoder::IsSupportedType(*type) ||
|
2016-12-20 11:24:17 +03:00
|
|
|
FlacDecoder::IsSupportedType(*type) ||
|
2013-03-05 18:56:35 +04:00
|
|
|
false;
|
2012-11-22 07:10:41 +04:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|