libxcoder  5.2.0
ni_device_api.c
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (C) 2022 NETINT Technologies
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18  * SOFTWARE.
19  *
20  ******************************************************************************/
21 
22 /*!*****************************************************************************
23  * \file ni_device_api.c
24  *
25  * \brief Public definitions for operating NETINT video processing devices for
26  * video processing
27  ******************************************************************************/
28 
29 #if __linux__ || __APPLE__
30 #define _GNU_SOURCE //O_DIRECT is Linux-specific. One must define _GNU_SOURCE to obtain its definitions
31 #if __linux__
32 #include <linux/types.h>
33 #endif
34 #include <unistd.h>
35 #include <sys/ioctl.h>
36 #include <sys/mman.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <sys/time.h>
40 #include <fcntl.h>
41 #include <errno.h>
42 #include <semaphore.h>
43 #include <limits.h>
44 #include <unistd.h>
45 #include <signal.h>
46 #include <poll.h>
47 #endif
48 
49 #include <stdint.h>
50 #include <string.h>
51 #include <stdio.h>
52 #include <stdlib.h>
53 #include <stdint.h>
54 #include <sys/stat.h>
55 #include "inttypes.h"
56 #include "ni_device_api.h"
57 #include "ni_device_api_priv.h"
58 #include "ni_nvme.h"
59 #include "ni_util.h"
60 #include "ni_rsrc_api.h"
61 #include "ni_rsrc_priv.h"
62 #include "ni_lat_meas.h"
63 #ifdef _WIN32
64 #include <shlobj.h>
65 #else
66 #include "ni_p2p_ioctl.h"
67 #endif
68 
78  0};
79 #if __linux__ || __APPLE__
80 static struct stat g_nvme_stat = { 0 };
81 
82 static int close_fd_zero_atexit = 0;
83 
84 static void close_fd_zero(void)
85 {
86  close(0);
87 }
88 
89 #endif
90 
91 /*!*****************************************************************************
92  * \brief Allocate and initialize a new ni_session_context_t struct
93  *
94  *
95  * \return On success returns a valid pointer to newly allocated context
96  * On failure returns NULL
97  ******************************************************************************/
99 {
100  ni_session_context_t *p_ctx = NULL;
101 
102  p_ctx = malloc(sizeof(ni_session_context_t));
103  if (!p_ctx)
104  {
106  "ERROR: %s() Failed to allocate memory for session context\n",
107  __func__);
108  } else
109  {
110  memset(p_ctx, 0, sizeof(ni_session_context_t));
111 
113  {
114  ni_log(NI_LOG_ERROR, "ERROR: %s() Failed to init session context\n",
115  __func__);
117  return NULL;
118  }
119  }
120  return p_ctx;
121 }
122 
123 /*!*****************************************************************************
124  * \brief Free previously allocated session context
125  *
126  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
127  * struct
128  *
129  ******************************************************************************/
131 {
132  if (p_ctx)
133  {
135 #ifdef MEASURE_LATENCY
136  if (p_ctx->frame_time_q)
137  {
139  }
140 #endif
141  free(p_ctx);
142  }
143 }
144 
145 /*!*****************************************************************************
146  * \brief Initialize already allocated session context to a known state
147  *
148  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
149  * struct
150  * \return On success
151  * NI_RETCODE_SUCCESS
152  * On failure
153  * NI_RETCODE_INVALID_PARAM
154  * NI_RETCODE_FAILURE
155  ******************************************************************************/
157 {
158  int bitrate = 0;
159  int framerate_num = 0;
160  int framerate_denom = 0;
161 
162  if (!p_ctx)
163  {
165  }
166 
168  {
169  // session context will reset so save the last values for sequence change
170  bitrate = p_ctx->last_bitrate;
171  framerate_num = p_ctx->last_framerate.framerate_num;
172  framerate_denom = p_ctx->last_framerate.framerate_denom;
173  }
174 
175  memset(p_ctx, 0, sizeof(ni_session_context_t));
176 
177  p_ctx->last_bitrate = bitrate;
178  p_ctx->last_framerate.framerate_num = framerate_num;
179  p_ctx->last_framerate.framerate_denom = framerate_denom;
180 
181  // Xcoder thread mutex init
182  if (ni_pthread_mutex_init(&p_ctx->mutex))
183  {
184  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): init xcoder_mutex fail, return\n",
185  __func__);
186  return NI_RETCODE_FAILURE;
187  }
188  p_ctx->pext_mutex = &p_ctx->mutex; //used exclusively for hwdl
189 
190  // low delay send/recv sync init
192  {
193  ni_log2(p_ctx, NI_LOG_ERROR,
194  "ERROR %s(): init xcoder_low_delay_sync_mutex fail return\n",
195  __func__);
196  return NI_RETCODE_FAILURE;
197  }
198  if (ni_pthread_cond_init(&p_ctx->low_delay_sync_cond, NULL))
199  {
200  ni_log2(p_ctx, NI_LOG_ERROR,
201  "ERROR %s(): init xcoder_low_delay_sync_cond fail return\n",
202  __func__);
203  return NI_RETCODE_FAILURE;
204  }
205 
206  p_ctx->mutex_initialized = true;
207 
208  // Init the max IO size to be invalid
212  p_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
213  p_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
214  p_ctx->hw_id = NI_INVALID_HWID;
215  p_ctx->event_handle = NI_INVALID_EVENT_HANDLE;
216  p_ctx->thread_event_handle = NI_INVALID_EVENT_HANDLE;
218  p_ctx->keep_alive_thread = (ni_pthread_t){0};
220  p_ctx->decoder_low_delay = 0;
221  p_ctx->enable_low_delay_check = 0;
222  p_ctx->low_delay_sync_flag = 0;
223  p_ctx->async_mode = 0;
225  p_ctx->buffered_frame_index = 0;
226  // by default, select the least model load card
227  strncpy(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR,
229 #ifdef MY_SAVE
230  p_ctx->debug_write_ptr = NULL;
231  p_ctx->debug_write_index_ptr = NULL;
232  p_ctx->debug_write_sent_size = 0;
233 #endif
234 
235 #ifdef MEASURE_LATENCY
236  p_ctx->frame_time_q = (void *)ni_lat_meas_q_create(2000);
237 #endif
238 
239  return NI_RETCODE_SUCCESS;
240 }
241 
242 /*!*****************************************************************************
243  * \brief Clear already allocated session context
244  *
245  * \param[in] p_ctx Pointer to an already allocated ni_session_context_t
246  *
247  *
248  ******************************************************************************/
250 {
251  if(p_ctx->mutex_initialized)
252  {
253  p_ctx->mutex_initialized = false;
257  }
258 }
259 
260 /*!*****************************************************************************
261  * \brief Create event and return event handle if successful (Windows only)
262  *
263  * \return On success returns a event handle
264  * On failure returns NI_INVALID_EVENT_HANDLE
265  ******************************************************************************/
266 ni_event_handle_t ni_create_event(void)
267 {
268 #ifdef _WIN32
269  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
270 
271  // Input-0 determines whether the returned handle can be inherited by the child process.If lpEventAttributes is NULL, this handle cannot be inherited.
272  // 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.
273  // Input-2 specifies the initial state of the event object.If TRUE, the initial state is signaled;Otherwise, no signal state.
274  // Input-3 If the lpName is NULL, a nameless event object is created.。
275  event_handle = CreateEvent(NULL, FALSE, FALSE, NULL);
276  if (event_handle == NULL)
277  {
278  ni_log(NI_LOG_ERROR, "ERROR %d: %s() create event failed\n",
279  NI_ERRNO, __func__);
280  return NI_INVALID_EVENT_HANDLE;
281  }
282  return event_handle;
283 #else
284  return NI_INVALID_EVENT_HANDLE;
285 #endif
286 }
287 
288 /*!*****************************************************************************
289  * \brief Close event and release resources (Windows only)
290  *
291  * \return NONE
292  *
293  ******************************************************************************/
294 void ni_close_event(ni_event_handle_t event_handle)
295 {
296  if ( NI_INVALID_DEVICE_HANDLE == event_handle )
297  {
298  ni_log(NI_LOG_DEBUG, "Warning %s: null parameter passed %x\n", __func__,
299  event_handle);
300  return;
301  }
302 
303  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
304 
305 #ifdef _WIN32
306  BOOL retval;
307  ni_log(NI_LOG_DEBUG, "%s(): closing %p\n", __func__, event_handle);
308 
309  retval = CloseHandle(event_handle);
310  if (FALSE == retval)
311  {
312  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): closing event_handle %p failed\n",
313  NI_ERRNO, __func__, event_handle);
314  }
315  else
316  {
317  ni_log(NI_LOG_DEBUG, "%s(): device %p closed successfuly\n", __func__,
318  event_handle);
319  }
320 #else
321  int err = 0;
322  ni_log(NI_LOG_DEBUG, "%s(): closing %d\n", __func__, event_handle);
323  err = close(event_handle);
324  if (err)
325  {
326  char error_message[100] = {'\0'};
327  char unknown_error_message[20] = {'\0'};
328  sprintf(error_message, "ERROR: %s(): ", __func__);
329  switch (err)
330  {
331  case EBADF:
332  strcat(error_message, "EBADF\n");
333  break;
334  case EINTR:
335  strcat(error_message, "EINTR\n");
336  break;
337  case EIO:
338  strcat(error_message, "EIO\n");
339  break;
340  default:
341  sprintf(unknown_error_message, "Unknown error %d\n", err);
342  strcat(error_message, unknown_error_message);
343  }
344  ni_log(NI_LOG_ERROR, "%s\n", error_message);
345  }
346 #endif
347  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
348 }
349 
350 /*!*****************************************************************************
351  * \brief Open device and return device device_handle if successful
352  *
353  * \param[in] p_dev Device name represented as c string. ex: "/dev/nvme0"
354  * \param[out] p_max_io_size_out Maximum IO Transfer size supported, could be
355  * NULL
356  *
357  * \return On success returns a device device_handle
358  * On failure returns NI_INVALID_DEVICE_HANDLE
359  ******************************************************************************/
360 ni_device_handle_t ni_device_open(const char * p_dev, uint32_t * p_max_io_size_out)
361 {
362 #ifdef _WIN32
363  DWORD retval;
364  HANDLE device_handle;
365 
366  if (!p_dev)
367  {
368  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
369  return NI_INVALID_DEVICE_HANDLE;
370  }
371 
372  if (p_max_io_size_out != NULL && *p_max_io_size_out == NI_INVALID_IO_SIZE)
373  {
374  // For now, we just use it to allocate p_leftover buffer
375  // NI_MAX_PACKET_SZ is big enough
376  *p_max_io_size_out = NI_MAX_PACKET_SZ;
377  }
378 
379  device_handle = CreateFile(p_dev, GENERIC_READ | GENERIC_WRITE,
380  FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
381  OPEN_EXISTING, FILE_FLAG_NO_BUFFERING, NULL);
382 
383  ni_log(NI_LOG_DEBUG, "%s() device_name: %s", __func__, p_dev);
384  if (INVALID_HANDLE_VALUE == device_handle)
385  {
386  retval = GetLastError();
387  ni_log(NI_LOG_ERROR, "Failed to open %s, retval %d \n", p_dev, retval);
388  } else
389  {
390  ni_log(NI_LOG_DEBUG, "Found NVME Controller at %s \n", p_dev);
391  }
392 
393  return device_handle;
394 #else
395  int retval = -1;
396  ni_device_handle_t fd = NI_INVALID_DEVICE_HANDLE;
397 
398  if (!p_dev)
399  {
400  ni_log(NI_LOG_ERROR, "ERROR: passed parameters are null!, return\n");
402  }
403 
404  if (p_max_io_size_out != NULL && *p_max_io_size_out == NI_INVALID_IO_SIZE)
405  {
406  #if __linux__
407  *p_max_io_size_out = ni_get_kernel_max_io_size(p_dev);
408  #elif __APPLE__
409  *p_max_io_size_out = MAX_IO_TRANSFER_SIZE;
410  #endif
411  }
412 
413  ni_log(NI_LOG_DEBUG, "%s: opening regular-io enabled %s\n", __func__,
414  p_dev);
415  //O_SYNC is added to ensure that data is written to the card when the pread/pwrite function returns
416  #if __linux__
417  //O_DIRECT is added to ensure that data can be sent directly to the card instead of to cache memory
418  fd = open(p_dev, O_RDWR | O_SYNC | O_DIRECT);
419  #elif __APPLE__
420  //O_DIRECT isn't available, so instead we use F_NOCACHE below
421  fd = open(p_dev, O_RDWR | O_SYNC);
422  #endif
423 
424  if (fd < 0)
425  {
426  ni_log(NI_LOG_ERROR, "ERROR: %d %s open() failed on %s\n", NI_ERRNO,
427  strerror(NI_ERRNO), p_dev);
428  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
429  fd = NI_INVALID_DEVICE_HANDLE;
430  LRETURN;
431  }
432  else if(fd == 0)
433  {
434  //this code is just for the case that we do not initialize all fds to NI_INVALID_DEVICE_HANDLE
435 
436  //if we make sure that all the fds in libxcoder is initialized to NI_INVALID_DEVICE_HANDLE
437  //we should remove this check
438 
439  //we hold the fd = 0, so other threads could not visit these code
440  //thread safe unless other thread close fd=0 accidently
441  ni_log(NI_LOG_ERROR, "open fd = 0 is not as expeceted\n");
442  if(close_fd_zero_atexit == 0)
443  {
444  close_fd_zero_atexit = 1;
445  atexit(close_fd_zero);
446  }
447  else
448  {
449  ni_log(NI_LOG_ERROR, "libxcoder has held the fd=0, but open fd=0 again, maybe fd=0 was closed accidently.");
450  }
451  fd = NI_INVALID_DEVICE_HANDLE;
452  }
453 
454  #if __APPLE__
455  //F_NOCACHE is set to ensure that data can be sent directly to the card instead of to cache memory
456  retval = fcntl(fd, F_NOCACHE, 1);
457  if (retval < 0)
458  {
459  ni_log(NI_LOG_ERROR, "ERROR: fnctl() failed on %s\n", p_dev);
460  ni_log(NI_LOG_ERROR, "ERROR: ni_device_open() failed!\n");
461  close(fd);
462  fd = NI_INVALID_DEVICE_HANDLE;
463  LRETURN;
464  }
465  #endif
466 
467  retval = fstat(fd, &g_nvme_stat);
468  if (retval < 0)
469  {
470  ni_log(NI_LOG_ERROR, "ERROR: fstat() failed on %s\n", p_dev);
471  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
472  close(fd);
473  fd = NI_INVALID_DEVICE_HANDLE;
474  LRETURN;
475  }
476 
477  if (!S_ISCHR(g_nvme_stat.st_mode) && !S_ISBLK(g_nvme_stat.st_mode))
478  {
479  ni_log(NI_LOG_ERROR, "ERROR: %s is not a block or character device\n",
480  p_dev);
481  ni_log(NI_LOG_ERROR, "ERROR: %s() failed!\n", __func__);
482  close(fd);
483  fd = NI_INVALID_DEVICE_HANDLE;
484  LRETURN;
485  }
486 
487  ni_log(NI_LOG_DEBUG, "%s: success, fd=%d\n", __func__, fd);
488 
489 END:
490 
491  return fd;
492 #endif
493 }
494 
495 /*!*****************************************************************************
496  * \brief Close device and release resources
497  *
498  * \param[in] device_handle Device handle obtained by calling ni_device_open()
499  *
500  * \return NONE
501  *
502  ******************************************************************************/
503 void ni_device_close(ni_device_handle_t device_handle)
504 {
505  if ( NI_INVALID_DEVICE_HANDLE == device_handle )
506  {
507  ni_log(NI_LOG_ERROR, "ERROR %s: null parameter passed %x\n", __func__,
508  device_handle);
509  return;
510  }
511 
512  if(device_handle == 0)
513  {
514  //this code is just for the case that we do not initialize all fds to NI_INVALID_DEVICE_HANDLE
515 
516  //if we make sure that all the fds in libxcoder is initialized to NI_INVALID_DEVICE_HANDLE
517  //we should remove this check
518  ni_log(NI_LOG_ERROR, "%s close fd=0 is not as expected", __func__);
519  return;
520  }
521 
522  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
523 
524 #ifdef _WIN32
525  BOOL retval;
526 
527  ni_log(NI_LOG_DEBUG, "%s(): closing %p\n", __func__, device_handle);
528 
529  retval = CloseHandle(device_handle);
530  if (FALSE == retval)
531  {
533  "ERROR: %s(): closing device device_handle %p failed, error: %d\n",
534  __func__, device_handle, NI_ERRNO);
535  }
536  else
537  {
538  ni_log(NI_LOG_DEBUG, "%s(): device %p closed successfuly\n", __func__,
539  device_handle);
540  }
541 #else
542  int err = 0;
543  ni_log(NI_LOG_DEBUG, "%s(): closing fd %d\n", __func__, device_handle);
544  err = close(device_handle);
545  if (err == -1)
546  {
547  char error_message[100] = {'\0'};
548  char unknown_error_message[20] = {'\0'};
549  sprintf(error_message, "ERROR: %s(): ", __func__);
550  switch (errno)
551  {
552  case EBADF:
553  strcat(error_message, "EBADF\n");
554  break;
555  case EINTR:
556  strcat(error_message, "EINTR\n");
557  break;
558  case EIO:
559  strcat(error_message, "EIO\n");
560  break;
561  default:
562  sprintf(unknown_error_message, "Unknown error %d\n", err);
563  strcat(error_message, unknown_error_message);
564  }
565  ni_log(NI_LOG_ERROR, "%s\n", strerror(errno));
566  ni_log(NI_LOG_ERROR, "%s\n", error_message);
567  }
568 #endif
569  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
570 }
571 
572 /*!*****************************************************************************
573  * \brief Query device and return device capability structure
574  * This function had been replaced by ni_device_capability_query2
575  * This function can't be callback in multi thread
576  *
577  * \param[in] device_handle Device handle obtained by calling ni_device_open
578  * \param[in] p_cap Pointer to a caller allocated ni_device_capability_t
579  * struct
580  * \return On success
581  * NI_RETCODE_SUCCESS
582  * On failure
583  * NI_RETCODE_INVALID_PARAM
584  * NI_RETCODE_ERROR_MEM_ALOC
585  * NI_RETCODE_ERROR_NVME_CMD_FAILED
586  ******************************************************************************/
588 {
589  void * p_buffer = NULL;
591  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
592 
593  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
594 
595  if ( (NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_cap) )
596  {
597  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
598  __func__);
599  retval = NI_RETCODE_INVALID_PARAM;
600  LRETURN;
601  }
602 
603  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE),
605  {
606  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer.\n",
607  NI_ERRNO, __func__);
608  retval = NI_RETCODE_ERROR_MEM_ALOC;
609  LRETURN;
610  }
611 
612  memset(p_buffer, 0, NI_NVME_IDENTITY_CMD_DATA_SZ);
613 
614  uint32_t ui32LBA = IDENTIFY_DEVICE_R;
615  if (ni_nvme_send_read_cmd(device_handle, event_handle, p_buffer, NI_NVME_IDENTITY_CMD_DATA_SZ, ui32LBA) < 0)
616  {
618  LRETURN;
619  }
620 
622 
623 END:
624 
625  ni_aligned_free(p_buffer);
626  ni_log(NI_LOG_DEBUG, "%s(): retval: %d\n", __func__, retval);
627 
628  return retval;
629 }
630 
631 /*!*****************************************************************************
632  * \brief Query device and return device capability structure
633  * This function had replaced ni_device_capability_query
634  * This function can be callback with multi thread
635  *
636  * \param[in] device_handle Device handle obtained by calling ni_device_open
637  * \param[in] p_cap Pointer to a caller allocated ni_device_capability_t
638  * struct
639  * \param[in] device_in_ctxt If device is in ctx
640  * \return On success
641  * NI_RETCODE_SUCCESS
642  * On failure
643  * NI_RETCODE_INVALID_PARAM
644  * NI_RETCODE_ERROR_MEM_ALOC
645  * NI_RETCODE_ERROR_NVME_CMD_FAILED
646  ******************************************************************************/
647 ni_retcode_t ni_device_capability_query2(ni_device_handle_t device_handle,
648  ni_device_capability_t *p_cap, bool device_in_ctxt)
649 {
650  void * p_buffer = NULL;
652  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
653 
654  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
655 
656  if ( (NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_cap) )
657  {
658  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
659  __func__);
660  retval = NI_RETCODE_INVALID_PARAM;
661  LRETURN;
662  }
663 
664  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE),
666  {
667  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer.\n",
668  NI_ERRNO, __func__);
669  retval = NI_RETCODE_ERROR_MEM_ALOC;
670  LRETURN;
671  }
672 
673  memset(p_buffer, 0, NI_NVME_IDENTITY_CMD_DATA_SZ);
674 
675  uint32_t ui32LBA = IDENTIFY_DEVICE_R;
676  if (ni_nvme_send_read_cmd(device_handle, event_handle, p_buffer, NI_NVME_IDENTITY_CMD_DATA_SZ, ui32LBA) < 0)
677  {
679  LRETURN;
680  }
681 
682  ni_populate_device_capability_struct(p_cap, p_buffer, device_handle, device_in_ctxt);
683 
684 END:
685 
686  ni_aligned_free(p_buffer);
687  ni_log(NI_LOG_DEBUG, "%s(): retval: %d\n", __func__, retval);
688 
689  return retval;
690 }
691 
692 /*!*****************************************************************************
693  * \brief Open a new device session depending on the device_type parameter
694  * If device_type is NI_DEVICE_TYPE_DECODER opens decoding session
695  * If device_type is NI_DEVICE_TYPE_ENCODER opens encoding session
696  * If device_type is NI_DEVICE_TYPE_SCALER opens scaling session
697  *
698  * \param[in] p_ctx Pointer to a caller allocated
699  * ni_session_context_t struct
700  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER,
701  * or NI_DEVICE_TYPE_SCALER
702  * \return On success
703  * NI_RETCODE_SUCCESS
704  * On failure
705  * NI_RETCODE_INVALID_PARAM
706  * NI_RETCODE_ERROR_MEM_ALOC
707  * NI_RETCODE_ERROR_NVME_CMD_FAILED
708  * NI_RETCODE_ERROR_INVALID_SESSION
709  ******************************************************************************/
711  ni_device_type_t device_type)
712 {
714  ni_device_pool_t *p_device_pool = NULL;
715  ni_device_context_t *p_device_context = NULL;
716  ni_device_info_t *p_dev_info = NULL;
717  ni_device_info_t dev_info = { 0 };
719  ni_device_context_t *rsrc_ctx = NULL;
720  int i = 0;
721  int rc = 0;
722  int num_coders = 0;
723  bool use_model_load = true;
724  int least_load = 0;
725  int curr_load = 0;
726  int guid = -1;
727  uint32_t num_sw_instances = 0;
728  uint32_t pixel_load = 0xFFFFFFFFU;
729  int user_handles = false;
730  ni_lock_handle_t lock = NI_INVALID_LOCK_HANDLE;
731  ni_device_handle_t handle = NI_INVALID_DEVICE_HANDLE;
732  ni_device_handle_t handle1 = NI_INVALID_DEVICE_HANDLE;
733  // For none nvme block device we just need to pass in dummy
734  uint32_t dummy_io_size = 0;
735  ni_session_context_t p_session_context = {0};
736  ni_device_type_t query_type = device_type;
737 
738  if (!p_ctx)
739  {
740  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
741  __func__);
743  }
744 
745 #ifdef _WIN32
746  if (!IsUserAnAdmin())
747  {
748  ni_log(NI_LOG_ERROR, "ERROR: %s must be in admin priviledge\n", __func__);
750  }
751 #endif
752 
753  ni_pthread_mutex_lock(&p_ctx->mutex);
755 
756  ni_device_session_context_init(&p_session_context);
757 
758  if (NI_INVALID_SESSION_ID != p_ctx->session_id)
759  {
760  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: trying to overwrite existing session, "
761  "device_type %d, session id %d\n",
762  device_type, p_ctx->session_id);
763  retval = NI_RETCODE_INVALID_PARAM;
764  LRETURN;
765  }
766 
767  p_ctx->p_hdr_buf = NULL;
768  p_ctx->hdr_buf_size = 0;
769 
770  p_ctx->roi_side_data_size = p_ctx->nb_rois = 0;
771  p_ctx->av_rois = NULL;
772  p_ctx->roi_map = NULL;
773  p_ctx->avc_roi_map = NULL;
774  p_ctx->hevc_roi_map = NULL;
775  p_ctx->hevc_sub_ctu_roi_buf = NULL;
776  p_ctx->p_master_display_meta_data = NULL;
777 
778  p_ctx->enc_change_params = NULL;
779 
780  p_ctx->target_bitrate = -1;
781  p_ctx->force_idr_frame = 0;
783  p_ctx->ltr_to_set.use_long_term_ref = 0;
784  p_ctx->ltr_interval = -1;
785  p_ctx->ltr_frame_ref_invalid = -1;
786  p_ctx->framerate.framerate_num = 0;
787  p_ctx->framerate.framerate_denom = 0;
788  p_ctx->vui.colorDescPresent = 0;
789  p_ctx->vui.colorPrimaries = 2; // 2 is unspecified
790  p_ctx->vui.colorTrc = 2; // 2 is unspecified
791  p_ctx->vui.colorSpace = 2; // 2 is unspecified
792  p_ctx->vui.aspectRatioWidth = 0;
793  p_ctx->vui.aspectRatioHeight = 0;
794  p_ctx->vui.videoFullRange = 0;
795  p_ctx->max_frame_size = 0;
796  p_ctx->reconfig_crf = -1;
797  p_ctx->reconfig_crf_decimal = 0;
798  p_ctx->reconfig_vbv_buffer_size = 0;
799  p_ctx->reconfig_vbv_max_rate = 0;
800  p_ctx->last_gop_size = 0;
801  p_ctx->initial_frame_delay = 0;
802  p_ctx->current_frame_delay = 0;
803  p_ctx->max_frame_delay = 0;
804  p_ctx->av1_pkt_num = 0;
805  p_ctx->pool_type = NI_POOL_TYPE_NONE;
806  p_ctx->force_low_delay = false;
807  p_ctx->force_low_delay_cnt = 0;
808  p_ctx->pkt_delay_cnt = 0;
809  p_ctx->reconfig_intra_period = -1;
810  p_ctx->reconfig_slice_arg = 0;
811 
812  memset(p_ctx->input_frame_fifo, 0, sizeof(ni_input_frame) * 120);
813  for (i = 0; i < 120; i++)
814  {
815  p_ctx->input_frame_fifo[i].usable = -1;
816  }
817 
818  handle = p_ctx->device_handle;
819  handle1 = p_ctx->blk_io_handle;
820 
821  p_device_pool = ni_rsrc_get_device_pool();
822 
823  if (!p_device_pool)
824  {
825  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Error calling ni_rsrc_get_device_pool()\n");
827  LRETURN;
828  }
829 
830  ni_log2(p_ctx, NI_LOG_DEBUG,
831  "%s: device type %d hw_id %d blk_dev_name: %s dev_xcoder_name: %s.\n",
832  __func__, device_type, p_ctx->hw_id, p_ctx->blk_dev_name,
833  p_ctx->dev_xcoder_name);
834 
835  if (device_type == NI_DEVICE_TYPE_UPLOAD)
836  {
837  //uploader shares resources with encoder to query as encoder for load info
838  query_type = NI_DEVICE_TYPE_ENCODER;
839  }
840 
841  // if caller requested device by block device name, try to find its GUID and
842  // use it to override the hw_id which is the passed in device GUID
843  if (0 != strcmp(p_ctx->blk_dev_name, ""))
844  {
845  int tmp_guid_id;
846  tmp_guid_id =
847  ni_rsrc_get_device_by_block_name(p_ctx->blk_dev_name, device_type);
848  if (tmp_guid_id != NI_RETCODE_FAILURE)
849  {
850  ni_log2(p_ctx, NI_LOG_DEBUG,
851  "%s: block device name %s type %d guid %d is to "
852  "override passed in guid %d\n",
853  __func__, p_ctx->blk_dev_name, device_type, tmp_guid_id,
854  p_ctx->hw_id);
855  p_ctx->hw_id = tmp_guid_id;
856  } else
857  {
858  ni_log(NI_LOG_INFO, "%s: block device name %s type %d NOT found ..\n",
859  __func__, p_ctx->blk_dev_name, device_type);
861  LRETURN;
862  }
863  }
864 
865  // User did not pass in any handle, so we create it for them
866  if ((handle1 == NI_INVALID_DEVICE_HANDLE) && (handle == NI_INVALID_DEVICE_HANDLE))
867  {
868  if (p_ctx->hw_id >=0) // User selected the encder/ decoder number
869  {
870  if ((rsrc_ctx = ni_rsrc_allocate_simple_direct(device_type, p_ctx->hw_id)) == NULL)
871  {
872 
873  ni_log2(p_ctx, NI_LOG_ERROR, "Error XCoder resource allocation: inst %d\n",
874  p_ctx->hw_id);
876  LRETURN;
877  }
878  ni_log2(p_ctx, NI_LOG_DEBUG, "device %p\n", rsrc_ctx);
879  // Now the device name is in the rsrc_ctx, we open this device to get the file handles
880 
881 #ifdef _WIN32
882  if ((handle = ni_device_open(rsrc_ctx->p_device_info->blk_name,
883  &dummy_io_size)) == NI_INVALID_DEVICE_HANDLE)
884  {
885  ni_rsrc_free_device_context(rsrc_ctx);
887  LRETURN;
888  } else
889  {
890  user_handles = true;
891  p_ctx->device_handle = handle;
892  p_ctx->blk_io_handle = handle;
893  p_ctx->max_nvme_io_size = dummy_io_size;
894  handle1 = handle;
895  strcpy(p_ctx->dev_xcoder_name, rsrc_ctx->p_device_info->dev_name);
896  strcpy(p_ctx->blk_xcoder_name, rsrc_ctx->p_device_info->blk_name);
897  ni_rsrc_free_device_context(rsrc_ctx);
898  }
899 #else
900  //The original design (code below) is to open char and block device file separately. And the ffmpeg will close the device twice.
901  //However, in I/O version, char device can't be opened. For compatibility, and to avoid errors, open the block device twice.
902  if (((handle = ni_device_open(rsrc_ctx->p_device_info->dev_name, &dummy_io_size)) == NI_INVALID_DEVICE_HANDLE) ||
903  ((handle1 = ni_device_open(rsrc_ctx->p_device_info->dev_name, &p_ctx->max_nvme_io_size)) == NI_INVALID_DEVICE_HANDLE))
904  {
905  ni_rsrc_free_device_context(rsrc_ctx);
907  LRETURN;
908  } else
909  {
910  user_handles = true;
911  p_ctx->device_handle = handle;
912  p_ctx->blk_io_handle = handle1;
913  // NOLINTNEXTLINE(clang-analyzer-core.NonNullParamChecker): Couldn't determine why it will be NULL.
914  strcpy(p_ctx->dev_xcoder_name, rsrc_ctx->p_device_info->dev_name);
915  strcpy(p_ctx->blk_xcoder_name, rsrc_ctx->p_device_info->blk_name);
916 
917  ni_rsrc_free_device_context(rsrc_ctx);
918  }
919 #endif
920  } else
921  {
922  int tmp_id = -1;
923 
924  // Decide on model load or real load to be used, based on name passed
925  // in from p_ctx->dev_xcoder_name; after checking it will be used to
926  // store device file name.
927  if (0 == strcmp(p_ctx->dev_xcoder_name, NI_BEST_REAL_LOAD_STR))
928  {
929  use_model_load = false;
930  } else if (0 != strcmp(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR))
931  {
932  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s unrecognized option: %s.\n",
933  __func__, p_ctx->dev_xcoder_name);
934  retval = NI_RETCODE_INVALID_PARAM;
935  LRETURN;
936  }
937 
938  if (ni_rsrc_lock_and_open(query_type, &lock) != NI_RETCODE_SUCCESS)
939  {
941  LRETURN;
942  }
943 
944  // We need to query through all the boards to confirm the least load.
945 
946  if (IS_XCODER_DEVICE_TYPE(query_type))
947  {
948  num_coders = p_device_pool->p_device_queue->xcoder_cnt[query_type];
949  } else
950  {
951  retval = NI_RETCODE_INVALID_PARAM;
952  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
953  {
955  LRETURN;
956  }
957  LRETURN;
958  }
959 
960  for (i = 0; i < num_coders; i++)
961  {
962  tmp_id = p_device_pool->p_device_queue->xcoders[query_type][i];
963  p_device_context = ni_rsrc_get_device_context(query_type, tmp_id);
964 
965  if (p_device_context == NULL)
966  {
967  ni_log2(p_ctx, NI_LOG_ERROR,
968  "ERROR: %s() ni_rsrc_get_device_context() failed\n",
969  __func__);
970  continue;
971  }
972 
973  // Code is included in the for loop. In the loop, the device is
974  // just opened once, and it will be closed once too.
975  p_session_context.blk_io_handle = ni_device_open(
976  p_device_context->p_device_info->dev_name, &dummy_io_size);
977  p_session_context.device_handle = p_session_context.blk_io_handle;
978 
979  if (NI_INVALID_DEVICE_HANDLE == p_session_context.device_handle)
980  {
981  ni_log2(p_ctx, NI_LOG_ERROR, "Error open device");
982  ni_rsrc_free_device_context(p_device_context);
983  continue;
984  }
985 
986  p_session_context.hw_id = p_device_context->p_device_info->hw_id;
987  rc = ni_device_session_query(&p_session_context, query_type);
988  if (NI_INVALID_DEVICE_HANDLE != p_session_context.device_handle)
989  {
990  ni_device_close(p_session_context.device_handle);
991  }
992 
993  if (NI_RETCODE_SUCCESS != rc)
994  {
995  ni_log2(p_ctx, NI_LOG_ERROR, "Error query %s %s.%d\n",
996  g_device_type_str[query_type],
997  p_device_context->p_device_info->dev_name,
998  p_device_context->p_device_info->hw_id);
999  ni_rsrc_free_device_context(p_device_context);
1000  continue;
1001  }
1002  ni_rsrc_update_record(p_device_context, &p_session_context);
1003  p_dev_info = p_device_context->p_device_info;
1004 
1005  // here we select the best load
1006  // for decoder/encoder: check the model_load/real_load
1007  // for hwuploader: check directly hwupload pixel load in query result
1008  if (NI_DEVICE_TYPE_UPLOAD == device_type)
1009  {
1010  if (lower_pixel_rate(&p_session_context.load_query, pixel_load))
1011  {
1012  guid = tmp_id;
1013  pixel_load = p_session_context.load_query.total_pixel_load;
1014  memcpy(&dev_info, p_dev_info, sizeof(ni_device_info_t));
1015  }
1016  } else
1017  {
1018  if (use_model_load)
1019  {
1020  curr_load = p_dev_info->model_load;
1021  } else
1022  {
1023  curr_load = p_dev_info->load;
1024  }
1025 
1026  if (i == 0 || curr_load < least_load ||
1027  (curr_load == least_load &&
1028  p_dev_info->active_num_inst < num_sw_instances))
1029  {
1030  guid = tmp_id;
1031  least_load = curr_load;
1032  num_sw_instances = p_dev_info->active_num_inst;
1033  memcpy(&dev_info, p_dev_info, sizeof(ni_device_info_t));
1034  }
1035  }
1036  ni_rsrc_free_device_context(p_device_context);
1037  }
1038 
1039 #ifdef _WIN32
1040  // Now we have the device info that has the least load of the FW
1041  // we open this device and assign the FD
1042  if ((handle = ni_device_open(dev_info.blk_name, &dummy_io_size)) ==
1043  NI_INVALID_DEVICE_HANDLE)
1044  {
1046  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1047  {
1049  LRETURN;
1050  }
1051  LRETURN;
1052  } else
1053  {
1054  p_ctx->device_handle = handle;
1055  p_ctx->blk_io_handle = handle;
1056  p_ctx->max_nvme_io_size = dummy_io_size;
1057  handle1 = handle;
1058  p_ctx->hw_id = guid;
1059  strcpy(p_ctx->dev_xcoder_name, dev_info.dev_name);
1060  strcpy(p_ctx->blk_xcoder_name, dev_info.blk_name);
1061  }
1062 #else
1063  //The original design (code below) is to open char and block device file separately. And the ffmpeg will close the device twice.
1064  //However, in I/O version, char device can't be opened. For compatibility, and to avoid errors, open the block device twice.
1065  if (((handle = ni_device_open(dev_info.dev_name, &dummy_io_size)) == NI_INVALID_DEVICE_HANDLE) ||
1066  ((handle1 = ni_device_open(dev_info.dev_name, &p_ctx->max_nvme_io_size)) == NI_INVALID_DEVICE_HANDLE))
1067  {
1069  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1070  {
1072  LRETURN;
1073  }
1074  LRETURN;
1075  }
1076  else
1077  {
1078  p_ctx->device_handle = handle;
1079  p_ctx->blk_io_handle = handle1;
1080  p_ctx->hw_id = guid;
1081  strcpy(p_ctx->dev_xcoder_name, dev_info.dev_name);
1082  strcpy(p_ctx->blk_xcoder_name, dev_info.blk_name);
1083  }
1084 #endif
1085  }
1086  }
1087  // user passed in the handle, but one of them is invalid, this is error case so we return error
1088  else if((handle1 == NI_INVALID_DEVICE_HANDLE) || (handle == NI_INVALID_DEVICE_HANDLE))
1089  {
1091  LRETURN;
1092  }
1093  // User passed in both handles, so we do not need to allocate for it
1094  else
1095  {
1096  user_handles = true;
1097  }
1098 
1099  ni_log2(p_ctx, NI_LOG_DEBUG,
1100  "Finish open the session dev:%s guid:%d handle:%p handle1:%p\n",
1101  p_ctx->dev_xcoder_name, p_ctx->hw_id,
1102  p_ctx->device_handle, p_ctx->blk_io_handle);
1103 
1104  // get FW API version
1105  p_device_context = ni_rsrc_get_device_context(device_type, p_ctx->hw_id);
1106  if (p_device_context == NULL)
1107  {
1108  ni_log2(p_ctx, NI_LOG_ERROR,
1109  "ERROR: %s() ni_rsrc_get_device_context() failed\n",
1110  __func__);
1111  if (user_handles != true)
1112  {
1113  if(ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1114  {
1116  LRETURN;
1117  }
1118  }
1120  LRETURN;
1121  }
1122 
1123  if (!(strcmp(p_ctx->dev_xcoder_name, "")) || !(strcmp(p_ctx->dev_xcoder_name, NI_BEST_MODEL_LOAD_STR)) ||
1124  !(strcmp(p_ctx->dev_xcoder_name, NI_BEST_REAL_LOAD_STR)))
1125  {
1126  strcpy(p_ctx->dev_xcoder_name, p_device_context->p_device_info->dev_name);
1127  }
1128 
1129  memcpy(p_ctx->fw_rev , p_device_context->p_device_info->fw_rev, 8);
1130 
1131  ni_rsrc_free_device_context(p_device_context);
1132 
1133  retval = ni_device_get_ddr_configuration(p_ctx);
1134  if (retval != NI_RETCODE_SUCCESS)
1135  {
1136  ni_log2(p_ctx, NI_LOG_ERROR,
1137  "ERROR: %s() cannot retrieve DDR configuration\n",
1138  __func__);
1139  if (user_handles != true)
1140  {
1141  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1142  {
1144  LRETURN;
1145  }
1146  }
1147  LRETURN;
1148  }
1149 
1150  if (p_ctx->keep_alive_timeout == 0)
1151  {
1152  ni_log2(p_ctx, NI_LOG_ERROR,
1153  "ERROR: %s() keep_alive_timeout was 0, should be between 1-100. "
1154  "Setting to default of %u\n",
1155  __func__, NI_DEFAULT_KEEP_ALIVE_TIMEOUT);
1157  }
1158  switch (device_type)
1159  {
1161  {
1162  retval = ni_decoder_session_open(p_ctx);
1163  if (user_handles != true)
1164  {
1165  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1166  {
1168  LRETURN;
1169  }
1170  }
1171  // send keep alive signal thread
1172  if (NI_RETCODE_SUCCESS != retval)
1173  {
1174  LRETURN;
1175  }
1176  break;
1177  }
1179  {
1180 #ifndef _WIN32
1181  // p2p is not supported on Windows, so skip following assignments.
1182  ni_xcoder_params_t *p_enc_params;
1183 
1184  p_enc_params = p_ctx->p_session_config;
1185 
1186  if (p_enc_params && p_enc_params->hwframes &&
1187  p_enc_params->p_first_frame)
1188  {
1189  niFrameSurface1_t *pSurface;
1190  pSurface =
1191  (niFrameSurface1_t *)p_enc_params->p_first_frame->p_data[3];
1192  p_ctx->sender_handle =
1193  (ni_device_handle_t)(int64_t)pSurface->device_handle;
1194  p_enc_params->rootBufId = pSurface->ui16FrameIdx;
1195 
1196  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: sender_handle and rootBufId %d set\n",
1197  __func__, p_enc_params->rootBufId);
1198  }
1199 #endif
1200 
1201  retval = ni_encoder_session_open(p_ctx);
1202  if (user_handles != true)
1203  {
1204  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1205  {
1207  LRETURN;
1208  }
1209  }
1210  // send keep alive signal thread
1211  if (NI_RETCODE_SUCCESS != retval)
1212  {
1213  LRETURN;
1214  }
1215  break;
1216  }
1217  case NI_DEVICE_TYPE_UPLOAD:
1218  {
1219  retval = ni_uploader_session_open(p_ctx);
1220  if (user_handles != true)
1221  {
1222  if (ni_rsrc_unlock(query_type, lock) != NI_RETCODE_SUCCESS)
1223  {
1225  LRETURN;
1226  }
1227  }
1228  // send keep alive signal thread
1229  if (NI_RETCODE_SUCCESS != retval)
1230  {
1231  LRETURN;
1232  }
1233  break;
1234  }
1235  case NI_DEVICE_TYPE_SCALER:
1236  {
1237  retval = ni_scaler_session_open(p_ctx);
1238  if (user_handles != true)
1239  {
1240  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1241  {
1243  LRETURN;
1244  }
1245  }
1246  // send keep alive signal thread
1247  if (NI_RETCODE_SUCCESS != retval)
1248  {
1249  LRETURN;
1250  }
1251  break;
1252  }
1253  case NI_DEVICE_TYPE_AI:
1254  {
1255  retval = ni_ai_session_open(p_ctx);
1256  if (user_handles != true)
1257  {
1258  if (ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1259  {
1261  LRETURN;
1262  }
1263  }
1264  // send keep alive signal thread
1265  if (NI_RETCODE_SUCCESS != retval)
1266  {
1267  LRETURN;
1268  }
1269  break;
1270  }
1271  default:
1272  {
1273  if (user_handles != true)
1274  {
1275  if( ni_rsrc_unlock(device_type, lock) != NI_RETCODE_SUCCESS)
1276  {
1278  LRETURN;
1279  }
1280  }
1281  retval = NI_RETCODE_INVALID_PARAM;
1282  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1283  __func__, device_type);
1284  LRETURN;
1285  }
1286  }
1287 
1289  if (!p_ctx->keep_alive_thread_args)
1290  {
1291  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: thread_args allocation failed!\n");
1292  ni_device_session_close(p_ctx, 0, device_type);
1293  retval = NI_RETCODE_ERROR_MEM_ALOC;
1294  LRETURN;
1295  }
1296 
1297  p_ctx->keep_alive_thread_args->session_id = p_ctx->session_id;
1299  p_ctx->keep_alive_thread_args->device_type = device_type;
1302  p_ctx->keep_alive_thread_args->close_thread = false;
1305  p_ctx->keep_alive_thread_args->p_mutex = &p_ctx->mutex;
1306  p_ctx->keep_alive_thread_args->hw_id = p_ctx->hw_id;
1307  p_ctx->last_access_time = ni_gettime_ns();
1308 
1310  sysconf(_SC_PAGESIZE), NI_DATA_BUFFER_LEN))
1311  {
1312  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: keep alive p_buffer allocation failed!\n");
1313  ni_device_session_close(p_ctx, 0, device_type);
1314  retval = NI_RETCODE_ERROR_MEM_ALOC;
1315  LRETURN;
1316  }
1318 
1319  if (0 !=
1320  ni_pthread_create(&p_ctx->keep_alive_thread, NULL,
1322  (void *)p_ctx->keep_alive_thread_args))
1323  {
1324  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to create keep alive thread\n");
1325  p_ctx->keep_alive_thread = (ni_pthread_t){0};
1328  ni_device_session_close(p_ctx, 0, device_type);
1329  retval = NI_RETCODE_ERROR_MEM_ALOC;
1330  LRETURN;
1331  }
1332  ni_log2(p_ctx, NI_LOG_DEBUG, "Enabled keep alive thread\n");
1333 
1334  // allocate memory for encoder change data to be reused
1335  p_ctx->enc_change_params = calloc(1, sizeof(ni_encoder_change_params_t));
1336  if (!p_ctx->enc_change_params)
1337  {
1338  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: enc_change_params allocation failed!\n");
1339  ni_device_session_close(p_ctx, 0, device_type);
1340  retval = NI_RETCODE_ERROR_MEM_ALOC;
1341  }
1342 
1343 END:
1344  ni_device_session_context_clear(&p_session_context);
1345 
1346  if (p_device_pool)
1347  {
1348  ni_rsrc_free_device_pool(p_device_pool);
1349  p_device_pool = NULL;
1350  }
1351 
1353 
1354  ni_pthread_mutex_unlock(&p_ctx->mutex);
1355 
1356  return retval;
1357 }
1358 
1359 /*!*****************************************************************************
1360  * \brief Close device session that was previously opened by calling
1361  * ni_device_session_open()
1362  * If device_type is NI_DEVICE_TYPE_DECODER closes decoding session
1363  * If device_type is NI_DEVICE_TYPE_ENCODER closes encoding session
1364  * If device_type is NI_DEVICE_TYPE_SCALER closes scaling session
1365  *
1366  * \param[in] p_ctx Pointer to a caller allocated
1367  * ni_session_context_t struct
1368  * \param[in] eos_received Flag indicating if End Of Stream indicator was
1369  * received
1370  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER,
1371  * or NI_DEVICE_TYPE_SCALER
1372  * \return On success
1373  * NI_RETCODE_SUCCESS
1374  * On failure
1375  * NI_RETCODE_INVALID_PARAM
1376  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1377  * NI_RETCODE_ERROR_INVALID_SESSION
1378  ******************************************************************************/
1380  int eos_recieved,
1381  ni_device_type_t device_type)
1382 {
1383  int ret;
1385 
1386  if (!p_ctx)
1387  {
1388  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1389  __func__);
1390  return NI_RETCODE_INVALID_PARAM;
1391  }
1392 
1393  ni_pthread_mutex_lock(&p_ctx->mutex);
1395  ni_pthread_mutex_unlock(&p_ctx->mutex);
1396 
1397 #ifdef _WIN32
1398  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args)
1399 #else
1400  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args)
1401 #endif
1402  {
1403  p_ctx->keep_alive_thread_args->close_thread = true;
1404  ret = ni_pthread_join(p_ctx->keep_alive_thread, NULL);
1405  if (ret)
1406  {
1407  ni_log2(p_ctx, NI_LOG_ERROR,
1408  "join keep alive thread fail! : sid %u ret %d\n",
1409  p_ctx->session_id, ret);
1410  }
1413  } else
1414  {
1415  ni_log2(p_ctx, NI_LOG_ERROR, "invalid keep alive thread: %u\n",
1416  p_ctx->session_id);
1417  }
1418 
1419  switch (device_type)
1420  {
1422  {
1423  retval = ni_decoder_session_close(p_ctx, eos_recieved);
1424  break;
1425  }
1426  case NI_DEVICE_TYPE_UPLOAD:
1427  {
1429  // fall through
1430  }
1432  {
1433  retval = ni_encoder_session_close(p_ctx, eos_recieved);
1434  break;
1435  }
1436  case NI_DEVICE_TYPE_SCALER:
1437  {
1438  retval = ni_scaler_session_close(p_ctx, eos_recieved);
1439  break;
1440  }
1441  case NI_DEVICE_TYPE_AI:
1442  {
1443  retval = ni_ai_session_close(p_ctx, eos_recieved);
1444  break;
1445  }
1446  default:
1447  {
1448  retval = NI_RETCODE_INVALID_PARAM;
1449  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1450  __func__, device_type);
1451  break;
1452  }
1453  }
1454 
1455  ni_pthread_mutex_lock(&p_ctx->mutex);
1456  // need set invalid after closed. May cause open invalid parameters.
1458 
1459  ni_memfree(p_ctx->p_hdr_buf);
1460  ni_memfree(p_ctx->av_rois);
1461  ni_memfree(p_ctx->roi_map);
1462  ni_memfree(p_ctx->avc_roi_map);
1463  ni_memfree(p_ctx->hevc_roi_map);
1466  ni_memfree(p_ctx->enc_change_params);
1467  p_ctx->hdr_buf_size = 0;
1468  p_ctx->roi_side_data_size = 0;
1469  p_ctx->nb_rois = 0;
1470  p_ctx->target_bitrate = -1;
1471  p_ctx->force_idr_frame = 0;
1473  p_ctx->ltr_to_set.use_long_term_ref = 0;
1474  p_ctx->ltr_interval = -1;
1475  p_ctx->ltr_frame_ref_invalid = -1;
1476  p_ctx->max_frame_size = 0;
1477  p_ctx->reconfig_crf = -1;
1478  p_ctx->reconfig_crf_decimal = 0;
1479  p_ctx->reconfig_vbv_buffer_size = 0;
1480  p_ctx->reconfig_vbv_max_rate = 0;
1481  p_ctx->last_gop_size = 0;
1482  p_ctx->initial_frame_delay = 0;
1483  p_ctx->current_frame_delay = 0;
1484  p_ctx->max_frame_delay = 0;
1485  p_ctx->av1_pkt_num = 0;
1486  p_ctx->reconfig_intra_period = -1;
1487  p_ctx->reconfig_slice_arg = 0;
1488 
1490  ni_pthread_mutex_unlock(&p_ctx->mutex);
1491 
1492  return retval;
1493 }
1494 
1495 /*!*****************************************************************************
1496  * \brief Send a flush command to the device
1497  * If device_type is NI_DEVICE_TYPE_DECODER sends EOS command to
1498  * decoder
1499  * If device_type is NI_DEVICE_TYPE_ENCODER sends EOS command to
1500  * encoder
1501  *
1502  * \param[in] p_ctx Pointer to a caller allocated
1503  * ni_session_context_t struct
1504  * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER
1505  * \return On success
1506  * NI_RETCODE_SUCCESS
1507  * On failure
1508  * NI_RETCODE_INVALID_PARAM
1509  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1510  * NI_RETCODE_ERROR_INVALID_SESSION
1511  ******************************************************************************/
1513 {
1515  if (!p_ctx)
1516  {
1517  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1518  __func__);
1519  return NI_RETCODE_INVALID_PARAM;
1520  }
1521 
1522  ni_pthread_mutex_lock(&p_ctx->mutex);
1524 
1525  switch (device_type)
1526  {
1528  {
1529  retval = ni_decoder_session_send_eos(p_ctx);
1530  break;
1531  }
1533  {
1534  retval = ni_encoder_session_send_eos(p_ctx);
1535  break;
1536  }
1537  default:
1538  {
1539  retval = NI_RETCODE_INVALID_PARAM;
1540  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1541  __func__, device_type);
1542  break;
1543  }
1544  }
1545  p_ctx->ready_to_close = (NI_RETCODE_SUCCESS == retval);
1547  ni_pthread_mutex_unlock(&p_ctx->mutex);
1548  return retval;
1549 }
1550 
1551 /*!*****************************************************************************
1552  * \brief Save a stream's headers in a decoder session that can be used later
1553  * for continuous decoding from the same source.
1554  *
1555  * \param[in] p_ctx Pointer to a caller allocated
1556  * ni_session_context_t struct
1557  * \param[in] hdr_data Pointer to header data
1558  * \param[in] hdr_size Size of header data in bytes
1559  * \return On success
1560  * NI_RETCODE_SUCCESS
1561  * On failure
1562  * NI_RETCODE_INVALID_PARAM
1563  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1564  * NI_RETCODE_ERROR_INVALID_SESSION
1565  ******************************************************************************/
1567  uint8_t *hdr_data,
1568  uint8_t hdr_size)
1569 {
1571 
1572  if (!p_ctx)
1573  {
1574  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s p_ctx null, return\n", __func__);
1575  return NI_RETCODE_INVALID_PARAM;
1576  }
1577 
1578  if (!hdr_data)
1579  {
1580  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s hdr_data null, return\n", __func__);
1581  return NI_RETCODE_INVALID_PARAM;
1582  } else if (p_ctx->p_hdr_buf && p_ctx->hdr_buf_size == hdr_size &&
1583  0 == memcmp(p_ctx->p_hdr_buf, hdr_data, hdr_size))
1584  {
1585  // no change from the saved headers, success !
1586  return retval;
1587  }
1588 
1589  // update the saved header data
1590  free(p_ctx->p_hdr_buf);
1591  p_ctx->hdr_buf_size = 0;
1592  p_ctx->p_hdr_buf = malloc(hdr_size);
1593  if (p_ctx->p_hdr_buf)
1594  {
1595  memcpy(p_ctx->p_hdr_buf, hdr_data, hdr_size);
1596  p_ctx->hdr_buf_size = hdr_size;
1597  ni_log2(p_ctx, NI_LOG_DEBUG, "%s saved hdr size %u\n", __func__,
1598  p_ctx->hdr_buf_size);
1599  } else
1600  {
1602  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s no memory.\n", __func__);
1603  }
1604  return retval;
1605 }
1606 
1607 /*!*****************************************************************************
1608  * \brief Flush a decoder session to get ready to continue decoding.
1609  * Note: this is different from ni_device_session_flush in that it closes the
1610  * current decode session and opens a new one for continuous decoding.
1611  *
1612  * \param[in] p_ctx Pointer to a caller allocated
1613  * ni_session_context_t struct
1614  * \return On success
1615  * NI_RETCODE_SUCCESS
1616  * On failure
1617  * NI_RETCODE_INVALID_PARAM
1618  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1619  * NI_RETCODE_ERROR_INVALID_SESSION
1620  ******************************************************************************/
1622 {
1624 
1625  if (!p_ctx)
1626  {
1627  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s ctx null, return\n", __func__);
1628  return NI_RETCODE_INVALID_PARAM;
1629  }
1630  ni_pthread_mutex_lock(&p_ctx->mutex);
1631  retval = ni_decoder_session_flush(p_ctx);
1632  if (NI_RETCODE_SUCCESS == retval) {
1633  p_ctx->ready_to_close = 0;
1634  }
1635  ni_pthread_mutex_unlock(&p_ctx->mutex);
1636  return retval;
1637 }
1638 
1639 /*!*****************************************************************************
1640  * \brief Sends data to the device
1641  * If device_type is NI_DEVICE_TYPE_DECODER sends data packet to
1642  * decoder
1643  * If device_type is NI_DEVICE_TYPE_ENCODER sends data frame to encoder
1644  * If device_type is NI_DEVICE_TYPE_AI sends data frame to ai engine
1645  *
1646  * \param[in] p_ctx Pointer to a caller allocated
1647  * ni_session_context_t struct
1648  * \param[in] p_data Pointer to a caller allocated
1649  * ni_session_data_io_t struct which contains either a
1650  * ni_frame_t data frame or ni_packet_t data packet to
1651  * send
1652  * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_ENCODER or
1653  * NI_DEVICE_TYPE_AI
1654  * If NI_DEVICE_TYPE_DECODER is specified, it is
1655  * expected that the ni_packet_t struct inside the
1656  * p_data pointer contains data to send.
1657  * If NI_DEVICE_TYPE_ENCODER or NI_DEVICE_TYPE_AI is
1658  * specified, it is expected that the ni_frame_t
1659  * struct inside the p_data pointer contains data to
1660  * send.
1661  * \return On success
1662  * Total number of bytes written
1663  * On failure
1664  * NI_RETCODE_INVALID_PARAM
1665  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1666  * NI_RETCODE_ERROR_INVALID_SESSION
1667  ******************************************************************************/
1669 {
1671 
1672  if (!p_ctx || !p_data)
1673  {
1674  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1675  __func__);
1676  return NI_RETCODE_INVALID_PARAM;
1677  }
1678  // Here check if keep alive thread is closed.
1679 #ifdef _WIN32
1680  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
1682 #else
1683  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
1685 #endif
1686  {
1687  ni_log2(p_ctx, NI_LOG_ERROR,
1688  "ERROR: %s() keep alive thread has been closed, "
1689  "hw:%d, session:%d\n",
1690  __func__, p_ctx->hw_id, p_ctx->session_id);
1692  }
1693 
1694  ni_pthread_mutex_lock(&p_ctx->mutex);
1695  // In close state, let the close process execute first.
1696  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
1697  {
1698  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
1699  ni_pthread_mutex_unlock(&p_ctx->mutex);
1700  ni_usleep(100);
1702  }
1704  ni_pthread_mutex_unlock(&p_ctx->mutex);
1705 
1706  switch (device_type)
1707  {
1709  {
1710  retval = ni_decoder_session_write(p_ctx, &(p_data->data.packet));
1711  break;
1712  }
1714  {
1715  retval = ni_encoder_session_write(p_ctx, &(p_data->data.frame));
1716  break;
1717  }
1718  case NI_DEVICE_TYPE_AI:
1719  {
1720  retval = ni_ai_session_write(p_ctx, &(p_data->data.frame));
1721  break;
1722  }
1723  default:
1724  {
1725  retval = NI_RETCODE_INVALID_PARAM;
1726  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1727  __func__, device_type);
1728  break;
1729  }
1730  }
1731 
1732  ni_pthread_mutex_lock(&p_ctx->mutex);
1734  ni_pthread_mutex_unlock(&p_ctx->mutex);
1735  return retval;
1736 }
1737 
1738 /*!*****************************************************************************
1739  * \brief Read data from the device
1740  * If device_type is NI_DEVICE_TYPE_DECODER reads data packet from
1741  * decoder
1742  * If device_type is NI_DEVICE_TYPE_ENCODER reads data frame from
1743  * encoder
1744  * If device_type is NI_DEVICE_TYPE_AI reads data frame from AI engine
1745  *
1746  * \param[in] p_ctx Pointer to a caller allocated
1747  * ni_session_context_t struct
1748  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
1749  * struct which contains either a ni_frame_t data frame
1750  * or ni_packet_t data packet to send
1751  * \param[in] device_type NI_DEVICE_TYPE_DECODER, NI_DEVICE_TYPE_ENCODER, or
1752  * NI_DEVICE_TYPE_SCALER
1753  * If NI_DEVICE_TYPE_DECODER is specified, data that
1754  * was read will be placed into ni_frame_t struct
1755  * inside the p_data pointer
1756  * If NI_DEVICE_TYPE_ENCODER is specified, data that
1757  * was read will be placed into ni_packet_t struct
1758  * inside the p_data pointer
1759  * If NI_DEVICE_TYPE_AI is specified, data that was
1760  * read will be placed into ni_frame_t struct inside
1761  * the p_data pointer
1762  * \return On success
1763  * Total number of bytes read
1764  * On failure
1765  * NI_RETCODE_INVALID_PARAM
1766  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1767  * NI_RETCODE_ERROR_INVALID_SESSION
1768  ******************************************************************************/
1770 {
1772  if ((!p_ctx) || (!p_data))
1773  {
1774  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1775  __func__);
1776  return NI_RETCODE_INVALID_PARAM;
1777  }
1778 
1779  // Here check if keep alive thread is closed.
1780 #ifdef _WIN32
1781  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
1783 #else
1784  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
1786 #endif
1787  {
1788  ni_log2(p_ctx, NI_LOG_ERROR,
1789  "ERROR: %s() keep alive thread has been closed, "
1790  "hw:%d, session:%d\n",
1791  __func__, p_ctx->hw_id, p_ctx->session_id);
1793  }
1794 
1795  ni_pthread_mutex_lock(&p_ctx->mutex);
1796  // In close state, let the close process execute first.
1797  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
1798  {
1799  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
1800  ni_pthread_mutex_unlock(&p_ctx->mutex);
1801  ni_usleep(100);
1803  }
1805  ni_pthread_mutex_unlock(&p_ctx->mutex);
1806 
1807  switch (device_type)
1808  {
1810  {
1811  int seq_change_read_count = 0;
1812  p_data->data.frame.src_codec = p_ctx->codec_format;
1813  for (;;)
1814  {
1815  retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
1816  // check resolution change only after initial setting obtained
1817  // p_data->data.frame.video_width is picture width and will be 32-align
1818  // adjusted to frame size; p_data->data.frame.video_height is the same as
1819  // frame size, then compare them to saved one for resolution checking
1820  //
1821  uint32_t aligned_width;
1822  if(QUADRA)
1823  {
1824  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
1825  }
1826  else
1827  {
1828  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
1829  }
1830 
1831  if (0 == retval && seq_change_read_count)
1832  {
1833  ni_log2(p_ctx, NI_LOG_DEBUG,
1834  "%s (decoder): seq change NO data, next time.\n", __func__);
1835  p_ctx->active_video_width = 0;
1836  p_ctx->active_video_height = 0;
1837  p_ctx->actual_video_width = 0;
1838  break;
1839  }
1840  else if (retval < 0)
1841  {
1842  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
1843  __func__, retval);
1844  break;
1845  }
1846  // aligned_width may equal to active_video_width if bit depth and width
1847  // are changed at the same time. So, check video_width != actual_video_width.
1848  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
1849  (p_data->data.frame.video_width &&
1850  p_data->data.frame.video_height &&
1851  (aligned_width != p_ctx->active_video_width ||
1852  p_data->data.frame.video_height != p_ctx->active_video_height))))
1853  {
1854  ni_log2(
1855  p_ctx, NI_LOG_DEBUG,
1856  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
1857  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
1858  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
1859  aligned_width, p_data->data.frame.video_height,
1860  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
1861  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
1862  // reset active video resolution to 0 so it can be queried in the re-read
1863  p_ctx->active_video_width = 0;
1864  p_ctx->active_video_height = 0;
1865  p_ctx->actual_video_width = 0;
1866  seq_change_read_count++;
1867  }
1868  else
1869  {
1870  break;
1871  }
1872  }
1873  break;
1874  }
1876  {
1877  retval = ni_encoder_session_read(p_ctx, &(p_data->data.packet));
1878  break;
1879  }
1880  case NI_DEVICE_TYPE_AI:
1881  {
1882  retval = ni_ai_session_read(p_ctx, &(p_data->data.packet));
1883  break;
1884  }
1885  default:
1886  {
1887  retval = NI_RETCODE_INVALID_PARAM;
1888  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1889  __func__, device_type);
1890  break;
1891  }
1892  }
1893 
1894  ni_pthread_mutex_lock(&p_ctx->mutex);
1896  ni_pthread_mutex_unlock(&p_ctx->mutex);
1897  return retval;
1898 }
1899 
1900 /*!*****************************************************************************
1901  * \brief Query session data from the device -
1902  * If device_type is valid, will query session data
1903  * from specified device type
1904  *
1905  * \param[in] p_ctx Pointer to a caller allocated
1906  * ni_session_context_t struct
1907  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
1908  * NI_DEVICE_TYPE_ENCODER or
1909  * NI_DEVICE_TYPE_SCALER or
1910  * NI_DEVICE_TYPE_AI or
1911  * NI_DEVICE_TYPE_UPLOADER
1912  *
1913  * \return On success
1914  * NI_RETCODE_SUCCESS
1915  * On failure
1916  * NI_RETCODE_INVALID_PARAM
1917  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1918  * NI_RETCODE_ERROR_INVALID_SESSION
1919  ******************************************************************************/
1921 {
1923  if (!p_ctx)
1924  {
1925  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1926  __func__);
1927  return NI_RETCODE_INVALID_PARAM;
1928  }
1929 
1930  if (IS_XCODER_DEVICE_TYPE(device_type))
1931  {
1932  retval = ni_xcoder_session_query(p_ctx, device_type);
1933  } else
1934  {
1935  retval = NI_RETCODE_INVALID_PARAM;
1936  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1937  __func__, device_type);
1938  }
1939 
1940  return retval;
1941 }
1942 
1943 /*!*****************************************************************************
1944  * \brief Query detail session data from the device -
1945  * If device_type is valid, will query session data
1946  * from specified device type
1947  *
1948  * \param[in] p_ctx Pointer to a caller allocated
1949  * ni_session_context_t struct
1950  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
1951  * NI_DEVICE_TYPE_ENCODER or
1952  *
1953  * \return On success
1954  * NI_RETCODE_SUCCESS
1955  * On failure
1956  * NI_RETCODE_INVALID_PARAM
1957  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1958  * NI_RETCODE_ERROR_INVALID_SESSION
1959  ******************************************************************************/
1961 {
1963  if (!p_ctx)
1964  {
1965  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
1966  __func__);
1967  return NI_RETCODE_INVALID_PARAM;
1968  }
1969 
1970  if (IS_XCODER_DEVICE_TYPE(device_type))
1971  {
1972  retval = ni_xcoder_session_query_detail(p_ctx, device_type, detail_data, 0);
1973  } else
1974  {
1975  retval = NI_RETCODE_INVALID_PARAM;
1976  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
1977  __func__, device_type);
1978  }
1979 
1980  return retval;
1981 }
1982 
1983 /*!*****************************************************************************
1984  * \brief Query detail session data from the device -
1985  * If device_type is valid, will query session data
1986  * from specified device type
1987  *
1988  * \param[in] p_ctx Pointer to a caller allocated
1989  * ni_session_context_t struct
1990  * \param[in] device_type NI_DEVICE_TYPE_DECODER or
1991  * NI_DEVICE_TYPE_ENCODER or
1992  *
1993  * \return On success
1994  * NI_RETCODE_SUCCESS
1995  * On failure
1996  * NI_RETCODE_INVALID_PARAM
1997  * NI_RETCODE_ERROR_NVME_CMD_FAILED
1998  * NI_RETCODE_ERROR_INVALID_SESSION
1999  ******************************************************************************/
2001 {
2003  if (!p_ctx)
2004  {
2005  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null, return\n",
2006  __func__);
2007  return NI_RETCODE_INVALID_PARAM;
2008  }
2009 
2010  if (IS_XCODER_DEVICE_TYPE(device_type))
2011  {
2012  retval = ni_xcoder_session_query_detail(p_ctx, device_type, detail_data, 1);
2013  } else
2014  {
2015  retval = NI_RETCODE_INVALID_PARAM;
2016  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
2017  __func__, device_type);
2018  }
2019 
2020  return retval;
2021 }
2022 
2023 /*!*****************************************************************************
2024  * \brief Send namespace num and SRIOv index to the device with specified logic block
2025  * address.
2026  *
2027  * \param[in] device_handle Device handle obtained by calling ni_device_open
2028  * \param[in] namespace_num Set the namespace number with designated sriov
2029  * \param[in] sriov_index Identify which sriov need to be set
2030  *
2031  * \return On success
2032  * NI_RETCODE_SUCCESS
2033  * On failure
2034  * NI_RETCODE_ERROR_MEM_ALOC
2035  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2036  ******************************************************************************/
2037 ni_retcode_t ni_device_config_namespace_num(ni_device_handle_t device_handle,
2038  uint32_t namespace_num, uint32_t sriov_index)
2039 {
2040  ni_log(NI_LOG_DEBUG, "%s namespace_num %u sriov_index %u\n",
2041  __func__, namespace_num, sriov_index);
2042  return ni_device_config_ns_qos(device_handle, namespace_num, sriov_index);
2043 }
2044 
2045 /*!*****************************************************************************
2046  * \brief Send qos mode to the device with specified logic block
2047  * address.
2048  *
2049  * \param[in] device_handle Device handle obtained by calling ni_device_open
2050  * \param[in] mode The requested qos mode
2051  *
2052  * \return On success
2053  * NI_RETCODE_SUCCESS
2054  * On failure
2055  * NI_RETCODE_ERROR_MEM_ALOC
2056  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2057  ******************************************************************************/
2058 ni_retcode_t ni_device_config_qos(ni_device_handle_t device_handle,
2059  uint32_t mode)
2060 {
2061  ni_log(NI_LOG_DEBUG, "%s device_handle %p mode %u\n",
2062  __func__, device_handle, mode);
2063  return ni_device_config_ns_qos(device_handle, QOS_NAMESPACE_CODE, mode);
2064 }
2065 
2066 /*!*****************************************************************************
2067  * \brief Send qos over provisioning mode to target namespace with specified logic
2068  * block address.
2069  *
2070  * \param[in] device_handle Device handle obtained by calling ni_device_open
2071  * \param[in] device_handle_t Target device handle of namespace required for OP
2072  * \param[in] over_provision The request overprovision percent
2073  *
2074  * \return On success
2075  * NI_RETCODE_SUCCESS
2076  * On failure
2077  * NI_RETCODE_ERROR_MEM_ALOC
2078  * NI_RETCODE_ERROR_NVME_CMD_FAILED
2079  ******************************************************************************/
2080 ni_retcode_t ni_device_config_qos_op(ni_device_handle_t device_handle,
2081  ni_device_handle_t device_handle_t,
2082  uint32_t over_provision)
2083 {
2084  ni_retcode_t retval;
2085  float f_over_provision = 0;
2086  memcpy(&f_over_provision, &over_provision, sizeof(int32_t));
2087  ni_log(NI_LOG_DEBUG, "%s device_handle %p target %p over_provision %f\n",
2088  __func__, device_handle, device_handle_t, f_over_provision);
2089  retval = ni_device_config_ns_qos(device_handle, QOS_OP_CONFIG_REC_OP_CODE,
2090  over_provision);
2091  if (NI_RETCODE_SUCCESS != retval)
2092  {
2093  return retval;
2094  }
2095  retval = ni_device_config_ns_qos(device_handle_t, QOS_OP_CONFIG_CODE,
2096  0);
2097  return retval;
2098 }
2099 
2100 /*!*****************************************************************************
2101  * \brief Allocate preliminary memory for the frame buffer based on provided
2102  * parameters. Applicable to YUV420 Planar pixel (8 or 10 bit/pixel)
2103  * format or 32-bit RGBA.
2104  *
2105  * \param[in] p_frame Pointer to a caller allocated
2106  * ni_frame_t struct
2107  * \param[in] video_width Width of the video frame
2108  * \param[in] video_height Height of the video frame
2109  * \param[in] alignment Allignment requirement
2110  * \param[in] metadata_flag Flag indicating if space for additional metadata
2111  * should be allocated
2112  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel,
2113  * 4 for 32 bits/pixel (RGBA)
2114  * \param[in] hw_frame_count Number of hw descriptors stored
2115  * \param[in] is_planar 0 if semiplanar else planar
2116  *
2117  * \return On success
2118  * NI_RETCODE_SUCCESS
2119  * On failure
2120  * NI_RETCODE_INVALID_PARAM
2121  * NI_RETCODE_ERROR_MEM_ALOC
2122  ******************************************************************************/
2124  int video_height, int alignment,
2125  int metadata_flag, int factor,
2126  int hw_frame_count, int is_planar)
2127 {
2128  void* p_buffer = NULL;
2129  int metadata_size = 0;
2130  int retval = NI_RETCODE_SUCCESS;
2131  int width_aligned = video_width;
2132  int height_aligned = video_height;
2133 
2134  if ((!p_frame) || ((factor!=1) && (factor!=2) && (factor !=4))
2135  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
2136  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
2137  {
2138  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2139  "factor %d, video_width %d, video_height %d\n",
2140  __func__, factor, video_width, video_height);
2141  return NI_RETCODE_INVALID_PARAM;
2142  }
2143 
2144  if (metadata_flag)
2145  {
2146  metadata_size = NI_FW_META_DATA_SZ + NI_MAX_SEI_DATA;
2147  }
2148 
2149  if (QUADRA)
2150  {
2151  switch (factor)
2152  {
2153  case 1: /* 8-bit YUV420 */
2154  case 2: /* 10-bit YUV420 */
2155  width_aligned = ((((video_width * factor) + 127) / 128) * 128) / factor;
2156  height_aligned = ((video_height + 1) / 2) * 2;
2157  break;
2158  case 4: /* 32-bit RGBA */
2159  //64byte aligned => 16 rgba pixels
2160  width_aligned = NI_VPU_ALIGN16(video_width);
2161  height_aligned = ((video_height + 1) / 2) * 2;
2162  break;
2163  default:
2164  return NI_RETCODE_INVALID_PARAM;
2165  }
2166  }
2167  else
2168  {
2169  width_aligned = ((video_width + 31) / 32) * 32;
2170  height_aligned = ((video_height + 7) / 8) * 8;
2171  if (alignment)
2172  {
2173  height_aligned = ((video_height + 15) / 16) * 16;
2174  }
2175  }
2176 
2177  int luma_size = width_aligned * height_aligned * factor;
2178  int chroma_b_size;
2179  int chroma_r_size;
2180  if (QUADRA)
2181  {
2182  int chroma_width_aligned = ((((video_width / 2 * factor) + 127) / 128) * 128) / factor;
2183  if (is_planar == NI_PIXEL_PLANAR_FORMAT_TILED4X4 ||
2184  is_planar == NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR)
2185  {
2186  chroma_width_aligned =
2187  ((((video_width * factor) + 127) / 128) * 128) / factor;
2188  }
2189  int chroma_height_aligned = height_aligned / 2;
2190  chroma_b_size = chroma_r_size = chroma_width_aligned * chroma_height_aligned * factor;
2191  if (is_planar == NI_PIXEL_PLANAR_FORMAT_TILED4X4 ||
2192  is_planar == NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR)
2193  {
2194  chroma_r_size = 0;
2195  }
2196  if (4 == factor)
2197  {
2198  chroma_b_size = chroma_r_size = 0;
2199  }
2200  //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);
2201  }
2202  else
2203  {
2204  chroma_b_size = luma_size / 4;
2205  chroma_r_size = chroma_b_size;
2206  }
2207  int buffer_size;
2208 
2209  /* if hw_frame_count is zero, this is a software frame */
2210  if (hw_frame_count == 0)
2211  buffer_size = luma_size + chroma_b_size + chroma_r_size + metadata_size;
2212  else
2213  buffer_size =
2214  (int)sizeof(niFrameSurface1_t) * hw_frame_count + metadata_size;
2215 
2216  // added 2 blocks of 512 bytes buffer space to handle any extra metadata
2217  // retrieval from fw
2218  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT * 3;
2219  //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);
2220 
2221  //Check if need to free
2222  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
2223  {
2225  "%s: free current p_frame, p_frame->buffer_size=%u\n", __func__,
2226  p_frame->buffer_size);
2227  ni_frame_buffer_free(p_frame);
2228  }
2229 
2230  //Check if need to realocate
2231  if (p_frame->buffer_size != buffer_size)
2232  {
2233  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
2234  {
2235  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
2236  NI_ERRNO, __func__);
2237  retval = NI_RETCODE_ERROR_MEM_ALOC;
2238  LRETURN;
2239  }
2240 
2241  // init once after allocation
2242  //memset(p_buffer, 0, buffer_size);
2243  p_frame->buffer_size = buffer_size;
2244  p_frame->p_buffer = p_buffer;
2245 
2246  ni_log(NI_LOG_DEBUG, "%s: Allocate new p_frame buffer\n", __func__);
2247  }
2248  else
2249  {
2250  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
2251  }
2252 
2253  if (hw_frame_count)
2254  {
2255  p_frame->data_len[0] = 0;
2256  p_frame->data_len[1] = 0;
2257  p_frame->data_len[2] = 0;
2258  p_frame->data_len[3] = sizeof(niFrameSurface1_t)*hw_frame_count;
2259  }
2260  else
2261  {
2262  p_frame->data_len[0] = luma_size;
2263  p_frame->data_len[1] = chroma_b_size;
2264  p_frame->data_len[2] = chroma_r_size;
2265  p_frame->data_len[3] = 0;//unused by hwdesc
2266  }
2267 
2268  p_frame->p_data[0] = p_frame->p_buffer;
2269  p_frame->p_data[1] = p_frame->p_data[0] + p_frame->data_len[0];
2270  p_frame->p_data[2] = p_frame->p_data[1] + p_frame->data_len[1];
2271  p_frame->p_data[3] = p_frame->p_data[2] + p_frame->data_len[2]; //hwdescriptor
2272 
2273  // init p_data[3] to 0 so that ni_frame_buffer_free frees only valid DMA buf
2274  // fd in hw frame read from fw
2275  if (hw_frame_count)
2276  {
2277  memset(p_frame->p_data[3], 0, sizeof(niFrameSurface1_t) * hw_frame_count);
2278  }
2279 
2280  p_frame->video_width = width_aligned;
2281  p_frame->video_height = height_aligned;
2282 
2283  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);
2284  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2285  p_frame->buffer_size);
2286 
2287 END:
2288 
2289  if (NI_RETCODE_SUCCESS != retval)
2290  {
2291  ni_aligned_free(p_buffer);
2292  }
2293 
2294  return retval;
2295 }
2296 
2297 /*!*****************************************************************************
2298  * \brief Wrapper function for ni_frame_buffer_alloc. Meant to handle RGBA min.
2299  * resoulution considerations for encoder.
2300  *
2301  * \param[in] p_frame Pointer to a caller allocated
2302  * ni_frame_t struct
2303  * \param[in] video_width Width of the video frame
2304  * \param[in] video_height Height of the video frame
2305  * \param[in] alignment Allignment requirement
2306  * \param[in] metadata_flag Flag indicating if space for additional metadata
2307  * should be allocated
2308  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel,
2309  * 4 for 32 bits/pixel (RGBA)
2310  * \param[in] hw_frame_count Number of hw descriptors stored
2311  * \param[in] is_planar 0 if semiplanar else planar
2312  * \param[in] pix_fmt pixel format to distinguish between planar types
2313  * and/or components
2314  *
2315  * \return On success
2316  * NI_RETCODE_SUCCESS
2317  * On failure
2318  * NI_RETCODE_INVALID_PARAM
2319  * NI_RETCODE_ERROR_MEM_ALOC
2320  ******************************************************************************/
2322  int video_height, int alignment,
2323  int metadata_flag, int factor,
2324  int hw_frame_count, int is_planar,
2325  ni_pix_fmt_t pix_fmt)
2326 {
2327  int extra_len = 0;
2328  int dst_stride[NI_MAX_NUM_DATA_POINTERS] = {0};
2329  int height_aligned[NI_MAX_NUM_DATA_POINTERS] = {0};
2330 
2331  if (((factor!=1) && (factor!=2) && (factor !=4))
2332  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
2333  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
2334  {
2335  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2336  "factor %d, video_width %d, video_height %d\n",
2337  __func__, factor, video_width, video_height);
2338  return NI_RETCODE_INVALID_PARAM;
2339  }
2340 
2341  switch (pix_fmt)
2342  {
2343  case NI_PIX_FMT_YUV420P:
2345  case NI_PIX_FMT_NV12:
2346  case NI_PIX_FMT_P010LE:
2347  case NI_PIX_FMT_NV16:
2348  case NI_PIX_FMT_YUYV422:
2349  case NI_PIX_FMT_UYVY422:
2350  case NI_PIX_FMT_ARGB:
2351  case NI_PIX_FMT_ABGR:
2352  case NI_PIX_FMT_RGBA:
2353  case NI_PIX_FMT_BGRA:
2354  case NI_PIX_FMT_BGR0:
2355  break;
2356  default:
2357  ni_log(NI_LOG_ERROR, "ERROR: %s pix_fmt %d not supported \n",
2358  __func__, pix_fmt);
2359  return NI_RETCODE_INVALID_PARAM;
2360  }
2361  //Get stride info for original resolution
2362  ni_get_frame_dim(video_width, video_height,
2363  pix_fmt,
2364  dst_stride, height_aligned);
2365 
2366  if (metadata_flag)
2367  {
2368  extra_len = NI_FW_META_DATA_SZ + NI_MAX_SEI_DATA;
2369  }
2370 
2371  return ni_frame_buffer_alloc_pixfmt(p_frame, pix_fmt, video_width,
2372  video_height, dst_stride, alignment,
2373  extra_len);
2374 }
2375 
2376 /*!*****************************************************************************
2377  * \brief Allocate preliminary memory for the frame buffer based on provided
2378  * parameters.
2379  *
2380  * \param[in] p_frame Pointer to a caller allocated
2381  * ni_frame_t struct
2382  * \param[in] video_width Width of the video frame
2383  * \param[in] video_height Height of the video frame
2384  * \param[in] alignment Allignment requirement
2385  * \param[in] pixel_format Format for input
2386  *
2387  * \return On success
2388  * NI_RETCODE_SUCCESS
2389  * On failure
2390  * NI_RETCODE_INVALID_PARAM
2391  * NI_RETCODE_ERROR_MEM_ALOC
2392  ******************************************************************************/
2394  int video_height, int pixel_format)
2395 {
2396  void *p_buffer = NULL;
2397  int retval = NI_RETCODE_SUCCESS;
2398  int width_aligned = video_width;
2399  int height_aligned = video_height;
2400  int buffer_size;
2401  int luma_size;
2402  int chroma_b_size;
2403  int chroma_r_size;
2404 
2405  if ((!p_frame) || (video_width > NI_MAX_RESOLUTION_WIDTH) ||
2406  (video_width <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT) ||
2407  (video_height <= 0))
2408  {
2410  "ERROR: %s passed parameters are null or not supported, "
2411  "video_width %d, video_height %d\n",
2412  __func__, video_width, video_height);
2413  return NI_RETCODE_INVALID_PARAM;
2414  }
2415 
2416  switch (pixel_format)
2417  {
2418  case NI_PIX_FMT_YUV420P:
2419  width_aligned = NI_VPU_ALIGN128(video_width);
2420  height_aligned = NI_VPU_CEIL(video_height, 2);
2421 
2422  luma_size = width_aligned * height_aligned;
2423  chroma_b_size =
2424  NI_VPU_ALIGN128(video_width / 2) * height_aligned / 2;
2425  chroma_r_size = chroma_b_size;
2426  break;
2428  width_aligned = NI_VPU_ALIGN128(video_width * 2) / 2;
2429  height_aligned = NI_VPU_CEIL(video_height, 2);
2430 
2431  luma_size = width_aligned * height_aligned * 2;
2432  chroma_b_size = NI_VPU_ALIGN128(video_width) * height_aligned / 2;
2433  chroma_r_size = chroma_b_size;
2434  break;
2435  case NI_PIX_FMT_NV12:
2436  width_aligned = NI_VPU_ALIGN128(video_width);
2437  height_aligned = NI_VPU_CEIL(video_height, 2);
2438 
2439  luma_size = width_aligned * height_aligned;
2440  chroma_b_size = width_aligned * height_aligned / 2;
2441  chroma_r_size = 0;
2442  break;
2443  case NI_PIX_FMT_P010LE:
2444  width_aligned = NI_VPU_ALIGN128(video_width * 2) / 2;
2445  height_aligned = NI_VPU_CEIL(video_height, 2);
2446 
2447  luma_size = width_aligned * height_aligned * 2;
2448  chroma_b_size = NI_VPU_ALIGN128(video_width) * height_aligned;
2449  chroma_r_size = 0;
2450  break;
2451  case NI_PIX_FMT_NV16:
2452  width_aligned = NI_VPU_ALIGN64(video_width);
2453  height_aligned = video_height;
2454 
2455  luma_size = width_aligned * height_aligned;
2456  chroma_b_size = luma_size;
2457  chroma_r_size = 0;
2458  break;
2459  case NI_PIX_FMT_YUYV422:
2460  case NI_PIX_FMT_UYVY422:
2461  width_aligned = NI_VPU_ALIGN16(video_width);
2462  height_aligned = video_height;
2463 
2464  luma_size = width_aligned * height_aligned * 2;
2465  chroma_b_size = 0;
2466  chroma_r_size = 0;
2467  break;
2468  case NI_PIX_FMT_RGBA:
2469  case NI_PIX_FMT_BGRA:
2470  case NI_PIX_FMT_ARGB:
2471  case NI_PIX_FMT_ABGR:
2472  case NI_PIX_FMT_BGR0:
2473  width_aligned = NI_VPU_ALIGN16(video_width);
2474  height_aligned = video_height;
2475 
2476  luma_size = width_aligned * height_aligned * 4;
2477  chroma_b_size = 0;
2478  chroma_r_size = 0;
2479  break;
2480  case NI_PIX_FMT_BGRP:
2481  width_aligned = NI_VPU_ALIGN32(video_width);
2482  height_aligned = video_height;
2483 
2484  luma_size = width_aligned * height_aligned;
2485  chroma_b_size = luma_size;
2486  chroma_r_size = luma_size;
2487  break;
2488  default:
2489  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n", pixel_format);
2490  return NI_RETCODE_INVALID_PARAM;
2491  }
2492 
2493  /* Allocate local memory to hold a software ni_frame */
2494  buffer_size = luma_size + chroma_b_size + chroma_r_size;
2495 
2496  /* Round up to nearest 4K block */
2497  buffer_size = NI_VPU_ALIGN4096(buffer_size);
2498 
2499  ni_log(NI_LOG_DEBUG, "%s: Rlen %d Glen %d Blen %d buffer_size %d\n",
2500  __func__, luma_size, chroma_b_size, chroma_r_size, buffer_size);
2501 
2502  /* If the frame has changed, reallocate it */
2503  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
2504  {
2506  "%s: free current p_frame, p_frame->buffer_size=%u\n", __func__,
2507  p_frame->buffer_size);
2508  ni_frame_buffer_free(p_frame);
2509  }
2510 
2511  /* Check if need to reallocate */
2512  if (p_frame->buffer_size != buffer_size)
2513  {
2514  ni_log(NI_LOG_DEBUG, "%s: Allocate new p_frame buffer\n", __func__);
2515  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
2516  {
2518  "ERROR %d: %s() Cannot allocate p_frame buffer.\n", NI_ERRNO,
2519  __func__);
2520  retval = NI_RETCODE_ERROR_MEM_ALOC;
2521  LRETURN;
2522  }
2523  } else
2524  {
2525  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
2526  p_buffer = p_frame->p_buffer;
2527  }
2528 
2529  // init once after allocation
2530  // memset(p_buffer, 0, buffer_size);
2531 
2532  p_frame->buffer_size = buffer_size;
2533  p_frame->p_buffer = p_buffer;
2534 
2535  p_frame->data_len[0] = luma_size;
2536  p_frame->data_len[1] = chroma_b_size;
2537  p_frame->data_len[2] = chroma_r_size;
2538  p_frame->data_len[3] = 0;
2539 
2540  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
2541  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + p_frame->data_len[0];
2542  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + p_frame->data_len[1];
2543  p_frame->p_data[3] = (uint8_t *)p_frame->p_data[2] + p_frame->data_len[2];
2544 
2545  // init p_data[3] to 0 so that ni_frame_buffer_free frees only valid DMA buf
2546  // fd in hw frame read from fw
2547  p_frame->video_width = width_aligned;
2548  p_frame->video_height = height_aligned;
2549 
2550  // 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);
2551  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2552  p_frame->buffer_size);
2553 END:
2554 
2555  if (NI_RETCODE_SUCCESS != retval)
2556  {
2557  ni_aligned_free(p_buffer);
2558  }
2559 
2560  return retval;
2561 }
2562 
2563 /*!*****************************************************************************
2564  * \brief Allocate memory for decoder frame buffer based on provided
2565  * parameters; the memory is retrieved from a buffer pool and will be
2566  * returned to the same buffer pool by ni_decoder_frame_buffer_free.
2567  * Note: all attributes of ni_frame_t will be set up except for memory and
2568  * buffer, which rely on the pool being allocated; the pool will be
2569  * allocated only after the frame resolution is known.
2570  *
2571  * \param[in] p_pool Buffer pool to get the memory from
2572  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
2573  * \param[in] alloc_mem Whether to get memory from buffer pool
2574  * \param[in] video_width Width of the video frame
2575  * \param[in] video_height Height of the video frame
2576  * \param[in] alignment Alignment requirement
2577  * \param[in] factor 1 for 8 bits/pixel format, 2 for 10 bits/pixel
2578  * \param[in] is_planar 0 if semiplanar else planar
2579  *
2580  * \return On success
2581  * NI_RETCODE_SUCCESS
2582  * On failure
2583  * NI_RETCODE_INVALID_PARAM
2584  * NI_RETCODE_ERROR_MEM_ALOC
2585  ******************************************************************************/
2587  ni_frame_t *p_frame, int alloc_mem,
2588  int video_width, int video_height,
2589  int alignment, int factor,
2590  int is_planar)
2591 {
2592  int retval = NI_RETCODE_SUCCESS;
2593 
2594  int width_aligned;
2595  int height_aligned;
2596 
2597  if ((!p_frame) || ((factor!=1) && (factor!=2))
2598  || (video_width > NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
2599  || (video_height > NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
2600  {
2601  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2602  "factor %d, video_width %d, video_height %d\n",
2603  __func__, factor, video_width, video_height);
2604  return NI_RETCODE_INVALID_PARAM;
2605  }
2606 
2607  if (QUADRA)
2608  {
2609  width_aligned = ((((video_width * factor) + 127) / 128) * 128) / factor;
2610  height_aligned = video_height;
2611  }
2612  else
2613  {
2614  width_aligned = ((video_width + 31) / 32) * 32;
2615  height_aligned = ((video_height + 7) / 8) * 8;
2616  if (alignment)
2617  {
2618  height_aligned = ((video_height + 15) / 16) * 16;
2619  }
2620  }
2621 
2622  ni_log(NI_LOG_DEBUG, "%s: aligned=%dx%d orig=%dx%d\n", __func__,
2623  width_aligned, height_aligned, video_width, video_height);
2624 
2625  int luma_size = width_aligned * height_aligned * factor;
2626  int chroma_b_size;
2627  int chroma_r_size;
2628  if (QUADRA)
2629  {
2630  int chroma_width_aligned = ((((video_width / 2 * factor) + 127) / 128) * 128) / factor;
2631  if (!is_planar)
2632  {
2633  chroma_width_aligned =
2634  ((((video_width * factor) + 127) / 128) * 128) / factor;
2635  }
2636  int chroma_height_aligned = height_aligned / 2;
2637  chroma_b_size = chroma_r_size = chroma_width_aligned * chroma_height_aligned * factor;
2638  if (!is_planar)
2639  {
2640  chroma_r_size = 0;
2641  }
2642  }
2643  else
2644  {
2645  chroma_b_size = luma_size / 4;
2646  chroma_r_size = chroma_b_size;
2647  }
2648  int buffer_size = luma_size + chroma_b_size + chroma_r_size +
2650 
2651  // added 2 blocks of 512 bytes buffer space to handle any extra metadata
2652  // retrieval from fw
2653  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT * 3;
2654 
2655  p_frame->buffer_size = buffer_size;
2656 
2657  // if need to get a buffer from pool, pool must have been set up
2658  if (alloc_mem)
2659  {
2660  if (! p_pool)
2661  {
2662  ni_log(NI_LOG_ERROR, "ERROR %s: invalid pool!\n", __func__);
2663  retval = NI_RETCODE_ERROR_MEM_ALOC;
2664  LRETURN;
2665  }
2666 
2667  p_frame->dec_buf = ni_buf_pool_get_buffer(p_pool);
2668  if (! p_frame->dec_buf)
2669  {
2670  retval = NI_RETCODE_ERROR_MEM_ALOC;
2671  LRETURN;
2672  }
2673 
2674  p_frame->p_buffer = p_frame->dec_buf->buf;
2675 
2676  ni_log(NI_LOG_DEBUG, "%s: got new frame ptr %p buffer %p\n", __func__,
2677  p_frame->p_buffer, p_frame->dec_buf);
2678  }
2679  else
2680  {
2681  p_frame->dec_buf = NULL;
2682  p_frame->p_buffer = NULL;
2683  ni_log(NI_LOG_DEBUG, "%s: NOT alloc mem buffer\n", __func__);
2684  }
2685 
2686  if (p_frame->p_buffer)
2687  {
2688  p_frame->p_data[0] = p_frame->p_buffer;
2689  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
2690  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
2691  p_frame->p_data[3] = p_frame->p_data[2] + chroma_r_size;
2692  }
2693  else
2694  {
2695  p_frame->p_data[0] = p_frame->p_data[1] = p_frame->p_data[2] = NULL;
2696  }
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; //for hwdesc
2702 
2703  p_frame->video_width = width_aligned;
2704  p_frame->video_height = height_aligned;
2705 
2706  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
2707  p_frame->buffer_size);
2708 
2709 END:
2710 
2711  return retval;
2712 }
2713 
2714 /*!*****************************************************************************
2715  * \brief Check if incoming frame is encoder zero copy compatible or not
2716  *
2717  * \param[in] p_enc_ctx pointer to encoder context
2718  * [in] p_enc_params pointer to encoder parameters
2719  * [in] width input width
2720  * [in] height input height
2721  * [in] linesize input linesizes (pointer to array)
2722  * [in] set_linesize setup linesizes 0 means not setup linesizes, 1 means setup linesizes (before encoder open)
2723  *
2724  * \return on success and can do zero copy
2725  * NI_RETCODE_SUCCESS
2726  *
2727  * cannot do zero copy
2728  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
2729  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
2730  * NI_RETCODE_INVALID_PARAM
2731  *
2732 *******************************************************************************/
2734  ni_xcoder_params_t *p_enc_params,
2735  int width, int height,
2736  const int linesize[],
2737  bool set_linesize)
2738 {
2739  // check pixel format / width / height / linesize can be supported
2740  if ((!p_enc_ctx) || (!p_enc_params) || (!linesize)
2741  || (linesize[0]<=0)
2742  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
2743  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
2744  {
2745  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
2746  "p_enc_ctx %p, p_enc_params %p, linesize %p, "
2747  "width %d, height %d linesize[0] %d\n",
2748  __func__, p_enc_ctx, p_enc_params, linesize,
2749  width, height, (linesize) ? linesize[0] : 0);
2750  return NI_RETCODE_INVALID_PARAM;
2751  }
2752 
2753  // check fw revision (if fw_rev has been populated in open session)
2754  if (p_enc_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
2756  "6Q") < 0))
2757  {
2758  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.Q\n", __func__);
2760  }
2761 
2762  bool isrgba = false;
2763  bool isplanar = false;
2764  bool issemiplanar = false;
2765 
2766  switch (p_enc_ctx->pixel_format)
2767  {
2768  case NI_PIX_FMT_YUV420P:
2770  isplanar = true;
2771  break;
2772  case NI_PIX_FMT_NV12:
2773  case NI_PIX_FMT_P010LE:
2774  issemiplanar = true;
2775  break;
2776  case NI_PIX_FMT_ABGR:
2777  case NI_PIX_FMT_ARGB:
2778  case NI_PIX_FMT_RGBA:
2779  case NI_PIX_FMT_BGRA:
2780  isrgba = true;
2781  break;
2782  default:
2783  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
2785  }
2786 
2787  // check fw revision (if fw_rev has been populated in open session)
2788  if (issemiplanar &&
2791  "6q") < 0))
2792  {
2793  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
2795  }
2796 
2797  // check zero copy compatibilty and set linesize
2798  if (p_enc_params->zerocopy_mode) // always allow zero copy for RGBA, because RGBA pixel format data copy currently not supported
2799  {
2800  if (set_linesize)
2801  {
2802  bool ishwframe = (p_enc_params->hwframes) ? true : false;
2803  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
2804  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s isrgba %u issemiplanar %u, ishwframe %u, "
2805  "p_enc_ctx %p, p_enc_params %p, linesize %p, "
2806  "width %d, height %d, linesize[0] %d linesize[1] %d\n",
2807  __func__, isrgba, issemiplanar, ishwframe, p_enc_ctx, p_enc_params, linesize,
2808  width, height, linesize[0], linesize[1]);
2809 
2810  if (linesize[0] <= max_linesize &&
2811  linesize[0] % 2 == 0 && //even stride
2812  linesize[1] % 2 == 0 && //even stride
2813  width % 2 == 0 && //even width
2814  height % 2 == 0 && //even height
2815  width >= NI_MIN_WIDTH &&
2816  height >= NI_MIN_HEIGHT &&
2817  !ishwframe &&
2818  (!isplanar || linesize[2] == linesize[1]) // for planar, make sure cb linesize equal to cr linesize
2819  )
2820  {
2821  // send luma / chorma linesize to device (device is also aware frame will not be padded for 2-pass workaround)
2822  p_enc_params->luma_linesize = linesize[0];
2823  p_enc_params->chroma_linesize = (isrgba) ? 0 : linesize[1]; // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format
2824  return NI_RETCODE_SUCCESS;
2825  }
2826  else
2827  {
2828  p_enc_params->luma_linesize = 0;
2829  p_enc_params->chroma_linesize = 0;
2830  }
2831  }
2832  else if (p_enc_params->luma_linesize ||
2833  p_enc_params->chroma_linesize)
2834  {
2835  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s "
2836  "luma_linesize %d, chroma_linesize %d, "
2837  "linesize[0] %d, linesize[1] %d\n",
2838  __func__, p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
2839  linesize[0], linesize[1]);
2840  if (p_enc_params->luma_linesize != linesize[0] ||
2841  (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
2842  )
2843  {
2844 #ifndef XCODER_311
2845  // linesizes can change during SW frame seqeunce change transcoding when FFmpeg noautoscale option is not set
2846  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: linesize changed from %u %u to %u %u - resolution change?\n", __func__,
2847  p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
2848  linesize[0], linesize[1]);
2849 #endif
2850  }
2851  else
2852  return NI_RETCODE_SUCCESS;
2853  }
2854  }
2855 
2857 }
2858 
2859 /*!*****************************************************************************
2860  * \brief Allocate memory for encoder zero copy (metadata, etc.)
2861  * for encoding based on given
2862  * parameters, taking into account pic linesize and extra data.
2863  * Applicable to YUV planr / semi-planar 8 or 10 bit and RGBA pixel formats.
2864  *
2865  *
2866  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
2867  * \param[in] video_width Width of the video frame
2868  * \param[in] video_height Height of the video frame
2869  * \param[in] linesize Picture line size
2870  * \param[in] data Picture data pointers (for each of YUV planes)
2871  * \param[in] extra_len Extra data size (incl. meta data)
2872  *
2873  * \return On success
2874  * NI_RETCODE_SUCCESS
2875  * On failure
2876  * NI_RETCODE_INVALID_PARAM
2877  * NI_RETCODE_ERROR_MEM_ALOC
2878  *****************************************************************************/
2880  int video_width, int video_height,
2881  const int linesize[], const uint8_t *data[],
2882  int extra_len)
2883 {
2884  int retval = NI_RETCODE_SUCCESS;
2885 
2886  if ((!p_frame) || (!linesize) || (!data))
2887  {
2888  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2889  "p_frame %p, linesize %p, data %p\n",
2890  __func__, p_frame, linesize, data);
2891  return NI_RETCODE_INVALID_PARAM;
2892  }
2893 
2895  "%s: resolution=%dx%d linesize=%d/%d/%d "
2896  "data=%p %p %p extra_len=%d\n",
2897  __func__, video_width, video_height,
2898  linesize[0], linesize[1], linesize[2],
2899  data[0], data[1], data[2], extra_len);
2900 
2901  if (p_frame->buffer_size)
2902  {
2903  p_frame->buffer_size = 0; //notify p_frame->p_buffer is not allocated
2904  ni_aligned_free(p_frame->p_buffer); // also free the temp p_buffer allocated for niFrameSurface1_t in encoder init stage
2905  }
2906 
2907  p_frame->p_buffer = (uint8_t *)data[0];
2908  p_frame->p_data[0] = (uint8_t *)data[0];
2909  p_frame->p_data[1] = (uint8_t *)data[1];
2910  p_frame->p_data[2] = (uint8_t *)data[2];
2911 
2912  int luma_size = linesize[0] * video_height;
2913  int chroma_b_size = 0;
2914  int chroma_r_size = 0;
2915 
2916  // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format, but only data[0] pointer is populated
2917  if (data[1]) // cb size is 0 for RGBA pixel format
2918  chroma_b_size = linesize[1] * (video_height / 2);
2919 
2920  if (data[2]) // cr size is 0 for semi-planar or RGBA pixel format
2921  chroma_r_size = linesize[2] * (video_height / 2);
2922 
2923  //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);
2924 
2925  uint32_t start_offset;
2926  uint32_t total_start_len = 0;
2927  int i;
2928 
2929  p_frame->inconsecutive_transfer = 0;
2930 
2931  // rgba has one data pointer, semi-planar has two data pointers
2932  if ((data[1] && (data[0] + luma_size != data[1]))
2933  || (data[2] && (data[1] + chroma_b_size != data[2])))
2934  {
2935  p_frame->inconsecutive_transfer = 1;
2936  }
2937 
2938  if (p_frame->inconsecutive_transfer)
2939  {
2940  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
2941  {
2942  start_offset = (uintptr_t)p_frame->p_data[i] % NI_MEM_PAGE_ALIGNMENT;
2943  p_frame->start_len[i] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
2944  total_start_len += p_frame->start_len[i];
2945  }
2946  }
2947  else
2948  {
2949  start_offset = (uintptr_t)p_frame->p_data[0] % NI_MEM_PAGE_ALIGNMENT;
2950  p_frame->start_len[0] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
2951  p_frame->start_len[1] = p_frame->start_len[2] = 0;
2952  total_start_len = p_frame->start_len[0];
2953  }
2954  p_frame->total_start_len = total_start_len;
2955 
2956  if (ni_encoder_metadata_buffer_alloc(p_frame, extra_len))
2957  {
2958  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_metadata_buffer buffer.\n",
2959  NI_ERRNO, __func__);
2960  retval = NI_RETCODE_ERROR_MEM_ALOC;
2961  LRETURN;
2962  }
2963  p_frame->separate_metadata = 1;
2964 
2965  if (total_start_len)
2966  {
2967  if (ni_encoder_start_buffer_alloc(p_frame))
2968  {
2969  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_start_buffer buffer.\n",
2970  NI_ERRNO, __func__);
2971  retval = NI_RETCODE_ERROR_MEM_ALOC;
2972  LRETURN;
2973  }
2974  p_frame->separate_start = 1;
2975 
2976  // copy non-4k-aligned part at the start of YUV data
2977  int start_buffer_offset = 0;
2978  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
2979  {
2980  if (p_frame->p_data[i])
2981  {
2982  memcpy(p_frame->p_start_buffer+start_buffer_offset, p_frame->p_data[i],
2983  p_frame->start_len[i]);
2984  start_buffer_offset += p_frame->start_len[i];
2985  }
2986  }
2987  }
2988 
2989  p_frame->data_len[0] = luma_size;
2990  p_frame->data_len[1] = chroma_b_size;
2991  p_frame->data_len[2] = chroma_r_size;
2992  p_frame->data_len[3] = 0;//unused by hwdesc
2993 
2994  p_frame->video_width = video_width;
2995  p_frame->video_height = video_height;
2996 
2998  "%s: success: p_metadata_buffer %p metadata_buffer_size %u "
2999  "p_start_buffer %p start_buffer_size %u data_len %u %u %u\n",
3000  __func__, p_frame->p_metadata_buffer, p_frame->metadata_buffer_size,
3001  p_frame->p_start_buffer, p_frame->start_buffer_size,
3002  p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2]);
3003 
3004 END:
3005 
3006  return retval;
3007 }
3008 
3009 
3010 /*!*****************************************************************************
3011  * \brief Check if incoming frame is hwupload zero copy compatible or not
3012  *
3013  * \param[in] p_upl_ctx pointer to uploader context
3014  * [in] width input width
3015  * [in] height input height
3016  * [in] linesize input linesizes (pointer to array)
3017  * [in] pixel_format input pixel format
3018  *
3019  * \return on success and can do zero copy
3020  * NI_RETCODE_SUCCESS
3021  *
3022  * cannot do zero copy
3023  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
3024  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
3025  * NI_RETCODE_INVALID_PARAM
3026  *
3027 *******************************************************************************/
3029  int width, int height,
3030  const int linesize[], int pixel_format)
3031 {
3032  // check pixel format / width / height / linesize can be supported
3033  if ((!p_upl_ctx) || (!linesize)
3034  || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3035  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
3036  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
3037  {
3038  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
3039  "p_enc_ctx %p, linesize %p, "
3040  "width %d, height %d linesize[0] %d\n",
3041  __func__, p_upl_ctx, linesize,
3042  width, height, (linesize) ? linesize[0] : 0);
3043  return NI_RETCODE_INVALID_PARAM;
3044  }
3045 
3046  // check fw revision (if fw_rev has been populated in open session)
3047  if (p_upl_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
3049  "6S") < 0))
3050  {
3051  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.S\n", __func__);
3053  }
3054 
3055  // upload does not have zeroCopyMode parameter, currently only allows resolution >= 1080p
3056  if ((width * height) < NI_NUM_OF_PIXELS_1080P)
3058 
3059  // check zero copy compatibilty
3060  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s pixel_format %d "
3061  "p_upl_ctx %p, linesize %p, "
3062  "width %d, height %d, linesize[0] %d\n",
3063  __func__, pixel_format, p_upl_ctx, linesize,
3064  width, height, linesize[0]);
3065 
3066  int bit_depth_factor;
3067  bool isrgba = false;
3068  bool isplanar = false;
3069  bool issemiplanar = false;
3070 
3071  switch (pixel_format)
3072  {
3073  case NI_PIX_FMT_YUV420P:
3074  isplanar = true;
3075  bit_depth_factor = 1;
3076  break;
3078  isplanar = true;
3079  bit_depth_factor = 2;
3080  break;
3081  case NI_PIX_FMT_NV12:
3082  issemiplanar = true;
3083  bit_depth_factor = 1;
3084  break;
3085  case NI_PIX_FMT_P010LE:
3086  issemiplanar = true;
3087  bit_depth_factor = 2;
3088  break;
3089  case NI_PIX_FMT_ABGR:
3090  case NI_PIX_FMT_ARGB:
3091  case NI_PIX_FMT_RGBA:
3092  case NI_PIX_FMT_BGRA:
3093  isrgba = true;
3094  bit_depth_factor = 4; // not accurate, only for linesize check
3095  break;
3096  default:
3097  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
3099  }
3100 
3101  // check fw revision (if fw_rev has been populated in open session)
3102  if (issemiplanar &&
3105  "6q") < 0))
3106  {
3107  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
3109  }
3110 
3111  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
3112  if (linesize[0] <= max_linesize &&
3113  width % 2 == 0 && //even width
3114  height % 2 == 0 && //even height
3115  width >= NI_MIN_WIDTH && height >= NI_MIN_HEIGHT)
3116  {
3117  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3118  if (isplanar &&
3119  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3120  linesize[1] == NI_VPU_ALIGN128(width * bit_depth_factor / 2) &&
3121  linesize[2] == linesize[1])
3122  return NI_RETCODE_SUCCESS;
3123 
3124  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3125  if (issemiplanar &&
3126  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3127  linesize[1] == linesize[0])
3128  return NI_RETCODE_SUCCESS;
3129 
3130  // rgba only support 64 bytes aligned for 2D
3131  if (isrgba &&
3132  linesize[0] == NI_VPU_ALIGN64(width * bit_depth_factor))
3133  return NI_RETCODE_SUCCESS;
3134  }
3135 
3137 }
3138 
3139 /*!*****************************************************************************
3140  * \brief Allocate memory for the frame buffer for encoding based on given
3141  * parameters, taking into account pic line size and extra data.
3142  * Applicable to YUV420p AVFrame only. 8 or 10 bit/pixel.
3143  * Cb/Cr size matches that of Y.
3144  *
3145  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3146  *
3147  * \param[in] video_width Width of the video frame
3148  * \param[in] video_height Height of the video frame
3149  * \param[in] linesize Picture line size
3150  * \param[in] alignment Allignment requirement
3151  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3152  * to allocate any buffer (zero-copy from existing)
3153  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3154  *
3155  * \return On success
3156  * NI_RETCODE_SUCCESS
3157  * On failure
3158  * NI_RETCODE_INVALID_PARAM
3159  * NI_RETCODE_ERROR_MEM_ALOC
3160  *****************************************************************************/
3162  int video_height, int linesize[],
3163  int alignment, int extra_len,
3164  bool alignment_2pass_wa)
3165 {
3166  void* p_buffer = NULL;
3167  int height_aligned;
3168  int retval = NI_RETCODE_SUCCESS;
3169 
3170  if ((!p_frame) || (!linesize) || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3171  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
3172  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
3173  {
3174  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3175  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3176  __func__, p_frame, linesize, video_width, video_height);
3177  return NI_RETCODE_INVALID_PARAM;
3178  }
3179 
3180  if (QUADRA)
3181  {
3182  height_aligned = ((video_height + 1) / 2) * 2;
3183  } else
3184  {
3185  height_aligned = ((video_height + 7) / 8) * 8;
3186 
3187  if (alignment)
3188  {
3189  height_aligned = ((video_height + 15) / 16) * 16;
3190  }
3191  }
3192  if (height_aligned < NI_MIN_HEIGHT)
3193  {
3194  height_aligned = NI_MIN_HEIGHT;
3195  }
3196 
3198  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d "
3199  "extra_len=%d\n",
3200  __func__, video_width, height_aligned, video_width, video_height,
3201  linesize[0], linesize[1], linesize[2], extra_len);
3202 
3203  int luma_size = linesize[0] * height_aligned;
3204  int chroma_b_size;
3205  int chroma_r_size;
3206  if (QUADRA)
3207  {
3208  chroma_b_size = chroma_r_size = linesize[1] * (height_aligned / 2);
3209  if (alignment_2pass_wa)
3210  {
3211  // for 2-pass encode output mismatch WA, need to extend (and pad) Cr plane height, because 1st pass assume input 32 align
3212  chroma_r_size = linesize[1] * (((height_aligned + 31) / 32) * 32) / 2;
3213  }
3214  //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);
3215  }
3216  else
3217  {
3218  chroma_b_size = luma_size / 4;
3219  chroma_r_size = luma_size / 4;
3220  }
3221  if(extra_len >= 0)
3222  {
3223  int buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
3224 
3225  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3226 
3227  //Check if Need to free
3228  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3229  {
3231  "%s: free current p_frame, "
3232  "p_frame->buffer_size=%u\n",
3233  __func__, p_frame->buffer_size);
3234  ni_frame_buffer_free(p_frame);
3235  }
3236 
3237  //Check if need to realocate
3238  if (p_frame->buffer_size != buffer_size)
3239  {
3240  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3241  {
3242  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3243  NI_ERRNO, __func__);
3244  retval = NI_RETCODE_ERROR_MEM_ALOC;
3245  LRETURN;
3246  }
3247 
3248  // init once after allocation
3249  memset(p_buffer, 0, buffer_size);
3250  p_frame->buffer_size = buffer_size;
3251  p_frame->p_buffer = p_buffer;
3252 
3253  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3254  }
3255  else
3256  {
3257  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3258  }
3259  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3260  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3261  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_b_size;
3262  }
3263  else
3264  {
3265  p_frame->buffer_size = 0; //no ownership
3266  }
3267 
3268  p_frame->data_len[0] = luma_size;
3269  p_frame->data_len[1] = chroma_b_size;
3270  p_frame->data_len[2] = chroma_r_size;
3271  p_frame->data_len[3] = 0;//unused by hwdesc
3272 
3273  p_frame->video_width = video_width;
3274  p_frame->video_height = height_aligned;
3275 
3277  "%s: success: p_frame->p_buffer %p "
3278  "p_frame->buffer_size=%u\n",
3279  __func__, p_frame->p_buffer, p_frame->buffer_size);
3280 
3281 END:
3282 
3283  if (NI_RETCODE_SUCCESS != retval)
3284  {
3285  ni_aligned_free(p_buffer);
3286  }
3287 
3288  return retval;
3289 }
3290 
3291 /*!*****************************************************************************
3292  * \brief allocate device destination frame from scaler hwframe pool
3293  *
3294  * \param
3295  *
3296  * \return 0 if successful, < 0 otherwise
3297  ******************************************************************************/
3299  ni_scaler_input_params_t scaler_params,
3300  niFrameSurface1_t *p_surface)
3301 {
3302  int ret = 0;
3303  if (scaler_params.op != NI_SCALER_OPCODE_OVERLAY && scaler_params.op != NI_SCALER_OPCODE_WATERMARK)
3304  {
3305  ret = ni_device_alloc_frame(
3306  p_ctx, scaler_params.output_width, scaler_params.output_height,
3307  scaler_params.output_format, NI_SCALER_FLAG_IO,
3308  scaler_params.out_rec_width, scaler_params.out_rec_height,
3309  scaler_params.out_rec_x, scaler_params.out_rec_y,
3310  scaler_params.rgba_color, -1, NI_DEVICE_TYPE_SCALER);
3311  } else
3312  {
3313  // in vf_overlay_ni.c: flags = (s->alpha_format ? NI_SCALER_FLAG_PA : 0) | NI_SCALER_FLAG_IO;
3314  ret = ni_device_alloc_frame(
3315  p_ctx, scaler_params.output_width, scaler_params.output_height,
3316  scaler_params.output_format, NI_SCALER_FLAG_IO,
3317  scaler_params.out_rec_width, scaler_params.out_rec_height,
3318  scaler_params.out_rec_x, scaler_params.out_rec_y,
3319  p_surface->ui32nodeAddress, p_surface->ui16FrameIdx,
3321  }
3322  return ret;
3323 }
3324 
3325 /*!*****************************************************************************
3326  * \brief allocate device input frame by hw descriptor. This call won't actually allocate
3327  a frame but sends the incoming hardware frame index to the scaler manager
3328  *
3329  * \param
3330  *
3331  * \return 0 if successful, < 0 otherwise
3332  ******************************************************************************/
3334  ni_scaler_input_params_t scaler_params,
3335  niFrameSurface1_t *p_src_surface)
3336 {
3337  int ret = 0;
3338 
3339  ret = ni_device_alloc_frame(
3340  p_ctx, scaler_params.input_width, scaler_params.input_height,
3341  scaler_params.input_format, 0, scaler_params.in_rec_width,
3342  scaler_params.in_rec_height, scaler_params.in_rec_x,
3343  scaler_params.in_rec_y, p_src_surface->ui32nodeAddress,
3344  p_src_surface->ui16FrameIdx, NI_DEVICE_TYPE_SCALER);
3345  return ret;
3346 }
3347 
3348 /*!*****************************************************************************
3349  * \brief init output pool of scaler frames
3350  *
3351  * \param
3352  *
3353  * \return 0 if successful, < 0 otherwise
3354  ******************************************************************************/
3356  ni_scaler_input_params_t scaler_params)
3357 {
3358  int rc = 0;
3359  int options = NI_SCALER_FLAG_IO | NI_SCALER_FLAG_PC;
3360  if (p_ctx->isP2P)
3361  options |= NI_SCALER_FLAG_P2;
3362 
3363  /* Allocate a pool of frames by the scaler */
3364  rc = ni_device_alloc_frame(p_ctx, scaler_params.output_width,
3365  scaler_params.output_height,
3366  scaler_params.output_format, options,
3367  0, // rec width
3368  0, // rec height
3369  0, // rec X pos
3370  0, // rec Y pos
3371  NI_MAX_FILTER_POOL_SIZE, // rgba color/pool size
3372  0, // frame index
3374  return rc;
3375 }
3376 
3377 /*!*****************************************************************************
3378 * \brief Allocate memory for the frame buffer based on provided parameters
3379 * taking into account pic line size and extra data.
3380 * Applicable to nv12 AVFrame only. Cb/Cr size matches that of Y.
3381 *
3382 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3383 *
3384 * \param[in] video_width Width of the video frame
3385 * \param[in] video_height Height of the video frame
3386 * \param[in] linesize Picture line size
3387 * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3388 * to allocate any buffer (zero-copy from existing)
3389 * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3390 *
3391 * \return On success
3392 * NI_RETCODE_SUCCESS
3393 * On failure
3394 * NI_RETCODE_INVALID_PARAM
3395 * NI_RETCODE_ERROR_MEM_ALOC
3396 *****************************************************************************/
3398  int video_height, int linesize[],
3399  int extra_len, bool alignment_2pass_wa)
3400 {
3401  void* p_buffer = NULL;
3402  int height_aligned;
3403  int retval = NI_RETCODE_SUCCESS;
3404 
3405  if ((!p_frame) || (!linesize) || (linesize[0] <= 0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3406  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
3407  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
3408  {
3409  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3410  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3411  __func__, p_frame, linesize, video_width, video_height);
3412  return NI_RETCODE_INVALID_PARAM;
3413  }
3414 
3415  height_aligned = ((video_height + 1) / 2) * 2;
3416 
3417  if (height_aligned < NI_MIN_HEIGHT)
3418  {
3419  height_aligned = NI_MIN_HEIGHT;
3420  }
3421 
3423  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d extra_len=%d\n",
3424  __func__, video_width, height_aligned, video_width, video_height,
3425  linesize[0], linesize[1], linesize[2], extra_len);
3426 
3427  int luma_size = linesize[0] * height_aligned;
3428  int chroma_br_size = luma_size / 2;
3429  //int chroma_r_size = luma_size / 4;
3430  if (alignment_2pass_wa)
3431  {
3432  // for 2-pass encode output mismatch WA, need to extend (and pad) CbCr plane height, because 1st pass assume input 32 align
3433  chroma_br_size = linesize[0] * ((((height_aligned + 31) / 32) * 32) / 2);
3434  }
3435  if (extra_len >= 0)
3436  {
3437  int buffer_size = luma_size + chroma_br_size + extra_len;
3438 
3439  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3440 
3441  //Check if Need to free
3442  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3443  {
3444  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
3445  __func__, p_frame->buffer_size);
3446  ni_frame_buffer_free(p_frame);
3447  }
3448 
3449  //Check if need to realocate
3450  if (p_frame->buffer_size != buffer_size)
3451  {
3452  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3453  {
3454  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3455  NI_ERRNO, __func__);
3456  retval = NI_RETCODE_ERROR_MEM_ALOC;
3457  LRETURN;
3458  }
3459 
3460  // init once after allocation
3461  memset(p_buffer, 0, buffer_size);
3462  p_frame->buffer_size = buffer_size;
3463  p_frame->p_buffer = p_buffer;
3464 
3465  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3466  }
3467  else
3468  {
3469  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3470  }
3471 
3472  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3473  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3474  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_br_size;
3475  }
3476  else
3477  {
3478  p_frame->buffer_size = 0; //no ownership
3479  }
3480  p_frame->data_len[0] = luma_size;
3481  p_frame->data_len[1] = chroma_br_size;
3482  p_frame->data_len[2] = 0;
3483 
3484  p_frame->video_width = video_width;
3485  p_frame->video_height = height_aligned;
3486 
3487  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
3488  p_frame->buffer_size);
3489 
3490 END:
3491 
3492  if (NI_RETCODE_SUCCESS != retval)
3493  {
3494  ni_aligned_free(p_buffer);
3495  }
3496 
3497  return retval;
3498 }
3499 
3500 /*!*****************************************************************************
3501  * \brief This API is a wrapper for ni_encoder_frame_buffer_alloc(), used
3502  * for planar pixel formats, and ni_frame_buffer_alloc_nv(), used for
3503  * semi-planar pixel formats. This API is meant to combine the
3504  * functionality for both individual format APIs.
3505  * Allocate memory for the frame buffer for encoding based on given
3506  * parameters, taking into account pic line size and extra data.
3507  * Applicable to YUV420p(8 or 10 bit/pixel) or nv12 AVFrame.
3508  * Cb/Cr size matches that of Y.
3509  *
3510  * \param[in] planar true: if planar:
3511  * pixel_format == (NI_PIX_FMT_YUV420P ||
3512  * NI_PIX_FMT_YUV420P10LE ||NI_PIX_FMT_RGBA).
3513  * false: semi-planar:
3514  * pixel_format == (NI_PIX_FMT_NV12 ||
3515  * NI_PIX_FMT_P010LE).
3516  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3517  * \param[in] video_width Width of the video frame
3518  * \param[in] video_height Height of the video frame
3519  * \param[in] linesize Picture line size
3520  * \param[in] alignment Allignment requirement. Only used for planar format.
3521  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3522  * to allocate any buffer (zero-copy from existing)
3523  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3524  *
3525  * \return On success
3526  * NI_RETCODE_SUCCESS
3527  * On failure
3528  * NI_RETCODE_INVALID_PARAM
3529  * NI_RETCODE_ERROR_MEM_ALOC
3530  *****************************************************************************/
3532  int video_width, int video_height,
3533  int linesize[], int alignment,
3534  int extra_len,
3535  bool alignment_2pass_wa)
3536 {
3537  if (true == planar)
3538  {
3539  return ni_encoder_frame_buffer_alloc(p_frame, video_width, video_height,
3540  linesize, alignment, extra_len,
3541  alignment_2pass_wa);
3542  }
3543  else
3544  {
3545  return ni_frame_buffer_alloc_nv(p_frame, video_width, video_height,
3546  linesize, extra_len,
3547  alignment_2pass_wa);
3548  }
3549 }
3550 
3551 /*!*****************************************************************************
3552  * \brief Free frame buffer that was previously allocated with either
3553  * ni_frame_buffer_alloc or ni_encoder_frame_buffer_alloc or
3554  * ni_frame_buffer_alloc_nv
3555  *
3556  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3557  *
3558  * \return On success NI_RETCODE_SUCCESS
3559  * On failure NI_RETCODE_INVALID_PARAM
3560  ******************************************************************************/
3562 {
3563  int i;
3565 
3566  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3567 
3568  if (!p_frame)
3569  {
3570  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3571  LRETURN;
3572  }
3573 
3574  if (!p_frame->p_buffer)
3575  {
3576  ni_log(NI_LOG_DEBUG, "WARN: %s(): already freed, nothing to free\n",
3577  __func__);
3578  }
3579 
3580 #ifndef _WIN32
3581  // If this is a hardware frame with a DMA buf fd attached, close the DMA buf fd
3582  if ((p_frame->data_len[3] > 0) && (p_frame->p_data[3] != NULL))
3583  {
3584  niFrameSurface1_t *p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
3585  if ((p_surface->dma_buf_fd > 0) && (p_surface->ui16FrameIdx > 0))
3586  {
3587  // Close the DMA buf fd
3589  "%s: close p_surface->dma_buf_fd %d "
3590  "ui16FrameIdx %u\n",
3591  __func__, p_surface->dma_buf_fd, p_surface->ui16FrameIdx);
3592  close(p_surface->dma_buf_fd);
3593  }
3594  }
3595 #endif
3596 
3597  if (p_frame->buffer_size)
3598  {
3599  p_frame->buffer_size = 0;
3600  ni_aligned_free(p_frame->p_buffer);
3601  }
3602 
3603  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3604  {
3605  p_frame->data_len[i] = 0;
3606  p_frame->p_data[i] = NULL;
3607  }
3608 
3609  ni_frame_wipe_aux_data(p_frame);
3610 
3611  if (p_frame->metadata_buffer_size)
3612  {
3613  p_frame->metadata_buffer_size = 0;
3615  }
3616  p_frame->separate_metadata = 0;
3617 
3618  if (p_frame->start_buffer_size)
3619  {
3620  p_frame->start_buffer_size = 0;
3621  ni_aligned_free(p_frame->p_start_buffer);
3622  }
3623  p_frame->separate_start = 0;
3624  memset(p_frame->start_len, 0, sizeof(p_frame->start_len));
3625  p_frame->total_start_len = 0;
3626  p_frame->inconsecutive_transfer = 0;
3627 
3628 END:
3629 
3630  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3631 
3632  return retval;
3633 }
3634 
3635 /*!*****************************************************************************
3636  * \brief Free decoder frame buffer that was previously allocated with
3637  * ni_decoder_frame_buffer_alloc, returning memory to a buffer pool.
3638  *
3639  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3640  *
3641  * \return On success NI_RETCODE_SUCCESS
3642  * On failure NI_RETCODE_INVALID_PARAM
3643  ******************************************************************************/
3645 {
3646  int i;
3648 
3649  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3650 
3651  if (!p_frame)
3652  {
3653  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3654  retval = NI_RETCODE_INVALID_PARAM;
3655  LRETURN;
3656  }
3657 
3658  if (p_frame->dec_buf)
3659  {
3661  ni_log(NI_LOG_DEBUG, "%s(): Mem buf returned ptr %p buf %p !\n", __func__,
3662  p_frame->dec_buf->buf, p_frame->dec_buf);
3663  }
3664  else
3665  {
3666  ni_log(NI_LOG_DEBUG, "%s(): NO mem buf returned !\n", __func__);
3667  }
3668 
3669  p_frame->dec_buf = NULL;
3670  p_frame->p_buffer = NULL;
3671  p_frame->buffer_size = 0;
3672  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3673  {
3674  p_frame->data_len[i] = 0;
3675  p_frame->p_data[i] = NULL;
3676  }
3677  ni_frame_wipe_aux_data(p_frame);
3678 
3679 END:
3680 
3681  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3682 
3683  return retval;
3684 }
3685 
3686 /*!*****************************************************************************
3687  * \brief Return a memory buffer to memory buffer pool.
3688  *
3689  * \param[in] buf Buffer to be returned.
3690  * \param[in] p_buffer_pool Buffer pool to return buffer to.
3691  *
3692  * \return None
3693  ******************************************************************************/
3695  ni_buf_pool_t *p_buffer_pool)
3696 {
3697  ni_buf_pool_return_buffer(buf, p_buffer_pool);
3698 }
3699 
3700 /*!*****************************************************************************
3701  * \brief Allocate memory for the packet buffer based on provided packet size
3702  *
3703  * \param[in] p_packet Pointer to a caller allocated
3704  * ni_packet_t struct
3705  * \param[in] packet_size Required allocation size
3706  *
3707  * \return On success
3708  * NI_RETCODE_SUCCESS
3709  * On failure
3710  * NI_RETCODE_INVALID_PARAM
3711  * NI_RETCODE_ERROR_MEM_ALOC
3712  ******************************************************************************/
3714 {
3715  void* p_buffer = NULL;
3716  int metadata_size = 0;
3717 
3718  metadata_size = NI_FW_META_DATA_SZ;
3719 
3720  int buffer_size = (((packet_size + metadata_size) / NI_MAX_PACKET_SZ) + 1) * NI_MAX_PACKET_SZ;
3721 
3722  ni_log(NI_LOG_TRACE, "%s: packet_size=%d\n", __func__,
3723  packet_size + metadata_size);
3724 
3725  if (!p_packet || !packet_size)
3726  {
3727  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3728  __func__);
3729  return NI_RETCODE_INVALID_PARAM;
3730  }
3731 
3732  if (buffer_size % NI_MEM_PAGE_ALIGNMENT)
3733  {
3734  buffer_size = ( (buffer_size / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT ) + NI_MEM_PAGE_ALIGNMENT;
3735  }
3736 
3737  if (p_packet->buffer_size == buffer_size)
3738  {
3739  // Already allocated the exact size.
3740  p_packet->p_data = p_packet->p_buffer;
3741  ni_log(NI_LOG_DEBUG, "%s: reuse current p_packet buffer\n", __func__);
3742  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3743  p_packet->buffer_size);
3744  return NI_RETCODE_SUCCESS;
3745  }
3746 
3747  if (p_packet->buffer_size)
3748  {
3750  "%s: free current p_packet, p_packet->buffer_size=%u\n", __func__,
3751  p_packet->buffer_size);
3752  ni_packet_buffer_free(p_packet);
3753  }
3754 
3755  ni_log(NI_LOG_DEBUG, "%s: Allocating p_frame buffer, buffer_size=%d\n",
3756  __func__, buffer_size);
3757 
3758  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3759  {
3760  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
3761  NI_ERRNO, __func__);
3762  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3763  p_packet->buffer_size);
3765  }
3766 
3767  p_packet->buffer_size = buffer_size;
3768  p_packet->p_buffer = p_buffer;
3769  p_packet->p_data = p_packet->p_buffer;
3770 
3771  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3772  p_packet->buffer_size);
3773 
3774  return NI_RETCODE_SUCCESS;
3775 }
3776 
3777 /*!*****************************************************************************
3778  * \brief Allocate packet buffer using a user provided pointer, the memory
3779  * is expected to have already been allocated.
3780  *
3781  * For ideal performance memory should be 4k aligned. If it is not 4K aligned
3782  * then a temporary 4k aligned memory will be used to copy data to and from
3783  * when writing and reading. This will negatively impact performance.
3784  *
3785  * This API will overwrite p_packet->buffer_size, p_packet->p_buffer and
3786  * p_packet->p_data fields in p_packet.
3787  *
3788  * This API will not free any memory associated with p_packet->p_buffer and
3789  * p_packet->p_data fields in p_packet.
3790  * Common use case could be,
3791  * 1. Allocate memory to pointer
3792  * 2. Call ni_custom_packet_buffer_alloc() with allocated pointer.
3793  * 3. Use p_packet as required.
3794  * 4. Call ni_packet_buffer_free() to free up the memory.
3795  *
3796  * \param[in] p_buffer User provided pointer to be used for buffer
3797  * \param[in] p_packet Pointer to a caller allocated
3798  * ni_packet_t struct
3799  * \param[in] buffer_size Buffer size
3800  *
3801  * \return On success
3802  * NI_RETCODE_SUCCESS
3803  * On failure
3804  * NI_RETCODE_INVALID_PARAM
3805  * NI_RETCODE_ERROR_MEM_ALOC
3806  ******************************************************************************/
3808  ni_packet_t *p_packet,
3809  int buffer_size)
3810 {
3811  ni_log(NI_LOG_TRACE, "%s(): enter buffer_size=%d\n", __func__, buffer_size);
3812 
3813  if (!p_buffer || !p_packet || !buffer_size)
3814  {
3815  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3816  __func__);
3817  return NI_RETCODE_INVALID_PARAM;
3818  }
3819  if (((uintptr_t)p_buffer) % NI_MEM_PAGE_ALIGNMENT)
3820  {
3821  ni_log(NI_LOG_INFO, "Info: %s: Warning buffer not 4k aligned = %p!. Will do an extra copy\n",
3822  __func__, p_buffer);
3823  }
3824 
3825  p_packet->buffer_size = buffer_size;
3826  p_packet->p_buffer = p_buffer;
3827  p_packet->p_data = p_packet->p_buffer;
3828 
3829  ni_log(NI_LOG_TRACE, "%s: exit: \n", __func__);
3830 
3831  return NI_RETCODE_SUCCESS;
3832 }
3833 
3834 /*!*****************************************************************************
3835  * \brief Free packet buffer that was previously allocated with
3836  * ni_packet_buffer_alloc
3837  *
3838  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
3839  *
3840  * \return On success NI_RETCODE_SUCCESS
3841  * On failure NI_RETCODE_INVALID_PARAM
3842  ******************************************************************************/
3844 {
3846 
3847  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
3848 
3849  if (!p_packet)
3850  {
3851  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
3852  retval = NI_RETCODE_FAILURE;
3853  LRETURN;
3854  }
3855 
3856  if (!p_packet->p_buffer)
3857  {
3858  ni_log(NI_LOG_DEBUG, "%s(): already freed, nothing to free\n", __func__);
3859  LRETURN;
3860  }
3861 
3862  ni_aligned_free(p_packet->p_buffer);
3863  p_packet->p_buffer = NULL;
3864  p_packet->buffer_size = 0;
3865  p_packet->data_len = 0;
3866  p_packet->p_data = NULL;
3867 
3868  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
3869 
3870 END:
3871 
3872  return retval;
3873 }
3874 
3875 /*!*****************************************************************************
3876  * \brief Free packet buffer that was previously allocated with
3877  * ni_packet_buffer_alloc for AV1 packets merge
3878  *
3879  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
3880  *
3881  * \return On success NI_RETCODE_SUCCESS
3882  * On failure NI_RETCODE_INVALID_PARAM
3883  ******************************************************************************/
3885 {
3886  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
3888  int i;
3889 
3890  if (!p_packet)
3891  {
3892  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
3893  retval = NI_RETCODE_FAILURE;
3894  LRETURN;
3895  }
3896 
3897  if (!p_packet->av1_buffer_index)
3898  {
3900  "%s(): no need to free previous av1 packet buffers\n", __func__);
3901  LRETURN;
3902  }
3903 
3904  for (i = 0; i < p_packet->av1_buffer_index; i++)
3905  {
3906  ni_log(NI_LOG_DEBUG, "%s(): free previous av1 packet buffer %d\n",
3907  __func__, i);
3908  ni_aligned_free(p_packet->av1_p_buffer[i]);
3909  p_packet->av1_p_buffer[i] = NULL;
3910  p_packet->av1_p_data[i] = NULL;
3911  p_packet->av1_buffer_size[i] = 0;
3912  p_packet->av1_data_len[i] = 0;
3913  }
3914 
3915  p_packet->av1_buffer_index = 0;
3916 
3917 END:
3918 
3919  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
3920 
3921  return retval;
3922 }
3923 
3924 /*!*****************************************************************************
3925  * \brief Copy video packet accounting for alignment
3926  *
3927  * \param[in] p_destination Destination to where to copy to
3928  * \param[in] p_source Source from where to copy from
3929  * \param[in] cur_size current size
3930  * \param[out] p_leftover Pointer to the data that was left over
3931  * \param[out] p_prev_size Size of the data leftover ??
3932  *
3933  * \return On success Total number of bytes that were copied
3934  * On failure NI_RETCODE_FAILURE
3935  ******************************************************************************/
3936 int ni_packet_copy(void* p_destination, const void* const p_source, int cur_size, void* p_leftover, int* p_prev_size)
3937 {
3938  int copy_size = 0;
3939  int padding_size = 0;
3940  int prev_size = p_prev_size == NULL? 0 : *p_prev_size;
3941 
3942  int total_size = cur_size + prev_size;
3943  uint8_t* p_src = (uint8_t*)p_source;
3944  uint8_t* p_dst = (uint8_t*)p_destination;
3945  uint8_t* p_lftover = (uint8_t*)p_leftover;
3946 
3947  if (!p_prev_size)
3948  {
3949  return NI_RETCODE_INVALID_PARAM;
3950  }
3951 
3952  ni_log(NI_LOG_TRACE, "%s(): enter, *prev_size=%d\n", __func__, *p_prev_size);
3953 
3954  if ((0 == cur_size) && (0 == prev_size))
3955  {
3956  return copy_size;
3957  }
3958 
3959  if (((0 != cur_size) && (!p_source)) || (!p_destination) || (!p_leftover))
3960  {
3961  return NI_RETCODE_FAILURE;
3962  }
3963 
3964  copy_size = ((total_size + NI_MEM_PAGE_ALIGNMENT - 1) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT;
3965 
3966  if (copy_size > total_size)
3967  {
3968  padding_size = copy_size - total_size;
3969  }
3970 
3971  if (prev_size > 0)
3972  {
3973  memcpy(p_dst, p_lftover, prev_size);
3974  }
3975 
3976  p_dst += prev_size;
3977 
3978  memcpy(p_dst, p_src, cur_size);
3979 
3980  if (padding_size)
3981  {
3982  p_dst += cur_size;
3983  memset(p_dst, 0, padding_size);
3984  }
3985 
3987  "%s(): exit, cur_size=%d, copy_size=%d, "
3988  "prev_size=%d, padding_size=%d\n", __func__, cur_size,
3989  copy_size, *p_prev_size, padding_size);
3990 
3991  *p_prev_size = 0;
3992 
3993  return copy_size;
3994 }
3995 
3996 /*!*****************************************************************************
3997  * \brief Add a new auxiliary data to a frame
3998  *
3999  * \param[in/out] frame a frame to which the auxiliary data should be added
4000  * \param[in] type type of the added auxiliary data
4001  * \param[in] data_size size of the added auxiliary data
4002  *
4003  * \return a pointer to the newly added aux data on success, NULL otherwise
4004  ******************************************************************************/
4006  int data_size)
4007 {
4008  ni_aux_data_t *ret;
4009 
4011  !(ret = malloc(sizeof(ni_aux_data_t))))
4012  {
4014  "ERROR: %s No memory or exceeding max aux_data number !\n",
4015  __func__);
4016  return NULL;
4017  }
4018 
4019  ret->type = type;
4020  ret->size = data_size;
4021  ret->data = calloc(1, data_size);
4022  if (!ret->data)
4023  {
4024  ni_log(NI_LOG_ERROR, "ERROR: %s No memory for aux data !\n", __func__);
4025  free(ret);
4026  ret = NULL;
4027  } else
4028  {
4029  frame->aux_data[frame->nb_aux_data++] = ret;
4030  }
4031 
4032  return ret;
4033 }
4034 
4035 /*!*****************************************************************************
4036  * \brief Add a new auxiliary data to a frame and copy in the raw data
4037  *
4038  * \param[in/out] frame a frame to which the auxiliary data should be added
4039  * \param[in] type type of the added auxiliary data
4040  * \param[in] raw_data the raw data of the aux data
4041  * \param[in] data_size size of the added auxiliary data
4042  *
4043  * \return a pointer to the newly added aux data on success, NULL otherwise
4044  ******************************************************************************/
4046  ni_aux_data_type_t type,
4047  const uint8_t *raw_data,
4048  int data_size)
4049 {
4050  ni_aux_data_t *ret = ni_frame_new_aux_data(frame, type, data_size);
4051  if (ret)
4052  {
4053  memcpy(ret->data, raw_data, data_size);
4054  }
4055  return ret;
4056 }
4057 
4058 /*!*****************************************************************************
4059  * \brief Retrieve from the frame auxiliary data of a given type if exists
4060  *
4061  * \param[in] frame a frame from which the auxiliary data should be retrieved
4062  * \param[in] type type of the auxiliary data to be retrieved
4063  *
4064  * \return a pointer to the aux data of a given type on success, NULL otherwise
4065  ******************************************************************************/
4067  ni_aux_data_type_t type)
4068 {
4069  int i;
4070  for (i = 0; i < frame->nb_aux_data; i++)
4071  {
4072  if (frame->aux_data[i]->type == type)
4073  {
4074  return frame->aux_data[i];
4075  }
4076  }
4077  return NULL;
4078 }
4079 
4080 /*!*****************************************************************************
4081  * \brief If auxiliary data of the given type exists in the frame, free it
4082  * and remove it from the frame.
4083  *
4084  * \param[in/out] frame a frame from which the auxiliary data should be removed
4085  * \param[in] type type of the auxiliary data to be removed
4086  *
4087  * \return None
4088  ******************************************************************************/
4090 {
4091  int i;
4092  ni_aux_data_t *aux;
4093 
4094  for (i = 0; i < frame->nb_aux_data; i++)
4095  {
4096  aux = frame->aux_data[i];
4097  if (aux->type == type)
4098  {
4099  frame->aux_data[i] = frame->aux_data[frame->nb_aux_data - 1];
4100  frame->aux_data[frame->nb_aux_data - 1] = NULL;
4101  frame->nb_aux_data--;
4102  free(aux->data);
4103  free(aux);
4104  }
4105  }
4106 }
4107 
4108 /*!*****************************************************************************
4109  * \brief Free and remove all auxiliary data from the frame.
4110  *
4111  * \param[in/out] frame a frame from which the auxiliary data should be removed
4112  *
4113  * \return None
4114  ******************************************************************************/
4116 {
4117  int i;
4118  ni_aux_data_t *aux;
4119 
4120  for (i = 0; i < frame->nb_aux_data; i++)
4121  {
4122  aux = frame->aux_data[i];
4123  free(aux->data);
4124  free(aux);
4125  }
4126  frame->nb_aux_data = 0;
4127 }
4128 
4129 /*!*****************************************************************************
4130  * \brief Initialize default encoder parameters
4131  *
4132  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4133  * to initialize to default parameters
4134  * \param[in] fps_num Frames per second
4135  * \param[in] fps_denom FPS denomination
4136  * \param[in] bit_rate bit rate
4137  * \param[in] width frame width
4138  * \param[in] height frame height
4139  * \param[in] codec_format codec from ni_codec_format_t
4140  *
4141  * \return On success
4142  * NI_RETCODE_SUCCESS
4143  * On failure
4144  * NI_RETCODE_FAILURE
4145  * NI_RETCODE_INVALID_PARAM
4146  ******************************************************************************/
4148  int fps_num, int fps_denom,
4149  long bit_rate, int width,
4150  int height,
4151  ni_codec_format_t codec_format)
4152 {
4153  ni_encoder_cfg_params_t *p_enc = NULL;
4154  int i = 0, j = 0;
4156 
4157  //Initialize p_param structure
4158  if (!p_param)
4159  {
4160  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
4161  __func__);
4162  retval = NI_RETCODE_INVALID_PARAM;
4163  LRETURN;
4164  }
4165 
4166  ni_log(NI_LOG_DEBUG, "%s()\n", __func__);
4167 
4168  //Initialize p_param structure
4169  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4170 
4171  p_enc = &p_param->cfg_enc_params;
4172 
4173  // Rev. B: unified for HEVC/H.264
4174  p_enc->profile = 0;
4175  p_enc->level_idc = 0;
4176  p_enc->high_tier = 0;
4177 
4178  if (QUADRA)
4180  else
4182 
4183  p_enc->use_recommend_enc_params = 0;
4184  p_enc->cu_size_mode = 7;
4185  p_enc->max_num_merge = 2;
4186  p_enc->enable_dynamic_8x8_merge = 1;
4187  p_enc->enable_dynamic_16x16_merge = 1;
4188  p_enc->enable_dynamic_32x32_merge = 1;
4189 
4190  p_enc->rc.trans_rate = 0;
4191 
4192  p_enc->rc.enable_rate_control = 0;
4193  if (QUADRA)
4194  p_enc->rc.enable_cu_level_rate_control = 0;
4195  else
4196  p_enc->rc.enable_cu_level_rate_control = 1;
4197  p_enc->rc.enable_hvs_qp = 0;
4198  p_enc->rc.enable_hvs_qp_scale = 1;
4199  p_enc->rc.hvs_qp_scale = 2;
4200  p_enc->rc.min_qp = 8;
4201  p_enc->rc.max_qp = 51;
4202  p_enc->rc.max_delta_qp = 10;
4203 
4204  // hrd is disabled if vbv_buffer_size=0, hrd is enabled if vbv_buffer_size is [10, 3000]
4205  p_enc->rc.vbv_buffer_size = -1;
4206  p_enc->rc.enable_filler = 0;
4207  p_enc->rc.enable_pic_skip = 0;
4208  p_enc->rc.vbv_max_rate = 0;
4209 
4210  p_enc->roi_enable = 0;
4211 
4213  // feature not supported on JPEG/AV1 - disable by default
4214  if (codec_format == NI_CODEC_FORMAT_JPEG ||
4215  codec_format == NI_CODEC_FORMAT_AV1)
4216  {
4218  }
4219 
4220  p_enc->long_term_ref_enable = 0;
4221  p_enc->long_term_ref_interval = 0;
4222  p_enc->long_term_ref_count = 2;
4223 
4224  p_enc->conf_win_top = 0;
4225  p_enc->conf_win_bottom = 0;
4226  p_enc->conf_win_left = 0;
4227  p_enc->conf_win_right = 0;
4228 
4229  p_enc->intra_period = 120;
4230  p_enc->rc.intra_qp = 22;
4231  p_enc->rc.intra_qp_delta = -2;
4232  if (QUADRA)
4233  p_enc->rc.enable_mb_level_rc = 0;
4234  else
4235  p_enc->rc.enable_mb_level_rc = 1;
4236 
4237  p_enc->decoding_refresh_type = 1;
4238 
4239  p_enc->slice_mode = 0;
4240  p_enc->slice_arg = 0;
4241 
4242  // Rev. B: H.264 only parameters.
4243  p_enc->enable_transform_8x8 = 1;
4244  p_enc->entropy_coding_mode = 1;
4245 
4246  p_enc->intra_mb_refresh_mode = 0;
4247  p_enc->intra_mb_refresh_arg = 0;
4248  p_enc->intra_reset_refresh = 0;
4249 
4251 #ifndef QUADRA
4252  if (!QUADRA)
4253  {
4254  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4255  {
4257  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4258  p_enc->custom_gop_params.pic_param[i].pic_qp = 0;
4259  p_enc->custom_gop_params.pic_param[i].num_ref_pic_L0 = 0;
4260  p_enc->custom_gop_params.pic_param[i].ref_poc_L0 = 0;
4261  p_enc->custom_gop_params.pic_param[i].ref_poc_L1 = 0;
4262  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4263  }
4264  }
4265  else // QUADRA
4266 #endif
4267  {
4268  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4269  {
4270  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4271  p_enc->custom_gop_params.pic_param[i].qp_offset = 0;
4273  (float)0.3; // QP Factor range is between 0.3 and 1, higher values mean lower quality and less bits
4274  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4277  for (j = 0; j < NI_MAX_REF_PIC; j++)
4278  {
4279  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic = 0;
4280  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic_used = -1;
4281  }
4282  }
4283  }
4284 
4285  p_param->source_width = width;
4286  p_param->source_height = height;
4287 
4288  p_param->fps_number = fps_num;
4289  p_param->fps_denominator = fps_denom;
4290 
4291  if (p_param->fps_number && p_param->fps_denominator)
4292  {
4293  p_enc->frame_rate = (int)(p_param->fps_number / p_param->fps_denominator);
4294  }
4295  else
4296  {
4297  p_enc->frame_rate = 30;
4298  }
4299 
4300  p_param->bitrate = (int)bit_rate;
4301  p_param->roi_demo_mode = 0;
4302  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4303  p_param->force_pic_qp_demo_mode = 0;
4304  p_param->force_frame_type = 0;
4305  p_param->hdrEnableVUI = 0;
4306  p_param->cacheRoi = 0;
4307  p_param->low_delay_mode = 0;
4308  p_param->padding = 1;
4309  p_param->generate_enc_hdrs = 0;
4310  p_param->use_low_delay_poc_type = 0;
4311  p_param->rootBufId = 0;
4312  p_param->staticMmapThreshold = 0;
4313  p_param->zerocopy_mode = 1;
4314  p_param->luma_linesize = 0;
4315  p_param->chroma_linesize = 0;
4316 
4318 
4319  p_param->dolby_vision_profile = 0;
4320 
4321  // encoder stream header VUI setting
4322  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4323  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4324  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4325  p_param->sar_num = 0; // default SAR numerator 0
4326  p_param->sar_denom = 1; // default SAR denominator 1
4327  p_param->video_full_range_flag = -1;
4328 
4329  p_param->enable2PassGop = 0;
4331  p_param->minFramesDelay = 0;
4332  p_param->interval_of_psnr = 1;
4333  for (i = 0; i < NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL; i++) {
4334  for (j = 0; j < NI_CUSTOMIZE_ROI_QP_NUM; j++) {
4335  // 127 is invalid for delta qp and absolute qp
4336  p_param->customize_roi_qp_map[i][j] = 127;
4337  }
4338  }
4339 
4340  //QUADRA
4341  p_enc->EnableAUD = 0;
4342  p_enc->lookAheadDepth = 0;
4343  p_enc->rdoLevel = (codec_format == NI_CODEC_FORMAT_JPEG) ? 0 : 1;
4344  p_enc->crf = -1;
4345  p_enc->HDR10MaxLight = 0;
4346  p_enc->HDR10AveLight = 0;
4347  p_enc->HDR10CLLEnable = 0;
4348  p_enc->EnableRdoQuant = 0;
4349  p_enc->ctbRcMode = 0;
4350  p_enc->gopSize = 0;
4351  p_enc->gopLowdelay = 0;
4352  p_enc->gdrDuration = 0;
4353  p_enc->hrdEnable = 0;
4354  p_enc->ltrRefInterval = 0;
4355  p_enc->ltrRefQpOffset = 0;
4356  p_enc->ltrFirstGap = 0;
4357  p_enc->ltrNextInterval = 1;
4358  p_enc->multicoreJointMode = 0;
4359  p_enc->qlevel = -1;
4360  p_enc->maxFrameSize = 0;
4361  p_enc->maxFrameSizeRatio = 0;
4362  p_enc->chromaQpOffset = 0;
4363  p_enc->tolCtbRcInter = (float)0.1;
4364  p_enc->tolCtbRcIntra = (float)0.1;
4365  p_enc->bitrateWindow = -255;
4366  p_enc->inLoopDSRatio = 1;
4367  p_enc->blockRCSize = 0;
4368  p_enc->rcQpDeltaRange = 10;
4369  p_enc->ctbRowQpStep = 0;
4370  p_enc->newRcEnable = -1;
4371  p_enc->colorDescPresent = 0;
4372  p_enc->colorPrimaries = 2;
4373  p_enc->colorTrc = 2;
4374  p_enc->colorSpace = 2;
4375  p_enc->aspectRatioWidth = 0;
4376  p_enc->aspectRatioHeight = 1;
4377  p_enc->videoFullRange = 0;
4379  p_enc->enable_ssim = 0;
4380  p_enc->HDR10Enable = 0;
4381  p_enc->HDR10dx0 = 0;
4382  p_enc->HDR10dy0 = 0;
4383  p_enc->HDR10dx1 = 0;
4384  p_enc->HDR10dy1 = 0;
4385  p_enc->HDR10dx2 = 0;
4386  p_enc->HDR10dy2 = 0;
4387  p_enc->HDR10wx = 0;
4388  p_enc->HDR10wy = 0;
4389  p_enc->HDR10maxluma = 0;
4390  p_enc->HDR10minluma = 0;
4391  p_enc->avcc_hvcc = 0;
4392  p_enc->av1_error_resilient_mode = 0;
4393  p_enc->temporal_layers_enable = 0;
4394  p_enc->crop_width = 0;
4395  p_enc->crop_height = 0;
4396  p_enc->hor_offset = 0;
4397  p_enc->ver_offset = 0;
4398  p_enc->crfMax = -1;
4399  p_enc->qcomp = (float)0.6;
4400  p_enc->noMbtree = 0;
4401  p_enc->noHWMultiPassSupport = 0;
4402  p_enc->cuTreeFactor = 5;
4403  p_enc->ipRatio = (float)1.4;
4404  p_enc->pbRatio = (float)1.3;
4405  p_enc->cplxDecay = (float)0.5;
4406  p_enc->pps_init_qp = -1;
4407  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)
4408  p_enc->pass1_qp = -1;
4409  p_enc->crfFloat = -1.0f;
4410  p_enc->hvsBaseMbComplexity = 15;
4411  p_enc->statistic_output_level = 0;
4412  p_enc->skip_frame_enable = 0;
4413  p_enc->max_consecutive_skip_num = 1;
4414  p_enc->skip_frame_interval = 0;
4415  p_enc->enableipRatio = 0;
4416  p_enc->enable_all_sei_passthru = 0;
4417  p_enc->iframe_size_ratio = 100;
4418  p_enc->crf_max_iframe_enable = 0;
4419  p_enc->vbv_min_rate = 0;
4420 #ifdef XCODER_311
4421  p_enc->disable_adaptive_buffers = 1;
4422 #else
4423  p_enc->disable_adaptive_buffers = 0;
4424 #endif
4425  p_enc->disableBframeRdoq = 0;
4426  p_enc->forceBframeQpfactor = (float)-1.0;
4427  p_enc->tune_bframe_visual = 0;
4428  p_enc->enable_acq_limit = 0;
4429  p_enc->get_psnr_mode = 3;
4430  p_enc->customize_roi_qp_level = 0;
4431  p_enc->motionConstrainedMode = 0;
4432  p_enc->still_image_detect_level = 0;
4433  p_enc->scene_change_detect_level = 0;
4434  p_enc->encMallocStrategy = 0;
4435  p_enc->enable_smooth_crf = 0;
4436  p_enc->enable_compensate_qp = 0;
4437  p_enc->spatial_layers = 1;
4438  p_enc->enable_timecode = 0;
4439  p_enc->spatial_layers_ref_base_layer = 0;
4440  p_enc->vbvBufferReencode = 0;
4441 
4442  if (codec_format == NI_CODEC_FORMAT_AV1)
4443  {
4444  if (p_param->source_width < NI_PARAM_AV1_MIN_WIDTH)
4445  {
4447  LRETURN;
4448  }
4449  if (p_param->source_height < NI_PARAM_AV1_MIN_HEIGHT)
4450  {
4452  LRETURN;
4453  }
4454  if (p_param->source_width > NI_PARAM_AV1_MAX_WIDTH)
4455  {
4457  LRETURN;
4458  }
4459  if (p_param->source_height > NI_PARAM_AV1_MAX_HEIGHT)
4460  {
4462  LRETURN;
4463  }
4464  if (p_param->source_height * p_param->source_width >
4466  {
4468  LRETURN;
4469  }
4470  // AV1 8x8 alignment HW limitation is now worked around by FW cropping input resolution
4472  {
4473  ni_log(NI_LOG_ERROR, "AV1 Picture Width not aligned to %d - picture will be cropped\n",
4475  }
4477  {
4478  ni_log(NI_LOG_ERROR, "AV1 Picture Height not aligned to %d - picture will be cropped\n",
4480  }
4481  }
4482 
4483  if (codec_format == NI_CODEC_FORMAT_JPEG)
4484  {
4485  if (p_param->source_width < NI_PARAM_JPEG_MIN_WIDTH)
4486  {
4488  LRETURN;
4489  }
4490  if (p_param->source_height < NI_PARAM_JPEG_MIN_HEIGHT)
4491  {
4493  LRETURN;
4494  }
4495  }
4496 
4497  if (p_param->source_width > NI_PARAM_MAX_WIDTH)
4498  {
4500  LRETURN;
4501  }
4502  if (p_param->source_width < NI_PARAM_MIN_WIDTH)
4503  {
4505  LRETURN;
4506  }
4507 
4508  if (p_param->source_height > NI_PARAM_MAX_HEIGHT)
4509  {
4511  LRETURN;
4512  }
4513  if (p_param->source_height < NI_PARAM_MIN_HEIGHT)
4514  {
4516  LRETURN;
4517  }
4518  if (p_param->source_height*p_param->source_width > NI_MAX_RESOLUTION_AREA)
4519  {
4521  LRETURN;
4522  }
4523 
4524 END:
4525 
4526  return retval;
4527 }
4528 
4529 /*!*****************************************************************************
4530  * \brief Initialize default decoder parameters
4531  *
4532  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4533  * to initialize to default parameters
4534  * \param[in] fps_num Frames per second
4535  * \param[in] fps_denom FPS denomination
4536  * \param[in] bit_rate bit rate
4537  * \param[in] width frame width
4538  * \param[in] height frame height
4539  *
4540  * \return On success
4541  * NI_RETCODE_SUCCESS
4542  * On failure
4543  * NI_RETCODE_FAILURE
4544  * NI_RETCODE_INVALID_PARAM
4545  ******************************************************************************/
4547  int fps_num, int fps_denom,
4548  long bit_rate, int width,
4549  int height)
4550 {
4551  ni_decoder_input_params_t* p_dec = NULL;
4552  int i;
4554 
4555  //Initialize p_param structure
4556  if (!p_param)
4557  {
4558  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameter passed\n",
4559  __func__);
4560  retval = NI_RETCODE_INVALID_PARAM;
4561  LRETURN;
4562  }
4563 
4564  ni_log(NI_LOG_DEBUG, "%s\n", __func__);
4565 
4566  //Initialize p_param structure
4567  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4568 
4569  p_dec = &p_param->dec_input_params;
4570 
4571  p_param->source_width = width;
4572  p_param->source_height = height;
4573 
4574  if(fps_num <= 0 || fps_denom <= 0)
4575  {
4576  fps_num = 30;
4577  fps_denom = 1;
4578  ni_log(NI_LOG_INFO, "%s(): FPS is not set, setting the default FPS to 30\n", __func__);
4579  }
4580 
4581  p_param->fps_number = fps_num;
4582  p_param->fps_denominator = fps_denom;
4583 
4584  p_dec->hwframes = 0;
4585  p_dec->mcmode = 0;
4586  p_dec->nb_save_pkt = 0;
4587  p_dec->enable_out1 = 0;
4588  p_dec->enable_out2 = 0;
4589  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
4590  {
4591  p_dec->force_8_bit[i] = 0;
4592  p_dec->semi_planar[i] = 0;
4593  p_dec->crop_mode[i] = NI_DEC_CROP_MODE_AUTO;
4594  p_dec->crop_whxy[i][0] = width;
4595  p_dec->crop_whxy[i][1] = height;
4596  p_dec->crop_whxy[i][2] = 0;
4597  p_dec->crop_whxy[i][3] = 0;
4598  p_dec->scale_wh[i][0] = 0;
4599  p_dec->scale_wh[i][1] = 0;
4600  p_dec->scale_long_short_edge[i] = 0;
4601  p_dec->scale_resolution_ceil[i] = 2;
4602  p_dec->scale_round[i] = -1;
4603  }
4605  p_dec->decoder_low_delay = 0;
4606  p_dec->force_low_delay = false;
4607  p_dec->enable_low_delay_check = 0;
4608  p_dec->enable_user_data_sei_passthru = 0;
4609  p_dec->custom_sei_passthru = -1;
4612  p_dec->enable_advanced_ec = 1;
4614  p_dec->enable_ppu_scale_adapt = 0;
4615  p_dec->enable_ppu_scale_limit = 0;
4616  p_dec->max_extra_hwframe_cnt = 255; //uint8_max
4617  p_dec->pkt_pts_unchange = 0;
4618  p_dec->enable_all_sei_passthru = 0;
4619  p_dec->enable_follow_iframe = 0;
4621 #ifdef XCODER_311
4622  p_dec->disable_adaptive_buffers = 1;
4623  p_dec->min_packets_delay = true;
4624  p_dec->reduce_dpb_delay = 1;
4625 #else
4626  p_dec->disable_adaptive_buffers = 0;
4627  p_dec->min_packets_delay = false;
4628  p_dec->reduce_dpb_delay = 0;
4629 #endif
4630  p_dec->survive_stream_err = 0;
4631  p_dec->skip_extra_headers = 0;
4632 
4633  //-------init unused param start----------
4634 
4635  p_param->bitrate = (int)bit_rate;
4636  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4637  p_param->force_pic_qp_demo_mode = 0;
4638  p_param->force_frame_type = 0;
4639  p_param->hdrEnableVUI = 0;
4640  p_param->cacheRoi = 0;
4641  p_param->low_delay_mode = 0;
4642  p_param->padding = 1;
4643  p_param->generate_enc_hdrs = 0;
4644  p_param->use_low_delay_poc_type = 0;
4645  p_param->dolby_vision_profile = 0;
4646 
4647  // encoder stream header VUI setting
4648  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4649  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4650  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4651  p_param->sar_num = 0; // default SAR numerator 0
4652  p_param->sar_denom = 1; // default SAR denominator 1
4653  p_param->video_full_range_flag = -1;
4654 
4655  //-------init unused param done----------
4656 
4657 END:
4658 
4659  return retval;
4660 }
4661 
4662 // read demo reconfig data file and parse out reconfig key/values in the format:
4663 // key:val1,val2,val3,...val9 (max 9 values); only digit/:/,/newline is allowed
4664 ni_retcode_t ni_parse_reconf_file(const char *reconf_file,
4666 {
4667  char keyChar[10] = "";
4668  int key;
4669  char valChar[10] = "";
4670  int val;
4671  int valIdx = 1;
4672  int parseKey = 1;
4673  int idx = 0;
4674  int readc = EOF;
4675  FILE *reconf = NULL;
4676 
4677  if (!reconf_file)
4678  {
4679  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4680  __func__);
4681  return NI_RETCODE_INVALID_PARAM;
4682  }
4683 
4684  reconf = fopen(reconf_file, "r");
4685  if (!reconf)
4686  {
4687  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4688  NI_ERRNO, __func__, reconf_file);
4690  }
4692 
4693  while ((readc = fgetc(reconf)) != EOF)
4694  {
4695  //parse lines
4696  if (isdigit(readc))
4697  {
4698  if (parseKey)
4699  {
4700  strncat(keyChar, (const char *)(&readc), 1);
4701  }
4702  else
4703  {
4704  strncat(valChar, (const char *)(&readc), 1);
4705  }
4706  }
4707  else if (readc == ':')
4708  {
4709  parseKey = 0;
4710  key = atoi(keyChar);
4711  hash_map[idx][0] = key;
4712  }
4713  else if (readc == ',')
4714  {
4716  {
4718  "ERROR: Number of entries per line in reconfig file is greater then the "
4719  "limit of %d\n",
4721  retval = NI_RETCODE_INVALID_PARAM;
4722  break;
4723  }
4724  val = atoi(valChar);
4725  hash_map[idx][valIdx] = val;
4726  valIdx++;
4727  memset(valChar, 0, 10);
4728  }
4729  else if (readc == '\n')
4730  {
4732  {
4734  "ERROR: Number of lines in reconfig file is greater then the "
4735  "limit of %d\n",
4737  retval = NI_RETCODE_INVALID_PARAM;
4738  break;
4739  }
4740  parseKey = 1;
4741  val = atoi (valChar);
4742  hash_map[idx][valIdx] = val;
4743  valIdx = 1;
4744  memset(keyChar,0,10);
4745  memset(valChar,0,10);
4746  idx ++;
4747  }
4748  else
4749  {
4750  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4751  }
4752  }
4753 
4754  fclose(reconf);
4755 
4756  if (NI_RETCODE_SUCCESS == retval && parseKey != 1)
4757  {
4759  "ERROR %d: %s(): Incorrect format / "
4760  "incomplete Key/Value pair in reconfig_file: %s\n",
4761  NI_ERRNO, __func__, reconf_file);
4763  }
4764 
4765  return retval;
4766 }
4767 
4769  int8_t qp_map[][NI_CUSTOMIZE_ROI_QP_NUM])
4770 {
4771  char valChar[5] = "";
4772  int val;
4773  int negative = 0;
4774  int qpIdx = 0;
4775  int levelIdx = 0;
4776  int readc = EOF;
4777  FILE *reconf = NULL;
4778 
4779  if (!customize_file)
4780  {
4781  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4782  __func__);
4783  return NI_RETCODE_INVALID_PARAM;
4784  }
4785 
4786  reconf = fopen(customize_file, "r");
4787  if (!reconf)
4788  {
4789  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4790  NI_ERRNO, __func__, customize_file);
4792  }
4794 
4795  while ((readc = fgetc(reconf)) != EOF)
4796  {
4797  //parse lines
4798  if (isdigit(readc))
4799  {
4800  strncat(valChar, (const char *)(&readc), 1);
4801  }
4802  else if (readc == '-') {
4803  negative = 1;
4804  }
4805  else if (readc == ',')
4806  {
4807  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4808  {
4810  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4811  "Number of levelIdx %d greater then the limit of %d\n",
4813  retval = NI_RETCODE_INVALID_PARAM;
4814  break;
4815  }
4816  if (!negative) {
4817  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
4818  qp_map[levelIdx][qpIdx] = val;
4819  } else {
4820  val = clip3(0, 32, atoi(valChar));
4821  qp_map[levelIdx][qpIdx] = val * -1;
4822  }
4823  negative = 0;
4824  memset(valChar, 0, 5);
4825  qpIdx++;
4826  }
4827  else if (readc == '\n')
4828  {
4829  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4830  {
4832  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4833  "Number of levelIdx %d greater then the limit of %d\n",
4835  retval = NI_RETCODE_INVALID_PARAM;
4836  break;
4837  }
4838  if (!negative) {
4839  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
4840  qp_map[levelIdx][qpIdx] = val;
4841  } else {
4842  val = clip3(0, 32, atoi(valChar));
4843  qp_map[levelIdx][qpIdx] = val * -1;
4844  }
4845  negative = 0;
4846  memset(valChar, 0, 5);
4847  qpIdx = 0;
4848  levelIdx++;
4849  }
4850  else
4851  {
4852  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4853  }
4854  }
4855  fclose(reconf);
4856 
4857  return retval;
4858 }
4859 
4860 
4861 #undef atoi
4862 #undef atof
4863 #define atoi(p_str) ni_atoi(p_str, &b_error)
4864 #define atof(p_str) ni_atof(p_str, &b_error)
4865 #define atobool(p_str) (ni_atobool(p_str, &b_error))
4866 /*!*****************************************************************************
4867 * \brief Set value referenced by name in decoder parameters structure
4868 *
4869 * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t (used
4870 * for decoder too for now ) to find and set a particular
4871 * parameter
4872 * \param[in] name String represented parameter name to search
4873 * \param[in] value Parameter value to set
4874 *
4875 * \return On success
4876 * NI_RETCODE_SUCCESS
4877 * On failure
4878 * NI_RETCODE_FAILURE
4879 * NI_RETCODE_INVALID_PARAM
4880 *******************************************************************************/
4882  const char *name, char *value)
4883 {
4884  bool b_error = false;
4885  bool bNameWasBool = false;
4886  bool bValueWasNull = !value;
4887  ni_decoder_input_params_t* p_dec = NULL;
4888  char nameBuf[64] = { 0 };
4889  const char delim[2] = ",";
4890  const char xdelim[2] = "x";
4891  char *chunk;//for parsing out multi param input
4892  int i, j, k;
4893 
4894  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
4895 
4896  if (!p_params)
4897  {
4898  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4899  __func__);
4900  return NI_RETCODE_INVALID_PARAM;
4901  }
4902 
4903  if (!name)
4904  {
4905  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
4906  __func__);
4908  }
4909  p_dec = &p_params->dec_input_params;
4910 
4911  // skip -- prefix if provided
4912  if (name[0] == '-' && name[1] == '-')
4913  {
4914  name += 2;
4915  }
4916 
4917  // s/_/-/g
4918  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
4919  {
4920  char* c;
4921  strcpy(nameBuf, name);
4922  while ((c = strchr(nameBuf, '_')) != 0)
4923  {
4924  *c = '-';
4925  }
4926  name = nameBuf;
4927  }
4928 
4929  if (!value)
4930  {
4931  value = "true";
4932  }
4933  else if (value[0] == '=')
4934  {
4935  value++;
4936  }
4937 
4938 #if defined(_MSC_VER)
4939 #define OPT(STR) else if (!_stricmp(name, STR))
4940 #define OPT2(STR1, STR2) \
4941  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
4942 #else
4943 #define OPT(STR) else if (!strcasecmp(name, STR))
4944 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
4945 #endif
4946  if (0); // suppress cppcheck
4948  {
4949  if (!strncmp(value, "hw", sizeof("hw"))){
4950  p_dec->hwframes = 1;
4951  }
4952  else if (!strncmp(value, "sw", sizeof("sw"))) {
4953  p_dec->hwframes = 0;
4954  }
4955  else{
4956  ni_log(NI_LOG_ERROR, "ERROR: %s(): out can only be <hw,sw> got %s\n",
4957  __func__, value);
4959  }
4960  }
4962  {
4963  if (atoi(value) == 1)
4964  p_dec->enable_out1 = 1;
4965  }
4967  {
4968  if (atoi(value) == 1)
4969  p_dec->enable_out2 = 1;
4970  }
4972  {
4973  if (atoi(value) == 1)
4974  p_dec->force_8_bit[0] = 1;
4975  }
4977  {
4978  if (atoi(value) == 1)
4979  p_dec->force_8_bit[1] = 1;
4980  }
4982  {
4983  if (atoi(value) == 1)
4984  p_dec->force_8_bit[2] = 1;
4985  }
4987  {
4988  if (atoi(value) == 1 || atoi(value) == 2)
4989  p_dec->semi_planar[0] = atoi(value);
4990  }
4992  {
4993  if (atoi(value) == 1 || atoi(value) == 2)
4994  p_dec->semi_planar[1] = atoi(value);
4995  }
4997  {
4998  if (atoi(value) == 1 || atoi(value) == 2)
4999  p_dec->semi_planar[2] = atoi(value);
5000  }
5002  {
5003  if (!strncmp(value, "manual", sizeof("manual"))) {
5004  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_MANUAL;
5005  }
5006  else if (!strncmp(value, "auto", sizeof("auto"))) {
5007  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_AUTO;
5008  }
5009  else{
5011  "ERROR: %s():cropMode0 input can only be <manual,auto> got %s\n",
5012  __func__, value);
5014  }
5015  }
5017  {
5018  if (!strncmp(value, "manual", sizeof("manual"))) {
5019  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_MANUAL;
5020  }
5021  else if (!strncmp(value, "auto", sizeof("auto"))) {
5022  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_AUTO;
5023  }
5024  else {
5026  "ERROR: %s():cropMode1 input can only be <manual,auto> got %s\n",
5027  __func__, value);
5029  }
5030  }
5032  {
5033  if (!strncmp(value, "manual", sizeof("manual"))) {
5034  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_MANUAL;
5035  }
5036  else if (!strncmp(value, "auto", sizeof("auto"))) {
5037  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_AUTO;
5038  }
5039  else {
5041  "ERROR: %s():cropMode2 input can only be <manual,auto> got %s\n",
5042  __func__, value);
5044  }
5045  }
5047  {
5048  char *saveptr = NULL;
5049  chunk = ni_strtok(value, delim, &saveptr);
5050  for (i = 0; i < 4; i++)
5051  {
5052  if (chunk != NULL)
5053  {
5054  j = k = 0;
5055  while (chunk[j])
5056  {
5057  if (chunk[j] != '\"' && chunk[j] != '\'')
5058  {
5059  p_dec->cr_expr[0][i][k] = chunk[j];
5060  k++;
5061  }
5062  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5063  {
5065  }
5066  }
5067  chunk = ni_strtok(NULL, delim, &saveptr);
5068  }
5069  else if (i == 2 ) //default offsets to centered image if not specified, may need recalc
5070  {
5071  strcpy(p_dec->cr_expr[0][i], "in_w/2-out_w/2");
5072  }
5073  else if (i == 3)
5074  {
5075  strcpy(p_dec->cr_expr[0][i], "in_h/2-out_h/2");
5076  } else
5077  {
5079  }
5080  }
5081  }
5083  {
5084  char *saveptr = NULL;
5085  chunk = ni_strtok(value, delim, &saveptr);
5086  for (i = 0; i < 4; i++)
5087  {
5088  if (chunk != NULL)
5089  {
5090  j = k = 0;
5091  while (chunk[j])
5092  {
5093  if (chunk[j] != '\"' && chunk[j] != '\'')
5094  {
5095  p_dec->cr_expr[1][i][k] = chunk[j];
5096  k++;
5097  }
5098  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5099  {
5101  }
5102  }
5103  chunk = ni_strtok(NULL, delim, &saveptr);
5104  }
5105  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5106  {
5107 
5108  strcpy(p_dec->cr_expr[1][i], "in_w/2-out_w/2");
5109  }
5110  else if (i == 3)
5111  {
5112  strcpy(p_dec->cr_expr[1][i], "in_h/2-out_h/2");
5113  }
5114  else
5115  {
5117  }
5118  }
5119  }
5121  {
5122  char *saveptr = NULL;
5123  chunk = ni_strtok(value, delim, &saveptr);
5124  for (i = 0; i < 4; i++)
5125  {
5126  if (chunk != NULL)
5127  {
5128  j = k = 0;
5129  while (chunk[j])
5130  {
5131  if (chunk[j] != '\"' && chunk[j] != '\'')
5132  {
5133  p_dec->cr_expr[2][i][k] = chunk[j];
5134  k++;
5135  }
5136  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5137  {
5139  }
5140  }
5141  chunk = ni_strtok(NULL, delim, &saveptr);
5142  }
5143  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5144  {
5145 
5146  strcpy(p_dec->cr_expr[2][i], "in_w/2-out_w/2");
5147  }
5148  else if (i == 3)
5149  {
5150  strcpy(p_dec->cr_expr[2][i], "in_h/2-out_h/2");
5151  }
5152  else
5153  {
5155  }
5156  }
5157  }
5159  {
5160  chunk = value;
5161  i = 0; // 'x' character counter
5162  while (*chunk++) {
5163  if (*chunk == xdelim[0]) {
5164  i++;
5165  }
5166  }
5167  if (i != 1) {
5169  }
5170  chunk = NULL;
5171 
5172  char *saveptr = NULL;
5173  chunk = ni_strtok(value, xdelim, &saveptr);
5174  for (i = 0; i < 2; i++)
5175  {
5176  if (chunk != NULL)
5177  {
5178  j = k = 0;
5179  while (chunk[j])
5180  {
5181  if (chunk[j] != '\"' && chunk[j] != '\'')
5182  {
5183  p_dec->sc_expr[0][i][k] = chunk[j];
5184  k++;
5185  }
5186  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5187  {
5189  }
5190  }
5191  chunk = ni_strtok(NULL, xdelim, &saveptr);
5192  }
5193  else
5194  {
5196  }
5197  }
5198  }
5200  {
5201  chunk = value;
5202  i = 0; // 'x' character counter
5203  while (*chunk++) {
5204  if (*chunk == xdelim[0]) {
5205  i++;
5206  }
5207  }
5208  if (i != 1) {
5210  }
5211  chunk = NULL;
5212 
5213  char *saveptr = NULL;
5214  chunk = ni_strtok(value, xdelim, &saveptr);
5215  for (i = 0; i < 2; i++)
5216  {
5217  if (chunk != NULL)
5218  {
5219  j = k = 0;
5220  while (chunk[j])
5221  {
5222  if (chunk[j] != '\"' && chunk[j] != '\'')
5223  {
5224  p_dec->sc_expr[1][i][k] = chunk[j];
5225  k++;
5226  }
5227  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5228  {
5230  }
5231  }
5232  chunk = ni_strtok(NULL, xdelim, &saveptr);
5233  }
5234  else
5235  {
5237  }
5238  }
5239  }
5241  {
5242  chunk = value;
5243  i = 0; // 'x' character counter
5244  while (*chunk++) {
5245  if (*chunk == xdelim[0]) {
5246  i++;
5247  }
5248  }
5249  if (i != 1) {
5251  }
5252  chunk = NULL;
5253 
5254  char *saveptr = NULL;
5255  chunk = ni_strtok(value, xdelim, &saveptr);
5256  for (i = 0; i < 2; i++)
5257  {
5258  if (chunk != NULL)
5259  {
5260  j = k = 0;
5261  while (chunk[j])
5262  {
5263  if (chunk[j] != '\"' && chunk[j] != '\'')
5264  {
5265  p_dec->sc_expr[2][i][k] = chunk[j];
5266  k++;
5267  }
5268  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5269  {
5271  }
5272  }
5273  chunk = ni_strtok(NULL, xdelim, &saveptr);
5274  }
5275  else
5276  {
5278  }
5279  }
5280  }
5282  {
5283  if ((atoi(value) < 0) || (atoi(value) > 2))
5284  {
5286  }
5287  p_dec->scale_long_short_edge[0] = atoi(value);
5288  }
5290  {
5291  if ((atoi(value) < 0) || (atoi(value) > 2))
5292  {
5294  }
5295  p_dec->scale_long_short_edge[1] = atoi(value);
5296  }
5298  {
5299  if ((atoi(value) < 0) || (atoi(value) > 2))
5300  {
5302  }
5303  p_dec->scale_long_short_edge[2] = atoi(value);
5304  }
5306  {
5307  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5308  {
5309  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5310  "and must be even number and less than or equal to 128. Got: %s\n",
5311  __func__, NI_DEC_PARAM_SCALE_0_RES_CEIL, value);
5312 
5314  }
5315  p_dec->scale_resolution_ceil[0] = atoi(value);
5316  }
5318  {
5319  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5320  {
5321  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5322  "and must be even number and less than or equal to 128. Got: %s\n",
5323  __func__, NI_DEC_PARAM_SCALE_1_RES_CEIL, value);
5325  }
5326  p_dec->scale_resolution_ceil[1] = atoi(value);
5327  }
5329  {
5330  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5331  {
5332  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5333  "and must be even number and less than or equal to 128. Got: %s\n",
5334  __func__, NI_DEC_PARAM_SCALE_2_RES_CEIL, value);
5336  }
5337  p_dec->scale_resolution_ceil[2] = atoi(value);
5338  }
5340  {
5341  if (!strncmp(value, "up", sizeof("up"))){
5342  p_dec->scale_round[0] = 0;
5343  }
5344  else if (!strncmp(value, "down", sizeof("down"))) {
5345  p_dec->scale_round[0] = 1;
5346  }
5347  else{
5348  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5349  __func__, NI_DEC_PARAM_SCALE_0_ROUND, value);
5351  }
5352  }
5354  {
5355  if (!strncmp(value, "up", sizeof("up"))){
5356  p_dec->scale_round[1] = 0;
5357  }
5358  else if (!strncmp(value, "down", sizeof("down"))) {
5359  p_dec->scale_round[1] = 1;
5360  }
5361  else{
5362  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5363  __func__, NI_DEC_PARAM_SCALE_1_ROUND, value);
5365  }
5366  }
5368  {
5369  if (!strncmp(value, "up", sizeof("up"))){
5370  p_dec->scale_round[2] = 0;
5371  }
5372  else if (!strncmp(value, "down", sizeof("down"))) {
5373  p_dec->scale_round[2] = 1;
5374  }
5375  else{
5376  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5377  __func__, NI_DEC_PARAM_SCALE_2_ROUND, value);
5379  }
5380  }
5382  {
5383  if ((atoi(value) != 0) && (atoi(value) != 1))
5384  {
5386  }
5387  p_dec->mcmode = atoi(value);
5388  }
5390  {
5391  if (atoi(value) < 0)
5392  {
5394  }
5395  p_dec->nb_save_pkt = atoi(value);
5396  }
5398  {
5399  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
5400  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
5401  {
5403  }
5404  p_dec->keep_alive_timeout = atoi(value);
5405  }
5407  {
5408  if (atoi(value) < 0)
5409  {
5411  }
5412  p_dec->decoder_low_delay = atoi(value);
5413  }
5415  {
5416  if ((atoi(value) != 0) && (atoi(value) != 1))
5417  {
5419  }
5420  p_dec->force_low_delay = atoi(value);
5421  }
5423  {
5424  if (atoi(value) < 0)
5425  {
5427  }
5428  p_dec->enable_low_delay_check = atoi(value);
5429  }
5431  {
5432  if ((atoi(value) != 0) && (atoi(value) != 1))
5433  {
5435  }
5436  p_dec->min_packets_delay = atoi(value);
5437  }
5439  {
5440  if (atoi(value) != NI_ENABLE_USR_DATA_SEI_PASSTHRU &&
5442  {
5444  }
5445  p_dec->enable_user_data_sei_passthru = atoi(value);
5446  }
5448  {
5449  if (atoi(value) < NI_MIN_CUSTOM_SEI_PASSTHRU ||
5451  {
5453  }
5454  p_dec->custom_sei_passthru = atoi(value);
5455  }
5457  {
5458  if (atoi(value) < NI_INVALID_SVCT_DECODING_LAYER)
5459  {
5461  }
5462  p_dec->svct_decoding_layer = atoi(value);
5463  }
5465  {
5466  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
5467  atoi(value) <= NI_DDR_PRIORITY_NONE)
5468  {
5470  }
5471  p_params->ddr_priority_mode = atoi(value);
5472  }
5474  {
5475  if (strncmp(value, "tolerant", sizeof("tolerant")) == 0) {
5477  } else if (strncmp(value, "ignore", sizeof("ignore")) == 0) {
5478  p_dec->ec_policy = NI_EC_POLICY_IGNORE;
5479  } else if (strncmp(value, "skip", sizeof("skip")) == 0) {
5480  p_dec->ec_policy = NI_EC_POLICY_SKIP;
5481  } else if (strncmp(value, "best_effort", sizeof("best_effort")) == 0) {
5483  } else if (strncmp(value, "limited_error", sizeof("limited_error")) == 0) {
5485  } else if (strncmp(value, "best_effort_out_dc", sizeof("best_effort_out_dc")) == 0) {
5487  } else {
5489  }
5490  }
5492  {
5493  if (atoi(value) != 0 &&
5494  atoi(value) != 1 &&
5495  atoi(value) != 2)
5496  {
5498  }
5499  p_dec->enable_advanced_ec = atoi(value);
5500  }
5502  {
5503  if (atoi(value) < 0 || (atoi(value) > 100))
5504  {
5506  }
5507  p_dec->error_ratio_threshold = atoi(value);
5508  }
5510  {
5511  if (atoi(value) < 0 || (atoi(value) > 2))
5512  {
5514  }
5515  p_dec->enable_ppu_scale_adapt = atoi(value);
5516  }
5518  {
5519  if (atoi(value) < 0 || (atoi(value) > 1))
5520  {
5522  }
5523  p_dec->enable_ppu_scale_limit = atoi(value);
5524  }
5526  {
5527  if (atoi(value) < 0 || atoi(value) > 255)
5528  {
5530  }
5531  p_dec->max_extra_hwframe_cnt = atoi(value);
5532  }
5534  {
5535  if (atoi(value) < 0 || atoi(value) > 1)
5536  {
5538  }
5539  p_dec->skip_pts_guess = atoi(value);
5540  }
5542  {
5543  if (atoi(value) != 0 && atoi(value) != 1)
5544  {
5546  }
5547  p_dec->pkt_pts_unchange = atoi(value);
5548  }
5550  {
5551  if (atoi(value) < 0 ||
5552  atoi(value) > 1)
5553  {
5555  }
5556  p_dec->enable_all_sei_passthru = atoi(value);
5557  }
5559  {
5560  if (atoi(value) != 0 && atoi(value) != 1)
5561  {
5563  }
5564  p_dec->enable_follow_iframe = atoi(value);
5565  }
5567  {
5568  if (atoi(value) < 0 ||
5569  atoi(value) > 1)
5570  {
5572  }
5573  p_dec->disable_adaptive_buffers = atoi(value);
5574  }
5576  {
5577  if (atoi(value) < 0 || atoi(value) > 1)
5578  {
5580  }
5581  p_dec->survive_stream_err = atoi(value);
5582  }
5584  {
5585  if ((atoi(value) != 0) && (atoi(value) != 1))
5586  {
5588  }
5589  p_dec->reduce_dpb_delay = atoi(value);
5590  }
5592  {
5593  if ((atoi(value) != 0) && (atoi(value) != 1))
5594  {
5596  }
5597  p_dec->skip_extra_headers = atoi(value);
5598  }
5599  else
5600  {
5602  }
5603 
5604 #undef OPT
5605 #undef atobool
5606 #undef atoi
5607 #undef atof
5608  b_error |= bValueWasNull && !bNameWasBool;
5609 
5610  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
5611 
5613 }
5614 
5615 #undef atoi
5616 #undef atof
5617 #define atoi(p_str) ni_atoi(p_str, &b_error)
5618 #define atof(p_str) ni_atof(p_str, &b_error)
5619 #define atobool(p_str) (ni_atobool(p_str, &b_error))
5620 
5621 /*!*****************************************************************************
5622  * \brief Set value referenced by name in encoder parameters structure
5623  *
5624  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
5625  * to find and set a particular parameter
5626  * \param[in] name String represented parameter name to search
5627  * \param[in] value Parameter value to set
5628 *
5629  * \return On success
5630  * NI_RETCODE_SUCCESS
5631  * On failure
5632  * NI_RETCODE_FAILURE
5633  * NI_RETCODE_INVALID_PARAM
5634  ******************************************************************************/
5636  const char *name, const char *value)
5637 {
5638  bool b_error = false;
5639  bool bNameWasBool = false;
5640  bool bValueWasNull = !value;
5641  ni_encoder_cfg_params_t *p_enc = NULL;
5642  char nameBuf[64] = { 0 };
5643  int i,j,k;
5644 
5645  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
5646 
5647  if (!p_params)
5648  {
5649  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
5650  __func__);
5651  return NI_RETCODE_INVALID_PARAM;
5652  }
5653 
5654  if ( !name )
5655  {
5656  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
5657  __func__);
5659  }
5660  p_enc = &p_params->cfg_enc_params;
5661  // skip -- prefix if provided
5662  if (name[0] == '-' && name[1] == '-')
5663  {
5664  name += 2;
5665  }
5666 
5667  // s/_/-/g
5668  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
5669  {
5670  char* c;
5671  strcpy(nameBuf, name);
5672  while ((c = strchr(nameBuf, '_')) != 0)
5673  {
5674  *c = '-';
5675  }
5676  name = nameBuf;
5677  }
5678 
5679  if (!value)
5680  {
5681  value = "true";
5682  }
5683  else if (value[0] == '=')
5684  {
5685  value++;
5686  }
5687 
5688 #if defined(_MSC_VER)
5689 #define OPT(STR) else if (!_stricmp(name, STR))
5690 #define OPT2(STR1, STR2) \
5691  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
5692 #else
5693 #define OPT(STR) else if (!strcasecmp(name, STR))
5694 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
5695 #endif
5696 #define COMPARE(STR1, STR2, STR3) \
5697  if ((atoi(STR1) > (STR2)) || (atoi(STR1) < (STR3))) \
5698  { \
5699  return NI_RETCODE_PARAM_ERROR_OOR; \
5700  }
5701  if (0); // suppress cppcheck
5703  {
5704  if (AV_CODEC_DEFAULT_BITRATE == p_params->bitrate)
5705  {
5706  if (atoi(value) > NI_MAX_BITRATE)
5707  {
5709  }
5710  if (atoi(value) < NI_MIN_BITRATE)
5711  {
5713  }
5714  p_params->bitrate = atoi(value);
5715  }
5716  }
5718  {
5719  p_params->reconf_demo_mode = atoi(value); // for encoder reconfiguration testing
5720  }
5722  {
5723  ni_retcode_t retval = ni_parse_reconf_file(value, p_params->reconf_hash);
5724  if (retval != NI_RETCODE_SUCCESS) // for encoder reconfiguration testing
5725  {
5726  return retval;
5727  }
5728  }
5730  {
5731  // for encoder reconfiguration testing
5732  p_params->roi_demo_mode = atoi(value);
5733  if ((p_params->roi_demo_mode < 0) || (p_params->roi_demo_mode > 2))
5734  {
5736  }
5737  }
5739  {
5740  if (0 > atoi(value))
5741  {
5743  }
5744  p_params->low_delay_mode = atoi(value);
5745  }
5747  {
5748  if (0 != atoi(value) && 1 != atoi(value))
5749  {
5751  }
5752  p_params->minFramesDelay = atoi(value);
5753  }
5755  {
5756  p_params->padding = atoi(value);
5757  }
5759  {
5760  if (0 != atoi(value) && 1 != atoi(value))
5761  {
5763  }
5764  p_params->generate_enc_hdrs = atoi(value);
5765  // genHdrs is deprecated in favour of libavcodec parameter -gen_global_headers
5767  }
5769  {
5770  if (0 != atoi(value) && 1 != atoi(value))
5771  {
5773  }
5774  p_params->use_low_delay_poc_type = atoi(value);
5775  }
5777  {
5778  if (QUADRA)
5779  {
5781  }
5782  p_params->force_frame_type = atoi(value);
5783  }
5785  {
5786  p_enc->profile = atoi(value);
5787  }
5789  {
5793  if (atof(value) <= 10)
5794  {
5795  p_enc->level_idc = (int)(10 * atof(value) + .5);
5796  }
5797  else
5798  {
5799  p_enc->level_idc = atoi(value);
5800  }
5801  }
5803  {
5804  p_enc->high_tier = atobool(value);
5805  }
5807  {
5808  p_params->log = atoi(value);
5809  if (b_error)
5810  {
5811  b_error = false;
5812  p_params->log = ni_parse_name(value, g_xcoder_log_names, &b_error) - 1;
5813  }
5814  }
5816  {
5817  if ((atoi(value) > NI_MAX_GOP_PRESET_IDX) || (atoi(value) < NI_MIN_GOP_PRESET_IDX))
5818  {
5820  }
5821  p_enc->gop_preset_index = atoi(value);
5822  }
5824  {
5826  {
5828  }
5829 
5830  p_enc->use_recommend_enc_params = atoi(value);
5831  }
5833  {
5834  if (QUADRA)
5835  {
5837  }
5838  if (((atoi(value) > NI_MAX_CU_SIZE_MODE) || (atoi(value) < NI_MIN_CU_SIZE_MODE)) && (atoi(value) != NI_DEFAULT_CU_SIZE_MODE))
5839  {
5841  }
5842 
5843  p_enc->cu_size_mode = atoi(value);
5844  }
5846  {
5847  if (QUADRA)
5848  {
5850  }
5851  if ((atoi(value) > NI_MAX_MAX_NUM_MERGE) || (atoi(value) < NI_MIN_MAX_NUM_MERGE))
5852  {
5854  }
5855 
5856  p_enc->max_num_merge = atoi(value);
5857  }
5859  {
5860  if (QUADRA)
5861  {
5863  }
5864  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5865  {
5867  }
5868 
5869  p_enc->enable_dynamic_8x8_merge = atoi(value);
5870  }
5872  {
5873  if (QUADRA)
5874  {
5876  }
5877  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5878  {
5880  }
5881 
5882  p_enc->enable_dynamic_16x16_merge = atoi(value);
5883  }
5885  {
5886  if (QUADRA)
5887  {
5889  }
5890  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5891  {
5893  }
5894 
5895  p_enc->enable_dynamic_32x32_merge = atoi(value);
5896  }
5898  {
5899  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5900  {
5902  }
5903 
5904  p_enc->rc.enable_rate_control = atoi(value);
5905  }
5907  {
5908  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5909  {
5911  }
5912 
5913  p_enc->rc.enable_cu_level_rate_control = atoi(value);
5914  }
5916  {
5917  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5918  {
5920  }
5921  p_enc->rc.enable_hvs_qp = atoi(value);
5922  }
5924  {
5925  if (QUADRA)
5926  {
5928  }
5929  p_enc->rc.enable_hvs_qp_scale = atoi(value);
5930  }
5932  {
5933  p_enc->rc.hvs_qp_scale = atoi(value);
5934  }
5936  {
5937  p_enc->rc.min_qp = atoi(value);
5938  }
5940  {
5941  p_enc->rc.max_qp = atoi(value);
5942  }
5944  {
5945  if (QUADRA)
5946  {
5948  }
5949  p_enc->rc.max_delta_qp = atoi(value);
5950  }
5952  {
5953  if ((atoi(value) > 51) || (atoi(value) < -1))
5954  {
5956  }
5957  p_enc->crf = atoi(value);
5958  }
5960  {
5961  p_enc->rc.vbv_buffer_size = atoi(value);
5962  if (QUADRA)
5963  {
5964  // RcInitDelay is deprecated and replaced with vbvBufferSize. But still accept the value.
5966  }
5967  }
5969  {
5970  p_enc->rc.vbv_buffer_size = atoi(value);
5971  }
5973  {
5974  p_enc->rc.vbv_max_rate = atoi(value);
5975  }
5977  {
5978  p_enc->rc.enable_filler = atoi(value);
5979  if (QUADRA)
5980  {
5981  // cbr is deprecated and replaced with fillerEnable. But still accept the value.
5983  }
5984  }
5986  {
5987  p_enc->rc.enable_filler = atoi(value);
5988  }
5990  {
5991  if (0 != atoi(value) && 1 != atoi(value))
5992  {
5994  }
5995  // Currenly pic skip is supported for low delay gops only - pic skip issues tracked by QDFW-1785/1958
5996  p_enc->rc.enable_pic_skip = atoi(value);
5997  }
5999  {
6000 #ifdef _MSC_VER
6001  if (!_strnicmp(value, "ratio", 5))
6002 #else
6003  if (!strncasecmp(value, "ratio", 5))
6004 #endif
6005  {
6006  char value_buf[32] = {0};
6007  for (i = 0; i < sizeof(value_buf); i++)
6008  {
6009  if (value[i+6] == ']')
6010  {
6011  break;
6012  }
6013  value_buf[i] = value[i+6];
6014  }
6015  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6016  {
6018  }
6019 
6020  p_enc->maxFrameSizeRatio = atoi(value_buf);
6021  }
6022  else
6023  {
6024  int size = atoi(value);
6025  if (size < NI_MIN_FRAME_SIZE)
6026  {
6028  }
6029  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6030  }
6031  }
6033  {
6034 #ifdef _MSC_VER
6035  if (!_strnicmp(value, "ratio", 5))
6036 #else
6037  if (!strncasecmp(value, "ratio", 5))
6038 #endif
6039  {
6040  char value_buf[32] = {0};
6041  for (i = 0; i < sizeof(value_buf); i++)
6042  {
6043  if (value[i+6] == ']')
6044  {
6045  break;
6046  }
6047  value_buf[i] = value[i+6];
6048  }
6049  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6050  {
6052  }
6053 
6054  p_enc->maxFrameSizeRatio = atoi(value_buf);
6055  }
6056  else
6057  {
6058  int size = atoi(value) / 8;
6059  if (size < NI_MIN_FRAME_SIZE)
6060  {
6062  }
6063  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6064  }
6065  }
6067  {
6068  if (0 != atoi(value) && 1 != atoi(value))
6069  {
6071  }
6072  p_enc->forced_header_enable = atoi(value);
6073  }
6075  {
6076  p_enc->roi_enable = atoi(value);
6077  }
6079  {
6080  p_enc->conf_win_top = atoi(value);
6081  }
6083  {
6084  p_enc->conf_win_bottom = atoi(value);
6085  }
6087  {
6088  p_enc->conf_win_left = atoi(value);
6089  }
6091  {
6092  p_enc->conf_win_right = atoi(value);
6093  }
6095  {
6096  p_enc->intra_period = atoi(value);
6097  //p_enc->bitrateWindow = p_enc->intra_period;
6098  }
6100  {
6101  if (atoi(value) > NI_MAX_BITRATE)
6102  {
6104  }
6105  if (atoi(value) < NI_MIN_BITRATE)
6106  {
6108  }
6109  p_enc->rc.trans_rate = atoi(value);
6110  }
6112  {
6113  if (atoi(value) <= 0 )
6114  {
6116  }
6117  p_params->fps_number = atoi(value);
6118  p_params->fps_denominator = 1;
6119  p_enc->frame_rate = p_params->fps_number;
6120  }
6122  {
6123  if (atoi(value) <= 0)
6124  {
6126  }
6127  p_params->fps_denominator = atoi(value);
6128  p_enc->frame_rate = (int)(p_params->fps_number / p_params->fps_denominator);
6129  }
6131  {
6132  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6133  {
6135  }
6136 
6137  p_enc->rc.intra_qp = atoi(value);
6138  }
6140  {
6141  if ((atoi(value) > NI_MAX_INTRA_QP_DELTA) ||
6142  (atoi(value) < NI_MIN_INTRA_QP_DELTA))
6143  {
6145  }
6146 
6147  p_enc->rc.intra_qp_delta = atoi(value);
6148  }
6150  {
6151  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6152  {
6154  }
6155  p_params->force_pic_qp_demo_mode = atoi(value);
6156  }
6158  {
6159  if (QUADRA)
6160  {
6162  }
6164  {
6166  }
6167  p_enc->decoding_refresh_type = atoi(value);
6168  }
6170  {
6171  if (0 != atoi(value) && 1 != atoi(value))
6172  {
6174  }
6175  p_enc->intra_reset_refresh = atoi(value);
6176  }
6177 // Rev. B: H.264 only parameters.
6179  {
6180  if (QUADRA)
6181  {
6183  }
6184  p_enc->enable_transform_8x8 = atoi(value);
6185  }
6187  {
6188  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6189  {
6191  }
6192  p_enc->slice_mode = atoi(value);
6193  }
6195  {
6196  p_enc->slice_arg = atoi(value);
6197  }
6199  {
6200  if (0 != atoi(value) && 1 != atoi(value))
6201  {
6203  }
6204  p_enc->entropy_coding_mode = atoi(value);
6205  }
6206 // Rev. B: shared between HEVC and H.264
6208  {
6209  p_enc->intra_mb_refresh_mode = atoi(value);
6210  }
6212  {
6213  p_enc->intra_mb_refresh_arg = atoi(value);
6214  }
6216  {
6217  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6218  {
6220  }
6221  p_enc->rc.enable_mb_level_rc = atoi(value);
6222  if (QUADRA)
6223  {
6224  // mbLevelRcEnable will be deprecated and cuLevelRCEnable should be used instead. But still accept the value.
6226  }
6227  }
6229  {
6230  if ((atoi(value) > 255) || (atoi(value) < 0))
6231  {
6233  }
6234  p_enc->preferred_transfer_characteristics = atoi(value);
6235  }
6237  {
6238  if (atoi(value) != 0 && atoi(value) != 5)
6239  {
6241  }
6242  p_params->dolby_vision_profile = atoi(value);
6243  }
6245  {
6246  if ((atoi(value) > 3) || (atoi(value) < 1))
6247  {
6249  }
6250  p_enc->rdoLevel = atoi(value);
6251  }
6253  {
6254  const char delim[2] = ",";
6255  char *chunk;
6256 #ifdef _MSC_VER
6257  char *v = _strdup(value);
6258 #else
6259  char *v = strdup(value);
6260 #endif
6261  char *saveptr = NULL;
6262  chunk = ni_strtok(v, delim, &saveptr);
6263  if (chunk != NULL)
6264  {
6265  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6266  {
6267  free(v);
6269  }
6270  p_enc->HDR10MaxLight = atoi(chunk);
6271  chunk = ni_strtok(NULL, delim, &saveptr);
6272  if (chunk != NULL)
6273  {
6274  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6275  {
6276  free(v);
6278  }
6279  p_enc->HDR10AveLight = atoi(chunk);
6280  p_enc->HDR10CLLEnable = 1; //Both param populated so enable
6281  free(v);
6282  }
6283  else
6284  {
6285  free(v);
6287  }
6288  }
6289  else
6290  {
6291  free(v);
6293  }
6294  }
6295 
6297  {
6298 #ifdef _MSC_VER
6299 #define STRDUP(value) _strdup(value);
6300 #else
6301 #define STRDUP(value) strdup(value);
6302 #endif
6303  const char G[2] = "G";
6304  const char B[2] = "B";
6305  const char R[2] = "R";
6306  const char W[2] = "W";
6307  const char L[2] = "L";
6308  const char P[2] = "P";
6309  const char parL[2] = "(";
6310  const char comma[2] = ",";
6311  const char parR[2] = ")";
6312  int synCheck_GBRWLPCP[8];
6313  int posCheck_GBRWL[5] = {0};
6314  char *chunk;//for parsing out more complex inputs
6315  char *subchunk;
6316  char *v = STRDUP(value);
6317  //basic check syntax correct
6318  for (i = 0; i<8; i++)
6319  {
6320  synCheck_GBRWLPCP[i] = 0;
6321  }
6322  chunk = v;
6323  i = 0; // character index
6324 
6325  //count keys and punctuation, save indicies to be parsed
6326  while (*chunk) {
6327  if (*chunk == G[0])
6328  {
6329  synCheck_GBRWLPCP[0]++;
6330  posCheck_GBRWL[0] = i;
6331  }
6332  else if (*chunk == B[0])
6333  {
6334  synCheck_GBRWLPCP[1]++;
6335  posCheck_GBRWL[1] = i;
6336  }
6337  else if (*chunk == R[0])
6338  {
6339  synCheck_GBRWLPCP[2]++;
6340  posCheck_GBRWL[2] = i;
6341  }
6342  else if (*chunk == W[0])
6343  {
6344  synCheck_GBRWLPCP[3]++;
6345  posCheck_GBRWL[3] = i;
6346  }
6347  else if (*chunk == L[0])
6348  {
6349  synCheck_GBRWLPCP[4]++;
6350  posCheck_GBRWL[4] = i;
6351  }
6352  else if (*chunk == parL[0])
6353  {
6354  synCheck_GBRWLPCP[5]++;
6355  }
6356  else if (*chunk == comma[0])
6357  {
6358  synCheck_GBRWLPCP[6]++;
6359  }
6360  else if (*chunk == parR[0])
6361  {
6362  synCheck_GBRWLPCP[7]++;
6363  }
6364  chunk++;
6365  i++;
6366  }
6367  free(v);
6368  if (synCheck_GBRWLPCP[0] != 1 || synCheck_GBRWLPCP[1] != 1 || synCheck_GBRWLPCP[2] != 1 ||
6369  synCheck_GBRWLPCP[3] != 1 || synCheck_GBRWLPCP[4] != 1 || synCheck_GBRWLPCP[5] != 5 ||
6370  synCheck_GBRWLPCP[6] != 5 || synCheck_GBRWLPCP[7] != 5)
6371  {
6373  }
6374 
6375  //Parse a key-value set like G(%hu, %hu)
6376 #define GBRWLPARSE(OUT1,OUT2,OFF,IDX) \
6377 { \
6378  char *v = STRDUP(value); \
6379  chunk = v + posCheck_GBRWL[IDX]; \
6380  i = j = k = 0; \
6381  while (chunk != NULL) \
6382  { \
6383  if (*chunk == parL[0] && i == 1+(OFF)) \
6384  { \
6385  j = 1; \
6386  } \
6387  if((OFF) == 1 && *chunk != P[0] && i == 1) \
6388  { \
6389  break; \
6390  } \
6391  if (*chunk == parR[0]) \
6392  { \
6393  k = 1; \
6394  break; \
6395  } \
6396  i++; \
6397  chunk++; \
6398  } \
6399  if (!j || !k) \
6400  { \
6401  free(v); \
6402  return NI_RETCODE_PARAM_INVALID_VALUE; \
6403  } \
6404  subchunk = malloc(i - 1 - (OFF)); \
6405  if (subchunk == NULL) \
6406  { \
6407  free(v); \
6408  return NI_RETCODE_ERROR_MEM_ALOC; \
6409  } \
6410  memcpy(subchunk, v + posCheck_GBRWL[IDX] + 2 + (OFF), i - 2 - (OFF)); \
6411  subchunk[i - 2 - (OFF)] = '\0'; \
6412  char *saveptr = NULL; \
6413  chunk = ni_strtok(subchunk, comma, &saveptr); \
6414  if (chunk != NULL) \
6415  { \
6416  if(atoi(chunk) < 0) \
6417  { \
6418  free(v); \
6419  if(subchunk != NULL){ \
6420  free(subchunk); \
6421  } \
6422  return NI_RETCODE_PARAM_INVALID_VALUE; \
6423  } \
6424  *(OUT1) = atoi(chunk); \
6425  } \
6426  chunk = ni_strtok(NULL, comma, &saveptr); \
6427  if (chunk != NULL) \
6428  { \
6429  if(atoi(chunk) < 0) \
6430  { \
6431  free(v); \
6432  if(subchunk != NULL){ \
6433  free(subchunk); \
6434  } \
6435  return NI_RETCODE_PARAM_INVALID_VALUE; \
6436  } \
6437  *(OUT2) = atoi(chunk); \
6438  } \
6439  free(subchunk); \
6440  free(v); \
6441 }
6442  GBRWLPARSE(&p_enc->HDR10dx0, &p_enc->HDR10dy0, 0, 0);
6443  GBRWLPARSE(&p_enc->HDR10dx1, &p_enc->HDR10dy1, 0, 1);
6444  GBRWLPARSE(&p_enc->HDR10dx2, &p_enc->HDR10dy2, 0, 2);
6445  GBRWLPARSE(&p_enc->HDR10wx, &p_enc->HDR10wy, 1, 3);
6446  GBRWLPARSE(&p_enc->HDR10maxluma, &p_enc->HDR10minluma, 0, 4);
6447  p_enc->HDR10Enable = 1;
6448  }
6450  {
6451  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
6452  {
6454  }
6455  p_enc->lookAheadDepth = atoi(value);
6456  }
6458  {
6459  if (atoi(value) != 0 && atoi(value) != 1)
6460  {
6462  }
6463  p_enc->hrdEnable = atoi(value);
6464  }
6466  {
6467  if ((atoi(value) != 0) && (atoi(value) != 1))
6468  {
6470  }
6471  p_enc->EnableAUD = atoi(value);
6472  }
6474  {
6475  if (atoi(value) != 0 && atoi(value) != 1)
6476  {
6478  }
6479  p_params->cacheRoi = atoi(value);
6480  }
6482  {
6483  if (atoi(value) != 0 && atoi(value) != 1)
6484  {
6486  }
6487  p_enc->long_term_ref_enable = atoi(value);
6488  }
6490  {
6491  p_enc->long_term_ref_interval = atoi(value);
6492  }
6494  {
6495  if (atoi(value) < 1 || atoi(value) > 2)
6496  {
6498  }
6499  p_enc->long_term_ref_count = atoi(value);
6500  }
6502  {
6503  if ((atoi(value) != 0) && (atoi(value) != 1))
6504  {
6506  }
6507  p_enc->EnableRdoQuant = atoi(value);
6508  }
6510  {
6511  if (QUADRA)
6512  {
6514  }
6515 
6516  if ((atoi(value) < 0) || (atoi(value) > 3))
6517  {
6519  }
6520  p_enc->ctbRcMode = atoi(value);
6521  }
6523  {
6524  if (QUADRA)
6525  {
6527  }
6528 
6529  p_enc->gopSize = atoi(value);
6530  }
6532  {
6533  if (QUADRA)
6534  {
6536  }
6537 
6538  if ((atoi(value) != 0) && (atoi(value) != 1))
6539  {
6541  }
6542  p_enc->gopLowdelay = atoi(value);
6543  }
6545  {
6546  if (QUADRA)
6547  {
6549  }
6550  p_enc->gdrDuration = atoi(value);
6551  }
6553  {
6554  p_enc->ltrRefInterval = atoi(value);
6555  }
6557  {
6558  p_enc->ltrRefQpOffset = atoi(value);
6559  }
6561  {
6562  p_enc->ltrFirstGap = atoi(value);
6563  }
6566  {
6567  if ((atoi(value) != 0) && (atoi(value) != 1))
6568  {
6570  }
6571  p_enc->multicoreJointMode = atoi(value);
6572  }
6574  {
6575  if ((atoi(value) < 0) || (atoi(value) > 9))
6576  {
6578  }
6579  p_enc->qlevel = atoi(value);
6580  }
6582  {
6583  if ((atoi(value) > 12) || (atoi(value) < -12))
6584  {
6586  }
6587  p_enc->chromaQpOffset = atoi(value);
6588  }
6589  OPT(NI_ENC_PARAM_TOL_RC_INTER) { p_enc->tolCtbRcInter = (float)atof(value); }
6590  OPT(NI_ENC_PARAM_TOL_RC_INTRA) { p_enc->tolCtbRcIntra = (float)atof(value); }
6592  {
6593  if ((atoi(value) > 300) || (atoi(value) < 1))
6594  {
6596  }
6597  p_enc->bitrateWindow = atoi(value);
6598  }
6600  {
6601  if ((atoi(value) > 2) || (atoi(value) < 0))
6602  {
6604  }
6605  p_enc->blockRCSize = atoi(value);
6606  }
6608  {
6609  if ((atoi(value) > 15) || (atoi(value) < 0))
6610  {
6612  }
6613  p_enc->rcQpDeltaRange = atoi(value);
6614  }
6616  {
6617  if ((atoi(value) > 500) || (atoi(value) < 0))
6618  {
6620  }
6621  p_enc->ctbRowQpStep = atoi(value);
6622  }
6624  {
6625  if ((atoi(value) > 1) || (atoi(value) < 0))
6626  {
6628  }
6629  p_enc->newRcEnable = atoi(value);
6630  }
6632  {
6633  if ((atoi(value) > 1) || (atoi(value) < 0))
6634  {
6636  }
6637  p_enc->inLoopDSRatio = atoi(value);
6638  }
6640  {
6641  COMPARE(value, 22, 0)
6642  p_params->color_primaries = p_enc->colorPrimaries = atoi(value);
6643  p_enc->colorDescPresent = 1;
6644  }
6646  {
6647  COMPARE(value, 18, 0)
6648  p_params->color_transfer_characteristic = p_enc->colorTrc = atoi(value);
6649  p_enc->colorDescPresent = 1;
6650  }
6652  {
6653  COMPARE(value, 14, 0)
6654  p_params->color_space = p_enc->colorSpace = atoi(value);
6655  p_enc->colorDescPresent = 1;
6656  }
6658  {
6659  p_params->sar_num = p_enc->aspectRatioWidth = atoi(value);
6660  }
6662  {
6663  p_params->sar_denom = p_enc->aspectRatioHeight = atoi(value);
6664  }
6666  {
6667  p_params->video_full_range_flag = p_enc->videoFullRange = atoi(value);
6668  }
6670  {
6671  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
6672  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
6673  {
6675  }
6676  p_enc->keep_alive_timeout = atoi(value);
6677  }
6679  {
6680  if (atoi(value) != 0 && atoi(value) != 1)
6681  {
6683  }
6684  p_params->enable_vfr = atoi(value);
6685  }
6687  {
6688  if (atoi(value) < 0 || atoi(value) > 3)
6689  {
6691  }
6692  p_enc->get_psnr_mode = atoi(value);
6693  }
6695  {
6696  if (atoi(value) < 1)
6697  {
6699  }
6700  p_params->interval_of_psnr = atoi(value);
6701  }
6703  {
6704  if (atoi(value) < 0 || atoi(value) > 1)
6705  {
6707  }
6708  p_enc->get_psnr_mode = atoi(value) + 3;
6709  }
6711  {
6712  if ((atoi(value) != 0) && (atoi(value) != 1))
6713  {
6715  }
6716  p_enc->enable_ssim = atoi(value);
6717  }
6719  {
6720  if ((atoi(value) != 0) && (atoi(value) != 1))
6721  {
6723  }
6724  p_enc->av1_error_resilient_mode = atoi(value);
6725  }
6727  {
6728  if ((atoi(value) != 0) && (atoi(value) != 1))
6729  {
6731  }
6732  p_params->staticMmapThreshold = atoi(value);
6733  }
6735  {
6736  p_enc->temporal_layers_enable = atoi(value);
6737  }
6739  {
6740  if ((atoi(value) != 0) && (atoi(value) != 1))
6741  {
6743  }
6744  p_params->enable_ai_enhance = atoi(value);
6745  }
6747  {
6748  if ((atoi(value) != 0) && (atoi(value) != 1))
6749  {
6751  }
6752  if(p_params->enable_ai_enhance)
6753  {
6754  ni_log(NI_LOG_ERROR, "Cannot set enableAIEnhance and enableHVSPlus at same time, just enableHVSPlus\n");
6755  }
6756  p_params->enable_ai_enhance = 2;
6757  }
6759  {
6760  if ((atoi(value) != 0) && (atoi(value) != 1))
6761  {
6763  }
6764  p_params->enable2PassGop = atoi(value);
6765  }
6767  {
6768  if ((atoi(value) != 0) && (atoi(value) != 1) && (atoi(value) != -1))
6769  {
6771  }
6772  p_params->zerocopy_mode = atoi(value);
6773  }
6775  {
6776  if ((atoi(value) == 0) || (atoi(value) > 3))
6777  {
6779  }
6780  p_params->ai_enhance_level = atoi(value);
6781  }
6783  {
6784  if ((atoi(value) == 0) || (atoi(value) > 2))
6785  {
6787  }
6788  p_params->ai_enhance_level = atoi(value);
6789  }
6791  {
6792  if ((atoi(value) < NI_MIN_WIDTH) ||
6793  (atoi(value) > NI_PARAM_MAX_WIDTH))
6794  {
6796  }
6797  p_enc->crop_width = atoi(value);
6798  }
6800  {
6801  if ((atoi(value) < NI_MIN_HEIGHT) ||
6802  (atoi(value) > NI_PARAM_MAX_HEIGHT))
6803  {
6805  }
6806  p_enc->crop_height = atoi(value);
6807  }
6809  {
6810  if ((atoi(value) < 0) ||
6811  (atoi(value) > NI_PARAM_MAX_WIDTH))
6812  {
6814  }
6815  p_enc->hor_offset = atoi(value);
6816  }
6818  {
6819  if ((atoi(value) < 0) ||
6820  (atoi(value) > NI_PARAM_MAX_HEIGHT))
6821  {
6823  }
6824  p_enc->ver_offset = atoi(value);
6825  }
6827  {
6828  if ((atoi(value) > 51) || (atoi(value) < -1))
6829  {
6831  }
6832  p_enc->crfMax = atoi(value);
6833  }
6835  {
6836  if ((atof(value) > 1.0) || (atof(value) < 0.0))
6837  {
6839  }
6840  p_enc->qcomp = (float)atof(value);
6841  }
6843  {
6844  if ((atoi(value) != 0) && (atoi(value) != 1))
6845  {
6847  }
6848  p_enc->noMbtree = atoi(value);
6849  }
6851  {
6852  if ((atoi(value) != 0) && (atoi(value) != 1))
6853  {
6855  }
6856  p_enc->avcc_hvcc = atoi(value);
6857  }
6859  {
6860  if ((atoi(value) != 0) && (atoi(value) != 1))
6861  {
6863  }
6864  p_enc->noHWMultiPassSupport = atoi(value);
6865  }
6867  {
6868  if ((atoi(value) > 10) || (atoi(value) < 1))
6869  {
6871  }
6872  p_enc->cuTreeFactor = atoi(value);
6873  }
6875  {
6876  if ((atof(value) > 10.0) || (atof(value) < 0.01))
6877  {
6879  }
6880  p_enc->ipRatio = (float)atof(value);
6881  }
6883  {
6884  if ((atoi(value) != 0) && (atoi(value) != 1))
6885  {
6887  }
6888  p_enc->enableipRatio = atoi(value);
6889  }
6891  {
6892  if ((atof(value) > 10.0) || (atof(value) < 0.01))
6893  {
6895  }
6896  p_enc->pbRatio = (float)atof(value);
6897  }
6899  {
6900  if ((atof(value) > 1.0) || (atof(value) < 0.1))
6901  {
6903  }
6904  p_enc->cplxDecay = (float)atof(value);
6905  }
6907  {
6908  if ((atoi(value) > 51) || (atoi(value) < -1))
6909  {
6911  }
6912  p_enc->pps_init_qp = atoi(value);
6913  }
6915  {
6916  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
6917  atoi(value) <= NI_DDR_PRIORITY_NONE)
6918  {
6920  }
6921  p_params->ddr_priority_mode = atoi(value);
6922  }
6924  {
6925  if ((atoi(value) != 0) && (atoi(value) != 1))
6926  {
6928  }
6929  p_enc->bitrateMode = atoi(value);
6930  }
6932  {
6933  if ((atoi(value) > 51) || (atoi(value) < -1))
6934  {
6936  }
6937  p_enc->pass1_qp = atoi(value);
6938  }
6940  {
6941  if (((atof(value) < 0.0) && (atof(value) != -1.0)) ||
6942  (atof(value) > 51.00))
6943  {
6945  }
6946  p_enc->crfFloat = (float)atof(value);
6947  }
6949  {
6950  if ((atoi(value) < 0) || (atoi(value) > 31))
6951  {
6953  }
6954  p_enc->hvsBaseMbComplexity = atoi(value);
6955  }
6957  {
6958  if (atoi(value) < 0 || atoi(value) > 1)
6959  {
6961  }
6962  p_enc->statistic_output_level = atoi(value);
6963  }
6965  {
6966  //Currently only support 6 stillImage detect level
6967  //0-3: no performance drop
6968  //4-6: performance drop
6969  if ((atoi(value) < 0 || atoi(value) > 6))
6970  {
6972  }
6973  p_enc->still_image_detect_level = atoi(value);
6974  }
6976  {
6977  //Currently only support 10 sceneChange detect level
6978  //1-5 : no performance drop
6979  //6-10: performance drop
6980  if ((atoi(value) < 0 || atoi(value) > 10))
6981  {
6983  }
6984  p_enc->scene_change_detect_level = atoi(value);
6985  }
6987  {
6988  if ((atoi(value) != 0) && (atoi(value) != 1))
6989  {
6991  }
6992  p_enc->enable_smooth_crf = atoi(value);
6993  }
6995  {
6996  if ((atoi(value) != 0) && (atoi(value) != 1))
6997  {
6999  }
7000  p_enc->enable_compensate_qp = atoi(value);
7001  }
7003  {
7004  if (atoi(value) < 0 || atoi(value) > 1)
7005  {
7007  }
7008  p_enc->skip_frame_enable = atoi(value);
7009  }
7011  {
7012  if (atoi(value) < 0)
7013  {
7015  }
7016  p_enc->max_consecutive_skip_num = atoi(value);
7017  }
7019  {
7020  if (atoi(value) < 0 || atoi(value) > 255)
7021  {
7023  }
7024  p_enc->skip_frame_interval = atoi(value);
7025  }
7027  {
7028  if (atoi(value) != 0 && atoi(value) != 1)
7029  {
7031  }
7032  p_enc->enable_all_sei_passthru = atoi(value);
7033  }
7035  {
7036  if (atoi(value) <= 0)
7037  {
7039  }
7040  p_enc->iframe_size_ratio = atoi(value);
7041  }
7043  {
7044  if (atoi(value) != 0 && atoi(value) != 1)
7045  {
7047  }
7048  p_enc->crf_max_iframe_enable = atoi(value);
7049  }
7051  {
7052  p_enc->vbv_min_rate = atoi(value);
7053  }
7055  {
7056  if (atoi(value) != 0 && atoi(value) != 1)
7057  {
7059  }
7060  p_enc->disable_adaptive_buffers = atoi(value);
7061  }
7063  {
7064  if ((atoi(value) != 0) && (atoi(value) != 1))
7065  {
7067  }
7068  p_enc->disableBframeRdoq = atoi(value);
7069  }
7071  {
7072  if ((atof(value) > 1.0) || (atof(value) < 0.0))
7073  {
7075  }
7076  p_enc->forceBframeQpfactor = (float)atof(value);
7077  }
7079  {
7080  if (atoi(value) < 0 || atoi(value) > 2)
7081  {
7083  }
7084  p_enc->tune_bframe_visual = atoi(value);
7085  }
7087  {
7088  if ((atoi(value) != 0) && (atoi(value) != 1))
7089  {
7091  }
7092  p_enc->enable_acq_limit = atoi(value);
7093  }
7095  {
7096  if (atoi(value) < 0 || atoi(value) > 1)
7097  {
7099  }
7100  p_enc->customize_roi_qp_level = atoi(value);
7101  }
7103  {
7105  if (retval != NI_RETCODE_SUCCESS)
7106  {
7107  return retval;
7108  }
7109  // indicate it need to upload roi qp map
7110  p_enc->customize_roi_qp_level += 64;
7111  }
7113  {
7114  if (atoi(value) < 0 || atoi(value) > 2)
7115  {
7117  }
7118  p_enc->motionConstrainedMode = atoi(value);
7119  }
7121  {
7124  {
7126  }
7127  p_enc->encMallocStrategy = atoi(value);
7128  }
7130  {
7131  if (atoi(value) < 1 || atoi(value) > 4)
7132  {
7134  }
7135  p_enc->spatial_layers = atoi(value);
7136  }
7138  {
7139  if (atoi(value) < 0 || atoi(value) > 1)
7140  {
7142  }
7143  p_enc->enable_timecode = atoi(value);
7144  }
7146  {
7147  if ((atoi(value) != 0) && (atoi(value) != 1))
7148  {
7150  }
7151  p_enc->spatial_layers_ref_base_layer = atoi(value);
7152  }
7154  {
7155  if ((atoi(value) != 0) && (atoi(value) != 1))
7156  {
7158  }
7159  p_enc->vbvBufferReencode = atoi(value);
7160  }
7161  else { return NI_RETCODE_PARAM_INVALID_NAME; }
7162 
7163 #undef OPT
7164 #undef OPT2
7165 #undef atobool
7166 #undef atoi
7167 #undef atof
7168 
7169  b_error |= bValueWasNull && !bNameWasBool;
7170 
7171  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
7172 
7174 }
7175 
7176 #undef atoi
7177 #undef atof
7178 #define atoi(p_str) ni_atoi(p_str, &b_error)
7179 #define atof(p_str) ni_atof(p_str, &b_error)
7180 #define atobool(p_str) (ni_atobool(p_str, &b_error))
7181 
7182 /*!*****************************************************************************
7183  * \brief Set GOP parameter value referenced by name in encoder parameters
7184  * structure
7185  *
7186  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
7187  * to find and set a particular parameter
7188  * \param[in] name String represented parameter name to search
7189  * \param[in] value Parameter value to set
7190 *
7191  * \return On success
7192  * NI_RETCODE_SUCCESS
7193  * On failure
7194  * NI_RETCODE_FAILURE
7195  * NI_RETCODE_INVALID_PARAM
7196  ******************************************************************************/
7198  const char *name,
7199  const char *value)
7200 {
7201  bool b_error = false;
7202  bool bNameWasBool = false;
7203  bool bValueWasNull = !value;
7204  ni_encoder_cfg_params_t *p_enc = NULL;
7205  ni_custom_gop_params_t* p_gop = NULL;
7206  char nameBuf[64] = { 0 };
7207 
7208  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
7209 
7210  if (!p_params)
7211  {
7212  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
7213  __func__);
7214  return NI_RETCODE_INVALID_PARAM;
7215  }
7216 
7217  if ( !name )
7218  {
7219  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
7220  __func__);
7222  }
7223  p_enc = &p_params->cfg_enc_params;
7224  p_gop = &p_enc->custom_gop_params;
7225 
7226  // skip -- prefix if provided
7227  if (name[0] == '-' && name[1] == '-')
7228  {
7229  name += 2;
7230  }
7231 
7232  // s/_/-/g
7233  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
7234  {
7235  char* c;
7236  strcpy(nameBuf, name);
7237  while ((c = strchr(nameBuf, '_')) != 0)
7238  {
7239  *c = '-';
7240  }
7241  name = nameBuf;
7242  }
7243 
7244  if (!value)
7245  {
7246  value = "true";
7247  }
7248  else if (value[0] == '=')
7249  {
7250  value++;
7251  }
7252 
7253 #if defined(_MSC_VER)
7254 #define OPT(STR) else if (!_stricmp(name, STR))
7255 #else
7256 #define OPT(STR) else if (!strcasecmp(name, STR))
7257 #endif
7258  if (0); // suppress cppcheck
7260  {
7261  if (atoi(value) > NI_MAX_GOP_SIZE)
7262  {
7264  }
7265  if (atoi(value) < NI_MIN_GOP_SIZE)
7266  {
7268  }
7269  p_gop->custom_gop_size = atoi(value);
7270  }
7271 
7272 #ifndef QUADRA
7274  {
7275  p_gop->pic_param[0].pic_type = atoi(value);
7276  }
7278  {
7279  p_gop->pic_param[0].poc_offset = atoi(value);
7280  }
7281  OPT(NI_ENC_GOP_PARAMS_G0_PIC_QP)
7282  {
7283  p_gop->pic_param[0].pic_qp = atoi(value);
7284  }
7285  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC_L0)
7286  {
7287  p_gop->pic_param[0].num_ref_pic_L0 = atoi(value);
7288  }
7289  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L0)
7290  {
7291  p_gop->pic_param[0].ref_poc_L0 = atoi(value);
7292  }
7293  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L1)
7294  {
7295  p_gop->pic_param[0].ref_poc_L1 = atoi(value);
7296  }
7298  {
7299  p_gop->pic_param[0].temporal_id = atoi(value);
7300  }
7301 
7303  {
7304  p_gop->pic_param[1].pic_type = atoi(value);
7305  }
7307  {
7308  p_gop->pic_param[1].poc_offset = atoi(value);
7309  }
7310  OPT(NI_ENC_GOP_PARAMS_G1_PIC_QP)
7311  {
7312  p_gop->pic_param[1].pic_qp = atoi(value);
7313  }
7314  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC_L0)
7315  {
7316  p_gop->pic_param[1].num_ref_pic_L0 = atoi(value);
7317  }
7318  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L0)
7319  {
7320  p_gop->pic_param[1].ref_poc_L0 = atoi(value);
7321  }
7322  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L1)
7323  {
7324  p_gop->pic_param[1].ref_poc_L1 = atoi(value);
7325  }
7327  {
7328  p_gop->pic_param[1].temporal_id = atoi(value);
7329  }
7330 
7332  {
7333  p_gop->pic_param[2].pic_type = atoi(value);
7334  }
7336  {
7337  p_gop->pic_param[2].poc_offset = atoi(value);
7338  }
7339  OPT(NI_ENC_GOP_PARAMS_G2_PIC_QP)
7340  {
7341  p_gop->pic_param[2].pic_qp = atoi(value);
7342  }
7343  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC_L0)
7344  {
7345  p_gop->pic_param[2].num_ref_pic_L0 = atoi(value);
7346  }
7347  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L0)
7348  {
7349  p_gop->pic_param[2].ref_poc_L0 = atoi(value);
7350  }
7351  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L1)
7352  {
7353  p_gop->pic_param[2].ref_poc_L1 = atoi(value);
7354  }
7356  {
7357  p_gop->pic_param[2].temporal_id = atoi(value);
7358  }
7359 
7361  {
7362  p_gop->pic_param[3].pic_type = atoi(value);
7363  }
7365  {
7366  p_gop->pic_param[3].poc_offset = atoi(value);
7367  }
7368  OPT(NI_ENC_GOP_PARAMS_G3_PIC_QP)
7369  {
7370  p_gop->pic_param[3].pic_qp = atoi(value);
7371  }
7372  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC_L0)
7373  {
7374  p_gop->pic_param[3].num_ref_pic_L0 = atoi(value);
7375  }
7376  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L0)
7377  {
7378  p_gop->pic_param[3].ref_poc_L0 = atoi(value);
7379  }
7380  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L1)
7381  {
7382  p_gop->pic_param[3].ref_poc_L1 = atoi(value);
7383  }
7385  {
7386  p_gop->pic_param[3].temporal_id = atoi(value);
7387  }
7388 
7390  {
7391  p_gop->pic_param[4].pic_type = atoi(value);
7392  }
7394  {
7395  p_gop->pic_param[4].poc_offset = atoi(value);
7396  }
7397  OPT(NI_ENC_GOP_PARAMS_G4_PIC_QP)
7398  {
7399  p_gop->pic_param[4].pic_qp = atoi(value);
7400  }
7401  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC_L0)
7402  {
7403  p_gop->pic_param[4].num_ref_pic_L0 = atoi(value);
7404  }
7405  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L0)
7406  {
7407  p_gop->pic_param[4].ref_poc_L0 = atoi(value);
7408  }
7409  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L1)
7410  {
7411  p_gop->pic_param[4].ref_poc_L1 = atoi(value);
7412  }
7414  {
7415  p_gop->pic_param[4].temporal_id = atoi(value);
7416  }
7417 
7419  {
7420  p_gop->pic_param[5].pic_type = atoi(value);
7421  }
7423  {
7424  p_gop->pic_param[5].poc_offset = atoi(value);
7425  }
7426  OPT(NI_ENC_GOP_PARAMS_G5_PIC_QP)
7427  {
7428  p_gop->pic_param[5].pic_qp = atoi(value);
7429  }
7430  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC_L0)
7431  {
7432  p_gop->pic_param[5].num_ref_pic_L0 = atoi(value);
7433  }
7434  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L0)
7435  {
7436  p_gop->pic_param[5].ref_poc_L0 = atoi(value);
7437  }
7438  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L1)
7439  {
7440  p_gop->pic_param[5].ref_poc_L1 = atoi(value);
7441  }
7443  {
7444  p_gop->pic_param[5].temporal_id = atoi(value);
7445  }
7446 
7448  {
7449  p_gop->pic_param[6].pic_type = atoi(value);
7450  }
7452  {
7453  p_gop->pic_param[6].poc_offset = atoi(value);
7454  }
7455  OPT(NI_ENC_GOP_PARAMS_G6_PIC_QP)
7456  {
7457  p_gop->pic_param[6].pic_qp = atoi(value);
7458  }
7459  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC_L0)
7460  {
7461  p_gop->pic_param[6].num_ref_pic_L0 = atoi(value);
7462  }
7463  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L0)
7464  {
7465  p_gop->pic_param[6].ref_poc_L0 = atoi(value);
7466  }
7467  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L1)
7468  {
7469  p_gop->pic_param[6].ref_poc_L1 = atoi(value);
7470  }
7472  {
7473  p_gop->pic_param[6].temporal_id = atoi(value);
7474  }
7475 
7477  {
7478  p_gop->pic_param[7].pic_type = atoi(value);
7479  }
7481  {
7482  p_gop->pic_param[7].poc_offset = atoi(value);
7483  }
7484  OPT(NI_ENC_GOP_PARAMS_G7_PIC_QP)
7485  {
7486  p_gop->pic_param[7].pic_qp = atoi(value);
7487  }
7488  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC_L0)
7489  {
7490  p_gop->pic_param[7].num_ref_pic_L0 = atoi(value);
7491  }
7492  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L0)
7493  {
7494  p_gop->pic_param[7].ref_poc_L0 = atoi(value);
7495  }
7496  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L1)
7497  {
7498  p_gop->pic_param[7].ref_poc_L1 = atoi(value);
7499  }
7501  {
7502  p_gop->pic_param[7].temporal_id = atoi(value);
7503  }
7504  else
7505  {
7506  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
7508  }
7509 #else
7511  {
7512  p_gop->pic_param[0].poc_offset = atoi(value);
7513  }
7515  {
7516  p_gop->pic_param[0].qp_offset = atoi(value);
7517  }
7518  /*
7519  OPT(NI_ENC_GOP_PARAMS_G0_QP_FACTOR)
7520  {
7521  p_gop->pic_param[0].qp_factor = atof(value);
7522  }
7523  */
7525  {
7526  p_gop->pic_param[0].temporal_id = atoi(value);
7527  }
7529  {
7530  p_gop->pic_param[0].pic_type = atoi(value);
7531  }
7533  {
7534  p_gop->pic_param[0].num_ref_pics = atoi(value);
7535  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 num_ref_pics %d\n", __func__, p_gop->pic_param[0].num_ref_pics);
7536  }
7538  {
7539  p_gop->pic_param[0].rps[0].ref_pic = atoi(value);
7540  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 %d rps[0].ref_pic %d\n", __func__, p_gop->pic_param[0].rps[0].ref_pic);
7541  }
7543  {
7544  p_gop->pic_param[0].rps[0].ref_pic_used = atoi(value);
7545  //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);
7546  }
7548  {
7549  p_gop->pic_param[0].rps[1].ref_pic = atoi(value);
7550  }
7552  {
7553  p_gop->pic_param[0].rps[1].ref_pic_used = atoi(value);
7554  }
7556  {
7557  p_gop->pic_param[0].rps[2].ref_pic = atoi(value);
7558  }
7560  {
7561  p_gop->pic_param[0].rps[2].ref_pic_used = atoi(value);
7562  }
7564  {
7565  p_gop->pic_param[0].rps[3].ref_pic = atoi(value);
7566  }
7568  {
7569  p_gop->pic_param[0].rps[3].ref_pic_used = atoi(value);
7570  }
7571 
7573  {
7574  p_gop->pic_param[1].poc_offset = atoi(value);
7575  }
7577  {
7578  p_gop->pic_param[1].qp_offset = atoi(value);
7579  }
7580  /*
7581  OPT(NI_ENC_GOP_PARAMS_G1_QP_FACTOR)
7582  {
7583  p_gop->pic_param[1].qp_factor = atof(value);
7584  }
7585  */
7587  {
7588  p_gop->pic_param[1].temporal_id = atoi(value);
7589  }
7591  {
7592  p_gop->pic_param[1].pic_type = atoi(value);
7593  }
7595  {
7596  p_gop->pic_param[1].num_ref_pics = atoi(value);
7597  }
7599  {
7600  p_gop->pic_param[1].rps[0].ref_pic = atoi(value);
7601  }
7603  {
7604  p_gop->pic_param[1].rps[0].ref_pic_used = atoi(value);
7605  }
7607  {
7608  p_gop->pic_param[1].rps[1].ref_pic = atoi(value);
7609  }
7611  {
7612  p_gop->pic_param[1].rps[1].ref_pic_used = atoi(value);
7613  }
7615  {
7616  p_gop->pic_param[1].rps[2].ref_pic = atoi(value);
7617  }
7619  {
7620  p_gop->pic_param[1].rps[2].ref_pic_used = atoi(value);
7621  }
7623  {
7624  p_gop->pic_param[1].rps[3].ref_pic = atoi(value);
7625  }
7627  {
7628  p_gop->pic_param[1].rps[3].ref_pic_used = atoi(value);
7629  }
7630 
7632  {
7633  p_gop->pic_param[2].poc_offset = atoi(value);
7634  }
7636  {
7637  p_gop->pic_param[2].qp_offset = atoi(value);
7638  }
7639  /*
7640  OPT(NI_ENC_GOP_PARAMS_G2_QP_FACTOR)
7641  {
7642  p_gop->pic_param[2].qp_factor = atof(value);
7643  }
7644  */
7646  {
7647  p_gop->pic_param[2].temporal_id = atoi(value);
7648  }
7650  {
7651  p_gop->pic_param[2].pic_type = atoi(value);
7652  }
7654  {
7655  p_gop->pic_param[2].num_ref_pics = atoi(value);
7656  }
7658  {
7659  p_gop->pic_param[2].rps[0].ref_pic = atoi(value);
7660  }
7662  {
7663  p_gop->pic_param[2].rps[0].ref_pic_used = atoi(value);
7664  }
7666  {
7667  p_gop->pic_param[2].rps[1].ref_pic = atoi(value);
7668  }
7670  {
7671  p_gop->pic_param[2].rps[1].ref_pic_used = atoi(value);
7672  }
7674  {
7675  p_gop->pic_param[2].rps[2].ref_pic = atoi(value);
7676  }
7678  {
7679  p_gop->pic_param[2].rps[2].ref_pic_used = atoi(value);
7680  }
7682  {
7683  p_gop->pic_param[2].rps[3].ref_pic = atoi(value);
7684  }
7686  {
7687  p_gop->pic_param[2].rps[3].ref_pic_used = atoi(value);
7688  }
7689 
7691  {
7692  p_gop->pic_param[3].poc_offset = atoi(value);
7693  }
7695  {
7696  p_gop->pic_param[3].qp_offset = atoi(value);
7697  }
7698  /*
7699  OPT(NI_ENC_GOP_PARAMS_G3_QP_FACTOR)
7700  {
7701  p_gop->pic_param[3].qp_factor = atof(value);
7702  }
7703  */
7705  {
7706  p_gop->pic_param[3].temporal_id = atoi(value);
7707  }
7709  {
7710  p_gop->pic_param[3].pic_type = atoi(value);
7711  }
7713  {
7714  p_gop->pic_param[3].num_ref_pics = atoi(value);
7715  }
7717  {
7718  p_gop->pic_param[3].rps[0].ref_pic = atoi(value);
7719  }
7721  {
7722  p_gop->pic_param[3].rps[0].ref_pic_used = atoi(value);
7723  }
7725  {
7726  p_gop->pic_param[3].rps[1].ref_pic = atoi(value);
7727  }
7729  {
7730  p_gop->pic_param[3].rps[1].ref_pic_used = atoi(value);
7731  }
7733  {
7734  p_gop->pic_param[3].rps[2].ref_pic = atoi(value);
7735  }
7737  {
7738  p_gop->pic_param[3].rps[2].ref_pic_used = atoi(value);
7739  }
7741  {
7742  p_gop->pic_param[3].rps[3].ref_pic = atoi(value);
7743  }
7745  {
7746  p_gop->pic_param[3].rps[3].ref_pic_used = atoi(value);
7747  }
7748 
7750  {
7751  p_gop->pic_param[4].poc_offset = atoi(value);
7752  }
7754  {
7755  p_gop->pic_param[4].qp_offset = atoi(value);
7756  }
7757  /*
7758  OPT(NI_ENC_GOP_PARAMS_G4_QP_FACTOR)
7759  {
7760  p_gop->pic_param[4].qp_factor = atof(value);
7761  }
7762  */
7764  {
7765  p_gop->pic_param[4].temporal_id = atoi(value);
7766  }
7768  {
7769  p_gop->pic_param[4].pic_type = atoi(value);
7770  }
7772  {
7773  p_gop->pic_param[4].num_ref_pics = atoi(value);
7774  }
7776  {
7777  p_gop->pic_param[4].rps[0].ref_pic = atoi(value);
7778  }
7780  {
7781  p_gop->pic_param[4].rps[0].ref_pic_used = atoi(value);
7782  }
7784  {
7785  p_gop->pic_param[4].rps[1].ref_pic = atoi(value);
7786  }
7788  {
7789  p_gop->pic_param[4].rps[1].ref_pic_used = atoi(value);
7790  }
7792  {
7793  p_gop->pic_param[4].rps[2].ref_pic = atoi(value);
7794  }
7796  {
7797  p_gop->pic_param[4].rps[2].ref_pic_used = atoi(value);
7798  }
7800  {
7801  p_gop->pic_param[4].rps[3].ref_pic = atoi(value);
7802  }
7804  {
7805  p_gop->pic_param[4].rps[3].ref_pic_used = atoi(value);
7806  }
7807 
7809  {
7810  p_gop->pic_param[5].poc_offset = atoi(value);
7811  }
7813  {
7814  p_gop->pic_param[5].qp_offset = atoi(value);
7815  }
7816  /*
7817  OPT(NI_ENC_GOP_PARAMS_G5_QP_FACTOR)
7818  {
7819  p_gop->pic_param[5].qp_factor = atof(value);
7820  }
7821  */
7823  {
7824  p_gop->pic_param[5].temporal_id = atoi(value);
7825  }
7827  {
7828  p_gop->pic_param[5].pic_type = atoi(value);
7829  }
7831  {
7832  p_gop->pic_param[5].num_ref_pics = atoi(value);
7833  }
7835  {
7836  p_gop->pic_param[5].rps[0].ref_pic = atoi(value);
7837  }
7839  {
7840  p_gop->pic_param[5].rps[0].ref_pic_used = atoi(value);
7841  }
7843  {
7844  p_gop->pic_param[5].rps[1].ref_pic = atoi(value);
7845  }
7847  {
7848  p_gop->pic_param[5].rps[1].ref_pic_used = atoi(value);
7849  }
7851  {
7852  p_gop->pic_param[5].rps[2].ref_pic = atoi(value);
7853  }
7855  {
7856  p_gop->pic_param[5].rps[2].ref_pic_used = atoi(value);
7857  }
7859  {
7860  p_gop->pic_param[5].rps[3].ref_pic = atoi(value);
7861  }
7863  {
7864  p_gop->pic_param[5].rps[3].ref_pic_used = atoi(value);
7865  }
7866 
7868  {
7869  p_gop->pic_param[6].poc_offset = atoi(value);
7870  }
7872  {
7873  p_gop->pic_param[6].qp_offset = atoi(value);
7874  }
7875  /*
7876  OPT(NI_ENC_GOP_PARAMS_G6_QP_FACTOR)
7877  {
7878  p_gop->pic_param[6].qp_factor = atof(value);
7879  }
7880  */
7882  {
7883  p_gop->pic_param[6].temporal_id = atoi(value);
7884  }
7886  {
7887  p_gop->pic_param[6].pic_type = atoi(value);
7888  }
7890  {
7891  p_gop->pic_param[6].num_ref_pics = atoi(value);
7892  }
7894  {
7895  p_gop->pic_param[6].rps[0].ref_pic = atoi(value);
7896  }
7898  {
7899  p_gop->pic_param[6].rps[0].ref_pic_used = atoi(value);
7900  }
7902  {
7903  p_gop->pic_param[6].rps[1].ref_pic = atoi(value);
7904  }
7906  {
7907  p_gop->pic_param[6].rps[1].ref_pic_used = atoi(value);
7908  }
7910  {
7911  p_gop->pic_param[6].rps[2].ref_pic = atoi(value);
7912  }
7914  {
7915  p_gop->pic_param[6].rps[2].ref_pic_used = atoi(value);
7916  }
7918  {
7919  p_gop->pic_param[6].rps[3].ref_pic = atoi(value);
7920  }
7922  {
7923  p_gop->pic_param[6].rps[3].ref_pic_used = atoi(value);
7924  }
7925 
7927  {
7928  p_gop->pic_param[7].poc_offset = atoi(value);
7929  }
7931  {
7932  p_gop->pic_param[7].qp_offset = atoi(value);
7933  }
7934  /*
7935  OPT(NI_ENC_GOP_PARAMS_G7_QP_FACTOR)
7936  {
7937  p_gop->pic_param[7].qp_factor = atof(value);
7938  }
7939  */
7941  {
7942  p_gop->pic_param[7].temporal_id = atoi(value);
7943  }
7945  {
7946  p_gop->pic_param[7].pic_type = atoi(value);
7947  }
7949  {
7950  p_gop->pic_param[7].num_ref_pics = atoi(value);
7951  }
7953  {
7954  p_gop->pic_param[7].rps[0].ref_pic = atoi(value);
7955  }
7957  {
7958  p_gop->pic_param[7].rps[0].ref_pic_used = atoi(value);
7959  }
7961  {
7962  p_gop->pic_param[7].rps[1].ref_pic = atoi(value);
7963  }
7965  {
7966  p_gop->pic_param[7].rps[1].ref_pic_used = atoi(value);
7967  }
7969  {
7970  p_gop->pic_param[7].rps[2].ref_pic = atoi(value);
7971  }
7973  {
7974  p_gop->pic_param[7].rps[2].ref_pic_used = atoi(value);
7975  }
7977  {
7978  p_gop->pic_param[7].rps[3].ref_pic = atoi(value);
7979  }
7981  {
7982  p_gop->pic_param[7].rps[3].ref_pic_used = atoi(value);
7983  }
7984  else
7985  {
7986  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
7988  }
7989 #endif
7990 
7991 #undef OPT
7992 #undef OPT2
7993 #undef atobool
7994 #undef atoi
7995 #undef atof
7996 
7997  b_error |= bValueWasNull && !bNameWasBool;
7998 
7999  ni_log(NI_LOG_TRACE, "%s(): exit, b_error=%d\n", __func__, b_error);
8000 
8002 }
8003 
8004 /*!*****************************************************************************
8005 * \brief Copy existing decoding session params for hw frame usage
8006 *
8007 * \param[in] src_p_ctx Pointer to a caller allocated source session context
8008 * \param[in] dst_p_ctx Pointer to a caller allocated destination session
8009 * context
8010 * \return On success
8011 * NI_RETCODE_SUCCESS
8012 * On failure
8013 * NI_RETCODE_INVALID_PARAM
8014 ******************************************************************************/
8016 {
8017  return ni_decoder_session_copy_internal(src_p_ctx, dst_p_ctx);
8018 }
8019 
8020 /*!*****************************************************************************
8021 * \brief Read data from the device
8022 * If device_type is NI_DEVICE_TYPE_DECODER reads data hwdesc from
8023 * decoder
8024 * If device_type is NI_DEVICE_TYPE_SCALER reads data hwdesc from
8025 * scaler
8026 *
8027 * \param[in] p_ctx Pointer to a caller allocated
8028 * ni_session_context_t struct
8029 * \param[in] p_data Pointer to a caller allocated
8030 * ni_session_data_io_t struct which contains either a
8031 * ni_frame_t data frame or ni_packet_t data packet to
8032 * send
8033 * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER
8034 * If NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER is specified,
8035 * hw descriptor info will be stored in p_data ni_frame
8036 * \return On success
8037 * Total number of bytes read
8038 * On failure
8039 * NI_RETCODE_INVALID_PARAM
8040 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8041 * NI_RETCODE_ERROR_INVALID_SESSION
8042 ******************************************************************************/
8044 {
8045  ni_log2(p_ctx, NI_LOG_DEBUG, "%s start\n", __func__);
8047  if ((!p_ctx) || (!p_data))
8048  {
8049  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8050  __func__);
8051  return NI_RETCODE_INVALID_PARAM;
8052  }
8053 
8054  // Here check if keep alive thread is closed.
8055 #ifdef _WIN32
8056  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
8058 #else
8059  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
8061 #endif
8062  {
8063  ni_log2(p_ctx, NI_LOG_ERROR,
8064  "ERROR: %s() keep alive thread has been closed, "
8065  "hw:%d, session:%d\n",
8066  __func__, p_ctx->hw_id, p_ctx->session_id);
8068  }
8069 
8070  ni_pthread_mutex_lock(&p_ctx->mutex);
8071  // In close state, let the close process execute first.
8072  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
8073  {
8074  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
8075  ni_pthread_mutex_unlock(&p_ctx->mutex);
8076  ni_usleep(100);
8078  }
8080  ni_pthread_mutex_unlock(&p_ctx->mutex);
8081 
8082  switch (device_type)
8083  {
8085  {
8086  int seq_change_read_count = 0;
8087  p_data->data.frame.src_codec = p_ctx->codec_format;
8088  for (;;)
8089  {
8090  //retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
8091  retval = ni_decoder_session_read_desc(p_ctx, &(p_data->data.frame));
8092  // check resolution change only after initial setting obtained
8093  // p_data->data.frame.video_width is picture width and will be 32-align
8094  // adjusted to frame size; p_data->data.frame.video_height is the same as
8095  // frame size, then compare them to saved one for resolution checking
8096  //
8097  uint32_t aligned_width;
8098  if(QUADRA)
8099  {
8100  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
8101  }
8102  else
8103  {
8104  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
8105  }
8106 
8107  ni_log2(p_ctx, NI_LOG_DEBUG,
8108  "FNum %" PRIu64
8109  ", DFVWxDFVH %u x %u, AlWid %u, AVW x AVH %u x %u\n",
8110  p_ctx->frame_num, p_data->data.frame.video_width,
8111  p_data->data.frame.video_height, aligned_width,
8112  p_ctx->active_video_width, p_ctx->active_video_height);
8113 
8114  if (0 == retval && seq_change_read_count)
8115  {
8116  ni_log2(p_ctx, NI_LOG_DEBUG, "%s (decoder): seq change NO data, next time.\n",
8117  __func__);
8118  p_ctx->active_video_width = 0;
8119  p_ctx->active_video_height = 0;
8120  p_ctx->actual_video_width = 0;
8121  break;
8122  }
8123  else if (retval < 0)
8124  {
8125  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
8126  __func__, retval);
8127  break;
8128  }
8129  // aligned_width may equal to active_video_width if bit depth and width
8130  // are changed at the same time. So, check video_width != actual_video_width.
8131  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
8132  (p_data->data.frame.video_width &&
8133  p_data->data.frame.video_height &&
8134  (aligned_width != p_ctx->active_video_width ||
8135  p_data->data.frame.video_height != p_ctx->active_video_height))))
8136  {
8137  ni_log2(
8138  p_ctx, NI_LOG_DEBUG,
8139  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
8140  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
8141  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
8142  aligned_width, p_data->data.frame.video_height,
8143  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
8144  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
8145  // reset active video resolution to 0 so it can be queried in the re-read
8146  p_ctx->active_video_width = 0;
8147  p_ctx->active_video_height = 0;
8148  p_ctx->actual_video_width = 0;
8149  seq_change_read_count++;
8150  //break;
8151  }
8152  else
8153  {
8154  break;
8155  }
8156  }
8157  break;
8158  }
8160  {
8161  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Encoder has no hwdesc to read\n");
8162  return NI_RETCODE_INVALID_PARAM;
8163  }
8164 
8165  case NI_DEVICE_TYPE_SCALER:
8166  {
8167  retval = ni_scaler_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8168  break;
8169  }
8170 
8171  case NI_DEVICE_TYPE_AI:
8172  {
8173  retval = ni_ai_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8174  break;
8175  }
8176 
8177  default:
8178  {
8179  retval = NI_RETCODE_INVALID_PARAM;
8180  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
8181  __func__, device_type);
8182  break;
8183  }
8184  }
8185 
8186  ni_pthread_mutex_lock(&p_ctx->mutex);
8188  ni_pthread_mutex_unlock(&p_ctx->mutex);
8189 
8190  return retval;
8191 }
8192 
8193 /*!*****************************************************************************
8194 * \brief Reads YUV data from hw descriptor stored location on device
8195 *
8196 * \param[in] p_ctx Pointer to a caller allocated
8197 * ni_session_context_t struct
8198 * \param[in] p_data Pointer to a caller allocated
8199 * ni_session_data_io_t struct which contains either a
8200 * ni_frame_t data frame or ni_packet_t data packet to
8201 * send
8202 * \param[in] hwdesc HW descriptor to find frame in XCODER
8203 * \return On success
8204 * Total number of bytes read
8205 * On failure
8206 * NI_RETCODE_INVALID_PARAM
8207 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8208 * NI_RETCODE_ERROR_INVALID_SESSION
8209 *******************************************************************************/
8211 {
8213  if ((!hwdesc) || (!p_data))
8214  {
8215  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8216  __func__);
8217  return NI_RETCODE_INVALID_PARAM;
8218  }
8219 
8220  /* download by frameidx */
8221  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rd") >= 0))
8222  {
8223  if(hwdesc->ui16FrameIdx == 0)
8224  {
8225  ni_log(NI_LOG_ERROR, "%s(): Invaild frame index\n", __func__);
8226  return NI_RETCODE_INVALID_PARAM;
8227  }
8228  retval = ni_hwdownload_by_frame_idx(hwdesc, &(p_data->data.frame), p_ctx->is_auto_dl);
8229  } else {
8230  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
8231  {
8232  if (p_ctx->pext_mutex == &(p_ctx->mutex))
8233  {
8234  ni_log(NI_LOG_ERROR, "ERROR %s(): Invalid session\n",
8235  __func__);
8237  }
8238  }
8239 
8241  bool use_external_mutex = false;
8242  uint32_t orig_session_id = p_ctx->session_id;
8243  ni_device_handle_t orig_blk_io_handle = p_ctx->blk_io_handle;
8244  uint32_t orig_codec_format = p_ctx->codec_format;
8245  int orig_bit_depth_factor = p_ctx->bit_depth_factor;
8246  int orig_hw_action = p_ctx->hw_action;
8247 
8248  ni_pthread_mutex_t *p_ctx_mutex = &(p_ctx->mutex);
8249  if ((p_ctx_mutex != p_ctx->pext_mutex) ||
8252  "6r8") < 0)
8253  {
8254  use_external_mutex = true;
8255  p_ctx->session_id = hwdesc->ui16session_ID;
8256  p_ctx->blk_io_handle = (ni_device_handle_t)(int64_t)hwdesc->device_handle;
8257  p_ctx->codec_format = NI_CODEC_FORMAT_H264; //unused
8258  p_ctx->bit_depth_factor = (int)hwdesc->bit_depth;
8260  }
8261 
8263 
8264  retval = ni_hwdownload_session_read(p_ctx, &(p_data->data.frame), hwdesc); //cut me down as needed
8265 
8267  if (use_external_mutex)
8268  {
8269  p_ctx->session_id = orig_session_id;
8270  p_ctx->blk_io_handle = orig_blk_io_handle;
8271  p_ctx->codec_format = orig_codec_format;
8272  p_ctx->bit_depth_factor = orig_bit_depth_factor;
8273  p_ctx->hw_action = orig_hw_action;
8274  }
8276  }
8277 
8278  return retval;
8279 }
8280 
8281 /*!*****************************************************************************
8282 * \brief Query the session if a buffer is available
8283 *
8284 * \param[in] p_ctx Pointer to a caller allocated
8285 * ni_session_context_t struct
8286 * [in] device_type Quadra device type
8287 *
8288 * \return On success
8289 * NI_RETCODE_SUCCESS
8290 * On failure
8291 * NI_RETCODE_INVALID_PARAM
8292 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8293 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8294 * NI_RETCODE_ERROR_INVALID_SESSION
8295 *******************************************************************************/
8297  ni_device_type_t device_type)
8298 {
8300 
8301  if (!p_ctx)
8302  {
8303  ni_log(NI_LOG_ERROR, "ERROR: No session\n");
8304  return NI_RETCODE_INVALID_PARAM;
8305  }
8306 
8307  if (ni_cmp_fw_api_ver(
8308  (char *) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
8309  "6rt") < 0)
8310  {
8311  ni_log2(p_ctx, NI_LOG_DEBUG,
8312  "%s function not supported in FW API version < 6rt\n",
8313  __func__);
8315  }
8316 
8317  switch (device_type)
8318  {
8319  case NI_DEVICE_TYPE_UPLOAD:
8320  ni_pthread_mutex_lock(&p_ctx->mutex);
8322 
8324 
8326  ni_pthread_mutex_unlock(&p_ctx->mutex);
8327  break;
8328 
8329  case NI_DEVICE_TYPE_SCALER:
8330  ni_pthread_mutex_lock(&p_ctx->mutex);
8332 
8333  retval = ni_scaler_session_query_buffer_avail(p_ctx);
8334 
8336  ni_pthread_mutex_unlock(&p_ctx->mutex);
8337  break;
8338 
8339  default:
8340  break;
8341  }
8342 
8343  return retval;
8344 }
8345 
8346 /*!*****************************************************************************
8347 * \brief Sends raw YUV input to uploader instance and retrieves a HW descriptor
8348 * to represent it
8349 *
8350 * \param[in] p_ctx Pointer to a caller allocated
8351 * ni_session_context_t struct
8352 * \param[in] p_src_data Pointer to a caller allocated
8353 * ni_session_data_io_t struct which contains a
8354 * ni_frame_t data frame to send to uploader
8355 * \param[out] hwdesc HW descriptor to find frame in XCODER
8356 * \return On success
8357 * Total number of bytes read
8358 * On failure
8359 * NI_RETCODE_INVALID_PARAM
8360 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8361 * NI_RETCODE_ERROR_INVALID_SESSION
8362 *******************************************************************************/
8364 {
8366  if ((!hwdesc) || (!p_src_data))
8367  {
8368  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8369  __func__);
8370  return NI_RETCODE_INVALID_PARAM;
8371  }
8372  ni_pthread_mutex_lock(&p_ctx->mutex);
8374 
8375  retval = ni_hwupload_session_write(p_ctx, &p_src_data->data.frame, hwdesc);
8376 
8378  ni_pthread_mutex_unlock(&p_ctx->mutex);
8379 
8380  return retval;
8381 }
8382 
8383 /*!*****************************************************************************
8384 * \brief Allocate memory for the hwDescriptor buffer based on provided
8385 * parameters taking into account pic size and extra data.
8386 *
8387 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
8388 *
8389 * \param[in] video_width Width of the video frame
8390 * \param[in] video_height Height of the video frame
8391 * \param[in] extra_len Extra data size (incl. meta data)
8392 *
8393 * \return On success
8394 * NI_RETCODE_SUCCESS
8395 * On failure
8396 * NI_RETCODE_INVALID_PARAM
8397 * NI_RETCODE_ERROR_MEM_ALOC
8398 *****************************************************************************/
8400  int video_height, int extra_len)
8401 {
8402  void* p_buffer = NULL;
8403  int height_aligned = video_height;
8404  int retval = NI_RETCODE_SUCCESS;
8405 
8406  if (!p_frame)
8407  {
8408  ni_log(NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8409  __func__);
8410  return NI_RETCODE_INVALID_PARAM;
8411  }
8412 
8413  ni_log(NI_LOG_DEBUG, "%s: extra_len=%d\n", __func__, extra_len);
8414 
8415  int buffer_size = (int)sizeof(niFrameSurface1_t) + extra_len;
8416 
8417  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
8418 
8419  //Check if Need to free
8420  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
8421  {
8422  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
8423  __func__, p_frame->buffer_size);
8424  ni_frame_buffer_free(p_frame);
8425  }
8426 
8427  //Check if need to realocate
8428  if (p_frame->buffer_size != buffer_size)
8429  {
8430  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
8431  {
8432  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
8433  NI_ERRNO, __func__);
8434  retval = NI_RETCODE_ERROR_MEM_ALOC;
8435  LRETURN;
8436  }
8437 
8438  // init once after allocation
8439  memset(p_buffer, 0, buffer_size);
8440  p_frame->buffer_size = buffer_size;
8441  p_frame->p_buffer = p_buffer;
8442 
8443  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
8444  }
8445  else
8446  {
8447  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
8448  }
8449 
8450  p_frame->p_data[3] = p_frame->p_buffer;
8451  p_frame->p_data[0] = NULL;
8452  p_frame->p_data[1] = NULL;
8453  p_frame->p_data[2] = NULL;
8454 
8455  p_frame->data_len[0] = 0;//luma_size;
8456  p_frame->data_len[1] = 0;//chroma_b_size;
8457  p_frame->data_len[2] = 0;//chroma_r_size;
8458  p_frame->data_len[3] = sizeof(niFrameSurface1_t);
8459 
8460  p_frame->video_width = video_width;
8461  p_frame->video_height = height_aligned;
8462 
8463  ((niFrameSurface1_t*)p_frame->p_data[3])->device_handle = (int32_t)NI_INVALID_DEVICE_HANDLE;
8464 
8465  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
8466  p_frame->buffer_size);
8467 
8468 END:
8469 
8470  if (NI_RETCODE_SUCCESS != retval)
8471  {
8472  ni_aligned_free(p_buffer);
8473  }
8474 
8475  return retval;
8476 }
8477 
8478 /*!*****************************************************************************
8479 * \brief Recycle a frame buffer on card
8480 *
8481 * \param[in] surface Struct containing device and frame location to clear out
8482 * \param[in] device_handle handle to access device memory buffer is stored in
8483 *
8484 * \return On success NI_RETCODE_SUCCESS
8485 * On failure NI_RETCODE_INVALID_PARAM
8486 *******************************************************************************/
8488  int32_t device_handle)
8489 {
8491 
8492  if (surface)
8493  {
8494  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8496  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8497  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8498  device_handle);
8499  retval = ni_clear_instance_buf(surface);
8500  }
8501  else
8502  {
8503  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8504  }
8505 
8506  return retval;
8507 }
8508 
8509 /*!*****************************************************************************
8510 * \brief Recycle a frame buffer on card, only hwframe descriptor is needed
8511 *
8512 * \param[in] surface Struct containing device and frame location to clear out
8513 *
8514 * \return On success NI_RETCODE_SUCCESS
8515 * On failure NI_RETCODE_INVALID_PARAM
8516 *******************************************************************************/
8518 {
8520  int32_t saved_dma_buf_fd;
8521  if (surface)
8522  {
8523  if(surface->ui16FrameIdx == 0)
8524  {
8525  ni_log(NI_LOG_DEBUG, "%s(): Invaild frame index\n", __func__);
8526  return retval;
8527  }
8528  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8530  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8531  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8532  surface->device_handle);
8533  retval = ni_clear_instance_buf(surface);
8534  saved_dma_buf_fd = surface->dma_buf_fd;
8535  memset(surface, 0, sizeof(niFrameSurface1_t));
8536  surface->dma_buf_fd = saved_dma_buf_fd;
8537  }
8538  else
8539  {
8540  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8541  retval = NI_RETCODE_INVALID_PARAM;
8542  }
8543 
8544  return retval;
8545 }
8546 
8547 /*!*****************************************************************************
8548 * \brief Sends frame pool setup info to device
8549 *
8550 * \param[in] p_ctx Pointer to a caller allocated
8551 * ni_session_context_t struct
8552 * \param[in] pool_size Upload session initial allocated frames count
8553 * must be > 0,
8554 * \param[in] pool 0 use the normal pool
8555 * 1 use a dedicated P2P pool
8556 *
8557 * \return On success Return code
8558 * On failure
8559 * NI_RETCODE_INVALID_PARAM
8560 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8561 * NI_RETCODE_ERROR_INVALID_SESSION
8562 * NI_RETCODE_ERROR_MEM_ALOC
8563 *******************************************************************************/
8565  uint32_t pool_size, uint32_t pool)
8566 {
8568  if (!p_ctx)
8569  {
8570  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8571  __func__);
8572  return NI_RETCODE_INVALID_PARAM;
8573  }
8574  if (pool_size == 0 || pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8575  {
8576  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Invalid poolsize == 0 or > 100\n");
8577  return NI_RETCODE_INVALID_PARAM;
8578  }
8579  if (pool & NI_UPLOADER_FLAG_LM)
8580  {
8581  ni_log2(p_ctx, NI_LOG_DEBUG, "uploader buffer acquisition is limited!\n");
8582  }
8583  ni_pthread_mutex_lock(&p_ctx->mutex);
8585 
8586  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, pool);
8587 
8589  ni_pthread_mutex_unlock(&p_ctx->mutex);
8590 
8591  return retval;
8592 }
8593 
8594 /*!*****************************************************************************
8595 * \brief Sends frame pool change info to device
8596 *
8597 * \param[in] p_ctx Pointer to a caller allocated
8598 * ni_session_context_t struct
8599 * \param[in] pool_size if pool_size = 0, free allocated device memory buffers
8600 * if pool_size > 0, expand device frame buffer pool of
8601 * current instance with pool_size more frame buffers
8602 *
8603 * \return On success Return code
8604 * On failure
8605 * NI_RETCODE_FAILURE
8606 * NI_RETCODE_INVALID_PARAM
8607 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8608 * NI_RETCODE_ERROR_INVALID_SESSION
8609 * NI_RETCODE_ERROR_MEM_ALOC
8610 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8611 *******************************************************************************/
8613  uint32_t pool_size)
8614 {
8616  if (!p_ctx)
8617  {
8618  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8619  __func__);
8620  return NI_RETCODE_INVALID_PARAM;
8621  }
8622  if (ni_cmp_fw_api_ver(
8624  "6r3") < 0)
8625  {
8626  ni_log2(p_ctx, NI_LOG_ERROR,
8627  "ERROR: %s function not supported in FW API version < 6r3\n",
8628  __func__);
8630  }
8631  if (p_ctx->pool_type == NI_POOL_TYPE_NONE)
8632  {
8633  ni_log2(p_ctx, NI_LOG_ERROR,
8634  "ERROR: can't free or expand framepool of session 0x%x "
8635  "before init framepool\n", p_ctx->session_id);
8636  return NI_RETCODE_FAILURE;
8637  }
8638  if (pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8639  {
8640  ni_log2(p_ctx, NI_LOG_ERROR,
8641  "ERROR: Invalid poolsize > %u\n", NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL);
8642  return NI_RETCODE_INVALID_PARAM;
8643  }
8644  if (pool_size == 0)
8645  {
8646  ni_log2(p_ctx, NI_LOG_INFO, "Free frame pool of session 0x%x\n", p_ctx->session_id);
8647  }
8648 
8649  ni_pthread_mutex_lock(&p_ctx->mutex);
8651 
8652  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, p_ctx->pool_type);
8653 
8655  ni_pthread_mutex_unlock(&p_ctx->mutex);
8656 
8657  return retval;
8658 }
8659 
8660 /*!*****************************************************************************
8661  * \brief Set parameters on the device for the 2D engine
8662  *
8663  * \param[in] p_ctx pointer to session context
8664  * \param[in] p_params pointer to scaler parameters
8665  *
8666  * \return NI_RETCODE_INVALID_PARAM
8667  * NI_RETCODE_ERROR_INVALID_SESSION
8668  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8669  * NI_RETCODE_ERROR_MEM_ALOC
8670  ******************************************************************************/
8672  ni_scaler_params_t *p_params)
8673 {
8675 
8676  if (!p_ctx || !p_params)
8677  {
8678  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8679  __func__);
8680  return NI_RETCODE_INVALID_PARAM;
8681  }
8682  ni_pthread_mutex_lock(&p_ctx->mutex);
8684 
8685  retval = ni_config_instance_set_scaler_params(p_ctx, p_params);
8686 
8688  ni_pthread_mutex_unlock(&p_ctx->mutex);
8689 
8690  return retval;
8691 }
8692 
8693 /*!******************************************************************************
8694  * \brief Send a p_config command to configure scaling drawbox parameters.
8695  *
8696  * \param ni_session_context_t p_ctx - xcoder Context
8697  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_drawbox params_t struct
8698  *
8699  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
8700 *******************************************************************************/
8702  ni_scaler_drawbox_params_t *p_params)
8703 {
8704  void *p_scaler_config = NULL;
8705  uint32_t buffer_size = sizeof(ni_scaler_multi_drawbox_params_t);
8707  uint32_t ui32LBA = 0;
8708 
8709  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
8710 
8711  if (!p_ctx || !p_params)
8712  {
8713  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
8714  retval = NI_RETCODE_INVALID_PARAM;
8715  LRETURN;
8716  }
8717 
8718  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
8719  {
8720  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
8722  LRETURN;
8723  }
8724 
8725  buffer_size =
8726  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
8728  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
8729  {
8730  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
8731  NI_ERRNO, __func__);
8732  retval = NI_RETCODE_ERROR_MEM_ALOC;
8733  LRETURN;
8734  }
8735  memset(p_scaler_config, 0, buffer_size);
8736 
8737  //configure the session here
8740 
8741  memcpy(p_scaler_config, p_params, buffer_size);
8742 
8744  p_scaler_config, buffer_size, ui32LBA) < 0)
8745  {
8746  ni_log2(p_ctx, NI_LOG_ERROR,
8747  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
8748  ", hw_id, %d, xcoder_inst_id: %d\n",
8749  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
8750  // Close the session since we can't configure it as per fw
8751  retval = ni_scaler_session_close(p_ctx, 0);
8752  if (NI_RETCODE_SUCCESS != retval)
8753  {
8754  ni_log2(p_ctx, NI_LOG_ERROR,
8755  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
8756  "hw_id, %d, xcoder_inst_id: %d\n",
8757  __func__,
8758  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
8759  p_ctx->session_id);
8760  }
8761 
8763  }
8764 
8765 END:
8766 
8767  ni_aligned_free(p_scaler_config);
8768  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
8769 
8770  return retval;
8771 }
8772 
8773 /*!******************************************************************************
8774  * \brief Send a p_config command to configure scaling watermark parameters.
8775  *
8776  * \param ni_session_context_t p_ctx - xcoder Context
8777  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_watermark_params_t struct
8778  *
8779  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
8780 *******************************************************************************/
8782  ni_scaler_watermark_params_t *p_params)
8783 {
8784  void *p_scaler_config = NULL;
8785  uint32_t buffer_size = sizeof(ni_scaler_multi_watermark_params_t);
8787  uint32_t ui32LBA = 0;
8788 
8789  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
8790 
8791  if (!p_ctx || !p_params)
8792  {
8793  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
8794  retval = NI_RETCODE_INVALID_PARAM;
8795  LRETURN;
8796  }
8797 
8798  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
8799  {
8800  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
8802  LRETURN;
8803  }
8804 
8805  buffer_size =
8806  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
8808  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
8809  {
8810  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
8811  NI_ERRNO, __func__);
8812  retval = NI_RETCODE_ERROR_MEM_ALOC;
8813  LRETURN;
8814  }
8815  memset(p_scaler_config, 0, buffer_size);
8816 
8817  //configure the session here
8820 
8821  memcpy(p_scaler_config, p_params, buffer_size);
8822 
8824  p_scaler_config, buffer_size, ui32LBA) < 0)
8825  {
8826  ni_log2(p_ctx, NI_LOG_ERROR,
8827  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
8828  ", hw_id, %d, xcoder_inst_id: %d\n",
8829  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
8830  // Close the session since we can't configure it as per fw
8831  retval = ni_scaler_session_close(p_ctx, 0);
8832  if (NI_RETCODE_SUCCESS != retval)
8833  {
8834  ni_log2(p_ctx, NI_LOG_ERROR,
8835  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
8836  "hw_id, %d, xcoder_inst_id: %d\n",
8837  __func__,
8838  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
8839  p_ctx->session_id);
8840  }
8841 
8843  }
8844 
8845 END:
8846 
8847  ni_aligned_free(p_scaler_config);
8848  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
8849 
8850  return retval;
8851 }
8852 
8853 
8854 /*!*****************************************************************************
8855  * \brief Allocate a frame on the device for 2D engine or AI engine
8856  * to work on based on provided parameters
8857  *
8858  * \param[in] p_ctx pointer to session context
8859  * \param[in] width width, in pixels
8860  * \param[in] height height, in pixels
8861  * \param[in] format pixel format
8862  * \param[in] options options bitmap flags, bit 0 (NI_SCALER_FLAG_IO) is
8863  * 0=input frame or 1=output frame. Bit 1 (NI_SCALER_FLAG_PC) is
8864  * 0=single allocation, 1=create pool. Bit 2 (NI_SCALER_FLAG_PA) is
8865  * 0=straight alpha, 1=premultiplied alpha
8866  * \param[in] rectangle_width clipping rectangle width
8867  * \param[in] rectangle_height clipping rectangle height
8868  * \param[in] rectangle_x horizontal position of clipping rectangle
8869  * \param[in] rectangle_y vertical position of clipping rectangle
8870  * \param[in] rgba_color RGBA fill colour (for padding only)
8871  * \param[in] frame_index input hwdesc index
8872  * \param[in] device_type only NI_DEVICE_TYPE_SCALER
8873  * and NI_DEVICE_TYPE_AI (only needs p_ctx and frame_index)
8874  *
8875  * \return NI_RETCODE_INVALID_PARAM
8876  * NI_RETCODE_ERROR_INVALID_SESSION
8877  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8878  * NI_RETCODE_ERROR_MEM_ALOC
8879  ******************************************************************************/
8881  int width,
8882  int height,
8883  int format,
8884  int options,
8885  int rectangle_width,
8886  int rectangle_height,
8887  int rectangle_x,
8888  int rectangle_y,
8889  int rgba_color,
8890  int frame_index,
8891  ni_device_type_t device_type)
8892 {
8894 
8895  if (!p_ctx)
8896  {
8897  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8898  __func__);
8899  return NI_RETCODE_INVALID_PARAM;
8900  }
8901  ni_pthread_mutex_lock(&p_ctx->mutex);
8903 
8904  switch (device_type)
8905  {
8906  case NI_DEVICE_TYPE_SCALER:
8907  retval = ni_scaler_alloc_frame(p_ctx,width, height, format, options,
8908  rectangle_width, rectangle_height,
8909  rectangle_x, rectangle_y,
8910  rgba_color, frame_index);
8911  break;
8912 
8913  case NI_DEVICE_TYPE_AI:
8914  retval = ni_ai_alloc_hwframe(p_ctx, width, height, options, rgba_color,
8915  frame_index);
8916  break;
8917 
8920  /* fall through */
8921 
8922  default:
8923  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
8924  retval = NI_RETCODE_INVALID_PARAM;
8925  break;
8926  }
8927 
8929  ni_pthread_mutex_unlock(&p_ctx->mutex);
8930 
8931  return retval;
8932 }
8933 
8934 /*!*****************************************************************************
8935  * \brief Allocate a frame on the device and return the frame index
8936  *
8937  * \param[in] p_ctx pointer to session context
8938  * \param[in] p_out_surface pointer to output frame surface
8939  * \param[in] device_type currently only NI_DEVICE_TYPE_AI
8940  *
8941  * \return NI_RETCODE_INVALID_PARAM
8942  * NI_RETCODE_ERROR_INVALID_SESSION
8943  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8944  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8945  * NI_RETCODE_ERROR_MEM_ALOC
8946  ******************************************************************************/
8948  niFrameSurface1_t *p_out_surface,
8949  ni_device_type_t device_type)
8950 {
8952 
8953  if (!p_ctx)
8954  {
8955  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, %p, return\n",
8956  __func__, p_ctx);
8957  return NI_RETCODE_INVALID_PARAM;
8958  }
8959  ni_pthread_mutex_lock(&p_ctx->mutex);
8961 
8962  switch (device_type)
8963  {
8964  case NI_DEVICE_TYPE_AI:
8965  retval = ni_ai_alloc_dst_frame(p_ctx, p_out_surface);
8966  break;
8967 
8968  case NI_DEVICE_TYPE_SCALER:
8971  /* fall through */
8972 
8973  default:
8974  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
8975  retval = NI_RETCODE_INVALID_PARAM;
8976  break;
8977  }
8978 
8980  ni_pthread_mutex_unlock(&p_ctx->mutex);
8981 
8982  return retval;
8983 }
8984 
8985 /*!*****************************************************************************
8986  * \brief Copy the data of src hwframe to dst hwframe
8987  *
8988  * \param[in] p_ctx pointer to session context
8989  * \param[in] p_frameclone_desc pointer to the frameclone descriptor
8990  *
8991  * \return NI_RETCODE_INVALID_PARAM
8992  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8993  * NI_RETCODE_ERROR_INVALID_SESSION
8994  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8995  * NI_RETCODE_ERROR_MEM_ALOC
8996  ******************************************************************************/
8998  ni_frameclone_desc_t *p_frameclone_desc)
8999 {
9001 
9002  if (!p_ctx)
9003  {
9004  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9005  __func__);
9006  return NI_RETCODE_INVALID_PARAM;
9007  }
9008 
9009  if (ni_cmp_fw_api_ver(
9011  "6rL") < 0)
9012  {
9013  ni_log2(p_ctx, NI_LOG_ERROR,
9014  "Error: %s function not supported on device with FW API version < 6rL\n",
9015  __func__);
9017  }
9018 
9019  ni_pthread_mutex_lock(&p_ctx->mutex);
9021  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
9022  {
9023  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n",
9024  __func__);
9026  LRETURN;
9027  }
9028 
9029  retval = ni_hwframe_clone(p_ctx, p_frameclone_desc);
9030 
9031 END:
9033  ni_pthread_mutex_unlock(&p_ctx->mutex);
9034 
9035  return retval;
9036 }
9037 
9038 /*!*****************************************************************************
9039  * \brief Configure the 2D engine to work based on provided parameters
9040  *
9041  * \param[in] p_ctx pointer to session context
9042  * \param[in] p_cfg pointer to frame configuration
9043  *
9044  * \return NI_RETCODE_INVALID_PARAM
9045  * NI_RETCODE_ERROR_INVALID_SESSION
9046  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9047  * NI_RETCODE_ERROR_MEM_ALOC
9048  ******************************************************************************/
9050  ni_frame_config_t *p_cfg)
9051 {
9053 
9054  if (!p_ctx || !p_cfg)
9055  {
9056  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9057  __func__);
9058  return NI_RETCODE_INVALID_PARAM;
9059  }
9060 
9061  ni_pthread_mutex_lock(&p_ctx->mutex);
9063 
9064  switch (p_ctx->device_type)
9065  {
9066  case NI_DEVICE_TYPE_SCALER:
9067  retval = ni_scaler_config_frame(p_ctx, p_cfg);
9068  break;
9069 
9070  default:
9071  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9072  retval = NI_RETCODE_INVALID_PARAM;
9073  break;
9074  }
9075 
9077  ni_pthread_mutex_unlock(&p_ctx->mutex);
9078 
9079  return retval;
9080 }
9081 
9082 /*!*****************************************************************************
9083  * \brief Configure the 2D engine to work based on provided parameters
9084  *
9085  * \param[in] p_ctx pointer to session context
9086  * \param[in] p_cfg_in pointer to input frame configuration
9087  * \param[in] numInCfgs number of input frame configurations
9088  * \param[in] p_cfg_out pointer to output frame configuration
9089  *
9090  * \return NI_RETCODE_INVALID_PARAM
9091  * NI_RETCODE_ERROR_INVALID_SESSION
9092  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9093  * NI_RETCODE_ERROR_MEM_ALOC
9094  ******************************************************************************/
9096  ni_frame_config_t p_cfg_in[],
9097  int numInCfgs,
9098  ni_frame_config_t *p_cfg_out)
9099 {
9101 
9102  if (!p_ctx || !p_cfg_in)
9103  {
9104  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9105  __func__);
9106  return NI_RETCODE_INVALID_PARAM;
9107  }
9108 
9109  ni_pthread_mutex_lock(&p_ctx->mutex);
9111 
9112  switch (p_ctx->device_type)
9113  {
9114  case NI_DEVICE_TYPE_SCALER:
9115  retval = ni_scaler_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9116  break;
9117 
9118  case NI_DEVICE_TYPE_AI:
9119  retval = ni_ai_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9120  break;
9121 
9122  default:
9123  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9124  retval = NI_RETCODE_INVALID_PARAM;
9125  break;
9126  }
9127 
9129  ni_pthread_mutex_unlock(&p_ctx->mutex);
9130 
9131  return retval;
9132 }
9133 
9134 /*!*****************************************************************************
9135  * \brief Calculate the total size of a frame based on the upload
9136  * context attributes and includes rounding up to the page size
9137  *
9138  * \param[in] p_upl_ctx pointer to an uploader session context
9139  * \param[in] linesize array of line stride
9140  *
9141  * \return size
9142  * NI_RETCODE_INVALID_PARAM
9143  *
9144  ******************************************************************************/
9146  const int linesize[])
9147 {
9148  int pixel_format;
9149  int width, height;
9150  int alignedh;
9151  int luma, chroma_b, chroma_r;
9152  int total;
9153 
9154  pixel_format = p_upl_ctx->pixel_format;
9155  width = p_upl_ctx->active_video_width;
9156  height = p_upl_ctx->active_video_height;
9157 
9158  switch (pixel_format)
9159  {
9160  case NI_PIX_FMT_YUV420P:
9162  case NI_PIX_FMT_NV12:
9163  case NI_PIX_FMT_P010LE:
9164  if (width < 0 || width > NI_MAX_RESOLUTION_WIDTH)
9165  {
9166  return NI_RETCODE_INVALID_PARAM;
9167  }
9168 
9169  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9170  {
9171  return NI_RETCODE_INVALID_PARAM;
9172  }
9173  break;
9174 
9175  case NI_PIX_FMT_RGBA:
9176  case NI_PIX_FMT_ABGR:
9177  case NI_PIX_FMT_ARGB:
9178  case NI_PIX_FMT_BGRA:
9179  case NI_PIX_FMT_BGR0:
9180  if ((width < 0) || (width > NI_MAX_RESOLUTION_WIDTH))
9181  {
9182  return NI_RETCODE_INVALID_PARAM;
9183  }
9184 
9185  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9186  {
9187  return NI_RETCODE_INVALID_PARAM;
9188  }
9189  break;
9190 
9191  default:
9192  return NI_RETCODE_INVALID_PARAM;
9193  }
9194 
9195  alignedh = NI_VPU_CEIL(height, 2);
9196 
9197  switch (pixel_format)
9198  {
9199  case NI_PIX_FMT_YUV420P:
9201  luma = linesize[0] * alignedh;
9202  chroma_b = linesize[1] * alignedh / 2;
9203  chroma_r = linesize[2] * alignedh / 2;
9204  total =
9205  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9206  break;
9207 
9208  case NI_PIX_FMT_NV12:
9209  case NI_PIX_FMT_P010LE:
9210  luma = linesize[0] * alignedh;
9211  chroma_b = linesize[1] * alignedh / 2;
9212  chroma_r = 0;
9213  total =
9214  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9215  break;
9216 
9217  case NI_PIX_FMT_RGBA:
9218  case NI_PIX_FMT_ABGR:
9219  case NI_PIX_FMT_ARGB:
9220  case NI_PIX_FMT_BGRA:
9221  case NI_PIX_FMT_BGR0:
9222  total = width * height * 4 + NI_APP_ENC_FRAME_META_DATA_SIZE;
9223  break;
9224 
9225  default:
9226  return NI_RETCODE_INVALID_PARAM;
9227  break;
9228  }
9229 
9231 
9232  return total;
9233 }
9234 
9235 /*!*****************************************************************************
9236  * \brief Allocate memory for the frame buffer based on provided parameters
9237  * taking into account the pixel format, width, height, stride,
9238  * alignment, and extra data
9239  * \param[in] p_frame Pointer to caller allocated ni_frame_t
9240  * \param[in] pixel_format a pixel format in ni_pix_fmt_t enum
9241  * \param[in] video_width width, in pixels
9242  * \param[in] video_height height, in pixels
9243  * \param[in] linesize horizontal stride
9244  * \param[in] alignment apply a 16 pixel height alignment (T408 only)
9245  * \param[in] extra_len meta data size
9246  *
9247  * \return NI_RETCODE_SUCCESS
9248  * NI_RETCODE_INVALID_PARAM
9249  * NI_RETCODE_ERROR_MEM_ALOC
9250  *
9251  ******************************************************************************/
9253  int video_width, int video_height,
9254  int linesize[], int alignment,
9255  int extra_len)
9256 {
9257  int buffer_size;
9258  void *p_buffer = NULL;
9259  int retval = NI_RETCODE_SUCCESS;
9260  int height_aligned;
9261  int luma_size = 0;
9262  int chroma_b_size = 0;
9263  int chroma_r_size = 0;
9264 
9265  if (!p_frame)
9266  {
9267  ni_log(NI_LOG_ERROR, "Invalid frame pointer\n");
9268  return NI_RETCODE_INVALID_PARAM;
9269  }
9270 
9271  switch (pixel_format)
9272  {
9273  case NI_PIX_FMT_YUV420P:
9275  case NI_PIX_FMT_NV12:
9276  case NI_PIX_FMT_P010LE:
9277  case NI_PIX_FMT_NV16:
9278  case NI_PIX_FMT_YUYV422:
9279  case NI_PIX_FMT_UYVY422:
9280  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9281  {
9282  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9283  video_width);
9284  return NI_RETCODE_INVALID_PARAM;
9285  }
9286 
9287  if ((video_height < 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9288  {
9289  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9290  video_width);
9291  return NI_RETCODE_INVALID_PARAM;
9292  }
9293  break;
9294 
9295  case NI_PIX_FMT_RGBA:
9296  case NI_PIX_FMT_BGRA:
9297  case NI_PIX_FMT_ARGB:
9298  case NI_PIX_FMT_ABGR:
9299  case NI_PIX_FMT_BGR0:
9300  case NI_PIX_FMT_BGRP:
9301  /*
9302  * For 2D engine using RGBA, the minimum width is 32. There is no
9303  * height restriction. The 2D engine supports a height/width of up to
9304  * 32K but but we will limit the max height and width to 8K.
9305  */
9306  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9307  {
9308  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9309  video_width);
9310  return NI_RETCODE_INVALID_PARAM;
9311  }
9312 
9313  if ((video_height <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9314  {
9315  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9316  video_height);
9317  return NI_RETCODE_INVALID_PARAM;
9318  }
9319  break;
9320 
9321  default:
9322  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n",pixel_format);
9323  return NI_RETCODE_INVALID_PARAM;
9324  }
9325 
9326  if (QUADRA)
9327  {
9328  /* Quadra requires an even-numbered height/width */
9329  height_aligned = NI_VPU_CEIL(video_height, 2);
9330  }
9331  else
9332  {
9333  height_aligned = NI_VPU_ALIGN8(video_height);
9334 
9335  if (alignment)
9336  {
9337  /* 16-pixel aligned pixel height for Quadra */
9338  height_aligned = NI_VPU_ALIGN16(video_height);
9339  }
9340  }
9341 
9342  switch (pixel_format)
9343  {
9344  case NI_PIX_FMT_YUV420P:
9346  luma_size = linesize[0] * height_aligned;
9347 
9348  if (QUADRA)
9349  {
9350  chroma_b_size = linesize[1] * height_aligned / 2;
9351  chroma_r_size = linesize[2] * height_aligned / 2;
9352  }
9353  else
9354  {
9355  chroma_b_size = luma_size / 4;
9356  chroma_r_size = luma_size / 4;
9357  }
9358  break;
9359 
9360  case NI_PIX_FMT_RGBA:
9361  case NI_PIX_FMT_BGRA:
9362  case NI_PIX_FMT_ARGB:
9363  case NI_PIX_FMT_ABGR:
9364  case NI_PIX_FMT_BGR0:
9365  luma_size = linesize[0] * video_height;
9366  chroma_b_size = 0;
9367  chroma_r_size = 0;
9368  break;
9369 
9370  case NI_PIX_FMT_NV12:
9371  case NI_PIX_FMT_P010LE:
9372  if (QUADRA)
9373  {
9374  luma_size = linesize[0] * height_aligned;
9375  chroma_b_size = linesize[1] * height_aligned / 2;
9376  chroma_r_size = 0;
9377  break;
9378  }
9379  case NI_PIX_FMT_NV16:
9380  if (QUADRA)
9381  {
9382  luma_size = linesize[0] * video_height;
9383  chroma_b_size = linesize[1] * video_height;
9384  chroma_r_size = 0;
9385  break;
9386  }
9387  case NI_PIX_FMT_YUYV422:
9388  case NI_PIX_FMT_UYVY422:
9389  if (QUADRA)
9390  {
9391  luma_size = linesize[0] * video_height;
9392  chroma_b_size = 0;
9393  chroma_r_size = 0;
9394  break;
9395  }
9396  case NI_PIX_FMT_BGRP:
9397  if (QUADRA)
9398  {
9399  luma_size = NI_VPU_ALIGN32(linesize[0] * video_height);
9400  chroma_b_size = NI_VPU_ALIGN32(linesize[1] * video_height);
9401  chroma_r_size = NI_VPU_ALIGN32(linesize[2] * video_height);
9402  break;
9403  }
9404  /*fall through*/
9405  default:
9406  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9407  return NI_RETCODE_INVALID_PARAM;
9408  }
9409 
9410  buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
9411 
9412  /* Allocate a buffer size that is page aligned for the host */
9413  buffer_size = NI_VPU_CEIL(buffer_size,NI_MEM_PAGE_ALIGNMENT) + NI_MEM_PAGE_ALIGNMENT;
9414 
9415  /* If this buffer has a different size, realloc a new buffer */
9416  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9417  {
9418  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9419  p_frame->buffer_size);
9420  ni_frame_buffer_free(p_frame);
9421  }
9422 
9423  if (p_frame->buffer_size != buffer_size)
9424  {
9425  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9426  {
9427  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9428  retval = NI_RETCODE_ERROR_MEM_ALOC;
9429  LRETURN;
9430  }
9431 
9432  memset(p_buffer, 0, buffer_size);
9433  p_frame->buffer_size = buffer_size;
9434  p_frame->p_buffer = p_buffer;
9435  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
9436  }
9437  else
9438  {
9439  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
9440  }
9441 
9442  switch (pixel_format)
9443  {
9444  case NI_PIX_FMT_YUV420P:
9446  p_frame->p_data[0] = p_frame->p_buffer;
9447  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
9448  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
9449  p_frame->p_data[3] = NULL;
9450 
9451  p_frame->data_len[0] = luma_size;
9452  p_frame->data_len[1] = chroma_b_size;
9453  p_frame->data_len[2] = chroma_r_size;
9454  p_frame->data_len[3] = 0;
9455  video_width = NI_VPU_ALIGN128(video_width);
9456  break;
9457 
9458  case NI_PIX_FMT_RGBA:
9459  case NI_PIX_FMT_BGRA:
9460  case NI_PIX_FMT_ARGB:
9461  case NI_PIX_FMT_ABGR:
9462  case NI_PIX_FMT_BGR0:
9463  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9464  p_frame->p_data[1] = NULL;
9465  p_frame->p_data[2] = NULL;
9466  p_frame->p_data[3] = NULL;
9467 
9468  p_frame->data_len[0] = luma_size;
9469  p_frame->data_len[1] = 0;
9470  p_frame->data_len[2] = 0;
9471  p_frame->data_len[3] = 0;
9472  video_width = NI_VPU_ALIGN16(video_width);
9473  break;
9474 
9475  case NI_PIX_FMT_NV12:
9476  case NI_PIX_FMT_P010LE:
9477  if (QUADRA)
9478  {
9479  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9480  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9481  p_frame->p_data[2] = NULL;
9482  p_frame->p_data[3] = NULL;
9483 
9484  p_frame->data_len[0] = luma_size;
9485  p_frame->data_len[1] = chroma_b_size;
9486  p_frame->data_len[2] = 0;
9487  p_frame->data_len[3] = 0;
9488 
9489  video_width = NI_VPU_ALIGN128(video_width);
9490  break;
9491  }
9492  case NI_PIX_FMT_NV16:
9493  if (QUADRA)
9494  {
9495  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9496  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9497  p_frame->p_data[2] = NULL;
9498  p_frame->p_data[3] = NULL;
9499 
9500  p_frame->data_len[0] = luma_size;
9501  p_frame->data_len[1] = chroma_b_size;
9502  p_frame->data_len[2] = 0;
9503  p_frame->data_len[3] = 0;
9504 
9505  video_width = NI_VPU_ALIGN64(video_width);
9506  break;
9507  }
9508 
9509  case NI_PIX_FMT_YUYV422:
9510  case NI_PIX_FMT_UYVY422:
9511  if (QUADRA)
9512  {
9513  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9514  p_frame->p_data[1] = NULL;
9515  p_frame->p_data[2] = NULL;
9516  p_frame->p_data[3] = NULL;
9517 
9518  p_frame->data_len[0] = luma_size;
9519  p_frame->data_len[1] = 0;
9520  p_frame->data_len[2] = 0;
9521  p_frame->data_len[3] = 0;
9522  video_width = NI_VPU_ALIGN16(video_width);
9523  break;
9524  }
9525  case NI_PIX_FMT_BGRP:
9526  if (QUADRA)
9527  {
9528  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9529  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9530  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + chroma_b_size;
9531  p_frame->p_data[3] = NULL;
9532 
9533  p_frame->data_len[0] = luma_size;
9534  p_frame->data_len[1] = chroma_b_size;
9535  p_frame->data_len[2] = chroma_r_size;
9536  p_frame->data_len[3] = 0;
9537  break;
9538  }
9539  /* fall through */
9540  default:
9541  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9542  retval = NI_RETCODE_INVALID_PARAM;
9543  LRETURN;
9544  }
9545 
9546  p_frame->video_width = video_width;
9547  p_frame->video_height = height_aligned;
9548 
9549  ni_log(NI_LOG_DEBUG, "%s success: w=%d; h=%d; aligned buffer size=%d\n",
9550  __func__, video_width, video_height, buffer_size);
9551 
9552 END:
9553 
9554  if (retval != NI_RETCODE_SUCCESS)
9555  {
9556  ni_aligned_free(p_buffer);
9557  }
9558 
9559  return retval;
9560 }
9561 
9563  ni_network_data_t *p_network,
9564  const char *file)
9565 {
9566  FILE *fp = NULL;
9567  struct stat file_stat;
9569  unsigned char *buffer = NULL;
9570 
9571  if (!p_ctx)
9572  {
9573  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9574  __func__);
9575  return NI_RETCODE_INVALID_PARAM;
9576  }
9577  ni_pthread_mutex_lock(&p_ctx->mutex);
9579  ni_pthread_mutex_unlock(&p_ctx->mutex);
9580 
9581  if (stat(file, &file_stat) != 0)
9582  {
9583  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to get network binary file stat, %s\n",
9584  __func__, strerror(NI_ERRNO));
9585  retval = NI_RETCODE_FAILURE;
9586  LRETURN;
9587  }
9588 
9589  if (file_stat.st_size == 0)
9590  {
9591  ni_log2(p_ctx, NI_LOG_ERROR, "%s: network binary size is null\n", __func__);
9592  retval = NI_RETCODE_FAILURE;
9593  LRETURN;
9594  }
9595 
9596  fp = fopen(file, "rb");
9597  if (!fp)
9598  {
9599  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to open network binary, %s\n", __func__,
9600  strerror(NI_ERRNO));
9601  retval = NI_RETCODE_FAILURE;
9602  LRETURN;
9603  }
9604 
9605  buffer = malloc(file_stat.st_size);
9606  if (!buffer)
9607  {
9608  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to alloate memory\n", __func__);
9609  retval = NI_RETCODE_ERROR_MEM_ALOC;
9610  LRETURN;
9611  }
9612 
9613  if (fread(buffer, file_stat.st_size, 1, fp) != 1)
9614  {
9615  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to read network binary\n", __func__);
9616  retval = NI_RETCODE_FAILURE;
9617  LRETURN;
9618  }
9619 
9620  retval =
9621  ni_config_instance_network_binary(p_ctx, buffer, file_stat.st_size);
9622  if (retval != NI_RETCODE_SUCCESS)
9623  {
9624  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9625  __func__, retval);
9626  LRETURN;
9627  }
9628 
9629  retval = ni_config_read_inout_layers(p_ctx, p_network);
9630  if (retval != NI_RETCODE_SUCCESS)
9631  {
9632  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9633  retval);
9634  }
9635 
9636 END:
9637 
9638  if (fp)
9639  {
9640  fclose(fp);
9641  }
9642  free(buffer);
9643 
9644  ni_pthread_mutex_lock(&p_ctx->mutex);
9646  ni_pthread_mutex_unlock(&p_ctx->mutex);
9647 
9648  return retval;
9649 }
9650 
9652  ni_network_data_t *p_network)
9653 {
9655 
9656  if (!p_ctx)
9657  {
9658  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9659  __func__);
9660  return NI_RETCODE_INVALID_PARAM;
9661  }
9662 
9663  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6ro") < 0))
9664  {
9665  ni_log2(p_ctx, NI_LOG_ERROR, "Error: hvsplus filter not supported on device with FW API version < 6ro\n");
9667  }
9668 
9669  ni_pthread_mutex_lock(&p_ctx->mutex);
9671  ni_pthread_mutex_unlock(&p_ctx->mutex);
9672 
9673  retval =
9674  ni_config_instance_hvsplus(p_ctx); //, buffer, file_stat.st_size);
9675  if (retval != NI_RETCODE_SUCCESS)
9676  {
9677  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9678  __func__, retval);
9679  LRETURN;
9680  }
9681 
9682  retval = ni_config_read_inout_layers(p_ctx, p_network);
9683  if (retval != NI_RETCODE_SUCCESS)
9684  {
9685  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9686  retval);
9687  }
9688 
9689 END:
9690 
9691  ni_pthread_mutex_lock(&p_ctx->mutex);
9693  ni_pthread_mutex_unlock(&p_ctx->mutex);
9694 
9695  return retval;
9696 }
9697 
9699  ni_network_data_t *p_network)
9700 {
9701  uint32_t buffer_size = 0;
9702  void *p_buffer = NULL;
9703  int retval = NI_RETCODE_SUCCESS;
9704  uint32_t i, this_size;
9705  ni_network_layer_info_t *p_linfo;
9706 
9707  if (!p_frame || !p_network)
9708  {
9709  ni_log(NI_LOG_ERROR, "Invalid frame or network layer pointer\n");
9710  return NI_RETCODE_INVALID_PARAM;
9711  }
9712 
9713  p_linfo = &p_network->linfo;
9714  for (i = 0; i < p_network->input_num; i++)
9715  {
9716  this_size = ni_ai_network_layer_size(&p_linfo->in_param[i]);
9717  this_size =
9718  (this_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
9719  if (p_network->inset[i].offset != buffer_size)
9720  {
9722  "ERROR: %s(): invalid buffer_size of network\n", __func__);
9723  return NI_RETCODE_INVALID_PARAM;
9724  }
9725  buffer_size += this_size;
9726  }
9727 
9728  /* fixed size */
9729  p_frame->data_len[0] = buffer_size;
9730 
9731  /* Allocate a buffer size that is page aligned for the host */
9732  buffer_size = (buffer_size + NI_MEM_PAGE_ALIGNMENT - 1) &
9733  ~(NI_MEM_PAGE_ALIGNMENT - 1);
9734 
9735  /* If this buffer has a different size, realloc a new buffer */
9736  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9737  {
9738  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9739  p_frame->buffer_size);
9740  ni_frame_buffer_free(p_frame);
9741  }
9742 
9743  if (p_frame->buffer_size != buffer_size)
9744  {
9745  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9746  {
9747  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9748  retval = NI_RETCODE_ERROR_MEM_ALOC;
9749  LRETURN;
9750  }
9751 
9752  // memset(p_buffer, 0, buffer_size);
9753  p_frame->buffer_size = buffer_size;
9754  p_frame->p_buffer = p_buffer;
9755  ni_log(NI_LOG_DEBUG, "%s(): allocated new p_frame buffer\n", __func__);
9756  } else
9757  {
9758  ni_log(NI_LOG_DEBUG, "%s(): reuse p_frame buffer\n", __func__);
9759  }
9760 
9761  p_frame->p_data[0] = p_frame->p_buffer;
9762  p_frame->p_data[1] = NULL;
9763  p_frame->p_data[2] = NULL;
9764  p_frame->p_data[3] = NULL;
9765 
9766  ni_log(NI_LOG_DEBUG, "%s() success: aligned buffer size=%u\n", __func__,
9767  buffer_size);
9768 
9769 END:
9770 
9771  if (retval != NI_RETCODE_SUCCESS)
9772  {
9773  ni_aligned_free(p_buffer);
9774  }
9775 
9776  return retval;
9777 }
9778 
9780  ni_network_data_t *p_network)
9781 {
9782  void *p_buffer = NULL;
9783  int retval = NI_RETCODE_SUCCESS;
9784  uint32_t buffer_size = 0;
9785  uint32_t i, data_size;
9786  ni_network_layer_info_t *p_linfo;
9787 
9788  if (!p_packet || !p_network)
9789  {
9790  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
9791  __func__);
9792  return NI_RETCODE_INVALID_PARAM;
9793  }
9794 
9795  p_linfo = &p_network->linfo;
9796  for (i = 0; i < p_network->output_num; i++)
9797  {
9798  data_size = ni_ai_network_layer_size(&p_linfo->out_param[i]);
9799  data_size =
9800  (data_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
9801  if (p_network->outset[i].offset != buffer_size)
9802  {
9804  "ERROR: %s(): invalid buffer_size of network\n", __func__);
9805  return NI_RETCODE_INVALID_PARAM;
9806  }
9807  buffer_size += data_size;
9808  }
9809  data_size = buffer_size;
9810 
9811  ni_log(NI_LOG_DEBUG, "%s(): packet_size=%u\n", __func__, buffer_size);
9812 
9813  if (buffer_size & (NI_MEM_PAGE_ALIGNMENT - 1))
9814  {
9815  buffer_size = (buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) &
9816  ~(NI_MEM_PAGE_ALIGNMENT - 1);
9817  }
9818 
9819  if (p_packet->buffer_size == buffer_size)
9820  {
9821  p_packet->p_data = p_packet->p_buffer;
9822  ni_log(NI_LOG_DEBUG, "%s(): reuse current p_packet buffer\n", __func__);
9823  LRETURN; //Already allocated the exact size
9824  } else if (p_packet->buffer_size > 0)
9825  {
9827  "%s(): free current p_packet, p_packet->buffer_size=%u\n",
9828  __func__, p_packet->buffer_size);
9829  ni_packet_buffer_free(p_packet);
9830  }
9831  ni_log(NI_LOG_DEBUG, "%s(): Allocating p_packet buffer, buffer_size=%u\n",
9832  __func__, buffer_size);
9833 
9834  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9835  {
9836  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
9837  NI_ERRNO, __func__);
9838  retval = NI_RETCODE_ERROR_MEM_ALOC;
9839  LRETURN;
9840  }
9841 
9842  p_packet->buffer_size = buffer_size;
9843  p_packet->p_buffer = p_buffer;
9844  p_packet->p_data = p_packet->p_buffer;
9845  p_packet->data_len = data_size;
9846 
9847 END:
9848 
9849  if (NI_RETCODE_SUCCESS != retval)
9850  {
9851  ni_aligned_free(p_buffer);
9852  }
9853 
9854  ni_log(NI_LOG_TRACE, "%s(): exit: p_packet->buffer_size=%u\n", __func__,
9855  p_packet->buffer_size);
9856 
9857  return retval;
9858 }
9859 
9860 /*!*****************************************************************************
9861  * \brief Reconfigure bitrate dynamically during encoding.
9862  *
9863  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
9864  * \param[in] bitrate Target bitrate to set
9865  *
9866  * \return On success NI_RETCODE_SUCCESS
9867  * On failure NI_RETCODE_INVALID_PARAM
9868  ******************************************************************************/
9870 {
9871  if (!p_ctx || bitrate < NI_MIN_BITRATE || bitrate > NI_MAX_BITRATE)
9872  {
9873  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid bitrate passed in %d\n",
9874  __func__, bitrate);
9875  return NI_RETCODE_INVALID_PARAM;
9876  }
9877  ni_pthread_mutex_lock(&p_ctx->mutex);
9879 
9880  if (p_ctx->target_bitrate > 0)
9881  {
9882  ni_log2(p_ctx, NI_LOG_DEBUG,
9883  "Warning: %s(): bitrate %d overwriting current one %d\n",
9884  __func__, bitrate, p_ctx->target_bitrate);
9885  }
9886 
9887  p_ctx->target_bitrate = bitrate;
9888 
9890  ni_pthread_mutex_unlock(&p_ctx->mutex);
9891 
9892  return NI_RETCODE_SUCCESS;
9893 }
9894 
9895 /*!*****************************************************************************
9896  * \brief Reconfigure intraPeriod dynamically during encoding.
9897  *
9898  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
9899  * \param[in] intra_period Target intra period to set
9900  *
9901  *
9902  * \return On success NI_RETCODE_SUCCESS
9903  * On failure NI_RETCODE_INVALID_PARAM
9904  *
9905  * NOTE - the frame upon which intra period is reconfigured is encoded as IDR frame
9906  * NOTE - reconfigure intra period is not allowed if intraRefreshMode is enabled or if gopPresetIdx is 1
9907  *
9908  ******************************************************************************/
9910  int32_t intra_period)
9911 {
9912  if (!p_ctx || intra_period < 0 || intra_period > 1024)
9913  {
9914  ni_log(NI_LOG_ERROR, "ERROR: %s(): invalid intraPeriod passed in %d\n",
9915  __func__, intra_period);
9916  return NI_RETCODE_INVALID_PARAM;
9917  }
9918  ni_pthread_mutex_lock(&p_ctx->mutex);
9920 
9921  if (p_ctx->reconfig_intra_period >= 0)
9922  {
9924  "Warning: %s(): intraPeriod %d overwriting current one %d\n",
9925  __func__, intra_period, p_ctx->reconfig_intra_period);
9926  }
9927 
9928  p_ctx->reconfig_intra_period = intra_period;
9929 
9931  ni_pthread_mutex_unlock(&p_ctx->mutex);
9932 
9933  return NI_RETCODE_SUCCESS;
9934 }
9935 
9936 /*!*****************************************************************************
9937  * \brief Reconfigure VUI HRD dynamically during encoding.
9938  *
9939  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
9940  * \param[in] bitrate Target bitrate to set
9941  *
9942  * \return On success NI_RETCODE_SUCCESS
9943  * On failure NI_RETCODE_INVALID_PARAM
9944  ******************************************************************************/
9946 {
9947  if (!p_ctx || vui->colorDescPresent < 0 || vui->colorDescPresent > 1)
9948  {
9949  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid colorDescPresent passed in %d\n",
9950  __func__, vui->colorDescPresent);
9951  return NI_RETCODE_INVALID_PARAM;
9952  }
9953 
9955  {
9956  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid aspect ratio passed in (%dx%d)\n",
9957  __func__, vui->aspectRatioWidth, vui->aspectRatioHeight);
9958  return NI_RETCODE_INVALID_PARAM;
9959  }
9960 
9961  if (vui->videoFullRange < 0 || vui->videoFullRange > 1)
9962  {
9963  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid videoFullRange passed in %d\n",
9964  __func__, vui->videoFullRange);
9965  return NI_RETCODE_INVALID_PARAM;
9966  }
9967 
9968  ni_pthread_mutex_lock(&p_ctx->mutex);
9970 
9971  p_ctx->vui.colorDescPresent = vui->colorDescPresent;
9972  p_ctx->vui.colorPrimaries = vui->colorPrimaries;
9973  p_ctx->vui.colorTrc = vui->colorTrc;
9974  p_ctx->vui.colorSpace = vui->colorSpace;
9975  p_ctx->vui.aspectRatioWidth = vui->aspectRatioWidth;
9976  p_ctx->vui.aspectRatioHeight = vui->aspectRatioHeight;
9977  p_ctx->vui.videoFullRange = vui->videoFullRange;
9978 
9980  ni_pthread_mutex_unlock(&p_ctx->mutex);
9981 
9982  return NI_RETCODE_SUCCESS;
9983 }
9984 
9985 /*!*****************************************************************************
9986  * \brief Force next frame to be IDR frame during encoding.
9987  *
9988  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
9989  *
9990  * \return On success NI_RETCODE_SUCCESS
9991  ******************************************************************************/
9993 {
9994  if (!p_ctx)
9995  {
9996  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9997  __func__);
9998  return NI_RETCODE_INVALID_PARAM;
9999  }
10000  ni_pthread_mutex_lock(&p_ctx->mutex);
10002 
10003  if (p_ctx->force_idr_frame)
10004  {
10005  ni_log2(p_ctx, NI_LOG_DEBUG, "Warning: %s(): already forcing IDR frame\n",
10006  __func__);
10007  }
10008 
10009  p_ctx->force_idr_frame = 1;
10010 
10012  ni_pthread_mutex_unlock(&p_ctx->mutex);
10013 
10014  return NI_RETCODE_SUCCESS;
10015 }
10016 
10017 /*!*****************************************************************************
10018  * \brief Set a frame's support of Long Term Reference frame during encoding.
10019  *
10020  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10021  * \param[in] ltr Pointer to struct specifying LTR support
10022  *
10023  * \return On success NI_RETCODE_SUCCESS
10024  * On failure NI_RETCODE_INVALID_PARAM
10025  ******************************************************************************/
10027 {
10028  if (!p_ctx)
10029  {
10030  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10031  __func__);
10032  return NI_RETCODE_INVALID_PARAM;
10033  }
10034  ni_pthread_mutex_lock(&p_ctx->mutex);
10035 
10039 
10040  ni_pthread_mutex_unlock(&p_ctx->mutex);
10041 
10042  return NI_RETCODE_SUCCESS;
10043 }
10044 
10045 /*!*****************************************************************************
10046  * \brief Set Long Term Reference interval
10047  *
10048  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10049  * \param[in] ltr_interval the new long term reference inteval value
10050  *
10051  * \return On success NI_RETCODE_SUCCESS
10052  * On failure NI_RETCODE_INVALID_PARAM
10053  ******************************************************************************/
10055  int32_t ltr_interval)
10056 {
10057  if (!p_ctx)
10058  {
10059  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10060  __func__);
10061  return NI_RETCODE_INVALID_PARAM;
10062  }
10063  ni_pthread_mutex_lock(&p_ctx->mutex);
10064 
10065  p_ctx->ltr_interval = ltr_interval;
10066 
10067  ni_pthread_mutex_unlock(&p_ctx->mutex);
10068 
10069  return NI_RETCODE_SUCCESS;
10070 }
10071 
10072 /*!*****************************************************************************
10073  * \brief Set frame reference invalidation
10074  *
10075  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10076  * \param[in] frame_num frame number after which all references shall be
10077  * invalidated
10078  *
10079  * \return On success NI_RETCODE_SUCCESS
10080  * On failure NI_RETCODE_INVALID_PARAM
10081  ******************************************************************************/
10083  int32_t frame_num)
10084 {
10085  if (!p_ctx)
10086  {
10087  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10088  __func__);
10089  return NI_RETCODE_INVALID_PARAM;
10090  }
10091  ni_pthread_mutex_lock(&p_ctx->mutex);
10092  p_ctx->ltr_frame_ref_invalid = frame_num;
10093  ni_pthread_mutex_unlock(&p_ctx->mutex);
10094 
10095  return NI_RETCODE_SUCCESS;
10096 }
10097 
10098 /*!*****************************************************************************
10099  * \brief Reconfigure framerate dynamically during encoding.
10100  *
10101  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10102  * \param[in] framerate Target framerate to set
10103  *
10104  * \return On success NI_RETCODE_SUCCESS
10105  * On failure NI_RETCODE_INVALID_PARAM
10106  ******************************************************************************/
10108  ni_framerate_t *framerate)
10109 {
10110  int32_t framerate_num = framerate->framerate_num;
10111  int32_t framerate_denom = framerate->framerate_denom;
10112  if (!p_ctx || framerate_num <= 0 || framerate_denom <= 0)
10113  {
10114  ni_log2(p_ctx, NI_LOG_ERROR,
10115  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10116  framerate_num, framerate_denom);
10117  return NI_RETCODE_INVALID_PARAM;
10118  }
10119 
10120  if ((framerate_num % framerate_denom) != 0)
10121  {
10122  uint32_t numUnitsInTick = 1000;
10123  framerate_num = framerate_num / framerate_denom;
10124  framerate_denom = numUnitsInTick + 1;
10125  framerate_num += 1;
10126  framerate_num *= numUnitsInTick;
10127  } else
10128  {
10129  framerate_num = framerate_num / framerate_denom;
10130  framerate_denom = 1;
10131  }
10132 
10133  if (((framerate_num + framerate_denom - 1) / framerate_denom) >
10135  {
10136  ni_log2(p_ctx, NI_LOG_ERROR,
10137  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10138  framerate->framerate_num, framerate->framerate_denom);
10139  return NI_RETCODE_INVALID_PARAM;
10140  }
10141 
10142  ni_pthread_mutex_lock(&p_ctx->mutex);
10144 
10145  if (p_ctx->framerate.framerate_num > 0)
10146  {
10147  ni_log2(p_ctx, NI_LOG_DEBUG,
10148  "Warning: %s(): framerate (%d/%d) overwriting current "
10149  "one (%d/%d)\n",
10150  __func__, framerate_num, framerate_denom,
10151  p_ctx->framerate.framerate_num,
10152  p_ctx->framerate.framerate_denom);
10153  }
10154 
10155  p_ctx->framerate.framerate_num = framerate_num;
10156  p_ctx->framerate.framerate_denom = framerate_denom;
10157 
10159  ni_pthread_mutex_unlock(&p_ctx->mutex);
10160 
10161  return NI_RETCODE_SUCCESS;
10162 }
10163 
10164 /*!*****************************************************************************
10165  * \brief Reconfigure maxFrameSize dynamically during encoding.
10166  *
10167  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10168  * \param[in] max_frame_size maxFrameSize to set
10169  *
10170  * \return On success NI_RETCODE_SUCCESS
10171  * On failure NI_RETCODE_INVALID_PARAM
10172  *
10173  * NOTE - maxFrameSize_Bytes value less than ((bitrate / 8) / framerate) will be rejected
10174  *
10175  ******************************************************************************/
10177 {
10178  ni_xcoder_params_t *api_param;
10179  int32_t bitrate, framerate_num, framerate_denom;
10180  uint32_t maxFrameSize = (uint32_t)max_frame_size / 2000;
10181  uint32_t min_maxFrameSize;
10182 
10183  if (!p_ctx || !p_ctx->p_session_config)
10184  {
10185  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10186  __func__);
10187  return NI_RETCODE_INVALID_PARAM;
10188  }
10189 
10190  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10191 
10192  if (!api_param->low_delay_mode)
10193  {
10194  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size is valid only when lowDelay mode is enabled\n",
10195  __func__, max_frame_size);
10196  return NI_RETCODE_INVALID_PARAM;
10197  }
10198 
10199  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10200 
10201  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10202  {
10203  framerate_num = p_ctx->framerate.framerate_num;
10204  framerate_denom = p_ctx->framerate.framerate_denom;
10205  }
10206  else
10207  {
10208  framerate_num = (int32_t) api_param->fps_number;
10209  framerate_denom = (int32_t) api_param->fps_denominator;
10210  }
10211 
10212  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10213 
10214  if (maxFrameSize < min_maxFrameSize)
10215  {
10216  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size %d is too small (invalid)\n",
10217  __func__, max_frame_size);
10218  return NI_RETCODE_INVALID_PARAM;
10219  }
10220  if (max_frame_size > NI_MAX_FRAME_SIZE) {
10221  max_frame_size = NI_MAX_FRAME_SIZE;
10222  }
10223 
10224  ni_pthread_mutex_lock(&p_ctx->mutex);
10226 
10227  if (p_ctx->max_frame_size > 0)
10228  {
10229  ni_log2(p_ctx, NI_LOG_DEBUG,
10230  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10231  __func__, max_frame_size, p_ctx->max_frame_size);
10232  }
10233 
10234  p_ctx->max_frame_size = max_frame_size;
10235 
10237  ni_pthread_mutex_unlock(&p_ctx->mutex);
10238 
10239  return NI_RETCODE_SUCCESS;
10240 }
10241 
10242 /*!*****************************************************************************
10243  * \brief Reconfigure min&max qp dynamically during encoding.
10244  *
10245  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10246  * \param[in] ni_rc_min_max_qp Target min&max qp to set
10247  *
10248  * \return On success NI_RETCODE_SUCCESS
10249  * On failure NI_RETCODE_INVALID_PARAM
10250  ******************************************************************************/
10252  ni_rc_min_max_qp *p_min_max_qp)
10253 {
10254  int32_t minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB;
10255 
10256  if (!p_ctx || !p_min_max_qp)
10257  {
10258  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_min_max_qp pointer\n",
10259  __func__);
10260  return NI_RETCODE_INVALID_PARAM;
10261  }
10262 
10263  minQpI = p_min_max_qp->minQpI;
10264  maxQpI = p_min_max_qp->maxQpI;
10265  maxDeltaQp = p_min_max_qp->maxDeltaQp;
10266  minQpPB = p_min_max_qp->minQpPB;
10267  maxQpPB = p_min_max_qp->maxQpPB;
10268 
10269  if (minQpI > maxQpI || minQpPB > maxQpPB ||
10270  maxQpI > 51 || minQpI < 0 || maxQpPB > 51 || minQpPB < 0)
10271  {
10272  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid qp setting <%d %d %d %d %d>\n",
10273  __func__, minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB);
10274  return NI_RETCODE_INVALID_PARAM;
10275  }
10276 
10277  ni_pthread_mutex_lock(&p_ctx->mutex);
10279 
10280  p_ctx->enc_change_params->minQpI = minQpI;
10281  p_ctx->enc_change_params->maxQpI = maxQpI;
10282  p_ctx->enc_change_params->maxDeltaQp = maxDeltaQp;
10283  p_ctx->enc_change_params->minQpPB = minQpPB;
10284  p_ctx->enc_change_params->maxQpPB = maxQpPB;
10285 
10287  ni_pthread_mutex_unlock(&p_ctx->mutex);
10288 
10289  return NI_RETCODE_SUCCESS;
10290 }
10291 
10292 /*!*****************************************************************************
10293  * \brief Reconfigure crf value dynamically during encoding.
10294  *
10295  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10296  * \param[in] crf crf value to reconfigure
10297  *
10298  * \return On success NI_RETCODE_SUCCESS
10299  * On failure NI_RETCODE_INVALID_PARAM
10300  ******************************************************************************/
10302  int32_t crf)
10303 {
10304  ni_xcoder_params_t *api_param;
10305 
10306  if (!p_ctx || !p_ctx->p_session_config)
10307  {
10308  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10309  __func__);
10310  return NI_RETCODE_INVALID_PARAM;
10311  }
10312 
10313  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10314 
10315  if (api_param->cfg_enc_params.crf < 0)
10316  {
10317  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %d is valid only in CRF mode\n",
10318  __func__, crf);
10319  return NI_RETCODE_INVALID_PARAM;
10320  }
10321 
10322  if (crf < 0 || crf > 51)
10323  {
10324  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %d is invalid (valid range in [0..51])\n",
10325  __func__, crf);
10326  return NI_RETCODE_INVALID_PARAM;
10327  }
10328 
10329  ni_pthread_mutex_lock(&p_ctx->mutex);
10330 
10332 
10333  if (p_ctx->reconfig_crf >= 0)
10334  {
10335  ni_log2(p_ctx, NI_LOG_DEBUG,
10336  "Warning: %s(): crf reconfig value %d overwriting current reconfig_crf %d\n",
10337  __func__, crf, p_ctx->reconfig_crf);
10338  }
10339 
10340  p_ctx->reconfig_crf = crf;
10341 
10343 
10344  ni_pthread_mutex_unlock(&p_ctx->mutex);
10345 
10346  return NI_RETCODE_SUCCESS;
10347 }
10348 
10349 /*!*****************************************************************************
10350  * \brief Reconfigure crf float point value dynamically during encoding.
10351  *
10352  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10353  * \param[in] crf crf float point value to reconfigure
10354  *
10355  * \return On success NI_RETCODE_SUCCESS
10356  * On failure NI_RETCODE_INVALID_PARAM
10357  ******************************************************************************/
10359  float crf)
10360 {
10361  ni_xcoder_params_t *api_param;
10362 
10363  if (!p_ctx || !p_ctx->p_session_config)
10364  {
10365  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10366  __func__);
10367  return NI_RETCODE_INVALID_PARAM;
10368  }
10369 
10370  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10371 
10372  if (api_param->cfg_enc_params.crfFloat < 0)
10373  {
10374  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %f is valid only in CRF mode\n",
10375  __func__, crf);
10376  return NI_RETCODE_INVALID_PARAM;
10377  }
10378 
10379  if (crf < 0.0 || crf > 51.0)
10380  {
10381  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %f is invalid (valid range in [0..51])\n",
10382  __func__, crf);
10383  return NI_RETCODE_INVALID_PARAM;
10384  }
10385 
10386  ni_pthread_mutex_lock(&p_ctx->mutex);
10387 
10389 
10390  if (p_ctx->reconfig_crf >= 0 || p_ctx->reconfig_crf_decimal > 0)
10391  {
10392  ni_log2(p_ctx, NI_LOG_DEBUG,
10393  "Warning: %s(): crf reconfig value %d overwriting current "
10394  "reconfig_crf %d, reconfig_crf_decimal %d\n", __func__,
10395  crf, p_ctx->reconfig_crf, p_ctx->reconfig_crf_decimal);
10396  }
10397 
10398  p_ctx->reconfig_crf = (int)crf;
10399  p_ctx->reconfig_crf_decimal = (int)((crf - (float)p_ctx->reconfig_crf) * 100);
10400 
10402 
10403  ni_pthread_mutex_unlock(&p_ctx->mutex);
10404 
10405  return NI_RETCODE_SUCCESS;
10406 }
10407 
10408 /*!*****************************************************************************
10409  * \brief Reconfigure vbv buffer size and vbv max rate dynamically during encoding.
10410  *
10411  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10412  * \param[in] vbvBufferSize Target vbvBufferSize to set
10413  * \param[in] vbvMaxRate Target vbvMaxRate to set
10414  *
10415  * \return On success NI_RETCODE_SUCCESS
10416  * On failure NI_RETCODE_INVALID_PARAM
10417  ******************************************************************************/
10419  int32_t vbvMaxRate, int32_t vbvBufferSize)
10420 {
10421  ni_xcoder_params_t *api_param;
10422  if (!p_ctx || !p_ctx->p_session_config)
10423  {
10424  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10425  __func__);
10426  return NI_RETCODE_INVALID_PARAM;
10427  }
10428  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
10429  {
10430  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): vbvBufferSize value %d\n",
10431  __func__, vbvBufferSize);
10432  return NI_RETCODE_INVALID_PARAM;
10433  }
10434  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10435  if (api_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < api_param->bitrate) {
10436  ni_log2(p_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
10437  vbvMaxRate, api_param->bitrate);
10438  return NI_RETCODE_INVALID_PARAM;
10439  }
10440  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
10441  ni_log2(p_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
10442  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
10443  vbvMaxRate);
10444  vbvMaxRate = 0;
10445  }
10446 
10447  ni_pthread_mutex_lock(&p_ctx->mutex);
10449 
10450  p_ctx->reconfig_vbv_buffer_size = vbvBufferSize;
10451  p_ctx->reconfig_vbv_max_rate = vbvMaxRate;
10452 
10454  ni_pthread_mutex_unlock(&p_ctx->mutex);
10455 
10456  return NI_RETCODE_SUCCESS;
10457 }
10458 
10459 /*!*****************************************************************************
10460  * \brief Reconfigure maxFrameSizeRatio dynamically during encoding.
10461  *
10462  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10463  * \param[in] max_frame_size_ratio maxFrameSizeRatio to set
10464  *
10465  * \return On success NI_RETCODE_SUCCESS
10466  * On failure NI_RETCODE_INVALID_PARAM
10467  ******************************************************************************/
10469 {
10470  ni_xcoder_params_t *api_param;
10471  int32_t bitrate, framerate_num, framerate_denom;
10472  uint32_t min_maxFrameSize, maxFrameSize;
10473 
10474  if (!p_ctx || !p_ctx->p_session_config)
10475  {
10476  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10477  __func__);
10478  return NI_RETCODE_INVALID_PARAM;
10479  }
10480 
10481  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10482 
10483  if (!api_param->low_delay_mode)
10484  {
10485  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio is valid only when lowDelay mode is enabled\n",
10486  __func__, max_frame_size_ratio);
10487  return NI_RETCODE_INVALID_PARAM;
10488  }
10489 
10490  if (max_frame_size_ratio < 1) {
10491  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio %d cannot < 1\n",
10492  max_frame_size_ratio);
10493  return NI_RETCODE_INVALID_PARAM;
10494  }
10495 
10496  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10497 
10498  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10499  {
10500  framerate_num = p_ctx->framerate.framerate_num;
10501  framerate_denom = p_ctx->framerate.framerate_denom;
10502  }
10503  else
10504  {
10505  framerate_num = (int32_t) api_param->fps_number;
10506  framerate_denom = (int32_t) api_param->fps_denominator;
10507  }
10508 
10509  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10510 
10511  maxFrameSize = min_maxFrameSize * max_frame_size_ratio > NI_MAX_FRAME_SIZE ?
10512  NI_MAX_FRAME_SIZE : min_maxFrameSize * max_frame_size_ratio;
10513 
10514  ni_pthread_mutex_lock(&p_ctx->mutex);
10516 
10517  if (p_ctx->max_frame_size > 0)
10518  {
10519  ni_log2(p_ctx, NI_LOG_DEBUG,
10520  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10521  __func__, maxFrameSize, p_ctx->max_frame_size);
10522  }
10523 
10524  p_ctx->max_frame_size = maxFrameSize;
10525 
10527  ni_pthread_mutex_unlock(&p_ctx->mutex);
10528 
10529  return NI_RETCODE_SUCCESS;
10530 }
10531 
10532 /*!*****************************************************************************
10533  * \brief Reconfigure sliceArg dynamically during encoding.
10534  *
10535  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10536  * \param[in] sliceArg the new sliceArg value
10537  *
10538  * \return On success NI_RETCODE_SUCCESS
10539  * On failure NI_RETCODE_INVALID_PARAM
10540  ******************************************************************************/
10542 {
10543  ni_xcoder_params_t *api_param;
10544  ni_encoder_cfg_params_t *p_enc;
10545 
10546  if (!p_ctx || !p_ctx->p_session_config)
10547  {
10548  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10549  __func__);
10550  return NI_RETCODE_INVALID_PARAM;
10551  }
10552 
10553  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10554  p_enc = &api_param->cfg_enc_params;
10555  if (p_enc->slice_mode == 0)
10556  {
10557  ni_log2(p_ctx, NI_LOG_ERROR, "%s():not support to reconfig slice_arg when slice_mode disable.\n",
10558  __func__);
10559  sliceArg = 0;
10560  }
10562  {
10563  ni_log2(p_ctx, NI_LOG_ERROR, "%s():sliceArg is only supported for H.264 or H.265.\n",
10564  __func__);
10565  sliceArg = 0;
10566  }
10567  int ctu_mb_size = (NI_CODEC_FORMAT_H264 == p_ctx->codec_format) ? 16 : 64;
10568  int max_num_ctu_mb_row = (api_param->source_height + ctu_mb_size - 1) / ctu_mb_size;
10569  if (sliceArg < 1 || sliceArg > max_num_ctu_mb_row)
10570  {
10571  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid data sliceArg %d\n", __func__,
10572  sliceArg);
10573  sliceArg = 0;
10574  }
10575 
10576  ni_pthread_mutex_lock(&p_ctx->mutex);
10578 
10579  p_ctx->reconfig_slice_arg = sliceArg;
10580 
10582  ni_pthread_mutex_unlock(&p_ctx->mutex);
10583 
10584  return NI_RETCODE_SUCCESS;
10585 }
10586 
10587 #ifndef _WIN32
10588 /*!*****************************************************************************
10589 * \brief Acquire a P2P frame buffer from the hwupload session
10590 *
10591 * \param[in] p_ctx Pointer to a caller allocated
10592 * ni_session_context_t struct
10593 * \param[out] p_frame Pointer to a caller allocated hw frame
10594 *
10595 * \return On success
10596 * NI_RETCODE_SUCCESS
10597 * On failure
10598 * NI_RETCODE_INVALID_PARAM
10599 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10600 * NI_RETCODE_ERROR_INVALID_SESSION
10601 *******************************************************************************/
10603 {
10605  struct netint_iocmd_export_dmabuf uexp;
10606  unsigned int offset;
10607  int ret, is_semi_planar;
10608  int linestride[NI_MAX_NUM_DATA_POINTERS];
10609  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10610  niFrameSurface1_t hwdesc = {0};
10611  niFrameSurface1_t *p_surface;
10612 
10613  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10614  {
10615  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10616  __func__);
10617  return NI_RETCODE_INVALID_PARAM;
10618  }
10619 
10620  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10621 
10622  ni_pthread_mutex_lock(&p_ctx->mutex);
10624 
10625  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10626 
10628  ni_pthread_mutex_unlock(&p_ctx->mutex);
10629 
10630  if (retval != NI_RETCODE_SUCCESS)
10631  {
10632  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10633  return retval;
10634  }
10635 
10636  retval = ni_get_memory_offset(p_ctx, &hwdesc, &offset);
10637  if (retval != NI_RETCODE_SUCCESS)
10638  {
10639  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: bad buffer id\n");
10640  return NI_RETCODE_INVALID_PARAM;
10641  }
10642 
10643  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
10644  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
10645  1 :
10646  0;
10647 
10649  p_ctx->bit_depth_factor, is_semi_planar, linestride,
10650  alignedheight);
10651 
10652  uexp.fd = -1;
10653  uexp.flags = 0;
10654  uexp.offset = offset;
10655 
10656  uexp.length = ni_calculate_total_frame_size(p_ctx, linestride);
10657  uexp.domain = p_ctx->domain;
10658  uexp.bus = p_ctx->bus;
10659  uexp.dev = p_ctx->dev;
10660  uexp.fn = p_ctx->fn;
10661  uexp.bar = 4; // PCI BAR4 configuration space
10662 
10663  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
10664  if (ret < 0)
10665  {
10666  ni_log2(p_ctx, NI_LOG_ERROR, "%s: Failed to export dmabuf %d errno %d\n",
10667  __func__, ret, NI_ERRNO);
10668  return NI_RETCODE_FAILURE;
10669  }
10670 
10671  *p_surface = hwdesc;
10672  p_surface->ui16width = p_ctx->active_video_width;
10673  p_surface->ui16height = p_ctx->active_video_height;
10674  p_surface->ui32nodeAddress = offset;
10675  p_surface->encoding_type = is_semi_planar ?
10678  p_surface->dma_buf_fd = uexp.fd;
10679 
10680  return retval;
10681 }
10682 
10683 /*!*****************************************************************************
10684 * \brief Acquire a P2P frame buffer from the hwupload session for P2P read
10685 *
10686 * \param[in] p_ctx Pointer to a caller allocated
10687 * ni_session_context_t struct
10688 * \param[out] p_frame Pointer to a caller allocated hw frame
10689 *
10690 * \return On success
10691 * NI_RETCODE_SUCCESS
10692 * On failure
10693 * NI_RETCODE_INVALID_PARAM
10694 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10695 * NI_RETCODE_ERROR_INVALID_SESSION
10696 *******************************************************************************/
10698 {
10700 
10701  int is_semi_planar;
10702  int linestride[NI_MAX_NUM_DATA_POINTERS];
10703  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10704  niFrameSurface1_t hwdesc = {0};
10705  niFrameSurface1_t *p_surface;
10706 
10707  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10708  {
10709  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10710  __func__);
10711  return NI_RETCODE_INVALID_PARAM;
10712  }
10713 
10714  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10715 
10716  ni_pthread_mutex_lock(&p_ctx->mutex);
10718 
10719  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10720 
10722  ni_pthread_mutex_unlock(&p_ctx->mutex);
10723 
10724  if (retval != NI_RETCODE_SUCCESS)
10725  {
10726  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10727  return retval;
10728  }
10729 
10730  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
10731  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
10732  1 :
10733  0;
10734 
10736  p_ctx->bit_depth_factor, is_semi_planar, linestride,
10737  alignedheight);
10738 
10739  *p_surface = hwdesc;
10740  p_surface->ui16width = p_ctx->active_video_width;
10741  p_surface->ui16height = p_ctx->active_video_height;
10742  p_surface->ui32nodeAddress = 0;
10743  p_surface->encoding_type = is_semi_planar ?
10746  p_surface->dma_buf_fd = 0;
10747 
10748  return retval;
10749 }
10750 
10751 
10752 /*!*****************************************************************************
10753  * \brief Lock a hardware P2P frame prior to encoding
10754  *
10755  * \param[in] p_upl_ctx pointer to caller allocated upload context
10756  * [in] p_frame pointer to caller allocated hardware P2P frame
10757  *
10758  * \return On success
10759  * NI_RETCODE_SUCCESS
10760  * On failure NI_RETCODE_FAILURE
10761  * NI_RETCODE_INVALID_PARAM
10762 *******************************************************************************/
10764  ni_frame_t *p_frame)
10765 {
10766  int ret;
10767  struct netint_iocmd_attach_rfence uatch = {0};
10768  struct pollfd pfds[1] = {0};
10769  niFrameSurface1_t *p_surface;
10770 
10771  if (p_upl_ctx == NULL || p_frame == NULL)
10772  {
10773  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: bad parameters\n", __func__);
10774  return NI_RETCODE_INVALID_PARAM;
10775  }
10776 
10777  if (p_frame->p_data[3] == NULL)
10778  {
10779  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: not a hardware frame\n", __func__);
10780  return NI_RETCODE_INVALID_PARAM;
10781  }
10782 
10783  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10784 
10785  pfds[0].fd = p_surface->dma_buf_fd;
10786  pfds[0].events = POLLIN;
10787  pfds[0].revents = 0;
10788 
10789  ret = poll(pfds, 1, -1);
10790  if (ret < 0)
10791  {
10792  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s:failed to poll dmabuf fd errno %s\n", __func__,
10793  strerror(NI_ERRNO));
10794  return ret;
10795  }
10796 
10797  uatch.fd = p_surface->dma_buf_fd;
10798  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ATTACH_RFENCE, &uatch);
10799  if (ret < 0)
10800  {
10801  ni_log2(p_upl_ctx, NI_LOG_ERROR,
10802  "%s: failed to attach dmabuf read fence errno %s\n", __func__,
10803  strerror(NI_ERRNO));
10804  return ret;
10805  }
10806 
10807  return NI_RETCODE_SUCCESS;
10808 }
10809 
10810 /*!*****************************************************************************
10811  * \brief Unlock a hardware P2P frame after encoding
10812  *
10813  * \param[in] p_upl_ctx pointer to caller allocated upload context
10814  * [in] p_frame pointer to caller allocated hardware P2P frame
10815  *
10816  * \return On success
10817  * NI_RETCODE_SUCCESS
10818  * On failure NI_RETCODE_FAILURE
10819  * NI_RETCODE_INVALID_PARAM
10820 *******************************************************************************/
10822  ni_frame_t *p_frame)
10823 {
10824  int ret;
10825  struct netint_iocmd_signal_rfence usigl = {0};
10826  niFrameSurface1_t *p_surface;
10827 
10828  if ((p_upl_ctx == NULL) || (p_frame == NULL))
10829  {
10830  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid parameters %p %p\n", __func__,
10831  p_upl_ctx, p_frame);
10832  return NI_RETCODE_INVALID_PARAM;
10833  }
10834 
10835  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10836 
10837  if (p_surface == NULL)
10838  {
10839  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
10840  return NI_RETCODE_INVALID_PARAM;
10841  }
10842 
10843  usigl.fd = p_surface->dma_buf_fd;
10844  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_SIGNAL_RFENCE, &usigl);
10845  if (ret < 0)
10846  {
10847  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Failed to signal dmabuf read fence\n");
10848  return NI_RETCODE_FAILURE;
10849  }
10850 
10851  return NI_RETCODE_SUCCESS;
10852 }
10853 
10854 /*!*****************************************************************************
10855  * \brief Special P2P test API function. Copies YUV data from the software
10856  * frame to the hardware P2P frame on the Quadra device
10857  *
10858  * \param[in] p_upl_ctx pointer to caller allocated uploader session
10859  * context
10860  * [in] p_swframe pointer to a caller allocated software frame
10861  * [in] p_hwframe pointer to a caller allocated hardware frame
10862  *
10863  * \return On success
10864  * NI_RETCODE_SUCCESS
10865  * On failure
10866  * NI_RETCODE_FAILURE
10867  * NI_RETCODE_INVALID_PARAM
10868 *******************************************************************************/
10870  uint8_t *p_data, uint32_t len,
10871  ni_frame_t *p_hwframe)
10872 {
10873  int ret;
10874  struct netint_iocmd_issue_request uis = {0};
10875  niFrameSurface1_t *p_surface;
10876 
10877  if (p_upl_ctx == NULL || p_data == NULL || p_hwframe == NULL)
10878  {
10879  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: invalid null parameters\n", __func__);
10880  return NI_RETCODE_INVALID_PARAM;
10881  }
10882 
10883  if (p_hwframe->p_data[3] == NULL)
10884  {
10885  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: empty frame\n", __func__);
10886  return NI_RETCODE_INVALID_PARAM;
10887  }
10888 
10889  p_surface = (niFrameSurface1_t *)p_hwframe->p_data[3];
10890 
10891  uis.fd = p_surface->dma_buf_fd;
10892  uis.data = p_data;
10893  uis.len = len;
10895 
10896  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ISSUE_REQ, &uis);
10897  if (ret < 0)
10898  {
10899  ni_log2(p_upl_ctx, NI_LOG_ERROR,
10900  "%s: Failed to request dmabuf rendering errno %d\n", __func__,
10901  NI_ERRNO);
10902  return NI_RETCODE_FAILURE;
10903  }
10904 
10905  return NI_RETCODE_SUCCESS;
10906 }
10907 
10908 /*!*****************************************************************************
10909  * \brief Special P2P test API function. Copies video data from the software
10910  * frame to the hardware P2P frame on the Quadra device. Does not
10911  * need the Netint kernel driver but requires root privilege.
10912  *
10913  * \param[in] p_upl_ctx pointer to caller allocated uploader session
10914  * context
10915  * [in] p_swframe pointer to a caller allocated software frame
10916  * [in] p_hwframe pointer to a caller allocated hardware frame
10917  *
10918  * \return On success
10919  * NI_RETCODE_SUCCESS
10920  * On failure
10921  * NI_RETCODE_FAILURE
10922  * NI_RETCODE_INVALID_PARAM
10923 *******************************************************************************/
10925  uint8_t *p_data, uint32_t len,
10926  ni_frame_t *p_hwframe)
10927 {
10928  int bar4_fd, ret;
10929  char bar4_name[128];
10930  char *bar4_mm;
10931  struct stat stat;
10932  niFrameSurface1_t *pSurf;
10933  uint32_t offset;
10934 
10935  pSurf = (niFrameSurface1_t *) p_hwframe->p_data[3];
10936 
10937  ret = ni_get_memory_offset(p_upl_ctx, pSurf, &offset);
10938  if (ret != 0)
10939  {
10940  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Error bad buffer id\n");
10941  return NI_RETCODE_FAILURE;
10942  }
10943 
10944  snprintf(bar4_name, 128,
10945  "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/resource4",
10946  p_upl_ctx->domain,p_upl_ctx->bus,p_upl_ctx->dev,p_upl_ctx->fn);
10947 
10948  bar4_fd = open(bar4_name, O_RDWR | O_SYNC);
10949 
10950  if (bar4_fd < 0)
10951  {
10952  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't open bar4 %s (%s)\n",
10953  bar4_name, strerror(errno));
10954  return NI_RETCODE_FAILURE;
10955  }
10956 
10957  if (fstat(bar4_fd, &stat) != 0)
10958  {
10959  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't stat bar4 (%s)\n",
10960  strerror(errno));
10961  close(bar4_fd);
10962  return NI_RETCODE_FAILURE;
10963  }
10964 
10965  bar4_mm = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, bar4_fd, 0);
10966 
10967  if (bar4_mm == MAP_FAILED)
10968  {
10969  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't mmap to bar4 (%s)\n",
10970  strerror(errno));
10971  close(bar4_fd);
10972  return NI_RETCODE_FAILURE;
10973  }
10974 
10975  /* Copy the data directly into Quadra video memory */
10976  memcpy(bar4_mm + offset, p_data, len);
10977 
10978  munmap(bar4_mm, 0);
10979  close(bar4_fd);
10980 
10981  return NI_RETCODE_SUCCESS;
10982 }
10983 
10984 
10985 /*!*****************************************************************************
10986  * \brief Recycle hw P2P frames
10987  *
10988  * \param [in] p_frame pointer to an acquired P2P hw frame
10989  *
10990  * \return on success
10991  * NI_RETCODE_SUCCESS
10992  *
10993  * on failure
10994  * NI_RETCODE_INVALID_PARAM
10995 *******************************************************************************/
10997 {
10998  niFrameSurface1_t *p_surface;
10999 
11000  if (p_frame == NULL)
11001  {
11002  ni_log(NI_LOG_ERROR, "%s: Invalid frame\n", __func__);
11003  return NI_RETCODE_INVALID_PARAM;
11004  }
11005 
11006  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11007  if (p_surface == NULL)
11008  {
11009  ni_log(NI_LOG_ERROR, "%s: Invalid surface data\n", __func__);
11010  return NI_RETCODE_INVALID_PARAM;
11011  }
11012 
11013  return ni_hwframe_buffer_recycle2(p_surface);
11014 }
11015 
11016 /*!*****************************************************************************
11017  * \brief Acquire the scaler P2P DMA buffer for read/write
11018  *
11019  * \param [in] p_ctx pointer to caller allocated upload context
11020  * [in] p_surface pointer to a caller allocated hardware frame
11021  * [in] data_len scaler frame buffer data length
11022  *
11023  * \return on success
11024  * NI_RETCODE_SUCCESS
11025  *
11026  * on failure
11027  * NI_RETCODE_FAILURE
11028 *******************************************************************************/
11030  niFrameSurface1_t *p_surface,
11031  int data_len)
11032 {
11033  unsigned int offset;
11034  int ret;
11035 
11036  ret = ni_get_memory_offset(p_ctx, p_surface, &offset);
11037  if (ret != 0)
11038  {
11039  ni_log2(p_ctx, NI_LOG_ERROR, "Error: bad buffer id\n");
11040  return NI_RETCODE_FAILURE;
11041  }
11042  p_surface->ui32nodeAddress = 0;
11043 
11044  struct netint_iocmd_export_dmabuf uexp;
11045  uexp.fd = -1;
11046  uexp.flags = 0;
11047  uexp.offset = offset;
11048  uexp.length = data_len;
11049  uexp.domain = p_ctx->domain;
11050  uexp.bus = p_ctx->bus;
11051  uexp.dev = p_ctx->dev;
11052  uexp.fn = p_ctx->fn;
11053  uexp.bar = 4;
11054  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
11055  if (ret < 0)
11056  {
11057  ni_log2(p_ctx, NI_LOG_ERROR, "failed to export dmabuf: %s\n", strerror(errno));
11058  return NI_RETCODE_FAILURE;
11059  }
11060  p_surface->dma_buf_fd = uexp.fd;
11061  return ret;
11062 }
11063 #endif
11064 
11065 /*!*****************************************************************************
11066  * \brief Set the incoming frame format for the encoder
11067  *
11068  * \param[in] p_enc_ctx pointer to encoder context
11069  * [in] p_enc_params pointer to encoder parameters
11070  * [in] width input width
11071  * [in] height input height
11072  * [in] bit_depth 8 for 8-bit YUV, 10 for 10-bit YUV
11073  * [in] src_endian NI_FRAME_LITTLE_ENDIAN or NI_FRAME_BIG_ENDIAN
11074  * [in] planar 0 for semi-planar YUV, 1 for planar YUV
11075  *
11076  * \return on success
11077  * NI_RETCODE_SUCCESS
11078  *
11079  * on failure
11080  * NI_RETCODE_INVALID_PARAM
11081  *
11082 *******************************************************************************/
11084  ni_xcoder_params_t *p_enc_params,
11085  int width, int height,
11086  int bit_depth, int src_endian,
11087  int planar)
11088 {
11089  int alignedw;
11090  int alignedh;
11091 
11092  if (p_enc_ctx == NULL || p_enc_params == NULL)
11093  {
11094  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11095  return NI_RETCODE_INVALID_PARAM;
11096  }
11097 
11098  if (!(bit_depth == 8) && !(bit_depth == 10))
11099  {
11100  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad bit depth %d\n", __func__, bit_depth);
11101  return NI_RETCODE_INVALID_PARAM;
11102  }
11103 
11104  if (!(src_endian == NI_FRAME_LITTLE_ENDIAN) &&
11105  !(src_endian == NI_FRAME_BIG_ENDIAN))
11106  {
11107  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad endian %d\n", __func__, src_endian);
11108  return NI_RETCODE_INVALID_PARAM;
11109  }
11110 
11111  if ((planar < 0) || (planar >= NI_PIXEL_PLANAR_MAX))
11112  {
11113  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad planar value %d\n", __func__, planar);
11114  return NI_RETCODE_INVALID_PARAM;
11115  }
11116 
11117  p_enc_ctx->src_bit_depth = bit_depth;
11118  p_enc_ctx->bit_depth_factor = (bit_depth == 8) ? 1 : 2;
11119  p_enc_ctx->src_endian = src_endian;
11120 
11121  alignedw = width;
11122 
11123  if (alignedw < NI_MIN_WIDTH)
11124  {
11125  p_enc_params->cfg_enc_params.conf_win_right +=
11126  (NI_MIN_WIDTH - width) / 2 * 2;
11127  alignedw = NI_MIN_WIDTH;
11128  } else
11129  {
11130  alignedw = ((width + 1) / 2) * 2;
11131  p_enc_params->cfg_enc_params.conf_win_right +=
11132  (alignedw - width) / 2 * 2;
11133  }
11134 
11135  p_enc_params->source_width = alignedw;
11136  alignedh = height;
11137 
11138  if (alignedh < NI_MIN_HEIGHT)
11139  {
11140  p_enc_params->cfg_enc_params.conf_win_bottom +=
11141  (NI_MIN_HEIGHT - height) / 2 * 2;
11142  alignedh = NI_MIN_HEIGHT;
11143  } else
11144  {
11145  alignedh = ((height + 1) / 2) * 2;
11146  p_enc_params->cfg_enc_params.conf_win_bottom +=
11147  (alignedh - height) / 2 * 2;
11148  }
11149 
11150  p_enc_params->source_height = alignedh;
11151  p_enc_params->cfg_enc_params.planar = planar;
11152 
11153  return NI_RETCODE_SUCCESS;
11154 }
11155 
11156 /*!*****************************************************************************
11157  * \brief Set the outgoing frame format for the uploader
11158  *
11159  * \param[in] p_upl_ctx pointer to uploader context
11160  * [in] width width
11161  * [in] height height
11162  * [in] pixel_format pixel format
11163  * [in] isP2P 0 = normal, 1 = P2P
11164  *
11165  * \return on success
11166  * NI_RETCODE_SUCCESS
11167  *
11168  * on failure
11169  * NI_RETCODE_INVALID_PARAM
11170 *******************************************************************************/
11172  int width, int height,
11173  ni_pix_fmt_t pixel_format, int isP2P)
11174 {
11175  if (p_upl_ctx == NULL)
11176  {
11177  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11178  return NI_RETCODE_INVALID_PARAM;
11179  }
11180 
11181  switch (pixel_format)
11182  {
11183  case NI_PIX_FMT_YUV420P:
11184  case NI_PIX_FMT_NV12:
11185  p_upl_ctx->src_bit_depth = 8;
11186  p_upl_ctx->bit_depth_factor = 1;
11187  break;
11189  case NI_PIX_FMT_P010LE:
11190  p_upl_ctx->src_bit_depth = 10;
11191  p_upl_ctx->bit_depth_factor = 2;
11192  break;
11193  case NI_PIX_FMT_RGBA:
11194  case NI_PIX_FMT_BGRA:
11195  case NI_PIX_FMT_ARGB:
11196  case NI_PIX_FMT_ABGR:
11197  case NI_PIX_FMT_BGR0:
11198  case NI_PIX_FMT_BGRP:
11199  p_upl_ctx->src_bit_depth = 8;
11200  p_upl_ctx->bit_depth_factor = 4;
11201  break;
11202  default:
11203  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid pixfmt %d\n", __func__,
11204  pixel_format);
11205  return NI_RETCODE_INVALID_PARAM;
11206  }
11207 
11208  p_upl_ctx->src_endian = NI_FRAME_LITTLE_ENDIAN;
11209  p_upl_ctx->pixel_format = pixel_format;
11210  p_upl_ctx->active_video_width = width;
11211  p_upl_ctx->active_video_height = height;
11212  p_upl_ctx->isP2P = isP2P;
11213 
11214  return NI_RETCODE_SUCCESS;
11215 }
11216 
11217 /*!*****************************************************************************
11218  * \brief Read encoder stream header from the device
11219  *
11220  * \param[in] p_ctx Pointer to a caller allocated
11221  * ni_session_context_t struct from encoder
11222  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
11223  * struct which contains a ni_packet_t data packet to
11224  * receive
11225  * \return On success
11226  * Total number of bytes read
11227  * On failure
11228  * NI_RETCODE_INVALID_PARAM
11229  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11230  * NI_RETCODE_ERROR_INVALID_SESSION
11231 *******************************************************************************/
11233  ni_session_data_io_t *p_data)
11234 {
11235  int rx_size;
11236  int done = 0;
11237  int bytes_read = 0;
11238 
11239  /* This function should be called once at the start of encoder read */
11240  if (p_ctx->pkt_num != 0)
11241  {
11242  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11244  }
11245 
11246  while (!done)
11247  {
11248  rx_size = ni_device_session_read(p_ctx, p_data, NI_DEVICE_TYPE_ENCODER);
11249 
11250  if (rx_size > (int)p_ctx->meta_size)
11251  {
11252  /* stream header has been read, return size */
11253  bytes_read += (rx_size - (int)p_ctx->meta_size);
11254 
11255  p_ctx->pkt_num = 1;
11256  ni_log2(p_ctx, NI_LOG_DEBUG, "Got encoded stream header\n");
11257  done = 1;
11258  } else if (rx_size != 0)
11259  {
11260  ni_log2(p_ctx, NI_LOG_ERROR, "Error: received rx_size = %d\n", rx_size);
11261  bytes_read = -1;
11262  done = 1;
11263  } else
11264  {
11265  ni_log2(p_ctx, NI_LOG_DEBUG, "No data, keep reading..\n");
11266  continue;
11267  }
11268  }
11269 
11270  return bytes_read;
11271 }
11272 
11273 /*!*****************************************************************************
11274  * \brief Get the DMA buffer file descriptor from the P2P frame
11275  *
11276  * \param[in] p_frame pointer to a P2P frame
11277  *
11278  * \return On success
11279  * DMA buffer file descriptor
11280  * On failure
11281  * NI_RETCODE_INVALID_PARAM
11282 *******************************************************************************/
11284 {
11285  const niFrameSurface1_t *p_surface;
11286 
11287  if (p_frame == NULL)
11288  {
11289  ni_log(NI_LOG_ERROR, "%s: NULL frame\n", __func__);
11290  return NI_RETCODE_INVALID_PARAM;
11291  }
11292 
11293  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11294 
11295  if (p_surface == NULL)
11296  {
11297  ni_log(NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
11298  return NI_RETCODE_INVALID_PARAM;
11299  }
11300 
11301  return p_surface->dma_buf_fd;
11302 }
11303 
11304 /*!*****************************************************************************
11305  * \brief Send sequence change information to device
11306  *
11307  * \param[in] p_ctx Pointer to a caller allocated
11308  * ni_session_context_t struct
11309  * \param[in] width input width
11310  * \param[in] height input height
11311  * \param[in] bit_depth_factor 1 for 8-bit YUV, 2 for 10-bit YUV
11312  * \param[in] device_type device type (must be encoder)
11313  * \return On success
11314  * NI_RETCODE_SUCCESS
11315  * On failure
11316  * NI_RETCODE_INVALID_PARAM
11317  * NI_RETCODE_ERROR_MEM_ALOC
11318  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11319  * NI_RETCODE_ERROR_INVALID_SESSION
11320  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
11321  ******************************************************************************/
11323  int width, int height, int bit_depth_factor, ni_device_type_t device_type)
11324 {
11325  ni_resolution_t resolution;
11327  ni_xcoder_params_t *p_param = NULL;
11328 
11329  // requires API version >= 54
11331  "54") < 0)
11332  {
11333  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
11335  }
11336 
11337  /* This function should be called only if sequence change is detected */
11339  {
11340  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11342  }
11343 
11344  resolution.width = width;
11345  resolution.height = height;
11346  resolution.bit_depth_factor = bit_depth_factor;
11347  resolution.luma_linesize = 0;
11348  resolution.chroma_linesize = 0;
11349  if (p_ctx->p_session_config)
11350  {
11351  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
11352  resolution.luma_linesize = p_param->luma_linesize;
11353  resolution.chroma_linesize = p_param->chroma_linesize;
11354  }
11355 
11356  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: resolution change config - width %d height %d bit_depth_factor %d "
11357  "luma_linesize %d chroma_linesize %d\n", __func__,
11358  resolution.width, resolution.height, resolution.bit_depth_factor,
11359  resolution.luma_linesize, resolution.chroma_linesize);
11360 
11361  switch (device_type)
11362  {
11364  {
11365  // config sequence change
11366  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
11367  break;
11368  }
11369  default:
11370  {
11371  retval = NI_RETCODE_INVALID_PARAM;
11372  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported for device type: %d", device_type);
11373  return retval;
11374  }
11375  }
11376  return retval;
11377 }
11378 
11380  ni_network_perf_metrics_t *p_metrics)
11381 {
11382  return ni_ai_session_query_metrics(p_ctx, p_metrics);
11383 }
11384 
11385 ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle,
11386  ni_device_info_t *p_dev_info)
11387 {
11388  void *buffer;
11389  uint32_t size;
11390  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11391  ni_log_fl_fw_versions_t fl_fw_versions;
11392 
11393  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_info))
11394  {
11395  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11396  __func__);
11397  return NI_RETCODE_INVALID_PARAM;
11398  }
11399 
11401  "6h") < 0)
11402  {
11404  "ERROR: %s function not supported on device with FW API version < 6.h\n",
11405  __func__);
11407  }
11408 
11409  buffer = NULL;
11411 
11412  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11413  {
11414  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11416  }
11417 
11418  memset(buffer, 0, size);
11419 
11420  if (ni_nvme_send_read_cmd(device_handle,
11421  event_handle,
11422  buffer,
11423  size,
11424  QUERY_GET_VERSIONS_R) < 0)
11425  {
11426  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11427  ni_aligned_free(buffer);
11429  }
11430 
11431  memcpy(&fl_fw_versions, buffer, sizeof(ni_log_fl_fw_versions_t));
11432 
11433  memcpy(p_dev_info->fl_ver_last_ran,
11434  &fl_fw_versions.last_ran_fl_version,
11436  memcpy(p_dev_info->fl_ver_nor_flash,
11437  &fl_fw_versions.nor_flash_fl_version,
11439  memcpy(p_dev_info->fw_rev_nor_flash,
11440  &fl_fw_versions.nor_flash_fw_revision,
11442 
11443  ni_aligned_free(buffer);
11444  return NI_RETCODE_SUCCESS;
11445 }
11446 
11448  ni_load_query_t *p_load_query)
11449 {
11450  void *buffer;
11451  uint32_t size;
11452 
11453  ni_instance_mgr_general_status_t general_status;
11454 
11455  if (!p_ctx)
11456  {
11457  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_ctx cannot be null\n");
11458  return NI_RETCODE_INVALID_PARAM;
11459  }
11460  if (!p_load_query)
11461  {
11462  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_load_query cannot be null\n");
11463  return NI_RETCODE_INVALID_PARAM;
11464  }
11465 
11467  "6O") < 0)
11468  {
11469  ni_log2(p_ctx, NI_LOG_ERROR,
11470  "ERROR: %s function not supported on device with FW API version < 6.O\n",
11471  __func__);
11473  }
11474 
11475  buffer = NULL;
11477 
11478  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11479  {
11480  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11482  }
11483 
11484  memset(buffer, 0, size);
11485 
11487  p_ctx->event_handle,
11488  buffer,
11489  size,
11491  {
11492  ni_log2(p_ctx, NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11493  ni_aligned_free(buffer);
11495  }
11496 
11497  memcpy(&general_status, buffer, sizeof(ni_instance_mgr_general_status_t));
11498 
11499  p_load_query->tp_fw_load = general_status.tp_fw_load;
11500  p_load_query->pcie_load = general_status.pcie_load;
11501  p_load_query->pcie_throughput = general_status.pcie_throughput;
11502  p_load_query->fw_load = general_status.fw_load;
11503  p_load_query->fw_share_mem_usage = general_status.fw_share_mem_usage;
11504 
11505  ni_aligned_free(buffer);
11506  return NI_RETCODE_SUCCESS;
11507 }
11508 
11509 ni_retcode_t ni_query_vf_ns_id(ni_device_handle_t device_handle,
11510  ni_device_vf_ns_id_t *p_dev_ns_vf,
11511  uint8_t fw_rev[])
11512 {
11513  void *p_buffer = NULL;
11514  uint32_t size;
11515  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11516 
11517  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_ns_vf))
11518  {
11519  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11520  __func__);
11521  return NI_RETCODE_INVALID_PARAM;
11522  }
11523 
11525  "6m") < 0)
11526  {
11528  "ERROR: %s function not supported on device with FW API version < 6.m\n",
11529  __func__);
11531  }
11532 
11534 
11535  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11536  {
11537  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11539  }
11540 
11541  memset(p_buffer, 0, size);
11542 
11543  if (ni_nvme_send_read_cmd(device_handle,
11544  event_handle,
11545  p_buffer,
11546  size,
11547  QUERY_GET_NS_VF_R) < 0)
11548  {
11549  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11550  ni_aligned_free(p_buffer);
11552  }
11553 
11554  ni_device_vf_ns_id_t *p_dev_ns_vf_data = (ni_device_vf_ns_id_t *)p_buffer;
11555  p_dev_ns_vf->vf_id = p_dev_ns_vf_data->vf_id;
11556  p_dev_ns_vf->ns_id = p_dev_ns_vf_data->ns_id;
11557  ni_log(NI_LOG_DEBUG, "%s(): NS/VF %u/%u\n", __func__, p_dev_ns_vf->ns_id, p_dev_ns_vf->vf_id);
11558  ni_aligned_free(p_buffer);
11559  return NI_RETCODE_SUCCESS;
11560 }
11561 
11562 ni_retcode_t ni_query_temperature(ni_device_handle_t device_handle,
11563  ni_device_temp_t *p_dev_temp,
11564  uint8_t fw_rev[])
11565 {
11566  void *p_buffer = NULL;
11567  uint32_t size;
11568  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11569 
11570  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_temp))
11571  {
11572  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11573  __func__);
11574  return NI_RETCODE_INVALID_PARAM;
11575  }
11576 
11578  "6rC") < 0)
11579  {
11581  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11582  __func__);
11584  }
11585 
11587 
11588  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11589  {
11590  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11592  }
11593 
11594  memset(p_buffer, 0, size);
11595 
11596  if (ni_nvme_send_read_cmd(device_handle,
11597  event_handle,
11598  p_buffer,
11599  size,
11601  {
11602  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11603  ni_aligned_free(p_buffer);
11605  }
11606 
11607  ni_device_temp_t *p_dev_temp_data = (ni_device_temp_t *)p_buffer;
11608  p_dev_temp->composite_temp = p_dev_temp_data->composite_temp;
11609  p_dev_temp->on_board_temp = p_dev_temp_data->on_board_temp;
11610  p_dev_temp->on_die_temp = p_dev_temp_data->on_die_temp;
11611  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d on die temperature %d\n",
11612  __func__, p_dev_temp->composite_temp, p_dev_temp->on_board_temp, p_dev_temp->on_die_temp);
11613  ni_aligned_free(p_buffer);
11614  return NI_RETCODE_SUCCESS;
11615 }
11616 
11617 ni_retcode_t ni_query_extra_info(ni_device_handle_t device_handle,
11618  ni_device_extra_info_t *p_dev_extra_info,
11619  uint8_t fw_rev[])
11620 {
11621  void *p_buffer = NULL;
11622  uint32_t size;
11623  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11624 
11625  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_extra_info))
11626  {
11627  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11628  __func__);
11629  return NI_RETCODE_INVALID_PARAM;
11630  }
11631 
11633  "6rC") < 0)
11634  {
11636  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11637  __func__);
11639  }
11640 
11642 
11643  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11644  {
11645  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11647  }
11648 
11649  memset(p_buffer, 0, size);
11650 
11651  if (ni_nvme_send_read_cmd(device_handle,
11652  event_handle,
11653  p_buffer,
11654  size,
11656  {
11657  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11658  ni_aligned_free(p_buffer);
11660  }
11661 
11662  ni_device_extra_info_t *p_dev_extra_info_data = (ni_device_extra_info_t *)p_buffer;
11663  p_dev_extra_info->composite_temp = p_dev_extra_info_data->composite_temp;
11664  p_dev_extra_info->on_board_temp = p_dev_extra_info_data->on_board_temp;
11665  p_dev_extra_info->on_die_temp = p_dev_extra_info_data->on_die_temp;
11666  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rC") >= 0 &&
11667  ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rR") < 0)
11668  {
11669  p_dev_extra_info->power_consumption = NI_INVALID_POWER;
11670  }
11671  else
11672  {
11673  p_dev_extra_info->power_consumption = p_dev_extra_info_data->power_consumption;
11674  }
11675  //QUADPV-1210-Remove ADC current measurement decoding from FW
11676  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6s4") >=0)
11677  {
11678  p_dev_extra_info->current_consumption = p_dev_extra_info_data->current_consumption;
11679  ni_device_capability_t device_capability = {0};
11680  if (ni_device_capability_query2(device_handle, &device_capability, false) != NI_RETCODE_SUCCESS)
11681  {
11682  ni_log(NI_LOG_ERROR, "ERROR: unable to query capability\n");
11684  }
11685  p_dev_extra_info->power_consumption = ni_decode_power_measurement(p_dev_extra_info->current_consumption, device_capability.serial_number);
11686  }
11687  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d "
11688  "on die temperature %d power consumption %d current consumption %d\n",
11689  __func__, p_dev_extra_info->composite_temp, p_dev_extra_info->on_board_temp,
11690  p_dev_extra_info->on_die_temp, p_dev_extra_info->power_consumption, p_dev_extra_info->current_consumption);
11691  ni_aligned_free(p_buffer);
11692  return NI_RETCODE_SUCCESS;
11693 }
11694 
11695 /*!*****************************************************************************
11696  * \brief Allocate log buffer if needed and retrieve firmware logs from device
11697  *
11698  * \param[in] p_ctx Pointer to a caller allocated
11699  * ni_session_context_t struct
11700  * \param[in] p_log_buffer Reference to pointer to a log buffer
11701  * If log buffer pointer is NULL, this function will allocate log buffer
11702  * NOTE caller is responsible for freeing log buffer after calling this function
11703  * \param[in] gen_log_file Indicating whether it is required to generate log files
11704  *
11705  *
11706  * \return on success
11707  * NI_RETCODE_SUCCESS
11708  *
11709  * on failure
11710  * NI_RETCODE_ERROR_MEM_ALOC
11711  * NI_RETCODE_INVALID_PARAM
11712 *******************************************************************************/
11713 ni_retcode_t ni_device_alloc_and_get_firmware_logs(ni_session_context_t *p_ctx, void** p_log_buffer, bool gen_log_file)
11714 {
11716  bool is_ext_buf = true;
11717  if (*p_log_buffer == NULL)
11718  {
11719  if (ni_posix_memalign(p_log_buffer, sysconf(_SC_PAGESIZE), TOTAL_CPU_LOG_BUFFER_SIZE))
11720  {
11721  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate log buffer\n",
11722  NI_ERRNO, __func__);
11724  }
11725  is_ext_buf = false;
11726  }
11727 
11728  if(*p_log_buffer != NULL){
11729  memset(*p_log_buffer, 0, TOTAL_CPU_LOG_BUFFER_SIZE);
11730  retval = ni_dump_log_all_cores(p_ctx, *p_log_buffer, gen_log_file); // dump FW logs
11731  if(!is_ext_buf)
11732  ni_aligned_free(*p_log_buffer);
11733  }else{
11735  }
11736 
11737  return retval;
11738 }
11739 
11740 /*!*****************************************************************************
11741  * \brief Set up hard coded demo ROI map
11742  *
11743  * \param[in] p_enc_ctx Pointer to a caller allocated
11744  *
11745  * \return on success
11746  * NI_RETCODE_SUCCESS
11747  *
11748  * on failure
11749  * NI_RETCODE_ERROR_MEM_ALOC
11750 *******************************************************************************/
11752 {
11753  ni_xcoder_params_t *p_param =
11754  (ni_xcoder_params_t *)(p_enc_ctx->p_session_config);
11755  int sumQp = 0, ctu, i, j;
11756  // mode 1: Set QP for center 1/3 of picture to highest - lowest quality
11757  // the rest to lowest - highest quality;
11758  // mode non-1: reverse of mode 1
11759  int importanceLevelCentre = p_param->roi_demo_mode == 1 ? 40 : 10;
11760  int importanceLevelRest = p_param->roi_demo_mode == 1 ? 10 : 40;
11761  int linesize_aligned = p_param->source_width;
11762  int height_aligned = p_param->source_height;
11763  if (QUADRA)
11764  {
11765  uint32_t block_size, max_cu_size, customMapSize;
11766  uint32_t mbWidth;
11767  uint32_t mbHeight;
11768  uint32_t numMbs;
11769  uint32_t roiMapBlockUnitSize;
11770  uint32_t entryPerMb;
11771  uint32_t entryWidth;
11772  uint32_t entryPos;
11773  bool bIsCenter;
11774 
11775  max_cu_size = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16: 64;
11776  // AV1 non-8x8-aligned resolution is implicitly cropped due to Quadra HW limitation
11777  if (NI_CODEC_FORMAT_AV1 == p_enc_ctx->codec_format)
11778  {
11779  linesize_aligned = (linesize_aligned / 8) * 8;
11780  height_aligned = (height_aligned / 8) * 8;
11781  }
11782 
11783  // (ROI map version >= 1) each QP info takes 8-bit, represent 8 x 8
11784  // pixel block
11785  block_size =
11786  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) *
11787  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11788  (8 * 8);
11789 
11790  // need to align to 64 bytes
11791  customMapSize = ((block_size + 63) & (~63));
11792  if (!p_enc_ctx->roi_map)
11793  {
11794  p_enc_ctx->roi_map =
11795  (ni_enc_quad_roi_custom_map *)calloc(1, customMapSize);
11796  }
11797  if (!p_enc_ctx->roi_map)
11798  {
11800  }
11801 
11802  // for H.264, select ROI Map Block Unit Size: 16x16
11803  // for H.265, select ROI Map Block Unit Size: 64x64
11804  roiMapBlockUnitSize = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16 : 64;
11805 
11806  mbWidth =
11807  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11808  roiMapBlockUnitSize;
11809  mbHeight =
11810  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11811  roiMapBlockUnitSize;
11812  numMbs = mbWidth * mbHeight;
11813 
11814  // copy roi MBs QPs into custom map
11815  // number of qp info (8x8) per mb or ctb
11816  entryPerMb = (roiMapBlockUnitSize / 8) * (roiMapBlockUnitSize / 8);
11817  entryWidth = roiMapBlockUnitSize / 8;
11818  for (i = 0; i < numMbs; i++)
11819  {
11820  for (j = 0; j < entryPerMb; j++)
11821  {
11822  entryPos = (i % mbWidth) * entryWidth + j % entryWidth;
11823  bIsCenter = (entryPos >= mbWidth * entryWidth / 3) && (entryPos < mbWidth * entryWidth * 2 / 3);
11824  /*
11825  g_quad_roi_map[i*4+j].field.skip_flag = 0; // don't force
11826  skip mode g_quad_roi_map[i*4+j].field.roiAbsQp_flag = 1; //
11827  absolute QP g_quad_roi_map[i*4+j].field.qp_info = bIsCenter
11828  ? importanceLevelCentre : importanceLevelRest;
11829  */
11830  p_enc_ctx->roi_map[i * entryPerMb + j].field.ipcm_flag =
11831  0; // don't force skip mode
11832  p_enc_ctx->roi_map[i * entryPerMb + j]
11833  .field.roiAbsQp_flag = 1; // absolute QP
11834  p_enc_ctx->roi_map[i * entryPerMb + j].field.qp_info =
11835  bIsCenter ? importanceLevelCentre : importanceLevelRest;
11836  sumQp += p_enc_ctx->roi_map[i * entryPerMb + j].field.qp_info;
11837  }
11838  }
11839  p_enc_ctx->roi_len = customMapSize;
11840  p_enc_ctx->roi_avg_qp =
11841  // NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
11842  (sumQp + ((numMbs * entryPerMb) >> 1)) / (numMbs * entryPerMb); // round off
11843  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s() set avg_qp %d\n",
11844  __func__, p_enc_ctx->roi_avg_qp);
11845  }
11846  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264)
11847  {
11848  // roi for H.264 is specified for 16x16 pixel macroblocks - 1 MB
11849  // is stored in each custom map entry
11850 
11851  // number of MBs in each row
11852  uint32_t mbWidth = (linesize_aligned + 16 - 1) >> 4;
11853  // number of MBs in each column
11854  uint32_t mbHeight = (height_aligned + 16 - 1) >> 4;
11855  uint32_t numMbs = mbWidth * mbHeight;
11856  uint32_t customMapSize =
11857  sizeof(ni_enc_avc_roi_custom_map_t) * numMbs;
11858  p_enc_ctx->avc_roi_map =
11859  (ni_enc_avc_roi_custom_map_t *)calloc(1, customMapSize);
11860  if (!p_enc_ctx->avc_roi_map)
11861  {
11863  }
11864 
11865  // copy roi MBs QPs into custom map
11866  for (i = 0; i < numMbs; i++)
11867  {
11868  if ((i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3))
11869  {
11870  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelCentre;
11871  }
11872  else
11873  {
11874  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelRest;
11875  }
11876  sumQp += p_enc_ctx->avc_roi_map[i].field.mb_qp;
11877  }
11878  p_enc_ctx->roi_len = customMapSize;
11879  p_enc_ctx->roi_avg_qp =
11880  (sumQp + (numMbs >> 1)) / numMbs; // round off
11881  }
11882  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H265)
11883  {
11884  // roi for H.265 is specified for 32x32 pixel subCTU blocks - 4
11885  // subCTU QPs are stored in each custom CTU map entry
11886 
11887  // number of CTUs in each row
11888  uint32_t ctuWidth = (linesize_aligned + 64 - 1) >> 6;
11889  // number of CTUs in each column
11890  uint32_t ctuHeight = (height_aligned + 64 - 1) >> 6;
11891  // number of sub CTUs in each row
11892  uint32_t subCtuWidth = ctuWidth * 2;
11893  // number of CTUs in each column
11894  uint32_t subCtuHeight = ctuHeight * 2;
11895  uint32_t numSubCtus = subCtuWidth * subCtuHeight;
11896 
11897  p_enc_ctx->hevc_sub_ctu_roi_buf = (uint8_t *)malloc(numSubCtus);
11898  if (!p_enc_ctx->hevc_sub_ctu_roi_buf)
11899  {
11901  }
11902  for (i = 0; i < numSubCtus; i++)
11903  {
11904  if ((i % subCtuWidth > subCtuWidth / 3) &&
11905  (i % subCtuWidth < subCtuWidth * 2 / 3))
11906  {
11907  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelCentre;
11908  }
11909  else
11910  {
11911  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelRest;
11912  }
11913  }
11914  p_enc_ctx->hevc_roi_map = (ni_enc_hevc_roi_custom_map_t *)calloc(
11915  1, sizeof(ni_enc_hevc_roi_custom_map_t) * ctuWidth * ctuHeight);
11916  if (!p_enc_ctx->hevc_roi_map)
11917  {
11919  }
11920 
11921  for (i = 0; i < ctuHeight; i++)
11922  {
11923  uint8_t *ptr = &p_enc_ctx->hevc_sub_ctu_roi_buf[subCtuWidth * i * 2];
11924  for (j = 0; j < ctuWidth; j++, ptr += 2)
11925  {
11926  ctu = (int)(i * ctuWidth + j);
11927  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 = *ptr;
11928  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 = *(ptr + 1);
11929  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 =
11930  *(ptr + subCtuWidth);
11931  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3 =
11932  *(ptr + subCtuWidth + 1);
11933  sumQp += (p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 +
11934  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 +
11935  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 +
11936  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3);
11937  }
11938  }
11939  p_enc_ctx->roi_len =
11940  ctuWidth * ctuHeight * sizeof(ni_enc_hevc_roi_custom_map_t);
11941  p_enc_ctx->roi_avg_qp =
11942  (sumQp + (numSubCtus >> 1)) / numSubCtus; // round off.
11943  }
11944  return NI_RETCODE_SUCCESS;
11945 }
11946 
11948 {
11949  // for encoder reconfiguration testing
11950  // reset encoder change data buffer for reconf parameters
11951  ni_retcode_t retval = 0;
11952  ni_xcoder_params_t *p_param =
11953  (ni_xcoder_params_t *)p_enc_ctx->p_session_config;
11954  ni_aux_data_t *aux_data = NULL;
11955  if (p_param->reconf_demo_mode > XCODER_TEST_RECONF_OFF &&
11957  {
11958  memset(p_enc_ctx->enc_change_params, 0, sizeof(ni_encoder_change_params_t));
11959  }
11960 
11961  switch (p_param->reconf_demo_mode) {
11962  case XCODER_TEST_RECONF_BR:
11963  if (p_enc_ctx->frame_num ==
11964  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
11965  {
11966  aux_data = ni_frame_new_aux_data(
11967  p_frame, NI_FRAME_AUX_DATA_BITRATE, sizeof(int32_t));
11968  if (!aux_data)
11969  {
11971  }
11972  *((int32_t *)aux_data->data) =
11973  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
11974 
11975  p_enc_ctx->reconfigCount++;
11976  if (p_param->cfg_enc_params.hrdEnable)
11977  {
11978  p_frame->force_key_frame = 1;
11979  p_frame->ni_pict_type = PIC_TYPE_IDR;
11980  }
11981  }
11982  break;
11983  // reconfig intraperiod param
11985  if (p_enc_ctx->frame_num ==
11986  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
11987  {
11988  aux_data = ni_frame_new_aux_data(
11989  p_frame, NI_FRAME_AUX_DATA_INTRAPRD, sizeof(int32_t));
11990  if (!aux_data)
11991  {
11993  }
11994  int32_t intraprd = *((int32_t *)aux_data->data) =
11995  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
11996  ni_log2(p_enc_ctx, NI_LOG_TRACE,
11997  "xcoder_send_frame: frame #%lu reconf "
11998  "intraPeriod %d\n",
11999  p_enc_ctx->frame_num,
12000  intraprd);
12001  p_enc_ctx->reconfigCount++;
12002  }
12003  break;
12004  // reconfig VUI parameters
12006  if (p_enc_ctx->frame_num ==
12007  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12008  {
12009  aux_data = ni_frame_new_aux_data(p_frame,
12011  sizeof(ni_vui_hrd_t));
12012  if (!aux_data)
12013  {
12015  }
12016  ni_vui_hrd_t *vui = (ni_vui_hrd_t *)aux_data->data;
12017  vui->colorDescPresent =
12018  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12019  vui->colorPrimaries =
12020  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12021  vui->colorTrc =
12022  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12023  vui->colorSpace =
12024  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12025  vui->aspectRatioWidth =
12026  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12027  vui->aspectRatioHeight =
12028  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12029  vui->videoFullRange =
12030  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12031  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12032  "xcoder_send_frame: frame #%lu reconf "
12033  "vui colorDescPresent %d colorPrimaries %d "
12034  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12035  "aspectRatioHeight %d videoFullRange %d\n",
12036  p_enc_ctx->frame_num, vui->colorDescPresent,
12037  vui->colorPrimaries, vui->colorTrc,
12038  vui->colorSpace, vui->aspectRatioWidth,
12039  vui->aspectRatioHeight, vui->videoFullRange);
12040 
12041  p_enc_ctx->reconfigCount++;
12042  }
12043  break;
12044  // long term ref
12046  // the reconf file data line format for this is:
12047  // <frame-number>:useCurSrcAsLongtermPic,useLongtermRef where
12048  // values will stay the same on every frame until changed.
12049  if (p_enc_ctx->frame_num ==
12050  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12051  {
12052  ni_long_term_ref_t *p_ltr;
12053  aux_data = ni_frame_new_aux_data(
12055  sizeof(ni_long_term_ref_t));
12056  if (!aux_data)
12057  {
12059  }
12060  p_ltr = (ni_long_term_ref_t *)aux_data->data;
12062  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12063  p_ltr->use_long_term_ref =
12064  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12065  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12066  "xcoder_send_frame: frame #%lu metadata "
12067  "use_cur_src_as_long_term_pic %d use_long_term_ref "
12068  "%d\n",
12069  p_enc_ctx->frame_num,
12071  p_ltr->use_long_term_ref);
12072  p_enc_ctx->reconfigCount++;
12073  }
12074  break;
12075  // reconfig min / max QP
12078  if (p_enc_ctx->frame_num ==
12079  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12080  aux_data = ni_frame_new_aux_data(
12082  if (!aux_data) {
12084  }
12085 
12086  ni_rc_min_max_qp *qp_info = (ni_rc_min_max_qp *)aux_data->data;
12087  qp_info->minQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12088  qp_info->maxQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12089  qp_info->maxDeltaQp = p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12090  qp_info->minQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12091  qp_info->maxQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12092 
12093  p_enc_ctx->reconfigCount++;
12094  }
12095  break;
12096 #ifdef QUADRA
12097  // reconfig LTR interval
12099  if (p_enc_ctx->frame_num ==
12100  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12101  aux_data = ni_frame_new_aux_data(p_frame,
12103  sizeof(int32_t));
12104  if (!aux_data) {
12106  }
12107  *((int32_t *)aux_data->data) =
12108  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12109  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12110  "xcoder_send_frame: frame #%lu reconf "
12111  "ltrInterval %d\n",
12112  p_enc_ctx->frame_num,
12113  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12114 
12115  p_enc_ctx->reconfigCount++;
12116  }
12117  break;
12118  // invalidate reference frames
12120  if (p_enc_ctx->frame_num ==
12121  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12122  aux_data = ni_frame_new_aux_data(
12124  sizeof(int32_t));
12125  if (!aux_data) {
12127  }
12128  *((int32_t *)aux_data->data) =
12129  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12130  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12131  "xcoder_send_frame: frame #%lu reconf "
12132  "invalidFrameNum %d\n",
12133  p_enc_ctx->frame_num,
12134  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12135 
12136  p_enc_ctx->reconfigCount++;
12137  }
12138  break;
12139  // reconfig framerate
12141  if (p_enc_ctx->frame_num ==
12142  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12143  ni_framerate_t *framerate;
12144 
12145  aux_data = ni_frame_new_aux_data(p_frame,
12147  sizeof(ni_framerate_t));
12148  if (!aux_data) {
12150  }
12151 
12152  framerate = (ni_framerate_t *)aux_data->data;
12153  framerate->framerate_num =
12154  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12155  framerate->framerate_denom =
12156  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12157  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12158  "xcoder_send_frame: frame #%lu reconf "
12159  "framerate (%d/%d)\n",
12160  p_enc_ctx->frame_num, framerate->framerate_num,
12161  framerate->framerate_denom);
12162  p_enc_ctx->reconfigCount++;
12163  }
12164  break;
12166  if (p_enc_ctx->frame_num ==
12167  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12168  aux_data = ni_frame_new_aux_data(
12169  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12170  if (!aux_data) {
12172  }
12173  *((int32_t *)aux_data->data) =
12174  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12175  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12176  "xcoder_send_frame: frame #%lu reconf "
12177  "maxFrameSize %d\n",
12178  p_enc_ctx->frame_num,
12179  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12180 
12181  p_enc_ctx->reconfigCount++;
12182  }
12183  break;
12185  if (p_enc_ctx->frame_num ==
12186  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12187  aux_data = ni_frame_new_aux_data(
12188  p_frame, NI_FRAME_AUX_DATA_CRF, sizeof(int32_t));
12189  if (!aux_data) {
12191  }
12192  *((int32_t *)aux_data->data) =
12193  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12194  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12195  "xcoder_send_frame: frame #%lu reconf "
12196  "crf %d\n",
12197  p_enc_ctx->frame_num,
12198  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12199 
12200  p_enc_ctx->reconfigCount++;
12201  }
12202  break;
12204  if (p_enc_ctx->frame_num ==
12205  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12206  aux_data = ni_frame_new_aux_data(
12207  p_frame, NI_FRAME_AUX_DATA_CRF_FLOAT, sizeof(float));
12208  if (!aux_data) {
12210  }
12211  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12212  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12213  *((float *)aux_data->data) = crf;
12214  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12215  "xcoder_send_frame: frame #%lu reconf "
12216  "crf %f\n",
12217  p_enc_ctx->frame_num, crf);
12218 
12219  p_enc_ctx->reconfigCount++;
12220  }
12221  break;
12223  if (p_enc_ctx->frame_num ==
12224  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12225  int32_t vbvBufferSize = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12226  int32_t vbvMaxRate = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12227  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
12228  {
12229  ni_log2(p_enc_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid vbvBufferSize value %d\n",
12230  __func__, vbvBufferSize);
12231  return NI_RETCODE_INVALID_PARAM;
12232  }
12233  if (p_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < p_param->bitrate) {
12234  ni_log2(p_enc_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
12235  vbvMaxRate, p_param->bitrate);
12236  return NI_RETCODE_INVALID_PARAM;
12237  }
12238  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
12239  ni_log2(p_enc_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
12240  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
12241  vbvMaxRate);
12242  vbvMaxRate = 0;
12243  }
12244 
12245  aux_data = ni_frame_new_aux_data(
12246  p_frame, NI_FRAME_AUX_DATA_VBV_MAX_RATE, sizeof(int32_t));
12247  if (!aux_data) {
12249  }
12250  *((int32_t *)aux_data->data) = vbvMaxRate;
12251  aux_data = ni_frame_new_aux_data(
12252  p_frame, NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE, sizeof(int32_t));
12253  if (!aux_data) {
12255  }
12256  *((int32_t *)aux_data->data) = vbvBufferSize;
12257  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12258  "xcoder_send_frame: frame #%lu reconfig vbvMaxRate %d vbvBufferSize "
12259  "%d by frame aux data\n",
12260  p_enc_ctx->frame_num, vbvMaxRate, vbvBufferSize);
12261 
12262  p_enc_ctx->reconfigCount++;
12263  }
12264  break;
12266  if (p_enc_ctx->frame_num ==
12267  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12268  int maxFrameSizeRatio = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12269  if (maxFrameSizeRatio < 1) {
12270  ni_log2(p_enc_ctx, NI_LOG_ERROR, "maxFrameSizeRatio %d cannot < 1\n",
12271  maxFrameSizeRatio);
12272  return NI_RETCODE_INVALID_PARAM;
12273  }
12274  aux_data = ni_frame_new_aux_data(
12275  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12276  if (!aux_data) {
12278  }
12279 
12280  int32_t bitrate, framerate_num, framerate_denom;
12281  uint32_t min_maxFrameSize, maxFrameSize;
12282  bitrate = (p_enc_ctx->target_bitrate > 0) ? p_enc_ctx->target_bitrate : p_param->bitrate;
12283 
12284  if ((p_enc_ctx->framerate.framerate_num > 0) && (p_enc_ctx->framerate.framerate_denom > 0))
12285  {
12286  framerate_num = p_enc_ctx->framerate.framerate_num;
12287  framerate_denom = p_enc_ctx->framerate.framerate_denom;
12288  }
12289  else
12290  {
12291  framerate_num = (int32_t) p_param->fps_number;
12292  framerate_denom = (int32_t) p_param->fps_denominator;
12293  }
12294 
12295  min_maxFrameSize = ((uint32_t)bitrate / framerate_num * framerate_denom) / 8;
12296  maxFrameSize = min_maxFrameSize * maxFrameSizeRatio > NI_MAX_FRAME_SIZE ?
12297  NI_MAX_FRAME_SIZE : min_maxFrameSize * maxFrameSizeRatio;
12298  *((int32_t *)aux_data->data) = maxFrameSize;
12299  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12300  "xcoder_send_frame: frame #%lu reconf "
12301  "maxFrameSizeRatio %d maxFrameSize %d\n",
12302  p_enc_ctx->frame_num, maxFrameSizeRatio, maxFrameSize);
12303 
12304  p_enc_ctx->reconfigCount++;
12305  }
12306  break;
12308  if (p_enc_ctx->frame_num ==
12309  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12310  aux_data = ni_frame_new_aux_data(
12311  p_frame, NI_FRAME_AUX_DATA_SLICE_ARG, sizeof(int16_t));
12312  if (!aux_data) {
12314  }
12315  *((int16_t *)aux_data->data) =
12316  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12317  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12318  "xcoder_send_frame: frame #%lu reconf "
12319  "sliceArg %d\n",
12320  p_enc_ctx->frame_num,
12321  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12322 
12323  p_enc_ctx->reconfigCount++;
12324  }
12325  break;
12326  // force IDR frame through API test code
12328  if (p_enc_ctx->frame_num ==
12329  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12330  ni_force_idr_frame_type(p_enc_ctx);
12331  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12332  "xcoder_send_frame: frame #%lu force IDR frame\n",
12333  p_enc_ctx->frame_num);
12334 
12335  p_enc_ctx->reconfigCount++;
12336  }
12337  break;
12338  // reconfig bit rate through API test code
12340  if (p_enc_ctx->frame_num ==
12341  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12342  if ((retval = ni_reconfig_bitrate(
12343  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))){
12344  return retval;
12345  }
12346  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12347  "xcoder_send_frame: frame #%lu API reconfig BR %d\n",
12348  p_enc_ctx->frame_num,
12349  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12350 
12351  p_enc_ctx->reconfigCount++;
12352  }
12353  break;
12355  if (p_enc_ctx->frame_num ==
12356  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12357  int32_t intraprd =
12358  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12359  if ((retval = ni_reconfig_intraprd(p_enc_ctx, intraprd))){
12360  return retval;
12361  }
12363  "xcoder_send_frame: frame #%lu API reconfig intraPeriod %d\n",
12364  p_enc_ctx->frame_num,
12365  intraprd);
12366 
12367  p_enc_ctx->reconfigCount++;
12368  }
12369  break;
12371  if (p_enc_ctx->frame_num ==
12372  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12373  ni_vui_hrd_t vui;
12374  vui.colorDescPresent =
12375  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12376  vui.colorPrimaries =
12377  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12378  vui.colorTrc =
12379  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12380  vui.colorSpace =
12381  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12382  vui.aspectRatioWidth =
12383  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12384  vui.aspectRatioHeight =
12385  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12386  vui.videoFullRange =
12387  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12388  if ((retval = ni_reconfig_vui(p_enc_ctx, &vui))){
12389  return retval;
12390  }
12391  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12392  "xcoder_send_frame: frame #%lu reconf "
12393  "vui colorDescPresent %d colorPrimaries %d "
12394  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12395  "aspectRatioHeight %d videoFullRange %d\n",
12396  p_enc_ctx->frame_num, vui.colorDescPresent,
12397  vui.colorPrimaries, vui.colorTrc,
12398  vui.colorSpace, vui.aspectRatioWidth,
12400  p_enc_ctx->reconfigCount++;
12401  }
12402  break;
12404  if (p_enc_ctx->frame_num ==
12405  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12406  ni_long_term_ref_t ltr;
12408  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12409  ltr.use_long_term_ref =
12410  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12411 
12412  if ((retval = ni_set_ltr(p_enc_ctx, &ltr))) {
12413  return retval;
12414  }
12415  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12416  "xcoder_send_frame(): frame #%lu API set LTR\n",
12417  p_enc_ctx->frame_num);
12418  p_enc_ctx->reconfigCount++;
12419  }
12420  break;
12423  if (p_enc_ctx->frame_num ==
12424  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12425  ni_rc_min_max_qp qp_info;
12426  qp_info.minQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12427  qp_info.maxQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12428  qp_info.maxDeltaQp = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12429  qp_info.minQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12430  qp_info.maxQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12431  if ((retval = ni_reconfig_min_max_qp(p_enc_ctx, &qp_info))) {
12432  return retval;
12433  }
12434  ni_log2(p_enc_ctx, NI_LOG_DEBUG,
12435  "%s(): frame %d minQpI %d maxQpI %d maxDeltaQp %d minQpPB %d maxQpPB %d\n",
12436  __func__, p_enc_ctx->frame_num,
12437  qp_info.minQpI, qp_info.maxQpI, qp_info.maxDeltaQp, qp_info.minQpPB, qp_info.maxQpPB);
12438  p_enc_ctx->reconfigCount++;
12439  }
12440  break;
12442  if (p_enc_ctx->frame_num ==
12443  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12444  if ((retval = ni_set_ltr_interval(
12445  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12446  return retval;
12447  }
12448  ni_log2(p_enc_ctx,
12449  NI_LOG_TRACE,
12450  "xcoder_send_frame(): frame #%lu API set LTR interval %d\n",
12451  p_enc_ctx->frame_num,
12452  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12453  p_enc_ctx->reconfigCount++;
12454  }
12455  break;
12457  if (p_enc_ctx->frame_num ==
12458  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12459  if ((retval = ni_set_frame_ref_invalid(
12460  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12461  return retval;
12462  }
12463  ni_log2(p_enc_ctx,
12464  NI_LOG_TRACE,
12465  "xcoder_send_frame(): frame #%lu API set frame ref invalid "
12466  "%d\n",
12467  p_enc_ctx->frame_num,
12468  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12469  p_enc_ctx->reconfigCount++;
12470  }
12471  break;
12473  if (p_enc_ctx->frame_num ==
12474  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12475  ni_framerate_t framerate;
12476  framerate.framerate_num =
12477  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12478  framerate.framerate_denom =
12479  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12480  if ((retval = ni_reconfig_framerate(p_enc_ctx, &framerate))) {
12481  return retval;
12482  }
12483  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12484  "xcoder_send_frame: frame #%lu API reconfig framerate "
12485  "(%d/%d)\n",
12486  p_enc_ctx->frame_num,
12487  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12488  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12489 
12490  p_enc_ctx->reconfigCount++;
12491  }
12492  break;
12494  if (p_enc_ctx->frame_num ==
12495  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12496  if ((retval = ni_reconfig_max_frame_size(
12497  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12498  return retval;
12499  }
12500  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12501  "xcoder_send_frame: frame #%lu API reconfig maxFrameSize %d\n",
12502  p_enc_ctx->frame_num,
12503  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12504 
12505  p_enc_ctx->reconfigCount++;
12506  }
12507  break;
12508  case XCODER_TEST_CRF_API:
12509  if (p_enc_ctx->frame_num ==
12510  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12511  if ((retval = ni_reconfig_crf(
12512  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12513  return retval;
12514  }
12515  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12516  "xcoder_send_frame: frame #%lu API reconfig crf %d\n",
12517  p_enc_ctx->frame_num,
12518  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12519 
12520  p_enc_ctx->reconfigCount++;
12521  }
12522  break;
12524  if (p_enc_ctx->frame_num ==
12525  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12526  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12527  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12528  if ((retval = ni_reconfig_crf2(p_enc_ctx, crf))) {
12529  return retval;
12530  }
12531  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12532  "xcoder_send_frame: frame #%lu API reconfig crf %f\n",
12533  p_enc_ctx->frame_num, crf);
12534 
12535  p_enc_ctx->reconfigCount++;
12536  }
12537  break;
12539  if (p_enc_ctx->frame_num ==
12540  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12541  if ((retval = ni_reconfig_vbv_value(
12542  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12543  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]))) {
12544  return retval;
12545  }
12546  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12547  "xcoder_send_frame: frame #%lu API reconfig vbvMaxRate %d vbvBufferSize %d\n",
12548  p_enc_ctx->frame_num,
12549  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12550  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12551 
12552  p_enc_ctx->reconfigCount++;
12553  }
12554  break;
12556  if (p_enc_ctx->frame_num ==
12557  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12558 
12559  if ((retval = ni_reconfig_max_frame_size_ratio(
12560  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12561  return retval;
12562  }
12563  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12564  "xcoder_send_frame: frame #%lu reconf maxFrameSizeRatio %d\n",
12565  p_enc_ctx->frame_num, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12566 
12567  p_enc_ctx->reconfigCount++;
12568  }
12569  break;
12571  if (p_enc_ctx->frame_num ==
12572  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12573  if ((retval = ni_reconfig_slice_arg(
12574  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12575  return retval;
12576  }
12577  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12578  "xcoder_send_frame: frame #%lu API reconfig sliceArg %d\n",
12579  p_enc_ctx->frame_num,
12580  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12581 
12582  p_enc_ctx->reconfigCount++;
12583  }
12584  break;
12585 #endif
12587  default:
12588  ;
12589  }
12590  return NI_RETCODE_SUCCESS;
12591 }
12592 
12596 static int ni_tolower(int c)
12597 {
12598  if (c >= 'A' && c <= 'Z')
12599  c ^= 0x20;
12600  return c;
12601 }
12602 
12603 int ni_strcasecmp(const char *a, const char *b)
12604 {
12605  uint8_t c1, c2;
12606  do
12607  {
12608  c1 = ni_tolower(*a++);
12609  c2 = ni_tolower(*b++);
12610  } while (c1 && c1 == c2);
12611  return c1 - c2;
12612 }
12613 
12614 void ni_gop_params_check_set(ni_xcoder_params_t *p_param, char *value)
12615 {
12616  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
12617  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
12619  p_gop->pic_param[0].rps[0].ref_pic = 1;
12621  p_gop->pic_param[0].rps[0].ref_pic_used = 1;
12623  p_gop->pic_param[0].rps[1].ref_pic = 1;
12625  p_gop->pic_param[0].rps[1].ref_pic_used = 1;
12627  p_gop->pic_param[0].rps[2].ref_pic = 1;
12629  p_gop->pic_param[0].rps[2].ref_pic_used = 1;
12631  p_gop->pic_param[0].rps[3].ref_pic = 1;
12633  p_gop->pic_param[0].rps[3].ref_pic_used = 1;
12635  p_gop->pic_param[1].rps[0].ref_pic = 1;
12637  p_gop->pic_param[1].rps[0].ref_pic_used = 1;
12639  p_gop->pic_param[1].rps[1].ref_pic = 1;
12641  p_gop->pic_param[1].rps[1].ref_pic_used = 1;
12643  p_gop->pic_param[1].rps[2].ref_pic = 1;
12645  p_gop->pic_param[1].rps[2].ref_pic_used = 1;
12647  p_gop->pic_param[1].rps[3].ref_pic = 1;
12649  p_gop->pic_param[1].rps[3].ref_pic_used = 1;
12651  p_gop->pic_param[2].rps[0].ref_pic = 1;
12653  p_gop->pic_param[2].rps[0].ref_pic_used = 1;
12655  p_gop->pic_param[2].rps[1].ref_pic = 1;
12657  p_gop->pic_param[2].rps[1].ref_pic_used = 1;
12659  p_gop->pic_param[2].rps[2].ref_pic = 1;
12661  p_gop->pic_param[2].rps[2].ref_pic_used = 1;
12663  p_gop->pic_param[2].rps[3].ref_pic = 1;
12665  p_gop->pic_param[2].rps[3].ref_pic_used = 1;
12667  p_gop->pic_param[3].rps[0].ref_pic = 1;
12669  p_gop->pic_param[3].rps[0].ref_pic_used = 1;
12671  p_gop->pic_param[3].rps[1].ref_pic = 1;
12673  p_gop->pic_param[3].rps[1].ref_pic_used = 1;
12675  p_gop->pic_param[3].rps[2].ref_pic = 1;
12677  p_gop->pic_param[3].rps[2].ref_pic_used = 1;
12679  p_gop->pic_param[3].rps[3].ref_pic = 1;
12681  p_gop->pic_param[3].rps[3].ref_pic_used = 1;
12683  p_gop->pic_param[4].rps[0].ref_pic = 1;
12685  p_gop->pic_param[4].rps[0].ref_pic_used = 1;
12687  p_gop->pic_param[4].rps[1].ref_pic = 1;
12689  p_gop->pic_param[4].rps[1].ref_pic_used = 1;
12691  p_gop->pic_param[4].rps[2].ref_pic = 1;
12693  p_gop->pic_param[4].rps[2].ref_pic_used = 1;
12695  p_gop->pic_param[4].rps[3].ref_pic = 1;
12697  p_gop->pic_param[4].rps[3].ref_pic_used = 1;
12699  p_gop->pic_param[5].rps[0].ref_pic = 1;
12701  p_gop->pic_param[5].rps[0].ref_pic_used = 1;
12703  p_gop->pic_param[5].rps[1].ref_pic = 1;
12705  p_gop->pic_param[5].rps[1].ref_pic_used = 1;
12707  p_gop->pic_param[5].rps[2].ref_pic = 1;
12709  p_gop->pic_param[5].rps[2].ref_pic_used = 1;
12711  p_gop->pic_param[5].rps[3].ref_pic = 1;
12713  p_gop->pic_param[5].rps[3].ref_pic_used = 1;
12715  p_gop->pic_param[6].rps[0].ref_pic = 1;
12717  p_gop->pic_param[6].rps[0].ref_pic_used = 1;
12719  p_gop->pic_param[6].rps[1].ref_pic = 1;
12721  p_gop->pic_param[6].rps[1].ref_pic_used = 1;
12723  p_gop->pic_param[6].rps[2].ref_pic = 1;
12725  p_gop->pic_param[6].rps[2].ref_pic_used = 1;
12727  p_gop->pic_param[6].rps[3].ref_pic = 1;
12729  p_gop->pic_param[6].rps[3].ref_pic_used = 1;
12731  p_gop->pic_param[7].rps[0].ref_pic = 1;
12733  p_gop->pic_param[7].rps[0].ref_pic_used = 1;
12735  p_gop->pic_param[7].rps[1].ref_pic = 1;
12737  p_gop->pic_param[7].rps[1].ref_pic_used = 1;
12739  p_gop->pic_param[7].rps[2].ref_pic = 1;
12741  p_gop->pic_param[7].rps[2].ref_pic_used = 1;
12743  p_gop->pic_param[7].rps[3].ref_pic = 1;
12745  p_gop->pic_param[7].rps[3].ref_pic_used = 1;
12746 
12747 }
12748 
12750 {
12751  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
12752  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
12753  int i, j;
12754  for (i=0; i<NI_MAX_GOP_NUM; i++)
12755  {
12756  for (j=0; j<NI_MAX_REF_PIC; j++)
12757  {
12758  if (p_gop->pic_param[i].rps[j].ref_pic == 1 &&
12759  p_gop->pic_param[i].rps[j].ref_pic_used != 1)
12760  {
12762  "g%drefPic%d specified without g%drefPic%dUsed specified!\n",
12763  i, j, i, j);
12764  return false;
12765  }
12766  }
12767  }
12768  // set custom_gop_params default.
12769  for (i=0; i<NI_MAX_GOP_NUM; i++)
12770  {
12771  for (j=0; j<NI_MAX_REF_PIC; j++)
12772  {
12773  p_gop->pic_param[i].rps[j].ref_pic = 0;
12774  p_gop->pic_param[i].rps[j].ref_pic_used = 0;
12775  }
12776  }
12777  return true;
12778 }
12779 
12780 /*!*****************************************************************************
12781  * \brief Initiate P2P transfer (P2P write) (deprecated)
12782  *
12783  * \param[in] pSession Pointer to source card destination
12784  * \param[in] source Pointer to source frame to transmit
12785  * \param[in] ui64DestAddr Destination address on target device
12786  * \param[in] ui32FrameSize Size of frame to transfer
12787  *
12788  * \return always returns
12789  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12790 *******************************************************************************/
12792  niFrameSurface1_t *source,
12793  uint64_t ui64DestAddr,
12794  uint32_t ui32FrameSize)
12795 {
12796  // avoid compiler warnings
12797  (void) pSession;
12798  (void) source;
12799  (void) ui64DestAddr;
12800  (void) ui32FrameSize;
12801 
12803 }
12804 
12805 /*!*****************************************************************************
12806  * \brief Initiate P2P transfer (P2P write)
12807  *
12808  * \param[in] pSession Pointer to source card destination
12809  * \param[in] source Pointer to source frame to transmit
12810  * \param[in] ui64DestAddr Destination address on target device
12811  * \param[in] ui32FrameSize Size of frame to transfer
12812  *
12813  * \return on success
12814  * NI_RETCODE_SUCCESS
12815  * on failure
12816  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12817  * NI_RETCODE_INVALID_PARAM
12818  * NI_RETCODE_ERROR_INVALID_SESSION
12819  * NI_RETCODE_ERROR_MEM_ALOC
12820  * NI_RETCODE_ERROR_NVME_CMD_FAILED
12821 *******************************************************************************/
12823  niFrameSurface1_t *source,
12824  uint64_t ui64DestAddr, uint32_t ui32FrameSize)
12825 {
12827 
12828  if ((pSession == NULL) || (source == NULL))
12829  {
12830  return NI_RETCODE_INVALID_PARAM;
12831  }
12832 
12833  /* Firmware compatibility check */
12834  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
12835  {
12836  ni_log2(pSession, NI_LOG_ERROR, "%s: FW doesn't support this operation\n", __func__);
12838  }
12839 
12840  retval = ni_send_to_target(pSession, source, ui64DestAddr, ui32FrameSize);
12841 
12842  if (retval < 0)
12843  {
12844  ni_log2(pSession, NI_LOG_ERROR, "%s(): Can't DMA to destination (%d)\n", __func__, retval);
12845  }
12846 
12847  return retval;
12848 }
12849 
12850 /*!*****************************************************************************
12851  * \brief Initiate a P2P transfer (P2P read)
12852  *
12853  * \param[in] pSession Pointer to destination upload session
12854  * \param[in] dmaAddrs Pointer to source DMA addresses
12855  * \param[in] pDstFrame Pointer to destination P2P frame
12856  *
12857  * \return on success
12858  * NI_RETCODE_SUCCESS
12859  * on failure
12860  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12861  * NI_RETCODE_INVALID_PARAM
12862  * NI_RETCODE_ERROR_INVALID_SESSION
12863  * NI_RETCODE_ERROR_MEM_ALOC
12864  * NI_RETCODE_ERROR_NVME_CMD_FAILED
12865 *******************************************************************************/
12867  const ni_p2p_sgl_t *dmaAddrs,
12868  ni_frame_t *pDstFrame)
12869 {
12871 
12872  if ((pSession == NULL) || (dmaAddrs == NULL) || (pDstFrame == NULL))
12873  {
12874  return NI_RETCODE_INVALID_PARAM;
12875  }
12876 
12877  /* Firmware compatibility check */
12878  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
12879  {
12880  ni_log2(pSession, NI_LOG_ERROR,
12881  "%s: FW doesn't support this operation\n", __func__);
12883  }
12884 
12885  retval = ni_recv_from_target(pSession, dmaAddrs, pDstFrame);
12886 
12887  if (retval < 0)
12888  {
12889  ni_log2(pSession, NI_LOG_ERROR,
12890  "%s(): Can't DMA from source (%d)\n", __func__, retval);
12891  retval = NI_RETCODE_INVALID_PARAM;
12892  }
12893 
12894  return retval;
12895 }
12896 
12897 /*!*****************************************************************************
12898  * \brief Send a restart command after flush command
12899  * Only support Encoder now
12900  *
12901  * \param[in] p_ctx Pointer to a caller allocated
12902  * ni_session_context_t struct
12903  * \param[in] width width, in pixels
12904  * \param[in] height height, in pixels
12905  * \param[in] device_type NI_DEVICE_TYPE_ENCODER
12906  * \return On success
12907  * NI_RETCODE_SUCCESS
12908  * On failure
12909  * NI_RETCODE_INVALID_PARAM
12910  * NI_RETCODE_ERROR_NVME_CMD_FAILED
12911  * NI_RETCODE_ERROR_INVALID_SESSION
12912  ******************************************************************************/
12914  int video_width,
12915  int video_height,
12916  ni_device_type_t device_type)
12917 {
12918  ni_retcode_t retval = 0;
12919  ni_resolution_t resolution;
12920  ni_xcoder_params_t *p_param = NULL;
12921 
12922  if (!p_ctx)
12923  {
12924  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
12925  __func__);
12926  return NI_RETCODE_INVALID_PARAM;
12927  }
12928 
12929  switch (device_type)
12930  {
12932  {
12933  // requires API version >= 54
12935  "54") < 0)
12936  {
12937  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
12939  }
12940 
12941  /* This function should be called only if flushing is detected */
12943  {
12944  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() wrong state %d\n",
12945  __func__, p_ctx->session_run_state);
12947  }
12948 
12949  if (video_width < NI_MIN_WIDTH || video_width > NI_MAX_WIDTH ||
12950  video_height < NI_MIN_HEIGHT || video_height > NI_MAX_HEIGHT)
12951  {
12952  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() invalid width %d or height %d\n",
12953  __func__, video_width, video_height);
12954  return NI_RETCODE_INVALID_PARAM;
12955  }
12956  resolution.width = video_width;
12957  resolution.height = video_height;
12958  resolution.bit_depth_factor = p_ctx->bit_depth_factor;
12959  resolution.luma_linesize = 0;
12960  resolution.chroma_linesize = 0;
12961  if (p_ctx->p_session_config)
12962  {
12963  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
12964  resolution.luma_linesize = p_param->luma_linesize;
12965  resolution.chroma_linesize = p_param->chroma_linesize;
12966  }
12967  ni_pthread_mutex_lock(&p_ctx->mutex);
12968 
12969  // reconfig the encoder session
12970  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
12971  if (NI_RETCODE_SUCCESS != retval)
12972  {
12973  ni_log(NI_LOG_ERROR, "Failed to reconfig config the encoder session (status = %d)\n", retval);
12974  ni_pthread_mutex_unlock(&p_ctx->mutex);
12975  return retval;
12976  }
12977 
12978  // update session context
12979  p_ctx->ready_to_close = 0;
12980  p_ctx->frame_num = 0;
12981  p_ctx->pkt_num = 0;
12982  ni_pthread_mutex_unlock(&p_ctx->mutex);
12983  break;
12984  }
12985  default:
12986  {
12987  retval = NI_RETCODE_INVALID_PARAM;
12988  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unsupported device type: %d",
12989  __func__, device_type);
12990  break;
12991  }
12992  }
12993  return retval;
12994 }
XCODER_TEST_RECONF_LTR_INTERVAL_API
@ XCODER_TEST_RECONF_LTR_INTERVAL_API
Definition: ni_device_api.h:1765
NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
Definition: ni_device_api.h:1866
_ni_xcoder_params::reconf_demo_mode
int reconf_demo_mode
Definition: ni_device_api.h:2731
CONFIG_INSTANCE_SetScalerWatermarkPara_W
#define CONFIG_INSTANCE_SetScalerWatermarkPara_W(sid, instance)
Definition: ni_nvme.h:830
NI_MAX_FRAMERATE
#define NI_MAX_FRAMERATE
Definition: ni_device_api.h:116
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:11713
_ni_encoder_cfg_params::enable_mb_level_rc
int enable_mb_level_rc
Definition: ni_device_api.h:2384
_ni_long_term_ref::use_long_term_ref
uint8_t use_long_term_ref
Definition: ni_device_api.h:691
NI_ENC_PARAM_ROI_DEMO_MODE
#define NI_ENC_PARAM_ROI_DEMO_MODE
Definition: ni_device_api.h:2065
_ni_encoder_cfg_params::frame_rate
int frame_rate
Definition: ni_device_api.h:2239
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
Definition: ni_device_api.h:286
NI_XCODER_CLOSE_STATE
@ NI_XCODER_CLOSE_STATE
Definition: ni_device_api.h:248
ni_set_demo_roi_map
ni_retcode_t ni_set_demo_roi_map(ni_session_context_t *p_enc_ctx)
Set up hard coded demo ROI map.
Definition: ni_device_api.c:11751
_ni_xcoder_params::fps_denominator
uint32_t fps_denominator
Definition: ni_device_api.h:2719
NI_PIX_FMT_UYVY422
@ NI_PIX_FMT_UYVY422
Definition: ni_device_api.h:274
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:11232
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:2189
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:18089
_ni_xcoder_params::luma_linesize
int luma_linesize
Definition: ni_device_api.h:2784
ni_pthread_mutex_unlock
int ni_pthread_mutex_unlock(ni_pthread_mutex_t *mutex)
thread mutex unlock
Definition: ni_util.c:4083
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC0
Definition: ni_device_api.h:1869
NI_PIX_FMT_BGRA
@ NI_PIX_FMT_BGRA
Definition: ni_device_api.h:267
_ni_scaler_input_params_t::output_height
int32_t output_height
Definition: ni_device_api.h:2556
_ni_session_context::force_idr_frame
int force_idr_frame
Definition: ni_device_api.h:1600
NI_CODEC_FORMAT_JPEG
@ NI_CODEC_FORMAT_JPEG
Definition: ni_device_api.h:914
_ni_encoder_cfg_params::ver_offset
int ver_offset
Definition: ni_device_api.h:2398
NI_DEC_PARAM_SCALE_0_RES_CEIL
#define NI_DEC_PARAM_SCALE_0_RES_CEIL
Definition: ni_device_api.h:2468
NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
@ NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
Definition: ni_device_api.h:566
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:4177
NI_ENC_PARAM_ZEROCOPY_MODE
#define NI_ENC_PARAM_ZEROCOPY_MODE
Definition: ni_device_api.h:2196
_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:4066
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:8671
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:17517
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:4032
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:587
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1885
NI_DEC_PARAM_SKIP_PTS_GUESS
#define NI_DEC_PARAM_SKIP_PTS_GUESS
Definition: ni_device_api.h:2490
NI_MAX_RESOLUTION_HEIGHT
#define NI_MAX_RESOLUTION_HEIGHT
Definition: ni_device_api.h:101
_ni_session_context::hevc_sub_ctu_roi_buf
uint8_t * hevc_sub_ctu_roi_buf
Definition: ni_device_api.h:1587
_ni_decoder_input_params_t::mcmode
int mcmode
Definition: ni_device_api.h:2502
ni_encoder_params_set_value
ni_retcode_t ni_encoder_params_set_value(ni_xcoder_params_t *p_params, const char *name, const char *value)
Set value referenced by name in encoder parameters structure.
Definition: ni_device_api.c:5635
NI_DEVICE_TYPE_ENCODER
@ NI_DEVICE_TYPE_ENCODER
Definition: ni_defs.h:347
NI_ENC_PARAM_MAX_FRAME_SIZE_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_LOW_DELAY
Definition: ni_device_api.h:2146
NI_DEC_PARAM_SCALE_2_RES_CEIL
#define NI_DEC_PARAM_SCALE_2_RES_CEIL
Definition: ni_device_api.h:2470
_ni_frame::separate_start
uint8_t separate_start
Definition: ni_device_api.h:2707
g_xcoder_log_names
const char *const g_xcoder_log_names[NI_XCODER_LOG_NAMES_ARRAY_LEN]
Definition: ni_device_api.c:71
XCODER_TEST_RECONF_CRF_FLOAT
@ XCODER_TEST_RECONF_CRF_FLOAT
Definition: ni_device_api.h:1755
NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
#define NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:2079
_ni_p2p_sgl_t
Definition: ni_defs.h:403
NI_MIN_MAX_NUM_MERGE
#define NI_MIN_MAX_NUM_MERGE
Definition: ni_device_api.h:164
_ni_frame::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2667
NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
#define NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
Definition: ni_device_api.h:2228
_ni_network_data
Definition: ni_device_api.h:1363
_ni_xcoder_params::dolby_vision_profile
int dolby_vision_profile
Definition: ni_device_api.h:2739
_ni_session_context::ltr_interval
int32_t ltr_interval
Definition: ni_device_api.h:1602
NI_DEC_PARAM_SCALE_0
#define NI_DEC_PARAM_SCALE_0
Definition: ni_device_api.h:2462
_ni_resolution::chroma_linesize
int32_t chroma_linesize
Definition: ni_device_api_priv.h:682
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1936
_ni_session_context::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:1594
_ni_decoder_input_params_t::error_ratio_threshold
int error_ratio_threshold
Definition: ni_device_api.h:2538
NI_ENC_PARAM_CONF_WIN_RIGHT
#define NI_ENC_PARAM_CONF_WIN_RIGHT
Definition: ni_device_api.h:2099
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:2080
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:9562
_ni_thread_arg_struct_t::p_mutex
ni_pthread_mutex_t * p_mutex
Definition: ni_device_api.h:1267
NI_ENC_PARAM_TOL_RC_INTRA
#define NI_ENC_PARAM_TOL_RC_INTRA
Definition: ni_device_api.h:2157
_ni_encoder_cfg_params::skip_frame_interval
int skip_frame_interval
Definition: ni_device_api.h:2419
ni_pix_fmt_t
ni_pix_fmt_t
Definition: ni_device_api.h:260
NI_EC_POLICY_SKIP
#define NI_EC_POLICY_SKIP
Definition: ni_device_api.h:320
QUERY_GET_NVME_STATUS_R
#define QUERY_GET_NVME_STATUS_R
Definition: ni_nvme.h:791
NI_XCODER_PRESET_NAME_CUSTOM
#define NI_XCODER_PRESET_NAME_CUSTOM
Definition: ni_device_api.h:2880
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:2352
_ni_encoder_cfg_params::hor_offset
int hor_offset
Definition: ni_device_api.h:2397
_ni_encoder_cfg_params::inLoopDSRatio
int inLoopDSRatio
Definition: ni_device_api.h:2335
NI_ENC_PARAM_GET_PSNR_MODE
#define NI_ENC_PARAM_GET_PSNR_MODE
Definition: ni_device_api.h:2226
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:2621
NI_ENC_PARAM_LTR_REF_INTERVAL
#define NI_ENC_PARAM_LTR_REF_INTERVAL
Definition: ni_device_api.h:2149
XCODER_TEST_RECONF_END
@ XCODER_TEST_RECONF_END
Definition: ni_device_api.h:1775
NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2218
XCODER_TEST_CRF_API
@ XCODER_TEST_CRF_API
Definition: ni_device_api.h:1770
_ni_enc_avc_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:870
NI_ENC_PARAM_INTRA_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_REFRESH_MODE
Definition: ni_device_api.h:2115
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:14055
NI_XCODER_LOG_NAME_WARN
#define NI_XCODER_LOG_NAME_WARN
Definition: ni_device_api.h:2884
NI_MAX_DYNAMIC_MERGE
#define NI_MAX_DYNAMIC_MERGE
Definition: ni_device_api.h:159
NI_ENC_PARAM_CONF_WIN_LEFT
#define NI_ENC_PARAM_CONF_WIN_LEFT
Definition: ni_device_api.h:2098
ni_frame_buffer_free
ni_retcode_t ni_frame_buffer_free(ni_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_frame_buffer_alloc or ni_encoder_frame...
Definition: ni_device_api.c:3561
OPT
#define OPT(STR)
NI_ENC_GOP_PARAMS_G5_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G5_PIC_TYPE
Definition: ni_device_api.h:1912
NI_ENC_PARAM_TRANS_RATE
#define NI_ENC_PARAM_TRANS_RATE
Definition: ni_device_api.h:2101
NI_DEC_PARAM_PKT_PTS_UNCHANGE
#define NI_DEC_PARAM_PKT_PTS_UNCHANGE
Definition: ni_device_api.h:2491
_ni_decoder_input_params_t::enable_ppu_scale_adapt
int enable_ppu_scale_adapt
Definition: ni_device_api.h:2525
_ni_encoder_cfg_params::pbRatio
float pbRatio
Definition: ni_device_api.h:2405
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
Definition: ni_device_api.h:1935
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:5715
_ni_decoder_input_params_t::enable_out1
int enable_out1
Definition: ni_device_api.h:2500
_ni_network_layer_info::in_param
ni_network_layer_params_t * in_param
Definition: ni_device_api.h:1354
_ni_encoder_cfg_params::vbvBufferReencode
int vbvBufferReencode
Definition: ni_device_api.h:2442
_ni_session_context::nb_rois
int nb_rois
Definition: ni_device_api.h:1581
_ni_session_context::xcoder_state
uint32_t xcoder_state
Definition: ni_device_api.h:1568
NI_ENC_BLOCK_RC_SIZE
#define NI_ENC_BLOCK_RC_SIZE
Definition: ni_device_api.h:2160
XCODER_TEST_RECONF_MAX_FRAME_SIZE
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE
Definition: ni_device_api.h:1752
_ni_xcoder_params::padding
int padding
Definition: ni_device_api.h:2734
_ni_encoder_cfg_params::enable_filler
int enable_filler
Definition: ni_device_api.h:2376
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:147
_ni_session_context::force_low_delay
bool force_low_delay
Definition: ni_device_api.h:1699
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1932
ni_config_instance_hvsplus
ni_retcode_t ni_config_instance_hvsplus(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:16033
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:3397
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:17125
_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:123
NI_ENC_GOP_PARAMS_G4_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G4_QP_OFFSET
Definition: ni_device_api.h:1894
NI_DEC_PARAM_LOW_DELAY
#define NI_DEC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2476
_ni_encoder_cfg_params::gopLowdelay
int gopLowdelay
Definition: ni_device_api.h:2324
NI_XCODER_LOG_NAME_FULL
#define NI_XCODER_LOG_NAME_FULL
Definition: ni_device_api.h:2887
NI_MIN_KEEP_ALIVE_TIMEOUT
#define NI_MIN_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:310
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:9095
NI_DEC_PARAM_ENABLE_OUT_2
#define NI_DEC_PARAM_ENABLE_OUT_2
Definition: ni_device_api.h:2449
_ni_gop_rps::ref_pic_used
int ref_pic_used
Definition: ni_device_api.h:1956
_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:1488
NI_ENC_NEW_RC_ENABLE
#define NI_ENC_NEW_RC_ENABLE
Definition: ni_device_api.h:2163
NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
#define NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
Definition: ni_device_api.h:2192
_ni_scaler_input_params_t::op
ni_scaler_opcode_t op
Definition: ni_device_api.h:2563
NI_INVALID_IO_SIZE
#define NI_INVALID_IO_SIZE
Definition: ni_defs.h:221
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:1920
_ni_session_context::frame_time_q
void * frame_time_q
Definition: ni_device_api.h:1413
XCODER_TEST_RECONF_LTR_INTERVAL
@ XCODER_TEST_RECONF_LTR_INTERVAL
Definition: ni_device_api.h:1749
_ni_encoder_cfg_params::statistic_output_level
int statistic_output_level
Definition: ni_device_api.h:2416
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1846
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:17879
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:2082
NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
#define NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
Definition: ni_device_api.h:2219
XCODER_TEST_RECONF_FRAMERATE_API
@ XCODER_TEST_RECONF_FRAMERATE_API
Definition: ni_device_api.h:1767
_ni_decoder_input_params_t::ec_policy
int ec_policy
Definition: ni_device_api.h:2523
NI_ENC_PARAM_MAX_QP
#define NI_ENC_PARAM_MAX_QP
Definition: ni_device_api.h:2092
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:1914
_ni_frame::metadata_buffer_size
uint32_t metadata_buffer_size
Definition: ni_device_api.h:2696
_ni_decoder_input_params_t::skip_pts_guess
int skip_pts_guess
Definition: ni_device_api.h:2528
NI_ENC_PARAM_BITRATE
#define NI_ENC_PARAM_BITRATE
Definition: ni_device_api.h:2062
_ni_vui_hrd
Definition: ni_device_api.h:654
_ni_rc_min_max_qp::minQpI
int32_t minQpI
Definition: ni_device_api.h:706
_ni_encoder_cfg_params::temporal_layers_enable
int temporal_layers_enable
Definition: ni_device_api.h:2392
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:14003
NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
Definition: ni_device_api.h:2167
ni_device_close
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
Definition: ni_device_api.c:503
NI_NUM_OF_PIXELS_1080P
#define NI_NUM_OF_PIXELS_1080P
Definition: ni_device_api.h:77
_ni_session_context::fn
unsigned short fn
Definition: ni_device_api.h:1622
netint_iocmd_attach_rfence
Definition: ni_p2p_ioctl.h:80
_niFrameSurface1::ui16height
uint16_t ui16height
Definition: ni_device_api.h:2798
NI_DEVICE_TYPE_DECODER
@ NI_DEVICE_TYPE_DECODER
Definition: ni_defs.h:346
_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:1181
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1844
NI_ENC_PARAM_ALLOCATE_STRAEGY
#define NI_ENC_PARAM_ALLOCATE_STRAEGY
Definition: ni_device_api.h:2231
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:9992
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:11029
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1876
_ni_session_context::roi_side_data_size
int roi_side_data_size
Definition: ni_device_api.h:1578
NI_ENC_PARAM_CU_SIZE_MODE
#define NI_ENC_PARAM_CU_SIZE_MODE
Definition: ni_device_api.h:2081
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
Definition: ni_device_api.h:1769
NI_MIN_INTRA_QP_DELTA
#define NI_MIN_INTRA_QP_DELTA
Definition: ni_device_api.h:168
_ni_session_context::input_frame_fifo
ni_input_frame input_frame_fifo[120]
encoder:calculate PSNR start
Definition: ni_device_api.h:1709
_ni_session_context::current_frame_delay
int current_frame_delay
Definition: ni_device_api.h:1693
_ni_scaler_watermark_params_t
Definition: ni_device_api.h:2584
NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
Definition: ni_device_api.h:1851
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:1480
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:15554
_ni_xcoder_params::source_width
int source_width
Definition: ni_device_api.h:2723
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:2652
NI_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_RETCODE_ERROR_GET_DEVICE_POOL
Definition: ni_defs.h:506
NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
#define NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
Definition: ni_device_api.h:2493
NI_PARAM_AV1_MAX_WIDTH
#define NI_PARAM_AV1_MAX_WIDTH
Definition: ni_device_api.h:145
NI_MAX_PACKET_SZ
#define NI_MAX_PACKET_SZ
Definition: ni_defs.h:227
NI_ENC_PARAM_GDR_DURATION
#define NI_ENC_PARAM_GDR_DURATION
Definition: ni_device_api.h:2138
_ni_input_frame::usable
int8_t usable
Definition: ni_device_api.h:1405
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:9909
_ni_decoder_input_params_t::enable_ppu_scale_limit
int enable_ppu_scale_limit
Definition: ni_device_api.h:2526
_ni_scaler_input_params_t::out_rec_height
int32_t out_rec_height
Definition: ni_device_api.h:2558
NI_SCALER_OPCODE_WATERMARK
@ NI_SCALER_OPCODE_WATERMARK
Definition: ni_defs.h:582
_ni_encoder_cfg_params::ltrRefInterval
int ltrRefInterval
Definition: ni_device_api.h:2285
_ni_session_context::target_bitrate
int32_t target_bitrate
Definition: ni_device_api.h:1599
_ni_session_context::mutex_initialized
bool mutex_initialized
Definition: ni_device_api.h:1671
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:11509
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:8612
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:15766
ni_device_session_sequence_change
ni_retcode_t ni_device_session_sequence_change(ni_session_context_t *p_ctx, int width, int height, int bit_depth_factor, ni_device_type_t device_type)
Send sequence change information to device.
Definition: ni_device_api.c:11322
NI_ENC_PARAM_CONF_WIN_TOP
#define NI_ENC_PARAM_CONF_WIN_TOP
Definition: ni_device_api.h:2096
_ni_session_context::netint_fd
int netint_fd
Definition: ni_device_api.h:1618
QOS_OP_CONFIG_REC_OP_CODE
@ QOS_OP_CONFIG_REC_OP_CODE
Definition: ni_device_api.h:237
NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
#define NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
Definition: ni_device_api.h:2206
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
Definition: ni_device_api.h:1948
NI_PIX_FMT_YUV420P
@ NI_PIX_FMT_YUV420P
Definition: ni_device_api.h:262
NI_DEC_PARAM_FORCE_8BIT_1
#define NI_DEC_PARAM_FORCE_8BIT_1
Definition: ni_device_api.h:2451
NI_ENC_PARAM_BITRATE_MODE
#define NI_ENC_PARAM_BITRATE_MODE
Definition: ni_device_api.h:2214
NI_EC_POLICY_IGNORE
#define NI_EC_POLICY_IGNORE
Definition: ni_device_api.h:319
_ni_rc_min_max_qp
Definition: ni_device_api.h:704
_ni_resolution
Definition: ni_device_api_priv.h:670
NI_ENC_PARAM_COLOR_PRIMARY
#define NI_ENC_PARAM_COLOR_PRIMARY
Definition: ni_device_api.h:2177
ni_device_type_t
ni_device_type_t
Definition: ni_defs.h:341
NI_ENC_PARAM_LONG_TERM_REFERENCE_ENABLE
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_ENABLE
Definition: ni_device_api.h:2165
_niFrameSurface1::ui32nodeAddress
uint32_t ui32nodeAddress
Definition: ni_device_api.h:2799
_ni_session_context::isP2P
int32_t isP2P
Definition: ni_device_api.h:1617
_ni_encoder_cfg_params::enable_hvs_qp_scale
int enable_hvs_qp_scale
Definition: ni_device_api.h:2381
NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
#define NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
Definition: ni_device_api.h:2089
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
Definition: ni_device_api.h:1860
ni_frame_buffer_alloc
ni_retcode_t ni_frame_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, int alignment, int metadata_flag, int factor, int hw_frame_count, int is_planar)
Allocate preliminary memory for the frame buffer based on provided parameters. Applicable to YUV420 P...
Definition: ni_device_api.c:2123
NI_XCODER_READ_STATE
@ NI_XCODER_READ_STATE
Definition: ni_device_api.h:247
_ni_encoder_cfg_params::trans_rate
int trans_rate
Definition: ni_device_api.h:2383
_ni_thread_arg_struct_t::close_thread
bool close_thread
Definition: ni_device_api.h:1262
NI_INVALID_HWID
#define NI_INVALID_HWID
Definition: ni_defs.h:220
_ni_session_data_io::packet
ni_packet_t packet
Definition: ni_device_api.h:2871
NI_MAX_RESOLUTION_RGBA_WIDTH
#define NI_MAX_RESOLUTION_RGBA_WIDTH
Definition: ni_device_api.h:103
_ni_xcoder_params::enable2PassGop
int enable2PassGop
Definition: ni_device_api.h:2782
NI_ENC_GOP_PARAMS_G7_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G7_PIC_TYPE
Definition: ni_device_api.h:1942
_ni_frame::src_codec
ni_codec_format_t src_codec
Definition: ni_device_api.h:2604
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
Definition: ni_device_api.h:1856
_ni_session_context::ltr_to_set
ni_long_term_ref_t ltr_to_set
Definition: ni_device_api.h:1601
NI_DEC_PARAM_SCALE_1
#define NI_DEC_PARAM_SCALE_1
Definition: ni_device_api.h:2463
NI_ENC_PARAM_NO_MBTREE
#define NI_ENC_PARAM_NO_MBTREE
Definition: ni_device_api.h:2205
_ni_encoder_cfg_params::crf_max_iframe_enable
int crf_max_iframe_enable
Definition: ni_device_api.h:2423
NI_MIN_DYNAMIC_MERGE
#define NI_MIN_DYNAMIC_MERGE
Definition: ni_device_api.h:160
XCODER_TEST_RECONF_SLICE_ARG
@ XCODER_TEST_RECONF_SLICE_ARG
Definition: ni_device_api.h:1758
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:427
NI_XCODER_LOG_NAME_NONE
#define NI_XCODER_LOG_NAME_NONE
Definition: ni_device_api.h:2882
_ni_session_context::active_video_width
uint32_t active_video_width
Definition: ni_device_api.h:1549
NI_ENC_PARAM_CROP_HEIGHT
#define NI_ENC_PARAM_CROP_HEIGHT
Definition: ni_device_api.h:2200
_ni_gop_params::poc_offset
int poc_offset
Definition: ni_device_api.h:1961
_ni_gop_params::qp_offset
int qp_offset
Definition: ni_device_api.h:1962
_ni_framerate::framerate_denom
int32_t framerate_denom
Definition: ni_device_api.h:701
NI_DEVICE_TYPE_UPLOAD
@ NI_DEVICE_TYPE_UPLOAD
Definition: ni_defs.h:353
ni_device_open
ni_device_handle_t ni_device_open(const char *p_dev, uint32_t *p_max_io_size_out)
Open device and return device device_handle if successful.
Definition: ni_device_api.c:360
_ni_decoder_input_params_t::enable_user_data_sei_passthru
int enable_user_data_sei_passthru
Definition: ni_device_api.h:2520
NI_ENC_PARAM_LTR_FIRST_GAP
#define NI_ENC_PARAM_LTR_FIRST_GAP
Definition: ni_device_api.h:2151
ni_ai_session_open
ni_retcode_t ni_ai_session_open(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:16741
NI_XCODER_HWDL_STATE
@ NI_XCODER_HWDL_STATE
Definition: ni_device_api.h:255
ni_encoder_sw_frame_buffer_alloc
ni_retcode_t ni_encoder_sw_frame_buffer_alloc(bool planar, ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
This API is a wrapper for ni_encoder_frame_buffer_alloc(), used for planar pixel formats,...
Definition: ni_device_api.c:3531
ni_device_session_context_alloc_init
ni_session_context_t * ni_device_session_context_alloc_init(void)
Allocate and initialize a new ni_session_context_t struct.
Definition: ni_device_api.c:98
g_dev_handle
NI_DEPRECATED ni_device_handle_t g_dev_handle
Definition: ni_rsrc_api.cpp:63
_ni_session_context::domain
unsigned short domain
Definition: ni_device_api.h:1619
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:10107
_ni_session_context::pool_type
ni_frame_pool_type_t pool_type
Definition: ni_device_api.h:1697
_ni_session_context::av_rois
ni_region_of_interest_t * av_rois
Definition: ni_device_api.h:1580
NI_DEC_PARAM_FORCE_8BIT_2
#define NI_DEC_PARAM_FORCE_8BIT_2
Definition: ni_device_api.h:2452
XCODER_TEST_RECONF_CRF
@ XCODER_TEST_RECONF_CRF
Definition: ni_device_api.h:1754
NI_FRAME_AUX_DATA_CRF
@ NI_FRAME_AUX_DATA_CRF
Definition: ni_device_api.h:574
NI_INVALID_SESSION_ID
#define NI_INVALID_SESSION_ID
Definition: ni_device_api.h:111
_ni_encoder_cfg_params::enable_ssim
int enable_ssim
Definition: ni_device_api.h:2387
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:1841
NI_MAX_CU_SIZE_MODE
#define NI_MAX_CU_SIZE_MODE
Definition: ni_device_api.h:156
NI_XCODER_LOG_NAME_INFO
#define NI_XCODER_LOG_NAME_INFO
Definition: ni_device_api.h:2885
_ni_xcoder_params::color_primaries
int color_primaries
Definition: ni_device_api.h:2756
_ni_encoder_cfg_params::enable_compensate_qp
int enable_compensate_qp
Definition: ni_device_api.h:2437
NI_ENC_PARAM_LOOK_AHEAD_DEPTH
#define NI_ENC_PARAM_LOOK_AHEAD_DEPTH
Definition: ni_device_api.h:2133
_ni_resolution::luma_linesize
int32_t luma_linesize
Definition: ni_device_api_priv.h:681
_ni_frame::total_start_len
uint32_t total_start_len
Definition: ni_device_api.h:2705
_ni_session_context::last_bitrate
int32_t last_bitrate
Definition: ni_device_api.h:1674
_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:3169
NI_ENC_PARAM_LTR_NEXT_INTERVAL
#define NI_ENC_PARAM_LTR_NEXT_INTERVAL
Definition: ni_device_api.h:2152
NI_DEC_CROP_MODE_AUTO
@ NI_DEC_CROP_MODE_AUTO
Definition: ni_device_api.h:929
NI_PARAM_MIN_WIDTH
#define NI_PARAM_MIN_WIDTH
Definition: ni_device_api.h:136
_ni_session_context::actual_video_width
uint32_t actual_video_width
Definition: ni_device_api.h:1553
XCODER_TEST_RECONF_VUI_HRD
@ XCODER_TEST_RECONF_VUI_HRD
Definition: ni_device_api.h:1744
ni_gettime_ns
uint64_t ni_gettime_ns(void)
Definition: ni_util.c:1998
_ni_encoder_cfg_params::chromaQpOffset
int chromaQpOffset
Definition: ni_device_api.h:2328
OPT2
#define OPT2(STR1, STR2)
NI_PIX_FMT_BGR0
@ NI_PIX_FMT_BGR0
Definition: ni_device_api.h:270
NI_KEEP_ALIVE_TIMEOUT
#define NI_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:2058
XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
Definition: ni_device_api.h:1753
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:4768
_ni_load_query::pcie_throughput
uint32_t pcie_throughput
Definition: ni_device_api.h:1204
NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
Definition: ni_device_api.h:1911
_ni_frameclone_desc
Definition: ni_device_api.h:1375
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1842
NI_EC_POLICY_LIMITED_ERROR
#define NI_EC_POLICY_LIMITED_ERROR
Definition: ni_device_api.h:322
_ni_xcoder_params::rootBufId
int rootBufId
Definition: ni_device_api.h:2775
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:313
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:2702
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:10082
_ni_session_context::event_handle
ni_event_handle_t event_handle
Definition: ni_device_api.h:1574
XCODER_TEST_RECONF_FRAMERATE
@ XCODER_TEST_RECONF_FRAMERATE
Definition: ni_device_api.h:1751
NI_ENC_PARAM_RDO_QUANT
#define NI_ENC_PARAM_RDO_QUANT
Definition: ni_device_api.h:2130
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:2447
NI_MAX_GOP_SIZE
#define NI_MAX_GOP_SIZE
Definition: ni_device_api.h:150
NI_MAX_FILTER_POOL_SIZE
#define NI_MAX_FILTER_POOL_SIZE
Definition: ni_defs.h:315
NI_ENC_GOP_PARAMS_G2_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G2_POC_OFFSET
Definition: ni_device_api.h:1863
_ni_frame::aux_data
ni_aux_data_t * aux_data[NI_MAX_NUM_AUX_DATA_PER_FRAME]
Definition: ni_device_api.h:2677
ni_pthread_cond_destroy
int ni_pthread_cond_destroy(ni_pthread_cond_t *cond)
destroy condition variables
Definition: ni_util.c:4196
_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:2191
NI_ENC_PARAM_CBR
#define NI_ENC_PARAM_CBR
Definition: ni_device_api.h:2122
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:5325
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:10301
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:1881
NI_ENC_PARAM_ENABLE_AUD
#define NI_ENC_PARAM_ENABLE_AUD
Definition: ni_device_api.h:2134
_ni_encoder_cfg_params::enable_acq_limit
int enable_acq_limit
Definition: ni_device_api.h:2429
_ni_encoder_cfg_params::noMbtree
int noMbtree
Definition: ni_device_api.h:2401
XCODER_TEST_RECONF_INTRAPRD
@ XCODER_TEST_RECONF_INTRAPRD
Definition: ni_device_api.h:1743
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:5837
NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
#define NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
Definition: ni_device_api.h:2048
ni_packet_buffer_free
ni_retcode_t ni_packet_buffer_free(ni_packet_t *p_packet)
Free packet buffer that was previously allocated with ni_packet_buffer_alloc.
Definition: ni_device_api.c:3843
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1465
ni_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:16468
_ni_frame::start_len
uint32_t start_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2704
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:8701
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
Definition: ni_device_api.h:1933
NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
Definition: ni_device_api.h:2147
NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
Definition: ni_defs.h:502
_ni_scaler_input_params_t
Definition: ni_device_api.h:2544
_ni_encoder_cfg_params::roi_enable
int roi_enable
Definition: ni_device_api.h:2257
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:294
_ni_encoder_cfg_params::intra_period
int intra_period
Definition: ni_device_api.h:2260
_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:2302
NI_ENC_PARAM_ENABLE_IP_RATIO
#define NI_ENC_PARAM_ENABLE_IP_RATIO
Definition: ni_device_api.h:2209
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1947
_ni_decoder_input_params_t::min_packets_delay
bool min_packets_delay
Definition: ni_device_api.h:2531
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
Definition: ni_device_api.h:1905
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
Definition: ni_device_api.h:1875
_ni_frame::separate_metadata
uint8_t separate_metadata
Definition: ni_device_api.h:2698
_ni_session_context::reconfig_slice_arg
int16_t reconfig_slice_arg
Definition: ni_device_api.h:1706
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:1621
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:10763
_ni_encoder_cfg_params::enable_pic_skip
int enable_pic_skip
Definition: ni_device_api.h:2370
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:1929
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:1371
_ni_network_perf_metrics
Definition: ni_device_api.h:1384
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:321
_ni_encoder_cfg_params::use_recommend_enc_params
int use_recommend_enc_params
Definition: ni_device_api.h:2346
_ni_thread_arg_struct_t::p_buffer
void * p_buffer
Definition: ni_device_api.h:1266
ni_parse_name
int32_t ni_parse_name(const char *arg, const char *const *names, bool *b_error)
Parse name.
Definition: ni_util.c:1970
ni_encoder_frame_zerocopy_check
ni_retcode_t ni_encoder_frame_zerocopy_check(ni_session_context_t *p_enc_ctx, ni_xcoder_params_t *p_enc_params, int width, int height, const int linesize[], bool set_linesize)
Check if incoming frame is encoder zero copy compatible or not.
Definition: ni_device_api.c:2733
NI_MAX_USE_RECOMMENDED_ENC_PARAMS
#define NI_MAX_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:161
NI_ENC_PARAM_ENABLE_DYNAMIC_16X16_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_16X16_MERGE
Definition: ni_device_api.h:2084
_ni_load_query::fw_share_mem_usage
uint32_t fw_share_mem_usage
Definition: ni_device_api.h:1210
_ni_gop_params::pic_type
int pic_type
Definition: ni_device_api.h:1965
NI_DEC_PARAM_SKIP_EXTRA_HEADERS
#define NI_DEC_PARAM_SKIP_EXTRA_HEADERS
Definition: ni_device_api.h:2497
_ni_encoder_cfg_params::min_qp
int min_qp
Definition: ni_device_api.h:2366
NI_MIN_GOP_SIZE
#define NI_MIN_GOP_SIZE
Definition: ni_device_api.h:151
_ni_encoder_change_params_t::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:1003
NI_FRAME_AUX_DATA_SLICE_ARG
@ NI_FRAME_AUX_DATA_SLICE_ARG
Definition: ni_device_api.h:590
NI_UPLOADER_FLAG_LM
#define NI_UPLOADER_FLAG_LM
Definition: ni_device_api.h:304
NI_ENC_PARAM_HIGH_TIER
#define NI_ENC_PARAM_HIGH_TIER
Definition: ni_device_api.h:2073
_ni_encoder_cfg_params::gop_preset_index
int gop_preset_index
Definition: ni_device_api.h:2251
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1904
_ni_encoder_cfg_params::max_qp
int max_qp
Definition: ni_device_api.h:2367
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:5478
_ni_frame_config
Definition: ni_device_api.h:2808
_ni_encoder_cfg_params::ipRatio
float ipRatio
Definition: ni_device_api.h:2404
NI_PIX_FMT_BGRP
@ NI_PIX_FMT_BGRP
Definition: ni_device_api.h:271
NI_SCALER_FLAG_IO
#define NI_SCALER_FLAG_IO
Definition: ni_device_api.h:291
_ni_packet::av1_p_data
uint8_t * av1_p_data[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2845
_ni_encoder_cfg_params::blockRCSize
int blockRCSize
Definition: ni_device_api.h:2336
NI_DEC_PARAM_CROP_MODE_2
#define NI_DEC_PARAM_CROP_MODE_2
Definition: ni_device_api.h:2458
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:2730
_ni_session_context::src_endian
int src_endian
Definition: ni_device_api.h:1493
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
Definition: ni_device_api.h:282
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:11447
_ni_session_context::low_delay_sync_mutex
ni_pthread_mutex_t low_delay_sync_mutex
Definition: ni_device_api.h:1665
_ni_encoder_cfg_params::intra_mb_refresh_mode
int intra_mb_refresh_mode
Definition: ni_device_api.h:2261
NI_ENC_PARAM_TOL_RC_INTER
#define NI_ENC_PARAM_TOL_RC_INTER
Definition: ni_device_api.h:2156
QUERY_GET_EXTTRA_INFO_R
#define QUERY_GET_EXTTRA_INFO_R
Definition: ni_nvme.h:800
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:9651
_ni_encoder_cfg_params::vbv_buffer_size
int vbv_buffer_size
Definition: ni_device_api.h:2377
_ni_packet::av1_buffer_size
uint32_t av1_buffer_size[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2846
NI_ENC_GOP_PARAMS_G6_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G6_PIC_TYPE
Definition: ni_device_api.h:1927
_ni_frame::p_buffer
uint8_t * p_buffer
Definition: ni_device_api.h:2666
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
Definition: ni_device_api.h:2128
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:10418
NI_ENC_INLOOP_DS_RATIO
#define NI_ENC_INLOOP_DS_RATIO
Definition: ni_device_api.h:2159
_ni_encoder_cfg_params::noHWMultiPassSupport
int noHWMultiPassSupport
Definition: ni_device_api.h:2402
NI_ENC_PARAM_CONF_WIN_BOTTOM
#define NI_ENC_PARAM_CONF_WIN_BOTTOM
Definition: ni_device_api.h:2097
_ni_encoder_cfg_params::gdrDuration
int gdrDuration
Definition: ni_device_api.h:2284
_ni_xcoder_params::video_full_range_flag
int video_full_range_flag
Definition: ni_device_api.h:2761
XCODER_TEST_RECONF_VBV
@ XCODER_TEST_RECONF_VBV
Definition: ni_device_api.h:1756
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:2518
NI_EC_POLICY_BEST_EFFORT_OUT_DC
#define NI_EC_POLICY_BEST_EFFORT_OUT_DC
Definition: ni_device_api.h:323
_ni_encoder_cfg_params::aspectRatioWidth
int aspectRatioWidth
Definition: ni_device_api.h:2240
NI_RETCODE_INVALID_PARAM
@ NI_RETCODE_INVALID_PARAM
Definition: ni_defs.h:429
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3
Definition: ni_device_api.h:1845
_ni_session_context::avc_roi_map
ni_enc_avc_roi_custom_map_t * avc_roi_map
Definition: ni_device_api.h:1585
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:1760
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:16181
_ni_scaler_input_params_t::input_height
int32_t input_height
Definition: ni_device_api.h:2548
_ni_session_context::buffered_frame_index
int16_t buffered_frame_index
Definition: ni_device_api.h:1717
NI_FRAME_BIG_ENDIAN
#define NI_FRAME_BIG_ENDIAN
Definition: ni_device_api.h:109
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1917
NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
#define NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
Definition: ni_device_api.h:2216
_ni_encoder_cfg_params::maxFrameSizeRatio
int maxFrameSizeRatio
Definition: ni_device_api.h:2244
_ni_decoder_input_params_t::enable_advanced_ec
int enable_advanced_ec
Definition: ni_device_api.h:2524
_ni_encoder_cfg_params::HDR10AveLight
int HDR10AveLight
Definition: ni_device_api.h:2271
_ni_encoder_cfg_params::rc
struct _ni_encoder_cfg_params::@16 rc
NI_ENC_PARAM_JPEG_QLEVEL
#define NI_ENC_PARAM_JPEG_QLEVEL
Definition: ni_device_api.h:2154
XCODER_TEST_INVALID_REF_FRAME
@ XCODER_TEST_INVALID_REF_FRAME
Definition: ni_device_api.h:1750
NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:311
NI_ENC_PARAM_DDR_PRIORITY_MODE
#define NI_ENC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2213
NI_ENC_PARAM_GOP_LOW_DELAY
#define NI_ENC_PARAM_GOP_LOW_DELAY
Definition: ni_device_api.h:2137
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:2254
_ni_decoder_input_params_t::sc_expr
char sc_expr[NI_MAX_NUM_OF_DECODER_OUTPUTS][2][NI_MAX_PPU_PARAM_EXPR_CHAR+1]
Definition: ni_device_api.h:2514
_ni_encoder_cfg_params::cu_size_mode
int cu_size_mode
Definition: ni_device_api.h:2348
_ni_packet::av1_data_len
uint32_t av1_data_len[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2847
NI_ENC_PARAM_DOLBY_VISION_PROFILE
#define NI_ENC_PARAM_DOLBY_VISION_PROFILE
Definition: ni_device_api.h:2140
_ni_encoder_cfg_params::hrdEnable
int hrdEnable
Definition: ni_device_api.h:2303
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:9049
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1494
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
Definition: ni_device_api.h:1764
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1902
NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
#define NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
Definition: ni_device_api.h:2123
_ni_session_context::reconfig_crf_decimal
int reconfig_crf_decimal
Definition: ni_device_api.h:1686
_ni_encoder_change_params_t
This is a data structure for encoding parameters that have changed.
Definition: ni_device_api.h:982
_ni_encoder_cfg_params::encMallocStrategy
int encMallocStrategy
Definition: ni_device_api.h:2435
NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2465
_ni_xcoder_params::log
int log
Definition: ni_device_api.h:2715
_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:2344
_ni_session_context::mutex
ni_pthread_mutex_t mutex
Definition: ni_device_api.h:1565
_ni_encoder_cfg_params::max_num_merge
int max_num_merge
Definition: ni_device_api.h:2349
_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:1966
_ni_packet::av1_buffer_index
int av1_buffer_index
Definition: ni_device_api.h:2848
_ni_decoder_input_params_t::crop_mode
int crop_mode[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2506
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:15324
_ni_aux_data::size
int size
Definition: ni_device_api.h:622
_ni_encoder_cfg_params::crf
int crf
Definition: ni_device_api.h:2269
_ni_load_query::pcie_load
uint32_t pcie_load
Definition: ni_device_api.h:1208
NI_ENC_REPEAT_HEADERS_FIRST_IDR
#define NI_ENC_REPEAT_HEADERS_FIRST_IDR
Definition: ni_device_api.h:2056
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1478
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:1870
NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
Definition: ni_device_api.h:2085
_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:586
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:10358
_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:2718
NI_FRAME_AUX_DATA_VBV_MAX_RATE
@ NI_FRAME_AUX_DATA_VBV_MAX_RATE
Definition: ni_device_api.h:582
NI_DEC_PARAM_CROP_MODE_0
#define NI_DEC_PARAM_CROP_MODE_0
Definition: ni_device_api.h:2456
_ni_enc_quad_roi_custom_map::roiAbsQp_flag
uint8_t roiAbsQp_flag
Definition: ni_device_api.h:887
NI_MIN_BIN
#define NI_MIN_BIN
Definition: ni_device_api.h:175
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1861
NI_ENC_PARAM_IP_RATIO
#define NI_ENC_PARAM_IP_RATIO
Definition: ni_device_api.h:2208
NI_DEC_PARAM_MULTICORE_JOINT_MODE
#define NI_DEC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2474
ni_cmp_fw_api_ver
int ni_cmp_fw_api_ver(const char ver1[], const char ver2[])
Compare two 3 character strings containing a FW API version. Handle comparision when FW API version f...
Definition: ni_util.c:3674
ni_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:3333
NI_XCODER_OPEN_STATE
@ NI_XCODER_OPEN_STATE
Definition: ni_device_api.h:245
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1921
_ni_scaler_input_params_t::input_format
int input_format
Definition: ni_device_api.h:2546
_ni_xcoder_params::hdrEnableVUI
int hdrEnableVUI
Definition: ni_device_api.h:2745
NI_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:316
_ni_scaler_params_t
Definition: ni_device_api.h:2566
NI_ENC_GOP_PARAMS_G0_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G0_PIC_TYPE
Definition: ni_device_api.h:1837
_ni_scaler_input_params_t::out_rec_width
int32_t out_rec_width
Definition: ni_device_api.h:2557
NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
Definition: ni_defs.h:498
_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:333
_ni_encoder_cfg_params::enable_timecode
int enable_timecode
Definition: ni_device_api.h:2439
NI_ENC_GOP_PARAMS_G4_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G4_PIC_TYPE
Definition: ni_device_api.h:1897
NI_DEC_PARAM_ENABLE_OUT_1
#define NI_DEC_PARAM_ENABLE_OUT_1
Definition: ni_device_api.h:2448
_ni_session_context::reconfig_intra_period
int reconfig_intra_period
Definition: ni_device_api.h:1704
NI_ENC_PARAM_FORCE_FRAME_TYPE
#define NI_ENC_PARAM_FORCE_FRAME_TYPE
Definition: ni_device_api.h:2070
NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_MEM_ALOC
Definition: ni_defs.h:431
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:425
_ni_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:570
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:8997
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:7865
NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
Definition: ni_device_api.h:2148
NI_MAX_KEEP_ALIVE_TIMEOUT
#define NI_MAX_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:309
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_2
uint32_t sub_ctu_qp_2
Definition: ni_device_api.h:857
_ni_vui_hrd::colorPrimaries
int32_t colorPrimaries
Definition: ni_device_api.h:661
NI_MAX_DECODING_REFRESH_TYPE
#define NI_MAX_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:154
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_0
uint32_t sub_ctu_qp_0
Definition: ni_device_api.h:855
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:10821
SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
Definition: ni_device_api.h:1178
NI_FW_META_DATA_SZ
#define NI_FW_META_DATA_SZ
Definition: ni_defs.h:306
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:634
_ni_session_context::fw_rev
uint8_t fw_rev[8]
Definition: ni_device_api.h:1625
NI_DEC_PARAM_SEMI_PLANAR_1
#define NI_DEC_PARAM_SEMI_PLANAR_1
Definition: ni_device_api.h:2454
NI_DMABUF_WRITE_TO_DEVICE
@ NI_DMABUF_WRITE_TO_DEVICE
Definition: ni_p2p_ioctl.h:40
ni_pthread_join
int ni_pthread_join(ni_pthread_t thread, void **value_ptr)
join with a terminated thread
Definition: ni_util.c:4148
_ni_network_data::output_num
uint32_t output_num
Definition: ni_device_api.h:1366
_ni_encoder_cfg_params::intra_mb_refresh_arg
int intra_mb_refresh_arg
Definition: ni_device_api.h:2262
SESSION_RUN_STATE_NORMAL
@ SESSION_RUN_STATE_NORMAL
Definition: ni_device_api.h:1177
ni_packet_buffer_alloc
ni_retcode_t ni_packet_buffer_alloc(ni_packet_t *p_packet, int packet_size)
Allocate memory for the packet buffer based on provided packet size.
Definition: ni_device_api.c:3713
NI_ENC_GOP_PARAMS_G1_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G1_QP_OFFSET
Definition: ni_device_api.h:1849
NI_MAX_REF_PIC
#define NI_MAX_REF_PIC
Definition: ni_device_api.h:59
ni_frame_new_aux_data
ni_aux_data_t * ni_frame_new_aux_data(ni_frame_t *frame, ni_aux_data_type_t type, int data_size)
Add a new auxiliary data to a frame.
Definition: ni_device_api.c:4005
NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
#define NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
Definition: ni_device_api.h:476
NI_ENC_PARAM_MIN_FRAMES_DELAY
#define NI_ENC_PARAM_MIN_FRAMES_DELAY
Definition: ni_device_api.h:2078
_ni_encoder_cfg_params::pps_init_qp
int pps_init_qp
Definition: ni_device_api.h:2407
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:17805
NI_RETCODE_PARAM_INVALID_VALUE
@ NI_RETCODE_PARAM_INVALID_VALUE
Definition: ni_defs.h:437
STRDUP
#define STRDUP(value)
NI_ENC_PARAM_MAX_CLL
#define NI_ENC_PARAM_MAX_CLL
Definition: ni_device_api.h:2131
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
Definition: ni_device_api.h:1871
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1855
_ni_encoder_cfg_params::gopSize
int gopSize
Definition: ni_device_api.h:2323
_ni_session_context::reconfig_vbv_buffer_size
int reconfig_vbv_buffer_size
Definition: ni_device_api.h:1688
_ni_session_context::framerate
ni_framerate_t framerate
Definition: ni_device_api.h:1604
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:1534
_ni_session_context::pext_mutex
ni_pthread_mutex_t * pext_mutex
Definition: ni_device_api.h:1670
_ni_thread_arg_struct_t::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1264
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
Definition: ni_device_api.h:1888
_ni_decoder_input_params_t::crop_whxy
int crop_whxy[NI_MAX_NUM_OF_DECODER_OUTPUTS][4]
Definition: ni_device_api.h:2507
_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:470
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:3298
_ni_encoder_cfg_params::qlevel
int qlevel
Definition: ni_device_api.h:2318
_ni_decoder_input_params_t::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2515
_ni_custom_gop_params::custom_gop_size
int custom_gop_size
Definition: ni_device_api.h:2052
XCODER_TEST_RECONF_OFF
@ XCODER_TEST_RECONF_OFF
Definition: ni_device_api.h:1741
_ni_scaler_input_params_t::rgba_color
uint32_t rgba_color
Definition: ni_device_api.h:2562
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:2037
NI_PARAM_MAX_HEIGHT
#define NI_PARAM_MAX_HEIGHT
Definition: ni_device_api.h:137
_niFrameSurface1::ui16FrameIdx
uint16_t ui16FrameIdx
Definition: ni_device_api.h:2795
NI_ENC_PARAM_CACHE_ROI
#define NI_ENC_PARAM_CACHE_ROI
Definition: ni_device_api.h:2066
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:3202
_ni_encoder_cfg_params::HDR10dx2
int HDR10dx2
Definition: ni_device_api.h:2278
_ni_long_term_ref
Definition: ni_device_api.h:683
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:61
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:657
NI_MAX_INTRA_QP
#define NI_MAX_INTRA_QP
Definition: ni_device_api.h:165
_ni_session_context::reconfig_vbv_max_rate
int reconfig_vbv_max_rate
Definition: ni_device_api.h:1689
NI_ENC_PARAM_SPATIAL_LAYERS
#define NI_ENC_PARAM_SPATIAL_LAYERS
Definition: ni_device_api.h:2232
NI_ENC_PARAM_INTRA_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_REFRESH_ARG
Definition: ni_device_api.h:2116
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:15233
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:10602
NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
Definition: ni_device_api.h:1913
NI_DEC_PARAM_CROP_PARAM_0
#define NI_DEC_PARAM_CROP_PARAM_0
Definition: ni_device_api.h:2459
NI_DEC_PARAM_CROP_PARAM_1
#define NI_DEC_PARAM_CROP_PARAM_1
Definition: ni_device_api.h:2460
_ni_encoder_cfg_params::HDR10wx
int HDR10wx
Definition: ni_device_api.h:2280
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:11617
NI_ENC_PARAM_ENABLE_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_RATE_CONTROL
Definition: ni_device_api.h:2086
NI_ENC_PARAM_VBV_BUFFER_REENCODE
#define NI_ENC_PARAM_VBV_BUFFER_REENCODE
Definition: ni_device_api.h:2236
atof
#define atof(p_str)
Definition: ni_device_api.c:7179
_ni_xcoder_params::source_height
int source_height
Definition: ni_device_api.h:2728
NI_ENC_GOP_PARAMS_G5_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G5_QP_OFFSET
Definition: ni_device_api.h:1909
NI_APP_ENC_FRAME_META_DATA_SIZE
#define NI_APP_ENC_FRAME_META_DATA_SIZE
Definition: ni_defs.h:308
_ni_decoder_input_params_t::cr_expr
char cr_expr[NI_MAX_NUM_OF_DECODER_OUTPUTS][4][NI_MAX_PPU_PARAM_EXPR_CHAR+1]
Definition: ni_device_api.h:2510
_ni_encoder_cfg_params::rcQpDeltaRange
int rcQpDeltaRange
Definition: ni_device_api.h:2340
_ni_encoder_change_params_t::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:1001
ni_decoder_frame_buffer_alloc
ni_retcode_t ni_decoder_frame_buffer_alloc(ni_buf_pool_t *p_pool, ni_frame_t *p_frame, int alloc_mem, int video_width, int video_height, int alignment, int factor, int is_planar)
Allocate memory for decoder frame buffer based on provided parameters; the memory is retrieved from a...
Definition: ni_device_api.c:2586
XCODER_TEST_RECONF_BR_API
@ XCODER_TEST_RECONF_BR_API
Definition: ni_device_api.h:1760
_ni_encoder_cfg_params::hvsBaseMbComplexity
int hvsBaseMbComplexity
Definition: ni_device_api.h:2411
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:60
_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:157
IS_XCODER_DEVICE_TYPE
#define IS_XCODER_DEVICE_TYPE(t)
Definition: ni_defs.h:410
_ni_frame::ni_pict_type
ni_pic_type_t ni_pict_type
Definition: ni_device_api.h:2627
_ni_session_context::src_bit_depth
int src_bit_depth
Definition: ni_device_api.h:1492
NI_FRAME_AUX_DATA_VUI
@ NI_FRAME_AUX_DATA_VUI
Definition: ni_device_api.h:543
ni_buf_pool_get_buffer
ni_buf_t * ni_buf_pool_get_buffer(ni_buf_pool_t *p_buffer_pool)
Definition: ni_util.c:468
_ni_vui_hrd::colorTrc
int32_t colorTrc
Definition: ni_device_api.h:665
NI_MAX_RESOLUTION_WIDTH
#define NI_MAX_RESOLUTION_WIDTH
Definition: ni_device_api.h:100
_ni_framerate::framerate_num
int32_t framerate_num
Definition: ni_device_api.h:698
NI_VPU_ALIGN16
#define NI_VPU_ALIGN16(_x)
Definition: ni_device_api.h:331
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:5027
GOP_PRESET_IDX_DEFAULT
@ GOP_PRESET_IDX_DEFAULT
Definition: ni_device_api_priv.h:318
_ni_encoder_cfg_params::HDR10maxluma
int HDR10maxluma
Definition: ni_device_api.h:2282
_ni_network_data::linfo
ni_network_layer_info_t linfo
Definition: ni_device_api.h:1367
_niFrameSurface1::ui16session_ID
uint16_t ui16session_ID
Definition: ni_device_api.h:2796
NI_SCALER_OPCODE_OVERLAY
@ NI_SCALER_OPCODE_OVERLAY
Definition: ni_defs.h:577
NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
@ NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
Definition: ni_defs.h:521
NI_MIN_DECODING_REFRESH_TYPE
#define NI_MIN_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:155
_ni_xcoder_params::cfg_enc_params
ni_encoder_cfg_params_t cfg_enc_params
Definition: ni_device_api.h:2765
NI_ENC_PARAM_RDO_LEVEL
#define NI_ENC_PARAM_RDO_LEVEL
Definition: ni_device_api.h:2129
NI_PARAM_JPEG_MIN_WIDTH
#define NI_PARAM_JPEG_MIN_WIDTH
Definition: ni_device_api.h:140
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:9779
NI_ENC_PARAM_PROFILE
#define NI_ENC_PARAM_PROFILE
Definition: ni_device_api.h:2071
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:2000
_ni_encoder_cfg_params::vbv_max_rate
int vbv_max_rate
Definition: ni_device_api.h:2378
_ni_gop_params::qp_factor
float qp_factor
Definition: ni_device_api.h:1963
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:529
_ni_xcoder_params::force_frame_type
int force_frame_type
Definition: ni_device_api.h:2742
_ni_gop_rps::ref_pic
int ref_pic
Definition: ni_device_api.h:1955
NI_XCODER_IDLE_STATE
@ NI_XCODER_IDLE_STATE
Definition: ni_device_api.h:244
NI_PIX_FMT_NV12
@ NI_PIX_FMT_NV12
Definition: ni_device_api.h:264
ni_encoder_gop_params_set_value
ni_retcode_t ni_encoder_gop_params_set_value(ni_xcoder_params_t *p_params, const char *name, const char *value)
Set GOP parameter value referenced by name in encoder parameters structure.
Definition: ni_device_api.c:7197
XCODER_TEST_RECONF_INTRAPRD_API
@ XCODER_TEST_RECONF_INTRAPRD_API
Definition: ni_device_api.h:1761
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2664
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:13323
_ni_session_context::pixel_format_changed
int pixel_format_changed
Definition: ni_device_api.h:1705
NI_RETCODE_ERROR_UNLOCK_DEVICE
@ NI_RETCODE_ERROR_UNLOCK_DEVICE
Definition: ni_defs.h:509
_ni_encoder_cfg_params::intra_qp
int intra_qp
Definition: ni_device_api.h:2368
QUERY_GET_VERSIONS_R
#define QUERY_GET_VERSIONS_R
Definition: ni_nvme.h:793
_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:1879
PIC_TYPE_I
@ PIC_TYPE_I
Definition: ni_device_api.h:384
_ni_encoder_cfg_params::enable_rate_control
int enable_rate_control
Definition: ni_device_api.h:2365
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:2418
NI_PIXEL_PLANAR_MAX
@ NI_PIXEL_PLANAR_MAX
Definition: ni_device_api.h:923
_ni_decoder_input_params_t::semi_planar
int semi_planar[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2505
_ni_decoder_input_params_t::scale_long_short_edge
int scale_long_short_edge[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2533
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:8363
_ni_scaler_input_params_t::out_rec_y
int32_t out_rec_y
Definition: ni_device_api.h:2560
NI_MIN_USE_RECOMMENDED_ENC_PARAMS
#define NI_MIN_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:162
NI_ENC_PARAM_INTRA_MB_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_MB_REFRESH_ARG
Definition: ni_device_api.h:2114
NI_DEC_PARAM_SCALE_0_ROUND
#define NI_DEC_PARAM_SCALE_0_ROUND
Definition: ni_device_api.h:2471
_ni_decoder_input_params_t::hwframes
int hwframes
Definition: ni_device_api.h:2499
_ni_device_info
Definition: ni_rsrc_api.h:102
NI_DEVICE_TYPE_AI
@ NI_DEVICE_TYPE_AI
Definition: ni_defs.h:349
ni_gop_params_check_set
void ni_gop_params_check_set(ni_xcoder_params_t *p_param, char *value)
Set custom gop and prepare to check if success.
Definition: ni_device_api.c:12614
ni_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:13917
_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:1275
_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:2790
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:5237
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:2289
ni_encoder_init_default_params
ni_retcode_t ni_encoder_init_default_params(ni_xcoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height, ni_codec_format_t codec_format)
Initialize default encoder parameters.
Definition: ni_device_api.c:4147
ni_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:4045
_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:2773
NI_FRAME_AUX_DATA_FRAMERATE
@ NI_FRAME_AUX_DATA_FRAMERATE
Definition: ni_device_api.h:562
_ni_xcoder_params::enable_ai_enhance
int enable_ai_enhance
Definition: ni_device_api.h:2781
_ni_load_query::tp_fw_load
uint32_t tp_fw_load
Definition: ni_device_api.h:1214
NI_ENC_PARAM_LTR_REF_QPOFFSET
#define NI_ENC_PARAM_LTR_REF_QPOFFSET
Definition: ni_device_api.h:2150
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:3355
NI_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_RETCODE_ERROR_NVME_CMD_FAILED
Definition: ni_defs.h:432
NI_ENC_PARAM_ENABLE_AI_ENHANCE
#define NI_ENC_PARAM_ENABLE_AI_ENHANCE
Definition: ni_device_api.h:2193
_ni_thread_arg_struct_t::device_type
uint32_t device_type
Definition: ni_device_api.h:1263
NI_ENC_PARAM_TUNE_BFRAME_VISUAL
#define NI_ENC_PARAM_TUNE_BFRAME_VISUAL
Definition: ni_device_api.h:2224
_ni_decoder_input_params_t
Definition: ni_device_api.h:2445
NI_XCODER_HWUP_STATE
@ NI_XCODER_HWUP_STATE
Definition: ni_device_api.h:254
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:2275
NI_ENC_GOP_PARAMS_G2_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G2_PIC_TYPE
Definition: ni_device_api.h:1867
_ni_encoder_cfg_params::enable_dynamic_8x8_merge
int enable_dynamic_8x8_merge
Definition: ni_device_api.h:2350
_ni_encoder_cfg_params::ctbRcMode
int ctbRcMode
Definition: ni_device_api.h:2322
_ni_scaler_drawbox_params_t
Definition: ni_device_api.h:2575
_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:2132
_ni_thread_arg_struct_t::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1268
NI_ENC_PARAM_SAR_NUM
#define NI_ENC_PARAM_SAR_NUM
Definition: ni_device_api.h:2181
NI_MEM_PAGE_ALIGNMENT
#define NI_MEM_PAGE_ALIGNMENT
Definition: ni_defs.h:251
NI_ENC_PARAM_CTB_RC_MODE
#define NI_ENC_PARAM_CTB_RC_MODE
Definition: ni_device_api.h:2135
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:63
_ni_encoder_cfg_params::long_term_ref_interval
int long_term_ref_interval
Definition: ni_device_api.h:2291
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:1146
NI_ENC_PARAM_PB_RATIO
#define NI_ENC_PARAM_PB_RATIO
Definition: ni_device_api.h:2210
_ni_xcoder_params::interval_of_psnr
int interval_of_psnr
Definition: ni_device_api.h:2789
NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
Definition: ni_device_api.h:2113
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1906
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:8781
NI_ENC_PARAM_ENABLE_FILLER
#define NI_ENC_PARAM_ENABLE_FILLER
Definition: ni_device_api.h:2143
NI_ENC_PARAM_ENABLE_HVS_QP
#define NI_ENC_PARAM_ENABLE_HVS_QP
Definition: ni_device_api.h:2088
ni_device_extra_info_t
struct _ni_device_extra_info ni_device_extra_info_t
_ni_buf_t
Definition: ni_device_api.h:1272
NI_CODEC_HW_DOWNLOAD
@ NI_CODEC_HW_DOWNLOAD
Definition: ni_device_api.h:941
PIC_TYPE_IDR
@ PIC_TYPE_IDR
Definition: ni_device_api.h:389
ni_pthread_mutex_lock
int ni_pthread_mutex_lock(ni_pthread_mutex_t *mutex)
thread mutex lock
Definition: ni_util.c:4057
NI_ENC_GOP_PARAMS_G0_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G0_POC_OFFSET
Definition: ni_device_api.h:1833
_niFrameSurface1::encoding_type
int8_t encoding_type
Definition: ni_device_api.h:2802
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:14923
_ni_xcoder_params::generate_enc_hdrs
NI_DEPRECATED int generate_enc_hdrs
Definition: ni_device_api.h:2735
_ni_xcoder_params::hwframes
int hwframes
Definition: ni_device_api.h:2774
NI_PIX_FMT_NV16
@ NI_PIX_FMT_NV16
Definition: ni_device_api.h:272
_ni_encoder_cfg_params::newRcEnable
int newRcEnable
Definition: ni_device_api.h:2391
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1462
_ni_session_context::enc_change_params
ni_encoder_change_params_t * enc_change_params
Definition: ni_device_api.h:1592
atobool
#define atobool(p_str)
Definition: ni_device_api.c:7180
_ni_session_context::p_session_config
void * p_session_config
Definition: ni_device_api.h:1473
NI_CODEC_FORMAT_AV1
@ NI_CODEC_FORMAT_AV1
Definition: ni_device_api.h:915
_ni_encoder_cfg_params::skip_frame_enable
int skip_frame_enable
Definition: ni_device_api.h:2417
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:1310
NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:2481
NI_PARAM_JPEG_MIN_HEIGHT
#define NI_PARAM_JPEG_MIN_HEIGHT
Definition: ni_device_api.h:141
XCODER_TEST_RECONF_SLICE_ARG_API
@ XCODER_TEST_RECONF_SLICE_ARG_API
Definition: ni_device_api.h:1774
NI_ENC_PARAM_CHROMA_QP_OFFSET
#define NI_ENC_PARAM_CHROMA_QP_OFFSET
Definition: ni_device_api.h:2155
_ni_packet::av1_p_buffer
uint8_t * av1_p_buffer[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2844
NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
Definition: ni_device_api.h:2488
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:318
_ni_enc_avc_roi_custom_map::mb_qp
uint8_t mb_qp
Definition: ni_device_api.h:875
NI_ENC_PARAM_RECONF_DEMO_MODE
#define NI_ENC_PARAM_RECONF_DEMO_MODE
Definition: ni_device_api.h:2063
NI_DDR_PRIORITY_MAX
@ NI_DDR_PRIORITY_MAX
Definition: ni_device_api.h:1829
NI_ENC_GOP_PARAMS_G5_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G5_POC_OFFSET
Definition: ni_device_api.h:1908
_ni_encoder_cfg_params::entropy_coding_mode
int entropy_coding_mode
Definition: ni_device_api.h:2307
NI_ENC_PARAM_INTRA_QP_DELTA
#define NI_ENC_PARAM_INTRA_QP_DELTA
Definition: ni_device_api.h:2164
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:11379
_ni_packet::p_data
void * p_data
Definition: ni_device_api.h:2837
ni_decoder_params_set_value
ni_retcode_t ni_decoder_params_set_value(ni_xcoder_params_t *p_params, const char *name, char *value)
Set value referenced by name in decoder parameters structure.
Definition: ni_device_api.c:4881
NI_ENC_PARAM_VBV_MAXRAE
#define NI_ENC_PARAM_VBV_MAXRAE
Definition: ni_device_api.h:2142
_ni_session_data_io
Definition: ni_device_api.h:2866
_ni_enc_quad_roi_custom_map::ipcm_flag
uint8_t ipcm_flag
Definition: ni_device_api.h:891
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:13122
ni_enc_prep_reconf_demo_data
ni_retcode_t ni_enc_prep_reconf_demo_data(ni_session_context_t *p_enc_ctx, ni_frame_t *p_frame)
Convert various reconfig and demo modes (stored in encoder configuration) to aux data and store them ...
Definition: ni_device_api.c:11947
NI_MAX_CUSTOM_SEI_PASSTHRU
#define NI_MAX_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:314
NI_ENC_PARAM_MAX_DELTA_QP
#define NI_ENC_PARAM_MAX_DELTA_QP
Definition: ni_device_api.h:2093
_ni_decoder_input_params_t::svct_decoding_layer
int svct_decoding_layer
Definition: ni_device_api.h:2522
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1887
_ni_encoder_cfg_params::ltrFirstGap
int ltrFirstGap
Definition: ni_device_api.h:2287
NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
#define NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
Definition: ni_device_api.h:2080
_ni_encoder_cfg_params::ltrRefQpOffset
int ltrRefQpOffset
Definition: ni_device_api.h:2286
_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:2174
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:2482
NI_PIX_FMT_YUV420P10LE
@ NI_PIX_FMT_YUV420P10LE
Definition: ni_device_api.h:263
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:2469
NI_ENC_GOP_PARAMS_G7_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G7_POC_OFFSET
Definition: ni_device_api.h:1938
_ni_scaler_input_params_t::in_rec_x
int32_t in_rec_x
Definition: ni_device_api.h:2551
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1945
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:16899
NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
Definition: ni_defs.h:96
_ni_encoder_cfg_params::enable_transform_8x8
int enable_transform_8x8
Definition: ni_device_api.h:2356
_ni_session_context::sender_handle
ni_device_handle_t sender_handle
Definition: ni_device_api.h:1468
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:15115
NI_ENC_PARAM_AI_ENHANCE_LEVEL
#define NI_ENC_PARAM_AI_ENHANCE_LEVEL
Definition: ni_device_api.h:2197
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:2321
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:9252
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:10996
ni_rsrc_unlock
int ni_rsrc_unlock(int device_type, ni_lock_handle_t lock)
unlock a file lock
Definition: ni_rsrc_api.cpp:2738
QOS_NAMESPACE_CODE
@ QOS_NAMESPACE_CODE
Definition: ni_device_api.h:236
NI_MAX_GOP_NUM
#define NI_MAX_GOP_NUM
Definition: ni_device_api.h:57
NI_CUSTOMIZE_ROI_QP_NUM
#define NI_CUSTOMIZE_ROI_QP_NUM
Max number of entries per line supported for the qp number.
Definition: ni_device_api.h:481
_ni_encoder_cfg_params::enable_smooth_crf
int enable_smooth_crf
Definition: ni_device_api.h:2436
_ni_device_info::model_load
int model_load
Definition: ni_rsrc_api.h:109
_ni_network_layer_info
Definition: ni_device_api.h:1352
_ni_session_context::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1521
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:9869
_ni_encoder_cfg_params::customize_roi_qp_level
int customize_roi_qp_level
Definition: ni_device_api.h:2431
_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:16332
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
Definition: ni_device_api.h:1843
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:4089
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:3884
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:9698
NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
Definition: ni_device_api.h:2166
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:4664
NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL
#define NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL
Definition: ni_defs.h:286
NI_ENC_PARAM_HRD_ENABLE
#define NI_ENC_PARAM_HRD_ENABLE
Definition: ni_device_api.h:2139
_ni_encoder_cfg_params
Definition: ni_device_api.h:2060
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
Definition: ni_device_api.h:1920
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1857
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
Definition: ni_device_api.h:1854
NI_DEC_PARAM_ENABLE_ADVANCED_EC
#define NI_DEC_PARAM_ENABLE_ADVANCED_EC
Definition: ni_device_api.h:2485
NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
#define NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
Definition: ni_device_api.h:2222
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
Definition: ni_device_api.h:1931
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1859
_ni_encoder_cfg_params::EnableAUD
int EnableAUD
Definition: ni_device_api.h:2301
NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
Definition: ni_device_api.h:1941
_ni_encoder_cfg_params::spatial_layers
int spatial_layers
Definition: ni_device_api.h:2438
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:11171
ni_usleep
void ni_usleep(int64_t usec)
Definition: ni_util.c:358
ni_query_fl_fw_versions
ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle, ni_device_info_t *p_dev_info)
Query firmware loader and firmware versions from the device.
Definition: ni_device_api.c:11385
_ni_encoder_cfg_params::scene_change_detect_level
int scene_change_detect_level
Definition: ni_device_api.h:2434
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:17000
NI_ENC_PARAM_PADDING
#define NI_ENC_PARAM_PADDING
Definition: ni_device_api.h:2069
_ni_session_context::device_type
uint32_t device_type
Definition: ni_device_api.h:1484
NI_RETCODE_ERROR_PERMISSION_DENIED
@ NI_RETCODE_ERROR_PERMISSION_DENIED
Definition: ni_defs.h:523
niFrameSurface1_t
struct _niFrameSurface1 niFrameSurface1_t
NI_AI_HW_ALIGN_SIZE
#define NI_AI_HW_ALIGN_SIZE
Definition: ni_device_api_priv.h:1232
NI_ENC_PARAM_CPLX_DECAY
#define NI_ENC_PARAM_CPLX_DECAY
Definition: ni_device_api.h:2211
_ni_frame::force_key_frame
int force_key_frame
Definition: ni_device_api.h:2624
ni_encoder_frame_zerocopy_buffer_alloc
ni_retcode_t ni_encoder_frame_zerocopy_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, const int linesize[], const uint8_t *data[], int extra_len)
Allocate memory for encoder zero copy (metadata, etc.) for encoding based on given parameters,...
Definition: ni_device_api.c:2879
LRETURN
#define LRETURN
Definition: ni_defs.h:323
NI_VPU_ALIGN32
#define NI_VPU_ALIGN32(_x)
Definition: ni_device_api.h:332
NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
Definition: ni_device_api.h:920
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1840
ni_packet_copy
int ni_packet_copy(void *p_destination, const void *const p_source, int cur_size, void *p_leftover, int *p_prev_size)
Copy video packet accounting for alignment.
Definition: ni_device_api.c:3936
NI_MAX_HEIGHT
#define NI_MAX_HEIGHT
Definition: ni_device_api.h:125
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:1919
_ni_encoder_cfg_params::HDR10CLLEnable
int HDR10CLLEnable
Definition: ni_device_api.h:2272
NI_ENC_PARAM_HORIZONTAL_OFFSET
#define NI_ENC_PARAM_HORIZONTAL_OFFSET
Definition: ni_device_api.h:2201
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
Definition: ni_device_api.h:1899
NI_RETCODE_PARAM_WARNING_DEPRECATED
@ NI_RETCODE_PARAM_WARNING_DEPRECATED
Definition: ni_defs.h:516
_ni_aux_data::data
void * data
Definition: ni_device_api.h:621
_ni_frame::dec_buf
ni_buf_t * dec_buf
Definition: ni_device_api.h:2670
_ni_xcoder_params::chroma_linesize
int chroma_linesize
Definition: ni_device_api.h:2785
_ni_xcoder_params::minFramesDelay
int minFramesDelay
Definition: ni_device_api.h:2788
_ni_xcoder_params::sar_num
int sar_num
Definition: ni_device_api.h:2759
NI_VPU_ALIGN128
#define NI_VPU_ALIGN128(_x)
Definition: ni_device_api.h:334
XCODER_TEST_RECONF_RC_MIN_MAX_QP
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP
Definition: ni_device_api.h:1747
NI_ENC_PARAM_CU_TREE_FACTOR
#define NI_ENC_PARAM_CU_TREE_FACTOR
Definition: ni_device_api.h:2207
NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
#define NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
Definition: ni_device_api.h:2184
_ni_packet
Definition: ni_device_api.h:2825
_ni_buf_pool_t
Definition: ni_device_api.h:1282
NI_DEC_PARAM_SCALE_2_ROUND
#define NI_DEC_PARAM_SCALE_2_ROUND
Definition: ni_device_api.h:2473
_ni_device_temp
Definition: ni_rsrc_api.h:235
NI_DATA_BUFFER_LEN
#define NI_DATA_BUFFER_LEN
Definition: ni_nvme.h:625
NI_ENC_PARAM_MOTION_CONSTRAINED_MODE
#define NI_ENC_PARAM_MOTION_CONSTRAINED_MODE
Definition: ni_device_api.h:2230
_ni_session_context::frame_num
uint64_t frame_num
Definition: ni_device_api.h:1531
_ni_encoder_cfg_params::HDR10Enable
int HDR10Enable
Definition: ni_device_api.h:2273
ni_device_session_context_clear
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
Definition: ni_device_api.c:249
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_1
uint32_t sub_ctu_qp_1
Definition: ni_device_api.h:856
_ni_encoder_cfg_params::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2386
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:11283
_ni_encoder_cfg_params::intra_qp_delta
int intra_qp_delta
Definition: ni_device_api.h:2369
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1951
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:13364
_ni_xcoder_params::ai_enhance_level
int ai_enhance_level
Definition: ni_device_api.h:2786
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
Definition: ni_device_api.h:1886
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:1932
_ni_session_context::roi_map
ni_enc_quad_roi_custom_map * roi_map
Definition: ni_device_api.h:1582
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:1489
_ni_network_layer_offset::offset
int32_t offset
Definition: ni_device_api.h:1360
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1934
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:2092
NI_XCODER_PRESET_NAME_DEFAULT
#define NI_XCODER_PRESET_NAME_DEFAULT
Definition: ni_device_api.h:2879
NI_VPU_ALIGN8
#define NI_VPU_ALIGN8(_x)
Definition: ni_device_api.h:330
_ni_encoder_cfg_params::colorDescPresent
int colorDescPresent
Definition: ni_device_api.h:2311
NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2467
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1874
NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
Definition: ni_device_api.h:1883
NI_RETCODE_PARAM_ERROR_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_TOO_BIG
Definition: ni_defs.h:489
NI_ENC_PARAM_RECONF_FILE
#define NI_ENC_PARAM_RECONF_FILE
Definition: ni_device_api.h:2064
_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:11083
_ni_session_context::last_gop_size
int last_gop_size
Definition: ni_device_api.h:1691
_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:2329
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:18139
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2663
NI_ENC_GOP_PARAMS_G7_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G7_QP_OFFSET
Definition: ni_device_api.h:1939
_ni_encoder_cfg_params::custom_gop_params
ni_custom_gop_params_t custom_gop_params
Definition: ni_device_api.h:2255
NI_VPU_CEIL
#define NI_VPU_CEIL(_data, _align)
Definition: ni_device_api.h:328
_ni_encoder_cfg_params::HDR10dx0
int HDR10dx0
Definition: ni_device_api.h:2274
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:4121
NI_EC_POLICY_DEFAULT
#define NI_EC_POLICY_DEFAULT
Definition: ni_device_api.h:324
_ni_xcoder_params::zerocopy_mode
int zerocopy_mode
Definition: ni_device_api.h:2783
_ni_xcoder_params::sar_denom
int sar_denom
Definition: ni_device_api.h:2760
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:8517
_ni_decoder_input_params_t::max_extra_hwframe_cnt
int max_extra_hwframe_cnt
Definition: ni_device_api.h:2527
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:2058
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:8880
_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:2426
ni_strcasecmp
int ni_strcasecmp(const char *a, const char *b)
Definition: ni_device_api.c:12603
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
Definition: ni_device_api.h:1839
XCODER_TEST_RECONF_VBV_API
@ XCODER_TEST_RECONF_VBV_API
Definition: ni_device_api.h:1772
XCODER_TEST_FORCE_IDR_FRAME
@ XCODER_TEST_FORCE_IDR_FRAME
Definition: ni_device_api.h:1759
NI_DEVICE_TYPE_SCALER
@ NI_DEVICE_TYPE_SCALER
Definition: ni_defs.h:348
_ni_scaler_input_params_t::in_rec_y
int32_t in_rec_y
Definition: ni_device_api.h:2552
_ni_encoder_cfg_params::tolCtbRcIntra
float tolCtbRcIntra
Definition: ni_device_api.h:2330
NI_XCODER_WRITE_STATE
@ NI_XCODER_WRITE_STATE
Definition: ni_device_api.h:246
NI_XCODER_LOG_NAMES_ARRAY_LEN
#define NI_XCODER_LOG_NAMES_ARRAY_LEN
Definition: ni_device_api.h:2877
ni_decoder_init_default_params
ni_retcode_t ni_decoder_init_default_params(ni_xcoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height)
Initialize default decoder parameters.
Definition: ni_device_api.c:4546
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:2421
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:3761
_ni_decoder_input_params_t::enable_all_sei_passthru
bool enable_all_sei_passthru
Definition: ni_device_api.h:2530
NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
#define NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
Definition: ni_device_api.h:2217
NI_ERRNO
#define NI_ERRNO
Definition: ni_defs.h:217
_ni_encoder_cfg_params::disable_adaptive_buffers
bool disable_adaptive_buffers
Definition: ni_device_api.h:2425
NI_ENC_PARAM_SKIP_FRAME_INTERVAL
#define NI_ENC_PARAM_SKIP_FRAME_INTERVAL
Definition: ni_device_api.h:2170
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
Definition: ni_defs.h:494
NI_DEC_PARAM_EC_POLICY
#define NI_DEC_PARAM_EC_POLICY
Definition: ni_device_api.h:2484
NI_DEC_PARAM_ERROR_THRESHOLD
#define NI_DEC_PARAM_ERROR_THRESHOLD
Definition: ni_device_api.h:2486
_ni_session_context::vui
ni_vui_hrd_t vui
Definition: ni_device_api.h:1605
_ni_encoder_cfg_params::enable_dynamic_16x16_merge
int enable_dynamic_16x16_merge
Definition: ni_device_api.h:2351
NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
#define NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
Definition: ni_device_api.h:2178
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:12791
NI_PARAM_AV1_ALIGN_WIDTH_HEIGHT
#define NI_PARAM_AV1_ALIGN_WIDTH_HEIGHT
Definition: ni_device_api.h:148
_ni_session_context::hw_action
int hw_action
Definition: ni_device_api.h:1609
NI_ENC_PARAM_LOG
#define NI_ENC_PARAM_LOG
Definition: ni_device_api.h:2075
NI_ENC_PARAM_SKIP_FRAME_ENABLE
#define NI_ENC_PARAM_SKIP_FRAME_ENABLE
Definition: ni_device_api.h:2168
_ni_session_context
Definition: ni_device_api.h:1408
_ni_rc_min_max_qp::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:709
_ni_encoder_cfg_params::iframe_size_ratio
int iframe_size_ratio
Definition: ni_device_api.h:2422
_ni_scaler_input_params_t::out_rec_x
int32_t out_rec_x
Definition: ni_device_api.h:2559
_ni_scaler_input_params_t::input_width
int32_t input_width
Definition: ni_device_api.h:2547
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:265
ni_memfree
#define ni_memfree(p_memptr)
Definition: ni_util.h:408
_ni_session_context::bus
unsigned short bus
Definition: ni_device_api.h:1620
NI_ENC_PARAM_FORCED_HEADER_ENABLE
#define NI_ENC_PARAM_FORCED_HEADER_ENABLE
Definition: ni_device_api.h:2094
NI_ENC_PARAM_BITRATE_WINDOW
#define NI_ENC_PARAM_BITRATE_WINDOW
Definition: ni_device_api.h:2158
_ni_thread_arg_struct_t::hw_id
int hw_id
Definition: ni_device_api.h:1259
NI_ENC_PARAM_ENABLE_VFR
#define NI_ENC_PARAM_ENABLE_VFR
Definition: ni_device_api.h:2186
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:1960
ni_device_session_read
int ni_device_session_read(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, ni_device_type_t device_type)
Read data from the device If device_type is NI_DEVICE_TYPE_DECODER reads data packet from decoder If ...
Definition: ni_device_api.c:1769
_niFrameSurface1
Definition: ni_device_api.h:2793
NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
Definition: ni_device_api.h:2083
NI_EC_ERR_THRESHOLD_DEFAULT
#define NI_EC_ERR_THRESHOLD_DEFAULT
Definition: ni_device_api.h:325
ni_frame_buffer_alloc_hwenc
ni_retcode_t ni_frame_buffer_alloc_hwenc(ni_frame_t *p_frame, int video_width, int video_height, int extra_len)
Allocate memory for the hwDescriptor buffer based on provided parameters taking into account pic size...
Definition: ni_device_api.c:8399
NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_NUM_DATA_POINTERS
Definition: ni_defs.h:232
ni_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:12913
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
Definition: ni_device_api.h:1950
NI_XCODER_GENERAL_STATE
@ NI_XCODER_GENERAL_STATE
Definition: ni_device_api.h:257
NI_ENC_PARAM_INTRA_REFRESH_RESET
#define NI_ENC_PARAM_INTRA_REFRESH_RESET
Definition: ni_device_api.h:2106
NI_PARAM_AV1_MAX_HEIGHT
#define NI_PARAM_AV1_MAX_HEIGHT
Definition: ni_device_api.h:146
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:528
ni_pthread_mutex_init
int ni_pthread_mutex_init(ni_pthread_mutex_t *mutex)
initialize a mutex
Definition: ni_util.c:4001
_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:143
_ni_session_context::blk_xcoder_name
char blk_xcoder_name[MAX_CHAR_IN_DEVICE_NAME]
Definition: ni_device_api.h:1490
_ni_frame
Definition: ni_device_api.h:2601
NI_ENC_GOP_PARAMS_G0_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G0_QP_OFFSET
Definition: ni_device_api.h:1834
_ni_network_data::input_num
uint32_t input_num
Definition: ni_device_api.h:1365
_ni_encoder_cfg_params::HDR10dy1
int HDR10dy1
Definition: ni_device_api.h:2277
NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
#define NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
Definition: ni_device_api.h:2173
NI_PIX_FMT_YUYV422
@ NI_PIX_FMT_YUYV422
Definition: ni_device_api.h:273
NI_PIX_FMT_RGBA
@ NI_PIX_FMT_RGBA
Definition: ni_device_api.h:266
_ni_encoder_change_params_t::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:1004
_ni_encoder_cfg_params::conf_win_bottom
int conf_win_bottom
Definition: ni_device_api.h:2298
_ni_decoder_input_params_t::scale_round
int scale_round[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2535
NI_ENC_PARAM_IFRAME_SIZE_RATIO
#define NI_ENC_PARAM_IFRAME_SIZE_RATIO
Definition: ni_device_api.h:2171
NI_DEPRECATED
#define NI_DEPRECATED
Definition: ni_defs.h:77
ni_device_session_open
ni_retcode_t ni_device_session_open(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Open a new device session depending on the device_type parameter If device_type is NI_DEVICE_TYPE_DEC...
Definition: ni_device_api.c:710
_ni_session_context::roi_len
uint32_t roi_len
Definition: ni_device_api.h:1496
NI_DDR_PRIORITY_NONE
@ NI_DDR_PRIORITY_NONE
Definition: ni_device_api.h:1824
ni_device_session_context_free
void ni_device_session_context_free(ni_session_context_t *p_ctx)
Free previously allocated session context.
Definition: ni_device_api.c:130
_ni_encoder_cfg_params::profile
int profile
Definition: ni_device_api.h:2248
_ni_resolution::width
int32_t width
Definition: ni_device_api_priv.h:673
XCODER_TEST_RECONF_VUI_HRD_API
@ XCODER_TEST_RECONF_VUI_HRD_API
Definition: ni_device_api.h:1762
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:2314
_ni_session_context::max_frame_delay
int max_frame_delay
Definition: ni_device_api.h:1694
_ni_gop_params::rps
ni_gop_rps_t rps[NI_MAX_REF_PIC]
Definition: ni_device_api.h:1967
CONFIG_INSTANCE_SetScalerDrawBoxPara_W
#define CONFIG_INSTANCE_SetScalerDrawBoxPara_W(sid, instance)
Definition: ni_nvme.h:824
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:2732
NI_DEC_CROP_MODE_MANUAL
@ NI_DEC_CROP_MODE_MANUAL
Definition: ni_device_api.h:930
XCODER_TEST_RECONF_LONG_TERM_REF
@ XCODER_TEST_RECONF_LONG_TERM_REF
Definition: ni_device_api.h:1745
NI_ENC_PARAM_GOP_PRESET_IDX
#define NI_ENC_PARAM_GOP_PRESET_IDX
Definition: ni_device_api.h:2076
NI_ENC_PARAM_ENTROPY_CODING_MODE
#define NI_ENC_PARAM_ENTROPY_CODING_MODE
Definition: ni_device_api.h:2109
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:338
_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:2331
NI_RETCODE_ERROR_INVALID_SESSION
@ NI_RETCODE_ERROR_INVALID_SESSION
Definition: ni_defs.h:433
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3
Definition: ni_device_api.h:1890
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:13561
NI_PIX_FMT_ABGR
@ NI_PIX_FMT_ABGR
Definition: ni_device_api.h:269
ni_strtok
char * ni_strtok(char *s, const char *delim, char **saveptr)
Definition: ni_util.c:420
ni_device_session_copy
ni_retcode_t ni_device_session_copy(ni_session_context_t *src_p_ctx, ni_session_context_t *dst_p_ctx)
Copy existing decoding session params for hw frame usage.
Definition: ni_device_api.c:8015
_ni_enc_hevc_roi_custom_map::field
struct _ni_enc_hevc_roi_custom_map::@4 field
_ni_load_query::total_pixel_load
uint32_t total_pixel_load
Definition: ni_device_api.h:1217
QUERY_GET_NS_VF_R
#define QUERY_GET_NS_VF_R
Definition: ni_nvme.h:796
NI_PIX_FMT_ARGB
@ NI_PIX_FMT_ARGB
Definition: ni_device_api.h:268
NI_ENC_PARAM_CONSTANT_RATE_FACTOR
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR
Definition: ni_device_api.h:2127
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:10176
_ni_xcoder_params
Definition: ni_device_api.h:2713
NI_ENC_PARAM_MULTICORE_JOINT_MODE
#define NI_ENC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2153
NI_DEC_PARAM_CROP_PARAM_2
#define NI_DEC_PARAM_CROP_PARAM_2
Definition: ni_device_api.h:2461
_ni_session_context::p_hdr_buf
uint8_t * p_hdr_buf
Definition: ni_device_api.h:1511
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
Definition: ni_defs.h:496
NI_ENC_PARAM_PREFERRED_TRANSFER_CHARACTERISTICS
#define NI_ENC_PARAM_PREFERRED_TRANSFER_CHARACTERISTICS
Definition: ni_device_api.h:2118
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
Definition: ni_device_api.h:2203
NI_XCODER_READ_DESC_STATE
@ NI_XCODER_READ_DESC_STATE
Definition: ni_device_api.h:253
_ni_decoder_input_params_t::reduce_dpb_delay
int reduce_dpb_delay
Definition: ni_device_api.h:2540
_ni_encoder_cfg_params::max_delta_qp
int max_delta_qp
Definition: ni_device_api.h:2382
_ni_xcoder_params::staticMmapThreshold
int staticMmapThreshold
Definition: ni_device_api.h:2780
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:1566
_ni_encoder_cfg_params::ctbRowQpStep
int ctbRowQpStep
Definition: ni_device_api.h:2390
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1949
NI_ENC_PARAM_COLOR_SPACE
#define NI_ENC_PARAM_COLOR_SPACE
Definition: ni_device_api.h:2179
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
Definition: ni_device_api.h:1873
_ni_session_context::low_delay_sync_cond
ni_pthread_cond_t low_delay_sync_cond
Definition: ni_device_api.h:1666
NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
#define NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
Definition: ni_device_api.h:2172
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
Definition: ni_device_api.h:1916
_ni_encoder_cfg_params::motionConstrainedMode
int motionConstrainedMode
Definition: ni_device_api.h:2432
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:13456
NI_ENC_GOP_PARAMS_G4_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G4_POC_OFFSET
Definition: ni_device_api.h:1893
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
Definition: ni_device_api.h:1773
_ni_session_context::ready_to_close
uint32_t ready_to_close
Definition: ni_device_api.h:1544
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1889
_ni_session_context::thread_event_handle
ni_event_handle_t thread_event_handle
Definition: ni_device_api.h:1575
NI_PARAM_AV1_MIN_HEIGHT
#define NI_PARAM_AV1_MIN_HEIGHT
Definition: ni_device_api.h:144
_ni_encoder_cfg_params::decoding_refresh_type
int decoding_refresh_type
Definition: ni_device_api.h:2360
NI_XCODER_LOG_NAME_ERROR
#define NI_XCODER_LOG_NAME_ERROR
Definition: ni_device_api.h:2883
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:3077
_ni_load_query::fw_load
uint32_t fw_load
Definition: ni_device_api.h:1200
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:17752
_ni_encoder_cfg_params::crop_width
int crop_width
Definition: ni_device_api.h:2395
GOP_PRESET_IDX_IBBBP
@ GOP_PRESET_IDX_IBBBP
Definition: ni_device_api_priv.h:325
_ni_thread_arg_struct_t
Definition: ni_device_api.h:1257
NI_MIN_FRAME_SIZE
#define NI_MIN_FRAME_SIZE
Definition: ni_device_api.h:177
_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:2453
_ni_encoder_cfg_params::slice_mode
int slice_mode
Definition: ni_device_api.h:2357
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:10468
NI_ENC_PARAM_FRAME_RATE_DENOM
#define NI_ENC_PARAM_FRAME_RATE_DENOM
Definition: ni_device_api.h:2103
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:9945
NI_ENC_PARAM_AVCC_HVCC
#define NI_ENC_PARAM_AVCC_HVCC
Definition: ni_device_api.h:2188
_ni_resolution::height
int32_t height
Definition: ni_device_api_priv.h:676
_ni_encoder_cfg_params::HDR10minluma
int HDR10minluma
Definition: ni_device_api.h:2283
NI_DEC_PARAM_SURVIVE_STREAM_ERR
#define NI_DEC_PARAM_SURVIVE_STREAM_ERR
Definition: ni_device_api.h:2495
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
Definition: ni_device_api.h:1884
NI_ENC_PARAM_QCOMP
#define NI_ENC_PARAM_QCOMP
Definition: ni_device_api.h:2204
NI_MAX_PPU_PARAM_EXPR_CHAR
#define NI_MAX_PPU_PARAM_EXPR_CHAR
Definition: ni_defs.h:247
XCODER_TEST_RECONF_LTR_API
@ XCODER_TEST_RECONF_LTR_API
Definition: ni_device_api.h:1763
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:17665
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:15297
_ni_session_context::codec_format
uint32_t codec_format
Definition: ni_device_api.h:1486
_ni_session_context::max_frame_size
int32_t max_frame_size
Definition: ni_device_api.h:1655
_ni_device_capability
device capability type
Definition: ni_device_api.h:1153
NI_MAX_NUM_OF_DECODER_OUTPUTS
#define NI_MAX_NUM_OF_DECODER_OUTPUTS
Definition: ni_defs.h:243
_ni_rc_min_max_qp::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:710
XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
Definition: ni_device_api.h:1768
NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
#define NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
Definition: ni_device_api.h:2234
ni_posix_memalign
int ni_posix_memalign(void **memptr, size_t alignment, size_t size)
Allocate aligned memory.
Definition: ni_util.c:198
NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
@ NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
Definition: ni_defs.h:522
NI_DEC_PARAM_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:2480
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:1923
_ni_decoder_input_params_t::scale_wh
int scale_wh[NI_MAX_NUM_OF_DECODER_OUTPUTS][2]
Definition: ni_device_api.h:2511
_ni_encoder_cfg_params::colorPrimaries
int colorPrimaries
Definition: ni_device_api.h:2312
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:8947
NI_DEC_PARAM_FORCE_8BIT_0
#define NI_DEC_PARAM_FORCE_8BIT_0
Definition: ni_device_api.h:2450
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:2876
NI_DISABLE_USR_DATA_SEI_PASSTHRU
#define NI_DISABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:315
_ni_encoder_cfg_params::forceBframeQpfactor
float forceBframeQpfactor
Definition: ni_device_api.h:2427
NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
#define NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
Definition: ni_device_api.h:2489
_ni_load_query
Definition: ni_device_api.h:1196
XCODER_TEST_CRF_FLOAT_API
@ XCODER_TEST_CRF_FLOAT_API
Definition: ni_device_api.h:1771
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:9145
_ni_session_context::is_auto_dl
uint8_t is_auto_dl
Definition: ni_device_api.h:1470
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
Definition: ni_device_api.h:1757
NI_DEC_PARAM_REDUCE_DPB_DELAY
#define NI_DEC_PARAM_REDUCE_DPB_DELAY
Definition: ni_device_api.h:2496
QUERY_GET_TEMPERATURE_R
#define QUERY_GET_TEMPERATURE_R
Definition: ni_nvme.h:798
_ni_thread_arg_struct_t::session_id
uint32_t session_id
Definition: ni_device_api.h:1260
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:10054
_ni_encoder_cfg_params::crfFloat
float crfFloat
Definition: ni_device_api.h:2410
_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:2292
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:2464
_niFrameSurface1::ui16width
uint16_t ui16width
Definition: ni_device_api.h:2797
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:10697
NI_ENC_GOP_PARAMS_G3_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G3_POC_OFFSET
Definition: ni_device_api.h:1878
_ni_resolution::bit_depth_factor
int32_t bit_depth_factor
Definition: ni_device_api_priv.h:679
NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
#define NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
Definition: ni_device_api.h:2067
NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
#define NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
Definition: ni_device_api.h:2108
_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:1265
NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
Definition: ni_device_api.h:1943
_ni_session_context::keep_alive_thread
ni_pthread_t keep_alive_thread
Definition: ni_device_api.h:1556
_ni_session_context::load_query
ni_load_query_t load_query
Definition: ni_device_api.h:1500
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:2870
NI_ENC_GOP_PARAMS_G3_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G3_PIC_TYPE
Definition: ni_device_api.h:1882
NI_ENC_PARAM_CROP_WIDTH
#define NI_ENC_PARAM_CROP_WIDTH
Definition: ni_device_api.h:2199
_ni_decoder_input_params_t::enable_out2
int enable_out2
Definition: ni_device_api.h:2501
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
Definition: ni_device_api.h:1918
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:11562
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:2249
NI_ENC_PARAM_ENABLE_AI_HVSPLUS
#define NI_ENC_PARAM_ENABLE_AI_HVSPLUS
Definition: ni_device_api.h:2194
_ni_encoder_cfg_params::HDR10dy2
int HDR10dy2
Definition: ni_device_api.h:2279
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:2104
NI_SCALER_FLAG_P2
#define NI_SCALER_FLAG_P2
Definition: ni_device_api.h:294
NI_ENC_RC_QP_DELTA_RANGE
#define NI_ENC_RC_QP_DELTA_RANGE
Definition: ni_device_api.h:2161
_ni_thread_arg_struct_t::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1261
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1900
NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
Definition: ni_device_api.h:1926
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:4384
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1891
NI_FRAME_AUX_DATA_LTR_INTERVAL
@ NI_FRAME_AUX_DATA_LTR_INTERVAL
Definition: ni_device_api.h:553
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:3161
NI_MAX_NUM_SW_FRAME_DATA_POINTERS
#define NI_MAX_NUM_SW_FRAME_DATA_POINTERS
Definition: ni_defs.h:234
NI_ENC_GOP_PARAMS_G2_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G2_QP_OFFSET
Definition: ni_device_api.h:1864
NI_ENC_PARAM_SAR_DENOM
#define NI_ENC_PARAM_SAR_DENOM
Definition: ni_device_api.h:2182
NI_MAX_QP_INFO
#define NI_MAX_QP_INFO
Definition: ni_device_api.h:173
NI_DEC_PARAM_SAVE_PKT
#define NI_DEC_PARAM_SAVE_PKT
Definition: ni_device_api.h:2475
NI_INVALID_SVCT_DECODING_LAYER
#define NI_INVALID_SVCT_DECODING_LAYER
Definition: ni_device_api.h:317
NI_ENC_PARAM_LEVEL
#define NI_ENC_PARAM_LEVEL
Definition: ni_device_api.h:2072
NI_RETCODE_PARAM_INVALID_NAME
@ NI_RETCODE_PARAM_INVALID_NAME
Definition: ni_defs.h:436
_ni_session_context::keep_alive_thread_args
ni_thread_arg_struct_t * keep_alive_thread_args
Definition: ni_device_api.h:1557
NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
Definition: ni_device_api.h:1898
_ni_xcoder_params::color_space
int color_space
Definition: ni_device_api.h:2758
netint_iocmd_issue_request
Definition: ni_p2p_ioctl.h:72
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:266
_ni_frame::nb_aux_data
int nb_aux_data
Definition: ni_device_api.h:2678
NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
Definition: ni_device_api.h:1928
_ni_session_context::reconfig_crf
int reconfig_crf
Definition: ni_device_api.h:1685
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
Definition: ni_device_api.h:1903
_ni_encoder_cfg_params::maxFrameSize
int maxFrameSize
Definition: ni_device_api.h:2243
_ni_encoder_cfg_params::hvs_qp_scale
int hvs_qp_scale
Definition: ni_device_api.h:2375
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1915
_ni_encoder_cfg_params::cplxDecay
float cplxDecay
Definition: ni_device_api.h:2406
_ni_instance_mgr_general_status
Definition: ni_device_api_priv.h:79
atoi
#define atoi(p_str)
Definition: ni_device_api.c:7178
_ni_encoder_change_params_t::minQpI
int32_t minQpI
Definition: ni_device_api.h:998
ni_get_hw_yuv420p_dim
void ni_get_hw_yuv420p_dim(int width, int height, int factor, int is_semiplanar, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of Netint HW YUV420p frame to be sent to encoder for encoding....
Definition: ni_util.c:2040
_ni_decoder_input_params_t::skip_extra_headers
int skip_extra_headers
Definition: ni_device_api.h:2541
_ni_instance_mgr_detail_status
Definition: ni_device_api.h:1230
NI_PARAM_MAX_WIDTH
#define NI_PARAM_MAX_WIDTH
Definition: ni_device_api.h:135
_ni_enc_hevc_roi_custom_map
encoder HEVC ROI custom map (1 CTU = 64bits)
Definition: ni_device_api.h:848
END
#define END
Definition: ni_defs.h:324
_ni_decoder_input_params_t::enable_follow_iframe
int enable_follow_iframe
Definition: ni_device_api.h:2536
_ni_encoder_cfg_params::enable_hvs_qp
int enable_hvs_qp
Definition: ni_device_api.h:2374
_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:2611
NI_DEC_PARAM_SCALE_1_ROUND
#define NI_DEC_PARAM_SCALE_1_ROUND
Definition: ni_device_api.h:2472
_ni_decoder_input_params_t::pkt_pts_unchange
int pkt_pts_unchange
Definition: ni_device_api.h:2529
_ni_network_data::inset
ni_network_layer_offset_t * inset
Definition: ni_device_api.h:1369
_ni_packet::p_buffer
void * p_buffer
Definition: ni_device_api.h:2841
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:3807
NI_ENC_PARAM_VERTICAL_OFFSET
#define NI_ENC_PARAM_VERTICAL_OFFSET
Definition: ni_device_api.h:2202
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:10251
NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
#define NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
Definition: ni_device_api.h:2235
_ni_decoder_input_params_t::force_8_bit
int force_8_bit[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2504
NI_ENC_PARAM_SLICE_ARG
#define NI_ENC_PARAM_SLICE_ARG
Definition: ni_device_api.h:2112
NI_MAX_MAX_NUM_MERGE
#define NI_MAX_MAX_NUM_MERGE
Definition: ni_device_api.h:163
_ni_vui_hrd::colorSpace
int32_t colorSpace
Definition: ni_device_api.h:668
_ni_encoder_cfg_params::qcomp
float qcomp
Definition: ni_device_api.h:2400
_ni_session_context::low_delay_sync_flag
int low_delay_sync_flag
Definition: ni_device_api.h:1664
NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
#define NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
Max number of lines supported for qpoffset level.
Definition: ni_device_api.h:479
_ni_encoder_cfg_params::avcc_hvcc
int avcc_hvcc
Definition: ni_device_api.h:2440
_ni_decoder_input_params_t::custom_sei_passthru
int custom_sei_passthru
Definition: ni_device_api.h:2521
_ni_xcoder_params::ddr_priority_mode
ni_ddr_priority_mode_t ddr_priority_mode
Definition: ni_device_api.h:2787
_ni_encoder_cfg_params::colorTrc
int colorTrc
Definition: ni_device_api.h:2313
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:3716
_ni_session_context::active_video_height
uint32_t active_video_height
Definition: ni_device_api.h:1551
NI_ENC_PARAM_INTRA_PERIOD
#define NI_ENC_PARAM_INTRA_PERIOD
Definition: ni_device_api.h:2100
ni_pthread_mutex_destroy
int ni_pthread_mutex_destroy(ni_pthread_mutex_t *mutex)
destory a mutex
Definition: ni_util.c:4039
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:8296
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:12866
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:18069
NI_FRAME_AUX_DATA_LONG_TERM_REF
@ NI_FRAME_AUX_DATA_LONG_TERM_REF
Definition: ni_device_api.h:548
NI_ENC_PARAM_VBV_BUFFER_SIZE
#define NI_ENC_PARAM_VBV_BUFFER_SIZE
Definition: ni_device_api.h:2141
NI_MAX_SEI_DATA
#define NI_MAX_SEI_DATA
Definition: ni_device_api.h:426
_ni_session_context::pkt_delay_cnt
uint32_t pkt_delay_cnt
Definition: ni_device_api.h:1702
_ni_encoder_cfg_params::av1_error_resilient_mode
int av1_error_resilient_mode
Definition: ni_device_api.h:2388
_ni_encoder_cfg_params::tune_bframe_visual
int tune_bframe_visual
Definition: ni_device_api.h:2428
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:12908
ni_gop_params_check
bool ni_gop_params_check(ni_xcoder_params_t *p_param)
Check custom gop params set.
Definition: ni_device_api.c:12749
_ni_encoder_cfg_params::conf_win_left
int conf_win_left
Definition: ni_device_api.h:2299
NI_MAX_FRAME_SIZE
#define NI_MAX_FRAME_SIZE
Definition: ni_device_api.h:178
_ni_encoder_cfg_params::pass1_qp
int pass1_qp
Definition: ni_device_api.h:2409
_ni_encoder_cfg_params::conf_win_right
int conf_win_right
Definition: ni_device_api.h:2300
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:858
_ni_session_context::blk_dev_name
char blk_dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_device_api.h:1659
_ni_decoder_input_params_t::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:2519
NI_POOL_TYPE_NONE
@ NI_POOL_TYPE_NONE
Definition: ni_device_api.h:491
NI_ENC_PARAM_RC_INIT_DELAY
#define NI_ENC_PARAM_RC_INIT_DELAY
Definition: ni_device_api.h:2121
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1547
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:687
_ni_session_context::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:1595
NI_ENC_PARAM_HVS_QP_SCALE
#define NI_ENC_PARAM_HVS_QP_SCALE
Definition: ni_device_api.h:2090
NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2492
_niFrameSurface1::device_handle
int32_t device_handle
Definition: ni_device_api.h:2800
_ni_encoder_cfg_params::crfMax
int crfMax
Definition: ni_device_api.h:2399
_niFrameSurface1::bit_depth
int8_t bit_depth
Definition: ni_device_api.h:2801
NI_ENC_PARAM_DECODING_REFRESH_TYPE
#define NI_ENC_PARAM_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:2105
NI_ENC_GOP_PARAMS_G1_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G1_PIC_TYPE
Definition: ni_device_api.h:1852
ni_device_session_write
int ni_device_session_write(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, ni_device_type_t device_type)
Sends data to the device If device_type is NI_DEVICE_TYPE_DECODER sends data packet to decoder If dev...
Definition: ni_device_api.c:1668
ni_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:2403
_ni_network_layer_info::out_param
ni_network_layer_params_t * out_param
Definition: ni_device_api.h:1355
XCODER_TEST_INVALID_REF_FRAME_API
@ XCODER_TEST_INVALID_REF_FRAME_API
Definition: ni_device_api.h:1766
_ni_encoder_cfg_params::enableipRatio
int enableipRatio
Definition: ni_device_api.h:2420
_ni_enc_quad_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:883
_ni_decoder_input_params_t::scale_resolution_ceil
int scale_resolution_ceil[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2534
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:1161
NI_ENC_PARAM_LOW_DELAY
#define NI_ENC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2077
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
Definition: ni_device_api.h:1944
NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
#define NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
Definition: ni_device_api.h:2225
_ni_session_context::meta_size
uint32_t meta_size
Params used in VFR mode Done///.
Definition: ni_device_api.h:1638
ni_hwframe_buffer_recycle
ni_retcode_t ni_hwframe_buffer_recycle(niFrameSurface1_t *surface, int32_t device_handle)
Recycle a frame buffer on card.
Definition: ni_device_api.c:8487
_ni_encoder_cfg_params::vbv_min_rate
int vbv_min_rate
Definition: ni_device_api.h:2424
NI_ENC_PARAM_PPS_INIT_QP
#define NI_ENC_PARAM_PPS_INIT_QP
Definition: ni_device_api.h:2212
_ni_encoder_cfg_params::HDR10MaxLight
int HDR10MaxLight
Definition: ni_device_api.h:2270
_ni_xcoder_params::cacheRoi
int cacheRoi
Definition: ni_device_api.h:2747
_ni_session_context::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1482
_ni_encoder_cfg_params::still_image_detect_level
int still_image_detect_level
Definition: ni_device_api.h:2433
_ni_encoder_change_params_t::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:999
_ni_encoder_cfg_params::crop_height
int crop_height
Definition: ni_device_api.h:2396
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1930
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1476
_ni_encoder_cfg_params::aspectRatioHeight
int aspectRatioHeight
Definition: ni_device_api.h:2241
NI_MIN_HEIGHT
#define NI_MIN_HEIGHT
Definition: ni_device_api.h:126
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:428
NI_ENC_PARAM_GEN_HDRS
#define NI_ENC_PARAM_GEN_HDRS
Definition: ni_device_api.h:2068
_ni_encoder_cfg_params::HDR10dx1
int HDR10dx1
Definition: ni_device_api.h:2276
NI_ENC_PARAM_PSNR_INTERVAL
#define NI_ENC_PARAM_PSNR_INTERVAL
Definition: ni_device_api.h:2227
XCODER_TEST_RECONF_BR
@ XCODER_TEST_RECONF_BR
Definition: ni_device_api.h:1742
_ni_aux_data::type
ni_aux_data_type_t type
Definition: ni_device_api.h:620
NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
Definition: ni_device_api.h:1896
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:17231
NI_ENC_PARAM_ROI_ENABLE
#define NI_ENC_PARAM_ROI_ENABLE
Definition: ni_device_api.h:2095
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:2091
NI_MIN_BITRATE
#define NI_MIN_BITRATE
Definition: ni_device_api.h:114
_niFrameSurface1::dma_buf_fd
int32_t dma_buf_fd
Definition: ni_device_api.h:2805
_ni_encoder_cfg_params::planar
int planar
Definition: ni_device_api.h:2242
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
Definition: ni_device_api.h:1901
_ni_buf_t::buf
void * buf
Definition: ni_device_api.h:1274
_ni_session_context::reconfigCount
int reconfigCount
Definition: ni_device_api.h:1698
NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
Definition: ni_device_api.h:1868
_ni_packet::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2842
_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:500
_ni_vui_hrd::videoFullRange
int32_t videoFullRange
Definition: ni_device_api.h:679
NI_ENC_PARAM_VBV_MINRATE
#define NI_ENC_PARAM_VBV_MINRATE
Definition: ni_device_api.h:2220
_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:675
_ni_session_context::hdr_buf_size
uint8_t hdr_buf_size
Definition: ni_device_api.h:1512
_ni_instance_mgr_detail_status_v1
Definition: ni_device_api.h:1252
_ni_xcoder_params::enable_vfr
int enable_vfr
Definition: ni_device_api.h:2778
_ni_frame::inconsecutive_transfer
uint8_t inconsecutive_transfer
Definition: ni_device_api.h:2708
_ni_session_context::last_framerate
ni_framerate_t last_framerate
Definition: ni_device_api.h:1675
NI_ENC_PARAM_FRAME_RATE
#define NI_ENC_PARAM_FRAME_RATE
Definition: ni_device_api.h:2102
_ni_session_context::ltr_frame_ref_invalid
int32_t ltr_frame_ref_invalid
Definition: ni_device_api.h:1603
NI_SCALER_FLAG_PC
#define NI_SCALER_FLAG_PC
Definition: ni_device_api.h:292
_ni_encoder_cfg_params::rdoLevel
int rdoLevel
Definition: ni_device_api.h:2268
_ni_encoder_cfg_params::long_term_ref_enable
int long_term_ref_enable
Definition: ni_device_api.h:2259
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:490
_ni_encoder_cfg_params::get_psnr_mode
int get_psnr_mode
Definition: ni_device_api.h:2430
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:647
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:1695
_ni_encoder_cfg_params::ltrNextInterval
int ltrNextInterval
Definition: ni_device_api.h:2288
_ni_decoder_input_params_t::survive_stream_err
int survive_stream_err
Definition: ni_device_api.h:2539
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
Definition: ni_device_api.h:1858
NI_ENC_PARAM_LOG_LEVEL
#define NI_ENC_PARAM_LOG_LEVEL
Definition: ni_device_api.h:2074
COMPARE
#define COMPARE(STR1, STR2, STR3)
NI_ENC_PARAM_GOP_SIZE
#define NI_ENC_PARAM_GOP_SIZE
Definition: ni_device_api.h:2136
_ni_encoder_cfg_params::videoFullRange
int videoFullRange
Definition: ni_device_api.h:2290
ni_device_session_hwdl
int ni_device_session_hwdl(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, niFrameSurface1_t *hwdesc)
Reads YUV data from hw descriptor stored location on device.
Definition: ni_device_api.c:8210
ni_device_session_read_hwdesc
int ni_device_session_read_hwdesc(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, ni_device_type_t device_type)
Read data from the device If device_type is NI_DEVICE_TYPE_DECODER reads data hwdesc from decoder If ...
Definition: ni_device_api.c:8043
ni_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:15739
_ni_encoder_cfg_params::intra_reset_refresh
int intra_reset_refresh
Definition: ni_device_api.h:2389
NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
#define NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
Definition: ni_device_api.h:2223
_ni_scaler_input_params_t::in_rec_height
int32_t in_rec_height
Definition: ni_device_api.h:2550
NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2221
_ni_encoder_cfg_params::slice_arg
int slice_arg
Definition: ni_device_api.h:2358
NI_ENC_PARAM_ENABLE_TIMECODE
#define NI_ENC_PARAM_ENABLE_TIMECODE
Definition: ni_device_api.h:2233
_ni_frame::p_metadata_buffer
uint8_t * p_metadata_buffer
Definition: ni_device_api.h:2695
TOTAL_CPU_LOG_BUFFER_SIZE
#define TOTAL_CPU_LOG_BUFFER_SIZE
Definition: ni_defs.h:360
g_device_in_ctxt
NI_DEPRECATED bool g_device_in_ctxt
Definition: ni_rsrc_api.cpp:62
NI_ENC_PARAM_ENABLE_2PASS_GOP
#define NI_ENC_PARAM_ENABLE_2PASS_GOP
Definition: ni_device_api.h:2195
_ni_rc_min_max_qp::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:707
lower_pixel_rate
int lower_pixel_rate(const ni_load_query_t *pQuery, uint32_t ui32CurrentLowest)
Definition: ni_device_api_priv.c:18211
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
Definition: ni_device_api.h:1946
NI_ENC_CTB_ROW_QP_STEP
#define NI_ENC_CTB_ROW_QP_STEP
Definition: ni_device_api.h:2162
_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:2393
_ni_encoder_cfg_params::lookAheadDepth
int lookAheadDepth
Definition: ni_device_api.h:2267
NI_RETCODE_ERROR_INVALID_HANDLE
@ NI_RETCODE_ERROR_INVALID_HANDLE
Definition: ni_defs.h:511
NI_XCODER_LOG_NAME_DEBUG
#define NI_XCODER_LOG_NAME_DEBUG
Definition: ni_device_api.h:2886
NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
#define NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
Definition: ni_device_api.h:2117
NI_FRAME_AUX_DATA_CRF_FLOAT
@ NI_FRAME_AUX_DATA_CRF_FLOAT
Definition: ni_device_api.h:578
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:1589
_ni_custom_gop_params::pic_param
ni_gop_params_t pic_param[NI_MAX_GOP_NUM]
Definition: ni_device_api.h:2053
NI_ENC_PARAM_ENABLE_PIC_SKIP
#define NI_ENC_PARAM_ENABLE_PIC_SKIP
Definition: ni_device_api.h:2144
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:4548
ni_aligned_free
#define ni_aligned_free(p_memptr)
Definition: ni_util.h:399
_ni_session_context::dev
unsigned short dev
Definition: ni_device_api.h:1621
_ni_decoder_input_params_t::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:2517
_ni_xcoder_params::low_delay_mode
int low_delay_mode
Definition: ni_device_api.h:2733
_ni_decoder_input_params_t::nb_save_pkt
int nb_save_pkt
Definition: ni_device_api.h:2503
_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:152
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:10924
NI_ENC_PARAM_ENABLE_COMPENSATE_QP
#define NI_ENC_PARAM_ENABLE_COMPENSATE_QP
Definition: ni_device_api.h:2175
ni_device_session_flush
ni_retcode_t ni_device_session_flush(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Send a flush command to the device If device_type is NI_DEVICE_TYPE_DECODER sends EOS command to deco...
Definition: ni_device_api.c:1512
NI_RETCODE_PARAM_ERROR_ZERO
@ NI_RETCODE_PARAM_ERROR_ZERO
Definition: ni_defs.h:492
_ni_session_context::pkt_num
uint64_t pkt_num
Definition: ni_device_api.h:1532
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1872
NI_ENC_ENABLE_SSIM
#define NI_ENC_ENABLE_SSIM
Definition: ni_device_api.h:2187
_ni_encoder_cfg_params::enable_cu_level_rate_control
int enable_cu_level_rate_control
Definition: ni_device_api.h:2373
_ni_decoder_input_params_t::disable_adaptive_buffers
int disable_adaptive_buffers
Definition: ni_device_api.h:2537
NI_CODEC_FORMAT_H264
@ NI_CODEC_FORMAT_H264
Definition: ni_device_api.h:911
_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:17425
NI_ENC_GOP_PARAMS_G6_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G6_QP_OFFSET
Definition: ni_device_api.h:1924
NI_FRAME_AUX_DATA_INVALID_REF_FRAME
@ NI_FRAME_AUX_DATA_INVALID_REF_FRAME
Definition: ni_device_api.h:558
_ni_thread_arg_struct_t::plast_access_time
volatile uint64_t * plast_access_time
Definition: ni_device_api.h:1269
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:2703
NI_MAX_BIN
#define NI_MAX_BIN
Definition: ni_device_api.h:174
NI_ENC_GOP_PARAMS_G0_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PICS
Definition: ni_device_api.h:1838
NI_MAX_BITRATE
#define NI_MAX_BITRATE
Definition: ni_device_api.h:113
NI_RETCODE_PARAM_ERROR_OOR
@ NI_RETCODE_PARAM_ERROR_OOR
Definition: ni_defs.h:493
NI_ENC_GOP_PARAMS_G1_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G1_POC_OFFSET
Definition: ni_device_api.h:1848
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2610
_ni_session_context::initial_frame_delay
int initial_frame_delay
Definition: ni_device_api.h:1692
_ni_input_frame
Definition: ni_device_api.h:1396
NI_FRAME_LITTLE_ENDIAN
#define NI_FRAME_LITTLE_ENDIAN
Definition: ni_device_api.h:108
_ni_xcoder_params::bitrate
int bitrate
Definition: ni_device_api.h:2729
_ni_encoder_cfg_params::HDR10wy
int HDR10wy
Definition: ni_device_api.h:2281
netint_iocmd_signal_rfence
Definition: ni_p2p_ioctl.h:87
NI_MIN_WIDTH
#define NI_MIN_WIDTH
Definition: ni_device_api.h:124
NI_DEC_PARAM_FORCE_LOW_DELAY
#define NI_DEC_PARAM_FORCE_LOW_DELAY
Definition: ni_device_api.h:2477
ni_device_session_context_init
ni_retcode_t ni_device_session_context_init(ni_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
Definition: ni_device_api.c:156
ni_uploader_frame_zerocopy_check
ni_retcode_t ni_uploader_frame_zerocopy_check(ni_session_context_t *p_upl_ctx, int width, int height, const int linesize[], int pixel_format)
Check if incoming frame is hwupload zero copy compatible or not.
Definition: ni_device_api.c:3028
_ni_encoder_cfg_params::preferred_transfer_characteristics
int preferred_transfer_characteristics
Definition: ni_device_api.h:2265
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:8564
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1616
_ni_xcoder_params::use_low_delay_poc_type
int use_low_delay_poc_type
Definition: ni_device_api.h:2736
_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:2297
QUADRA
#define QUADRA
Definition: ni_defs.h:120
NI_ENC_PARAM_PASS1_QP
#define NI_ENC_PARAM_PASS1_QP
Definition: ni_device_api.h:2215
_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:1836
ni_ai_network_layer_size
uint32_t ni_ai_network_layer_size(ni_network_layer_params_t *p_param)
Definition: ni_util.c:3363
NI_DEC_PARAM_DDR_PRIORITY_MODE
#define NI_DEC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2483
MAX_CHAR_IN_DEVICE_NAME
#define MAX_CHAR_IN_DEVICE_NAME
Definition: ni_device_api.h:184
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:2229
_ni_encoder_cfg_params::bitrateMode
int bitrateMode
Definition: ni_device_api.h:2408
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:12822
NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
#define NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
Definition: ni_device_api.h:2479
_ni_aux_data
Definition: ni_device_api.h:618
_ni_scaler_input_params_t::in_rec_width
int32_t in_rec_width
Definition: ni_device_api.h:2549
NI_PIXEL_PLANAR_FORMAT_TILED4X4
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
Definition: ni_device_api.h:922
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:62
_ni_framerate
Definition: ni_device_api.h:695
_ni_vui_hrd::aspectRatioWidth
int32_t aspectRatioWidth
Definition: ni_device_api.h:672
NI_ENC_PARAM_SLICE_MODE
#define NI_ENC_PARAM_SLICE_MODE
Definition: ni_device_api.h:2111
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:10869
NI_MAX_RESOLUTION_LINESIZE
#define NI_MAX_RESOLUTION_LINESIZE
Definition: ni_device_api.h:106
NI_FRAME_AUX_DATA_INTRAPRD
@ NI_FRAME_AUX_DATA_INTRAPRD
Definition: ni_device_api.h:539
NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
#define NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
Definition: ni_device_api.h:2057
ni_decoder_frame_buffer_pool_return_buf
void ni_decoder_frame_buffer_pool_return_buf(ni_buf_t *buf, ni_buf_pool_t *p_buffer_pool)
Return a memory buffer to memory buffer pool.
Definition: ni_device_api.c:3694
_ni_xcoder_params::dec_input_params
ni_decoder_input_params_t dec_input_params
Definition: ni_device_api.h:2766
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:238
_ni_xcoder_params::color_transfer_characteristic
int color_transfer_characteristic
Definition: ni_device_api.h:2757
_ni_custom_gop_params
Definition: ni_device_api.h:2050
ni_device_session_close
ni_retcode_t ni_device_session_close(ni_session_context_t *p_ctx, int eos_recieved, ni_device_type_t device_type)
Close device session that was previously opened by calling ni_device_session_open() If device_type is...
Definition: ni_device_api.c:1379
NI_DEC_PARAM_ENABLE_PPU_SCALE_ADAPT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_ADAPT
Definition: ni_device_api.h:2487
NI_PARAM_MIN_HEIGHT
#define NI_PARAM_MIN_HEIGHT
Definition: ni_device_api.h:138
_ni_enc_quad_roi_custom_map::qp_info
uint8_t qp_info
Definition: ni_device_api.h:889
_ni_gop_params::temporal_id
int temporal_id
Definition: ni_device_api.h:1964
NI_PIXEL_PLANAR_FORMAT_PLANAR
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
Definition: ni_device_api.h:921
_ni_rc_min_max_qp::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:708
NI_DEFAULT_CU_SIZE_MODE
#define NI_DEFAULT_CU_SIZE_MODE
Definition: ni_device_api.h:158
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:4984
NI_MIN_GOP_PRESET_IDX
#define NI_MIN_GOP_PRESET_IDX
Definition: ni_device_api.h:153
NI_XCODER_FLUSH_STATE
@ NI_XCODER_FLUSH_STATE
Definition: ni_device_api.h:250
NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
Definition: ni_device_api.h:2087
NI_DEC_PARAM_SEMI_PLANAR_2
#define NI_DEC_PARAM_SEMI_PLANAR_2
Definition: ni_device_api.h:2455
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:10026
NI_MAX_INTRA_QP_DELTA
#define NI_MAX_INTRA_QP_DELTA
Definition: ni_device_api.h:167
ni_decoder_frame_buffer_free
ni_retcode_t ni_decoder_frame_buffer_free(ni_frame_t *p_frame)
Free decoder frame buffer that was previously allocated with ni_decoder_frame_buffer_alloc,...
Definition: ni_device_api.c:3644
_ni_session_context::roi_avg_qp
uint32_t roi_avg_qp
Definition: ni_device_api.h:1497
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:1579
NI_MAX_ASPECTRATIO
#define NI_MAX_ASPECTRATIO
Definition: ni_device_api.h:117
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:10541
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:473
_ni_session_context::force_low_delay_cnt
uint32_t force_low_delay_cnt
Definition: ni_device_api.h:1700
NI_MAX_RESOLUTION_AREA
#define NI_MAX_RESOLUTION_AREA
Definition: ni_device_api.h:102
_ni_xcoder_params::p_first_frame
ni_frame_t * p_first_frame
Definition: ni_device_api.h:2776
NI_ENC_PARAM_HVSPLUS_LEVEL
#define NI_ENC_PARAM_HVSPLUS_LEVEL
Definition: ni_device_api.h:2198
NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
Definition: ni_device_api.h:1853
_ni_session_context::p_master_display_meta_data
void * p_master_display_meta_data
Definition: ni_device_api.h:1432
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:1799
NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2494
_ni_encoder_cfg_params::forced_header_enable
int forced_header_enable
Definition: ni_device_api.h:2258
NI_DEC_PARAM_MIN_PACKETS_DELAY
#define NI_DEC_PARAM_MIN_PACKETS_DELAY
Definition: ni_device_api.h:2478
_ni_encoder_cfg_params::spatial_layers_ref_base_layer
int spatial_layers_ref_base_layer
Definition: ni_device_api.h:2441
_ni_session_context::async_mode
int async_mode
Definition: ni_device_api.h:1663
NI_FRAME_AUX_DATA_BITRATE
@ NI_FRAME_AUX_DATA_BITRATE
Definition: ni_device_api.h:535
NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
@ NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
Definition: ni_defs.h:507
IDENTIFY_DEVICE_R
#define IDENTIFY_DEVICE_R
Definition: ni_nvme.h:688
NI_DEC_PARAM_SCALE_1_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_1_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2466
_ni_scaler_input_params_t::output_format
int output_format
Definition: ni_device_api.h:2554
NI_RETCODE_ERROR_OPEN_DEVICE
@ NI_RETCODE_ERROR_OPEN_DEVICE
Definition: ni_defs.h:510
NI_CODEC_FORMAT_H265
@ NI_CODEC_FORMAT_H265
Definition: ni_device_api.h:912
_ni_scaler_input_params_t::output_width
int32_t output_width
Definition: ni_device_api.h:2555
NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
#define NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
Definition: ni_device_api.h:2169
ni_frame_wipe_aux_data
void ni_frame_wipe_aux_data(ni_frame_t *frame)
Free and remove all auxiliary data from the frame.
Definition: ni_device_api.c:4115
_ni_session_context::last_access_time
volatile uint64_t last_access_time
Definition: ni_device_api.h:1683
_ni_packet::data_len
uint32_t data_len
Definition: ni_device_api.h:2838
NI_MIN_INTRA_QP
#define NI_MIN_INTRA_QP
Definition: ni_device_api.h:166
NI_DEC_PARAM_CROP_MODE_1
#define NI_DEC_PARAM_CROP_MODE_1
Definition: ni_device_api.h:2457