This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler: AM5728: GStream playing TS files

Tool/software: TI C/C++ Compiler

Hello:

I will save a test.ts file locally and use the following gstream command to display it properly.

gst-launch-1.0 -v filesrc location=test.ts ! queue ! tsdemux ! h264parse ! ducatih264dec ! waylandsink 

I try to use C language to write,The image is not displayed when compiling execution.

Here is my source code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>
#include <gst/gst.h>
int main(int argc, char *argv[])
{
    GstElement *pipeline, *filesrc, *queue, *tsdemux, *h264parse, *ducatih264dec, *waylandsink;
    static GMainLoop *loop;
    gst_init(&argc, &argv);
    loop = g_main_loop_new(NULL, FALSE);
    pipeline = gst_pipeline_new("pipeline");
    if (!pipeline) {
        g_printerr("%d gst_pipeline_new error \n", __LINE__);
        return -1;
    }
    filesrc = gst_element_factory_make("filesrc", "filesrc0");
    if (!filesrc) {
        g_printerr("%d gst_element_factory_make error \n", __LINE__);
    }
    queue = gst_element_factory_make("queue", "queue0");
    if (!queue) {
        g_printerr("%d gst_element_factory_make error \n", __LINE__);
    }
    tsdemux = gst_element_factory_make("tsdemux", "tsdemux0");
    if (!tsdemux) {
        g_printerr("%d gst_element_factory_make error \n", __LINE__);
    }
    h264parse = gst_element_factory_make("h264parse", "h264parse0");
    if (!h264parse) {
        g_printerr("%d gst_element_factory_make error \n", __LINE__);
    }
    ducatih264dec = gst_element_factory_make("ducatih264dec", "ducatih264dec0");
    if (!ducatih264dec) {
        g_printerr("%d gst_element_factory_make error \n", __LINE__);
    }
    waylandsink = gst_element_factory_make("waylandsink", "waylandsink0");
    if (!waylandsink) {
        g_printerr("%d gst_element_factory_make error \n", __LINE__);
    }
    g_object_set(G_OBJECT(filesrc), "location", "test.ts", NULL);
    gst_bin_add_many(GST_BIN(pipeline), filesrc, queue, tsdemux, h264parse, ducatih264dec, waylandsink, NULL);
    gst_element_link_many(filesrc, queue, tsdemux, h264parse, ducatih264dec, waylandsink, NULL);
    gst_element_set_state(pipeline, GST_STATE_PLAYING);
    g_main_loop_run(loop);
    g_main_loop_unref(loop);
    return 0;
}

I try to add the "--gst-debug = 4" parameter when executing, and the red section has an error message

GST_ELEMENT_PADS ../../gstreamer-1.2.3/gst/gstelement.c:894:gst_element_get_static_pad: no such pad 'sink' in element "filesrc0"
0:00:02.207006671  1091   0x13d8f0 INFO               GST_EVENT ../../gstreamer-1.2.3/gst/gstevent.c:709:gst_event_new_segment: creating segment event bytes segment start=0, stop=-1, rate=1.000000, applied_rate=1.000000, flags=0x00, time=0, base=0, position 0, duration 1875968
0:00:02.207197967  1091   0x13d8f0 INFO                 basesrc ../../../../gstreamer-1.2.3/libs/gst/base/gstbasesrc.c:2772:gst_base_src_loop:<filesrc0> marking pending DISCONT
0:00:02.207344855  1091   0x13d8c0 INFO        mpegtspacketizer ../../../git/gst/mpegtsdemux/mpegtspacketizer.c:770:mpegts_try_discover_packet_size: have packetsize detected: 188 bytes
0:00:02.207464578  1091   0x13d8c0 INFO              mpegtsbase ../../../git/gst/mpegtsdemux/mpegtsbase.c:726:mpegts_base_apply_pat:<tsdemux0> PAT
0:00:02.207720941  1091   0x13d8c0 INFO        GST_ELEMENT_PADS ../../gstreamer-1.2.3/gst/gstelement.c:897:gst_element_get_static_pad: found pad tsdemux0:sink
0:00:02.207803413  1091   0x13d8c0 INFO               GST_EVENT ../../gstreamer-1.2.3/gst/gstevent.c:628:gst_event_new_caps: creating caps event video/x-h264, stream-format=(string)byte-stream, alignment=(string)nal
0:00:02.208967130  1091   0x13d8c0 INFO        GST_ELEMENT_PADS ../../gstreamer-1.2.3/gst/gstelement.c:646:gst_element_add_pad:<tsdemux0> adding pad 'video_0041'
0:00:02.209020485  1091   0x13d8c0 INFO               GST_EVENT ../../gstreamer-1.2.3/gst/gstevent.c:709:gst_event_new_segment: creating segment event time segment start=0:00:00.125000000, stop=99:99:99.999999999, rate=1.000000, applied_rate=1.000000, flags=0x00, time=0:00:00.125000000, base=0:00:00.000000000, position 0:00:00.125000000, duration 99:99:99.999999999
0:00:02.209187869  1091   0x13d8c0 INFO                    task ../../gstreamer-1.2.3/gst/gsttask.c:300:gst_task_func:<queue0:src> Task going to paused
0:00:02.209288559  1091   0x13d8f0 INFO                 basesrc ../../../../gstreamer-1.2.3/libs/gst/base/gstbasesrc.c:2785:gst_base_src_loop:<filesrc0> pausing after gst_pad_push() = not-linked
0:00:02.209340125  1091   0x13d8f0 WARN                 basesrc ../../../../gstreamer-1.2.3/libs/gst/base/gstbasesrc.c:2865:gst_base_src_loop:<filesrc0> error: Internal data flow error.
0:00:02.209373797  1091   0x13d8f0 WARN                 basesrc ../../../../gstreamer-1.2.3/libs/gst/base/gstbasesrc.c:2865:gst_base_src_loop:<filesrc0> error: streaming task paused, reason not-linked (-1)
0:00:02.209429266  1091   0x13d8f0 INFO        GST_ERROR_SYSTEM ../../gstreamer-1.2.3/gst/gstelement.c:1835:gst_element_message_full:<filesrc0> posting message: Internal data flow error.
0:00:02.209511250  1091   0x13d8f0 INFO        GST_ERROR_SYSTEM ../../gstreamer-1.2.3/gst/gstelement.c:1858:gst_element_message_full:<filesrc0> posted error message: Internal data flow error.
0:00:02.562908161  1091   0x13d8f0 INFO                    task ../../gstreamer-1.2.3/gst/gsttask.c:300:gst_task_func:<filesrc0:src> Task going to paused
Please help me where I am wrong?
  • The software team have been notified. They will respond here.
  • hello:
    thank you very much.
    Please help me solve as soon as possible.
  • Hello,

    In the code I do not see the correct adding of the demuxer element.

    With gst-inspect-1.0  you could check the SRC and SINK templates.

    Here is example of how demuxer could be add:

    static void on_pad_added (GstElement *element, GstPad *pad, gpointer data)

    {

    GstPad *sinkpad;

    gchar *name;

    GstElement *vqueue = (GstElement *) data;

    GstElement *aqueue = (GstElement *) data;

    /* Link this pad with the queue sink pad */

    name = gst_pad_get_name( pad );

    if (strncmp(name, "video_00", NULL)==0){

    g_print ("Dynamic pad created, linking demuxer/vsink\n");

    sinkpad = gst_element_get_static_pad (vqueue, "sink");

    gst_pad_link (pad, sinkpad);

    gst_object_unref (sinkpad);

       }  

    else if (strncmp(name, "audio_00",  NULL)==0){

    g_print ("Dynamic pad created, linking demuxer/asink\n");

    sinkpad = gst_element_get_static_pad (aqueue, "sink");

    gst_pad_link (pad, sinkpad);

    gst_object_unref (sinkpad);

    }

    printf( "%s - New pad '%s'\n", __FUNCTION__, name);

    }

    The bold test should be changed based on which demuxer you are using (SRC and SINK templates from gst-inspect command.).

    With function g_signal_connect  you could "listen" for the newly created demuxer's pads and link the elements.

    BR
    Margarita

  • Hello,

    Please try this code:



    #include <stdio.h>
    #include <gst/gst.h>




    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_free (debug);
    g_printerr ("Error: %s\n", error->message);
    g_error_free (error);
    g_main_loop_quit (loop);
    break;
    }
    default:
    break;
    }

    return TRUE;
    }



    static void on_pad_added (GstElement *element, GstPad *pad, gpointer data)
    {
    GstPad *sinkpad;
    gchar *name;

    GstElement *vqueue = (GstElement *) data;
    GstElement *aqueue = (GstElement *) data;
    /* Link this pad with the queue sink pad */
    name = gst_pad_get_name( pad );
    if (strncmp(name, "video_0041", NULL)==0){
    g_print ("Dynamic pad created, linking demuxer/vsink\n");
    sinkpad = gst_element_get_static_pad (vqueue, "sink");
    gst_pad_link (pad, sinkpad);
    gst_object_unref (sinkpad);
    }

    printf( "%s - New pad '%s'\n", __FUNCTION__, name);

    }



    int main (int argc, char *argv[])
    {
    GMainLoop *loop;
    GstBus *bus;
    GstCaps *caps;

    GstElement *pipeline;
    GstElement *filesrc;
    GstElement *demuxer;
    GstElement *vqueue;
    GstElement *parser;
    GstElement *decoder;
    GstElement *vsink;





    /* Initialisation */
    gst_init (&argc, &argv);
    loop = g_main_loop_new (NULL, FALSE);

    /* Create gstreamer elements*/

    pipeline = gst_pipeline_new("tsplay");

    filesrc = gst_element_factory_make("filesrc", "filesource");
    g_return_val_if_fail (filesrc, -1);
    g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);

    demuxer = gst_element_factory_make("tsdemux", "demux");
    g_return_val_if_fail (demuxer, -1);

    vqueue = gst_element_factory_make("queue","vqueue");
    g_return_val_if_fail (vqueue, -1);

    parser = gst_element_factory_make("h264parse","parser");
    g_return_val_if_fail (parser, -1);

    decoder = gst_element_factory_make("ducatih264dec", "decoder");
    g_return_val_if_fail (decoder, -1);


    vsink = gst_element_factory_make("waylandsink", "sink");
    g_return_val_if_fail (vsink, -1);



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


    /* Add elements to pipeline before linking them.*/


    gst_bin_add (GST_BIN (pipeline), filesrc);
    gst_bin_add (GST_BIN (pipeline), demuxer);
    gst_bin_add (GST_BIN (pipeline), vqueue);
    gst_bin_add (GST_BIN (pipeline), parser);
    gst_bin_add (GST_BIN (pipeline), decoder);
    gst_bin_add (GST_BIN (pipeline), vsink);


    /* Link the pipeline */
    gst_element_link_pads (filesrc, "src", demuxer, "sink");
    gst_element_link_pads (demuxer, "src", vqueue, "sink");
    /* listen for newly created pads */
    g_signal_connect (G_OBJECT (demuxer), "pad-added", G_CALLBACK (on_pad_added), vqueue);
    gst_element_link_pads (vqueue, "src", parser, "sink");
    gst_element_link_pads (parser, "src", decoder, "sink");
    gst_element_link_pads (decoder, "src", vsink, "sink");

    /* Set the pipeline to "playing" state */
    g_print ("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;
    }

    Let me know the result.
    Execution: ./<name of the app> <video file name>


    BR
    Margarita

  • Hi:
    thank you very much.
    Can be displayed.
  • Hello,

    If this code is working for you, please verify the answer.

    BR
    Margarita
  • Hello,

    I am sorry I see in the source code that I forgot to unref(msg). Please add this line
    gst_message_unref( msg ); before
    return TRUE;
    }
    in bus_call function.

    BR
    Margarita