rendered paste body/*********************** INCLUSIONE LIBRERIE ***********************/#include <gst/gst.h>#include <stdio.h>#include <string.h>/*********************************** DICHIARAZIONE VARIABILI GLOBALI ***********************************/GstElement *pipeline, *source, *oggmuxer, *oggdecoder, *conv, *mp3decoder, *sink, *oggencoder;static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data) { /* dichiarazione variabili locali */ GMainLoop *loop = data; switch (GST_MESSAGE_TYPE (msg)) { case GST_MESSAGE_EOS: { g_main_loop_quit (loop); g_print ("\rEnd-Of-Stream at: \n"); break; } case GST_MESSAGE_ERROR: { gchar *debug; GError *err; gst_message_parse_error (msg, &err, &debug); g_print ("Debug: %s\n", debug); g_free (debug); g_print ("Error: %s\n", err->message); g_error_free (err); g_main_loop_quit (loop); break; } default: break; } return TRUE;}static void new_pad_mux (GstElement *element, GstPad *pad, gpointer data) { GstPad *sinkpad; /* We can now link this pad with the audio decoder */ g_print ("Dynamic pad created, linking encoder/muxer\n"); sinkpad = gst_element_get_pad (oggmuxer, "sink"); gst_pad_link (pad, sinkpad); gst_object_unref (sinkpad);}static gboolean cb_print_position (GstElement *pipeline) { /* dichiarazione variabili locali */ GstFormat fmt = GST_FORMAT_TIME; gint64 pos, len; if (gst_element_query_position (pipeline, &fmt, &pos) && gst_element_query_duration (pipeline, &fmt, &len)) { g_print ("Time: %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\r", GST_TIME_ARGS (pos), GST_TIME_ARGS (len)); } /* call me again */ return TRUE;}int main (int argc, char *argv[]) { /* dichiarazione variabili locali */ GMainLoop *loop; GstBus *bus; int create_err = 0, link_err = 0; /* initialize GStreamer */ gst_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); /* check input arguments */ if (argc != 3) { g_print ("Usage: <MP3/Lame filenam> <Ogg/Vorbis filename>\n"); exit(EXIT_FAILURE); } /* create elements */ pipeline = gst_pipeline_new ("converter"); source = gst_element_factory_make ("filesrc", "file-input"); conv = gst_element_factory_make ("audioconvert", "converter-1"); sink = gst_element_factory_make ("filesink", "file-output"); mp3decoder = gst_element_factory_make ("mp3parse", "mp3-decoder"); oggencoder = gst_element_factory_make ("vorbisenc", "vorbis-encoder"); oggmuxer = gst_element_factory_make ("oggmux", "ogg-muxer"); if (!oggmuxer || !mp3decoder || !oggencoder || !pipeline || !source || !conv || !sink) { create_err = 1; } if (create_err != 0) { g_print ("One element could not be created. (%d4)\n", create_err); printf ("Application will be terminated.\n"); exit(EXIT_FAILURE); }/* set filename property on the file source. Also add a message * handler. */ g_object_set (G_OBJECT (source), "location", argv[1], NULL); g_object_set (G_OBJECT (sink), "location", argv[2], NULL); bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus); /* put all elements in a bin */ gst_bin_add_many (GST_BIN (pipeline), source, conv, sink, NULL); gst_bin_add_many (GST_BIN (pipeline), oggencoder, oggmuxer, mp3decoder, NULL); /* link together - note that we cannot link the parser and * decoder yet, becuse the parser uses dynamic pads. For that, * we set a pad-added signal handler. */ g_signal_connect (oggencoder, "pad-added", G_CALLBACK (new_pad_mux), NULL); if (!gst_element_link(oggencoder, oggmuxer)) { g_warning("Failed to link source/parser elements\n"); return -1; } else { if (!gst_element_link_many(mp3decoder, conv, oggencoder, oggmuxer, sink, NULL)) link_err = 4; } if (link_err != 0) { g_warning("Failed to link elements (step #%d)\n", link_err); printf ("Application will be terminated.\n"); exit(EXIT_FAILURE); } /* Now set to playing and iterate. */ g_print ("Setting to PLAYING\n"); gst_element_set_state (pipeline, GST_STATE_PLAYING); g_print ("Running\n"); g_timeout_add (200, (GSourceFunc) cb_print_position, pipeline); g_main_loop_run (loop); /* clean up nicely */ g_print ("Returned, stopping playback\n"); gst_element_set_state (pipeline, GST_STATE_NULL); g_print ("Deleting pipeline\n"); gst_object_unref (GST_OBJECT (pipeline)); return 0;}