mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-25 11:11:08 +00:00
appsrc: Make caps set action queued together with buffer
https://bugzilla.gnome.org/show_bug.cgi?id=729760
This commit is contained in:
parent
a0a9fd004b
commit
251c63c4ab
1 changed files with 59 additions and 27 deletions
|
@ -104,14 +104,15 @@ struct _GstAppSrcPrivate
|
||||||
GMutex mutex;
|
GMutex mutex;
|
||||||
GQueue *queue;
|
GQueue *queue;
|
||||||
|
|
||||||
GstCaps *caps;
|
GstCaps *last_caps;
|
||||||
|
GstCaps *current_caps;
|
||||||
|
|
||||||
gint64 size;
|
gint64 size;
|
||||||
GstAppStreamType stream_type;
|
GstAppStreamType stream_type;
|
||||||
guint64 max_bytes;
|
guint64 max_bytes;
|
||||||
GstFormat format;
|
GstFormat format;
|
||||||
gboolean block;
|
gboolean block;
|
||||||
gchar *uri;
|
gchar *uri;
|
||||||
gboolean new_caps;
|
|
||||||
|
|
||||||
gboolean flushing;
|
gboolean flushing;
|
||||||
gboolean started;
|
gboolean started;
|
||||||
|
@ -530,11 +531,15 @@ gst_app_src_init (GstAppSrc * appsrc)
|
||||||
static void
|
static void
|
||||||
gst_app_src_flush_queued (GstAppSrc * src)
|
gst_app_src_flush_queued (GstAppSrc * src)
|
||||||
{
|
{
|
||||||
GstBuffer *buf;
|
GstMiniObject *caps_or_buffer;
|
||||||
GstAppSrcPrivate *priv = src->priv;
|
GstAppSrcPrivate *priv = src->priv;
|
||||||
|
|
||||||
while ((buf = g_queue_pop_head (priv->queue)))
|
while ((caps_or_buffer = g_queue_pop_head (priv->queue))) {
|
||||||
gst_buffer_unref (buf);
|
if (caps_or_buffer) {
|
||||||
|
gst_mini_object_unref (caps_or_buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
priv->queued_bytes = 0;
|
priv->queued_bytes = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,9 +550,13 @@ gst_app_src_dispose (GObject * obj)
|
||||||
GstAppSrcPrivate *priv = appsrc->priv;
|
GstAppSrcPrivate *priv = appsrc->priv;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (appsrc);
|
GST_OBJECT_LOCK (appsrc);
|
||||||
if (priv->caps) {
|
if (priv->current_caps) {
|
||||||
gst_caps_unref (priv->caps);
|
gst_caps_unref (priv->current_caps);
|
||||||
priv->caps = NULL;
|
priv->current_caps = NULL;
|
||||||
|
}
|
||||||
|
if (priv->last_caps) {
|
||||||
|
gst_caps_unref (priv->last_caps);
|
||||||
|
priv->last_caps = NULL;
|
||||||
}
|
}
|
||||||
if (priv->notify) {
|
if (priv->notify) {
|
||||||
priv->notify (priv->user_data);
|
priv->notify (priv->user_data);
|
||||||
|
@ -583,7 +592,7 @@ gst_app_src_internal_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (appsrc);
|
GST_OBJECT_LOCK (appsrc);
|
||||||
if ((caps = appsrc->priv->caps))
|
if ((caps = appsrc->priv->current_caps))
|
||||||
gst_caps_ref (caps);
|
gst_caps_ref (caps);
|
||||||
GST_OBJECT_UNLOCK (appsrc);
|
GST_OBJECT_UNLOCK (appsrc);
|
||||||
|
|
||||||
|
@ -767,7 +776,6 @@ gst_app_src_start (GstBaseSrc * bsrc)
|
||||||
|
|
||||||
g_mutex_lock (&priv->mutex);
|
g_mutex_lock (&priv->mutex);
|
||||||
GST_DEBUG_OBJECT (appsrc, "starting");
|
GST_DEBUG_OBJECT (appsrc, "starting");
|
||||||
priv->new_caps = FALSE;
|
|
||||||
priv->started = TRUE;
|
priv->started = TRUE;
|
||||||
/* set the offset to -1 so that we always do a first seek. This is only used
|
/* set the offset to -1 so that we always do a first seek. This is only used
|
||||||
* in random-access mode. */
|
* in random-access mode. */
|
||||||
|
@ -978,7 +986,7 @@ gst_app_src_do_negotiate (GstBaseSrc * basesrc)
|
||||||
GstCaps *caps;
|
GstCaps *caps;
|
||||||
|
|
||||||
GST_OBJECT_LOCK (basesrc);
|
GST_OBJECT_LOCK (basesrc);
|
||||||
caps = priv->caps ? gst_caps_ref (priv->caps) : NULL;
|
caps = priv->current_caps ? gst_caps_ref (priv->current_caps) : NULL;
|
||||||
GST_OBJECT_UNLOCK (basesrc);
|
GST_OBJECT_UNLOCK (basesrc);
|
||||||
|
|
||||||
/* Avoid deadlock by unlocking mutex
|
/* Avoid deadlock by unlocking mutex
|
||||||
|
@ -1003,7 +1011,6 @@ gst_app_src_negotiate (GstBaseSrc * basesrc)
|
||||||
gboolean result;
|
gboolean result;
|
||||||
|
|
||||||
g_mutex_lock (&priv->mutex);
|
g_mutex_lock (&priv->mutex);
|
||||||
priv->new_caps = FALSE;
|
|
||||||
result = gst_app_src_do_negotiate (basesrc);
|
result = gst_app_src_do_negotiate (basesrc);
|
||||||
g_mutex_unlock (&priv->mutex);
|
g_mutex_unlock (&priv->mutex);
|
||||||
return result;
|
return result;
|
||||||
|
@ -1059,10 +1066,26 @@ gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
|
||||||
/* return data as long as we have some */
|
/* return data as long as we have some */
|
||||||
if (!g_queue_is_empty (priv->queue)) {
|
if (!g_queue_is_empty (priv->queue)) {
|
||||||
guint buf_size;
|
guint buf_size;
|
||||||
|
GstMiniObject *caps_or_buffer = g_queue_pop_head (priv->queue);
|
||||||
|
|
||||||
if (priv->new_caps) {
|
if (!GST_IS_BUFFER (caps_or_buffer)) {
|
||||||
priv->new_caps = FALSE;
|
|
||||||
gst_app_src_do_negotiate (bsrc);
|
GstCaps *next_caps = caps_or_buffer;
|
||||||
|
gboolean caps_changed = TRUE;
|
||||||
|
|
||||||
|
if (next_caps && priv->current_caps)
|
||||||
|
caps_changed = !gst_caps_is_equal (next_caps, priv->current_caps);
|
||||||
|
else
|
||||||
|
caps_changed = (next_caps != priv->current_caps);
|
||||||
|
|
||||||
|
gst_caps_replace (&priv->current_caps, next_caps);
|
||||||
|
|
||||||
|
if (next_caps) {
|
||||||
|
gst_caps_unref (next_caps);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caps_changed)
|
||||||
|
gst_app_src_do_negotiate (bsrc);
|
||||||
|
|
||||||
/* Lock has released so now may need
|
/* Lock has released so now may need
|
||||||
*- flushing
|
*- flushing
|
||||||
|
@ -1073,7 +1096,7 @@ gst_app_src_create (GstBaseSrc * bsrc, guint64 offset, guint size,
|
||||||
/* Contiue checks caps and queue */
|
/* Contiue checks caps and queue */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*buf = g_queue_pop_head (priv->queue);
|
*buf = GST_BUFFER (caps_or_buffer);
|
||||||
buf_size = gst_buffer_get_size (*buf);
|
buf_size = gst_buffer_get_size (*buf);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (appsrc, "we have buffer %p of size %u", *buf, buf_size);
|
GST_DEBUG_OBJECT (appsrc, "we have buffer %p of size %u", *buf, buf_size);
|
||||||
|
@ -1161,7 +1184,7 @@ seek_error:
|
||||||
void
|
void
|
||||||
gst_app_src_set_caps (GstAppSrc * appsrc, const GstCaps * caps)
|
gst_app_src_set_caps (GstAppSrc * appsrc, const GstCaps * caps)
|
||||||
{
|
{
|
||||||
GstCaps *old;
|
GstCaps *new_caps;
|
||||||
GstAppSrcPrivate *priv;
|
GstAppSrcPrivate *priv;
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_APP_SRC (appsrc));
|
g_return_if_fail (GST_IS_APP_SRC (appsrc));
|
||||||
|
@ -1172,15 +1195,15 @@ gst_app_src_set_caps (GstAppSrc * appsrc, const GstCaps * caps)
|
||||||
|
|
||||||
GST_OBJECT_LOCK (appsrc);
|
GST_OBJECT_LOCK (appsrc);
|
||||||
GST_DEBUG_OBJECT (appsrc, "setting caps to %" GST_PTR_FORMAT, caps);
|
GST_DEBUG_OBJECT (appsrc, "setting caps to %" GST_PTR_FORMAT, caps);
|
||||||
if ((old = priv->caps) != caps) {
|
if (caps)
|
||||||
if (caps)
|
new_caps = gst_caps_copy (caps);
|
||||||
priv->caps = gst_caps_copy (caps);
|
else
|
||||||
else
|
new_caps = NULL;
|
||||||
priv->caps = NULL;
|
|
||||||
if (old)
|
g_queue_push_tail (priv->queue, new_caps);
|
||||||
gst_caps_unref (old);
|
|
||||||
priv->new_caps = TRUE;
|
gst_caps_replace (&priv->last_caps, new_caps);
|
||||||
}
|
|
||||||
GST_OBJECT_UNLOCK (appsrc);
|
GST_OBJECT_UNLOCK (appsrc);
|
||||||
|
|
||||||
g_mutex_unlock (&priv->mutex);
|
g_mutex_unlock (&priv->mutex);
|
||||||
|
@ -1197,9 +1220,18 @@ gst_app_src_set_caps (GstAppSrc * appsrc, const GstCaps * caps)
|
||||||
GstCaps *
|
GstCaps *
|
||||||
gst_app_src_get_caps (GstAppSrc * appsrc)
|
gst_app_src_get_caps (GstAppSrc * appsrc)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
GstCaps *caps;
|
||||||
|
|
||||||
g_return_val_if_fail (GST_IS_APP_SRC (appsrc), NULL);
|
g_return_val_if_fail (GST_IS_APP_SRC (appsrc), NULL);
|
||||||
|
|
||||||
return gst_app_src_internal_get_caps (GST_BASE_SRC_CAST (appsrc), NULL);
|
GST_OBJECT_LOCK (appsrc);
|
||||||
|
if ((caps = appsrc->priv->last_caps))
|
||||||
|
gst_caps_ref (caps);
|
||||||
|
GST_OBJECT_UNLOCK (appsrc);
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue