content/media/DecoderTraits.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/DecoderTraits.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,679 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "DecoderTraits.h"
    1.11 +#include "MediaDecoder.h"
    1.12 +#include "nsCharSeparatedTokenizer.h"
    1.13 +#include "mozilla/Preferences.h"
    1.14 +
    1.15 +#ifdef MOZ_MEDIA_PLUGINS
    1.16 +#include "MediaPluginHost.h"
    1.17 +#endif
    1.18 +
    1.19 +#include "OggDecoder.h"
    1.20 +#include "OggReader.h"
    1.21 +#ifdef MOZ_WAVE
    1.22 +#include "WaveDecoder.h"
    1.23 +#include "WaveReader.h"
    1.24 +#endif
    1.25 +#ifdef MOZ_WEBM
    1.26 +#include "WebMDecoder.h"
    1.27 +#include "WebMReader.h"
    1.28 +#endif
    1.29 +#ifdef MOZ_RAW
    1.30 +#include "RawDecoder.h"
    1.31 +#include "RawReader.h"
    1.32 +#endif
    1.33 +#ifdef MOZ_GSTREAMER
    1.34 +#include "GStreamerDecoder.h"
    1.35 +#include "GStreamerReader.h"
    1.36 +#endif
    1.37 +#ifdef MOZ_MEDIA_PLUGINS
    1.38 +#include "MediaPluginHost.h"
    1.39 +#include "MediaPluginDecoder.h"
    1.40 +#include "MediaPluginReader.h"
    1.41 +#include "MediaPluginHost.h"
    1.42 +#endif
    1.43 +#ifdef MOZ_OMX_DECODER
    1.44 +#include "MediaOmxDecoder.h"
    1.45 +#include "MediaOmxReader.h"
    1.46 +#include "nsIPrincipal.h"
    1.47 +#include "mozilla/dom/HTMLMediaElement.h"
    1.48 +#endif
    1.49 +#ifdef NECKO_PROTOCOL_rtsp
    1.50 +#include "RtspOmxDecoder.h"
    1.51 +#include "RtspOmxReader.h"
    1.52 +#endif
    1.53 +#ifdef MOZ_WMF
    1.54 +#include "WMFDecoder.h"
    1.55 +#include "WMFReader.h"
    1.56 +#endif
    1.57 +#ifdef MOZ_DIRECTSHOW
    1.58 +#include "DirectShowDecoder.h"
    1.59 +#include "DirectShowReader.h"
    1.60 +#endif
    1.61 +#ifdef MOZ_APPLEMEDIA
    1.62 +#include "AppleDecoder.h"
    1.63 +#include "AppleMP3Reader.h"
    1.64 +#endif
    1.65 +#ifdef MOZ_FMP4
    1.66 +#include "MP4Reader.h"
    1.67 +#include "MP4Decoder.h"
    1.68 +#endif
    1.69 +
    1.70 +namespace mozilla
    1.71 +{
    1.72 +
    1.73 +template <class String>
    1.74 +static bool
    1.75 +CodecListContains(char const *const * aCodecs, const String& aCodec)
    1.76 +{
    1.77 +  for (int32_t i = 0; aCodecs[i]; ++i) {
    1.78 +    if (aCodec.EqualsASCII(aCodecs[i]))
    1.79 +      return true;
    1.80 +  }
    1.81 +  return false;
    1.82 +}
    1.83 +
    1.84 +#ifdef MOZ_RAW
    1.85 +static const char* gRawTypes[3] = {
    1.86 +  "video/x-raw",
    1.87 +  "video/x-raw-yuv",
    1.88 +  nullptr
    1.89 +};
    1.90 +
    1.91 +static const char* gRawCodecs[1] = {
    1.92 +  nullptr
    1.93 +};
    1.94 +
    1.95 +static bool
    1.96 +IsRawType(const nsACString& aType)
    1.97 +{
    1.98 +  if (!MediaDecoder::IsRawEnabled()) {
    1.99 +    return false;
   1.100 +  }
   1.101 +
   1.102 +  return CodecListContains(gRawTypes, aType);
   1.103 +}
   1.104 +#endif
   1.105 +
   1.106 +// See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
   1.107 +// of Ogg media types and codec types
   1.108 +static const char* const gOggTypes[4] = {
   1.109 +  "video/ogg",
   1.110 +  "audio/ogg",
   1.111 +  "application/ogg",
   1.112 +  nullptr
   1.113 +};
   1.114 +
   1.115 +static char const *const gOggCodecs[3] = {
   1.116 +  "vorbis",
   1.117 +  "theora",
   1.118 +  nullptr
   1.119 +};
   1.120 +
   1.121 +static char const *const gOggCodecsWithOpus[4] = {
   1.122 +  "vorbis",
   1.123 +  "opus",
   1.124 +  "theora",
   1.125 +  nullptr
   1.126 +};
   1.127 +
   1.128 +static bool
   1.129 +IsOggType(const nsACString& aType)
   1.130 +{
   1.131 +  if (!MediaDecoder::IsOggEnabled()) {
   1.132 +    return false;
   1.133 +  }
   1.134 +
   1.135 +  return CodecListContains(gOggTypes, aType);
   1.136 +}
   1.137 +
   1.138 +#ifdef MOZ_WAVE
   1.139 +// See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
   1.140 +// of WAVE media types and codec types. However, the audio/vnd.wave
   1.141 +// MIME type described there is not used.
   1.142 +static const char* const gWaveTypes[5] = {
   1.143 +  "audio/x-wav",
   1.144 +  "audio/wav",
   1.145 +  "audio/wave",
   1.146 +  "audio/x-pn-wav",
   1.147 +  nullptr
   1.148 +};
   1.149 +
   1.150 +static char const *const gWaveCodecs[2] = {
   1.151 +  "1", // Microsoft PCM Format
   1.152 +  nullptr
   1.153 +};
   1.154 +
   1.155 +static bool
   1.156 +IsWaveType(const nsACString& aType)
   1.157 +{
   1.158 +  if (!MediaDecoder::IsWaveEnabled()) {
   1.159 +    return false;
   1.160 +  }
   1.161 +
   1.162 +  return CodecListContains(gWaveTypes, aType);
   1.163 +}
   1.164 +#endif
   1.165 +
   1.166 +#ifdef MOZ_WEBM
   1.167 +static const char* const gWebMTypes[3] = {
   1.168 +  "video/webm",
   1.169 +  "audio/webm",
   1.170 +  nullptr
   1.171 +};
   1.172 +
   1.173 +static char const *const gWebMCodecs[7] = {
   1.174 +  "vp8",
   1.175 +  "vp8.0",
   1.176 +  "vp9",
   1.177 +  "vp9.0",
   1.178 +  "vorbis",
   1.179 +  "opus",
   1.180 +  nullptr
   1.181 +};
   1.182 +
   1.183 +static bool
   1.184 +IsWebMType(const nsACString& aType)
   1.185 +{
   1.186 +  if (!MediaDecoder::IsWebMEnabled()) {
   1.187 +    return false;
   1.188 +  }
   1.189 +
   1.190 +  return CodecListContains(gWebMTypes, aType);
   1.191 +}
   1.192 +#endif
   1.193 +
   1.194 +#ifdef MOZ_GSTREAMER
   1.195 +static bool
   1.196 +IsGStreamerSupportedType(const nsACString& aMimeType)
   1.197 +{
   1.198 +  if (!MediaDecoder::IsGStreamerEnabled())
   1.199 +    return false;
   1.200 +
   1.201 +#ifdef MOZ_WEBM
   1.202 +  if (IsWebMType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
   1.203 +    return false;
   1.204 +#endif
   1.205 +  if (IsOggType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
   1.206 +    return false;
   1.207 +
   1.208 +  return GStreamerDecoder::CanHandleMediaType(aMimeType, nullptr);
   1.209 +}
   1.210 +#endif
   1.211 +
   1.212 +#ifdef MOZ_OMX_DECODER
   1.213 +static const char* const gOmxTypes[7] = {
   1.214 +  "audio/mpeg",
   1.215 +  "audio/mp4",
   1.216 +  "audio/amr",
   1.217 +  "video/mp4",
   1.218 +  "video/3gpp",
   1.219 +  "video/quicktime",
   1.220 +  nullptr
   1.221 +};
   1.222 +
   1.223 +static bool
   1.224 +IsOmxSupportedType(const nsACString& aType)
   1.225 +{
   1.226 +  if (!MediaDecoder::IsOmxEnabled()) {
   1.227 +    return false;
   1.228 +  }
   1.229 +
   1.230 +  return CodecListContains(gOmxTypes, aType);
   1.231 +}
   1.232 +
   1.233 +static char const *const gH264Codecs[9] = {
   1.234 +  "avc1.42E01E",  // H.264 Constrained Baseline Profile Level 3.0
   1.235 +  "avc1.42001E",  // H.264 Baseline Profile Level 3.0
   1.236 +  "avc1.58A01E",  // H.264 Extended Profile Level 3.0
   1.237 +  "avc1.4D401E",  // H.264 Main Profile Level 3.0
   1.238 +  "avc1.64001E",  // H.264 High Profile Level 3.0
   1.239 +  "avc1.64001F",  // H.264 High Profile Level 3.1
   1.240 +  "mp4v.20.3",    // 3GPP
   1.241 +  "mp4a.40.2",    // AAC-LC
   1.242 +  nullptr
   1.243 +};
   1.244 +
   1.245 +static char const *const gMpegAudioCodecs[2] = {
   1.246 +  "mp3",          // MP3
   1.247 +  nullptr
   1.248 +};
   1.249 +#endif
   1.250 +
   1.251 +#ifdef NECKO_PROTOCOL_rtsp
   1.252 +static const char* const gRtspTypes[2] = {
   1.253 +    "RTSP",
   1.254 +    nullptr
   1.255 +};
   1.256 +
   1.257 +static bool
   1.258 +IsRtspSupportedType(const nsACString& aMimeType)
   1.259 +{
   1.260 +  return MediaDecoder::IsRtspEnabled() &&
   1.261 +    CodecListContains(gRtspTypes, aMimeType);
   1.262 +}
   1.263 +#endif
   1.264 +
   1.265 +/* static */
   1.266 +bool DecoderTraits::DecoderWaitsForOnConnected(const nsACString& aMimeType) {
   1.267 +#ifdef NECKO_PROTOCOL_rtsp
   1.268 +  return CodecListContains(gRtspTypes, aMimeType);
   1.269 +#else
   1.270 +  return false;
   1.271 +#endif
   1.272 +}
   1.273 +
   1.274 +#ifdef MOZ_MEDIA_PLUGINS
   1.275 +static bool
   1.276 +IsMediaPluginsType(const nsACString& aType)
   1.277 +{
   1.278 +  if (!MediaDecoder::IsMediaPluginsEnabled()) {
   1.279 +    return false;
   1.280 +  }
   1.281 +
   1.282 +  static const char* supportedTypes[] = {
   1.283 +    "audio/mpeg", "audio/mp4", "video/mp4", nullptr
   1.284 +  };
   1.285 +  return CodecListContains(supportedTypes, aType);
   1.286 +}
   1.287 +#endif
   1.288 +
   1.289 +#ifdef MOZ_WMF
   1.290 +static bool
   1.291 +IsWMFSupportedType(const nsACString& aType)
   1.292 +{
   1.293 +  return WMFDecoder::CanPlayType(aType, NS_LITERAL_STRING(""));
   1.294 +}
   1.295 +#endif
   1.296 +
   1.297 +#ifdef MOZ_DIRECTSHOW
   1.298 +static bool
   1.299 +IsDirectShowSupportedType(const nsACString& aType)
   1.300 +{
   1.301 +  return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
   1.302 +}
   1.303 +#endif
   1.304 +
   1.305 +#ifdef MOZ_FMP4
   1.306 +static bool
   1.307 +IsMP4SupportedType(const nsACString& aType)
   1.308 +{
   1.309 +  return Preferences::GetBool("media.fragmented-mp4.exposed", false) &&
   1.310 +         MP4Decoder::GetSupportedCodecs(aType, nullptr);
   1.311 +}
   1.312 +#endif
   1.313 +
   1.314 +#ifdef MOZ_APPLEMEDIA
   1.315 +static const char * const gAppleMP3Types[] = {
   1.316 +  "audio/mp3",
   1.317 +  "audio/mpeg",
   1.318 +  nullptr,
   1.319 +};
   1.320 +
   1.321 +static const char * const gAppleMP3Codecs[] = {
   1.322 +  "mp3",
   1.323 +  nullptr
   1.324 +};
   1.325 +
   1.326 +static bool
   1.327 +IsAppleMediaSupportedType(const nsACString& aType,
   1.328 +                     const char * const ** aCodecs = nullptr)
   1.329 +{
   1.330 +  if (MediaDecoder::IsAppleMP3Enabled()
   1.331 +      && CodecListContains(gAppleMP3Types, aType)) {
   1.332 +
   1.333 +    if (aCodecs) {
   1.334 +      *aCodecs = gAppleMP3Codecs;
   1.335 +    }
   1.336 +
   1.337 +    return true;
   1.338 +  }
   1.339 +
   1.340 +  // TODO MP4
   1.341 +
   1.342 +  return false;
   1.343 +}
   1.344 +#endif
   1.345 +
   1.346 +/* static */
   1.347 +bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType)
   1.348 +{
   1.349 +#ifdef MOZ_WAVE
   1.350 +  if (IsWaveType(nsDependentCString(aMIMEType))) {
   1.351 +    // We should not return true for Wave types, since there are some
   1.352 +    // Wave codecs actually in use in the wild that we don't support, and
   1.353 +    // we should allow those to be handled by plugins or helper apps.
   1.354 +    // Furthermore people can play Wave files on most platforms by other
   1.355 +    // means.
   1.356 +    return false;
   1.357 +  }
   1.358 +#endif
   1.359 +  return CanHandleMediaType(aMIMEType, false, EmptyString()) != CANPLAY_NO;
   1.360 +}
   1.361 +
   1.362 +/* static */
   1.363 +CanPlayStatus
   1.364 +DecoderTraits::CanHandleMediaType(const char* aMIMEType,
   1.365 +                                  bool aHaveRequestedCodecs,
   1.366 +                                  const nsAString& aRequestedCodecs)
   1.367 +{
   1.368 +  char const* const* codecList = nullptr;
   1.369 +  CanPlayStatus result = CANPLAY_NO;
   1.370 +#ifdef MOZ_RAW
   1.371 +  if (IsRawType(nsDependentCString(aMIMEType))) {
   1.372 +    codecList = gRawCodecs;
   1.373 +    result = CANPLAY_MAYBE;
   1.374 +  }
   1.375 +#endif
   1.376 +  if (IsOggType(nsDependentCString(aMIMEType))) {
   1.377 +    codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
   1.378 +    result = CANPLAY_MAYBE;
   1.379 +  }
   1.380 +#ifdef MOZ_WAVE
   1.381 +  if (IsWaveType(nsDependentCString(aMIMEType))) {
   1.382 +    codecList = gWaveCodecs;
   1.383 +    result = CANPLAY_MAYBE;
   1.384 +  }
   1.385 +#endif
   1.386 +#ifdef MOZ_WEBM
   1.387 +  if (IsWebMType(nsDependentCString(aMIMEType))) {
   1.388 +    codecList = gWebMCodecs;
   1.389 +    result = CANPLAY_MAYBE;
   1.390 +  }
   1.391 +#endif
   1.392 +#ifdef MOZ_GSTREAMER
   1.393 +  if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType),
   1.394 +                                           aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) {
   1.395 +    if (aHaveRequestedCodecs)
   1.396 +      return CANPLAY_YES;
   1.397 +    return CANPLAY_MAYBE;
   1.398 +  }
   1.399 +#endif
   1.400 +#ifdef MOZ_OMX_DECODER
   1.401 +  if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
   1.402 +    result = CANPLAY_MAYBE;
   1.403 +    if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
   1.404 +      codecList = gMpegAudioCodecs;
   1.405 +    } else {
   1.406 +      codecList = gH264Codecs;
   1.407 +    }
   1.408 +  }
   1.409 +#endif
   1.410 +#ifdef MOZ_DIRECTSHOW
   1.411 +  // Note: DirectShow should come before WMF, so that we prefer DirectShow's
   1.412 +  // MP3 support over WMF's.
   1.413 +  if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
   1.414 +    result = CANPLAY_MAYBE;
   1.415 +  }
   1.416 +#endif
   1.417 +#ifdef MOZ_WMF
   1.418 +  if (IsWMFSupportedType(nsDependentCString(aMIMEType))) {
   1.419 +    if (!aHaveRequestedCodecs) {
   1.420 +      return CANPLAY_MAYBE;
   1.421 +    }
   1.422 +    return WMFDecoder::CanPlayType(nsDependentCString(aMIMEType),
   1.423 +                                   aRequestedCodecs)
   1.424 +           ? CANPLAY_YES : CANPLAY_NO;
   1.425 +  }
   1.426 +#endif
   1.427 +#ifdef MOZ_APPLEMEDIA
   1.428 +  if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) {
   1.429 +    result = CANPLAY_MAYBE;
   1.430 +  }
   1.431 +#endif
   1.432 +#ifdef MOZ_MEDIA_PLUGINS
   1.433 +  if (MediaDecoder::IsMediaPluginsEnabled() &&
   1.434 +      GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList))
   1.435 +    result = CANPLAY_MAYBE;
   1.436 +#endif
   1.437 +#ifdef NECKO_PROTOCOL_rtsp
   1.438 +  if (IsRtspSupportedType(nsDependentCString(aMIMEType))) {
   1.439 +    result = CANPLAY_MAYBE;
   1.440 +  }
   1.441 +#endif
   1.442 +  if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) {
   1.443 +    return result;
   1.444 +  }
   1.445 +
   1.446 +  // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
   1.447 +  // of the 'codecs' parameter
   1.448 +  nsCharSeparatedTokenizer tokenizer(aRequestedCodecs, ',');
   1.449 +  bool expectMoreTokens = false;
   1.450 +  while (tokenizer.hasMoreTokens()) {
   1.451 +    const nsSubstring& token = tokenizer.nextToken();
   1.452 +
   1.453 +    if (!CodecListContains(codecList, token)) {
   1.454 +      // Totally unsupported codec
   1.455 +      return CANPLAY_NO;
   1.456 +    }
   1.457 +    expectMoreTokens = tokenizer.separatorAfterCurrentToken();
   1.458 +  }
   1.459 +  if (expectMoreTokens) {
   1.460 +    // Last codec name was empty
   1.461 +    return CANPLAY_NO;
   1.462 +  }
   1.463 +  return CANPLAY_YES;
   1.464 +}
   1.465 +
   1.466 +// Instantiates but does not initialize decoder.
   1.467 +static
   1.468 +already_AddRefed<MediaDecoder>
   1.469 +InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
   1.470 +{
   1.471 +  nsRefPtr<MediaDecoder> decoder;
   1.472 +
   1.473 +#ifdef MOZ_GSTREAMER
   1.474 +  if (IsGStreamerSupportedType(aType)) {
   1.475 +    decoder = new GStreamerDecoder();
   1.476 +    return decoder.forget();
   1.477 +  }
   1.478 +#endif
   1.479 +#ifdef MOZ_RAW
   1.480 +  if (IsRawType(aType)) {
   1.481 +    decoder = new RawDecoder();
   1.482 +    return decoder.forget();
   1.483 +  }
   1.484 +#endif
   1.485 +  if (IsOggType(aType)) {
   1.486 +    decoder = new OggDecoder();
   1.487 +    return decoder.forget();
   1.488 +  }
   1.489 +#ifdef MOZ_WAVE
   1.490 +  if (IsWaveType(aType)) {
   1.491 +    decoder = new WaveDecoder();
   1.492 +    return decoder.forget();
   1.493 +  }
   1.494 +#endif
   1.495 +#ifdef MOZ_OMX_DECODER
   1.496 +  if (IsOmxSupportedType(aType)) {
   1.497 +    // AMR audio is enabled for MMS, but we are discouraging Web and App
   1.498 +    // developers from using AMR, thus we only allow AMR to be played on WebApps.
   1.499 +    if (aType.EqualsASCII("audio/amr")) {
   1.500 +      dom::HTMLMediaElement* element = aOwner->GetMediaElement();
   1.501 +      if (!element) {
   1.502 +        return nullptr;
   1.503 +      }
   1.504 +      nsIPrincipal* principal = element->NodePrincipal();
   1.505 +      if (!principal) {
   1.506 +        return nullptr;
   1.507 +      }
   1.508 +      if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
   1.509 +        return nullptr;
   1.510 +      }
   1.511 +    }
   1.512 +    decoder = new MediaOmxDecoder();
   1.513 +    return decoder.forget();
   1.514 +  }
   1.515 +#endif
   1.516 +#ifdef NECKO_PROTOCOL_rtsp
   1.517 +  if (IsRtspSupportedType(aType)) {
   1.518 +    decoder = new RtspOmxDecoder();
   1.519 +    return decoder.forget();
   1.520 +  }
   1.521 +#endif
   1.522 +#ifdef MOZ_MEDIA_PLUGINS
   1.523 +  if (MediaDecoder::IsMediaPluginsEnabled() &&
   1.524 +      GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
   1.525 +    decoder = new MediaPluginDecoder(aType);
   1.526 +    return decoder.forget();
   1.527 +  }
   1.528 +#endif
   1.529 +#ifdef MOZ_WEBM
   1.530 +  if (IsWebMType(aType)) {
   1.531 +    decoder = new WebMDecoder();
   1.532 +    return decoder.forget();
   1.533 +  }
   1.534 +#endif
   1.535 +#ifdef MOZ_DIRECTSHOW
   1.536 +  // Note: DirectShow should come before WMF, so that we prefer DirectShow's
   1.537 +  // MP3 support over WMF's.
   1.538 +  if (IsDirectShowSupportedType(aType)) {
   1.539 +    decoder = new DirectShowDecoder();
   1.540 +    return decoder.forget();
   1.541 +  }
   1.542 +#endif
   1.543 +#ifdef MOZ_FMP4
   1.544 +  if (IsMP4SupportedType(aType)) {
   1.545 +    decoder = new MP4Decoder();
   1.546 +    return decoder.forget();
   1.547 +  }
   1.548 +#endif
   1.549 +#ifdef MOZ_WMF
   1.550 +  if (IsWMFSupportedType(aType)) {
   1.551 +    decoder = new WMFDecoder();
   1.552 +    return decoder.forget();
   1.553 +  }
   1.554 +#endif
   1.555 +#ifdef MOZ_APPLEMEDIA
   1.556 +  if (IsAppleMediaSupportedType(aType)) {
   1.557 +    decoder = new AppleDecoder();
   1.558 +    return decoder.forget();
   1.559 +  }
   1.560 +#endif
   1.561 +
   1.562 +  NS_ENSURE_TRUE(decoder != nullptr, nullptr);
   1.563 +  NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
   1.564 +  return nullptr;
   1.565 +}
   1.566 +
   1.567 +/* static */
   1.568 +already_AddRefed<MediaDecoder>
   1.569 +DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
   1.570 +{
   1.571 +  nsRefPtr<MediaDecoder> decoder(InstantiateDecoder(aType, aOwner));
   1.572 +  NS_ENSURE_TRUE(decoder != nullptr, nullptr);
   1.573 +  NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
   1.574 +
   1.575 +  return decoder.forget();
   1.576 +}
   1.577 +
   1.578 +/* static */
   1.579 +MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
   1.580 +{
   1.581 +  MediaDecoderReader* decoderReader = nullptr;
   1.582 +
   1.583 +#ifdef MOZ_GSTREAMER
   1.584 +  if (IsGStreamerSupportedType(aType)) {
   1.585 +    decoderReader = new GStreamerReader(aDecoder);
   1.586 +  } else
   1.587 +#endif
   1.588 +#ifdef MOZ_RAW
   1.589 +  if (IsRawType(aType)) {
   1.590 +    decoderReader = new RawReader(aDecoder);
   1.591 +  } else
   1.592 +#endif
   1.593 +  if (IsOggType(aType)) {
   1.594 +    decoderReader = new OggReader(aDecoder);
   1.595 +  } else
   1.596 +#ifdef MOZ_WAVE
   1.597 +  if (IsWaveType(aType)) {
   1.598 +    decoderReader = new WaveReader(aDecoder);
   1.599 +  } else
   1.600 +#endif
   1.601 +#ifdef MOZ_OMX_DECODER
   1.602 +  if (IsOmxSupportedType(aType)) {
   1.603 +    decoderReader = new MediaOmxReader(aDecoder);
   1.604 +  } else
   1.605 +#endif
   1.606 +#ifdef MOZ_MEDIA_PLUGINS
   1.607 +  if (MediaDecoder::IsMediaPluginsEnabled() &&
   1.608 +      GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
   1.609 +    decoderReader = new MediaPluginReader(aDecoder, aType);
   1.610 +  } else
   1.611 +#endif
   1.612 +#ifdef MOZ_WEBM
   1.613 +  if (IsWebMType(aType)) {
   1.614 +    decoderReader = new WebMReader(aDecoder);
   1.615 +  } else
   1.616 +#endif
   1.617 +#ifdef MOZ_DIRECTSHOW
   1.618 +  // Note: DirectShowReader is preferred for MP3, but if it's disabled we
   1.619 +  // fallback to the WMFReader.
   1.620 +  if (IsDirectShowSupportedType(aType)) {
   1.621 +    decoderReader = new DirectShowReader(aDecoder);
   1.622 +  } else
   1.623 +#endif
   1.624 +#ifdef MOZ_FMP4
   1.625 +  if (IsMP4SupportedType(aType)) {
   1.626 +    decoderReader = new MP4Reader(aDecoder);
   1.627 +  } else
   1.628 +#endif
   1.629 +#ifdef MOZ_WMF
   1.630 +  if (IsWMFSupportedType(aType)) {
   1.631 +    decoderReader = new WMFReader(aDecoder);
   1.632 +  } else
   1.633 +#endif
   1.634 +#ifdef MOZ_APPLEMEDIA
   1.635 +  if (IsAppleMediaSupportedType(aType)) {
   1.636 +    decoderReader = new AppleMP3Reader(aDecoder);
   1.637 +  } else
   1.638 +#endif
   1.639 +  if (false) {} // dummy if to take care of the dangling else
   1.640 +
   1.641 +  return decoderReader;
   1.642 +}
   1.643 +
   1.644 +/* static */
   1.645 +bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
   1.646 +{
   1.647 +  return
   1.648 +    IsOggType(aType) ||
   1.649 +#ifdef MOZ_OMX_DECODER
   1.650 +    // We support amr inside WebApps on firefoxOS but not in general web content.
   1.651 +    // Ensure we dont create a VideoDocument when accessing amr URLs directly.
   1.652 +    (IsOmxSupportedType(aType) && !aType.EqualsASCII("audio/amr")) ||
   1.653 +#endif
   1.654 +#ifdef MOZ_WEBM
   1.655 +    IsWebMType(aType) ||
   1.656 +#endif
   1.657 +#ifdef MOZ_GSTREAMER
   1.658 +    IsGStreamerSupportedType(aType) ||
   1.659 +#endif
   1.660 +#ifdef MOZ_MEDIA_PLUGINS
   1.661 +    (MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) ||
   1.662 +#endif
   1.663 +#ifdef MOZ_FMP4
   1.664 +    IsMP4SupportedType(aType) ||
   1.665 +#endif
   1.666 +#ifdef MOZ_WMF
   1.667 +    (IsWMFSupportedType(aType) &&
   1.668 +     Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true)) ||
   1.669 +#endif
   1.670 +#ifdef MOZ_DIRECTSHOW
   1.671 +    IsDirectShowSupportedType(aType) ||
   1.672 +#endif
   1.673 +#ifdef MOZ_APPLEMEDIA
   1.674 +    IsAppleMediaSupportedType(aType) ||
   1.675 +#endif
   1.676 +#ifdef NECKO_PROTOCOL_rtsp
   1.677 +    IsRtspSupportedType(aType) ||
   1.678 +#endif
   1.679 +    false;
   1.680 +}
   1.681 +
   1.682 +}

mercurial