Bug 1294616 - Somewhat improve the string performance by defining string literals whose length is known at compile time.
MozReview-Commit-ID: LAlqMDtGQN7
--- a/dom/media/VideoUtils.h
+++ b/dom/media/VideoUtils.h
@@ -35,19 +35,19 @@ using mozilla::CheckedUint32;
// remove this file in the near future.
// This belongs in xpcom/monitor/Monitor.h, once we've made
// mozilla::Monitor non-reentrant.
namespace mozilla {
// EME Key System String.
-static const char* const kEMEKeySystemClearkey = "org.w3.clearkey";
-static const char* const kEMEKeySystemWidevine = "com.widevine.alpha";
-static const char* const kEMEKeySystemPrimetime = "com.adobe.primetime";
+static NS_NAMED_LITERAL_CSTRING(kEMEKeySystemClearkey, "org.w3.clearkey");
+static NS_NAMED_LITERAL_CSTRING(kEMEKeySystemWidevine, "com.widevine.alpha");
+static NS_NAMED_LITERAL_CSTRING(kEMEKeySystemPrimetime, "com.adobe.primetime");
/**
* ReentrantMonitorConditionallyEnter
*
* Enters the supplied monitor only if the conditional value |aEnter| is true.
* E.g. Used to allow unmonitored read access on the decode thread,
* and monitored access on all other threads.
*/
--- a/dom/media/eme/EMEUtils.cpp
+++ b/dom/media/eme/EMEUtils.cpp
@@ -130,28 +130,28 @@ CopyArrayBufferViewOrArrayBufferData(con
return;
}
aOutData.AppendElements(data.mData, data.mLength);
}
nsString
KeySystemToGMPName(const nsAString& aKeySystem)
{
- if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemPrimetime, aKeySystem)) {
return NS_LITERAL_STRING("gmp-eme-adobe");
}
- if (aKeySystem.EqualsASCII(kEMEKeySystemClearkey)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemClearkey, aKeySystem)) {
return NS_LITERAL_STRING("gmp-clearkey");
}
- if (aKeySystem.EqualsASCII(kEMEKeySystemWidevine)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemWidevine, aKeySystem)) {
return NS_LITERAL_STRING("gmp-widevinecdm");
}
MOZ_ASSERT(false, "We should only call this for known GMPs");
return EmptyString();
}
bool
IsClearkeyKeySystem(const nsAString& aKeySystem)
{
- return aKeySystem.EqualsASCII(kEMEKeySystemClearkey);
+ return !CompareUTF8toUTF16(kEMEKeySystemClearkey, aKeySystem);
}
} // namespace mozilla
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -186,17 +186,17 @@ MediaKeySystemAccess::IsGMPPresentOnDisk
&result, &message);
aOutMessage = message;
return ok && result;
}
bool isPresent = true;
#if XP_WIN
- if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemPrimetime, aKeySystem)) {
if (!AdobePluginDLLExists(aVersion)) {
NS_WARNING("Adobe EME plugin disappeared from disk!");
aOutMessage = NS_LITERAL_CSTRING("Adobe DLL was expected to be on disk but was not");
isPresent = false;
}
if (!AdobePluginVoucherExists(aVersion)) {
NS_WARNING("Adobe EME voucher disappeared from disk!");
aOutMessage = NS_LITERAL_CSTRING("Adobe plugin voucher was expected to be on disk but was not");
@@ -271,39 +271,39 @@ MediaKeySystemAccess::GetKeySystemStatus
MOZ_ASSERT(MediaPrefs::EMEEnabled() || IsClearkeyKeySystem(aKeySystem));
nsCOMPtr<mozIGeckoMediaPluginService> mps =
do_GetService("@mozilla.org/gecko-media-plugin-service;1");
if (NS_WARN_IF(!mps)) {
aOutMessage = NS_LITERAL_CSTRING("Failed to get GMP service");
return MediaKeySystemStatus::Error;
}
- if (aKeySystem.EqualsASCII(kEMEKeySystemClearkey)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemClearkey, aKeySystem)) {
return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
}
if (Preferences::GetBool("media.gmp-eme-adobe.visible", false)) {
- if (aKeySystem.EqualsASCII(kEMEKeySystemPrimetime)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemPrimetime, aKeySystem)) {
if (!Preferences::GetBool("media.gmp-eme-adobe.enabled", false)) {
aOutMessage = NS_LITERAL_CSTRING("Adobe EME disabled");
return MediaKeySystemStatus::Cdm_disabled;
}
#ifdef XP_WIN
// Win Vista and later only.
if (!IsVistaOrLater()) {
aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version (Vista) not met for Adobe EME");
return MediaKeySystemStatus::Cdm_not_supported;
}
#endif
return EnsureMinCDMVersion(mps, aKeySystem, aMinCdmVersion, aOutMessage, aOutCdmVersion);
}
}
if (Preferences::GetBool("media.gmp-widevinecdm.visible", false)) {
- if (aKeySystem.EqualsASCII(kEMEKeySystemWidevine)) {
+ if (!CompareUTF8toUTF16(kEMEKeySystemWidevine, aKeySystem)) {
#ifdef XP_WIN
// Win Vista and later only.
if (!IsVistaOrLater()) {
aOutMessage = NS_LITERAL_CSTRING("Minimum Windows version (Vista) not met for Widevine EME");
return MediaKeySystemStatus::Cdm_not_supported;
}
#endif
if (!Preferences::GetBool("media.gmp-widevinecdm.enabled", false)) {
@@ -558,17 +558,17 @@ CanDecryptAndDecode(mozIGeckoMediaPlugin
#if defined(XP_WIN)
// Widevine CDM doesn't include an AAC decoder. So if WMF can't
// decode AAC, and a codec wasn't specified, be conservative
// and reject the MediaKeys request, since our policy is to prevent
// the Adobe GMP's unencrypted AAC decoding path being used to
// decode content decrypted by the Widevine CDM.
if (codec == GMP_CODEC_AAC &&
- aKeySystem.EqualsASCII(kEMEKeySystemWidevine) &&
+ !CompareUTF8toUTF16(kEMEKeySystemWidevine, aKeySystem) &&
!WMFDecoderModule::HasAAC()) {
if (aDiagnostics) {
aDiagnostics->SetKeySystemIssue(
DecoderDoctorDiagnostics::eWidevineWithNoWMF);
}
}
#endif
return false;
@@ -1125,17 +1125,17 @@ GetSupportedConfig(mozIGeckoMediaPluginS
}
}
// Note: Omitting steps 20-22. We don't ask for consent.
#if defined(XP_WIN)
// Widevine CDM doesn't include an AAC decoder. So if WMF can't decode AAC,
// and a codec wasn't specified, be conservative and reject the MediaKeys request.
- if (aKeySystem.mKeySystem.EqualsASCII(kEMEKeySystemWidevine) &&
+ if (!CompareUTF8toUTF16(kEMEKeySystemWidevine, aKeySystem.mKeySystem) &&
(aCandidate.mAudioCapabilities.IsEmpty() ||
aCandidate.mVideoCapabilities.IsEmpty()) &&
!WMFDecoderModule::HasAAC()) {
if (aDiagnostics) {
aDiagnostics->SetKeySystemIssue(
DecoderDoctorDiagnostics::eWidevineWithNoWMF);
}
EME_LOG("MediaKeySystemConfiguration (label='%s') rejected; "
--- a/dom/media/eme/MediaKeySystemAccessManager.cpp
+++ b/dom/media/eme/MediaKeySystemAccessManager.cpp
@@ -137,18 +137,18 @@ MediaKeySystemAccessManager::Request(Det
minCdmVersion,
MediaKeySystemStatusValues::strings[(size_t)status].value,
cdmVersion.get(),
message.get());
LogToBrowserConsole(NS_ConvertUTF8toUTF16(msg));
if ((status == MediaKeySystemStatus::Cdm_not_installed ||
status == MediaKeySystemStatus::Cdm_insufficient_version) &&
- (keySystem.EqualsASCII(kEMEKeySystemPrimetime) ||
- keySystem.EqualsASCII(kEMEKeySystemWidevine))) {
+ (!CompareUTF8toUTF16(kEMEKeySystemPrimetime, keySystem) ||
+ !CompareUTF8toUTF16(kEMEKeySystemWidevine, keySystem))) {
// These are cases which could be resolved by downloading a new(er) CDM.
// When we send the status to chrome, chrome's GMPProvider will attempt to
// download or update the CDM. In AwaitInstall() we add listeners to wait
// for the update to complete, and we'll call this function again with
// aType==Subsequent once the download has completed and the GMPService
// has had a new plugin added. AwaitInstall() sets a timer to fail if the
// update/download takes too long or fails.
if (aType == RequestType::Initial &&
--- a/dom/media/gmp/GMPParent.cpp
+++ b/dom/media/gmp/GMPParent.cpp
@@ -894,17 +894,17 @@ GMPParent::ReadGMPInfoFile(nsIFile* aFil
mDisplayName.get());
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
}
#endif
#ifdef XP_WIN
// Adobe GMP doesn't work without SSE2. Check the tags to see if
// the decryptor is for the Adobe GMP, and refuse to load it if
// SSE2 isn't supported.
- if (cap.mAPITags.Contains(nsCString(kEMEKeySystemPrimetime)) &&
+ if (cap.mAPITags.Contains(kEMEKeySystemPrimetime) &&
!mozilla::supports_sse2()) {
return GenericPromise::CreateAndReject(NS_ERROR_FAILURE, __func__);
}
#endif // XP_WIN
}
mCapabilities.AppendElement(Move(cap));
}
@@ -951,21 +951,21 @@ GMPParent::ParseChromiumManifest(nsStrin
mDisplayName = NS_ConvertUTF16toUTF8(m.mName);
mDescription = NS_ConvertUTF16toUTF8(m.mDescription);
mVersion = NS_ConvertUTF16toUTF8(m.mVersion);
GMPCapability video(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER));
video.mAPITags.AppendElement(NS_LITERAL_CSTRING("h264"));
video.mAPITags.AppendElement(NS_LITERAL_CSTRING("vp8"));
video.mAPITags.AppendElement(NS_LITERAL_CSTRING("vp9"));
- video.mAPITags.AppendElement(nsCString(kEMEKeySystemWidevine));
+ video.mAPITags.AppendElement(kEMEKeySystemWidevine);
mCapabilities.AppendElement(Move(video));
GMPCapability decrypt(NS_LITERAL_CSTRING(GMP_API_DECRYPTOR));
- decrypt.mAPITags.AppendElement(nsCString(kEMEKeySystemWidevine));
+ decrypt.mAPITags.AppendElement(kEMEKeySystemWidevine);
mCapabilities.AppendElement(Move(decrypt));
MOZ_ASSERT(mName.EqualsLiteral("widevinecdm"));
mAdapter = NS_LITERAL_STRING("widevine");
#ifdef XP_WIN
mLibs = NS_LITERAL_CSTRING("dxva2.dll");
#endif
--- a/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
+++ b/dom/media/gmp/widevine-adapter/WidevineAdapter.cpp
@@ -105,18 +105,18 @@ WidevineAdapter::GMPGetAPI(const char* a
aAPIName, aHostAPI, aPluginAPI, this);
return GMPGenericErr;
}
WidevineDecryptor* decryptor = new WidevineDecryptor();
auto cdm = reinterpret_cast<cdm::ContentDecryptionModule*>(
create(cdm::ContentDecryptionModule::kVersion,
- kEMEKeySystemWidevine,
- strlen(kEMEKeySystemWidevine),
+ kEMEKeySystemWidevine.get(),
+ kEMEKeySystemWidevine.Length(),
&GetCdmHost,
decryptor));
if (!cdm) {
Log("WidevineAdapter::GMPGetAPI(%s, 0x%p, 0x%p) this=0x%p FAILED to create cdm",
aAPIName, aHostAPI, aPluginAPI, this);
return GMPGenericErr;
}
Log("cdm: 0x%x", cdm);
--- a/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
+++ b/dom/media/platforms/agnostic/gmp/GMPDecoderModule.cpp
@@ -137,17 +137,17 @@ HasGMPFor(const nsACString& aAPI,
return false;
}
return hasPlugin;
}
StaticMutex sGMPCodecsMutex;
struct GMPCodecs {
- const char* mKeySystem;
+ const nsLiteralCString mKeySystem;
bool mHasAAC;
bool mHasH264;
bool mHasVP8;
bool mHasVP9;
};
static GMPCodecs sGMPCodecs[] = {
{ kEMEKeySystemClearkey, false, false, false, false },
@@ -159,26 +159,26 @@ void
GMPDecoderModule::UpdateUsableCodecs()
{
MOZ_ASSERT(NS_IsMainThread());
StaticMutexAutoLock lock(sGMPCodecsMutex);
for (GMPCodecs& gmp : sGMPCodecs) {
gmp.mHasAAC = HasGMPFor(NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER),
NS_LITERAL_CSTRING("aac"),
- nsDependentCString(gmp.mKeySystem));
+ gmp.mKeySystem);
gmp.mHasH264 = HasGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
NS_LITERAL_CSTRING("h264"),
- nsDependentCString(gmp.mKeySystem));
+ gmp.mKeySystem);
gmp.mHasVP8 = HasGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
- NS_LITERAL_CSTRING("vp8"),
- nsDependentCString(gmp.mKeySystem));
+ NS_LITERAL_CSTRING("vp8"),
+ gmp.mKeySystem);
gmp.mHasVP9 = HasGMPFor(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
- NS_LITERAL_CSTRING("vp9"),
- nsDependentCString(gmp.mKeySystem));
+ NS_LITERAL_CSTRING("vp9"),
+ gmp.mKeySystem);
}
}
/* static */
void
GMPDecoderModule::Init()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -190,26 +190,26 @@ GMPDecoderModule::Init()
/* static */
const Maybe<nsCString>
GMPDecoderModule::PreferredGMP(const nsACString& aMimeType)
{
Maybe<nsCString> rv;
if (aMimeType.EqualsLiteral("audio/mp4a-latm")) {
switch (MediaPrefs::GMPAACPreferred()) {
- case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
- case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
+ case 1: rv.emplace(kEMEKeySystemClearkey); break;
+ case 2: rv.emplace(kEMEKeySystemPrimetime); break;
default: break;
}
}
if (MP4Decoder::IsH264(aMimeType)) {
switch (MediaPrefs::GMPH264Preferred()) {
- case 1: rv.emplace(nsCString(kEMEKeySystemClearkey)); break;
- case 2: rv.emplace(nsCString(kEMEKeySystemPrimetime)); break;
+ case 1: rv.emplace(kEMEKeySystemClearkey); break;
+ case 2: rv.emplace(kEMEKeySystemPrimetime); break;
default: break;
}
}
return rv;
}
/* static */
@@ -218,17 +218,17 @@ GMPDecoderModule::SupportsMimeType(const
const Maybe<nsCString>& aGMP)
{
StaticMutexAutoLock lock(sGMPCodecsMutex);
for (GMPCodecs& gmp : sGMPCodecs) {
if (((aMimeType.EqualsLiteral("audio/mp4a-latm") && gmp.mHasAAC) ||
(MP4Decoder::IsH264(aMimeType) && gmp.mHasH264) ||
(VPXDecoder::IsVP8(aMimeType) && gmp.mHasVP8) ||
(VPXDecoder::IsVP9(aMimeType) && gmp.mHasVP9)) &&
- (aGMP.isNothing() || aGMP.value().EqualsASCII(gmp.mKeySystem))) {
+ (aGMP.isNothing() || aGMP.value().Equals(gmp.mKeySystem))) {
return true;
}
}
return false;
}
bool