2006-01-18 17:57:57 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* unit test for fakesink
|
|
|
|
*
|
|
|
|
* Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org>
|
2007-04-05 10:10:08 +00:00
|
|
|
* <2007> Wim Taymans <wim@fluendo.com>
|
2009-05-30 19:36:25 +00:00
|
|
|
* <2009> Tim-Philipp Müller <tim centricular net>
|
2006-01-18 17:57:57 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2009-05-30 19:36:25 +00:00
|
|
|
#include <gst/base/gstpushsrc.h>
|
2006-01-18 17:57:57 +00:00
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstPad *pad;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GThread *thread;
|
|
|
|
GstFlowReturn ret;
|
|
|
|
} ChainData;
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
chain_async_buffer (gpointer data)
|
|
|
|
{
|
|
|
|
ChainData *chain_data = (ChainData *) data;
|
|
|
|
|
|
|
|
chain_data->ret = gst_pad_chain (chain_data->pad, chain_data->buffer);
|
|
|
|
|
|
|
|
return chain_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ChainData *
|
|
|
|
chain_async (GstPad * pad, GstBuffer * buffer)
|
|
|
|
{
|
|
|
|
GThread *thread;
|
|
|
|
ChainData *chain_data;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
chain_data = g_new (ChainData, 1);
|
|
|
|
chain_data->pad = pad;
|
|
|
|
chain_data->buffer = buffer;
|
|
|
|
chain_data->ret = GST_FLOW_ERROR;
|
|
|
|
|
|
|
|
thread = g_thread_create (chain_async_buffer, chain_data, TRUE, &error);
|
|
|
|
if (error != NULL) {
|
|
|
|
g_warning ("could not create thread reason: %s", error->message);
|
|
|
|
g_free (chain_data);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
chain_data->thread = thread;
|
|
|
|
|
|
|
|
return chain_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
chain_async_return (ChainData * data)
|
|
|
|
{
|
|
|
|
GstFlowReturn ret;
|
|
|
|
|
|
|
|
g_thread_join (data->thread);
|
|
|
|
ret = data->ret;
|
|
|
|
g_free (data);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_clipping)
|
|
|
|
{
|
|
|
|
GstElement *sink;
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
/* create sink */
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
fail_if (sink == NULL);
|
|
|
|
|
2008-05-21 15:57:52 +00:00
|
|
|
sinkpad = gst_element_get_static_pad (sink, "sink");
|
2006-01-18 17:57:57 +00:00
|
|
|
fail_if (sinkpad == NULL);
|
|
|
|
|
|
|
|
/* make element ready to accept data */
|
|
|
|
ret = gst_element_set_state (sink, GST_STATE_PAUSED);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send segment */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstSegment segment;
|
2006-01-18 17:57:57 +00:00
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 1 * GST_SECOND;
|
|
|
|
segment.stop = 5 * GST_SECOND;
|
|
|
|
segment.time = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
event = gst_event_new_segment (&segment);
|
2006-01-18 17:57:57 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
2006-01-18 17:57:57 +00:00
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* new segment should not have finished preroll */
|
|
|
|
ret = gst_element_get_state (sink, NULL, NULL, 0);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send buffer that should be dropped */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 0;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_MSECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer to be dropped");
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
|
|
|
}
|
|
|
|
/* dropped buffer should not have finished preroll */
|
|
|
|
ret = gst_element_get_state (sink, NULL, NULL, 0);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send buffer that should be dropped */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 5 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_MSECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer to be dropped");
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
|
|
|
}
|
|
|
|
/* dropped buffer should not have finished preroll */
|
|
|
|
ret = gst_element_get_state (sink, NULL, NULL, 0);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send buffer that should block and finish preroll */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
ChainData *data;
|
|
|
|
GstState current, pending;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_MSECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer to finish preroll");
|
|
|
|
data = chain_async (sinkpad, buffer);
|
|
|
|
fail_if (data == NULL);
|
|
|
|
|
|
|
|
/* state should now eventually change to PAUSED */
|
|
|
|
ret = gst_element_get_state (sink, ¤t, &pending, GST_CLOCK_TIME_NONE);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
fail_unless (current == GST_STATE_PAUSED);
|
|
|
|
fail_unless (pending == GST_STATE_VOID_PENDING);
|
|
|
|
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
/* playing should render the buffer */
|
2006-01-18 17:57:57 +00:00
|
|
|
ret = gst_element_set_state (sink, GST_STATE_PLAYING);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
/* and we should get a success return value */
|
|
|
|
fret = chain_async_return (data);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send some buffer that will be dropped or clipped, this can
|
|
|
|
* only be observed in the debug log. */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 6 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_MSECOND;
|
|
|
|
|
|
|
|
/* should be dropped */
|
|
|
|
GST_DEBUG ("sending buffer to drop");
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 0 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 2 * GST_SECOND;
|
|
|
|
|
|
|
|
/* should be clipped */
|
|
|
|
GST_DEBUG ("sending buffer to clip");
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 4 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 2 * GST_SECOND;
|
|
|
|
|
|
|
|
/* should be clipped */
|
|
|
|
GST_DEBUG ("sending buffer to clip");
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
|
|
|
}
|
2006-01-28 00:59:37 +00:00
|
|
|
|
|
|
|
gst_element_set_state (sink, GST_STATE_NULL);
|
|
|
|
gst_element_get_state (sink, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (sink);
|
2006-01-18 17:57:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-02-03 11:52:49 +00:00
|
|
|
static gint num_preroll = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
preroll_count (GstElement * sink)
|
|
|
|
{
|
|
|
|
num_preroll++;
|
|
|
|
GST_DEBUG ("got preroll handoff %d", num_preroll);
|
|
|
|
}
|
|
|
|
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
GST_START_TEST (test_preroll_sync)
|
|
|
|
{
|
|
|
|
GstElement *pipeline, *sink;
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
/* create sink */
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
fail_if (pipeline == NULL);
|
|
|
|
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
fail_if (sink == NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
|
2009-02-03 11:52:49 +00:00
|
|
|
g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
|
|
|
|
g_signal_connect (sink, "preroll-handoff", G_CALLBACK (preroll_count), NULL);
|
|
|
|
|
|
|
|
fail_unless (num_preroll == 0);
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (pipeline), sink);
|
|
|
|
|
2008-05-21 15:57:52 +00:00
|
|
|
sinkpad = gst_element_get_static_pad (sink, "sink");
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
fail_if (sinkpad == NULL);
|
|
|
|
|
|
|
|
/* make pipeline and element ready to accept data */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send segment */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstSegment segment;
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 0 * GST_SECOND;
|
|
|
|
segment.stop = 102 * GST_SECOND;
|
|
|
|
segment.time = 0 * GST_SECOND;
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
event = gst_event_new_segment (&segment);
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send buffer that should block and finish preroll */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
ChainData *data;
|
|
|
|
GstState current, pending;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer to finish preroll");
|
|
|
|
data = chain_async (sinkpad, buffer);
|
|
|
|
fail_if (data == NULL);
|
|
|
|
|
|
|
|
/* state should now eventually change to PAUSED */
|
|
|
|
ret =
|
|
|
|
gst_element_get_state (pipeline, ¤t, &pending,
|
|
|
|
GST_CLOCK_TIME_NONE);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
fail_unless (current == GST_STATE_PAUSED);
|
|
|
|
fail_unless (pending == GST_STATE_VOID_PENDING);
|
|
|
|
|
2009-02-03 11:52:49 +00:00
|
|
|
fail_unless (num_preroll == 1);
|
|
|
|
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
/* playing should render the buffer */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
/* and we should get a success return value */
|
|
|
|
fret = chain_async_return (data);
|
|
|
|
fail_if (fret != GST_FLOW_OK);
|
2009-02-03 11:52:49 +00:00
|
|
|
|
|
|
|
/* now we are playing no new preroll was done */
|
|
|
|
fail_unless (num_preroll == 1);
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
/* far in the future to make sure we block */
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 100 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 100 * GST_SECOND;
|
|
|
|
data = chain_async (sinkpad, buffer);
|
|
|
|
fail_if (data == NULL);
|
|
|
|
|
|
|
|
g_usleep (1000000);
|
|
|
|
|
|
|
|
/* pause again. Since the buffer has a humongous timestamp we likely
|
|
|
|
* interrupt the clock_wait and we should preroll on this buffer again */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
ret =
|
|
|
|
gst_element_get_state (pipeline, ¤t, &pending,
|
|
|
|
GST_CLOCK_TIME_NONE);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
fail_unless (current == GST_STATE_PAUSED);
|
|
|
|
fail_unless (pending == GST_STATE_VOID_PENDING);
|
|
|
|
|
|
|
|
fail_unless (num_preroll == 2);
|
|
|
|
|
|
|
|
/* shutdown */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
/* should be wrong state now */
|
|
|
|
fret = chain_async_return (data);
|
|
|
|
fail_if (fret != GST_FLOW_WRONG_STATE);
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
}
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2007-04-05 10:10:08 +00:00
|
|
|
/* after EOS, we refuse everything */
|
|
|
|
GST_START_TEST (test_eos)
|
|
|
|
{
|
|
|
|
GstElement *pipeline, *sink;
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
GstMessage *message;
|
|
|
|
GstBus *bus;
|
|
|
|
|
|
|
|
/* create sink */
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
fail_if (pipeline == NULL);
|
|
|
|
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE_CAST (pipeline));
|
|
|
|
fail_if (bus == NULL);
|
|
|
|
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
fail_if (sink == NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (pipeline), sink);
|
|
|
|
|
2008-05-21 15:57:52 +00:00
|
|
|
sinkpad = gst_element_get_static_pad (sink, "sink");
|
2007-04-05 10:10:08 +00:00
|
|
|
fail_if (sinkpad == NULL);
|
|
|
|
|
|
|
|
/* make pipeline and element ready to accept data */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send EOS, this should work fine */
|
|
|
|
{
|
|
|
|
GstEvent *eos;
|
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending EOS");
|
|
|
|
eos = gst_event_new_eos ();
|
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, eos);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for preroll */
|
|
|
|
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
|
|
|
|
/* EOS should be on the bus at some point */
|
|
|
|
while (TRUE) {
|
|
|
|
GstMessageType type;
|
|
|
|
|
|
|
|
/* blocking wait for messages */
|
|
|
|
message = gst_bus_timed_pop (bus, GST_CLOCK_TIME_NONE);
|
|
|
|
type = GST_MESSAGE_TYPE (message);
|
|
|
|
gst_message_unref (message);
|
|
|
|
|
|
|
|
GST_DEBUG ("got message %s", gst_message_type_get_name (type));
|
|
|
|
|
|
|
|
if (type == GST_MESSAGE_EOS)
|
|
|
|
break;
|
|
|
|
}
|
2007-04-05 11:16:09 +00:00
|
|
|
gst_object_unref (bus);
|
2007-04-05 10:10:08 +00:00
|
|
|
|
|
|
|
/* send another EOS, this should fail */
|
|
|
|
{
|
|
|
|
GstEvent *eos;
|
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending second EOS");
|
|
|
|
eos = gst_event_new_eos ();
|
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, eos);
|
|
|
|
fail_if (eret == TRUE);
|
|
|
|
}
|
|
|
|
|
2011-05-30 11:40:04 +00:00
|
|
|
/* send segment, this should fail */
|
2007-04-05 10:10:08 +00:00
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstSegment segment;
|
2007-04-05 10:10:08 +00:00
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 0 * GST_SECOND;
|
|
|
|
segment.stop = 2 * GST_SECOND;
|
|
|
|
segment.time = 0 * GST_SECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2007-04-05 10:10:08 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
2011-05-30 11:40:04 +00:00
|
|
|
fail_if (eret == TRUE);
|
2007-04-05 10:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* send buffer that should fail after EOS */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
2011-10-10 09:33:51 +00:00
|
|
|
/* buffer after EOS is not EOS */
|
2007-04-05 10:10:08 +00:00
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
2011-10-10 09:33:51 +00:00
|
|
|
fail_unless (fret == GST_FLOW_EOS);
|
2007-04-05 10:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* flush, EOS state is flushed again. */
|
|
|
|
{
|
|
|
|
GstEvent *event;
|
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending FLUSH_START");
|
|
|
|
event = gst_event_new_flush_start ();
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_unless (eret == TRUE);
|
|
|
|
|
|
|
|
GST_DEBUG ("sending FLUSH_STOP");
|
2011-06-10 09:55:08 +00:00
|
|
|
event = gst_event_new_flush_stop (TRUE);
|
2007-04-05 10:10:08 +00:00
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_unless (eret == TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send segment, this should now work again */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstSegment segment;
|
2007-04-05 10:10:08 +00:00
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 0 * GST_SECOND;
|
|
|
|
segment.stop = 2 * GST_SECOND;
|
|
|
|
segment.time = 0 * GST_SECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2007-04-05 10:10:08 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
2007-04-05 10:10:08 +00:00
|
|
|
fail_unless (eret == TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send buffer that should work and block */
|
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
|
|
|
fail_unless (fret == GST_FLOW_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2007-04-05 11:16:09 +00:00
|
|
|
/* test EOS triggered by the element */
|
|
|
|
GST_START_TEST (test_eos2)
|
|
|
|
{
|
|
|
|
GstElement *pipeline, *sink;
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
|
|
|
|
/* create sink */
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
fail_if (pipeline == NULL);
|
|
|
|
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
fail_if (sink == NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "num-buffers", 1, NULL);
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (pipeline), sink);
|
|
|
|
|
2008-05-21 15:57:52 +00:00
|
|
|
sinkpad = gst_element_get_static_pad (sink, "sink");
|
2007-04-05 11:16:09 +00:00
|
|
|
fail_if (sinkpad == NULL);
|
|
|
|
|
|
|
|
/* make pipeline and element ready to accept data */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* send segment, this should work */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstEvent *event;
|
|
|
|
GstSegment segment;
|
2007-04-05 11:16:09 +00:00
|
|
|
gboolean eret;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 0 * GST_SECOND;
|
|
|
|
segment.stop = 2 * GST_SECOND;
|
|
|
|
segment.time = 0 * GST_SECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2007-04-05 11:16:09 +00:00
|
|
|
|
2011-05-13 16:07:24 +00:00
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
2007-04-05 11:16:09 +00:00
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:33:51 +00:00
|
|
|
/* send buffer that should return EOS */
|
2007-04-05 11:16:09 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
2011-10-10 09:33:51 +00:00
|
|
|
/* this buffer will generate EOS */
|
2007-04-05 11:16:09 +00:00
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
2011-10-10 09:33:51 +00:00
|
|
|
fail_unless (fret == GST_FLOW_EOS);
|
2007-04-05 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
2011-10-10 09:33:51 +00:00
|
|
|
/* send buffer that should return EOS */
|
2007-04-05 11:16:09 +00:00
|
|
|
{
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
|
|
|
fret = gst_pad_chain (sinkpad, buffer);
|
2011-10-10 09:33:51 +00:00
|
|
|
fail_unless (fret == GST_FLOW_EOS);
|
2007-04-05 11:16:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2008-08-19 16:47:07 +00:00
|
|
|
/* test position reporting before, during and after flush
|
|
|
|
* in PAUSED and PLAYING */
|
|
|
|
GST_START_TEST (test_position)
|
|
|
|
{
|
|
|
|
GstElement *pipeline, *sink;
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstStateChangeReturn ret;
|
|
|
|
gboolean qret;
|
|
|
|
gint64 qcur;
|
|
|
|
GstBuffer *buffer;
|
|
|
|
GstFlowReturn fret;
|
|
|
|
ChainData *data;
|
|
|
|
GstEvent *event;
|
|
|
|
gboolean eret;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* create sink */
|
|
|
|
pipeline = gst_pipeline_new ("pipeline");
|
|
|
|
fail_if (pipeline == NULL);
|
|
|
|
|
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
|
|
fail_if (sink == NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "num-buffers", 2, NULL);
|
|
|
|
|
|
|
|
gst_bin_add (GST_BIN (pipeline), sink);
|
|
|
|
|
|
|
|
sinkpad = gst_element_get_static_pad (sink, "sink");
|
|
|
|
fail_if (sinkpad == NULL);
|
|
|
|
|
|
|
|
/* do position query, this should fail, we have nothing received yet */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
/* do position query, this should fail, we have nothing received yet */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
/* make pipeline and element ready to accept data */
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* do position query, this should fail, we have nothing received yet */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
/* send segment, this should work */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstSegment segment;
|
|
|
|
|
2008-08-19 16:47:07 +00:00
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 1 * GST_SECOND;
|
|
|
|
segment.stop = 3 * GST_SECOND;
|
|
|
|
segment.time = 1 * GST_SECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME, do position query, this should succeed with the time value from the
|
|
|
|
* segment. */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur == 1 * GST_SECOND);
|
|
|
|
|
|
|
|
/* send buffer that we will flush out */
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
|
|
|
/* this buffer causes the sink to preroll */
|
|
|
|
data = chain_async (sinkpad, buffer);
|
|
|
|
fail_if (data == NULL);
|
|
|
|
|
|
|
|
/* wait for preroll */
|
|
|
|
ret = gst_element_get_state (pipeline, NULL, NULL, -1);
|
|
|
|
|
|
|
|
/* do position query, this should succeed with the time value from the
|
|
|
|
* segment. */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur == 1 * GST_SECOND);
|
|
|
|
|
|
|
|
/* start flushing, no timing is affected yet */
|
|
|
|
{
|
|
|
|
GST_DEBUG ("sending flush_start");
|
|
|
|
event = gst_event_new_flush_start ();
|
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* preroll buffer is flushed out */
|
|
|
|
fret = chain_async_return (data);
|
|
|
|
fail_unless (fret == GST_FLOW_WRONG_STATE);
|
|
|
|
|
|
|
|
/* do position query, this should succeed with the time value from the
|
|
|
|
* segment before the flush. */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur == 1 * GST_SECOND);
|
|
|
|
|
|
|
|
/* stop flushing, timing is affected now */
|
|
|
|
{
|
|
|
|
GST_DEBUG ("sending flush_stop");
|
2011-06-10 09:55:08 +00:00
|
|
|
event = gst_event_new_flush_stop (TRUE);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do position query, this should fail, the segment is flushed */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
/* send segment, this should work */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstSegment segment;
|
|
|
|
|
2008-08-19 16:47:07 +00:00
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 2 * GST_SECOND;
|
|
|
|
segment.stop = 4 * GST_SECOND;
|
|
|
|
segment.time = 1 * GST_SECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send buffer that should return OK */
|
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
|
|
|
/* this buffer causes the sink to preroll */
|
|
|
|
data = chain_async (sinkpad, buffer);
|
|
|
|
fail_if (data == NULL);
|
|
|
|
|
|
|
|
/* wait for preroll */
|
|
|
|
ret = gst_element_get_state (pipeline, NULL, NULL, -1);
|
|
|
|
|
|
|
|
/* do position query, this should succeed with the time value from the
|
|
|
|
* segment. */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur == 1 * GST_SECOND);
|
|
|
|
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
/* position now is increasing but never exceeds the boundaries of the segment */
|
|
|
|
for (i = 0; i < 5; i++) {
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
GST_DEBUG ("position %" GST_TIME_FORMAT, GST_TIME_ARGS (qcur));
|
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur >= 1 * GST_SECOND && qcur <= 3 * GST_SECOND);
|
|
|
|
g_usleep (1000 * 250);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* preroll buffer is rendered, we expect one more buffer after this one */
|
|
|
|
fret = chain_async_return (data);
|
|
|
|
fail_unless (fret == GST_FLOW_OK);
|
|
|
|
|
|
|
|
/* after rendering the position must be bigger then the stream_time of the
|
|
|
|
* buffer */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur >= 2 * GST_SECOND && qcur <= 3 * GST_SECOND);
|
|
|
|
|
|
|
|
/* start flushing in PLAYING */
|
|
|
|
{
|
|
|
|
GST_DEBUG ("sending flush_start");
|
|
|
|
event = gst_event_new_flush_start ();
|
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* this should now just report the stream time of the last buffer */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur == 2 * GST_SECOND);
|
|
|
|
|
|
|
|
{
|
|
|
|
GST_DEBUG ("sending flush_stop");
|
2011-06-10 09:55:08 +00:00
|
|
|
event = gst_event_new_flush_stop (TRUE);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* do position query, this should fail, the segment is flushed */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
/* send segment, this should work */
|
|
|
|
{
|
2011-05-13 16:07:24 +00:00
|
|
|
GstSegment segment;
|
|
|
|
|
2008-08-19 16:47:07 +00:00
|
|
|
GST_DEBUG ("sending segment");
|
2011-05-13 16:07:24 +00:00
|
|
|
gst_segment_init (&segment, GST_FORMAT_TIME);
|
|
|
|
segment.start = 2 * GST_SECOND;
|
|
|
|
segment.stop = 4 * GST_SECOND;
|
|
|
|
segment.time = 1 * GST_SECOND;
|
|
|
|
event = gst_event_new_segment (&segment);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
eret = gst_pad_send_event (sinkpad, event);
|
|
|
|
fail_if (eret == FALSE);
|
|
|
|
}
|
|
|
|
|
2011-10-10 09:33:51 +00:00
|
|
|
/* send buffer that should return EOS */
|
2008-08-19 16:47:07 +00:00
|
|
|
buffer = gst_buffer_new ();
|
|
|
|
GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND;
|
|
|
|
GST_BUFFER_DURATION (buffer) = 1 * GST_SECOND;
|
|
|
|
|
|
|
|
GST_DEBUG ("sending buffer");
|
|
|
|
|
|
|
|
/* this buffer causes the sink to preroll */
|
|
|
|
data = chain_async (sinkpad, buffer);
|
|
|
|
fail_if (data == NULL);
|
|
|
|
|
|
|
|
/* wait for preroll */
|
|
|
|
ret = gst_element_get_state (pipeline, NULL, NULL, -1);
|
|
|
|
|
|
|
|
/* preroll buffer is rendered, we expect no more buffer after this one */
|
|
|
|
fret = chain_async_return (data);
|
2011-10-10 09:33:51 +00:00
|
|
|
fail_unless (fret == GST_FLOW_EOS);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
/* do position query, this should succeed with the stream time of the buffer
|
|
|
|
* against the clock. Since the buffer is synced against the clock, the time
|
|
|
|
* should be at least the stream time of the buffer. */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur >= 2 * GST_SECOND && qcur <= 3 * GST_SECOND);
|
|
|
|
|
|
|
|
/* wait 2 more seconds, enough to test if the position was clipped correctly
|
|
|
|
* against the segment */
|
|
|
|
g_usleep (2 * G_USEC_PER_SEC);
|
|
|
|
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
|
|
|
fail_unless (qcur == 3 * GST_SECOND);
|
|
|
|
|
|
|
|
GST_DEBUG ("going to PAUSED");
|
|
|
|
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_ASYNC);
|
|
|
|
|
|
|
|
/* we report the time of the last start of the buffer. This is slightly
|
|
|
|
* incorrect, we should report the exact time when we paused but there is no
|
|
|
|
* record of that anywhere */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == TRUE);
|
2010-11-25 17:48:09 +00:00
|
|
|
fail_unless (qcur >= 4 * GST_SECOND);
|
2008-08-19 16:47:07 +00:00
|
|
|
|
|
|
|
ret = gst_element_set_state (pipeline, GST_STATE_READY);
|
|
|
|
fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
/* fails again because we are in the wrong state */
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
2011-07-26 23:28:50 +00:00
|
|
|
qret = gst_element_query_position (sink, GST_FORMAT_TIME, &qcur);
|
2008-08-19 16:47:07 +00:00
|
|
|
fail_unless (qret == FALSE);
|
|
|
|
|
|
|
|
gst_object_unref (sinkpad);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2009-05-30 19:36:25 +00:00
|
|
|
/* like fakesrc, but also pushes an OOB event after each buffer */
|
|
|
|
typedef GstPushSrc OOBSource;
|
|
|
|
typedef GstPushSrcClass OOBSourceClass;
|
|
|
|
|
2010-03-02 22:51:18 +00:00
|
|
|
GType oob_source_get_type (void);
|
2011-04-18 16:19:51 +00:00
|
|
|
G_DEFINE_TYPE (OOBSource, oob_source, GST_TYPE_PUSH_SRC);
|
2009-05-30 19:36:25 +00:00
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
oob_source_create (GstPushSrc * src, GstBuffer ** p_buf)
|
|
|
|
{
|
|
|
|
*p_buf = gst_buffer_new ();
|
|
|
|
|
|
|
|
gst_pad_push_event (GST_BASE_SRC_PAD (src),
|
|
|
|
gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, NULL));
|
|
|
|
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
oob_source_class_init (OOBSourceClass * klass)
|
|
|
|
{
|
2011-04-18 16:19:51 +00:00
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS_ANY);
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
2009-05-30 19:36:25 +00:00
|
|
|
GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass);
|
|
|
|
|
2011-04-18 16:19:51 +00:00
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_static_pad_template_get (&sinktemplate));
|
|
|
|
|
2009-05-30 19:36:25 +00:00
|
|
|
pushsrc_class->create = GST_DEBUG_FUNCPTR (oob_source_create);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-18 16:19:51 +00:00
|
|
|
oob_source_init (OOBSource * src)
|
2009-05-30 19:36:25 +00:00
|
|
|
{
|
|
|
|
/* nothing to do */
|
|
|
|
}
|
|
|
|
|
2009-10-22 10:33:01 +00:00
|
|
|
#define NOTIFY_RACE_NUM_PIPELINES 10
|
2009-05-30 19:36:25 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstElement *src;
|
|
|
|
GstElement *queue;
|
|
|
|
GstElement *sink;
|
|
|
|
GstElement *pipe;
|
|
|
|
} NotifyRacePipeline;
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_notify_race_setup_pipeline (NotifyRacePipeline * p)
|
|
|
|
{
|
2009-10-22 10:33:37 +00:00
|
|
|
GST_DEBUG ("Creating pipeline");
|
2009-05-30 19:36:25 +00:00
|
|
|
p->pipe = gst_pipeline_new ("pipeline");
|
|
|
|
p->src = g_object_new (oob_source_get_type (), NULL);
|
|
|
|
|
|
|
|
p->queue = gst_element_factory_make ("queue", NULL);
|
|
|
|
g_object_set (p->queue, "max-size-buffers", 2, NULL);
|
|
|
|
|
|
|
|
p->sink = gst_element_factory_make ("fakesink", NULL);
|
|
|
|
gst_bin_add (GST_BIN (p->pipe), p->src);
|
|
|
|
gst_bin_add (GST_BIN (p->pipe), p->queue);
|
|
|
|
gst_bin_add (GST_BIN (p->pipe), p->sink);
|
|
|
|
gst_element_link_many (p->src, p->queue, p->sink, NULL);
|
|
|
|
|
2009-10-22 10:33:37 +00:00
|
|
|
GST_DEBUG ("Setting pipeline to PLAYING");
|
2009-05-30 19:36:25 +00:00
|
|
|
fail_unless_equals_int (gst_element_set_state (p->pipe, GST_STATE_PLAYING),
|
|
|
|
GST_STATE_CHANGE_ASYNC);
|
2009-10-22 10:33:37 +00:00
|
|
|
GST_DEBUG ("Getting state");
|
2009-05-30 19:36:25 +00:00
|
|
|
fail_unless_equals_int (gst_element_get_state (p->pipe, NULL, NULL, -1),
|
|
|
|
GST_STATE_CHANGE_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
test_notify_race_cleanup_pipeline (NotifyRacePipeline * p)
|
|
|
|
{
|
|
|
|
gst_element_set_state (p->pipe, GST_STATE_NULL);
|
|
|
|
gst_object_unref (p->pipe);
|
|
|
|
memset (p, 0, sizeof (NotifyRacePipeline));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we create N pipelines to make sure the notify race isn't per-class, but
|
|
|
|
* only per instance */
|
|
|
|
GST_START_TEST (test_notify_race)
|
|
|
|
{
|
|
|
|
NotifyRacePipeline pipelines[NOTIFY_RACE_NUM_PIPELINES];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (pipelines); ++i) {
|
2009-10-22 10:33:37 +00:00
|
|
|
GST_DEBUG ("Starting up pipeline %d", i);
|
2009-05-30 19:36:25 +00:00
|
|
|
test_notify_race_setup_pipeline (&pipelines[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_usleep (2 * G_USEC_PER_SEC);
|
|
|
|
|
|
|
|
for (i = 0; i < G_N_ELEMENTS (pipelines); ++i) {
|
2009-10-22 10:33:37 +00:00
|
|
|
GST_DEBUG ("Cleaning up pipeline %d", i);
|
2009-05-30 19:36:25 +00:00
|
|
|
test_notify_race_cleanup_pipeline (&pipelines[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2008-02-29 13:59:24 +00:00
|
|
|
static Suite *
|
2006-01-18 17:57:57 +00:00
|
|
|
fakesink_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("fakesink");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
2008-08-19 16:47:07 +00:00
|
|
|
tcase_set_timeout (tc_chain, 20);
|
|
|
|
|
2006-01-18 17:57:57 +00:00
|
|
|
suite_add_tcase (s, tc_chain);
|
|
|
|
tcase_add_test (tc_chain, test_clipping);
|
docs/design/part-element-sink.txt: Updated document.
Original commit message from CVS:
* docs/design/part-element-sink.txt:
Updated document.
* libs/gst/base/gstbasesink.c: (gst_base_sink_init),
(gst_base_sink_finalize), (gst_base_sink_preroll_queue_flush),
(gst_base_sink_configure_segment), (gst_base_sink_commit_state),
(gst_base_sink_get_sync_times), (gst_base_sink_wait_clock),
(gst_base_sink_do_sync), (gst_base_sink_render_object),
(gst_base_sink_preroll_object),
(gst_base_sink_queue_object_unlocked),
(gst_base_sink_queue_object), (gst_base_sink_event),
(gst_base_sink_chain_unlocked), (gst_base_sink_chain),
(gst_base_sink_loop), (gst_base_sink_activate_pull),
(gst_base_sink_get_position), (gst_base_sink_change_state):
* libs/gst/base/gstbasesink.h:
Totally refactored matching the design doc.
Use two segments, one to clip incomming buffers and another to
perform sync.
Handle queueing correctly, bypass the queue when playing.
Make EOS cancelable.
Handle errors correctly when operating in pull based mode.
* tests/check/elements/fakesink.c: (GST_START_TEST),
(fakesink_suite):
Added new check for sinks.
2006-02-02 12:07:48 +00:00
|
|
|
tcase_add_test (tc_chain, test_preroll_sync);
|
2007-04-05 10:10:08 +00:00
|
|
|
tcase_add_test (tc_chain, test_eos);
|
2007-04-05 11:16:09 +00:00
|
|
|
tcase_add_test (tc_chain, test_eos2);
|
2008-08-19 16:47:07 +00:00
|
|
|
tcase_add_test (tc_chain, test_position);
|
2009-05-30 19:36:25 +00:00
|
|
|
tcase_add_test (tc_chain, test_notify_race);
|
2006-01-18 17:57:57 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2006-07-01 20:56:56 +00:00
|
|
|
GST_CHECK_MAIN (fakesink);
|