extern "C" void C_Func_MediaInfo (char * filename) { CustomData data; GError *err = NULL; gchar *uri = filename; /* if a URI was provided, use it instead of the default one */ // if (argc > 1) { // uri = argv[1]; // } /* Initialize cumstom data structure */ memset (&data, 0, sizeof (data)); /* Initialize GStreamer */ // gst_init (NULL,NULL); g_print ("Discovering '%s'\n", uri); /* Instantiate the Discoverer */ data.discoverer = gst_discoverer_new (5 * GST_SECOND, &err); if (!data.discoverer) { g_print ("Error creating discoverer instance: %s\n", err->message); g_clear_error (&err); //return -1; } else { /* Connect to the interesting signals */ g_signal_connect (data.discoverer, "discovered", G_CALLBACK (on_discovered_cb), &data); g_signal_connect (data.discoverer, "finished", G_CALLBACK (on_finished_cb), &data); /* Start the discoverer process (nothing to do yet) */ gst_discoverer_start (data.discoverer); /* Add a request to process asynchronously the URI passed through the command line */ if (!gst_discoverer_discover_uri_async (data.discoverer, uri)) { g_print ("Failed to start discovering URI '%s'\n", uri); g_object_unref (data.discoverer); } else { /* Create a GLib Main Loop and set it to run, so we can wait for the signals */ data.loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (data.loop); } /* Stop the discoverer process */ gst_discoverer_stop (data.discoverer); /* Free resources */ g_object_unref (data.discoverer); g_main_loop_unref (data.loop); } // return 0; }
static void gst_discoverer_dispose (GObject * obj) { GstDiscoverer *dc = (GstDiscoverer *) obj; GST_DEBUG_OBJECT (dc, "Disposing"); discoverer_reset (dc); if (G_LIKELY (dc->priv->pipeline)) { /* Workaround for bug #118536 */ DISCONNECT_SIGNAL (dc->priv->uridecodebin, dc->priv->pad_added_id); DISCONNECT_SIGNAL (dc->priv->uridecodebin, dc->priv->pad_remove_id); DISCONNECT_SIGNAL (dc->priv->uridecodebin, dc->priv->element_added_id); DISCONNECT_SIGNAL (dc->priv->bus, dc->priv->bus_cb_id); /* pipeline was set to NULL in _reset */ gst_object_unref (dc->priv->pipeline); gst_object_unref (dc->priv->bus); dc->priv->pipeline = NULL; dc->priv->uridecodebin = NULL; dc->priv->bus = NULL; } gst_discoverer_stop (dc); if (dc->priv->lock) { g_mutex_free (dc->priv->lock); dc->priv->lock = NULL; } if (dc->priv->seeking_query) { gst_query_unref (dc->priv->seeking_query); dc->priv->seeking_query = NULL; } G_OBJECT_CLASS (gst_discoverer_parent_class)->dispose (obj); }
int main (int argc, char **argv) { GError *err = NULL; GstDiscoverer *dc; gint timeout = 10; GOptionEntry options[] = { {"async", 'a', 0, G_OPTION_ARG_NONE, &async, "Run asynchronously", NULL}, {"silent", 's', 0, G_OPTION_ARG_NONE, &silent, "Don't output the information structure", NULL}, {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "Specify timeout (in seconds, default 10)", "T"}, /* {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek, */ /* "Seek on elements instead of pads", NULL}, */ {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose properties", NULL}, {NULL} }; GOptionContext *ctx; if (!g_thread_supported ()) g_thread_init (NULL); ctx = g_option_context_new ("- discover files synchronously with GstDiscoverer"); g_option_context_add_main_entries (ctx, options, NULL); g_option_context_add_group (ctx, gst_init_get_option_group ()); if (!g_option_context_parse (ctx, &argc, &argv, &err)) { g_print ("Error initializing: %s\n", err->message); exit (1); } g_option_context_free (ctx); if (argc < 2) { g_print ("usage: %s <uris>\n", argv[0]); exit (-1); } dc = gst_discoverer_new (timeout * GST_SECOND, &err); if (G_UNLIKELY (dc == NULL)) { g_print ("Error initializing: %s\n", err->message); exit (1); } if (async == FALSE) { gint i; for (i = 1; i < argc; i++) process_file (dc, argv[i]); } else { PrivStruct *ps = g_new0 (PrivStruct, 1); GMainLoop *ml = g_main_loop_new (NULL, FALSE); ps->dc = dc; ps->argc = argc; ps->argv = argv; /* adding uris will be started when the mainloop runs */ g_idle_add ((GSourceFunc) _run_async, ps); /* connect signals */ g_signal_connect (dc, "discovered", G_CALLBACK (_new_discovered_uri), NULL); g_signal_connect (dc, "finished", G_CALLBACK (_discoverer_finished), ml); gst_discoverer_start (dc); /* run mainloop */ g_main_loop_run (ml); gst_discoverer_stop (dc); g_free (ps); g_main_loop_unref (ml); } g_object_unref (dc); return 0; }