libxcoder  5.5.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 
84  0};
85 #if __linux__ || __APPLE__
86 static struct stat g_nvme_stat = { 0 };
87 
88 static int close_fd_zero_atexit = 0;
89 
90 static void close_fd_zero(void)
91 {
92  close(0);
93 }
94 
95 #endif
96 
97 /*!*****************************************************************************
98  * \brief Allocate and initialize a new ni_session_context_t struct
99  *
100  *
101  * \return On success returns a valid pointer to newly allocated context
102  * On failure returns NULL
103  ******************************************************************************/
105 {
106  ni_session_context_t *p_ctx = NULL;
107 
108  p_ctx = malloc(sizeof(ni_session_context_t));
109  if (!p_ctx)
110  {
112  "ERROR: %s() Failed to allocate memory for session context\n",
113  __func__);
114  } else
115  {
116  memset(p_ctx, 0, sizeof(ni_session_context_t));
117 
119  {
120  ni_log(NI_LOG_ERROR, "ERROR: %s() Failed to init session context\n",
121  __func__);
123  return NULL;
124  }
125  }
126  return p_ctx;
127 }
128 
129 /*!*****************************************************************************
130  * \brief Free previously allocated session context
131  *
132  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
133  * struct
134  *
135  ******************************************************************************/
137 {
138  if (p_ctx)
139  {
141 #ifdef MEASURE_LATENCY
142  if (p_ctx->frame_time_q)
143  {
145  }
146 #endif
147  free(p_ctx);
148  }
149 }
150 
151 /*!*****************************************************************************
152  * \brief Initialize already allocated session context to a known state
153  *
154  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
155  * struct
156  * \return On success
157  * NI_RETCODE_SUCCESS
158  * On failure
159  * NI_RETCODE_INVALID_PARAM
160  * NI_RETCODE_FAILURE
161  ******************************************************************************/
163 {
164  int bitrate = 0;
165  int framerate_num = 0;
166  int framerate_denom = 0;
167 
168  if (!p_ctx)
169  {
171  }
172 
174  {
175  // session context will reset so save the last values for sequence change
176  if (p_ctx->last_bitrate < NI_MIN_BITRATE)
177  bitrate = NI_MIN_BITRATE;
178  else if (p_ctx->last_bitrate > NI_MAX_BITRATE)
179  bitrate = NI_MAX_BITRATE;
180  else
181  bitrate = p_ctx->last_bitrate;
182  framerate_num = p_ctx->last_framerate.framerate_num;
183  framerate_denom = p_ctx->last_framerate.framerate_denom;
184  }
185 
186  memset(p_ctx, 0, sizeof(ni_session_context_t));
187 
188  p_ctx->last_bitrate = bitrate;
189  p_ctx->last_framerate.framerate_num = framerate_num;
190  p_ctx->last_framerate.framerate_denom = framerate_denom;
191 
192  // Xcoder thread mutex init
193  if (ni_pthread_mutex_init(&p_ctx->mutex))
194  {
195  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): init xcoder_mutex fail, return\n",
196  __func__);
197  return NI_RETCODE_FAILURE;
198  }
199  p_ctx->pext_mutex = &p_ctx->mutex; //used exclusively for hwdl
200 
201  // low delay send/recv sync init
203  {
204  ni_log2(p_ctx, NI_LOG_ERROR,
205  "ERROR %s(): init xcoder_low_delay_sync_mutex fail return\n",
206  __func__);
207  return NI_RETCODE_FAILURE;
208  }
209  if (ni_pthread_cond_init(&p_ctx->low_delay_sync_cond, NULL))
210  {
211  ni_log2(p_ctx, NI_LOG_ERROR,
212  "ERROR %s(): init xcoder_low_delay_sync_cond fail return\n",
213  __func__);
214  return NI_RETCODE_FAILURE;
215  }
216 
217  p_ctx->mutex_initialized = true;
218 
219  // Init the max IO size to be invalid
223  p_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
224  p_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
225  p_ctx->hw_id = NI_INVALID_HWID;
226  p_ctx->event_handle = NI_INVALID_EVENT_HANDLE;
227  p_ctx->thread_event_handle = NI_INVALID_EVENT_HANDLE;
229  p_ctx->keep_alive_thread = (ni_pthread_t){0};
231  p_ctx->decoder_low_delay = 0;
232  p_ctx->enable_low_delay_check = 0;
233  p_ctx->low_delay_sync_flag = 0;
234  p_ctx->async_mode = 0;
236  p_ctx->buffered_frame_index = 0;
237  p_ctx->ppu_reconfig_pkt_pos = 0;
238  p_ctx->headers_length = 0;
239  // by default, select the least model load card
242 #ifdef MY_SAVE
243  p_ctx->debug_write_ptr = NULL;
244  p_ctx->debug_write_index_ptr = NULL;
245  p_ctx->debug_write_sent_size = 0;
246 #endif
247 
248 #ifdef MEASURE_LATENCY
249  p_ctx->frame_time_q = (void *)ni_lat_meas_q_create(2000);
250 #endif
251 
252  return NI_RETCODE_SUCCESS;
253 }
254 
255 /*!*****************************************************************************
256  * \brief Clear already allocated session context
257  *
258  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
259  *
260  *
261  ******************************************************************************/
263 {
264  if(p_ctx->mutex_initialized)
265  {
266  p_ctx->mutex_initialized = false;
270  }
271 }
272 
273 /*!*****************************************************************************
274  * \brief Create event and return event handle if successful (Windows only)
275  *
276  * \return On success returns a event handle
277  * On failure returns NI_INVALID_EVENT_HANDLE
278  ******************************************************************************/
279 ni_event_handle_t ni_create_event(void)
280 {
281 #ifdef _WIN32
282  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
283 
284  // Input-0 determines whether the returned handle can be inherited by the child process.If lpEventAttributes is NULL, this handle cannot be inherited.
285  // 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.
286  // Input-2 specifies the initial state of the event object.If TRUE, the initial state is signaled;Otherwise, no signal state.
287  // Input-3 If the lpName is NULL, a nameless event object is created.。
288  event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
289  if (event_handle == NULL)
290  {
291  ni_log(NI_LOG_ERROR, "ERROR %d: %s() create event failed\n",
292  NI_ERRNO, __func__);
293  return NI_INVALID_EVENT_HANDLE;
294  }
295  return event_handle;
296 #else
297  return NI_INVALID_EVENT_HANDLE;
298 #endif
299 }
300 
301 /*!*****************************************************************************
302  * \brief Close event and release resources (Windows only)
303  *
304  * \return NONE
305  *
306  ******************************************************************************/
307 void ni_close_event(ni_event_handle_t event_handle)
308 {
309  if ( NI_INVALID_DEVICE_HANDLE == event_handle )
310  {
311  ni_log(NI_LOG_DEBUG, "Warning %s: null parameter passed %x\n", __func__,
312  event_handle);
313  return;
314  }
315 
316  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
317 
318 #ifdef _WIN32
319  BOOL retval;
320  ni_log(NI_LOG_DEBUG, "%s(): closing %p\n", __func__, event_handle);
321 
322  retval = CloseHandle(event_handle);
323  if (FALSE == retval)
324  {
325  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): closing event_handle %p failed\n",
326  NI_ERRNO, __func__, event_handle);
327  }
328  else
329  {
330  ni_log(NI_LOG_DEBUG, "%s(): device %p closed successfuly\n", __func__,
331  event_handle);
332  }
333 #else
334  int err = 0;
335  ni_log(NI_LOG_DEBUG, "%s(): closing %d\n", __func__, event_handle);
336  err = close(event_handle);
337  if (err)
338  {
339  char error_message[100] = {'\0'};
340  char unknown_error_message[20] = {'\0'};
341  ni_sprintf(error_message, 100, "ERROR: %s(): ", __func__);
342  switch (err)
343  {
344  case EBADF:
345  ni_strcat(error_message, 100, "EBADF\n");
346  break;
347  case EINTR:
348  ni_strcat(error_message, 100, "EINTR\n");
349  break;
350  case EIO:
351  ni_strcat(error_message, 100, "EIO\n");
352  break;
353  default:
354  ni_sprintf(unknown_error_message, 20, "Unknown error %d\n", err);
355  ni_strcat(error_message, 100, unknown_error_message);
356  }
357  ni_log(NI_LOG_ERROR, "%s\n", error_message);
358  }
359 #endif
360  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
361 }
362 
363 #ifndef DEPRECATION_AS_ERROR
364 /*!*****************************************************************************
365  * \brief Open device and return device device_handle if successful
366  *
367  * \param[in] p_dev Device name represented as c string. ex: "/dev/nvme0"
368  * \param[out] p_max_io_size_out Maximum IO Transfer size supported, could be
369  * NULL
370  *
371  * \return On success returns a device device_handle
372  * On failure returns NI_INVALID_DEVICE_HANDLE
373  ******************************************************************************/
374 NI_DEPRECATED ni_device_handle_t ni_device_open(const char * p_dev, uint32_t * p_max_io_size_out)
375 {
376 #ifdef _WIN32
377  DWORD retval;
378  HANDLE device_handle;
379 
380  if (!p_dev)
381  {
382  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
383  return NI_INVALID_DEVICE_HANDLE;
384  }
385 
386  if (p_max_io_size_out != NULL && *p_max_io_size_out == NI_INVALID_IO_SIZE)
387  {
388  // For now, we just use it to allocate p_leftover buffer
389  // NI_MAX_PACKET_SZ is big enough
390  *p_max_io_size_out = NI_MAX_PACKET_SZ;
391  }
392 
393  device_handle = CreateFile(p_dev, GENERIC_READ | GENERIC_WRITE,
394  FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
395  OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
396 
397  ni_log(NI_LOG_DEBUG, "%s() device_name: %s", __func__, p_dev);
398  if (INVALID_HANDLE_VALUE == device_handle)
399  {
400  retval = GetLastError();
401  ni_log(NI_LOG_ERROR, "Failed to open %s, retval %d \n", p_dev, retval);
402  } else
403  {
404  ni_log(NI_LOG_DEBUG, "Found NVME Controller at %s \n", p_dev);
405  }
406 
407  return device_handle;
408 #else
409  int retval = -1;
410  ni_device_handle_t fd = NI_INVALID_DEVICE_HANDLE;
411 
412  if (!p_dev)
413  {
414  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
416  }
417 
418  if (p_max_io_size_out != NULL && *p_max_io_size_out == NI_INVALID_IO_SIZE)
419  {
420 #if __linux__
421  *p_max_io_size_out = ni_get_kernel_max_io_size(p_dev);
422 #elif __APPLE__
423  *p_max_io_size_out = MAX_IO_TRANSFER_SIZE;
424 #endif
425  }
426 
427  ni_log(NI_LOG_DEBUG, "%s: opening regular-io enabled %s\n", __func__,
428  p_dev);
429  //O_SYNC is added to ensure that data is written to the card when the pread/pwrite function returns
430  #if __linux__
431  //O_DIRECT is added to ensure that data can be sent directly to the card instead of to cache memory
432  fd = open(p_dev, O_RDWR | O_SYNC | O_DIRECT);
433  #elif __APPLE__
434  //O_DIRECT isn't available, so instead we use F_NOCACHE below
435  fd = open(p_dev, O_RDWR | O_SYNC);
436  #endif
437 
438  if (fd < 0)
439  {
440  char errmsg[NI_ERRNO_LEN] = {0};
442  ni_log(NI_LOG_ERROR, "ERROR: %d %s open() failed on %s\n", NI_ERRNO,
443  errmsg, p_dev);
444  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
445  fd = NI_INVALID_DEVICE_HANDLE;
446  LRETURN;
447  }
448  else if(fd == 0)
449  {
450  //this code is just for the case that we do not initialize all fds to NI_INVALID_DEVICE_HANDLE
451 
452  //if we make sure that all the fds in libxcoder is initialized to NI_INVALID_DEVICE_HANDLE
453  //we should remove this check
454 
455  //we hold the fd = 0, so other threads could not visit these code
456  //thread safe unless other thread close fd=0 accidently
457  ni_log(NI_LOG_ERROR, "open fd = 0 is not as expeceted\n");
458  if(close_fd_zero_atexit == 0)
459  {
460  close_fd_zero_atexit = 1;
461  atexit(close_fd_zero);
462  }
463  else
464  {
465  ni_log(NI_LOG_ERROR, "libxcoder has held the fd=0, but open fd=0 again, maybe fd=0 was closed accidently.");
466  }
467  fd = NI_INVALID_DEVICE_HANDLE;
468  }
469 
470  #if __APPLE__
471  //F_NOCACHE is set to ensure that data can be sent directly to the card instead of to cache memory
472  retval = fcntl(fd, F_NOCACHE, 1);
473  if (retval < 0)
474  {
475  ni_log(NI_LOG_ERROR, "ERROR: fnctl() failed on %s\n", p_dev);
476  ni_log(NI_LOG_ERROR, "ERROR: ni_device_open() failed!\n");
477  close(fd);
478  fd = NI_INVALID_DEVICE_HANDLE;
479  LRETURN;
480  }
481  #endif
482 
483  retval = fstat(fd, &g_nvme_stat);
484  if (retval < 0)
485  {
486  ni_log(NI_LOG_ERROR, "ERROR: fstat() failed on %s\n", p_dev);
487  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
488  close(fd);
489  fd = NI_INVALID_DEVICE_HANDLE;
490  LRETURN;
491  }
492 
493  if (!S_ISCHR(g_nvme_stat.st_mode) && !S_ISBLK(g_nvme_stat.st_mode))
494  {
495  ni_log(NI_LOG_ERROR, "ERROR: %s is not a block or character device\n",
496  p_dev);
497  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
498  close(fd);
499  fd = NI_INVALID_DEVICE_HANDLE;
500  LRETURN;
501  }
502 
503  ni_log(NI_LOG_DEBUG, "%s: success, fd=%d\n", __func__, fd);
504 
505 END:
506 
507  return fd;
508 #endif
509 }
510 #endif
511 
512 /*!*****************************************************************************
513  * \brief Open device and return device device_handle if successful
514  *
515  * \param[in] p_dev Device name represented as c string. ex: "/dev/nvme0"
516  * \param[in] p_config Device configuration parameters
517  *
518  * \return On success returns a device device_handle
519  * On failure returns NI_INVALID_DEVICE_HANDLE
520  ******************************************************************************/
521 ni_device_handle_t ni_device_open2(const char * p_dev, ni_device_mode_t mode)
522 {
523 #ifdef _WIN32
524  DWORD retval;
525  HANDLE device_handle;
526  DWORD dwDesiredAccess = 0;
527 
528  if (!p_dev)
529  {
530  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
531  return NI_INVALID_DEVICE_HANDLE;
532  }
533 
534  /* Convert access mode using bit operations */
535  switch(mode & NI_DEVICE_READ_WRITE)
536  {
537  case NI_DEVICE_READ_ONLY:
538  /* Read-only mode */
539  dwDesiredAccess = GENERIC_READ;
540  break;
542  /* Write-only mode */
543  dwDesiredAccess = GENERIC_WRITE;
544  break;
546  default:
547  /* Read-write mode takes precedence */
548  dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
549  break;
550  }
551 
552  device_handle = CreateFile(p_dev, dwDesiredAccess,
553  FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
554  OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
555 
556  ni_log(NI_LOG_DEBUG, "%s() device_name: %s", __func__, p_dev);
557  if (INVALID_HANDLE_VALUE == device_handle)
558  {
559  retval = GetLastError();
560  ni_log(NI_LOG_ERROR, "Failed to open %s, retval %d \n", p_dev, retval);
561  } else
562  {
563  ni_log(NI_LOG_DEBUG, "Found NVME Controller at %s \n", p_dev);
564  }
565 
566  return device_handle;
567 #else
568  int retval = -1;
569  ni_device_handle_t fd = NI_INVALID_DEVICE_HANDLE;
570  int open_flags = 0;
571 
572  if (!p_dev)
573  {
574  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
576  }
577 
578  ni_log(NI_LOG_DEBUG, "%s: opening regular-io enabled %s\n", __func__,
579  p_dev);
580 
581  /* Set access mode using bit operations */
582  switch(mode & NI_DEVICE_READ_WRITE)
583  {
584  case NI_DEVICE_READ_ONLY:
585  /* Read-only mode */
586  open_flags = O_RDONLY;
587  break;
589  /* Write-only mode */
590  open_flags = O_WRONLY;
591  break;
593  default:
594  /* Read-write mode takes precedence */
595  open_flags = O_RDWR;
596  break;
597  }
598 
599  open_flags |= O_SYNC;
600 #if __linux__
601  open_flags |= O_DIRECT;
602 #elif __APPLE__
603  /* macOS doesn't support O_DIRECT, use F_NOCACHE instead */
604 #endif
605 
606  fd = open(p_dev, open_flags);
607  if (fd < 0)
608  {
609  ni_log(NI_LOG_ERROR, "ERROR: %d %s open() failed on %s\n", NI_ERRNO,
610  strerror(NI_ERRNO), p_dev);
611  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
612  fd = NI_INVALID_DEVICE_HANDLE;
613  LRETURN;
614  }
615 
616 #if __APPLE__
617  //F_NOCACHE is set to ensure that data can be sent directly to the card instead of to cache memory
618  retval = fcntl(fd, F_NOCACHE, 1);
619  if (retval < 0)
620  {
621  ni_log(NI_LOG_ERROR, "ERROR: fnctl() failed on %s\n", p_dev);
622  ni_log(NI_LOG_ERROR, "ERROR: ni_device_open2() failed!\n");
623  close(fd);
624  fd = NI_INVALID_DEVICE_HANDLE;
625  LRETURN;
626  }
627 #endif
628 
629  retval = fstat(fd, &g_nvme_stat);
630  if (retval < 0)
631  {
632  ni_log(NI_LOG_ERROR, "ERROR: fstat() failed on %s\n", p_dev);
633  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
634  close(fd);
635  fd = NI_INVALID_DEVICE_HANDLE;
636  LRETURN;
637  }
638 
639  if (!S_ISCHR(g_nvme_stat.st_mode) && !S_ISBLK(g_nvme_stat.st_mode))
640  {
641  ni_log(NI_LOG_ERROR, "ERROR: %s is not a block or character device\n",
642  p_dev);
643  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
644  close(fd);
645  fd = NI_INVALID_DEVICE_HANDLE;
646  LRETURN;
647  }
648 
649  ni_log(NI_LOG_DEBUG, "%s: success, fd=%d\n", __func__, fd);
650 
651 END:
652 
653  return fd;
654 #endif
655 }
656 
657 /*!*****************************************************************************
658  * \brief Close device and release resources
659  *
660  * \param[in] device_handle Device handle obtained by calling ni_device_open()
661  *
662  * \return NONE
663  *
664  ******************************************************************************/
665 void ni_device_close(ni_device_handle_t device_handle)
666 {
667  if ( NI_INVALID_DEVICE_HANDLE == device_handle )
668  {
669  ni_log(NI_LOG_ERROR, "ERROR %s: null parameter passed %x\n", __func__,
670  device_handle);
671  return;
672  }
673 
674  if(device_handle == 0)
675  {
676  //this code is just for the case that we do not initialize all fds to NI_INVALID_DEVICE_HANDLE
677 
678  //if we make sure that all the fds in libxcoder is initialized to NI_INVALID_DEVICE_HANDLE
679  //we should remove this check
680  ni_log(NI_LOG_ERROR, "%s close fd=0 is not as expected", __func__);
681  return;
682  }
683 
684  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
685 
686 #ifdef _WIN32
687  BOOL retval;
688 
689  ni_log(NI_LOG_DEBUG, "%s(): closing %p\n", __func__, device_handle);
690 
691  retval = CloseHandle(device_handle);
692  if (FALSE == retval)
693  {
695  "ERROR: %s(): closing device device_handle %p failed, error: %d\n",
696  __func__, device_handle, NI_ERRNO);
697  }
698  else
699  {
700  ni_log(NI_LOG_DEBUG, "%s(): device %p closed successfuly\n", __func__,
701  device_handle);
702  }
703 #else
704  int err = 0;
705  ni_log(NI_LOG_DEBUG, "%s(): closing fd %d\n", __func__, device_handle);
706  err = close(device_handle);
707  if (err == -1)
708  {
709  char error_message[100] = {'\0'};
710  char unknown_error_message[20] = {'\0'};
711  ni_sprintf(error_message, 100, "ERROR: %s(): ", __func__);
712  switch (errno)
713  {
714  case EBADF:
715  ni_strcat(error_message, 100, "EBADF\n");
716  break;
717  case EINTR:
718  ni_strcat(error_message, 100, "EINTR\n");
719  break;
720  case EIO:
721  ni_strcat(error_message, 100, "EIO\n");
722  break;
723  default:
724  ni_sprintf(unknown_error_message, 20, "Unknown error %d\n", err);
725  ni_strcat(error_message, 100, unknown_error_message);
726  }
727  char errmsg[NI_ERRNO_LEN] = {0};
729  ni_log(NI_LOG_ERROR, "%s\n", errmsg);
730  ni_log(NI_LOG_ERROR, "%s\n", error_message);
731  }
732 #endif
733  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
734 }
735 
736 #ifndef DEPRECATION_AS_ERROR
737 /*!*****************************************************************************
738  * \brief Query device and return device capability structure
739  * This function had been replaced by ni_device_capability_query2
740  * This function can't be callback in multi thread
741  *
742  * \param[in] device_handle Device handle obtained by calling ni_device_open
743  * \param[in] p_cap Pointer to a caller allocated ni_device_capability_t
744  * struct
745  * \return On success
746  * NI_RETCODE_SUCCESS
747  * On failure
748  * NI_RETCODE_INVALID_PARAM
749  * NI_RETCODE_ERROR_MEM_ALOC
750  * NI_RETCODE_ERROR_NVME_CMD_FAILED
751  ******************************************************************************/
753 {
754  void * p_buffer = NULL;
756  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
757 
758  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
759 
760  if ( (NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_cap) )
761  {
762  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
763  __func__);
764  retval = NI_RETCODE_INVALID_PARAM;
765  LRETURN;
766  }
767 
768  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE),
770  {
771  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer.\n",
772  NI_ERRNO, __func__);
773  retval = NI_RETCODE_ERROR_MEM_ALOC;
774  LRETURN;
775  }
776 
777  memset(p_buffer, 0, NI_NVME_IDENTITY_CMD_DATA_SZ);
778 
779  uint32_t ui32LBA = IDENTIFY_DEVICE_R;
780  if (ni_nvme_send_read_cmd(device_handle, event_handle, p_buffer, NI_NVME_IDENTITY_CMD_DATA_SZ, ui32LBA) < 0)
781  {
783  LRETURN;
784  }
785 
787 
788 END:
789 
790  ni_aligned_free(p_buffer);
791  ni_log(NI_LOG_DEBUG, "%s(): retval: %d\n", __func__, retval);
792 
793  return retval;
794 }
795 #endif
796 
797 /*!*****************************************************************************
798  * \brief Query device and return device capability structure
799  * This function had replaced ni_device_capability_query
800  * This function can be callback with multi thread
801  *
802  * \param[in] device_handle Device handle obtained by calling ni_device_open
803  * \param[in] p_cap Pointer to a caller allocated ni_device_capability_t
804  * struct
805  * \param[in] device_in_ctxt If device is in ctx
806  * \return On success
807  * NI_RETCODE_SUCCESS
808  * On failure
809  * NI_RETCODE_INVALID_PARAM
810  * NI_RETCODE_ERROR_MEM_ALOC
811  * NI_RETCODE_ERROR_NVME_CMD_FAILED
812  ******************************************************************************/
813 ni_retcode_t ni_device_capability_query2(ni_device_handle_t device_handle,
814  ni_device_capability_t *p_cap, bool device_in_ctxt)
815 {
816  void * p_buffer = NULL;
818  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
819 
820  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
821 
822  if ( (NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_cap) )
823  {
824  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
825  __func__);
826  retval = NI_RETCODE_INVALID_PARAM;
827  LRETURN;
828  }
829 
830  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE),
832  {
833  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer.\n",
834  NI_ERRNO, __func__);
835  retval = NI_RETCODE_ERROR_MEM_ALOC;
836  LRETURN;
837  }
838 
839  memset(p_buffer, 0, NI_NVME_IDENTITY_CMD_DATA_SZ);
840 
841  uint32_t ui32LBA = IDENTIFY_DEVICE_R;
842  if (ni_nvme_send_read_cmd(device_handle, event_handle, p_buffer, NI_NVME_IDENTITY_CMD_DATA_SZ, ui32LBA) < 0)
843  {
845  LRETURN;
846  }
847 
848  ni_populate_device_capability_struct(p_cap, p_buffer, device_handle, device_in_ctxt);
849 
850 END:
851 
852  ni_aligned_free(p_buffer);
853  ni_log(NI_LOG_DEBUG, "%s(): retval: %d\n", __func__, retval);
854 
855  return retval;
856 }
857 
858 /*!*****************************************************************************
859  * \brief Open a new device session depending on the device_type parameter
860  * If device_type is NI_DEVICE_TYPE_DECODER opens decoding session
861  * If device_type is NI_DEVICE_TYPE_ENCODER opens encoding session
862  * If device_type is NI_DEVICE_TYPE_SCALER opens scaling session
863  *
864  * \param[in] p_ctx Pointer to a caller allocated
865  * ni_session_context_t struct
866  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER,
867  * or NI_DEVICE_TYPE_SCALER
868  * \return On success
869  * NI_RETCODE_SUCCESS
870  * On failure
871  * NI_RETCODE_INVALID_PARAM
872  * NI_RETCODE_ERROR_MEM_ALOC
873  * NI_RETCODE_ERROR_NVME_CMD_FAILED
874  * NI_RETCODE_ERROR_INVALID_SESSION
875  ******************************************************************************/
877  ni_device_type_t device_type)
878 {
880  ni_device_pool_t *p_device_pool = NULL;
881  ni_device_context_t *p_device_context = NULL;
882  ni_device_info_t *p_dev_info = NULL;
883  ni_device_info_t dev_info = { 0 };
885  ni_device_context_t *rsrc_ctx = NULL;
886  int i = 0;
887  int rc = 0;
888  int num_coders = 0;
889  bool use_model_load = true;
890  int least_load = 0;
891  int curr_load = 0;
892  int guid = -1;
893  uint32_t num_sw_instances = 0;
894  uint32_t pixel_load = 0xFFFFFFFFU;
895  int user_handles = false;
896  ni_lock_handle_t lock = NI_INVALID_LOCK_HANDLE;
897  ni_device_handle_t handle = NI_INVALID_DEVICE_HANDLE;
898  ni_device_handle_t handle1 = NI_INVALID_DEVICE_HANDLE;
899  // For none nvme block device we just need to pass in dummy
900  ni_session_context_t p_session_context = {0};
901  ni_device_type_t query_type = device_type;
902 
903  if (!p_ctx)
904  {
905  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
906  __func__);
908  }
909 
910 #ifdef _WIN32
911  if (!IsUserAnAdmin())
912  {
913  ni_log(NI_LOG_ERROR, "ERROR: %s must be in admin priviledge\n", __func__);
915  }
916 #endif
917 
918  ni_pthread_mutex_lock(&p_ctx->mutex);
920 
921  ni_device_session_context_init(&p_session_context);
922 
923  if (NI_INVALID_SESSION_ID != p_ctx->session_id)
924  {
925  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: trying to overwrite existing session, "
926  "device_type %d, session id %d\n",
927  device_type, p_ctx->session_id);
928  retval = NI_RETCODE_INVALID_PARAM;
929  LRETURN;
930  }
931 
932  p_ctx->p_hdr_buf = NULL;
933  p_ctx->hdr_buf_size = 0;
934 
935  p_ctx->roi_side_data_size = p_ctx->nb_rois = 0;
936  p_ctx->av_rois = NULL;
937  p_ctx->roi_map = NULL;
938  p_ctx->avc_roi_map = NULL;
939  p_ctx->hevc_roi_map = NULL;
940  p_ctx->hevc_sub_ctu_roi_buf = NULL;
941  p_ctx->p_master_display_meta_data = NULL;
942 
943  p_ctx->enc_change_params = NULL;
944 
945  p_ctx->target_bitrate = -1;
946  p_ctx->force_idr_frame = 0;
948  p_ctx->ltr_to_set.use_long_term_ref = 0;
949  p_ctx->ltr_interval = -1;
950  p_ctx->ltr_frame_ref_invalid = -1;
951  p_ctx->framerate.framerate_num = 0;
952  p_ctx->framerate.framerate_denom = 0;
953  p_ctx->vui.colorDescPresent = 0;
954  p_ctx->vui.colorPrimaries = 2; // 2 is unspecified
955  p_ctx->vui.colorTrc = 2; // 2 is unspecified
956  p_ctx->vui.colorSpace = 2; // 2 is unspecified
957  p_ctx->vui.aspectRatioWidth = 0;
958  p_ctx->vui.aspectRatioHeight = 0;
959  p_ctx->vui.videoFullRange = 0;
960  p_ctx->max_frame_size = 0;
961  p_ctx->reconfig_crf = -1;
962  p_ctx->reconfig_crf_decimal = 0;
963  p_ctx->reconfig_vbv_buffer_size = 0;
964  p_ctx->reconfig_vbv_max_rate = 0;
965  p_ctx->last_gop_size = 0;
966  p_ctx->initial_frame_delay = 0;
967  p_ctx->current_frame_delay = 0;
968  p_ctx->max_frame_delay = 0;
969  p_ctx->av1_pkt_num = 0;
970  p_ctx->pool_type = NI_POOL_TYPE_NONE;
971  p_ctx->force_low_delay = false;
972  p_ctx->force_low_delay_cnt = 0;
973  p_ctx->pkt_delay_cnt = 0;
974  p_ctx->reconfig_intra_period = -1;
975  p_ctx->reconfig_slice_arg = 0;
976 
977  memset(p_ctx->input_frame_fifo, 0, sizeof(ni_input_frame) * 120);
978  for (i = 0; i < 120; i++)
979  {
980  p_ctx->input_frame_fifo[i].usable = -1;
981  }
982 
983  handle = p_ctx->device_handle;
984  handle1 = p_ctx->blk_io_handle;
985 
986  ni_log2(p_ctx, NI_LOG_DEBUG,
987  "%s: device type %d hw_id %d blk_dev_name: %s dev_xcoder_name: %s.\n",
988  __func__, device_type, p_ctx->hw_id, p_ctx->blk_dev_name,
989  p_ctx->dev_xcoder_name);
990 
991  if (device_type == NI_DEVICE_TYPE_UPLOAD)
992  {
993  //uploader shares resources with encoder to query as encoder for load info
994  query_type = NI_DEVICE_TYPE_ENCODER;
995  }
996 
997  // if caller requested device by block device name, try to find its GUID and
998  // use it to override the hw_id which is the passed in device GUID
999  if (0 != strcmp(p_ctx->blk_dev_name, ""))
1000  {
1001  int tmp_guid_id;
1002  tmp_guid_id =
1003  ni_rsrc_get_device_by_block_name(p_ctx->blk_dev_name, device_type);
1004  if (tmp_guid_id != NI_RETCODE_FAILURE)
1005  {
1006  ni_log2(p_ctx, NI_LOG_DEBUG,
1007  "%s: block device name %s type %d guid %d is to "
1008  "override passed in guid %d\n",
1009  __func__, p_ctx->blk_dev_name, device_type, tmp_guid_id,
1010  p_ctx->hw_id);
1011  p_ctx->hw_id = tmp_guid_id;
1012  } else
1013  {
1014  ni_log(NI_LOG_INFO, "%s: block device name %s type %d NOT found ..\n",
1015  __func__, p_ctx->blk_dev_name, device_type);
1017  LRETURN;
1018  }
1019  }
1020 
1021  // User did not pass in any handle, so we create it for them
1022  if ((handle1 == NI_INVALID_DEVICE_HANDLE) && (handle == NI_INVALID_DEVICE_HANDLE))
1023  {
1024  if (p_ctx->hw_id >=0) // User selected the encder/ decoder number
1025  {
1026  if ((rsrc_ctx = ni_rsrc_allocate_simple_direct(device_type, p_ctx->hw_id)) == NULL)
1027  {
1028 
1029  ni_log2(p_ctx, NI_LOG_ERROR, "Error XCoder resource allocation: inst %d\n",
1030  p_ctx->hw_id);
1032  LRETURN;
1033  }
1034  ni_log2(p_ctx, NI_LOG_DEBUG, "device %p\n", rsrc_ctx);
1035  // Now the device name is in the rsrc_ctx, we open this device to get the file handles
1036 
1037 #ifdef _WIN32
1038  if ((handle = ni_device_open2(rsrc_ctx->p_device_info->blk_name,
1039  NI_DEVICE_READ_WRITE)) == NI_INVALID_DEVICE_HANDLE)
1040  {
1041  ni_rsrc_free_device_context(rsrc_ctx);
1043  LRETURN;
1044  } else
1045  {
1046  user_handles = true;
1047  p_ctx->device_handle = handle;
1048  p_ctx->blk_io_handle = handle;
1049  handle1 = handle;
1052  ni_rsrc_free_device_context(rsrc_ctx);
1053  }
1054 #else
1055  //The original design (code below) is to open char and block device file separately. And the ffmpeg will close the device twice.
1056  //However, in I/O version, char device can't be opened. For compatibility, and to avoid errors, open the block device twice.
1057  if (((handle = ni_device_open2(rsrc_ctx->p_device_info->dev_name, NI_DEVICE_READ_WRITE)) == NI_INVALID_DEVICE_HANDLE) ||
1058  ((handle1 = ni_device_open2(rsrc_ctx->p_device_info->dev_name, NI_DEVICE_READ_WRITE)) == NI_INVALID_DEVICE_HANDLE))
1059  {
1060  ni_rsrc_free_device_context(rsrc_ctx);
1062  LRETURN;
1063  } else
1064  {
1065  user_handles = true;
1066  p_ctx->device_handle = handle;
1067  p_ctx->blk_io_handle = handle1;
1068  // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker): Couldn't determine why it will be NULL.
1071 
1072  ni_rsrc_free_device_context(rsrc_ctx);
1073  }
1074 #endif
1075  } else
1076  {
1077  int tmp_id = -1;
1078 
1079  // Decide on model load or real load to be used, based on name passed
1080  // in from p_ctx->dev_xcoder_name; after checking it will be used to
1081  // store device file name.
1082  if (0 == strcmp(p_ctx->dev_xcoder_name, NI_BEST_REAL_LOAD_STR))
1083  {
1084  use_model_load = false;
1085  } else if (0 != strcmp(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR))
1086  {
1087  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s unrecognized option: %s.\n",
1088  __func__, p_ctx->dev_xcoder_name);
1089  retval = NI_RETCODE_INVALID_PARAM;
1090  LRETURN;
1091  }
1092 
1093  if (ni_rsrc_lock_and_open(query_type, &lock) != NI_RETCODE_SUCCESS)
1094  {
1096  LRETURN;
1097  }
1098 
1099  // We need to query through all the boards to confirm the least load.
1100 
1101  p_device_pool = ni_rsrc_get_device_pool();
1102 
1103  if (!p_device_pool)
1104  {
1105  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Error calling ni_rsrc_get_device_pool()\n");
1107  LRETURN;
1108  }
1109  if (IS_XCODER_DEVICE_TYPE(query_type))
1110  {
1111  num_coders = p_device_pool->p_device_queue->xcoder_cnt[query_type];
1112  } else
1113  {
1114  retval = NI_RETCODE_INVALID_PARAM;
1115  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1116  {
1118  LRETURN;
1119  }
1120  LRETURN;
1121  }
1122 
1123  for (i = 0; i < num_coders; i++)
1124  {
1125  tmp_id = p_device_pool->p_device_queue->xcoders[query_type][i];
1126  p_device_context = ni_rsrc_get_device_context(query_type, tmp_id);
1127 
1128  if (p_device_context == NULL)
1129  {
1130  ni_log2(p_ctx, NI_LOG_ERROR,
1131  "ERROR: %s() ni_rsrc_get_device_context() failed\n",
1132  __func__);
1133  continue;
1134  }
1135 
1136  // Code is included in the for loop. In the loop, the device is
1137  // just opened once, and it will be closed once too.
1138  p_session_context.blk_io_handle = ni_device_open2(
1139  p_device_context->p_device_info->dev_name, NI_DEVICE_READ_WRITE);
1140  p_session_context.device_handle = p_session_context.blk_io_handle;
1141 
1142  if (NI_INVALID_DEVICE_HANDLE == p_session_context.device_handle)
1143  {
1144  ni_log2(p_ctx, NI_LOG_ERROR, "Error open device");
1145  ni_rsrc_free_device_context(p_device_context);
1146  continue;
1147  }
1148 
1149  p_session_context.hw_id = p_device_context->p_device_info->hw_id;
1150  rc = ni_device_session_query(&p_session_context, query_type);
1151  if (NI_INVALID_DEVICE_HANDLE != p_session_context.device_handle)
1152  {
1153  ni_device_close(p_session_context.device_handle);
1154  }
1155 
1156  if (NI_RETCODE_SUCCESS != rc)
1157  {
1158  ni_log2(p_ctx, NI_LOG_ERROR, "Error query %s %s.%d\n",
1159  g_device_type_str[query_type],
1160  p_device_context->p_device_info->dev_name,
1161  p_device_context->p_device_info->hw_id);
1162  ni_rsrc_free_device_context(p_device_context);
1163  continue;
1164  }
1165  ni_rsrc_update_record(p_device_context, &p_session_context);
1166  p_dev_info = p_device_context->p_device_info;
1167 
1168  // here we select the best load
1169  // for decoder/encoder: check the model_load/real_load
1170  // for hwuploader: check directly hwupload pixel load in query result
1171  if (NI_DEVICE_TYPE_UPLOAD == device_type)
1172  {
1173  if (lower_pixel_rate(&p_session_context.load_query, pixel_load))
1174  {
1175  guid = tmp_id;
1176  pixel_load = p_session_context.load_query.total_pixel_load;
1177  memcpy(&dev_info, p_dev_info, sizeof(ni_device_info_t));
1178  }
1179  } else
1180  {
1181  if (use_model_load)
1182  {
1183  curr_load = p_dev_info->model_load;
1184  } else
1185  {
1186  curr_load = p_dev_info->load;
1187  }
1188 
1189  if (i == 0 || curr_load < least_load ||
1190  (curr_load == least_load &&
1191  p_dev_info->active_num_inst < num_sw_instances))
1192  {
1193  guid = tmp_id;
1194  least_load = curr_load;
1195  num_sw_instances = p_dev_info->active_num_inst;
1196  memcpy(&dev_info, p_dev_info, sizeof(ni_device_info_t));
1197  }
1198  }
1199  ni_rsrc_free_device_context(p_device_context);
1200  }
1201 
1202 #ifdef _WIN32
1203  // Now we have the device info that has the least load of the FW
1204  // we open this device and assign the FD
1205  if ((handle = ni_device_open2(dev_info.blk_name, NI_DEVICE_READ_WRITE)) ==
1206  NI_INVALID_DEVICE_HANDLE)
1207  {
1209  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1210  {
1212  LRETURN;
1213  }
1214  LRETURN;
1215  } else
1216  {
1217  p_ctx->device_handle = handle;
1218  p_ctx->blk_io_handle = handle;
1219  handle1 = handle;
1220  p_ctx->hw_id = guid;
1223  }
1224 #else
1225  //The original design (code below) is to open char and block device file separately. And the ffmpeg will close the device twice.
1226  //However, in I/O version, char device can't be opened. For compatibility, and to avoid errors, open the block device twice.
1227  if (((handle = ni_device_open2(dev_info.dev_name, NI_DEVICE_READ_WRITE)) == NI_INVALID_DEVICE_HANDLE) ||
1228  ((handle1 = ni_device_open2(dev_info.dev_name, NI_DEVICE_READ_WRITE)) == NI_INVALID_DEVICE_HANDLE))
1229  {
1231  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1232  {
1234  LRETURN;
1235  }
1236  LRETURN;
1237  }
1238  else
1239  {
1240  p_ctx->device_handle = handle;
1241  p_ctx->blk_io_handle = handle1;
1242  p_ctx->hw_id = guid;
1245  }
1246 #endif
1247  }
1248  }
1249  // user passed in the handle, but one of them is invalid, this is error case so we return error
1250  else if((handle1 == NI_INVALID_DEVICE_HANDLE) || (handle == NI_INVALID_DEVICE_HANDLE))
1251  {
1253  LRETURN;
1254  }
1255  // User passed in both handles, so we do not need to allocate for it
1256  else
1257  {
1258  user_handles = true;
1259  }
1260 
1261  ni_log2(p_ctx, NI_LOG_DEBUG,
1262  "Finish open the session dev:%s guid:%d handle:%p handle1:%p\n",
1263  p_ctx->dev_xcoder_name, p_ctx->hw_id,
1264  p_ctx->device_handle, p_ctx->blk_io_handle);
1265  if (p_ctx->max_nvme_io_size == NI_INVALID_IO_SIZE)
1267  // get FW API version
1268  p_device_context = ni_rsrc_get_device_context(device_type, p_ctx->hw_id);
1269  if (p_device_context == NULL)
1270  {
1271  ni_log2(p_ctx, NI_LOG_ERROR,
1272  "ERROR: %s() ni_rsrc_get_device_context() failed\n",
1273  __func__);
1274  if (user_handles != true)
1275  {
1276  if(ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1277  {
1279  LRETURN;
1280  }
1281  }
1283  LRETURN;
1284  }
1285 
1286  if (!(strcmp(p_ctx->dev_xcoder_name, "")) || !(strcmp(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR)) ||
1287  !(strcmp(p_ctx->dev_xcoder_name, NI_BEST_REAL_LOAD_STR)))
1288  {
1290  }
1291 
1292  memcpy(p_ctx->fw_rev , p_device_context->p_device_info->fw_rev, 8);
1293 
1294  ni_rsrc_free_device_context(p_device_context);
1295 
1296  retval = ni_device_get_ddr_configuration(p_ctx);
1297  if (retval != NI_RETCODE_SUCCESS)
1298  {
1299  ni_log2(p_ctx, NI_LOG_ERROR,
1300  "ERROR: %s() cannot retrieve DDR configuration\n",
1301  __func__);
1302  if (user_handles != true)
1303  {
1304  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1305  {
1307  LRETURN;
1308  }
1309  }
1310  LRETURN;
1311  }
1312 
1313  if (p_ctx->keep_alive_timeout == 0)
1314  {
1315  ni_log2(p_ctx, NI_LOG_ERROR,
1316  "ERROR: %s() keep_alive_timeout was 0, should be between 1-100. "
1317  "Setting to default of %u\n",
1318  __func__, NI_DEFAULT_KEEP_ALIVE_TIMEOUT);
1320  }
1321  switch (device_type)
1322  {
1324  {
1325  retval = ni_decoder_session_open(p_ctx);
1326  if (user_handles != true)
1327  {
1328  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1329  {
1331  LRETURN;
1332  }
1333  }
1334  // send keep alive signal thread
1335  if (NI_RETCODE_SUCCESS != retval)
1336  {
1337  LRETURN;
1338  }
1339  break;
1340  }
1342  {
1343 #ifndef _WIN32
1344  // p2p is not supported on Windows, so skip following assignments.
1345  ni_xcoder_params_t *p_enc_params;
1346 
1347  p_enc_params = p_ctx->p_session_config;
1348 
1349  if (p_enc_params && p_enc_params->hwframes &&
1350  p_enc_params->p_first_frame)
1351  {
1352  niFrameSurface1_t *pSurface;
1353  pSurface =
1354  (niFrameSurface1_t *)p_enc_params->p_first_frame->p_data[3];
1355  p_ctx->sender_handle =
1356  (ni_device_handle_t)(int64_t)pSurface->device_handle;
1357  p_enc_params->rootBufId = pSurface->ui16FrameIdx;
1358 
1359  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: sender_handle and rootBufId %d set\n",
1360  __func__, p_enc_params->rootBufId);
1361  }
1362 #endif
1363 
1364  retval = ni_encoder_session_open(p_ctx);
1365  if (user_handles != true)
1366  {
1367  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1368  {
1370  LRETURN;
1371  }
1372  }
1373  // send keep alive signal thread
1374  if (NI_RETCODE_SUCCESS != retval)
1375  {
1376  LRETURN;
1377  }
1378  break;
1379  }
1380  case NI_DEVICE_TYPE_UPLOAD:
1381  {
1382  retval = ni_uploader_session_open(p_ctx);
1383  if (user_handles != true)
1384  {
1385  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1386  {
1388  LRETURN;
1389  }
1390  }
1391  // send keep alive signal thread
1392  if (NI_RETCODE_SUCCESS != retval)
1393  {
1394  LRETURN;
1395  }
1396  break;
1397  }
1398  case NI_DEVICE_TYPE_SCALER:
1399  {
1400  retval = ni_scaler_session_open(p_ctx);
1401  if (user_handles != true)
1402  {
1403  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1404  {
1406  LRETURN;
1407  }
1408  }
1409  // send keep alive signal thread
1410  if (NI_RETCODE_SUCCESS != retval)
1411  {
1412  LRETURN;
1413  }
1414  break;
1415  }
1416  case NI_DEVICE_TYPE_AI:
1417  {
1418  retval = ni_ai_session_open(p_ctx);
1419  if (user_handles != true)
1420  {
1421  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1422  {
1424  LRETURN;
1425  }
1426  }
1427  // send keep alive signal thread
1428  if (NI_RETCODE_SUCCESS != retval)
1429  {
1430  LRETURN;
1431  }
1432  break;
1433  }
1434  default:
1435  {
1436  if (user_handles != true)
1437  {
1438  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1439  {
1441  LRETURN;
1442  }
1443  }
1444  retval = NI_RETCODE_INVALID_PARAM;
1445  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1446  __func__, device_type);
1447  LRETURN;
1448  }
1449  }
1450 
1452  if (!p_ctx->keep_alive_thread_args)
1453  {
1454  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: thread_args allocation failed!\n");
1455  ni_device_session_close(p_ctx, 0, device_type);
1456  retval = NI_RETCODE_ERROR_MEM_ALOC;
1457  LRETURN;
1458  }
1459 
1460  p_ctx->keep_alive_thread_args->session_id = p_ctx->session_id;
1462  p_ctx->keep_alive_thread_args->device_type = device_type;
1465  p_ctx->keep_alive_thread_args->close_thread = false;
1468  p_ctx->keep_alive_thread_args->p_mutex = &p_ctx->mutex;
1469  p_ctx->keep_alive_thread_args->hw_id = p_ctx->hw_id;
1470  p_ctx->last_access_time = ni_gettime_ns();
1471 
1473  sysconf(_SC_PAGESIZE), NI_DATA_BUFFER_LEN))
1474  {
1475  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: keep alive p_buffer allocation failed!\n");
1476  ni_device_session_close(p_ctx, 0, device_type);
1477  retval = NI_RETCODE_ERROR_MEM_ALOC;
1478  LRETURN;
1479  }
1481 
1482  if (0 !=
1483  ni_pthread_create(&p_ctx->keep_alive_thread, NULL,
1485  (void *)p_ctx->keep_alive_thread_args))
1486  {
1487  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to create keep alive thread\n");
1488  p_ctx->keep_alive_thread = (ni_pthread_t){0};
1491  ni_device_session_close(p_ctx, 0, device_type);
1492  retval = NI_RETCODE_ERROR_MEM_ALOC;
1493  LRETURN;
1494  }
1495  ni_log2(p_ctx, NI_LOG_DEBUG, "Enabled keep alive thread\n");
1496 
1497  // allocate memory for encoder change data to be reused
1498  p_ctx->enc_change_params = calloc(1, sizeof(ni_encoder_change_params_t));
1499  if (!p_ctx->enc_change_params)
1500  {
1501  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: enc_change_params allocation failed!\n");
1502  ni_device_session_close(p_ctx, 0, device_type);
1503  retval = NI_RETCODE_ERROR_MEM_ALOC;
1504  }
1505 
1506 END:
1507  ni_device_session_context_clear(&p_session_context);
1508 
1509  if (p_device_pool)
1510  {
1511  ni_rsrc_free_device_pool(p_device_pool);
1512  p_device_pool = NULL;
1513  }
1514 
1516 
1517  ni_pthread_mutex_unlock(&p_ctx->mutex);
1518 
1519  return retval;
1520 }
1521 
1522 /*!*****************************************************************************
1523  * \brief Close device session that was previously opened by calling
1524  * ni_device_session_open()
1525  * If device_type is NI_DEVICE_TYPE_DECODER closes decoding session
1526  * If device_type is NI_DEVICE_TYPE_ENCODER closes encoding session
1527  * If device_type is NI_DEVICE_TYPE_SCALER closes scaling session
1528  *
1529  * \param[in] p_ctx Pointer to a caller allocated
1530  * ni_session_context_t struct
1531  * \param[in] eos_received Flag indicating if End Of Stream indicator was
1532  * received
1533  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER,
1534  * or NI_DEVICE_TYPE_SCALER
1535  * \return On success
1536  * NI_RETCODE_SUCCESS
1537  * On failure
1538  * NI_RETCODE_INVALID_PARAM
1539  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1540  * NI_RETCODE_ERROR_INVALID_SESSION
1541  ******************************************************************************/
1543  int eos_recieved,
1544  ni_device_type_t device_type)
1545 {
1546  int ret;
1548 
1549  if (!p_ctx)
1550  {
1551  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1552  __func__);
1553  return NI_RETCODE_INVALID_PARAM;
1554  }
1555 
1556  ni_pthread_mutex_lock(&p_ctx->mutex);
1558  ni_pthread_mutex_unlock(&p_ctx->mutex);
1559 
1560 #ifdef _WIN32
1561  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args)
1562 #else
1563  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args)
1564 #endif
1565  {
1566  p_ctx->keep_alive_thread_args->close_thread = true;
1567  ret = ni_pthread_join(p_ctx->keep_alive_thread, NULL);
1568  if (ret)
1569  {
1570  ni_log2(p_ctx, NI_LOG_ERROR,
1571  "join keep alive thread fail! : sid %u ret %d\n",
1572  p_ctx->session_id, ret);
1573  }
1576  } else
1577  {
1578  ni_log2(p_ctx, NI_LOG_ERROR, "invalid keep alive thread: %u\n",
1579  p_ctx->session_id);
1580  }
1581 
1582  switch (device_type)
1583  {
1585  {
1586  retval = ni_decoder_session_close(p_ctx, eos_recieved);
1587  break;
1588  }
1589  case NI_DEVICE_TYPE_UPLOAD:
1590  {
1592  // fall through
1593  }
1595  {
1596  retval = ni_encoder_session_close(p_ctx, eos_recieved);
1597  break;
1598  }
1599  case NI_DEVICE_TYPE_SCALER:
1600  {
1601  retval = ni_scaler_session_close(p_ctx, eos_recieved);
1602  break;
1603  }
1604  case NI_DEVICE_TYPE_AI:
1605  {
1606  retval = ni_ai_session_close(p_ctx, eos_recieved);
1607  break;
1608  }
1609  default:
1610  {
1611  retval = NI_RETCODE_INVALID_PARAM;
1612  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1613  __func__, device_type);
1614  break;
1615  }
1616  }
1617 
1618  ni_pthread_mutex_lock(&p_ctx->mutex);
1619  // need set invalid after closed. May cause open invalid parameters.
1621 
1622  ni_memfree(p_ctx->p_hdr_buf);
1623  ni_memfree(p_ctx->av_rois);
1624  ni_memfree(p_ctx->roi_map);
1625  ni_memfree(p_ctx->avc_roi_map);
1626  ni_memfree(p_ctx->hevc_roi_map);
1629  ni_memfree(p_ctx->enc_change_params);
1630  p_ctx->hdr_buf_size = 0;
1631  p_ctx->roi_side_data_size = 0;
1632  p_ctx->nb_rois = 0;
1633  p_ctx->target_bitrate = -1;
1634  p_ctx->force_idr_frame = 0;
1636  p_ctx->ltr_to_set.use_long_term_ref = 0;
1637  p_ctx->ltr_interval = -1;
1638  p_ctx->ltr_frame_ref_invalid = -1;
1639  p_ctx->max_frame_size = 0;
1640  p_ctx->reconfig_crf = -1;
1641  p_ctx->reconfig_crf_decimal = 0;
1642  p_ctx->reconfig_vbv_buffer_size = 0;
1643  p_ctx->reconfig_vbv_max_rate = 0;
1644  p_ctx->last_gop_size = 0;
1645  p_ctx->initial_frame_delay = 0;
1646  p_ctx->current_frame_delay = 0;
1647  p_ctx->max_frame_delay = 0;
1648  p_ctx->av1_pkt_num = 0;
1649  p_ctx->reconfig_intra_period = -1;
1650  p_ctx->reconfig_slice_arg = 0;
1651 
1653  ni_pthread_mutex_unlock(&p_ctx->mutex);
1654 
1655  return retval;
1656 }
1657 
1658 /*!*****************************************************************************
1659  * \brief Send a flush command to the device
1660  * If device_type is NI_DEVICE_TYPE_DECODER sends EOS command to
1661  * decoder
1662  * If device_type is NI_DEVICE_TYPE_ENCODER sends EOS command to
1663  * encoder
1664  *
1665  * \param[in] p_ctx Pointer to a caller allocated
1666  * ni_session_context_t struct
1667  * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
1668  * \return On success
1669  * NI_RETCODE_SUCCESS
1670  * On failure
1671  * NI_RETCODE_INVALID_PARAM
1672  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1673  * NI_RETCODE_ERROR_INVALID_SESSION
1674  ******************************************************************************/
1676 {
1678  if (!p_ctx)
1679  {
1680  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1681  __func__);
1682  return NI_RETCODE_INVALID_PARAM;
1683  }
1684 
1685  ni_pthread_mutex_lock(&p_ctx->mutex);
1687 
1688  switch (device_type)
1689  {
1691  {
1692  retval = ni_decoder_session_send_eos(p_ctx);
1693  break;
1694  }
1696  {
1697  retval = ni_encoder_session_send_eos(p_ctx);
1698  break;
1699  }
1700  default:
1701  {
1702  retval = NI_RETCODE_INVALID_PARAM;
1703  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1704  __func__, device_type);
1705  break;
1706  }
1707  }
1708  p_ctx->ready_to_close = (NI_RETCODE_SUCCESS == retval);
1710  ni_pthread_mutex_unlock(&p_ctx->mutex);
1711  return retval;
1712 }
1713 
1714 /*!*****************************************************************************
1715  * \brief Save a stream's headers in a decoder session that can be used later
1716  * for continuous decoding from the same source.
1717  *
1718  * \param[in] p_ctx Pointer to a caller allocated
1719  * ni_session_context_t struct
1720  * \param[in] hdr_data Pointer to header data
1721  * \param[in] hdr_size Size of header data in bytes
1722  * \return On success
1723  * NI_RETCODE_SUCCESS
1724  * On failure
1725  * NI_RETCODE_INVALID_PARAM
1726  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1727  * NI_RETCODE_ERROR_INVALID_SESSION
1728  ******************************************************************************/
1730  uint8_t *hdr_data,
1731  uint8_t hdr_size)
1732 {
1734 
1735  if (!p_ctx)
1736  {
1737  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s p_ctx null, return\n", __func__);
1738  return NI_RETCODE_INVALID_PARAM;
1739  }
1740 
1741  if (!hdr_data)
1742  {
1743  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s hdr_data null, return\n", __func__);
1744  return NI_RETCODE_INVALID_PARAM;
1745  } else if (p_ctx->p_hdr_buf && p_ctx->hdr_buf_size == hdr_size &&
1746  0 == memcmp(p_ctx->p_hdr_buf, hdr_data, hdr_size))
1747  {
1748  // no change from the saved headers, success !
1749  return retval;
1750  }
1751 
1752  // update the saved header data
1753  free(p_ctx->p_hdr_buf);
1754  p_ctx->hdr_buf_size = 0;
1755  p_ctx->p_hdr_buf = malloc(hdr_size);
1756  if (p_ctx->p_hdr_buf)
1757  {
1758  memcpy(p_ctx->p_hdr_buf, hdr_data, hdr_size);
1759  p_ctx->hdr_buf_size = hdr_size;
1760  ni_log2(p_ctx, NI_LOG_DEBUG, "%s saved hdr size %u\n", __func__,
1761  p_ctx->hdr_buf_size);
1762  } else
1763  {
1765  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s no memory.\n", __func__);
1766  }
1767  return retval;
1768 }
1769 
1770 /*!*****************************************************************************
1771  * \brief Flush a decoder session to get ready to continue decoding.
1772  * Note: this is different from ni_device_session_flush in that it closes the
1773  * current decode session and opens a new one for continuous decoding.
1774  *
1775  * \param[in] p_ctx Pointer to a caller allocated
1776  * ni_session_context_t struct
1777  * \return On success
1778  * NI_RETCODE_SUCCESS
1779  * On failure
1780  * NI_RETCODE_INVALID_PARAM
1781  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1782  * NI_RETCODE_ERROR_INVALID_SESSION
1783  ******************************************************************************/
1785 {
1787 
1788  if (!p_ctx)
1789  {
1790  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s ctx null, return\n", __func__);
1791  return NI_RETCODE_INVALID_PARAM;
1792  }
1793  ni_pthread_mutex_lock(&p_ctx->mutex);
1794  retval = ni_decoder_session_flush(p_ctx);
1795  if (NI_RETCODE_SUCCESS == retval) {
1796  p_ctx->ready_to_close = 0;
1797  }
1798  ni_pthread_mutex_unlock(&p_ctx->mutex);
1799  return retval;
1800 }
1801 
1802 /*!*****************************************************************************
1803  * \brief Sends data to the device
1804  * If device_type is NI_DEVICE_TYPE_DECODER sends data packet to
1805  * decoder
1806  * If device_type is NI_DEVICE_TYPE_ENCODER sends data frame to encoder
1807  * If device_type is NI_DEVICE_TYPE_AI sends data frame to ai engine
1808  *
1809  * \param[in] p_ctx Pointer to a caller allocated
1810  * ni_session_context_t struct
1811  * \param[in] p_data Pointer to a caller allocated
1812  * ni_session_data_io_t struct which contains either a
1813  * ni_frame_t data frame or ni_packet_t data packet to
1814  * send
1815  * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER or
1816  * NI_DEVICE_TYPE_AI
1817  * If NI_DEVICE_TYPE_DECODER is specified, it is
1818  * expected that the ni_packet_t struct inside the
1819  * p_data pointer contains data to send.
1820  * If NI_DEVICE_TYPE_ENCODER or NI_DEVICE_TYPE_AI is
1821  * specified, it is expected that the ni_frame_t
1822  * struct inside the p_data pointer contains data to
1823  * send.
1824  * \return On success
1825  * Total number of bytes written
1826  * On failure
1827  * NI_RETCODE_INVALID_PARAM
1828  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1829  * NI_RETCODE_ERROR_INVALID_SESSION
1830  ******************************************************************************/
1832 {
1834 
1835  if (!p_ctx || !p_data)
1836  {
1837  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1838  __func__);
1839  return NI_RETCODE_INVALID_PARAM;
1840  }
1841  // Here check if keep alive thread is closed.
1842 #ifdef _WIN32
1843  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
1845 #else
1846  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
1848 #endif
1849  {
1850  ni_log2(p_ctx, NI_LOG_ERROR,
1851  "ERROR: %s() keep alive thread has been closed, "
1852  "hw:%d, session:%d\n",
1853  __func__, p_ctx->hw_id, p_ctx->session_id);
1855  }
1856 
1857  ni_pthread_mutex_lock(&p_ctx->mutex);
1858  // In close state, let the close process execute first.
1859  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
1860  {
1861  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
1862  ni_pthread_mutex_unlock(&p_ctx->mutex);
1863  ni_usleep(100);
1865  }
1867  ni_pthread_mutex_unlock(&p_ctx->mutex);
1868 
1869  switch (device_type)
1870  {
1872  {
1873  retval = ni_decoder_session_write(p_ctx, &(p_data->data.packet));
1874  break;
1875  }
1877  {
1878  retval = ni_encoder_session_write(p_ctx, &(p_data->data.frame));
1879  break;
1880  }
1881  case NI_DEVICE_TYPE_AI:
1882  {
1883  retval = ni_ai_session_write(p_ctx, &(p_data->data.frame));
1884  break;
1885  }
1886  default:
1887  {
1888  retval = NI_RETCODE_INVALID_PARAM;
1889  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1890  __func__, device_type);
1891  break;
1892  }
1893  }
1894 
1895  ni_pthread_mutex_lock(&p_ctx->mutex);
1897  ni_pthread_mutex_unlock(&p_ctx->mutex);
1898  return retval;
1899 }
1900 
1901 /*!*****************************************************************************
1902  * \brief Read data from the device
1903  * If device_type is NI_DEVICE_TYPE_DECODER reads data packet from
1904  * decoder
1905  * If device_type is NI_DEVICE_TYPE_ENCODER reads data frame from
1906  * encoder
1907  * If device_type is NI_DEVICE_TYPE_AI reads data frame from AI engine
1908  *
1909  * \param[in] p_ctx Pointer to a caller allocated
1910  * ni_session_context_t struct
1911  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
1912  * struct which contains either a ni_frame_t data frame
1913  * or ni_packet_t data packet to send
1914  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER, or
1915  * NI_DEVICE_TYPE_SCALER
1916  * If NI_DEVICE_TYPE_DECODER is specified, data that
1917  * was read will be placed into ni_frame_t struct
1918  * inside the p_data pointer
1919  * If NI_DEVICE_TYPE_ENCODER is specified, data that
1920  * was read will be placed into ni_packet_t struct
1921  * inside the p_data pointer
1922  * If NI_DEVICE_TYPE_AI is specified, data that was
1923  * read will be placed into ni_frame_t struct inside
1924  * the p_data pointer
1925  * \return On success
1926  * Total number of bytes read
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) || (!p_data))
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  // Here check if keep alive thread is closed.
1943 #ifdef _WIN32
1944  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
1946 #else
1947  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
1949 #endif
1950  {
1951  ni_log2(p_ctx, NI_LOG_ERROR,
1952  "ERROR: %s() keep alive thread has been closed, "
1953  "hw:%d, session:%d\n",
1954  __func__, p_ctx->hw_id, p_ctx->session_id);
1956  }
1957 
1958  ni_pthread_mutex_lock(&p_ctx->mutex);
1959  // In close state, let the close process execute first.
1960  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
1961  {
1962  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
1963  ni_pthread_mutex_unlock(&p_ctx->mutex);
1964  ni_usleep(100);
1966  }
1968  ni_pthread_mutex_unlock(&p_ctx->mutex);
1969 
1970  switch (device_type)
1971  {
1973  {
1974  int seq_change_read_count = 0;
1975  p_data->data.frame.src_codec = p_ctx->codec_format;
1976  for (;;)
1977  {
1978  retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
1979  // check resolution change only after initial setting obtained
1980  // p_data->data.frame.video_width is picture width and will be 32-align
1981  // adjusted to frame size; p_data->data.frame.video_height is the same as
1982  // frame size, then compare them to saved one for resolution checking
1983  //
1984  uint32_t aligned_width;
1985  if(QUADRA)
1986  {
1987  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
1988  }
1989  else
1990  {
1991  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
1992  }
1993 
1994  if (0 == retval && seq_change_read_count)
1995  {
1996  ni_log2(p_ctx, NI_LOG_DEBUG,
1997  "%s (decoder): seq change NO data, next time.\n", __func__);
1998  p_ctx->active_video_width = 0;
1999  p_ctx->active_video_height = 0;
2000  p_ctx->actual_video_width = 0;
2001  break;
2002  }
2003  else if (retval < 0)
2004  {
2005  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
2006  __func__, retval);
2007  break;
2008  }
2009  // aligned_width may equal to active_video_width if bit depth and width
2010  // are changed at the same time. So, check video_width != actual_video_width.
2011  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
2012  (p_data->data.frame.video_width &&
2013  p_data->data.frame.video_height &&
2014  (aligned_width != p_ctx->active_video_width ||
2015  p_data->data.frame.video_height != p_ctx->active_video_height))))
2016  {
2017  ni_log2(
2018  p_ctx, NI_LOG_DEBUG,
2019  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
2020  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
2021  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
2022  aligned_width, p_data->data.frame.video_height,
2023  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
2024  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
2025  // reset active video resolution to 0 so it can be queried in the re-read
2026  p_ctx->active_video_width = 0;
2027  p_ctx->active_video_height = 0;
2028  p_ctx->actual_video_width = 0;
2029  seq_change_read_count++;
2030  }
2031  else
2032  {
2033  break;
2034  }
2035  }
2036  break;
2037  }
2039  {
2040  retval = ni_encoder_session_read(p_ctx, &(p_data->data.packet));
2041  break;
2042  }
2043  case NI_DEVICE_TYPE_AI:
2044  {
2045  retval = ni_ai_session_read(p_ctx, &(p_data->data.packet));
2046  break;
2047  }
2048  default:
2049  {
2050  retval = NI_RETCODE_INVALID_PARAM;
2051  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
2052  __func__, device_type);
2053  break;
2054  }
2055  }
2056 
2057  ni_pthread_mutex_lock(&p_ctx->mutex);
2059  ni_pthread_mutex_unlock(&p_ctx->mutex);
2060  return retval;
2061 }
2062 
2063 /*!*****************************************************************************
2064  * \brief Query session data from the device -
2065  * If device_type is valid, will query session data
2066  * from specified device type
2067  *
2068  * \param[in] p_ctx Pointer to a caller allocated
2069  * ni_session_context_t struct
2070  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
2071  * NI_DEVICE_TYPE_ENCODER or
2072  * NI_DEVICE_TYPE_SCALER or
2073  * NI_DEVICE_TYPE_AI or
2074  * NI_DEVICE_TYPE_UPLOADER
2075  *
2076  * \return On success
2077  * NI_RETCODE_SUCCESS
2078  * On failure
2079  * NI_RETCODE_INVALID_PARAM
2080  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2081  * NI_RETCODE_ERROR_INVALID_SESSION
2082  ******************************************************************************/
2084 {
2086  if (!p_ctx)
2087  {
2088  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
2089  __func__);
2090  return NI_RETCODE_INVALID_PARAM;
2091  }
2092 
2093  if (IS_XCODER_DEVICE_TYPE(device_type))
2094  {
2095  retval = ni_xcoder_session_query(p_ctx, device_type);
2096  } else
2097  {
2098  retval = NI_RETCODE_INVALID_PARAM;
2099  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
2100  __func__, device_type);
2101  }
2102 
2103  return retval;
2104 }
2105 
2106 /*!*****************************************************************************
2107  * \brief Query detail session data from the device -
2108  * If device_type is valid, will query session data
2109  * from specified device type
2110  *
2111  * \param[in] p_ctx Pointer to a caller allocated
2112  * ni_session_context_t struct
2113  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
2114  * NI_DEVICE_TYPE_ENCODER or
2115  *
2116  * \return On success
2117  * NI_RETCODE_SUCCESS
2118  * On failure
2119  * NI_RETCODE_INVALID_PARAM
2120  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2121  * NI_RETCODE_ERROR_INVALID_SESSION
2122  ******************************************************************************/
2124 {
2126  if (!p_ctx)
2127  {
2128  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
2129  __func__);
2130  return NI_RETCODE_INVALID_PARAM;
2131  }
2132 
2133  if (IS_XCODER_DEVICE_TYPE(device_type))
2134  {
2135  retval = ni_xcoder_session_query_detail(p_ctx, device_type, detail_data, 0);
2136  } else
2137  {
2138  retval = NI_RETCODE_INVALID_PARAM;
2139  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
2140  __func__, device_type);
2141  }
2142 
2143  return retval;
2144 }
2145 
2146 /*!*****************************************************************************
2147  * \brief Query detail session data from the device -
2148  * If device_type is valid, will query session data
2149  * from specified device type
2150  *
2151  * \param[in] p_ctx Pointer to a caller allocated
2152  * ni_session_context_t struct
2153  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
2154  * NI_DEVICE_TYPE_ENCODER or
2155  *
2156  * \return On success
2157  * NI_RETCODE_SUCCESS
2158  * On failure
2159  * NI_RETCODE_INVALID_PARAM
2160  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2161  * NI_RETCODE_ERROR_INVALID_SESSION
2162  ******************************************************************************/
2164 {
2166  if (!p_ctx)
2167  {
2168  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
2169  __func__);
2170  return NI_RETCODE_INVALID_PARAM;
2171  }
2172 
2173  if (IS_XCODER_DEVICE_TYPE(device_type))
2174  {
2175  retval = ni_xcoder_session_query_detail(p_ctx, device_type, detail_data, 1);
2176  } else
2177  {
2178  retval = NI_RETCODE_INVALID_PARAM;
2179  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
2180  __func__, device_type);
2181  }
2182 
2183  return retval;
2184 }
2185 
2186 /*!*****************************************************************************
2187  * \brief Send namespace num and SRIOv index to the device with specified logic block
2188  * address.
2189  *
2190  * \param[in] device_handle Device handle obtained by calling ni_device_open
2191  * \param[in] namespace_num Set the namespace number with designated sriov
2192  * \param[in] sriov_index Identify which sriov need to be set
2193  *
2194  * \return On success
2195  * NI_RETCODE_SUCCESS
2196  * On failure
2197  * NI_RETCODE_ERROR_MEM_ALOC
2198  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2199  ******************************************************************************/
2200 ni_retcode_t ni_device_config_namespace_num(ni_device_handle_t device_handle,
2201  uint32_t namespace_num, uint32_t sriov_index)
2202 {
2203  ni_log(NI_LOG_DEBUG, "%s namespace_num %u sriov_index %u\n",
2204  __func__, namespace_num, sriov_index);
2205  return ni_device_config_ns_qos(device_handle, namespace_num, sriov_index);
2206 }
2207 
2208 /*!*****************************************************************************
2209  * \brief Send qos mode to the device with specified logic block
2210  * address.
2211  *
2212  * \param[in] device_handle Device handle obtained by calling ni_device_open
2213  * \param[in] mode The requested qos mode
2214  *
2215  * \return On success
2216  * NI_RETCODE_SUCCESS
2217  * On failure
2218  * NI_RETCODE_ERROR_MEM_ALOC
2219  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2220  ******************************************************************************/
2221 ni_retcode_t ni_device_config_qos(ni_device_handle_t device_handle,
2222  uint32_t mode)
2223 {
2224  ni_log(NI_LOG_DEBUG, "%s device_handle %p mode %u\n",
2225  __func__, device_handle, mode);
2226  return ni_device_config_ns_qos(device_handle, QOS_NAMESPACE_CODE, mode);
2227 }
2228 
2229 /*!*****************************************************************************
2230  * \brief Send qos over provisioning mode to target namespace with specified logic
2231  * block address.
2232  *
2233  * \param[in] device_handle Device handle obtained by calling ni_device_open
2234  * \param[in] device_handle_t Target device handle of namespace required for OP
2235  * \param[in] over_provision The request overprovision percent
2236  *
2237  * \return On success
2238  * NI_RETCODE_SUCCESS
2239  * On failure
2240  * NI_RETCODE_ERROR_MEM_ALOC
2241  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2242  ******************************************************************************/
2243 ni_retcode_t ni_device_config_qos_op(ni_device_handle_t device_handle,
2244  ni_device_handle_t device_handle_t,
2245  uint32_t over_provision)
2246 {
2247  ni_retcode_t retval;
2248  float f_over_provision = 0;
2249  memcpy(&f_over_provision, &over_provision, sizeof(int32_t));
2250  ni_log(NI_LOG_DEBUG, "%s device_handle %p target %p over_provision %f\n",
2251  __func__, device_handle, device_handle_t, f_over_provision);
2252  retval = ni_device_config_ns_qos(device_handle, QOS_OP_CONFIG_REC_OP_CODE,
2253  over_provision);
2254  if (NI_RETCODE_SUCCESS != retval)
2255  {
2256  return retval;
2257  }
2258  retval = ni_device_config_ns_qos(device_handle_t, QOS_OP_CONFIG_CODE,
2259  0);
2260  return retval;
2261 }
2262 
2263 /*!*****************************************************************************
2264  * \brief Allocate preliminary memory for the frame buffer based on provided
2265  * parameters. Applicable to YUV420 Planar pixel (8 or 10 bit/pixel)
2266  * format or 32-bit RGBA.
2267  *
2268  * \param[in] p_frame Pointer to a caller allocated
2269  * ni_frame_t struct
2270  * \param[in] video_width Width of the video frame
2271  * \param[in] video_height Height of the video frame
2272  * \param[in] alignment Allignment requirement
2273  * \param[in] metadata_flag Flag indicating if space for additional metadata
2274  * should be allocated
2275  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel,
2276  * 4 for 32 bits/pixel (RGBA)
2277  * \param[in] hw_frame_count Number of hw descriptors stored
2278  * \param[in] is_planar 0 if semiplanar else planar
2279  *
2280  * \return On success
2281  * NI_RETCODE_SUCCESS
2282  * On failure
2283  * NI_RETCODE_INVALID_PARAM
2284  * NI_RETCODE_ERROR_MEM_ALOC
2285  ******************************************************************************/
2287  int video_height, int alignment,
2288  int metadata_flag, int factor,
2289  int hw_frame_count, int is_planar)
2290 {
2291  void* p_buffer = NULL;
2292  int metadata_size = 0;
2293  int retval = NI_RETCODE_SUCCESS;
2294  int width_aligned = video_width;
2295  int height_aligned = video_height;
2296 
2297  if ((!p_frame) || ((factor!=1) && (factor!=2) && (factor !=4))
2298  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
2299  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
2300  {
2301  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2302  "factor %d, video_width %d, video_height %d\n",
2303  __func__, factor, video_width, video_height);
2304  return NI_RETCODE_INVALID_PARAM;
2305  }
2306 
2307  if (metadata_flag)
2308  {
2309  metadata_size = NI_FW_META_DATA_SZ + NI_MAX_SEI_DATA;
2310  }
2311 
2312  if (QUADRA)
2313  {
2314  switch (factor)
2315  {
2316  case 1: /* 8-bit YUV420 */
2317  case 2: /* 10-bit YUV420 */
2318  width_aligned = ((((video_width * factor) + 127) / 128) * 128) / factor;
2319  height_aligned = ((video_height + 1) / 2) * 2;
2320  break;
2321  case 4: /* 32-bit RGBA */
2322  //64byte aligned => 16 rgba pixels
2323  width_aligned = NI_VPU_ALIGN16(video_width);
2324  height_aligned = ((video_height + 1) / 2) * 2;
2325  break;
2326  default:
2327  return NI_RETCODE_INVALID_PARAM;
2328  }
2329  }
2330  else
2331  {
2332  width_aligned = ((video_width + 31) / 32) * 32;
2333  height_aligned = ((video_height + 7) / 8) * 8;
2334  if (alignment)
2335  {
2336  height_aligned = ((video_height + 15) / 16) * 16;
2337  }
2338  }
2339 
2340  int luma_size = width_aligned * height_aligned * factor;
2341  int chroma_b_size;
2342  int chroma_r_size;
2343  if (QUADRA)
2344  {
2345  int chroma_width_aligned = ((((video_width / 2 * factor) + 127) / 128) * 128) / factor;
2346  if (is_planar == NI_PIXEL_PLANAR_FORMAT_TILED4X4 ||
2347  is_planar == NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR)
2348  {
2349  chroma_width_aligned =
2350  ((((video_width * factor) + 127) / 128) * 128) / factor;
2351  }
2352  int chroma_height_aligned = height_aligned / 2;
2353  chroma_b_size = chroma_r_size = chroma_width_aligned * chroma_height_aligned * factor;
2354  if (is_planar == NI_PIXEL_PLANAR_FORMAT_TILED4X4 ||
2355  is_planar == NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR)
2356  {
2357  chroma_r_size = 0;
2358  }
2359  if (4 == factor)
2360  {
2361  chroma_b_size = chroma_r_size = 0;
2362  }
2363  //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);
2364  }
2365  else
2366  {
2367  chroma_b_size = luma_size / 4;
2368  chroma_r_size = chroma_b_size;
2369  }
2370  int buffer_size;
2371 
2372  /* if hw_frame_count is zero, this is a software frame */
2373  if (hw_frame_count == 0)
2374  buffer_size = luma_size + chroma_b_size + chroma_r_size + metadata_size;
2375  else
2376  buffer_size =
2377  (int)sizeof(niFrameSurface1_t) * hw_frame_count + metadata_size;
2378 
2379  // added 2 blocks of 512 bytes buffer space to handle any extra metadata
2380  // retrieval from fw
2381  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT * 3;
2382  //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);
2383 
2384  //Check if need to free
2385  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
2386  {
2388  "%s: free current p_frame, p_frame->buffer_size=%u\n", __func__,
2389  p_frame->buffer_size);
2390  ni_frame_buffer_free(p_frame);
2391  }
2392 
2393  //Check if need to realocate
2394  if (p_frame->buffer_size != buffer_size)
2395  {
2396  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
2397  {
2398  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
2399  NI_ERRNO, __func__);
2400  retval = NI_RETCODE_ERROR_MEM_ALOC;
2401  LRETURN;
2402  }
2403 
2404  // init once after allocation
2405  //memset(p_buffer, 0, buffer_size);
2406  p_frame->buffer_size = buffer_size;
2407  p_frame->p_buffer = p_buffer;
2408 
2409  ni_log(NI_LOG_DEBUG, "%s: Allocate new p_frame buffer\n", __func__);
2410  }
2411  else
2412  {
2413  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
2414  }
2415 
2416  if (hw_frame_count)
2417  {
2418  p_frame->data_len[0] = 0;
2419  p_frame->data_len[1] = 0;
2420  p_frame->data_len[2] = 0;
2421  p_frame->data_len[3] = sizeof(niFrameSurface1_t)*hw_frame_count;
2422  }
2423  else
2424  {
2425  p_frame->data_len[0] = luma_size;
2426  p_frame->data_len[1] = chroma_b_size;
2427  p_frame->data_len[2] = chroma_r_size;
2428  p_frame->data_len[3] = 0;//unused by hwdesc
2429  }
2430 
2431  p_frame->p_data[0] = p_frame->p_buffer;
2432  p_frame->p_data[1] = p_frame->p_data[0] + p_frame->data_len[0];
2433  p_frame->p_data[2] = p_frame->p_data[1] + p_frame->data_len[1];
2434  p_frame->p_data[3] = p_frame->p_data[2] + p_frame->data_len[2]; //hwdescriptor
2435 
2436  // init p_data[3] to 0 so that ni_frame_buffer_free frees only valid DMA buf
2437  // fd in hw frame read from fw
2438  if (hw_frame_count)
2439  {
2440  memset(p_frame->p_data[3], 0, sizeof(niFrameSurface1_t) * hw_frame_count);
2441  }
2442 
2443  p_frame->video_width = width_aligned;
2444  p_frame->video_height = height_aligned;
2445 
2446  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);
2447  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2448  p_frame->buffer_size);
2449 
2450 END:
2451 
2452  if (NI_RETCODE_SUCCESS != retval)
2453  {
2454  ni_aligned_free(p_buffer);
2455  }
2456 
2457  return retval;
2458 }
2459 
2460 /*!*****************************************************************************
2461  * \brief Wrapper function for ni_frame_buffer_alloc. Meant to handle RGBA min.
2462  * resoulution considerations for encoder.
2463  *
2464  * \param[in] p_frame Pointer to a caller allocated
2465  * ni_frame_t struct
2466  * \param[in] video_width Width of the video frame
2467  * \param[in] video_height Height of the video frame
2468  * \param[in] alignment Allignment requirement
2469  * \param[in] metadata_flag Flag indicating if space for additional metadata
2470  * should be allocated
2471  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel,
2472  * 4 for 32 bits/pixel (RGBA)
2473  * \param[in] hw_frame_count Number of hw descriptors stored
2474  * \param[in] is_planar 0 if semiplanar else planar
2475  * \param[in] pix_fmt pixel format to distinguish between planar types
2476  * and/or components
2477  *
2478  * \return On success
2479  * NI_RETCODE_SUCCESS
2480  * On failure
2481  * NI_RETCODE_INVALID_PARAM
2482  * NI_RETCODE_ERROR_MEM_ALOC
2483  ******************************************************************************/
2485  int video_height, int alignment,
2486  int metadata_flag, int factor,
2487  int hw_frame_count, int is_planar,
2488  ni_pix_fmt_t pix_fmt)
2489 {
2490  int extra_len = 0;
2491  int dst_stride[NI_MAX_NUM_DATA_POINTERS] = {0};
2492  int height_aligned[NI_MAX_NUM_DATA_POINTERS] = {0};
2493 
2494  if (((factor!=1) && (factor!=2) && (factor !=4))
2495  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
2496  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
2497  {
2498  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2499  "factor %d, video_width %d, video_height %d\n",
2500  __func__, factor, video_width, video_height);
2501  return NI_RETCODE_INVALID_PARAM;
2502  }
2503 
2504  switch (pix_fmt)
2505  {
2506  case NI_PIX_FMT_YUV420P:
2508  case NI_PIX_FMT_NV12:
2509  case NI_PIX_FMT_P010LE:
2510  case NI_PIX_FMT_NV16:
2511  case NI_PIX_FMT_YUYV422:
2512  case NI_PIX_FMT_UYVY422:
2513  case NI_PIX_FMT_ARGB:
2514  case NI_PIX_FMT_ABGR:
2515  case NI_PIX_FMT_RGBA:
2516  case NI_PIX_FMT_BGRA:
2517  case NI_PIX_FMT_BGR0:
2518  break;
2519  default:
2520  ni_log(NI_LOG_ERROR, "ERROR: %s pix_fmt %d not supported \n",
2521  __func__, pix_fmt);
2522  return NI_RETCODE_INVALID_PARAM;
2523  }
2524  //Get stride info for original resolution
2525  ni_get_frame_dim(video_width, video_height,
2526  pix_fmt,
2527  dst_stride, height_aligned);
2528 
2529  if (metadata_flag)
2530  {
2531  extra_len = NI_FW_META_DATA_SZ + NI_MAX_SEI_DATA;
2532  }
2533 
2534  return ni_frame_buffer_alloc_pixfmt(p_frame, pix_fmt, video_width,
2535  video_height, dst_stride, alignment,
2536  extra_len);
2537 }
2538 
2539 /*!*****************************************************************************
2540  * \brief Allocate preliminary memory for the frame buffer based on provided
2541  * parameters.
2542  *
2543  * \param[in] p_frame Pointer to a caller allocated
2544  * ni_frame_t struct
2545  * \param[in] video_width Width of the video frame
2546  * \param[in] video_height Height of the video frame
2547  * \param[in] alignment Allignment requirement
2548  * \param[in] pixel_format Format for input
2549  *
2550  * \return On success
2551  * NI_RETCODE_SUCCESS
2552  * On failure
2553  * NI_RETCODE_INVALID_PARAM
2554  * NI_RETCODE_ERROR_MEM_ALOC
2555  ******************************************************************************/
2557  int video_height, int pixel_format)
2558 {
2559  void *p_buffer = NULL;
2560  int retval = NI_RETCODE_SUCCESS;
2561  int width_aligned = video_width;
2562  int height_aligned = video_height;
2563  int buffer_size;
2564  int luma_size;
2565  int chroma_b_size;
2566  int chroma_r_size;
2567 
2568  if ((!p_frame) || (video_width > NI_MAX_RESOLUTION_WIDTH) ||
2569  (video_width <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT) ||
2570  (video_height <= 0))
2571  {
2573  "ERROR: %s passed parameters are null or not supported, "
2574  "video_width %d, video_height %d\n",
2575  __func__, video_width, video_height);
2576  return NI_RETCODE_INVALID_PARAM;
2577  }
2578 
2579  switch (pixel_format)
2580  {
2581  case NI_PIX_FMT_YUV420P:
2582  width_aligned = NI_VPU_ALIGN128(video_width);
2583  height_aligned = NI_VPU_CEIL(video_height, 2);
2584 
2585  luma_size = width_aligned * height_aligned;
2586  chroma_b_size =
2587  NI_VPU_ALIGN128(video_width / 2) * height_aligned / 2;
2588  chroma_r_size = chroma_b_size;
2589  break;
2591  width_aligned = NI_VPU_ALIGN128(video_width * 2) / 2;
2592  height_aligned = NI_VPU_CEIL(video_height, 2);
2593 
2594  luma_size = width_aligned * height_aligned * 2;
2595  chroma_b_size = NI_VPU_ALIGN128(video_width) * height_aligned / 2;
2596  chroma_r_size = chroma_b_size;
2597  break;
2598  case NI_PIX_FMT_NV12:
2599  width_aligned = NI_VPU_ALIGN128(video_width);
2600  height_aligned = NI_VPU_CEIL(video_height, 2);
2601 
2602  luma_size = width_aligned * height_aligned;
2603  chroma_b_size = width_aligned * height_aligned / 2;
2604  chroma_r_size = 0;
2605  break;
2606  case NI_PIX_FMT_P010LE:
2607  width_aligned = NI_VPU_ALIGN128(video_width * 2) / 2;
2608  height_aligned = NI_VPU_CEIL(video_height, 2);
2609 
2610  luma_size = width_aligned * height_aligned * 2;
2611  chroma_b_size = NI_VPU_ALIGN128(video_width) * height_aligned;
2612  chroma_r_size = 0;
2613  break;
2614  case NI_PIX_FMT_NV16:
2615  width_aligned = NI_VPU_ALIGN64(video_width);
2616  height_aligned = video_height;
2617 
2618  luma_size = width_aligned * height_aligned;
2619  chroma_b_size = luma_size;
2620  chroma_r_size = 0;
2621  break;
2622  case NI_PIX_FMT_YUYV422:
2623  case NI_PIX_FMT_UYVY422:
2624  width_aligned = NI_VPU_ALIGN16(video_width);
2625  height_aligned = video_height;
2626 
2627  luma_size = width_aligned * height_aligned * 2;
2628  chroma_b_size = 0;
2629  chroma_r_size = 0;
2630  break;
2631  case NI_PIX_FMT_RGBA:
2632  case NI_PIX_FMT_BGRA:
2633  case NI_PIX_FMT_ARGB:
2634  case NI_PIX_FMT_ABGR:
2635  case NI_PIX_FMT_BGR0:
2636  width_aligned = NI_VPU_ALIGN16(video_width);
2637  height_aligned = video_height;
2638 
2639  luma_size = width_aligned * height_aligned * 4;
2640  chroma_b_size = 0;
2641  chroma_r_size = 0;
2642  break;
2643  case NI_PIX_FMT_BGRP:
2644  width_aligned = NI_VPU_ALIGN32(video_width);
2645  height_aligned = video_height;
2646 
2647  luma_size = width_aligned * height_aligned;
2648  chroma_b_size = luma_size;
2649  chroma_r_size = luma_size;
2650  break;
2651  default:
2652  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n", pixel_format);
2653  return NI_RETCODE_INVALID_PARAM;
2654  }
2655 
2656  /* Allocate local memory to hold a software ni_frame */
2657  buffer_size = luma_size + chroma_b_size + chroma_r_size;
2658 
2659  /* Round up to nearest 4K block */
2660  buffer_size = NI_VPU_ALIGN4096(buffer_size);
2661 
2662  ni_log(NI_LOG_DEBUG, "%s: Rlen %d Glen %d Blen %d buffer_size %d\n",
2663  __func__, luma_size, chroma_b_size, chroma_r_size, buffer_size);
2664 
2665  /* If the frame has changed, reallocate it */
2666  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
2667  {
2669  "%s: free current p_frame, p_frame->buffer_size=%u\n", __func__,
2670  p_frame->buffer_size);
2671  ni_frame_buffer_free(p_frame);
2672  }
2673 
2674  /* Check if need to reallocate */
2675  if (p_frame->buffer_size != buffer_size)
2676  {
2677  ni_log(NI_LOG_DEBUG, "%s: Allocate new p_frame buffer\n", __func__);
2678  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
2679  {
2681  "ERROR %d: %s() Cannot allocate p_frame buffer.\n", NI_ERRNO,
2682  __func__);
2683  retval = NI_RETCODE_ERROR_MEM_ALOC;
2684  LRETURN;
2685  }
2686  } else
2687  {
2688  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
2689  p_buffer = p_frame->p_buffer;
2690  }
2691 
2692  // init once after allocation
2693  // memset(p_buffer, 0, buffer_size);
2694 
2695  p_frame->buffer_size = buffer_size;
2696  p_frame->p_buffer = p_buffer;
2697 
2698  p_frame->data_len[0] = luma_size;
2699  p_frame->data_len[1] = chroma_b_size;
2700  p_frame->data_len[2] = chroma_r_size;
2701  p_frame->data_len[3] = 0;
2702 
2703  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
2704  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + p_frame->data_len[0];
2705  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + p_frame->data_len[1];
2706  p_frame->p_data[3] = (uint8_t *)p_frame->p_data[2] + p_frame->data_len[2];
2707 
2708  // init p_data[3] to 0 so that ni_frame_buffer_free frees only valid DMA buf
2709  // fd in hw frame read from fw
2710  p_frame->video_width = width_aligned;
2711  p_frame->video_height = height_aligned;
2712 
2713  // 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);
2714  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2715  p_frame->buffer_size);
2716 END:
2717 
2718  if (NI_RETCODE_SUCCESS != retval)
2719  {
2720  ni_aligned_free(p_buffer);
2721  }
2722 
2723  return retval;
2724 }
2725 
2726 /*!*****************************************************************************
2727  * \brief Allocate memory for decoder frame buffer based on provided
2728  * parameters; the memory is retrieved from a buffer pool and will be
2729  * returned to the same buffer pool by ni_decoder_frame_buffer_free.
2730  * Note: all attributes of ni_frame_t will be set up except for memory and
2731  * buffer, which rely on the pool being allocated; the pool will be
2732  * allocated only after the frame resolution is known.
2733  *
2734  * \param[in] p_pool Buffer pool to get the memory from
2735  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
2736  * \param[in] alloc_mem Whether to get memory from buffer pool
2737  * \param[in] video_width Width of the video frame
2738  * \param[in] video_height Height of the video frame
2739  * \param[in] alignment Alignment requirement
2740  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel
2741  * \param[in] is_planar 0 if semiplanar else planar
2742  *
2743  * \return On success
2744  * NI_RETCODE_SUCCESS
2745  * On failure
2746  * NI_RETCODE_INVALID_PARAM
2747  * NI_RETCODE_ERROR_MEM_ALOC
2748  ******************************************************************************/
2750  ni_frame_t *p_frame, int alloc_mem,
2751  int video_width, int video_height,
2752  int alignment, int factor,
2753  int is_planar)
2754 {
2755  int retval = NI_RETCODE_SUCCESS;
2756 
2757  int width_aligned;
2758  int height_aligned;
2759 
2760  if ((!p_frame) || ((factor!=1) && (factor!=2))
2761  || (video_width > NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
2762  || (video_height > NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
2763  {
2764  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2765  "factor %d, video_width %d, video_height %d\n",
2766  __func__, factor, video_width, video_height);
2767  return NI_RETCODE_INVALID_PARAM;
2768  }
2769 
2770  if (QUADRA)
2771  {
2772  width_aligned = ((((video_width * factor) + 127) / 128) * 128) / factor;
2773  height_aligned = video_height;
2774  }
2775  else
2776  {
2777  width_aligned = ((video_width + 31) / 32) * 32;
2778  height_aligned = ((video_height + 7) / 8) * 8;
2779  if (alignment)
2780  {
2781  height_aligned = ((video_height + 15) / 16) * 16;
2782  }
2783  }
2784 
2785  ni_log(NI_LOG_DEBUG, "%s: aligned=%dx%d orig=%dx%d\n", __func__,
2786  width_aligned, height_aligned, video_width, video_height);
2787 
2788  int luma_size = width_aligned * height_aligned * factor;
2789  int chroma_b_size;
2790  int chroma_r_size;
2791  if (QUADRA)
2792  {
2793  int chroma_width_aligned = ((((video_width / 2 * factor) + 127) / 128) * 128) / factor;
2794  if (!is_planar)
2795  {
2796  chroma_width_aligned =
2797  ((((video_width * factor) + 127) / 128) * 128) / factor;
2798  }
2799  int chroma_height_aligned = height_aligned / 2;
2800  chroma_b_size = chroma_r_size = chroma_width_aligned * chroma_height_aligned * factor;
2801  if (!is_planar)
2802  {
2803  chroma_r_size = 0;
2804  }
2805  }
2806  else
2807  {
2808  chroma_b_size = luma_size / 4;
2809  chroma_r_size = chroma_b_size;
2810  }
2811  int buffer_size = luma_size + chroma_b_size + chroma_r_size +
2813 
2814  // added 2 blocks of 512 bytes buffer space to handle any extra metadata
2815  // retrieval from fw
2816  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT * 3;
2817 
2818  p_frame->buffer_size = buffer_size;
2819 
2820  // if need to get a buffer from pool, pool must have been set up
2821  if (alloc_mem)
2822  {
2823  if (! p_pool)
2824  {
2825  ni_log(NI_LOG_ERROR, "ERROR %s: invalid pool!\n", __func__);
2826  retval = NI_RETCODE_ERROR_MEM_ALOC;
2827  LRETURN;
2828  }
2829 
2830  p_frame->dec_buf = ni_buf_pool_get_buffer(p_pool);
2831  if (! p_frame->dec_buf)
2832  {
2833  retval = NI_RETCODE_ERROR_MEM_ALOC;
2834  LRETURN;
2835  }
2836 
2837  p_frame->p_buffer = p_frame->dec_buf->buf;
2838 
2839  ni_log(NI_LOG_DEBUG, "%s: got new frame ptr %p buffer %p\n", __func__,
2840  p_frame->p_buffer, p_frame->dec_buf);
2841  }
2842  else
2843  {
2844  p_frame->dec_buf = NULL;
2845  p_frame->p_buffer = NULL;
2846  ni_log(NI_LOG_DEBUG, "%s: NOT alloc mem buffer\n", __func__);
2847  }
2848 
2849  if (p_frame->p_buffer)
2850  {
2851  p_frame->p_data[0] = p_frame->p_buffer;
2852  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
2853  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
2854  p_frame->p_data[3] = p_frame->p_data[2] + chroma_r_size;
2855  }
2856  else
2857  {
2858  p_frame->p_data[0] = p_frame->p_data[1] = p_frame->p_data[2] = NULL;
2859  }
2860 
2861  p_frame->data_len[0] = luma_size;
2862  p_frame->data_len[1] = chroma_b_size;
2863  p_frame->data_len[2] = chroma_r_size;
2864  p_frame->data_len[3] = 0; //for hwdesc
2865 
2866  p_frame->video_width = width_aligned;
2867  p_frame->video_height = height_aligned;
2868 
2869  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2870  p_frame->buffer_size);
2871 
2872 END:
2873 
2874  return retval;
2875 }
2876 
2877 /*!*****************************************************************************
2878  * \brief Check if incoming frame is encoder zero copy compatible or not
2879  *
2880  * \param[in] p_enc_ctx pointer to encoder context
2881  * [in] p_enc_params pointer to encoder parameters
2882  * [in] width input width
2883  * [in] height input height
2884  * [in] linesize input linesizes (pointer to array)
2885  * [in] set_linesize setup linesizes 0 means not setup linesizes, 1 means setup linesizes (before encoder open)
2886  *
2887  * \return on success and can do zero copy
2888  * NI_RETCODE_SUCCESS
2889  *
2890  * cannot do zero copy
2891  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
2892  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
2893  * NI_RETCODE_INVALID_PARAM
2894  *
2895 *******************************************************************************/
2897  ni_xcoder_params_t *p_enc_params,
2898  int width, int height,
2899  const int linesize[],
2900  bool set_linesize)
2901 {
2902  // check pixel format / width / height / linesize can be supported
2903  if ((!p_enc_ctx) || (!p_enc_params) || (!linesize)
2904  || (linesize[0]<=0)
2905  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
2906  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
2907  {
2908  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
2909  "p_enc_ctx %p, p_enc_params %p, linesize %p, "
2910  "width %d, height %d linesize[0] %d\n",
2911  __func__, p_enc_ctx, p_enc_params, linesize,
2912  width, height, (linesize) ? linesize[0] : 0);
2913  return NI_RETCODE_INVALID_PARAM;
2914  }
2915 
2916  // check fw revision (if fw_rev has been populated in open session)
2917  if (p_enc_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
2919  "6Q") < 0))
2920  {
2921  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.Q\n", __func__);
2923  }
2924 
2925  bool isrgba = false;
2926  bool isplanar = false;
2927  bool issemiplanar = false;
2928 
2929  switch (p_enc_ctx->pixel_format)
2930  {
2931  case NI_PIX_FMT_YUV420P:
2933  isplanar = true;
2934  break;
2935  case NI_PIX_FMT_NV12:
2936  case NI_PIX_FMT_P010LE:
2937  issemiplanar = true;
2938  break;
2939  case NI_PIX_FMT_ABGR:
2940  case NI_PIX_FMT_ARGB:
2941  case NI_PIX_FMT_RGBA:
2942  case NI_PIX_FMT_BGRA:
2943  isrgba = true;
2944  break;
2945  default:
2946  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
2948  }
2949 
2950  // check fw revision (if fw_rev has been populated in open session)
2951  if (issemiplanar &&
2954  "6q") < 0))
2955  {
2956  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
2958  }
2959 
2960  // check zero copy compatibilty and set linesize
2961  if (p_enc_params->zerocopy_mode) // always allow zero copy for RGBA, because RGBA pixel format data copy currently not supported
2962  {
2963  if (set_linesize)
2964  {
2965  bool ishwframe = (p_enc_params->hwframes) ? true : false;
2966  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
2967  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s isrgba %u issemiplanar %u, ishwframe %u, "
2968  "p_enc_ctx %p, p_enc_params %p, linesize %p, "
2969  "width %d, height %d, linesize[0] %d linesize[1] %d\n",
2970  __func__, isrgba, issemiplanar, ishwframe, p_enc_ctx, p_enc_params, linesize,
2971  width, height, linesize[0], linesize[1]);
2972 
2973  if (linesize[0] <= max_linesize &&
2974  linesize[0] % 2 == 0 && //even stride
2975  linesize[1] % 2 == 0 && //even stride
2976  width % 2 == 0 && //even width
2977  height % 2 == 0 && //even height
2978  (!p_enc_params->enable_ai_enhance || width % 128 == 0) && // align for AI engine
2979  width >= NI_MIN_WIDTH &&
2980  height >= NI_MIN_HEIGHT &&
2981  !ishwframe &&
2982  (!isplanar || linesize[2] == linesize[1]) // for planar, make sure cb linesize equal to cr linesize
2983  )
2984  {
2985  // send luma / chorma linesize to device (device is also aware frame will not be padded for 2-pass workaround)
2986  p_enc_params->luma_linesize = linesize[0];
2987  p_enc_params->chroma_linesize = (isrgba) ? 0 : linesize[1]; // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format
2988  return NI_RETCODE_SUCCESS;
2989  }
2990  else
2991  {
2992  p_enc_params->luma_linesize = 0;
2993  p_enc_params->chroma_linesize = 0;
2994  }
2995  }
2996  else if (p_enc_params->luma_linesize ||
2997  p_enc_params->chroma_linesize)
2998  {
2999  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s "
3000  "luma_linesize %d, chroma_linesize %d, "
3001  "linesize[0] %d, linesize[1] %d\n",
3002  __func__, p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
3003  linesize[0], linesize[1]);
3004  if (p_enc_params->luma_linesize != linesize[0] ||
3005  (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
3006  )
3007  {
3008 #ifndef XCODER_311
3009  // linesizes can change during SW frame seqeunce change transcoding when FFmpeg noautoscale option is not set
3010  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: linesize changed from %u %u to %u %u - resolution change?\n", __func__,
3011  p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
3012  linesize[0], linesize[1]);
3013 #endif
3014  }
3015  else
3016  return NI_RETCODE_SUCCESS;
3017  }
3018  }
3019 
3021 }
3022 
3023 /*!*****************************************************************************
3024  * \brief Allocate memory for encoder zero copy (metadata, etc.)
3025  * for encoding based on given
3026  * parameters, taking into account pic linesize and extra data.
3027  * Applicable to YUV planr / semi-planar 8 or 10 bit and RGBA pixel formats.
3028  *
3029  *
3030  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3031  * \param[in] video_width Width of the video frame
3032  * \param[in] video_height Height of the video frame
3033  * \param[in] linesize Picture line size
3034  * \param[in] data Picture data pointers (for each of YUV planes)
3035  * \param[in] extra_len Extra data size (incl. meta data)
3036  *
3037  * \return On success
3038  * NI_RETCODE_SUCCESS
3039  * On failure
3040  * NI_RETCODE_INVALID_PARAM
3041  * NI_RETCODE_ERROR_MEM_ALOC
3042  *****************************************************************************/
3044  int video_width, int video_height,
3045  const int linesize[], const uint8_t *data[],
3046  int extra_len)
3047 {
3048  int retval = NI_RETCODE_SUCCESS;
3049 
3050  if ((!p_frame) || (!linesize) || (!data))
3051  {
3052  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3053  "p_frame %p, linesize %p, data %p\n",
3054  __func__, p_frame, linesize, data);
3055  return NI_RETCODE_INVALID_PARAM;
3056  }
3057 
3059  "%s: resolution=%dx%d linesize=%d/%d/%d "
3060  "data=%p %p %p extra_len=%d\n",
3061  __func__, video_width, video_height,
3062  linesize[0], linesize[1], linesize[2],
3063  data[0], data[1], data[2], extra_len);
3064 
3065  if (p_frame->buffer_size)
3066  {
3067  p_frame->buffer_size = 0; //notify p_frame->p_buffer is not allocated
3068  ni_aligned_free(p_frame->p_buffer); // also free the temp p_buffer allocated for niFrameSurface1_t in encoder init stage
3069  }
3070 
3071  p_frame->p_buffer = (uint8_t *)data[0];
3072  p_frame->p_data[0] = (uint8_t *)data[0];
3073  p_frame->p_data[1] = (uint8_t *)data[1];
3074  p_frame->p_data[2] = (uint8_t *)data[2];
3075 
3076  int luma_size = linesize[0] * video_height;
3077  int chroma_b_size = 0;
3078  int chroma_r_size = 0;
3079 
3080  // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format, but only data[0] pointer is populated
3081  if (data[1]) // cb size is 0 for RGBA pixel format
3082  chroma_b_size = linesize[1] * (video_height / 2);
3083 
3084  if (data[2]) // cr size is 0 for semi-planar or RGBA pixel format
3085  chroma_r_size = linesize[2] * (video_height / 2);
3086 
3087  //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);
3088 
3089  uint32_t start_offset;
3090  uint32_t total_start_len = 0;
3091  int i;
3092 
3093  p_frame->inconsecutive_transfer = 0;
3094 
3095  // rgba has one data pointer, semi-planar has two data pointers
3096  if ((data[1] && (data[0] + luma_size != data[1]))
3097  || (data[2] && (data[1] + chroma_b_size != data[2])))
3098  {
3099  p_frame->inconsecutive_transfer = 1;
3100  }
3101 
3102  if (p_frame->inconsecutive_transfer)
3103  {
3104  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
3105  {
3106  start_offset = (uintptr_t)p_frame->p_data[i] % NI_MEM_PAGE_ALIGNMENT;
3107  p_frame->start_len[i] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
3108  total_start_len += p_frame->start_len[i];
3109  }
3110  }
3111  else
3112  {
3113  start_offset = (uintptr_t)p_frame->p_data[0] % NI_MEM_PAGE_ALIGNMENT;
3114  p_frame->start_len[0] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
3115  p_frame->start_len[1] = p_frame->start_len[2] = 0;
3116  total_start_len = p_frame->start_len[0];
3117  }
3118  p_frame->total_start_len = total_start_len;
3119 
3120  if (ni_encoder_metadata_buffer_alloc(p_frame, extra_len))
3121  {
3122  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_metadata_buffer buffer.\n",
3123  NI_ERRNO, __func__);
3124  retval = NI_RETCODE_ERROR_MEM_ALOC;
3125  LRETURN;
3126  }
3127  p_frame->separate_metadata = 1;
3128 
3129  if (total_start_len)
3130  {
3131  if (ni_encoder_start_buffer_alloc(p_frame))
3132  {
3133  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_start_buffer buffer.\n",
3134  NI_ERRNO, __func__);
3135  retval = NI_RETCODE_ERROR_MEM_ALOC;
3136  LRETURN;
3137  }
3138  p_frame->separate_start = 1;
3139 
3140  // copy non-4k-aligned part at the start of YUV data
3141  int start_buffer_offset = 0;
3142  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
3143  {
3144  if (p_frame->p_data[i])
3145  {
3146  memcpy(p_frame->p_start_buffer+start_buffer_offset, p_frame->p_data[i],
3147  p_frame->start_len[i]);
3148  start_buffer_offset += p_frame->start_len[i];
3149  }
3150  }
3151  }
3152 
3153  p_frame->data_len[0] = luma_size;
3154  p_frame->data_len[1] = chroma_b_size;
3155  p_frame->data_len[2] = chroma_r_size;
3156  p_frame->data_len[3] = 0;//unused by hwdesc
3157 
3158  p_frame->video_width = video_width;
3159  p_frame->video_height = video_height;
3160 
3162  "%s: success: p_metadata_buffer %p metadata_buffer_size %u "
3163  "p_start_buffer %p start_buffer_size %u data_len %u %u %u\n",
3164  __func__, p_frame->p_metadata_buffer, p_frame->metadata_buffer_size,
3165  p_frame->p_start_buffer, p_frame->start_buffer_size,
3166  p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2]);
3167 
3168 END:
3169 
3170  return retval;
3171 }
3172 
3173 
3174 /*!*****************************************************************************
3175  * \brief Check if incoming frame is hwupload zero copy compatible or not
3176  *
3177  * \param[in] p_upl_ctx pointer to uploader context
3178  * [in] width input width
3179  * [in] height input height
3180  * [in] linesize input linesizes (pointer to array)
3181  * [in] pixel_format input pixel format
3182  *
3183  * \return on success and can do zero copy
3184  * NI_RETCODE_SUCCESS
3185  *
3186  * cannot do zero copy
3187  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
3188  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
3189  * NI_RETCODE_INVALID_PARAM
3190  *
3191 *******************************************************************************/
3193  int width, int height,
3194  const int linesize[], int pixel_format)
3195 {
3196  // check pixel format / width / height / linesize can be supported
3197  if ((!p_upl_ctx) || (!linesize)
3198  || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3199  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
3200  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
3201  {
3202  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
3203  "p_enc_ctx %p, linesize %p, "
3204  "width %d, height %d linesize[0] %d\n",
3205  __func__, p_upl_ctx, linesize,
3206  width, height, (linesize) ? linesize[0] : 0);
3207  return NI_RETCODE_INVALID_PARAM;
3208  }
3209 
3210  // check fw revision (if fw_rev has been populated in open session)
3211  if (p_upl_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
3213  "6S") < 0))
3214  {
3215  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.S\n", __func__);
3217  }
3218 
3219  // upload does not have zeroCopyMode parameter, currently only allows resolution >= 1080p
3220  if ((width * height) < NI_NUM_OF_PIXELS_1080P)
3222 
3223  // check zero copy compatibilty
3224  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s pixel_format %d "
3225  "p_upl_ctx %p, linesize %p, "
3226  "width %d, height %d, linesize[0] %d\n",
3227  __func__, pixel_format, p_upl_ctx, linesize,
3228  width, height, linesize[0]);
3229 
3230  int bit_depth_factor;
3231  bool isrgba = false;
3232  bool isplanar = false;
3233  bool issemiplanar = false;
3234 
3235  switch (pixel_format)
3236  {
3237  case NI_PIX_FMT_YUV420P:
3238  isplanar = true;
3239  bit_depth_factor = 1;
3240  break;
3242  isplanar = true;
3243  bit_depth_factor = 2;
3244  break;
3245  case NI_PIX_FMT_NV12:
3246  issemiplanar = true;
3247  bit_depth_factor = 1;
3248  break;
3249  case NI_PIX_FMT_P010LE:
3250  issemiplanar = true;
3251  bit_depth_factor = 2;
3252  break;
3253  case NI_PIX_FMT_ABGR:
3254  case NI_PIX_FMT_ARGB:
3255  case NI_PIX_FMT_RGBA:
3256  case NI_PIX_FMT_BGRA:
3257  isrgba = true;
3258  bit_depth_factor = 4; // not accurate, only for linesize check
3259  break;
3260  default:
3261  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
3263  }
3264 
3265  // check fw revision (if fw_rev has been populated in open session)
3266  if (issemiplanar &&
3269  "6q") < 0))
3270  {
3271  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
3273  }
3274 
3275  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
3276  if (linesize[0] <= max_linesize &&
3277  width % 2 == 0 && //even width
3278  height % 2 == 0 && //even height
3279  width >= NI_MIN_WIDTH && height >= NI_MIN_HEIGHT)
3280  {
3281  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3282  if (isplanar &&
3283  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3284  linesize[1] == NI_VPU_ALIGN128(width * bit_depth_factor / 2) &&
3285  linesize[2] == linesize[1])
3286  return NI_RETCODE_SUCCESS;
3287 
3288  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3289  if (issemiplanar &&
3290  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3291  linesize[1] == linesize[0])
3292  return NI_RETCODE_SUCCESS;
3293 
3294  // rgba only support 64 bytes aligned for 2D
3295  if (isrgba &&
3296  linesize[0] == NI_VPU_ALIGN64(width * bit_depth_factor))
3297  return NI_RETCODE_SUCCESS;
3298  }
3299 
3301 }
3302 
3303 /*!*****************************************************************************
3304  * \brief Allocate memory for the frame buffer for encoding based on given
3305  * parameters, taking into account pic line size and extra data.
3306  * Applicable to YUV420p AVFrame only. 8 or 10 bit/pixel.
3307  * Cb/Cr size matches that of Y.
3308  *
3309  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3310  *
3311  * \param[in] video_width Width of the video frame
3312  * \param[in] video_height Height of the video frame
3313  * \param[in] linesize Picture line size
3314  * \param[in] alignment Allignment requirement
3315  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3316  * to allocate any buffer (zero-copy from existing)
3317  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3318  *
3319  * \return On success
3320  * NI_RETCODE_SUCCESS
3321  * On failure
3322  * NI_RETCODE_INVALID_PARAM
3323  * NI_RETCODE_ERROR_MEM_ALOC
3324  *****************************************************************************/
3326  int video_height, int linesize[],
3327  int alignment, int extra_len,
3328  bool alignment_2pass_wa)
3329 {
3330  void* p_buffer = NULL;
3331  int height_aligned;
3332  int retval = NI_RETCODE_SUCCESS;
3333 
3334  if ((!p_frame) || (!linesize) || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3335  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
3336  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
3337  {
3338  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3339  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3340  __func__, p_frame, linesize, video_width, video_height);
3341  return NI_RETCODE_INVALID_PARAM;
3342  }
3343 
3344  if (QUADRA)
3345  {
3346  height_aligned = ((video_height + 1) / 2) * 2;
3347  } else
3348  {
3349  height_aligned = ((video_height + 7) / 8) * 8;
3350 
3351  if (alignment)
3352  {
3353  height_aligned = ((video_height + 15) / 16) * 16;
3354  }
3355  }
3356  if (height_aligned < NI_MIN_HEIGHT)
3357  {
3358  height_aligned = NI_MIN_HEIGHT;
3359  }
3360 
3362  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d "
3363  "extra_len=%d\n",
3364  __func__, video_width, height_aligned, video_width, video_height,
3365  linesize[0], linesize[1], linesize[2], extra_len);
3366 
3367  int luma_size = linesize[0] * height_aligned;
3368  int chroma_b_size;
3369  int chroma_r_size;
3370  if (QUADRA)
3371  {
3372  chroma_b_size = chroma_r_size = linesize[1] * (height_aligned / 2);
3373  if (alignment_2pass_wa)
3374  {
3375  // for 2-pass encode output mismatch WA, need to extend (and pad) Cr plane height, because 1st pass assume input 32 align
3376  chroma_r_size = linesize[1] * (((height_aligned + 31) / 32) * 32) / 2;
3377  }
3378  //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);
3379  }
3380  else
3381  {
3382  chroma_b_size = luma_size / 4;
3383  chroma_r_size = luma_size / 4;
3384  }
3385  if(extra_len >= 0)
3386  {
3387  int buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
3388 
3389  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3390 
3391  //Check if Need to free
3392  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3393  {
3395  "%s: free current p_frame, "
3396  "p_frame->buffer_size=%u\n",
3397  __func__, p_frame->buffer_size);
3398  ni_frame_buffer_free(p_frame);
3399  }
3400 
3401  //Check if need to realocate
3402  if (p_frame->buffer_size != buffer_size)
3403  {
3404  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3405  {
3406  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3407  NI_ERRNO, __func__);
3408  retval = NI_RETCODE_ERROR_MEM_ALOC;
3409  LRETURN;
3410  }
3411 
3412  // init once after allocation
3413  memset(p_buffer, 0, buffer_size);
3414  p_frame->buffer_size = buffer_size;
3415  p_frame->p_buffer = p_buffer;
3416 
3417  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3418  }
3419  else
3420  {
3421  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3422  }
3423  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3424  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3425  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_b_size;
3426  }
3427  else
3428  {
3429  p_frame->buffer_size = 0; //no ownership
3430  }
3431 
3432  p_frame->data_len[0] = luma_size;
3433  p_frame->data_len[1] = chroma_b_size;
3434  p_frame->data_len[2] = chroma_r_size;
3435  p_frame->data_len[3] = 0;//unused by hwdesc
3436 
3437  p_frame->video_width = video_width;
3438  p_frame->video_height = height_aligned;
3439 
3441  "%s: success: p_frame->p_buffer %p "
3442  "p_frame->buffer_size=%u\n",
3443  __func__, p_frame->p_buffer, p_frame->buffer_size);
3444 
3445 END:
3446 
3447  if (NI_RETCODE_SUCCESS != retval)
3448  {
3449  ni_aligned_free(p_buffer);
3450  }
3451 
3452  return retval;
3453 }
3454 
3455 /*!*****************************************************************************
3456  * \brief allocate device destination frame from scaler hwframe pool
3457  *
3458  * \param
3459  *
3460  * \return 0 if successful, < 0 otherwise
3461  ******************************************************************************/
3463  ni_scaler_input_params_t scaler_params,
3464  niFrameSurface1_t *p_surface)
3465 {
3466  int ret = 0;
3467  if (scaler_params.op != NI_SCALER_OPCODE_OVERLAY && scaler_params.op != NI_SCALER_OPCODE_WATERMARK)
3468  {
3469  ret = ni_device_alloc_frame(
3470  p_ctx, scaler_params.output_width, scaler_params.output_height,
3471  scaler_params.output_format, NI_SCALER_FLAG_IO,
3472  scaler_params.out_rec_width, scaler_params.out_rec_height,
3473  scaler_params.out_rec_x, scaler_params.out_rec_y,
3474  scaler_params.rgba_color, -1, NI_DEVICE_TYPE_SCALER);
3475  } else
3476  {
3477  // in vf_overlay_ni.c: flags = (s->alpha_format ? NI_SCALER_FLAG_PA : 0) | NI_SCALER_FLAG_IO;
3478  ret = ni_device_alloc_frame(
3479  p_ctx, scaler_params.output_width, scaler_params.output_height,
3480  scaler_params.output_format, NI_SCALER_FLAG_IO,
3481  scaler_params.out_rec_width, scaler_params.out_rec_height,
3482  scaler_params.out_rec_x, scaler_params.out_rec_y,
3483  p_surface->ui32nodeAddress, p_surface->ui16FrameIdx,
3485  }
3486  return ret;
3487 }
3488 
3489 /*!*****************************************************************************
3490  * \brief allocate device input frame by hw descriptor. This call won't actually allocate
3491  a frame but sends the incoming hardware frame index to the scaler manager
3492  *
3493  * \param
3494  *
3495  * \return 0 if successful, < 0 otherwise
3496  ******************************************************************************/
3498  ni_scaler_input_params_t scaler_params,
3499  niFrameSurface1_t *p_src_surface)
3500 {
3501  int ret = 0;
3502 
3503  ret = ni_device_alloc_frame(
3504  p_ctx, scaler_params.input_width, scaler_params.input_height,
3505  scaler_params.input_format, 0, scaler_params.in_rec_width,
3506  scaler_params.in_rec_height, scaler_params.in_rec_x,
3507  scaler_params.in_rec_y, p_src_surface->ui32nodeAddress,
3508  p_src_surface->ui16FrameIdx, NI_DEVICE_TYPE_SCALER);
3509  return ret;
3510 }
3511 
3512 /*!*****************************************************************************
3513  * \brief init output pool of scaler frames
3514  *
3515  * \param
3516  *
3517  * \return 0 if successful, < 0 otherwise
3518  ******************************************************************************/
3520  ni_scaler_input_params_t scaler_params)
3521 {
3522  int rc = 0;
3523  int options = NI_SCALER_FLAG_IO | NI_SCALER_FLAG_PC;
3524  if (p_ctx->isP2P)
3525  options |= NI_SCALER_FLAG_P2;
3526 
3527  /* Allocate a pool of frames by the scaler */
3528  rc = ni_device_alloc_frame(p_ctx, scaler_params.output_width,
3529  scaler_params.output_height,
3530  scaler_params.output_format, options,
3531  0, // rec width
3532  0, // rec height
3533  0, // rec X pos
3534  0, // rec Y pos
3535  NI_MAX_FILTER_POOL_SIZE, // rgba color/pool size
3536  0, // frame index
3538  return rc;
3539 }
3540 
3541 /*!*****************************************************************************
3542 * \brief Allocate memory for the frame buffer based on provided parameters
3543 * taking into account pic line size and extra data.
3544 * Applicable to nv12 AVFrame only. Cb/Cr size matches that of Y.
3545 *
3546 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3547 *
3548 * \param[in] video_width Width of the video frame
3549 * \param[in] video_height Height of the video frame
3550 * \param[in] linesize Picture line size
3551 * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3552 * to allocate any buffer (zero-copy from existing)
3553 * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3554 *
3555 * \return On success
3556 * NI_RETCODE_SUCCESS
3557 * On failure
3558 * NI_RETCODE_INVALID_PARAM
3559 * NI_RETCODE_ERROR_MEM_ALOC
3560 *****************************************************************************/
3562  int video_height, int linesize[],
3563  int extra_len, bool alignment_2pass_wa)
3564 {
3565  void* p_buffer = NULL;
3566  int height_aligned;
3567  int retval = NI_RETCODE_SUCCESS;
3568 
3569  if ((!p_frame) || (!linesize) || (linesize[0] <= 0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3570  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
3571  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
3572  {
3573  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3574  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3575  __func__, p_frame, linesize, video_width, video_height);
3576  return NI_RETCODE_INVALID_PARAM;
3577  }
3578 
3579  height_aligned = ((video_height + 1) / 2) * 2;
3580 
3581  if (height_aligned < NI_MIN_HEIGHT)
3582  {
3583  height_aligned = NI_MIN_HEIGHT;
3584  }
3585 
3587  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d extra_len=%d\n",
3588  __func__, video_width, height_aligned, video_width, video_height,
3589  linesize[0], linesize[1], linesize[2], extra_len);
3590 
3591  int luma_size = linesize[0] * height_aligned;
3592  int chroma_br_size = luma_size / 2;
3593  //int chroma_r_size = luma_size / 4;
3594  if (alignment_2pass_wa)
3595  {
3596  // for 2-pass encode output mismatch WA, need to extend (and pad) CbCr plane height, because 1st pass assume input 32 align
3597  chroma_br_size = linesize[0] * ((((height_aligned + 31) / 32) * 32) / 2);
3598  }
3599  if (extra_len >= 0)
3600  {
3601  int buffer_size = luma_size + chroma_br_size + extra_len;
3602 
3603  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3604 
3605  //Check if Need to free
3606  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3607  {
3608  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
3609  __func__, p_frame->buffer_size);
3610  ni_frame_buffer_free(p_frame);
3611  }
3612 
3613  //Check if need to realocate
3614  if (p_frame->buffer_size != buffer_size)
3615  {
3616  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3617  {
3618  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3619  NI_ERRNO, __func__);
3620  retval = NI_RETCODE_ERROR_MEM_ALOC;
3621  LRETURN;
3622  }
3623 
3624  // init once after allocation
3625  memset(p_buffer, 0, buffer_size);
3626  p_frame->buffer_size = buffer_size;
3627  p_frame->p_buffer = p_buffer;
3628 
3629  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3630  }
3631  else
3632  {
3633  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3634  }
3635 
3636  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3637  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3638  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_br_size;
3639  }
3640  else
3641  {
3642  p_frame->buffer_size = 0; //no ownership
3643  }
3644  p_frame->data_len[0] = luma_size;
3645  p_frame->data_len[1] = chroma_br_size;
3646  p_frame->data_len[2] = 0;
3647 
3648  p_frame->video_width = video_width;
3649  p_frame->video_height = height_aligned;
3650 
3651  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
3652  p_frame->buffer_size);
3653 
3654 END:
3655 
3656  if (NI_RETCODE_SUCCESS != retval)
3657  {
3658  ni_aligned_free(p_buffer);
3659  }
3660 
3661  return retval;
3662 }
3663 
3664 /*!*****************************************************************************
3665  * \brief This API is a wrapper for ni_encoder_frame_buffer_alloc(), used
3666  * for planar pixel formats, and ni_frame_buffer_alloc_nv(), used for
3667  * semi-planar pixel formats. This API is meant to combine the
3668  * functionality for both individual format APIs.
3669  * Allocate memory for the frame buffer for encoding based on given
3670  * parameters, taking into account pic line size and extra data.
3671  * Applicable to YUV420p(8 or 10 bit/pixel) or nv12 AVFrame.
3672  * Cb/Cr size matches that of Y.
3673  *
3674  * \param[in] planar true: if planar:
3675  * pixel_format == (NI_PIX_FMT_YUV420P ||
3676  * NI_PIX_FMT_YUV420P10LE ||NI_PIX_FMT_RGBA).
3677  * false: semi-planar:
3678  * pixel_format == (NI_PIX_FMT_NV12 ||
3679  * NI_PIX_FMT_P010LE).
3680  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3681  * \param[in] video_width Width of the video frame
3682  * \param[in] video_height Height of the video frame
3683  * \param[in] linesize Picture line size
3684  * \param[in] alignment Allignment requirement. Only used for planar format.
3685  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3686  * to allocate any buffer (zero-copy from existing)
3687  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3688  *
3689  * \return On success
3690  * NI_RETCODE_SUCCESS
3691  * On failure
3692  * NI_RETCODE_INVALID_PARAM
3693  * NI_RETCODE_ERROR_MEM_ALOC
3694  *****************************************************************************/
3696  int video_width, int video_height,
3697  int linesize[], int alignment,
3698  int extra_len,
3699  bool alignment_2pass_wa)
3700 {
3701  if (true == planar)
3702  {
3703  return ni_encoder_frame_buffer_alloc(p_frame, video_width, video_height,
3704  linesize, alignment, extra_len,
3705  alignment_2pass_wa);
3706  }
3707  else
3708  {
3709  return ni_frame_buffer_alloc_nv(p_frame, video_width, video_height,
3710  linesize, extra_len,
3711  alignment_2pass_wa);
3712  }
3713 }
3714 
3715 /*!*****************************************************************************
3716  * \brief Free frame buffer that was previously allocated with either
3717  * ni_frame_buffer_alloc or ni_encoder_frame_buffer_alloc or
3718  * ni_frame_buffer_alloc_nv
3719  *
3720  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3721  *
3722  * \return On success NI_RETCODE_SUCCESS
3723  * On failure NI_RETCODE_INVALID_PARAM
3724  ******************************************************************************/
3726 {
3727  int i;
3729 
3730  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3731 
3732  if (!p_frame)
3733  {
3734  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3735  LRETURN;
3736  }
3737 
3738  if (!p_frame->p_buffer)
3739  {
3740  ni_log(NI_LOG_DEBUG, "WARN: %s(): already freed, nothing to free\n",
3741  __func__);
3742  }
3743 
3744 #ifndef _WIN32
3745  // If this is a hardware frame with a DMA buf fd attached, close the DMA buf fd
3746  if ((p_frame->data_len[3] > 0) && (p_frame->p_data[3] != NULL))
3747  {
3748  niFrameSurface1_t *p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
3749  if ((p_surface->dma_buf_fd > 0) && (p_surface->ui16FrameIdx > 0))
3750  {
3751  // Close the DMA buf fd
3753  "%s: close p_surface->dma_buf_fd %d "
3754  "ui16FrameIdx %u\n",
3755  __func__, p_surface->dma_buf_fd, p_surface->ui16FrameIdx);
3756  close(p_surface->dma_buf_fd);
3757  }
3758  }
3759 #endif
3760 
3761  if (p_frame->buffer_size)
3762  {
3763  p_frame->buffer_size = 0;
3764  ni_aligned_free(p_frame->p_buffer);
3765  }
3766 
3767  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3768  {
3769  p_frame->data_len[i] = 0;
3770  p_frame->p_data[i] = NULL;
3771  }
3772 
3773  ni_frame_wipe_aux_data(p_frame);
3774 
3775  if (p_frame->metadata_buffer_size)
3776  {
3777  p_frame->metadata_buffer_size = 0;
3779  }
3780  p_frame->separate_metadata = 0;
3781 
3782  if (p_frame->start_buffer_size)
3783  {
3784  p_frame->start_buffer_size = 0;
3785  ni_aligned_free(p_frame->p_start_buffer);
3786  }
3787  p_frame->separate_start = 0;
3788  memset(p_frame->start_len, 0, sizeof(p_frame->start_len));
3789  p_frame->total_start_len = 0;
3790  p_frame->inconsecutive_transfer = 0;
3791 
3792 END:
3793 
3794  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3795 
3796  return retval;
3797 }
3798 
3799 /*!*****************************************************************************
3800  * \brief Free decoder frame buffer that was previously allocated with
3801  * ni_decoder_frame_buffer_alloc, returning memory to a buffer pool.
3802  *
3803  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3804  *
3805  * \return On success NI_RETCODE_SUCCESS
3806  * On failure NI_RETCODE_INVALID_PARAM
3807  ******************************************************************************/
3809 {
3810  int i;
3812 
3813  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3814 
3815  if (!p_frame)
3816  {
3817  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3818  retval = NI_RETCODE_INVALID_PARAM;
3819  LRETURN;
3820  }
3821 
3822  if (p_frame->dec_buf)
3823  {
3825  ni_log(NI_LOG_DEBUG, "%s(): Mem buf returned ptr %p buf %p !\n", __func__,
3826  p_frame->dec_buf->buf, p_frame->dec_buf);
3827  }
3828  else
3829  {
3830  ni_log(NI_LOG_DEBUG, "%s(): NO mem buf returned !\n", __func__);
3831  }
3832 
3833  p_frame->dec_buf = NULL;
3834  p_frame->p_buffer = NULL;
3835  p_frame->buffer_size = 0;
3836  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3837  {
3838  p_frame->data_len[i] = 0;
3839  p_frame->p_data[i] = NULL;
3840  }
3841  ni_frame_wipe_aux_data(p_frame);
3842 
3843 END:
3844 
3845  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3846 
3847  return retval;
3848 }
3849 
3850 /*!*****************************************************************************
3851  * \brief Return a memory buffer to memory buffer pool.
3852  *
3853  * \param[in] buf Buffer to be returned.
3854  * \param[in] p_buffer_pool Buffer pool to return buffer to.
3855  *
3856  * \return None
3857  ******************************************************************************/
3859  ni_buf_pool_t *p_buffer_pool)
3860 {
3861  ni_buf_pool_return_buffer(buf, p_buffer_pool);
3862 }
3863 
3864 /*!*****************************************************************************
3865  * \brief Allocate memory for the packet buffer based on provided packet size
3866  *
3867  * \param[in] p_packet Pointer to a caller allocated
3868  * ni_packet_t struct
3869  * \param[in] packet_size Required allocation size
3870  *
3871  * \return On success
3872  * NI_RETCODE_SUCCESS
3873  * On failure
3874  * NI_RETCODE_INVALID_PARAM
3875  * NI_RETCODE_ERROR_MEM_ALOC
3876  ******************************************************************************/
3878 {
3879  void* p_buffer = NULL;
3880  int metadata_size = 0;
3881 
3882  metadata_size = NI_FW_META_DATA_SZ;
3883 
3884  int buffer_size = (((packet_size + metadata_size) / NI_MAX_PACKET_SZ) + 1) * NI_MAX_PACKET_SZ;
3885 
3886  ni_log(NI_LOG_TRACE, "%s: packet_size=%d\n", __func__,
3887  packet_size + metadata_size);
3888 
3889  if (!p_packet || !packet_size)
3890  {
3891  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3892  __func__);
3893  return NI_RETCODE_INVALID_PARAM;
3894  }
3895 
3896  if (buffer_size % NI_MEM_PAGE_ALIGNMENT)
3897  {
3898  buffer_size = ( (buffer_size / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT ) + NI_MEM_PAGE_ALIGNMENT;
3899  }
3900 
3901  if (p_packet->buffer_size == buffer_size)
3902  {
3903  // Already allocated the exact size.
3904  p_packet->p_data = p_packet->p_buffer;
3905  ni_log(NI_LOG_DEBUG, "%s: reuse current p_packet buffer\n", __func__);
3906  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3907  p_packet->buffer_size);
3908  return NI_RETCODE_SUCCESS;
3909  }
3910 
3911  if (p_packet->buffer_size)
3912  {
3914  "%s: free current p_packet, p_packet->buffer_size=%u\n", __func__,
3915  p_packet->buffer_size);
3916  ni_packet_buffer_free(p_packet);
3917  }
3918 
3919  ni_log(NI_LOG_DEBUG, "%s: Allocating p_frame buffer, buffer_size=%d\n",
3920  __func__, buffer_size);
3921 
3922  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3923  {
3924  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
3925  NI_ERRNO, __func__);
3926  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3927  p_packet->buffer_size);
3929  }
3930 
3931  p_packet->buffer_size = buffer_size;
3932  p_packet->p_buffer = p_buffer;
3933  p_packet->p_data = p_packet->p_buffer;
3934 
3935  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3936  p_packet->buffer_size);
3937 
3938  return NI_RETCODE_SUCCESS;
3939 }
3940 
3941 /*!*****************************************************************************
3942  * \brief Allocate packet buffer using a user provided pointer, the memory
3943  * is expected to have already been allocated.
3944  *
3945  * For ideal performance memory should be 4k aligned. If it is not 4K aligned
3946  * then a temporary 4k aligned memory will be used to copy data to and from
3947  * when writing and reading. This will negatively impact performance.
3948  *
3949  * This API will overwrite p_packet->buffer_size, p_packet->p_buffer and
3950  * p_packet->p_data fields in p_packet.
3951  *
3952  * This API will not free any memory associated with p_packet->p_buffer and
3953  * p_packet->p_data fields in p_packet.
3954  * Common use case could be,
3955  * 1. Allocate memory to pointer
3956  * 2. Call ni_custom_packet_buffer_alloc() with allocated pointer.
3957  * 3. Use p_packet as required.
3958  * 4. Call ni_packet_buffer_free() to free up the memory.
3959  *
3960  * \param[in] p_buffer User provided pointer to be used for buffer
3961  * \param[in] p_packet Pointer to a caller allocated
3962  * ni_packet_t struct
3963  * \param[in] buffer_size Buffer size
3964  *
3965  * \return On success
3966  * NI_RETCODE_SUCCESS
3967  * On failure
3968  * NI_RETCODE_INVALID_PARAM
3969  * NI_RETCODE_ERROR_MEM_ALOC
3970  ******************************************************************************/
3972  ni_packet_t *p_packet,
3973  int buffer_size)
3974 {
3975  ni_log(NI_LOG_TRACE, "%s(): enter buffer_size=%d\n", __func__, buffer_size);
3976 
3977  if (!p_buffer || !p_packet || !buffer_size)
3978  {
3979  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3980  __func__);
3981  return NI_RETCODE_INVALID_PARAM;
3982  }
3983  if (((uintptr_t)p_buffer) % NI_MEM_PAGE_ALIGNMENT)
3984  {
3985  ni_log(NI_LOG_INFO, "Info: %s: Warning buffer not 4k aligned = %p!. Will do an extra copy\n",
3986  __func__, p_buffer);
3987  }
3988 
3989  p_packet->buffer_size = buffer_size;
3990  p_packet->p_buffer = p_buffer;
3991  p_packet->p_data = p_packet->p_buffer;
3992 
3993  ni_log(NI_LOG_TRACE, "%s: exit: \n", __func__);
3994 
3995  return NI_RETCODE_SUCCESS;
3996 }
3997 
3998 /*!*****************************************************************************
3999  * \brief Free packet buffer that was previously allocated with
4000  * ni_packet_buffer_alloc
4001  *
4002  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
4003  *
4004  * \return On success NI_RETCODE_SUCCESS
4005  * On failure NI_RETCODE_INVALID_PARAM
4006  ******************************************************************************/
4008 {
4010 
4011  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
4012 
4013  if (!p_packet)
4014  {
4015  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
4016  retval = NI_RETCODE_FAILURE;
4017  LRETURN;
4018  }
4019 
4020  if (!p_packet->p_buffer)
4021  {
4022  ni_log(NI_LOG_DEBUG, "%s(): already freed, nothing to free\n", __func__);
4023  LRETURN;
4024  }
4025 
4026  ni_aligned_free(p_packet->p_buffer);
4027  p_packet->p_buffer = NULL;
4028  p_packet->buffer_size = 0;
4029  p_packet->data_len = 0;
4030  p_packet->p_data = NULL;
4031 
4032  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
4033 
4034 END:
4035 
4036  return retval;
4037 }
4038 
4039 /*!*****************************************************************************
4040  * \brief Free packet buffer that was previously allocated with
4041  * ni_packet_buffer_alloc for AV1 packets merge
4042  *
4043  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
4044  *
4045  * \return On success NI_RETCODE_SUCCESS
4046  * On failure NI_RETCODE_INVALID_PARAM
4047  ******************************************************************************/
4049 {
4050  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
4052  int i;
4053 
4054  if (!p_packet)
4055  {
4056  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
4057  retval = NI_RETCODE_FAILURE;
4058  LRETURN;
4059  }
4060 
4061  if (!p_packet->av1_buffer_index)
4062  {
4064  "%s(): no need to free previous av1 packet buffers\n", __func__);
4065  LRETURN;
4066  }
4067 
4068  for (i = 0; i < p_packet->av1_buffer_index; i++)
4069  {
4070  ni_log(NI_LOG_DEBUG, "%s(): free previous av1 packet buffer %d\n",
4071  __func__, i);
4072  ni_aligned_free(p_packet->av1_p_buffer[i]);
4073  p_packet->av1_p_buffer[i] = NULL;
4074  p_packet->av1_p_data[i] = NULL;
4075  p_packet->av1_buffer_size[i] = 0;
4076  p_packet->av1_data_len[i] = 0;
4077  }
4078 
4079  p_packet->av1_buffer_index = 0;
4080 
4081 END:
4082 
4083  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
4084 
4085  return retval;
4086 }
4087 
4088 /*!*****************************************************************************
4089  * \brief Copy video packet accounting for alignment
4090  *
4091  * \param[in] p_destination Destination to where to copy to
4092  * \param[in] p_source Source from where to copy from
4093  * \param[in] cur_size current size
4094  * \param[out] p_leftover Pointer to the data that was left over
4095  * \param[out] p_prev_size Size of the data leftover ??
4096  *
4097  * \return On success Total number of bytes that were copied
4098  * On failure NI_RETCODE_FAILURE
4099  ******************************************************************************/
4100 int ni_packet_copy(void* p_destination, const void* const p_source, int cur_size, void* p_leftover, int* p_prev_size)
4101 {
4102  int copy_size = 0;
4103  int padding_size = 0;
4104  int prev_size = p_prev_size == NULL? 0 : *p_prev_size;
4105 
4106  int total_size = cur_size + prev_size;
4107  uint8_t* p_src = (uint8_t*)p_source;
4108  uint8_t* p_dst = (uint8_t*)p_destination;
4109  uint8_t* p_lftover = (uint8_t*)p_leftover;
4110 
4111  if (!p_prev_size)
4112  {
4113  return NI_RETCODE_INVALID_PARAM;
4114  }
4115 
4116  ni_log(NI_LOG_TRACE, "%s(): enter, *prev_size=%d\n", __func__, *p_prev_size);
4117 
4118  if ((0 == cur_size) && (0 == prev_size))
4119  {
4120  return copy_size;
4121  }
4122 
4123  if (((0 != cur_size) && (!p_source)) || (!p_destination) || (!p_leftover))
4124  {
4125  return NI_RETCODE_FAILURE;
4126  }
4127 
4128  copy_size = ((total_size + NI_MEM_PAGE_ALIGNMENT - 1) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT;
4129 
4130  if (copy_size > total_size)
4131  {
4132  padding_size = copy_size - total_size;
4133  }
4134 
4135  if (prev_size > 0)
4136  {
4137  memcpy(p_dst, p_lftover, prev_size);
4138  }
4139 
4140  p_dst += prev_size;
4141 
4142  memcpy(p_dst, p_src, cur_size);
4143 
4144  if (padding_size)
4145  {
4146  p_dst += cur_size;
4147  memset(p_dst, 0, padding_size);
4148  }
4149 
4151  "%s(): exit, cur_size=%d, copy_size=%d, "
4152  "prev_size=%d, padding_size=%d\n", __func__, cur_size,
4153  copy_size, *p_prev_size, padding_size);
4154 
4155  *p_prev_size = 0;
4156 
4157  return copy_size;
4158 }
4159 
4160 /*!*****************************************************************************
4161  * \brief Add a new auxiliary data to a frame
4162  *
4163  * \param[in/out] frame a frame to which the auxiliary data should be added
4164  * \param[in] type type of the added auxiliary data
4165  * \param[in] data_size size of the added auxiliary data
4166  *
4167  * \return a pointer to the newly added aux data on success, NULL otherwise
4168  ******************************************************************************/
4170  int data_size)
4171 {
4172  ni_aux_data_t *ret;
4173 
4175  !(ret = malloc(sizeof(ni_aux_data_t))))
4176  {
4178  "ERROR: %s No memory or exceeding max aux_data number !\n",
4179  __func__);
4180  return NULL;
4181  }
4182 
4183  ret->type = type;
4184  ret->size = data_size;
4185  ret->data = calloc(1, data_size);
4186  if (!ret->data)
4187  {
4188  ni_log(NI_LOG_ERROR, "ERROR: %s No memory for aux data !\n", __func__);
4189  free(ret);
4190  ret = NULL;
4191  } else
4192  {
4193  frame->aux_data[frame->nb_aux_data++] = ret;
4194  }
4195 
4196  return ret;
4197 }
4198 
4199 /*!*****************************************************************************
4200  * \brief Add a new auxiliary data to a frame and copy in the raw data
4201  *
4202  * \param[in/out] frame a frame to which the auxiliary data should be added
4203  * \param[in] type type of the added auxiliary data
4204  * \param[in] raw_data the raw data of the aux data
4205  * \param[in] data_size size of the added auxiliary data
4206  *
4207  * \return a pointer to the newly added aux data on success, NULL otherwise
4208  ******************************************************************************/
4210  ni_aux_data_type_t type,
4211  const uint8_t *raw_data,
4212  int data_size)
4213 {
4214  ni_aux_data_t *ret = ni_frame_new_aux_data(frame, type, data_size);
4215  if (ret)
4216  {
4217  memcpy(ret->data, raw_data, data_size);
4218  }
4219  return ret;
4220 }
4221 
4222 /*!*****************************************************************************
4223  * \brief Retrieve from the frame auxiliary data of a given type if exists
4224  *
4225  * \param[in] frame a frame from which the auxiliary data should be retrieved
4226  * \param[in] type type of the auxiliary data to be retrieved
4227  *
4228  * \return a pointer to the aux data of a given type on success, NULL otherwise
4229  ******************************************************************************/
4231  ni_aux_data_type_t type)
4232 {
4233  int i;
4234  for (i = 0; i < frame->nb_aux_data; i++)
4235  {
4236  if (frame->aux_data[i]->type == type)
4237  {
4238  return frame->aux_data[i];
4239  }
4240  }
4241  return NULL;
4242 }
4243 
4244 /*!*****************************************************************************
4245  * \brief If auxiliary data of the given type exists in the frame, free it
4246  * and remove it from the frame.
4247  *
4248  * \param[in/out] frame a frame from which the auxiliary data should be removed
4249  * \param[in] type type of the auxiliary data to be removed
4250  *
4251  * \return None
4252  ******************************************************************************/
4254 {
4255  int i;
4256  ni_aux_data_t *aux;
4257 
4258  for (i = 0; i < frame->nb_aux_data; i++)
4259  {
4260  aux = frame->aux_data[i];
4261  if (aux->type == type)
4262  {
4263  frame->aux_data[i] = frame->aux_data[frame->nb_aux_data - 1];
4264  frame->aux_data[frame->nb_aux_data - 1] = NULL;
4265  frame->nb_aux_data--;
4266  free(aux->data);
4267  free(aux);
4268  }
4269  }
4270 }
4271 
4272 /*!*****************************************************************************
4273  * \brief Free and remove all auxiliary data from the frame.
4274  *
4275  * \param[in/out] frame a frame from which the auxiliary data should be removed
4276  *
4277  * \return None
4278  ******************************************************************************/
4280 {
4281  int i;
4282  ni_aux_data_t *aux;
4283 
4284  for (i = 0; i < frame->nb_aux_data; i++)
4285  {
4286  aux = frame->aux_data[i];
4287  free(aux->data);
4288  free(aux);
4289  }
4290  frame->nb_aux_data = 0;
4291 }
4292 
4293 /*!*****************************************************************************
4294  * \brief Initialize default encoder parameters
4295  *
4296  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4297  * to initialize to default parameters
4298  * \param[in] fps_num Frames per second
4299  * \param[in] fps_denom FPS denomination
4300  * \param[in] bit_rate bit rate
4301  * \param[in] width frame width
4302  * \param[in] height frame height
4303  * \param[in] codec_format codec from ni_codec_format_t
4304  *
4305  * \return On success
4306  * NI_RETCODE_SUCCESS
4307  * On failure
4308  * NI_RETCODE_FAILURE
4309  * NI_RETCODE_INVALID_PARAM
4310  ******************************************************************************/
4312  int fps_num, int fps_denom,
4313  long bit_rate, int width,
4314  int height,
4315  ni_codec_format_t codec_format)
4316 {
4317  ni_encoder_cfg_params_t *p_enc = NULL;
4318  int i = 0, j = 0;
4320 
4321  //Initialize p_param structure
4322  if (!p_param)
4323  {
4324  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
4325  __func__);
4326  retval = NI_RETCODE_INVALID_PARAM;
4327  LRETURN;
4328  }
4329 
4330  ni_log(NI_LOG_DEBUG, "%s()\n", __func__);
4331 
4332  //Initialize p_param structure
4333  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4334 
4335  p_enc = &p_param->cfg_enc_params;
4336 
4337  // Rev. B: unified for HEVC/H.264
4338  p_enc->profile = 0;
4339  p_enc->level_idc = 0;
4340  p_enc->high_tier = 0;
4341 
4342  if (QUADRA)
4344  else
4346 
4347  p_enc->use_recommend_enc_params = 0;
4348  p_enc->cu_size_mode = 7;
4349  p_enc->max_num_merge = 2;
4350  p_enc->enable_dynamic_8x8_merge = 1;
4351  p_enc->enable_dynamic_16x16_merge = 1;
4352  p_enc->enable_dynamic_32x32_merge = 1;
4353 
4354  p_enc->rc.trans_rate = 0;
4355 
4356  p_enc->rc.enable_rate_control = 0;
4357  if (QUADRA)
4358  p_enc->rc.enable_cu_level_rate_control = 0;
4359  else
4360  p_enc->rc.enable_cu_level_rate_control = 1;
4361  p_enc->rc.enable_hvs_qp = 0;
4362  p_enc->rc.enable_hvs_qp_scale = 1;
4363  p_enc->rc.hvs_qp_scale = 2;
4364  p_enc->rc.min_qp = 8;
4365  p_enc->rc.max_qp = 51;
4366  p_enc->rc.max_delta_qp = 10;
4367 
4368  // hrd is disabled if vbv_buffer_size=0, hrd is enabled if vbv_buffer_size is [10, 3000]
4369  p_enc->rc.vbv_buffer_size = -1;
4370  p_enc->rc.enable_filler = 0;
4371  p_enc->rc.enable_pic_skip = 0;
4372  p_enc->rc.vbv_max_rate = 0;
4373 
4374  p_enc->roi_enable = 0;
4375 
4377  // feature not supported on JPEG/AV1 - disable by default
4378  if (codec_format == NI_CODEC_FORMAT_JPEG ||
4379  codec_format == NI_CODEC_FORMAT_AV1)
4380  {
4382  }
4383 
4384  p_enc->long_term_ref_enable = 0;
4385  p_enc->long_term_ref_interval = 0;
4386  p_enc->long_term_ref_count = 2;
4387 
4388  p_enc->conf_win_top = 0;
4389  p_enc->conf_win_bottom = 0;
4390  p_enc->conf_win_left = 0;
4391  p_enc->conf_win_right = 0;
4392 
4393  p_enc->intra_period = 120;
4394  p_enc->rc.intra_qp = 22;
4395  p_enc->rc.intra_qp_delta = -2;
4396  if (QUADRA)
4397  p_enc->rc.enable_mb_level_rc = 0;
4398  else
4399  p_enc->rc.enable_mb_level_rc = 1;
4400 
4401  p_enc->decoding_refresh_type = 1;
4402 
4403  p_enc->slice_mode = 0;
4404  p_enc->slice_arg = 0;
4405 
4406  // Rev. B: H.264 only parameters.
4407  p_enc->enable_transform_8x8 = 1;
4408  p_enc->entropy_coding_mode = 1;
4409 
4410  p_enc->intra_mb_refresh_mode = 0;
4411  p_enc->intra_mb_refresh_arg = 0;
4412  p_enc->intra_reset_refresh = 0;
4413 
4415 #ifndef QUADRA
4416  if (!QUADRA)
4417  {
4418  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4419  {
4421  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4422  p_enc->custom_gop_params.pic_param[i].pic_qp = 0;
4423  p_enc->custom_gop_params.pic_param[i].num_ref_pic_L0 = 0;
4424  p_enc->custom_gop_params.pic_param[i].ref_poc_L0 = 0;
4425  p_enc->custom_gop_params.pic_param[i].ref_poc_L1 = 0;
4426  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4427  }
4428  }
4429  else // QUADRA
4430 #endif
4431  {
4432  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4433  {
4434  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4435  p_enc->custom_gop_params.pic_param[i].qp_offset = 0;
4437  (float)0.3; // QP Factor range is between 0.3 and 1, higher values mean lower quality and less bits
4438  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4441  for (j = 0; j < NI_MAX_REF_PIC; j++)
4442  {
4443  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic = 0;
4444  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic_used = -1;
4445  }
4446  }
4447  }
4448 
4449  p_param->source_width = width;
4450  p_param->source_height = height;
4451 
4452  p_param->fps_number = fps_num;
4453  p_param->fps_denominator = fps_denom;
4454 
4455  if (p_param->fps_number && p_param->fps_denominator)
4456  {
4457  p_enc->frame_rate = (int)(p_param->fps_number / p_param->fps_denominator);
4458  }
4459  else
4460  {
4461  p_enc->frame_rate = 30;
4462  }
4463 
4464  p_param->bitrate = (int)bit_rate;
4465  p_param->roi_demo_mode = 0;
4466  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4467  p_param->force_pic_qp_demo_mode = 0;
4468  p_param->force_frame_type = 0;
4469  p_param->hdrEnableVUI = 0;
4470  p_param->cacheRoi = 0;
4471  p_param->low_delay_mode = 0;
4472  p_param->padding = 1;
4473  p_param->generate_enc_hdrs = 0;
4474  p_param->use_low_delay_poc_type = 0;
4475  p_param->rootBufId = 0;
4476  p_param->staticMmapThreshold = 0;
4477  p_param->zerocopy_mode = 1;
4478  p_param->luma_linesize = 0;
4479  p_param->chroma_linesize = 0;
4480  p_param ->enableCpuAffinity = 0;
4481 
4483 
4484  p_param->dolby_vision_profile = 0;
4485 
4486  // encoder stream header VUI setting
4487  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4488  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4489  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4490  p_param->sar_num = 0; // default SAR numerator 0
4491  p_param->sar_denom = 1; // default SAR denominator 1
4492  p_param->video_full_range_flag = -1;
4493 
4494  p_param->enable2PassGop = 0;
4496  p_param->minFramesDelay = 0;
4497  p_param->interval_of_psnr = 1;
4498  for (i = 0; i < NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL; i++) {
4499  for (j = 0; j < NI_CUSTOMIZE_ROI_QP_NUM; j++) {
4500  // 127 is invalid for delta qp and absolute qp
4501  p_param->customize_roi_qp_map[i][j] = 127;
4502  }
4503  }
4504 
4505  //QUADRA
4506  p_enc->EnableAUD = 0;
4507  p_enc->lookAheadDepth = 0;
4508  p_enc->rdoLevel = (codec_format == NI_CODEC_FORMAT_JPEG) ? 0 : 1;
4509  p_enc->crf = -1;
4510  p_enc->HDR10MaxLight = 0;
4511  p_enc->HDR10AveLight = 0;
4512  p_enc->HDR10CLLEnable = 0;
4513  p_enc->EnableRdoQuant = -1;
4514  p_enc->ctbRcMode = 0;
4515  p_enc->gopSize = 0;
4516  p_enc->gopLowdelay = 0;
4517  p_enc->gdrDuration = 0;
4518  p_enc->hrdEnable = 0;
4519  p_enc->ltrRefInterval = 0;
4520  p_enc->ltrRefQpOffset = 0;
4521  p_enc->ltrFirstGap = 0;
4522  p_enc->ltrNextInterval = 1;
4523  p_enc->multicoreJointMode = 0;
4524  p_enc->qlevel = -1;
4525  p_enc->maxFrameSize = 0;
4526  p_enc->maxFrameSizeRatio = 0;
4527  p_enc->chromaQpOffset = 0;
4528  p_enc->tolCtbRcInter = (float)0.1;
4529  p_enc->tolCtbRcIntra = (float)0.1;
4530  p_enc->bitrateWindow = -255;
4531  p_enc->inLoopDSRatio = 1;
4532  p_enc->blockRCSize = 0;
4533  p_enc->rcQpDeltaRange = 10;
4534  p_enc->ctbRowQpStep = 0;
4535  p_enc->newRcEnable = -1;
4536  p_enc->colorDescPresent = 0;
4537  p_enc->colorPrimaries = 2;
4538  p_enc->colorTrc = 2;
4539  p_enc->colorSpace = 2;
4540  p_enc->aspectRatioWidth = 0;
4541  p_enc->aspectRatioHeight = 1;
4542  p_enc->videoFullRange = 0;
4544  p_enc->enable_ssim = 0;
4545  p_enc->HDR10Enable = 0;
4546  p_enc->HDR10dx0 = 0;
4547  p_enc->HDR10dy0 = 0;
4548  p_enc->HDR10dx1 = 0;
4549  p_enc->HDR10dy1 = 0;
4550  p_enc->HDR10dx2 = 0;
4551  p_enc->HDR10dy2 = 0;
4552  p_enc->HDR10wx = 0;
4553  p_enc->HDR10wy = 0;
4554  p_enc->HDR10maxluma = 0;
4555  p_enc->HDR10minluma = 0;
4556  p_enc->avcc_hvcc = 0;
4557  p_enc->av1_error_resilient_mode = 0;
4558  p_enc->temporal_layers_enable = 0;
4559  p_enc->crop_width = 0;
4560  p_enc->crop_height = 0;
4561  p_enc->hor_offset = 0;
4562  p_enc->ver_offset = 0;
4563  p_enc->crfMax = -1;
4564  p_enc->qcomp = (float)0.6;
4565  p_enc->noMbtree = 0;
4566  p_enc->noHWMultiPassSupport = 0;
4567  p_enc->cuTreeFactor = 5;
4568  p_enc->ipRatio = (float)1.4;
4569  p_enc->pbRatio = (float)1.3;
4570  p_enc->cplxDecay = (float)0.5;
4571  p_enc->pps_init_qp = -1;
4572  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)
4573  p_enc->pass1_qp = -1;
4574  p_enc->crfFloat = -1.0f;
4575  p_enc->hvsBaseMbComplexity = 15;
4576  p_enc->statistic_output_level = 0;
4577  p_enc->skip_frame_enable = 0;
4578  p_enc->max_consecutive_skip_num = 1;
4579  p_enc->skip_frame_interval = 0;
4580  p_enc->enableipRatio = 0;
4581  p_enc->enable_all_sei_passthru = 0;
4582  p_enc->iframe_size_ratio = 100;
4583  p_enc->crf_max_iframe_enable = 0;
4584  p_enc->vbv_min_rate = 0;
4585  p_enc->totalCuTreeDepth = 0;
4586  p_enc->adaptiveCuTree = 0;
4587  p_enc->preIntraHandling = 1;
4588  p_enc->baseLayerOnly = 0;
4589  p_enc->pastFrameMaxIntraRatio = 20;
4590  p_enc->linkFrameMaxIntraRatio = 40;
4591  p_enc->adaptiveLamdaMode = 0;
4592  p_enc->adaptiveCrfMode = 0;
4593 #ifdef XCODER_311
4594  p_enc->disable_adaptive_buffers = 1;
4595 #else
4596  p_enc->disable_adaptive_buffers = 0;
4597 #endif
4598  p_enc->disableBframeRdoq = 0;
4599  p_enc->forceBframeQpfactor = (float)-1.0;
4600  p_enc->tune_bframe_visual = 0;
4601  p_enc->enable_acq_limit = 0;
4602  p_enc->get_psnr_mode = 3;
4604  p_enc->motionConstrainedMode = 0;
4605  p_enc->still_image_detect_level = 0;
4606  p_enc->scene_change_detect_level = 0;
4607  p_enc->encMallocStrategy = 0;
4608  p_enc->enable_smooth_crf = 0;
4609  p_enc->enable_compensate_qp = 0;
4610  p_enc->spatial_layers = 1;
4611  p_enc->enable_timecode = 0;
4612  p_enc->spatial_layers_ref_base_layer = 0;
4613  p_enc->vbvBufferReencode = 0;
4614  p_enc->disableAv1TimingInfo = 0;
4615  p_enc->preset_index = NI_PRESETS_NONE;
4616  p_enc->preset_enabled = 0;
4617  p_enc->reset_dts_offset = 1;
4618  for (i = 0; i < NI_MAX_SPATIAL_LAYERS; i++)
4619  {
4620  p_enc->spatialLayerBitrate[i] = 0;
4621  p_enc->av1OpLevel[i] = 0;
4622  }
4623  p_enc->intraCompensateMode = 0;
4624 
4625  if (codec_format == NI_CODEC_FORMAT_AV1)
4626  {
4627  if (p_param->source_width < NI_PARAM_AV1_MIN_WIDTH)
4628  {
4630  LRETURN;
4631  }
4632  if (p_param->source_height < NI_PARAM_AV1_MIN_HEIGHT)
4633  {
4635  LRETURN;
4636  }
4637  if (p_param->source_width > NI_PARAM_AV1_MAX_WIDTH)
4638  {
4640  LRETURN;
4641  }
4642  if (p_param->source_height > NI_PARAM_AV1_MAX_HEIGHT)
4643  {
4645  LRETURN;
4646  }
4647  if (p_param->source_height * p_param->source_width >
4649  {
4651  LRETURN;
4652  }
4653  // AV1 8x8 alignment HW limitation is now worked around by FW cropping input resolution
4655  {
4656  ni_log(NI_LOG_ERROR, "AV1 Picture Width not aligned to %d - picture will be cropped\n",
4658  }
4660  {
4661  ni_log(NI_LOG_ERROR, "AV1 Picture Height not aligned to %d - picture will be cropped\n",
4663  }
4664  }
4665 
4666  if (codec_format == NI_CODEC_FORMAT_JPEG)
4667  {
4668  if (p_param->source_width < NI_MIN_WIDTH)
4669  {
4671  LRETURN;
4672  }
4673  if (p_param->source_height < NI_MIN_HEIGHT)
4674  {
4676  LRETURN;
4677  }
4678  }
4679 
4680  if (p_param->source_width > NI_PARAM_MAX_WIDTH)
4681  {
4683  LRETURN;
4684  }
4685  if (p_param->source_width < NI_PARAM_MIN_WIDTH)
4686  {
4688  LRETURN;
4689  }
4690 
4691  if (p_param->source_height > NI_PARAM_MAX_HEIGHT)
4692  {
4694  LRETURN;
4695  }
4696  if (p_param->source_height < NI_PARAM_MIN_HEIGHT)
4697  {
4699  LRETURN;
4700  }
4701  if (p_param->source_height*p_param->source_width > NI_MAX_RESOLUTION_AREA)
4702  {
4704  LRETURN;
4705  }
4706 
4707 END:
4708 
4709  return retval;
4710 }
4711 
4712 /*!*****************************************************************************
4713  * \brief Initialize default decoder parameters
4714  *
4715  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4716  * to initialize to default parameters
4717  * \param[in] fps_num Frames per second
4718  * \param[in] fps_denom FPS denomination
4719  * \param[in] bit_rate bit rate
4720  * \param[in] width frame width
4721  * \param[in] height frame height
4722  *
4723  * \return On success
4724  * NI_RETCODE_SUCCESS
4725  * On failure
4726  * NI_RETCODE_FAILURE
4727  * NI_RETCODE_INVALID_PARAM
4728  ******************************************************************************/
4730  int fps_num, int fps_denom,
4731  long bit_rate, int width,
4732  int height)
4733 {
4734  ni_decoder_input_params_t* p_dec = NULL;
4735  int i;
4737 
4738  //Initialize p_param structure
4739  if (!p_param)
4740  {
4741  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameter passed\n",
4742  __func__);
4743  retval = NI_RETCODE_INVALID_PARAM;
4744  LRETURN;
4745  }
4746 
4747  ni_log(NI_LOG_DEBUG, "%s\n", __func__);
4748 
4749  //Initialize p_param structure
4750  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4751 
4752  p_dec = &p_param->dec_input_params;
4753 
4754  p_param->source_width = width;
4755  p_param->source_height = height;
4756 
4757  if(fps_num <= 0 || fps_denom <= 0)
4758  {
4759  fps_num = 30;
4760  fps_denom = 1;
4761  ni_log(NI_LOG_INFO, "%s(): FPS is not set, setting the default FPS to 30\n", __func__);
4762  }
4763 
4764  p_param->fps_number = fps_num;
4765  p_param->fps_denominator = fps_denom;
4766 
4767  p_dec->hwframes = 0;
4768  p_dec->mcmode = 0;
4769  p_dec->nb_save_pkt = 0;
4770  p_dec->enable_out1 = 0;
4771  p_dec->enable_out2 = 0;
4772  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
4773  {
4774  p_dec->force_8_bit[i] = 0;
4775  p_dec->semi_planar[i] = 0;
4776  p_dec->crop_mode[i] = NI_DEC_CROP_MODE_AUTO;
4777  p_dec->crop_whxy[i][0] = width;
4778  p_dec->crop_whxy[i][1] = height;
4779  p_dec->crop_whxy[i][2] = 0;
4780  p_dec->crop_whxy[i][3] = 0;
4781  p_dec->scale_wh[i][0] = 0;
4782  p_dec->scale_wh[i][1] = 0;
4783  p_dec->scale_long_short_edge[i] = 0;
4784  p_dec->scale_resolution_ceil[i] = 2;
4785  p_dec->scale_round[i] = -1;
4786  }
4788  p_dec->decoder_low_delay = 0;
4789  p_dec->force_low_delay = false;
4790  p_dec->enable_low_delay_check = 0;
4791  p_dec->enable_user_data_sei_passthru = 0;
4792  p_dec->custom_sei_passthru = -1;
4795  p_dec->enable_advanced_ec = 1;
4797  p_dec->enable_ppu_scale_adapt = 0;
4798  p_dec->enable_ppu_scale_limit = 0;
4799  p_dec->max_extra_hwframe_cnt = 255; //uint8_max
4800  p_dec->pkt_pts_unchange = 0;
4801  p_dec->enable_all_sei_passthru = 0;
4802  p_dec->enable_follow_iframe = 0;
4804 #ifdef XCODER_311
4805  p_dec->disable_adaptive_buffers = 1;
4806  p_dec->min_packets_delay = true;
4807  p_dec->reduce_dpb_delay = 1;
4808 #else
4809  p_dec->disable_adaptive_buffers = 0;
4810  p_dec->min_packets_delay = false;
4811  p_dec->reduce_dpb_delay = 0;
4812 #endif
4813  p_dec->survive_stream_err = 0;
4814  p_dec->skip_extra_headers = 0;
4815 
4816  //-------init unused param start----------
4817 
4818  p_param->bitrate = (int)bit_rate;
4819  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4820  p_param->force_pic_qp_demo_mode = 0;
4821  p_param->force_frame_type = 0;
4822  p_param->hdrEnableVUI = 0;
4823  p_param->cacheRoi = 0;
4824  p_param->low_delay_mode = 0;
4825  p_param->padding = 1;
4826  p_param->generate_enc_hdrs = 0;
4827  p_param->use_low_delay_poc_type = 0;
4828  p_param->dolby_vision_profile = 0;
4829 
4830  // encoder stream header VUI setting
4831  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4832  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4833  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4834  p_param->sar_num = 0; // default SAR numerator 0
4835  p_param->sar_denom = 1; // default SAR denominator 1
4836  p_param->video_full_range_flag = -1;
4837 
4838  //-------init unused param done----------
4839 
4840 END:
4841 
4842  return retval;
4843 }
4844 
4845 // read demo reconfig data file and parse out reconfig key/values in the format:
4846 // key:val1,val2,val3,...val9 (max 9 values); only digit/:/,/newline is allowed
4847 ni_retcode_t ni_parse_reconf_file(const char *reconf_file,
4849 {
4850  char keyChar[10] = "";
4851  int key;
4852  char valChar[10] = "";
4853  int val;
4854  int valIdx = 1;
4855  int parseKey = 1;
4856  int idx = 0;
4857  int readc = EOF;
4858  FILE *reconf = NULL;
4859 
4860  if (!reconf_file)
4861  {
4862  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4863  __func__);
4864  return NI_RETCODE_INVALID_PARAM;
4865  }
4866 
4867  ni_fopen(&reconf, reconf_file, "r");
4868  if (!reconf)
4869  {
4870  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4871  NI_ERRNO, __func__, reconf_file);
4873  }
4875 
4876  while ((readc = fgetc(reconf)) != EOF)
4877  {
4878  //parse lines
4879  if (isdigit(readc))
4880  {
4881  if (parseKey)
4882  {
4883  ni_strncat(keyChar, 10, (const char *)(&readc), 1);
4884  }
4885  else
4886  {
4887  ni_strncat(valChar, 10, (const char *)(&readc), 1);
4888  }
4889  }
4890  else if (readc == ':')
4891  {
4892  parseKey = 0;
4893  key = atoi(keyChar);
4894  hash_map[idx][0] = key;
4895  }
4896  else if (readc == ',')
4897  {
4899  {
4901  "ERROR: Number of entries per line in reconfig file is greater then the "
4902  "limit of %d\n",
4904  retval = NI_RETCODE_INVALID_PARAM;
4905  break;
4906  }
4907  val = atoi(valChar);
4908  hash_map[idx][valIdx] = val;
4909  valIdx++;
4910  memset(valChar, 0, 10);
4911  }
4912  else if (readc == '\n')
4913  {
4915  {
4917  "ERROR: Number of lines in reconfig file is greater then the "
4918  "limit of %d\n",
4920  retval = NI_RETCODE_INVALID_PARAM;
4921  break;
4922  }
4923  parseKey = 1;
4924  val = atoi (valChar);
4925  hash_map[idx][valIdx] = val;
4926  valIdx = 1;
4927  memset(keyChar,0,10);
4928  memset(valChar,0,10);
4929  idx ++;
4930  }
4931  else
4932  {
4933  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4934  }
4935  }
4936 
4937  fclose(reconf);
4938 
4939  if (NI_RETCODE_SUCCESS == retval && parseKey != 1)
4940  {
4942  "ERROR %d: %s(): Incorrect format / "
4943  "incomplete Key/Value pair in reconfig_file: %s\n",
4944  NI_ERRNO, __func__, reconf_file);
4946  }
4947 
4948  return retval;
4949 }
4950 
4952  int8_t qp_map[][NI_CUSTOMIZE_ROI_QP_NUM])
4953 {
4954  char valChar[5] = "";
4955  int val;
4956  int negative = 0;
4957  int qpIdx = 0;
4958  int levelIdx = 0;
4959  int readc = EOF;
4960  FILE *reconf = NULL;
4961 
4962  if (!customize_file)
4963  {
4964  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4965  __func__);
4966  return NI_RETCODE_INVALID_PARAM;
4967  }
4968 
4969  ni_fopen(&reconf, customize_file, "r");
4970  if (!reconf)
4971  {
4972  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4973  NI_ERRNO, __func__, customize_file);
4975  }
4977 
4978  while ((readc = fgetc(reconf)) != EOF)
4979  {
4980  //parse lines
4981  if (isdigit(readc))
4982  {
4983  ni_strncat(valChar, 5, (const char *)(&readc), 1);
4984  }
4985  else if (readc == '-') {
4986  negative = 1;
4987  }
4988  else if (readc == ',')
4989  {
4990  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4991  {
4993  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4994  "Number of levelIdx %d greater then the limit of %d\n",
4996  retval = NI_RETCODE_INVALID_PARAM;
4997  break;
4998  }
4999  if (!negative) {
5000  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
5001  qp_map[levelIdx][qpIdx] = val;
5002  } else {
5003  val = clip3(0, 32, atoi(valChar));
5004  qp_map[levelIdx][qpIdx] = val * -1;
5005  }
5006  negative = 0;
5007  memset(valChar, 0, 5);
5008  qpIdx++;
5009  }
5010  else if (readc == '\n')
5011  {
5012  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
5013  {
5015  "ERROR: Number of qpIdx %d greater then the limit of %d or"
5016  "Number of levelIdx %d greater then the limit of %d\n",
5018  retval = NI_RETCODE_INVALID_PARAM;
5019  break;
5020  }
5021  if (!negative) {
5022  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
5023  qp_map[levelIdx][qpIdx] = val;
5024  } else {
5025  val = clip3(0, 32, atoi(valChar));
5026  qp_map[levelIdx][qpIdx] = val * -1;
5027  }
5028  negative = 0;
5029  memset(valChar, 0, 5);
5030  qpIdx = 0;
5031  levelIdx++;
5032  }
5033  else
5034  {
5035  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
5036  }
5037  }
5038  fclose(reconf);
5039 
5040  return retval;
5041 }
5042 
5043 
5044 #undef atoi
5045 #undef atof
5046 #define atoi(p_str) ni_atoi(p_str, &b_error)
5047 #define atof(p_str) ni_atof(p_str, &b_error)
5048 #define atobool(p_str) (ni_atobool(p_str, &b_error))
5049 /*!*****************************************************************************
5050 * \brief Set value referenced by name in decoder parameters structure
5051 *
5052 * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t (used
5053 * for decoder too for now ) to find and set a particular
5054 * parameter
5055 * \param[in] name String represented parameter name to search
5056 * \param[in] value Parameter value to set
5057 *
5058 * \return On success
5059 * NI_RETCODE_SUCCESS
5060 * On failure
5061 * NI_RETCODE_FAILURE
5062 * NI_RETCODE_INVALID_PARAM
5063 *******************************************************************************/
5065  const char *name, char *value)
5066 {
5067  bool b_error = false;
5068  bool bNameWasBool = false;
5069  bool bValueWasNull = !value;
5070  ni_decoder_input_params_t* p_dec = NULL;
5071  char nameBuf[64] = { 0 };
5072  const char delim[2] = ",";
5073  const char xdelim[2] = "x";
5074  char *chunk;//for parsing out multi param input
5075  int i, j, k;
5076 
5077  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
5078 
5079  if (!p_params)
5080  {
5081  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
5082  __func__);
5083  return NI_RETCODE_INVALID_PARAM;
5084  }
5085 
5086  if (!name)
5087  {
5088  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
5089  __func__);
5091  }
5092  p_dec = &p_params->dec_input_params;
5093 
5094  // skip -- prefix if provided
5095  if (name[0] == '-' && name[1] == '-')
5096  {
5097  name += 2;
5098  }
5099 
5100  // s/_/-/g
5101  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
5102  {
5103  char* c;
5104  ni_strcpy(nameBuf, sizeof(nameBuf), name);
5105  while ((c = strchr(nameBuf, '_')) != 0)
5106  {
5107  *c = '-';
5108  }
5109  name = nameBuf;
5110  }
5111 
5112  if (!value)
5113  {
5114  value = "true";
5115  }
5116  else if (value[0] == '=')
5117  {
5118  value++;
5119  }
5120 
5121 #if defined(_MSC_VER)
5122 #define OPT(STR) else if (!_stricmp(name, STR))
5123 #define OPT2(STR1, STR2) \
5124  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
5125 #else
5126 #define OPT(STR) else if (!strcasecmp(name, STR))
5127 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
5128 #endif
5129  if (0); // suppress cppcheck
5131  {
5132  if (!strncmp(value, "hw", sizeof("hw"))){
5133  p_dec->hwframes = 1;
5134  }
5135  else if (!strncmp(value, "sw", sizeof("sw"))) {
5136  p_dec->hwframes = 0;
5137  }
5138  else{
5139  ni_log(NI_LOG_ERROR, "ERROR: %s(): out can only be <hw,sw> got %s\n",
5140  __func__, value);
5142  }
5143  }
5145  {
5146  if (atoi(value) == 1)
5147  p_dec->enable_out1 = 1;
5148  }
5150  {
5151  if (atoi(value) == 1)
5152  p_dec->enable_out2 = 1;
5153  }
5155  {
5156  if (atoi(value) == 1)
5157  p_dec->force_8_bit[0] = 1;
5158  }
5160  {
5161  if (atoi(value) == 1)
5162  p_dec->force_8_bit[1] = 1;
5163  }
5165  {
5166  if (atoi(value) == 1)
5167  p_dec->force_8_bit[2] = 1;
5168  }
5170  {
5171  if (atoi(value) == 1 || atoi(value) == 2)
5172  p_dec->semi_planar[0] = atoi(value);
5173  }
5175  {
5176  if (atoi(value) == 1 || atoi(value) == 2)
5177  p_dec->semi_planar[1] = atoi(value);
5178  }
5180  {
5181  if (atoi(value) == 1 || atoi(value) == 2)
5182  p_dec->semi_planar[2] = atoi(value);
5183  }
5185  {
5186  if (!strncmp(value, "manual", sizeof("manual"))) {
5187  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_MANUAL;
5188  }
5189  else if (!strncmp(value, "auto", sizeof("auto"))) {
5190  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_AUTO;
5191  }
5192  else{
5194  "ERROR: %s():cropMode0 input can only be <manual,auto> got %s\n",
5195  __func__, value);
5197  }
5198  }
5200  {
5201  if (!strncmp(value, "manual", sizeof("manual"))) {
5202  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_MANUAL;
5203  }
5204  else if (!strncmp(value, "auto", sizeof("auto"))) {
5205  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_AUTO;
5206  }
5207  else {
5209  "ERROR: %s():cropMode1 input can only be <manual,auto> got %s\n",
5210  __func__, value);
5212  }
5213  }
5215  {
5216  if (!strncmp(value, "manual", sizeof("manual"))) {
5217  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_MANUAL;
5218  }
5219  else if (!strncmp(value, "auto", sizeof("auto"))) {
5220  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_AUTO;
5221  }
5222  else {
5224  "ERROR: %s():cropMode2 input can only be <manual,auto> got %s\n",
5225  __func__, value);
5227  }
5228  }
5230  {
5231  char *saveptr = NULL;
5232  chunk = ni_strtok(value, delim, &saveptr);
5233  for (i = 0; i < 4; i++)
5234  {
5235  if (chunk != NULL)
5236  {
5237  j = k = 0;
5238  while (chunk[j])
5239  {
5240  if (chunk[j] != '\"' && chunk[j] != '\'')
5241  {
5242  p_dec->cr_expr[0][i][k] = chunk[j];
5243  k++;
5244  }
5245  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5246  {
5248  }
5249  }
5250  chunk = ni_strtok(NULL, delim, &saveptr);
5251  }
5252  else if (i == 2 ) //default offsets to centered image if not specified, may need recalc
5253  {
5254  ni_strcpy(p_dec->cr_expr[0][i], sizeof(p_dec->cr_expr[0][i]), "in_w/2-out_w/2");
5255  }
5256  else if (i == 3)
5257  {
5258  ni_strcpy(p_dec->cr_expr[0][i], sizeof(p_dec->cr_expr[0][i]), "in_h/2-out_h/2");
5259  } else
5260  {
5262  }
5263  }
5264  }
5266  {
5267  char *saveptr = NULL;
5268  chunk = ni_strtok(value, delim, &saveptr);
5269  for (i = 0; i < 4; i++)
5270  {
5271  if (chunk != NULL)
5272  {
5273  j = k = 0;
5274  while (chunk[j])
5275  {
5276  if (chunk[j] != '\"' && chunk[j] != '\'')
5277  {
5278  p_dec->cr_expr[1][i][k] = chunk[j];
5279  k++;
5280  }
5281  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5282  {
5284  }
5285  }
5286  chunk = ni_strtok(NULL, delim, &saveptr);
5287  }
5288  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5289  {
5290  ni_strcpy(p_dec->cr_expr[1][i], sizeof(p_dec->cr_expr[1][i]), "in_w/2-out_w/2");
5291  }
5292  else if (i == 3)
5293  {
5294  ni_strcpy(p_dec->cr_expr[1][i], sizeof(p_dec->cr_expr[1][i]), "in_h/2-out_h/2");
5295  }
5296  else
5297  {
5299  }
5300  }
5301  }
5303  {
5304  char *saveptr = NULL;
5305  chunk = ni_strtok(value, delim, &saveptr);
5306  for (i = 0; i < 4; i++)
5307  {
5308  if (chunk != NULL)
5309  {
5310  j = k = 0;
5311  while (chunk[j])
5312  {
5313  if (chunk[j] != '\"' && chunk[j] != '\'')
5314  {
5315  p_dec->cr_expr[2][i][k] = chunk[j];
5316  k++;
5317  }
5318  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5319  {
5321  }
5322  }
5323  chunk = ni_strtok(NULL, delim, &saveptr);
5324  }
5325  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5326  {
5327  ni_strcpy(p_dec->cr_expr[2][i], sizeof(p_dec->cr_expr[2][i]), "in_w/2-out_w/2");
5328  }
5329  else if (i == 3)
5330  {
5331  ni_strcpy(p_dec->cr_expr[2][i], sizeof(p_dec->cr_expr[2][i]), "in_h/2-out_h/2");
5332  }
5333  else
5334  {
5336  }
5337  }
5338  }
5340  {
5341  chunk = value;
5342  i = 0; // 'x' character counter
5343  while (*chunk++) {
5344  if (*chunk == xdelim[0]) {
5345  i++;
5346  }
5347  }
5348  if (i != 1) {
5350  }
5351  chunk = NULL;
5352 
5353  char *saveptr = NULL;
5354  chunk = ni_strtok(value, xdelim, &saveptr);
5355  for (i = 0; i < 2; i++)
5356  {
5357  if (chunk != NULL)
5358  {
5359  j = k = 0;
5360  while (chunk[j])
5361  {
5362  if (chunk[j] != '\"' && chunk[j] != '\'')
5363  {
5364  p_dec->sc_expr[0][i][k] = chunk[j];
5365  k++;
5366  }
5367  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5368  {
5370  }
5371  }
5372  chunk = ni_strtok(NULL, xdelim, &saveptr);
5373  }
5374  else
5375  {
5377  }
5378  }
5379  }
5381  {
5382  chunk = value;
5383  i = 0; // 'x' character counter
5384  while (*chunk++) {
5385  if (*chunk == xdelim[0]) {
5386  i++;
5387  }
5388  }
5389  if (i != 1) {
5391  }
5392  chunk = NULL;
5393 
5394  char *saveptr = NULL;
5395  chunk = ni_strtok(value, xdelim, &saveptr);
5396  for (i = 0; i < 2; i++)
5397  {
5398  if (chunk != NULL)
5399  {
5400  j = k = 0;
5401  while (chunk[j])
5402  {
5403  if (chunk[j] != '\"' && chunk[j] != '\'')
5404  {
5405  p_dec->sc_expr[1][i][k] = chunk[j];
5406  k++;
5407  }
5408  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5409  {
5411  }
5412  }
5413  chunk = ni_strtok(NULL, xdelim, &saveptr);
5414  }
5415  else
5416  {
5418  }
5419  }
5420  }
5422  {
5423  chunk = value;
5424  i = 0; // 'x' character counter
5425  while (*chunk++) {
5426  if (*chunk == xdelim[0]) {
5427  i++;
5428  }
5429  }
5430  if (i != 1) {
5432  }
5433  chunk = NULL;
5434 
5435  char *saveptr = NULL;
5436  chunk = ni_strtok(value, xdelim, &saveptr);
5437  for (i = 0; i < 2; i++)
5438  {
5439  if (chunk != NULL)
5440  {
5441  j = k = 0;
5442  while (chunk[j])
5443  {
5444  if (chunk[j] != '\"' && chunk[j] != '\'')
5445  {
5446  p_dec->sc_expr[2][i][k] = chunk[j];
5447  k++;
5448  }
5449  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5450  {
5452  }
5453  }
5454  chunk = ni_strtok(NULL, xdelim, &saveptr);
5455  }
5456  else
5457  {
5459  }
5460  }
5461  }
5463  {
5464  if ((atoi(value) < 0) || (atoi(value) > 2))
5465  {
5467  }
5468  p_dec->scale_long_short_edge[0] = atoi(value);
5469  }
5471  {
5472  if ((atoi(value) < 0) || (atoi(value) > 2))
5473  {
5475  }
5476  p_dec->scale_long_short_edge[1] = atoi(value);
5477  }
5479  {
5480  if ((atoi(value) < 0) || (atoi(value) > 2))
5481  {
5483  }
5484  p_dec->scale_long_short_edge[2] = atoi(value);
5485  }
5487  {
5488  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5489  {
5490  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5491  "and must be even number and less than or equal to 128. Got: %s\n",
5492  __func__, NI_DEC_PARAM_SCALE_0_RES_CEIL, value);
5493 
5495  }
5496  p_dec->scale_resolution_ceil[0] = atoi(value);
5497  }
5499  {
5500  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5501  {
5502  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5503  "and must be even number and less than or equal to 128. Got: %s\n",
5504  __func__, NI_DEC_PARAM_SCALE_1_RES_CEIL, value);
5506  }
5507  p_dec->scale_resolution_ceil[1] = atoi(value);
5508  }
5510  {
5511  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5512  {
5513  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5514  "and must be even number and less than or equal to 128. Got: %s\n",
5515  __func__, NI_DEC_PARAM_SCALE_2_RES_CEIL, value);
5517  }
5518  p_dec->scale_resolution_ceil[2] = atoi(value);
5519  }
5521  {
5522  if (!strncmp(value, "up", sizeof("up"))){
5523  p_dec->scale_round[0] = 0;
5524  }
5525  else if (!strncmp(value, "down", sizeof("down"))) {
5526  p_dec->scale_round[0] = 1;
5527  }
5528  else{
5529  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5530  __func__, NI_DEC_PARAM_SCALE_0_ROUND, value);
5532  }
5533  }
5535  {
5536  if (!strncmp(value, "up", sizeof("up"))){
5537  p_dec->scale_round[1] = 0;
5538  }
5539  else if (!strncmp(value, "down", sizeof("down"))) {
5540  p_dec->scale_round[1] = 1;
5541  }
5542  else{
5543  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5544  __func__, NI_DEC_PARAM_SCALE_1_ROUND, value);
5546  }
5547  }
5549  {
5550  if (!strncmp(value, "up", sizeof("up"))){
5551  p_dec->scale_round[2] = 0;
5552  }
5553  else if (!strncmp(value, "down", sizeof("down"))) {
5554  p_dec->scale_round[2] = 1;
5555  }
5556  else{
5557  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5558  __func__, NI_DEC_PARAM_SCALE_2_ROUND, value);
5560  }
5561  }
5563  {
5564  if ((atoi(value) != 0) && (atoi(value) != 1))
5565  {
5567  }
5568  p_dec->mcmode = atoi(value);
5569  }
5571  {
5572  if (atoi(value) < 0)
5573  {
5575  }
5576  p_dec->nb_save_pkt = atoi(value);
5577  }
5579  {
5580  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
5581  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
5582  {
5584  }
5585  p_dec->keep_alive_timeout = atoi(value);
5586  }
5588  {
5589  if (atoi(value) < 0)
5590  {
5592  }
5593  p_dec->decoder_low_delay = atoi(value);
5594  }
5596  {
5597  if ((atoi(value) != 0) && (atoi(value) != 1))
5598  {
5600  }
5601  p_dec->force_low_delay = atoi(value);
5602  }
5604  {
5605  if (atoi(value) < 0)
5606  {
5608  }
5609  p_dec->enable_low_delay_check = atoi(value);
5610  }
5612  {
5613  if ((atoi(value) != 0) && (atoi(value) != 1))
5614  {
5616  }
5617  p_dec->min_packets_delay = atoi(value);
5618  }
5620  {
5621  if (atoi(value) != NI_ENABLE_USR_DATA_SEI_PASSTHRU &&
5623  {
5625  }
5626  p_dec->enable_user_data_sei_passthru = atoi(value);
5627  }
5629  {
5630  if (atoi(value) < NI_MIN_CUSTOM_SEI_PASSTHRU ||
5632  {
5634  }
5635  p_dec->custom_sei_passthru = atoi(value);
5636  }
5638  {
5639  if (atoi(value) < NI_INVALID_SVCT_DECODING_LAYER)
5640  {
5642  }
5643  p_dec->svct_decoding_layer = atoi(value);
5644  }
5646  {
5647  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
5648  atoi(value) <= NI_DDR_PRIORITY_NONE)
5649  {
5651  }
5652  p_params->ddr_priority_mode = atoi(value);
5653  }
5655  {
5656  if (strncmp(value, "tolerant", sizeof("tolerant")) == 0) {
5658  } else if (strncmp(value, "ignore", sizeof("ignore")) == 0) {
5659  p_dec->ec_policy = NI_EC_POLICY_IGNORE;
5660  } else if (strncmp(value, "skip", sizeof("skip")) == 0) {
5661  p_dec->ec_policy = NI_EC_POLICY_SKIP;
5662  } else if (strncmp(value, "best_effort", sizeof("best_effort")) == 0) {
5664  } else if (strncmp(value, "limited_error", sizeof("limited_error")) == 0) {
5666  } else if (strncmp(value, "best_effort_out_dc", sizeof("best_effort_out_dc")) == 0) {
5668  } else {
5670  }
5671  }
5673  {
5674  if (atoi(value) != 0 &&
5675  atoi(value) != 1 &&
5676  atoi(value) != 2)
5677  {
5679  }
5680  p_dec->enable_advanced_ec = atoi(value);
5681  }
5683  {
5684  if (atoi(value) < 0 || (atoi(value) > 100))
5685  {
5687  }
5688  p_dec->error_ratio_threshold = atoi(value);
5689  }
5691  {
5692  if (atoi(value) < 0 || (atoi(value) > 2))
5693  {
5695  }
5696  p_dec->enable_ppu_scale_adapt = atoi(value);
5697  }
5699  {
5700  if (atoi(value) < 0 || (atoi(value) > 1))
5701  {
5703  }
5704  p_dec->enable_ppu_scale_limit = atoi(value);
5705  }
5707  {
5708  if (atoi(value) < 0 || atoi(value) > 255)
5709  {
5711  }
5712  p_dec->max_extra_hwframe_cnt = atoi(value);
5713  }
5715  {
5716  if (atoi(value) < 0 || atoi(value) > 1)
5717  {
5719  }
5720  p_dec->skip_pts_guess = atoi(value);
5721  }
5723  {
5724  if (atoi(value) != 0 && atoi(value) != 1)
5725  {
5727  }
5728  p_dec->pkt_pts_unchange = atoi(value);
5729  }
5731  {
5732  if (atoi(value) < 0 ||
5733  atoi(value) > 1)
5734  {
5736  }
5737  p_dec->enable_all_sei_passthru = atoi(value);
5738  }
5740  {
5741  if (atoi(value) != 0 && atoi(value) != 1)
5742  {
5744  }
5745  p_dec->enable_follow_iframe = atoi(value);
5746  }
5748  {
5749  if (atoi(value) < 0 ||
5750  atoi(value) > 1)
5751  {
5753  }
5754  p_dec->disable_adaptive_buffers = atoi(value);
5755  }
5757  {
5758  if (atoi(value) < 0 || atoi(value) > 1)
5759  {
5761  }
5762  p_dec->survive_stream_err = atoi(value);
5763  }
5765  {
5766  if ((atoi(value) != 0) && (atoi(value) != 1))
5767  {
5769  }
5770  p_dec->reduce_dpb_delay = atoi(value);
5771  }
5773  {
5774  if ((atoi(value) != 0) && (atoi(value) != 1))
5775  {
5777  }
5778  p_dec->skip_extra_headers = atoi(value);
5779  }
5781  {
5782  if ((atoi(value) != 0) && (atoi(value) != 1))
5783  {
5785  }
5786  p_params->enableCpuAffinity = atoi(value);
5787  }
5788  else
5789  {
5791  }
5792 
5793 #undef OPT
5794 #undef atobool
5795 #undef atoi
5796 #undef atof
5797  b_error |= bValueWasNull && !bNameWasBool;
5798 
5799  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
5800 
5802 }
5803 
5804 #undef atoi
5805 #undef atof
5806 #define atoi(p_str) ni_atoi(p_str, &b_error)
5807 #define atof(p_str) ni_atof(p_str, &b_error)
5808 #define atobool(p_str) (ni_atobool(p_str, &b_error))
5809 
5810 /*!*****************************************************************************
5811  * \brief Set value referenced by name in encoder parameters structure
5812  *
5813  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
5814  * to find and set a particular parameter
5815  * \param[in] name String represented parameter name to search
5816  * \param[in] value Parameter value to set
5817 *
5818  * \return On success
5819  * NI_RETCODE_SUCCESS
5820  * On failure
5821  * NI_RETCODE_FAILURE
5822  * NI_RETCODE_INVALID_PARAM
5823  ******************************************************************************/
5825  const char *name, const char *value)
5826 {
5827  bool b_error = false;
5828  bool bNameWasBool = false;
5829  bool bValueWasNull = !value;
5830  ni_encoder_cfg_params_t *p_enc = NULL;
5831  char nameBuf[64] = { 0 };
5832  int i,j,k;
5833 
5834  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
5835 
5836  if (!p_params)
5837  {
5838  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
5839  __func__);
5840  return NI_RETCODE_INVALID_PARAM;
5841  }
5842 
5843  if ( !name )
5844  {
5845  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
5846  __func__);
5848  }
5849  p_enc = &p_params->cfg_enc_params;
5850  // skip -- prefix if provided
5851  if (name[0] == '-' && name[1] == '-')
5852  {
5853  name += 2;
5854  }
5855 
5856  // s/_/-/g
5857  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
5858  {
5859  char* c;
5860  ni_strcpy(nameBuf, sizeof(nameBuf), name);
5861  while ((c = strchr(nameBuf, '_')) != 0)
5862  {
5863  *c = '-';
5864  }
5865  name = nameBuf;
5866  }
5867 
5868  if (!value)
5869  {
5870  value = "true";
5871  }
5872  else if (value[0] == '=')
5873  {
5874  value++;
5875  }
5876 
5877 #if defined(_MSC_VER)
5878 #define OPT(STR) else if (!_stricmp(name, STR))
5879 #define OPT2(STR1, STR2) \
5880  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
5881 #else
5882 #define OPT(STR) else if (!strcasecmp(name, STR))
5883 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
5884 #endif
5885 #define COMPARE(STR1, STR2, STR3) \
5886  if ((atoi(STR1) > (STR2)) || (atoi(STR1) < (STR3))) \
5887  { \
5888  return NI_RETCODE_PARAM_ERROR_OOR; \
5889  }
5890  if (0); // suppress cppcheck
5892  {
5893  if (AV_CODEC_DEFAULT_BITRATE == p_params->bitrate)
5894  {
5895  if (atoi(value) > NI_MAX_BITRATE)
5896  {
5898  }
5899  if (atoi(value) < NI_MIN_BITRATE)
5900  {
5902  }
5903  p_params->bitrate = atoi(value);
5904  }
5905  }
5907  {
5908  p_params->reconf_demo_mode = atoi(value); // for encoder reconfiguration testing
5909  }
5911  {
5912  ni_retcode_t retval = ni_parse_reconf_file(value, p_params->reconf_hash);
5913  if (retval != NI_RETCODE_SUCCESS) // for encoder reconfiguration testing
5914  {
5915  return retval;
5916  }
5917  }
5919  {
5920  // for encoder reconfiguration testing
5921  p_params->roi_demo_mode = atoi(value);
5922  if ((p_params->roi_demo_mode < 0) || (p_params->roi_demo_mode > 2))
5923  {
5925  }
5926  }
5928  {
5929  if (0 > atoi(value))
5930  {
5932  }
5933  p_params->low_delay_mode = atoi(value);
5934  }
5936  {
5937  if (0 != atoi(value) && 1 != atoi(value))
5938  {
5940  }
5941  p_params->minFramesDelay = atoi(value);
5942  }
5944  {
5945  p_params->padding = atoi(value);
5946  }
5947 #ifndef DEPRECATION_AS_ERROR
5949  {
5950  if (0 != atoi(value) && 1 != atoi(value))
5951  {
5953  }
5954  p_params->generate_enc_hdrs = atoi(value);
5955  // genHdrs is deprecated in favour of libavcodec parameter -gen_global_headers
5957  }
5958 #endif
5960  {
5961  if (0 != atoi(value) && 1 != atoi(value))
5962  {
5964  }
5965  p_params->use_low_delay_poc_type = atoi(value);
5966  }
5968  {
5969  if (QUADRA)
5970  {
5972  }
5973  p_params->force_frame_type = atoi(value);
5974  }
5976  {
5977  p_enc->profile = atoi(value);
5978  }
5980  {
5984  if (atof(value) <= 10)
5985  {
5986  p_enc->level_idc = (int)(10 * atof(value) + .5);
5987  }
5988  else
5989  {
5990  p_enc->level_idc = atoi(value);
5991  }
5992  }
5994  {
5995  p_enc->high_tier = atobool(value);
5996  }
5998  {
5999  p_params->log = atoi(value);
6000  if (b_error)
6001  {
6002  b_error = false;
6003  p_params->log = ni_parse_name(value, g_xcoder_log_names, &b_error) - 1;
6004  }
6005  }
6007  {
6008  if ((atoi(value) > NI_MAX_GOP_PRESET_IDX) || (atoi(value) < NI_MIN_GOP_PRESET_IDX))
6009  {
6011  }
6012  p_enc->gop_preset_index = atoi(value);
6013  }
6015  {
6017  {
6019  }
6020 
6021  p_enc->use_recommend_enc_params = atoi(value);
6022  }
6024  {
6025  if (QUADRA)
6026  {
6028  }
6029  if (((atoi(value) > NI_MAX_CU_SIZE_MODE) || (atoi(value) < NI_MIN_CU_SIZE_MODE)) && (atoi(value) != NI_DEFAULT_CU_SIZE_MODE))
6030  {
6032  }
6033 
6034  p_enc->cu_size_mode = atoi(value);
6035  }
6037  {
6038  if (QUADRA)
6039  {
6041  }
6042  if ((atoi(value) > NI_MAX_MAX_NUM_MERGE) || (atoi(value) < NI_MIN_MAX_NUM_MERGE))
6043  {
6045  }
6046 
6047  p_enc->max_num_merge = atoi(value);
6048  }
6050  {
6051  if (QUADRA)
6052  {
6054  }
6055  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
6056  {
6058  }
6059 
6060  p_enc->enable_dynamic_8x8_merge = atoi(value);
6061  }
6063  {
6064  if (QUADRA)
6065  {
6067  }
6068  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
6069  {
6071  }
6072 
6073  p_enc->enable_dynamic_16x16_merge = atoi(value);
6074  }
6076  {
6077  if (QUADRA)
6078  {
6080  }
6081  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
6082  {
6084  }
6085 
6086  p_enc->enable_dynamic_32x32_merge = atoi(value);
6087  }
6089  {
6090  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6091  {
6093  }
6094 
6095  p_enc->rc.enable_rate_control = atoi(value);
6096  }
6098  {
6099  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6100  {
6102  }
6103 
6104  p_enc->rc.enable_cu_level_rate_control = atoi(value);
6105  }
6107  {
6108  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6109  {
6111  }
6112  p_enc->rc.enable_hvs_qp = atoi(value);
6113  }
6115  {
6116  if (QUADRA)
6117  {
6119  }
6120  p_enc->rc.enable_hvs_qp_scale = atoi(value);
6121  }
6123  {
6124  p_enc->rc.hvs_qp_scale = atoi(value);
6125  }
6127  {
6128  p_enc->rc.min_qp = atoi(value);
6129  }
6131  {
6132  p_enc->rc.max_qp = atoi(value);
6133  }
6135  {
6136  if (QUADRA)
6137  {
6139  }
6140  p_enc->rc.max_delta_qp = atoi(value);
6141  }
6142 #ifndef DEPRECATION_AS_ERROR
6144  {
6145  if ((atoi(value) > 51) || (atoi(value) < -1))
6146  {
6148  }
6149  p_enc->crf = atoi(value);
6150  }
6151 #endif
6153  {
6154  p_enc->rc.vbv_buffer_size = atoi(value);
6155  if (QUADRA)
6156  {
6157  // RcInitDelay is deprecated and replaced with vbvBufferSize. But still accept the value.
6159  }
6160  }
6162  {
6163  p_enc->rc.vbv_buffer_size = atoi(value);
6164  }
6166  {
6167  p_enc->rc.vbv_max_rate = atoi(value);
6168  }
6170  {
6171  p_enc->rc.enable_filler = atoi(value);
6172  if (QUADRA)
6173  {
6174  // cbr is deprecated and replaced with fillerEnable. But still accept the value.
6176  }
6177  }
6179  {
6180  p_enc->rc.enable_filler = atoi(value);
6181  }
6183  {
6184  if (0 != atoi(value) && 1 != atoi(value))
6185  {
6187  }
6188  // Currenly pic skip is supported for low delay gops only - pic skip issues tracked by QDFW-1785/1958
6189  p_enc->rc.enable_pic_skip = atoi(value);
6190  }
6191 #ifndef DEPRECATION_AS_ERROR
6193 #else
6195 #endif
6196  {
6197 #ifdef _MSC_VER
6198  if (!_strnicmp(value, "ratio", 5))
6199 #else
6200  if (!strncasecmp(value, "ratio", 5))
6201 #endif
6202  {
6203  char value_buf[32] = {0};
6204  for (i = 0; i < sizeof(value_buf); i++)
6205  {
6206  if (value[i+6] == ']')
6207  {
6208  break;
6209  }
6210  value_buf[i] = value[i+6];
6211  }
6212  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6213  {
6215  }
6216 
6217  p_enc->maxFrameSizeRatio = atoi(value_buf);
6218  }
6219  else
6220  {
6221  int size = atoi(value);
6222  if (size < NI_MIN_FRAME_SIZE)
6223  {
6225  }
6226  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6227  }
6228  }
6230  {
6231 #ifdef _MSC_VER
6232  if (!_strnicmp(value, "ratio", 5))
6233 #else
6234  if (!strncasecmp(value, "ratio", 5))
6235 #endif
6236  {
6237  char value_buf[32] = {0};
6238  for (i = 0; i < sizeof(value_buf); i++)
6239  {
6240  if (value[i+6] == ']')
6241  {
6242  break;
6243  }
6244  value_buf[i] = value[i+6];
6245  }
6246  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6247  {
6249  }
6250 
6251  p_enc->maxFrameSizeRatio = atoi(value_buf);
6252  }
6253  else
6254  {
6255  int size = atoi(value) / 8;
6256  if (size < NI_MIN_FRAME_SIZE)
6257  {
6259  }
6260  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6261  }
6262  }
6264  {
6265  if (0 != atoi(value) && 1 != atoi(value))
6266  {
6268  }
6269  p_enc->forced_header_enable = atoi(value);
6270  }
6272  {
6273  p_enc->roi_enable = atoi(value);
6274  }
6276  {
6277  p_enc->conf_win_top = atoi(value);
6278  }
6280  {
6281  p_enc->conf_win_bottom = atoi(value);
6282  }
6284  {
6285  p_enc->conf_win_left = atoi(value);
6286  }
6288  {
6289  p_enc->conf_win_right = atoi(value);
6290  }
6292  {
6293  p_enc->intra_period = atoi(value);
6294  //p_enc->bitrateWindow = p_enc->intra_period;
6295  }
6297  {
6298  if (atoi(value) > NI_MAX_BITRATE)
6299  {
6301  }
6302  if (atoi(value) < NI_MIN_BITRATE)
6303  {
6305  }
6306  p_enc->rc.trans_rate = atoi(value);
6307  }
6309  {
6310  if (atoi(value) <= 0 )
6311  {
6313  }
6314  p_params->fps_number = atoi(value);
6315  p_params->fps_denominator = 1;
6316  p_enc->frame_rate = p_params->fps_number;
6317  }
6319  {
6320  if (atoi(value) <= 0)
6321  {
6323  }
6324  p_params->fps_denominator = atoi(value);
6325  p_enc->frame_rate = (int)(p_params->fps_number / p_params->fps_denominator);
6326  }
6328  {
6329  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6330  {
6332  }
6333 
6334  p_enc->rc.intra_qp = atoi(value);
6335  }
6337  {
6338  if ((atoi(value) > NI_MAX_INTRA_QP_DELTA) ||
6339  (atoi(value) < NI_MIN_INTRA_QP_DELTA))
6340  {
6342  }
6343 
6344  p_enc->rc.intra_qp_delta = atoi(value);
6345  }
6347  {
6348  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6349  {
6351  }
6352  p_params->force_pic_qp_demo_mode = atoi(value);
6353  }
6355  {
6356  if (QUADRA)
6357  {
6359  }
6361  {
6363  }
6364  p_enc->decoding_refresh_type = atoi(value);
6365  }
6367  {
6368  if (0 != atoi(value) && 1 != atoi(value))
6369  {
6371  }
6372  p_enc->intra_reset_refresh = atoi(value);
6373  }
6374  // Rev. B: H.264 only parameters.
6376  {
6377  if (QUADRA)
6378  {
6380  }
6381  p_enc->enable_transform_8x8 = atoi(value);
6382  }
6384  {
6385  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6386  {
6388  }
6389  p_enc->slice_mode = atoi(value);
6390  }
6392  {
6393  p_enc->slice_arg = atoi(value);
6394  }
6396  {
6397  if (0 != atoi(value) && 1 != atoi(value))
6398  {
6400  }
6401  p_enc->entropy_coding_mode = atoi(value);
6402  }
6403 // Rev. B: shared between HEVC and H.264
6405  {
6406  p_enc->intra_mb_refresh_mode = atoi(value);
6407  }
6409  {
6410  p_enc->intra_mb_refresh_arg = atoi(value);
6411  }
6413  {
6414  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6415  {
6417  }
6418  p_enc->rc.enable_mb_level_rc = atoi(value);
6419  if (QUADRA)
6420  {
6421  // mbLevelRcEnable will be deprecated and cuLevelRCEnable should be used instead. But still accept the value.
6423  }
6424  }
6426  {
6427  if ((atoi(value) > 255) || (atoi(value) < 0))
6428  {
6430  }
6431  p_enc->preferred_transfer_characteristics = atoi(value);
6432  }
6434  {
6435  if (atoi(value) != 0 && atoi(value) != 5)
6436  {
6438  }
6439  p_params->dolby_vision_profile = atoi(value);
6440  }
6442  {
6443  if ((atoi(value) > 3) || (atoi(value) < 1))
6444  {
6446  }
6447  p_enc->rdoLevel = atoi(value);
6448  }
6450  {
6451  const char delim[2] = ",";
6452  char *chunk;
6453 #ifdef _MSC_VER
6454  char *v = _strdup(value);
6455 #else
6456  char *v = strdup(value);
6457 #endif
6458  char *saveptr = NULL;
6459  chunk = ni_strtok(v, delim, &saveptr);
6460  if (chunk != NULL)
6461  {
6462  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6463  {
6464  free(v);
6466  }
6467  p_enc->HDR10MaxLight = atoi(chunk);
6468  chunk = ni_strtok(NULL, delim, &saveptr);
6469  if (chunk != NULL)
6470  {
6471  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6472  {
6473  free(v);
6475  }
6476  p_enc->HDR10AveLight = atoi(chunk);
6477  p_enc->HDR10CLLEnable = 1; //Both param populated so enable
6478  free(v);
6479  }
6480  else
6481  {
6482  free(v);
6484  }
6485  }
6486  else
6487  {
6488  free(v);
6490  }
6491  }
6492 
6494  {
6495 #ifdef _MSC_VER
6496 #define STRDUP(value) _strdup(value);
6497 #else
6498 #define STRDUP(value) strdup(value);
6499 #endif
6500  const char G[2] = "G";
6501  const char B[2] = "B";
6502  const char R[2] = "R";
6503  const char W[2] = "W";
6504  const char L[2] = "L";
6505  const char P[2] = "P";
6506  const char parL[2] = "(";
6507  const char comma[2] = ",";
6508  const char parR[2] = ")";
6509  int synCheck_GBRWLPCP[8];
6510  int posCheck_GBRWL[5] = {0};
6511  char *chunk;//for parsing out more complex inputs
6512  char *subchunk;
6513  char *v = STRDUP(value);
6514  //basic check syntax correct
6515  for (i = 0; i<8; i++)
6516  {
6517  synCheck_GBRWLPCP[i] = 0;
6518  }
6519  chunk = v;
6520  i = 0; // character index
6521 
6522  //count keys and punctuation, save indicies to be parsed
6523  while (*chunk) {
6524  if (*chunk == G[0])
6525  {
6526  synCheck_GBRWLPCP[0]++;
6527  posCheck_GBRWL[0] = i;
6528  }
6529  else if (*chunk == B[0])
6530  {
6531  synCheck_GBRWLPCP[1]++;
6532  posCheck_GBRWL[1] = i;
6533  }
6534  else if (*chunk == R[0])
6535  {
6536  synCheck_GBRWLPCP[2]++;
6537  posCheck_GBRWL[2] = i;
6538  }
6539  else if (*chunk == W[0])
6540  {
6541  synCheck_GBRWLPCP[3]++;
6542  posCheck_GBRWL[3] = i;
6543  }
6544  else if (*chunk == L[0])
6545  {
6546  synCheck_GBRWLPCP[4]++;
6547  posCheck_GBRWL[4] = i;
6548  }
6549  else if (*chunk == parL[0])
6550  {
6551  synCheck_GBRWLPCP[5]++;
6552  }
6553  else if (*chunk == comma[0])
6554  {
6555  synCheck_GBRWLPCP[6]++;
6556  }
6557  else if (*chunk == parR[0])
6558  {
6559  synCheck_GBRWLPCP[7]++;
6560  }
6561  chunk++;
6562  i++;
6563  }
6564  free(v);
6565  if (synCheck_GBRWLPCP[0] != 1 || synCheck_GBRWLPCP[1] != 1 || synCheck_GBRWLPCP[2] != 1 ||
6566  synCheck_GBRWLPCP[3] != 1 || synCheck_GBRWLPCP[4] != 1 || synCheck_GBRWLPCP[5] != 5 ||
6567  synCheck_GBRWLPCP[6] != 5 || synCheck_GBRWLPCP[7] != 5)
6568  {
6570  }
6571 
6572  //Parse a key-value set like G(%hu, %hu)
6573 #define GBRWLPARSE(OUT1,OUT2,OFF,IDX) \
6574 { \
6575  char *v = STRDUP(value); \
6576  chunk = v + posCheck_GBRWL[IDX]; \
6577  i = j = k = 0; \
6578  while (chunk != NULL) \
6579  { \
6580  if (*chunk == parL[0] && i == 1+(OFF)) \
6581  { \
6582  j = 1; \
6583  } \
6584  if((OFF) == 1 && *chunk != P[0] && i == 1) \
6585  { \
6586  break; \
6587  } \
6588  if (*chunk == parR[0]) \
6589  { \
6590  k = 1; \
6591  break; \
6592  } \
6593  i++; \
6594  chunk++; \
6595  } \
6596  if (!j || !k) \
6597  { \
6598  free(v); \
6599  return NI_RETCODE_PARAM_INVALID_VALUE; \
6600  } \
6601  subchunk = malloc(i - 1 - (OFF)); \
6602  if (subchunk == NULL) \
6603  { \
6604  free(v); \
6605  return NI_RETCODE_ERROR_MEM_ALOC; \
6606  } \
6607  memcpy(subchunk, v + posCheck_GBRWL[IDX] + 2 + (OFF), i - 2 - (OFF)); \
6608  subchunk[i - 2 - (OFF)] = '\0'; \
6609  char *saveptr = NULL; \
6610  chunk = ni_strtok(subchunk, comma, &saveptr); \
6611  if (chunk != NULL) \
6612  { \
6613  if(atoi(chunk) < 0) \
6614  { \
6615  free(v); \
6616  if(subchunk != NULL){ \
6617  free(subchunk); \
6618  } \
6619  return NI_RETCODE_PARAM_INVALID_VALUE; \
6620  } \
6621  *(OUT1) = atoi(chunk); \
6622  } \
6623  chunk = ni_strtok(NULL, comma, &saveptr); \
6624  if (chunk != NULL) \
6625  { \
6626  if(atoi(chunk) < 0) \
6627  { \
6628  free(v); \
6629  if(subchunk != NULL){ \
6630  free(subchunk); \
6631  } \
6632  return NI_RETCODE_PARAM_INVALID_VALUE; \
6633  } \
6634  *(OUT2) = atoi(chunk); \
6635  } \
6636  free(subchunk); \
6637  free(v); \
6638 }
6639  GBRWLPARSE(&p_enc->HDR10dx0, &p_enc->HDR10dy0, 0, 0);
6640  GBRWLPARSE(&p_enc->HDR10dx1, &p_enc->HDR10dy1, 0, 1);
6641  GBRWLPARSE(&p_enc->HDR10dx2, &p_enc->HDR10dy2, 0, 2);
6642  GBRWLPARSE(&p_enc->HDR10wx, &p_enc->HDR10wy, 1, 3);
6643  GBRWLPARSE(&p_enc->HDR10maxluma, &p_enc->HDR10minluma, 0, 4);
6644  p_enc->HDR10Enable = 1;
6645  }
6647  {
6648  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
6649  {
6651  }
6652  p_enc->lookAheadDepth = atoi(value);
6653  }
6655  {
6656  if (atoi(value) != 0 && atoi(value) != 1)
6657  {
6659  }
6660  p_enc->hrdEnable = atoi(value);
6661  }
6663  {
6664  if ((atoi(value) != 0) && (atoi(value) != 1))
6665  {
6667  }
6668  p_enc->EnableAUD = atoi(value);
6669  }
6671  {
6672  if (atoi(value) != 0 && atoi(value) != 1)
6673  {
6675  }
6676  p_params->cacheRoi = atoi(value);
6677  }
6679  {
6680  if (atoi(value) != 0 && atoi(value) != 1)
6681  {
6683  }
6684  p_enc->long_term_ref_enable = atoi(value);
6685  }
6687  {
6688  p_enc->long_term_ref_interval = atoi(value);
6689  }
6691  {
6692  if (atoi(value) < 1 || atoi(value) > 2)
6693  {
6695  }
6696  p_enc->long_term_ref_count = atoi(value);
6697  }
6699  {
6700  if ((atoi(value) != 0) && (atoi(value) != 1))
6701  {
6703  }
6704  p_enc->EnableRdoQuant = atoi(value);
6705  }
6707  {
6708  if (QUADRA)
6709  {
6711  }
6712 
6713  if ((atoi(value) < 0) || (atoi(value) > 3))
6714  {
6716  }
6717  p_enc->ctbRcMode = atoi(value);
6718  }
6720  {
6721  if (QUADRA)
6722  {
6724  }
6725 
6726  p_enc->gopSize = atoi(value);
6727  }
6729  {
6730  if (QUADRA)
6731  {
6733  }
6734 
6735  if ((atoi(value) != 0) && (atoi(value) != 1))
6736  {
6738  }
6739  p_enc->gopLowdelay = atoi(value);
6740  }
6742  {
6743  if (QUADRA)
6744  {
6746  }
6747  p_enc->gdrDuration = atoi(value);
6748  }
6750  {
6751  p_enc->ltrRefInterval = atoi(value);
6752  }
6754  {
6755  p_enc->ltrRefQpOffset = atoi(value);
6756  }
6758  {
6759  p_enc->ltrFirstGap = atoi(value);
6760  }
6763  {
6764  if ((atoi(value) != 0) && (atoi(value) != 1))
6765  {
6767  }
6768  p_enc->multicoreJointMode = atoi(value);
6769  }
6771  {
6772  if ((atoi(value) < 0) || (atoi(value) > 9))
6773  {
6775  }
6776  p_enc->qlevel = atoi(value);
6777  }
6779  {
6780  if ((atoi(value) > 12) || (atoi(value) < -12))
6781  {
6783  }
6784  p_enc->chromaQpOffset = atoi(value);
6785  }
6786  OPT(NI_ENC_PARAM_TOL_RC_INTER) { p_enc->tolCtbRcInter = (float)atof(value); }
6787  OPT(NI_ENC_PARAM_TOL_RC_INTRA) { p_enc->tolCtbRcIntra = (float)atof(value); }
6789  {
6790  if ((atoi(value) > 300) || (atoi(value) < 1))
6791  {
6793  }
6794  p_enc->bitrateWindow = atoi(value);
6795  }
6797  {
6798  if ((atoi(value) > 2) || (atoi(value) < 0))
6799  {
6801  }
6802  p_enc->blockRCSize = atoi(value);
6803  }
6805  {
6806  if ((atoi(value) > 15) || (atoi(value) < 0))
6807  {
6809  }
6810  p_enc->rcQpDeltaRange = atoi(value);
6811  }
6813  {
6814  if ((atoi(value) > 500) || (atoi(value) < 0))
6815  {
6817  }
6818  p_enc->ctbRowQpStep = atoi(value);
6819  }
6821  {
6822  if ((atoi(value) > 1) || (atoi(value) < 0))
6823  {
6825  }
6826  p_enc->newRcEnable = atoi(value);
6827  }
6829  {
6830  if ((atoi(value) > 1) || (atoi(value) < 0))
6831  {
6833  }
6834  p_enc->inLoopDSRatio = atoi(value);
6835  }
6837  {
6838  COMPARE(value, 22, 0)
6839  p_params->color_primaries = p_enc->colorPrimaries = atoi(value);
6840  p_enc->colorDescPresent = 1;
6841  }
6843  {
6844  COMPARE(value, 18, 0)
6845  p_params->color_transfer_characteristic = p_enc->colorTrc = atoi(value);
6846  p_enc->colorDescPresent = 1;
6847  }
6849  {
6850  COMPARE(value, 14, 0)
6851  p_params->color_space = p_enc->colorSpace = atoi(value);
6852  p_enc->colorDescPresent = 1;
6853  }
6855  {
6856  p_params->sar_num = p_enc->aspectRatioWidth = atoi(value);
6857  }
6859  {
6860  p_params->sar_denom = p_enc->aspectRatioHeight = atoi(value);
6861  }
6863  {
6864  p_params->video_full_range_flag = p_enc->videoFullRange = atoi(value);
6865  }
6867  {
6868  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
6869  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
6870  {
6872  }
6873  p_enc->keep_alive_timeout = atoi(value);
6874  }
6876  {
6877  if (atoi(value) != 0 && atoi(value) != 1)
6878  {
6880  }
6881  p_params->enable_vfr = atoi(value);
6882  }
6884  {
6885  if (atoi(value) < 0 || atoi(value) > 3)
6886  {
6888  }
6889  p_enc->get_psnr_mode = atoi(value);
6890  }
6892  {
6893  if (atoi(value) < 1)
6894  {
6896  }
6897  p_params->interval_of_psnr = atoi(value);
6898  }
6900  {
6901  if (atoi(value) < 0 || atoi(value) > 1)
6902  {
6904  }
6905  p_enc->get_psnr_mode = atoi(value) + 3;
6906  }
6908  {
6909  if ((atoi(value) != 0) && (atoi(value) != 1))
6910  {
6912  }
6913  p_enc->enable_ssim = atoi(value);
6914  }
6916  {
6917  if ((atoi(value) != 0) && (atoi(value) != 1))
6918  {
6920  }
6921  p_enc->av1_error_resilient_mode = atoi(value);
6922  }
6924  {
6925  if ((atoi(value) != 0) && (atoi(value) != 1))
6926  {
6928  }
6929  p_params->staticMmapThreshold = atoi(value);
6930  }
6932  {
6933  p_enc->temporal_layers_enable = atoi(value);
6934  }
6936  {
6937  if ((atoi(value) != 0) && (atoi(value) != 1))
6938  {
6940  }
6941  p_params->enable_ai_enhance = atoi(value);
6942  }
6944  {
6945  if ((atoi(value) != 0) && (atoi(value) != 1))
6946  {
6948  }
6949  if(p_params->enable_ai_enhance)
6950  {
6951  ni_log(NI_LOG_ERROR, "Cannot set enableAIEnhance and enableHVSPlus at same time, just enableHVSPlus\n");
6952  }
6953  p_params->enable_ai_enhance = (atoi(value) == 1) ? 2 : 0;
6954  }
6956  {
6957  if ((atoi(value) != 0) && (atoi(value) != 1))
6958  {
6960  }
6961  p_params->enable2PassGop = atoi(value);
6962  }
6964  {
6965  if ((atoi(value) != 0) && (atoi(value) != 1) && (atoi(value) != -1))
6966  {
6968  }
6969  p_params->zerocopy_mode = atoi(value);
6970  }
6972  {
6973  if ((atoi(value) == 0) || (atoi(value) > 3))
6974  {
6976  }
6977  p_params->ai_enhance_level = atoi(value);
6978  }
6980  {
6981  if ((atoi(value) == 0) || (atoi(value) > 2))
6982  {
6984  }
6985  p_params->ai_enhance_level = atoi(value);
6986  }
6988  {
6989  if ((atoi(value) < NI_MIN_WIDTH) ||
6990  (atoi(value) > NI_PARAM_MAX_WIDTH))
6991  {
6993  }
6994  p_enc->crop_width = atoi(value);
6995  }
6997  {
6998  if ((atoi(value) < NI_MIN_HEIGHT) ||
6999  (atoi(value) > NI_PARAM_MAX_HEIGHT))
7000  {
7002  }
7003  p_enc->crop_height = atoi(value);
7004  }
7006  {
7007  if ((atoi(value) < 0) ||
7008  (atoi(value) > NI_PARAM_MAX_WIDTH))
7009  {
7011  }
7012  p_enc->hor_offset = atoi(value);
7013  }
7015  {
7016  if ((atoi(value) < 0) ||
7017  (atoi(value) > NI_PARAM_MAX_HEIGHT))
7018  {
7020  }
7021  p_enc->ver_offset = atoi(value);
7022  }
7024  {
7025  if ((atoi(value) > 51) || (atoi(value) < -1))
7026  {
7028  }
7029  p_enc->crfMax = atoi(value);
7030  }
7032  {
7033  if ((atof(value) > 1.0) || (atof(value) < 0.0))
7034  {
7036  }
7037  p_enc->qcomp = (float)atof(value);
7038  }
7040  {
7041  if ((atoi(value) != 0) && (atoi(value) != 1))
7042  {
7044  }
7045  p_enc->noMbtree = atoi(value);
7046  }
7048  {
7049  if ((atoi(value) != 0) && (atoi(value) != 1))
7050  {
7052  }
7053  p_enc->avcc_hvcc = atoi(value);
7054  }
7056  {
7057  if ((atoi(value) != 0) && (atoi(value) != 1))
7058  {
7060  }
7061  p_enc->noHWMultiPassSupport = atoi(value);
7062  }
7064  {
7065  if ((atoi(value) > 10) || (atoi(value) < 1))
7066  {
7068  }
7069  p_enc->cuTreeFactor = atoi(value);
7070  }
7072  {
7073  if ((atof(value) > 10.0) || (atof(value) < 0.01))
7074  {
7076  }
7077  p_enc->ipRatio = (float)atof(value);
7078  }
7080  {
7081  if ((atoi(value) != 0) && (atoi(value) != 1))
7082  {
7084  }
7085  p_enc->enableipRatio = atoi(value);
7086  }
7088  {
7089  if ((atof(value) > 10.0) || (atof(value) < 0.01))
7090  {
7092  }
7093  p_enc->pbRatio = (float)atof(value);
7094  }
7096  {
7097  if ((atof(value) > 1.0) || (atof(value) < 0.1))
7098  {
7100  }
7101  p_enc->cplxDecay = (float)atof(value);
7102  }
7104  {
7105  if ((atoi(value) > 51) || (atoi(value) < -1))
7106  {
7108  }
7109  p_enc->pps_init_qp = atoi(value);
7110  }
7112  {
7113  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
7114  atoi(value) <= NI_DDR_PRIORITY_NONE)
7115  {
7117  }
7118  p_params->ddr_priority_mode = atoi(value);
7119  }
7121  {
7122  if ((atoi(value) != 0) && (atoi(value) != 1))
7123  {
7125  }
7126  p_enc->bitrateMode = atoi(value);
7127  }
7129  {
7130  if ((atoi(value) > 51) || (atoi(value) < -1))
7131  {
7133  }
7134  p_enc->pass1_qp = atoi(value);
7135  }
7137  {
7138  if (((atof(value) < 0.0) && (atof(value) != -1.0)) ||
7139  (atof(value) > 51.00))
7140  {
7142  }
7143  p_enc->crfFloat = (float)atof(value);
7144  }
7146  {
7147  if ((atoi(value) < 0) || (atoi(value) > 31))
7148  {
7150  }
7151  p_enc->hvsBaseMbComplexity = atoi(value);
7152  }
7154  {
7155  if (atoi(value) != 0 && atoi(value) != 1 && atoi(value) != 6)
7156  {
7158  }
7159  p_enc->statistic_output_level = atoi(value);
7160  }
7162  {
7163  //Currently only support 6 stillImage detect level
7164  //0-3: no performance drop
7165  //4-6: performance drop
7166  if ((atoi(value) < 0 || atoi(value) > 6))
7167  {
7169  }
7170  p_enc->still_image_detect_level = atoi(value);
7171  }
7173  {
7174  //Currently only support 10 sceneChange detect level
7175  //1-5 : no performance drop
7176  //6-10: performance drop
7177  if ((atoi(value) < 0 || atoi(value) > 10))
7178  {
7180  }
7181  p_enc->scene_change_detect_level = atoi(value);
7182  }
7184  {
7185  if ((atoi(value) != 0) && (atoi(value) != 1))
7186  {
7188  }
7189  p_enc->enable_smooth_crf = atoi(value);
7190  }
7192  {
7193  if ((atoi(value) != 0) && (atoi(value) != 1))
7194  {
7196  }
7197  p_enc->enable_compensate_qp = atoi(value);
7198  }
7200  {
7201  if (atoi(value) < 0 || atoi(value) > 1)
7202  {
7204  }
7205  p_enc->skip_frame_enable = atoi(value);
7206  }
7208  {
7209  if (atoi(value) < 0)
7210  {
7212  }
7213  p_enc->max_consecutive_skip_num = atoi(value);
7214  }
7216  {
7217  if (atoi(value) < 0 || atoi(value) > 255)
7218  {
7220  }
7221  p_enc->skip_frame_interval = atoi(value);
7222  }
7224  {
7225  if (atoi(value) != 0 && atoi(value) != 1)
7226  {
7228  }
7229  p_enc->enable_all_sei_passthru = atoi(value);
7230  }
7232  {
7233  if (atoi(value) <= 0)
7234  {
7236  }
7237  p_enc->iframe_size_ratio = atoi(value);
7238  }
7240  {
7241  if ((atoi(value) < 0 || atoi(value) > 2) &&
7242  atoi(value) != 5 && atoi(value) != 6)
7243  {
7245  }
7246  p_enc->crf_max_iframe_enable = atoi(value);
7247  }
7249  {
7250  p_enc->vbv_min_rate = atoi(value);
7251  }
7253  {
7254  if (atoi(value) != 0 && atoi(value) != 1)
7255  {
7257  }
7258  p_enc->disable_adaptive_buffers = atoi(value);
7259  }
7261  {
7262  if ((atoi(value) != 0) && (atoi(value) != 1))
7263  {
7265  }
7266  p_enc->disableBframeRdoq = atoi(value);
7267  }
7269  {
7270  if ((atof(value) > 1.0) || (atof(value) < 0.0))
7271  {
7273  }
7274  p_enc->forceBframeQpfactor = (float)atof(value);
7275  }
7277  {
7278  if (atoi(value) < 0 || atoi(value) > 2)
7279  {
7281  }
7282  p_enc->tune_bframe_visual = atoi(value);
7283  }
7285  {
7286  if ((atoi(value) != 0) && (atoi(value) != 1))
7287  {
7289  }
7290  p_enc->enable_acq_limit = atoi(value);
7291  }
7293  {
7294  if (atoi(value) < NI_CUS_ROI_DISABLE || atoi(value) > NI_CUS_ROI_MERGE)
7295  {
7297  }
7298  p_enc->customize_roi_qp_level += atoi(value);
7299  }
7301  {
7303  if (retval != NI_RETCODE_SUCCESS)
7304  {
7305  return retval;
7306  }
7307  // indicate it need to upload roi qp map
7308  p_enc->customize_roi_qp_level += 64;
7309  }
7311  {
7312  if (atoi(value) < 0 || atoi(value) > 2)
7313  {
7315  }
7316  p_enc->motionConstrainedMode = atoi(value);
7317  }
7319  {
7322  {
7324  }
7325  p_enc->encMallocStrategy = atoi(value);
7326  }
7328  {
7329  if (atoi(value) < 1 || atoi(value) > 4)
7330  {
7332  }
7333  p_enc->spatial_layers = atoi(value);
7334  }
7336  {
7337  if (atoi(value) < 0 || atoi(value) > 1)
7338  {
7340  }
7341  p_enc->enable_timecode = atoi(value);
7342  }
7344  {
7345  if ((atoi(value) != 0) && (atoi(value) != 1))
7346  {
7348  }
7349  p_enc->spatial_layers_ref_base_layer = atoi(value);
7350  }
7352  {
7353  if ((atoi(value) != 0) && (atoi(value) != 1))
7354  {
7356  }
7357  p_enc->vbvBufferReencode = atoi(value);
7358  }
7360  {
7361  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
7362  {
7364  }
7365  p_enc->totalCuTreeDepth = atoi(value);
7366  }
7368  {
7369  if (atoi(value) != 0 && atoi(value) != 1)
7370  {
7372  }
7373  p_enc->adaptiveCuTree = atoi(value);
7374  }
7376  {
7377  if (atoi(value) != 0 && atoi(value) != 1)
7378  {
7380  }
7381  p_enc->preIntraHandling = atoi(value);
7382  }
7384  {
7385  if (atoi(value) != 0 && atoi(value) != 1)
7386  {
7388  }
7389  p_enc->baseLayerOnly = atoi(value);
7390  }
7392  {
7393  if (atoi(value) < 0 || atoi(value) > 100)
7394  {
7396  }
7397  p_enc->pastFrameMaxIntraRatio = atoi(value);
7398  }
7400  {
7401  if (atoi(value) < 0 || atoi(value) > 100)
7402  {
7404  }
7405  p_enc->linkFrameMaxIntraRatio = atoi(value);
7406  }
7408  {
7409  const char delim[2] = ",";
7410  char *chunk;
7411 #ifdef _MSC_VER
7412  char *v = _strdup(value);
7413 #else
7414  char *v = strdup(value);
7415 #endif
7416  char *saveptr = NULL;
7417  i = 0;
7418  chunk = ni_strtok(v, delim, &saveptr);
7419  while (chunk != NULL && i < NI_MAX_SPATIAL_LAYERS)
7420  {
7421  if ((atoi(chunk) > NI_MAX_BITRATE) || (atoi(chunk) < NI_MIN_BITRATE))
7422  {
7423  free(v);
7425  }
7426  p_enc->spatialLayerBitrate[i] = atoi(chunk);
7427  chunk = ni_strtok(NULL, delim, &saveptr);
7428  i++;
7429  }
7430  free(v);
7431  }
7433  {
7434  const char delim[2] = ",";
7435  char *chunk;
7436 #ifdef _MSC_VER
7437  char *v = _strdup(value);
7438 #else
7439  char *v = strdup(value);
7440 #endif
7441  char *saveptr = NULL;
7442  i = 0;
7443  chunk = ni_strtok(v, delim, &saveptr);
7444  while (chunk != NULL && i < NI_MAX_SPATIAL_LAYERS)
7445  {
7449  if (atof(chunk) <= 10)
7450  {
7451  p_enc->av1OpLevel[i] = (int)(10 * atof(chunk) + .5);
7452  }
7453  else
7454  {
7455  p_enc->av1OpLevel[i] = atoi(chunk);
7456  }
7457  chunk = ni_strtok(NULL, delim, &saveptr);
7458  i++;
7459  }
7460  free(v);
7461  }
7463  {
7464  if ((atoi(value) != 0) && (atoi(value) != 1))
7465  {
7467  }
7468  p_enc->disableAv1TimingInfo = atoi(value);
7469  }
7471  {
7472  if ((atoi(value) != 0) && (atoi(value) != 1))
7473  {
7475  }
7476  p_params->enableCpuAffinity = atoi(value);
7477  }
7479  {
7480  for (i = 0; i < NI_NUM_PRESETS_MAX; i++) {
7481  if (0 == strcmp(value, g_xcoder_preset_names[i])) {
7482  p_enc->preset_index = i;
7483  break;
7484  }
7485  else if(i == NI_NUM_PRESETS_MAX - 1) {
7487  }
7488  }
7489  }
7491  {
7492  if (atoi(value) < 0 || atoi(value) > 3)
7493  {
7495  }
7496  p_enc->adaptiveLamdaMode = atoi(value);
7497  }
7499  {
7500  if (atoi(value) < 0 || atoi(value) > 1)
7501  {
7503  }
7504  p_enc->adaptiveCrfMode = atoi(value);
7505  }
7507  {
7508  if (atoi(value) < 0 || atoi(value) > 3)
7509  {
7511  }
7512  p_enc->intraCompensateMode = atoi(value);
7513  }
7514  else { return NI_RETCODE_PARAM_INVALID_NAME; }
7515 
7516 #undef OPT
7517 #undef OPT2
7518 #undef atobool
7519 #undef atoi
7520 #undef atof
7521 
7522  b_error |= bValueWasNull && !bNameWasBool;
7523 
7524  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
7525 
7527 }
7528 
7529 #undef atoi
7530 #undef atof
7531 #define atoi(p_str) ni_atoi(p_str, &b_error)
7532 #define atof(p_str) ni_atof(p_str, &b_error)
7533 #define atobool(p_str) (ni_atobool(p_str, &b_error))
7534 
7535 /*!*****************************************************************************
7536  * \brief Set GOP parameter value referenced by name in encoder parameters
7537  * structure
7538  *
7539  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
7540  * to find and set a particular parameter
7541  * \param[in] name String represented parameter name to search
7542  * \param[in] value Parameter value to set
7543 *
7544  * \return On success
7545  * NI_RETCODE_SUCCESS
7546  * On failure
7547  * NI_RETCODE_FAILURE
7548  * NI_RETCODE_INVALID_PARAM
7549  ******************************************************************************/
7551  const char *name,
7552  const char *value)
7553 {
7554  bool b_error = false;
7555  bool bNameWasBool = false;
7556  bool bValueWasNull = !value;
7557  ni_encoder_cfg_params_t *p_enc = NULL;
7558  ni_custom_gop_params_t* p_gop = NULL;
7559  char nameBuf[64] = { 0 };
7560 
7561  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
7562 
7563  if (!p_params)
7564  {
7565  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
7566  __func__);
7567  return NI_RETCODE_INVALID_PARAM;
7568  }
7569 
7570  if ( !name )
7571  {
7572  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
7573  __func__);
7575  }
7576  p_enc = &p_params->cfg_enc_params;
7577  p_gop = &p_enc->custom_gop_params;
7578 
7579  // skip -- prefix if provided
7580  if (name[0] == '-' && name[1] == '-')
7581  {
7582  name += 2;
7583  }
7584 
7585  // s/_/-/g
7586  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
7587  {
7588  char* c;
7589  ni_strcpy(nameBuf, sizeof(nameBuf), name);
7590  while ((c = strchr(nameBuf, '_')) != 0)
7591  {
7592  *c = '-';
7593  }
7594  name = nameBuf;
7595  }
7596 
7597  if (!value)
7598  {
7599  value = "true";
7600  }
7601  else if (value[0] == '=')
7602  {
7603  value++;
7604  }
7605 
7606 #if defined(_MSC_VER)
7607 #define OPT(STR) else if (!_stricmp(name, STR))
7608 #else
7609 #define OPT(STR) else if (!strcasecmp(name, STR))
7610 #endif
7611  if (0); // suppress cppcheck
7613  {
7614  if (atoi(value) > NI_MAX_GOP_SIZE)
7615  {
7617  }
7618  if (atoi(value) < NI_MIN_GOP_SIZE)
7619  {
7621  }
7622  p_gop->custom_gop_size = atoi(value);
7623  }
7624 
7625 #ifndef QUADRA
7627  {
7628  p_gop->pic_param[0].pic_type = atoi(value);
7629  }
7631  {
7632  p_gop->pic_param[0].poc_offset = atoi(value);
7633  }
7634  OPT(NI_ENC_GOP_PARAMS_G0_PIC_QP)
7635  {
7636  p_gop->pic_param[0].pic_qp = atoi(value);
7637  }
7638  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC_L0)
7639  {
7640  p_gop->pic_param[0].num_ref_pic_L0 = atoi(value);
7641  }
7642  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L0)
7643  {
7644  p_gop->pic_param[0].ref_poc_L0 = atoi(value);
7645  }
7646  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L1)
7647  {
7648  p_gop->pic_param[0].ref_poc_L1 = atoi(value);
7649  }
7651  {
7652  p_gop->pic_param[0].temporal_id = atoi(value);
7653  }
7654 
7656  {
7657  p_gop->pic_param[1].pic_type = atoi(value);
7658  }
7660  {
7661  p_gop->pic_param[1].poc_offset = atoi(value);
7662  }
7663  OPT(NI_ENC_GOP_PARAMS_G1_PIC_QP)
7664  {
7665  p_gop->pic_param[1].pic_qp = atoi(value);
7666  }
7667  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC_L0)
7668  {
7669  p_gop->pic_param[1].num_ref_pic_L0 = atoi(value);
7670  }
7671  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L0)
7672  {
7673  p_gop->pic_param[1].ref_poc_L0 = atoi(value);
7674  }
7675  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L1)
7676  {
7677  p_gop->pic_param[1].ref_poc_L1 = atoi(value);
7678  }
7680  {
7681  p_gop->pic_param[1].temporal_id = atoi(value);
7682  }
7683 
7685  {
7686  p_gop->pic_param[2].pic_type = atoi(value);
7687  }
7689  {
7690  p_gop->pic_param[2].poc_offset = atoi(value);
7691  }
7692  OPT(NI_ENC_GOP_PARAMS_G2_PIC_QP)
7693  {
7694  p_gop->pic_param[2].pic_qp = atoi(value);
7695  }
7696  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC_L0)
7697  {
7698  p_gop->pic_param[2].num_ref_pic_L0 = atoi(value);
7699  }
7700  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L0)
7701  {
7702  p_gop->pic_param[2].ref_poc_L0 = atoi(value);
7703  }
7704  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L1)
7705  {
7706  p_gop->pic_param[2].ref_poc_L1 = atoi(value);
7707  }
7709  {
7710  p_gop->pic_param[2].temporal_id = atoi(value);
7711  }
7712 
7714  {
7715  p_gop->pic_param[3].pic_type = atoi(value);
7716  }
7718  {
7719  p_gop->pic_param[3].poc_offset = atoi(value);
7720  }
7721  OPT(NI_ENC_GOP_PARAMS_G3_PIC_QP)
7722  {
7723  p_gop->pic_param[3].pic_qp = atoi(value);
7724  }
7725  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC_L0)
7726  {
7727  p_gop->pic_param[3].num_ref_pic_L0 = atoi(value);
7728  }
7729  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L0)
7730  {
7731  p_gop->pic_param[3].ref_poc_L0 = atoi(value);
7732  }
7733  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L1)
7734  {
7735  p_gop->pic_param[3].ref_poc_L1 = atoi(value);
7736  }
7738  {
7739  p_gop->pic_param[3].temporal_id = atoi(value);
7740  }
7741 
7743  {
7744  p_gop->pic_param[4].pic_type = atoi(value);
7745  }
7747  {
7748  p_gop->pic_param[4].poc_offset = atoi(value);
7749  }
7750  OPT(NI_ENC_GOP_PARAMS_G4_PIC_QP)
7751  {
7752  p_gop->pic_param[4].pic_qp = atoi(value);
7753  }
7754  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC_L0)
7755  {
7756  p_gop->pic_param[4].num_ref_pic_L0 = atoi(value);
7757  }
7758  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L0)
7759  {
7760  p_gop->pic_param[4].ref_poc_L0 = atoi(value);
7761  }
7762  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L1)
7763  {
7764  p_gop->pic_param[4].ref_poc_L1 = atoi(value);
7765  }
7767  {
7768  p_gop->pic_param[4].temporal_id = atoi(value);
7769  }
7770 
7772  {
7773  p_gop->pic_param[5].pic_type = atoi(value);
7774  }
7776  {
7777  p_gop->pic_param[5].poc_offset = atoi(value);
7778  }
7779  OPT(NI_ENC_GOP_PARAMS_G5_PIC_QP)
7780  {
7781  p_gop->pic_param[5].pic_qp = atoi(value);
7782  }
7783  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC_L0)
7784  {
7785  p_gop->pic_param[5].num_ref_pic_L0 = atoi(value);
7786  }
7787  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L0)
7788  {
7789  p_gop->pic_param[5].ref_poc_L0 = atoi(value);
7790  }
7791  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L1)
7792  {
7793  p_gop->pic_param[5].ref_poc_L1 = atoi(value);
7794  }
7796  {
7797  p_gop->pic_param[5].temporal_id = atoi(value);
7798  }
7799 
7801  {
7802  p_gop->pic_param[6].pic_type = atoi(value);
7803  }
7805  {
7806  p_gop->pic_param[6].poc_offset = atoi(value);
7807  }
7808  OPT(NI_ENC_GOP_PARAMS_G6_PIC_QP)
7809  {
7810  p_gop->pic_param[6].pic_qp = atoi(value);
7811  }
7812  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC_L0)
7813  {
7814  p_gop->pic_param[6].num_ref_pic_L0 = atoi(value);
7815  }
7816  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L0)
7817  {
7818  p_gop->pic_param[6].ref_poc_L0 = atoi(value);
7819  }
7820  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L1)
7821  {
7822  p_gop->pic_param[6].ref_poc_L1 = atoi(value);
7823  }
7825  {
7826  p_gop->pic_param[6].temporal_id = atoi(value);
7827  }
7828 
7830  {
7831  p_gop->pic_param[7].pic_type = atoi(value);
7832  }
7834  {
7835  p_gop->pic_param[7].poc_offset = atoi(value);
7836  }
7837  OPT(NI_ENC_GOP_PARAMS_G7_PIC_QP)
7838  {
7839  p_gop->pic_param[7].pic_qp = atoi(value);
7840  }
7841  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC_L0)
7842  {
7843  p_gop->pic_param[7].num_ref_pic_L0 = atoi(value);
7844  }
7845  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L0)
7846  {
7847  p_gop->pic_param[7].ref_poc_L0 = atoi(value);
7848  }
7849  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L1)
7850  {
7851  p_gop->pic_param[7].ref_poc_L1 = atoi(value);
7852  }
7854  {
7855  p_gop->pic_param[7].temporal_id = atoi(value);
7856  }
7857  else
7858  {
7859  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
7861  }
7862 #else
7864  {
7865  p_gop->pic_param[0].poc_offset = atoi(value);
7866  }
7868  {
7869  p_gop->pic_param[0].qp_offset = atoi(value);
7870  }
7871  /*
7872  OPT(NI_ENC_GOP_PARAMS_G0_QP_FACTOR)
7873  {
7874  p_gop->pic_param[0].qp_factor = atof(value);
7875  }
7876  */
7878  {
7879  p_gop->pic_param[0].temporal_id = atoi(value);
7880  }
7882  {
7883  p_gop->pic_param[0].pic_type = atoi(value);
7884  }
7886  {
7887  p_gop->pic_param[0].num_ref_pics = atoi(value);
7888  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 num_ref_pics %d\n", __func__, p_gop->pic_param[0].num_ref_pics);
7889  }
7891  {
7892  p_gop->pic_param[0].rps[0].ref_pic = atoi(value);
7893  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 %d rps[0].ref_pic %d\n", __func__, p_gop->pic_param[0].rps[0].ref_pic);
7894  }
7896  {
7897  p_gop->pic_param[0].rps[0].ref_pic_used = atoi(value);
7898  //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);
7899  }
7901  {
7902  p_gop->pic_param[0].rps[1].ref_pic = atoi(value);
7903  }
7905  {
7906  p_gop->pic_param[0].rps[1].ref_pic_used = atoi(value);
7907  }
7909  {
7910  p_gop->pic_param[0].rps[2].ref_pic = atoi(value);
7911  }
7913  {
7914  p_gop->pic_param[0].rps[2].ref_pic_used = atoi(value);
7915  }
7917  {
7918  p_gop->pic_param[0].rps[3].ref_pic = atoi(value);
7919  }
7921  {
7922  p_gop->pic_param[0].rps[3].ref_pic_used = atoi(value);
7923  }
7924 
7926  {
7927  p_gop->pic_param[1].poc_offset = atoi(value);
7928  }
7930  {
7931  p_gop->pic_param[1].qp_offset = atoi(value);
7932  }
7933  /*
7934  OPT(NI_ENC_GOP_PARAMS_G1_QP_FACTOR)
7935  {
7936  p_gop->pic_param[1].qp_factor = atof(value);
7937  }
7938  */
7940  {
7941  p_gop->pic_param[1].temporal_id = atoi(value);
7942  }
7944  {
7945  p_gop->pic_param[1].pic_type = atoi(value);
7946  }
7948  {
7949  p_gop->pic_param[1].num_ref_pics = atoi(value);
7950  }
7952  {
7953  p_gop->pic_param[1].rps[0].ref_pic = atoi(value);
7954  }
7956  {
7957  p_gop->pic_param[1].rps[0].ref_pic_used = atoi(value);
7958  }
7960  {
7961  p_gop->pic_param[1].rps[1].ref_pic = atoi(value);
7962  }
7964  {
7965  p_gop->pic_param[1].rps[1].ref_pic_used = atoi(value);
7966  }
7968  {
7969  p_gop->pic_param[1].rps[2].ref_pic = atoi(value);
7970  }
7972  {
7973  p_gop->pic_param[1].rps[2].ref_pic_used = atoi(value);
7974  }
7976  {
7977  p_gop->pic_param[1].rps[3].ref_pic = atoi(value);
7978  }
7980  {
7981  p_gop->pic_param[1].rps[3].ref_pic_used = atoi(value);
7982  }
7983 
7985  {
7986  p_gop->pic_param[2].poc_offset = atoi(value);
7987  }
7989  {
7990  p_gop->pic_param[2].qp_offset = atoi(value);
7991  }
7992  /*
7993  OPT(NI_ENC_GOP_PARAMS_G2_QP_FACTOR)
7994  {
7995  p_gop->pic_param[2].qp_factor = atof(value);
7996  }
7997  */
7999  {
8000  p_gop->pic_param[2].temporal_id = atoi(value);
8001  }
8003  {
8004  p_gop->pic_param[2].pic_type = atoi(value);
8005  }
8007  {
8008  p_gop->pic_param[2].num_ref_pics = atoi(value);
8009  }
8011  {
8012  p_gop->pic_param[2].rps[0].ref_pic = atoi(value);
8013  }
8015  {
8016  p_gop->pic_param[2].rps[0].ref_pic_used = atoi(value);
8017  }
8019  {
8020  p_gop->pic_param[2].rps[1].ref_pic = atoi(value);
8021  }
8023  {
8024  p_gop->pic_param[2].rps[1].ref_pic_used = atoi(value);
8025  }
8027  {
8028  p_gop->pic_param[2].rps[2].ref_pic = atoi(value);
8029  }
8031  {
8032  p_gop->pic_param[2].rps[2].ref_pic_used = atoi(value);
8033  }
8035  {
8036  p_gop->pic_param[2].rps[3].ref_pic = atoi(value);
8037  }
8039  {
8040  p_gop->pic_param[2].rps[3].ref_pic_used = atoi(value);
8041  }
8042 
8044  {
8045  p_gop->pic_param[3].poc_offset = atoi(value);
8046  }
8048  {
8049  p_gop->pic_param[3].qp_offset = atoi(value);
8050  }
8051  /*
8052  OPT(NI_ENC_GOP_PARAMS_G3_QP_FACTOR)
8053  {
8054  p_gop->pic_param[3].qp_factor = atof(value);
8055  }
8056  */
8058  {
8059  p_gop->pic_param[3].temporal_id = atoi(value);
8060  }
8062  {
8063  p_gop->pic_param[3].pic_type = atoi(value);
8064  }
8066  {
8067  p_gop->pic_param[3].num_ref_pics = atoi(value);
8068  }
8070  {
8071  p_gop->pic_param[3].rps[0].ref_pic = atoi(value);
8072  }
8074  {
8075  p_gop->pic_param[3].rps[0].ref_pic_used = atoi(value);
8076  }
8078  {
8079  p_gop->pic_param[3].rps[1].ref_pic = atoi(value);
8080  }
8082  {
8083  p_gop->pic_param[3].rps[1].ref_pic_used = atoi(value);
8084  }
8086  {
8087  p_gop->pic_param[3].rps[2].ref_pic = atoi(value);
8088  }
8090  {
8091  p_gop->pic_param[3].rps[2].ref_pic_used = atoi(value);
8092  }
8094  {
8095  p_gop->pic_param[3].rps[3].ref_pic = atoi(value);
8096  }
8098  {
8099  p_gop->pic_param[3].rps[3].ref_pic_used = atoi(value);
8100  }
8101 
8103  {
8104  p_gop->pic_param[4].poc_offset = atoi(value);
8105  }
8107  {
8108  p_gop->pic_param[4].qp_offset = atoi(value);
8109  }
8110  /*
8111  OPT(NI_ENC_GOP_PARAMS_G4_QP_FACTOR)
8112  {
8113  p_gop->pic_param[4].qp_factor = atof(value);
8114  }
8115  */
8117  {
8118  p_gop->pic_param[4].temporal_id = atoi(value);
8119  }
8121  {
8122  p_gop->pic_param[4].pic_type = atoi(value);
8123  }
8125  {
8126  p_gop->pic_param[4].num_ref_pics = atoi(value);
8127  }
8129  {
8130  p_gop->pic_param[4].rps[0].ref_pic = atoi(value);
8131  }
8133  {
8134  p_gop->pic_param[4].rps[0].ref_pic_used = atoi(value);
8135  }
8137  {
8138  p_gop->pic_param[4].rps[1].ref_pic = atoi(value);
8139  }
8141  {
8142  p_gop->pic_param[4].rps[1].ref_pic_used = atoi(value);
8143  }
8145  {
8146  p_gop->pic_param[4].rps[2].ref_pic = atoi(value);
8147  }
8149  {
8150  p_gop->pic_param[4].rps[2].ref_pic_used = atoi(value);
8151  }
8153  {
8154  p_gop->pic_param[4].rps[3].ref_pic = atoi(value);
8155  }
8157  {
8158  p_gop->pic_param[4].rps[3].ref_pic_used = atoi(value);
8159  }
8160 
8162  {
8163  p_gop->pic_param[5].poc_offset = atoi(value);
8164  }
8166  {
8167  p_gop->pic_param[5].qp_offset = atoi(value);
8168  }
8169  /*
8170  OPT(NI_ENC_GOP_PARAMS_G5_QP_FACTOR)
8171  {
8172  p_gop->pic_param[5].qp_factor = atof(value);
8173  }
8174  */
8176  {
8177  p_gop->pic_param[5].temporal_id = atoi(value);
8178  }
8180  {
8181  p_gop->pic_param[5].pic_type = atoi(value);
8182  }
8184  {
8185  p_gop->pic_param[5].num_ref_pics = atoi(value);
8186  }
8188  {
8189  p_gop->pic_param[5].rps[0].ref_pic = atoi(value);
8190  }
8192  {
8193  p_gop->pic_param[5].rps[0].ref_pic_used = atoi(value);
8194  }
8196  {
8197  p_gop->pic_param[5].rps[1].ref_pic = atoi(value);
8198  }
8200  {
8201  p_gop->pic_param[5].rps[1].ref_pic_used = atoi(value);
8202  }
8204  {
8205  p_gop->pic_param[5].rps[2].ref_pic = atoi(value);
8206  }
8208  {
8209  p_gop->pic_param[5].rps[2].ref_pic_used = atoi(value);
8210  }
8212  {
8213  p_gop->pic_param[5].rps[3].ref_pic = atoi(value);
8214  }
8216  {
8217  p_gop->pic_param[5].rps[3].ref_pic_used = atoi(value);
8218  }
8219 
8221  {
8222  p_gop->pic_param[6].poc_offset = atoi(value);
8223  }
8225  {
8226  p_gop->pic_param[6].qp_offset = atoi(value);
8227  }
8228  /*
8229  OPT(NI_ENC_GOP_PARAMS_G6_QP_FACTOR)
8230  {
8231  p_gop->pic_param[6].qp_factor = atof(value);
8232  }
8233  */
8235  {
8236  p_gop->pic_param[6].temporal_id = atoi(value);
8237  }
8239  {
8240  p_gop->pic_param[6].pic_type = atoi(value);
8241  }
8243  {
8244  p_gop->pic_param[6].num_ref_pics = atoi(value);
8245  }
8247  {
8248  p_gop->pic_param[6].rps[0].ref_pic = atoi(value);
8249  }
8251  {
8252  p_gop->pic_param[6].rps[0].ref_pic_used = atoi(value);
8253  }
8255  {
8256  p_gop->pic_param[6].rps[1].ref_pic = atoi(value);
8257  }
8259  {
8260  p_gop->pic_param[6].rps[1].ref_pic_used = atoi(value);
8261  }
8263  {
8264  p_gop->pic_param[6].rps[2].ref_pic = atoi(value);
8265  }
8267  {
8268  p_gop->pic_param[6].rps[2].ref_pic_used = atoi(value);
8269  }
8271  {
8272  p_gop->pic_param[6].rps[3].ref_pic = atoi(value);
8273  }
8275  {
8276  p_gop->pic_param[6].rps[3].ref_pic_used = atoi(value);
8277  }
8278 
8280  {
8281  p_gop->pic_param[7].poc_offset = atoi(value);
8282  }
8284  {
8285  p_gop->pic_param[7].qp_offset = atoi(value);
8286  }
8287  /*
8288  OPT(NI_ENC_GOP_PARAMS_G7_QP_FACTOR)
8289  {
8290  p_gop->pic_param[7].qp_factor = atof(value);
8291  }
8292  */
8294  {
8295  p_gop->pic_param[7].temporal_id = atoi(value);
8296  }
8298  {
8299  p_gop->pic_param[7].pic_type = atoi(value);
8300  }
8302  {
8303  p_gop->pic_param[7].num_ref_pics = atoi(value);
8304  }
8306  {
8307  p_gop->pic_param[7].rps[0].ref_pic = atoi(value);
8308  }
8310  {
8311  p_gop->pic_param[7].rps[0].ref_pic_used = atoi(value);
8312  }
8314  {
8315  p_gop->pic_param[7].rps[1].ref_pic = atoi(value);
8316  }
8318  {
8319  p_gop->pic_param[7].rps[1].ref_pic_used = atoi(value);
8320  }
8322  {
8323  p_gop->pic_param[7].rps[2].ref_pic = atoi(value);
8324  }
8326  {
8327  p_gop->pic_param[7].rps[2].ref_pic_used = atoi(value);
8328  }
8330  {
8331  p_gop->pic_param[7].rps[3].ref_pic = atoi(value);
8332  }
8334  {
8335  p_gop->pic_param[7].rps[3].ref_pic_used = atoi(value);
8336  }
8337  else
8338  {
8339  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
8341  }
8342 #endif
8343 
8344 #undef OPT
8345 #undef OPT2
8346 #undef atobool
8347 #undef atoi
8348 #undef atof
8349 
8350  b_error |= bValueWasNull && !bNameWasBool;
8351 
8352  ni_log(NI_LOG_TRACE, "%s(): exit, b_error=%d\n", __func__, b_error);
8353 
8355 }
8356 
8357 /*!*****************************************************************************
8358 * \brief Copy existing decoding session params for hw frame usage
8359 *
8360 * \param[in] src_p_ctx Pointer to a caller allocated source session context
8361 * \param[in] dst_p_ctx Pointer to a caller allocated destination session
8362 * context
8363 * \return On success
8364 * NI_RETCODE_SUCCESS
8365 * On failure
8366 * NI_RETCODE_INVALID_PARAM
8367 ******************************************************************************/
8369 {
8370  return ni_decoder_session_copy_internal(src_p_ctx, dst_p_ctx);
8371 }
8372 
8373 /*!*****************************************************************************
8374 * \brief Read data from the device
8375 * If device_type is NI_DEVICE_TYPE_DECODER reads data hwdesc from
8376 * decoder
8377 * If device_type is NI_DEVICE_TYPE_SCALER reads data hwdesc from
8378 * scaler
8379 *
8380 * \param[in] p_ctx Pointer to a caller allocated
8381 * ni_session_context_t struct
8382 * \param[in] p_data Pointer to a caller allocated
8383 * ni_session_data_io_t struct which contains either a
8384 * ni_frame_t data frame or ni_packet_t data packet to
8385 * send
8386 * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER
8387 * If NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER is specified,
8388 * hw descriptor info will be stored in p_data ni_frame
8389 * \return On success
8390 * Total number of bytes read
8391 * On failure
8392 * NI_RETCODE_INVALID_PARAM
8393 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8394 * NI_RETCODE_ERROR_INVALID_SESSION
8395 ******************************************************************************/
8397 {
8398  ni_log2(p_ctx, NI_LOG_DEBUG, "%s start\n", __func__);
8400  if ((!p_ctx) || (!p_data))
8401  {
8402  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8403  __func__);
8404  return NI_RETCODE_INVALID_PARAM;
8405  }
8406 
8407  // Here check if keep alive thread is closed.
8408 #ifdef _WIN32
8409  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
8411 #else
8412  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
8414 #endif
8415  {
8416  ni_log2(p_ctx, NI_LOG_ERROR,
8417  "ERROR: %s() keep alive thread has been closed, "
8418  "hw:%d, session:%d\n",
8419  __func__, p_ctx->hw_id, p_ctx->session_id);
8421  }
8422 
8423  ni_pthread_mutex_lock(&p_ctx->mutex);
8424  // In close state, let the close process execute first.
8425  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
8426  {
8427  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
8428  ni_pthread_mutex_unlock(&p_ctx->mutex);
8429  ni_usleep(100);
8431  }
8433  ni_pthread_mutex_unlock(&p_ctx->mutex);
8434 
8435  switch (device_type)
8436  {
8438  {
8439  int seq_change_read_count = 0;
8440  p_data->data.frame.src_codec = p_ctx->codec_format;
8441  for (;;)
8442  {
8443  //retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
8444  retval = ni_decoder_session_read_desc(p_ctx, &(p_data->data.frame));
8445  // check resolution change only after initial setting obtained
8446  // p_data->data.frame.video_width is picture width and will be 32-align
8447  // adjusted to frame size; p_data->data.frame.video_height is the same as
8448  // frame size, then compare them to saved one for resolution checking
8449  //
8450  uint32_t aligned_width;
8451  if(QUADRA)
8452  {
8453  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
8454  }
8455  else
8456  {
8457  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
8458  }
8459 
8460  ni_log2(p_ctx, NI_LOG_DEBUG,
8461  "FNum %" PRIu64
8462  ", DFVWxDFVH %u x %u, AlWid %u, AVW x AVH %u x %u\n",
8463  p_ctx->frame_num, p_data->data.frame.video_width,
8464  p_data->data.frame.video_height, aligned_width,
8465  p_ctx->active_video_width, p_ctx->active_video_height);
8466 
8467  if (0 == retval && seq_change_read_count)
8468  {
8469  ni_log2(p_ctx, NI_LOG_DEBUG, "%s (decoder): seq change NO data, next time.\n",
8470  __func__);
8471  p_ctx->active_video_width = 0;
8472  p_ctx->active_video_height = 0;
8473  p_ctx->actual_video_width = 0;
8474  break;
8475  }
8476  else if (retval < 0)
8477  {
8478  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
8479  __func__, retval);
8480  break;
8481  }
8482  // aligned_width may equal to active_video_width if bit depth and width
8483  // are changed at the same time. So, check video_width != actual_video_width.
8484  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
8485  (p_data->data.frame.video_width &&
8486  p_data->data.frame.video_height &&
8487  (aligned_width != p_ctx->active_video_width ||
8488  p_data->data.frame.video_height != p_ctx->active_video_height))))
8489  {
8490  ni_log2(
8491  p_ctx, NI_LOG_DEBUG,
8492  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
8493  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
8494  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
8495  aligned_width, p_data->data.frame.video_height,
8496  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
8497  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
8498  // reset active video resolution to 0 so it can be queried in the re-read
8499  p_ctx->active_video_width = 0;
8500  p_ctx->active_video_height = 0;
8501  p_ctx->actual_video_width = 0;
8502  seq_change_read_count++;
8503  //break;
8504  }
8505  else
8506  {
8507  break;
8508  }
8509  }
8510  break;
8511  }
8513  {
8514  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Encoder has no hwdesc to read\n");
8515  return NI_RETCODE_INVALID_PARAM;
8516  }
8517 
8518  case NI_DEVICE_TYPE_SCALER:
8519  {
8520  retval = ni_scaler_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8521  break;
8522  }
8523 
8524  case NI_DEVICE_TYPE_AI:
8525  {
8526  retval = ni_ai_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8527  break;
8528  }
8529 
8530  default:
8531  {
8532  retval = NI_RETCODE_INVALID_PARAM;
8533  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
8534  __func__, device_type);
8535  break;
8536  }
8537  }
8538 
8539  ni_pthread_mutex_lock(&p_ctx->mutex);
8541  ni_pthread_mutex_unlock(&p_ctx->mutex);
8542 
8543  return retval;
8544 }
8545 
8546 /*!*****************************************************************************
8547 * \brief Reads YUV data from hw descriptor stored location on device
8548 *
8549 * \param[in] p_ctx Pointer to a caller allocated
8550 * ni_session_context_t struct
8551 * \param[in] p_data Pointer to a caller allocated
8552 * ni_session_data_io_t struct which contains either a
8553 * ni_frame_t data frame or ni_packet_t data packet to
8554 * send
8555 * \param[in] hwdesc HW descriptor to find frame in XCODER
8556 * \return On success
8557 * Total number of bytes read
8558 * On failure
8559 * NI_RETCODE_INVALID_PARAM
8560 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8561 * NI_RETCODE_ERROR_INVALID_SESSION
8562 *******************************************************************************/
8564 {
8566  if ((!hwdesc) || (!p_data))
8567  {
8568  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8569  __func__);
8570  return NI_RETCODE_INVALID_PARAM;
8571  }
8572 
8573  /* download by frameidx */
8574  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rd") >= 0))
8575  {
8576  if(hwdesc->ui16FrameIdx == 0)
8577  {
8578  ni_log(NI_LOG_ERROR, "%s(): Invaild frame index\n", __func__);
8579  return NI_RETCODE_INVALID_PARAM;
8580  }
8581  retval = ni_hwdownload_by_frame_idx(hwdesc, &(p_data->data.frame), p_ctx->is_auto_dl);
8582  } else {
8583  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
8584  {
8585  if (p_ctx->pext_mutex == &(p_ctx->mutex))
8586  {
8587  ni_log(NI_LOG_ERROR, "ERROR %s(): Invalid session\n",
8588  __func__);
8590  }
8591  }
8592 
8594  bool use_external_mutex = false;
8595  uint32_t orig_session_id = p_ctx->session_id;
8596  ni_device_handle_t orig_blk_io_handle = p_ctx->blk_io_handle;
8597  uint32_t orig_codec_format = p_ctx->codec_format;
8598  int orig_bit_depth_factor = p_ctx->bit_depth_factor;
8599  int orig_hw_action = p_ctx->hw_action;
8600 
8601  ni_pthread_mutex_t *p_ctx_mutex = &(p_ctx->mutex);
8602  if ((p_ctx_mutex != p_ctx->pext_mutex) ||
8605  "6r8") < 0)
8606  {
8607  use_external_mutex = true;
8608  p_ctx->session_id = hwdesc->ui16session_ID;
8609  p_ctx->blk_io_handle = (ni_device_handle_t)(int64_t)hwdesc->device_handle;
8610  p_ctx->codec_format = NI_CODEC_FORMAT_H264; //unused
8611  p_ctx->bit_depth_factor = (int)hwdesc->bit_depth;
8613  }
8614 
8616 
8617  retval = ni_hwdownload_session_read(p_ctx, &(p_data->data.frame), hwdesc); //cut me down as needed
8618 
8620  if (use_external_mutex)
8621  {
8622  p_ctx->session_id = orig_session_id;
8623  p_ctx->blk_io_handle = orig_blk_io_handle;
8624  p_ctx->codec_format = orig_codec_format;
8625  p_ctx->bit_depth_factor = orig_bit_depth_factor;
8626  p_ctx->hw_action = orig_hw_action;
8627  }
8629  }
8630 
8631  return retval;
8632 }
8633 
8634 /*!*****************************************************************************
8635 * \brief Query the session if a buffer is available
8636 *
8637 * \param[in] p_ctx Pointer to a caller allocated
8638 * ni_session_context_t struct
8639 * [in] device_type Quadra device type
8640 *
8641 * \return On success
8642 * NI_RETCODE_SUCCESS
8643 * On failure
8644 * NI_RETCODE_INVALID_PARAM
8645 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8646 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8647 * NI_RETCODE_ERROR_INVALID_SESSION
8648 *******************************************************************************/
8650  ni_device_type_t device_type)
8651 {
8653 
8654  if (!p_ctx)
8655  {
8656  ni_log(NI_LOG_ERROR, "ERROR: No session\n");
8657  return NI_RETCODE_INVALID_PARAM;
8658  }
8659 
8660  if (ni_cmp_fw_api_ver(
8661  (char *) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
8662  "6rt") < 0)
8663  {
8664  ni_log2(p_ctx, NI_LOG_DEBUG,
8665  "%s function not supported in FW API version < 6rt\n",
8666  __func__);
8668  }
8669 
8670  switch (device_type)
8671  {
8672  case NI_DEVICE_TYPE_UPLOAD:
8673  ni_pthread_mutex_lock(&p_ctx->mutex);
8675 
8677 
8679  ni_pthread_mutex_unlock(&p_ctx->mutex);
8680  break;
8681 
8682  case NI_DEVICE_TYPE_SCALER:
8683  ni_pthread_mutex_lock(&p_ctx->mutex);
8685 
8686  retval = ni_scaler_session_query_buffer_avail(p_ctx);
8687 
8689  ni_pthread_mutex_unlock(&p_ctx->mutex);
8690  break;
8691 
8692  default:
8693  break;
8694  }
8695 
8696  return retval;
8697 }
8698 
8699 /*!*****************************************************************************
8700 * \brief Sends raw YUV input to uploader instance and retrieves a HW descriptor
8701 * to represent it
8702 *
8703 * \param[in] p_ctx Pointer to a caller allocated
8704 * ni_session_context_t struct
8705 * \param[in] p_src_data Pointer to a caller allocated
8706 * ni_session_data_io_t struct which contains a
8707 * ni_frame_t data frame to send to uploader
8708 * \param[out] hwdesc HW descriptor to find frame in XCODER
8709 * \return On success
8710 * Total number of bytes read
8711 * On failure
8712 * NI_RETCODE_INVALID_PARAM
8713 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8714 * NI_RETCODE_ERROR_INVALID_SESSION
8715 *******************************************************************************/
8717 {
8719  if ((!hwdesc) || (!p_src_data))
8720  {
8721  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8722  __func__);
8723  return NI_RETCODE_INVALID_PARAM;
8724  }
8725  ni_pthread_mutex_lock(&p_ctx->mutex);
8727 
8728  retval = ni_hwupload_session_write(p_ctx, &p_src_data->data.frame, hwdesc);
8729 
8731  ni_pthread_mutex_unlock(&p_ctx->mutex);
8732 
8733  return retval;
8734 }
8735 
8736 /*!*****************************************************************************
8737 * \brief Allocate memory for the hwDescriptor buffer based on provided
8738 * parameters taking into account pic size and extra data.
8739 *
8740 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
8741 *
8742 * \param[in] video_width Width of the video frame
8743 * \param[in] video_height Height of the video frame
8744 * \param[in] extra_len Extra data size (incl. meta data)
8745 *
8746 * \return On success
8747 * NI_RETCODE_SUCCESS
8748 * On failure
8749 * NI_RETCODE_INVALID_PARAM
8750 * NI_RETCODE_ERROR_MEM_ALOC
8751 *****************************************************************************/
8753  int video_height, int extra_len)
8754 {
8755  void* p_buffer = NULL;
8756  int height_aligned = video_height;
8757  int retval = NI_RETCODE_SUCCESS;
8758 
8759  if (!p_frame)
8760  {
8761  ni_log(NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8762  __func__);
8763  return NI_RETCODE_INVALID_PARAM;
8764  }
8765 
8766  ni_log(NI_LOG_DEBUG, "%s: extra_len=%d\n", __func__, extra_len);
8767 
8768  int buffer_size = (int)sizeof(niFrameSurface1_t) + extra_len;
8769 
8770  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
8771 
8772  //Check if Need to free
8773  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
8774  {
8775  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
8776  __func__, p_frame->buffer_size);
8777  ni_frame_buffer_free(p_frame);
8778  }
8779 
8780  //Check if need to realocate
8781  if (p_frame->buffer_size != buffer_size)
8782  {
8783  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
8784  {
8785  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
8786  NI_ERRNO, __func__);
8787  retval = NI_RETCODE_ERROR_MEM_ALOC;
8788  LRETURN;
8789  }
8790 
8791  // init once after allocation
8792  memset(p_buffer, 0, buffer_size);
8793  p_frame->buffer_size = buffer_size;
8794  p_frame->p_buffer = p_buffer;
8795 
8796  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
8797  }
8798  else
8799  {
8800  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
8801  }
8802 
8803  p_frame->p_data[3] = p_frame->p_buffer;
8804  p_frame->p_data[0] = NULL;
8805  p_frame->p_data[1] = NULL;
8806  p_frame->p_data[2] = NULL;
8807 
8808  p_frame->data_len[0] = 0;//luma_size;
8809  p_frame->data_len[1] = 0;//chroma_b_size;
8810  p_frame->data_len[2] = 0;//chroma_r_size;
8811  p_frame->data_len[3] = sizeof(niFrameSurface1_t);
8812 
8813  p_frame->video_width = video_width;
8814  p_frame->video_height = height_aligned;
8815 
8816  ((niFrameSurface1_t*)p_frame->p_data[3])->device_handle = (int32_t)NI_INVALID_DEVICE_HANDLE;
8817 
8818  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
8819  p_frame->buffer_size);
8820 
8821 END:
8822 
8823  if (NI_RETCODE_SUCCESS != retval)
8824  {
8825  ni_aligned_free(p_buffer);
8826  }
8827 
8828  return retval;
8829 }
8830 
8831 /*!*****************************************************************************
8832 * \brief Recycle a frame buffer on card
8833 *
8834 * \param[in] surface Struct containing device and frame location to clear out
8835 * \param[in] device_handle handle to access device memory buffer is stored in
8836 *
8837 * \return On success NI_RETCODE_SUCCESS
8838 * On failure NI_RETCODE_INVALID_PARAM
8839 *******************************************************************************/
8841  int32_t device_handle)
8842 {
8844 
8845  if (surface)
8846  {
8847  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8849  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8850  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8851  device_handle);
8852  retval = ni_clear_instance_buf(surface);
8853  }
8854  else
8855  {
8856  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8857  }
8858 
8859  return retval;
8860 }
8861 
8862 /*!*****************************************************************************
8863 * \brief Recycle a frame buffer on card, only hwframe descriptor is needed
8864 *
8865 * \param[in] surface Struct containing device and frame location to clear out
8866 *
8867 * \return On success NI_RETCODE_SUCCESS
8868 * On failure NI_RETCODE_INVALID_PARAM
8869 *******************************************************************************/
8871 {
8873  int32_t saved_dma_buf_fd;
8874  if (surface)
8875  {
8876  if(surface->ui16FrameIdx == 0)
8877  {
8878  ni_log(NI_LOG_DEBUG, "%s(): Invaild frame index\n", __func__);
8879  return retval;
8880  }
8881  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8883  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8884  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8885  surface->device_handle);
8886  retval = ni_clear_instance_buf(surface);
8887  saved_dma_buf_fd = surface->dma_buf_fd;
8888  memset(surface, 0, sizeof(niFrameSurface1_t));
8889  surface->dma_buf_fd = saved_dma_buf_fd;
8890  }
8891  else
8892  {
8893  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8894  retval = NI_RETCODE_INVALID_PARAM;
8895  }
8896 
8897  return retval;
8898 }
8899 
8900 /*!*****************************************************************************
8901 * \brief Sends frame pool setup info to device
8902 *
8903 * \param[in] p_ctx Pointer to a caller allocated
8904 * ni_session_context_t struct
8905 * \param[in] pool_size Upload session initial allocated frames count
8906 * must be > 0,
8907 * \param[in] pool 0 use the normal pool
8908 * 1 use a dedicated P2P pool
8909 *
8910 * \return On success Return code
8911 * On failure
8912 * NI_RETCODE_INVALID_PARAM
8913 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8914 * NI_RETCODE_ERROR_INVALID_SESSION
8915 * NI_RETCODE_ERROR_MEM_ALOC
8916 *******************************************************************************/
8918  uint32_t pool_size, uint32_t pool)
8919 {
8921  if (!p_ctx)
8922  {
8923  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8924  __func__);
8925  return NI_RETCODE_INVALID_PARAM;
8926  }
8927  if (pool_size == 0 || pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8928  {
8929  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Invalid poolsize == 0 or > 100\n");
8930  return NI_RETCODE_INVALID_PARAM;
8931  }
8932  if (pool & NI_UPLOADER_FLAG_LM)
8933  {
8934  ni_log2(p_ctx, NI_LOG_DEBUG, "uploader buffer acquisition is limited!\n");
8935  }
8936  ni_pthread_mutex_lock(&p_ctx->mutex);
8938 
8939  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, pool);
8940 
8942  ni_pthread_mutex_unlock(&p_ctx->mutex);
8943 
8944  return retval;
8945 }
8946 
8947 /*!*****************************************************************************
8948 * \brief Sends frame pool change info to device
8949 *
8950 * \param[in] p_ctx Pointer to a caller allocated
8951 * ni_session_context_t struct
8952 * \param[in] pool_size if pool_size = 0, free allocated device memory buffers
8953 * if pool_size > 0, expand device frame buffer pool of
8954 * current instance with pool_size more frame buffers
8955 *
8956 * \return On success Return code
8957 * On failure
8958 * NI_RETCODE_FAILURE
8959 * NI_RETCODE_INVALID_PARAM
8960 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8961 * NI_RETCODE_ERROR_INVALID_SESSION
8962 * NI_RETCODE_ERROR_MEM_ALOC
8963 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8964 *******************************************************************************/
8966  uint32_t pool_size)
8967 {
8969  if (!p_ctx)
8970  {
8971  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8972  __func__);
8973  return NI_RETCODE_INVALID_PARAM;
8974  }
8975  if (ni_cmp_fw_api_ver(
8977  "6r3") < 0)
8978  {
8979  ni_log2(p_ctx, NI_LOG_ERROR,
8980  "ERROR: %s function not supported in FW API version < 6r3\n",
8981  __func__);
8983  }
8984  if (p_ctx->pool_type == NI_POOL_TYPE_NONE)
8985  {
8986  ni_log2(p_ctx, NI_LOG_ERROR,
8987  "ERROR: can't free or expand framepool of session 0x%x "
8988  "before init framepool\n", p_ctx->session_id);
8989  return NI_RETCODE_FAILURE;
8990  }
8991  if (pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8992  {
8993  ni_log2(p_ctx, NI_LOG_ERROR,
8994  "ERROR: Invalid poolsize > %u\n", NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL);
8995  return NI_RETCODE_INVALID_PARAM;
8996  }
8997  if (pool_size == 0)
8998  {
8999  ni_log2(p_ctx, NI_LOG_INFO, "Free frame pool of session 0x%x\n", p_ctx->session_id);
9000  }
9001 
9002  ni_pthread_mutex_lock(&p_ctx->mutex);
9004 
9005  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, p_ctx->pool_type);
9006 
9008  ni_pthread_mutex_unlock(&p_ctx->mutex);
9009 
9010  return retval;
9011 }
9012 
9013 /*!*****************************************************************************
9014  * \brief Set parameters on the device for the 2D engine
9015  *
9016  * \param[in] p_ctx pointer to session context
9017  * \param[in] p_params pointer to scaler parameters
9018  *
9019  * \return NI_RETCODE_INVALID_PARAM
9020  * NI_RETCODE_ERROR_INVALID_SESSION
9021  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9022  * NI_RETCODE_ERROR_MEM_ALOC
9023  ******************************************************************************/
9025  ni_scaler_params_t *p_params)
9026 {
9028 
9029  if (!p_ctx || !p_params)
9030  {
9031  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9032  __func__);
9033  return NI_RETCODE_INVALID_PARAM;
9034  }
9035  ni_pthread_mutex_lock(&p_ctx->mutex);
9037 
9038  retval = ni_config_instance_set_scaler_params(p_ctx, p_params);
9039 
9041  ni_pthread_mutex_unlock(&p_ctx->mutex);
9042 
9043  return retval;
9044 }
9045 
9046 /*!******************************************************************************
9047  * \brief Send a p_config command to configure scaling drawbox parameters.
9048  *
9049  * \param ni_session_context_t p_ctx - xcoder Context
9050  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_drawbox params_t struct
9051  *
9052  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
9053 *******************************************************************************/
9055  ni_scaler_drawbox_params_t *p_params)
9056 {
9057  void *p_scaler_config = NULL;
9058  uint32_t buffer_size = sizeof(ni_scaler_multi_drawbox_params_t);
9060  uint32_t ui32LBA = 0;
9061 
9062  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
9063 
9064  if (!p_ctx || !p_params)
9065  {
9066  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
9067  retval = NI_RETCODE_INVALID_PARAM;
9068  LRETURN;
9069  }
9070 
9071  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
9072  {
9073  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
9075  LRETURN;
9076  }
9077 
9078  buffer_size =
9079  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
9081  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
9082  {
9083  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
9084  NI_ERRNO, __func__);
9085  retval = NI_RETCODE_ERROR_MEM_ALOC;
9086  LRETURN;
9087  }
9088  memset(p_scaler_config, 0, buffer_size);
9089 
9090  //configure the session here
9093 
9094  memcpy(p_scaler_config, p_params, buffer_size);
9095 
9097  p_scaler_config, buffer_size, ui32LBA) < 0)
9098  {
9099  ni_log2(p_ctx, NI_LOG_ERROR,
9100  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
9101  ", hw_id, %d, xcoder_inst_id: %d\n",
9102  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
9103  // Close the session since we can't configure it as per fw
9104  retval = ni_scaler_session_close(p_ctx, 0);
9105  if (NI_RETCODE_SUCCESS != retval)
9106  {
9107  ni_log2(p_ctx, NI_LOG_ERROR,
9108  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
9109  "hw_id, %d, xcoder_inst_id: %d\n",
9110  __func__,
9111  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
9112  p_ctx->session_id);
9113  }
9114 
9116  }
9117 
9118 END:
9119 
9120  ni_aligned_free(p_scaler_config);
9121  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
9122 
9123  return retval;
9124 }
9125 
9126 /*!******************************************************************************
9127  * \brief Send a p_config command to configure scaling watermark parameters.
9128  *
9129  * \param ni_session_context_t p_ctx - xcoder Context
9130  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_watermark_params_t struct
9131  *
9132  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
9133 *******************************************************************************/
9135  ni_scaler_watermark_params_t *p_params)
9136 {
9137  void *p_scaler_config = NULL;
9138  uint32_t buffer_size = sizeof(ni_scaler_multi_watermark_params_t);
9140  uint32_t ui32LBA = 0;
9141 
9142  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
9143 
9144  if (!p_ctx || !p_params)
9145  {
9146  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
9147  retval = NI_RETCODE_INVALID_PARAM;
9148  LRETURN;
9149  }
9150 
9151  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
9152  {
9153  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
9155  LRETURN;
9156  }
9157 
9158  buffer_size =
9159  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
9161  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
9162  {
9163  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
9164  NI_ERRNO, __func__);
9165  retval = NI_RETCODE_ERROR_MEM_ALOC;
9166  LRETURN;
9167  }
9168  memset(p_scaler_config, 0, buffer_size);
9169 
9170  //configure the session here
9173 
9174  memcpy(p_scaler_config, p_params, buffer_size);
9175 
9177  p_scaler_config, buffer_size, ui32LBA) < 0)
9178  {
9179  ni_log2(p_ctx, NI_LOG_ERROR,
9180  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
9181  ", hw_id, %d, xcoder_inst_id: %d\n",
9182  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
9183  // Close the session since we can't configure it as per fw
9184  retval = ni_scaler_session_close(p_ctx, 0);
9185  if (NI_RETCODE_SUCCESS != retval)
9186  {
9187  ni_log2(p_ctx, NI_LOG_ERROR,
9188  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
9189  "hw_id, %d, xcoder_inst_id: %d\n",
9190  __func__,
9191  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
9192  p_ctx->session_id);
9193  }
9194 
9196  }
9197 
9198 END:
9199 
9200  ni_aligned_free(p_scaler_config);
9201  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
9202 
9203  return retval;
9204 }
9205 
9206 
9207 /*!*****************************************************************************
9208  * \brief Allocate a frame on the device for 2D engine or AI engine
9209  * to work on based on provided parameters
9210  *
9211  * \param[in] p_ctx pointer to session context
9212  * \param[in] width width, in pixels
9213  * \param[in] height height, in pixels
9214  * \param[in] format pixel format
9215  * \param[in] options options bitmap flags, bit 0 (NI_SCALER_FLAG_IO) is
9216  * 0=input frame or 1=output frame. Bit 1 (NI_SCALER_FLAG_PC) is
9217  * 0=single allocation, 1=create pool. Bit 2 (NI_SCALER_FLAG_PA) is
9218  * 0=straight alpha, 1=premultiplied alpha
9219  * \param[in] rectangle_width clipping rectangle width
9220  * \param[in] rectangle_height clipping rectangle height
9221  * \param[in] rectangle_x horizontal position of clipping rectangle
9222  * \param[in] rectangle_y vertical position of clipping rectangle
9223  * \param[in] rgba_color RGBA fill colour (for padding only)
9224  * \param[in] frame_index input hwdesc index
9225  * \param[in] device_type only NI_DEVICE_TYPE_SCALER
9226  * and NI_DEVICE_TYPE_AI (only needs p_ctx and frame_index)
9227  *
9228  * \return NI_RETCODE_INVALID_PARAM
9229  * NI_RETCODE_ERROR_INVALID_SESSION
9230  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9231  * NI_RETCODE_ERROR_MEM_ALOC
9232  ******************************************************************************/
9234  int width,
9235  int height,
9236  int format,
9237  int options,
9238  int rectangle_width,
9239  int rectangle_height,
9240  int rectangle_x,
9241  int rectangle_y,
9242  int rgba_color,
9243  int frame_index,
9244  ni_device_type_t device_type)
9245 {
9247 
9248  if (!p_ctx)
9249  {
9250  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9251  __func__);
9252  return NI_RETCODE_INVALID_PARAM;
9253  }
9254  ni_pthread_mutex_lock(&p_ctx->mutex);
9256 
9257  switch (device_type)
9258  {
9259  case NI_DEVICE_TYPE_SCALER:
9260  retval = ni_scaler_alloc_frame(p_ctx,width, height, format, options,
9261  rectangle_width, rectangle_height,
9262  rectangle_x, rectangle_y,
9263  rgba_color, frame_index);
9264  break;
9265 
9266  case NI_DEVICE_TYPE_AI:
9267  retval = ni_ai_alloc_hwframe(p_ctx, width, height, options, rgba_color,
9268  frame_index);
9269  break;
9270 
9273  /* fall through */
9274 
9275  default:
9276  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
9277  retval = NI_RETCODE_INVALID_PARAM;
9278  break;
9279  }
9280 
9282  ni_pthread_mutex_unlock(&p_ctx->mutex);
9283 
9284  return retval;
9285 }
9286 
9287 /*!*****************************************************************************
9288  * \brief Allocate a frame on the device and return the frame index
9289  *
9290  * \param[in] p_ctx pointer to session context
9291  * \param[in] p_out_surface pointer to output frame surface
9292  * \param[in] device_type currently only NI_DEVICE_TYPE_AI
9293  *
9294  * \return NI_RETCODE_INVALID_PARAM
9295  * NI_RETCODE_ERROR_INVALID_SESSION
9296  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
9297  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9298  * NI_RETCODE_ERROR_MEM_ALOC
9299  ******************************************************************************/
9301  niFrameSurface1_t *p_out_surface,
9302  ni_device_type_t device_type)
9303 {
9305 
9306  if (!p_ctx)
9307  {
9308  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, %p, return\n",
9309  __func__, p_ctx);
9310  return NI_RETCODE_INVALID_PARAM;
9311  }
9312  ni_pthread_mutex_lock(&p_ctx->mutex);
9314 
9315  switch (device_type)
9316  {
9317  case NI_DEVICE_TYPE_AI:
9318  retval = ni_ai_alloc_dst_frame(p_ctx, p_out_surface);
9319  break;
9320 
9321  case NI_DEVICE_TYPE_SCALER:
9324  /* fall through */
9325 
9326  default:
9327  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
9328  retval = NI_RETCODE_INVALID_PARAM;
9329  break;
9330  }
9331 
9333  ni_pthread_mutex_unlock(&p_ctx->mutex);
9334 
9335  return retval;
9336 }
9337 
9338 /*!*****************************************************************************
9339  * \brief Copy the data of src hwframe to dst hwframe
9340  *
9341  * \param[in] p_ctx pointer to session context
9342  * \param[in] p_frameclone_desc pointer to the frameclone descriptor
9343  *
9344  * \return NI_RETCODE_INVALID_PARAM
9345  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
9346  * NI_RETCODE_ERROR_INVALID_SESSION
9347  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9348  * NI_RETCODE_ERROR_MEM_ALOC
9349  ******************************************************************************/
9351  ni_frameclone_desc_t *p_frameclone_desc)
9352 {
9354 
9355  if (!p_ctx)
9356  {
9357  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9358  __func__);
9359  return NI_RETCODE_INVALID_PARAM;
9360  }
9361 
9362  if (ni_cmp_fw_api_ver(
9364  "6rL") < 0)
9365  {
9366  ni_log2(p_ctx, NI_LOG_ERROR,
9367  "Error: %s function not supported on device with FW API version < 6rL\n",
9368  __func__);
9370  }
9371 
9372  ni_pthread_mutex_lock(&p_ctx->mutex);
9374  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
9375  {
9376  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n",
9377  __func__);
9379  LRETURN;
9380  }
9381 
9382  retval = ni_hwframe_clone(p_ctx, p_frameclone_desc);
9383 
9384 END:
9386  ni_pthread_mutex_unlock(&p_ctx->mutex);
9387 
9388  return retval;
9389 }
9390 
9391 /*!*****************************************************************************
9392  * \brief Configure the 2D engine to work based on provided parameters
9393  *
9394  * \param[in] p_ctx pointer to session context
9395  * \param[in] p_cfg pointer to frame configuration
9396  *
9397  * \return NI_RETCODE_INVALID_PARAM
9398  * NI_RETCODE_ERROR_INVALID_SESSION
9399  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9400  * NI_RETCODE_ERROR_MEM_ALOC
9401  ******************************************************************************/
9403  ni_frame_config_t *p_cfg)
9404 {
9406 
9407  if (!p_ctx || !p_cfg)
9408  {
9409  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9410  __func__);
9411  return NI_RETCODE_INVALID_PARAM;
9412  }
9413 
9414  ni_pthread_mutex_lock(&p_ctx->mutex);
9416 
9417  switch (p_ctx->device_type)
9418  {
9419  case NI_DEVICE_TYPE_SCALER:
9420  retval = ni_scaler_config_frame(p_ctx, p_cfg);
9421  break;
9422 
9423  default:
9424  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9425  retval = NI_RETCODE_INVALID_PARAM;
9426  break;
9427  }
9428 
9430  ni_pthread_mutex_unlock(&p_ctx->mutex);
9431 
9432  return retval;
9433 }
9434 
9435 /*!*****************************************************************************
9436  * \brief Configure the 2D engine to work based on provided parameters
9437  *
9438  * \param[in] p_ctx pointer to session context
9439  * \param[in] p_cfg_in pointer to input frame configuration
9440  * \param[in] numInCfgs number of input frame configurations
9441  * \param[in] p_cfg_out pointer to output frame configuration
9442  *
9443  * \return NI_RETCODE_INVALID_PARAM
9444  * NI_RETCODE_ERROR_INVALID_SESSION
9445  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9446  * NI_RETCODE_ERROR_MEM_ALOC
9447  ******************************************************************************/
9449  ni_frame_config_t p_cfg_in[],
9450  int numInCfgs,
9451  ni_frame_config_t *p_cfg_out)
9452 {
9454 
9455  if (!p_ctx || !p_cfg_in)
9456  {
9457  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9458  __func__);
9459  return NI_RETCODE_INVALID_PARAM;
9460  }
9461 
9462  ni_pthread_mutex_lock(&p_ctx->mutex);
9464 
9465  switch (p_ctx->device_type)
9466  {
9467  case NI_DEVICE_TYPE_SCALER:
9468  retval = ni_scaler_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9469  break;
9470 
9471  case NI_DEVICE_TYPE_AI:
9472  retval = ni_ai_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9473  break;
9474 
9475  default:
9476  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9477  retval = NI_RETCODE_INVALID_PARAM;
9478  break;
9479  }
9480 
9482  ni_pthread_mutex_unlock(&p_ctx->mutex);
9483 
9484  return retval;
9485 }
9486 
9487 /*!*****************************************************************************
9488  * \brief Calculate the total size of a frame based on the upload
9489  * context attributes and includes rounding up to the page size
9490  *
9491  * \param[in] p_upl_ctx pointer to an uploader session context
9492  * \param[in] linesize array of line stride
9493  *
9494  * \return size
9495  * NI_RETCODE_INVALID_PARAM
9496  *
9497  ******************************************************************************/
9499  const int linesize[])
9500 {
9501  int pixel_format;
9502  int width, height;
9503  int alignedh;
9504  int luma, chroma_b, chroma_r;
9505  int total;
9506 
9507  pixel_format = p_upl_ctx->pixel_format;
9508  width = p_upl_ctx->active_video_width;
9509  height = p_upl_ctx->active_video_height;
9510 
9511  switch (pixel_format)
9512  {
9513  case NI_PIX_FMT_YUV420P:
9515  case NI_PIX_FMT_NV12:
9516  case NI_PIX_FMT_P010LE:
9517  if (width < 0 || width > NI_MAX_RESOLUTION_WIDTH)
9518  {
9519  return NI_RETCODE_INVALID_PARAM;
9520  }
9521 
9522  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9523  {
9524  return NI_RETCODE_INVALID_PARAM;
9525  }
9526  break;
9527 
9528  case NI_PIX_FMT_RGBA:
9529  case NI_PIX_FMT_ABGR:
9530  case NI_PIX_FMT_ARGB:
9531  case NI_PIX_FMT_BGRA:
9532  case NI_PIX_FMT_BGR0:
9533  if ((width < 0) || (width > NI_MAX_RESOLUTION_WIDTH))
9534  {
9535  return NI_RETCODE_INVALID_PARAM;
9536  }
9537 
9538  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9539  {
9540  return NI_RETCODE_INVALID_PARAM;
9541  }
9542  break;
9543 
9544  default:
9545  return NI_RETCODE_INVALID_PARAM;
9546  }
9547 
9548  alignedh = NI_VPU_CEIL(height, 2);
9549 
9550  switch (pixel_format)
9551  {
9552  case NI_PIX_FMT_YUV420P:
9554  luma = linesize[0] * alignedh;
9555  chroma_b = linesize[1] * alignedh / 2;
9556  chroma_r = linesize[2] * alignedh / 2;
9557  total =
9558  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9559  break;
9560 
9561  case NI_PIX_FMT_NV12:
9562  case NI_PIX_FMT_P010LE:
9563  luma = linesize[0] * alignedh;
9564  chroma_b = linesize[1] * alignedh / 2;
9565  chroma_r = 0;
9566  total =
9567  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9568  break;
9569 
9570  case NI_PIX_FMT_RGBA:
9571  case NI_PIX_FMT_ABGR:
9572  case NI_PIX_FMT_ARGB:
9573  case NI_PIX_FMT_BGRA:
9574  case NI_PIX_FMT_BGR0:
9575  total = width * height * 4 + NI_APP_ENC_FRAME_META_DATA_SIZE;
9576  break;
9577 
9578  default:
9579  return NI_RETCODE_INVALID_PARAM;
9580  break;
9581  }
9582 
9584 
9585  return total;
9586 }
9587 
9588 /*!*****************************************************************************
9589  * \brief Allocate memory for the frame buffer based on provided parameters
9590  * taking into account the pixel format, width, height, stride,
9591  * alignment, and extra data
9592  * \param[in] p_frame Pointer to caller allocated ni_frame_t
9593  * \param[in] pixel_format a pixel format in ni_pix_fmt_t enum
9594  * \param[in] video_width width, in pixels
9595  * \param[in] video_height height, in pixels
9596  * \param[in] linesize horizontal stride
9597  * \param[in] alignment apply a 16 pixel height alignment (T408 only)
9598  * \param[in] extra_len meta data size
9599  *
9600  * \return NI_RETCODE_SUCCESS
9601  * NI_RETCODE_INVALID_PARAM
9602  * NI_RETCODE_ERROR_MEM_ALOC
9603  *
9604  ******************************************************************************/
9606  int video_width, int video_height,
9607  int linesize[], int alignment,
9608  int extra_len)
9609 {
9610  int buffer_size;
9611  void *p_buffer = NULL;
9612  int retval = NI_RETCODE_SUCCESS;
9613  int height_aligned;
9614  int luma_size = 0;
9615  int chroma_b_size = 0;
9616  int chroma_r_size = 0;
9617 
9618  if (!p_frame)
9619  {
9620  ni_log(NI_LOG_ERROR, "Invalid frame pointer\n");
9621  return NI_RETCODE_INVALID_PARAM;
9622  }
9623 
9624  switch (pixel_format)
9625  {
9626  case NI_PIX_FMT_YUV420P:
9628  case NI_PIX_FMT_NV12:
9629  case NI_PIX_FMT_P010LE:
9630  case NI_PIX_FMT_NV16:
9631  case NI_PIX_FMT_YUYV422:
9632  case NI_PIX_FMT_UYVY422:
9633  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9634  {
9635  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9636  video_width);
9637  return NI_RETCODE_INVALID_PARAM;
9638  }
9639 
9640  if ((video_height < 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9641  {
9642  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9643  video_width);
9644  return NI_RETCODE_INVALID_PARAM;
9645  }
9646  break;
9647 
9648  case NI_PIX_FMT_RGBA:
9649  case NI_PIX_FMT_BGRA:
9650  case NI_PIX_FMT_ARGB:
9651  case NI_PIX_FMT_ABGR:
9652  case NI_PIX_FMT_BGR0:
9653  case NI_PIX_FMT_BGRP:
9654  /*
9655  * For 2D engine using RGBA, the minimum width is 32. There is no
9656  * height restriction. The 2D engine supports a height/width of up to
9657  * 32K but but we will limit the max height and width to 8K.
9658  */
9659  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9660  {
9661  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9662  video_width);
9663  return NI_RETCODE_INVALID_PARAM;
9664  }
9665 
9666  if ((video_height <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9667  {
9668  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9669  video_height);
9670  return NI_RETCODE_INVALID_PARAM;
9671  }
9672  break;
9673 
9674  default:
9675  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n",pixel_format);
9676  return NI_RETCODE_INVALID_PARAM;
9677  }
9678 
9679  if (QUADRA)
9680  {
9681  /* Quadra requires an even-numbered height/width */
9682  height_aligned = NI_VPU_CEIL(video_height, 2);
9683  }
9684  else
9685  {
9686  height_aligned = NI_VPU_ALIGN8(video_height);
9687 
9688  if (alignment)
9689  {
9690  /* 16-pixel aligned pixel height for Quadra */
9691  height_aligned = NI_VPU_ALIGN16(video_height);
9692  }
9693  }
9694 
9695  switch (pixel_format)
9696  {
9697  case NI_PIX_FMT_YUV420P:
9699  luma_size = linesize[0] * height_aligned;
9700 
9701  if (QUADRA)
9702  {
9703  chroma_b_size = linesize[1] * height_aligned / 2;
9704  chroma_r_size = linesize[2] * height_aligned / 2;
9705  }
9706  else
9707  {
9708  chroma_b_size = luma_size / 4;
9709  chroma_r_size = luma_size / 4;
9710  }
9711  break;
9712 
9713  case NI_PIX_FMT_RGBA:
9714  case NI_PIX_FMT_BGRA:
9715  case NI_PIX_FMT_ARGB:
9716  case NI_PIX_FMT_ABGR:
9717  case NI_PIX_FMT_BGR0:
9718  luma_size = linesize[0] * video_height;
9719  chroma_b_size = 0;
9720  chroma_r_size = 0;
9721  break;
9722 
9723  case NI_PIX_FMT_NV12:
9724  case NI_PIX_FMT_P010LE:
9725  if (QUADRA)
9726  {
9727  luma_size = linesize[0] * height_aligned;
9728  chroma_b_size = linesize[1] * height_aligned / 2;
9729  chroma_r_size = 0;
9730  break;
9731  }
9732  case NI_PIX_FMT_NV16:
9733  if (QUADRA)
9734  {
9735  luma_size = linesize[0] * video_height;
9736  chroma_b_size = linesize[1] * video_height;
9737  chroma_r_size = 0;
9738  break;
9739  }
9740  case NI_PIX_FMT_YUYV422:
9741  case NI_PIX_FMT_UYVY422:
9742  if (QUADRA)
9743  {
9744  luma_size = linesize[0] * video_height;
9745  chroma_b_size = 0;
9746  chroma_r_size = 0;
9747  break;
9748  }
9749  case NI_PIX_FMT_BGRP:
9750  if (QUADRA)
9751  {
9752  luma_size = NI_VPU_ALIGN32(linesize[0] * video_height);
9753  chroma_b_size = NI_VPU_ALIGN32(linesize[1] * video_height);
9754  chroma_r_size = NI_VPU_ALIGN32(linesize[2] * video_height);
9755  break;
9756  }
9757  /*fall through*/
9758  default:
9759  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9760  return NI_RETCODE_INVALID_PARAM;
9761  }
9762 
9763  buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
9764 
9765  /* Allocate a buffer size that is page aligned for the host */
9766  buffer_size = NI_VPU_CEIL(buffer_size,NI_MEM_PAGE_ALIGNMENT) + NI_MEM_PAGE_ALIGNMENT;
9767 
9768  /* If this buffer has a different size, realloc a new buffer */
9769  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9770  {
9771  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9772  p_frame->buffer_size);
9773  ni_frame_buffer_free(p_frame);
9774  }
9775 
9776  if (p_frame->buffer_size != buffer_size)
9777  {
9778  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9779  {
9780  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9781  retval = NI_RETCODE_ERROR_MEM_ALOC;
9782  LRETURN;
9783  }
9784 
9785  memset(p_buffer, 0, buffer_size);
9786  p_frame->buffer_size = buffer_size;
9787  p_frame->p_buffer = p_buffer;
9788  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
9789  }
9790  else
9791  {
9792  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
9793  }
9794 
9795  switch (pixel_format)
9796  {
9797  case NI_PIX_FMT_YUV420P:
9799  p_frame->p_data[0] = p_frame->p_buffer;
9800  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
9801  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
9802  p_frame->p_data[3] = NULL;
9803 
9804  p_frame->data_len[0] = luma_size;
9805  p_frame->data_len[1] = chroma_b_size;
9806  p_frame->data_len[2] = chroma_r_size;
9807  p_frame->data_len[3] = 0;
9808  video_width = NI_VPU_ALIGN128(video_width);
9809  break;
9810 
9811  case NI_PIX_FMT_RGBA:
9812  case NI_PIX_FMT_BGRA:
9813  case NI_PIX_FMT_ARGB:
9814  case NI_PIX_FMT_ABGR:
9815  case NI_PIX_FMT_BGR0:
9816  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9817  p_frame->p_data[1] = NULL;
9818  p_frame->p_data[2] = NULL;
9819  p_frame->p_data[3] = NULL;
9820 
9821  p_frame->data_len[0] = luma_size;
9822  p_frame->data_len[1] = 0;
9823  p_frame->data_len[2] = 0;
9824  p_frame->data_len[3] = 0;
9825  video_width = NI_VPU_ALIGN16(video_width);
9826  break;
9827 
9828  case NI_PIX_FMT_NV12:
9829  case NI_PIX_FMT_P010LE:
9830  if (QUADRA)
9831  {
9832  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9833  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9834  p_frame->p_data[2] = NULL;
9835  p_frame->p_data[3] = NULL;
9836 
9837  p_frame->data_len[0] = luma_size;
9838  p_frame->data_len[1] = chroma_b_size;
9839  p_frame->data_len[2] = 0;
9840  p_frame->data_len[3] = 0;
9841 
9842  video_width = NI_VPU_ALIGN128(video_width);
9843  break;
9844  }
9845  case NI_PIX_FMT_NV16:
9846  if (QUADRA)
9847  {
9848  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9849  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9850  p_frame->p_data[2] = NULL;
9851  p_frame->p_data[3] = NULL;
9852 
9853  p_frame->data_len[0] = luma_size;
9854  p_frame->data_len[1] = chroma_b_size;
9855  p_frame->data_len[2] = 0;
9856  p_frame->data_len[3] = 0;
9857 
9858  video_width = NI_VPU_ALIGN64(video_width);
9859  break;
9860  }
9861 
9862  case NI_PIX_FMT_YUYV422:
9863  case NI_PIX_FMT_UYVY422:
9864  if (QUADRA)
9865  {
9866  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9867  p_frame->p_data[1] = NULL;
9868  p_frame->p_data[2] = NULL;
9869  p_frame->p_data[3] = NULL;
9870 
9871  p_frame->data_len[0] = luma_size;
9872  p_frame->data_len[1] = 0;
9873  p_frame->data_len[2] = 0;
9874  p_frame->data_len[3] = 0;
9875  video_width = NI_VPU_ALIGN16(video_width);
9876  break;
9877  }
9878  case NI_PIX_FMT_BGRP:
9879  if (QUADRA)
9880  {
9881  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9882  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9883  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + chroma_b_size;
9884  p_frame->p_data[3] = NULL;
9885 
9886  p_frame->data_len[0] = luma_size;
9887  p_frame->data_len[1] = chroma_b_size;
9888  p_frame->data_len[2] = chroma_r_size;
9889  p_frame->data_len[3] = 0;
9890  break;
9891  }
9892  /* fall through */
9893  default:
9894  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9895  retval = NI_RETCODE_INVALID_PARAM;
9896  LRETURN;
9897  }
9898 
9899  p_frame->video_width = video_width;
9900  p_frame->video_height = height_aligned;
9901 
9902  ni_log(NI_LOG_DEBUG, "%s success: w=%d; h=%d; aligned buffer size=%d\n",
9903  __func__, video_width, video_height, buffer_size);
9904 
9905 END:
9906 
9907  if (retval != NI_RETCODE_SUCCESS)
9908  {
9909  ni_aligned_free(p_buffer);
9910  }
9911 
9912  return retval;
9913 }
9914 
9916  ni_network_data_t *p_network,
9917  const char *file)
9918 {
9919  FILE *fp = NULL;
9920  struct stat file_stat;
9922  unsigned char *buffer = NULL;
9923 
9924  if (!p_ctx)
9925  {
9926  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9927  __func__);
9928  return NI_RETCODE_INVALID_PARAM;
9929  }
9930  ni_pthread_mutex_lock(&p_ctx->mutex);
9932  ni_pthread_mutex_unlock(&p_ctx->mutex);
9933 
9934  char errmsg[NI_ERRNO_LEN] = {0};
9935  if (stat(file, &file_stat) != 0)
9936  {
9937  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
9938  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to get network binary file stat, %s\n",
9939  __func__, errmsg);
9940  retval = NI_RETCODE_FAILURE;
9941  LRETURN;
9942  }
9943 
9944  if (file_stat.st_size == 0)
9945  {
9946  ni_log2(p_ctx, NI_LOG_ERROR, "%s: network binary size is null\n", __func__);
9947  retval = NI_RETCODE_FAILURE;
9948  LRETURN;
9949  }
9950 
9951  ni_fopen(&fp, file, "rb");
9952  if (!fp)
9953  {
9954  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
9955  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to open network binary, %s\n", __func__,
9956  errmsg);
9957  retval = NI_RETCODE_FAILURE;
9958  LRETURN;
9959  }
9960 
9961  buffer = malloc(file_stat.st_size);
9962  if (!buffer)
9963  {
9964  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to alloate memory\n", __func__);
9965  retval = NI_RETCODE_ERROR_MEM_ALOC;
9966  LRETURN;
9967  }
9968 
9969  if (fread(buffer, file_stat.st_size, 1, fp) != 1)
9970  {
9971  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to read network binary\n", __func__);
9972  retval = NI_RETCODE_FAILURE;
9973  LRETURN;
9974  }
9975 
9976  retval =
9977  ni_config_instance_network_binary(p_ctx, buffer, file_stat.st_size);
9978  if (retval != NI_RETCODE_SUCCESS)
9979  {
9980  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9981  __func__, retval);
9982  LRETURN;
9983  }
9984 
9985  retval = ni_config_read_inout_layers(p_ctx, p_network);
9986  if (retval != NI_RETCODE_SUCCESS)
9987  {
9988  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9989  retval);
9990  }
9991 
9992 END:
9993 
9994  if (fp)
9995  {
9996  fclose(fp);
9997  }
9998  free(buffer);
9999 
10000  ni_pthread_mutex_lock(&p_ctx->mutex);
10002  ni_pthread_mutex_unlock(&p_ctx->mutex);
10003 
10004  return retval;
10005 }
10006 
10008  ni_network_data_t *p_network)
10009 {
10011 
10012  if (!p_ctx)
10013  {
10014  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10015  __func__);
10016  return NI_RETCODE_INVALID_PARAM;
10017  }
10018 
10019  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6ro") < 0))
10020  {
10021  ni_log2(p_ctx, NI_LOG_ERROR, "Error: hvsplus filter not supported on device with FW API version < 6ro\n");
10023  }
10024 
10025  ni_pthread_mutex_lock(&p_ctx->mutex);
10027  ni_pthread_mutex_unlock(&p_ctx->mutex);
10028 
10029  retval =
10030  ni_config_instance_hvsplus(p_ctx); //, buffer, file_stat.st_size);
10031  if (retval != NI_RETCODE_SUCCESS)
10032  {
10033  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
10034  __func__, retval);
10035  LRETURN;
10036  }
10037 
10038  retval = ni_config_read_inout_layers(p_ctx, p_network);
10039  if (retval != NI_RETCODE_SUCCESS)
10040  {
10041  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
10042  retval);
10043  }
10044 
10045 END:
10046 
10047  ni_pthread_mutex_lock(&p_ctx->mutex);
10049  ni_pthread_mutex_unlock(&p_ctx->mutex);
10050 
10051  return retval;
10052 }
10053 
10055  ni_network_data_t *p_network)
10056 {
10057  uint32_t buffer_size = 0;
10058  void *p_buffer = NULL;
10059  int retval = NI_RETCODE_SUCCESS;
10060  uint32_t i, this_size;
10061  ni_network_layer_info_t *p_linfo;
10062 
10063  if (!p_frame || !p_network)
10064  {
10065  ni_log(NI_LOG_ERROR, "Invalid frame or network layer pointer\n");
10066  return NI_RETCODE_INVALID_PARAM;
10067  }
10068 
10069  p_linfo = &p_network->linfo;
10070  for (i = 0; i < p_network->input_num; i++)
10071  {
10072  this_size = ni_ai_network_layer_size(&p_linfo->in_param[i]);
10073  this_size =
10074  (this_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
10075  if (p_network->inset[i].offset != buffer_size)
10076  {
10078  "ERROR: %s(): invalid buffer_size of network\n", __func__);
10079  return NI_RETCODE_INVALID_PARAM;
10080  }
10081  buffer_size += this_size;
10082  }
10083 
10084  /* fixed size */
10085  p_frame->data_len[0] = buffer_size;
10086 
10087  /* Allocate a buffer size that is page aligned for the host */
10088  buffer_size = (buffer_size + NI_MEM_PAGE_ALIGNMENT - 1) &
10089  ~(NI_MEM_PAGE_ALIGNMENT - 1);
10090 
10091  /* If this buffer has a different size, realloc a new buffer */
10092  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
10093  {
10094  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
10095  p_frame->buffer_size);
10096  ni_frame_buffer_free(p_frame);
10097  }
10098 
10099  if (p_frame->buffer_size != buffer_size)
10100  {
10101  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
10102  {
10103  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
10104  retval = NI_RETCODE_ERROR_MEM_ALOC;
10105  LRETURN;
10106  }
10107 
10108  // memset(p_buffer, 0, buffer_size);
10109  p_frame->buffer_size = buffer_size;
10110  p_frame->p_buffer = p_buffer;
10111  ni_log(NI_LOG_DEBUG, "%s(): allocated new p_frame buffer\n", __func__);
10112  } else
10113  {
10114  ni_log(NI_LOG_DEBUG, "%s(): reuse p_frame buffer\n", __func__);
10115  }
10116 
10117  p_frame->p_data[0] = p_frame->p_buffer;
10118  p_frame->p_data[1] = NULL;
10119  p_frame->p_data[2] = NULL;
10120  p_frame->p_data[3] = NULL;
10121 
10122  p_frame->iovec = NULL;
10123  p_frame->iovec_num = 0;
10124 
10125  ni_log(NI_LOG_DEBUG, "%s() success: aligned buffer size=%u\n", __func__,
10126  buffer_size);
10127 
10128 END:
10129 
10130  if (retval != NI_RETCODE_SUCCESS)
10131  {
10132  ni_aligned_free(p_buffer);
10133  }
10134 
10135  return retval;
10136 }
10137 
10139  ni_network_data_t *p_network)
10140 {
10141  void *p_buffer = NULL;
10142  int retval = NI_RETCODE_SUCCESS;
10143  uint32_t buffer_size = 0;
10144  uint32_t i, data_size;
10145  ni_network_layer_info_t *p_linfo;
10146 
10147  if (!p_packet || !p_network)
10148  {
10149  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
10150  __func__);
10151  return NI_RETCODE_INVALID_PARAM;
10152  }
10153 
10154  p_linfo = &p_network->linfo;
10155  for (i = 0; i < p_network->output_num; i++)
10156  {
10157  data_size = ni_ai_network_layer_size(&p_linfo->out_param[i]);
10158  data_size =
10159  (data_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
10160  if (p_network->outset[i].offset != buffer_size)
10161  {
10163  "ERROR: %s(): invalid buffer_size of network\n", __func__);
10164  return NI_RETCODE_INVALID_PARAM;
10165  }
10166  buffer_size += data_size;
10167  }
10168  data_size = buffer_size;
10169 
10170  ni_log(NI_LOG_DEBUG, "%s(): packet_size=%u\n", __func__, buffer_size);
10171 
10172  if (buffer_size & (NI_MEM_PAGE_ALIGNMENT - 1))
10173  {
10174  buffer_size = (buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) &
10175  ~(NI_MEM_PAGE_ALIGNMENT - 1);
10176  }
10177 
10178  if (p_packet->buffer_size == buffer_size)
10179  {
10180  p_packet->p_data = p_packet->p_buffer;
10181  ni_log(NI_LOG_DEBUG, "%s(): reuse current p_packet buffer\n", __func__);
10182  LRETURN; //Already allocated the exact size
10183  } else if (p_packet->buffer_size > 0)
10184  {
10186  "%s(): free current p_packet, p_packet->buffer_size=%u\n",
10187  __func__, p_packet->buffer_size);
10188  ni_packet_buffer_free(p_packet);
10189  }
10190  ni_log(NI_LOG_DEBUG, "%s(): Allocating p_packet buffer, buffer_size=%u\n",
10191  __func__, buffer_size);
10192 
10193  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
10194  {
10195  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
10196  NI_ERRNO, __func__);
10197  retval = NI_RETCODE_ERROR_MEM_ALOC;
10198  LRETURN;
10199  }
10200 
10201  p_packet->buffer_size = buffer_size;
10202  p_packet->p_buffer = p_buffer;
10203  p_packet->p_data = p_packet->p_buffer;
10204  p_packet->data_len = data_size;
10205 
10206 END:
10207 
10208  if (NI_RETCODE_SUCCESS != retval)
10209  {
10210  ni_aligned_free(p_buffer);
10211  }
10212 
10213  ni_log(NI_LOG_TRACE, "%s(): exit: p_packet->buffer_size=%u\n", __func__,
10214  p_packet->buffer_size);
10215 
10216  return retval;
10217 }
10218 
10219 /*!*****************************************************************************
10220  * \brief Reconfigure bitrate dynamically during encoding.
10221  *
10222  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10223  * \param[in] bitrate Target bitrate to set
10224  *
10225  * \return On success NI_RETCODE_SUCCESS
10226  * On failure NI_RETCODE_INVALID_PARAM
10227  ******************************************************************************/
10229 {
10230  if (!p_ctx || bitrate < NI_MIN_BITRATE || bitrate > NI_MAX_BITRATE)
10231  {
10232  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid bitrate passed in %d\n",
10233  __func__, bitrate);
10234  return NI_RETCODE_INVALID_PARAM;
10235  }
10236  ni_pthread_mutex_lock(&p_ctx->mutex);
10238 
10239  if (p_ctx->target_bitrate > 0)
10240  {
10241  ni_log2(p_ctx, NI_LOG_DEBUG,
10242  "Warning: %s(): bitrate %d overwriting current one %d\n",
10243  __func__, bitrate, p_ctx->target_bitrate);
10244  }
10245 
10246  p_ctx->target_bitrate = bitrate;
10247 
10249  ni_pthread_mutex_unlock(&p_ctx->mutex);
10250 
10251  return NI_RETCODE_SUCCESS;
10252 }
10253 
10254 /*!*****************************************************************************
10255  * \brief Reconfigure intraPeriod dynamically during encoding.
10256  *
10257  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10258  * \param[in] intra_period Target intra period to set
10259  *
10260  *
10261  * \return On success NI_RETCODE_SUCCESS
10262  * On failure NI_RETCODE_INVALID_PARAM
10263  *
10264  * NOTE - the frame upon which intra period is reconfigured is encoded as IDR frame
10265  * NOTE - reconfigure intra period is not allowed if intraRefreshMode is enabled or if gopPresetIdx is 1
10266  *
10267  ******************************************************************************/
10269  int32_t intra_period)
10270 {
10271  if (!p_ctx || intra_period < 0 || intra_period > 1024)
10272  {
10273  ni_log(NI_LOG_ERROR, "ERROR: %s(): invalid intraPeriod passed in %d\n",
10274  __func__, intra_period);
10275  return NI_RETCODE_INVALID_PARAM;
10276  }
10277  ni_pthread_mutex_lock(&p_ctx->mutex);
10279 
10280  if (p_ctx->reconfig_intra_period >= 0)
10281  {
10283  "Warning: %s(): intraPeriod %d overwriting current one %d\n",
10284  __func__, intra_period, p_ctx->reconfig_intra_period);
10285  }
10286 
10287  p_ctx->reconfig_intra_period = intra_period;
10288 
10290  ni_pthread_mutex_unlock(&p_ctx->mutex);
10291 
10292  return NI_RETCODE_SUCCESS;
10293 }
10294 
10295 /*!*****************************************************************************
10296  * \brief Reconfigure VUI HRD dynamically during encoding.
10297  *
10298  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10299  * \param[in] bitrate Target bitrate to set
10300  *
10301  * \return On success NI_RETCODE_SUCCESS
10302  * On failure NI_RETCODE_INVALID_PARAM
10303  ******************************************************************************/
10305 {
10306  if (!p_ctx || vui->colorDescPresent < 0 || vui->colorDescPresent > 1)
10307  {
10308  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid colorDescPresent passed in %d\n",
10309  __func__, vui->colorDescPresent);
10310  return NI_RETCODE_INVALID_PARAM;
10311  }
10312 
10314  {
10315  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid aspect ratio passed in (%dx%d)\n",
10316  __func__, vui->aspectRatioWidth, vui->aspectRatioHeight);
10317  return NI_RETCODE_INVALID_PARAM;
10318  }
10319 
10320  if (vui->videoFullRange < 0 || vui->videoFullRange > 1)
10321  {
10322  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid videoFullRange passed in %d\n",
10323  __func__, vui->videoFullRange);
10324  return NI_RETCODE_INVALID_PARAM;
10325  }
10326 
10327  ni_pthread_mutex_lock(&p_ctx->mutex);
10329 
10330  p_ctx->vui.colorDescPresent = vui->colorDescPresent;
10331  p_ctx->vui.colorPrimaries = vui->colorPrimaries;
10332  p_ctx->vui.colorTrc = vui->colorTrc;
10333  p_ctx->vui.colorSpace = vui->colorSpace;
10334  p_ctx->vui.aspectRatioWidth = vui->aspectRatioWidth;
10335  p_ctx->vui.aspectRatioHeight = vui->aspectRatioHeight;
10336  p_ctx->vui.videoFullRange = vui->videoFullRange;
10337 
10339  ni_pthread_mutex_unlock(&p_ctx->mutex);
10340 
10341  return NI_RETCODE_SUCCESS;
10342 }
10343 
10344 /*!*****************************************************************************
10345  * \brief Force next frame to be IDR frame during encoding.
10346  *
10347  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10348  *
10349  * \return On success NI_RETCODE_SUCCESS
10350  ******************************************************************************/
10352 {
10353  if (!p_ctx)
10354  {
10355  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10356  __func__);
10357  return NI_RETCODE_INVALID_PARAM;
10358  }
10359  ni_pthread_mutex_lock(&p_ctx->mutex);
10361 
10362  if (p_ctx->force_idr_frame)
10363  {
10364  ni_log2(p_ctx, NI_LOG_DEBUG, "Warning: %s(): already forcing IDR frame\n",
10365  __func__);
10366  }
10367 
10368  p_ctx->force_idr_frame = 1;
10369 
10371  ni_pthread_mutex_unlock(&p_ctx->mutex);
10372 
10373  return NI_RETCODE_SUCCESS;
10374 }
10375 
10376 /*!*****************************************************************************
10377  * \brief Set a frame's support of Long Term Reference frame during encoding.
10378  *
10379  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10380  * \param[in] ltr Pointer to struct specifying LTR support
10381  *
10382  * \return On success NI_RETCODE_SUCCESS
10383  * On failure NI_RETCODE_INVALID_PARAM
10384  ******************************************************************************/
10386 {
10387  if (!p_ctx)
10388  {
10389  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10390  __func__);
10391  return NI_RETCODE_INVALID_PARAM;
10392  }
10393  ni_pthread_mutex_lock(&p_ctx->mutex);
10394 
10398 
10399  ni_pthread_mutex_unlock(&p_ctx->mutex);
10400 
10401  return NI_RETCODE_SUCCESS;
10402 }
10403 
10404 /*!*****************************************************************************
10405  * \brief Set Long Term Reference interval
10406  *
10407  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10408  * \param[in] ltr_interval the new long term reference inteval value
10409  *
10410  * \return On success NI_RETCODE_SUCCESS
10411  * On failure NI_RETCODE_INVALID_PARAM
10412  ******************************************************************************/
10414  int32_t ltr_interval)
10415 {
10416  if (!p_ctx)
10417  {
10418  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10419  __func__);
10420  return NI_RETCODE_INVALID_PARAM;
10421  }
10422  ni_pthread_mutex_lock(&p_ctx->mutex);
10423 
10424  p_ctx->ltr_interval = ltr_interval;
10425 
10426  ni_pthread_mutex_unlock(&p_ctx->mutex);
10427 
10428  return NI_RETCODE_SUCCESS;
10429 }
10430 
10431 /*!*****************************************************************************
10432  * \brief Set frame reference invalidation
10433  *
10434  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10435  * \param[in] frame_num frame number after which all references shall be
10436  * invalidated
10437  *
10438  * \return On success NI_RETCODE_SUCCESS
10439  * On failure NI_RETCODE_INVALID_PARAM
10440  ******************************************************************************/
10442  int32_t frame_num)
10443 {
10444  if (!p_ctx)
10445  {
10446  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10447  __func__);
10448  return NI_RETCODE_INVALID_PARAM;
10449  }
10450  ni_pthread_mutex_lock(&p_ctx->mutex);
10451  p_ctx->ltr_frame_ref_invalid = frame_num;
10452  ni_pthread_mutex_unlock(&p_ctx->mutex);
10453 
10454  return NI_RETCODE_SUCCESS;
10455 }
10456 
10457 /*!*****************************************************************************
10458  * \brief Reconfigure framerate dynamically during encoding.
10459  *
10460  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10461  * \param[in] framerate Target framerate to set
10462  *
10463  * \return On success NI_RETCODE_SUCCESS
10464  * On failure NI_RETCODE_INVALID_PARAM
10465  ******************************************************************************/
10467  ni_framerate_t *framerate)
10468 {
10469  int32_t framerate_num = framerate->framerate_num;
10470  int32_t framerate_denom = framerate->framerate_denom;
10471  if (!p_ctx || framerate_num <= 0 || framerate_denom <= 0)
10472  {
10473  ni_log2(p_ctx, NI_LOG_ERROR,
10474  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10475  framerate_num, framerate_denom);
10476  return NI_RETCODE_INVALID_PARAM;
10477  }
10478 
10479  if ((framerate_num % framerate_denom) != 0)
10480  {
10481  uint32_t numUnitsInTick = 1000;
10482  framerate_num = framerate_num / framerate_denom;
10483  framerate_denom = numUnitsInTick + 1;
10484  framerate_num += 1;
10485  framerate_num *= numUnitsInTick;
10486  } else
10487  {
10488  framerate_num = framerate_num / framerate_denom;
10489  framerate_denom = 1;
10490  }
10491 
10492  if (((framerate_num + framerate_denom - 1) / framerate_denom) >
10494  {
10495  ni_log2(p_ctx, NI_LOG_ERROR,
10496  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10497  framerate->framerate_num, framerate->framerate_denom);
10498  return NI_RETCODE_INVALID_PARAM;
10499  }
10500 
10501  ni_pthread_mutex_lock(&p_ctx->mutex);
10503 
10504  if (p_ctx->framerate.framerate_num > 0)
10505  {
10506  ni_log2(p_ctx, NI_LOG_DEBUG,
10507  "Warning: %s(): framerate (%d/%d) overwriting current "
10508  "one (%d/%d)\n",
10509  __func__, framerate_num, framerate_denom,
10510  p_ctx->framerate.framerate_num,
10511  p_ctx->framerate.framerate_denom);
10512  }
10513 
10514  p_ctx->framerate.framerate_num = framerate_num;
10515  p_ctx->framerate.framerate_denom = framerate_denom;
10516 
10518  ni_pthread_mutex_unlock(&p_ctx->mutex);
10519 
10520  return NI_RETCODE_SUCCESS;
10521 }
10522 
10523 /*!*****************************************************************************
10524  * \brief Reconfigure maxFrameSize dynamically during encoding.
10525  *
10526  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10527  * \param[in] max_frame_size maxFrameSize to set
10528  *
10529  * \return On success NI_RETCODE_SUCCESS
10530  * On failure NI_RETCODE_INVALID_PARAM
10531  *
10532  * NOTE - maxFrameSize_Bytes value less than ((bitrate / 8) / framerate) will be rejected
10533  *
10534  ******************************************************************************/
10536 {
10537  ni_xcoder_params_t *api_param;
10538  int32_t bitrate, framerate_num, framerate_denom;
10539  uint32_t maxFrameSize = (uint32_t)max_frame_size / 2000;
10540  uint32_t min_maxFrameSize;
10541 
10542  if (!p_ctx || !p_ctx->p_session_config)
10543  {
10544  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10545  __func__);
10546  return NI_RETCODE_INVALID_PARAM;
10547  }
10548 
10549  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10550 
10551  if (!api_param->low_delay_mode)
10552  {
10553  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size is valid only when lowDelay mode is enabled\n",
10554  __func__, max_frame_size);
10555  return NI_RETCODE_INVALID_PARAM;
10556  }
10557 
10558  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10559 
10560  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10561  {
10562  framerate_num = p_ctx->framerate.framerate_num;
10563  framerate_denom = p_ctx->framerate.framerate_denom;
10564  }
10565  else
10566  {
10567  framerate_num = (int32_t) api_param->fps_number;
10568  framerate_denom = (int32_t) api_param->fps_denominator;
10569  }
10570 
10571  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10572 
10573  if (maxFrameSize < min_maxFrameSize)
10574  {
10575  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size %d is too small (invalid)\n",
10576  __func__, max_frame_size);
10577  return NI_RETCODE_INVALID_PARAM;
10578  }
10579  if (max_frame_size > NI_MAX_FRAME_SIZE) {
10580  max_frame_size = NI_MAX_FRAME_SIZE;
10581  }
10582 
10583  ni_pthread_mutex_lock(&p_ctx->mutex);
10585 
10586  if (p_ctx->max_frame_size > 0)
10587  {
10588  ni_log2(p_ctx, NI_LOG_DEBUG,
10589  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10590  __func__, max_frame_size, p_ctx->max_frame_size);
10591  }
10592 
10593  p_ctx->max_frame_size = max_frame_size;
10594 
10596  ni_pthread_mutex_unlock(&p_ctx->mutex);
10597 
10598  return NI_RETCODE_SUCCESS;
10599 }
10600 
10601 /*!*****************************************************************************
10602  * \brief Reconfigure min&max qp dynamically during encoding.
10603  *
10604  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10605  * \param[in] ni_rc_min_max_qp Target min&max qp to set
10606  *
10607  * \return On success NI_RETCODE_SUCCESS
10608  * On failure NI_RETCODE_INVALID_PARAM
10609  ******************************************************************************/
10611  ni_rc_min_max_qp *p_min_max_qp)
10612 {
10613  int32_t minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB;
10614 
10615  if (!p_ctx || !p_min_max_qp)
10616  {
10617  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_min_max_qp pointer\n",
10618  __func__);
10619  return NI_RETCODE_INVALID_PARAM;
10620  }
10621 
10622  minQpI = p_min_max_qp->minQpI;
10623  maxQpI = p_min_max_qp->maxQpI;
10624  maxDeltaQp = p_min_max_qp->maxDeltaQp;
10625  minQpPB = p_min_max_qp->minQpPB;
10626  maxQpPB = p_min_max_qp->maxQpPB;
10627 
10628  if (minQpI > maxQpI || minQpPB > maxQpPB ||
10629  maxQpI > 51 || minQpI < 0 || maxQpPB > 51 || minQpPB < 0)
10630  {
10631  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid qp setting <%d %d %d %d %d>\n",
10632  __func__, minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB);
10633  return NI_RETCODE_INVALID_PARAM;
10634  }
10635 
10636  ni_pthread_mutex_lock(&p_ctx->mutex);
10638 
10639  p_ctx->enc_change_params->minQpI = minQpI;
10640  p_ctx->enc_change_params->maxQpI = maxQpI;
10641  p_ctx->enc_change_params->maxDeltaQp = maxDeltaQp;
10642  p_ctx->enc_change_params->minQpPB = minQpPB;
10643  p_ctx->enc_change_params->maxQpPB = maxQpPB;
10644 
10646  ni_pthread_mutex_unlock(&p_ctx->mutex);
10647 
10648  return NI_RETCODE_SUCCESS;
10649 }
10650 
10651 /*!*****************************************************************************
10652  * \brief Reconfigure crf value dynamically during encoding.
10653  *
10654  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10655  * \param[in] crf crf value to reconfigure
10656  *
10657  * \return On success NI_RETCODE_SUCCESS
10658  * On failure NI_RETCODE_INVALID_PARAM
10659  ******************************************************************************/
10661  int32_t crf)
10662 {
10663  ni_xcoder_params_t *api_param;
10664 
10665  if (!p_ctx || !p_ctx->p_session_config)
10666  {
10667  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10668  __func__);
10669  return NI_RETCODE_INVALID_PARAM;
10670  }
10671 
10672  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10673 
10674  if (api_param->cfg_enc_params.crf < 0)
10675  {
10676  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %d is valid only in CRF mode\n",
10677  __func__, crf);
10678  return NI_RETCODE_INVALID_PARAM;
10679  }
10680 
10681  if (crf < 0 || crf > 51)
10682  {
10683  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %d is invalid (valid range in [0..51])\n",
10684  __func__, crf);
10685  return NI_RETCODE_INVALID_PARAM;
10686  }
10687 
10688  ni_pthread_mutex_lock(&p_ctx->mutex);
10689 
10691 
10692  if (p_ctx->reconfig_crf >= 0)
10693  {
10694  ni_log2(p_ctx, NI_LOG_DEBUG,
10695  "Warning: %s(): crf reconfig value %d overwriting current reconfig_crf %d\n",
10696  __func__, crf, p_ctx->reconfig_crf);
10697  }
10698 
10699  p_ctx->reconfig_crf = crf;
10700 
10702 
10703  ni_pthread_mutex_unlock(&p_ctx->mutex);
10704 
10705  return NI_RETCODE_SUCCESS;
10706 }
10707 
10708 /*!*****************************************************************************
10709  * \brief Reconfigure crf float point value dynamically during encoding.
10710  *
10711  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10712  * \param[in] crf crf float point value to reconfigure
10713  *
10714  * \return On success NI_RETCODE_SUCCESS
10715  * On failure NI_RETCODE_INVALID_PARAM
10716  ******************************************************************************/
10718  float crf)
10719 {
10720  ni_xcoder_params_t *api_param;
10721 
10722  if (!p_ctx || !p_ctx->p_session_config)
10723  {
10724  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10725  __func__);
10726  return NI_RETCODE_INVALID_PARAM;
10727  }
10728 
10729  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10730 
10731  if (api_param->cfg_enc_params.crfFloat < 0)
10732  {
10733  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %f is valid only in CRF mode\n",
10734  __func__, crf);
10735  return NI_RETCODE_INVALID_PARAM;
10736  }
10737 
10738  if (crf < 0.0 || crf > 51.0)
10739  {
10740  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %f is invalid (valid range in [0..51])\n",
10741  __func__, crf);
10742  return NI_RETCODE_INVALID_PARAM;
10743  }
10744 
10745  ni_pthread_mutex_lock(&p_ctx->mutex);
10746 
10748 
10749  if (p_ctx->reconfig_crf >= 0 || p_ctx->reconfig_crf_decimal > 0)
10750  {
10751  ni_log2(p_ctx, NI_LOG_DEBUG,
10752  "Warning: %s(): crf reconfig value %d overwriting current "
10753  "reconfig_crf %d, reconfig_crf_decimal %d\n", __func__,
10754  crf, p_ctx->reconfig_crf, p_ctx->reconfig_crf_decimal);
10755  }
10756 
10757  p_ctx->reconfig_crf = (int)crf;
10758  p_ctx->reconfig_crf_decimal = (int)((crf - (float)p_ctx->reconfig_crf) * 100);
10759 
10761 
10762  ni_pthread_mutex_unlock(&p_ctx->mutex);
10763 
10764  return NI_RETCODE_SUCCESS;
10765 }
10766 
10767 /*!*****************************************************************************
10768  * \brief Reconfigure vbv buffer size and vbv max rate dynamically during encoding.
10769  *
10770  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10771  * \param[in] vbvBufferSize Target vbvBufferSize to set
10772  * \param[in] vbvMaxRate Target vbvMaxRate to set
10773  *
10774  * \return On success NI_RETCODE_SUCCESS
10775  * On failure NI_RETCODE_INVALID_PARAM
10776  ******************************************************************************/
10778  int32_t vbvMaxRate, int32_t vbvBufferSize)
10779 {
10780  ni_xcoder_params_t *api_param;
10781  if (!p_ctx || !p_ctx->p_session_config)
10782  {
10783  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10784  __func__);
10785  return NI_RETCODE_INVALID_PARAM;
10786  }
10787  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
10788  {
10789  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): vbvBufferSize value %d\n",
10790  __func__, vbvBufferSize);
10791  return NI_RETCODE_INVALID_PARAM;
10792  }
10793  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10794  if (api_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < api_param->bitrate) {
10795  ni_log2(p_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
10796  vbvMaxRate, api_param->bitrate);
10797  return NI_RETCODE_INVALID_PARAM;
10798  }
10799  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
10800  ni_log2(p_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
10801  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
10802  vbvMaxRate);
10803  vbvMaxRate = 0;
10804  }
10805 
10806  ni_pthread_mutex_lock(&p_ctx->mutex);
10808 
10809  p_ctx->reconfig_vbv_buffer_size = vbvBufferSize;
10810  p_ctx->reconfig_vbv_max_rate = vbvMaxRate;
10811 
10813  ni_pthread_mutex_unlock(&p_ctx->mutex);
10814 
10815  return NI_RETCODE_SUCCESS;
10816 }
10817 
10818 /*!*****************************************************************************
10819  * \brief Reconfigure maxFrameSizeRatio dynamically during encoding.
10820  *
10821  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10822  * \param[in] max_frame_size_ratio maxFrameSizeRatio to set
10823  *
10824  * \return On success NI_RETCODE_SUCCESS
10825  * On failure NI_RETCODE_INVALID_PARAM
10826  ******************************************************************************/
10828 {
10829  ni_xcoder_params_t *api_param;
10830  int32_t bitrate, framerate_num, framerate_denom;
10831  uint32_t min_maxFrameSize, maxFrameSize;
10832 
10833  if (!p_ctx || !p_ctx->p_session_config)
10834  {
10835  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10836  __func__);
10837  return NI_RETCODE_INVALID_PARAM;
10838  }
10839 
10840  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10841 
10842  if (!api_param->low_delay_mode)
10843  {
10844  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio is valid only when lowDelay mode is enabled\n",
10845  __func__, max_frame_size_ratio);
10846  return NI_RETCODE_INVALID_PARAM;
10847  }
10848 
10849  if (max_frame_size_ratio < 1) {
10850  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio %d cannot < 1\n",
10851  max_frame_size_ratio);
10852  return NI_RETCODE_INVALID_PARAM;
10853  }
10854 
10855  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10856 
10857  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10858  {
10859  framerate_num = p_ctx->framerate.framerate_num;
10860  framerate_denom = p_ctx->framerate.framerate_denom;
10861  }
10862  else
10863  {
10864  framerate_num = (int32_t) api_param->fps_number;
10865  framerate_denom = (int32_t) api_param->fps_denominator;
10866  }
10867 
10868  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10869 
10870  maxFrameSize = min_maxFrameSize * max_frame_size_ratio > NI_MAX_FRAME_SIZE ?
10871  NI_MAX_FRAME_SIZE : min_maxFrameSize * max_frame_size_ratio;
10872 
10873  ni_pthread_mutex_lock(&p_ctx->mutex);
10875 
10876  if (p_ctx->max_frame_size > 0)
10877  {
10878  ni_log2(p_ctx, NI_LOG_DEBUG,
10879  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10880  __func__, maxFrameSize, p_ctx->max_frame_size);
10881  }
10882 
10883  p_ctx->max_frame_size = maxFrameSize;
10884 
10886  ni_pthread_mutex_unlock(&p_ctx->mutex);
10887 
10888  return NI_RETCODE_SUCCESS;
10889 }
10890 
10891 /*!*****************************************************************************
10892  * \brief Reconfigure sliceArg dynamically during encoding.
10893  *
10894  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10895  * \param[in] sliceArg the new sliceArg value
10896  *
10897  * \return On success NI_RETCODE_SUCCESS
10898  * On failure NI_RETCODE_INVALID_PARAM
10899  ******************************************************************************/
10901 {
10902  ni_xcoder_params_t *api_param;
10903  ni_encoder_cfg_params_t *p_enc;
10904 
10905  if (!p_ctx || !p_ctx->p_session_config)
10906  {
10907  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10908  __func__);
10909  return NI_RETCODE_INVALID_PARAM;
10910  }
10911 
10912  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10913  p_enc = &api_param->cfg_enc_params;
10914  if (p_enc->slice_mode == 0)
10915  {
10916  ni_log2(p_ctx, NI_LOG_ERROR, "%s():not support to reconfig slice_arg when slice_mode disable.\n",
10917  __func__);
10918  sliceArg = 0;
10919  }
10921  {
10922  ni_log2(p_ctx, NI_LOG_ERROR, "%s():sliceArg is only supported for H.264 or H.265.\n",
10923  __func__);
10924  sliceArg = 0;
10925  }
10926  int ctu_mb_size = (NI_CODEC_FORMAT_H264 == p_ctx->codec_format) ? 16 : 64;
10927  int max_num_ctu_mb_row = (api_param->source_height + ctu_mb_size - 1) / ctu_mb_size;
10928  if (sliceArg < 1 || sliceArg > max_num_ctu_mb_row)
10929  {
10930  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid data sliceArg %d\n", __func__,
10931  sliceArg);
10932  sliceArg = 0;
10933  }
10934 
10935  ni_pthread_mutex_lock(&p_ctx->mutex);
10937 
10938  p_ctx->reconfig_slice_arg = sliceArg;
10939 
10941  ni_pthread_mutex_unlock(&p_ctx->mutex);
10942 
10943  return NI_RETCODE_SUCCESS;
10944 }
10945 
10946 #ifndef _WIN32
10947 /*!*****************************************************************************
10948 * \brief Acquire a P2P frame buffer from the hwupload session
10949 *
10950 * \param[in] p_ctx Pointer to a caller allocated
10951 * ni_session_context_t struct
10952 * \param[out] p_frame Pointer to a caller allocated hw frame
10953 *
10954 * \return On success
10955 * NI_RETCODE_SUCCESS
10956 * On failure
10957 * NI_RETCODE_INVALID_PARAM
10958 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10959 * NI_RETCODE_ERROR_INVALID_SESSION
10960 *******************************************************************************/
10962 {
10964  struct netint_iocmd_export_dmabuf uexp;
10965  unsigned int offset;
10966  int ret, is_semi_planar;
10967  int linestride[NI_MAX_NUM_DATA_POINTERS];
10968  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10969  niFrameSurface1_t hwdesc = {0};
10970  niFrameSurface1_t *p_surface;
10971 
10972  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10973  {
10974  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10975  __func__);
10976  return NI_RETCODE_INVALID_PARAM;
10977  }
10978 
10979  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10980 
10981  ni_pthread_mutex_lock(&p_ctx->mutex);
10983 
10984  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10985 
10987  ni_pthread_mutex_unlock(&p_ctx->mutex);
10988 
10989  if (retval != NI_RETCODE_SUCCESS)
10990  {
10991  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10992  return retval;
10993  }
10994 
10995  retval = ni_get_memory_offset(p_ctx, &hwdesc, &offset);
10996  if (retval != NI_RETCODE_SUCCESS)
10997  {
10998  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: bad buffer id\n");
10999  return NI_RETCODE_INVALID_PARAM;
11000  }
11001 
11002  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
11003  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
11004  1 :
11005  0;
11006 
11008  p_ctx->bit_depth_factor, is_semi_planar, linestride,
11009  alignedheight);
11010 
11011  uexp.fd = -1;
11012  uexp.flags = 0;
11013  uexp.offset = offset;
11014 
11015  uexp.length = ni_calculate_total_frame_size(p_ctx, linestride);
11016  uexp.domain = p_ctx->domain;
11017  uexp.bus = p_ctx->bus;
11018  uexp.dev = p_ctx->dev;
11019  uexp.fn = p_ctx->fn;
11020  uexp.bar = 4; // PCI BAR4 configuration space
11021 
11022  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
11023  if (ret < 0)
11024  {
11025  ni_log2(p_ctx, NI_LOG_ERROR, "%s: Failed to export dmabuf %d errno %d\n",
11026  __func__, ret, NI_ERRNO);
11027  return NI_RETCODE_FAILURE;
11028  }
11029 
11030  *p_surface = hwdesc;
11031  p_surface->ui16width = p_ctx->active_video_width;
11032  p_surface->ui16height = p_ctx->active_video_height;
11033  p_surface->ui32nodeAddress = offset;
11034  p_surface->encoding_type = is_semi_planar ?
11037  p_surface->dma_buf_fd = uexp.fd;
11038 
11039  return retval;
11040 }
11041 
11042 /*!*****************************************************************************
11043 * \brief Acquire a P2P frame buffer from the hwupload session for P2P read
11044 *
11045 * \param[in] p_ctx Pointer to a caller allocated
11046 * ni_session_context_t struct
11047 * \param[out] p_frame Pointer to a caller allocated hw frame
11048 *
11049 * \return On success
11050 * NI_RETCODE_SUCCESS
11051 * On failure
11052 * NI_RETCODE_INVALID_PARAM
11053 * NI_RETCODE_ERROR_NVME_CMD_FAILED
11054 * NI_RETCODE_ERROR_INVALID_SESSION
11055 *******************************************************************************/
11057 {
11059 
11060  int is_semi_planar;
11061  int linestride[NI_MAX_NUM_DATA_POINTERS];
11062  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
11063  niFrameSurface1_t hwdesc = {0};
11064  niFrameSurface1_t *p_surface;
11065 
11066  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
11067  {
11068  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
11069  __func__);
11070  return NI_RETCODE_INVALID_PARAM;
11071  }
11072 
11073  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11074 
11075  ni_pthread_mutex_lock(&p_ctx->mutex);
11077 
11078  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
11079 
11081  ni_pthread_mutex_unlock(&p_ctx->mutex);
11082 
11083  if (retval != NI_RETCODE_SUCCESS)
11084  {
11085  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
11086  return retval;
11087  }
11088 
11089  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
11090  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
11091  1 :
11092  0;
11093 
11095  p_ctx->bit_depth_factor, is_semi_planar, linestride,
11096  alignedheight);
11097 
11098  *p_surface = hwdesc;
11099  p_surface->ui16width = p_ctx->active_video_width;
11100  p_surface->ui16height = p_ctx->active_video_height;
11101  p_surface->ui32nodeAddress = 0;
11102  p_surface->encoding_type = is_semi_planar ?
11105  p_surface->dma_buf_fd = 0;
11106 
11107  return retval;
11108 }
11109 
11110 
11111 /*!*****************************************************************************
11112  * \brief Lock a hardware P2P frame prior to encoding
11113  *
11114  * \param[in] p_upl_ctx pointer to caller allocated upload context
11115  * [in] p_frame pointer to caller allocated hardware P2P frame
11116  *
11117  * \return On success
11118  * NI_RETCODE_SUCCESS
11119  * On failure NI_RETCODE_FAILURE
11120  * NI_RETCODE_INVALID_PARAM
11121 *******************************************************************************/
11123  ni_frame_t *p_frame)
11124 {
11125  int ret;
11126  struct netint_iocmd_attach_rfence uatch = {0};
11127  struct pollfd pfds[1] = {0};
11128  niFrameSurface1_t *p_surface;
11129 
11130  if (p_upl_ctx == NULL || p_frame == NULL)
11131  {
11132  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: bad parameters\n", __func__);
11133  return NI_RETCODE_INVALID_PARAM;
11134  }
11135 
11136  if (p_frame->p_data[3] == NULL)
11137  {
11138  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: not a hardware frame\n", __func__);
11139  return NI_RETCODE_INVALID_PARAM;
11140  }
11141 
11142  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11143 
11144  pfds[0].fd = p_surface->dma_buf_fd;
11145  pfds[0].events = POLLIN;
11146  pfds[0].revents = 0;
11147 
11148  ret = poll(pfds, 1, -1);
11149  char errmsg[NI_ERRNO_LEN] = {0};
11150  if (ret < 0)
11151  {
11152  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11153  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s:failed to poll dmabuf fd errno %s\n", __func__,
11154  errmsg);
11155  return ret;
11156  }
11157 
11158  uatch.fd = p_surface->dma_buf_fd;
11159  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ATTACH_RFENCE, &uatch);
11160  if (ret < 0)
11161  {
11162  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11163  ni_log2(p_upl_ctx, NI_LOG_ERROR,
11164  "%s: failed to attach dmabuf read fence errno %s\n", __func__,
11165  errmsg);
11166  return ret;
11167  }
11168 
11169  return NI_RETCODE_SUCCESS;
11170 }
11171 
11172 /*!*****************************************************************************
11173  * \brief Unlock a hardware P2P frame after encoding
11174  *
11175  * \param[in] p_upl_ctx pointer to caller allocated upload context
11176  * [in] p_frame pointer to caller allocated hardware P2P frame
11177  *
11178  * \return On success
11179  * NI_RETCODE_SUCCESS
11180  * On failure NI_RETCODE_FAILURE
11181  * NI_RETCODE_INVALID_PARAM
11182 *******************************************************************************/
11184  ni_frame_t *p_frame)
11185 {
11186  int ret;
11187  struct netint_iocmd_signal_rfence usigl = {0};
11188  niFrameSurface1_t *p_surface;
11189 
11190  if ((p_upl_ctx == NULL) || (p_frame == NULL))
11191  {
11192  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid parameters %p %p\n", __func__,
11193  p_upl_ctx, p_frame);
11194  return NI_RETCODE_INVALID_PARAM;
11195  }
11196 
11197  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11198 
11199  if (p_surface == NULL)
11200  {
11201  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
11202  return NI_RETCODE_INVALID_PARAM;
11203  }
11204 
11205  usigl.fd = p_surface->dma_buf_fd;
11206  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_SIGNAL_RFENCE, &usigl);
11207  if (ret < 0)
11208  {
11209  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Failed to signal dmabuf read fence\n");
11210  return NI_RETCODE_FAILURE;
11211  }
11212 
11213  return NI_RETCODE_SUCCESS;
11214 }
11215 
11216 /*!*****************************************************************************
11217  * \brief Special P2P test API function. Copies YUV data from the software
11218  * frame to the hardware P2P frame on the Quadra device
11219  *
11220  * \param[in] p_upl_ctx pointer to caller allocated uploader session
11221  * context
11222  * [in] p_swframe pointer to a caller allocated software frame
11223  * [in] p_hwframe pointer to a caller allocated hardware frame
11224  *
11225  * \return On success
11226  * NI_RETCODE_SUCCESS
11227  * On failure
11228  * NI_RETCODE_FAILURE
11229  * NI_RETCODE_INVALID_PARAM
11230 *******************************************************************************/
11232  uint8_t *p_data, uint32_t len,
11233  ni_frame_t *p_hwframe)
11234 {
11235  int ret;
11236  struct netint_iocmd_issue_request uis = {0};
11237  niFrameSurface1_t *p_surface;
11238 
11239  if (p_upl_ctx == NULL || p_data == NULL || p_hwframe == NULL)
11240  {
11241  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: invalid null parameters\n", __func__);
11242  return NI_RETCODE_INVALID_PARAM;
11243  }
11244 
11245  if (p_hwframe->p_data[3] == NULL)
11246  {
11247  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: empty frame\n", __func__);
11248  return NI_RETCODE_INVALID_PARAM;
11249  }
11250 
11251  p_surface = (niFrameSurface1_t *)p_hwframe->p_data[3];
11252 
11253  uis.fd = p_surface->dma_buf_fd;
11254  uis.data = p_data;
11255  uis.len = len;
11257 
11258  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ISSUE_REQ, &uis);
11259  if (ret < 0)
11260  {
11261  ni_log2(p_upl_ctx, NI_LOG_ERROR,
11262  "%s: Failed to request dmabuf rendering errno %d\n", __func__,
11263  NI_ERRNO);
11264  return NI_RETCODE_FAILURE;
11265  }
11266 
11267  return NI_RETCODE_SUCCESS;
11268 }
11269 
11270 /*!*****************************************************************************
11271  * \brief Special P2P test API function. Copies video data from the software
11272  * frame to the hardware P2P frame on the Quadra device. Does not
11273  * need the Netint kernel driver but requires root privilege.
11274  *
11275  * \param[in] p_upl_ctx pointer to caller allocated uploader session
11276  * context
11277  * [in] p_swframe pointer to a caller allocated software frame
11278  * [in] p_hwframe pointer to a caller allocated hardware frame
11279  *
11280  * \return On success
11281  * NI_RETCODE_SUCCESS
11282  * On failure
11283  * NI_RETCODE_FAILURE
11284  * NI_RETCODE_INVALID_PARAM
11285 *******************************************************************************/
11287  uint8_t *p_data, uint32_t len,
11288  ni_frame_t *p_hwframe)
11289 {
11290  int bar4_fd, ret;
11291  char bar4_name[128];
11292  char *bar4_mm;
11293  struct stat stat;
11294  niFrameSurface1_t *pSurf;
11295  uint32_t offset;
11296 
11297  pSurf = (niFrameSurface1_t *) p_hwframe->p_data[3];
11298 
11299  ret = ni_get_memory_offset(p_upl_ctx, pSurf, &offset);
11300  if (ret != 0)
11301  {
11302  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Error bad buffer id\n");
11303  return NI_RETCODE_FAILURE;
11304  }
11305 
11306  snprintf(bar4_name, 128,
11307  "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/resource4",
11308  p_upl_ctx->domain,p_upl_ctx->bus,p_upl_ctx->dev,p_upl_ctx->fn);
11309 
11310  bar4_fd = open(bar4_name, O_RDWR | O_SYNC);
11311 
11312  char errmsg[NI_ERRNO_LEN] = {0};
11313  if (bar4_fd < 0)
11314  {
11315  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11316  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't open bar4 %s (%s)\n",
11317  bar4_name, errmsg);
11318  return NI_RETCODE_FAILURE;
11319  }
11320 
11321  if (fstat(bar4_fd, &stat) != 0)
11322  {
11323  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11324  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't stat bar4 (%s)\n",
11325  errmsg);
11326  close(bar4_fd);
11327  return NI_RETCODE_FAILURE;
11328  }
11329 
11330  bar4_mm = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, bar4_fd, 0);
11331 
11332  if (bar4_mm == MAP_FAILED)
11333  {
11334  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11335  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't mmap to bar4 (%s)\n",
11336  errmsg);
11337  close(bar4_fd);
11338  return NI_RETCODE_FAILURE;
11339  }
11340 
11341  /* Copy the data directly into Quadra video memory */
11342  memcpy(bar4_mm + offset, p_data, len);
11343 
11344  munmap(bar4_mm, 0);
11345  close(bar4_fd);
11346 
11347  return NI_RETCODE_SUCCESS;
11348 }
11349 
11350 
11351 /*!*****************************************************************************
11352  * \brief Recycle hw P2P frames
11353  *
11354  * \param [in] p_frame pointer to an acquired P2P hw frame
11355  *
11356  * \return on success
11357  * NI_RETCODE_SUCCESS
11358  *
11359  * on failure
11360  * NI_RETCODE_INVALID_PARAM
11361 *******************************************************************************/
11363 {
11364  niFrameSurface1_t *p_surface;
11365 
11366  if (p_frame == NULL)
11367  {
11368  ni_log(NI_LOG_ERROR, "%s: Invalid frame\n", __func__);
11369  return NI_RETCODE_INVALID_PARAM;
11370  }
11371 
11372  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11373  if (p_surface == NULL)
11374  {
11375  ni_log(NI_LOG_ERROR, "%s: Invalid surface data\n", __func__);
11376  return NI_RETCODE_INVALID_PARAM;
11377  }
11378 
11379  return ni_hwframe_buffer_recycle2(p_surface);
11380 }
11381 
11382 /*!*****************************************************************************
11383  * \brief Acquire the scaler P2P DMA buffer for read/write
11384  *
11385  * \param [in] p_ctx pointer to caller allocated upload context
11386  * [in] p_surface pointer to a caller allocated hardware frame
11387  * [in] data_len scaler frame buffer data length
11388  *
11389  * \return on success
11390  * NI_RETCODE_SUCCESS
11391  *
11392  * on failure
11393  * NI_RETCODE_FAILURE
11394 *******************************************************************************/
11396  niFrameSurface1_t *p_surface,
11397  int data_len)
11398 {
11399  unsigned int offset;
11400  int ret;
11401 
11402  ret = ni_get_memory_offset(p_ctx, p_surface, &offset);
11403  if (ret != 0)
11404  {
11405  ni_log2(p_ctx, NI_LOG_ERROR, "Error: bad buffer id\n");
11406  return NI_RETCODE_FAILURE;
11407  }
11408  p_surface->ui32nodeAddress = 0;
11409 
11410  struct netint_iocmd_export_dmabuf uexp;
11411  uexp.fd = -1;
11412  uexp.flags = 0;
11413  uexp.offset = offset;
11414  uexp.length = data_len;
11415  uexp.domain = p_ctx->domain;
11416  uexp.bus = p_ctx->bus;
11417  uexp.dev = p_ctx->dev;
11418  uexp.fn = p_ctx->fn;
11419  uexp.bar = 4;
11420  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
11421  if (ret < 0)
11422  {
11423  char errmsg[NI_ERRNO_LEN] = {0};
11424  ni_strerror(errmsg, NI_ERRNO_LEN, NI_ERRNO);
11425  ni_log2(p_ctx, NI_LOG_ERROR, "failed to export dmabuf: %s\n", errmsg);
11426  return NI_RETCODE_FAILURE;
11427  }
11428  p_surface->dma_buf_fd = uexp.fd;
11429  return ret;
11430 }
11431 #endif
11432 
11433 /*!*****************************************************************************
11434  * \brief Set the incoming frame format for the encoder
11435  *
11436  * \param[in] p_enc_ctx pointer to encoder context
11437  * [in] p_enc_params pointer to encoder parameters
11438  * [in] width input width
11439  * [in] height input height
11440  * [in] bit_depth 8 for 8-bit YUV, 10 for 10-bit YUV
11441  * [in] src_endian NI_FRAME_LITTLE_ENDIAN or NI_FRAME_BIG_ENDIAN
11442  * [in] planar 0 for semi-planar YUV, 1 for planar YUV
11443  *
11444  * \return on success
11445  * NI_RETCODE_SUCCESS
11446  *
11447  * on failure
11448  * NI_RETCODE_INVALID_PARAM
11449  *
11450 *******************************************************************************/
11452  ni_xcoder_params_t *p_enc_params,
11453  int width, int height,
11454  int bit_depth, int src_endian,
11455  int planar)
11456 {
11457  int alignedw;
11458  int alignedh;
11459 
11460  if (p_enc_ctx == NULL || p_enc_params == NULL)
11461  {
11462  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11463  return NI_RETCODE_INVALID_PARAM;
11464  }
11465 
11466  if (!(bit_depth == 8) && !(bit_depth == 10))
11467  {
11468  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad bit depth %d\n", __func__, bit_depth);
11469  return NI_RETCODE_INVALID_PARAM;
11470  }
11471 
11472  if (!(src_endian == NI_FRAME_LITTLE_ENDIAN) &&
11473  !(src_endian == NI_FRAME_BIG_ENDIAN))
11474  {
11475  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad endian %d\n", __func__, src_endian);
11476  return NI_RETCODE_INVALID_PARAM;
11477  }
11478 
11479  if ((planar < 0) || (planar >= NI_PIXEL_PLANAR_MAX))
11480  {
11481  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad planar value %d\n", __func__, planar);
11482  return NI_RETCODE_INVALID_PARAM;
11483  }
11484 
11485  p_enc_ctx->src_bit_depth = bit_depth;
11486  p_enc_ctx->bit_depth_factor = (bit_depth == 8) ? 1 : 2;
11487  p_enc_ctx->src_endian = src_endian;
11488 
11489  alignedw = width;
11490 
11491  if (alignedw < NI_MIN_WIDTH)
11492  {
11493  p_enc_params->cfg_enc_params.conf_win_right +=
11494  (NI_MIN_WIDTH - width) / 2 * 2;
11495  alignedw = NI_MIN_WIDTH;
11496  } else
11497  {
11498  alignedw = ((width + 1) / 2) * 2;
11499  p_enc_params->cfg_enc_params.conf_win_right +=
11500  (alignedw - width) / 2 * 2;
11501  }
11502 
11503  p_enc_params->source_width = alignedw;
11504  alignedh = height;
11505 
11506  if (alignedh < NI_MIN_HEIGHT)
11507  {
11508  p_enc_params->cfg_enc_params.conf_win_bottom +=
11509  (NI_MIN_HEIGHT - height) / 2 * 2;
11510  alignedh = NI_MIN_HEIGHT;
11511  } else
11512  {
11513  alignedh = ((height + 1) / 2) * 2;
11514  p_enc_params->cfg_enc_params.conf_win_bottom +=
11515  (alignedh - height) / 2 * 2;
11516  }
11517 
11518  p_enc_params->source_height = alignedh;
11519  p_enc_params->cfg_enc_params.planar = planar;
11520 
11521  return NI_RETCODE_SUCCESS;
11522 }
11523 
11524 /*!*****************************************************************************
11525  * \brief Set the outgoing frame format for the uploader
11526  *
11527  * \param[in] p_upl_ctx pointer to uploader context
11528  * [in] width width
11529  * [in] height height
11530  * [in] pixel_format pixel format
11531  * [in] isP2P 0 = normal, 1 = P2P
11532  *
11533  * \return on success
11534  * NI_RETCODE_SUCCESS
11535  *
11536  * on failure
11537  * NI_RETCODE_INVALID_PARAM
11538 *******************************************************************************/
11540  int width, int height,
11541  ni_pix_fmt_t pixel_format, int isP2P)
11542 {
11543  if (p_upl_ctx == NULL)
11544  {
11545  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11546  return NI_RETCODE_INVALID_PARAM;
11547  }
11548 
11549  switch (pixel_format)
11550  {
11551  case NI_PIX_FMT_YUV420P:
11552  case NI_PIX_FMT_NV12:
11553  p_upl_ctx->src_bit_depth = 8;
11554  p_upl_ctx->bit_depth_factor = 1;
11555  break;
11557  case NI_PIX_FMT_P010LE:
11558  p_upl_ctx->src_bit_depth = 10;
11559  p_upl_ctx->bit_depth_factor = 2;
11560  break;
11561  case NI_PIX_FMT_RGBA:
11562  case NI_PIX_FMT_BGRA:
11563  case NI_PIX_FMT_ARGB:
11564  case NI_PIX_FMT_ABGR:
11565  case NI_PIX_FMT_BGR0:
11566  case NI_PIX_FMT_BGRP:
11567  p_upl_ctx->src_bit_depth = 8;
11568  p_upl_ctx->bit_depth_factor = 4;
11569  break;
11570  default:
11571  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid pixfmt %d\n", __func__,
11572  pixel_format);
11573  return NI_RETCODE_INVALID_PARAM;
11574  }
11575 
11576  p_upl_ctx->src_endian = NI_FRAME_LITTLE_ENDIAN;
11577  p_upl_ctx->pixel_format = pixel_format;
11578  p_upl_ctx->active_video_width = width;
11579  p_upl_ctx->active_video_height = height;
11580  p_upl_ctx->isP2P = isP2P;
11581 
11582  return NI_RETCODE_SUCCESS;
11583 }
11584 
11585 /*!*****************************************************************************
11586  * \brief Read encoder stream header from the device
11587  *
11588  * \param[in] p_ctx Pointer to a caller allocated
11589  * ni_session_context_t struct from encoder
11590  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
11591  * struct which contains a ni_packet_t data packet to
11592  * receive
11593  * \return On success
11594  * Total number of bytes read
11595  * On failure
11596  * NI_RETCODE_INVALID_PARAM
11597  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11598  * NI_RETCODE_ERROR_INVALID_SESSION
11599 *******************************************************************************/
11601  ni_session_data_io_t *p_data)
11602 {
11603  int rx_size;
11604  int done = 0;
11605  int bytes_read = 0;
11606 
11607  /* This function should be called once at the start of encoder read */
11608  if (p_ctx->pkt_num != 0)
11609  {
11610  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11612  }
11613 
11614  while (!done)
11615  {
11616  rx_size = ni_device_session_read(p_ctx, p_data, NI_DEVICE_TYPE_ENCODER);
11617 
11618  if (rx_size > (int)p_ctx->meta_size)
11619  {
11620  /* stream header has been read, return size */
11621  bytes_read += (rx_size - (int)p_ctx->meta_size);
11622 
11623  p_ctx->pkt_num = 1;
11624  ni_log2(p_ctx, NI_LOG_DEBUG, "Got encoded stream header\n");
11625  done = 1;
11626  } else if (rx_size != 0)
11627  {
11628  ni_log2(p_ctx, NI_LOG_ERROR, "Error: received rx_size = %d\n", rx_size);
11629  bytes_read = -1;
11630  done = 1;
11631  } else
11632  {
11633  ni_log2(p_ctx, NI_LOG_DEBUG, "No data, keep reading..\n");
11634  continue;
11635  }
11636  }
11637 
11638  return bytes_read;
11639 }
11640 
11641 /*!*****************************************************************************
11642  * \brief Get the DMA buffer file descriptor from the P2P frame
11643  *
11644  * \param[in] p_frame pointer to a P2P frame
11645  *
11646  * \return On success
11647  * DMA buffer file descriptor
11648  * On failure
11649  * NI_RETCODE_INVALID_PARAM
11650 *******************************************************************************/
11652 {
11653  const niFrameSurface1_t *p_surface;
11654 
11655  if (p_frame == NULL)
11656  {
11657  ni_log(NI_LOG_ERROR, "%s: NULL frame\n", __func__);
11658  return NI_RETCODE_INVALID_PARAM;
11659  }
11660 
11661  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11662 
11663  if (p_surface == NULL)
11664  {
11665  ni_log(NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
11666  return NI_RETCODE_INVALID_PARAM;
11667  }
11668 
11669  return p_surface->dma_buf_fd;
11670 }
11671 
11672 /*!*****************************************************************************
11673  * \brief Send sequence change information to device
11674  *
11675  * \param[in] p_ctx Pointer to a caller allocated
11676  * ni_session_context_t struct
11677  * \param[in] width input width
11678  * \param[in] height input height
11679  * \param[in] bit_depth_factor 1 for 8-bit YUV, 2 for 10-bit YUV
11680  * \param[in] device_type device type (must be encoder)
11681  * \return On success
11682  * NI_RETCODE_SUCCESS
11683  * On failure
11684  * NI_RETCODE_INVALID_PARAM
11685  * NI_RETCODE_ERROR_MEM_ALOC
11686  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11687  * NI_RETCODE_ERROR_INVALID_SESSION
11688  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
11689  ******************************************************************************/
11691  int width, int height, int bit_depth_factor, ni_device_type_t device_type)
11692 {
11693  ni_resolution_t resolution;
11695  ni_xcoder_params_t *p_param = NULL;
11696 
11697  // requires API version >= 54
11699  "54") < 0)
11700  {
11701  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
11703  }
11704 
11705  /* This function should be called only if sequence change is detected */
11707  {
11708  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11710  }
11711 
11712  resolution.width = width;
11713  resolution.height = height;
11714  resolution.bit_depth_factor = bit_depth_factor;
11715  resolution.luma_linesize = 0;
11716  resolution.chroma_linesize = 0;
11717  if (p_ctx->p_session_config)
11718  {
11719  ni_encoder_cfg_params_t *p_enc;
11720  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
11721  p_enc = &p_param->cfg_enc_params;
11722  if (p_enc->spatial_layers > 1)
11723  {
11724  retval = NI_RETCODE_INVALID_PARAM;
11725  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported when spatialLayers > 1\n");
11726  return retval;
11727  }
11728  resolution.luma_linesize = p_param->luma_linesize;
11729  resolution.chroma_linesize = p_param->chroma_linesize;
11730  }
11731  else
11732  {
11734  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: invalid p_session_config\n");
11735  return retval;
11736  }
11737 
11738  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: resolution change config - width %d height %d bit_depth_factor %d "
11739  "luma_linesize %d chroma_linesize %d\n", __func__,
11740  resolution.width, resolution.height, resolution.bit_depth_factor,
11741  resolution.luma_linesize, resolution.chroma_linesize);
11742 
11743  switch (device_type)
11744  {
11746  {
11747  // config sequence change
11748  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
11749  break;
11750  }
11751  default:
11752  {
11753  retval = NI_RETCODE_INVALID_PARAM;
11754  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported for device type: %d", device_type);
11755  return retval;
11756  }
11757  }
11758  return retval;
11759 }
11760 
11762  ni_network_perf_metrics_t *p_metrics)
11763 {
11764  return ni_ai_session_query_metrics(p_ctx, p_metrics);
11765 }
11766 
11767 ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle,
11768  ni_device_info_t *p_dev_info)
11769 {
11770  void *buffer;
11771  uint32_t size;
11772  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11773  ni_log_fl_fw_versions_t fl_fw_versions;
11774 
11775  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_info))
11776  {
11777  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11778  __func__);
11779  return NI_RETCODE_INVALID_PARAM;
11780  }
11781 
11783  "6h") < 0)
11784  {
11786  "ERROR: %s function not supported on device with FW API version < 6.h\n",
11787  __func__);
11789  }
11790 
11791  buffer = NULL;
11793 
11794  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11795  {
11796  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11798  }
11799 
11800  memset(buffer, 0, size);
11801 
11802  if (ni_nvme_send_read_cmd(device_handle,
11803  event_handle,
11804  buffer,
11805  size,
11806  QUERY_GET_VERSIONS_R) < 0)
11807  {
11808  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11809  ni_aligned_free(buffer);
11811  }
11812 
11813  memcpy(&fl_fw_versions, buffer, sizeof(ni_log_fl_fw_versions_t));
11814 
11815  memcpy(p_dev_info->fl_ver_last_ran,
11816  &fl_fw_versions.last_ran_fl_version,
11818  memcpy(p_dev_info->fl_ver_nor_flash,
11819  &fl_fw_versions.nor_flash_fl_version,
11821  memcpy(p_dev_info->fw_rev_nor_flash,
11822  &fl_fw_versions.nor_flash_fw_revision,
11824 
11825  ni_aligned_free(buffer);
11826  return NI_RETCODE_SUCCESS;
11827 }
11828 
11830  ni_load_query_t *p_load_query)
11831 {
11832  void *buffer;
11833  uint32_t size;
11834 
11835  ni_instance_mgr_general_status_t general_status;
11836 
11837  if (!p_ctx)
11838  {
11839  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_ctx cannot be null\n");
11840  return NI_RETCODE_INVALID_PARAM;
11841  }
11842  if (!p_load_query)
11843  {
11844  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_load_query cannot be null\n");
11845  return NI_RETCODE_INVALID_PARAM;
11846  }
11847 
11849  "6O") < 0)
11850  {
11851  ni_log2(p_ctx, NI_LOG_ERROR,
11852  "ERROR: %s function not supported on device with FW API version < 6.O\n",
11853  __func__);
11855  }
11856 
11857  buffer = NULL;
11859 
11860  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11861  {
11862  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11864  }
11865 
11866  memset(buffer, 0, size);
11867 
11869  p_ctx->event_handle,
11870  buffer,
11871  size,
11873  {
11874  ni_log2(p_ctx, NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11875  ni_aligned_free(buffer);
11877  }
11878 
11879  memcpy(&general_status, buffer, sizeof(ni_instance_mgr_general_status_t));
11880 
11881  p_load_query->tp_fw_load = general_status.tp_fw_load;
11882  p_load_query->pcie_load = general_status.pcie_load;
11883  p_load_query->pcie_throughput = general_status.pcie_throughput;
11884  p_load_query->fw_load = general_status.fw_load;
11885  p_load_query->fw_share_mem_usage = general_status.fw_share_mem_usage;
11886 
11887  ni_aligned_free(buffer);
11888  return NI_RETCODE_SUCCESS;
11889 }
11890 
11891 ni_retcode_t ni_query_vf_ns_id(ni_device_handle_t device_handle,
11892  ni_device_vf_ns_id_t *p_dev_ns_vf,
11893  uint8_t fw_rev[])
11894 {
11895  void *p_buffer = NULL;
11896  uint32_t size;
11897  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11898 
11899  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_ns_vf))
11900  {
11901  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11902  __func__);
11903  return NI_RETCODE_INVALID_PARAM;
11904  }
11905 
11907  "6m") < 0)
11908  {
11910  "ERROR: %s function not supported on device with FW API version < 6.m\n",
11911  __func__);
11913  }
11914 
11916 
11917  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11918  {
11919  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11921  }
11922 
11923  memset(p_buffer, 0, size);
11924 
11925  if (ni_nvme_send_read_cmd(device_handle,
11926  event_handle,
11927  p_buffer,
11928  size,
11929  QUERY_GET_NS_VF_R) < 0)
11930  {
11931  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11932  ni_aligned_free(p_buffer);
11934  }
11935 
11936  ni_device_vf_ns_id_t *p_dev_ns_vf_data = (ni_device_vf_ns_id_t *)p_buffer;
11937  p_dev_ns_vf->vf_id = p_dev_ns_vf_data->vf_id;
11938  p_dev_ns_vf->ns_id = p_dev_ns_vf_data->ns_id;
11939  ni_log(NI_LOG_DEBUG, "%s(): NS/VF %u/%u\n", __func__, p_dev_ns_vf->ns_id, p_dev_ns_vf->vf_id);
11940  ni_aligned_free(p_buffer);
11941  return NI_RETCODE_SUCCESS;
11942 }
11943 
11944 ni_retcode_t ni_query_temperature(ni_device_handle_t device_handle,
11945  ni_device_temp_t *p_dev_temp,
11946  uint8_t fw_rev[])
11947 {
11948  void *p_buffer = NULL;
11949  uint32_t size;
11950  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11951 
11952  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_temp))
11953  {
11954  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11955  __func__);
11956  return NI_RETCODE_INVALID_PARAM;
11957  }
11958 
11960  "6rC") < 0)
11961  {
11963  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11964  __func__);
11966  }
11967 
11969 
11970  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11971  {
11972  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11974  }
11975 
11976  memset(p_buffer, 0, size);
11977 
11978  if (ni_nvme_send_read_cmd(device_handle,
11979  event_handle,
11980  p_buffer,
11981  size,
11983  {
11984  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11985  ni_aligned_free(p_buffer);
11987  }
11988 
11989  ni_device_temp_t *p_dev_temp_data = (ni_device_temp_t *)p_buffer;
11990  p_dev_temp->composite_temp = p_dev_temp_data->composite_temp;
11991  p_dev_temp->on_board_temp = p_dev_temp_data->on_board_temp;
11992  p_dev_temp->on_die_temp = p_dev_temp_data->on_die_temp;
11993  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d on die temperature %d\n",
11994  __func__, p_dev_temp->composite_temp, p_dev_temp->on_board_temp, p_dev_temp->on_die_temp);
11995  ni_aligned_free(p_buffer);
11996  return NI_RETCODE_SUCCESS;
11997 }
11998 
11999 ni_retcode_t ni_query_extra_info(ni_device_handle_t device_handle,
12000  ni_device_extra_info_t *p_dev_extra_info,
12001  uint8_t fw_rev[])
12002 {
12003  void *p_buffer = NULL;
12004  uint32_t size;
12005  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
12006 
12007  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_extra_info))
12008  {
12009  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
12010  __func__);
12011  return NI_RETCODE_INVALID_PARAM;
12012  }
12013 
12015  "6rC") < 0)
12016  {
12018  "ERROR: %s function not supported on device with FW API version < 6rC\n",
12019  __func__);
12021  }
12022 
12024 
12025  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
12026  {
12027  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
12029  }
12030 
12031  memset(p_buffer, 0, size);
12032 
12033  if (ni_nvme_send_read_cmd(device_handle,
12034  event_handle,
12035  p_buffer,
12036  size,
12038  {
12039  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
12040  ni_aligned_free(p_buffer);
12042  }
12043 
12044  ni_device_extra_info_t *p_dev_extra_info_data = (ni_device_extra_info_t *)p_buffer;
12045  p_dev_extra_info->composite_temp = p_dev_extra_info_data->composite_temp;
12046  p_dev_extra_info->on_board_temp = p_dev_extra_info_data->on_board_temp;
12047  p_dev_extra_info->on_die_temp = p_dev_extra_info_data->on_die_temp;
12048  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6sN") >= 0)
12049  {
12050  p_dev_extra_info->fw_flavour = p_dev_extra_info_data->fw_flavour;
12051  }
12052  else
12053  {
12054  p_dev_extra_info->fw_flavour = (uint8_t)'-';
12055  }
12056  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rC") >= 0 &&
12057  ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rR") < 0)
12058  {
12059  p_dev_extra_info->power_consumption = NI_INVALID_POWER;
12060  }
12061  else
12062  {
12063  p_dev_extra_info->power_consumption = p_dev_extra_info_data->power_consumption;
12064  }
12065  //QUADPV-1210-Remove ADC current measurement decoding from FW
12066  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6s4") >=0)
12067  {
12068  p_dev_extra_info->current_consumption = p_dev_extra_info_data->current_consumption;
12069  ni_device_capability_t device_capability = {0};
12070  if (ni_device_capability_query2(device_handle, &device_capability, false) != NI_RETCODE_SUCCESS)
12071  {
12072  ni_log(NI_LOG_ERROR, "ERROR: unable to query capability\n");
12074  }
12075  p_dev_extra_info->power_consumption = ni_decode_power_measurement(p_dev_extra_info->current_consumption, device_capability.serial_number);
12076  }
12077  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d "
12078  "on die temperature %d power consumption %d current consumption %d\n",
12079  __func__, p_dev_extra_info->composite_temp, p_dev_extra_info->on_board_temp,
12080  p_dev_extra_info->on_die_temp, p_dev_extra_info->power_consumption, p_dev_extra_info->current_consumption);
12081  ni_aligned_free(p_buffer);
12082  return NI_RETCODE_SUCCESS;
12083 }
12084 
12085 /*!*****************************************************************************
12086  * \brief Allocate log buffer if needed and retrieve firmware logs from device
12087  *
12088  * \param[in] p_ctx Pointer to a caller allocated
12089  * ni_session_context_t struct
12090  * \param[in] p_log_buffer Reference to pointer to a log buffer
12091  * If log buffer pointer is NULL, this function will allocate log buffer
12092  * NOTE caller is responsible for freeing log buffer after calling this function
12093  * \param[in] gen_log_file Indicating whether it is required to generate log files
12094  *
12095  *
12096  * \return on success
12097  * NI_RETCODE_SUCCESS
12098  *
12099  * on failure
12100  * NI_RETCODE_ERROR_MEM_ALOC
12101  * NI_RETCODE_INVALID_PARAM
12102 *******************************************************************************/
12103 ni_retcode_t ni_device_alloc_and_get_firmware_logs(ni_session_context_t *p_ctx, void** p_log_buffer, bool gen_log_file)
12104 {
12106  bool is_ext_buf = true;
12107  if (*p_log_buffer == NULL)
12108  {
12109  if (ni_posix_memalign(p_log_buffer, sysconf(_SC_PAGESIZE), TOTAL_CPU_LOG_BUFFER_SIZE))
12110  {
12111  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate log buffer\n",
12112  NI_ERRNO, __func__);
12114  }
12115  is_ext_buf = false;
12116  }
12117 
12118  if(*p_log_buffer != NULL){
12119  memset(*p_log_buffer, 0, TOTAL_CPU_LOG_BUFFER_SIZE);
12120  retval = ni_dump_log_all_cores(p_ctx, *p_log_buffer, gen_log_file); // dump FW logs
12121  if(!is_ext_buf)
12122  ni_aligned_free(*p_log_buffer);
12123  }else{
12125  }
12126 
12127  return retval;
12128 }
12129 
12130 /*!*****************************************************************************
12131  * \brief Set up hard coded demo ROI map
12132  *
12133  * \param[in] p_enc_ctx Pointer to a caller allocated
12134  *
12135  * \return on success
12136  * NI_RETCODE_SUCCESS
12137  *
12138  * on failure
12139  * NI_RETCODE_ERROR_MEM_ALOC
12140 *******************************************************************************/
12142 {
12143  ni_xcoder_params_t *p_param =
12144  (ni_xcoder_params_t *)(p_enc_ctx->p_session_config);
12145  int sumQp = 0;
12146  uint32_t ctu, i, j;
12147  // mode 1: Set QP for center 1/3 of picture to highest - lowest quality
12148  // the rest to lowest - highest quality;
12149  // mode non-1: reverse of mode 1
12150  int importanceLevelCentre = p_param->roi_demo_mode == 1 ? 40 : 10;
12151  int importanceLevelRest = p_param->roi_demo_mode == 1 ? 10 : 40;
12152  int linesize_aligned = p_param->source_width;
12153  int height_aligned = p_param->source_height;
12154  if (QUADRA)
12155  {
12156  uint32_t block_size, max_cu_size, customMapSize;
12157  uint32_t mbWidth;
12158  uint32_t mbHeight;
12159  uint32_t numMbs;
12160  uint32_t roiMapBlockUnitSize;
12161  uint32_t entryPerMb;
12162 
12163  max_cu_size = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16: 64;
12164  // AV1 non-8x8-aligned resolution is implicitly cropped due to Quadra HW limitation
12165  if (NI_CODEC_FORMAT_AV1 == p_enc_ctx->codec_format)
12166  {
12167  linesize_aligned = (linesize_aligned / 8) * 8;
12168  height_aligned = (height_aligned / 8) * 8;
12169  }
12170 
12171  // (ROI map version >= 1) each QP info takes 8-bit, represent 8 x 8
12172  // pixel block
12173  block_size =
12174  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) *
12175  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
12176  (8 * 8);
12177 
12178  // need to align to 64 bytes
12179  customMapSize = ((block_size + 63) & (~63));
12180  if (!p_enc_ctx->roi_map)
12181  {
12182  p_enc_ctx->roi_map =
12183  (ni_enc_quad_roi_custom_map *)calloc(1, customMapSize);
12184  }
12185  if (!p_enc_ctx->roi_map)
12186  {
12188  }
12189 
12190  // for H.264, select ROI Map Block Unit Size: 16x16
12191  // for H.265, select ROI Map Block Unit Size: 64x64
12192  roiMapBlockUnitSize = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16 : 64;
12193 
12194  mbWidth =
12195  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
12196  roiMapBlockUnitSize;
12197  mbHeight =
12198  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
12199  roiMapBlockUnitSize;
12200  numMbs = mbWidth * mbHeight;
12201 
12202  // copy roi MBs QPs into custom map
12203  // number of qp info (8x8) per mb or ctb
12204  entryPerMb = (roiMapBlockUnitSize / 8) * (roiMapBlockUnitSize / 8);
12205 
12206  for (i = 0; i < numMbs; i++)
12207  {
12208  bool bIsCenter = (i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3);
12209  for (j = 0; j < entryPerMb; j++)
12210  {
12211  /*
12212  g_quad_roi_map[i*4+j].field.skip_flag = 0; // don't force
12213  skip mode g_quad_roi_map[i*4+j].field.roiAbsQp_flag = 1; //
12214  absolute QP g_quad_roi_map[i*4+j].field.qp_info = bIsCenter
12215  ? importanceLevelCentre : importanceLevelRest;
12216  */
12217  p_enc_ctx->roi_map[i * entryPerMb + j].field.ipcm_flag =
12218  0; // don't force skip mode
12219  p_enc_ctx->roi_map[i * entryPerMb + j]
12220  .field.roiAbsQp_flag = 1; // absolute QP
12221  p_enc_ctx->roi_map[i * entryPerMb + j].field.qp_info =
12222  bIsCenter ? importanceLevelCentre : importanceLevelRest;
12223  }
12224  sumQp += p_enc_ctx->roi_map[i * entryPerMb].field.qp_info;
12225  }
12226  p_enc_ctx->roi_len = customMapSize;
12227  p_enc_ctx->roi_avg_qp =
12228  // NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
12229  (sumQp + (numMbs >> 1)) / numMbs; // round off
12230  }
12231  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264)
12232  {
12233  // roi for H.264 is specified for 16x16 pixel macroblocks - 1 MB
12234  // is stored in each custom map entry
12235 
12236  // number of MBs in each row
12237  uint32_t mbWidth = (linesize_aligned + 16 - 1) >> 4;
12238  // number of MBs in each column
12239  uint32_t mbHeight = (height_aligned + 16 - 1) >> 4;
12240  uint32_t numMbs = mbWidth * mbHeight;
12241  uint32_t customMapSize =
12242  sizeof(ni_enc_avc_roi_custom_map_t) * numMbs;
12243  p_enc_ctx->avc_roi_map =
12244  (ni_enc_avc_roi_custom_map_t *)calloc(1, customMapSize);
12245  if (!p_enc_ctx->avc_roi_map)
12246  {
12248  }
12249 
12250  // copy roi MBs QPs into custom map
12251  for (i = 0; i < numMbs; i++)
12252  {
12253  if ((i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3))
12254  {
12255  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelCentre;
12256  }
12257  else
12258  {
12259  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelRest;
12260  }
12261  sumQp += p_enc_ctx->avc_roi_map[i].field.mb_qp;
12262  }
12263  p_enc_ctx->roi_len = customMapSize;
12264  p_enc_ctx->roi_avg_qp =
12265  (sumQp + (numMbs >> 1)) / numMbs; // round off
12266  }
12267  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H265)
12268  {
12269  // roi for H.265 is specified for 32x32 pixel subCTU blocks - 4
12270  // subCTU QPs are stored in each custom CTU map entry
12271 
12272  // number of CTUs in each row
12273  uint32_t ctuWidth = (linesize_aligned + 64 - 1) >> 6;
12274  // number of CTUs in each column
12275  uint32_t ctuHeight = (height_aligned + 64 - 1) >> 6;
12276  // number of sub CTUs in each row
12277  uint32_t subCtuWidth = ctuWidth * 2;
12278  // number of CTUs in each column
12279  uint32_t subCtuHeight = ctuHeight * 2;
12280  uint32_t numSubCtus = subCtuWidth * subCtuHeight;
12281 
12282  p_enc_ctx->hevc_sub_ctu_roi_buf = (uint8_t *)malloc(numSubCtus);
12283  if (!p_enc_ctx->hevc_sub_ctu_roi_buf)
12284  {
12286  }
12287  for (i = 0; i < numSubCtus; i++)
12288  {
12289  if ((i % subCtuWidth > subCtuWidth / 3) &&
12290  (i % subCtuWidth < subCtuWidth * 2 / 3))
12291  {
12292  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelCentre;
12293  }
12294  else
12295  {
12296  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelRest;
12297  }
12298  }
12299  p_enc_ctx->hevc_roi_map = (ni_enc_hevc_roi_custom_map_t *)calloc(
12300  1, sizeof(ni_enc_hevc_roi_custom_map_t) * ctuWidth * ctuHeight);
12301  if (!p_enc_ctx->hevc_roi_map)
12302  {
12304  }
12305 
12306  for (i = 0; i < ctuHeight; i++)
12307  {
12308  uint8_t *ptr = &p_enc_ctx->hevc_sub_ctu_roi_buf[subCtuWidth * i * 2];
12309  for (j = 0; j < ctuWidth; j++, ptr += 2)
12310  {
12311  ctu = (i * ctuWidth + j);
12312  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 = *ptr;
12313  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 = *(ptr + 1);
12314  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 =
12315  *(ptr + subCtuWidth);
12316  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3 =
12317  *(ptr + subCtuWidth + 1);
12318  sumQp += (p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 +
12319  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 +
12320  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 +
12321  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3);
12322  }
12323  }
12324  p_enc_ctx->roi_len =
12325  ctuWidth * ctuHeight * sizeof(ni_enc_hevc_roi_custom_map_t);
12326  p_enc_ctx->roi_avg_qp =
12327  (sumQp + (numSubCtus >> 1)) / numSubCtus; // round off.
12328  }
12329  return NI_RETCODE_SUCCESS;
12330 }
12331 
12333 {
12334  // for encoder reconfiguration testing
12335  // reset encoder change data buffer for reconf parameters
12336  ni_retcode_t retval = 0;
12337  ni_xcoder_params_t *p_param =
12338  (ni_xcoder_params_t *)p_enc_ctx->p_session_config;
12339  ni_aux_data_t *aux_data = NULL;
12340  if (p_param->reconf_demo_mode > XCODER_TEST_RECONF_OFF &&
12342  {
12343  memset(p_enc_ctx->enc_change_params, 0, sizeof(ni_encoder_change_params_t));
12344  }
12345 
12346  switch (p_param->reconf_demo_mode) {
12347  case XCODER_TEST_RECONF_BR:
12348  if (p_enc_ctx->frame_num ==
12349  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12350  {
12351  aux_data = ni_frame_new_aux_data(
12352  p_frame, NI_FRAME_AUX_DATA_BITRATE, sizeof(int32_t));
12353  if (!aux_data)
12354  {
12356  }
12357  *((int32_t *)aux_data->data) =
12358  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12359 
12360  p_enc_ctx->reconfigCount++;
12361  if (p_param->cfg_enc_params.hrdEnable)
12362  {
12363  p_frame->force_key_frame = 1;
12364  p_frame->ni_pict_type = PIC_TYPE_IDR;
12365  }
12366  }
12367  break;
12368  // reconfig intraperiod param
12370  if (p_enc_ctx->frame_num ==
12371  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12372  {
12373  aux_data = ni_frame_new_aux_data(
12374  p_frame, NI_FRAME_AUX_DATA_INTRAPRD, sizeof(int32_t));
12375  if (!aux_data)
12376  {
12378  }
12379  int32_t intraprd = *((int32_t *)aux_data->data) =
12380  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12381  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12382  "xcoder_send_frame: frame #%lu reconf "
12383  "intraPeriod %d\n",
12384  p_enc_ctx->frame_num,
12385  intraprd);
12386  p_enc_ctx->reconfigCount++;
12387  }
12388  break;
12389  // reconfig VUI parameters
12391  if (p_enc_ctx->frame_num ==
12392  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12393  {
12394  aux_data = ni_frame_new_aux_data(p_frame,
12396  sizeof(ni_vui_hrd_t));
12397  if (!aux_data)
12398  {
12400  }
12401  ni_vui_hrd_t *vui = (ni_vui_hrd_t *)aux_data->data;
12402  vui->colorDescPresent =
12403  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12404  vui->colorPrimaries =
12405  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12406  vui->colorTrc =
12407  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12408  vui->colorSpace =
12409  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12410  vui->aspectRatioWidth =
12411  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12412  vui->aspectRatioHeight =
12413  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12414  vui->videoFullRange =
12415  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12416  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12417  "xcoder_send_frame: frame #%lu reconf "
12418  "vui colorDescPresent %d colorPrimaries %d "
12419  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12420  "aspectRatioHeight %d videoFullRange %d\n",
12421  p_enc_ctx->frame_num, vui->colorDescPresent,
12422  vui->colorPrimaries, vui->colorTrc,
12423  vui->colorSpace, vui->aspectRatioWidth,
12424  vui->aspectRatioHeight, vui->videoFullRange);
12425 
12426  p_enc_ctx->reconfigCount++;
12427  }
12428  break;
12429  // long term ref
12431  // the reconf file data line format for this is:
12432  // <frame-number>:useCurSrcAsLongtermPic,useLongtermRef where
12433  // values will stay the same on every frame until changed.
12434  if (p_enc_ctx->frame_num ==
12435  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12436  {
12437  ni_long_term_ref_t *p_ltr;
12438  aux_data = ni_frame_new_aux_data(
12440  sizeof(ni_long_term_ref_t));
12441  if (!aux_data)
12442  {
12444  }
12445  p_ltr = (ni_long_term_ref_t *)aux_data->data;
12447  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12448  p_ltr->use_long_term_ref =
12449  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12450  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12451  "xcoder_send_frame: frame #%lu metadata "
12452  "use_cur_src_as_long_term_pic %d use_long_term_ref "
12453  "%d\n",
12454  p_enc_ctx->frame_num,
12456  p_ltr->use_long_term_ref);
12457  p_enc_ctx->reconfigCount++;
12458  }
12459  break;
12460  // reconfig min / max QP
12463  if (p_enc_ctx->frame_num ==
12464  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12465  aux_data = ni_frame_new_aux_data(
12467  if (!aux_data) {
12469  }
12470 
12471  ni_rc_min_max_qp *qp_info = (ni_rc_min_max_qp *)aux_data->data;
12472  qp_info->minQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12473  qp_info->maxQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12474  qp_info->maxDeltaQp = p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12475  qp_info->minQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12476  qp_info->maxQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12477 
12478  p_enc_ctx->reconfigCount++;
12479  }
12480  break;
12481 #ifdef QUADRA
12482  // reconfig LTR interval
12484  if (p_enc_ctx->frame_num ==
12485  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12486  aux_data = ni_frame_new_aux_data(p_frame,
12488  sizeof(int32_t));
12489  if (!aux_data) {
12491  }
12492  *((int32_t *)aux_data->data) =
12493  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12494  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12495  "xcoder_send_frame: frame #%lu reconf "
12496  "ltrInterval %d\n",
12497  p_enc_ctx->frame_num,
12498  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12499 
12500  p_enc_ctx->reconfigCount++;
12501  }
12502  break;
12503  // invalidate reference frames
12505  if (p_enc_ctx->frame_num ==
12506  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12507  aux_data = ni_frame_new_aux_data(
12509  sizeof(int32_t));
12510  if (!aux_data) {
12512  }
12513  *((int32_t *)aux_data->data) =
12514  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12515  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12516  "xcoder_send_frame: frame #%lu reconf "
12517  "invalidFrameNum %d\n",
12518  p_enc_ctx->frame_num,
12519  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12520 
12521  p_enc_ctx->reconfigCount++;
12522  }
12523  break;
12524  // reconfig framerate
12526  if (p_enc_ctx->frame_num ==
12527  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12528  ni_framerate_t *framerate;
12529 
12530  aux_data = ni_frame_new_aux_data(p_frame,
12532  sizeof(ni_framerate_t));
12533  if (!aux_data) {
12535  }
12536 
12537  framerate = (ni_framerate_t *)aux_data->data;
12538  framerate->framerate_num =
12539  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12540  framerate->framerate_denom =
12541  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12542  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12543  "xcoder_send_frame: frame #%lu reconf "
12544  "framerate (%d/%d)\n",
12545  p_enc_ctx->frame_num, framerate->framerate_num,
12546  framerate->framerate_denom);
12547  p_enc_ctx->reconfigCount++;
12548  }
12549  break;
12551  if (p_enc_ctx->frame_num ==
12552  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12553  aux_data = ni_frame_new_aux_data(
12554  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12555  if (!aux_data) {
12557  }
12558  *((int32_t *)aux_data->data) =
12559  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12560  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12561  "xcoder_send_frame: frame #%lu reconf "
12562  "maxFrameSize %d\n",
12563  p_enc_ctx->frame_num,
12564  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12565 
12566  p_enc_ctx->reconfigCount++;
12567  }
12568  break;
12570  if (p_enc_ctx->frame_num ==
12571  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12572  aux_data = ni_frame_new_aux_data(
12573  p_frame, NI_FRAME_AUX_DATA_CRF, sizeof(int32_t));
12574  if (!aux_data) {
12576  }
12577  *((int32_t *)aux_data->data) =
12578  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12579  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12580  "xcoder_send_frame: frame #%lu reconf "
12581  "crf %d\n",
12582  p_enc_ctx->frame_num,
12583  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12584 
12585  p_enc_ctx->reconfigCount++;
12586  }
12587  break;
12589  if (p_enc_ctx->frame_num ==
12590  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12591  aux_data = ni_frame_new_aux_data(
12592  p_frame, NI_FRAME_AUX_DATA_CRF_FLOAT, sizeof(float));
12593  if (!aux_data) {
12595  }
12596  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12597  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12598  *((float *)aux_data->data) = crf;
12599  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12600  "xcoder_send_frame: frame #%lu reconf "
12601  "crf %f\n",
12602  p_enc_ctx->frame_num, crf);
12603 
12604  p_enc_ctx->reconfigCount++;
12605  }
12606  break;
12608  if (p_enc_ctx->frame_num ==
12609  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12610  int32_t vbvBufferSize = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12611  int32_t vbvMaxRate = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12612  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
12613  {
12614  ni_log2(p_enc_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid vbvBufferSize value %d\n",
12615  __func__, vbvBufferSize);
12616  return NI_RETCODE_INVALID_PARAM;
12617  }
12618  if (p_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < p_param->bitrate) {
12619  ni_log2(p_enc_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
12620  vbvMaxRate, p_param->bitrate);
12621  return NI_RETCODE_INVALID_PARAM;
12622  }
12623  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
12624  ni_log2(p_enc_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
12625  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
12626  vbvMaxRate);
12627  vbvMaxRate = 0;
12628  }
12629 
12630  aux_data = ni_frame_new_aux_data(
12631  p_frame, NI_FRAME_AUX_DATA_VBV_MAX_RATE, sizeof(int32_t));
12632  if (!aux_data) {
12634  }
12635  *((int32_t *)aux_data->data) = vbvMaxRate;
12636  aux_data = ni_frame_new_aux_data(
12637  p_frame, NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE, sizeof(int32_t));
12638  if (!aux_data) {
12640  }
12641  *((int32_t *)aux_data->data) = vbvBufferSize;
12642  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12643  "xcoder_send_frame: frame #%lu reconfig vbvMaxRate %d vbvBufferSize "
12644  "%d by frame aux data\n",
12645  p_enc_ctx->frame_num, vbvMaxRate, vbvBufferSize);
12646 
12647  p_enc_ctx->reconfigCount++;
12648  }
12649  break;
12651  if (p_enc_ctx->frame_num ==
12652  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12653  int maxFrameSizeRatio = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12654  if (maxFrameSizeRatio < 1) {
12655  ni_log2(p_enc_ctx, NI_LOG_ERROR, "maxFrameSizeRatio %d cannot < 1\n",
12656  maxFrameSizeRatio);
12657  return NI_RETCODE_INVALID_PARAM;
12658  }
12659  aux_data = ni_frame_new_aux_data(
12660  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12661  if (!aux_data) {
12663  }
12664 
12665  int32_t bitrate, framerate_num, framerate_denom;
12666  uint32_t min_maxFrameSize, maxFrameSize;
12667  bitrate = (p_enc_ctx->target_bitrate > 0) ? p_enc_ctx->target_bitrate : p_param->bitrate;
12668 
12669  if ((p_enc_ctx->framerate.framerate_num > 0) && (p_enc_ctx->framerate.framerate_denom > 0))
12670  {
12671  framerate_num = p_enc_ctx->framerate.framerate_num;
12672  framerate_denom = p_enc_ctx->framerate.framerate_denom;
12673  }
12674  else
12675  {
12676  framerate_num = (int32_t) p_param->fps_number;
12677  framerate_denom = (int32_t) p_param->fps_denominator;
12678  }
12679 
12680  min_maxFrameSize = ((uint32_t)bitrate / framerate_num * framerate_denom) / 8;
12681  maxFrameSize = min_maxFrameSize * maxFrameSizeRatio > NI_MAX_FRAME_SIZE ?
12682  NI_MAX_FRAME_SIZE : min_maxFrameSize * maxFrameSizeRatio;
12683  *((int32_t *)aux_data->data) = maxFrameSize;
12684  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12685  "xcoder_send_frame: frame #%lu reconf "
12686  "maxFrameSizeRatio %d maxFrameSize %d\n",
12687  p_enc_ctx->frame_num, maxFrameSizeRatio, maxFrameSize);
12688 
12689  p_enc_ctx->reconfigCount++;
12690  }
12691  break;
12693  if (p_enc_ctx->frame_num ==
12694  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12695  aux_data = ni_frame_new_aux_data(
12696  p_frame, NI_FRAME_AUX_DATA_SLICE_ARG, sizeof(int16_t));
12697  if (!aux_data) {
12699  }
12700  *((int16_t *)aux_data->data) =
12701  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12702  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12703  "xcoder_send_frame: frame #%lu reconf "
12704  "sliceArg %d\n",
12705  p_enc_ctx->frame_num,
12706  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12707 
12708  p_enc_ctx->reconfigCount++;
12709  }
12710  break;
12711  // force IDR frame through API test code
12713  if (p_enc_ctx->frame_num ==
12714  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12715  ni_force_idr_frame_type(p_enc_ctx);
12716  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12717  "xcoder_send_frame: frame #%lu force IDR frame\n",
12718  p_enc_ctx->frame_num);
12719 
12720  p_enc_ctx->reconfigCount++;
12721  }
12722  break;
12723  // reconfig bit rate through API test code
12725  if (p_enc_ctx->frame_num ==
12726  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12727  if ((retval = ni_reconfig_bitrate(
12728  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))){
12729  return retval;
12730  }
12731  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12732  "xcoder_send_frame: frame #%lu API reconfig BR %d\n",
12733  p_enc_ctx->frame_num,
12734  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
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  int32_t intraprd =
12743  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12744  if ((retval = ni_reconfig_intraprd(p_enc_ctx, intraprd))){
12745  return retval;
12746  }
12748  "xcoder_send_frame: frame #%lu API reconfig intraPeriod %d\n",
12749  p_enc_ctx->frame_num,
12750  intraprd);
12751 
12752  p_enc_ctx->reconfigCount++;
12753  }
12754  break;
12756  if (p_enc_ctx->frame_num ==
12757  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12758  ni_vui_hrd_t vui;
12759  vui.colorDescPresent =
12760  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12761  vui.colorPrimaries =
12762  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12763  vui.colorTrc =
12764  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12765  vui.colorSpace =
12766  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12767  vui.aspectRatioWidth =
12768  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12769  vui.aspectRatioHeight =
12770  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12771  vui.videoFullRange =
12772  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12773  if ((retval = ni_reconfig_vui(p_enc_ctx, &vui))){
12774  return retval;
12775  }
12776  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12777  "xcoder_send_frame: frame #%lu reconf "
12778  "vui colorDescPresent %d colorPrimaries %d "
12779  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12780  "aspectRatioHeight %d videoFullRange %d\n",
12781  p_enc_ctx->frame_num, vui.colorDescPresent,
12782  vui.colorPrimaries, vui.colorTrc,
12783  vui.colorSpace, vui.aspectRatioWidth,
12785  p_enc_ctx->reconfigCount++;
12786  }
12787  break;
12789  if (p_enc_ctx->frame_num ==
12790  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12791  ni_long_term_ref_t ltr;
12793  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12794  ltr.use_long_term_ref =
12795  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12796 
12797  if ((retval = ni_set_ltr(p_enc_ctx, &ltr))) {
12798  return retval;
12799  }
12800  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12801  "xcoder_send_frame(): frame #%lu API set LTR\n",
12802  p_enc_ctx->frame_num);
12803  p_enc_ctx->reconfigCount++;
12804  }
12805  break;
12808  if (p_enc_ctx->frame_num ==
12809  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12810  ni_rc_min_max_qp qp_info;
12811  qp_info.minQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12812  qp_info.maxQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12813  qp_info.maxDeltaQp = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12814  qp_info.minQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12815  qp_info.maxQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12816  if ((retval = ni_reconfig_min_max_qp(p_enc_ctx, &qp_info))) {
12817  return retval;
12818  }
12819  ni_log2(p_enc_ctx, NI_LOG_DEBUG,
12820  "%s(): frame %d minQpI %d maxQpI %d maxDeltaQp %d minQpPB %d maxQpPB %d\n",
12821  __func__, p_enc_ctx->frame_num,
12822  qp_info.minQpI, qp_info.maxQpI, qp_info.maxDeltaQp, qp_info.minQpPB, qp_info.maxQpPB);
12823  p_enc_ctx->reconfigCount++;
12824  }
12825  break;
12827  if (p_enc_ctx->frame_num ==
12828  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12829  if ((retval = ni_set_ltr_interval(
12830  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12831  return retval;
12832  }
12833  ni_log2(p_enc_ctx,
12834  NI_LOG_TRACE,
12835  "xcoder_send_frame(): frame #%lu API set LTR interval %d\n",
12836  p_enc_ctx->frame_num,
12837  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12838  p_enc_ctx->reconfigCount++;
12839  }
12840  break;
12842  if (p_enc_ctx->frame_num ==
12843  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12844  if ((retval = ni_set_frame_ref_invalid(
12845  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12846  return retval;
12847  }
12848  ni_log2(p_enc_ctx,
12849  NI_LOG_TRACE,
12850  "xcoder_send_frame(): frame #%lu API set frame ref invalid "
12851  "%d\n",
12852  p_enc_ctx->frame_num,
12853  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12854  p_enc_ctx->reconfigCount++;
12855  }
12856  break;
12858  if (p_enc_ctx->frame_num ==
12859  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12860  ni_framerate_t framerate;
12861  framerate.framerate_num =
12862  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12863  framerate.framerate_denom =
12864  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12865  if ((retval = ni_reconfig_framerate(p_enc_ctx, &framerate))) {
12866  return retval;
12867  }
12868  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12869  "xcoder_send_frame: frame #%lu API reconfig framerate "
12870  "(%d/%d)\n",
12871  p_enc_ctx->frame_num,
12872  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12873  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12874 
12875  p_enc_ctx->reconfigCount++;
12876  }
12877  break;
12879  if (p_enc_ctx->frame_num ==
12880  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12881  if ((retval = ni_reconfig_max_frame_size(
12882  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12883  return retval;
12884  }
12885  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12886  "xcoder_send_frame: frame #%lu API reconfig maxFrameSize %d\n",
12887  p_enc_ctx->frame_num,
12888  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12889 
12890  p_enc_ctx->reconfigCount++;
12891  }
12892  break;
12893  case XCODER_TEST_CRF_API:
12894  if (p_enc_ctx->frame_num ==
12895  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12896  if ((retval = ni_reconfig_crf(
12897  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12898  return retval;
12899  }
12900  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12901  "xcoder_send_frame: frame #%lu API reconfig crf %d\n",
12902  p_enc_ctx->frame_num,
12903  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12904 
12905  p_enc_ctx->reconfigCount++;
12906  }
12907  break;
12909  if (p_enc_ctx->frame_num ==
12910  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12911  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12912  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12913  if ((retval = ni_reconfig_crf2(p_enc_ctx, crf))) {
12914  return retval;
12915  }
12916  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12917  "xcoder_send_frame: frame #%lu API reconfig crf %f\n",
12918  p_enc_ctx->frame_num, crf);
12919 
12920  p_enc_ctx->reconfigCount++;
12921  }
12922  break;
12924  if (p_enc_ctx->frame_num ==
12925  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12926  if ((retval = ni_reconfig_vbv_value(
12927  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12928  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]))) {
12929  return retval;
12930  }
12931  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12932  "xcoder_send_frame: frame #%lu API reconfig vbvMaxRate %d vbvBufferSize %d\n",
12933  p_enc_ctx->frame_num,
12934  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12935  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12936 
12937  p_enc_ctx->reconfigCount++;
12938  }
12939  break;
12941  if (p_enc_ctx->frame_num ==
12942  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12943 
12944  if ((retval = ni_reconfig_max_frame_size_ratio(
12945  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12946  return retval;
12947  }
12948  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12949  "xcoder_send_frame: frame #%lu reconf maxFrameSizeRatio %d\n",
12950  p_enc_ctx->frame_num, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12951 
12952  p_enc_ctx->reconfigCount++;
12953  }
12954  break;
12956  if (p_enc_ctx->frame_num ==
12957  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12958  if ((retval = ni_reconfig_slice_arg(
12959  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12960  return retval;
12961  }
12962  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12963  "xcoder_send_frame: frame #%lu API reconfig sliceArg %d\n",
12964  p_enc_ctx->frame_num,
12965  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12966 
12967  p_enc_ctx->reconfigCount++;
12968  }
12969  break;
12970 #endif
12972  default:
12973  ;
12974  }
12975  return NI_RETCODE_SUCCESS;
12976 }
12977 
12981 static int ni_tolower(int c)
12982 {
12983  if (c >= 'A' && c <= 'Z')
12984  c ^= 0x20;
12985  return c;
12986 }
12987 
12988 int ni_strcasecmp(const char *a, const char *b)
12989 {
12990  uint8_t c1, c2;
12991  do
12992  {
12993  c1 = ni_tolower(*a++);
12994  c2 = ni_tolower(*b++);
12995  } while (c1 && c1 == c2);
12996  return c1 - c2;
12997 }
12998 
12999 void ni_gop_params_check_set(ni_xcoder_params_t *p_param, char *value)
13000 {
13001  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
13002  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
13004  p_gop->pic_param[0].rps[0].ref_pic = 1;
13006  p_gop->pic_param[0].rps[0].ref_pic_used = 1;
13008  p_gop->pic_param[0].rps[1].ref_pic = 1;
13010  p_gop->pic_param[0].rps[1].ref_pic_used = 1;
13012  p_gop->pic_param[0].rps[2].ref_pic = 1;
13014  p_gop->pic_param[0].rps[2].ref_pic_used = 1;
13016  p_gop->pic_param[0].rps[3].ref_pic = 1;
13018  p_gop->pic_param[0].rps[3].ref_pic_used = 1;
13020  p_gop->pic_param[1].rps[0].ref_pic = 1;
13022  p_gop->pic_param[1].rps[0].ref_pic_used = 1;
13024  p_gop->pic_param[1].rps[1].ref_pic = 1;
13026  p_gop->pic_param[1].rps[1].ref_pic_used = 1;
13028  p_gop->pic_param[1].rps[2].ref_pic = 1;
13030  p_gop->pic_param[1].rps[2].ref_pic_used = 1;
13032  p_gop->pic_param[1].rps[3].ref_pic = 1;
13034  p_gop->pic_param[1].rps[3].ref_pic_used = 1;
13036  p_gop->pic_param[2].rps[0].ref_pic = 1;
13038  p_gop->pic_param[2].rps[0].ref_pic_used = 1;
13040  p_gop->pic_param[2].rps[1].ref_pic = 1;
13042  p_gop->pic_param[2].rps[1].ref_pic_used = 1;
13044  p_gop->pic_param[2].rps[2].ref_pic = 1;
13046  p_gop->pic_param[2].rps[2].ref_pic_used = 1;
13048  p_gop->pic_param[2].rps[3].ref_pic = 1;
13050  p_gop->pic_param[2].rps[3].ref_pic_used = 1;
13052  p_gop->pic_param[3].rps[0].ref_pic = 1;
13054  p_gop->pic_param[3].rps[0].ref_pic_used = 1;
13056  p_gop->pic_param[3].rps[1].ref_pic = 1;
13058  p_gop->pic_param[3].rps[1].ref_pic_used = 1;
13060  p_gop->pic_param[3].rps[2].ref_pic = 1;
13062  p_gop->pic_param[3].rps[2].ref_pic_used = 1;
13064  p_gop->pic_param[3].rps[3].ref_pic = 1;
13066  p_gop->pic_param[3].rps[3].ref_pic_used = 1;
13068  p_gop->pic_param[4].rps[0].ref_pic = 1;
13070  p_gop->pic_param[4].rps[0].ref_pic_used = 1;
13072  p_gop->pic_param[4].rps[1].ref_pic = 1;
13074  p_gop->pic_param[4].rps[1].ref_pic_used = 1;
13076  p_gop->pic_param[4].rps[2].ref_pic = 1;
13078  p_gop->pic_param[4].rps[2].ref_pic_used = 1;
13080  p_gop->pic_param[4].rps[3].ref_pic = 1;
13082  p_gop->pic_param[4].rps[3].ref_pic_used = 1;
13084  p_gop->pic_param[5].rps[0].ref_pic = 1;
13086  p_gop->pic_param[5].rps[0].ref_pic_used = 1;
13088  p_gop->pic_param[5].rps[1].ref_pic = 1;
13090  p_gop->pic_param[5].rps[1].ref_pic_used = 1;
13092  p_gop->pic_param[5].rps[2].ref_pic = 1;
13094  p_gop->pic_param[5].rps[2].ref_pic_used = 1;
13096  p_gop->pic_param[5].rps[3].ref_pic = 1;
13098  p_gop->pic_param[5].rps[3].ref_pic_used = 1;
13100  p_gop->pic_param[6].rps[0].ref_pic = 1;
13102  p_gop->pic_param[6].rps[0].ref_pic_used = 1;
13104  p_gop->pic_param[6].rps[1].ref_pic = 1;
13106  p_gop->pic_param[6].rps[1].ref_pic_used = 1;
13108  p_gop->pic_param[6].rps[2].ref_pic = 1;
13110  p_gop->pic_param[6].rps[2].ref_pic_used = 1;
13112  p_gop->pic_param[6].rps[3].ref_pic = 1;
13114  p_gop->pic_param[6].rps[3].ref_pic_used = 1;
13116  p_gop->pic_param[7].rps[0].ref_pic = 1;
13118  p_gop->pic_param[7].rps[0].ref_pic_used = 1;
13120  p_gop->pic_param[7].rps[1].ref_pic = 1;
13122  p_gop->pic_param[7].rps[1].ref_pic_used = 1;
13124  p_gop->pic_param[7].rps[2].ref_pic = 1;
13126  p_gop->pic_param[7].rps[2].ref_pic_used = 1;
13128  p_gop->pic_param[7].rps[3].ref_pic = 1;
13130  p_gop->pic_param[7].rps[3].ref_pic_used = 1;
13131 
13132 }
13133 
13135 {
13136  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
13137  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
13138  int i, j;
13139  for (i=0; i<NI_MAX_GOP_NUM; i++)
13140  {
13141  for (j=0; j<NI_MAX_REF_PIC; j++)
13142  {
13143  if (p_gop->pic_param[i].rps[j].ref_pic == 1 &&
13144  p_gop->pic_param[i].rps[j].ref_pic_used != 1)
13145  {
13147  "g%drefPic%d specified without g%drefPic%dUsed specified!\n",
13148  i, j, i, j);
13149  return false;
13150  }
13151  }
13152  }
13153  // set custom_gop_params default.
13154  for (i=0; i<NI_MAX_GOP_NUM; i++)
13155  {
13156  for (j=0; j<NI_MAX_REF_PIC; j++)
13157  {
13158  p_gop->pic_param[i].rps[j].ref_pic = 0;
13159  p_gop->pic_param[i].rps[j].ref_pic_used = 0;
13160  }
13161  }
13162  return true;
13163 }
13164 
13165 #ifndef DEPRECATION_AS_ERROR
13166 /*!*****************************************************************************
13167  * \brief Initiate P2P transfer (P2P write) (deprecated)
13168  *
13169  * \param[in] pSession Pointer to source card destination
13170  * \param[in] source Pointer to source frame to transmit
13171  * \param[in] ui64DestAddr Destination address on target device
13172  * \param[in] ui32FrameSize Size of frame to transfer
13173  *
13174  * \return always returns
13175  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
13176 *******************************************************************************/
13178  niFrameSurface1_t *source,
13179  uint64_t ui64DestAddr,
13180  uint32_t ui32FrameSize)
13181 {
13182  // avoid compiler warnings
13183  (void) pSession;
13184  (void) source;
13185  (void) ui64DestAddr;
13186  (void) ui32FrameSize;
13187 
13189 }
13190 #endif
13191 
13192 /*!*****************************************************************************
13193  * \brief Initiate P2P transfer (P2P write)
13194  *
13195  * \param[in] pSession Pointer to source card destination
13196  * \param[in] source Pointer to source frame to transmit
13197  * \param[in] ui64DestAddr Destination address on target device
13198  * \param[in] ui32FrameSize Size of frame to transfer
13199  *
13200  * \return on success
13201  * NI_RETCODE_SUCCESS
13202  * on failure
13203  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
13204  * NI_RETCODE_INVALID_PARAM
13205  * NI_RETCODE_ERROR_INVALID_SESSION
13206  * NI_RETCODE_ERROR_MEM_ALOC
13207  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13208 *******************************************************************************/
13210  niFrameSurface1_t *source,
13211  uint64_t ui64DestAddr, uint32_t ui32FrameSize)
13212 {
13214 
13215  if ((pSession == NULL) || (source == NULL))
13216  {
13217  return NI_RETCODE_INVALID_PARAM;
13218  }
13219 
13220  /* Firmware compatibility check */
13221  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
13222  {
13223  ni_log2(pSession, NI_LOG_ERROR, "%s: FW doesn't support this operation\n", __func__);
13225  }
13226 
13227  retval = ni_send_to_target(pSession, source, ui64DestAddr, ui32FrameSize);
13228 
13229  if (retval < 0)
13230  {
13231  ni_log2(pSession, NI_LOG_ERROR, "%s(): Can't DMA to destination (%d)\n", __func__, retval);
13232  }
13233 
13234  return retval;
13235 }
13236 
13237 /*!*****************************************************************************
13238  * \brief Initiate a P2P transfer (P2P read)
13239  *
13240  * \param[in] pSession Pointer to destination upload session
13241  * \param[in] dmaAddrs Pointer to source DMA addresses
13242  * \param[in] pDstFrame Pointer to destination P2P frame
13243  *
13244  * \return on success
13245  * NI_RETCODE_SUCCESS
13246  * on failure
13247  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
13248  * NI_RETCODE_INVALID_PARAM
13249  * NI_RETCODE_ERROR_INVALID_SESSION
13250  * NI_RETCODE_ERROR_MEM_ALOC
13251  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13252 *******************************************************************************/
13254  const ni_p2p_sgl_t *dmaAddrs,
13255  ni_frame_t *pDstFrame)
13256 {
13258 
13259  if ((pSession == NULL) || (dmaAddrs == NULL) || (pDstFrame == NULL))
13260  {
13261  return NI_RETCODE_INVALID_PARAM;
13262  }
13263 
13264  /* Firmware compatibility check */
13265  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
13266  {
13267  ni_log2(pSession, NI_LOG_ERROR,
13268  "%s: FW doesn't support this operation\n", __func__);
13270  }
13271 
13272  retval = ni_recv_from_target(pSession, dmaAddrs, pDstFrame);
13273 
13274  if (retval < 0)
13275  {
13276  ni_log2(pSession, NI_LOG_ERROR,
13277  "%s(): Can't DMA from source (%d)\n", __func__, retval);
13278  retval = NI_RETCODE_INVALID_PARAM;
13279  }
13280 
13281  return retval;
13282 }
13283 
13284 /*!*****************************************************************************
13285  * \brief Send a restart command after flush command
13286  * Only support Encoder now
13287  *
13288  * \param[in] p_ctx Pointer to a caller allocated
13289  * ni_session_context_t struct
13290  * \param[in] width width, in pixels
13291  * \param[in] height height, in pixels
13292  * \param[in] device_type NI_DEVICE_TYPE_ENCODER
13293  * \return On success
13294  * NI_RETCODE_SUCCESS
13295  * On failure
13296  * NI_RETCODE_INVALID_PARAM
13297  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13298  * NI_RETCODE_ERROR_INVALID_SESSION
13299  ******************************************************************************/
13301  int video_width,
13302  int video_height,
13303  ni_device_type_t device_type)
13304 {
13305  ni_retcode_t retval = 0;
13306  ni_resolution_t resolution;
13307  ni_xcoder_params_t *p_param = NULL;
13308 
13309  if (!p_ctx)
13310  {
13311  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
13312  __func__);
13313  return NI_RETCODE_INVALID_PARAM;
13314  }
13315 
13316  switch (device_type)
13317  {
13319  {
13320  // requires API version >= 54
13322  "54") < 0)
13323  {
13324  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
13326  }
13327 
13328  /* This function should be called only if flushing is detected */
13330  {
13331  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() wrong state %d\n",
13332  __func__, p_ctx->session_run_state);
13334  }
13335 
13336  if (video_width < NI_MIN_WIDTH || video_width > NI_MAX_WIDTH ||
13337  video_height < NI_MIN_HEIGHT || video_height > NI_MAX_HEIGHT)
13338  {
13339  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() invalid width %d or height %d\n",
13340  __func__, video_width, video_height);
13341  return NI_RETCODE_INVALID_PARAM;
13342  }
13343  resolution.width = video_width;
13344  resolution.height = video_height;
13345  resolution.bit_depth_factor = p_ctx->bit_depth_factor;
13346  resolution.luma_linesize = 0;
13347  resolution.chroma_linesize = 0;
13348  if (p_ctx->p_session_config)
13349  {
13350  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
13351  resolution.luma_linesize = p_param->luma_linesize;
13352  resolution.chroma_linesize = p_param->chroma_linesize;
13353  }
13354  ni_pthread_mutex_lock(&p_ctx->mutex);
13355 
13356  // reconfig the encoder session
13357  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
13358  if (NI_RETCODE_SUCCESS != retval)
13359  {
13360  ni_log(NI_LOG_ERROR, "Failed to reconfig config the encoder session (status = %d)\n", retval);
13361  ni_pthread_mutex_unlock(&p_ctx->mutex);
13362  return retval;
13363  }
13364 
13365  // update session context
13366  p_ctx->ready_to_close = 0;
13367  p_ctx->frame_num = 0;
13368  p_ctx->pkt_num = 0;
13369  ni_pthread_mutex_unlock(&p_ctx->mutex);
13370  break;
13371  }
13372  default:
13373  {
13374  retval = NI_RETCODE_INVALID_PARAM;
13375  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unsupported device type: %d",
13376  __func__, device_type);
13377  break;
13378  }
13379  }
13380  return retval;
13381 }
13382 
13383 /*!******************************************************************************
13384 * \brief Send a p_config command to reconfigure decoding ppu params.
13385 *
13386 * \param ni_session_context_t p_session_ctx - xcoder Context
13387 * \param ni_xcoder_params_t p_param - xcoder Params
13388 * \param ni_ppu_config_t p_ppu_config - Struct ni_ppu_config
13389 *
13390 * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
13391 *******************************************************************************/
13393  ni_xcoder_params_t *p_param, ni_ppu_config_t *p_ppu_config)
13394 {
13395  int ret = 0, i = 0;
13396  if (!p_session_ctx || !p_param || !p_ppu_config)
13397  {
13399  return ret;
13400  }
13401  if (p_session_ctx->ppu_reconfig_pkt_pos != 0)
13402  {
13403  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s: Warning ignore ppu reconfig before last config done!\n", __func__);
13404  return 0;
13405  }
13406 
13407  // check fw revision
13408  if (ni_cmp_fw_api_ver(
13409  (char*) &p_session_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
13410  "6sF") < 0)
13411  {
13412  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s: not supported on device with FW API version < 6sF\n", __func__);
13414  }
13415 
13416  if (NI_CODEC_FORMAT_H264 != p_session_ctx->codec_format &&
13417  NI_CODEC_FORMAT_H265 != p_session_ctx->codec_format)
13418  {
13419  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): only supported for h264 and h265 decoder\n", __func__);
13421  }
13422 
13423  ni_decoder_input_params_t *p_dec_input_param = &(p_param->dec_input_params);
13424  if (p_dec_input_param->hwframes != 1)
13425  {
13426  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): only supported for hw mode\n", __func__);
13428  }
13429  if (!p_dec_input_param->disable_adaptive_buffers)
13430  {
13431  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): not supported when disable_adaptive_buffers is disabled\n", __func__);
13433  }
13434  if (p_dec_input_param->mcmode)
13435  {
13436  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): not supported when MulticoreJointMode is enabled\n", __func__);
13438  }
13439  if (p_dec_input_param->enable_out1 == 0 &&
13440  p_ppu_config->ppu_set_enable & (0x01 << 1))
13441  {
13442  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): Error reconfig ppu1 while ppu1 is not enabled\n", __func__);
13444  }
13445  if (p_dec_input_param->enable_out2 == 0 &&
13446  p_ppu_config->ppu_set_enable & (0x01 << 2))
13447  {
13448  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): Error reconfig ppu2 while ppu2 is not enabled\n", __func__);
13450  }
13451  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
13452  {
13453  if (p_ppu_config->ppu_set_enable & (0x01 << i))
13454  {
13455  if (p_ppu_config->ppu_w[i] > NI_MAX_RESOLUTION_WIDTH ||
13456  p_ppu_config->ppu_h[i] > NI_MAX_RESOLUTION_HEIGHT ||
13457  p_ppu_config->ppu_w[i] < NI_MIN_RESOLUTION_WIDTH_SCALER ||
13458  p_ppu_config->ppu_h[i] < NI_MIN_RESOLUTION_WIDTH_SCALER)
13459  {
13460  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): ppu[%d] width x height %ux%u "
13461  "out of range\n", __func__, i, p_ppu_config->ppu_w[i], p_ppu_config->ppu_h[i]);
13463  return ret;
13464  }
13465  if ((p_ppu_config->ppu_w[i] & 1) || (p_ppu_config->ppu_h[i] & 1))
13466  {
13467  ni_log2(p_session_ctx, NI_LOG_ERROR, "%s(): ppu[%d] wxh %dx%d not align to 2!\n",
13468  __func__, i, p_ppu_config->ppu_w[i], p_ppu_config->ppu_h[i]);
13470  return ret;
13471  }
13472  }
13473  }
13475  p_session_ctx, p_ppu_config, sizeof(ni_ppu_config_t));
13476  if (ret == NI_RETCODE_SUCCESS)
13477  {
13478  p_session_ctx->ppu_reconfig_pkt_pos = p_session_ctx->pkt_num;
13479  }
13480  return ret;
13481 }
_ni_ppu_config
Definition: ni_device_api.h:1429
XCODER_TEST_RECONF_LTR_INTERVAL_API
@ XCODER_TEST_RECONF_LTR_INTERVAL_API
Definition: ni_device_api.h:1805
NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
Definition: ni_device_api.h:1919
_ni_xcoder_params::reconf_demo_mode
int reconf_demo_mode
Definition: ni_device_api.h:2832
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:119
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:12103
_ni_encoder_cfg_params::enable_mb_level_rc
int enable_mb_level_rc
Definition: ni_device_api.h:2459
_ni_long_term_ref::use_long_term_ref
uint8_t use_long_term_ref
Definition: ni_device_api.h:705
NI_ENC_PARAM_ROI_DEMO_MODE
#define NI_ENC_PARAM_ROI_DEMO_MODE
Definition: ni_device_api.h:2118
_ni_encoder_cfg_params::frame_rate
int frame_rate
Definition: ni_device_api.h:2314
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
Definition: ni_device_api.h:290
NI_XCODER_CLOSE_STATE
@ NI_XCODER_CLOSE_STATE
Definition: ni_device_api.h:252
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:12141
_ni_xcoder_params::fps_denominator
uint32_t fps_denominator
Definition: ni_device_api.h:2820
NI_ENC_PARAM_LINK_FRAME_MAX_INTRA_RATIO
#define NI_ENC_PARAM_LINK_FRAME_MAX_INTRA_RATIO
Definition: ni_device_api.h:2306
NI_PIX_FMT_UYVY422
@ NI_PIX_FMT_UYVY422
Definition: ni_device_api.h:278
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:11600
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:2253
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:19091
_ni_xcoder_params::luma_linesize
int luma_linesize
Definition: ni_device_api.h:2887
ni_pthread_mutex_unlock
int ni_pthread_mutex_unlock(ni_pthread_mutex_t *mutex)
thread mutex unlock
Definition: ni_util.c:4712
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0
Definition: ni_device_api.h:1922
NI_PIX_FMT_BGRA
@ NI_PIX_FMT_BGRA
Definition: ni_device_api.h:271
_ni_scaler_input_params_t::output_height
int32_t output_height
Definition: ni_device_api.h:2648
_ni_session_context::force_idr_frame
int force_idr_frame
Definition: ni_device_api.h:1631
NI_CODEC_FORMAT_JPEG
@ NI_CODEC_FORMAT_JPEG
Definition: ni_device_api.h:928
_ni_encoder_cfg_params::ver_offset
int ver_offset
Definition: ni_device_api.h:2473
NI_DEC_PARAM_SCALE_0_RES_CEIL
#define NI_DEC_PARAM_SCALE_0_RES_CEIL
Definition: ni_device_api.h:2559
NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
@ NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
Definition: ni_device_api.h:580
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:4806
NI_ENC_PARAM_ZEROCOPY_MODE
#define NI_ENC_PARAM_ZEROCOPY_MODE
Definition: ni_device_api.h:2260
_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:4230
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:9024
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:18519
NI_NUM_PRESETS_MAX
@ NI_NUM_PRESETS_MAX
Definition: ni_device_api.h:1882
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:4217
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:752
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1938
NI_DEC_PARAM_SKIP_PTS_GUESS
#define NI_DEC_PARAM_SKIP_PTS_GUESS
Definition: ni_device_api.h:2581
NI_MAX_RESOLUTION_HEIGHT
#define NI_MAX_RESOLUTION_HEIGHT
Definition: ni_device_api.h:104
_ni_session_context::hevc_sub_ctu_roi_buf
uint8_t * hevc_sub_ctu_roi_buf
Definition: ni_device_api.h:1618
_ni_decoder_input_params_t::mcmode
int mcmode
Definition: ni_device_api.h:2594
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:5824
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:2206
NI_DEVICE_READ_ONLY
@ NI_DEVICE_READ_ONLY
Definition: ni_device_api.h:3051
NI_DEC_PARAM_SCALE_2_RES_CEIL
#define NI_DEC_PARAM_SCALE_2_RES_CEIL
Definition: ni_device_api.h:2561
_ni_frame::separate_start
uint8_t separate_start
Definition: ni_device_api.h:2804
ni_strerror
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
Definition: ni_util.c:656
g_xcoder_log_names
const char *const g_xcoder_log_names[NI_XCODER_LOG_NAMES_ARRAY_LEN]
Definition: ni_device_api.c:77
XCODER_TEST_RECONF_CRF_FLOAT
@ XCODER_TEST_RECONF_CRF_FLOAT
Definition: ni_device_api.h:1795
NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
#define NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:2136
_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:167
_ni_frame::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2764
_ni_encoder_cfg_params::adaptiveLamdaMode
int adaptiveLamdaMode
Definition: ni_device_api.h:2531
NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
#define NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
Definition: ni_device_api.h:2292
_ni_network_data
Definition: ni_device_api.h:1377
_ni_xcoder_params::dolby_vision_profile
int dolby_vision_profile
Definition: ni_device_api.h:2840
_ni_session_context::ltr_interval
int32_t ltr_interval
Definition: ni_device_api.h:1633
NI_DEC_PARAM_SCALE_0
#define NI_DEC_PARAM_SCALE_0
Definition: ni_device_api.h:2553
_ni_resolution::chroma_linesize
int32_t chroma_linesize
Definition: ni_device_api_priv.h:915
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1989
_ni_session_context::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:1625
_ni_decoder_input_params_t::error_ratio_threshold
int error_ratio_threshold
Definition: ni_device_api.h:2630
NI_ENC_PARAM_CONF_WIN_RIGHT
#define NI_ENC_PARAM_CONF_WIN_RIGHT
Definition: ni_device_api.h:2156
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:2243
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:9915
_ni_thread_arg_struct_t::p_mutex
ni_pthread_mutex_t * p_mutex
Definition: ni_device_api.h:1281
NI_ENC_PARAM_TOL_RC_INTRA
#define NI_ENC_PARAM_TOL_RC_INTRA
Definition: ni_device_api.h:2218
_ni_encoder_cfg_params::skip_frame_interval
int skip_frame_interval
Definition: ni_device_api.h:2495
ni_pix_fmt_t
ni_pix_fmt_t
Definition: ni_device_api.h:264
NI_EC_POLICY_SKIP
#define NI_EC_POLICY_SKIP
Definition: ni_device_api.h:334
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:807
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:2427
_ni_encoder_cfg_params::hor_offset
int hor_offset
Definition: ni_device_api.h:2472
_ni_encoder_cfg_params::inLoopDSRatio
int inLoopDSRatio
Definition: ni_device_api.h:2410
NI_ENC_PARAM_GET_PSNR_MODE
#define NI_ENC_PARAM_GET_PSNR_MODE
Definition: ni_device_api.h:2290
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:2664
NI_ENC_PARAM_LTR_REF_INTERVAL
#define NI_ENC_PARAM_LTR_REF_INTERVAL
Definition: ni_device_api.h:2210
XCODER_TEST_RECONF_END
@ XCODER_TEST_RECONF_END
Definition: ni_device_api.h:1815
NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2282
XCODER_TEST_CRF_API
@ XCODER_TEST_CRF_API
Definition: ni_device_api.h:1810
_ni_enc_avc_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:884
NI_ENC_PARAM_INTRA_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_REFRESH_MODE
Definition: ni_device_api.h:2172
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:14710
NI_XCODER_LOG_NAME_WARN
#define NI_XCODER_LOG_NAME_WARN
Definition: ni_device_api.h:3070
NI_MAX_DYNAMIC_MERGE
#define NI_MAX_DYNAMIC_MERGE
Definition: ni_device_api.h:162
NI_ENC_PARAM_CONF_WIN_LEFT
#define NI_ENC_PARAM_CONF_WIN_LEFT
Definition: ni_device_api.h:2155
_ni_encoder_cfg_params::reset_dts_offset
int reset_dts_offset
Definition: ni_device_api.h:2530
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:3725
OPT
#define OPT(STR)
NI_XCODER_PRESET_NAME_SLOW
#define NI_XCODER_PRESET_NAME_SLOW
Definition: ni_device_api.h:3064
NI_ENC_GOP_PARAMS_G5_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G5_PIC_TYPE
Definition: ni_device_api.h:1965
NI_XCODER_PRESET_NAME_FAST
#define NI_XCODER_PRESET_NAME_FAST
Definition: ni_device_api.h:3062
NI_ENC_PARAM_TRANS_RATE
#define NI_ENC_PARAM_TRANS_RATE
Definition: ni_device_api.h:2158
NI_DEC_PARAM_PKT_PTS_UNCHANGE
#define NI_DEC_PARAM_PKT_PTS_UNCHANGE
Definition: ni_device_api.h:2582
_ni_decoder_input_params_t::enable_ppu_scale_adapt
int enable_ppu_scale_adapt
Definition: ni_device_api.h:2617
_ni_encoder_cfg_params::pbRatio
float pbRatio
Definition: ni_device_api.h:2480
NI_ENC_PARAM_DISABLE_AV1_TIMING_INFO
#define NI_ENC_PARAM_DISABLE_AV1_TIMING_INFO
Definition: ni_device_api.h:2308
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
Definition: ni_device_api.h:1988
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:5971
_ni_decoder_input_params_t::enable_out1
int enable_out1
Definition: ni_device_api.h:2592
ni_device_open2
ni_device_handle_t ni_device_open2(const char *p_dev, ni_device_mode_t mode)
Open device and return device device_handle if successful.
Definition: ni_device_api.c:521
_ni_network_layer_info::in_param
ni_network_layer_params_t * in_param
Definition: ni_device_api.h:1368
_ni_encoder_cfg_params::vbvBufferReencode
int vbvBufferReencode
Definition: ni_device_api.h:2518
_ni_session_context::nb_rois
int nb_rois
Definition: ni_device_api.h:1612
_ni_session_context::xcoder_state
uint32_t xcoder_state
Definition: ni_device_api.h:1599
NI_ENC_BLOCK_RC_SIZE
#define NI_ENC_BLOCK_RC_SIZE
Definition: ni_device_api.h:2221
XCODER_TEST_RECONF_MAX_FRAME_SIZE
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE
Definition: ni_device_api.h:1792
_ni_xcoder_params::padding
int padding
Definition: ni_device_api.h:2835
NI_ENC_PARAM_ENABLE_CPU_AFFINITY
#define NI_ENC_PARAM_ENABLE_CPU_AFFINITY
Definition: ni_device_api.h:2310
_ni_encoder_cfg_params::enable_filler
int enable_filler
Definition: ni_device_api.h:2451
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:150
_ni_session_context::force_low_delay
bool force_low_delay
Definition: ni_device_api.h:1730
GOP_PRESET_IDX_NONE
@ GOP_PRESET_IDX_NONE
Definition: ni_device_api_priv.h:325
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1985
ni_config_instance_hvsplus
ni_retcode_t ni_config_instance_hvsplus(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:16812
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:3561
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:18127
_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:126
NI_ENC_GOP_PARAMS_G4_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G4_QP_OFFSET
Definition: ni_device_api.h:1947
NI_DEC_PARAM_LOW_DELAY
#define NI_DEC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2567
_ni_encoder_cfg_params::gopLowdelay
int gopLowdelay
Definition: ni_device_api.h:2399
NI_XCODER_LOG_NAME_FULL
#define NI_XCODER_LOG_NAME_FULL
Definition: ni_device_api.h:3073
NI_MIN_KEEP_ALIVE_TIMEOUT
#define NI_MIN_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:324
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:9448
NI_DEC_PARAM_ENABLE_OUT_2
#define NI_DEC_PARAM_ENABLE_OUT_2
Definition: ni_device_api.h:2540
_ni_gop_rps::ref_pic_used
int ref_pic_used
Definition: ni_device_api.h:2009
_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:1519
NI_ENC_NEW_RC_ENABLE
#define NI_ENC_NEW_RC_ENABLE
Definition: ni_device_api.h:2224
NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
#define NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
Definition: ni_device_api.h:2256
_ni_scaler_input_params_t::op
ni_scaler_opcode_t op
Definition: ni_device_api.h:2655
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:2083
_ni_session_context::frame_time_q
void * frame_time_q
Definition: ni_device_api.h:1440
XCODER_TEST_RECONF_LTR_INTERVAL
@ XCODER_TEST_RECONF_LTR_INTERVAL
Definition: ni_device_api.h:1789
_ni_encoder_cfg_params::statistic_output_level
int statistic_output_level
Definition: ni_device_api.h:2492
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1899
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:18881
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:2139
NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
#define NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
Definition: ni_device_api.h:2283
XCODER_TEST_RECONF_FRAMERATE_API
@ XCODER_TEST_RECONF_FRAMERATE_API
Definition: ni_device_api.h:1807
_ni_decoder_input_params_t::ec_policy
int ec_policy
Definition: ni_device_api.h:2615
NI_ENC_PARAM_MAX_QP
#define NI_ENC_PARAM_MAX_QP
Definition: ni_device_api.h:2149
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:1967
_ni_frame::metadata_buffer_size
uint32_t metadata_buffer_size
Definition: ni_device_api.h:2793
_ni_decoder_input_params_t::skip_pts_guess
int skip_pts_guess
Definition: ni_device_api.h:2620
NI_ENC_PARAM_BITRATE
#define NI_ENC_PARAM_BITRATE
Definition: ni_device_api.h:2115
_ni_vui_hrd
Definition: ni_device_api.h:668
_ni_rc_min_max_qp::minQpI
int32_t minQpI
Definition: ni_device_api.h:720
_ni_encoder_cfg_params::temporal_layers_enable
int temporal_layers_enable
Definition: ni_device_api.h:2467
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:14658
NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
Definition: ni_device_api.h:2228
ni_device_close
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
Definition: ni_device_api.c:665
NI_NUM_OF_PIXELS_1080P
#define NI_NUM_OF_PIXELS_1080P
Definition: ni_device_api.h:80
_ni_session_context::fn
unsigned short fn
Definition: ni_device_api.h:1653
_ni_encoder_cfg_params::adaptiveCrfMode
int adaptiveCrfMode
Definition: ni_device_api.h:2532
netint_iocmd_attach_rfence
Definition: ni_p2p_ioctl.h:80
_niFrameSurface1::ui16height
uint16_t ui16height
Definition: ni_device_api.h:2902
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:1195
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1897
NI_ENC_PARAM_ALLOCATE_STRAEGY
#define NI_ENC_PARAM_ALLOCATE_STRAEGY
Definition: ni_device_api.h:2295
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:10351
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:11395
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1929
_ni_session_context::roi_side_data_size
int roi_side_data_size
Definition: ni_device_api.h:1609
NI_ENC_PARAM_CU_SIZE_MODE
#define NI_ENC_PARAM_CU_SIZE_MODE
Definition: ni_device_api.h:2138
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
Definition: ni_device_api.h:1809
NI_MIN_INTRA_QP_DELTA
#define NI_MIN_INTRA_QP_DELTA
Definition: ni_device_api.h:171
_ni_session_context::input_frame_fifo
ni_input_frame input_frame_fifo[120]
encoder:calculate PSNR start
Definition: ni_device_api.h:1740
_ni_session_context::current_frame_delay
int current_frame_delay
Definition: ni_device_api.h:1724
_ni_scaler_watermark_params_t
Definition: ni_device_api.h:2676
NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
Definition: ni_device_api.h:1904
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:1511
ni_strcpy
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
Definition: ni_util.c:453
NI_XCODER_PRESET_NAME_MEDIUM
#define NI_XCODER_PRESET_NAME_MEDIUM
Definition: ni_device_api.h:3063
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:16328
_ni_xcoder_params::source_width
int source_width
Definition: ni_device_api.h:2824
NI_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_RETCODE_ERROR_GET_DEVICE_POOL
Definition: ni_defs.h:520
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:2695
NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
#define NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
Definition: ni_device_api.h:2584
NI_PARAM_AV1_MAX_WIDTH
#define NI_PARAM_AV1_MAX_WIDTH
Definition: ni_device_api.h:148
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:2197
_ni_input_frame::usable
int8_t usable
Definition: ni_device_api.h:1419
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:10268
_ni_decoder_input_params_t::enable_ppu_scale_limit
int enable_ppu_scale_limit
Definition: ni_device_api.h:2618
_ni_scaler_input_params_t::out_rec_height
int32_t out_rec_height
Definition: ni_device_api.h:2650
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:2360
_ni_session_context::target_bitrate
int32_t target_bitrate
Definition: ni_device_api.h:1630
_ni_session_context::mutex_initialized
bool mutex_initialized
Definition: ni_device_api.h:1702
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:11891
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:8965
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:16540
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:11690
NI_ENC_PARAM_CONF_WIN_TOP
#define NI_ENC_PARAM_CONF_WIN_TOP
Definition: ni_device_api.h:2153
_ni_session_context::netint_fd
int netint_fd
Definition: ni_device_api.h:1649
QOS_OP_CONFIG_REC_OP_CODE
@ QOS_OP_CONFIG_REC_OP_CODE
Definition: ni_device_api.h:241
NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
#define NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
Definition: ni_device_api.h:2270
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
Definition: ni_device_api.h:2001
NI_DEC_PARAM_ENABLE_CPU_AFFINITY
#define NI_DEC_PARAM_ENABLE_CPU_AFFINITY
Definition: ni_device_api.h:2589
NI_PIX_FMT_YUV420P
@ NI_PIX_FMT_YUV420P
Definition: ni_device_api.h:266
NI_DEC_PARAM_FORCE_8BIT_1
#define NI_DEC_PARAM_FORCE_8BIT_1
Definition: ni_device_api.h:2542
NI_ENC_PARAM_BITRATE_MODE
#define NI_ENC_PARAM_BITRATE_MODE
Definition: ni_device_api.h:2278
NI_EC_POLICY_IGNORE
#define NI_EC_POLICY_IGNORE
Definition: ni_device_api.h:333
_ni_rc_min_max_qp
Definition: ni_device_api.h:718
_ni_resolution
Definition: ni_device_api_priv.h:903
NI_ENC_PARAM_COLOR_PRIMARY
#define NI_ENC_PARAM_COLOR_PRIMARY
Definition: ni_device_api.h:2241
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:2226
_niFrameSurface1::ui32nodeAddress
uint32_t ui32nodeAddress
Definition: ni_device_api.h:2903
_ni_session_context::isP2P
int32_t isP2P
Definition: ni_device_api.h:1648
_ni_encoder_cfg_params::enable_hvs_qp_scale
int enable_hvs_qp_scale
Definition: ni_device_api.h:2456
NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
#define NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
Definition: ni_device_api.h:2146
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
Definition: ni_device_api.h:1913
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:2286
NI_XCODER_READ_STATE
@ NI_XCODER_READ_STATE
Definition: ni_device_api.h:251
_ni_encoder_cfg_params::trans_rate
int trans_rate
Definition: ni_device_api.h:2458
_ni_thread_arg_struct_t::close_thread
bool close_thread
Definition: ni_device_api.h:1276
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:3039
NI_MAX_RESOLUTION_RGBA_WIDTH
#define NI_MAX_RESOLUTION_RGBA_WIDTH
Definition: ni_device_api.h:106
_ni_xcoder_params::enable2PassGop
int enable2PassGop
Definition: ni_device_api.h:2885
NI_ENC_GOP_PARAMS_G7_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G7_PIC_TYPE
Definition: ni_device_api.h:1995
_ni_frame::src_codec
ni_codec_format_t src_codec
Definition: ni_device_api.h:2701
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
Definition: ni_device_api.h:1909
_ni_session_context::ltr_to_set
ni_long_term_ref_t ltr_to_set
Definition: ni_device_api.h:1632
NI_DEC_PARAM_SCALE_1
#define NI_DEC_PARAM_SCALE_1
Definition: ni_device_api.h:2554
NI_ENC_PARAM_NO_MBTREE
#define NI_ENC_PARAM_NO_MBTREE
Definition: ni_device_api.h:2269
_ni_encoder_cfg_params::crf_max_iframe_enable
int crf_max_iframe_enable
Definition: ni_device_api.h:2499
NI_MIN_DYNAMIC_MERGE
#define NI_MIN_DYNAMIC_MERGE
Definition: ni_device_api.h:163
XCODER_TEST_RECONF_SLICE_ARG
@ XCODER_TEST_RECONF_SLICE_ARG
Definition: ni_device_api.h:1798
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:3068
_ni_session_context::active_video_width
uint32_t active_video_width
Definition: ni_device_api.h:1580
NI_ENC_PARAM_CROP_HEIGHT
#define NI_ENC_PARAM_CROP_HEIGHT
Definition: ni_device_api.h:2264
_ni_gop_params::poc_offset
int poc_offset
Definition: ni_device_api.h:2014
_ni_gop_params::qp_offset
int qp_offset
Definition: ni_device_api.h:2015
_ni_framerate::framerate_denom
int32_t framerate_denom
Definition: ni_device_api.h:715
NI_DEVICE_TYPE_UPLOAD
@ NI_DEVICE_TYPE_UPLOAD
Definition: ni_defs.h:367
_ni_decoder_input_params_t::enable_user_data_sei_passthru
int enable_user_data_sei_passthru
Definition: ni_device_api.h:2612
NI_ENC_PARAM_LTR_FIRST_GAP
#define NI_ENC_PARAM_LTR_FIRST_GAP
Definition: ni_device_api.h:2212
ni_ai_session_open
ni_retcode_t ni_ai_session_open(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:17693
NI_XCODER_HWDL_STATE
@ NI_XCODER_HWDL_STATE
Definition: ni_device_api.h:259
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:3695
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:104
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:1650
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:10466
_ni_session_context::pool_type
ni_frame_pool_type_t pool_type
Definition: ni_device_api.h:1728
_ni_session_context::av_rois
ni_region_of_interest_t * av_rois
Definition: ni_device_api.h:1611
NI_DEC_PARAM_FORCE_8BIT_2
#define NI_DEC_PARAM_FORCE_8BIT_2
Definition: ni_device_api.h:2543
XCODER_TEST_RECONF_CRF
@ XCODER_TEST_RECONF_CRF
Definition: ni_device_api.h:1794
NI_FRAME_AUX_DATA_CRF
@ NI_FRAME_AUX_DATA_CRF
Definition: ni_device_api.h:588
NI_INVALID_SESSION_ID
#define NI_INVALID_SESSION_ID
Definition: ni_device_api.h:114
_ni_encoder_cfg_params::enable_ssim
int enable_ssim
Definition: ni_device_api.h:2462
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:1894
NI_MAX_CU_SIZE_MODE
#define NI_MAX_CU_SIZE_MODE
Definition: ni_device_api.h:159
NI_XCODER_LOG_NAME_INFO
#define NI_XCODER_LOG_NAME_INFO
Definition: ni_device_api.h:3071
_ni_xcoder_params::color_primaries
int color_primaries
Definition: ni_device_api.h:2859
_ni_encoder_cfg_params::enable_compensate_qp
int enable_compensate_qp
Definition: ni_device_api.h:2513
NI_ENC_PARAM_AV1_OP_LEVEL
#define NI_ENC_PARAM_AV1_OP_LEVEL
Definition: ni_device_api.h:2309
NI_ENC_PARAM_LOOK_AHEAD_DEPTH
#define NI_ENC_PARAM_LOOK_AHEAD_DEPTH
Definition: ni_device_api.h:2192
_ni_resolution::luma_linesize
int32_t luma_linesize
Definition: ni_device_api_priv.h:914
_ni_frame::total_start_len
uint32_t total_start_len
Definition: ni_device_api.h:2802
_ni_session_context::last_bitrate
int32_t last_bitrate
Definition: ni_device_api.h:1705
_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:3328
NI_ENC_PARAM_LTR_NEXT_INTERVAL
#define NI_ENC_PARAM_LTR_NEXT_INTERVAL
Definition: ni_device_api.h:2213
NI_DEC_CROP_MODE_AUTO
@ NI_DEC_CROP_MODE_AUTO
Definition: ni_device_api.h:943
NI_PARAM_MIN_WIDTH
#define NI_PARAM_MIN_WIDTH
Definition: ni_device_api.h:139
_ni_session_context::actual_video_width
uint32_t actual_video_width
Definition: ni_device_api.h:1584
XCODER_TEST_RECONF_VUI_HRD
@ XCODER_TEST_RECONF_VUI_HRD
Definition: ni_device_api.h:1784
ni_gettime_ns
uint64_t ni_gettime_ns(void)
Definition: ni_util.c:2622
_ni_encoder_cfg_params::chromaQpOffset
int chromaQpOffset
Definition: ni_device_api.h:2403
OPT2
#define OPT2(STR1, STR2)
_ni_frame::iovec
ni_iovec_t * iovec
Definition: ni_device_api.h:2811
NI_PIX_FMT_BGR0
@ NI_PIX_FMT_BGR0
Definition: ni_device_api.h:274
NI_KEEP_ALIVE_TIMEOUT
#define NI_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:2111
XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
Definition: ni_device_api.h:1793
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:4951
_ni_load_query::pcie_throughput
uint32_t pcie_throughput
Definition: ni_device_api.h:1218
NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
Definition: ni_device_api.h:1964
_ni_frameclone_desc
Definition: ni_device_api.h:1389
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1895
NI_EC_POLICY_LIMITED_ERROR
#define NI_EC_POLICY_LIMITED_ERROR
Definition: ni_device_api.h:336
_ni_xcoder_params::rootBufId
int rootBufId
Definition: ni_device_api.h:2878
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:16240
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:327
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:2799
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:10441
_ni_session_context::event_handle
ni_event_handle_t event_handle
Definition: ni_device_api.h:1605
XCODER_TEST_RECONF_FRAMERATE
@ XCODER_TEST_RECONF_FRAMERATE
Definition: ni_device_api.h:1791
NI_ENC_PARAM_RDO_QUANT
#define NI_ENC_PARAM_RDO_QUANT
Definition: ni_device_api.h:2189
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:2538
NI_MAX_GOP_SIZE
#define NI_MAX_GOP_SIZE
Definition: ni_device_api.h:153
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:1916
_ni_frame::aux_data
ni_aux_data_t * aux_data[NI_MAX_NUM_AUX_DATA_PER_FRAME]
Definition: ni_device_api.h:2774
ni_pthread_cond_destroy
int ni_pthread_cond_destroy(ni_pthread_cond_t *cond)
destroy condition variables
Definition: ni_util.c:4825
_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:2255
NI_ENC_PARAM_CBR
#define NI_ENC_PARAM_CBR
Definition: ni_device_api.h:2179
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:5550
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:10660
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:1934
NI_ENC_PARAM_ENABLE_AUD
#define NI_ENC_PARAM_ENABLE_AUD
Definition: ni_device_api.h:2193
_ni_encoder_cfg_params::enable_acq_limit
int enable_acq_limit
Definition: ni_device_api.h:2505
_ni_encoder_cfg_params::noMbtree
int noMbtree
Definition: ni_device_api.h:2476
XCODER_TEST_RECONF_INTRAPRD
@ XCODER_TEST_RECONF_INTRAPRD
Definition: ni_device_api.h:1783
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:6093
NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
#define NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
Definition: ni_device_api.h:2101
NI_ENC_PARAM_PRE_INTRA_HANDLING
#define NI_ENC_PARAM_PRE_INTRA_HANDLING
Definition: ni_device_api.h:2303
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:4007
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1496
NI_DEVICE_WRITE_ONLY
@ NI_DEVICE_WRITE_ONLY
Definition: ni_device_api.h:3052
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:17420
_ni_frame::start_len
uint32_t start_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2801
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:9054
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
Definition: ni_device_api.h:1986
NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
Definition: ni_device_api.h:2208
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:2636
_ni_encoder_cfg_params::roi_enable
int roi_enable
Definition: ni_device_api.h:2332
_ni_encoder_cfg_params::pastFrameMaxIntraRatio
int pastFrameMaxIntraRatio
Definition: ni_device_api.h:2523
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:307
_ni_encoder_cfg_params::intra_period
int intra_period
Definition: ni_device_api.h:2335
_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:2377
NI_ENC_PARAM_ENABLE_IP_RATIO
#define NI_ENC_PARAM_ENABLE_IP_RATIO
Definition: ni_device_api.h:2273
_ni_encoder_cfg_params::spatialLayerBitrate
int spatialLayerBitrate[NI_MAX_SPATIAL_LAYERS]
Definition: ni_device_api.h:2525
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
Definition: ni_device_api.h:2000
_ni_xcoder_params::generate_enc_hdrs
int generate_enc_hdrs
Definition: ni_device_api.h:2836
_ni_decoder_input_params_t::min_packets_delay
bool min_packets_delay
Definition: ni_device_api.h:2623
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
Definition: ni_device_api.h:1958
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
Definition: ni_device_api.h:1928
_ni_frame::separate_metadata
uint8_t separate_metadata
Definition: ni_device_api.h:2795
_ni_session_context::reconfig_slice_arg
int16_t reconfig_slice_arg
Definition: ni_device_api.h:1737
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:1784
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:11122
_ni_encoder_cfg_params::enable_pic_skip
int enable_pic_skip
Definition: ni_device_api.h:2445
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:1982
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:1385
_ni_network_perf_metrics
Definition: ni_device_api.h:1398
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:335
_ni_encoder_cfg_params::use_recommend_enc_params
int use_recommend_enc_params
Definition: ni_device_api.h:2421
_ni_thread_arg_struct_t::p_buffer
void * p_buffer
Definition: ni_device_api.h:1280
ni_parse_name
int32_t ni_parse_name(const char *arg, const char *const *names, bool *b_error)
Parse name.
Definition: ni_util.c:2594
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:2896
NI_MAX_USE_RECOMMENDED_ENC_PARAMS
#define NI_MAX_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:164
NI_ENC_PARAM_ENABLE_DYNAMIC_16X16_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_16X16_MERGE
Definition: ni_device_api.h:2141
_ni_load_query::fw_share_mem_usage
uint32_t fw_share_mem_usage
Definition: ni_device_api.h:1224
_ni_gop_params::pic_type
int pic_type
Definition: ni_device_api.h:2018
NI_DEC_PARAM_SKIP_EXTRA_HEADERS
#define NI_DEC_PARAM_SKIP_EXTRA_HEADERS
Definition: ni_device_api.h:2588
_ni_encoder_cfg_params::min_qp
int min_qp
Definition: ni_device_api.h:2441
NI_MIN_GOP_SIZE
#define NI_MIN_GOP_SIZE
Definition: ni_device_api.h:154
_ni_encoder_change_params_t::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:1017
NI_FRAME_AUX_DATA_SLICE_ARG
@ NI_FRAME_AUX_DATA_SLICE_ARG
Definition: ni_device_api.h:604
NI_UPLOADER_FLAG_LM
#define NI_UPLOADER_FLAG_LM
Definition: ni_device_api.h:318
NI_ENC_PARAM_HIGH_TIER
#define NI_ENC_PARAM_HIGH_TIER
Definition: ni_device_api.h:2130
_ni_encoder_cfg_params::gop_preset_index
int gop_preset_index
Definition: ni_device_api.h:2326
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1957
NI_ENC_PARAM_ADAPTIVE_LAMDA_MODE
#define NI_ENC_PARAM_ADAPTIVE_LAMDA_MODE
Definition: ni_device_api.h:2237
_ni_encoder_cfg_params::max_qp
int max_qp
Definition: ni_device_api.h:2442
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:5734
_ni_frame_config
Definition: ni_device_api.h:2912
_ni_encoder_cfg_params::ipRatio
float ipRatio
Definition: ni_device_api.h:2479
NI_PIX_FMT_BGRP
@ NI_PIX_FMT_BGRP
Definition: ni_device_api.h:275
NI_SCALER_FLAG_IO
#define NI_SCALER_FLAG_IO
Definition: ni_device_api.h:303
_ni_packet::av1_p_data
uint8_t * av1_p_data[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:3013
_ni_encoder_cfg_params::blockRCSize
int blockRCSize
Definition: ni_device_api.h:2411
NI_DEC_PARAM_CROP_MODE_2
#define NI_DEC_PARAM_CROP_MODE_2
Definition: ni_device_api.h:2549
_ni_encoder_cfg_params::av1OpLevel
int av1OpLevel[NI_MAX_SPATIAL_LAYERS]
Definition: ni_device_api.h:2527
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:2831
_ni_session_context::src_endian
int src_endian
Definition: ni_device_api.h:1524
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
Definition: ni_device_api.h:286
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:11829
_ni_session_context::low_delay_sync_mutex
ni_pthread_mutex_t low_delay_sync_mutex
Definition: ni_device_api.h:1696
_ni_encoder_cfg_params::intra_mb_refresh_mode
int intra_mb_refresh_mode
Definition: ni_device_api.h:2336
NI_ENC_PARAM_TOL_RC_INTER
#define NI_ENC_PARAM_TOL_RC_INTER
Definition: ni_device_api.h:2217
NI_MIN_RESOLUTION_WIDTH_SCALER
#define NI_MIN_RESOLUTION_WIDTH_SCALER
Definition: ni_device_api.h:97
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:10007
_ni_encoder_cfg_params::vbv_buffer_size
int vbv_buffer_size
Definition: ni_device_api.h:2452
_ni_packet::av1_buffer_size
uint32_t av1_buffer_size[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:3014
NI_ENC_GOP_PARAMS_G6_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G6_PIC_TYPE
Definition: ni_device_api.h:1980
_ni_frame::p_buffer
uint8_t * p_buffer
Definition: ni_device_api.h:2763
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
Definition: ni_device_api.h:2187
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:10777
NI_ENC_INLOOP_DS_RATIO
#define NI_ENC_INLOOP_DS_RATIO
Definition: ni_device_api.h:2220
_ni_encoder_cfg_params::noHWMultiPassSupport
int noHWMultiPassSupport
Definition: ni_device_api.h:2477
NI_ENC_PARAM_CONF_WIN_BOTTOM
#define NI_ENC_PARAM_CONF_WIN_BOTTOM
Definition: ni_device_api.h:2154
_ni_encoder_cfg_params::gdrDuration
int gdrDuration
Definition: ni_device_api.h:2359
_ni_xcoder_params::video_full_range_flag
int video_full_range_flag
Definition: ni_device_api.h:2864
XCODER_TEST_RECONF_VBV
@ XCODER_TEST_RECONF_VBV
Definition: ni_device_api.h:1796
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:2610
NI_EC_POLICY_BEST_EFFORT_OUT_DC
#define NI_EC_POLICY_BEST_EFFORT_OUT_DC
Definition: ni_device_api.h:337
_ni_encoder_cfg_params::aspectRatioWidth
int aspectRatioWidth
Definition: ni_device_api.h:2315
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:1898
_ni_session_context::avc_roi_map
ni_enc_avc_roi_custom_map_t * avc_roi_map
Definition: ni_device_api.h:1616
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:1888
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:16960
_ni_session_context::ppu_reconfig_pkt_pos
uint64_t ppu_reconfig_pkt_pos
Definition: ni_device_api.h:1760
_ni_scaler_input_params_t::input_height
int32_t input_height
Definition: ni_device_api.h:2640
_ni_session_context::buffered_frame_index
int16_t buffered_frame_index
Definition: ni_device_api.h:1748
NI_FRAME_BIG_ENDIAN
#define NI_FRAME_BIG_ENDIAN
Definition: ni_device_api.h:112
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1970
NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
#define NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
Definition: ni_device_api.h:2280
_ni_encoder_cfg_params::maxFrameSizeRatio
int maxFrameSizeRatio
Definition: ni_device_api.h:2319
_ni_decoder_input_params_t::enable_advanced_ec
int enable_advanced_ec
Definition: ni_device_api.h:2616
_ni_encoder_cfg_params::HDR10AveLight
int HDR10AveLight
Definition: ni_device_api.h:2346
_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:2215
XCODER_TEST_INVALID_REF_FRAME
@ XCODER_TEST_INVALID_REF_FRAME
Definition: ni_device_api.h:1790
NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:325
NI_ENC_PARAM_DDR_PRIORITY_MODE
#define NI_ENC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2277
NI_ENC_PARAM_SPATIAL_LAYER_BITRATE
#define NI_ENC_PARAM_SPATIAL_LAYER_BITRATE
Definition: ni_device_api.h:2307
NI_ENC_PARAM_GOP_LOW_DELAY
#define NI_ENC_PARAM_GOP_LOW_DELAY
Definition: ni_device_api.h:2196
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:2384
_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:2606
_ni_encoder_cfg_params::cu_size_mode
int cu_size_mode
Definition: ni_device_api.h:2423
_ni_packet::av1_data_len
uint32_t av1_data_len[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:3015
NI_ENC_PARAM_DOLBY_VISION_PROFILE
#define NI_ENC_PARAM_DOLBY_VISION_PROFILE
Definition: ni_device_api.h:2199
_ni_encoder_cfg_params::hrdEnable
int hrdEnable
Definition: ni_device_api.h:2378
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:9402
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1525
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
Definition: ni_device_api.h:1804
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1955
NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
#define NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
Definition: ni_device_api.h:2180
_ni_session_context::reconfig_crf_decimal
int reconfig_crf_decimal
Definition: ni_device_api.h:1717
_ni_encoder_change_params_t
This is a data structure for encoding parameters that have changed.
Definition: ni_device_api.h:996
_ni_encoder_cfg_params::encMallocStrategy
int encMallocStrategy
Definition: ni_device_api.h:2511
NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2556
_ni_xcoder_params::log
int log
Definition: ni_device_api.h:2816
_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:2419
_ni_session_context::mutex
ni_pthread_mutex_t mutex
Definition: ni_device_api.h:1596
_ni_encoder_cfg_params::max_num_merge
int max_num_merge
Definition: ni_device_api.h:2424
_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:2019
_ni_packet::av1_buffer_index
int av1_buffer_index
Definition: ni_device_api.h:3016
_ni_decoder_input_params_t::crop_mode
int crop_mode[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2598
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:16014
_ni_aux_data::size
int size
Definition: ni_device_api.h:636
_ni_encoder_cfg_params::crf
int crf
Definition: ni_device_api.h:2344
_ni_load_query::pcie_load
uint32_t pcie_load
Definition: ni_device_api.h:1222
NI_ENC_PARAM_BASE_LAYER_ONLY
#define NI_ENC_PARAM_BASE_LAYER_ONLY
Definition: ni_device_api.h:2304
NI_ENC_REPEAT_HEADERS_FIRST_IDR
#define NI_ENC_REPEAT_HEADERS_FIRST_IDR
Definition: ni_device_api.h:2109
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1509
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:1923
NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
Definition: ni_device_api.h:2142
_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:600
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:10717
NI_XCODER_PRESET_NAME_VERYFAST
#define NI_XCODER_PRESET_NAME_VERYFAST
Definition: ni_device_api.h:3060
_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:2819
NI_FRAME_AUX_DATA_VBV_MAX_RATE
@ NI_FRAME_AUX_DATA_VBV_MAX_RATE
Definition: ni_device_api.h:596
NI_DEC_PARAM_CROP_MODE_0
#define NI_DEC_PARAM_CROP_MODE_0
Definition: ni_device_api.h:2547
_ni_enc_quad_roi_custom_map::roiAbsQp_flag
uint8_t roiAbsQp_flag
Definition: ni_device_api.h:901
NI_MIN_BIN
#define NI_MIN_BIN
Definition: ni_device_api.h:178
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1914
NI_ENC_PARAM_IP_RATIO
#define NI_ENC_PARAM_IP_RATIO
Definition: ni_device_api.h:2272
_ni_device_extra_info::fw_flavour
uint8_t fw_flavour
Definition: ni_rsrc_api.h:249
NI_DEC_PARAM_MULTICORE_JOINT_MODE
#define NI_DEC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2565
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:4302
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:3497
NI_XCODER_OPEN_STATE
@ NI_XCODER_OPEN_STATE
Definition: ni_device_api.h:249
_ni_ppu_config::ppu_w
uint16_t ppu_w[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:1431
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1974
_ni_scaler_input_params_t::input_format
int input_format
Definition: ni_device_api.h:2638
_ni_xcoder_params::hdrEnableVUI
int hdrEnableVUI
Definition: ni_device_api.h:2846
NI_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:330
_ni_scaler_params_t
Definition: ni_device_api.h:2658
NI_ENC_GOP_PARAMS_G0_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G0_PIC_TYPE
Definition: ni_device_api.h:1890
_ni_scaler_input_params_t::out_rec_width
int32_t out_rec_width
Definition: ni_device_api.h:2649
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:347
_ni_encoder_cfg_params::enable_timecode
int enable_timecode
Definition: ni_device_api.h:2515
NI_ENC_GOP_PARAMS_G4_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G4_PIC_TYPE
Definition: ni_device_api.h:1950
NI_DEC_PARAM_ENABLE_OUT_1
#define NI_DEC_PARAM_ENABLE_OUT_1
Definition: ni_device_api.h:2539
_ni_session_context::reconfig_intra_period
int reconfig_intra_period
Definition: ni_device_api.h:1735
NI_ENC_PARAM_FORCE_FRAME_TYPE
#define NI_ENC_PARAM_FORCE_FRAME_TYPE
Definition: ni_device_api.h:2127
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:584
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:9350
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:8128
NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
Definition: ni_device_api.h:2209
NI_MAX_KEEP_ALIVE_TIMEOUT
#define NI_MAX_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:323
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_2
uint32_t sub_ctu_qp_2
Definition: ni_device_api.h:871
_ni_vui_hrd::colorPrimaries
int32_t colorPrimaries
Definition: ni_device_api.h:675
NI_MAX_DECODING_REFRESH_TYPE
#define NI_MAX_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:157
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_0
uint32_t sub_ctu_qp_0
Definition: ni_device_api.h:869
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:11183
SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
Definition: ni_device_api.h:1192
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:1656
NI_DEC_PARAM_SEMI_PLANAR_1
#define NI_DEC_PARAM_SEMI_PLANAR_1
Definition: ni_device_api.h:2545
ni_pthread_join
int ni_pthread_join(ni_pthread_t thread, void **value_ptr)
join with a terminated thread
Definition: ni_util.c:4777
_ni_network_data::output_num
uint32_t output_num
Definition: ni_device_api.h:1380
_ni_encoder_cfg_params::intra_mb_refresh_arg
int intra_mb_refresh_arg
Definition: ni_device_api.h:2337
SESSION_RUN_STATE_NORMAL
@ SESSION_RUN_STATE_NORMAL
Definition: ni_device_api.h:1191
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:3877
NI_ENC_GOP_PARAMS_G1_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G1_QP_OFFSET
Definition: ni_device_api.h:1902
NI_MAX_REF_PIC
#define NI_MAX_REF_PIC
Definition: ni_device_api.h:60
_ni_encoder_cfg_params::intraCompensateMode
int intraCompensateMode
Definition: ni_device_api.h:2533
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:4169
NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
#define NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
Definition: ni_device_api.h:490
NI_ENC_PARAM_MIN_FRAMES_DELAY
#define NI_ENC_PARAM_MIN_FRAMES_DELAY
Definition: ni_device_api.h:2135
_ni_encoder_cfg_params::pps_init_qp
int pps_init_qp
Definition: ni_device_api.h:2482
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:18807
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:2190
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
Definition: ni_device_api.h:1924
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1908
_ni_encoder_cfg_params::gopSize
int gopSize
Definition: ni_device_api.h:2398
_ni_session_context::reconfig_vbv_buffer_size
int reconfig_vbv_buffer_size
Definition: ni_device_api.h:1719
_ni_session_context::framerate
ni_framerate_t framerate
Definition: ni_device_api.h:1635
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:1660
_ni_session_context::pext_mutex
ni_pthread_mutex_t * pext_mutex
Definition: ni_device_api.h:1701
_ni_frame::iovec_num
uint32_t iovec_num
Definition: ni_device_api.h:2810
_ni_thread_arg_struct_t::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1278
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
Definition: ni_device_api.h:1941
_ni_decoder_input_params_t::crop_whxy
int crop_whxy[NI_MAX_NUM_OF_DECODER_OUTPUTS][4]
Definition: ni_device_api.h:2599
_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:484
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:3462
_ni_encoder_cfg_params::qlevel
int qlevel
Definition: ni_device_api.h:2393
NI_MAX_SPATIAL_LAYERS
#define NI_MAX_SPATIAL_LAYERS
Definition: ni_device_api.h:183
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:2607
_ni_custom_gop_params::custom_gop_size
int custom_gop_size
Definition: ni_device_api.h:2105
XCODER_TEST_RECONF_OFF
@ XCODER_TEST_RECONF_OFF
Definition: ni_device_api.h:1781
_ni_scaler_input_params_t::rgba_color
uint32_t rgba_color
Definition: ni_device_api.h:2654
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:2200
NI_PARAM_MAX_HEIGHT
#define NI_PARAM_MAX_HEIGHT
Definition: ni_device_api.h:140
_niFrameSurface1::ui16FrameIdx
uint16_t ui16FrameIdx
Definition: ni_device_api.h:2899
NI_ENC_PARAM_CACHE_ROI
#define NI_ENC_PARAM_CACHE_ROI
Definition: ni_device_api.h:2119
_ni_encoder_cfg_params::preset_enabled
int preset_enabled
Definition: ni_device_api.h:2528
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:3361
_ni_encoder_cfg_params::HDR10dx2
int HDR10dx2
Definition: ni_device_api.h:2353
_ni_long_term_ref
Definition: ni_device_api.h:697
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:671
NI_MAX_INTRA_QP
#define NI_MAX_INTRA_QP
Definition: ni_device_api.h:168
_ni_session_context::reconfig_vbv_max_rate
int reconfig_vbv_max_rate
Definition: ni_device_api.h:1720
NI_ENC_PARAM_SPATIAL_LAYERS
#define NI_ENC_PARAM_SPATIAL_LAYERS
Definition: ni_device_api.h:2296
NI_ENC_PARAM_INTRA_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_REFRESH_ARG
Definition: ni_device_api.h:2173
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:15923
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:10961
NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
Definition: ni_device_api.h:1966
NI_DEC_PARAM_CROP_PARAM_0
#define NI_DEC_PARAM_CROP_PARAM_0
Definition: ni_device_api.h:2550
NI_DEC_PARAM_CROP_PARAM_1
#define NI_DEC_PARAM_CROP_PARAM_1
Definition: ni_device_api.h:2551
_ni_encoder_cfg_params::HDR10wx
int HDR10wx
Definition: ni_device_api.h:2355
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:11999
NI_XCODER_PRESET_NAME_VERYSLOW
#define NI_XCODER_PRESET_NAME_VERYSLOW
Definition: ni_device_api.h:3066
NI_ENC_PARAM_ENABLE_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_RATE_CONTROL
Definition: ni_device_api.h:2143
NI_ENC_PARAM_VBV_BUFFER_REENCODE
#define NI_ENC_PARAM_VBV_BUFFER_REENCODE
Definition: ni_device_api.h:2300
atof
#define atof(p_str)
Definition: ni_device_api.c:7532
_ni_xcoder_params::source_height
int source_height
Definition: ni_device_api.h:2829
NI_ENC_GOP_PARAMS_G5_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G5_QP_OFFSET
Definition: ni_device_api.h:1962
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:2602
_ni_encoder_cfg_params::rcQpDeltaRange
int rcQpDeltaRange
Definition: ni_device_api.h:2415
_ni_encoder_change_params_t::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:1015
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:2749
XCODER_TEST_RECONF_BR_API
@ XCODER_TEST_RECONF_BR_API
Definition: ni_device_api.h:1800
_ni_encoder_cfg_params::hvsBaseMbComplexity
int hvsBaseMbComplexity
Definition: ni_device_api.h:2486
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:160
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:2724
_ni_session_context::src_bit_depth
int src_bit_depth
Definition: ni_device_api.h:1523
_ni_ppu_config::ppu_set_enable
uint8_t ppu_set_enable
Definition: ni_device_api.h:1430
NI_FRAME_AUX_DATA_VUI
@ NI_FRAME_AUX_DATA_VUI
Definition: ni_device_api.h:557
ni_buf_pool_get_buffer
ni_buf_t * ni_buf_pool_get_buffer(ni_buf_pool_t *p_buffer_pool)
Definition: ni_util.c:1091
_ni_vui_hrd::colorTrc
int32_t colorTrc
Definition: ni_device_api.h:679
NI_MAX_RESOLUTION_WIDTH
#define NI_MAX_RESOLUTION_WIDTH
Definition: ni_device_api.h:103
_ni_framerate::framerate_num
int32_t framerate_num
Definition: ni_device_api.h:712
NI_VPU_ALIGN16
#define NI_VPU_ALIGN16(_x)
Definition: ni_device_api.h:345
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:5242
_ni_encoder_cfg_params::HDR10maxluma
int HDR10maxluma
Definition: ni_device_api.h:2357
_ni_network_data::linfo
ni_network_layer_info_t linfo
Definition: ni_device_api.h:1381
_niFrameSurface1::ui16session_ID
uint16_t ui16session_ID
Definition: ni_device_api.h:2900
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:158
_ni_xcoder_params::cfg_enc_params
ni_encoder_cfg_params_t cfg_enc_params
Definition: ni_device_api.h:2868
NI_ENC_PARAM_RDO_LEVEL
#define NI_ENC_PARAM_RDO_LEVEL
Definition: ni_device_api.h:2188
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:10138
NI_ENC_PARAM_PROFILE
#define NI_ENC_PARAM_PROFILE
Definition: ni_device_api.h:2128
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:2163
_ni_xcoder_params::enableCpuAffinity
int enableCpuAffinity
Definition: ni_device_api.h:2894
_ni_encoder_cfg_params::vbv_max_rate
int vbv_max_rate
Definition: ni_device_api.h:2453
_ni_gop_params::qp_factor
float qp_factor
Definition: ni_device_api.h:2016
NI_ENC_PARAM_INTRA_COMPENSATE_MODE
#define NI_ENC_PARAM_INTRA_COMPENSATE_MODE
Definition: ni_device_api.h:2239
_ni_encoder_cfg_params::preset_index
int preset_index
Definition: ni_device_api.h:2529
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:1152
_ni_xcoder_params::force_frame_type
int force_frame_type
Definition: ni_device_api.h:2843
_ni_gop_rps::ref_pic
int ref_pic
Definition: ni_device_api.h:2008
NI_XCODER_IDLE_STATE
@ NI_XCODER_IDLE_STATE
Definition: ni_device_api.h:248
NI_PIX_FMT_NV12
@ NI_PIX_FMT_NV12
Definition: ni_device_api.h:268
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:7550
XCODER_TEST_RECONF_INTRAPRD_API
@ XCODER_TEST_RECONF_INTRAPRD_API
Definition: ni_device_api.h:1801
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2761
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:13977
_ni_session_context::pixel_format_changed
int pixel_format_changed
Definition: ni_device_api.h:1736
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:2443
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:1932
PIC_TYPE_I
@ PIC_TYPE_I
Definition: ni_device_api.h:398
_ni_encoder_cfg_params::enable_rate_control
int enable_rate_control
Definition: ni_device_api.h:2440
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:2494
NI_PIXEL_PLANAR_MAX
@ NI_PIXEL_PLANAR_MAX
Definition: ni_device_api.h:937
_ni_decoder_input_params_t::semi_planar
int semi_planar[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2597
_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:2625
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:8716
_ni_scaler_input_params_t::out_rec_y
int32_t out_rec_y
Definition: ni_device_api.h:2652
NI_MIN_USE_RECOMMENDED_ENC_PARAMS
#define NI_MIN_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:165
NI_ENC_PARAM_INTRA_MB_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_MB_REFRESH_ARG
Definition: ni_device_api.h:2171
NI_DEC_PARAM_SCALE_0_ROUND
#define NI_DEC_PARAM_SCALE_0_ROUND
Definition: ni_device_api.h:2562
_ni_decoder_input_params_t::hwframes
int hwframes
Definition: ni_device_api.h:2591
_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:12999
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:14572
_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:1289
_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:2893
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:5462
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:2364
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:4311
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:4209
_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:2876
NI_FRAME_AUX_DATA_FRAMERATE
@ NI_FRAME_AUX_DATA_FRAMERATE
Definition: ni_device_api.h:576
_ni_xcoder_params::enable_ai_enhance
int enable_ai_enhance
Definition: ni_device_api.h:2884
_ni_load_query::tp_fw_load
uint32_t tp_fw_load
Definition: ni_device_api.h:1228
NI_ENC_PARAM_LTR_REF_QPOFFSET
#define NI_ENC_PARAM_LTR_REF_QPOFFSET
Definition: ni_device_api.h:2211
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:3519
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:2257
_ni_thread_arg_struct_t::device_type
uint32_t device_type
Definition: ni_device_api.h:1277
NI_ENC_PARAM_TUNE_BFRAME_VISUAL
#define NI_ENC_PARAM_TUNE_BFRAME_VISUAL
Definition: ni_device_api.h:2288
_ni_decoder_input_params_t
Definition: ni_device_api.h:2536
NI_XCODER_HWUP_STATE
@ NI_XCODER_HWUP_STATE
Definition: ni_device_api.h:258
NI_CUS_ROI_DISABLE
@ NI_CUS_ROI_DISABLE
Definition: ni_device_api.h:294
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:13392
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:2350
NI_ENC_GOP_PARAMS_G2_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G2_PIC_TYPE
Definition: ni_device_api.h:1920
_ni_encoder_cfg_params::enable_dynamic_8x8_merge
int enable_dynamic_8x8_merge
Definition: ni_device_api.h:2425
_ni_encoder_cfg_params::ctbRcMode
int ctbRcMode
Definition: ni_device_api.h:2397
_ni_scaler_drawbox_params_t
Definition: ni_device_api.h:2667
_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:2191
_ni_thread_arg_struct_t::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1282
NI_ENC_PARAM_SAR_NUM
#define NI_ENC_PARAM_SAR_NUM
Definition: ni_device_api.h:2245
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:2194
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:2366
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:1252
NI_ENC_PARAM_PB_RATIO
#define NI_ENC_PARAM_PB_RATIO
Definition: ni_device_api.h:2274
_ni_xcoder_params::interval_of_psnr
int interval_of_psnr
Definition: ni_device_api.h:2892
NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
Definition: ni_device_api.h:2170
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1959
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:9134
NI_ENC_PARAM_ENABLE_FILLER
#define NI_ENC_PARAM_ENABLE_FILLER
Definition: ni_device_api.h:2202
_ni_session_context::headers_length
uint32_t headers_length
Definition: ni_device_api.h:1762
NI_ENC_PARAM_ENABLE_HVS_QP
#define NI_ENC_PARAM_ENABLE_HVS_QP
Definition: ni_device_api.h:2145
ni_device_extra_info_t
struct _ni_device_extra_info ni_device_extra_info_t
_ni_buf_t
Definition: ni_device_api.h:1286
NI_CODEC_HW_DOWNLOAD
@ NI_CODEC_HW_DOWNLOAD
Definition: ni_device_api.h:955
PIC_TYPE_IDR
@ PIC_TYPE_IDR
Definition: ni_device_api.h:403
ni_pthread_mutex_lock
int ni_pthread_mutex_lock(ni_pthread_mutex_t *mutex)
thread mutex lock
Definition: ni_util.c:4686
NI_ENC_GOP_PARAMS_G0_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G0_POC_OFFSET
Definition: ni_device_api.h:1886
_niFrameSurface1::encoding_type
int8_t encoding_type
Definition: ni_device_api.h:2906
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:15613
_ni_xcoder_params::hwframes
int hwframes
Definition: ni_device_api.h:2877
NI_PIX_FMT_NV16
@ NI_PIX_FMT_NV16
Definition: ni_device_api.h:276
_ni_encoder_cfg_params::newRcEnable
int newRcEnable
Definition: ni_device_api.h:2466
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1493
_ni_session_context::enc_change_params
ni_encoder_change_params_t * enc_change_params
Definition: ni_device_api.h:1623
atobool
#define atobool(p_str)
Definition: ni_device_api.c:7533
_ni_session_context::p_session_config
void * p_session_config
Definition: ni_device_api.h:1504
NI_CODEC_FORMAT_AV1
@ NI_CODEC_FORMAT_AV1
Definition: ni_device_api.h:929
_ni_encoder_cfg_params::skip_frame_enable
int skip_frame_enable
Definition: ni_device_api.h:2493
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:1336
NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:2572
XCODER_TEST_RECONF_SLICE_ARG_API
@ XCODER_TEST_RECONF_SLICE_ARG_API
Definition: ni_device_api.h:1814
NI_ENC_PARAM_CHROMA_QP_OFFSET
#define NI_ENC_PARAM_CHROMA_QP_OFFSET
Definition: ni_device_api.h:2216
_ni_packet::av1_p_buffer
uint8_t * av1_p_buffer[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:3012
NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
Definition: ni_device_api.h:2579
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:332
_ni_enc_avc_roi_custom_map::mb_qp
uint8_t mb_qp
Definition: ni_device_api.h:889
NI_ENC_PARAM_RECONF_DEMO_MODE
#define NI_ENC_PARAM_RECONF_DEMO_MODE
Definition: ni_device_api.h:2116
NI_DDR_PRIORITY_MAX
@ NI_DDR_PRIORITY_MAX
Definition: ni_device_api.h:1869
NI_ENC_GOP_PARAMS_G5_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G5_POC_OFFSET
Definition: ni_device_api.h:1961
_ni_encoder_cfg_params::entropy_coding_mode
int entropy_coding_mode
Definition: ni_device_api.h:2382
NI_ENC_PARAM_INTRA_QP_DELTA
#define NI_ENC_PARAM_INTRA_QP_DELTA
Definition: ni_device_api.h:2225
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:11761
_ni_packet::p_data
void * p_data
Definition: ni_device_api.h:3005
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:5064
NI_ENC_PARAM_VBV_MAXRAE
#define NI_ENC_PARAM_VBV_MAXRAE
Definition: ni_device_api.h:2201
_ni_session_data_io
Definition: ni_device_api.h:3034
_ni_enc_quad_roi_custom_map::ipcm_flag
uint8_t ipcm_flag
Definition: ni_device_api.h:905
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:13776
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:12332
NI_MAX_CUSTOM_SEI_PASSTHRU
#define NI_MAX_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:328
NI_ENC_PARAM_MAX_DELTA_QP
#define NI_ENC_PARAM_MAX_DELTA_QP
Definition: ni_device_api.h:2150
_ni_decoder_input_params_t::svct_decoding_layer
int svct_decoding_layer
Definition: ni_device_api.h:2614
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1940
_ni_encoder_cfg_params::ltrFirstGap
int ltrFirstGap
Definition: ni_device_api.h:2362
NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
#define NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
Definition: ni_device_api.h:2137
_ni_encoder_cfg_params::ltrRefQpOffset
int ltrRefQpOffset
Definition: ni_device_api.h:2361
_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:2235
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:2573
ni_device_open
NI_DEPRECATED 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:374
NI_DEVICE_READ_WRITE
@ NI_DEVICE_READ_WRITE
Definition: ni_device_api.h:3053
NI_PIX_FMT_YUV420P10LE
@ NI_PIX_FMT_YUV420P10LE
Definition: ni_device_api.h:267
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:2560
NI_ENC_GOP_PARAMS_G7_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G7_POC_OFFSET
Definition: ni_device_api.h:1991
_ni_scaler_input_params_t::in_rec_x
int32_t in_rec_x
Definition: ni_device_api.h:2643
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1998
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:17884
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:2431
_ni_session_context::sender_handle
ni_device_handle_t sender_handle
Definition: ni_device_api.h:1499
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:15805
NI_ENC_PARAM_AI_ENHANCE_LEVEL
#define NI_ENC_PARAM_AI_ENHANCE_LEVEL
Definition: ni_device_api.h:2261
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:2484
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:9605
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:11362
ni_rsrc_unlock
int ni_rsrc_unlock(int device_type, ni_lock_handle_t lock)
unlock a file lock
Definition: ni_rsrc_api.cpp:2780
QOS_NAMESPACE_CODE
@ QOS_NAMESPACE_CODE
Definition: ni_device_api.h:240
NI_MAX_GOP_NUM
#define NI_MAX_GOP_NUM
Definition: ni_device_api.h:58
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:495
_ni_encoder_cfg_params::enable_smooth_crf
int enable_smooth_crf
Definition: ni_device_api.h:2512
_ni_device_info::model_load
int model_load
Definition: ni_rsrc_api.h:109
_ni_network_layer_info
Definition: ni_device_api.h:1366
_ni_session_context::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1552
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:10228
_ni_encoder_cfg_params::totalCuTreeDepth
int totalCuTreeDepth
Definition: ni_device_api.h:2519
_ni_encoder_cfg_params::customize_roi_qp_level
int customize_roi_qp_level
Definition: ni_device_api.h:2507
_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:17284
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
Definition: ni_device_api.h:1896
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:4253
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:4048
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:10054
NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
Definition: ni_device_api.h:2227
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:4847
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:2198
_ni_encoder_cfg_params
Definition: ni_device_api.h:2113
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
Definition: ni_device_api.h:1973
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1910
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
Definition: ni_device_api.h:1907
NI_DEC_PARAM_ENABLE_ADVANCED_EC
#define NI_DEC_PARAM_ENABLE_ADVANCED_EC
Definition: ni_device_api.h:2576
NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
#define NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
Definition: ni_device_api.h:2286
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
Definition: ni_device_api.h:1984
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1912
_ni_encoder_cfg_params::EnableAUD
int EnableAUD
Definition: ni_device_api.h:2376
NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
Definition: ni_device_api.h:1994
_ni_encoder_cfg_params::spatial_layers
int spatial_layers
Definition: ni_device_api.h:2514
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:11539
ni_usleep
void ni_usleep(int64_t usec)
Definition: ni_util.c:362
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:11767
_ni_encoder_cfg_params::scene_change_detect_level
int scene_change_detect_level
Definition: ni_device_api.h:2510
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:18002
NI_ENC_PARAM_PADDING
#define NI_ENC_PARAM_PADDING
Definition: ni_device_api.h:2126
_ni_session_context::device_type
uint32_t device_type
Definition: ni_device_api.h:1515
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:1483
NI_ENC_PARAM_CPLX_DECAY
#define NI_ENC_PARAM_CPLX_DECAY
Definition: ni_device_api.h:2275
_ni_frame::force_key_frame
int force_key_frame
Definition: ni_device_api.h:2721
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:3043
ni_device_mode_t
enum _ni_device_mode ni_device_mode_t
Device access mode enumeration.
LRETURN
#define LRETURN
Definition: ni_defs.h:337
NI_VPU_ALIGN32
#define NI_VPU_ALIGN32(_x)
Definition: ni_device_api.h:346
NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
Definition: ni_device_api.h:934
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1893
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:4100
NI_MAX_HEIGHT
#define NI_MAX_HEIGHT
Definition: ni_device_api.h:128
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:1972
_ni_encoder_cfg_params::HDR10CLLEnable
int HDR10CLLEnable
Definition: ni_device_api.h:2347
NI_ENC_PARAM_HORIZONTAL_OFFSET
#define NI_ENC_PARAM_HORIZONTAL_OFFSET
Definition: ni_device_api.h:2265
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
Definition: ni_device_api.h:1952
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:635
_ni_frame::dec_buf
ni_buf_t * dec_buf
Definition: ni_device_api.h:2767
_ni_xcoder_params::chroma_linesize
int chroma_linesize
Definition: ni_device_api.h:2888
_ni_xcoder_params::minFramesDelay
int minFramesDelay
Definition: ni_device_api.h:2891
_ni_xcoder_params::sar_num
int sar_num
Definition: ni_device_api.h:2862
NI_VPU_ALIGN128
#define NI_VPU_ALIGN128(_x)
Definition: ni_device_api.h:348
XCODER_TEST_RECONF_RC_MIN_MAX_QP
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP
Definition: ni_device_api.h:1787
NI_ENC_PARAM_CU_TREE_FACTOR
#define NI_ENC_PARAM_CU_TREE_FACTOR
Definition: ni_device_api.h:2271
NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
#define NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
Definition: ni_device_api.h:2248
_ni_packet
Definition: ni_device_api.h:2993
_ni_buf_pool_t
Definition: ni_device_api.h:1296
NI_DEC_PARAM_SCALE_2_ROUND
#define NI_DEC_PARAM_SCALE_2_ROUND
Definition: ni_device_api.h:2564
_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:2294
_ni_session_context::frame_num
uint64_t frame_num
Definition: ni_device_api.h:1562
_ni_encoder_cfg_params::HDR10Enable
int HDR10Enable
Definition: ni_device_api.h:2348
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:262
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_1
uint32_t sub_ctu_qp_1
Definition: ni_device_api.h:870
_ni_encoder_cfg_params::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2461
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:11651
_ni_encoder_cfg_params::intra_qp_delta
int intra_qp_delta
Definition: ni_device_api.h:2444
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
Definition: ni_device_api.h:2004
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:14018
_ni_xcoder_params::ai_enhance_level
int ai_enhance_level
Definition: ni_device_api.h:2889
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
Definition: ni_device_api.h:1939
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:1961
_ni_session_context::roi_map
ni_enc_quad_roi_custom_map * roi_map
Definition: ni_device_api.h:1613
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:1615
_ni_network_layer_offset::offset
int32_t offset
Definition: ni_device_api.h:1374
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1987
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:2716
NI_VPU_ALIGN8
#define NI_VPU_ALIGN8(_x)
Definition: ni_device_api.h:344
_ni_encoder_cfg_params::colorDescPresent
int colorDescPresent
Definition: ni_device_api.h:2386
NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2558
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1927
NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
Definition: ni_device_api.h:1936
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:2117
_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:11451
_ni_session_context::last_gop_size
int last_gop_size
Definition: ni_device_api.h:1722
_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:2404
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:19141
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2760
NI_ENC_GOP_PARAMS_G7_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G7_QP_OFFSET
Definition: ni_device_api.h:1992
_ni_encoder_cfg_params::custom_gop_params
ni_custom_gop_params_t custom_gop_params
Definition: ni_device_api.h:2330
NI_VPU_CEIL
#define NI_VPU_CEIL(_data, _align)
Definition: ni_device_api.h:342
_ni_encoder_cfg_params::HDR10dx0
int HDR10dx0
Definition: ni_device_api.h:2349
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:4750
NI_EC_POLICY_DEFAULT
#define NI_EC_POLICY_DEFAULT
Definition: ni_device_api.h:338
_ni_xcoder_params::zerocopy_mode
int zerocopy_mode
Definition: ni_device_api.h:2886
_ni_xcoder_params::sar_denom
int sar_denom
Definition: ni_device_api.h:2863
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:8870
_ni_decoder_input_params_t::max_extra_hwframe_cnt
int max_extra_hwframe_cnt
Definition: ni_device_api.h:2619
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:2221
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:9233
_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:2502
ni_strcasecmp
int ni_strcasecmp(const char *a, const char *b)
Definition: ni_device_api.c:12988
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
Definition: ni_device_api.h:1892
XCODER_TEST_RECONF_VBV_API
@ XCODER_TEST_RECONF_VBV_API
Definition: ni_device_api.h:1812
XCODER_TEST_FORCE_IDR_FRAME
@ XCODER_TEST_FORCE_IDR_FRAME
Definition: ni_device_api.h:1799
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:2644
_ni_encoder_cfg_params::tolCtbRcIntra
float tolCtbRcIntra
Definition: ni_device_api.h:2405
NI_XCODER_WRITE_STATE
@ NI_XCODER_WRITE_STATE
Definition: ni_device_api.h:250
NI_ENC_PARAM_ADAPTIVE_CRF_MODE
#define NI_ENC_PARAM_ADAPTIVE_CRF_MODE
Definition: ni_device_api.h:2238
NI_XCODER_LOG_NAMES_ARRAY_LEN
#define NI_XCODER_LOG_NAMES_ARRAY_LEN
Definition: ni_device_api.h:3057
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:4729
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:2497
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:3944
_ni_decoder_input_params_t::enable_all_sei_passthru
bool enable_all_sei_passthru
Definition: ni_device_api.h:2622
NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
#define NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
Definition: ni_device_api.h:2281
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:2501
NI_ENC_PARAM_SKIP_FRAME_INTERVAL
#define NI_ENC_PARAM_SKIP_FRAME_INTERVAL
Definition: ni_device_api.h:2231
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:2575
NI_DEC_PARAM_ERROR_THRESHOLD
#define NI_DEC_PARAM_ERROR_THRESHOLD
Definition: ni_device_api.h:2577
_ni_session_context::vui
ni_vui_hrd_t vui
Definition: ni_device_api.h:1636
_ni_encoder_cfg_params::enable_dynamic_16x16_merge
int enable_dynamic_16x16_merge
Definition: ni_device_api.h:2426
NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
#define NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
Definition: ni_device_api.h:2242
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:13177
NI_PARAM_AV1_ALIGN_WIDTH_HEIGHT
#define NI_PARAM_AV1_ALIGN_WIDTH_HEIGHT
Definition: ni_device_api.h:151
_ni_session_context::hw_action
int hw_action
Definition: ni_device_api.h:1640
NI_ENC_PARAM_LOG
#define NI_ENC_PARAM_LOG
Definition: ni_device_api.h:2132
NI_ENC_PARAM_SKIP_FRAME_ENABLE
#define NI_ENC_PARAM_SKIP_FRAME_ENABLE
Definition: ni_device_api.h:2229
_ni_session_context
Definition: ni_device_api.h:1435
_ni_rc_min_max_qp::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:723
_ni_encoder_cfg_params::iframe_size_ratio
int iframe_size_ratio
Definition: ni_device_api.h:2498
_ni_scaler_input_params_t::out_rec_x
int32_t out_rec_x
Definition: ni_device_api.h:2651
_ni_scaler_input_params_t::input_width
int32_t input_width
Definition: ni_device_api.h:2639
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:269
ni_memfree
#define ni_memfree(p_memptr)
Definition: ni_util.h:410
_ni_session_context::bus
unsigned short bus
Definition: ni_device_api.h:1651
NI_ENC_PARAM_FORCED_HEADER_ENABLE
#define NI_ENC_PARAM_FORCED_HEADER_ENABLE
Definition: ni_device_api.h:2151
NI_ENC_PARAM_BITRATE_WINDOW
#define NI_ENC_PARAM_BITRATE_WINDOW
Definition: ni_device_api.h:2219
_ni_thread_arg_struct_t::hw_id
int hw_id
Definition: ni_device_api.h:1273
NI_ENC_PARAM_ENABLE_VFR
#define NI_ENC_PARAM_ENABLE_VFR
Definition: ni_device_api.h:2250
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:2123
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:1932
_niFrameSurface1
Definition: ni_device_api.h:2897
NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
Definition: ni_device_api.h:2140
NI_EC_ERR_THRESHOLD_DEFAULT
#define NI_EC_ERR_THRESHOLD_DEFAULT
Definition: ni_device_api.h:339
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:8752
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:13300
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
Definition: ni_device_api.h:2003
NI_XCODER_GENERAL_STATE
@ NI_XCODER_GENERAL_STATE
Definition: ni_device_api.h:261
NI_ENC_PARAM_INTRA_REFRESH_RESET
#define NI_ENC_PARAM_INTRA_REFRESH_RESET
Definition: ni_device_api.h:2163
NI_PARAM_AV1_MAX_HEIGHT
#define NI_PARAM_AV1_MAX_HEIGHT
Definition: ni_device_api.h:149
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:2520
ni_pthread_mutex_init
int ni_pthread_mutex_init(ni_pthread_mutex_t *mutex)
initialize a mutex
Definition: ni_util.c:4630
_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:146
_ni_session_context::blk_xcoder_name
char blk_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1521
_ni_frame
Definition: ni_device_api.h:2698
NI_ENC_GOP_PARAMS_G0_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G0_QP_OFFSET
Definition: ni_device_api.h:1887
NI_ENC_PARAM_PAST_FRAME_MAX_INTRA_RATIO
#define NI_ENC_PARAM_PAST_FRAME_MAX_INTRA_RATIO
Definition: ni_device_api.h:2305
_ni_network_data::input_num
uint32_t input_num
Definition: ni_device_api.h:1379
_ni_encoder_cfg_params::HDR10dy1
int HDR10dy1
Definition: ni_device_api.h:2352
NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
#define NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
Definition: ni_device_api.h:2234
NI_PIX_FMT_YUYV422
@ NI_PIX_FMT_YUYV422
Definition: ni_device_api.h:277
NI_PIX_FMT_RGBA
@ NI_PIX_FMT_RGBA
Definition: ni_device_api.h:270
_ni_encoder_change_params_t::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:1018
_ni_encoder_cfg_params::conf_win_bottom
int conf_win_bottom
Definition: ni_device_api.h:2373
_ni_decoder_input_params_t::scale_round
int scale_round[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2627
NI_ENC_PARAM_IFRAME_SIZE_RATIO
#define NI_ENC_PARAM_IFRAME_SIZE_RATIO
Definition: ni_device_api.h:2232
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:876
_ni_session_context::roi_len
uint32_t roi_len
Definition: ni_device_api.h:1527
_ni_encoder_cfg_params::linkFrameMaxIntraRatio
int linkFrameMaxIntraRatio
Definition: ni_device_api.h:2524
NI_DDR_PRIORITY_NONE
@ NI_DDR_PRIORITY_NONE
Definition: ni_device_api.h:1864
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:136
_ni_encoder_cfg_params::profile
int profile
Definition: ni_device_api.h:2323
_ni_resolution::width
int32_t width
Definition: ni_device_api_priv.h:906
XCODER_TEST_RECONF_VUI_HRD_API
@ XCODER_TEST_RECONF_VUI_HRD_API
Definition: ni_device_api.h:1802
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:2389
_ni_session_context::max_frame_delay
int max_frame_delay
Definition: ni_device_api.h:1725
_ni_gop_params::rps
ni_gop_rps_t rps[NI_MAX_REF_PIC]
Definition: ni_device_api.h:2020
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:2833
NI_DEC_CROP_MODE_MANUAL
@ NI_DEC_CROP_MODE_MANUAL
Definition: ni_device_api.h:944
XCODER_TEST_RECONF_LONG_TERM_REF
@ XCODER_TEST_RECONF_LONG_TERM_REF
Definition: ni_device_api.h:1785
NI_ENC_PARAM_GOP_PRESET_IDX
#define NI_ENC_PARAM_GOP_PRESET_IDX
Definition: ni_device_api.h:2133
NI_ENC_PARAM_ENTROPY_CODING_MODE
#define NI_ENC_PARAM_ENTROPY_CODING_MODE
Definition: ni_device_api.h:2166
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:352
NI_CUS_ROI_MERGE
@ NI_CUS_ROI_MERGE
Definition: ni_device_api.h:298
_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:2406
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:1943
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:14215
NI_PIX_FMT_ABGR
@ NI_PIX_FMT_ABGR
Definition: ni_device_api.h:273
ni_strtok
char * ni_strtok(char *s, const char *delim, char **saveptr)
Definition: ni_util.c:424
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:8368
_ni_enc_hevc_roi_custom_map::field
struct _ni_enc_hevc_roi_custom_map::@4 field
NI_PRESETS_NONE
@ NI_PRESETS_NONE
Definition: ni_device_api.h:1874
_ni_load_query::total_pixel_load
uint32_t total_pixel_load
Definition: ni_device_api.h:1231
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:272
NI_ENC_PARAM_CONSTANT_RATE_FACTOR
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR
Definition: ni_device_api.h:2185
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:10535
_ni_xcoder_params
Definition: ni_device_api.h:2814
NI_ENC_PARAM_MULTICORE_JOINT_MODE
#define NI_ENC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2214
NI_DEC_PARAM_CROP_PARAM_2
#define NI_DEC_PARAM_CROP_PARAM_2
Definition: ni_device_api.h:2552
_ni_session_context::p_hdr_buf
uint8_t * p_hdr_buf
Definition: ni_device_api.h:1542
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:2175
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
Definition: ni_device_api.h:2267
NI_XCODER_READ_DESC_STATE
@ NI_XCODER_READ_DESC_STATE
Definition: ni_device_api.h:257
_ni_decoder_input_params_t::reduce_dpb_delay
int reduce_dpb_delay
Definition: ni_device_api.h:2632
_ni_encoder_cfg_params::max_delta_qp
int max_delta_qp
Definition: ni_device_api.h:2457
_ni_xcoder_params::staticMmapThreshold
int staticMmapThreshold
Definition: ni_device_api.h:2883
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:1729
_ni_encoder_cfg_params::ctbRowQpStep
int ctbRowQpStep
Definition: ni_device_api.h:2465
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
Definition: ni_device_api.h:2002
NI_ENC_PARAM_COLOR_SPACE
#define NI_ENC_PARAM_COLOR_SPACE
Definition: ni_device_api.h:2243
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
Definition: ni_device_api.h:1926
_ni_session_context::low_delay_sync_cond
ni_pthread_cond_t low_delay_sync_cond
Definition: ni_device_api.h:1697
NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
#define NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
Definition: ni_device_api.h:2233
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
Definition: ni_device_api.h:1969
_ni_encoder_cfg_params::motionConstrainedMode
int motionConstrainedMode
Definition: ni_device_api.h:2508
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:14110
NI_ENC_GOP_PARAMS_G4_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G4_POC_OFFSET
Definition: ni_device_api.h:1946
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
Definition: ni_device_api.h:1813
_ni_session_context::ready_to_close
uint32_t ready_to_close
Definition: ni_device_api.h:1575
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1942
_ni_session_context::thread_event_handle
ni_event_handle_t thread_event_handle
Definition: ni_device_api.h:1606
NI_PARAM_AV1_MIN_HEIGHT
#define NI_PARAM_AV1_MIN_HEIGHT
Definition: ni_device_api.h:147
_ni_encoder_cfg_params::decoding_refresh_type
int decoding_refresh_type
Definition: ni_device_api.h:2435
NI_XCODER_LOG_NAME_ERROR
#define NI_XCODER_LOG_NAME_ERROR
Definition: ni_device_api.h:3069
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:3236
_ni_load_query::fw_load
uint32_t fw_load
Definition: ni_device_api.h:1214
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:18754
_ni_encoder_cfg_params::disableAv1TimingInfo
int disableAv1TimingInfo
Definition: ni_device_api.h:2526
_ni_encoder_cfg_params::crop_width
int crop_width
Definition: ni_device_api.h:2470
GOP_PRESET_IDX_IBBBP
@ GOP_PRESET_IDX_IBBBP
Definition: ni_device_api_priv.h:333
_ni_thread_arg_struct_t
Definition: ni_device_api.h:1271
NI_MIN_FRAME_SIZE
#define NI_MIN_FRAME_SIZE
Definition: ni_device_api.h:180
_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:2544
_ni_encoder_cfg_params::slice_mode
int slice_mode
Definition: ni_device_api.h:2432
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:10827
NI_ENC_PARAM_FRAME_RATE_DENOM
#define NI_ENC_PARAM_FRAME_RATE_DENOM
Definition: ni_device_api.h:2160
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:10304
NI_ENC_PARAM_AVCC_HVCC
#define NI_ENC_PARAM_AVCC_HVCC
Definition: ni_device_api.h:2252
_ni_resolution::height
int32_t height
Definition: ni_device_api_priv.h:909
_ni_encoder_cfg_params::HDR10minluma
int HDR10minluma
Definition: ni_device_api.h:2358
NI_XCODER_PRESET_NAME_SLOWER
#define NI_XCODER_PRESET_NAME_SLOWER
Definition: ni_device_api.h:3065
NI_DEC_PARAM_SURVIVE_STREAM_ERR
#define NI_DEC_PARAM_SURVIVE_STREAM_ERR
Definition: ni_device_api.h:2586
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
Definition: ni_device_api.h:1937
NI_ENC_PARAM_QCOMP
#define NI_ENC_PARAM_QCOMP
Definition: ni_device_api.h:2268
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:1803
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:18667
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:15987
NI_XCODER_PRESET_NAME_FASTER
#define NI_XCODER_PRESET_NAME_FASTER
Definition: ni_device_api.h:3061
_ni_session_context::codec_format
uint32_t codec_format
Definition: ni_device_api.h:1517
_ni_session_context::max_frame_size
int32_t max_frame_size
Definition: ni_device_api.h:1686
_ni_device_capability
device capability type
Definition: ni_device_api.h:1167
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:724
XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
Definition: ni_device_api.h:1808
NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
#define NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
Definition: ni_device_api.h:2298
ni_sprintf
int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
Definition: ni_util.c:1063
ni_posix_memalign
int ni_posix_memalign(void **memptr, size_t alignment, size_t size)
Allocate aligned memory.
Definition: ni_util.c:202
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:2571
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:1976
_ni_decoder_input_params_t::scale_wh
int scale_wh[NI_MAX_NUM_OF_DECODER_OUTPUTS][2]
Definition: ni_device_api.h:2603
_ni_encoder_cfg_params::colorPrimaries
int colorPrimaries
Definition: ni_device_api.h:2387
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:9300
NI_DEC_PARAM_FORCE_8BIT_0
#define NI_DEC_PARAM_FORCE_8BIT_0
Definition: ni_device_api.h:2541
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:3056
NI_DISABLE_USR_DATA_SEI_PASSTHRU
#define NI_DISABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:329
_ni_encoder_cfg_params::forceBframeQpfactor
float forceBframeQpfactor
Definition: ni_device_api.h:2503
NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
#define NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
Definition: ni_device_api.h:2580
_ni_load_query
Definition: ni_device_api.h:1210
XCODER_TEST_CRF_FLOAT_API
@ XCODER_TEST_CRF_FLOAT_API
Definition: ni_device_api.h:1811
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:9498
_ni_session_context::is_auto_dl
uint8_t is_auto_dl
Definition: ni_device_api.h:1501
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
Definition: ni_device_api.h:1797
NI_DEC_PARAM_REDUCE_DPB_DELAY
#define NI_DEC_PARAM_REDUCE_DPB_DELAY
Definition: ni_device_api.h:2587
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:1274
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:10413
_ni_encoder_cfg_params::crfFloat
float crfFloat
Definition: ni_device_api.h:2485
_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:2367
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:2555
_niFrameSurface1::ui16width
uint16_t ui16width
Definition: ni_device_api.h:2901
ni_strncpy
ni_retcode_t ni_strncpy(char *dest, size_t dmax, const char *src, size_t slen)
Definition: ni_util.c:518
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:11056
NI_ENC_GOP_PARAMS_G3_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G3_POC_OFFSET
Definition: ni_device_api.h:1931
_ni_resolution::bit_depth_factor
int32_t bit_depth_factor
Definition: ni_device_api_priv.h:912
NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
#define NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
Definition: ni_device_api.h:2120
NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
#define NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
Definition: ni_device_api.h:2165
_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:1279
NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
Definition: ni_device_api.h:1996
_ni_session_context::keep_alive_thread
ni_pthread_t keep_alive_thread
Definition: ni_device_api.h:1587
_ni_session_context::load_query
ni_load_query_t load_query
Definition: ni_device_api.h:1531
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:3038
NI_ENC_GOP_PARAMS_G3_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G3_PIC_TYPE
Definition: ni_device_api.h:1935
NI_ENC_PARAM_CROP_WIDTH
#define NI_ENC_PARAM_CROP_WIDTH
Definition: ni_device_api.h:2263
_ni_decoder_input_params_t::enable_out2
int enable_out2
Definition: ni_device_api.h:2593
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
Definition: ni_device_api.h:1971
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:11944
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:2324
NI_ENC_PARAM_ENABLE_AI_HVSPLUS
#define NI_ENC_PARAM_ENABLE_AI_HVSPLUS
Definition: ni_device_api.h:2258
_ni_encoder_cfg_params::HDR10dy2
int HDR10dy2
Definition: ni_device_api.h:2354
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:2161
NI_SCALER_FLAG_P2
#define NI_SCALER_FLAG_P2
Definition: ni_device_api.h:306
NI_ENC_RC_QP_DELTA_RANGE
#define NI_ENC_RC_QP_DELTA_RANGE
Definition: ni_device_api.h:2222
_ni_thread_arg_struct_t::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1275
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1953
NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
Definition: ni_device_api.h:1979
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:5013
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1944
NI_FRAME_AUX_DATA_LTR_INTERVAL
@ NI_FRAME_AUX_DATA_LTR_INTERVAL
Definition: ni_device_api.h:567
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:3325
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:1917
NI_ENC_PARAM_SAR_DENOM
#define NI_ENC_PARAM_SAR_DENOM
Definition: ni_device_api.h:2246
NI_MAX_QP_INFO
#define NI_MAX_QP_INFO
Definition: ni_device_api.h:176
_ni_encoder_cfg_params::preIntraHandling
int preIntraHandling
Definition: ni_device_api.h:2521
NI_DEC_PARAM_SAVE_PKT
#define NI_DEC_PARAM_SAVE_PKT
Definition: ni_device_api.h:2566
NI_INVALID_SVCT_DECODING_LAYER
#define NI_INVALID_SVCT_DECODING_LAYER
Definition: ni_device_api.h:331
NI_ENC_PARAM_LEVEL
#define NI_ENC_PARAM_LEVEL
Definition: ni_device_api.h:2129
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:1588
NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
Definition: ni_device_api.h:1951
_ni_xcoder_params::color_space
int color_space
Definition: ni_device_api.h:2861
netint_iocmd_issue_request
Definition: ni_p2p_ioctl.h:72
_ni_encoder_cfg_params::baseLayerOnly
int baseLayerOnly
Definition: ni_device_api.h:2522
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:279
_ni_frame::nb_aux_data
int nb_aux_data
Definition: ni_device_api.h:2775
NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
Definition: ni_device_api.h:1981
_ni_session_context::reconfig_crf
int reconfig_crf
Definition: ni_device_api.h:1716
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
Definition: ni_device_api.h:1956
_ni_encoder_cfg_params::maxFrameSize
int maxFrameSize
Definition: ni_device_api.h:2318
_ni_encoder_cfg_params::hvs_qp_scale
int hvs_qp_scale
Definition: ni_device_api.h:2450
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1968
_ni_encoder_cfg_params::cplxDecay
float cplxDecay
Definition: ni_device_api.h:2481
_ni_instance_mgr_general_status
Definition: ni_device_api_priv.h:79
atoi
#define atoi(p_str)
Definition: ni_device_api.c:7531
_ni_encoder_change_params_t::minQpI
int32_t minQpI
Definition: ni_device_api.h:1012
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:2664
_ni_decoder_input_params_t::skip_extra_headers
int skip_extra_headers
Definition: ni_device_api.h:2633
_ni_instance_mgr_detail_status
Definition: ni_device_api.h:1244
NI_PARAM_MAX_WIDTH
#define NI_PARAM_MAX_WIDTH
Definition: ni_device_api.h:138
_ni_enc_hevc_roi_custom_map
encoder HEVC ROI custom map (1 CTU = 64bits)
Definition: ni_device_api.h:862
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:2628
_ni_encoder_cfg_params::enable_hvs_qp
int enable_hvs_qp
Definition: ni_device_api.h:2449
_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:2708
NI_DEC_PARAM_SCALE_1_ROUND
#define NI_DEC_PARAM_SCALE_1_ROUND
Definition: ni_device_api.h:2563
_ni_decoder_input_params_t::pkt_pts_unchange
int pkt_pts_unchange
Definition: ni_device_api.h:2621
_ni_network_data::inset
ni_network_layer_offset_t * inset
Definition: ni_device_api.h:1383
_ni_packet::p_buffer
void * p_buffer
Definition: ni_device_api.h:3009
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:3971
NI_ENC_PARAM_VERTICAL_OFFSET
#define NI_ENC_PARAM_VERTICAL_OFFSET
Definition: ni_device_api.h:2266
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:10610
NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
#define NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
Definition: ni_device_api.h:2299
_ni_decoder_input_params_t::force_8_bit
int force_8_bit[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2596
NI_ENC_PARAM_SLICE_ARG
#define NI_ENC_PARAM_SLICE_ARG
Definition: ni_device_api.h:2169
NI_MAX_MAX_NUM_MERGE
#define NI_MAX_MAX_NUM_MERGE
Definition: ni_device_api.h:166
_ni_vui_hrd::colorSpace
int32_t colorSpace
Definition: ni_device_api.h:682
_ni_encoder_cfg_params::qcomp
float qcomp
Definition: ni_device_api.h:2475
_ni_session_context::low_delay_sync_flag
int low_delay_sync_flag
Definition: ni_device_api.h:1695
NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
#define NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
Max number of lines supported for qpoffset level.
Definition: ni_device_api.h:493
_ni_encoder_cfg_params::avcc_hvcc
int avcc_hvcc
Definition: ni_device_api.h:2516
_ni_decoder_input_params_t::custom_sei_passthru
int custom_sei_passthru
Definition: ni_device_api.h:2613
_ni_xcoder_params::ddr_priority_mode
ni_ddr_priority_mode_t ddr_priority_mode
Definition: ni_device_api.h:2890
_ni_encoder_cfg_params::colorTrc
int colorTrc
Definition: ni_device_api.h:2388
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:3899
_ni_ppu_config::ppu_h
uint16_t ppu_h[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:1432
_ni_session_context::active_video_height
uint32_t active_video_height
Definition: ni_device_api.h:1582
NI_ENC_PARAM_INTRA_PERIOD
#define NI_ENC_PARAM_INTRA_PERIOD
Definition: ni_device_api.h:2157
ni_pthread_mutex_destroy
int ni_pthread_mutex_destroy(ni_pthread_mutex_t *mutex)
destory a mutex
Definition: ni_util.c:4668
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:8649
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:13253
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:19071
NI_FRAME_AUX_DATA_LONG_TERM_REF
@ NI_FRAME_AUX_DATA_LONG_TERM_REF
Definition: ni_device_api.h:562
NI_ENC_PARAM_VBV_BUFFER_SIZE
#define NI_ENC_PARAM_VBV_BUFFER_SIZE
Definition: ni_device_api.h:2200
NI_MAX_SEI_DATA
#define NI_MAX_SEI_DATA
Definition: ni_device_api.h:440
_ni_session_context::pkt_delay_cnt
uint32_t pkt_delay_cnt
Definition: ni_device_api.h:1733
_ni_encoder_cfg_params::av1_error_resilient_mode
int av1_error_resilient_mode
Definition: ni_device_api.h:2463
_ni_encoder_cfg_params::tune_bframe_visual
int tune_bframe_visual
Definition: ni_device_api.h:2504
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:13559
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:13134
_ni_encoder_cfg_params::conf_win_left
int conf_win_left
Definition: ni_device_api.h:2374
NI_MAX_FRAME_SIZE
#define NI_MAX_FRAME_SIZE
Definition: ni_device_api.h:181
_ni_encoder_cfg_params::pass1_qp
int pass1_qp
Definition: ni_device_api.h:2484
_ni_encoder_cfg_params::conf_win_right
int conf_win_right
Definition: ni_device_api.h:2375
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:872
_ni_session_context::blk_dev_name
char blk_dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_device_api.h:1690
_ni_decoder_input_params_t::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:2611
NI_POOL_TYPE_NONE
@ NI_POOL_TYPE_NONE
Definition: ni_device_api.h:505
NI_ENC_PARAM_RC_INIT_DELAY
#define NI_ENC_PARAM_RC_INIT_DELAY
Definition: ni_device_api.h:2178
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1578
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:701
_ni_session_context::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:1626
NI_ENC_PARAM_HVS_QP_SCALE
#define NI_ENC_PARAM_HVS_QP_SCALE
Definition: ni_device_api.h:2147
NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2583
_niFrameSurface1::device_handle
int32_t device_handle
Definition: ni_device_api.h:2904
_ni_encoder_cfg_params::crfMax
int crfMax
Definition: ni_device_api.h:2474
_niFrameSurface1::bit_depth
int8_t bit_depth
Definition: ni_device_api.h:2905
NI_ENC_PARAM_DECODING_REFRESH_TYPE
#define NI_ENC_PARAM_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:2162
NI_ENC_GOP_PARAMS_G1_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G1_PIC_TYPE
Definition: ni_device_api.h:1905
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:1831
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:2478
_ni_network_layer_info::out_param
ni_network_layer_params_t * out_param
Definition: ni_device_api.h:1369
XCODER_TEST_INVALID_REF_FRAME_API
@ XCODER_TEST_INVALID_REF_FRAME_API
Definition: ni_device_api.h:1806
_ni_encoder_cfg_params::enableipRatio
int enableipRatio
Definition: ni_device_api.h:2496
_ni_enc_quad_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:897
_ni_decoder_input_params_t::scale_resolution_ceil
int scale_resolution_ceil[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2626
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:1175
NI_ENC_PARAM_LOW_DELAY
#define NI_ENC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2134
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
Definition: ni_device_api.h:1997
NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
#define NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
Definition: ni_device_api.h:2289
_ni_session_context::meta_size
uint32_t meta_size
Params used in VFR mode Done///.
Definition: ni_device_api.h:1669
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:8840
_ni_encoder_cfg_params::vbv_min_rate
int vbv_min_rate
Definition: ni_device_api.h:2500
NI_ENC_PARAM_PPS_INIT_QP
#define NI_ENC_PARAM_PPS_INIT_QP
Definition: ni_device_api.h:2276
_ni_encoder_cfg_params::HDR10MaxLight
int HDR10MaxLight
Definition: ni_device_api.h:2345
_ni_xcoder_params::cacheRoi
int cacheRoi
Definition: ni_device_api.h:2848
_ni_session_context::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1513
_ni_encoder_cfg_params::still_image_detect_level
int still_image_detect_level
Definition: ni_device_api.h:2509
_ni_encoder_change_params_t::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:1013
_ni_encoder_cfg_params::crop_height
int crop_height
Definition: ni_device_api.h:2471
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1983
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1507
_ni_encoder_cfg_params::aspectRatioHeight
int aspectRatioHeight
Definition: ni_device_api.h:2316
NI_MIN_HEIGHT
#define NI_MIN_HEIGHT
Definition: ni_device_api.h:129
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:2124
_ni_encoder_cfg_params::HDR10dx1
int HDR10dx1
Definition: ni_device_api.h:2351
ni_strcat
ni_retcode_t ni_strcat(char *dest, size_t dmax, const char *src)
Definition: ni_util.c:689
NI_ENC_PARAM_PSNR_INTERVAL
#define NI_ENC_PARAM_PSNR_INTERVAL
Definition: ni_device_api.h:2291
XCODER_TEST_RECONF_BR
@ XCODER_TEST_RECONF_BR
Definition: ni_device_api.h:1782
_ni_aux_data::type
ni_aux_data_type_t type
Definition: ni_device_api.h:634
NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
Definition: ni_device_api.h:1949
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:18233
NI_ENC_PARAM_ROI_ENABLE
#define NI_ENC_PARAM_ROI_ENABLE
Definition: ni_device_api.h:2152
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:2148
NI_MIN_BITRATE
#define NI_MIN_BITRATE
Definition: ni_device_api.h:117
_niFrameSurface1::dma_buf_fd
int32_t dma_buf_fd
Definition: ni_device_api.h:2909
_ni_encoder_cfg_params::planar
int planar
Definition: ni_device_api.h:2317
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
Definition: ni_device_api.h:1954
_ni_buf_t::buf
void * buf
Definition: ni_device_api.h:1288
_ni_session_context::reconfigCount
int reconfigCount
Definition: ni_device_api.h:1729
NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
Definition: ni_device_api.h:1921
_ni_packet::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:3010
_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:693
NI_ENC_PARAM_VBV_MINRATE
#define NI_ENC_PARAM_VBV_MINRATE
Definition: ni_device_api.h:2284
_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:689
_ni_session_context::hdr_buf_size
uint8_t hdr_buf_size
Definition: ni_device_api.h:1543
_ni_instance_mgr_detail_status_v1
Definition: ni_device_api.h:1266
_ni_xcoder_params::enable_vfr
int enable_vfr
Definition: ni_device_api.h:2881
_ni_frame::inconsecutive_transfer
uint8_t inconsecutive_transfer
Definition: ni_device_api.h:2805
_ni_session_context::last_framerate
ni_framerate_t last_framerate
Definition: ni_device_api.h:1706
NI_ENC_PARAM_FRAME_RATE
#define NI_ENC_PARAM_FRAME_RATE
Definition: ni_device_api.h:2159
_ni_session_context::ltr_frame_ref_invalid
int32_t ltr_frame_ref_invalid
Definition: ni_device_api.h:1634
NI_SCALER_FLAG_PC
#define NI_SCALER_FLAG_PC
Definition: ni_device_api.h:304
_ni_encoder_cfg_params::rdoLevel
int rdoLevel
Definition: ni_device_api.h:2343
_ni_encoder_cfg_params::long_term_ref_enable
int long_term_ref_enable
Definition: ni_device_api.h:2334
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:2506
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:813
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:1726
_ni_encoder_cfg_params::ltrNextInterval
int ltrNextInterval
Definition: ni_device_api.h:2363
_ni_decoder_input_params_t::survive_stream_err
int survive_stream_err
Definition: ni_device_api.h:2631
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
Definition: ni_device_api.h:1911
NI_ENC_PARAM_LOG_LEVEL
#define NI_ENC_PARAM_LOG_LEVEL
Definition: ni_device_api.h:2131
COMPARE
#define COMPARE(STR1, STR2, STR3)
NI_ENC_PARAM_GOP_SIZE
#define NI_ENC_PARAM_GOP_SIZE
Definition: ni_device_api.h:2195
_ni_encoder_cfg_params::videoFullRange
int videoFullRange
Definition: ni_device_api.h:2365
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:8563
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:8396
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:16513
_ni_encoder_cfg_params::intra_reset_refresh
int intra_reset_refresh
Definition: ni_device_api.h:2464
NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
#define NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
Definition: ni_device_api.h:2287
_ni_scaler_input_params_t::in_rec_height
int32_t in_rec_height
Definition: ni_device_api.h:2642
NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2285
_ni_encoder_cfg_params::slice_arg
int slice_arg
Definition: ni_device_api.h:2433
NI_ENC_PARAM_ENABLE_TIMECODE
#define NI_ENC_PARAM_ENABLE_TIMECODE
Definition: ni_device_api.h:2297
_ni_frame::p_metadata_buffer
uint8_t * p_metadata_buffer
Definition: ni_device_api.h:2792
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:2259
_ni_rc_min_max_qp::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:721
lower_pixel_rate
int lower_pixel_rate(const ni_load_query_t *pQuery, uint32_t ui32CurrentLowest)
Definition: ni_device_api_priv.c:19213
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
Definition: ni_device_api.h:1999
NI_ENC_CTB_ROW_QP_STEP
#define NI_ENC_CTB_ROW_QP_STEP
Definition: ni_device_api.h:2223
_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:2556
_ni_encoder_cfg_params::lookAheadDepth
int lookAheadDepth
Definition: ni_device_api.h:2342
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:3072
NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
#define NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
Definition: ni_device_api.h:2174
NI_FRAME_AUX_DATA_CRF_FLOAT
@ NI_FRAME_AUX_DATA_CRF_FLOAT
Definition: ni_device_api.h:592
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:1620
_ni_custom_gop_params::pic_param
ni_gop_params_t pic_param[NI_MAX_GOP_NUM]
Definition: ni_device_api.h:2106
NI_ENC_PARAM_ENABLE_PIC_SKIP
#define NI_ENC_PARAM_ENABLE_PIC_SKIP
Definition: ni_device_api.h:2203
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:4733
ni_aligned_free
#define ni_aligned_free(p_memptr)
Definition: ni_util.h:400
_ni_session_context::dev
unsigned short dev
Definition: ni_device_api.h:1652
_ni_decoder_input_params_t::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:2609
_ni_xcoder_params::low_delay_mode
int low_delay_mode
Definition: ni_device_api.h:2834
_ni_decoder_input_params_t::nb_save_pkt
int nb_save_pkt
Definition: ni_device_api.h:2595
_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:155
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:11286
NI_ENC_PARAM_ENABLE_COMPENSATE_QP
#define NI_ENC_PARAM_ENABLE_COMPENSATE_QP
Definition: ni_device_api.h:2236
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:1675
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:1563
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1925
NI_ENC_ENABLE_SSIM
#define NI_ENC_ENABLE_SSIM
Definition: ni_device_api.h:2251
_ni_encoder_cfg_params::enable_cu_level_rate_control
int enable_cu_level_rate_control
Definition: ni_device_api.h:2448
_ni_decoder_input_params_t::disable_adaptive_buffers
int disable_adaptive_buffers
Definition: ni_device_api.h:2629
NI_CODEC_FORMAT_H264
@ NI_CODEC_FORMAT_H264
Definition: ni_device_api.h:925
_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:18427
NI_ENC_GOP_PARAMS_G6_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G6_QP_OFFSET
Definition: ni_device_api.h:1977
NI_FRAME_AUX_DATA_INVALID_REF_FRAME
@ NI_FRAME_AUX_DATA_INVALID_REF_FRAME
Definition: ni_device_api.h:572
_ni_thread_arg_struct_t::plast_access_time
volatile uint64_t * plast_access_time
Definition: ni_device_api.h:1283
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:2800
NI_MAX_BIN
#define NI_MAX_BIN
Definition: ni_device_api.h:177
NI_ENC_GOP_PARAMS_G0_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PICS
Definition: ni_device_api.h:1891
NI_MAX_BITRATE
#define NI_MAX_BITRATE
Definition: ni_device_api.h:116
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:1901
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2707
_ni_session_context::initial_frame_delay
int initial_frame_delay
Definition: ni_device_api.h:1723
_ni_input_frame
Definition: ni_device_api.h:1410
NI_FRAME_LITTLE_ENDIAN
#define NI_FRAME_LITTLE_ENDIAN
Definition: ni_device_api.h:111
_ni_xcoder_params::bitrate
int bitrate
Definition: ni_device_api.h:2830
_ni_encoder_cfg_params::HDR10wy
int HDR10wy
Definition: ni_device_api.h:2356
netint_iocmd_signal_rfence
Definition: ni_p2p_ioctl.h:87
NI_MIN_WIDTH
#define NI_MIN_WIDTH
Definition: ni_device_api.h:127
NI_DEC_PARAM_FORCE_LOW_DELAY
#define NI_DEC_PARAM_FORCE_LOW_DELAY
Definition: ni_device_api.h:2568
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:162
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:3192
_ni_encoder_cfg_params::preferred_transfer_characteristics
int preferred_transfer_characteristics
Definition: ni_device_api.h:2340
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:8917
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1647
_ni_xcoder_params::use_low_delay_poc_type
int use_low_delay_poc_type
Definition: ni_device_api.h:2837
_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:2372
NI_ENC_PARAM_TOTAL_CUTREE_DEPTH
#define NI_ENC_PARAM_TOTAL_CUTREE_DEPTH
Definition: ni_device_api.h:2301
QUADRA
#define QUADRA
Definition: ni_defs.h:123
NI_ENC_PARAM_PASS1_QP
#define NI_ENC_PARAM_PASS1_QP
Definition: ni_device_api.h:2279
_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:1889
ni_ai_network_layer_size
uint32_t ni_ai_network_layer_size(ni_network_layer_params_t *p_param)
Definition: ni_util.c:3989
NI_DEC_PARAM_DDR_PRIORITY_MODE
#define NI_DEC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2574
MAX_CHAR_IN_DEVICE_NAME
#define MAX_CHAR_IN_DEVICE_NAME
Definition: ni_device_api.h:188
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:2293
_ni_encoder_cfg_params::bitrateMode
int bitrateMode
Definition: ni_device_api.h:2483
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:13209
NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
#define NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
Definition: ni_device_api.h:2570
_ni_aux_data
Definition: ni_device_api.h:632
_ni_scaler_input_params_t::in_rec_width
int32_t in_rec_width
Definition: ni_device_api.h:2641
NI_PIXEL_PLANAR_FORMAT_TILED4X4
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
Definition: ni_device_api.h:936
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:64
_ni_framerate
Definition: ni_device_api.h:709
_ni_vui_hrd::aspectRatioWidth
int32_t aspectRatioWidth
Definition: ni_device_api.h:686
NI_ENC_PARAM_SLICE_MODE
#define NI_ENC_PARAM_SLICE_MODE
Definition: ni_device_api.h:2168
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:11231
NI_MAX_RESOLUTION_LINESIZE
#define NI_MAX_RESOLUTION_LINESIZE
Definition: ni_device_api.h:109
NI_FRAME_AUX_DATA_INTRAPRD
@ NI_FRAME_AUX_DATA_INTRAPRD
Definition: ni_device_api.h:553
NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
#define NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
Definition: ni_device_api.h:2110
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:3858
_ni_xcoder_params::dec_input_params
ni_decoder_input_params_t dec_input_params
Definition: ni_device_api.h:2869
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:242
_ni_xcoder_params::color_transfer_characteristic
int color_transfer_characteristic
Definition: ni_device_api.h:2860
_ni_custom_gop_params
Definition: ni_device_api.h:2103
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:1542
NI_DEC_PARAM_ENABLE_PPU_SCALE_ADAPT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_ADAPT
Definition: ni_device_api.h:2578
NI_PARAM_MIN_HEIGHT
#define NI_PARAM_MIN_HEIGHT
Definition: ni_device_api.h:141
_ni_enc_quad_roi_custom_map::qp_info
uint8_t qp_info
Definition: ni_device_api.h:903
_ni_gop_params::temporal_id
int temporal_id
Definition: ni_device_api.h:2017
NI_PIXEL_PLANAR_FORMAT_PLANAR
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
Definition: ni_device_api.h:935
_ni_rc_min_max_qp::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:722
NI_DEFAULT_CU_SIZE_MODE
#define NI_DEFAULT_CU_SIZE_MODE
Definition: ni_device_api.h:161
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:5199
ni_fopen
ni_retcode_t ni_fopen(FILE **fp, const char *filename, const char *mode)
Definition: ni_util.c:983
NI_MIN_GOP_PRESET_IDX
#define NI_MIN_GOP_PRESET_IDX
Definition: ni_device_api.h:156
NI_XCODER_FLUSH_STATE
@ NI_XCODER_FLUSH_STATE
Definition: ni_device_api.h:254
NI_ENC_PARAM_PRESET
#define NI_ENC_PARAM_PRESET
Definition: ni_device_api.h:2311
NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
Definition: ni_device_api.h:2144
NI_DEC_PARAM_SEMI_PLANAR_2
#define NI_DEC_PARAM_SEMI_PLANAR_2
Definition: ni_device_api.h:2546
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:10385
NI_MAX_INTRA_QP_DELTA
#define NI_MAX_INTRA_QP_DELTA
Definition: ni_device_api.h:170
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:3808
_ni_session_context::roi_avg_qp
uint32_t roi_avg_qp
Definition: ni_device_api.h:1528
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:1705
NI_MAX_ASPECTRATIO
#define NI_MAX_ASPECTRATIO
Definition: ni_device_api.h:120
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:10900
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:487
_ni_session_context::force_low_delay_cnt
uint32_t force_low_delay_cnt
Definition: ni_device_api.h:1731
NI_MAX_RESOLUTION_AREA
#define NI_MAX_RESOLUTION_AREA
Definition: ni_device_api.h:105
_ni_xcoder_params::p_first_frame
ni_frame_t * p_first_frame
Definition: ni_device_api.h:2879
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:2262
NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
Definition: ni_device_api.h:1906
_ni_session_context::p_master_display_meta_data
void * p_master_display_meta_data
Definition: ni_device_api.h:1461
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:1828
NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2585
_ni_encoder_cfg_params::forced_header_enable
int forced_header_enable
Definition: ni_device_api.h:2333
NI_DEC_PARAM_MIN_PACKETS_DELAY
#define NI_DEC_PARAM_MIN_PACKETS_DELAY
Definition: ni_device_api.h:2569
_ni_encoder_cfg_params::spatial_layers_ref_base_layer
int spatial_layers_ref_base_layer
Definition: ni_device_api.h:2517
_ni_session_context::async_mode
int async_mode
Definition: ni_device_api.h:1694
NI_FRAME_AUX_DATA_BITRATE
@ NI_FRAME_AUX_DATA_BITRATE
Definition: ni_device_api.h:549
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:2302
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:2557
_ni_scaler_input_params_t::output_format
int output_format
Definition: ni_device_api.h:2646
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:926
_ni_scaler_input_params_t::output_width
int32_t output_width
Definition: ni_device_api.h:2647
NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
#define NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
Definition: ni_device_api.h:2230
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:4279
_ni_session_context::last_access_time
volatile uint64_t last_access_time
Definition: ni_device_api.h:1714
_ni_packet::data_len
uint32_t data_len
Definition: ni_device_api.h:3006
NI_MIN_INTRA_QP
#define NI_MIN_INTRA_QP
Definition: ni_device_api.h:169
NI_DEC_PARAM_CROP_MODE_1
#define NI_DEC_PARAM_CROP_MODE_1
Definition: ni_device_api.h:2548