mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-27 04:01:08 +00:00
1c1af875d4
Original commit message from CVS: * check/gst/gstbin.c: (pop_messages), (GST_START_TEST): * check/gst/gstbus.c: (message_func_eos), (message_func_app), (send_messages), (GST_START_TEST), (gstbus_suite): * check/gst/gstpipeline.c: (GST_START_TEST): * check/pipelines/cleanup.c: (run_pipeline): * check/pipelines/simple_launch_lines.c: (run_pipeline), (GST_START_TEST): * gst/gstbus.c: (gst_bus_have_pending), (gst_bus_source_prepare), (gst_bus_source_check), (gst_bus_source_dispatch), (gst_bus_create_watch), (gst_bus_add_watch_full), (gst_bus_add_watch), (poll_func), (poll_timeout), (gst_bus_poll): * gst/gstbus.h: * tools/gst-launch.c: (event_loop): * tools/gst-md5sum.c: (event_loop): GstBusHandler -> GstBusFunc, return value has the same meaning as any other GSource (FALSE == remove source). _add_watch() and _add_watch_full() now take a MessageType mask to only handle specific types of messages. _poll() returns the GstMessage instead of the message type to avoid race conditions. _have_pending() takes a MessageType mask now too. Added testsuite for multiple bus watches. Fix testsuites and applications for new bus API.
112 lines
2.6 KiB
C
112 lines
2.6 KiB
C
#ifdef HAVE_CONFIG_H
|
|
# include "config.h"
|
|
#endif
|
|
|
|
#include <string.h>
|
|
#include <stdlib.h>
|
|
#include <gst/gst.h>
|
|
#include <locale.h>
|
|
|
|
/* blocking */
|
|
static gboolean
|
|
event_loop (GstElement * pipeline)
|
|
{
|
|
GstBus *bus;
|
|
GstMessage *message = NULL;
|
|
|
|
bus = gst_element_get_bus (GST_ELEMENT (pipeline));
|
|
|
|
while (TRUE) {
|
|
message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
|
|
|
|
g_return_val_if_fail (message != NULL, TRUE);
|
|
|
|
switch (GST_MESSAGE_TYPE (message)) {
|
|
case GST_MESSAGE_EOS:
|
|
gst_message_unref (message);
|
|
return FALSE;
|
|
case GST_MESSAGE_WARNING:
|
|
case GST_MESSAGE_ERROR:{
|
|
GError *gerror;
|
|
gchar *debug;
|
|
|
|
gst_message_parse_error (message, &gerror, &debug);
|
|
gst_message_unref (message);
|
|
gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
|
|
g_error_free (gerror);
|
|
g_free (debug);
|
|
return TRUE;
|
|
}
|
|
default:
|
|
gst_message_unref (message);
|
|
break;
|
|
}
|
|
}
|
|
|
|
g_assert_not_reached ();
|
|
return TRUE;
|
|
}
|
|
|
|
int
|
|
main (int argc, char *argv[])
|
|
{
|
|
GstElement *pipeline = NULL;
|
|
GError *error = NULL;
|
|
GstElement *md5sink;
|
|
gchar **argvn;
|
|
gchar *md5string = g_malloc0 (33);
|
|
|
|
free (malloc (8)); /* -lefence */
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
argvn = g_new0 (char *, argc);
|
|
memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
|
|
pipeline = (GstElement *) gst_parse_launchv ((const gchar **) argvn, &error);
|
|
if (!pipeline) {
|
|
if (error) {
|
|
g_warning ("pipeline could not be constructed: %s\n", error->message);
|
|
g_error_free (error);
|
|
} else
|
|
g_warning ("pipeline could not be constructed\n");
|
|
return 1;
|
|
}
|
|
|
|
md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0");
|
|
if (md5sink == NULL) {
|
|
g_print ("ERROR: pipeline has no element named md5sink0.\n");
|
|
g_print ("Did you forget to put an md5sink in the pipeline?\n");
|
|
return 1;
|
|
}
|
|
|
|
if (!pipeline) {
|
|
if (error) {
|
|
g_warning ("pipeline could not be constructed: %s\n", error->message);
|
|
g_error_free (error);
|
|
} else
|
|
g_warning ("pipeline could not be constructed\n");
|
|
return 1;
|
|
}
|
|
|
|
if (gst_element_set_state (pipeline,
|
|
GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS) {
|
|
g_warning ("pipeline doesn't want to play\n");
|
|
return 1;
|
|
}
|
|
|
|
event_loop (pipeline);
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
/* print out md5sink here */
|
|
md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0");
|
|
g_assert (md5sink);
|
|
g_object_get (G_OBJECT (md5sink), "md5", &md5string, NULL);
|
|
printf ("%s\n", md5string);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
return 0;
|
|
}
|