content/media/DecoderTraits.cpp

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #include "DecoderTraits.h"
michael@0 8 #include "MediaDecoder.h"
michael@0 9 #include "nsCharSeparatedTokenizer.h"
michael@0 10 #include "mozilla/Preferences.h"
michael@0 11
michael@0 12 #ifdef MOZ_MEDIA_PLUGINS
michael@0 13 #include "MediaPluginHost.h"
michael@0 14 #endif
michael@0 15
michael@0 16 #include "OggDecoder.h"
michael@0 17 #include "OggReader.h"
michael@0 18 #ifdef MOZ_WAVE
michael@0 19 #include "WaveDecoder.h"
michael@0 20 #include "WaveReader.h"
michael@0 21 #endif
michael@0 22 #ifdef MOZ_WEBM
michael@0 23 #include "WebMDecoder.h"
michael@0 24 #include "WebMReader.h"
michael@0 25 #endif
michael@0 26 #ifdef MOZ_RAW
michael@0 27 #include "RawDecoder.h"
michael@0 28 #include "RawReader.h"
michael@0 29 #endif
michael@0 30 #ifdef MOZ_GSTREAMER
michael@0 31 #include "GStreamerDecoder.h"
michael@0 32 #include "GStreamerReader.h"
michael@0 33 #endif
michael@0 34 #ifdef MOZ_MEDIA_PLUGINS
michael@0 35 #include "MediaPluginHost.h"
michael@0 36 #include "MediaPluginDecoder.h"
michael@0 37 #include "MediaPluginReader.h"
michael@0 38 #include "MediaPluginHost.h"
michael@0 39 #endif
michael@0 40 #ifdef MOZ_OMX_DECODER
michael@0 41 #include "MediaOmxDecoder.h"
michael@0 42 #include "MediaOmxReader.h"
michael@0 43 #include "nsIPrincipal.h"
michael@0 44 #include "mozilla/dom/HTMLMediaElement.h"
michael@0 45 #endif
michael@0 46 #ifdef NECKO_PROTOCOL_rtsp
michael@0 47 #include "RtspOmxDecoder.h"
michael@0 48 #include "RtspOmxReader.h"
michael@0 49 #endif
michael@0 50 #ifdef MOZ_WMF
michael@0 51 #include "WMFDecoder.h"
michael@0 52 #include "WMFReader.h"
michael@0 53 #endif
michael@0 54 #ifdef MOZ_DIRECTSHOW
michael@0 55 #include "DirectShowDecoder.h"
michael@0 56 #include "DirectShowReader.h"
michael@0 57 #endif
michael@0 58 #ifdef MOZ_APPLEMEDIA
michael@0 59 #include "AppleDecoder.h"
michael@0 60 #include "AppleMP3Reader.h"
michael@0 61 #endif
michael@0 62 #ifdef MOZ_FMP4
michael@0 63 #include "MP4Reader.h"
michael@0 64 #include "MP4Decoder.h"
michael@0 65 #endif
michael@0 66
michael@0 67 namespace mozilla
michael@0 68 {
michael@0 69
michael@0 70 template <class String>
michael@0 71 static bool
michael@0 72 CodecListContains(char const *const * aCodecs, const String& aCodec)
michael@0 73 {
michael@0 74 for (int32_t i = 0; aCodecs[i]; ++i) {
michael@0 75 if (aCodec.EqualsASCII(aCodecs[i]))
michael@0 76 return true;
michael@0 77 }
michael@0 78 return false;
michael@0 79 }
michael@0 80
michael@0 81 #ifdef MOZ_RAW
michael@0 82 static const char* gRawTypes[3] = {
michael@0 83 "video/x-raw",
michael@0 84 "video/x-raw-yuv",
michael@0 85 nullptr
michael@0 86 };
michael@0 87
michael@0 88 static const char* gRawCodecs[1] = {
michael@0 89 nullptr
michael@0 90 };
michael@0 91
michael@0 92 static bool
michael@0 93 IsRawType(const nsACString& aType)
michael@0 94 {
michael@0 95 if (!MediaDecoder::IsRawEnabled()) {
michael@0 96 return false;
michael@0 97 }
michael@0 98
michael@0 99 return CodecListContains(gRawTypes, aType);
michael@0 100 }
michael@0 101 #endif
michael@0 102
michael@0 103 // See http://www.rfc-editor.org/rfc/rfc5334.txt for the definitions
michael@0 104 // of Ogg media types and codec types
michael@0 105 static const char* const gOggTypes[4] = {
michael@0 106 "video/ogg",
michael@0 107 "audio/ogg",
michael@0 108 "application/ogg",
michael@0 109 nullptr
michael@0 110 };
michael@0 111
michael@0 112 static char const *const gOggCodecs[3] = {
michael@0 113 "vorbis",
michael@0 114 "theora",
michael@0 115 nullptr
michael@0 116 };
michael@0 117
michael@0 118 static char const *const gOggCodecsWithOpus[4] = {
michael@0 119 "vorbis",
michael@0 120 "opus",
michael@0 121 "theora",
michael@0 122 nullptr
michael@0 123 };
michael@0 124
michael@0 125 static bool
michael@0 126 IsOggType(const nsACString& aType)
michael@0 127 {
michael@0 128 if (!MediaDecoder::IsOggEnabled()) {
michael@0 129 return false;
michael@0 130 }
michael@0 131
michael@0 132 return CodecListContains(gOggTypes, aType);
michael@0 133 }
michael@0 134
michael@0 135 #ifdef MOZ_WAVE
michael@0 136 // See http://www.rfc-editor.org/rfc/rfc2361.txt for the definitions
michael@0 137 // of WAVE media types and codec types. However, the audio/vnd.wave
michael@0 138 // MIME type described there is not used.
michael@0 139 static const char* const gWaveTypes[5] = {
michael@0 140 "audio/x-wav",
michael@0 141 "audio/wav",
michael@0 142 "audio/wave",
michael@0 143 "audio/x-pn-wav",
michael@0 144 nullptr
michael@0 145 };
michael@0 146
michael@0 147 static char const *const gWaveCodecs[2] = {
michael@0 148 "1", // Microsoft PCM Format
michael@0 149 nullptr
michael@0 150 };
michael@0 151
michael@0 152 static bool
michael@0 153 IsWaveType(const nsACString& aType)
michael@0 154 {
michael@0 155 if (!MediaDecoder::IsWaveEnabled()) {
michael@0 156 return false;
michael@0 157 }
michael@0 158
michael@0 159 return CodecListContains(gWaveTypes, aType);
michael@0 160 }
michael@0 161 #endif
michael@0 162
michael@0 163 #ifdef MOZ_WEBM
michael@0 164 static const char* const gWebMTypes[3] = {
michael@0 165 "video/webm",
michael@0 166 "audio/webm",
michael@0 167 nullptr
michael@0 168 };
michael@0 169
michael@0 170 static char const *const gWebMCodecs[7] = {
michael@0 171 "vp8",
michael@0 172 "vp8.0",
michael@0 173 "vp9",
michael@0 174 "vp9.0",
michael@0 175 "vorbis",
michael@0 176 "opus",
michael@0 177 nullptr
michael@0 178 };
michael@0 179
michael@0 180 static bool
michael@0 181 IsWebMType(const nsACString& aType)
michael@0 182 {
michael@0 183 if (!MediaDecoder::IsWebMEnabled()) {
michael@0 184 return false;
michael@0 185 }
michael@0 186
michael@0 187 return CodecListContains(gWebMTypes, aType);
michael@0 188 }
michael@0 189 #endif
michael@0 190
michael@0 191 #ifdef MOZ_GSTREAMER
michael@0 192 static bool
michael@0 193 IsGStreamerSupportedType(const nsACString& aMimeType)
michael@0 194 {
michael@0 195 if (!MediaDecoder::IsGStreamerEnabled())
michael@0 196 return false;
michael@0 197
michael@0 198 #ifdef MOZ_WEBM
michael@0 199 if (IsWebMType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
michael@0 200 return false;
michael@0 201 #endif
michael@0 202 if (IsOggType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false))
michael@0 203 return false;
michael@0 204
michael@0 205 return GStreamerDecoder::CanHandleMediaType(aMimeType, nullptr);
michael@0 206 }
michael@0 207 #endif
michael@0 208
michael@0 209 #ifdef MOZ_OMX_DECODER
michael@0 210 static const char* const gOmxTypes[7] = {
michael@0 211 "audio/mpeg",
michael@0 212 "audio/mp4",
michael@0 213 "audio/amr",
michael@0 214 "video/mp4",
michael@0 215 "video/3gpp",
michael@0 216 "video/quicktime",
michael@0 217 nullptr
michael@0 218 };
michael@0 219
michael@0 220 static bool
michael@0 221 IsOmxSupportedType(const nsACString& aType)
michael@0 222 {
michael@0 223 if (!MediaDecoder::IsOmxEnabled()) {
michael@0 224 return false;
michael@0 225 }
michael@0 226
michael@0 227 return CodecListContains(gOmxTypes, aType);
michael@0 228 }
michael@0 229
michael@0 230 static char const *const gH264Codecs[9] = {
michael@0 231 "avc1.42E01E", // H.264 Constrained Baseline Profile Level 3.0
michael@0 232 "avc1.42001E", // H.264 Baseline Profile Level 3.0
michael@0 233 "avc1.58A01E", // H.264 Extended Profile Level 3.0
michael@0 234 "avc1.4D401E", // H.264 Main Profile Level 3.0
michael@0 235 "avc1.64001E", // H.264 High Profile Level 3.0
michael@0 236 "avc1.64001F", // H.264 High Profile Level 3.1
michael@0 237 "mp4v.20.3", // 3GPP
michael@0 238 "mp4a.40.2", // AAC-LC
michael@0 239 nullptr
michael@0 240 };
michael@0 241
michael@0 242 static char const *const gMpegAudioCodecs[2] = {
michael@0 243 "mp3", // MP3
michael@0 244 nullptr
michael@0 245 };
michael@0 246 #endif
michael@0 247
michael@0 248 #ifdef NECKO_PROTOCOL_rtsp
michael@0 249 static const char* const gRtspTypes[2] = {
michael@0 250 "RTSP",
michael@0 251 nullptr
michael@0 252 };
michael@0 253
michael@0 254 static bool
michael@0 255 IsRtspSupportedType(const nsACString& aMimeType)
michael@0 256 {
michael@0 257 return MediaDecoder::IsRtspEnabled() &&
michael@0 258 CodecListContains(gRtspTypes, aMimeType);
michael@0 259 }
michael@0 260 #endif
michael@0 261
michael@0 262 /* static */
michael@0 263 bool DecoderTraits::DecoderWaitsForOnConnected(const nsACString& aMimeType) {
michael@0 264 #ifdef NECKO_PROTOCOL_rtsp
michael@0 265 return CodecListContains(gRtspTypes, aMimeType);
michael@0 266 #else
michael@0 267 return false;
michael@0 268 #endif
michael@0 269 }
michael@0 270
michael@0 271 #ifdef MOZ_MEDIA_PLUGINS
michael@0 272 static bool
michael@0 273 IsMediaPluginsType(const nsACString& aType)
michael@0 274 {
michael@0 275 if (!MediaDecoder::IsMediaPluginsEnabled()) {
michael@0 276 return false;
michael@0 277 }
michael@0 278
michael@0 279 static const char* supportedTypes[] = {
michael@0 280 "audio/mpeg", "audio/mp4", "video/mp4", nullptr
michael@0 281 };
michael@0 282 return CodecListContains(supportedTypes, aType);
michael@0 283 }
michael@0 284 #endif
michael@0 285
michael@0 286 #ifdef MOZ_WMF
michael@0 287 static bool
michael@0 288 IsWMFSupportedType(const nsACString& aType)
michael@0 289 {
michael@0 290 return WMFDecoder::CanPlayType(aType, NS_LITERAL_STRING(""));
michael@0 291 }
michael@0 292 #endif
michael@0 293
michael@0 294 #ifdef MOZ_DIRECTSHOW
michael@0 295 static bool
michael@0 296 IsDirectShowSupportedType(const nsACString& aType)
michael@0 297 {
michael@0 298 return DirectShowDecoder::GetSupportedCodecs(aType, nullptr);
michael@0 299 }
michael@0 300 #endif
michael@0 301
michael@0 302 #ifdef MOZ_FMP4
michael@0 303 static bool
michael@0 304 IsMP4SupportedType(const nsACString& aType)
michael@0 305 {
michael@0 306 return Preferences::GetBool("media.fragmented-mp4.exposed", false) &&
michael@0 307 MP4Decoder::GetSupportedCodecs(aType, nullptr);
michael@0 308 }
michael@0 309 #endif
michael@0 310
michael@0 311 #ifdef MOZ_APPLEMEDIA
michael@0 312 static const char * const gAppleMP3Types[] = {
michael@0 313 "audio/mp3",
michael@0 314 "audio/mpeg",
michael@0 315 nullptr,
michael@0 316 };
michael@0 317
michael@0 318 static const char * const gAppleMP3Codecs[] = {
michael@0 319 "mp3",
michael@0 320 nullptr
michael@0 321 };
michael@0 322
michael@0 323 static bool
michael@0 324 IsAppleMediaSupportedType(const nsACString& aType,
michael@0 325 const char * const ** aCodecs = nullptr)
michael@0 326 {
michael@0 327 if (MediaDecoder::IsAppleMP3Enabled()
michael@0 328 && CodecListContains(gAppleMP3Types, aType)) {
michael@0 329
michael@0 330 if (aCodecs) {
michael@0 331 *aCodecs = gAppleMP3Codecs;
michael@0 332 }
michael@0 333
michael@0 334 return true;
michael@0 335 }
michael@0 336
michael@0 337 // TODO MP4
michael@0 338
michael@0 339 return false;
michael@0 340 }
michael@0 341 #endif
michael@0 342
michael@0 343 /* static */
michael@0 344 bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType)
michael@0 345 {
michael@0 346 #ifdef MOZ_WAVE
michael@0 347 if (IsWaveType(nsDependentCString(aMIMEType))) {
michael@0 348 // We should not return true for Wave types, since there are some
michael@0 349 // Wave codecs actually in use in the wild that we don't support, and
michael@0 350 // we should allow those to be handled by plugins or helper apps.
michael@0 351 // Furthermore people can play Wave files on most platforms by other
michael@0 352 // means.
michael@0 353 return false;
michael@0 354 }
michael@0 355 #endif
michael@0 356 return CanHandleMediaType(aMIMEType, false, EmptyString()) != CANPLAY_NO;
michael@0 357 }
michael@0 358
michael@0 359 /* static */
michael@0 360 CanPlayStatus
michael@0 361 DecoderTraits::CanHandleMediaType(const char* aMIMEType,
michael@0 362 bool aHaveRequestedCodecs,
michael@0 363 const nsAString& aRequestedCodecs)
michael@0 364 {
michael@0 365 char const* const* codecList = nullptr;
michael@0 366 CanPlayStatus result = CANPLAY_NO;
michael@0 367 #ifdef MOZ_RAW
michael@0 368 if (IsRawType(nsDependentCString(aMIMEType))) {
michael@0 369 codecList = gRawCodecs;
michael@0 370 result = CANPLAY_MAYBE;
michael@0 371 }
michael@0 372 #endif
michael@0 373 if (IsOggType(nsDependentCString(aMIMEType))) {
michael@0 374 codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
michael@0 375 result = CANPLAY_MAYBE;
michael@0 376 }
michael@0 377 #ifdef MOZ_WAVE
michael@0 378 if (IsWaveType(nsDependentCString(aMIMEType))) {
michael@0 379 codecList = gWaveCodecs;
michael@0 380 result = CANPLAY_MAYBE;
michael@0 381 }
michael@0 382 #endif
michael@0 383 #ifdef MOZ_WEBM
michael@0 384 if (IsWebMType(nsDependentCString(aMIMEType))) {
michael@0 385 codecList = gWebMCodecs;
michael@0 386 result = CANPLAY_MAYBE;
michael@0 387 }
michael@0 388 #endif
michael@0 389 #ifdef MOZ_GSTREAMER
michael@0 390 if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType),
michael@0 391 aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) {
michael@0 392 if (aHaveRequestedCodecs)
michael@0 393 return CANPLAY_YES;
michael@0 394 return CANPLAY_MAYBE;
michael@0 395 }
michael@0 396 #endif
michael@0 397 #ifdef MOZ_OMX_DECODER
michael@0 398 if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
michael@0 399 result = CANPLAY_MAYBE;
michael@0 400 if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
michael@0 401 codecList = gMpegAudioCodecs;
michael@0 402 } else {
michael@0 403 codecList = gH264Codecs;
michael@0 404 }
michael@0 405 }
michael@0 406 #endif
michael@0 407 #ifdef MOZ_DIRECTSHOW
michael@0 408 // Note: DirectShow should come before WMF, so that we prefer DirectShow's
michael@0 409 // MP3 support over WMF's.
michael@0 410 if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
michael@0 411 result = CANPLAY_MAYBE;
michael@0 412 }
michael@0 413 #endif
michael@0 414 #ifdef MOZ_WMF
michael@0 415 if (IsWMFSupportedType(nsDependentCString(aMIMEType))) {
michael@0 416 if (!aHaveRequestedCodecs) {
michael@0 417 return CANPLAY_MAYBE;
michael@0 418 }
michael@0 419 return WMFDecoder::CanPlayType(nsDependentCString(aMIMEType),
michael@0 420 aRequestedCodecs)
michael@0 421 ? CANPLAY_YES : CANPLAY_NO;
michael@0 422 }
michael@0 423 #endif
michael@0 424 #ifdef MOZ_APPLEMEDIA
michael@0 425 if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) {
michael@0 426 result = CANPLAY_MAYBE;
michael@0 427 }
michael@0 428 #endif
michael@0 429 #ifdef MOZ_MEDIA_PLUGINS
michael@0 430 if (MediaDecoder::IsMediaPluginsEnabled() &&
michael@0 431 GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList))
michael@0 432 result = CANPLAY_MAYBE;
michael@0 433 #endif
michael@0 434 #ifdef NECKO_PROTOCOL_rtsp
michael@0 435 if (IsRtspSupportedType(nsDependentCString(aMIMEType))) {
michael@0 436 result = CANPLAY_MAYBE;
michael@0 437 }
michael@0 438 #endif
michael@0 439 if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) {
michael@0 440 return result;
michael@0 441 }
michael@0 442
michael@0 443 // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
michael@0 444 // of the 'codecs' parameter
michael@0 445 nsCharSeparatedTokenizer tokenizer(aRequestedCodecs, ',');
michael@0 446 bool expectMoreTokens = false;
michael@0 447 while (tokenizer.hasMoreTokens()) {
michael@0 448 const nsSubstring& token = tokenizer.nextToken();
michael@0 449
michael@0 450 if (!CodecListContains(codecList, token)) {
michael@0 451 // Totally unsupported codec
michael@0 452 return CANPLAY_NO;
michael@0 453 }
michael@0 454 expectMoreTokens = tokenizer.separatorAfterCurrentToken();
michael@0 455 }
michael@0 456 if (expectMoreTokens) {
michael@0 457 // Last codec name was empty
michael@0 458 return CANPLAY_NO;
michael@0 459 }
michael@0 460 return CANPLAY_YES;
michael@0 461 }
michael@0 462
michael@0 463 // Instantiates but does not initialize decoder.
michael@0 464 static
michael@0 465 already_AddRefed<MediaDecoder>
michael@0 466 InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
michael@0 467 {
michael@0 468 nsRefPtr<MediaDecoder> decoder;
michael@0 469
michael@0 470 #ifdef MOZ_GSTREAMER
michael@0 471 if (IsGStreamerSupportedType(aType)) {
michael@0 472 decoder = new GStreamerDecoder();
michael@0 473 return decoder.forget();
michael@0 474 }
michael@0 475 #endif
michael@0 476 #ifdef MOZ_RAW
michael@0 477 if (IsRawType(aType)) {
michael@0 478 decoder = new RawDecoder();
michael@0 479 return decoder.forget();
michael@0 480 }
michael@0 481 #endif
michael@0 482 if (IsOggType(aType)) {
michael@0 483 decoder = new OggDecoder();
michael@0 484 return decoder.forget();
michael@0 485 }
michael@0 486 #ifdef MOZ_WAVE
michael@0 487 if (IsWaveType(aType)) {
michael@0 488 decoder = new WaveDecoder();
michael@0 489 return decoder.forget();
michael@0 490 }
michael@0 491 #endif
michael@0 492 #ifdef MOZ_OMX_DECODER
michael@0 493 if (IsOmxSupportedType(aType)) {
michael@0 494 // AMR audio is enabled for MMS, but we are discouraging Web and App
michael@0 495 // developers from using AMR, thus we only allow AMR to be played on WebApps.
michael@0 496 if (aType.EqualsASCII("audio/amr")) {
michael@0 497 dom::HTMLMediaElement* element = aOwner->GetMediaElement();
michael@0 498 if (!element) {
michael@0 499 return nullptr;
michael@0 500 }
michael@0 501 nsIPrincipal* principal = element->NodePrincipal();
michael@0 502 if (!principal) {
michael@0 503 return nullptr;
michael@0 504 }
michael@0 505 if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
michael@0 506 return nullptr;
michael@0 507 }
michael@0 508 }
michael@0 509 decoder = new MediaOmxDecoder();
michael@0 510 return decoder.forget();
michael@0 511 }
michael@0 512 #endif
michael@0 513 #ifdef NECKO_PROTOCOL_rtsp
michael@0 514 if (IsRtspSupportedType(aType)) {
michael@0 515 decoder = new RtspOmxDecoder();
michael@0 516 return decoder.forget();
michael@0 517 }
michael@0 518 #endif
michael@0 519 #ifdef MOZ_MEDIA_PLUGINS
michael@0 520 if (MediaDecoder::IsMediaPluginsEnabled() &&
michael@0 521 GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
michael@0 522 decoder = new MediaPluginDecoder(aType);
michael@0 523 return decoder.forget();
michael@0 524 }
michael@0 525 #endif
michael@0 526 #ifdef MOZ_WEBM
michael@0 527 if (IsWebMType(aType)) {
michael@0 528 decoder = new WebMDecoder();
michael@0 529 return decoder.forget();
michael@0 530 }
michael@0 531 #endif
michael@0 532 #ifdef MOZ_DIRECTSHOW
michael@0 533 // Note: DirectShow should come before WMF, so that we prefer DirectShow's
michael@0 534 // MP3 support over WMF's.
michael@0 535 if (IsDirectShowSupportedType(aType)) {
michael@0 536 decoder = new DirectShowDecoder();
michael@0 537 return decoder.forget();
michael@0 538 }
michael@0 539 #endif
michael@0 540 #ifdef MOZ_FMP4
michael@0 541 if (IsMP4SupportedType(aType)) {
michael@0 542 decoder = new MP4Decoder();
michael@0 543 return decoder.forget();
michael@0 544 }
michael@0 545 #endif
michael@0 546 #ifdef MOZ_WMF
michael@0 547 if (IsWMFSupportedType(aType)) {
michael@0 548 decoder = new WMFDecoder();
michael@0 549 return decoder.forget();
michael@0 550 }
michael@0 551 #endif
michael@0 552 #ifdef MOZ_APPLEMEDIA
michael@0 553 if (IsAppleMediaSupportedType(aType)) {
michael@0 554 decoder = new AppleDecoder();
michael@0 555 return decoder.forget();
michael@0 556 }
michael@0 557 #endif
michael@0 558
michael@0 559 NS_ENSURE_TRUE(decoder != nullptr, nullptr);
michael@0 560 NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
michael@0 561 return nullptr;
michael@0 562 }
michael@0 563
michael@0 564 /* static */
michael@0 565 already_AddRefed<MediaDecoder>
michael@0 566 DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
michael@0 567 {
michael@0 568 nsRefPtr<MediaDecoder> decoder(InstantiateDecoder(aType, aOwner));
michael@0 569 NS_ENSURE_TRUE(decoder != nullptr, nullptr);
michael@0 570 NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
michael@0 571
michael@0 572 return decoder.forget();
michael@0 573 }
michael@0 574
michael@0 575 /* static */
michael@0 576 MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
michael@0 577 {
michael@0 578 MediaDecoderReader* decoderReader = nullptr;
michael@0 579
michael@0 580 #ifdef MOZ_GSTREAMER
michael@0 581 if (IsGStreamerSupportedType(aType)) {
michael@0 582 decoderReader = new GStreamerReader(aDecoder);
michael@0 583 } else
michael@0 584 #endif
michael@0 585 #ifdef MOZ_RAW
michael@0 586 if (IsRawType(aType)) {
michael@0 587 decoderReader = new RawReader(aDecoder);
michael@0 588 } else
michael@0 589 #endif
michael@0 590 if (IsOggType(aType)) {
michael@0 591 decoderReader = new OggReader(aDecoder);
michael@0 592 } else
michael@0 593 #ifdef MOZ_WAVE
michael@0 594 if (IsWaveType(aType)) {
michael@0 595 decoderReader = new WaveReader(aDecoder);
michael@0 596 } else
michael@0 597 #endif
michael@0 598 #ifdef MOZ_OMX_DECODER
michael@0 599 if (IsOmxSupportedType(aType)) {
michael@0 600 decoderReader = new MediaOmxReader(aDecoder);
michael@0 601 } else
michael@0 602 #endif
michael@0 603 #ifdef MOZ_MEDIA_PLUGINS
michael@0 604 if (MediaDecoder::IsMediaPluginsEnabled() &&
michael@0 605 GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
michael@0 606 decoderReader = new MediaPluginReader(aDecoder, aType);
michael@0 607 } else
michael@0 608 #endif
michael@0 609 #ifdef MOZ_WEBM
michael@0 610 if (IsWebMType(aType)) {
michael@0 611 decoderReader = new WebMReader(aDecoder);
michael@0 612 } else
michael@0 613 #endif
michael@0 614 #ifdef MOZ_DIRECTSHOW
michael@0 615 // Note: DirectShowReader is preferred for MP3, but if it's disabled we
michael@0 616 // fallback to the WMFReader.
michael@0 617 if (IsDirectShowSupportedType(aType)) {
michael@0 618 decoderReader = new DirectShowReader(aDecoder);
michael@0 619 } else
michael@0 620 #endif
michael@0 621 #ifdef MOZ_FMP4
michael@0 622 if (IsMP4SupportedType(aType)) {
michael@0 623 decoderReader = new MP4Reader(aDecoder);
michael@0 624 } else
michael@0 625 #endif
michael@0 626 #ifdef MOZ_WMF
michael@0 627 if (IsWMFSupportedType(aType)) {
michael@0 628 decoderReader = new WMFReader(aDecoder);
michael@0 629 } else
michael@0 630 #endif
michael@0 631 #ifdef MOZ_APPLEMEDIA
michael@0 632 if (IsAppleMediaSupportedType(aType)) {
michael@0 633 decoderReader = new AppleMP3Reader(aDecoder);
michael@0 634 } else
michael@0 635 #endif
michael@0 636 if (false) {} // dummy if to take care of the dangling else
michael@0 637
michael@0 638 return decoderReader;
michael@0 639 }
michael@0 640
michael@0 641 /* static */
michael@0 642 bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType)
michael@0 643 {
michael@0 644 return
michael@0 645 IsOggType(aType) ||
michael@0 646 #ifdef MOZ_OMX_DECODER
michael@0 647 // We support amr inside WebApps on firefoxOS but not in general web content.
michael@0 648 // Ensure we dont create a VideoDocument when accessing amr URLs directly.
michael@0 649 (IsOmxSupportedType(aType) && !aType.EqualsASCII("audio/amr")) ||
michael@0 650 #endif
michael@0 651 #ifdef MOZ_WEBM
michael@0 652 IsWebMType(aType) ||
michael@0 653 #endif
michael@0 654 #ifdef MOZ_GSTREAMER
michael@0 655 IsGStreamerSupportedType(aType) ||
michael@0 656 #endif
michael@0 657 #ifdef MOZ_MEDIA_PLUGINS
michael@0 658 (MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) ||
michael@0 659 #endif
michael@0 660 #ifdef MOZ_FMP4
michael@0 661 IsMP4SupportedType(aType) ||
michael@0 662 #endif
michael@0 663 #ifdef MOZ_WMF
michael@0 664 (IsWMFSupportedType(aType) &&
michael@0 665 Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true)) ||
michael@0 666 #endif
michael@0 667 #ifdef MOZ_DIRECTSHOW
michael@0 668 IsDirectShowSupportedType(aType) ||
michael@0 669 #endif
michael@0 670 #ifdef MOZ_APPLEMEDIA
michael@0 671 IsAppleMediaSupportedType(aType) ||
michael@0 672 #endif
michael@0 673 #ifdef NECKO_PROTOCOL_rtsp
michael@0 674 IsRtspSupportedType(aType) ||
michael@0 675 #endif
michael@0 676 false;
michael@0 677 }
michael@0 678
michael@0 679 }

mercurial