Bug 1423901 - Update cubeb from upstream to a88bf02. r?padenot draft
authorAlex Chronopoulos <achronop@gmail.com>
Thu, 07 Dec 2017 16:42:20 +0200
changeset 709073 303122afdf003557c446157a6998c8f6140f9484
parent 709072 441bb5af46ac8c5d51a620343d29ed18ccd0dc45
child 743317 0539805d2bfa79fa0cabdf86bc2b59e6cc933331
push id92528
push userachronop@gmail.com
push dateThu, 07 Dec 2017 14:43:32 +0000
reviewerspadenot
bugs1423901
milestone59.0a1
Bug 1423901 - Update cubeb from upstream to a88bf02. r?padenot MozReview-Commit-ID: Kk8IwJZY0Mt
media/libcubeb/README_MOZILLA
media/libcubeb/src/cubeb_audiounit.cpp
media/libcubeb/src/cubeb_wasapi.cpp
--- a/media/libcubeb/README_MOZILLA
+++ b/media/libcubeb/README_MOZILLA
@@ -1,8 +1,8 @@
 The source from this directory was copied from the cubeb 
 git repository using the update.sh script.  The only changes
 made were those applied by update.sh and the addition of
 Makefile.in build files for the Mozilla build system.
 
 The cubeb git repository is: git://github.com/kinetiknz/cubeb.git
 
-The git commit ID used was e17ba01b210b00fc15a33cad242286acb15a3492 (2017-11-28 16:18:38 +0200)
+The git commit ID used was a88bf027a27038feedca386efe5801350832dd91 (2017-12-07 16:23:55 +0200)
--- a/media/libcubeb/src/cubeb_audiounit.cpp
+++ b/media/libcubeb/src/cubeb_audiounit.cpp
@@ -1747,31 +1747,34 @@ audiounit_create_aggregate_device(cubeb_
 
   r = audiounit_activate_clock_drift_compensation(stm->aggregate_device_id);
   if (r != CUBEB_OK) {
     LOG("(%p) Failed to activate clock drift compensation for aggregate device", stm);
     audiounit_destroy_aggregate_device(stm->plugin_id, &stm->aggregate_device_id);
     return  CUBEB_ERROR;
   }
 
-  if (input_nominal_rate != output_nominal_rate) {
-    Float64 rate = std::min(input_nominal_rate, output_nominal_rate);
+  /* Do not attempt to change the nominal rate if it's the same with the nominal rate of
+   * output device because it's the master device and rate will set to that anyway. */
+  uint32_t min_rate = std::min(input_nominal_rate, output_nominal_rate);
+  if (input_nominal_rate != output_nominal_rate && min_rate != output_nominal_rate) {
+    LOG("Update aggregate device rate to %u", min_rate);
+    Float64 rate = min_rate;
     AudioObjectPropertyAddress addr = {kAudioDevicePropertyNominalSampleRate,
                                        kAudioObjectPropertyScopeGlobal,
                                        kAudioObjectPropertyElementMaster};
 
     OSStatus rv = AudioObjectSetPropertyData(stm->aggregate_device_id,
                                              &addr,
                                              0,
                                              nullptr,
                                              sizeof(Float64),
                                              &rate);
     if (rv != noErr) {
-      LOG("AudioObjectSetPropertyData/kAudioDevicePropertyNominalSampleRate, rv=%d", rv);
-      return CUBEB_ERROR;
+      LOG("Non fatal error, AudioObjectSetPropertyData/kAudioDevicePropertyNominalSampleRate, rv=%d", rv);
     }
   }
 
   return CUBEB_OK;
 }
 
 static int
 audiounit_destroy_aggregate_device(AudioObjectID plugin_id, AudioDeviceID * aggregate_device_id)
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -494,19 +494,31 @@ mask_to_channel_layout(WAVEFORMATEX cons
     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;
+    // Special case similar to MASK_2F2 but with rear left and right
+    // speakers instead of side left and right. This mapping is a band-aid as
+    // cubeb does not current have an enum to differentiate this and MASK_2F2,
+    // but is preferred to returning an undefined layout.
+    // See: https://github.com/kinetiknz/cubeb/issues/178 and https://bugzilla.mozilla.org/show_bug.cgi?id=1325023
+    case KSAUDIO_SPEAKER_QUAD: return CUBEB_LAYOUT_2F2;
     case MASK_2F2_LFE: return CUBEB_LAYOUT_2F2_LFE;
     case MASK_3F2: return CUBEB_LAYOUT_3F2;
     case MASK_3F2_LFE: return CUBEB_LAYOUT_3F2_LFE;
+    // Special case similar to MASK_3F2_LFE but with rear left and right
+    // speakers instead of side left and right. his mapping is a band-aid as
+    // cubeb does not current have an enum to differentiate this and MASK_3F2_LFE,
+    // but is preferred to returning an undefined layout.
+    // See: https://github.com/kinetiknz/cubeb/issues/178 and https://bugzilla.mozilla.org/show_bug.cgi?id=1325023
+    case KSAUDIO_SPEAKER_5POINT1: return CUBEB_LAYOUT_3F2_LFE;
     case MASK_3F3R_LFE: return CUBEB_LAYOUT_3F3R_LFE;
     case MASK_3F4_LFE: return CUBEB_LAYOUT_3F4_LFE;
     default: return CUBEB_LAYOUT_UNDEFINED;
   }
 }
 
 uint32_t
 get_rate(cubeb_stream * stm)
@@ -545,16 +557,17 @@ frames_to_bytes_before_mix(cubeb_stream 
 
 /* This function handles the processing of the input and output audio,
  * converting it to rate and channel layout specified at initialization.
  * It then calls the data callback, via the resampler. */
 long
 refill(cubeb_stream * stm, void * input_buffer, long input_frames_count,
        void * output_buffer, long output_frames_needed)
 {
+  XASSERT(!stm->draining);
   /* If we need to upmix after resampling, resample into the mix buffer to
      avoid a copy. */
   void * dest = nullptr;
   if (has_output(stm)) {
     if (cubeb_should_mix(&stm->output_stream_params, &stm->output_mix_params)) {
       dest = stm->mix_buffer.data();
     } else {
       dest = output_buffer;
@@ -751,16 +764,20 @@ refill_callback_duplex(cubeb_stream * st
   }
 
   /* This can only happen when debugging, and having breakpoints set in the
    * callback in a way that it makes the stream underrun. */
   if (output_frames == 0) {
     return true;
   }
 
+  /* Wait for draining is not important on duplex. */
+  if (stm->draining) {
+    return false;
+  }
 
   ALOGV("Duplex callback: input frames: %Iu, output frames: %Iu",
         input_frames, output_frames);
 
   refill(stm,
          stm->linear_input_buffer->data(),
          input_frames,
          output_buffer,
@@ -1567,17 +1584,17 @@ int setup_wasapi_stream_one_side(cubeb_s
     handle_channel_layout(stm, direction, mix_format, stream_params);
   }
 
   mix_params->format = stream_params->format;
   mix_params->rate = mix_format->nSamplesPerSec;
   mix_params->channels = mix_format->nChannels;
   mix_params->layout = mask_to_channel_layout(mix_format.get());
   if (mix_params->layout == CUBEB_LAYOUT_UNDEFINED) {
-    LOG("Output using undefined layout!\n");
+    LOG("Stream using undefined layout! Any mixing may be unpredictable!\n");
   } else if (mix_format->nChannels != CUBEB_CHANNEL_LAYOUT_MAPS[mix_params->layout].channels) {
     // The CUBEB_CHANNEL_LAYOUT_MAPS[mix_params->layout].channels may be
     // different from the mix_params->channels. 6 channel ouput with stereo
     // layout is acceptable in Windows. If this happens, it should not downmix
     // audio according to layout.
     LOG("Channel count is different from the layout standard!\n");
   }
   LOG("Setup requested=[f=%d r=%u c=%u l=%s] mix=[f=%d r=%u c=%u l=%s]",