Bug 971693 - Fallback properly when WASAPI does not give us a stream format suggestion. r=kinetik
authorPaul Adenot <paul@paul.cx>
Thu, 27 Feb 2014 14:36:58 +0100
changeset 171290 7a8e0a49b3f67f1d5a4dce0bbacadcd476d2d40e
parent 171289 95fd860273067e84e81e4f88eb4b12e69e8e638b
child 171291 9b0bf77d6f244185cff30fcfe2a3ba2718df9cf9
push id270
push userpvanderbeken@mozilla.com
push dateThu, 06 Mar 2014 09:24:21 +0000
reviewerskinetik
bugs971693
milestone30.0a1
Bug 971693 - Fallback properly when WASAPI does not give us a stream format suggestion. r=kinetik
media/libcubeb/src/cubeb_wasapi.cpp
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -636,16 +636,17 @@ handle_channel_layout(cubeb_stream * stm
 {
   /* Common case: the hardware is stereo. Up-mixing and down-mixing will be
    * handled in the callback. */
   if ((*mix_format)->nChannels <= 2) {
     return;
   }
 
   /* Otherwise, the hardware supports more than two channels. */
+  WAVEFORMATEX hw_mixformat = **mix_format;
 
   /* The docs say that GetMixFormat is always of type WAVEFORMATEXTENSIBLE [1],
    * so the reinterpret_cast below should be safe. In practice, this is not
    * true, and we just want to bail out and let the rest of the code find a good
    * conversion path instead of trying to make WASAPI do it by itself.
    * [1]: http://msdn.microsoft.com/en-us/library/windows/desktop/dd370811%28v=vs.85%29.aspx*/
   if ((*mix_format)->wFormatTag != WAVE_FORMAT_EXTENSIBLE) {
     return;
@@ -683,18 +684,19 @@ handle_channel_layout(cubeb_stream * stm
      * eventual upmix/downmix ourselves */
     LOG("Using WASAPI suggested format: channels: %d", closest->nChannels);
     WAVEFORMATEXTENSIBLE * closest_pcm = reinterpret_cast<WAVEFORMATEXTENSIBLE *>(closest);
     assert(closest_pcm->SubFormat == format_pcm->SubFormat);
     CoTaskMemFree(*mix_format);
     *mix_format = closest;
   } else if (hr == AUDCLNT_E_UNSUPPORTED_FORMAT) {
     /* Not supported, no suggestion. This should not happen, but it does in the
-     * field with some sound cards. We simply bail out and let the rest of the
-     * code figure out the right conversion path. */
+     * field with some sound cards. We restore the mix format, and let the rest
+     * of the code figure out the right conversion path. */
+    **mix_format = hw_mixformat;
   } else if (hr == S_OK) {
     LOG("Requested format accepted by WASAPI.");
   }
 }
 
 int
 wasapi_stream_init(cubeb * context, cubeb_stream ** stream,
                    char const * stream_name, cubeb_stream_params stream_params,