#include <stdio.h>
#include <gst/gst.h>
 
int main()
{
    printf("Application started.\n");
   
    gst_init(NULL,NULL);
 
    GMainLoop *loop = g_main_loop_new(NULL, FALSE);
 
    GstElement *pipeline = gst_pipeline_new("pipe");
    GstElement *source = gst_element_factory_make("audiotestsrc", "source");
    GstElement *decoder = gst_element_factory_make("decodebin", "decoder");;
    GstElement *sink = gst_element_factory_make("alsasink", "sink");
 
    if(!pipeline || !source || !decoder || !sink)
    {
        printf("Failed to create required elements\n");
        return -1;
    }
 
    gst_bin_add_many(GST_BIN(pipeline), source, decoder, sink, NULL);
 
    gst_element_link_many(source, decoder, sink, NULL);
 
    gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
 
    printf("Playing...\n");
    g_main_loop_run(loop);
 
    gst_element_set_state(pipeline, GST_STATE_NULL);
    gst_object_unref(GST_OBJECT(pipeline));
    g_main_loop_unref(loop);
 
    printf("Exiting.\n");
    return 0;
}