From: <sl...@ke...> - 2008-05-13 10:59:58
|
CVS Root: /cvs/gstreamer Module: gst-plugins-base Changes by: slomo Date: Tue May 13 2008 11:00:03 UTC Log message: Patch by: Sjoerd Simons <sjoerd at luon dot net> * tests/check/elements/audioresample.c: (live_switch_alloc_only_48000), (live_switch_get_sink_caps), (live_switch_push), (GST_START_TEST): Add unit test for the latest basetransform negotiation changes. See bug #526768. Modified files: . : ChangeLog tests/check/elements: audioresample.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/ChangeLog.diff?r1=1.3922&r2=1.3923 http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins-base/tests/check/elements/audioresample.c.diff?r1=1.14&r2=1.15 ====Begin Diffs==== Index: ChangeLog =================================================================== RCS file: /cvs/gstreamer/gst-plugins-base/ChangeLog,v retrieving revision 1.3922 retrieving revision 1.3923 diff -u -d -r1.3922 -r1.3923 --- ChangeLog 13 May 2008 09:14:43 -0000 1.3922 +++ ChangeLog 13 May 2008 10:59:47 -0000 1.3923 @@ -1,5 +1,15 @@ 2008-05-13 Sebastian Dröge <sl...@ci...> + Patch by: Sjoerd Simons <sjoerd at luon dot net> + + * tests/check/elements/audioresample.c: + (live_switch_alloc_only_48000), (live_switch_get_sink_caps), + (live_switch_push), (GST_START_TEST): + Add unit test for the latest basetransform negotiation changes. + See bug #526768. +2008-05-13 Sebastian Dröge <sl...@ci...> * gst/ffmpegcolorspace/imgconvert.c: (nv12_to_nv21): Fix nv12<->nv21 conversion if stride is larger than width. Index: audioresample.c RCS file: /cvs/gstreamer/gst-plugins-base/tests/check/elements/audioresample.c,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- audioresample.c 8 May 2008 06:20:42 -0000 1.14 +++ audioresample.c 13 May 2008 10:59:49 -0000 1.15 @@ -417,55 +417,67 @@ GST_END_TEST; static GstFlowReturn -alloc_only_48000 (GstPad * pad, guint64 offset, guint size, GstCaps * caps, - GstBuffer ** buf) +live_switch_alloc_only_48000 (GstPad * pad, guint64 offset, + guint size, GstCaps * caps, GstBuffer ** buf) { GstStructure *structure; gint rate; + gint channels; + GstCaps *desired; structure = gst_caps_get_structure (caps, 0); fail_unless (gst_structure_get_int (structure, "rate", &rate)); + fail_unless (gst_structure_get_int (structure, "channels", &channels)); - if (rate != 48000) + if (rate < 48000) return GST_FLOW_NOT_NEGOTIATED; - *buf = NULL; + desired = gst_caps_copy (caps); + gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL); + *buf = gst_buffer_new_and_alloc (channels * 48000); + gst_buffer_set_caps (*buf, desired); + gst_caps_unref (desired); return GST_FLOW_OK; } -GST_START_TEST (test_live_switch) +static GstCaps * +live_switch_get_sink_caps (GstPad * pad) - GstElement *audioresample; - GstEvent *newseg; - GstBuffer *inbuffer; - GstCaps *caps; - GstCaps *newcaps; - GList *l; + GstCaps *result; - audioresample = setup_audioresample (1, 48000, 48000); + result = gst_caps_copy (GST_PAD_CAPS (pad)); - /* Let the sinkpad act like something that can only handle things of - * rate 48000 and can only allocate buffers for that rate */ - gst_pad_set_bufferalloc_function (mysinkpad, alloc_only_48000); + gst_caps_set_simple (result, + "rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL); - caps = gst_pad_get_negotiated_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); + return result; +} - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); +static void +live_switch_push (int rate, GstCaps * caps) +{ + GstBuffer *inbuffer; + GList *l; - newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); + gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL); fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad, - GST_BUFFER_OFFSET_NONE, 48000 * 4, caps, &inbuffer) == GST_FLOW_OK); + GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK); + /* When the basetransform hits the non-configured case it always + * returns a buffer with exactly the same caps as we requested so the actual + * renegotiation (if needed) will be done in the _chain*/ + fail_unless (inbuffer != NULL); + fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer))); memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); GST_BUFFER_DURATION (inbuffer) = GST_SECOND; GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_OFFSET (inbuffer) = 0; - gst_buffer_set_caps (inbuffer, caps); /* pushing gives away my reference ... */ fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); @@ -473,33 +485,55 @@ /* ... but it ends up being collected on the global buffer list */ fail_unless_equals_int (g_list_length (buffers), 1); - /* Prepare a new buffer, but now with different caps */ - fail_unless ((newcaps = - gst_caps_make_writable (gst_caps_ref (caps))) != NULL); - gst_caps_set_simple (newcaps, "rate", G_TYPE_INT, 1234, NULL); - - fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad, - GST_BUFFER_OFFSET_NONE, 1234 * 4, newcaps, &inbuffer) == GST_FLOW_OK); - memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - gst_buffer_set_caps (inbuffer, newcaps); - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - fail_unless_equals_int (g_list_length (buffers), 2); - cleanup_audioresample (audioresample); for (l = buffers; l; l = l->next) { GstBuffer *buffer = GST_BUFFER (l->data); gst_buffer_unref (buffer); } g_list_free (buffers); buffers = NULL; +GST_START_TEST (test_live_switch) + GstElement *audioresample; + GstEvent *newseg; + GstCaps *caps; + audioresample = setup_audioresample (4, 48000, 48000); + /* Let the sinkpad act like something that can only handle things of + * rate 48000- and can only allocate buffers for that rate, but if someone + * tries to get a buffer with a rate higher then 48000 tries to renegotiate + * */ + gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000); + gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps); + caps = gst_pad_get_negotiated_caps (mysrcpad); + fail_unless (gst_caps_is_fixed (caps)); + fail_unless (gst_element_set_state (audioresample, + GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, + "could not set to playing"); + newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); + fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); + /* downstream can provide the requested rate, a buffer alloc will be passed + * on */ + live_switch_push (48000, caps); + /* Downstream can never accept this rate, buffer alloc isn't passed on */ + live_switch_push (40000, caps); + /* Downstream can provide the requested rate but will re-negotiate */ + live_switch_push (50000, caps); + cleanup_audioresample (audioresample); gst_caps_unref (caps); - gst_caps_unref (newcaps); GST_END_TEST static Suite * |