#include #include struct paraminfo { gchar *name; GObject *obj; GParamSpecInt *pspec; }; static struct paraminfo* new_paraminfo (GstElement *obj, gchar *name) { struct paraminfo *info = g_new (struct paraminfo, 1); info->name = name; info->obj = G_OBJECT (obj); info->pspec = G_PARAM_SPEC_INT ( g_object_class_find_property (G_OBJECT_GET_CLASS (obj), name)); return info; } static void free_paraminfo (gpointer ptr) { g_free (ptr); } struct appdata { GList *paramlist; GRand *rand; gint min,max; }; static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: g_print ("End of stream\n"); g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR: { gchar *debug; GError *error; gst_message_parse_error (msg, &error, &debug); g_free (debug); g_printerr ("Error: %s\n", error->message); g_error_free (error); g_main_loop_quit (loop); break; } default: break; } return TRUE; } static gboolean source_tick (struct appdata *data) { int randparam = g_rand_int_range (data->rand, 0, g_list_length (data->paramlist)); struct paraminfo *info = g_list_nth_data (data->paramlist, randparam); int randval = g_rand_int_range (data->rand, -10000, 10000); //info->pspec->minimum, info->pspec->maximum); g_print ("setting '%s' to '%d'\n", info->name, randval); g_object_set (info->obj, info->name, randval, NULL); return TRUE; } int main (int argc, char *argv[]) { GMainLoop *loop; GstElement *pipeline, *box; GstBus *bus; guint bus_watch_id; GSource *source; struct appdata data = { .paramlist = NULL, .rand = g_rand_new (), }; /* Initialisation */ gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); /* Create gstreamer elements */ pipeline = gst_parse_launch ("videotestsrc ! video/x-raw,width=1024,height=1024 ! " "videobox name=box ! fakesink", NULL); box = gst_bin_get_by_name (GST_BIN (pipeline), "box"); data.paramlist = g_list_append (data.paramlist, new_paraminfo (box, "left")); data.paramlist = g_list_append (data.paramlist, new_paraminfo (box, "right")); data.paramlist = g_list_append (data.paramlist, new_paraminfo (box, "top")); data.paramlist = g_list_append (data.paramlist, new_paraminfo (box, "bottom")); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); gst_element_set_state (pipeline, GST_STATE_PLAYING); g_print ("Running...\n"); source = g_timeout_source_new (1); g_source_set_callback (source, (GSourceFunc)source_tick, &data, NULL); g_source_attach (source, NULL); g_source_unref (source); g_main_loop_run (loop); g_print ("Returned, stopping playback\n"); gst_element_set_state (pipeline, GST_STATE_NULL); g_print ("Deleting pipeline\n"); gst_object_unref (GST_OBJECT (pipeline)); g_source_remove (bus_watch_id); g_main_loop_unref (loop); g_list_free_full (data.paramlist, free_paraminfo); g_rand_free (data.rand); return 0; }