Bug 1432779 - P4. Remove the concept of preferred layout. r=padenot,r=kamidphish
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 31 Jan 2018 19:08:51 +0100
changeset 463332 4e8af01f19c29b43c1f0606d1fac0d262c777b40
parent 463331 075811af8d4aeaa4f4895917fc49d66f8026d3b0
child 463333 52a4fb079d6c5bfe87bfcc0fbff7ec57a4ecab8e
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot, kamidphish
bugs1432779
milestone61.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 1432779 - P4. Remove the concept of preferred layout. r=padenot,r=kamidphish Channel layout is derived by the content being played. The concept of preferred layout is meaningless. Either we have a layout defined, or we don't. There's no in-between. So we remove it. MozReview-Commit-ID: CSCAInNmzMS
dom/base/nsDOMWindowUtils.cpp
dom/interfaces/base/nsIDOMWindowUtils.idl
dom/media/AudioStream.cpp
dom/media/AudioStream.h
dom/media/CubebUtils.cpp
dom/media/CubebUtils.h
dom/media/GraphDriver.cpp
dom/media/MediaPrefs.h
dom/media/mediasink/AudioSink.cpp
toolkit/content/aboutSupport.js
toolkit/modules/Troubleshoot.jsm
toolkit/modules/tests/browser/browser_Troubleshoot.js
--- a/dom/base/nsDOMWindowUtils.cpp
+++ b/dom/base/nsDOMWindowUtils.cpp
@@ -2324,23 +2324,16 @@ nsDOMWindowUtils::GetCurrentAudioBackend
 NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentMaxAudioChannels(uint32_t* aChannels)
 {
   *aChannels = CubebUtils::MaxNumberOfChannels();
   return NS_OK;
 }
 
 NS_IMETHODIMP
-nsDOMWindowUtils::GetCurrentPreferredChannelLayout(nsAString& aLayout)
-{
-  CubebUtils::GetPreferredChannelLayout(aLayout);
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsDOMWindowUtils::GetCurrentPreferredSampleRate(uint32_t* aRate)
 {
   *aRate = CubebUtils::PreferredSampleRate();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMWindowUtils::AudioDevices(uint16_t aSide, nsIArray** aDevices)
--- a/dom/interfaces/base/nsIDOMWindowUtils.idl
+++ b/dom/interfaces/base/nsIDOMWindowUtils.idl
@@ -1289,21 +1289,16 @@ interface nsIDOMWindowUtils : nsISupport
   readonly attribute AString currentAudioBackend;
 
   /**
    * Returns the max channel counts of the current audio device.
    */
   readonly attribute unsigned long currentMaxAudioChannels;
 
   /**
-   * Returns the preferred channel layout of the current audio device.
-   */
-  readonly attribute AString currentPreferredChannelLayout;
-
-  /**
    * Returns the preferred sample rate of the current audio device.
    */
   readonly attribute unsigned long currentPreferredSampleRate;
 
   /**
    * Returns all the audio input/output devices.
    */
   const unsigned short AUDIO_INPUT   = 0;
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -343,17 +343,17 @@ AudioStream::Init(uint32_t aNumChannels,
   mChannels = aNumChannels;
   mOutChannels = aNumChannels;
 
   mDumpFile = OpenDumpFile(aNumChannels, aRate);
 
   cubeb_stream_params params;
   params.rate = aRate;
   params.channels = mOutChannels;
-  params.layout = CubebUtils::ConvertChannelMapToCubebLayout(aChannelMap);
+  params.layout = CUBEB_LAYOUT_UNDEFINED;
   params.format = ToCubebFormat<AUDIO_OUTPUT_FORMAT>::value;
   params.prefs = CUBEB_STREAM_PREF_NONE;
 
   mAudioClock.Init(aRate);
 
   cubeb* cubebContext = CubebUtils::GetCubebContext();
   if (!cubebContext) {
     LOGE("Can't get cubeb context!");
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -230,21 +230,16 @@ public:
   // was opened, of the audio hardware.  Thread-safe.
   int64_t GetPositionInFrames();
 
   static uint32_t GetPreferredRate()
   {
     return CubebUtils::PreferredSampleRate();
   }
 
-  static uint32_t GetPreferredChannelMap(uint32_t aChannels)
-  {
-    return CubebUtils::PreferredChannelMap(aChannels);
-  }
-
   uint32_t GetOutChannels() { return mOutChannels; }
 
   // Set playback rate as a multiple of the intrinsic playback rate. This is to
   // be called only with aPlaybackRate > 0.0.
   nsresult SetPlaybackRate(double aPlaybackRate);
   // Switch between resampling (if false) and time stretching (if true, default).
   nsresult SetPreservesPitch(bool aPreservesPitch);
 
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -199,21 +199,16 @@ const layoutInfo kLayoutInfos[CUBEB_LAYO
 // thread before fetching, after which it is safe to fetch without holding the
 // mutex because it is only written once per process execution (by the first
 // initialization to complete).  Since the init must have been called on a
 // given thread before fetching the value, it's guaranteed (via the mutex) that
 // sufficient memory barriers have occurred to ensure the correct value is
 // visible on the querying thread/CPU.
 uint32_t sPreferredSampleRate;
 
-// We only support SMPTE layout in cubeb for now. If the value is
-// CUBEB_LAYOUT_UNDEFINED, then it implies that the preferred layout is
-// non-SMPTE format.
-cubeb_channel_layout sPreferredChannelLayout;
-
 } // namespace
 
 static const uint32_t CUBEB_NORMAL_LATENCY_MS = 100;
 // Consevative default that can work on all platforms.
 static const uint32_t CUBEB_NORMAL_LATENCY_FRAMES = 1024;
 
 namespace CubebUtils {
 cubeb* GetCubebContextUnlocked();
@@ -340,69 +335,16 @@ uint32_t PreferredSampleRate()
   }
   if (!InitPreferredSampleRate()) {
     return 44100;
   }
   MOZ_ASSERT(sPreferredSampleRate);
   return sPreferredSampleRate;
 }
 
-bool InitPreferredChannelLayout()
-{
-  {
-    StaticMutexAutoLock lock(sMutex);
-    if (sPreferredChannelLayout != 0) {
-      return true;
-    }
-  }
-
-  cubeb* context = GetCubebContext();
-  if (!context) {
-    return false;
-  }
-
-  // Favor calling cubeb api with the mutex unlock, potential deadlock.
-  cubeb_channel_layout layout;
-  if (cubeb_get_preferred_channel_layout(context, &layout) != CUBEB_OK) {
-    return false;
-  }
-
-  StaticMutexAutoLock lock(sMutex);
-  sPreferredChannelLayout = layout;
-  return true;
-}
-
-uint32_t PreferredChannelMap(uint32_t aChannels)
-{
-  // Use SMPTE default channel map if we can't get preferred layout
-  // or the channel counts of preferred layout is different from input's one
-  if (!InitPreferredChannelLayout() ||
-      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();
@@ -636,63 +578,29 @@ uint32_t MaxNumberOfChannels()
       cubeb_get_max_channel_count(cubebContext,
                                   &maxNumberOfChannels) == CUBEB_OK) {
     return maxNumberOfChannels;
   }
 
   return 0;
 }
 
-cubeb_channel_layout ConvertChannelMapToCubebLayout(uint32_t aChannelMap)
-{
-  switch(aChannelMap) {
-    case MASK_MONO: return CUBEB_LAYOUT_MONO;
-    case MASK_MONO_LFE: return CUBEB_LAYOUT_MONO_LFE;
-    case MASK_STEREO: return CUBEB_LAYOUT_STEREO;
-    case MASK_STEREO_LFE: return CUBEB_LAYOUT_STEREO_LFE;
-    case MASK_3F: return CUBEB_LAYOUT_3F;
-    case MASK_3F_LFE: return CUBEB_LAYOUT_3F_LFE;
-    case MASK_2F1: return CUBEB_LAYOUT_2F1;
-    case MASK_2F1_LFE: return CUBEB_LAYOUT_2F1_LFE;
-    case MASK_3F1: return CUBEB_LAYOUT_3F1;
-    case MASK_3F1_LFE: return CUBEB_LAYOUT_3F1_LFE;
-    case MASK_2F2: return CUBEB_LAYOUT_2F2;
-    case MASK_2F2_LFE: return CUBEB_LAYOUT_2F2_LFE;
-    case MASK_QUAD: return CUBEB_LAYOUT_QUAD;
-    case MASK_QUAD_LFE: return CUBEB_LAYOUT_QUAD_LFE;
-    case MASK_3F2: return CUBEB_LAYOUT_3F2;
-    case MASK_3F2_LFE: return CUBEB_LAYOUT_3F2_LFE;
-    case MASK_3F3R_LFE: return CUBEB_LAYOUT_3F3R_LFE;
-    case MASK_3F4_LFE: return CUBEB_LAYOUT_3F4_LFE;
-    default:
-      NS_ERROR("The channel map is unsupported");
-      return CUBEB_LAYOUT_UNDEFINED;
-  }
-}
-
 void GetCurrentBackend(nsAString& aBackend)
 {
   cubeb* cubebContext = GetCubebContext();
   if (cubebContext) {
     const char* backend = cubeb_get_backend_id(cubebContext);
     if (backend) {
       aBackend.AssignASCII(backend);
       return;
     }
   }
   aBackend.AssignLiteral("unknown");
 }
 
-void GetPreferredChannelLayout(nsAString& aLayout)
-{
-  const char* layout = InitPreferredChannelLayout() ?
-    kLayoutInfos[sPreferredChannelLayout].name : "unknown";
-  aLayout.AssignASCII(layout);
-}
-
 uint16_t ConvertCubebType(cubeb_device_type aType)
 {
   uint16_t map[] = {
     nsIAudioDeviceInfo::TYPE_UNKNOWN, // CUBEB_DEVICE_TYPE_UNKNOWN
     nsIAudioDeviceInfo::TYPE_INPUT,   // CUBEB_DEVICE_TYPE_INPUT,
     nsIAudioDeviceInfo::TYPE_OUTPUT   // CUBEB_DEVICE_TYPE_OUTPUT
   };
   return map[aType];
--- a/dom/media/CubebUtils.h
+++ b/dom/media/CubebUtils.h
@@ -25,38 +25,32 @@ void InitLibrary();
 void ShutdownLibrary();
 
 // Returns the maximum number of channels supported by the audio hardware.
 uint32_t MaxNumberOfChannels();
 
 // Get the sample rate the hardware/mixer runs at. Thread safe.
 uint32_t PreferredSampleRate();
 
-// Get the bit mask of the connected audio device's preferred layout.
-uint32_t PreferredChannelMap(uint32_t aChannels);
-
 enum Side {
   Input,
   Output
 };
 
 double GetVolumeScale();
 bool GetFirstStream();
 cubeb* GetCubebContext();
 void ReportCubebStreamInitFailure(bool aIsFirstStream);
 void ReportCubebBackendUsed();
 uint32_t GetCubebPlaybackLatencyInMilliseconds();
 uint32_t GetCubebMSGLatencyInFrames(cubeb_stream_params * params);
 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);
 
 #ifdef MOZ_WIDGET_ANDROID
 uint32_t AndroidGetAudioOutputSampleRate();
 uint32_t AndroidGetAudioOutputFramesPerBuffer();
 #endif
 } // namespace CubebUtils
 } // namespace mozilla
 
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -625,17 +625,17 @@ AudioCallbackDriver::Init()
     FallbackToSystemClockDriver();
     return true;
   }
 
   mBuffer = AudioCallbackBufferWrapper<AudioDataValue>(mOutputChannels);
   mScratchBuffer = SpillBuffer<AudioDataValue, WEBAUDIO_BLOCK_SIZE * 2>(mOutputChannels);
 
   output.channels = mOutputChannels;
-  output.layout = CubebUtils::GetPreferredChannelLayoutOrSMPTE(cubebContext, mOutputChannels);
+  output.layout = CUBEB_LAYOUT_UNDEFINED;
   output.prefs = CUBEB_STREAM_PREF_NONE;
 
   uint32_t latency_frames = CubebUtils::GetCubebMSGLatencyInFrames(&output);
 
   // Macbook and MacBook air don't have enough CPU to run very low latency
   // MediaStreamGraphs, cap the minimal latency to 512 frames int this case.
   if (IsMacbookOrMacbookAir()) {
     latency_frames = std::max((uint32_t) 512, latency_frames);
--- a/dom/media/MediaPrefs.h
+++ b/dom/media/MediaPrefs.h
@@ -97,17 +97,16 @@ private:
 
   DECL_MEDIA_PREF("media.cache_resume_threshold",             MediaCacheResumeThreshold, int32_t, 10);
   DECL_MEDIA_PREF("media.cache_readahead_limit",              MediaCacheReadaheadLimit, int32_t, 30);
 
   // AudioSink
   DECL_MEDIA_PREF("accessibility.monoaudio.enable",           MonoAudio, bool, false);
   DECL_MEDIA_PREF("media.resampling.enabled",                 AudioSinkResampling, bool, false);
 #if defined(XP_WIN) || defined(XP_DARWIN) || defined(MOZ_PULSEAUDIO)
-  // libcubeb backend implement .get_preferred_channel_layout
   DECL_MEDIA_PREF("media.forcestereo.enabled",                AudioSinkForceStereo, bool, false);
 #else
   DECL_MEDIA_PREF("media.forcestereo.enabled",                AudioSinkForceStereo, bool, true);
 #endif
   // VideoSink
   DECL_MEDIA_PREF("media.ruin-av-sync.enabled",               RuinAvSync, bool, false);
 
   // Encrypted Media Extensions
--- a/dom/media/mediasink/AudioSink.cpp
+++ b/dom/media/mediasink/AudioSink.cpp
@@ -192,17 +192,17 @@ AudioSink::SetPlaying(bool aPlaying)
 nsresult
 AudioSink::InitializeAudioStream(const PlaybackParams& aParams)
 {
   mAudioStream = new AudioStream(*this);
   // When AudioQueue is empty, there is no way to know the channel layout of
   // the coming audio data, so we use the predefined channel map instead.
   uint32_t channelMap = mConverter
                         ? mConverter->OutputConfig().Layout().Map()
-                        : AudioStream::GetPreferredChannelMap(mOutputChannels);
+                        : AudioConfig::ChannelLayout(mOutputChannels).Map();
   // The layout map used here is already processed by mConverter with
   // mOutputChannels into SMPTE format, so there is no need to worry if
   // MediaPrefs::MonoAudio() or MediaPrefs::AudioSinkForceStereo() is applied.
   nsresult rv = mAudioStream->Init(mOutputChannels, channelMap, mOutputRate);
   if (NS_FAILED(rv)) {
     mAudioStream->Shutdown();
     mAudioStream = nullptr;
     return rv;
--- a/toolkit/content/aboutSupport.js
+++ b/toolkit/content/aboutSupport.js
@@ -706,17 +706,16 @@ var snapshotFormatters = {
         rows.push(createDeviceInfoRow(dev));
       }
       $.append($("media-" + side + "-devices-tbody"), rows);
     }
 
     // Basic information
     insertBasicInfo("audioBackend", data.currentAudioBackend);
     insertBasicInfo("maxAudioChannels", data.currentMaxAudioChannels);
-    insertBasicInfo("channelLayout", data.currentPreferredChannelLayout);
     insertBasicInfo("sampleRate", data.currentPreferredSampleRate);
 
     // Output devices information
     insertDeviceInfo("output", data.audioOutputDevices);
 
     // Input devices information
     insertDeviceInfo("input", data.audioInputDevices);
   },
--- a/toolkit/modules/Troubleshoot.jsm
+++ b/toolkit/modules/Troubleshoot.jsm
@@ -581,17 +581,16 @@ var dataProviders = {
     }
 
     let data = {};
     let winUtils = Services.wm.getMostRecentWindow("").
                    QueryInterface(Ci.nsIInterfaceRequestor).
                    getInterface(Ci.nsIDOMWindowUtils);
     data.currentAudioBackend = winUtils.currentAudioBackend;
     data.currentMaxAudioChannels = winUtils.currentMaxAudioChannels;
-    data.currentPreferredChannelLayout = winUtils.currentPreferredChannelLayout;
     data.currentPreferredSampleRate = winUtils.currentPreferredSampleRate;
     data.audioOutputDevices = convertDevices(winUtils.audioDevices(Ci.nsIDOMWindowUtils.AUDIO_OUTPUT).
                                              QueryInterface(Ci.nsIArray));
     data.audioInputDevices = convertDevices(winUtils.audioDevices(Ci.nsIDOMWindowUtils.AUDIO_INPUT).
                                             QueryInterface(Ci.nsIArray));
     done(data);
   },
 
--- a/toolkit/modules/tests/browser/browser_Troubleshoot.js
+++ b/toolkit/modules/tests/browser/browser_Troubleshoot.js
@@ -420,20 +420,16 @@ const SNAPSHOT_SCHEMA = {
         currentAudioBackend: {
           required: true,
           type: "string",
         },
         currentMaxAudioChannels: {
           required: true,
           type: "number",
         },
-        currentPreferredChannelLayout: {
-          required: true,
-          type: "string",
-        },
         currentPreferredSampleRate: {
           required: true,
           type: "number",
         },
         audioOutputDevices: {
           required: true,
           type: "array",
           items: {