Bug 845648 - Use shortBrand for the name of cubeb streams. r=kinetik

MozReview-Commit-ID: 1PUY8wHVOxy
This commit is contained in:
Paul Adenot 2016-06-08 17:29:38 +02:00
Родитель ffd9e007e6
Коммит c29cb7b0f6
1 изменённых файлов: 45 добавлений и 4 удалений

Просмотреть файл

@ -6,8 +6,13 @@
#include <stdint.h> #include <stdint.h>
#include <algorithm> #include <algorithm>
#include "nsIStringBundle.h"
#include "nsDebug.h"
#include "nsString.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/StaticMutex.h" #include "mozilla/StaticMutex.h"
#include "mozilla/StaticPtr.h"
#include "nsThreadUtils.h"
#include "CubebUtils.h" #include "CubebUtils.h"
#include "nsAutoRef.h" #include "nsAutoRef.h"
#include "prdtoa.h" #include "prdtoa.h"
@ -25,6 +30,9 @@ cubeb* sCubebContext;
double sVolumeScale; double sVolumeScale;
uint32_t sCubebLatency; uint32_t sCubebLatency;
bool sCubebLatencyPrefSet; bool sCubebLatencyPrefSet;
StaticAutoPtr<char> sBrandName;
const char kBrandBundleURL[] = "chrome://branding/locale/brand.properties";
// Prefered samplerate, in Hz (characteristic of the hardware, mixer, platform, // Prefered samplerate, in Hz (characteristic of the hardware, mixer, platform,
// and API used). // and API used).
@ -101,15 +109,46 @@ void InitPreferredSampleRate()
} }
} }
void InitBrandName()
{
if (sBrandName) {
return;
}
nsXPIDLString brandName;
nsCOMPtr<nsIStringBundleService> stringBundleService =
mozilla::services::GetStringBundleService();
if (stringBundleService) {
nsCOMPtr<nsIStringBundle> brandBundle;
nsresult rv = stringBundleService->CreateBundle(kBrandBundleURL,
getter_AddRefs(brandBundle));
if (NS_SUCCEEDED(rv)) {
rv = brandBundle->GetStringFromName(MOZ_UTF16("brandShortName"),
getter_Copies(brandName));
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
"Could not get the program name for a cubeb stream.");
}
}
/* cubeb expects a c-string. */
const char* ascii = NS_LossyConvertUTF16toASCII(brandName).get();
sBrandName = new char[brandName.Length() + 1];
PodCopy(sBrandName.get(), ascii, brandName.Length());
sBrandName[brandName.Length()] = 0;
}
cubeb* GetCubebContextUnlocked() cubeb* GetCubebContextUnlocked()
{ {
sMutex.AssertCurrentThreadOwns(); sMutex.AssertCurrentThreadOwns();
if (sCubebContext || if (sCubebContext) {
cubeb_init(&sCubebContext, "CubebUtils") == CUBEB_OK) {
return sCubebContext; return sCubebContext;
} }
NS_WARNING("cubeb_init failed");
return nullptr; NS_WARN_IF_FALSE(sBrandName, "Could not get brandName?");
NS_WARN_IF_FALSE(
cubeb_init(&sCubebContext, sBrandName) == CUBEB_OK,
"Could not get a cubeb context.");
return sCubebContext;
} }
uint32_t GetCubebLatency() uint32_t GetCubebLatency()
@ -130,6 +169,7 @@ void InitLibrary()
Preferences::RegisterCallback(PrefChanged, PREF_VOLUME_SCALE); Preferences::RegisterCallback(PrefChanged, PREF_VOLUME_SCALE);
PrefChanged(PREF_CUBEB_LATENCY, nullptr); PrefChanged(PREF_CUBEB_LATENCY, nullptr);
Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_LATENCY); Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_LATENCY);
NS_DispatchToMainThread(NS_NewRunnableFunction(&InitBrandName));
} }
void ShutdownLibrary() void ShutdownLibrary()
@ -142,6 +182,7 @@ void ShutdownLibrary()
cubeb_destroy(sCubebContext); cubeb_destroy(sCubebContext);
sCubebContext = nullptr; sCubebContext = nullptr;
} }
sBrandName = nullptr;
} }
uint32_t MaxNumberOfChannels() uint32_t MaxNumberOfChannels()