Remove dead code
[gstfs.git] / xcode.c
blobe36bac7c6bb07f8cd65d0c9f590537dce525ce16
1 /*
2 * gstfs - gstreamer glue routines for transcoding
3 */
5 #include <gst/gst.h>
6 #include <glib.h>
7 #include <unistd.h>
8 #include <sys/wait.h>
9 #include <pthread.h>
11 struct pipe_params
13 int fd;
14 void (*add_data_cb)(char *, size_t, void *);
15 void *user_data;
18 void *send_pipe(void *data)
20 struct pipe_params *param = (struct pipe_params *) data;
21 char buf[PIPE_BUF];
22 size_t sizeread;
24 while ((sizeread = read(param->fd, buf, sizeof(buf))) > 0)
26 param->add_data_cb(buf, sizeread, param->user_data);
28 return NULL;
32 * Transcodes a file into a buffer, blocking until done.
34 int transcode(char *filename, void (*add_data_cb)(char *, size_t, void *),
35 void *user_data)
37 GstElement *pipeline, *source, *dest;
38 GError *error = NULL;
39 GstBus *bus;
40 char *pipeline_str = "filesrc name=\"_source\" ! oggdemux ! "
41 "vorbisdec ! audioconvert ! lame bitrate=160 ! "
42 "fdsink name=\"_dest\" sync=false";
44 int pipefds[2];
46 struct pipe_params thread_params;
47 pthread_t thread;
48 void *thread_status;
50 pipeline = gst_parse_launch(pipeline_str, &error);
51 if (error)
53 fprintf(stderr, "Error parsing pipeline: %s\n", error->message);
54 return -1;
57 source = gst_bin_get_by_name(GST_BIN(pipeline), "_source");
58 dest = gst_bin_get_by_name(GST_BIN(pipeline), "_dest");
60 if (!pipeline || !source || !dest)
62 fprintf(stderr, "Could not initialize pipeline\n");
63 return -2;
66 if (pipe(pipefds))
68 perror("gstfs");
69 return -1;
72 thread_params.fd = pipefds[0];
73 thread_params.add_data_cb = add_data_cb;
74 thread_params.user_data = user_data;
76 pthread_create(&thread, NULL, send_pipe, (void *) &thread_params);
78 g_object_set(G_OBJECT(source), "location", filename, NULL);
79 g_object_set(G_OBJECT(dest), "fd", pipefds[1], NULL);
81 bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
82 gst_bus_add_signal_watch(bus);
83 gst_element_set_state(pipeline, GST_STATE_PLAYING);
84 GstMessage *message = gst_bus_poll(bus, GST_MESSAGE_EOS |
85 GST_MESSAGE_ERROR, -1);
86 gst_message_unref(message);
88 // close read-side so pipe will terminate
89 close(pipefds[1]);
90 pthread_join(thread, thread_status);
92 return 0;