gstreamer/tools/gst-md5sum.c
Andy Wingo e040bb2dbe gst/gstelement.h (GstState): Renamed from GstElementState, changed to be a normal enum instead of flags.
Original commit message from CVS:
2005-09-02  Andy Wingo  <wingo@pobox.com>

* gst/gstelement.h (GstState): Renamed from GstElementState,
changed to be a normal enum instead of flags.
(GstStateChangeReturn): Renamed from GstElementStateReturn, names
munged to be GST_STATE_CHANGE_*.
(GST_STATE_CHANGE): Renamed from GST_STATE_TRANSITION, updated to
work with the new state representation.
(GstStateChange): New enumeration of possible state transitions.
Replaces GST_STATE_FOO_TO_BAR with GST_STATE_CHANGE_FOO_TO_BAR.
(GstElementClass::change_state): Pass the GstStateChange along as
an argument. Helps language bindings, so they don't have to use
tricky lock-needing macros like GST_STATE_CHANGE ().

* scripts/update-states (file): New script. Run it on a file to
update it for state naming and API changes. Updates files in
place.

* All files updated for the new API.
2005-09-02 15:42:00 +00:00

114 lines
2.7 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;
GstMessageType revent;
GstMessage *message = NULL;
bus = gst_element_get_bus (GST_ELEMENT (pipeline));
while (TRUE) {
revent = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);
message = gst_bus_pop (bus);
g_return_val_if_fail (message != NULL, TRUE);
switch (revent) {
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;
}