Bug 1426174 - New reentrant get layout method to solve synchronization issues. r=jesup
authorAlex Chronopoulos <achronop@gmail.com>
Wed, 20 Dec 2017 20:52:06 +0200
changeset 448787 50dfae23ef9583bff536d60b78aa6bbc8ba84830
parent 448786 24eff1df1d3bf865f0f9befaca9b9ed9e998cb54
child 448788 4ae5f2caa47120e4247d7d09f11fcc4f77357cd8
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1426174
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1426174 - New reentrant get layout method to solve synchronization issues. r=jesup MozReview-Commit-ID: JwOAjuO22bd
dom/media/CubebUtils.cpp
dom/media/CubebUtils.h
dom/media/GraphDriver.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -355,16 +355,31 @@ uint32_t PreferredChannelMap(uint32_t aC
       kLayoutInfos[sPreferredChannelLayout].channels != aChannels) {
     AudioConfig::ChannelLayout smpteLayout(aChannels);
     return smpteLayout.Map();
   }
 
   return kLayoutInfos[sPreferredChannelLayout].mask;
 }
 
+cubeb_channel_layout GetPreferredChannelLayoutOrSMPTE(cubeb* context, uint32_t aChannels)
+{
+  cubeb_channel_layout layout = CUBEB_LAYOUT_UNDEFINED;
+  if (cubeb_get_preferred_channel_layout(context, &layout) != CUBEB_OK) {
+    return layout; //undefined
+  }
+
+  if (kLayoutInfos[layout].channels != aChannels) {
+    AudioConfig::ChannelLayout smpteLayout(aChannels);
+    return ConvertChannelMapToCubebLayout(smpteLayout.Map());
+  }
+
+  return layout;
+}
+
 void InitBrandName()
 {
   if (sBrandName) {
     return;
   }
   nsAutoString brandName;
   nsCOMPtr<nsIStringBundleService> stringBundleService =
     mozilla::services::GetStringBundleService();
--- a/dom/media/CubebUtils.h
+++ b/dom/media/CubebUtils.h
@@ -48,12 +48,13 @@ void ReportCubebBackendUsed();
 uint32_t GetCubebPlaybackLatencyInMilliseconds();
 Maybe<uint32_t> GetCubebMSGLatencyInFrames();
 bool CubebLatencyPrefSet();
 cubeb_channel_layout ConvertChannelMapToCubebLayout(uint32_t aChannelMap);
 void GetCurrentBackend(nsAString& aBackend);
 void GetPreferredChannelLayout(nsAString& aLayout);
 void GetDeviceCollection(nsTArray<RefPtr<AudioDeviceInfo>>& aDeviceInfos,
                          Side aSide);
+cubeb_channel_layout GetPreferredChannelLayoutOrSMPTE(cubeb* context, uint32_t aChannels);
 } // namespace CubebUtils
 } // namespace mozilla
 
 #endif // CubebUtils_h_
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -620,17 +620,17 @@ AudioCallbackDriver::Init()
     FallbackToSystemClockDriver();
     return true;
   }
 
   mBuffer = AudioCallbackBufferWrapper<AudioDataValue>(mOutputChannels);
   mScratchBuffer = SpillBuffer<AudioDataValue, WEBAUDIO_BLOCK_SIZE * 2>(mOutputChannels);
 
   output.channels = mOutputChannels;
-  output.layout = CubebUtils::ConvertChannelMapToCubebLayout(CubebUtils::PreferredChannelMap(mOutputChannels));
+  output.layout = CubebUtils::GetPreferredChannelLayoutOrSMPTE(cubebContext, mOutputChannels);
 
   Maybe<uint32_t> latencyPref = CubebUtils::GetCubebMSGLatencyInFrames();
   if (latencyPref) {
     latency_frames = latencyPref.value();
   } else {
     if (cubeb_get_min_latency(cubebContext, &output, &latency_frames) != CUBEB_OK) {
       NS_WARNING("Could not get minimal latency from cubeb.");
     }