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 *pipeline_str
, char *filename
,
35 void (*add_data_cb
)(char *, size_t, void *), void *user_data
)
37 GstElement
*pipeline
, *source
, *dest
;
42 struct pipe_params thread_params
;
46 pipeline
= gst_parse_launch(pipeline_str
, &error
);
49 fprintf(stderr
, "Error parsing pipeline: %s\n", error
->message
);
53 source
= gst_bin_get_by_name(GST_BIN(pipeline
), "_source");
54 dest
= gst_bin_get_by_name(GST_BIN(pipeline
), "_dest");
56 if (!pipeline
|| !source
|| !dest
)
58 fprintf(stderr
, "Could not initialize pipeline\n");
68 thread_params
.fd
= pipefds
[0];
69 thread_params
.add_data_cb
= add_data_cb
;
70 thread_params
.user_data
= user_data
;
72 pthread_create(&thread
, NULL
, send_pipe
, (void *) &thread_params
);
74 g_object_set(G_OBJECT(source
), "location", filename
, NULL
);
75 g_object_set(G_OBJECT(dest
), "fd", pipefds
[1], NULL
);
77 bus
= gst_pipeline_get_bus(GST_PIPELINE(pipeline
));
78 gst_bus_add_signal_watch(bus
);
79 gst_element_set_state(pipeline
, GST_STATE_PLAYING
);
80 GstMessage
*message
= gst_bus_poll(bus
, GST_MESSAGE_EOS
|
81 GST_MESSAGE_ERROR
, -1);
82 gst_message_unref(message
);
84 // close read-side so pipe will terminate
86 pthread_join(thread
, thread_status
);