All pastes #374867 Raw Edit

Stuff

public c v1 · immutable
#374867 ·published 2007-02-27 21:21 UTC
rendered paste body
#include <gst/gst.h>#include <stdio.h>#include <string.h>GstElement *pipeline, *source, *oggmuxer, *oggdecoder, *conv, *decoder, *sink, *oggencoder;static gboolean bus_call (GstBus *bus, GstMessage *msg,  gpointer data){  GMainLoop *loop = data;  switch (GST_MESSAGE_TYPE (msg)) {    case GST_MESSAGE_EOS:      g_print ("End-of-stream\n");      g_main_loop_quit (loop);      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 (GstElement *element,             GstPad     *pad,             gpointer    data){  GstPad *srcpad;  /* We can now link this pad with the audio decoder */  g_print ("Dynamic pad created, linking parser/decoder\n");  srcpad = gst_element_get_pad (decoder, "src%d");  gst_pad_link (srcpad, pad);  gst_object_unref (srcpad);}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)); /*   g_print ("Size: "  " / "  "\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;  /* GstQuery *query;  gboolean res; */  int create_err = 0, link_err = 0;  /* char mode_str[7], br_mode_str[5]; */  /* initialize GStreamer */  gst_init (&argc, &argv);  loop = g_main_loop_new (NULL, FALSE);  /* check input arguments */  if (argc != 3) {    g_print ("Usage: <MP3/Lame filename> <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");  decoder = gst_element_factory_make ("decodebin", "decoder");    oggencoder = gst_element_factory_make ("vorbisenc", "vorbis-encoder");  oggmuxer = gst_element_factory_make ("oggmux", "ogg-muxer");    if (!pipeline)  create_err = 1;  if (!source) create_err = 2;  if (!decoder) create_err = 3;  if (!conv)    create_err = 4;  if (!oggencoder)    create_err = 5;  if (!oggmuxer)    create_err = 6;  if (!sink)    create_err = 7;  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, oggencoder, oggmuxer, decoder, 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 (decoder, "pad-added", G_CALLBACK (new_pad), NULL);  if (!gst_element_link(decoder, conv)) {    link_err = 2;    g_warning("Failed to link elements (step #%d)\n", link_err); }  if (!gst_element_link(conv, oggencoder)) {    link_err = 3;    g_warning("Failed to link elements (step #%d)\n", link_err); }  if (!gst_element_link(oggencoder, oggmuxer)) {    link_err = 4;    g_warning("Failed to link elements (step #%d)\n", link_err); }  if (!gst_element_link(oggmuxer, sink)) {    link_err = 5;    g_warning("Failed to link elements (step #%d)\n", link_err); }    if (link_err != 0) {    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;}