opensles: ensure that we register the callback only in STOPPED
authorJosep Torra <n770galaxy@gmail.com>
Thu, 27 Sep 2012 16:33:09 +0000 (18:33 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Thu, 18 Oct 2012 12:03:09 +0000 (14:03 +0200)
Fixes the error registering the callback on the PLAYING -> PAUSE ->
PLAYING state change sequence.

sys/opensles/openslesringbuffer.c
sys/opensles/openslesringbuffer.h

index 295658a..aa0486a 100644 (file)
@@ -215,12 +215,15 @@ _opensles_recorder_start (GstRingBuffer * rb)
   gint i;
 
   /* Register callback on the buffer queue */
-  result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue,
-      _opensles_recorder_cb, rb);
-  if (result != SL_RESULT_SUCCESS) {
-    GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)",
-        (guint32) result);
-    return FALSE;
+  if (!thiz->is_queue_callback_registered) {
+    result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue,
+        _opensles_recorder_cb, rb);
+    if (result != SL_RESULT_SUCCESS) {
+      GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)",
+          (guint32) result);
+      return FALSE;
+    }
+    thiz->is_queue_callback_registered = TRUE;
   }
 
   /* Fill the queue by enqueing buffers */
@@ -264,6 +267,7 @@ _opensles_recorder_stop (GstRingBuffer * rb)
         (guint32) result);
     return FALSE;
   }
+  thiz->is_queue_callback_registered = FALSE;
 
   /* Reset the queue */
   result = (*thiz->bufferQueue)->Clear (thiz->bufferQueue);
@@ -494,12 +498,15 @@ _opensles_player_start (GstRingBuffer * rb)
   gint i;
 
   /* Register callback on the buffer queue */
-  result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue,
-      _opensles_player_cb, rb);
-  if (result != SL_RESULT_SUCCESS) {
-    GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)",
-        (guint32) result);
-    return FALSE;
+  if (!thiz->is_queue_callback_registered) {
+    result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue,
+        _opensles_player_cb, rb);
+    if (result != SL_RESULT_SUCCESS) {
+      GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)",
+          (guint32) result);
+      return FALSE;
+    }
+    thiz->is_queue_callback_registered = TRUE;
   }
 
   /* Fill the queue by enqueing buffers */
@@ -561,6 +568,7 @@ _opensles_player_stop (GstRingBuffer * rb)
         (guint32) result);
     return FALSE;
   }
+  thiz->is_queue_callback_registered = FALSE;
 
   /* Reset the queue */
   result = (*thiz->bufferQueue)->Clear (thiz->bufferQueue);
@@ -571,6 +579,7 @@ _opensles_player_stop (GstRingBuffer * rb)
   }
 
   g_atomic_int_set (&thiz->segqueued, 0);
+  thiz->cursor = 0;
 
   return TRUE;
 }
@@ -900,4 +909,5 @@ gst_opensles_ringbuffer_init (GstOpenSLESRingBuffer * thiz,
   thiz->outputMixObject = NULL;
   thiz->playerObject = NULL;
   thiz->recorderObject = NULL;
+  thiz->is_queue_callback_registered = FALSE;
 }
index b9111e8..2673685 100644 (file)
@@ -88,6 +88,7 @@ struct _GstOpenSLESRingBuffer
   guint8 * data;
   guint cursor;
   gint segqueued; /* ATOMIC */
+  gboolean is_queue_callback_registered;
 
   /* vmethods */
   AcquireFunc acquire;