[gst-devel] Converting a gst-launch pipeline to C code

MSJ mauricio_sj at yahoo.com
Sat Oct 3 00:01:44 CEST 2009


I'm trying to do the same, but my pipeline doesn't seem to work; if I removed
either of the lines marked *** then video or audio play, but having both
lines doesn't seem to work.  I've been trying evrything, and I notice than
in the working case I get an sync-done message which I don't get in the
other cases.  I appreaciate any insight.

Thanks.


static void on_pad_added (GstElement *element,
    GstPad *pad,
    gpointer data)
{
    GstCaps *caps;
    const gchar *mime;

    GstPad *audiopad, *videopad;

    caps = gst_pad_get_caps (pad);
    g_assert (caps != NULL);
    mime = gst_structure_get_name (gst_caps_get_structure (caps, 0));

    if (g_strrstr (mime, "audio")) {
        /* only link once */
        audiopad = gst_element_get_static_pad (audio, "sink");
        g_assert(audiopad);
        if (GST_PAD_IS_LINKED (audiopad)) {
            g_error("Audio already Linked\n");
            g_object_unref (audiopad);
            return;
        }
        g_print("Linking the audio %s\n", mime);
        /* link’n’play */
        gst_pad_link (pad, audiopad);
        gst_object_unref (audiopad);
    }

    if (g_strrstr (mime, "video")) {
        /* only link once */
        videopad = gst_element_get_static_pad (video, "sink");
        g_assert(videopad);
        if (GST_PAD_IS_LINKED (videopad)) {
            g_error("Video already Linked\n");  
            g_object_unref (videopad);
            return;
        }
        gst_pad_link (pad, videopad);
        gst_object_unref (videopad);
    }
   

    gst_caps_unref (caps);
}

[...] Main Initialization

    /* Pipeline Creation */
    gst_bin_add_many (GST_BIN (pipeline), source, demux, NULL);

    /* Link of the elements together */
    /* file-source -> AVI-demuxer ~> A/V CODEC -> sink */
    gst_element_link (source, demux);
    g_signal_connect (demux, "pad-added", G_CALLBACK (on_pad_added), NULL);

    /* create audio output */
    audio = gst_bin_new ("audiobin");
    gst_bin_add_many (GST_BIN (audio), aqueue, adec, asink, NULL);
    gst_element_link_many(aqueue, adec, asink, NULL);

    audiopad = gst_element_get_static_pad (aqueue, "sink");    
    gst_element_add_pad (audio, gst_ghost_pad_new ("sink", audiopad));
    gst_object_unref (audiopad);
    gst_bin_add (GST_BIN (pipeline), audio);  ***

    /* create video output */
    video = gst_bin_new ("videobin");
    gst_bin_add_many (GST_BIN (video), vqueue, vdec, vsink, NULL);
    gst_element_link_many (vqueue, vdec, vsink, NULL);

    videopad = gst_element_get_static_pad (vqueue, "sink");    
    gst_element_add_pad (video, gst_ghost_pad_new ("sink", videopad));
    gst_object_unref (videopad);
    gst_bin_add (GST_BIN (pipeline), video  ***

[...]
    /* Set the pipeline to "playing" state*/
    g_print ("Now playing: %s\n", aviFile);
    gst_element_set_state (pipeline, GST_STATE_PLAYING);
    
    /* Iterate */
    g_print ("Running...\n");
    /* Out of the main 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));
-- 
View this message in context: http://www.nabble.com/Converting-a-gst-launch-pipeline-to-C-code-tp19728759p25722086.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.





More information about the gstreamer-devel mailing list