Using appsrc and uridecodebin together in a pipeline

Please provide complete information as applicable to your setup.

• Hardware Platform (Jetson / GPU) :- dGPU
• DeepStream Version :- 6.4

I am trying to work with appsrc element and uridecodebin element together in a pipeline. I am able to link all the required elements together, but for some reason, I am not able to see the images pushed through appsrc in the display sink.

This is my pipeline.

and here is my code.

#include <glib.h>
#include <gst/gst.h>
#include <hiredis/hiredis.h>
#include <unistd.h>

#include <cmath>
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <nlohmann/json.hpp>
#include <string>

#include "gst/app/gstappsrc.h"
#include "gstnvdsinfer.h"
#include "gstnvdsmeta.h"
#include "nvbufsurface.h"
#include "nvds_obj_encode.h"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"

using json = nlohmann::json;

using namespace std;
#define MUXER_OUTPUT_WIDTH 1280
#define MUXER_OUTPUT_HEIGHT 720

#define MUXER_BATCH_TIMEOUT_USEC 40000

// #define perf_measurement
#define enable_probes
#define TILED_OUTPUT_WIDTH 1280
#define TILED_OUTPUT_HEIGHT 720

#define GST_CAPS_FEATURES_NVMM "memory:NVMM"
using json = nlohmann::json;

typedef struct _AppSrcData {
    GstElement *app_source;
    long frame_size;
    FILE *file;
    gint appsrc_frame_num;
    guint fps;
    guint sourceid;
} AppSrcData;

struct UserData {
    GMainLoop *main_loop;
    GstElement *pipeline;
};

void signal_handler_final(int signum) {
    std::cout << "Existing because you insist!" << std::endl;
    exit(EXIT_SUCCESS);
}

GstBuffer *createGstBufferFromMat(const cv::Mat &mat) {
    if (mat.empty()) {
        std::cerr << "Empty cv::Mat provided" << std::endl;
        return nullptr;
    }
    size_t bufferSize = mat.total() * mat.elemSize();
    GstBuffer *buffer = gst_buffer_new_allocate(nullptr, bufferSize, nullptr);

    if (!buffer) {
        std::cerr << "Failed to create GstBuffer" << std::endl;
        return nullptr;
    }
    GstMapInfo map;
    if (!gst_buffer_map(buffer, &map, GST_MAP_WRITE)) {
        std::cerr << "Failed to map GstBuffer" << std::endl;
        gst_buffer_unref(buffer);
        return nullptr;
    }
    std::memcpy(map.data, mat.data, bufferSize);
    gst_buffer_unmap(buffer, &map);
    return buffer;
}

gboolean read_data(AppSrcData *data2) {
    std::cout << "in read data " << std::endl;
    while (true) {
        cv::Mat image = cv::imread("image.jpg", cv::IMREAD_COLOR);
        if (image.empty()) {
            std::cerr << "Failed to load image" << std::endl;
            return FALSE;
        }
        GstBuffer *gstBuffer = createGstBufferFromMat(image);
        int gstret;
        if (gstBuffer != nullptr) {
            for (int i = 0; i < 10; i++) {
                gstret = gst_app_src_push_buffer((GstAppSrc *)data2->app_source,
                                                 gstBuffer);
                if (gstret != GST_FLOW_OK) {
                    g_print("gst_app_src_push_buffer returned %d \n", gstret);
                    return FALSE;
                }
            }
        }
    }
    return TRUE;
}

void signal_handler(int sig_num) {
    std::cout << std::endl
              << "Caught signal" << sig_num << std::endl
              << "Press CTRL+C again to exit!" << std::endl;
    std::signal(SIGINT, signal_handler_final);
}
static void start_feed(GstElement *source, guint size, AppSrcData *data) {
    read_data(data);
}

static void stop_feed(GstElement *source, AppSrcData *data) {
    if (data->sourceid != 0) {
        g_source_remove(data->sourceid);
        data->sourceid = 0;
    }
}

gboolean bus_call_short(GstBus *bus, GstMessage *msg, gpointer user_data) {
    struct UserData *data = (struct UserData *)user_data;

    GMainLoop *loop = (GMainLoop *)data->main_loop;
    GstElement *pipeline = data->pipeline;
    switch (GST_MESSAGE_TYPE(msg)) {
        case GST_MESSAGE_ERROR: {
            gchar *debug;
            GError *error;
            gst_message_parse_error(msg, &error, &debug);
            g_printerr("ERROR from element %s: %s\n", GST_OBJECT_NAME(msg->src),
                       error->message);
            if (debug) g_printerr("Error details: %s\n", debug);
            g_free(debug);
            g_error_free(error);
            g_main_loop_quit(loop);
            break;
        }
        case GST_MESSAGE_EOS:
            g_print("End of stream\n");
            g_main_loop_quit(loop);
            gst_element_set_state(pipeline, GST_STATE_NULL);
            g_print("Deleting pipeline\n");
            gst_object_unref(GST_OBJECT(pipeline));
            break;
        default:
            std::cout << " ()()() some other error ()()() " << std::endl;
            break;
    }

    return TRUE;
}

static void cb_newpad(GstElement *decodebin, GstPad *decoder_src_pad,
                      gpointer data) {
    GstCaps *caps = gst_pad_get_current_caps(decoder_src_pad);
    if (!caps) {
        caps = gst_pad_query_caps(decoder_src_pad, NULL);
    }
    const GstStructure *str = gst_caps_get_structure(caps, 0);
    const gchar *name = gst_structure_get_name(str);
    GstElement *source_bin = (GstElement *)data;
    GstCapsFeatures *features = gst_caps_get_features(caps, 0);

    /* Need to check if the pad created by the decodebin is for video and not
     * audio. */
    if (!strncmp(name, "video", 5)) {
        /* Link the decodebin pad only if decodebin has picked nvidia
         * decoder plugin nvdec_*. We do this by checking if the pad caps
         * contain NVMM memory features. */
        if (gst_caps_features_contains(features, GST_CAPS_FEATURES_NVMM)) {
            /* Get the source bin ghost pad */
            GstPad *bin_ghost_pad =
                gst_element_get_static_pad(source_bin, "src");
            if (!gst_ghost_pad_set_target(GST_GHOST_PAD(bin_ghost_pad),
                                          decoder_src_pad)) {
                g_printerr(
                    "Failed to link decoder src pad to source bin ghost pad\n");
            }
            gst_object_unref(bin_ghost_pad);
        } else {
            g_printerr(
                "Error: Decodebin did not pick nvidia decoder plugin.\n");
        }
    }
}

static void decodebin_child_added(GstChildProxy *child_proxy, GObject *object,
                                  gchar *name, gpointer user_data) {
    g_print("Decodebin child added: %s\n", name);
    if (g_strrstr(name, "decodebin") == name) {
        g_signal_connect(G_OBJECT(object), "child-added",
                         G_CALLBACK(decodebin_child_added), user_data);
    }
    if (g_strrstr(name, "source") == name) {
        g_object_set(G_OBJECT(object), "drop-on-latency", true, NULL);
    }
}

static GstElement *create_source_bin(guint index, gchar *uri) {
    GstElement *bin = NULL, *uri_decode_bin = NULL;
    gchar bin_name[16] = {};

    g_snprintf(bin_name, 15, "source-bin-%02d", index);
    /* Create a source GstBin to abstract this bin's content from the rest of
     * the pipeline */
    bin = gst_bin_new(bin_name);

    /* Source element for reading from the uri.
     * We will use decodebin and let it figure out the container format of the
     * stream and the codec and plug the appropriate demux and decode plugins.
     */
    bool PERF_MODE = true;
    if (PERF_MODE) {
        uri_decode_bin =
            gst_element_factory_make("nvurisrcbin", "uri-decode-bin");
        g_object_set(G_OBJECT(uri_decode_bin), "file-loop", false, NULL);
        g_object_set(G_OBJECT(uri_decode_bin), "cudadec-memtype", 0, NULL);
        g_object_set(G_OBJECT(uri_decode_bin), "latency", 50, NULL);
        g_object_set(G_OBJECT(uri_decode_bin), "rtsp-reconnect-interval", 60,
                     NULL);
    } else {
        uri_decode_bin =
            gst_element_factory_make("uridecodebin", "uri-decode-bin");
    }

    if (!bin || !uri_decode_bin) {
        g_printerr("One element in source bin could not be created.\n");
        return NULL;
    }

    /* We set the input uri to the source element */
    g_object_set(G_OBJECT(uri_decode_bin), "uri", uri, NULL);

    /* Connect to the "pad-added" signal of the decodebin which generates a
     * callback once a new pad for raw data has beed created by the decodebin */
    g_signal_connect(G_OBJECT(uri_decode_bin), "pad-added",
                     G_CALLBACK(cb_newpad), bin);
    g_signal_connect(G_OBJECT(uri_decode_bin), "child-added",
                     G_CALLBACK(decodebin_child_added), bin);

    gst_bin_add(GST_BIN(bin), uri_decode_bin);

    /* We need to create a ghost pad for the source bin which will act as a
     * proxy for the video decoder src pad. The ghost pad will not have a target
     * right now. Once the decode bin creates the video decoder and generates
     * the cb_newpad callback, we will set the ghost pad target to the video
     * decoder src pad. */
    if (!gst_element_add_pad(bin,
                             gst_ghost_pad_new_no_target("src", GST_PAD_SRC))) {
        g_printerr("Failed to add ghost pad in source bin\n");
        return NULL;
    }

    return bin;
}

// std::vector<std::string> *person_name;
int main(int argc, char *argv[]) {
    GMainLoop *loop = nullptr;
    GstElement *pipeline = nullptr, *streammux = nullptr, *sink = nullptr,
               *pgie = nullptr, *nvtracker = nullptr, *nvdsanalytics = nullptr,
               *decoder = nullptr, *nvvidconv = nullptr, *nvosd = nullptr,
               *tiler = nullptr, *nvvidconv2 = nullptr, *sgie = nullptr,
               *person_detector = nullptr, *queue1, *queue2, *queue3, *queue4,
               *queue5, *queue6, *tee = nullptr, *decodebin = nullptr,
               *jpegenc = nullptr, *filesink = nullptr,
               *landmarks_model = nullptr, *fakesink = nullptr;

    GstBus *bus = nullptr;
    GstElement *jpegparser = nullptr;
    AppSrcData data2;
    guint bus_watch_id;
    GstPad *nvdsanalytics_src_pad = nullptr;
    guint i, num_sources = argc - 1;
    guint tiler_rows, tiler_columns;
    guint pgie_batch_size;

    struct UserData user_data = {.main_loop = loop, .pipeline = pipeline};

    int current_device = -1;
    cudaGetDevice(&current_device);
    struct cudaDeviceProp prop;
    cudaGetDeviceProperties(&prop, current_device);
    putenv("NVDS_ENABLE_LATENCY_MEASUREMENT=1");
    putenv("NVDS_ENABLE_COMPONENT_LATENCY_MEASUREMENT=1");

    gst_init(&argc, &argv);
    loop = g_main_loop_new(nullptr, FALSE);
    pipeline = gst_pipeline_new("FRS_Pipeline");

    data2.app_source = gst_element_factory_make("appsrc", "app-source");
    jpegparser = gst_element_factory_make("jpegparse", "jpeg-parser");
    decoder = gst_element_factory_make("nvv4l2decoder", "nvv4l2-decoder");

    streammux = gst_element_factory_make("nvstreammux", "stream-muxer");
    pgie = gst_element_factory_make("nvinfer", "PGIE");
    landmarks_model = gst_element_factory_make("nvinfer", "landmarks_model");
    sgie = gst_element_factory_make("nvinfer", "SGIE");
    person_detector = gst_element_factory_make("nvinfer", "person_detector");
    nvtracker = gst_element_factory_make("nvtracker", "nvtracker");
    nvdsanalytics = gst_element_factory_make("nvdsanalytics", "nvdsanalytics");
    tiler = gst_element_factory_make("nvmultistreamtiler", "nvtiler");
    nvvidconv = gst_element_factory_make("nvvideoconvert", "nvvideo-converter");
    nvvidconv2 =
        gst_element_factory_make("nvvideoconvert", "nvvideo-converter2");
    tee = gst_element_factory_make("tee", "nvsink-tee");
    nvosd = gst_element_factory_make("nvdsosd", "nv-onscreendisplay");
    fakesink = gst_element_factory_make("fakesink", "fakesink");
    jpegenc = gst_element_factory_make("jpegenc", "jpegenc");
    filesink = gst_element_factory_make("multifilesink", "filesink");
    tee = gst_element_factory_make("tee", "nvsink-tee");
    sink = gst_element_factory_make("nveglglessink", "nvvideo-renderer");

    queue1 = gst_element_factory_make("queue", "queue1");
    queue2 = gst_element_factory_make("queue", "queue2");
    queue3 = gst_element_factory_make("queue", "queue3");
    queue4 = gst_element_factory_make("queue", "queue4");
    queue5 = gst_element_factory_make("queue", "queue5");
    queue6 = gst_element_factory_make("queue", "queue6");

    if (!pgie || !sgie || !nvtracker || !nvdsanalytics || !tiler ||
        !nvvidconv || !nvosd || !sink || !jpegenc || !filesink) {
        g_printerr("One element could not be created. Exiting.\n");
        return -1;
    }

    g_object_set(G_OBJECT(data2.app_source), "num-buffers", -1, "stream-type",
                 0, "format", GST_FORMAT_TIME, "is-live", 1, NULL);

    // g_object_set(G_OBJECT(jpegparser), "disable-passthrough", 1, NULL);
    g_signal_connect(data2.app_source, "need-data", G_CALLBACK(start_feed),
                     &data2);
    // g_signal_connect (data2.app_source, "enough-data", G_CALLBACK
    // (stop_feed),&data2);

    g_object_set(G_OBJECT(streammux), "width", MUXER_OUTPUT_WIDTH, "height",
                 MUXER_OUTPUT_HEIGHT, "live-source", 1, "batch-size", 1,
                 "batched-push-timeout", MUXER_BATCH_TIMEOUT_USEC, NULL);

    tiler_rows = (guint)sqrt(std::max(1, argc - 1)) + 1;
    tiler_columns = (guint)ceil(1.0 * std::max(1, argc - 1) / tiler_rows) + 1;
    g_object_set(G_OBJECT(tiler), "rows", tiler_rows, "columns", tiler_columns,
                 "width", TILED_OUTPUT_WIDTH, "height", TILED_OUTPUT_HEIGHT,
                 NULL);

    // bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));
    // gst_bus_add_watch(bus, bus_call_short, &user_data);
    // gst_bus_add_signal_watch(bus);
    // gst_object_unref(bus);
    g_object_set(G_OBJECT(queue1), "max-size-buffers", 1, NULL);
    g_object_set(G_OBJECT(queue2), "max-size-buffers", 1, NULL);
    g_object_set(G_OBJECT(queue3), "max-size-buffers", 1, NULL);
    g_object_set(G_OBJECT(queue4), "max-size-buffers", 1, NULL);
    gst_bin_add_many(GST_BIN(pipeline), data2.app_source, jpegparser, decoder,
                     streammux, queue2, queue3, queue4, queue5, queue6,
                     nvvidconv, /*tiler,*/ nvosd,
                     /*nvvidconv2,jpegenc , filesink,*/ sink, NULL);

    for (i = 0; i < num_sources; i++) {
        GstPad *sinkpad, *srcpad;
        gchar pad_name[16] = {};

        GstElement *source_bin = NULL;

        source_bin = create_source_bin(i, argv[i + 1]);

        if (!source_bin) {
            g_printerr("Failed to create source bin. Exiting.\n");
            return -1;
        }

        gst_bin_add(GST_BIN(pipeline), source_bin);

        g_snprintf(pad_name, 15, "sink_%u", i + 1);
        sinkpad = gst_element_get_request_pad(streammux, pad_name);
        if (!sinkpad) {
            g_printerr("Streammux request sink pad failed. Exiting.\n");
            return -1;
        }

        srcpad = gst_element_get_static_pad(source_bin, "src");
        if (!srcpad) {
            g_printerr("Failed to get src pad of source bin. Exiting.\n");
            return -1;
        }

        if (gst_pad_link(srcpad, sinkpad) != GST_PAD_LINK_OK) {
            g_printerr("Failed to link source bin to stream muxer. Exiting.\n");
            return -1;
        }

        gst_object_unref(srcpad);
        gst_object_unref(sinkpad);
    }

    GstIterator *iter = gst_bin_iterate_elements(GST_BIN(pipeline));
    GValue elem = G_VALUE_INIT;
    gboolean done = false;

    while (!done) {
        switch (gst_iterator_next(iter, &elem)) {
            case GST_ITERATOR_OK: {
                GstElement *element = GST_ELEMENT(g_value_get_object(&elem));
                g_print("Element name: %s\n", GST_ELEMENT_NAME(element));
                break;
            }
            case GST_ITERATOR_RESYNC:
                gst_iterator_resync(iter);
                break;
            case GST_ITERATOR_DONE:
            case GST_ITERATOR_ERROR:
                done = TRUE;
                break;
        }
    }

    if (!gst_element_link_many(data2.app_source, jpegparser, decoder, NULL))

    {
        g_printerr("Elements could not be linked. Exiting.\n");
        return -1;
    }
    if (!gst_element_link_many(streammux, queue2, queue3, queue4, queue5,
                               nvvidconv, NULL)) {
        g_printerr("Elements could not be linked. Exiting.\n");
        return -1;
    }

    if (!gst_element_link_many(nvvidconv, nvosd, sink, NULL)) {
        g_printerr("Elements could not be linked. Exiting.\n");
        return -1;
    }

    GstPad *sinkpad = nullptr, *srcpad = nullptr;
    gchar pad_name_sink[16] = "sink_0";
    gchar pad_name_src[16] = "src";

    sinkpad = gst_element_get_request_pad(streammux, pad_name_sink);
    if (!sinkpad) {
        g_printerr("Streammux request sink pad failed. Exiting.\n");
        return -1;
    }

    srcpad = gst_element_get_static_pad(decoder, pad_name_src);
    if (!srcpad) {
        g_printerr("Decoder request src pad failed. Exiting.\n");
        return -1;
    }

    if (gst_pad_link(srcpad, sinkpad) != GST_PAD_LINK_OK) {
        g_printerr("Failed to link caps filter to stream muxer. Exiting.\n");
        return -1;
    }

    gst_object_unref(sinkpad);
    gst_object_unref(srcpad);

    GST_DEBUG_BIN_TO_DOT_FILE(GST_BIN(pipeline), GST_DEBUG_GRAPH_SHOW_ALL,
                              "pipeline");
    gst_element_set_state(pipeline, GST_STATE_PLAYING);
    g_print("Running...\n");
    g_main_loop_run(loop);
    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));
    g_source_remove(bus_watch_id);
    g_main_loop_unref(loop);
    return 0;
}

can you please check and point out what am I doing wrong ?

also, there is no tiler, so sink should display images from different source one by one right ?

s_pipeline.zip (268.0 KB)

if you need the entire code. it would be here.

Debug logs :-

0:00:51.658073341 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c841b10, maxsize:199751 offset:0 size:199744
0:00:51.658491656 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1c7b6480, we are flushing
could not push buffer0:00:51.684935013 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c8727f0, maxsize:30855 offset:0 size:30848
0:00:51.725737216 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c87a110, maxsize:278535 offset:0 size:278528
0:00:51.749017834 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c8be1b0, maxsize:30663 offset:0 size:30656
0:00:51.788843339 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c8c5a10, maxsize:277927 offset:0 size:277920
0:00:51.807226226 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c909850, maxsize:29575 offset:0 size:29568
0:00:51.842712096 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c910c70, maxsize:199719 offset:0 size:199712
0:00:51.842930982 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1c7b6a20, we are flushing
could not push buffer0:00:51.871850181 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c941930, maxsize:29607 offset:0 size:29600
0:00:51.904874865 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c948d70, maxsize:199751 offset:0 size:199744
0:00:51.905180762 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1c7b6c60, we are flushing
could not push buffer0:00:51.934651304 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c979a50, maxsize:30983 offset:0 size:30976
0:00:51.974834258 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c9813f0, maxsize:279175 offset:0 size:279168
0:00:52.000704128 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c9c5710, maxsize:30663 offset:0 size:30656
0:00:52.040839145 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1c9ccf70, maxsize:277415 offset:0 size:277408
0:00:52.055978715 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ca10bb0, maxsize:29575 offset:0 size:29568
0:00:52.086180860 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ca19000, maxsize:199687 offset:0 size:199680
0:00:52.086727947 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ca18120, we are flushing
could not push buffer0:00:52.128924587 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ca49ca0, maxsize:29607 offset:0 size:29600
0:00:52.160935612 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ca510e0, maxsize:199815 offset:0 size:199808
0:00:52.161168002 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ca18360, we are flushing
could not push buffer0:00:52.188344979 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ca81e00, maxsize:31015 offset:0 size:31008
0:00:52.227608741 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ca897c0, maxsize:279687 offset:0 size:279680
0:00:52.256588550 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cacdce0, maxsize:30567 offset:0 size:30560
0:00:52.295675443 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cad54e0, maxsize:277511 offset:0 size:277504
0:00:52.316614431 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cb19180, maxsize:29607 offset:0 size:29600
0:00:52.349921139 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cb205c0, maxsize:199687 offset:0 size:199680
0:00:52.350716328 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ca187e0, we are flushing
could not push buffer0:00:52.380619617 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cb51260, maxsize:29543 offset:0 size:29536
0:00:52.412919674 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cb58660, maxsize:199623 offset:0 size:199616
0:00:52.413131712 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ca18a20, we are flushing
could not push buffer0:00:52.451086863 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cb892c0, maxsize:31047 offset:0 size:31040
0:00:52.486050031 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cb90ca0, maxsize:279975 offset:0 size:279968
0:00:52.507106654 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cbd52e0, maxsize:30631 offset:0 size:30624
0:00:52.544566240 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cbde000, maxsize:277031 offset:0 size:277024
0:00:52.563830239 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cc21ac0, maxsize:29607 offset:0 size:29600
0:00:52.599314188 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cc28f00, maxsize:199559 offset:0 size:199552
0:00:52.599642517 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ca18ea0, we are flushing
could not push buffer0:00:52.629814550 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cc59b20, maxsize:29543 offset:0 size:29536
0:00:52.661786182 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cc60f20, maxsize:199783 offset:0 size:199776
0:00:52.662731487 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ca18ea0, we are flushing
could not push buffer0:00:52.694086687 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cc91c20, maxsize:31175 offset:0 size:31168
0:00:52.734024963 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cc99680, maxsize:280871 offset:0 size:280864
0:00:52.753930963 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ccde040, maxsize:30471 offset:0 size:30464
0:00:52.792870396 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cce57e0, maxsize:276487 offset:0 size:276480
0:00:52.811747665 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cd29080, maxsize:29607 offset:0 size:29600
0:00:52.844571832 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cd304c0, maxsize:199655 offset:0 size:199648
0:00:52.844799294 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1cbdd5a0, we are flushing
could not push buffer0:00:52.878732867 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cd61140, maxsize:29607 offset:0 size:29600
0:00:52.910184485 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cd68580, maxsize:199527 offset:0 size:199520
0:00:52.910435372 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1cbdd6c0, we are flushing
could not push buffer0:00:52.942992620 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cd99180, maxsize:31271 offset:0 size:31264
0:00:52.982253854 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cda0c40, maxsize:280871 offset:0 size:280864
0:00:53.001562430 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cde5600, maxsize:30471 offset:0 size:30464
0:00:53.040757870 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cdecda0, maxsize:276071 offset:0 size:276064
0:00:53.057631054 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ce304a0, maxsize:29575 offset:0 size:29568
0:00:53.092619950 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ce378c0, maxsize:199751 offset:0 size:199744
0:00:53.092961655 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1cbddc60, we are flushing
could not push buffer0:00:53.128817039 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ce6a000, maxsize:29543 offset:0 size:29536
0:00:53.163231808 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ce71400, maxsize:199591 offset:0 size:199584
0:00:53.163548232 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1cbddea0, we are flushing
could not push buffer0:00:53.187177595 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cea2040, maxsize:31303 offset:0 size:31296
0:00:53.228078041 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cea9b20, maxsize:281319 offset:0 size:281312
0:00:53.258018515 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1ceee6a0, maxsize:30407 offset:0 size:30400
0:00:53.295508566 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cef5e00, maxsize:275271 offset:0 size:275264
^C0:00:53.316862604 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cf391e0, maxsize:29575 offset:0 size:29568
0:00:53.350793969 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cf40600, maxsize:199687 offset:0 size:199680
0:00:53.351049656 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ce69360, we are flushing
could not push buffer0:00:53.383604247 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cf712a0, maxsize:29607 offset:0 size:29600
0:00:53.415175037 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cf786e0, maxsize:199783 offset:0 size:199776
0:00:53.415391907 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ce695a0, we are flushing
could not push buffer0:00:53.439950543 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cfa93e0, maxsize:31303 offset:0 size:31296
0:00:53.480788426 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cfb0ec0, maxsize:281031 offset:0 size:281024
0:00:53.504846281 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cff5920, maxsize:30215 offset:0 size:30208
0:00:53.543813459 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1cffcfc0, maxsize:274919 offset:0 size:274912
0:00:53.578023166 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1d040240, maxsize:29575 offset:0 size:29568
0:00:53.603823435 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1d047660, maxsize:199847 offset:0 size:199840
0:00:53.604294935 106224 0xaaab0fcb3b60 DEBUG                 appsrc gstappsrc.c:2690:gst_app_src_push_internal:<app-source> refuse buffer 0xffff1ce69a20, we are flushing
could not push buffer0:00:53.625146561 106224 0xaaab0fcb3b60 DEBUG             GST_MEMORY gstmemory.c:139:gst_memory_init: new memory 0xffff1d0783a0, maxsize:29543 offset:0 size:29536

deepstream_test3_app.c (24.0 KB)

Since there are a lot of useless codes in your code, I can’t understand the purpose.

I modified deepstream_test3_app.c, put it to /opt/nvidia/deepstream/deepstream/sources/apps/sample_apps/deepstream-test3.

make CUDA_VER=12.2
./deepstream-test3-app image.jpg file:///opt/nvidia/deepstream/deepstream/samples/streams/sample_720p.h264 

image.jpg is pushed to the pipeline through appsrc, and sample_720p.h264 is pushed to uridecodebin.

There is a known issue with frame_num in framemeta

I needed an nvvideoconvert element before streammux in the appsrc branch, it worked after that. The custom made camera that I am using, gives image in some weird format.
Thanks for you help, also, will try to keep my code precise, from next time onward.

also, do you have any idea on the meaning of the logs refuse buffer... we are flushing?

Thanks

I seem to be unable to reproduce it in the sample I provided?

This problem seems to be due to appsrc pending, you can check whether gst_app_src_unlock/gst_app_src_stop is triggered. Capture all logs via GST_DEBUG=3,appsrc:5.

I can run your sample. let me describe the problem more clearly.

Setup One:-
[1] Producer :- this program reads images from a directory and writes them one by one on shared memory.
[2] DS Pipeline :- This pipeline has appsrc and uridecodebin. read_data function of appsrc reads the images from shared memory, creates a buffer out of them and pushes in the pipeline.

This setup works. Both sources work fine.

Setup Two :- Instead of using the producer as above, I have a camera that writes images in shared memory. and again, the appsrc reads images from there. But in this setup, the images from appsrc do not reach pipeline.
What seems to be happening is, the internal queue of appsrc is getting filled.
here is the log of that.

0:00:00.226458123 245716 0xaaab1577c4f0 DEBUG                 appsrc gstappsrc.c:2013:gst_app_src_set_stream_type:<app-source> setting stream_type of 0
0:00:00.226489259 245716 0xaaab1577c4f0 DEBUG                 appsrc gstappsrc.c:2065:gst_app_src_set_max_bytes:<app-source> setting max-bytes to 1000000
0:00:00.227134236 245716 0xaaab1577c4f0 DEBUG                 appsrc gstappsrc.c:853:gst_app_src_internal_get_caps:<app-source> caps: (NULL)
0:00:00.227176317 245716 0xaaab1577c4f0 DEBUG                 appsrc gstappsrc.c:853:gst_app_src_internal_get_caps:<app-source> caps: (NULL)
Now playing: Opening in BLOCKING MODE 
0:00:00.402235199 245716 0xaaab1577c4f0 DEBUG                 appsrc gstappsrc.c:1072:gst_app_src_start:<app-source> starting
0:00:00.403100597 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:853:gst_app_src_internal_get_caps:<app-source> caps: (NULL)
Running...
0:00:00.416486436 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xaaab156607e0
0:00:00.416585383 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 29760 bytes, 1 buffers, 0:00:00.000000000
0:00:00.417593664 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xaaab15660900
0:00:00.417629377 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 59488 bytes, 2 buffers, 0:00:00.077000000
0:00:00.421557700 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xaaab15660c60
0:00:00.421612869 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 89184 bytes, 3 buffers, 0:00:00.245000000
0:00:00.422763810 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xaaab15660d80
0:00:00.422796227 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 118944 bytes, 4 buffers, 0:00:00.326000000
0:00:00.426874409 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805f120
0:00:00.426921706 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 148704 bytes, 5 buffers, 0:00:00.495000000
0:00:00.428067207 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805f240
0:00:00.428154889 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 178464 bytes, 6 buffers, 0:00:00.576000000
0:00:00.432487957 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805f5a0
0:00:00.432532791 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 208224 bytes, 7 buffers, 0:00:00.745000000
0:00:00.434241217 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805f6c0
0:00:00.434269666 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 238016 bytes, 8 buffers, 0:00:00.826000000
0:00:00.437554260 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805fa20
0:00:00.437587157 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 267808 bytes, 9 buffers, 0:00:01.000000000
0:00:00.446881694 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805fb40
0:00:00.446966336 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 297600 bytes, 10 buffers, 0:00:01.076000000
0:00:00.450556538 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff2805fea0
0:00:00.450595995 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 327360 bytes, 11 buffers, 0:00:01.244000000
0:00:00.454085235 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff280d3000
0:00:00.454187797 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 357120 bytes, 12 buffers, 0:00:01.326000000
0:00:00.458973805 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff280d3360
0:00:00.459028431 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 386880 bytes, 13 buffers, 0:00:01.499000000
0:00:00.461603439 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff280d3480
0:00:00.461646384 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 416672 bytes, 14 buffers, 0:00:01.576000000
0:00:00.465114183 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff280d37e0
0:00:00.465258635 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 446400 bytes, 15 buffers, 0:00:01.748000000
0:00:00.466858867 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff280d3900
0:00:00.466982710 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 476192 bytes, 16 buffers, 0:00:01.826000000
0:00:00.471441606 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:2671:gst_app_src_push_internal:<app-source> queueing buffer 0xffff280d3c60
0:00:00.471557512 245716 0xaaab15654360 DEBUG                 appsrc gstappsrc.c:1547:gst_app_src_update_queued_push:<app-source> Currently queued: 505984 bytes, 17 buffers, 0:00:01.998000000  

also, when I checked the pts values of buffers from both the sources, there was a huge difference.
PTS from appsrc : 1723620712177
PTS from uridecodebin: 1387865732

will update you with the logs that you asked for

logs with GST_DEBUG=3,appsrc:5

forum_logs.txt (26.8 KB)

1.Do you mean that the queue of appsrc is always growing?

I think you have given the answer. Try to modify the pts of image which from the appsrc. nvstreammux uses pts when combining multiple streams into a batch.

    GST_BUFFER_PTS (buffer) =
        gst_util_uint64_scale (data->appsrc_frame_num++, GST_SECOND, 30);

2.From the log you provided, it seems that the pipeline is not running properly.

(client:19811): GStreamer-CRITICAL **: 17:30:54.023: gst_element_get_static_pad: assertion 'GST_IS_ELEMENT (element)' failed

(client:19811): GStreamer-CRITICAL **: 17:30:54.023: gst_pad_link_full: assertion 'GST_IS_PAD (sinkpad)' failed
Failed to link pads.

(client:19811): GStreamer-CRITICAL **: 17:30:54.024: gst_object_unref: assertion 'object != NULL' failed
0:00:01.496656336 19811 0xffff0801ede0 ERROR               GST_PADS gstpad.c:3429:gst_pad_query_latency_default:<stream-muxer:src> minimum latency bigger than maximum latency
0:00:01.510322260 19811 0xffff4006af00 WARN                 basesrc gstbasesrc.c:3127:gst_base_src_loop:<udpsrc3> error: Internal data stream error.
0:00:01.510391733 19811 0xffff4006af00 WARN                 basesrc gstbasesrc.c:3127:gst_base_src_loop:<udpsrc3> error: streaming stopped, reason not-linked (-1)

yes I mean queue of appsrc.
also, I tried modifying the PTS of buffers pushed through appsrc.

You can try to make the pts from appsrc branch similar to the uridecodebin branch.

In addition, make sure that appsrc and nvstreammux have been linked successfully. From the .dot and log you provided, it seems there are some errors.

resolved those errors. both streams work fine now. there is a delay in rtsp stream though.

You can try adjusting the properties of nvstreammux, here is a FAQ

okay. thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.