Luffy
Luffy

Reputation: 97

error while playing .wav file using gstreamer apis

I know this question has been posted several times. But none of the solutions worked for me.

I am trying to play .wav files using gstreamer apis. The below command plays .wav files (with or without the audioconvert):

gst-launch-1.0 filesrc location=sound.wav ! wavparse ! audioconvert ! alsasink

I have written a simple c++ code for the above command referring the GStreamer Hello world example. But it ends with "Internal data flow error". This is my code:

{
    gst_init(NULL, NULL);
    m_pipeline  = gst_pipeline_new("audio-player");
    m_fileSource = gst_element_factory_make("filesrc", "file-source");
    m_parser = gst_element_factory_make("wavparse", "wav-parser");
    m_sink = gst_element_factory_make("alsasink", "audio-output");
    if (!m_pipeline || !m_fileSource || !m_parser || !m_sink) {
        g_printerr ("One or more elements could not be created !! \n");
        return false;
    }
    /* Set up the pipeline */
    else {
        /* set the input filename to the source element */
        g_object_set (G_OBJECT (m_fileSource), "location", path.toLatin1().data(), NULL);

        /* set a message handler on a bus */
        GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (m_pipeline));
        gst_bus_add_watch(bus, bus_call, this);
        gst_object_unref(bus);

        /* add all elements into the pipeline */
        gst_bin_add_many (GST_BIN (m_pipeline), m_fileSource, m_parser, m_sink, NULL);

        /* link the elements together */
        gst_element_link (m_fileSource, m_parser);

        g_signal_connect(m_parser, "pad-added", G_CALLBACK(on_pad_added), m_sink);
    }
    gst_element_set_state(m_pipeline, GST_STATE_READY);
    gst_element_set_state(m_pipeline, GST_STATE_PAUSED);
}

on_pad_added(GstElement *src_element, GstPad *src_pad, gpointer data)
{
    GstElement *sink_element = (GstElement *)data;

    GstPad *sink_pad = gst_element_get_static_pad(sink_element, "sink");
gst_pad_link(src_pad, sink_pad);

    gst_object_unref(sink_pad);
    src_element = NULL;
}

I even tried the solutions suggested in this link; replaced "oggdemux" with "wavparse" and "vorbisdec" with "identity" from the Gstreamer Hello World example as suggested in this link. Error I received:

    0:00:00.289443936  1624  0x1234e00 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<file-source> pad not activated yet
0:00:00.290993573  1624  0x1740030 FIXME                default gstutils.c:3643:gst_pad_create_stream_id_internal:<wav-parser:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.291883886  1624  0x1740030 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk bext
0:00:00.292198262  1624  0x1740030 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk junk
0:00:00.305086920  1624  0x1234e00 WARN                 basesrc gstbasesrc.c:3470:gst_base_src_start_complete:<file-source> pad not activated yet
0:00:00.306444838  1624  0x17400c0 FIXME                default gstutils.c:3643:gst_pad_create_stream_id_internal:<wav-parser:src> Creating random stream-id, consider implementing a deterministic way of creating a stream-id
0:00:00.307224214  1624  0x17400c0 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk bext
0:00:00.307636819  1624  0x17400c0 WARN                wavparse gstwavparse.c:1564:gst_wavparse_stream_headers:<wav-parser> Ignoring chunk junk
0:00:00.526277506  1624  0x17400c0 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: Internal data flow error.
0:00:00.526495475  1624  0x17400c0 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: streaming task paused, reason not-linked (-1)
0:00:00.527296570  1624  0x1740030 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: Internal data flow error.
0:00:00.527439278  1624  0x1740030 WARN                wavparse gstwavparse.c:2186:gst_wavparse_loop:<wav-parser> error: streaming task paused, reason not-linked (-1)
ERROR: Internal data flow error.
ERROR: Internal data flow error.

What am I missing in the code?

Upvotes: 0

Views: 2360

Answers (1)

thiagoss
thiagoss

Reputation: 2094

You get a not-linked error, some element was left unlinked.

The element is wavparse. Your code is trying to wait for it to add a pad to link it, but wavparse has an 'always' source pad, meaning that it is there since the creation of the element so you can just link it directly just like you did with your filesrc.

Upvotes: 1

Related Questions