/* cc -o disco discoverer.c $(pkg-config --libs --cflags gstreamer-pbutils-1.0
 * gio-2.0 */
#include <gio/gio.h>
#include <gst/pbutils/pbutils.h>
#include <stdio.h>

char *uri;
gint32 i = 0;

void next(void);

void on_discovered (GstDiscoverer *disco, GstDiscovererInfo *info, GError *error, gpointer user_data)
{
    if (error != NULL) {
        g_error ("Error: %s", error->message);
    }

    printf ("Iteration: %d\n", i++);
    g_object_unref (disco);

    next ();
}

void next ()
{
    GstDiscoverer *disco;

    disco = gst_discoverer_new ((GstClockTime) 10 * GST_SECOND, NULL);
    gst_discoverer_start (disco);
    g_signal_connect (disco, "discovered", G_CALLBACK (on_discovered), NULL);
    gst_discoverer_discover_uri_async (disco, uri);
}

int main (int argc, char *argv[]) {
    GstDiscoverer *disco;
    GFile *file;
    GFile *file2;
    GTimer *timer;
    GstDiscovererInfo *info;
    GstSample *sample;
    GMainLoop *loop;

    g_type_init ();
    gst_init (&argc, &argv);

    file = g_file_new_for_commandline_arg (argv[1]);
    uri = g_file_get_uri (file);

    next();
    loop = g_main_loop_new (NULL, FALSE);
    g_main_loop_run (loop);

    return 0;
}
