GStreamer C++ nvarguscamerasrc

Hello guys,
we are having a problem with nvarguscamerasrc when running from GStreamer C++. (gst-launch-1.0 works good)

I have my camera src pipeline which is connected with interpipes to other pipelines which display and save to file. Anyway, setting my pipeline to NULL_STATE atfer playing and then to PLAYING_STATE again gives me the following error:

GST_ARGUS: Running with following settings:
Camera index = 1
Camera mode = 0
Output Stream W = 3872 H = 2192
seconds to Run = 0
Frame Rate = 25.999999
GST_ARGUS: Setup Complete, Starting captures for 0 seconds
GST_ARGUS: Starting repeat capture requests.
CONSUMER: Producer has connected; continuing.
nvbuf_utils: dmabuf_fd -1 mapped entry NOT found
nvbuf_utils: Can not get HW buffer from FD… Exiting…

I can rerun the program and everything is working fine again, but I cannot stop and play the pipeline while running.

My pipeline creation:

nvarguscamerasrc = gst_element_factory_make(“nvarguscamerasrc”, “nvarguscamerasrc”);
cam_src = gst_element_factory_make(“interpipesink”, “cam_src”);
vid_xraw = gst_element_factory_make(“capsfilter”, “vid_xraw”);
pipeline = gst_pipeline_new(“pipeline”);

if (!pipeline ||  !cam_src || !nvarguscamerasrc ||
    !vid_xraw ) {
    g_printerr ("Not all elements could be created.\n");
    return;
}

gst_bin_add_many (GST_BIN (pipeline), nvarguscamerasrc, vid_xraw, cam_src, NULL);

if(gst_element_link_many(nvarguscamerasrc, vid_xraw, cam_src, NULL) != TRUE){
    g_printerr ("Elements could not be linked.\n");
    gst_object_unref (pipeline);
    return;
}

g_object_set(nvarguscamerasrc, "saturation", 2.0, "aeantibanding", 0, "sensor-id", 1, NULL);
g_object_set(cam_src, "sync", FALSE, "async", FALSE, NULL);


filtercaps = gst_caps_from_string("video/x-raw(memory:NVMM), width=(int)3840, height=(int)2160, format=(string)NV12, framerate=(fraction)26/1");
g_object_set(G_OBJECT (vid_xraw), "caps", filtercaps, NULL);
gst_caps_unref(filtercaps);

Can you help me with that?
Best regards,
jb

Hi,
The case of switching to NULL and back to PLAYING states is not verified. We suggest unref the pipeline and launch a new one in the C++ code.

Hey, thanks for your fast response!
I already did this: The error remains.

gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref(pipeline);

Hi,
We don’t observe the issue in running the sample:

#include <cstdlib>
#include <cstring>
#include <sstream>
#include <gst/gst.h>

using namespace std;

#define USE(x) ((void)(x))

static GstPipeline *gst_pipeline = nullptr;
static string launch_string;

GstClockTime usec = 1000000;
static int w = 1920;
static int h = 1080;

int main(int argc, char** argv) {
    USE(argc);
    USE(argv);

    gst_init (&argc, &argv);

    GMainLoop *main_loop;
    main_loop = g_main_loop_new (NULL, FALSE);
    ostringstream launch_stream;
    GstBus *bus;

    launch_stream
    << "nvarguscamerasrc name=mysource ! "
    << "video/x-raw(memory:NVMM),width="<< w <<",height="<< h <<",framerate=30/1,format=NV12 ! "
    << "fakesink ";

    launch_string = launch_stream.str();

    g_print("Using launch string: %s\n", launch_string.c_str());

    GError *error = nullptr;
for(guint i=0; i<10; i++) {
    g_print("loop= %d \n", i);
    gst_pipeline  = (GstPipeline*) gst_parse_launch(launch_string.c_str(), &error);

    if (gst_pipeline == nullptr) {
        g_print( "Failed to parse launch: %s\n", error->message);
        return -1;
    }
    if(error) g_error_free(error);

    gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_PLAYING); 
    g_usleep(5*usec);
    gst_element_send_event ((GstElement*)gst_pipeline, gst_event_new_eos ());
    // Wait for EOS message
    bus = gst_pipeline_get_bus(GST_PIPELINE(gst_pipeline));
    gst_bus_poll(bus, GST_MESSAGE_EOS, GST_CLOCK_TIME_NONE);
    gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL);

    gst_object_unref(GST_OBJECT(gst_pipeline));
    g_usleep(1*usec);
}
    g_main_loop_unref(main_loop);

    g_print("going to exit \n");
    return 0;
}

Please give it a try.

I will try your example, and then apply my pipeline to it and see what happens. I feel like the problem might come from interpipe I am using. Let’s see!

Hey,
sorry I got back to you so late.

Using your example the nvarguscamerasrc can be restarted fine!

gst_element_send_event ((GstElement*)gst_pipeline, gst_event_new_eos ());
// Wait for EOS message
bus = gst_pipeline_get_bus(GST_PIPELINE(gst_pipeline));
gst_bus_poll(bus, GST_MESSAGE_EOS, GST_CLOCK_TIME_NONE);
gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL);

Sending EOS before setting STATE to NULL seemed to be the missing piece!

This way the nvarguscamerasrc can be restarted. But using RidgeRun interpipe in my pipelines does not work this way. Interpipesink after nvarguscamerasrc und interpipesrc before nvdrmvideosink cannot be restarted.

Maybe guys from RidgeRun can help me out?

nvarguscamerasrc → interpipesink
interpipesink → nvdrmvideosink

Best regards,
jb

Hi,
Looks like the plugins are developed by 3rdparty. You may contact the vendor to get further support.