mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 02:31:03 +00:00
5905655ead
Original commit message from CVS: * gst/gstthread.c: (gst_thread_dispose), (gst_thread_sync), (gst_thread_change_state), (gst_thread_child_state_change), (gst_thread_main_loop): * gst/gstthread.h: * testsuite/threads/Makefile.am: * testsuite/threads/queue.c: * testsuite/threads/thread.c: (construct_pipeline), (change_state), (main): * testsuite/threads/threadc.c: (construct_pipeline): * testsuite/threads/threadd.c: (main): * testsuite/threads/threade.c: (main): * testsuite/threads/threadf.c: Reworked the GstThread implementation, make more operations threadsafe and more reliable. Moved testcases from the failing to the working list.
89 lines
2.2 KiB
C
89 lines
2.2 KiB
C
#include <gst/gst.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
/*
|
|
* queue test code
|
|
* starts a fakesrc num_buffers=50 ! { queue ! fakesink } thread
|
|
* by first setting the output thread to play, then the whole pipeline
|
|
*/
|
|
|
|
static volatile gint handoff_count = 0;
|
|
|
|
/* handoff callback */
|
|
static void
|
|
handoff (GstElement * element, gpointer data)
|
|
{
|
|
++handoff_count;
|
|
g_print ("handoff (%d) ", handoff_count);
|
|
}
|
|
|
|
static void
|
|
construct_pipeline (GstElement * pipeline, GstElement * thread)
|
|
{
|
|
GstElement *src, *sink, *queue;
|
|
|
|
src = gst_element_factory_make ("fakesrc", NULL);
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
|
queue = gst_element_factory_make ("queue", NULL);
|
|
|
|
gst_bin_add_many (GST_BIN (thread), queue, sink, NULL);
|
|
gst_bin_add_many (GST_BIN (pipeline), src, thread, NULL);
|
|
|
|
gst_element_link_many (src, queue, sink, NULL);
|
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 50, NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, NULL);
|
|
g_signal_connect (G_OBJECT (sink), "handoff", G_CALLBACK (handoff), NULL);
|
|
}
|
|
|
|
void
|
|
change_state (GstElement * element, GstBuffer * buf, GstElement * pipeline)
|
|
{
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
}
|
|
|
|
int
|
|
main (gint argc, gchar * argv[])
|
|
{
|
|
GstElement *pipeline;
|
|
GstElement *thread = NULL;
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
pipeline = gst_thread_new ("main_pipeline");
|
|
thread = gst_element_factory_make ("thread", NULL);
|
|
construct_pipeline (pipeline, thread);
|
|
|
|
g_print ("First run: to show the pipeline works\n");
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
|
g_print ("SLEEPING 1 sec\n");
|
|
sleep (1);
|
|
|
|
g_print ("Pipeline done. Resetting to NULL.\n");
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
if (handoff_count == 0) {
|
|
g_print ("ERROR: no buffers have passed\n");
|
|
return -1;
|
|
}
|
|
|
|
handoff_count = 0;
|
|
|
|
g_print
|
|
("Second run: setting consumer thread to playing, then complete pipeline\n");
|
|
gst_element_set_state (thread, GST_STATE_PLAYING);
|
|
g_print ("SLEEPING 1 sec\n");
|
|
sleep (1);
|
|
gst_element_set_state (pipeline, gst_element_get_state (pipeline));
|
|
g_print ("SLEEPING 2 sec\n");
|
|
sleep (2);
|
|
|
|
if (handoff_count == 0) {
|
|
g_print ("ERROR: no buffers have passed\n");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|