190 lines
4.4 KiB
C
190 lines
4.4 KiB
C
#include "ecdb.h"
|
|
|
|
/* A lot of the code below is from brasero, so thanks to them for it */
|
|
char *ecdb_audio_output_create(Ecdb_Source *src);
|
|
static gboolean cb_buscall(GstBus *bus, GstMessage *msg, gpointer data);
|
|
static void cb_newpad(GstElement *decodebin, GstPad *pad,
|
|
gboolean last, gpointer data);
|
|
|
|
int
|
|
ecdb_audio_project_setup(Ecdb_Burn_Project *proj)
|
|
{
|
|
int argc;
|
|
char **argv;
|
|
|
|
GMainLoop *loop;
|
|
|
|
ecore_app_args_get(&argc, &argv);
|
|
gst_init(&argc, &argv);
|
|
loop = g_main_loop_new(NULL, FALSE);
|
|
return TRUE;
|
|
}
|
|
|
|
static gboolean
|
|
cb_buscall(GstBus *bus, GstMessage *msg, gpointer data)
|
|
{
|
|
if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_EOS)
|
|
printf("End of stream\n");
|
|
|
|
else if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ERROR)
|
|
{
|
|
gchar *debug;
|
|
GError *err;
|
|
|
|
gst_message_parse_error(msg, &err, &debug);
|
|
g_free(debug);
|
|
g_print("Error: %s\n", err->message);
|
|
g_error_free(err);
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
static void
|
|
cb_newpad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer data)
|
|
{
|
|
GstPad *sink;
|
|
GstCaps *caps;
|
|
GstStructure *structure;
|
|
GstElement *convert;
|
|
|
|
convert = (GstElement *) data;
|
|
|
|
sink = gst_element_get_pad (convert, "sink");
|
|
if (GST_PAD_IS_LINKED (sink))
|
|
return;
|
|
|
|
/* make sure we only have audio */
|
|
caps = gst_pad_get_caps (pad);
|
|
if (!caps)
|
|
return;
|
|
|
|
structure = gst_caps_get_structure (caps, 0);
|
|
if (structure
|
|
&& g_strrstr (gst_structure_get_name (structure), "audio"))
|
|
gst_pad_link (pad, sink);
|
|
|
|
gst_object_unref (sink);
|
|
gst_caps_unref (caps);
|
|
}
|
|
|
|
int
|
|
ecdb_audio_project_handle(Ecdb_Source *src, char *error)
|
|
{
|
|
GstElement *decode;
|
|
GstElement *source;
|
|
GstBus *bus = NULL;
|
|
GstCaps *filtercaps;
|
|
GstElement *pipeline;
|
|
GstElement *sink = NULL;
|
|
GstElement *filter = NULL;
|
|
GstElement *convert = NULL;
|
|
GstElement *resample = NULL;
|
|
char *output;
|
|
|
|
pipeline = gst_pipeline_new(NULL);
|
|
bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
|
|
gst_bus_add_watch(bus, cb_buscall, NULL);
|
|
gst_object_unref(bus);
|
|
|
|
/* source */
|
|
source = gst_element_make_from_uri(GST_URI_SRC, src->dst, NULL);
|
|
if (!source)
|
|
{
|
|
error = "Source couldn't be created!";
|
|
gst_object_unref(GST_OBJECT(pipeline));
|
|
return FALSE;
|
|
}
|
|
gst_bin_add(GST_BIN(pipeline), source);
|
|
g_object_set(source, "typefind", FALSE, NULL);
|
|
|
|
/* Output */
|
|
sink = gst_element_factory_make("filesink", NULL);
|
|
output = ecdb_audio_output_create(src);
|
|
g_object_set(sink, "location", output, NULL);
|
|
src->dst = output;
|
|
if (!sink)
|
|
{
|
|
error = "Sink couldn't be created!";
|
|
gst_object_unref(GST_OBJECT(pipeline));
|
|
FREE(output);
|
|
return FALSE;
|
|
}
|
|
gst_bin_add(GST_BIN(pipeline), sink);
|
|
g_object_set(sink, "sync", FALSE, NULL);
|
|
|
|
/* Audioconvert */
|
|
convert = gst_element_factory_make("audioconvert", NULL);
|
|
if (!convert)
|
|
{
|
|
error = "Audioconvert couldn't be created!";
|
|
gst_object_unref(GST_OBJECT(pipeline));
|
|
FREE(output);
|
|
return FALSE;
|
|
}
|
|
|
|
/* resample */
|
|
resample = gst_element_factory_make("audioresample", NULL);
|
|
if (!resample)
|
|
{
|
|
error = "Audioresampler couldn't be create!";
|
|
gst_object_unref(GST_OBJECT(pipeline));
|
|
FREE(output);
|
|
return FALSE;
|
|
}
|
|
gst_bin_add(GST_BIN(pipeline), resample);
|
|
|
|
/* Filter */
|
|
filter = gst_element_factory_make("capsfilter", NULL);
|
|
if (!filter)
|
|
{
|
|
error = "Filter couldn't be created!";
|
|
gst_object_unref(GST_OBJECT(pipeline));
|
|
FREE(output);
|
|
return FALSE;
|
|
}
|
|
gst_bin_add(GST_BIN(pipeline), filter);
|
|
filtercaps = gst_caps_new_full(gst_structure_new("audio/x-raw-int",
|
|
"channels", G_TYPE_INT, 2,
|
|
"width", G_TYPE_INT, 16,
|
|
"depth", G_TYPE_INT, 16,
|
|
"endianness", G_TYPE_INT, 1234,
|
|
"rate", G_TYPE_INT, 44100,
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
|
NULL), NULL);
|
|
g_object_set(GST_OBJECT(filter), "caps", filtercaps, NULL);
|
|
gst_caps_unref(filtercaps);
|
|
|
|
/* decode */
|
|
decode = gst_element_factory_make("decodebin", NULL);
|
|
if (!decode)
|
|
{
|
|
error = "Decode couldn't be created!";
|
|
gst_object_unref(GST_OBJECT(pipeline));
|
|
FREE(output);
|
|
return FALSE;
|
|
}
|
|
gst_bin_add(GST_BIN(pipeline), decode);
|
|
gst_element_link_many(source, decode, NULL);
|
|
g_signal_connect(G_OBJECT(decode), "new-decoded-pad",
|
|
G_CALLBACK(cb_newpad), resample);
|
|
gst_element_link_many(resample, convert, filter, sink, NULL);
|
|
|
|
/* End stuff */
|
|
gst_element_set_state(pipeline, GST_STATE_PLAYING);
|
|
FREE(output);
|
|
return TRUE;
|
|
}
|
|
|
|
char *
|
|
ecdb_audio_output_create(Ecdb_Source *src)
|
|
{
|
|
char ret[PATH_MAX];
|
|
|
|
snprintf(ret, PATH_MAX, "/tmp/ecdb/%s.wav",
|
|
ecore_file_file_get
|
|
(ecore_file_strip_ext(src->dst)));
|
|
return strdup(ret);
|
|
}
|
|
|