2 * gstfs - gstreamer glue routines for transcoding
14 void (*add_data_cb
)(char *, size_t, void *);
18 void *send_pipe(void *data
)
20 struct pipe_params
*param
= (struct pipe_params
*) data
;
24 while ((sizeread
= read(param
->fd
, buf
, sizeof(buf
))) > 0)
26 param
->add_data_cb(buf
, sizeread
, param
->user_data
);
32 * Transcodes a file into a buffer, blocking until done.
34 int transcode(char *filename
, void (*add_data_cb
)(char *, size_t, void *),
37 GstElement
*pipeline
, *source
, *dest
;
40 char *pipeline_str
= "filesrc name=\"_source\" ! oggdemux ! "
41 "vorbisdec ! audioconvert ! lame bitrate=160 ! "
42 "fdsink name=\"_dest\" sync=false";
46 struct pipe_params thread_params
;
50 pipeline
= gst_parse_launch(pipeline_str
, &error
);
53 fprintf(stderr
, "Error parsing pipeline: %s\n", error
->message
);
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");
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
90 pthread_join(thread
, thread_status
);