/* 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 */ 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 */ 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 */ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder) { MediaDecoderReader* decoderReader = nullptr; #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoderReader = new GStreamerReader(aDecoder); } else #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoderReader = new RawReader(aDecoder); } else #endif #ifdef MOZ_OGG if (IsOggType(aType)) { decoderReader = new OggReader(aDecoder); } else #endif #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoderReader = new WaveReader(aDecoder); } else #endif #ifdef MOZ_WIDGET_GONK if (IsOmxSupportedType(aType)) { decoderReader = new MediaOmxReader(aDecoder); } else #endif #ifdef MOZ_MEDIA_PLUGINS if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, nullptr)) { decoderReader = new MediaPluginReader(aDecoder, aType); } else #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { decoderReader = new WebMReader(aDecoder); } else #endif #ifdef MOZ_WMF if (IsWMFSupportedType(aType)) { decoderReader = new WMFReader(aDecoder); } else #endif #ifdef MOZ_DASH // The DASH decoder is not supported. #endif if (false) {} // dummy if to take care of the dangling else return decoderReader; }
static bool IsGStreamerSupportedType(const nsACString& aMimeType) { if (!MediaDecoder::IsGStreamerEnabled()) return false; #ifdef MOZ_WEBM if (IsWebMType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false)) return false; #endif if (IsOggType(aMimeType) && !Preferences::GetBool("media.prefer-gstreamer", false)) return false; return GStreamerDecoder::CanHandleMediaType(aMimeType, nullptr); }
/* 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; }
static bool IsGStreamerSupportedType(const nsACString& aMimeType) { if (!MediaDecoder::IsGStreamerEnabled()) return false; if (IsH264Type(aMimeType)) return true; if (!Preferences::GetBool("media.prefer-gstreamer", false)) return false; #ifdef MOZ_WEBM if (IsWebMType(aMimeType)) return true; #endif #ifdef MOZ_OGG if (IsOggType(aMimeType)) return true; #endif return false; }
// 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)) { // 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")) { 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(); return decoder.forget(); } #endif #ifdef NECKO_PROTOCOL_rtsp if (IsRtspSupportedType(aType)) { decoder = new RtspOmxDecoder(); return decoder.forget(); } #endif #ifdef MOZ_MEDIA_PLUGINS if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, nullptr)) { decoder = new MediaPluginDecoder(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; }
/* static */ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder) { MediaDecoderReader* decoderReader = nullptr; #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoderReader = new GStreamerReader(aDecoder); } else #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoderReader = new RawReader(aDecoder); } else #endif #ifdef MOZ_OGG if (IsOggType(aType)) { decoderReader = new OggReader(aDecoder); } else #endif #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoderReader = new WaveReader(aDecoder); } else #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { decoderReader = new MediaOmxReader(aDecoder); } else #endif #ifdef MOZ_MEDIA_PLUGINS if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, nullptr)) { decoderReader = new MediaPluginReader(aDecoder, aType); } else #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { decoderReader = new WebMReader(aDecoder); } else #endif #ifdef MOZ_DIRECTSHOW // Note: DirectShowReader is preferred for MP3, but if it's disabled we // fallback to the WMFReader. if (IsDirectShowSupportedType(aType)) { decoderReader = new DirectShowReader(aDecoder); } else #endif #ifdef MOZ_WMF if (IsWMFSupportedType(aType)) { decoderReader = new WMFReader(aDecoder); } else #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(aType)) { decoderReader = new AppleMP3Reader(aDecoder); } else #endif #ifdef MOZ_DASH // The DASH decoder is not supported. #endif if (false) {} // dummy if to take care of the dangling else return decoderReader; }
/* 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; }
/* static */ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder) { MediaDecoderReader* decoderReader = nullptr; if (!aDecoder) { return decoderReader; } #ifdef MOZ_FMP4 if (IsMP4SupportedType(aType)) { decoderReader = new MP4Reader(aDecoder); } else #endif #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoderReader = new GStreamerReader(aDecoder); } else #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoderReader = new RawReader(aDecoder); } else #endif if (IsOggType(aType)) { decoderReader = new OggReader(aDecoder); } else #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoderReader = new WaveReader(aDecoder); } else #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { #if ANDROID_VERSION >= 18 decoderReader = MediaDecoder::IsOmxAsyncEnabled() ? static_cast<MediaDecoderReader*>(new MediaCodecReader(aDecoder)) : static_cast<MediaDecoderReader*>(new MediaOmxReader(aDecoder)); #else decoderReader = new MediaOmxReader(aDecoder); #endif } else #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled() && GetAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) { decoderReader = new AndroidMediaReader(aDecoder, aType); } else #endif #ifdef MOZ_WEBM if (IsWebMType(aType)) { decoderReader = new WebMReader(aDecoder); } else #endif #ifdef MOZ_DIRECTSHOW // Note: DirectShowReader is preferred for MP3, but if it's disabled we // fallback to the WMFReader. if (IsDirectShowSupportedType(aType)) { decoderReader = new DirectShowReader(aDecoder); } else #endif #ifdef MOZ_WMF if (IsWMFSupportedType(aType)) { decoderReader = new WMFReader(aDecoder); } else #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(aType)) { decoderReader = new AppleMP3Reader(aDecoder); } else #endif if (false) {} // dummy if to take care of the dangling else return decoderReader; }
// 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; }
/* 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 if (IsOggType(nsDependentCString(aMIMEType))) { codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs; result = CANPLAY_MAYBE; } #ifdef MOZ_WAVE if (IsWaveType(nsDependentCString(aMIMEType))) { codecList = gWaveCodecs; result = CANPLAY_MAYBE; } #endif #if defined(MOZ_WEBM) && !defined(MOZ_OMX_WEBM_DECODER) if (IsWebMType(nsDependentCString(aMIMEType))) { codecList = gWebMCodecs; result = CANPLAY_MAYBE; } #endif #ifdef MOZ_FMP4 if (IsMP4SupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) { return aHaveRequestedCodecs ? CANPLAY_YES : CANPLAY_MAYBE; } #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; #ifdef MOZ_OMX_WEBM_DECODER } else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") || nsDependentCString(aMIMEType).EqualsASCII("video/webm")) { codecList = gOMXWebMCodecs; #endif } else { codecList = gH264Codecs; } } #endif #ifdef MOZ_DIRECTSHOW // Note: DirectShow should come before WMF, so that we prefer DirectShow's // MP3 support over WMF's. if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) { result = CANPLAY_MAYBE; } #endif #ifdef MOZ_WMF if (!Preferences::GetBool("media.fragmented-mp4.exposed", false) && IsWMFSupportedType(nsDependentCString(aMIMEType))) { if (!aHaveRequestedCodecs) { return CANPLAY_MAYBE; } return WMFDecoder::CanPlayType(nsDependentCString(aMIMEType), aRequestedCodecs) ? CANPLAY_YES : CANPLAY_NO; } #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) { result = CANPLAY_MAYBE; } #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled() && GetAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList)) result = CANPLAY_MAYBE; #endif #ifdef NECKO_PROTOCOL_rtsp if (IsRtspSupportedType(nsDependentCString(aMIMEType))) { 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.separatorAfterCurrentToken(); } if (expectMoreTokens) { // Last codec name was empty return CANPLAY_NO; } return CANPLAY_YES; }
/* static */ CanPlayStatus DecoderTraits::CanHandleCodecsType(const char* aMIMEType, const nsAString& aRequestedCodecs) { char const* const* codecList = nullptr; #ifdef MOZ_RAW if (IsRawType(nsDependentCString(aMIMEType))) { codecList = gRawCodecs; } #endif if (IsOggType(nsDependentCString(aMIMEType))) { codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs; } #ifdef MOZ_WAVE if (IsWaveType(nsDependentCString(aMIMEType))) { codecList = gWaveCodecs; } #endif #if !defined(MOZ_OMX_WEBM_DECODER) if (IsWebMType(nsDependentCString(aMIMEType))) { codecList = gWebMCodecs; } #endif #ifdef MOZ_FMP4 if (IsMP4Type(nsDependentCString(aMIMEType))) { if (IsMP4SupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) { return CANPLAY_YES; } else { // 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; } } #endif if (IsMP3SupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) { return CANPLAY_YES; } #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(nsDependentCString(aMIMEType))) { if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) { codecList = gMpegAudioCodecs; #ifdef MOZ_OMX_WEBM_DECODER } else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") || nsDependentCString(aMIMEType).EqualsASCII("video/webm")) { codecList = gOMXWebMCodecs; #endif } else { codecList = gH264Codecs; } } #endif #ifdef MOZ_DIRECTSHOW DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList); #endif #ifdef MOZ_APPLEMEDIA IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList); #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled()) { EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList); } #endif if (!codecList) { return CANPLAY_MAYBE; } // 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.separatorAfterCurrentToken(); } if (expectMoreTokens) { // Last codec name was empty return CANPLAY_NO; } return CANPLAY_YES; }
/* static */ CanPlayStatus DecoderTraits::CanHandleMediaType(const char* aMIMEType, bool aHaveRequestedCodecs, const nsAString& aRequestedCodecs) { MOZ_ASSERT(NS_IsMainThread()); if (aHaveRequestedCodecs) { CanPlayStatus result = CanHandleCodecsType(aMIMEType, aRequestedCodecs); if (result == CANPLAY_NO || result == CANPLAY_YES) { return result; } } #ifdef MOZ_RAW if (IsRawType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #endif if (IsOggType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #ifdef MOZ_WAVE if (IsWaveType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #endif if (IsMP4Type(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #if !defined(MOZ_OMX_WEBM_DECODER) if (IsWebMType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #endif if (IsMP3SupportedType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #ifdef MOZ_GSTREAMER if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType), aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) { return aHaveRequestedCodecs ? CANPLAY_YES : CANPLAY_MAYBE; } #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #endif #ifdef MOZ_DIRECTSHOW if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), nullptr)) { return CANPLAY_MAYBE; } #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), nullptr)) { return CANPLAY_MAYBE; } #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled() && EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), nullptr)) { return CANPLAY_MAYBE; } #endif #ifdef NECKO_PROTOCOL_rtsp if (IsRtspSupportedType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #endif return CANPLAY_NO; }
/* static */ MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder) { MOZ_ASSERT(NS_IsMainThread()); MediaDecoderReader* decoderReader = nullptr; if (!aDecoder) { return decoderReader; } #ifdef MOZ_FMP4 if (IsMP4SupportedType(aType)) { decoderReader = new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource())); } else #endif if (IsMP3SupportedType(aType)) { decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource())); } else #ifdef MOZ_GSTREAMER if (IsGStreamerSupportedType(aType)) { decoderReader = new GStreamerReader(aDecoder); } else #endif #ifdef MOZ_RAW if (IsRawType(aType)) { decoderReader = new RawReader(aDecoder); } else #endif if (IsOggType(aType)) { decoderReader = new OggReader(aDecoder); } else #ifdef MOZ_WAVE if (IsWaveType(aType)) { decoderReader = new WaveReader(aDecoder); } else #endif #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { #if ANDROID_VERSION >= 18 decoderReader = MediaDecoder::IsOmxAsyncEnabled() ? static_cast<MediaDecoderReader*>(new MediaCodecReader(aDecoder)) : static_cast<MediaDecoderReader*>(new MediaOmxReader(aDecoder)); #else decoderReader = new MediaOmxReader(aDecoder); #endif } else #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaEnabled() && EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) { decoderReader = new AndroidMediaReader(aDecoder, aType); } else #endif if (IsWebMType(aType)) { decoderReader = Preferences::GetBool("media.format-reader.webm", true) ? static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource()))) : new WebMReader(aDecoder); } else #ifdef MOZ_DIRECTSHOW if (IsDirectShowSupportedType(aType)) { decoderReader = new DirectShowReader(aDecoder); } else #endif #ifdef MOZ_APPLEMEDIA if (IsAppleMediaSupportedType(aType)) { decoderReader = new AppleMP3Reader(aDecoder); } else #endif if (false) {} // dummy if to take care of the dangling else return decoderReader; }