mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-24 08:08:22 +00:00
tests: add example app for stream-status
Add an example application that adjusts the thread priority of a task using the stream-status messages.
This commit is contained in:
parent
2d8a22c1da
commit
5eccc07856
5 changed files with 145 additions and 0 deletions
|
@ -681,6 +681,7 @@ tests/examples/launch/Makefile
|
|||
tests/examples/manual/Makefile
|
||||
tests/examples/metadata/Makefile
|
||||
tests/examples/queue/Makefile
|
||||
tests/examples/streams/Makefile
|
||||
tests/examples/typefind/Makefile
|
||||
tests/examples/xml/Makefile
|
||||
tools/Makefile
|
||||
|
|
|
@ -22,6 +22,7 @@ always_dirs = \
|
|||
helloworld \
|
||||
manual \
|
||||
metadata \
|
||||
streams \
|
||||
queue
|
||||
|
||||
#appreader
|
||||
|
|
5
tests/examples/streams/.gitignore
vendored
Normal file
5
tests/examples/streams/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
stream-status
|
||||
*.bb
|
||||
*.bbg
|
||||
*.da
|
||||
stream-status-stream-status.gcno
|
4
tests/examples/streams/Makefile.am
Normal file
4
tests/examples/streams/Makefile.am
Normal file
|
@ -0,0 +1,4 @@
|
|||
noinst_PROGRAMS = stream-status
|
||||
|
||||
stream_status_LDADD = $(GST_OBJ_LIBS)
|
||||
stream_status_CFLAGS = $(GST_OBJ_CFLAGS)
|
134
tests/examples/streams/stream-status.c
Normal file
134
tests/examples/streams/stream-status.c
Normal file
|
@ -0,0 +1,134 @@
|
|||
#include <stdlib.h>
|
||||
#include <gst/gst.h>
|
||||
|
||||
static void
|
||||
event_loop (GstBus * bus, GstElement * pipe)
|
||||
{
|
||||
GstMessage *message = NULL;
|
||||
|
||||
while (TRUE) {
|
||||
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
||||
|
||||
g_assert (message != NULL);
|
||||
|
||||
switch (message->type) {
|
||||
case GST_MESSAGE_EOS:
|
||||
g_message ("received EOS");
|
||||
gst_message_unref (message);
|
||||
return;
|
||||
case GST_MESSAGE_WARNING:
|
||||
case GST_MESSAGE_ERROR:{
|
||||
GError *gerror;
|
||||
gchar *debug;
|
||||
|
||||
gst_message_parse_error (message, &gerror, &debug);
|
||||
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
||||
gst_message_unref (message);
|
||||
g_error_free (gerror);
|
||||
g_free (debug);
|
||||
return;
|
||||
}
|
||||
default:
|
||||
gst_message_unref (message);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GstBusSyncReply
|
||||
sync_bus_handler (GstBus * bus, GstMessage * message, GstElement * bin)
|
||||
{
|
||||
switch (GST_MESSAGE_TYPE (message)) {
|
||||
case GST_MESSAGE_STREAM_STATUS:
|
||||
{
|
||||
GstStreamStatusType type;
|
||||
GstElement *owner;
|
||||
const GValue *val;
|
||||
gchar *path;
|
||||
|
||||
g_message ("received STREAM_STATUS");
|
||||
gst_message_parse_stream_status (message, &type, &owner);
|
||||
|
||||
val = gst_message_get_stream_status_object (message);
|
||||
|
||||
g_message ("type: %d", type);
|
||||
path = gst_object_get_path_string (GST_MESSAGE_SRC (message));
|
||||
g_message ("source: %s", path);
|
||||
g_free (path);
|
||||
path = gst_object_get_path_string (GST_OBJECT (owner));
|
||||
g_message ("owner: %s", path);
|
||||
g_free (path);
|
||||
g_message ("object: type %s, value %p", G_VALUE_TYPE_NAME (val),
|
||||
g_value_get_object (val));
|
||||
|
||||
switch (type) {
|
||||
case GST_STREAM_STATUS_TYPE_ENTER:
|
||||
{
|
||||
/* see if we know how to deal with this object */
|
||||
if (G_VALUE_TYPE (val) == GST_TYPE_TASK) {
|
||||
GstTask *task;
|
||||
|
||||
task = g_value_get_object (val);
|
||||
|
||||
g_message ("raising task priority");
|
||||
gst_task_set_priority (task, G_THREAD_PRIORITY_HIGH);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case GST_STREAM_STATUS_TYPE_LEAVE:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* pass all messages on the async queue */
|
||||
return GST_BUS_PASS;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
GstElement *bin, *fakesrc, *fakesink;
|
||||
GstBus *bus;
|
||||
|
||||
gst_init (&argc, &argv);
|
||||
|
||||
/* create a new bin to hold the elements */
|
||||
bin = gst_pipeline_new ("pipeline");
|
||||
g_assert (bin);
|
||||
|
||||
/* create a source */
|
||||
fakesrc = gst_element_factory_make ("fakesrc", "fakesrc");
|
||||
g_assert (fakesrc);
|
||||
g_object_set (fakesrc, "num-buffers", 50, NULL);
|
||||
|
||||
/* and a sink */
|
||||
fakesink = gst_element_factory_make ("fakesink", "fakesink");
|
||||
g_assert (fakesink);
|
||||
|
||||
/* add objects to the main pipeline */
|
||||
gst_bin_add_many (GST_BIN (bin), fakesrc, fakesink, NULL);
|
||||
|
||||
/* link the elements */
|
||||
gst_element_link (fakesrc, fakesink);
|
||||
|
||||
/* start playing */
|
||||
gst_element_set_state (bin, GST_STATE_PLAYING);
|
||||
|
||||
/* get the bus, we need to install a sync handler */
|
||||
bus = gst_pipeline_get_bus (GST_PIPELINE (bin));
|
||||
gst_bus_set_sync_handler (bus, (GstBusSyncHandler) sync_bus_handler, bin);
|
||||
|
||||
/* Run event loop listening for bus messages until EOS or ERROR */
|
||||
event_loop (bus, bin);
|
||||
|
||||
/* stop the bin */
|
||||
gst_element_set_state (bin, GST_STATE_NULL);
|
||||
gst_object_unref (bus);
|
||||
|
||||
exit (0);
|
||||
}
|
Loading…
Reference in a new issue