+struct play_file_param
+{
+ GstElement *pipeline;
+ GstElement *source;
+ gint* sval;
+ GCond* cond;
+ GMutex* mutex;
+ GAsyncQueue* queue;
+ const char* media_d;
+};
+
+static gpointer player(gpointer data)
+{
+ struct play_file_param *p = (struct play_file_param*)data;
+ GstElement* pipeline = p->pipeline;
+ GstElement* source = p->source;
+ gint* sval = p->sval;
+ GCond* cond = p->cond;
+ GMutex* mutex = p->mutex;
+ GAsyncQueue* queue = p->queue;
+ const char* media_d = p->media_d;
+ free(p);
+
+ g_printf("Player thread started\n");
+
+ for(;;) {
+ g_mutex_lock(mutex);
+ while((*sval) < 1)
+ g_cond_wait(cond, mutex);
+ *sval = 0;
+ g_mutex_unlock(mutex);
+
+ char* name = (char*)g_async_queue_pop(queue);
+ if(!name)
+ return NULL;
+
+ gst_element_set_state(pipeline, GST_STATE_READY);
+
+ char* path;
+ asprintf(&path, "%s/%s.ogg", media_d, name);
+ free(name);
+ if(!path)
+ return NULL;
+
+ g_print("playing '%s'\n", path);
+ g_object_set(G_OBJECT(source), "location", path, NULL);
+ free(path);
+ gst_element_set_state(pipeline, GST_STATE_PLAYING);
+ }
+
+ return NULL;
+}
+
+GstElement* init_pipeline(GMainLoop *loop, const char* media_d, GAsyncQueue* queue, gint* sval)