From 3ec8704c9e674fab5b27f61e131cb89641b731a0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 6 May 2005 17:13:49 +0000 Subject: [PATCH] Fixed negotiation wrt _peer_get_caps() Original commit message from CVS: * gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain), (gst_audio_convert_caps_remove_format_info), (gst_audio_convert_getcaps), (gst_audio_convert_setcaps), (gst_audio_convert_fixate), (gst_audio_convert_channels): * gst/ffmpegcolorspace/gstffmpegcolorspace.c: (gst_ffmpegcsp_getcaps), (gst_ffmpegcsp_configure_context), (gst_ffmpegcsp_setcaps), (gst_ffmpegcsp_chain): * gst/sine/Makefile.am: * gst/sine/gstsinesrc.c: (gst_sinesrc_get_type), (gst_sinesrc_class_init), (gst_sinesrc_init), (gst_sinesrc_src_fixate), (gst_sinesrc_setcaps), (gst_sinesrc_src_query), (gst_sinesrc_create), (gst_sinesrc_start), (gst_sinesrc_update_freq): * gst/sine/gstsinesrc.h: * gst/tcp/gstmultifdsink.c: * sys/xvimage/xvimagesink.c: Fixed negotiation wrt _peer_get_caps() Some cleanups. --- ChangeLog | 22 ++++ gst/audioconvert/gstaudioconvert.c | 17 +-- gst/ffmpegcolorspace/gstffmpegcolorspace.c | 14 ++- gst/sine/Makefile.am | 2 +- gst/sine/gstsinesrc.c | 159 +++++++++-------------------- gst/sine/gstsinesrc.h | 5 +- gst/tcp/gstmultifdsink.c | 2 +- sys/xvimage/xvimagesink.c | 39 ------- 8 files changed, 96 insertions(+), 164 deletions(-) diff --git a/ChangeLog b/ChangeLog index 47c5f09..55aacaf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,27 @@ 2005-05-06 Wim Taymans + * gst/audioconvert/gstaudioconvert.c: (gst_audio_convert_chain), + (gst_audio_convert_caps_remove_format_info), + (gst_audio_convert_getcaps), (gst_audio_convert_setcaps), + (gst_audio_convert_fixate), (gst_audio_convert_channels): + * gst/ffmpegcolorspace/gstffmpegcolorspace.c: + (gst_ffmpegcsp_getcaps), (gst_ffmpegcsp_configure_context), + (gst_ffmpegcsp_setcaps), (gst_ffmpegcsp_chain): + * gst/sine/Makefile.am: + * gst/sine/gstsinesrc.c: (gst_sinesrc_get_type), + (gst_sinesrc_class_init), (gst_sinesrc_init), + (gst_sinesrc_src_fixate), (gst_sinesrc_setcaps), + (gst_sinesrc_src_query), (gst_sinesrc_create), (gst_sinesrc_start), + (gst_sinesrc_update_freq): + * gst/sine/gstsinesrc.h: + * gst/tcp/gstmultifdsink.c: + * sys/xvimage/xvimagesink.c: + Fixed negotiation wrt _peer_get_caps() + Some cleanups. + + +2005-05-06 Wim Taymans + * gst-libs/gst/audio/gstaudiosink.c: (gst_audioringbuffer_get_type), (gst_audioringbuffer_class_init), (audioringbuffer_thread_func), (gst_audioringbuffer_init), diff --git a/gst/audioconvert/gstaudioconvert.c b/gst/audioconvert/gstaudioconvert.c index c4aca50..d9f7427 100644 --- a/gst/audioconvert/gstaudioconvert.c +++ b/gst/audioconvert/gstaudioconvert.c @@ -328,12 +328,17 @@ gst_audio_convert_getcaps (GstPad * pad) /* we can do all our peer can */ othercaps = gst_pad_peer_get_caps (otherpad); - /* without the format info even */ - othercaps = gst_audio_convert_caps_remove_format_info (pad, othercaps); - /* but filtered against our template */ - templcaps = gst_pad_get_pad_template_caps (pad); - caps = gst_caps_intersect (othercaps, templcaps); - gst_caps_unref (othercaps); + if (othercaps != NULL) { + /* without the format info even */ + othercaps = gst_audio_convert_caps_remove_format_info (pad, othercaps); + /* but filtered against our template */ + templcaps = gst_pad_get_pad_template_caps (pad); + caps = gst_caps_intersect (othercaps, templcaps); + gst_caps_unref (othercaps); + } else { + /* no peer, then our template is enough */ + caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); + } /* Get the channel positions in as well. */ gst_audio_set_caps_channel_positions_list (caps, supported_positions, diff --git a/gst/ffmpegcolorspace/gstffmpegcolorspace.c b/gst/ffmpegcolorspace/gstffmpegcolorspace.c index 80b0732..8eb90c8 100644 --- a/gst/ffmpegcolorspace/gstffmpegcolorspace.c +++ b/gst/ffmpegcolorspace/gstffmpegcolorspace.c @@ -157,11 +157,15 @@ gst_ffmpegcsp_getcaps (GstPad * pad) otherpad = (pad == space->srcpad) ? space->sinkpad : space->srcpad; /* we can do whatever the peer can */ othercaps = gst_pad_peer_get_caps (otherpad); - /* without the format info */ - othercaps = gst_ffmpegcsp_caps_remove_format_info (othercaps); - /* and filtered against our padtemplate */ - caps = gst_caps_intersect (othercaps, gst_pad_get_pad_template_caps (pad)); - gst_caps_unref (othercaps); + if (othercaps != NULL) { + /* without the format info */ + othercaps = gst_ffmpegcsp_caps_remove_format_info (othercaps); + /* and filtered against our padtemplate */ + caps = gst_caps_intersect (othercaps, gst_pad_get_pad_template_caps (pad)); + gst_caps_unref (othercaps); + } else { + caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad)); + } return caps; } diff --git a/gst/sine/Makefile.am b/gst/sine/Makefile.am index 7902928..3c6a950 100644 --- a/gst/sine/Makefile.am +++ b/gst/sine/Makefile.am @@ -3,7 +3,7 @@ plugin_LTLIBRARIES = libgstsinesrc.la libgstsinesrc_la_SOURCES = gstsinesrc.c libgstsinesrc_la_CFLAGS = $(GST_CFLAGS) -libgstsinesrc_la_LIBADD = $(GST_LIBS) $(GST_CONTROL_LIBS) +libgstsinesrc_la_LIBADD = $(GST_LIBS) $(GST_CONTROL_LIBS) $(GST_BASE_LIBS) libgstsinesrc_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) noinst_HEADERS = gstsinesrc.h diff --git a/gst/sine/gstsinesrc.c b/gst/sine/gstsinesrc.c index 962d8c0..1f71c5c 100644 --- a/gst/sine/gstsinesrc.c +++ b/gst/sine/gstsinesrc.c @@ -72,13 +72,14 @@ static void gst_sinesrc_class_init (GstSineSrcClass * klass); static void gst_sinesrc_base_init (GstSineSrcClass * klass); static void gst_sinesrc_init (GstSineSrc * src); static void gst_sinesrc_dispose (GObject * object); + static void gst_sinesrc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_sinesrc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -static GstPadLinkReturn gst_sinesrc_link (GstPad * pad, GstPad * peerpad); -static GstElementStateReturn gst_sinesrc_change_state (GstElement * element); -static void gst_sinesrc_set_clock (GstElement * element, GstClock * clock); + +static gboolean gst_sinesrc_setcaps (GstBaseSrc * basesrc, GstCaps * caps); +static GstCaps *gst_sinesrc_src_fixate (GstPad * pad, GstCaps * caps); static void gst_sinesrc_update_freq (const GValue * value, gpointer data); static void gst_sinesrc_populate_sinetable (GstSineSrc * src); @@ -88,9 +89,9 @@ static const GstQueryType *gst_sinesrc_get_query_types (GstPad * pad); static gboolean gst_sinesrc_src_query (GstPad * pad, GstQueryType type, GstFormat * format, gint64 * value); -static GstFlowReturn gst_sinesrc_getrange (GstPad * pad, guint64 offset, +static GstFlowReturn gst_sinesrc_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstBuffer ** buffer); -static GstCaps *gst_sinesrc_src_fixate (GstPad * pad, GstCaps * caps); +static gboolean gst_sinesrc_start (GstBaseSrc * basesrc); static GstElementClass *parent_class = NULL; @@ -110,7 +111,7 @@ gst_sinesrc_get_type (void) (GInstanceInitFunc) gst_sinesrc_init, }; - sinesrc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstSineSrc", + sinesrc_type = g_type_register_static (GST_TYPE_BASESRC, "GstSineSrc", &sinesrc_info, 0); } return sinesrc_type; @@ -131,11 +132,13 @@ gst_sinesrc_class_init (GstSineSrcClass * klass) { GObjectClass *gobject_class; GstElementClass *gstelement_class; + GstBaseSrcClass *gstbasesrc_class; gobject_class = (GObjectClass *) klass; gstelement_class = (GstElementClass *) klass; + gstbasesrc_class = (GstBaseSrcClass *) klass; - parent_class = g_type_class_ref (GST_TYPE_ELEMENT); + parent_class = g_type_class_ref (GST_TYPE_BASESRC); gobject_class->set_property = gst_sinesrc_set_property; gobject_class->get_property = gst_sinesrc_get_property; @@ -159,22 +162,20 @@ gst_sinesrc_class_init (GstSineSrcClass * klass) g_param_spec_boolean ("sync", "Sync", "Synchronize to clock", FALSE, G_PARAM_READWRITE)); - gstelement_class->change_state = gst_sinesrc_change_state; - gstelement_class->set_clock = gst_sinesrc_set_clock; + //gstbasesrc_class->get_caps = GST_DEBUG_FUNCPTR (); + gstbasesrc_class->set_caps = GST_DEBUG_FUNCPTR (gst_sinesrc_setcaps); + gstbasesrc_class->start = GST_DEBUG_FUNCPTR (gst_sinesrc_start); + gstbasesrc_class->create = GST_DEBUG_FUNCPTR (gst_sinesrc_create); } static void gst_sinesrc_init (GstSineSrc * src) { - src->srcpad = - gst_pad_new_from_template (gst_static_pad_template_get - (&gst_sinesrc_src_template), "src"); - gst_pad_set_link_function (src->srcpad, gst_sinesrc_link); + src->srcpad = GST_BASESRC (src)->srcpad; + gst_pad_set_fixatecaps_function (src->srcpad, gst_sinesrc_src_fixate); - gst_pad_set_getrange_function (src->srcpad, gst_sinesrc_getrange); gst_pad_set_query_function (src->srcpad, gst_sinesrc_src_query); gst_pad_set_query_type_function (src->srcpad, gst_sinesrc_get_query_types); - gst_element_add_pad (GST_ELEMENT (src), src->srcpad); src->samplerate = 44100; src->volume = 1.0; @@ -219,14 +220,6 @@ gst_sinesrc_dispose (GObject * object) GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object)); } -static void -gst_sinesrc_set_clock (GstElement * element, GstClock * clock) -{ - GstSineSrc *sinesrc = GST_SINESRC (element); - - gst_object_replace ((GstObject **) & sinesrc->clock, (GstObject *) clock); -} - static GstCaps * gst_sinesrc_src_fixate (GstPad * pad, GstCaps * caps) { @@ -236,37 +229,27 @@ gst_sinesrc_src_fixate (GstPad * pad, GstCaps * caps) if (gst_caps_get_size (caps) > 1) return NULL; - newcaps = gst_caps_copy (caps); + newcaps = gst_caps_make_writable (caps); structure = gst_caps_get_structure (newcaps, 0); - if (gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100)) { - return newcaps; - } + gst_caps_structure_fixate_field_nearest_int (structure, "rate", 44100); - gst_caps_unref (newcaps); - return NULL; + return newcaps; } -static GstPadLinkReturn -gst_sinesrc_link (GstPad * pad, GstPad * peerpad) +static gboolean +gst_sinesrc_setcaps (GstBaseSrc * basesrc, GstCaps * caps) { - GstCaps *caps; GstSineSrc *sinesrc; const GstStructure *structure; gboolean ret; - GST_DEBUG ("gst_sinesrc_src_link"); - sinesrc = GST_SINESRC (gst_pad_get_parent (pad)); + sinesrc = GST_SINESRC (basesrc); - caps = gst_pad_get_caps (pad); structure = gst_caps_get_structure (caps, 0); - ret = gst_structure_get_int (structure, "rate", &sinesrc->samplerate); - if (!ret) - return GST_PAD_LINK_REFUSED; - - return GST_PAD_LINK_OK; + return ret; } static const GstQueryType * @@ -287,7 +270,7 @@ gst_sinesrc_src_query (GstPad * pad, gboolean res = FALSE; GstSineSrc *src; - src = GST_SINESRC (gst_pad_get_parent (pad)); + src = GST_SINESRC (GST_PAD_PARENT (pad)); switch (type) { case GST_QUERY_POSITION: @@ -316,7 +299,7 @@ gst_sinesrc_src_query (GstPad * pad, } static GstFlowReturn -gst_sinesrc_getrange (GstPad * pad, guint64 offset, +gst_sinesrc_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstBuffer ** buffer) { GstSineSrc *src; @@ -326,8 +309,7 @@ gst_sinesrc_getrange (GstPad * pad, guint64 offset, gint16 *samples; gint i = 0; - g_return_val_if_fail (pad != NULL, GST_FLOW_ERROR); - src = GST_SINESRC (gst_pad_get_parent (pad)); + src = GST_SINESRC (basesrc); if (!src->tags_pushed) { GstTagList *taglist; @@ -338,28 +320,31 @@ gst_sinesrc_getrange (GstPad * pad, guint64 offset, gst_tag_list_add (taglist, GST_TAG_MERGE_APPEND, GST_TAG_DESCRIPTION, "sine wave", NULL); -#if 0 - gst_element_found_tags (GST_ELEMENT (src), taglist); -#endif event = gst_event_new_tag (taglist); + gst_pad_push_event (basesrc->srcpad, event); src->tags_pushed = TRUE; - *buffer = GST_BUFFER (event); - return GST_FLOW_OK; + } + + /* not negotiated, fixate and set */ + if (GST_PAD_CAPS (basesrc->srcpad) == NULL) { + GstCaps *caps; + + /* see whatever we are allowed to do */ + caps = gst_pad_get_allowed_caps (basesrc->srcpad); + /* fix unfixed values */ + caps = gst_sinesrc_src_fixate (basesrc->srcpad, caps); + /* and use those */ + gst_pad_set_caps (basesrc->srcpad, caps); + gst_caps_unref (caps); } tdiff = src->samples_per_buffer * GST_SECOND / src->samplerate; /* note: the 2 is because of the format we use */ buf = gst_buffer_new_and_alloc (src->samples_per_buffer * 2); + gst_buffer_set_caps (buf, GST_PAD_CAPS (basesrc->srcpad)); GST_BUFFER_TIMESTAMP (buf) = src->timestamp; - if (src->sync) { - if (src->clock) { -#if 0 - gst_element_wait (GST_ELEMENT (src), GST_BUFFER_TIMESTAMP (buf)); -#endif - } - } /* offset is the number of samples */ GST_BUFFER_OFFSET (buf) = src->offset; GST_BUFFER_OFFSET_END (buf) = src->offset + src->samples_per_buffer; @@ -409,17 +394,8 @@ gst_sinesrc_getrange (GstPad * pad, guint64 offset, i++; } -#if 0 - if (!GST_PAD_CAPS (src->srcpad)) { - if (gst_sinesrc_link (src->srcpad, - gst_pad_get_allowed_caps (src->srcpad)) <= 0) { - GST_ELEMENT_ERROR (src, CORE, NEGOTIATION, (NULL), (NULL)); - return NULL; - } - } -#endif - *buffer = buf; + return GST_FLOW_OK; } @@ -489,24 +465,15 @@ gst_sinesrc_get_property (GObject * object, guint prop_id, } } -static GstElementStateReturn -gst_sinesrc_change_state (GstElement * element) +static gboolean +gst_sinesrc_start (GstBaseSrc * basesrc) { - GstSineSrc *src = GST_SINESRC (element); + GstSineSrc *src = GST_SINESRC (basesrc); - switch (GST_STATE_TRANSITION (element)) { - case GST_STATE_PAUSED_TO_READY: - src->timestamp = G_GINT64_CONSTANT (0); - src->offset = G_GINT64_CONSTANT (0); - break; - default: - break; - } - - if (GST_ELEMENT_CLASS (parent_class)->change_state) - return GST_ELEMENT_CLASS (parent_class)->change_state (element); + src->timestamp = G_GINT64_CONSTANT (0); + src->offset = G_GINT64_CONSTANT (0); - return GST_STATE_SUCCESS; + return TRUE; } static void @@ -534,7 +501,7 @@ gst_sinesrc_update_freq (const GValue * value, gpointer data) src->freq = g_value_get_double (value); src->table_inc = src->table_size * src->freq / src->samplerate; - /*GST_DEBUG ("freq %f", src->freq); */ + GST_DEBUG ("freq %f", src->freq); } static inline void @@ -543,34 +510,6 @@ gst_sinesrc_update_table_inc (GstSineSrc * src) src->table_inc = src->table_size * src->freq / src->samplerate; } -#if 0 -static gboolean -gst_sinesrc_force_caps (GstSineSrc * src) -{ - static GstStaticCaps static_caps = GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) BYTE_ORDER, " - "signed = (boolean) true, " - "width = (int) 16, " - "depth = (int) 16, " - "rate = (int) [ 8000, 48000 ], " "channels = (int) 1"); - GstCaps *caps; - GstStructure *structure; - - if (!src->newcaps) - return TRUE; - - caps = gst_caps_copy (gst_static_caps_get (&static_caps)); - - structure = gst_caps_get_structure (caps, 0); - - gst_structure_set (structure, "rate", G_TYPE_INT, src->samplerate, NULL); - - src->newcaps = gst_pad_try_set_caps (src->srcpad, caps) < GST_PAD_LINK_OK; - - return !src->newcaps; -} -#endif - static gboolean plugin_init (GstPlugin * plugin) { diff --git a/gst/sine/gstsinesrc.h b/gst/sine/gstsinesrc.h index a98d830..a10a813 100644 --- a/gst/sine/gstsinesrc.h +++ b/gst/sine/gstsinesrc.h @@ -26,6 +26,7 @@ #include +#include G_BEGIN_DECLS @@ -48,7 +49,7 @@ typedef struct _GstSineSrc GstSineSrc; typedef struct _GstSineSrcClass GstSineSrcClass; struct _GstSineSrc { - GstElement element; + GstBaseSrc parent; /* pads */ GstPad *srcpad; @@ -85,7 +86,7 @@ struct _GstSineSrc { }; struct _GstSineSrcClass { - GstElementClass parent_class; + GstBaseSrcClass parent_class; }; GType gst_sinesrc_get_type(void); diff --git a/gst/tcp/gstmultifdsink.c b/gst/tcp/gstmultifdsink.c index 46bb677..5c70e3c 100644 --- a/gst/tcp/gstmultifdsink.c +++ b/gst/tcp/gstmultifdsink.c @@ -1138,7 +1138,7 @@ gst_multifdsink_recover_client (GstMultiFdSink * sink, GstTCPClient * client) * client->sending queue. * * After adding the buffer, we update all client positions in the queue. If - * a client moves of the soft max, we start the recovery procedure for this + * a client moves over the soft max, we start the recovery procedure for this * slow client. If it goes over the hard max, it is put into the slow list * and removed. * diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index 3732b82..735d8e7 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -1442,45 +1442,6 @@ gst_xvimagesink_show_frame (GstBaseSink * bsink, GstBuffer * buf) return GST_FLOW_OK; } -#if 0 -static GstFlowReturn -gst_xvimagesink_chain (GstPad * pad, GstBuffer * buffer) -{ - GstBuffer *buf = NULL; - GstXvImageSink *xvimagesink; - GstCaps *caps; - GstFlowReturn result; - - xvimagesink = GST_XVIMAGESINK (GST_PAD_PARENT (pad)); - - buf = GST_BUFFER (buffer); - - caps = gst_buffer_get_caps (buffer); - if (caps && caps != GST_PAD_CAPS (pad)) { - if (gst_xvimagesink_parse_caps (pad, caps)) { - gst_pad_set_caps (pad, caps); - } else { - GST_ELEMENT_ERROR (xvimagesink, CORE, NEGOTIATION, (NULL), - ("received unkown format")); - gst_element_abort_preroll (GST_ELEMENT (xvimagesink)); - gst_buffer_unref (buffer); - return GST_FLOW_NOT_NEGOTIATED; - } - } - if (!GST_PAD_CAPS (pad)) { - gst_buffer_unref (buffer); - return GST_FLOW_NOT_NEGOTIATED; - } - - gst_xvimagesink_show_frame (xvimagesink, buf); - - - gst_xvimagesink_handle_xevents (xvimagesink, pad); - - return result; -} -#endif - /* Buffer management */ static void -- 2.7.4