summaryrefslogtreecommitdiff
path: root/gst
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2015-07-14 15:58:43 +0200
committerWim Taymans <wtaymans@redhat.com>2015-07-14 16:01:10 +0200
commit2b2766494bc8b2e49ded063bb6caa0ecfd858762 (patch)
tree14d81ce17a6a5fd0e7b406456863764bee7e984d /gst
parent07d5e7ab4d233d1f1c6cc030c26967cede117433 (diff)
socketsrc: add caps property
Add caps property that allows the src to easily negotiate a format.
Diffstat (limited to 'gst')
-rw-r--r--gst/tcp/gstsocketsrc.c64
-rw-r--r--gst/tcp/gstsocketsrc.h1
2 files changed, 65 insertions, 0 deletions
diff --git a/gst/tcp/gstsocketsrc.c b/gst/tcp/gstsocketsrc.c
index 81eef0a5e..149ced185 100644
--- a/gst/tcp/gstsocketsrc.c
+++ b/gst/tcp/gstsocketsrc.c
@@ -69,6 +69,7 @@ enum
{
PROP_0,
PROP_SOCKET,
+ PROP_CAPS,
};
enum
@@ -85,6 +86,7 @@ G_DEFINE_TYPE (GstSocketSrc, gst_socket_src, GST_TYPE_PUSH_SRC);
static void gst_socket_src_finalize (GObject * gobject);
+static GstCaps *gst_socketsrc_getcaps (GstBaseSrc * src, GstCaps * filter);
static GstFlowReturn gst_socket_src_fill (GstPushSrc * psrc,
GstBuffer * outbuf);
static gboolean gst_socket_src_unlock (GstBaseSrc * bsrc);
@@ -119,6 +121,11 @@ gst_socket_src_class_init (GstSocketSrcClass * klass)
"The socket to receive packets from", G_TYPE_SOCKET,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (gobject_class, PROP_CAPS,
+ g_param_spec_boxed ("caps", "Caps",
+ "The caps of the source pad", GST_TYPE_CAPS,
+ G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
gst_socket_src_signals[CONNECTION_CLOSED_BY_PEER] =
g_signal_new ("connection-closed-by-peer", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (GstSocketSrcClass,
@@ -133,6 +140,7 @@ gst_socket_src_class_init (GstSocketSrcClass * klass)
"Thomas Vander Stichele <thomas at apestaart dot org>, "
"William Manley <will@williammanley.net>");
+ gstbasesrc_class->get_caps = gst_socketsrc_getcaps;
gstbasesrc_class->unlock = gst_socket_src_unlock;
gstbasesrc_class->unlock_stop = gst_socket_src_unlock_stop;
@@ -153,12 +161,40 @@ gst_socket_src_finalize (GObject * gobject)
{
GstSocketSrc *this = GST_SOCKET_SRC (gobject);
+ if (this->caps)
+ gst_caps_unref (this->caps);
g_clear_object (&this->cancellable);
g_clear_object (&this->socket);
G_OBJECT_CLASS (parent_class)->finalize (gobject);
}
+static GstCaps *
+gst_socketsrc_getcaps (GstBaseSrc * src, GstCaps * filter)
+{
+ GstSocketSrc *socketsrc;
+ GstCaps *caps, *result;
+
+ socketsrc = GST_SOCKET_SRC (src);
+
+ GST_OBJECT_LOCK (src);
+ if ((caps = socketsrc->caps))
+ gst_caps_ref (caps);
+ GST_OBJECT_UNLOCK (src);
+
+ if (caps) {
+ if (filter) {
+ result = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (caps);
+ } else {
+ result = caps;
+ }
+ } else {
+ result = (filter) ? gst_caps_ref (filter) : gst_caps_new_any ();
+ }
+ return result;
+}
+
static GstFlowReturn
gst_socket_src_fill (GstPushSrc * psrc, GstBuffer * outbuf)
{
@@ -285,6 +321,29 @@ gst_socket_src_set_property (GObject * object, guint prop_id,
g_clear_object (&socket);
break;
}
+ case PROP_CAPS:
+ {
+ const GstCaps *new_caps_val = gst_value_get_caps (value);
+ GstCaps *new_caps;
+ GstCaps *old_caps;
+
+ if (new_caps_val == NULL) {
+ new_caps = gst_caps_new_any ();
+ } else {
+ new_caps = gst_caps_copy (new_caps_val);
+ }
+
+ GST_OBJECT_LOCK (socketsrc);
+ old_caps = socketsrc->caps;
+ socketsrc->caps = new_caps;
+ GST_OBJECT_UNLOCK (socketsrc);
+
+ if (old_caps)
+ gst_caps_unref (old_caps);
+
+ gst_pad_mark_reconfigure (GST_BASE_SRC_PAD (socketsrc));
+ break;
+ }
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -301,6 +360,11 @@ gst_socket_src_get_property (GObject * object, guint prop_id,
case PROP_SOCKET:
g_value_set_object (value, socketsrc->socket);
break;
+ case PROP_CAPS:
+ GST_OBJECT_LOCK (socketsrc);
+ gst_value_set_caps (value, socketsrc->caps);
+ GST_OBJECT_UNLOCK (socketsrc);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
diff --git a/gst/tcp/gstsocketsrc.h b/gst/tcp/gstsocketsrc.h
index e628b3a5a..9529e1218 100644
--- a/gst/tcp/gstsocketsrc.h
+++ b/gst/tcp/gstsocketsrc.h
@@ -48,6 +48,7 @@ struct _GstSocketSrc {
GstPushSrc element;
/*< private >*/
+ GstCaps *caps;
GSocket *socket;
GCancellable *cancellable;
};