Improper process shutdown after linking nvjpeg

Hello,

I am running into a rather strange issue on the Xavier. I have written a C++ application for video processing that runs without many issues, however I recently added hardware accelerated jpeg encoding/decoding support via nvjpeg and tegra_multimedia_api. To summarize the problem as simply as I can:

Compiled with:

CMake, GCC 7.4.0, C++17 support

Without linking nvjpeg the application has no issues handling SIGINT and SIGTERM and shuts down correctly. However when nvjpeg is linked, as soon as SIGINT/SIGTERM are received the application immediately terminates. This is an issue as there are a lot of steps to perform a clean shutdown of my application.

Does anyone know why this would be happening? I have narrowed the problem down to simply linking nvjpeg without including any of the tegra_multimedia_api source code.

This is the last thing that I get from strace:

futex(0x7fb6ac23f0, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x7f72316ea0, FUTEX_WAIT, 17893, NULL) = ?
+++ killed by SIGTERM +++

Hi,
Please check if you can share a patch on 05_jpeg_encode, or 06_jpeg_decode, to reproduce the issue.
For more information, do you use r32.1 or r32.2?

I have modified 06_jpeg_decode to loop until a signal is received and it appears to work just fine. Wondering if it is maybe caused by linking nvjpeg in combination with another library I may be using.

I am running r32.1 currently.

Hi,
The samples are maintained and verified in each release. If you still suffer the issue and suspect it is something wrong in our software stack, please try to reproduce it with these samples and share us the patch and steps. Thanks.

Hello again,

I was able to reproduce the error in r32.2 using a modified version of 06_jpeg_decode. The application immediately terminates instead of properly shutting down. Let me know if you have any questions. The reason I was unable to reproduce the issue before was an unrelated problem.

Here is the code:

/*
 * Copyright (c) 2016-2017, NVIDIA CORPORATION. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *  * Neither the name of NVIDIA CORPORATION nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include "NvUtils.h"
#include <errno.h>
#include <fstream>
#include <iostream>
#include <malloc.h>
#include <csignal>
#include <string.h>
#include <thread>
#include <unistd.h>

#include "jpeg_decode.h"

#define TEST_ERROR(cond, str, label) if(cond) { \
                                        cerr << str << endl; \
                                        error = 1; \
                                        goto label; }

using namespace std;

static bool running = true;

static void
abort(context_t * ctx)
{
    ctx->got_error = true;
    ctx->conv->abort();
}

static bool
conv_capture_dqbuf_thread_callback(struct v4l2_buffer *v4l2_buf,
                                   NvBuffer * buffer, NvBuffer * shared_buffer,
                                   void *arg)
{
    context_t *ctx = (context_t *) arg;

    if (!v4l2_buf)
    {
        cerr << "Failed to dequeue buffer from conv capture plane" << endl;
        abort(ctx);
        return false;
    }

    write_video_frame(ctx->out_file[ctx->current_file++], *buffer);
    return false;
}

static uint64_t
get_file_size(ifstream * stream)
{
    uint64_t size = 0;
    streampos current_pos = stream->tellg();
    stream->seekg(0, stream->end);
    size = stream->tellg();
    stream->seekg(current_pos, stream->beg);
    return size;
}

static void
set_defaults(context_t * ctx)
{
    memset(ctx, 0, sizeof(context_t));
    ctx->use_fd = true;
    ctx->stress_test = 1;
    ctx->current_file = 0;
}

static int
jpeg_decode_proc(context_t& ctx, int argc, char *argv[])
{
    int ret = 0;
    int error = 0;
    int fd = 0;
    uint32_t width, height, pixfmt;
    int i = 0;

    set_defaults(&ctx);

    ret = parse_csv_args(&ctx, argc, argv);
    TEST_ERROR(ret < 0, "Error parsing commandline arguments", cleanup);

    for(i = 0; i < ctx.num_files; i++)
    {
      ctx.in_file[i] = new ifstream(ctx.in_file_path[i]);
      TEST_ERROR(!ctx.in_file[i]->is_open(), "Could not open input file", cleanup);

      ctx.out_file[i] = new ofstream(ctx.out_file_path[i]);
      TEST_ERROR(!ctx.out_file[i]->is_open(), "Could not open output file", cleanup);
    }

    ctx.jpegdec = NvJPEGDecoder::createJPEGDecoder("jpegdec");
    TEST_ERROR(!ctx.jpegdec, "Could not create Jpeg Decoder", cleanup);

    for(i = 0; i < ctx.num_files; i++)
    {
      ctx.in_file_size = get_file_size(ctx.in_file[i]);
      ctx.in_buffer = new unsigned char[ctx.in_file_size];
      ctx.in_file[i]->read((char *) ctx.in_buffer, ctx.in_file_size);

      if (!ctx.use_fd)
      {
        NvBuffer *buffer;
        ret = ctx.jpegdec->decodeToBuffer(&buffer, ctx.in_buffer,
            ctx.in_file_size, &pixfmt, &width, &height);
        TEST_ERROR(ret < 0, "Could not decode image", cleanup);
        cout << "Image Resolution - " << width << " x " << height << endl;
        write_video_frame(ctx.out_file[i], *buffer);
        delete buffer;
        goto cleanup;
      }

      ctx.conv = NvVideoConverter::createVideoConverter("conv");
      TEST_ERROR(!ctx.conv, "Could not create Video Converter", cleanup);

      ret = ctx.jpegdec->decodeToFd(fd, ctx.in_buffer, ctx.in_file_size, pixfmt,
          width, height);
      TEST_ERROR(ret < 0, "Could not decode image", cleanup);
      cout << "Image Resolution - " << width << " x " << height << endl;

      ret = ctx.conv->setCropRect(0, 0, width, height);
      TEST_ERROR(ret < 0, "Could not set crop rect for conv0", cleanup);

      // Set conv output plane format
      ret =
        ctx.conv->setOutputPlaneFormat(pixfmt, width,
            height, V4L2_NV_BUFFER_LAYOUT_PITCH);
      TEST_ERROR(ret < 0, "Could not set output plane format for conv", cleanup);

      // Set conv capture plane format
      ret =
        ctx.conv->setCapturePlaneFormat(pixfmt, width,
            height,
            V4L2_NV_BUFFER_LAYOUT_PITCH);
      TEST_ERROR(ret < 0, "Could not set capture plane format for conv", cleanup);

      // REQBUF, EXPORT and MAP conv output plane buffers
      ret = ctx.conv->output_plane.setupPlane(V4L2_MEMORY_DMABUF, 1, false, false);
      TEST_ERROR(ret < 0, "Error while setting up output plane for conv",
          cleanup);

      // REQBUF and EXPORT conv capture plane buffers
      // No need to MAP since buffer will be shared to next component
      // and not read in application
      ret =
        ctx.conv->capture_plane.setupPlane(V4L2_MEMORY_MMAP, 1,
            true, false);
      TEST_ERROR(ret < 0, "Error while setting up capture plane for conv",
          cleanup);

      // conv output plane STREAMON
      ret = ctx.conv->output_plane.setStreamStatus(true);
      TEST_ERROR(ret < 0, "Error in output plane streamon for conv", cleanup);

      // conv capture plane STREAMON
      ret = ctx.conv->capture_plane.setStreamStatus(true);
      TEST_ERROR(ret < 0, "Error in capture plane streamon for conv", cleanup);

      ctx.conv->
        capture_plane.setDQThreadCallback(conv_capture_dqbuf_thread_callback);

      // Start threads to dequeue buffers on conv capture plane
      ctx.conv->capture_plane.startDQThread(&ctx);

      // Enqueue all empty conv capture plane buffers
      for (uint32_t i = 0; i < ctx.conv->capture_plane.getNumBuffers(); i++)
      {
        struct v4l2_buffer v4l2_buf;
        struct v4l2_plane planes[MAX_PLANES];

        memset(&v4l2_buf, 0, sizeof(v4l2_buf));
        memset(planes, 0, MAX_PLANES * sizeof(struct v4l2_plane));

        v4l2_buf.index = i;
        v4l2_buf.m.planes = planes;

        ret = ctx.conv->capture_plane.qBuffer(v4l2_buf, NULL);
        if (ret < 0)
        {
          cerr << "Error while queueing buffer at conv capture plane" << endl;
          abort(&ctx);
          goto cleanup;
        }
      }

      {
        struct v4l2_buffer v4l2_buf;
        struct v4l2_plane planes[MAX_PLANES];

        memset(&v4l2_buf, 0, sizeof(v4l2_buf));
        memset(planes, 0, MAX_PLANES * sizeof(struct v4l2_plane));

        v4l2_buf.index = 0;
        v4l2_buf.m.planes = planes;
        planes[0].m.fd = fd;
        planes[0].bytesused = 1234;

        ret = ctx.conv->output_plane.qBuffer(v4l2_buf, NULL);
        if (ret < 0)
        {
          cerr << "Error while queueing buffer at conv output plane" << endl;
          abort(&ctx);
          goto cleanup;
        }
      }

      // Wait till all capture plane buffers on conv are dequeued
      ctx.conv->capture_plane.waitForDQThread(2000);

cleanup:
      if (ctx.conv && ctx.conv->isInError())
      {
        cerr << "VideoConverter is in error" << endl;
        error = 1;
      }

      if (ctx.got_error)
      {
        error = 1;
      }
      delete ctx.conv;
      delete[] ctx.in_buffer;
    }

    for(i = 0; i < ctx.num_files; i++)
    {

      delete ctx.in_file[i];
      delete ctx.out_file[i];

      free(ctx.in_file_path[i]);
      free(ctx.out_file_path[i]);
    }
    // Destructors do all the cleanup, unmapping and deallocating buffers
    // and calling v4l2_close on fd
    delete ctx.jpegdec;

    return -error;
}

void signalHandler(sigset_t* set)
{
    int sig;
    sigwait(set, &sig);

    std::cout << "Got signal " << sig << "... terminating application..." << std::endl;

    running = false;
}

  int
main(int argc, char *argv[])
{
    context_t ctx;
    int ret = 0;
    int iterator_num = 0; //save iterator number

    std::thread signalThread;

    sigset_t set;

    sigemptyset(&set);
    sigaddset(&set, SIGQUIT);
    sigaddset(&set, SIGINT);
    sigaddset(&set, SIGTERM);

    pthread_sigmask(SIG_BLOCK, &set, nullptr);

    signalThread = std::thread(&signalHandler, &set);

    do
    {
        ret = jpeg_decode_proc(ctx, argc, argv);
        iterator_num++;
    } while(running && ret == 0);

    if (ret)
    {
        cout << "App run failed" << endl;
    }
    else
    {
        cout << "App run was successful" << endl;
    }

    signalThread.join();

    return ret;
}

Hi,
We will build/run the test code to reproduce the issue.

Hi nr94,

I compiler your code and run below pipeline, repeat output “Image Resolution” message, is it expected result?

$ ./jpeg_decode num_files 1 /usr/src/tegra_multimedia_api/data/Picture/nvidia-logo.jpg /home/nvidia/test-user.yuv --decode-buffer
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080

If yes, how long are you reproduce issue? Thanks!

Hello,

The modifications I made to the code make it loop forever until a signal is sent to the process. The expected result when sending SIGINT would be that running is set to false, the main loop exits, and “App run was successful” is printed to stdout. However, instead of printing anything the application immediately terminates when a signal is received.

Let me know if you have any other questions.

Hi nr94,

Looks I can’t repro your issue.
Running about 10 mins and press ctrl+c to stop, I can get “App run was successful” and no panic or any errors in log.

Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
Image Resolution - 1920 x 1080
^CGot signal 2... terminating application...
Image Resolution - 1920 x 1080
App run was successful

Looks like my output looks a bit different when running. Here is what I get:

./jpeg_decode num_files 1 Nick.jpg decoded.out
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 2320 x 3088
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
^C

Hi nr94,

I’m using 1920x1080 jpg file and remove “–decode-buffer” option, I can see the same output:

$ ./jpeg_decode num_files 1 /usr/src/tegra_multimedia_api/data/Picture/nvidia-logo.jpg /home/nvidia/1004.yuv
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
^CGot signal 2... terminating application...
App run was successful

Could you share your “Nick.jpg” 2320x3088 file?
We can try to reproduce issue and figure out it’s file issue or not. Thanks!

This is very puzzling. Here is my output when I run the same command as you. Perhaps there is something else we should look at? I flashed 4.2.2 on this device about two weeks ago so I am not sure what would be different outside of packages I’ve installed.

./jpeg_decode num_files 1 /usr/src/tegra_multimedia_api/data/Picture/nvidia-logo.jpg 1004.yuv
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
^C

Hi nr94,

I’m using pure JetPack-4.2.2, it’s no problem.
Suggest you can check your image or flash pure JetPack again. Thanks!

Hello again,

I have freshly flashed 4.2.2 on a new Xavier and tested the issue again. I did not install any additional packages. I see the exact same behavior. I have attached a log below showing my steps

root@nvidia-desktop:/usr/src/tegra_multimedia_api/samples/06_jpeg_decode# make clean
root@nvidia-desktop:/usr/src/tegra_multimedia_api/samples/06_jpeg_decode# make
Compiling: jpeg_decode_csvparser.cpp
Compiling: jpeg_decode_main.cpp
make[1]: Entering directory '/usr/src/tegra_multimedia_api/samples/common/classes'
Compiling: NvElementProfiler.cpp
Compiling: NvElement.cpp
Compiling: NvApplicationProfiler.cpp
Compiling: NvVideoDecoder.cpp
Compiling: NvJpegEncoder.cpp
Compiling: NvVideoConverter.cpp
Compiling: NvBuffer.cpp
Compiling: NvLogging.cpp
Compiling: NvEglRenderer.cpp
Compiling: NvUtils.cpp
Compiling: NvDrmRenderer.cpp
Compiling: NvJpegDecoder.cpp
Compiling: NvVideoEncoder.cpp
Compiling: NvV4l2ElementPlane.cpp
Compiling: NvV4l2Element.cpp
make[1]: Leaving directory '/usr/src/tegra_multimedia_api/samples/common/classes'
Linking: jpeg_decode
root@nvidia-desktop:/usr/src/tegra_multimedia_api/samples/06_jpeg_decode# ll
total 548
drwxr-xr-x  2 root root   4096 Oct 16 12:04 ./
drwxr-xr-x 20 root root   4096 Oct 13 18:46 ../
-rwxr-xr-x  1 root root 426288 Oct 16 12:04 jpeg_decode*
-rw-r--r--  1 root root   5025 Oct 13 18:46 jpeg_decode_csvparser.cpp
-rw-r--r--  1 root root   9544 Oct 16 12:03 jpeg_decode_csvparser.o
-rw-r--r--  1 root root   2215 Oct 13 18:46 jpeg_decode.h
-rw-r--r--  1 root root   9463 Oct 16 12:03 jpeg_decode_main.cpp
-rw-r--r--  1 root root   8944 Oct 16 11:57 jpeg_decode_main.cpp.bak
-rw-r--r--  1 root root  65704 Oct 16 12:03 jpeg_decode_main.o
-rw-r--r--  1 root root   2125 Oct 13 18:46 Makefile
root@nvidia-desktop:/usr/src/tegra_multimedia_api/samples/06_jpeg_decode# gcc --version
gcc (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

root@nvidia-desktop:/usr/src/tegra_multimedia_api/samples/06_jpeg_decode# ./jpeg_decode num_files 1 /usr/src/tegra_multimedia_api/data/Picture/nvidia-logo.jpg /home/nvidia/1004.yuv
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
Image Resolution - 1920 x 1080
libv4l2_nvvidconv (0):(802) (INFO) : Allocating (1) OUTPUT PLANE BUFFERS Layout=0
libv4l2_nvvidconv (0):(818) (INFO) : Allocating (1) CAPTURE PLANE BUFFERS Layout=0
^C
root@nvidia-desktop:/usr/src/tegra_multimedia_api/samples/06_jpeg_decode# cat /etc/nv_tegra_release 
# R32 (release), REVISION: 2.1, GCID: 16294929, BOARD: t186ref, EABI: aarch64, DATE: Tue Aug 13 04:45:36 UTC 2019
629aafd8e377e23a02a7b1b72e7002d275eaf4ff */usr/lib/xorg/modules/extensions/libglxserver_nvidia.so
2c73b76ce1f33fad884d8461a91b48b41d705ceb */usr/lib/xorg/modules/drivers/nvidia_drv.so
c1e97836b26beddc0d1e95e2b71d166a573d8476 */usr/lib/aarch64-linux-gnu/tegra/libnvmm_parser.so
5d2f29678eda3641466f089ce7919b593fa19a47 */usr/lib/aarch64-linux-gnu/tegra/libnvphs.so
73b83f680bc52d62758eece9ef265710cfbb4f81 */usr/lib/aarch64-linux-gnu/tegra/libnvmm_contentpipe.so
3ce22114c0709424e2ed9955f4712eeaf02e90ed */usr/lib/aarch64-linux-gnu/tegra/libnvscf.so
27f705a18f7a8adbe29a4fe69d810e91e7f944f4 */usr/lib/aarch64-linux-gnu/tegra/libnvfnetstorehdfx.so
a78b7833bef896fa091953bd82d97cdd79e3759f */usr/lib/aarch64-linux-gnu/tegra/libnvodm_imager.so
bb35942445d997f648f2931e517dbe771535b159 */usr/lib/aarch64-linux-gnu/tegra/libnvfnetstoredefog.so
ac8f9892a7ee6f5def88d32da7368bb9c5dddd3e */usr/lib/aarch64-linux-gnu/tegra/libnvtvmr.so
fc46da4b539590229e1428cc354e190fc6bdb401 */usr/lib/aarch64-linux-gnu/tegra/libv4l2_nvvideocodec.so
048550a2b6ec751b71328b5375dac25c4915bdf4 */usr/lib/aarch64-linux-gnu/tegra/libnvvulkan-producer.so
7cc1df004d4004212076c0a1375dc6cf6b20299d */usr/lib/aarch64-linux-gnu/tegra/libnvddk_2d_v2.so
0530975bdacc74c8abf3b7bae5ad076e3a0ddad8 */usr/lib/aarch64-linux-gnu/tegra/libnveglstream_camconsumer.so
c3e7ff77c6d107385c5505c7ddb6e12280b4e0e3 */usr/lib/aarch64-linux-gnu/tegra/libtegrav4l2.so
8034a43900953ec5fed13102cf36ced56fdfd496 */usr/lib/aarch64-linux-gnu/tegra/libnvtracebuf.so
d2f179c30e458928ae287e629f24567cbc3372d8 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_boot.so
65436dbfd7a5ba89366b35adb975b0e938adcd62 */usr/lib/aarch64-linux-gnu/tegra/libnvos.so
6571c21ece0ab134d0bff265b59bdc608f814df1 */usr/lib/aarch64-linux-gnu/tegra/libnvmedia.so
7da9c8ae9334c94949746bf09412971af2d2ffe7 */usr/lib/aarch64-linux-gnu/tegra/libnvtestresults.so
67b9b42721ac0012b90f1723a89470025fb24ad1 */usr/lib/aarch64-linux-gnu/tegra/libnvmm.so
19cb5560a289e1eabb0ed0c30420c8b32323b897 */usr/lib/aarch64-linux-gnu/tegra/libnvwinsys.so
c5013222163ad7143f9d2467be33e39552d73bf7 */usr/lib/aarch64-linux-gnu/tegra/libnvmmlite_video.so
42c7dd60e5c7b8cb30066ffe6e5ab8b2d406e8a3 */usr/lib/aarch64-linux-gnu/tegra/libnvmmlite_utils.so
80f62304114a4d4451a1afa872cb59e59baa296c */usr/lib/aarch64-linux-gnu/tegra/libnvisp_utils.so
6f655a98f596f2e71ee4750bb8eb53e972eff3c4 */usr/lib/aarch64-linux-gnu/tegra/libnvddk_vic.so
f4d16dddcc4aadecaac250fefe3b60f9e7b606a3 */usr/lib/aarch64-linux-gnu/tegra/libnvidia-egl-wayland.so
13967ec85f3c66ad98e8862215264736e3937f07 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_il.so
a4239abeabbb436468321f2a24337eab067adcf0 */usr/lib/aarch64-linux-gnu/tegra/libv4l2_nvvidconv.so
0e7d38ad840668a9ca21dffd90c02f3807e657de */usr/lib/aarch64-linux-gnu/tegra/libnvdc.so
32f4b6d5ee5c56706de37900e7dd0004567c2252 */usr/lib/aarch64-linux-gnu/tegra/libnvdla_compiler.so
e73ea22ab4a1368177848a7fe80bcffc2e226079 */usr/lib/aarch64-linux-gnu/tegra/libnvosd.so
15e2a6414e9c85b675f77fd2a3d4f8a4399552ee */usr/lib/aarch64-linux-gnu/tegra/libnvomxilclient.so
d6a33e96ad7519a1d20ec8926134c43f209a04bc */usr/lib/aarch64-linux-gnu/tegra/libnvtnr.so
f3a811fabb1b5f715b19f3fa4eed63f38a7fee6f */usr/lib/aarch64-linux-gnu/tegra/libnvcamerautils.so
a81f32fe01b50f00f568ac97baedb2daa65bf38b */usr/lib/aarch64-linux-gnu/tegra/libnvparser.so
95ab307a692bcf90195b983b48d4a3adeb74c9c2 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_force.so
551ab635345a69ec4152cd08e346cd167a58f0b4 */usr/lib/aarch64-linux-gnu/tegra/libnveventlib.so
e6adad044852376a7a5f27b6b8ac671434c284c4 */usr/lib/aarch64-linux-gnu/tegra/libnvjpeg.so
0586e6779fd0c2f14bd244f3c008028362c7ff69 */usr/lib/aarch64-linux-gnu/tegra/libnvcamv4l2.so
e5a480dfd73316d3ce695ac2f051510a722ae123 */usr/lib/aarch64-linux-gnu/tegra/libnvcamlog.so
0bd2ba4e03c3fb1edf6e818416e2261243729b00 */usr/lib/aarch64-linux-gnu/tegra/libnvrm.so
d60fdead80b68739d1758eb691029d91e482f290 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_graphics.so
1bb56df3132ecdf6203dceaf3594b98450da16bb */usr/lib/aarch64-linux-gnu/tegra/libnvrm_gpu.so
16d9672a8d1dfed70cdef5189da87c195acca15d */usr/lib/aarch64-linux-gnu/tegra/libnvargus.so
a9e157b87ebfb93a90a34370ded3a1c52ee7b886 */usr/lib/aarch64-linux-gnu/tegra/libnvll.so
b27ba7dba1482d38e2ec8898051af844b04321e2 */usr/lib/aarch64-linux-gnu/tegra/libnvimp.so
25f418b93dc46b3aeff6dcd587dba5428dc9317f */usr/lib/aarch64-linux-gnu/tegra/libnvargus_socketserver.so
d84124b158529e9a2bb9119d6e88ceb01b979a97 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_gpucompute.so
58dca5c3ec5046df53a4510a4c5e5729fe70bad2 */usr/lib/aarch64-linux-gnu/tegra/libnvargus_socketclient.so
36df666f59508c7c48396a9fcd0b9a5029f150dc */usr/lib/aarch64-linux-gnu/tegra/libnvcameratools.so
f7b6bb091b3f7538380a70aab891b82d80445a01 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_camera.so
e6eab1fab6fb4a1b356a7a527a25ec538f4da913 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_generic.so
fd71940f3dd3e387c5c87ff612104e15b28c8ec6 */usr/lib/aarch64-linux-gnu/tegra/libnvmmlite_image.so
5f43d2ec31ae80f0a3b9b04fb174262d3699d958 */usr/lib/aarch64-linux-gnu/tegra/libnvmmlite.so
f9ef4ff247d62e52b4f77eb1f77832b154bba3c8 */usr/lib/aarch64-linux-gnu/tegra/libnvcolorutil.so
2c9e1f3cee71e258dbb5c506062ee698fb8d5a2a */usr/lib/aarch64-linux-gnu/tegra/libnvcapture.so
f561275f3fda49dc0eaf7213223d6c8f3ce6d401 */usr/lib/aarch64-linux-gnu/tegra/libnvrm_graphics.so
2aec3d2182fde74c4f828fc3799e73512a192a3e */usr/lib/aarch64-linux-gnu/tegra/libnvgov_spincircle.so
0029efd1d35d522468710c8e7b515c1c1f2ee4b9 */usr/lib/aarch64-linux-gnu/tegra/libnvexif.so
e888d04fde7ff5f3337a162a0717ba69b4027a86 */usr/lib/aarch64-linux-gnu/tegra/libnvphsd.so
0ffce73c2aa0fa360bd2110b455fc93ad7fff5bf */usr/lib/aarch64-linux-gnu/tegra/libnvfnet.so
97e66c067f225ca95e7b0af2d2cb015fa6fac286 */usr/lib/aarch64-linux-gnu/tegra/libsensors.hal-client.nvs.so
f867cbba9e99bae1ffffbbbe5e33d6c311c2a163 */usr/lib/aarch64-linux-gnu/tegra/libnvomx.so
dd2245bb24b6b6ebe7aa5515763ec610856434ce */usr/lib/aarch64-linux-gnu/tegra/libnvmm_utils.so
a7fb6e2c05fa1ad39b76abfd913cfa10a7163382 */usr/lib/aarch64-linux-gnu/tegra/libnvofsdk.so
d320695f119f3f01a5005bdc7a1db3dde979fb9a */usr/lib/aarch64-linux-gnu/tegra/libsensors.l4t.no_fusion.nvs.so
b34ffc44929dc692e0ab91dad7b3827ef8f26f04 */usr/lib/aarch64-linux-gnu/tegra/libnvapputil.so
176c41fd3e22d90f8285559e954a160ea977df8a */usr/lib/aarch64-linux-gnu/tegra/libnvdla_runtime.so
e34acae518284f8e0cf9dbcf213a2533d258922e */usr/lib/aarch64-linux-gnu/tegra/libnvcam_imageencoder.so
6313226a4f2b04273a97670f499660039f3d31e0 */usr/lib/aarch64-linux-gnu/tegra/libnvv4l2.so
3b842c3b573c647032bcb96956b33e12076b71df */usr/lib/aarch64-linux-gnu/tegra/libnvgov_ui.so
d9818a70f356e6f46d0bec217caad6939101f6fd */usr/lib/aarch64-linux-gnu/tegra/libnvavp.so
4204264ec5cfd13a9803c52379186c5bef139f83 */usr/lib/aarch64-linux-gnu/tegra/libnvv4lconvert.so
9d628ca3ea4c05c56f612f66d7a8ba8d76e07214 */usr/lib/aarch64-linux-gnu/tegra/libnvgov_tbc.so
42bc717ef98a5c9d181fd1948d219323f15fb7ed */usr/lib/aarch64-linux-gnu/tegra/libnveglstreamproducer.so
ba0fdb56e2100579fd9d5306e3d2d35039c81eaf */usr/lib/aarch64-linux-gnu/tegra/libsensors_hal.nvs.so
fc46da4b539590229e1428cc354e190fc6bdb401 */usr/lib/aarch64-linux-gnu/libv4l/plugins/nv/libv4l2_nvvideocodec.so
a4239abeabbb436468321f2a24337eab067adcf0 */usr/lib/aarch64-linux-gnu/libv4l/plugins/nv/libv4l2_nvvidconv.so

It looks like the issue is related to some dependency on X. If I run the executable either from the desktop session directly or with ssh -X nvidia@ip, then the application shuts down correctly. If I run it as a service from /etc/systemd/system or with ssh nvidia@ip then the application terminates incorrectly.

Any ideas as to why this might be happening? I am not sure why there would be a dependency on X for nvjpeg.

Hi,
All samples are verified with X enabled. Suggest you also have the same environment.

A little frustrating that X is a dependency, but here is what I did to resolve the problem.

My application start script now runs with:

startx – :1 &
DISPLAY=:1 ./myapplication

This resolved all issues with shutdown as well as any other error messages related to this issue.