2 * gstfs - gstreamer glue routines for transcoding
14 void (*add_data_cb
)(char *, size_t, void *);
20 static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data)
24 done_cb_t callback = (done_cb_t) data;
26 switch (GST_MESSAGE_TYPE (msg)) {
29 g_main_loop_quit (loop);
32 case GST_MESSAGE_ERROR:
33 gst_message_parse_error (msg, &error, &debug);
36 g_printerr ("Error: %s\n", error->message);
39 g_main_loop_quit (loop);
49 void close_pipe(void *data
)
52 printf("close pipe! %d\n", fd
);
56 void *send_pipe(void *data
)
58 struct pipe_params
*param
= (struct pipe_params
*) data
;
62 while ((sizeread
= read(param
->fd
, buf
, sizeof(buf
))) > 0)
64 param
->add_data_cb(buf
, sizeread
, param
->user_data
);
70 * Transcodes a file into a buffer, blocking until done.
72 int transcode(char *filename
, void (*add_data_cb
)(char *, size_t, void *),
75 GstElement
*pipeline
, *source
, *dest
;
78 char *pipeline_str
= "filesrc name=\"_source\" ! oggdemux ! vorbisdec ! audioconvert ! wavenc ! fdsink name=\"_dest\" sync=false";
81 struct pipe_params thread_params
;
85 pipeline
= gst_parse_launch(pipeline_str
, &error
);
88 fprintf(stderr
, "Error parsing pipeline: %s\n", error
->message
);
92 source
= gst_bin_get_by_name(GST_BIN(pipeline
), "_source");
93 dest
= gst_bin_get_by_name(GST_BIN(pipeline
), "_dest");
95 if (!pipeline
|| !source
|| !dest
)
97 fprintf(stderr
, "Could not initialize pipeline\n");
107 thread_params
.fd
= pipefds
[0];
108 thread_params
.add_data_cb
= add_data_cb
;
109 thread_params
.user_data
= user_data
;
111 pthread_create(&thread
, NULL
, send_pipe
, (void *) &thread_params
);
113 g_object_set(G_OBJECT(source
), "location", filename
, NULL
);
114 g_object_set(G_OBJECT(dest
), "fd", pipefds
[1], NULL
);
116 bus
= gst_pipeline_get_bus(GST_PIPELINE(pipeline
));
117 gst_bus_add_signal_watch(bus
);
118 gst_element_set_state(pipeline
, GST_STATE_PLAYING
);
119 GstMessage
*message
= gst_bus_poll(bus
, GST_MESSAGE_EOS
|
120 GST_MESSAGE_ERROR
, -1);
121 gst_message_unref(message
);
123 // close read-side so pipe will terminate
125 pthread_join(&thread
, thread_status
);