/**
 * Test case to check for a specific memory leak bug. See https://bugzilla.gnome.org/show_bug.cgi?id=687493
 * gcc testcase_leak_vp8enc.c -Wall `pkg-config --cflags --libs gstreamer-1.0` -o testcase
 * G_SLICE=always_malloc GST_DEBUG=3 valgrind --leak-check=full --show-reachable=no ./testcase
 * 
 * You might want to change the num-buffer parameter. It's how many frames to grab and encode.
 * If you remove the deadline parameter, it is supposed to not leak anymore.
 */
#include <gst/gst.h>
  
int main(int argc, char *argv[]) {
  GstElement *pipeline;
  GstBus *bus;
  GstMessage *msg;
  
  /* Initialize GStreamer */
  gst_init (&argc, &argv);
  
  /* Build the pipeline */
  pipeline = gst_parse_launch ("ximagesrc endx=1919 endy=1079 use-damage=false show-pointer=true num-buffers=20 ! queue ! videorate ! video/x-raw,framerate=25/1 !  videoconvert !  vp8enc end-usage=vbr cpu-used=6 target-bitrate=80000000 threads=4 token-partitions=2 min-quantizer=10 max-quantizer=30 deadline=100000 ! queue name=before_mux ! webmmux name=mux ! queue ! filesink location=\"test-videorate.webm\"", NULL);
  
  /* Start playing */
  gst_element_set_state (pipeline, GST_STATE_PLAYING);
  
  /* Wait until error or EOS */
  bus = gst_element_get_bus (pipeline);
  msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
  
  /* Free resources */
  if (msg != NULL)
    gst_message_unref (msg);
  gst_object_unref (bus);
  gst_element_set_state (pipeline, GST_STATE_NULL);
  gst_object_unref (pipeline);

  /* Make Valgrind's output less noisy */
  gst_deinit();
  return 0;
}
