/* static */ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType) { return #ifdef MOZ_OGG IsOggType(aType) || #endif #ifdef MOZ_OMX_DECODER // We support amr inside WebApps on firefoxOS but not in general web content. // Ensure we dont create a VideoDocument when accessing amr URLs directly. (IsOmxSupportedType(aType) && !aType.EqualsASCII("audio/amr")) || #endif #ifdef MOZ_WEBM IsWebMType(aType) || #endif #ifdef MOZ_DASH IsDASHMPDType(aType) || #endif #ifdef MOZ_GSTREAMER IsGStreamerSupportedType(aType) || #endif #ifdef MOZ_MEDIA_PLUGINS (MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) || #endif #ifdef MOZ_WMF (IsWMFSupportedType(aType) && Preferences::GetBool("media.windows-media-foundation.play-stand-alone", true)) || #endif #ifdef MOZ_DIRECTSHOW IsDirectShowSupportedType(aType) || #endif #ifdef MOZ_APPLEMEDIA IsAppleMediaSupportedType(aType) || #endif false; }
/* static */ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType) { return #ifdef MOZ_OGG IsOggType(aType) || #endif #ifdef MOZ_WIDGET_GONK IsOmxSupportedType(aType) || #endif #ifdef MOZ_WEBM IsWebMType(aType) || #endif #ifdef MOZ_DASH IsDASHMPDType(aType) || #endif #ifdef MOZ_GSTREAMER IsGStreamerSupportedType(aType) || #endif #ifdef MOZ_MEDIA_PLUGINS (MediaDecoder::IsMediaPluginsEnabled() && IsMediaPluginsType(aType)) || #endif #ifdef MOZ_WMF IsWMFSupportedType(aType) || #endif false; }
/* static */ already_AddRefed<MediaDecoder> DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner) { nsRefPtr<MediaDecoder> decoder; #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoder = new GStreamerDecoder(); } #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoder = new RawDecoder(); } #endif #ifdef MOZ_OGG if (IsOggType(aType)) { decoder = new OggDecoder(); } #endif #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoder = new WaveDecoder(); } #endif #ifdef MOZ_WIDGET_GONK if (IsOmxSupportedType(aType)) { decoder = new MediaOmxDecoder(); } #endif #ifdef MOZ_MEDIA_PLUGINS if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) { decoder = new MediaPluginDecoder(aType); } #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { decoder = new WebMDecoder(); } #endif #ifdef MOZ_DASH if (IsDASHMPDType(aType)) { decoder = new DASHDecoder(); } #endif #ifdef MOZ_WMF if (IsWMFSupportedType(aType)) { decoder = new WMFDecoder(); } #endif NS_ENSURE_TRUE(decoder != nullptr, nullptr); NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr); return decoder.forget(); }
/* static */ already_AddRefed<MediaDecoder> DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner) { nsRefPtr<MediaDecoder> decoder; #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoder = new GStreamerDecoder(); } #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoder = new RawDecoder(); } #endif #ifdef MOZ_OGG if (IsOggType(aType)) { decoder = new OggDecoder(); } #endif #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoder = new WaveDecoder(); } #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { // AMR audio is enabled for MMS, but we are discouraging Web and App // developers from using AMR, thus we only allow AMR to be played on WebApps. if (aType.EqualsASCII("audio/amr")) { HTMLMediaElement* element = aOwner->GetMediaElement(); if (!element) { return nullptr; } nsIPrincipal* principal = element->NodePrincipal(); if (!principal) { return nullptr; } if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) { return nullptr; } } decoder = new MediaOmxDecoder(); } #endif #ifdef MOZ_MEDIA_PLUGINS if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) { decoder = new MediaPluginDecoder(aType); } #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { decoder = new WebMDecoder(); } #endif #ifdef MOZ_DASH if (IsDASHMPDType(aType)) { decoder = new DASHDecoder(); } #endif #ifdef MOZ_DIRECTSHOW // Note: DirectShow decoder must come before WMFDecoder, else the pref // "media.directshow.preferred" won't be honored. if (IsDirectShowSupportedType(aType)) { decoder = new DirectShowDecoder(); } #endif #ifdef MOZ_WMF if (IsWMFSupportedType(aType)) { decoder = new WMFDecoder(); } #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(aType)) { decoder = new AppleDecoder(); } #endif NS_ENSURE_TRUE(decoder != nullptr, nullptr); NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr); return decoder.forget(); }
/* static */ CanPlayStatus DecoderTraits::CanHandleMediaType(const char* aMIMEType, bool aHaveRequestedCodecs, const nsAString& aRequestedCodecs) { char const* const* codecList = nullptr; CanPlayStatus result = CANPLAY_NO; #ifdef MOZ_RAW if (IsRawType(nsDependentCString(aMIMEType))) { codecList = gRawCodecs; result = CANPLAY_MAYBE; } #endif #ifdef MOZ_OGG if (IsOggType(nsDependentCString(aMIMEType))) { codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs; result = CANPLAY_MAYBE; } #endif #ifdef MOZ_WAVE if (IsWaveType(nsDependentCString(aMIMEType))) { codecList = gWaveCodecs; result = CANPLAY_MAYBE; } #endif #ifdef MOZ_WEBM if (IsWebMType(nsDependentCString(aMIMEType))) { codecList = gWebMCodecs; result = CANPLAY_YES; } #endif #ifdef MOZ_DASH if (IsDASHMPDType(nsDependentCString(aMIMEType))) { // DASH manifest uses WebM codecs only. codecList = gWebMCodecs; result = CANPLAY_YES; } #endif #ifdef MOZ_GSTREAMER if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType), aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) { if (aHaveRequestedCodecs) return CANPLAY_YES; return CANPLAY_MAYBE; } #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(nsDependentCString(aMIMEType))) { result = CANPLAY_MAYBE; if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) { codecList = gMpegAudioCodecs; } else { codecList = gH264Codecs; } } #endif #ifdef MOZ_WMF if (WMFDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) { result = CANPLAY_MAYBE; } #endif #ifdef MOZ_DIRECTSHOW if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) { result = CANPLAY_MAYBE; } #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) { result = CANPLAY_MAYBE; } #endif #ifdef MOZ_MEDIA_PLUGINS if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList)) result = CANPLAY_MAYBE; #endif if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) { return result; } // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description // of the 'codecs' parameter nsCharSeparatedTokenizer tokenizer(aRequestedCodecs, ','); bool expectMoreTokens = false; while (tokenizer.hasMoreTokens()) { const nsSubstring& token = tokenizer.nextToken(); if (!CodecListContains(codecList, token)) { // Totally unsupported codec return CANPLAY_NO; } expectMoreTokens = tokenizer.lastTokenEndedWithSeparator(); } if (expectMoreTokens) { // Last codec name was empty return CANPLAY_NO; } return CANPLAY_YES; }