Bug 792109 - Generate an outmix per opensl cubeb context not stream, r=kinetik
authorMichael Wu <mwu@mozilla.com>
Wed, 19 Sep 2012 13:51:34 -0400
changeset 107860 d7c22610380aa0d3b454b7ab3997f2e5927de221
parent 107859 50ec63e18d1a5ba92af4c87ec80fa74c38895c3c
child 107861 e5a74d48fd5ffc968956c3613af8ce3b54445793
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerskinetik
bugs792109
milestone18.0a1
Bug 792109 - Generate an outmix per opensl cubeb context not stream, r=kinetik
media/libcubeb/src/cubeb_opensl.c
--- a/media/libcubeb/src/cubeb_opensl.c
+++ b/media/libcubeb/src/cubeb_opensl.c
@@ -8,31 +8,30 @@
 #include "cubeb/cubeb.h"
 #include <assert.h>
 #include <dlfcn.h>
 #include <stdlib.h>
 #include <SLES/OpenSLES.h>
 
 struct cubeb {
   void * lib;
-  SLInterfaceID SL_IID_OUTPUTMIX;
   SLInterfaceID SL_IID_BUFFERQUEUE;
   SLInterfaceID SL_IID_PLAY;
   SLObjectItf engObj;
   SLEngineItf eng;
+  SLObjectItf outmixObj;
 };
 
 #define NBUFS 4
 
 struct cubeb_stream {
   struct cubeb * context;
   SLObjectItf playerObj;
   SLPlayItf play;
   SLBufferQueueItf bufq;
-  SLObjectItf outmixObj;
   void *queuebuf[NBUFS];
   int queuebuf_idx;
   long queuebuf_len;
   long bytespersec;
   long framesize;
   int draining;
 
   cubeb_data_callback data_callback;
@@ -97,22 +96,22 @@ cubeb_init(cubeb ** context, char const 
                                        SLuint32,
                                        const SLEngineOption *,
                                        SLuint32,
                                        const SLInterfaceID *,
                                        const SLboolean *);
   slCreateEngine_t f_slCreateEngine =
     (slCreateEngine_t)dlsym(ctx->lib, "slCreateEngine");
   SLInterfaceID SL_IID_ENGINE = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_ENGINE");
-  ctx->SL_IID_OUTPUTMIX = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_OUTPUTMIX");
+  SLInterfaceID SL_IID_OUTPUTMIX = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_OUTPUTMIX");
   ctx->SL_IID_BUFFERQUEUE = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_BUFFERQUEUE");
   ctx->SL_IID_PLAY = *(SLInterfaceID *)dlsym(ctx->lib, "SL_IID_PLAY");
   if (!f_slCreateEngine ||
       !SL_IID_ENGINE ||
-      !ctx->SL_IID_OUTPUTMIX ||
+      !SL_IID_OUTPUTMIX ||
       !ctx->SL_IID_BUFFERQUEUE ||
       !ctx->SL_IID_PLAY) {
     cubeb_destroy(ctx);
     return CUBEB_ERROR;
   }
 
 
   const SLEngineOption opt[] = {{SL_ENGINEOPTION_THREADSAFE, SL_BOOLEAN_TRUE}};
@@ -131,31 +130,47 @@ cubeb_init(cubeb ** context, char const 
   }
 
   res = (*ctx->engObj)->GetInterface(ctx->engObj, SL_IID_ENGINE, &ctx->eng);
   if (res != SL_RESULT_SUCCESS) {
     cubeb_destroy(ctx);
     return CUBEB_ERROR;
   }
 
+  const SLInterfaceID idsom[] = {SL_IID_OUTPUTMIX};
+  const SLboolean reqom[] = {SL_BOOLEAN_TRUE};
+  res = (*ctx->eng)->CreateOutputMix(ctx->eng, &ctx->outmixObj, 1, idsom, reqom);
+  if (res != SL_RESULT_SUCCESS) {
+    cubeb_destroy(ctx);
+    return CUBEB_ERROR;
+  }
+
+  res = (*ctx->outmixObj)->Realize(ctx->outmixObj, SL_BOOLEAN_FALSE);
+  if (res != SL_RESULT_SUCCESS) {
+    cubeb_destroy(ctx);
+    return CUBEB_ERROR;
+  }
+
   *context = ctx;
 
   return CUBEB_OK;
 }
 
 char const *
 cubeb_get_backend_id(cubeb * ctx)
 {
   return "opensl";
 }
 
 void
 cubeb_destroy(cubeb * ctx)
 {
   dlclose(ctx->lib);
+  if (ctx->outmixObj)
+    (*ctx->outmixObj)->Destroy(ctx->outmixObj);
   if (ctx->engObj)
     (*ctx->engObj)->Destroy(ctx->engObj);
   free(ctx);
 }
 
 int
 cubeb_stream_init(cubeb * ctx, cubeb_stream ** stream, char const * stream_name,
                   cubeb_stream_params stream_params, unsigned int latency,
@@ -217,42 +232,27 @@ cubeb_stream_init(cubeb * ctx, cubeb_str
 
   SLDataLocator_BufferQueue loc_bufq;
   loc_bufq.locatorType = SL_DATALOCATOR_BUFFERQUEUE;
   loc_bufq.numBuffers = NBUFS;
   SLDataSource source;
   source.pLocator = &loc_bufq;
   source.pFormat = &format;
 
-  SLresult res;
-  const SLInterfaceID idsom[] = {ctx->SL_IID_OUTPUTMIX};
-  const SLboolean reqom[] = {SL_BOOLEAN_TRUE};
-  res = (*ctx->eng)->CreateOutputMix(ctx->eng, &stm->outmixObj, 1, idsom, reqom);
-  if (res != SL_RESULT_SUCCESS) {
-    cubeb_stream_destroy(stm);
-    return CUBEB_ERROR;
-  }
-
-  res = (*stm->outmixObj)->Realize(stm->outmixObj, SL_BOOLEAN_FALSE);
-  if (res != SL_RESULT_SUCCESS) {
-    cubeb_stream_destroy(stm);
-    return CUBEB_ERROR;
-  }
-
   SLDataLocator_OutputMix loc_outmix;
   loc_outmix.locatorType = SL_DATALOCATOR_OUTPUTMIX;
-  loc_outmix.outputMix = stm->outmixObj;
+  loc_outmix.outputMix = ctx->outmixObj;
   SLDataSink sink;
   sink.pLocator = &loc_outmix;
   sink.pFormat = NULL;
 
   const SLInterfaceID ids[] = {ctx->SL_IID_BUFFERQUEUE};
   const SLboolean req[] = {SL_BOOLEAN_TRUE};
-  res = (*ctx->eng)->CreateAudioPlayer(ctx->eng, &stm->playerObj,
-                                       &source, &sink, 1, ids, req);
+  SLresult res = (*ctx->eng)->CreateAudioPlayer(ctx->eng, &stm->playerObj,
+                                                &source, &sink, 1, ids, req);
   if (res != SL_RESULT_SUCCESS) {
     cubeb_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   res = (*stm->playerObj)->Realize(stm->playerObj, SL_BOOLEAN_FALSE);
   if (res != SL_RESULT_SUCCESS) {
     cubeb_stream_destroy(stm);
@@ -283,18 +283,16 @@ cubeb_stream_init(cubeb * ctx, cubeb_str
   return CUBEB_OK;
 }
 
 void
 cubeb_stream_destroy(cubeb_stream * stm)
 {
   if (stm->playerObj)
     (*stm->playerObj)->Destroy(stm->playerObj);
-  if (stm->outmixObj)
-    (*stm->outmixObj)->Destroy(stm->outmixObj);
   free(stm);
 }
 
 int
 cubeb_stream_start(cubeb_stream * stm)
 {
   SLresult res = (*stm->play)->SetPlayState(stm->play, SL_PLAYSTATE_PLAYING);
   if (res != SL_RESULT_SUCCESS)