Bug 1189197 - enqueue a silent frame to kick off the buffer queue callbacks. r=kinetik.
authorJW Wang <jwwang@mozilla.com>
Fri, 31 Jul 2015 13:25:59 +0800
changeset 255614 692828b8e47a601b4c8dc83ff26409d6f5b1ec54
parent 255613 8eace5363f8590a120f7e89a4ed05e8b51742285
child 255615 ecf03b35eac02455ad1b8080f78400e5040329df
push id14346
push usercbook@mozilla.com
push dateFri, 31 Jul 2015 12:21:03 +0000
treeherderfx-team@97c79f717d2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1189197
milestone42.0a1
Bug 1189197 - enqueue a silent frame to kick off the buffer queue callbacks. r=kinetik.
media/libcubeb/src/cubeb_opensl.c
--- a/media/libcubeb/src/cubeb_opensl.c
+++ b/media/libcubeb/src/cubeb_opensl.c
@@ -648,16 +648,27 @@ opensl_stream_init(cubeb * ctx, cubeb_st
   }
 
   res = (*stm->bufq)->RegisterCallback(stm->bufq, bufferqueue_callback, stm);
   if (res != SL_RESULT_SUCCESS) {
     opensl_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
+  {
+    // Enqueue a silent frame so once the player becomes playing, the frame
+    // will be consumed and kick off the buffer queue callback.
+    // Note the duration of a single frame is less than 1ms. We don't bother
+    // adjusting the playback position.
+    uint8_t *buf = stm->queuebuf[stm->queuebuf_idx++];
+    memset(buf, 0, stm->framesize);
+    res = (*stm->bufq)->Enqueue(stm->bufq, buf, stm->framesize);
+    assert(res == SL_RESULT_SUCCESS);
+  }
+
   *stream = stm;
   return CUBEB_OK;
 }
 
 static void
 opensl_stream_destroy(cubeb_stream * stm)
 {
   if (stm->playerObj)
@@ -671,19 +682,16 @@ opensl_stream_destroy(cubeb_stream * stm
   cubeb_resampler_destroy(stm->resampler);
 
   free(stm);
 }
 
 static int
 opensl_stream_start(cubeb_stream * stm)
 {
-  /* To refill the queues before starting playback in order to avoid racing
-   * with refills started by SetPlayState on OpenSLES ndk threads. */
-  bufferqueue_callback(NULL, stm);
   SLresult res = (*stm->play)->SetPlayState(stm->play, SL_PLAYSTATE_PLAYING);
   if (res != SL_RESULT_SUCCESS)
     return CUBEB_ERROR;
   stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STARTED);
   return CUBEB_OK;
 }
 
 static int