Hello, we are trying to get the NVMM memory buffer from AppSink in a gstreamer pipeline. We saw in the Jetson forums that a suggested method is to call the function ExtractFdFromNvBuffer on the gst mapped buffer to get the NVMM file descriptor. We did so but the function is failing with the following error:
NVMAP_IOC_GET_FD failed: Invalid argument
The return value is 0 (should be -1 for a failure, according to the docs) and the file descriptor ID is set to -24. Those are the caps of the samples received by the AppSink:
video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
The mapped gst buffer has the “size” field set to 64 and the “data” field set to what seems a pointer.
Environment is Orin AGX Dev kit in headless mode. Same issue still persist with a monitor plugged.
Jetpack version in 5.0.2
Can you help us with this issue?
Thanks!
I’ll paste the code, which is a sample taken from the forums, with additional logs added;
#include <cstdlib>
#include <gst/gst.h>
#include <gst/gstinfo.h>
#include <gst/app/gstappsink.h>
#include <glib-unix.h>
#include <dlfcn.h>
#include <iostream>
#include <sstream>
#include <thread>
#include "NvEglRenderer.h"
#include "nvbuf_utils.h"
#include <iostream>
using namespace std;
#define USE(x) ((void)(x))
static GstPipeline* gst_pipeline = nullptr;
static string launch_string;
static int frame_count = 0;
static int sleep_count = 0;
static int eos = 0;
static NvEglRenderer* renderer;
static void appsink_eos(GstAppSink* appsink, gpointer user_data)
{
printf("app sink receive eos\n");
eos = 1;
// g_main_loop_quit (hpipe->loop);
}
static GstFlowReturn new_buffer(GstAppSink* appsink, gpointer user_data)
{
GstSample* sample = NULL;
g_signal_emit_by_name(appsink, "pull-sample", &sample, NULL);
if (sample)
{
GstBuffer* buffer = NULL;
GstCaps* caps = NULL;
GstMapInfo map = { 0 };
int dmabuf_fd = 0;
caps = gst_sample_get_caps(sample);
if (!caps)
{
printf("could not get snapshot format\n");
}
gst_caps_get_structure(caps, 0);
buffer = gst_sample_get_buffer(sample);
gst_buffer_map(buffer, &map, GST_MAP_READ);
std::cout << "New sample received" << std::endl;
int res = ExtractFdFromNvBuffer((void*)map.data, &dmabuf_fd);
std::cout << "Sample Caps: " << gst_caps_to_string(caps) << std::endl;
std::cout << "Buffer mapping, 'size': " << map.size << " 'data': " << (void*)map.data << " 'flags': " << map.flags << " 'maxsize': " << map.maxsize << std::endl;
std::cout << "ExtractFdFromNvBuffer res:" << res << " dmabuf_fd: " << dmabuf_fd << std::endl;
std::cout << std::endl;
//renderer->render(dmabuf_fd);
frame_count++;
gst_buffer_unmap(buffer, &map);
gst_sample_unref(sample);
}
else
{
g_print("could not make snapshot\n");
}
return GST_FLOW_OK;
}
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;
GstAppSinkCallbacks callbacks = { appsink_eos, NULL, new_buffer };
launch_stream << "filesrc location=/home/va/test.mp4 ! decodebin ! appsink name=mysink ";
launch_string = launch_stream.str();
g_print("Using launch string: %s\n", launch_string.c_str());
GError* error = nullptr;
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);
GstElement* appsink_ = gst_bin_get_by_name(GST_BIN(gst_pipeline), "mysink");
gst_app_sink_set_callbacks(GST_APP_SINK(appsink_), &callbacks, NULL, NULL);
//renderer = NvEglRenderer::createEglRenderer("renderer0",w, h, 0, 0);
//renderer->setFPS(24);
gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_PLAYING);
while (eos == 0) {
sleep(1);
sleep_count++;
}
//sleep(90);
//g_main_loop_run (main_loop);
gst_element_set_state((GstElement*)gst_pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(gst_pipeline));
g_main_loop_unref(main_loop);
//delete renderer;
g_print("going to exit, decode %d frames in %d seconds \n", frame_count, sleep_count);
return 0;
}
and those are the logs printed:
Using launch string: filesrc location=/home/va/test.mp4 ! decodebin ! appsink name=mysink
Opening in BLOCKING MODE
NvMMLiteOpen : Block : BlockType = 261
NVMEDIA: Reading vendor.tegra.display-size : status: 6
NvMMLiteBlockCreate : Block : BlockType = 261
New sample received
NVMAP_IOC_GET_FD failed: Bad file descriptor
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8015feb0 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff80169ad0 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8016a260 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8016a9f0 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff80169340 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8016b910 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8016c0a0 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8016c830 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Invalid argument
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8016b180 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24
New sample received
NVMAP_IOC_GET_FD failed: Bad file descriptor
Sample Caps: video/x-raw(memory:NVMM), format=(string)NV12, width=(int)1920, height=(int)1080, interlace-mode=(string)progressive, multiview-mode=(string)mono, multiview-flags=(GstVideoMultiviewFlagsSet)0:ffffffff:/right-view-first/left-flipped/left-flopped/right-flipped/right-flopped/half-aspect/mixed-mono, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)bt709, framerate=(fraction)25/1
Buffer mapping, 'size': 64 'data': 0xffff8015feb0 'flags': 1 'maxsize': 2088960
ExtractFdFromNvBuffer res:0 dmabuf_fd: -24