static gboolean
backend_extract_async (GUPnPDLNAMetadataExtractor  *extractor,
                       const gchar                 *uri,
                       guint                        timeout,
                       GError                     **error)
{
        GError *gst_error = NULL;
        GstClockTime clock_time = GST_MSECOND * timeout;
        GstDiscoverer *discoverer = gst_discoverer_new (clock_time, &gst_error);

        if (gst_error) {
                g_propagate_error (error, gst_error);

                return FALSE;
        }

        g_signal_connect_swapped (discoverer,
                                  "discovered",
                                  G_CALLBACK (gupnp_dlna_discovered_cb),
                                  extractor);
        gst_discoverer_start (discoverer);

        return gst_discoverer_discover_uri_async (discoverer,
                                                  uri);
}
Beispiel #2
0
 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;
}
Beispiel #3
0
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;
}