[gst-devel] Playing avi - a newbie question

Štěpán stepan1117 at atlas.cz
Sun Oct 12 17:22:21 CEST 2008


Hi,
   thanks very much for your answer, I studied the given part of manual
and found, that somebody before me was facing similar problem. So, I
rewrote the code and now it looks like this:

-------------- code begins -------------------
#include <gst/gst.h>
#include <glib.h>
#include <string.h>

static GstElement *source, *demuxer, *vdqueue, *adqueue, *vdsink,
*adsink, *decvd, *decad;

void on_pad_added (GstElement *element, GstPad *pad)
{

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

    GstCaps *caps;
    GstStructure *str;

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

    if (g_strrstr (gst_structure_get_name (str), "video")) {
        g_debug ("Linking video pad to dec_vd");
        // Link it actually
        GstPad *targetsink = gst_element_get_pad (decvd, "sink");
        g_assert (targetsink != NULL);
        gst_pad_link (pad, targetsink);
        gst_object_unref (targetsink);
    }

    if (g_strrstr (gst_structure_get_name (str), "audio")) {
        g_debug ("Linking audio pad to dec_ad");
        // Link it actually
        GstPad *targetsink = gst_element_get_pad (decad, "sink");
        g_assert (targetsink != NULL);
        gst_pad_link (pad, targetsink);
        gst_object_unref (targetsink);
    }

    gst_caps_unref (caps);
}

static gboolean
bus_call (GstBus *bus,
        GstMessage *msg,
        gpointer data)
{
    GMainLoop *loop = (GMainLoop *) 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 *error;

        gst_message_parse_error (msg, &error, &debug);

        g_printerr ("Error: %s (%s) \n", error->message, debug);
        g_free (debug);
        g_error_free (error);

        g_main_loop_quit (loop);
        break;
    }
    default:
        break;
    }

    return TRUE;
}

int
main (int argc,
        char *argv[])
{
    GMainLoop *loop;

    GstElement *pipeline;
    GstBus *bus;

    /* Initialisation */
    gst_init (&argc, &argv);

    loop = g_main_loop_new (NULL, FALSE);


    /* Check input arguments */
    if (argc != 2) {
        g_printerr ("Usage: %s <AVI filename>\n", argv[0]);
        return -1;
    }


    /* Create gstreamer elements */
    pipeline = gst_pipeline_new ("media-player");
    source = gst_element_factory_make ("filesrc", "file-source");
    demuxer = gst_element_factory_make ("avidemux", "avi-demuxer");
    decvd = gst_element_factory_make ("ffdec_mpeg4", "video-decoder");
    decad = gst_element_factory_make ("mad", "mp3-decoder");
    vdsink = gst_element_factory_make ("autovideosink", "video-sink");
    vdqueue = gst_element_factory_make ("queue", "video-queue");
    adqueue = gst_element_factory_make ("queue", "audio-queue");
    adsink = gst_element_factory_make ("alsasink", "audio-sink");

    if (!pipeline || !source || !demuxer || !decvd || !decad || !vdsink
            || !vdqueue || !adqueue || !adsink) {
        g_printerr ("One element could not be created. Exiting.\n");
        return -1;
    }

    /* Set up the pipeline */

    /* we set the input filename to the source element */
    g_object_set (G_OBJECT (source), "location", argv[1], NULL);

    /* we add a message handler */
    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
    gst_bus_add_watch (bus, bus_call, loop);
    gst_object_unref (bus);

    gst_bin_add_many (GST_BIN (pipeline),
            source, demuxer, decvd, decad, adqueue, vdqueue,
            vdsink, adsink, NULL);

    gst_element_link (source, demuxer);
    gst_element_link (decvd, vdqueue);
    gst_element_link (vdqueue, vdsink);
    gst_element_link (decad, adqueue);
    gst_element_link (adqueue, adsink);

    g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added),
NULL);

    /* Set the pipeline to "playing" state*/
    g_print ("Now playing: %s\n", argv[1]);
    gst_element_set_state (pipeline, GST_STATE_PLAYING);

    /* Iterate */
    g_print ("Running...\n");
    g_main_loop_run (loop);

    /* 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));

    return 0;
}
------------ code ends ------------

Now, it does not give me "not-linked", but "not-negotiated" error. More
detailed:

Now playing: something.avi
Running...
** (srtk:15847): DEBUG: A new pad video_00 was created

** (srtk:15847): DEBUG: Linking video pad to dec_vd
** (srtk:15847): DEBUG: A new pad audio_00 was created

** (srtk:15847): DEBUG: Linking audio pad to dec_ad
Error: Internal data stream error. (gstavidemux.c(4115):
gst_avi_demux_loop ():
/GstPipeline:media-player/GstAviDemux:avi-demuxer: streaming stopped,
reason not-negotiated)
Returned, stopping playback
Deleting pipeline

My .avi is:
something.avi: RIFF (little-endian) data, AVI, 640 x 272, 25.00 fps,
video: DivX 4, audio: MPEG-1 Layer 3 (stereo, 48000 Hz)

So, I am still stuck :)
Thank you,
   Stepan




More information about the gstreamer-devel mailing list