[gst-devel] problem linking audio elements dynamically

danielkun at iremo.com danielkun at iremo.com
Tue Mar 25 04:35:02 CET 2008


I am still new to Gstreamer but I'm quite pleased to have managed to
build my first MPEG video player.

I'm having problems with the dynamic audio linking though. I added a
callback to my demuxer where I would like to load the appropriate audio
decoder based on the type. (MPEG1L2 / AC-3)
It works perfectly if I link my elements before I start the pipeline,
but when I try to link my audio objects in the demuxer callback, the
movie is played a few frames and then stops. 

Is my understanding of how the dynamic linking works wrong or have I
missed anything?

I'd appreciate any help.


Here's my demuxer callback:

static void
new_pad (GstElement *element, GstPad *pad, gpointer data)
  GstCaps *caps;
  gchar *name;
  gchar *type;

  caps = gst_pad_get_caps (pad);
  name = gst_pad_get_name (pad);
  type = gst_caps_to_string (caps);

  // VIDEO
  if ( NULL != strstr(name, "video"))
    GstPad *sinkpad;
    sinkpad = gst_element_get_pad (queue_video, "sink");
    gst_pad_link (pad, sinkpad);
    gst_object_unref (sinkpad);

  // AUDIO
  if ( NULL != strstr(name, "audio"))
    GstPad *sinkpad;

    if (0 == strncmp("audio/x-ac3", type, strlen("audio/x-ac3")))
      g_print("AC-3 AUDIO\n");
      decoder_audio	= gst_element_factory_make ("a52dec", NULL);
    else if (0 == strncmp("audio/mpeg", type, strlen("audio/mpeg")))
      g_print("MPEG AUDIO\n");
      decoder_audio	= gst_element_factory_make ("mad", NULL);

    gst_bin_add_many (GST_BIN (pipeline), queue_audio, decoder_audio,
convert_audio, sink_audio, NULL);
    gst_element_link_many (queue_audio, decoder_audio, convert_audio,
sink_audio, NULL);

    sinkpad = gst_element_get_pad (queue_audio, "sink");
    gst_pad_link (pad, sinkpad);
    gst_object_unref (sinkpad);

More information about the gstreamer-devel mailing list