Deepstream-image-decode-test not work as use cv::mat encode data input

test env

deepstream-app version 6.1.1
DeepStreamSDK 6.1.1
CUDA Driver Version: 12.0
CUDA Runtime Version: 11.7
TensorRT Version: 8.4
cuDNN Version: 8.5
libNVWarp360 Version: 2.0.1d3

what i want to do

i need input network image to my pipeline, so use appsrc to read data by imencode, in my test pipeline, i use cv::imread/imencode to mock network data input. but pipeline run crash.

test code


#include <gst/app/gstappsrc.h>
#include <gst/app/gstappsink.h>
#include <vector>
#include <unistd.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <cstdio>
#include <string>
#include <map>
#include <opencv2/imgcodecs.hpp>

#define DEFAULT_IMAGE_WIDTH   480
#define DEFAULT_IMAGE_HEIGHT  640
#define DEFAULT_FRAME_SIZE    (3 * DEFAULT_IMAGE_WIDTH * DEFAULT_IMAGE_HEIGHT)
#define DEFAULT_MAX_FRAMES    (10 * DEFAULT_FRAME_SIZE)

#define USE_TIME_FORMAT       0
#define USE_CUSTOM_PTS        1
#define DEFAULT_FPS           25

/* Muxer batch formation timeout, for e.g. 40 millisec. Should ideally be set
 * based on the fastest source's framerate. */
#define MUXER_BATCH_TIMEOUT_USEC 33000

/* Structure to contain all our information for appsrc,
 * so we can pass it to callbacks */
typedef struct _CustomData {
  GstElement *app_source;
  guint fps; /* To set the FPS value */
  guint source_id; /* To control the GSource */
  gint frame_num;
} CustomData;

std::map<std::string, std::string> image_files;
static CustomData app_src_data = {NULL, DEFAULT_FPS, 0, 0};
GstElement *pipeline = NULL;

/* new_sample is an appsink callback that will extract metadata received
 * tee sink pad and update params for drawing rectangle,
 *object information etc. */
static GstFlowReturn
new_sample(GstElement *sink, gpointer *data) {
  static gint frame_number = 0;
  guint num_frame = 0;
  guint num_body = 0;
  guint num_face = 0;
  unsigned long int pts = 0;

  g_print(">>> new_sample coming %d.\n", frame_number);
  if (gst_app_sink_is_eos(GST_APP_SINK(sink))) {
    g_print("EOS received in Appsink********\n");
  }

  GstSample *sample = gst_app_sink_pull_sample(GST_APP_SINK(sink));
  if (!sample) {
    g_printerr("gst_app_sink_pull_sample failed.\n");
    return GST_FLOW_ERROR;
  }

  gst_sample_unref(sample);
  g_print("<<< Frame Number = %d (%d) Number of body = %d Number of face = %d PTS = %" GST_TIME_FORMAT "\n",
          frame_number, num_frame, num_body, num_face, GST_TIME_ARGS (pts));
  frame_number++;
  return GST_FLOW_OK;
}


/* This method is called by the idle GSource in the mainloop,
 * to feed one raw video frame into appsrc.
 * The idle handler is added to the mainloop when appsrc requests us
 * to start sending data (need-data signal)
 * and is removed when appsrc has enough data (enough-data signal).
 *
 * return False, will remove read_data callback in idle-loop
 */
static gboolean
read_data(CustomData *data) {
  static u_int64_t idl_idx = 0;
  static auto read_iter = image_files.begin();

  GstMapInfo map;
  GstBuffer *buffer = gst_buffer_new_allocate(NULL, DEFAULT_FRAME_SIZE, NULL);
  if (!gst_buffer_map(buffer, &map, GST_MAP_WRITE)) {
    printf("Unable to map info from buffer");
    return false;
  }

  if (read_iter != image_files.end()) {
    int fd = open(read_iter->second.c_str(), O_RDWR);
    if (fd != -1) {
      size_t ret = 0;
#if 1
      {
        cv::Mat img = cv::imread(read_iter->second.c_str());

        std::vector<int> param = std::vector<int>(2);
        param[0] = cv::IMWRITE_JPEG_QUALITY;
        param[1] = 100;
        std::vector<uchar> data_encode;
        imencode(".jpeg", img, data_encode, param);

        memset (map.data, 0, data_encode.size());
        map.size = data_encode.size();

        memcpy(map.data, &data_encode[0], data_encode.size() * sizeof(uchar));

      }
#else
      {
        ret = read(fd, map.data, DEFAULT_FRAME_SIZE);
      }
#endif
      ret = map.size;
      gst_buffer_unmap(buffer, &map);

      if (ret > 0) {
        GstFlowReturn gstret = gst_app_src_push_buffer((GstAppSrc *) data->app_source, buffer);
        if (gstret == GST_FLOW_OK) {
          g_print("gst_app_src_push_buffer success, %d.\n", data->frame_num);
        } else {
          g_print("gst_app_src_push_buffer returned %d \n", gstret);
          //return FALSE;
        }
      }

      data->frame_num++;
    }
    read_iter++;
  } else {
    GstFlowReturn gstret = gst_app_src_end_of_stream((GstAppSrc *) data->app_source);
    if (gstret != GST_FLOW_OK) {
      g_print
          ("gst_app_src_end_of_stream returned %d. EoS not queued successfully.\n",
           gstret);
      return FALSE;
    }
  }

  return TRUE;
}

/* This signal callback triggers when appsrc needs data. Here,
 * we add an idle handler to the mainloop to start pushing
 * data into the appsrc */
static void
start_feed(GstElement *source, guint size, CustomData *data) {
  if (data->source_id == 0) {
    data->source_id = g_idle_add((GSourceFunc) read_data, data);
    g_print("start_feed source_id %d \n", data->source_id);
  }
}

/* This callback triggers when appsrc has enough data and we can stop sending.
 * We remove the idle handler from the mainloop */
static void
stop_feed(GstElement *source, CustomData *data) {
  if (data->source_id != 0) {
    g_print("stop_feed source_id %d \n", data->source_id);
    g_source_remove(data->source_id);
    data->source_id = 0;
  }
}

static gboolean bus_watch_call(GstBus *bus, GstMessage *msg, gpointer data) {
  GMainLoop *loop = (GMainLoop *) data;
  g_print("+++ got message %s\n", gst_message_type_get_name(GST_MESSAGE_TYPE (msg)));

  switch (GST_MESSAGE_TYPE (msg)) {
    case GST_MESSAGE_EOS: {
      g_print("End of stream !!!\n");
      g_main_loop_quit(loop);
      break;
    }
    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_STATE_CHANGED: {
      GstState old_state, new_state, pending_state;
      gst_message_parse_state_changed(msg, &old_state, &new_state, &pending_state);
      g_print("Pipeline state changed from %s to %s:\n",
              gst_element_state_get_name(old_state),
              gst_element_state_get_name(new_state));
      break;
    }
    case GST_MESSAGE_STREAM_STATUS: {
      GstStreamStatusType type;
      GstElement *owner;
      const GValue *val;
      gchar *path;
      GstTask *task = NULL;

      g_message ("received STREAM_STATUS");
      gst_message_parse_stream_status(msg, &type, &owner);
      val = gst_message_get_stream_status_object(msg);

      g_message ("type: %d", type);
      path = gst_object_get_path_string(GST_MESSAGE_SRC (msg));
      g_message ("source: %s", path);
      g_free(path);

      path = gst_object_get_path_string(GST_OBJECT (owner));
      g_message ("owner: %s", path);
      g_free(path);
      g_message ("object: type %s, value %p", G_VALUE_TYPE_NAME(val), g_value_get_object(val));
      break;
    }
    default:
      break;
  }
  return TRUE;
}

int run_pipeline() {
  GMainLoop *loop = g_main_loop_new(NULL, FALSE);

  GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
  guint bus_watch_id = gst_bus_add_watch(bus, bus_watch_call, loop);
  gst_object_unref(bus);

  /* Set the pipeline to "playing" state */
  gst_element_set_state(pipeline, GST_STATE_PLAYING);

  /* Wait till pipeline encounters an error or EOS */
  g_print("===> Running...\n");
  g_main_loop_run(loop);

  /* Out of the main loop, clean up nicely */
  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;
}

GstElement *create_image_source_bin(guint index) {
  GstElement *bin = NULL/*, *uri_decode_bin = NULL*/;
  gchar bin_name[32] = {};
  gchar ele_name[32] = {};
  gboolean multi_file_src = FALSE;


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

  GstElement *source = NULL, *jpeg_parser = NULL, *decoder = NULL;

  source = gst_element_factory_make("appsrc", "source");

//  g_snprintf(ele_name, sizeof(ele_name) - 1, "decoder_queue%d", index);
//  decoder_queue = gst_element_factory_make("queue", ele_name);

  jpeg_parser = gst_element_factory_make("jpegparse", "jpeg-parser");
  decoder = gst_element_factory_make("nvv4l2decoder", "nvv4l2-decoder");


  if (!source || !jpeg_parser || !decoder) {
    g_printerr("One element could not be created. Exiting.\n");
    return NULL;
  }

  app_src_data.app_source = source;
  g_object_set(G_OBJECT (source),
               "stream-type", GST_APP_STREAM_TYPE_STREAM,
               "format", GST_FORMAT_BYTES,
               "max-bytes", DEFAULT_MAX_FRAMES,
               NULL);

  g_signal_connect (source, "need-data", G_CALLBACK(start_feed), &app_src_data);
  g_signal_connect (source, "enough-data", G_CALLBACK(stop_feed), &app_src_data);

  g_object_set(G_OBJECT(decoder), "cudadec-memtype", 0, NULL);

  gst_bin_add_many(GST_BIN(bin), source, jpeg_parser, decoder, NULL);
  gst_element_link_many(source, jpeg_parser, decoder, NULL);

  /* 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;
  }

  GstPad *srcpad = gst_element_get_static_pad(decoder, "src");
  if (!srcpad) {
    g_printerr("Failed to get src pad of source bin. Exiting.\n");
    return NULL;
  }
  GstPad *bin_ghost_pad = gst_element_get_static_pad(bin, "src");
  if (!gst_ghost_pad_set_target(GST_GHOST_PAD(bin_ghost_pad), srcpad)) {
    g_printerr("Failed to link decoder src pad to source bin ghost pad\n");
  }

  return bin;
}

int build_pipeline() {
  GstElement *source_bin = NULL, *streammux = NULL, *pgie = NULL, *transfer = NULL,
      *reid = NULL, *nvvidconv2 = NULL, *appsink = NULL;

//  int current_device = -1;
//  cudaGetDevice(&current_device);
//  struct cudaDeviceProp prop;
//  cudaGetDeviceProperties(&prop, current_device);

  /* Create gstreamer elements */
  /* Create Pipeline element that will form a connection of other elements */
  pipeline = gst_pipeline_new("pos-image-track-pipeline");
  if (!pipeline) {
    g_printerr("Pipeline could not be created. Exiting.\n");
    return -1;
  }

  /* Create nvstreammux instance to form batches from one or more sources. */
  streammux = gst_element_factory_make("nvstreammux", "stream-muxer");
  if (!streammux) {
    g_printerr("nvstreammux could not be created. Exiting.\n");
    return -1;
  }
  /* Set streammux properties */
  g_object_set(G_OBJECT (streammux),
               "gpu-id", 0,
               "nvbuf-memory-type", 2,
               "width", 640,
               "height", 480,
               "batch-size", 1,
               "batched-push-timeout", 1000000,
               NULL);

  gst_bin_add(GST_BIN (pipeline), streammux);

  /*Create Source Bin. */
  {
    int index = 0;
    GstPad *sinkpad, *srcpad;
    gchar pad_name[16] = {};

    source_bin = create_image_source_bin(index);
    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", index);
    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);
  }

  pgie = gst_element_factory_make("nvinfer", "face-detect");
  if (!pgie) {
    g_printerr("Primary nvinfer could not be created. Exiting.\n");
    return -1;
  }

  /* Set detect properties */
  g_object_set(G_OBJECT (pgie),
               "gpu-id", 0,
               "config-file-path", "/app/insights_engine/config/skyeye_guard/skyeye_pos/config_hema_face_trtx.cfg",
               NULL);

  reid = gst_element_factory_make("nvinfer", "face-reid");
  if (!reid) {
    g_printerr("Second nvinfer for reid could not be created. Exiting.\n");
    return -1;
  }

  /* Set infer properties */
  g_object_set(G_OBJECT (reid),
               "gpu-id", 0,
               "config-file-path", "/app/insights_engine/config/skyeye_guard/skyeye_pos/config_hema_face_reid.cfg",
               NULL);

  /* Use convertor to convert from NV12 to RGBA as required by nvdsosd */
  nvvidconv2 = gst_element_factory_make("nvvideoconvert", "nvvideo-converter2");
  if (!nvvidconv2) {
    g_printerr("nvvideoconvert2 could not be created. Exiting.\n");
    return -1;
  }

  appsink = gst_element_factory_make("appsink", "app-sink");
  if (!appsink) {
    g_printerr("Appsink element could not be created. Exiting.\n");
    return -1;
  }

  /* Set up the pipeline */
  /* we add all elements into the pipeline */
  gst_bin_add_many(GST_BIN (pipeline), pgie, reid, nvvidconv2, appsink, NULL);

  /* we link the elements together */
  /* source_bin -> streammux -> nvinfer -> reid -> nvvidconv -> appsink */
  if (!gst_element_link_many(streammux, pgie, reid, nvvidconv2, appsink, NULL)) {
    g_printerr("Elements could not be linked: Exiting.\n");
    return -1;
  }

  /* Configure appsink to extract data from DeepStream pipeline */
  g_object_set(appsink, "emit-signals", TRUE, "sync", FALSE, NULL);

  /* Callback to access buffer and object info. */
  g_signal_connect (appsink, "new-sample", G_CALLBACK(new_sample), &app_src_data);
  return 0;
}

static void find_images(const std::string &path,
                        std::map<std::string, std::string> &out,
                        const std::string &filerExt = "",
                        bool include_child = true) {
  DIR *d = NULL;
  struct dirent *dp = NULL;
  struct stat st;
  char p[1024] = {0};
  if (stat(path.c_str(), &st) < 0 || !S_ISDIR(st.st_mode)) {
    //printf("invalid path: %s\n", path.c_str());
    return;
  }

  if (!(d = opendir(path.c_str()))) {
    //printf("opendir[%s] error\n", path.c_str());
    return;
  }

  while ((dp = readdir(d)) != NULL) {
    if ((!strncmp(dp->d_name, ".", 1)) || (!strncmp(dp->d_name, "..", 2)))
      continue;

    snprintf(p, sizeof(p) - 1, "%s/%s", path.c_str(), dp->d_name);
    stat(p, &st);
    if (!S_ISDIR(st.st_mode)) {
      //printf("%s/%s\n",path.c_str(), dp->d_name);
      if (!filerExt.empty()) {
        std::string name(dp->d_name);
        auto pos = name.find_last_of(".");
        auto ext = name.substr(pos);
        //printf("ext %s\n", ext.c_str());
        if (0 == ext.compare(filerExt)) {
          out[dp->d_name] = p;
        }
      } else {
        out[dp->d_name] = p;
      }
    } else {
      if (include_child) {
        //printf("%s/\n", dp->d_name);
        find_images(p, out);
      }
    }
  }

  closedir(d);
}

int main(int argc, char *argv[]) {
  find_images("/app/insights_engine/testdata", image_files, ".jpg", true);
  printf("image_files size=%ld.\n", image_files.size());

  // Gstreamer 初始化
  gst_init(&argc, &argv);

  printf("build_pipeline\n");
  int ret = build_pipeline();
  if (ret == 0) {
    printf("run_pipeline\n");
    run_pipeline();
  }

  printf("end_pipeline\n");
}

problem

key test code follow, if use cv::imread and imencode to read image to GstBuffer, run will crash. but use read run ok.

#if 1
      {
        cv::Mat img = cv::imread(read_iter->second.c_str());

        std::vector<int> param = std::vector<int>(2);
        param[0] = cv::IMWRITE_JPEG_QUALITY;
        param[1] = 100;
        std::vector<uchar> data_encode;
        imencode(".jpeg", img, data_encode, param);

        memset (map.data, 0, data_encode.size());
        map.size = data_encode.size();

        memcpy(map.data, &data_encode[0], data_encode.size() * sizeof(uchar));

      }
#else
      {
        ret = read(fd, map.data, DEFAULT_FRAME_SIZE);
      }
#endif

debug info

0:00:03.911671171 22913 0x555556c74000 DEBUG              jpegparse gstjpegparse.c:253:gst_jpeg_parse_get_image_length: 0x0007cd1e: EOI marker
0:00:03.911674336 22913 0x555556c74000 LOG                jpegparse gstjpegparse.c:779:gst_jpeg_parse_handle_frame:<jpeg-parser> parsed image of size 511264
0:00:03.911677382 22913 0x555556c74000 DEBUG              jpegparse gstjpegparse.c:599:gst_jpeg_parse_read_header:<jpeg-parser> marker = d8
0:00:03.911681282 22913 0x555556c74000 LOG                baseparse gstbaseparse.c:2680:gst_base_parse_finish_frame:<jpeg-parser> finished frame at offset 7676850, flushing size 511264
0:00:03.911685093 22913 0x555556c74000 LOG                  adapter gstadapter.c:973:gst_adapter_get_buffer:<GstAdapter@0x55555650b000> getting buffer of 511264 bytes
0:00:03.911688433 22913 0x555556c74000 LOG                  adapter gstadapter.c:993:gst_adapter_get_buffer:<GstAdapter@0x55555650b000> providing buffer of 511264 bytes via region copy
0:00:03.911691507 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:844:gst_buffer_new: new 0x555574f87a20
0:00:03.911695432 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:2119:gst_buffer_copy_region: new region copy 0x555574f87a20 of 0x555574f87c60 304050-511264
0:00:03.911699651 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:556:gst_buffer_copy_into: copy 0x555574f87c60 to 0x555574f87a20, offset 304050-511264/921600
0:00:03.911703822 22913 0x555556c74000 DEBUG             GST_MEMORY gstmemory.c:138:gst_memory_init: new memory 0x7fff0c22c0f0, maxsize:921607 offset:304050 size:511264
0:00:03.911707676 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:450:_memory_add: buffer 0x555574f87a20, idx -1, mem 0x7fff0c22c0f0
0:00:03.911711145 22913 0x555556c74000 LOG                  adapter gstadapter.c:634:gst_adapter_flush_unchecked:<GstAdapter@0x55555650b000> flushing 511264 bytes
0:00:03.911714428 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:768:_gst_buffer_free: finalize 0x555574f877e0
0:00:03.911717481 22913 0x555556c74000 DEBUG             GST_MEMORY gstmemory.c:88:_gst_memory_free: free memory 0x555556c77460
0:00:03.911720761 22913 0x555556c74000 DEBUG              baseparse gstbaseparse.c:2374:gst_base_parse_handle_and_push_frame:<jpeg-parser> no next fallback timestamp
0:00:03.911727190 22913 0x555556c74000 LOG                baseparse gstbaseparse.c:2427:gst_base_parse_push_frame:<jpeg-parser> processing buffer of size 511264 with dts 99:99:99.999999999, pts 99:99:99.999999999, duration 99:99:99.999999999
0:00:03.911737406 22913 0x555556c74000 DEBUG               GST_CAPS gstpad.c:2704:gst_pad_has_current_caps:<jpeg-parser:src> check current pad caps image/jpeg, parsed=(boolean)true, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)1/1
0:00:03.911742592 22913 0x555556c74000 LOG                baseparse gstbaseparse.c:2578:gst_base_parse_push_frame:<jpeg-parser> pushing frame (511264 bytes) now..
0:00:03.911750406 22913 0x555556c74000 DEBUG         GST_SCHEDULING gstpad.c:4323:gst_pad_chain_data_unchecked:<nvv4l2-decoder:sink> calling chainfunction &gst_video_decoder_chain with buffer buffer: 0x555574f87a20, pts 99:99:99.999999999, dts 99:99:99.999999999, dur 99:99:99.999999999, size 511264, offset 7676850, offset_end none, flags 0x4040
0:00:03.911758794 22913 0x555556c74000 LOG             videodecoder gstvideodecoder.c:2407:gst_video_decoder_chain:<nvv4l2-decoder> chain PTS 99:99:99.999999999, DTS 99:99:99.999999999 duration 99:99:99.999999999 size 511264 flags 4040
0:00:03.911763308 22913 0x555556c74000 LOG             videodecoder gstvideodecoder.c:2569:gst_video_decoder_new_frame:<nvv4l2-decoder> Created new frame 0x7fff0c22d5a0 (sfn:5)
0:00:03.911766499 22913 0x555556c74000 LOG             videodecoder gstvideodecoder.c:2115:gst_video_decoder_chain_forward:<nvv4l2-decoder> Marking current_frame as sync point
0:00:03.911771710 22913 0x555556c74000 LOG             videodecoder gstvideodecoder.c:3387:gst_video_decoder_decode_frame:<nvv4l2-decoder> PTS 99:99:99.999999999, DTS 99:99:99.999999999, dist 5
0:00:03.911774955 22913 0x555556c74000 DEBUG                default gstsegment.c:737:gst_segment_to_running_time_full: invalid position (-1)
0:00:03.911779925 22913 0x555556c74000 DEBUG           v4l2videodec gstv4l2videodec.c:1404:gst_v4l2_video_dec_handle_frame:<nvv4l2-decoder> Handling frame 5
0:00:03.911784684 22913 0x555556c74000 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:2077:gst_v4l2_buffer_pool_process:<nvv4l2-decoder:pool:sink> process buffer 0x7fff0c22d5d8
0:00:03.911787905 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:2280:gst_v4l2_buffer_pool_process:<nvv4l2-decoder:pool:sink> alloc buffer from our pool
0:00:03.911791157 22913 0x555556c74000 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:1641:gst_v4l2_buffer_pool_acquire_buffer:<nvv4l2-decoder:pool:sink> acquire
0:00:03.911794813 22913 0x555556c74000 LOG               bufferpool gstbufferpool.c:1123:default_acquire_buffer:<nvv4l2-decoder:pool:sink> acquired buffer 0x555574f87480
0:00:03.911798186 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:144:gst_v4l2_buffer_pool_copy_buffer:<nvv4l2-decoder:pool:sink> copying buffer
0:00:03.911801217 22913 0x555556c74000 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:176:gst_v4l2_buffer_pool_copy_buffer:<nvv4l2-decoder:pool:sink> copy raw bytes
0:00:03.911805293 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:1800:gst_buffer_map_range: buffer 0x555574f87a20, idx 0, length -1, flags 0001
0:00:03.911809054 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:244:_get_merged_memory: buffer 0x555574f87a20, idx 0, length 1
0:00:03.911812983 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:1904:gst_buffer_fill: buffer 0x555574f87480, offset 0, size 511264
0:00:03.911841483 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:1656:gst_buffer_resize_range: trim 0x555574f87480 0-511264 size:307200 offs:0 max:307200

(my_gst_test:22913): GStreamer-CRITICAL **: 11:13:34.837: gst_buffer_resize_range: assertion 'bufmax >= bufoffs + offset + size' failed
0:00:03.911864673 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:556:gst_buffer_copy_into: copy 0x555574f87a20 to 0x555574f87480, offset 0-511264/511264
0:00:03.911868350 22913 0x555556c74000 LOG          GST_PERFORMANCE gstv4l2bufferpool.c:303:gst_v4l2_buffer_pool_copy_buffer:<nvv4l2-decoder:pool:sink> slow copy into buffer 0x555574f87480
0:00:03.911872934 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:1375:gst_v4l2_buffer_pool_qbuf:<nvv4l2-decoder:pool:sink> queuing buffer 1
0:00:03.911882835 22913 0x555556c74000 LOG            v4l2allocator gstv4l2allocator.c:1405:gst_v4l2_allocator_qbuf:<nvv4l2-decoder:pool:sink:allocator> queued buffer 1 (flags 0x2)
0:00:03.911888429 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:753:_gst_buffer_dispose: release 0x555574f87480 to pool 0x7fff0c227ec0
0:00:03.911893223 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:1656:gst_buffer_resize_range: trim 0x555574f87480 0-307200 size:307200 offs:0 max:307200
0:00:03.911896750 22913 0x555556c74000 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:1719:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> release buffer 0x555574f87480
0:00:03.911900204 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:1810:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> buffer 1 is queued
0:00:03.911903375 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:1449:gst_v4l2_buffer_pool_dqbuf:<nvv4l2-decoder:pool:sink> dequeueing a buffer
0:00:03.911908390 22913 0x555556c74000 LOG            v4l2allocator gstv4l2allocator.c:1463:gst_v4l2_allocator_dqbuf:<nvv4l2-decoder:pool:sink:allocator> dequeued buffer 0 (flags 0x0)
0:00:03.911915404 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:1510:gst_v4l2_buffer_pool_dqbuf:<nvv4l2-decoder:pool:sink> dequeued buffer 0x555574f87360 seq:0 (ix=0), mem 0x555556c774f0 used 64, plane=0, flags 00000000, ts 0:00:00.000000000, pool-queued=1, buffer=0x555574f87360
0:00:03.911920010 22913 0x555556c74000 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:1719:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> release buffer 0x555574f87360
0:00:03.911923710 22913 0x555556c74000 LOG           v4l2bufferpool gstv4l2bufferpool.c:1794:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> buffer 0 not queued, putting on free list
0:00:03.911927516 22913 0x555556c74000 LOG               bufferpool gstbufferpool.c:1285:default_release_buffer:<nvv4l2-decoder:pool:sink> released buffer 0x555574f87360 0
0:00:03.911930886 22913 0x555556c74000 DEBUG             GST_BUFFER gstbuffer.c:1451:gst_buffer_is_memory_range_writable: idx 0, length -1
0:00:03.911934501 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:844:gst_buffer_new: new 0x555574f877e0
0:00:03.911938861 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:556:gst_buffer_copy_into: copy 0x555574f87a20 to 0x555574f877e0, offset 0-0/511264
0:00:03.911941968 22913 0x555556c74000 LOG               GST_BUFFER gstbuffer.c:768:_gst_buffer_free: finalize 0x555574f87a20
0:00:03.911945136 22913 0x555556c74000 DEBUG             GST_MEMORY gstmemory.c:88:_gst_memory_free: free memory 0x7fff0c22c0f0
0:00:03.911949959 22913 0x555556c74000 DEBUG         GST_SCHEDULING gstpad.c:4329:gst_pad_chain_data_unchecked:<nvv4l2-decoder:sink> called chainfunction &gst_video_decoder_chain with buffer 0x555574f87a20, returned ok
0:00:03.911953864 22913 0x555556c74000 LOG                baseparse gstbaseparse.c:2581:gst_base_parse_push_frame:<jpeg-parser> frame pushed, flow ok
0:00:03.911957632 22913 0x555556c74000 LOG                baseparse gstbaseparse.c:2206:gst_base_parse_handle_buffer:<jpeg-parser> handle_frame skipped 199031, flushed 511264
**
ERROR:gstbaseparse.c:2210:gst_base_parse_handle_buffer: assertion failed: (*skip == 0 || *flushed == 0)
Bail out! ERROR:gstbaseparse.c:2210:gst_base_parse_handle_buffer: assertion failed: (*skip == 0 || *flushed == 0)
Signal: SIGABRT (Aborted)

help !!!

please refer to deepstream sample deepstream-appsrc-test, it will use appsrc to read the local files.

hi, fanzh, thank you reply.
read from local files by appsrc read-dat callback, still crash.

0:10:19.054354095 23984 0x5555564e1c00 DEBUG             GST_MEMORY gstmemory.c:138:gst_memory_init: new memory 0x7ffefc30c240, maxsize:922655 offset:207996 size:714652
0:10:19.054362938 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:450:_memory_add: buffer 0x555574e4d000, idx -1, mem 0x7ffefc30c240
0:10:19.054372227 23984 0x5555564e1c00 DEBUG             GST_BUFFER gstbuffer.c:2282:gst_buffer_add_meta: alloc metadata 0x7ffeb800c410 (NvDsMeta) of size 72
0:10:19.054386471 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2184:gst_base_parse_handle_buffer:<jpeg-parser> handling buffer of size 714652 with dts 99:99:99.999999999, pts 99:99:99.999999999, duration 99:99:99.999999999
0:10:19.054396820 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2147:gst_base_parse_prepare_frame:<jpeg-parser> preparing frame at offset 18446744073709551615 (0xffffffffffffffff) of size 714652
0:10:19.054403277 23984 0x5555564e1c00 DEBUG              baseparse gstbaseparse.c:794:gst_base_parse_update_frame:<jpeg-parser> marking DISCONT
0:10:19.054409614 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:801:gst_base_parse_update_frame:<jpeg-parser> marking as new frame
0:10:19.054417943 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:1800:gst_buffer_map_range: buffer 0x555574e4d000, idx 0, length -1, flags 0001
0:10:19.054426059 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:244:_get_merged_memory: buffer 0x555574e4d000, idx 0, length 1
0:10:19.054566977 23984 0x555555aac200 DEBUG             GST_MEMORY gstmemory.c:138:gst_memory_init: new memory 0x55559b84c710, maxsize:922655 offset:0 size:922648
0:10:19.054584434 23984 0x555555aac200 LOG               GST_BUFFER gstbuffer.c:844:gst_buffer_new: new 0x555574779d80
0:10:19.054594735 23984 0x555555aac200 LOG               GST_BUFFER gstbuffer.c:450:_memory_add: buffer 0x555574779d80, idx -1, mem 0x55559b84c710
0:10:19.054606738 23984 0x555555aac200 LOG               GST_BUFFER gstbuffer.c:898:gst_buffer_new_allocate: new buffer 0x555574779d80 of size 922648 from allocator (nil)
0:10:19.054616726 23984 0x555555aac200 LOG               GST_BUFFER gstbuffer.c:1800:gst_buffer_map_range: buffer 0x555574779d80, idx 0, length -1, flags 0002
0:10:19.054627038 23984 0x555555aac200 LOG               GST_BUFFER gstbuffer.c:244:_get_merged_memory: buffer 0x555574779d80, idx 0, length 1
0:10:19.054695402 23984 0x5555564e1c00 DEBUG              jpegparse gstjpegparse.c:211:gst_jpeg_parse_get_image_length: Parsing jpeg image data (714652 bytes)
0:10:19.054705343 23984 0x5555564e1c00 DEBUG              jpegparse gstjpegparse.c:213:gst_jpeg_parse_get_image_length: Parse state: offset=0, resync=0, entropy len=0
0:10:19.054712166 23984 0x5555564e1c00 DEBUG              jpegparse gstjpegparse.c:232:gst_jpeg_parse_get_image_length: Lost sync at 0x00000002, resyncing
0:10:19.054718731 23984 0x5555564e1c00 DEBUG              jpegparse gstjpegparse.c:253:gst_jpeg_parse_get_image_length: 0x00000003: EOI marker
0:10:19.054725610 23984 0x5555564e1c00 LOG                jpegparse gstjpegparse.c:779:gst_jpeg_parse_handle_frame:<jpeg-parser> parsed image of size 5
0:10:19.054732344 23984 0x5555564e1c00 DEBUG              jpegparse gstjpegparse.c:599:gst_jpeg_parse_read_header:<jpeg-parser> marker = d8
0:10:19.054740537 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2680:gst_base_parse_finish_frame:<jpeg-parser> finished frame at offset 5340494620, flushing size 5
0:10:19.054748159 23984 0x5555564e1c00 LOG                  adapter gstadapter.c:973:gst_adapter_get_buffer:<GstAdapter@0x555555d2e000> getting buffer of 5 bytes
0:10:19.054755546 23984 0x5555564e1c00 LOG                  adapter gstadapter.c:993:gst_adapter_get_buffer:<GstAdapter@0x555555d2e000> providing buffer of 5 bytes via region copy
0:10:19.054761927 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:844:gst_buffer_new: new 0x5555747795a0
0:10:19.054770733 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:2119:gst_buffer_copy_region: new region copy 0x5555747795a0 of 0x5555694fcea0 207996-5
0:10:19.054779998 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:556:gst_buffer_copy_into: copy 0x5555694fcea0 to 0x5555747795a0, offset 207996-5/922648
0:10:19.054789312 23984 0x5555564e1c00 DEBUG             GST_MEMORY gstmemory.c:138:gst_memory_init: new memory 0x7ffefc30c1b0, maxsize:922655 offset:207996 size:5
0:10:19.054800296 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:450:_memory_add: buffer 0x5555747795a0, idx -1, mem 0x7ffefc30c1b0
0:10:19.054809190 23984 0x5555564e1c00 DEBUG             GST_BUFFER gstbuffer.c:2282:gst_buffer_add_meta: alloc metadata 0x55556b505d30 (NvDsMeta) of size 72
0:10:19.054820306 23984 0x5555564e1c00 LOG                  adapter gstadapter.c:634:gst_adapter_flush_unchecked:<GstAdapter@0x555555d2e000> flushing 5 bytes
0:10:19.054827067 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:768:_gst_buffer_free: finalize 0x555574e4d000
0:10:19.054833962 23984 0x5555564e1c00 DEBUG             GST_MEMORY gstmemory.c:88:_gst_memory_free: free memory 0x7ffefc30c240
0:10:19.054841138 23984 0x5555564e1c00 DEBUG              baseparse gstbaseparse.c:2374:gst_base_parse_handle_and_push_frame:<jpeg-parser> no next fallback timestamp
0:10:19.054854772 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2427:gst_base_parse_push_frame:<jpeg-parser> processing buffer of size 5 with dts 99:99:99.999999999, pts 99:99:99.999999999, duration 99:99:99.999999999
0:10:19.054871052 23984 0x5555564e1c00 DEBUG               GST_CAPS gstpad.c:2704:gst_pad_has_current_caps:<jpeg-parser:src> check current pad caps image/jpeg, parsed=(boolean)true, format=(string)I420, width=(int)640, height=(int)480, framerate=(fraction)1/1
0:10:19.054881410 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2578:gst_base_parse_push_frame:<jpeg-parser> pushing frame (5 bytes) now..
0:10:19.054895883 23984 0x5555564e1c00 DEBUG         GST_SCHEDULING gstpad.c:4323:gst_pad_chain_data_unchecked:<nvv4l2-decoder:sink> calling chainfunction &gst_video_decoder_chain with buffer buffer: 0x5555747795a0, pts 99:99:99.999999999, dts 99:99:99.999999999, dur 99:99:99.999999999, size 5, offset 5340494620, offset_end none, flags 0x4040
0:10:19.054911157 23984 0x5555564e1c00 LOG             videodecoder gstvideodecoder.c:2407:gst_video_decoder_chain:<nvv4l2-decoder> chain PTS 99:99:99.999999999, DTS 99:99:99.999999999 duration 99:99:99.999999999 size 5 flags 4040
0:10:19.054921775 23984 0x5555564e1c00 LOG             videodecoder gstvideodecoder.c:2569:gst_video_decoder_new_frame:<nvv4l2-decoder> Created new frame 0x7ffefc02dbd0 (sfn:5779)
0:10:19.054928553 23984 0x5555564e1c00 LOG             videodecoder gstvideodecoder.c:2115:gst_video_decoder_chain_forward:<nvv4l2-decoder> Marking current_frame as sync point
0:10:19.054940192 23984 0x5555564e1c00 LOG             videodecoder gstvideodecoder.c:3387:gst_video_decoder_decode_frame:<nvv4l2-decoder> PTS 99:99:99.999999999, DTS 99:99:99.999999999, dist 5779
0:10:19.054948532 23984 0x5555564e1c00 DEBUG           videodecoder gstvideodecoder.c:3395:gst_video_decoder_decode_frame:<nvv4l2-decoder> decoder frame list getting long: 17 frames,possible internal leaking?
0:10:19.054954427 23984 0x5555564e1c00 DEBUG                default gstsegment.c:737:gst_segment_to_running_time_full: invalid position (-1)
0:10:19.054962617 23984 0x5555564e1c00 DEBUG           v4l2videodec gstv4l2videodec.c:1404:gst_v4l2_video_dec_handle_frame:<nvv4l2-decoder> Handling frame 5779
0:10:19.054970351 23984 0x5555564e1c00 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:2077:gst_v4l2_buffer_pool_process:<nvv4l2-decoder:pool:sink> process buffer 0x7ffefc02dc08
0:10:19.054977885 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:2280:gst_v4l2_buffer_pool_process:<nvv4l2-decoder:pool:sink> alloc buffer from our pool
0:10:19.054984764 23984 0x5555564e1c00 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:1641:gst_v4l2_buffer_pool_acquire_buffer:<nvv4l2-decoder:pool:sink> acquire
0:10:19.054992132 23984 0x5555564e1c00 LOG               bufferpool gstbufferpool.c:1123:default_acquire_buffer:<nvv4l2-decoder:pool:sink> acquired buffer 0x55556f30a480
0:10:19.054998653 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:144:gst_v4l2_buffer_pool_copy_buffer:<nvv4l2-decoder:pool:sink> copying buffer
0:10:19.055005146 23984 0x5555564e1c00 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:176:gst_v4l2_buffer_pool_copy_buffer:<nvv4l2-decoder:pool:sink> copy raw bytes
0:10:19.055013551 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:1800:gst_buffer_map_range: buffer 0x5555747795a0, idx 0, length -1, flags 0001
0:10:19.055021820 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:244:_get_merged_memory: buffer 0x5555747795a0, idx 0, length 1
0:10:19.055030112 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:1904:gst_buffer_fill: buffer 0x55556f30a480, offset 0, size 5
0:10:19.055040985 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:1656:gst_buffer_resize_range: trim 0x55556f30a480 0-5 size:307200 offs:0 max:307200
0:10:19.055054442 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:556:gst_buffer_copy_into: copy 0x5555747795a0 to 0x55556f30a480, offset 0-5/5
0:10:19.055061815 23984 0x5555564e1c00 LOG          GST_PERFORMANCE gstv4l2bufferpool.c:303:gst_v4l2_buffer_pool_copy_buffer:<nvv4l2-decoder:pool:sink> slow copy into buffer 0x55556f30a480
0:10:19.055070324 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:1375:gst_v4l2_buffer_pool_qbuf:<nvv4l2-decoder:pool:sink> queuing buffer 1
0:10:19.055086903 23984 0x5555564e1c00 LOG            v4l2allocator gstv4l2allocator.c:1405:gst_v4l2_allocator_qbuf:<nvv4l2-decoder:pool:sink:allocator> queued buffer 1 (flags 0x2)
0:10:19.055098012 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:753:_gst_buffer_dispose: release 0x55556f30a480 to pool 0x7ffefc3085c0
0:10:19.055108036 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:1656:gst_buffer_resize_range: trim 0x55556f30a480 0-307200 size:5 offs:0 max:307200
0:10:19.055115989 23984 0x5555564e1c00 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:1719:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> release buffer 0x55556f30a480
0:10:19.055123437 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:1810:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> buffer 1 is queued
0:10:19.055130079 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:1449:gst_v4l2_buffer_pool_dqbuf:<nvv4l2-decoder:pool:sink> dequeueing a buffer
0:10:19.055138896 23984 0x5555564e1c00 LOG            v4l2allocator gstv4l2allocator.c:1463:gst_v4l2_allocator_dqbuf:<nvv4l2-decoder:pool:sink:allocator> dequeued buffer 0 (flags 0x0)
0:10:19.055140486 23984 0x555555aac200 DEBUG             GST_BUFFER gstbuffer.c:2282:gst_buffer_add_meta: alloc metadata 0x55556b505e50 (NvDsMeta) of size 72
0:10:19.055154143 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:1510:gst_v4l2_buffer_pool_dqbuf:<nvv4l2-decoder:pool:sink> dequeued buffer 0x55556f30a360 seq:0 (ix=0), mem 0x5555564e34f0 used 64, plane=0, flags 00000000, ts 0:00:00.000000000, pool-queued=1, buffer=0x55556f30a360
0:10:19.055159301 23984 0x555555aac200 DEBUG                 appsrc gstappsrc.c:1907:gst_app_src_push_internal:<source> queueing buffer 0x555574779d80
0:10:19.055161572 23984 0x5555564e1c00 DEBUG         v4l2bufferpool gstv4l2bufferpool.c:1719:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> release buffer 0x55556f30a360
0:10:19.055178091 23984 0x5555564e1c00 LOG           v4l2bufferpool gstv4l2bufferpool.c:1794:gst_v4l2_buffer_pool_release_buffer:<nvv4l2-decoder:pool:sink> buffer 0 not queued, putting on free list
0:10:19.055186375 23984 0x5555564e1c00 LOG               bufferpool gstbufferpool.c:1285:default_release_buffer:<nvv4l2-decoder:pool:sink> released buffer 0x55556f30a360 0
0:10:19.055193667 23984 0x5555564e1c00 DEBUG             GST_BUFFER gstbuffer.c:1451:gst_buffer_is_memory_range_writable: idx 0, length -1
0:10:19.055201432 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:844:gst_buffer_new: new 0x555574e4d000
0:10:19.055210891 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:556:gst_buffer_copy_into: copy 0x5555747795a0 to 0x555574e4d000, offset 0-0/5
0:10:19.055220388 23984 0x5555564e1c00 DEBUG             GST_BUFFER gstbuffer.c:2282:gst_buffer_add_meta: alloc metadata 0x7ffefc0f08d0 (NvDsMeta) of size 72
0:10:19.055227627 23984 0x5555564e1c00 LOG               GST_BUFFER gstbuffer.c:768:_gst_buffer_free: finalize 0x5555747795a0
0:10:19.055234917 23984 0x5555564e1c00 DEBUG             GST_MEMORY gstmemory.c:88:_gst_memory_free: free memory 0x7ffefc30c1b0
0:10:19.055244860 23984 0x5555564e1c00 DEBUG         GST_SCHEDULING gstpad.c:4329:gst_pad_chain_data_unchecked:<nvv4l2-decoder:sink> called chainfunction &gst_video_decoder_chain with buffer 0x5555747795a0, returned ok
0:10:19.055253036 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2581:gst_base_parse_push_frame:<jpeg-parser> frame pushed, flow ok
0:10:19.055260787 23984 0x5555564e1c00 LOG                baseparse gstbaseparse.c:2206:gst_base_parse_handle_buffer:<jpeg-parser> handle_frame skipped 156738, flushed 5
**
ERROR:gstbaseparse.c:2210:gst_base_parse_handle_buffer: assertion failed: (*skip == 0 || *flushed == 0)
Signal: SIGABRT (Aborted)

my testcode has use appsrc to read data! i’m test 20000+ pics, but stiil crash after process 2000+.

my pipeline input is jpg-image not video, so my pipeline is refer deepstream-appsrc-test and image-decode-test.

my pilieline (as mentioned above sample code)
appsrc->jpegparse->nvv4l2decoder->nvstreammux->infer->infer->nvvideoconvert->appsink

from the log, it crashed in jpeg-parser, did it crash on the specific jpeg file?

after use jpegdec, i can make sure some specific jpeg file decode failed. use jpegdec can run all 20000+ pics over, but nvusermeta losed after jpegdec plugin.

new pipeline:
appsrc->jpegdec->nvvideoconvert->capterfilter->nvstreammux->infer->nvvideoconvert->appsink

use sink-prob i found jpegdec-sink recv nvusermeta, but jpegdec-src lost after pass jpegdec .

  1. how did you add nvusermeta? I did not find it in your code.
  2. jpegdec is Gstreamer opensource, please refer to Gstreamer code if needed.

meta data constructor

static gpointer
pos_image_meta_copy_func(gpointer data, gpointer user_data) {
  NvPosImageMeta *src_pos_meta = (NvPosImageMeta *) data;
  NvPosImageMeta *dst_pos_meta = (NvPosImageMeta *) g_malloc0(
      sizeof(NvPosImageMeta));
  memcpy(dst_pos_meta, src_pos_meta, sizeof(NvPosImageMeta));
  return (gpointer) dst_pos_meta;
}

/* gst meta release function set by user */
static void
pos_image_meta_release_func(gpointer data, gpointer user_data) {
  NvPosImageMeta *pos_meta = (NvPosImageMeta *) data;
  if (pos_meta) {
    g_free(pos_meta);
    pos_meta = NULL;
  }
}

/* gst to nvds transform function set by user. "data" holds a pointer to NvDsUserMeta */
static gpointer
pos_image_gst_to_nvds_meta_transform_func(gpointer data, gpointer user_data) {
  NvDsUserMeta *user_meta = (NvDsUserMeta *) data;
  NvPosImageMeta *src_pos_meta = (NvPosImageMeta *) user_meta->user_meta_data;
  NvPosImageMeta *dst_pos_meta = (NvPosImageMeta *) pos_image_meta_copy_func(src_pos_meta, NULL);
  return (gpointer) dst_pos_meta;
}

/* release function set by user to release gst to nvds transformed metadata.
 * "data" holds a pointer to NvDsUserMeta */
static void
pos_image_gst_nvds_meta_release_func(gpointer data, gpointer user_data) {
  NvDsUserMeta *user_meta = (NvDsUserMeta *) data;
  NvPosImageMeta *pos_meta = (NvPosImageMeta *) user_meta->user_meta_data;
  pos_image_meta_release_func(pos_meta, NULL);
}

bool AddNvMetaToPosSrcBuffer(GstBuffer *buf, NvPosImageMeta* pos_meta) {
  if (pos_meta == NULL || buf == NULL) {
    return -1;
  }

  /* Attach decoder metadata to gst buffer using gst_buffer_add_nvds_meta() */
  NvDsMeta *meta = gst_buffer_add_nvds_meta(buf, pos_meta, NULL,
                                            pos_image_meta_copy_func,
                                            pos_image_meta_release_func);

  /* Set metadata type */
  meta->meta_type = (GstNvDsMetaType) NVDS_POS_IMAGE_GST_META;

  /* Set transform function to transform decoder metadata from Gst meta to
   * nvds meta */
  meta->gst_to_nvds_meta_transform_func = pos_image_gst_to_nvds_meta_transform_func;

  /* Set release function to release the transformed nvds metadata */
  meta->gst_to_nvds_meta_release_func = pos_image_gst_nvds_meta_release_func;

  return true;
}

add metadata


static gboolean read_data(AppSrcData *data) {
  ...

  GstMapInfo map;
  GstBuffer *buffer = gst_buffer_new_allocate(NULL, DEFAULT_FRAME_SIZE, NULL);
  if (gst_buffer_map(buffer, &map, GST_MAP_WRITE)) {
    NvPosImageMeta *pos_meta = (NvPosImageMeta *) g_malloc0(sizeof(NvPosImageMeta));
    if (pos_meta == NULL) {
      g_printerr("NvPosImageMeta g_malloc0 failed.\n");
      return FALSE;
    }

    size_t ret = data->reader->ReadImage(map.data, DEFAULT_FRAME_SIZE, pos_meta);
    if (ret > 0) {
      map.size = ret;

      AddNvMetaToPosSrcBuffer(buffer, pos_meta);
      GstFlowReturn gstret = gst_app_src_push_buffer((GstAppSrc *) data->app_source, buffer);
      if (gstret == GST_FLOW_OK) {
        ...
        g_print("gst_app_src_push_buffer success, %d.\n", data->frame_num);
      } else {
        g_print("gst_app_src_push_buffer returned %d \n", gstret);
      }
    } else {
      g_print("read image failed, w=%d, h=%d.\n", pos_meta->width, pos_meta->height);
      if (pos_meta != NULL) {
        g_free(pos_meta);
      }
    }
    gst_buffer_unmap(buffer, &map);
  }

  ...
  return TRUE;
}

i use gst_buffer_new_allocate allocate buffer and add usermeta as appsrc plugin read_data callback

There is no update from you for a period, assuming this is not an issue anymore.
Hence we are closing this topic. If need further support, please open a new one.
Thanks

  1. did you have same issue when using “appsrc->jpegparse->nvv4l2decoder”?
  2. seemed jpegdec didn’t copy meta from your test, please add log in pos_image_meta_copy_func or pos_image_gst_to_nvds_meta_transform_func to check if the mata data is copied.

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