Bug 1074010 - Update cubeb from upstream. r=padenot
authorMatthew Gregan <kinetik@flim.org>
Mon, 29 Sep 2014 13:19:09 +1300
changeset 211828 1037bad284805e0b4a7d54cfdd6358f17ff140a5
parent 211827 0d2e63e0505595a2ab2b2664e572d884c4081099
child 211829 2099b21b855121eb383469e42a55f5f17daac3e8
push id50815
push usermgregan@mozilla.com
push dateWed, 22 Oct 2014 22:10:14 +0000
treeherdermozilla-inbound@1037bad28480 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1074010
milestone36.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 1074010 - Update cubeb from upstream. r=padenot
media/libcubeb/README
media/libcubeb/README.md
media/libcubeb/README_MOZILLA
media/libcubeb/include/cubeb.h
media/libcubeb/src/cubeb_pulse.c
media/libcubeb/src/cubeb_wasapi.cpp
media/libcubeb/src/cubeb_winmm.c
media/libcubeb/tests/test_sanity.cpp
media/libcubeb/update.sh
rename from media/libcubeb/README
rename to media/libcubeb/README.md
--- a/media/libcubeb/README
+++ b/media/libcubeb/README.md
@@ -1,3 +1,5 @@
+[![Build Status](https://travis-ci.org/kinetiknz/cubeb.svg?branch=master)](https://travis-ci.org/kinetiknz/cubeb)
+
 See INSTALL for build instructions.
 
 Licensed under an ISC-style license.  See LICENSE for details.
--- 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 bb0437c060a85a4f1f11b962a53ca0af02801967.
+The git commit ID used was 8948986e9c8d1e1988e67d2819492a52b719b13a.
--- a/media/libcubeb/include/cubeb.h
+++ b/media/libcubeb/include/cubeb.h
@@ -199,25 +199,25 @@ char const * cubeb_get_backend_id(cubeb 
 int cubeb_get_max_channel_count(cubeb * context, uint32_t * max_channels);
 
 /** Get the minimal latency value, in milliseconds, that is guaranteed to work
     when creating a stream for the specified sample rate. This is platform and
     backend dependant.
     @param context
     @param params On some backends, the minimum achievable latency depends on
                   the characteristics of the stream.
-    @param latency The latency value, in ms, to pass to cubeb_stream_init.
+    @param latency_ms The latency value, in ms, to pass to cubeb_stream_init.
     @retval CUBEB_ERROR_INVALID_PARAMETER
     @retval CUBEB_OK */
 int cubeb_get_min_latency(cubeb * context, cubeb_stream_params params, uint32_t * latency_ms);
 
 /** Get the preferred sample rate for this backend: this is hardware and platform
    dependant, and can avoid resampling, and/or trigger fastpaths.
    @param context
-   @param samplerate The samplerate (in Hz) the current configuration prefers.
+   @param rate The samplerate (in Hz) the current configuration prefers.
    @return CUBEB_ERROR_INVALID_PARAMETER
    @return CUBEB_OK */
 int cubeb_get_preferred_sample_rate(cubeb * context, uint32_t * rate);
 
 /** Destroy an application context.
     @param context */
 void cubeb_destroy(cubeb * context);
 
@@ -270,17 +270,17 @@ int cubeb_stream_get_position(cubeb_stre
     @param latency Current approximate stream latency in frames.
     @retval CUBEB_OK
     @retval CUBEB_ERROR */
 int cubeb_stream_get_latency(cubeb_stream * stream, uint32_t * latency);
 
 /**
  * Set the volume for a stream.
  * @param stream the stream for which to adjust the volume.
- * @param volumes a float between 0.0 (muted) and 1.0 (maximum volumes)
+ * @param volume a float between 0.0 (muted) and 1.0 (maximum volume)
  * @return CUBEB_ERROR_INVALID_PARAMETER if volume is outside [0.0; 1.0]
  * @return CUBEB_ERROR_INVALID_PARAMETER if stream is an invalid pointer
  * @return CUBEB_OK otherwise
  */
 int cubeb_stream_set_volume(cubeb_stream * stream, float volume);
 
 /**
  * If the stream is stereo, set the left/right panning. If the stream is mono,
--- a/media/libcubeb/src/cubeb_pulse.c
+++ b/media/libcubeb/src/cubeb_pulse.c
@@ -494,18 +494,16 @@ pulse_context_destroy(cubeb * ctx)
   WRAP(pa_context_disconnect)(ctx->context);
   WRAP(pa_context_unref)(ctx->context);
   WRAP(pa_threaded_mainloop_unlock)(ctx->mainloop);
 }
 
 static void
 pulse_destroy(cubeb * ctx)
 {
-  pa_operation * o;
-
   if (ctx->context_name) {
     free(ctx->context_name);
   }
   if (ctx->context) {
     pulse_context_destroy(ctx);
   }
 
   if (ctx->mainloop) {
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -16,16 +16,21 @@
 #include <process.h>
 #include <avrt.h>
 #include "cubeb/cubeb.h"
 #include "cubeb-internal.h"
 #include "cubeb/cubeb-stdint.h"
 #include "cubeb_resampler.h"
 #include <stdio.h>
 
+/**Taken from winbase.h, Not in MinGW.*/
+#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
+#define STACK_SIZE_PARAM_IS_A_RESERVATION   0x00010000    // Threads only
+#endif
+
 #if 1
 #  define LOG(...) do {         \
   fprintf(stderr, __VA_ARGS__); \
   fprintf(stderr, "\n");        \
 } while(0);
 #else
 #  define LOG(...)
 #endif
--- a/media/libcubeb/src/cubeb_winmm.c
+++ b/media/libcubeb/src/cubeb_winmm.c
@@ -22,16 +22,26 @@
 #include "cubeb/cubeb.h"
 #include "cubeb-internal.h"
 
 /* This is missing from the MinGW headers. Use a safe fallback. */
 #if !defined(MEMORY_ALLOCATION_ALIGNMENT)
 #define MEMORY_ALLOCATION_ALIGNMENT 16
 #endif
 
+/**This is also missing from the MinGW headers. It  also appears to be undocumented by Microsoft.*/
+#ifndef WAVE_FORMAT_48S16
+#define WAVE_FORMAT_48S16      0x00008000       /* 48     kHz, Stereo, 16-bit */
+#endif
+
+/**Taken from winbase.h, also not in MinGW.*/
+#ifndef STACK_SIZE_PARAM_IS_A_RESERVATION
+#define STACK_SIZE_PARAM_IS_A_RESERVATION   0x00010000    // Threads only
+#endif
+
 #define CUBEB_STREAM_MAX 32
 #define NBUFS 4
 /* When cubeb_stream.soft_volume is set to this value, the device supports
  * setting the volume. Otherwise, a gain will be applied manually. */
 #define SETTING_VOLUME_SUPPORTED -1.0
 
 const GUID KSDATAFORMAT_SUBTYPE_PCM =
 { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
--- a/media/libcubeb/tests/test_sanity.cpp
+++ b/media/libcubeb/tests/test_sanity.cpp
@@ -63,32 +63,33 @@ test_init_destroy_context(void)
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
 static void
 test_init_destroy_multiple_contexts(void)
 {
-  int i;
+  size_t i;
   int r;
   cubeb * ctx[4];
+  int order[4] = {2, 0, 3, 1};
+  assert(ARRAY_LENGTH(ctx) == ARRAY_LENGTH(order));
 
   BEGIN_TEST
 
-  for (i = 0; i < 4; ++i) {
+  for (i = 0; i < ARRAY_LENGTH(ctx); ++i) {
     r = cubeb_init(&ctx[i], NULL);
     assert(r == 0 && ctx[i]);
   }
 
   /* destroy in a different order */
-  cubeb_destroy(ctx[2]);
-  cubeb_destroy(ctx[0]);
-  cubeb_destroy(ctx[3]);
-  cubeb_destroy(ctx[1]);
+  for (i = 0; i < ARRAY_LENGTH(ctx); ++i) {
+    cubeb_destroy(ctx[order[i]]);
+  }
 
   END_TEST
 }
 
 static void
 test_init_destroy_stream(void)
 {
   int r;
@@ -113,138 +114,140 @@ test_init_destroy_stream(void)
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
 static void
 test_init_destroy_multiple_streams(void)
 {
-  int i;
+  size_t i;
   int r;
   cubeb * ctx;
   cubeb_stream * stream[8];
   cubeb_stream_params params;
 
   BEGIN_TEST
 
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
-  for (i = 0; i < 8; ++i) {
+  for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
     r = cubeb_stream_init(ctx, &stream[i], "test", params, STREAM_LATENCY,
                           test_data_callback, test_state_callback, &dummy);
     assert(r == 0);
     assert(stream[i]);
   }
 
-  for (i = 0; i < 8; ++i) {
+  for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
     cubeb_stream_destroy(stream[i]);
   }
 
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
 static void
 test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
 {
-  int i;
+  size_t i;
   int r;
   cubeb * ctx;
   cubeb_stream * stream[8];
   cubeb_stream_params params;
 
   BEGIN_TEST
 
   r = cubeb_init(&ctx, "test_sanity");
   assert(r == 0 && ctx);
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
-  for (i = 0; i < 8; ++i) {
+  for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
     r = cubeb_stream_init(ctx, &stream[i], "test", params, STREAM_LATENCY,
                           test_data_callback, test_state_callback, &dummy);
     assert(r == 0);
     assert(stream[i]);
     if (early) {
       r = cubeb_stream_start(stream[i]);
       assert(r == 0);
     }
   }
 
 
   if (!early) {
-    for (i = 0; i < 8; ++i) {
+    for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
       r = cubeb_stream_start(stream[i]);
       assert(r == 0);
     }
   }
 
   if (delay_ms) {
     delay(delay_ms);
   }
 
   if (!early) {
-    for (i = 0; i < 8; ++i) {
+    for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
       r = cubeb_stream_stop(stream[i]);
       assert(r == 0);
     }
   }
 
-  for (i = 0; i < 8; ++i) {
+  for (i = 0; i < ARRAY_LENGTH(stream); ++i) {
     if (early) {
       r = cubeb_stream_stop(stream[i]);
       assert(r == 0);
     }
     cubeb_stream_destroy(stream[i]);
   }
 
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
 static void
 test_init_destroy_multiple_contexts_and_streams(void)
 {
-  int i, j;
+  size_t i, j;
   int r;
   cubeb * ctx[2];
   cubeb_stream * stream[8];
   cubeb_stream_params params;
+  size_t streams_per_ctx = ARRAY_LENGTH(stream) / ARRAY_LENGTH(ctx);
+  assert(ARRAY_LENGTH(ctx) * streams_per_ctx == ARRAY_LENGTH(stream));
 
   BEGIN_TEST
 
   params.format = STREAM_FORMAT;
   params.rate = STREAM_RATE;
   params.channels = STREAM_CHANNELS;
 
-  for (i = 0; i < 2; ++i) {
+  for (i = 0; i < ARRAY_LENGTH(ctx); ++i) {
     r = cubeb_init(&ctx[i], "test_sanity");
     assert(r == 0 && ctx[i]);
 
-    for (j = 0; j < 4; ++j) {
-      r = cubeb_stream_init(ctx[i], &stream[i * 4 + j], "test", params, STREAM_LATENCY,
+    for (j = 0; j < streams_per_ctx; ++j) {
+      r = cubeb_stream_init(ctx[i], &stream[i * streams_per_ctx + j], "test", params, STREAM_LATENCY,
                             test_data_callback, test_state_callback, &dummy);
       assert(r == 0);
-      assert(stream[i * 4 + j]);
+      assert(stream[i * streams_per_ctx + j]);
     }
   }
 
-  for (i = 0; i < 2; ++i) {
-    for (j = 0; j < 4; ++j) {
-      cubeb_stream_destroy(stream[i * 4 + j]);
+  for (i = 0; i < ARRAY_LENGTH(ctx); ++i) {
+    for (j = 0; j < streams_per_ctx; ++j) {
+      cubeb_stream_destroy(stream[i * streams_per_ctx + j]);
     }
     cubeb_destroy(ctx[i]);
   }
 
   END_TEST
 }
 
 static void
@@ -291,17 +294,17 @@ test_basic_stream_operations(void)
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
 static void
 test_stream_position(void)
 {
-  int i;
+  size_t i;
   int r;
   cubeb * ctx;
   cubeb_stream * stream;
   cubeb_stream_params params;
   uint64_t position, last_position;
 
   BEGIN_TEST
 
@@ -442,58 +445,43 @@ test_drain(void)
   do_drain = 1;
 
   for (;;) {
     r = cubeb_stream_get_position(stream, &position);
     assert(r == 0);
     if (got_drain) {
       break;
     } else {
-      uint32_t i, skip = 0;
-      /* Latency passed to cubeb_stream_init is not really honored on OSX,
-         win32/winmm and android, skip this test. */
-      const char * backend_id = cubeb_get_backend_id(ctx);
-      const char * latency_not_honored_bakends[] = {
-        "audiounit",
-        "winmm",
-        "audiotrack",
-        "opensl"
-      };
-
-      for (i = 0; i < ARRAY_LENGTH(latency_not_honored_bakends); i++) {
-        if (!strcmp(backend_id, latency_not_honored_bakends[i])) {
-          skip = 1;
-        }
-      }
-      if (!skip) {
-        /* Position should roughly be equal to the number of written frames. We
-         * need to take the latency into account. */
-        int latency = (STREAM_LATENCY * STREAM_RATE) / 1000;
-        assert(position + latency <= total_frames_written);
-      }
+      assert(position <= total_frames_written);
     }
     delay(500);
   }
 
   r = cubeb_stream_get_position(stream, &position);
   assert(r == 0);
   assert(got_drain);
 
-  // Disabled due to failures in the ALSA backend.
-  //assert(position == total_frames_written);
+  // Really, we should be able to rely on position reaching our final written frame, but
+  // for now let's make sure it doesn't continue beyond that point.
+  //assert(position <= total_frames_written);
 
   cubeb_stream_destroy(stream);
   cubeb_destroy(ctx);
 
   END_TEST
 }
 
 int is_windows_7()
 {
-#if (defined(_WIN32) || defined(__WIN32__))
+#ifdef __MINGW32__
+   printf("Warning: this test was built with MinGW.\n"
+   "MinGW does not contain necessary version checking infrastructure. Claiming to be Windows 7, even if we're not.\n");
+   return 1;
+#endif
+#if (defined(_WIN32) || defined(__WIN32__)) && ( !defined(__MINGW32__))
    OSVERSIONINFOEX osvi;
    DWORDLONG condition_mask = 0;
 
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
 
    // NT 6.1 is Windows 7
    osvi.dwMajorVersion = 6;
--- a/media/libcubeb/update.sh
+++ b/media/libcubeb/update.sh
@@ -8,26 +8,28 @@ cp $1/src/cubeb_alsa.c src
 cp $1/src/cubeb_winmm.c src
 cp $1/src/cubeb_audiounit.c src
 cp $1/src/cubeb_pulse.c src
 cp $1/src/cubeb_sndio.c src
 cp $1/src/cubeb_opensl.c src
 cp $1/src/cubeb_audiotrack.c src
 cp $1/src/cubeb_wasapi.cpp src
 cp $1/src/cubeb-speex-resampler.h src
+cp $1/src/cubeb_panner.h src
+cp $1/src/cubeb_panner.cpp src
 cp $1/src/android/audiotrack_definitions.h src/android
 cp $1/src/android/sles_definitions.h src/android
 cp $1/LICENSE .
-cp $1/README .
+cp $1/README.md .
 cp $1/AUTHORS .
 cp $1/test/common.h tests/common.h
-cp $1/test/test_audio.c tests/test_audio.cpp
-cp $1/test/test_tone.c tests/test_tone.cpp
-cp $1/test/test_sanity.c tests/test_sanity.cpp
-cp $1/test/test_latency.c tests/test_latency.cpp
+cp $1/test/test_audio.cpp tests/test_audio.cpp
+cp $1/test/test_tone.cpp tests/test_tone.cpp
+cp $1/test/test_sanity.cpp tests/test_sanity.cpp
+cp $1/test/test_latency.cpp tests/test_latency.cpp
 
 if [ -d $1/.git ]; then
   rev=$(cd $1 && git rev-parse --verify HEAD)
   dirty=$(cd $1 && git diff-index --name-only HEAD)
 fi
 
 if [ -n "$rev" ]; then
   version=$rev