/* static */ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType) { // 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; } return IsOggType(aType) || #ifdef MOZ_OMX_DECODER // 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. (IsOmxSupportedType(aType) && !IsB2GSupportOnlyType(aType)) || #endif IsWebMSupportedType(aType) || #ifdef MOZ_ANDROID_OMX (MediaDecoder::IsAndroidMediaPluginEnabled() && IsAndroidMediaType(aType)) || #endif #ifdef MOZ_FMP4 IsMP4SupportedType(aType, /* DecoderDoctorDiagnostics* */ nullptr) || #endif IsMP3SupportedType(aType) || IsAACSupportedType(aType) || #ifdef MOZ_DIRECTSHOW IsDirectShowSupportedType(aType) || #endif false; }
/* static */ bool DecoderTraits::IsSupportedInVideoDocument(const nsACString& aType) { // 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; } return IsOggType(aType) || #ifdef MOZ_OMX_DECODER // 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. (IsOmxSupportedType(aType) && !IsB2GSupportOnlyType(aType)) || #endif #ifdef MOZ_WEBM IsWebMType(aType) || #endif #ifdef MOZ_GSTREAMER IsGStreamerSupportedType(aType) || #endif #ifdef MOZ_ANDROID_OMX (MediaDecoder::IsAndroidMediaEnabled() && IsAndroidMediaType(aType)) || #endif #ifdef MOZ_FMP4 IsMP4SupportedType(aType) || #endif #ifdef MOZ_WMF IsWMFSupportedType(aType) || #endif #ifdef MOZ_DIRECTSHOW IsDirectShowSupportedType(aType) || #endif #ifdef MOZ_APPLEMEDIA IsAppleMediaSupportedType(aType) || #endif #ifdef NECKO_PROTOCOL_rtsp IsRtspSupportedType(aType) || #endif false; }
// Instantiates but does not initialize decoder. static already_AddRefed<MediaDecoder> InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner, DecoderDoctorDiagnostics* aDiagnostics) { MOZ_ASSERT(NS_IsMainThread()); RefPtr<MediaDecoder> decoder; #ifdef MOZ_FMP4 if (IsMP4SupportedType(aType, aDiagnostics)) { decoder = new MP4Decoder(aOwner); return decoder.forget(); } #endif if (IsMP3SupportedType(aType)) { decoder = new MP3Decoder(aOwner); return decoder.forget(); } if (IsAACSupportedType(aType)) { decoder = new ADTSDecoder(aOwner); return decoder.forget(); } #ifdef MOZ_RAW if (IsRawType(aType)) { decoder = new RawDecoder(aOwner); return decoder.forget(); } #endif if (IsOggType(aType)) { decoder = new OggDecoder(aOwner); return decoder.forget(); } if (IsWaveType(aType)) { decoder = new WaveDecoder(aOwner); return decoder.forget(); } #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { // 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)) { dom::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(aOwner); return decoder.forget(); } #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaPluginEnabled() && EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) { decoder = new AndroidMediaDecoder(aOwner, aType); return decoder.forget(); } #endif if (IsWebMSupportedType(aType)) { decoder = new WebMDecoder(aOwner); return decoder.forget(); } #ifdef MOZ_DIRECTSHOW // Note: DirectShow should come before WMF, so that we prefer DirectShow's // MP3 support over WMF's. if (IsDirectShowSupportedType(aType)) { decoder = new DirectShowDecoder(aOwner); return decoder.forget(); } #endif if (IsHttpLiveStreamingType(aType)) { // We don't have an HLS decoder. Telemetry::Accumulate(Telemetry::MEDIA_HLS_DECODER_SUCCESS, false); } return nullptr; }
// Instantiates but does not initialize decoder. static already_AddRefed<MediaDecoder> InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner) { nsRefPtr<MediaDecoder> decoder; #ifdef MOZ_FMP4 if (IsMP4SupportedType(aType)) { decoder = new MP4Decoder(); return decoder.forget(); } #endif #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoder = new GStreamerDecoder(); return decoder.forget(); } #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoder = new RawDecoder(); return decoder.forget(); } #endif if (IsOggType(aType)) { decoder = new OggDecoder(); return decoder.forget(); } #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoder = new WaveDecoder(); return decoder.forget(); } #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { // 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)) { dom::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; } } #if ANDROID_VERSION >= 18 decoder = MediaDecoder::IsOmxAsyncEnabled() ? static_cast<MediaDecoder*>(new MediaCodecDecoder()) : static_cast<MediaDecoder*>(new MediaOmxDecoder()); #else decoder = new MediaOmxDecoder(); #endif return decoder.forget(); } #endif #ifdef NECKO_PROTOCOL_rtsp if (IsRtspSupportedType(aType)) { #if ANDROID_VERSION >= 18 decoder = MediaDecoder::IsOmxAsyncEnabled() ? static_cast<MediaDecoder*>(new RtspMediaCodecDecoder()) : static_cast<MediaDecoder*>(new RtspOmxDecoder()); #else decoder = new RtspOmxDecoder(); #endif return decoder.forget(); } #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled() && GetAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) { decoder = new AndroidMediaDecoder(aType); return decoder.forget(); } #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { decoder = new WebMDecoder(); return decoder.forget(); } #endif #ifdef MOZ_DIRECTSHOW // Note: DirectShow should come before WMF, so that we prefer DirectShow's // MP3 support over WMF's. if (IsDirectShowSupportedType(aType)) { decoder = new DirectShowDecoder(); return decoder.forget(); } #endif #ifdef MOZ_WMF if (IsWMFSupportedType(aType)) { decoder = new WMFDecoder(); return decoder.forget(); } #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(aType)) { decoder = new AppleDecoder(); return decoder.forget(); } #endif NS_ENSURE_TRUE(decoder != nullptr, nullptr); NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr); return nullptr; }
// Instantiates but does not initialize decoder. static already_AddRefed<MediaDecoder> InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner) { MOZ_ASSERT(NS_IsMainThread()); RefPtr<MediaDecoder> decoder; #ifdef MOZ_FMP4 if (IsMP4SupportedType(aType)) { decoder = new MP4Decoder(aOwner); return decoder.forget(); } #endif if (IsMP3SupportedType(aType)) { decoder = new MP3Decoder(aOwner); return decoder.forget(); } #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoder = new GStreamerDecoder(aOwner); return decoder.forget(); } #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoder = new RawDecoder(aOwner); return decoder.forget(); } #endif if (IsOggType(aType)) { decoder = new OggDecoder(aOwner); return decoder.forget(); } #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoder = new WaveDecoder(aOwner); return decoder.forget(); } #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { // 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)) { dom::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(aOwner); return decoder.forget(); } #endif #ifdef NECKO_PROTOCOL_rtsp if (IsRtspSupportedType(aType)) { decoder = new RtspOmxDecoder(aOwner); return decoder.forget(); } #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled() && EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) { decoder = new AndroidMediaDecoder(aOwner, aType); return decoder.forget(); } #endif if (DecoderTraits::IsWebMTypeAndEnabled(aType)) { decoder = new WebMDecoder(aOwner); return decoder.forget(); } #ifdef MOZ_DIRECTSHOW // Note: DirectShow should come before WMF, so that we prefer DirectShow's // MP3 support over WMF's. if (IsDirectShowSupportedType(aType)) { decoder = new DirectShowDecoder(aOwner); return decoder.forget(); } #endif return nullptr; }