Bug 818364 - Update libcubeb to 0.2. r=doublec
authorMatthew Gregan <kinetik@flim.org>
Wed, 05 Dec 2012 17:20:47 +1300
changeset 124556 4498adcb9a36b9769506ce3d2044eba61ec193bf
parent 124555 0477e846f994dbee815210ef2fc425582216ae72
child 124557 fe0abb4decb66a99b3a9603190f4580e30f4e328
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdoublec
bugs818364
milestone20.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 818364 - Update libcubeb to 0.2. r=doublec
media/libcubeb/README_MOZILLA
media/libcubeb/src/cubeb_audiounit.c
media/libcubeb/src/cubeb_winmm.c
--- 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 98769a7861b067125a76c97ddb51c5db8f528b75.
+The git commit ID used was 0f53b9b70c4e6af9da4a7eb0d38a7757c5a10edd..
--- a/media/libcubeb/src/cubeb_audiounit.c
+++ b/media/libcubeb/src/cubeb_audiounit.c
@@ -3,17 +3,16 @@
  *
  * This program is made available under an ISC-style license.  See the
  * accompanying file LICENSE for details.
  */
 #undef NDEBUG
 #include <assert.h>
 #include <pthread.h>
 #include <stdlib.h>
-#include <CoreServices/CoreServices.h>
 #include <AudioUnit/AudioUnit.h>
 #include "cubeb/cubeb.h"
 
 #define NBUFS 4
 
 struct cubeb_stream {
   AudioUnit unit;
   cubeb_data_callback data_callback;
@@ -59,17 +58,17 @@ audio_unit_output_callback(void * user_p
   pthread_mutex_lock(&stm->mutex);
   if (got < 0) {
     // XXX handle this case.
     assert(false);
     pthread_mutex_unlock(&stm->mutex);
     return noErr;
   }
 
-  if (got < nframes) {
+  if ((UInt32) got < nframes) {
     size_t got_bytes = got * stm->sample_spec.mBytesPerFrame;
     size_t rem_bytes = (nframes - got) * stm->sample_spec.mBytesPerFrame;
 
     stm->draining = 1;
 
     memset(buf + got_bytes, 0, rem_bytes);
   }
 
@@ -101,19 +100,24 @@ cubeb_destroy(cubeb * ctx)
 
 int
 cubeb_stream_init(cubeb * context, cubeb_stream ** stream, char const * stream_name,
                   cubeb_stream_params stream_params, unsigned int latency,
                   cubeb_data_callback data_callback, cubeb_state_callback state_callback,
                   void * user_ptr)
 {
   AudioStreamBasicDescription ss;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
   ComponentDescription desc;
+  Component comp;
+#else
+  AudioComponentDescription desc;
+  AudioComponent comp;
+#endif
   cubeb_stream * stm;
-  Component comp;
   AURenderCallbackStruct input;
   unsigned int buffer_size;
   OSStatus r;
 
   assert(context == (void *) 0xdeadbeef);
   *stream = NULL;
 
   if (stream_params.rate < 1 || stream_params.rate > 192000 ||
@@ -157,17 +161,21 @@ cubeb_stream_init(cubeb * context, cubeb
   ss.mFramesPerPacket = 1;
   ss.mBytesPerPacket = ss.mBytesPerFrame * ss.mFramesPerPacket;
 
   desc.componentType = kAudioUnitType_Output;
   desc.componentSubType = kAudioUnitSubType_DefaultOutput;
   desc.componentManufacturer = kAudioUnitManufacturer_Apple;
   desc.componentFlags = 0;
   desc.componentFlagsMask = 0;
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
   comp = FindNextComponent(NULL, &desc);
+#else
+  comp = AudioComponentFindNext(NULL, &desc);
+#endif
   assert(comp);
 
   stm = calloc(1, sizeof(*stm));
   assert(stm);
 
   stm->data_callback = data_callback;
   stm->state_callback = state_callback;
   stm->user_ptr = user_ptr;
@@ -175,17 +183,21 @@ cubeb_stream_init(cubeb * context, cubeb
   stm->sample_spec = ss;
 
   r = pthread_mutex_init(&stm->mutex, NULL);
   assert(r == 0);
 
   stm->frames_played = 0;
   stm->frames_queued = 0;
 
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
   r = OpenAComponent(comp, &stm->unit);
+#else
+  r = AudioComponentInstanceNew(comp, &stm->unit);
+#endif
   if (r != 0) {
     cubeb_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   input.inputProc = audio_unit_output_callback;
   input.inputProcRefCon = stm;
   r = AudioUnitSetProperty(stm->unit, kAudioUnitProperty_SetRenderCallback,
@@ -224,17 +236,21 @@ cubeb_stream_destroy(cubeb_stream * stm)
 {
   int r;
 
   stm->shutdown = 1;
 
   if (stm->unit) {
     AudioOutputUnitStop(stm->unit);
     AudioUnitUninitialize(stm->unit);
+#if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
     CloseComponent(stm->unit);
+#else
+    AudioComponentInstanceDispose(stm->unit);
+#endif
   }
 
   r = pthread_mutex_destroy(&stm->mutex);
   assert(r == 0);
 
   free(stm);
 }
 
--- a/media/libcubeb/src/cubeb_winmm.c
+++ b/media/libcubeb/src/cubeb_winmm.c
@@ -1,23 +1,32 @@
 /*
  * Copyright © 2011 Mozilla Foundation
  *
  * This program is made available under an ISC-style license.  See the
  * accompanying file LICENSE for details.
  */
 #undef NDEBUG
+#define __MSVCRT_VERSION__ 0x0700
+#define WINVER 0x0501
+#define WIN32_LEAN_AND_MEAN
+#include <malloc.h>
 #include <assert.h>
 #include <windows.h>
 #include <mmreg.h>
 #include <mmsystem.h>
 #include <process.h>
 #include <stdlib.h>
 #include "cubeb/cubeb.h"
 
+/* This is missing from the MinGW headers. Use a safe fallback. */
+#ifndef MEMORY_ALLOCATION_ALIGNMENT
+#define MEMORY_ALLOCATION_ALIGNMENT 16
+#endif
+
 #define CUBEB_STREAM_MAX 32
 #define NBUFS 4
 
 const GUID KSDATAFORMAT_SUBTYPE_PCM =
 { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
 const GUID KSDATAFORMAT_SUBTYPE_IEEE_FLOAT =
 { 0x00000003, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
 
@@ -28,17 +37,17 @@ struct cubeb_stream_item {
 
 struct cubeb {
   HANDLE event;
   HANDLE thread;
   int shutdown;
   PSLIST_HEADER work;
   CRITICAL_SECTION lock;
   unsigned int active_streams;
-  int minimum_latency;
+  unsigned int minimum_latency;
 };
 
 struct cubeb_stream {
   cubeb * context;
   cubeb_stream_params params;
   cubeb_data_callback data_callback;
   cubeb_state_callback state_callback;
   void * user_ptr;
@@ -155,19 +164,25 @@ cubeb_buffer_thread(void * user_ptr)
 
   for (;;) {
     DWORD rv;
     PSLIST_ENTRY item;
 
     rv = WaitForSingleObject(ctx->event, INFINITE);
     assert(rv == WAIT_OBJECT_0);
 
-    while ((item = InterlockedPopEntrySList(ctx->work)) != NULL) {
-      cubeb_refill_stream(((struct cubeb_stream_item *) item)->stream);
-      _aligned_free(item);
+    /* Process work items in batches so that a single stream can't
+       starve the others by continuously adding new work to the top of
+       the work item stack. */
+    item = InterlockedFlushSList(ctx->work);
+    while (item != NULL) {
+      PSLIST_ENTRY tmp = item;
+      cubeb_refill_stream(((struct cubeb_stream_item *) tmp)->stream);
+      item = item->Next;
+      _aligned_free(tmp);
     }
 
     if (ctx->shutdown) {
       break;
     }
   }
 
   return 0;
@@ -186,17 +201,17 @@ cubeb_buffer_callback(HWAVEOUT waveout, 
   item = _aligned_malloc(sizeof(struct cubeb_stream_item), MEMORY_ALLOCATION_ALIGNMENT);
   assert(item);
   item->stream = stm;
   InterlockedPushEntrySList(stm->context->work, &item->head);
 
   SetEvent(stm->context->event);
 }
 
-static int
+static unsigned int
 calculate_minimum_latency(void)
 {
   OSVERSIONINFOEX osvi;
   DWORDLONG mask;
 
   /* Running under Terminal Services results in underruns with low latency. */
   if (GetSystemMetrics(SM_REMOTESESSION) == TRUE) {
     return 500;