LibArgus EGLStream to nvivafilter

Reference patch and steps for r32.5.1:

  1. Run the script to re-install OpenCV:
    JEP/install_opencv4.5.0_Jetson.sh at master · AastaNV/JEP · GitHub
  2. Apply the patch and rebuild 00_video_code:
diff --git a/multimedia_api/ll_samples/samples/00_video_decode/Makefile b/multimedia_api/ll_samples/samples/00_video_decode/Makefile
index 06239b1..f5dc104 100644
--- a/multimedia_api/ll_samples/samples/00_video_decode/Makefile
+++ b/multimedia_api/ll_samples/samples/00_video_decode/Makefile
@@ -39,18 +39,30 @@ SRCS := \
 
 OBJS := $(SRCS:.cpp=.o)
 
+OBJS += \
+	$(ALGO_CUDA_DIR)/NvAnalysis.o \
+	$(ALGO_CUDA_DIR)/NvCudaProc.o
+
+CVLDFLAGS:=`pkg-config --libs opencv4`
+
 all: $(APP)
 
 $(CLASS_DIR)/%.o: $(CLASS_DIR)/%.cpp
 	$(AT)$(MAKE) -C $(CLASS_DIR)
 
+$(ALGO_CUDA_DIR)/%.o: $(ALGO_CUDA_DIR)/%.cpp
+	$(AT)$(MAKE) -C $(ALGO_CUDA_DIR)
+
+$(ALGO_CUDA_DIR)/%.o: $(ALGO_CUDA_DIR)/%.cu
+	$(AT)$(MAKE) -C $(ALGO_CUDA_DIR)
+
 %.o: %.cpp
 	@echo "Compiling: $<"
 	$(CPP) $(CPPFLAGS) -c $<
 
 $(APP): $(OBJS)
 	@echo "Linking: $@"
-	$(CPP) -o $@ $(OBJS) $(CPPFLAGS) $(LDFLAGS)
+	$(CPP) -o $@ $(OBJS) $(CPPFLAGS) $(LDFLAGS) $(CVLDFLAGS)
 
 clean:
 	$(AT)rm -rf $(APP) $(OBJS)
diff --git a/multimedia_api/ll_samples/samples/00_video_decode/video_decode_main.cpp b/multimedia_api/ll_samples/samples/00_video_decode/video_decode_main.cpp
index d2dedf5..10befa6 100644
--- a/multimedia_api/ll_samples/samples/00_video_decode/video_decode_main.cpp
+++ b/multimedia_api/ll_samples/samples/00_video_decode/video_decode_main.cpp
@@ -42,6 +42,7 @@
 
 #include "video_decode.h"
 #include "nvbuf_utils.h"
+#include "NvCudaProc.h"
 
 #define TEST_ERROR(cond, str, label) if(cond) { \
                                         cerr << str << endl; \
@@ -616,6 +617,7 @@ query_and_set_capture(context_t * ctx)
 
     input_params.nvbuf_tag = NvBufferTag_VIDEO_CONVERT;
 
+    input_params.colorFormat = NvBufferColorFormat_ABGR32;
     ret = NvBufferCreateEx (&ctx->dst_dma_fd, &input_params);
     TEST_ERROR(ret == -1, "create dmabuf failed", error);
 #else
@@ -1173,6 +1175,12 @@ dec_capture_loop_fcn(void *arg)
 
                 if (!ctx->stats && !ctx->disable_rendering)
                 {
+
+                    EGLImageKHR egl_image = NULL;
+                    egl_image = NvEGLImageFromFd(ctx->renderer->getEGLDisplay(), ctx->dst_dma_fd);
+                    HandleEGLImage(&egl_image);
+                    NvDestroyEGLImage(ctx->renderer->getEGLDisplay(), egl_image);
+
                     ctx->renderer->render(ctx->dst_dma_fd);
                 }
 
diff --git a/multimedia_api/ll_samples/samples/common/algorithm/cuda/Makefile b/multimedia_api/ll_samples/samples/common/algorithm/cuda/Makefile
index dc40f07..75b7d45 100644
--- a/multimedia_api/ll_samples/samples/common/algorithm/cuda/Makefile
+++ b/multimedia_api/ll_samples/samples/common/algorithm/cuda/Makefile
@@ -39,6 +39,8 @@ ifneq ($(CUDA_DEBUG),)
 NVCCFLAGS += -g -G
 endif
 
+CVCCFLAGS:=`pkg-config --cflags opencv4`
+
 # Filter C++11 to workaround cuda compilation error
 ALL_CPPFLAGS := $(NVCCFLAGS)
 ALL_CPPFLAGS += $(addprefix -Xcompiler ,$(filter-out -std=c++11, $(CPPFLAGS)))
@@ -59,7 +61,7 @@ NvAnalysis.o : NvAnalysis.cu
 
 NvCudaProc.o : NvCudaProc.cpp
 	@echo "Compiling: $<"
-	$(NVCC) $(ALL_CPPFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
+	$(NVCC) $(ALL_CPPFLAGS) $(CVCCFLAGS) $(GENCODE_FLAGS) -o $@ -c $<
 
 clean:
 	$(AT)rm -rf *.o
diff --git a/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvCudaProc.cpp b/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvCudaProc.cpp
index 64f058f..369cbb6 100644
--- a/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvCudaProc.cpp
+++ b/multimedia_api/ll_samples/samples/common/algorithm/cuda/NvCudaProc.cpp
@@ -28,6 +28,8 @@
 
 #include <stdio.h>
 #include <cuda_runtime_api.h>
+#include <opencv2/opencv.hpp>
+#include <opencv2/cudafilters.hpp>
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
 #include <GLES2/gl2.h>
@@ -41,6 +43,21 @@
 
 #include "NvCudaProc.h"
 
+static bool create_filter = true;
+cv::Ptr< cv::cuda::Filter > filter;
+
+static void cv_process(void *pdata, int32_t width, int32_t height)
+{
+    if (create_filter) {
+        //filter = cv::cuda::createSobelFilter(CV_8UC4, CV_8UC4, 1, 0, 3, 1, cv::BORDER_DEFAULT);
+        filter = cv::cuda::createGaussianFilter(CV_8UC4, CV_8UC4, cv::Size(31,31), 0, 0, cv::BORDER_DEFAULT);
+        create_filter = false;
+    }
+    cv::cuda::GpuMat d_mat(height, width, CV_8UC4, pdata);
+    filter->apply (d_mat, d_mat);
+}
+
+
 static void
 Handle_EGLImage(EGLImageKHR image);
 
@@ -89,7 +106,7 @@ Handle_EGLImage(EGLImageKHR image)
     if (eglFrame.frameType == CU_EGL_FRAME_TYPE_PITCH)
     {
         //Rect label in plan Y, you can replace this with any cuda algorithms.
-        addLabels((CUdeviceptr) eglFrame.frame.pPitch[0], eglFrame.pitch);
+        cv_process(eglFrame.frame.pPitch[0], eglFrame.width, eglFrame.height);
     }
 
     status = cuCtxSynchronize();
  1. Run
$ sudo ldconfig
$ export DISPLAY=:0(or 1)
$ ./video_decode H264 ../../data/Video/sample_outdoor_car_1080p_10fps.h264