Vishvesh
Vishvesh

Reputation: 522

Gstreamer HLS pipeline creation error

I am trying to stream a HLS Stream using gstreamer 1.0. I have a filter which works

gst-launch-1.0 -v souphttpsrc location="http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8" ! hlsdemux ! tsdemux ! h264parse ! avdec_h264 ! autovideosink

But when I try to convert this into c code, it fails.

int main(int argc, char* argv[])
{
    GMainLoop *loop;
    GstElement *pipeline, *source, *demuxer, *tsdemux, *h264parse, *vdecoder, *vsink;
    GstElement *aacparse, *adecoder, *aconvert, *asink;
    GstBus *bus;
    int bus_watch_id;

    gst_debug_set_default_threshold(3);
    gst_init(&argc, &argv);
    loop = g_main_loop_new(NULL, FALSE);

    if (argc != 2)
    {
       g_printerr("Usage: %s <http stream source>\n", argv[0]);
       return -1;
    } 

    pipeline = gst_pipeline_new("myApp");
    source = gst_element_factory_make("souphttpsrc", "http-src");
    demuxer = gst_element_factory_make("hlsdemux", "hls-demuxer");
    tsdemux = gst_element_factory_make("tsdemux", "ts-demuxer");
    h264parse = gst_element_factory_make("h264parse", "h264parse");
    vdecoder = gst_element_factory_make("avdec_h264", "h264decoder");
    vsink = gst_element_factory_make("autovideosink", "videosink");


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

    bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
    bus_watch_id = gst_bus_add_watch(bus, bus_call, loop);
    gst_object_unref(bus);

    /* add elements into the pipeline */ //next aacparse
    gst_bin_add_many(GST_BIN (pipeline), source, demuxer, tsdemux, h264parse, vdecoder,vsink,  NULL);

    gst_element_link(source, demuxer);
    // this was wrong
    /*gst_element_link_many(tsdemux, h264parse, vdecoder, vsink, NULL);*/


    /* connect demuxer and decoder on pad added */
    /*g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), vdecoder);*/

    // Correct Implementation
    gst_element_link_many(h264parse, vdecoder, vsink, NULL);

    g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), tsdemux);
    g_signal_connect(tsdemux, "pad-added", G_CALLBACK(on_pad_added), h264parse);
    g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), vdecoder);
    // Correct Implementation

    g_print ("Starting play: %s\n", argv[1]);
    gst_element_set_state(pipeline, GST_STATE_PLAYING);

    g_print ("Running\n");
    g_main_loop_run(loop);

    /* Clean up after execution of main loop */
    g_print ("Stopping Playback: %s\n", argv[1]);
    gst_element_set_state(pipeline, GST_STATE_NULL);

    g_print ("Quitting\n");
    g_object_unref(G_OBJECT(pipeline));
    g_source_remove(bus_watch_id);

    g_main_loop_unref(loop);

    return 0;
}

I compile the code using:

cc my_app.c -o my_app $(pkg-config --cflags --libs gstreamer-1.0)

And launch the application using:

./my_app http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8

I always get the following error:

hlsdemux gsthlsdemux.c:792:gst_hls_demux_stream_loop:<hls-demuxer> error: stream stopped, reason not-negotiated

Do I have to do anything differently?

Upvotes: 0

Views: 2246

Answers (2)

user3614789
user3614789

Reputation: 200

// this was wrong
gst_element_link(source, demuxer);
// Correct Implementation
gst_element_link(source, demuxer,NULL);

where is your void on_pad_added (GstElement *element, GstPad *pad, gpointer data); function?
and take a look at here.

Upvotes: 1

Vishvesh
Vishvesh

Reputation: 522

I was able to get it working. The problem was "tsdemux" and "demuxer" have to connect at run time in "on_pad_added" method.

Upvotes: 1

Related Questions