/* 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, /* DecoderDoctorDiagnostics* */ nullptr)) { decoderReader = new MediaFormatReader(aDecoder, new MP4Demuxer(aDecoder->GetResource())); } else #endif if (IsMP3SupportedType(aType)) { decoderReader = new MediaFormatReader(aDecoder, new mp3::MP3Demuxer(aDecoder->GetResource())); } else if (IsAACSupportedType(aType)) { decoderReader = new MediaFormatReader(aDecoder, new ADTSDemuxer(aDecoder->GetResource())); } else if (IsWAVSupportedType(aType)) { decoderReader = new MediaFormatReader(aDecoder, new WAVDemuxer(aDecoder->GetResource())); } else #ifdef MOZ_RAW if (IsRawType(aType)) { decoderReader = new RawReader(aDecoder); } else #endif if (IsOggType(aType)) { decoderReader = Preferences::GetBool("media.format-reader.ogg", true) ? static_cast<MediaDecoderReader*>(new MediaFormatReader(aDecoder, new OggDemuxer(aDecoder->GetResource()))) : new OggReader(aDecoder); } else if (IsWaveType(aType)) { decoderReader = new WaveReader(aDecoder); } else #ifdef MOZ_OMX_DECODER if (IsOmxSupportedType(aType)) { decoderReader = new MediaOmxReader(aDecoder); } else #endif #ifdef MOZ_ANDROID_OMX if (MediaDecoder::IsAndroidMediaPluginEnabled() && EnsureAndroidMediaPluginHost()->FindDecoder(aType, nullptr)) { decoderReader = new AndroidMediaReader(aDecoder, aType); } else #endif if (IsWebMSupportedType(aType)) { decoderReader = new MediaFormatReader(aDecoder, new WebMDemuxer(aDecoder->GetResource())); } else #ifdef MOZ_DIRECTSHOW if (IsDirectShowSupportedType(aType)) { decoderReader = new DirectShowReader(aDecoder); } else #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_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; }
// 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; }
/* static */ CanPlayStatus DecoderTraits::CanHandleMediaType(const char* aMIMEType, bool aHaveRequestedCodecs, const nsAString& aRequestedCodecs, DecoderDoctorDiagnostics* aDiagnostics) { MOZ_ASSERT(NS_IsMainThread()); if (IsHttpLiveStreamingType(nsDependentCString(aMIMEType))) { Telemetry::Accumulate(Telemetry::MEDIA_HLS_CANPLAY_REQUESTED, true); } if (aHaveRequestedCodecs) { CanPlayStatus result = CanHandleCodecsType(aMIMEType, aRequestedCodecs, aDiagnostics); 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; } if (IsWaveType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } if (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType), aDiagnostics)) { return CANPLAY_MAYBE; } #if !defined(MOZ_OMX_WEBM_DECODER) if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #endif if (IsMP3SupportedType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } if (IsAACSupportedType(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #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_ANDROID_OMX if (MediaDecoder::IsAndroidMediaPluginEnabled() && EnsureAndroidMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), nullptr)) { return CANPLAY_MAYBE; } #endif return CANPLAY_NO; }
/* static */ CanPlayStatus DecoderTraits::CanHandleCodecsType(const char* aMIMEType, const nsAString& aRequestedCodecs, DecoderDoctorDiagnostics* aDiagnostics) { char const* const* codecList = nullptr; #ifdef MOZ_RAW if (IsRawType(nsDependentCString(aMIMEType))) { codecList = gRawCodecs; } #endif if (IsOggType(nsDependentCString(aMIMEType))) { codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs; } if (IsWaveType(nsDependentCString(aMIMEType))) { codecList = gWaveCodecs; } #if !defined(MOZ_OMX_WEBM_DECODER) if (IsWebMTypeAndEnabled(nsDependentCString(aMIMEType))) { if (IsWebMSupportedType(nsDependentCString(aMIMEType), aRequestedCodecs)) { return CANPLAY_YES; } else { // We can only reach this position if a particular codec was requested, // webm is supported and working: the codec must be invalid. return CANPLAY_NO; } } #endif #ifdef MOZ_FMP4 if (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType), aDiagnostics)) { if (IsMP4SupportedType(nsDependentCString(aMIMEType), aDiagnostics, 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; } if (IsAACSupportedType(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_ANDROID_OMX if (MediaDecoder::IsAndroidMediaPluginEnabled()) { 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 */ 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; }
// 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; }
/* 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 (IsMP4TypeAndEnabled(nsDependentCString(aMIMEType))) { return CANPLAY_MAYBE; } #if !defined(MOZ_OMX_WEBM_DECODER) if (IsWebMTypeAndEnabled(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_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; }
// 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; }