libxcoder  5.2.0
ni_quadra_dec_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_dec_api.c
24  *
25  * \brief Private definitions used by ni_quadra_dec_api.c for video processing
26  * tasks
27  ******************************************************************************/
28 
29 #include "ni_defs.h"
30 #include "ni_rsrc_api.h"
31 #include "ni_util.h"
32 #include "ni_device_api.h"
33 #include "ni_av_codec.h"
34 #include "ni_bitstream.h"
35 #include "ni_quadra_dec_api.h"
36 
37 #define USER_DATA_UNREGISTERED_SEI_PAYLOAD_TYPE 5
38 #define NI_DEC_PKT_BUF_NUM_MAX 300
39 // copy maximum number of bytes of a string from src to dst, ensuring null byte
40 // terminated
41 static void ni_quadra_xcoder_strncpy(char *dst, const char *src, int max)
42 {
43  if (dst && src && max)
44  {
45  *dst = '\0';
46  strncpy(dst, src, max);
47  *(dst + max - 1) = '\0';
48  }
49 }
50 
51 void ni_quadra_align_free(void *opaque, uint8_t *data)
52 {
53  ni_buf_t *buf = (ni_buf_t *)opaque;
54  if (buf)
55  {
57  (ni_buf_pool_t *)buf->pool);
58  }
59 }
60 
61 void ni_quadra_frame_free(void *opaque, uint8_t *data)
62 {
63  int ret;
64  if (data)
65  {
66  niFrameSurface1_t *p_data3 =
67  (niFrameSurface1_t *)((uint8_t *)data);
68  if (p_data3->ui16FrameIdx != 0)
69  {
71  "Recycle trace ui16FrameIdx = [%d] DevHandle %d\n",
72  p_data3->ui16FrameIdx, p_data3->device_handle);
73  ret = ni_hwframe_buffer_recycle(p_data3, p_data3->device_handle);
74  if (ret != NI_RETCODE_SUCCESS)
75  {
77  "ERROR Failed to recycle trace ui16frameidx = [%d] "
78  "DevHandle %d\n",
79  p_data3->ui16FrameIdx, p_data3->device_handle);
80  }
81  }
82  ni_aligned_free(data);
83  (void)data; // suppress cppcheck
84  }
85 }
86 
88 {
89  ni_retcode_t ret;
90  ni_xcoder_params_t *p_param = ni_dec_ctx->api_param;
91  ni_session_context_t *p_session_ctx = ni_dec_ctx->api_ctx;
92  ni_session_data_io_t *p_ni_packet = NULL;
93  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
94  ni_session_data_io_t *p_session_data1 = ni_dec_ctx->p_session_data1;
95  ni_session_data_io_t *p_session_data2 = ni_dec_ctx->p_session_data2;
96 
97  if (p_session_ctx)
98  {
99  ret = ni_device_session_close(p_session_ctx, ni_dec_ctx->eos,
101  if (NI_RETCODE_SUCCESS != ret)
102  {
104  "Failed to close Decode Session (status = %d)\n", ret);
105  }
106  if (ni_cmp_fw_api_ver(
107  (char *) &p_session_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rg") >= 0)
108  {
109  ni_dec_ctx->ui32FramesCorrupted = p_session_ctx->session_statistic.ui32FramesCorrupted;
110  }
111 
112  ni_device_session_context_clear(p_session_ctx);
113 
114  if (ni_dec_ctx->suspended)
115  {
117  "File BLK handle %d close suspended to frames Uninit\n",
118  p_session_ctx->blk_io_handle); // suspended_device_handle
119 #ifdef __linux__
120  ni_device_close(p_session_ctx->device_handle);
121 #endif
122  } else
123  {
124 #ifdef _WIN32
125  ni_device_close(p_session_ctx->device_handle);
126 #elif __linux__
127  ni_device_close(p_session_ctx->device_handle);
128  ni_device_close(p_session_ctx->blk_io_handle);
129 #endif
130  }
131 
132  p_session_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
133  p_session_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
134  }
135  free(ni_dec_ctx->extradata);
136  ni_dec_ctx->extradata = NULL;
137  ni_dec_ctx->extradata_size = 0;
138  ni_dec_ctx->got_first_key_frame = 0;
139  if (ni_dec_ctx->input_data_fifo)
140  {
141  // push back
142  do
143  {
144  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_write(ni_dec_ctx->input_data_fifo);
145  } while (p_ni_packet);
146  // free all
147  do
148  {
149  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_read(ni_dec_ctx->input_data_fifo);
150  if (p_ni_packet)
151  {
152  ni_packet_buffer_free(&(p_ni_packet->data.packet));
153  }
154  } while (p_ni_packet);
155  }
156 
157  ni_fifo_free(ni_dec_ctx->input_data_fifo);
158  ni_log(NI_LOG_DEBUG, "%s(): decoder frame fifo freed.\n", __FUNCTION__);
159  if (p_session_ctx)
160  {
161  free(p_session_ctx);
162  }
163  if (p_param)
164  {
165  free(p_param);
166  }
167  if (p_ni_packet)
168  {
169  free(p_ni_packet);
170  }
171  if (p_session_data)
172  {
173  free(p_session_data);
174  }
175  if (p_session_data1)
176  {
177  free(p_session_data1);
178  }
179  if (p_session_data2)
180  {
181  free(p_session_data2);
182  }
183 }
184 
186 {
187  ni_xcoder_params_t *p_param = NULL;
188  ni_session_context_t *p_session_ctx = NULL;
189  ni_session_data_io_t *p_session_data = NULL;
190  ni_session_data_io_t *p_session_data1 = NULL;
191  ni_session_data_io_t *p_session_data2 = NULL;
192  int ret = NI_RETCODE_SUCCESS;
193  int min_resolution_width, min_resolution_height;
195  ni_log(NI_LOG_DEBUG, "XCoder setup device decoder\n");
196 
197  p_session_data = malloc(sizeof(ni_session_data_io_t));
198  if (!p_session_data)
199  {
201  "ERROR %d:%s() line %d, alloc p_session_data failed\n", NI_ERRNO,
202  __FUNCTION__, __LINE__);
204  goto end;
205  } else
206  {
207  ni_dec_ctx->p_session_data = p_session_data;
208  }
209  p_session_data1 = malloc(sizeof(ni_session_data_io_t));
210  if (!p_session_data1)
211  {
213  "ERROR %d:%s() line %d, alloc p_session_data failed\n", NI_ERRNO,
214  __FUNCTION__, __LINE__);
216  goto end;
217  } else
218  {
219  ni_dec_ctx->p_session_data1 = p_session_data1;
220  }
221  p_session_data2 = malloc(sizeof(ni_session_data_io_t));
222  if (!p_session_data2)
223  {
225  "ERROR %d:%s() line %d, alloc p_session_data failed\n", NI_ERRNO,
226  __FUNCTION__, __LINE__);
228  goto end;
229  } else
230  {
231  ni_dec_ctx->p_session_data2 = p_session_data2;
232  }
233  // Xcoder Session Context
234  p_session_ctx = malloc(sizeof(ni_session_context_t));
235  if (!p_session_ctx)
236  {
238  "ERROR %d:%s() line %d, alloc session context failed\n",
239  NI_ERRNO, __FUNCTION__, __LINE__);
241  goto end;
242  } else
243  {
244  ni_dec_ctx->api_ctx = p_session_ctx;
246  }
247  if (ni_device_session_context_init(p_session_ctx) < 0)
248  {
249  ni_log(NI_LOG_ERROR, "Error XCoder init decoder context failure\n");
250  ret = NI_RETCODE_FAILURE;
251  goto end;
252  }
253 
254  min_resolution_width = NI_MIN_RESOLUTION_WIDTH;
255  min_resolution_height = NI_MIN_RESOLUTION_HEIGHT;
256 
257  // Check codec id or format as well as profile idc.
258  p_session_ctx->codec_format = ni_dec_ctx->codec_format;
259  if (p_session_ctx->codec_format == NI_CODEC_FORMAT_JPEG)
260  {
261  min_resolution_width = NI_MIN_RESOLUTION_WIDTH_JPEG;
262  min_resolution_height = NI_MIN_RESOLUTION_HEIGHT_JPEG;
263  }
264 
265  if (ni_dec_ctx->width > NI_MAX_RESOLUTION_WIDTH ||
266  ni_dec_ctx->height > NI_MAX_RESOLUTION_HEIGHT ||
267  ni_dec_ctx->width * ni_dec_ctx->height > NI_MAX_RESOLUTION_AREA)
268  {
269  ni_log(NI_LOG_ERROR, "Error XCoder resolution %dx%d not supported\n",
270  ni_dec_ctx->width, ni_dec_ctx->height);
271  ni_log(NI_LOG_ERROR, "Max Supported Width: %d Height %d Area %d\n",
274  return NI_RETCODE_FAILURE;
275  } else if (ni_dec_ctx->width < min_resolution_width ||
276  ni_dec_ctx->height < min_resolution_height)
277  {
278  ni_log(NI_LOG_ERROR, "Error XCoder resolution %dx%d not supported\n",
279  ni_dec_ctx->width, ni_dec_ctx->height);
280  ni_log(NI_LOG_ERROR, "Min Supported Width: %d Height %d\n",
281  min_resolution_width, min_resolution_height);
282  return NI_RETCODE_FAILURE;
283  }
284 
285  ni_dec_ctx->offset = 0LL;
286 
287  ni_dec_ctx->draining = 0;
288 
289  p_session_ctx->pic_reorder_delay = ni_dec_ctx->has_b_frames;
290  p_session_ctx->bit_depth_factor = ni_dec_ctx->bit_depth_factor;
291 
292  ni_log(NI_LOG_TRACE, "%s pix_fmt %u bit_depth_factor %u\n", __FUNCTION__,
293  ni_dec_ctx->codec_format, p_session_ctx->bit_depth_factor);
294 
295  // Xcoder User Configuration
296  p_param = malloc(sizeof(ni_xcoder_params_t));
297  if (!p_param)
298  {
300  "ERROR %d:%s() line %d, alloc session context failed\n",
301  NI_ERRNO, __FUNCTION__, __LINE__);
303  goto end;
304  } else
305  {
306  ni_dec_ctx->api_param = p_param;
308  p_param, ni_dec_ctx->fps_num, ni_dec_ctx->fps_denom,
309  ni_dec_ctx->bit_rate, ni_dec_ctx->width,
310  ni_dec_ctx->height) < 0)
311  {
312  ni_log(NI_LOG_INFO, "Error setting params\n");
313 
314  ret = NI_RETCODE_FAILURE;
315  goto end;
316  }
317  }
318 
319  // Init input fifo
320  ni_dec_ctx->input_data_fifo = ni_fifo_initialize(
322  if (!ni_dec_ctx->input_data_fifo)
323  {
325  "%s(): line %d initialize enc frame buffer pool failed\n",
326  __FUNCTION__, __LINE__);
328  LRETURN;
329  }
330  ni_log(NI_LOG_DEBUG, "xcoder_setup success\n");
331 end:
332  if (ret != NI_RETCODE_SUCCESS)
333  {
334  free(p_session_ctx);
335  ni_dec_ctx->api_ctx = NULL;
336  free(p_param);
337  ni_dec_ctx->api_param = NULL;
338  ni_fifo_free(ni_dec_ctx->input_data_fifo);
339  free(p_session_data);
340  ni_dec_ctx->p_session_data = NULL;
341  free(p_session_data1);
342  ni_dec_ctx->p_session_data1 = NULL;
343  free(p_session_data2);
344  ni_dec_ctx->p_session_data2 = NULL;
345  }
346 
347  return 0;
348 }
349 
351 {
352  int ret;
353  ni_xcoder_params_t *p_param = NULL;
354  ni_session_context_t *p_session_ctx = NULL;
355 
356  if (!ni_dec_ctx)
357  {
358  ni_log(NI_LOG_ERROR, "ni_dec_ctx is null\n");
360  }
361  p_param = ni_dec_ctx->api_param;
362  p_session_ctx = ni_dec_ctx->api_ctx;
363  if (!p_param || !p_session_ctx)
364  {
365  ni_log(NI_LOG_ERROR, "%s(): line %d, Invalid Parameter, %p, %p\n",
366  __FUNCTION__, __LINE__, p_param, p_session_ctx);
368  }
369  // overwrite keep alive timeout value here with a custom value if it was
370  // provided
371  // if xcoder option is set then overwrite the (legacy) decoder option
372  uint32_t xcoder_timeout = p_param->dec_input_params.keep_alive_timeout;
373  if (xcoder_timeout != NI_DEFAULT_KEEP_ALIVE_TIMEOUT)
374  {
375  p_session_ctx->keep_alive_timeout = xcoder_timeout;
376  } else
377  {
378  p_session_ctx->keep_alive_timeout = ni_dec_ctx->keep_alive_timeout;
379  }
380  ni_log(NI_LOG_DEBUG, "Custom NVME Keep Alive Timeout set to %d\n",
381  p_session_ctx->keep_alive_timeout);
382 
383  if (p_param->dec_input_params.decoder_low_delay != 0)
384  {
385  ni_dec_ctx->low_delay = p_param->dec_input_params.decoder_low_delay;
386  } else
387  {
388  p_param->dec_input_params.decoder_low_delay = ni_dec_ctx->low_delay;
389  }
390  p_session_ctx->force_low_delay = p_param->dec_input_params.force_low_delay;
391  p_session_ctx->enable_low_delay_check =
392  ni_dec_ctx->enable_low_delay_check =
395 
396  if (ni_dec_ctx->has_b_frames && ni_dec_ctx->enable_low_delay_check)
397  {
398  // If has B frame, must set lowdelay to 0
399  ni_log(NI_LOG_ERROR,"Warning: decoder lowDelay mode "
400  "is cancelled due to has_b_frames with enable_low_delay_check\n");
401  ni_dec_ctx->low_delay = p_param->dec_input_params.decoder_low_delay = 0;
402  }
403  p_session_ctx->decoder_low_delay = ni_dec_ctx->low_delay;
404 
405  if (p_param->dec_input_params.hwframes)
406  { // need to set before open decoder
407  p_session_ctx->hw_action = NI_CODEC_HW_ENABLE;
408  ni_dec_ctx->hwframes = 1;
409  } else
410  {
411  p_session_ctx->hw_action = NI_CODEC_HW_NONE;
412  }
413  p_session_ctx->bit_depth_factor = ni_dec_ctx->bit_depth_factor;
414 
415  if (ni_dec_ctx->custom_sei_type ==
419  {
420  // use SW passthru only
421  p_session_ctx->enable_user_data_sei_passthru = 0;
422  } else
423  {
424  p_session_ctx->enable_user_data_sei_passthru =
425  ni_dec_ctx->enable_user_data_sei_passthru;
426  }
427 
429  "api_ctx %p api_ctx/s: user_data_sei_passthru = %d/%d, custom_sei = "
430  "%d\n",
431  p_session_ctx, p_session_ctx->enable_user_data_sei_passthru,
432  ni_dec_ctx->enable_user_data_sei_passthru,
433  ni_dec_ctx->custom_sei_type);
434 
435  ni_dec_ctx->started = 0;
436  ni_dec_ctx->extradata = NULL;
437  ni_dec_ctx->extradata_size = 0;
438  ni_dec_ctx->pkt_nal_bitmap = 0;
439  ni_dec_ctx->svct_skip_next_packet = 0;
440 
441  ni_dec_ctx->eos_pkt_received = 0;
442  ni_dec_ctx->dec_wait = NI_POLL_INTERVAL;
443 
444  ni_dec_ctx->pkt_duration = 0;
445  ni_dec_ctx->ui32FramesCorrupted = 0;
446 
447  p_session_ctx->p_session_config = p_param;
448 
449  p_session_ctx->hw_id = ni_dec_ctx->dev_dec_idx;
450  p_session_ctx->decoder_low_delay = 0;
451  ni_quadra_xcoder_strncpy(p_session_ctx->blk_dev_name,
452  ni_dec_ctx->dev_blk_name,
454  ni_quadra_xcoder_strncpy(p_session_ctx->dev_xcoder_name,
455  ni_dec_ctx->dev_xcoder,
457 
458  ret = ni_device_session_open(p_session_ctx, NI_DEVICE_TYPE_DECODER);
459  if (ret != 0)
460  {
462  "Failed to open decoder (status = %d), "
463  "resource unavailable\n",
464  ret);
465  ret = NI_RETCODE_FAILURE;
466  } else
467  {
468  ni_dec_ctx->dev_xcoder_name = p_session_ctx->dev_xcoder_name;
469  ni_dec_ctx->blk_xcoder_name = p_session_ctx->blk_xcoder_name;
470  ni_dec_ctx->dev_dec_idx = p_session_ctx->hw_id;
472  "XCoder %s Index %d (inst: %d) opened successfully\n",
473  ni_dec_ctx->dev_xcoder_name, ni_dec_ctx->dev_dec_idx,
474  p_session_ctx->session_id);
475 
476  if (p_param->dec_input_params.hwframes)
477  {
478  ni_dec_ctx->hwframes = 1;
479  p_session_ctx->hw_action = NI_CODEC_HW_ENABLE;
480  } else
481  {
482  // reassign in case above conditions alter value
483  p_session_ctx->hw_action = NI_CODEC_HW_NONE;
484  }
485  }
486 
487  ni_dec_ctx->current_pts = 0;
489  return ret;
490 }
491 
492 // reset and restart when xcoder decoder resets
494 {
495  ni_session_context_t *p_session_ctx = ni_dec_ctx->api_ctx;
496  ni_session_data_io_t *p_ni_packet = NULL;
498  ni_log(NI_LOG_DEBUG, "XCoder decode reset\n");
499 
500  int ori_run_state = p_session_ctx->session_run_state;
501  ni_device_session_close(p_session_ctx, ni_dec_ctx->eos,
503 
504  ni_device_session_context_clear(p_session_ctx);
505 
506 #ifdef _WIN32
507  ni_device_close(p_session_ctx->device_handle);
508 #elif __linux__
509  ni_device_close(p_session_ctx->device_handle);
510  ni_device_close(p_session_ctx->blk_io_handle);
511 #endif
512  p_session_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
513  p_session_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
514  if (ni_dec_ctx->input_data_fifo)
515  {
516  // push back
517  do
518  {
519  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_write(ni_dec_ctx->input_data_fifo);
520  } while (p_ni_packet);
521  // free all
522  do
523  {
524  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_read(ni_dec_ctx->input_data_fifo);
525  if (p_ni_packet)
526  {
527  ni_packet_buffer_free(&(p_ni_packet->data.packet));
528  }
529  } while (p_ni_packet);
530  }
531  ni_fifo_free(ni_dec_ctx->input_data_fifo);
532  ni_log(NI_LOG_DEBUG, "%s(): decoder frame fifo freed.\n", __FUNCTION__);
533 
534  int64_t bcp_current_pts = ni_dec_ctx->current_pts;
535  ret = ni_quadra_dec_init(ni_dec_ctx);
536  ni_dec_ctx->current_pts = bcp_current_pts;
537  // p_session_ctx->session_run_state = ori_run_state;
538  p_session_ctx->session_run_state = ori_run_state;
539 
540  return ret;
541 }
542 
543 // return 1 if need to prepend saved header to pkt data, 0 otherwise
544 int ni_quadra_add_headers(ni_quadra_dec_context_t *ni_dec_ctx, int pkt_flag,
545  const uint8_t *data, int size, uint8_t *extradata,
546  int extradata_size)
547 {
548  int ret = 0;
549  int vps_num, sps_num, pps_num;
550 
551  // check key frame packet only
552  if (!(pkt_flag & NI_PKT_FLAG_KEY) || !data || !extradata || !extradata_size)
553  {
554  return ret;
555  }
556 
557  if (ni_dec_ctx->extradata_size == extradata_size &&
558  memcmp(ni_dec_ctx->extradata, extradata, extradata_size) == 0)
559  {
560  ni_log(NI_LOG_TRACE, "%s extradata unchanged.\n", __FUNCTION__);
561  return ret;
562  }
563 
564  if (NI_CODEC_FORMAT_H264 != ni_dec_ctx->codec_format &&
565  NI_CODEC_FORMAT_H265 != ni_dec_ctx->codec_format)
566  {
567  ni_log(NI_LOG_TRACE, "%s not AVC/HEVC codec: %d, skip!\n",
568  __FUNCTION__, ni_dec_ctx->codec_format);
569  return ret;
570  }
571 
572  // extradata (headers) non-existing or changed: save/update it in the
573  // session storage
574  free(ni_dec_ctx->extradata);
575  ni_dec_ctx->extradata_size = 0;
576  ni_dec_ctx->got_first_key_frame = 0;
577  ni_dec_ctx->extradata = malloc(extradata_size);
578  if (!ni_dec_ctx->extradata)
579  {
580  ni_log(NI_LOG_ERROR, "%s memory allocation failed !\n", __FUNCTION__);
581  return ret;
582  }
583 
584  memcpy(ni_dec_ctx->extradata, extradata, extradata_size);
585  ni_dec_ctx->extradata_size = extradata_size;
586  // prepend header by default (assuming no header found in the pkt itself)
587  ret = 1;
588  // and we've got the first key frame of this stream
589  ni_dec_ctx->got_first_key_frame = 1;
590  vps_num = sps_num = pps_num = 0;
591 
592  if (ni_dec_ctx->skip_extra_headers &&
593  (ni_dec_ctx->extradata_size > 0) &&
594  ni_dec_ctx->extradata)
595  {
596  const uint8_t *ptr = ni_dec_ctx->extradata;
597  const uint8_t *end = ni_dec_ctx->extradata + ni_dec_ctx->extradata_size;
598  uint32_t stc;
599  int nalu_type;
600  while (ptr < end)
601  {
602  stc = -1;
603  ptr = ni_find_start_code(ptr, end, &stc);
604  if (ptr == end)
605  {
606  break;
607  }
608 
609  if (NI_CODEC_FORMAT_H264 == ni_dec_ctx->codec_format)
610  {
611  nalu_type = (int)stc & 0x1f;
612 
613  if (7 /*H264_NAL_SPS */ == nalu_type)
614  {
615  sps_num++;
616  } else if(8 /*H264_NAL_PPS */ == nalu_type)
617  {
618  pps_num++;
619  }
620 #define H264_MAX_SPS_COUNT 32
621 #define H264_MAX_PPS_COUNT 256
622  if (sps_num > H264_MAX_SPS_COUNT ||
623  pps_num > H264_MAX_PPS_COUNT)
624  {
625  ret = 0;
626  ni_log(NI_LOG_DEBUG, "Drop extradata because of repeated SPS/PPS\n");
627  break;
628  }
629  } else if (NI_CODEC_FORMAT_H265 == ni_dec_ctx->codec_format)
630  {
631  nalu_type = (int)(stc >> 1) & 0x3F;
632 
633  if (32 /* HEVC_NAL_VPS */ == nalu_type)
634  {
635  vps_num++;
636  } else if (33 /* HEVC_NAL_SPS */ == nalu_type)
637  {
638  sps_num++;
639  } else if(34 /* HEVC_NAL_PPS */ == nalu_type)
640  {
641  pps_num++;
642  }
643 
644 #define HEVC_MAX_VPS_COUNT 16
645 #define HEVC_MAX_SPS_COUNT 16
646 #define HEVC_MAX_PPS_COUNT 64
647  if (vps_num > HEVC_MAX_VPS_COUNT ||
648  sps_num > HEVC_MAX_SPS_COUNT ||
649  pps_num > HEVC_MAX_PPS_COUNT) {
650  ret = 0;
651  ni_log(NI_LOG_DEBUG, "Drop extradata because of repeated VPS/SPS/PPS\n");
652  break;
653  }
654 
655  }
656  }
657  }
658 
659  return ret;
660 }
661 
662 int ni_quadra_dec_send(ni_quadra_dec_context_t *ni_dec_ctx, int pkt_flags,
663  uint8_t *data, int pkt_size,
664  uint8_t *lonedata, int lone_size, int64_t pkt_pts,
665  int64_t pkt_dts, int pkt_pos, int width, int height,
666  uint8_t *extradata, int extradata_size)
667 {
668  /* call xcoder_dec_send to send compressed video packet to the decoder
669  instance */
670  ni_session_context_t *p_session_ctx = ni_dec_ctx->api_ctx;
671  ni_session_data_io_t *p_ni_packet = NULL;
672  int need_draining = 0;
673  size_t size;
674  ni_packet_t *xpkt = NULL;
675  int ret;
676  int sent;
677  int send_size = 0;
678  int new_packet = 0;
679  int extra_prev_size = 0;
680  int svct_skip_packet = ni_dec_ctx->svct_skip_next_packet;
681 
682  size = pkt_size;
683 
684  if (ni_dec_ctx->flushing)
685  {
687  "Decoder is flushing and cannot accept new "
688  "buffer until all output buffers have been released\n");
689  return NI_RETCODE_FAILURE;
690  }
691 
692  if (pkt_size == 0)
693  {
694  need_draining = 1;
695  // Once VPU reset, the s->draining would be recovered during session reset.
696  // And so is the s->eos in case that it lost in the last session read.
697  ni_dec_ctx->eos |= (ni_dec_ctx->draining && ni_dec_ctx->vpu_reset);
698  }
699 
700  if (ni_dec_ctx->draining && ni_dec_ctx->eos)
701  {
702  ni_log(NI_LOG_DEBUG, "Decoder is draining, eos\n");
703  return NI_RETCODE_FAILURE;
704  }
705  if (!ni_dec_ctx->eos_pkt_received)
706  {
707  if (ni_fifo_is_full(ni_dec_ctx->input_data_fifo))
708  {
709  ni_log(NI_LOG_ERROR, "fifo full,need lost 1 frame....\n");
710  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_read(ni_dec_ctx->input_data_fifo);
711  ni_packet_buffer_free(&(p_ni_packet->data.packet));
712  }
713  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_write(ni_dec_ctx->input_data_fifo);
714  xpkt = &p_ni_packet->data.packet;
715  {
716  memset(xpkt, 0, sizeof(ni_packet_t));
717  xpkt->pts = pkt_pts;
718  xpkt->dts = pkt_dts;
719  xpkt->flags = pkt_flags;
720  // pkt->pos does not accurately reflect the position of the current pkt
721  // in the bitstream; instead we track the size of data sent to decoder
722  // and use that to track the returned decoded frame and its pts.
723  // xpkt->pos = pkt->pos;
724  xpkt->video_width = width;
725  xpkt->video_height = height;
726  xpkt->p_data = NULL;
727  xpkt->data_len = pkt_size;
728  xpkt->pkt_pos = pkt_pos;
729 
730  if (pkt_flags & NI_PKT_FLAG_KEY && extradata_size > 0 &&
731  ni_quadra_add_headers(ni_dec_ctx, pkt_flags, data, pkt_size,
732  extradata, extradata_size))
733  {
734  if (extradata_size > p_session_ctx->max_nvme_io_size * 2)
735  {
737  "ff_xcoder_dec_send extradata_size %d "
738  "exceeding max size supported: %d\n",
739  extradata_size, p_session_ctx->max_nvme_io_size * 2);
740  } else
741  {
743  "ff_xcoder_dec_send extradata_size %d "
744  "copied to pkt start.\n",
745  ni_dec_ctx->extradata_size);
746 
747  p_session_ctx->prev_size = ni_dec_ctx->extradata_size;
748  memcpy(p_session_ctx->p_leftover, ni_dec_ctx->extradata,
749  ni_dec_ctx->extradata_size);
750  }
751  }
752 
753  ni_dec_ctx->svct_skip_next_packet = 0;
754  // If there was lone custom sei in the last packet and the firmware would
755  // fail to recognize it. So passthrough the custom sei here.
756  if (lone_size > 0)
757  {
758  // No need to check the return value here because the lone_sei_pkt was
759  // parsed before. Here it is only to extract the SEI data.
760  ni_dec_packet_parse(ni_dec_ctx->api_ctx, ni_dec_ctx->api_param,lonedata,lone_size,xpkt,
761  ni_dec_ctx->low_delay,ni_dec_ctx->codec_format,ni_dec_ctx->pkt_nal_bitmap,
762  ni_dec_ctx->custom_sei_type,&ni_dec_ctx->svct_skip_next_packet,
763  &ni_dec_ctx->is_lone_sei_pkt);
764  }
765 
766  ret = ni_dec_packet_parse(ni_dec_ctx->api_ctx, ni_dec_ctx->api_param,data, size, xpkt,
767  ni_dec_ctx->low_delay, ni_dec_ctx->codec_format, ni_dec_ctx->pkt_nal_bitmap,
768  ni_dec_ctx->custom_sei_type, &ni_dec_ctx->svct_skip_next_packet,
769  &ni_dec_ctx->is_lone_sei_pkt);
770  if (ret != 0)
771  {
772  goto fail;
773  }
774 
775  if (svct_skip_packet)
776  {
778  "ff_xcoder_dec_send packet: pts:%" PRIi64 ","
779  " size:%d\n",
780  pkt_pts, pkt_size);
781  xpkt->data_len = 0;
782  return pkt_size;
783  }
784  // If the current packet is a lone SEI, save it to be sent with the next
785  // packet. And also check if getting the first packet containing key frame
786  // in decoder low delay mode.
787  if (ni_dec_ctx->is_lone_sei_pkt)
788  {
789  // av_packet_ref(&s->lone_sei_pkt, pkt);
790  xpkt->data_len = 0;
791  free(xpkt->p_custom_sei_set);
792  xpkt->p_custom_sei_set = NULL;
793  if (ni_dec_ctx->low_delay && ni_dec_ctx->got_first_key_frame &&
794  !(ni_dec_ctx->pkt_nal_bitmap &
796  {
797  // Packets before the IDR is sent cannot be decoded. So
798  // set packet num to zero here.
799  p_session_ctx->decoder_low_delay = ni_dec_ctx->low_delay;
800  p_session_ctx->pkt_num = 0;
801  ni_dec_ctx->pkt_nal_bitmap |=
804  "%s got first IDR in decoder low delay mode, "
805  "delay time %dms, pkt_nal_bitmap %d\n",
806  __FUNCTION__, ni_dec_ctx->low_delay,
807  ni_dec_ctx->pkt_nal_bitmap);
808  }
809  ni_log(NI_LOG_TRACE, "%s pkt lone SEI, saved, and return %d\n",
810  __FUNCTION__, pkt_size);
811  return pkt_size;
812  }
813  // embed lone SEI saved previously (if any) to send to decoder
814  if (lone_size > 0)
815  {
816  ni_log(NI_LOG_TRACE, "%s copy over lone SEI data size: %d\n",
817  __FUNCTION__, lone_size);
818 
819  memcpy(p_session_ctx->p_leftover + p_session_ctx->prev_size,
820  lonedata, lone_size);
821  p_session_ctx->prev_size += lone_size;
822  // av_packet_unref(&s->lone_sei_pkt);
823  }
824 
825  if (ni_dec_ctx->ppu_reconfig)
826  {
827  ni_ppu_config_t ppu_config = {0};
828 
829  for (int idx = 0; idx < NI_MAX_NUM_OF_DECODER_OUTPUTS; idx ++)
830  {
831  if (ni_dec_ctx->ni_quadra_ppu_config.out_enabled[idx] == 1)
832  {
833  ppu_config.ppu_set_enable += (0x1 << idx);
834  ppu_config.ppu_w[idx] =
835  ni_dec_ctx->ni_quadra_ppu_config.ppu_w[idx];
836  ppu_config.ppu_h[idx] =
837  ni_dec_ctx->ni_quadra_ppu_config.ppu_h[idx];
838  }
839  }
840  ret = ni_reconfig_ppu_output(p_session_ctx,
841  (ni_xcoder_params_t *)ni_dec_ctx->api_param, &ppu_config);
842  if (ret < 0)
843  {
844  ni_log(NI_LOG_ERROR, "ni_reconfig_ppu_output failed, ret = %d\n", ret);
845  goto fail;
846  }
847  }
848 
849  if ((pkt_size + p_session_ctx->prev_size) > 0)
850  {
852  (pkt_size + p_session_ctx->prev_size));
853  if (!xpkt->p_data)
854  {
856  goto fail;
857  }
858  }
859  new_packet = 1;
860  }
861 
862  ni_log(NI_LOG_DEBUG, "ni_quadra_dec_send: pkt size=%d dts=%lld\n",
863  pkt_size, pkt_dts);
864  if (ni_dec_ctx->started == 0)
865  {
866  xpkt->start_of_stream = 1;
867  ni_dec_ctx->started = 1;
868  }
869 
871  "ni_packet_copy before: size=%d, s->prev_size=%d, send_size=%d, "
872  "(end of stream)\n",
873  pkt_size, p_session_ctx->prev_size, send_size);
874  if (new_packet)
875  {
876  extra_prev_size = p_session_ctx->prev_size;
877  send_size = ni_packet_copy(xpkt->p_data, data, pkt_size,
878  p_session_ctx->p_leftover,
879  &p_session_ctx->prev_size);
880  // increment offset of data sent to decoder and save it
881  xpkt->pos = (long long)ni_dec_ctx->offset;
882  ni_dec_ctx->offset += pkt_size + extra_prev_size;
883  }
885  "ni_packet_copy after: size=%d, s->prev_size=%d, send_size=%d, "
886  "xpkt->data_len=%d (end of stream)\n",
887  pkt_size, p_session_ctx->prev_size, send_size, xpkt->data_len);
888  if (send_size < 0)
889  {
890  ni_log(NI_LOG_ERROR, "Failed to copy pkt (status = %d)\n",
891  send_size);
892  ret = NI_RETCODE_FAILURE;
893  goto fail;
894  }
895 
896  xpkt->data_len += extra_prev_size;
897 
898  if (need_draining && !ni_dec_ctx->draining)
899  {
900  ni_log(NI_LOG_DEBUG, "Sending End Of Stream signal\n");
901  xpkt->end_of_stream = 1;
902  xpkt->data_len = 0;
903  ni_dec_ctx->eos_pkt_received = 1;
904  }
905  }
906  if (ni_dec_ctx->eos_pkt_received && !ni_dec_ctx->draining)
907  {
908  sent = 1;
909  while (!ni_fifo_is_empty(ni_dec_ctx->input_data_fifo))
910  {
911  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_read(ni_dec_ctx->input_data_fifo);
912  ni_log(NI_LOG_TRACE, "%s pts=%" PRIi64 ", dts=%" PRIi64 "\n",
913  __FUNCTION__, p_ni_packet->data.packet.pts,
914  p_ni_packet->data.packet.dts);
915 
916  sent = ni_device_session_write(p_session_ctx,
917  p_ni_packet,
919 
920  if (sent == 0 && !ni_fifo_is_empty(ni_dec_ctx->input_data_fifo))
921  {
923  "dec_send EAGAIN this better not happen "
924  "sleep %d us !\n",
925  ni_dec_ctx->dec_wait);
926  usleep(ni_dec_ctx->dec_wait);
927  ni_dec_ctx->dec_wait += NI_POLL_INTERVAL;
929  break;
930  } else if (sent < 0)
931  {
933  "Failed to send eos signal (status = %d)\n", sent);
934  if (NI_RETCODE_ERROR_VPU_RECOVERY == sent)
935  {
936  ni_log(NI_LOG_INFO, "%s VPU recovery, need to reset\n",
937  __FUNCTION__);
938  p_session_ctx->session_run_state =
940  if (ni_quadra_dec_reset(ni_dec_ctx) < 0)
941  {
942  return NI_RETCODE_FAILURE;
943  }
944  return 0;
945  }
946  ret = NI_RETCODE_FAILURE;
947  goto fail;
948  } else
949  {
950  ni_packet_buffer_free(&(p_ni_packet->data.packet));
951  if ((p_ni_packet->data.packet).data_len == 0)
952  {
953  free((p_ni_packet->data.packet).p_custom_sei_set);
954  (p_ni_packet->data.packet).p_custom_sei_set = NULL;
955  }
956  // wait time is incremental, and reset after a successful send
957  ni_dec_ctx->dec_wait = NI_POLL_INTERVAL;
958  }
959  }
960  if (ni_fifo_is_empty(ni_dec_ctx->input_data_fifo))
961  {
963  ni_dec_ctx->draining = 1;
965  ni_dec_ctx->eos_pkt_received = 0;
966  }
967  } else
968  {
969  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_read(ni_dec_ctx->input_data_fifo);
970  ni_log(NI_LOG_DEBUG, "%s pts=%" PRIi64 ", dts=%" PRIi64 " \n",
971  __FUNCTION__, p_ni_packet->data.packet.pts,
972  p_ni_packet->data.packet.dts);
973 
975  p_session_ctx, p_ni_packet, NI_DEVICE_TYPE_DECODER);
976  if (sent < 0)
977  {
978  ni_log(NI_LOG_ERROR, "Failed to send compressed pkt (status=%d)\n",
979  sent);
980  if (NI_RETCODE_ERROR_VPU_RECOVERY == sent)
981  {
982  ni_log(NI_LOG_INFO, "%s VPU recovery, need to reset\n",
983  __FUNCTION__);
985  if (ni_quadra_dec_reset(ni_dec_ctx) < 0)
986  {
987  return NI_RETCODE_FAILURE;
988  }
989  return 0;
990  }
991  ret = NI_RETCODE_FAILURE;
992  goto fail;
993  } else if (sent == 0)
994  {
996  sent = size;
997  } else
998  {
999  if (p_session_ctx->session_run_state == SESSION_RUN_STATE_RESETTING)
1000  {
1002  }
1003  ni_packet_buffer_free(&(p_ni_packet->data.packet));
1004  if ((p_ni_packet->data.packet).data_len == 0)
1005  {
1006  free((p_ni_packet->data.packet).p_custom_sei_set);
1007  (p_ni_packet->data.packet).p_custom_sei_set = NULL;
1008  }
1009  }
1010  }
1011  return sent;
1012 
1013 fail:
1014  ni_packet_buffer_free(xpkt);
1015  if (xpkt)
1016  {
1017  free(xpkt->p_custom_sei_set);
1018  xpkt->p_custom_sei_set = NULL;
1019  }
1020  ni_dec_ctx->draining = 1;
1021  ni_dec_ctx->eos = 1;
1022 
1023  return ret;
1024 }
1025 
1027 {
1028  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
1029  ni_frame_t *nifme = &p_session_data->data.frame;
1030  ni_dec_retrieve_aux_data(nifme);
1031 }
1032 
1034 {
1035  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
1036  ni_frame_t *nifme = &p_session_data->data.frame;
1037  ni_frame_wipe_aux_data(nifme);
1038 }
1039 
1041 {
1042  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
1043  ni_frame_t *nifme = &p_session_data->data.frame;
1044  ni_aux_data_t *aux = NULL;
1045  aux = ni_frame_get_aux_data(nifme, type);
1046  if (aux)
1047  return aux->size;
1048  return 0;
1049 }
1050 
1052  uint8_t *dst_data, int type, int size)
1053 {
1054  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
1055  ni_frame_t *nifme = &p_session_data->data.frame;
1056  ni_aux_data_t *aux = NULL;
1057  aux = ni_frame_get_aux_data(nifme, type);
1058  memcpy(dst_data, aux->data, size);
1059 }
1060 
1062 {
1063  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
1064  ni_frame_t *xfme = &p_session_data->data.frame;
1066  "Got output buffer pts=%lld "
1067  "dts=%lld eos=%d sos=%d\n",
1068  p_session_data->data.frame.pts, p_session_data->data.frame.dts,
1069  p_session_data->data.frame.end_of_stream,
1070  p_session_data->data.frame.start_of_stream);
1071 
1072  ni_dec_ctx->eos = xfme->end_of_stream;
1073  ni_dec_ctx->niframe.pts = xfme->pts;
1074  ni_dec_ctx->niframe.dts = xfme->dts;
1075  ni_dec_ctx->niframe.end_of_stream = xfme->end_of_stream;
1076  ni_dec_ctx->niframe.start_of_stream = xfme->start_of_stream;
1077  ni_dec_ctx->niframe.video_width = xfme->video_width;
1078  ni_dec_ctx->niframe.video_height = xfme->video_height;
1079  ni_dec_ctx->niframe.pkt_pos = xfme->pkt_pos;
1080  ni_dec_ctx->niframe.p_data[0] = xfme->p_data[0];
1081  ni_dec_ctx->niframe.data_len[0] = xfme->data_len[0];
1082  ni_dec_ctx->niframe.data_len[1] = xfme->data_len[1];
1083  ni_dec_ctx->niframe.data_len[2] = xfme->data_len[2];
1084  ni_dec_ctx->niframe.data_len[3] = xfme->data_len[3];
1085  ni_dec_ctx->niframe.ni_pict_type = xfme->ni_pict_type;
1086  ni_dec_ctx->niframe.vui_time_scale = xfme->vui_time_scale;
1088  ni_dec_ctx->niframe.sei_user_data_unreg_offset =
1099  ni_dec_ctx->niframe.sei_cc_offset = xfme->sei_cc_offset;
1100  ni_dec_ctx->niframe.sei_cc_len = xfme->sei_cc_len;
1101  ni_dec_ctx->niframe.p_custom_sei_set = xfme->p_custom_sei_set;
1102  ni_dec_ctx->niframe.p_buffer = xfme->p_buffer;
1103  ni_dec_ctx->niframe.crop_left = xfme->crop_left;
1104  ni_dec_ctx->niframe.crop_right = xfme->crop_right;
1105  ni_dec_ctx->niframe.crop_top = xfme->crop_top;
1106  ni_dec_ctx->niframe.crop_bottom = xfme->crop_bottom;
1107  ni_dec_ctx->niframe.dec_buf = xfme->dec_buf;
1108  ni_dec_ctx->niframe.color_primaries = xfme->color_primaries;
1109  ni_dec_ctx->niframe.color_trc = xfme->color_trc;
1110  ni_dec_ctx->niframe.color_space = xfme->color_space;
1112  ni_dec_ctx->niframe.vui_len = xfme->vui_len;
1113  ni_dec_ctx->niframe.orignal_pts = xfme->orignal_pts;
1114  ni_dec_ctx->niframe.error_ratio = xfme->error_ratio;
1115 }
1116 
1117 int ni_quadra_dec_receive(ni_quadra_dec_context_t *ni_dec_ctx, int avctx_width,
1118  int avctx_height, int frame_planar)
1119 {
1120  int ret;
1121  int retry_cnt = 0;
1122  int retry_read_cnt = 0;
1123  int fifo_flush_cnt = 0;
1124  uint64_t t0 = 0;
1125  int height, actual_width, alloc_mem;
1126  ni_xcoder_params_t *p_param = ni_dec_ctx->api_param;
1127  ni_session_context_t *p_session_ctx = ni_dec_ctx->api_ctx;
1128  ni_session_data_io_t *p_session_data = ni_dec_ctx->p_session_data;
1129  ni_dec_ctx->bSequenceChange = 0;
1130  ni_dec_ctx->pkt_pts_unchange = p_param->dec_input_params.pkt_pts_unchange;
1131  memset(p_session_data, 0, sizeof(ni_session_data_io_t));
1132  if (p_session_ctx->frame_num % 2 == 0)
1133  {
1134  p_session_ctx->burst_control =
1135  (p_session_ctx->burst_control == 0 ? 1 : 0); // toggle
1136  }
1137  if (p_session_ctx->burst_control)
1138  {
1140  "ff_xcoder_dec_receive burst return%" PRId64 " frame\n",
1141  p_session_ctx->frame_num);
1142  return 0;
1143  }
1144  t0 = ni_gettime_ns();
1145 
1146 to_malloc:
1147  // if active video resolution has been obtained we just use it as it's the
1148  // exact size of frame to be returned, otherwise we use what we are told by
1149  // upper stream as the initial setting and it will be adjusted.
1150  height = (int)(p_session_ctx->active_video_height > 0 ?
1151  p_session_ctx->active_video_height :
1152  avctx_height);
1153  actual_width = (int)(p_session_ctx->actual_video_width > 0 ?
1154  p_session_ctx->actual_video_width :
1155  avctx_width);
1156  // allocate memory only after resolution is known (buffer pool set up)
1157  alloc_mem = (p_session_ctx->active_video_width > 0 &&
1158  p_session_ctx->active_video_height > 0 ?
1159  1 :
1160  0);
1161 
1162  if (ni_dec_ctx->hwframes != 1)
1163  {
1165  p_session_ctx->dec_fme_buf_pool, &(p_session_data->data.frame),
1166  alloc_mem, actual_width, height,
1167  (ni_dec_ctx->codec_format == NI_CODEC_FORMAT_H264),
1168  p_session_ctx->bit_depth_factor, frame_planar);
1169  } else
1170  {
1171  ret = ni_frame_buffer_alloc(
1172  &(p_session_data->data.frame), actual_width, height,
1173  (ni_dec_ctx->codec_format == NI_CODEC_FORMAT_H264), 1,
1174  p_session_ctx->bit_depth_factor, 3, frame_planar);
1175  }
1176  if (NI_RETCODE_SUCCESS != ret)
1177  {
1178  return NI_RETCODE_FAILURE;
1179  }
1180 
1181 to_read:
1182  if (ni_dec_ctx->hwframes != 1)
1183  {
1184  ret = ni_device_session_read(p_session_ctx, p_session_data,
1186  } else
1187  {
1188  ret = ni_device_session_read_hwdesc(p_session_ctx, p_session_data,
1190  }
1191  if (ret == 0)
1192  {
1193  ni_dec_ctx->eos = p_session_data->data.frame.end_of_stream;
1194 
1195  uint64_t diff = p_session_ctx->pkt_num - p_session_ctx->frame_num - p_session_ctx->session_statistic.ui32FramesDropped;
1196  while (!ni_dec_ctx->eos && p_param->dec_input_params.min_packets_delay &&
1197  diff < p_session_ctx->pkt_delay_cnt &&
1198  diff + ni_fifo_number_of_buffers(ni_dec_ctx->input_data_fifo) >= p_session_ctx->pkt_delay_cnt)
1199  {
1200  ni_session_data_io_t *p_ni_packet = NULL;
1201  p_ni_packet = (ni_session_data_io_t *)ni_fifo_generic_read(ni_dec_ctx->input_data_fifo);
1202  ni_log(NI_LOG_TRACE, "%s pts=%" PRIi64 ", dts=%" PRIi64 "\n",
1203  __FUNCTION__, p_ni_packet->data.packet.pts,
1204  p_ni_packet->data.packet.dts);
1205  int sent = ni_device_session_write(p_session_ctx, p_ni_packet, NI_DEVICE_TYPE_DECODER);
1206  if (sent > 0)
1207  {
1208  if (p_session_ctx->session_run_state == SESSION_RUN_STATE_RESETTING)
1209  {
1211  }
1212  ni_packet_buffer_free(&(p_ni_packet->data.packet));
1213  if ((p_ni_packet->data.packet).data_len == 0)
1214  {
1215  free((p_ni_packet->data.packet).p_custom_sei_set);
1216  (p_ni_packet->data.packet).p_custom_sei_set = NULL;
1217  }
1218  diff = p_session_ctx->pkt_num - p_session_ctx->frame_num - p_session_ctx->session_statistic.ui32FramesDropped;
1219  fifo_flush_cnt++;
1220  } else if (sent == 0) {
1221  ni_fifo_return_read(ni_dec_ctx->input_data_fifo);
1222  break;
1223  } else {
1224  ni_fifo_return_read(ni_dec_ctx->input_data_fifo);
1225  ni_log(NI_LOG_ERROR, "Failed to send fifo's compressed pkt (status=%d)\n", sent);
1226  ret = sent;
1227  if (ret == NI_RETCODE_ERROR_VPU_RECOVERY)
1228  {
1229  ni_log(NI_LOG_INFO, "%s VPU recovery, need to reset\n",
1230  __FUNCTION__);
1232  ni_decoder_frame_buffer_free(&(p_session_data->data.frame));
1233 
1234  ret = ni_quadra_dec_reset(ni_dec_ctx);
1235  if (ret == 0)
1236  {
1238  }
1239  return ret;
1240  } else if (ret == NI_RETCODE_ERROR_INVALID_SESSION ||
1242  {
1244  }
1245  return NI_RETCODE_FAILURE;
1246  }
1247  }
1248 
1249  if (fifo_flush_cnt > 0 &&
1250  retry_read_cnt < 1 &&
1251  diff >= p_session_ctx->pkt_delay_cnt &&
1252  p_session_ctx->pkt_delay_cnt > 0)
1253  {
1254  fifo_flush_cnt = 0;
1255  retry_read_cnt++;
1256  ni_log(NI_LOG_DEBUG, "Re-try to read frame.\n");
1257  goto to_read;
1258  }
1259 
1260  if (!ni_dec_ctx->eos && (p_session_ctx->pkt_num - p_session_ctx->frame_num >
1261  ni_dec_ctx->num_reorder_pics + p_session_ctx->session_statistic.ui32FramesDropped)) {
1262  if (retry_cnt < 200 && (ni_gettime_ns() - t0) < 40000000LL) // 40ms timeout
1263  {
1264  retry_cnt++;
1265  if (ni_dec_ctx->hwframes != 1) {
1266  if (p_session_data->data.frame.data_len[0] == 0) {
1267  ni_decoder_frame_buffer_free(&(p_session_data->data.frame));
1268  goto to_malloc;
1269  }
1270  } else {
1271  if (p_session_data->data.frame.data_len[3] == 0) {
1272  ni_frame_buffer_free(&(p_session_data->data.frame));
1273  goto to_malloc;
1274  }
1275  }
1276  ni_usleep(200); // sleep 200us
1277  goto to_read;
1278  }
1279  else
1280  {
1281  ni_dec_ctx->num_reorder_pics++;
1282  ni_log(NI_LOG_INFO, "Warning: timeout, increaing num_reorder_pics to %d\n",
1283  ni_dec_ctx->num_reorder_pics);
1284  }
1285  }
1286 
1287  if (ni_dec_ctx->hwframes != 1)
1288  {
1289  ni_decoder_frame_buffer_free(&(p_session_data->data.frame));
1290  } else
1291  {
1292  ni_frame_buffer_free(&(p_session_data->data.frame));
1293  }
1294  } else if (ret > 0)
1295  {
1296  if (p_session_ctx->session_run_state == SESSION_RUN_STATE_RESETTING)
1297  {
1298  // On decoder VPU recovery the first received frame corresponding to the
1299  // cached seq_hdr_pkt should be dropped since the data is outdated.
1300  // p_session_ctx->session_run_state = SESSION_RUN_STATE_NORMAL;
1302  if (ni_dec_ctx->hwframes != 1)
1303  {
1304  ni_decoder_frame_buffer_free(&(p_session_data->data.frame));
1305  } else
1306  {
1307  ni_frame_buffer_free(&(p_session_data->data.frame));
1308  }
1309  return 0;
1310  }
1311  // retrieve side data if available
1312  ni_quadra_dec_aux_data(ni_dec_ctx);
1313  ni_quadra_frame_sync(ni_dec_ctx);
1314  if (ni_dec_ctx->niframe.video_width != avctx_width ||
1315  ni_dec_ctx->niframe.video_height != avctx_height)
1316  {
1318  "ff_xcoder_dec_receive: resolution "
1319  "changed: %dx%d to %dx%d\n",
1320  avctx_width, avctx_height, ni_dec_ctx->niframe.video_width,
1321  ni_dec_ctx->niframe.video_height);
1322  ni_dec_ctx->bSequenceChange = 1;
1323  // set num_reorder_pics to default 3 when sequence change
1324  ni_dec_ctx->num_reorder_pics = 3;
1325  }
1326  if (p_session_ctx->frame_num == 1)
1327  {
1328  ni_log(NI_LOG_DEBUG, "NI:%s:out\n",
1329  (frame_planar == 0) ?
1330  "semiplanar" :
1331  (frame_planar == 2) ? "tiled" : "planar");
1332  }
1333  ni_dec_ctx->pixel_format = p_session_ctx->pixel_format;
1334  ni_dec_ctx->num_extra_outputs =
1335  (p_param->dec_input_params.enable_out1 > 0) +
1336  (p_param->dec_input_params.enable_out2 > 0);
1337  ni_dec_ctx->device_handle = p_session_ctx->device_handle;
1338  ni_dec_ctx->active_video_width = p_session_ctx->active_video_width;
1339  ni_dec_ctx->active_video_height = p_session_ctx->active_video_height;
1340  ni_dec_ctx->bit_depth_factor = p_session_ctx->bit_depth_factor;
1341  ni_dec_ctx->ready_to_close = p_session_ctx->ready_to_close;
1342  memset(ni_dec_ctx->p_session_data1, 0, sizeof(ni_session_data_io_t));
1343  memset(ni_dec_ctx->p_session_data2, 0, sizeof(ni_session_data_io_t));
1344  if (ni_dec_ctx->num_extra_outputs)
1345  {
1346  ni_session_data_io_t *p_session_data1 = ni_dec_ctx->p_session_data1;
1347  ni_session_data_io_t *p_session_data2 = ni_dec_ctx->p_session_data2;
1348  // width height does not matter//codec id does not matter//no metadata
1349  ni_frame_buffer_alloc(&(p_session_data1->data.frame), 1, 1, 1, 0, 1,
1350  1, frame_planar);
1351  // buf1 = p_session_data1->data.frame.p_data[0];
1352  if (ni_dec_ctx->num_extra_outputs > 1)
1353  {
1354  // width height does not matter
1355  ni_frame_buffer_alloc(&(p_session_data2->data.frame), 1, 1, 1,
1356  0, 1, 1, frame_planar);
1357  // buf2 = p_session_data2->data.frame.p_data[0];
1358  }
1359  }
1360  } else if (ret < 0)
1361  {
1362  ni_log(NI_LOG_ERROR, "Failed to get output buffer (status = %d)\n",
1363  ret);
1364  if (NI_RETCODE_ERROR_VPU_RECOVERY == ret)
1365  {
1367  "ni_quadra_dec_receive VPU recovery, need to reset ..\n");
1368  // p_session_ctx->session_run_state = SESSION_RUN_STATE_RESETTING;
1370  ni_decoder_frame_buffer_free(&(p_session_data->data.frame));
1371 
1372  ret = ni_quadra_dec_reset(ni_dec_ctx);
1373  if (0 == ret)
1374  {
1376  }
1377  return ret;
1378  } else if (ret == NI_RETCODE_ERROR_INVALID_SESSION ||
1380  {
1382  }
1383  return NI_RETCODE_FAILURE;
1384  }
1385 
1386 #ifdef MEASURE_LATENCY
1387  ni_log(NI_LOG_INFO, "DEC pkt_num %d, fme_num %d, fifo_pkt %d, latency is %d\n",
1388  p_session_ctx->pkt_num, p_session_ctx->frame_num, ni_dec_ctx->input_data_fifo->number_of_buffers_used,
1389  (p_session_ctx->pkt_num + ni_dec_ctx->input_data_fifo->number_of_buffers_used - p_session_ctx->frame_num));
1390 #endif
1391  return ret;
1392 }
1393 
1395 {
1396  ni_dec_ctx->draining = 0;
1397  ni_dec_ctx->flushing = 0;
1398  ni_dec_ctx->eos = 0;
1399  /* Future: for now, always return 1 to indicate the codec has been flushed
1400  and it leaves the flushing state and can process again ! will consider
1401  case of user retaining frames in HW "surface" usage */
1402  return 1;
1403 }
1404 
1406 {
1407  int ret = 1;
1408  if (ni_dec_ctx->flushing)
1409  {
1410  if (!ni_quadra_dec_flush(ni_dec_ctx))
1411  {
1412  ni_log(NI_LOG_DEBUG, "IS flushing and NOT dec_flush, AGAIN!!!\n");
1413  ret = 0;
1414  }
1415  }
1416  return ret;
1417 }
1418 
1420  const char *name, char *value)
1421 {
1422  ni_xcoder_params_t *p_param = ni_dec_ctx->api_param;
1423  int parse_ret = ni_decoder_params_set_value(p_param, name, value);
1424  if (parse_ret != NI_RETCODE_SUCCESS)
1425  {
1426  switch (parse_ret)
1427  {
1429  ni_log(NI_LOG_ERROR, "Unknown option: %s.\n", name);
1430  return NI_RETCODE_FAILURE;
1432  ni_log(NI_LOG_ERROR, "Invalid %s: too big, max char len = %d\n",
1434  return NI_RETCODE_FAILURE;
1436  ni_log(NI_LOG_ERROR, "Invalid %s: too small\n", name);
1437  return NI_RETCODE_FAILURE;
1439  ni_log(NI_LOG_ERROR, "Invalid %s: out of range\n", name);
1440  return NI_RETCODE_FAILURE;
1442  ni_log(NI_LOG_ERROR, "Error setting option %s to value 0\n",
1443  name);
1444  return NI_RETCODE_FAILURE;
1446  ni_log(NI_LOG_ERROR, "Invalid value for %s: %s.\n", name,
1447  value);
1448  return NI_RETCODE_FAILURE;
1450  ni_log(NI_LOG_INFO, "Parameter %s is deprecated\n", name);
1452  break;
1453  default:
1454  ni_log(NI_LOG_ERROR, "Invalid %s: ret %d\n", name, parse_ret);
1455  return NI_RETCODE_FAILURE;
1456  }
1457  }
1458  return parse_ret;
1459 }
1460 
1462  int type)
1463 {
1464  int i, j;
1465  ni_xcoder_params_t *p_param = ni_dec_ctx->api_param;
1466  ni_decoder_input_params_t *pdec_param = &p_param->dec_input_params;
1467  if (!pdec_param)
1468  {
1469  return NI_RETCODE_FAILURE;
1470  }
1471 
1472  if (type == 0) // sync ni_dec_input_params_t to ni_decoder_input_params_t
1473  {
1474  memcpy(ni_dec_ctx->niparam.cr_expr, pdec_param->cr_expr,sizeof(pdec_param->cr_expr));
1475  memcpy(ni_dec_ctx->niparam.sc_expr, pdec_param->sc_expr,sizeof(pdec_param->sc_expr));
1476  memcpy(ni_dec_ctx->niparam.crop_whxy, pdec_param->crop_whxy,sizeof(pdec_param->crop_whxy));
1477  } else if (type ==
1478  1) // sync ni_decoder_input_params_t to ni_xcoder_params_t
1479  {
1480  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
1481  {
1482  if (pdec_param->cr_expr[i][0][0] && pdec_param->cr_expr[i][1][0])
1483  {
1484  pdec_param->crop_whxy[i][0] =
1485  (int)ni_dec_ctx->niparam.crop_whxy[i][0];
1486  pdec_param->crop_whxy[i][1] =
1487  (int)ni_dec_ctx->niparam.crop_whxy[i][1];
1488  }
1489  if (pdec_param->cr_expr[i][2][0])
1490  {
1491  pdec_param->crop_whxy[i][2] =
1492  (int)(ni_dec_ctx->niparam.crop_whxy[i][2]);
1493  }
1494  if (pdec_param->cr_expr[i][3][0])
1495  {
1496  pdec_param->crop_whxy[i][3] =
1497  (int)(ni_dec_ctx->niparam.crop_whxy[i][3]);
1498  }
1499  if (pdec_param->sc_expr[i][0][0] && pdec_param->sc_expr[i][1][0])
1500  {
1501  pdec_param->scale_wh[i][0] = ni_dec_ctx->niparam.scale_wh[i][0];
1502  pdec_param->scale_wh[i][1] = ni_dec_ctx->niparam.scale_wh[i][1];
1503  }
1504  }
1505  } else if (type == 2)
1506  {
1507  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
1508  {
1510  {
1511  continue;
1512  }
1513  for (j = 0; j < 4; j++)
1514  {
1515  if (strlen(p_param->dec_input_params.cr_expr[i][j]))
1516  {
1518  "Setting crop parameters without "
1519  "setting crop mode to manual?\n");
1520  return NI_RETCODE_FAILURE;
1521  }
1522  }
1523  }
1524  ni_dec_ctx->niparam.semi_planar[0] =
1525  p_param->dec_input_params.semi_planar[0];
1526  ni_dec_ctx->niparam.force_8_bit[0] =
1527  p_param->dec_input_params.force_8_bit[0];
1528  }
1529  return 0;
1530 }
1531 
1533  void *p_session_data)
1534 {
1535  ni_session_data_io_t *p_session_data1 = p_session_data;
1536  return p_session_data1->data.frame.p_data[0];
1537 }
_ni_ppu_config
Definition: ni_av_codec.h:473
NI_RETCODE_ERROR_VPU_RECOVERY
@ NI_RETCODE_ERROR_VPU_RECOVERY
Definition: ni_defs.h:515
_ni_quadra_dec_context_t::offset
unsigned long long offset
Definition: ni_quadra_dec_api.h:163
NI_CODEC_FORMAT_JPEG
@ NI_CODEC_FORMAT_JPEG
Definition: ni_device_api.h:914
ni_frame_get_aux_data
ni_aux_data_t * ni_frame_get_aux_data(const ni_frame_t *frame, ni_aux_data_type_t type)
Retrieve from the frame auxiliary data of a given type if exists.
Definition: ni_device_api.c:4066
ni_quadra_symbolic_decoder_param
int ni_quadra_symbolic_decoder_param(ni_quadra_dec_context_t *ni_dec_ctx, int type)
sync ni_decoder_input_params_t and ni_xcoder_params_t
Definition: ni_quadra_dec_api.c:1461
NI_MAX_RESOLUTION_HEIGHT
#define NI_MAX_RESOLUTION_HEIGHT
Definition: ni_device_api.h:101
_ni_quadra_frame::crop_top
uint32_t crop_top
Definition: ni_quadra_dec_api.h:73
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
_ni_packet::p_custom_sei_set
ni_custom_sei_set_t * p_custom_sei_set
Definition: ni_device_api.h:2853
NI_GENERATE_ALL_NAL_HEADER_BIT
#define NI_GENERATE_ALL_NAL_HEADER_BIT
Definition: ni_av_codec.h:42
_ni_session_context::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:1594
_ni_quadra_dec_context_t::extradata
uint8_t * extradata
Definition: ni_quadra_dec_api.h:157
NI_MIN_RESOLUTION_WIDTH
#define NI_MIN_RESOLUTION_WIDTH
Definition: ni_device_api.h:86
ni_bitstream.h
Utility definitions to operate on bits in a bitstream.
_ni_quadra_dec_context_t::is_lone_sei_pkt
int is_lone_sei_pkt
Definition: ni_quadra_dec_api.h:171
_ni_quadra_dec_context_t::input_data_fifo
ni_fifo_buffer_t * input_data_fifo
Definition: ni_quadra_dec_api.h:215
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_DEC_PKT_BUF_NUM_MAX
#define NI_DEC_PKT_BUF_NUM_MAX
Definition: ni_quadra_dec_api.c:38
_ni_quadra_frame::sei_hdr_mastering_display_color_vol_len
unsigned int sei_hdr_mastering_display_color_vol_len
Definition: ni_quadra_dec_api.h:89
_ni_frame::vui_len
unsigned int vui_len
Definition: ni_device_api.h:2650
_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_quadra_dec_context_t::niframe
ni_quadra_frame_t niframe
Definition: ni_quadra_dec_api.h:213
_ni_decoder_input_params_t::enable_out1
int enable_out1
Definition: ni_device_api.h:2500
_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_MIN_RESOLUTION_WIDTH_JPEG
#define NI_MIN_RESOLUTION_WIDTH_JPEG
Definition: ni_device_api.h:83
_ni_session_context::force_low_delay
bool force_low_delay
Definition: ni_device_api.h:1699
_ni_quadra_dec_context_t::num_reorder_pics
int num_reorder_pics
Definition: ni_quadra_dec_api.h:200
ni_quadra_dec_init
int ni_quadra_dec_init(ni_quadra_dec_context_t *ni_dec_ctx)
Initialize decode parameters and open decoder device including ni_quadra_dec_context_t,...
Definition: ni_quadra_dec_api.c:350
_ni_session_context::dev_xcoder_name
char dev_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1488
H264_MAX_SPS_COUNT
#define H264_MAX_SPS_COUNT
_ni_quadra_frame::end_of_stream
uint32_t end_of_stream
Definition: ni_quadra_dec_api.h:68
_ni_quadra_dec_context_t::extradata_size
int extradata_size
Definition: ni_quadra_dec_api.h:158
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_packet::flags
int flags
Definition: ni_device_api.h:2851
_ni_quadra_dec_context_t::width
int width
Definition: ni_quadra_dec_api.h:193
NI_DEVICE_TYPE_DECODER
@ NI_DEVICE_TYPE_DECODER
Definition: ni_defs.h:346
ni_fifo_generic_write
uint8_t * ni_fifo_generic_write(ni_fifo_buffer_t *p_fifo)
Get free buffer to write in the fifo.
Definition: ni_quadra_filter_api.c:148
_ni_session_context::session_id
uint32_t session_id
Definition: ni_device_api.h:1480
_ni_packet::start_of_stream
uint32_t start_of_stream
Definition: ni_device_api.h:2832
_ni_quadra_dec_context_t::ui32FramesCorrupted
u_int32_t ui32FramesCorrupted
Definition: ni_quadra_dec_api.h:219
ni_fifo_return_read
int ni_fifo_return_read(ni_fifo_buffer_t *p_fifo)
Push back the last read buffer to the fifo.
Definition: ni_quadra_filter_api.c:207
_ni_quadra_dec_context_t::current_pts
int64_t current_pts
Definition: ni_quadra_dec_api.h:160
NI_CODEC_HW_NONE
@ NI_CODEC_HW_NONE
Definition: ni_device_api.h:939
_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_quadra_dec_close
void ni_quadra_dec_close(ni_quadra_dec_context_t *ni_dec_ctx)
Decode close, including ni_quadra_dec_context_t,.
Definition: ni_quadra_dec_api.c:87
_ni_session_context::p_leftover
uint8_t * p_leftover
Definition: ni_device_api.h:1506
_ni_session_data_io::packet
ni_packet_t packet
Definition: ni_device_api.h:2871
_ni_packet::dts
long long dts
Definition: ni_device_api.h:2827
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:427
_ni_session_context::active_video_width
uint32_t active_video_width
Definition: ni_device_api.h:1549
ni_fifo_generic_read
uint8_t * ni_fifo_generic_read(ni_fifo_buffer_t *p_fifo)
Get first filled buffer to read in the fifo.
Definition: ni_quadra_filter_api.c:178
_ni_frame::color_trc
uint8_t color_trc
Definition: ni_device_api.h:2683
_ni_quadra_dec_context_t::pkt_pts_unchange
int pkt_pts_unchange
Definition: ni_quadra_dec_api.h:217
NI_DEC_CROP_MODE_AUTO
@ NI_DEC_CROP_MODE_AUTO
Definition: ni_device_api.h:929
ni_log_set_level
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition: ni_log.c:202
_ni_session_context::actual_video_width
uint32_t actual_video_width
Definition: ni_device_api.h:1553
ni_gettime_ns
uint64_t ni_gettime_ns(void)
Definition: ni_util.c:1998
_ni_quadra_dec_context_t::bit_rate
long bit_rate
Definition: ni_quadra_dec_api.h:192
_ni_dec_input_params_t::force_8_bit
int force_8_bit[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_quadra_dec_api.h:120
ni_quadra_dec_frame_buffer_alloc
uint8_t * ni_quadra_dec_frame_buffer_alloc(ni_quadra_dec_context_t *ni_dec_ctx, void *p_session_data)
alloc session p_data
Definition: ni_quadra_dec_api.c:1532
_ni_frame::vui_num_units_in_tick
uint32_t vui_num_units_in_tick
Definition: ni_device_api.h:2689
ni_rsrc_api.h
Public definitions for managing NETINT video processing devices.
_ni_quadra_dec_context_t::ppu_reconfig
bool ppu_reconfig
Definition: ni_quadra_dec_api.h:220
ni_av_codec.h
Audio/video related utility definitions.
_ni_frame::crop_top
uint32_t crop_top
Definition: ni_device_api.h:2613
ni_quadra_frame_copy_aux_data
void ni_quadra_frame_copy_aux_data(ni_quadra_dec_context_t *ni_dec_ctx, uint8_t *dst_data, int type, int size)
Retrieve from the frame auxiliary data of a given type if exists.
Definition: ni_quadra_dec_api.c:1051
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_frame::pts
long long pts
Definition: ni_quadra_dec_api.h:67
_ni_quadra_frame::dts
long long dts
Definition: ni_quadra_dec_api.h:66
_ni_quadra_dec_context_t::eos
int eos
Definition: ni_quadra_dec_api.h:169
_ni_decoder_input_params_t::min_packets_delay
bool min_packets_delay
Definition: ni_device_api.h:2531
_ni_quadra_dec_context_t::ff_log_level
int ff_log_level
Definition: ni_quadra_dec_api.h:188
_ni_quadra_frame::vui_time_scale
uint32_t vui_time_scale
Definition: ni_quadra_dec_api.h:107
_ni_frame::error_ratio
uint32_t error_ratio
Definition: ni_device_api.h:2710
_ni_frame::sei_user_data_unreg_len
unsigned int sei_user_data_unreg_len
Definition: ni_device_api.h:2644
_ni_dec_input_params_t::crop_whxy
int crop_whxy[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS][4]
Definition: ni_quadra_dec_api.h:123
_ni_session_statistic_t::ui32FramesCorrupted
uint32_t ui32FramesCorrupted
Definition: ni_defs.h:398
_ni_quadra_frame::sei_user_data_unreg_len
unsigned int sei_user_data_unreg_len
Definition: ni_quadra_dec_api.h:87
ni_quadra_frame_free
void ni_quadra_frame_free(void *opaque, uint8_t *data)
frame free, including void*
Definition: ni_quadra_dec_api.c:61
_ni_frame::orignal_pts
long long orignal_pts
Definition: ni_device_api.h:2709
_ni_frame::p_buffer
uint8_t * p_buffer
Definition: ni_device_api.h:2666
_ni_frame::dts
long long dts
Definition: ni_device_api.h:2606
_ni_quadra_dec_context_t::started
int started
Definition: ni_quadra_dec_api.h:166
_ni_decoder_input_params_t::force_low_delay
bool force_low_delay
Definition: ni_device_api.h:2518
NI_RETCODE_INVALID_PARAM
@ NI_RETCODE_INVALID_PARAM
Definition: ni_defs.h:429
_ni_frame::pkt_pos
uint64_t pkt_pos
Definition: ni_device_api.h:2699
_ni_frame::crop_left
uint32_t crop_left
Definition: ni_device_api.h:2615
NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:311
_ni_quadra_dec_context_t::suspended
int suspended
Definition: ni_quadra_dec_api.h:216
_ni_decoder_input_params_t::sc_expr
char sc_expr[NI_MAX_NUM_OF_DECODER_OUTPUTS][2][NI_MAX_PPU_PARAM_EXPR_CHAR+1]
Definition: ni_device_api.h:2514
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1494
_ni_quadra_dec_context_t::low_delay
int low_delay
Definition: ni_quadra_dec_api.h:180
_ni_decoder_input_params_t::crop_mode
int crop_mode[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2506
_ni_aux_data::size
int size
Definition: ni_device_api.h:622
_ni_quadra_dec_context_t::active_video_width
uint32_t active_video_width
Definition: ni_quadra_dec_api.h:203
_ni_quadra_frame::p_custom_sei_set
void * p_custom_sei_set
Definition: ni_quadra_dec_api.h:102
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1478
ni_fifo_is_empty
int ni_fifo_is_empty(ni_fifo_buffer_t *p_fifo)
Check if a fifo is empty.
Definition: ni_quadra_filter_api.c:123
_ni_quadra_frame::video_height
uint32_t video_height
Definition: ni_quadra_dec_api.h:71
ni_cmp_fw_api_ver
int ni_cmp_fw_api_ver(const char ver1[], const char ver2[])
Compare two 3 character strings containing a FW API version. Handle comparision when FW API version f...
Definition: ni_util.c:3674
_ni_ppu_config::ppu_w
uint16_t ppu_w[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_av_codec.h:475
_ni_quadra_dec_context_t::custom_sei_type
int custom_sei_type
Definition: ni_quadra_dec_api.h:179
NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_MEM_ALOC
Definition: ni_defs.h:431
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:425
_ni_quadra_dec_context_t::fps_denom
int fps_denom
Definition: ni_quadra_dec_api.h:191
_ni_session_context::fw_rev
uint8_t fw_rev[8]
Definition: ni_device_api.h:1625
SESSION_RUN_STATE_NORMAL
@ SESSION_RUN_STATE_NORMAL
Definition: ni_device_api.h:1177
ni_quadra_dec_flush
int ni_quadra_dec_flush(ni_quadra_dec_context_t *ni_dec_ctx)
Definition: ni_quadra_dec_api.c:1394
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_quadra_dec_context_t::enable_follow_iframe
int enable_follow_iframe
Definition: ni_quadra_dec_api.h:218
_ni_fifo_buffer_t::number_of_buffers_used
uint32_t number_of_buffers_used
Definition: ni_quadra_filter_api.h:154
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_packet::pkt_pos
uint64_t pkt_pos
Definition: ni_device_api.h:2830
_ni_quadra_frame::sei_cc_offset
unsigned int sei_cc_offset
Definition: ni_quadra_dec_api.h:82
_ni_quadra_frame::crop_left
uint32_t crop_left
Definition: ni_quadra_dec_api.h:75
_ni_decoder_input_params_t::crop_whxy
int crop_whxy[NI_MAX_NUM_OF_DECODER_OUTPUTS][4]
Definition: ni_device_api.h:2507
_ni_decoder_input_params_t::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2515
_ni_quadra_dec_context_t::p_session_data
void * p_session_data
Definition: ni_quadra_dec_api.h:210
_ni_quadra_frame::vui_num_units_in_tick
uint32_t vui_num_units_in_tick
Definition: ni_quadra_dec_api.h:106
HEVC_MAX_SPS_COUNT
#define HEVC_MAX_SPS_COUNT
_niFrameSurface1::ui16FrameIdx
uint16_t ui16FrameIdx
Definition: ni_device_api.h:2795
ni_quadra_dec_wipe_aux_data
void ni_quadra_dec_wipe_aux_data(ni_quadra_dec_context_t *ni_dec_ctx)
Free and remove all auxiliary data from the ni_dec_ctx frame.
Definition: ni_quadra_dec_api.c:1033
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:61
option::name
const char * name
Definition: ni_getopt.h:75
_ni_quadra_dec_context_t::dev_blk_name
char * dev_blk_name
Definition: ni_quadra_dec_api.h:147
_ni_quadra_frame::sei_hdr_mastering_display_color_vol_offset
unsigned int sei_hdr_mastering_display_color_vol_offset
Definition: ni_quadra_dec_api.h:88
_ni_decoder_input_params_t::cr_expr
char cr_expr[NI_MAX_NUM_OF_DECODER_OUTPUTS][4][NI_MAX_PPU_PARAM_EXPR_CHAR+1]
Definition: ni_device_api.h:2510
ni_decoder_frame_buffer_alloc
ni_retcode_t ni_decoder_frame_buffer_alloc(ni_buf_pool_t *p_pool, ni_frame_t *p_frame, int alloc_mem, int video_width, int video_height, int alignment, int factor, int is_planar)
Allocate memory for decoder frame buffer based on provided parameters; the memory is retrieved from a...
Definition: ni_device_api.c:2586
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:60
_ni_quadra_frame::error_ratio
uint32_t error_ratio
Definition: ni_quadra_dec_api.h:115
_ni_quadra_frame::color_trc
uint8_t color_trc
Definition: ni_quadra_dec_api.h:110
_ni_frame::ni_pict_type
ni_pic_type_t ni_pict_type
Definition: ni_device_api.h:2627
_ni_ppu_config::ppu_set_enable
uint8_t ppu_set_enable
Definition: ni_av_codec.h:474
NI_MAX_RESOLUTION_WIDTH
#define NI_MAX_RESOLUTION_WIDTH
Definition: ni_device_api.h:100
_ni_quadra_dec_context_t::dev_xcoder
char * dev_xcoder
Definition: ni_quadra_dec_api.h:143
ni_defs.h
Common NETINT definitions used by all modules.
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2664
_ni_quadra_frame::p_data
uint8_t * p_data[NI_QUADRA_MAX_NUM_DATA_POINTERS]
Definition: ni_quadra_dec_api.h:93
_ni_quadra_dec_context_t::pkt_duration
int64_t pkt_duration
Definition: ni_quadra_dec_api.h:173
_ni_decoder_input_params_t::semi_planar
int semi_planar[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2505
_ni_decoder_input_params_t::hwframes
int hwframes
Definition: ni_device_api.h:2499
_ni_buf_t::pool
struct _ni_buf_pool_t * pool
Definition: ni_device_api.h:1275
NI_MIN_RESOLUTION_HEIGHT_JPEG
#define NI_MIN_RESOLUTION_HEIGHT_JPEG
Definition: ni_device_api.h:84
NI_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_RETCODE_ERROR_NVME_CMD_FAILED
Definition: ni_defs.h:432
_ni_decoder_input_params_t
Definition: ni_device_api.h:2445
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:63
_ni_quadra_dec_context_t::active_video_height
uint32_t active_video_height
Definition: ni_quadra_dec_api.h:205
_ni_frame::end_of_stream
uint32_t end_of_stream
Definition: ni_device_api.h:2608
_ni_buf_t
Definition: ni_device_api.h:1272
_ni_session_context::prev_size
int prev_size
Definition: ni_device_api.h:1507
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1462
_ni_session_context::p_session_config
void * p_session_config
Definition: ni_device_api.h:1473
_ni_quadra_dec_context_t::enable_low_delay_check
int enable_low_delay_check
Definition: ni_quadra_dec_api.h:182
_ni_session_context::dec_fme_buf_pool
ni_buf_pool_t * dec_fme_buf_pool
Definition: ni_device_api.h:1559
ni_quadra_dec_aux_data
void ni_quadra_dec_aux_data(ni_quadra_dec_context_t *ni_dec_ctx)
Definition: ni_quadra_dec_api.c:1026
NI_POLL_INTERVAL
#define NI_POLL_INTERVAL
Definition: ni_defs.h:228
_ni_quadra_dec_context_t::has_b_frames
int has_b_frames
Definition: ni_quadra_dec_api.h:197
_ni_packet::p_data
void * p_data
Definition: ni_device_api.h:2837
ni_decoder_params_set_value
ni_retcode_t ni_decoder_params_set_value(ni_xcoder_params_t *p_params, const char *name, char *value)
Set value referenced by name in decoder parameters structure.
Definition: ni_device_api.c:4881
_ni_quadra_frame::orignal_pts
long long orignal_pts
Definition: ni_quadra_dec_api.h:114
ni_dec_packet_parse
int ni_dec_packet_parse(ni_session_context_t *p_session_ctx, ni_xcoder_params_t *p_param, uint8_t *data, int size, ni_packet_t *p_packet, int low_delay, int codec_format, int pkt_nal_bitmap, int custom_sei_type, int *svct_skip_next_packet, int *is_lone_sei_pkt)
Decode parse packet.
Definition: ni_av_codec.c:3065
_ni_session_data_io
Definition: ni_device_api.h:2866
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_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_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
Definition: ni_defs.h:96
_ni_quadra_dec_context_t::svct_skip_next_packet
int svct_skip_next_packet
Definition: ni_quadra_dec_api.h:164
_ni_frame::vui_time_scale
uint32_t vui_time_scale
Definition: ni_device_api.h:2690
_ni_quadra_dec_context_t::bSequenceChange
int bSequenceChange
Definition: ni_quadra_dec_api.h:172
_ni_session_context::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1521
_ni_quadra_frame::sei_cc_len
unsigned int sei_cc_len
Definition: ni_quadra_dec_api.h:83
ni_usleep
void ni_usleep(int64_t usec)
Definition: ni_util.c:358
_ni_quadra_dec_context_t::dev_dec_idx
int dev_dec_idx
Definition: ni_quadra_dec_api.h:146
LRETURN
#define LRETURN
Definition: ni_defs.h:323
ni_packet_copy
int ni_packet_copy(void *p_destination, const void *const p_source, int cur_size, void *p_leftover, int *p_prev_size)
Copy video packet accounting for alignment.
Definition: ni_device_api.c:3936
_ni_quadra_dec_context_t::draining
int draining
Definition: ni_quadra_dec_api.h:167
ni_quadra_frame_sync
void ni_quadra_frame_sync(ni_quadra_dec_context_t *ni_dec_ctx)
Definition: ni_quadra_dec_api.c:1061
_ni_dec_input_params_t::scale_wh
int scale_wh[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS][2]
Definition: ni_quadra_dec_api.h:127
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_dec_retrieve_aux_data
void ni_dec_retrieve_aux_data(ni_frame_t *frame)
Retrieve auxiliary data (close caption, various SEI) associated with this frame that is returned by d...
Definition: ni_av_codec.c:237
_ni_frame::dec_buf
ni_buf_t * dec_buf
Definition: ni_device_api.h:2670
_ni_packet::video_height
uint32_t video_height
Definition: ni_device_api.h:2834
_ni_quadra_frame::start_of_stream
uint32_t start_of_stream
Definition: ni_quadra_dec_api.h:69
_ni_packet
Definition: ni_device_api.h:2825
_ni_buf_pool_t
Definition: ni_device_api.h:1282
_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_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_dec_context_t::p_session_data2
void * p_session_data2
Definition: ni_quadra_dec_api.h:212
_ni_quadra_dec_context_t::flushing
int flushing
Definition: ni_quadra_dec_api.h:168
ni_quadra_frame_get_aux_size
int ni_quadra_frame_get_aux_size(ni_quadra_dec_context_t *ni_dec_ctx, int type)
get size from the frame auxiliary data of a given type if exists
Definition: ni_quadra_dec_api.c:1040
NI_RETCODE_PARAM_ERROR_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_TOO_BIG
Definition: ni_defs.h:489
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2663
_ni_quadra_dec_context_t::api_ctx
void * api_ctx
Definition: ni_quadra_dec_api.h:208
ni_fifo_initialize
ni_fifo_buffer_t * ni_fifo_initialize(uint32_t number_of_buffers, uint32_t size)
Initialize a fifo buffer.
Definition: ni_quadra_filter_api.c:44
_ni_quadra_frame::pkt_pos
uint64_t pkt_pos
Definition: ni_quadra_dec_api.h:108
ni_decoder_init_default_params
ni_retcode_t ni_decoder_init_default_params(ni_xcoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height)
Initialize default decoder parameters.
Definition: ni_device_api.c:4546
ni_fifo_is_full
int ni_fifo_is_full(ni_fifo_buffer_t *p_fifo)
Check if a fifo is full.
Definition: ni_quadra_filter_api.c:111
NI_ERRNO
#define NI_ERRNO
Definition: ni_defs.h:217
_ni_quadra_dec_context_t::eos_pkt_received
int eos_pkt_received
Definition: ni_quadra_dec_api.h:152
_ni_quadra_frame::crop_right
uint32_t crop_right
Definition: ni_quadra_dec_api.h:76
_ni_quadra_frame::sei_hdr_content_light_level_info_len
unsigned int sei_hdr_content_light_level_info_len
Definition: ni_quadra_dec_api.h:91
_ni_session_context::hw_action
int hw_action
Definition: ni_device_api.h:1609
_ni_session_context
Definition: ni_device_api.h:1408
ni_fifo_number_of_buffers
uint32_t ni_fifo_number_of_buffers(ni_fifo_buffer_t *p_fifo)
Get number of buffers used in fifo.
Definition: ni_quadra_filter_api.c:135
_ni_quadra_dec_context_t::fps_num
int fps_num
Definition: ni_quadra_dec_api.h:190
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
_niFrameSurface1
Definition: ni_device_api.h:2793
NI_CODEC_HW_ENABLE
@ NI_CODEC_HW_ENABLE
Definition: ni_device_api.h:940
_ni_quadra_frame::video_width
uint32_t video_width
Definition: ni_quadra_dec_api.h:70
NI_MAX_DEVICE_NAME_LEN
#define NI_MAX_DEVICE_NAME_LEN
Definition: ni_defs.h:224
HEVC_MAX_VPS_COUNT
#define HEVC_MAX_VPS_COUNT
NI_PKT_FLAG_KEY
#define NI_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: ni_quadra_dec_api.h:47
_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_frame::color_space
uint8_t color_space
Definition: ni_device_api.h:2684
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_reconfig_ppu_output
int ni_reconfig_ppu_output(ni_session_context_t *p_session_ctx, ni_xcoder_params_t *p_param, ni_ppu_config_t *ppu_config)
Reset decoder ppu resolution.
Definition: ni_av_codec.c:3485
_ni_quadra_dec_context_t::got_first_key_frame
int got_first_key_frame
Definition: ni_quadra_dec_api.h:156
_ni_quadra_dec_context_t::p_session_data1
void * p_session_data1
Definition: ni_quadra_dec_api.h:211
_ni_quadra_dec_context_t::height
int height
Definition: ni_quadra_dec_api.h:194
NI_RETCODE_ERROR_INVALID_SESSION
@ NI_RETCODE_ERROR_INVALID_SESSION
Definition: ni_defs.h:433
_ni_quadra_dec_context_t::num_extra_outputs
int num_extra_outputs
Definition: ni_quadra_dec_api.h:174
_ni_frame::color_primaries
uint8_t color_primaries
Definition: ni_device_api.h:2682
NI_QUADRA_ERROR_INVALID_SESSION
@ NI_QUADRA_ERROR_INVALID_SESSION
Definition: ni_quadra_filter_api.h:210
_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
SESSION_RUN_STATE_RESETTING
@ SESSION_RUN_STATE_RESETTING
Definition: ni_device_api.h:1180
USER_DATA_UNREGISTERED_SEI_PAYLOAD_TYPE
#define USER_DATA_UNREGISTERED_SEI_PAYLOAD_TYPE
Definition: ni_quadra_dec_api.c:37
_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_frame::video_full_range_flag
int video_full_range_flag
Definition: ni_device_api.h:2685
_ni_session_context::ready_to_close
uint32_t ready_to_close
Definition: ni_device_api.h:1544
_ni_quadra_frame::dec_buf
void * dec_buf
Definition: ni_quadra_dec_api.h:98
_ni_quadra_dec_context_t::blk_xcoder_name
char * blk_xcoder_name
Definition: ni_quadra_dec_api.h:145
NI_MAX_PPU_PARAM_EXPR_CHAR
#define NI_MAX_PPU_PARAM_EXPR_CHAR
Definition: ni_defs.h:247
_ni_session_context::codec_format
uint32_t codec_format
Definition: ni_device_api.h:1486
NI_MAX_NUM_OF_DECODER_OUTPUTS
#define NI_MAX_NUM_OF_DECODER_OUTPUTS
Definition: ni_defs.h:243
ni_quadra_dec_receive
int ni_quadra_dec_receive(ni_quadra_dec_context_t *ni_dec_ctx, int avctx_width, int avctx_height, int frame_planar)
Receive decoded data from decoder, including ni_quadra_dec_context_t,.
Definition: ni_quadra_dec_api.c:1117
_ni_decoder_input_params_t::scale_wh
int scale_wh[NI_MAX_NUM_OF_DECODER_OUTPUTS][2]
Definition: ni_device_api.h:2511
_ni_quadra_ppu_config::ppu_w
uint16_t ppu_w[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_quadra_dec_api.h:136
ni_quadra_dec_is_flushing
int ni_quadra_dec_is_flushing(ni_quadra_dec_context_t *ni_dec_ctx)
Decode is flushing or not, including ni_quadra_dec_context_t,.
Definition: ni_quadra_dec_api.c:1405
_ni_quadra_frame::p_buffer
uint8_t * p_buffer
Definition: ni_quadra_dec_api.h:96
_ni_quadra_dec_context_t::ni_quadra_ppu_config
ni_quadra_ppu_config_t ni_quadra_ppu_config
Definition: ni_quadra_dec_api.h:221
_ni_quadra_ppu_config::ppu_h
uint16_t ppu_h[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_quadra_dec_api.h:137
_ni_session_statistic_t::ui32FramesDropped
uint32_t ui32FramesDropped
Definition: ni_defs.h:383
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:2870
_ni_dec_input_params_t::semi_planar
int semi_planar[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_quadra_dec_api.h:121
_ni_decoder_input_params_t::enable_out2
int enable_out2
Definition: ni_device_api.h:2501
_ni_quadra_frame::video_full_range_flag
uint8_t video_full_range_flag
Definition: ni_quadra_dec_api.h:112
NI_QUADRA_PARAM_WARNING_DEPRECATED
@ NI_QUADRA_PARAM_WARNING_DEPRECATED
Definition: ni_quadra_filter_api.h:213
NI_RETCODE_PARAM_INVALID_NAME
@ NI_RETCODE_PARAM_INVALID_NAME
Definition: ni_defs.h:436
ni_quadra_add_headers
int ni_quadra_add_headers(ni_quadra_dec_context_t *ni_dec_ctx, int pkt_flag, const uint8_t *data, int size, uint8_t *extradata, int extradata_size)
Definition: ni_quadra_dec_api.c:544
_ni_frame::sei_user_data_unreg_offset
unsigned int sei_user_data_unreg_offset
Definition: ni_device_api.h:2643
_ni_decoder_input_params_t::skip_extra_headers
int skip_extra_headers
Definition: ni_device_api.h:2541
ni_quadra_align_free
void ni_quadra_align_free(void *opaque, uint8_t *data)
buffer free, including void*
Definition: ni_quadra_dec_api.c:51
_ni_decoder_input_params_t::enable_follow_iframe
int enable_follow_iframe
Definition: ni_device_api.h:2536
_ni_frame::video_height
uint32_t video_height
Definition: ni_device_api.h:2611
ni_quadra_dec_api.h
NETINT decoder API header file.
_ni_decoder_input_params_t::pkt_pts_unchange
int pkt_pts_unchange
Definition: ni_device_api.h:2529
_ni_decoder_input_params_t::force_8_bit
int force_8_bit[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2504
_ni_quadra_frame::color_primaries
uint8_t color_primaries
Definition: ni_quadra_dec_api.h:109
_ni_quadra_dec_context_t::keep_alive_timeout
int keep_alive_timeout
Definition: ni_quadra_dec_api.h:150
_ni_packet::pos
long long pos
Definition: ni_device_api.h:2829
_ni_decoder_input_params_t::custom_sei_passthru
int custom_sei_passthru
Definition: ni_device_api.h:2521
_ni_quadra_dec_context_t::bit_depth_factor
int bit_depth_factor
Definition: ni_quadra_dec_api.h:196
_ni_session_context::active_video_height
uint32_t active_video_height
Definition: ni_device_api.h:1551
_ni_ppu_config::ppu_h
uint16_t ppu_h[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_av_codec.h:476
_ni_quadra_frame::ni_pict_type
int ni_pict_type
Definition: ni_quadra_dec_api.h:79
ni_fifo_free
void ni_fifo_free(ni_fifo_buffer_t *p_fifo)
Free a fifo.
Definition: ni_quadra_filter_api.c:85
_ni_session_context::pkt_delay_cnt
uint32_t pkt_delay_cnt
Definition: ni_device_api.h:1702
_ni_quadra_frame::crop_bottom
uint32_t crop_bottom
Definition: ni_quadra_dec_api.h:74
_ni_quadra_dec_context_t::niparam
ni_dec_input_params_t niparam
Definition: ni_quadra_dec_api.h:214
HEVC_MAX_PPS_COUNT
#define HEVC_MAX_PPS_COUNT
_ni_quadra_dec_context_t::enable_user_data_sei_passthru
int enable_user_data_sei_passthru
Definition: ni_quadra_dec_api.h:177
ni_quadra_dec_params_set_value
int ni_quadra_dec_params_set_value(ni_quadra_dec_context_t *ni_dec_ctx, const char *name, char *value)
Set value referenced by name in decoder parameters structure.
Definition: ni_quadra_dec_api.c:1419
_ni_quadra_dec_context_t::dev_xcoder_name
char * dev_xcoder_name
Definition: ni_quadra_dec_api.h:144
_ni_session_context::blk_dev_name
char blk_dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_device_api.h:1659
_ni_decoder_input_params_t::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:2519
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1547
_ni_session_context::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:1595
_niFrameSurface1::device_handle
int32_t device_handle
Definition: ni_device_api.h:2800
_ni_quadra_frame::color_space
uint8_t color_space
Definition: ni_quadra_dec_api.h:111
_ni_quadra_dec_context_t::pixel_format
int pixel_format
Definition: ni_quadra_dec_api.h:199
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_device_api.h
Public definitions for operating NETINT video processing devices for video processing.
ni_hwframe_buffer_recycle
ni_retcode_t ni_hwframe_buffer_recycle(niFrameSurface1_t *surface, int32_t device_handle)
Recycle a frame buffer on card.
Definition: ni_device_api.c:8487
_ni_quadra_dec_context_t
Definition: ni_quadra_dec_api.h:140
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1476
_ni_session_context::enable_user_data_sei_passthru
int enable_user_data_sei_passthru
Definition: ni_device_api.h:1614
_ni_quadra_frame::vui_len
unsigned int vui_len
Definition: ni_quadra_dec_api.h:113
NI_RETCODE_FAILURE
@ NI_RETCODE_FAILURE
Definition: ni_defs.h:428
_ni_dec_input_params_t::sc_expr
char sc_expr[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS][2][NI_QUADRA_MAX_PPU_PARAM_EXPR_CHAR+1]
Definition: ni_quadra_dec_api.h:130
_ni_frame::start_of_stream
uint32_t start_of_stream
Definition: ni_device_api.h:2609
_ni_quadra_dec_context_t::vpu_reset
int vpu_reset
Definition: ni_quadra_dec_api.h:170
_ni_quadra_ppu_config::out_enabled
uint16_t out_enabled[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_quadra_dec_api.h:135
_ni_frame::pts
long long pts
Definition: ni_device_api.h:2607
_ni_quadra_dec_context_t::device_handle
int device_handle
Definition: ni_quadra_dec_api.h:149
_ni_frame::crop_right
uint32_t crop_right
Definition: ni_device_api.h:2616
NI_RETCODE_PARAM_ERROR_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_TOO_SMALL
Definition: ni_defs.h:490
ni_util.h
Utility definitions.
ni_device_session_read_hwdesc
int ni_device_session_read_hwdesc(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 hwdesc from decoder If ...
Definition: ni_device_api.c:8043
_ni_dec_input_params_t::cr_expr
char cr_expr[NI_QUADRA_MAX_NUM_OF_DECODER_OUTPUTS][4][NI_QUADRA_MAX_PPU_PARAM_EXPR_CHAR+1]
Definition: ni_quadra_dec_api.h:126
ni_quadra_setup_decoder
int ni_quadra_setup_decoder(ni_quadra_dec_context_t *ni_dec_ctx)
Initialize init device session_context and init default params including ni_quadra_dec_context_t,...
Definition: ni_quadra_dec_api.c:185
_ni_quadra_dec_context_t::api_param
void * api_param
Definition: ni_quadra_dec_api.h:209
_ni_quadra_dec_context_t::codec_format
int codec_format
Definition: ni_quadra_dec_api.h:195
_ni_session_context::pic_reorder_delay
int pic_reorder_delay
Definition: ni_device_api.h:1641
ni_aligned_free
#define ni_aligned_free(p_memptr)
Definition: ni_util.h:399
_ni_decoder_input_params_t::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:2517
_ni_packet::video_width
uint32_t video_width
Definition: ni_device_api.h:2833
NI_MIN_RESOLUTION_HEIGHT
#define NI_MIN_RESOLUTION_HEIGHT
Definition: ni_device_api.h:87
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_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_dec_send
int ni_quadra_dec_send(ni_quadra_dec_context_t *ni_dec_ctx, int pkt_flags, uint8_t *data, int pkt_size, uint8_t *lonedata, int lone_size, int64_t pkt_pts, int64_t pkt_dts, int pkt_pos, int width, int height, uint8_t *extradata, int extradata_size)
Parse the packet and send the packet to decode device.
Definition: ni_quadra_dec_api.c:662
NI_RETCODE_PARAM_ERROR_OOR
@ NI_RETCODE_PARAM_ERROR_OOR
Definition: ni_defs.h:493
_ni_quadra_dec_context_t::hwframes
int hwframes
Definition: ni_quadra_dec_api.h:198
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2610
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
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1616
MAX_CHAR_IN_DEVICE_NAME
#define MAX_CHAR_IN_DEVICE_NAME
Definition: ni_device_api.h:184
_ni_quadra_dec_context_t::skip_extra_headers
int skip_extra_headers
Definition: ni_quadra_dec_api.h:184
_ni_aux_data
Definition: ni_device_api.h:618
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:62
_ni_quadra_frame::sei_hdr_content_light_level_info_offset
unsigned int sei_hdr_content_light_level_info_offset
Definition: ni_quadra_dec_api.h:90
_ni_frame::crop_bottom
uint32_t crop_bottom
Definition: ni_device_api.h:2614
ni_decoder_frame_buffer_pool_return_buf
void ni_decoder_frame_buffer_pool_return_buf(ni_buf_t *buf, ni_buf_pool_t *p_buffer_pool)
Return a memory buffer to memory buffer pool.
Definition: ni_device_api.c:3694
_ni_xcoder_params::dec_input_params
ni_decoder_input_params_t dec_input_params
Definition: ni_device_api.h:2766
ni_quadra_dec_reset
int ni_quadra_dec_reset(ni_quadra_dec_context_t *ni_dec_ctx)
Definition: ni_quadra_dec_api.c:493
_ni_quadra_frame::sei_user_data_unreg_offset
unsigned int sei_user_data_unreg_offset
Definition: ni_quadra_dec_api.h:86
H264_MAX_PPS_COUNT
#define H264_MAX_PPS_COUNT
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_frame::p_custom_sei_set
ni_custom_sei_set_t * p_custom_sei_set
Definition: ni_device_api.h:2674
_ni_quadra_dec_context_t::ready_to_close
uint32_t ready_to_close
Definition: ni_quadra_dec_api.h:206
ni_decoder_frame_buffer_free
ni_retcode_t ni_decoder_frame_buffer_free(ni_frame_t *p_frame)
Free decoder frame buffer that was previously allocated with ni_decoder_frame_buffer_alloc,...
Definition: ni_device_api.c:3644
NI_MAX_RESOLUTION_AREA
#define NI_MAX_RESOLUTION_AREA
Definition: ni_device_api.h:102
_ni_quadra_frame::data_len
uint32_t data_len[NI_QUADRA_MAX_NUM_DATA_POINTERS]
Definition: ni_quadra_dec_api.h:94
_ni_session_context::session_statistic
ni_session_statistic_t session_statistic
Definition: ni_device_api.h:1650
_ni_session_context::burst_control
int burst_control
Definition: ni_device_api.h:1615
_ni_quadra_dec_context_t::dec_wait
int dec_wait
Definition: ni_quadra_dec_api.h:153
NI_CODEC_FORMAT_H265
@ NI_CODEC_FORMAT_H265
Definition: ni_device_api.h:912
ni_frame_wipe_aux_data
void ni_frame_wipe_aux_data(ni_frame_t *frame)
Free and remove all auxiliary data from the frame.
Definition: ni_device_api.c:4115
_ni_quadra_dec_context_t::pkt_nal_bitmap
int pkt_nal_bitmap
Definition: ni_quadra_dec_api.h:183
_ni_packet::data_len
uint32_t data_len
Definition: ni_device_api.h:2838