/* 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.wmf.play-stand-alone", true) || !Preferences::GetBool("media.play-stand-alone", true)) { return false; } Maybe<MediaContainerType> type = MakeMediaContainerType(aType); if (!type) { return false; } return OggDecoder::IsSupportedType(*type) || WebMDecoder::IsSupportedType(*type) || #ifdef MOZ_FMP4 MP4Decoder::IsSupportedType(*type, /* DecoderDoctorDiagnostics* */ nullptr) || #endif MP3Decoder::IsSupportedType(*type) || ADTSDecoder::IsSupportedType(*type) || FlacDecoder::IsSupportedType(*type) || #ifdef MOZ_ANDROID_HLS_SUPPORT HLSDecoder::IsSupportedType(*type) || #endif false; }
/* static */ bool DecoderTraits::ShouldHandleMediaType(const char* aMIMEType, DecoderDoctorDiagnostics* aDiagnostics) { Maybe<MediaContainerType> containerType = MakeMediaContainerType(aMIMEType); if (!containerType) { return false; } if (WaveDecoder::IsSupportedType(*containerType)) { // We should not return true for Wave types, since there are some // Wave codecs actually in use in the wild that we don't support, and // we should allow those to be handled by plugins or helper apps. // Furthermore people can play Wave files on most platforms by other // means. return false; } // If an external plugin which can handle quicktime video is available // (and not disabled), prefer it over native playback as there several // codecs found in the wild that we do not handle. if (containerType->Type() == MEDIAMIMETYPE("video/quicktime")) { RefPtr<nsPluginHost> pluginHost = nsPluginHost::GetInst(); if (pluginHost && pluginHost->HavePluginForType(containerType->Type().AsString())) { return false; } } return CanHandleMediaType(*containerType, aDiagnostics) != CANPLAY_NO; }
already_AddRefed<SourceBuffer> MediaSource::AddSourceBuffer(const nsAString& aType, ErrorResult& aRv) { MOZ_ASSERT(NS_IsMainThread()); DecoderDoctorDiagnostics diagnostics; nsresult rv = IsTypeSupported(aType, &diagnostics); diagnostics.StoreFormatDiagnostics(GetOwner() ? GetOwner()->GetExtantDoc() : nullptr, aType, NS_SUCCEEDED(rv), __func__); MSE_API("AddSourceBuffer(aType=%s)%s", NS_ConvertUTF16toUTF8(aType).get(), rv == NS_OK ? "" : " [not supported]"); if (NS_FAILED(rv)) { aRv.Throw(rv); return nullptr; } if (mSourceBuffers->Length() >= MAX_SOURCE_BUFFERS) { aRv.Throw(NS_ERROR_DOM_QUOTA_EXCEEDED_ERR); return nullptr; } if (mReadyState != MediaSourceReadyState::Open) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; } Maybe<MediaContainerType> containerType = MakeMediaContainerType(aType); if (!containerType) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return nullptr; } RefPtr<SourceBuffer> sourceBuffer = new SourceBuffer(this, *containerType); if (!sourceBuffer) { aRv.Throw(NS_ERROR_FAILURE); // XXX need a better error here return nullptr; } mSourceBuffers->Append(sourceBuffer); DDLINKCHILD("sourcebuffer[]", sourceBuffer.get()); MSE_DEBUG("sourceBuffer=%p", sourceBuffer.get()); return sourceBuffer.forget(); }
bool HTMLLinkElement::CheckPreloadAttrs(const nsAttrValue& aAs, const nsAString& aType, const nsAString& aMedia, Document* aDocument) { nsContentPolicyType policyType = Link::AsValueToContentPolicy(aAs); if (policyType == nsIContentPolicy::TYPE_INVALID) { return false; } // Check if media attribute is valid. if (!aMedia.IsEmpty()) { RefPtr<MediaList> mediaList = MediaList::Create(aMedia); if (!mediaList->Matches(*aDocument)) { return false; } } if (aType.IsEmpty()) { return true; } nsString type = nsString(aType); ToLowerCase(type); if (policyType == nsIContentPolicy::TYPE_OTHER) { return true; } else if (policyType == nsIContentPolicy::TYPE_MEDIA) { if (aAs.GetEnumValue() == DESTINATION_TRACK) { if (type.EqualsASCII("text/vtt")) { return true; } else { return false; } } Maybe<MediaContainerType> mimeType = MakeMediaContainerType(aType); if (!mimeType) { return false; } DecoderDoctorDiagnostics diagnostics; CanPlayStatus status = DecoderTraits::CanHandleContainerType(*mimeType, &diagnostics); // Preload if this return CANPLAY_YES and CANPLAY_MAYBE. if (status == CANPLAY_NO) { return false; } else { return true; } } else if (policyType == nsIContentPolicy::TYPE_FONT) { if (IsFontMimeType(type)) { return true; } else { return false; } } else if (policyType == nsIContentPolicy::TYPE_IMAGE) { if (imgLoader::SupportImageWithMimeType( NS_ConvertUTF16toUTF8(type).get(), AcceptedMimeTypes::IMAGES_AND_DOCUMENTS)) { return true; } else { return false; } } else if (policyType == nsIContentPolicy::TYPE_SCRIPT) { if (nsContentUtils::IsJavascriptMIMEType(type)) { return true; } else { return false; } } else if (policyType == nsIContentPolicy::TYPE_STYLESHEET) { if (type.EqualsASCII("text/css")) { return true; } else { return false; } } return false; }
Maybe<MediaContainerType> MakeMediaContainerType(const char* aType) { if (!aType) { return Nothing(); } return MakeMediaContainerType(nsDependentCString(aType)); }
Maybe<MediaContainerType> MakeMediaContainerType(const nsACString& aType) { return MakeMediaContainerType(NS_ConvertUTF8toUTF16(aType)); }