client-source: fix caps handling

The caps we stream between the src and sink are always
application/x-pinos. Keep the negotiated format ouside of the
capsfilter in a separate variable. We can then also avoid a query
to get the format.
This commit is contained in:
Wim Taymans 2015-12-03 15:47:53 +01:00
parent 1e5c892564
commit d81cbb2d93

View file

@ -31,10 +31,10 @@ struct _PinosClientSourcePrivate
{ {
GstElement *pipeline; GstElement *pipeline;
GstElement *src; GstElement *src;
GstElement *filter;
GstElement *sink; GstElement *sink;
guint id; guint id;
GstCaps *format;
GSocket *socket; GSocket *socket;
GBytes *possible_formats; GBytes *possible_formats;
@ -129,8 +129,10 @@ setup_pipeline (PinosClientSource *source)
PinosClientSourcePrivate *priv = source->priv; PinosClientSourcePrivate *priv = source->priv;
GstBus *bus; GstBus *bus;
priv->pipeline = gst_parse_launch ("socketsrc name=src ! " priv->pipeline = gst_parse_launch ("socketsrc "
"capsfilter name=filter ! " "name=src "
"caps=application/x-pinos ! "
"pinospay ! "
"multisocketsink " "multisocketsink "
"buffers-max=2 " "buffers-max=2 "
"buffers-soft-max=1 " "buffers-soft-max=1 "
@ -140,7 +142,6 @@ setup_pipeline (PinosClientSource *source)
"sync=true " "sync=true "
"enable-last-sample=false", "enable-last-sample=false",
NULL); NULL);
priv->filter = gst_bin_get_by_name (GST_BIN (priv->pipeline), "filter");
priv->sink = gst_bin_get_by_name (GST_BIN (priv->pipeline), "sink"); priv->sink = gst_bin_get_by_name (GST_BIN (priv->pipeline), "sink");
priv->src = gst_bin_get_by_name (GST_BIN (priv->pipeline), "src"); priv->src = gst_bin_get_by_name (GST_BIN (priv->pipeline), "src");
@ -154,16 +155,11 @@ collect_caps (PinosSource *source,
GstCaps *filter) GstCaps *filter)
{ {
PinosClientSourcePrivate *priv = PINOS_CLIENT_SOURCE (source)->priv; PinosClientSourcePrivate *priv = PINOS_CLIENT_SOURCE (source)->priv;
GstCaps *res;
GstQuery *query;
query = gst_query_new_caps (NULL); if (priv->format)
gst_element_query (priv->filter, query); return gst_caps_ref (priv->format);
gst_query_parse_caps_result (query, &res); else
gst_caps_ref (res); return gst_caps_new_any ();
gst_query_unref (query);
return res;
} }
static gboolean static gboolean
@ -327,11 +323,12 @@ client_source_finalize (GObject * object)
PinosClientSourcePrivate *priv = PINOS_CLIENT_SOURCE (object)->priv; PinosClientSourcePrivate *priv = PINOS_CLIENT_SOURCE (object)->priv;
g_clear_object (&priv->input); g_clear_object (&priv->input);
g_clear_object (&priv->filter);
g_clear_object (&priv->sink); g_clear_object (&priv->sink);
g_clear_object (&priv->src); g_clear_object (&priv->src);
g_clear_object (&priv->pipeline); g_clear_object (&priv->pipeline);
gst_caps_replace (&priv->format, NULL);
G_OBJECT_CLASS (pinos_client_source_parent_class)->finalize (object); G_OBJECT_CLASS (pinos_client_source_parent_class)->finalize (object);
} }
@ -355,14 +352,13 @@ on_input_socket_notify (GObject *gobject,
g_assert (requested_format != NULL); g_assert (requested_format != NULL);
g_object_set (gobject, "format", requested_format, NULL); g_object_set (gobject, "format", requested_format, NULL);
/* and set as caps on the source */ /* and set as the current format */
caps = gst_caps_from_string (g_bytes_get_data (requested_format, NULL)); caps = gst_caps_from_string (g_bytes_get_data (requested_format, NULL));
g_assert (caps != NULL); g_assert (caps != NULL);
g_object_set (priv->src, "caps", caps, NULL); gst_caps_replace (&priv->format, caps);
gst_caps_unref (caps);
g_bytes_unref (requested_format); g_bytes_unref (requested_format);
} else { } else {
g_object_set (priv->src, "caps", NULL, NULL); gst_caps_replace (&priv->format, NULL);
} }
g_object_set (priv->src, "socket", socket, NULL); g_object_set (priv->src, "socket", socket, NULL);
@ -385,11 +381,10 @@ pinos_client_source_get_source_input (PinosClientSource *source,
g_return_val_if_fail (PINOS_IS_CLIENT_SOURCE (source), NULL); g_return_val_if_fail (PINOS_IS_CLIENT_SOURCE (source), NULL);
priv = source->priv; priv = source->priv;
if (priv->input == NULL) { if (priv->input == NULL) {
GstCaps *caps = gst_caps_from_string (g_bytes_get_data (format_filter, NULL)); GstCaps *caps = gst_caps_from_string (g_bytes_get_data (format_filter, NULL));
g_object_set (priv->filter, "caps", caps, NULL); gst_caps_replace (&priv->format, caps);
priv->input = PINOS_SOURCE_CLASS (pinos_client_source_parent_class) priv->input = PINOS_SOURCE_CLASS (pinos_client_source_parent_class)
->create_source_output (PINOS_SOURCE (source), ->create_source_output (PINOS_SOURCE (source),