Bug 946618 - Disable part of a cubeb test on Windows 7. r=kinetik
authorPaul Adenot <paul@paul.cx>
Mon, 24 Mar 2014 11:06:05 +0100
changeset 195201 9fedde6e6e5fafc351ba21139cf3757bf8eb866d
parent 195200 b199abcbfae1dc895ac149fe776df5820cbdd11f
child 195202 e89976cb4b4b260d75a6684b1fb1ddc86ff2d92d
push idunknown
push userunknown
push dateunknown
reviewerskinetik
bugs946618
milestone31.0a1
Bug 946618 - Disable part of a cubeb test on Windows 7. r=kinetik
media/libcubeb/src/cubeb_wasapi.cpp
media/libcubeb/tests/test_sanity.cpp
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -323,18 +323,17 @@ wasapi_stream_render_loop(LPVOID stream)
   DWORD mmcss_task_index = 0;
 
   /* We could consider using "Pro Audio" here for WebAudio and
    * maybe WebRTC. */
   mmcss_handle =
     stm->context->set_mm_thread_characteristics("Audio", &mmcss_task_index);
   if (!mmcss_handle) {
     /* This is not fatal, but we might glitch under heavy load. */
-    LOG("Unable to use mmcss to bump the render thread priority: %d",
-        GetLastError());
+    LOG("Unable to use mmcss to bump the render thread priority: %x", GetLastError());
   }
 
   hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
   if (FAILED(hr)) {
     LOG("could not initialize COM in render thread: %x", hr);
     return hr;
   }
 
@@ -481,17 +480,17 @@ int wasapi_init(cubeb ** context, char c
   if (ctx->mmcss_module) {
     ctx->set_mm_thread_characteristics =
       (set_mm_thread_characteristics_function) GetProcAddress(
           ctx->mmcss_module, "AvSetMmThreadCharacteristicsA");
     ctx->revert_mm_thread_characteristics =
       (revert_mm_thread_characteristics_function) GetProcAddress(
           ctx->mmcss_module, "AvRevertMmThreadCharacteristics");
     if (!(ctx->set_mm_thread_characteristics && ctx->revert_mm_thread_characteristics)) {
-      LOG("Could not load AvSetMmThreadCharacteristics or AvRevertMmThreadCharacteristics: %d", GetLastError());
+      LOG("Could not load AvSetMmThreadCharacteristics or AvRevertMmThreadCharacteristics: %x", GetLastError());
       FreeLibrary(ctx->mmcss_module);
     }
   } else {
     // This is not a fatal error, but we might end up glitching when
     // the system is under high load.
     LOG("Could not load Avrt.dll");
     ctx->set_mm_thread_characteristics = &set_mm_thread_characteristics_noop;
     ctx->revert_mm_thread_characteristics = &revert_mm_thread_characteristics_noop;
@@ -724,52 +723,53 @@ wasapi_stream_init(cubeb * context, cube
   stm->user_ptr = user_ptr;
   stm->stream_params = stream_params;
   stm->draining = false;
 
   stm->shutdown_event = CreateEvent(NULL, 0, 0, NULL);
   stm->refill_event = CreateEvent(NULL, 0, 0, NULL);
 
   if (!stm->shutdown_event) {
-    LOG("Can't create the shutdown event, error: %d.", GetLastError());
+    LOG("Can't create the shutdown event, error: %x.", GetLastError());
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   if (!stm->refill_event) {
     SafeRelease(stm->shutdown_event);
-    LOG("Can't create the refill event, error: %d.", GetLastError());
+    LOG("Can't create the refill event, error: %x.", GetLastError());
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   IMMDevice * device;
   hr = get_default_endpoint(&device);
   if (FAILED(hr)) {
+    LOG("Could not get default endpoint, error: %x", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   /* Get a client. We will get all other interfaces we need from
    * this pointer. */
   hr = device->Activate(__uuidof(IAudioClient),
                         CLSCTX_INPROC_SERVER,
                         NULL, (void **)&stm->client);
   SafeRelease(device);
   if (FAILED(hr)) {
-    LOG("Could not activate the device to get an audio client.");
+    LOG("Could not activate the device to get an audio client: error: %x", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   /* We have to distinguish between the format the mixer uses,
   * and the format the stream we want to play uses. */
   hr = stm->client->GetMixFormat(&mix_format);
   if (FAILED(hr)) {
-    LOG("Could not fetch current mix format from the audio client.");
+    LOG("Could not fetch current mix format from the audio client: error: %x", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   handle_channel_layout(stm, &mix_format, &stream_params);
 
   /* Shared mode WASAPI always supports float32 sample format, so this
    * is safe. */
@@ -787,16 +787,17 @@ wasapi_stream_init(cubeb * context, cube
      * of channels of the stream, not the number of channels
      * that WASAPI wants. */
     stm->resampler = speex_resampler_init(stm->stream_params.channels,
                                           stm->stream_params.rate,
                                           stm->mix_params.rate,
                                           SPEEX_RESAMPLER_QUALITY_DESKTOP,
                                           NULL);
     if (!stm->resampler) {
+      LOG("Could not get a resampler");
       CoTaskMemFree(mix_format);
       wasapi_stream_destroy(stm);
       return CUBEB_ERROR;
     }
 
     /* Get a little buffer so we can store the leftover frames,
      * that is, the samples not consumed by the resampler that we will end up
      * using next time the render callback is called. */
@@ -821,17 +822,17 @@ wasapi_stream_init(cubeb * context, cube
   if (FAILED(hr)) {
     LOG("Unable to initialize audio client: %x.", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   hr = stm->client->GetBufferSize(&stm->buffer_frame_count);
   if (FAILED(hr)) {
-    LOG("Could not get the buffer size from the client.");
+    LOG("Could not get the buffer size from the client %x.", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   if (should_upmix(stm) || should_downmix(stm)) {
     stm->mix_buffer = (float *) malloc(frames_to_bytes_before_mix(stm, stm->buffer_frame_count));
   }
 
@@ -841,40 +842,40 @@ wasapi_stream_init(cubeb * context, cube
    * factor and the channel layout into account. */
   if (stm->resampler) {
     size_t frames_needed = static_cast<size_t>(frame_count_at_rate(stm->buffer_frame_count, resampling_rate));
     stm->resampling_src_buffer = (float *)malloc(frames_to_bytes_before_mix(stm, frames_needed));
   }
 
   hr = stm->client->SetEventHandle(stm->refill_event);
   if (FAILED(hr)) {
-    LOG("Could set the event handle for the client.");
+    LOG("Could set the event handle for the client %x.", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   hr = stm->client->GetService(__uuidof(IAudioRenderClient),
                                (void **)&stm->render_client);
   if (FAILED(hr)) {
-    LOG("Could not get the render client.");
+    LOG("Could not get the render client %x.", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   hr = stm->client->GetService(__uuidof(IAudioClock),
                                (void **)&stm->audio_clock);
   if (FAILED(hr)) {
-    LOG("Could not get the IAudioClock.");
+    LOG("Could not get the IAudioClock, %x", hr);
     wasapi_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   hr = stm->audio_clock->GetFrequency(&stm->clock_freq);
   if (FAILED(hr)) {
-    LOG("failed to get audio clock frequency.");
+    LOG("failed to get audio clock frequency, %x", hr);
     return CUBEB_ERROR;
   }
 
   *stream = stm;
 
   return CUBEB_OK;
 }
 
--- a/media/libcubeb/tests/test_sanity.cpp
+++ b/media/libcubeb/tests/test_sanity.cpp
@@ -481,36 +481,58 @@ test_drain(void)
   //assert(position == total_frames_written);
 
   cubeb_stream_destroy(stream);
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
+int is_windows_7()
+{
+#ifdef __WIN32__
+#include <windows.h>
+    DWORD version = GetVersion();
+    DWORD major = (DWORD) (LOBYTE(LOWORD(version)));
+    DWORD minor = (DWORD) (HIBYTE(LOWORD(version)));
+
+    return (major == 6) && (minor == 1);
+#else
+  return-0;
+#endif
+}
+
 int
 main(int argc, char * argv[])
 {
   test_init_destroy_context();
   test_init_destroy_multiple_contexts();
   test_init_destroy_stream();
   test_init_destroy_multiple_streams();
   test_init_destroy_multiple_contexts_and_streams();
   test_basic_stream_operations();
   test_stream_position();
-  delay_callback = 0;
-  test_init_start_stop_destroy_multiple_streams(0, 0);
-  test_init_start_stop_destroy_multiple_streams(1, 0);
-  test_init_start_stop_destroy_multiple_streams(0, 150);
-  test_init_start_stop_destroy_multiple_streams(1, 150);
-  delay_callback = 1;
-  test_init_start_stop_destroy_multiple_streams(0, 0);
-  test_init_start_stop_destroy_multiple_streams(1, 0);
-  test_init_start_stop_destroy_multiple_streams(0, 150);
-  test_init_start_stop_destroy_multiple_streams(1, 150);
+
+  /* Sometimes, when using WASAPI on windows 7 (vista and 8 are okay), and
+   * calling Activate a lot on an AudioClient, 0x800700b7 is returned. This is
+   * the HRESULT value for "Cannot create a file when that file already exists",
+   * and is not documented as a possible return value for this call. Hence, we
+   * try to limit the number of streams we create in this test. */
+  if (!is_windows_7()) {
+    delay_callback = 0;
+    test_init_start_stop_destroy_multiple_streams(0, 0);
+    test_init_start_stop_destroy_multiple_streams(1, 0);
+    test_init_start_stop_destroy_multiple_streams(0, 150);
+    test_init_start_stop_destroy_multiple_streams(1, 150);
+    delay_callback = 1;
+    test_init_start_stop_destroy_multiple_streams(0, 0);
+    test_init_start_stop_destroy_multiple_streams(1, 0);
+    test_init_start_stop_destroy_multiple_streams(0, 150);
+    test_init_start_stop_destroy_multiple_streams(1, 150);
+  }
   delay_callback = 0;
   test_drain();
 /*
   to implement:
   test_eos_during_prefill();
   test_stream_destroy_pending_drain();
 */
   printf("\n");