/*
 * gcc -Wall `pkg-config --cflags --libs gstreamer-1.0 gtk+-3.0 glib-2.0` playbin-leak.c
 * GOBJECT_DEBUG=instance-count GTK_DEBUG=interactive ./a.out
 */

#include <gst/gst.h>
#include <gtk/gtk.h>
#include <glib.h>

gboolean create_pipeline(gpointer user_data) {

  GstElement *playbin;
  static guint i = 0;

  i += 1;
  g_print ("%d\n", i);

  playbin = gst_element_factory_make ("playbin", "playbin");

  g_object_set (G_OBJECT (playbin), "uri", "file:///home/lazka/Desktop/bugs/playbin-leak/a.ogg", NULL);

  gst_element_set_state (playbin, GST_STATE_PLAYING);
  gst_element_get_state (playbin, NULL, NULL, GST_CLOCK_TIME_NONE);

  gst_element_set_state (playbin, GST_STATE_NULL);
  gst_element_get_state (playbin, NULL, NULL, GST_CLOCK_TIME_NONE);

  gst_object_unref (playbin);

  return G_SOURCE_CONTINUE;
}

int main(int argc, char *argv[]) {
  GtkWidget *window;
   
  gst_init (&argc, &argv);
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_show_all(window);

  g_idle_add(create_pipeline, NULL);

  gtk_main();

  return 0;
}
