rm documents to github
[svn42.git] / dart-sounds / src / dart-sounds.c
index 25482a7..0d2fd9c 100644 (file)
@@ -89,6 +89,7 @@ struct play_file_param
   GCond* cond;
   GMutex* mutex;
   GAsyncQueue* queue;
+  const char* media_d;
 };
 
 static gpointer player(gpointer data)
@@ -100,6 +101,7 @@ static gpointer player(gpointer data)
   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");
@@ -117,13 +119,13 @@ static gpointer player(gpointer data)
 
     gst_element_set_state(pipeline, GST_STATE_READY);
    
-    g_print("playing '../media/%s.ogg'\n", name);
     char* path;
-    asprintf(&path, "../media/%s.ogg", name);
+    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);
@@ -132,7 +134,7 @@ static gpointer player(gpointer data)
   return NULL;
 }
 
-GstElement* init_pipeline(GMainLoop *loop, GAsyncQueue* queue, gint* sval)
+GstElement* init_pipeline(GMainLoop *loop, const char* media_d, GAsyncQueue* queue, gint* sval)
 {
   GCond* cond = g_cond_new();
   if(!cond) {
@@ -150,9 +152,10 @@ GstElement* init_pipeline(GMainLoop *loop, GAsyncQueue* queue, gint* sval)
   GstElement *demuxer = gst_element_factory_make("oggdemux", "demuxer");
   GstElement *decoder = gst_element_factory_make("vorbisdec", "decoder");
   GstElement *conv = gst_element_factory_make("audioconvert", "converter");
+  GstElement *filter = gst_element_factory_make("capsfilter", "filter");
   GstElement *sink = gst_element_factory_make("autoaudiosink", "sink");
 
-  if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) {
+  if (!pipeline || !source || !demuxer || !decoder || !conv || !filter || !sink) {
     g_printerr("One element could not be created. Exiting.\n");
     return NULL;
   }
@@ -170,9 +173,13 @@ GstElement* init_pipeline(GMainLoop *loop, GAsyncQueue* queue, gint* sval)
   gst_bus_add_watch(bus, bus_call, datab);
   gst_object_unref(bus);
 
-  gst_bin_add_many(GST_BIN(pipeline), source, demuxer, decoder, conv, sink, NULL);
+
+  GstCaps* caps = gst_caps_new_simple("audio/x-raw-int", "channels", G_TYPE_INT, 2, NULL);
+  g_object_set(G_OBJECT(filter), "caps", caps, NULL);
+
+  gst_bin_add_many(GST_BIN(pipeline), source, demuxer, decoder, conv, filter, sink, NULL);
   gst_element_link(source, demuxer);
-  gst_element_link_many(decoder, conv, sink, NULL);
+  gst_element_link_many(decoder, conv, filter, sink, NULL);
   g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), decoder);
 
   struct play_file_param* datap = malloc(sizeof(struct play_file_param));
@@ -183,6 +190,7 @@ GstElement* init_pipeline(GMainLoop *loop, GAsyncQueue* queue, gint* sval)
     datap->cond = cond;
     datap->mutex = mutex;
     datap->queue = queue;
+    datap->media_d = media_d;
     g_thread_create(player, datap, 0, NULL);
   } else {
     g_printerr("Memory Error\n");
@@ -239,7 +247,13 @@ static gboolean stdin_read(GIOChannel* src, GIOCondition cond, gpointer data)
 
 int main(int argc, char *argv[])
 {
-  gst_init(&argc, &argv);
+  if(argc < 2) {
+    fprintf(stderr, "Please specify the path to the media directory");
+    return 2;
+  }
+  char* media_d = argv[1];
+
+  gst_init(NULL, NULL);
 
   GMainLoop *loop = g_main_loop_new(NULL, FALSE);
   if(!loop) {
@@ -254,7 +268,7 @@ int main(int argc, char *argv[])
   }
 
   gint sval = 1;
-  GstElement *pipeline = init_pipeline(loop, queue, &sval);
+  GstElement *pipeline = init_pipeline(loop, media_d, queue, &sval);
   if(!pipeline) return 1;