libxcoder  5.2.0
ni_quadra_enc_api.c
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (C) 2022 NETINT Technologies
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18  * SOFTWARE.
19  *
20  ******************************************************************************/
21 
22 /*!*****************************************************************************
23  * \file ni_quadra_enc_api.c
24  *
25  * \brief Private definitions used by ni_quadra_enc_api.c for video processing
26  * tasks
27  ******************************************************************************/
28 
29 #include "ni_quadra_enc_api.h"
30 #include "ni_device_api.h"
31 #include "ni_defs.h"
32 #include "ni_rsrc_api.h"
33 #include "ni_util.h"
34 #include "ni_av_codec.h"
35 
37 {
38  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
39  ni_gop_params_check_set(p_param, key);
40 }
41 
43 {
44  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
45  return ni_gop_params_check(p_param);
46 }
47 
49  ni_quadra_enc_context_t *p_enc_ctx, const char *name, const char *value)
50 {
51  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
52  int parse_ret = ni_encoder_params_set_value(p_param, name, value);
53  if (parse_ret != NI_RETCODE_SUCCESS)
54  {
55  switch (parse_ret)
56  {
58  ni_log(NI_LOG_ERROR, "Unknown option: %s.\n", name);
59  return NI_RETCODE_FAILURE;
61  ni_log(NI_LOG_ERROR, "Invalid %s: too big\n", name);
62  return NI_RETCODE_FAILURE;
64  ni_log(NI_LOG_ERROR, "Invalid %s: too small\n", name);
65  return NI_RETCODE_FAILURE;
67  ni_log(NI_LOG_ERROR, "Invalid %s: out of range\n", name);
68  return NI_RETCODE_FAILURE;
70  ni_log(NI_LOG_ERROR, "Error setting option %s to value 0\n",
71  name);
72  return NI_RETCODE_FAILURE;
74  ni_log(NI_LOG_ERROR, "Invalid value for %s: %s.\n", name,
75  value);
76  return NI_RETCODE_FAILURE;
77  case NI_RETCODE_FAILURE:
79  "Generic failure during xcoder-params setting for %s\n",
80  name);
81  return NI_RETCODE_FAILURE;
83  ni_log(NI_LOG_INFO, "Parameter %s is deprecated\n", name);
85  break;
86  default:
87  ni_log(NI_LOG_ERROR, "Invalid %s: ret %d\n", name, parse_ret);
88  return NI_RETCODE_FAILURE;
89  }
90  }
91  return parse_ret;
92 }
93 
95  ni_quadra_enc_context_t *p_enc_ctx, const char *name, const char *value)
96 {
97  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
98  int parse_ret = ni_encoder_gop_params_set_value(p_param, name, value);
99  if (parse_ret != NI_RETCODE_SUCCESS)
100  {
101  // deprecated param will trigger warning, not error
102  // so do not free param dict for it
103  // if (parse_ret != NI_RETCODE_PARAM_WARNING_DEPRECATED)
104  // av_dict_free(&dict);
105  switch (parse_ret)
106  {
108  ni_log(NI_LOG_ERROR, "Unknown option: %s.\n", name);
109  return NI_RETCODE_FAILURE;
112  "Invalid custom GOP parameters: %s too big\n", name);
113  return NI_RETCODE_FAILURE;
116  "Invalid custom GOP parameters: %s too small\n", name);
117  return NI_RETCODE_FAILURE;
120  "Invalid custom GOP parameters: %s out of range \n",
121  name);
122  return NI_RETCODE_FAILURE;
125  "Invalid custom GOP paramaters: Error setting option %s "
126  "to value 0 \n",
127  name);
128  return NI_RETCODE_FAILURE;
130  ni_log(NI_LOG_ERROR, "Invalid value for GOP param %s: %s.\n",
131  name, value);
132  return NI_RETCODE_FAILURE;
133  case NI_RETCODE_FAILURE:
135  "Generic failure during xcoder-params setting for %s\n",
136  name);
137  return NI_RETCODE_FAILURE;
139  ni_log(NI_LOG_INFO, "Parameter %s is deprecated\n", name);
141  break;
142  default:
143  ni_log(NI_LOG_ERROR, "Invalid %s: ret %d\n", name, parse_ret);
144  return NI_RETCODE_FAILURE;
145  }
146  }
147  return parse_ret;
148 }
149 
150 static int
151 ni_xcoder_encoder_header_check_set(ni_quadra_enc_context_t *p_enc_ctx)
152 {
153  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
154  ni_xcoder_params_t *p_param;
155  p_param = (ni_xcoder_params_t *)p_session_ctx->p_session_config;
156  p_param->cfg_enc_params.videoFullRange = 0;
157 
158  // DolbyVision support
159  if (5 == p_param->dolby_vision_profile)
160  {
162  "dolbyVisionProfile is not supported on FFmpeg version 4.2.1 "
163  "and earlier.\n");
164  return -1;
165  }
166 
167  if (p_enc_ctx->color_primaries != 2 || p_enc_ctx->color_trc != 2 ||
168  p_enc_ctx->color_space != 2)
169  {
170  p_param->cfg_enc_params.colorDescPresent = 1;
171  p_param->cfg_enc_params.colorPrimaries = p_enc_ctx->color_primaries;
172  p_param->cfg_enc_params.colorTrc = p_enc_ctx->color_trc;
173  p_param->cfg_enc_params.colorSpace = p_enc_ctx->color_space;
174 
176  "XCoder HDR color info color_primaries: %d "
177  "color_trc: %d color_space %d\n",
178  p_enc_ctx->color_primaries, p_enc_ctx->color_trc,
179  p_enc_ctx->color_space);
180  }
181 
182  // for YUVJ420P pix fmt, indicate it's full range video
183  if (p_enc_ctx->color_range == 2 || 12 == p_enc_ctx->pix_fmt ||
185  {
186  p_param->cfg_enc_params.videoFullRange = 1;
187  }
188 
189  return 0;
190 }
191 
193 {
194  // use a copy of encoder context, take care to restore original config
195  // cropping setting
196  ni_xcoder_params_t *p_param;
197  ni_session_context_t *p_orig_session_ctx = p_enc_ctx->api_ctx;
198  ni_session_data_io_t *p_packet = p_enc_ctx->api_pkt;
199  ni_session_context_t session_ctx = {0};
200  ni_packet_t *xpkt;
201  int orig_conf_win_right;
202  int orig_conf_win_bottom;
203  int linesize_aligned, height_aligned;
204  int ret = 0, recv = 0, saved_ret = 0;
205 
206  memcpy(&session_ctx, p_enc_ctx->api_ctx, sizeof(ni_session_context_t));
207  p_param = (ni_xcoder_params_t *)p_orig_session_ctx->p_session_config;
208 
209  orig_conf_win_right = p_param->cfg_enc_params.conf_win_right;
210  orig_conf_win_bottom = p_param->cfg_enc_params.conf_win_bottom;
211  //p_enc_ctx->api_ctx = &session_ctx;
212  linesize_aligned = p_enc_ctx->width;
213  if (linesize_aligned < NI_MIN_WIDTH)
214  {
215  p_param->cfg_enc_params.conf_win_right +=
216  (NI_MIN_WIDTH - p_enc_ctx->width) / 2 * 2;
217  linesize_aligned = NI_MIN_WIDTH;
218  } else
219  {
220  if (p_enc_ctx->sw_pix_fmt ==
221  NI_QUADRA_PIX_FMT_8_TILED4X4 || //AV_PIX_FMT_NI_QUAD_8_TILE_4X4 ||
223  { //AV_PIX_FMT_NI_QUAD_10_TILE_4X4) {
224  linesize_aligned = NIALIGN(p_enc_ctx->width, 4);
225  p_param->cfg_enc_params.conf_win_right +=
226  (linesize_aligned - p_enc_ctx->width) / 2 * 2;
227  } else
228  {
229  linesize_aligned = NIALIGN(p_enc_ctx->width, 2);
230  p_param->cfg_enc_params.conf_win_right +=
231  (linesize_aligned - p_enc_ctx->width) / 2 * 2;
232  }
233  }
234  p_param->source_width = linesize_aligned;
235 
236  height_aligned = p_enc_ctx->height;
237  if (height_aligned < NI_MIN_HEIGHT)
238  {
239  p_param->cfg_enc_params.conf_win_bottom +=
240  (NI_MIN_HEIGHT - p_enc_ctx->height) / 2 * 2;
241  height_aligned = NI_MIN_HEIGHT;
242  } else
243  {
244  if (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_8_TILED4X4 ||
246  {
247  height_aligned = NIALIGN(p_enc_ctx->height, 4);
248  p_param->cfg_enc_params.conf_win_bottom +=
249  (height_aligned - p_enc_ctx->height) / 4 * 4;
250  } else
251  {
252  height_aligned = NIALIGN(p_enc_ctx->height, 2);
253  p_param->cfg_enc_params.conf_win_bottom +=
254  (height_aligned - p_enc_ctx->height) / 2 * 2;
255  }
256  }
257  p_param->source_height = height_aligned;
258 
259  session_ctx.hw_id = p_enc_ctx->dev_enc_idx;
260  ni_xcoder_strncpy(session_ctx.blk_dev_name, p_enc_ctx->dev_blk_name,
262  ni_xcoder_strncpy(session_ctx.dev_xcoder_name, p_enc_ctx->dev_xcoder,
264 
265  ret = ni_device_session_open(&session_ctx, NI_DEVICE_TYPE_ENCODER);
266 
267  p_enc_ctx->dev_xcoder_name = session_ctx.dev_xcoder_name;
268  p_enc_ctx->blk_xcoder_name = session_ctx.blk_xcoder_name;
269  p_enc_ctx->dev_enc_idx = session_ctx.hw_id;
270 
271  if (ret != 0)
272  {
274  "Failed to open encoder (status = %d), "
275  "critical error or resource unavailable\n",
276  ret);
277  ret = NI_RETCODE_FAILURE;
278  goto end;
279  } else
280  {
282  "XCoder %s Index %d (inst: %d) opened successfully\n",
283  p_enc_ctx->dev_xcoder_name, p_enc_ctx->dev_enc_idx,
284  session_ctx.session_id);
285  }
286 
287  xpkt = &p_packet->data.packet;
289 
290  while (1)
291  {
292  recv = ni_device_session_read(&session_ctx, p_packet,
294 
295  if (recv > 0)
296  {
297  p_enc_ctx->extradata_size = recv - (int)session_ctx.meta_size;
298  p_enc_ctx->extradata = malloc(p_enc_ctx->extradata_size);
299  if (!p_enc_ctx->extradata)
300  {
302  "ERROR %d:%s() line %d, alloc extradata failed\n",
303  NI_ERRNO, __FUNCTION__, __LINE__);
304  p_enc_ctx->extradata_size = 0;
306  } else
307  {
308  memset(p_enc_ctx->extradata, 0, p_enc_ctx->extradata_size);
309  memcpy(p_enc_ctx->extradata,
310  (uint8_t *)xpkt->p_data + session_ctx.meta_size,
311  p_enc_ctx->extradata_size);
312  }
313  ni_log(NI_LOG_DEBUG, "Xcoder encoder headers len: %d\n",
314  p_enc_ctx->extradata_size);
315  break;
316  } else if (recv == NI_RETCODE_SUCCESS)
317  {
318  continue;
319  } else
320  {
321  ni_log(NI_LOG_ERROR, "Xcoder encoder headers error: %d", recv);
322  break;
323  }
324  }
325 
326 end:
327  // close and clean up the temporary session
328  saved_ret = ret;
329 
330  ret = ni_device_session_close(&session_ctx, p_enc_ctx->encoder_eof,
332  ret = (ret < 0) ? ret : saved_ret;
333 
334 #ifdef _WIN32
335  ni_device_close(session_ctx.device_handle);
336 #elif __linux__
337  ni_device_close(session_ctx.device_handle);
338  ni_device_close(session_ctx.blk_io_handle);
339 #endif
340  session_ctx.device_handle = NI_INVALID_DEVICE_HANDLE;
341  session_ctx.blk_io_handle = NI_INVALID_DEVICE_HANDLE;
342 
343  ni_packet_buffer_free(&(p_packet->data.packet));
344 
345  p_param->cfg_enc_params.conf_win_right = orig_conf_win_right;
346  p_param->cfg_enc_params.conf_win_bottom = orig_conf_win_bottom;
347  p_enc_ctx->api_ctx = p_orig_session_ctx;
348  return (recv < 0 ? recv : ret);
349 }
350 
351 static int ni_quadra_to_ni_pix_fmt(ni_quadra_enc_context_t *p_enc_ctx)
352 {
353  int pixel_format;
354  switch (p_enc_ctx->sw_pix_fmt)
355  {
358  pixel_format = NI_PIX_FMT_YUV420P;
359  break;
361  pixel_format = NI_PIX_FMT_P010LE;
362  break;
364  pixel_format = NI_PIX_FMT_YUV420P10LE;
365  break;
367  pixel_format = NI_PIX_FMT_ARGB;
368  break;
370  pixel_format = NI_PIX_FMT_ABGR;
371  break;
373  pixel_format = NI_PIX_FMT_RGBA;
374  break;
376  pixel_format = NI_PIX_FMT_BGRA;
377  break;
379  pixel_format = NI_PIX_FMT_NV12;
380  break;
382  pixel_format = NI_PIX_FMT_8_TILED4X4;
383  break;
385  pixel_format = NI_PIX_FMT_10_TILED4X4;
386  break;
387  default:
388  ni_log(NI_LOG_ERROR, "Pixfmt %d not supported in Quadra encoder\n",
389  p_enc_ctx->pix_fmt);
390  return NI_RETCODE_FAILURE;
391  }
392  return pixel_format;
393 }
394 
396 {
397  int ret = 0;
398  uint32_t xcoder_timeout;
399  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
400  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
401  ni_xcoder_params_t *pparams = NULL;
402  ni_session_data_io_t *p_packet = p_enc_ctx->api_pkt;
403  ni_session_data_io_t *p_frame = p_enc_ctx->api_fme;
404  p_session_ctx->codec_format = p_enc_ctx->codec_format;
405 
406  p_enc_ctx->firstPktArrived = 0;
407  p_enc_ctx->spsPpsArrived = 0;
408  p_enc_ctx->spsPpsHdrLen = 0;
409  p_enc_ctx->p_spsPpsHdr = NULL;
410  p_enc_ctx->xcode_load_pixel = 0;
411  p_enc_ctx->reconfigCount = 0;
412  p_enc_ctx->gotPacket = 0;
413  p_enc_ctx->sentFrame = 0;
414  p_enc_ctx->latest_dts = 0;
415  p_enc_ctx->eos_fme_received = 0;
416 
417  #ifdef MEASURE_LATENCY
418  p_enc_ctx->enable_test_latency = 1;
419  #else
420  p_enc_ctx->enable_test_latency = 0;
421  #endif
422 
423  ret = ni_quadra_to_ni_pix_fmt(p_enc_ctx);
424  if (ret < 0) {
425  return NI_RETCODE_FAILURE;
426  }
427  else {
428  p_session_ctx->pixel_format = ret;
429  }
430 
431  if (p_param->enable_vfr)
432  {
433  // in the vfr mode, if the initial framerate is out of [5-120]
434  // think the initial framerate is incorrect, set it to default 30 fps
435  if (p_param->cfg_enc_params.frame_rate < 5 ||
436  p_param->cfg_enc_params.frame_rate > 120)
437  {
438  p_param->cfg_enc_params.frame_rate = 30;
439  p_session_ctx->prev_fps = 30;
440  } else
441  {
442  p_session_ctx->prev_fps = p_param->cfg_enc_params.frame_rate;
443  }
444  p_session_ctx->last_change_framenum = 0;
445  p_session_ctx->fps_change_detect_count = 0;
446  }
447 
448  if (p_enc_ctx->nvme_io_size > 0 && p_enc_ctx->nvme_io_size % 4096 != 0)
449  {
450  ni_log(NI_LOG_ERROR, "Error XCoder iosize is not 4KB aligned!\n");
451  return NI_RETCODE_FAILURE;
452  }
453 
454  p_session_ctx->p_session_config = p_enc_ctx->api_param;
455  pparams = (ni_xcoder_params_t *)p_session_ctx->p_session_config;
456 
457  // keep dtsOffset in case of sequence change
459  p_session_ctx->session_run_state)
460  {
461  switch (pparams->cfg_enc_params.gop_preset_index)
462  {
463  /* dtsOffset is the max number of non-reference frames in a GOP
464  * (derived from x264/5 algo) In case of IBBBP the first dts of the I
465  * frame should be input_pts-(3*ticks_per_frame) In case of IBP the
466  * first dts of the I frame should be input_pts-(1*ticks_per_frame)
467  * thus we ensure pts>dts in all cases
468  * */
469  case 1:
470  case 9:
471  case 10:
472  p_enc_ctx->dts_offset = 0;
473  break;
474  /* ts requires dts/pts of I fraem not same when there are B frames in
475  * streams */
476  case 3:
477  case 4:
478  case 7:
479  p_enc_ctx->dts_offset = 1;
480  break;
481  case 5:
482  p_enc_ctx->dts_offset = 2;
483  break;
484  case -1: // adaptive GOP
485  case 8:
486  p_enc_ctx->dts_offset = 3;
487  break;
488  default:
489  p_enc_ctx->dts_offset = 7;
490  break;
491  }
493  {
494  int dts_offset = 0;
495  p_enc_ctx->dts_offset = 0;
496  bool has_b_frame = false;
497  for (int idx = 0; idx <
499  idx++)
500  {
501  if (pparams->cfg_enc_params.custom_gop_params.pic_param[idx]
502  .poc_offset < idx + 1)
503  {
504  dts_offset = (idx + 1) -
506  .poc_offset;
507  if (p_enc_ctx->dts_offset < dts_offset)
508  {
509  p_enc_ctx->dts_offset = dts_offset;
510  }
511  }
512  if (!has_b_frame &&
514  .pic_type == PIC_TYPE_B))
515  {
516  has_b_frame = true;
517  }
518  }
519 
520  if (has_b_frame && !p_enc_ctx->dts_offset)
521  {
522  p_enc_ctx->dts_offset = 1;
523  }
524  }
525  ni_log(NI_LOG_DEBUG, "dts offset set to %ld\n", p_enc_ctx->dts_offset);
526  }
527 
528  p_enc_ctx->total_frames_received = 0;
529  p_enc_ctx->gop_offset_count = 0;
530  ni_log(NI_LOG_DEBUG, "dts offset: %" PRId64 ", gop_offset_count: %d\n",
531  p_enc_ctx->dts_offset, p_enc_ctx->gop_offset_count);
532 
533  //overwrite the nvme io size here with a custom value if it was provided
534  if (p_enc_ctx->nvme_io_size > 0)
535  {
536  p_session_ctx->max_nvme_io_size = p_enc_ctx->nvme_io_size;
537  ni_log(NI_LOG_INFO, "Custom NVMe IO Size set to = %d\n",
538  p_session_ctx->max_nvme_io_size);
539  }
540  // overwrite keep alive timeout value here with a custom value if it was
541  // provided
542  // if xcoder option is set then overwrite the (legacy) decoder option
543  xcoder_timeout = p_param->cfg_enc_params.keep_alive_timeout;
544  if (xcoder_timeout != NI_DEFAULT_KEEP_ALIVE_TIMEOUT)
545  {
546  p_session_ctx->keep_alive_timeout = xcoder_timeout;
547  } else
548  {
549  p_session_ctx->keep_alive_timeout = p_enc_ctx->keep_alive_timeout;
550  }
551  ni_log(NI_LOG_DEBUG, "Custom NVME Keep Alive Timeout set to = %d\n",
552  p_session_ctx->keep_alive_timeout);
553  p_enc_ctx->encoder_eof = 0;
554  p_enc_ctx->encoder_flushing = 0;
555  if (!p_enc_ctx->is_swframes)
556  {
557  if ((p_enc_ctx->height >= NI_MIN_HEIGHT) &&
558  (p_enc_ctx->width >= NI_MIN_WIDTH))
559  {
560  p_param->hwframes = 1;
561  } else if (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_8_TILED4X4 ||
563  {
565  "Invalid Picture Height or Width: too small\n");
566  return NI_RETCODE_FAILURE;
567  }
568  }
569 
570  ni_log(NI_LOG_INFO, "p_param->hwframes = %d\n", p_param->hwframes);
571  p_session_ctx->roi_len = 0;
572  p_session_ctx->roi_avg_qp = 0;
573  p_session_ctx->src_bit_depth = 8;
574  p_session_ctx->src_endian = NI_FRAME_LITTLE_ENDIAN;
575  p_session_ctx->bit_depth_factor = 1;
576 
577  if (NI_QUADRA_PIX_FMT_YUV420P10BE == p_enc_ctx->sw_pix_fmt ||
578  NI_QUADRA_PIX_FMT_YUV420P10LE == p_enc_ctx->sw_pix_fmt ||
579  NI_QUADRA_PIX_FMT_P010LE == p_enc_ctx->sw_pix_fmt ||
581  {
582  p_session_ctx->bit_depth_factor = 2;
583  p_session_ctx->src_bit_depth = 10;
584  if (NI_QUADRA_PIX_FMT_YUV420P10BE == p_enc_ctx->sw_pix_fmt)
585  {
586  p_session_ctx->src_endian = NI_FRAME_BIG_ENDIAN;
587  }
588  }
589 
590  switch (p_enc_ctx->sw_pix_fmt)
591  {
595  break;
599  break;
600  default:
602  break;
603  }
604 
605  p_enc_ctx->user_sar_num = 0;
606  p_enc_ctx->user_sar_den = 1;
607  // check user set sar
608  if (pparams->cfg_enc_params.aspectRatioWidth != p_enc_ctx->sar_num ||
609  pparams->cfg_enc_params.aspectRatioHeight != p_enc_ctx->sar_den)
610  {
611  p_enc_ctx->user_sar_num = pparams->cfg_enc_params.aspectRatioWidth;
612  p_enc_ctx->user_sar_den = pparams->cfg_enc_params.aspectRatioHeight;
613  }
614 
615  // init HDR SEI stuff
616  p_session_ctx->sei_hdr_content_light_level_info_len =
617  p_session_ctx->light_level_data_len =
619  p_session_ctx->mdcv_max_min_lum_data_len = 0;
620  p_session_ctx->p_master_display_meta_data = NULL;
621 
622  p_packet->data.packet.av1_buffer_index = 0;
623  if (p_enc_ctx->width > 0 && p_enc_ctx->height > 0)
624  {
625  bool isnv12frame = (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_NV12 ||
626  p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_P010LE);
627  ni_frame_buffer_alloc(&p_frame->data.frame,
628  NIODD2EVEN(p_enc_ctx->width),
629  NIODD2EVEN(p_enc_ctx->height), 0, 0,
630  p_session_ctx->bit_depth_factor, 1, !isnv12frame);
631  }
632 
633  if (ni_xcoder_encoder_header_check_set(p_enc_ctx) < 0)
634  {
635  return NI_RETCODE_FAILURE;
636  }
637 
638  // original resolution this stream started with, this is used in encoder
639  // sequence change
640  p_session_ctx->ori_width = p_enc_ctx->width;
641  p_session_ctx->ori_height = p_enc_ctx->height;
642  p_session_ctx->ori_bit_depth_factor = p_session_ctx->bit_depth_factor;
643  p_session_ctx->ori_pix_fmt = p_session_ctx->pixel_format;
644 
646  "ni_quadra_setup_encoder "
647  "sw_pix_fmt %d ori_pix_fmt %d\n",
648  p_enc_ctx->sw_pix_fmt, p_session_ctx->ori_pix_fmt);
649 
650  p_session_ctx->ori_luma_linesize = 0;
651  p_session_ctx->ori_chroma_linesize = 0;
652  p_enc_ctx->bit_rate = pparams->bitrate;
653  if (p_param->cfg_enc_params.get_psnr_mode != 3)
654  {
655  p_enc_ctx->bget_psnr = 1;
656  }
657  else
658  {
659  p_enc_ctx->bget_psnr = 0;
660  }
661 
662 #define NI_CODEC_ID_MJPEG 8
663  if ((pparams->generate_enc_hdrs || p_enc_ctx->generate_enc_hdrs) && \
664  p_enc_ctx->codec_id != NI_CODEC_ID_MJPEG)
665  {
666  ret = ni_quadra_xcoder_encoder_headers(p_enc_ctx);
667  }
668 #undef NI_CODEC_ID_MJPEG
669  return ret;
670 }
671 
673 {
674  ni_xcoder_params_t *p_param = NULL;
675  ni_session_context_t *p_session_ctx = NULL;
676  ni_session_data_io_t *p_session_data_fme = NULL;
677  ni_session_data_io_t *p_session_data_pkt = NULL;
678  ni_frame_t *p_input_frame = NULL;
679  ni_session_run_state_t prev_state;
680  int ret = NI_RETCODE_SUCCESS;
681  int i;
682 
684  ni_log(NI_LOG_DEBUG, "XCoder setup device encoder\n");
685 
686  if (!p_enc_ctx->api_ctx || !p_enc_ctx->api_param)
687  {
688  p_session_data_fme = malloc(sizeof(ni_session_data_io_t));
689  if (!p_session_data_fme)
690  {
692  "ERROR %d:%s() line %d, alloc p_session_data frame failed\n",
693  NI_ERRNO, __FUNCTION__, __LINE__);
695  LRETURN;
696  } else
697  {
698  p_enc_ctx->api_fme = p_session_data_fme;
699  }
700  p_session_data_pkt = malloc(sizeof(ni_session_data_io_t));
701  if (!p_session_data_pkt)
702  {
704  "ERROR %d:%s() line %d, alloc p_session_data pkt failed\n",
705  NI_ERRNO, __FUNCTION__, __LINE__);
707  LRETURN;
708  } else
709  {
710  p_enc_ctx->api_pkt = p_session_data_pkt;
711  }
712  p_input_frame = malloc(sizeof(ni_frame_t));
713  if (!p_input_frame)
714  {
716  "ERROR %d:%s() line %d, alloc p_input_frame failed\n", NI_ERRNO,
717  __FUNCTION__, __LINE__);
719  LRETURN;
720  } else
721  {
722  p_enc_ctx->input_frame = p_input_frame;
723  }
724  // Xcoder Session Context
725  p_session_ctx = malloc(sizeof(ni_session_context_t));
726  if (!p_session_ctx)
727  {
729  "ERROR %d:%s() line %d, alloc session context failed\n",
730  NI_ERRNO, __FUNCTION__, __LINE__);
732  LRETURN;
733  } else
734  {
735  memset(p_session_ctx, 0, sizeof(ni_session_context_t));
736  p_enc_ctx->api_ctx = p_session_ctx;
737  }
738 
739  p_param = malloc(sizeof(ni_xcoder_params_t));
740  if (!p_param)
741  {
743  "ERROR %d:%s() line %d, alloc session context failed\n",
744  NI_ERRNO, __FUNCTION__, __LINE__);
746  LRETURN;
747  } else
748  {
749  p_enc_ctx->api_param = p_param;
750  }
751  }
752  else
753  {
754  ni_log(NI_LOG_DEBUG, "api_ctx and api_param had alloced\n");
755  p_session_ctx = p_enc_ctx->api_ctx;
756  p_param = p_enc_ctx->api_param;
757  }
758 
759  memset(p_enc_ctx->api_fme, 0, sizeof(ni_session_data_io_t));
760  memset(p_enc_ctx->api_pkt, 0, sizeof(ni_session_data_io_t));
761  memset(p_enc_ctx->input_frame, 0, sizeof(ni_frame_t));
762  prev_state = p_session_ctx->session_run_state;
763  if (p_session_ctx->session_run_state ==
765  {
766  p_enc_ctx->dev_enc_idx = p_enc_ctx->orig_dev_enc_idx;
767  } else
768  {
769  p_enc_ctx->orig_dev_enc_idx = p_enc_ctx->dev_enc_idx;
770  }
771 
772  //p_session_ctx->session_id = NI_INVALID_SESSION_ID;
773  if (ni_device_session_context_init(p_session_ctx) < 0)
774  {
775  ni_log(NI_LOG_ERROR, "Error XCoder init encoder context failure\n");
776  return NI_RETCODE_FAILURE;
777  }
778  p_session_ctx->session_run_state = prev_state;
779 
780  //Xcoder User Configuration
782  p_param, p_enc_ctx->framerate_num, p_enc_ctx->framerate_den,
783  p_enc_ctx->bit_rate, p_enc_ctx->width, p_enc_ctx->height,
784  p_enc_ctx->codec_format);
785 
786  switch (ret)
787  {
789  ni_log(NI_LOG_ERROR, "Invalid Picture Width: too big\n");
790  return NI_RETCODE_FAILURE;
792  ni_log(NI_LOG_ERROR, "Invalid Picture Width: too small\n");
793  return NI_RETCODE_FAILURE;
795  ni_log(NI_LOG_ERROR, "Invalid Picture Height: too big\n");
796  return NI_RETCODE_FAILURE;
798  ni_log(NI_LOG_ERROR, "Invalid Picture Height: too small\n");
799  return NI_RETCODE_FAILURE;
801  ni_log(NI_LOG_ERROR, "Invalid Picture Width x Height: exceeds %d\n",
803  return NI_RETCODE_FAILURE;
805  ni_log(NI_LOG_ERROR, "Invalid Picture Width\n");
806  return NI_RETCODE_FAILURE;
808  ni_log(NI_LOG_ERROR, "Invalid Picture Height\n");
809  return NI_RETCODE_FAILURE;
810  default:
811  if (ret < 0)
812  {
813  ni_log(NI_LOG_ERROR, "Error setting preset or log.\n");
814  ni_log(NI_LOG_INFO, "Possible presets:");
815  for (i = 0; g_xcoder_preset_names[i]; i++)
817  ni_log(NI_LOG_INFO, "\n");
818 
819  ni_log(NI_LOG_INFO, "Possible log:");
820  for (i = 0; g_xcoder_log_names[i]; i++)
822  ni_log(NI_LOG_INFO, "\n");
823 
824  return -22;
825  }
826  break;
827  }
828  if (p_param->cfg_enc_params.aspectRatioWidth == 0 &&
829  p_param->cfg_enc_params.aspectRatioHeight == 1)
830  {
831  p_param->cfg_enc_params.aspectRatioWidth = p_enc_ctx->sar_num;
832  p_param->cfg_enc_params.aspectRatioHeight = p_enc_ctx->sar_den;
833  ni_log(NI_LOG_DEBUG, "%s sar set to %d:%d\n", __func__,
836  }
837  return ret;
838 
839 end:
840  if (ret != NI_RETCODE_SUCCESS)
841  {
842  free(p_session_ctx);
843  p_enc_ctx->api_ctx = NULL;
844  free(p_session_data_fme);
845  p_enc_ctx->api_fme = NULL;
846  free(p_input_frame);
847  p_enc_ctx->input_frame = NULL;
848  free(p_session_data_pkt);
849  p_enc_ctx->api_pkt = NULL;
850  free(p_param);
851  p_enc_ctx->api_param = NULL;
852  }
853  return ret;
854 }
855 
857 {
858  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
859  int ret = 0;
860  ni_session_data_io_t *ni_frame = p_enc_ctx->api_fme;
861  ni_session_data_io_t *ni_packet = p_enc_ctx->api_pkt;
862  ret = ni_device_session_close(p_session_ctx, p_enc_ctx->encoder_eof,
864  if (NI_RETCODE_SUCCESS != ret)
865  {
866  ni_log(NI_LOG_ERROR, "Failed to close Encoder Session (status = %d)\n",
867  ret);
868  }
869 
870  if (ni_frame->data.frame.buffer_size ||
871  ni_frame->data.frame.metadata_buffer_size ||
872  ni_frame->data.frame.start_buffer_size)
873  {
874  ni_frame_buffer_free(&(ni_frame->data.frame));
875  }
876  ni_packet_buffer_free(&(ni_packet->data.packet));
877  ni_log(NI_LOG_DEBUG, "XCoder encode close (status = %d)\n", ret);
878  ni_device_session_context_clear(p_session_ctx);
879 
880  ni_log(NI_LOG_INFO, "XCoder encode close: session_run_state %d\n",
881  p_session_ctx->session_run_state);
882  if (p_session_ctx->session_run_state !=
884  {
886  "XCoder encode close: close blk_io_handle %d device_handle %d\n",
887  p_session_ctx->blk_io_handle, p_session_ctx->device_handle);
888 #ifdef _WIN32
889  ni_device_close(p_session_ctx->device_handle);
890 #elif __linux__
891  ni_device_close(p_session_ctx->device_handle);
892  ni_device_close(p_session_ctx->blk_io_handle);
893 #endif
894  p_session_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
895  p_session_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
896  p_session_ctx->auto_dl_handle = NI_INVALID_DEVICE_HANDLE;
897  p_session_ctx->sender_handle = NI_INVALID_DEVICE_HANDLE;
898  // ni_device_session_context_clear(p_session_ctx);
899  if (p_enc_ctx->api_ctx)
900  free(p_enc_ctx->api_ctx);
901  p_enc_ctx->api_ctx = NULL;
902  p_session_ctx = NULL;
903  if (p_enc_ctx->api_fme)
904  free(p_enc_ctx->api_fme);
905  p_enc_ctx->api_fme = NULL;
906  if (p_enc_ctx->input_frame)
907  free(p_enc_ctx->input_frame);
908  p_enc_ctx->input_frame = NULL;
909  if (p_enc_ctx->api_pkt)
910  free(p_enc_ctx->api_pkt);
911  p_enc_ctx->api_pkt = NULL;
912  if (p_enc_ctx->api_param)
913  free(p_enc_ctx->api_param);
914  p_enc_ctx->api_param = NULL;
915  }
916 
917  free(p_enc_ctx->g_enc_change_params);
918  p_enc_ctx->g_enc_change_params = NULL;
919  free(p_enc_ctx->p_spsPpsHdr);
920  p_enc_ctx->p_spsPpsHdr = NULL;
921  p_enc_ctx->started = 0;
922 
923  return 0;
924 }
925 
927  int width, int height,
928  int bit_depth_factor)
929 {
930  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
931  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
932  ni_xcoder_params_t *pparams =
933  (ni_xcoder_params_t *)p_session_ctx->p_session_config;
934  ni_session_data_io_t *ni_packet = p_enc_ctx->api_pkt;
935  int ret = 0;
937  "ni_quadra_encode_sequence_change encode sequence change: "
938  "session_run_state: %d\n",
939  p_session_ctx->session_run_state);
941  p_session_ctx, width, height, bit_depth_factor, NI_DEVICE_TYPE_ENCODER);
942 
943  if (NI_RETCODE_SUCCESS != ret)
944  {
946  "Failed to send Sequence Change to Encoder "
947  "Session (status = %d)\n",
948  ret);
949  return ret;
950  }
951  if (!p_enc_ctx->is_swframes)
952  {
953  if (p_enc_ctx->height >= NI_MIN_HEIGHT &&
954  p_enc_ctx->width >= NI_MIN_WIDTH)
955  {
956  p_param->hwframes = 1;
957  }
958  }
959 
960  // update session context
961  p_session_ctx->bit_depth_factor = bit_depth_factor;
962  p_session_ctx->src_bit_depth = (bit_depth_factor == 1) ? 8 : 10;
963  p_session_ctx->src_endian =
964  (NI_QUADRA_PIX_FMT_YUV420P10BE == p_enc_ctx->sw_pix_fmt) ?
967  p_session_ctx->ready_to_close = 0;
968  // need to reset frame_num because pkt_num is set to 1 when header received
969  // after sequnce change, and low delay mode compares frame_num and pkt_num
970  p_session_ctx->frame_num = 0;
971  // also need to reset pkt_num because before header received,
972  // pkt_num > frame_num will also cause low delay mode stuck
973  p_session_ctx->pkt_num = 0;
974  ni_packet->data.packet.end_of_stream = 0;
975 
976  switch (p_enc_ctx->sw_pix_fmt)
977  {
981  break;
985  break;
986  default:
988  break;
989  }
990  return ret;
991 }
992 
994  int frame_width, int frame_height,
995  const int *frame_linesize,
996  niquadraFrameSurface1_t *p_surface,
997  bool hw_frames_ctx, int frame_queqe,
998  int avctx_flags)
999 {
1000  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
1001  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
1002  ni_session_data_io_t *p_niframe = p_enc_ctx->api_fme;
1003  int ret = 0;
1004  int bIsCenter = 0;
1005  if (p_enc_ctx->started == 0)
1006  {
1007  // adjust sample aspect ratio based on: user config, incoming decoded
1008  // frame and session context, in that order.
1009  if (p_enc_ctx->user_sar_num == 0 && p_enc_ctx->user_sar_den == 1)
1010  {
1011  if (p_param->cfg_enc_params.aspectRatioWidth !=
1012  p_enc_ctx->sar_num ||
1013  p_param->cfg_enc_params.aspectRatioHeight != p_enc_ctx->sar_den)
1014  {
1015  p_param->cfg_enc_params.aspectRatioWidth = p_enc_ctx->sar_num;
1016  p_param->cfg_enc_params.aspectRatioHeight = p_enc_ctx->sar_den;
1017  ni_log(NI_LOG_DEBUG, "%s sar set to %d:%d\n", __func__,
1020  }
1021  }
1022 
1023  int linesize_aligned = frame_width;
1024  if (linesize_aligned < NI_MIN_WIDTH)
1025  {
1026  p_param->cfg_enc_params.conf_win_right +=
1027  (NI_MIN_WIDTH - frame_width) / 2 * 2;
1028  linesize_aligned = NI_MIN_WIDTH;
1029  } else
1030  {
1031  linesize_aligned = NIALIGN(frame_width, 2);
1032  p_param->cfg_enc_params.conf_win_right +=
1033  (linesize_aligned - frame_width) / 2 * 2;
1034  }
1035  p_param->source_width = linesize_aligned;
1036 
1037  int height_aligned = frame_height;
1038  if (height_aligned < NI_MIN_HEIGHT)
1039  {
1040  p_param->cfg_enc_params.conf_win_bottom +=
1041  (NI_MIN_HEIGHT - frame_height) / 2 * 2;
1042  height_aligned = NI_MIN_HEIGHT;
1043  } else
1044  {
1045  height_aligned = NIALIGN(frame_height, 2);
1046  p_param->cfg_enc_params.conf_win_bottom +=
1047  (height_aligned - frame_height) / 2 * 2;
1048  }
1049  p_param->source_height = height_aligned;
1050  ret = ni_quadra_to_ni_pix_fmt(p_enc_ctx);
1051  if (ret < 0) {
1052  return NI_RETCODE_FAILURE;
1053  }
1054  else {
1055  p_session_ctx->pixel_format = ret;
1056  }
1057  if (ni_xcoder_encoder_header_check_set(p_enc_ctx) < 0)
1058  {
1059  return NI_RETCODE_FAILURE;
1060  }
1061  ni_log(
1062  NI_LOG_INFO,
1063  "width/height %dx%d conf_win_right %d conf_win_bottom %d , "
1064  "color primaries %u trc %u space %u\n",
1065  frame_width, frame_height, p_param->cfg_enc_params.conf_win_right,
1066  p_param->cfg_enc_params.conf_win_bottom, p_enc_ctx->color_primaries,
1067  p_enc_ctx->color_trc, p_enc_ctx->color_space);
1069  p_session_ctx->session_run_state)
1070  {
1071  // sequence change backup / restore encoder device handles, hw_id
1072  // and block device name, so no need to overwrite
1073  // hw_id/blk_dev_name to user set values
1074  p_session_ctx->hw_id = p_enc_ctx->dev_enc_idx;
1075  ni_xcoder_strncpy(p_session_ctx->dev_xcoder_name,
1076  p_enc_ctx->dev_xcoder, MAX_CHAR_IN_DEVICE_NAME);
1077 
1078  ni_xcoder_strncpy(p_session_ctx->blk_dev_name,
1079  p_enc_ctx->dev_blk_name, NI_MAX_DEVICE_NAME_LEN);
1080  }
1081  p_param->rootBufId =
1082  p_enc_ctx->is_swframes ? 0 : p_surface->ui16FrameIdx;
1083 
1084  if (!p_enc_ctx->is_swframes)
1085  {
1086  p_param->hwframes = 1;
1087  // if HW frame does not meet minimal resolution requirement, set
1088  // to SW frame encode.
1089  if (p_enc_ctx->height < NI_MIN_HEIGHT ||
1090  p_enc_ctx->width < NI_MIN_WIDTH)
1091  {
1092  p_param->hwframes = 0;
1093  }
1094  p_session_ctx->hw_action = NI_CODEC_HW_ENABLE;
1095  p_session_ctx->sender_handle =
1096  (ni_device_handle_t)((int64_t)p_surface->device_handle);
1097  }
1098 
1099  if (hw_frames_ctx && p_session_ctx->hw_id == -1 &&
1100  0 == strcmp(p_session_ctx->blk_dev_name, ""))
1101  {
1102  p_session_ctx->hw_id = frame_queqe;
1103  ni_log(
1104  NI_LOG_INFO,
1105  "xcoder_send_frame: hw_id -1, empty blk_dev_name, collocated "
1106  "to %d\n",
1107  p_session_ctx->hw_id);
1108  }
1109  // AUD insertion has to be handled differently in the firmware
1110  // if it is global header
1111  if (p_param->cfg_enc_params.EnableAUD)
1112  {
1113  if (avctx_flags & NI_CODEC_FLAG_GLOBAL_HEADER)
1114  {
1115  p_param->cfg_enc_params.EnableAUD =
1117  }
1118 
1119  ni_log(NI_LOG_INFO, "%s: EnableAUD %d global header flag %d\n",
1120  __FUNCTION__, (p_param->cfg_enc_params.EnableAUD),
1121  (avctx_flags & NI_CODEC_FLAG_GLOBAL_HEADER) ? 1 : 0);
1122  }
1123 
1124  // config linesize for zero copy (if input resolution is zero copy compatible)
1125  ni_encoder_frame_zerocopy_check(p_session_ctx, p_param, frame_width,
1126  frame_height,
1127  (const int *)frame_linesize, true);
1128 
1129  ret = ni_device_session_open(p_session_ctx, NI_DEVICE_TYPE_ENCODER);
1130  // // As the file handle may change we need to assign back
1131  p_enc_ctx->dev_xcoder_name = p_session_ctx->dev_xcoder_name;
1132  p_enc_ctx->blk_xcoder_name = p_session_ctx->blk_xcoder_name;
1133  p_enc_ctx->dev_enc_idx = p_session_ctx->hw_id;
1134  switch (ret)
1135  {
1136  case NI_RETCODE_SUCCESS:
1138  "XCoder %s.%d (inst: %d) opened successfully\n",
1139  p_enc_ctx->dev_xcoder_name, p_enc_ctx->dev_enc_idx,
1140  p_session_ctx->session_id);
1141  break;
1143  ni_log(
1144  NI_LOG_ERROR,
1145  "Failed to open encoder (status = %d), invalid parameter "
1146  "values given: %s\n",
1147  ret, p_session_ctx->param_err_msg);
1148  ni_device_session_close(p_session_ctx, p_enc_ctx->encoder_eof,
1150  ni_device_session_context_clear(p_session_ctx);
1151  ret = NI_RETCODE_FAILURE;
1152  return ret;
1153  default:
1155  "Failed to open encoder (status = %d), "
1156  "resource unavailable\n",
1157  ret);
1158  ni_device_session_close(p_session_ctx, p_enc_ctx->encoder_eof,
1160  ni_device_session_context_clear(p_session_ctx);
1161  ret = NI_RETCODE_FAILURE;
1162  return ret;
1163  }
1164 
1165  if (p_param->cfg_enc_params.roi_enable &&
1166  (1 == p_param->roi_demo_mode || 2 == p_param->roi_demo_mode))
1167  {
1168  if (ni_set_demo_roi_map(p_enc_ctx->api_ctx) < 0)
1169  {
1171  }
1172  } // roi_enable && roi_demo_mode
1173  } // p_enc_ctx->started == 0
1174 
1175  if (p_enc_ctx->started == 0)
1176  {
1177  p_niframe->data.frame.start_of_stream = 1;
1178  p_enc_ctx->started = 1;
1179  } else if (p_session_ctx->session_run_state ==
1181  {
1182  p_niframe->data.frame.start_of_stream = 1;
1183  } else
1184  {
1185  p_niframe->data.frame.start_of_stream = 0;
1186  }
1188  p_niframe->data.frame.end_of_stream = 0;
1189  p_niframe->data.frame.force_key_frame =
1191  p_niframe->data.frame.use_long_term_ref = 0;
1192 
1193  p_niframe->data.frame.sei_total_len = p_niframe->data.frame.sei_cc_offset =
1194  p_niframe->data.frame
1195  .sei_cc_len = p_niframe->data.frame
1200  p_niframe->data.frame.sei_hdr_plus_offset =
1201  p_niframe->data.frame.sei_hdr_plus_len = 0;
1202 
1203  p_niframe->data.frame.roi_len = 0;
1204  p_niframe->data.frame.reconf_len = 0;
1205  p_niframe->data.frame.force_pic_qp = 0;
1206 
1207  return ret;
1208 }
1209 
1211  niquadraFrameSurface1_t *p_surface,
1212  int frame_width, int frame_height)
1213 {
1214  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
1215  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
1216  ni_session_data_io_t *p_niframe = p_enc_ctx->api_fme;
1217  ni_frame_t *p_input_frame = p_enc_ctx->input_frame;
1218  ni_aux_data_t *aux_data = NULL;
1219  int ret = 0;
1220  memset(p_input_frame, 0, sizeof(ni_frame_t));
1221  p_enc_ctx->need_free_frame = 0;
1222  //pass the frame_pts to niframe
1223  p_niframe->data.frame.pts = p_enc_ctx->frame_pts;
1224  p_niframe->data.frame.dts = p_enc_ctx->pkt_dts;
1225  if (!p_enc_ctx->eos_fme_received)
1226  {
1227  int8_t bit_depth = 1;
1228  if (!p_enc_ctx->is_swframes)
1229  {
1230  if (p_session_ctx->pixel_format == NI_PIX_FMT_RGBA ||
1231  p_session_ctx->pixel_format == NI_PIX_FMT_BGRA ||
1232  p_session_ctx->pixel_format == NI_PIX_FMT_ARGB ||
1233  p_session_ctx->pixel_format == NI_PIX_FMT_ABGR)
1234  bit_depth = 1;
1235  else
1236  bit_depth = p_surface->bit_depth;
1237 
1238  switch (bit_depth)
1239  {
1240  case 1:
1241  case 2:
1242  break;
1243  default:
1244  ni_log(NI_LOG_ERROR, "ERROR: Unknown bit depth %d!\n",
1245  bit_depth);
1246  return NI_RETCODE_FAILURE;
1247  }
1248  } else
1249  {
1250  if (NI_QUADRA_PIX_FMT_YUV420P10BE == p_enc_ctx->sw_pix_fmt ||
1251  NI_QUADRA_PIX_FMT_YUV420P10LE == p_enc_ctx->sw_pix_fmt ||
1252  NI_QUADRA_PIX_FMT_P010LE == p_enc_ctx->sw_pix_fmt)
1253  {
1254  bit_depth = 2;
1255  }
1256  }
1257  if ((frame_height && frame_width) &&
1258  (frame_height != p_enc_ctx->height ||
1259  frame_width != p_enc_ctx->width) ||
1260  bit_depth != p_session_ctx->bit_depth_factor ||
1261  p_enc_ctx->color_change == 1)
1262  {
1264  "xcoder_send_frame resolution change %dx%d "
1265  "-> %dx%d or bit depth change %d -> %d "
1266  "or color changed 0 -> %d\n",
1267  p_enc_ctx->width, p_enc_ctx->height, frame_width,
1268  frame_height, p_session_ctx->bit_depth_factor,
1269  bit_depth, p_enc_ctx->color_change);
1270  p_session_ctx->session_run_state =
1272  p_enc_ctx->eos_fme_received = 1;
1273  if (p_enc_ctx->is_fifo_empty)
1274  {
1275  p_enc_ctx->need_free_frame = 1;
1276  }
1277  }
1278  }
1279 
1281  p_session_ctx->session_run_state ||
1282  (p_enc_ctx->eos_fme_received && p_enc_ctx->is_fifo_empty))
1283  {
1284  ni_log(NI_LOG_DEBUG, "XCoder start flushing\n");
1285  p_niframe->data.frame.end_of_stream = 1;
1286  p_enc_ctx->encoder_flushing = 1;
1287  } else
1288  {
1289  // extra data starts with metadata header, various aux data sizes
1290  // have been reset above
1292  p_niframe->data.frame.ni_pict_type = 0;
1294  ret = ni_enc_prep_reconf_demo_data(p_enc_ctx->api_ctx, p_input_frame);
1295  if (ret < 0)
1296  {
1297  return ret;
1298  }
1299 
1300  // support VFR
1301  if (p_param->enable_vfr)
1302  {
1303  uint32_t cur_fps, pre_fps;
1304 
1305  pre_fps = p_session_ctx->prev_fps;
1306 
1307  if (p_enc_ctx->frame_pts > p_session_ctx->prev_pts)
1308  {
1309  p_session_ctx->passed_time_in_timebase_unit +=
1310  p_enc_ctx->frame_pts - p_session_ctx->prev_pts;
1311  p_session_ctx->count_frame_num_in_sec++;
1312 
1313  // change the FrameRate for VFR
1314  // 1. Only when the fps change, setting the new bitrate
1315  // 2. The interval between two framerate change settings shall be
1316  // greater than 1 seconds, or at the start of the transcoding
1317  if (p_session_ctx->passed_time_in_timebase_unit >=
1318  (p_enc_ctx->timebase_den / p_enc_ctx->timebase_num))
1319  {
1320  cur_fps = p_session_ctx->count_frame_num_in_sec;
1321  if ((p_session_ctx->frame_num != 0) &&
1322  (pre_fps != cur_fps) &&
1323  ((p_session_ctx->frame_num <
1324  p_param->cfg_enc_params.frame_rate) ||
1325  (p_session_ctx->frame_num -
1326  p_session_ctx->last_change_framenum >=
1327  p_param->cfg_enc_params.frame_rate)))
1328  {
1329  aux_data = ni_frame_new_aux_data(
1330  p_input_frame, NI_FRAME_AUX_DATA_FRAMERATE,
1331  sizeof(ni_framerate_t));
1332  if (aux_data)
1333  {
1334  ni_framerate_t *framerate =
1335  (ni_framerate_t *)aux_data->data;
1336  framerate->framerate_num = cur_fps;
1337  framerate->framerate_denom = 1;
1338  }
1339 
1340  p_session_ctx->last_change_framenum =
1341  p_session_ctx->frame_num;
1342  p_session_ctx->prev_fps = cur_fps;
1343  }
1344  p_session_ctx->count_frame_num_in_sec = 0;
1345  p_session_ctx->passed_time_in_timebase_unit = 0;
1346  }
1347  p_session_ctx->prev_pts = p_enc_ctx->frame_pts;
1348  } else if (p_enc_ctx->frame_pts < p_session_ctx->prev_pts)
1349  {
1350  // Error handle for the case that pts jump back,
1351  // this may cause a little error in the bitrate setting which is
1352  // acceptable.
1353  // As long as the subsequent PTS is normal, it will be back to
1354  // normal quickly.
1355  p_session_ctx->prev_pts = p_enc_ctx->frame_pts;
1356  } else
1357  {
1358  // do nothing, when the pts of two adjacent frames are the same;
1359  // this may cause a little error in the bitrate setting which is
1360  // acceptable.
1361  // As long as the subsequent PTS is normal, it will be back to
1362  // normal quickly.
1363  }
1364  }
1365 
1366  // force pic qp demo mode: initial QP (200 frames) -> QP value specified by
1367  // ForcePicQpDemoMode (100 frames) -> initial QP (remaining frames)
1368  if (p_param->force_pic_qp_demo_mode)
1369  {
1370  if (p_session_ctx->frame_num >= 300)
1371  {
1372  p_niframe->data.frame.force_pic_qp =
1373  p_param->cfg_enc_params.rc.intra_qp;
1374  } else if (p_session_ctx->frame_num >= 200)
1375  {
1376  p_niframe->data.frame.force_pic_qp =
1377  p_param->force_pic_qp_demo_mode;
1378  }
1379  }
1380  // END NETINT_INTERNAL - currently only for internal testing
1381 
1382  // roi data, if enabled, with demo mode
1383  // Quadra case: when ROI demo enabled, always have a data buffer for ROI
1384  // Note: when ROI demo modes enabled, supply ROI map for the specified range
1385  // frames, and 0 map for others
1386  if (p_param->roi_demo_mode && p_param->cfg_enc_params.roi_enable)
1387  {
1388  if (p_session_ctx->frame_num > 90 && p_session_ctx->frame_num < 300)
1389  {
1390  p_niframe->data.frame.roi_len = p_session_ctx->roi_len;
1391  } else
1392  {
1393  p_niframe->data.frame.roi_len = 0;
1394  }
1395  // when ROI enabled, always have a data buffer for ROI
1396  // Note: this is handled separately from ROI through side/aux data
1397  p_niframe->data.frame.extra_data_len += p_session_ctx->roi_len;
1398  }
1399 
1400  p_enc_ctx->enable_all_sei_passthru =
1403  {
1404  // SEI (HDR)
1405  // content light level info (only user-set since FFmpeg 3.1.1 has no support
1406  // of that frame side data type yet !)
1407  p_enc_ctx->HDR10CLLEnable = p_param->cfg_enc_params.HDR10CLLEnable;
1408  if (p_param->cfg_enc_params.HDR10CLLEnable &&
1409  (NI_CODEC_FORMAT_H264 == p_enc_ctx->codec_format ||
1410  p_session_ctx->bit_depth_factor == 1) &&
1411  p_session_ctx->light_level_data_len == 0)
1412  {
1413  // User input maxCLL so create SEIs for h264 and don't touch for (h265
1414  // && hdr10) since that is conveyed in config step
1415  // Quadra autoset only for hdr10 format with hevc
1416  aux_data = ni_frame_new_aux_data(
1418  sizeof(ni_content_light_level_t));
1419  if (aux_data)
1420  {
1422  (ni_content_light_level_t *)(aux_data->data);
1423 
1424  cll->max_cll = p_param->cfg_enc_params.HDR10MaxLight;
1425  cll->max_fall = p_param->cfg_enc_params.HDR10AveLight;
1426  }
1427  }
1428  p_enc_ctx->HDR10Enable = p_param->cfg_enc_params.HDR10Enable;
1429  // mastering display color volume
1430  if (!p_param->cfg_enc_params.HDR10Enable) // not user set
1431  {
1432  p_enc_ctx->HDR10Enable = p_param->cfg_enc_params.HDR10Enable;
1433  } else if ((NI_CODEC_FORMAT_H264 == p_enc_ctx->codec_format ||
1434  p_session_ctx->bit_depth_factor == 1) &&
1435  p_session_ctx->sei_hdr_mastering_display_color_vol_len == 0)
1436  {
1437  // User input masterDisplay so create SEIs for h264 and don't touch for
1438  // (h265 && hdr10) since that is conveyed in config step
1439  // Quadra autoset only for hdr10 format with hevc
1440  aux_data = ni_frame_new_aux_data(
1443  if (aux_data)
1444  {
1446  (ni_mastering_display_metadata_t *)(aux_data->data);
1447 
1448  // X, Y display primaries for RGB channels and white point(WP) in
1449  // units of 0.00002 and max, min luminance(L) values in units of
1450  // 0.0001 nits, xy are denom = 50000 num = HDR10dx0/y
1451  mst_dsp->display_primaries[0][0].den =
1453  mst_dsp->display_primaries[0][1].den =
1455  mst_dsp->display_primaries[1][0].den =
1457  mst_dsp->display_primaries[1][1].den =
1459  mst_dsp->display_primaries[2][0].den =
1461  mst_dsp->display_primaries[2][1].den =
1467  // ni_mastering_display_metadata_t has to be filled with R,G,B
1468  // values, in that order, while HDR10d is filled in order of G,B,R,
1469  // so do the conversion here.
1470  mst_dsp->display_primaries[0][0].num =
1471  p_param->cfg_enc_params.HDR10dx2;
1472  mst_dsp->display_primaries[0][1].num =
1473  p_param->cfg_enc_params.HDR10dy2;
1474  mst_dsp->display_primaries[1][0].num =
1475  p_param->cfg_enc_params.HDR10dx0;
1476  mst_dsp->display_primaries[1][1].num =
1477  p_param->cfg_enc_params.HDR10dy0;
1478  mst_dsp->display_primaries[2][0].num =
1479  p_param->cfg_enc_params.HDR10dx1;
1480  mst_dsp->display_primaries[2][1].num =
1481  p_param->cfg_enc_params.HDR10dy1;
1482  mst_dsp->white_point[0].num = p_param->cfg_enc_params.HDR10wx;
1483  mst_dsp->white_point[1].num = p_param->cfg_enc_params.HDR10wy;
1484  mst_dsp->min_luminance.num =
1485  p_param->cfg_enc_params.HDR10minluma;
1486  mst_dsp->max_luminance.num =
1487  p_param->cfg_enc_params.HDR10maxluma;
1488  mst_dsp->has_primaries = 1;
1489  mst_dsp->has_luminance = 1;
1490  }
1491  }
1492  }
1493  }
1494  return ret;
1495 }
1496 
1498  void *side_data, int data_size, int type)
1499 {
1500  ni_aux_data_t *aux_data = NULL;
1501  ni_frame_t *p_input_frame = p_enc_ctx->input_frame;
1502  int aux_size;
1503  switch (type)
1504  {
1506  aux_size = sizeof(ni_long_term_ref_t);
1507  break;
1509  aux_size = sizeof(ni_mastering_display_metadata_t);
1510  break;
1512  aux_size = sizeof(ni_content_light_level_t);
1513  break;
1515  case NI_FRAME_AUX_DATA_CRF:
1518  aux_size = sizeof(int32_t);
1519  break;
1521  aux_size = sizeof(float);
1522  break;
1523  default:
1524  aux_size = data_size;
1525  break;
1526  }
1527  if (aux_size == 0)
1528  {
1529  return;
1530  }
1532  {
1533  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
1534  if (p_param->roi_demo_mode || !p_param->cfg_enc_params.roi_enable)
1535  {
1536  return ;
1537  }
1538  }
1539  aux_data = ni_frame_new_aux_data(p_input_frame, type, aux_size);
1540  if (aux_data)
1541  {
1542  memcpy(aux_data->data, side_data, data_size);
1543  }
1544 }
1550 
1552  void *side_data, int data_size)
1553 {
1554  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
1555  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
1556  ni_session_data_io_t *p_niframe = p_enc_ctx->api_fme;
1557  ni_frame_t *p_input_frame = p_enc_ctx->input_frame;
1558 
1559  int ret = 0;
1560  int i, j;
1561  p_niframe->data.frame.ni_pict_type = 0;
1562  if (p_session_ctx->force_frame_type)
1563  {
1564  switch (p_enc_ctx->pict_type)
1565  {
1566  case 1:
1567  p_niframe->data.frame.ni_pict_type = PIC_TYPE_IDR;
1568  break;
1569  case 2:
1570  p_niframe->data.frame.ni_pict_type = PIC_TYPE_P;
1571  break;
1572  default:;
1573  }
1574  } else if (p_enc_ctx->pict_type == 1)
1575  {
1576  p_niframe->data.frame.force_key_frame = 1;
1577  p_niframe->data.frame.ni_pict_type = PIC_TYPE_IDR;
1578  }
1579 
1582  "xcoder_send_frame: #%" PRIu64 " ni_pict_type %d"
1583  " forced_header_enable %d intraPeriod %d\n",
1584  p_session_ctx->frame_num, p_niframe->data.frame.ni_pict_type,
1586  p_param->cfg_enc_params.intra_period);
1587  // whether should send SEI with this frame
1588  int send_sei_with_idr = ni_should_send_sei_with_frame(
1589  p_session_ctx, p_niframe->data.frame.ni_pict_type, p_param);
1590  // prep for auxiliary data (various SEI, ROI) in encode frame, based on the
1591  // data returned in decoded frame
1592  ni_enc_prep_aux_data(p_session_ctx, &p_niframe->data.frame, p_input_frame,
1593  p_session_ctx->codec_format, send_sei_with_idr,
1595  if (side_data && data_size > 0)
1596  {
1597  int64_t local_pts = p_enc_ctx->frame_pts;
1598  uint8_t *p_src_sei_data, *p_dst_sei_data;
1599  int sei_size;
1600  uint8_t sei_type;
1601  int size;
1602  ni_custom_sei_set_t *src_custom_sei_set, *dst_custom_sei_set;
1603  ni_custom_sei_t *p_src_custom_sei, *p_dst_custom_sei;
1604 
1605  // if one picture can be skipped, nienc will send that frame but will
1606  // not receive packet, therefore it will skip the free in receive
1607  // packet as well and cause memory leak. So check the last
1608  // pkt_custom_sei_set has been released or not.
1609  dst_custom_sei_set =
1610  p_session_ctx->pkt_custom_sei_set[local_pts % NI_FIFO_SZ];
1611  if (dst_custom_sei_set)
1612  {
1613  free(dst_custom_sei_set);
1614  }
1615 
1616  /* copy the whole SEI data */
1617  src_custom_sei_set = (ni_custom_sei_set_t *)side_data;
1618  dst_custom_sei_set = malloc(sizeof(ni_custom_sei_set_t));
1619  if (dst_custom_sei_set == NULL)
1620  {
1622  "%s failed to allocate memory for custom sei data\n",
1623  __FUNCTION__);
1625  return ret;
1626  }
1627  memset(dst_custom_sei_set, 0, sizeof(ni_custom_sei_set_t));
1628 
1629  /* fill sei data */
1630  for (i = 0; i < src_custom_sei_set->count; i++)
1631  {
1632  int len;
1633  p_src_custom_sei = &src_custom_sei_set->custom_sei[i];
1634  sei_size = p_src_custom_sei->size;
1635  sei_type = p_src_custom_sei->type;
1636  p_src_sei_data = &p_src_custom_sei->data[0];
1637 
1638  p_dst_custom_sei = &dst_custom_sei_set->custom_sei[i];
1639  p_dst_sei_data = &p_dst_custom_sei->data[0];
1640  size = 0;
1641 
1642  // long start code
1643  p_dst_sei_data[size++] = 0x00;
1644  p_dst_sei_data[size++] = 0x00;
1645  p_dst_sei_data[size++] = 0x00;
1646  p_dst_sei_data[size++] = 0x01;
1647 
1648  if (NI_CODEC_FORMAT_H264 == p_enc_ctx->codec_format)
1649  {
1650  p_dst_sei_data[size++] = 0x06; //nal type: SEI
1651  } else
1652  {
1653  p_dst_sei_data[size++] = 0x4e; //nal type: SEI
1654  p_dst_sei_data[size++] = 0x01;
1655  }
1656 
1657  // SEI type
1658  p_dst_sei_data[size++] = sei_type;
1659 
1660  // original payload size
1661  len = sei_size;
1662  while (len >= 0)
1663  {
1664  p_dst_sei_data[size++] = len > 0xff ? 0xff : len;
1665  len -= 0xff;
1666  }
1667 
1668  // payload data
1669  for (j = 0; j < sei_size && size < NI_MAX_CUSTOM_SEI_DATA - 1; j++)
1670  {
1671  if (j >= 2 && !p_dst_sei_data[size - 2] &&
1672  !p_dst_sei_data[size - 1] && p_src_sei_data[j] <= 0x03)
1673  {
1674  /* insert 0x3 as emulation_prevention_three_byte */
1675  p_dst_sei_data[size++] = 0x03;
1676  }
1677  p_dst_sei_data[size++] = p_src_sei_data[j];
1678  }
1679 
1680  if (j != sei_size)
1681  {
1683  "%s: sei RBSP size exceeds limit "
1684  "(%d), idx=%u, type=%u, size=%d, custom_sei_loc=%d.\n",
1685  __FUNCTION__, NI_MAX_CUSTOM_SEI_DATA, i, sei_type, sei_size,
1686  p_src_custom_sei->location);
1687  free(dst_custom_sei_set);
1688  break;
1689  }
1690 
1691  // trailing byte
1692  p_dst_sei_data[size++] = 0x80;
1693 
1694  p_dst_custom_sei->size = size;
1695  p_dst_custom_sei->type = sei_type;
1696  p_dst_custom_sei->location = p_src_custom_sei->location;
1698  "%s: custom sei idx %d type %u len %d "
1699  "loc %d.\n",
1700  __FUNCTION__, i, sei_type, size, p_dst_custom_sei->location);
1701  }
1702 
1703  dst_custom_sei_set->count = src_custom_sei_set->count;
1704  p_session_ctx->pkt_custom_sei_set[local_pts % NI_FIFO_SZ] =
1705  dst_custom_sei_set;
1706  ni_log(NI_LOG_TRACE, "%s: sei number %d pts %" PRId64 ".\n", __func__,
1707  dst_custom_sei_set->count, local_pts);
1708  }
1709 
1711  {
1713  "xcoder_send_frame: sei total length %u exceeds maximum sei "
1714  "size %u.\n",
1716  ret = NI_RETCODE_FAILURE;
1717  return ret;
1718  }
1719 
1720  p_niframe->data.frame.extra_data_len += p_niframe->data.frame.sei_total_len;
1721 
1722  // data layout requirement: leave space for reconfig data if at least one of
1723  // reconfig, SEI or ROI is present
1724  // Note: ROI is present when enabled, so use encode config flag instead of
1725  // frame's roi_len as it can be 0 indicating a 0'd ROI map setting !
1726  if (p_niframe->data.frame.reconf_len ||
1727  p_niframe->data.frame.sei_total_len ||
1728  p_param->cfg_enc_params.roi_enable)
1729  {
1730  p_niframe->data.frame.extra_data_len +=
1732  }
1733 
1734  p_niframe->data.frame.pts = p_enc_ctx->frame_pts;
1735  p_niframe->data.frame.dts = p_enc_ctx->pkt_dts;
1736 
1737  p_niframe->data.frame.video_width = p_enc_ctx->width;
1738  p_niframe->data.frame.video_height = p_enc_ctx->height;
1739 
1740  p_enc_ctx->auto_dl_handle = 0;
1741  if (p_session_ctx->auto_dl_handle != 0 ||
1742  (p_enc_ctx->height < NI_MIN_HEIGHT) ||
1743  (p_enc_ctx->width < NI_MIN_WIDTH))
1744  {
1745  p_session_ctx->hw_action = 0;
1746  p_enc_ctx->auto_dl_handle = 1;
1747  p_enc_ctx->ishwframe = 0;
1748  }
1749  return ret;
1750 }
1751 
1753  uint8_t **data, uint8_t *nidata, int *linesize,
1754  int frame_width, int frame_height,
1755  NIFramesContext *nif_src_ctx)
1756 {
1757  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
1758  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
1759  ni_session_data_io_t *p_niframe = p_enc_ctx->api_fme;
1760  ni_frame_t *p_input_frame = p_enc_ctx->input_frame;
1761  int ret;
1762  int need_to_copy = 1;
1763  int isnv12frame = (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_NV12 ||
1764  p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_P010LE);
1765  bool alignment_2pass_wa = ((p_param->cfg_enc_params.lookAheadDepth ||
1766  p_param->cfg_enc_params.crf >= 0 ||
1767  p_param->cfg_enc_params.crfFloat >= 0) &&
1768  p_enc_ctx->codec_format == NI_CODEC_FORMAT_H265);
1769  int dst_stride[NI_MAX_NUM_DATA_POINTERS] = {0};
1770  int height_aligned[NI_MAX_NUM_DATA_POINTERS] = {0};
1771  int src_height[NI_MAX_NUM_DATA_POINTERS] = {0};
1772 
1773  src_height[0] = frame_height;
1774  src_height[1] = frame_height / 2;
1775  src_height[2] = (isnv12frame) ? 0 : (frame_height / 2);
1776  if (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_RGBA ||
1777  p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_BGRA ||
1778  p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_ARGB ||
1779  p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_ABGR)
1780  {
1781  src_height[0] = frame_height;
1782  src_height[1] = 0;
1783  src_height[2] = 0;
1784  alignment_2pass_wa = 0;
1785  }
1786  ni_get_hw_yuv420p_dim(frame_width, frame_height,
1787  p_session_ctx->bit_depth_factor, isnv12frame,
1788  dst_stride, height_aligned);
1789 
1791  "xcoder_send_frame frame->width %d "
1792  "p_session_ctx->bit_depth_factor %d dst_stride[0/1/2] %d/%d/%d\n",
1793  frame_width, p_session_ctx->bit_depth_factor, dst_stride[0],
1794  dst_stride[1], dst_stride[2]);
1795 
1796  /* The main reason for the problem is that when using out=sw and noautoscale=0,
1797  * the incoming stream initially conforms to zerocopy, so the firmware will allocate memory according to zerocopy.
1798  * The resolution after this changes, but the software inserts autoscale,
1799  * so the encoder cannot detect the change in resolution and cannot reopen.
1800  * However, due to ffmpeg being 64 bit aligned, So the linesize is not consistent with the linesize we initially decoded,
1801  * so the encoding will take the path of non-zero copy. At this time, due to lookahead>0,
1802  * the software will send the firmware a size larger than the originally requested size,
1803  * so it will not be able to send it. Moreover, at this point,
1804  * the firmware is unable to perceive changes in linesize and respond accordingly.
1805  * For fix this, we can check the linesize and disable 2-pass workaround.
1806  */
1807  if (p_param->luma_linesize)
1808  {
1809  alignment_2pass_wa = false;
1810  }
1811 
1812  if (alignment_2pass_wa && !p_enc_ctx->ishwframe)
1813  {
1814  if (isnv12frame)
1815  {
1816  // for 2-pass encode output mismatch WA, need to extend (and
1817  // pad) CbCr plane height, because 1st pass assume input 32
1818  // align
1819  height_aligned[1] = NIALIGN(height_aligned[0], 32) / 2;
1820  } else
1821  {
1822  // for 2-pass encode output mismatch WA, need to extend (and
1823  // pad) Cr plane height, because 1st pass assume input 32 align
1824  height_aligned[2] = NIALIGN(height_aligned[0], 32) / 2;
1825  }
1826  }
1827 
1828  // alignment(16) extra padding for H.264 encoding
1829  if (p_enc_ctx->ishwframe)
1830  {
1831  uint8_t *dsthw;
1832  const uint8_t *srchw;
1833 
1834  ni_frame_buffer_alloc_hwenc(&(p_niframe->data.frame), frame_width,
1835  frame_height,
1836  (int)p_niframe->data.frame.extra_data_len);
1837  if (!p_niframe->data.frame.p_data[3])
1838  {
1840  }
1841  dsthw = p_niframe->data.frame.p_data[3];
1842  srchw = (const uint8_t *)nidata;
1843  ni_log(NI_LOG_TRACE, "dst=%p src=%p len=%d\n", dsthw, srchw,
1844  p_niframe->data.frame.data_len[3]);
1845  memcpy(dsthw, srchw, p_niframe->data.frame.data_len[3]);
1846  ni_log(NI_LOG_TRACE, "frame_data[3] %p memcpy to %p\n", nidata, dsthw);
1847  } else // traditional yuv transfer
1848  {
1850  "%s %s %d buffered_fme.data[0] %p data[3] %p wxh %u %u "
1851  "dst_stride[0] %d %d linesize[0] %d %d data[1] %p %p data[2] "
1852  "%p %p data[3] %p avctx(w:h:cw:ch) %u:%u\n",
1853  __FILE__, __FUNCTION__, __LINE__, data[0], data[3], frame_width,
1854  frame_height, dst_stride[0], dst_stride[1], linesize[0],
1855  linesize[1], data[1], data[0] + dst_stride[0] * frame_height,
1856  data[2], data[1] + dst_stride[1] * frame_height / 2, data[3],
1857  p_enc_ctx->width, p_enc_ctx->height);
1858 
1859  // check input resolution zero copy compatible or not
1860  if (ni_encoder_frame_zerocopy_check(p_session_ctx, p_param, frame_width,
1861  frame_height, linesize,
1862  false) == NI_RETCODE_SUCCESS)
1863  {
1864  need_to_copy = 0;
1865  // alloc metadata buffer etc. (if needed)
1867  &(p_niframe->data.frame), frame_width, frame_height, linesize,
1868  (const uint8_t **)data,
1869  (int)p_niframe->data.frame.extra_data_len);
1870  if (ret != NI_RETCODE_SUCCESS)
1872  } else
1873  {
1874  // if linesize changes (while resolution remains the same), copy to
1875  // previously configured linesizes
1876  if (p_param->luma_linesize && p_param->chroma_linesize)
1877  {
1878  dst_stride[0] = p_param->luma_linesize;
1879  dst_stride[1] = dst_stride[2] = p_param->chroma_linesize;
1880  }
1881 
1883  !isnv12frame, &(p_niframe->data.frame), frame_width,
1884  height_aligned[0], dst_stride,
1885  p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264,
1886  (int)p_niframe->data.frame.extra_data_len, alignment_2pass_wa);
1887  }
1888 
1889  ni_log(NI_LOG_TRACE, "%p need_to_copy %d! pts = %ld\n",
1890  p_niframe->data.frame.p_buffer, need_to_copy,
1891  p_enc_ctx->frame_pts);
1892 
1893  if (!p_niframe->data.frame.p_data[0])
1895 
1896  // if this is indeed sw frame, do the YUV data layout, otherwise may
1897  // need to do frame download
1898  if (p_enc_ctx->is_swframes)
1899  {
1900  ni_log(
1901  NI_LOG_TRACE,
1902  "xcoder_send_frame: fme.data_len[0]=%d, "
1903  "buf_fme->linesize=%d/%d/%d, dst alloc linesize = %d/%d/%d, "
1904  "src height = %d/%d/%d, dst height aligned = %d/%d/%d, "
1905  "force_key_frame=%d, extra_data_len=%d sei_size=%d "
1906  "(hdr_content_light_level %u hdr_mastering_display_color_vol "
1907  "%u "
1908  "hdr10+ %u cc %u udu %u prefC %u) roi_size=%u reconf_size=%u "
1909  "force_pic_qp=%u "
1910  "use_cur_src_as_long_term_pic %u use_long_term_ref %u\n",
1911  p_niframe->data.frame.data_len[0], linesize[0], linesize[1],
1912  linesize[2], dst_stride[0], dst_stride[1], dst_stride[2],
1913  src_height[0], src_height[1], src_height[2], height_aligned[0],
1914  height_aligned[1], height_aligned[2],
1915  p_niframe->data.frame.force_key_frame,
1916  p_niframe->data.frame.extra_data_len,
1917  p_niframe->data.frame.sei_total_len,
1920  p_niframe->data.frame.sei_hdr_plus_len,
1921  p_niframe->data.frame.sei_cc_len,
1922  p_niframe->data.frame.sei_user_data_unreg_len,
1924  (p_param->cfg_enc_params.roi_enable ? p_session_ctx->roi_len :
1925  0),
1926  p_niframe->data.frame.reconf_len,
1927  p_niframe->data.frame.force_pic_qp,
1929  p_niframe->data.frame.use_long_term_ref);
1930 
1931  // YUV part of the encoder input data layout
1932  if (need_to_copy)
1933  {
1935  (uint8_t **)(p_niframe->data.frame.p_data), data,
1936  frame_width, frame_height, p_session_ctx->bit_depth_factor,
1937  isnv12frame, p_param->cfg_enc_params.conf_win_right,
1938  dst_stride, height_aligned, linesize, src_height);
1939  }
1940  } else
1941  {
1942  ni_session_data_io_t *p_session_data;
1943  ni_session_data_io_t niframe;
1944 
1946  "xcoder_send_frame:Autodownload to be run: hdl: %d w: %d h: "
1947  "%d\n",
1948  p_session_ctx->auto_dl_handle, p_enc_ctx->width,
1949  p_enc_ctx->height);
1950 
1951  niquadraFrameSurface1_t *src_surf =
1952  (niquadraFrameSurface1_t *)data[3];
1953 
1954  if (p_enc_ctx->height < NI_MIN_HEIGHT ||
1955  p_enc_ctx->width < NI_MIN_WIDTH)
1956  {
1957  int bit_depth;
1958  int is_planar;
1959 
1960  p_session_data = &niframe;
1961  memset(&niframe, 0, sizeof(niframe));
1962  bit_depth =
1963  ((p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_YUV420P10LE) ||
1964  (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_P010LE)) ?
1965  2 :
1966  1;
1967  is_planar =
1968  (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_YUV420P) ||
1969  (p_enc_ctx->sw_pix_fmt == NI_QUADRA_PIX_FMT_YUV420P10LE);
1970 
1971  /* Allocate a minimal frame */
1972  ni_frame_buffer_alloc(&niframe.data.frame, p_enc_ctx->width,
1973  p_enc_ctx->height, 0, /* alignment */
1974  1, /* metadata */
1975  bit_depth, 0, /* hw_frame_count */
1976  is_planar);
1977  } else
1978  {
1979  p_session_data = p_niframe;
1980  }
1981  ni_quadra_filter_session_dl_set(nif_src_ctx->api_ctx, true);
1982  ret = ni_device_session_hwdl(nif_src_ctx->api_ctx, p_session_data,
1983  (niFrameSurface1_t *)src_surf);
1984  p_enc_ctx->ishwframe = false;
1985  if (ret <= 0)
1986  {
1988  "nienc.c:ni_hwdl_frame() failed to retrieve frame\n");
1989  return NI_RETCODE_FAILURE;
1990  }
1991 
1992  if ((p_enc_ctx->height < NI_MIN_HEIGHT) ||
1993  (p_enc_ctx->width < NI_MIN_WIDTH))
1994  {
1995  ni_expand_frame(&p_niframe->data.frame,
1996  &p_session_data->data.frame, dst_stride,
1997  p_enc_ctx->width, p_enc_ctx->height,
1998  p_session_ctx->pixel_format, p_enc_ctx->nb_planes);
1999 
2000  ni_frame_buffer_free(&niframe.data.frame);
2001  }
2002  }
2003  } // traditional yuv transfer
2004  ni_enc_copy_aux_data(p_session_ctx, &p_niframe->data.frame, p_input_frame,
2005  p_session_ctx->codec_format, mdcv_data, cll_data,
2006  cc_data, udu_data, hdrp_data, p_enc_ctx->ishwframe,
2007  isnv12frame);
2008  ni_frame_buffer_free(p_input_frame);
2009 
2010  return 0;
2011 }
2012 
2014 {
2015  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
2016  ni_session_data_io_t *p_niframe = p_enc_ctx->api_fme;
2017  int sent = 0;
2018  sent = ni_device_session_write(p_session_ctx, p_niframe,
2021  "ni_quadra_enc_send_frame: pts %lld dts %lld "
2022  "size %d sent to xcoder\n",
2023  p_niframe->data.frame.pts, p_niframe->data.frame.dts, sent);
2024  // return EIO at error
2025  if (NI_RETCODE_ERROR_VPU_RECOVERY == sent)
2026  {
2028  }
2029  else if (sent <= 0)
2030  {
2031  p_enc_ctx->start_of_stream = p_niframe->data.frame.start_of_stream;
2032  }
2033  else
2034  {
2035  p_enc_ctx->auto_dl_handle = p_session_ctx->auto_dl_handle;
2036 
2037  // pushing input pts in circular FIFO
2038  p_session_ctx->enc_pts_list[p_session_ctx->enc_pts_w_idx % NI_FIFO_SZ] =
2039  p_niframe->data.frame.pts;
2040  p_session_ctx->enc_pts_w_idx++;
2041  }
2042  return sent;
2043 }
2044 
2046 {
2048 }
2049 
2050 int ni_quadra_encode_reinit(ni_quadra_enc_context_t *p_enc_ctx, int frame_width,
2051  int frame_height, const int *linesize)
2052 {
2053  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
2054  p_enc_ctx->tmp_device_handle = p_session_ctx->device_handle;
2055  p_enc_ctx->tmp_blk_io_handle = p_session_ctx->blk_io_handle;
2056  p_enc_ctx->tmp_hw_id = p_session_ctx->hw_id;
2057  int stride, ori_stride;
2058  bool bIsSmallPicture = false;
2059 
2060  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
2061 
2062  ni_xcoder_strncpy(p_enc_ctx->tmp_blk_dev_name, p_session_ctx->blk_dev_name,
2064 
2065  p_enc_ctx->eos_fme_received = 0;
2066  p_enc_ctx->encoder_eof = 0;
2067  p_enc_ctx->encoder_flushing = 0;
2068  p_enc_ctx->firstPktArrived = 0;
2069  p_enc_ctx->spsPpsArrived = 0;
2070  p_enc_ctx->spsPpsHdrLen = 0;
2071  free(p_enc_ctx->p_spsPpsHdr);
2072  p_enc_ctx->p_spsPpsHdr = NULL;
2073  p_enc_ctx->seqChangeCount++;
2074  // check if resolution is zero copy compatible and set linesize according to
2075  // new resolution
2076  if (ni_encoder_frame_zerocopy_check(p_session_ctx, p_param, frame_width,
2077  frame_height, linesize,
2078  true) == NI_RETCODE_SUCCESS)
2079  {
2080  stride =
2081  p_param->luma_linesize; // new sequence is zero copy compatible
2082  } else
2083  {
2084  stride = NIALIGN(frame_width * p_enc_ctx->bit_depth, 128);
2085  }
2086 
2087  if (p_session_ctx->ori_luma_linesize && p_session_ctx->ori_chroma_linesize)
2088  {
2089  // previous sequence was zero copy compatible
2090  ori_stride = p_session_ctx->ori_luma_linesize;
2091  } else
2092  {
2093  ori_stride =
2094  NIALIGN(p_session_ctx->ori_width * p_enc_ctx->bit_depth, 128);
2095  }
2096 
2097  if (p_enc_ctx->pix_fmt == NI_PIX_FMT_ARGB ||
2098  p_enc_ctx->pix_fmt == NI_PIX_FMT_ABGR)
2099  {
2100  stride = frame_width;
2101  ori_stride = p_session_ctx->ori_width;
2102  }
2103 
2104  if (p_param->cfg_enc_params.lookAheadDepth ||
2105  p_param->cfg_enc_params.crf >= 0 ||
2106  p_param->cfg_enc_params.crfFloat >= 0)
2107  {
2109  "ni_quadra_encode_reinit 2-pass lookaheadDepth %d "
2110  "and/or CRF %d and/or CRFFloat %f\n",
2111  p_param->cfg_enc_params.lookAheadDepth,
2112  p_param->cfg_enc_params.crf,
2113  p_param->cfg_enc_params.crfFloat);
2114  if ((frame_width < NI_2PASS_ENCODE_MIN_WIDTH) ||
2115  (frame_height < NI_2PASS_ENCODE_MIN_HEIGHT))
2116  {
2117  bIsSmallPicture = true;
2118  }
2119  } else
2120  {
2121  if ((frame_width < NI_MIN_WIDTH) || (frame_height < NI_MIN_HEIGHT))
2122  {
2123  bIsSmallPicture = true;
2124  }
2125  }
2126 
2127  if (p_param->cfg_enc_params.multicoreJointMode)
2128  {
2130  "ni_quadra_encode_reinit multicore "
2131  "joint mode\n");
2132  if ((frame_width < 256) || (frame_height < 256))
2133  {
2134  bIsSmallPicture = true;
2135  }
2136  }
2137  p_enc_ctx->reinit = 0;
2138  if ((ori_stride * p_session_ctx->ori_height < stride * frame_height) ||
2139  (p_session_ctx->ori_pix_fmt != p_enc_ctx->pix_fmt) || bIsSmallPicture ||
2141  {
2142  p_enc_ctx->reinit = 1;
2143  }
2144 
2145  return 0;
2146 }
2148 {
2149  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
2150  // keep device handle(s) open during sequence change to fix mem bin buffer
2151  // not recycled
2152  p_session_ctx->device_handle = p_enc_ctx->tmp_device_handle;
2153  p_session_ctx->blk_io_handle = p_enc_ctx->tmp_blk_io_handle;
2154  p_session_ctx->hw_id = p_enc_ctx->tmp_hw_id;
2155  ni_xcoder_strncpy(p_session_ctx->blk_dev_name, p_enc_ctx->tmp_blk_dev_name,
2157  // this state is referenced when sending first frame after sequence change
2159  return 0;
2160 }
2161 
2163 {
2164  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
2165  ni_session_data_io_t *p_packet = p_enc_ctx->api_pkt;
2166  ni_xcoder_params_t *p_param = p_enc_ctx->api_param;
2167  int i, ret = 0;
2168  int recv;
2169  ni_packet_t *xpkt = &p_packet->data.packet;
2170 
2171  while (1)
2172  {
2173  p_enc_ctx->retstatus = NI_QUADRA_RET_SUCCESS;
2174  xpkt->recycle_index = -1;
2175  recv = ni_device_session_read(p_session_ctx, p_packet,
2177  ni_log(
2178  NI_LOG_TRACE,
2179  "XCoder receive packet: xpkt.end_of_stream=%d, xpkt.data_len=%d, "
2180  "recv=%d, encoder_flushing=%d, encoder_eof=%d\n",
2181  xpkt->end_of_stream, xpkt->data_len, recv,
2182  p_enc_ctx->encoder_flushing, p_enc_ctx->encoder_eof);
2183  p_enc_ctx->end_of_stream = xpkt->end_of_stream;
2184 
2185  if (recv <= 0)
2186  {
2187  p_enc_ctx->encoder_eof = xpkt->end_of_stream;
2188  /* not ready ?? */
2189  if (p_enc_ctx->encoder_eof)
2190  {
2192  p_session_ctx->session_run_state)
2193  {
2194  // after sequence change completes, reset codec state
2196  "xcoder_receive_packet 1: sequence "
2197  "change completed, return AVERROR(EAGAIN) and will "
2198  "reopen codec!\n");
2200  }
2201 
2203  "xcoder_receive_packet: got encoder_eof, "
2204  "return AVERROR_EOF\n");
2205  break;
2206  } else
2207  {
2208  if (NI_RETCODE_ERROR_VPU_RECOVERY == recv)
2209  {
2211  break;
2212  } else if (recv < 0)
2213  {
2214  if ((NI_RETCODE_ERROR_INVALID_SESSION == recv) &&
2215  !p_enc_ctx->started) // session may be in recovery state, return
2216  // EAGAIN
2217  {
2219  } else
2220  {
2221  ;
2222  }
2223  p_enc_ctx->gotPacket = 0;
2224  p_enc_ctx->sentFrame = 0;
2225  break;
2226  } else if (p_param->low_delay_mode && p_enc_ctx->sentFrame &&
2227  !p_enc_ctx->gotPacket)
2228  {
2230  "XCoder receive packet: low delay mode,"
2231  " keep reading until pkt arrives\n");
2232  continue;
2233  }
2234 
2235  p_enc_ctx->gotPacket = 0;
2236  p_enc_ctx->sentFrame = 0;
2237  p_enc_ctx->retstatus = NI_QUADRA_EAGAIN;
2238  if (!p_enc_ctx->encoder_flushing &&
2239  !p_enc_ctx->eos_fme_received)
2240  {
2242  "xcoder_receive_packet: NOT "
2243  "encoder_flushing, return AVERROR(EAGAIN)\n");
2244  break;
2245  }
2246  }
2247  } else
2248  {
2249  p_enc_ctx->need_to_recycle = false;
2250  /* got encoded data back */
2251  int meta_size = p_session_ctx->meta_size;
2252  if (p_enc_ctx->is_swframes == 0 && xpkt->recycle_index >= 0 &&
2253  xpkt->recycle_index <
2254  NI_GET_MAX_HWDESC_FRAME_INDEX(p_session_ctx->ddr_config) &&
2255  p_enc_ctx->height >= NI_MIN_HEIGHT &&
2256  p_enc_ctx->width >= NI_MIN_WIDTH)
2257  {
2258  p_enc_ctx->recycle_index = xpkt->recycle_index;
2259  p_enc_ctx->need_to_recycle = true;
2260  xpkt->recycle_index = -1;
2261  }
2262 
2263  if (!p_enc_ctx->spsPpsArrived)
2264  {
2265  p_enc_ctx->retstatus = NI_QUADRA_EAGAIN;
2266  // ret = AVERROR(EAGAIN);
2267  p_enc_ctx->spsPpsArrived = 1;
2268  p_enc_ctx->spsPpsHdrLen = recv - meta_size;
2269  p_enc_ctx->p_spsPpsHdr = malloc(p_enc_ctx->spsPpsHdrLen);
2270  if (!p_enc_ctx->p_spsPpsHdr)
2271  {
2272  p_enc_ctx->retstatus = NI_QUADRA_ERROR;
2273  // ret = NI_RETCODE_ERROR_MEM_ALOC;
2274  break;
2275  }
2276 
2277  memcpy(p_enc_ctx->p_spsPpsHdr,
2278  (uint8_t *)xpkt->p_data + meta_size,
2279  xpkt->data_len - meta_size);
2280 
2281  // start pkt_num counter from 1 to get the real first frame
2282  p_session_ctx->pkt_num = 1;
2283  // for low-latency mode, keep reading until the first frame is
2284  // back
2285  if (p_param->low_delay_mode)
2286  {
2288  "XCoder receive packet: low delay mode,"
2289  " keep reading until 1st pkt arrives\n");
2290  continue;
2291  }
2292  break;
2293  }
2294  // handle pic skip
2295  if (xpkt->frame_type == 3) // 0=I, 1=P, 2=B, 3=not coded / skip
2296  {
2297  p_enc_ctx->retstatus = NI_QUADRA_EAGAIN;
2298  // ret = AVERROR(EAGAIN);
2299  if (p_enc_ctx->first_frame_pts == INT_MIN)
2300  p_enc_ctx->first_frame_pts = xpkt->pts;
2301  /* no support for AV1 now
2302  if (AV_CODEC_ID_AV1 == avctx->codec_id) {
2303  ctx->latest_dts = xpkt->pts;
2304  } else */
2305  if (p_enc_ctx->total_frames_received < p_enc_ctx->dts_offset)
2306  {
2307  // guess dts
2308  int64_t bframes_delay = 0;
2309  if (p_session_ctx->enc_pts_w_idx > p_enc_ctx->dts_offset)
2310  bframes_delay = p_session_ctx->enc_pts_list[p_enc_ctx->dts_offset] - p_session_ctx->enc_pts_list[0];
2311  ni_log(NI_LOG_INFO, "%s xcoder_bframes_delay=%"PRId64"\n", __func__, bframes_delay);
2312  p_enc_ctx->latest_dts = p_enc_ctx->first_frame_pts +
2313  ((p_enc_ctx->gop_offset_count - p_enc_ctx->dts_offset) * (bframes_delay ? bframes_delay / p_enc_ctx->dts_offset : p_enc_ctx->ticks_per_frame));
2314  p_enc_ctx->gop_offset_count++;
2315  } else
2316  {
2317  // get dts from pts FIFO
2318  p_enc_ctx->latest_dts =
2319  p_session_ctx
2320  ->enc_pts_list[p_session_ctx->enc_pts_r_idx %
2321  NI_FIFO_SZ];
2322  p_session_ctx->enc_pts_r_idx++;
2323  }
2324  if (p_enc_ctx->latest_dts > xpkt->pts)
2325  {
2326  p_enc_ctx->latest_dts = xpkt->pts;
2327  }
2328  p_enc_ctx->total_frames_received++;
2329 
2330  if (!p_enc_ctx->encoder_flushing &&
2331  !p_enc_ctx->eos_fme_received)
2332  {
2334  "xcoder_receive_packet: skip"
2335  " picture output, return AVERROR(EAGAIN)\n");
2336  break;
2337  } else
2338  continue;
2339  }
2340 
2341  p_enc_ctx->gotPacket = 1;
2342  p_enc_ctx->sentFrame = 0;
2343 
2344  uint32_t nalu_type = 0;
2345  const uint8_t *p_start_code;
2346  uint32_t stc = -1;
2347  p_enc_ctx->copy_len = 0;
2348  uint8_t *p_src = (uint8_t *)xpkt->p_data + meta_size;
2349  uint8_t *p_end = p_src + (xpkt->data_len - meta_size);
2350  p_enc_ctx->local_pts = xpkt->pts;
2351  p_enc_ctx->total_custom_sei_size = 0;
2352  p_enc_ctx->custom_sei_count = 0;
2353  ni_custom_sei_set_t *p_custom_sei_set;
2354  p_enc_ctx->data_len = xpkt->data_len - meta_size;
2355  p_custom_sei_set =
2356  p_session_ctx
2357  ->pkt_custom_sei_set[p_enc_ctx->local_pts % NI_FIFO_SZ];
2358  if (p_custom_sei_set != NULL)
2359  {
2360  p_enc_ctx->custom_sei_count = p_custom_sei_set->count;
2361  for (i = 0; i < p_custom_sei_set->count; i++)
2362  {
2363  p_enc_ctx->total_custom_sei_size +=
2364  p_custom_sei_set->custom_sei[i].size;
2365  }
2366  }
2367 
2368  if (p_enc_ctx->custom_sei_count)
2369  {
2370  // if HRD or custom sei enabled, search for pic_timing or custom
2371  // SEI insertion point by skipping non-VCL until video data is
2372  // found.
2373  p_start_code = p_src;
2374  if (NI_CODEC_FORMAT_H265 == p_enc_ctx->codec_format)
2375  {
2376  do
2377  {
2378  stc = -1;
2379  p_start_code =
2380  ni_find_start_code(p_start_code, p_end, &stc);
2381  nalu_type = (stc >> 1) & 0x3F;
2382  } while (nalu_type > 31 /* HEVC_NAL_RSV_VCL31 */);
2383 
2384  // calc. length to copy
2385  p_enc_ctx->copy_len = p_start_code - 5 - p_src;
2386  } else if (NI_CODEC_FORMAT_H264 == p_enc_ctx->codec_format)
2387  {
2388  do
2389  {
2390  stc = -1;
2391  p_start_code =
2392  ni_find_start_code(p_start_code, p_end, &stc);
2393  nalu_type = stc & 0x1F;
2394  } while (nalu_type > 5 /* H264_NAL_IDR_SLICE */);
2395 
2396  // calc. length to copy
2397  p_enc_ctx->copy_len = p_start_code - 5 - p_src;
2398  } else
2399  {
2401  "%s: codec %d not supported for "
2402  "SEI !\n",
2403  __FUNCTION__, p_enc_ctx->codec_format);
2404  }
2405  }
2406 #define NI_CODEC_ID_MJPEG 8
2407  if (p_enc_ctx->codec_id == NI_CODEC_ID_MJPEG &&
2408  (!p_enc_ctx->firstPktArrived))
2409  {
2410  // there is no header for Jpeg, so skip header copy
2411  p_enc_ctx->firstPktArrived = 1;
2412  p_enc_ctx->first_frame_pts = xpkt->pts;
2413  }
2414 #undef NI_CODEC_ID_MJPEG
2415  if (!p_enc_ctx->firstPktArrived)
2416  {
2417  // p_enc_ctx->firstPktArrived = 1;
2418  p_enc_ctx->first_frame_pts = xpkt->pts;
2419  }
2420 
2421  break;
2422  }
2423  }
2424  return recv;
2425 }
2426 
2428  uint8_t *p_dst)
2429 {
2430  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
2431  ni_session_data_io_t *p_packet = p_enc_ctx->api_pkt;
2432  ni_packet_t *xpkt = &p_packet->data.packet;
2433  uint8_t *p_src = (uint8_t *)xpkt->p_data + p_session_ctx->meta_size;
2434  int i;
2435  ni_custom_sei_set_t *p_custom_sei_set;
2436  p_custom_sei_set =
2437  p_session_ctx->pkt_custom_sei_set[p_enc_ctx->local_pts % NI_FIFO_SZ];
2438  if (p_enc_ctx->custom_sei_count)
2439  {
2440  // copy buf_period
2441  memcpy(p_dst, p_src, p_enc_ctx->copy_len);
2442  p_dst += p_enc_ctx->copy_len;
2443 
2444  for (i = 0; i < p_enc_ctx->custom_sei_count; i++)
2445  {
2446  // copy custom sei
2447  ni_custom_sei_t *p_custom_sei = &p_custom_sei_set->custom_sei[i];
2448  if (p_custom_sei->location == NI_CUSTOM_SEI_LOC_AFTER_VCL)
2449  {
2450  break;
2451  }
2452  memcpy(p_dst, &p_custom_sei->data[0], p_custom_sei->size);
2453  p_dst += p_custom_sei->size;
2454  }
2455 
2456  // copy the IDR data
2457  memcpy(p_dst, p_src + p_enc_ctx->copy_len,
2458  xpkt->data_len - p_session_ctx->meta_size - p_enc_ctx->copy_len);
2459  p_dst +=
2460  xpkt->data_len - p_session_ctx->meta_size - p_enc_ctx->copy_len;
2461 
2462  // copy custom sei after slice
2463  for (; i < p_enc_ctx->custom_sei_count; i++)
2464  {
2465  ni_custom_sei_t *p_custom_sei = &p_custom_sei_set->custom_sei[i];
2466  memcpy(p_dst, &p_custom_sei->data[0], p_custom_sei->size);
2467  p_dst += p_custom_sei->size;
2468  }
2469  } else
2470  {
2471  memcpy(p_dst, (uint8_t *)xpkt->p_data + p_session_ctx->meta_size,
2472  xpkt->data_len - p_session_ctx->meta_size);
2473  }
2474  return 0;
2475 }
2476 
2478  int is_pkt, int64_t *pkt_pts,
2479  int64_t *pkt_dts, int *pkt_flag)
2480 {
2481  ni_session_context_t *p_session_ctx = p_enc_ctx->api_ctx;
2482  ni_session_data_io_t *p_packet = p_enc_ctx->api_pkt;
2483  ni_packet_t *xpkt = &p_packet->data.packet;
2484  ni_custom_sei_set_t *p_custom_sei_set;
2485  p_custom_sei_set =
2486  p_session_ctx->pkt_custom_sei_set[p_enc_ctx->local_pts % NI_FIFO_SZ];
2487  // free buffer
2488  if (p_enc_ctx->custom_sei_count)
2489  {
2490  free(p_custom_sei_set);
2491  p_session_ctx->pkt_custom_sei_set[p_enc_ctx->local_pts % NI_FIFO_SZ] =
2492  NULL;
2493  }
2494 
2495  if (!is_pkt)
2496  {
2497  if (PIC_TYPE_I == xpkt->frame_type)
2498  {
2499  *pkt_flag |= 0x0001;
2500  }
2501  *pkt_pts = xpkt->pts;
2502  /* to ensure pts>dts for all frames, we assign a guess pts for the
2503  * first 'dtsOffset' frames and then the pts from input stream is
2504  * extracted from input pts FIFO. if GOP = IBBBP and PTSs = 0 1 2
2505  * 3 4 5 .. then out DTSs = -3 -2 -1 0 1 ... and -3 -2 -1 are the
2506  * guessed values if GOP = IBPBP and PTSs = 0 1 2 3 4 5 .. then
2507  * out DTSs = -1 0 1 2 3 ... and -1 is the guessed value the
2508  * number of guessed values is equal to dtsOffset
2509  */
2510  if (p_enc_ctx->total_frames_received < p_enc_ctx->dts_offset)
2511  {
2512  // guess dts
2513  int64_t bframes_delay = 0;
2514  if (p_session_ctx->enc_pts_w_idx > p_enc_ctx->dts_offset)
2515  bframes_delay = p_session_ctx->enc_pts_list[p_enc_ctx->dts_offset] - p_session_ctx->enc_pts_list[0];
2516  ni_log(NI_LOG_INFO, "%s xcoder_bframes_delay=%"PRId64"\n", __func__, bframes_delay);
2517  *pkt_dts = p_enc_ctx->first_frame_pts +
2518  ((p_enc_ctx->gop_offset_count - p_enc_ctx->dts_offset) * (bframes_delay ? bframes_delay / p_enc_ctx->dts_offset : p_enc_ctx->ticks_per_frame));
2519  p_enc_ctx->gop_offset_count++;
2520  } else
2521  {
2522  // get dts from pts FIFO
2523  *pkt_dts =
2524  p_session_ctx
2525  ->enc_pts_list[p_session_ctx->enc_pts_r_idx % NI_FIFO_SZ];
2526  p_session_ctx->enc_pts_r_idx++;
2527  }
2528  if (p_enc_ctx->total_frames_received >= 1)
2529  {
2530  if (*pkt_dts < p_enc_ctx->latest_dts)
2531  {
2532  ni_log(NI_LOG_INFO, "dts: %ld < latest_dts: %ld.\n", *pkt_dts,
2533  p_enc_ctx->latest_dts);
2534  }
2535  }
2536 
2537  if (*pkt_pts < p_enc_ctx->first_frame_pts)
2538  {
2539  ni_log(NI_LOG_INFO, "pts %ld less than first frame pts %ld. Force it to first frame pts\n",
2540  *pkt_pts, p_enc_ctx->first_frame_pts);
2541  *pkt_pts = p_enc_ctx->first_frame_pts;
2542  }
2543  if (*pkt_dts > *pkt_pts)
2544  {
2545  ni_log(NI_LOG_INFO, "dts: %ld, pts: %ld. Forcing dts = pts \n",
2546  *pkt_dts, *pkt_pts);
2547  *pkt_dts = *pkt_pts;
2548  }
2549 
2550  // For test script video checker purpose
2552  "XCoder recv pkt #%" PRId64 ""
2553  " pts %" PRId64 " dts %" PRId64 " frame_type %u avg qp %u\n",
2554  p_session_ctx->pkt_num - 1, *pkt_dts, *pkt_pts, xpkt->frame_type,
2555  xpkt->avg_frame_qp);
2556 
2557  p_enc_ctx->total_frames_received++;
2558  p_enc_ctx->latest_dts = *pkt_dts;
2559  }
2560  p_enc_ctx->encoder_eof = xpkt->end_of_stream;
2562  p_session_ctx->session_run_state)
2563  {
2564  // p_enc_ctx->retstatus = NI_QUADRA_SEQ_CHANGE_DRAINING;
2565  }
2566  return 0;
2567 }
2568 
2569 void ni_quadra_set_session_wh(void *session_ctx, int width, int height)
2570 {
2571  ni_session_context_t *p_session_ctx = session_ctx;
2572  p_session_ctx->ori_width = width;
2573  p_session_ctx->ori_height = height;
2574 }
2575 
2577 {
2578  ni_session_data_io_t *p_packet = p_enc_ctx->api_pkt;
2579  int ret = 0;
2580  ni_packet_t *xpkt = &p_packet->data.packet;
2582  {
2583  ni_log(
2584  NI_LOG_ERROR,
2585  "ni_quadra_packet_buffer_alloc: packet buffer size %d allocation failed\n",
2586  NI_MAX_TX_SZ);
2588  }
2589  return ret;
2590 }
2591 
2593 {
2594  return sizeof(ni_pkt_info);
2595 }
2596 
2597 void ni_quadra_get_pkt_info(void *session_ctx, void *data)
2598 {
2599  ni_session_context_t *p_session_ctx = session_ctx;
2600  ni_pkt_info *pkt_info = data;
2601  pkt_info->psnr_y = p_session_ctx->psnr_y;
2602  pkt_info->psnr_u = p_session_ctx->psnr_u;
2603  pkt_info->psnr_v = p_session_ctx->psnr_v;
2604  pkt_info->average_psnr = p_session_ctx->average_psnr;
2605  ni_log(NI_LOG_DEBUG,"Add PSNR Y:%lf U:%lf V:%lf Ava:%lf to packet side data\n",
2606  p_session_ctx->psnr_y,p_session_ctx->psnr_u, p_session_ctx->psnr_v,p_session_ctx->average_psnr);
2607 }
_ni_mastering_display_metadata::max_luminance
ni_rational_t max_luminance
Definition: ni_av_codec.h:208
_ni_encoder_cfg_params::frame_rate
int frame_rate
Definition: ni_device_api.h:2239
ni_set_demo_roi_map
ni_retcode_t ni_set_demo_roi_map(ni_session_context_t *p_enc_ctx)
Set up hard coded demo ROI map.
Definition: ni_device_api.c:11751
NI_RETCODE_ERROR_VPU_RECOVERY
@ NI_RETCODE_ERROR_VPU_RECOVERY
Definition: ni_defs.h:515
_ni_xcoder_params::luma_linesize
int luma_linesize
Definition: ni_device_api.h:2784
NI_PIX_FMT_BGRA
@ NI_PIX_FMT_BGRA
Definition: ni_device_api.h:267
NI_MAX_TX_SZ
#define NI_MAX_TX_SZ
Definition: ni_defs.h:249
_ni_session_context::sei_hdr_mastering_display_color_vol_len
int sei_hdr_mastering_display_color_vol_len
Definition: ni_device_api.h:1429
ni_encoder_params_set_value
ni_retcode_t ni_encoder_params_set_value(ni_xcoder_params_t *p_params, const char *name, const char *value)
Set value referenced by name in encoder parameters structure.
Definition: ni_device_api.c:5635
NI_DEVICE_TYPE_ENCODER
@ NI_DEVICE_TYPE_ENCODER
Definition: ni_defs.h:347
_ni_quadra_enc_context::forced_header_enable
int forced_header_enable
Definition: ni_quadra_enc_api.h:187
ff_to_ni_log_level
ni_log_level_t ff_to_ni_log_level(int fflog_level)
Convert ffmpeg log level integer to appropriate ni_log_level_t.
Definition: ni_log.c:224
g_xcoder_log_names
const char *const g_xcoder_log_names[NI_XCODER_LOG_NAMES_ARRAY_LEN]
Definition: ni_device_api.c:71
MASTERING_DISP_CHROMA_DEN
#define MASTERING_DISP_CHROMA_DEN
Definition: ni_av_codec.h:217
_ni_quadra_enc_context::seqChangeCount
int seqChangeCount
Definition: ni_quadra_enc_api.h:150
_ni_frame::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2667
_ni_xcoder_params::dolby_vision_profile
int dolby_vision_profile
Definition: ni_device_api.h:2739
_ni_session_context::auto_dl_handle
ni_device_handle_t auto_dl_handle
Definition: ni_device_api.h:1469
ni_frame_buffer_free
ni_retcode_t ni_frame_buffer_free(ni_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_frame_buffer_alloc or ni_encoder_frame...
Definition: ni_device_api.c:3561
ni_quadra_enc_init
int ni_quadra_enc_init(ni_quadra_enc_context_t *p_enc_ctx)
Initialize malloc device session_context and malloc params including ni_quadra_enc_context_t,...
Definition: ni_quadra_enc_api.c:672
_ni_frame::sei_hdr_content_light_level_info_offset
unsigned int sei_hdr_content_light_level_info_offset
Definition: ni_device_api.h:2637
_ni_packet::pts
long long pts
Definition: ni_device_api.h:2828
NI_QUADRA_ERROR_VPU_RECOVERY
@ NI_QUADRA_ERROR_VPU_RECOVERY
Definition: ni_quadra_filter_api.h:209
NI_CODEC_FLAG_GLOBAL_HEADER
#define NI_CODEC_FLAG_GLOBAL_HEADER
Definition: ni_quadra_enc_api.h:59
_ni_session_context::mdcv_max_min_lum_data_len
int mdcv_max_min_lum_data_len
Definition: ni_device_api.h:1430
_ni_custom_sei::size
uint32_t size
Definition: ni_device_api.h:1121
NI_QUADRA_PIX_FMT_8_TILED4X4
@ NI_QUADRA_PIX_FMT_8_TILED4X4
Definition: ni_quadra_filter_api.h:250
_ni_quadra_enc_context::ishwframe
int ishwframe
Definition: ni_quadra_enc_api.h:115
_ni_quadra_enc_context::timebase_den
int timebase_den
Definition: ni_quadra_enc_api.h:99
_ni_quadra_enc_context::reinit
int reinit
Definition: ni_quadra_enc_api.h:176
ni_quadra_encoder_receive_packet
int ni_quadra_encoder_receive_packet(ni_quadra_enc_context_t *p_enc_ctx)
Recive packet frome encode.
Definition: ni_quadra_enc_api.c:2162
_ni_session_context::prev_fps
uint32_t prev_fps
Params used in VFR mode Start///.
Definition: ni_device_api.h:1631
_ni_quadra_enc_context::nb_planes
int nb_planes
Definition: ni_quadra_enc_api.h:186
_ni_session_context::dev_xcoder_name
char dev_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1488
_ni_packet::recycle_index
int recycle_index
Definition: ni_device_api.h:2836
NI_ENC_MAX_SEI_BUF_SIZE
#define NI_ENC_MAX_SEI_BUF_SIZE
Definition: ni_device_api.h:399
ni_encoder_change_params_t
struct _ni_encoder_change_params_t ni_encoder_change_params_t
This is a data structure for encoding parameters that have changed.
_ni_frame::metadata_buffer_size
uint32_t metadata_buffer_size
Definition: ni_device_api.h:2696
ni_enc_copy_aux_data
void ni_enc_copy_aux_data(ni_session_context_t *p_enc_ctx, ni_frame_t *p_enc_frame, ni_frame_t *p_dec_frame, ni_codec_format_t codec_format, const uint8_t *mdcv_data, const uint8_t *cll_data, const uint8_t *cc_data, const uint8_t *udu_data, const uint8_t *hdrp_data, int is_hwframe, int is_semiplanar)
Copy auxiliary data that should be sent together with this frame to encoder.
Definition: ni_av_codec.c:2267
ni_device_close
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
Definition: ni_device_api.c:503
_ni_quadra_enc_context
Definition: ni_quadra_enc_api.h:74
_ni_quadra_enc_context::recycle_index
int recycle_index
Definition: ni_quadra_enc_api.h:179
NI_DEVICE_TYPE_DECODER
@ NI_DEVICE_TYPE_DECODER
Definition: ni_defs.h:346
_ni_quadra_enc_context::sentFrame
int sentFrame
Definition: ni_quadra_enc_api.h:159
_ni_quadra_enc_context::gotPacket
int gotPacket
Definition: ni_quadra_enc_api.h:157
_ni_session_context::enc_pts_w_idx
int64_t enc_pts_w_idx
Definition: ni_device_api.h:1441
_ni_session_context::session_id
uint32_t session_id
Definition: ni_device_api.h:1480
_ni_xcoder_params::source_width
int source_width
Definition: ni_device_api.h:2723
_ni_frame::reconf_len
unsigned int reconf_len
Definition: ni_device_api.h:2655
cll_data
uint8_t cll_data[NI_MAX_SEI_DATA]
Definition: ni_quadra_enc_api.c:1546
ni_quadra_enc_get_extra_data
int ni_quadra_enc_get_extra_data(ni_quadra_enc_context_t *p_enc_ctx, uint8_t *p_dst)
Copy niframe to make avframe.
Definition: ni_quadra_enc_api.c:2427
_ni_quadra_enc_context::dev_enc_idx
int dev_enc_idx
Definition: ni_quadra_enc_api.h:79
_ni_custom_sei::location
ni_custom_sei_location_t location
Definition: ni_device_api.h:1120
_niquadraFrameSurface1::device_handle
int32_t device_handle
Definition: ni_quadra_filter_api.h:392
ni_device_session_sequence_change
ni_retcode_t ni_device_session_sequence_change(ni_session_context_t *p_ctx, int width, int height, int bit_depth_factor, ni_device_type_t device_type)
Send sequence change information to device.
Definition: ni_device_api.c:11322
_ni_mastering_display_metadata::has_primaries
int has_primaries
Definition: ni_av_codec.h:211
_ni_pkt_info::psnr_u
double psnr_u
Definition: ni_device_api.h:1096
PIC_TYPE_P
@ PIC_TYPE_P
Definition: ni_device_api.h:385
_ni_quadra_enc_context::ff_log_level
int ff_log_level
Definition: ni_quadra_enc_api.h:106
NI_PIX_FMT_YUV420P
@ NI_PIX_FMT_YUV420P
Definition: ni_device_api.h:262
_ni_quadra_enc_context::gop_offset_count
int gop_offset_count
Definition: ni_quadra_enc_api.h:148
_ni_packet::end_of_stream
uint32_t end_of_stream
Definition: ni_device_api.h:2831
ni_frame_buffer_alloc
ni_retcode_t ni_frame_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, int alignment, int metadata_flag, int factor, int hw_frame_count, int is_planar)
Allocate preliminary memory for the frame buffer based on provided parameters. Applicable to YUV420 P...
Definition: ni_device_api.c:2123
_ni_mastering_display_metadata::min_luminance
ni_rational_t min_luminance
Definition: ni_av_codec.h:205
_ni_session_data_io::packet
ni_packet_t packet
Definition: ni_device_api.h:2871
_ni_quadra_enc_context::pix_fmt
int pix_fmt
Definition: ni_quadra_enc_api.h:109
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:427
_ni_content_light_level::max_fall
uint16_t max_fall
Definition: ni_av_codec.h:227
_ni_gop_params::poc_offset
int poc_offset
Definition: ni_device_api.h:1961
_ni_framerate::framerate_denom
int32_t framerate_denom
Definition: ni_device_api.h:701
NI_RETCODE_PARAM_ERROR_PIC_WIDTH
@ NI_RETCODE_PARAM_ERROR_PIC_WIDTH
Definition: ni_defs.h:480
ni_quadra_enc_make_niframe
int ni_quadra_enc_make_niframe(ni_quadra_enc_context_t *p_enc_ctx, uint8_t **data, uint8_t *nidata, int *linesize, int frame_width, int frame_height, NIFramesContext *nif_src_ctx)
Copy avframe to niframe.
Definition: ni_quadra_enc_api.c:1752
_ni_quadra_enc_context::HDR10CLLEnable
int HDR10CLLEnable
Definition: ni_quadra_enc_api.h:173
ni_encoder_sw_frame_buffer_alloc
ni_retcode_t ni_encoder_sw_frame_buffer_alloc(bool planar, ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
This API is a wrapper for ni_encoder_frame_buffer_alloc(), used for planar pixel formats,...
Definition: ni_device_api.c:3531
NI_2PASS_ENCODE_MIN_WIDTH
#define NI_2PASS_ENCODE_MIN_WIDTH
Definition: ni_device_api.h:128
NI_FRAME_AUX_DATA_CRF
@ NI_FRAME_AUX_DATA_CRF
Definition: ni_device_api.h:574
_ni_session_context::param_err_msg
char param_err_msg[512]
Definition: ni_device_api.h:1528
_ni_session_context::ori_chroma_linesize
int ori_chroma_linesize
Definition: ni_device_api.h:1681
_ni_quadra_enc_context::auto_dl_handle
int auto_dl_handle
Definition: ni_quadra_enc_api.h:114
_ni_quadra_enc_context::timebase_num
int timebase_num
Definition: ni_quadra_enc_api.h:98
ni_log_set_level
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition: ni_log.c:202
ni_quadra_setup_encoder
int ni_quadra_setup_encoder(ni_quadra_enc_context_t *p_enc_ctx)
Initialize init device session_context and init default params including ni_quadra_enc_context_t,...
Definition: ni_quadra_enc_api.c:395
_ni_xcoder_params::rootBufId
int rootBufId
Definition: ni_device_api.h:2775
_ni_custom_sei::data
uint8_t data[NI_MAX_CUSTOM_SEI_DATA]
Definition: ni_device_api.h:1122
ni_rsrc_api.h
Public definitions for managing NETINT video processing devices.
ni_quadra_encode_close
int ni_quadra_encode_close(ni_quadra_enc_context_t *p_enc_ctx)
Close device session_context including ni_quadra_enc_context_t,.
Definition: ni_quadra_enc_api.c:856
ni_av_codec.h
Audio/video related utility definitions.
NI_2PASS_ENCODE_MIN_HEIGHT
#define NI_2PASS_ENCODE_MIN_HEIGHT
Definition: ni_device_api.h:129
ni_packet_buffer_free
ni_retcode_t ni_packet_buffer_free(ni_packet_t *p_packet)
Free packet buffer that was previously allocated with ni_packet_buffer_alloc.
Definition: ni_device_api.c:3843
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1465
NI_QUADRA_EAGAIN
@ NI_QUADRA_EAGAIN
Definition: ni_quadra_filter_api.h:211
NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
Definition: ni_defs.h:502
_ni_encoder_cfg_params::roi_enable
int roi_enable
Definition: ni_device_api.h:2257
_ni_encoder_cfg_params::intra_period
int intra_period
Definition: ni_device_api.h:2260
_ni_quadra_enc_context::color_range
int color_range
Definition: ni_quadra_enc_api.h:123
_ni_quadra_enc_context::need_to_recycle
bool need_to_recycle
Definition: ni_quadra_enc_api.h:180
_ni_packet::frame_type
uint32_t frame_type
Definition: ni_device_api.h:2835
ni_encoder_frame_zerocopy_check
ni_retcode_t ni_encoder_frame_zerocopy_check(ni_session_context_t *p_enc_ctx, ni_xcoder_params_t *p_enc_params, int width, int height, const int linesize[], bool set_linesize)
Check if incoming frame is encoder zero copy compatible or not.
Definition: ni_device_api.c:2733
_ni_session_context::prev_pts
uint64_t prev_pts
Definition: ni_device_api.h:1633
_ni_session_context::light_level_data_len
int light_level_data_len
Definition: ni_device_api.h:1427
_ni_gop_params::pic_type
int pic_type
Definition: ni_device_api.h:1965
NIFramesContext::api_ctx
void * api_ctx
Definition: ni_quadra_filter_api.h:405
_ni_quadra_enc_context::latest_dts
int64_t latest_dts
Definition: ni_quadra_enc_api.h:153
_ni_encoder_cfg_params::gop_preset_index
int gop_preset_index
Definition: ni_device_api.h:2251
_ni_frame::sei_user_data_unreg_len
unsigned int sei_user_data_unreg_len
Definition: ni_device_api.h:2644
_ni_session_context::force_frame_type
int force_frame_type
Definition: ni_device_api.h:1542
ni_quadra_enc_gop_params_check
bool ni_quadra_enc_gop_params_check(ni_quadra_enc_context_t *p_enc_ctx)
Check gop_params.
Definition: ni_quadra_enc_api.c:42
_ni_xcoder_params::roi_demo_mode
int roi_demo_mode
Definition: ni_device_api.h:2730
_ni_session_context::src_endian
int src_endian
Definition: ni_device_api.h:1493
_ni_frame::sei_total_len
unsigned int sei_total_len
Definition: ni_device_api.h:2629
_ni_quadra_enc_context::end_of_stream
int end_of_stream
Definition: ni_quadra_enc_api.h:178
_ni_frame::p_buffer
uint8_t * p_buffer
Definition: ni_device_api.h:2666
_ni_quadra_enc_context::extradata_size
int extradata_size
Definition: ni_quadra_enc_api.h:96
NI_FIFO_SZ
#define NI_FIFO_SZ
Definition: ni_defs.h:291
_ni_frame::dts
long long dts
Definition: ni_device_api.h:2606
_ni_quadra_enc_context::xcode_load_pixel
uint64_t xcode_load_pixel
Definition: ni_quadra_enc_api.h:82
_ni_encoder_cfg_params::aspectRatioWidth
int aspectRatioWidth
Definition: ni_device_api.h:2240
NI_RETCODE_INVALID_PARAM
@ NI_RETCODE_INVALID_PARAM
Definition: ni_defs.h:429
_ni_quadra_enc_context::blk_xcoder_name
char * blk_xcoder_name
Definition: ni_quadra_enc_api.h:78
NI_FRAME_BIG_ENDIAN
#define NI_FRAME_BIG_ENDIAN
Definition: ni_device_api.h:109
_ni_encoder_cfg_params::HDR10AveLight
int HDR10AveLight
Definition: ni_device_api.h:2271
_ni_encoder_cfg_params::rc
struct _ni_encoder_cfg_params::@16 rc
NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:311
_ni_mastering_display_metadata
Definition: ni_av_codec.h:196
_ni_quadra_enc_context::p_spsPpsHdr
uint8_t * p_spsPpsHdr
Definition: ni_quadra_enc_api.h:142
_ni_content_light_level
Definition: ni_av_codec.h:221
_ni_frame::preferred_characteristics_data_len
uint8_t preferred_characteristics_data_len
Definition: ni_device_api.h:2671
NI_QUADRA_PIX_FMT_P010LE
@ NI_QUADRA_PIX_FMT_P010LE
Definition: ni_quadra_filter_api.h:240
NI_PIX_FMT_8_TILED4X4
@ NI_PIX_FMT_8_TILED4X4
Definition: ni_device_api.h:275
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1494
_ni_frame::force_pic_qp
uint16_t force_pic_qp
Definition: ni_device_api.h:2659
_ni_packet::av1_buffer_index
int av1_buffer_index
Definition: ni_device_api.h:2848
ni_quadra_frame_new_aux_data
void ni_quadra_frame_new_aux_data(ni_quadra_enc_context_t *p_enc_ctx, void *side_data, int data_size, int type)
Add a new auxiliary data to a frame.
Definition: ni_quadra_enc_api.c:1497
_ni_encoder_cfg_params::crf
int crf
Definition: ni_device_api.h:2269
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1478
NI_ENABLE_AUD_FOR_GLOBAL_HEADER
#define NI_ENABLE_AUD_FOR_GLOBAL_HEADER
Definition: ni_device_api.h:209
ni_copy_hw_yuv420p
void ni_copy_hw_yuv420p(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int factor, int is_semiplanar, int conf_win_right, int dst_stride[NI_MAX_NUM_DATA_POINTERS], int dst_height[NI_MAX_NUM_DATA_POINTERS], int src_stride[NI_MAX_NUM_DATA_POINTERS], int src_height[NI_MAX_NUM_DATA_POINTERS])
Copy YUV data to Netint HW YUV420p frame layout to be sent to encoder for encoding....
Definition: ni_util.c:2352
_ni_quadra_enc_context::user_sar_num
int user_sar_num
Definition: ni_quadra_enc_api.h:133
NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE
@ NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE
Definition: ni_device_api.h:586
_ni_quadra_enc_context::codec_format
int codec_format
Definition: ni_quadra_enc_api.h:107
_ni_session_context::ori_width
int ori_width
Definition: ni_device_api.h:1562
NI_FRAME_AUX_DATA_VBV_MAX_RATE
@ NI_FRAME_AUX_DATA_VBV_MAX_RATE
Definition: ni_device_api.h:582
_ni_session_context::ddr_config
uint8_t ddr_config
Definition: ni_device_api.h:1626
NI_QUADRA_PIX_FMT_10_TILED4X4
@ NI_QUADRA_PIX_FMT_10_TILED4X4
Definition: ni_quadra_filter_api.h:251
NI_QUADRA_PIX_FMT_YUV420P
@ NI_QUADRA_PIX_FMT_YUV420P
Definition: ni_quadra_filter_api.h:237
NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
Definition: ni_defs.h:498
_ni_quadra_enc_context::color_space
int color_space
Definition: ni_quadra_enc_api.h:122
NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_MEM_ALOC
Definition: ni_defs.h:431
_ni_content_light_level::max_cll
uint16_t max_cll
Definition: ni_av_codec.h:224
ni_quadra_encoder_xcoder_opts_params_set_value
int ni_quadra_encoder_xcoder_opts_params_set_value(ni_quadra_enc_context_t *p_enc_ctx, const char *name, const char *value)
Set value referenced by name in encode parameters structure.
Definition: ni_quadra_enc_api.c:48
_ni_quadra_enc_context::framerate_num
int framerate_num
Definition: ni_quadra_enc_api.h:100
SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
Definition: ni_device_api.h:1178
_ni_quadra_enc_context::total_frames_received
uint64_t total_frames_received
Definition: ni_quadra_enc_api.h:151
ni_enc_prep_aux_data
void ni_enc_prep_aux_data(ni_session_context_t *p_enc_ctx, ni_frame_t *p_enc_frame, ni_frame_t *p_dec_frame, ni_codec_format_t codec_format, int should_send_sei_with_frame, uint8_t *mdcv_data, uint8_t *cll_data, uint8_t *cc_data, uint8_t *udu_data, uint8_t *hdrp_data)
Prepare auxiliary data that should be sent together with this frame to encoder based on the auxiliary...
Definition: ni_av_codec.c:858
ni_quadra_encode_reinit
int ni_quadra_encode_reinit(ni_quadra_enc_context_t *p_enc_ctx, int frame_width, int frame_height, const int *linesize)
Reinit encode context.
Definition: ni_quadra_enc_api.c:2050
ni_packet_buffer_alloc
ni_retcode_t ni_packet_buffer_alloc(ni_packet_t *p_packet, int packet_size)
Allocate memory for the packet buffer based on provided packet size.
Definition: ni_device_api.c:3713
ni_frame_new_aux_data
ni_aux_data_t * ni_frame_new_aux_data(ni_frame_t *frame, ni_aux_data_type_t type, int data_size)
Add a new auxiliary data to a frame.
Definition: ni_device_api.c:4005
_ni_quadra_enc_context::width
int width
Definition: ni_quadra_enc_api.h:104
NI_RETCODE_PARAM_INVALID_VALUE
@ NI_RETCODE_PARAM_INVALID_VALUE
Definition: ni_defs.h:437
_ni_frame::sei_hdr_mastering_display_color_vol_offset
unsigned int sei_hdr_mastering_display_color_vol_offset
Definition: ni_device_api.h:2635
_ni_frame::sei_cc_offset
unsigned int sei_cc_offset
Definition: ni_device_api.h:2632
_ni_pkt_info::average_psnr
double average_psnr
Definition: ni_device_api.h:1098
_ni_session_context::average_psnr
double average_psnr
Definition: ni_device_api.h:1713
_ni_quadra_enc_context::framerate_den
int framerate_den
Definition: ni_quadra_enc_api.h:101
ni_quadra_enc_send_frame
int ni_quadra_enc_send_frame(ni_quadra_enc_context_t *p_enc_ctx)
Send niframe to do encoder.
Definition: ni_quadra_enc_api.c:2013
_ni_quadra_enc_context::spsPpsHdrLen
int spsPpsHdrLen
Definition: ni_quadra_enc_api.h:143
_ni_custom_gop_params::custom_gop_size
int custom_gop_size
Definition: ni_device_api.h:2052
XCODER_TEST_RECONF_OFF
@ XCODER_TEST_RECONF_OFF
Definition: ni_device_api.h:1741
_ni_pkt_info
Definition: ni_device_api.h:1093
_ni_encoder_cfg_params::HDR10dx2
int HDR10dx2
Definition: ni_device_api.h:2278
udu_data
uint8_t udu_data[NI_MAX_SEI_DATA]
Definition: ni_quadra_enc_api.c:1548
_ni_session_context::psnr_v
double psnr_v
Definition: ni_device_api.h:1712
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:61
_ni_quadra_enc_context::codec_id
int codec_id
Definition: ni_quadra_enc_api.h:108
_ni_quadra_enc_context::nvme_io_size
int nvme_io_size
Definition: ni_quadra_enc_api.h:161
_ni_encoder_cfg_params::HDR10wx
int HDR10wx
Definition: ni_device_api.h:2280
NI_QUADRA_PIX_FMT_YUV420P10LE
@ NI_QUADRA_PIX_FMT_YUV420P10LE
Definition: ni_quadra_filter_api.h:238
_ni_xcoder_params::source_height
int source_height
Definition: ni_device_api.h:2728
_ni_quadra_enc_context::orig_dev_enc_idx
int orig_dev_enc_idx
Definition: ni_quadra_enc_api.h:155
MASTERING_DISP_LUMA_DEN
#define MASTERING_DISP_LUMA_DEN
Definition: ni_av_codec.h:218
NI_APP_ENC_FRAME_META_DATA_SIZE
#define NI_APP_ENC_FRAME_META_DATA_SIZE
Definition: ni_defs.h:308
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:60
_ni_frame::ni_pict_type
ni_pic_type_t ni_pict_type
Definition: ni_device_api.h:2627
_ni_session_context::src_bit_depth
int src_bit_depth
Definition: ni_device_api.h:1492
_ni_framerate::framerate_num
int32_t framerate_num
Definition: ni_device_api.h:698
ni_quadra_get_pkt_info_size
int ni_quadra_get_pkt_info_size(void)
Get struct ni_pkt_info size.
Definition: ni_quadra_enc_api.c:2592
_ni_encoder_cfg_params::HDR10maxluma
int HDR10maxluma
Definition: ni_device_api.h:2282
_ni_quadra_enc_context::height
int height
Definition: ni_quadra_enc_api.h:105
_ni_xcoder_params::cfg_enc_params
ni_encoder_cfg_params_t cfg_enc_params
Definition: ni_device_api.h:2765
ni_pkt_info
struct _ni_pkt_info ni_pkt_info
NIODD2EVEN
#define NIODD2EVEN(X)
Definition: ni_quadra_enc_api.h:55
ni_defs.h
Common NETINT definitions used by all modules.
NI_PIX_FMT_NV12
@ NI_PIX_FMT_NV12
Definition: ni_device_api.h:264
_ni_quadra_enc_context::started
int started
Definition: ni_quadra_enc_api.h:141
ni_encoder_gop_params_set_value
ni_retcode_t ni_encoder_gop_params_set_value(ni_xcoder_params_t *p_params, const char *name, const char *value)
Set GOP parameter value referenced by name in encoder parameters structure.
Definition: ni_device_api.c:7197
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2664
_ni_frame::extra_data_len
unsigned int extra_data_len
Definition: ni_device_api.h:2657
_ni_encoder_cfg_params::intra_qp
int intra_qp
Definition: ni_device_api.h:2368
PIC_TYPE_I
@ PIC_TYPE_I
Definition: ni_device_api.h:384
_ni_quadra_enc_context::copy_len
uint32_t copy_len
Definition: ni_quadra_enc_api.h:184
ni_quadra_packet_buffer_alloc
int ni_quadra_packet_buffer_alloc(ni_quadra_enc_context_t *p_enc_ctx)
Allocate memory for the packet buffer based on provided packet size.
Definition: ni_quadra_enc_api.c:2576
_ni_quadra_enc_context::eos_fme_received
int eos_fme_received
Definition: ni_quadra_enc_api.h:87
ni_gop_params_check_set
void ni_gop_params_check_set(ni_xcoder_params_t *p_param, char *value)
Set custom gop and prepare to check if success.
Definition: ni_device_api.c:12614
_ni_session_context::passed_time_in_timebase_unit
uint32_t passed_time_in_timebase_unit
Definition: ni_device_api.h:1653
PIC_TYPE_B
@ PIC_TYPE_B
Definition: ni_device_api.h:386
_ni_encoder_cfg_params::multicoreJointMode
int multicoreJointMode
Definition: ni_device_api.h:2289
ni_encoder_init_default_params
ni_retcode_t ni_encoder_init_default_params(ni_xcoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height, ni_codec_format_t codec_format)
Initialize default encoder parameters.
Definition: ni_device_api.c:4147
_ni_quadra_enc_context::ticks_per_frame
int ticks_per_frame
Definition: ni_quadra_enc_api.h:102
_ni_quadra_enc_context::input_frame
void * input_frame
Definition: ni_quadra_enc_api.h:93
NI_FRAME_AUX_DATA_FRAMERATE
@ NI_FRAME_AUX_DATA_FRAMERATE
Definition: ni_device_api.h:562
_ni_quadra_enc_context::tmp_device_handle
int32_t tmp_device_handle
Definition: ni_quadra_enc_api.h:84
_ni_quadra_enc_context::sar_num
int sar_num
Definition: ni_quadra_enc_api.h:131
_ni_quadra_enc_context::total_custom_sei_size
int total_custom_sei_size
Definition: ni_quadra_enc_api.h:182
_ni_encoder_cfg_params::HDR10dy0
int HDR10dy0
Definition: ni_device_api.h:2275
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:63
_ni_frame::end_of_stream
uint32_t end_of_stream
Definition: ni_device_api.h:2608
PIC_TYPE_IDR
@ PIC_TYPE_IDR
Definition: ni_device_api.h:389
_ni_xcoder_params::generate_enc_hdrs
NI_DEPRECATED int generate_enc_hdrs
Definition: ni_device_api.h:2735
_ni_xcoder_params::hwframes
int hwframes
Definition: ni_device_api.h:2774
_ni_quadra_enc_context::custom_sei_count
int custom_sei_count
Definition: ni_quadra_enc_api.h:183
ni_quadra_encoder_xcoder_gop_params_set_value
int ni_quadra_encoder_xcoder_gop_params_set_value(ni_quadra_enc_context_t *p_enc_ctx, const char *name, const char *value)
Set value referenced by name in encode parameters structure.
Definition: ni_quadra_enc_api.c:94
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1462
_ni_quadra_enc_context::need_free_frame
int need_free_frame
Definition: ni_quadra_enc_api.h:185
_ni_session_context::p_session_config
void * p_session_config
Definition: ni_device_api.h:1473
_ni_mastering_display_metadata::has_luminance
int has_luminance
Definition: ni_av_codec.h:214
_ni_frame::sei_hdr_plus_len
unsigned int sei_hdr_plus_len
Definition: ni_device_api.h:2641
_ni_quadra_enc_context::dev_xcoder_name
char * dev_xcoder_name
Definition: ni_quadra_enc_api.h:77
_ni_custom_sei_set
Definition: ni_device_api.h:1125
cc_data
uint8_t cc_data[NI_MAX_SEI_DATA]
Definition: ni_quadra_enc_api.c:1547
ni_quadra_encode_sequence_change
int ni_quadra_encode_sequence_change(ni_quadra_enc_context_t *p_enc_ctx, int width, int height, int bit_depth_factor)
Set encode sequence change.
Definition: ni_quadra_enc_api.c:926
_ni_packet::p_data
void * p_data
Definition: ni_device_api.h:2837
ni_quadra_set_session_wh
void ni_quadra_set_session_wh(void *session_ctx, int width, int height)
Set width and height to session context.
Definition: ni_quadra_enc_api.c:2569
_ni_session_data_io
Definition: ni_device_api.h:2866
_ni_quadra_enc_context::encoder_eof
int encoder_eof
Definition: ni_quadra_enc_api.h:164
_ni_quadra_enc_context::extradata
uint8_t * extradata
Definition: ni_quadra_enc_api.h:95
ni_enc_prep_reconf_demo_data
ni_retcode_t ni_enc_prep_reconf_demo_data(ni_session_context_t *p_enc_ctx, ni_frame_t *p_frame)
Convert various reconfig and demo modes (stored in encoder configuration) to aux data and store them ...
Definition: ni_device_api.c:11947
_ni_quadra_enc_context::color_trc
int color_trc
Definition: ni_quadra_enc_api.h:121
ni_find_start_code
const uint8_t * ni_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state)
Find the next start code.
Definition: ni_av_codec.c:2897
_ni_session_context::last_change_framenum
uint32_t last_change_framenum
Definition: ni_device_api.h:1634
_ni_rational::num
int num
Definition: ni_device_api.h:600
NI_PIX_FMT_YUV420P10LE
@ NI_PIX_FMT_YUV420P10LE
Definition: ni_device_api.h:263
ni_log
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Definition: ni_log.c:183
_ni_session_context::sender_handle
ni_device_handle_t sender_handle
Definition: ni_device_api.h:1468
NI_QUADRA_PIX_FMT_ARGB
@ NI_QUADRA_PIX_FMT_ARGB
Definition: ni_quadra_filter_api.h:243
NI_FRAME_AUX_DATA_REGIONS_OF_INTEREST
@ NI_FRAME_AUX_DATA_REGIONS_OF_INTEREST
Definition: ni_device_api.h:519
ni_content_light_level_t
struct _ni_content_light_level ni_content_light_level_t
_ni_session_context::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1521
ni_quadra_filter_session_dl_set
void ni_quadra_filter_session_dl_set(void *session_ctx, bool value)
Set download filter session context.
Definition: ni_quadra_filter_api.c:1679
_ni_encoder_cfg_params::EnableAUD
int EnableAUD
Definition: ni_device_api.h:2301
_ni_quadra_enc_context::dev_blk_name
char * dev_blk_name
Definition: ni_quadra_enc_api.h:80
_niquadraFrameSurface1
Definition: ni_quadra_filter_api.h:385
_ni_quadra_enc_context::data_len
uint32_t data_len
Definition: ni_quadra_enc_api.h:117
NI_QUADRA_RET_SUCCESS
@ NI_QUADRA_RET_SUCCESS
Definition: ni_quadra_filter_api.h:207
_ni_frame::force_key_frame
int force_key_frame
Definition: ni_device_api.h:2624
NI_GET_MAX_HWDESC_FRAME_INDEX
#define NI_GET_MAX_HWDESC_FRAME_INDEX(x)
Definition: ni_defs.h:278
ni_encoder_frame_zerocopy_buffer_alloc
ni_retcode_t ni_encoder_frame_zerocopy_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, const int linesize[], const uint8_t *data[], int extra_len)
Allocate memory for encoder zero copy (metadata, etc.) for encoding based on given parameters,...
Definition: ni_device_api.c:2879
LRETURN
#define LRETURN
Definition: ni_defs.h:323
NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
Definition: ni_device_api.h:920
NI_QUADRA_PIX_FMT_BGRA
@ NI_QUADRA_PIX_FMT_BGRA
Definition: ni_quadra_filter_api.h:242
_ni_quadra_enc_context::bget_psnr
bool bget_psnr
Definition: ni_quadra_enc_api.h:190
_ni_encoder_cfg_params::HDR10CLLEnable
int HDR10CLLEnable
Definition: ni_device_api.h:2272
ni_expand_frame
int ni_expand_frame(ni_frame_t *dst, ni_frame_t *src, int dst_stride[], int raw_width, int raw_height, int ni_fmt, int nb_planes)
Expand frame form src frame.
Definition: ni_av_codec.c:3289
NI_RETCODE_PARAM_WARNING_DEPRECATED
@ NI_RETCODE_PARAM_WARNING_DEPRECATED
Definition: ni_defs.h:516
_ni_aux_data::data
void * data
Definition: ni_device_api.h:621
NI_QUADRA_SEQ_CHANGE_DRAINING
@ NI_QUADRA_SEQ_CHANGE_DRAINING
Definition: ni_quadra_filter_api.h:208
_ni_xcoder_params::chroma_linesize
int chroma_linesize
Definition: ni_device_api.h:2785
ni_quadra_enc_device_session_flush
int ni_quadra_enc_device_session_flush(ni_quadra_enc_context_t *p_enc_ctx)
Flush encode session context.
Definition: ni_quadra_enc_api.c:2045
_ni_quadra_enc_context::reconfigCount
int reconfigCount
Definition: ni_quadra_enc_api.h:169
_ni_packet
Definition: ni_device_api.h:2825
_ni_session_context::frame_num
uint64_t frame_num
Definition: ni_device_api.h:1531
_ni_frame::sei_cc_len
unsigned int sei_cc_len
Definition: ni_device_api.h:2633
_ni_encoder_cfg_params::HDR10Enable
int HDR10Enable
Definition: ni_device_api.h:2273
ni_device_session_context_clear
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
Definition: ni_device_api.c:249
_ni_quadra_enc_context::HDR10Enable
int HDR10Enable
Definition: ni_quadra_enc_api.h:174
_ni_encoder_cfg_params::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2386
_ni_quadra_enc_context::enable_test_latency
bool enable_test_latency
Definition: ni_quadra_enc_api.h:189
_ni_session_context::ori_luma_linesize
int ori_luma_linesize
Definition: ni_device_api.h:1680
_ni_quadra_enc_context::tmp_blk_dev_name
char tmp_blk_dev_name[32]
Definition: ni_quadra_enc_api.h:83
NI_MAX_CUSTOM_SEI_DATA
#define NI_MAX_CUSTOM_SEI_DATA
Definition: ni_device_api.h:428
_ni_custom_sei::type
uint8_t type
Definition: ni_device_api.h:1119
_ni_encoder_cfg_params::colorDescPresent
int colorDescPresent
Definition: ni_device_api.h:2311
NIALIGN
#define NIALIGN(x, a)
Definition: ni_quadra_enc_api.h:54
NI_RETCODE_PARAM_ERROR_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_TOO_BIG
Definition: ni_defs.h:489
NI_CODEC_ID_MJPEG
#define NI_CODEC_ID_MJPEG
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2663
_ni_encoder_cfg_params::custom_gop_params
ni_custom_gop_params_t custom_gop_params
Definition: ni_device_api.h:2255
_ni_encoder_cfg_params::HDR10dx0
int HDR10dx0
Definition: ni_device_api.h:2274
_ni_session_context::fps_change_detect_count
uint32_t fps_change_detect_count
Definition: ni_device_api.h:1635
_ni_quadra_enc_context::bit_depth
int bit_depth
Definition: ni_quadra_enc_api.h:177
_ni_quadra_enc_context::api_ctx
void * api_ctx
Definition: ni_quadra_enc_api.h:91
_ni_quadra_enc_context::api_pkt
void * api_pkt
Definition: ni_quadra_enc_api.h:89
_ni_quadra_enc_context::dts_offset
int64_t dts_offset
Definition: ni_quadra_enc_api.h:147
_ni_frame::roi_len
unsigned int roi_len
Definition: ni_device_api.h:2653
_ni_quadra_enc_context::start_of_stream
int start_of_stream
Definition: ni_quadra_enc_api.h:175
_ni_quadra_enc_context::generate_enc_hdrs
bool generate_enc_hdrs
Definition: ni_quadra_enc_api.h:191
ni_quadra_encoder_prepare_avpkt
int ni_quadra_encoder_prepare_avpkt(ni_quadra_enc_context_t *p_enc_ctx, int is_pkt, int64_t *pkt_pts, int64_t *pkt_dts, int *pkt_flag)
Make avpkt from encode.
Definition: ni_quadra_enc_api.c:2477
_ni_encoder_cfg_params::enable_all_sei_passthru
bool enable_all_sei_passthru
Definition: ni_device_api.h:2421
NI_ERRNO
#define NI_ERRNO
Definition: ni_defs.h:217
_ni_encoder_cfg_params::disable_adaptive_buffers
bool disable_adaptive_buffers
Definition: ni_device_api.h:2425
NIFramesContext
Definition: ni_quadra_filter_api.h:400
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
Definition: ni_defs.h:494
_ni_quadra_enc_context::is_swframes
bool is_swframes
Definition: ni_quadra_enc_api.h:165
_ni_frame::sei_hdr_plus_offset
unsigned int sei_hdr_plus_offset
Definition: ni_device_api.h:2640
_ni_session_context::hw_action
int hw_action
Definition: ni_device_api.h:1609
_ni_session_context
Definition: ni_device_api.h:1408
ni_quadra_encode_send_prepare
int ni_quadra_encode_send_prepare(ni_quadra_enc_context_t *p_enc_ctx, niquadraFrameSurface1_t *p_surface, int frame_width, int frame_height)
Prepare a niframe which to send to encoder.
Definition: ni_quadra_enc_api.c:1210
NI_PIX_FMT_P010LE
@ NI_PIX_FMT_P010LE
Definition: ni_device_api.h:265
ni_quadra_get_pkt_info
void ni_quadra_get_pkt_info(void *session_ctx, void *data)
Get ni_pkt_info psnr info.
Definition: ni_quadra_enc_api.c:2597
ni_device_session_read
int ni_device_session_read(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, ni_device_type_t device_type)
Read data from the device If device_type is NI_DEVICE_TYPE_DECODER reads data packet from decoder If ...
Definition: ni_device_api.c:1769
ni_long_term_ref_t
struct _ni_long_term_ref ni_long_term_ref_t
_niFrameSurface1
Definition: ni_device_api.h:2793
_ni_quadra_enc_context::tmp_hw_id
int tmp_hw_id
Definition: ni_quadra_enc_api.h:86
NI_CODEC_HW_ENABLE
@ NI_CODEC_HW_ENABLE
Definition: ni_device_api.h:940
ni_frame_buffer_alloc_hwenc
ni_retcode_t ni_frame_buffer_alloc_hwenc(ni_frame_t *p_frame, int video_width, int video_height, int extra_len)
Allocate memory for the hwDescriptor buffer based on provided parameters taking into account pic size...
Definition: ni_device_api.c:8399
NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_NUM_DATA_POINTERS
Definition: ni_defs.h:232
NI_MAX_DEVICE_NAME_LEN
#define NI_MAX_DEVICE_NAME_LEN
Definition: ni_defs.h:224
_ni_quadra_enc_context::reconf_demo_mode
int reconf_demo_mode
Definition: ni_quadra_enc_api.h:170
_ni_quadra_enc_context::sw_pix_fmt
int sw_pix_fmt
Definition: ni_quadra_enc_api.h:110
_ni_session_data_io::data
union _ni_session_data_io::@19 data
_ni_session_context::blk_xcoder_name
char blk_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1490
_ni_frame
Definition: ni_device_api.h:2601
_ni_quadra_enc_context::frame_pts
int64_t frame_pts
Definition: ni_quadra_enc_api.h:112
_ni_encoder_cfg_params::HDR10dy1
int HDR10dy1
Definition: ni_device_api.h:2277
NI_PIX_FMT_RGBA
@ NI_PIX_FMT_RGBA
Definition: ni_device_api.h:266
_ni_encoder_cfg_params::conf_win_bottom
int conf_win_bottom
Definition: ni_device_api.h:2298
ni_device_session_open
ni_retcode_t ni_device_session_open(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Open a new device session depending on the device_type parameter If device_type is NI_DEVICE_TYPE_DEC...
Definition: ni_device_api.c:710
NI_QUADRA_PIX_FMT_YUVJ420P
@ NI_QUADRA_PIX_FMT_YUVJ420P
Definition: ni_quadra_filter_api.h:254
_ni_session_context::roi_len
uint32_t roi_len
Definition: ni_device_api.h:1496
NI_QUADRA_PIX_FMT_NV12
@ NI_QUADRA_PIX_FMT_NV12
Definition: ni_quadra_filter_api.h:239
_niquadraFrameSurface1::bit_depth
int8_t bit_depth
Definition: ni_quadra_filter_api.h:393
_ni_quadra_enc_context::keep_alive_timeout
int keep_alive_timeout
Definition: ni_quadra_enc_api.h:81
_ni_encoder_cfg_params::colorSpace
int colorSpace
Definition: ni_device_api.h:2314
_ni_xcoder_params::force_pic_qp_demo_mode
int force_pic_qp_demo_mode
Definition: ni_device_api.h:2732
NI_RETCODE_ERROR_INVALID_SESSION
@ NI_RETCODE_ERROR_INVALID_SESSION
Definition: ni_defs.h:433
NI_PIX_FMT_ABGR
@ NI_PIX_FMT_ABGR
Definition: ni_device_api.h:269
NI_QUADRA_ERROR_INVALID_SESSION
@ NI_QUADRA_ERROR_INVALID_SESSION
Definition: ni_quadra_filter_api.h:210
NI_QUADRA_PIX_FMT_ABGR
@ NI_QUADRA_PIX_FMT_ABGR
Definition: ni_quadra_filter_api.h:244
ni_session_run_state_t
enum _ni_session_run_state ni_session_run_state_t
Session running state type.
NI_PIX_FMT_ARGB
@ NI_PIX_FMT_ARGB
Definition: ni_device_api.h:268
_ni_xcoder_params
Definition: ni_device_api.h:2713
_ni_frame::sei_hdr_content_light_level_info_len
unsigned int sei_hdr_content_light_level_info_len
Definition: ni_device_api.h:2638
_ni_quadra_enc_context::color_primaries
int color_primaries
Definition: ni_quadra_enc_api.h:120
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
Definition: ni_defs.h:496
_ni_frame::sei_hdr_mastering_display_color_vol_len
unsigned int sei_hdr_mastering_display_color_vol_len
Definition: ni_device_api.h:2636
_ni_session_context::ready_to_close
uint32_t ready_to_close
Definition: ni_device_api.h:1544
ni_quadra_enc_api.h
NETINT encoder API header file.
_ni_encoder_cfg_params::HDR10minluma
int HDR10minluma
Definition: ni_device_api.h:2283
_ni_session_context::codec_format
uint32_t codec_format
Definition: ni_device_api.h:1486
ni_quadra_encode_after_reinit
int ni_quadra_encode_after_reinit(ni_quadra_enc_context_t *p_enc_ctx)
Reinit after need to sync context.
Definition: ni_quadra_enc_api.c:2147
ni_quadra_xcoder_encoder_headers
int ni_quadra_xcoder_encoder_headers(ni_quadra_enc_context_t *p_enc_ctx)
Definition: ni_quadra_enc_api.c:192
_ni_session_context::psnr_y
double psnr_y
Definition: ni_device_api.h:1710
NI_RETCODE_PARAM_ERROR_PIC_HEIGHT
@ NI_RETCODE_PARAM_ERROR_PIC_HEIGHT
Definition: ni_defs.h:482
_ni_encoder_cfg_params::colorPrimaries
int colorPrimaries
Definition: ni_device_api.h:2312
ni_quadra_enc_prep_aux_data
int ni_quadra_enc_prep_aux_data(ni_quadra_enc_context_t *p_enc_ctx, void *side_data, int data_size)
Prepare auxiliary data that should be sent together with this frame to encoder based on the auxiliary...
Definition: ni_quadra_enc_api.c:1551
_ni_quadra_enc_context::color_change
int color_change
Definition: ni_quadra_enc_api.h:124
_ni_encoder_cfg_params::crfFloat
float crfFloat
Definition: ni_device_api.h:2410
mdcv_data
uint8_t mdcv_data[NI_MAX_SEI_DATA]
Definition: ni_quadra_enc_api.c:1545
NI_QUADRA_PIX_FMT_YUV420P10BE
@ NI_QUADRA_PIX_FMT_YUV420P10BE
Definition: ni_quadra_filter_api.h:253
_ni_quadra_enc_context::api_fme
void * api_fme
Definition: ni_quadra_enc_api.h:90
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:2870
_ni_session_context::ori_pix_fmt
int ori_pix_fmt
Definition: ni_device_api.h:1562
_ni_quadra_enc_context::bit_rate
int64_t bit_rate
Definition: ni_quadra_enc_api.h:103
_ni_quadra_enc_context::enable_all_sei_passthru
int enable_all_sei_passthru
Definition: ni_quadra_enc_api.h:188
_ni_encoder_cfg_params::HDR10dy2
int HDR10dy2
Definition: ni_device_api.h:2279
NI_QUADRA_PARAM_WARNING_DEPRECATED
@ NI_QUADRA_PARAM_WARNING_DEPRECATED
Definition: ni_quadra_filter_api.h:213
_ni_pkt_info::psnr_y
double psnr_y
Definition: ni_device_api.h:1095
NI_RETCODE_PARAM_INVALID_NAME
@ NI_RETCODE_PARAM_INVALID_NAME
Definition: ni_defs.h:436
ni_get_hw_yuv420p_dim
void ni_get_hw_yuv420p_dim(int width, int height, int factor, int is_semiplanar, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of Netint HW YUV420p frame to be sent to encoder for encoding....
Definition: ni_util.c:2040
NI_QUADRA_ERROR
@ NI_QUADRA_ERROR
Definition: ni_quadra_filter_api.h:212
_ni_quadra_enc_context::encoder_flushing
int encoder_flushing
Definition: ni_quadra_enc_api.h:163
_ni_frame::video_height
uint32_t video_height
Definition: ni_device_api.h:2611
NI_QUADRA_PIX_FMT_RGBA
@ NI_QUADRA_PIX_FMT_RGBA
Definition: ni_quadra_filter_api.h:241
ni_quadra_enc_gop_params_set
void ni_quadra_enc_gop_params_set(ni_quadra_enc_context_t *p_enc_ctx, char *key)
Set gop_params.
Definition: ni_quadra_enc_api.c:36
_ni_encoder_cfg_params::colorTrc
int colorTrc
Definition: ni_device_api.h:2313
_ni_quadra_enc_context::api_param
void * api_param
Definition: ni_quadra_enc_api.h:92
NI_FRAME_AUX_DATA_LONG_TERM_REF
@ NI_FRAME_AUX_DATA_LONG_TERM_REF
Definition: ni_device_api.h:548
_ni_quadra_enc_context::dev_xcoder
char * dev_xcoder
Definition: ni_quadra_enc_api.h:76
NI_MAX_SEI_DATA
#define NI_MAX_SEI_DATA
Definition: ni_device_api.h:426
_ni_session_context::enc_pts_r_idx
int64_t enc_pts_r_idx
Definition: ni_device_api.h:1440
_ni_custom_sei
custom sei payload passthrough
Definition: ni_device_api.h:1117
_ni_session_context::count_frame_num_in_sec
uint32_t count_frame_num_in_sec
Definition: ni_device_api.h:1652
ni_gop_params_check
bool ni_gop_params_check(ni_xcoder_params_t *p_param)
Check custom gop params set.
Definition: ni_device_api.c:12749
_ni_encoder_cfg_params::conf_win_right
int conf_win_right
Definition: ni_device_api.h:2300
_ni_session_context::blk_dev_name
char blk_dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_device_api.h:1659
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1547
_ni_quadra_enc_context::firstPktArrived
int firstPktArrived
Definition: ni_quadra_enc_api.h:146
_ni_quadra_enc_context::pict_type
int pict_type
Definition: ni_quadra_enc_api.h:111
ni_device_session_write
int ni_device_session_write(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, ni_device_type_t device_type)
Sends data to the device If device_type is NI_DEVICE_TYPE_DECODER sends data packet to decoder If dev...
Definition: ni_device_api.c:1668
_ni_quadra_enc_context::sar_den
int sar_den
Definition: ni_quadra_enc_api.h:132
ni_device_api.h
Public definitions for operating NETINT video processing devices for video processing.
_ni_session_context::meta_size
uint32_t meta_size
Params used in VFR mode Done///.
Definition: ni_device_api.h:1638
_ni_encoder_cfg_params::HDR10MaxLight
int HDR10MaxLight
Definition: ni_device_api.h:2270
_ni_session_context::psnr_u
double psnr_u
Definition: ni_device_api.h:1711
_ni_mastering_display_metadata::white_point
ni_rational_t white_point[2]
Definition: ni_av_codec.h:202
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1476
_ni_encoder_cfg_params::aspectRatioHeight
int aspectRatioHeight
Definition: ni_device_api.h:2241
NI_FRAME_AUX_DATA_MASTERING_DISPLAY_METADATA
@ NI_FRAME_AUX_DATA_MASTERING_DISPLAY_METADATA
Definition: ni_device_api.h:505
NI_MIN_HEIGHT
#define NI_MIN_HEIGHT
Definition: ni_device_api.h:126
NI_RETCODE_FAILURE
@ NI_RETCODE_FAILURE
Definition: ni_defs.h:428
_ni_encoder_cfg_params::HDR10dx1
int HDR10dx1
Definition: ni_device_api.h:2276
_ni_encoder_cfg_params::planar
int planar
Definition: ni_device_api.h:2242
_ni_rational::den
int den
Definition: ni_device_api.h:601
_ni_frame::start_of_stream
uint32_t start_of_stream
Definition: ni_device_api.h:2609
NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_SMALL
Definition: ni_defs.h:500
_ni_frame::pts
long long pts
Definition: ni_device_api.h:2607
_ni_xcoder_params::enable_vfr
int enable_vfr
Definition: ni_device_api.h:2778
NI_CUSTOM_SEI_LOC_AFTER_VCL
@ NI_CUSTOM_SEI_LOC_AFTER_VCL
Definition: ni_device_api.h:1111
NI_RETCODE_PARAM_ERROR_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_TOO_SMALL
Definition: ni_defs.h:490
_ni_encoder_cfg_params::get_psnr_mode
int get_psnr_mode
Definition: ni_device_api.h:2430
ni_util.h
Utility definitions.
_ni_encoder_cfg_params::videoFullRange
int videoFullRange
Definition: ni_device_api.h:2290
_ni_quadra_enc_context::local_pts
int64_t local_pts
Definition: ni_quadra_enc_api.h:116
ni_device_session_hwdl
int ni_device_session_hwdl(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, niFrameSurface1_t *hwdesc)
Reads YUV data from hw descriptor stored location on device.
Definition: ni_device_api.c:8210
_ni_custom_sei_set::count
int count
Definition: ni_device_api.h:1128
NI_PIX_FMT_10_TILED4X4
@ NI_PIX_FMT_10_TILED4X4
Definition: ni_device_api.h:276
_ni_quadra_enc_context::retstatus
ni_quadra_retcode_t retstatus
Definition: ni_quadra_enc_api.h:181
_ni_session_context::enc_pts_list
int64_t enc_pts_list[NI_FIFO_SZ]
Definition: ni_device_api.h:1439
_ni_custom_sei_set::custom_sei
ni_custom_sei_t custom_sei[NI_MAX_CUSTOM_SEI_CNT]
Definition: ni_device_api.h:1127
_ni_encoder_cfg_params::lookAheadDepth
int lookAheadDepth
Definition: ni_device_api.h:2267
SESSION_RUN_STATE_SEQ_CHANGE_OPENING
@ SESSION_RUN_STATE_SEQ_CHANGE_OPENING
Definition: ni_device_api.h:1179
_ni_quadra_enc_context::first_frame_pts
int64_t first_frame_pts
Definition: ni_quadra_enc_api.h:152
NI_FRAME_AUX_DATA_CRF_FLOAT
@ NI_FRAME_AUX_DATA_CRF_FLOAT
Definition: ni_device_api.h:578
_ni_custom_gop_params::pic_param
ni_gop_params_t pic_param[NI_MAX_GOP_NUM]
Definition: ni_device_api.h:2053
_ni_quadra_enc_context::user_sar_den
int user_sar_den
Definition: ni_quadra_enc_api.h:134
_ni_quadra_enc_context::is_fifo_empty
int is_fifo_empty
Definition: ni_quadra_enc_api.h:167
NI_FRAME_AUX_DATA_CONTENT_LIGHT_LEVEL
@ NI_FRAME_AUX_DATA_CONTENT_LIGHT_LEVEL
Definition: ni_device_api.h:509
_ni_xcoder_params::low_delay_mode
int low_delay_mode
Definition: ni_device_api.h:2733
ni_device_session_flush
ni_retcode_t ni_device_session_flush(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Send a flush command to the device If device_type is NI_DEVICE_TYPE_DECODER sends EOS command to deco...
Definition: ni_device_api.c:1512
NI_RETCODE_PARAM_ERROR_ZERO
@ NI_RETCODE_PARAM_ERROR_ZERO
Definition: ni_defs.h:492
ni_mastering_display_metadata_t
struct _ni_mastering_display_metadata ni_mastering_display_metadata_t
_ni_session_context::pkt_num
uint64_t pkt_num
Definition: ni_device_api.h:1532
NI_CODEC_FORMAT_H264
@ NI_CODEC_FORMAT_H264
Definition: ni_device_api.h:911
ni_quadra_encode_session_open
int ni_quadra_encode_session_open(ni_quadra_enc_context_t *p_enc_ctx, int frame_width, int frame_height, const int *frame_linesize, niquadraFrameSurface1_t *p_surface, bool hw_frames_ctx, int frame_queqe, int avctx_flags)
Set encode session open and set niframe default info.
Definition: ni_quadra_enc_api.c:993
_ni_frame::use_cur_src_as_long_term_pic
uint8_t use_cur_src_as_long_term_pic
Definition: ni_device_api.h:2621
_ni_frame::start_buffer_size
uint32_t start_buffer_size
Definition: ni_device_api.h:2703
NI_RETCODE_PARAM_ERROR_OOR
@ NI_RETCODE_PARAM_ERROR_OOR
Definition: ni_defs.h:493
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2610
ni_should_send_sei_with_frame
int ni_should_send_sei_with_frame(ni_session_context_t *p_enc_ctx, ni_pic_type_t pic_type, ni_xcoder_params_t *p_param)
Whether SEI (HDR) should be sent together with this frame to encoder.
Definition: ni_av_codec.c:186
NI_FRAME_LITTLE_ENDIAN
#define NI_FRAME_LITTLE_ENDIAN
Definition: ni_device_api.h:108
_ni_xcoder_params::bitrate
int bitrate
Definition: ni_device_api.h:2729
_ni_encoder_cfg_params::HDR10wy
int HDR10wy
Definition: ni_device_api.h:2281
NI_MIN_WIDTH
#define NI_MIN_WIDTH
Definition: ni_device_api.h:124
_ni_session_context::sei_hdr_content_light_level_info_len
int sei_hdr_content_light_level_info_len
Definition: ni_device_api.h:1426
ni_device_session_context_init
ni_retcode_t ni_device_session_context_init(ni_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
Definition: ni_device_api.c:156
hdrp_data
uint8_t hdrp_data[NI_MAX_SEI_DATA]
Definition: ni_quadra_enc_api.c:1549
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1616
g_xcoder_preset_names
const char *const g_xcoder_preset_names[NI_XCODER_PRESET_NAMES_ARRAY_LEN]
Definition: ni_device_api.c:69
MAX_CHAR_IN_DEVICE_NAME
#define MAX_CHAR_IN_DEVICE_NAME
Definition: ni_device_api.h:184
_ni_aux_data
Definition: ni_device_api.h:618
_ni_session_context::pkt_custom_sei_set
ni_custom_sei_set_t * pkt_custom_sei_set[NI_FIFO_SZ]
Definition: ni_device_api.h:1456
NI_PIXEL_PLANAR_FORMAT_TILED4X4
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
Definition: ni_device_api.h:922
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:62
_ni_framerate
Definition: ni_device_api.h:695
_ni_quadra_enc_context::g_enc_change_params
void * g_enc_change_params
Definition: ni_quadra_enc_api.h:166
_ni_mastering_display_metadata::display_primaries
ni_rational_t display_primaries[3][2]
Definition: ni_av_codec.h:199
_ni_session_context::ori_bit_depth_factor
int ori_bit_depth_factor
Definition: ni_device_api.h:1562
_ni_session_context::ori_height
int ori_height
Definition: ni_device_api.h:1562
_ni_quadra_enc_context::spsPpsArrived
int spsPpsArrived
Definition: ni_quadra_enc_api.h:145
ni_device_session_close
ni_retcode_t ni_device_session_close(ni_session_context_t *p_ctx, int eos_recieved, ni_device_type_t device_type)
Close device session that was previously opened by calling ni_device_session_open() If device_type is...
Definition: ni_device_api.c:1379
NI_PIXEL_PLANAR_FORMAT_PLANAR
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
Definition: ni_device_api.h:921
_ni_packet::avg_frame_qp
uint32_t avg_frame_qp
Definition: ni_device_api.h:2843
_niquadraFrameSurface1::ui16FrameIdx
uint16_t ui16FrameIdx
Definition: ni_quadra_filter_api.h:387
_ni_pkt_info::psnr_v
double psnr_v
Definition: ni_device_api.h:1097
_ni_session_context::roi_avg_qp
uint32_t roi_avg_qp
Definition: ni_device_api.h:1497
_ni_quadra_enc_context::pkt_dts
int64_t pkt_dts
Definition: ni_quadra_enc_api.h:113
NI_MAX_RESOLUTION_AREA
#define NI_MAX_RESOLUTION_AREA
Definition: ni_device_api.h:102
_ni_session_context::p_master_display_meta_data
void * p_master_display_meta_data
Definition: ni_device_api.h:1432
_ni_encoder_cfg_params::forced_header_enable
int forced_header_enable
Definition: ni_device_api.h:2258
NI_FRAME_AUX_DATA_BITRATE
@ NI_FRAME_AUX_DATA_BITRATE
Definition: ni_device_api.h:535
NI_CODEC_FORMAT_H265
@ NI_CODEC_FORMAT_H265
Definition: ni_device_api.h:912
_ni_frame::use_long_term_ref
uint8_t use_long_term_ref
Definition: ni_device_api.h:2622
_ni_packet::data_len
uint32_t data_len
Definition: ni_device_api.h:2838
_ni_quadra_enc_context::tmp_blk_io_handle
int32_t tmp_blk_io_handle
Definition: ni_quadra_enc_api.h:85