libxcoder  5.4.0
ni_device_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_device_api.c
24  *
25  * \brief Public definitions for operating NETINT video processing devices for
26  * video processing
27  ******************************************************************************/
28 
29 #if __linux__ || __APPLE__
30 #define _GNU_SOURCE //O_DIRECT is Linux-specific. One must define _GNU_SOURCE to obtain its definitions
31 #if __linux__
32 #include <linux/types.h>
33 #endif
34 #include <unistd.h>
35 #include <sys/ioctl.h>
36 #include <sys/mman.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/time.h>
40 #include <fcntl.h>
41 #include <errno.h>
42 #include <semaphore.h>
43 #include <limits.h>
44 #include <unistd.h>
45 #include <signal.h>
46 #include <poll.h>
47 #endif
48 
49 #include <stdint.h>
50 #include <string.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <stdint.h>
54 #include <sys/stat.h>
55 #include "inttypes.h"
56 #include "ni_device_api.h"
57 #include "ni_device_api_priv.h"
58 #include "ni_nvme.h"
59 #include "ni_util.h"
60 #include "ni_rsrc_api.h"
61 #include "ni_rsrc_priv.h"
62 #include "ni_lat_meas.h"
63 #ifdef _WIN32
64 #include <shlobj.h>
65 #else
66 #include "ni_p2p_ioctl.h"
67 #endif
68 
78  0};
79 #if __linux__ || __APPLE__
80 static struct stat g_nvme_stat = { 0 };
81 
82 static int close_fd_zero_atexit = 0;
83 
84 static void close_fd_zero(void)
85 {
86  close(0);
87 }
88 
89 #endif
90 
91 /*!*****************************************************************************
92  * \brief Allocate and initialize a new ni_session_context_t struct
93  *
94  *
95  * \return On success returns a valid pointer to newly allocated context
96  * On failure returns NULL
97  ******************************************************************************/
99 {
100  ni_session_context_t *p_ctx = NULL;
101 
102  p_ctx = malloc(sizeof(ni_session_context_t));
103  if (!p_ctx)
104  {
106  "ERROR: %s() Failed to allocate memory for session context\n",
107  __func__);
108  } else
109  {
110  memset(p_ctx, 0, sizeof(ni_session_context_t));
111 
113  {
114  ni_log(NI_LOG_ERROR, "ERROR: %s() Failed to init session context\n",
115  __func__);
117  return NULL;
118  }
119  }
120  return p_ctx;
121 }
122 
123 /*!*****************************************************************************
124  * \brief Free previously allocated session context
125  *
126  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
127  * struct
128  *
129  ******************************************************************************/
131 {
132  if (p_ctx)
133  {
135 #ifdef MEASURE_LATENCY
136  if (p_ctx->frame_time_q)
137  {
139  }
140 #endif
141  free(p_ctx);
142  }
143 }
144 
145 /*!*****************************************************************************
146  * \brief Initialize already allocated session context to a known state
147  *
148  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
149  * struct
150  * \return On success
151  * NI_RETCODE_SUCCESS
152  * On failure
153  * NI_RETCODE_INVALID_PARAM
154  * NI_RETCODE_FAILURE
155  ******************************************************************************/
157 {
158  int bitrate = 0;
159  int framerate_num = 0;
160  int framerate_denom = 0;
161 
162  if (!p_ctx)
163  {
165  }
166 
168  {
169  // session context will reset so save the last values for sequence change
170  if (p_ctx->last_bitrate < NI_MIN_BITRATE)
171  bitrate = NI_MIN_BITRATE;
172  else if (p_ctx->last_bitrate > NI_MAX_BITRATE)
173  bitrate = NI_MAX_BITRATE;
174  else
175  bitrate = p_ctx->last_bitrate;
176  framerate_num = p_ctx->last_framerate.framerate_num;
177  framerate_denom = p_ctx->last_framerate.framerate_denom;
178  }
179 
180  memset(p_ctx, 0, sizeof(ni_session_context_t));
181 
182  p_ctx->last_bitrate = bitrate;
183  p_ctx->last_framerate.framerate_num = framerate_num;
184  p_ctx->last_framerate.framerate_denom = framerate_denom;
185 
186  // Xcoder thread mutex init
187  if (ni_pthread_mutex_init(&p_ctx->mutex))
188  {
189  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): init xcoder_mutex fail, return\n",
190  __func__);
191  return NI_RETCODE_FAILURE;
192  }
193  p_ctx->pext_mutex = &p_ctx->mutex; //used exclusively for hwdl
194 
195  // low delay send/recv sync init
197  {
198  ni_log2(p_ctx, NI_LOG_ERROR,
199  "ERROR %s(): init xcoder_low_delay_sync_mutex fail return\n",
200  __func__);
201  return NI_RETCODE_FAILURE;
202  }
203  if (ni_pthread_cond_init(&p_ctx->low_delay_sync_cond, NULL))
204  {
205  ni_log2(p_ctx, NI_LOG_ERROR,
206  "ERROR %s(): init xcoder_low_delay_sync_cond fail return\n",
207  __func__);
208  return NI_RETCODE_FAILURE;
209  }
210 
211  p_ctx->mutex_initialized = true;
212 
213  // Init the max IO size to be invalid
217  p_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
218  p_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
219  p_ctx->hw_id = NI_INVALID_HWID;
220  p_ctx->event_handle = NI_INVALID_EVENT_HANDLE;
221  p_ctx->thread_event_handle = NI_INVALID_EVENT_HANDLE;
223  p_ctx->keep_alive_thread = (ni_pthread_t){0};
225  p_ctx->decoder_low_delay = 0;
226  p_ctx->enable_low_delay_check = 0;
227  p_ctx->low_delay_sync_flag = 0;
228  p_ctx->async_mode = 0;
230  p_ctx->buffered_frame_index = 0;
231  p_ctx->ppu_reconfig_pkt_pos = 0;
232  // by default, select the least model load card
235 #ifdef MY_SAVE
236  p_ctx->debug_write_ptr = NULL;
237  p_ctx->debug_write_index_ptr = NULL;
238  p_ctx->debug_write_sent_size = 0;
239 #endif
240 
241 #ifdef MEASURE_LATENCY
242  p_ctx->frame_time_q = (void *)ni_lat_meas_q_create(2000);
243 #endif
244 
245  return NI_RETCODE_SUCCESS;
246 }
247 
248 /*!*****************************************************************************
249  * \brief Clear already allocated session context
250  *
251  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
252  *
253  *
254  ******************************************************************************/
256 {
257  if(p_ctx->mutex_initialized)
258  {
259  p_ctx->mutex_initialized = false;
263  }
264 }
265 
266 /*!*****************************************************************************
267  * \brief Create event and return event handle if successful (Windows only)
268  *
269  * \return On success returns a event handle
270  * On failure returns NI_INVALID_EVENT_HANDLE
271  ******************************************************************************/
272 ni_event_handle_t ni_create_event(void)
273 {
274 #ifdef _WIN32
275  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
276 
277  // Input-0 determines whether the returned handle can be inherited by the child process.If lpEventAttributes is NULL, this handle cannot be inherited.
278  // Input-1 specifies whether the event object is created to be restored manually or automatically.If set to FALSE, when a thread waits for an event signal, the system automatically restores the event state to a non-signaled state.
279  // Input-2 specifies the initial state of the event object.If TRUE, the initial state is signaled;Otherwise, no signal state.
280  // Input-3 If the lpName is NULL, a nameless event object is created.。
281  event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
282  if (event_handle == NULL)
283  {
284  ni_log(NI_LOG_ERROR, "ERROR %d: %s() create event failed\n",
285  NI_ERRNO, __func__);
286  return NI_INVALID_EVENT_HANDLE;
287  }
288  return event_handle;
289 #else
290  return NI_INVALID_EVENT_HANDLE;
291 #endif
292 }
293 
294 /*!*****************************************************************************
295  * \brief Close event and release resources (Windows only)
296  *
297  * \return NONE
298  *
299  ******************************************************************************/
300 void ni_close_event(ni_event_handle_t event_handle)
301 {
302  if ( NI_INVALID_DEVICE_HANDLE == event_handle )
303  {
304  ni_log(NI_LOG_DEBUG, "Warning %s: null parameter passed %x\n", __func__,
305  event_handle);
306  return;
307  }
308 
309  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
310 
311 #ifdef _WIN32
312  BOOL retval;
313  ni_log(NI_LOG_DEBUG, "%s(): closing %p\n", __func__, event_handle);
314 
315  retval = CloseHandle(event_handle);
316  if (FALSE == retval)
317  {
318  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): closing event_handle %p failed\n",
319  NI_ERRNO, __func__, event_handle);
320  }
321  else
322  {
323  ni_log(NI_LOG_DEBUG, "%s(): device %p closed successfuly\n", __func__,
324  event_handle);
325  }
326 #else
327  int err = 0;
328  ni_log(NI_LOG_DEBUG, "%s(): closing %d\n", __func__, event_handle);
329  err = close(event_handle);
330  if (err)
331  {
332  char error_message[100] = {'\0'};
333  char unknown_error_message[20] = {'\0'};
334  ni_sprintf(error_message, 100, "ERROR: %s(): ", __func__);
335  switch (err)
336  {
337  case EBADF:
338  ni_strcat(error_message, 100, "EBADF\n");
339  break;
340  case EINTR:
341  ni_strcat(error_message, 100, "EINTR\n");
342  break;
343  case EIO:
344  ni_strcat(error_message, 100, "EIO\n");
345  break;
346  default:
347  ni_sprintf(unknown_error_message, 20, "Unknown error %d\n", err);
348  ni_strcat(error_message, 100, unknown_error_message);
349  }
350  ni_log(NI_LOG_ERROR, "%s\n", error_message);
351  }
352 #endif
353  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
354 }
355 
356 /*!*****************************************************************************
357  * \brief Open device and return device device_handle if successful
358  *
359  * \param[in] p_dev Device name represented as c string. ex: "/dev/nvme0"
360  * \param[out] p_max_io_size_out Maximum IO Transfer size supported, could be
361  * NULL
362  *
363  * \return On success returns a device device_handle
364  * On failure returns NI_INVALID_DEVICE_HANDLE
365  ******************************************************************************/
366 ni_device_handle_t ni_device_open(const char * p_dev, uint32_t * p_max_io_size_out)
367 {
368 #ifdef _WIN32
369  DWORD retval;
370  HANDLE device_handle;
371 
372  if (!p_dev)
373  {
374  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
375  return NI_INVALID_DEVICE_HANDLE;
376  }
377 
378  if (p_max_io_size_out != NULL && *p_max_io_size_out == NI_INVALID_IO_SIZE)
379  {
380  // For now, we just use it to allocate p_leftover buffer
381  // NI_MAX_PACKET_SZ is big enough
382  *p_max_io_size_out = NI_MAX_PACKET_SZ;
383  }
384 
385  device_handle = CreateFile(p_dev, GENERIC_READ | GENERIC_WRITE,
386  FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
387  OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
388 
389  ni_log(NI_LOG_DEBUG, "%s() device_name: %s", __func__, p_dev);
390  if (INVALID_HANDLE_VALUE == device_handle)
391  {
392  retval = GetLastError();
393  ni_log(NI_LOG_ERROR, "Failed to open %s, retval %d \n", p_dev, retval);
394  } else
395  {
396  ni_log(NI_LOG_DEBUG, "Found NVME Controller at %s \n", p_dev);
397  }
398 
399  return device_handle;
400 #else
401  int retval = -1;
402  ni_device_handle_t fd = NI_INVALID_DEVICE_HANDLE;
403 
404  if (!p_dev)
405  {
406  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
408  }
409 
410  if (p_max_io_size_out != NULL && *p_max_io_size_out == NI_INVALID_IO_SIZE)
411  {
412 #if __linux__
413  *p_max_io_size_out = ni_get_kernel_max_io_size(p_dev);
414 #elif __APPLE__
415  *p_max_io_size_out = MAX_IO_TRANSFER_SIZE;
416 #endif
417  }
418 
419  ni_log(NI_LOG_DEBUG, "%s: opening regular-io enabled %s\n", __func__,
420  p_dev);
421  //O_SYNC is added to ensure that data is written to the card when the pread/pwrite function returns
422  #if __linux__
423  //O_DIRECT is added to ensure that data can be sent directly to the card instead of to cache memory
424  fd = open(p_dev, O_RDWR | O_SYNC | O_DIRECT);
425  #elif __APPLE__
426  //O_DIRECT isn't available, so instead we use F_NOCACHE below
427  fd = open(p_dev, O_RDWR | O_SYNC);
428  #endif
429 
430  if (fd < 0)
431  {
432  char errmsg[NI_ERRNO_LEN] = {0};
434  ni_log(NI_LOG_ERROR, "ERROR: %d %s open() failed on %s\n", NI_ERRNO,
435  errmsg, p_dev);
436  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
437  fd = NI_INVALID_DEVICE_HANDLE;
438  LRETURN;
439  }
440  else if(fd == 0)
441  {
442  //this code is just for the case that we do not initialize all fds to NI_INVALID_DEVICE_HANDLE
443 
444  //if we make sure that all the fds in libxcoder is initialized to NI_INVALID_DEVICE_HANDLE
445  //we should remove this check
446 
447  //we hold the fd = 0, so other threads could not visit these code
448  //thread safe unless other thread close fd=0 accidently
449  ni_log(NI_LOG_ERROR, "open fd = 0 is not as expeceted\n");
450  if(close_fd_zero_atexit == 0)
451  {
452  close_fd_zero_atexit = 1;
453  atexit(close_fd_zero);
454  }
455  else
456  {
457  ni_log(NI_LOG_ERROR, "libxcoder has held the fd=0, but open fd=0 again, maybe fd=0 was closed accidently.");
458  }
459  fd = NI_INVALID_DEVICE_HANDLE;
460  }
461 
462  #if __APPLE__
463  //F_NOCACHE is set to ensure that data can be sent directly to the card instead of to cache memory
464  retval = fcntl(fd, F_NOCACHE, 1);
465  if (retval < 0)
466  {
467  ni_log(NI_LOG_ERROR, "ERROR: fnctl() failed on %s\n", p_dev);
468  ni_log(NI_LOG_ERROR, "ERROR: ni_device_open() failed!\n");
469  close(fd);
470  fd = NI_INVALID_DEVICE_HANDLE;
471  LRETURN;
472  }
473  #endif
474 
475  retval = fstat(fd, &g_nvme_stat);
476  if (retval < 0)
477  {
478  ni_log(NI_LOG_ERROR, "ERROR: fstat() failed on %s\n", p_dev);
479  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
480  close(fd);
481  fd = NI_INVALID_DEVICE_HANDLE;
482  LRETURN;
483  }
484 
485  if (!S_ISCHR(g_nvme_stat.st_mode) && !S_ISBLK(g_nvme_stat.st_mode))
486  {
487  ni_log(NI_LOG_ERROR, "ERROR: %s is not a block or character device\n",
488  p_dev);
489  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
490  close(fd);
491  fd = NI_INVALID_DEVICE_HANDLE;
492  LRETURN;
493  }
494 
495  ni_log(NI_LOG_DEBUG, "%s: success, fd=%d\n", __func__, fd);
496 
497 END:
498 
499  return fd;
500 #endif
501 }
502 
503 /*!*****************************************************************************
504  * \brief Close device and release resources
505  *
506  * \param[in] device_handle Device handle obtained by calling ni_device_open()
507  *
508  * \return NONE
509  *
510  ******************************************************************************/
511 void ni_device_close(ni_device_handle_t device_handle)
512 {
513  if ( NI_INVALID_DEVICE_HANDLE == device_handle )
514  {
515  ni_log(NI_LOG_ERROR, "ERROR %s: null parameter passed %x\n", __func__,
516  device_handle);
517  return;
518  }
519 
520  if(device_handle == 0)
521  {
522  //this code is just for the case that we do not initialize all fds to NI_INVALID_DEVICE_HANDLE
523 
524  //if we make sure that all the fds in libxcoder is initialized to NI_INVALID_DEVICE_HANDLE
525  //we should remove this check
526  ni_log(NI_LOG_ERROR, "%s close fd=0 is not as expected", __func__);
527  return;
528  }
529 
530  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
531 
532 #ifdef _WIN32
533  BOOL retval;
534 
535  ni_log(NI_LOG_DEBUG, "%s(): closing %p\n", __func__, device_handle);
536 
537  retval = CloseHandle(device_handle);
538  if (FALSE == retval)
539  {
541  "ERROR: %s(): closing device device_handle %p failed, error: %d\n",
542  __func__, device_handle, NI_ERRNO);
543  }
544  else
545  {
546  ni_log(NI_LOG_DEBUG, "%s(): device %p closed successfuly\n", __func__,
547  device_handle);
548  }
549 #else
550  int err = 0;
551  ni_log(NI_LOG_DEBUG, "%s(): closing fd %d\n", __func__, device_handle);
552  err = close(device_handle);
553  if (err == -1)
554  {
555  char error_message[100] = {'\0'};
556  char unknown_error_message[20] = {'\0'};
557  ni_sprintf(error_message, 100, "ERROR: %s(): ", __func__);
558  switch (errno)
559  {
560  case EBADF:
561  ni_strcat(error_message, 100, "EBADF\n");
562  break;
563  case EINTR:
564  ni_strcat(error_message, 100, "EINTR\n");
565  break;
566  case EIO:
567  ni_strcat(error_message, 100, "EIO\n");
568  break;
569  default:
570  ni_sprintf(unknown_error_message, 20, "Unknown error %d\n", err);
571  ni_strcat(error_message, 100, unknown_error_message);
572  }
573  char errmsg[NI_ERRNO_LEN] = {0};
575  ni_log(NI_LOG_ERROR, "%s\n", errmsg);
576  ni_log(NI_LOG_ERROR, "%s\n", error_message);
577  }
578 #endif
579  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
580 }
581 
582 #ifndef DEPRECATION_AS_ERROR
583 /*!*****************************************************************************
584  * \brief Query device and return device capability structure
585  * This function had been replaced by ni_device_capability_query2
586  * This function can't be callback in multi thread
587  *
588  * \param[in] device_handle Device handle obtained by calling ni_device_open
589  * \param[in] p_cap Pointer to a caller allocated ni_device_capability_t
590  * struct
591  * \return On success
592  * NI_RETCODE_SUCCESS
593  * On failure
594  * NI_RETCODE_INVALID_PARAM
595  * NI_RETCODE_ERROR_MEM_ALOC
596  * NI_RETCODE_ERROR_NVME_CMD_FAILED
597  ******************************************************************************/
599 {
600  void * p_buffer = NULL;
602  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
603 
604  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
605 
606  if ( (NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_cap) )
607  {
608  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
609  __func__);
610  retval = NI_RETCODE_INVALID_PARAM;
611  LRETURN;
612  }
613 
614  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE),
616  {
617  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer.\n",
618  NI_ERRNO, __func__);
619  retval = NI_RETCODE_ERROR_MEM_ALOC;
620  LRETURN;
621  }
622 
623  memset(p_buffer, 0, NI_NVME_IDENTITY_CMD_DATA_SZ);
624 
625  uint32_t ui32LBA = IDENTIFY_DEVICE_R;
626  if (ni_nvme_send_read_cmd(device_handle, event_handle, p_buffer, NI_NVME_IDENTITY_CMD_DATA_SZ, ui32LBA) < 0)
627  {
629  LRETURN;
630  }
631 
633 
634 END:
635 
636  ni_aligned_free(p_buffer);
637  ni_log(NI_LOG_DEBUG, "%s(): retval: %d\n", __func__, retval);
638 
639  return retval;
640 }
641 #endif
642 
643 /*!*****************************************************************************
644  * \brief Query device and return device capability structure
645  * This function had replaced ni_device_capability_query
646  * This function can be callback with multi thread
647  *
648  * \param[in] device_handle Device handle obtained by calling ni_device_open
649  * \param[in] p_cap Pointer to a caller allocated ni_device_capability_t
650  * struct
651  * \param[in] device_in_ctxt If device is in ctx
652  * \return On success
653  * NI_RETCODE_SUCCESS
654  * On failure
655  * NI_RETCODE_INVALID_PARAM
656  * NI_RETCODE_ERROR_MEM_ALOC
657  * NI_RETCODE_ERROR_NVME_CMD_FAILED
658  ******************************************************************************/
659 ni_retcode_t ni_device_capability_query2(ni_device_handle_t device_handle,
660  ni_device_capability_t *p_cap, bool device_in_ctxt)
661 {
662  void * p_buffer = NULL;
664  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
665 
666  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
667 
668  if ( (NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_cap) )
669  {
670  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
671  __func__);
672  retval = NI_RETCODE_INVALID_PARAM;
673  LRETURN;
674  }
675 
676  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE),
678  {
679  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer.\n",
680  NI_ERRNO, __func__);
681  retval = NI_RETCODE_ERROR_MEM_ALOC;
682  LRETURN;
683  }
684 
685  memset(p_buffer, 0, NI_NVME_IDENTITY_CMD_DATA_SZ);
686 
687  uint32_t ui32LBA = IDENTIFY_DEVICE_R;
688  if (ni_nvme_send_read_cmd(device_handle, event_handle, p_buffer, NI_NVME_IDENTITY_CMD_DATA_SZ, ui32LBA) < 0)
689  {
691  LRETURN;
692  }
693 
694  ni_populate_device_capability_struct(p_cap, p_buffer, device_handle, device_in_ctxt);
695 
696 END:
697 
698  ni_aligned_free(p_buffer);
699  ni_log(NI_LOG_DEBUG, "%s(): retval: %d\n", __func__, retval);
700 
701  return retval;
702 }
703 
704 /*!*****************************************************************************
705  * \brief Open a new device session depending on the device_type parameter
706  * If device_type is NI_DEVICE_TYPE_DECODER opens decoding session
707  * If device_type is NI_DEVICE_TYPE_ENCODER opens encoding session
708  * If device_type is NI_DEVICE_TYPE_SCALER opens scaling session
709  *
710  * \param[in] p_ctx Pointer to a caller allocated
711  * ni_session_context_t struct
712  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER,
713  * or NI_DEVICE_TYPE_SCALER
714  * \return On success
715  * NI_RETCODE_SUCCESS
716  * On failure
717  * NI_RETCODE_INVALID_PARAM
718  * NI_RETCODE_ERROR_MEM_ALOC
719  * NI_RETCODE_ERROR_NVME_CMD_FAILED
720  * NI_RETCODE_ERROR_INVALID_SESSION
721  ******************************************************************************/
723  ni_device_type_t device_type)
724 {
726  ni_device_pool_t *p_device_pool = NULL;
727  ni_device_context_t *p_device_context = NULL;
728  ni_device_info_t *p_dev_info = NULL;
729  ni_device_info_t dev_info = { 0 };
731  ni_device_context_t *rsrc_ctx = NULL;
732  int i = 0;
733  int rc = 0;
734  int num_coders = 0;
735  bool use_model_load = true;
736  int least_load = 0;
737  int curr_load = 0;
738  int guid = -1;
739  uint32_t num_sw_instances = 0;
740  uint32_t pixel_load = 0xFFFFFFFFU;
741  int user_handles = false;
742  ni_lock_handle_t lock = NI_INVALID_LOCK_HANDLE;
743  ni_device_handle_t handle = NI_INVALID_DEVICE_HANDLE;
744  ni_device_handle_t handle1 = NI_INVALID_DEVICE_HANDLE;
745  // For none nvme block device we just need to pass in dummy
746  uint32_t dummy_io_size = 0;
747  ni_session_context_t p_session_context = {0};
748  ni_device_type_t query_type = device_type;
749 
750  if (!p_ctx)
751  {
752  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
753  __func__);
755  }
756 
757 #ifdef _WIN32
758  if (!IsUserAnAdmin())
759  {
760  ni_log(NI_LOG_ERROR, "ERROR: %s must be in admin priviledge\n", __func__);
762  }
763 #endif
764 
765  ni_pthread_mutex_lock(&p_ctx->mutex);
767 
768  ni_device_session_context_init(&p_session_context);
769 
770  if (NI_INVALID_SESSION_ID != p_ctx->session_id)
771  {
772  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: trying to overwrite existing session, "
773  "device_type %d, session id %d\n",
774  device_type, p_ctx->session_id);
775  retval = NI_RETCODE_INVALID_PARAM;
776  LRETURN;
777  }
778 
779  p_ctx->p_hdr_buf = NULL;
780  p_ctx->hdr_buf_size = 0;
781 
782  p_ctx->roi_side_data_size = p_ctx->nb_rois = 0;
783  p_ctx->av_rois = NULL;
784  p_ctx->roi_map = NULL;
785  p_ctx->avc_roi_map = NULL;
786  p_ctx->hevc_roi_map = NULL;
787  p_ctx->hevc_sub_ctu_roi_buf = NULL;
788  p_ctx->p_master_display_meta_data = NULL;
789 
790  p_ctx->enc_change_params = NULL;
791 
792  p_ctx->target_bitrate = -1;
793  p_ctx->force_idr_frame = 0;
795  p_ctx->ltr_to_set.use_long_term_ref = 0;
796  p_ctx->ltr_interval = -1;
797  p_ctx->ltr_frame_ref_invalid = -1;
798  p_ctx->framerate.framerate_num = 0;
799  p_ctx->framerate.framerate_denom = 0;
800  p_ctx->vui.colorDescPresent = 0;
801  p_ctx->vui.colorPrimaries = 2; // 2 is unspecified
802  p_ctx->vui.colorTrc = 2; // 2 is unspecified
803  p_ctx->vui.colorSpace = 2; // 2 is unspecified
804  p_ctx->vui.aspectRatioWidth = 0;
805  p_ctx->vui.aspectRatioHeight = 0;
806  p_ctx->vui.videoFullRange = 0;
807  p_ctx->max_frame_size = 0;
808  p_ctx->reconfig_crf = -1;
809  p_ctx->reconfig_crf_decimal = 0;
810  p_ctx->reconfig_vbv_buffer_size = 0;
811  p_ctx->reconfig_vbv_max_rate = 0;
812  p_ctx->last_gop_size = 0;
813  p_ctx->initial_frame_delay = 0;
814  p_ctx->current_frame_delay = 0;
815  p_ctx->max_frame_delay = 0;
816  p_ctx->av1_pkt_num = 0;
817  p_ctx->pool_type = NI_POOL_TYPE_NONE;
818  p_ctx->force_low_delay = false;
819  p_ctx->force_low_delay_cnt = 0;
820  p_ctx->pkt_delay_cnt = 0;
821  p_ctx->reconfig_intra_period = -1;
822  p_ctx->reconfig_slice_arg = 0;
823 
824  memset(p_ctx->input_frame_fifo, 0, sizeof(ni_input_frame) * 120);
825  for (i = 0; i < 120; i++)
826  {
827  p_ctx->input_frame_fifo[i].usable = -1;
828  }
829 
830  handle = p_ctx->device_handle;
831  handle1 = p_ctx->blk_io_handle;
832 
833  p_device_pool = ni_rsrc_get_device_pool();
834 
835  if (!p_device_pool)
836  {
837  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Error calling ni_rsrc_get_device_pool()\n");
839  LRETURN;
840  }
841 
842  ni_log2(p_ctx, NI_LOG_DEBUG,
843  "%s: device type %d hw_id %d blk_dev_name: %s dev_xcoder_name: %s.\n",
844  __func__, device_type, p_ctx->hw_id, p_ctx->blk_dev_name,
845  p_ctx->dev_xcoder_name);
846 
847  if (device_type == NI_DEVICE_TYPE_UPLOAD)
848  {
849  //uploader shares resources with encoder to query as encoder for load info
850  query_type = NI_DEVICE_TYPE_ENCODER;
851  }
852 
853  // if caller requested device by block device name, try to find its GUID and
854  // use it to override the hw_id which is the passed in device GUID
855  if (0 != strcmp(p_ctx->blk_dev_name, ""))
856  {
857  int tmp_guid_id;
858  tmp_guid_id =
859  ni_rsrc_get_device_by_block_name(p_ctx->blk_dev_name, device_type);
860  if (tmp_guid_id != NI_RETCODE_FAILURE)
861  {
862  ni_log2(p_ctx, NI_LOG_DEBUG,
863  "%s: block device name %s type %d guid %d is to "
864  "override passed in guid %d\n",
865  __func__, p_ctx->blk_dev_name, device_type, tmp_guid_id,
866  p_ctx->hw_id);
867  p_ctx->hw_id = tmp_guid_id;
868  } else
869  {
870  ni_log(NI_LOG_INFO, "%s: block device name %s type %d NOT found ..\n",
871  __func__, p_ctx->blk_dev_name, device_type);
873  LRETURN;
874  }
875  }
876 
877  // User did not pass in any handle, so we create it for them
878  if ((handle1 == NI_INVALID_DEVICE_HANDLE) && (handle == NI_INVALID_DEVICE_HANDLE))
879  {
880  if (p_ctx->hw_id >=0) // User selected the encder/ decoder number
881  {
882  if ((rsrc_ctx = ni_rsrc_allocate_simple_direct(device_type, p_ctx->hw_id)) == NULL)
883  {
884 
885  ni_log2(p_ctx, NI_LOG_ERROR, "Error XCoder resource allocation: inst %d\n",
886  p_ctx->hw_id);
888  LRETURN;
889  }
890  ni_log2(p_ctx, NI_LOG_DEBUG, "device %p\n", rsrc_ctx);
891  // Now the device name is in the rsrc_ctx, we open this device to get the file handles
892 
893 #ifdef _WIN32
894  if ((handle = ni_device_open(rsrc_ctx->p_device_info->blk_name,
895  &dummy_io_size)) == NI_INVALID_DEVICE_HANDLE)
896  {
897  ni_rsrc_free_device_context(rsrc_ctx);
899  LRETURN;
900  } else
901  {
902  user_handles = true;
903  p_ctx->device_handle = handle;
904  p_ctx->blk_io_handle = handle;
905  p_ctx->max_nvme_io_size = dummy_io_size;
906  handle1 = handle;
909  ni_rsrc_free_device_context(rsrc_ctx);
910  }
911 #else
912  //The original design (code below) is to open char and block device file separately. And the ffmpeg will close the device twice.
913  //However, in I/O version, char device can't be opened. For compatibility, and to avoid errors, open the block device twice.
914  if (((handle = ni_device_open(rsrc_ctx->p_device_info->dev_name, &dummy_io_size)) == NI_INVALID_DEVICE_HANDLE) ||
915  ((handle1 = ni_device_open(rsrc_ctx->p_device_info->dev_name, &p_ctx->max_nvme_io_size)) == NI_INVALID_DEVICE_HANDLE))
916  {
917  ni_rsrc_free_device_context(rsrc_ctx);
919  LRETURN;
920  } else
921  {
922  user_handles = true;
923  p_ctx->device_handle = handle;
924  p_ctx->blk_io_handle = handle1;
925  // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker): Couldn't determine why it will be NULL.
928 
929  ni_rsrc_free_device_context(rsrc_ctx);
930  }
931 #endif
932  } else
933  {
934  int tmp_id = -1;
935 
936  // Decide on model load or real load to be used, based on name passed
937  // in from p_ctx->dev_xcoder_name; after checking it will be used to
938  // store device file name.
939  if (0 == strcmp(p_ctx->dev_xcoder_name, NI_BEST_REAL_LOAD_STR))
940  {
941  use_model_load = false;
942  } else if (0 != strcmp(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR))
943  {
944  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s unrecognized option: %s.\n",
945  __func__, p_ctx->dev_xcoder_name);
946  retval = NI_RETCODE_INVALID_PARAM;
947  LRETURN;
948  }
949 
950  if (ni_rsrc_lock_and_open(query_type, &lock) != NI_RETCODE_SUCCESS)
951  {
953  LRETURN;
954  }
955 
956  // We need to query through all the boards to confirm the least load.
957 
958  if (IS_XCODER_DEVICE_TYPE(query_type))
959  {
960  num_coders = p_device_pool->p_device_queue->xcoder_cnt[query_type];
961  } else
962  {
963  retval = NI_RETCODE_INVALID_PARAM;
964  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
965  {
967  LRETURN;
968  }
969  LRETURN;
970  }
971 
972  for (i = 0; i < num_coders; i++)
973  {
974  tmp_id = p_device_pool->p_device_queue->xcoders[query_type][i];
975  p_device_context = ni_rsrc_get_device_context(query_type, tmp_id);
976 
977  if (p_device_context == NULL)
978  {
979  ni_log2(p_ctx, NI_LOG_ERROR,
980  "ERROR: %s() ni_rsrc_get_device_context() failed\n",
981  __func__);
982  continue;
983  }
984 
985  // Code is included in the for loop. In the loop, the device is
986  // just opened once, and it will be closed once too.
987  p_session_context.blk_io_handle = ni_device_open(
988  p_device_context->p_device_info->dev_name, &dummy_io_size);
989  p_session_context.device_handle = p_session_context.blk_io_handle;
990 
991  if (NI_INVALID_DEVICE_HANDLE == p_session_context.device_handle)
992  {
993  ni_log2(p_ctx, NI_LOG_ERROR, "Error open device");
994  ni_rsrc_free_device_context(p_device_context);
995  continue;
996  }
997 
998  p_session_context.hw_id = p_device_context->p_device_info->hw_id;
999  rc = ni_device_session_query(&p_session_context, query_type);
1000  if (NI_INVALID_DEVICE_HANDLE != p_session_context.device_handle)
1001  {
1002  ni_device_close(p_session_context.device_handle);
1003  }
1004 
1005  if (NI_RETCODE_SUCCESS != rc)
1006  {
1007  ni_log2(p_ctx, NI_LOG_ERROR, "Error query %s %s.%d\n",
1008  g_device_type_str[query_type],
1009  p_device_context->p_device_info->dev_name,
1010  p_device_context->p_device_info->hw_id);
1011  ni_rsrc_free_device_context(p_device_context);
1012  continue;
1013  }
1014  ni_rsrc_update_record(p_device_context, &p_session_context);
1015  p_dev_info = p_device_context->p_device_info;
1016 
1017  // here we select the best load
1018  // for decoder/encoder: check the model_load/real_load
1019  // for hwuploader: check directly hwupload pixel load in query result
1020  if (NI_DEVICE_TYPE_UPLOAD == device_type)
1021  {
1022  if (lower_pixel_rate(&p_session_context.load_query, pixel_load))
1023  {
1024  guid = tmp_id;
1025  pixel_load = p_session_context.load_query.total_pixel_load;
1026  memcpy(&dev_info, p_dev_info, sizeof(ni_device_info_t));
1027  }
1028  } else
1029  {
1030  if (use_model_load)
1031  {
1032  curr_load = p_dev_info->model_load;
1033  } else
1034  {
1035  curr_load = p_dev_info->load;
1036  }
1037 
1038  if (i == 0 || curr_load < least_load ||
1039  (curr_load == least_load &&
1040  p_dev_info->active_num_inst < num_sw_instances))
1041  {
1042  guid = tmp_id;
1043  least_load = curr_load;
1044  num_sw_instances = p_dev_info->active_num_inst;
1045  memcpy(&dev_info, p_dev_info, sizeof(ni_device_info_t));
1046  }
1047  }
1048  ni_rsrc_free_device_context(p_device_context);
1049  }
1050 
1051 #ifdef _WIN32
1052  // Now we have the device info that has the least load of the FW
1053  // we open this device and assign the FD
1054  if ((handle = ni_device_open(dev_info.blk_name, &dummy_io_size)) ==
1055  NI_INVALID_DEVICE_HANDLE)
1056  {
1058  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1059  {
1061  LRETURN;
1062  }
1063  LRETURN;
1064  } else
1065  {
1066  p_ctx->device_handle = handle;
1067  p_ctx->blk_io_handle = handle;
1068  p_ctx->max_nvme_io_size = dummy_io_size;
1069  handle1 = handle;
1070  p_ctx->hw_id = guid;
1073  }
1074 #else
1075  //The original design (code below) is to open char and block device file separately. And the ffmpeg will close the device twice.
1076  //However, in I/O version, char device can't be opened. For compatibility, and to avoid errors, open the block device twice.
1077  if (((handle = ni_device_open(dev_info.dev_name, &dummy_io_size)) == NI_INVALID_DEVICE_HANDLE) ||
1078  ((handle1 = ni_device_open(dev_info.dev_name, &p_ctx->max_nvme_io_size)) == NI_INVALID_DEVICE_HANDLE))
1079  {
1081  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1082  {
1084  LRETURN;
1085  }
1086  LRETURN;
1087  }
1088  else
1089  {
1090  p_ctx->device_handle = handle;
1091  p_ctx->blk_io_handle = handle1;
1092  p_ctx->hw_id = guid;
1095  }
1096 #endif
1097  }
1098  }
1099  // user passed in the handle, but one of them is invalid, this is error case so we return error
1100  else if((handle1 == NI_INVALID_DEVICE_HANDLE) || (handle == NI_INVALID_DEVICE_HANDLE))
1101  {
1103  LRETURN;
1104  }
1105  // User passed in both handles, so we do not need to allocate for it
1106  else
1107  {
1108  user_handles = true;
1109  }
1110 
1111  ni_log2(p_ctx, NI_LOG_DEBUG,
1112  "Finish open the session dev:%s guid:%d handle:%p handle1:%p\n",
1113  p_ctx->dev_xcoder_name, p_ctx->hw_id,
1114  p_ctx->device_handle, p_ctx->blk_io_handle);
1115 
1116  // get FW API version
1117  p_device_context = ni_rsrc_get_device_context(device_type, p_ctx->hw_id);
1118  if (p_device_context == NULL)
1119  {
1120  ni_log2(p_ctx, NI_LOG_ERROR,
1121  "ERROR: %s() ni_rsrc_get_device_context() failed\n",
1122  __func__);
1123  if (user_handles != true)
1124  {
1125  if(ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1126  {
1128  LRETURN;
1129  }
1130  }
1132  LRETURN;
1133  }
1134 
1135  if (!(strcmp(p_ctx->dev_xcoder_name, "")) || !(strcmp(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR)) ||
1136  !(strcmp(p_ctx->dev_xcoder_name, NI_BEST_REAL_LOAD_STR)))
1137  {
1139  }
1140 
1141  memcpy(p_ctx->fw_rev , p_device_context->p_device_info->fw_rev, 8);
1142 
1143  ni_rsrc_free_device_context(p_device_context);
1144 
1145  retval = ni_device_get_ddr_configuration(p_ctx);
1146  if (retval != NI_RETCODE_SUCCESS)
1147  {
1148  ni_log2(p_ctx, NI_LOG_ERROR,
1149  "ERROR: %s() cannot retrieve DDR configuration\n",
1150  __func__);
1151  if (user_handles != true)
1152  {
1153  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1154  {
1156  LRETURN;
1157  }
1158  }
1159  LRETURN;
1160  }
1161 
1162  if (p_ctx->keep_alive_timeout == 0)
1163  {
1164  ni_log2(p_ctx, NI_LOG_ERROR,
1165  "ERROR: %s() keep_alive_timeout was 0, should be between 1-100. "
1166  "Setting to default of %u\n",
1167  __func__, NI_DEFAULT_KEEP_ALIVE_TIMEOUT);
1169  }
1170  switch (device_type)
1171  {
1173  {
1174  retval = ni_decoder_session_open(p_ctx);
1175  if (user_handles != true)
1176  {
1177  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1178  {
1180  LRETURN;
1181  }
1182  }
1183  // send keep alive signal thread
1184  if (NI_RETCODE_SUCCESS != retval)
1185  {
1186  LRETURN;
1187  }
1188  break;
1189  }
1191  {
1192 #ifndef _WIN32
1193  // p2p is not supported on Windows, so skip following assignments.
1194  ni_xcoder_params_t *p_enc_params;
1195 
1196  p_enc_params = p_ctx->p_session_config;
1197 
1198  if (p_enc_params && p_enc_params->hwframes &&
1199  p_enc_params->p_first_frame)
1200  {
1201  niFrameSurface1_t *pSurface;
1202  pSurface =
1203  (niFrameSurface1_t *)p_enc_params->p_first_frame->p_data[3];
1204  p_ctx->sender_handle =
1205  (ni_device_handle_t)(int64_t)pSurface->device_handle;
1206  p_enc_params->rootBufId = pSurface->ui16FrameIdx;
1207 
1208  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: sender_handle and rootBufId %d set\n",
1209  __func__, p_enc_params->rootBufId);
1210  }
1211 #endif
1212 
1213  retval = ni_encoder_session_open(p_ctx);
1214  if (user_handles != true)
1215  {
1216  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1217  {
1219  LRETURN;
1220  }
1221  }
1222  // send keep alive signal thread
1223  if (NI_RETCODE_SUCCESS != retval)
1224  {
1225  LRETURN;
1226  }
1227  break;
1228  }
1229  case NI_DEVICE_TYPE_UPLOAD:
1230  {
1231  retval = ni_uploader_session_open(p_ctx);
1232  if (user_handles != true)
1233  {
1234  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1235  {
1237  LRETURN;
1238  }
1239  }
1240  // send keep alive signal thread
1241  if (NI_RETCODE_SUCCESS != retval)
1242  {
1243  LRETURN;
1244  }
1245  break;
1246  }
1247  case NI_DEVICE_TYPE_SCALER:
1248  {
1249  retval = ni_scaler_session_open(p_ctx);
1250  if (user_handles != true)
1251  {
1252  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1253  {
1255  LRETURN;
1256  }
1257  }
1258  // send keep alive signal thread
1259  if (NI_RETCODE_SUCCESS != retval)
1260  {
1261  LRETURN;
1262  }
1263  break;
1264  }
1265  case NI_DEVICE_TYPE_AI:
1266  {
1267  retval = ni_ai_session_open(p_ctx);
1268  if (user_handles != true)
1269  {
1270  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1271  {
1273  LRETURN;
1274  }
1275  }
1276  // send keep alive signal thread
1277  if (NI_RETCODE_SUCCESS != retval)
1278  {
1279  LRETURN;
1280  }
1281  break;
1282  }
1283  default:
1284  {
1285  if (user_handles != true)
1286  {
1287  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1288  {
1290  LRETURN;
1291  }
1292  }
1293  retval = NI_RETCODE_INVALID_PARAM;
1294  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1295  __func__, device_type);
1296  LRETURN;
1297  }
1298  }
1299 
1301  if (!p_ctx->keep_alive_thread_args)
1302  {
1303  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: thread_args allocation failed!\n");
1304  ni_device_session_close(p_ctx, 0, device_type);
1305  retval = NI_RETCODE_ERROR_MEM_ALOC;
1306  LRETURN;
1307  }
1308 
1309  p_ctx->keep_alive_thread_args->session_id = p_ctx->session_id;
1311  p_ctx->keep_alive_thread_args->device_type = device_type;
1314  p_ctx->keep_alive_thread_args->close_thread = false;
1317  p_ctx->keep_alive_thread_args->p_mutex = &p_ctx->mutex;
1318  p_ctx->keep_alive_thread_args->hw_id = p_ctx->hw_id;
1319  p_ctx->last_access_time = ni_gettime_ns();
1320 
1322  sysconf(_SC_PAGESIZE), NI_DATA_BUFFER_LEN))
1323  {
1324  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: keep alive p_buffer allocation failed!\n");
1325  ni_device_session_close(p_ctx, 0, device_type);
1326  retval = NI_RETCODE_ERROR_MEM_ALOC;
1327  LRETURN;
1328  }
1330 
1331  if (0 !=
1332  ni_pthread_create(&p_ctx->keep_alive_thread, NULL,
1334  (void *)p_ctx->keep_alive_thread_args))
1335  {
1336  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to create keep alive thread\n");
1337  p_ctx->keep_alive_thread = (ni_pthread_t){0};
1340  ni_device_session_close(p_ctx, 0, device_type);
1341  retval = NI_RETCODE_ERROR_MEM_ALOC;
1342  LRETURN;
1343  }
1344  ni_log2(p_ctx, NI_LOG_DEBUG, "Enabled keep alive thread\n");
1345 
1346  // allocate memory for encoder change data to be reused
1347  p_ctx->enc_change_params = calloc(1, sizeof(ni_encoder_change_params_t));
1348  if (!p_ctx->enc_change_params)
1349  {
1350  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: enc_change_params allocation failed!\n");
1351  ni_device_session_close(p_ctx, 0, device_type);
1352  retval = NI_RETCODE_ERROR_MEM_ALOC;
1353  }
1354 
1355 END:
1356  ni_device_session_context_clear(&p_session_context);
1357 
1358  if (p_device_pool)
1359  {
1360  ni_rsrc_free_device_pool(p_device_pool);
1361  p_device_pool = NULL;
1362  }
1363 
1365 
1366  ni_pthread_mutex_unlock(&p_ctx->mutex);
1367 
1368  return retval;
1369 }
1370 
1371 /*!*****************************************************************************
1372  * \brief Close device session that was previously opened by calling
1373  * ni_device_session_open()
1374  * If device_type is NI_DEVICE_TYPE_DECODER closes decoding session
1375  * If device_type is NI_DEVICE_TYPE_ENCODER closes encoding session
1376  * If device_type is NI_DEVICE_TYPE_SCALER closes scaling session
1377  *
1378  * \param[in] p_ctx Pointer to a caller allocated
1379  * ni_session_context_t struct
1380  * \param[in] eos_received Flag indicating if End Of Stream indicator was
1381  * received
1382  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER,
1383  * or NI_DEVICE_TYPE_SCALER
1384  * \return On success
1385  * NI_RETCODE_SUCCESS
1386  * On failure
1387  * NI_RETCODE_INVALID_PARAM
1388  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1389  * NI_RETCODE_ERROR_INVALID_SESSION
1390  ******************************************************************************/
1392  int eos_recieved,
1393  ni_device_type_t device_type)
1394 {
1395  int ret;
1397 
1398  if (!p_ctx)
1399  {
1400  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1401  __func__);
1402  return NI_RETCODE_INVALID_PARAM;
1403  }
1404 
1405  ni_pthread_mutex_lock(&p_ctx->mutex);
1407  ni_pthread_mutex_unlock(&p_ctx->mutex);
1408 
1409 #ifdef _WIN32
1410  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args)
1411 #else
1412  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args)
1413 #endif
1414  {
1415  p_ctx->keep_alive_thread_args->close_thread = true;
1416  ret = ni_pthread_join(p_ctx->keep_alive_thread, NULL);
1417  if (ret)
1418  {
1419  ni_log2(p_ctx, NI_LOG_ERROR,
1420  "join keep alive thread fail! : sid %u ret %d\n",
1421  p_ctx->session_id, ret);
1422  }
1425  } else
1426  {
1427  ni_log2(p_ctx, NI_LOG_ERROR, "invalid keep alive thread: %u\n",
1428  p_ctx->session_id);
1429  }
1430 
1431  switch (device_type)
1432  {
1434  {
1435  retval = ni_decoder_session_close(p_ctx, eos_recieved);
1436  break;
1437  }
1438  case NI_DEVICE_TYPE_UPLOAD:
1439  {
1441  // fall through
1442  }
1444  {
1445  retval = ni_encoder_session_close(p_ctx, eos_recieved);
1446  break;
1447  }
1448  case NI_DEVICE_TYPE_SCALER:
1449  {
1450  retval = ni_scaler_session_close(p_ctx, eos_recieved);
1451  break;
1452  }
1453  case NI_DEVICE_TYPE_AI:
1454  {
1455  retval = ni_ai_session_close(p_ctx, eos_recieved);
1456  break;
1457  }
1458  default:
1459  {
1460  retval = NI_RETCODE_INVALID_PARAM;
1461  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1462  __func__, device_type);
1463  break;
1464  }
1465  }
1466 
1467  ni_pthread_mutex_lock(&p_ctx->mutex);
1468  // need set invalid after closed. May cause open invalid parameters.
1470 
1471  ni_memfree(p_ctx->p_hdr_buf);
1472  ni_memfree(p_ctx->av_rois);
1473  ni_memfree(p_ctx->roi_map);
1474  ni_memfree(p_ctx->avc_roi_map);
1475  ni_memfree(p_ctx->hevc_roi_map);
1478  ni_memfree(p_ctx->enc_change_params);
1479  p_ctx->hdr_buf_size = 0;
1480  p_ctx->roi_side_data_size = 0;
1481  p_ctx->nb_rois = 0;
1482  p_ctx->target_bitrate = -1;
1483  p_ctx->force_idr_frame = 0;
1485  p_ctx->ltr_to_set.use_long_term_ref = 0;
1486  p_ctx->ltr_interval = -1;
1487  p_ctx->ltr_frame_ref_invalid = -1;
1488  p_ctx->max_frame_size = 0;
1489  p_ctx->reconfig_crf = -1;
1490  p_ctx->reconfig_crf_decimal = 0;
1491  p_ctx->reconfig_vbv_buffer_size = 0;
1492  p_ctx->reconfig_vbv_max_rate = 0;
1493  p_ctx->last_gop_size = 0;
1494  p_ctx->initial_frame_delay = 0;
1495  p_ctx->current_frame_delay = 0;
1496  p_ctx->max_frame_delay = 0;
1497  p_ctx->av1_pkt_num = 0;
1498  p_ctx->reconfig_intra_period = -1;
1499  p_ctx->reconfig_slice_arg = 0;
1500 
1502  ni_pthread_mutex_unlock(&p_ctx->mutex);
1503 
1504  return retval;
1505 }
1506 
1507 /*!*****************************************************************************
1508  * \brief Send a flush command to the device
1509  * If device_type is NI_DEVICE_TYPE_DECODER sends EOS command to
1510  * decoder
1511  * If device_type is NI_DEVICE_TYPE_ENCODER sends EOS command to
1512  * encoder
1513  *
1514  * \param[in] p_ctx Pointer to a caller allocated
1515  * ni_session_context_t struct
1516  * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
1517  * \return On success
1518  * NI_RETCODE_SUCCESS
1519  * On failure
1520  * NI_RETCODE_INVALID_PARAM
1521  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1522  * NI_RETCODE_ERROR_INVALID_SESSION
1523  ******************************************************************************/
1525 {
1527  if (!p_ctx)
1528  {
1529  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1530  __func__);
1531  return NI_RETCODE_INVALID_PARAM;
1532  }
1533 
1534  ni_pthread_mutex_lock(&p_ctx->mutex);
1536 
1537  switch (device_type)
1538  {
1540  {
1541  retval = ni_decoder_session_send_eos(p_ctx);
1542  break;
1543  }
1545  {
1546  retval = ni_encoder_session_send_eos(p_ctx);
1547  break;
1548  }
1549  default:
1550  {
1551  retval = NI_RETCODE_INVALID_PARAM;
1552  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1553  __func__, device_type);
1554  break;
1555  }
1556  }
1557  p_ctx->ready_to_close = (NI_RETCODE_SUCCESS == retval);
1559  ni_pthread_mutex_unlock(&p_ctx->mutex);
1560  return retval;
1561 }
1562 
1563 /*!*****************************************************************************
1564  * \brief Save a stream's headers in a decoder session that can be used later
1565  * for continuous decoding from the same source.
1566  *
1567  * \param[in] p_ctx Pointer to a caller allocated
1568  * ni_session_context_t struct
1569  * \param[in] hdr_data Pointer to header data
1570  * \param[in] hdr_size Size of header data in bytes
1571  * \return On success
1572  * NI_RETCODE_SUCCESS
1573  * On failure
1574  * NI_RETCODE_INVALID_PARAM
1575  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1576  * NI_RETCODE_ERROR_INVALID_SESSION
1577  ******************************************************************************/
1579  uint8_t *hdr_data,
1580  uint8_t hdr_size)
1581 {
1583 
1584  if (!p_ctx)
1585  {
1586  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s p_ctx null, return\n", __func__);
1587  return NI_RETCODE_INVALID_PARAM;
1588  }
1589 
1590  if (!hdr_data)
1591  {
1592  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s hdr_data null, return\n", __func__);
1593  return NI_RETCODE_INVALID_PARAM;
1594  } else if (p_ctx->p_hdr_buf && p_ctx->hdr_buf_size == hdr_size &&
1595  0 == memcmp(p_ctx->p_hdr_buf, hdr_data, hdr_size))
1596  {
1597  // no change from the saved headers, success !
1598  return retval;
1599  }
1600 
1601  // update the saved header data
1602  free(p_ctx->p_hdr_buf);
1603  p_ctx->hdr_buf_size = 0;
1604  p_ctx->p_hdr_buf = malloc(hdr_size);
1605  if (p_ctx->p_hdr_buf)
1606  {
1607  memcpy(p_ctx->p_hdr_buf, hdr_data, hdr_size);
1608  p_ctx->hdr_buf_size = hdr_size;
1609  ni_log2(p_ctx, NI_LOG_DEBUG, "%s saved hdr size %u\n", __func__,
1610  p_ctx->hdr_buf_size);
1611  } else
1612  {
1614  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s no memory.\n", __func__);
1615  }
1616  return retval;
1617 }
1618 
1619 /*!*****************************************************************************
1620  * \brief Flush a decoder session to get ready to continue decoding.
1621  * Note: this is different from ni_device_session_flush in that it closes the
1622  * current decode session and opens a new one for continuous decoding.
1623  *
1624  * \param[in] p_ctx Pointer to a caller allocated
1625  * ni_session_context_t struct
1626  * \return On success
1627  * NI_RETCODE_SUCCESS
1628  * On failure
1629  * NI_RETCODE_INVALID_PARAM
1630  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1631  * NI_RETCODE_ERROR_INVALID_SESSION
1632  ******************************************************************************/
1634 {
1636 
1637  if (!p_ctx)
1638  {
1639  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s ctx null, return\n", __func__);
1640  return NI_RETCODE_INVALID_PARAM;
1641  }
1642  ni_pthread_mutex_lock(&p_ctx->mutex);
1643  retval = ni_decoder_session_flush(p_ctx);
1644  if (NI_RETCODE_SUCCESS == retval) {
1645  p_ctx->ready_to_close = 0;
1646  }
1647  ni_pthread_mutex_unlock(&p_ctx->mutex);
1648  return retval;
1649 }
1650 
1651 /*!*****************************************************************************
1652  * \brief Sends data to the device
1653  * If device_type is NI_DEVICE_TYPE_DECODER sends data packet to
1654  * decoder
1655  * If device_type is NI_DEVICE_TYPE_ENCODER sends data frame to encoder
1656  * If device_type is NI_DEVICE_TYPE_AI sends data frame to ai engine
1657  *
1658  * \param[in] p_ctx Pointer to a caller allocated
1659  * ni_session_context_t struct
1660  * \param[in] p_data Pointer to a caller allocated
1661  * ni_session_data_io_t struct which contains either a
1662  * ni_frame_t data frame or ni_packet_t data packet to
1663  * send
1664  * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER or
1665  * NI_DEVICE_TYPE_AI
1666  * If NI_DEVICE_TYPE_DECODER is specified, it is
1667  * expected that the ni_packet_t struct inside the
1668  * p_data pointer contains data to send.
1669  * If NI_DEVICE_TYPE_ENCODER or NI_DEVICE_TYPE_AI is
1670  * specified, it is expected that the ni_frame_t
1671  * struct inside the p_data pointer contains data to
1672  * send.
1673  * \return On success
1674  * Total number of bytes written
1675  * On failure
1676  * NI_RETCODE_INVALID_PARAM
1677  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1678  * NI_RETCODE_ERROR_INVALID_SESSION
1679  ******************************************************************************/
1681 {
1683 
1684  if (!p_ctx || !p_data)
1685  {
1686  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1687  __func__);
1688  return NI_RETCODE_INVALID_PARAM;
1689  }
1690  // Here check if keep alive thread is closed.
1691 #ifdef _WIN32
1692  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
1694 #else
1695  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
1697 #endif
1698  {
1699  ni_log2(p_ctx, NI_LOG_ERROR,
1700  "ERROR: %s() keep alive thread has been closed, "
1701  "hw:%d, session:%d\n",
1702  __func__, p_ctx->hw_id, p_ctx->session_id);
1704  }
1705 
1706  ni_pthread_mutex_lock(&p_ctx->mutex);
1707  // In close state, let the close process execute first.
1708  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
1709  {
1710  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
1711  ni_pthread_mutex_unlock(&p_ctx->mutex);
1712  ni_usleep(100);
1714  }
1716  ni_pthread_mutex_unlock(&p_ctx->mutex);
1717 
1718  switch (device_type)
1719  {
1721  {
1722  retval = ni_decoder_session_write(p_ctx, &(p_data->data.packet));
1723  break;
1724  }
1726  {
1727  retval = ni_encoder_session_write(p_ctx, &(p_data->data.frame));
1728  break;
1729  }
1730  case NI_DEVICE_TYPE_AI:
1731  {
1732  retval = ni_ai_session_write(p_ctx, &(p_data->data.frame));
1733  break;
1734  }
1735  default:
1736  {
1737  retval = NI_RETCODE_INVALID_PARAM;
1738  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1739  __func__, device_type);
1740  break;
1741  }
1742  }
1743 
1744  ni_pthread_mutex_lock(&p_ctx->mutex);
1746  ni_pthread_mutex_unlock(&p_ctx->mutex);
1747  return retval;
1748 }
1749 
1750 /*!*****************************************************************************
1751  * \brief Read data from the device
1752  * If device_type is NI_DEVICE_TYPE_DECODER reads data packet from
1753  * decoder
1754  * If device_type is NI_DEVICE_TYPE_ENCODER reads data frame from
1755  * encoder
1756  * If device_type is NI_DEVICE_TYPE_AI reads data frame from AI engine
1757  *
1758  * \param[in] p_ctx Pointer to a caller allocated
1759  * ni_session_context_t struct
1760  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
1761  * struct which contains either a ni_frame_t data frame
1762  * or ni_packet_t data packet to send
1763  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER, or
1764  * NI_DEVICE_TYPE_SCALER
1765  * If NI_DEVICE_TYPE_DECODER is specified, data that
1766  * was read will be placed into ni_frame_t struct
1767  * inside the p_data pointer
1768  * If NI_DEVICE_TYPE_ENCODER is specified, data that
1769  * was read will be placed into ni_packet_t struct
1770  * inside the p_data pointer
1771  * If NI_DEVICE_TYPE_AI is specified, data that was
1772  * read will be placed into ni_frame_t struct inside
1773  * the p_data pointer
1774  * \return On success
1775  * Total number of bytes read
1776  * On failure
1777  * NI_RETCODE_INVALID_PARAM
1778  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1779  * NI_RETCODE_ERROR_INVALID_SESSION
1780  ******************************************************************************/
1782 {
1784  if ((!p_ctx) || (!p_data))
1785  {
1786  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1787  __func__);
1788  return NI_RETCODE_INVALID_PARAM;
1789  }
1790 
1791  // Here check if keep alive thread is closed.
1792 #ifdef _WIN32
1793  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
1795 #else
1796  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
1798 #endif
1799  {
1800  ni_log2(p_ctx, NI_LOG_ERROR,
1801  "ERROR: %s() keep alive thread has been closed, "
1802  "hw:%d, session:%d\n",
1803  __func__, p_ctx->hw_id, p_ctx->session_id);
1805  }
1806 
1807  ni_pthread_mutex_lock(&p_ctx->mutex);
1808  // In close state, let the close process execute first.
1809  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
1810  {
1811  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
1812  ni_pthread_mutex_unlock(&p_ctx->mutex);
1813  ni_usleep(100);
1815  }
1817  ni_pthread_mutex_unlock(&p_ctx->mutex);
1818 
1819  switch (device_type)
1820  {
1822  {
1823  int seq_change_read_count = 0;
1824  p_data->data.frame.src_codec = p_ctx->codec_format;
1825  for (;;)
1826  {
1827  retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
1828  // check resolution change only after initial setting obtained
1829  // p_data->data.frame.video_width is picture width and will be 32-align
1830  // adjusted to frame size; p_data->data.frame.video_height is the same as
1831  // frame size, then compare them to saved one for resolution checking
1832  //
1833  uint32_t aligned_width;
1834  if(QUADRA)
1835  {
1836  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
1837  }
1838  else
1839  {
1840  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
1841  }
1842 
1843  if (0 == retval && seq_change_read_count)
1844  {
1845  ni_log2(p_ctx, NI_LOG_DEBUG,
1846  "%s (decoder): seq change NO data, next time.\n", __func__);
1847  p_ctx->active_video_width = 0;
1848  p_ctx->active_video_height = 0;
1849  p_ctx->actual_video_width = 0;
1850  break;
1851  }
1852  else if (retval < 0)
1853  {
1854  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
1855  __func__, retval);
1856  break;
1857  }
1858  // aligned_width may equal to active_video_width if bit depth and width
1859  // are changed at the same time. So, check video_width != actual_video_width.
1860  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
1861  (p_data->data.frame.video_width &&
1862  p_data->data.frame.video_height &&
1863  (aligned_width != p_ctx->active_video_width ||
1864  p_data->data.frame.video_height != p_ctx->active_video_height))))
1865  {
1866  ni_log2(
1867  p_ctx, NI_LOG_DEBUG,
1868  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
1869  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
1870  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
1871  aligned_width, p_data->data.frame.video_height,
1872  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
1873  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
1874  // reset active video resolution to 0 so it can be queried in the re-read
1875  p_ctx->active_video_width = 0;
1876  p_ctx->active_video_height = 0;
1877  p_ctx->actual_video_width = 0;
1878  seq_change_read_count++;
1879  }
1880  else
1881  {
1882  break;
1883  }
1884  }
1885  break;
1886  }
1888  {
1889  retval = ni_encoder_session_read(p_ctx, &(p_data->data.packet));
1890  break;
1891  }
1892  case NI_DEVICE_TYPE_AI:
1893  {
1894  retval = ni_ai_session_read(p_ctx, &(p_data->data.packet));
1895  break;
1896  }
1897  default:
1898  {
1899  retval = NI_RETCODE_INVALID_PARAM;
1900  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1901  __func__, device_type);
1902  break;
1903  }
1904  }
1905 
1906  ni_pthread_mutex_lock(&p_ctx->mutex);
1908  ni_pthread_mutex_unlock(&p_ctx->mutex);
1909  return retval;
1910 }
1911 
1912 /*!*****************************************************************************
1913  * \brief Query session data from the device -
1914  * If device_type is valid, will query session data
1915  * from specified device type
1916  *
1917  * \param[in] p_ctx Pointer to a caller allocated
1918  * ni_session_context_t struct
1919  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
1920  * NI_DEVICE_TYPE_ENCODER or
1921  * NI_DEVICE_TYPE_SCALER or
1922  * NI_DEVICE_TYPE_AI or
1923  * NI_DEVICE_TYPE_UPLOADER
1924  *
1925  * \return On success
1926  * NI_RETCODE_SUCCESS
1927  * On failure
1928  * NI_RETCODE_INVALID_PARAM
1929  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1930  * NI_RETCODE_ERROR_INVALID_SESSION
1931  ******************************************************************************/
1933 {
1935  if (!p_ctx)
1936  {
1937  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1938  __func__);
1939  return NI_RETCODE_INVALID_PARAM;
1940  }
1941 
1942  if (IS_XCODER_DEVICE_TYPE(device_type))
1943  {
1944  retval = ni_xcoder_session_query(p_ctx, device_type);
1945  } else
1946  {
1947  retval = NI_RETCODE_INVALID_PARAM;
1948  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1949  __func__, device_type);
1950  }
1951 
1952  return retval;
1953 }
1954 
1955 /*!*****************************************************************************
1956  * \brief Query detail session data from the device -
1957  * If device_type is valid, will query session data
1958  * from specified device type
1959  *
1960  * \param[in] p_ctx Pointer to a caller allocated
1961  * ni_session_context_t struct
1962  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
1963  * NI_DEVICE_TYPE_ENCODER or
1964  *
1965  * \return On success
1966  * NI_RETCODE_SUCCESS
1967  * On failure
1968  * NI_RETCODE_INVALID_PARAM
1969  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1970  * NI_RETCODE_ERROR_INVALID_SESSION
1971  ******************************************************************************/
1973 {
1975  if (!p_ctx)
1976  {
1977  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1978  __func__);
1979  return NI_RETCODE_INVALID_PARAM;
1980  }
1981 
1982  if (IS_XCODER_DEVICE_TYPE(device_type))
1983  {
1984  retval = ni_xcoder_session_query_detail(p_ctx, device_type, detail_data, 0);
1985  } else
1986  {
1987  retval = NI_RETCODE_INVALID_PARAM;
1988  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1989  __func__, device_type);
1990  }
1991 
1992  return retval;
1993 }
1994 
1995 /*!*****************************************************************************
1996  * \brief Query detail session data from the device -
1997  * If device_type is valid, will query session data
1998  * from specified device type
1999  *
2000  * \param[in] p_ctx Pointer to a caller allocated
2001  * ni_session_context_t struct
2002  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
2003  * NI_DEVICE_TYPE_ENCODER or
2004  *
2005  * \return On success
2006  * NI_RETCODE_SUCCESS
2007  * On failure
2008  * NI_RETCODE_INVALID_PARAM
2009  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2010  * NI_RETCODE_ERROR_INVALID_SESSION
2011  ******************************************************************************/
2013 {
2015  if (!p_ctx)
2016  {
2017  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
2018  __func__);
2019  return NI_RETCODE_INVALID_PARAM;
2020  }
2021 
2022  if (IS_XCODER_DEVICE_TYPE(device_type))
2023  {
2024  retval = ni_xcoder_session_query_detail(p_ctx, device_type, detail_data, 1);
2025  } else
2026  {
2027  retval = NI_RETCODE_INVALID_PARAM;
2028  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
2029  __func__, device_type);
2030  }
2031 
2032  return retval;
2033 }
2034 
2035 /*!*****************************************************************************
2036  * \brief Send namespace num and SRIOv index to the device with specified logic block
2037  * address.
2038  *
2039  * \param[in] device_handle Device handle obtained by calling ni_device_open
2040  * \param[in] namespace_num Set the namespace number with designated sriov
2041  * \param[in] sriov_index Identify which sriov need to be set
2042  *
2043  * \return On success
2044  * NI_RETCODE_SUCCESS
2045  * On failure
2046  * NI_RETCODE_ERROR_MEM_ALOC
2047  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2048  ******************************************************************************/
2049 ni_retcode_t ni_device_config_namespace_num(ni_device_handle_t device_handle,
2050  uint32_t namespace_num, uint32_t sriov_index)
2051 {
2052  ni_log(NI_LOG_DEBUG, "%s namespace_num %u sriov_index %u\n",
2053  __func__, namespace_num, sriov_index);
2054  return ni_device_config_ns_qos(device_handle, namespace_num, sriov_index);
2055 }
2056 
2057 /*!*****************************************************************************
2058  * \brief Send qos mode to the device with specified logic block
2059  * address.
2060  *
2061  * \param[in] device_handle Device handle obtained by calling ni_device_open
2062  * \param[in] mode The requested qos mode
2063  *
2064  * \return On success
2065  * NI_RETCODE_SUCCESS
2066  * On failure
2067  * NI_RETCODE_ERROR_MEM_ALOC
2068  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2069  ******************************************************************************/
2070 ni_retcode_t ni_device_config_qos(ni_device_handle_t device_handle,
2071  uint32_t mode)
2072 {
2073  ni_log(NI_LOG_DEBUG, "%s device_handle %p mode %u\n",
2074  __func__, device_handle, mode);
2075  return ni_device_config_ns_qos(device_handle, QOS_NAMESPACE_CODE, mode);
2076 }
2077 
2078 /*!*****************************************************************************
2079  * \brief Send qos over provisioning mode to target namespace with specified logic
2080  * block address.
2081  *
2082  * \param[in] device_handle Device handle obtained by calling ni_device_open
2083  * \param[in] device_handle_t Target device handle of namespace required for OP
2084  * \param[in] over_provision The request overprovision percent
2085  *
2086  * \return On success
2087  * NI_RETCODE_SUCCESS
2088  * On failure
2089  * NI_RETCODE_ERROR_MEM_ALOC
2090  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2091  ******************************************************************************/
2092 ni_retcode_t ni_device_config_qos_op(ni_device_handle_t device_handle,
2093  ni_device_handle_t device_handle_t,
2094  uint32_t over_provision)
2095 {
2096  ni_retcode_t retval;
2097  float f_over_provision = 0;
2098  memcpy(&f_over_provision, &over_provision, sizeof(int32_t));
2099  ni_log(NI_LOG_DEBUG, "%s device_handle %p target %p over_provision %f\n",
2100  __func__, device_handle, device_handle_t, f_over_provision);
2101  retval = ni_device_config_ns_qos(device_handle, QOS_OP_CONFIG_REC_OP_CODE,
2102  over_provision);
2103  if (NI_RETCODE_SUCCESS != retval)
2104  {
2105  return retval;
2106  }
2107  retval = ni_device_config_ns_qos(device_handle_t, QOS_OP_CONFIG_CODE,
2108  0);
2109  return retval;
2110 }
2111 
2112 /*!*****************************************************************************
2113  * \brief Allocate preliminary memory for the frame buffer based on provided
2114  * parameters. Applicable to YUV420 Planar pixel (8 or 10 bit/pixel)
2115  * format or 32-bit RGBA.
2116  *
2117  * \param[in] p_frame Pointer to a caller allocated
2118  * ni_frame_t struct
2119  * \param[in] video_width Width of the video frame
2120  * \param[in] video_height Height of the video frame
2121  * \param[in] alignment Allignment requirement
2122  * \param[in] metadata_flag Flag indicating if space for additional metadata
2123  * should be allocated
2124  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel,
2125  * 4 for 32 bits/pixel (RGBA)
2126  * \param[in] hw_frame_count Number of hw descriptors stored
2127  * \param[in] is_planar 0 if semiplanar else planar
2128  *
2129  * \return On success
2130  * NI_RETCODE_SUCCESS
2131  * On failure
2132  * NI_RETCODE_INVALID_PARAM
2133  * NI_RETCODE_ERROR_MEM_ALOC
2134  ******************************************************************************/
2136  int video_height, int alignment,
2137  int metadata_flag, int factor,
2138  int hw_frame_count, int is_planar)
2139 {
2140  void* p_buffer = NULL;
2141  int metadata_size = 0;
2142  int retval = NI_RETCODE_SUCCESS;
2143  int width_aligned = video_width;
2144  int height_aligned = video_height;
2145 
2146  if ((!p_frame) || ((factor!=1) && (factor!=2) && (factor !=4))
2147  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
2148  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
2149  {
2150  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2151  "factor %d, video_width %d, video_height %d\n",
2152  __func__, factor, video_width, video_height);
2153  return NI_RETCODE_INVALID_PARAM;
2154  }
2155 
2156  if (metadata_flag)
2157  {
2158  metadata_size = NI_FW_META_DATA_SZ + NI_MAX_SEI_DATA;
2159  }
2160 
2161  if (QUADRA)
2162  {
2163  switch (factor)
2164  {
2165  case 1: /* 8-bit YUV420 */
2166  case 2: /* 10-bit YUV420 */
2167  width_aligned = ((((video_width * factor) + 127) / 128) * 128) / factor;
2168  height_aligned = ((video_height + 1) / 2) * 2;
2169  break;
2170  case 4: /* 32-bit RGBA */
2171  //64byte aligned => 16 rgba pixels
2172  width_aligned = NI_VPU_ALIGN16(video_width);
2173  height_aligned = ((video_height + 1) / 2) * 2;
2174  break;
2175  default:
2176  return NI_RETCODE_INVALID_PARAM;
2177  }
2178  }
2179  else
2180  {
2181  width_aligned = ((video_width + 31) / 32) * 32;
2182  height_aligned = ((video_height + 7) / 8) * 8;
2183  if (alignment)
2184  {
2185  height_aligned = ((video_height + 15) / 16) * 16;
2186  }
2187  }
2188 
2189  int luma_size = width_aligned * height_aligned * factor;
2190  int chroma_b_size;
2191  int chroma_r_size;
2192  if (QUADRA)
2193  {
2194  int chroma_width_aligned = ((((video_width / 2 * factor) + 127) / 128) * 128) / factor;
2195  if (is_planar == NI_PIXEL_PLANAR_FORMAT_TILED4X4 ||
2196  is_planar == NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR)
2197  {
2198  chroma_width_aligned =
2199  ((((video_width * factor) + 127) / 128) * 128) / factor;
2200  }
2201  int chroma_height_aligned = height_aligned / 2;
2202  chroma_b_size = chroma_r_size = chroma_width_aligned * chroma_height_aligned * factor;
2203  if (is_planar == NI_PIXEL_PLANAR_FORMAT_TILED4X4 ||
2204  is_planar == NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR)
2205  {
2206  chroma_r_size = 0;
2207  }
2208  if (4 == factor)
2209  {
2210  chroma_b_size = chroma_r_size = 0;
2211  }
2212  //ni_log(NI_LOG_DEBUG, "%s: factor %d chroma_aligned=%dx%d org=%dx%d\n", __func__, factor, chroma_width_aligned, chroma_height_aligned, video_width, video_height);
2213  }
2214  else
2215  {
2216  chroma_b_size = luma_size / 4;
2217  chroma_r_size = chroma_b_size;
2218  }
2219  int buffer_size;
2220 
2221  /* if hw_frame_count is zero, this is a software frame */
2222  if (hw_frame_count == 0)
2223  buffer_size = luma_size + chroma_b_size + chroma_r_size + metadata_size;
2224  else
2225  buffer_size =
2226  (int)sizeof(niFrameSurface1_t) * hw_frame_count + metadata_size;
2227 
2228  // added 2 blocks of 512 bytes buffer space to handle any extra metadata
2229  // retrieval from fw
2230  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT * 3;
2231  //ni_log(NI_LOG_DEBUG, "%s: luma_size %d chroma_b_size %d chroma_r_size %d metadata_size %d buffer_size %d\n", __func__, luma_size, chroma_b_size, chroma_r_size, metadata_size, buffer_size);
2232 
2233  //Check if need to free
2234  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
2235  {
2237  "%s: free current p_frame, p_frame->buffer_size=%u\n", __func__,
2238  p_frame->buffer_size);
2239  ni_frame_buffer_free(p_frame);
2240  }
2241 
2242  //Check if need to realocate
2243  if (p_frame->buffer_size != buffer_size)
2244  {
2245  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
2246  {
2247  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
2248  NI_ERRNO, __func__);
2249  retval = NI_RETCODE_ERROR_MEM_ALOC;
2250  LRETURN;
2251  }
2252 
2253  // init once after allocation
2254  //memset(p_buffer, 0, buffer_size);
2255  p_frame->buffer_size = buffer_size;
2256  p_frame->p_buffer = p_buffer;
2257 
2258  ni_log(NI_LOG_DEBUG, "%s: Allocate new p_frame buffer\n", __func__);
2259  }
2260  else
2261  {
2262  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
2263  }
2264 
2265  if (hw_frame_count)
2266  {
2267  p_frame->data_len[0] = 0;
2268  p_frame->data_len[1] = 0;
2269  p_frame->data_len[2] = 0;
2270  p_frame->data_len[3] = sizeof(niFrameSurface1_t)*hw_frame_count;
2271  }
2272  else
2273  {
2274  p_frame->data_len[0] = luma_size;
2275  p_frame->data_len[1] = chroma_b_size;
2276  p_frame->data_len[2] = chroma_r_size;
2277  p_frame->data_len[3] = 0;//unused by hwdesc
2278  }
2279 
2280  p_frame->p_data[0] = p_frame->p_buffer;
2281  p_frame->p_data[1] = p_frame->p_data[0] + p_frame->data_len[0];
2282  p_frame->p_data[2] = p_frame->p_data[1] + p_frame->data_len[1];
2283  p_frame->p_data[3] = p_frame->p_data[2] + p_frame->data_len[2]; //hwdescriptor
2284 
2285  // init p_data[3] to 0 so that ni_frame_buffer_free frees only valid DMA buf
2286  // fd in hw frame read from fw
2287  if (hw_frame_count)
2288  {
2289  memset(p_frame->p_data[3], 0, sizeof(niFrameSurface1_t) * hw_frame_count);
2290  }
2291 
2292  p_frame->video_width = width_aligned;
2293  p_frame->video_height = height_aligned;
2294 
2295  ni_log(NI_LOG_DEBUG, "ni_frame_buffer_alloc: p_buffer %p p_data [%p %p %p %p] data_len [%d %d %d %d] video_width %d video_height %d\n", p_frame->p_buffer, p_frame->p_data[0], p_frame->p_data[1], p_frame->p_data[2], p_frame->p_data[3], p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2], p_frame->data_len[3], p_frame->video_width, p_frame->video_height);
2296  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2297  p_frame->buffer_size);
2298 
2299 END:
2300 
2301  if (NI_RETCODE_SUCCESS != retval)
2302  {
2303  ni_aligned_free(p_buffer);
2304  }
2305 
2306  return retval;
2307 }
2308 
2309 /*!*****************************************************************************
2310  * \brief Wrapper function for ni_frame_buffer_alloc. Meant to handle RGBA min.
2311  * resoulution considerations for encoder.
2312  *
2313  * \param[in] p_frame Pointer to a caller allocated
2314  * ni_frame_t struct
2315  * \param[in] video_width Width of the video frame
2316  * \param[in] video_height Height of the video frame
2317  * \param[in] alignment Allignment requirement
2318  * \param[in] metadata_flag Flag indicating if space for additional metadata
2319  * should be allocated
2320  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel,
2321  * 4 for 32 bits/pixel (RGBA)
2322  * \param[in] hw_frame_count Number of hw descriptors stored
2323  * \param[in] is_planar 0 if semiplanar else planar
2324  * \param[in] pix_fmt pixel format to distinguish between planar types
2325  * and/or components
2326  *
2327  * \return On success
2328  * NI_RETCODE_SUCCESS
2329  * On failure
2330  * NI_RETCODE_INVALID_PARAM
2331  * NI_RETCODE_ERROR_MEM_ALOC
2332  ******************************************************************************/
2334  int video_height, int alignment,
2335  int metadata_flag, int factor,
2336  int hw_frame_count, int is_planar,
2337  ni_pix_fmt_t pix_fmt)
2338 {
2339  int extra_len = 0;
2340  int dst_stride[NI_MAX_NUM_DATA_POINTERS] = {0};
2341  int height_aligned[NI_MAX_NUM_DATA_POINTERS] = {0};
2342 
2343  if (((factor!=1) && (factor!=2) && (factor !=4))
2344  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
2345  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
2346  {
2347  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2348  "factor %d, video_width %d, video_height %d\n",
2349  __func__, factor, video_width, video_height);
2350  return NI_RETCODE_INVALID_PARAM;
2351  }
2352 
2353  switch (pix_fmt)
2354  {
2355  case NI_PIX_FMT_YUV420P:
2357  case NI_PIX_FMT_NV12:
2358  case NI_PIX_FMT_P010LE:
2359  case NI_PIX_FMT_NV16:
2360  case NI_PIX_FMT_YUYV422:
2361  case NI_PIX_FMT_UYVY422:
2362  case NI_PIX_FMT_ARGB:
2363  case NI_PIX_FMT_ABGR:
2364  case NI_PIX_FMT_RGBA:
2365  case NI_PIX_FMT_BGRA:
2366  case NI_PIX_FMT_BGR0:
2367  break;
2368  default:
2369  ni_log(NI_LOG_ERROR, "ERROR: %s pix_fmt %d not supported \n",
2370  __func__, pix_fmt);
2371  return NI_RETCODE_INVALID_PARAM;
2372  }
2373  //Get stride info for original resolution
2374  ni_get_frame_dim(video_width, video_height,
2375  pix_fmt,
2376  dst_stride, height_aligned);
2377 
2378  if (metadata_flag)
2379  {
2380  extra_len = NI_FW_META_DATA_SZ + NI_MAX_SEI_DATA;
2381  }
2382 
2383  return ni_frame_buffer_alloc_pixfmt(p_frame, pix_fmt, video_width,
2384  video_height, dst_stride, alignment,
2385  extra_len);
2386 }
2387 
2388 /*!*****************************************************************************
2389  * \brief Allocate preliminary memory for the frame buffer based on provided
2390  * parameters.
2391  *
2392  * \param[in] p_frame Pointer to a caller allocated
2393  * ni_frame_t struct
2394  * \param[in] video_width Width of the video frame
2395  * \param[in] video_height Height of the video frame
2396  * \param[in] alignment Allignment requirement
2397  * \param[in] pixel_format Format for input
2398  *
2399  * \return On success
2400  * NI_RETCODE_SUCCESS
2401  * On failure
2402  * NI_RETCODE_INVALID_PARAM
2403  * NI_RETCODE_ERROR_MEM_ALOC
2404  ******************************************************************************/
2406  int video_height, int pixel_format)
2407 {
2408  void *p_buffer = NULL;
2409  int retval = NI_RETCODE_SUCCESS;
2410  int width_aligned = video_width;
2411  int height_aligned = video_height;
2412  int buffer_size;
2413  int luma_size;
2414  int chroma_b_size;
2415  int chroma_r_size;
2416 
2417  if ((!p_frame) || (video_width > NI_MAX_RESOLUTION_WIDTH) ||
2418  (video_width <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT) ||
2419  (video_height <= 0))
2420  {
2422  "ERROR: %s passed parameters are null or not supported, "
2423  "video_width %d, video_height %d\n",
2424  __func__, video_width, video_height);
2425  return NI_RETCODE_INVALID_PARAM;
2426  }
2427 
2428  switch (pixel_format)
2429  {
2430  case NI_PIX_FMT_YUV420P:
2431  width_aligned = NI_VPU_ALIGN128(video_width);
2432  height_aligned = NI_VPU_CEIL(video_height, 2);
2433 
2434  luma_size = width_aligned * height_aligned;
2435  chroma_b_size =
2436  NI_VPU_ALIGN128(video_width / 2) * height_aligned / 2;
2437  chroma_r_size = chroma_b_size;
2438  break;
2440  width_aligned = NI_VPU_ALIGN128(video_width * 2) / 2;
2441  height_aligned = NI_VPU_CEIL(video_height, 2);
2442 
2443  luma_size = width_aligned * height_aligned * 2;
2444  chroma_b_size = NI_VPU_ALIGN128(video_width) * height_aligned / 2;
2445  chroma_r_size = chroma_b_size;
2446  break;
2447  case NI_PIX_FMT_NV12:
2448  width_aligned = NI_VPU_ALIGN128(video_width);
2449  height_aligned = NI_VPU_CEIL(video_height, 2);
2450 
2451  luma_size = width_aligned * height_aligned;
2452  chroma_b_size = width_aligned * height_aligned / 2;
2453  chroma_r_size = 0;
2454  break;
2455  case NI_PIX_FMT_P010LE:
2456  width_aligned = NI_VPU_ALIGN128(video_width * 2) / 2;
2457  height_aligned = NI_VPU_CEIL(video_height, 2);
2458 
2459  luma_size = width_aligned * height_aligned * 2;
2460  chroma_b_size = NI_VPU_ALIGN128(video_width) * height_aligned;
2461  chroma_r_size = 0;
2462  break;
2463  case NI_PIX_FMT_NV16:
2464  width_aligned = NI_VPU_ALIGN64(video_width);
2465  height_aligned = video_height;
2466 
2467  luma_size = width_aligned * height_aligned;
2468  chroma_b_size = luma_size;
2469  chroma_r_size = 0;
2470  break;
2471  case NI_PIX_FMT_YUYV422:
2472  case NI_PIX_FMT_UYVY422:
2473  width_aligned = NI_VPU_ALIGN16(video_width);
2474  height_aligned = video_height;
2475 
2476  luma_size = width_aligned * height_aligned * 2;
2477  chroma_b_size = 0;
2478  chroma_r_size = 0;
2479  break;
2480  case NI_PIX_FMT_RGBA:
2481  case NI_PIX_FMT_BGRA:
2482  case NI_PIX_FMT_ARGB:
2483  case NI_PIX_FMT_ABGR:
2484  case NI_PIX_FMT_BGR0:
2485  width_aligned = NI_VPU_ALIGN16(video_width);
2486  height_aligned = video_height;
2487 
2488  luma_size = width_aligned * height_aligned * 4;
2489  chroma_b_size = 0;
2490  chroma_r_size = 0;
2491  break;
2492  case NI_PIX_FMT_BGRP:
2493  width_aligned = NI_VPU_ALIGN32(video_width);
2494  height_aligned = video_height;
2495 
2496  luma_size = width_aligned * height_aligned;
2497  chroma_b_size = luma_size;
2498  chroma_r_size = luma_size;
2499  break;
2500  default:
2501  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n", pixel_format);
2502  return NI_RETCODE_INVALID_PARAM;
2503  }
2504 
2505  /* Allocate local memory to hold a software ni_frame */
2506  buffer_size = luma_size + chroma_b_size + chroma_r_size;
2507 
2508  /* Round up to nearest 4K block */
2509  buffer_size = NI_VPU_ALIGN4096(buffer_size);
2510 
2511  ni_log(NI_LOG_DEBUG, "%s: Rlen %d Glen %d Blen %d buffer_size %d\n",
2512  __func__, luma_size, chroma_b_size, chroma_r_size, buffer_size);
2513 
2514  /* If the frame has changed, reallocate it */
2515  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
2516  {
2518  "%s: free current p_frame, p_frame->buffer_size=%u\n", __func__,
2519  p_frame->buffer_size);
2520  ni_frame_buffer_free(p_frame);
2521  }
2522 
2523  /* Check if need to reallocate */
2524  if (p_frame->buffer_size != buffer_size)
2525  {
2526  ni_log(NI_LOG_DEBUG, "%s: Allocate new p_frame buffer\n", __func__);
2527  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
2528  {
2530  "ERROR %d: %s() Cannot allocate p_frame buffer.\n", NI_ERRNO,
2531  __func__);
2532  retval = NI_RETCODE_ERROR_MEM_ALOC;
2533  LRETURN;
2534  }
2535  } else
2536  {
2537  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
2538  p_buffer = p_frame->p_buffer;
2539  }
2540 
2541  // init once after allocation
2542  // memset(p_buffer, 0, buffer_size);
2543 
2544  p_frame->buffer_size = buffer_size;
2545  p_frame->p_buffer = p_buffer;
2546 
2547  p_frame->data_len[0] = luma_size;
2548  p_frame->data_len[1] = chroma_b_size;
2549  p_frame->data_len[2] = chroma_r_size;
2550  p_frame->data_len[3] = 0;
2551 
2552  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
2553  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + p_frame->data_len[0];
2554  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + p_frame->data_len[1];
2555  p_frame->p_data[3] = (uint8_t *)p_frame->p_data[2] + p_frame->data_len[2];
2556 
2557  // init p_data[3] to 0 so that ni_frame_buffer_free frees only valid DMA buf
2558  // fd in hw frame read from fw
2559  p_frame->video_width = width_aligned;
2560  p_frame->video_height = height_aligned;
2561 
2562  // ni_log(NI_LOG_DEBUG, "ni_frame_buffer_alloc: p_buffer %p p_data [%p %p %p %p] data_len [%d %d %d %d] video_width %d video_height %d\n", p_frame->p_buffer, p_frame->p_data[0], p_frame->p_data[1], p_frame->p_data[2], p_frame->p_data[3], p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2], p_frame->data_len[3], p_frame->video_width, p_frame->video_height);
2563  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2564  p_frame->buffer_size);
2565 END:
2566 
2567  if (NI_RETCODE_SUCCESS != retval)
2568  {
2569  ni_aligned_free(p_buffer);
2570  }
2571 
2572  return retval;
2573 }
2574 
2575 /*!*****************************************************************************
2576  * \brief Allocate memory for decoder frame buffer based on provided
2577  * parameters; the memory is retrieved from a buffer pool and will be
2578  * returned to the same buffer pool by ni_decoder_frame_buffer_free.
2579  * Note: all attributes of ni_frame_t will be set up except for memory and
2580  * buffer, which rely on the pool being allocated; the pool will be
2581  * allocated only after the frame resolution is known.
2582  *
2583  * \param[in] p_pool Buffer pool to get the memory from
2584  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
2585  * \param[in] alloc_mem Whether to get memory from buffer pool
2586  * \param[in] video_width Width of the video frame
2587  * \param[in] video_height Height of the video frame
2588  * \param[in] alignment Alignment requirement
2589  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel
2590  * \param[in] is_planar 0 if semiplanar else planar
2591  *
2592  * \return On success
2593  * NI_RETCODE_SUCCESS
2594  * On failure
2595  * NI_RETCODE_INVALID_PARAM
2596  * NI_RETCODE_ERROR_MEM_ALOC
2597  ******************************************************************************/
2599  ni_frame_t *p_frame, int alloc_mem,
2600  int video_width, int video_height,
2601  int alignment, int factor,
2602  int is_planar)
2603 {
2604  int retval = NI_RETCODE_SUCCESS;
2605 
2606  int width_aligned;
2607  int height_aligned;
2608 
2609  if ((!p_frame) || ((factor!=1) && (factor!=2))
2610  || (video_width > NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
2611  || (video_height > NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
2612  {
2613  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2614  "factor %d, video_width %d, video_height %d\n",
2615  __func__, factor, video_width, video_height);
2616  return NI_RETCODE_INVALID_PARAM;
2617  }
2618 
2619  if (QUADRA)
2620  {
2621  width_aligned = ((((video_width * factor) + 127) / 128) * 128) / factor;
2622  height_aligned = video_height;
2623  }
2624  else
2625  {
2626  width_aligned = ((video_width + 31) / 32) * 32;
2627  height_aligned = ((video_height + 7) / 8) * 8;
2628  if (alignment)
2629  {
2630  height_aligned = ((video_height + 15) / 16) * 16;
2631  }
2632  }
2633 
2634  ni_log(NI_LOG_DEBUG, "%s: aligned=%dx%d orig=%dx%d\n", __func__,
2635  width_aligned, height_aligned, video_width, video_height);
2636 
2637  int luma_size = width_aligned * height_aligned * factor;
2638  int chroma_b_size;
2639  int chroma_r_size;
2640  if (QUADRA)
2641  {
2642  int chroma_width_aligned = ((((video_width / 2 * factor) + 127) / 128) * 128) / factor;
2643  if (!is_planar)
2644  {
2645  chroma_width_aligned =
2646  ((((video_width * factor) + 127) / 128) * 128) / factor;
2647  }
2648  int chroma_height_aligned = height_aligned / 2;
2649  chroma_b_size = chroma_r_size = chroma_width_aligned * chroma_height_aligned * factor;
2650  if (!is_planar)
2651  {
2652  chroma_r_size = 0;
2653  }
2654  }
2655  else
2656  {
2657  chroma_b_size = luma_size / 4;
2658  chroma_r_size = chroma_b_size;
2659  }
2660  int buffer_size = luma_size + chroma_b_size + chroma_r_size +
2662 
2663  // added 2 blocks of 512 bytes buffer space to handle any extra metadata
2664  // retrieval from fw
2665  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT * 3;
2666 
2667  p_frame->buffer_size = buffer_size;
2668 
2669  // if need to get a buffer from pool, pool must have been set up
2670  if (alloc_mem)
2671  {
2672  if (! p_pool)
2673  {
2674  ni_log(NI_LOG_ERROR, "ERROR %s: invalid pool!\n", __func__);
2675  retval = NI_RETCODE_ERROR_MEM_ALOC;
2676  LRETURN;
2677  }
2678 
2679  p_frame->dec_buf = ni_buf_pool_get_buffer(p_pool);
2680  if (! p_frame->dec_buf)
2681  {
2682  retval = NI_RETCODE_ERROR_MEM_ALOC;
2683  LRETURN;
2684  }
2685 
2686  p_frame->p_buffer = p_frame->dec_buf->buf;
2687 
2688  ni_log(NI_LOG_DEBUG, "%s: got new frame ptr %p buffer %p\n", __func__,
2689  p_frame->p_buffer, p_frame->dec_buf);
2690  }
2691  else
2692  {
2693  p_frame->dec_buf = NULL;
2694  p_frame->p_buffer = NULL;
2695  ni_log(NI_LOG_DEBUG, "%s: NOT alloc mem buffer\n", __func__);
2696  }
2697 
2698  if (p_frame->p_buffer)
2699  {
2700  p_frame->p_data[0] = p_frame->p_buffer;
2701  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
2702  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
2703  p_frame->p_data[3] = p_frame->p_data[2] + chroma_r_size;
2704  }
2705  else
2706  {
2707  p_frame->p_data[0] = p_frame->p_data[1] = p_frame->p_data[2] = NULL;
2708  }
2709 
2710  p_frame->data_len[0] = luma_size;
2711  p_frame->data_len[1] = chroma_b_size;
2712  p_frame->data_len[2] = chroma_r_size;
2713  p_frame->data_len[3] = 0; //for hwdesc
2714 
2715  p_frame->video_width = width_aligned;
2716  p_frame->video_height = height_aligned;
2717 
2718  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2719  p_frame->buffer_size);
2720 
2721 END:
2722 
2723  return retval;
2724 }
2725 
2726 /*!*****************************************************************************
2727  * \brief Check if incoming frame is encoder zero copy compatible or not
2728  *
2729  * \param[in] p_enc_ctx pointer to encoder context
2730  * [in] p_enc_params pointer to encoder parameters
2731  * [in] width input width
2732  * [in] height input height
2733  * [in] linesize input linesizes (pointer to array)
2734  * [in] set_linesize setup linesizes 0 means not setup linesizes, 1 means setup linesizes (before encoder open)
2735  *
2736  * \return on success and can do zero copy
2737  * NI_RETCODE_SUCCESS
2738  *
2739  * cannot do zero copy
2740  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
2741  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
2742  * NI_RETCODE_INVALID_PARAM
2743  *
2744 *******************************************************************************/
2746  ni_xcoder_params_t *p_enc_params,
2747  int width, int height,
2748  const int linesize[],
2749  bool set_linesize)
2750 {
2751  // check pixel format / width / height / linesize can be supported
2752  if ((!p_enc_ctx) || (!p_enc_params) || (!linesize)
2753  || (linesize[0]<=0)
2754  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
2755  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
2756  {
2757  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
2758  "p_enc_ctx %p, p_enc_params %p, linesize %p, "
2759  "width %d, height %d linesize[0] %d\n",
2760  __func__, p_enc_ctx, p_enc_params, linesize,
2761  width, height, (linesize) ? linesize[0] : 0);
2762  return NI_RETCODE_INVALID_PARAM;
2763  }
2764 
2765  // check fw revision (if fw_rev has been populated in open session)
2766  if (p_enc_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
2768  "6Q") < 0))
2769  {
2770  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.Q\n", __func__);
2772  }
2773 
2774  bool isrgba = false;
2775  bool isplanar = false;
2776  bool issemiplanar = false;
2777 
2778  switch (p_enc_ctx->pixel_format)
2779  {
2780  case NI_PIX_FMT_YUV420P:
2782  isplanar = true;
2783  break;
2784  case NI_PIX_FMT_NV12:
2785  case NI_PIX_FMT_P010LE:
2786  issemiplanar = true;
2787  break;
2788  case NI_PIX_FMT_ABGR:
2789  case NI_PIX_FMT_ARGB:
2790  case NI_PIX_FMT_RGBA:
2791  case NI_PIX_FMT_BGRA:
2792  isrgba = true;
2793  break;
2794  default:
2795  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
2797  }
2798 
2799  // check fw revision (if fw_rev has been populated in open session)
2800  if (issemiplanar &&
2803  "6q") < 0))
2804  {
2805  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
2807  }
2808 
2809  // check zero copy compatibilty and set linesize
2810  if (p_enc_params->zerocopy_mode) // always allow zero copy for RGBA, because RGBA pixel format data copy currently not supported
2811  {
2812  if (set_linesize)
2813  {
2814  bool ishwframe = (p_enc_params->hwframes) ? true : false;
2815  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
2816  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s isrgba %u issemiplanar %u, ishwframe %u, "
2817  "p_enc_ctx %p, p_enc_params %p, linesize %p, "
2818  "width %d, height %d, linesize[0] %d linesize[1] %d\n",
2819  __func__, isrgba, issemiplanar, ishwframe, p_enc_ctx, p_enc_params, linesize,
2820  width, height, linesize[0], linesize[1]);
2821 
2822  if (linesize[0] <= max_linesize &&
2823  linesize[0] % 2 == 0 && //even stride
2824  linesize[1] % 2 == 0 && //even stride
2825  width % 2 == 0 && //even width
2826  height % 2 == 0 && //even height
2827  (!p_enc_params->enable_ai_enhance || width % 128 == 0) && // align for AI engine
2828  width >= NI_MIN_WIDTH &&
2829  height >= NI_MIN_HEIGHT &&
2830  !ishwframe &&
2831  (!isplanar || linesize[2] == linesize[1]) // for planar, make sure cb linesize equal to cr linesize
2832  )
2833  {
2834  // send luma / chorma linesize to device (device is also aware frame will not be padded for 2-pass workaround)
2835  p_enc_params->luma_linesize = linesize[0];
2836  p_enc_params->chroma_linesize = (isrgba) ? 0 : linesize[1]; // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format
2837  return NI_RETCODE_SUCCESS;
2838  }
2839  else
2840  {
2841  p_enc_params->luma_linesize = 0;
2842  p_enc_params->chroma_linesize = 0;
2843  }
2844  }
2845  else if (p_enc_params->luma_linesize ||
2846  p_enc_params->chroma_linesize)
2847  {
2848  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s "
2849  "luma_linesize %d, chroma_linesize %d, "
2850  "linesize[0] %d, linesize[1] %d\n",
2851  __func__, p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
2852  linesize[0], linesize[1]);
2853  if (p_enc_params->luma_linesize != linesize[0] ||
2854  (p_enc_params->chroma_linesize && p_enc_params->chroma_linesize != linesize[1]) // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format
2855  )
2856  {
2857 #ifndef XCODER_311
2858  // linesizes can change during SW frame seqeunce change transcoding when FFmpeg noautoscale option is not set
2859  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: linesize changed from %u %u to %u %u - resolution change?\n", __func__,
2860  p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
2861  linesize[0], linesize[1]);
2862 #endif
2863  }
2864  else
2865  return NI_RETCODE_SUCCESS;
2866  }
2867  }
2868 
2870 }
2871 
2872 /*!*****************************************************************************
2873  * \brief Allocate memory for encoder zero copy (metadata, etc.)
2874  * for encoding based on given
2875  * parameters, taking into account pic linesize and extra data.
2876  * Applicable to YUV planr / semi-planar 8 or 10 bit and RGBA pixel formats.
2877  *
2878  *
2879  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
2880  * \param[in] video_width Width of the video frame
2881  * \param[in] video_height Height of the video frame
2882  * \param[in] linesize Picture line size
2883  * \param[in] data Picture data pointers (for each of YUV planes)
2884  * \param[in] extra_len Extra data size (incl. meta data)
2885  *
2886  * \return On success
2887  * NI_RETCODE_SUCCESS
2888  * On failure
2889  * NI_RETCODE_INVALID_PARAM
2890  * NI_RETCODE_ERROR_MEM_ALOC
2891  *****************************************************************************/
2893  int video_width, int video_height,
2894  const int linesize[], const uint8_t *data[],
2895  int extra_len)
2896 {
2897  int retval = NI_RETCODE_SUCCESS;
2898 
2899  if ((!p_frame) || (!linesize) || (!data))
2900  {
2901  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2902  "p_frame %p, linesize %p, data %p\n",
2903  __func__, p_frame, linesize, data);
2904  return NI_RETCODE_INVALID_PARAM;
2905  }
2906 
2908  "%s: resolution=%dx%d linesize=%d/%d/%d "
2909  "data=%p %p %p extra_len=%d\n",
2910  __func__, video_width, video_height,
2911  linesize[0], linesize[1], linesize[2],
2912  data[0], data[1], data[2], extra_len);
2913 
2914  if (p_frame->buffer_size)
2915  {
2916  p_frame->buffer_size = 0; //notify p_frame->p_buffer is not allocated
2917  ni_aligned_free(p_frame->p_buffer); // also free the temp p_buffer allocated for niFrameSurface1_t in encoder init stage
2918  }
2919 
2920  p_frame->p_buffer = (uint8_t *)data[0];
2921  p_frame->p_data[0] = (uint8_t *)data[0];
2922  p_frame->p_data[1] = (uint8_t *)data[1];
2923  p_frame->p_data[2] = (uint8_t *)data[2];
2924 
2925  int luma_size = linesize[0] * video_height;
2926  int chroma_b_size = 0;
2927  int chroma_r_size = 0;
2928 
2929  // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format, but only data[0] pointer is populated
2930  if (data[1]) // cb size is 0 for RGBA pixel format
2931  chroma_b_size = linesize[1] * (video_height / 2);
2932 
2933  if (data[2]) // cr size is 0 for semi-planar or RGBA pixel format
2934  chroma_r_size = linesize[2] * (video_height / 2);
2935 
2936  //ni_log(NI_LOG_DEBUG, "%s: luma_size=%d chroma_b_size=%d chroma_r_size=%d\n", __func__, luma_size, chroma_b_size, chroma_r_size);
2937 
2938  uint32_t start_offset;
2939  uint32_t total_start_len = 0;
2940  int i;
2941 
2942  p_frame->inconsecutive_transfer = 0;
2943 
2944  // rgba has one data pointer, semi-planar has two data pointers
2945  if ((data[1] && (data[0] + luma_size != data[1]))
2946  || (data[2] && (data[1] + chroma_b_size != data[2])))
2947  {
2948  p_frame->inconsecutive_transfer = 1;
2949  }
2950 
2951  if (p_frame->inconsecutive_transfer)
2952  {
2953  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
2954  {
2955  start_offset = (uintptr_t)p_frame->p_data[i] % NI_MEM_PAGE_ALIGNMENT;
2956  p_frame->start_len[i] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
2957  total_start_len += p_frame->start_len[i];
2958  }
2959  }
2960  else
2961  {
2962  start_offset = (uintptr_t)p_frame->p_data[0] % NI_MEM_PAGE_ALIGNMENT;
2963  p_frame->start_len[0] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
2964  p_frame->start_len[1] = p_frame->start_len[2] = 0;
2965  total_start_len = p_frame->start_len[0];
2966  }
2967  p_frame->total_start_len = total_start_len;
2968 
2969  if (ni_encoder_metadata_buffer_alloc(p_frame, extra_len))
2970  {
2971  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_metadata_buffer buffer.\n",
2972  NI_ERRNO, __func__);
2973  retval = NI_RETCODE_ERROR_MEM_ALOC;
2974  LRETURN;
2975  }
2976  p_frame->separate_metadata = 1;
2977 
2978  if (total_start_len)
2979  {
2980  if (ni_encoder_start_buffer_alloc(p_frame))
2981  {
2982  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_start_buffer buffer.\n",
2983  NI_ERRNO, __func__);
2984  retval = NI_RETCODE_ERROR_MEM_ALOC;
2985  LRETURN;
2986  }
2987  p_frame->separate_start = 1;
2988 
2989  // copy non-4k-aligned part at the start of YUV data
2990  int start_buffer_offset = 0;
2991  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
2992  {
2993  if (p_frame->p_data[i])
2994  {
2995  memcpy(p_frame->p_start_buffer+start_buffer_offset, p_frame->p_data[i],
2996  p_frame->start_len[i]);
2997  start_buffer_offset += p_frame->start_len[i];
2998  }
2999  }
3000  }
3001 
3002  p_frame->data_len[0] = luma_size;
3003  p_frame->data_len[1] = chroma_b_size;
3004  p_frame->data_len[2] = chroma_r_size;
3005  p_frame->data_len[3] = 0;//unused by hwdesc
3006 
3007  p_frame->video_width = video_width;
3008  p_frame->video_height = video_height;
3009 
3011  "%s: success: p_metadata_buffer %p metadata_buffer_size %u "
3012  "p_start_buffer %p start_buffer_size %u data_len %u %u %u\n",
3013  __func__, p_frame->p_metadata_buffer, p_frame->metadata_buffer_size,
3014  p_frame->p_start_buffer, p_frame->start_buffer_size,
3015  p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2]);
3016 
3017 END:
3018 
3019  return retval;
3020 }
3021 
3022 
3023 /*!*****************************************************************************
3024  * \brief Check if incoming frame is hwupload zero copy compatible or not
3025  *
3026  * \param[in] p_upl_ctx pointer to uploader context
3027  * [in] width input width
3028  * [in] height input height
3029  * [in] linesize input linesizes (pointer to array)
3030  * [in] pixel_format input pixel format
3031  *
3032  * \return on success and can do zero copy
3033  * NI_RETCODE_SUCCESS
3034  *
3035  * cannot do zero copy
3036  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
3037  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
3038  * NI_RETCODE_INVALID_PARAM
3039  *
3040 *******************************************************************************/
3042  int width, int height,
3043  const int linesize[], int pixel_format)
3044 {
3045  // check pixel format / width / height / linesize can be supported
3046  if ((!p_upl_ctx) || (!linesize)
3047  || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3048  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
3049  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
3050  {
3051  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
3052  "p_enc_ctx %p, linesize %p, "
3053  "width %d, height %d linesize[0] %d\n",
3054  __func__, p_upl_ctx, linesize,
3055  width, height, (linesize) ? linesize[0] : 0);
3056  return NI_RETCODE_INVALID_PARAM;
3057  }
3058 
3059  // check fw revision (if fw_rev has been populated in open session)
3060  if (p_upl_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
3062  "6S") < 0))
3063  {
3064  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.S\n", __func__);
3066  }
3067 
3068  // upload does not have zeroCopyMode parameter, currently only allows resolution >= 1080p
3069  if ((width * height) < NI_NUM_OF_PIXELS_1080P)
3071 
3072  // check zero copy compatibilty
3073  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s pixel_format %d "
3074  "p_upl_ctx %p, linesize %p, "
3075  "width %d, height %d, linesize[0] %d\n",
3076  __func__, pixel_format, p_upl_ctx, linesize,
3077  width, height, linesize[0]);
3078 
3079  int bit_depth_factor;
3080  bool isrgba = false;
3081  bool isplanar = false;
3082  bool issemiplanar = false;
3083 
3084  switch (pixel_format)
3085  {
3086  case NI_PIX_FMT_YUV420P:
3087  isplanar = true;
3088  bit_depth_factor = 1;
3089  break;
3091  isplanar = true;
3092  bit_depth_factor = 2;
3093  break;
3094  case NI_PIX_FMT_NV12:
3095  issemiplanar = true;
3096  bit_depth_factor = 1;
3097  break;
3098  case NI_PIX_FMT_P010LE:
3099  issemiplanar = true;
3100  bit_depth_factor = 2;
3101  break;
3102  case NI_PIX_FMT_ABGR:
3103  case NI_PIX_FMT_ARGB:
3104  case NI_PIX_FMT_RGBA:
3105  case NI_PIX_FMT_BGRA:
3106  isrgba = true;
3107  bit_depth_factor = 4; // not accurate, only for linesize check
3108  break;
3109  default:
3110  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
3112  }
3113 
3114  // check fw revision (if fw_rev has been populated in open session)
3115  if (issemiplanar &&
3118  "6q") < 0))
3119  {
3120  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
3122  }
3123 
3124  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
3125  if (linesize[0] <= max_linesize &&
3126  width % 2 == 0 && //even width
3127  height % 2 == 0 && //even height
3128  width >= NI_MIN_WIDTH && height >= NI_MIN_HEIGHT)
3129  {
3130  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3131  if (isplanar &&
3132  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3133  linesize[1] == NI_VPU_ALIGN128(width * bit_depth_factor / 2) &&
3134  linesize[2] == linesize[1])
3135  return NI_RETCODE_SUCCESS;
3136 
3137  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3138  if (issemiplanar &&
3139  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3140  linesize[1] == linesize[0])
3141  return NI_RETCODE_SUCCESS;
3142 
3143  // rgba only support 64 bytes aligned for 2D
3144  if (isrgba &&
3145  linesize[0] == NI_VPU_ALIGN64(width * bit_depth_factor))
3146  return NI_RETCODE_SUCCESS;
3147  }
3148 
3150 }
3151 
3152 /*!*****************************************************************************
3153  * \brief Allocate memory for the frame buffer for encoding based on given
3154  * parameters, taking into account pic line size and extra data.
3155  * Applicable to YUV420p AVFrame only. 8 or 10 bit/pixel.
3156  * Cb/Cr size matches that of Y.
3157  *
3158  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3159  *
3160  * \param[in] video_width Width of the video frame
3161  * \param[in] video_height Height of the video frame
3162  * \param[in] linesize Picture line size
3163  * \param[in] alignment Allignment requirement
3164  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3165  * to allocate any buffer (zero-copy from existing)
3166  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3167  *
3168  * \return On success
3169  * NI_RETCODE_SUCCESS
3170  * On failure
3171  * NI_RETCODE_INVALID_PARAM
3172  * NI_RETCODE_ERROR_MEM_ALOC
3173  *****************************************************************************/
3175  int video_height, int linesize[],
3176  int alignment, int extra_len,
3177  bool alignment_2pass_wa)
3178 {
3179  void* p_buffer = NULL;
3180  int height_aligned;
3181  int retval = NI_RETCODE_SUCCESS;
3182 
3183  if ((!p_frame) || (!linesize) || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3184  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
3185  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
3186  {
3187  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3188  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3189  __func__, p_frame, linesize, video_width, video_height);
3190  return NI_RETCODE_INVALID_PARAM;
3191  }
3192 
3193  if (QUADRA)
3194  {
3195  height_aligned = ((video_height + 1) / 2) * 2;
3196  } else
3197  {
3198  height_aligned = ((video_height + 7) / 8) * 8;
3199 
3200  if (alignment)
3201  {
3202  height_aligned = ((video_height + 15) / 16) * 16;
3203  }
3204  }
3205  if (height_aligned < NI_MIN_HEIGHT)
3206  {
3207  height_aligned = NI_MIN_HEIGHT;
3208  }
3209 
3211  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d "
3212  "extra_len=%d\n",
3213  __func__, video_width, height_aligned, video_width, video_height,
3214  linesize[0], linesize[1], linesize[2], extra_len);
3215 
3216  int luma_size = linesize[0] * height_aligned;
3217  int chroma_b_size;
3218  int chroma_r_size;
3219  if (QUADRA)
3220  {
3221  chroma_b_size = chroma_r_size = linesize[1] * (height_aligned / 2);
3222  if (alignment_2pass_wa)
3223  {
3224  // for 2-pass encode output mismatch WA, need to extend (and pad) Cr plane height, because 1st pass assume input 32 align
3225  chroma_r_size = linesize[1] * (((height_aligned + 31) / 32) * 32) / 2;
3226  }
3227  //ni_log(NI_LOG_DEBUG, "%s: luma_size=%d chroma_b_size=%d chroma_r_size=%d\n", __func__, luma_size, chroma_b_size, chroma_r_size);
3228  }
3229  else
3230  {
3231  chroma_b_size = luma_size / 4;
3232  chroma_r_size = luma_size / 4;
3233  }
3234  if(extra_len >= 0)
3235  {
3236  int buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
3237 
3238  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3239 
3240  //Check if Need to free
3241  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3242  {
3244  "%s: free current p_frame, "
3245  "p_frame->buffer_size=%u\n",
3246  __func__, p_frame->buffer_size);
3247  ni_frame_buffer_free(p_frame);
3248  }
3249 
3250  //Check if need to realocate
3251  if (p_frame->buffer_size != buffer_size)
3252  {
3253  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3254  {
3255  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3256  NI_ERRNO, __func__);
3257  retval = NI_RETCODE_ERROR_MEM_ALOC;
3258  LRETURN;
3259  }
3260 
3261  // init once after allocation
3262  memset(p_buffer, 0, buffer_size);
3263  p_frame->buffer_size = buffer_size;
3264  p_frame->p_buffer = p_buffer;
3265 
3266  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3267  }
3268  else
3269  {
3270  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3271  }
3272  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3273  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3274  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_b_size;
3275  }
3276  else
3277  {
3278  p_frame->buffer_size = 0; //no ownership
3279  }
3280 
3281  p_frame->data_len[0] = luma_size;
3282  p_frame->data_len[1] = chroma_b_size;
3283  p_frame->data_len[2] = chroma_r_size;
3284  p_frame->data_len[3] = 0;//unused by hwdesc
3285 
3286  p_frame->video_width = video_width;
3287  p_frame->video_height = height_aligned;
3288 
3290  "%s: success: p_frame->p_buffer %p "
3291  "p_frame->buffer_size=%u\n",
3292  __func__, p_frame->p_buffer, p_frame->buffer_size);
3293 
3294 END:
3295 
3296  if (NI_RETCODE_SUCCESS != retval)
3297  {
3298  ni_aligned_free(p_buffer);
3299  }
3300 
3301  return retval;
3302 }
3303 
3304 /*!*****************************************************************************
3305  * \brief allocate device destination frame from scaler hwframe pool
3306  *
3307  * \param
3308  *
3309  * \return 0 if successful, < 0 otherwise
3310  ******************************************************************************/
3312  ni_scaler_input_params_t scaler_params,
3313  niFrameSurface1_t *p_surface)
3314 {
3315  int ret = 0;
3316  if (scaler_params.op != NI_SCALER_OPCODE_OVERLAY && scaler_params.op != NI_SCALER_OPCODE_WATERMARK)
3317  {
3318  ret = ni_device_alloc_frame(
3319  p_ctx, scaler_params.output_width, scaler_params.output_height,
3320  scaler_params.output_format, NI_SCALER_FLAG_IO,
3321  scaler_params.out_rec_width, scaler_params.out_rec_height,
3322  scaler_params.out_rec_x, scaler_params.out_rec_y,
3323  scaler_params.rgba_color, -1, NI_DEVICE_TYPE_SCALER);
3324  } else
3325  {
3326  // in vf_overlay_ni.c: flags = (s->alpha_format ? NI_SCALER_FLAG_PA : 0) | NI_SCALER_FLAG_IO;
3327  ret = ni_device_alloc_frame(
3328  p_ctx, scaler_params.output_width, scaler_params.output_height,
3329  scaler_params.output_format, NI_SCALER_FLAG_IO,
3330  scaler_params.out_rec_width, scaler_params.out_rec_height,
3331  scaler_params.out_rec_x, scaler_params.out_rec_y,
3332  p_surface->ui32nodeAddress, p_surface->ui16FrameIdx,
3334  }
3335  return ret;
3336 }
3337 
3338 /*!*****************************************************************************
3339  * \brief allocate device input frame by hw descriptor. This call won't actually allocate
3340  a frame but sends the incoming hardware frame index to the scaler manager
3341  *
3342  * \param
3343  *
3344  * \return 0 if successful, < 0 otherwise
3345  ******************************************************************************/
3347  ni_scaler_input_params_t scaler_params,
3348  niFrameSurface1_t *p_src_surface)
3349 {
3350  int ret = 0;
3351 
3352  ret = ni_device_alloc_frame(
3353  p_ctx, scaler_params.input_width, scaler_params.input_height,
3354  scaler_params.input_format, 0, scaler_params.in_rec_width,
3355  scaler_params.in_rec_height, scaler_params.in_rec_x,
3356  scaler_params.in_rec_y, p_src_surface->ui32nodeAddress,
3357  p_src_surface->ui16FrameIdx, NI_DEVICE_TYPE_SCALER);
3358  return ret;
3359 }
3360 
3361 /*!*****************************************************************************
3362  * \brief init output pool of scaler frames
3363  *
3364  * \param
3365  *
3366  * \return 0 if successful, < 0 otherwise
3367  ******************************************************************************/
3369  ni_scaler_input_params_t scaler_params)
3370 {
3371  int rc = 0;
3372  int options = NI_SCALER_FLAG_IO | NI_SCALER_FLAG_PC;
3373  if (p_ctx->isP2P)
3374  options |= NI_SCALER_FLAG_P2;
3375 
3376  /* Allocate a pool of frames by the scaler */
3377  rc = ni_device_alloc_frame(p_ctx, scaler_params.output_width,
3378  scaler_params.output_height,
3379  scaler_params.output_format, options,
3380  0, // rec width
3381  0, // rec height
3382  0, // rec X pos
3383  0, // rec Y pos
3384  NI_MAX_FILTER_POOL_SIZE, // rgba color/pool size
3385  0, // frame index
3387  return rc;
3388 }
3389 
3390 /*!*****************************************************************************
3391 * \brief Allocate memory for the frame buffer based on provided parameters
3392 * taking into account pic line size and extra data.
3393 * Applicable to nv12 AVFrame only. Cb/Cr size matches that of Y.
3394 *
3395 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3396 *
3397 * \param[in] video_width Width of the video frame
3398 * \param[in] video_height Height of the video frame
3399 * \param[in] linesize Picture line size
3400 * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3401 * to allocate any buffer (zero-copy from existing)
3402 * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3403 *
3404 * \return On success
3405 * NI_RETCODE_SUCCESS
3406 * On failure
3407 * NI_RETCODE_INVALID_PARAM
3408 * NI_RETCODE_ERROR_MEM_ALOC
3409 *****************************************************************************/
3411  int video_height, int linesize[],
3412  int extra_len, bool alignment_2pass_wa)
3413 {
3414  void* p_buffer = NULL;
3415  int height_aligned;
3416  int retval = NI_RETCODE_SUCCESS;
3417 
3418  if ((!p_frame) || (!linesize) || (linesize[0] <= 0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3419  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
3420  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
3421  {
3422  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3423  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3424  __func__, p_frame, linesize, video_width, video_height);
3425  return NI_RETCODE_INVALID_PARAM;
3426  }
3427 
3428  height_aligned = ((video_height + 1) / 2) * 2;
3429 
3430  if (height_aligned < NI_MIN_HEIGHT)
3431  {
3432  height_aligned = NI_MIN_HEIGHT;
3433  }
3434 
3436  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d extra_len=%d\n",
3437  __func__, video_width, height_aligned, video_width, video_height,
3438  linesize[0], linesize[1], linesize[2], extra_len);
3439 
3440  int luma_size = linesize[0] * height_aligned;
3441  int chroma_br_size = luma_size / 2;
3442  //int chroma_r_size = luma_size / 4;
3443  if (alignment_2pass_wa)
3444  {
3445  // for 2-pass encode output mismatch WA, need to extend (and pad) CbCr plane height, because 1st pass assume input 32 align
3446  chroma_br_size = linesize[0] * ((((height_aligned + 31) / 32) * 32) / 2);
3447  }
3448  if (extra_len >= 0)
3449  {
3450  int buffer_size = luma_size + chroma_br_size + extra_len;
3451 
3452  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3453 
3454  //Check if Need to free
3455  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3456  {
3457  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
3458  __func__, p_frame->buffer_size);
3459  ni_frame_buffer_free(p_frame);
3460  }
3461 
3462  //Check if need to realocate
3463  if (p_frame->buffer_size != buffer_size)
3464  {
3465  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3466  {
3467  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3468  NI_ERRNO, __func__);
3469  retval = NI_RETCODE_ERROR_MEM_ALOC;
3470  LRETURN;
3471  }
3472 
3473  // init once after allocation
3474  memset(p_buffer, 0, buffer_size);
3475  p_frame->buffer_size = buffer_size;
3476  p_frame->p_buffer = p_buffer;
3477 
3478  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3479  }
3480  else
3481  {
3482  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3483  }
3484 
3485  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3486  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3487  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_br_size;
3488  }
3489  else
3490  {
3491  p_frame->buffer_size = 0; //no ownership
3492  }
3493  p_frame->data_len[0] = luma_size;
3494  p_frame->data_len[1] = chroma_br_size;
3495  p_frame->data_len[2] = 0;
3496 
3497  p_frame->video_width = video_width;
3498  p_frame->video_height = height_aligned;
3499 
3500  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
3501  p_frame->buffer_size);
3502 
3503 END:
3504 
3505  if (NI_RETCODE_SUCCESS != retval)
3506  {
3507  ni_aligned_free(p_buffer);
3508  }
3509 
3510  return retval;
3511 }
3512 
3513 /*!*****************************************************************************
3514  * \brief This API is a wrapper for ni_encoder_frame_buffer_alloc(), used
3515  * for planar pixel formats, and ni_frame_buffer_alloc_nv(), used for
3516  * semi-planar pixel formats. This API is meant to combine the
3517  * functionality for both individual format APIs.
3518  * Allocate memory for the frame buffer for encoding based on given
3519  * parameters, taking into account pic line size and extra data.
3520  * Applicable to YUV420p(8 or 10 bit/pixel) or nv12 AVFrame.
3521  * Cb/Cr size matches that of Y.
3522  *
3523  * \param[in] planar true: if planar:
3524  * pixel_format == (NI_PIX_FMT_YUV420P ||
3525  * NI_PIX_FMT_YUV420P10LE ||NI_PIX_FMT_RGBA).
3526  * false: semi-planar:
3527  * pixel_format == (NI_PIX_FMT_NV12 ||
3528  * NI_PIX_FMT_P010LE).
3529  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3530  * \param[in] video_width Width of the video frame
3531  * \param[in] video_height Height of the video frame
3532  * \param[in] linesize Picture line size
3533  * \param[in] alignment Allignment requirement. Only used for planar format.
3534  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3535  * to allocate any buffer (zero-copy from existing)
3536  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3537  *
3538  * \return On success
3539  * NI_RETCODE_SUCCESS
3540  * On failure
3541  * NI_RETCODE_INVALID_PARAM
3542  * NI_RETCODE_ERROR_MEM_ALOC
3543  *****************************************************************************/
3545  int video_width, int video_height,
3546  int linesize[], int alignment,
3547  int extra_len,
3548  bool alignment_2pass_wa)
3549 {
3550  if (true == planar)
3551  {
3552  return ni_encoder_frame_buffer_alloc(p_frame, video_width, video_height,
3553  linesize, alignment, extra_len,
3554  alignment_2pass_wa);
3555  }
3556  else
3557  {
3558  return ni_frame_buffer_alloc_nv(p_frame, video_width, video_height,
3559  linesize, extra_len,
3560  alignment_2pass_wa);
3561  }
3562 }
3563 
3564 /*!*****************************************************************************
3565  * \brief Free frame buffer that was previously allocated with either
3566  * ni_frame_buffer_alloc or ni_encoder_frame_buffer_alloc or
3567  * ni_frame_buffer_alloc_nv
3568  *
3569  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3570  *
3571  * \return On success NI_RETCODE_SUCCESS
3572  * On failure NI_RETCODE_INVALID_PARAM
3573  ******************************************************************************/
3575 {
3576  int i;
3578 
3579  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3580 
3581  if (!p_frame)
3582  {
3583  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3584  LRETURN;
3585  }
3586 
3587  if (!p_frame->p_buffer)
3588  {
3589  ni_log(NI_LOG_DEBUG, "WARN: %s(): already freed, nothing to free\n",
3590  __func__);
3591  }
3592 
3593 #ifndef _WIN32
3594  // If this is a hardware frame with a DMA buf fd attached, close the DMA buf fd
3595  if ((p_frame->data_len[3] > 0) && (p_frame->p_data[3] != NULL))
3596  {
3597  niFrameSurface1_t *p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
3598  if ((p_surface->dma_buf_fd > 0) && (p_surface->ui16FrameIdx > 0))
3599  {
3600  // Close the DMA buf fd
3602  "%s: close p_surface->dma_buf_fd %d "
3603  "ui16FrameIdx %u\n",
3604  __func__, p_surface->dma_buf_fd, p_surface->ui16FrameIdx);
3605  close(p_surface->dma_buf_fd);
3606  }
3607  }
3608 #endif
3609 
3610  if (p_frame->buffer_size)
3611  {
3612  p_frame->buffer_size = 0;
3613  ni_aligned_free(p_frame->p_buffer);
3614  }
3615 
3616  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3617  {
3618  p_frame->data_len[i] = 0;
3619  p_frame->p_data[i] = NULL;
3620  }
3621 
3622  ni_frame_wipe_aux_data(p_frame);
3623 
3624  if (p_frame->metadata_buffer_size)
3625  {
3626  p_frame->metadata_buffer_size = 0;
3628  }
3629  p_frame->separate_metadata = 0;
3630 
3631  if (p_frame->start_buffer_size)
3632  {
3633  p_frame->start_buffer_size = 0;
3634  ni_aligned_free(p_frame->p_start_buffer);
3635  }
3636  p_frame->separate_start = 0;
3637  memset(p_frame->start_len, 0, sizeof(p_frame->start_len));
3638  p_frame->total_start_len = 0;
3639  p_frame->inconsecutive_transfer = 0;
3640 
3641 END:
3642 
3643  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3644 
3645  return retval;
3646 }
3647 
3648 /*!*****************************************************************************
3649  * \brief Free decoder frame buffer that was previously allocated with
3650  * ni_decoder_frame_buffer_alloc, returning memory to a buffer pool.
3651  *
3652  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3653  *
3654  * \return On success NI_RETCODE_SUCCESS
3655  * On failure NI_RETCODE_INVALID_PARAM
3656  ******************************************************************************/
3658 {
3659  int i;
3661 
3662  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3663 
3664  if (!p_frame)
3665  {
3666  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3667  retval = NI_RETCODE_INVALID_PARAM;
3668  LRETURN;
3669  }
3670 
3671  if (p_frame->dec_buf)
3672  {
3674  ni_log(NI_LOG_DEBUG, "%s(): Mem buf returned ptr %p buf %p !\n", __func__,
3675  p_frame->dec_buf->buf, p_frame->dec_buf);
3676  }
3677  else
3678  {
3679  ni_log(NI_LOG_DEBUG, "%s(): NO mem buf returned !\n", __func__);
3680  }
3681 
3682  p_frame->dec_buf = NULL;
3683  p_frame->p_buffer = NULL;
3684  p_frame->buffer_size = 0;
3685  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3686  {
3687  p_frame->data_len[i] = 0;
3688  p_frame->p_data[i] = NULL;
3689  }
3690  ni_frame_wipe_aux_data(p_frame);
3691 
3692 END:
3693 
3694  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3695 
3696  return retval;
3697 }
3698 
3699 /*!*****************************************************************************
3700  * \brief Return a memory buffer to memory buffer pool.
3701  *
3702  * \param[in] buf Buffer to be returned.
3703  * \param[in] p_buffer_pool Buffer pool to return buffer to.
3704  *
3705  * \return None
3706  ******************************************************************************/
3708  ni_buf_pool_t *p_buffer_pool)
3709 {
3710  ni_buf_pool_return_buffer(buf, p_buffer_pool);
3711 }
3712 
3713 /*!*****************************************************************************
3714  * \brief Allocate memory for the packet buffer based on provided packet size
3715  *
3716  * \param[in] p_packet Pointer to a caller allocated
3717  * ni_packet_t struct
3718  * \param[in] packet_size Required allocation size
3719  *
3720  * \return On success
3721  * NI_RETCODE_SUCCESS
3722  * On failure
3723  * NI_RETCODE_INVALID_PARAM
3724  * NI_RETCODE_ERROR_MEM_ALOC
3725  ******************************************************************************/
3727 {
3728  void* p_buffer = NULL;
3729  int metadata_size = 0;
3730 
3731  metadata_size = NI_FW_META_DATA_SZ;
3732 
3733  int buffer_size = (((packet_size + metadata_size) / NI_MAX_PACKET_SZ) + 1) * NI_MAX_PACKET_SZ;
3734 
3735  ni_log(NI_LOG_TRACE, "%s: packet_size=%d\n", __func__,
3736  packet_size + metadata_size);
3737 
3738  if (!p_packet || !packet_size)
3739  {
3740  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3741  __func__);
3742  return NI_RETCODE_INVALID_PARAM;
3743  }
3744 
3745  if (buffer_size % NI_MEM_PAGE_ALIGNMENT)
3746  {
3747  buffer_size = ( (buffer_size / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT ) + NI_MEM_PAGE_ALIGNMENT;
3748  }
3749 
3750  if (p_packet->buffer_size == buffer_size)
3751  {
3752  // Already allocated the exact size.
3753  p_packet->p_data = p_packet->p_buffer;
3754  ni_log(NI_LOG_DEBUG, "%s: reuse current p_packet buffer\n", __func__);
3755  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3756  p_packet->buffer_size);
3757  return NI_RETCODE_SUCCESS;
3758  }
3759 
3760  if (p_packet->buffer_size)
3761  {
3763  "%s: free current p_packet, p_packet->buffer_size=%u\n", __func__,
3764  p_packet->buffer_size);
3765  ni_packet_buffer_free(p_packet);
3766  }
3767 
3768  ni_log(NI_LOG_DEBUG, "%s: Allocating p_frame buffer, buffer_size=%d\n",
3769  __func__, buffer_size);
3770 
3771  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3772  {
3773  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
3774  NI_ERRNO, __func__);
3775  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3776  p_packet->buffer_size);
3778  }
3779 
3780  p_packet->buffer_size = buffer_size;
3781  p_packet->p_buffer = p_buffer;
3782  p_packet->p_data = p_packet->p_buffer;
3783 
3784  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3785  p_packet->buffer_size);
3786 
3787  return NI_RETCODE_SUCCESS;
3788 }
3789 
3790 /*!*****************************************************************************
3791  * \brief Allocate packet buffer using a user provided pointer, the memory
3792  * is expected to have already been allocated.
3793  *
3794  * For ideal performance memory should be 4k aligned. If it is not 4K aligned
3795  * then a temporary 4k aligned memory will be used to copy data to and from
3796  * when writing and reading. This will negatively impact performance.
3797  *
3798  * This API will overwrite p_packet->buffer_size, p_packet->p_buffer and
3799  * p_packet->p_data fields in p_packet.
3800  *
3801  * This API will not free any memory associated with p_packet->p_buffer and
3802  * p_packet->p_data fields in p_packet.
3803  * Common use case could be,
3804  * 1. Allocate memory to pointer
3805  * 2. Call ni_custom_packet_buffer_alloc() with allocated pointer.
3806  * 3. Use p_packet as required.
3807  * 4. Call ni_packet_buffer_free() to free up the memory.
3808  *
3809  * \param[in] p_buffer User provided pointer to be used for buffer
3810  * \param[in] p_packet Pointer to a caller allocated
3811  * ni_packet_t struct
3812  * \param[in] buffer_size Buffer size
3813  *
3814  * \return On success
3815  * NI_RETCODE_SUCCESS
3816  * On failure
3817  * NI_RETCODE_INVALID_PARAM
3818  * NI_RETCODE_ERROR_MEM_ALOC
3819  ******************************************************************************/
3821  ni_packet_t *p_packet,
3822  int buffer_size)
3823 {
3824  ni_log(NI_LOG_TRACE, "%s(): enter buffer_size=%d\n", __func__, buffer_size);
3825 
3826  if (!p_buffer || !p_packet || !buffer_size)
3827  {
3828  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3829  __func__);
3830  return NI_RETCODE_INVALID_PARAM;
3831  }
3832  if (((uintptr_t)p_buffer) % NI_MEM_PAGE_ALIGNMENT)
3833  {
3834  ni_log(NI_LOG_INFO, "Info: %s: Warning buffer not 4k aligned = %p!. Will do an extra copy\n",
3835  __func__, p_buffer);
3836  }
3837 
3838  p_packet->buffer_size = buffer_size;
3839  p_packet->p_buffer = p_buffer;
3840  p_packet->p_data = p_packet->p_buffer;
3841 
3842  ni_log(NI_LOG_TRACE, "%s: exit: \n", __func__);
3843 
3844  return NI_RETCODE_SUCCESS;
3845 }
3846 
3847 /*!*****************************************************************************
3848  * \brief Free packet buffer that was previously allocated with
3849  * ni_packet_buffer_alloc
3850  *
3851  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
3852  *
3853  * \return On success NI_RETCODE_SUCCESS
3854  * On failure NI_RETCODE_INVALID_PARAM
3855  ******************************************************************************/
3857 {
3859 
3860  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
3861 
3862  if (!p_packet)
3863  {
3864  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
3865  retval = NI_RETCODE_FAILURE;
3866  LRETURN;
3867  }
3868 
3869  if (!p_packet->p_buffer)
3870  {
3871  ni_log(NI_LOG_DEBUG, "%s(): already freed, nothing to free\n", __func__);
3872  LRETURN;
3873  }
3874 
3875  ni_aligned_free(p_packet->p_buffer);
3876  p_packet->p_buffer = NULL;
3877  p_packet->buffer_size = 0;
3878  p_packet->data_len = 0;
3879  p_packet->p_data = NULL;
3880 
3881  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
3882 
3883 END:
3884 
3885  return retval;
3886 }
3887 
3888 /*!*****************************************************************************
3889  * \brief Free packet buffer that was previously allocated with
3890  * ni_packet_buffer_alloc for AV1 packets merge
3891  *
3892  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
3893  *
3894  * \return On success NI_RETCODE_SUCCESS
3895  * On failure NI_RETCODE_INVALID_PARAM
3896  ******************************************************************************/
3898 {
3899  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
3901  int i;
3902 
3903  if (!p_packet)
3904  {
3905  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
3906  retval = NI_RETCODE_FAILURE;
3907  LRETURN;
3908  }
3909 
3910  if (!p_packet->av1_buffer_index)
3911  {
3913  "%s(): no need to free previous av1 packet buffers\n", __func__);
3914  LRETURN;
3915  }
3916 
3917  for (i = 0; i < p_packet->av1_buffer_index; i++)
3918  {
3919  ni_log(NI_LOG_DEBUG, "%s(): free previous av1 packet buffer %d\n",
3920  __func__, i);
3921  ni_aligned_free(p_packet->av1_p_buffer[i]);
3922  p_packet->av1_p_buffer[i] = NULL;
3923  p_packet->av1_p_data[i] = NULL;
3924  p_packet->av1_buffer_size[i] = 0;
3925  p_packet->av1_data_len[i] = 0;
3926  }
3927 
3928  p_packet->av1_buffer_index = 0;
3929 
3930 END:
3931 
3932  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
3933 
3934  return retval;
3935 }
3936 
3937 /*!*****************************************************************************
3938  * \brief Copy video packet accounting for alignment
3939  *
3940  * \param[in] p_destination Destination to where to copy to
3941  * \param[in] p_source Source from where to copy from
3942  * \param[in] cur_size current size
3943  * \param[out] p_leftover Pointer to the data that was left over
3944  * \param[out] p_prev_size Size of the data leftover ??
3945  *
3946  * \return On success Total number of bytes that were copied
3947  * On failure NI_RETCODE_FAILURE
3948  ******************************************************************************/
3949 int ni_packet_copy(void* p_destination, const void* const p_source, int cur_size, void* p_leftover, int* p_prev_size)
3950 {
3951  int copy_size = 0;
3952  int padding_size = 0;
3953  int prev_size = p_prev_size == NULL? 0 : *p_prev_size;
3954 
3955  int total_size = cur_size + prev_size;
3956  uint8_t* p_src = (uint8_t*)p_source;
3957  uint8_t* p_dst = (uint8_t*)p_destination;
3958  uint8_t* p_lftover = (uint8_t*)p_leftover;
3959 
3960  if (!p_prev_size)
3961  {
3962  return NI_RETCODE_INVALID_PARAM;
3963  }
3964 
3965  ni_log(NI_LOG_TRACE, "%s(): enter, *prev_size=%d\n", __func__, *p_prev_size);
3966 
3967  if ((0 == cur_size) && (0 == prev_size))
3968  {
3969  return copy_size;
3970  }
3971 
3972  if (((0 != cur_size) && (!p_source)) || (!p_destination) || (!p_leftover))
3973  {
3974  return NI_RETCODE_FAILURE;
3975  }
3976 
3977  copy_size = ((total_size + NI_MEM_PAGE_ALIGNMENT - 1) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT;
3978 
3979  if (copy_size > total_size)
3980  {
3981  padding_size = copy_size - total_size;
3982  }
3983 
3984  if (prev_size > 0)
3985  {
3986  memcpy(p_dst, p_lftover, prev_size);
3987  }
3988 
3989  p_dst += prev_size;
3990 
3991  memcpy(p_dst, p_src, cur_size);
3992 
3993  if (padding_size)
3994  {
3995  p_dst += cur_size;
3996  memset(p_dst, 0, padding_size);
3997  }
3998 
4000  "%s(): exit, cur_size=%d, copy_size=%d, "
4001  "prev_size=%d, padding_size=%d\n", __func__, cur_size,
4002  copy_size, *p_prev_size, padding_size);
4003 
4004  *p_prev_size = 0;
4005 
4006  return copy_size;
4007 }
4008 
4009 /*!*****************************************************************************
4010  * \brief Add a new auxiliary data to a frame
4011  *
4012  * \param[in/out] frame a frame to which the auxiliary data should be added
4013  * \param[in] type type of the added auxiliary data
4014  * \param[in] data_size size of the added auxiliary data
4015  *
4016  * \return a pointer to the newly added aux data on success, NULL otherwise
4017  ******************************************************************************/
4019  int data_size)
4020 {
4021  ni_aux_data_t *ret;
4022 
4024  !(ret = malloc(sizeof(ni_aux_data_t))))
4025  {
4027  "ERROR: %s No memory or exceeding max aux_data number !\n",
4028  __func__);
4029  return NULL;
4030  }
4031 
4032  ret->type = type;
4033  ret->size = data_size;
4034  ret->data = calloc(1, data_size);
4035  if (!ret->data)
4036  {
4037  ni_log(NI_LOG_ERROR, "ERROR: %s No memory for aux data !\n", __func__);
4038  free(ret);
4039  ret = NULL;
4040  } else
4041  {
4042  frame->aux_data[frame->nb_aux_data++] = ret;
4043  }
4044 
4045  return ret;
4046 }
4047 
4048 /*!*****************************************************************************
4049  * \brief Add a new auxiliary data to a frame and copy in the raw data
4050  *
4051  * \param[in/out] frame a frame to which the auxiliary data should be added
4052  * \param[in] type type of the added auxiliary data
4053  * \param[in] raw_data the raw data of the aux data
4054  * \param[in] data_size size of the added auxiliary data
4055  *
4056  * \return a pointer to the newly added aux data on success, NULL otherwise
4057  ******************************************************************************/
4059  ni_aux_data_type_t type,
4060  const uint8_t *raw_data,
4061  int data_size)
4062 {
4063  ni_aux_data_t *ret = ni_frame_new_aux_data(frame, type, data_size);
4064  if (ret)
4065  {
4066  memcpy(ret->data, raw_data, data_size);
4067  }
4068  return ret;
4069 }
4070 
4071 /*!*****************************************************************************
4072  * \brief Retrieve from the frame auxiliary data of a given type if exists
4073  *
4074  * \param[in] frame a frame from which the auxiliary data should be retrieved
4075  * \param[in] type type of the auxiliary data to be retrieved
4076  *
4077  * \return a pointer to the aux data of a given type on success, NULL otherwise
4078  ******************************************************************************/
4080  ni_aux_data_type_t type)
4081 {
4082  int i;
4083  for (i = 0; i < frame->nb_aux_data; i++)
4084  {
4085  if (frame->aux_data[i]->type == type)
4086  {
4087  return frame->aux_data[i];
4088  }
4089  }
4090  return NULL;
4091 }
4092 
4093 /*!*****************************************************************************
4094  * \brief If auxiliary data of the given type exists in the frame, free it
4095  * and remove it from the frame.
4096  *
4097  * \param[in/out] frame a frame from which the auxiliary data should be removed
4098  * \param[in] type type of the auxiliary data to be removed
4099  *
4100  * \return None
4101  ******************************************************************************/
4103 {
4104  int i;
4105  ni_aux_data_t *aux;
4106 
4107  for (i = 0; i < frame->nb_aux_data; i++)
4108  {
4109  aux = frame->aux_data[i];
4110  if (aux->type == type)
4111  {
4112  frame->aux_data[i] = frame->aux_data[frame->nb_aux_data - 1];
4113  frame->aux_data[frame->nb_aux_data - 1] = NULL;
4114  frame->nb_aux_data--;
4115  free(aux->data);
4116  free(aux);
4117  }
4118  }
4119 }
4120 
4121 /*!*****************************************************************************
4122  * \brief Free and remove all auxiliary data from the frame.
4123  *
4124  * \param[in/out] frame a frame from which the auxiliary data should be removed
4125  *
4126  * \return None
4127  ******************************************************************************/
4129 {
4130  int i;
4131  ni_aux_data_t *aux;
4132 
4133  for (i = 0; i < frame->nb_aux_data; i++)
4134  {
4135  aux = frame->aux_data[i];
4136  free(aux->data);
4137  free(aux);
4138  }
4139  frame->nb_aux_data = 0;
4140 }
4141 
4142 /*!*****************************************************************************
4143  * \brief Initialize default encoder parameters
4144  *
4145  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4146  * to initialize to default parameters
4147  * \param[in] fps_num Frames per second
4148  * \param[in] fps_denom FPS denomination
4149  * \param[in] bit_rate bit rate
4150  * \param[in] width frame width
4151  * \param[in] height frame height
4152  * \param[in] codec_format codec from ni_codec_format_t
4153  *
4154  * \return On success
4155  * NI_RETCODE_SUCCESS
4156  * On failure
4157  * NI_RETCODE_FAILURE
4158  * NI_RETCODE_INVALID_PARAM
4159  ******************************************************************************/
4161  int fps_num, int fps_denom,
4162  long bit_rate, int width,
4163  int height,
4164  ni_codec_format_t codec_format)
4165 {
4166  ni_encoder_cfg_params_t *p_enc = NULL;
4167  int i = 0, j = 0;
4169 
4170  //Initialize p_param structure
4171  if (!p_param)
4172  {
4173  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
4174  __func__);
4175  retval = NI_RETCODE_INVALID_PARAM;
4176  LRETURN;
4177  }
4178 
4179  ni_log(NI_LOG_DEBUG, "%s()\n", __func__);
4180 
4181  //Initialize p_param structure
4182  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4183 
4184  p_enc = &p_param->cfg_enc_params;
4185 
4186  // Rev. B: unified for HEVC/H.264
4187  p_enc->profile = 0;
4188  p_enc->level_idc = 0;
4189  p_enc->high_tier = 0;
4190 
4191  if (QUADRA)
4193  else
4195 
4196  p_enc->use_recommend_enc_params = 0;
4197  p_enc->cu_size_mode = 7;
4198  p_enc->max_num_merge = 2;
4199  p_enc->enable_dynamic_8x8_merge = 1;
4200  p_enc->enable_dynamic_16x16_merge = 1;
4201  p_enc->enable_dynamic_32x32_merge = 1;
4202 
4203  p_enc->rc.trans_rate = 0;
4204 
4205  p_enc->rc.enable_rate_control = 0;
4206  if (QUADRA)
4207  p_enc->rc.enable_cu_level_rate_control = 0;
4208  else
4209  p_enc->rc.enable_cu_level_rate_control = 1;
4210  p_enc->rc.enable_hvs_qp = 0;
4211  p_enc->rc.enable_hvs_qp_scale = 1;
4212  p_enc->rc.hvs_qp_scale = 2;
4213  p_enc->rc.min_qp = 8;
4214  p_enc->rc.max_qp = 51;
4215  p_enc->rc.max_delta_qp = 10;
4216 
4217  // hrd is disabled if vbv_buffer_size=0, hrd is enabled if vbv_buffer_size is [10, 3000]
4218  p_enc->rc.vbv_buffer_size = -1;
4219  p_enc->rc.enable_filler = 0;
4220  p_enc->rc.enable_pic_skip = 0;
4221  p_enc->rc.vbv_max_rate = 0;
4222 
4223  p_enc->roi_enable = 0;
4224 
4226  // feature not supported on JPEG/AV1 - disable by default
4227  if (codec_format == NI_CODEC_FORMAT_JPEG ||
4228  codec_format == NI_CODEC_FORMAT_AV1)
4229  {
4231  }
4232 
4233  p_enc->long_term_ref_enable = 0;
4234  p_enc->long_term_ref_interval = 0;
4235  p_enc->long_term_ref_count = 2;
4236 
4237  p_enc->conf_win_top = 0;
4238  p_enc->conf_win_bottom = 0;
4239  p_enc->conf_win_left = 0;
4240  p_enc->conf_win_right = 0;
4241 
4242  p_enc->intra_period = 120;
4243  p_enc->rc.intra_qp = 22;
4244  p_enc->rc.intra_qp_delta = -2;
4245  if (QUADRA)
4246  p_enc->rc.enable_mb_level_rc = 0;
4247  else
4248  p_enc->rc.enable_mb_level_rc = 1;
4249 
4250  p_enc->decoding_refresh_type = 1;
4251 
4252  p_enc->slice_mode = 0;
4253  p_enc->slice_arg = 0;
4254 
4255  // Rev. B: H.264 only parameters.
4256  p_enc->enable_transform_8x8 = 1;
4257  p_enc->entropy_coding_mode = 1;
4258 
4259  p_enc->intra_mb_refresh_mode = 0;
4260  p_enc->intra_mb_refresh_arg = 0;
4261  p_enc->intra_reset_refresh = 0;
4262 
4264 #ifndef QUADRA
4265  if (!QUADRA)
4266  {
4267  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4268  {
4270  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4271  p_enc->custom_gop_params.pic_param[i].pic_qp = 0;
4272  p_enc->custom_gop_params.pic_param[i].num_ref_pic_L0 = 0;
4273  p_enc->custom_gop_params.pic_param[i].ref_poc_L0 = 0;
4274  p_enc->custom_gop_params.pic_param[i].ref_poc_L1 = 0;
4275  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4276  }
4277  }
4278  else // QUADRA
4279 #endif
4280  {
4281  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4282  {
4283  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4284  p_enc->custom_gop_params.pic_param[i].qp_offset = 0;
4286  (float)0.3; // QP Factor range is between 0.3 and 1, higher values mean lower quality and less bits
4287  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4290  for (j = 0; j < NI_MAX_REF_PIC; j++)
4291  {
4292  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic = 0;
4293  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic_used = -1;
4294  }
4295  }
4296  }
4297 
4298  p_param->source_width = width;
4299  p_param->source_height = height;
4300 
4301  p_param->fps_number = fps_num;
4302  p_param->fps_denominator = fps_denom;
4303 
4304  if (p_param->fps_number && p_param->fps_denominator)
4305  {
4306  p_enc->frame_rate = (int)(p_param->fps_number / p_param->fps_denominator);
4307  }
4308  else
4309  {
4310  p_enc->frame_rate = 30;
4311  }
4312 
4313  p_param->bitrate = (int)bit_rate;
4314  p_param->roi_demo_mode = 0;
4315  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4316  p_param->force_pic_qp_demo_mode = 0;
4317  p_param->force_frame_type = 0;
4318  p_param->hdrEnableVUI = 0;
4319  p_param->cacheRoi = 0;
4320  p_param->low_delay_mode = 0;
4321  p_param->padding = 1;
4322  p_param->generate_enc_hdrs = 0;
4323  p_param->use_low_delay_poc_type = 0;
4324  p_param->rootBufId = 0;
4325  p_param->staticMmapThreshold = 0;
4326  p_param->zerocopy_mode = 1;
4327  p_param->luma_linesize = 0;
4328  p_param->chroma_linesize = 0;
4329  p_param ->enableCpuAffinity = 0;
4330 
4332 
4333  p_param->dolby_vision_profile = 0;
4334 
4335  // encoder stream header VUI setting
4336  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4337  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4338  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4339  p_param->sar_num = 0; // default SAR numerator 0
4340  p_param->sar_denom = 1; // default SAR denominator 1
4341  p_param->video_full_range_flag = -1;
4342 
4343  p_param->enable2PassGop = 0;
4345  p_param->minFramesDelay = 0;
4346  p_param->interval_of_psnr = 1;
4347  for (i = 0; i < NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL; i++) {
4348  for (j = 0; j < NI_CUSTOMIZE_ROI_QP_NUM; j++) {
4349  // 127 is invalid for delta qp and absolute qp
4350  p_param->customize_roi_qp_map[i][j] = 127;
4351  }
4352  }
4353 
4354  //QUADRA
4355  p_enc->EnableAUD = 0;
4356  p_enc->lookAheadDepth = 0;
4357  p_enc->rdoLevel = (codec_format == NI_CODEC_FORMAT_JPEG) ? 0 : 1;
4358  p_enc->crf = -1;
4359  p_enc->HDR10MaxLight = 0;
4360  p_enc->HDR10AveLight = 0;
4361  p_enc->HDR10CLLEnable = 0;
4362  p_enc->EnableRdoQuant = 0;
4363  p_enc->ctbRcMode = 0;
4364  p_enc->gopSize = 0;
4365  p_enc->gopLowdelay = 0;
4366  p_enc->gdrDuration = 0;
4367  p_enc->hrdEnable = 0;
4368  p_enc->ltrRefInterval = 0;
4369  p_enc->ltrRefQpOffset = 0;
4370  p_enc->ltrFirstGap = 0;
4371  p_enc->ltrNextInterval = 1;
4372  p_enc->multicoreJointMode = 0;
4373  p_enc->qlevel = -1;
4374  p_enc->maxFrameSize = 0;
4375  p_enc->maxFrameSizeRatio = 0;
4376  p_enc->chromaQpOffset = 0;
4377  p_enc->tolCtbRcInter = (float)0.1;
4378  p_enc->tolCtbRcIntra = (float)0.1;
4379  p_enc->bitrateWindow = -255;
4380  p_enc->inLoopDSRatio = 1;
4381  p_enc->blockRCSize = 0;
4382  p_enc->rcQpDeltaRange = 10;
4383  p_enc->ctbRowQpStep = 0;
4384  p_enc->newRcEnable = -1;
4385  p_enc->colorDescPresent = 0;
4386  p_enc->colorPrimaries = 2;
4387  p_enc->colorTrc = 2;
4388  p_enc->colorSpace = 2;
4389  p_enc->aspectRatioWidth = 0;
4390  p_enc->aspectRatioHeight = 1;
4391  p_enc->videoFullRange = 0;
4393  p_enc->enable_ssim = 0;
4394  p_enc->HDR10Enable = 0;
4395  p_enc->HDR10dx0 = 0;
4396  p_enc->HDR10dy0 = 0;
4397  p_enc->HDR10dx1 = 0;
4398  p_enc->HDR10dy1 = 0;
4399  p_enc->HDR10dx2 = 0;
4400  p_enc->HDR10dy2 = 0;
4401  p_enc->HDR10wx = 0;
4402  p_enc->HDR10wy = 0;
4403  p_enc->HDR10maxluma = 0;
4404  p_enc->HDR10minluma = 0;
4405  p_enc->avcc_hvcc = 0;
4406  p_enc->av1_error_resilient_mode = 0;
4407  p_enc->temporal_layers_enable = 0;
4408  p_enc->crop_width = 0;
4409  p_enc->crop_height = 0;
4410  p_enc->hor_offset = 0;
4411  p_enc->ver_offset = 0;
4412  p_enc->crfMax = -1;
4413  p_enc->qcomp = (float)0.6;
4414  p_enc->noMbtree = 0;
4415  p_enc->noHWMultiPassSupport = 0;
4416  p_enc->cuTreeFactor = 5;
4417  p_enc->ipRatio = (float)1.4;
4418  p_enc->pbRatio = (float)1.3;
4419  p_enc->cplxDecay = (float)0.5;
4420  p_enc->pps_init_qp = -1;
4421  p_enc->bitrateMode = -1; // -1 = not set, bitrateMode 0 = max bitrate (actual bitrate can be lower than bitrate), bitrateMode 1 = average bitrate (actual bitrate approximately equal to bitrate)
4422  p_enc->pass1_qp = -1;
4423  p_enc->crfFloat = -1.0f;
4424  p_enc->hvsBaseMbComplexity = 15;
4425  p_enc->statistic_output_level = 0;
4426  p_enc->skip_frame_enable = 0;
4427  p_enc->max_consecutive_skip_num = 1;
4428  p_enc->skip_frame_interval = 0;
4429  p_enc->enableipRatio = 0;
4430  p_enc->enable_all_sei_passthru = 0;
4431  p_enc->iframe_size_ratio = 100;
4432  p_enc->crf_max_iframe_enable = 0;
4433  p_enc->vbv_min_rate = 0;
4434  p_enc->totalCuTreeDepth = 0;
4435  p_enc->adaptiveCuTree = 0;
4436  p_enc->preIntraHandling = 1;
4437  p_enc->baseLayerOnly = 0;
4438  p_enc->pastFrameMaxIntraRatio = 20;
4439  p_enc->linkFrameMaxIntraRatio = 40;
4440 #ifdef XCODER_311
4441  p_enc->disable_adaptive_buffers = 1;
4442 #else
4443  p_enc->disable_adaptive_buffers = 0;
4444 #endif
4445  p_enc->disableBframeRdoq = 0;
4446  p_enc->forceBframeQpfactor = (float)-1.0;
4447  p_enc->tune_bframe_visual = 0;
4448  p_enc->enable_acq_limit = 0;
4449  p_enc->get_psnr_mode = 3;
4451  p_enc->motionConstrainedMode = 0;
4452  p_enc->still_image_detect_level = 0;
4453  p_enc->scene_change_detect_level = 0;
4454  p_enc->encMallocStrategy = 0;
4455  p_enc->enable_smooth_crf = 0;
4456  p_enc->enable_compensate_qp = 0;
4457  p_enc->spatial_layers = 1;
4458  p_enc->enable_timecode = 0;
4459  p_enc->spatial_layers_ref_base_layer = 0;
4460  p_enc->vbvBufferReencode = 0;
4461  p_enc->disableAv1TimingInfo = 0;
4462  for (i = 0; i < NI_MAX_SPATIAL_LAYERS; i++)
4463  {
4464  p_enc->spatialLayerBitrate[i] = 0;
4465  p_enc->av1OpLevel[i] = 0;
4466  }
4467 
4468  if (codec_format == NI_CODEC_FORMAT_AV1)
4469  {
4470  if (p_param->source_width < NI_PARAM_AV1_MIN_WIDTH)
4471  {
4473  LRETURN;
4474  }
4475  if (p_param->source_height < NI_PARAM_AV1_MIN_HEIGHT)
4476  {
4478  LRETURN;
4479  }
4480  if (p_param->source_width > NI_PARAM_AV1_MAX_WIDTH)
4481  {
4483  LRETURN;
4484  }
4485  if (p_param->source_height > NI_PARAM_AV1_MAX_HEIGHT)
4486  {
4488  LRETURN;
4489  }
4490  if (p_param->source_height * p_param->source_width >
4492  {
4494  LRETURN;
4495  }
4496  // AV1 8x8 alignment HW limitation is now worked around by FW cropping input resolution
4498  {
4499  ni_log(NI_LOG_ERROR, "AV1 Picture Width not aligned to %d - picture will be cropped\n",
4501  }
4503  {
4504  ni_log(NI_LOG_ERROR, "AV1 Picture Height not aligned to %d - picture will be cropped\n",
4506  }
4507  }
4508 
4509  if (codec_format == NI_CODEC_FORMAT_JPEG)
4510  {
4511  if (p_param->source_width < NI_MIN_WIDTH)
4512  {
4514  LRETURN;
4515  }
4516  if (p_param->source_height < NI_MIN_HEIGHT)
4517  {
4519  LRETURN;
4520  }
4521  }
4522 
4523  if (p_param->source_width > NI_PARAM_MAX_WIDTH)
4524  {
4526  LRETURN;
4527  }
4528  if (p_param->source_width < NI_PARAM_MIN_WIDTH)
4529  {
4531  LRETURN;
4532  }
4533 
4534  if (p_param->source_height > NI_PARAM_MAX_HEIGHT)
4535  {
4537  LRETURN;
4538  }
4539  if (p_param->source_height < NI_PARAM_MIN_HEIGHT)
4540  {
4542  LRETURN;
4543  }
4544  if (p_param->source_height*p_param->source_width > NI_MAX_RESOLUTION_AREA)
4545  {
4547  LRETURN;
4548  }
4549 
4550 END:
4551 
4552  return retval;
4553 }
4554 
4555 /*!*****************************************************************************
4556  * \brief Initialize default decoder parameters
4557  *
4558  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4559  * to initialize to default parameters
4560  * \param[in] fps_num Frames per second
4561  * \param[in] fps_denom FPS denomination
4562  * \param[in] bit_rate bit rate
4563  * \param[in] width frame width
4564  * \param[in] height frame height
4565  *
4566  * \return On success
4567  * NI_RETCODE_SUCCESS
4568  * On failure
4569  * NI_RETCODE_FAILURE
4570  * NI_RETCODE_INVALID_PARAM
4571  ******************************************************************************/
4573  int fps_num, int fps_denom,
4574  long bit_rate, int width,
4575  int height)
4576 {
4577  ni_decoder_input_params_t* p_dec = NULL;
4578  int i;
4580 
4581  //Initialize p_param structure
4582  if (!p_param)
4583  {
4584  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameter passed\n",
4585  __func__);
4586  retval = NI_RETCODE_INVALID_PARAM;
4587  LRETURN;
4588  }
4589 
4590  ni_log(NI_LOG_DEBUG, "%s\n", __func__);
4591 
4592  //Initialize p_param structure
4593  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4594 
4595  p_dec = &p_param->dec_input_params;
4596 
4597  p_param->source_width = width;
4598  p_param->source_height = height;
4599 
4600  if(fps_num <= 0 || fps_denom <= 0)
4601  {
4602  fps_num = 30;
4603  fps_denom = 1;
4604  ni_log(NI_LOG_INFO, "%s(): FPS is not set, setting the default FPS to 30\n", __func__);
4605  }
4606 
4607  p_param->fps_number = fps_num;
4608  p_param->fps_denominator = fps_denom;
4609 
4610  p_dec->hwframes = 0;
4611  p_dec->mcmode = 0;
4612  p_dec->nb_save_pkt = 0;
4613  p_dec->enable_out1 = 0;
4614  p_dec->enable_out2 = 0;
4615  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
4616  {
4617  p_dec->force_8_bit[i] = 0;
4618  p_dec->semi_planar[i] = 0;
4619  p_dec->crop_mode[i] = NI_DEC_CROP_MODE_AUTO;
4620  p_dec->crop_whxy[i][0] = width;
4621  p_dec->crop_whxy[i][1] = height;
4622  p_dec->crop_whxy[i][2] = 0;
4623  p_dec->crop_whxy[i][3] = 0;
4624  p_dec->scale_wh[i][0] = 0;
4625  p_dec->scale_wh[i][1] = 0;
4626  p_dec->scale_long_short_edge[i] = 0;
4627  p_dec->scale_resolution_ceil[i] = 2;
4628  p_dec->scale_round[i] = -1;
4629  }
4631  p_dec->decoder_low_delay = 0;
4632  p_dec->force_low_delay = false;
4633  p_dec->enable_low_delay_check = 0;
4634  p_dec->enable_user_data_sei_passthru = 0;
4635  p_dec->custom_sei_passthru = -1;
4638  p_dec->enable_advanced_ec = 1;
4640  p_dec->enable_ppu_scale_adapt = 0;
4641  p_dec->enable_ppu_scale_limit = 0;
4642  p_dec->max_extra_hwframe_cnt = 255; //uint8_max
4643  p_dec->pkt_pts_unchange = 0;
4644  p_dec->enable_all_sei_passthru = 0;
4645  p_dec->enable_follow_iframe = 0;
4647 #ifdef XCODER_311
4648  p_dec->disable_adaptive_buffers = 1;
4649  p_dec->min_packets_delay = true;
4650  p_dec->reduce_dpb_delay = 1;
4651 #else
4652  p_dec->disable_adaptive_buffers = 0;
4653  p_dec->min_packets_delay = false;
4654  p_dec->reduce_dpb_delay = 0;
4655 #endif
4656  p_dec->survive_stream_err = 0;
4657  p_dec->skip_extra_headers = 0;
4658 
4659  //-------init unused param start----------
4660 
4661  p_param->bitrate = (int)bit_rate;
4662  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4663  p_param->force_pic_qp_demo_mode = 0;
4664  p_param->force_frame_type = 0;
4665  p_param->hdrEnableVUI = 0;
4666  p_param->cacheRoi = 0;
4667  p_param->low_delay_mode = 0;
4668  p_param->padding = 1;
4669  p_param->generate_enc_hdrs = 0;
4670  p_param->use_low_delay_poc_type = 0;
4671  p_param->dolby_vision_profile = 0;
4672 
4673  // encoder stream header VUI setting
4674  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4675  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4676  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4677  p_param->sar_num = 0; // default SAR numerator 0
4678  p_param->sar_denom = 1; // default SAR denominator 1
4679  p_param->video_full_range_flag = -1;
4680 
4681  //-------init unused param done----------
4682 
4683 END:
4684 
4685  return retval;
4686 }
4687 
4688 // read demo reconfig data file and parse out reconfig key/values in the format:
4689 // key:val1,val2,val3,...val9 (max 9 values); only digit/:/,/newline is allowed
4690 ni_retcode_t ni_parse_reconf_file(const char *reconf_file,
4692 {
4693  char keyChar[10] = "";
4694  int key;
4695  char valChar[10] = "";
4696  int val;
4697  int valIdx = 1;
4698  int parseKey = 1;
4699  int idx = 0;
4700  int readc = EOF;
4701  FILE *reconf = NULL;
4702 
4703  if (!reconf_file)
4704  {
4705  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4706  __func__);
4707  return NI_RETCODE_INVALID_PARAM;
4708  }
4709 
4710  ni_fopen(&reconf, reconf_file, "r");
4711  if (!reconf)
4712  {
4713  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4714  NI_ERRNO, __func__, reconf_file);
4716  }
4718 
4719  while ((readc = fgetc(reconf)) != EOF)
4720  {
4721  //parse lines
4722  if (isdigit(readc))
4723  {
4724  if (parseKey)
4725  {
4726  ni_strncat(keyChar, 10, (const char *)(&readc), 1);
4727  }
4728  else
4729  {
4730  ni_strncat(valChar, 10, (const char *)(&readc), 1);
4731  }
4732  }
4733  else if (readc == ':')
4734  {
4735  parseKey = 0;
4736  key = atoi(keyChar);
4737  hash_map[idx][0] = key;
4738  }
4739  else if (readc == ',')
4740  {
4742  {
4744  "ERROR: Number of entries per line in reconfig file is greater then the "
4745  "limit of %d\n",
4747  retval = NI_RETCODE_INVALID_PARAM;
4748  break;
4749  }
4750  val = atoi(valChar);
4751  hash_map[idx][valIdx] = val;
4752  valIdx++;
4753  memset(valChar, 0, 10);
4754  }
4755  else if (readc == '\n')
4756  {
4758  {
4760  "ERROR: Number of lines in reconfig file is greater then the "
4761  "limit of %d\n",
4763  retval = NI_RETCODE_INVALID_PARAM;
4764  break;
4765  }
4766  parseKey = 1;
4767  val = atoi (valChar);
4768  hash_map[idx][valIdx] = val;
4769  valIdx = 1;
4770  memset(keyChar,0,10);
4771  memset(valChar,0,10);
4772  idx ++;
4773  }
4774  else
4775  {
4776  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4777  }
4778  }
4779 
4780  fclose(reconf);
4781 
4782  if (NI_RETCODE_SUCCESS == retval && parseKey != 1)
4783  {
4785  "ERROR %d: %s(): Incorrect format / "
4786  "incomplete Key/Value pair in reconfig_file: %s\n",
4787  NI_ERRNO, __func__, reconf_file);
4789  }
4790 
4791  return retval;
4792 }
4793 
4795  int8_t qp_map[][NI_CUSTOMIZE_ROI_QP_NUM])
4796 {
4797  char valChar[5] = "";
4798  int val;
4799  int negative = 0;
4800  int qpIdx = 0;
4801  int levelIdx = 0;
4802  int readc = EOF;
4803  FILE *reconf = NULL;
4804 
4805  if (!customize_file)
4806  {
4807  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4808  __func__);
4809  return NI_RETCODE_INVALID_PARAM;
4810  }
4811 
4812  ni_fopen(&reconf, customize_file, "r");
4813  if (!reconf)
4814  {
4815  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4816  NI_ERRNO, __func__, customize_file);
4818  }
4820 
4821  while ((readc = fgetc(reconf)) != EOF)
4822  {
4823  //parse lines
4824  if (isdigit(readc))
4825  {
4826  ni_strncat(valChar, 5, (const char *)(&readc), 1);
4827  }
4828  else if (readc == '-') {
4829  negative = 1;
4830  }
4831  else if (readc == ',')
4832  {
4833  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4834  {
4836  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4837  "Number of levelIdx %d greater then the limit of %d\n",
4839  retval = NI_RETCODE_INVALID_PARAM;
4840  break;
4841  }
4842  if (!negative) {
4843  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
4844  qp_map[levelIdx][qpIdx] = val;
4845  } else {
4846  val = clip3(0, 32, atoi(valChar));
4847  qp_map[levelIdx][qpIdx] = val * -1;
4848  }
4849  negative = 0;
4850  memset(valChar, 0, 5);
4851  qpIdx++;
4852  }
4853  else if (readc == '\n')
4854  {
4855  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4856  {
4858  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4859  "Number of levelIdx %d greater then the limit of %d\n",
4861  retval = NI_RETCODE_INVALID_PARAM;
4862  break;
4863  }
4864  if (!negative) {
4865  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
4866  qp_map[levelIdx][qpIdx] = val;
4867  } else {
4868  val = clip3(0, 32, atoi(valChar));
4869  qp_map[levelIdx][qpIdx] = val * -1;
4870  }
4871  negative = 0;
4872  memset(valChar, 0, 5);
4873  qpIdx = 0;
4874  levelIdx++;
4875  }
4876  else
4877  {
4878  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4879  }
4880  }
4881  fclose(reconf);
4882 
4883  return retval;
4884 }
4885 
4886 
4887 #undef atoi
4888 #undef atof
4889 #define atoi(p_str) ni_atoi(p_str, &b_error)
4890 #define atof(p_str) ni_atof(p_str, &b_error)
4891 #define atobool(p_str) (ni_atobool(p_str, &b_error))
4892 /*!*****************************************************************************
4893 * \brief Set value referenced by name in decoder parameters structure
4894 *
4895 * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t (used
4896 * for decoder too for now ) to find and set a particular
4897 * parameter
4898 * \param[in] name String represented parameter name to search
4899 * \param[in] value Parameter value to set
4900 *
4901 * \return On success
4902 * NI_RETCODE_SUCCESS
4903 * On failure
4904 * NI_RETCODE_FAILURE
4905 * NI_RETCODE_INVALID_PARAM
4906 *******************************************************************************/
4908  const char *name, char *value)
4909 {
4910  bool b_error = false;
4911  bool bNameWasBool = false;
4912  bool bValueWasNull = !value;
4913  ni_decoder_input_params_t* p_dec = NULL;
4914  char nameBuf[64] = { 0 };
4915  const char delim[2] = ",";
4916  const char xdelim[2] = "x";
4917  char *chunk;//for parsing out multi param input
4918  int i, j, k;
4919 
4920  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
4921 
4922  if (!p_params)
4923  {
4924  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4925  __func__);
4926  return NI_RETCODE_INVALID_PARAM;
4927  }
4928 
4929  if (!name)
4930  {
4931  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
4932  __func__);
4934  }
4935  p_dec = &p_params->dec_input_params;
4936 
4937  // skip -- prefix if provided
4938  if (name[0] == '-' && name[1] == '-')
4939  {
4940  name += 2;
4941  }
4942 
4943  // s/_/-/g
4944  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
4945  {
4946  char* c;
4947  ni_strcpy(nameBuf, sizeof(nameBuf), name);
4948  while ((c = strchr(nameBuf, '_')) != 0)
4949  {
4950  *c = '-';
4951  }
4952  name = nameBuf;
4953  }
4954 
4955  if (!value)
4956  {
4957  value = "true";
4958  }
4959  else if (value[0] == '=')
4960  {
4961  value++;
4962  }
4963 
4964 #if defined(_MSC_VER)
4965 #define OPT(STR) else if (!_stricmp(name, STR))
4966 #define OPT2(STR1, STR2) \
4967  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
4968 #else
4969 #define OPT(STR) else if (!strcasecmp(name, STR))
4970 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
4971 #endif
4972  if (0); // suppress cppcheck
4974  {
4975  if (!strncmp(value, "hw", sizeof("hw"))){
4976  p_dec->hwframes = 1;
4977  }
4978  else if (!strncmp(value, "sw", sizeof("sw"))) {
4979  p_dec->hwframes = 0;
4980  }
4981  else{
4982  ni_log(NI_LOG_ERROR, "ERROR: %s(): out can only be <hw,sw> got %s\n",
4983  __func__, value);
4985  }
4986  }
4988  {
4989  if (atoi(value) == 1)
4990  p_dec->enable_out1 = 1;
4991  }
4993  {
4994  if (atoi(value) == 1)
4995  p_dec->enable_out2 = 1;
4996  }
4998  {
4999  if (atoi(value) == 1)
5000  p_dec->force_8_bit[0] = 1;
5001  }
5003  {
5004  if (atoi(value) == 1)
5005  p_dec->force_8_bit[1] = 1;
5006  }
5008  {
5009  if (atoi(value) == 1)
5010  p_dec->force_8_bit[2] = 1;
5011  }
5013  {
5014  if (atoi(value) == 1 || atoi(value) == 2)
5015  p_dec->semi_planar[0] = atoi(value);
5016  }
5018  {
5019  if (atoi(value) == 1 || atoi(value) == 2)
5020  p_dec->semi_planar[1] = atoi(value);
5021  }
5023  {
5024  if (atoi(value) == 1 || atoi(value) == 2)
5025  p_dec->semi_planar[2] = atoi(value);
5026  }
5028  {
5029  if (!strncmp(value, "manual", sizeof("manual"))) {
5030  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_MANUAL;
5031  }
5032  else if (!strncmp(value, "auto", sizeof("auto"))) {
5033  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_AUTO;
5034  }
5035  else{
5037  "ERROR: %s():cropMode0 input can only be <manual,auto> got %s\n",
5038  __func__, value);
5040  }
5041  }
5043  {
5044  if (!strncmp(value, "manual", sizeof("manual"))) {
5045  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_MANUAL;
5046  }
5047  else if (!strncmp(value, "auto", sizeof("auto"))) {
5048  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_AUTO;
5049  }
5050  else {
5052  "ERROR: %s():cropMode1 input can only be <manual,auto> got %s\n",
5053  __func__, value);
5055  }
5056  }
5058  {
5059  if (!strncmp(value, "manual", sizeof("manual"))) {
5060  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_MANUAL;
5061  }
5062  else if (!strncmp(value, "auto", sizeof("auto"))) {
5063  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_AUTO;
5064  }
5065  else {
5067  "ERROR: %s():cropMode2 input can only be <manual,auto> got %s\n",
5068  __func__, value);
5070  }
5071  }
5073  {
5074  char *saveptr = NULL;
5075  chunk = ni_strtok(value, delim, &saveptr);
5076  for (i = 0; i < 4; i++)
5077  {
5078  if (chunk != NULL)
5079  {
5080  j = k = 0;
5081  while (chunk[j])
5082  {
5083  if (chunk[j] != '\"' && chunk[j] != '\'')
5084  {
5085  p_dec->cr_expr[0][i][k] = chunk[j];
5086  k++;
5087  }
5088  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5089  {
5091  }
5092  }
5093  chunk = ni_strtok(NULL, delim, &saveptr);
5094  }
5095  else if (i == 2 ) //default offsets to centered image if not specified, may need recalc
5096  {
5097  ni_strcpy(p_dec->cr_expr[0][i], sizeof(p_dec->cr_expr[0][i]), "in_w/2-out_w/2");
5098  }
5099  else if (i == 3)
5100  {
5101  ni_strcpy(p_dec->cr_expr[0][i], sizeof(p_dec->cr_expr[0][i]), "in_h/2-out_h/2");
5102  } else
5103  {
5105  }
5106  }
5107  }
5109  {
5110  char *saveptr = NULL;
5111  chunk = ni_strtok(value, delim, &saveptr);
5112  for (i = 0; i < 4; i++)
5113  {
5114  if (chunk != NULL)
5115  {
5116  j = k = 0;
5117  while (chunk[j])
5118  {
5119  if (chunk[j] != '\"' && chunk[j] != '\'')
5120  {
5121  p_dec->cr_expr[1][i][k] = chunk[j];
5122  k++;
5123  }
5124  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5125  {
5127  }
5128  }
5129  chunk = ni_strtok(NULL, delim, &saveptr);
5130  }
5131  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5132  {
5133  ni_strcpy(p_dec->cr_expr[1][i], sizeof(p_dec->cr_expr[1][i]), "in_w/2-out_w/2");
5134  }
5135  else if (i == 3)
5136  {
5137  ni_strcpy(p_dec->cr_expr[1][i], sizeof(p_dec->cr_expr[1][i]), "in_h/2-out_h/2");
5138  }
5139  else
5140  {
5142  }
5143  }
5144  }
5146  {
5147  char *saveptr = NULL;
5148  chunk = ni_strtok(value, delim, &saveptr);
5149  for (i = 0; i < 4; i++)
5150  {
5151  if (chunk != NULL)
5152  {
5153  j = k = 0;
5154  while (chunk[j])
5155  {
5156  if (chunk[j] != '\"' && chunk[j] != '\'')
5157  {
5158  p_dec->cr_expr[2][i][k] = chunk[j];
5159  k++;
5160  }
5161  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5162  {
5164  }
5165  }
5166  chunk = ni_strtok(NULL, delim, &saveptr);
5167  }
5168  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5169  {
5170  ni_strcpy(p_dec->cr_expr[2][i], sizeof(p_dec->cr_expr[2][i]), "in_w/2-out_w/2");
5171  }
5172  else if (i == 3)
5173  {
5174  ni_strcpy(p_dec->cr_expr[2][i], sizeof(p_dec->cr_expr[2][i]), "in_h/2-out_h/2");
5175  }
5176  else
5177  {
5179  }
5180  }
5181  }
5183  {
5184  chunk = value;
5185  i = 0; // 'x' character counter
5186  while (*chunk++) {
5187  if (*chunk == xdelim[0]) {
5188  i++;
5189  }
5190  }
5191  if (i != 1) {
5193  }
5194  chunk = NULL;
5195 
5196  char *saveptr = NULL;
5197  chunk = ni_strtok(value, xdelim, &saveptr);
5198  for (i = 0; i < 2; i++)
5199  {
5200  if (chunk != NULL)
5201  {
5202  j = k = 0;
5203  while (chunk[j])
5204  {
5205  if (chunk[j] != '\"' && chunk[j] != '\'')
5206  {
5207  p_dec->sc_expr[0][i][k] = chunk[j];
5208  k++;
5209  }
5210  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5211  {
5213  }
5214  }
5215  chunk = ni_strtok(NULL, xdelim, &saveptr);
5216  }
5217  else
5218  {
5220  }
5221  }
5222  }
5224  {
5225  chunk = value;
5226  i = 0; // 'x' character counter
5227  while (*chunk++) {
5228  if (*chunk == xdelim[0]) {
5229  i++;
5230  }
5231  }
5232  if (i != 1) {
5234  }
5235  chunk = NULL;
5236 
5237  char *saveptr = NULL;
5238  chunk = ni_strtok(value, xdelim, &saveptr);
5239  for (i = 0; i < 2; i++)
5240  {
5241  if (chunk != NULL)
5242  {
5243  j = k = 0;
5244  while (chunk[j])
5245  {
5246  if (chunk[j] != '\"' && chunk[j] != '\'')
5247  {
5248  p_dec->sc_expr[1][i][k] = chunk[j];
5249  k++;
5250  }
5251  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5252  {
5254  }
5255  }
5256  chunk = ni_strtok(NULL, xdelim, &saveptr);
5257  }
5258  else
5259  {
5261  }
5262  }
5263  }
5265  {
5266  chunk = value;
5267  i = 0; // 'x' character counter
5268  while (*chunk++) {
5269  if (*chunk == xdelim[0]) {
5270  i++;
5271  }
5272  }
5273  if (i != 1) {
5275  }
5276  chunk = NULL;
5277 
5278  char *saveptr = NULL;
5279  chunk = ni_strtok(value, xdelim, &saveptr);
5280  for (i = 0; i < 2; i++)
5281  {
5282  if (chunk != NULL)
5283  {
5284  j = k = 0;
5285  while (chunk[j])
5286  {
5287  if (chunk[j] != '\"' && chunk[j] != '\'')
5288  {
5289  p_dec->sc_expr[2][i][k] = chunk[j];
5290  k++;
5291  }
5292  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5293  {
5295  }
5296  }
5297  chunk = ni_strtok(NULL, xdelim, &saveptr);
5298  }
5299  else
5300  {
5302  }
5303  }
5304  }
5306  {
5307  if ((atoi(value) < 0) || (atoi(value) > 2))
5308  {
5310  }
5311  p_dec->scale_long_short_edge[0] = atoi(value);
5312  }
5314  {
5315  if ((atoi(value) < 0) || (atoi(value) > 2))
5316  {
5318  }
5319  p_dec->scale_long_short_edge[1] = atoi(value);
5320  }
5322  {
5323  if ((atoi(value) < 0) || (atoi(value) > 2))
5324  {
5326  }
5327  p_dec->scale_long_short_edge[2] = atoi(value);
5328  }
5330  {
5331  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5332  {
5333  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5334  "and must be even number and less than or equal to 128. Got: %s\n",
5335  __func__, NI_DEC_PARAM_SCALE_0_RES_CEIL, value);
5336 
5338  }
5339  p_dec->scale_resolution_ceil[0] = atoi(value);
5340  }
5342  {
5343  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5344  {
5345  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5346  "and must be even number and less than or equal to 128. Got: %s\n",
5347  __func__, NI_DEC_PARAM_SCALE_1_RES_CEIL, value);
5349  }
5350  p_dec->scale_resolution_ceil[1] = atoi(value);
5351  }
5353  {
5354  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5355  {
5356  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5357  "and must be even number and less than or equal to 128. Got: %s\n",
5358  __func__, NI_DEC_PARAM_SCALE_2_RES_CEIL, value);
5360  }
5361  p_dec->scale_resolution_ceil[2] = atoi(value);
5362  }
5364  {
5365  if (!strncmp(value, "up", sizeof("up"))){
5366  p_dec->scale_round[0] = 0;
5367  }
5368  else if (!strncmp(value, "down", sizeof("down"))) {
5369  p_dec->scale_round[0] = 1;
5370  }
5371  else{
5372  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5373  __func__, NI_DEC_PARAM_SCALE_0_ROUND, value);
5375  }
5376  }
5378  {
5379  if (!strncmp(value, "up", sizeof("up"))){
5380  p_dec->scale_round[1] = 0;
5381  }
5382  else if (!strncmp(value, "down", sizeof("down"))) {
5383  p_dec->scale_round[1] = 1;
5384  }
5385  else{
5386  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5387  __func__, NI_DEC_PARAM_SCALE_1_ROUND, value);
5389  }
5390  }
5392  {
5393  if (!strncmp(value, "up", sizeof("up"))){
5394  p_dec->scale_round[2] = 0;
5395  }
5396  else if (!strncmp(value, "down", sizeof("down"))) {
5397  p_dec->scale_round[2] = 1;
5398  }
5399  else{
5400  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5401  __func__, NI_DEC_PARAM_SCALE_2_ROUND, value);
5403  }
5404  }
5406  {
5407  if ((atoi(value) != 0) && (atoi(value) != 1))
5408  {
5410  }
5411  p_dec->mcmode = atoi(value);
5412  }
5414  {
5415  if (atoi(value) < 0)
5416  {
5418  }
5419  p_dec->nb_save_pkt = atoi(value);
5420  }
5422  {
5423  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
5424  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
5425  {
5427  }
5428  p_dec->keep_alive_timeout = atoi(value);
5429  }
5431  {
5432  if (atoi(value) < 0)
5433  {
5435  }
5436  p_dec->decoder_low_delay = atoi(value);
5437  }
5439  {
5440  if ((atoi(value) != 0) && (atoi(value) != 1))
5441  {
5443  }
5444  p_dec->force_low_delay = atoi(value);
5445  }
5447  {
5448  if (atoi(value) < 0)
5449  {
5451  }
5452  p_dec->enable_low_delay_check = atoi(value);
5453  }
5455  {
5456  if ((atoi(value) != 0) && (atoi(value) != 1))
5457  {
5459  }
5460  p_dec->min_packets_delay = atoi(value);
5461  }
5463  {
5464  if (atoi(value) != NI_ENABLE_USR_DATA_SEI_PASSTHRU &&
5466  {
5468  }
5469  p_dec->enable_user_data_sei_passthru = atoi(value);
5470  }
5472  {
5473  if (atoi(value) < NI_MIN_CUSTOM_SEI_PASSTHRU ||
5475  {
5477  }
5478  p_dec->custom_sei_passthru = atoi(value);
5479  }
5481  {
5482  if (atoi(value) < NI_INVALID_SVCT_DECODING_LAYER)
5483  {
5485  }
5486  p_dec->svct_decoding_layer = atoi(value);
5487  }
5489  {
5490  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
5491  atoi(value) <= NI_DDR_PRIORITY_NONE)
5492  {
5494  }
5495  p_params->ddr_priority_mode = atoi(value);
5496  }
5498  {
5499  if (strncmp(value, "tolerant", sizeof("tolerant")) == 0) {
5501  } else if (strncmp(value, "ignore", sizeof("ignore")) == 0) {
5502  p_dec->ec_policy = NI_EC_POLICY_IGNORE;
5503  } else if (strncmp(value, "skip", sizeof("skip")) == 0) {
5504  p_dec->ec_policy = NI_EC_POLICY_SKIP;
5505  } else if (strncmp(value, "best_effort", sizeof("best_effort")) == 0) {
5507  } else if (strncmp(value, "limited_error", sizeof("limited_error")) == 0) {
5509  } else if (strncmp(value, "best_effort_out_dc", sizeof("best_effort_out_dc")) == 0) {
5511  } else {
5513  }
5514  }
5516  {
5517  if (atoi(value) != 0 &&
5518  atoi(value) != 1 &&
5519  atoi(value) != 2)
5520  {
5522  }
5523  p_dec->enable_advanced_ec = atoi(value);
5524  }
5526  {
5527  if (atoi(value) < 0 || (atoi(value) > 100))
5528  {
5530  }
5531  p_dec->error_ratio_threshold = atoi(value);
5532  }
5534  {
5535  if (atoi(value) < 0 || (atoi(value) > 2))
5536  {
5538  }
5539  p_dec->enable_ppu_scale_adapt = atoi(value);
5540  }
5542  {
5543  if (atoi(value) < 0 || (atoi(value) > 1))
5544  {
5546  }
5547  p_dec->enable_ppu_scale_limit = atoi(value);
5548  }
5550  {
5551  if (atoi(value) < 0 || atoi(value) > 255)
5552  {
5554  }
5555  p_dec->max_extra_hwframe_cnt = atoi(value);
5556  }
5558  {
5559  if (atoi(value) < 0 || atoi(value) > 1)
5560  {
5562  }
5563  p_dec->skip_pts_guess = atoi(value);
5564  }
5566  {
5567  if (atoi(value) != 0 && atoi(value) != 1)
5568  {
5570  }
5571  p_dec->pkt_pts_unchange = atoi(value);
5572  }
5574  {
5575  if (atoi(value) < 0 ||
5576  atoi(value) > 1)
5577  {
5579  }
5580  p_dec->enable_all_sei_passthru = atoi(value);
5581  }
5583  {
5584  if (atoi(value) != 0 && atoi(value) != 1)
5585  {
5587  }
5588  p_dec->enable_follow_iframe = atoi(value);
5589  }
5591  {
5592  if (atoi(value) < 0 ||
5593  atoi(value) > 1)
5594  {
5596  }
5597  p_dec->disable_adaptive_buffers = atoi(value);
5598  }
5600  {
5601  if (atoi(value) < 0 || atoi(value) > 1)
5602  {
5604  }
5605  p_dec->survive_stream_err = atoi(value);
5606  }
5608  {
5609  if ((atoi(value) != 0) && (atoi(value) != 1))
5610  {
5612  }
5613  p_dec->reduce_dpb_delay = atoi(value);
5614  }
5616  {
5617  if ((atoi(value) != 0) && (atoi(value) != 1))
5618  {
5620  }
5621  p_dec->skip_extra_headers = atoi(value);
5622  }
5624  {
5625  if ((atoi(value) != 0) && (atoi(value) != 1))
5626  {
5628  }
5629  p_params->enableCpuAffinity = atoi(value);
5630  }
5631  else
5632  {
5634  }
5635 
5636 #undef OPT
5637 #undef atobool
5638 #undef atoi
5639 #undef atof
5640  b_error |= bValueWasNull && !bNameWasBool;
5641 
5642  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
5643 
5645 }
5646 
5647 #undef atoi
5648 #undef atof
5649 #define atoi(p_str) ni_atoi(p_str, &b_error)
5650 #define atof(p_str) ni_atof(p_str, &b_error)
5651 #define atobool(p_str) (ni_atobool(p_str, &b_error))
5652 
5653 /*!*****************************************************************************
5654  * \brief Set value referenced by name in encoder parameters structure
5655  *
5656  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
5657  * to find and set a particular parameter
5658  * \param[in] name String represented parameter name to search
5659  * \param[in] value Parameter value to set
5660 *
5661  * \return On success
5662  * NI_RETCODE_SUCCESS
5663  * On failure
5664  * NI_RETCODE_FAILURE
5665  * NI_RETCODE_INVALID_PARAM
5666  ******************************************************************************/
5668  const char *name, const char *value)
5669 {
5670  bool b_error = false;
5671  bool bNameWasBool = false;
5672  bool bValueWasNull = !value;
5673  ni_encoder_cfg_params_t *p_enc = NULL;
5674  char nameBuf[64] = { 0 };
5675  int i,j,k;
5676 
5677  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
5678 
5679  if (!p_params)
5680  {
5681  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
5682  __func__);
5683  return NI_RETCODE_INVALID_PARAM;
5684  }
5685 
5686  if ( !name )
5687  {
5688  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
5689  __func__);
5691  }
5692  p_enc = &p_params->cfg_enc_params;
5693  // skip -- prefix if provided
5694  if (name[0] == '-' && name[1] == '-')
5695  {
5696  name += 2;
5697  }
5698 
5699  // s/_/-/g
5700  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
5701  {
5702  char* c;
5703  ni_strcpy(nameBuf, sizeof(nameBuf), name);
5704  while ((c = strchr(nameBuf, '_')) != 0)
5705  {
5706  *c = '-';
5707  }
5708  name = nameBuf;
5709  }
5710 
5711  if (!value)
5712  {
5713  value = "true";
5714  }
5715  else if (value[0] == '=')
5716  {
5717  value++;
5718  }
5719 
5720 #if defined(_MSC_VER)
5721 #define OPT(STR) else if (!_stricmp(name, STR))
5722 #define OPT2(STR1, STR2) \
5723  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
5724 #else
5725 #define OPT(STR) else if (!strcasecmp(name, STR))
5726 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
5727 #endif
5728 #define COMPARE(STR1, STR2, STR3) \
5729  if ((atoi(STR1) > (STR2)) || (atoi(STR1) < (STR3))) \
5730  { \
5731  return NI_RETCODE_PARAM_ERROR_OOR; \
5732  }
5733  if (0); // suppress cppcheck
5735  {
5736  if (AV_CODEC_DEFAULT_BITRATE == p_params->bitrate)
5737  {
5738  if (atoi(value) > NI_MAX_BITRATE)
5739  {
5741  }
5742  if (atoi(value) < NI_MIN_BITRATE)
5743  {
5745  }
5746  p_params->bitrate = atoi(value);
5747  }
5748  }
5750  {
5751  p_params->reconf_demo_mode = atoi(value); // for encoder reconfiguration testing
5752  }
5754  {
5755  ni_retcode_t retval = ni_parse_reconf_file(value, p_params->reconf_hash);
5756  if (retval != NI_RETCODE_SUCCESS) // for encoder reconfiguration testing
5757  {
5758  return retval;
5759  }
5760  }
5762  {
5763  // for encoder reconfiguration testing
5764  p_params->roi_demo_mode = atoi(value);
5765  if ((p_params->roi_demo_mode < 0) || (p_params->roi_demo_mode > 2))
5766  {
5768  }
5769  }
5771  {
5772  if (0 > atoi(value))
5773  {
5775  }
5776  p_params->low_delay_mode = atoi(value);
5777  }
5779  {
5780  if (0 != atoi(value) && 1 != atoi(value))
5781  {
5783  }
5784  p_params->minFramesDelay = atoi(value);
5785  }
5787  {
5788  p_params->padding = atoi(value);
5789  }
5790 #ifndef DEPRECATION_AS_ERROR
5792  {
5793  if (0 != atoi(value) && 1 != atoi(value))
5794  {
5796  }
5797  p_params->generate_enc_hdrs = atoi(value);
5798  // genHdrs is deprecated in favour of libavcodec parameter -gen_global_headers
5800  }
5801 #endif
5803  {
5804  if (0 != atoi(value) && 1 != atoi(value))
5805  {
5807  }
5808  p_params->use_low_delay_poc_type = atoi(value);
5809  }
5811  {
5812  if (QUADRA)
5813  {
5815  }
5816  p_params->force_frame_type = atoi(value);
5817  }
5819  {
5820  p_enc->profile = atoi(value);
5821  }
5823  {
5827  if (atof(value) <= 10)
5828  {
5829  p_enc->level_idc = (int)(10 * atof(value) + .5);
5830  }
5831  else
5832  {
5833  p_enc->level_idc = atoi(value);
5834  }
5835  }
5837  {
5838  p_enc->high_tier = atobool(value);
5839  }
5841  {
5842  p_params->log = atoi(value);
5843  if (b_error)
5844  {
5845  b_error = false;
5846  p_params->log = ni_parse_name(value, g_xcoder_log_names, &b_error) - 1;
5847  }
5848  }
5850  {
5851  if ((atoi(value) > NI_MAX_GOP_PRESET_IDX) || (atoi(value) < NI_MIN_GOP_PRESET_IDX))
5852  {
5854  }
5855  p_enc->gop_preset_index = atoi(value);
5856  }
5858  {
5860  {
5862  }
5863 
5864  p_enc->use_recommend_enc_params = atoi(value);
5865  }
5867  {
5868  if (QUADRA)
5869  {
5871  }
5872  if (((atoi(value) > NI_MAX_CU_SIZE_MODE) || (atoi(value) < NI_MIN_CU_SIZE_MODE)) && (atoi(value) != NI_DEFAULT_CU_SIZE_MODE))
5873  {
5875  }
5876 
5877  p_enc->cu_size_mode = atoi(value);
5878  }
5880  {
5881  if (QUADRA)
5882  {
5884  }
5885  if ((atoi(value) > NI_MAX_MAX_NUM_MERGE) || (atoi(value) < NI_MIN_MAX_NUM_MERGE))
5886  {
5888  }
5889 
5890  p_enc->max_num_merge = atoi(value);
5891  }
5893  {
5894  if (QUADRA)
5895  {
5897  }
5898  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5899  {
5901  }
5902 
5903  p_enc->enable_dynamic_8x8_merge = atoi(value);
5904  }
5906  {
5907  if (QUADRA)
5908  {
5910  }
5911  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5912  {
5914  }
5915 
5916  p_enc->enable_dynamic_16x16_merge = atoi(value);
5917  }
5919  {
5920  if (QUADRA)
5921  {
5923  }
5924  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5925  {
5927  }
5928 
5929  p_enc->enable_dynamic_32x32_merge = atoi(value);
5930  }
5932  {
5933  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5934  {
5936  }
5937 
5938  p_enc->rc.enable_rate_control = atoi(value);
5939  }
5941  {
5942  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5943  {
5945  }
5946 
5947  p_enc->rc.enable_cu_level_rate_control = atoi(value);
5948  }
5950  {
5951  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5952  {
5954  }
5955  p_enc->rc.enable_hvs_qp = atoi(value);
5956  }
5958  {
5959  if (QUADRA)
5960  {
5962  }
5963  p_enc->rc.enable_hvs_qp_scale = atoi(value);
5964  }
5966  {
5967  p_enc->rc.hvs_qp_scale = atoi(value);
5968  }
5970  {
5971  p_enc->rc.min_qp = atoi(value);
5972  }
5974  {
5975  p_enc->rc.max_qp = atoi(value);
5976  }
5978  {
5979  if (QUADRA)
5980  {
5982  }
5983  p_enc->rc.max_delta_qp = atoi(value);
5984  }
5985 #ifndef DEPRECATION_AS_ERROR
5987  {
5988  if ((atoi(value) > 51) || (atoi(value) < -1))
5989  {
5991  }
5992  p_enc->crf = atoi(value);
5993  }
5994 #endif
5996  {
5997  p_enc->rc.vbv_buffer_size = atoi(value);
5998  if (QUADRA)
5999  {
6000  // RcInitDelay is deprecated and replaced with vbvBufferSize. But still accept the value.
6002  }
6003  }
6005  {
6006  p_enc->rc.vbv_buffer_size = atoi(value);
6007  }
6009  {
6010  p_enc->rc.vbv_max_rate = atoi(value);
6011  }
6013  {
6014  p_enc->rc.enable_filler = atoi(value);
6015  if (QUADRA)
6016  {
6017  // cbr is deprecated and replaced with fillerEnable. But still accept the value.
6019  }
6020  }
6022  {
6023  p_enc->rc.enable_filler = atoi(value);
6024  }
6026  {
6027  if (0 != atoi(value) && 1 != atoi(value))
6028  {
6030  }
6031  // Currenly pic skip is supported for low delay gops only - pic skip issues tracked by QDFW-1785/1958
6032  p_enc->rc.enable_pic_skip = atoi(value);
6033  }
6034 #ifndef DEPRECATION_AS_ERROR
6036 #else
6038 #endif
6039  {
6040 #ifdef _MSC_VER
6041  if (!_strnicmp(value, "ratio", 5))
6042 #else
6043  if (!strncasecmp(value, "ratio", 5))
6044 #endif
6045  {
6046  char value_buf[32] = {0};
6047  for (i = 0; i < sizeof(value_buf); i++)
6048  {
6049  if (value[i+6] == ']')
6050  {
6051  break;
6052  }
6053  value_buf[i] = value[i+6];
6054  }
6055  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6056  {
6058  }
6059 
6060  p_enc->maxFrameSizeRatio = atoi(value_buf);
6061  }
6062  else
6063  {
6064  int size = atoi(value);
6065  if (size < NI_MIN_FRAME_SIZE)
6066  {
6068  }
6069  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6070  }
6071  }
6073  {
6074 #ifdef _MSC_VER
6075  if (!_strnicmp(value, "ratio", 5))
6076 #else
6077  if (!strncasecmp(value, "ratio", 5))
6078 #endif
6079  {
6080  char value_buf[32] = {0};
6081  for (i = 0; i < sizeof(value_buf); i++)
6082  {
6083  if (value[i+6] == ']')
6084  {
6085  break;
6086  }
6087  value_buf[i] = value[i+6];
6088  }
6089  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6090  {
6092  }
6093 
6094  p_enc->maxFrameSizeRatio = atoi(value_buf);
6095  }
6096  else
6097  {
6098  int size = atoi(value) / 8;
6099  if (size < NI_MIN_FRAME_SIZE)
6100  {
6102  }
6103  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6104  }
6105  }
6107  {
6108  if (0 != atoi(value) && 1 != atoi(value))
6109  {
6111  }
6112  p_enc->forced_header_enable = atoi(value);
6113  }
6115  {
6116  p_enc->roi_enable = atoi(value);
6117  }
6119  {
6120  p_enc->conf_win_top = atoi(value);
6121  }
6123  {
6124  p_enc->conf_win_bottom = atoi(value);
6125  }
6127  {
6128  p_enc->conf_win_left = atoi(value);
6129  }
6131  {
6132  p_enc->conf_win_right = atoi(value);
6133  }
6135  {
6136  p_enc->intra_period = atoi(value);
6137  //p_enc->bitrateWindow = p_enc->intra_period;
6138  }
6140  {
6141  if (atoi(value) > NI_MAX_BITRATE)
6142  {
6144  }
6145  if (atoi(value) < NI_MIN_BITRATE)
6146  {
6148  }
6149  p_enc->rc.trans_rate = atoi(value);
6150  }
6152  {
6153  if (atoi(value) <= 0 )
6154  {
6156  }
6157  p_params->fps_number = atoi(value);
6158  p_params->fps_denominator = 1;
6159  p_enc->frame_rate = p_params->fps_number;
6160  }
6162  {
6163  if (atoi(value) <= 0)
6164  {
6166  }
6167  p_params->fps_denominator = atoi(value);
6168  p_enc->frame_rate = (int)(p_params->fps_number / p_params->fps_denominator);
6169  }
6171  {
6172  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6173  {
6175  }
6176 
6177  p_enc->rc.intra_qp = atoi(value);
6178  }
6180  {
6181  if ((atoi(value) > NI_MAX_INTRA_QP_DELTA) ||
6182  (atoi(value) < NI_MIN_INTRA_QP_DELTA))
6183  {
6185  }
6186 
6187  p_enc->rc.intra_qp_delta = atoi(value);
6188  }
6190  {
6191  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6192  {
6194  }
6195  p_params->force_pic_qp_demo_mode = atoi(value);
6196  }
6198  {
6199  if (QUADRA)
6200  {
6202  }
6204  {
6206  }
6207  p_enc->decoding_refresh_type = atoi(value);
6208  }
6210  {
6211  if (0 != atoi(value) && 1 != atoi(value))
6212  {
6214  }
6215  p_enc->intra_reset_refresh = atoi(value);
6216  }
6217  // Rev. B: H.264 only parameters.
6219  {
6220  if (QUADRA)
6221  {
6223  }
6224  p_enc->enable_transform_8x8 = atoi(value);
6225  }
6227  {
6228  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6229  {
6231  }
6232  p_enc->slice_mode = atoi(value);
6233  }
6235  {
6236  p_enc->slice_arg = atoi(value);
6237  }
6239  {
6240  if (0 != atoi(value) && 1 != atoi(value))
6241  {
6243  }
6244  p_enc->entropy_coding_mode = atoi(value);
6245  }
6246 // Rev. B: shared between HEVC and H.264
6248  {
6249  p_enc->intra_mb_refresh_mode = atoi(value);
6250  }
6252  {
6253  p_enc->intra_mb_refresh_arg = atoi(value);
6254  }
6256  {
6257  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6258  {
6260  }
6261  p_enc->rc.enable_mb_level_rc = atoi(value);
6262  if (QUADRA)
6263  {
6264  // mbLevelRcEnable will be deprecated and cuLevelRCEnable should be used instead. But still accept the value.
6266  }
6267  }
6269  {
6270  if ((atoi(value) > 255) || (atoi(value) < 0))
6271  {
6273  }
6274  p_enc->preferred_transfer_characteristics = atoi(value);
6275  }
6277  {
6278  if (atoi(value) != 0 && atoi(value) != 5)
6279  {
6281  }
6282  p_params->dolby_vision_profile = atoi(value);
6283  }
6285  {
6286  if ((atoi(value) > 3) || (atoi(value) < 1))
6287  {
6289  }
6290  p_enc->rdoLevel = atoi(value);
6291  }
6293  {
6294  const char delim[2] = ",";
6295  char *chunk;
6296 #ifdef _MSC_VER
6297  char *v = _strdup(value);
6298 #else
6299  char *v = strdup(value);
6300 #endif
6301  char *saveptr = NULL;
6302  chunk = ni_strtok(v, delim, &saveptr);
6303  if (chunk != NULL)
6304  {
6305  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6306  {
6307  free(v);
6309  }
6310  p_enc->HDR10MaxLight = atoi(chunk);
6311  chunk = ni_strtok(NULL, delim, &saveptr);
6312  if (chunk != NULL)
6313  {
6314  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6315  {
6316  free(v);
6318  }
6319  p_enc->HDR10AveLight = atoi(chunk);
6320  p_enc->HDR10CLLEnable = 1; //Both param populated so enable
6321  free(v);
6322  }
6323  else
6324  {
6325  free(v);
6327  }
6328  }
6329  else
6330  {
6331  free(v);
6333  }
6334  }
6335 
6337  {
6338 #ifdef _MSC_VER
6339 #define STRDUP(value) _strdup(value);
6340 #else
6341 #define STRDUP(value) strdup(value);
6342 #endif
6343  const char G[2] = "G";
6344  const char B[2] = "B";
6345  const char R[2] = "R";
6346  const char W[2] = "W";
6347  const char L[2] = "L";
6348  const char P[2] = "P";
6349  const char parL[2] = "(";
6350  const char comma[2] = ",";
6351  const char parR[2] = ")";
6352  int synCheck_GBRWLPCP[8];
6353  int posCheck_GBRWL[5] = {0};
6354  char *chunk;//for parsing out more complex inputs
6355  char *subchunk;
6356  char *v = STRDUP(value);
6357  //basic check syntax correct
6358  for (i = 0; i<8; i++)
6359  {
6360  synCheck_GBRWLPCP[i] = 0;
6361  }
6362  chunk = v;
6363  i = 0; // character index
6364 
6365  //count keys and punctuation, save indicies to be parsed
6366  while (*chunk) {
6367  if (*chunk == G[0])
6368  {
6369  synCheck_GBRWLPCP[0]++;
6370  posCheck_GBRWL[0] = i;
6371  }
6372  else if (*chunk == B[0])
6373  {
6374  synCheck_GBRWLPCP[1]++;
6375  posCheck_GBRWL[1] = i;
6376  }
6377  else if (*chunk == R[0])
6378  {
6379  synCheck_GBRWLPCP[2]++;
6380  posCheck_GBRWL[2] = i;
6381  }
6382  else if (*chunk == W[0])
6383  {
6384  synCheck_GBRWLPCP[3]++;
6385  posCheck_GBRWL[3] = i;
6386  }
6387  else if (*chunk == L[0])
6388  {
6389  synCheck_GBRWLPCP[4]++;
6390  posCheck_GBRWL[4] = i;
6391  }
6392  else if (*chunk == parL[0])
6393  {
6394  synCheck_GBRWLPCP[5]++;
6395  }
6396  else if (*chunk == comma[0])
6397  {
6398  synCheck_GBRWLPCP[6]++;
6399  }
6400  else if (*chunk == parR[0])
6401  {
6402  synCheck_GBRWLPCP[7]++;
6403  }
6404  chunk++;
6405  i++;
6406  }
6407  free(v);
6408  if (synCheck_GBRWLPCP[0] != 1 || synCheck_GBRWLPCP[1] != 1 || synCheck_GBRWLPCP[2] != 1 ||
6409  synCheck_GBRWLPCP[3] != 1 || synCheck_GBRWLPCP[4] != 1 || synCheck_GBRWLPCP[5] != 5 ||
6410  synCheck_GBRWLPCP[6] != 5 || synCheck_GBRWLPCP[7] != 5)
6411  {
6413  }
6414 
6415  //Parse a key-value set like G(%hu, %hu)
6416 #define GBRWLPARSE(OUT1,OUT2,OFF,IDX) \
6417 { \
6418  char *v = STRDUP(value); \
6419  chunk = v + posCheck_GBRWL[IDX]; \
6420  i = j = k = 0; \
6421  while (chunk != NULL) \
6422  { \
6423  if (*chunk == parL[0] && i == 1+(OFF)) \
6424  { \
6425  j = 1; \
6426  } \
6427  if((OFF) == 1 && *chunk != P[0] && i == 1) \
6428  { \
6429  break; \
6430  } \
6431  if (*chunk == parR[0]) \
6432  { \
6433  k = 1; \
6434  break; \
6435  } \
6436  i++; \
6437  chunk++; \
6438  } \
6439  if (!j || !k) \
6440  { \
6441  free(v); \
6442  return NI_RETCODE_PARAM_INVALID_VALUE; \
6443  } \
6444  subchunk = malloc(i - 1 - (OFF)); \
6445  if (subchunk == NULL) \
6446  { \
6447  free(v); \
6448  return NI_RETCODE_ERROR_MEM_ALOC; \
6449  } \
6450  memcpy(subchunk, v + posCheck_GBRWL[IDX] + 2 + (OFF), i - 2 - (OFF)); \
6451  subchunk[i - 2 - (OFF)] = '\0'; \
6452  char *saveptr = NULL; \
6453  chunk = ni_strtok(subchunk, comma, &saveptr); \
6454  if (chunk != NULL) \
6455  { \
6456  if(atoi(chunk) < 0) \
6457  { \
6458  free(v); \
6459  if(subchunk != NULL){ \
6460  free(subchunk); \
6461  } \
6462  return NI_RETCODE_PARAM_INVALID_VALUE; \
6463  } \
6464  *(OUT1) = atoi(chunk); \
6465  } \
6466  chunk = ni_strtok(NULL, comma, &saveptr); \
6467  if (chunk != NULL) \
6468  { \
6469  if(atoi(chunk) < 0) \
6470  { \
6471  free(v); \
6472  if(subchunk != NULL){ \
6473  free(subchunk); \
6474  } \
6475  return NI_RETCODE_PARAM_INVALID_VALUE; \
6476  } \
6477  *(OUT2) = atoi(chunk); \
6478  } \
6479  free(subchunk); \
6480  free(v); \
6481 }
6482  GBRWLPARSE(&p_enc->HDR10dx0, &p_enc->HDR10dy0, 0, 0);
6483  GBRWLPARSE(&p_enc->HDR10dx1, &p_enc->HDR10dy1, 0, 1);
6484  GBRWLPARSE(&p_enc->HDR10dx2, &p_enc->HDR10dy2, 0, 2);
6485  GBRWLPARSE(&p_enc->HDR10wx, &p_enc->HDR10wy, 1, 3);
6486  GBRWLPARSE(&p_enc->HDR10maxluma, &p_enc->HDR10minluma, 0, 4);
6487  p_enc->HDR10Enable = 1;
6488  }
6490  {
6491  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
6492  {
6494  }
6495  p_enc->lookAheadDepth = atoi(value);
6496  }
6498  {
6499  if (atoi(value) != 0 && atoi(value) != 1)
6500  {
6502  }
6503  p_enc->hrdEnable = atoi(value);
6504  }
6506  {
6507  if ((atoi(value) != 0) && (atoi(value) != 1))
6508  {
6510  }
6511  p_enc->EnableAUD = atoi(value);
6512  }
6514  {
6515  if (atoi(value) != 0 && atoi(value) != 1)
6516  {
6518  }
6519  p_params->cacheRoi = atoi(value);
6520  }
6522  {
6523  if (atoi(value) != 0 && atoi(value) != 1)
6524  {
6526  }
6527  p_enc->long_term_ref_enable = atoi(value);
6528  }
6530  {
6531  p_enc->long_term_ref_interval = atoi(value);
6532  }
6534  {
6535  if (atoi(value) < 1 || atoi(value) > 2)
6536  {
6538  }
6539  p_enc->long_term_ref_count = atoi(value);
6540  }
6542  {
6543  if ((atoi(value) != 0) && (atoi(value) != 1))
6544  {
6546  }
6547  p_enc->EnableRdoQuant = atoi(value);
6548  }
6550  {
6551  if (QUADRA)
6552  {
6554  }
6555 
6556  if ((atoi(value) < 0) || (atoi(value) > 3))
6557  {
6559  }
6560  p_enc->ctbRcMode = atoi(value);
6561  }
6563  {
6564  if (QUADRA)
6565  {
6567  }
6568 
6569  p_enc->gopSize = atoi(value);
6570  }
6572  {
6573  if (QUADRA)
6574  {
6576  }
6577 
6578  if ((atoi(value) != 0) && (atoi(value) != 1))
6579  {
6581  }
6582  p_enc->gopLowdelay = atoi(value);
6583  }
6585  {
6586  if (QUADRA)
6587  {
6589  }
6590  p_enc->gdrDuration = atoi(value);
6591  }
6593  {
6594  p_enc->ltrRefInterval = atoi(value);
6595  }
6597  {
6598  p_enc->ltrRefQpOffset = atoi(value);
6599  }
6601  {
6602  p_enc->ltrFirstGap = atoi(value);
6603  }
6606  {
6607  if ((atoi(value) != 0) && (atoi(value) != 1))
6608  {
6610  }
6611  p_enc->multicoreJointMode = atoi(value);
6612  }
6614  {
6615  if ((atoi(value) < 0) || (atoi(value) > 9))
6616  {
6618  }
6619  p_enc->qlevel = atoi(value);
6620  }
6622  {
6623  if ((atoi(value) > 12) || (atoi(value) < -12))
6624  {
6626  }
6627  p_enc->chromaQpOffset = atoi(value);
6628  }
6629  OPT(NI_ENC_PARAM_TOL_RC_INTER) { p_enc->tolCtbRcInter = (float)atof(value); }
6630  OPT(NI_ENC_PARAM_TOL_RC_INTRA) { p_enc->tolCtbRcIntra = (float)atof(value); }
6632  {
6633  if ((atoi(value) > 300) || (atoi(value) < 1))
6634  {
6636  }
6637  p_enc->bitrateWindow = atoi(value);
6638  }
6640  {
6641  if ((atoi(value) > 2) || (atoi(value) < 0))
6642  {
6644  }
6645  p_enc->blockRCSize = atoi(value);
6646  }
6648  {
6649  if ((atoi(value) > 15) || (atoi(value) < 0))
6650  {
6652  }
6653  p_enc->rcQpDeltaRange = atoi(value);
6654  }
6656  {
6657  if ((atoi(value) > 500) || (atoi(value) < 0))
6658  {
6660  }
6661  p_enc->ctbRowQpStep = atoi(value);
6662  }
6664  {
6665  if ((atoi(value) > 1) || (atoi(value) < 0))
6666  {
6668  }
6669  p_enc->newRcEnable = atoi(value);
6670  }
6672  {
6673  if ((atoi(value) > 1) || (atoi(value) < 0))
6674  {
6676  }
6677  p_enc->inLoopDSRatio = atoi(value);
6678  }
6680  {
6681  COMPARE(value, 22, 0)
6682  p_params->color_primaries = p_enc->colorPrimaries = atoi(value);
6683  p_enc->colorDescPresent = 1;
6684  }
6686  {
6687  COMPARE(value, 18, 0)
6688  p_params->color_transfer_characteristic = p_enc->colorTrc = atoi(value);
6689  p_enc->colorDescPresent = 1;
6690  }
6692  {
6693  COMPARE(value, 14, 0)
6694  p_params->color_space = p_enc->colorSpace = atoi(value);
6695  p_enc->colorDescPresent = 1;
6696  }
6698  {
6699  p_params->sar_num = p_enc->aspectRatioWidth = atoi(value);
6700  }
6702  {
6703  p_params->sar_denom = p_enc->aspectRatioHeight = atoi(value);
6704  }
6706  {
6707  p_params->video_full_range_flag = p_enc->videoFullRange = atoi(value);
6708  }
6710  {
6711  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
6712  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
6713  {
6715  }
6716  p_enc->keep_alive_timeout = atoi(value);
6717  }
6719  {
6720  if (atoi(value) != 0 && atoi(value) != 1)
6721  {
6723  }
6724  p_params->enable_vfr = atoi(value);
6725  }
6727  {
6728  if (atoi(value) < 0 || atoi(value) > 3)
6729  {
6731  }
6732  p_enc->get_psnr_mode = atoi(value);
6733  }
6735  {
6736  if (atoi(value) < 1)
6737  {
6739  }
6740  p_params->interval_of_psnr = atoi(value);
6741  }
6743  {
6744  if (atoi(value) < 0 || atoi(value) > 1)
6745  {
6747  }
6748  p_enc->get_psnr_mode = atoi(value) + 3;
6749  }
6751  {
6752  if ((atoi(value) != 0) && (atoi(value) != 1))
6753  {
6755  }
6756  p_enc->enable_ssim = atoi(value);
6757  }
6759  {
6760  if ((atoi(value) != 0) && (atoi(value) != 1))
6761  {
6763  }
6764  p_enc->av1_error_resilient_mode = atoi(value);
6765  }
6767  {
6768  if ((atoi(value) != 0) && (atoi(value) != 1))
6769  {
6771  }
6772  p_params->staticMmapThreshold = atoi(value);
6773  }
6775  {
6776  p_enc->temporal_layers_enable = atoi(value);
6777  }
6779  {
6780  if ((atoi(value) != 0) && (atoi(value) != 1))
6781  {
6783  }
6784  p_params->enable_ai_enhance = atoi(value);
6785  }
6787  {
6788  if ((atoi(value) != 0) && (atoi(value) != 1))
6789  {
6791  }
6792  if(p_params->enable_ai_enhance)
6793  {
6794  ni_log(NI_LOG_ERROR, "Cannot set enableAIEnhance and enableHVSPlus at same time, just enableHVSPlus\n");
6795  }
6796  p_params->enable_ai_enhance = (atoi(value) == 1) ? 2 : 0;
6797  }
6799  {
6800  if ((atoi(value) != 0) && (atoi(value) != 1))
6801  {
6803  }
6804  p_params->enable2PassGop = atoi(value);
6805  }
6807  {
6808  if ((atoi(value) != 0) && (atoi(value) != 1) && (atoi(value) != -1))
6809  {
6811  }
6812  p_params->zerocopy_mode = atoi(value);
6813  }
6815  {
6816  if ((atoi(value) == 0) || (atoi(value) > 3))
6817  {
6819  }
6820  p_params->ai_enhance_level = atoi(value);
6821  }
6823  {
6824  if ((atoi(value) == 0) || (atoi(value) > 2))
6825  {
6827  }
6828  p_params->ai_enhance_level = atoi(value);
6829  }
6831  {
6832  if ((atoi(value) < NI_MIN_WIDTH) ||
6833  (atoi(value) > NI_PARAM_MAX_WIDTH))
6834  {
6836  }
6837  p_enc->crop_width = atoi(value);
6838  }
6840  {
6841  if ((atoi(value) < NI_MIN_HEIGHT) ||
6842  (atoi(value) > NI_PARAM_MAX_HEIGHT))
6843  {
6845  }
6846  p_enc->crop_height = atoi(value);
6847  }
6849  {
6850  if ((atoi(value) < 0) ||
6851  (atoi(value) > NI_PARAM_MAX_WIDTH))
6852  {
6854  }
6855  p_enc->hor_offset = atoi(value);
6856  }
6858  {
6859  if ((atoi(value) < 0) ||
6860  (atoi(value) > NI_PARAM_MAX_HEIGHT))
6861  {
6863  }
6864  p_enc->ver_offset = atoi(value);
6865  }
6867  {
6868  if ((atoi(value) > 51) || (atoi(value) < -1))
6869  {
6871  }
6872  p_enc->crfMax = atoi(value);
6873  }
6875  {
6876  if ((atof(value) > 1.0) || (atof(value) < 0.0))
6877  {
6879  }
6880  p_enc->qcomp = (float)atof(value);
6881  }
6883  {
6884  if ((atoi(value) != 0) && (atoi(value) != 1))
6885  {
6887  }
6888  p_enc->noMbtree = atoi(value);
6889  }
6891  {
6892  if ((atoi(value) != 0) && (atoi(value) != 1))
6893  {
6895  }
6896  p_enc->avcc_hvcc = atoi(value);
6897  }
6899  {
6900  if ((atoi(value) != 0) && (atoi(value) != 1))
6901  {
6903  }
6904  p_enc->noHWMultiPassSupport = atoi(value);
6905  }
6907  {
6908  if ((atoi(value) > 10) || (atoi(value) < 1))
6909  {
6911  }
6912  p_enc->cuTreeFactor = atoi(value);
6913  }
6915  {
6916  if ((atof(value) > 10.0) || (atof(value) < 0.01))
6917  {
6919  }
6920  p_enc->ipRatio = (float)atof(value);
6921  }
6923  {
6924  if ((atoi(value) != 0) && (atoi(value) != 1))
6925  {
6927  }
6928  p_enc->enableipRatio = atoi(value);
6929  }
6931  {
6932  if ((atof(value) > 10.0) || (atof(value) < 0.01))
6933  {
6935  }
6936  p_enc->pbRatio = (float)atof(value);
6937  }
6939  {
6940  if ((atof(value) > 1.0) || (atof(value) < 0.1))
6941  {
6943  }
6944  p_enc->cplxDecay = (float)atof(value);
6945  }
6947  {
6948  if ((atoi(value) > 51) || (atoi(value) < -1))
6949  {
6951  }
6952  p_enc->pps_init_qp = atoi(value);
6953  }
6955  {
6956  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
6957  atoi(value) <= NI_DDR_PRIORITY_NONE)
6958  {
6960  }
6961  p_params->ddr_priority_mode = atoi(value);
6962  }
6964  {
6965  if ((atoi(value) != 0) && (atoi(value) != 1))
6966  {
6968  }
6969  p_enc->bitrateMode = atoi(value);
6970  }
6972  {
6973  if ((atoi(value) > 51) || (atoi(value) < -1))
6974  {
6976  }
6977  p_enc->pass1_qp = atoi(value);
6978  }
6980  {
6981  if (((atof(value) < 0.0) && (atof(value) != -1.0)) ||
6982  (atof(value) > 51.00))
6983  {
6985  }
6986  p_enc->crfFloat = (float)atof(value);
6987  }
6989  {
6990  if ((atoi(value) < 0) || (atoi(value) > 31))
6991  {
6993  }
6994  p_enc->hvsBaseMbComplexity = atoi(value);
6995  }
6997  {
6998  if (atoi(value) != 0 && atoi(value) != 1 && atoi(value) != 6)
6999  {
7001  }
7002  p_enc->statistic_output_level = atoi(value);
7003  }
7005  {
7006  //Currently only support 6 stillImage detect level
7007  //0-3: no performance drop
7008  //4-6: performance drop
7009  if ((atoi(value) < 0 || atoi(value) > 6))
7010  {
7012  }
7013  p_enc->still_image_detect_level = atoi(value);
7014  }
7016  {
7017  //Currently only support 10 sceneChange detect level
7018  //1-5 : no performance drop
7019  //6-10: performance drop
7020  if ((atoi(value) < 0 || atoi(value) > 10))
7021  {
7023  }
7024  p_enc->scene_change_detect_level = atoi(value);
7025  }
7027  {
7028  if ((atoi(value) != 0) && (atoi(value) != 1))
7029  {
7031  }
7032  p_enc->enable_smooth_crf = atoi(value);
7033  }
7035  {
7036  if ((atoi(value) != 0) && (atoi(value) != 1))
7037  {
7039  }
7040  p_enc->enable_compensate_qp = atoi(value);
7041  }
7043  {
7044  if (atoi(value) < 0 || atoi(value) > 1)
7045  {
7047  }
7048  p_enc->skip_frame_enable = atoi(value);
7049  }
7051  {
7052  if (atoi(value) < 0)
7053  {
7055  }
7056  p_enc->max_consecutive_skip_num = atoi(value);
7057  }
7059  {
7060  if (atoi(value) < 0 || atoi(value) > 255)
7061  {
7063  }
7064  p_enc->skip_frame_interval = atoi(value);
7065  }
7067  {
7068  if (atoi(value) != 0 && atoi(value) != 1)
7069  {
7071  }
7072  p_enc->enable_all_sei_passthru = atoi(value);
7073  }
7075  {
7076  if (atoi(value) <= 0)
7077  {
7079  }
7080  p_enc->iframe_size_ratio = atoi(value);
7081  }
7083  {
7084  if ((atoi(value) < 0 || atoi(value) > 2) &&
7085  atoi(value) != 5 && atoi(value) != 6)
7086  {
7088  }
7089  p_enc->crf_max_iframe_enable = atoi(value);
7090  }
7092  {
7093  p_enc->vbv_min_rate = atoi(value);
7094  }
7096  {
7097  if (atoi(value) != 0 && atoi(value) != 1)
7098  {
7100  }
7101  p_enc->disable_adaptive_buffers = atoi(value);
7102  }
7104  {
7105  if ((atoi(value) != 0) && (atoi(value) != 1))
7106  {
7108  }
7109  p_enc->disableBframeRdoq = atoi(value);
7110  }
7112  {
7113  if ((atof(value) > 1.0) || (atof(value) < 0.0))
7114  {
7116  }
7117  p_enc->forceBframeQpfactor = (float)atof(value);
7118  }
7120  {
7121  if (atoi(value) < 0 || atoi(value) > 2)
7122  {
7124  }
7125  p_enc->tune_bframe_visual = atoi(value);
7126  }
7128  {
7129  if ((atoi(value) != 0) && (atoi(value) != 1))
7130  {
7132  }
7133  p_enc->enable_acq_limit = atoi(value);
7134  }
7136  {
7137  if (atoi(value) < NI_CUS_ROI_DISABLE || atoi(value) > NI_CUS_ROI_MERGE)
7138  {
7140  }
7141  p_enc->customize_roi_qp_level += atoi(value);
7142  }
7144  {
7146  if (retval != NI_RETCODE_SUCCESS)
7147  {
7148  return retval;
7149  }
7150  // indicate it need to upload roi qp map
7151  p_enc->customize_roi_qp_level += 64;
7152  }
7154  {
7155  if (atoi(value) < 0 || atoi(value) > 2)
7156  {
7158  }
7159  p_enc->motionConstrainedMode = atoi(value);
7160  }
7162  {
7165  {
7167  }
7168  p_enc->encMallocStrategy = atoi(value);
7169  }
7171  {
7172  if (atoi(value) < 1 || atoi(value) > 4)
7173  {
7175  }
7176  p_enc->spatial_layers = atoi(value);
7177  }
7179  {
7180  if (atoi(value) < 0 || atoi(value) > 1)
7181  {
7183  }
7184  p_enc->enable_timecode = atoi(value);
7185  }
7187  {
7188  if ((atoi(value) != 0) && (atoi(value) != 1))
7189  {
7191  }
7192  p_enc->spatial_layers_ref_base_layer = atoi(value);
7193  }
7195  {
7196  if ((atoi(value) != 0) && (atoi(value) != 1))
7197  {
7199  }
7200  p_enc->vbvBufferReencode = atoi(value);
7201  }
7203  {
7204  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
7205  {
7207  }
7208  p_enc->totalCuTreeDepth = atoi(value);
7209  }
7211  {
7212  if (atoi(value) != 0 && atoi(value) != 1)
7213  {
7215  }
7216  p_enc->adaptiveCuTree = atoi(value);
7217  }
7219  {
7220  if (atoi(value) != 0 && atoi(value) != 1)
7221  {
7223  }
7224  p_enc->preIntraHandling = atoi(value);
7225  }
7227  {
7228  if (atoi(value) != 0 && atoi(value) != 1)
7229  {
7231  }
7232  p_enc->baseLayerOnly = atoi(value);
7233  }
7235  {
7236  if (atoi(value) < 0 || atoi(value) > 100)
7237  {
7239  }
7240  p_enc->pastFrameMaxIntraRatio = atoi(value);
7241  }
7243  {
7244  if (atoi(value) < 0 || atoi(value) > 100)
7245  {
7247  }
7248  p_enc->linkFrameMaxIntraRatio = atoi(value);
7249  }
7251  {
7252  const char delim[2] = ",";
7253  char *chunk;
7254 #ifdef _MSC_VER
7255  char *v = _strdup(value);
7256 #else
7257  char *v = strdup(value);
7258 #endif
7259  char *saveptr = NULL;
7260  i = 0;
7261  chunk = ni_strtok(v, delim, &saveptr);
7262  while (chunk != NULL && i < NI_MAX_SPATIAL_LAYERS)
7263  {
7264  if ((atoi(chunk) > NI_MAX_BITRATE) || (atoi(chunk) < NI_MIN_BITRATE))
7265  {
7266  free(v);
7268  }
7269  p_enc->spatialLayerBitrate[i] = atoi(chunk);
7270  chunk = ni_strtok(NULL, delim, &saveptr);
7271  i++;
7272  }
7273  free(v);
7274  }
7276  {
7277  const char delim[2] = ",";
7278  char *chunk;
7279 #ifdef _MSC_VER
7280  char *v = _strdup(value);
7281 #else
7282  char *v = strdup(value);
7283 #endif
7284  char *saveptr = NULL;
7285  i = 0;
7286  chunk = ni_strtok(v, delim, &saveptr);
7287  while (chunk != NULL && i < NI_MAX_SPATIAL_LAYERS)
7288  {
7292  if (atof(chunk) <= 10)
7293  {
7294  p_enc->av1OpLevel[i] = (int)(10 * atof(chunk) + .5);
7295  }
7296  else
7297  {
7298  p_enc->av1OpLevel[i] = atoi(chunk);
7299  }
7300  chunk = ni_strtok(NULL, delim, &saveptr);
7301  i++;
7302  }
7303  free(v);
7304  }
7306  {
7307  if ((atoi(value) != 0) && (atoi(value) != 1))
7308  {
7310  }
7311  p_enc->disableAv1TimingInfo = atoi(value);
7312  }
7314  {
7315  if ((atoi(value) != 0) && (atoi(value) != 1))
7316  {
7318  }
7319  p_params->enableCpuAffinity = atoi(value);
7320  }
7321  else { return NI_RETCODE_PARAM_INVALID_NAME; }
7322 
7323 #undef OPT
7324 #undef OPT2
7325 #undef atobool
7326 #undef atoi
7327 #undef atof
7328 
7329  b_error |= bValueWasNull && !bNameWasBool;
7330 
7331  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
7332 
7334 }
7335 
7336 #undef atoi
7337 #undef atof
7338 #define atoi(p_str) ni_atoi(p_str, &b_error)
7339 #define atof(p_str) ni_atof(p_str, &b_error)
7340 #define atobool(p_str) (ni_atobool(p_str, &b_error))
7341 
7342 /*!*****************************************************************************
7343  * \brief Set GOP parameter value referenced by name in encoder parameters
7344  * structure
7345  *
7346  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
7347  * to find and set a particular parameter
7348  * \param[in] name String represented parameter name to search
7349  * \param[in] value Parameter value to set
7350 *
7351  * \return On success
7352  * NI_RETCODE_SUCCESS
7353  * On failure
7354  * NI_RETCODE_FAILURE
7355  * NI_RETCODE_INVALID_PARAM
7356  ******************************************************************************/
7358  const char *name,
7359  const char *value)
7360 {
7361  bool b_error = false;
7362  bool bNameWasBool = false;
7363  bool bValueWasNull = !value;
7364  ni_encoder_cfg_params_t *p_enc = NULL;
7365  ni_custom_gop_params_t* p_gop = NULL;
7366  char nameBuf[64] = { 0 };
7367 
7368  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
7369 
7370  if (!p_params)
7371  {
7372  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
7373  __func__);
7374  return NI_RETCODE_INVALID_PARAM;
7375  }
7376 
7377  if ( !name )
7378  {
7379  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
7380  __func__);
7382  }
7383  p_enc = &p_params->cfg_enc_params;
7384  p_gop = &p_enc->custom_gop_params;
7385 
7386  // skip -- prefix if provided
7387  if (name[0] == '-' && name[1] == '-')
7388  {
7389  name += 2;
7390  }
7391 
7392  // s/_/-/g
7393  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
7394  {
7395  char* c;
7396  ni_strcpy(nameBuf, sizeof(nameBuf), name);
7397  while ((c = strchr(nameBuf, '_')) != 0)
7398  {
7399  *c = '-';
7400  }
7401  name = nameBuf;
7402  }
7403 
7404  if (!value)
7405  {
7406  value = "true";
7407  }
7408  else if (value[0] == '=')
7409  {
7410  value++;
7411  }
7412 
7413 #if defined(_MSC_VER)
7414 #define OPT(STR) else if (!_stricmp(name, STR))
7415 #else
7416 #define OPT(STR) else if (!strcasecmp(name, STR))
7417 #endif
7418  if (0); // suppress cppcheck
7420  {
7421  if (atoi(value) > NI_MAX_GOP_SIZE)
7422  {
7424  }
7425  if (atoi(value) < NI_MIN_GOP_SIZE)
7426  {
7428  }
7429  p_gop->custom_gop_size = atoi(value);
7430  }
7431 
7432 #ifndef QUADRA
7434  {
7435  p_gop->pic_param[0].pic_type = atoi(value);
7436  }
7438  {
7439  p_gop->pic_param[0].poc_offset = atoi(value);
7440  }
7441  OPT(NI_ENC_GOP_PARAMS_G0_PIC_QP)
7442  {
7443  p_gop->pic_param[0].pic_qp = atoi(value);
7444  }
7445  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC_L0)
7446  {
7447  p_gop->pic_param[0].num_ref_pic_L0 = atoi(value);
7448  }
7449  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L0)
7450  {
7451  p_gop->pic_param[0].ref_poc_L0 = atoi(value);
7452  }
7453  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L1)
7454  {
7455  p_gop->pic_param[0].ref_poc_L1 = atoi(value);
7456  }
7458  {
7459  p_gop->pic_param[0].temporal_id = atoi(value);
7460  }
7461 
7463  {
7464  p_gop->pic_param[1].pic_type = atoi(value);
7465  }
7467  {
7468  p_gop->pic_param[1].poc_offset = atoi(value);
7469  }
7470  OPT(NI_ENC_GOP_PARAMS_G1_PIC_QP)
7471  {
7472  p_gop->pic_param[1].pic_qp = atoi(value);
7473  }
7474  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC_L0)
7475  {
7476  p_gop->pic_param[1].num_ref_pic_L0 = atoi(value);
7477  }
7478  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L0)
7479  {
7480  p_gop->pic_param[1].ref_poc_L0 = atoi(value);
7481  }
7482  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L1)
7483  {
7484  p_gop->pic_param[1].ref_poc_L1 = atoi(value);
7485  }
7487  {
7488  p_gop->pic_param[1].temporal_id = atoi(value);
7489  }
7490 
7492  {
7493  p_gop->pic_param[2].pic_type = atoi(value);
7494  }
7496  {
7497  p_gop->pic_param[2].poc_offset = atoi(value);
7498  }
7499  OPT(NI_ENC_GOP_PARAMS_G2_PIC_QP)
7500  {
7501  p_gop->pic_param[2].pic_qp = atoi(value);
7502  }
7503  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC_L0)
7504  {
7505  p_gop->pic_param[2].num_ref_pic_L0 = atoi(value);
7506  }
7507  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L0)
7508  {
7509  p_gop->pic_param[2].ref_poc_L0 = atoi(value);
7510  }
7511  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L1)
7512  {
7513  p_gop->pic_param[2].ref_poc_L1 = atoi(value);
7514  }
7516  {
7517  p_gop->pic_param[2].temporal_id = atoi(value);
7518  }
7519 
7521  {
7522  p_gop->pic_param[3].pic_type = atoi(value);
7523  }
7525  {
7526  p_gop->pic_param[3].poc_offset = atoi(value);
7527  }
7528  OPT(NI_ENC_GOP_PARAMS_G3_PIC_QP)
7529  {
7530  p_gop->pic_param[3].pic_qp = atoi(value);
7531  }
7532  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC_L0)
7533  {
7534  p_gop->pic_param[3].num_ref_pic_L0 = atoi(value);
7535  }
7536  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L0)
7537  {
7538  p_gop->pic_param[3].ref_poc_L0 = atoi(value);
7539  }
7540  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L1)
7541  {
7542  p_gop->pic_param[3].ref_poc_L1 = atoi(value);
7543  }
7545  {
7546  p_gop->pic_param[3].temporal_id = atoi(value);
7547  }
7548 
7550  {
7551  p_gop->pic_param[4].pic_type = atoi(value);
7552  }
7554  {
7555  p_gop->pic_param[4].poc_offset = atoi(value);
7556  }
7557  OPT(NI_ENC_GOP_PARAMS_G4_PIC_QP)
7558  {
7559  p_gop->pic_param[4].pic_qp = atoi(value);
7560  }
7561  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC_L0)
7562  {
7563  p_gop->pic_param[4].num_ref_pic_L0 = atoi(value);
7564  }
7565  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L0)
7566  {
7567  p_gop->pic_param[4].ref_poc_L0 = atoi(value);
7568  }
7569  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L1)
7570  {
7571  p_gop->pic_param[4].ref_poc_L1 = atoi(value);
7572  }
7574  {
7575  p_gop->pic_param[4].temporal_id = atoi(value);
7576  }
7577 
7579  {
7580  p_gop->pic_param[5].pic_type = atoi(value);
7581  }
7583  {
7584  p_gop->pic_param[5].poc_offset = atoi(value);
7585  }
7586  OPT(NI_ENC_GOP_PARAMS_G5_PIC_QP)
7587  {
7588  p_gop->pic_param[5].pic_qp = atoi(value);
7589  }
7590  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC_L0)
7591  {
7592  p_gop->pic_param[5].num_ref_pic_L0 = atoi(value);
7593  }
7594  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L0)
7595  {
7596  p_gop->pic_param[5].ref_poc_L0 = atoi(value);
7597  }
7598  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L1)
7599  {
7600  p_gop->pic_param[5].ref_poc_L1 = atoi(value);
7601  }
7603  {
7604  p_gop->pic_param[5].temporal_id = atoi(value);
7605  }
7606 
7608  {
7609  p_gop->pic_param[6].pic_type = atoi(value);
7610  }
7612  {
7613  p_gop->pic_param[6].poc_offset = atoi(value);
7614  }
7615  OPT(NI_ENC_GOP_PARAMS_G6_PIC_QP)
7616  {
7617  p_gop->pic_param[6].pic_qp = atoi(value);
7618  }
7619  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC_L0)
7620  {
7621  p_gop->pic_param[6].num_ref_pic_L0 = atoi(value);
7622  }
7623  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L0)
7624  {
7625  p_gop->pic_param[6].ref_poc_L0 = atoi(value);
7626  }
7627  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L1)
7628  {
7629  p_gop->pic_param[6].ref_poc_L1 = atoi(value);
7630  }
7632  {
7633  p_gop->pic_param[6].temporal_id = atoi(value);
7634  }
7635 
7637  {
7638  p_gop->pic_param[7].pic_type = atoi(value);
7639  }
7641  {
7642  p_gop->pic_param[7].poc_offset = atoi(value);
7643  }
7644  OPT(NI_ENC_GOP_PARAMS_G7_PIC_QP)
7645  {
7646  p_gop->pic_param[7].pic_qp = atoi(value);
7647  }
7648  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC_L0)
7649  {
7650  p_gop->pic_param[7].num_ref_pic_L0 = atoi(value);
7651  }
7652  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L0)
7653  {
7654  p_gop->pic_param[7].ref_poc_L0 = atoi(value);
7655  }
7656  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L1)
7657  {
7658  p_gop->pic_param[7].ref_poc_L1 = atoi(value);
7659  }
7661  {
7662  p_gop->pic_param[7].temporal_id = atoi(value);
7663  }
7664  else
7665  {
7666  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
7668  }
7669 #else
7671  {
7672  p_gop->pic_param[0].poc_offset = atoi(value);
7673  }
7675  {
7676  p_gop->pic_param[0].qp_offset = atoi(value);
7677  }
7678  /*
7679  OPT(NI_ENC_GOP_PARAMS_G0_QP_FACTOR)
7680  {
7681  p_gop->pic_param[0].qp_factor = atof(value);
7682  }
7683  */
7685  {
7686  p_gop->pic_param[0].temporal_id = atoi(value);
7687  }
7689  {
7690  p_gop->pic_param[0].pic_type = atoi(value);
7691  }
7693  {
7694  p_gop->pic_param[0].num_ref_pics = atoi(value);
7695  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 num_ref_pics %d\n", __func__, p_gop->pic_param[0].num_ref_pics);
7696  }
7698  {
7699  p_gop->pic_param[0].rps[0].ref_pic = atoi(value);
7700  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 %d rps[0].ref_pic %d\n", __func__, p_gop->pic_param[0].rps[0].ref_pic);
7701  }
7703  {
7704  p_gop->pic_param[0].rps[0].ref_pic_used = atoi(value);
7705  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 %d rps[0].ref_pic_used %d\n", __func__, p_gop->pic_param[0].rps[0].ref_pic_used);
7706  }
7708  {
7709  p_gop->pic_param[0].rps[1].ref_pic = atoi(value);
7710  }
7712  {
7713  p_gop->pic_param[0].rps[1].ref_pic_used = atoi(value);
7714  }
7716  {
7717  p_gop->pic_param[0].rps[2].ref_pic = atoi(value);
7718  }
7720  {
7721  p_gop->pic_param[0].rps[2].ref_pic_used = atoi(value);
7722  }
7724  {
7725  p_gop->pic_param[0].rps[3].ref_pic = atoi(value);
7726  }
7728  {
7729  p_gop->pic_param[0].rps[3].ref_pic_used = atoi(value);
7730  }
7731 
7733  {
7734  p_gop->pic_param[1].poc_offset = atoi(value);
7735  }
7737  {
7738  p_gop->pic_param[1].qp_offset = atoi(value);
7739  }
7740  /*
7741  OPT(NI_ENC_GOP_PARAMS_G1_QP_FACTOR)
7742  {
7743  p_gop->pic_param[1].qp_factor = atof(value);
7744  }
7745  */
7747  {
7748  p_gop->pic_param[1].temporal_id = atoi(value);
7749  }
7751  {
7752  p_gop->pic_param[1].pic_type = atoi(value);
7753  }
7755  {
7756  p_gop->pic_param[1].num_ref_pics = atoi(value);
7757  }
7759  {
7760  p_gop->pic_param[1].rps[0].ref_pic = atoi(value);
7761  }
7763  {
7764  p_gop->pic_param[1].rps[0].ref_pic_used = atoi(value);
7765  }
7767  {
7768  p_gop->pic_param[1].rps[1].ref_pic = atoi(value);
7769  }
7771  {
7772  p_gop->pic_param[1].rps[1].ref_pic_used = atoi(value);
7773  }
7775  {
7776  p_gop->pic_param[1].rps[2].ref_pic = atoi(value);
7777  }
7779  {
7780  p_gop->pic_param[1].rps[2].ref_pic_used = atoi(value);
7781  }
7783  {
7784  p_gop->pic_param[1].rps[3].ref_pic = atoi(value);
7785  }
7787  {
7788  p_gop->pic_param[1].rps[3].ref_pic_used = atoi(value);
7789  }
7790 
7792  {
7793  p_gop->pic_param[2].poc_offset = atoi(value);
7794  }
7796  {
7797  p_gop->pic_param[2].qp_offset = atoi(value);
7798  }
7799  /*
7800  OPT(NI_ENC_GOP_PARAMS_G2_QP_FACTOR)
7801  {
7802  p_gop->pic_param[2].qp_factor = atof(value);
7803  }
7804  */
7806  {
7807  p_gop->pic_param[2].temporal_id = atoi(value);
7808  }
7810  {
7811  p_gop->pic_param[2].pic_type = atoi(value);
7812  }
7814  {
7815  p_gop->pic_param[2].num_ref_pics = atoi(value);
7816  }
7818  {
7819  p_gop->pic_param[2].rps[0].ref_pic = atoi(value);
7820  }
7822  {
7823  p_gop->pic_param[2].rps[0].ref_pic_used = atoi(value);
7824  }
7826  {
7827  p_gop->pic_param[2].rps[1].ref_pic = atoi(value);
7828  }
7830  {
7831  p_gop->pic_param[2].rps[1].ref_pic_used = atoi(value);
7832  }
7834  {
7835  p_gop->pic_param[2].rps[2].ref_pic = atoi(value);
7836  }
7838  {
7839  p_gop->pic_param[2].rps[2].ref_pic_used = atoi(value);
7840  }
7842  {
7843  p_gop->pic_param[2].rps[3].ref_pic = atoi(value);
7844  }
7846  {
7847  p_gop->pic_param[2].rps[3].ref_pic_used = atoi(value);
7848  }
7849 
7851  {
7852  p_gop->pic_param[3].poc_offset = atoi(value);
7853  }
7855  {
7856  p_gop->pic_param[3].qp_offset = atoi(value);
7857  }
7858  /*
7859  OPT(NI_ENC_GOP_PARAMS_G3_QP_FACTOR)
7860  {
7861  p_gop->pic_param[3].qp_factor = atof(value);
7862  }
7863  */
7865  {
7866  p_gop->pic_param[3].temporal_id = atoi(value);
7867  }
7869  {
7870  p_gop->pic_param[3].pic_type = atoi(value);
7871  }
7873  {
7874  p_gop->pic_param[3].num_ref_pics = atoi(value);
7875  }
7877  {
7878  p_gop->pic_param[3].rps[0].ref_pic = atoi(value);
7879  }
7881  {
7882  p_gop->pic_param[3].rps[0].ref_pic_used = atoi(value);
7883  }
7885  {
7886  p_gop->pic_param[3].rps[1].ref_pic = atoi(value);
7887  }
7889  {
7890  p_gop->pic_param[3].rps[1].ref_pic_used = atoi(value);
7891  }
7893  {
7894  p_gop->pic_param[3].rps[2].ref_pic = atoi(value);
7895  }
7897  {
7898  p_gop->pic_param[3].rps[2].ref_pic_used = atoi(value);
7899  }
7901  {
7902  p_gop->pic_param[3].rps[3].ref_pic = atoi(value);
7903  }
7905  {
7906  p_gop->pic_param[3].rps[3].ref_pic_used = atoi(value);
7907  }
7908 
7910  {
7911  p_gop->pic_param[4].poc_offset = atoi(value);
7912  }
7914  {
7915  p_gop->pic_param[4].qp_offset = atoi(value);
7916  }
7917  /*
7918  OPT(NI_ENC_GOP_PARAMS_G4_QP_FACTOR)
7919  {
7920  p_gop->pic_param[4].qp_factor = atof(value);
7921  }
7922  */
7924  {
7925  p_gop->pic_param[4].temporal_id = atoi(value);
7926  }
7928  {
7929  p_gop->pic_param[4].pic_type = atoi(value);
7930  }
7932  {
7933  p_gop->pic_param[4].num_ref_pics = atoi(value);
7934  }
7936  {
7937  p_gop->pic_param[4].rps[0].ref_pic = atoi(value);
7938  }
7940  {
7941  p_gop->pic_param[4].rps[0].ref_pic_used = atoi(value);
7942  }
7944  {
7945  p_gop->pic_param[4].rps[1].ref_pic = atoi(value);
7946  }
7948  {
7949  p_gop->pic_param[4].rps[1].ref_pic_used = atoi(value);
7950  }
7952  {
7953  p_gop->pic_param[4].rps[2].ref_pic = atoi(value);
7954  }
7956  {
7957  p_gop->pic_param[4].rps[2].ref_pic_used = atoi(value);
7958  }
7960  {
7961  p_gop->pic_param[4].rps[3].ref_pic = atoi(value);
7962  }
7964  {
7965  p_gop->pic_param[4].rps[3].ref_pic_used = atoi(value);
7966  }
7967 
7969  {
7970  p_gop->pic_param[5].poc_offset = atoi(value);
7971  }
7973  {
7974  p_gop->pic_param[5].qp_offset = atoi(value);
7975  }
7976  /*
7977  OPT(NI_ENC_GOP_PARAMS_G5_QP_FACTOR)
7978  {
7979  p_gop->pic_param[5].qp_factor = atof(value);
7980  }
7981  */
7983  {
7984  p_gop->pic_param[5].temporal_id = atoi(value);
7985  }
7987  {
7988  p_gop->pic_param[5].pic_type = atoi(value);
7989  }
7991  {
7992  p_gop->pic_param[5].num_ref_pics = atoi(value);
7993  }
7995  {
7996  p_gop->pic_param[5].rps[0].ref_pic = atoi(value);
7997  }
7999  {
8000  p_gop->pic_param[5].rps[0].ref_pic_used = atoi(value);
8001  }
8003  {
8004  p_gop->pic_param[5].rps[1].ref_pic = atoi(value);
8005  }
8007  {
8008  p_gop->pic_param[5].rps[1].ref_pic_used = atoi(value);
8009  }
8011  {
8012  p_gop->pic_param[5].rps[2].ref_pic = atoi(value);
8013  }
8015  {
8016  p_gop->pic_param[5].rps[2].ref_pic_used = atoi(value);
8017  }
8019  {
8020  p_gop->pic_param[5].rps[3].ref_pic = atoi(value);
8021  }
8023  {
8024  p_gop->pic_param[5].rps[3].ref_pic_used = atoi(value);
8025  }
8026 
8028  {
8029  p_gop->pic_param[6].poc_offset = atoi(value);
8030  }
8032  {
8033  p_gop->pic_param[6].qp_offset = atoi(value);
8034  }
8035  /*
8036  OPT(NI_ENC_GOP_PARAMS_G6_QP_FACTOR)
8037  {
8038  p_gop->pic_param[6].qp_factor = atof(value);
8039  }
8040  */
8042  {
8043  p_gop->pic_param[6].temporal_id = atoi(value);
8044  }
8046  {
8047  p_gop->pic_param[6].pic_type = atoi(value);
8048  }
8050  {
8051  p_gop->pic_param[6].num_ref_pics = atoi(value);
8052  }
8054  {
8055  p_gop->pic_param[6].rps[0].ref_pic = atoi(value);
8056  }
8058  {
8059  p_gop->pic_param[6].rps[0].ref_pic_used = atoi(value);
8060  }
8062  {
8063  p_gop->pic_param[6].rps[1].ref_pic = atoi(value);
8064  }
8066  {
8067  p_gop->pic_param[6].rps[1].ref_pic_used = atoi(value);
8068  }
8070  {
8071  p_gop->pic_param[6].rps[2].ref_pic = atoi(value);
8072  }
8074  {
8075  p_gop->pic_param[6].rps[2].ref_pic_used = atoi(value);
8076  }
8078  {
8079  p_gop->pic_param[6].rps[3].ref_pic = atoi(value);
8080  }
8082  {
8083  p_gop->pic_param[6].rps[3].ref_pic_used = atoi(value);
8084  }
8085 
8087  {
8088  p_gop->pic_param[7].poc_offset = atoi(value);
8089  }
8091  {
8092  p_gop->pic_param[7].qp_offset = atoi(value);
8093  }
8094  /*
8095  OPT(NI_ENC_GOP_PARAMS_G7_QP_FACTOR)
8096  {
8097  p_gop->pic_param[7].qp_factor = atof(value);
8098  }
8099  */
8101  {
8102  p_gop->pic_param[7].temporal_id = atoi(value);
8103  }
8105  {
8106  p_gop->pic_param[7].pic_type = atoi(value);
8107  }
8109  {
8110  p_gop->pic_param[7].num_ref_pics = atoi(value);
8111  }
8113  {
8114  p_gop->pic_param[7].rps[0].ref_pic = atoi(value);
8115  }
8117  {
8118  p_gop->pic_param[7].rps[0].ref_pic_used = atoi(value);
8119  }
8121  {
8122  p_gop->pic_param[7].rps[1].ref_pic = atoi(value);
8123  }
8125  {
8126  p_gop->pic_param[7].rps[1].ref_pic_used = atoi(value);
8127  }
8129  {
8130  p_gop->pic_param[7].rps[2].ref_pic = atoi(value);
8131  }
8133  {
8134  p_gop->pic_param[7].rps[2].ref_pic_used = atoi(value);
8135  }
8137  {
8138  p_gop->pic_param[7].rps[3].ref_pic = atoi(value);
8139  }
8141  {
8142  p_gop->pic_param[7].rps[3].ref_pic_used = atoi(value);
8143  }
8144  else
8145  {
8146  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
8148  }
8149 #endif
8150 
8151 #undef OPT
8152 #undef OPT2
8153 #undef atobool
8154 #undef atoi
8155 #undef atof
8156 
8157  b_error |= bValueWasNull && !bNameWasBool;
8158 
8159  ni_log(NI_LOG_TRACE, "%s(): exit, b_error=%d\n", __func__, b_error);
8160 
8162 }
8163 
8164 /*!*****************************************************************************
8165 * \brief Copy existing decoding session params for hw frame usage
8166 *
8167 * \param[in] src_p_ctx Pointer to a caller allocated source session context
8168 * \param[in] dst_p_ctx Pointer to a caller allocated destination session
8169 * context
8170 * \return On success
8171 * NI_RETCODE_SUCCESS
8172 * On failure
8173 * NI_RETCODE_INVALID_PARAM
8174 ******************************************************************************/
8176 {
8177  return ni_decoder_session_copy_internal(src_p_ctx, dst_p_ctx);
8178 }
8179 
8180 /*!*****************************************************************************
8181 * \brief Read data from the device
8182 * If device_type is NI_DEVICE_TYPE_DECODER reads data hwdesc from
8183 * decoder
8184 * If device_type is NI_DEVICE_TYPE_SCALER reads data hwdesc from
8185 * scaler
8186 *
8187 * \param[in] p_ctx Pointer to a caller allocated
8188 * ni_session_context_t struct
8189 * \param[in] p_data Pointer to a caller allocated
8190 * ni_session_data_io_t struct which contains either a
8191 * ni_frame_t data frame or ni_packet_t data packet to
8192 * send
8193 * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER
8194 * If NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER is specified,
8195 * hw descriptor info will be stored in p_data ni_frame
8196 * \return On success
8197 * Total number of bytes read
8198 * On failure
8199 * NI_RETCODE_INVALID_PARAM
8200 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8201 * NI_RETCODE_ERROR_INVALID_SESSION
8202 ******************************************************************************/
8204 {
8205  ni_log2(p_ctx, NI_LOG_DEBUG, "%s start\n", __func__);
8207  if ((!p_ctx) || (!p_data))
8208  {
8209  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8210  __func__);
8211  return NI_RETCODE_INVALID_PARAM;
8212  }
8213 
8214  // Here check if keep alive thread is closed.
8215 #ifdef _WIN32
8216  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
8218 #else
8219  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
8221 #endif
8222  {
8223  ni_log2(p_ctx, NI_LOG_ERROR,
8224  "ERROR: %s() keep alive thread has been closed, "
8225  "hw:%d, session:%d\n",
8226  __func__, p_ctx->hw_id, p_ctx->session_id);
8228  }
8229 
8230  ni_pthread_mutex_lock(&p_ctx->mutex);
8231  // In close state, let the close process execute first.
8232  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
8233  {
8234  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
8235  ni_pthread_mutex_unlock(&p_ctx->mutex);
8236  ni_usleep(100);
8238  }
8240  ni_pthread_mutex_unlock(&p_ctx->mutex);
8241 
8242  switch (device_type)
8243  {
8245  {
8246  int seq_change_read_count = 0;
8247  p_data->data.frame.src_codec = p_ctx->codec_format;
8248  for (;;)
8249  {
8250  //retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
8251  retval = ni_decoder_session_read_desc(p_ctx, &(p_data->data.frame));
8252  // check resolution change only after initial setting obtained
8253  // p_data->data.frame.video_width is picture width and will be 32-align
8254  // adjusted to frame size; p_data->data.frame.video_height is the same as
8255  // frame size, then compare them to saved one for resolution checking
8256  //
8257  uint32_t aligned_width;
8258  if(QUADRA)
8259  {
8260  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
8261  }
8262  else
8263  {
8264  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
8265  }
8266 
8267  ni_log2(p_ctx, NI_LOG_DEBUG,
8268  "FNum %" PRIu64
8269  ", DFVWxDFVH %u x %u, AlWid %u, AVW x AVH %u x %u\n",
8270  p_ctx->frame_num, p_data->data.frame.video_width,
8271  p_data->data.frame.video_height, aligned_width,
8272  p_ctx->active_video_width, p_ctx->active_video_height);
8273 
8274  if (0 == retval && seq_change_read_count)
8275  {
8276  ni_log2(p_ctx, NI_LOG_DEBUG, "%s (decoder): seq change NO data, next time.\n",
8277  __func__);
8278  p_ctx->active_video_width = 0;
8279  p_ctx->active_video_height = 0;
8280  p_ctx->actual_video_width = 0;
8281  break;
8282  }
8283  else if (retval < 0)
8284  {
8285  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
8286  __func__, retval);
8287  break;
8288  }
8289  // aligned_width may equal to active_video_width if bit depth and width
8290  // are changed at the same time. So, check video_width != actual_video_width.
8291  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
8292  (p_data->data.frame.video_width &&
8293  p_data->data.frame.video_height &&
8294  (aligned_width != p_ctx->active_video_width ||
8295  p_data->data.frame.video_height != p_ctx->active_video_height))))
8296  {
8297  ni_log2(
8298  p_ctx, NI_LOG_DEBUG,
8299  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
8300  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
8301  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
8302  aligned_width, p_data->data.frame.video_height,
8303  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
8304  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
8305  // reset active video resolution to 0 so it can be queried in the re-read
8306  p_ctx->active_video_width = 0;
8307  p_ctx->active_video_height = 0;
8308  p_ctx->actual_video_width = 0;
8309  seq_change_read_count++;
8310  //break;
8311  }
8312  else
8313  {
8314  break;
8315  }
8316  }
8317  break;
8318  }
8320  {
8321  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Encoder has no hwdesc to read\n");
8322  return NI_RETCODE_INVALID_PARAM;
8323  }
8324 
8325  case NI_DEVICE_TYPE_SCALER:
8326  {
8327  retval = ni_scaler_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8328  break;
8329  }
8330 
8331  case NI_DEVICE_TYPE_AI:
8332  {
8333  retval = ni_ai_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8334  break;
8335  }
8336 
8337  default:
8338  {
8339  retval = NI_RETCODE_INVALID_PARAM;
8340  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
8341  __func__, device_type);
8342  break;
8343  }
8344  }
8345 
8346  ni_pthread_mutex_lock(&p_ctx->mutex);
8348  ni_pthread_mutex_unlock(&p_ctx->mutex);
8349 
8350  return retval;
8351 }
8352 
8353 /*!*****************************************************************************
8354 * \brief Reads YUV data from hw descriptor stored location on device
8355 *
8356 * \param[in] p_ctx Pointer to a caller allocated
8357 * ni_session_context_t struct
8358 * \param[in] p_data Pointer to a caller allocated
8359 * ni_session_data_io_t struct which contains either a
8360 * ni_frame_t data frame or ni_packet_t data packet to
8361 * send
8362 * \param[in] hwdesc HW descriptor to find frame in XCODER
8363 * \return On success
8364 * Total number of bytes read
8365 * On failure
8366 * NI_RETCODE_INVALID_PARAM
8367 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8368 * NI_RETCODE_ERROR_INVALID_SESSION
8369 *******************************************************************************/
8371 {
8373  if ((!hwdesc) || (!p_data))
8374  {
8375  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8376  __func__);
8377  return NI_RETCODE_INVALID_PARAM;
8378  }
8379 
8380  /* download by frameidx */
8381  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rd") >= 0))
8382  {
8383  if(hwdesc->ui16FrameIdx == 0)
8384  {
8385  ni_log(NI_LOG_ERROR, "%s(): Invaild frame index\n", __func__);
8386  return NI_RETCODE_INVALID_PARAM;
8387  }
8388  retval = ni_hwdownload_by_frame_idx(hwdesc, &(p_data->data.frame), p_ctx->is_auto_dl);
8389  } else {
8390  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
8391  {
8392  if (p_ctx->pext_mutex == &(p_ctx->mutex))
8393  {
8394  ni_log(NI_LOG_ERROR, "ERROR %s(): Invalid session\n",
8395  __func__);
8397  }
8398  }
8399 
8401  bool use_external_mutex = false;
8402  uint32_t orig_session_id = p_ctx->session_id;
8403  ni_device_handle_t orig_blk_io_handle = p_ctx->blk_io_handle;
8404  uint32_t orig_codec_format = p_ctx->codec_format;
8405  int orig_bit_depth_factor = p_ctx->bit_depth_factor;
8406  int orig_hw_action = p_ctx->hw_action;
8407 
8408  ni_pthread_mutex_t *p_ctx_mutex = &(p_ctx->mutex);
8409  if ((p_ctx_mutex != p_ctx->pext_mutex) ||
8412  "6r8") < 0)
8413  {
8414  use_external_mutex = true;
8415  p_ctx->session_id = hwdesc->ui16session_ID;
8416  p_ctx->blk_io_handle = (ni_device_handle_t)(int64_t)hwdesc->device_handle;
8417  p_ctx->codec_format = NI_CODEC_FORMAT_H264; //unused
8418  p_ctx->bit_depth_factor = (int)hwdesc->bit_depth;
8420  }
8421 
8423 
8424  retval = ni_hwdownload_session_read(p_ctx, &(p_data->data.frame), hwdesc); //cut me down as needed
8425 
8427  if (use_external_mutex)
8428  {
8429  p_ctx->session_id = orig_session_id;
8430  p_ctx->blk_io_handle = orig_blk_io_handle;
8431  p_ctx->codec_format = orig_codec_format;
8432  p_ctx->bit_depth_factor = orig_bit_depth_factor;
8433  p_ctx->hw_action = orig_hw_action;
8434  }
8436  }
8437 
8438  return retval;
8439 }
8440 
8441 /*!*****************************************************************************
8442 * \brief Query the session if a buffer is available
8443 *
8444 * \param[in] p_ctx Pointer to a caller allocated
8445 * ni_session_context_t struct
8446 * [in] device_type Quadra device type
8447 *
8448 * \return On success
8449 * NI_RETCODE_SUCCESS
8450 * On failure
8451 * NI_RETCODE_INVALID_PARAM
8452 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8453 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8454 * NI_RETCODE_ERROR_INVALID_SESSION
8455 *******************************************************************************/
8457  ni_device_type_t device_type)
8458 {
8460 
8461  if (!p_ctx)
8462  {
8463  ni_log(NI_LOG_ERROR, "ERROR: No session\n");
8464  return NI_RETCODE_INVALID_PARAM;
8465  }
8466 
8467  if (ni_cmp_fw_api_ver(
8468  (char *) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
8469  "6rt") < 0)
8470  {
8471  ni_log2(p_ctx, NI_LOG_DEBUG,
8472  "%s function not supported in FW API version < 6rt\n",
8473  __func__);
8475  }
8476 
8477  switch (device_type)
8478  {
8479  case NI_DEVICE_TYPE_UPLOAD:
8480  ni_pthread_mutex_lock(&p_ctx->mutex);
8482 
8484 
8486  ni_pthread_mutex_unlock(&p_ctx->mutex);
8487  break;
8488 
8489  case NI_DEVICE_TYPE_SCALER:
8490  ni_pthread_mutex_lock(&p_ctx->mutex);
8492 
8493  retval = ni_scaler_session_query_buffer_avail(p_ctx);
8494 
8496  ni_pthread_mutex_unlock(&p_ctx->mutex);
8497  break;
8498 
8499  default:
8500  break;
8501  }
8502 
8503  return retval;
8504 }
8505 
8506 /*!*****************************************************************************
8507 * \brief Sends raw YUV input to uploader instance and retrieves a HW descriptor
8508 * to represent it
8509 *
8510 * \param[in] p_ctx Pointer to a caller allocated
8511 * ni_session_context_t struct
8512 * \param[in] p_src_data Pointer to a caller allocated
8513 * ni_session_data_io_t struct which contains a
8514 * ni_frame_t data frame to send to uploader
8515 * \param[out] hwdesc HW descriptor to find frame in XCODER
8516 * \return On success
8517 * Total number of bytes read
8518 * On failure
8519 * NI_RETCODE_INVALID_PARAM
8520 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8521 * NI_RETCODE_ERROR_INVALID_SESSION
8522 *******************************************************************************/
8524 {
8526  if ((!hwdesc) || (!p_src_data))
8527  {
8528  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8529  __func__);
8530  return NI_RETCODE_INVALID_PARAM;
8531  }
8532  ni_pthread_mutex_lock(&p_ctx->mutex);
8534 
8535  retval = ni_hwupload_session_write(p_ctx, &p_src_data->data.frame, hwdesc);
8536 
8538  ni_pthread_mutex_unlock(&p_ctx->mutex);
8539 
8540  return retval;
8541 }
8542 
8543 /*!*****************************************************************************
8544 * \brief Allocate memory for the hwDescriptor buffer based on provided
8545 * parameters taking into account pic size and extra data.
8546 *
8547 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
8548 *
8549 * \param[in] video_width Width of the video frame
8550 * \param[in] video_height Height of the video frame
8551 * \param[in] extra_len Extra data size (incl. meta data)
8552 *
8553 * \return On success
8554 * NI_RETCODE_SUCCESS
8555 * On failure
8556 * NI_RETCODE_INVALID_PARAM
8557 * NI_RETCODE_ERROR_MEM_ALOC
8558 *****************************************************************************/
8560  int video_height, int extra_len)
8561 {
8562  void* p_buffer = NULL;
8563  int height_aligned = video_height;
8564  int retval = NI_RETCODE_SUCCESS;
8565 
8566  if (!p_frame)
8567  {
8568  ni_log(NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8569  __func__);
8570  return NI_RETCODE_INVALID_PARAM;
8571  }
8572 
8573  ni_log(NI_LOG_DEBUG, "%s: extra_len=%d\n", __func__, extra_len);
8574 
8575  int buffer_size = (int)sizeof(niFrameSurface1_t) + extra_len;
8576 
8577  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
8578 
8579  //Check if Need to free
8580  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
8581  {
8582  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
8583  __func__, p_frame->buffer_size);
8584  ni_frame_buffer_free(p_frame);
8585  }
8586 
8587  //Check if need to realocate
8588  if (p_frame->buffer_size != buffer_size)
8589  {
8590  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
8591  {
8592  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
8593  NI_ERRNO, __func__);
8594  retval = NI_RETCODE_ERROR_MEM_ALOC;
8595  LRETURN;
8596  }
8597 
8598  // init once after allocation
8599  memset(p_buffer, 0, buffer_size);
8600  p_frame->buffer_size = buffer_size;
8601  p_frame->p_buffer = p_buffer;
8602 
8603  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
8604  }
8605  else
8606  {
8607  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
8608  }
8609 
8610  p_frame->p_data[3] = p_frame->p_buffer;
8611  p_frame->p_data[0] = NULL;
8612  p_frame->p_data[1] = NULL;
8613  p_frame->p_data[2] = NULL;
8614 
8615  p_frame->data_len[0] = 0;//luma_size;
8616  p_frame->data_len[1] = 0;//chroma_b_size;
8617  p_frame->data_len[2] = 0;//chroma_r_size;
8618  p_frame->data_len[3] = sizeof(niFrameSurface1_t);
8619 
8620  p_frame->video_width = video_width;
8621  p_frame->video_height = height_aligned;
8622 
8623  ((niFrameSurface1_t*)p_frame->p_data[3])->device_handle = (int32_t)NI_INVALID_DEVICE_HANDLE;
8624 
8625  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
8626  p_frame->buffer_size);
8627 
8628 END:
8629 
8630  if (NI_RETCODE_SUCCESS != retval)
8631  {
8632  ni_aligned_free(p_buffer);
8633  }
8634 
8635  return retval;
8636 }
8637 
8638 /*!*****************************************************************************
8639 * \brief Recycle a frame buffer on card
8640 *
8641 * \param[in] surface Struct containing device and frame location to clear out
8642 * \param[in] device_handle handle to access device memory buffer is stored in
8643 *
8644 * \return On success NI_RETCODE_SUCCESS
8645 * On failure NI_RETCODE_INVALID_PARAM
8646 *******************************************************************************/
8648  int32_t device_handle)
8649 {
8651 
8652  if (surface)
8653  {
8654  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8656  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8657  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8658  device_handle);
8659  retval = ni_clear_instance_buf(surface);
8660  }
8661  else
8662  {
8663  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8664  }
8665 
8666  return retval;
8667 }
8668 
8669 /*!*****************************************************************************
8670 * \brief Recycle a frame buffer on card, only hwframe descriptor is needed
8671 *
8672 * \param[in] surface Struct containing device and frame location to clear out
8673 *
8674 * \return On success NI_RETCODE_SUCCESS
8675 * On failure NI_RETCODE_INVALID_PARAM
8676 *******************************************************************************/
8678 {
8680  int32_t saved_dma_buf_fd;
8681  if (surface)
8682  {
8683  if(surface->ui16FrameIdx == 0)
8684  {
8685  ni_log(NI_LOG_DEBUG, "%s(): Invaild frame index\n", __func__);
8686  return retval;
8687  }
8688  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8690  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8691  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8692  surface->device_handle);
8693  retval = ni_clear_instance_buf(surface);
8694  saved_dma_buf_fd = surface->dma_buf_fd;
8695  memset(surface, 0, sizeof(niFrameSurface1_t));
8696  surface->dma_buf_fd = saved_dma_buf_fd;
8697  }
8698  else
8699  {
8700  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8701  retval = NI_RETCODE_INVALID_PARAM;
8702  }
8703 
8704  return retval;
8705 }
8706 
8707 /*!*****************************************************************************
8708 * \brief Sends frame pool setup info to device
8709 *
8710 * \param[in] p_ctx Pointer to a caller allocated
8711 * ni_session_context_t struct
8712 * \param[in] pool_size Upload session initial allocated frames count
8713 * must be > 0,
8714 * \param[in] pool 0 use the normal pool
8715 * 1 use a dedicated P2P pool
8716 *
8717 * \return On success Return code
8718 * On failure
8719 * NI_RETCODE_INVALID_PARAM
8720 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8721 * NI_RETCODE_ERROR_INVALID_SESSION
8722 * NI_RETCODE_ERROR_MEM_ALOC
8723 *******************************************************************************/
8725  uint32_t pool_size, uint32_t pool)
8726 {
8728  if (!p_ctx)
8729  {
8730  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8731  __func__);
8732  return NI_RETCODE_INVALID_PARAM;
8733  }
8734  if (pool_size == 0 || pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8735  {
8736  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Invalid poolsize == 0 or > 100\n");
8737  return NI_RETCODE_INVALID_PARAM;
8738  }
8739  if (pool & NI_UPLOADER_FLAG_LM)
8740  {
8741  ni_log2(p_ctx, NI_LOG_DEBUG, "uploader buffer acquisition is limited!\n");
8742  }
8743  ni_pthread_mutex_lock(&p_ctx->mutex);
8745 
8746  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, pool);
8747 
8749  ni_pthread_mutex_unlock(&p_ctx->mutex);
8750 
8751  return retval;
8752 }
8753 
8754 /*!*****************************************************************************
8755 * \brief Sends frame pool change info to device
8756 *
8757 * \param[in] p_ctx Pointer to a caller allocated
8758 * ni_session_context_t struct
8759 * \param[in] pool_size if pool_size = 0, free allocated device memory buffers
8760 * if pool_size > 0, expand device frame buffer pool of
8761 * current instance with pool_size more frame buffers
8762 *
8763 * \return On success Return code
8764 * On failure
8765 * NI_RETCODE_FAILURE
8766 * NI_RETCODE_INVALID_PARAM
8767 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8768 * NI_RETCODE_ERROR_INVALID_SESSION
8769 * NI_RETCODE_ERROR_MEM_ALOC
8770 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8771 *******************************************************************************/
8773  uint32_t pool_size)
8774 {
8776  if (!p_ctx)
8777  {
8778  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8779  __func__);
8780  return NI_RETCODE_INVALID_PARAM;
8781  }
8782  if (ni_cmp_fw_api_ver(
8784  "6r3") < 0)
8785  {
8786  ni_log2(p_ctx, NI_LOG_ERROR,
8787  "ERROR: %s function not supported in FW API version < 6r3\n",
8788  __func__);
8790  }
8791  if (p_ctx->pool_type == NI_POOL_TYPE_NONE)
8792  {
8793  ni_log2(p_ctx, NI_LOG_ERROR,
8794  "ERROR: can't free or expand framepool of session 0x%x "
8795  "before init framepool\n", p_ctx->session_id);
8796  return NI_RETCODE_FAILURE;
8797  }
8798  if (pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8799  {
8800  ni_log2(p_ctx, NI_LOG_ERROR,
8801  "ERROR: Invalid poolsize > %u\n", NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL);
8802  return NI_RETCODE_INVALID_PARAM;
8803  }
8804  if (pool_size == 0)
8805  {
8806  ni_log2(p_ctx, NI_LOG_INFO, "Free frame pool of session 0x%x\n", p_ctx->session_id);
8807  }
8808 
8809  ni_pthread_mutex_lock(&p_ctx->mutex);
8811 
8812  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, p_ctx->pool_type);
8813 
8815  ni_pthread_mutex_unlock(&p_ctx->mutex);
8816 
8817  return retval;
8818 }
8819 
8820 /*!*****************************************************************************
8821  * \brief Set parameters on the device for the 2D engine
8822  *
8823  * \param[in] p_ctx pointer to session context
8824  * \param[in] p_params pointer to scaler parameters
8825  *
8826  * \return NI_RETCODE_INVALID_PARAM
8827  * NI_RETCODE_ERROR_INVALID_SESSION
8828  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8829  * NI_RETCODE_ERROR_MEM_ALOC
8830  ******************************************************************************/
8832  ni_scaler_params_t *p_params)
8833 {
8835 
8836  if (!p_ctx || !p_params)
8837  {
8838  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8839  __func__);
8840  return NI_RETCODE_INVALID_PARAM;
8841  }
8842  ni_pthread_mutex_lock(&p_ctx->mutex);
8844 
8845  retval = ni_config_instance_set_scaler_params(p_ctx, p_params);
8846 
8848  ni_pthread_mutex_unlock(&p_ctx->mutex);
8849 
8850  return retval;
8851 }
8852 
8853 /*!******************************************************************************
8854  * \brief Send a p_config command to configure scaling drawbox parameters.
8855  *
8856  * \param ni_session_context_t p_ctx - xcoder Context
8857  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_drawbox params_t struct
8858  *
8859  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
8860 *******************************************************************************/
8862  ni_scaler_drawbox_params_t *p_params)
8863 {
8864  void *p_scaler_config = NULL;
8865  uint32_t buffer_size = sizeof(ni_scaler_multi_drawbox_params_t);
8867  uint32_t ui32LBA = 0;
8868 
8869  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
8870 
8871  if (!p_ctx || !p_params)
8872  {
8873  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
8874  retval = NI_RETCODE_INVALID_PARAM;
8875  LRETURN;
8876  }
8877 
8878  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
8879  {
8880  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
8882  LRETURN;
8883  }
8884 
8885  buffer_size =
8886  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
8888  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
8889  {
8890  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
8891  NI_ERRNO, __func__);
8892  retval = NI_RETCODE_ERROR_MEM_ALOC;
8893  LRETURN;
8894  }
8895  memset(p_scaler_config, 0, buffer_size);
8896 
8897  //configure the session here
8900 
8901  memcpy(p_scaler_config, p_params, buffer_size);
8902 
8904  p_scaler_config, buffer_size, ui32LBA) < 0)
8905  {
8906  ni_log2(p_ctx, NI_LOG_ERROR,
8907  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
8908  ", hw_id, %d, xcoder_inst_id: %d\n",
8909  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
8910  // Close the session since we can't configure it as per fw
8911  retval = ni_scaler_session_close(p_ctx, 0);
8912  if (NI_RETCODE_SUCCESS != retval)
8913  {
8914  ni_log2(p_ctx, NI_LOG_ERROR,
8915  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
8916  "hw_id, %d, xcoder_inst_id: %d\n",
8917  __func__,
8918  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
8919  p_ctx->session_id);
8920  }
8921 
8923  }
8924 
8925 END:
8926 
8927  ni_aligned_free(p_scaler_config);
8928  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
8929 
8930  return retval;
8931 }
8932 
8933 /*!******************************************************************************
8934  * \brief Send a p_config command to configure scaling watermark parameters.
8935  *
8936  * \param ni_session_context_t p_ctx - xcoder Context
8937  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_watermark_params_t struct
8938  *
8939  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
8940 *******************************************************************************/
8942  ni_scaler_watermark_params_t *p_params)
8943 {
8944  void *p_scaler_config = NULL;
8945  uint32_t buffer_size = sizeof(ni_scaler_multi_watermark_params_t);
8947  uint32_t ui32LBA = 0;
8948 
8949  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
8950 
8951  if (!p_ctx || !p_params)
8952  {
8953  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
8954  retval = NI_RETCODE_INVALID_PARAM;
8955  LRETURN;
8956  }
8957 
8958  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
8959  {
8960  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
8962  LRETURN;
8963  }
8964 
8965  buffer_size =
8966  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
8968  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
8969  {
8970  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
8971  NI_ERRNO, __func__);
8972  retval = NI_RETCODE_ERROR_MEM_ALOC;
8973  LRETURN;
8974  }
8975  memset(p_scaler_config, 0, buffer_size);
8976 
8977  //configure the session here
8980 
8981  memcpy(p_scaler_config, p_params, buffer_size);
8982 
8984  p_scaler_config, buffer_size, ui32LBA) < 0)
8985  {
8986  ni_log2(p_ctx, NI_LOG_ERROR,
8987  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
8988  ", hw_id, %d, xcoder_inst_id: %d\n",
8989  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
8990  // Close the session since we can't configure it as per fw
8991  retval = ni_scaler_session_close(p_ctx, 0);
8992  if (NI_RETCODE_SUCCESS != retval)
8993  {
8994  ni_log2(p_ctx, NI_LOG_ERROR,
8995  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
8996  "hw_id, %d, xcoder_inst_id: %d\n",
8997  __func__,
8998  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
8999  p_ctx->session_id);
9000  }
9001 
9003  }
9004 
9005 END:
9006 
9007  ni_aligned_free(p_scaler_config);
9008  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
9009 
9010  return retval;
9011 }
9012 
9013 
9014 /*!*****************************************************************************
9015  * \brief Allocate a frame on the device for 2D engine or AI engine
9016  * to work on based on provided parameters
9017  *
9018  * \param[in] p_ctx pointer to session context
9019  * \param[in] width width, in pixels
9020  * \param[in] height height, in pixels
9021  * \param[in] format pixel format
9022  * \param[in] options options bitmap flags, bit 0 (NI_SCALER_FLAG_IO) is
9023  * 0=input frame or 1=output frame. Bit 1 (NI_SCALER_FLAG_PC) is
9024  * 0=single allocation, 1=create pool. Bit 2 (NI_SCALER_FLAG_PA) is
9025  * 0=straight alpha, 1=premultiplied alpha
9026  * \param[in] rectangle_width clipping rectangle width
9027  * \param[in] rectangle_height clipping rectangle height
9028  * \param[in] rectangle_x horizontal position of clipping rectangle
9029  * \param[in] rectangle_y vertical position of clipping rectangle
9030  * \param[in] rgba_color RGBA fill colour (for padding only)
9031  * \param[in] frame_index input hwdesc index
9032  * \param[in] device_type only NI_DEVICE_TYPE_SCALER
9033  * and NI_DEVICE_TYPE_AI (only needs p_ctx and frame_index)
9034  *
9035  * \return NI_RETCODE_INVALID_PARAM
9036  * NI_RETCODE_ERROR_INVALID_SESSION
9037  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9038  * NI_RETCODE_ERROR_MEM_ALOC
9039  ******************************************************************************/
9041  int width,
9042  int height,
9043  int format,
9044  int options,
9045  int rectangle_width,
9046  int rectangle_height,
9047  int rectangle_x,
9048  int rectangle_y,
9049  int rgba_color,
9050  int frame_index,
9051  ni_device_type_t device_type)
9052 {
9054 
9055  if (!p_ctx)
9056  {
9057  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9058  __func__);
9059  return NI_RETCODE_INVALID_PARAM;
9060  }
9061  ni_pthread_mutex_lock(&p_ctx->mutex);
9063 
9064  switch (device_type)
9065  {
9066  case NI_DEVICE_TYPE_SCALER:
9067  retval = ni_scaler_alloc_frame(p_ctx,width, height, format, options,
9068  rectangle_width, rectangle_height,
9069  rectangle_x, rectangle_y,
9070  rgba_color, frame_index);
9071  break;
9072 
9073  case NI_DEVICE_TYPE_AI:
9074  retval = ni_ai_alloc_hwframe(p_ctx, width, height, options, rgba_color,
9075  frame_index);
9076  break;
9077 
9080  /* fall through */
9081 
9082  default:
9083  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
9084  retval = NI_RETCODE_INVALID_PARAM;
9085  break;
9086  }
9087 
9089  ni_pthread_mutex_unlock(&p_ctx->mutex);
9090 
9091  return retval;
9092 }
9093 
9094 /*!*****************************************************************************
9095  * \brief Allocate a frame on the device and return the frame index
9096  *
9097  * \param[in] p_ctx pointer to session context
9098  * \param[in] p_out_surface pointer to output frame surface
9099  * \param[in] device_type currently only NI_DEVICE_TYPE_AI
9100  *
9101  * \return NI_RETCODE_INVALID_PARAM
9102  * NI_RETCODE_ERROR_INVALID_SESSION
9103  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
9104  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9105  * NI_RETCODE_ERROR_MEM_ALOC
9106  ******************************************************************************/
9108  niFrameSurface1_t *p_out_surface,
9109  ni_device_type_t device_type)
9110 {
9112 
9113  if (!p_ctx)
9114  {
9115  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, %p, return\n",
9116  __func__, p_ctx);
9117  return NI_RETCODE_INVALID_PARAM;
9118  }
9119  ni_pthread_mutex_lock(&p_ctx->mutex);
9121 
9122  switch (device_type)
9123  {
9124  case NI_DEVICE_TYPE_AI:
9125  retval = ni_ai_alloc_dst_frame(p_ctx, p_out_surface);
9126  break;
9127 
9128  case NI_DEVICE_TYPE_SCALER:
9131  /* fall through */
9132 
9133  default:
9134  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
9135  retval = NI_RETCODE_INVALID_PARAM;
9136  break;
9137  }
9138 
9140  ni_pthread_mutex_unlock(&p_ctx->mutex);
9141 
9142  return retval;
9143 }
9144 
9145 /*!*****************************************************************************
9146  * \brief Copy the data of src hwframe to dst hwframe
9147  *
9148  * \param[in] p_ctx pointer to session context
9149  * \param[in] p_frameclone_desc pointer to the frameclone descriptor
9150  *
9151  * \return NI_RETCODE_INVALID_PARAM
9152  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
9153  * NI_RETCODE_ERROR_INVALID_SESSION
9154  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9155  * NI_RETCODE_ERROR_MEM_ALOC
9156  ******************************************************************************/
9158  ni_frameclone_desc_t *p_frameclone_desc)
9159 {
9161 
9162  if (!p_ctx)
9163  {
9164  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9165  __func__);
9166  return NI_RETCODE_INVALID_PARAM;
9167  }
9168 
9169  if (ni_cmp_fw_api_ver(
9171  "6rL") < 0)
9172  {
9173  ni_log2(p_ctx, NI_LOG_ERROR,
9174  "Error: %s function not supported on device with FW API version < 6rL\n",
9175  __func__);
9177  }
9178 
9179  ni_pthread_mutex_lock(&p_ctx->mutex);
9181  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
9182  {
9183  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n",
9184  __func__);
9186  LRETURN;
9187  }
9188 
9189  retval = ni_hwframe_clone(p_ctx, p_frameclone_desc);
9190 
9191 END:
9193  ni_pthread_mutex_unlock(&p_ctx->mutex);
9194 
9195  return retval;
9196 }
9197 
9198 /*!*****************************************************************************
9199  * \brief Configure the 2D engine to work based on provided parameters
9200  *
9201  * \param[in] p_ctx pointer to session context
9202  * \param[in] p_cfg pointer to frame configuration
9203  *
9204  * \return NI_RETCODE_INVALID_PARAM
9205  * NI_RETCODE_ERROR_INVALID_SESSION
9206  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9207  * NI_RETCODE_ERROR_MEM_ALOC
9208  ******************************************************************************/
9210  ni_frame_config_t *p_cfg)
9211 {
9213 
9214  if (!p_ctx || !p_cfg)
9215  {
9216  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9217  __func__);
9218  return NI_RETCODE_INVALID_PARAM;
9219  }
9220 
9221  ni_pthread_mutex_lock(&p_ctx->mutex);
9223 
9224  switch (p_ctx->device_type)
9225  {
9226  case NI_DEVICE_TYPE_SCALER:
9227  retval = ni_scaler_config_frame(p_ctx, p_cfg);
9228  break;
9229 
9230  default:
9231  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9232  retval = NI_RETCODE_INVALID_PARAM;
9233  break;
9234  }
9235 
9237  ni_pthread_mutex_unlock(&p_ctx->mutex);
9238 
9239  return retval;
9240 }
9241 
9242 /*!*****************************************************************************
9243  * \brief Configure the 2D engine to work based on provided parameters
9244  *
9245  * \param[in] p_ctx pointer to session context
9246  * \param[in] p_cfg_in pointer to input frame configuration
9247  * \param[in] numInCfgs number of input frame configurations
9248  * \param[in] p_cfg_out pointer to output frame configuration
9249  *
9250  * \return NI_RETCODE_INVALID_PARAM
9251  * NI_RETCODE_ERROR_INVALID_SESSION
9252  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9253  * NI_RETCODE_ERROR_MEM_ALOC
9254  ******************************************************************************/
9256  ni_frame_config_t p_cfg_in[],
9257  int numInCfgs,
9258  ni_frame_config_t *p_cfg_out)
9259 {
9261 
9262  if (!p_ctx || !p_cfg_in)
9263  {
9264  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9265  __func__);
9266  return NI_RETCODE_INVALID_PARAM;
9267  }
9268 
9269  ni_pthread_mutex_lock(&p_ctx->mutex);
9271 
9272  switch (p_ctx->device_type)
9273  {
9274  case NI_DEVICE_TYPE_SCALER:
9275  retval = ni_scaler_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9276  break;
9277 
9278  case NI_DEVICE_TYPE_AI:
9279  retval = ni_ai_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9280  break;
9281 
9282  default:
9283  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9284  retval = NI_RETCODE_INVALID_PARAM;
9285  break;
9286  }
9287 
9289  ni_pthread_mutex_unlock(&p_ctx->mutex);
9290 
9291  return retval;
9292 }
9293 
9294 /*!*****************************************************************************
9295  * \brief Calculate the total size of a frame based on the upload
9296  * context attributes and includes rounding up to the page size
9297  *
9298  * \param[in] p_upl_ctx pointer to an uploader session context
9299  * \param[in] linesize array of line stride
9300  *
9301  * \return size
9302  * NI_RETCODE_INVALID_PARAM
9303  *
9304  ******************************************************************************/
9306  const int linesize[])
9307 {
9308  int pixel_format;
9309  int width, height;
9310  int alignedh;
9311  int luma, chroma_b, chroma_r;
9312  int total;
9313 
9314  pixel_format = p_upl_ctx->pixel_format;
9315  width = p_upl_ctx->active_video_width;
9316  height = p_upl_ctx->active_video_height;
9317 
9318  switch (pixel_format)
9319  {
9320  case NI_PIX_FMT_YUV420P:
9322  case NI_PIX_FMT_NV12:
9323  case NI_PIX_FMT_P010LE:
9324  if (width < 0 || width > NI_MAX_RESOLUTION_WIDTH)
9325  {
9326  return NI_RETCODE_INVALID_PARAM;
9327  }
9328 
9329  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9330  {
9331  return NI_RETCODE_INVALID_PARAM;
9332  }
9333  break;
9334 
9335  case NI_PIX_FMT_RGBA:
9336  case NI_PIX_FMT_ABGR:
9337  case NI_PIX_FMT_ARGB:
9338  case NI_PIX_FMT_BGRA:
9339  case NI_PIX_FMT_BGR0:
9340  if ((width < 0) || (width > NI_MAX_RESOLUTION_WIDTH))
9341  {
9342  return NI_RETCODE_INVALID_PARAM;
9343  }
9344 
9345  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9346  {
9347  return NI_RETCODE_INVALID_PARAM;
9348  }
9349  break;
9350 
9351  default:
9352  return NI_RETCODE_INVALID_PARAM;
9353  }
9354 
9355  alignedh = NI_VPU_CEIL(height, 2);
9356 
9357  switch (pixel_format)
9358  {
9359  case NI_PIX_FMT_YUV420P:
9361  luma = linesize[0] * alignedh;
9362  chroma_b = linesize[1] * alignedh / 2;
9363  chroma_r = linesize[2] * alignedh / 2;
9364  total =
9365  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9366  break;
9367 
9368  case NI_PIX_FMT_NV12:
9369  case NI_PIX_FMT_P010LE:
9370  luma = linesize[0] * alignedh;
9371  chroma_b = linesize[1] * alignedh / 2;
9372  chroma_r = 0;
9373  total =
9374  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9375  break;
9376 
9377  case NI_PIX_FMT_RGBA:
9378  case NI_PIX_FMT_ABGR:
9379  case NI_PIX_FMT_ARGB:
9380  case NI_PIX_FMT_BGRA:
9381  case NI_PIX_FMT_BGR0:
9382  total = width * height * 4 + NI_APP_ENC_FRAME_META_DATA_SIZE;
9383  break;
9384 
9385  default:
9386  return NI_RETCODE_INVALID_PARAM;
9387  break;
9388  }
9389 
9391 
9392  return total;
9393 }
9394 
9395 /*!*****************************************************************************
9396  * \brief Allocate memory for the frame buffer based on provided parameters
9397  * taking into account the pixel format, width, height, stride,
9398  * alignment, and extra data
9399  * \param[in] p_frame Pointer to caller allocated ni_frame_t
9400  * \param[in] pixel_format a pixel format in ni_pix_fmt_t enum
9401  * \param[in] video_width width, in pixels
9402  * \param[in] video_height height, in pixels
9403  * \param[in] linesize horizontal stride
9404  * \param[in] alignment apply a 16 pixel height alignment (T408 only)
9405  * \param[in] extra_len meta data size
9406  *
9407  * \return NI_RETCODE_SUCCESS
9408  * NI_RETCODE_INVALID_PARAM
9409  * NI_RETCODE_ERROR_MEM_ALOC
9410  *
9411  ******************************************************************************/
9413  int video_width, int video_height,
9414  int linesize[], int alignment,
9415  int extra_len)
9416 {
9417  int buffer_size;
9418  void *p_buffer = NULL;
9419  int retval = NI_RETCODE_SUCCESS;
9420  int height_aligned;
9421  int luma_size = 0;
9422  int chroma_b_size = 0;
9423  int chroma_r_size = 0;
9424 
9425  if (!p_frame)
9426  {
9427  ni_log(NI_LOG_ERROR, "Invalid frame pointer\n");
9428  return NI_RETCODE_INVALID_PARAM;
9429  }
9430 
9431  switch (pixel_format)
9432  {
9433  case NI_PIX_FMT_YUV420P:
9435  case NI_PIX_FMT_NV12:
9436  case NI_PIX_FMT_P010LE:
9437  case NI_PIX_FMT_NV16:
9438  case NI_PIX_FMT_YUYV422:
9439  case NI_PIX_FMT_UYVY422:
9440  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9441  {
9442  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9443  video_width);
9444  return NI_RETCODE_INVALID_PARAM;
9445  }
9446 
9447  if ((video_height < 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9448  {
9449  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9450  video_width);
9451  return NI_RETCODE_INVALID_PARAM;
9452  }
9453  break;
9454 
9455  case NI_PIX_FMT_RGBA:
9456  case NI_PIX_FMT_BGRA:
9457  case NI_PIX_FMT_ARGB:
9458  case NI_PIX_FMT_ABGR:
9459  case NI_PIX_FMT_BGR0:
9460  case NI_PIX_FMT_BGRP:
9461  /*
9462  * For 2D engine using RGBA, the minimum width is 32. There is no
9463  * height restriction. The 2D engine supports a height/width of up to
9464  * 32K but but we will limit the max height and width to 8K.
9465  */
9466  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9467  {
9468  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9469  video_width);
9470  return NI_RETCODE_INVALID_PARAM;
9471  }
9472 
9473  if ((video_height <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9474  {
9475  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9476  video_height);
9477  return NI_RETCODE_INVALID_PARAM;
9478  }
9479  break;
9480 
9481  default:
9482  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n",pixel_format);
9483  return NI_RETCODE_INVALID_PARAM;
9484  }
9485 
9486  if (QUADRA)
9487  {
9488  /* Quadra requires an even-numbered height/width */
9489  height_aligned = NI_VPU_CEIL(video_height, 2);
9490  }
9491  else
9492  {
9493  height_aligned = NI_VPU_ALIGN8(video_height);
9494 
9495  if (alignment)
9496  {
9497  /* 16-pixel aligned pixel height for Quadra */
9498  height_aligned = NI_VPU_ALIGN16(video_height);
9499  }
9500  }
9501 
9502  switch (pixel_format)
9503  {
9504  case NI_PIX_FMT_YUV420P:
9506  luma_size = linesize[0] * height_aligned;
9507 
9508  if (QUADRA)
9509  {
9510  chroma_b_size = linesize[1] * height_aligned / 2;
9511  chroma_r_size = linesize[2] * height_aligned / 2;
9512  }
9513  else
9514  {
9515  chroma_b_size = luma_size / 4;
9516  chroma_r_size = luma_size / 4;
9517  }
9518  break;
9519 
9520  case NI_PIX_FMT_RGBA:
9521  case NI_PIX_FMT_BGRA:
9522  case NI_PIX_FMT_ARGB:
9523  case NI_PIX_FMT_ABGR:
9524  case NI_PIX_FMT_BGR0:
9525  luma_size = linesize[0] * video_height;
9526  chroma_b_size = 0;
9527  chroma_r_size = 0;
9528  break;
9529 
9530  case NI_PIX_FMT_NV12:
9531  case NI_PIX_FMT_P010LE:
9532  if (QUADRA)
9533  {
9534  luma_size = linesize[0] * height_aligned;
9535  chroma_b_size = linesize[1] * height_aligned / 2;
9536  chroma_r_size = 0;
9537  break;
9538  }
9539  case NI_PIX_FMT_NV16:
9540  if (QUADRA)
9541  {
9542  luma_size = linesize[0] * video_height;
9543  chroma_b_size = linesize[1] * video_height;
9544  chroma_r_size = 0;
9545  break;
9546  }
9547  case NI_PIX_FMT_YUYV422:
9548  case NI_PIX_FMT_UYVY422:
9549  if (QUADRA)
9550  {
9551  luma_size = linesize[0] * video_height;
9552  chroma_b_size = 0;
9553  chroma_r_size = 0;
9554  break;
9555  }
9556  case NI_PIX_FMT_BGRP:
9557  if (QUADRA)
9558  {
9559  luma_size = NI_VPU_ALIGN32(linesize[0] * video_height);
9560  chroma_b_size = NI_VPU_ALIGN32(linesize[1] * video_height);
9561  chroma_r_size = NI_VPU_ALIGN32(linesize[2] * video_height);
9562  break;
9563  }
9564  /*fall through*/
9565  default:
9566  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9567  return NI_RETCODE_INVALID_PARAM;
9568  }
9569 
9570  buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
9571 
9572  /* Allocate a buffer size that is page aligned for the host */
9573  buffer_size = NI_VPU_CEIL(buffer_size,NI_MEM_PAGE_ALIGNMENT) + NI_MEM_PAGE_ALIGNMENT;
9574 
9575  /* If this buffer has a different size, realloc a new buffer */
9576  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9577  {
9578  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9579  p_frame->buffer_size);
9580  ni_frame_buffer_free(p_frame);
9581  }
9582 
9583  if (p_frame->buffer_size != buffer_size)
9584  {
9585  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9586  {
9587  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9588  retval = NI_RETCODE_ERROR_MEM_ALOC;
9589  LRETURN;
9590  }
9591 
9592  memset(p_buffer, 0, buffer_size);
9593  p_frame->buffer_size = buffer_size;
9594  p_frame->p_buffer = p_buffer;
9595  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
9596  }
9597  else
9598  {
9599  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
9600  }
9601 
9602  switch (pixel_format)
9603  {
9604  case NI_PIX_FMT_YUV420P:
9606  p_frame->p_data[0] = p_frame->p_buffer;
9607  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
9608  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
9609  p_frame->p_data[3] = NULL;
9610 
9611  p_frame->data_len[0] = luma_size;
9612  p_frame->data_len[1] = chroma_b_size;
9613  p_frame->data_len[2] = chroma_r_size;
9614  p_frame->data_len[3] = 0;
9615  video_width = NI_VPU_ALIGN128(video_width);
9616  break;
9617 
9618  case NI_PIX_FMT_RGBA:
9619  case NI_PIX_FMT_BGRA:
9620  case NI_PIX_FMT_ARGB:
9621  case NI_PIX_FMT_ABGR:
9622  case NI_PIX_FMT_BGR0:
9623  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9624  p_frame->p_data[1] = NULL;
9625  p_frame->p_data[2] = NULL;
9626  p_frame->p_data[3] = NULL;
9627 
9628  p_frame->data_len[0] = luma_size;
9629  p_frame->data_len[1] = 0;
9630  p_frame->data_len[2] = 0;
9631  p_frame->data_len[3] = 0;
9632  video_width = NI_VPU_ALIGN16(video_width);
9633  break;
9634 
9635  case NI_PIX_FMT_NV12:
9636  case NI_PIX_FMT_P010LE:
9637  if (QUADRA)
9638  {
9639  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9640  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9641  p_frame->p_data[2] = NULL;
9642  p_frame->p_data[3] = NULL;
9643 
9644  p_frame->data_len[0] = luma_size;
9645  p_frame->data_len[1] = chroma_b_size;
9646  p_frame->data_len[2] = 0;
9647  p_frame->data_len[3] = 0;
9648 
9649  video_width = NI_VPU_ALIGN128(video_width);
9650  break;
9651  }
9652  case NI_PIX_FMT_NV16:
9653  if (QUADRA)
9654  {
9655  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9656  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9657  p_frame->p_data[2] = NULL;
9658  p_frame->p_data[3] = NULL;
9659 
9660  p_frame->data_len[0] = luma_size;
9661  p_frame->data_len[1] = chroma_b_size;
9662  p_frame->data_len[2] = 0;
9663  p_frame->data_len[3] = 0;
9664 
9665  video_width = NI_VPU_ALIGN64(video_width);
9666  break;
9667  }
9668 
9669  case NI_PIX_FMT_YUYV422:
9670  case NI_PIX_FMT_UYVY422:
9671  if (QUADRA)
9672  {
9673  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9674  p_frame->p_data[1] = NULL;
9675  p_frame->p_data[2] = NULL;
9676  p_frame->p_data[3] = NULL;
9677 
9678  p_frame->data_len[0] = luma_size;
9679  p_frame->data_len[1] = 0;
9680  p_frame->data_len[2] = 0;
9681  p_frame->data_len[3] = 0;
9682  video_width = NI_VPU_ALIGN16(video_width);
9683  break;
9684  }
9685  case NI_PIX_FMT_BGRP:
9686  if (QUADRA)
9687  {
9688  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9689  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9690  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + chroma_b_size;
9691  p_frame->p_data[3] = NULL;
9692 
9693  p_frame->data_len[0] = luma_size;
9694  p_frame->data_len[1] = chroma_b_size;
9695  p_frame->data_len[2] = chroma_r_size;
9696  p_frame->data_len[3] = 0;
9697  break;
9698  }
9699  /* fall through */
9700  default:
9701  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9702  retval = NI_RETCODE_INVALID_PARAM;
9703  LRETURN;
9704  }
9705 
9706  p_frame->video_width = video_width;
9707  p_frame->video_height = height_aligned;
9708 
9709  ni_log(NI_LOG_DEBUG, "%s success: w=%d; h=%d; aligned buffer size=%d\n",
9710  __func__, video_width, video_height, buffer_size);
9711 
9712 END:
9713 
9714  if (retval != NI_RETCODE_SUCCESS)
9715  {
9716  ni_aligned_free(p_buffer);
9717  }
9718 
9719  return retval;
9720 }
9721 
9723  ni_network_data_t *p_network,
9724  const char *file)
9725 {
9726  FILE *fp = NULL;
9727  struct stat file_stat;
9729  unsigned char *buffer = NULL;
9730 
9731  if (!p_ctx)
9732  {
9733  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9734  __func__);
9735  return NI_RETCODE_INVALID_PARAM;
9736  }
9737  ni_pthread_mutex_lock(&p_ctx->mutex);
9739  ni_pthread_mutex_unlock(&p_ctx->mutex);
9740 
9741  char errmsg[NI_ERRNO_LEN] = {0};
9742  if (stat(file, &file_stat) != 0)
9743  {
9744  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
9745  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to get network binary file stat, %s\n",
9746  __func__, errmsg);
9747  retval = NI_RETCODE_FAILURE;
9748  LRETURN;
9749  }
9750 
9751  if (file_stat.st_size == 0)
9752  {
9753  ni_log2(p_ctx, NI_LOG_ERROR, "%s: network binary size is null\n", __func__);
9754  retval = NI_RETCODE_FAILURE;
9755  LRETURN;
9756  }
9757 
9758  ni_fopen(&fp, file, "rb");
9759  if (!fp)
9760  {
9761  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
9762  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to open network binary, %s\n", __func__,
9763  errmsg);
9764  retval = NI_RETCODE_FAILURE;
9765  LRETURN;
9766  }
9767 
9768  buffer = malloc(file_stat.st_size);
9769  if (!buffer)
9770  {
9771  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to alloate memory\n", __func__);
9772  retval = NI_RETCODE_ERROR_MEM_ALOC;
9773  LRETURN;
9774  }
9775 
9776  if (fread(buffer, file_stat.st_size, 1, fp) != 1)
9777  {
9778  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to read network binary\n", __func__);
9779  retval = NI_RETCODE_FAILURE;
9780  LRETURN;
9781  }
9782 
9783  retval =
9784  ni_config_instance_network_binary(p_ctx, buffer, file_stat.st_size);
9785  if (retval != NI_RETCODE_SUCCESS)
9786  {
9787  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9788  __func__, retval);
9789  LRETURN;
9790  }
9791 
9792  retval = ni_config_read_inout_layers(p_ctx, p_network);
9793  if (retval != NI_RETCODE_SUCCESS)
9794  {
9795  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9796  retval);
9797  }
9798 
9799 END:
9800 
9801  if (fp)
9802  {
9803  fclose(fp);
9804  }
9805  free(buffer);
9806 
9807  ni_pthread_mutex_lock(&p_ctx->mutex);
9809  ni_pthread_mutex_unlock(&p_ctx->mutex);
9810 
9811  return retval;
9812 }
9813 
9815  ni_network_data_t *p_network)
9816 {
9818 
9819  if (!p_ctx)
9820  {
9821  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9822  __func__);
9823  return NI_RETCODE_INVALID_PARAM;
9824  }
9825 
9826  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6ro") < 0))
9827  {
9828  ni_log2(p_ctx, NI_LOG_ERROR, "Error: hvsplus filter not supported on device with FW API version < 6ro\n");
9830  }
9831 
9832  ni_pthread_mutex_lock(&p_ctx->mutex);
9834  ni_pthread_mutex_unlock(&p_ctx->mutex);
9835 
9836  retval =
9837  ni_config_instance_hvsplus(p_ctx); //, buffer, file_stat.st_size);
9838  if (retval != NI_RETCODE_SUCCESS)
9839  {
9840  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9841  __func__, retval);
9842  LRETURN;
9843  }
9844 
9845  retval = ni_config_read_inout_layers(p_ctx, p_network);
9846  if (retval != NI_RETCODE_SUCCESS)
9847  {
9848  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9849  retval);
9850  }
9851 
9852 END:
9853 
9854  ni_pthread_mutex_lock(&p_ctx->mutex);
9856  ni_pthread_mutex_unlock(&p_ctx->mutex);
9857 
9858  return retval;
9859 }
9860 
9862  ni_network_data_t *p_network)
9863 {
9864  uint32_t buffer_size = 0;
9865  void *p_buffer = NULL;
9866  int retval = NI_RETCODE_SUCCESS;
9867  uint32_t i, this_size;
9868  ni_network_layer_info_t *p_linfo;
9869 
9870  if (!p_frame || !p_network)
9871  {
9872  ni_log(NI_LOG_ERROR, "Invalid frame or network layer pointer\n");
9873  return NI_RETCODE_INVALID_PARAM;
9874  }
9875 
9876  p_linfo = &p_network->linfo;
9877  for (i = 0; i < p_network->input_num; i++)
9878  {
9879  this_size = ni_ai_network_layer_size(&p_linfo->in_param[i]);
9880  this_size =
9881  (this_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
9882  if (p_network->inset[i].offset != buffer_size)
9883  {
9885  "ERROR: %s(): invalid buffer_size of network\n", __func__);
9886  return NI_RETCODE_INVALID_PARAM;
9887  }
9888  buffer_size += this_size;
9889  }
9890 
9891  /* fixed size */
9892  p_frame->data_len[0] = buffer_size;
9893 
9894  /* Allocate a buffer size that is page aligned for the host */
9895  buffer_size = (buffer_size + NI_MEM_PAGE_ALIGNMENT - 1) &
9896  ~(NI_MEM_PAGE_ALIGNMENT - 1);
9897 
9898  /* If this buffer has a different size, realloc a new buffer */
9899  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9900  {
9901  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9902  p_frame->buffer_size);
9903  ni_frame_buffer_free(p_frame);
9904  }
9905 
9906  if (p_frame->buffer_size != buffer_size)
9907  {
9908  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9909  {
9910  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9911  retval = NI_RETCODE_ERROR_MEM_ALOC;
9912  LRETURN;
9913  }
9914 
9915  // memset(p_buffer, 0, buffer_size);
9916  p_frame->buffer_size = buffer_size;
9917  p_frame->p_buffer = p_buffer;
9918  ni_log(NI_LOG_DEBUG, "%s(): allocated new p_frame buffer\n", __func__);
9919  } else
9920  {
9921  ni_log(NI_LOG_DEBUG, "%s(): reuse p_frame buffer\n", __func__);
9922  }
9923 
9924  p_frame->p_data[0] = p_frame->p_buffer;
9925  p_frame->p_data[1] = NULL;
9926  p_frame->p_data[2] = NULL;
9927  p_frame->p_data[3] = NULL;
9928 
9929  p_frame->iovec = NULL;
9930  p_frame->iovec_num = 0;
9931 
9932  ni_log(NI_LOG_DEBUG, "%s() success: aligned buffer size=%u\n", __func__,
9933  buffer_size);
9934 
9935 END:
9936 
9937  if (retval != NI_RETCODE_SUCCESS)
9938  {
9939  ni_aligned_free(p_buffer);
9940  }
9941 
9942  return retval;
9943 }
9944 
9946  ni_network_data_t *p_network)
9947 {
9948  void *p_buffer = NULL;
9949  int retval = NI_RETCODE_SUCCESS;
9950  uint32_t buffer_size = 0;
9951  uint32_t i, data_size;
9952  ni_network_layer_info_t *p_linfo;
9953 
9954  if (!p_packet || !p_network)
9955  {
9956  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
9957  __func__);
9958  return NI_RETCODE_INVALID_PARAM;
9959  }
9960 
9961  p_linfo = &p_network->linfo;
9962  for (i = 0; i < p_network->output_num; i++)
9963  {
9964  data_size = ni_ai_network_layer_size(&p_linfo->out_param[i]);
9965  data_size =
9966  (data_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
9967  if (p_network->outset[i].offset != buffer_size)
9968  {
9970  "ERROR: %s(): invalid buffer_size of network\n", __func__);
9971  return NI_RETCODE_INVALID_PARAM;
9972  }
9973  buffer_size += data_size;
9974  }
9975  data_size = buffer_size;
9976 
9977  ni_log(NI_LOG_DEBUG, "%s(): packet_size=%u\n", __func__, buffer_size);
9978 
9979  if (buffer_size & (NI_MEM_PAGE_ALIGNMENT - 1))
9980  {
9981  buffer_size = (buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) &
9982  ~(NI_MEM_PAGE_ALIGNMENT - 1);
9983  }
9984 
9985  if (p_packet->buffer_size == buffer_size)
9986  {
9987  p_packet->p_data = p_packet->p_buffer;
9988  ni_log(NI_LOG_DEBUG, "%s(): reuse current p_packet buffer\n", __func__);
9989  LRETURN; //Already allocated the exact size
9990  } else if (p_packet->buffer_size > 0)
9991  {
9993  "%s(): free current p_packet, p_packet->buffer_size=%u\n",
9994  __func__, p_packet->buffer_size);
9995  ni_packet_buffer_free(p_packet);
9996  }
9997  ni_log(NI_LOG_DEBUG, "%s(): Allocating p_packet buffer, buffer_size=%u\n",
9998  __func__, buffer_size);
9999 
10000  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
10001  {
10002  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
10003  NI_ERRNO, __func__);
10004  retval = NI_RETCODE_ERROR_MEM_ALOC;
10005  LRETURN;
10006  }
10007 
10008  p_packet->buffer_size = buffer_size;
10009  p_packet->p_buffer = p_buffer;
10010  p_packet->p_data = p_packet->p_buffer;
10011  p_packet->data_len = data_size;
10012 
10013 END:
10014 
10015  if (NI_RETCODE_SUCCESS != retval)
10016  {
10017  ni_aligned_free(p_buffer);
10018  }
10019 
10020  ni_log(NI_LOG_TRACE, "%s(): exit: p_packet->buffer_size=%u\n", __func__,
10021  p_packet->buffer_size);
10022 
10023  return retval;
10024 }
10025 
10026 /*!*****************************************************************************
10027  * \brief Reconfigure bitrate dynamically during encoding.
10028  *
10029  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10030  * \param[in] bitrate Target bitrate to set
10031  *
10032  * \return On success NI_RETCODE_SUCCESS
10033  * On failure NI_RETCODE_INVALID_PARAM
10034  ******************************************************************************/
10036 {
10037  if (!p_ctx || bitrate < NI_MIN_BITRATE || bitrate > NI_MAX_BITRATE)
10038  {
10039  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid bitrate passed in %d\n",
10040  __func__, bitrate);
10041  return NI_RETCODE_INVALID_PARAM;
10042  }
10043  ni_pthread_mutex_lock(&p_ctx->mutex);
10045 
10046  if (p_ctx->target_bitrate > 0)
10047  {
10048  ni_log2(p_ctx, NI_LOG_DEBUG,
10049  "Warning: %s(): bitrate %d overwriting current one %d\n",
10050  __func__, bitrate, p_ctx->target_bitrate);
10051  }
10052 
10053  p_ctx->target_bitrate = bitrate;
10054 
10056  ni_pthread_mutex_unlock(&p_ctx->mutex);
10057 
10058  return NI_RETCODE_SUCCESS;
10059 }
10060 
10061 /*!*****************************************************************************
10062  * \brief Reconfigure intraPeriod dynamically during encoding.
10063  *
10064  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10065  * \param[in] intra_period Target intra period to set
10066  *
10067  *
10068  * \return On success NI_RETCODE_SUCCESS
10069  * On failure NI_RETCODE_INVALID_PARAM
10070  *
10071  * NOTE - the frame upon which intra period is reconfigured is encoded as IDR frame
10072  * NOTE - reconfigure intra period is not allowed if intraRefreshMode is enabled or if gopPresetIdx is 1
10073  *
10074  ******************************************************************************/
10076  int32_t intra_period)
10077 {
10078  if (!p_ctx || intra_period < 0 || intra_period > 1024)
10079  {
10080  ni_log(NI_LOG_ERROR, "ERROR: %s(): invalid intraPeriod passed in %d\n",
10081  __func__, intra_period);
10082  return NI_RETCODE_INVALID_PARAM;
10083  }
10084  ni_pthread_mutex_lock(&p_ctx->mutex);
10086 
10087  if (p_ctx->reconfig_intra_period >= 0)
10088  {
10090  "Warning: %s(): intraPeriod %d overwriting current one %d\n",
10091  __func__, intra_period, p_ctx->reconfig_intra_period);
10092  }
10093 
10094  p_ctx->reconfig_intra_period = intra_period;
10095 
10097  ni_pthread_mutex_unlock(&p_ctx->mutex);
10098 
10099  return NI_RETCODE_SUCCESS;
10100 }
10101 
10102 /*!*****************************************************************************
10103  * \brief Reconfigure VUI HRD dynamically during encoding.
10104  *
10105  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10106  * \param[in] bitrate Target bitrate to set
10107  *
10108  * \return On success NI_RETCODE_SUCCESS
10109  * On failure NI_RETCODE_INVALID_PARAM
10110  ******************************************************************************/
10112 {
10113  if (!p_ctx || vui->colorDescPresent < 0 || vui->colorDescPresent > 1)
10114  {
10115  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid colorDescPresent passed in %d\n",
10116  __func__, vui->colorDescPresent);
10117  return NI_RETCODE_INVALID_PARAM;
10118  }
10119 
10121  {
10122  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid aspect ratio passed in (%dx%d)\n",
10123  __func__, vui->aspectRatioWidth, vui->aspectRatioHeight);
10124  return NI_RETCODE_INVALID_PARAM;
10125  }
10126 
10127  if (vui->videoFullRange < 0 || vui->videoFullRange > 1)
10128  {
10129  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid videoFullRange passed in %d\n",
10130  __func__, vui->videoFullRange);
10131  return NI_RETCODE_INVALID_PARAM;
10132  }
10133 
10134  ni_pthread_mutex_lock(&p_ctx->mutex);
10136 
10137  p_ctx->vui.colorDescPresent = vui->colorDescPresent;
10138  p_ctx->vui.colorPrimaries = vui->colorPrimaries;
10139  p_ctx->vui.colorTrc = vui->colorTrc;
10140  p_ctx->vui.colorSpace = vui->colorSpace;
10141  p_ctx->vui.aspectRatioWidth = vui->aspectRatioWidth;
10142  p_ctx->vui.aspectRatioHeight = vui->aspectRatioHeight;
10143  p_ctx->vui.videoFullRange = vui->videoFullRange;
10144 
10146  ni_pthread_mutex_unlock(&p_ctx->mutex);
10147 
10148  return NI_RETCODE_SUCCESS;
10149 }
10150 
10151 /*!*****************************************************************************
10152  * \brief Force next frame to be IDR frame during encoding.
10153  *
10154  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10155  *
10156  * \return On success NI_RETCODE_SUCCESS
10157  ******************************************************************************/
10159 {
10160  if (!p_ctx)
10161  {
10162  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10163  __func__);
10164  return NI_RETCODE_INVALID_PARAM;
10165  }
10166  ni_pthread_mutex_lock(&p_ctx->mutex);
10168 
10169  if (p_ctx->force_idr_frame)
10170  {
10171  ni_log2(p_ctx, NI_LOG_DEBUG, "Warning: %s(): already forcing IDR frame\n",
10172  __func__);
10173  }
10174 
10175  p_ctx->force_idr_frame = 1;
10176 
10178  ni_pthread_mutex_unlock(&p_ctx->mutex);
10179 
10180  return NI_RETCODE_SUCCESS;
10181 }
10182 
10183 /*!*****************************************************************************
10184  * \brief Set a frame's support of Long Term Reference frame during encoding.
10185  *
10186  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10187  * \param[in] ltr Pointer to struct specifying LTR support
10188  *
10189  * \return On success NI_RETCODE_SUCCESS
10190  * On failure NI_RETCODE_INVALID_PARAM
10191  ******************************************************************************/
10193 {
10194  if (!p_ctx)
10195  {
10196  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10197  __func__);
10198  return NI_RETCODE_INVALID_PARAM;
10199  }
10200  ni_pthread_mutex_lock(&p_ctx->mutex);
10201 
10205 
10206  ni_pthread_mutex_unlock(&p_ctx->mutex);
10207 
10208  return NI_RETCODE_SUCCESS;
10209 }
10210 
10211 /*!*****************************************************************************
10212  * \brief Set Long Term Reference interval
10213  *
10214  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10215  * \param[in] ltr_interval the new long term reference inteval value
10216  *
10217  * \return On success NI_RETCODE_SUCCESS
10218  * On failure NI_RETCODE_INVALID_PARAM
10219  ******************************************************************************/
10221  int32_t ltr_interval)
10222 {
10223  if (!p_ctx)
10224  {
10225  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10226  __func__);
10227  return NI_RETCODE_INVALID_PARAM;
10228  }
10229  ni_pthread_mutex_lock(&p_ctx->mutex);
10230 
10231  p_ctx->ltr_interval = ltr_interval;
10232 
10233  ni_pthread_mutex_unlock(&p_ctx->mutex);
10234 
10235  return NI_RETCODE_SUCCESS;
10236 }
10237 
10238 /*!*****************************************************************************
10239  * \brief Set frame reference invalidation
10240  *
10241  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10242  * \param[in] frame_num frame number after which all references shall be
10243  * invalidated
10244  *
10245  * \return On success NI_RETCODE_SUCCESS
10246  * On failure NI_RETCODE_INVALID_PARAM
10247  ******************************************************************************/
10249  int32_t frame_num)
10250 {
10251  if (!p_ctx)
10252  {
10253  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10254  __func__);
10255  return NI_RETCODE_INVALID_PARAM;
10256  }
10257  ni_pthread_mutex_lock(&p_ctx->mutex);
10258  p_ctx->ltr_frame_ref_invalid = frame_num;
10259  ni_pthread_mutex_unlock(&p_ctx->mutex);
10260 
10261  return NI_RETCODE_SUCCESS;
10262 }
10263 
10264 /*!*****************************************************************************
10265  * \brief Reconfigure framerate dynamically during encoding.
10266  *
10267  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10268  * \param[in] framerate Target framerate to set
10269  *
10270  * \return On success NI_RETCODE_SUCCESS
10271  * On failure NI_RETCODE_INVALID_PARAM
10272  ******************************************************************************/
10274  ni_framerate_t *framerate)
10275 {
10276  int32_t framerate_num = framerate->framerate_num;
10277  int32_t framerate_denom = framerate->framerate_denom;
10278  if (!p_ctx || framerate_num <= 0 || framerate_denom <= 0)
10279  {
10280  ni_log2(p_ctx, NI_LOG_ERROR,
10281  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10282  framerate_num, framerate_denom);
10283  return NI_RETCODE_INVALID_PARAM;
10284  }
10285 
10286  if ((framerate_num % framerate_denom) != 0)
10287  {
10288  uint32_t numUnitsInTick = 1000;
10289  framerate_num = framerate_num / framerate_denom;
10290  framerate_denom = numUnitsInTick + 1;
10291  framerate_num += 1;
10292  framerate_num *= numUnitsInTick;
10293  } else
10294  {
10295  framerate_num = framerate_num / framerate_denom;
10296  framerate_denom = 1;
10297  }
10298 
10299  if (((framerate_num + framerate_denom - 1) / framerate_denom) >
10301  {
10302  ni_log2(p_ctx, NI_LOG_ERROR,
10303  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10304  framerate->framerate_num, framerate->framerate_denom);
10305  return NI_RETCODE_INVALID_PARAM;
10306  }
10307 
10308  ni_pthread_mutex_lock(&p_ctx->mutex);
10310 
10311  if (p_ctx->framerate.framerate_num > 0)
10312  {
10313  ni_log2(p_ctx, NI_LOG_DEBUG,
10314  "Warning: %s(): framerate (%d/%d) overwriting current "
10315  "one (%d/%d)\n",
10316  __func__, framerate_num, framerate_denom,
10317  p_ctx->framerate.framerate_num,
10318  p_ctx->framerate.framerate_denom);
10319  }
10320 
10321  p_ctx->framerate.framerate_num = framerate_num;
10322  p_ctx->framerate.framerate_denom = framerate_denom;
10323 
10325  ni_pthread_mutex_unlock(&p_ctx->mutex);
10326 
10327  return NI_RETCODE_SUCCESS;
10328 }
10329 
10330 /*!*****************************************************************************
10331  * \brief Reconfigure maxFrameSize dynamically during encoding.
10332  *
10333  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10334  * \param[in] max_frame_size maxFrameSize to set
10335  *
10336  * \return On success NI_RETCODE_SUCCESS
10337  * On failure NI_RETCODE_INVALID_PARAM
10338  *
10339  * NOTE - maxFrameSize_Bytes value less than ((bitrate / 8) / framerate) will be rejected
10340  *
10341  ******************************************************************************/
10343 {
10344  ni_xcoder_params_t *api_param;
10345  int32_t bitrate, framerate_num, framerate_denom;
10346  uint32_t maxFrameSize = (uint32_t)max_frame_size / 2000;
10347  uint32_t min_maxFrameSize;
10348 
10349  if (!p_ctx || !p_ctx->p_session_config)
10350  {
10351  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10352  __func__);
10353  return NI_RETCODE_INVALID_PARAM;
10354  }
10355 
10356  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10357 
10358  if (!api_param->low_delay_mode)
10359  {
10360  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size is valid only when lowDelay mode is enabled\n",
10361  __func__, max_frame_size);
10362  return NI_RETCODE_INVALID_PARAM;
10363  }
10364 
10365  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10366 
10367  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10368  {
10369  framerate_num = p_ctx->framerate.framerate_num;
10370  framerate_denom = p_ctx->framerate.framerate_denom;
10371  }
10372  else
10373  {
10374  framerate_num = (int32_t) api_param->fps_number;
10375  framerate_denom = (int32_t) api_param->fps_denominator;
10376  }
10377 
10378  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10379 
10380  if (maxFrameSize < min_maxFrameSize)
10381  {
10382  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size %d is too small (invalid)\n",
10383  __func__, max_frame_size);
10384  return NI_RETCODE_INVALID_PARAM;
10385  }
10386  if (max_frame_size > NI_MAX_FRAME_SIZE) {
10387  max_frame_size = NI_MAX_FRAME_SIZE;
10388  }
10389 
10390  ni_pthread_mutex_lock(&p_ctx->mutex);
10392 
10393  if (p_ctx->max_frame_size > 0)
10394  {
10395  ni_log2(p_ctx, NI_LOG_DEBUG,
10396  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10397  __func__, max_frame_size, p_ctx->max_frame_size);
10398  }
10399 
10400  p_ctx->max_frame_size = max_frame_size;
10401 
10403  ni_pthread_mutex_unlock(&p_ctx->mutex);
10404 
10405  return NI_RETCODE_SUCCESS;
10406 }
10407 
10408 /*!*****************************************************************************
10409  * \brief Reconfigure min&max qp dynamically during encoding.
10410  *
10411  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10412  * \param[in] ni_rc_min_max_qp Target min&max qp to set
10413  *
10414  * \return On success NI_RETCODE_SUCCESS
10415  * On failure NI_RETCODE_INVALID_PARAM
10416  ******************************************************************************/
10418  ni_rc_min_max_qp *p_min_max_qp)
10419 {
10420  int32_t minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB;
10421 
10422  if (!p_ctx || !p_min_max_qp)
10423  {
10424  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_min_max_qp pointer\n",
10425  __func__);
10426  return NI_RETCODE_INVALID_PARAM;
10427  }
10428 
10429  minQpI = p_min_max_qp->minQpI;
10430  maxQpI = p_min_max_qp->maxQpI;
10431  maxDeltaQp = p_min_max_qp->maxDeltaQp;
10432  minQpPB = p_min_max_qp->minQpPB;
10433  maxQpPB = p_min_max_qp->maxQpPB;
10434 
10435  if (minQpI > maxQpI || minQpPB > maxQpPB ||
10436  maxQpI > 51 || minQpI < 0 || maxQpPB > 51 || minQpPB < 0)
10437  {
10438  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid qp setting <%d %d %d %d %d>\n",
10439  __func__, minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB);
10440  return NI_RETCODE_INVALID_PARAM;
10441  }
10442 
10443  ni_pthread_mutex_lock(&p_ctx->mutex);
10445 
10446  p_ctx->enc_change_params->minQpI = minQpI;
10447  p_ctx->enc_change_params->maxQpI = maxQpI;
10448  p_ctx->enc_change_params->maxDeltaQp = maxDeltaQp;
10449  p_ctx->enc_change_params->minQpPB = minQpPB;
10450  p_ctx->enc_change_params->maxQpPB = maxQpPB;
10451 
10453  ni_pthread_mutex_unlock(&p_ctx->mutex);
10454 
10455  return NI_RETCODE_SUCCESS;
10456 }
10457 
10458 /*!*****************************************************************************
10459  * \brief Reconfigure crf value dynamically during encoding.
10460  *
10461  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10462  * \param[in] crf crf value to reconfigure
10463  *
10464  * \return On success NI_RETCODE_SUCCESS
10465  * On failure NI_RETCODE_INVALID_PARAM
10466  ******************************************************************************/
10468  int32_t crf)
10469 {
10470  ni_xcoder_params_t *api_param;
10471 
10472  if (!p_ctx || !p_ctx->p_session_config)
10473  {
10474  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10475  __func__);
10476  return NI_RETCODE_INVALID_PARAM;
10477  }
10478 
10479  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10480 
10481  if (api_param->cfg_enc_params.crf < 0)
10482  {
10483  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %d is valid only in CRF mode\n",
10484  __func__, crf);
10485  return NI_RETCODE_INVALID_PARAM;
10486  }
10487 
10488  if (crf < 0 || crf > 51)
10489  {
10490  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %d is invalid (valid range in [0..51])\n",
10491  __func__, crf);
10492  return NI_RETCODE_INVALID_PARAM;
10493  }
10494 
10495  ni_pthread_mutex_lock(&p_ctx->mutex);
10496 
10498 
10499  if (p_ctx->reconfig_crf >= 0)
10500  {
10501  ni_log2(p_ctx, NI_LOG_DEBUG,
10502  "Warning: %s(): crf reconfig value %d overwriting current reconfig_crf %d\n",
10503  __func__, crf, p_ctx->reconfig_crf);
10504  }
10505 
10506  p_ctx->reconfig_crf = crf;
10507 
10509 
10510  ni_pthread_mutex_unlock(&p_ctx->mutex);
10511 
10512  return NI_RETCODE_SUCCESS;
10513 }
10514 
10515 /*!*****************************************************************************
10516  * \brief Reconfigure crf float point value dynamically during encoding.
10517  *
10518  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10519  * \param[in] crf crf float point value to reconfigure
10520  *
10521  * \return On success NI_RETCODE_SUCCESS
10522  * On failure NI_RETCODE_INVALID_PARAM
10523  ******************************************************************************/
10525  float crf)
10526 {
10527  ni_xcoder_params_t *api_param;
10528 
10529  if (!p_ctx || !p_ctx->p_session_config)
10530  {
10531  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10532  __func__);
10533  return NI_RETCODE_INVALID_PARAM;
10534  }
10535 
10536  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10537 
10538  if (api_param->cfg_enc_params.crfFloat < 0)
10539  {
10540  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %f is valid only in CRF mode\n",
10541  __func__, crf);
10542  return NI_RETCODE_INVALID_PARAM;
10543  }
10544 
10545  if (crf < 0.0 || crf > 51.0)
10546  {
10547  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %f is invalid (valid range in [0..51])\n",
10548  __func__, crf);
10549  return NI_RETCODE_INVALID_PARAM;
10550  }
10551 
10552  ni_pthread_mutex_lock(&p_ctx->mutex);
10553 
10555 
10556  if (p_ctx->reconfig_crf >= 0 || p_ctx->reconfig_crf_decimal > 0)
10557  {
10558  ni_log2(p_ctx, NI_LOG_DEBUG,
10559  "Warning: %s(): crf reconfig value %d overwriting current "
10560  "reconfig_crf %d, reconfig_crf_decimal %d\n", __func__,
10561  crf, p_ctx->reconfig_crf, p_ctx->reconfig_crf_decimal);
10562  }
10563 
10564  p_ctx->reconfig_crf = (int)crf;
10565  p_ctx->reconfig_crf_decimal = (int)((crf - (float)p_ctx->reconfig_crf) * 100);
10566 
10568 
10569  ni_pthread_mutex_unlock(&p_ctx->mutex);
10570 
10571  return NI_RETCODE_SUCCESS;
10572 }
10573 
10574 /*!*****************************************************************************
10575  * \brief Reconfigure vbv buffer size and vbv max rate dynamically during encoding.
10576  *
10577  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10578  * \param[in] vbvBufferSize Target vbvBufferSize to set
10579  * \param[in] vbvMaxRate Target vbvMaxRate to set
10580  *
10581  * \return On success NI_RETCODE_SUCCESS
10582  * On failure NI_RETCODE_INVALID_PARAM
10583  ******************************************************************************/
10585  int32_t vbvMaxRate, int32_t vbvBufferSize)
10586 {
10587  ni_xcoder_params_t *api_param;
10588  if (!p_ctx || !p_ctx->p_session_config)
10589  {
10590  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10591  __func__);
10592  return NI_RETCODE_INVALID_PARAM;
10593  }
10594  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
10595  {
10596  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): vbvBufferSize value %d\n",
10597  __func__, vbvBufferSize);
10598  return NI_RETCODE_INVALID_PARAM;
10599  }
10600  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10601  if (api_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < api_param->bitrate) {
10602  ni_log2(p_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
10603  vbvMaxRate, api_param->bitrate);
10604  return NI_RETCODE_INVALID_PARAM;
10605  }
10606  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
10607  ni_log2(p_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
10608  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
10609  vbvMaxRate);
10610  vbvMaxRate = 0;
10611  }
10612 
10613  ni_pthread_mutex_lock(&p_ctx->mutex);
10615 
10616  p_ctx->reconfig_vbv_buffer_size = vbvBufferSize;
10617  p_ctx->reconfig_vbv_max_rate = vbvMaxRate;
10618 
10620  ni_pthread_mutex_unlock(&p_ctx->mutex);
10621 
10622  return NI_RETCODE_SUCCESS;
10623 }
10624 
10625 /*!*****************************************************************************
10626  * \brief Reconfigure maxFrameSizeRatio dynamically during encoding.
10627  *
10628  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10629  * \param[in] max_frame_size_ratio maxFrameSizeRatio to set
10630  *
10631  * \return On success NI_RETCODE_SUCCESS
10632  * On failure NI_RETCODE_INVALID_PARAM
10633  ******************************************************************************/
10635 {
10636  ni_xcoder_params_t *api_param;
10637  int32_t bitrate, framerate_num, framerate_denom;
10638  uint32_t min_maxFrameSize, maxFrameSize;
10639 
10640  if (!p_ctx || !p_ctx->p_session_config)
10641  {
10642  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10643  __func__);
10644  return NI_RETCODE_INVALID_PARAM;
10645  }
10646 
10647  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10648 
10649  if (!api_param->low_delay_mode)
10650  {
10651  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio is valid only when lowDelay mode is enabled\n",
10652  __func__, max_frame_size_ratio);
10653  return NI_RETCODE_INVALID_PARAM;
10654  }
10655 
10656  if (max_frame_size_ratio < 1) {
10657  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio %d cannot < 1\n",
10658  max_frame_size_ratio);
10659  return NI_RETCODE_INVALID_PARAM;
10660  }
10661 
10662  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10663 
10664  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10665  {
10666  framerate_num = p_ctx->framerate.framerate_num;
10667  framerate_denom = p_ctx->framerate.framerate_denom;
10668  }
10669  else
10670  {
10671  framerate_num = (int32_t) api_param->fps_number;
10672  framerate_denom = (int32_t) api_param->fps_denominator;
10673  }
10674 
10675  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10676 
10677  maxFrameSize = min_maxFrameSize * max_frame_size_ratio > NI_MAX_FRAME_SIZE ?
10678  NI_MAX_FRAME_SIZE : min_maxFrameSize * max_frame_size_ratio;
10679 
10680  ni_pthread_mutex_lock(&p_ctx->mutex);
10682 
10683  if (p_ctx->max_frame_size > 0)
10684  {
10685  ni_log2(p_ctx, NI_LOG_DEBUG,
10686  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10687  __func__, maxFrameSize, p_ctx->max_frame_size);
10688  }
10689 
10690  p_ctx->max_frame_size = maxFrameSize;
10691 
10693  ni_pthread_mutex_unlock(&p_ctx->mutex);
10694 
10695  return NI_RETCODE_SUCCESS;
10696 }
10697 
10698 /*!*****************************************************************************
10699  * \brief Reconfigure sliceArg dynamically during encoding.
10700  *
10701  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10702  * \param[in] sliceArg the new sliceArg value
10703  *
10704  * \return On success NI_RETCODE_SUCCESS
10705  * On failure NI_RETCODE_INVALID_PARAM
10706  ******************************************************************************/
10708 {
10709  ni_xcoder_params_t *api_param;
10710  ni_encoder_cfg_params_t *p_enc;
10711 
10712  if (!p_ctx || !p_ctx->p_session_config)
10713  {
10714  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10715  __func__);
10716  return NI_RETCODE_INVALID_PARAM;
10717  }
10718 
10719  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10720  p_enc = &api_param->cfg_enc_params;
10721  if (p_enc->slice_mode == 0)
10722  {
10723  ni_log2(p_ctx, NI_LOG_ERROR, "%s():not support to reconfig slice_arg when slice_mode disable.\n",
10724  __func__);
10725  sliceArg = 0;
10726  }
10728  {
10729  ni_log2(p_ctx, NI_LOG_ERROR, "%s():sliceArg is only supported for H.264 or H.265.\n",
10730  __func__);
10731  sliceArg = 0;
10732  }
10733  int ctu_mb_size = (NI_CODEC_FORMAT_H264 == p_ctx->codec_format) ? 16 : 64;
10734  int max_num_ctu_mb_row = (api_param->source_height + ctu_mb_size - 1) / ctu_mb_size;
10735  if (sliceArg < 1 || sliceArg > max_num_ctu_mb_row)
10736  {
10737  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid data sliceArg %d\n", __func__,
10738  sliceArg);
10739  sliceArg = 0;
10740  }
10741 
10742  ni_pthread_mutex_lock(&p_ctx->mutex);
10744 
10745  p_ctx->reconfig_slice_arg = sliceArg;
10746 
10748  ni_pthread_mutex_unlock(&p_ctx->mutex);
10749 
10750  return NI_RETCODE_SUCCESS;
10751 }
10752 
10753 #ifndef _WIN32
10754 /*!*****************************************************************************
10755 * \brief Acquire a P2P frame buffer from the hwupload session
10756 *
10757 * \param[in] p_ctx Pointer to a caller allocated
10758 * ni_session_context_t struct
10759 * \param[out] p_frame Pointer to a caller allocated hw frame
10760 *
10761 * \return On success
10762 * NI_RETCODE_SUCCESS
10763 * On failure
10764 * NI_RETCODE_INVALID_PARAM
10765 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10766 * NI_RETCODE_ERROR_INVALID_SESSION
10767 *******************************************************************************/
10769 {
10771  struct netint_iocmd_export_dmabuf uexp;
10772  unsigned int offset;
10773  int ret, is_semi_planar;
10774  int linestride[NI_MAX_NUM_DATA_POINTERS];
10775  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10776  niFrameSurface1_t hwdesc = {0};
10777  niFrameSurface1_t *p_surface;
10778 
10779  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10780  {
10781  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10782  __func__);
10783  return NI_RETCODE_INVALID_PARAM;
10784  }
10785 
10786  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10787 
10788  ni_pthread_mutex_lock(&p_ctx->mutex);
10790 
10791  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10792 
10794  ni_pthread_mutex_unlock(&p_ctx->mutex);
10795 
10796  if (retval != NI_RETCODE_SUCCESS)
10797  {
10798  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10799  return retval;
10800  }
10801 
10802  retval = ni_get_memory_offset(p_ctx, &hwdesc, &offset);
10803  if (retval != NI_RETCODE_SUCCESS)
10804  {
10805  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: bad buffer id\n");
10806  return NI_RETCODE_INVALID_PARAM;
10807  }
10808 
10809  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
10810  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
10811  1 :
10812  0;
10813 
10815  p_ctx->bit_depth_factor, is_semi_planar, linestride,
10816  alignedheight);
10817 
10818  uexp.fd = -1;
10819  uexp.flags = 0;
10820  uexp.offset = offset;
10821 
10822  uexp.length = ni_calculate_total_frame_size(p_ctx, linestride);
10823  uexp.domain = p_ctx->domain;
10824  uexp.bus = p_ctx->bus;
10825  uexp.dev = p_ctx->dev;
10826  uexp.fn = p_ctx->fn;
10827  uexp.bar = 4; // PCI BAR4 configuration space
10828 
10829  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
10830  if (ret < 0)
10831  {
10832  ni_log2(p_ctx, NI_LOG_ERROR, "%s: Failed to export dmabuf %d errno %d\n",
10833  __func__, ret, NI_ERRNO);
10834  return NI_RETCODE_FAILURE;
10835  }
10836 
10837  *p_surface = hwdesc;
10838  p_surface->ui16width = p_ctx->active_video_width;
10839  p_surface->ui16height = p_ctx->active_video_height;
10840  p_surface->ui32nodeAddress = offset;
10841  p_surface->encoding_type = is_semi_planar ?
10844  p_surface->dma_buf_fd = uexp.fd;
10845 
10846  return retval;
10847 }
10848 
10849 /*!*****************************************************************************
10850 * \brief Acquire a P2P frame buffer from the hwupload session for P2P read
10851 *
10852 * \param[in] p_ctx Pointer to a caller allocated
10853 * ni_session_context_t struct
10854 * \param[out] p_frame Pointer to a caller allocated hw frame
10855 *
10856 * \return On success
10857 * NI_RETCODE_SUCCESS
10858 * On failure
10859 * NI_RETCODE_INVALID_PARAM
10860 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10861 * NI_RETCODE_ERROR_INVALID_SESSION
10862 *******************************************************************************/
10864 {
10866 
10867  int is_semi_planar;
10868  int linestride[NI_MAX_NUM_DATA_POINTERS];
10869  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10870  niFrameSurface1_t hwdesc = {0};
10871  niFrameSurface1_t *p_surface;
10872 
10873  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10874  {
10875  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10876  __func__);
10877  return NI_RETCODE_INVALID_PARAM;
10878  }
10879 
10880  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10881 
10882  ni_pthread_mutex_lock(&p_ctx->mutex);
10884 
10885  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10886 
10888  ni_pthread_mutex_unlock(&p_ctx->mutex);
10889 
10890  if (retval != NI_RETCODE_SUCCESS)
10891  {
10892  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10893  return retval;
10894  }
10895 
10896  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
10897  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
10898  1 :
10899  0;
10900 
10902  p_ctx->bit_depth_factor, is_semi_planar, linestride,
10903  alignedheight);
10904 
10905  *p_surface = hwdesc;
10906  p_surface->ui16width = p_ctx->active_video_width;
10907  p_surface->ui16height = p_ctx->active_video_height;
10908  p_surface->ui32nodeAddress = 0;
10909  p_surface->encoding_type = is_semi_planar ?
10912  p_surface->dma_buf_fd = 0;
10913 
10914  return retval;
10915 }
10916 
10917 
10918 /*!*****************************************************************************
10919  * \brief Lock a hardware P2P frame prior to encoding
10920  *
10921  * \param[in] p_upl_ctx pointer to caller allocated upload context
10922  * [in] p_frame pointer to caller allocated hardware P2P frame
10923  *
10924  * \return On success
10925  * NI_RETCODE_SUCCESS
10926  * On failure NI_RETCODE_FAILURE
10927  * NI_RETCODE_INVALID_PARAM
10928 *******************************************************************************/
10930  ni_frame_t *p_frame)
10931 {
10932  int ret;
10933  struct netint_iocmd_attach_rfence uatch = {0};
10934  struct pollfd pfds[1] = {0};
10935  niFrameSurface1_t *p_surface;
10936 
10937  if (p_upl_ctx == NULL || p_frame == NULL)
10938  {
10939  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: bad parameters\n", __func__);
10940  return NI_RETCODE_INVALID_PARAM;
10941  }
10942 
10943  if (p_frame->p_data[3] == NULL)
10944  {
10945  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: not a hardware frame\n", __func__);
10946  return NI_RETCODE_INVALID_PARAM;
10947  }
10948 
10949  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10950 
10951  pfds[0].fd = p_surface->dma_buf_fd;
10952  pfds[0].events = POLLIN;
10953  pfds[0].revents = 0;
10954 
10955  ret = poll(pfds, 1, -1);
10956  char errmsg[NI_ERRNO_LEN] = {0};
10957  if (ret < 0)
10958  {
10959  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
10960  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s:failed to poll dmabuf fd errno %s\n", __func__,
10961  errmsg);
10962  return ret;
10963  }
10964 
10965  uatch.fd = p_surface->dma_buf_fd;
10966  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ATTACH_RFENCE, &uatch);
10967  if (ret < 0)
10968  {
10969  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
10970  ni_log2(p_upl_ctx, NI_LOG_ERROR,
10971  "%s: failed to attach dmabuf read fence errno %s\n", __func__,
10972  errmsg);
10973  return ret;
10974  }
10975 
10976  return NI_RETCODE_SUCCESS;
10977 }
10978 
10979 /*!*****************************************************************************
10980  * \brief Unlock a hardware P2P frame after encoding
10981  *
10982  * \param[in] p_upl_ctx pointer to caller allocated upload context
10983  * [in] p_frame pointer to caller allocated hardware P2P frame
10984  *
10985  * \return On success
10986  * NI_RETCODE_SUCCESS
10987  * On failure NI_RETCODE_FAILURE
10988  * NI_RETCODE_INVALID_PARAM
10989 *******************************************************************************/
10991  ni_frame_t *p_frame)
10992 {
10993  int ret;
10994  struct netint_iocmd_signal_rfence usigl = {0};
10995  niFrameSurface1_t *p_surface;
10996 
10997  if ((p_upl_ctx == NULL) || (p_frame == NULL))
10998  {
10999  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid parameters %p %p\n", __func__,
11000  p_upl_ctx, p_frame);
11001  return NI_RETCODE_INVALID_PARAM;
11002  }
11003 
11004  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11005 
11006  if (p_surface == NULL)
11007  {
11008  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
11009  return NI_RETCODE_INVALID_PARAM;
11010  }
11011 
11012  usigl.fd = p_surface->dma_buf_fd;
11013  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_SIGNAL_RFENCE, &usigl);
11014  if (ret < 0)
11015  {
11016  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Failed to signal dmabuf read fence\n");
11017  return NI_RETCODE_FAILURE;
11018  }
11019 
11020  return NI_RETCODE_SUCCESS;
11021 }
11022 
11023 /*!*****************************************************************************
11024  * \brief Special P2P test API function. Copies YUV data from the software
11025  * frame to the hardware P2P frame on the Quadra device
11026  *
11027  * \param[in] p_upl_ctx pointer to caller allocated uploader session
11028  * context
11029  * [in] p_swframe pointer to a caller allocated software frame
11030  * [in] p_hwframe pointer to a caller allocated hardware frame
11031  *
11032  * \return On success
11033  * NI_RETCODE_SUCCESS
11034  * On failure
11035  * NI_RETCODE_FAILURE
11036  * NI_RETCODE_INVALID_PARAM
11037 *******************************************************************************/
11039  uint8_t *p_data, uint32_t len,
11040  ni_frame_t *p_hwframe)
11041 {
11042  int ret;
11043  struct netint_iocmd_issue_request uis = {0};
11044  niFrameSurface1_t *p_surface;
11045 
11046  if (p_upl_ctx == NULL || p_data == NULL || p_hwframe == NULL)
11047  {
11048  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: invalid null parameters\n", __func__);
11049  return NI_RETCODE_INVALID_PARAM;
11050  }
11051 
11052  if (p_hwframe->p_data[3] == NULL)
11053  {
11054  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: empty frame\n", __func__);
11055  return NI_RETCODE_INVALID_PARAM;
11056  }
11057 
11058  p_surface = (niFrameSurface1_t *)p_hwframe->p_data[3];
11059 
11060  uis.fd = p_surface->dma_buf_fd;
11061  uis.data = p_data;
11062  uis.len = len;
11064 
11065  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ISSUE_REQ, &uis);
11066  if (ret < 0)
11067  {
11068  ni_log2(p_upl_ctx, NI_LOG_ERROR,
11069  "%s: Failed to request dmabuf rendering errno %d\n", __func__,
11070  NI_ERRNO);
11071  return NI_RETCODE_FAILURE;
11072  }
11073 
11074  return NI_RETCODE_SUCCESS;
11075 }
11076 
11077 /*!*****************************************************************************
11078  * \brief Special P2P test API function. Copies video data from the software
11079  * frame to the hardware P2P frame on the Quadra device. Does not
11080  * need the Netint kernel driver but requires root privilege.
11081  *
11082  * \param[in] p_upl_ctx pointer to caller allocated uploader session
11083  * context
11084  * [in] p_swframe pointer to a caller allocated software frame
11085  * [in] p_hwframe pointer to a caller allocated hardware frame
11086  *
11087  * \return On success
11088  * NI_RETCODE_SUCCESS
11089  * On failure
11090  * NI_RETCODE_FAILURE
11091  * NI_RETCODE_INVALID_PARAM
11092 *******************************************************************************/
11094  uint8_t *p_data, uint32_t len,
11095  ni_frame_t *p_hwframe)
11096 {
11097  int bar4_fd, ret;
11098  char bar4_name[128];
11099  char *bar4_mm;
11100  struct stat stat;
11101  niFrameSurface1_t *pSurf;
11102  uint32_t offset;
11103 
11104  pSurf = (niFrameSurface1_t *) p_hwframe->p_data[3];
11105 
11106  ret = ni_get_memory_offset(p_upl_ctx, pSurf, &offset);
11107  if (ret != 0)
11108  {
11109  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Error bad buffer id\n");
11110  return NI_RETCODE_FAILURE;
11111  }
11112 
11113  snprintf(bar4_name, 128,
11114  "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/resource4",
11115  p_upl_ctx->domain,p_upl_ctx->bus,p_upl_ctx->dev,p_upl_ctx->fn);
11116 
11117  bar4_fd = open(bar4_name, O_RDWR | O_SYNC);
11118 
11119  char errmsg[NI_ERRNO_LEN] = {0};
11120  if (bar4_fd < 0)
11121  {
11122  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11123  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't open bar4 %s (%s)\n",
11124  bar4_name, errmsg);
11125  return NI_RETCODE_FAILURE;
11126  }
11127 
11128  if (fstat(bar4_fd, &stat) != 0)
11129  {
11130  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11131  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't stat bar4 (%s)\n",
11132  errmsg);
11133  close(bar4_fd);
11134  return NI_RETCODE_FAILURE;
11135  }
11136 
11137  bar4_mm = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, bar4_fd, 0);
11138 
11139  if (bar4_mm == MAP_FAILED)
11140  {
11141  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11142  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't mmap to bar4 (%s)\n",
11143  errmsg);
11144  close(bar4_fd);
11145  return NI_RETCODE_FAILURE;
11146  }
11147 
11148  /* Copy the data directly into Quadra video memory */
11149  memcpy(bar4_mm + offset, p_data, len);
11150 
11151  munmap(bar4_mm, 0);
11152  close(bar4_fd);
11153 
11154  return NI_RETCODE_SUCCESS;
11155 }
11156 
11157 
11158 /*!*****************************************************************************
11159  * \brief Recycle hw P2P frames
11160  *
11161  * \param [in] p_frame pointer to an acquired P2P hw frame
11162  *
11163  * \return on success
11164  * NI_RETCODE_SUCCESS
11165  *
11166  * on failure
11167  * NI_RETCODE_INVALID_PARAM
11168 *******************************************************************************/
11170 {
11171  niFrameSurface1_t *p_surface;
11172 
11173  if (p_frame == NULL)
11174  {
11175  ni_log(NI_LOG_ERROR, "%s: Invalid frame\n", __func__);
11176  return NI_RETCODE_INVALID_PARAM;
11177  }
11178 
11179  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11180  if (p_surface == NULL)
11181  {
11182  ni_log(NI_LOG_ERROR, "%s: Invalid surface data\n", __func__);
11183  return NI_RETCODE_INVALID_PARAM;
11184  }
11185 
11186  return ni_hwframe_buffer_recycle2(p_surface);
11187 }
11188 
11189 /*!*****************************************************************************
11190  * \brief Acquire the scaler P2P DMA buffer for read/write
11191  *
11192  * \param [in] p_ctx pointer to caller allocated upload context
11193  * [in] p_surface pointer to a caller allocated hardware frame
11194  * [in] data_len scaler frame buffer data length
11195  *
11196  * \return on success
11197  * NI_RETCODE_SUCCESS
11198  *
11199  * on failure
11200  * NI_RETCODE_FAILURE
11201 *******************************************************************************/
11203  niFrameSurface1_t *p_surface,
11204  int data_len)
11205 {
11206  unsigned int offset;
11207  int ret;
11208 
11209  ret = ni_get_memory_offset(p_ctx, p_surface, &offset);
11210  if (ret != 0)
11211  {
11212  ni_log2(p_ctx, NI_LOG_ERROR, "Error: bad buffer id\n");
11213  return NI_RETCODE_FAILURE;
11214  }
11215  p_surface->ui32nodeAddress = 0;
11216 
11217  struct netint_iocmd_export_dmabuf uexp;
11218  uexp.fd = -1;
11219  uexp.flags = 0;
11220  uexp.offset = offset;
11221  uexp.length = data_len;
11222  uexp.domain = p_ctx->domain;
11223  uexp.bus = p_ctx->bus;
11224  uexp.dev = p_ctx->dev;
11225  uexp.fn = p_ctx->fn;
11226  uexp.bar = 4;
11227  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
11228  if (ret < 0)
11229  {
11230  char errmsg[NI_ERRNO_LEN] = {0};
11231  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11232  ni_log2(p_ctx, NI_LOG_ERROR, "failed to export dmabuf: %s\n", errmsg);
11233  return NI_RETCODE_FAILURE;
11234  }
11235  p_surface->dma_buf_fd = uexp.fd;
11236  return ret;
11237 }
11238 #endif
11239 
11240 /*!*****************************************************************************
11241  * \brief Set the incoming frame format for the encoder
11242  *
11243  * \param[in] p_enc_ctx pointer to encoder context
11244  * [in] p_enc_params pointer to encoder parameters
11245  * [in] width input width
11246  * [in] height input height
11247  * [in] bit_depth 8 for 8-bit YUV, 10 for 10-bit YUV
11248  * [in] src_endian NI_FRAME_LITTLE_ENDIAN or NI_FRAME_BIG_ENDIAN
11249  * [in] planar 0 for semi-planar YUV, 1 for planar YUV
11250  *
11251  * \return on success
11252  * NI_RETCODE_SUCCESS
11253  *
11254  * on failure
11255  * NI_RETCODE_INVALID_PARAM
11256  *
11257 *******************************************************************************/
11259  ni_xcoder_params_t *p_enc_params,
11260  int width, int height,
11261  int bit_depth, int src_endian,
11262  int planar)
11263 {
11264  int alignedw;
11265  int alignedh;
11266 
11267  if (p_enc_ctx == NULL || p_enc_params == NULL)
11268  {
11269  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11270  return NI_RETCODE_INVALID_PARAM;
11271  }
11272 
11273  if (!(bit_depth == 8) && !(bit_depth == 10))
11274  {
11275  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad bit depth %d\n", __func__, bit_depth);
11276  return NI_RETCODE_INVALID_PARAM;
11277  }
11278 
11279  if (!(src_endian == NI_FRAME_LITTLE_ENDIAN) &&
11280  !(src_endian == NI_FRAME_BIG_ENDIAN))
11281  {
11282  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad endian %d\n", __func__, src_endian);
11283  return NI_RETCODE_INVALID_PARAM;
11284  }
11285 
11286  if ((planar < 0) || (planar >= NI_PIXEL_PLANAR_MAX))
11287  {
11288  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad planar value %d\n", __func__, planar);
11289  return NI_RETCODE_INVALID_PARAM;
11290  }
11291 
11292  p_enc_ctx->src_bit_depth = bit_depth;
11293  p_enc_ctx->bit_depth_factor = (bit_depth == 8) ? 1 : 2;
11294  p_enc_ctx->src_endian = src_endian;
11295 
11296  alignedw = width;
11297 
11298  if (alignedw < NI_MIN_WIDTH)
11299  {
11300  p_enc_params->cfg_enc_params.conf_win_right +=
11301  (NI_MIN_WIDTH - width) / 2 * 2;
11302  alignedw = NI_MIN_WIDTH;
11303  } else
11304  {
11305  alignedw = ((width + 1) / 2) * 2;
11306  p_enc_params->cfg_enc_params.conf_win_right +=
11307  (alignedw - width) / 2 * 2;
11308  }
11309 
11310  p_enc_params->source_width = alignedw;
11311  alignedh = height;
11312 
11313  if (alignedh < NI_MIN_HEIGHT)
11314  {
11315  p_enc_params->cfg_enc_params.conf_win_bottom +=
11316  (NI_MIN_HEIGHT - height) / 2 * 2;
11317  alignedh = NI_MIN_HEIGHT;
11318  } else
11319  {
11320  alignedh = ((height + 1) / 2) * 2;
11321  p_enc_params->cfg_enc_params.conf_win_bottom +=
11322  (alignedh - height) / 2 * 2;
11323  }
11324 
11325  p_enc_params->source_height = alignedh;
11326  p_enc_params->cfg_enc_params.planar = planar;
11327 
11328  return NI_RETCODE_SUCCESS;
11329 }
11330 
11331 /*!*****************************************************************************
11332  * \brief Set the outgoing frame format for the uploader
11333  *
11334  * \param[in] p_upl_ctx pointer to uploader context
11335  * [in] width width
11336  * [in] height height
11337  * [in] pixel_format pixel format
11338  * [in] isP2P 0 = normal, 1 = P2P
11339  *
11340  * \return on success
11341  * NI_RETCODE_SUCCESS
11342  *
11343  * on failure
11344  * NI_RETCODE_INVALID_PARAM
11345 *******************************************************************************/
11347  int width, int height,
11348  ni_pix_fmt_t pixel_format, int isP2P)
11349 {
11350  if (p_upl_ctx == NULL)
11351  {
11352  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11353  return NI_RETCODE_INVALID_PARAM;
11354  }
11355 
11356  switch (pixel_format)
11357  {
11358  case NI_PIX_FMT_YUV420P:
11359  case NI_PIX_FMT_NV12:
11360  p_upl_ctx->src_bit_depth = 8;
11361  p_upl_ctx->bit_depth_factor = 1;
11362  break;
11364  case NI_PIX_FMT_P010LE:
11365  p_upl_ctx->src_bit_depth = 10;
11366  p_upl_ctx->bit_depth_factor = 2;
11367  break;
11368  case NI_PIX_FMT_RGBA:
11369  case NI_PIX_FMT_BGRA:
11370  case NI_PIX_FMT_ARGB:
11371  case NI_PIX_FMT_ABGR:
11372  case NI_PIX_FMT_BGR0:
11373  case NI_PIX_FMT_BGRP:
11374  p_upl_ctx->src_bit_depth = 8;
11375  p_upl_ctx->bit_depth_factor = 4;
11376  break;
11377  default:
11378  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid pixfmt %d\n", __func__,
11379  pixel_format);
11380  return NI_RETCODE_INVALID_PARAM;
11381  }
11382 
11383  p_upl_ctx->src_endian = NI_FRAME_LITTLE_ENDIAN;
11384  p_upl_ctx->pixel_format = pixel_format;
11385  p_upl_ctx->active_video_width = width;
11386  p_upl_ctx->active_video_height = height;
11387  p_upl_ctx->isP2P = isP2P;
11388 
11389  return NI_RETCODE_SUCCESS;
11390 }
11391 
11392 /*!*****************************************************************************
11393  * \brief Read encoder stream header from the device
11394  *
11395  * \param[in] p_ctx Pointer to a caller allocated
11396  * ni_session_context_t struct from encoder
11397  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
11398  * struct which contains a ni_packet_t data packet to
11399  * receive
11400  * \return On success
11401  * Total number of bytes read
11402  * On failure
11403  * NI_RETCODE_INVALID_PARAM
11404  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11405  * NI_RETCODE_ERROR_INVALID_SESSION
11406 *******************************************************************************/
11408  ni_session_data_io_t *p_data)
11409 {
11410  int rx_size;
11411  int done = 0;
11412  int bytes_read = 0;
11413 
11414  /* This function should be called once at the start of encoder read */
11415  if (p_ctx->pkt_num != 0)
11416  {
11417  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11419  }
11420 
11421  while (!done)
11422  {
11423  rx_size = ni_device_session_read(p_ctx, p_data, NI_DEVICE_TYPE_ENCODER);
11424 
11425  if (rx_size > (int)p_ctx->meta_size)
11426  {
11427  /* stream header has been read, return size */
11428  bytes_read += (rx_size - (int)p_ctx->meta_size);
11429 
11430  p_ctx->pkt_num = 1;
11431  ni_log2(p_ctx, NI_LOG_DEBUG, "Got encoded stream header\n");
11432  done = 1;
11433  } else if (rx_size != 0)
11434  {
11435  ni_log2(p_ctx, NI_LOG_ERROR, "Error: received rx_size = %d\n", rx_size);
11436  bytes_read = -1;
11437  done = 1;
11438  } else
11439  {
11440  ni_log2(p_ctx, NI_LOG_DEBUG, "No data, keep reading..\n");
11441  continue;
11442  }
11443  }
11444 
11445  return bytes_read;
11446 }
11447 
11448 /*!*****************************************************************************
11449  * \brief Get the DMA buffer file descriptor from the P2P frame
11450  *
11451  * \param[in] p_frame pointer to a P2P frame
11452  *
11453  * \return On success
11454  * DMA buffer file descriptor
11455  * On failure
11456  * NI_RETCODE_INVALID_PARAM
11457 *******************************************************************************/
11459 {
11460  const niFrameSurface1_t *p_surface;
11461 
11462  if (p_frame == NULL)
11463  {
11464  ni_log(NI_LOG_ERROR, "%s: NULL frame\n", __func__);
11465  return NI_RETCODE_INVALID_PARAM;
11466  }
11467 
11468  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11469 
11470  if (p_surface == NULL)
11471  {
11472  ni_log(NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
11473  return NI_RETCODE_INVALID_PARAM;
11474  }
11475 
11476  return p_surface->dma_buf_fd;
11477 }
11478 
11479 /*!*****************************************************************************
11480  * \brief Send sequence change information to device
11481  *
11482  * \param[in] p_ctx Pointer to a caller allocated
11483  * ni_session_context_t struct
11484  * \param[in] width input width
11485  * \param[in] height input height
11486  * \param[in] bit_depth_factor 1 for 8-bit YUV, 2 for 10-bit YUV
11487  * \param[in] device_type device type (must be encoder)
11488  * \return On success
11489  * NI_RETCODE_SUCCESS
11490  * On failure
11491  * NI_RETCODE_INVALID_PARAM
11492  * NI_RETCODE_ERROR_MEM_ALOC
11493  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11494  * NI_RETCODE_ERROR_INVALID_SESSION
11495  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
11496  ******************************************************************************/
11498  int width, int height, int bit_depth_factor, ni_device_type_t device_type)
11499 {
11500  ni_resolution_t resolution;
11502  ni_xcoder_params_t *p_param = NULL;
11503 
11504  // requires API version >= 54
11506  "54") < 0)
11507  {
11508  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
11510  }
11511 
11512  /* This function should be called only if sequence change is detected */
11514  {
11515  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11517  }
11518 
11519  resolution.width = width;
11520  resolution.height = height;
11521  resolution.bit_depth_factor = bit_depth_factor;
11522  resolution.luma_linesize = 0;
11523  resolution.chroma_linesize = 0;
11524  if (p_ctx->p_session_config)
11525  {
11526  ni_encoder_cfg_params_t *p_enc;
11527  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
11528  p_enc = &p_param->cfg_enc_params;
11529  if (p_enc->spatial_layers > 1)
11530  {
11531  retval = NI_RETCODE_INVALID_PARAM;
11532  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported when spatialLayers > 1\n");
11533  return retval;
11534  }
11535  resolution.luma_linesize = p_param->luma_linesize;
11536  resolution.chroma_linesize = p_param->chroma_linesize;
11537  }
11538  else
11539  {
11541  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: invalid p_session_config\n");
11542  return retval;
11543  }
11544 
11545  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: resolution change config - width %d height %d bit_depth_factor %d "
11546  "luma_linesize %d chroma_linesize %d\n", __func__,
11547  resolution.width, resolution.height, resolution.bit_depth_factor,
11548  resolution.luma_linesize, resolution.chroma_linesize);
11549 
11550  switch (device_type)
11551  {
11553  {
11554  // config sequence change
11555  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
11556  break;
11557  }
11558  default:
11559  {
11560  retval = NI_RETCODE_INVALID_PARAM;
11561  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported for device type: %d", device_type);
11562  return retval;
11563  }
11564  }
11565  return retval;
11566 }
11567 
11569  ni_network_perf_metrics_t *p_metrics)
11570 {
11571  return ni_ai_session_query_metrics(p_ctx, p_metrics);
11572 }
11573 
11574 ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle,
11575  ni_device_info_t *p_dev_info)
11576 {
11577  void *buffer;
11578  uint32_t size;
11579  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11580  ni_log_fl_fw_versions_t fl_fw_versions;
11581 
11582  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_info))
11583  {
11584  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11585  __func__);
11586  return NI_RETCODE_INVALID_PARAM;
11587  }
11588 
11590  "6h") < 0)
11591  {
11593  "ERROR: %s function not supported on device with FW API version < 6.h\n",
11594  __func__);
11596  }
11597 
11598  buffer = NULL;
11600 
11601  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11602  {
11603  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11605  }
11606 
11607  memset(buffer, 0, size);
11608 
11609  if (ni_nvme_send_read_cmd(device_handle,
11610  event_handle,
11611  buffer,
11612  size,
11613  QUERY_GET_VERSIONS_R) < 0)
11614  {
11615  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11616  ni_aligned_free(buffer);
11618  }
11619 
11620  memcpy(&fl_fw_versions, buffer, sizeof(ni_log_fl_fw_versions_t));
11621 
11622  memcpy(p_dev_info->fl_ver_last_ran,
11623  &fl_fw_versions.last_ran_fl_version,
11625  memcpy(p_dev_info->fl_ver_nor_flash,
11626  &fl_fw_versions.nor_flash_fl_version,
11628  memcpy(p_dev_info->fw_rev_nor_flash,
11629  &fl_fw_versions.nor_flash_fw_revision,
11631 
11632  ni_aligned_free(buffer);
11633  return NI_RETCODE_SUCCESS;
11634 }
11635 
11637  ni_load_query_t *p_load_query)
11638 {
11639  void *buffer;
11640  uint32_t size;
11641 
11642  ni_instance_mgr_general_status_t general_status;
11643 
11644  if (!p_ctx)
11645  {
11646  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_ctx cannot be null\n");
11647  return NI_RETCODE_INVALID_PARAM;
11648  }
11649  if (!p_load_query)
11650  {
11651  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_load_query cannot be null\n");
11652  return NI_RETCODE_INVALID_PARAM;
11653  }
11654 
11656  "6O") < 0)
11657  {
11658  ni_log2(p_ctx, NI_LOG_ERROR,
11659  "ERROR: %s function not supported on device with FW API version < 6.O\n",
11660  __func__);
11662  }
11663 
11664  buffer = NULL;
11666 
11667  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11668  {
11669  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11671  }
11672 
11673  memset(buffer, 0, size);
11674 
11676  p_ctx->event_handle,
11677  buffer,
11678  size,
11680  {
11681  ni_log2(p_ctx, NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11682  ni_aligned_free(buffer);
11684  }
11685 
11686  memcpy(&general_status, buffer, sizeof(ni_instance_mgr_general_status_t));
11687 
11688  p_load_query->tp_fw_load = general_status.tp_fw_load;
11689  p_load_query->pcie_load = general_status.pcie_load;
11690  p_load_query->pcie_throughput = general_status.pcie_throughput;
11691  p_load_query->fw_load = general_status.fw_load;
11692  p_load_query->fw_share_mem_usage = general_status.fw_share_mem_usage;
11693 
11694  ni_aligned_free(buffer);
11695  return NI_RETCODE_SUCCESS;
11696 }
11697 
11698 ni_retcode_t ni_query_vf_ns_id(ni_device_handle_t device_handle,
11699  ni_device_vf_ns_id_t *p_dev_ns_vf,
11700  uint8_t fw_rev[])
11701 {
11702  void *p_buffer = NULL;
11703  uint32_t size;
11704  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11705 
11706  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_ns_vf))
11707  {
11708  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11709  __func__);
11710  return NI_RETCODE_INVALID_PARAM;
11711  }
11712 
11714  "6m") < 0)
11715  {
11717  "ERROR: %s function not supported on device with FW API version < 6.m\n",
11718  __func__);
11720  }
11721 
11723 
11724  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11725  {
11726  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11728  }
11729 
11730  memset(p_buffer, 0, size);
11731 
11732  if (ni_nvme_send_read_cmd(device_handle,
11733  event_handle,
11734  p_buffer,
11735  size,
11736  QUERY_GET_NS_VF_R) < 0)
11737  {
11738  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11739  ni_aligned_free(p_buffer);
11741  }
11742 
11743  ni_device_vf_ns_id_t *p_dev_ns_vf_data = (ni_device_vf_ns_id_t *)p_buffer;
11744  p_dev_ns_vf->vf_id = p_dev_ns_vf_data->vf_id;
11745  p_dev_ns_vf->ns_id = p_dev_ns_vf_data->ns_id;
11746  ni_log(NI_LOG_DEBUG, "%s(): NS/VF %u/%u\n", __func__, p_dev_ns_vf->ns_id, p_dev_ns_vf->vf_id);
11747  ni_aligned_free(p_buffer);
11748  return NI_RETCODE_SUCCESS;
11749 }
11750 
11751 ni_retcode_t ni_query_temperature(ni_device_handle_t device_handle,
11752  ni_device_temp_t *p_dev_temp,
11753  uint8_t fw_rev[])
11754 {
11755  void *p_buffer = NULL;
11756  uint32_t size;
11757  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11758 
11759  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_temp))
11760  {
11761  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11762  __func__);
11763  return NI_RETCODE_INVALID_PARAM;
11764  }
11765 
11767  "6rC") < 0)
11768  {
11770  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11771  __func__);
11773  }
11774 
11776 
11777  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11778  {
11779  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11781  }
11782 
11783  memset(p_buffer, 0, size);
11784 
11785  if (ni_nvme_send_read_cmd(device_handle,
11786  event_handle,
11787  p_buffer,
11788  size,
11790  {
11791  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11792  ni_aligned_free(p_buffer);
11794  }
11795 
11796  ni_device_temp_t *p_dev_temp_data = (ni_device_temp_t *)p_buffer;
11797  p_dev_temp->composite_temp = p_dev_temp_data->composite_temp;
11798  p_dev_temp->on_board_temp = p_dev_temp_data->on_board_temp;
11799  p_dev_temp->on_die_temp = p_dev_temp_data->on_die_temp;
11800  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d on die temperature %d\n",
11801  __func__, p_dev_temp->composite_temp, p_dev_temp->on_board_temp, p_dev_temp->on_die_temp);
11802  ni_aligned_free(p_buffer);
11803  return NI_RETCODE_SUCCESS;
11804 }
11805 
11806 ni_retcode_t ni_query_extra_info(ni_device_handle_t device_handle,
11807  ni_device_extra_info_t *p_dev_extra_info,
11808  uint8_t fw_rev[])
11809 {
11810  void *p_buffer = NULL;
11811  uint32_t size;
11812  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11813 
11814  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_extra_info))
11815  {
11816  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11817  __func__);
11818  return NI_RETCODE_INVALID_PARAM;
11819  }
11820 
11822  "6rC") < 0)
11823  {
11825  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11826  __func__);
11828  }
11829 
11831 
11832  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11833  {
11834  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11836  }
11837 
11838  memset(p_buffer, 0, size);
11839 
11840  if (ni_nvme_send_read_cmd(device_handle,
11841  event_handle,
11842  p_buffer,
11843  size,
11845  {
11846  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11847  ni_aligned_free(p_buffer);
11849  }
11850 
11851  ni_device_extra_info_t *p_dev_extra_info_data = (ni_device_extra_info_t *)p_buffer;
11852  p_dev_extra_info->composite_temp = p_dev_extra_info_data->composite_temp;
11853  p_dev_extra_info->on_board_temp = p_dev_extra_info_data->on_board_temp;
11854  p_dev_extra_info->on_die_temp = p_dev_extra_info_data->on_die_temp;
11855  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rC") >= 0 &&
11856  ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rR") < 0)
11857  {
11858  p_dev_extra_info->power_consumption = NI_INVALID_POWER;
11859  }
11860  else
11861  {
11862  p_dev_extra_info->power_consumption = p_dev_extra_info_data->power_consumption;
11863  }
11864  //QUADPV-1210-Remove ADC current measurement decoding from FW
11865  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6s4") >=0)
11866  {
11867  p_dev_extra_info->current_consumption = p_dev_extra_info_data->current_consumption;
11868  ni_device_capability_t device_capability = {0};
11869  if (ni_device_capability_query2(device_handle, &device_capability, false) != NI_RETCODE_SUCCESS)
11870  {
11871  ni_log(NI_LOG_ERROR, "ERROR: unable to query capability\n");
11873  }
11874  p_dev_extra_info->power_consumption = ni_decode_power_measurement(p_dev_extra_info->current_consumption, device_capability.serial_number);
11875  }
11876  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d "
11877  "on die temperature %d power consumption %d current consumption %d\n",
11878  __func__, p_dev_extra_info->composite_temp, p_dev_extra_info->on_board_temp,
11879  p_dev_extra_info->on_die_temp, p_dev_extra_info->power_consumption, p_dev_extra_info->current_consumption);
11880  ni_aligned_free(p_buffer);
11881  return NI_RETCODE_SUCCESS;
11882 }
11883 
11884 /*!*****************************************************************************
11885  * \brief Allocate log buffer if needed and retrieve firmware logs from device
11886  *
11887  * \param[in] p_ctx Pointer to a caller allocated
11888  * ni_session_context_t struct
11889  * \param[in] p_log_buffer Reference to pointer to a log buffer
11890  * If log buffer pointer is NULL, this function will allocate log buffer
11891  * NOTE caller is responsible for freeing log buffer after calling this function
11892  * \param[in] gen_log_file Indicating whether it is required to generate log files
11893  *
11894  *
11895  * \return on success
11896  * NI_RETCODE_SUCCESS
11897  *
11898  * on failure
11899  * NI_RETCODE_ERROR_MEM_ALOC
11900  * NI_RETCODE_INVALID_PARAM
11901 *******************************************************************************/
11902 ni_retcode_t ni_device_alloc_and_get_firmware_logs(ni_session_context_t *p_ctx, void** p_log_buffer, bool gen_log_file)
11903 {
11905  bool is_ext_buf = true;
11906  if (*p_log_buffer == NULL)
11907  {
11908  if (ni_posix_memalign(p_log_buffer, sysconf(_SC_PAGESIZE), TOTAL_CPU_LOG_BUFFER_SIZE))
11909  {
11910  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate log buffer\n",
11911  NI_ERRNO, __func__);
11913  }
11914  is_ext_buf = false;
11915  }
11916 
11917  if(*p_log_buffer != NULL){
11918  memset(*p_log_buffer, 0, TOTAL_CPU_LOG_BUFFER_SIZE);
11919  retval = ni_dump_log_all_cores(p_ctx, *p_log_buffer, gen_log_file); // dump FW logs
11920  if(!is_ext_buf)
11921  ni_aligned_free(*p_log_buffer);
11922  }else{
11924  }
11925 
11926  return retval;
11927 }
11928 
11929 /*!*****************************************************************************
11930  * \brief Set up hard coded demo ROI map
11931  *
11932  * \param[in] p_enc_ctx Pointer to a caller allocated
11933  *
11934  * \return on success
11935  * NI_RETCODE_SUCCESS
11936  *
11937  * on failure
11938  * NI_RETCODE_ERROR_MEM_ALOC
11939 *******************************************************************************/
11941 {
11942  ni_xcoder_params_t *p_param =
11943  (ni_xcoder_params_t *)(p_enc_ctx->p_session_config);
11944  int sumQp = 0;
11945  uint32_t ctu, i, j;
11946  // mode 1: Set QP for center 1/3 of picture to highest - lowest quality
11947  // the rest to lowest - highest quality;
11948  // mode non-1: reverse of mode 1
11949  int importanceLevelCentre = p_param->roi_demo_mode == 1 ? 40 : 10;
11950  int importanceLevelRest = p_param->roi_demo_mode == 1 ? 10 : 40;
11951  int linesize_aligned = p_param->source_width;
11952  int height_aligned = p_param->source_height;
11953  if (QUADRA)
11954  {
11955  uint32_t block_size, max_cu_size, customMapSize;
11956  uint32_t mbWidth;
11957  uint32_t mbHeight;
11958  uint32_t numMbs;
11959  uint32_t roiMapBlockUnitSize;
11960  uint32_t entryPerMb;
11961 
11962  max_cu_size = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16: 64;
11963  // AV1 non-8x8-aligned resolution is implicitly cropped due to Quadra HW limitation
11964  if (NI_CODEC_FORMAT_AV1 == p_enc_ctx->codec_format)
11965  {
11966  linesize_aligned = (linesize_aligned / 8) * 8;
11967  height_aligned = (height_aligned / 8) * 8;
11968  }
11969 
11970  // (ROI map version >= 1) each QP info takes 8-bit, represent 8 x 8
11971  // pixel block
11972  block_size =
11973  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) *
11974  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11975  (8 * 8);
11976 
11977  // need to align to 64 bytes
11978  customMapSize = ((block_size + 63) & (~63));
11979  if (!p_enc_ctx->roi_map)
11980  {
11981  p_enc_ctx->roi_map =
11982  (ni_enc_quad_roi_custom_map *)calloc(1, customMapSize);
11983  }
11984  if (!p_enc_ctx->roi_map)
11985  {
11987  }
11988 
11989  // for H.264, select ROI Map Block Unit Size: 16x16
11990  // for H.265, select ROI Map Block Unit Size: 64x64
11991  roiMapBlockUnitSize = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16 : 64;
11992 
11993  mbWidth =
11994  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11995  roiMapBlockUnitSize;
11996  mbHeight =
11997  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11998  roiMapBlockUnitSize;
11999  numMbs = mbWidth * mbHeight;
12000 
12001  // copy roi MBs QPs into custom map
12002  // number of qp info (8x8) per mb or ctb
12003  entryPerMb = (roiMapBlockUnitSize / 8) * (roiMapBlockUnitSize / 8);
12004 
12005  for (i = 0; i < numMbs; i++)
12006  {
12007  bool bIsCenter = (i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3);
12008  for (j = 0; j < entryPerMb; j++)
12009  {
12010  /*
12011  g_quad_roi_map[i*4+j].field.skip_flag = 0; // don't force
12012  skip mode g_quad_roi_map[i*4+j].field.roiAbsQp_flag = 1; //
12013  absolute QP g_quad_roi_map[i*4+j].field.qp_info = bIsCenter
12014  ? importanceLevelCentre : importanceLevelRest;
12015  */
12016  p_enc_ctx->roi_map[i * entryPerMb + j].field.ipcm_flag =
12017  0; // don't force skip mode
12018  p_enc_ctx->roi_map[i * entryPerMb + j]
12019  .field.roiAbsQp_flag = 1; // absolute QP
12020  p_enc_ctx->roi_map[i * entryPerMb + j].field.qp_info =
12021  bIsCenter ? importanceLevelCentre : importanceLevelRest;
12022  }
12023  sumQp += p_enc_ctx->roi_map[i * entryPerMb].field.qp_info;
12024  }
12025  p_enc_ctx->roi_len = customMapSize;
12026  p_enc_ctx->roi_avg_qp =
12027  // NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
12028  (sumQp + (numMbs >> 1)) / numMbs; // round off
12029  }
12030  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264)
12031  {
12032  // roi for H.264 is specified for 16x16 pixel macroblocks - 1 MB
12033  // is stored in each custom map entry
12034 
12035  // number of MBs in each row
12036  uint32_t mbWidth = (linesize_aligned + 16 - 1) >> 4;
12037  // number of MBs in each column
12038  uint32_t mbHeight = (height_aligned + 16 - 1) >> 4;
12039  uint32_t numMbs = mbWidth * mbHeight;
12040  uint32_t customMapSize =
12041  sizeof(ni_enc_avc_roi_custom_map_t) * numMbs;
12042  p_enc_ctx->avc_roi_map =
12043  (ni_enc_avc_roi_custom_map_t *)calloc(1, customMapSize);
12044  if (!p_enc_ctx->avc_roi_map)
12045  {
12047  }
12048 
12049  // copy roi MBs QPs into custom map
12050  for (i = 0; i < numMbs; i++)
12051  {
12052  if ((i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3))
12053  {
12054  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelCentre;
12055  }
12056  else
12057  {
12058  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelRest;
12059  }
12060  sumQp += p_enc_ctx->avc_roi_map[i].field.mb_qp;
12061  }
12062  p_enc_ctx->roi_len = customMapSize;
12063  p_enc_ctx->roi_avg_qp =
12064  (sumQp + (numMbs >> 1)) / numMbs; // round off
12065  }
12066  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H265)
12067  {
12068  // roi for H.265 is specified for 32x32 pixel subCTU blocks - 4
12069  // subCTU QPs are stored in each custom CTU map entry
12070 
12071  // number of CTUs in each row
12072  uint32_t ctuWidth = (linesize_aligned + 64 - 1) >> 6;
12073  // number of CTUs in each column
12074  uint32_t ctuHeight = (height_aligned + 64 - 1) >> 6;
12075  // number of sub CTUs in each row
12076  uint32_t subCtuWidth = ctuWidth * 2;
12077  // number of CTUs in each column
12078  uint32_t subCtuHeight = ctuHeight * 2;
12079  uint32_t numSubCtus = subCtuWidth * subCtuHeight;
12080 
12081  p_enc_ctx->hevc_sub_ctu_roi_buf = (uint8_t *)malloc(numSubCtus);
12082  if (!p_enc_ctx->hevc_sub_ctu_roi_buf)
12083  {
12085  }
12086  for (i = 0; i < numSubCtus; i++)
12087  {
12088  if ((i % subCtuWidth > subCtuWidth / 3) &&
12089  (i % subCtuWidth < subCtuWidth * 2 / 3))
12090  {
12091  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelCentre;
12092  }
12093  else
12094  {
12095  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelRest;
12096  }
12097  }
12098  p_enc_ctx->hevc_roi_map = (ni_enc_hevc_roi_custom_map_t *)calloc(
12099  1, sizeof(ni_enc_hevc_roi_custom_map_t) * ctuWidth * ctuHeight);
12100  if (!p_enc_ctx->hevc_roi_map)
12101  {
12103  }
12104 
12105  for (i = 0; i < ctuHeight; i++)
12106  {
12107  uint8_t *ptr = &p_enc_ctx->hevc_sub_ctu_roi_buf[subCtuWidth * i * 2];
12108  for (j = 0; j < ctuWidth; j++, ptr += 2)
12109  {
12110  ctu = (i * ctuWidth + j);
12111  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 = *ptr;
12112  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 = *(ptr + 1);
12113  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 =
12114  *(ptr + subCtuWidth);
12115  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3 =
12116  *(ptr + subCtuWidth + 1);
12117  sumQp += (p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 +
12118  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 +
12119  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 +
12120  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3);
12121  }
12122  }
12123  p_enc_ctx->roi_len =
12124  ctuWidth * ctuHeight * sizeof(ni_enc_hevc_roi_custom_map_t);
12125  p_enc_ctx->roi_avg_qp =
12126  (sumQp + (numSubCtus >> 1)) / numSubCtus; // round off.
12127  }
12128  return NI_RETCODE_SUCCESS;
12129 }
12130 
12132 {
12133  // for encoder reconfiguration testing
12134  // reset encoder change data buffer for reconf parameters
12135  ni_retcode_t retval = 0;
12136  ni_xcoder_params_t *p_param =
12137  (ni_xcoder_params_t *)p_enc_ctx->p_session_config;
12138  ni_aux_data_t *aux_data = NULL;
12139  if (p_param->reconf_demo_mode > XCODER_TEST_RECONF_OFF &&
12141  {
12142  memset(p_enc_ctx->enc_change_params, 0, sizeof(ni_encoder_change_params_t));
12143  }
12144 
12145  switch (p_param->reconf_demo_mode) {
12146  case XCODER_TEST_RECONF_BR:
12147  if (p_enc_ctx->frame_num ==
12148  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12149  {
12150  aux_data = ni_frame_new_aux_data(
12151  p_frame, NI_FRAME_AUX_DATA_BITRATE, sizeof(int32_t));
12152  if (!aux_data)
12153  {
12155  }
12156  *((int32_t *)aux_data->data) =
12157  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12158 
12159  p_enc_ctx->reconfigCount++;
12160  if (p_param->cfg_enc_params.hrdEnable)
12161  {
12162  p_frame->force_key_frame = 1;
12163  p_frame->ni_pict_type = PIC_TYPE_IDR;
12164  }
12165  }
12166  break;
12167  // reconfig intraperiod param
12169  if (p_enc_ctx->frame_num ==
12170  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12171  {
12172  aux_data = ni_frame_new_aux_data(
12173  p_frame, NI_FRAME_AUX_DATA_INTRAPRD, sizeof(int32_t));
12174  if (!aux_data)
12175  {
12177  }
12178  int32_t intraprd = *((int32_t *)aux_data->data) =
12179  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12180  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12181  "xcoder_send_frame: frame #%lu reconf "
12182  "intraPeriod %d\n",
12183  p_enc_ctx->frame_num,
12184  intraprd);
12185  p_enc_ctx->reconfigCount++;
12186  }
12187  break;
12188  // reconfig VUI parameters
12190  if (p_enc_ctx->frame_num ==
12191  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12192  {
12193  aux_data = ni_frame_new_aux_data(p_frame,
12195  sizeof(ni_vui_hrd_t));
12196  if (!aux_data)
12197  {
12199  }
12200  ni_vui_hrd_t *vui = (ni_vui_hrd_t *)aux_data->data;
12201  vui->colorDescPresent =
12202  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12203  vui->colorPrimaries =
12204  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12205  vui->colorTrc =
12206  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12207  vui->colorSpace =
12208  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12209  vui->aspectRatioWidth =
12210  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12211  vui->aspectRatioHeight =
12212  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12213  vui->videoFullRange =
12214  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12215  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12216  "xcoder_send_frame: frame #%lu reconf "
12217  "vui colorDescPresent %d colorPrimaries %d "
12218  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12219  "aspectRatioHeight %d videoFullRange %d\n",
12220  p_enc_ctx->frame_num, vui->colorDescPresent,
12221  vui->colorPrimaries, vui->colorTrc,
12222  vui->colorSpace, vui->aspectRatioWidth,
12223  vui->aspectRatioHeight, vui->videoFullRange);
12224 
12225  p_enc_ctx->reconfigCount++;
12226  }
12227  break;
12228  // long term ref
12230  // the reconf file data line format for this is:
12231  // <frame-number>:useCurSrcAsLongtermPic,useLongtermRef where
12232  // values will stay the same on every frame until changed.
12233  if (p_enc_ctx->frame_num ==
12234  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12235  {
12236  ni_long_term_ref_t *p_ltr;
12237  aux_data = ni_frame_new_aux_data(
12239  sizeof(ni_long_term_ref_t));
12240  if (!aux_data)
12241  {
12243  }
12244  p_ltr = (ni_long_term_ref_t *)aux_data->data;
12246  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12247  p_ltr->use_long_term_ref =
12248  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12249  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12250  "xcoder_send_frame: frame #%lu metadata "
12251  "use_cur_src_as_long_term_pic %d use_long_term_ref "
12252  "%d\n",
12253  p_enc_ctx->frame_num,
12255  p_ltr->use_long_term_ref);
12256  p_enc_ctx->reconfigCount++;
12257  }
12258  break;
12259  // reconfig min / max QP
12262  if (p_enc_ctx->frame_num ==
12263  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12264  aux_data = ni_frame_new_aux_data(
12266  if (!aux_data) {
12268  }
12269 
12270  ni_rc_min_max_qp *qp_info = (ni_rc_min_max_qp *)aux_data->data;
12271  qp_info->minQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12272  qp_info->maxQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12273  qp_info->maxDeltaQp = p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12274  qp_info->minQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12275  qp_info->maxQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12276 
12277  p_enc_ctx->reconfigCount++;
12278  }
12279  break;
12280 #ifdef QUADRA
12281  // reconfig LTR interval
12283  if (p_enc_ctx->frame_num ==
12284  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12285  aux_data = ni_frame_new_aux_data(p_frame,
12287  sizeof(int32_t));
12288  if (!aux_data) {
12290  }
12291  *((int32_t *)aux_data->data) =
12292  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12293  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12294  "xcoder_send_frame: frame #%lu reconf "
12295  "ltrInterval %d\n",
12296  p_enc_ctx->frame_num,
12297  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12298 
12299  p_enc_ctx->reconfigCount++;
12300  }
12301  break;
12302  // invalidate reference frames
12304  if (p_enc_ctx->frame_num ==
12305  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12306  aux_data = ni_frame_new_aux_data(
12308  sizeof(int32_t));
12309  if (!aux_data) {
12311  }
12312  *((int32_t *)aux_data->data) =
12313  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12314  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12315  "xcoder_send_frame: frame #%lu reconf "
12316  "invalidFrameNum %d\n",
12317  p_enc_ctx->frame_num,
12318  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12319 
12320  p_enc_ctx->reconfigCount++;
12321  }
12322  break;
12323  // reconfig framerate
12325  if (p_enc_ctx->frame_num ==
12326  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12327  ni_framerate_t *framerate;
12328 
12329  aux_data = ni_frame_new_aux_data(p_frame,
12331  sizeof(ni_framerate_t));
12332  if (!aux_data) {
12334  }
12335 
12336  framerate = (ni_framerate_t *)aux_data->data;
12337  framerate->framerate_num =
12338  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12339  framerate->framerate_denom =
12340  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12341  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12342  "xcoder_send_frame: frame #%lu reconf "
12343  "framerate (%d/%d)\n",
12344  p_enc_ctx->frame_num, framerate->framerate_num,
12345  framerate->framerate_denom);
12346  p_enc_ctx->reconfigCount++;
12347  }
12348  break;
12350  if (p_enc_ctx->frame_num ==
12351  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12352  aux_data = ni_frame_new_aux_data(
12353  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12354  if (!aux_data) {
12356  }
12357  *((int32_t *)aux_data->data) =
12358  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12359  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12360  "xcoder_send_frame: frame #%lu reconf "
12361  "maxFrameSize %d\n",
12362  p_enc_ctx->frame_num,
12363  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12364 
12365  p_enc_ctx->reconfigCount++;
12366  }
12367  break;
12369  if (p_enc_ctx->frame_num ==
12370  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12371  aux_data = ni_frame_new_aux_data(
12372  p_frame, NI_FRAME_AUX_DATA_CRF, sizeof(int32_t));
12373  if (!aux_data) {
12375  }
12376  *((int32_t *)aux_data->data) =
12377  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12378  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12379  "xcoder_send_frame: frame #%lu reconf "
12380  "crf %d\n",
12381  p_enc_ctx->frame_num,
12382  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12383 
12384  p_enc_ctx->reconfigCount++;
12385  }
12386  break;
12388  if (p_enc_ctx->frame_num ==
12389  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12390  aux_data = ni_frame_new_aux_data(
12391  p_frame, NI_FRAME_AUX_DATA_CRF_FLOAT, sizeof(float));
12392  if (!aux_data) {
12394  }
12395  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12396  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12397  *((float *)aux_data->data) = crf;
12398  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12399  "xcoder_send_frame: frame #%lu reconf "
12400  "crf %f\n",
12401  p_enc_ctx->frame_num, crf);
12402 
12403  p_enc_ctx->reconfigCount++;
12404  }
12405  break;
12407  if (p_enc_ctx->frame_num ==
12408  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12409  int32_t vbvBufferSize = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12410  int32_t vbvMaxRate = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12411  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
12412  {
12413  ni_log2(p_enc_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid vbvBufferSize value %d\n",
12414  __func__, vbvBufferSize);
12415  return NI_RETCODE_INVALID_PARAM;
12416  }
12417  if (p_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < p_param->bitrate) {
12418  ni_log2(p_enc_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
12419  vbvMaxRate, p_param->bitrate);
12420  return NI_RETCODE_INVALID_PARAM;
12421  }
12422  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
12423  ni_log2(p_enc_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
12424  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
12425  vbvMaxRate);
12426  vbvMaxRate = 0;
12427  }
12428 
12429  aux_data = ni_frame_new_aux_data(
12430  p_frame, NI_FRAME_AUX_DATA_VBV_MAX_RATE, sizeof(int32_t));
12431  if (!aux_data) {
12433  }
12434  *((int32_t *)aux_data->data) = vbvMaxRate;
12435  aux_data = ni_frame_new_aux_data(
12436  p_frame, NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE, sizeof(int32_t));
12437  if (!aux_data) {
12439  }
12440  *((int32_t *)aux_data->data) = vbvBufferSize;
12441  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12442  "xcoder_send_frame: frame #%lu reconfig vbvMaxRate %d vbvBufferSize "
12443  "%d by frame aux data\n",
12444  p_enc_ctx->frame_num, vbvMaxRate, vbvBufferSize);
12445 
12446  p_enc_ctx->reconfigCount++;
12447  }
12448  break;
12450  if (p_enc_ctx->frame_num ==
12451  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12452  int maxFrameSizeRatio = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12453  if (maxFrameSizeRatio < 1) {
12454  ni_log2(p_enc_ctx, NI_LOG_ERROR, "maxFrameSizeRatio %d cannot < 1\n",
12455  maxFrameSizeRatio);
12456  return NI_RETCODE_INVALID_PARAM;
12457  }
12458  aux_data = ni_frame_new_aux_data(
12459  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12460  if (!aux_data) {
12462  }
12463 
12464  int32_t bitrate, framerate_num, framerate_denom;
12465  uint32_t min_maxFrameSize, maxFrameSize;
12466  bitrate = (p_enc_ctx->target_bitrate > 0) ? p_enc_ctx->target_bitrate : p_param->bitrate;
12467 
12468  if ((p_enc_ctx->framerate.framerate_num > 0) && (p_enc_ctx->framerate.framerate_denom > 0))
12469  {
12470  framerate_num = p_enc_ctx->framerate.framerate_num;
12471  framerate_denom = p_enc_ctx->framerate.framerate_denom;
12472  }
12473  else
12474  {
12475  framerate_num = (int32_t) p_param->fps_number;
12476  framerate_denom = (int32_t) p_param->fps_denominator;
12477  }
12478 
12479  min_maxFrameSize = ((uint32_t)bitrate / framerate_num * framerate_denom) / 8;
12480  maxFrameSize = min_maxFrameSize * maxFrameSizeRatio > NI_MAX_FRAME_SIZE ?
12481  NI_MAX_FRAME_SIZE : min_maxFrameSize * maxFrameSizeRatio;
12482  *((int32_t *)aux_data->data) = maxFrameSize;
12483  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12484  "xcoder_send_frame: frame #%lu reconf "
12485  "maxFrameSizeRatio %d maxFrameSize %d\n",
12486  p_enc_ctx->frame_num, maxFrameSizeRatio, maxFrameSize);
12487 
12488  p_enc_ctx->reconfigCount++;
12489  }
12490  break;
12492  if (p_enc_ctx->frame_num ==
12493  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12494  aux_data = ni_frame_new_aux_data(
12495  p_frame, NI_FRAME_AUX_DATA_SLICE_ARG, sizeof(int16_t));
12496  if (!aux_data) {
12498  }
12499  *((int16_t *)aux_data->data) =
12500  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12501  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12502  "xcoder_send_frame: frame #%lu reconf "
12503  "sliceArg %d\n",
12504  p_enc_ctx->frame_num,
12505  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12506 
12507  p_enc_ctx->reconfigCount++;
12508  }
12509  break;
12510  // force IDR frame through API test code
12512  if (p_enc_ctx->frame_num ==
12513  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12514  ni_force_idr_frame_type(p_enc_ctx);
12515  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12516  "xcoder_send_frame: frame #%lu force IDR frame\n",
12517  p_enc_ctx->frame_num);
12518 
12519  p_enc_ctx->reconfigCount++;
12520  }
12521  break;
12522  // reconfig bit rate through API test code
12524  if (p_enc_ctx->frame_num ==
12525  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12526  if ((retval = ni_reconfig_bitrate(
12527  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))){
12528  return retval;
12529  }
12530  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12531  "xcoder_send_frame: frame #%lu API reconfig BR %d\n",
12532  p_enc_ctx->frame_num,
12533  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12534 
12535  p_enc_ctx->reconfigCount++;
12536  }
12537  break;
12539  if (p_enc_ctx->frame_num ==
12540  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12541  int32_t intraprd =
12542  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12543  if ((retval = ni_reconfig_intraprd(p_enc_ctx, intraprd))){
12544  return retval;
12545  }
12547  "xcoder_send_frame: frame #%lu API reconfig intraPeriod %d\n",
12548  p_enc_ctx->frame_num,
12549  intraprd);
12550 
12551  p_enc_ctx->reconfigCount++;
12552  }
12553  break;
12555  if (p_enc_ctx->frame_num ==
12556  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12557  ni_vui_hrd_t vui;
12558  vui.colorDescPresent =
12559  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12560  vui.colorPrimaries =
12561  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12562  vui.colorTrc =
12563  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12564  vui.colorSpace =
12565  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12566  vui.aspectRatioWidth =
12567  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12568  vui.aspectRatioHeight =
12569  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12570  vui.videoFullRange =
12571  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12572  if ((retval = ni_reconfig_vui(p_enc_ctx, &vui))){
12573  return retval;
12574  }
12575  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12576  "xcoder_send_frame: frame #%lu reconf "
12577  "vui colorDescPresent %d colorPrimaries %d "
12578  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12579  "aspectRatioHeight %d videoFullRange %d\n",
12580  p_enc_ctx->frame_num, vui.colorDescPresent,
12581  vui.colorPrimaries, vui.colorTrc,
12582  vui.colorSpace, vui.aspectRatioWidth,
12584  p_enc_ctx->reconfigCount++;
12585  }
12586  break;
12588  if (p_enc_ctx->frame_num ==
12589  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12590  ni_long_term_ref_t ltr;
12592  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12593  ltr.use_long_term_ref =
12594  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12595 
12596  if ((retval = ni_set_ltr(p_enc_ctx, &ltr))) {
12597  return retval;
12598  }
12599  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12600  "xcoder_send_frame(): frame #%lu API set LTR\n",
12601  p_enc_ctx->frame_num);
12602  p_enc_ctx->reconfigCount++;
12603  }
12604  break;
12607  if (p_enc_ctx->frame_num ==
12608  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12609  ni_rc_min_max_qp qp_info;
12610  qp_info.minQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12611  qp_info.maxQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12612  qp_info.maxDeltaQp = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12613  qp_info.minQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12614  qp_info.maxQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12615  if ((retval = ni_reconfig_min_max_qp(p_enc_ctx, &qp_info))) {
12616  return retval;
12617  }
12618  ni_log2(p_enc_ctx, NI_LOG_DEBUG,
12619  "%s(): frame %d minQpI %d maxQpI %d maxDeltaQp %d minQpPB %d maxQpPB %d\n",
12620  __func__, p_enc_ctx->frame_num,
12621  qp_info.minQpI, qp_info.maxQpI, qp_info.maxDeltaQp, qp_info.minQpPB, qp_info.maxQpPB);
12622  p_enc_ctx->reconfigCount++;
12623  }
12624  break;
12626  if (p_enc_ctx->frame_num ==
12627  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12628  if ((retval = ni_set_ltr_interval(
12629  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12630  return retval;
12631  }
12632  ni_log2(p_enc_ctx,
12633  NI_LOG_TRACE,
12634  "xcoder_send_frame(): frame #%lu API set LTR interval %d\n",
12635  p_enc_ctx->frame_num,
12636  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12637  p_enc_ctx->reconfigCount++;
12638  }
12639  break;
12641  if (p_enc_ctx->frame_num ==
12642  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12643  if ((retval = ni_set_frame_ref_invalid(
12644  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12645  return retval;
12646  }
12647  ni_log2(p_enc_ctx,
12648  NI_LOG_TRACE,
12649  "xcoder_send_frame(): frame #%lu API set frame ref invalid "
12650  "%d\n",
12651  p_enc_ctx->frame_num,
12652  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12653  p_enc_ctx->reconfigCount++;
12654  }
12655  break;
12657  if (p_enc_ctx->frame_num ==
12658  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12659  ni_framerate_t framerate;
12660  framerate.framerate_num =
12661  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12662  framerate.framerate_denom =
12663  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12664  if ((retval = ni_reconfig_framerate(p_enc_ctx, &framerate))) {
12665  return retval;
12666  }
12667  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12668  "xcoder_send_frame: frame #%lu API reconfig framerate "
12669  "(%d/%d)\n",
12670  p_enc_ctx->frame_num,
12671  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12672  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12673 
12674  p_enc_ctx->reconfigCount++;
12675  }
12676  break;
12678  if (p_enc_ctx->frame_num ==
12679  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12680  if ((retval = ni_reconfig_max_frame_size(
12681  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12682  return retval;
12683  }
12684  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12685  "xcoder_send_frame: frame #%lu API reconfig maxFrameSize %d\n",
12686  p_enc_ctx->frame_num,
12687  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12688 
12689  p_enc_ctx->reconfigCount++;
12690  }
12691  break;
12692  case XCODER_TEST_CRF_API:
12693  if (p_enc_ctx->frame_num ==
12694  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12695  if ((retval = ni_reconfig_crf(
12696  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12697  return retval;
12698  }
12699  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12700  "xcoder_send_frame: frame #%lu API reconfig crf %d\n",
12701  p_enc_ctx->frame_num,
12702  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12703 
12704  p_enc_ctx->reconfigCount++;
12705  }
12706  break;
12708  if (p_enc_ctx->frame_num ==
12709  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12710  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12711  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12712  if ((retval = ni_reconfig_crf2(p_enc_ctx, crf))) {
12713  return retval;
12714  }
12715  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12716  "xcoder_send_frame: frame #%lu API reconfig crf %f\n",
12717  p_enc_ctx->frame_num, crf);
12718 
12719  p_enc_ctx->reconfigCount++;
12720  }
12721  break;
12723  if (p_enc_ctx->frame_num ==
12724  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12725  if ((retval = ni_reconfig_vbv_value(
12726  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12727  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]))) {
12728  return retval;
12729  }
12730  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12731  "xcoder_send_frame: frame #%lu API reconfig vbvMaxRate %d vbvBufferSize %d\n",
12732  p_enc_ctx->frame_num,
12733  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12734  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12735 
12736  p_enc_ctx->reconfigCount++;
12737  }
12738  break;
12740  if (p_enc_ctx->frame_num ==
12741  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12742 
12743  if ((retval = ni_reconfig_max_frame_size_ratio(
12744  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12745  return retval;
12746  }
12747  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12748  "xcoder_send_frame: frame #%lu reconf maxFrameSizeRatio %d\n",
12749  p_enc_ctx->frame_num, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12750 
12751  p_enc_ctx->reconfigCount++;
12752  }
12753  break;
12755  if (p_enc_ctx->frame_num ==
12756  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12757  if ((retval = ni_reconfig_slice_arg(
12758  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12759  return retval;
12760  }
12761  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12762  "xcoder_send_frame: frame #%lu API reconfig sliceArg %d\n",
12763  p_enc_ctx->frame_num,
12764  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12765 
12766  p_enc_ctx->reconfigCount++;
12767  }
12768  break;
12769 #endif
12771  default:
12772  ;
12773  }
12774  return NI_RETCODE_SUCCESS;
12775 }
12776 
12780 static int ni_tolower(int c)
12781 {
12782  if (c >= 'A' && c <= 'Z')
12783  c ^= 0x20;
12784  return c;
12785 }
12786 
12787 int ni_strcasecmp(const char *a, const char *b)
12788 {
12789  uint8_t c1, c2;
12790  do
12791  {
12792  c1 = ni_tolower(*a++);
12793  c2 = ni_tolower(*b++);
12794  } while (c1 && c1 == c2);
12795  return c1 - c2;
12796 }
12797 
12798 void ni_gop_params_check_set(ni_xcoder_params_t *p_param, char *value)
12799 {
12800  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
12801  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
12803  p_gop->pic_param[0].rps[0].ref_pic = 1;
12805  p_gop->pic_param[0].rps[0].ref_pic_used = 1;
12807  p_gop->pic_param[0].rps[1].ref_pic = 1;
12809  p_gop->pic_param[0].rps[1].ref_pic_used = 1;
12811  p_gop->pic_param[0].rps[2].ref_pic = 1;
12813  p_gop->pic_param[0].rps[2].ref_pic_used = 1;
12815  p_gop->pic_param[0].rps[3].ref_pic = 1;
12817  p_gop->pic_param[0].rps[3].ref_pic_used = 1;
12819  p_gop->pic_param[1].rps[0].ref_pic = 1;
12821  p_gop->pic_param[1].rps[0].ref_pic_used = 1;
12823  p_gop->pic_param[1].rps[1].ref_pic = 1;
12825  p_gop->pic_param[1].rps[1].ref_pic_used = 1;
12827  p_gop->pic_param[1].rps[2].ref_pic = 1;
12829  p_gop->pic_param[1].rps[2].ref_pic_used = 1;
12831  p_gop->pic_param[1].rps[3].ref_pic = 1;
12833  p_gop->pic_param[1].rps[3].ref_pic_used = 1;
12835  p_gop->pic_param[2].rps[0].ref_pic = 1;
12837  p_gop->pic_param[2].rps[0].ref_pic_used = 1;
12839  p_gop->pic_param[2].rps[1].ref_pic = 1;
12841  p_gop->pic_param[2].rps[1].ref_pic_used = 1;
12843  p_gop->pic_param[2].rps[2].ref_pic = 1;
12845  p_gop->pic_param[2].rps[2].ref_pic_used = 1;
12847  p_gop->pic_param[2].rps[3].ref_pic = 1;
12849  p_gop->pic_param[2].rps[3].ref_pic_used = 1;
12851  p_gop->pic_param[3].rps[0].ref_pic = 1;
12853  p_gop->pic_param[3].rps[0].ref_pic_used = 1;
12855  p_gop->pic_param[3].rps[1].ref_pic = 1;
12857  p_gop->pic_param[3].rps[1].ref_pic_used = 1;
12859  p_gop->pic_param[3].rps[2].ref_pic = 1;
12861  p_gop->pic_param[3].rps[2].ref_pic_used = 1;
12863  p_gop->pic_param[3].rps[3].ref_pic = 1;
12865  p_gop->pic_param[3].rps[3].ref_pic_used = 1;
12867  p_gop->pic_param[4].rps[0].ref_pic = 1;
12869  p_gop->pic_param[4].rps[0].ref_pic_used = 1;
12871  p_gop->pic_param[4].rps[1].ref_pic = 1;
12873  p_gop->pic_param[4].rps[1].ref_pic_used = 1;
12875  p_gop->pic_param[4].rps[2].ref_pic = 1;
12877  p_gop->pic_param[4].rps[2].ref_pic_used = 1;
12879  p_gop->pic_param[4].rps[3].ref_pic = 1;
12881  p_gop->pic_param[4].rps[3].ref_pic_used = 1;
12883  p_gop->pic_param[5].rps[0].ref_pic = 1;
12885  p_gop->pic_param[5].rps[0].ref_pic_used = 1;
12887  p_gop->pic_param[5].rps[1].ref_pic = 1;
12889  p_gop->pic_param[5].rps[1].ref_pic_used = 1;
12891  p_gop->pic_param[5].rps[2].ref_pic = 1;
12893  p_gop->pic_param[5].rps[2].ref_pic_used = 1;
12895  p_gop->pic_param[5].rps[3].ref_pic = 1;
12897  p_gop->pic_param[5].rps[3].ref_pic_used = 1;
12899  p_gop->pic_param[6].rps[0].ref_pic = 1;
12901  p_gop->pic_param[6].rps[0].ref_pic_used = 1;
12903  p_gop->pic_param[6].rps[1].ref_pic = 1;
12905  p_gop->pic_param[6].rps[1].ref_pic_used = 1;
12907  p_gop->pic_param[6].rps[2].ref_pic = 1;
12909  p_gop->pic_param[6].rps[2].ref_pic_used = 1;
12911  p_gop->pic_param[6].rps[3].ref_pic = 1;
12913  p_gop->pic_param[6].rps[3].ref_pic_used = 1;
12915  p_gop->pic_param[7].rps[0].ref_pic = 1;
12917  p_gop->pic_param[7].rps[0].ref_pic_used = 1;
12919  p_gop->pic_param[7].rps[1].ref_pic = 1;
12921  p_gop->pic_param[7].rps[1].ref_pic_used = 1;
12923  p_gop->pic_param[7].rps[2].ref_pic = 1;
12925  p_gop->pic_param[7].rps[2].ref_pic_used = 1;
12927  p_gop->pic_param[7].rps[3].ref_pic = 1;
12929  p_gop->pic_param[7].rps[3].ref_pic_used = 1;
12930 
12931 }
12932 
12934 {
12935  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
12936  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
12937  int i, j;
12938  for (i=0; i<NI_MAX_GOP_NUM; i++)
12939  {
12940  for (j=0; j<NI_MAX_REF_PIC; j++)
12941  {
12942  if (p_gop->pic_param[i].rps[j].ref_pic == 1 &&
12943  p_gop->pic_param[i].rps[j].ref_pic_used != 1)
12944  {
12946  "g%drefPic%d specified without g%drefPic%dUsed specified!\n",
12947  i, j, i, j);
12948  return false;
12949  }
12950  }
12951  }
12952  // set custom_gop_params default.
12953  for (i=0; i<NI_MAX_GOP_NUM; i++)
12954  {
12955  for (j=0; j<NI_MAX_REF_PIC; j++)
12956  {
12957  p_gop->pic_param[i].rps[j].ref_pic = 0;
12958  p_gop->pic_param[i].rps[j].ref_pic_used = 0;
12959  }
12960  }
12961  return true;
12962 }
12963 
12964 #ifndef DEPRECATION_AS_ERROR
12965 /*!*****************************************************************************
12966  * \brief Initiate P2P transfer (P2P write) (deprecated)
12967  *
12968  * \param[in] pSession Pointer to source card destination
12969  * \param[in] source Pointer to source frame to transmit
12970  * \param[in] ui64DestAddr Destination address on target device
12971  * \param[in] ui32FrameSize Size of frame to transfer
12972  *
12973  * \return always returns
12974  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12975 *******************************************************************************/
12977  niFrameSurface1_t *source,
12978  uint64_t ui64DestAddr,
12979  uint32_t ui32FrameSize)
12980 {
12981  // avoid compiler warnings
12982  (void) pSession;
12983  (void) source;
12984  (void) ui64DestAddr;
12985  (void) ui32FrameSize;
12986 
12988 }
12989 #endif
12990 
12991 /*!*****************************************************************************
12992  * \brief Initiate P2P transfer (P2P write)
12993  *
12994  * \param[in] pSession Pointer to source card destination
12995  * \param[in] source Pointer to source frame to transmit
12996  * \param[in] ui64DestAddr Destination address on target device
12997  * \param[in] ui32FrameSize Size of frame to transfer
12998  *
12999  * \return on success
13000  * NI_RETCODE_SUCCESS
13001  * on failure
13002  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
13003  * NI_RETCODE_INVALID_PARAM
13004  * NI_RETCODE_ERROR_INVALID_SESSION
13005  * NI_RETCODE_ERROR_MEM_ALOC
13006  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13007 *******************************************************************************/
13009  niFrameSurface1_t *source,
13010  uint64_t ui64DestAddr, uint32_t ui32FrameSize)
13011 {
13013 
13014  if ((pSession == NULL) || (source == NULL))
13015  {
13016  return NI_RETCODE_INVALID_PARAM;
13017  }
13018 
13019  /* Firmware compatibility check */
13020  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
13021  {
13022  ni_log2(pSession, NI_LOG_ERROR, "%s: FW doesn't support this operation\n", __func__);
13024  }
13025 
13026  retval = ni_send_to_target(pSession, source, ui64DestAddr, ui32FrameSize);
13027 
13028  if (retval < 0)
13029  {
13030  ni_log2(pSession, NI_LOG_ERROR, "%s(): Can't DMA to destination (%d)\n", __func__, retval);
13031  }
13032 
13033  return retval;
13034 }
13035 
13036 /*!*****************************************************************************
13037  * \brief Initiate a P2P transfer (P2P read)
13038  *
13039  * \param[in] pSession Pointer to destination upload session
13040  * \param[in] dmaAddrs Pointer to source DMA addresses
13041  * \param[in] pDstFrame Pointer to destination P2P frame
13042  *
13043  * \return on success
13044  * NI_RETCODE_SUCCESS
13045  * on failure
13046  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
13047  * NI_RETCODE_INVALID_PARAM
13048  * NI_RETCODE_ERROR_INVALID_SESSION
13049  * NI_RETCODE_ERROR_MEM_ALOC
13050  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13051 *******************************************************************************/
13053  const ni_p2p_sgl_t *dmaAddrs,
13054  ni_frame_t *pDstFrame)
13055 {
13057 
13058  if ((pSession == NULL) || (dmaAddrs == NULL) || (pDstFrame == NULL))
13059  {
13060  return NI_RETCODE_INVALID_PARAM;
13061  }
13062 
13063  /* Firmware compatibility check */
13064  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
13065  {
13066  ni_log2(pSession, NI_LOG_ERROR,
13067  "%s: FW doesn't support this operation\n", __func__);
13069  }
13070 
13071  retval = ni_recv_from_target(pSession, dmaAddrs, pDstFrame);
13072 
13073  if (retval < 0)
13074  {
13075  ni_log2(pSession, NI_LOG_ERROR,
13076  "%s(): Can't DMA from source (%d)\n", __func__, retval);
13077  retval = NI_RETCODE_INVALID_PARAM;
13078  }
13079 
13080  return retval;
13081 }
13082 
13083 /*!*****************************************************************************
13084  * \brief Send a restart command after flush command
13085  * Only support Encoder now
13086  *
13087  * \param[in] p_ctx Pointer to a caller allocated
13088  * ni_session_context_t struct
13089  * \param[in] width width, in pixels
13090  * \param[in] height height, in pixels
13091  * \param[in] device_type NI_DEVICE_TYPE_ENCODER
13092  * \return On success
13093  * NI_RETCODE_SUCCESS
13094  * On failure
13095  * NI_RETCODE_INVALID_PARAM
13096  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13097  * NI_RETCODE_ERROR_INVALID_SESSION
13098  ******************************************************************************/
13100  int video_width,
13101  int video_height,
13102  ni_device_type_t device_type)
13103 {
13104  ni_retcode_t retval = 0;
13105  ni_resolution_t resolution;
13106  ni_xcoder_params_t *p_param = NULL;
13107 
13108  if (!p_ctx)
13109  {
13110  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
13111  __func__);
13112  return NI_RETCODE_INVALID_PARAM;
13113  }
13114 
13115  switch (device_type)
13116  {
13118  {
13119  // requires API version >= 54
13121  "54") < 0)
13122  {
13123  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
13125  }
13126 
13127  /* This function should be called only if flushing is detected */
13129  {
13130  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() wrong state %d\n",
13131  __func__, p_ctx->session_run_state);
13133  }
13134 
13135  if (video_width < NI_MIN_WIDTH || video_width > NI_MAX_WIDTH ||
13136  video_height < NI_MIN_HEIGHT || video_height > NI_MAX_HEIGHT)
13137  {
13138  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() invalid width %d or height %d\n",
13139  __func__, video_width, video_height);
13140  return NI_RETCODE_INVALID_PARAM;
13141  }
13142  resolution.width = video_width;
13143  resolution.height = video_height;
13144  resolution.bit_depth_factor = p_ctx->bit_depth_factor;
13145  resolution.luma_linesize = 0;
13146  resolution.chroma_linesize = 0;
13147  if (p_ctx->p_session_config)
13148  {
13149  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
13150  resolution.luma_linesize = p_param->luma_linesize;
13151  resolution.chroma_linesize = p_param->chroma_linesize;
13152  }
13153  ni_pthread_mutex_lock(&p_ctx->mutex);
13154 
13155  // reconfig the encoder session
13156  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
13157  if (NI_RETCODE_SUCCESS != retval)
13158  {
13159  ni_log(NI_LOG_ERROR, "Failed to reconfig config the encoder session (status = %d)\n", retval);
13160  ni_pthread_mutex_unlock(&p_ctx->mutex);
13161  return retval;
13162  }
13163 
13164  // update session context
13165  p_ctx->ready_to_close = 0;
13166  p_ctx->frame_num = 0;
13167  p_ctx->pkt_num = 0;
13168  ni_pthread_mutex_unlock(&p_ctx->mutex);
13169  break;
13170  }
13171  default:
13172  {
13173  retval = NI_RETCODE_INVALID_PARAM;
13174  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unsupported device type: %d",
13175  __func__, device_type);
13176  break;
13177  }
13178  }
13179  return retval;
13180 }
13181 
13182 /*!******************************************************************************
13183 * \brief Send a p_config command to reconfigure decoding ppu params.
13184 *
13185 * \param ni_session_context_t p_session_ctx - xcoder Context
13186 * \param ni_xcoder_params_t p_param - xcoder Params
13187 * \param ni_ppu_config_t p_ppu_config - Struct ni_ppu_config
13188 *
13189 * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
13190 *******************************************************************************/
13192  ni_xcoder_params_t *p_param, ni_ppu_config_t *p_ppu_config)
13193 {
13194  int ret = 0, i = 0;
13195  if (!p_session_ctx || !p_param || !p_ppu_config)
13196  {
13198  return ret;
13199  }
13200  if (p_session_ctx->ppu_reconfig_pkt_pos != 0)
13201  {
13202  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s: Warning ignore ppu reconfig before last config done!\n", __func__);
13203  return 0;
13204  }
13205 
13206  // check fw revision
13207  if (ni_cmp_fw_api_ver(
13208  (char*) &p_session_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
13209  "6sF") < 0)
13210  {
13211  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s: not supported on device with FW API version < 6sF\n", __func__);
13213  }
13214 
13215  if (NI_CODEC_FORMAT_H264 != p_session_ctx->codec_format &&
13216  NI_CODEC_FORMAT_H265 != p_session_ctx->codec_format)
13217  {
13218  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): only supported for h264 and h265 decoder\n", __func__);
13220  }
13221 
13222  ni_decoder_input_params_t *p_dec_input_param = &(p_param->dec_input_params);
13223  if (p_dec_input_param->hwframes != 1)
13224  {
13225  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): only supported for hw mode\n", __func__);
13227  }
13228  if (!p_dec_input_param->disable_adaptive_buffers)
13229  {
13230  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): not supported when disable_adaptive_buffers is disabled\n", __func__);
13232  }
13233  if (p_dec_input_param->mcmode)
13234  {
13235  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): not supported when MulticoreJointMode is enabled\n", __func__);
13237  }
13238  if (p_dec_input_param->enable_out1 == 0 &&
13239  p_ppu_config->ppu_set_enable & (0x01 << 1))
13240  {
13241  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): Error reconfig ppu1 while ppu1 is not enabled\n", __func__);
13243  }
13244  if (p_dec_input_param->enable_out2 == 0 &&
13245  p_ppu_config->ppu_set_enable & (0x01 << 2))
13246  {
13247  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): Error reconfig ppu2 while ppu2 is not enabled\n", __func__);
13249  }
13250  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
13251  {
13252  if (p_ppu_config->ppu_set_enable & (0x01 << i))
13253  {
13254  if (p_ppu_config->ppu_w[i] > NI_MAX_RESOLUTION_WIDTH ||
13255  p_ppu_config->ppu_h[i] > NI_MAX_RESOLUTION_HEIGHT ||
13256  p_ppu_config->ppu_w[i] < NI_MIN_RESOLUTION_WIDTH_SCALER ||
13257  p_ppu_config->ppu_h[i] < NI_MIN_RESOLUTION_WIDTH_SCALER)
13258  {
13259  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): ppu[%d] width x height %ux%u "
13260  "out of range\n", __func__, i, p_ppu_config->ppu_w[i], p_ppu_config->ppu_h[i]);
13262  return ret;
13263  }
13264  if ((p_ppu_config->ppu_w[i] & 1) || (p_ppu_config->ppu_h[i] & 1))
13265  {
13266  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): ppu[%d] wxh %dx%d not align to 2!\n",
13267  __func__, i, p_ppu_config->ppu_w[i], p_ppu_config->ppu_h[i]);
13269  return ret;
13270  }
13271  }
13272  }
13274  p_session_ctx, p_ppu_config, sizeof(ni_ppu_config_t));
13275  if (ret == NI_RETCODE_SUCCESS)
13276  {
13277  p_session_ctx->ppu_reconfig_pkt_pos = p_session_ctx->pkt_num;
13278  }
13279  return ret;
13280 }
_ni_ppu_config
Definition: ni_device_api.h:1428
XCODER_TEST_RECONF_LTR_INTERVAL_API
@ XCODER_TEST_RECONF_LTR_INTERVAL_API
Definition: ni_device_api.h:1801
NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
Definition: ni_device_api.h:1902
_ni_xcoder_params::reconf_demo_mode
int reconf_demo_mode
Definition: ni_device_api.h:2805
CONFIG_INSTANCE_SetScalerWatermarkPara_W
#define CONFIG_INSTANCE_SetScalerWatermarkPara_W(sid, instance)
Definition: ni_nvme.h:831
NI_MAX_FRAMERATE
#define NI_MAX_FRAMERATE
Definition: ni_device_api.h:118
ni_device_alloc_and_get_firmware_logs
ni_retcode_t ni_device_alloc_and_get_firmware_logs(ni_session_context_t *p_ctx, void **p_log_buffer, bool gen_log_file)
Allocate log buffer if needed and retrieve firmware logs from device.
Definition: ni_device_api.c:11902
_ni_encoder_cfg_params::enable_mb_level_rc
int enable_mb_level_rc
Definition: ni_device_api.h:2438
_ni_long_term_ref::use_long_term_ref
uint8_t use_long_term_ref
Definition: ni_device_api.h:704
NI_ENC_PARAM_ROI_DEMO_MODE
#define NI_ENC_PARAM_ROI_DEMO_MODE
Definition: ni_device_api.h:2101
_ni_encoder_cfg_params::frame_rate
int frame_rate
Definition: ni_device_api.h:2293
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
Definition: ni_device_api.h:289
NI_XCODER_CLOSE_STATE
@ NI_XCODER_CLOSE_STATE
Definition: ni_device_api.h:251
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:11940
_ni_xcoder_params::fps_denominator
uint32_t fps_denominator
Definition: ni_device_api.h:2793
NI_ENC_PARAM_LINK_FRAME_MAX_INTRA_RATIO
#define NI_ENC_PARAM_LINK_FRAME_MAX_INTRA_RATIO
Definition: ni_device_api.h:2286
NI_PIX_FMT_UYVY422
@ NI_PIX_FMT_UYVY422
Definition: ni_device_api.h:277
ni_encoder_session_read_stream_header
int ni_encoder_session_read_stream_header(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data)
Read encoder stream header from the device.
Definition: ni_device_api.c:11407
ni_lat_meas.h
Utility definitions for measuring frame/packet processing time in NETINT video processing devices.
NI_ENC_PARAM_AV1_ERROR_RESILIENT_MODE
#define NI_ENC_PARAM_AV1_ERROR_RESILIENT_MODE
Definition: ni_device_api.h:2233
ni_send_to_target
ni_retcode_t ni_send_to_target(ni_session_context_t *p_ctx, niFrameSurface1_t *source, uint64_t ui64DestAddr, uint32_t ui32FrameSize)
Definition: ni_device_api_priv.c:18844
_ni_xcoder_params::luma_linesize
int luma_linesize
Definition: ni_device_api.h:2860
ni_pthread_mutex_unlock
int ni_pthread_mutex_unlock(ni_pthread_mutex_t *mutex)
thread mutex unlock
Definition: ni_util.c:4708
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0
Definition: ni_device_api.h:1905
NI_PIX_FMT_BGRA
@ NI_PIX_FMT_BGRA
Definition: ni_device_api.h:270
_ni_scaler_input_params_t::output_height
int32_t output_height
Definition: ni_device_api.h:2621
_ni_session_context::force_idr_frame
int force_idr_frame
Definition: ni_device_api.h:1630
NI_CODEC_FORMAT_JPEG
@ NI_CODEC_FORMAT_JPEG
Definition: ni_device_api.h:927
_ni_encoder_cfg_params::ver_offset
int ver_offset
Definition: ni_device_api.h:2452
NI_DEC_PARAM_SCALE_0_RES_CEIL
#define NI_DEC_PARAM_SCALE_0_RES_CEIL
Definition: ni_device_api.h:2532
NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
@ NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
Definition: ni_device_api.h:579
ni_pthread_cond_init
int ni_pthread_cond_init(ni_pthread_cond_t *cond, const ni_pthread_condattr_t *attr)
initialize condition variables
Definition: ni_util.c:4802
NI_ENC_PARAM_ZEROCOPY_MODE
#define NI_ENC_PARAM_ZEROCOPY_MODE
Definition: ni_device_api.h:2240
_ni_device_info::fw_rev
uint8_t fw_rev[8]
Definition: ni_rsrc_api.h:115
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:4079
ni_scaler_set_params
ni_retcode_t ni_scaler_set_params(ni_session_context_t *p_ctx, ni_scaler_params_t *p_params)
Set parameters on the device for the 2D engine.
Definition: ni_device_api.c:8831
ni_device_get_ddr_configuration
ni_retcode_t ni_device_get_ddr_configuration(ni_session_context_t *p_ctx)
Get DDR configuration of Quadra device.
Definition: ni_device_api_priv.c:18272
ni_encoder_session_write
int ni_encoder_session_write(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
Send a YUV p_frame to encoder.
Definition: ni_device_api_priv.c:4118
ni_device_capability_query
NI_DEPRECATED ni_retcode_t ni_device_capability_query(ni_device_handle_t device_handle, ni_device_capability_t *p_cap)
Query device and return device capability structure This function had been replaced by ni_device_capa...
Definition: ni_device_api.c:598
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1921
NI_DEC_PARAM_SKIP_PTS_GUESS
#define NI_DEC_PARAM_SKIP_PTS_GUESS
Definition: ni_device_api.h:2554
NI_MAX_RESOLUTION_HEIGHT
#define NI_MAX_RESOLUTION_HEIGHT
Definition: ni_device_api.h:103
_ni_session_context::hevc_sub_ctu_roi_buf
uint8_t * hevc_sub_ctu_roi_buf
Definition: ni_device_api.h:1617
_ni_decoder_input_params_t::mcmode
int mcmode
Definition: ni_device_api.h:2567
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:5667
NI_DEVICE_TYPE_ENCODER
@ NI_DEVICE_TYPE_ENCODER
Definition: ni_defs.h:361
NI_ENC_PARAM_MAX_FRAME_SIZE_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_LOW_DELAY
Definition: ni_device_api.h:2189
NI_DEC_PARAM_SCALE_2_RES_CEIL
#define NI_DEC_PARAM_SCALE_2_RES_CEIL
Definition: ni_device_api.h:2534
_ni_frame::separate_start
uint8_t separate_start
Definition: ni_device_api.h:2777
ni_strerror
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
Definition: ni_util.c:652
g_xcoder_log_names
const char *const g_xcoder_log_names[NI_XCODER_LOG_NAMES_ARRAY_LEN]
Definition: ni_device_api.c:71
XCODER_TEST_RECONF_CRF_FLOAT
@ XCODER_TEST_RECONF_CRF_FLOAT
Definition: ni_device_api.h:1791
NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
#define NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:2119
_ni_p2p_sgl_t
Definition: ni_defs.h:417
NI_MIN_MAX_NUM_MERGE
#define NI_MIN_MAX_NUM_MERGE
Definition: ni_device_api.h:166
_ni_frame::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2737
NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
#define NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
Definition: ni_device_api.h:2272
_ni_network_data
Definition: ni_device_api.h:1376
_ni_xcoder_params::dolby_vision_profile
int dolby_vision_profile
Definition: ni_device_api.h:2813
_ni_session_context::ltr_interval
int32_t ltr_interval
Definition: ni_device_api.h:1632
NI_DEC_PARAM_SCALE_0
#define NI_DEC_PARAM_SCALE_0
Definition: ni_device_api.h:2526
_ni_resolution::chroma_linesize
int32_t chroma_linesize
Definition: ni_device_api_priv.h:692
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1972
_ni_session_context::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:1624
_ni_decoder_input_params_t::error_ratio_threshold
int error_ratio_threshold
Definition: ni_device_api.h:2603
NI_ENC_PARAM_CONF_WIN_RIGHT
#define NI_ENC_PARAM_CONF_WIN_RIGHT
Definition: ni_device_api.h:2139
ni_device_config_qos_op
ni_retcode_t ni_device_config_qos_op(ni_device_handle_t device_handle, ni_device_handle_t device_handle_t, uint32_t over_provision)
Send qos over provisioning mode to target namespace with specified logic block address.
Definition: ni_device_api.c:2092
ni_ai_config_network_binary
ni_retcode_t ni_ai_config_network_binary(ni_session_context_t *p_ctx, ni_network_data_t *p_network, const char *file)
configure a network context based with the network binary
Definition: ni_device_api.c:9722
_ni_thread_arg_struct_t::p_mutex
ni_pthread_mutex_t * p_mutex
Definition: ni_device_api.h:1280
NI_ENC_PARAM_TOL_RC_INTRA
#define NI_ENC_PARAM_TOL_RC_INTRA
Definition: ni_device_api.h:2201
_ni_encoder_cfg_params::skip_frame_interval
int skip_frame_interval
Definition: ni_device_api.h:2474
ni_pix_fmt_t
ni_pix_fmt_t
Definition: ni_device_api.h:263
NI_EC_POLICY_SKIP
#define NI_EC_POLICY_SKIP
Definition: ni_device_api.h:333
QUERY_GET_NVME_STATUS_R
#define QUERY_GET_NVME_STATUS_R
Definition: ni_nvme.h:790
ni_strncat
ni_retcode_t ni_strncat(char *dest, size_t dmax, const char *src, size_t slen)
Definition: ni_util.c:803
NI_XCODER_PRESET_NAME_CUSTOM
#define NI_XCODER_PRESET_NAME_CUSTOM
Definition: ni_device_api.h:2957
ni_enc_avc_roi_custom_map_t
union _ni_enc_avc_roi_custom_map ni_enc_avc_roi_custom_map_t
encoder AVC ROI custom map (1 MB = 8bits)
_ni_encoder_cfg_params::enable_dynamic_32x32_merge
int enable_dynamic_32x32_merge
Definition: ni_device_api.h:2406
_ni_encoder_cfg_params::hor_offset
int hor_offset
Definition: ni_device_api.h:2451
_ni_encoder_cfg_params::inLoopDSRatio
int inLoopDSRatio
Definition: ni_device_api.h:2389
NI_ENC_PARAM_GET_PSNR_MODE
#define NI_ENC_PARAM_GET_PSNR_MODE
Definition: ni_device_api.h:2270
ni_rsrc_free_device_pool
void ni_rsrc_free_device_pool(ni_device_pool_t *p_device_pool)
Free all resources taken by the device pool.
Definition: ni_rsrc_api.cpp:2668
NI_ENC_PARAM_LTR_REF_INTERVAL
#define NI_ENC_PARAM_LTR_REF_INTERVAL
Definition: ni_device_api.h:2193
XCODER_TEST_RECONF_END
@ XCODER_TEST_RECONF_END
Definition: ni_device_api.h:1811
NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2262
XCODER_TEST_CRF_API
@ XCODER_TEST_CRF_API
Definition: ni_device_api.h:1806
_ni_enc_avc_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:883
NI_ENC_PARAM_INTRA_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_REFRESH_MODE
Definition: ni_device_api.h:2155
ni_decoder_session_read_desc
ni_retcode_t ni_decoder_session_read_desc(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
Retrieve a hw desc p_frame from decoder.
Definition: ni_device_api_priv.c:14490
NI_XCODER_LOG_NAME_WARN
#define NI_XCODER_LOG_NAME_WARN
Definition: ni_device_api.h:2961
NI_MAX_DYNAMIC_MERGE
#define NI_MAX_DYNAMIC_MERGE
Definition: ni_device_api.h:161
NI_ENC_PARAM_CONF_WIN_LEFT
#define NI_ENC_PARAM_CONF_WIN_LEFT
Definition: ni_device_api.h:2138
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:3574
OPT
#define OPT(STR)
NI_ENC_GOP_PARAMS_G5_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G5_PIC_TYPE
Definition: ni_device_api.h:1948
NI_ENC_PARAM_TRANS_RATE
#define NI_ENC_PARAM_TRANS_RATE
Definition: ni_device_api.h:2141
NI_DEC_PARAM_PKT_PTS_UNCHANGE
#define NI_DEC_PARAM_PKT_PTS_UNCHANGE
Definition: ni_device_api.h:2555
_ni_decoder_input_params_t::enable_ppu_scale_adapt
int enable_ppu_scale_adapt
Definition: ni_device_api.h:2590
_ni_encoder_cfg_params::pbRatio
float pbRatio
Definition: ni_device_api.h:2459
NI_ENC_PARAM_DISABLE_AV1_TIMING_INFO
#define NI_ENC_PARAM_DISABLE_AV1_TIMING_INFO
Definition: ni_device_api.h:2288
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
Definition: ni_device_api.h:1971
ni_scaler_config_frame
ni_retcode_t ni_scaler_config_frame(ni_session_context_t *p_ctx, ni_frame_config_t *p_cfg)
config a frame in the scaler
Definition: ni_device_api_priv.c:5820
_ni_decoder_input_params_t::enable_out1
int enable_out1
Definition: ni_device_api.h:2565
_ni_network_layer_info::in_param
ni_network_layer_params_t * in_param
Definition: ni_device_api.h:1367
_ni_encoder_cfg_params::vbvBufferReencode
int vbvBufferReencode
Definition: ni_device_api.h:2497
_ni_session_context::nb_rois
int nb_rois
Definition: ni_device_api.h:1611
_ni_session_context::xcoder_state
uint32_t xcoder_state
Definition: ni_device_api.h:1598
NI_ENC_BLOCK_RC_SIZE
#define NI_ENC_BLOCK_RC_SIZE
Definition: ni_device_api.h:2204
XCODER_TEST_RECONF_MAX_FRAME_SIZE
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE
Definition: ni_device_api.h:1788
_ni_xcoder_params::padding
int padding
Definition: ni_device_api.h:2808
NI_ENC_PARAM_ENABLE_CPU_AFFINITY
#define NI_ENC_PARAM_ENABLE_CPU_AFFINITY
Definition: ni_device_api.h:2290
_ni_encoder_cfg_params::enable_filler
int enable_filler
Definition: ni_device_api.h:2430
ni_rsrc_get_device_context
LIB_API ni_device_context_t * ni_rsrc_get_device_context(ni_device_type_t type, int guid)
Allocates and returns a pointer to ni_device_context_t struct based on provided device_type and guid....
NI_PARAM_AV1_MAX_AREA
#define NI_PARAM_AV1_MAX_AREA
Definition: ni_device_api.h:149
_ni_session_context::force_low_delay
bool force_low_delay
Definition: ni_device_api.h:1729
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1968
ni_config_instance_hvsplus
ni_retcode_t ni_config_instance_hvsplus(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:16565
ni_frame_buffer_alloc_nv
ni_retcode_t ni_frame_buffer_alloc_nv(ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int extra_len, bool alignment_2pass_wa)
Allocate memory for the frame buffer based on provided parameters taking into account pic line size a...
Definition: ni_device_api.c:3410
ni_ai_alloc_dst_frame
ni_retcode_t ni_ai_alloc_dst_frame(ni_session_context_t *p_ctx, niFrameSurface1_t *p_out_surface)
Definition: ni_device_api_priv.c:17880
_ni_instance_mgr_general_status::fw_share_mem_usage
uint8_t fw_share_mem_usage
Definition: ni_device_api_priv.h:94
NI_MAX_WIDTH
#define NI_MAX_WIDTH
Definition: ni_device_api.h:125
NI_ENC_GOP_PARAMS_G4_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G4_QP_OFFSET
Definition: ni_device_api.h:1930
NI_DEC_PARAM_LOW_DELAY
#define NI_DEC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2540
_ni_encoder_cfg_params::gopLowdelay
int gopLowdelay
Definition: ni_device_api.h:2378
NI_XCODER_LOG_NAME_FULL
#define NI_XCODER_LOG_NAME_FULL
Definition: ni_device_api.h:2964
NI_MIN_KEEP_ALIVE_TIMEOUT
#define NI_MIN_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:323
ni_device_multi_config_frame
ni_retcode_t ni_device_multi_config_frame(ni_session_context_t *p_ctx, ni_frame_config_t p_cfg_in[], int numInCfgs, ni_frame_config_t *p_cfg_out)
Configure the 2D engine to work based on provided parameters.
Definition: ni_device_api.c:9255
NI_DEC_PARAM_ENABLE_OUT_2
#define NI_DEC_PARAM_ENABLE_OUT_2
Definition: ni_device_api.h:2513
_ni_gop_rps::ref_pic_used
int ref_pic_used
Definition: ni_device_api.h:1992
_ni_device_extra_info::on_board_temp
int32_t on_board_temp
Definition: ni_rsrc_api.h:245
_ni_session_context::dev_xcoder_name
char dev_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1518
NI_ENC_NEW_RC_ENABLE
#define NI_ENC_NEW_RC_ENABLE
Definition: ni_device_api.h:2207
NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
#define NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
Definition: ni_device_api.h:2236
_ni_scaler_input_params_t::op
ni_scaler_opcode_t op
Definition: ni_device_api.h:2628
NI_INVALID_IO_SIZE
#define NI_INVALID_IO_SIZE
Definition: ni_defs.h:233
ni_device_session_query
ni_retcode_t ni_device_session_query(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query session data from the device - If device_type is valid, will query session data from specified ...
Definition: ni_device_api.c:1932
_ni_session_context::frame_time_q
void * frame_time_q
Definition: ni_device_api.h:1439
XCODER_TEST_RECONF_LTR_INTERVAL
@ XCODER_TEST_RECONF_LTR_INTERVAL
Definition: ni_device_api.h:1785
_ni_encoder_cfg_params::statistic_output_level
int statistic_output_level
Definition: ni_device_api.h:2471
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1882
ni_device_config_ns_qos
ni_retcode_t ni_device_config_ns_qos(ni_device_handle_t device_handle, uint32_t key, uint32_t value)
Send namespace num / Opmode and SRIOv index/value to the device with specified logic block address.
Definition: ni_device_api_priv.c:18634
netint_iocmd_issue_request::len
unsigned int len
Definition: ni_p2p_ioctl.h:75
NI_ENC_PARAM_MAX_NUM_MERGE
#define NI_ENC_PARAM_MAX_NUM_MERGE
Definition: ni_device_api.h:2122
NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
#define NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
Definition: ni_device_api.h:2263
XCODER_TEST_RECONF_FRAMERATE_API
@ XCODER_TEST_RECONF_FRAMERATE_API
Definition: ni_device_api.h:1803
_ni_decoder_input_params_t::ec_policy
int ec_policy
Definition: ni_device_api.h:2588
NI_ENC_PARAM_MAX_QP
#define NI_ENC_PARAM_MAX_QP
Definition: ni_device_api.h:2132
ni_device_api_priv.h
Private definitions used by ni_device_api.c for video processing tasks.
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0
Definition: ni_device_api.h:1950
_ni_frame::metadata_buffer_size
uint32_t metadata_buffer_size
Definition: ni_device_api.h:2766
_ni_decoder_input_params_t::skip_pts_guess
int skip_pts_guess
Definition: ni_device_api.h:2593
NI_ENC_PARAM_BITRATE
#define NI_ENC_PARAM_BITRATE
Definition: ni_device_api.h:2098
_ni_vui_hrd
Definition: ni_device_api.h:667
_ni_rc_min_max_qp::minQpI
int32_t minQpI
Definition: ni_device_api.h:719
_ni_encoder_cfg_params::temporal_layers_enable
int temporal_layers_enable
Definition: ni_device_api.h:2446
ni_clear_instance_buf
ni_retcode_t ni_clear_instance_buf(niFrameSurface1_t *surface)
clear a particular xcoder instance buffer/data
Definition: ni_device_api_priv.c:14438
NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
Definition: ni_device_api.h:2211
ni_device_close
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
Definition: ni_device_api.c:511
NI_NUM_OF_PIXELS_1080P
#define NI_NUM_OF_PIXELS_1080P
Definition: ni_device_api.h:79
_ni_session_context::fn
unsigned short fn
Definition: ni_device_api.h:1652
netint_iocmd_attach_rfence
Definition: ni_p2p_ioctl.h:80
_niFrameSurface1::ui16height
uint16_t ui16height
Definition: ni_device_api.h:2875
NI_DEVICE_TYPE_DECODER
@ NI_DEVICE_TYPE_DECODER
Definition: ni_defs.h:360
_ni_enc_avc_roi_custom_map::field
struct _ni_enc_avc_roi_custom_map::@5 field
SESSION_RUN_STATE_FLUSHING
@ SESSION_RUN_STATE_FLUSHING
Definition: ni_device_api.h:1194
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1880
NI_ENC_PARAM_ALLOCATE_STRAEGY
#define NI_ENC_PARAM_ALLOCATE_STRAEGY
Definition: ni_device_api.h:2275
ni_force_idr_frame_type
ni_retcode_t ni_force_idr_frame_type(ni_session_context_t *p_ctx)
Force next frame to be IDR frame during encoding.
Definition: ni_device_api.c:10158
ni_scaler_p2p_frame_acquire
ni_retcode_t ni_scaler_p2p_frame_acquire(ni_session_context_t *p_ctx, niFrameSurface1_t *p_surface, int data_len)
Acquire the scaler P2P DMA buffer for read/write.
Definition: ni_device_api.c:11202
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1912
_ni_session_context::roi_side_data_size
int roi_side_data_size
Definition: ni_device_api.h:1608
NI_ENC_PARAM_CU_SIZE_MODE
#define NI_ENC_PARAM_CU_SIZE_MODE
Definition: ni_device_api.h:2121
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
Definition: ni_device_api.h:1805
NI_MIN_INTRA_QP_DELTA
#define NI_MIN_INTRA_QP_DELTA
Definition: ni_device_api.h:170
_ni_session_context::input_frame_fifo
ni_input_frame input_frame_fifo[120]
encoder:calculate PSNR start
Definition: ni_device_api.h:1739
_ni_session_context::current_frame_delay
int current_frame_delay
Definition: ni_device_api.h:1723
_ni_scaler_watermark_params_t
Definition: ni_device_api.h:2649
NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
Definition: ni_device_api.h:1887
ni_instance_mgr_general_status_t
struct _ni_instance_mgr_general_status ni_instance_mgr_general_status_t
_ni_session_context::session_id
uint32_t session_id
Definition: ni_device_api.h:1510
ni_strcpy
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition: ni_util.c:449
ni_scaler_session_read_hwdesc
ni_retcode_t ni_scaler_session_read_hwdesc(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
read a hardware descriptor from a scaler session
Definition: ni_device_api_priv.c:16081
_ni_xcoder_params::source_width
int source_width
Definition: ni_device_api.h:2797
ni_rsrc_lock_and_open
int ni_rsrc_lock_and_open(int device_type, ni_lock_handle_t *lock)
lock a file lock and open a session on a device
Definition: ni_rsrc_api.cpp:2699
NI_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_RETCODE_ERROR_GET_DEVICE_POOL
Definition: ni_defs.h:520
NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
#define NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
Definition: ni_device_api.h:2557
NI_PARAM_AV1_MAX_WIDTH
#define NI_PARAM_AV1_MAX_WIDTH
Definition: ni_device_api.h:147
NI_MAX_PACKET_SZ
#define NI_MAX_PACKET_SZ
Definition: ni_defs.h:239
NI_ENC_PARAM_GDR_DURATION
#define NI_ENC_PARAM_GDR_DURATION
Definition: ni_device_api.h:2180
_ni_input_frame::usable
int8_t usable
Definition: ni_device_api.h:1418
ni_reconfig_intraprd
ni_retcode_t ni_reconfig_intraprd(ni_session_context_t *p_ctx, int32_t intra_period)
Reconfigure intraPeriod dynamically during encoding.
Definition: ni_device_api.c:10075
_ni_decoder_input_params_t::enable_ppu_scale_limit
int enable_ppu_scale_limit
Definition: ni_device_api.h:2591
_ni_scaler_input_params_t::out_rec_height
int32_t out_rec_height
Definition: ni_device_api.h:2623
NI_SCALER_OPCODE_WATERMARK
@ NI_SCALER_OPCODE_WATERMARK
Definition: ni_defs.h:596
_ni_encoder_cfg_params::ltrRefInterval
int ltrRefInterval
Definition: ni_device_api.h:2339
_ni_session_context::target_bitrate
int32_t target_bitrate
Definition: ni_device_api.h:1629
_ni_session_context::mutex_initialized
bool mutex_initialized
Definition: ni_device_api.h:1701
ni_query_vf_ns_id
ni_retcode_t ni_query_vf_ns_id(ni_device_handle_t device_handle, ni_device_vf_ns_id_t *p_dev_ns_vf, uint8_t fw_rev[])
Query VF and NS id from device.
Definition: ni_device_api.c:11698
ni_device_session_update_framepool
ni_retcode_t ni_device_session_update_framepool(ni_session_context_t *p_ctx, uint32_t pool_size)
Sends frame pool change info to device.
Definition: ni_device_api.c:8772
ni_config_instance_network_binary
ni_retcode_t ni_config_instance_network_binary(ni_session_context_t *p_ctx, void *nb_data, uint32_t nb_size)
Definition: ni_device_api_priv.c:16293
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:11497
NI_ENC_PARAM_CONF_WIN_TOP
#define NI_ENC_PARAM_CONF_WIN_TOP
Definition: ni_device_api.h:2136
_ni_session_context::netint_fd
int netint_fd
Definition: ni_device_api.h:1648
QOS_OP_CONFIG_REC_OP_CODE
@ QOS_OP_CONFIG_REC_OP_CODE
Definition: ni_device_api.h:240
NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
#define NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
Definition: ni_device_api.h:2250
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
Definition: ni_device_api.h:1984
NI_DEC_PARAM_ENABLE_CPU_AFFINITY
#define NI_DEC_PARAM_ENABLE_CPU_AFFINITY
Definition: ni_device_api.h:2562
NI_PIX_FMT_YUV420P
@ NI_PIX_FMT_YUV420P
Definition: ni_device_api.h:265
NI_DEC_PARAM_FORCE_8BIT_1
#define NI_DEC_PARAM_FORCE_8BIT_1
Definition: ni_device_api.h:2515
NI_ENC_PARAM_BITRATE_MODE
#define NI_ENC_PARAM_BITRATE_MODE
Definition: ni_device_api.h:2258
NI_EC_POLICY_IGNORE
#define NI_EC_POLICY_IGNORE
Definition: ni_device_api.h:332
_ni_rc_min_max_qp
Definition: ni_device_api.h:717
_ni_resolution
Definition: ni_device_api_priv.h:680
NI_ENC_PARAM_COLOR_PRIMARY
#define NI_ENC_PARAM_COLOR_PRIMARY
Definition: ni_device_api.h:2221
ni_device_type_t
ni_device_type_t
Definition: ni_defs.h:355
NI_ENC_PARAM_LONG_TERM_REFERENCE_ENABLE
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_ENABLE
Definition: ni_device_api.h:2209
_niFrameSurface1::ui32nodeAddress
uint32_t ui32nodeAddress
Definition: ni_device_api.h:2876
_ni_session_context::isP2P
int32_t isP2P
Definition: ni_device_api.h:1647
_ni_encoder_cfg_params::enable_hvs_qp_scale
int enable_hvs_qp_scale
Definition: ni_device_api.h:2435
NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
#define NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
Definition: ni_device_api.h:2129
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
Definition: ni_device_api.h:1896
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:2135
NI_XCODER_READ_STATE
@ NI_XCODER_READ_STATE
Definition: ni_device_api.h:250
_ni_encoder_cfg_params::trans_rate
int trans_rate
Definition: ni_device_api.h:2437
_ni_thread_arg_struct_t::close_thread
bool close_thread
Definition: ni_device_api.h:1275
NI_INVALID_HWID
#define NI_INVALID_HWID
Definition: ni_defs.h:232
_ni_session_data_io::packet
ni_packet_t packet
Definition: ni_device_api.h:2948
NI_MAX_RESOLUTION_RGBA_WIDTH
#define NI_MAX_RESOLUTION_RGBA_WIDTH
Definition: ni_device_api.h:105
_ni_xcoder_params::enable2PassGop
int enable2PassGop
Definition: ni_device_api.h:2858
NI_ENC_GOP_PARAMS_G7_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G7_PIC_TYPE
Definition: ni_device_api.h:1978
_ni_frame::src_codec
ni_codec_format_t src_codec
Definition: ni_device_api.h:2674
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
Definition: ni_device_api.h:1892
_ni_session_context::ltr_to_set
ni_long_term_ref_t ltr_to_set
Definition: ni_device_api.h:1631
NI_DEC_PARAM_SCALE_1
#define NI_DEC_PARAM_SCALE_1
Definition: ni_device_api.h:2527
NI_ENC_PARAM_NO_MBTREE
#define NI_ENC_PARAM_NO_MBTREE
Definition: ni_device_api.h:2249
_ni_encoder_cfg_params::crf_max_iframe_enable
int crf_max_iframe_enable
Definition: ni_device_api.h:2478
NI_MIN_DYNAMIC_MERGE
#define NI_MIN_DYNAMIC_MERGE
Definition: ni_device_api.h:162
XCODER_TEST_RECONF_SLICE_ARG
@ XCODER_TEST_RECONF_SLICE_ARG
Definition: ni_device_api.h:1794
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:441
NI_XCODER_LOG_NAME_NONE
#define NI_XCODER_LOG_NAME_NONE
Definition: ni_device_api.h:2959
_ni_session_context::active_video_width
uint32_t active_video_width
Definition: ni_device_api.h:1579
NI_ENC_PARAM_CROP_HEIGHT
#define NI_ENC_PARAM_CROP_HEIGHT
Definition: ni_device_api.h:2244
_ni_gop_params::poc_offset
int poc_offset
Definition: ni_device_api.h:1997
_ni_gop_params::qp_offset
int qp_offset
Definition: ni_device_api.h:1998
_ni_framerate::framerate_denom
int32_t framerate_denom
Definition: ni_device_api.h:714
NI_DEVICE_TYPE_UPLOAD
@ NI_DEVICE_TYPE_UPLOAD
Definition: ni_defs.h:367
ni_device_open
ni_device_handle_t ni_device_open(const char *p_dev, uint32_t *p_max_io_size_out)
Open device and return device device_handle if successful.
Definition: ni_device_api.c:366
_ni_decoder_input_params_t::enable_user_data_sei_passthru
int enable_user_data_sei_passthru
Definition: ni_device_api.h:2585
NI_ENC_PARAM_LTR_FIRST_GAP
#define NI_ENC_PARAM_LTR_FIRST_GAP
Definition: ni_device_api.h:2195
ni_ai_session_open
ni_retcode_t ni_ai_session_open(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:17446
NI_XCODER_HWDL_STATE
@ NI_XCODER_HWDL_STATE
Definition: ni_device_api.h:258
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:3544
ni_device_session_context_alloc_init
ni_session_context_t * ni_device_session_context_alloc_init(void)
Allocate and initialize a new ni_session_context_t struct.
Definition: ni_device_api.c:98
g_dev_handle
NI_DEPRECATED ni_device_handle_t g_dev_handle
Definition: ni_rsrc_api.cpp:64
_ni_session_context::domain
unsigned short domain
Definition: ni_device_api.h:1649
ni_reconfig_framerate
ni_retcode_t ni_reconfig_framerate(ni_session_context_t *p_ctx, ni_framerate_t *framerate)
Reconfigure framerate dynamically during encoding.
Definition: ni_device_api.c:10273
_ni_session_context::pool_type
ni_frame_pool_type_t pool_type
Definition: ni_device_api.h:1727
_ni_session_context::av_rois
ni_region_of_interest_t * av_rois
Definition: ni_device_api.h:1610
NI_DEC_PARAM_FORCE_8BIT_2
#define NI_DEC_PARAM_FORCE_8BIT_2
Definition: ni_device_api.h:2516
XCODER_TEST_RECONF_CRF
@ XCODER_TEST_RECONF_CRF
Definition: ni_device_api.h:1790
NI_FRAME_AUX_DATA_CRF
@ NI_FRAME_AUX_DATA_CRF
Definition: ni_device_api.h:587
NI_INVALID_SESSION_ID
#define NI_INVALID_SESSION_ID
Definition: ni_device_api.h:113
_ni_encoder_cfg_params::enable_ssim
int enable_ssim
Definition: ni_device_api.h:2441
ni_log_fl_fw_versions_t
struct _ni_log_fl_fw_versions ni_log_fl_fw_versions_t
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1
Definition: ni_device_api.h:1877
NI_MAX_CU_SIZE_MODE
#define NI_MAX_CU_SIZE_MODE
Definition: ni_device_api.h:158
NI_XCODER_LOG_NAME_INFO
#define NI_XCODER_LOG_NAME_INFO
Definition: ni_device_api.h:2962
_ni_xcoder_params::color_primaries
int color_primaries
Definition: ni_device_api.h:2832
_ni_encoder_cfg_params::enable_compensate_qp
int enable_compensate_qp
Definition: ni_device_api.h:2492
NI_ENC_PARAM_AV1_OP_LEVEL
#define NI_ENC_PARAM_AV1_OP_LEVEL
Definition: ni_device_api.h:2289
NI_ENC_PARAM_LOOK_AHEAD_DEPTH
#define NI_ENC_PARAM_LOOK_AHEAD_DEPTH
Definition: ni_device_api.h:2175
_ni_resolution::luma_linesize
int32_t luma_linesize
Definition: ni_device_api_priv.h:691
_ni_frame::total_start_len
uint32_t total_start_len
Definition: ni_device_api.h:2775
_ni_session_context::last_bitrate
int32_t last_bitrate
Definition: ni_device_api.h:1704
_ni_device_info::active_num_inst
uint32_t active_num_inst
Definition: ni_rsrc_api.h:128
ni_xcoder_session_query_detail
int ni_xcoder_session_query_detail(ni_session_context_t *p_ctx, ni_device_type_t device_type, void *detail_data, int ver)
Query current xcoder status.
Definition: ni_device_api_priv.c:3234
NI_ENC_PARAM_LTR_NEXT_INTERVAL
#define NI_ENC_PARAM_LTR_NEXT_INTERVAL
Definition: ni_device_api.h:2196
NI_DEC_CROP_MODE_AUTO
@ NI_DEC_CROP_MODE_AUTO
Definition: ni_device_api.h:942
NI_PARAM_MIN_WIDTH
#define NI_PARAM_MIN_WIDTH
Definition: ni_device_api.h:138
_ni_session_context::actual_video_width
uint32_t actual_video_width
Definition: ni_device_api.h:1583
XCODER_TEST_RECONF_VUI_HRD
@ XCODER_TEST_RECONF_VUI_HRD
Definition: ni_device_api.h:1780
ni_gettime_ns
uint64_t ni_gettime_ns(void)
Definition: ni_util.c:2618
_ni_encoder_cfg_params::chromaQpOffset
int chromaQpOffset
Definition: ni_device_api.h:2382
OPT2
#define OPT2(STR1, STR2)
_ni_frame::iovec
ni_iovec_t * iovec
Definition: ni_device_api.h:2784
NI_PIX_FMT_BGR0
@ NI_PIX_FMT_BGR0
Definition: ni_device_api.h:273
NI_KEEP_ALIVE_TIMEOUT
#define NI_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:2094
XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
Definition: ni_device_api.h:1789
ni_parse_customize_qpoffset_file
ni_retcode_t ni_parse_customize_qpoffset_file(const char *customize_file, int8_t qp_map[][NI_CUSTOMIZE_ROI_QP_NUM])
Definition: ni_device_api.c:4794
_ni_load_query::pcie_throughput
uint32_t pcie_throughput
Definition: ni_device_api.h:1217
NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
Definition: ni_device_api.h:1947
_ni_frameclone_desc
Definition: ni_device_api.h:1388
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1878
NI_EC_POLICY_LIMITED_ERROR
#define NI_EC_POLICY_LIMITED_ERROR
Definition: ni_device_api.h:335
_ni_xcoder_params::rootBufId
int rootBufId
Definition: ni_device_api.h:2851
ni_config_instance_set_decoder_ppu_params
ni_retcode_t ni_config_instance_set_decoder_ppu_params(ni_session_context_t *p_ctx, void *p_dec_ppu_config, int buffer_size)
Send a p_config command to configure decoding parameters.
Definition: ni_device_api_priv.c:15993
NETINT_IOCTL_ATTACH_RFENCE
#define NETINT_IOCTL_ATTACH_RFENCE
Definition: ni_p2p_ioctl.h:95
NI_MIN_CUSTOM_SEI_PASSTHRU
#define NI_MIN_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:326
ni_rsrc_api.h
Public definitions for managing NETINT video processing devices.
_ni_frame::p_start_buffer
uint8_t * p_start_buffer
Definition: ni_device_api.h:2772
ni_set_frame_ref_invalid
ni_retcode_t ni_set_frame_ref_invalid(ni_session_context_t *p_ctx, int32_t frame_num)
Set frame reference invalidation.
Definition: ni_device_api.c:10248
_ni_session_context::event_handle
ni_event_handle_t event_handle
Definition: ni_device_api.h:1604
XCODER_TEST_RECONF_FRAMERATE
@ XCODER_TEST_RECONF_FRAMERATE
Definition: ni_device_api.h:1787
NI_ENC_PARAM_RDO_QUANT
#define NI_ENC_PARAM_RDO_QUANT
Definition: ni_device_api.h:2172
ni_scaler_multi_watermark_params_t
struct _ni_scaler_multi_watermark_params_t ni_scaler_multi_watermark_params_t
NI_DEC_PARAM_OUT
#define NI_DEC_PARAM_OUT
Definition: ni_device_api.h:2511
NI_MAX_GOP_SIZE
#define NI_MAX_GOP_SIZE
Definition: ni_device_api.h:152
NI_MAX_FILTER_POOL_SIZE
#define NI_MAX_FILTER_POOL_SIZE
Definition: ni_defs.h:329
NI_ENC_GOP_PARAMS_G2_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G2_POC_OFFSET
Definition: ni_device_api.h:1899
_ni_frame::aux_data
ni_aux_data_t * aux_data[NI_MAX_NUM_AUX_DATA_PER_FRAME]
Definition: ni_device_api.h:2747
ni_pthread_cond_destroy
int ni_pthread_cond_destroy(ni_pthread_cond_t *cond)
destroy condition variables
Definition: ni_util.c:4821
_ni_device_info::fl_ver_nor_flash
uint8_t fl_ver_nor_flash[8]
Definition: ni_rsrc_api.h:112
NI_ENC_PARAM_STATIC_MMAP_THRESHOLD
#define NI_ENC_PARAM_STATIC_MMAP_THRESHOLD
Definition: ni_device_api.h:2235
NI_ENC_PARAM_CBR
#define NI_ENC_PARAM_CBR
Definition: ni_device_api.h:2162
ni_config_instance_set_scaler_params
ni_retcode_t ni_config_instance_set_scaler_params(ni_session_context_t *p_ctx, ni_scaler_params_t *p_params)
Send a p_config command to configure scaling parameters.
Definition: ni_device_api_priv.c:5430
ni_reconfig_crf
ni_retcode_t ni_reconfig_crf(ni_session_context_t *p_ctx, int32_t crf)
Reconfigure crf value dynamically during encoding.
Definition: ni_device_api.c:10467
ni_aux_data_type_t
enum _ni_frame_aux_data_type ni_aux_data_type_t
netint_iocmd_issue_request::dir
int dir
Definition: ni_p2p_ioctl.h:76
NI_ENC_GOP_PARAMS_G3_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G3_TEMPORAL_ID
Definition: ni_device_api.h:1917
NI_ENC_PARAM_ENABLE_AUD
#define NI_ENC_PARAM_ENABLE_AUD
Definition: ni_device_api.h:2176
_ni_encoder_cfg_params::enable_acq_limit
int enable_acq_limit
Definition: ni_device_api.h:2484
_ni_encoder_cfg_params::noMbtree
int noMbtree
Definition: ni_device_api.h:2455
XCODER_TEST_RECONF_INTRAPRD
@ XCODER_TEST_RECONF_INTRAPRD
Definition: ni_device_api.h:1779
ni_scaler_multi_config_frame
ni_retcode_t ni_scaler_multi_config_frame(ni_session_context_t *p_ctx, ni_frame_config_t p_cfg_in[], int numInCfgs, ni_frame_config_t *p_cfg_out)
config multiple frames in the scaler
Definition: ni_device_api_priv.c:5942
NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
#define NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
Definition: ni_device_api.h:2084
NI_ENC_PARAM_PRE_INTRA_HANDLING
#define NI_ENC_PARAM_PRE_INTRA_HANDLING
Definition: ni_device_api.h:2283
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:3856
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1495
ni_config_read_inout_layers
ni_retcode_t ni_config_read_inout_layers(ni_session_context_t *p_ctx, ni_network_data_t *p_network)
Definition: ni_device_api_priv.c:17173
_ni_frame::start_len
uint32_t start_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2774
ni_scaler_set_drawbox_params
ni_retcode_t ni_scaler_set_drawbox_params(ni_session_context_t *p_ctx, ni_scaler_drawbox_params_t *p_params)
Send a p_config command to configure scaling drawbox parameters.
Definition: ni_device_api.c:8861
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
Definition: ni_device_api.h:1969
NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
Definition: ni_device_api.h:2191
NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
Definition: ni_defs.h:516
_ni_scaler_input_params_t
Definition: ni_device_api.h:2609
_ni_encoder_cfg_params::roi_enable
int roi_enable
Definition: ni_device_api.h:2311
_ni_encoder_cfg_params::pastFrameMaxIntraRatio
int pastFrameMaxIntraRatio
Definition: ni_device_api.h:2502
ni_close_event
void ni_close_event(ni_event_handle_t event_handle)
Close event and release resources (Windows only)
Definition: ni_device_api.c:300
_ni_encoder_cfg_params::intra_period
int intra_period
Definition: ni_device_api.h:2314
_ni_device_pool::p_device_queue
ni_device_queue_t * p_device_queue
Definition: ni_rsrc_api.h:99
_ni_encoder_cfg_params::EnableRdoQuant
int EnableRdoQuant
Definition: ni_device_api.h:2356
NI_ENC_PARAM_ENABLE_IP_RATIO
#define NI_ENC_PARAM_ENABLE_IP_RATIO
Definition: ni_device_api.h:2253
_ni_encoder_cfg_params::spatialLayerBitrate
int spatialLayerBitrate[NI_MAX_SPATIAL_LAYERS]
Definition: ni_device_api.h:2504
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1983
_ni_xcoder_params::generate_enc_hdrs
int generate_enc_hdrs
Definition: ni_device_api.h:2809
_ni_decoder_input_params_t::min_packets_delay
bool min_packets_delay
Definition: ni_device_api.h:2596
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
Definition: ni_device_api.h:1941
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
Definition: ni_device_api.h:1911
_ni_frame::separate_metadata
uint8_t separate_metadata
Definition: ni_device_api.h:2768
_ni_session_context::reconfig_slice_arg
int16_t reconfig_slice_arg
Definition: ni_device_api.h:1736
ni_device_dec_session_flush
ni_retcode_t ni_device_dec_session_flush(ni_session_context_t *p_ctx)
Flush a decoder session to get ready to continue decoding. Note: this is different from ni_device_ses...
Definition: ni_device_api.c:1633
ni_uploader_frame_buffer_lock
ni_retcode_t ni_uploader_frame_buffer_lock(ni_session_context_t *p_upl_ctx, ni_frame_t *p_frame)
Lock a hardware P2P frame prior to encoding.
Definition: ni_device_api.c:10929
_ni_encoder_cfg_params::enable_pic_skip
int enable_pic_skip
Definition: ni_device_api.h:2424
netint_iocmd_export_dmabuf::bar
int bar
Definition: ni_p2p_ioctl.h:51
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0
Definition: ni_device_api.h:1965
ni_rsrc_update_record
void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx)
_ni_network_data::outset
ni_network_layer_offset_t * outset
Definition: ni_device_api.h:1384
_ni_network_perf_metrics
Definition: ni_device_api.h:1397
ni_device_temp_t
struct _ni_device_temp ni_device_temp_t
NI_EC_POLICY_BEST_EFFORT
#define NI_EC_POLICY_BEST_EFFORT
Definition: ni_device_api.h:334
_ni_encoder_cfg_params::use_recommend_enc_params
int use_recommend_enc_params
Definition: ni_device_api.h:2400
_ni_thread_arg_struct_t::p_buffer
void * p_buffer
Definition: ni_device_api.h:1279
ni_parse_name
int32_t ni_parse_name(const char *arg, const char *const *names, bool *b_error)
Parse name.
Definition: ni_util.c:2590
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:2745
NI_MAX_USE_RECOMMENDED_ENC_PARAMS
#define NI_MAX_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:163
NI_ENC_PARAM_ENABLE_DYNAMIC_16X16_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_16X16_MERGE
Definition: ni_device_api.h:2124
_ni_load_query::fw_share_mem_usage
uint32_t fw_share_mem_usage
Definition: ni_device_api.h:1223
_ni_gop_params::pic_type
int pic_type
Definition: ni_device_api.h:2001
NI_DEC_PARAM_SKIP_EXTRA_HEADERS
#define NI_DEC_PARAM_SKIP_EXTRA_HEADERS
Definition: ni_device_api.h:2561
_ni_encoder_cfg_params::min_qp
int min_qp
Definition: ni_device_api.h:2420
NI_MIN_GOP_SIZE
#define NI_MIN_GOP_SIZE
Definition: ni_device_api.h:153
_ni_encoder_change_params_t::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:1016
NI_FRAME_AUX_DATA_SLICE_ARG
@ NI_FRAME_AUX_DATA_SLICE_ARG
Definition: ni_device_api.h:603
NI_UPLOADER_FLAG_LM
#define NI_UPLOADER_FLAG_LM
Definition: ni_device_api.h:317
NI_ENC_PARAM_HIGH_TIER
#define NI_ENC_PARAM_HIGH_TIER
Definition: ni_device_api.h:2113
_ni_encoder_cfg_params::gop_preset_index
int gop_preset_index
Definition: ni_device_api.h:2305
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1940
_ni_encoder_cfg_params::max_qp
int max_qp
Definition: ni_device_api.h:2421
ni_scaler_alloc_frame
ni_retcode_t ni_scaler_alloc_frame(ni_session_context_t *p_ctx, int width, int height, int format, int options, int rectangle_width, int rectangle_height, int rectangle_x, int rectangle_y, int rgba_color, int frame_index)
allocate a frame in the scaler
Definition: ni_device_api_priv.c:5583
_ni_frame_config
Definition: ni_device_api.h:2885
_ni_encoder_cfg_params::ipRatio
float ipRatio
Definition: ni_device_api.h:2458
NI_PIX_FMT_BGRP
@ NI_PIX_FMT_BGRP
Definition: ni_device_api.h:274
NI_SCALER_FLAG_IO
#define NI_SCALER_FLAG_IO
Definition: ni_device_api.h:302
_ni_packet::av1_p_data
uint8_t * av1_p_data[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2922
_ni_encoder_cfg_params::blockRCSize
int blockRCSize
Definition: ni_device_api.h:2390
NI_DEC_PARAM_CROP_MODE_2
#define NI_DEC_PARAM_CROP_MODE_2
Definition: ni_device_api.h:2522
_ni_encoder_cfg_params::av1OpLevel
int av1OpLevel[NI_MAX_SPATIAL_LAYERS]
Definition: ni_device_api.h:2506
NETINT_IOCTL_EXPORT_DMABUF
#define NETINT_IOCTL_EXPORT_DMABUF
Definition: ni_p2p_ioctl.h:93
_ni_xcoder_params::roi_demo_mode
int roi_demo_mode
Definition: ni_device_api.h:2804
_ni_session_context::src_endian
int src_endian
Definition: ni_device_api.h:1523
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
Definition: ni_device_api.h:285
ni_query_nvme_status
ni_retcode_t ni_query_nvme_status(ni_session_context_t *p_ctx, ni_load_query_t *p_load_query)
Query NVMe load from the device.
Definition: ni_device_api.c:11636
_ni_session_context::low_delay_sync_mutex
ni_pthread_mutex_t low_delay_sync_mutex
Definition: ni_device_api.h:1695
_ni_encoder_cfg_params::intra_mb_refresh_mode
int intra_mb_refresh_mode
Definition: ni_device_api.h:2315
NI_ENC_PARAM_TOL_RC_INTER
#define NI_ENC_PARAM_TOL_RC_INTER
Definition: ni_device_api.h:2200
NI_MIN_RESOLUTION_WIDTH_SCALER
#define NI_MIN_RESOLUTION_WIDTH_SCALER
Definition: ni_device_api.h:96
QUERY_GET_EXTTRA_INFO_R
#define QUERY_GET_EXTTRA_INFO_R
Definition: ni_nvme.h:799
netint_iocmd_export_dmabuf::bus
int bus
Definition: ni_p2p_ioctl.h:48
ni_ai_config_hvsplus
ni_retcode_t ni_ai_config_hvsplus(ni_session_context_t *p_ctx, ni_network_data_t *p_network)
configure a hvsplus filter
Definition: ni_device_api.c:9814
_ni_encoder_cfg_params::vbv_buffer_size
int vbv_buffer_size
Definition: ni_device_api.h:2431
_ni_packet::av1_buffer_size
uint32_t av1_buffer_size[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2923
NI_ENC_GOP_PARAMS_G6_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G6_PIC_TYPE
Definition: ni_device_api.h:1963
_ni_frame::p_buffer
uint8_t * p_buffer
Definition: ni_device_api.h:2736
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
Definition: ni_device_api.h:2170
ni_reconfig_vbv_value
ni_retcode_t ni_reconfig_vbv_value(ni_session_context_t *p_ctx, int32_t vbvMaxRate, int32_t vbvBufferSize)
Reconfigure vbv buffer size and vbv max rate dynamically during encoding.
Definition: ni_device_api.c:10584
NI_ENC_INLOOP_DS_RATIO
#define NI_ENC_INLOOP_DS_RATIO
Definition: ni_device_api.h:2203
_ni_encoder_cfg_params::noHWMultiPassSupport
int noHWMultiPassSupport
Definition: ni_device_api.h:2456
NI_ENC_PARAM_CONF_WIN_BOTTOM
#define NI_ENC_PARAM_CONF_WIN_BOTTOM
Definition: ni_device_api.h:2137
_ni_encoder_cfg_params::gdrDuration
int gdrDuration
Definition: ni_device_api.h:2338
_ni_xcoder_params::video_full_range_flag
int video_full_range_flag
Definition: ni_device_api.h:2837
XCODER_TEST_RECONF_VBV
@ XCODER_TEST_RECONF_VBV
Definition: ni_device_api.h:1792
NI_VERSION_CHARACTER_COUNT
#define NI_VERSION_CHARACTER_COUNT
Definition: ni_device_api_priv.h:112
_ni_decoder_input_params_t::force_low_delay
bool force_low_delay
Definition: ni_device_api.h:2583
NI_EC_POLICY_BEST_EFFORT_OUT_DC
#define NI_EC_POLICY_BEST_EFFORT_OUT_DC
Definition: ni_device_api.h:336
_ni_encoder_cfg_params::aspectRatioWidth
int aspectRatioWidth
Definition: ni_device_api.h:2294
NI_RETCODE_INVALID_PARAM
@ NI_RETCODE_INVALID_PARAM
Definition: ni_defs.h:443
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3
Definition: ni_device_api.h:1881
_ni_session_context::avc_roi_map
ni_enc_avc_roi_custom_map_t * avc_roi_map
Definition: ni_device_api.h:1615
ni_decoder_session_write
int ni_decoder_session_write(ni_session_context_t *p_ctx, ni_packet_t *p_packet)
Send a video p_packet to decoder.
Definition: ni_device_api_priv.c:1821
ni_ai_session_write
ni_retcode_t ni_ai_session_write(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
Definition: ni_device_api_priv.c:16713
_ni_session_context::ppu_reconfig_pkt_pos
uint64_t ppu_reconfig_pkt_pos
Definition: ni_device_api.h:1759
_ni_scaler_input_params_t::input_height
int32_t input_height
Definition: ni_device_api.h:2613
_ni_session_context::buffered_frame_index
int16_t buffered_frame_index
Definition: ni_device_api.h:1747
NI_FRAME_BIG_ENDIAN
#define NI_FRAME_BIG_ENDIAN
Definition: ni_device_api.h:111
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1953
NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
#define NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
Definition: ni_device_api.h:2260
_ni_encoder_cfg_params::maxFrameSizeRatio
int maxFrameSizeRatio
Definition: ni_device_api.h:2298
_ni_decoder_input_params_t::enable_advanced_ec
int enable_advanced_ec
Definition: ni_device_api.h:2589
_ni_encoder_cfg_params::HDR10AveLight
int HDR10AveLight
Definition: ni_device_api.h:2325
_ni_encoder_cfg_params::rc
struct _ni_encoder_cfg_params::@16 rc
NI_ENC_PARAM_JPEG_QLEVEL
#define NI_ENC_PARAM_JPEG_QLEVEL
Definition: ni_device_api.h:2198
XCODER_TEST_INVALID_REF_FRAME
@ XCODER_TEST_INVALID_REF_FRAME
Definition: ni_device_api.h:1786
NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:324
NI_ENC_PARAM_DDR_PRIORITY_MODE
#define NI_ENC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2257
NI_ENC_PARAM_SPATIAL_LAYER_BITRATE
#define NI_ENC_PARAM_SPATIAL_LAYER_BITRATE
Definition: ni_device_api.h:2287
NI_ENC_PARAM_GOP_LOW_DELAY
#define NI_ENC_PARAM_GOP_LOW_DELAY
Definition: ni_device_api.h:2179
ni_decoder_session_read
int ni_decoder_session_read(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
Retrieve a YUV p_frame from decoder.
Definition: ni_device_api_priv.c:2317
_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:2579
_ni_encoder_cfg_params::cu_size_mode
int cu_size_mode
Definition: ni_device_api.h:2402
_ni_packet::av1_data_len
uint32_t av1_data_len[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2924
NI_ENC_PARAM_DOLBY_VISION_PROFILE
#define NI_ENC_PARAM_DOLBY_VISION_PROFILE
Definition: ni_device_api.h:2182
_ni_encoder_cfg_params::hrdEnable
int hrdEnable
Definition: ni_device_api.h:2357
ni_device_config_frame
ni_retcode_t ni_device_config_frame(ni_session_context_t *p_ctx, ni_frame_config_t *p_cfg)
Configure the 2D engine to work based on provided parameters.
Definition: ni_device_api.c:9209
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1524
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
Definition: ni_device_api.h:1800
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1938
NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
#define NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
Definition: ni_device_api.h:2163
_ni_session_context::reconfig_crf_decimal
int reconfig_crf_decimal
Definition: ni_device_api.h:1716
_ni_encoder_change_params_t
This is a data structure for encoding parameters that have changed.
Definition: ni_device_api.h:995
_ni_encoder_cfg_params::encMallocStrategy
int encMallocStrategy
Definition: ni_device_api.h:2490
NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2529
_ni_xcoder_params::log
int log
Definition: ni_device_api.h:2789
_ni_device_extra_info::power_consumption
uint32_t power_consumption
Definition: ni_rsrc_api.h:247
_ni_encoder_cfg_params::high_tier
int high_tier
Definition: ni_device_api.h:2398
_ni_session_context::mutex
ni_pthread_mutex_t mutex
Definition: ni_device_api.h:1595
_ni_encoder_cfg_params::max_num_merge
int max_num_merge
Definition: ni_device_api.h:2403
_ni_log_fl_fw_versions::last_ran_fl_version
uint8_t last_ran_fl_version[NI_VERSION_CHARACTER_COUNT]
Definition: ni_device_api_priv.h:116
_ni_gop_params::num_ref_pics
int num_ref_pics
Definition: ni_device_api.h:2002
_ni_packet::av1_buffer_index
int av1_buffer_index
Definition: ni_device_api.h:2925
_ni_decoder_input_params_t::crop_mode
int crop_mode[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2571
ni_config_instance_set_uploader_params
ni_retcode_t ni_config_instance_set_uploader_params(ni_session_context_t *p_ctx, uint32_t pool_size, uint32_t pool)
Send a p_config command to configure uploading parameters.
Definition: ni_device_api_priv.c:15767
_ni_aux_data::size
int size
Definition: ni_device_api.h:635
_ni_encoder_cfg_params::crf
int crf
Definition: ni_device_api.h:2323
_ni_load_query::pcie_load
uint32_t pcie_load
Definition: ni_device_api.h:1221
NI_ENC_PARAM_BASE_LAYER_ONLY
#define NI_ENC_PARAM_BASE_LAYER_ONLY
Definition: ni_device_api.h:2284
NI_ENC_REPEAT_HEADERS_FIRST_IDR
#define NI_ENC_REPEAT_HEADERS_FIRST_IDR
Definition: ni_device_api.h:2092
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1508
netint_iocmd_export_dmabuf
Definition: ni_p2p_ioctl.h:43
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1906
NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
Definition: ni_device_api.h:2125
_ni_device_info::hw_id
int hw_id
Definition: ni_rsrc_api.h:106
NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE
@ NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE
Definition: ni_device_api.h:599
ni_reconfig_crf2
ni_retcode_t ni_reconfig_crf2(ni_session_context_t *p_ctx, float crf)
Reconfigure crf float point value dynamically during encoding.
Definition: ni_device_api.c:10524
_ni_device_extra_info::composite_temp
int32_t composite_temp
Definition: ni_rsrc_api.h:244
_ni_xcoder_params::fps_number
uint32_t fps_number
Definition: ni_device_api.h:2792
NI_FRAME_AUX_DATA_VBV_MAX_RATE
@ NI_FRAME_AUX_DATA_VBV_MAX_RATE
Definition: ni_device_api.h:595
NI_DEC_PARAM_CROP_MODE_0
#define NI_DEC_PARAM_CROP_MODE_0
Definition: ni_device_api.h:2520
_ni_enc_quad_roi_custom_map::roiAbsQp_flag
uint8_t roiAbsQp_flag
Definition: ni_device_api.h:900
NI_MIN_BIN
#define NI_MIN_BIN
Definition: ni_device_api.h:177
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1897
NI_ENC_PARAM_IP_RATIO
#define NI_ENC_PARAM_IP_RATIO
Definition: ni_device_api.h:2252
NI_DEC_PARAM_MULTICORE_JOINT_MODE
#define NI_DEC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2538
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:4298
ni_scaler_input_frame_alloc
ni_retcode_t ni_scaler_input_frame_alloc(ni_session_context_t *p_ctx, ni_scaler_input_params_t scaler_params, niFrameSurface1_t *p_src_surface)
allocate device input frame by hw descriptor. This call won't actually allocate a frame but sends the...
Definition: ni_device_api.c:3346
NI_XCODER_OPEN_STATE
@ NI_XCODER_OPEN_STATE
Definition: ni_device_api.h:248
_ni_ppu_config::ppu_w
uint16_t ppu_w[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:1430
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1957
_ni_scaler_input_params_t::input_format
int input_format
Definition: ni_device_api.h:2611
_ni_xcoder_params::hdrEnableVUI
int hdrEnableVUI
Definition: ni_device_api.h:2819
NI_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:329
_ni_scaler_params_t
Definition: ni_device_api.h:2631
NI_ENC_GOP_PARAMS_G0_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G0_PIC_TYPE
Definition: ni_device_api.h:1873
_ni_scaler_input_params_t::out_rec_width
int32_t out_rec_width
Definition: ni_device_api.h:2622
NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
Definition: ni_defs.h:512
_ni_device_info::dev_name
char dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_rsrc_api.h:104
NI_VPU_ALIGN64
#define NI_VPU_ALIGN64(_x)
Definition: ni_device_api.h:346
_ni_encoder_cfg_params::enable_timecode
int enable_timecode
Definition: ni_device_api.h:2494
NI_ENC_GOP_PARAMS_G4_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G4_PIC_TYPE
Definition: ni_device_api.h:1933
NI_DEC_PARAM_ENABLE_OUT_1
#define NI_DEC_PARAM_ENABLE_OUT_1
Definition: ni_device_api.h:2512
_ni_session_context::reconfig_intra_period
int reconfig_intra_period
Definition: ni_device_api.h:1734
NI_ENC_PARAM_FORCE_FRAME_TYPE
#define NI_ENC_PARAM_FORCE_FRAME_TYPE
Definition: ni_device_api.h:2110
NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_MEM_ALOC
Definition: ni_defs.h:445
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:439
_ni_instance_mgr_general_status::pcie_throughput
uint8_t pcie_throughput
Definition: ni_device_api_priv.h:89
NI_FRAME_AUX_DATA_MAX_MIN_QP
@ NI_FRAME_AUX_DATA_MAX_MIN_QP
Definition: ni_device_api.h:583
ni_device_clone_hwframe
ni_retcode_t ni_device_clone_hwframe(ni_session_context_t *p_ctx, ni_frameclone_desc_t *p_frameclone_desc)
Copy the data of src hwframe to dst hwframe.
Definition: ni_device_api.c:9157
ni_populate_device_capability_struct
void ni_populate_device_capability_struct(ni_device_capability_t *p_cap, void *p_data, ni_device_handle_t device_handle, bool device_in_ctxt)
Get info from received xcoder capability.
Definition: ni_device_api_priv.c:7977
NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
Definition: ni_device_api.h:2192
NI_MAX_KEEP_ALIVE_TIMEOUT
#define NI_MAX_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:322
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_2
uint32_t sub_ctu_qp_2
Definition: ni_device_api.h:870
_ni_vui_hrd::colorPrimaries
int32_t colorPrimaries
Definition: ni_device_api.h:674
NI_MAX_DECODING_REFRESH_TYPE
#define NI_MAX_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:156
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_0
uint32_t sub_ctu_qp_0
Definition: ni_device_api.h:868
ni_uploader_frame_buffer_unlock
ni_retcode_t ni_uploader_frame_buffer_unlock(ni_session_context_t *p_upl_ctx, ni_frame_t *p_frame)
Unlock a hardware P2P frame after encoding.
Definition: ni_device_api.c:10990
SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
Definition: ni_device_api.h:1191
NI_FW_META_DATA_SZ
#define NI_FW_META_DATA_SZ
Definition: ni_defs.h:320
ni_nvme_send_write_cmd
int32_t ni_nvme_send_write_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose a io write command.
Definition: ni_nvme.c:660
_ni_session_context::fw_rev
uint8_t fw_rev[8]
Definition: ni_device_api.h:1655
NI_DEC_PARAM_SEMI_PLANAR_1
#define NI_DEC_PARAM_SEMI_PLANAR_1
Definition: ni_device_api.h:2518
ni_pthread_join
int ni_pthread_join(ni_pthread_t thread, void **value_ptr)
join with a terminated thread
Definition: ni_util.c:4773
_ni_network_data::output_num
uint32_t output_num
Definition: ni_device_api.h:1379
_ni_encoder_cfg_params::intra_mb_refresh_arg
int intra_mb_refresh_arg
Definition: ni_device_api.h:2316
SESSION_RUN_STATE_NORMAL
@ SESSION_RUN_STATE_NORMAL
Definition: ni_device_api.h:1190
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:3726
NI_ENC_GOP_PARAMS_G1_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G1_QP_OFFSET
Definition: ni_device_api.h:1885
NI_MAX_REF_PIC
#define NI_MAX_REF_PIC
Definition: ni_device_api.h:59
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:4018
NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
#define NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
Definition: ni_device_api.h:489
NI_ENC_PARAM_MIN_FRAMES_DELAY
#define NI_ENC_PARAM_MIN_FRAMES_DELAY
Definition: ni_device_api.h:2118
_ni_encoder_cfg_params::pps_init_qp
int pps_init_qp
Definition: ni_device_api.h:2461
ni_ai_session_query_metrics
ni_retcode_t ni_ai_session_query_metrics(ni_session_context_t *p_ctx, ni_network_perf_metrics_t *p_metrics)
Definition: ni_device_api_priv.c:18560
NI_RETCODE_PARAM_INVALID_VALUE
@ NI_RETCODE_PARAM_INVALID_VALUE
Definition: ni_defs.h:451
STRDUP
#define STRDUP(value)
NI_ENC_PARAM_MAX_CLL
#define NI_ENC_PARAM_MAX_CLL
Definition: ni_device_api.h:2173
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
Definition: ni_device_api.h:1907
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1891
_ni_encoder_cfg_params::gopSize
int gopSize
Definition: ni_device_api.h:2377
_ni_session_context::reconfig_vbv_buffer_size
int reconfig_vbv_buffer_size
Definition: ni_device_api.h:1718
_ni_session_context::framerate
ni_framerate_t framerate
Definition: ni_device_api.h:1634
ni_decoder_session_flush
ni_retcode_t ni_decoder_session_flush(ni_session_context_t *p_ctx)
Flush decoder output.
Definition: ni_device_api_priv.c:1593
_ni_session_context::pext_mutex
ni_pthread_mutex_t * pext_mutex
Definition: ni_device_api.h:1700
_ni_frame::iovec_num
uint32_t iovec_num
Definition: ni_device_api.h:2783
_ni_thread_arg_struct_t::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1277
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
Definition: ni_device_api.h:1924
_ni_decoder_input_params_t::crop_whxy
int crop_whxy[NI_MAX_NUM_OF_DECODER_OUTPUTS][4]
Definition: ni_device_api.h:2572
_ni_device_vf_ns_id::ns_id
uint16_t ns_id
Definition: ni_rsrc_api.h:232
NI_MAX_NUM_AUX_DATA_PER_FRAME
#define NI_MAX_NUM_AUX_DATA_PER_FRAME
Definition: ni_device_api.h:483
ni_scaler_dest_frame_alloc
ni_retcode_t ni_scaler_dest_frame_alloc(ni_session_context_t *p_ctx, ni_scaler_input_params_t scaler_params, niFrameSurface1_t *p_surface)
allocate device destination frame from scaler hwframe pool
Definition: ni_device_api.c:3311
_ni_encoder_cfg_params::qlevel
int qlevel
Definition: ni_device_api.h:2372
NI_MAX_SPATIAL_LAYERS
#define NI_MAX_SPATIAL_LAYERS
Definition: ni_device_api.h:182
NI_ERRNO_LEN
#define NI_ERRNO_LEN
Definition: ni_log.h:51
_ni_decoder_input_params_t::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2580
_ni_custom_gop_params::custom_gop_size
int custom_gop_size
Definition: ni_device_api.h:2088
XCODER_TEST_RECONF_OFF
@ XCODER_TEST_RECONF_OFF
Definition: ni_device_api.h:1777
_ni_scaler_input_params_t::rgba_color
uint32_t rgba_color
Definition: ni_device_api.h:2627
ni_device_config_namespace_num
ni_retcode_t ni_device_config_namespace_num(ni_device_handle_t device_handle, uint32_t namespace_num, uint32_t sriov_index)
Send namespace num and SRIOv index to the device with specified logic block address.
Definition: ni_device_api.c:2049
NI_PARAM_MAX_HEIGHT
#define NI_PARAM_MAX_HEIGHT
Definition: ni_device_api.h:139
_niFrameSurface1::ui16FrameIdx
uint16_t ui16FrameIdx
Definition: ni_device_api.h:2872
NI_ENC_PARAM_CACHE_ROI
#define NI_ENC_PARAM_CACHE_ROI
Definition: ni_device_api.h:2102
ni_encoder_session_open
ni_retcode_t ni_encoder_session_open(ni_session_context_t *p_ctx)
Open a xcoder encoder instance.
Definition: ni_device_api_priv.c:3267
_ni_encoder_cfg_params::HDR10dx2
int HDR10dx2
Definition: ni_device_api.h:2332
_ni_long_term_ref
Definition: ni_device_api.h:696
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:63
ni_rsrc_get_device_pool
LIB_API ni_device_pool_t * ni_rsrc_get_device_pool(void)
Create and return the allocated ni_device_pool_t struct.
_ni_vui_hrd::colorDescPresent
int32_t colorDescPresent
Definition: ni_device_api.h:670
NI_MAX_INTRA_QP
#define NI_MAX_INTRA_QP
Definition: ni_device_api.h:167
_ni_session_context::reconfig_vbv_max_rate
int reconfig_vbv_max_rate
Definition: ni_device_api.h:1719
NI_ENC_PARAM_SPATIAL_LAYERS
#define NI_ENC_PARAM_SPATIAL_LAYERS
Definition: ni_device_api.h:2276
NI_ENC_PARAM_INTRA_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_REFRESH_ARG
Definition: ni_device_api.h:2156
ni_hwframe_clone
ni_retcode_t ni_hwframe_clone(ni_session_context_t *p_ctx, ni_frameclone_desc_t *p_frameclone_desc)
Copy a src hw frame to a dst hw frame.
Definition: ni_device_api_priv.c:15676
ni_device_session_acquire
int ni_device_session_acquire(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
Acquire a P2P frame buffer from the hwupload session.
Definition: ni_device_api.c:10768
NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
Definition: ni_device_api.h:1949
NI_DEC_PARAM_CROP_PARAM_0
#define NI_DEC_PARAM_CROP_PARAM_0
Definition: ni_device_api.h:2523
NI_DEC_PARAM_CROP_PARAM_1
#define NI_DEC_PARAM_CROP_PARAM_1
Definition: ni_device_api.h:2524
_ni_encoder_cfg_params::HDR10wx
int HDR10wx
Definition: ni_device_api.h:2334
ni_query_extra_info
ni_retcode_t ni_query_extra_info(ni_device_handle_t device_handle, ni_device_extra_info_t *p_dev_extra_info, uint8_t fw_rev[])
Query CompositeTemp from device.
Definition: ni_device_api.c:11806
NI_ENC_PARAM_ENABLE_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_RATE_CONTROL
Definition: ni_device_api.h:2126
NI_ENC_PARAM_VBV_BUFFER_REENCODE
#define NI_ENC_PARAM_VBV_BUFFER_REENCODE
Definition: ni_device_api.h:2280
atof
#define atof(p_str)
Definition: ni_device_api.c:7339
_ni_xcoder_params::source_height
int source_height
Definition: ni_device_api.h:2802
NI_ENC_GOP_PARAMS_G5_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G5_QP_OFFSET
Definition: ni_device_api.h:1945
NI_APP_ENC_FRAME_META_DATA_SIZE
#define NI_APP_ENC_FRAME_META_DATA_SIZE
Definition: ni_defs.h:322
_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:2575
_ni_encoder_cfg_params::rcQpDeltaRange
int rcQpDeltaRange
Definition: ni_device_api.h:2394
_ni_encoder_change_params_t::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:1014
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:2598
XCODER_TEST_RECONF_BR_API
@ XCODER_TEST_RECONF_BR_API
Definition: ni_device_api.h:1796
_ni_encoder_cfg_params::hvsBaseMbComplexity
int hvsBaseMbComplexity
Definition: ni_device_api.h:2465
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:62
_ni_device_queue::xcoders
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
Definition: ni_rsrc_api.h:70
NI_MIN_CU_SIZE_MODE
#define NI_MIN_CU_SIZE_MODE
Definition: ni_device_api.h:159
IS_XCODER_DEVICE_TYPE
#define IS_XCODER_DEVICE_TYPE(t)
Definition: ni_defs.h:424
_ni_frame::ni_pict_type
ni_pic_type_t ni_pict_type
Definition: ni_device_api.h:2697
_ni_session_context::src_bit_depth
int src_bit_depth
Definition: ni_device_api.h:1522
_ni_ppu_config::ppu_set_enable
uint8_t ppu_set_enable
Definition: ni_device_api.h:1429
NI_FRAME_AUX_DATA_VUI
@ NI_FRAME_AUX_DATA_VUI
Definition: ni_device_api.h:556
ni_buf_pool_get_buffer
ni_buf_t * ni_buf_pool_get_buffer(ni_buf_pool_t *p_buffer_pool)
Definition: ni_util.c:1087
_ni_vui_hrd::colorTrc
int32_t colorTrc
Definition: ni_device_api.h:678
NI_MAX_RESOLUTION_WIDTH
#define NI_MAX_RESOLUTION_WIDTH
Definition: ni_device_api.h:102
_ni_framerate::framerate_num
int32_t framerate_num
Definition: ni_device_api.h:711
NI_VPU_ALIGN16
#define NI_VPU_ALIGN16(_x)
Definition: ni_device_api.h:344
ni_scaler_session_open
int ni_scaler_session_open(ni_session_context_t *p_ctx)
Open a xcoder scaler instance.
Definition: ni_device_api_priv.c:5122
GOP_PRESET_IDX_DEFAULT
@ GOP_PRESET_IDX_DEFAULT
Definition: ni_device_api_priv.h:319
_ni_encoder_cfg_params::HDR10maxluma
int HDR10maxluma
Definition: ni_device_api.h:2336
_ni_network_data::linfo
ni_network_layer_info_t linfo
Definition: ni_device_api.h:1380
_niFrameSurface1::ui16session_ID
uint16_t ui16session_ID
Definition: ni_device_api.h:2873
NI_SCALER_OPCODE_OVERLAY
@ NI_SCALER_OPCODE_OVERLAY
Definition: ni_defs.h:591
NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
@ NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
Definition: ni_defs.h:535
NI_MIN_DECODING_REFRESH_TYPE
#define NI_MIN_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:157
_ni_xcoder_params::cfg_enc_params
ni_encoder_cfg_params_t cfg_enc_params
Definition: ni_device_api.h:2841
NI_ENC_PARAM_RDO_LEVEL
#define NI_ENC_PARAM_RDO_LEVEL
Definition: ni_device_api.h:2171
ni_ai_packet_buffer_alloc
ni_retcode_t ni_ai_packet_buffer_alloc(ni_packet_t *p_packet, ni_network_data_t *p_network)
Allocate output layers memory for the packet buffer based on provided network.
Definition: ni_device_api.c:9945
NI_ENC_PARAM_PROFILE
#define NI_ENC_PARAM_PROFILE
Definition: ni_device_api.h:2111
ni_device_session_query_detail_v1
ni_retcode_t ni_device_session_query_detail_v1(ni_session_context_t *p_ctx, ni_device_type_t device_type, ni_instance_mgr_detail_status_v1_t *detail_data)
Query detail session data from the device - If device_type is valid, will query session data from spe...
Definition: ni_device_api.c:2012
_ni_xcoder_params::enableCpuAffinity
int enableCpuAffinity
Definition: ni_device_api.h:2867
_ni_encoder_cfg_params::vbv_max_rate
int vbv_max_rate
Definition: ni_device_api.h:2432
_ni_gop_params::qp_factor
float qp_factor
Definition: ni_device_api.h:1999
ni_buf_pool_return_buffer
void ni_buf_pool_return_buffer(ni_buf_t *buf, ni_buf_pool_t *p_buffer_pool)
Definition: ni_util.c:1148
_ni_xcoder_params::force_frame_type
int force_frame_type
Definition: ni_device_api.h:2816
_ni_gop_rps::ref_pic
int ref_pic
Definition: ni_device_api.h:1991
NI_XCODER_IDLE_STATE
@ NI_XCODER_IDLE_STATE
Definition: ni_device_api.h:247
NI_PIX_FMT_NV12
@ NI_PIX_FMT_NV12
Definition: ni_device_api.h:267
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:7357
XCODER_TEST_RECONF_INTRAPRD_API
@ XCODER_TEST_RECONF_INTRAPRD_API
Definition: ni_device_api.h:1797
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2734
ni_decoder_session_copy_internal
ni_retcode_t ni_decoder_session_copy_internal(ni_session_context_t *src_p_ctx, ni_session_context_t *dst_p_ctx)
Copy a xcoder decoder worker thread info.
Definition: ni_device_api_priv.c:13757
_ni_session_context::pixel_format_changed
int pixel_format_changed
Definition: ni_device_api.h:1735
NI_RETCODE_ERROR_UNLOCK_DEVICE
@ NI_RETCODE_ERROR_UNLOCK_DEVICE
Definition: ni_defs.h:523
_ni_encoder_cfg_params::intra_qp
int intra_qp
Definition: ni_device_api.h:2422
QUERY_GET_VERSIONS_R
#define QUERY_GET_VERSIONS_R
Definition: ni_nvme.h:792
_ni_device_info::fw_rev_nor_flash
uint8_t fw_rev_nor_flash[8]
Definition: ni_rsrc_api.h:114
NI_ENC_GOP_PARAMS_G3_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G3_QP_OFFSET
Definition: ni_device_api.h:1915
PIC_TYPE_I
@ PIC_TYPE_I
Definition: ni_device_api.h:397
_ni_encoder_cfg_params::enable_rate_control
int enable_rate_control
Definition: ni_device_api.h:2419
ni_p2p_ioctl.h
Definitions related to NETINT P2P kernel driver interface.
_ni_encoder_cfg_params::max_consecutive_skip_num
int max_consecutive_skip_num
Definition: ni_device_api.h:2473
NI_PIXEL_PLANAR_MAX
@ NI_PIXEL_PLANAR_MAX
Definition: ni_device_api.h:936
_ni_decoder_input_params_t::semi_planar
int semi_planar[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2570
_ni_decoder_input_params_t::scale_long_short_edge
int scale_long_short_edge[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2598
ni_device_session_hwup
int ni_device_session_hwup(ni_session_context_t *p_ctx, ni_session_data_io_t *p_src_data, niFrameSurface1_t *hwdesc)
Sends raw YUV input to uploader instance and retrieves a HW descriptor to represent it.
Definition: ni_device_api.c:8523
_ni_scaler_input_params_t::out_rec_y
int32_t out_rec_y
Definition: ni_device_api.h:2625
NI_MIN_USE_RECOMMENDED_ENC_PARAMS
#define NI_MIN_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:164
NI_ENC_PARAM_INTRA_MB_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_MB_REFRESH_ARG
Definition: ni_device_api.h:2154
NI_DEC_PARAM_SCALE_0_ROUND
#define NI_DEC_PARAM_SCALE_0_ROUND
Definition: ni_device_api.h:2535
_ni_decoder_input_params_t::hwframes
int hwframes
Definition: ni_device_api.h:2564
_ni_device_info
Definition: ni_rsrc_api.h:102
NI_DEVICE_TYPE_AI
@ NI_DEVICE_TYPE_AI
Definition: ni_defs.h:363
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:12798
ni_hwupload_session_read_hwdesc
int ni_hwupload_session_read_hwdesc(ni_session_context_t *p_ctx, niFrameSurface1_t *hwdesc)
Retrieve a HW descriptor of uploaded frame.
Definition: ni_device_api_priv.c:14352
_ni_device_temp::on_board_temp
int32_t on_board_temp
Definition: ni_rsrc_api.h:238
_ni_buf_t::pool
struct _ni_buf_pool_t * pool
Definition: ni_device_api.h:1288
_ni_xcoder_params::customize_roi_qp_map
int8_t customize_roi_qp_map[NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL][NI_CUSTOMIZE_ROI_QP_NUM]
Definition: ni_device_api.h:2866
ni_scaler_session_close
ni_retcode_t ni_scaler_session_close(ni_session_context_t *p_ctx, int eos_received)
close a scaler session
Definition: ni_device_api_priv.c:5342
netint_iocmd_issue_request::fd
int fd
Definition: ni_p2p_ioctl.h:74
_ni_encoder_cfg_params::multicoreJointMode
int multicoreJointMode
Definition: ni_device_api.h:2343
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:4160
ni_frame_new_aux_data_from_raw_data
ni_aux_data_t * ni_frame_new_aux_data_from_raw_data(ni_frame_t *frame, ni_aux_data_type_t type, const uint8_t *raw_data, int data_size)
Add a new auxiliary data to a frame and copy in the raw data.
Definition: ni_device_api.c:4058
_ni_xcoder_params::reconf_hash
int reconf_hash[NI_BITRATE_RECONFIG_FILE_MAX_LINES][NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE]
Definition: ni_device_api.h:2849
NI_FRAME_AUX_DATA_FRAMERATE
@ NI_FRAME_AUX_DATA_FRAMERATE
Definition: ni_device_api.h:575
_ni_xcoder_params::enable_ai_enhance
int enable_ai_enhance
Definition: ni_device_api.h:2857
_ni_load_query::tp_fw_load
uint32_t tp_fw_load
Definition: ni_device_api.h:1227
NI_ENC_PARAM_LTR_REF_QPOFFSET
#define NI_ENC_PARAM_LTR_REF_QPOFFSET
Definition: ni_device_api.h:2194
ni_scaler_frame_pool_alloc
ni_retcode_t ni_scaler_frame_pool_alloc(ni_session_context_t *p_ctx, ni_scaler_input_params_t scaler_params)
init output pool of scaler frames
Definition: ni_device_api.c:3368
NI_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_RETCODE_ERROR_NVME_CMD_FAILED
Definition: ni_defs.h:446
NI_ENC_PARAM_ENABLE_AI_ENHANCE
#define NI_ENC_PARAM_ENABLE_AI_ENHANCE
Definition: ni_device_api.h:2237
_ni_thread_arg_struct_t::device_type
uint32_t device_type
Definition: ni_device_api.h:1276
NI_ENC_PARAM_TUNE_BFRAME_VISUAL
#define NI_ENC_PARAM_TUNE_BFRAME_VISUAL
Definition: ni_device_api.h:2268
_ni_decoder_input_params_t
Definition: ni_device_api.h:2509
NI_XCODER_HWUP_STATE
@ NI_XCODER_HWUP_STATE
Definition: ni_device_api.h:257
NI_CUS_ROI_DISABLE
@ NI_CUS_ROI_DISABLE
Definition: ni_device_api.h:293
ni_dec_reconfig_ppu_params
ni_retcode_t ni_dec_reconfig_ppu_params(ni_session_context_t *p_session_ctx, ni_xcoder_params_t *p_param, ni_ppu_config_t *p_ppu_config)
Send a p_config command to reconfigure decoding ppu params.
Definition: ni_device_api.c:13191
netint_iocmd_export_dmabuf::flags
unsigned int flags
Definition: ni_p2p_ioctl.h:46
_ni_encoder_cfg_params::HDR10dy0
int HDR10dy0
Definition: ni_device_api.h:2329
NI_ENC_GOP_PARAMS_G2_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G2_PIC_TYPE
Definition: ni_device_api.h:1903
_ni_encoder_cfg_params::enable_dynamic_8x8_merge
int enable_dynamic_8x8_merge
Definition: ni_device_api.h:2404
_ni_encoder_cfg_params::ctbRcMode
int ctbRcMode
Definition: ni_device_api.h:2376
_ni_scaler_drawbox_params_t
Definition: ni_device_api.h:2640
_ni_device_info::fl_ver_last_ran
uint8_t fl_ver_last_ran[8]
Definition: ni_rsrc_api.h:113
NI_ENC_PARAM_MASTER_DISPLAY
#define NI_ENC_PARAM_MASTER_DISPLAY
Definition: ni_device_api.h:2174
_ni_thread_arg_struct_t::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1281
NI_ENC_PARAM_SAR_NUM
#define NI_ENC_PARAM_SAR_NUM
Definition: ni_device_api.h:2225
NI_MEM_PAGE_ALIGNMENT
#define NI_MEM_PAGE_ALIGNMENT
Definition: ni_defs.h:263
NI_ENC_PARAM_CTB_RC_MODE
#define NI_ENC_PARAM_CTB_RC_MODE
Definition: ni_device_api.h:2177
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:65
_ni_encoder_cfg_params::long_term_ref_interval
int long_term_ref_interval
Definition: ni_device_api.h:2345
GBRWLPARSE
#define GBRWLPARSE(OUT1, OUT2, OFF, IDX)
ni_decoder_session_open
ni_retcode_t ni_decoder_session_open(ni_session_context_t *p_ctx)
Open a xcoder decoder instance.
Definition: ni_device_api_priv.c:1186
NI_ENC_PARAM_PB_RATIO
#define NI_ENC_PARAM_PB_RATIO
Definition: ni_device_api.h:2254
_ni_xcoder_params::interval_of_psnr
int interval_of_psnr
Definition: ni_device_api.h:2865
NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
Definition: ni_device_api.h:2153
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1942
ni_scaler_set_watermark_params
ni_retcode_t ni_scaler_set_watermark_params(ni_session_context_t *p_ctx, ni_scaler_watermark_params_t *p_params)
Send a p_config command to configure scaling watermark parameters.
Definition: ni_device_api.c:8941
NI_ENC_PARAM_ENABLE_FILLER
#define NI_ENC_PARAM_ENABLE_FILLER
Definition: ni_device_api.h:2185
NI_ENC_PARAM_ENABLE_HVS_QP
#define NI_ENC_PARAM_ENABLE_HVS_QP
Definition: ni_device_api.h:2128
ni_device_extra_info_t
struct _ni_device_extra_info ni_device_extra_info_t
_ni_buf_t
Definition: ni_device_api.h:1285
NI_CODEC_HW_DOWNLOAD
@ NI_CODEC_HW_DOWNLOAD
Definition: ni_device_api.h:954
PIC_TYPE_IDR
@ PIC_TYPE_IDR
Definition: ni_device_api.h:402
ni_pthread_mutex_lock
int ni_pthread_mutex_lock(ni_pthread_mutex_t *mutex)
thread mutex lock
Definition: ni_util.c:4682
NI_ENC_GOP_PARAMS_G0_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G0_POC_OFFSET
Definition: ni_device_api.h:1869
_niFrameSurface1::encoding_type
int8_t encoding_type
Definition: ni_device_api.h:2879
ni_hwdownload_session_read
int ni_hwdownload_session_read(ni_session_context_t *p_ctx, ni_frame_t *p_frame, niFrameSurface1_t *hwdesc)
Retrieve a YUV p_frame from decoder.
Definition: ni_device_api_priv.c:15366
_ni_xcoder_params::hwframes
int hwframes
Definition: ni_device_api.h:2850
NI_PIX_FMT_NV16
@ NI_PIX_FMT_NV16
Definition: ni_device_api.h:275
_ni_encoder_cfg_params::newRcEnable
int newRcEnable
Definition: ni_device_api.h:2445
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1492
_ni_session_context::enc_change_params
ni_encoder_change_params_t * enc_change_params
Definition: ni_device_api.h:1622
atobool
#define atobool(p_str)
Definition: ni_device_api.c:7340
_ni_session_context::p_session_config
void * p_session_config
Definition: ni_device_api.h:1503
NI_CODEC_FORMAT_AV1
@ NI_CODEC_FORMAT_AV1
Definition: ni_device_api.h:928
_ni_encoder_cfg_params::skip_frame_enable
int skip_frame_enable
Definition: ni_device_api.h:2472
ni_rsrc_free_device_context
void ni_rsrc_free_device_context(ni_device_context_t *p_device_context)
Free previously allocated device context.
Definition: ni_rsrc_api.cpp:1338
NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:2545
XCODER_TEST_RECONF_SLICE_ARG_API
@ XCODER_TEST_RECONF_SLICE_ARG_API
Definition: ni_device_api.h:1810
NI_ENC_PARAM_CHROMA_QP_OFFSET
#define NI_ENC_PARAM_CHROMA_QP_OFFSET
Definition: ni_device_api.h:2199
_ni_packet::av1_p_buffer
uint8_t * av1_p_buffer[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2921
NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
Definition: ni_device_api.h:2552
netint_iocmd_export_dmabuf::fn
int fn
Definition: ni_p2p_ioctl.h:50
NI_EC_POLICY_TOLERANT
#define NI_EC_POLICY_TOLERANT
Definition: ni_device_api.h:331
_ni_enc_avc_roi_custom_map::mb_qp
uint8_t mb_qp
Definition: ni_device_api.h:888
NI_ENC_PARAM_RECONF_DEMO_MODE
#define NI_ENC_PARAM_RECONF_DEMO_MODE
Definition: ni_device_api.h:2099
NI_DDR_PRIORITY_MAX
@ NI_DDR_PRIORITY_MAX
Definition: ni_device_api.h:1865
NI_ENC_GOP_PARAMS_G5_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G5_POC_OFFSET
Definition: ni_device_api.h:1944
_ni_encoder_cfg_params::entropy_coding_mode
int entropy_coding_mode
Definition: ni_device_api.h:2361
NI_ENC_PARAM_INTRA_QP_DELTA
#define NI_ENC_PARAM_INTRA_QP_DELTA
Definition: ni_device_api.h:2208
ni_ai_session_read_metrics
ni_retcode_t ni_ai_session_read_metrics(ni_session_context_t *p_ctx, ni_network_perf_metrics_t *p_metrics)
Fetch perf metrics of inferences from device.
Definition: ni_device_api.c:11568
_ni_packet::p_data
void * p_data
Definition: ni_device_api.h:2914
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:4907
NI_ENC_PARAM_VBV_MAXRAE
#define NI_ENC_PARAM_VBV_MAXRAE
Definition: ni_device_api.h:2184
_ni_session_data_io
Definition: ni_device_api.h:2943
_ni_enc_quad_roi_custom_map::ipcm_flag
uint8_t ipcm_flag
Definition: ni_device_api.h:904
ni_uploader_session_open
ni_retcode_t ni_uploader_session_open(ni_session_context_t *p_ctx)
Open a xcoder upload instance.
Definition: ni_device_api_priv.c:13556
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:12131
NI_MAX_CUSTOM_SEI_PASSTHRU
#define NI_MAX_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:327
NI_ENC_PARAM_MAX_DELTA_QP
#define NI_ENC_PARAM_MAX_DELTA_QP
Definition: ni_device_api.h:2133
_ni_decoder_input_params_t::svct_decoding_layer
int svct_decoding_layer
Definition: ni_device_api.h:2587
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1923
_ni_encoder_cfg_params::ltrFirstGap
int ltrFirstGap
Definition: ni_device_api.h:2341
NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
#define NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
Definition: ni_device_api.h:2120
_ni_encoder_cfg_params::ltrRefQpOffset
int ltrRefQpOffset
Definition: ni_device_api.h:2340
_ni_enc_quad_roi_custom_map::field
struct _ni_enc_quad_roi_custom_map::@6 field
NI_ENC_PARAM_ENABLE_SMOOTH_CRF
#define NI_ENC_PARAM_ENABLE_SMOOTH_CRF
Definition: ni_device_api.h:2218
netint_iocmd_signal_rfence::fd
int fd
Definition: ni_p2p_ioctl.h:89
NI_DEC_PARAM_SVC_T_DECODING_LAYER
#define NI_DEC_PARAM_SVC_T_DECODING_LAYER
Definition: ni_device_api.h:2546
NI_PIX_FMT_YUV420P10LE
@ NI_PIX_FMT_YUV420P10LE
Definition: ni_device_api.h:266
ni_scaler_multi_drawbox_params_t
struct _ni_scaler_multi_drawbox_params_t ni_scaler_multi_drawbox_params_t
NI_DEC_PARAM_SCALE_1_RES_CEIL
#define NI_DEC_PARAM_SCALE_1_RES_CEIL
Definition: ni_device_api.h:2533
NI_ENC_GOP_PARAMS_G7_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G7_POC_OFFSET
Definition: ni_device_api.h:1974
_ni_scaler_input_params_t::in_rec_x
int32_t in_rec_x
Definition: ni_device_api.h:2616
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1981
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_ai_session_close
ni_retcode_t ni_ai_session_close(ni_session_context_t *p_ctx, int eos_recieved)
Definition: ni_device_api_priv.c:17637
NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
Definition: ni_defs.h:99
_ni_encoder_cfg_params::enable_transform_8x8
int enable_transform_8x8
Definition: ni_device_api.h:2410
_ni_session_context::sender_handle
ni_device_handle_t sender_handle
Definition: ni_device_api.h:1498
ni_hwdownload_by_frame_idx
int ni_hwdownload_by_frame_idx(niFrameSurface1_t *hwdesc, ni_frame_t *p_frame, int is_auto_dl)
Retrieve a YUV p_frame by frame index.
Definition: ni_device_api_priv.c:15558
NI_ENC_PARAM_AI_ENHANCE_LEVEL
#define NI_ENC_PARAM_AI_ENHANCE_LEVEL
Definition: ni_device_api.h:2241
ni_enc_frame_buffer_alloc
ni_retcode_t ni_enc_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, ni_pix_fmt_t pix_fmt)
Wrapper function for ni_frame_buffer_alloc. Meant to handle RGBA min. resoulution considerations for ...
Definition: ni_device_api.c:2333
ni_frame_buffer_alloc_pixfmt
ni_retcode_t ni_frame_buffer_alloc_pixfmt(ni_frame_t *p_frame, int pixel_format, int video_width, int video_height, int linesize[], int alignment, int extra_len)
Allocate memory for the frame buffer based on provided parameters taking into account the pixel forma...
Definition: ni_device_api.c:9412
ni_hwframe_p2p_buffer_recycle
ni_retcode_t ni_hwframe_p2p_buffer_recycle(ni_frame_t *p_frame)
Recycle hw P2P frames.
Definition: ni_device_api.c:11169
ni_rsrc_unlock
int ni_rsrc_unlock(int device_type, ni_lock_handle_t lock)
unlock a file lock
Definition: ni_rsrc_api.cpp:2779
QOS_NAMESPACE_CODE
@ QOS_NAMESPACE_CODE
Definition: ni_device_api.h:239
NI_MAX_GOP_NUM
#define NI_MAX_GOP_NUM
Definition: ni_device_api.h:57
NI_CUSTOMIZE_ROI_QP_NUM
#define NI_CUSTOMIZE_ROI_QP_NUM
Max number of entries per line supported for the qp number.
Definition: ni_device_api.h:494
_ni_encoder_cfg_params::enable_smooth_crf
int enable_smooth_crf
Definition: ni_device_api.h:2491
_ni_device_info::model_load
int model_load
Definition: ni_rsrc_api.h:109
_ni_network_layer_info
Definition: ni_device_api.h:1365
_ni_session_context::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1551
ni_reconfig_bitrate
ni_retcode_t ni_reconfig_bitrate(ni_session_context_t *p_ctx, int32_t bitrate)
Reconfigure bitrate dynamically during encoding.
Definition: ni_device_api.c:10035
_ni_encoder_cfg_params::totalCuTreeDepth
int totalCuTreeDepth
Definition: ni_device_api.h:2498
_ni_encoder_cfg_params::customize_roi_qp_level
int customize_roi_qp_level
Definition: ni_device_api.h:2486
_ni_device_extra_info::current_consumption
uint32_t current_consumption
Definition: ni_rsrc_api.h:248
ni_ai_session_read
ni_retcode_t ni_ai_session_read(ni_session_context_t *p_ctx, ni_packet_t *p_packet)
Definition: ni_device_api_priv.c:17037
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
Definition: ni_device_api.h:1879
ni_frame_free_aux_data
void ni_frame_free_aux_data(ni_frame_t *frame, ni_aux_data_type_t type)
If auxiliary data of the given type exists in the frame, free it and remove it from the frame.
Definition: ni_device_api.c:4102
ni_packet_buffer_free_av1
ni_retcode_t ni_packet_buffer_free_av1(ni_packet_t *p_packet)
Free packet buffer that was previously allocated with ni_packet_buffer_alloc for AV1 packets merge.
Definition: ni_device_api.c:3897
ni_ai_frame_buffer_alloc
ni_retcode_t ni_ai_frame_buffer_alloc(ni_frame_t *p_frame, ni_network_data_t *p_network)
Allocate input layers memory for AI frame buffer based on provided parameters taking into account wid...
Definition: ni_device_api.c:9861
NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
Definition: ni_device_api.h:2210
ni_parse_reconf_file
ni_retcode_t ni_parse_reconf_file(const char *reconf_file, int hash_map[][NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE])
Definition: ni_device_api.c:4690
NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL
#define NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL
Definition: ni_defs.h:300
NI_ENC_PARAM_HRD_ENABLE
#define NI_ENC_PARAM_HRD_ENABLE
Definition: ni_device_api.h:2181
_ni_encoder_cfg_params
Definition: ni_device_api.h:2096
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
Definition: ni_device_api.h:1956
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1893
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
Definition: ni_device_api.h:1890
NI_DEC_PARAM_ENABLE_ADVANCED_EC
#define NI_DEC_PARAM_ENABLE_ADVANCED_EC
Definition: ni_device_api.h:2549
NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
#define NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
Definition: ni_device_api.h:2266
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
Definition: ni_device_api.h:1967
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1895
_ni_encoder_cfg_params::EnableAUD
int EnableAUD
Definition: ni_device_api.h:2355
NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
Definition: ni_device_api.h:1977
_ni_encoder_cfg_params::spatial_layers
int spatial_layers
Definition: ni_device_api.h:2493
ni_uploader_set_frame_format
ni_retcode_t ni_uploader_set_frame_format(ni_session_context_t *p_upl_ctx, int width, int height, ni_pix_fmt_t pixel_format, int isP2P)
Set the outgoing frame format for the uploader.
Definition: ni_device_api.c:11346
ni_usleep
void ni_usleep(int64_t usec)
Definition: ni_util.c:358
ni_query_fl_fw_versions
ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle, ni_device_info_t *p_dev_info)
Query firmware loader and firmware versions from the device.
Definition: ni_device_api.c:11574
_ni_encoder_cfg_params::scene_change_detect_level
int scene_change_detect_level
Definition: ni_device_api.h:2489
ni_ai_multi_config_frame
ni_retcode_t ni_ai_multi_config_frame(ni_session_context_t *p_ctx, ni_frame_config_t p_cfg_in[], int numInCfgs, ni_frame_config_t *p_cfg_out)
Definition: ni_device_api_priv.c:17755
NI_ENC_PARAM_PADDING
#define NI_ENC_PARAM_PADDING
Definition: ni_device_api.h:2109
_ni_session_context::device_type
uint32_t device_type
Definition: ni_device_api.h:1514
NI_RETCODE_ERROR_PERMISSION_DENIED
@ NI_RETCODE_ERROR_PERMISSION_DENIED
Definition: ni_defs.h:537
niFrameSurface1_t
struct _niFrameSurface1 niFrameSurface1_t
NI_AI_HW_ALIGN_SIZE
#define NI_AI_HW_ALIGN_SIZE
Definition: ni_device_api_priv.h:1257
NI_ENC_PARAM_CPLX_DECAY
#define NI_ENC_PARAM_CPLX_DECAY
Definition: ni_device_api.h:2255
_ni_frame::force_key_frame
int force_key_frame
Definition: ni_device_api.h:2694
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:2892
LRETURN
#define LRETURN
Definition: ni_defs.h:337
NI_VPU_ALIGN32
#define NI_VPU_ALIGN32(_x)
Definition: ni_device_api.h:345
NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
Definition: ni_device_api.h:933
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1876
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:3949
NI_MAX_HEIGHT
#define NI_MAX_HEIGHT
Definition: ni_device_api.h:127
ni_device_vf_ns_id_t
struct _ni_device_vf_ns_id ni_device_vf_ns_id_t
_ni_instance_mgr_general_status::tp_fw_load
uint8_t tp_fw_load
Definition: ni_device_api_priv.h:106
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1955
_ni_encoder_cfg_params::HDR10CLLEnable
int HDR10CLLEnable
Definition: ni_device_api.h:2326
NI_ENC_PARAM_HORIZONTAL_OFFSET
#define NI_ENC_PARAM_HORIZONTAL_OFFSET
Definition: ni_device_api.h:2245
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
Definition: ni_device_api.h:1935
NI_RETCODE_PARAM_WARNING_DEPRECATED
@ NI_RETCODE_PARAM_WARNING_DEPRECATED
Definition: ni_defs.h:530
_ni_aux_data::data
void * data
Definition: ni_device_api.h:634
_ni_frame::dec_buf
ni_buf_t * dec_buf
Definition: ni_device_api.h:2740
_ni_xcoder_params::chroma_linesize
int chroma_linesize
Definition: ni_device_api.h:2861
_ni_xcoder_params::minFramesDelay
int minFramesDelay
Definition: ni_device_api.h:2864
_ni_xcoder_params::sar_num
int sar_num
Definition: ni_device_api.h:2835
NI_VPU_ALIGN128
#define NI_VPU_ALIGN128(_x)
Definition: ni_device_api.h:347
XCODER_TEST_RECONF_RC_MIN_MAX_QP
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP
Definition: ni_device_api.h:1783
NI_ENC_PARAM_CU_TREE_FACTOR
#define NI_ENC_PARAM_CU_TREE_FACTOR
Definition: ni_device_api.h:2251
NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
#define NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
Definition: ni_device_api.h:2228
_ni_packet
Definition: ni_device_api.h:2902
_ni_buf_pool_t
Definition: ni_device_api.h:1295
NI_DEC_PARAM_SCALE_2_ROUND
#define NI_DEC_PARAM_SCALE_2_ROUND
Definition: ni_device_api.h:2537
_ni_device_temp
Definition: ni_rsrc_api.h:235
NI_DATA_BUFFER_LEN
#define NI_DATA_BUFFER_LEN
Definition: ni_nvme.h:624
NI_ENC_PARAM_MOTION_CONSTRAINED_MODE
#define NI_ENC_PARAM_MOTION_CONSTRAINED_MODE
Definition: ni_device_api.h:2274
_ni_session_context::frame_num
uint64_t frame_num
Definition: ni_device_api.h:1561
_ni_encoder_cfg_params::HDR10Enable
int HDR10Enable
Definition: ni_device_api.h:2327
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:255
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_1
uint32_t sub_ctu_qp_1
Definition: ni_device_api.h:869
_ni_encoder_cfg_params::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2440
ni_get_dma_buf_file_descriptor
int32_t ni_get_dma_buf_file_descriptor(const ni_frame_t *p_frame)
Get the DMA buffer file descriptor from the P2P frame.
Definition: ni_device_api.c:11458
_ni_encoder_cfg_params::intra_qp_delta
int intra_qp_delta
Definition: ni_device_api.h:2423
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1987
ni_scaler_session_query_buffer_avail
ni_retcode_t ni_scaler_session_query_buffer_avail(ni_session_context_t *p_ctx)
Query and acquire buffer from xcoder scaler instance.
Definition: ni_device_api_priv.c:13798
_ni_xcoder_params::ai_enhance_level
int ai_enhance_level
Definition: ni_device_api.h:2862
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
Definition: ni_device_api.h:1922
ni_rsrc_allocate_simple_direct
ni_device_context_t * ni_rsrc_allocate_simple_direct(ni_device_type_t device_type, int guid)
Allocate resources for decoding/encoding, by designating explicitly the device to use....
Definition: ni_rsrc_api.cpp:1964
_ni_session_context::roi_map
ni_enc_quad_roi_custom_map * roi_map
Definition: ni_device_api.h:1612
ni_decoder_session_send_eos
ni_retcode_t ni_decoder_session_send_eos(ni_session_context_t *p_ctx)
Send end of stream signal to the decoder.
Definition: ni_device_api_priv.c:1548
_ni_network_layer_offset::offset
int32_t offset
Definition: ni_device_api.h:1373
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1970
ni_get_frame_dim
void ni_get_frame_dim(int width, int height, ni_pix_fmt_t pix_fmt, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of frame to be sent to encoder for encoding. Caller usually retrieves this ...
Definition: ni_util.c:2712
NI_XCODER_PRESET_NAME_DEFAULT
#define NI_XCODER_PRESET_NAME_DEFAULT
Definition: ni_device_api.h:2956
NI_VPU_ALIGN8
#define NI_VPU_ALIGN8(_x)
Definition: ni_device_api.h:343
_ni_encoder_cfg_params::colorDescPresent
int colorDescPresent
Definition: ni_device_api.h:2365
NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2531
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1910
NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
Definition: ni_device_api.h:1919
NI_RETCODE_PARAM_ERROR_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_TOO_BIG
Definition: ni_defs.h:503
NI_ENC_PARAM_RECONF_FILE
#define NI_ENC_PARAM_RECONF_FILE
Definition: ni_device_api.h:2100
_ni_log_fl_fw_versions
Definition: ni_device_api_priv.h:114
_ni_device_context
Definition: ni_rsrc_api.h:145
ni_encoder_set_input_frame_format
ni_retcode_t ni_encoder_set_input_frame_format(ni_session_context_t *p_enc_ctx, ni_xcoder_params_t *p_enc_params, int width, int height, int bit_depth, int src_endian, int planar)
Set the incoming frame format for the encoder.
Definition: ni_device_api.c:11258
_ni_session_context::last_gop_size
int last_gop_size
Definition: ni_device_api.h:1721
_ni_instance_mgr_general_status::pcie_load
uint8_t pcie_load
Definition: ni_device_api_priv.h:85
_ni_encoder_cfg_params::tolCtbRcInter
float tolCtbRcInter
Definition: ni_device_api.h:2383
ni_recv_from_target
ni_retcode_t ni_recv_from_target(ni_session_context_t *p_ctx, const ni_p2p_sgl_t *dmaAddrs, ni_frame_t *pDstFrame)
Definition: ni_device_api_priv.c:18894
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2733
NI_ENC_GOP_PARAMS_G7_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G7_QP_OFFSET
Definition: ni_device_api.h:1975
_ni_encoder_cfg_params::custom_gop_params
ni_custom_gop_params_t custom_gop_params
Definition: ni_device_api.h:2309
NI_VPU_CEIL
#define NI_VPU_CEIL(_data, _align)
Definition: ni_device_api.h:341
_ni_encoder_cfg_params::HDR10dx0
int HDR10dx0
Definition: ni_device_api.h:2328
ni_pthread_create
int ni_pthread_create(ni_pthread_t *thread, const ni_pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
create a new thread
Definition: ni_util.c:4746
NI_EC_POLICY_DEFAULT
#define NI_EC_POLICY_DEFAULT
Definition: ni_device_api.h:337
_ni_xcoder_params::zerocopy_mode
int zerocopy_mode
Definition: ni_device_api.h:2859
_ni_xcoder_params::sar_denom
int sar_denom
Definition: ni_device_api.h:2836
ni_hwframe_buffer_recycle2
ni_retcode_t ni_hwframe_buffer_recycle2(niFrameSurface1_t *surface)
Recycle a frame buffer on card, only hwframe descriptor is needed.
Definition: ni_device_api.c:8677
_ni_decoder_input_params_t::max_extra_hwframe_cnt
int max_extra_hwframe_cnt
Definition: ni_device_api.h:2592
ni_device_config_qos
ni_retcode_t ni_device_config_qos(ni_device_handle_t device_handle, uint32_t mode)
Send qos mode to the device with specified logic block address.
Definition: ni_device_api.c:2070
ni_device_alloc_frame
ni_retcode_t ni_device_alloc_frame(ni_session_context_t *p_ctx, int width, int height, int format, int options, int rectangle_width, int rectangle_height, int rectangle_x, int rectangle_y, int rgba_color, int frame_index, ni_device_type_t device_type)
Allocate a frame on the device for 2D engine or AI engine to work on based on provided parameters.
Definition: ni_device_api.c:9040
_ni_device_info::blk_name
char blk_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_rsrc_api.h:105
_ni_encoder_cfg_params::disableBframeRdoq
int disableBframeRdoq
Definition: ni_device_api.h:2481
ni_strcasecmp
int ni_strcasecmp(const char *a, const char *b)
Definition: ni_device_api.c:12787
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
Definition: ni_device_api.h:1875
XCODER_TEST_RECONF_VBV_API
@ XCODER_TEST_RECONF_VBV_API
Definition: ni_device_api.h:1808
XCODER_TEST_FORCE_IDR_FRAME
@ XCODER_TEST_FORCE_IDR_FRAME
Definition: ni_device_api.h:1795
NI_DEVICE_TYPE_SCALER
@ NI_DEVICE_TYPE_SCALER
Definition: ni_defs.h:362
_ni_scaler_input_params_t::in_rec_y
int32_t in_rec_y
Definition: ni_device_api.h:2617
_ni_encoder_cfg_params::tolCtbRcIntra
float tolCtbRcIntra
Definition: ni_device_api.h:2384
NI_XCODER_WRITE_STATE
@ NI_XCODER_WRITE_STATE
Definition: ni_device_api.h:249
NI_XCODER_LOG_NAMES_ARRAY_LEN
#define NI_XCODER_LOG_NAMES_ARRAY_LEN
Definition: ni_device_api.h:2954
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:4572
netint_iocmd_export_dmabuf::domain
int domain
Definition: ni_p2p_ioctl.h:47
_ni_encoder_cfg_params::enable_all_sei_passthru
bool enable_all_sei_passthru
Definition: ni_device_api.h:2476
ni_encoder_session_close
ni_retcode_t ni_encoder_session_close(ni_session_context_t *p_ctx, int eos_recieved)
Close a xcoder encoder instance.
Definition: ni_device_api_priv.c:3845
_ni_decoder_input_params_t::enable_all_sei_passthru
bool enable_all_sei_passthru
Definition: ni_device_api.h:2595
NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
#define NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
Definition: ni_device_api.h:2261
NI_ERRNO
#define NI_ERRNO
Definition: ni_defs.h:229
_ni_encoder_cfg_params::disable_adaptive_buffers
bool disable_adaptive_buffers
Definition: ni_device_api.h:2480
NI_ENC_PARAM_SKIP_FRAME_INTERVAL
#define NI_ENC_PARAM_SKIP_FRAME_INTERVAL
Definition: ni_device_api.h:2214
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
Definition: ni_defs.h:508
NI_DEC_PARAM_EC_POLICY
#define NI_DEC_PARAM_EC_POLICY
Definition: ni_device_api.h:2548
NI_DEC_PARAM_ERROR_THRESHOLD
#define NI_DEC_PARAM_ERROR_THRESHOLD
Definition: ni_device_api.h:2550
_ni_session_context::vui
ni_vui_hrd_t vui
Definition: ni_device_api.h:1635
_ni_encoder_cfg_params::enable_dynamic_16x16_merge
int enable_dynamic_16x16_merge
Definition: ni_device_api.h:2405
NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
#define NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
Definition: ni_device_api.h:2222
ni_p2p_xfer
NI_DEPRECATED ni_retcode_t ni_p2p_xfer(ni_session_context_t *pSession, niFrameSurface1_t *source, uint64_t ui64DestAddr, uint32_t ui32FrameSize)
Initiate P2P transfer (P2P write) (deprecated)
Definition: ni_device_api.c:12976
NI_PARAM_AV1_ALIGN_WIDTH_HEIGHT
#define NI_PARAM_AV1_ALIGN_WIDTH_HEIGHT
Definition: ni_device_api.h:150
_ni_session_context::hw_action
int hw_action
Definition: ni_device_api.h:1639
NI_ENC_PARAM_LOG
#define NI_ENC_PARAM_LOG
Definition: ni_device_api.h:2115
NI_ENC_PARAM_SKIP_FRAME_ENABLE
#define NI_ENC_PARAM_SKIP_FRAME_ENABLE
Definition: ni_device_api.h:2212
_ni_session_context
Definition: ni_device_api.h:1434
_ni_rc_min_max_qp::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:722
_ni_encoder_cfg_params::iframe_size_ratio
int iframe_size_ratio
Definition: ni_device_api.h:2477
_ni_scaler_input_params_t::out_rec_x
int32_t out_rec_x
Definition: ni_device_api.h:2624
_ni_scaler_input_params_t::input_width
int32_t input_width
Definition: ni_device_api.h:2612
netint_iocmd_issue_request::data
unsigned char * data
Definition: ni_p2p_ioctl.h:77
NI_PIX_FMT_P010LE
@ NI_PIX_FMT_P010LE
Definition: ni_device_api.h:268
ni_memfree
#define ni_memfree(p_memptr)
Definition: ni_util.h:408
_ni_session_context::bus
unsigned short bus
Definition: ni_device_api.h:1650
NI_ENC_PARAM_FORCED_HEADER_ENABLE
#define NI_ENC_PARAM_FORCED_HEADER_ENABLE
Definition: ni_device_api.h:2134
NI_ENC_PARAM_BITRATE_WINDOW
#define NI_ENC_PARAM_BITRATE_WINDOW
Definition: ni_device_api.h:2202
_ni_thread_arg_struct_t::hw_id
int hw_id
Definition: ni_device_api.h:1272
NI_ENC_PARAM_ENABLE_VFR
#define NI_ENC_PARAM_ENABLE_VFR
Definition: ni_device_api.h:2230
ni_device_session_query_detail
ni_retcode_t ni_device_session_query_detail(ni_session_context_t *p_ctx, ni_device_type_t device_type, ni_instance_mgr_detail_status_t *detail_data)
Query detail session data from the device - If device_type is valid, will query session data from spe...
Definition: ni_device_api.c:1972
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:1781
_niFrameSurface1
Definition: ni_device_api.h:2870
NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
Definition: ni_device_api.h:2123
NI_EC_ERR_THRESHOLD_DEFAULT
#define NI_EC_ERR_THRESHOLD_DEFAULT
Definition: ni_device_api.h:338
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:8559
NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_NUM_DATA_POINTERS
Definition: ni_defs.h:244
ni_device_session_restart
ni_retcode_t ni_device_session_restart(ni_session_context_t *p_ctx, int video_width, int video_height, ni_device_type_t device_type)
Send a restart command after flush command Only support Encoder now.
Definition: ni_device_api.c:13099
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
Definition: ni_device_api.h:1986
NI_XCODER_GENERAL_STATE
@ NI_XCODER_GENERAL_STATE
Definition: ni_device_api.h:260
NI_ENC_PARAM_INTRA_REFRESH_RESET
#define NI_ENC_PARAM_INTRA_REFRESH_RESET
Definition: ni_device_api.h:2146
NI_PARAM_AV1_MAX_HEIGHT
#define NI_PARAM_AV1_MAX_HEIGHT
Definition: ni_device_api.h:148
ni_nvme_send_read_cmd
int32_t ni_nvme_send_read_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose an io read command.
Definition: ni_nvme.c:554
_ni_encoder_cfg_params::adaptiveCuTree
int adaptiveCuTree
Definition: ni_device_api.h:2499
ni_pthread_mutex_init
int ni_pthread_mutex_init(ni_pthread_mutex_t *mutex)
initialize a mutex
Definition: ni_util.c:4626
_ni_session_data_io::data
union _ni_session_data_io::@19 data
NI_PARAM_AV1_MIN_WIDTH
#define NI_PARAM_AV1_MIN_WIDTH
Definition: ni_device_api.h:145
_ni_session_context::blk_xcoder_name
char blk_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1520
_ni_frame
Definition: ni_device_api.h:2671
NI_ENC_GOP_PARAMS_G0_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G0_QP_OFFSET
Definition: ni_device_api.h:1870
NI_ENC_PARAM_PAST_FRAME_MAX_INTRA_RATIO
#define NI_ENC_PARAM_PAST_FRAME_MAX_INTRA_RATIO
Definition: ni_device_api.h:2285
_ni_network_data::input_num
uint32_t input_num
Definition: ni_device_api.h:1378
_ni_encoder_cfg_params::HDR10dy1
int HDR10dy1
Definition: ni_device_api.h:2331
NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
#define NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
Definition: ni_device_api.h:2217
NI_PIX_FMT_YUYV422
@ NI_PIX_FMT_YUYV422
Definition: ni_device_api.h:276
NI_PIX_FMT_RGBA
@ NI_PIX_FMT_RGBA
Definition: ni_device_api.h:269
_ni_encoder_change_params_t::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:1017
_ni_encoder_cfg_params::conf_win_bottom
int conf_win_bottom
Definition: ni_device_api.h:2352
_ni_decoder_input_params_t::scale_round
int scale_round[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2600
NI_ENC_PARAM_IFRAME_SIZE_RATIO
#define NI_ENC_PARAM_IFRAME_SIZE_RATIO
Definition: ni_device_api.h:2215
NI_DEPRECATED
#define NI_DEPRECATED
Definition: ni_defs.h:80
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:722
_ni_session_context::roi_len
uint32_t roi_len
Definition: ni_device_api.h:1526
_ni_encoder_cfg_params::linkFrameMaxIntraRatio
int linkFrameMaxIntraRatio
Definition: ni_device_api.h:2503
NI_DDR_PRIORITY_NONE
@ NI_DDR_PRIORITY_NONE
Definition: ni_device_api.h:1860
ni_device_session_context_free
void ni_device_session_context_free(ni_session_context_t *p_ctx)
Free previously allocated session context.
Definition: ni_device_api.c:130
_ni_encoder_cfg_params::profile
int profile
Definition: ni_device_api.h:2302
_ni_resolution::width
int32_t width
Definition: ni_device_api_priv.h:683
XCODER_TEST_RECONF_VUI_HRD_API
@ XCODER_TEST_RECONF_VUI_HRD_API
Definition: ni_device_api.h:1798
netint_iocmd_attach_rfence::fd
int fd
Definition: ni_p2p_ioctl.h:82
_ni_encoder_cfg_params::colorSpace
int colorSpace
Definition: ni_device_api.h:2368
_ni_session_context::max_frame_delay
int max_frame_delay
Definition: ni_device_api.h:1724
_ni_gop_params::rps
ni_gop_rps_t rps[NI_MAX_REF_PIC]
Definition: ni_device_api.h:2003
CONFIG_INSTANCE_SetScalerDrawBoxPara_W
#define CONFIG_INSTANCE_SetScalerDrawBoxPara_W(sid, instance)
Definition: ni_nvme.h:825
ni_rsrc_priv.h
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
_ni_xcoder_params::force_pic_qp_demo_mode
int force_pic_qp_demo_mode
Definition: ni_device_api.h:2806
NI_DEC_CROP_MODE_MANUAL
@ NI_DEC_CROP_MODE_MANUAL
Definition: ni_device_api.h:943
XCODER_TEST_RECONF_LONG_TERM_REF
@ XCODER_TEST_RECONF_LONG_TERM_REF
Definition: ni_device_api.h:1781
NI_ENC_PARAM_GOP_PRESET_IDX
#define NI_ENC_PARAM_GOP_PRESET_IDX
Definition: ni_device_api.h:2116
NI_ENC_PARAM_ENTROPY_CODING_MODE
#define NI_ENC_PARAM_ENTROPY_CODING_MODE
Definition: ni_device_api.h:2149
ni_lat_meas_q_create
ni_lat_meas_q_t * ni_lat_meas_q_create(int capacity)
Create a latency measurement queue object of a given capacity.
Definition: ni_lat_meas.c:52
NI_VPU_ALIGN4096
#define NI_VPU_ALIGN4096(_x)
Definition: ni_device_api.h:351
NI_CUS_ROI_MERGE
@ NI_CUS_ROI_MERGE
Definition: ni_device_api.h:297
_ni_device_extra_info::on_die_temp
int32_t on_die_temp
Definition: ni_rsrc_api.h:246
_ni_encoder_cfg_params::bitrateWindow
int bitrateWindow
Definition: ni_device_api.h:2385
NI_RETCODE_ERROR_INVALID_SESSION
@ NI_RETCODE_ERROR_INVALID_SESSION
Definition: ni_defs.h:447
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3
Definition: ni_device_api.h:1926
ni_hwupload_session_write
int ni_hwupload_session_write(ni_session_context_t *p_ctx, ni_frame_t *p_frame, niFrameSurface1_t *hwdesc)
Send a YUV p_frame to upload session.
Definition: ni_device_api_priv.c:13995
NI_PIX_FMT_ABGR
@ NI_PIX_FMT_ABGR
Definition: ni_device_api.h:272
ni_strtok
char * ni_strtok(char *s, const char *delim, char **saveptr)
Definition: ni_util.c:420
ni_device_session_copy
ni_retcode_t ni_device_session_copy(ni_session_context_t *src_p_ctx, ni_session_context_t *dst_p_ctx)
Copy existing decoding session params for hw frame usage.
Definition: ni_device_api.c:8175
_ni_enc_hevc_roi_custom_map::field
struct _ni_enc_hevc_roi_custom_map::@4 field
_ni_load_query::total_pixel_load
uint32_t total_pixel_load
Definition: ni_device_api.h:1230
QUERY_GET_NS_VF_R
#define QUERY_GET_NS_VF_R
Definition: ni_nvme.h:795
NI_PIX_FMT_ARGB
@ NI_PIX_FMT_ARGB
Definition: ni_device_api.h:271
NI_ENC_PARAM_CONSTANT_RATE_FACTOR
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR
Definition: ni_device_api.h:2168
ni_reconfig_max_frame_size
ni_retcode_t ni_reconfig_max_frame_size(ni_session_context_t *p_ctx, int32_t max_frame_size)
Reconfigure maxFrameSize dynamically during encoding.
Definition: ni_device_api.c:10342
_ni_xcoder_params
Definition: ni_device_api.h:2787
NI_ENC_PARAM_MULTICORE_JOINT_MODE
#define NI_ENC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2197
NI_DEC_PARAM_CROP_PARAM_2
#define NI_DEC_PARAM_CROP_PARAM_2
Definition: ni_device_api.h:2525
_ni_session_context::p_hdr_buf
uint8_t * p_hdr_buf
Definition: ni_device_api.h:1541
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
Definition: ni_defs.h:510
NI_ENC_PARAM_PREFERRED_TRANSFER_CHARACTERISTICS
#define NI_ENC_PARAM_PREFERRED_TRANSFER_CHARACTERISTICS
Definition: ni_device_api.h:2158
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
Definition: ni_device_api.h:2247
NI_XCODER_READ_DESC_STATE
@ NI_XCODER_READ_DESC_STATE
Definition: ni_device_api.h:256
_ni_decoder_input_params_t::reduce_dpb_delay
int reduce_dpb_delay
Definition: ni_device_api.h:2605
_ni_encoder_cfg_params::max_delta_qp
int max_delta_qp
Definition: ni_device_api.h:2436
_ni_xcoder_params::staticMmapThreshold
int staticMmapThreshold
Definition: ni_device_api.h:2856
ni_device_dec_session_save_hdrs
ni_retcode_t ni_device_dec_session_save_hdrs(ni_session_context_t *p_ctx, uint8_t *hdr_data, uint8_t hdr_size)
Save a stream's headers in a decoder session that can be used later for continuous decoding from the ...
Definition: ni_device_api.c:1578
_ni_encoder_cfg_params::ctbRowQpStep
int ctbRowQpStep
Definition: ni_device_api.h:2444
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1985
NI_ENC_PARAM_COLOR_SPACE
#define NI_ENC_PARAM_COLOR_SPACE
Definition: ni_device_api.h:2223
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
Definition: ni_device_api.h:1909
_ni_session_context::low_delay_sync_cond
ni_pthread_cond_t low_delay_sync_cond
Definition: ni_device_api.h:1696
NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
#define NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
Definition: ni_device_api.h:2216
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
Definition: ni_device_api.h:1952
_ni_encoder_cfg_params::motionConstrainedMode
int motionConstrainedMode
Definition: ni_device_api.h:2487
ni_hwupload_session_query_buffer_avail
ni_retcode_t ni_hwupload_session_query_buffer_avail(ni_session_context_t *p_ctx)
Query and acquire buffer from xcoder upload instance.
Definition: ni_device_api_priv.c:13890
NI_ENC_GOP_PARAMS_G4_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G4_POC_OFFSET
Definition: ni_device_api.h:1929
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
Definition: ni_device_api.h:1809
_ni_session_context::ready_to_close
uint32_t ready_to_close
Definition: ni_device_api.h:1574
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1925
_ni_session_context::thread_event_handle
ni_event_handle_t thread_event_handle
Definition: ni_device_api.h:1605
NI_PARAM_AV1_MIN_HEIGHT
#define NI_PARAM_AV1_MIN_HEIGHT
Definition: ni_device_api.h:146
_ni_encoder_cfg_params::decoding_refresh_type
int decoding_refresh_type
Definition: ni_device_api.h:2414
NI_XCODER_LOG_NAME_ERROR
#define NI_XCODER_LOG_NAME_ERROR
Definition: ni_device_api.h:2960
ni_xcoder_session_query
int ni_xcoder_session_query(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query current xcoder status.
Definition: ni_device_api_priv.c:3142
_ni_load_query::fw_load
uint32_t fw_load
Definition: ni_device_api.h:1213
ni_encoder_start_buffer_alloc
ni_retcode_t ni_encoder_start_buffer_alloc(ni_frame_t *p_frame)
Allocate memory for the non-4k-aligned part at the start of YUV data for encoder input data.
Definition: ni_device_api_priv.c:18507
_ni_encoder_cfg_params::disableAv1TimingInfo
int disableAv1TimingInfo
Definition: ni_device_api.h:2505
_ni_encoder_cfg_params::crop_width
int crop_width
Definition: ni_device_api.h:2449
GOP_PRESET_IDX_IBBBP
@ GOP_PRESET_IDX_IBBBP
Definition: ni_device_api_priv.h:326
_ni_thread_arg_struct_t
Definition: ni_device_api.h:1270
NI_MIN_FRAME_SIZE
#define NI_MIN_FRAME_SIZE
Definition: ni_device_api.h:179
_ni_device_vf_ns_id
Definition: ni_rsrc_api.h:229
NI_DEC_PARAM_SEMI_PLANAR_0
#define NI_DEC_PARAM_SEMI_PLANAR_0
Definition: ni_device_api.h:2517
_ni_encoder_cfg_params::slice_mode
int slice_mode
Definition: ni_device_api.h:2411
ni_reconfig_max_frame_size_ratio
ni_retcode_t ni_reconfig_max_frame_size_ratio(ni_session_context_t *p_ctx, int32_t max_frame_size_ratio)
Reconfigure maxFrameSizeRatio dynamically during encoding.
Definition: ni_device_api.c:10634
NI_ENC_PARAM_FRAME_RATE_DENOM
#define NI_ENC_PARAM_FRAME_RATE_DENOM
Definition: ni_device_api.h:2143
ni_reconfig_vui
ni_retcode_t ni_reconfig_vui(ni_session_context_t *p_ctx, ni_vui_hrd_t *vui)
Reconfigure VUI HRD dynamically during encoding.
Definition: ni_device_api.c:10111
NI_ENC_PARAM_AVCC_HVCC
#define NI_ENC_PARAM_AVCC_HVCC
Definition: ni_device_api.h:2232
_ni_resolution::height
int32_t height
Definition: ni_device_api_priv.h:686
_ni_encoder_cfg_params::HDR10minluma
int HDR10minluma
Definition: ni_device_api.h:2337
NI_DEC_PARAM_SURVIVE_STREAM_ERR
#define NI_DEC_PARAM_SURVIVE_STREAM_ERR
Definition: ni_device_api.h:2559
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
Definition: ni_device_api.h:1920
NI_ENC_PARAM_QCOMP
#define NI_ENC_PARAM_QCOMP
Definition: ni_device_api.h:2248
NI_MAX_PPU_PARAM_EXPR_CHAR
#define NI_MAX_PPU_PARAM_EXPR_CHAR
Definition: ni_defs.h:259
XCODER_TEST_RECONF_LTR_API
@ XCODER_TEST_RECONF_LTR_API
Definition: ni_device_api.h:1799
ni_encoder_metadata_buffer_alloc
ni_retcode_t ni_encoder_metadata_buffer_alloc(ni_frame_t *p_frame, int extra_len)
Allocate memory for the metadata header and auxillary data for encoder input data.
Definition: ni_device_api_priv.c:18420
ni_uploader_session_close
ni_retcode_t ni_uploader_session_close(ni_session_context_t *p_ctx)
Close an xcoder upload instance.
Definition: ni_device_api_priv.c:15740
_ni_session_context::codec_format
uint32_t codec_format
Definition: ni_device_api.h:1516
_ni_session_context::max_frame_size
int32_t max_frame_size
Definition: ni_device_api.h:1685
_ni_device_capability
device capability type
Definition: ni_device_api.h:1166
NI_MAX_NUM_OF_DECODER_OUTPUTS
#define NI_MAX_NUM_OF_DECODER_OUTPUTS
Definition: ni_defs.h:255
_ni_rc_min_max_qp::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:723
XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
Definition: ni_device_api.h:1804
NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
#define NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
Definition: ni_device_api.h:2278
ni_sprintf
int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
Definition: ni_util.c:1059
ni_posix_memalign
int ni_posix_memalign(void **memptr, size_t alignment, size_t size)
Allocate aligned memory.
Definition: ni_util.c:198
NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
@ NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
Definition: ni_defs.h:536
NI_DEC_PARAM_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:2544
NI_INVALID_POWER
#define NI_INVALID_POWER
Definition: ni_util.h:44
NI_ENC_GOP_PARAMS_G6_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G6_POC_OFFSET
Definition: ni_device_api.h:1959
_ni_decoder_input_params_t::scale_wh
int scale_wh[NI_MAX_NUM_OF_DECODER_OUTPUTS][2]
Definition: ni_device_api.h:2576
_ni_encoder_cfg_params::colorPrimaries
int colorPrimaries
Definition: ni_device_api.h:2366
ni_device_alloc_dst_frame
ni_retcode_t ni_device_alloc_dst_frame(ni_session_context_t *p_ctx, niFrameSurface1_t *p_out_surface, ni_device_type_t device_type)
Allocate a frame on the device and return the frame index.
Definition: ni_device_api.c:9107
NI_DEC_PARAM_FORCE_8BIT_0
#define NI_DEC_PARAM_FORCE_8BIT_0
Definition: ni_device_api.h:2514
ni_log2
void ni_log2(const void *p_context, ni_log_level_t level, const char *fmt,...)
print log message and additional information using ni_log_callback,
Definition: ni_log.c:337
NI_XCODER_PRESET_NAMES_ARRAY_LEN
#define NI_XCODER_PRESET_NAMES_ARRAY_LEN
Definition: ni_device_api.h:2953
NI_DISABLE_USR_DATA_SEI_PASSTHRU
#define NI_DISABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:328
_ni_encoder_cfg_params::forceBframeQpfactor
float forceBframeQpfactor
Definition: ni_device_api.h:2482
NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
#define NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
Definition: ni_device_api.h:2553
_ni_load_query
Definition: ni_device_api.h:1209
XCODER_TEST_CRF_FLOAT_API
@ XCODER_TEST_CRF_FLOAT_API
Definition: ni_device_api.h:1807
ni_calculate_total_frame_size
int ni_calculate_total_frame_size(const ni_session_context_t *p_upl_ctx, const int linesize[])
Calculate the total size of a frame based on the upload context attributes and includes rounding up t...
Definition: ni_device_api.c:9305
_ni_session_context::is_auto_dl
uint8_t is_auto_dl
Definition: ni_device_api.h:1500
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
Definition: ni_device_api.h:1793
NI_DEC_PARAM_REDUCE_DPB_DELAY
#define NI_DEC_PARAM_REDUCE_DPB_DELAY
Definition: ni_device_api.h:2560
QUERY_GET_TEMPERATURE_R
#define QUERY_GET_TEMPERATURE_R
Definition: ni_nvme.h:797
_ni_thread_arg_struct_t::session_id
uint32_t session_id
Definition: ni_device_api.h:1273
ni_set_ltr_interval
ni_retcode_t ni_set_ltr_interval(ni_session_context_t *p_ctx, int32_t ltr_interval)
Set Long Term Reference interval.
Definition: ni_device_api.c:10220
_ni_encoder_cfg_params::crfFloat
float crfFloat
Definition: ni_device_api.h:2464
_ni_device_context::p_device_info
ni_device_info_t * p_device_info
Definition: ni_rsrc_api.h:149
_ni_encoder_cfg_params::long_term_ref_count
int long_term_ref_count
Definition: ni_device_api.h:2346
ni_nvme.h
Private definitions for interfacing with NETINT video processing devices over NVMe.
NI_DEC_PARAM_SCALE_2
#define NI_DEC_PARAM_SCALE_2
Definition: ni_device_api.h:2528
_niFrameSurface1::ui16width
uint16_t ui16width
Definition: ni_device_api.h:2874
ni_strncpy
ni_retcode_t ni_strncpy(char *dest, size_t dmax, const char *src, size_t slen)
Definition: ni_util.c:514
ni_device_session_acquire_for_read
int ni_device_session_acquire_for_read(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
Acquire a P2P frame buffer from the hwupload session for P2P read.
Definition: ni_device_api.c:10863
NI_ENC_GOP_PARAMS_G3_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G3_POC_OFFSET
Definition: ni_device_api.h:1914
_ni_resolution::bit_depth_factor
int32_t bit_depth_factor
Definition: ni_device_api_priv.h:689
NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
#define NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
Definition: ni_device_api.h:2103
NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
#define NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
Definition: ni_device_api.h:2148
_ni_log_fl_fw_versions::nor_flash_fw_revision
uint8_t nor_flash_fw_revision[NI_VERSION_CHARACTER_COUNT]
Definition: ni_device_api_priv.h:119
_ni_thread_arg_struct_t::thread_event_handle
ni_event_handle_t thread_event_handle
Definition: ni_device_api.h:1278
NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
Definition: ni_device_api.h:1979
_ni_session_context::keep_alive_thread
ni_pthread_t keep_alive_thread
Definition: ni_device_api.h:1586
_ni_session_context::load_query
ni_load_query_t load_query
Definition: ni_device_api.h:1530
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:2947
NI_ENC_GOP_PARAMS_G3_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G3_PIC_TYPE
Definition: ni_device_api.h:1918
NI_ENC_PARAM_CROP_WIDTH
#define NI_ENC_PARAM_CROP_WIDTH
Definition: ni_device_api.h:2243
_ni_decoder_input_params_t::enable_out2
int enable_out2
Definition: ni_device_api.h:2566
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
Definition: ni_device_api.h:1954
ni_query_temperature
ni_retcode_t ni_query_temperature(ni_device_handle_t device_handle, ni_device_temp_t *p_dev_temp, uint8_t fw_rev[])
Query CompositeTemp from device.
Definition: ni_device_api.c:11751
netint_iocmd_export_dmabuf::length
unsigned long length
Definition: ni_p2p_ioctl.h:53
_ni_encoder_cfg_params::level_idc
int level_idc
Definition: ni_device_api.h:2303
NI_ENC_PARAM_ENABLE_AI_HVSPLUS
#define NI_ENC_PARAM_ENABLE_AI_HVSPLUS
Definition: ni_device_api.h:2238
_ni_encoder_cfg_params::HDR10dy2
int HDR10dy2
Definition: ni_device_api.h:2333
netint_iocmd_export_dmabuf::fd
int fd
Definition: ni_p2p_ioctl.h:45
NI_ENC_PARAM_INTRA_QP
#define NI_ENC_PARAM_INTRA_QP
Definition: ni_device_api.h:2144
NI_SCALER_FLAG_P2
#define NI_SCALER_FLAG_P2
Definition: ni_device_api.h:305
NI_ENC_RC_QP_DELTA_RANGE
#define NI_ENC_RC_QP_DELTA_RANGE
Definition: ni_device_api.h:2205
_ni_thread_arg_struct_t::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1274
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1936
NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
Definition: ni_device_api.h:1962
ni_decode_power_measurement
uint32_t ni_decode_power_measurement(uint32_t current_data, const uint8_t *serial_number)
decode the raw current obtained and determine power
Definition: ni_util.c:5009
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1927
NI_FRAME_AUX_DATA_LTR_INTERVAL
@ NI_FRAME_AUX_DATA_LTR_INTERVAL
Definition: ni_device_api.h:566
ni_encoder_frame_buffer_alloc
ni_retcode_t ni_encoder_frame_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
Allocate memory for the frame buffer for encoding based on given parameters, taking into account pic ...
Definition: ni_device_api.c:3174
NI_MAX_NUM_SW_FRAME_DATA_POINTERS
#define NI_MAX_NUM_SW_FRAME_DATA_POINTERS
Definition: ni_defs.h:246
NI_ENC_GOP_PARAMS_G2_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G2_QP_OFFSET
Definition: ni_device_api.h:1900
NI_ENC_PARAM_SAR_DENOM
#define NI_ENC_PARAM_SAR_DENOM
Definition: ni_device_api.h:2226
NI_MAX_QP_INFO
#define NI_MAX_QP_INFO
Definition: ni_device_api.h:175
_ni_encoder_cfg_params::preIntraHandling
int preIntraHandling
Definition: ni_device_api.h:2500
NI_DEC_PARAM_SAVE_PKT
#define NI_DEC_PARAM_SAVE_PKT
Definition: ni_device_api.h:2539
NI_INVALID_SVCT_DECODING_LAYER
#define NI_INVALID_SVCT_DECODING_LAYER
Definition: ni_device_api.h:330
NI_ENC_PARAM_LEVEL
#define NI_ENC_PARAM_LEVEL
Definition: ni_device_api.h:2112
NI_RETCODE_PARAM_INVALID_NAME
@ NI_RETCODE_PARAM_INVALID_NAME
Definition: ni_defs.h:450
_ni_session_context::keep_alive_thread_args
ni_thread_arg_struct_t * keep_alive_thread_args
Definition: ni_device_api.h:1587
NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
Definition: ni_device_api.h:1934
_ni_xcoder_params::color_space
int color_space
Definition: ni_device_api.h:2834
netint_iocmd_issue_request
Definition: ni_p2p_ioctl.h:72
_ni_encoder_cfg_params::baseLayerOnly
int baseLayerOnly
Definition: ni_device_api.h:2501
ni_create_event
ni_event_handle_t ni_create_event(void)
Create event and return event handle if successful (Windows only)
Definition: ni_device_api.c:272
_ni_frame::nb_aux_data
int nb_aux_data
Definition: ni_device_api.h:2748
NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
Definition: ni_device_api.h:1964
_ni_session_context::reconfig_crf
int reconfig_crf
Definition: ni_device_api.h:1715
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
Definition: ni_device_api.h:1939
_ni_encoder_cfg_params::maxFrameSize
int maxFrameSize
Definition: ni_device_api.h:2297
_ni_encoder_cfg_params::hvs_qp_scale
int hvs_qp_scale
Definition: ni_device_api.h:2429
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1951
_ni_encoder_cfg_params::cplxDecay
float cplxDecay
Definition: ni_device_api.h:2460
_ni_instance_mgr_general_status
Definition: ni_device_api_priv.h:79
atoi
#define atoi(p_str)
Definition: ni_device_api.c:7338
_ni_encoder_change_params_t::minQpI
int32_t minQpI
Definition: ni_device_api.h:1011
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:2660
_ni_decoder_input_params_t::skip_extra_headers
int skip_extra_headers
Definition: ni_device_api.h:2606
_ni_instance_mgr_detail_status
Definition: ni_device_api.h:1243
NI_PARAM_MAX_WIDTH
#define NI_PARAM_MAX_WIDTH
Definition: ni_device_api.h:137
_ni_enc_hevc_roi_custom_map
encoder HEVC ROI custom map (1 CTU = 64bits)
Definition: ni_device_api.h:861
END
#define END
Definition: ni_defs.h:338
_ni_decoder_input_params_t::enable_follow_iframe
int enable_follow_iframe
Definition: ni_device_api.h:2601
_ni_encoder_cfg_params::enable_hvs_qp
int enable_hvs_qp
Definition: ni_device_api.h:2428
_ni_device_extra_info
Definition: ni_rsrc_api.h:242
netint_iocmd_export_dmabuf::dev
int dev
Definition: ni_p2p_ioctl.h:49
_ni_frame::video_height
uint32_t video_height
Definition: ni_device_api.h:2681
NI_DEC_PARAM_SCALE_1_ROUND
#define NI_DEC_PARAM_SCALE_1_ROUND
Definition: ni_device_api.h:2536
_ni_decoder_input_params_t::pkt_pts_unchange
int pkt_pts_unchange
Definition: ni_device_api.h:2594
_ni_network_data::inset
ni_network_layer_offset_t * inset
Definition: ni_device_api.h:1382
_ni_packet::p_buffer
void * p_buffer
Definition: ni_device_api.h:2918
ni_custom_packet_buffer_alloc
ni_retcode_t ni_custom_packet_buffer_alloc(void *p_buffer, ni_packet_t *p_packet, int buffer_size)
Allocate packet buffer using a user provided pointer, the memory is expected to have already been all...
Definition: ni_device_api.c:3820
NI_ENC_PARAM_VERTICAL_OFFSET
#define NI_ENC_PARAM_VERTICAL_OFFSET
Definition: ni_device_api.h:2246
ni_reconfig_min_max_qp
ni_retcode_t ni_reconfig_min_max_qp(ni_session_context_t *p_ctx, ni_rc_min_max_qp *p_min_max_qp)
Reconfigure min&max qp dynamically during encoding.
Definition: ni_device_api.c:10417
NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
#define NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
Definition: ni_device_api.h:2279
_ni_decoder_input_params_t::force_8_bit
int force_8_bit[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2569
NI_ENC_PARAM_SLICE_ARG
#define NI_ENC_PARAM_SLICE_ARG
Definition: ni_device_api.h:2152
NI_MAX_MAX_NUM_MERGE
#define NI_MAX_MAX_NUM_MERGE
Definition: ni_device_api.h:165
_ni_vui_hrd::colorSpace
int32_t colorSpace
Definition: ni_device_api.h:681
_ni_encoder_cfg_params::qcomp
float qcomp
Definition: ni_device_api.h:2454
_ni_session_context::low_delay_sync_flag
int low_delay_sync_flag
Definition: ni_device_api.h:1694
NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
#define NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
Max number of lines supported for qpoffset level.
Definition: ni_device_api.h:492
_ni_encoder_cfg_params::avcc_hvcc
int avcc_hvcc
Definition: ni_device_api.h:2495
_ni_decoder_input_params_t::custom_sei_passthru
int custom_sei_passthru
Definition: ni_device_api.h:2586
_ni_xcoder_params::ddr_priority_mode
ni_ddr_priority_mode_t ddr_priority_mode
Definition: ni_device_api.h:2863
_ni_encoder_cfg_params::colorTrc
int colorTrc
Definition: ni_device_api.h:2367
ni_encoder_session_send_eos
ni_retcode_t ni_encoder_session_send_eos(ni_session_context_t *p_ctx)
Flush encoder output.
Definition: ni_device_api_priv.c:3800
_ni_ppu_config::ppu_h
uint16_t ppu_h[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:1431
_ni_session_context::active_video_height
uint32_t active_video_height
Definition: ni_device_api.h:1581
NI_ENC_PARAM_INTRA_PERIOD
#define NI_ENC_PARAM_INTRA_PERIOD
Definition: ni_device_api.h:2140
ni_pthread_mutex_destroy
int ni_pthread_mutex_destroy(ni_pthread_mutex_t *mutex)
destory a mutex
Definition: ni_util.c:4664
ni_device_session_query_buffer_avail
ni_retcode_t ni_device_session_query_buffer_avail(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query the session if a buffer is available.
Definition: ni_device_api.c:8456
ni_p2p_recv
ni_retcode_t ni_p2p_recv(ni_session_context_t *pSession, const ni_p2p_sgl_t *dmaAddrs, ni_frame_t *pDstFrame)
Initiate a P2P transfer (P2P read)
Definition: ni_device_api.c:13052
ni_dump_log_all_cores
ni_retcode_t ni_dump_log_all_cores(ni_session_context_t *p_ctx, void *p_data, bool gen_log_file)
Definition: ni_device_api_priv.c:18824
NI_FRAME_AUX_DATA_LONG_TERM_REF
@ NI_FRAME_AUX_DATA_LONG_TERM_REF
Definition: ni_device_api.h:561
NI_ENC_PARAM_VBV_BUFFER_SIZE
#define NI_ENC_PARAM_VBV_BUFFER_SIZE
Definition: ni_device_api.h:2183
NI_MAX_SEI_DATA
#define NI_MAX_SEI_DATA
Definition: ni_device_api.h:439
_ni_session_context::pkt_delay_cnt
uint32_t pkt_delay_cnt
Definition: ni_device_api.h:1732
_ni_encoder_cfg_params::av1_error_resilient_mode
int av1_error_resilient_mode
Definition: ni_device_api.h:2442
_ni_encoder_cfg_params::tune_bframe_visual
int tune_bframe_visual
Definition: ni_device_api.h:2483
ni_session_keep_alive_thread
void * ni_session_keep_alive_thread(void *arguments)
decoder keep alive thread function triggers every 1 second
Definition: ni_device_api_priv.c:13339
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:12933
_ni_encoder_cfg_params::conf_win_left
int conf_win_left
Definition: ni_device_api.h:2353
NI_MAX_FRAME_SIZE
#define NI_MAX_FRAME_SIZE
Definition: ni_device_api.h:180
_ni_encoder_cfg_params::pass1_qp
int pass1_qp
Definition: ni_device_api.h:2463
_ni_encoder_cfg_params::conf_win_right
int conf_win_right
Definition: ni_device_api.h:2354
ni_enc_hevc_roi_custom_map_t
union _ni_enc_hevc_roi_custom_map ni_enc_hevc_roi_custom_map_t
encoder HEVC ROI custom map (1 CTU = 64bits)
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_3
uint32_t sub_ctu_qp_3
Definition: ni_device_api.h:871
_ni_session_context::blk_dev_name
char blk_dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_device_api.h:1689
_ni_decoder_input_params_t::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:2584
NI_POOL_TYPE_NONE
@ NI_POOL_TYPE_NONE
Definition: ni_device_api.h:504
NI_ENC_PARAM_RC_INIT_DELAY
#define NI_ENC_PARAM_RC_INIT_DELAY
Definition: ni_device_api.h:2161
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1577
NI_NVME_IDENTITY_CMD_DATA_SZ
#define NI_NVME_IDENTITY_CMD_DATA_SZ
Definition: ni_nvme.h:38
_ni_long_term_ref::use_cur_src_as_long_term_pic
uint8_t use_cur_src_as_long_term_pic
Definition: ni_device_api.h:700
_ni_session_context::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:1625
NI_ENC_PARAM_HVS_QP_SCALE
#define NI_ENC_PARAM_HVS_QP_SCALE
Definition: ni_device_api.h:2130
NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2556
_niFrameSurface1::device_handle
int32_t device_handle
Definition: ni_device_api.h:2877
_ni_encoder_cfg_params::crfMax
int crfMax
Definition: ni_device_api.h:2453
_niFrameSurface1::bit_depth
int8_t bit_depth
Definition: ni_device_api.h:2878
NI_ENC_PARAM_DECODING_REFRESH_TYPE
#define NI_ENC_PARAM_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:2145
NI_ENC_GOP_PARAMS_G1_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G1_PIC_TYPE
Definition: ni_device_api.h:1888
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:1680
ni_lat_meas_q_destroy
void ni_lat_meas_q_destroy(ni_lat_meas_q_t *frame_time_q)
Destroy a latency measurement queue object.
Definition: ni_lat_meas.c:97
_ni_encoder_cfg_params::cuTreeFactor
int cuTreeFactor
Definition: ni_device_api.h:2457
_ni_network_layer_info::out_param
ni_network_layer_params_t * out_param
Definition: ni_device_api.h:1368
XCODER_TEST_INVALID_REF_FRAME_API
@ XCODER_TEST_INVALID_REF_FRAME_API
Definition: ni_device_api.h:1802
_ni_encoder_cfg_params::enableipRatio
int enableipRatio
Definition: ni_device_api.h:2475
_ni_enc_quad_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:896
_ni_decoder_input_params_t::scale_resolution_ceil
int scale_resolution_ceil[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2599
ni_device_api.h
Public definitions for operating NETINT video processing devices for video processing.
_ni_device_capability::serial_number
uint8_t serial_number[20]
Definition: ni_device_api.h:1174
NI_ENC_PARAM_LOW_DELAY
#define NI_ENC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2117
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
Definition: ni_device_api.h:1980
NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
#define NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
Definition: ni_device_api.h:2269
_ni_session_context::meta_size
uint32_t meta_size
Params used in VFR mode Done///.
Definition: ni_device_api.h:1668
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:8647
_ni_encoder_cfg_params::vbv_min_rate
int vbv_min_rate
Definition: ni_device_api.h:2479
NI_ENC_PARAM_PPS_INIT_QP
#define NI_ENC_PARAM_PPS_INIT_QP
Definition: ni_device_api.h:2256
_ni_encoder_cfg_params::HDR10MaxLight
int HDR10MaxLight
Definition: ni_device_api.h:2324
_ni_xcoder_params::cacheRoi
int cacheRoi
Definition: ni_device_api.h:2821
_ni_session_context::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1512
_ni_encoder_cfg_params::still_image_detect_level
int still_image_detect_level
Definition: ni_device_api.h:2488
_ni_encoder_change_params_t::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:1012
_ni_encoder_cfg_params::crop_height
int crop_height
Definition: ni_device_api.h:2450
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1966
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1506
_ni_encoder_cfg_params::aspectRatioHeight
int aspectRatioHeight
Definition: ni_device_api.h:2295
NI_MIN_HEIGHT
#define NI_MIN_HEIGHT
Definition: ni_device_api.h:128
NI_BEST_REAL_LOAD_STR
#define NI_BEST_REAL_LOAD_STR
Definition: ni_device_api.h:42
NI_RETCODE_FAILURE
@ NI_RETCODE_FAILURE
Definition: ni_defs.h:442
NI_ENC_PARAM_GEN_HDRS
#define NI_ENC_PARAM_GEN_HDRS
Definition: ni_device_api.h:2107
_ni_encoder_cfg_params::HDR10dx1
int HDR10dx1
Definition: ni_device_api.h:2330
ni_strcat
ni_retcode_t ni_strcat(char *dest, size_t dmax, const char *src)
Definition: ni_util.c:685
NI_ENC_PARAM_PSNR_INTERVAL
#define NI_ENC_PARAM_PSNR_INTERVAL
Definition: ni_device_api.h:2271
XCODER_TEST_RECONF_BR
@ XCODER_TEST_RECONF_BR
Definition: ni_device_api.h:1778
_ni_aux_data::type
ni_aux_data_type_t type
Definition: ni_device_api.h:633
NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
Definition: ni_device_api.h:1932
ni_ai_alloc_hwframe
ni_retcode_t ni_ai_alloc_hwframe(ni_session_context_t *p_ctx, int width, int height, int options, int pool_size, int frame_index)
Definition: ni_device_api_priv.c:17986
NI_ENC_PARAM_ROI_ENABLE
#define NI_ENC_PARAM_ROI_ENABLE
Definition: ni_device_api.h:2135
NI_BEST_MODEL_LOAD_STR
#define NI_BEST_MODEL_LOAD_STR
Definition: ni_device_api.h:41
NI_ENC_PARAM_MIN_QP
#define NI_ENC_PARAM_MIN_QP
Definition: ni_device_api.h:2131
NI_MIN_BITRATE
#define NI_MIN_BITRATE
Definition: ni_device_api.h:116
_niFrameSurface1::dma_buf_fd
int32_t dma_buf_fd
Definition: ni_device_api.h:2882
_ni_encoder_cfg_params::planar
int planar
Definition: ni_device_api.h:2296
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
Definition: ni_device_api.h:1937
_ni_buf_t::buf
void * buf
Definition: ni_device_api.h:1287
_ni_session_context::reconfigCount
int reconfigCount
Definition: ni_device_api.h:1728
NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
Definition: ni_device_api.h:1904
_ni_packet::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2919
_ni_instance_mgr_general_status::fw_load
uint8_t fw_load
Definition: ni_device_api_priv.h:97
_ni_device_pool
Definition: ni_rsrc_api.h:96
NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_SMALL
Definition: ni_defs.h:514
_ni_vui_hrd::videoFullRange
int32_t videoFullRange
Definition: ni_device_api.h:692
NI_ENC_PARAM_VBV_MINRATE
#define NI_ENC_PARAM_VBV_MINRATE
Definition: ni_device_api.h:2264
_ni_log_fl_fw_versions::nor_flash_fl_version
uint8_t nor_flash_fl_version[NI_VERSION_CHARACTER_COUNT]
Definition: ni_device_api_priv.h:117
_ni_vui_hrd::aspectRatioHeight
int32_t aspectRatioHeight
Definition: ni_device_api.h:688
_ni_session_context::hdr_buf_size
uint8_t hdr_buf_size
Definition: ni_device_api.h:1542
_ni_instance_mgr_detail_status_v1
Definition: ni_device_api.h:1265
_ni_xcoder_params::enable_vfr
int enable_vfr
Definition: ni_device_api.h:2854
_ni_frame::inconsecutive_transfer
uint8_t inconsecutive_transfer
Definition: ni_device_api.h:2778
_ni_session_context::last_framerate
ni_framerate_t last_framerate
Definition: ni_device_api.h:1705
NI_ENC_PARAM_FRAME_RATE
#define NI_ENC_PARAM_FRAME_RATE
Definition: ni_device_api.h:2142
_ni_session_context::ltr_frame_ref_invalid
int32_t ltr_frame_ref_invalid
Definition: ni_device_api.h:1633
NI_SCALER_FLAG_PC
#define NI_SCALER_FLAG_PC
Definition: ni_device_api.h:303
_ni_encoder_cfg_params::rdoLevel
int rdoLevel
Definition: ni_device_api.h:2322
_ni_encoder_cfg_params::long_term_ref_enable
int long_term_ref_enable
Definition: ni_device_api.h:2313
NETINT_IOCTL_ISSUE_REQ
#define NETINT_IOCTL_ISSUE_REQ
Definition: ni_p2p_ioctl.h:99
NI_RETCODE_PARAM_ERROR_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_TOO_SMALL
Definition: ni_defs.h:504
_ni_encoder_cfg_params::get_psnr_mode
int get_psnr_mode
Definition: ni_device_api.h:2485
ni_device_capability_query2
ni_retcode_t ni_device_capability_query2(ni_device_handle_t device_handle, ni_device_capability_t *p_cap, bool device_in_ctxt)
Query device and return device capability structure This function had replaced ni_device_capability_q...
Definition: ni_device_api.c:659
ni_codec_format_t
enum _ni_codec_format ni_codec_format_t
This is an enumeration for supported codec formats.
ni_util.h
Utility definitions.
_ni_session_context::av1_pkt_num
uint64_t av1_pkt_num
Definition: ni_device_api.h:1725
_ni_encoder_cfg_params::ltrNextInterval
int ltrNextInterval
Definition: ni_device_api.h:2342
_ni_decoder_input_params_t::survive_stream_err
int survive_stream_err
Definition: ni_device_api.h:2604
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
Definition: ni_device_api.h:1894
NI_ENC_PARAM_LOG_LEVEL
#define NI_ENC_PARAM_LOG_LEVEL
Definition: ni_device_api.h:2114
COMPARE
#define COMPARE(STR1, STR2, STR3)
NI_ENC_PARAM_GOP_SIZE
#define NI_ENC_PARAM_GOP_SIZE
Definition: ni_device_api.h:2178
_ni_encoder_cfg_params::videoFullRange
int videoFullRange
Definition: ni_device_api.h:2344
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:8370
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:8203
ni_get_memory_offset
ni_retcode_t ni_get_memory_offset(ni_session_context_t *p_ctx, const niFrameSurface1_t *hwdesc, uint32_t *p_offset)
Get an address offset from a hw descriptor.
Definition: ni_device_api_priv.c:16266
_ni_encoder_cfg_params::intra_reset_refresh
int intra_reset_refresh
Definition: ni_device_api.h:2443
NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
#define NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
Definition: ni_device_api.h:2267
_ni_scaler_input_params_t::in_rec_height
int32_t in_rec_height
Definition: ni_device_api.h:2615
NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2265
_ni_encoder_cfg_params::slice_arg
int slice_arg
Definition: ni_device_api.h:2412
NI_ENC_PARAM_ENABLE_TIMECODE
#define NI_ENC_PARAM_ENABLE_TIMECODE
Definition: ni_device_api.h:2277
_ni_frame::p_metadata_buffer
uint8_t * p_metadata_buffer
Definition: ni_device_api.h:2765
TOTAL_CPU_LOG_BUFFER_SIZE
#define TOTAL_CPU_LOG_BUFFER_SIZE
Definition: ni_defs.h:374
g_device_in_ctxt
NI_DEPRECATED bool g_device_in_ctxt
Definition: ni_rsrc_api.cpp:63
NI_ENC_PARAM_ENABLE_2PASS_GOP
#define NI_ENC_PARAM_ENABLE_2PASS_GOP
Definition: ni_device_api.h:2239
_ni_rc_min_max_qp::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:720
lower_pixel_rate
int lower_pixel_rate(const ni_load_query_t *pQuery, uint32_t ui32CurrentLowest)
Definition: ni_device_api_priv.c:18966
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
Definition: ni_device_api.h:1982
NI_ENC_CTB_ROW_QP_STEP
#define NI_ENC_CTB_ROW_QP_STEP
Definition: ni_device_api.h:2206
_ni_device_temp::composite_temp
int32_t composite_temp
Definition: ni_rsrc_api.h:237
ni_frame_buffer_alloc_dl
ni_retcode_t ni_frame_buffer_alloc_dl(ni_frame_t *p_frame, int video_width, int video_height, int pixel_format)
Allocate preliminary memory for the frame buffer based on provided parameters.
Definition: ni_device_api.c:2405
_ni_encoder_cfg_params::lookAheadDepth
int lookAheadDepth
Definition: ni_device_api.h:2321
NI_RETCODE_ERROR_INVALID_HANDLE
@ NI_RETCODE_ERROR_INVALID_HANDLE
Definition: ni_defs.h:525
NI_XCODER_LOG_NAME_DEBUG
#define NI_XCODER_LOG_NAME_DEBUG
Definition: ni_device_api.h:2963
NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
#define NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
Definition: ni_device_api.h:2157
NI_FRAME_AUX_DATA_CRF_FLOAT
@ NI_FRAME_AUX_DATA_CRF_FLOAT
Definition: ni_device_api.h:591
AV_CODEC_DEFAULT_BITRATE
#define AV_CODEC_DEFAULT_BITRATE
Definition: ni_device_api.h:55
_ni_session_context::hevc_roi_map
ni_enc_hevc_roi_custom_map_t * hevc_roi_map
Definition: ni_device_api.h:1619
_ni_custom_gop_params::pic_param
ni_gop_params_t pic_param[NI_MAX_GOP_NUM]
Definition: ni_device_api.h:2089
NI_ENC_PARAM_ENABLE_PIC_SKIP
#define NI_ENC_PARAM_ENABLE_PIC_SKIP
Definition: ni_device_api.h:2186
ni_encoder_session_read
int ni_encoder_session_read(ni_session_context_t *p_ctx, ni_packet_t *p_packet)
Definition: ni_device_api_priv.c:4635
ni_aligned_free
#define ni_aligned_free(p_memptr)
Definition: ni_util.h:399
_ni_session_context::dev
unsigned short dev
Definition: ni_device_api.h:1651
_ni_decoder_input_params_t::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:2582
_ni_xcoder_params::low_delay_mode
int low_delay_mode
Definition: ni_device_api.h:2807
_ni_decoder_input_params_t::nb_save_pkt
int nb_save_pkt
Definition: ni_device_api.h:2568
_ni_device_vf_ns_id::vf_id
uint16_t vf_id
Definition: ni_rsrc_api.h:231
NI_MAX_GOP_PRESET_IDX
#define NI_MAX_GOP_PRESET_IDX
Definition: ni_device_api.h:154
ni_uploader_p2p_test_load
ni_retcode_t ni_uploader_p2p_test_load(ni_session_context_t *p_upl_ctx, uint8_t *p_data, uint32_t len, ni_frame_t *p_hwframe)
Special P2P test API function. Copies video data from the software frame to the hardware P2P frame on...
Definition: ni_device_api.c:11093
NI_ENC_PARAM_ENABLE_COMPENSATE_QP
#define NI_ENC_PARAM_ENABLE_COMPENSATE_QP
Definition: ni_device_api.h:2219
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:1524
NI_RETCODE_PARAM_ERROR_ZERO
@ NI_RETCODE_PARAM_ERROR_ZERO
Definition: ni_defs.h:506
_ni_session_context::pkt_num
uint64_t pkt_num
Definition: ni_device_api.h:1562
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1908
NI_ENC_ENABLE_SSIM
#define NI_ENC_ENABLE_SSIM
Definition: ni_device_api.h:2231
_ni_encoder_cfg_params::enable_cu_level_rate_control
int enable_cu_level_rate_control
Definition: ni_device_api.h:2427
_ni_decoder_input_params_t::disable_adaptive_buffers
int disable_adaptive_buffers
Definition: ni_device_api.h:2602
NI_CODEC_FORMAT_H264
@ NI_CODEC_FORMAT_H264
Definition: ni_device_api.h:924
_ni_device_temp::on_die_temp
int32_t on_die_temp
Definition: ni_rsrc_api.h:239
ni_ai_session_read_hwdesc
ni_retcode_t ni_ai_session_read_hwdesc(ni_session_context_t *p_ctx, ni_frame_t *p_frame)
read a hardware descriptor from a scaler session
Definition: ni_device_api_priv.c:18180
NI_ENC_GOP_PARAMS_G6_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G6_QP_OFFSET
Definition: ni_device_api.h:1960
NI_FRAME_AUX_DATA_INVALID_REF_FRAME
@ NI_FRAME_AUX_DATA_INVALID_REF_FRAME
Definition: ni_device_api.h:571
_ni_thread_arg_struct_t::plast_access_time
volatile uint64_t * plast_access_time
Definition: ni_device_api.h:1282
NETINT_IOCTL_SIGNAL_RFENCE
#define NETINT_IOCTL_SIGNAL_RFENCE
Definition: ni_p2p_ioctl.h:97
_ni_frame::start_buffer_size
uint32_t start_buffer_size
Definition: ni_device_api.h:2773
NI_MAX_BIN
#define NI_MAX_BIN
Definition: ni_device_api.h:176
NI_ENC_GOP_PARAMS_G0_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PICS
Definition: ni_device_api.h:1874
NI_MAX_BITRATE
#define NI_MAX_BITRATE
Definition: ni_device_api.h:115
NI_RETCODE_PARAM_ERROR_OOR
@ NI_RETCODE_PARAM_ERROR_OOR
Definition: ni_defs.h:507
NI_ENC_GOP_PARAMS_G1_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G1_POC_OFFSET
Definition: ni_device_api.h:1884
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2680
_ni_session_context::initial_frame_delay
int initial_frame_delay
Definition: ni_device_api.h:1722
_ni_input_frame
Definition: ni_device_api.h:1409
NI_FRAME_LITTLE_ENDIAN
#define NI_FRAME_LITTLE_ENDIAN
Definition: ni_device_api.h:110
_ni_xcoder_params::bitrate
int bitrate
Definition: ni_device_api.h:2803
_ni_encoder_cfg_params::HDR10wy
int HDR10wy
Definition: ni_device_api.h:2335
netint_iocmd_signal_rfence
Definition: ni_p2p_ioctl.h:87
NI_MIN_WIDTH
#define NI_MIN_WIDTH
Definition: ni_device_api.h:126
NI_DEC_PARAM_FORCE_LOW_DELAY
#define NI_DEC_PARAM_FORCE_LOW_DELAY
Definition: ni_device_api.h:2541
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_uploader_frame_zerocopy_check
ni_retcode_t ni_uploader_frame_zerocopy_check(ni_session_context_t *p_upl_ctx, int width, int height, const int linesize[], int pixel_format)
Check if incoming frame is hwupload zero copy compatible or not.
Definition: ni_device_api.c:3041
_ni_encoder_cfg_params::preferred_transfer_characteristics
int preferred_transfer_characteristics
Definition: ni_device_api.h:2319
ni_device_session_init_framepool
int ni_device_session_init_framepool(ni_session_context_t *p_ctx, uint32_t pool_size, uint32_t pool)
Sends frame pool setup info to device.
Definition: ni_device_api.c:8724
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1646
_ni_xcoder_params::use_low_delay_poc_type
int use_low_delay_poc_type
Definition: ni_device_api.h:2810
_ni_device_queue::xcoder_cnt
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
Definition: ni_rsrc_api.h:69
_ni_encoder_cfg_params::conf_win_top
int conf_win_top
Definition: ni_device_api.h:2351
NI_ENC_PARAM_TOTAL_CUTREE_DEPTH
#define NI_ENC_PARAM_TOTAL_CUTREE_DEPTH
Definition: ni_device_api.h:2281
QUADRA
#define QUADRA
Definition: ni_defs.h:123
NI_ENC_PARAM_PASS1_QP
#define NI_ENC_PARAM_PASS1_QP
Definition: ni_device_api.h:2259
_ni_device_info::load
int load
Definition: ni_rsrc_api.h:108
NI_ENC_GOP_PARAMS_G0_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G0_TEMPORAL_ID
Definition: ni_device_api.h:1872
ni_ai_network_layer_size
uint32_t ni_ai_network_layer_size(ni_network_layer_params_t *p_param)
Definition: ni_util.c:3985
NI_DEC_PARAM_DDR_PRIORITY_MODE
#define NI_DEC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2547
MAX_CHAR_IN_DEVICE_NAME
#define MAX_CHAR_IN_DEVICE_NAME
Definition: ni_device_api.h:187
g_xcoder_preset_names
const char *const g_xcoder_preset_names[NI_XCODER_PRESET_NAMES_ARRAY_LEN]
Definition: ni_device_api.c:69
NI_ENC_PARAM_CUSTOMIZE_ROI_QP_MAP
#define NI_ENC_PARAM_CUSTOMIZE_ROI_QP_MAP
Definition: ni_device_api.h:2273
_ni_encoder_cfg_params::bitrateMode
int bitrateMode
Definition: ni_device_api.h:2462
ni_p2p_send
ni_retcode_t ni_p2p_send(ni_session_context_t *pSession, niFrameSurface1_t *source, uint64_t ui64DestAddr, uint32_t ui32FrameSize)
Initiate P2P transfer (P2P write)
Definition: ni_device_api.c:13008
NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
#define NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
Definition: ni_device_api.h:2543
_ni_aux_data
Definition: ni_device_api.h:631
_ni_scaler_input_params_t::in_rec_width
int32_t in_rec_width
Definition: ni_device_api.h:2614
NI_PIXEL_PLANAR_FORMAT_TILED4X4
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
Definition: ni_device_api.h:935
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:64
_ni_framerate
Definition: ni_device_api.h:708
_ni_vui_hrd::aspectRatioWidth
int32_t aspectRatioWidth
Definition: ni_device_api.h:685
NI_ENC_PARAM_SLICE_MODE
#define NI_ENC_PARAM_SLICE_MODE
Definition: ni_device_api.h:2151
ni_uploader_p2p_test_send
ni_retcode_t ni_uploader_p2p_test_send(ni_session_context_t *p_upl_ctx, uint8_t *p_data, uint32_t len, ni_frame_t *p_hwframe)
Special P2P test API function. Copies YUV data from the software frame to the hardware P2P frame on t...
Definition: ni_device_api.c:11038
NI_MAX_RESOLUTION_LINESIZE
#define NI_MAX_RESOLUTION_LINESIZE
Definition: ni_device_api.h:108
NI_FRAME_AUX_DATA_INTRAPRD
@ NI_FRAME_AUX_DATA_INTRAPRD
Definition: ni_device_api.h:552
NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
#define NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
Definition: ni_device_api.h:2093
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:3707
_ni_xcoder_params::dec_input_params
ni_decoder_input_params_t dec_input_params
Definition: ni_device_api.h:2842
netint_iocmd_export_dmabuf::offset
unsigned long offset
Definition: ni_p2p_ioctl.h:52
QOS_OP_CONFIG_CODE
@ QOS_OP_CONFIG_CODE
Definition: ni_device_api.h:241
_ni_xcoder_params::color_transfer_characteristic
int color_transfer_characteristic
Definition: ni_device_api.h:2833
_ni_custom_gop_params
Definition: ni_device_api.h:2086
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:1391
NI_DEC_PARAM_ENABLE_PPU_SCALE_ADAPT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_ADAPT
Definition: ni_device_api.h:2551
NI_PARAM_MIN_HEIGHT
#define NI_PARAM_MIN_HEIGHT
Definition: ni_device_api.h:140
_ni_enc_quad_roi_custom_map::qp_info
uint8_t qp_info
Definition: ni_device_api.h:902
_ni_gop_params::temporal_id
int temporal_id
Definition: ni_device_api.h:2000
NI_PIXEL_PLANAR_FORMAT_PLANAR
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
Definition: ni_device_api.h:934
_ni_rc_min_max_qp::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:721
NI_DEFAULT_CU_SIZE_MODE
#define NI_DEFAULT_CU_SIZE_MODE
Definition: ni_device_api.h:160
ni_encoder_session_sequence_change
ni_retcode_t ni_encoder_session_sequence_change(ni_session_context_t *p_ctx, ni_resolution_t *p_resolution)
Send sequnce change to a xcoder encoder instance.
Definition: ni_device_api_priv.c:5079
ni_fopen
ni_retcode_t ni_fopen(FILE **fp, const char *filename, const char *mode)
Definition: ni_util.c:979
NI_MIN_GOP_PRESET_IDX
#define NI_MIN_GOP_PRESET_IDX
Definition: ni_device_api.h:155
NI_XCODER_FLUSH_STATE
@ NI_XCODER_FLUSH_STATE
Definition: ni_device_api.h:253
NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
Definition: ni_device_api.h:2127
NI_DEC_PARAM_SEMI_PLANAR_2
#define NI_DEC_PARAM_SEMI_PLANAR_2
Definition: ni_device_api.h:2519
ni_set_ltr
ni_retcode_t ni_set_ltr(ni_session_context_t *p_ctx, ni_long_term_ref_t *ltr)
Set a frame's support of Long Term Reference frame during encoding.
Definition: ni_device_api.c:10192
NI_MAX_INTRA_QP_DELTA
#define NI_MAX_INTRA_QP_DELTA
Definition: ni_device_api.h:169
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:3657
_ni_session_context::roi_avg_qp
uint32_t roi_avg_qp
Definition: ni_device_api.h:1527
ni_decoder_session_close
ni_retcode_t ni_decoder_session_close(ni_session_context_t *p_ctx, int eos_recieved)
Close a xcoder decoder instance.
Definition: ni_device_api_priv.c:1638
NI_MAX_ASPECTRATIO
#define NI_MAX_ASPECTRATIO
Definition: ni_device_api.h:119
ni_reconfig_slice_arg
ni_retcode_t ni_reconfig_slice_arg(ni_session_context_t *p_ctx, int16_t sliceArg)
Reconfigure sliceArg dynamically during encoding.
Definition: ni_device_api.c:10707
NI_BITRATE_RECONFIG_FILE_MAX_LINES
#define NI_BITRATE_RECONFIG_FILE_MAX_LINES
Max number of lines supported for the bitrate reconfig file.
Definition: ni_device_api.h:486
_ni_session_context::force_low_delay_cnt
uint32_t force_low_delay_cnt
Definition: ni_device_api.h:1730
NI_MAX_RESOLUTION_AREA
#define NI_MAX_RESOLUTION_AREA
Definition: ni_device_api.h:104
_ni_xcoder_params::p_first_frame
ni_frame_t * p_first_frame
Definition: ni_device_api.h:2852
NI_DMABUF_WRITE_TO_DEVICE
@ NI_DMABUF_WRITE_TO_DEVICE
Definition: ni_p2p_ioctl.h:40
NI_ENC_PARAM_HVSPLUS_LEVEL
#define NI_ENC_PARAM_HVSPLUS_LEVEL
Definition: ni_device_api.h:2242
NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
Definition: ni_device_api.h:1889
_ni_session_context::p_master_display_meta_data
void * p_master_display_meta_data
Definition: ni_device_api.h:1460
ni_rsrc_get_device_by_block_name
int ni_rsrc_get_device_by_block_name(const char *blk_name, ni_device_type_t device_type)
Get GUID of the device by block device name and type.
Definition: ni_rsrc_api.cpp:1831
NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2558
_ni_encoder_cfg_params::forced_header_enable
int forced_header_enable
Definition: ni_device_api.h:2312
NI_DEC_PARAM_MIN_PACKETS_DELAY
#define NI_DEC_PARAM_MIN_PACKETS_DELAY
Definition: ni_device_api.h:2542
_ni_encoder_cfg_params::spatial_layers_ref_base_layer
int spatial_layers_ref_base_layer
Definition: ni_device_api.h:2496
_ni_session_context::async_mode
int async_mode
Definition: ni_device_api.h:1693
NI_FRAME_AUX_DATA_BITRATE
@ NI_FRAME_AUX_DATA_BITRATE
Definition: ni_device_api.h:548
NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
@ NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
Definition: ni_defs.h:521
NI_ENC_PARAM_ADAPTIVE_CUTREE
#define NI_ENC_PARAM_ADAPTIVE_CUTREE
Definition: ni_device_api.h:2282
IDENTIFY_DEVICE_R
#define IDENTIFY_DEVICE_R
Definition: ni_nvme.h:687
NI_DEC_PARAM_SCALE_1_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_1_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2530
_ni_scaler_input_params_t::output_format
int output_format
Definition: ni_device_api.h:2619
NI_RETCODE_ERROR_OPEN_DEVICE
@ NI_RETCODE_ERROR_OPEN_DEVICE
Definition: ni_defs.h:524
NI_CODEC_FORMAT_H265
@ NI_CODEC_FORMAT_H265
Definition: ni_device_api.h:925
_ni_scaler_input_params_t::output_width
int32_t output_width
Definition: ni_device_api.h:2620
NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
#define NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
Definition: ni_device_api.h:2213
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:4128
_ni_session_context::last_access_time
volatile uint64_t last_access_time
Definition: ni_device_api.h:1713
_ni_packet::data_len
uint32_t data_len
Definition: ni_device_api.h:2915
NI_MIN_INTRA_QP
#define NI_MIN_INTRA_QP
Definition: ni_device_api.h:168
NI_DEC_PARAM_CROP_MODE_1
#define NI_DEC_PARAM_CROP_MODE_1
Definition: ni_device_api.h:2521