[gst-devel] Dynamic and requested pads with transcoding

Angelo Difino angelo.difino at gmail.com
Tue Sep 11 19:47:52 CEST 2007

Hi all,
I'm troubling with transcoding an audiovideo content. I really have
some problems with dynamic pada (created by mux) when used with
requested pada (created by demux)...
I've tried to create a complete chain with avi mux and avi demux.
The content simply holds raw audio and video.
IMP: if no demux is used (if audiotestsrc and videotestsrc are used),
no problems are reached!

If anybody know where i can find an example that show how to use
dynamic and requested pad together, i'll be really greatful :)

Best regards,

#include <gst/gst.h>

GstElement *pipeline;
GstElement *mux;

static void
cb_new_pad (GstElement *element,
       GstPad     *pad,
       gpointer    data)
 gchar *name;
 gboolean rit;
 GstPad *pad_to_request;

 name = gst_pad_get_name (pad);
 g_print ("A new pad %s was created\n", name);

 //set pause before link new pads
 gst_element_set_state (pipeline, GST_STATE_PAUSED);

 //DIRTY: request pad from mux that has "same name" of the demux
 pad_to_request = gst_element_get_request_pad (mux, name);
 name = gst_pad_get_name (pad_to_request);
 g_print ("A new pad %s was requested\n", name);
 rit = gst_pad_link (pad, pad_to_request);
 g_print ("Rit %d \n", rit);

 //set play after link new pads
 gst_element_set_state (pipeline, GST_STATE_PLAYING);

 g_free (name);

static void
event_loop (GstElement * pipe)
 GstBus *bus;
 GstMessage *message = NULL;

 bus = gst_element_get_bus (GST_ELEMENT (pipe));

 while (TRUE) {
   message = gst_bus_poll (bus, GST_MESSAGE_ANY, -1);

   g_assert (message != NULL);

   switch (message->type) {
     case GST_MESSAGE_EOS:
       gst_message_unref (message);
       GError *gerror;
       gchar *debug;

       gst_message_parse_error (message, &gerror, &debug);
       gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug);
       gst_message_unref (message);
       g_error_free (gerror);
       g_free (debug);
       gst_message_unref (message);

gint main (gint argc, gchar * argv[])
 GstElement *filesrc, *demux;
 GstElement *filesink;
 gboolean rit;

 gst_init (&argc, &argv);
 pipeline = gst_pipeline_new ("pipeline");

 //setting src file: AVI file
 filesrc= gst_element_factory_make ("filesrc", "filesrc");
 g_object_set (G_OBJECT (filesrc), "location", "orig.avi", NULL);

 //setting mux/demux
 demux= gst_element_factory_make ("avidemux", "avidemux");
 mux = gst_element_factory_make ("avimux", "avimux");

 //setting dest file: AVI file
 filesink= gst_element_factory_make ("filesink", "filesink");
 g_object_set (G_OBJECT (filesink), "location", "test.avi", NULL);

 //add to pipeline
 gst_bin_add_many (GST_BIN (pipeline), filesrc, demux, mux, filesink, NULL);

 rit=gst_element_link_pads (filesrc, "src", demux, "sink");
 g_print ("Rit %d \n", rit);
 rit=gst_element_link_pads (mux, "src", filesink, "sink");
 g_print ("Rit %d \n", rit);

 g_signal_connect (demux, "pad-added", G_CALLBACK (cb_new_pad), NULL);

 /* start playing */
 gst_element_set_state (pipeline, GST_STATE_PLAYING);

 /* Run event loop listening for bus messages until EOS or ERROR */
 event_loop (pipeline);

 /* stop the bin */
 gst_element_set_state (pipeline, GST_STATE_NULL);

 return (0);

More information about the gstreamer-devel mailing list