#include "gstappsrc.h"
+typedef enum
+{
+ NOONE_WAITING,
+ STREAM_WAITING, /* streaming thread is waiting for application thread */
+ APP_WAITING, /* application thread is waiting for streaming thread */
+} GstAppSrcWaitStatus;
+
struct _GstAppSrcPrivate
{
GCond cond;
GMutex mutex;
GstQueueArray *queue;
+ GstAppSrcWaitStatus wait_status;
GstCaps *last_caps;
GstCaps *current_caps;
g_mutex_init (&priv->mutex);
g_cond_init (&priv->cond);
priv->queue = gst_queue_array_new (16);
+ priv->wait_status = NOONE_WAITING;
priv->size = DEFAULT_PROP_SIZE;
priv->duration = DEFAULT_PROP_DURATION;
priv->offset += buf_size;
/* signal that we removed an item */
- g_cond_broadcast (&priv->cond);
+ if (priv->wait_status == APP_WAITING)
+ g_cond_broadcast (&priv->cond);
/* see if we go lower than the empty-percent */
if (priv->min_percent && priv->max_bytes) {
goto eos;
/* nothing to return, wait a while for new data or flushing. */
+ priv->wait_status = STREAM_WAITING;
g_cond_wait (&priv->cond, &priv->mutex);
+ priv->wait_status = NOONE_WAITING;
}
g_mutex_unlock (&priv->mutex);
return ret;
GST_DEBUG_OBJECT (appsrc, "waiting for free space");
/* we are filled, wait until a buffer gets popped or when we
* flush. */
+ priv->wait_status = APP_WAITING;
g_cond_wait (&priv->cond, &priv->mutex);
+ priv->wait_status = NOONE_WAITING;
} else {
/* no need to wait for free space, we just pump more data into the
* queue hoping that the caller reacts to the enough-data signal and
gst_queue_array_push_tail (priv->queue, buffer);
priv->queued_bytes += gst_buffer_get_size (buffer);
}
- g_cond_broadcast (&priv->cond);
+
+ if (priv->wait_status == STREAM_WAITING)
+ g_cond_broadcast (&priv->cond);
+
g_mutex_unlock (&priv->mutex);
return GST_FLOW_OK;