/* XXX Change these macros in order to use the test case.  XXX */

// This should be the path to an Ogg Vorbis file somewhere on your system.
#define OGG_FILE_NAME "/home/ian/music/archive/0007.ogg"
// This should be the set of properties required to connect to your
// shoutcast server.
#define ICECAST_PARAMS      \
    "ip", "127.0.0.1",      \
    "port", 8000,           \
    "password", "trustno1", \
    "mount", "/stream"

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

static void gst_element_set_state_sync(GstElement * element,
                                       GstState state) {
    GstStateChangeReturn result =
        gst_element_set_state(element, state);

    switch (result) {
    case GST_STATE_CHANGE_FAILURE:
        g_assert_not_reached();
        /* NOTREACHED */
    case GST_STATE_CHANGE_SUCCESS:
    case GST_STATE_CHANGE_NO_PREROLL:
        return;
    case GST_STATE_CHANGE_ASYNC:
        result = gst_element_get_state(element, NULL, NULL,
                                       10 * 10000000000ULL);
        g_assert(result == GST_STATE_CHANGE_SUCCESS ||
                 result == GST_STATE_CHANGE_NO_PREROLL);
        return;
    }

    g_assert_not_reached();
}

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

    GstElement * gstPipeline = gst_pipeline_new(NULL);
    GstElement * gstFileSrc = gst_element_factory_make("filesrc", NULL);
    g_object_set(G_OBJECT(gstFileSrc),
                 "location", OGG_FILE_NAME, NULL);
    GstElement * gstIceCast = gst_element_factory_make("shout2send", NULL);
    g_object_set(G_OBJECT(gstIceCast), ICECAST_PARAMS, NULL);

    gst_bin_add_many(GST_BIN(gstPipeline), gstFileSrc, gstIceCast,
                     NULL);
    gst_element_link_many(gstFileSrc, gstIceCast, NULL);

    gst_element_set_state_sync(gstPipeline, GST_STATE_PLAYING);
    fprintf(stderr, "Started playing.\n");
    sleep(15);

    gst_element_seek(gstPipeline, 1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
                     GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_END, 0);

    fprintf(stderr, "Seeked backwards.\n");
    sleep(15);

    return 0;
}
