libxcoder  5.3.1
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  (!p_enc_params->enable_ai_enhance || width % 128 == 0) && // align for AI engine
2816  width >= NI_MIN_WIDTH &&
2817  height >= NI_MIN_HEIGHT &&
2818  !ishwframe &&
2819  (!isplanar || linesize[2] == linesize[1]) // for planar, make sure cb linesize equal to cr linesize
2820  )
2821  {
2822  // send luma / chorma linesize to device (device is also aware frame will not be padded for 2-pass workaround)
2823  p_enc_params->luma_linesize = linesize[0];
2824  p_enc_params->chroma_linesize = (isrgba) ? 0 : linesize[1]; // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format
2825  return NI_RETCODE_SUCCESS;
2826  }
2827  else
2828  {
2829  p_enc_params->luma_linesize = 0;
2830  p_enc_params->chroma_linesize = 0;
2831  }
2832  }
2833  else if (p_enc_params->luma_linesize ||
2834  p_enc_params->chroma_linesize)
2835  {
2836  ni_log2(p_enc_ctx, NI_LOG_DEBUG, "%s "
2837  "luma_linesize %d, chroma_linesize %d, "
2838  "linesize[0] %d, linesize[1] %d\n",
2839  __func__, p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
2840  linesize[0], linesize[1]);
2841  if (p_enc_params->luma_linesize != linesize[0] ||
2842  (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
2843  )
2844  {
2845 #ifndef XCODER_311
2846  // linesizes can change during SW frame seqeunce change transcoding when FFmpeg noautoscale option is not set
2847  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: linesize changed from %u %u to %u %u - resolution change?\n", __func__,
2848  p_enc_params->luma_linesize, p_enc_params->chroma_linesize,
2849  linesize[0], linesize[1]);
2850 #endif
2851  }
2852  else
2853  return NI_RETCODE_SUCCESS;
2854  }
2855  }
2856 
2858 }
2859 
2860 /*!*****************************************************************************
2861  * \brief Allocate memory for encoder zero copy (metadata, etc.)
2862  * for encoding based on given
2863  * parameters, taking into account pic linesize and extra data.
2864  * Applicable to YUV planr / semi-planar 8 or 10 bit and RGBA pixel formats.
2865  *
2866  *
2867  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
2868  * \param[in] video_width Width of the video frame
2869  * \param[in] video_height Height of the video frame
2870  * \param[in] linesize Picture line size
2871  * \param[in] data Picture data pointers (for each of YUV planes)
2872  * \param[in] extra_len Extra data size (incl. meta data)
2873  *
2874  * \return On success
2875  * NI_RETCODE_SUCCESS
2876  * On failure
2877  * NI_RETCODE_INVALID_PARAM
2878  * NI_RETCODE_ERROR_MEM_ALOC
2879  *****************************************************************************/
2881  int video_width, int video_height,
2882  const int linesize[], const uint8_t *data[],
2883  int extra_len)
2884 {
2885  int retval = NI_RETCODE_SUCCESS;
2886 
2887  if ((!p_frame) || (!linesize) || (!data))
2888  {
2889  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
2890  "p_frame %p, linesize %p, data %p\n",
2891  __func__, p_frame, linesize, data);
2892  return NI_RETCODE_INVALID_PARAM;
2893  }
2894 
2896  "%s: resolution=%dx%d linesize=%d/%d/%d "
2897  "data=%p %p %p extra_len=%d\n",
2898  __func__, video_width, video_height,
2899  linesize[0], linesize[1], linesize[2],
2900  data[0], data[1], data[2], extra_len);
2901 
2902  if (p_frame->buffer_size)
2903  {
2904  p_frame->buffer_size = 0; //notify p_frame->p_buffer is not allocated
2905  ni_aligned_free(p_frame->p_buffer); // also free the temp p_buffer allocated for niFrameSurface1_t in encoder init stage
2906  }
2907 
2908  p_frame->p_buffer = (uint8_t *)data[0];
2909  p_frame->p_data[0] = (uint8_t *)data[0];
2910  p_frame->p_data[1] = (uint8_t *)data[1];
2911  p_frame->p_data[2] = (uint8_t *)data[2];
2912 
2913  int luma_size = linesize[0] * video_height;
2914  int chroma_b_size = 0;
2915  int chroma_r_size = 0;
2916 
2917  // gstreamer assigns stride length to linesize[0] linesize[1] linesize[2] for RGBA pixel format, but only data[0] pointer is populated
2918  if (data[1]) // cb size is 0 for RGBA pixel format
2919  chroma_b_size = linesize[1] * (video_height / 2);
2920 
2921  if (data[2]) // cr size is 0 for semi-planar or RGBA pixel format
2922  chroma_r_size = linesize[2] * (video_height / 2);
2923 
2924  //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);
2925 
2926  uint32_t start_offset;
2927  uint32_t total_start_len = 0;
2928  int i;
2929 
2930  p_frame->inconsecutive_transfer = 0;
2931 
2932  // rgba has one data pointer, semi-planar has two data pointers
2933  if ((data[1] && (data[0] + luma_size != data[1]))
2934  || (data[2] && (data[1] + chroma_b_size != data[2])))
2935  {
2936  p_frame->inconsecutive_transfer = 1;
2937  }
2938 
2939  if (p_frame->inconsecutive_transfer)
2940  {
2941  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
2942  {
2943  start_offset = (uintptr_t)p_frame->p_data[i] % NI_MEM_PAGE_ALIGNMENT;
2944  p_frame->start_len[i] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
2945  total_start_len += p_frame->start_len[i];
2946  }
2947  }
2948  else
2949  {
2950  start_offset = (uintptr_t)p_frame->p_data[0] % NI_MEM_PAGE_ALIGNMENT;
2951  p_frame->start_len[0] = start_offset ? (NI_MEM_PAGE_ALIGNMENT - start_offset) : 0;
2952  p_frame->start_len[1] = p_frame->start_len[2] = 0;
2953  total_start_len = p_frame->start_len[0];
2954  }
2955  p_frame->total_start_len = total_start_len;
2956 
2957  if (ni_encoder_metadata_buffer_alloc(p_frame, extra_len))
2958  {
2959  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_metadata_buffer buffer.\n",
2960  NI_ERRNO, __func__);
2961  retval = NI_RETCODE_ERROR_MEM_ALOC;
2962  LRETURN;
2963  }
2964  p_frame->separate_metadata = 1;
2965 
2966  if (total_start_len)
2967  {
2968  if (ni_encoder_start_buffer_alloc(p_frame))
2969  {
2970  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_start_buffer buffer.\n",
2971  NI_ERRNO, __func__);
2972  retval = NI_RETCODE_ERROR_MEM_ALOC;
2973  LRETURN;
2974  }
2975  p_frame->separate_start = 1;
2976 
2977  // copy non-4k-aligned part at the start of YUV data
2978  int start_buffer_offset = 0;
2979  for (i = 0; i < NI_MAX_NUM_SW_FRAME_DATA_POINTERS; i++)
2980  {
2981  if (p_frame->p_data[i])
2982  {
2983  memcpy(p_frame->p_start_buffer+start_buffer_offset, p_frame->p_data[i],
2984  p_frame->start_len[i]);
2985  start_buffer_offset += p_frame->start_len[i];
2986  }
2987  }
2988  }
2989 
2990  p_frame->data_len[0] = luma_size;
2991  p_frame->data_len[1] = chroma_b_size;
2992  p_frame->data_len[2] = chroma_r_size;
2993  p_frame->data_len[3] = 0;//unused by hwdesc
2994 
2995  p_frame->video_width = video_width;
2996  p_frame->video_height = video_height;
2997 
2999  "%s: success: p_metadata_buffer %p metadata_buffer_size %u "
3000  "p_start_buffer %p start_buffer_size %u data_len %u %u %u\n",
3001  __func__, p_frame->p_metadata_buffer, p_frame->metadata_buffer_size,
3002  p_frame->p_start_buffer, p_frame->start_buffer_size,
3003  p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2]);
3004 
3005 END:
3006 
3007  return retval;
3008 }
3009 
3010 
3011 /*!*****************************************************************************
3012  * \brief Check if incoming frame is hwupload zero copy compatible or not
3013  *
3014  * \param[in] p_upl_ctx pointer to uploader context
3015  * [in] width input width
3016  * [in] height input height
3017  * [in] linesize input linesizes (pointer to array)
3018  * [in] pixel_format input pixel format
3019  *
3020  * \return on success and can do zero copy
3021  * NI_RETCODE_SUCCESS
3022  *
3023  * cannot do zero copy
3024  * NI_RETCODE_ERROR_UNSUPPORTED_FEATURE
3025  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
3026  * NI_RETCODE_INVALID_PARAM
3027  *
3028 *******************************************************************************/
3030  int width, int height,
3031  const int linesize[], int pixel_format)
3032 {
3033  // check pixel format / width / height / linesize can be supported
3034  if ((!p_upl_ctx) || (!linesize)
3035  || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3036  || (width>NI_MAX_RESOLUTION_WIDTH) || (width<=0)
3037  || (height>NI_MAX_RESOLUTION_HEIGHT) || (height<=0))
3038  {
3039  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s passed parameters are null or not supported, "
3040  "p_enc_ctx %p, linesize %p, "
3041  "width %d, height %d linesize[0] %d\n",
3042  __func__, p_upl_ctx, linesize,
3043  width, height, (linesize) ? linesize[0] : 0);
3044  return NI_RETCODE_INVALID_PARAM;
3045  }
3046 
3047  // check fw revision (if fw_rev has been populated in open session)
3048  if (p_upl_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX] &&
3050  "6S") < 0))
3051  {
3052  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: not supported on device with FW API version < 6.S\n", __func__);
3054  }
3055 
3056  // upload does not have zeroCopyMode parameter, currently only allows resolution >= 1080p
3057  if ((width * height) < NI_NUM_OF_PIXELS_1080P)
3059 
3060  // check zero copy compatibilty
3061  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s pixel_format %d "
3062  "p_upl_ctx %p, linesize %p, "
3063  "width %d, height %d, linesize[0] %d\n",
3064  __func__, pixel_format, p_upl_ctx, linesize,
3065  width, height, linesize[0]);
3066 
3067  int bit_depth_factor;
3068  bool isrgba = false;
3069  bool isplanar = false;
3070  bool issemiplanar = false;
3071 
3072  switch (pixel_format)
3073  {
3074  case NI_PIX_FMT_YUV420P:
3075  isplanar = true;
3076  bit_depth_factor = 1;
3077  break;
3079  isplanar = true;
3080  bit_depth_factor = 2;
3081  break;
3082  case NI_PIX_FMT_NV12:
3083  issemiplanar = true;
3084  bit_depth_factor = 1;
3085  break;
3086  case NI_PIX_FMT_P010LE:
3087  issemiplanar = true;
3088  bit_depth_factor = 2;
3089  break;
3090  case NI_PIX_FMT_ABGR:
3091  case NI_PIX_FMT_ARGB:
3092  case NI_PIX_FMT_RGBA:
3093  case NI_PIX_FMT_BGRA:
3094  isrgba = true;
3095  bit_depth_factor = 4; // not accurate, only for linesize check
3096  break;
3097  default:
3098  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: pixel_format %d not supported\n", __func__);
3100  }
3101 
3102  // check fw revision (if fw_rev has been populated in open session)
3103  if (issemiplanar &&
3106  "6q") < 0))
3107  {
3108  ni_log2(p_upl_ctx, NI_LOG_DEBUG, "%s: semi-planar not supported on device with FW API version < 6.q\n", __func__);
3110  }
3111 
3112  int max_linesize = isrgba ? (NI_MAX_RESOLUTION_RGBA_WIDTH*4) : NI_MAX_RESOLUTION_LINESIZE;
3113  if (linesize[0] <= max_linesize &&
3114  width % 2 == 0 && //even width
3115  height % 2 == 0 && //even height
3116  width >= NI_MIN_WIDTH && height >= NI_MIN_HEIGHT)
3117  {
3118  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3119  if (isplanar &&
3120  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3121  linesize[1] == NI_VPU_ALIGN128(width * bit_depth_factor / 2) &&
3122  linesize[2] == linesize[1])
3123  return NI_RETCODE_SUCCESS;
3124 
3125  // yuv only support default 128 bytes aligned linesize, because downstream filter or encoder expect HW frame 128 bytes aligned
3126  if (issemiplanar &&
3127  linesize[0] == NI_VPU_ALIGN128(width * bit_depth_factor) &&
3128  linesize[1] == linesize[0])
3129  return NI_RETCODE_SUCCESS;
3130 
3131  // rgba only support 64 bytes aligned for 2D
3132  if (isrgba &&
3133  linesize[0] == NI_VPU_ALIGN64(width * bit_depth_factor))
3134  return NI_RETCODE_SUCCESS;
3135  }
3136 
3138 }
3139 
3140 /*!*****************************************************************************
3141  * \brief Allocate memory for the frame buffer for encoding based on given
3142  * parameters, taking into account pic line size and extra data.
3143  * Applicable to YUV420p AVFrame only. 8 or 10 bit/pixel.
3144  * Cb/Cr size matches that of Y.
3145  *
3146  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3147  *
3148  * \param[in] video_width Width of the video frame
3149  * \param[in] video_height Height of the video frame
3150  * \param[in] linesize Picture line size
3151  * \param[in] alignment Allignment requirement
3152  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3153  * to allocate any buffer (zero-copy from existing)
3154  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3155  *
3156  * \return On success
3157  * NI_RETCODE_SUCCESS
3158  * On failure
3159  * NI_RETCODE_INVALID_PARAM
3160  * NI_RETCODE_ERROR_MEM_ALOC
3161  *****************************************************************************/
3163  int video_height, int linesize[],
3164  int alignment, int extra_len,
3165  bool alignment_2pass_wa)
3166 {
3167  void* p_buffer = NULL;
3168  int height_aligned;
3169  int retval = NI_RETCODE_SUCCESS;
3170 
3171  if ((!p_frame) || (!linesize) || (linesize[0]<=0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3172  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width<=0)
3173  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height<=0))
3174  {
3175  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3176  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3177  __func__, p_frame, linesize, video_width, video_height);
3178  return NI_RETCODE_INVALID_PARAM;
3179  }
3180 
3181  if (QUADRA)
3182  {
3183  height_aligned = ((video_height + 1) / 2) * 2;
3184  } else
3185  {
3186  height_aligned = ((video_height + 7) / 8) * 8;
3187 
3188  if (alignment)
3189  {
3190  height_aligned = ((video_height + 15) / 16) * 16;
3191  }
3192  }
3193  if (height_aligned < NI_MIN_HEIGHT)
3194  {
3195  height_aligned = NI_MIN_HEIGHT;
3196  }
3197 
3199  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d "
3200  "extra_len=%d\n",
3201  __func__, video_width, height_aligned, video_width, video_height,
3202  linesize[0], linesize[1], linesize[2], extra_len);
3203 
3204  int luma_size = linesize[0] * height_aligned;
3205  int chroma_b_size;
3206  int chroma_r_size;
3207  if (QUADRA)
3208  {
3209  chroma_b_size = chroma_r_size = linesize[1] * (height_aligned / 2);
3210  if (alignment_2pass_wa)
3211  {
3212  // for 2-pass encode output mismatch WA, need to extend (and pad) Cr plane height, because 1st pass assume input 32 align
3213  chroma_r_size = linesize[1] * (((height_aligned + 31) / 32) * 32) / 2;
3214  }
3215  //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);
3216  }
3217  else
3218  {
3219  chroma_b_size = luma_size / 4;
3220  chroma_r_size = luma_size / 4;
3221  }
3222  if(extra_len >= 0)
3223  {
3224  int buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
3225 
3226  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3227 
3228  //Check if Need to free
3229  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3230  {
3232  "%s: free current p_frame, "
3233  "p_frame->buffer_size=%u\n",
3234  __func__, p_frame->buffer_size);
3235  ni_frame_buffer_free(p_frame);
3236  }
3237 
3238  //Check if need to realocate
3239  if (p_frame->buffer_size != buffer_size)
3240  {
3241  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3242  {
3243  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3244  NI_ERRNO, __func__);
3245  retval = NI_RETCODE_ERROR_MEM_ALOC;
3246  LRETURN;
3247  }
3248 
3249  // init once after allocation
3250  memset(p_buffer, 0, buffer_size);
3251  p_frame->buffer_size = buffer_size;
3252  p_frame->p_buffer = p_buffer;
3253 
3254  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3255  }
3256  else
3257  {
3258  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3259  }
3260  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3261  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3262  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_b_size;
3263  }
3264  else
3265  {
3266  p_frame->buffer_size = 0; //no ownership
3267  }
3268 
3269  p_frame->data_len[0] = luma_size;
3270  p_frame->data_len[1] = chroma_b_size;
3271  p_frame->data_len[2] = chroma_r_size;
3272  p_frame->data_len[3] = 0;//unused by hwdesc
3273 
3274  p_frame->video_width = video_width;
3275  p_frame->video_height = height_aligned;
3276 
3278  "%s: success: p_frame->p_buffer %p "
3279  "p_frame->buffer_size=%u\n",
3280  __func__, p_frame->p_buffer, p_frame->buffer_size);
3281 
3282 END:
3283 
3284  if (NI_RETCODE_SUCCESS != retval)
3285  {
3286  ni_aligned_free(p_buffer);
3287  }
3288 
3289  return retval;
3290 }
3291 
3292 /*!*****************************************************************************
3293  * \brief allocate device destination frame from scaler hwframe pool
3294  *
3295  * \param
3296  *
3297  * \return 0 if successful, < 0 otherwise
3298  ******************************************************************************/
3300  ni_scaler_input_params_t scaler_params,
3301  niFrameSurface1_t *p_surface)
3302 {
3303  int ret = 0;
3304  if (scaler_params.op != NI_SCALER_OPCODE_OVERLAY && scaler_params.op != NI_SCALER_OPCODE_WATERMARK)
3305  {
3306  ret = ni_device_alloc_frame(
3307  p_ctx, scaler_params.output_width, scaler_params.output_height,
3308  scaler_params.output_format, NI_SCALER_FLAG_IO,
3309  scaler_params.out_rec_width, scaler_params.out_rec_height,
3310  scaler_params.out_rec_x, scaler_params.out_rec_y,
3311  scaler_params.rgba_color, -1, NI_DEVICE_TYPE_SCALER);
3312  } else
3313  {
3314  // in vf_overlay_ni.c: flags = (s->alpha_format ? NI_SCALER_FLAG_PA : 0) | NI_SCALER_FLAG_IO;
3315  ret = ni_device_alloc_frame(
3316  p_ctx, scaler_params.output_width, scaler_params.output_height,
3317  scaler_params.output_format, NI_SCALER_FLAG_IO,
3318  scaler_params.out_rec_width, scaler_params.out_rec_height,
3319  scaler_params.out_rec_x, scaler_params.out_rec_y,
3320  p_surface->ui32nodeAddress, p_surface->ui16FrameIdx,
3322  }
3323  return ret;
3324 }
3325 
3326 /*!*****************************************************************************
3327  * \brief allocate device input frame by hw descriptor. This call won't actually allocate
3328  a frame but sends the incoming hardware frame index to the scaler manager
3329  *
3330  * \param
3331  *
3332  * \return 0 if successful, < 0 otherwise
3333  ******************************************************************************/
3335  ni_scaler_input_params_t scaler_params,
3336  niFrameSurface1_t *p_src_surface)
3337 {
3338  int ret = 0;
3339 
3340  ret = ni_device_alloc_frame(
3341  p_ctx, scaler_params.input_width, scaler_params.input_height,
3342  scaler_params.input_format, 0, scaler_params.in_rec_width,
3343  scaler_params.in_rec_height, scaler_params.in_rec_x,
3344  scaler_params.in_rec_y, p_src_surface->ui32nodeAddress,
3345  p_src_surface->ui16FrameIdx, NI_DEVICE_TYPE_SCALER);
3346  return ret;
3347 }
3348 
3349 /*!*****************************************************************************
3350  * \brief init output pool of scaler frames
3351  *
3352  * \param
3353  *
3354  * \return 0 if successful, < 0 otherwise
3355  ******************************************************************************/
3357  ni_scaler_input_params_t scaler_params)
3358 {
3359  int rc = 0;
3360  int options = NI_SCALER_FLAG_IO | NI_SCALER_FLAG_PC;
3361  if (p_ctx->isP2P)
3362  options |= NI_SCALER_FLAG_P2;
3363 
3364  /* Allocate a pool of frames by the scaler */
3365  rc = ni_device_alloc_frame(p_ctx, scaler_params.output_width,
3366  scaler_params.output_height,
3367  scaler_params.output_format, options,
3368  0, // rec width
3369  0, // rec height
3370  0, // rec X pos
3371  0, // rec Y pos
3372  NI_MAX_FILTER_POOL_SIZE, // rgba color/pool size
3373  0, // frame index
3375  return rc;
3376 }
3377 
3378 /*!*****************************************************************************
3379 * \brief Allocate memory for the frame buffer based on provided parameters
3380 * taking into account pic line size and extra data.
3381 * Applicable to nv12 AVFrame only. Cb/Cr size matches that of Y.
3382 *
3383 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3384 *
3385 * \param[in] video_width Width of the video frame
3386 * \param[in] video_height Height of the video frame
3387 * \param[in] linesize Picture line size
3388 * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3389 * to allocate any buffer (zero-copy from existing)
3390 * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3391 *
3392 * \return On success
3393 * NI_RETCODE_SUCCESS
3394 * On failure
3395 * NI_RETCODE_INVALID_PARAM
3396 * NI_RETCODE_ERROR_MEM_ALOC
3397 *****************************************************************************/
3399  int video_height, int linesize[],
3400  int extra_len, bool alignment_2pass_wa)
3401 {
3402  void* p_buffer = NULL;
3403  int height_aligned;
3404  int retval = NI_RETCODE_SUCCESS;
3405 
3406  if ((!p_frame) || (!linesize) || (linesize[0] <= 0) || (linesize[0]>NI_MAX_RESOLUTION_LINESIZE)
3407  || (video_width>NI_MAX_RESOLUTION_WIDTH) || (video_width <= 0)
3408  || (video_height>NI_MAX_RESOLUTION_HEIGHT) || (video_height <= 0))
3409  {
3410  ni_log(NI_LOG_ERROR, "ERROR: %s passed parameters are null or not supported, "
3411  "p_frame %p, linesize %p, video_width %d, video_height %d\n",
3412  __func__, p_frame, linesize, video_width, video_height);
3413  return NI_RETCODE_INVALID_PARAM;
3414  }
3415 
3416  height_aligned = ((video_height + 1) / 2) * 2;
3417 
3418  if (height_aligned < NI_MIN_HEIGHT)
3419  {
3420  height_aligned = NI_MIN_HEIGHT;
3421  }
3422 
3424  "%s: aligned=%dx%d org=%dx%d linesize=%d/%d/%d extra_len=%d\n",
3425  __func__, video_width, height_aligned, video_width, video_height,
3426  linesize[0], linesize[1], linesize[2], extra_len);
3427 
3428  int luma_size = linesize[0] * height_aligned;
3429  int chroma_br_size = luma_size / 2;
3430  //int chroma_r_size = luma_size / 4;
3431  if (alignment_2pass_wa)
3432  {
3433  // for 2-pass encode output mismatch WA, need to extend (and pad) CbCr plane height, because 1st pass assume input 32 align
3434  chroma_br_size = linesize[0] * ((((height_aligned + 31) / 32) * 32) / 2);
3435  }
3436  if (extra_len >= 0)
3437  {
3438  int buffer_size = luma_size + chroma_br_size + extra_len;
3439 
3440  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
3441 
3442  //Check if Need to free
3443  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
3444  {
3445  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
3446  __func__, p_frame->buffer_size);
3447  ni_frame_buffer_free(p_frame);
3448  }
3449 
3450  //Check if need to realocate
3451  if (p_frame->buffer_size != buffer_size)
3452  {
3453  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3454  {
3455  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
3456  NI_ERRNO, __func__);
3457  retval = NI_RETCODE_ERROR_MEM_ALOC;
3458  LRETURN;
3459  }
3460 
3461  // init once after allocation
3462  memset(p_buffer, 0, buffer_size);
3463  p_frame->buffer_size = buffer_size;
3464  p_frame->p_buffer = p_buffer;
3465 
3466  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
3467  }
3468  else
3469  {
3470  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
3471  }
3472 
3473  p_frame->p_data[0] = (uint8_t*)p_frame->p_buffer;
3474  p_frame->p_data[1] = (uint8_t*)p_frame->p_data[0] + luma_size;
3475  p_frame->p_data[2] = (uint8_t*)p_frame->p_data[1] + chroma_br_size;
3476  }
3477  else
3478  {
3479  p_frame->buffer_size = 0; //no ownership
3480  }
3481  p_frame->data_len[0] = luma_size;
3482  p_frame->data_len[1] = chroma_br_size;
3483  p_frame->data_len[2] = 0;
3484 
3485  p_frame->video_width = video_width;
3486  p_frame->video_height = height_aligned;
3487 
3488  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
3489  p_frame->buffer_size);
3490 
3491 END:
3492 
3493  if (NI_RETCODE_SUCCESS != retval)
3494  {
3495  ni_aligned_free(p_buffer);
3496  }
3497 
3498  return retval;
3499 }
3500 
3501 /*!*****************************************************************************
3502  * \brief This API is a wrapper for ni_encoder_frame_buffer_alloc(), used
3503  * for planar pixel formats, and ni_frame_buffer_alloc_nv(), used for
3504  * semi-planar pixel formats. This API is meant to combine the
3505  * functionality for both individual format APIs.
3506  * Allocate memory for the frame buffer for encoding based on given
3507  * parameters, taking into account pic line size and extra data.
3508  * Applicable to YUV420p(8 or 10 bit/pixel) or nv12 AVFrame.
3509  * Cb/Cr size matches that of Y.
3510  *
3511  * \param[in] planar true: if planar:
3512  * pixel_format == (NI_PIX_FMT_YUV420P ||
3513  * NI_PIX_FMT_YUV420P10LE ||NI_PIX_FMT_RGBA).
3514  * false: semi-planar:
3515  * pixel_format == (NI_PIX_FMT_NV12 ||
3516  * NI_PIX_FMT_P010LE).
3517  * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
3518  * \param[in] video_width Width of the video frame
3519  * \param[in] video_height Height of the video frame
3520  * \param[in] linesize Picture line size
3521  * \param[in] alignment Allignment requirement. Only used for planar format.
3522  * \param[in] extra_len Extra data size (incl. meta data). < 0 means not
3523  * to allocate any buffer (zero-copy from existing)
3524  * \param[in] alignment_2pass_wa set alignment to work with 2pass encode
3525  *
3526  * \return On success
3527  * NI_RETCODE_SUCCESS
3528  * On failure
3529  * NI_RETCODE_INVALID_PARAM
3530  * NI_RETCODE_ERROR_MEM_ALOC
3531  *****************************************************************************/
3533  int video_width, int video_height,
3534  int linesize[], int alignment,
3535  int extra_len,
3536  bool alignment_2pass_wa)
3537 {
3538  if (true == planar)
3539  {
3540  return ni_encoder_frame_buffer_alloc(p_frame, video_width, video_height,
3541  linesize, alignment, extra_len,
3542  alignment_2pass_wa);
3543  }
3544  else
3545  {
3546  return ni_frame_buffer_alloc_nv(p_frame, video_width, video_height,
3547  linesize, extra_len,
3548  alignment_2pass_wa);
3549  }
3550 }
3551 
3552 /*!*****************************************************************************
3553  * \brief Free frame buffer that was previously allocated with either
3554  * ni_frame_buffer_alloc or ni_encoder_frame_buffer_alloc or
3555  * ni_frame_buffer_alloc_nv
3556  *
3557  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3558  *
3559  * \return On success NI_RETCODE_SUCCESS
3560  * On failure NI_RETCODE_INVALID_PARAM
3561  ******************************************************************************/
3563 {
3564  int i;
3566 
3567  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3568 
3569  if (!p_frame)
3570  {
3571  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3572  LRETURN;
3573  }
3574 
3575  if (!p_frame->p_buffer)
3576  {
3577  ni_log(NI_LOG_DEBUG, "WARN: %s(): already freed, nothing to free\n",
3578  __func__);
3579  }
3580 
3581 #ifndef _WIN32
3582  // If this is a hardware frame with a DMA buf fd attached, close the DMA buf fd
3583  if ((p_frame->data_len[3] > 0) && (p_frame->p_data[3] != NULL))
3584  {
3585  niFrameSurface1_t *p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
3586  if ((p_surface->dma_buf_fd > 0) && (p_surface->ui16FrameIdx > 0))
3587  {
3588  // Close the DMA buf fd
3590  "%s: close p_surface->dma_buf_fd %d "
3591  "ui16FrameIdx %u\n",
3592  __func__, p_surface->dma_buf_fd, p_surface->ui16FrameIdx);
3593  close(p_surface->dma_buf_fd);
3594  }
3595  }
3596 #endif
3597 
3598  if (p_frame->buffer_size)
3599  {
3600  p_frame->buffer_size = 0;
3601  ni_aligned_free(p_frame->p_buffer);
3602  }
3603 
3604  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3605  {
3606  p_frame->data_len[i] = 0;
3607  p_frame->p_data[i] = NULL;
3608  }
3609 
3610  ni_frame_wipe_aux_data(p_frame);
3611 
3612  if (p_frame->metadata_buffer_size)
3613  {
3614  p_frame->metadata_buffer_size = 0;
3616  }
3617  p_frame->separate_metadata = 0;
3618 
3619  if (p_frame->start_buffer_size)
3620  {
3621  p_frame->start_buffer_size = 0;
3622  ni_aligned_free(p_frame->p_start_buffer);
3623  }
3624  p_frame->separate_start = 0;
3625  memset(p_frame->start_len, 0, sizeof(p_frame->start_len));
3626  p_frame->total_start_len = 0;
3627  p_frame->inconsecutive_transfer = 0;
3628 
3629 END:
3630 
3631  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3632 
3633  return retval;
3634 }
3635 
3636 /*!*****************************************************************************
3637  * \brief Free decoder frame buffer that was previously allocated with
3638  * ni_decoder_frame_buffer_alloc, returning memory to a buffer pool.
3639  *
3640  * \param[in] p_frame Pointer to a previously allocated ni_frame_t struct
3641  *
3642  * \return On success NI_RETCODE_SUCCESS
3643  * On failure NI_RETCODE_INVALID_PARAM
3644  ******************************************************************************/
3646 {
3647  int i;
3649 
3650  ni_log(NI_LOG_TRACE, "%s: enter\n", __func__);
3651 
3652  if (!p_frame)
3653  {
3654  ni_log(NI_LOG_DEBUG, "WARN: %s(): p_frame is NULL\n", __func__);
3655  retval = NI_RETCODE_INVALID_PARAM;
3656  LRETURN;
3657  }
3658 
3659  if (p_frame->dec_buf)
3660  {
3662  ni_log(NI_LOG_DEBUG, "%s(): Mem buf returned ptr %p buf %p !\n", __func__,
3663  p_frame->dec_buf->buf, p_frame->dec_buf);
3664  }
3665  else
3666  {
3667  ni_log(NI_LOG_DEBUG, "%s(): NO mem buf returned !\n", __func__);
3668  }
3669 
3670  p_frame->dec_buf = NULL;
3671  p_frame->p_buffer = NULL;
3672  p_frame->buffer_size = 0;
3673  for (i = 0; i < NI_MAX_NUM_DATA_POINTERS; i++)
3674  {
3675  p_frame->data_len[i] = 0;
3676  p_frame->p_data[i] = NULL;
3677  }
3678  ni_frame_wipe_aux_data(p_frame);
3679 
3680 END:
3681 
3682  ni_log(NI_LOG_TRACE, "%s: exit\n", __func__);
3683 
3684  return retval;
3685 }
3686 
3687 /*!*****************************************************************************
3688  * \brief Return a memory buffer to memory buffer pool.
3689  *
3690  * \param[in] buf Buffer to be returned.
3691  * \param[in] p_buffer_pool Buffer pool to return buffer to.
3692  *
3693  * \return None
3694  ******************************************************************************/
3696  ni_buf_pool_t *p_buffer_pool)
3697 {
3698  ni_buf_pool_return_buffer(buf, p_buffer_pool);
3699 }
3700 
3701 /*!*****************************************************************************
3702  * \brief Allocate memory for the packet buffer based on provided packet size
3703  *
3704  * \param[in] p_packet Pointer to a caller allocated
3705  * ni_packet_t struct
3706  * \param[in] packet_size Required allocation size
3707  *
3708  * \return On success
3709  * NI_RETCODE_SUCCESS
3710  * On failure
3711  * NI_RETCODE_INVALID_PARAM
3712  * NI_RETCODE_ERROR_MEM_ALOC
3713  ******************************************************************************/
3715 {
3716  void* p_buffer = NULL;
3717  int metadata_size = 0;
3718 
3719  metadata_size = NI_FW_META_DATA_SZ;
3720 
3721  int buffer_size = (((packet_size + metadata_size) / NI_MAX_PACKET_SZ) + 1) * NI_MAX_PACKET_SZ;
3722 
3723  ni_log(NI_LOG_TRACE, "%s: packet_size=%d\n", __func__,
3724  packet_size + metadata_size);
3725 
3726  if (!p_packet || !packet_size)
3727  {
3728  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3729  __func__);
3730  return NI_RETCODE_INVALID_PARAM;
3731  }
3732 
3733  if (buffer_size % NI_MEM_PAGE_ALIGNMENT)
3734  {
3735  buffer_size = ( (buffer_size / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT ) + NI_MEM_PAGE_ALIGNMENT;
3736  }
3737 
3738  if (p_packet->buffer_size == buffer_size)
3739  {
3740  // Already allocated the exact size.
3741  p_packet->p_data = p_packet->p_buffer;
3742  ni_log(NI_LOG_DEBUG, "%s: reuse current p_packet buffer\n", __func__);
3743  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3744  p_packet->buffer_size);
3745  return NI_RETCODE_SUCCESS;
3746  }
3747 
3748  if (p_packet->buffer_size)
3749  {
3751  "%s: free current p_packet, p_packet->buffer_size=%u\n", __func__,
3752  p_packet->buffer_size);
3753  ni_packet_buffer_free(p_packet);
3754  }
3755 
3756  ni_log(NI_LOG_DEBUG, "%s: Allocating p_frame buffer, buffer_size=%d\n",
3757  __func__, buffer_size);
3758 
3759  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
3760  {
3761  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
3762  NI_ERRNO, __func__);
3763  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3764  p_packet->buffer_size);
3766  }
3767 
3768  p_packet->buffer_size = buffer_size;
3769  p_packet->p_buffer = p_buffer;
3770  p_packet->p_data = p_packet->p_buffer;
3771 
3772  ni_log(NI_LOG_TRACE, "%s: exit: p_packet->buffer_size=%u\n", __func__,
3773  p_packet->buffer_size);
3774 
3775  return NI_RETCODE_SUCCESS;
3776 }
3777 
3778 /*!*****************************************************************************
3779  * \brief Allocate packet buffer using a user provided pointer, the memory
3780  * is expected to have already been allocated.
3781  *
3782  * For ideal performance memory should be 4k aligned. If it is not 4K aligned
3783  * then a temporary 4k aligned memory will be used to copy data to and from
3784  * when writing and reading. This will negatively impact performance.
3785  *
3786  * This API will overwrite p_packet->buffer_size, p_packet->p_buffer and
3787  * p_packet->p_data fields in p_packet.
3788  *
3789  * This API will not free any memory associated with p_packet->p_buffer and
3790  * p_packet->p_data fields in p_packet.
3791  * Common use case could be,
3792  * 1. Allocate memory to pointer
3793  * 2. Call ni_custom_packet_buffer_alloc() with allocated pointer.
3794  * 3. Use p_packet as required.
3795  * 4. Call ni_packet_buffer_free() to free up the memory.
3796  *
3797  * \param[in] p_buffer User provided pointer to be used for buffer
3798  * \param[in] p_packet Pointer to a caller allocated
3799  * ni_packet_t struct
3800  * \param[in] buffer_size Buffer size
3801  *
3802  * \return On success
3803  * NI_RETCODE_SUCCESS
3804  * On failure
3805  * NI_RETCODE_INVALID_PARAM
3806  * NI_RETCODE_ERROR_MEM_ALOC
3807  ******************************************************************************/
3809  ni_packet_t *p_packet,
3810  int buffer_size)
3811 {
3812  ni_log(NI_LOG_TRACE, "%s(): enter buffer_size=%d\n", __func__, buffer_size);
3813 
3814  if (!p_buffer || !p_packet || !buffer_size)
3815  {
3816  ni_log(NI_LOG_ERROR, "ERROR: %s: null pointer parameters passed\n",
3817  __func__);
3818  return NI_RETCODE_INVALID_PARAM;
3819  }
3820  if (((uintptr_t)p_buffer) % NI_MEM_PAGE_ALIGNMENT)
3821  {
3822  ni_log(NI_LOG_INFO, "Info: %s: Warning buffer not 4k aligned = %p!. Will do an extra copy\n",
3823  __func__, p_buffer);
3824  }
3825 
3826  p_packet->buffer_size = buffer_size;
3827  p_packet->p_buffer = p_buffer;
3828  p_packet->p_data = p_packet->p_buffer;
3829 
3830  ni_log(NI_LOG_TRACE, "%s: exit: \n", __func__);
3831 
3832  return NI_RETCODE_SUCCESS;
3833 }
3834 
3835 /*!*****************************************************************************
3836  * \brief Free packet buffer that was previously allocated with
3837  * ni_packet_buffer_alloc
3838  *
3839  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
3840  *
3841  * \return On success NI_RETCODE_SUCCESS
3842  * On failure NI_RETCODE_INVALID_PARAM
3843  ******************************************************************************/
3845 {
3847 
3848  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
3849 
3850  if (!p_packet)
3851  {
3852  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
3853  retval = NI_RETCODE_FAILURE;
3854  LRETURN;
3855  }
3856 
3857  if (!p_packet->p_buffer)
3858  {
3859  ni_log(NI_LOG_DEBUG, "%s(): already freed, nothing to free\n", __func__);
3860  LRETURN;
3861  }
3862 
3863  ni_aligned_free(p_packet->p_buffer);
3864  p_packet->p_buffer = NULL;
3865  p_packet->buffer_size = 0;
3866  p_packet->data_len = 0;
3867  p_packet->p_data = NULL;
3868 
3869  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
3870 
3871 END:
3872 
3873  return retval;
3874 }
3875 
3876 /*!*****************************************************************************
3877  * \brief Free packet buffer that was previously allocated with
3878  * ni_packet_buffer_alloc for AV1 packets merge
3879  *
3880  * \param[in] p_packet Pointer to a previously allocated ni_packet_t struct
3881  *
3882  * \return On success NI_RETCODE_SUCCESS
3883  * On failure NI_RETCODE_INVALID_PARAM
3884  ******************************************************************************/
3886 {
3887  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
3889  int i;
3890 
3891  if (!p_packet)
3892  {
3893  ni_log(NI_LOG_ERROR, "ERROR: %s(): p_packet is NULL\n", __func__);
3894  retval = NI_RETCODE_FAILURE;
3895  LRETURN;
3896  }
3897 
3898  if (!p_packet->av1_buffer_index)
3899  {
3901  "%s(): no need to free previous av1 packet buffers\n", __func__);
3902  LRETURN;
3903  }
3904 
3905  for (i = 0; i < p_packet->av1_buffer_index; i++)
3906  {
3907  ni_log(NI_LOG_DEBUG, "%s(): free previous av1 packet buffer %d\n",
3908  __func__, i);
3909  ni_aligned_free(p_packet->av1_p_buffer[i]);
3910  p_packet->av1_p_buffer[i] = NULL;
3911  p_packet->av1_p_data[i] = NULL;
3912  p_packet->av1_buffer_size[i] = 0;
3913  p_packet->av1_data_len[i] = 0;
3914  }
3915 
3916  p_packet->av1_buffer_index = 0;
3917 
3918 END:
3919 
3920  ni_log(NI_LOG_TRACE, "%s(): exit\n", __func__);
3921 
3922  return retval;
3923 }
3924 
3925 /*!*****************************************************************************
3926  * \brief Copy video packet accounting for alignment
3927  *
3928  * \param[in] p_destination Destination to where to copy to
3929  * \param[in] p_source Source from where to copy from
3930  * \param[in] cur_size current size
3931  * \param[out] p_leftover Pointer to the data that was left over
3932  * \param[out] p_prev_size Size of the data leftover ??
3933  *
3934  * \return On success Total number of bytes that were copied
3935  * On failure NI_RETCODE_FAILURE
3936  ******************************************************************************/
3937 int ni_packet_copy(void* p_destination, const void* const p_source, int cur_size, void* p_leftover, int* p_prev_size)
3938 {
3939  int copy_size = 0;
3940  int padding_size = 0;
3941  int prev_size = p_prev_size == NULL? 0 : *p_prev_size;
3942 
3943  int total_size = cur_size + prev_size;
3944  uint8_t* p_src = (uint8_t*)p_source;
3945  uint8_t* p_dst = (uint8_t*)p_destination;
3946  uint8_t* p_lftover = (uint8_t*)p_leftover;
3947 
3948  if (!p_prev_size)
3949  {
3950  return NI_RETCODE_INVALID_PARAM;
3951  }
3952 
3953  ni_log(NI_LOG_TRACE, "%s(): enter, *prev_size=%d\n", __func__, *p_prev_size);
3954 
3955  if ((0 == cur_size) && (0 == prev_size))
3956  {
3957  return copy_size;
3958  }
3959 
3960  if (((0 != cur_size) && (!p_source)) || (!p_destination) || (!p_leftover))
3961  {
3962  return NI_RETCODE_FAILURE;
3963  }
3964 
3965  copy_size = ((total_size + NI_MEM_PAGE_ALIGNMENT - 1) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT;
3966 
3967  if (copy_size > total_size)
3968  {
3969  padding_size = copy_size - total_size;
3970  }
3971 
3972  if (prev_size > 0)
3973  {
3974  memcpy(p_dst, p_lftover, prev_size);
3975  }
3976 
3977  p_dst += prev_size;
3978 
3979  memcpy(p_dst, p_src, cur_size);
3980 
3981  if (padding_size)
3982  {
3983  p_dst += cur_size;
3984  memset(p_dst, 0, padding_size);
3985  }
3986 
3988  "%s(): exit, cur_size=%d, copy_size=%d, "
3989  "prev_size=%d, padding_size=%d\n", __func__, cur_size,
3990  copy_size, *p_prev_size, padding_size);
3991 
3992  *p_prev_size = 0;
3993 
3994  return copy_size;
3995 }
3996 
3997 /*!*****************************************************************************
3998  * \brief Add a new auxiliary data to a frame
3999  *
4000  * \param[in/out] frame a frame to which the auxiliary data should be added
4001  * \param[in] type type of the added auxiliary data
4002  * \param[in] data_size size of the added auxiliary data
4003  *
4004  * \return a pointer to the newly added aux data on success, NULL otherwise
4005  ******************************************************************************/
4007  int data_size)
4008 {
4009  ni_aux_data_t *ret;
4010 
4012  !(ret = malloc(sizeof(ni_aux_data_t))))
4013  {
4015  "ERROR: %s No memory or exceeding max aux_data number !\n",
4016  __func__);
4017  return NULL;
4018  }
4019 
4020  ret->type = type;
4021  ret->size = data_size;
4022  ret->data = calloc(1, data_size);
4023  if (!ret->data)
4024  {
4025  ni_log(NI_LOG_ERROR, "ERROR: %s No memory for aux data !\n", __func__);
4026  free(ret);
4027  ret = NULL;
4028  } else
4029  {
4030  frame->aux_data[frame->nb_aux_data++] = ret;
4031  }
4032 
4033  return ret;
4034 }
4035 
4036 /*!*****************************************************************************
4037  * \brief Add a new auxiliary data to a frame and copy in the raw data
4038  *
4039  * \param[in/out] frame a frame to which the auxiliary data should be added
4040  * \param[in] type type of the added auxiliary data
4041  * \param[in] raw_data the raw data of the aux data
4042  * \param[in] data_size size of the added auxiliary data
4043  *
4044  * \return a pointer to the newly added aux data on success, NULL otherwise
4045  ******************************************************************************/
4047  ni_aux_data_type_t type,
4048  const uint8_t *raw_data,
4049  int data_size)
4050 {
4051  ni_aux_data_t *ret = ni_frame_new_aux_data(frame, type, data_size);
4052  if (ret)
4053  {
4054  memcpy(ret->data, raw_data, data_size);
4055  }
4056  return ret;
4057 }
4058 
4059 /*!*****************************************************************************
4060  * \brief Retrieve from the frame auxiliary data of a given type if exists
4061  *
4062  * \param[in] frame a frame from which the auxiliary data should be retrieved
4063  * \param[in] type type of the auxiliary data to be retrieved
4064  *
4065  * \return a pointer to the aux data of a given type on success, NULL otherwise
4066  ******************************************************************************/
4068  ni_aux_data_type_t type)
4069 {
4070  int i;
4071  for (i = 0; i < frame->nb_aux_data; i++)
4072  {
4073  if (frame->aux_data[i]->type == type)
4074  {
4075  return frame->aux_data[i];
4076  }
4077  }
4078  return NULL;
4079 }
4080 
4081 /*!*****************************************************************************
4082  * \brief If auxiliary data of the given type exists in the frame, free it
4083  * and remove it from the frame.
4084  *
4085  * \param[in/out] frame a frame from which the auxiliary data should be removed
4086  * \param[in] type type of the auxiliary data to be removed
4087  *
4088  * \return None
4089  ******************************************************************************/
4091 {
4092  int i;
4093  ni_aux_data_t *aux;
4094 
4095  for (i = 0; i < frame->nb_aux_data; i++)
4096  {
4097  aux = frame->aux_data[i];
4098  if (aux->type == type)
4099  {
4100  frame->aux_data[i] = frame->aux_data[frame->nb_aux_data - 1];
4101  frame->aux_data[frame->nb_aux_data - 1] = NULL;
4102  frame->nb_aux_data--;
4103  free(aux->data);
4104  free(aux);
4105  }
4106  }
4107 }
4108 
4109 /*!*****************************************************************************
4110  * \brief Free and remove all auxiliary data from the frame.
4111  *
4112  * \param[in/out] frame a frame from which the auxiliary data should be removed
4113  *
4114  * \return None
4115  ******************************************************************************/
4117 {
4118  int i;
4119  ni_aux_data_t *aux;
4120 
4121  for (i = 0; i < frame->nb_aux_data; i++)
4122  {
4123  aux = frame->aux_data[i];
4124  free(aux->data);
4125  free(aux);
4126  }
4127  frame->nb_aux_data = 0;
4128 }
4129 
4130 /*!*****************************************************************************
4131  * \brief Initialize default encoder parameters
4132  *
4133  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4134  * to initialize to default parameters
4135  * \param[in] fps_num Frames per second
4136  * \param[in] fps_denom FPS denomination
4137  * \param[in] bit_rate bit rate
4138  * \param[in] width frame width
4139  * \param[in] height frame height
4140  * \param[in] codec_format codec from ni_codec_format_t
4141  *
4142  * \return On success
4143  * NI_RETCODE_SUCCESS
4144  * On failure
4145  * NI_RETCODE_FAILURE
4146  * NI_RETCODE_INVALID_PARAM
4147  ******************************************************************************/
4149  int fps_num, int fps_denom,
4150  long bit_rate, int width,
4151  int height,
4152  ni_codec_format_t codec_format)
4153 {
4154  ni_encoder_cfg_params_t *p_enc = NULL;
4155  int i = 0, j = 0;
4157 
4158  //Initialize p_param structure
4159  if (!p_param)
4160  {
4161  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
4162  __func__);
4163  retval = NI_RETCODE_INVALID_PARAM;
4164  LRETURN;
4165  }
4166 
4167  ni_log(NI_LOG_DEBUG, "%s()\n", __func__);
4168 
4169  //Initialize p_param structure
4170  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4171 
4172  p_enc = &p_param->cfg_enc_params;
4173 
4174  // Rev. B: unified for HEVC/H.264
4175  p_enc->profile = 0;
4176  p_enc->level_idc = 0;
4177  p_enc->high_tier = 0;
4178 
4179  if (QUADRA)
4181  else
4183 
4184  p_enc->use_recommend_enc_params = 0;
4185  p_enc->cu_size_mode = 7;
4186  p_enc->max_num_merge = 2;
4187  p_enc->enable_dynamic_8x8_merge = 1;
4188  p_enc->enable_dynamic_16x16_merge = 1;
4189  p_enc->enable_dynamic_32x32_merge = 1;
4190 
4191  p_enc->rc.trans_rate = 0;
4192 
4193  p_enc->rc.enable_rate_control = 0;
4194  if (QUADRA)
4195  p_enc->rc.enable_cu_level_rate_control = 0;
4196  else
4197  p_enc->rc.enable_cu_level_rate_control = 1;
4198  p_enc->rc.enable_hvs_qp = 0;
4199  p_enc->rc.enable_hvs_qp_scale = 1;
4200  p_enc->rc.hvs_qp_scale = 2;
4201  p_enc->rc.min_qp = 8;
4202  p_enc->rc.max_qp = 51;
4203  p_enc->rc.max_delta_qp = 10;
4204 
4205  // hrd is disabled if vbv_buffer_size=0, hrd is enabled if vbv_buffer_size is [10, 3000]
4206  p_enc->rc.vbv_buffer_size = -1;
4207  p_enc->rc.enable_filler = 0;
4208  p_enc->rc.enable_pic_skip = 0;
4209  p_enc->rc.vbv_max_rate = 0;
4210 
4211  p_enc->roi_enable = 0;
4212 
4214  // feature not supported on JPEG/AV1 - disable by default
4215  if (codec_format == NI_CODEC_FORMAT_JPEG ||
4216  codec_format == NI_CODEC_FORMAT_AV1)
4217  {
4219  }
4220 
4221  p_enc->long_term_ref_enable = 0;
4222  p_enc->long_term_ref_interval = 0;
4223  p_enc->long_term_ref_count = 2;
4224 
4225  p_enc->conf_win_top = 0;
4226  p_enc->conf_win_bottom = 0;
4227  p_enc->conf_win_left = 0;
4228  p_enc->conf_win_right = 0;
4229 
4230  p_enc->intra_period = 120;
4231  p_enc->rc.intra_qp = 22;
4232  p_enc->rc.intra_qp_delta = -2;
4233  if (QUADRA)
4234  p_enc->rc.enable_mb_level_rc = 0;
4235  else
4236  p_enc->rc.enable_mb_level_rc = 1;
4237 
4238  p_enc->decoding_refresh_type = 1;
4239 
4240  p_enc->slice_mode = 0;
4241  p_enc->slice_arg = 0;
4242 
4243  // Rev. B: H.264 only parameters.
4244  p_enc->enable_transform_8x8 = 1;
4245  p_enc->entropy_coding_mode = 1;
4246 
4247  p_enc->intra_mb_refresh_mode = 0;
4248  p_enc->intra_mb_refresh_arg = 0;
4249  p_enc->intra_reset_refresh = 0;
4250 
4252 #ifndef QUADRA
4253  if (!QUADRA)
4254  {
4255  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4256  {
4258  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4259  p_enc->custom_gop_params.pic_param[i].pic_qp = 0;
4260  p_enc->custom_gop_params.pic_param[i].num_ref_pic_L0 = 0;
4261  p_enc->custom_gop_params.pic_param[i].ref_poc_L0 = 0;
4262  p_enc->custom_gop_params.pic_param[i].ref_poc_L1 = 0;
4263  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4264  }
4265  }
4266  else // QUADRA
4267 #endif
4268  {
4269  for (i = 0; i < NI_MAX_GOP_NUM; i++)
4270  {
4271  p_enc->custom_gop_params.pic_param[i].poc_offset = 0;
4272  p_enc->custom_gop_params.pic_param[i].qp_offset = 0;
4274  (float)0.3; // QP Factor range is between 0.3 and 1, higher values mean lower quality and less bits
4275  p_enc->custom_gop_params.pic_param[i].temporal_id = 0;
4278  for (j = 0; j < NI_MAX_REF_PIC; j++)
4279  {
4280  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic = 0;
4281  p_enc->custom_gop_params.pic_param[i].rps[j].ref_pic_used = -1;
4282  }
4283  }
4284  }
4285 
4286  p_param->source_width = width;
4287  p_param->source_height = height;
4288 
4289  p_param->fps_number = fps_num;
4290  p_param->fps_denominator = fps_denom;
4291 
4292  if (p_param->fps_number && p_param->fps_denominator)
4293  {
4294  p_enc->frame_rate = (int)(p_param->fps_number / p_param->fps_denominator);
4295  }
4296  else
4297  {
4298  p_enc->frame_rate = 30;
4299  }
4300 
4301  p_param->bitrate = (int)bit_rate;
4302  p_param->roi_demo_mode = 0;
4303  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4304  p_param->force_pic_qp_demo_mode = 0;
4305  p_param->force_frame_type = 0;
4306  p_param->hdrEnableVUI = 0;
4307  p_param->cacheRoi = 0;
4308  p_param->low_delay_mode = 0;
4309  p_param->padding = 1;
4310  p_param->generate_enc_hdrs = 0;
4311  p_param->use_low_delay_poc_type = 0;
4312  p_param->rootBufId = 0;
4313  p_param->staticMmapThreshold = 0;
4314  p_param->zerocopy_mode = 1;
4315  p_param->luma_linesize = 0;
4316  p_param->chroma_linesize = 0;
4317 
4319 
4320  p_param->dolby_vision_profile = 0;
4321 
4322  // encoder stream header VUI setting
4323  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4324  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4325  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4326  p_param->sar_num = 0; // default SAR numerator 0
4327  p_param->sar_denom = 1; // default SAR denominator 1
4328  p_param->video_full_range_flag = -1;
4329 
4330  p_param->enable2PassGop = 0;
4332  p_param->minFramesDelay = 0;
4333  p_param->interval_of_psnr = 1;
4334  for (i = 0; i < NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL; i++) {
4335  for (j = 0; j < NI_CUSTOMIZE_ROI_QP_NUM; j++) {
4336  // 127 is invalid for delta qp and absolute qp
4337  p_param->customize_roi_qp_map[i][j] = 127;
4338  }
4339  }
4340 
4341  //QUADRA
4342  p_enc->EnableAUD = 0;
4343  p_enc->lookAheadDepth = 0;
4344  p_enc->rdoLevel = (codec_format == NI_CODEC_FORMAT_JPEG) ? 0 : 1;
4345  p_enc->crf = -1;
4346  p_enc->HDR10MaxLight = 0;
4347  p_enc->HDR10AveLight = 0;
4348  p_enc->HDR10CLLEnable = 0;
4349  p_enc->EnableRdoQuant = 0;
4350  p_enc->ctbRcMode = 0;
4351  p_enc->gopSize = 0;
4352  p_enc->gopLowdelay = 0;
4353  p_enc->gdrDuration = 0;
4354  p_enc->hrdEnable = 0;
4355  p_enc->ltrRefInterval = 0;
4356  p_enc->ltrRefQpOffset = 0;
4357  p_enc->ltrFirstGap = 0;
4358  p_enc->ltrNextInterval = 1;
4359  p_enc->multicoreJointMode = 0;
4360  p_enc->qlevel = -1;
4361  p_enc->maxFrameSize = 0;
4362  p_enc->maxFrameSizeRatio = 0;
4363  p_enc->chromaQpOffset = 0;
4364  p_enc->tolCtbRcInter = (float)0.1;
4365  p_enc->tolCtbRcIntra = (float)0.1;
4366  p_enc->bitrateWindow = -255;
4367  p_enc->inLoopDSRatio = 1;
4368  p_enc->blockRCSize = 0;
4369  p_enc->rcQpDeltaRange = 10;
4370  p_enc->ctbRowQpStep = 0;
4371  p_enc->newRcEnable = -1;
4372  p_enc->colorDescPresent = 0;
4373  p_enc->colorPrimaries = 2;
4374  p_enc->colorTrc = 2;
4375  p_enc->colorSpace = 2;
4376  p_enc->aspectRatioWidth = 0;
4377  p_enc->aspectRatioHeight = 1;
4378  p_enc->videoFullRange = 0;
4380  p_enc->enable_ssim = 0;
4381  p_enc->HDR10Enable = 0;
4382  p_enc->HDR10dx0 = 0;
4383  p_enc->HDR10dy0 = 0;
4384  p_enc->HDR10dx1 = 0;
4385  p_enc->HDR10dy1 = 0;
4386  p_enc->HDR10dx2 = 0;
4387  p_enc->HDR10dy2 = 0;
4388  p_enc->HDR10wx = 0;
4389  p_enc->HDR10wy = 0;
4390  p_enc->HDR10maxluma = 0;
4391  p_enc->HDR10minluma = 0;
4392  p_enc->avcc_hvcc = 0;
4393  p_enc->av1_error_resilient_mode = 0;
4394  p_enc->temporal_layers_enable = 0;
4395  p_enc->crop_width = 0;
4396  p_enc->crop_height = 0;
4397  p_enc->hor_offset = 0;
4398  p_enc->ver_offset = 0;
4399  p_enc->crfMax = -1;
4400  p_enc->qcomp = (float)0.6;
4401  p_enc->noMbtree = 0;
4402  p_enc->noHWMultiPassSupport = 0;
4403  p_enc->cuTreeFactor = 5;
4404  p_enc->ipRatio = (float)1.4;
4405  p_enc->pbRatio = (float)1.3;
4406  p_enc->cplxDecay = (float)0.5;
4407  p_enc->pps_init_qp = -1;
4408  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)
4409  p_enc->pass1_qp = -1;
4410  p_enc->crfFloat = -1.0f;
4411  p_enc->hvsBaseMbComplexity = 15;
4412  p_enc->statistic_output_level = 0;
4413  p_enc->skip_frame_enable = 0;
4414  p_enc->max_consecutive_skip_num = 1;
4415  p_enc->skip_frame_interval = 0;
4416  p_enc->enableipRatio = 0;
4417  p_enc->enable_all_sei_passthru = 0;
4418  p_enc->iframe_size_ratio = 100;
4419  p_enc->crf_max_iframe_enable = 0;
4420  p_enc->vbv_min_rate = 0;
4421  p_enc->totalCuTreeDepth = 0;
4422  p_enc->adaptiveCuTree = 0;
4423  p_enc->preIntraHandling = 1;
4424  p_enc->baseLayerOnly = 0;
4425  p_enc->pastFrameMaxIntraRatio = 20;
4426  p_enc->linkFrameMaxIntraRatio = 40;
4427 #ifdef XCODER_311
4428  p_enc->disable_adaptive_buffers = 1;
4429 #else
4430  p_enc->disable_adaptive_buffers = 0;
4431 #endif
4432  p_enc->disableBframeRdoq = 0;
4433  p_enc->forceBframeQpfactor = (float)-1.0;
4434  p_enc->tune_bframe_visual = 0;
4435  p_enc->enable_acq_limit = 0;
4436  p_enc->get_psnr_mode = 3;
4437  p_enc->customize_roi_qp_level = 0;
4438  p_enc->motionConstrainedMode = 0;
4439  p_enc->still_image_detect_level = 0;
4440  p_enc->scene_change_detect_level = 0;
4441  p_enc->encMallocStrategy = 0;
4442  p_enc->enable_smooth_crf = 0;
4443  p_enc->enable_compensate_qp = 0;
4444  p_enc->spatial_layers = 1;
4445  p_enc->enable_timecode = 0;
4446  p_enc->spatial_layers_ref_base_layer = 0;
4447  p_enc->vbvBufferReencode = 0;
4448  for (i = 0; i < NI_MAX_SPATIAL_LAYERS; i++)
4449  {
4450  p_enc->spatialLayerBitrate[i] = 0;
4451  }
4452 
4453  if (codec_format == NI_CODEC_FORMAT_AV1)
4454  {
4455  if (p_param->source_width < NI_PARAM_AV1_MIN_WIDTH)
4456  {
4458  LRETURN;
4459  }
4460  if (p_param->source_height < NI_PARAM_AV1_MIN_HEIGHT)
4461  {
4463  LRETURN;
4464  }
4465  if (p_param->source_width > NI_PARAM_AV1_MAX_WIDTH)
4466  {
4468  LRETURN;
4469  }
4470  if (p_param->source_height > NI_PARAM_AV1_MAX_HEIGHT)
4471  {
4473  LRETURN;
4474  }
4475  if (p_param->source_height * p_param->source_width >
4477  {
4479  LRETURN;
4480  }
4481  // AV1 8x8 alignment HW limitation is now worked around by FW cropping input resolution
4483  {
4484  ni_log(NI_LOG_ERROR, "AV1 Picture Width not aligned to %d - picture will be cropped\n",
4486  }
4488  {
4489  ni_log(NI_LOG_ERROR, "AV1 Picture Height not aligned to %d - picture will be cropped\n",
4491  }
4492  }
4493 
4494  if (codec_format == NI_CODEC_FORMAT_JPEG)
4495  {
4496  if (p_param->source_width < NI_PARAM_JPEG_MIN_WIDTH)
4497  {
4499  LRETURN;
4500  }
4501  if (p_param->source_height < NI_PARAM_JPEG_MIN_HEIGHT)
4502  {
4504  LRETURN;
4505  }
4506  }
4507 
4508  if (p_param->source_width > NI_PARAM_MAX_WIDTH)
4509  {
4511  LRETURN;
4512  }
4513  if (p_param->source_width < NI_PARAM_MIN_WIDTH)
4514  {
4516  LRETURN;
4517  }
4518 
4519  if (p_param->source_height > NI_PARAM_MAX_HEIGHT)
4520  {
4522  LRETURN;
4523  }
4524  if (p_param->source_height < NI_PARAM_MIN_HEIGHT)
4525  {
4527  LRETURN;
4528  }
4529  if (p_param->source_height*p_param->source_width > NI_MAX_RESOLUTION_AREA)
4530  {
4532  LRETURN;
4533  }
4534 
4535 END:
4536 
4537  return retval;
4538 }
4539 
4540 /*!*****************************************************************************
4541  * \brief Initialize default decoder parameters
4542  *
4543  * \param[out] param Pointer to a user allocated ni_xcoder_params_t
4544  * to initialize to default parameters
4545  * \param[in] fps_num Frames per second
4546  * \param[in] fps_denom FPS denomination
4547  * \param[in] bit_rate bit rate
4548  * \param[in] width frame width
4549  * \param[in] height frame height
4550  *
4551  * \return On success
4552  * NI_RETCODE_SUCCESS
4553  * On failure
4554  * NI_RETCODE_FAILURE
4555  * NI_RETCODE_INVALID_PARAM
4556  ******************************************************************************/
4558  int fps_num, int fps_denom,
4559  long bit_rate, int width,
4560  int height)
4561 {
4562  ni_decoder_input_params_t* p_dec = NULL;
4563  int i;
4565 
4566  //Initialize p_param structure
4567  if (!p_param)
4568  {
4569  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameter passed\n",
4570  __func__);
4571  retval = NI_RETCODE_INVALID_PARAM;
4572  LRETURN;
4573  }
4574 
4575  ni_log(NI_LOG_DEBUG, "%s\n", __func__);
4576 
4577  //Initialize p_param structure
4578  memset(p_param, 0, sizeof(ni_xcoder_params_t));
4579 
4580  p_dec = &p_param->dec_input_params;
4581 
4582  p_param->source_width = width;
4583  p_param->source_height = height;
4584 
4585  if(fps_num <= 0 || fps_denom <= 0)
4586  {
4587  fps_num = 30;
4588  fps_denom = 1;
4589  ni_log(NI_LOG_INFO, "%s(): FPS is not set, setting the default FPS to 30\n", __func__);
4590  }
4591 
4592  p_param->fps_number = fps_num;
4593  p_param->fps_denominator = fps_denom;
4594 
4595  p_dec->hwframes = 0;
4596  p_dec->mcmode = 0;
4597  p_dec->nb_save_pkt = 0;
4598  p_dec->enable_out1 = 0;
4599  p_dec->enable_out2 = 0;
4600  for (i = 0; i < NI_MAX_NUM_OF_DECODER_OUTPUTS; i++)
4601  {
4602  p_dec->force_8_bit[i] = 0;
4603  p_dec->semi_planar[i] = 0;
4604  p_dec->crop_mode[i] = NI_DEC_CROP_MODE_AUTO;
4605  p_dec->crop_whxy[i][0] = width;
4606  p_dec->crop_whxy[i][1] = height;
4607  p_dec->crop_whxy[i][2] = 0;
4608  p_dec->crop_whxy[i][3] = 0;
4609  p_dec->scale_wh[i][0] = 0;
4610  p_dec->scale_wh[i][1] = 0;
4611  p_dec->scale_long_short_edge[i] = 0;
4612  p_dec->scale_resolution_ceil[i] = 2;
4613  p_dec->scale_round[i] = -1;
4614  }
4616  p_dec->decoder_low_delay = 0;
4617  p_dec->force_low_delay = false;
4618  p_dec->enable_low_delay_check = 0;
4619  p_dec->enable_user_data_sei_passthru = 0;
4620  p_dec->custom_sei_passthru = -1;
4623  p_dec->enable_advanced_ec = 1;
4625  p_dec->enable_ppu_scale_adapt = 0;
4626  p_dec->enable_ppu_scale_limit = 0;
4627  p_dec->max_extra_hwframe_cnt = 255; //uint8_max
4628  p_dec->pkt_pts_unchange = 0;
4629  p_dec->enable_all_sei_passthru = 0;
4630  p_dec->enable_follow_iframe = 0;
4632 #ifdef XCODER_311
4633  p_dec->disable_adaptive_buffers = 1;
4634  p_dec->min_packets_delay = true;
4635  p_dec->reduce_dpb_delay = 1;
4636 #else
4637  p_dec->disable_adaptive_buffers = 0;
4638  p_dec->min_packets_delay = false;
4639  p_dec->reduce_dpb_delay = 0;
4640 #endif
4641  p_dec->survive_stream_err = 0;
4642  p_dec->skip_extra_headers = 0;
4643 
4644  //-------init unused param start----------
4645 
4646  p_param->bitrate = (int)bit_rate;
4647  p_param->reconf_demo_mode = 0; // for encoder reconfiguration testing
4648  p_param->force_pic_qp_demo_mode = 0;
4649  p_param->force_frame_type = 0;
4650  p_param->hdrEnableVUI = 0;
4651  p_param->cacheRoi = 0;
4652  p_param->low_delay_mode = 0;
4653  p_param->padding = 1;
4654  p_param->generate_enc_hdrs = 0;
4655  p_param->use_low_delay_poc_type = 0;
4656  p_param->dolby_vision_profile = 0;
4657 
4658  // encoder stream header VUI setting
4659  p_param->color_primaries = 2; // default COL_PRI_UNSPECIFIED
4660  p_param->color_transfer_characteristic = 2; // default COL_TRC_UNSPECIFIED
4661  p_param->color_space = 2; // default COL_SPC_UNSPECIFIED
4662  p_param->sar_num = 0; // default SAR numerator 0
4663  p_param->sar_denom = 1; // default SAR denominator 1
4664  p_param->video_full_range_flag = -1;
4665 
4666  //-------init unused param done----------
4667 
4668 END:
4669 
4670  return retval;
4671 }
4672 
4673 // read demo reconfig data file and parse out reconfig key/values in the format:
4674 // key:val1,val2,val3,...val9 (max 9 values); only digit/:/,/newline is allowed
4675 ni_retcode_t ni_parse_reconf_file(const char *reconf_file,
4677 {
4678  char keyChar[10] = "";
4679  int key;
4680  char valChar[10] = "";
4681  int val;
4682  int valIdx = 1;
4683  int parseKey = 1;
4684  int idx = 0;
4685  int readc = EOF;
4686  FILE *reconf = NULL;
4687 
4688  if (!reconf_file)
4689  {
4690  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4691  __func__);
4692  return NI_RETCODE_INVALID_PARAM;
4693  }
4694 
4695  reconf = fopen(reconf_file, "r");
4696  if (!reconf)
4697  {
4698  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4699  NI_ERRNO, __func__, reconf_file);
4701  }
4703 
4704  while ((readc = fgetc(reconf)) != EOF)
4705  {
4706  //parse lines
4707  if (isdigit(readc))
4708  {
4709  if (parseKey)
4710  {
4711  strncat(keyChar, (const char *)(&readc), 1);
4712  }
4713  else
4714  {
4715  strncat(valChar, (const char *)(&readc), 1);
4716  }
4717  }
4718  else if (readc == ':')
4719  {
4720  parseKey = 0;
4721  key = atoi(keyChar);
4722  hash_map[idx][0] = key;
4723  }
4724  else if (readc == ',')
4725  {
4727  {
4729  "ERROR: Number of entries per line in reconfig file is greater then the "
4730  "limit of %d\n",
4732  retval = NI_RETCODE_INVALID_PARAM;
4733  break;
4734  }
4735  val = atoi(valChar);
4736  hash_map[idx][valIdx] = val;
4737  valIdx++;
4738  memset(valChar, 0, 10);
4739  }
4740  else if (readc == '\n')
4741  {
4743  {
4745  "ERROR: Number of lines in reconfig file is greater then the "
4746  "limit of %d\n",
4748  retval = NI_RETCODE_INVALID_PARAM;
4749  break;
4750  }
4751  parseKey = 1;
4752  val = atoi (valChar);
4753  hash_map[idx][valIdx] = val;
4754  valIdx = 1;
4755  memset(keyChar,0,10);
4756  memset(valChar,0,10);
4757  idx ++;
4758  }
4759  else
4760  {
4761  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4762  }
4763  }
4764 
4765  fclose(reconf);
4766 
4767  if (NI_RETCODE_SUCCESS == retval && parseKey != 1)
4768  {
4770  "ERROR %d: %s(): Incorrect format / "
4771  "incomplete Key/Value pair in reconfig_file: %s\n",
4772  NI_ERRNO, __func__, reconf_file);
4774  }
4775 
4776  return retval;
4777 }
4778 
4780  int8_t qp_map[][NI_CUSTOMIZE_ROI_QP_NUM])
4781 {
4782  char valChar[5] = "";
4783  int val;
4784  int negative = 0;
4785  int qpIdx = 0;
4786  int levelIdx = 0;
4787  int readc = EOF;
4788  FILE *reconf = NULL;
4789 
4790  if (!customize_file)
4791  {
4792  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4793  __func__);
4794  return NI_RETCODE_INVALID_PARAM;
4795  }
4796 
4797  reconf = fopen(customize_file, "r");
4798  if (!reconf)
4799  {
4800  ni_log(NI_LOG_ERROR, "ERROR %d: %s(): Cannot open reconfig_file: %s\n",
4801  NI_ERRNO, __func__, customize_file);
4803  }
4805 
4806  while ((readc = fgetc(reconf)) != EOF)
4807  {
4808  //parse lines
4809  if (isdigit(readc))
4810  {
4811  strncat(valChar, (const char *)(&readc), 1);
4812  }
4813  else if (readc == '-') {
4814  negative = 1;
4815  }
4816  else if (readc == ',')
4817  {
4818  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4819  {
4821  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4822  "Number of levelIdx %d greater then the limit of %d\n",
4824  retval = NI_RETCODE_INVALID_PARAM;
4825  break;
4826  }
4827  if (!negative) {
4828  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
4829  qp_map[levelIdx][qpIdx] = val;
4830  } else {
4831  val = clip3(0, 32, atoi(valChar));
4832  qp_map[levelIdx][qpIdx] = val * -1;
4833  }
4834  negative = 0;
4835  memset(valChar, 0, 5);
4836  qpIdx++;
4837  }
4838  else if (readc == '\n')
4839  {
4840  if (qpIdx >= NI_CUSTOMIZE_ROI_QP_NUM || levelIdx >= NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL)
4841  {
4843  "ERROR: Number of qpIdx %d greater then the limit of %d or"
4844  "Number of levelIdx %d greater then the limit of %d\n",
4846  retval = NI_RETCODE_INVALID_PARAM;
4847  break;
4848  }
4849  if (!negative) {
4850  val = clip3(0, NI_MAX_QP_INFO, atoi(valChar));
4851  qp_map[levelIdx][qpIdx] = val;
4852  } else {
4853  val = clip3(0, 32, atoi(valChar));
4854  qp_map[levelIdx][qpIdx] = val * -1;
4855  }
4856  negative = 0;
4857  memset(valChar, 0, 5);
4858  qpIdx = 0;
4859  levelIdx++;
4860  }
4861  else
4862  {
4863  ni_log(NI_LOG_ERROR, "ERROR: character %c in reconfig file. this may lead to mistaken reconfiguration values\n", readc);
4864  }
4865  }
4866  fclose(reconf);
4867 
4868  return retval;
4869 }
4870 
4871 
4872 #undef atoi
4873 #undef atof
4874 #define atoi(p_str) ni_atoi(p_str, &b_error)
4875 #define atof(p_str) ni_atof(p_str, &b_error)
4876 #define atobool(p_str) (ni_atobool(p_str, &b_error))
4877 /*!*****************************************************************************
4878 * \brief Set value referenced by name in decoder parameters structure
4879 *
4880 * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t (used
4881 * for decoder too for now ) to find and set a particular
4882 * parameter
4883 * \param[in] name String represented parameter name to search
4884 * \param[in] value Parameter value to set
4885 *
4886 * \return On success
4887 * NI_RETCODE_SUCCESS
4888 * On failure
4889 * NI_RETCODE_FAILURE
4890 * NI_RETCODE_INVALID_PARAM
4891 *******************************************************************************/
4893  const char *name, char *value)
4894 {
4895  bool b_error = false;
4896  bool bNameWasBool = false;
4897  bool bValueWasNull = !value;
4898  ni_decoder_input_params_t* p_dec = NULL;
4899  char nameBuf[64] = { 0 };
4900  const char delim[2] = ",";
4901  const char xdelim[2] = "x";
4902  char *chunk;//for parsing out multi param input
4903  int i, j, k;
4904 
4905  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
4906 
4907  if (!p_params)
4908  {
4909  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
4910  __func__);
4911  return NI_RETCODE_INVALID_PARAM;
4912  }
4913 
4914  if (!name)
4915  {
4916  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
4917  __func__);
4919  }
4920  p_dec = &p_params->dec_input_params;
4921 
4922  // skip -- prefix if provided
4923  if (name[0] == '-' && name[1] == '-')
4924  {
4925  name += 2;
4926  }
4927 
4928  // s/_/-/g
4929  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
4930  {
4931  char* c;
4932  strcpy(nameBuf, name);
4933  while ((c = strchr(nameBuf, '_')) != 0)
4934  {
4935  *c = '-';
4936  }
4937  name = nameBuf;
4938  }
4939 
4940  if (!value)
4941  {
4942  value = "true";
4943  }
4944  else if (value[0] == '=')
4945  {
4946  value++;
4947  }
4948 
4949 #if defined(_MSC_VER)
4950 #define OPT(STR) else if (!_stricmp(name, STR))
4951 #define OPT2(STR1, STR2) \
4952  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
4953 #else
4954 #define OPT(STR) else if (!strcasecmp(name, STR))
4955 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
4956 #endif
4957  if (0); // suppress cppcheck
4959  {
4960  if (!strncmp(value, "hw", sizeof("hw"))){
4961  p_dec->hwframes = 1;
4962  }
4963  else if (!strncmp(value, "sw", sizeof("sw"))) {
4964  p_dec->hwframes = 0;
4965  }
4966  else{
4967  ni_log(NI_LOG_ERROR, "ERROR: %s(): out can only be <hw,sw> got %s\n",
4968  __func__, value);
4970  }
4971  }
4973  {
4974  if (atoi(value) == 1)
4975  p_dec->enable_out1 = 1;
4976  }
4978  {
4979  if (atoi(value) == 1)
4980  p_dec->enable_out2 = 1;
4981  }
4983  {
4984  if (atoi(value) == 1)
4985  p_dec->force_8_bit[0] = 1;
4986  }
4988  {
4989  if (atoi(value) == 1)
4990  p_dec->force_8_bit[1] = 1;
4991  }
4993  {
4994  if (atoi(value) == 1)
4995  p_dec->force_8_bit[2] = 1;
4996  }
4998  {
4999  if (atoi(value) == 1 || atoi(value) == 2)
5000  p_dec->semi_planar[0] = atoi(value);
5001  }
5003  {
5004  if (atoi(value) == 1 || atoi(value) == 2)
5005  p_dec->semi_planar[1] = atoi(value);
5006  }
5008  {
5009  if (atoi(value) == 1 || atoi(value) == 2)
5010  p_dec->semi_planar[2] = atoi(value);
5011  }
5013  {
5014  if (!strncmp(value, "manual", sizeof("manual"))) {
5015  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_MANUAL;
5016  }
5017  else if (!strncmp(value, "auto", sizeof("auto"))) {
5018  p_dec->crop_mode[0] = NI_DEC_CROP_MODE_AUTO;
5019  }
5020  else{
5022  "ERROR: %s():cropMode0 input can only be <manual,auto> got %s\n",
5023  __func__, value);
5025  }
5026  }
5028  {
5029  if (!strncmp(value, "manual", sizeof("manual"))) {
5030  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_MANUAL;
5031  }
5032  else if (!strncmp(value, "auto", sizeof("auto"))) {
5033  p_dec->crop_mode[1] = NI_DEC_CROP_MODE_AUTO;
5034  }
5035  else {
5037  "ERROR: %s():cropMode1 input can only be <manual,auto> got %s\n",
5038  __func__, value);
5040  }
5041  }
5043  {
5044  if (!strncmp(value, "manual", sizeof("manual"))) {
5045  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_MANUAL;
5046  }
5047  else if (!strncmp(value, "auto", sizeof("auto"))) {
5048  p_dec->crop_mode[2] = NI_DEC_CROP_MODE_AUTO;
5049  }
5050  else {
5052  "ERROR: %s():cropMode2 input can only be <manual,auto> got %s\n",
5053  __func__, value);
5055  }
5056  }
5058  {
5059  char *saveptr = NULL;
5060  chunk = ni_strtok(value, delim, &saveptr);
5061  for (i = 0; i < 4; i++)
5062  {
5063  if (chunk != NULL)
5064  {
5065  j = k = 0;
5066  while (chunk[j])
5067  {
5068  if (chunk[j] != '\"' && chunk[j] != '\'')
5069  {
5070  p_dec->cr_expr[0][i][k] = chunk[j];
5071  k++;
5072  }
5073  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5074  {
5076  }
5077  }
5078  chunk = ni_strtok(NULL, delim, &saveptr);
5079  }
5080  else if (i == 2 ) //default offsets to centered image if not specified, may need recalc
5081  {
5082  strcpy(p_dec->cr_expr[0][i], "in_w/2-out_w/2");
5083  }
5084  else if (i == 3)
5085  {
5086  strcpy(p_dec->cr_expr[0][i], "in_h/2-out_h/2");
5087  } else
5088  {
5090  }
5091  }
5092  }
5094  {
5095  char *saveptr = NULL;
5096  chunk = ni_strtok(value, delim, &saveptr);
5097  for (i = 0; i < 4; i++)
5098  {
5099  if (chunk != NULL)
5100  {
5101  j = k = 0;
5102  while (chunk[j])
5103  {
5104  if (chunk[j] != '\"' && chunk[j] != '\'')
5105  {
5106  p_dec->cr_expr[1][i][k] = chunk[j];
5107  k++;
5108  }
5109  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5110  {
5112  }
5113  }
5114  chunk = ni_strtok(NULL, delim, &saveptr);
5115  }
5116  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5117  {
5118 
5119  strcpy(p_dec->cr_expr[1][i], "in_w/2-out_w/2");
5120  }
5121  else if (i == 3)
5122  {
5123  strcpy(p_dec->cr_expr[1][i], "in_h/2-out_h/2");
5124  }
5125  else
5126  {
5128  }
5129  }
5130  }
5132  {
5133  char *saveptr = NULL;
5134  chunk = ni_strtok(value, delim, &saveptr);
5135  for (i = 0; i < 4; i++)
5136  {
5137  if (chunk != NULL)
5138  {
5139  j = k = 0;
5140  while (chunk[j])
5141  {
5142  if (chunk[j] != '\"' && chunk[j] != '\'')
5143  {
5144  p_dec->cr_expr[2][i][k] = chunk[j];
5145  k++;
5146  }
5147  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5148  {
5150  }
5151  }
5152  chunk = ni_strtok(NULL, delim, &saveptr);
5153  }
5154  else if (i == 2) //default offsets to centered image if not specified, may need recalc
5155  {
5156 
5157  strcpy(p_dec->cr_expr[2][i], "in_w/2-out_w/2");
5158  }
5159  else if (i == 3)
5160  {
5161  strcpy(p_dec->cr_expr[2][i], "in_h/2-out_h/2");
5162  }
5163  else
5164  {
5166  }
5167  }
5168  }
5170  {
5171  chunk = value;
5172  i = 0; // 'x' character counter
5173  while (*chunk++) {
5174  if (*chunk == xdelim[0]) {
5175  i++;
5176  }
5177  }
5178  if (i != 1) {
5180  }
5181  chunk = NULL;
5182 
5183  char *saveptr = NULL;
5184  chunk = ni_strtok(value, xdelim, &saveptr);
5185  for (i = 0; i < 2; i++)
5186  {
5187  if (chunk != NULL)
5188  {
5189  j = k = 0;
5190  while (chunk[j])
5191  {
5192  if (chunk[j] != '\"' && chunk[j] != '\'')
5193  {
5194  p_dec->sc_expr[0][i][k] = chunk[j];
5195  k++;
5196  }
5197  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5198  {
5200  }
5201  }
5202  chunk = ni_strtok(NULL, xdelim, &saveptr);
5203  }
5204  else
5205  {
5207  }
5208  }
5209  }
5211  {
5212  chunk = value;
5213  i = 0; // 'x' character counter
5214  while (*chunk++) {
5215  if (*chunk == xdelim[0]) {
5216  i++;
5217  }
5218  }
5219  if (i != 1) {
5221  }
5222  chunk = NULL;
5223 
5224  char *saveptr = NULL;
5225  chunk = ni_strtok(value, xdelim, &saveptr);
5226  for (i = 0; i < 2; i++)
5227  {
5228  if (chunk != NULL)
5229  {
5230  j = k = 0;
5231  while (chunk[j])
5232  {
5233  if (chunk[j] != '\"' && chunk[j] != '\'')
5234  {
5235  p_dec->sc_expr[1][i][k] = chunk[j];
5236  k++;
5237  }
5238  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5239  {
5241  }
5242  }
5243  chunk = ni_strtok(NULL, xdelim, &saveptr);
5244  }
5245  else
5246  {
5248  }
5249  }
5250  }
5252  {
5253  chunk = value;
5254  i = 0; // 'x' character counter
5255  while (*chunk++) {
5256  if (*chunk == xdelim[0]) {
5257  i++;
5258  }
5259  }
5260  if (i != 1) {
5262  }
5263  chunk = NULL;
5264 
5265  char *saveptr = NULL;
5266  chunk = ni_strtok(value, xdelim, &saveptr);
5267  for (i = 0; i < 2; i++)
5268  {
5269  if (chunk != NULL)
5270  {
5271  j = k = 0;
5272  while (chunk[j])
5273  {
5274  if (chunk[j] != '\"' && chunk[j] != '\'')
5275  {
5276  p_dec->sc_expr[2][i][k] = chunk[j];
5277  k++;
5278  }
5279  if (++j > NI_MAX_PPU_PARAM_EXPR_CHAR)
5280  {
5282  }
5283  }
5284  chunk = ni_strtok(NULL, xdelim, &saveptr);
5285  }
5286  else
5287  {
5289  }
5290  }
5291  }
5293  {
5294  if ((atoi(value) < 0) || (atoi(value) > 2))
5295  {
5297  }
5298  p_dec->scale_long_short_edge[0] = atoi(value);
5299  }
5301  {
5302  if ((atoi(value) < 0) || (atoi(value) > 2))
5303  {
5305  }
5306  p_dec->scale_long_short_edge[1] = atoi(value);
5307  }
5309  {
5310  if ((atoi(value) < 0) || (atoi(value) > 2))
5311  {
5313  }
5314  p_dec->scale_long_short_edge[2] = atoi(value);
5315  }
5317  {
5318  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5319  {
5320  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5321  "and must be even number and less than or equal to 128. Got: %s\n",
5322  __func__, NI_DEC_PARAM_SCALE_0_RES_CEIL, value);
5323 
5325  }
5326  p_dec->scale_resolution_ceil[0] = 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_1_RES_CEIL, value);
5336  }
5337  p_dec->scale_resolution_ceil[1] = atoi(value);
5338  }
5340  {
5341  if (atoi(value) < 2 || atoi(value) % 2 != 0 || atoi(value) > 128)
5342  {
5343  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s must be greater than or equal to 2 "
5344  "and must be even number and less than or equal to 128. Got: %s\n",
5345  __func__, NI_DEC_PARAM_SCALE_2_RES_CEIL, value);
5347  }
5348  p_dec->scale_resolution_ceil[2] = atoi(value);
5349  }
5351  {
5352  if (!strncmp(value, "up", sizeof("up"))){
5353  p_dec->scale_round[0] = 0;
5354  }
5355  else if (!strncmp(value, "down", sizeof("down"))) {
5356  p_dec->scale_round[0] = 1;
5357  }
5358  else{
5359  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5360  __func__, NI_DEC_PARAM_SCALE_0_ROUND, value);
5362  }
5363  }
5365  {
5366  if (!strncmp(value, "up", sizeof("up"))){
5367  p_dec->scale_round[1] = 0;
5368  }
5369  else if (!strncmp(value, "down", sizeof("down"))) {
5370  p_dec->scale_round[1] = 1;
5371  }
5372  else{
5373  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5374  __func__, NI_DEC_PARAM_SCALE_1_ROUND, value);
5376  }
5377  }
5379  {
5380  if (!strncmp(value, "up", sizeof("up"))){
5381  p_dec->scale_round[2] = 0;
5382  }
5383  else if (!strncmp(value, "down", sizeof("down"))) {
5384  p_dec->scale_round[2] = 1;
5385  }
5386  else{
5387  ni_log(NI_LOG_ERROR, "ERROR: %s(): %s can only be {up, down}. Got: %s\n",
5388  __func__, NI_DEC_PARAM_SCALE_2_ROUND, value);
5390  }
5391  }
5393  {
5394  if ((atoi(value) != 0) && (atoi(value) != 1))
5395  {
5397  }
5398  p_dec->mcmode = atoi(value);
5399  }
5401  {
5402  if (atoi(value) < 0)
5403  {
5405  }
5406  p_dec->nb_save_pkt = atoi(value);
5407  }
5409  {
5410  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
5411  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
5412  {
5414  }
5415  p_dec->keep_alive_timeout = atoi(value);
5416  }
5418  {
5419  if (atoi(value) < 0)
5420  {
5422  }
5423  p_dec->decoder_low_delay = atoi(value);
5424  }
5426  {
5427  if ((atoi(value) != 0) && (atoi(value) != 1))
5428  {
5430  }
5431  p_dec->force_low_delay = atoi(value);
5432  }
5434  {
5435  if (atoi(value) < 0)
5436  {
5438  }
5439  p_dec->enable_low_delay_check = atoi(value);
5440  }
5442  {
5443  if ((atoi(value) != 0) && (atoi(value) != 1))
5444  {
5446  }
5447  p_dec->min_packets_delay = atoi(value);
5448  }
5450  {
5451  if (atoi(value) != NI_ENABLE_USR_DATA_SEI_PASSTHRU &&
5453  {
5455  }
5456  p_dec->enable_user_data_sei_passthru = atoi(value);
5457  }
5459  {
5460  if (atoi(value) < NI_MIN_CUSTOM_SEI_PASSTHRU ||
5462  {
5464  }
5465  p_dec->custom_sei_passthru = atoi(value);
5466  }
5468  {
5469  if (atoi(value) < NI_INVALID_SVCT_DECODING_LAYER)
5470  {
5472  }
5473  p_dec->svct_decoding_layer = atoi(value);
5474  }
5476  {
5477  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
5478  atoi(value) <= NI_DDR_PRIORITY_NONE)
5479  {
5481  }
5482  p_params->ddr_priority_mode = atoi(value);
5483  }
5485  {
5486  if (strncmp(value, "tolerant", sizeof("tolerant")) == 0) {
5488  } else if (strncmp(value, "ignore", sizeof("ignore")) == 0) {
5489  p_dec->ec_policy = NI_EC_POLICY_IGNORE;
5490  } else if (strncmp(value, "skip", sizeof("skip")) == 0) {
5491  p_dec->ec_policy = NI_EC_POLICY_SKIP;
5492  } else if (strncmp(value, "best_effort", sizeof("best_effort")) == 0) {
5494  } else if (strncmp(value, "limited_error", sizeof("limited_error")) == 0) {
5496  } else if (strncmp(value, "best_effort_out_dc", sizeof("best_effort_out_dc")) == 0) {
5498  } else {
5500  }
5501  }
5503  {
5504  if (atoi(value) != 0 &&
5505  atoi(value) != 1 &&
5506  atoi(value) != 2)
5507  {
5509  }
5510  p_dec->enable_advanced_ec = atoi(value);
5511  }
5513  {
5514  if (atoi(value) < 0 || (atoi(value) > 100))
5515  {
5517  }
5518  p_dec->error_ratio_threshold = atoi(value);
5519  }
5521  {
5522  if (atoi(value) < 0 || (atoi(value) > 2))
5523  {
5525  }
5526  p_dec->enable_ppu_scale_adapt = atoi(value);
5527  }
5529  {
5530  if (atoi(value) < 0 || (atoi(value) > 1))
5531  {
5533  }
5534  p_dec->enable_ppu_scale_limit = atoi(value);
5535  }
5537  {
5538  if (atoi(value) < 0 || atoi(value) > 255)
5539  {
5541  }
5542  p_dec->max_extra_hwframe_cnt = atoi(value);
5543  }
5545  {
5546  if (atoi(value) < 0 || atoi(value) > 1)
5547  {
5549  }
5550  p_dec->skip_pts_guess = atoi(value);
5551  }
5553  {
5554  if (atoi(value) != 0 && atoi(value) != 1)
5555  {
5557  }
5558  p_dec->pkt_pts_unchange = atoi(value);
5559  }
5561  {
5562  if (atoi(value) < 0 ||
5563  atoi(value) > 1)
5564  {
5566  }
5567  p_dec->enable_all_sei_passthru = atoi(value);
5568  }
5570  {
5571  if (atoi(value) != 0 && atoi(value) != 1)
5572  {
5574  }
5575  p_dec->enable_follow_iframe = atoi(value);
5576  }
5578  {
5579  if (atoi(value) < 0 ||
5580  atoi(value) > 1)
5581  {
5583  }
5584  p_dec->disable_adaptive_buffers = atoi(value);
5585  }
5587  {
5588  if (atoi(value) < 0 || atoi(value) > 1)
5589  {
5591  }
5592  p_dec->survive_stream_err = atoi(value);
5593  }
5595  {
5596  if ((atoi(value) != 0) && (atoi(value) != 1))
5597  {
5599  }
5600  p_dec->reduce_dpb_delay = atoi(value);
5601  }
5603  {
5604  if ((atoi(value) != 0) && (atoi(value) != 1))
5605  {
5607  }
5608  p_dec->skip_extra_headers = atoi(value);
5609  }
5610  else
5611  {
5613  }
5614 
5615 #undef OPT
5616 #undef atobool
5617 #undef atoi
5618 #undef atof
5619  b_error |= bValueWasNull && !bNameWasBool;
5620 
5621  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
5622 
5624 }
5625 
5626 #undef atoi
5627 #undef atof
5628 #define atoi(p_str) ni_atoi(p_str, &b_error)
5629 #define atof(p_str) ni_atof(p_str, &b_error)
5630 #define atobool(p_str) (ni_atobool(p_str, &b_error))
5631 
5632 /*!*****************************************************************************
5633  * \brief Set value referenced by name in encoder parameters structure
5634  *
5635  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
5636  * to find and set a particular parameter
5637  * \param[in] name String represented parameter name to search
5638  * \param[in] value Parameter value to set
5639 *
5640  * \return On success
5641  * NI_RETCODE_SUCCESS
5642  * On failure
5643  * NI_RETCODE_FAILURE
5644  * NI_RETCODE_INVALID_PARAM
5645  ******************************************************************************/
5647  const char *name, const char *value)
5648 {
5649  bool b_error = false;
5650  bool bNameWasBool = false;
5651  bool bValueWasNull = !value;
5652  ni_encoder_cfg_params_t *p_enc = NULL;
5653  char nameBuf[64] = { 0 };
5654  int i,j,k;
5655 
5656  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
5657 
5658  if (!p_params)
5659  {
5660  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
5661  __func__);
5662  return NI_RETCODE_INVALID_PARAM;
5663  }
5664 
5665  if ( !name )
5666  {
5667  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
5668  __func__);
5670  }
5671  p_enc = &p_params->cfg_enc_params;
5672  // skip -- prefix if provided
5673  if (name[0] == '-' && name[1] == '-')
5674  {
5675  name += 2;
5676  }
5677 
5678  // s/_/-/g
5679  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
5680  {
5681  char* c;
5682  strcpy(nameBuf, name);
5683  while ((c = strchr(nameBuf, '_')) != 0)
5684  {
5685  *c = '-';
5686  }
5687  name = nameBuf;
5688  }
5689 
5690  if (!value)
5691  {
5692  value = "true";
5693  }
5694  else if (value[0] == '=')
5695  {
5696  value++;
5697  }
5698 
5699 #if defined(_MSC_VER)
5700 #define OPT(STR) else if (!_stricmp(name, STR))
5701 #define OPT2(STR1, STR2) \
5702  else if (!_stricmp(name, STR1) || !_stricmp(name, STR2))
5703 #else
5704 #define OPT(STR) else if (!strcasecmp(name, STR))
5705 #define OPT2(STR1, STR2) else if (!strcasecmp(name, STR1) || !strcasecmp(name, STR2))
5706 #endif
5707 #define COMPARE(STR1, STR2, STR3) \
5708  if ((atoi(STR1) > (STR2)) || (atoi(STR1) < (STR3))) \
5709  { \
5710  return NI_RETCODE_PARAM_ERROR_OOR; \
5711  }
5712  if (0); // suppress cppcheck
5714  {
5715  if (AV_CODEC_DEFAULT_BITRATE == p_params->bitrate)
5716  {
5717  if (atoi(value) > NI_MAX_BITRATE)
5718  {
5720  }
5721  if (atoi(value) < NI_MIN_BITRATE)
5722  {
5724  }
5725  p_params->bitrate = atoi(value);
5726  }
5727  }
5729  {
5730  p_params->reconf_demo_mode = atoi(value); // for encoder reconfiguration testing
5731  }
5733  {
5734  ni_retcode_t retval = ni_parse_reconf_file(value, p_params->reconf_hash);
5735  if (retval != NI_RETCODE_SUCCESS) // for encoder reconfiguration testing
5736  {
5737  return retval;
5738  }
5739  }
5741  {
5742  // for encoder reconfiguration testing
5743  p_params->roi_demo_mode = atoi(value);
5744  if ((p_params->roi_demo_mode < 0) || (p_params->roi_demo_mode > 2))
5745  {
5747  }
5748  }
5750  {
5751  if (0 > atoi(value))
5752  {
5754  }
5755  p_params->low_delay_mode = atoi(value);
5756  }
5758  {
5759  if (0 != atoi(value) && 1 != atoi(value))
5760  {
5762  }
5763  p_params->minFramesDelay = atoi(value);
5764  }
5766  {
5767  p_params->padding = atoi(value);
5768  }
5770  {
5771  if (0 != atoi(value) && 1 != atoi(value))
5772  {
5774  }
5775  p_params->generate_enc_hdrs = atoi(value);
5776  // genHdrs is deprecated in favour of libavcodec parameter -gen_global_headers
5778  }
5780  {
5781  if (0 != atoi(value) && 1 != atoi(value))
5782  {
5784  }
5785  p_params->use_low_delay_poc_type = atoi(value);
5786  }
5788  {
5789  if (QUADRA)
5790  {
5792  }
5793  p_params->force_frame_type = atoi(value);
5794  }
5796  {
5797  p_enc->profile = atoi(value);
5798  }
5800  {
5804  if (atof(value) <= 10)
5805  {
5806  p_enc->level_idc = (int)(10 * atof(value) + .5);
5807  }
5808  else
5809  {
5810  p_enc->level_idc = atoi(value);
5811  }
5812  }
5814  {
5815  p_enc->high_tier = atobool(value);
5816  }
5818  {
5819  p_params->log = atoi(value);
5820  if (b_error)
5821  {
5822  b_error = false;
5823  p_params->log = ni_parse_name(value, g_xcoder_log_names, &b_error) - 1;
5824  }
5825  }
5827  {
5828  if ((atoi(value) > NI_MAX_GOP_PRESET_IDX) || (atoi(value) < NI_MIN_GOP_PRESET_IDX))
5829  {
5831  }
5832  p_enc->gop_preset_index = atoi(value);
5833  }
5835  {
5837  {
5839  }
5840 
5841  p_enc->use_recommend_enc_params = atoi(value);
5842  }
5844  {
5845  if (QUADRA)
5846  {
5848  }
5849  if (((atoi(value) > NI_MAX_CU_SIZE_MODE) || (atoi(value) < NI_MIN_CU_SIZE_MODE)) && (atoi(value) != NI_DEFAULT_CU_SIZE_MODE))
5850  {
5852  }
5853 
5854  p_enc->cu_size_mode = atoi(value);
5855  }
5857  {
5858  if (QUADRA)
5859  {
5861  }
5862  if ((atoi(value) > NI_MAX_MAX_NUM_MERGE) || (atoi(value) < NI_MIN_MAX_NUM_MERGE))
5863  {
5865  }
5866 
5867  p_enc->max_num_merge = atoi(value);
5868  }
5870  {
5871  if (QUADRA)
5872  {
5874  }
5875  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5876  {
5878  }
5879 
5880  p_enc->enable_dynamic_8x8_merge = atoi(value);
5881  }
5883  {
5884  if (QUADRA)
5885  {
5887  }
5888  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5889  {
5891  }
5892 
5893  p_enc->enable_dynamic_16x16_merge = atoi(value);
5894  }
5896  {
5897  if (QUADRA)
5898  {
5900  }
5901  if ((atoi(value) > NI_MAX_DYNAMIC_MERGE) || (atoi(value) < NI_MIN_DYNAMIC_MERGE))
5902  {
5904  }
5905 
5906  p_enc->enable_dynamic_32x32_merge = atoi(value);
5907  }
5909  {
5910  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5911  {
5913  }
5914 
5915  p_enc->rc.enable_rate_control = atoi(value);
5916  }
5918  {
5919  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5920  {
5922  }
5923 
5924  p_enc->rc.enable_cu_level_rate_control = atoi(value);
5925  }
5927  {
5928  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
5929  {
5931  }
5932  p_enc->rc.enable_hvs_qp = atoi(value);
5933  }
5935  {
5936  if (QUADRA)
5937  {
5939  }
5940  p_enc->rc.enable_hvs_qp_scale = atoi(value);
5941  }
5943  {
5944  p_enc->rc.hvs_qp_scale = atoi(value);
5945  }
5947  {
5948  p_enc->rc.min_qp = atoi(value);
5949  }
5951  {
5952  p_enc->rc.max_qp = atoi(value);
5953  }
5955  {
5956  if (QUADRA)
5957  {
5959  }
5960  p_enc->rc.max_delta_qp = atoi(value);
5961  }
5963  {
5964  if ((atoi(value) > 51) || (atoi(value) < -1))
5965  {
5967  }
5968  p_enc->crf = atoi(value);
5969  }
5971  {
5972  p_enc->rc.vbv_buffer_size = atoi(value);
5973  if (QUADRA)
5974  {
5975  // RcInitDelay is deprecated and replaced with vbvBufferSize. But still accept the value.
5977  }
5978  }
5980  {
5981  p_enc->rc.vbv_buffer_size = atoi(value);
5982  }
5984  {
5985  p_enc->rc.vbv_max_rate = atoi(value);
5986  }
5988  {
5989  p_enc->rc.enable_filler = atoi(value);
5990  if (QUADRA)
5991  {
5992  // cbr is deprecated and replaced with fillerEnable. But still accept the value.
5994  }
5995  }
5997  {
5998  p_enc->rc.enable_filler = atoi(value);
5999  }
6001  {
6002  if (0 != atoi(value) && 1 != atoi(value))
6003  {
6005  }
6006  // Currenly pic skip is supported for low delay gops only - pic skip issues tracked by QDFW-1785/1958
6007  p_enc->rc.enable_pic_skip = atoi(value);
6008  }
6010  {
6011 #ifdef _MSC_VER
6012  if (!_strnicmp(value, "ratio", 5))
6013 #else
6014  if (!strncasecmp(value, "ratio", 5))
6015 #endif
6016  {
6017  char value_buf[32] = {0};
6018  for (i = 0; i < sizeof(value_buf); i++)
6019  {
6020  if (value[i+6] == ']')
6021  {
6022  break;
6023  }
6024  value_buf[i] = value[i+6];
6025  }
6026  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6027  {
6029  }
6030 
6031  p_enc->maxFrameSizeRatio = atoi(value_buf);
6032  }
6033  else
6034  {
6035  int size = atoi(value);
6036  if (size < NI_MIN_FRAME_SIZE)
6037  {
6039  }
6040  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6041  }
6042  }
6044  {
6045 #ifdef _MSC_VER
6046  if (!_strnicmp(value, "ratio", 5))
6047 #else
6048  if (!strncasecmp(value, "ratio", 5))
6049 #endif
6050  {
6051  char value_buf[32] = {0};
6052  for (i = 0; i < sizeof(value_buf); i++)
6053  {
6054  if (value[i+6] == ']')
6055  {
6056  break;
6057  }
6058  value_buf[i] = value[i+6];
6059  }
6060  if (i == sizeof(value_buf) || atoi(value_buf) < 0)
6061  {
6063  }
6064 
6065  p_enc->maxFrameSizeRatio = atoi(value_buf);
6066  }
6067  else
6068  {
6069  int size = atoi(value) / 8;
6070  if (size < NI_MIN_FRAME_SIZE)
6071  {
6073  }
6074  p_enc->maxFrameSize = (size > NI_MAX_FRAME_SIZE) ? NI_MAX_FRAME_SIZE : size;
6075  }
6076  }
6078  {
6079  if (0 != atoi(value) && 1 != atoi(value))
6080  {
6082  }
6083  p_enc->forced_header_enable = atoi(value);
6084  }
6086  {
6087  p_enc->roi_enable = atoi(value);
6088  }
6090  {
6091  p_enc->conf_win_top = atoi(value);
6092  }
6094  {
6095  p_enc->conf_win_bottom = atoi(value);
6096  }
6098  {
6099  p_enc->conf_win_left = atoi(value);
6100  }
6102  {
6103  p_enc->conf_win_right = atoi(value);
6104  }
6106  {
6107  p_enc->intra_period = atoi(value);
6108  //p_enc->bitrateWindow = p_enc->intra_period;
6109  }
6111  {
6112  if (atoi(value) > NI_MAX_BITRATE)
6113  {
6115  }
6116  if (atoi(value) < NI_MIN_BITRATE)
6117  {
6119  }
6120  p_enc->rc.trans_rate = atoi(value);
6121  }
6123  {
6124  if (atoi(value) <= 0 )
6125  {
6127  }
6128  p_params->fps_number = atoi(value);
6129  p_params->fps_denominator = 1;
6130  p_enc->frame_rate = p_params->fps_number;
6131  }
6133  {
6134  if (atoi(value) <= 0)
6135  {
6137  }
6138  p_params->fps_denominator = atoi(value);
6139  p_enc->frame_rate = (int)(p_params->fps_number / p_params->fps_denominator);
6140  }
6142  {
6143  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6144  {
6146  }
6147 
6148  p_enc->rc.intra_qp = atoi(value);
6149  }
6151  {
6152  if ((atoi(value) > NI_MAX_INTRA_QP_DELTA) ||
6153  (atoi(value) < NI_MIN_INTRA_QP_DELTA))
6154  {
6156  }
6157 
6158  p_enc->rc.intra_qp_delta = atoi(value);
6159  }
6161  {
6162  if ((atoi(value) > NI_MAX_INTRA_QP) || (atoi(value) < NI_MIN_INTRA_QP))
6163  {
6165  }
6166  p_params->force_pic_qp_demo_mode = atoi(value);
6167  }
6169  {
6170  if (QUADRA)
6171  {
6173  }
6175  {
6177  }
6178  p_enc->decoding_refresh_type = atoi(value);
6179  }
6181  {
6182  if (0 != atoi(value) && 1 != atoi(value))
6183  {
6185  }
6186  p_enc->intra_reset_refresh = atoi(value);
6187  }
6188  // Rev. B: H.264 only parameters.
6190  {
6191  if (QUADRA)
6192  {
6194  }
6195  p_enc->enable_transform_8x8 = atoi(value);
6196  }
6198  {
6199  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6200  {
6202  }
6203  p_enc->slice_mode = atoi(value);
6204  }
6206  {
6207  p_enc->slice_arg = atoi(value);
6208  }
6210  {
6211  if (0 != atoi(value) && 1 != atoi(value))
6212  {
6214  }
6215  p_enc->entropy_coding_mode = atoi(value);
6216  }
6217 // Rev. B: shared between HEVC and H.264
6219  {
6220  p_enc->intra_mb_refresh_mode = atoi(value);
6221  }
6223  {
6224  p_enc->intra_mb_refresh_arg = atoi(value);
6225  }
6227  {
6228  if ((atoi(value) > NI_MAX_BIN) || (atoi(value) < NI_MIN_BIN))
6229  {
6231  }
6232  p_enc->rc.enable_mb_level_rc = atoi(value);
6233  if (QUADRA)
6234  {
6235  // mbLevelRcEnable will be deprecated and cuLevelRCEnable should be used instead. But still accept the value.
6237  }
6238  }
6240  {
6241  if ((atoi(value) > 255) || (atoi(value) < 0))
6242  {
6244  }
6245  p_enc->preferred_transfer_characteristics = atoi(value);
6246  }
6248  {
6249  if (atoi(value) != 0 && atoi(value) != 5)
6250  {
6252  }
6253  p_params->dolby_vision_profile = atoi(value);
6254  }
6256  {
6257  if ((atoi(value) > 3) || (atoi(value) < 1))
6258  {
6260  }
6261  p_enc->rdoLevel = atoi(value);
6262  }
6264  {
6265  const char delim[2] = ",";
6266  char *chunk;
6267 #ifdef _MSC_VER
6268  char *v = _strdup(value);
6269 #else
6270  char *v = strdup(value);
6271 #endif
6272  char *saveptr = NULL;
6273  chunk = ni_strtok(v, delim, &saveptr);
6274  if (chunk != NULL)
6275  {
6276  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6277  {
6278  free(v);
6280  }
6281  p_enc->HDR10MaxLight = atoi(chunk);
6282  chunk = ni_strtok(NULL, delim, &saveptr);
6283  if (chunk != NULL)
6284  {
6285  if ((atoi(chunk) > 65535) || (atoi(chunk) < 0))
6286  {
6287  free(v);
6289  }
6290  p_enc->HDR10AveLight = atoi(chunk);
6291  p_enc->HDR10CLLEnable = 1; //Both param populated so enable
6292  free(v);
6293  }
6294  else
6295  {
6296  free(v);
6298  }
6299  }
6300  else
6301  {
6302  free(v);
6304  }
6305  }
6306 
6308  {
6309 #ifdef _MSC_VER
6310 #define STRDUP(value) _strdup(value);
6311 #else
6312 #define STRDUP(value) strdup(value);
6313 #endif
6314  const char G[2] = "G";
6315  const char B[2] = "B";
6316  const char R[2] = "R";
6317  const char W[2] = "W";
6318  const char L[2] = "L";
6319  const char P[2] = "P";
6320  const char parL[2] = "(";
6321  const char comma[2] = ",";
6322  const char parR[2] = ")";
6323  int synCheck_GBRWLPCP[8];
6324  int posCheck_GBRWL[5] = {0};
6325  char *chunk;//for parsing out more complex inputs
6326  char *subchunk;
6327  char *v = STRDUP(value);
6328  //basic check syntax correct
6329  for (i = 0; i<8; i++)
6330  {
6331  synCheck_GBRWLPCP[i] = 0;
6332  }
6333  chunk = v;
6334  i = 0; // character index
6335 
6336  //count keys and punctuation, save indicies to be parsed
6337  while (*chunk) {
6338  if (*chunk == G[0])
6339  {
6340  synCheck_GBRWLPCP[0]++;
6341  posCheck_GBRWL[0] = i;
6342  }
6343  else if (*chunk == B[0])
6344  {
6345  synCheck_GBRWLPCP[1]++;
6346  posCheck_GBRWL[1] = i;
6347  }
6348  else if (*chunk == R[0])
6349  {
6350  synCheck_GBRWLPCP[2]++;
6351  posCheck_GBRWL[2] = i;
6352  }
6353  else if (*chunk == W[0])
6354  {
6355  synCheck_GBRWLPCP[3]++;
6356  posCheck_GBRWL[3] = i;
6357  }
6358  else if (*chunk == L[0])
6359  {
6360  synCheck_GBRWLPCP[4]++;
6361  posCheck_GBRWL[4] = i;
6362  }
6363  else if (*chunk == parL[0])
6364  {
6365  synCheck_GBRWLPCP[5]++;
6366  }
6367  else if (*chunk == comma[0])
6368  {
6369  synCheck_GBRWLPCP[6]++;
6370  }
6371  else if (*chunk == parR[0])
6372  {
6373  synCheck_GBRWLPCP[7]++;
6374  }
6375  chunk++;
6376  i++;
6377  }
6378  free(v);
6379  if (synCheck_GBRWLPCP[0] != 1 || synCheck_GBRWLPCP[1] != 1 || synCheck_GBRWLPCP[2] != 1 ||
6380  synCheck_GBRWLPCP[3] != 1 || synCheck_GBRWLPCP[4] != 1 || synCheck_GBRWLPCP[5] != 5 ||
6381  synCheck_GBRWLPCP[6] != 5 || synCheck_GBRWLPCP[7] != 5)
6382  {
6384  }
6385 
6386  //Parse a key-value set like G(%hu, %hu)
6387 #define GBRWLPARSE(OUT1,OUT2,OFF,IDX) \
6388 { \
6389  char *v = STRDUP(value); \
6390  chunk = v + posCheck_GBRWL[IDX]; \
6391  i = j = k = 0; \
6392  while (chunk != NULL) \
6393  { \
6394  if (*chunk == parL[0] && i == 1+(OFF)) \
6395  { \
6396  j = 1; \
6397  } \
6398  if((OFF) == 1 && *chunk != P[0] && i == 1) \
6399  { \
6400  break; \
6401  } \
6402  if (*chunk == parR[0]) \
6403  { \
6404  k = 1; \
6405  break; \
6406  } \
6407  i++; \
6408  chunk++; \
6409  } \
6410  if (!j || !k) \
6411  { \
6412  free(v); \
6413  return NI_RETCODE_PARAM_INVALID_VALUE; \
6414  } \
6415  subchunk = malloc(i - 1 - (OFF)); \
6416  if (subchunk == NULL) \
6417  { \
6418  free(v); \
6419  return NI_RETCODE_ERROR_MEM_ALOC; \
6420  } \
6421  memcpy(subchunk, v + posCheck_GBRWL[IDX] + 2 + (OFF), i - 2 - (OFF)); \
6422  subchunk[i - 2 - (OFF)] = '\0'; \
6423  char *saveptr = NULL; \
6424  chunk = ni_strtok(subchunk, comma, &saveptr); \
6425  if (chunk != NULL) \
6426  { \
6427  if(atoi(chunk) < 0) \
6428  { \
6429  free(v); \
6430  if(subchunk != NULL){ \
6431  free(subchunk); \
6432  } \
6433  return NI_RETCODE_PARAM_INVALID_VALUE; \
6434  } \
6435  *(OUT1) = atoi(chunk); \
6436  } \
6437  chunk = ni_strtok(NULL, comma, &saveptr); \
6438  if (chunk != NULL) \
6439  { \
6440  if(atoi(chunk) < 0) \
6441  { \
6442  free(v); \
6443  if(subchunk != NULL){ \
6444  free(subchunk); \
6445  } \
6446  return NI_RETCODE_PARAM_INVALID_VALUE; \
6447  } \
6448  *(OUT2) = atoi(chunk); \
6449  } \
6450  free(subchunk); \
6451  free(v); \
6452 }
6453  GBRWLPARSE(&p_enc->HDR10dx0, &p_enc->HDR10dy0, 0, 0);
6454  GBRWLPARSE(&p_enc->HDR10dx1, &p_enc->HDR10dy1, 0, 1);
6455  GBRWLPARSE(&p_enc->HDR10dx2, &p_enc->HDR10dy2, 0, 2);
6456  GBRWLPARSE(&p_enc->HDR10wx, &p_enc->HDR10wy, 1, 3);
6457  GBRWLPARSE(&p_enc->HDR10maxluma, &p_enc->HDR10minluma, 0, 4);
6458  p_enc->HDR10Enable = 1;
6459  }
6461  {
6462  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
6463  {
6465  }
6466  p_enc->lookAheadDepth = atoi(value);
6467  }
6469  {
6470  if (atoi(value) != 0 && atoi(value) != 1)
6471  {
6473  }
6474  p_enc->hrdEnable = atoi(value);
6475  }
6477  {
6478  if ((atoi(value) != 0) && (atoi(value) != 1))
6479  {
6481  }
6482  p_enc->EnableAUD = atoi(value);
6483  }
6485  {
6486  if (atoi(value) != 0 && atoi(value) != 1)
6487  {
6489  }
6490  p_params->cacheRoi = atoi(value);
6491  }
6493  {
6494  if (atoi(value) != 0 && atoi(value) != 1)
6495  {
6497  }
6498  p_enc->long_term_ref_enable = atoi(value);
6499  }
6501  {
6502  p_enc->long_term_ref_interval = atoi(value);
6503  }
6505  {
6506  if (atoi(value) < 1 || atoi(value) > 2)
6507  {
6509  }
6510  p_enc->long_term_ref_count = atoi(value);
6511  }
6513  {
6514  if ((atoi(value) != 0) && (atoi(value) != 1))
6515  {
6517  }
6518  p_enc->EnableRdoQuant = atoi(value);
6519  }
6521  {
6522  if (QUADRA)
6523  {
6525  }
6526 
6527  if ((atoi(value) < 0) || (atoi(value) > 3))
6528  {
6530  }
6531  p_enc->ctbRcMode = atoi(value);
6532  }
6534  {
6535  if (QUADRA)
6536  {
6538  }
6539 
6540  p_enc->gopSize = atoi(value);
6541  }
6543  {
6544  if (QUADRA)
6545  {
6547  }
6548 
6549  if ((atoi(value) != 0) && (atoi(value) != 1))
6550  {
6552  }
6553  p_enc->gopLowdelay = atoi(value);
6554  }
6556  {
6557  if (QUADRA)
6558  {
6560  }
6561  p_enc->gdrDuration = atoi(value);
6562  }
6564  {
6565  p_enc->ltrRefInterval = atoi(value);
6566  }
6568  {
6569  p_enc->ltrRefQpOffset = atoi(value);
6570  }
6572  {
6573  p_enc->ltrFirstGap = atoi(value);
6574  }
6577  {
6578  if ((atoi(value) != 0) && (atoi(value) != 1))
6579  {
6581  }
6582  p_enc->multicoreJointMode = atoi(value);
6583  }
6585  {
6586  if ((atoi(value) < 0) || (atoi(value) > 9))
6587  {
6589  }
6590  p_enc->qlevel = atoi(value);
6591  }
6593  {
6594  if ((atoi(value) > 12) || (atoi(value) < -12))
6595  {
6597  }
6598  p_enc->chromaQpOffset = atoi(value);
6599  }
6600  OPT(NI_ENC_PARAM_TOL_RC_INTER) { p_enc->tolCtbRcInter = (float)atof(value); }
6601  OPT(NI_ENC_PARAM_TOL_RC_INTRA) { p_enc->tolCtbRcIntra = (float)atof(value); }
6603  {
6604  if ((atoi(value) > 300) || (atoi(value) < 1))
6605  {
6607  }
6608  p_enc->bitrateWindow = atoi(value);
6609  }
6611  {
6612  if ((atoi(value) > 2) || (atoi(value) < 0))
6613  {
6615  }
6616  p_enc->blockRCSize = atoi(value);
6617  }
6619  {
6620  if ((atoi(value) > 15) || (atoi(value) < 0))
6621  {
6623  }
6624  p_enc->rcQpDeltaRange = atoi(value);
6625  }
6627  {
6628  if ((atoi(value) > 500) || (atoi(value) < 0))
6629  {
6631  }
6632  p_enc->ctbRowQpStep = atoi(value);
6633  }
6635  {
6636  if ((atoi(value) > 1) || (atoi(value) < 0))
6637  {
6639  }
6640  p_enc->newRcEnable = atoi(value);
6641  }
6643  {
6644  if ((atoi(value) > 1) || (atoi(value) < 0))
6645  {
6647  }
6648  p_enc->inLoopDSRatio = atoi(value);
6649  }
6651  {
6652  COMPARE(value, 22, 0)
6653  p_params->color_primaries = p_enc->colorPrimaries = atoi(value);
6654  p_enc->colorDescPresent = 1;
6655  }
6657  {
6658  COMPARE(value, 18, 0)
6659  p_params->color_transfer_characteristic = p_enc->colorTrc = atoi(value);
6660  p_enc->colorDescPresent = 1;
6661  }
6663  {
6664  COMPARE(value, 14, 0)
6665  p_params->color_space = p_enc->colorSpace = atoi(value);
6666  p_enc->colorDescPresent = 1;
6667  }
6669  {
6670  p_params->sar_num = p_enc->aspectRatioWidth = atoi(value);
6671  }
6673  {
6674  p_params->sar_denom = p_enc->aspectRatioHeight = atoi(value);
6675  }
6677  {
6678  p_params->video_full_range_flag = p_enc->videoFullRange = atoi(value);
6679  }
6681  {
6682  if ((atoi(value) < NI_MIN_KEEP_ALIVE_TIMEOUT) ||
6683  (atoi(value) > NI_MAX_KEEP_ALIVE_TIMEOUT))
6684  {
6686  }
6687  p_enc->keep_alive_timeout = atoi(value);
6688  }
6690  {
6691  if (atoi(value) != 0 && atoi(value) != 1)
6692  {
6694  }
6695  p_params->enable_vfr = atoi(value);
6696  }
6698  {
6699  if (atoi(value) < 0 || atoi(value) > 3)
6700  {
6702  }
6703  p_enc->get_psnr_mode = atoi(value);
6704  }
6706  {
6707  if (atoi(value) < 1)
6708  {
6710  }
6711  p_params->interval_of_psnr = atoi(value);
6712  }
6714  {
6715  if (atoi(value) < 0 || atoi(value) > 1)
6716  {
6718  }
6719  p_enc->get_psnr_mode = atoi(value) + 3;
6720  }
6722  {
6723  if ((atoi(value) != 0) && (atoi(value) != 1))
6724  {
6726  }
6727  p_enc->enable_ssim = atoi(value);
6728  }
6730  {
6731  if ((atoi(value) != 0) && (atoi(value) != 1))
6732  {
6734  }
6735  p_enc->av1_error_resilient_mode = atoi(value);
6736  }
6738  {
6739  if ((atoi(value) != 0) && (atoi(value) != 1))
6740  {
6742  }
6743  p_params->staticMmapThreshold = atoi(value);
6744  }
6746  {
6747  p_enc->temporal_layers_enable = atoi(value);
6748  }
6750  {
6751  if ((atoi(value) != 0) && (atoi(value) != 1))
6752  {
6754  }
6755  p_params->enable_ai_enhance = atoi(value);
6756  }
6758  {
6759  if ((atoi(value) != 0) && (atoi(value) != 1))
6760  {
6762  }
6763  if(p_params->enable_ai_enhance)
6764  {
6765  ni_log(NI_LOG_ERROR, "Cannot set enableAIEnhance and enableHVSPlus at same time, just enableHVSPlus\n");
6766  }
6767  p_params->enable_ai_enhance = (atoi(value) == 1) ? 2 : 0;
6768  }
6770  {
6771  if ((atoi(value) != 0) && (atoi(value) != 1))
6772  {
6774  }
6775  p_params->enable2PassGop = atoi(value);
6776  }
6778  {
6779  if ((atoi(value) != 0) && (atoi(value) != 1) && (atoi(value) != -1))
6780  {
6782  }
6783  p_params->zerocopy_mode = atoi(value);
6784  }
6786  {
6787  if ((atoi(value) == 0) || (atoi(value) > 3))
6788  {
6790  }
6791  p_params->ai_enhance_level = atoi(value);
6792  }
6794  {
6795  if ((atoi(value) == 0) || (atoi(value) > 2))
6796  {
6798  }
6799  p_params->ai_enhance_level = atoi(value);
6800  }
6802  {
6803  if ((atoi(value) < NI_MIN_WIDTH) ||
6804  (atoi(value) > NI_PARAM_MAX_WIDTH))
6805  {
6807  }
6808  p_enc->crop_width = atoi(value);
6809  }
6811  {
6812  if ((atoi(value) < NI_MIN_HEIGHT) ||
6813  (atoi(value) > NI_PARAM_MAX_HEIGHT))
6814  {
6816  }
6817  p_enc->crop_height = atoi(value);
6818  }
6820  {
6821  if ((atoi(value) < 0) ||
6822  (atoi(value) > NI_PARAM_MAX_WIDTH))
6823  {
6825  }
6826  p_enc->hor_offset = atoi(value);
6827  }
6829  {
6830  if ((atoi(value) < 0) ||
6831  (atoi(value) > NI_PARAM_MAX_HEIGHT))
6832  {
6834  }
6835  p_enc->ver_offset = atoi(value);
6836  }
6838  {
6839  if ((atoi(value) > 51) || (atoi(value) < -1))
6840  {
6842  }
6843  p_enc->crfMax = atoi(value);
6844  }
6846  {
6847  if ((atof(value) > 1.0) || (atof(value) < 0.0))
6848  {
6850  }
6851  p_enc->qcomp = (float)atof(value);
6852  }
6854  {
6855  if ((atoi(value) != 0) && (atoi(value) != 1))
6856  {
6858  }
6859  p_enc->noMbtree = atoi(value);
6860  }
6862  {
6863  if ((atoi(value) != 0) && (atoi(value) != 1))
6864  {
6866  }
6867  p_enc->avcc_hvcc = atoi(value);
6868  }
6870  {
6871  if ((atoi(value) != 0) && (atoi(value) != 1))
6872  {
6874  }
6875  p_enc->noHWMultiPassSupport = atoi(value);
6876  }
6878  {
6879  if ((atoi(value) > 10) || (atoi(value) < 1))
6880  {
6882  }
6883  p_enc->cuTreeFactor = atoi(value);
6884  }
6886  {
6887  if ((atof(value) > 10.0) || (atof(value) < 0.01))
6888  {
6890  }
6891  p_enc->ipRatio = (float)atof(value);
6892  }
6894  {
6895  if ((atoi(value) != 0) && (atoi(value) != 1))
6896  {
6898  }
6899  p_enc->enableipRatio = atoi(value);
6900  }
6902  {
6903  if ((atof(value) > 10.0) || (atof(value) < 0.01))
6904  {
6906  }
6907  p_enc->pbRatio = (float)atof(value);
6908  }
6910  {
6911  if ((atof(value) > 1.0) || (atof(value) < 0.1))
6912  {
6914  }
6915  p_enc->cplxDecay = (float)atof(value);
6916  }
6918  {
6919  if ((atoi(value) > 51) || (atoi(value) < -1))
6920  {
6922  }
6923  p_enc->pps_init_qp = atoi(value);
6924  }
6926  {
6927  if (atoi(value) >= NI_DDR_PRIORITY_MAX ||
6928  atoi(value) <= NI_DDR_PRIORITY_NONE)
6929  {
6931  }
6932  p_params->ddr_priority_mode = atoi(value);
6933  }
6935  {
6936  if ((atoi(value) != 0) && (atoi(value) != 1))
6937  {
6939  }
6940  p_enc->bitrateMode = atoi(value);
6941  }
6943  {
6944  if ((atoi(value) > 51) || (atoi(value) < -1))
6945  {
6947  }
6948  p_enc->pass1_qp = atoi(value);
6949  }
6951  {
6952  if (((atof(value) < 0.0) && (atof(value) != -1.0)) ||
6953  (atof(value) > 51.00))
6954  {
6956  }
6957  p_enc->crfFloat = (float)atof(value);
6958  }
6960  {
6961  if ((atoi(value) < 0) || (atoi(value) > 31))
6962  {
6964  }
6965  p_enc->hvsBaseMbComplexity = atoi(value);
6966  }
6968  {
6969  if (atoi(value) < 0 || atoi(value) > 1)
6970  {
6972  }
6973  p_enc->statistic_output_level = atoi(value);
6974  }
6976  {
6977  //Currently only support 6 stillImage detect level
6978  //0-3: no performance drop
6979  //4-6: performance drop
6980  if ((atoi(value) < 0 || atoi(value) > 6))
6981  {
6983  }
6984  p_enc->still_image_detect_level = atoi(value);
6985  }
6987  {
6988  //Currently only support 10 sceneChange detect level
6989  //1-5 : no performance drop
6990  //6-10: performance drop
6991  if ((atoi(value) < 0 || atoi(value) > 10))
6992  {
6994  }
6995  p_enc->scene_change_detect_level = atoi(value);
6996  }
6998  {
6999  if ((atoi(value) != 0) && (atoi(value) != 1))
7000  {
7002  }
7003  p_enc->enable_smooth_crf = atoi(value);
7004  }
7006  {
7007  if ((atoi(value) != 0) && (atoi(value) != 1))
7008  {
7010  }
7011  p_enc->enable_compensate_qp = atoi(value);
7012  }
7014  {
7015  if (atoi(value) < 0 || atoi(value) > 1)
7016  {
7018  }
7019  p_enc->skip_frame_enable = atoi(value);
7020  }
7022  {
7023  if (atoi(value) < 0)
7024  {
7026  }
7027  p_enc->max_consecutive_skip_num = atoi(value);
7028  }
7030  {
7031  if (atoi(value) < 0 || atoi(value) > 255)
7032  {
7034  }
7035  p_enc->skip_frame_interval = atoi(value);
7036  }
7038  {
7039  if (atoi(value) != 0 && atoi(value) != 1)
7040  {
7042  }
7043  p_enc->enable_all_sei_passthru = atoi(value);
7044  }
7046  {
7047  if (atoi(value) <= 0)
7048  {
7050  }
7051  p_enc->iframe_size_ratio = atoi(value);
7052  }
7054  {
7055  if ((atoi(value) < 0 || atoi(value) > 2) &&
7056  atoi(value) != 5 && atoi(value) != 6)
7057  {
7059  }
7060  p_enc->crf_max_iframe_enable = atoi(value);
7061  }
7063  {
7064  p_enc->vbv_min_rate = atoi(value);
7065  }
7067  {
7068  if (atoi(value) != 0 && atoi(value) != 1)
7069  {
7071  }
7072  p_enc->disable_adaptive_buffers = atoi(value);
7073  }
7075  {
7076  if ((atoi(value) != 0) && (atoi(value) != 1))
7077  {
7079  }
7080  p_enc->disableBframeRdoq = atoi(value);
7081  }
7083  {
7084  if ((atof(value) > 1.0) || (atof(value) < 0.0))
7085  {
7087  }
7088  p_enc->forceBframeQpfactor = (float)atof(value);
7089  }
7091  {
7092  if (atoi(value) < 0 || atoi(value) > 2)
7093  {
7095  }
7096  p_enc->tune_bframe_visual = atoi(value);
7097  }
7099  {
7100  if ((atoi(value) != 0) && (atoi(value) != 1))
7101  {
7103  }
7104  p_enc->enable_acq_limit = atoi(value);
7105  }
7107  {
7108  if (atoi(value) < 0 || atoi(value) > 1)
7109  {
7111  }
7112  p_enc->customize_roi_qp_level = atoi(value);
7113  }
7115  {
7117  if (retval != NI_RETCODE_SUCCESS)
7118  {
7119  return retval;
7120  }
7121  // indicate it need to upload roi qp map
7122  p_enc->customize_roi_qp_level += 64;
7123  }
7125  {
7126  if (atoi(value) < 0 || atoi(value) > 2)
7127  {
7129  }
7130  p_enc->motionConstrainedMode = atoi(value);
7131  }
7133  {
7136  {
7138  }
7139  p_enc->encMallocStrategy = atoi(value);
7140  }
7142  {
7143  if (atoi(value) < 1 || atoi(value) > 4)
7144  {
7146  }
7147  p_enc->spatial_layers = atoi(value);
7148  }
7150  {
7151  if (atoi(value) < 0 || atoi(value) > 1)
7152  {
7154  }
7155  p_enc->enable_timecode = atoi(value);
7156  }
7158  {
7159  if ((atoi(value) != 0) && (atoi(value) != 1))
7160  {
7162  }
7163  p_enc->spatial_layers_ref_base_layer = atoi(value);
7164  }
7166  {
7167  if ((atoi(value) != 0) && (atoi(value) != 1))
7168  {
7170  }
7171  p_enc->vbvBufferReencode = atoi(value);
7172  }
7174  {
7175  if (atoi(value)!= 0 && ((atoi(value) > 40 ) || (atoi(value) < 4)))
7176  {
7178  }
7179  p_enc->totalCuTreeDepth = atoi(value);
7180  }
7182  {
7183  if (atoi(value) != 0 && atoi(value) != 1)
7184  {
7186  }
7187  p_enc->adaptiveCuTree = atoi(value);
7188  }
7190  {
7191  if (atoi(value) != 0 && atoi(value) != 1)
7192  {
7194  }
7195  p_enc->preIntraHandling = atoi(value);
7196  }
7198  {
7199  if (atoi(value) != 0 && atoi(value) != 1)
7200  {
7202  }
7203  p_enc->baseLayerOnly = atoi(value);
7204  }
7206  {
7207  if (atoi(value) < 0 || atoi(value) > 100)
7208  {
7210  }
7211  p_enc->pastFrameMaxIntraRatio = atoi(value);
7212  }
7214  {
7215  if (atoi(value) < 0 || atoi(value) > 100)
7216  {
7218  }
7219  p_enc->linkFrameMaxIntraRatio = atoi(value);
7220  }
7222  {
7223  const char delim[2] = ",";
7224  char *chunk;
7225 #ifdef _MSC_VER
7226  char *v = _strdup(value);
7227 #else
7228  char *v = strdup(value);
7229 #endif
7230  char *saveptr = NULL;
7231  i = 0;
7232  chunk = ni_strtok(v, delim, &saveptr);
7233  while (chunk != NULL && i < NI_MAX_SPATIAL_LAYERS)
7234  {
7235  if ((atoi(chunk) > NI_MAX_BITRATE) || (atoi(chunk) < NI_MIN_BITRATE))
7236  {
7237  free(v);
7239  }
7240  p_enc->spatialLayerBitrate[i] = atoi(chunk);
7241  chunk = ni_strtok(NULL, delim, &saveptr);
7242  i++;
7243  }
7244  free(v);
7245  }
7246  else { return NI_RETCODE_PARAM_INVALID_NAME; }
7247 
7248 #undef OPT
7249 #undef OPT2
7250 #undef atobool
7251 #undef atoi
7252 #undef atof
7253 
7254  b_error |= bValueWasNull && !bNameWasBool;
7255 
7256  ni_log(NI_LOG_TRACE, "%s: exit, b_error=%d\n", __func__, b_error);
7257 
7259 }
7260 
7261 #undef atoi
7262 #undef atof
7263 #define atoi(p_str) ni_atoi(p_str, &b_error)
7264 #define atof(p_str) ni_atof(p_str, &b_error)
7265 #define atobool(p_str) (ni_atobool(p_str, &b_error))
7266 
7267 /*!*****************************************************************************
7268  * \brief Set GOP parameter value referenced by name in encoder parameters
7269  * structure
7270  *
7271  * \param[in] p_params Pointer to a user allocated ni_xcoder_params_t
7272  * to find and set a particular parameter
7273  * \param[in] name String represented parameter name to search
7274  * \param[in] value Parameter value to set
7275 *
7276  * \return On success
7277  * NI_RETCODE_SUCCESS
7278  * On failure
7279  * NI_RETCODE_FAILURE
7280  * NI_RETCODE_INVALID_PARAM
7281  ******************************************************************************/
7283  const char *name,
7284  const char *value)
7285 {
7286  bool b_error = false;
7287  bool bNameWasBool = false;
7288  bool bValueWasNull = !value;
7289  ni_encoder_cfg_params_t *p_enc = NULL;
7290  ni_custom_gop_params_t* p_gop = NULL;
7291  char nameBuf[64] = { 0 };
7292 
7293  ni_log(NI_LOG_TRACE, "%s(): enter\n", __func__);
7294 
7295  if (!p_params)
7296  {
7297  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null pointer parameters passed\n",
7298  __func__);
7299  return NI_RETCODE_INVALID_PARAM;
7300  }
7301 
7302  if ( !name )
7303  {
7304  ni_log(NI_LOG_ERROR, "ERROR: %s(): Null name pointer parameters passed\n",
7305  __func__);
7307  }
7308  p_enc = &p_params->cfg_enc_params;
7309  p_gop = &p_enc->custom_gop_params;
7310 
7311  // skip -- prefix if provided
7312  if (name[0] == '-' && name[1] == '-')
7313  {
7314  name += 2;
7315  }
7316 
7317  // s/_/-/g
7318  if (strlen(name) + 1 < sizeof(nameBuf) && strchr(name, '_'))
7319  {
7320  char* c;
7321  strcpy(nameBuf, name);
7322  while ((c = strchr(nameBuf, '_')) != 0)
7323  {
7324  *c = '-';
7325  }
7326  name = nameBuf;
7327  }
7328 
7329  if (!value)
7330  {
7331  value = "true";
7332  }
7333  else if (value[0] == '=')
7334  {
7335  value++;
7336  }
7337 
7338 #if defined(_MSC_VER)
7339 #define OPT(STR) else if (!_stricmp(name, STR))
7340 #else
7341 #define OPT(STR) else if (!strcasecmp(name, STR))
7342 #endif
7343  if (0); // suppress cppcheck
7345  {
7346  if (atoi(value) > NI_MAX_GOP_SIZE)
7347  {
7349  }
7350  if (atoi(value) < NI_MIN_GOP_SIZE)
7351  {
7353  }
7354  p_gop->custom_gop_size = atoi(value);
7355  }
7356 
7357 #ifndef QUADRA
7359  {
7360  p_gop->pic_param[0].pic_type = atoi(value);
7361  }
7363  {
7364  p_gop->pic_param[0].poc_offset = atoi(value);
7365  }
7366  OPT(NI_ENC_GOP_PARAMS_G0_PIC_QP)
7367  {
7368  p_gop->pic_param[0].pic_qp = atoi(value);
7369  }
7370  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC_L0)
7371  {
7372  p_gop->pic_param[0].num_ref_pic_L0 = atoi(value);
7373  }
7374  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L0)
7375  {
7376  p_gop->pic_param[0].ref_poc_L0 = atoi(value);
7377  }
7378  OPT(NI_ENC_GOP_PARAMS_G0_NUM_REF_POC_L1)
7379  {
7380  p_gop->pic_param[0].ref_poc_L1 = atoi(value);
7381  }
7383  {
7384  p_gop->pic_param[0].temporal_id = atoi(value);
7385  }
7386 
7388  {
7389  p_gop->pic_param[1].pic_type = atoi(value);
7390  }
7392  {
7393  p_gop->pic_param[1].poc_offset = atoi(value);
7394  }
7395  OPT(NI_ENC_GOP_PARAMS_G1_PIC_QP)
7396  {
7397  p_gop->pic_param[1].pic_qp = atoi(value);
7398  }
7399  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC_L0)
7400  {
7401  p_gop->pic_param[1].num_ref_pic_L0 = atoi(value);
7402  }
7403  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L0)
7404  {
7405  p_gop->pic_param[1].ref_poc_L0 = atoi(value);
7406  }
7407  OPT(NI_ENC_GOP_PARAMS_G1_NUM_REF_POC_L1)
7408  {
7409  p_gop->pic_param[1].ref_poc_L1 = atoi(value);
7410  }
7412  {
7413  p_gop->pic_param[1].temporal_id = atoi(value);
7414  }
7415 
7417  {
7418  p_gop->pic_param[2].pic_type = atoi(value);
7419  }
7421  {
7422  p_gop->pic_param[2].poc_offset = atoi(value);
7423  }
7424  OPT(NI_ENC_GOP_PARAMS_G2_PIC_QP)
7425  {
7426  p_gop->pic_param[2].pic_qp = atoi(value);
7427  }
7428  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC_L0)
7429  {
7430  p_gop->pic_param[2].num_ref_pic_L0 = atoi(value);
7431  }
7432  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L0)
7433  {
7434  p_gop->pic_param[2].ref_poc_L0 = atoi(value);
7435  }
7436  OPT(NI_ENC_GOP_PARAMS_G2_NUM_REF_POC_L1)
7437  {
7438  p_gop->pic_param[2].ref_poc_L1 = atoi(value);
7439  }
7441  {
7442  p_gop->pic_param[2].temporal_id = atoi(value);
7443  }
7444 
7446  {
7447  p_gop->pic_param[3].pic_type = atoi(value);
7448  }
7450  {
7451  p_gop->pic_param[3].poc_offset = atoi(value);
7452  }
7453  OPT(NI_ENC_GOP_PARAMS_G3_PIC_QP)
7454  {
7455  p_gop->pic_param[3].pic_qp = atoi(value);
7456  }
7457  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC_L0)
7458  {
7459  p_gop->pic_param[3].num_ref_pic_L0 = atoi(value);
7460  }
7461  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L0)
7462  {
7463  p_gop->pic_param[3].ref_poc_L0 = atoi(value);
7464  }
7465  OPT(NI_ENC_GOP_PARAMS_G3_NUM_REF_POC_L1)
7466  {
7467  p_gop->pic_param[3].ref_poc_L1 = atoi(value);
7468  }
7470  {
7471  p_gop->pic_param[3].temporal_id = atoi(value);
7472  }
7473 
7475  {
7476  p_gop->pic_param[4].pic_type = atoi(value);
7477  }
7479  {
7480  p_gop->pic_param[4].poc_offset = atoi(value);
7481  }
7482  OPT(NI_ENC_GOP_PARAMS_G4_PIC_QP)
7483  {
7484  p_gop->pic_param[4].pic_qp = atoi(value);
7485  }
7486  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC_L0)
7487  {
7488  p_gop->pic_param[4].num_ref_pic_L0 = atoi(value);
7489  }
7490  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L0)
7491  {
7492  p_gop->pic_param[4].ref_poc_L0 = atoi(value);
7493  }
7494  OPT(NI_ENC_GOP_PARAMS_G4_NUM_REF_POC_L1)
7495  {
7496  p_gop->pic_param[4].ref_poc_L1 = atoi(value);
7497  }
7499  {
7500  p_gop->pic_param[4].temporal_id = atoi(value);
7501  }
7502 
7504  {
7505  p_gop->pic_param[5].pic_type = atoi(value);
7506  }
7508  {
7509  p_gop->pic_param[5].poc_offset = atoi(value);
7510  }
7511  OPT(NI_ENC_GOP_PARAMS_G5_PIC_QP)
7512  {
7513  p_gop->pic_param[5].pic_qp = atoi(value);
7514  }
7515  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC_L0)
7516  {
7517  p_gop->pic_param[5].num_ref_pic_L0 = atoi(value);
7518  }
7519  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L0)
7520  {
7521  p_gop->pic_param[5].ref_poc_L0 = atoi(value);
7522  }
7523  OPT(NI_ENC_GOP_PARAMS_G5_NUM_REF_POC_L1)
7524  {
7525  p_gop->pic_param[5].ref_poc_L1 = atoi(value);
7526  }
7528  {
7529  p_gop->pic_param[5].temporal_id = atoi(value);
7530  }
7531 
7533  {
7534  p_gop->pic_param[6].pic_type = atoi(value);
7535  }
7537  {
7538  p_gop->pic_param[6].poc_offset = atoi(value);
7539  }
7540  OPT(NI_ENC_GOP_PARAMS_G6_PIC_QP)
7541  {
7542  p_gop->pic_param[6].pic_qp = atoi(value);
7543  }
7544  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC_L0)
7545  {
7546  p_gop->pic_param[6].num_ref_pic_L0 = atoi(value);
7547  }
7548  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L0)
7549  {
7550  p_gop->pic_param[6].ref_poc_L0 = atoi(value);
7551  }
7552  OPT(NI_ENC_GOP_PARAMS_G6_NUM_REF_POC_L1)
7553  {
7554  p_gop->pic_param[6].ref_poc_L1 = atoi(value);
7555  }
7557  {
7558  p_gop->pic_param[6].temporal_id = atoi(value);
7559  }
7560 
7562  {
7563  p_gop->pic_param[7].pic_type = atoi(value);
7564  }
7566  {
7567  p_gop->pic_param[7].poc_offset = atoi(value);
7568  }
7569  OPT(NI_ENC_GOP_PARAMS_G7_PIC_QP)
7570  {
7571  p_gop->pic_param[7].pic_qp = atoi(value);
7572  }
7573  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC_L0)
7574  {
7575  p_gop->pic_param[7].num_ref_pic_L0 = atoi(value);
7576  }
7577  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L0)
7578  {
7579  p_gop->pic_param[7].ref_poc_L0 = atoi(value);
7580  }
7581  OPT(NI_ENC_GOP_PARAMS_G7_NUM_REF_POC_L1)
7582  {
7583  p_gop->pic_param[7].ref_poc_L1 = atoi(value);
7584  }
7586  {
7587  p_gop->pic_param[7].temporal_id = atoi(value);
7588  }
7589  else
7590  {
7591  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
7593  }
7594 #else
7596  {
7597  p_gop->pic_param[0].poc_offset = atoi(value);
7598  }
7600  {
7601  p_gop->pic_param[0].qp_offset = atoi(value);
7602  }
7603  /*
7604  OPT(NI_ENC_GOP_PARAMS_G0_QP_FACTOR)
7605  {
7606  p_gop->pic_param[0].qp_factor = atof(value);
7607  }
7608  */
7610  {
7611  p_gop->pic_param[0].temporal_id = atoi(value);
7612  }
7614  {
7615  p_gop->pic_param[0].pic_type = atoi(value);
7616  }
7618  {
7619  p_gop->pic_param[0].num_ref_pics = atoi(value);
7620  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 num_ref_pics %d\n", __func__, p_gop->pic_param[0].num_ref_pics);
7621  }
7623  {
7624  p_gop->pic_param[0].rps[0].ref_pic = atoi(value);
7625  //ni_log(NI_LOG_DEBUG, "%s(): Frame1 %d rps[0].ref_pic %d\n", __func__, p_gop->pic_param[0].rps[0].ref_pic);
7626  }
7628  {
7629  p_gop->pic_param[0].rps[0].ref_pic_used = atoi(value);
7630  //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);
7631  }
7633  {
7634  p_gop->pic_param[0].rps[1].ref_pic = atoi(value);
7635  }
7637  {
7638  p_gop->pic_param[0].rps[1].ref_pic_used = atoi(value);
7639  }
7641  {
7642  p_gop->pic_param[0].rps[2].ref_pic = atoi(value);
7643  }
7645  {
7646  p_gop->pic_param[0].rps[2].ref_pic_used = atoi(value);
7647  }
7649  {
7650  p_gop->pic_param[0].rps[3].ref_pic = atoi(value);
7651  }
7653  {
7654  p_gop->pic_param[0].rps[3].ref_pic_used = atoi(value);
7655  }
7656 
7658  {
7659  p_gop->pic_param[1].poc_offset = atoi(value);
7660  }
7662  {
7663  p_gop->pic_param[1].qp_offset = atoi(value);
7664  }
7665  /*
7666  OPT(NI_ENC_GOP_PARAMS_G1_QP_FACTOR)
7667  {
7668  p_gop->pic_param[1].qp_factor = atof(value);
7669  }
7670  */
7672  {
7673  p_gop->pic_param[1].temporal_id = atoi(value);
7674  }
7676  {
7677  p_gop->pic_param[1].pic_type = atoi(value);
7678  }
7680  {
7681  p_gop->pic_param[1].num_ref_pics = atoi(value);
7682  }
7684  {
7685  p_gop->pic_param[1].rps[0].ref_pic = atoi(value);
7686  }
7688  {
7689  p_gop->pic_param[1].rps[0].ref_pic_used = atoi(value);
7690  }
7692  {
7693  p_gop->pic_param[1].rps[1].ref_pic = atoi(value);
7694  }
7696  {
7697  p_gop->pic_param[1].rps[1].ref_pic_used = atoi(value);
7698  }
7700  {
7701  p_gop->pic_param[1].rps[2].ref_pic = atoi(value);
7702  }
7704  {
7705  p_gop->pic_param[1].rps[2].ref_pic_used = atoi(value);
7706  }
7708  {
7709  p_gop->pic_param[1].rps[3].ref_pic = atoi(value);
7710  }
7712  {
7713  p_gop->pic_param[1].rps[3].ref_pic_used = atoi(value);
7714  }
7715 
7717  {
7718  p_gop->pic_param[2].poc_offset = atoi(value);
7719  }
7721  {
7722  p_gop->pic_param[2].qp_offset = atoi(value);
7723  }
7724  /*
7725  OPT(NI_ENC_GOP_PARAMS_G2_QP_FACTOR)
7726  {
7727  p_gop->pic_param[2].qp_factor = atof(value);
7728  }
7729  */
7731  {
7732  p_gop->pic_param[2].temporal_id = atoi(value);
7733  }
7735  {
7736  p_gop->pic_param[2].pic_type = atoi(value);
7737  }
7739  {
7740  p_gop->pic_param[2].num_ref_pics = atoi(value);
7741  }
7743  {
7744  p_gop->pic_param[2].rps[0].ref_pic = atoi(value);
7745  }
7747  {
7748  p_gop->pic_param[2].rps[0].ref_pic_used = atoi(value);
7749  }
7751  {
7752  p_gop->pic_param[2].rps[1].ref_pic = atoi(value);
7753  }
7755  {
7756  p_gop->pic_param[2].rps[1].ref_pic_used = atoi(value);
7757  }
7759  {
7760  p_gop->pic_param[2].rps[2].ref_pic = atoi(value);
7761  }
7763  {
7764  p_gop->pic_param[2].rps[2].ref_pic_used = atoi(value);
7765  }
7767  {
7768  p_gop->pic_param[2].rps[3].ref_pic = atoi(value);
7769  }
7771  {
7772  p_gop->pic_param[2].rps[3].ref_pic_used = atoi(value);
7773  }
7774 
7776  {
7777  p_gop->pic_param[3].poc_offset = atoi(value);
7778  }
7780  {
7781  p_gop->pic_param[3].qp_offset = atoi(value);
7782  }
7783  /*
7784  OPT(NI_ENC_GOP_PARAMS_G3_QP_FACTOR)
7785  {
7786  p_gop->pic_param[3].qp_factor = atof(value);
7787  }
7788  */
7790  {
7791  p_gop->pic_param[3].temporal_id = atoi(value);
7792  }
7794  {
7795  p_gop->pic_param[3].pic_type = atoi(value);
7796  }
7798  {
7799  p_gop->pic_param[3].num_ref_pics = atoi(value);
7800  }
7802  {
7803  p_gop->pic_param[3].rps[0].ref_pic = atoi(value);
7804  }
7806  {
7807  p_gop->pic_param[3].rps[0].ref_pic_used = atoi(value);
7808  }
7810  {
7811  p_gop->pic_param[3].rps[1].ref_pic = atoi(value);
7812  }
7814  {
7815  p_gop->pic_param[3].rps[1].ref_pic_used = atoi(value);
7816  }
7818  {
7819  p_gop->pic_param[3].rps[2].ref_pic = atoi(value);
7820  }
7822  {
7823  p_gop->pic_param[3].rps[2].ref_pic_used = atoi(value);
7824  }
7826  {
7827  p_gop->pic_param[3].rps[3].ref_pic = atoi(value);
7828  }
7830  {
7831  p_gop->pic_param[3].rps[3].ref_pic_used = atoi(value);
7832  }
7833 
7835  {
7836  p_gop->pic_param[4].poc_offset = atoi(value);
7837  }
7839  {
7840  p_gop->pic_param[4].qp_offset = atoi(value);
7841  }
7842  /*
7843  OPT(NI_ENC_GOP_PARAMS_G4_QP_FACTOR)
7844  {
7845  p_gop->pic_param[4].qp_factor = atof(value);
7846  }
7847  */
7849  {
7850  p_gop->pic_param[4].temporal_id = atoi(value);
7851  }
7853  {
7854  p_gop->pic_param[4].pic_type = atoi(value);
7855  }
7857  {
7858  p_gop->pic_param[4].num_ref_pics = atoi(value);
7859  }
7861  {
7862  p_gop->pic_param[4].rps[0].ref_pic = atoi(value);
7863  }
7865  {
7866  p_gop->pic_param[4].rps[0].ref_pic_used = atoi(value);
7867  }
7869  {
7870  p_gop->pic_param[4].rps[1].ref_pic = atoi(value);
7871  }
7873  {
7874  p_gop->pic_param[4].rps[1].ref_pic_used = atoi(value);
7875  }
7877  {
7878  p_gop->pic_param[4].rps[2].ref_pic = atoi(value);
7879  }
7881  {
7882  p_gop->pic_param[4].rps[2].ref_pic_used = atoi(value);
7883  }
7885  {
7886  p_gop->pic_param[4].rps[3].ref_pic = atoi(value);
7887  }
7889  {
7890  p_gop->pic_param[4].rps[3].ref_pic_used = atoi(value);
7891  }
7892 
7894  {
7895  p_gop->pic_param[5].poc_offset = atoi(value);
7896  }
7898  {
7899  p_gop->pic_param[5].qp_offset = atoi(value);
7900  }
7901  /*
7902  OPT(NI_ENC_GOP_PARAMS_G5_QP_FACTOR)
7903  {
7904  p_gop->pic_param[5].qp_factor = atof(value);
7905  }
7906  */
7908  {
7909  p_gop->pic_param[5].temporal_id = atoi(value);
7910  }
7912  {
7913  p_gop->pic_param[5].pic_type = atoi(value);
7914  }
7916  {
7917  p_gop->pic_param[5].num_ref_pics = atoi(value);
7918  }
7920  {
7921  p_gop->pic_param[5].rps[0].ref_pic = atoi(value);
7922  }
7924  {
7925  p_gop->pic_param[5].rps[0].ref_pic_used = atoi(value);
7926  }
7928  {
7929  p_gop->pic_param[5].rps[1].ref_pic = atoi(value);
7930  }
7932  {
7933  p_gop->pic_param[5].rps[1].ref_pic_used = atoi(value);
7934  }
7936  {
7937  p_gop->pic_param[5].rps[2].ref_pic = atoi(value);
7938  }
7940  {
7941  p_gop->pic_param[5].rps[2].ref_pic_used = atoi(value);
7942  }
7944  {
7945  p_gop->pic_param[5].rps[3].ref_pic = atoi(value);
7946  }
7948  {
7949  p_gop->pic_param[5].rps[3].ref_pic_used = atoi(value);
7950  }
7951 
7953  {
7954  p_gop->pic_param[6].poc_offset = atoi(value);
7955  }
7957  {
7958  p_gop->pic_param[6].qp_offset = atoi(value);
7959  }
7960  /*
7961  OPT(NI_ENC_GOP_PARAMS_G6_QP_FACTOR)
7962  {
7963  p_gop->pic_param[6].qp_factor = atof(value);
7964  }
7965  */
7967  {
7968  p_gop->pic_param[6].temporal_id = atoi(value);
7969  }
7971  {
7972  p_gop->pic_param[6].pic_type = atoi(value);
7973  }
7975  {
7976  p_gop->pic_param[6].num_ref_pics = atoi(value);
7977  }
7979  {
7980  p_gop->pic_param[6].rps[0].ref_pic = atoi(value);
7981  }
7983  {
7984  p_gop->pic_param[6].rps[0].ref_pic_used = atoi(value);
7985  }
7987  {
7988  p_gop->pic_param[6].rps[1].ref_pic = atoi(value);
7989  }
7991  {
7992  p_gop->pic_param[6].rps[1].ref_pic_used = atoi(value);
7993  }
7995  {
7996  p_gop->pic_param[6].rps[2].ref_pic = atoi(value);
7997  }
7999  {
8000  p_gop->pic_param[6].rps[2].ref_pic_used = atoi(value);
8001  }
8003  {
8004  p_gop->pic_param[6].rps[3].ref_pic = atoi(value);
8005  }
8007  {
8008  p_gop->pic_param[6].rps[3].ref_pic_used = atoi(value);
8009  }
8010 
8012  {
8013  p_gop->pic_param[7].poc_offset = atoi(value);
8014  }
8016  {
8017  p_gop->pic_param[7].qp_offset = atoi(value);
8018  }
8019  /*
8020  OPT(NI_ENC_GOP_PARAMS_G7_QP_FACTOR)
8021  {
8022  p_gop->pic_param[7].qp_factor = atof(value);
8023  }
8024  */
8026  {
8027  p_gop->pic_param[7].temporal_id = atoi(value);
8028  }
8030  {
8031  p_gop->pic_param[7].pic_type = atoi(value);
8032  }
8034  {
8035  p_gop->pic_param[7].num_ref_pics = atoi(value);
8036  }
8038  {
8039  p_gop->pic_param[7].rps[0].ref_pic = atoi(value);
8040  }
8042  {
8043  p_gop->pic_param[7].rps[0].ref_pic_used = atoi(value);
8044  }
8046  {
8047  p_gop->pic_param[7].rps[1].ref_pic = atoi(value);
8048  }
8050  {
8051  p_gop->pic_param[7].rps[1].ref_pic_used = atoi(value);
8052  }
8054  {
8055  p_gop->pic_param[7].rps[2].ref_pic = atoi(value);
8056  }
8058  {
8059  p_gop->pic_param[7].rps[2].ref_pic_used = atoi(value);
8060  }
8062  {
8063  p_gop->pic_param[7].rps[3].ref_pic = atoi(value);
8064  }
8066  {
8067  p_gop->pic_param[7].rps[3].ref_pic_used = atoi(value);
8068  }
8069  else
8070  {
8071  ni_log(NI_LOG_ERROR, "%s(): Invalid parameter name passed\n", __func__);
8073  }
8074 #endif
8075 
8076 #undef OPT
8077 #undef OPT2
8078 #undef atobool
8079 #undef atoi
8080 #undef atof
8081 
8082  b_error |= bValueWasNull && !bNameWasBool;
8083 
8084  ni_log(NI_LOG_TRACE, "%s(): exit, b_error=%d\n", __func__, b_error);
8085 
8087 }
8088 
8089 /*!*****************************************************************************
8090 * \brief Copy existing decoding session params for hw frame usage
8091 *
8092 * \param[in] src_p_ctx Pointer to a caller allocated source session context
8093 * \param[in] dst_p_ctx Pointer to a caller allocated destination session
8094 * context
8095 * \return On success
8096 * NI_RETCODE_SUCCESS
8097 * On failure
8098 * NI_RETCODE_INVALID_PARAM
8099 ******************************************************************************/
8101 {
8102  return ni_decoder_session_copy_internal(src_p_ctx, dst_p_ctx);
8103 }
8104 
8105 /*!*****************************************************************************
8106 * \brief Read data from the device
8107 * If device_type is NI_DEVICE_TYPE_DECODER reads data hwdesc from
8108 * decoder
8109 * If device_type is NI_DEVICE_TYPE_SCALER reads data hwdesc from
8110 * scaler
8111 *
8112 * \param[in] p_ctx Pointer to a caller allocated
8113 * ni_session_context_t struct
8114 * \param[in] p_data Pointer to a caller allocated
8115 * ni_session_data_io_t struct which contains either a
8116 * ni_frame_t data frame or ni_packet_t data packet to
8117 * send
8118 * \param[in] device_type NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER
8119 * If NI_DEVICE_TYPE_DECODER or NI_DEVICE_TYPE_SCALER is specified,
8120 * hw descriptor info will be stored in p_data ni_frame
8121 * \return On success
8122 * Total number of bytes read
8123 * On failure
8124 * NI_RETCODE_INVALID_PARAM
8125 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8126 * NI_RETCODE_ERROR_INVALID_SESSION
8127 ******************************************************************************/
8129 {
8130  ni_log2(p_ctx, NI_LOG_DEBUG, "%s start\n", __func__);
8132  if ((!p_ctx) || (!p_data))
8133  {
8134  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8135  __func__);
8136  return NI_RETCODE_INVALID_PARAM;
8137  }
8138 
8139  // Here check if keep alive thread is closed.
8140 #ifdef _WIN32
8141  if (p_ctx->keep_alive_thread.handle && p_ctx->keep_alive_thread_args &&
8143 #else
8144  if (p_ctx->keep_alive_thread && p_ctx->keep_alive_thread_args &&
8146 #endif
8147  {
8148  ni_log2(p_ctx, NI_LOG_ERROR,
8149  "ERROR: %s() keep alive thread has been closed, "
8150  "hw:%d, session:%d\n",
8151  __func__, p_ctx->hw_id, p_ctx->session_id);
8153  }
8154 
8155  ni_pthread_mutex_lock(&p_ctx->mutex);
8156  // In close state, let the close process execute first.
8157  if (p_ctx->xcoder_state & NI_XCODER_CLOSE_STATE)
8158  {
8159  ni_log2(p_ctx, NI_LOG_DEBUG, "%s close state, return\n", __func__);
8160  ni_pthread_mutex_unlock(&p_ctx->mutex);
8161  ni_usleep(100);
8163  }
8165  ni_pthread_mutex_unlock(&p_ctx->mutex);
8166 
8167  switch (device_type)
8168  {
8170  {
8171  int seq_change_read_count = 0;
8172  p_data->data.frame.src_codec = p_ctx->codec_format;
8173  for (;;)
8174  {
8175  //retval = ni_decoder_session_read(p_ctx, &(p_data->data.frame));
8176  retval = ni_decoder_session_read_desc(p_ctx, &(p_data->data.frame));
8177  // check resolution change only after initial setting obtained
8178  // p_data->data.frame.video_width is picture width and will be 32-align
8179  // adjusted to frame size; p_data->data.frame.video_height is the same as
8180  // frame size, then compare them to saved one for resolution checking
8181  //
8182  uint32_t aligned_width;
8183  if(QUADRA)
8184  {
8185  aligned_width = ((((p_data->data.frame.video_width * p_ctx->bit_depth_factor) + 127) / 128) * 128);
8186  }
8187  else
8188  {
8189  aligned_width = ((p_data->data.frame.video_width + 31) / 32) * 32;
8190  }
8191 
8192  ni_log2(p_ctx, NI_LOG_DEBUG,
8193  "FNum %" PRIu64
8194  ", DFVWxDFVH %u x %u, AlWid %u, AVW x AVH %u x %u\n",
8195  p_ctx->frame_num, p_data->data.frame.video_width,
8196  p_data->data.frame.video_height, aligned_width,
8197  p_ctx->active_video_width, p_ctx->active_video_height);
8198 
8199  if (0 == retval && seq_change_read_count)
8200  {
8201  ni_log2(p_ctx, NI_LOG_DEBUG, "%s (decoder): seq change NO data, next time.\n",
8202  __func__);
8203  p_ctx->active_video_width = 0;
8204  p_ctx->active_video_height = 0;
8205  p_ctx->actual_video_width = 0;
8206  break;
8207  }
8208  else if (retval < 0)
8209  {
8210  ni_log2(p_ctx, NI_LOG_ERROR, "%s (decoder): failure ret %d, return ..\n",
8211  __func__, retval);
8212  break;
8213  }
8214  // aligned_width may equal to active_video_width if bit depth and width
8215  // are changed at the same time. So, check video_width != actual_video_width.
8216  else if (p_ctx->frame_num && (p_ctx->pixel_format_changed ||
8217  (p_data->data.frame.video_width &&
8218  p_data->data.frame.video_height &&
8219  (aligned_width != p_ctx->active_video_width ||
8220  p_data->data.frame.video_height != p_ctx->active_video_height))))
8221  {
8222  ni_log2(
8223  p_ctx, NI_LOG_DEBUG,
8224  "%s (decoder): resolution change, frame size %ux%u -> %ux%u, "
8225  "width %u bit %d, pix_fromat_changed %d, actual_video_width %d, continue read ...\n",
8226  __func__, p_ctx->active_video_width, p_ctx->active_video_height,
8227  aligned_width, p_data->data.frame.video_height,
8228  p_data->data.frame.video_width, p_ctx->bit_depth_factor,
8229  p_ctx->pixel_format_changed, p_ctx->actual_video_width);
8230  // reset active video resolution to 0 so it can be queried in the re-read
8231  p_ctx->active_video_width = 0;
8232  p_ctx->active_video_height = 0;
8233  p_ctx->actual_video_width = 0;
8234  seq_change_read_count++;
8235  //break;
8236  }
8237  else
8238  {
8239  break;
8240  }
8241  }
8242  break;
8243  }
8245  {
8246  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Encoder has no hwdesc to read\n");
8247  return NI_RETCODE_INVALID_PARAM;
8248  }
8249 
8250  case NI_DEVICE_TYPE_SCALER:
8251  {
8252  retval = ni_scaler_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8253  break;
8254  }
8255 
8256  case NI_DEVICE_TYPE_AI:
8257  {
8258  retval = ni_ai_session_read_hwdesc(p_ctx, &(p_data->data.frame));
8259  break;
8260  }
8261 
8262  default:
8263  {
8264  retval = NI_RETCODE_INVALID_PARAM;
8265  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unrecognized device type: %d",
8266  __func__, device_type);
8267  break;
8268  }
8269  }
8270 
8271  ni_pthread_mutex_lock(&p_ctx->mutex);
8273  ni_pthread_mutex_unlock(&p_ctx->mutex);
8274 
8275  return retval;
8276 }
8277 
8278 /*!*****************************************************************************
8279 * \brief Reads YUV data from hw descriptor stored location on device
8280 *
8281 * \param[in] p_ctx Pointer to a caller allocated
8282 * ni_session_context_t struct
8283 * \param[in] p_data Pointer to a caller allocated
8284 * ni_session_data_io_t struct which contains either a
8285 * ni_frame_t data frame or ni_packet_t data packet to
8286 * send
8287 * \param[in] hwdesc HW descriptor to find frame in XCODER
8288 * \return On success
8289 * Total number of bytes read
8290 * On failure
8291 * NI_RETCODE_INVALID_PARAM
8292 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8293 * NI_RETCODE_ERROR_INVALID_SESSION
8294 *******************************************************************************/
8296 {
8298  if ((!hwdesc) || (!p_data))
8299  {
8300  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8301  __func__);
8302  return NI_RETCODE_INVALID_PARAM;
8303  }
8304 
8305  /* download by frameidx */
8306  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rd") >= 0))
8307  {
8308  if(hwdesc->ui16FrameIdx == 0)
8309  {
8310  ni_log(NI_LOG_ERROR, "%s(): Invaild frame index\n", __func__);
8311  return NI_RETCODE_INVALID_PARAM;
8312  }
8313  retval = ni_hwdownload_by_frame_idx(hwdesc, &(p_data->data.frame), p_ctx->is_auto_dl);
8314  } else {
8315  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
8316  {
8317  if (p_ctx->pext_mutex == &(p_ctx->mutex))
8318  {
8319  ni_log(NI_LOG_ERROR, "ERROR %s(): Invalid session\n",
8320  __func__);
8322  }
8323  }
8324 
8326  bool use_external_mutex = false;
8327  uint32_t orig_session_id = p_ctx->session_id;
8328  ni_device_handle_t orig_blk_io_handle = p_ctx->blk_io_handle;
8329  uint32_t orig_codec_format = p_ctx->codec_format;
8330  int orig_bit_depth_factor = p_ctx->bit_depth_factor;
8331  int orig_hw_action = p_ctx->hw_action;
8332 
8333  ni_pthread_mutex_t *p_ctx_mutex = &(p_ctx->mutex);
8334  if ((p_ctx_mutex != p_ctx->pext_mutex) ||
8337  "6r8") < 0)
8338  {
8339  use_external_mutex = true;
8340  p_ctx->session_id = hwdesc->ui16session_ID;
8341  p_ctx->blk_io_handle = (ni_device_handle_t)(int64_t)hwdesc->device_handle;
8342  p_ctx->codec_format = NI_CODEC_FORMAT_H264; //unused
8343  p_ctx->bit_depth_factor = (int)hwdesc->bit_depth;
8345  }
8346 
8348 
8349  retval = ni_hwdownload_session_read(p_ctx, &(p_data->data.frame), hwdesc); //cut me down as needed
8350 
8352  if (use_external_mutex)
8353  {
8354  p_ctx->session_id = orig_session_id;
8355  p_ctx->blk_io_handle = orig_blk_io_handle;
8356  p_ctx->codec_format = orig_codec_format;
8357  p_ctx->bit_depth_factor = orig_bit_depth_factor;
8358  p_ctx->hw_action = orig_hw_action;
8359  }
8361  }
8362 
8363  return retval;
8364 }
8365 
8366 /*!*****************************************************************************
8367 * \brief Query the session if a buffer is available
8368 *
8369 * \param[in] p_ctx Pointer to a caller allocated
8370 * ni_session_context_t struct
8371 * [in] device_type Quadra device type
8372 *
8373 * \return On success
8374 * NI_RETCODE_SUCCESS
8375 * On failure
8376 * NI_RETCODE_INVALID_PARAM
8377 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8378 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8379 * NI_RETCODE_ERROR_INVALID_SESSION
8380 *******************************************************************************/
8382  ni_device_type_t device_type)
8383 {
8385 
8386  if (!p_ctx)
8387  {
8388  ni_log(NI_LOG_ERROR, "ERROR: No session\n");
8389  return NI_RETCODE_INVALID_PARAM;
8390  }
8391 
8392  if (ni_cmp_fw_api_ver(
8393  (char *) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX],
8394  "6rt") < 0)
8395  {
8396  ni_log2(p_ctx, NI_LOG_DEBUG,
8397  "%s function not supported in FW API version < 6rt\n",
8398  __func__);
8400  }
8401 
8402  switch (device_type)
8403  {
8404  case NI_DEVICE_TYPE_UPLOAD:
8405  ni_pthread_mutex_lock(&p_ctx->mutex);
8407 
8409 
8411  ni_pthread_mutex_unlock(&p_ctx->mutex);
8412  break;
8413 
8414  case NI_DEVICE_TYPE_SCALER:
8415  ni_pthread_mutex_lock(&p_ctx->mutex);
8417 
8418  retval = ni_scaler_session_query_buffer_avail(p_ctx);
8419 
8421  ni_pthread_mutex_unlock(&p_ctx->mutex);
8422  break;
8423 
8424  default:
8425  break;
8426  }
8427 
8428  return retval;
8429 }
8430 
8431 /*!*****************************************************************************
8432 * \brief Sends raw YUV input to uploader instance and retrieves a HW descriptor
8433 * to represent it
8434 *
8435 * \param[in] p_ctx Pointer to a caller allocated
8436 * ni_session_context_t struct
8437 * \param[in] p_src_data Pointer to a caller allocated
8438 * ni_session_data_io_t struct which contains a
8439 * ni_frame_t data frame to send to uploader
8440 * \param[out] hwdesc HW descriptor to find frame in XCODER
8441 * \return On success
8442 * Total number of bytes read
8443 * On failure
8444 * NI_RETCODE_INVALID_PARAM
8445 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8446 * NI_RETCODE_ERROR_INVALID_SESSION
8447 *******************************************************************************/
8449 {
8451  if ((!hwdesc) || (!p_src_data))
8452  {
8453  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8454  __func__);
8455  return NI_RETCODE_INVALID_PARAM;
8456  }
8457  ni_pthread_mutex_lock(&p_ctx->mutex);
8459 
8460  retval = ni_hwupload_session_write(p_ctx, &p_src_data->data.frame, hwdesc);
8461 
8463  ni_pthread_mutex_unlock(&p_ctx->mutex);
8464 
8465  return retval;
8466 }
8467 
8468 /*!*****************************************************************************
8469 * \brief Allocate memory for the hwDescriptor buffer based on provided
8470 * parameters taking into account pic size and extra data.
8471 *
8472 * \param[in] p_frame Pointer to a caller allocated ni_frame_t struct
8473 *
8474 * \param[in] video_width Width of the video frame
8475 * \param[in] video_height Height of the video frame
8476 * \param[in] extra_len Extra data size (incl. meta data)
8477 *
8478 * \return On success
8479 * NI_RETCODE_SUCCESS
8480 * On failure
8481 * NI_RETCODE_INVALID_PARAM
8482 * NI_RETCODE_ERROR_MEM_ALOC
8483 *****************************************************************************/
8485  int video_height, int extra_len)
8486 {
8487  void* p_buffer = NULL;
8488  int height_aligned = video_height;
8489  int retval = NI_RETCODE_SUCCESS;
8490 
8491  if (!p_frame)
8492  {
8493  ni_log(NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8494  __func__);
8495  return NI_RETCODE_INVALID_PARAM;
8496  }
8497 
8498  ni_log(NI_LOG_DEBUG, "%s: extra_len=%d\n", __func__, extra_len);
8499 
8500  int buffer_size = (int)sizeof(niFrameSurface1_t) + extra_len;
8501 
8502  buffer_size = ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) * NI_MEM_PAGE_ALIGNMENT + NI_MEM_PAGE_ALIGNMENT;
8503 
8504  //Check if Need to free
8505  if ((p_frame->buffer_size != buffer_size) && (p_frame->buffer_size > 0))
8506  {
8507  ni_log(NI_LOG_DEBUG, "%s: free current p_frame->buffer_size=%u\n",
8508  __func__, p_frame->buffer_size);
8509  ni_frame_buffer_free(p_frame);
8510  }
8511 
8512  //Check if need to realocate
8513  if (p_frame->buffer_size != buffer_size)
8514  {
8515  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
8516  {
8517  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_frame buffer.\n",
8518  NI_ERRNO, __func__);
8519  retval = NI_RETCODE_ERROR_MEM_ALOC;
8520  LRETURN;
8521  }
8522 
8523  // init once after allocation
8524  memset(p_buffer, 0, buffer_size);
8525  p_frame->buffer_size = buffer_size;
8526  p_frame->p_buffer = p_buffer;
8527 
8528  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
8529  }
8530  else
8531  {
8532  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
8533  }
8534 
8535  p_frame->p_data[3] = p_frame->p_buffer;
8536  p_frame->p_data[0] = NULL;
8537  p_frame->p_data[1] = NULL;
8538  p_frame->p_data[2] = NULL;
8539 
8540  p_frame->data_len[0] = 0;//luma_size;
8541  p_frame->data_len[1] = 0;//chroma_b_size;
8542  p_frame->data_len[2] = 0;//chroma_r_size;
8543  p_frame->data_len[3] = sizeof(niFrameSurface1_t);
8544 
8545  p_frame->video_width = video_width;
8546  p_frame->video_height = height_aligned;
8547 
8548  ((niFrameSurface1_t*)p_frame->p_data[3])->device_handle = (int32_t)NI_INVALID_DEVICE_HANDLE;
8549 
8550  ni_log(NI_LOG_DEBUG, "%s: success: p_frame->buffer_size=%u\n", __func__,
8551  p_frame->buffer_size);
8552 
8553 END:
8554 
8555  if (NI_RETCODE_SUCCESS != retval)
8556  {
8557  ni_aligned_free(p_buffer);
8558  }
8559 
8560  return retval;
8561 }
8562 
8563 /*!*****************************************************************************
8564 * \brief Recycle a frame buffer on card
8565 *
8566 * \param[in] surface Struct containing device and frame location to clear out
8567 * \param[in] device_handle handle to access device memory buffer is stored in
8568 *
8569 * \return On success NI_RETCODE_SUCCESS
8570 * On failure NI_RETCODE_INVALID_PARAM
8571 *******************************************************************************/
8573  int32_t device_handle)
8574 {
8576 
8577  if (surface)
8578  {
8579  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8581  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8582  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8583  device_handle);
8584  retval = ni_clear_instance_buf(surface);
8585  }
8586  else
8587  {
8588  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8589  }
8590 
8591  return retval;
8592 }
8593 
8594 /*!*****************************************************************************
8595 * \brief Recycle a frame buffer on card, only hwframe descriptor is needed
8596 *
8597 * \param[in] surface Struct containing device and frame location to clear out
8598 *
8599 * \return On success NI_RETCODE_SUCCESS
8600 * On failure NI_RETCODE_INVALID_PARAM
8601 *******************************************************************************/
8603 {
8605  int32_t saved_dma_buf_fd;
8606  if (surface)
8607  {
8608  if(surface->ui16FrameIdx == 0)
8609  {
8610  ni_log(NI_LOG_DEBUG, "%s(): Invaild frame index\n", __func__);
8611  return retval;
8612  }
8613  ni_log(NI_LOG_DEBUG, "%s(): Start cleaning out buffer\n", __func__);
8615  "%s(): ui16FrameIdx=%d sessionId=%d device_handle=0x%x\n",
8616  __func__, surface->ui16FrameIdx, surface->ui16session_ID,
8617  surface->device_handle);
8618  retval = ni_clear_instance_buf(surface);
8619  saved_dma_buf_fd = surface->dma_buf_fd;
8620  memset(surface, 0, sizeof(niFrameSurface1_t));
8621  surface->dma_buf_fd = saved_dma_buf_fd;
8622  }
8623  else
8624  {
8625  ni_log(NI_LOG_DEBUG, "%s(): Surface is empty\n", __func__);
8626  retval = NI_RETCODE_INVALID_PARAM;
8627  }
8628 
8629  return retval;
8630 }
8631 
8632 /*!*****************************************************************************
8633 * \brief Sends frame pool setup info to device
8634 *
8635 * \param[in] p_ctx Pointer to a caller allocated
8636 * ni_session_context_t struct
8637 * \param[in] pool_size Upload session initial allocated frames count
8638 * must be > 0,
8639 * \param[in] pool 0 use the normal pool
8640 * 1 use a dedicated P2P pool
8641 *
8642 * \return On success Return code
8643 * On failure
8644 * NI_RETCODE_INVALID_PARAM
8645 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8646 * NI_RETCODE_ERROR_INVALID_SESSION
8647 * NI_RETCODE_ERROR_MEM_ALOC
8648 *******************************************************************************/
8650  uint32_t pool_size, uint32_t pool)
8651 {
8653  if (!p_ctx)
8654  {
8655  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8656  __func__);
8657  return NI_RETCODE_INVALID_PARAM;
8658  }
8659  if (pool_size == 0 || pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8660  {
8661  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Invalid poolsize == 0 or > 100\n");
8662  return NI_RETCODE_INVALID_PARAM;
8663  }
8664  if (pool & NI_UPLOADER_FLAG_LM)
8665  {
8666  ni_log2(p_ctx, NI_LOG_DEBUG, "uploader buffer acquisition is limited!\n");
8667  }
8668  ni_pthread_mutex_lock(&p_ctx->mutex);
8670 
8671  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, pool);
8672 
8674  ni_pthread_mutex_unlock(&p_ctx->mutex);
8675 
8676  return retval;
8677 }
8678 
8679 /*!*****************************************************************************
8680 * \brief Sends frame pool change info to device
8681 *
8682 * \param[in] p_ctx Pointer to a caller allocated
8683 * ni_session_context_t struct
8684 * \param[in] pool_size if pool_size = 0, free allocated device memory buffers
8685 * if pool_size > 0, expand device frame buffer pool of
8686 * current instance with pool_size more frame buffers
8687 *
8688 * \return On success Return code
8689 * On failure
8690 * NI_RETCODE_FAILURE
8691 * NI_RETCODE_INVALID_PARAM
8692 * NI_RETCODE_ERROR_NVME_CMD_FAILED
8693 * NI_RETCODE_ERROR_INVALID_SESSION
8694 * NI_RETCODE_ERROR_MEM_ALOC
8695 * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
8696 *******************************************************************************/
8698  uint32_t pool_size)
8699 {
8701  if (!p_ctx)
8702  {
8703  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
8704  __func__);
8705  return NI_RETCODE_INVALID_PARAM;
8706  }
8707  if (ni_cmp_fw_api_ver(
8709  "6r3") < 0)
8710  {
8711  ni_log2(p_ctx, NI_LOG_ERROR,
8712  "ERROR: %s function not supported in FW API version < 6r3\n",
8713  __func__);
8715  }
8716  if (p_ctx->pool_type == NI_POOL_TYPE_NONE)
8717  {
8718  ni_log2(p_ctx, NI_LOG_ERROR,
8719  "ERROR: can't free or expand framepool of session 0x%x "
8720  "before init framepool\n", p_ctx->session_id);
8721  return NI_RETCODE_FAILURE;
8722  }
8723  if (pool_size > NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL)
8724  {
8725  ni_log2(p_ctx, NI_LOG_ERROR,
8726  "ERROR: Invalid poolsize > %u\n", NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL);
8727  return NI_RETCODE_INVALID_PARAM;
8728  }
8729  if (pool_size == 0)
8730  {
8731  ni_log2(p_ctx, NI_LOG_INFO, "Free frame pool of session 0x%x\n", p_ctx->session_id);
8732  }
8733 
8734  ni_pthread_mutex_lock(&p_ctx->mutex);
8736 
8737  retval = ni_config_instance_set_uploader_params(p_ctx, pool_size, p_ctx->pool_type);
8738 
8740  ni_pthread_mutex_unlock(&p_ctx->mutex);
8741 
8742  return retval;
8743 }
8744 
8745 /*!*****************************************************************************
8746  * \brief Set parameters on the device for the 2D engine
8747  *
8748  * \param[in] p_ctx pointer to session context
8749  * \param[in] p_params pointer to scaler parameters
8750  *
8751  * \return NI_RETCODE_INVALID_PARAM
8752  * NI_RETCODE_ERROR_INVALID_SESSION
8753  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8754  * NI_RETCODE_ERROR_MEM_ALOC
8755  ******************************************************************************/
8757  ni_scaler_params_t *p_params)
8758 {
8760 
8761  if (!p_ctx || !p_params)
8762  {
8763  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8764  __func__);
8765  return NI_RETCODE_INVALID_PARAM;
8766  }
8767  ni_pthread_mutex_lock(&p_ctx->mutex);
8769 
8770  retval = ni_config_instance_set_scaler_params(p_ctx, p_params);
8771 
8773  ni_pthread_mutex_unlock(&p_ctx->mutex);
8774 
8775  return retval;
8776 }
8777 
8778 /*!******************************************************************************
8779  * \brief Send a p_config command to configure scaling drawbox parameters.
8780  *
8781  * \param ni_session_context_t p_ctx - xcoder Context
8782  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_drawbox params_t struct
8783  *
8784  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
8785 *******************************************************************************/
8787  ni_scaler_drawbox_params_t *p_params)
8788 {
8789  void *p_scaler_config = NULL;
8790  uint32_t buffer_size = sizeof(ni_scaler_multi_drawbox_params_t);
8792  uint32_t ui32LBA = 0;
8793 
8794  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
8795 
8796  if (!p_ctx || !p_params)
8797  {
8798  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
8799  retval = NI_RETCODE_INVALID_PARAM;
8800  LRETURN;
8801  }
8802 
8803  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
8804  {
8805  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
8807  LRETURN;
8808  }
8809 
8810  buffer_size =
8811  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
8813  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
8814  {
8815  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
8816  NI_ERRNO, __func__);
8817  retval = NI_RETCODE_ERROR_MEM_ALOC;
8818  LRETURN;
8819  }
8820  memset(p_scaler_config, 0, buffer_size);
8821 
8822  //configure the session here
8825 
8826  memcpy(p_scaler_config, p_params, buffer_size);
8827 
8829  p_scaler_config, buffer_size, ui32LBA) < 0)
8830  {
8831  ni_log2(p_ctx, NI_LOG_ERROR,
8832  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
8833  ", hw_id, %d, xcoder_inst_id: %d\n",
8834  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
8835  // Close the session since we can't configure it as per fw
8836  retval = ni_scaler_session_close(p_ctx, 0);
8837  if (NI_RETCODE_SUCCESS != retval)
8838  {
8839  ni_log2(p_ctx, NI_LOG_ERROR,
8840  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
8841  "hw_id, %d, xcoder_inst_id: %d\n",
8842  __func__,
8843  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
8844  p_ctx->session_id);
8845  }
8846 
8848  }
8849 
8850 END:
8851 
8852  ni_aligned_free(p_scaler_config);
8853  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
8854 
8855  return retval;
8856 }
8857 
8858 /*!******************************************************************************
8859  * \brief Send a p_config command to configure scaling watermark parameters.
8860  *
8861  * \param ni_session_context_t p_ctx - xcoder Context
8862  * \param ni_scaler_params_t * params - pointer to the scaler ni_scaler_watermark_params_t struct
8863  *
8864  * \return - NI_RETCODE_SUCCESS on success, NI_RETCODE_ERROR_INVALID_SESSION, NI_RETCODE_ERROR_NVME_CMD_FAILED on failure
8865 *******************************************************************************/
8867  ni_scaler_watermark_params_t *p_params)
8868 {
8869  void *p_scaler_config = NULL;
8870  uint32_t buffer_size = sizeof(ni_scaler_multi_watermark_params_t);
8872  uint32_t ui32LBA = 0;
8873 
8874  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): enter\n", __func__);
8875 
8876  if (!p_ctx || !p_params)
8877  {
8878  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n", __func__);
8879  retval = NI_RETCODE_INVALID_PARAM;
8880  LRETURN;
8881  }
8882 
8883  if (NI_INVALID_SESSION_ID == p_ctx->session_id)
8884  {
8885  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n", __func__);
8887  LRETURN;
8888  }
8889 
8890  buffer_size =
8891  ((buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) / NI_MEM_PAGE_ALIGNMENT) *
8893  if (ni_posix_memalign(&p_scaler_config, sysconf(_SC_PAGESIZE), buffer_size))
8894  {
8895  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() malloc p_scaler_config buffer failed\n",
8896  NI_ERRNO, __func__);
8897  retval = NI_RETCODE_ERROR_MEM_ALOC;
8898  LRETURN;
8899  }
8900  memset(p_scaler_config, 0, buffer_size);
8901 
8902  //configure the session here
8905 
8906  memcpy(p_scaler_config, p_params, buffer_size);
8907 
8909  p_scaler_config, buffer_size, ui32LBA) < 0)
8910  {
8911  ni_log2(p_ctx, NI_LOG_ERROR,
8912  "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
8913  ", hw_id, %d, xcoder_inst_id: %d\n",
8914  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id, p_ctx->session_id);
8915  // Close the session since we can't configure it as per fw
8916  retval = ni_scaler_session_close(p_ctx, 0);
8917  if (NI_RETCODE_SUCCESS != retval)
8918  {
8919  ni_log2(p_ctx, NI_LOG_ERROR,
8920  "ERROR: %s failed: blk_io_handle: %" PRIx64 ","
8921  "hw_id, %d, xcoder_inst_id: %d\n",
8922  __func__,
8923  (int64_t)p_ctx->blk_io_handle, p_ctx->hw_id,
8924  p_ctx->session_id);
8925  }
8926 
8928  }
8929 
8930 END:
8931 
8932  ni_aligned_free(p_scaler_config);
8933  ni_log2(p_ctx, NI_LOG_TRACE, "%s(): exit\n", __func__);
8934 
8935  return retval;
8936 }
8937 
8938 
8939 /*!*****************************************************************************
8940  * \brief Allocate a frame on the device for 2D engine or AI engine
8941  * to work on based on provided parameters
8942  *
8943  * \param[in] p_ctx pointer to session context
8944  * \param[in] width width, in pixels
8945  * \param[in] height height, in pixels
8946  * \param[in] format pixel format
8947  * \param[in] options options bitmap flags, bit 0 (NI_SCALER_FLAG_IO) is
8948  * 0=input frame or 1=output frame. Bit 1 (NI_SCALER_FLAG_PC) is
8949  * 0=single allocation, 1=create pool. Bit 2 (NI_SCALER_FLAG_PA) is
8950  * 0=straight alpha, 1=premultiplied alpha
8951  * \param[in] rectangle_width clipping rectangle width
8952  * \param[in] rectangle_height clipping rectangle height
8953  * \param[in] rectangle_x horizontal position of clipping rectangle
8954  * \param[in] rectangle_y vertical position of clipping rectangle
8955  * \param[in] rgba_color RGBA fill colour (for padding only)
8956  * \param[in] frame_index input hwdesc index
8957  * \param[in] device_type only NI_DEVICE_TYPE_SCALER
8958  * and NI_DEVICE_TYPE_AI (only needs p_ctx and frame_index)
8959  *
8960  * \return NI_RETCODE_INVALID_PARAM
8961  * NI_RETCODE_ERROR_INVALID_SESSION
8962  * NI_RETCODE_ERROR_NVME_CMD_FAILED
8963  * NI_RETCODE_ERROR_MEM_ALOC
8964  ******************************************************************************/
8966  int width,
8967  int height,
8968  int format,
8969  int options,
8970  int rectangle_width,
8971  int rectangle_height,
8972  int rectangle_x,
8973  int rectangle_y,
8974  int rgba_color,
8975  int frame_index,
8976  ni_device_type_t device_type)
8977 {
8979 
8980  if (!p_ctx)
8981  {
8982  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
8983  __func__);
8984  return NI_RETCODE_INVALID_PARAM;
8985  }
8986  ni_pthread_mutex_lock(&p_ctx->mutex);
8988 
8989  switch (device_type)
8990  {
8991  case NI_DEVICE_TYPE_SCALER:
8992  retval = ni_scaler_alloc_frame(p_ctx,width, height, format, options,
8993  rectangle_width, rectangle_height,
8994  rectangle_x, rectangle_y,
8995  rgba_color, frame_index);
8996  break;
8997 
8998  case NI_DEVICE_TYPE_AI:
8999  retval = ni_ai_alloc_hwframe(p_ctx, width, height, options, rgba_color,
9000  frame_index);
9001  break;
9002 
9005  /* fall through */
9006 
9007  default:
9008  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
9009  retval = NI_RETCODE_INVALID_PARAM;
9010  break;
9011  }
9012 
9014  ni_pthread_mutex_unlock(&p_ctx->mutex);
9015 
9016  return retval;
9017 }
9018 
9019 /*!*****************************************************************************
9020  * \brief Allocate a frame on the device and return the frame index
9021  *
9022  * \param[in] p_ctx pointer to session context
9023  * \param[in] p_out_surface pointer to output frame surface
9024  * \param[in] device_type currently only NI_DEVICE_TYPE_AI
9025  *
9026  * \return NI_RETCODE_INVALID_PARAM
9027  * NI_RETCODE_ERROR_INVALID_SESSION
9028  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
9029  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9030  * NI_RETCODE_ERROR_MEM_ALOC
9031  ******************************************************************************/
9033  niFrameSurface1_t *p_out_surface,
9034  ni_device_type_t device_type)
9035 {
9037 
9038  if (!p_ctx)
9039  {
9040  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, %p, return\n",
9041  __func__, p_ctx);
9042  return NI_RETCODE_INVALID_PARAM;
9043  }
9044  ni_pthread_mutex_lock(&p_ctx->mutex);
9046 
9047  switch (device_type)
9048  {
9049  case NI_DEVICE_TYPE_AI:
9050  retval = ni_ai_alloc_dst_frame(p_ctx, p_out_surface);
9051  break;
9052 
9053  case NI_DEVICE_TYPE_SCALER:
9056  /* fall through */
9057 
9058  default:
9059  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", device_type);
9060  retval = NI_RETCODE_INVALID_PARAM;
9061  break;
9062  }
9063 
9065  ni_pthread_mutex_unlock(&p_ctx->mutex);
9066 
9067  return retval;
9068 }
9069 
9070 /*!*****************************************************************************
9071  * \brief Copy the data of src hwframe to dst hwframe
9072  *
9073  * \param[in] p_ctx pointer to session context
9074  * \param[in] p_frameclone_desc pointer to the frameclone descriptor
9075  *
9076  * \return NI_RETCODE_INVALID_PARAM
9077  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
9078  * NI_RETCODE_ERROR_INVALID_SESSION
9079  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9080  * NI_RETCODE_ERROR_MEM_ALOC
9081  ******************************************************************************/
9083  ni_frameclone_desc_t *p_frameclone_desc)
9084 {
9086 
9087  if (!p_ctx)
9088  {
9089  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9090  __func__);
9091  return NI_RETCODE_INVALID_PARAM;
9092  }
9093 
9094  if (ni_cmp_fw_api_ver(
9096  "6rL") < 0)
9097  {
9098  ni_log2(p_ctx, NI_LOG_ERROR,
9099  "Error: %s function not supported on device with FW API version < 6rL\n",
9100  __func__);
9102  }
9103 
9104  ni_pthread_mutex_lock(&p_ctx->mutex);
9106  if (p_ctx->session_id == NI_INVALID_SESSION_ID)
9107  {
9108  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %s(): Invalid session ID, return.\n",
9109  __func__);
9111  LRETURN;
9112  }
9113 
9114  retval = ni_hwframe_clone(p_ctx, p_frameclone_desc);
9115 
9116 END:
9118  ni_pthread_mutex_unlock(&p_ctx->mutex);
9119 
9120  return retval;
9121 }
9122 
9123 /*!*****************************************************************************
9124  * \brief Configure the 2D engine to work based on provided parameters
9125  *
9126  * \param[in] p_ctx pointer to session context
9127  * \param[in] p_cfg pointer to frame configuration
9128  *
9129  * \return NI_RETCODE_INVALID_PARAM
9130  * NI_RETCODE_ERROR_INVALID_SESSION
9131  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9132  * NI_RETCODE_ERROR_MEM_ALOC
9133  ******************************************************************************/
9135  ni_frame_config_t *p_cfg)
9136 {
9138 
9139  if (!p_ctx || !p_cfg)
9140  {
9141  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9142  __func__);
9143  return NI_RETCODE_INVALID_PARAM;
9144  }
9145 
9146  ni_pthread_mutex_lock(&p_ctx->mutex);
9148 
9149  switch (p_ctx->device_type)
9150  {
9151  case NI_DEVICE_TYPE_SCALER:
9152  retval = ni_scaler_config_frame(p_ctx, p_cfg);
9153  break;
9154 
9155  default:
9156  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9157  retval = NI_RETCODE_INVALID_PARAM;
9158  break;
9159  }
9160 
9162  ni_pthread_mutex_unlock(&p_ctx->mutex);
9163 
9164  return retval;
9165 }
9166 
9167 /*!*****************************************************************************
9168  * \brief Configure the 2D engine to work based on provided parameters
9169  *
9170  * \param[in] p_ctx pointer to session context
9171  * \param[in] p_cfg_in pointer to input frame configuration
9172  * \param[in] numInCfgs number of input frame configurations
9173  * \param[in] p_cfg_out pointer to output frame configuration
9174  *
9175  * \return NI_RETCODE_INVALID_PARAM
9176  * NI_RETCODE_ERROR_INVALID_SESSION
9177  * NI_RETCODE_ERROR_NVME_CMD_FAILED
9178  * NI_RETCODE_ERROR_MEM_ALOC
9179  ******************************************************************************/
9181  ni_frame_config_t p_cfg_in[],
9182  int numInCfgs,
9183  ni_frame_config_t *p_cfg_out)
9184 {
9186 
9187  if (!p_ctx || !p_cfg_in)
9188  {
9189  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9190  __func__);
9191  return NI_RETCODE_INVALID_PARAM;
9192  }
9193 
9194  ni_pthread_mutex_lock(&p_ctx->mutex);
9196 
9197  switch (p_ctx->device_type)
9198  {
9199  case NI_DEVICE_TYPE_SCALER:
9200  retval = ni_scaler_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9201  break;
9202 
9203  case NI_DEVICE_TYPE_AI:
9204  retval = ni_ai_multi_config_frame(p_ctx, p_cfg_in, numInCfgs, p_cfg_out);
9205  break;
9206 
9207  default:
9208  ni_log2(p_ctx, NI_LOG_ERROR, "Bad device type %d\n", p_ctx->device_type);
9209  retval = NI_RETCODE_INVALID_PARAM;
9210  break;
9211  }
9212 
9214  ni_pthread_mutex_unlock(&p_ctx->mutex);
9215 
9216  return retval;
9217 }
9218 
9219 /*!*****************************************************************************
9220  * \brief Calculate the total size of a frame based on the upload
9221  * context attributes and includes rounding up to the page size
9222  *
9223  * \param[in] p_upl_ctx pointer to an uploader session context
9224  * \param[in] linesize array of line stride
9225  *
9226  * \return size
9227  * NI_RETCODE_INVALID_PARAM
9228  *
9229  ******************************************************************************/
9231  const int linesize[])
9232 {
9233  int pixel_format;
9234  int width, height;
9235  int alignedh;
9236  int luma, chroma_b, chroma_r;
9237  int total;
9238 
9239  pixel_format = p_upl_ctx->pixel_format;
9240  width = p_upl_ctx->active_video_width;
9241  height = p_upl_ctx->active_video_height;
9242 
9243  switch (pixel_format)
9244  {
9245  case NI_PIX_FMT_YUV420P:
9247  case NI_PIX_FMT_NV12:
9248  case NI_PIX_FMT_P010LE:
9249  if (width < 0 || width > NI_MAX_RESOLUTION_WIDTH)
9250  {
9251  return NI_RETCODE_INVALID_PARAM;
9252  }
9253 
9254  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9255  {
9256  return NI_RETCODE_INVALID_PARAM;
9257  }
9258  break;
9259 
9260  case NI_PIX_FMT_RGBA:
9261  case NI_PIX_FMT_ABGR:
9262  case NI_PIX_FMT_ARGB:
9263  case NI_PIX_FMT_BGRA:
9264  case NI_PIX_FMT_BGR0:
9265  if ((width < 0) || (width > NI_MAX_RESOLUTION_WIDTH))
9266  {
9267  return NI_RETCODE_INVALID_PARAM;
9268  }
9269 
9270  if ((height < 0) || (height > NI_MAX_RESOLUTION_HEIGHT))
9271  {
9272  return NI_RETCODE_INVALID_PARAM;
9273  }
9274  break;
9275 
9276  default:
9277  return NI_RETCODE_INVALID_PARAM;
9278  }
9279 
9280  alignedh = NI_VPU_CEIL(height, 2);
9281 
9282  switch (pixel_format)
9283  {
9284  case NI_PIX_FMT_YUV420P:
9286  luma = linesize[0] * alignedh;
9287  chroma_b = linesize[1] * alignedh / 2;
9288  chroma_r = linesize[2] * alignedh / 2;
9289  total =
9290  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9291  break;
9292 
9293  case NI_PIX_FMT_NV12:
9294  case NI_PIX_FMT_P010LE:
9295  luma = linesize[0] * alignedh;
9296  chroma_b = linesize[1] * alignedh / 2;
9297  chroma_r = 0;
9298  total =
9299  luma + chroma_b + chroma_r + NI_APP_ENC_FRAME_META_DATA_SIZE;
9300  break;
9301 
9302  case NI_PIX_FMT_RGBA:
9303  case NI_PIX_FMT_ABGR:
9304  case NI_PIX_FMT_ARGB:
9305  case NI_PIX_FMT_BGRA:
9306  case NI_PIX_FMT_BGR0:
9307  total = width * height * 4 + NI_APP_ENC_FRAME_META_DATA_SIZE;
9308  break;
9309 
9310  default:
9311  return NI_RETCODE_INVALID_PARAM;
9312  break;
9313  }
9314 
9316 
9317  return total;
9318 }
9319 
9320 /*!*****************************************************************************
9321  * \brief Allocate memory for the frame buffer based on provided parameters
9322  * taking into account the pixel format, width, height, stride,
9323  * alignment, and extra data
9324  * \param[in] p_frame Pointer to caller allocated ni_frame_t
9325  * \param[in] pixel_format a pixel format in ni_pix_fmt_t enum
9326  * \param[in] video_width width, in pixels
9327  * \param[in] video_height height, in pixels
9328  * \param[in] linesize horizontal stride
9329  * \param[in] alignment apply a 16 pixel height alignment (T408 only)
9330  * \param[in] extra_len meta data size
9331  *
9332  * \return NI_RETCODE_SUCCESS
9333  * NI_RETCODE_INVALID_PARAM
9334  * NI_RETCODE_ERROR_MEM_ALOC
9335  *
9336  ******************************************************************************/
9338  int video_width, int video_height,
9339  int linesize[], int alignment,
9340  int extra_len)
9341 {
9342  int buffer_size;
9343  void *p_buffer = NULL;
9344  int retval = NI_RETCODE_SUCCESS;
9345  int height_aligned;
9346  int luma_size = 0;
9347  int chroma_b_size = 0;
9348  int chroma_r_size = 0;
9349 
9350  if (!p_frame)
9351  {
9352  ni_log(NI_LOG_ERROR, "Invalid frame pointer\n");
9353  return NI_RETCODE_INVALID_PARAM;
9354  }
9355 
9356  switch (pixel_format)
9357  {
9358  case NI_PIX_FMT_YUV420P:
9360  case NI_PIX_FMT_NV12:
9361  case NI_PIX_FMT_P010LE:
9362  case NI_PIX_FMT_NV16:
9363  case NI_PIX_FMT_YUYV422:
9364  case NI_PIX_FMT_UYVY422:
9365  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9366  {
9367  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9368  video_width);
9369  return NI_RETCODE_INVALID_PARAM;
9370  }
9371 
9372  if ((video_height < 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9373  {
9374  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9375  video_width);
9376  return NI_RETCODE_INVALID_PARAM;
9377  }
9378  break;
9379 
9380  case NI_PIX_FMT_RGBA:
9381  case NI_PIX_FMT_BGRA:
9382  case NI_PIX_FMT_ARGB:
9383  case NI_PIX_FMT_ABGR:
9384  case NI_PIX_FMT_BGR0:
9385  case NI_PIX_FMT_BGRP:
9386  /*
9387  * For 2D engine using RGBA, the minimum width is 32. There is no
9388  * height restriction. The 2D engine supports a height/width of up to
9389  * 32K but but we will limit the max height and width to 8K.
9390  */
9391  if ((video_width < 0) || (video_width > NI_MAX_RESOLUTION_WIDTH))
9392  {
9393  ni_log(NI_LOG_ERROR, "Video resolution width %d out of range\n",
9394  video_width);
9395  return NI_RETCODE_INVALID_PARAM;
9396  }
9397 
9398  if ((video_height <= 0) || (video_height > NI_MAX_RESOLUTION_HEIGHT))
9399  {
9400  ni_log(NI_LOG_ERROR, "Video resolution height %d out of range\n",
9401  video_height);
9402  return NI_RETCODE_INVALID_PARAM;
9403  }
9404  break;
9405 
9406  default:
9407  ni_log(NI_LOG_ERROR, "Unknown pixel format %d\n",pixel_format);
9408  return NI_RETCODE_INVALID_PARAM;
9409  }
9410 
9411  if (QUADRA)
9412  {
9413  /* Quadra requires an even-numbered height/width */
9414  height_aligned = NI_VPU_CEIL(video_height, 2);
9415  }
9416  else
9417  {
9418  height_aligned = NI_VPU_ALIGN8(video_height);
9419 
9420  if (alignment)
9421  {
9422  /* 16-pixel aligned pixel height for Quadra */
9423  height_aligned = NI_VPU_ALIGN16(video_height);
9424  }
9425  }
9426 
9427  switch (pixel_format)
9428  {
9429  case NI_PIX_FMT_YUV420P:
9431  luma_size = linesize[0] * height_aligned;
9432 
9433  if (QUADRA)
9434  {
9435  chroma_b_size = linesize[1] * height_aligned / 2;
9436  chroma_r_size = linesize[2] * height_aligned / 2;
9437  }
9438  else
9439  {
9440  chroma_b_size = luma_size / 4;
9441  chroma_r_size = luma_size / 4;
9442  }
9443  break;
9444 
9445  case NI_PIX_FMT_RGBA:
9446  case NI_PIX_FMT_BGRA:
9447  case NI_PIX_FMT_ARGB:
9448  case NI_PIX_FMT_ABGR:
9449  case NI_PIX_FMT_BGR0:
9450  luma_size = linesize[0] * video_height;
9451  chroma_b_size = 0;
9452  chroma_r_size = 0;
9453  break;
9454 
9455  case NI_PIX_FMT_NV12:
9456  case NI_PIX_FMT_P010LE:
9457  if (QUADRA)
9458  {
9459  luma_size = linesize[0] * height_aligned;
9460  chroma_b_size = linesize[1] * height_aligned / 2;
9461  chroma_r_size = 0;
9462  break;
9463  }
9464  case NI_PIX_FMT_NV16:
9465  if (QUADRA)
9466  {
9467  luma_size = linesize[0] * video_height;
9468  chroma_b_size = linesize[1] * video_height;
9469  chroma_r_size = 0;
9470  break;
9471  }
9472  case NI_PIX_FMT_YUYV422:
9473  case NI_PIX_FMT_UYVY422:
9474  if (QUADRA)
9475  {
9476  luma_size = linesize[0] * video_height;
9477  chroma_b_size = 0;
9478  chroma_r_size = 0;
9479  break;
9480  }
9481  case NI_PIX_FMT_BGRP:
9482  if (QUADRA)
9483  {
9484  luma_size = NI_VPU_ALIGN32(linesize[0] * video_height);
9485  chroma_b_size = NI_VPU_ALIGN32(linesize[1] * video_height);
9486  chroma_r_size = NI_VPU_ALIGN32(linesize[2] * video_height);
9487  break;
9488  }
9489  /*fall through*/
9490  default:
9491  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9492  return NI_RETCODE_INVALID_PARAM;
9493  }
9494 
9495  buffer_size = luma_size + chroma_b_size + chroma_r_size + extra_len;
9496 
9497  /* Allocate a buffer size that is page aligned for the host */
9498  buffer_size = NI_VPU_CEIL(buffer_size,NI_MEM_PAGE_ALIGNMENT) + NI_MEM_PAGE_ALIGNMENT;
9499 
9500  /* If this buffer has a different size, realloc a new buffer */
9501  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9502  {
9503  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9504  p_frame->buffer_size);
9505  ni_frame_buffer_free(p_frame);
9506  }
9507 
9508  if (p_frame->buffer_size != buffer_size)
9509  {
9510  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9511  {
9512  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9513  retval = NI_RETCODE_ERROR_MEM_ALOC;
9514  LRETURN;
9515  }
9516 
9517  memset(p_buffer, 0, buffer_size);
9518  p_frame->buffer_size = buffer_size;
9519  p_frame->p_buffer = p_buffer;
9520  ni_log(NI_LOG_DEBUG, "%s: allocated new p_frame buffer\n", __func__);
9521  }
9522  else
9523  {
9524  ni_log(NI_LOG_DEBUG, "%s: reuse p_frame buffer\n", __func__);
9525  }
9526 
9527  switch (pixel_format)
9528  {
9529  case NI_PIX_FMT_YUV420P:
9531  p_frame->p_data[0] = p_frame->p_buffer;
9532  p_frame->p_data[1] = p_frame->p_data[0] + luma_size;
9533  p_frame->p_data[2] = p_frame->p_data[1] + chroma_b_size;
9534  p_frame->p_data[3] = NULL;
9535 
9536  p_frame->data_len[0] = luma_size;
9537  p_frame->data_len[1] = chroma_b_size;
9538  p_frame->data_len[2] = chroma_r_size;
9539  p_frame->data_len[3] = 0;
9540  video_width = NI_VPU_ALIGN128(video_width);
9541  break;
9542 
9543  case NI_PIX_FMT_RGBA:
9544  case NI_PIX_FMT_BGRA:
9545  case NI_PIX_FMT_ARGB:
9546  case NI_PIX_FMT_ABGR:
9547  case NI_PIX_FMT_BGR0:
9548  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9549  p_frame->p_data[1] = NULL;
9550  p_frame->p_data[2] = NULL;
9551  p_frame->p_data[3] = NULL;
9552 
9553  p_frame->data_len[0] = luma_size;
9554  p_frame->data_len[1] = 0;
9555  p_frame->data_len[2] = 0;
9556  p_frame->data_len[3] = 0;
9557  video_width = NI_VPU_ALIGN16(video_width);
9558  break;
9559 
9560  case NI_PIX_FMT_NV12:
9561  case NI_PIX_FMT_P010LE:
9562  if (QUADRA)
9563  {
9564  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9565  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9566  p_frame->p_data[2] = NULL;
9567  p_frame->p_data[3] = NULL;
9568 
9569  p_frame->data_len[0] = luma_size;
9570  p_frame->data_len[1] = chroma_b_size;
9571  p_frame->data_len[2] = 0;
9572  p_frame->data_len[3] = 0;
9573 
9574  video_width = NI_VPU_ALIGN128(video_width);
9575  break;
9576  }
9577  case NI_PIX_FMT_NV16:
9578  if (QUADRA)
9579  {
9580  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9581  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9582  p_frame->p_data[2] = NULL;
9583  p_frame->p_data[3] = NULL;
9584 
9585  p_frame->data_len[0] = luma_size;
9586  p_frame->data_len[1] = chroma_b_size;
9587  p_frame->data_len[2] = 0;
9588  p_frame->data_len[3] = 0;
9589 
9590  video_width = NI_VPU_ALIGN64(video_width);
9591  break;
9592  }
9593 
9594  case NI_PIX_FMT_YUYV422:
9595  case NI_PIX_FMT_UYVY422:
9596  if (QUADRA)
9597  {
9598  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9599  p_frame->p_data[1] = NULL;
9600  p_frame->p_data[2] = NULL;
9601  p_frame->p_data[3] = NULL;
9602 
9603  p_frame->data_len[0] = luma_size;
9604  p_frame->data_len[1] = 0;
9605  p_frame->data_len[2] = 0;
9606  p_frame->data_len[3] = 0;
9607  video_width = NI_VPU_ALIGN16(video_width);
9608  break;
9609  }
9610  case NI_PIX_FMT_BGRP:
9611  if (QUADRA)
9612  {
9613  p_frame->p_data[0] = (uint8_t *)p_frame->p_buffer;
9614  p_frame->p_data[1] = (uint8_t *)p_frame->p_data[0] + luma_size;
9615  p_frame->p_data[2] = (uint8_t *)p_frame->p_data[1] + chroma_b_size;
9616  p_frame->p_data[3] = NULL;
9617 
9618  p_frame->data_len[0] = luma_size;
9619  p_frame->data_len[1] = chroma_b_size;
9620  p_frame->data_len[2] = chroma_r_size;
9621  p_frame->data_len[3] = 0;
9622  break;
9623  }
9624  /* fall through */
9625  default:
9626  ni_log(NI_LOG_ERROR, "Error: unsupported pixel format %d\n",pixel_format);
9627  retval = NI_RETCODE_INVALID_PARAM;
9628  LRETURN;
9629  }
9630 
9631  p_frame->video_width = video_width;
9632  p_frame->video_height = height_aligned;
9633 
9634  ni_log(NI_LOG_DEBUG, "%s success: w=%d; h=%d; aligned buffer size=%d\n",
9635  __func__, video_width, video_height, buffer_size);
9636 
9637 END:
9638 
9639  if (retval != NI_RETCODE_SUCCESS)
9640  {
9641  ni_aligned_free(p_buffer);
9642  }
9643 
9644  return retval;
9645 }
9646 
9648  ni_network_data_t *p_network,
9649  const char *file)
9650 {
9651  FILE *fp = NULL;
9652  struct stat file_stat;
9654  unsigned char *buffer = NULL;
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  ni_pthread_mutex_lock(&p_ctx->mutex);
9664  ni_pthread_mutex_unlock(&p_ctx->mutex);
9665 
9666  if (stat(file, &file_stat) != 0)
9667  {
9668  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to get network binary file stat, %s\n",
9669  __func__, strerror(NI_ERRNO));
9670  retval = NI_RETCODE_FAILURE;
9671  LRETURN;
9672  }
9673 
9674  if (file_stat.st_size == 0)
9675  {
9676  ni_log2(p_ctx, NI_LOG_ERROR, "%s: network binary size is null\n", __func__);
9677  retval = NI_RETCODE_FAILURE;
9678  LRETURN;
9679  }
9680 
9681  fp = fopen(file, "rb");
9682  if (!fp)
9683  {
9684  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to open network binary, %s\n", __func__,
9685  strerror(NI_ERRNO));
9686  retval = NI_RETCODE_FAILURE;
9687  LRETURN;
9688  }
9689 
9690  buffer = malloc(file_stat.st_size);
9691  if (!buffer)
9692  {
9693  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to alloate memory\n", __func__);
9694  retval = NI_RETCODE_ERROR_MEM_ALOC;
9695  LRETURN;
9696  }
9697 
9698  if (fread(buffer, file_stat.st_size, 1, fp) != 1)
9699  {
9700  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to read network binary\n", __func__);
9701  retval = NI_RETCODE_FAILURE;
9702  LRETURN;
9703  }
9704 
9705  retval =
9706  ni_config_instance_network_binary(p_ctx, buffer, file_stat.st_size);
9707  if (retval != NI_RETCODE_SUCCESS)
9708  {
9709  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9710  __func__, retval);
9711  LRETURN;
9712  }
9713 
9714  retval = ni_config_read_inout_layers(p_ctx, p_network);
9715  if (retval != NI_RETCODE_SUCCESS)
9716  {
9717  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9718  retval);
9719  }
9720 
9721 END:
9722 
9723  if (fp)
9724  {
9725  fclose(fp);
9726  }
9727  free(buffer);
9728 
9729  ni_pthread_mutex_lock(&p_ctx->mutex);
9731  ni_pthread_mutex_unlock(&p_ctx->mutex);
9732 
9733  return retval;
9734 }
9735 
9737  ni_network_data_t *p_network)
9738 {
9740 
9741  if (!p_ctx)
9742  {
9743  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
9744  __func__);
9745  return NI_RETCODE_INVALID_PARAM;
9746  }
9747 
9748  if ((ni_cmp_fw_api_ver((char*) &p_ctx->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6ro") < 0))
9749  {
9750  ni_log2(p_ctx, NI_LOG_ERROR, "Error: hvsplus filter not supported on device with FW API version < 6ro\n");
9752  }
9753 
9754  ni_pthread_mutex_lock(&p_ctx->mutex);
9756  ni_pthread_mutex_unlock(&p_ctx->mutex);
9757 
9758  retval =
9759  ni_config_instance_hvsplus(p_ctx); //, buffer, file_stat.st_size);
9760  if (retval != NI_RETCODE_SUCCESS)
9761  {
9762  ni_log2(p_ctx, NI_LOG_ERROR, "%s: failed to configure instance, retval %d\n",
9763  __func__, retval);
9764  LRETURN;
9765  }
9766 
9767  retval = ni_config_read_inout_layers(p_ctx, p_network);
9768  if (retval != NI_RETCODE_SUCCESS)
9769  {
9770  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: failed to read network layers, retval %d\n",
9771  retval);
9772  }
9773 
9774 END:
9775 
9776  ni_pthread_mutex_lock(&p_ctx->mutex);
9778  ni_pthread_mutex_unlock(&p_ctx->mutex);
9779 
9780  return retval;
9781 }
9782 
9784  ni_network_data_t *p_network)
9785 {
9786  uint32_t buffer_size = 0;
9787  void *p_buffer = NULL;
9788  int retval = NI_RETCODE_SUCCESS;
9789  uint32_t i, this_size;
9790  ni_network_layer_info_t *p_linfo;
9791 
9792  if (!p_frame || !p_network)
9793  {
9794  ni_log(NI_LOG_ERROR, "Invalid frame or network layer pointer\n");
9795  return NI_RETCODE_INVALID_PARAM;
9796  }
9797 
9798  p_linfo = &p_network->linfo;
9799  for (i = 0; i < p_network->input_num; i++)
9800  {
9801  this_size = ni_ai_network_layer_size(&p_linfo->in_param[i]);
9802  this_size =
9803  (this_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
9804  if (p_network->inset[i].offset != buffer_size)
9805  {
9807  "ERROR: %s(): invalid buffer_size of network\n", __func__);
9808  return NI_RETCODE_INVALID_PARAM;
9809  }
9810  buffer_size += this_size;
9811  }
9812 
9813  /* fixed size */
9814  p_frame->data_len[0] = buffer_size;
9815 
9816  /* Allocate a buffer size that is page aligned for the host */
9817  buffer_size = (buffer_size + NI_MEM_PAGE_ALIGNMENT - 1) &
9818  ~(NI_MEM_PAGE_ALIGNMENT - 1);
9819 
9820  /* If this buffer has a different size, realloc a new buffer */
9821  if ((p_frame->buffer_size > 0) && (p_frame->buffer_size != buffer_size))
9822  {
9823  ni_log(NI_LOG_DEBUG, "Free current p_frame, p_frame->buffer_size %u\n",
9824  p_frame->buffer_size);
9825  ni_frame_buffer_free(p_frame);
9826  }
9827 
9828  if (p_frame->buffer_size != buffer_size)
9829  {
9830  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9831  {
9832  ni_log(NI_LOG_ERROR, "Error: Cannot allocate p_frame\n");
9833  retval = NI_RETCODE_ERROR_MEM_ALOC;
9834  LRETURN;
9835  }
9836 
9837  // memset(p_buffer, 0, buffer_size);
9838  p_frame->buffer_size = buffer_size;
9839  p_frame->p_buffer = p_buffer;
9840  ni_log(NI_LOG_DEBUG, "%s(): allocated new p_frame buffer\n", __func__);
9841  } else
9842  {
9843  ni_log(NI_LOG_DEBUG, "%s(): reuse p_frame buffer\n", __func__);
9844  }
9845 
9846  p_frame->p_data[0] = p_frame->p_buffer;
9847  p_frame->p_data[1] = NULL;
9848  p_frame->p_data[2] = NULL;
9849  p_frame->p_data[3] = NULL;
9850 
9851  p_frame->iovec = NULL;
9852  p_frame->iovec_num = 0;
9853 
9854  ni_log(NI_LOG_DEBUG, "%s() success: aligned buffer size=%u\n", __func__,
9855  buffer_size);
9856 
9857 END:
9858 
9859  if (retval != NI_RETCODE_SUCCESS)
9860  {
9861  ni_aligned_free(p_buffer);
9862  }
9863 
9864  return retval;
9865 }
9866 
9868  ni_network_data_t *p_network)
9869 {
9870  void *p_buffer = NULL;
9871  int retval = NI_RETCODE_SUCCESS;
9872  uint32_t buffer_size = 0;
9873  uint32_t i, data_size;
9874  ni_network_layer_info_t *p_linfo;
9875 
9876  if (!p_packet || !p_network)
9877  {
9878  ni_log(NI_LOG_ERROR, "ERROR: %s(): null pointer parameters passed\n",
9879  __func__);
9880  return NI_RETCODE_INVALID_PARAM;
9881  }
9882 
9883  p_linfo = &p_network->linfo;
9884  for (i = 0; i < p_network->output_num; i++)
9885  {
9886  data_size = ni_ai_network_layer_size(&p_linfo->out_param[i]);
9887  data_size =
9888  (data_size + NI_AI_HW_ALIGN_SIZE - 1) & ~(NI_AI_HW_ALIGN_SIZE - 1);
9889  if (p_network->outset[i].offset != buffer_size)
9890  {
9892  "ERROR: %s(): invalid buffer_size of network\n", __func__);
9893  return NI_RETCODE_INVALID_PARAM;
9894  }
9895  buffer_size += data_size;
9896  }
9897  data_size = buffer_size;
9898 
9899  ni_log(NI_LOG_DEBUG, "%s(): packet_size=%u\n", __func__, buffer_size);
9900 
9901  if (buffer_size & (NI_MEM_PAGE_ALIGNMENT - 1))
9902  {
9903  buffer_size = (buffer_size + (NI_MEM_PAGE_ALIGNMENT - 1)) &
9904  ~(NI_MEM_PAGE_ALIGNMENT - 1);
9905  }
9906 
9907  if (p_packet->buffer_size == buffer_size)
9908  {
9909  p_packet->p_data = p_packet->p_buffer;
9910  ni_log(NI_LOG_DEBUG, "%s(): reuse current p_packet buffer\n", __func__);
9911  LRETURN; //Already allocated the exact size
9912  } else if (p_packet->buffer_size > 0)
9913  {
9915  "%s(): free current p_packet, p_packet->buffer_size=%u\n",
9916  __func__, p_packet->buffer_size);
9917  ni_packet_buffer_free(p_packet);
9918  }
9919  ni_log(NI_LOG_DEBUG, "%s(): Allocating p_packet buffer, buffer_size=%u\n",
9920  __func__, buffer_size);
9921 
9922  if (ni_posix_memalign(&p_buffer, sysconf(_SC_PAGESIZE), buffer_size))
9923  {
9924  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate p_packet buffer.\n",
9925  NI_ERRNO, __func__);
9926  retval = NI_RETCODE_ERROR_MEM_ALOC;
9927  LRETURN;
9928  }
9929 
9930  p_packet->buffer_size = buffer_size;
9931  p_packet->p_buffer = p_buffer;
9932  p_packet->p_data = p_packet->p_buffer;
9933  p_packet->data_len = data_size;
9934 
9935 END:
9936 
9937  if (NI_RETCODE_SUCCESS != retval)
9938  {
9939  ni_aligned_free(p_buffer);
9940  }
9941 
9942  ni_log(NI_LOG_TRACE, "%s(): exit: p_packet->buffer_size=%u\n", __func__,
9943  p_packet->buffer_size);
9944 
9945  return retval;
9946 }
9947 
9948 /*!*****************************************************************************
9949  * \brief Reconfigure bitrate dynamically during encoding.
9950  *
9951  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
9952  * \param[in] bitrate Target bitrate to set
9953  *
9954  * \return On success NI_RETCODE_SUCCESS
9955  * On failure NI_RETCODE_INVALID_PARAM
9956  ******************************************************************************/
9958 {
9959  if (!p_ctx || bitrate < NI_MIN_BITRATE || bitrate > NI_MAX_BITRATE)
9960  {
9961  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid bitrate passed in %d\n",
9962  __func__, bitrate);
9963  return NI_RETCODE_INVALID_PARAM;
9964  }
9965  ni_pthread_mutex_lock(&p_ctx->mutex);
9967 
9968  if (p_ctx->target_bitrate > 0)
9969  {
9970  ni_log2(p_ctx, NI_LOG_DEBUG,
9971  "Warning: %s(): bitrate %d overwriting current one %d\n",
9972  __func__, bitrate, p_ctx->target_bitrate);
9973  }
9974 
9975  p_ctx->target_bitrate = bitrate;
9976 
9978  ni_pthread_mutex_unlock(&p_ctx->mutex);
9979 
9980  return NI_RETCODE_SUCCESS;
9981 }
9982 
9983 /*!*****************************************************************************
9984  * \brief Reconfigure intraPeriod dynamically during encoding.
9985  *
9986  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
9987  * \param[in] intra_period Target intra period to set
9988  *
9989  *
9990  * \return On success NI_RETCODE_SUCCESS
9991  * On failure NI_RETCODE_INVALID_PARAM
9992  *
9993  * NOTE - the frame upon which intra period is reconfigured is encoded as IDR frame
9994  * NOTE - reconfigure intra period is not allowed if intraRefreshMode is enabled or if gopPresetIdx is 1
9995  *
9996  ******************************************************************************/
9998  int32_t intra_period)
9999 {
10000  if (!p_ctx || intra_period < 0 || intra_period > 1024)
10001  {
10002  ni_log(NI_LOG_ERROR, "ERROR: %s(): invalid intraPeriod passed in %d\n",
10003  __func__, intra_period);
10004  return NI_RETCODE_INVALID_PARAM;
10005  }
10006  ni_pthread_mutex_lock(&p_ctx->mutex);
10008 
10009  if (p_ctx->reconfig_intra_period >= 0)
10010  {
10012  "Warning: %s(): intraPeriod %d overwriting current one %d\n",
10013  __func__, intra_period, p_ctx->reconfig_intra_period);
10014  }
10015 
10016  p_ctx->reconfig_intra_period = intra_period;
10017 
10019  ni_pthread_mutex_unlock(&p_ctx->mutex);
10020 
10021  return NI_RETCODE_SUCCESS;
10022 }
10023 
10024 /*!*****************************************************************************
10025  * \brief Reconfigure VUI HRD dynamically during encoding.
10026  *
10027  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10028  * \param[in] bitrate Target bitrate to set
10029  *
10030  * \return On success NI_RETCODE_SUCCESS
10031  * On failure NI_RETCODE_INVALID_PARAM
10032  ******************************************************************************/
10034 {
10035  if (!p_ctx || vui->colorDescPresent < 0 || vui->colorDescPresent > 1)
10036  {
10037  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid colorDescPresent passed in %d\n",
10038  __func__, vui->colorDescPresent);
10039  return NI_RETCODE_INVALID_PARAM;
10040  }
10041 
10043  {
10044  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid aspect ratio passed in (%dx%d)\n",
10045  __func__, vui->aspectRatioWidth, vui->aspectRatioHeight);
10046  return NI_RETCODE_INVALID_PARAM;
10047  }
10048 
10049  if (vui->videoFullRange < 0 || vui->videoFullRange > 1)
10050  {
10051  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid videoFullRange passed in %d\n",
10052  __func__, vui->videoFullRange);
10053  return NI_RETCODE_INVALID_PARAM;
10054  }
10055 
10056  ni_pthread_mutex_lock(&p_ctx->mutex);
10058 
10059  p_ctx->vui.colorDescPresent = vui->colorDescPresent;
10060  p_ctx->vui.colorPrimaries = vui->colorPrimaries;
10061  p_ctx->vui.colorTrc = vui->colorTrc;
10062  p_ctx->vui.colorSpace = vui->colorSpace;
10063  p_ctx->vui.aspectRatioWidth = vui->aspectRatioWidth;
10064  p_ctx->vui.aspectRatioHeight = vui->aspectRatioHeight;
10065  p_ctx->vui.videoFullRange = vui->videoFullRange;
10066 
10068  ni_pthread_mutex_unlock(&p_ctx->mutex);
10069 
10070  return NI_RETCODE_SUCCESS;
10071 }
10072 
10073 /*!*****************************************************************************
10074  * \brief Force next frame to be IDR frame during encoding.
10075  *
10076  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10077  *
10078  * \return On success NI_RETCODE_SUCCESS
10079  ******************************************************************************/
10081 {
10082  if (!p_ctx)
10083  {
10084  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10085  __func__);
10086  return NI_RETCODE_INVALID_PARAM;
10087  }
10088  ni_pthread_mutex_lock(&p_ctx->mutex);
10090 
10091  if (p_ctx->force_idr_frame)
10092  {
10093  ni_log2(p_ctx, NI_LOG_DEBUG, "Warning: %s(): already forcing IDR frame\n",
10094  __func__);
10095  }
10096 
10097  p_ctx->force_idr_frame = 1;
10098 
10100  ni_pthread_mutex_unlock(&p_ctx->mutex);
10101 
10102  return NI_RETCODE_SUCCESS;
10103 }
10104 
10105 /*!*****************************************************************************
10106  * \brief Set a frame's support of Long Term Reference frame during encoding.
10107  *
10108  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10109  * \param[in] ltr Pointer to struct specifying LTR support
10110  *
10111  * \return On success NI_RETCODE_SUCCESS
10112  * On failure NI_RETCODE_INVALID_PARAM
10113  ******************************************************************************/
10115 {
10116  if (!p_ctx)
10117  {
10118  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10119  __func__);
10120  return NI_RETCODE_INVALID_PARAM;
10121  }
10122  ni_pthread_mutex_lock(&p_ctx->mutex);
10123 
10127 
10128  ni_pthread_mutex_unlock(&p_ctx->mutex);
10129 
10130  return NI_RETCODE_SUCCESS;
10131 }
10132 
10133 /*!*****************************************************************************
10134  * \brief Set Long Term Reference interval
10135  *
10136  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10137  * \param[in] ltr_interval the new long term reference inteval value
10138  *
10139  * \return On success NI_RETCODE_SUCCESS
10140  * On failure NI_RETCODE_INVALID_PARAM
10141  ******************************************************************************/
10143  int32_t ltr_interval)
10144 {
10145  if (!p_ctx)
10146  {
10147  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10148  __func__);
10149  return NI_RETCODE_INVALID_PARAM;
10150  }
10151  ni_pthread_mutex_lock(&p_ctx->mutex);
10152 
10153  p_ctx->ltr_interval = ltr_interval;
10154 
10155  ni_pthread_mutex_unlock(&p_ctx->mutex);
10156 
10157  return NI_RETCODE_SUCCESS;
10158 }
10159 
10160 /*!*****************************************************************************
10161  * \brief Set frame reference invalidation
10162  *
10163  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10164  * \param[in] frame_num frame number after which all references shall be
10165  * invalidated
10166  *
10167  * \return On success NI_RETCODE_SUCCESS
10168  * On failure NI_RETCODE_INVALID_PARAM
10169  ******************************************************************************/
10171  int32_t frame_num)
10172 {
10173  if (!p_ctx)
10174  {
10175  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
10176  __func__);
10177  return NI_RETCODE_INVALID_PARAM;
10178  }
10179  ni_pthread_mutex_lock(&p_ctx->mutex);
10180  p_ctx->ltr_frame_ref_invalid = frame_num;
10181  ni_pthread_mutex_unlock(&p_ctx->mutex);
10182 
10183  return NI_RETCODE_SUCCESS;
10184 }
10185 
10186 /*!*****************************************************************************
10187  * \brief Reconfigure framerate dynamically during encoding.
10188  *
10189  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10190  * \param[in] framerate Target framerate to set
10191  *
10192  * \return On success NI_RETCODE_SUCCESS
10193  * On failure NI_RETCODE_INVALID_PARAM
10194  ******************************************************************************/
10196  ni_framerate_t *framerate)
10197 {
10198  int32_t framerate_num = framerate->framerate_num;
10199  int32_t framerate_denom = framerate->framerate_denom;
10200  if (!p_ctx || framerate_num <= 0 || framerate_denom <= 0)
10201  {
10202  ni_log2(p_ctx, NI_LOG_ERROR,
10203  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10204  framerate_num, framerate_denom);
10205  return NI_RETCODE_INVALID_PARAM;
10206  }
10207 
10208  if ((framerate_num % framerate_denom) != 0)
10209  {
10210  uint32_t numUnitsInTick = 1000;
10211  framerate_num = framerate_num / framerate_denom;
10212  framerate_denom = numUnitsInTick + 1;
10213  framerate_num += 1;
10214  framerate_num *= numUnitsInTick;
10215  } else
10216  {
10217  framerate_num = framerate_num / framerate_denom;
10218  framerate_denom = 1;
10219  }
10220 
10221  if (((framerate_num + framerate_denom - 1) / framerate_denom) >
10223  {
10224  ni_log2(p_ctx, NI_LOG_ERROR,
10225  "ERROR: %s(): invalid framerate passed in (%d/%d)\n", __func__,
10226  framerate->framerate_num, framerate->framerate_denom);
10227  return NI_RETCODE_INVALID_PARAM;
10228  }
10229 
10230  ni_pthread_mutex_lock(&p_ctx->mutex);
10232 
10233  if (p_ctx->framerate.framerate_num > 0)
10234  {
10235  ni_log2(p_ctx, NI_LOG_DEBUG,
10236  "Warning: %s(): framerate (%d/%d) overwriting current "
10237  "one (%d/%d)\n",
10238  __func__, framerate_num, framerate_denom,
10239  p_ctx->framerate.framerate_num,
10240  p_ctx->framerate.framerate_denom);
10241  }
10242 
10243  p_ctx->framerate.framerate_num = framerate_num;
10244  p_ctx->framerate.framerate_denom = framerate_denom;
10245 
10247  ni_pthread_mutex_unlock(&p_ctx->mutex);
10248 
10249  return NI_RETCODE_SUCCESS;
10250 }
10251 
10252 /*!*****************************************************************************
10253  * \brief Reconfigure maxFrameSize dynamically during encoding.
10254  *
10255  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10256  * \param[in] max_frame_size maxFrameSize to set
10257  *
10258  * \return On success NI_RETCODE_SUCCESS
10259  * On failure NI_RETCODE_INVALID_PARAM
10260  *
10261  * NOTE - maxFrameSize_Bytes value less than ((bitrate / 8) / framerate) will be rejected
10262  *
10263  ******************************************************************************/
10265 {
10266  ni_xcoder_params_t *api_param;
10267  int32_t bitrate, framerate_num, framerate_denom;
10268  uint32_t maxFrameSize = (uint32_t)max_frame_size / 2000;
10269  uint32_t min_maxFrameSize;
10270 
10271  if (!p_ctx || !p_ctx->p_session_config)
10272  {
10273  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10274  __func__);
10275  return NI_RETCODE_INVALID_PARAM;
10276  }
10277 
10278  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10279 
10280  if (!api_param->low_delay_mode)
10281  {
10282  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size is valid only when lowDelay mode is enabled\n",
10283  __func__, max_frame_size);
10284  return NI_RETCODE_INVALID_PARAM;
10285  }
10286 
10287  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10288 
10289  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10290  {
10291  framerate_num = p_ctx->framerate.framerate_num;
10292  framerate_denom = p_ctx->framerate.framerate_denom;
10293  }
10294  else
10295  {
10296  framerate_num = (int32_t) api_param->fps_number;
10297  framerate_denom = (int32_t) api_param->fps_denominator;
10298  }
10299 
10300  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10301 
10302  if (maxFrameSize < min_maxFrameSize)
10303  {
10304  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size %d is too small (invalid)\n",
10305  __func__, max_frame_size);
10306  return NI_RETCODE_INVALID_PARAM;
10307  }
10308  if (max_frame_size > NI_MAX_FRAME_SIZE) {
10309  max_frame_size = NI_MAX_FRAME_SIZE;
10310  }
10311 
10312  ni_pthread_mutex_lock(&p_ctx->mutex);
10314 
10315  if (p_ctx->max_frame_size > 0)
10316  {
10317  ni_log2(p_ctx, NI_LOG_DEBUG,
10318  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10319  __func__, max_frame_size, p_ctx->max_frame_size);
10320  }
10321 
10322  p_ctx->max_frame_size = max_frame_size;
10323 
10325  ni_pthread_mutex_unlock(&p_ctx->mutex);
10326 
10327  return NI_RETCODE_SUCCESS;
10328 }
10329 
10330 /*!*****************************************************************************
10331  * \brief Reconfigure min&max qp dynamically during encoding.
10332  *
10333  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10334  * \param[in] ni_rc_min_max_qp Target min&max qp to set
10335  *
10336  * \return On success NI_RETCODE_SUCCESS
10337  * On failure NI_RETCODE_INVALID_PARAM
10338  ******************************************************************************/
10340  ni_rc_min_max_qp *p_min_max_qp)
10341 {
10342  int32_t minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB;
10343 
10344  if (!p_ctx || !p_min_max_qp)
10345  {
10346  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_min_max_qp pointer\n",
10347  __func__);
10348  return NI_RETCODE_INVALID_PARAM;
10349  }
10350 
10351  minQpI = p_min_max_qp->minQpI;
10352  maxQpI = p_min_max_qp->maxQpI;
10353  maxDeltaQp = p_min_max_qp->maxDeltaQp;
10354  minQpPB = p_min_max_qp->minQpPB;
10355  maxQpPB = p_min_max_qp->maxQpPB;
10356 
10357  if (minQpI > maxQpI || minQpPB > maxQpPB ||
10358  maxQpI > 51 || minQpI < 0 || maxQpPB > 51 || minQpPB < 0)
10359  {
10360  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid qp setting <%d %d %d %d %d>\n",
10361  __func__, minQpI, maxQpI, maxDeltaQp, minQpPB, maxQpPB);
10362  return NI_RETCODE_INVALID_PARAM;
10363  }
10364 
10365  ni_pthread_mutex_lock(&p_ctx->mutex);
10367 
10368  p_ctx->enc_change_params->minQpI = minQpI;
10369  p_ctx->enc_change_params->maxQpI = maxQpI;
10370  p_ctx->enc_change_params->maxDeltaQp = maxDeltaQp;
10371  p_ctx->enc_change_params->minQpPB = minQpPB;
10372  p_ctx->enc_change_params->maxQpPB = maxQpPB;
10373 
10375  ni_pthread_mutex_unlock(&p_ctx->mutex);
10376 
10377  return NI_RETCODE_SUCCESS;
10378 }
10379 
10380 /*!*****************************************************************************
10381  * \brief Reconfigure crf value dynamically during encoding.
10382  *
10383  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10384  * \param[in] crf crf value to reconfigure
10385  *
10386  * \return On success NI_RETCODE_SUCCESS
10387  * On failure NI_RETCODE_INVALID_PARAM
10388  ******************************************************************************/
10390  int32_t crf)
10391 {
10392  ni_xcoder_params_t *api_param;
10393 
10394  if (!p_ctx || !p_ctx->p_session_config)
10395  {
10396  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10397  __func__);
10398  return NI_RETCODE_INVALID_PARAM;
10399  }
10400 
10401  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10402 
10403  if (api_param->cfg_enc_params.crf < 0)
10404  {
10405  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %d is valid only in CRF mode\n",
10406  __func__, crf);
10407  return NI_RETCODE_INVALID_PARAM;
10408  }
10409 
10410  if (crf < 0 || crf > 51)
10411  {
10412  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %d is invalid (valid range in [0..51])\n",
10413  __func__, crf);
10414  return NI_RETCODE_INVALID_PARAM;
10415  }
10416 
10417  ni_pthread_mutex_lock(&p_ctx->mutex);
10418 
10420 
10421  if (p_ctx->reconfig_crf >= 0)
10422  {
10423  ni_log2(p_ctx, NI_LOG_DEBUG,
10424  "Warning: %s(): crf reconfig value %d overwriting current reconfig_crf %d\n",
10425  __func__, crf, p_ctx->reconfig_crf);
10426  }
10427 
10428  p_ctx->reconfig_crf = crf;
10429 
10431 
10432  ni_pthread_mutex_unlock(&p_ctx->mutex);
10433 
10434  return NI_RETCODE_SUCCESS;
10435 }
10436 
10437 /*!*****************************************************************************
10438  * \brief Reconfigure crf float point value dynamically during encoding.
10439  *
10440  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10441  * \param[in] crf crf float point value to reconfigure
10442  *
10443  * \return On success NI_RETCODE_SUCCESS
10444  * On failure NI_RETCODE_INVALID_PARAM
10445  ******************************************************************************/
10447  float crf)
10448 {
10449  ni_xcoder_params_t *api_param;
10450 
10451  if (!p_ctx || !p_ctx->p_session_config)
10452  {
10453  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10454  __func__);
10455  return NI_RETCODE_INVALID_PARAM;
10456  }
10457 
10458  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10459 
10460  if (api_param->cfg_enc_params.crfFloat < 0)
10461  {
10462  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): reconfigure crf value %f is valid only in CRF mode\n",
10463  __func__, crf);
10464  return NI_RETCODE_INVALID_PARAM;
10465  }
10466 
10467  if (crf < 0.0 || crf > 51.0)
10468  {
10469  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): crf value %f is invalid (valid range in [0..51])\n",
10470  __func__, crf);
10471  return NI_RETCODE_INVALID_PARAM;
10472  }
10473 
10474  ni_pthread_mutex_lock(&p_ctx->mutex);
10475 
10477 
10478  if (p_ctx->reconfig_crf >= 0 || p_ctx->reconfig_crf_decimal > 0)
10479  {
10480  ni_log2(p_ctx, NI_LOG_DEBUG,
10481  "Warning: %s(): crf reconfig value %d overwriting current "
10482  "reconfig_crf %d, reconfig_crf_decimal %d\n", __func__,
10483  crf, p_ctx->reconfig_crf, p_ctx->reconfig_crf_decimal);
10484  }
10485 
10486  p_ctx->reconfig_crf = (int)crf;
10487  p_ctx->reconfig_crf_decimal = (int)((crf - (float)p_ctx->reconfig_crf) * 100);
10488 
10490 
10491  ni_pthread_mutex_unlock(&p_ctx->mutex);
10492 
10493  return NI_RETCODE_SUCCESS;
10494 }
10495 
10496 /*!*****************************************************************************
10497  * \brief Reconfigure vbv buffer size and vbv max rate dynamically during encoding.
10498  *
10499  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10500  * \param[in] vbvBufferSize Target vbvBufferSize to set
10501  * \param[in] vbvMaxRate Target vbvMaxRate to set
10502  *
10503  * \return On success NI_RETCODE_SUCCESS
10504  * On failure NI_RETCODE_INVALID_PARAM
10505  ******************************************************************************/
10507  int32_t vbvMaxRate, int32_t vbvBufferSize)
10508 {
10509  ni_xcoder_params_t *api_param;
10510  if (!p_ctx || !p_ctx->p_session_config)
10511  {
10512  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10513  __func__);
10514  return NI_RETCODE_INVALID_PARAM;
10515  }
10516  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
10517  {
10518  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): vbvBufferSize value %d\n",
10519  __func__, vbvBufferSize);
10520  return NI_RETCODE_INVALID_PARAM;
10521  }
10522  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10523  if (api_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < api_param->bitrate) {
10524  ni_log2(p_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
10525  vbvMaxRate, api_param->bitrate);
10526  return NI_RETCODE_INVALID_PARAM;
10527  }
10528  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
10529  ni_log2(p_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
10530  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
10531  vbvMaxRate);
10532  vbvMaxRate = 0;
10533  }
10534 
10535  ni_pthread_mutex_lock(&p_ctx->mutex);
10537 
10538  p_ctx->reconfig_vbv_buffer_size = vbvBufferSize;
10539  p_ctx->reconfig_vbv_max_rate = vbvMaxRate;
10540 
10542  ni_pthread_mutex_unlock(&p_ctx->mutex);
10543 
10544  return NI_RETCODE_SUCCESS;
10545 }
10546 
10547 /*!*****************************************************************************
10548  * \brief Reconfigure maxFrameSizeRatio dynamically during encoding.
10549  *
10550  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10551  * \param[in] max_frame_size_ratio maxFrameSizeRatio to set
10552  *
10553  * \return On success NI_RETCODE_SUCCESS
10554  * On failure NI_RETCODE_INVALID_PARAM
10555  ******************************************************************************/
10557 {
10558  ni_xcoder_params_t *api_param;
10559  int32_t bitrate, framerate_num, framerate_denom;
10560  uint32_t min_maxFrameSize, maxFrameSize;
10561 
10562  if (!p_ctx || !p_ctx->p_session_config)
10563  {
10564  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10565  __func__);
10566  return NI_RETCODE_INVALID_PARAM;
10567  }
10568 
10569  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10570 
10571  if (!api_param->low_delay_mode)
10572  {
10573  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio is valid only when lowDelay mode is enabled\n",
10574  __func__, max_frame_size_ratio);
10575  return NI_RETCODE_INVALID_PARAM;
10576  }
10577 
10578  if (max_frame_size_ratio < 1) {
10579  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): max_frame_size_ratio %d cannot < 1\n",
10580  max_frame_size_ratio);
10581  return NI_RETCODE_INVALID_PARAM;
10582  }
10583 
10584  bitrate = (p_ctx->target_bitrate > 0) ? p_ctx->target_bitrate : api_param->bitrate;
10585 
10586  if ((p_ctx->framerate.framerate_num > 0) && (p_ctx->framerate.framerate_denom > 0))
10587  {
10588  framerate_num = p_ctx->framerate.framerate_num;
10589  framerate_denom = p_ctx->framerate.framerate_denom;
10590  }
10591  else
10592  {
10593  framerate_num = (int32_t) api_param->fps_number;
10594  framerate_denom = (int32_t) api_param->fps_denominator;
10595  }
10596 
10597  min_maxFrameSize = (((uint32_t)bitrate / framerate_num * framerate_denom) / 8) / 2000;
10598 
10599  maxFrameSize = min_maxFrameSize * max_frame_size_ratio > NI_MAX_FRAME_SIZE ?
10600  NI_MAX_FRAME_SIZE : min_maxFrameSize * max_frame_size_ratio;
10601 
10602  ni_pthread_mutex_lock(&p_ctx->mutex);
10604 
10605  if (p_ctx->max_frame_size > 0)
10606  {
10607  ni_log2(p_ctx, NI_LOG_DEBUG,
10608  "Warning: %s(): max_frame_size %d overwriting current one %d\n",
10609  __func__, maxFrameSize, p_ctx->max_frame_size);
10610  }
10611 
10612  p_ctx->max_frame_size = maxFrameSize;
10613 
10615  ni_pthread_mutex_unlock(&p_ctx->mutex);
10616 
10617  return NI_RETCODE_SUCCESS;
10618 }
10619 
10620 /*!*****************************************************************************
10621  * \brief Reconfigure sliceArg dynamically during encoding.
10622  *
10623  * \param[in] p_ctx Pointer to caller allocated ni_session_context_t
10624  * \param[in] sliceArg the new sliceArg value
10625  *
10626  * \return On success NI_RETCODE_SUCCESS
10627  * On failure NI_RETCODE_INVALID_PARAM
10628  ******************************************************************************/
10630 {
10631  ni_xcoder_params_t *api_param;
10632  ni_encoder_cfg_params_t *p_enc;
10633 
10634  if (!p_ctx || !p_ctx->p_session_config)
10635  {
10636  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid ni_session_context_t or p_session_config pointer\n",
10637  __func__);
10638  return NI_RETCODE_INVALID_PARAM;
10639  }
10640 
10641  api_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
10642  p_enc = &api_param->cfg_enc_params;
10643  if (p_enc->slice_mode == 0)
10644  {
10645  ni_log2(p_ctx, NI_LOG_ERROR, "%s():not support to reconfig slice_arg when slice_mode disable.\n",
10646  __func__);
10647  sliceArg = 0;
10648  }
10650  {
10651  ni_log2(p_ctx, NI_LOG_ERROR, "%s():sliceArg is only supported for H.264 or H.265.\n",
10652  __func__);
10653  sliceArg = 0;
10654  }
10655  int ctu_mb_size = (NI_CODEC_FORMAT_H264 == p_ctx->codec_format) ? 16 : 64;
10656  int max_num_ctu_mb_row = (api_param->source_height + ctu_mb_size - 1) / ctu_mb_size;
10657  if (sliceArg < 1 || sliceArg > max_num_ctu_mb_row)
10658  {
10659  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid data sliceArg %d\n", __func__,
10660  sliceArg);
10661  sliceArg = 0;
10662  }
10663 
10664  ni_pthread_mutex_lock(&p_ctx->mutex);
10666 
10667  p_ctx->reconfig_slice_arg = sliceArg;
10668 
10670  ni_pthread_mutex_unlock(&p_ctx->mutex);
10671 
10672  return NI_RETCODE_SUCCESS;
10673 }
10674 
10675 #ifndef _WIN32
10676 /*!*****************************************************************************
10677 * \brief Acquire a P2P frame buffer from the hwupload session
10678 *
10679 * \param[in] p_ctx Pointer to a caller allocated
10680 * ni_session_context_t struct
10681 * \param[out] p_frame Pointer to a caller allocated hw frame
10682 *
10683 * \return On success
10684 * NI_RETCODE_SUCCESS
10685 * On failure
10686 * NI_RETCODE_INVALID_PARAM
10687 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10688 * NI_RETCODE_ERROR_INVALID_SESSION
10689 *******************************************************************************/
10691 {
10693  struct netint_iocmd_export_dmabuf uexp;
10694  unsigned int offset;
10695  int ret, is_semi_planar;
10696  int linestride[NI_MAX_NUM_DATA_POINTERS];
10697  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10698  niFrameSurface1_t hwdesc = {0};
10699  niFrameSurface1_t *p_surface;
10700 
10701  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10702  {
10703  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10704  __func__);
10705  return NI_RETCODE_INVALID_PARAM;
10706  }
10707 
10708  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10709 
10710  ni_pthread_mutex_lock(&p_ctx->mutex);
10712 
10713  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10714 
10716  ni_pthread_mutex_unlock(&p_ctx->mutex);
10717 
10718  if (retval != NI_RETCODE_SUCCESS)
10719  {
10720  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10721  return retval;
10722  }
10723 
10724  retval = ni_get_memory_offset(p_ctx, &hwdesc, &offset);
10725  if (retval != NI_RETCODE_SUCCESS)
10726  {
10727  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: bad buffer id\n");
10728  return NI_RETCODE_INVALID_PARAM;
10729  }
10730 
10731  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
10732  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
10733  1 :
10734  0;
10735 
10737  p_ctx->bit_depth_factor, is_semi_planar, linestride,
10738  alignedheight);
10739 
10740  uexp.fd = -1;
10741  uexp.flags = 0;
10742  uexp.offset = offset;
10743 
10744  uexp.length = ni_calculate_total_frame_size(p_ctx, linestride);
10745  uexp.domain = p_ctx->domain;
10746  uexp.bus = p_ctx->bus;
10747  uexp.dev = p_ctx->dev;
10748  uexp.fn = p_ctx->fn;
10749  uexp.bar = 4; // PCI BAR4 configuration space
10750 
10751  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
10752  if (ret < 0)
10753  {
10754  ni_log2(p_ctx, NI_LOG_ERROR, "%s: Failed to export dmabuf %d errno %d\n",
10755  __func__, ret, NI_ERRNO);
10756  return NI_RETCODE_FAILURE;
10757  }
10758 
10759  *p_surface = hwdesc;
10760  p_surface->ui16width = p_ctx->active_video_width;
10761  p_surface->ui16height = p_ctx->active_video_height;
10762  p_surface->ui32nodeAddress = offset;
10763  p_surface->encoding_type = is_semi_planar ?
10766  p_surface->dma_buf_fd = uexp.fd;
10767 
10768  return retval;
10769 }
10770 
10771 /*!*****************************************************************************
10772 * \brief Acquire a P2P frame buffer from the hwupload session for P2P read
10773 *
10774 * \param[in] p_ctx Pointer to a caller allocated
10775 * ni_session_context_t struct
10776 * \param[out] p_frame Pointer to a caller allocated hw frame
10777 *
10778 * \return On success
10779 * NI_RETCODE_SUCCESS
10780 * On failure
10781 * NI_RETCODE_INVALID_PARAM
10782 * NI_RETCODE_ERROR_NVME_CMD_FAILED
10783 * NI_RETCODE_ERROR_INVALID_SESSION
10784 *******************************************************************************/
10786 {
10788 
10789  int is_semi_planar;
10790  int linestride[NI_MAX_NUM_DATA_POINTERS];
10791  int alignedheight[NI_MAX_NUM_DATA_POINTERS];
10792  niFrameSurface1_t hwdesc = {0};
10793  niFrameSurface1_t *p_surface;
10794 
10795  if (p_ctx == NULL || p_frame == NULL || p_frame->p_data[3] == NULL)
10796  {
10797  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null!, return\n",
10798  __func__);
10799  return NI_RETCODE_INVALID_PARAM;
10800  }
10801 
10802  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10803 
10804  ni_pthread_mutex_lock(&p_ctx->mutex);
10806 
10807  retval = ni_hwupload_session_read_hwdesc(p_ctx, &hwdesc);
10808 
10810  ni_pthread_mutex_unlock(&p_ctx->mutex);
10811 
10812  if (retval != NI_RETCODE_SUCCESS)
10813  {
10814  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: hwdesc read failure %d\n", retval);
10815  return retval;
10816  }
10817 
10818  is_semi_planar = ((p_ctx->pixel_format == NI_PIX_FMT_NV12) ||
10819  p_ctx->pixel_format == NI_PIX_FMT_P010LE) ?
10820  1 :
10821  0;
10822 
10824  p_ctx->bit_depth_factor, is_semi_planar, linestride,
10825  alignedheight);
10826 
10827  *p_surface = hwdesc;
10828  p_surface->ui16width = p_ctx->active_video_width;
10829  p_surface->ui16height = p_ctx->active_video_height;
10830  p_surface->ui32nodeAddress = 0;
10831  p_surface->encoding_type = is_semi_planar ?
10834  p_surface->dma_buf_fd = 0;
10835 
10836  return retval;
10837 }
10838 
10839 
10840 /*!*****************************************************************************
10841  * \brief Lock a hardware P2P frame prior to encoding
10842  *
10843  * \param[in] p_upl_ctx pointer to caller allocated upload context
10844  * [in] p_frame pointer to caller allocated hardware P2P frame
10845  *
10846  * \return On success
10847  * NI_RETCODE_SUCCESS
10848  * On failure NI_RETCODE_FAILURE
10849  * NI_RETCODE_INVALID_PARAM
10850 *******************************************************************************/
10852  ni_frame_t *p_frame)
10853 {
10854  int ret;
10855  struct netint_iocmd_attach_rfence uatch = {0};
10856  struct pollfd pfds[1] = {0};
10857  niFrameSurface1_t *p_surface;
10858 
10859  if (p_upl_ctx == NULL || p_frame == NULL)
10860  {
10861  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: bad parameters\n", __func__);
10862  return NI_RETCODE_INVALID_PARAM;
10863  }
10864 
10865  if (p_frame->p_data[3] == NULL)
10866  {
10867  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: not a hardware frame\n", __func__);
10868  return NI_RETCODE_INVALID_PARAM;
10869  }
10870 
10871  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10872 
10873  pfds[0].fd = p_surface->dma_buf_fd;
10874  pfds[0].events = POLLIN;
10875  pfds[0].revents = 0;
10876 
10877  ret = poll(pfds, 1, -1);
10878  if (ret < 0)
10879  {
10880  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s:failed to poll dmabuf fd errno %s\n", __func__,
10881  strerror(NI_ERRNO));
10882  return ret;
10883  }
10884 
10885  uatch.fd = p_surface->dma_buf_fd;
10886  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ATTACH_RFENCE, &uatch);
10887  if (ret < 0)
10888  {
10889  ni_log2(p_upl_ctx, NI_LOG_ERROR,
10890  "%s: failed to attach dmabuf read fence errno %s\n", __func__,
10891  strerror(NI_ERRNO));
10892  return ret;
10893  }
10894 
10895  return NI_RETCODE_SUCCESS;
10896 }
10897 
10898 /*!*****************************************************************************
10899  * \brief Unlock a hardware P2P frame after encoding
10900  *
10901  * \param[in] p_upl_ctx pointer to caller allocated upload context
10902  * [in] p_frame pointer to caller allocated hardware P2P frame
10903  *
10904  * \return On success
10905  * NI_RETCODE_SUCCESS
10906  * On failure NI_RETCODE_FAILURE
10907  * NI_RETCODE_INVALID_PARAM
10908 *******************************************************************************/
10910  ni_frame_t *p_frame)
10911 {
10912  int ret;
10913  struct netint_iocmd_signal_rfence usigl = {0};
10914  niFrameSurface1_t *p_surface;
10915 
10916  if ((p_upl_ctx == NULL) || (p_frame == NULL))
10917  {
10918  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid parameters %p %p\n", __func__,
10919  p_upl_ctx, p_frame);
10920  return NI_RETCODE_INVALID_PARAM;
10921  }
10922 
10923  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
10924 
10925  if (p_surface == NULL)
10926  {
10927  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
10928  return NI_RETCODE_INVALID_PARAM;
10929  }
10930 
10931  usigl.fd = p_surface->dma_buf_fd;
10932  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_SIGNAL_RFENCE, &usigl);
10933  if (ret < 0)
10934  {
10935  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Failed to signal dmabuf read fence\n");
10936  return NI_RETCODE_FAILURE;
10937  }
10938 
10939  return NI_RETCODE_SUCCESS;
10940 }
10941 
10942 /*!*****************************************************************************
10943  * \brief Special P2P test API function. Copies YUV data from the software
10944  * frame to the hardware P2P frame on the Quadra device
10945  *
10946  * \param[in] p_upl_ctx pointer to caller allocated uploader session
10947  * context
10948  * [in] p_swframe pointer to a caller allocated software frame
10949  * [in] p_hwframe pointer to a caller allocated hardware frame
10950  *
10951  * \return On success
10952  * NI_RETCODE_SUCCESS
10953  * On failure
10954  * NI_RETCODE_FAILURE
10955  * NI_RETCODE_INVALID_PARAM
10956 *******************************************************************************/
10958  uint8_t *p_data, uint32_t len,
10959  ni_frame_t *p_hwframe)
10960 {
10961  int ret;
10962  struct netint_iocmd_issue_request uis = {0};
10963  niFrameSurface1_t *p_surface;
10964 
10965  if (p_upl_ctx == NULL || p_data == NULL || p_hwframe == NULL)
10966  {
10967  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: invalid null parameters\n", __func__);
10968  return NI_RETCODE_INVALID_PARAM;
10969  }
10970 
10971  if (p_hwframe->p_data[3] == NULL)
10972  {
10973  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: empty frame\n", __func__);
10974  return NI_RETCODE_INVALID_PARAM;
10975  }
10976 
10977  p_surface = (niFrameSurface1_t *)p_hwframe->p_data[3];
10978 
10979  uis.fd = p_surface->dma_buf_fd;
10980  uis.data = p_data;
10981  uis.len = len;
10983 
10984  ret = ioctl(p_upl_ctx->netint_fd, NETINT_IOCTL_ISSUE_REQ, &uis);
10985  if (ret < 0)
10986  {
10987  ni_log2(p_upl_ctx, NI_LOG_ERROR,
10988  "%s: Failed to request dmabuf rendering errno %d\n", __func__,
10989  NI_ERRNO);
10990  return NI_RETCODE_FAILURE;
10991  }
10992 
10993  return NI_RETCODE_SUCCESS;
10994 }
10995 
10996 /*!*****************************************************************************
10997  * \brief Special P2P test API function. Copies video data from the software
10998  * frame to the hardware P2P frame on the Quadra device. Does not
10999  * need the Netint kernel driver but requires root privilege.
11000  *
11001  * \param[in] p_upl_ctx pointer to caller allocated uploader session
11002  * context
11003  * [in] p_swframe pointer to a caller allocated software frame
11004  * [in] p_hwframe pointer to a caller allocated hardware frame
11005  *
11006  * \return On success
11007  * NI_RETCODE_SUCCESS
11008  * On failure
11009  * NI_RETCODE_FAILURE
11010  * NI_RETCODE_INVALID_PARAM
11011 *******************************************************************************/
11013  uint8_t *p_data, uint32_t len,
11014  ni_frame_t *p_hwframe)
11015 {
11016  int bar4_fd, ret;
11017  char bar4_name[128];
11018  char *bar4_mm;
11019  struct stat stat;
11020  niFrameSurface1_t *pSurf;
11021  uint32_t offset;
11022 
11023  pSurf = (niFrameSurface1_t *) p_hwframe->p_data[3];
11024 
11025  ret = ni_get_memory_offset(p_upl_ctx, pSurf, &offset);
11026  if (ret != 0)
11027  {
11028  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Error bad buffer id\n");
11029  return NI_RETCODE_FAILURE;
11030  }
11031 
11032  snprintf(bar4_name, 128,
11033  "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/resource4",
11034  p_upl_ctx->domain,p_upl_ctx->bus,p_upl_ctx->dev,p_upl_ctx->fn);
11035 
11036  bar4_fd = open(bar4_name, O_RDWR | O_SYNC);
11037 
11038  if (bar4_fd < 0)
11039  {
11040  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't open bar4 %s (%s)\n",
11041  bar4_name, strerror(errno));
11042  return NI_RETCODE_FAILURE;
11043  }
11044 
11045  if (fstat(bar4_fd, &stat) != 0)
11046  {
11047  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't stat bar4 (%s)\n",
11048  strerror(errno));
11049  close(bar4_fd);
11050  return NI_RETCODE_FAILURE;
11051  }
11052 
11053  bar4_mm = mmap(NULL, stat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED, bar4_fd, 0);
11054 
11055  if (bar4_mm == MAP_FAILED)
11056  {
11057  ni_log2(p_upl_ctx, NI_LOG_ERROR, "Can't mmap to bar4 (%s)\n",
11058  strerror(errno));
11059  close(bar4_fd);
11060  return NI_RETCODE_FAILURE;
11061  }
11062 
11063  /* Copy the data directly into Quadra video memory */
11064  memcpy(bar4_mm + offset, p_data, len);
11065 
11066  munmap(bar4_mm, 0);
11067  close(bar4_fd);
11068 
11069  return NI_RETCODE_SUCCESS;
11070 }
11071 
11072 
11073 /*!*****************************************************************************
11074  * \brief Recycle hw P2P frames
11075  *
11076  * \param [in] p_frame pointer to an acquired P2P hw frame
11077  *
11078  * \return on success
11079  * NI_RETCODE_SUCCESS
11080  *
11081  * on failure
11082  * NI_RETCODE_INVALID_PARAM
11083 *******************************************************************************/
11085 {
11086  niFrameSurface1_t *p_surface;
11087 
11088  if (p_frame == NULL)
11089  {
11090  ni_log(NI_LOG_ERROR, "%s: Invalid frame\n", __func__);
11091  return NI_RETCODE_INVALID_PARAM;
11092  }
11093 
11094  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11095  if (p_surface == NULL)
11096  {
11097  ni_log(NI_LOG_ERROR, "%s: Invalid surface data\n", __func__);
11098  return NI_RETCODE_INVALID_PARAM;
11099  }
11100 
11101  return ni_hwframe_buffer_recycle2(p_surface);
11102 }
11103 
11104 /*!*****************************************************************************
11105  * \brief Acquire the scaler P2P DMA buffer for read/write
11106  *
11107  * \param [in] p_ctx pointer to caller allocated upload context
11108  * [in] p_surface pointer to a caller allocated hardware frame
11109  * [in] data_len scaler frame buffer data length
11110  *
11111  * \return on success
11112  * NI_RETCODE_SUCCESS
11113  *
11114  * on failure
11115  * NI_RETCODE_FAILURE
11116 *******************************************************************************/
11118  niFrameSurface1_t *p_surface,
11119  int data_len)
11120 {
11121  unsigned int offset;
11122  int ret;
11123 
11124  ret = ni_get_memory_offset(p_ctx, p_surface, &offset);
11125  if (ret != 0)
11126  {
11127  ni_log2(p_ctx, NI_LOG_ERROR, "Error: bad buffer id\n");
11128  return NI_RETCODE_FAILURE;
11129  }
11130  p_surface->ui32nodeAddress = 0;
11131 
11132  struct netint_iocmd_export_dmabuf uexp;
11133  uexp.fd = -1;
11134  uexp.flags = 0;
11135  uexp.offset = offset;
11136  uexp.length = data_len;
11137  uexp.domain = p_ctx->domain;
11138  uexp.bus = p_ctx->bus;
11139  uexp.dev = p_ctx->dev;
11140  uexp.fn = p_ctx->fn;
11141  uexp.bar = 4;
11142  ret = ioctl(p_ctx->netint_fd, NETINT_IOCTL_EXPORT_DMABUF, &uexp);
11143  if (ret < 0)
11144  {
11145  ni_log2(p_ctx, NI_LOG_ERROR, "failed to export dmabuf: %s\n", strerror(errno));
11146  return NI_RETCODE_FAILURE;
11147  }
11148  p_surface->dma_buf_fd = uexp.fd;
11149  return ret;
11150 }
11151 #endif
11152 
11153 /*!*****************************************************************************
11154  * \brief Set the incoming frame format for the encoder
11155  *
11156  * \param[in] p_enc_ctx pointer to encoder context
11157  * [in] p_enc_params pointer to encoder parameters
11158  * [in] width input width
11159  * [in] height input height
11160  * [in] bit_depth 8 for 8-bit YUV, 10 for 10-bit YUV
11161  * [in] src_endian NI_FRAME_LITTLE_ENDIAN or NI_FRAME_BIG_ENDIAN
11162  * [in] planar 0 for semi-planar YUV, 1 for planar YUV
11163  *
11164  * \return on success
11165  * NI_RETCODE_SUCCESS
11166  *
11167  * on failure
11168  * NI_RETCODE_INVALID_PARAM
11169  *
11170 *******************************************************************************/
11172  ni_xcoder_params_t *p_enc_params,
11173  int width, int height,
11174  int bit_depth, int src_endian,
11175  int planar)
11176 {
11177  int alignedw;
11178  int alignedh;
11179 
11180  if (p_enc_ctx == NULL || p_enc_params == NULL)
11181  {
11182  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11183  return NI_RETCODE_INVALID_PARAM;
11184  }
11185 
11186  if (!(bit_depth == 8) && !(bit_depth == 10))
11187  {
11188  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad bit depth %d\n", __func__, bit_depth);
11189  return NI_RETCODE_INVALID_PARAM;
11190  }
11191 
11192  if (!(src_endian == NI_FRAME_LITTLE_ENDIAN) &&
11193  !(src_endian == NI_FRAME_BIG_ENDIAN))
11194  {
11195  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad endian %d\n", __func__, src_endian);
11196  return NI_RETCODE_INVALID_PARAM;
11197  }
11198 
11199  if ((planar < 0) || (planar >= NI_PIXEL_PLANAR_MAX))
11200  {
11201  ni_log2(p_enc_ctx, NI_LOG_ERROR, "%s: bad planar value %d\n", __func__, planar);
11202  return NI_RETCODE_INVALID_PARAM;
11203  }
11204 
11205  p_enc_ctx->src_bit_depth = bit_depth;
11206  p_enc_ctx->bit_depth_factor = (bit_depth == 8) ? 1 : 2;
11207  p_enc_ctx->src_endian = src_endian;
11208 
11209  alignedw = width;
11210 
11211  if (alignedw < NI_MIN_WIDTH)
11212  {
11213  p_enc_params->cfg_enc_params.conf_win_right +=
11214  (NI_MIN_WIDTH - width) / 2 * 2;
11215  alignedw = NI_MIN_WIDTH;
11216  } else
11217  {
11218  alignedw = ((width + 1) / 2) * 2;
11219  p_enc_params->cfg_enc_params.conf_win_right +=
11220  (alignedw - width) / 2 * 2;
11221  }
11222 
11223  p_enc_params->source_width = alignedw;
11224  alignedh = height;
11225 
11226  if (alignedh < NI_MIN_HEIGHT)
11227  {
11228  p_enc_params->cfg_enc_params.conf_win_bottom +=
11229  (NI_MIN_HEIGHT - height) / 2 * 2;
11230  alignedh = NI_MIN_HEIGHT;
11231  } else
11232  {
11233  alignedh = ((height + 1) / 2) * 2;
11234  p_enc_params->cfg_enc_params.conf_win_bottom +=
11235  (alignedh - height) / 2 * 2;
11236  }
11237 
11238  p_enc_params->source_height = alignedh;
11239  p_enc_params->cfg_enc_params.planar = planar;
11240 
11241  return NI_RETCODE_SUCCESS;
11242 }
11243 
11244 /*!*****************************************************************************
11245  * \brief Set the outgoing frame format for the uploader
11246  *
11247  * \param[in] p_upl_ctx pointer to uploader context
11248  * [in] width width
11249  * [in] height height
11250  * [in] pixel_format pixel format
11251  * [in] isP2P 0 = normal, 1 = P2P
11252  *
11253  * \return on success
11254  * NI_RETCODE_SUCCESS
11255  *
11256  * on failure
11257  * NI_RETCODE_INVALID_PARAM
11258 *******************************************************************************/
11260  int width, int height,
11261  ni_pix_fmt_t pixel_format, int isP2P)
11262 {
11263  if (p_upl_ctx == NULL)
11264  {
11265  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: null ptr\n", __func__);
11266  return NI_RETCODE_INVALID_PARAM;
11267  }
11268 
11269  switch (pixel_format)
11270  {
11271  case NI_PIX_FMT_YUV420P:
11272  case NI_PIX_FMT_NV12:
11273  p_upl_ctx->src_bit_depth = 8;
11274  p_upl_ctx->bit_depth_factor = 1;
11275  break;
11277  case NI_PIX_FMT_P010LE:
11278  p_upl_ctx->src_bit_depth = 10;
11279  p_upl_ctx->bit_depth_factor = 2;
11280  break;
11281  case NI_PIX_FMT_RGBA:
11282  case NI_PIX_FMT_BGRA:
11283  case NI_PIX_FMT_ARGB:
11284  case NI_PIX_FMT_ABGR:
11285  case NI_PIX_FMT_BGR0:
11286  case NI_PIX_FMT_BGRP:
11287  p_upl_ctx->src_bit_depth = 8;
11288  p_upl_ctx->bit_depth_factor = 4;
11289  break;
11290  default:
11291  ni_log2(p_upl_ctx, NI_LOG_ERROR, "%s: Invalid pixfmt %d\n", __func__,
11292  pixel_format);
11293  return NI_RETCODE_INVALID_PARAM;
11294  }
11295 
11296  p_upl_ctx->src_endian = NI_FRAME_LITTLE_ENDIAN;
11297  p_upl_ctx->pixel_format = pixel_format;
11298  p_upl_ctx->active_video_width = width;
11299  p_upl_ctx->active_video_height = height;
11300  p_upl_ctx->isP2P = isP2P;
11301 
11302  return NI_RETCODE_SUCCESS;
11303 }
11304 
11305 /*!*****************************************************************************
11306  * \brief Read encoder stream header from the device
11307  *
11308  * \param[in] p_ctx Pointer to a caller allocated
11309  * ni_session_context_t struct from encoder
11310  * \param[in] p_data Pointer to a caller allocated ni_session_data_io_t
11311  * struct which contains a ni_packet_t data packet to
11312  * receive
11313  * \return On success
11314  * Total number of bytes read
11315  * On failure
11316  * NI_RETCODE_INVALID_PARAM
11317  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11318  * NI_RETCODE_ERROR_INVALID_SESSION
11319 *******************************************************************************/
11321  ni_session_data_io_t *p_data)
11322 {
11323  int rx_size;
11324  int done = 0;
11325  int bytes_read = 0;
11326 
11327  /* This function should be called once at the start of encoder read */
11328  if (p_ctx->pkt_num != 0)
11329  {
11330  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11332  }
11333 
11334  while (!done)
11335  {
11336  rx_size = ni_device_session_read(p_ctx, p_data, NI_DEVICE_TYPE_ENCODER);
11337 
11338  if (rx_size > (int)p_ctx->meta_size)
11339  {
11340  /* stream header has been read, return size */
11341  bytes_read += (rx_size - (int)p_ctx->meta_size);
11342 
11343  p_ctx->pkt_num = 1;
11344  ni_log2(p_ctx, NI_LOG_DEBUG, "Got encoded stream header\n");
11345  done = 1;
11346  } else if (rx_size != 0)
11347  {
11348  ni_log2(p_ctx, NI_LOG_ERROR, "Error: received rx_size = %d\n", rx_size);
11349  bytes_read = -1;
11350  done = 1;
11351  } else
11352  {
11353  ni_log2(p_ctx, NI_LOG_DEBUG, "No data, keep reading..\n");
11354  continue;
11355  }
11356  }
11357 
11358  return bytes_read;
11359 }
11360 
11361 /*!*****************************************************************************
11362  * \brief Get the DMA buffer file descriptor from the P2P frame
11363  *
11364  * \param[in] p_frame pointer to a P2P frame
11365  *
11366  * \return On success
11367  * DMA buffer file descriptor
11368  * On failure
11369  * NI_RETCODE_INVALID_PARAM
11370 *******************************************************************************/
11372 {
11373  const niFrameSurface1_t *p_surface;
11374 
11375  if (p_frame == NULL)
11376  {
11377  ni_log(NI_LOG_ERROR, "%s: NULL frame\n", __func__);
11378  return NI_RETCODE_INVALID_PARAM;
11379  }
11380 
11381  p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
11382 
11383  if (p_surface == NULL)
11384  {
11385  ni_log(NI_LOG_ERROR, "%s: Invalid hw frame\n", __func__);
11386  return NI_RETCODE_INVALID_PARAM;
11387  }
11388 
11389  return p_surface->dma_buf_fd;
11390 }
11391 
11392 /*!*****************************************************************************
11393  * \brief Send sequence change information to device
11394  *
11395  * \param[in] p_ctx Pointer to a caller allocated
11396  * ni_session_context_t struct
11397  * \param[in] width input width
11398  * \param[in] height input height
11399  * \param[in] bit_depth_factor 1 for 8-bit YUV, 2 for 10-bit YUV
11400  * \param[in] device_type device type (must be encoder)
11401  * \return On success
11402  * NI_RETCODE_SUCCESS
11403  * On failure
11404  * NI_RETCODE_INVALID_PARAM
11405  * NI_RETCODE_ERROR_MEM_ALOC
11406  * NI_RETCODE_ERROR_NVME_CMD_FAILED
11407  * NI_RETCODE_ERROR_INVALID_SESSION
11408  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
11409  ******************************************************************************/
11411  int width, int height, int bit_depth_factor, ni_device_type_t device_type)
11412 {
11413  ni_resolution_t resolution;
11415  ni_xcoder_params_t *p_param = NULL;
11416 
11417  // requires API version >= 54
11419  "54") < 0)
11420  {
11421  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
11423  }
11424 
11425  /* This function should be called only if sequence change is detected */
11427  {
11428  ni_log2(p_ctx, NI_LOG_ERROR, "Error: stream header has already been read\n");
11430  }
11431 
11432  resolution.width = width;
11433  resolution.height = height;
11434  resolution.bit_depth_factor = bit_depth_factor;
11435  resolution.luma_linesize = 0;
11436  resolution.chroma_linesize = 0;
11437  if (p_ctx->p_session_config)
11438  {
11439  ni_encoder_cfg_params_t *p_enc;
11440  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
11441  p_enc = &p_param->cfg_enc_params;
11442  if (p_enc->spatial_layers > 1)
11443  {
11444  retval = NI_RETCODE_INVALID_PARAM;
11445  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported when spatialLayers > 1\n");
11446  return retval;
11447  }
11448  resolution.luma_linesize = p_param->luma_linesize;
11449  resolution.chroma_linesize = p_param->chroma_linesize;
11450  }
11451  else
11452  {
11454  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: invalid p_session_config\n");
11455  return retval;
11456  }
11457 
11458  ni_log2(p_ctx, NI_LOG_DEBUG, "%s: resolution change config - width %d height %d bit_depth_factor %d "
11459  "luma_linesize %d chroma_linesize %d\n", __func__,
11460  resolution.width, resolution.height, resolution.bit_depth_factor,
11461  resolution.luma_linesize, resolution.chroma_linesize);
11462 
11463  switch (device_type)
11464  {
11466  {
11467  // config sequence change
11468  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
11469  break;
11470  }
11471  default:
11472  {
11473  retval = NI_RETCODE_INVALID_PARAM;
11474  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: Config sequence change not supported for device type: %d", device_type);
11475  return retval;
11476  }
11477  }
11478  return retval;
11479 }
11480 
11482  ni_network_perf_metrics_t *p_metrics)
11483 {
11484  return ni_ai_session_query_metrics(p_ctx, p_metrics);
11485 }
11486 
11487 ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle,
11488  ni_device_info_t *p_dev_info)
11489 {
11490  void *buffer;
11491  uint32_t size;
11492  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11493  ni_log_fl_fw_versions_t fl_fw_versions;
11494 
11495  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_info))
11496  {
11497  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11498  __func__);
11499  return NI_RETCODE_INVALID_PARAM;
11500  }
11501 
11503  "6h") < 0)
11504  {
11506  "ERROR: %s function not supported on device with FW API version < 6.h\n",
11507  __func__);
11509  }
11510 
11511  buffer = NULL;
11513 
11514  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11515  {
11516  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11518  }
11519 
11520  memset(buffer, 0, size);
11521 
11522  if (ni_nvme_send_read_cmd(device_handle,
11523  event_handle,
11524  buffer,
11525  size,
11526  QUERY_GET_VERSIONS_R) < 0)
11527  {
11528  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11529  ni_aligned_free(buffer);
11531  }
11532 
11533  memcpy(&fl_fw_versions, buffer, sizeof(ni_log_fl_fw_versions_t));
11534 
11535  memcpy(p_dev_info->fl_ver_last_ran,
11536  &fl_fw_versions.last_ran_fl_version,
11538  memcpy(p_dev_info->fl_ver_nor_flash,
11539  &fl_fw_versions.nor_flash_fl_version,
11541  memcpy(p_dev_info->fw_rev_nor_flash,
11542  &fl_fw_versions.nor_flash_fw_revision,
11544 
11545  ni_aligned_free(buffer);
11546  return NI_RETCODE_SUCCESS;
11547 }
11548 
11550  ni_load_query_t *p_load_query)
11551 {
11552  void *buffer;
11553  uint32_t size;
11554 
11555  ni_instance_mgr_general_status_t general_status;
11556 
11557  if (!p_ctx)
11558  {
11559  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_ctx cannot be null\n");
11560  return NI_RETCODE_INVALID_PARAM;
11561  }
11562  if (!p_load_query)
11563  {
11564  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: p_load_query cannot be null\n");
11565  return NI_RETCODE_INVALID_PARAM;
11566  }
11567 
11569  "6O") < 0)
11570  {
11571  ni_log2(p_ctx, NI_LOG_ERROR,
11572  "ERROR: %s function not supported on device with FW API version < 6.O\n",
11573  __func__);
11575  }
11576 
11577  buffer = NULL;
11579 
11580  if (ni_posix_memalign((void **)&buffer, sysconf(_SC_PAGESIZE), size))
11581  {
11582  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11584  }
11585 
11586  memset(buffer, 0, size);
11587 
11589  p_ctx->event_handle,
11590  buffer,
11591  size,
11593  {
11594  ni_log2(p_ctx, NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11595  ni_aligned_free(buffer);
11597  }
11598 
11599  memcpy(&general_status, buffer, sizeof(ni_instance_mgr_general_status_t));
11600 
11601  p_load_query->tp_fw_load = general_status.tp_fw_load;
11602  p_load_query->pcie_load = general_status.pcie_load;
11603  p_load_query->pcie_throughput = general_status.pcie_throughput;
11604  p_load_query->fw_load = general_status.fw_load;
11605  p_load_query->fw_share_mem_usage = general_status.fw_share_mem_usage;
11606 
11607  ni_aligned_free(buffer);
11608  return NI_RETCODE_SUCCESS;
11609 }
11610 
11611 ni_retcode_t ni_query_vf_ns_id(ni_device_handle_t device_handle,
11612  ni_device_vf_ns_id_t *p_dev_ns_vf,
11613  uint8_t fw_rev[])
11614 {
11615  void *p_buffer = NULL;
11616  uint32_t size;
11617  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11618 
11619  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_ns_vf))
11620  {
11621  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11622  __func__);
11623  return NI_RETCODE_INVALID_PARAM;
11624  }
11625 
11627  "6m") < 0)
11628  {
11630  "ERROR: %s function not supported on device with FW API version < 6.m\n",
11631  __func__);
11633  }
11634 
11636 
11637  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11638  {
11639  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11641  }
11642 
11643  memset(p_buffer, 0, size);
11644 
11645  if (ni_nvme_send_read_cmd(device_handle,
11646  event_handle,
11647  p_buffer,
11648  size,
11649  QUERY_GET_NS_VF_R) < 0)
11650  {
11651  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11652  ni_aligned_free(p_buffer);
11654  }
11655 
11656  ni_device_vf_ns_id_t *p_dev_ns_vf_data = (ni_device_vf_ns_id_t *)p_buffer;
11657  p_dev_ns_vf->vf_id = p_dev_ns_vf_data->vf_id;
11658  p_dev_ns_vf->ns_id = p_dev_ns_vf_data->ns_id;
11659  ni_log(NI_LOG_DEBUG, "%s(): NS/VF %u/%u\n", __func__, p_dev_ns_vf->ns_id, p_dev_ns_vf->vf_id);
11660  ni_aligned_free(p_buffer);
11661  return NI_RETCODE_SUCCESS;
11662 }
11663 
11664 ni_retcode_t ni_query_temperature(ni_device_handle_t device_handle,
11665  ni_device_temp_t *p_dev_temp,
11666  uint8_t fw_rev[])
11667 {
11668  void *p_buffer = NULL;
11669  uint32_t size;
11670  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11671 
11672  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_temp))
11673  {
11674  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11675  __func__);
11676  return NI_RETCODE_INVALID_PARAM;
11677  }
11678 
11680  "6rC") < 0)
11681  {
11683  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11684  __func__);
11686  }
11687 
11689 
11690  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11691  {
11692  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11694  }
11695 
11696  memset(p_buffer, 0, size);
11697 
11698  if (ni_nvme_send_read_cmd(device_handle,
11699  event_handle,
11700  p_buffer,
11701  size,
11703  {
11704  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11705  ni_aligned_free(p_buffer);
11707  }
11708 
11709  ni_device_temp_t *p_dev_temp_data = (ni_device_temp_t *)p_buffer;
11710  p_dev_temp->composite_temp = p_dev_temp_data->composite_temp;
11711  p_dev_temp->on_board_temp = p_dev_temp_data->on_board_temp;
11712  p_dev_temp->on_die_temp = p_dev_temp_data->on_die_temp;
11713  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d on die temperature %d\n",
11714  __func__, p_dev_temp->composite_temp, p_dev_temp->on_board_temp, p_dev_temp->on_die_temp);
11715  ni_aligned_free(p_buffer);
11716  return NI_RETCODE_SUCCESS;
11717 }
11718 
11719 ni_retcode_t ni_query_extra_info(ni_device_handle_t device_handle,
11720  ni_device_extra_info_t *p_dev_extra_info,
11721  uint8_t fw_rev[])
11722 {
11723  void *p_buffer = NULL;
11724  uint32_t size;
11725  ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
11726 
11727  if ((NI_INVALID_DEVICE_HANDLE == device_handle) || (!p_dev_extra_info))
11728  {
11729  ni_log(NI_LOG_ERROR, "ERROR: %s(): passed parameters are null, return\n",
11730  __func__);
11731  return NI_RETCODE_INVALID_PARAM;
11732  }
11733 
11735  "6rC") < 0)
11736  {
11738  "ERROR: %s function not supported on device with FW API version < 6rC\n",
11739  __func__);
11741  }
11742 
11744 
11745  if (ni_posix_memalign((void **)&p_buffer, sysconf(_SC_PAGESIZE), size))
11746  {
11747  ni_log(NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate buffer\n", NI_ERRNO, __func__);
11749  }
11750 
11751  memset(p_buffer, 0, size);
11752 
11753  if (ni_nvme_send_read_cmd(device_handle,
11754  event_handle,
11755  p_buffer,
11756  size,
11758  {
11759  ni_log(NI_LOG_ERROR, "%s(): NVME command Failed\n", __func__);
11760  ni_aligned_free(p_buffer);
11762  }
11763 
11764  ni_device_extra_info_t *p_dev_extra_info_data = (ni_device_extra_info_t *)p_buffer;
11765  p_dev_extra_info->composite_temp = p_dev_extra_info_data->composite_temp;
11766  p_dev_extra_info->on_board_temp = p_dev_extra_info_data->on_board_temp;
11767  p_dev_extra_info->on_die_temp = p_dev_extra_info_data->on_die_temp;
11768  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rC") >= 0 &&
11769  ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6rR") < 0)
11770  {
11771  p_dev_extra_info->power_consumption = NI_INVALID_POWER;
11772  }
11773  else
11774  {
11775  p_dev_extra_info->power_consumption = p_dev_extra_info_data->power_consumption;
11776  }
11777  //QUADPV-1210-Remove ADC current measurement decoding from FW
11778  if (ni_cmp_fw_api_ver((char*) &fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6s4") >=0)
11779  {
11780  p_dev_extra_info->current_consumption = p_dev_extra_info_data->current_consumption;
11781  ni_device_capability_t device_capability = {0};
11782  if (ni_device_capability_query2(device_handle, &device_capability, false) != NI_RETCODE_SUCCESS)
11783  {
11784  ni_log(NI_LOG_ERROR, "ERROR: unable to query capability\n");
11786  }
11787  p_dev_extra_info->power_consumption = ni_decode_power_measurement(p_dev_extra_info->current_consumption, device_capability.serial_number);
11788  }
11789  ni_log(NI_LOG_DEBUG, "%s(): current composite temperature %d on board temperature %d "
11790  "on die temperature %d power consumption %d current consumption %d\n",
11791  __func__, p_dev_extra_info->composite_temp, p_dev_extra_info->on_board_temp,
11792  p_dev_extra_info->on_die_temp, p_dev_extra_info->power_consumption, p_dev_extra_info->current_consumption);
11793  ni_aligned_free(p_buffer);
11794  return NI_RETCODE_SUCCESS;
11795 }
11796 
11797 /*!*****************************************************************************
11798  * \brief Allocate log buffer if needed and retrieve firmware logs from device
11799  *
11800  * \param[in] p_ctx Pointer to a caller allocated
11801  * ni_session_context_t struct
11802  * \param[in] p_log_buffer Reference to pointer to a log buffer
11803  * If log buffer pointer is NULL, this function will allocate log buffer
11804  * NOTE caller is responsible for freeing log buffer after calling this function
11805  * \param[in] gen_log_file Indicating whether it is required to generate log files
11806  *
11807  *
11808  * \return on success
11809  * NI_RETCODE_SUCCESS
11810  *
11811  * on failure
11812  * NI_RETCODE_ERROR_MEM_ALOC
11813  * NI_RETCODE_INVALID_PARAM
11814 *******************************************************************************/
11815 ni_retcode_t ni_device_alloc_and_get_firmware_logs(ni_session_context_t *p_ctx, void** p_log_buffer, bool gen_log_file)
11816 {
11818  bool is_ext_buf = true;
11819  if (*p_log_buffer == NULL)
11820  {
11821  if (ni_posix_memalign(p_log_buffer, sysconf(_SC_PAGESIZE), TOTAL_CPU_LOG_BUFFER_SIZE))
11822  {
11823  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR %d: %s() Cannot allocate log buffer\n",
11824  NI_ERRNO, __func__);
11826  }
11827  is_ext_buf = false;
11828  }
11829 
11830  if(*p_log_buffer != NULL){
11831  memset(*p_log_buffer, 0, TOTAL_CPU_LOG_BUFFER_SIZE);
11832  retval = ni_dump_log_all_cores(p_ctx, *p_log_buffer, gen_log_file); // dump FW logs
11833  if(!is_ext_buf)
11834  ni_aligned_free(*p_log_buffer);
11835  }else{
11837  }
11838 
11839  return retval;
11840 }
11841 
11842 /*!*****************************************************************************
11843  * \brief Set up hard coded demo ROI map
11844  *
11845  * \param[in] p_enc_ctx Pointer to a caller allocated
11846  *
11847  * \return on success
11848  * NI_RETCODE_SUCCESS
11849  *
11850  * on failure
11851  * NI_RETCODE_ERROR_MEM_ALOC
11852 *******************************************************************************/
11854 {
11855  ni_xcoder_params_t *p_param =
11856  (ni_xcoder_params_t *)(p_enc_ctx->p_session_config);
11857  int sumQp = 0, ctu, i, j;
11858  // mode 1: Set QP for center 1/3 of picture to highest - lowest quality
11859  // the rest to lowest - highest quality;
11860  // mode non-1: reverse of mode 1
11861  int importanceLevelCentre = p_param->roi_demo_mode == 1 ? 40 : 10;
11862  int importanceLevelRest = p_param->roi_demo_mode == 1 ? 10 : 40;
11863  int linesize_aligned = p_param->source_width;
11864  int height_aligned = p_param->source_height;
11865  if (QUADRA)
11866  {
11867  uint32_t block_size, max_cu_size, customMapSize;
11868  uint32_t mbWidth;
11869  uint32_t mbHeight;
11870  uint32_t numMbs;
11871  uint32_t roiMapBlockUnitSize;
11872  uint32_t entryPerMb;
11873 
11874  max_cu_size = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16: 64;
11875  // AV1 non-8x8-aligned resolution is implicitly cropped due to Quadra HW limitation
11876  if (NI_CODEC_FORMAT_AV1 == p_enc_ctx->codec_format)
11877  {
11878  linesize_aligned = (linesize_aligned / 8) * 8;
11879  height_aligned = (height_aligned / 8) * 8;
11880  }
11881 
11882  // (ROI map version >= 1) each QP info takes 8-bit, represent 8 x 8
11883  // pixel block
11884  block_size =
11885  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) *
11886  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11887  (8 * 8);
11888 
11889  // need to align to 64 bytes
11890  customMapSize = ((block_size + 63) & (~63));
11891  if (!p_enc_ctx->roi_map)
11892  {
11893  p_enc_ctx->roi_map =
11894  (ni_enc_quad_roi_custom_map *)calloc(1, customMapSize);
11895  }
11896  if (!p_enc_ctx->roi_map)
11897  {
11899  }
11900 
11901  // for H.264, select ROI Map Block Unit Size: 16x16
11902  // for H.265, select ROI Map Block Unit Size: 64x64
11903  roiMapBlockUnitSize = p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264 ? 16 : 64;
11904 
11905  mbWidth =
11906  ((linesize_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11907  roiMapBlockUnitSize;
11908  mbHeight =
11909  ((height_aligned + max_cu_size - 1) & (~(max_cu_size - 1))) /
11910  roiMapBlockUnitSize;
11911  numMbs = mbWidth * mbHeight;
11912 
11913  // copy roi MBs QPs into custom map
11914  // number of qp info (8x8) per mb or ctb
11915  entryPerMb = (roiMapBlockUnitSize / 8) * (roiMapBlockUnitSize / 8);
11916 
11917  for (i = 0; i < numMbs; i++)
11918  {
11919  bool bIsCenter = (i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3);
11920  for (j = 0; j < entryPerMb; j++)
11921  {
11922  /*
11923  g_quad_roi_map[i*4+j].field.skip_flag = 0; // don't force
11924  skip mode g_quad_roi_map[i*4+j].field.roiAbsQp_flag = 1; //
11925  absolute QP g_quad_roi_map[i*4+j].field.qp_info = bIsCenter
11926  ? importanceLevelCentre : importanceLevelRest;
11927  */
11928  p_enc_ctx->roi_map[i * entryPerMb + j].field.ipcm_flag =
11929  0; // don't force skip mode
11930  p_enc_ctx->roi_map[i * entryPerMb + j]
11931  .field.roiAbsQp_flag = 1; // absolute QP
11932  p_enc_ctx->roi_map[i * entryPerMb + j].field.qp_info =
11933  bIsCenter ? importanceLevelCentre : importanceLevelRest;
11934  }
11935  sumQp += p_enc_ctx->roi_map[i * entryPerMb].field.qp_info;
11936  }
11937  p_enc_ctx->roi_len = customMapSize;
11938  p_enc_ctx->roi_avg_qp =
11939  // NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
11940  (sumQp + (numMbs >> 1)) / numMbs; // round off
11941  }
11942  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H264)
11943  {
11944  // roi for H.264 is specified for 16x16 pixel macroblocks - 1 MB
11945  // is stored in each custom map entry
11946 
11947  // number of MBs in each row
11948  uint32_t mbWidth = (linesize_aligned + 16 - 1) >> 4;
11949  // number of MBs in each column
11950  uint32_t mbHeight = (height_aligned + 16 - 1) >> 4;
11951  uint32_t numMbs = mbWidth * mbHeight;
11952  uint32_t customMapSize =
11953  sizeof(ni_enc_avc_roi_custom_map_t) * numMbs;
11954  p_enc_ctx->avc_roi_map =
11955  (ni_enc_avc_roi_custom_map_t *)calloc(1, customMapSize);
11956  if (!p_enc_ctx->avc_roi_map)
11957  {
11959  }
11960 
11961  // copy roi MBs QPs into custom map
11962  for (i = 0; i < numMbs; i++)
11963  {
11964  if ((i % mbWidth > mbWidth / 3) && (i % mbWidth < mbWidth * 2 / 3))
11965  {
11966  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelCentre;
11967  }
11968  else
11969  {
11970  p_enc_ctx->avc_roi_map[i].field.mb_qp = importanceLevelRest;
11971  }
11972  sumQp += p_enc_ctx->avc_roi_map[i].field.mb_qp;
11973  }
11974  p_enc_ctx->roi_len = customMapSize;
11975  p_enc_ctx->roi_avg_qp =
11976  (sumQp + (numMbs >> 1)) / numMbs; // round off
11977  }
11978  else if (p_enc_ctx->codec_format == NI_CODEC_FORMAT_H265)
11979  {
11980  // roi for H.265 is specified for 32x32 pixel subCTU blocks - 4
11981  // subCTU QPs are stored in each custom CTU map entry
11982 
11983  // number of CTUs in each row
11984  uint32_t ctuWidth = (linesize_aligned + 64 - 1) >> 6;
11985  // number of CTUs in each column
11986  uint32_t ctuHeight = (height_aligned + 64 - 1) >> 6;
11987  // number of sub CTUs in each row
11988  uint32_t subCtuWidth = ctuWidth * 2;
11989  // number of CTUs in each column
11990  uint32_t subCtuHeight = ctuHeight * 2;
11991  uint32_t numSubCtus = subCtuWidth * subCtuHeight;
11992 
11993  p_enc_ctx->hevc_sub_ctu_roi_buf = (uint8_t *)malloc(numSubCtus);
11994  if (!p_enc_ctx->hevc_sub_ctu_roi_buf)
11995  {
11997  }
11998  for (i = 0; i < numSubCtus; i++)
11999  {
12000  if ((i % subCtuWidth > subCtuWidth / 3) &&
12001  (i % subCtuWidth < subCtuWidth * 2 / 3))
12002  {
12003  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelCentre;
12004  }
12005  else
12006  {
12007  p_enc_ctx->hevc_sub_ctu_roi_buf[i] = importanceLevelRest;
12008  }
12009  }
12010  p_enc_ctx->hevc_roi_map = (ni_enc_hevc_roi_custom_map_t *)calloc(
12011  1, sizeof(ni_enc_hevc_roi_custom_map_t) * ctuWidth * ctuHeight);
12012  if (!p_enc_ctx->hevc_roi_map)
12013  {
12015  }
12016 
12017  for (i = 0; i < ctuHeight; i++)
12018  {
12019  uint8_t *ptr = &p_enc_ctx->hevc_sub_ctu_roi_buf[subCtuWidth * i * 2];
12020  for (j = 0; j < ctuWidth; j++, ptr += 2)
12021  {
12022  ctu = (int)(i * ctuWidth + j);
12023  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 = *ptr;
12024  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 = *(ptr + 1);
12025  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 =
12026  *(ptr + subCtuWidth);
12027  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3 =
12028  *(ptr + subCtuWidth + 1);
12029  sumQp += (p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_0 +
12030  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_1 +
12031  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_2 +
12032  p_enc_ctx->hevc_roi_map[ctu].field.sub_ctu_qp_3);
12033  }
12034  }
12035  p_enc_ctx->roi_len =
12036  ctuWidth * ctuHeight * sizeof(ni_enc_hevc_roi_custom_map_t);
12037  p_enc_ctx->roi_avg_qp =
12038  (sumQp + (numSubCtus >> 1)) / numSubCtus; // round off.
12039  }
12040  return NI_RETCODE_SUCCESS;
12041 }
12042 
12044 {
12045  // for encoder reconfiguration testing
12046  // reset encoder change data buffer for reconf parameters
12047  ni_retcode_t retval = 0;
12048  ni_xcoder_params_t *p_param =
12049  (ni_xcoder_params_t *)p_enc_ctx->p_session_config;
12050  ni_aux_data_t *aux_data = NULL;
12051  if (p_param->reconf_demo_mode > XCODER_TEST_RECONF_OFF &&
12053  {
12054  memset(p_enc_ctx->enc_change_params, 0, sizeof(ni_encoder_change_params_t));
12055  }
12056 
12057  switch (p_param->reconf_demo_mode) {
12058  case XCODER_TEST_RECONF_BR:
12059  if (p_enc_ctx->frame_num ==
12060  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12061  {
12062  aux_data = ni_frame_new_aux_data(
12063  p_frame, NI_FRAME_AUX_DATA_BITRATE, sizeof(int32_t));
12064  if (!aux_data)
12065  {
12067  }
12068  *((int32_t *)aux_data->data) =
12069  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12070 
12071  p_enc_ctx->reconfigCount++;
12072  if (p_param->cfg_enc_params.hrdEnable)
12073  {
12074  p_frame->force_key_frame = 1;
12075  p_frame->ni_pict_type = PIC_TYPE_IDR;
12076  }
12077  }
12078  break;
12079  // reconfig intraperiod param
12081  if (p_enc_ctx->frame_num ==
12082  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12083  {
12084  aux_data = ni_frame_new_aux_data(
12085  p_frame, NI_FRAME_AUX_DATA_INTRAPRD, sizeof(int32_t));
12086  if (!aux_data)
12087  {
12089  }
12090  int32_t intraprd = *((int32_t *)aux_data->data) =
12091  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12092  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12093  "xcoder_send_frame: frame #%lu reconf "
12094  "intraPeriod %d\n",
12095  p_enc_ctx->frame_num,
12096  intraprd);
12097  p_enc_ctx->reconfigCount++;
12098  }
12099  break;
12100  // reconfig VUI parameters
12102  if (p_enc_ctx->frame_num ==
12103  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12104  {
12105  aux_data = ni_frame_new_aux_data(p_frame,
12107  sizeof(ni_vui_hrd_t));
12108  if (!aux_data)
12109  {
12111  }
12112  ni_vui_hrd_t *vui = (ni_vui_hrd_t *)aux_data->data;
12113  vui->colorDescPresent =
12114  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12115  vui->colorPrimaries =
12116  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12117  vui->colorTrc =
12118  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12119  vui->colorSpace =
12120  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12121  vui->aspectRatioWidth =
12122  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12123  vui->aspectRatioHeight =
12124  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12125  vui->videoFullRange =
12126  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12127  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12128  "xcoder_send_frame: frame #%lu reconf "
12129  "vui colorDescPresent %d colorPrimaries %d "
12130  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12131  "aspectRatioHeight %d videoFullRange %d\n",
12132  p_enc_ctx->frame_num, vui->colorDescPresent,
12133  vui->colorPrimaries, vui->colorTrc,
12134  vui->colorSpace, vui->aspectRatioWidth,
12135  vui->aspectRatioHeight, vui->videoFullRange);
12136 
12137  p_enc_ctx->reconfigCount++;
12138  }
12139  break;
12140  // long term ref
12142  // the reconf file data line format for this is:
12143  // <frame-number>:useCurSrcAsLongtermPic,useLongtermRef where
12144  // values will stay the same on every frame until changed.
12145  if (p_enc_ctx->frame_num ==
12146  p_param->reconf_hash[p_enc_ctx->reconfigCount][0])
12147  {
12148  ni_long_term_ref_t *p_ltr;
12149  aux_data = ni_frame_new_aux_data(
12151  sizeof(ni_long_term_ref_t));
12152  if (!aux_data)
12153  {
12155  }
12156  p_ltr = (ni_long_term_ref_t *)aux_data->data;
12158  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12159  p_ltr->use_long_term_ref =
12160  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12161  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12162  "xcoder_send_frame: frame #%lu metadata "
12163  "use_cur_src_as_long_term_pic %d use_long_term_ref "
12164  "%d\n",
12165  p_enc_ctx->frame_num,
12167  p_ltr->use_long_term_ref);
12168  p_enc_ctx->reconfigCount++;
12169  }
12170  break;
12171  // reconfig min / max QP
12174  if (p_enc_ctx->frame_num ==
12175  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12176  aux_data = ni_frame_new_aux_data(
12178  if (!aux_data) {
12180  }
12181 
12182  ni_rc_min_max_qp *qp_info = (ni_rc_min_max_qp *)aux_data->data;
12183  qp_info->minQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12184  qp_info->maxQpI = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12185  qp_info->maxDeltaQp = p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12186  qp_info->minQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12187  qp_info->maxQpPB = p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12188 
12189  p_enc_ctx->reconfigCount++;
12190  }
12191  break;
12192 #ifdef QUADRA
12193  // reconfig LTR interval
12195  if (p_enc_ctx->frame_num ==
12196  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12197  aux_data = ni_frame_new_aux_data(p_frame,
12199  sizeof(int32_t));
12200  if (!aux_data) {
12202  }
12203  *((int32_t *)aux_data->data) =
12204  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12205  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12206  "xcoder_send_frame: frame #%lu reconf "
12207  "ltrInterval %d\n",
12208  p_enc_ctx->frame_num,
12209  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12210 
12211  p_enc_ctx->reconfigCount++;
12212  }
12213  break;
12214  // invalidate reference frames
12216  if (p_enc_ctx->frame_num ==
12217  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12218  aux_data = ni_frame_new_aux_data(
12220  sizeof(int32_t));
12221  if (!aux_data) {
12223  }
12224  *((int32_t *)aux_data->data) =
12225  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12226  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12227  "xcoder_send_frame: frame #%lu reconf "
12228  "invalidFrameNum %d\n",
12229  p_enc_ctx->frame_num,
12230  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12231 
12232  p_enc_ctx->reconfigCount++;
12233  }
12234  break;
12235  // reconfig framerate
12237  if (p_enc_ctx->frame_num ==
12238  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12239  ni_framerate_t *framerate;
12240 
12241  aux_data = ni_frame_new_aux_data(p_frame,
12243  sizeof(ni_framerate_t));
12244  if (!aux_data) {
12246  }
12247 
12248  framerate = (ni_framerate_t *)aux_data->data;
12249  framerate->framerate_num =
12250  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12251  framerate->framerate_denom =
12252  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12253  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12254  "xcoder_send_frame: frame #%lu reconf "
12255  "framerate (%d/%d)\n",
12256  p_enc_ctx->frame_num, framerate->framerate_num,
12257  framerate->framerate_denom);
12258  p_enc_ctx->reconfigCount++;
12259  }
12260  break;
12262  if (p_enc_ctx->frame_num ==
12263  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12264  aux_data = ni_frame_new_aux_data(
12265  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12266  if (!aux_data) {
12268  }
12269  *((int32_t *)aux_data->data) =
12270  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12271  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12272  "xcoder_send_frame: frame #%lu reconf "
12273  "maxFrameSize %d\n",
12274  p_enc_ctx->frame_num,
12275  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12276 
12277  p_enc_ctx->reconfigCount++;
12278  }
12279  break;
12281  if (p_enc_ctx->frame_num ==
12282  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12283  aux_data = ni_frame_new_aux_data(
12284  p_frame, NI_FRAME_AUX_DATA_CRF, sizeof(int32_t));
12285  if (!aux_data) {
12287  }
12288  *((int32_t *)aux_data->data) =
12289  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12290  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12291  "xcoder_send_frame: frame #%lu reconf "
12292  "crf %d\n",
12293  p_enc_ctx->frame_num,
12294  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12295 
12296  p_enc_ctx->reconfigCount++;
12297  }
12298  break;
12300  if (p_enc_ctx->frame_num ==
12301  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12302  aux_data = ni_frame_new_aux_data(
12303  p_frame, NI_FRAME_AUX_DATA_CRF_FLOAT, sizeof(float));
12304  if (!aux_data) {
12306  }
12307  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12308  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12309  *((float *)aux_data->data) = crf;
12310  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12311  "xcoder_send_frame: frame #%lu reconf "
12312  "crf %f\n",
12313  p_enc_ctx->frame_num, crf);
12314 
12315  p_enc_ctx->reconfigCount++;
12316  }
12317  break;
12319  if (p_enc_ctx->frame_num ==
12320  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12321  int32_t vbvBufferSize = p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12322  int32_t vbvMaxRate = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12323  if ((vbvBufferSize < 10 && vbvBufferSize != 0) || vbvBufferSize > 3000)
12324  {
12325  ni_log2(p_enc_ctx, NI_LOG_ERROR, "ERROR: %s(): invalid vbvBufferSize value %d\n",
12326  __func__, vbvBufferSize);
12327  return NI_RETCODE_INVALID_PARAM;
12328  }
12329  if (p_param->bitrate > 0 && vbvMaxRate > 0 && vbvMaxRate < p_param->bitrate) {
12330  ni_log2(p_enc_ctx, NI_LOG_ERROR, "vbvMaxRate %u cannot be smaller than bitrate %d\n",
12331  vbvMaxRate, p_param->bitrate);
12332  return NI_RETCODE_INVALID_PARAM;
12333  }
12334  if (vbvBufferSize == 0 && vbvMaxRate > 0) {
12335  ni_log2(p_enc_ctx, NI_LOG_INFO, "vbvMaxRate %d does not take effect when "
12336  "vbvBufferSize is 0, force vbvMaxRate to 0\n",
12337  vbvMaxRate);
12338  vbvMaxRate = 0;
12339  }
12340 
12341  aux_data = ni_frame_new_aux_data(
12342  p_frame, NI_FRAME_AUX_DATA_VBV_MAX_RATE, sizeof(int32_t));
12343  if (!aux_data) {
12345  }
12346  *((int32_t *)aux_data->data) = vbvMaxRate;
12347  aux_data = ni_frame_new_aux_data(
12348  p_frame, NI_FRAME_AUX_DATA_VBV_BUFFER_SIZE, sizeof(int32_t));
12349  if (!aux_data) {
12351  }
12352  *((int32_t *)aux_data->data) = vbvBufferSize;
12353  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12354  "xcoder_send_frame: frame #%lu reconfig vbvMaxRate %d vbvBufferSize "
12355  "%d by frame aux data\n",
12356  p_enc_ctx->frame_num, vbvMaxRate, vbvBufferSize);
12357 
12358  p_enc_ctx->reconfigCount++;
12359  }
12360  break;
12362  if (p_enc_ctx->frame_num ==
12363  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12364  int maxFrameSizeRatio = p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12365  if (maxFrameSizeRatio < 1) {
12366  ni_log2(p_enc_ctx, NI_LOG_ERROR, "maxFrameSizeRatio %d cannot < 1\n",
12367  maxFrameSizeRatio);
12368  return NI_RETCODE_INVALID_PARAM;
12369  }
12370  aux_data = ni_frame_new_aux_data(
12371  p_frame, NI_FRAME_AUX_DATA_MAX_FRAME_SIZE, sizeof(int32_t));
12372  if (!aux_data) {
12374  }
12375 
12376  int32_t bitrate, framerate_num, framerate_denom;
12377  uint32_t min_maxFrameSize, maxFrameSize;
12378  bitrate = (p_enc_ctx->target_bitrate > 0) ? p_enc_ctx->target_bitrate : p_param->bitrate;
12379 
12380  if ((p_enc_ctx->framerate.framerate_num > 0) && (p_enc_ctx->framerate.framerate_denom > 0))
12381  {
12382  framerate_num = p_enc_ctx->framerate.framerate_num;
12383  framerate_denom = p_enc_ctx->framerate.framerate_denom;
12384  }
12385  else
12386  {
12387  framerate_num = (int32_t) p_param->fps_number;
12388  framerate_denom = (int32_t) p_param->fps_denominator;
12389  }
12390 
12391  min_maxFrameSize = ((uint32_t)bitrate / framerate_num * framerate_denom) / 8;
12392  maxFrameSize = min_maxFrameSize * maxFrameSizeRatio > NI_MAX_FRAME_SIZE ?
12393  NI_MAX_FRAME_SIZE : min_maxFrameSize * maxFrameSizeRatio;
12394  *((int32_t *)aux_data->data) = maxFrameSize;
12395  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12396  "xcoder_send_frame: frame #%lu reconf "
12397  "maxFrameSizeRatio %d maxFrameSize %d\n",
12398  p_enc_ctx->frame_num, maxFrameSizeRatio, maxFrameSize);
12399 
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  aux_data = ni_frame_new_aux_data(
12407  p_frame, NI_FRAME_AUX_DATA_SLICE_ARG, sizeof(int16_t));
12408  if (!aux_data) {
12410  }
12411  *((int16_t *)aux_data->data) =
12412  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12413  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12414  "xcoder_send_frame: frame #%lu reconf "
12415  "sliceArg %d\n",
12416  p_enc_ctx->frame_num,
12417  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12418 
12419  p_enc_ctx->reconfigCount++;
12420  }
12421  break;
12422  // force IDR frame through API test code
12424  if (p_enc_ctx->frame_num ==
12425  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12426  ni_force_idr_frame_type(p_enc_ctx);
12427  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12428  "xcoder_send_frame: frame #%lu force IDR frame\n",
12429  p_enc_ctx->frame_num);
12430 
12431  p_enc_ctx->reconfigCount++;
12432  }
12433  break;
12434  // reconfig bit rate through API test code
12436  if (p_enc_ctx->frame_num ==
12437  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12438  if ((retval = ni_reconfig_bitrate(
12439  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))){
12440  return retval;
12441  }
12442  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12443  "xcoder_send_frame: frame #%lu API reconfig BR %d\n",
12444  p_enc_ctx->frame_num,
12445  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12446 
12447  p_enc_ctx->reconfigCount++;
12448  }
12449  break;
12451  if (p_enc_ctx->frame_num ==
12452  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12453  int32_t intraprd =
12454  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12455  if ((retval = ni_reconfig_intraprd(p_enc_ctx, intraprd))){
12456  return retval;
12457  }
12459  "xcoder_send_frame: frame #%lu API reconfig intraPeriod %d\n",
12460  p_enc_ctx->frame_num,
12461  intraprd);
12462 
12463  p_enc_ctx->reconfigCount++;
12464  }
12465  break;
12467  if (p_enc_ctx->frame_num ==
12468  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12469  ni_vui_hrd_t vui;
12470  vui.colorDescPresent =
12471  p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12472  vui.colorPrimaries =
12473  p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12474  vui.colorTrc =
12475  p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12476  vui.colorSpace =
12477  p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12478  vui.aspectRatioWidth =
12479  p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12480  vui.aspectRatioHeight =
12481  p_param->reconf_hash[p_enc_ctx->reconfigCount][6];
12482  vui.videoFullRange =
12483  p_param->reconf_hash[p_enc_ctx->reconfigCount][7];
12484  if ((retval = ni_reconfig_vui(p_enc_ctx, &vui))){
12485  return retval;
12486  }
12487  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12488  "xcoder_send_frame: frame #%lu reconf "
12489  "vui colorDescPresent %d colorPrimaries %d "
12490  "colorTrc %d colorSpace %d aspectRatioWidth %d "
12491  "aspectRatioHeight %d videoFullRange %d\n",
12492  p_enc_ctx->frame_num, vui.colorDescPresent,
12493  vui.colorPrimaries, vui.colorTrc,
12494  vui.colorSpace, vui.aspectRatioWidth,
12496  p_enc_ctx->reconfigCount++;
12497  }
12498  break;
12500  if (p_enc_ctx->frame_num ==
12501  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12502  ni_long_term_ref_t ltr;
12504  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12505  ltr.use_long_term_ref =
12506  (uint8_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12507 
12508  if ((retval = ni_set_ltr(p_enc_ctx, &ltr))) {
12509  return retval;
12510  }
12511  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12512  "xcoder_send_frame(): frame #%lu API set LTR\n",
12513  p_enc_ctx->frame_num);
12514  p_enc_ctx->reconfigCount++;
12515  }
12516  break;
12519  if (p_enc_ctx->frame_num ==
12520  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12521  ni_rc_min_max_qp qp_info;
12522  qp_info.minQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12523  qp_info.maxQpI = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12524  qp_info.maxDeltaQp = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][3];
12525  qp_info.minQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][4];
12526  qp_info.maxQpPB = (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][5];
12527  if ((retval = ni_reconfig_min_max_qp(p_enc_ctx, &qp_info))) {
12528  return retval;
12529  }
12530  ni_log2(p_enc_ctx, NI_LOG_DEBUG,
12531  "%s(): frame %d minQpI %d maxQpI %d maxDeltaQp %d minQpPB %d maxQpPB %d\n",
12532  __func__, p_enc_ctx->frame_num,
12533  qp_info.minQpI, qp_info.maxQpI, qp_info.maxDeltaQp, qp_info.minQpPB, qp_info.maxQpPB);
12534  p_enc_ctx->reconfigCount++;
12535  }
12536  break;
12538  if (p_enc_ctx->frame_num ==
12539  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12540  if ((retval = ni_set_ltr_interval(
12541  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12542  return retval;
12543  }
12544  ni_log2(p_enc_ctx,
12545  NI_LOG_TRACE,
12546  "xcoder_send_frame(): frame #%lu API set LTR interval %d\n",
12547  p_enc_ctx->frame_num,
12548  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12549  p_enc_ctx->reconfigCount++;
12550  }
12551  break;
12553  if (p_enc_ctx->frame_num ==
12554  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12555  if ((retval = ni_set_frame_ref_invalid(
12556  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12557  return retval;
12558  }
12559  ni_log2(p_enc_ctx,
12560  NI_LOG_TRACE,
12561  "xcoder_send_frame(): frame #%lu API set frame ref invalid "
12562  "%d\n",
12563  p_enc_ctx->frame_num,
12564  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12565  p_enc_ctx->reconfigCount++;
12566  }
12567  break;
12569  if (p_enc_ctx->frame_num ==
12570  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12571  ni_framerate_t framerate;
12572  framerate.framerate_num =
12573  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][1];
12574  framerate.framerate_denom =
12575  (int32_t)p_param->reconf_hash[p_enc_ctx->reconfigCount][2];
12576  if ((retval = ni_reconfig_framerate(p_enc_ctx, &framerate))) {
12577  return retval;
12578  }
12579  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12580  "xcoder_send_frame: frame #%lu API reconfig framerate "
12581  "(%d/%d)\n",
12582  p_enc_ctx->frame_num,
12583  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12584  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12585 
12586  p_enc_ctx->reconfigCount++;
12587  }
12588  break;
12590  if (p_enc_ctx->frame_num ==
12591  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12592  if ((retval = ni_reconfig_max_frame_size(
12593  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12594  return retval;
12595  }
12596  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12597  "xcoder_send_frame: frame #%lu API reconfig maxFrameSize %d\n",
12598  p_enc_ctx->frame_num,
12599  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12600 
12601  p_enc_ctx->reconfigCount++;
12602  }
12603  break;
12604  case XCODER_TEST_CRF_API:
12605  if (p_enc_ctx->frame_num ==
12606  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12607  if ((retval = ni_reconfig_crf(
12608  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12609  return retval;
12610  }
12611  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12612  "xcoder_send_frame: frame #%lu API reconfig crf %d\n",
12613  p_enc_ctx->frame_num,
12614  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12615 
12616  p_enc_ctx->reconfigCount++;
12617  }
12618  break;
12620  if (p_enc_ctx->frame_num ==
12621  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12622  float crf = (float)(p_param->reconf_hash[p_enc_ctx->reconfigCount][1] +
12623  (float)p_param->reconf_hash[p_enc_ctx->reconfigCount][2] / 100.0);
12624  if ((retval = ni_reconfig_crf2(p_enc_ctx, crf))) {
12625  return retval;
12626  }
12627  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12628  "xcoder_send_frame: frame #%lu API reconfig crf %f\n",
12629  p_enc_ctx->frame_num, crf);
12630 
12631  p_enc_ctx->reconfigCount++;
12632  }
12633  break;
12635  if (p_enc_ctx->frame_num ==
12636  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12637  if ((retval = ni_reconfig_vbv_value(
12638  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12639  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]))) {
12640  return retval;
12641  }
12642  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12643  "xcoder_send_frame: frame #%lu API reconfig vbvMaxRate %d vbvBufferSize %d\n",
12644  p_enc_ctx->frame_num,
12645  p_param->reconf_hash[p_enc_ctx->reconfigCount][1],
12646  p_param->reconf_hash[p_enc_ctx->reconfigCount][2]);
12647 
12648  p_enc_ctx->reconfigCount++;
12649  }
12650  break;
12652  if (p_enc_ctx->frame_num ==
12653  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12654 
12655  if ((retval = ni_reconfig_max_frame_size_ratio(
12656  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12657  return retval;
12658  }
12659  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12660  "xcoder_send_frame: frame #%lu reconf maxFrameSizeRatio %d\n",
12661  p_enc_ctx->frame_num, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12662 
12663  p_enc_ctx->reconfigCount++;
12664  }
12665  break;
12667  if (p_enc_ctx->frame_num ==
12668  p_param->reconf_hash[p_enc_ctx->reconfigCount][0]) {
12669  if ((retval = ni_reconfig_slice_arg(
12670  p_enc_ctx, p_param->reconf_hash[p_enc_ctx->reconfigCount][1]))) {
12671  return retval;
12672  }
12673  ni_log2(p_enc_ctx, NI_LOG_TRACE,
12674  "xcoder_send_frame: frame #%lu API reconfig sliceArg %d\n",
12675  p_enc_ctx->frame_num,
12676  p_param->reconf_hash[p_enc_ctx->reconfigCount][1]);
12677 
12678  p_enc_ctx->reconfigCount++;
12679  }
12680  break;
12681 #endif
12683  default:
12684  ;
12685  }
12686  return NI_RETCODE_SUCCESS;
12687 }
12688 
12692 static int ni_tolower(int c)
12693 {
12694  if (c >= 'A' && c <= 'Z')
12695  c ^= 0x20;
12696  return c;
12697 }
12698 
12699 int ni_strcasecmp(const char *a, const char *b)
12700 {
12701  uint8_t c1, c2;
12702  do
12703  {
12704  c1 = ni_tolower(*a++);
12705  c2 = ni_tolower(*b++);
12706  } while (c1 && c1 == c2);
12707  return c1 - c2;
12708 }
12709 
12710 void ni_gop_params_check_set(ni_xcoder_params_t *p_param, char *value)
12711 {
12712  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
12713  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
12715  p_gop->pic_param[0].rps[0].ref_pic = 1;
12717  p_gop->pic_param[0].rps[0].ref_pic_used = 1;
12719  p_gop->pic_param[0].rps[1].ref_pic = 1;
12721  p_gop->pic_param[0].rps[1].ref_pic_used = 1;
12723  p_gop->pic_param[0].rps[2].ref_pic = 1;
12725  p_gop->pic_param[0].rps[2].ref_pic_used = 1;
12727  p_gop->pic_param[0].rps[3].ref_pic = 1;
12729  p_gop->pic_param[0].rps[3].ref_pic_used = 1;
12731  p_gop->pic_param[1].rps[0].ref_pic = 1;
12733  p_gop->pic_param[1].rps[0].ref_pic_used = 1;
12735  p_gop->pic_param[1].rps[1].ref_pic = 1;
12737  p_gop->pic_param[1].rps[1].ref_pic_used = 1;
12739  p_gop->pic_param[1].rps[2].ref_pic = 1;
12741  p_gop->pic_param[1].rps[2].ref_pic_used = 1;
12743  p_gop->pic_param[1].rps[3].ref_pic = 1;
12745  p_gop->pic_param[1].rps[3].ref_pic_used = 1;
12747  p_gop->pic_param[2].rps[0].ref_pic = 1;
12749  p_gop->pic_param[2].rps[0].ref_pic_used = 1;
12751  p_gop->pic_param[2].rps[1].ref_pic = 1;
12753  p_gop->pic_param[2].rps[1].ref_pic_used = 1;
12755  p_gop->pic_param[2].rps[2].ref_pic = 1;
12757  p_gop->pic_param[2].rps[2].ref_pic_used = 1;
12759  p_gop->pic_param[2].rps[3].ref_pic = 1;
12761  p_gop->pic_param[2].rps[3].ref_pic_used = 1;
12763  p_gop->pic_param[3].rps[0].ref_pic = 1;
12765  p_gop->pic_param[3].rps[0].ref_pic_used = 1;
12767  p_gop->pic_param[3].rps[1].ref_pic = 1;
12769  p_gop->pic_param[3].rps[1].ref_pic_used = 1;
12771  p_gop->pic_param[3].rps[2].ref_pic = 1;
12773  p_gop->pic_param[3].rps[2].ref_pic_used = 1;
12775  p_gop->pic_param[3].rps[3].ref_pic = 1;
12777  p_gop->pic_param[3].rps[3].ref_pic_used = 1;
12779  p_gop->pic_param[4].rps[0].ref_pic = 1;
12781  p_gop->pic_param[4].rps[0].ref_pic_used = 1;
12783  p_gop->pic_param[4].rps[1].ref_pic = 1;
12785  p_gop->pic_param[4].rps[1].ref_pic_used = 1;
12787  p_gop->pic_param[4].rps[2].ref_pic = 1;
12789  p_gop->pic_param[4].rps[2].ref_pic_used = 1;
12791  p_gop->pic_param[4].rps[3].ref_pic = 1;
12793  p_gop->pic_param[4].rps[3].ref_pic_used = 1;
12795  p_gop->pic_param[5].rps[0].ref_pic = 1;
12797  p_gop->pic_param[5].rps[0].ref_pic_used = 1;
12799  p_gop->pic_param[5].rps[1].ref_pic = 1;
12801  p_gop->pic_param[5].rps[1].ref_pic_used = 1;
12803  p_gop->pic_param[5].rps[2].ref_pic = 1;
12805  p_gop->pic_param[5].rps[2].ref_pic_used = 1;
12807  p_gop->pic_param[5].rps[3].ref_pic = 1;
12809  p_gop->pic_param[5].rps[3].ref_pic_used = 1;
12811  p_gop->pic_param[6].rps[0].ref_pic = 1;
12813  p_gop->pic_param[6].rps[0].ref_pic_used = 1;
12815  p_gop->pic_param[6].rps[1].ref_pic = 1;
12817  p_gop->pic_param[6].rps[1].ref_pic_used = 1;
12819  p_gop->pic_param[6].rps[2].ref_pic = 1;
12821  p_gop->pic_param[6].rps[2].ref_pic_used = 1;
12823  p_gop->pic_param[6].rps[3].ref_pic = 1;
12825  p_gop->pic_param[6].rps[3].ref_pic_used = 1;
12827  p_gop->pic_param[7].rps[0].ref_pic = 1;
12829  p_gop->pic_param[7].rps[0].ref_pic_used = 1;
12831  p_gop->pic_param[7].rps[1].ref_pic = 1;
12833  p_gop->pic_param[7].rps[1].ref_pic_used = 1;
12835  p_gop->pic_param[7].rps[2].ref_pic = 1;
12837  p_gop->pic_param[7].rps[2].ref_pic_used = 1;
12839  p_gop->pic_param[7].rps[3].ref_pic = 1;
12841  p_gop->pic_param[7].rps[3].ref_pic_used = 1;
12842 
12843 }
12844 
12846 {
12847  ni_encoder_cfg_params_t *p_enc = &p_param->cfg_enc_params;
12848  ni_custom_gop_params_t* p_gop = &p_enc->custom_gop_params;
12849  int i, j;
12850  for (i=0; i<NI_MAX_GOP_NUM; i++)
12851  {
12852  for (j=0; j<NI_MAX_REF_PIC; j++)
12853  {
12854  if (p_gop->pic_param[i].rps[j].ref_pic == 1 &&
12855  p_gop->pic_param[i].rps[j].ref_pic_used != 1)
12856  {
12858  "g%drefPic%d specified without g%drefPic%dUsed specified!\n",
12859  i, j, i, j);
12860  return false;
12861  }
12862  }
12863  }
12864  // set custom_gop_params default.
12865  for (i=0; i<NI_MAX_GOP_NUM; i++)
12866  {
12867  for (j=0; j<NI_MAX_REF_PIC; j++)
12868  {
12869  p_gop->pic_param[i].rps[j].ref_pic = 0;
12870  p_gop->pic_param[i].rps[j].ref_pic_used = 0;
12871  }
12872  }
12873  return true;
12874 }
12875 
12876 /*!*****************************************************************************
12877  * \brief Initiate P2P transfer (P2P write) (deprecated)
12878  *
12879  * \param[in] pSession Pointer to source card destination
12880  * \param[in] source Pointer to source frame to transmit
12881  * \param[in] ui64DestAddr Destination address on target device
12882  * \param[in] ui32FrameSize Size of frame to transfer
12883  *
12884  * \return always returns
12885  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12886 *******************************************************************************/
12888  niFrameSurface1_t *source,
12889  uint64_t ui64DestAddr,
12890  uint32_t ui32FrameSize)
12891 {
12892  // avoid compiler warnings
12893  (void) pSession;
12894  (void) source;
12895  (void) ui64DestAddr;
12896  (void) ui32FrameSize;
12897 
12899 }
12900 
12901 /*!*****************************************************************************
12902  * \brief Initiate P2P transfer (P2P write)
12903  *
12904  * \param[in] pSession Pointer to source card destination
12905  * \param[in] source Pointer to source frame to transmit
12906  * \param[in] ui64DestAddr Destination address on target device
12907  * \param[in] ui32FrameSize Size of frame to transfer
12908  *
12909  * \return on success
12910  * NI_RETCODE_SUCCESS
12911  * on failure
12912  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12913  * NI_RETCODE_INVALID_PARAM
12914  * NI_RETCODE_ERROR_INVALID_SESSION
12915  * NI_RETCODE_ERROR_MEM_ALOC
12916  * NI_RETCODE_ERROR_NVME_CMD_FAILED
12917 *******************************************************************************/
12919  niFrameSurface1_t *source,
12920  uint64_t ui64DestAddr, uint32_t ui32FrameSize)
12921 {
12923 
12924  if ((pSession == NULL) || (source == NULL))
12925  {
12926  return NI_RETCODE_INVALID_PARAM;
12927  }
12928 
12929  /* Firmware compatibility check */
12930  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
12931  {
12932  ni_log2(pSession, NI_LOG_ERROR, "%s: FW doesn't support this operation\n", __func__);
12934  }
12935 
12936  retval = ni_send_to_target(pSession, source, ui64DestAddr, ui32FrameSize);
12937 
12938  if (retval < 0)
12939  {
12940  ni_log2(pSession, NI_LOG_ERROR, "%s(): Can't DMA to destination (%d)\n", __func__, retval);
12941  }
12942 
12943  return retval;
12944 }
12945 
12946 /*!*****************************************************************************
12947  * \brief Initiate a P2P transfer (P2P read)
12948  *
12949  * \param[in] pSession Pointer to destination upload session
12950  * \param[in] dmaAddrs Pointer to source DMA addresses
12951  * \param[in] pDstFrame Pointer to destination P2P frame
12952  *
12953  * \return on success
12954  * NI_RETCODE_SUCCESS
12955  * on failure
12956  * NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
12957  * NI_RETCODE_INVALID_PARAM
12958  * NI_RETCODE_ERROR_INVALID_SESSION
12959  * NI_RETCODE_ERROR_MEM_ALOC
12960  * NI_RETCODE_ERROR_NVME_CMD_FAILED
12961 *******************************************************************************/
12963  const ni_p2p_sgl_t *dmaAddrs,
12964  ni_frame_t *pDstFrame)
12965 {
12967 
12968  if ((pSession == NULL) || (dmaAddrs == NULL) || (pDstFrame == NULL))
12969  {
12970  return NI_RETCODE_INVALID_PARAM;
12971  }
12972 
12973  /* Firmware compatibility check */
12974  if (ni_cmp_fw_api_ver((char *) &pSession->fw_rev[NI_XCODER_REVISION_API_MAJOR_VER_IDX], "6re") < 0)
12975  {
12976  ni_log2(pSession, NI_LOG_ERROR,
12977  "%s: FW doesn't support this operation\n", __func__);
12979  }
12980 
12981  retval = ni_recv_from_target(pSession, dmaAddrs, pDstFrame);
12982 
12983  if (retval < 0)
12984  {
12985  ni_log2(pSession, NI_LOG_ERROR,
12986  "%s(): Can't DMA from source (%d)\n", __func__, retval);
12987  retval = NI_RETCODE_INVALID_PARAM;
12988  }
12989 
12990  return retval;
12991 }
12992 
12993 /*!*****************************************************************************
12994  * \brief Send a restart command after flush command
12995  * Only support Encoder now
12996  *
12997  * \param[in] p_ctx Pointer to a caller allocated
12998  * ni_session_context_t struct
12999  * \param[in] width width, in pixels
13000  * \param[in] height height, in pixels
13001  * \param[in] device_type NI_DEVICE_TYPE_ENCODER
13002  * \return On success
13003  * NI_RETCODE_SUCCESS
13004  * On failure
13005  * NI_RETCODE_INVALID_PARAM
13006  * NI_RETCODE_ERROR_NVME_CMD_FAILED
13007  * NI_RETCODE_ERROR_INVALID_SESSION
13008  ******************************************************************************/
13010  int video_width,
13011  int video_height,
13012  ni_device_type_t device_type)
13013 {
13014  ni_retcode_t retval = 0;
13015  ni_resolution_t resolution;
13016  ni_xcoder_params_t *p_param = NULL;
13017 
13018  if (!p_ctx)
13019  {
13020  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() passed parameters are null, return\n",
13021  __func__);
13022  return NI_RETCODE_INVALID_PARAM;
13023  }
13024 
13025  switch (device_type)
13026  {
13028  {
13029  // requires API version >= 54
13031  "54") < 0)
13032  {
13033  ni_log2(p_ctx, NI_LOG_ERROR, "Error: %s function not supported on device with FW API version < 5.4\n", __func__);
13035  }
13036 
13037  /* This function should be called only if flushing is detected */
13039  {
13040  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() wrong state %d\n",
13041  __func__, p_ctx->session_run_state);
13043  }
13044 
13045  if (video_width < NI_MIN_WIDTH || video_width > NI_MAX_WIDTH ||
13046  video_height < NI_MIN_HEIGHT || video_height > NI_MAX_HEIGHT)
13047  {
13048  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() invalid width %d or height %d\n",
13049  __func__, video_width, video_height);
13050  return NI_RETCODE_INVALID_PARAM;
13051  }
13052  resolution.width = video_width;
13053  resolution.height = video_height;
13054  resolution.bit_depth_factor = p_ctx->bit_depth_factor;
13055  resolution.luma_linesize = 0;
13056  resolution.chroma_linesize = 0;
13057  if (p_ctx->p_session_config)
13058  {
13059  p_param = (ni_xcoder_params_t *)p_ctx->p_session_config;
13060  resolution.luma_linesize = p_param->luma_linesize;
13061  resolution.chroma_linesize = p_param->chroma_linesize;
13062  }
13063  ni_pthread_mutex_lock(&p_ctx->mutex);
13064 
13065  // reconfig the encoder session
13066  retval = ni_encoder_session_sequence_change(p_ctx, &resolution);
13067  if (NI_RETCODE_SUCCESS != retval)
13068  {
13069  ni_log(NI_LOG_ERROR, "Failed to reconfig config the encoder session (status = %d)\n", retval);
13070  ni_pthread_mutex_unlock(&p_ctx->mutex);
13071  return retval;
13072  }
13073 
13074  // update session context
13075  p_ctx->ready_to_close = 0;
13076  p_ctx->frame_num = 0;
13077  p_ctx->pkt_num = 0;
13078  ni_pthread_mutex_unlock(&p_ctx->mutex);
13079  break;
13080  }
13081  default:
13082  {
13083  retval = NI_RETCODE_INVALID_PARAM;
13084  ni_log2(p_ctx, NI_LOG_ERROR, "ERROR: %s() Unsupported device type: %d",
13085  __func__, device_type);
13086  break;
13087  }
13088  }
13089  return retval;
13090 }
XCODER_TEST_RECONF_LTR_INTERVAL_API
@ XCODER_TEST_RECONF_LTR_INTERVAL_API
Definition: ni_device_api.h:1772
NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G2_TEMPORAL_ID
Definition: ni_device_api.h:1873
_ni_xcoder_params::reconf_demo_mode
int reconf_demo_mode
Definition: ni_device_api.h:2761
CONFIG_INSTANCE_SetScalerWatermarkPara_W
#define CONFIG_INSTANCE_SetScalerWatermarkPara_W(sid, instance)
Definition: ni_nvme.h:828
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:11815
_ni_encoder_cfg_params::enable_mb_level_rc
int enable_mb_level_rc
Definition: ni_device_api.h:2398
_ni_long_term_ref::use_long_term_ref
uint8_t use_long_term_ref
Definition: ni_device_api.h:693
NI_ENC_PARAM_ROI_DEMO_MODE
#define NI_ENC_PARAM_ROI_DEMO_MODE
Definition: ni_device_api.h:2072
_ni_encoder_cfg_params::frame_rate
int frame_rate
Definition: ni_device_api.h:2253
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MAX
Definition: ni_device_api.h:287
NI_XCODER_CLOSE_STATE
@ NI_XCODER_CLOSE_STATE
Definition: ni_device_api.h:249
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:11853
_ni_xcoder_params::fps_denominator
uint32_t fps_denominator
Definition: ni_device_api.h:2749
NI_ENC_PARAM_LINK_FRAME_MAX_INTRA_RATIO
#define NI_ENC_PARAM_LINK_FRAME_MAX_INTRA_RATIO
Definition: ni_device_api.h:2249
NI_PIX_FMT_UYVY422
@ NI_PIX_FMT_UYVY422
Definition: ni_device_api.h:275
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:11320
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:2196
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:18557
_ni_xcoder_params::luma_linesize
int luma_linesize
Definition: ni_device_api.h:2814
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:1876
NI_PIX_FMT_BGRA
@ NI_PIX_FMT_BGRA
Definition: ni_device_api.h:268
_ni_scaler_input_params_t::output_height
int32_t output_height
Definition: ni_device_api.h:2577
_ni_session_context::force_idr_frame
int force_idr_frame
Definition: ni_device_api.h:1602
NI_CODEC_FORMAT_JPEG
@ NI_CODEC_FORMAT_JPEG
Definition: ni_device_api.h:916
_ni_encoder_cfg_params::ver_offset
int ver_offset
Definition: ni_device_api.h:2412
NI_DEC_PARAM_SCALE_0_RES_CEIL
#define NI_DEC_PARAM_SCALE_0_RES_CEIL
Definition: ni_device_api.h:2489
NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
@ NI_FRAME_AUX_DATA_MAX_FRAME_SIZE
Definition: ni_device_api.h:568
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:2203
_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:4067
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:8756
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:17985
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:4067
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:1892
NI_DEC_PARAM_SKIP_PTS_GUESS
#define NI_DEC_PARAM_SKIP_PTS_GUESS
Definition: ni_device_api.h:2511
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:1589
_ni_decoder_input_params_t::mcmode
int mcmode
Definition: ni_device_api.h:2523
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:5646
NI_DEVICE_TYPE_ENCODER
@ NI_DEVICE_TYPE_ENCODER
Definition: ni_defs.h:359
NI_ENC_PARAM_MAX_FRAME_SIZE_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_LOW_DELAY
Definition: ni_device_api.h:2153
NI_DEC_PARAM_SCALE_2_RES_CEIL
#define NI_DEC_PARAM_SCALE_2_RES_CEIL
Definition: ni_device_api.h:2491
_ni_frame::separate_start
uint8_t separate_start
Definition: ni_device_api.h:2733
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:1762
NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
#define NI_ENC_PARAM_USE_RECOMMENDED_ENC_PARAMS
Definition: ni_device_api.h:2086
_ni_p2p_sgl_t
Definition: ni_defs.h:415
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:2693
NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
#define NI_ENC_PARAM_CUSTOMIZE_ROI_QP_LEVEL
Definition: ni_device_api.h:2235
_ni_network_data
Definition: ni_device_api.h:1365
_ni_xcoder_params::dolby_vision_profile
int dolby_vision_profile
Definition: ni_device_api.h:2769
_ni_session_context::ltr_interval
int32_t ltr_interval
Definition: ni_device_api.h:1604
NI_DEC_PARAM_SCALE_0
#define NI_DEC_PARAM_SCALE_0
Definition: ni_device_api.h:2483
_ni_resolution::chroma_linesize
int32_t chroma_linesize
Definition: ni_device_api_priv.h:689
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1943
_ni_session_context::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:1596
_ni_decoder_input_params_t::error_ratio_threshold
int error_ratio_threshold
Definition: ni_device_api.h:2559
NI_ENC_PARAM_CONF_WIN_RIGHT
#define NI_ENC_PARAM_CONF_WIN_RIGHT
Definition: ni_device_api.h:2106
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:9647
_ni_thread_arg_struct_t::p_mutex
ni_pthread_mutex_t * p_mutex
Definition: ni_device_api.h:1269
NI_ENC_PARAM_TOL_RC_INTRA
#define NI_ENC_PARAM_TOL_RC_INTRA
Definition: ni_device_api.h:2164
_ni_encoder_cfg_params::skip_frame_interval
int skip_frame_interval
Definition: ni_device_api.h:2433
ni_pix_fmt_t
ni_pix_fmt_t
Definition: ni_device_api.h:261
NI_EC_POLICY_SKIP
#define NI_EC_POLICY_SKIP
Definition: ni_device_api.h:322
QUERY_GET_NVME_STATUS_R
#define QUERY_GET_NVME_STATUS_R
Definition: ni_nvme.h:789
NI_XCODER_PRESET_NAME_CUSTOM
#define NI_XCODER_PRESET_NAME_CUSTOM
Definition: ni_device_api.h:2910
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:2366
_ni_encoder_cfg_params::hor_offset
int hor_offset
Definition: ni_device_api.h:2411
_ni_encoder_cfg_params::inLoopDSRatio
int inLoopDSRatio
Definition: ni_device_api.h:2349
NI_ENC_PARAM_GET_PSNR_MODE
#define NI_ENC_PARAM_GET_PSNR_MODE
Definition: ni_device_api.h:2233
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:2640
NI_ENC_PARAM_LTR_REF_INTERVAL
#define NI_ENC_PARAM_LTR_REF_INTERVAL
Definition: ni_device_api.h:2156
XCODER_TEST_RECONF_END
@ XCODER_TEST_RECONF_END
Definition: ni_device_api.h:1782
NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_ENC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2225
XCODER_TEST_CRF_API
@ XCODER_TEST_CRF_API
Definition: ni_device_api.h:1777
_ni_enc_avc_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:872
NI_ENC_PARAM_INTRA_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_REFRESH_MODE
Definition: ni_device_api.h:2122
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:14295
NI_XCODER_LOG_NAME_WARN
#define NI_XCODER_LOG_NAME_WARN
Definition: ni_device_api.h:2914
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:2105
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:3562
OPT
#define OPT(STR)
NI_ENC_GOP_PARAMS_G5_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G5_PIC_TYPE
Definition: ni_device_api.h:1919
NI_ENC_PARAM_TRANS_RATE
#define NI_ENC_PARAM_TRANS_RATE
Definition: ni_device_api.h:2108
NI_DEC_PARAM_PKT_PTS_UNCHANGE
#define NI_DEC_PARAM_PKT_PTS_UNCHANGE
Definition: ni_device_api.h:2512
_ni_decoder_input_params_t::enable_ppu_scale_adapt
int enable_ppu_scale_adapt
Definition: ni_device_api.h:2546
_ni_encoder_cfg_params::pbRatio
float pbRatio
Definition: ni_device_api.h:2419
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC3
Definition: ni_device_api.h:1942
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:5750
_ni_decoder_input_params_t::enable_out1
int enable_out1
Definition: ni_device_api.h:2521
_ni_network_layer_info::in_param
ni_network_layer_params_t * in_param
Definition: ni_device_api.h:1356
_ni_encoder_cfg_params::vbvBufferReencode
int vbvBufferReencode
Definition: ni_device_api.h:2456
_ni_session_context::nb_rois
int nb_rois
Definition: ni_device_api.h:1583
_ni_session_context::xcoder_state
uint32_t xcoder_state
Definition: ni_device_api.h:1570
NI_ENC_BLOCK_RC_SIZE
#define NI_ENC_BLOCK_RC_SIZE
Definition: ni_device_api.h:2167
XCODER_TEST_RECONF_MAX_FRAME_SIZE
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE
Definition: ni_device_api.h:1759
_ni_xcoder_params::padding
int padding
Definition: ni_device_api.h:2764
_ni_encoder_cfg_params::enable_filler
int enable_filler
Definition: ni_device_api.h:2390
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:1701
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1939
ni_config_instance_hvsplus
ni_retcode_t ni_config_instance_hvsplus(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:16278
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:3398
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:17593
_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:1901
NI_DEC_PARAM_LOW_DELAY
#define NI_DEC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2497
_ni_encoder_cfg_params::gopLowdelay
int gopLowdelay
Definition: ni_device_api.h:2338
NI_XCODER_LOG_NAME_FULL
#define NI_XCODER_LOG_NAME_FULL
Definition: ni_device_api.h:2917
NI_MIN_KEEP_ALIVE_TIMEOUT
#define NI_MIN_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:312
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:9180
NI_DEC_PARAM_ENABLE_OUT_2
#define NI_DEC_PARAM_ENABLE_OUT_2
Definition: ni_device_api.h:2470
_ni_gop_rps::ref_pic_used
int ref_pic_used
Definition: ni_device_api.h:1963
_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:1490
NI_ENC_NEW_RC_ENABLE
#define NI_ENC_NEW_RC_ENABLE
Definition: ni_device_api.h:2170
NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
#define NI_ENC_PARAM_TEMPORAL_LAYERS_ENABLE
Definition: ni_device_api.h:2199
_ni_scaler_input_params_t::op
ni_scaler_opcode_t op
Definition: ni_device_api.h:2584
NI_INVALID_IO_SIZE
#define NI_INVALID_IO_SIZE
Definition: ni_defs.h:233
ni_device_session_query
ni_retcode_t ni_device_session_query(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query session data from the device - If device_type is valid, will query session data from specified ...
Definition: ni_device_api.c:1920
_ni_session_context::frame_time_q
void * frame_time_q
Definition: ni_device_api.h:1415
XCODER_TEST_RECONF_LTR_INTERVAL
@ XCODER_TEST_RECONF_LTR_INTERVAL
Definition: ni_device_api.h:1756
_ni_encoder_cfg_params::statistic_output_level
int statistic_output_level
Definition: ni_device_api.h:2430
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1853
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:18347
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:2089
NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
#define NI_ENC_PARAM_CRF_MAX_IFRAME_ENABLE
Definition: ni_device_api.h:2226
XCODER_TEST_RECONF_FRAMERATE_API
@ XCODER_TEST_RECONF_FRAMERATE_API
Definition: ni_device_api.h:1774
_ni_decoder_input_params_t::ec_policy
int ec_policy
Definition: ni_device_api.h:2544
NI_ENC_PARAM_MAX_QP
#define NI_ENC_PARAM_MAX_QP
Definition: ni_device_api.h:2099
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:1921
_ni_frame::metadata_buffer_size
uint32_t metadata_buffer_size
Definition: ni_device_api.h:2722
_ni_decoder_input_params_t::skip_pts_guess
int skip_pts_guess
Definition: ni_device_api.h:2549
NI_ENC_PARAM_BITRATE
#define NI_ENC_PARAM_BITRATE
Definition: ni_device_api.h:2069
_ni_vui_hrd
Definition: ni_device_api.h:656
_ni_rc_min_max_qp::minQpI
int32_t minQpI
Definition: ni_device_api.h:708
_ni_encoder_cfg_params::temporal_layers_enable
int temporal_layers_enable
Definition: ni_device_api.h:2406
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:14243
NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_INTERVAL
Definition: ni_device_api.h:2174
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:1624
netint_iocmd_attach_rfence
Definition: ni_p2p_ioctl.h:80
_niFrameSurface1::ui16height
uint16_t ui16height
Definition: ni_device_api.h:2828
NI_DEVICE_TYPE_DECODER
@ NI_DEVICE_TYPE_DECODER
Definition: ni_defs.h:358
_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:1183
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1851
NI_ENC_PARAM_ALLOCATE_STRAEGY
#define NI_ENC_PARAM_ALLOCATE_STRAEGY
Definition: ni_device_api.h:2238
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:10080
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:11117
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1883
_ni_session_context::roi_side_data_size
int roi_side_data_size
Definition: ni_device_api.h:1580
NI_ENC_PARAM_CU_SIZE_MODE
#define NI_ENC_PARAM_CU_SIZE_MODE
Definition: ni_device_api.h:2088
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API
Definition: ni_device_api.h:1776
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:1711
_ni_session_context::current_frame_delay
int current_frame_delay
Definition: ni_device_api.h:1695
_ni_scaler_watermark_params_t
Definition: ni_device_api.h:2605
NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G1_TEMPORAL_ID
Definition: ni_device_api.h:1858
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:1482
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:15794
_ni_xcoder_params::source_width
int source_width
Definition: ni_device_api.h:2753
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:2671
NI_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_RETCODE_ERROR_GET_DEVICE_POOL
Definition: ni_defs.h:518
NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
#define NI_DEC_PARAM_ENABLE_FOLLOW_IFRAME
Definition: ni_device_api.h:2514
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:239
NI_ENC_PARAM_GDR_DURATION
#define NI_ENC_PARAM_GDR_DURATION
Definition: ni_device_api.h:2145
_ni_input_frame::usable
int8_t usable
Definition: ni_device_api.h:1407
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:9997
_ni_decoder_input_params_t::enable_ppu_scale_limit
int enable_ppu_scale_limit
Definition: ni_device_api.h:2547
_ni_scaler_input_params_t::out_rec_height
int32_t out_rec_height
Definition: ni_device_api.h:2579
NI_SCALER_OPCODE_WATERMARK
@ NI_SCALER_OPCODE_WATERMARK
Definition: ni_defs.h:594
_ni_encoder_cfg_params::ltrRefInterval
int ltrRefInterval
Definition: ni_device_api.h:2299
_ni_session_context::target_bitrate
int32_t target_bitrate
Definition: ni_device_api.h:1601
_ni_session_context::mutex_initialized
bool mutex_initialized
Definition: ni_device_api.h:1673
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:11611
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:8697
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:16006
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:11410
NI_ENC_PARAM_CONF_WIN_TOP
#define NI_ENC_PARAM_CONF_WIN_TOP
Definition: ni_device_api.h:2103
_ni_session_context::netint_fd
int netint_fd
Definition: ni_device_api.h:1620
QOS_OP_CONFIG_REC_OP_CODE
@ QOS_OP_CONFIG_REC_OP_CODE
Definition: ni_device_api.h:238
NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
#define NI_ENC_PARAM_NO_HW_MULTIPASS_SUPPORT
Definition: ni_device_api.h:2213
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2
Definition: ni_device_api.h:1955
NI_PIX_FMT_YUV420P
@ NI_PIX_FMT_YUV420P
Definition: ni_device_api.h:263
NI_DEC_PARAM_FORCE_8BIT_1
#define NI_DEC_PARAM_FORCE_8BIT_1
Definition: ni_device_api.h:2472
NI_ENC_PARAM_BITRATE_MODE
#define NI_ENC_PARAM_BITRATE_MODE
Definition: ni_device_api.h:2221
NI_EC_POLICY_IGNORE
#define NI_EC_POLICY_IGNORE
Definition: ni_device_api.h:321
_ni_rc_min_max_qp
Definition: ni_device_api.h:706
_ni_resolution
Definition: ni_device_api_priv.h:677
NI_ENC_PARAM_COLOR_PRIMARY
#define NI_ENC_PARAM_COLOR_PRIMARY
Definition: ni_device_api.h:2184
ni_device_type_t
ni_device_type_t
Definition: ni_defs.h:353
NI_ENC_PARAM_LONG_TERM_REFERENCE_ENABLE
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_ENABLE
Definition: ni_device_api.h:2172
_niFrameSurface1::ui32nodeAddress
uint32_t ui32nodeAddress
Definition: ni_device_api.h:2829
_ni_session_context::isP2P
int32_t isP2P
Definition: ni_device_api.h:1619
_ni_encoder_cfg_params::enable_hvs_qp_scale
int enable_hvs_qp_scale
Definition: ni_device_api.h:2395
NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
#define NI_ENC_PARAM_ENABLE_HVS_QP_SCALE
Definition: ni_device_api.h:2096
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC3
Definition: ni_device_api.h:1867
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:248
_ni_encoder_cfg_params::trans_rate
int trans_rate
Definition: ni_device_api.h:2397
_ni_thread_arg_struct_t::close_thread
bool close_thread
Definition: ni_device_api.h:1264
NI_INVALID_HWID
#define NI_INVALID_HWID
Definition: ni_defs.h:232
_ni_session_data_io::packet
ni_packet_t packet
Definition: ni_device_api.h:2901
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:2812
NI_ENC_GOP_PARAMS_G7_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G7_PIC_TYPE
Definition: ni_device_api.h:1949
_ni_frame::src_codec
ni_codec_format_t src_codec
Definition: ni_device_api.h:2630
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1
Definition: ni_device_api.h:1863
_ni_session_context::ltr_to_set
ni_long_term_ref_t ltr_to_set
Definition: ni_device_api.h:1603
NI_DEC_PARAM_SCALE_1
#define NI_DEC_PARAM_SCALE_1
Definition: ni_device_api.h:2484
NI_ENC_PARAM_NO_MBTREE
#define NI_ENC_PARAM_NO_MBTREE
Definition: ni_device_api.h:2212
_ni_encoder_cfg_params::crf_max_iframe_enable
int crf_max_iframe_enable
Definition: ni_device_api.h:2437
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:1765
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:439
NI_XCODER_LOG_NAME_NONE
#define NI_XCODER_LOG_NAME_NONE
Definition: ni_device_api.h:2912
_ni_session_context::active_video_width
uint32_t active_video_width
Definition: ni_device_api.h:1551
NI_ENC_PARAM_CROP_HEIGHT
#define NI_ENC_PARAM_CROP_HEIGHT
Definition: ni_device_api.h:2207
_ni_gop_params::poc_offset
int poc_offset
Definition: ni_device_api.h:1968
_ni_gop_params::qp_offset
int qp_offset
Definition: ni_device_api.h:1969
_ni_framerate::framerate_denom
int32_t framerate_denom
Definition: ni_device_api.h:703
NI_DEVICE_TYPE_UPLOAD
@ NI_DEVICE_TYPE_UPLOAD
Definition: ni_defs.h:365
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:2541
NI_ENC_PARAM_LTR_FIRST_GAP
#define NI_ENC_PARAM_LTR_FIRST_GAP
Definition: ni_device_api.h:2158
ni_ai_session_open
ni_retcode_t ni_ai_session_open(ni_session_context_t *p_ctx)
Definition: ni_device_api_priv.c:17159
NI_XCODER_HWDL_STATE
@ NI_XCODER_HWDL_STATE
Definition: ni_device_api.h:256
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:3532
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:1621
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:10195
_ni_session_context::pool_type
ni_frame_pool_type_t pool_type
Definition: ni_device_api.h:1699
_ni_session_context::av_rois
ni_region_of_interest_t * av_rois
Definition: ni_device_api.h:1582
NI_DEC_PARAM_FORCE_8BIT_2
#define NI_DEC_PARAM_FORCE_8BIT_2
Definition: ni_device_api.h:2473
XCODER_TEST_RECONF_CRF
@ XCODER_TEST_RECONF_CRF
Definition: ni_device_api.h:1761
NI_FRAME_AUX_DATA_CRF
@ NI_FRAME_AUX_DATA_CRF
Definition: ni_device_api.h:576
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:2401
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:1848
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:2915
_ni_xcoder_params::color_primaries
int color_primaries
Definition: ni_device_api.h:2786
_ni_encoder_cfg_params::enable_compensate_qp
int enable_compensate_qp
Definition: ni_device_api.h:2451
NI_ENC_PARAM_LOOK_AHEAD_DEPTH
#define NI_ENC_PARAM_LOOK_AHEAD_DEPTH
Definition: ni_device_api.h:2140
_ni_resolution::luma_linesize
int32_t luma_linesize
Definition: ni_device_api_priv.h:688
_ni_frame::total_start_len
uint32_t total_start_len
Definition: ni_device_api.h:2731
_ni_session_context::last_bitrate
int32_t last_bitrate
Definition: ni_device_api.h:1676
_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:3204
NI_ENC_PARAM_LTR_NEXT_INTERVAL
#define NI_ENC_PARAM_LTR_NEXT_INTERVAL
Definition: ni_device_api.h:2159
NI_DEC_CROP_MODE_AUTO
@ NI_DEC_CROP_MODE_AUTO
Definition: ni_device_api.h:931
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:1555
XCODER_TEST_RECONF_VUI_HRD
@ XCODER_TEST_RECONF_VUI_HRD
Definition: ni_device_api.h:1751
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:2342
OPT2
#define OPT2(STR1, STR2)
_ni_frame::iovec
ni_iovec_t * iovec
Definition: ni_device_api.h:2740
NI_PIX_FMT_BGR0
@ NI_PIX_FMT_BGR0
Definition: ni_device_api.h:271
NI_KEEP_ALIVE_TIMEOUT
#define NI_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:2065
XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_REDUNDANT
Definition: ni_device_api.h:1760
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:4779
_ni_load_query::pcie_throughput
uint32_t pcie_throughput
Definition: ni_device_api.h:1206
NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G5_TEMPORAL_ID
Definition: ni_device_api.h:1918
_ni_frameclone_desc
Definition: ni_device_api.h:1377
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1849
NI_EC_POLICY_LIMITED_ERROR
#define NI_EC_POLICY_LIMITED_ERROR
Definition: ni_device_api.h:324
_ni_xcoder_params::rootBufId
int rootBufId
Definition: ni_device_api.h:2805
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:315
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:2728
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:10170
_ni_session_context::event_handle
ni_event_handle_t event_handle
Definition: ni_device_api.h:1576
XCODER_TEST_RECONF_FRAMERATE
@ XCODER_TEST_RECONF_FRAMERATE
Definition: ni_device_api.h:1758
NI_ENC_PARAM_RDO_QUANT
#define NI_ENC_PARAM_RDO_QUANT
Definition: ni_device_api.h:2137
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:2468
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:327
NI_ENC_GOP_PARAMS_G2_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G2_POC_OFFSET
Definition: ni_device_api.h:1870
_ni_frame::aux_data
ni_aux_data_t * aux_data[NI_MAX_NUM_AUX_DATA_PER_FRAME]
Definition: ni_device_api.h:2703
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:2198
NI_ENC_PARAM_CBR
#define NI_ENC_PARAM_CBR
Definition: ni_device_api.h:2129
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:5360
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:10389
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:1888
NI_ENC_PARAM_ENABLE_AUD
#define NI_ENC_PARAM_ENABLE_AUD
Definition: ni_device_api.h:2141
_ni_encoder_cfg_params::enable_acq_limit
int enable_acq_limit
Definition: ni_device_api.h:2443
_ni_encoder_cfg_params::noMbtree
int noMbtree
Definition: ni_device_api.h:2415
XCODER_TEST_RECONF_INTRAPRD
@ XCODER_TEST_RECONF_INTRAPRD
Definition: ni_device_api.h:1750
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:5872
NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
#define NI_ENC_GOP_PARAMS_CUSTOM_GOP_SIZE
Definition: ni_device_api.h:2055
NI_ENC_PARAM_PRE_INTRA_HANDLING
#define NI_ENC_PARAM_PRE_INTRA_HANDLING
Definition: ni_device_api.h:2246
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:3844
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1467
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:16886
_ni_frame::start_len
uint32_t start_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2730
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:8786
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2
Definition: ni_device_api.h:1940
NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BITS_LOW_DELAY
Definition: ni_device_api.h:2154
NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
Definition: ni_defs.h:514
_ni_scaler_input_params_t
Definition: ni_device_api.h:2565
_ni_encoder_cfg_params::roi_enable
int roi_enable
Definition: ni_device_api.h:2271
_ni_encoder_cfg_params::pastFrameMaxIntraRatio
int pastFrameMaxIntraRatio
Definition: ni_device_api.h:2461
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:2274
_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:2316
NI_ENC_PARAM_ENABLE_IP_RATIO
#define NI_ENC_PARAM_ENABLE_IP_RATIO
Definition: ni_device_api.h:2216
_ni_encoder_cfg_params::spatialLayerBitrate
int spatialLayerBitrate[NI_MAX_SPATIAL_LAYERS]
Definition: ni_device_api.h:2463
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1954
_ni_decoder_input_params_t::min_packets_delay
bool min_packets_delay
Definition: ni_device_api.h:2552
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3
Definition: ni_device_api.h:1912
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC3
Definition: ni_device_api.h:1882
_ni_frame::separate_metadata
uint8_t separate_metadata
Definition: ni_device_api.h:2724
_ni_session_context::reconfig_slice_arg
int16_t reconfig_slice_arg
Definition: ni_device_api.h:1708
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:10851
_ni_encoder_cfg_params::enable_pic_skip
int enable_pic_skip
Definition: ni_device_api.h:2384
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:1936
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:1373
_ni_network_perf_metrics
Definition: ni_device_api.h:1386
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:323
_ni_encoder_cfg_params::use_recommend_enc_params
int use_recommend_enc_params
Definition: ni_device_api.h:2360
_ni_thread_arg_struct_t::p_buffer
void * p_buffer
Definition: ni_device_api.h:1268
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:2091
_ni_load_query::fw_share_mem_usage
uint32_t fw_share_mem_usage
Definition: ni_device_api.h:1212
_ni_gop_params::pic_type
int pic_type
Definition: ni_device_api.h:1972
NI_DEC_PARAM_SKIP_EXTRA_HEADERS
#define NI_DEC_PARAM_SKIP_EXTRA_HEADERS
Definition: ni_device_api.h:2518
_ni_encoder_cfg_params::min_qp
int min_qp
Definition: ni_device_api.h:2380
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:1005
NI_FRAME_AUX_DATA_SLICE_ARG
@ NI_FRAME_AUX_DATA_SLICE_ARG
Definition: ni_device_api.h:592
NI_UPLOADER_FLAG_LM
#define NI_UPLOADER_FLAG_LM
Definition: ni_device_api.h:306
NI_ENC_PARAM_HIGH_TIER
#define NI_ENC_PARAM_HIGH_TIER
Definition: ni_device_api.h:2080
_ni_encoder_cfg_params::gop_preset_index
int gop_preset_index
Definition: ni_device_api.h:2265
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1911
_ni_encoder_cfg_params::max_qp
int max_qp
Definition: ni_device_api.h:2381
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:5513
_ni_frame_config
Definition: ni_device_api.h:2838
_ni_encoder_cfg_params::ipRatio
float ipRatio
Definition: ni_device_api.h:2418
NI_PIX_FMT_BGRP
@ NI_PIX_FMT_BGRP
Definition: ni_device_api.h:272
NI_SCALER_FLAG_IO
#define NI_SCALER_FLAG_IO
Definition: ni_device_api.h:292
_ni_packet::av1_p_data
uint8_t * av1_p_data[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2875
_ni_encoder_cfg_params::blockRCSize
int blockRCSize
Definition: ni_device_api.h:2350
NI_DEC_PARAM_CROP_MODE_2
#define NI_DEC_PARAM_CROP_MODE_2
Definition: ni_device_api.h:2479
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:2760
_ni_session_context::src_endian
int src_endian
Definition: ni_device_api.h:1495
NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
@ NI_ENC_MEM_ALLOCATE_STRATEGY_INVALID_MIN
Definition: ni_device_api.h:283
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:11549
_ni_session_context::low_delay_sync_mutex
ni_pthread_mutex_t low_delay_sync_mutex
Definition: ni_device_api.h:1667
_ni_encoder_cfg_params::intra_mb_refresh_mode
int intra_mb_refresh_mode
Definition: ni_device_api.h:2275
NI_ENC_PARAM_TOL_RC_INTER
#define NI_ENC_PARAM_TOL_RC_INTER
Definition: ni_device_api.h:2163
QUERY_GET_EXTTRA_INFO_R
#define QUERY_GET_EXTTRA_INFO_R
Definition: ni_nvme.h:798
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:9736
_ni_encoder_cfg_params::vbv_buffer_size
int vbv_buffer_size
Definition: ni_device_api.h:2391
_ni_packet::av1_buffer_size
uint32_t av1_buffer_size[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2876
NI_ENC_GOP_PARAMS_G6_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G6_PIC_TYPE
Definition: ni_device_api.h:1934
_ni_frame::p_buffer
uint8_t * p_buffer
Definition: ni_device_api.h:2692
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_FLOAT
Definition: ni_device_api.h:2135
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:10506
NI_ENC_INLOOP_DS_RATIO
#define NI_ENC_INLOOP_DS_RATIO
Definition: ni_device_api.h:2166
_ni_encoder_cfg_params::noHWMultiPassSupport
int noHWMultiPassSupport
Definition: ni_device_api.h:2416
NI_ENC_PARAM_CONF_WIN_BOTTOM
#define NI_ENC_PARAM_CONF_WIN_BOTTOM
Definition: ni_device_api.h:2104
_ni_encoder_cfg_params::gdrDuration
int gdrDuration
Definition: ni_device_api.h:2298
_ni_xcoder_params::video_full_range_flag
int video_full_range_flag
Definition: ni_device_api.h:2791
XCODER_TEST_RECONF_VBV
@ XCODER_TEST_RECONF_VBV
Definition: ni_device_api.h:1763
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:2539
NI_EC_POLICY_BEST_EFFORT_OUT_DC
#define NI_EC_POLICY_BEST_EFFORT_OUT_DC
Definition: ni_device_api.h:325
_ni_encoder_cfg_params::aspectRatioWidth
int aspectRatioWidth
Definition: ni_device_api.h:2254
NI_RETCODE_INVALID_PARAM
@ NI_RETCODE_INVALID_PARAM
Definition: ni_defs.h:441
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC3
Definition: ni_device_api.h:1852
_ni_session_context::avc_roi_map
ni_enc_avc_roi_custom_map_t * avc_roi_map
Definition: ni_device_api.h:1587
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:1795
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:16426
_ni_scaler_input_params_t::input_height
int32_t input_height
Definition: ni_device_api.h:2569
_ni_session_context::buffered_frame_index
int16_t buffered_frame_index
Definition: ni_device_api.h:1719
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:1924
NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
#define NI_ENC_PARAM_HVS_BASE_MB_COMPLEXITY
Definition: ni_device_api.h:2223
_ni_encoder_cfg_params::maxFrameSizeRatio
int maxFrameSizeRatio
Definition: ni_device_api.h:2258
_ni_decoder_input_params_t::enable_advanced_ec
int enable_advanced_ec
Definition: ni_device_api.h:2545
_ni_encoder_cfg_params::HDR10AveLight
int HDR10AveLight
Definition: ni_device_api.h:2285
_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:2161
XCODER_TEST_INVALID_REF_FRAME
@ XCODER_TEST_INVALID_REF_FRAME
Definition: ni_device_api.h:1757
NI_DEFAULT_KEEP_ALIVE_TIMEOUT
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:313
NI_ENC_PARAM_DDR_PRIORITY_MODE
#define NI_ENC_PARAM_DDR_PRIORITY_MODE
Definition: ni_device_api.h:2220
NI_ENC_PARAM_SPATIAL_LAYER_BITRATE
#define NI_ENC_PARAM_SPATIAL_LAYER_BITRATE
Definition: ni_device_api.h:2250
NI_ENC_PARAM_GOP_LOW_DELAY
#define NI_ENC_PARAM_GOP_LOW_DELAY
Definition: ni_device_api.h:2144
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:2289
_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:2535
_ni_encoder_cfg_params::cu_size_mode
int cu_size_mode
Definition: ni_device_api.h:2362
_ni_packet::av1_data_len
uint32_t av1_data_len[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2877
NI_ENC_PARAM_DOLBY_VISION_PROFILE
#define NI_ENC_PARAM_DOLBY_VISION_PROFILE
Definition: ni_device_api.h:2147
_ni_encoder_cfg_params::hrdEnable
int hrdEnable
Definition: ni_device_api.h:2317
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:9134
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1496
XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP_API_REDUNDANT
Definition: ni_device_api.h:1771
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1909
NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
#define NI_ENC_PARAM_INTRA_REFRESH_MIN_PERIOD
Definition: ni_device_api.h:2130
_ni_session_context::reconfig_crf_decimal
int reconfig_crf_decimal
Definition: ni_device_api.h:1688
_ni_encoder_change_params_t
This is a data structure for encoding parameters that have changed.
Definition: ni_device_api.h:984
_ni_encoder_cfg_params::encMallocStrategy
int encMallocStrategy
Definition: ni_device_api.h:2449
NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_0_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2486
_ni_xcoder_params::log
int log
Definition: ni_device_api.h:2745
_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:2358
_ni_session_context::mutex
ni_pthread_mutex_t mutex
Definition: ni_device_api.h:1567
_ni_encoder_cfg_params::max_num_merge
int max_num_merge
Definition: ni_device_api.h:2363
_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:1973
_ni_packet::av1_buffer_index
int av1_buffer_index
Definition: ni_device_api.h:2878
_ni_decoder_input_params_t::crop_mode
int crop_mode[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2527
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:15564
_ni_aux_data::size
int size
Definition: ni_device_api.h:624
_ni_encoder_cfg_params::crf
int crf
Definition: ni_device_api.h:2283
_ni_load_query::pcie_load
uint32_t pcie_load
Definition: ni_device_api.h:1210
NI_ENC_PARAM_BASE_LAYER_ONLY
#define NI_ENC_PARAM_BASE_LAYER_ONLY
Definition: ni_device_api.h:2247
NI_ENC_REPEAT_HEADERS_FIRST_IDR
#define NI_ENC_REPEAT_HEADERS_FIRST_IDR
Definition: ni_device_api.h:2063
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1480
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:1877
NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_32X32_MERGE
Definition: ni_device_api.h:2092
_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:588
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:10446
_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:2748
NI_FRAME_AUX_DATA_VBV_MAX_RATE
@ NI_FRAME_AUX_DATA_VBV_MAX_RATE
Definition: ni_device_api.h:584
NI_DEC_PARAM_CROP_MODE_0
#define NI_DEC_PARAM_CROP_MODE_0
Definition: ni_device_api.h:2477
_ni_enc_quad_roi_custom_map::roiAbsQp_flag
uint8_t roiAbsQp_flag
Definition: ni_device_api.h:889
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:1868
NI_ENC_PARAM_IP_RATIO
#define NI_ENC_PARAM_IP_RATIO
Definition: ni_device_api.h:2215
NI_DEC_PARAM_MULTICORE_JOINT_MODE
#define NI_DEC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2495
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:3334
NI_XCODER_OPEN_STATE
@ NI_XCODER_OPEN_STATE
Definition: ni_device_api.h:246
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1928
_ni_scaler_input_params_t::input_format
int input_format
Definition: ni_device_api.h:2567
_ni_xcoder_params::hdrEnableVUI
int hdrEnableVUI
Definition: ni_device_api.h:2775
NI_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:318
_ni_scaler_params_t
Definition: ni_device_api.h:2587
NI_ENC_GOP_PARAMS_G0_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G0_PIC_TYPE
Definition: ni_device_api.h:1844
_ni_scaler_input_params_t::out_rec_width
int32_t out_rec_width
Definition: ni_device_api.h:2578
NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
Definition: ni_defs.h:510
_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:335
_ni_encoder_cfg_params::enable_timecode
int enable_timecode
Definition: ni_device_api.h:2453
NI_ENC_GOP_PARAMS_G4_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G4_PIC_TYPE
Definition: ni_device_api.h:1904
NI_DEC_PARAM_ENABLE_OUT_1
#define NI_DEC_PARAM_ENABLE_OUT_1
Definition: ni_device_api.h:2469
_ni_session_context::reconfig_intra_period
int reconfig_intra_period
Definition: ni_device_api.h:1706
NI_ENC_PARAM_FORCE_FRAME_TYPE
#define NI_ENC_PARAM_FORCE_FRAME_TYPE
Definition: ni_device_api.h:2077
NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_MEM_ALOC
Definition: ni_defs.h:443
ni_retcode_t
ni_retcode_t
Definition: ni_defs.h:437
_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:572
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:9082
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:7904
NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
#define NI_ENC_PARAM_MAX_FRAME_SIZE_BYTES_LOW_DELAY
Definition: ni_device_api.h:2155
NI_MAX_KEEP_ALIVE_TIMEOUT
#define NI_MAX_KEEP_ALIVE_TIMEOUT
Definition: ni_device_api.h:311
_ni_enc_hevc_roi_custom_map::sub_ctu_qp_2
uint32_t sub_ctu_qp_2
Definition: ni_device_api.h:859
_ni_vui_hrd::colorPrimaries
int32_t colorPrimaries
Definition: ni_device_api.h:663
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:857
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:10909
SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
Definition: ni_device_api.h:1180
NI_FW_META_DATA_SZ
#define NI_FW_META_DATA_SZ
Definition: ni_defs.h:318
ni_nvme_send_write_cmd
int32_t ni_nvme_send_write_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose a io write command.
Definition: ni_nvme.c:660
_ni_session_context::fw_rev
uint8_t fw_rev[8]
Definition: ni_device_api.h:1627
NI_DEC_PARAM_SEMI_PLANAR_1
#define NI_DEC_PARAM_SEMI_PLANAR_1
Definition: ni_device_api.h:2475
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:1368
_ni_encoder_cfg_params::intra_mb_refresh_arg
int intra_mb_refresh_arg
Definition: ni_device_api.h:2276
SESSION_RUN_STATE_NORMAL
@ SESSION_RUN_STATE_NORMAL
Definition: ni_device_api.h:1179
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:3714
NI_ENC_GOP_PARAMS_G1_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G1_QP_OFFSET
Definition: ni_device_api.h:1856
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:4006
NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
#define NI_BITRATE_RECONFIG_FILE_MAX_ENTRIES_PER_LINE
Definition: ni_device_api.h:478
NI_ENC_PARAM_MIN_FRAMES_DELAY
#define NI_ENC_PARAM_MIN_FRAMES_DELAY
Definition: ni_device_api.h:2085
_ni_encoder_cfg_params::pps_init_qp
int pps_init_qp
Definition: ni_device_api.h:2421
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:18273
NI_RETCODE_PARAM_INVALID_VALUE
@ NI_RETCODE_PARAM_INVALID_VALUE
Definition: ni_defs.h:449
STRDUP
#define STRDUP(value)
NI_ENC_PARAM_MAX_CLL
#define NI_ENC_PARAM_MAX_CLL
Definition: ni_device_api.h:2138
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1
Definition: ni_device_api.h:1878
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1862
_ni_encoder_cfg_params::gopSize
int gopSize
Definition: ni_device_api.h:2337
_ni_session_context::reconfig_vbv_buffer_size
int reconfig_vbv_buffer_size
Definition: ni_device_api.h:1690
_ni_session_context::framerate
ni_framerate_t framerate
Definition: ni_device_api.h:1606
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:1569
_ni_session_context::pext_mutex
ni_pthread_mutex_t * pext_mutex
Definition: ni_device_api.h:1672
_ni_frame::iovec_num
uint32_t iovec_num
Definition: ni_device_api.h:2739
_ni_thread_arg_struct_t::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1266
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2
Definition: ni_device_api.h:1895
_ni_decoder_input_params_t::crop_whxy
int crop_whxy[NI_MAX_NUM_OF_DECODER_OUTPUTS][4]
Definition: ni_device_api.h:2528
_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:472
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:3299
_ni_encoder_cfg_params::qlevel
int qlevel
Definition: ni_device_api.h:2332
NI_MAX_SPATIAL_LAYERS
#define NI_MAX_SPATIAL_LAYERS
Definition: ni_device_api.h:180
_ni_decoder_input_params_t::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2536
_ni_custom_gop_params::custom_gop_size
int custom_gop_size
Definition: ni_device_api.h:2059
XCODER_TEST_RECONF_OFF
@ XCODER_TEST_RECONF_OFF
Definition: ni_device_api.h:1748
_ni_scaler_input_params_t::rgba_color
uint32_t rgba_color
Definition: ni_device_api.h:2583
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:2825
NI_ENC_PARAM_CACHE_ROI
#define NI_ENC_PARAM_CACHE_ROI
Definition: ni_device_api.h:2073
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:3237
_ni_encoder_cfg_params::HDR10dx2
int HDR10dx2
Definition: ni_device_api.h:2292
_ni_long_term_ref
Definition: ni_device_api.h:685
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:659
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:1691
NI_ENC_PARAM_SPATIAL_LAYERS
#define NI_ENC_PARAM_SPATIAL_LAYERS
Definition: ni_device_api.h:2239
NI_ENC_PARAM_INTRA_REFRESH_ARG
#define NI_ENC_PARAM_INTRA_REFRESH_ARG
Definition: ni_device_api.h:2123
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:15473
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:10690
NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PICS
Definition: ni_device_api.h:1920
NI_DEC_PARAM_CROP_PARAM_0
#define NI_DEC_PARAM_CROP_PARAM_0
Definition: ni_device_api.h:2480
NI_DEC_PARAM_CROP_PARAM_1
#define NI_DEC_PARAM_CROP_PARAM_1
Definition: ni_device_api.h:2481
_ni_encoder_cfg_params::HDR10wx
int HDR10wx
Definition: ni_device_api.h:2294
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:11719
NI_ENC_PARAM_ENABLE_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_RATE_CONTROL
Definition: ni_device_api.h:2093
NI_ENC_PARAM_VBV_BUFFER_REENCODE
#define NI_ENC_PARAM_VBV_BUFFER_REENCODE
Definition: ni_device_api.h:2243
atof
#define atof(p_str)
Definition: ni_device_api.c:7264
_ni_xcoder_params::source_height
int source_height
Definition: ni_device_api.h:2758
NI_ENC_GOP_PARAMS_G5_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G5_QP_OFFSET
Definition: ni_device_api.h:1916
NI_APP_ENC_FRAME_META_DATA_SIZE
#define NI_APP_ENC_FRAME_META_DATA_SIZE
Definition: ni_defs.h:320
_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:2531
_ni_encoder_cfg_params::rcQpDeltaRange
int rcQpDeltaRange
Definition: ni_device_api.h:2354
_ni_encoder_change_params_t::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:1003
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:1767
_ni_encoder_cfg_params::hvsBaseMbComplexity
int hvsBaseMbComplexity
Definition: ni_device_api.h:2425
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:422
_ni_frame::ni_pict_type
ni_pic_type_t ni_pict_type
Definition: ni_device_api.h:2653
_ni_session_context::src_bit_depth
int src_bit_depth
Definition: ni_device_api.h:1494
NI_FRAME_AUX_DATA_VUI
@ NI_FRAME_AUX_DATA_VUI
Definition: ni_device_api.h:545
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:667
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:700
NI_VPU_ALIGN16
#define NI_VPU_ALIGN16(_x)
Definition: ni_device_api.h:333
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:5062
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:2296
_ni_network_data::linfo
ni_network_layer_info_t linfo
Definition: ni_device_api.h:1369
_niFrameSurface1::ui16session_ID
uint16_t ui16session_ID
Definition: ni_device_api.h:2826
NI_SCALER_OPCODE_OVERLAY
@ NI_SCALER_OPCODE_OVERLAY
Definition: ni_defs.h:589
NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
@ NI_RETCODE_ERROR_UNSUPPORTED_FW_VERSION
Definition: ni_defs.h:533
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:2795
NI_ENC_PARAM_RDO_LEVEL
#define NI_ENC_PARAM_RDO_LEVEL
Definition: ni_device_api.h:2136
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:9867
NI_ENC_PARAM_PROFILE
#define NI_ENC_PARAM_PROFILE
Definition: ni_device_api.h:2078
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:2392
_ni_gop_params::qp_factor
float qp_factor
Definition: ni_device_api.h:1970
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:2772
_ni_gop_rps::ref_pic
int ref_pic
Definition: ni_device_api.h:1962
NI_XCODER_IDLE_STATE
@ NI_XCODER_IDLE_STATE
Definition: ni_device_api.h:245
NI_PIX_FMT_NV12
@ NI_PIX_FMT_NV12
Definition: ni_device_api.h:265
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:7282
XCODER_TEST_RECONF_INTRAPRD_API
@ XCODER_TEST_RECONF_INTRAPRD_API
Definition: ni_device_api.h:1768
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2690
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:13563
_ni_session_context::pixel_format_changed
int pixel_format_changed
Definition: ni_device_api.h:1707
NI_RETCODE_ERROR_UNLOCK_DEVICE
@ NI_RETCODE_ERROR_UNLOCK_DEVICE
Definition: ni_defs.h:521
_ni_encoder_cfg_params::intra_qp
int intra_qp
Definition: ni_device_api.h:2382
QUERY_GET_VERSIONS_R
#define QUERY_GET_VERSIONS_R
Definition: ni_nvme.h:791
_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:1886
PIC_TYPE_I
@ PIC_TYPE_I
Definition: ni_device_api.h:386
_ni_encoder_cfg_params::enable_rate_control
int enable_rate_control
Definition: ni_device_api.h:2379
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:2432
NI_PIXEL_PLANAR_MAX
@ NI_PIXEL_PLANAR_MAX
Definition: ni_device_api.h:925
_ni_decoder_input_params_t::semi_planar
int semi_planar[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2526
_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:2554
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:8448
_ni_scaler_input_params_t::out_rec_y
int32_t out_rec_y
Definition: ni_device_api.h:2581
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:2121
NI_DEC_PARAM_SCALE_0_ROUND
#define NI_DEC_PARAM_SCALE_0_ROUND
Definition: ni_device_api.h:2492
_ni_decoder_input_params_t::hwframes
int hwframes
Definition: ni_device_api.h:2520
_ni_device_info
Definition: ni_rsrc_api.h:102
NI_DEVICE_TYPE_AI
@ NI_DEVICE_TYPE_AI
Definition: ni_defs.h:361
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:12710
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:14157
_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:1277
_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:2820
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:5272
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:2303
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:4148
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:4046
_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:2803
NI_FRAME_AUX_DATA_FRAMERATE
@ NI_FRAME_AUX_DATA_FRAMERATE
Definition: ni_device_api.h:564
_ni_xcoder_params::enable_ai_enhance
int enable_ai_enhance
Definition: ni_device_api.h:2811
_ni_load_query::tp_fw_load
uint32_t tp_fw_load
Definition: ni_device_api.h:1216
NI_ENC_PARAM_LTR_REF_QPOFFSET
#define NI_ENC_PARAM_LTR_REF_QPOFFSET
Definition: ni_device_api.h:2157
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:3356
NI_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_RETCODE_ERROR_NVME_CMD_FAILED
Definition: ni_defs.h:444
NI_ENC_PARAM_ENABLE_AI_ENHANCE
#define NI_ENC_PARAM_ENABLE_AI_ENHANCE
Definition: ni_device_api.h:2200
_ni_thread_arg_struct_t::device_type
uint32_t device_type
Definition: ni_device_api.h:1265
NI_ENC_PARAM_TUNE_BFRAME_VISUAL
#define NI_ENC_PARAM_TUNE_BFRAME_VISUAL
Definition: ni_device_api.h:2231
_ni_decoder_input_params_t
Definition: ni_device_api.h:2466
NI_XCODER_HWUP_STATE
@ NI_XCODER_HWUP_STATE
Definition: ni_device_api.h:255
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:2289
NI_ENC_GOP_PARAMS_G2_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G2_PIC_TYPE
Definition: ni_device_api.h:1874
_ni_encoder_cfg_params::enable_dynamic_8x8_merge
int enable_dynamic_8x8_merge
Definition: ni_device_api.h:2364
_ni_encoder_cfg_params::ctbRcMode
int ctbRcMode
Definition: ni_device_api.h:2336
_ni_scaler_drawbox_params_t
Definition: ni_device_api.h:2596
_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:2139
_ni_thread_arg_struct_t::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1270
NI_ENC_PARAM_SAR_NUM
#define NI_ENC_PARAM_SAR_NUM
Definition: ni_device_api.h:2188
NI_MEM_PAGE_ALIGNMENT
#define NI_MEM_PAGE_ALIGNMENT
Definition: ni_defs.h:263
NI_ENC_PARAM_CTB_RC_MODE
#define NI_ENC_PARAM_CTB_RC_MODE
Definition: ni_device_api.h:2142
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:2305
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:1181
NI_ENC_PARAM_PB_RATIO
#define NI_ENC_PARAM_PB_RATIO
Definition: ni_device_api.h:2217
_ni_xcoder_params::interval_of_psnr
int interval_of_psnr
Definition: ni_device_api.h:2819
NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
#define NI_ENC_PARAM_INTRA_MB_REFRESH_MODE
Definition: ni_device_api.h:2120
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1913
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:8866
NI_ENC_PARAM_ENABLE_FILLER
#define NI_ENC_PARAM_ENABLE_FILLER
Definition: ni_device_api.h:2150
NI_ENC_PARAM_ENABLE_HVS_QP
#define NI_ENC_PARAM_ENABLE_HVS_QP
Definition: ni_device_api.h:2095
ni_device_extra_info_t
struct _ni_device_extra_info ni_device_extra_info_t
_ni_buf_t
Definition: ni_device_api.h:1274
NI_CODEC_HW_DOWNLOAD
@ NI_CODEC_HW_DOWNLOAD
Definition: ni_device_api.h:943
PIC_TYPE_IDR
@ PIC_TYPE_IDR
Definition: ni_device_api.h:391
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:1840
_niFrameSurface1::encoding_type
int8_t encoding_type
Definition: ni_device_api.h:2832
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:15163
_ni_xcoder_params::generate_enc_hdrs
NI_DEPRECATED int generate_enc_hdrs
Definition: ni_device_api.h:2765
_ni_xcoder_params::hwframes
int hwframes
Definition: ni_device_api.h:2804
NI_PIX_FMT_NV16
@ NI_PIX_FMT_NV16
Definition: ni_device_api.h:273
_ni_encoder_cfg_params::newRcEnable
int newRcEnable
Definition: ni_device_api.h:2405
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1464
_ni_session_context::enc_change_params
ni_encoder_change_params_t * enc_change_params
Definition: ni_device_api.h:1594
atobool
#define atobool(p_str)
Definition: ni_device_api.c:7265
_ni_session_context::p_session_config
void * p_session_config
Definition: ni_device_api.h:1475
NI_CODEC_FORMAT_AV1
@ NI_CODEC_FORMAT_AV1
Definition: ni_device_api.h:917
_ni_encoder_cfg_params::skip_frame_enable
int skip_frame_enable
Definition: ni_device_api.h:2431
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:1322
NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:2502
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:1781
NI_ENC_PARAM_CHROMA_QP_OFFSET
#define NI_ENC_PARAM_CHROMA_QP_OFFSET
Definition: ni_device_api.h:2162
_ni_packet::av1_p_buffer
uint8_t * av1_p_buffer[MAX_AV1_ENCODER_GOP_NUM]
Definition: ni_device_api.h:2874
NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
#define NI_DEC_PARAM_ENABLE_PPU_SCALE_LIMIT
Definition: ni_device_api.h:2509
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:320
_ni_enc_avc_roi_custom_map::mb_qp
uint8_t mb_qp
Definition: ni_device_api.h:877
NI_ENC_PARAM_RECONF_DEMO_MODE
#define NI_ENC_PARAM_RECONF_DEMO_MODE
Definition: ni_device_api.h:2070
NI_DDR_PRIORITY_MAX
@ NI_DDR_PRIORITY_MAX
Definition: ni_device_api.h:1836
NI_ENC_GOP_PARAMS_G5_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G5_POC_OFFSET
Definition: ni_device_api.h:1915
_ni_encoder_cfg_params::entropy_coding_mode
int entropy_coding_mode
Definition: ni_device_api.h:2321
NI_ENC_PARAM_INTRA_QP_DELTA
#define NI_ENC_PARAM_INTRA_QP_DELTA
Definition: ni_device_api.h:2171
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:11481
_ni_packet::p_data
void * p_data
Definition: ni_device_api.h:2867
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:4892
NI_ENC_PARAM_VBV_MAXRAE
#define NI_ENC_PARAM_VBV_MAXRAE
Definition: ni_device_api.h:2149
_ni_session_data_io
Definition: ni_device_api.h:2896
_ni_enc_quad_roi_custom_map::ipcm_flag
uint8_t ipcm_flag
Definition: ni_device_api.h:893
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:13362
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:12043
NI_MAX_CUSTOM_SEI_PASSTHRU
#define NI_MAX_CUSTOM_SEI_PASSTHRU
Definition: ni_device_api.h:316
NI_ENC_PARAM_MAX_DELTA_QP
#define NI_ENC_PARAM_MAX_DELTA_QP
Definition: ni_device_api.h:2100
_ni_decoder_input_params_t::svct_decoding_layer
int svct_decoding_layer
Definition: ni_device_api.h:2543
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1894
_ni_encoder_cfg_params::ltrFirstGap
int ltrFirstGap
Definition: ni_device_api.h:2301
NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
#define NI_ENC_PARAM_USE_LOW_DELAY_POC_TYPE
Definition: ni_device_api.h:2087
_ni_encoder_cfg_params::ltrRefQpOffset
int ltrRefQpOffset
Definition: ni_device_api.h:2300
_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:2181
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:2503
NI_PIX_FMT_YUV420P10LE
@ NI_PIX_FMT_YUV420P10LE
Definition: ni_device_api.h:264
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:2490
NI_ENC_GOP_PARAMS_G7_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G7_POC_OFFSET
Definition: ni_device_api.h:1945
_ni_scaler_input_params_t::in_rec_x
int32_t in_rec_x
Definition: ni_device_api.h:2572
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1952
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:17350
NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
Definition: ni_defs.h:99
_ni_encoder_cfg_params::enable_transform_8x8
int enable_transform_8x8
Definition: ni_device_api.h:2370
_ni_session_context::sender_handle
ni_device_handle_t sender_handle
Definition: ni_device_api.h:1470
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:15355
NI_ENC_PARAM_AI_ENHANCE_LEVEL
#define NI_ENC_PARAM_AI_ENHANCE_LEVEL
Definition: ni_device_api.h:2204
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:9337
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:11084
ni_rsrc_unlock
int ni_rsrc_unlock(int device_type, ni_lock_handle_t lock)
unlock a file lock
Definition: ni_rsrc_api.cpp:2747
QOS_NAMESPACE_CODE
@ QOS_NAMESPACE_CODE
Definition: ni_device_api.h:237
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:483
_ni_encoder_cfg_params::enable_smooth_crf
int enable_smooth_crf
Definition: ni_device_api.h:2450
_ni_device_info::model_load
int model_load
Definition: ni_rsrc_api.h:109
_ni_network_layer_info
Definition: ni_device_api.h:1354
_ni_session_context::keep_alive_timeout
uint32_t keep_alive_timeout
Definition: ni_device_api.h:1523
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:9957
_ni_encoder_cfg_params::totalCuTreeDepth
int totalCuTreeDepth
Definition: ni_device_api.h:2457
_ni_encoder_cfg_params::customize_roi_qp_level
int customize_roi_qp_level
Definition: ni_device_api.h:2445
_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:16750
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC2
Definition: ni_device_api.h:1850
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:4090
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:3885
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:9783
NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
#define NI_ENC_PARAM_LONG_TERM_REFERENCE_COUNT
Definition: ni_device_api.h:2173
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:4675
NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL
#define NI_MAX_UPLOAD_INSTANCE_FRAMEPOOL
Definition: ni_defs.h:298
NI_ENC_PARAM_HRD_ENABLE
#define NI_ENC_PARAM_HRD_ENABLE
Definition: ni_device_api.h:2146
_ni_encoder_cfg_params
Definition: ni_device_api.h:2067
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC3
Definition: ni_device_api.h:1927
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1864
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC0
Definition: ni_device_api.h:1861
NI_DEC_PARAM_ENABLE_ADVANCED_EC
#define NI_DEC_PARAM_ENABLE_ADVANCED_EC
Definition: ni_device_api.h:2506
NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
#define NI_ENC_PARAM_DISABLE_BFRAME_RDOQ
Definition: ni_device_api.h:2229
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC1
Definition: ni_device_api.h:1938
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1866
_ni_encoder_cfg_params::EnableAUD
int EnableAUD
Definition: ni_device_api.h:2315
NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G7_TEMPORAL_ID
Definition: ni_device_api.h:1948
_ni_encoder_cfg_params::spatial_layers
int spatial_layers
Definition: ni_device_api.h:2452
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:11259
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:11487
_ni_encoder_cfg_params::scene_change_detect_level
int scene_change_detect_level
Definition: ni_device_api.h:2448
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:17468
NI_ENC_PARAM_PADDING
#define NI_ENC_PARAM_PADDING
Definition: ni_device_api.h:2076
_ni_session_context::device_type
uint32_t device_type
Definition: ni_device_api.h:1486
NI_RETCODE_ERROR_PERMISSION_DENIED
@ NI_RETCODE_ERROR_PERMISSION_DENIED
Definition: ni_defs.h:535
niFrameSurface1_t
struct _niFrameSurface1 niFrameSurface1_t
NI_AI_HW_ALIGN_SIZE
#define NI_AI_HW_ALIGN_SIZE
Definition: ni_device_api_priv.h:1254
NI_ENC_PARAM_CPLX_DECAY
#define NI_ENC_PARAM_CPLX_DECAY
Definition: ni_device_api.h:2218
_ni_frame::force_key_frame
int force_key_frame
Definition: ni_device_api.h:2650
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:2880
LRETURN
#define LRETURN
Definition: ni_defs.h:335
NI_VPU_ALIGN32
#define NI_VPU_ALIGN32(_x)
Definition: ni_device_api.h:334
NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
Definition: ni_device_api.h:922
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1847
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:3937
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:1926
_ni_encoder_cfg_params::HDR10CLLEnable
int HDR10CLLEnable
Definition: ni_device_api.h:2286
NI_ENC_PARAM_HORIZONTAL_OFFSET
#define NI_ENC_PARAM_HORIZONTAL_OFFSET
Definition: ni_device_api.h:2208
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0
Definition: ni_device_api.h:1906
NI_RETCODE_PARAM_WARNING_DEPRECATED
@ NI_RETCODE_PARAM_WARNING_DEPRECATED
Definition: ni_defs.h:528
_ni_aux_data::data
void * data
Definition: ni_device_api.h:623
_ni_frame::dec_buf
ni_buf_t * dec_buf
Definition: ni_device_api.h:2696
_ni_xcoder_params::chroma_linesize
int chroma_linesize
Definition: ni_device_api.h:2815
_ni_xcoder_params::minFramesDelay
int minFramesDelay
Definition: ni_device_api.h:2818
_ni_xcoder_params::sar_num
int sar_num
Definition: ni_device_api.h:2789
NI_VPU_ALIGN128
#define NI_VPU_ALIGN128(_x)
Definition: ni_device_api.h:336
XCODER_TEST_RECONF_RC_MIN_MAX_QP
@ XCODER_TEST_RECONF_RC_MIN_MAX_QP
Definition: ni_device_api.h:1754
NI_ENC_PARAM_CU_TREE_FACTOR
#define NI_ENC_PARAM_CU_TREE_FACTOR
Definition: ni_device_api.h:2214
NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
#define NI_ENC_PARAM_VIDEO_FULL_RANGE_FLAG
Definition: ni_device_api.h:2191
_ni_packet
Definition: ni_device_api.h:2855
_ni_buf_pool_t
Definition: ni_device_api.h:1284
NI_DEC_PARAM_SCALE_2_ROUND
#define NI_DEC_PARAM_SCALE_2_ROUND
Definition: ni_device_api.h:2494
_ni_device_temp
Definition: ni_rsrc_api.h:235
NI_DATA_BUFFER_LEN
#define NI_DATA_BUFFER_LEN
Definition: ni_nvme.h:623
NI_ENC_PARAM_MOTION_CONSTRAINED_MODE
#define NI_ENC_PARAM_MOTION_CONSTRAINED_MODE
Definition: ni_device_api.h:2237
_ni_session_context::frame_num
uint64_t frame_num
Definition: ni_device_api.h:1533
_ni_encoder_cfg_params::HDR10Enable
int HDR10Enable
Definition: ni_device_api.h:2287
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:858
_ni_encoder_cfg_params::keep_alive_timeout
int keep_alive_timeout
Definition: ni_device_api.h:2400
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:11371
_ni_encoder_cfg_params::intra_qp_delta
int intra_qp_delta
Definition: ni_device_api.h:2383
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3_USED
Definition: ni_device_api.h:1958
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:13604
_ni_xcoder_params::ai_enhance_level
int ai_enhance_level
Definition: ni_device_api.h:2816
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC1
Definition: ni_device_api.h:1893
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:1944
_ni_session_context::roi_map
ni_enc_quad_roi_custom_map * roi_map
Definition: ni_device_api.h:1584
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:1524
_ni_network_layer_offset::offset
int32_t offset
Definition: ni_device_api.h:1362
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1941
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:2909
NI_VPU_ALIGN8
#define NI_VPU_ALIGN8(_x)
Definition: ni_device_api.h:332
_ni_encoder_cfg_params::colorDescPresent
int colorDescPresent
Definition: ni_device_api.h:2325
NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_2_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2488
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1881
NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PICS
Definition: ni_device_api.h:1890
NI_RETCODE_PARAM_ERROR_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_TOO_BIG
Definition: ni_defs.h:501
NI_ENC_PARAM_RECONF_FILE
#define NI_ENC_PARAM_RECONF_FILE
Definition: ni_device_api.h:2071
_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:11171
_ni_session_context::last_gop_size
int last_gop_size
Definition: ni_device_api.h:1693
_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:2343
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:18607
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2689
NI_ENC_GOP_PARAMS_G7_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G7_QP_OFFSET
Definition: ni_device_api.h:1946
_ni_encoder_cfg_params::custom_gop_params
ni_custom_gop_params_t custom_gop_params
Definition: ni_device_api.h:2269
NI_VPU_CEIL
#define NI_VPU_CEIL(_data, _align)
Definition: ni_device_api.h:330
_ni_encoder_cfg_params::HDR10dx0
int HDR10dx0
Definition: ni_device_api.h:2288
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:326
_ni_xcoder_params::zerocopy_mode
int zerocopy_mode
Definition: ni_device_api.h:2813
_ni_xcoder_params::sar_denom
int sar_denom
Definition: ni_device_api.h:2790
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:8602
_ni_decoder_input_params_t::max_extra_hwframe_cnt
int max_extra_hwframe_cnt
Definition: ni_device_api.h:2548
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:8965
_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:2440
ni_strcasecmp
int ni_strcasecmp(const char *a, const char *b)
Definition: ni_device_api.c:12699
NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G0_NUM_REF_PIC0
Definition: ni_device_api.h:1846
XCODER_TEST_RECONF_VBV_API
@ XCODER_TEST_RECONF_VBV_API
Definition: ni_device_api.h:1779
XCODER_TEST_FORCE_IDR_FRAME
@ XCODER_TEST_FORCE_IDR_FRAME
Definition: ni_device_api.h:1766
NI_DEVICE_TYPE_SCALER
@ NI_DEVICE_TYPE_SCALER
Definition: ni_defs.h:360
_ni_scaler_input_params_t::in_rec_y
int32_t in_rec_y
Definition: ni_device_api.h:2573
_ni_encoder_cfg_params::tolCtbRcIntra
float tolCtbRcIntra
Definition: ni_device_api.h:2344
NI_XCODER_WRITE_STATE
@ NI_XCODER_WRITE_STATE
Definition: ni_device_api.h:247
NI_XCODER_LOG_NAMES_ARRAY_LEN
#define NI_XCODER_LOG_NAMES_ARRAY_LEN
Definition: ni_device_api.h:2907
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:4557
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:2435
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:3796
_ni_decoder_input_params_t::enable_all_sei_passthru
bool enable_all_sei_passthru
Definition: ni_device_api.h:2551
NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
#define NI_ENC_PARAM_STATISTIC_OUTPUT_LEVEL
Definition: ni_device_api.h:2224
NI_ERRNO
#define NI_ERRNO
Definition: ni_defs.h:229
_ni_encoder_cfg_params::disable_adaptive_buffers
bool disable_adaptive_buffers
Definition: ni_device_api.h:2439
NI_ENC_PARAM_SKIP_FRAME_INTERVAL
#define NI_ENC_PARAM_SKIP_FRAME_INTERVAL
Definition: ni_device_api.h:2177
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
Definition: ni_defs.h:506
NI_DEC_PARAM_EC_POLICY
#define NI_DEC_PARAM_EC_POLICY
Definition: ni_device_api.h:2505
NI_DEC_PARAM_ERROR_THRESHOLD
#define NI_DEC_PARAM_ERROR_THRESHOLD
Definition: ni_device_api.h:2507
_ni_session_context::vui
ni_vui_hrd_t vui
Definition: ni_device_api.h:1607
_ni_encoder_cfg_params::enable_dynamic_16x16_merge
int enable_dynamic_16x16_merge
Definition: ni_device_api.h:2365
NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
#define NI_ENC_PARAM_COLOR_TRANSFER_CHARACTERISTIC
Definition: ni_device_api.h:2185
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:12887
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:1611
NI_ENC_PARAM_LOG
#define NI_ENC_PARAM_LOG
Definition: ni_device_api.h:2082
NI_ENC_PARAM_SKIP_FRAME_ENABLE
#define NI_ENC_PARAM_SKIP_FRAME_ENABLE
Definition: ni_device_api.h:2175
_ni_session_context
Definition: ni_device_api.h:1410
_ni_rc_min_max_qp::minQpPB
int32_t minQpPB
Definition: ni_device_api.h:711
_ni_encoder_cfg_params::iframe_size_ratio
int iframe_size_ratio
Definition: ni_device_api.h:2436
_ni_scaler_input_params_t::out_rec_x
int32_t out_rec_x
Definition: ni_device_api.h:2580
_ni_scaler_input_params_t::input_width
int32_t input_width
Definition: ni_device_api.h:2568
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:266
ni_memfree
#define ni_memfree(p_memptr)
Definition: ni_util.h:408
_ni_session_context::bus
unsigned short bus
Definition: ni_device_api.h:1622
NI_ENC_PARAM_FORCED_HEADER_ENABLE
#define NI_ENC_PARAM_FORCED_HEADER_ENABLE
Definition: ni_device_api.h:2101
NI_ENC_PARAM_BITRATE_WINDOW
#define NI_ENC_PARAM_BITRATE_WINDOW
Definition: ni_device_api.h:2165
_ni_thread_arg_struct_t::hw_id
int hw_id
Definition: ni_device_api.h:1261
NI_ENC_PARAM_ENABLE_VFR
#define NI_ENC_PARAM_ENABLE_VFR
Definition: ni_device_api.h:2193
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:2823
NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
#define NI_ENC_PARAM_ENABLE_DYNAMIC_8X8_MERGE
Definition: ni_device_api.h:2090
NI_EC_ERR_THRESHOLD_DEFAULT
#define NI_EC_ERR_THRESHOLD_DEFAULT
Definition: ni_device_api.h:327
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:8484
NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_NUM_DATA_POINTERS
Definition: ni_defs.h:244
ni_device_session_restart
ni_retcode_t ni_device_session_restart(ni_session_context_t *p_ctx, int video_width, int video_height, ni_device_type_t device_type)
Send a restart command after flush command Only support Encoder now.
Definition: ni_device_api.c:13009
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC3
Definition: ni_device_api.h:1957
NI_XCODER_GENERAL_STATE
@ NI_XCODER_GENERAL_STATE
Definition: ni_device_api.h:258
NI_ENC_PARAM_INTRA_REFRESH_RESET
#define NI_ENC_PARAM_INTRA_REFRESH_RESET
Definition: ni_device_api.h:2113
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:554
_ni_encoder_cfg_params::adaptiveCuTree
int adaptiveCuTree
Definition: ni_device_api.h:2458
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:1492
_ni_frame
Definition: ni_device_api.h:2627
NI_ENC_GOP_PARAMS_G0_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G0_QP_OFFSET
Definition: ni_device_api.h:1841
NI_ENC_PARAM_PAST_FRAME_MAX_INTRA_RATIO
#define NI_ENC_PARAM_PAST_FRAME_MAX_INTRA_RATIO
Definition: ni_device_api.h:2248
_ni_network_data::input_num
uint32_t input_num
Definition: ni_device_api.h:1367
_ni_encoder_cfg_params::HDR10dy1
int HDR10dy1
Definition: ni_device_api.h:2291
NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
#define NI_ENC_PARAM_SCENE_CHANG_DETECT_LEVEL
Definition: ni_device_api.h:2180
NI_PIX_FMT_YUYV422
@ NI_PIX_FMT_YUYV422
Definition: ni_device_api.h:274
NI_PIX_FMT_RGBA
@ NI_PIX_FMT_RGBA
Definition: ni_device_api.h:267
_ni_encoder_change_params_t::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:1006
_ni_encoder_cfg_params::conf_win_bottom
int conf_win_bottom
Definition: ni_device_api.h:2312
_ni_decoder_input_params_t::scale_round
int scale_round[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2556
NI_ENC_PARAM_IFRAME_SIZE_RATIO
#define NI_ENC_PARAM_IFRAME_SIZE_RATIO
Definition: ni_device_api.h:2178
NI_DEPRECATED
#define NI_DEPRECATED
Definition: ni_defs.h:80
ni_device_session_open
ni_retcode_t ni_device_session_open(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Open a new device session depending on the device_type parameter If device_type is NI_DEVICE_TYPE_DEC...
Definition: ni_device_api.c:710
_ni_session_context::roi_len
uint32_t roi_len
Definition: ni_device_api.h:1498
_ni_encoder_cfg_params::linkFrameMaxIntraRatio
int linkFrameMaxIntraRatio
Definition: ni_device_api.h:2462
NI_DDR_PRIORITY_NONE
@ NI_DDR_PRIORITY_NONE
Definition: ni_device_api.h:1831
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:2262
_ni_resolution::width
int32_t width
Definition: ni_device_api_priv.h:680
XCODER_TEST_RECONF_VUI_HRD_API
@ XCODER_TEST_RECONF_VUI_HRD_API
Definition: ni_device_api.h:1769
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:2328
_ni_session_context::max_frame_delay
int max_frame_delay
Definition: ni_device_api.h:1696
_ni_gop_params::rps
ni_gop_rps_t rps[NI_MAX_REF_PIC]
Definition: ni_device_api.h:1974
CONFIG_INSTANCE_SetScalerDrawBoxPara_W
#define CONFIG_INSTANCE_SetScalerDrawBoxPara_W(sid, instance)
Definition: ni_nvme.h:822
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:2762
NI_DEC_CROP_MODE_MANUAL
@ NI_DEC_CROP_MODE_MANUAL
Definition: ni_device_api.h:932
XCODER_TEST_RECONF_LONG_TERM_REF
@ XCODER_TEST_RECONF_LONG_TERM_REF
Definition: ni_device_api.h:1752
NI_ENC_PARAM_GOP_PRESET_IDX
#define NI_ENC_PARAM_GOP_PRESET_IDX
Definition: ni_device_api.h:2083
NI_ENC_PARAM_ENTROPY_CODING_MODE
#define NI_ENC_PARAM_ENTROPY_CODING_MODE
Definition: ni_device_api.h:2116
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:340
_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:2345
NI_RETCODE_ERROR_INVALID_SESSION
@ NI_RETCODE_ERROR_INVALID_SESSION
Definition: ni_defs.h:445
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC3
Definition: ni_device_api.h:1897
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:13801
NI_PIX_FMT_ABGR
@ NI_PIX_FMT_ABGR
Definition: ni_device_api.h:270
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:8100
_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:1219
QUERY_GET_NS_VF_R
#define QUERY_GET_NS_VF_R
Definition: ni_nvme.h:794
NI_PIX_FMT_ARGB
@ NI_PIX_FMT_ARGB
Definition: ni_device_api.h:269
NI_ENC_PARAM_CONSTANT_RATE_FACTOR
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR
Definition: ni_device_api.h:2134
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:10264
_ni_xcoder_params
Definition: ni_device_api.h:2743
NI_ENC_PARAM_MULTICORE_JOINT_MODE
#define NI_ENC_PARAM_MULTICORE_JOINT_MODE
Definition: ni_device_api.h:2160
NI_DEC_PARAM_CROP_PARAM_2
#define NI_DEC_PARAM_CROP_PARAM_2
Definition: ni_device_api.h:2482
_ni_session_context::p_hdr_buf
uint8_t * p_hdr_buf
Definition: ni_device_api.h:1513
NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
Definition: ni_defs.h:508
NI_ENC_PARAM_PREFERRED_TRANSFER_CHARACTERISTICS
#define NI_ENC_PARAM_PREFERRED_TRANSFER_CHARACTERISTICS
Definition: ni_device_api.h:2125
NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
#define NI_ENC_PARAM_CONSTANT_RATE_FACTOR_MAX
Definition: ni_device_api.h:2210
NI_XCODER_READ_DESC_STATE
@ NI_XCODER_READ_DESC_STATE
Definition: ni_device_api.h:254
_ni_decoder_input_params_t::reduce_dpb_delay
int reduce_dpb_delay
Definition: ni_device_api.h:2561
_ni_encoder_cfg_params::max_delta_qp
int max_delta_qp
Definition: ni_device_api.h:2396
_ni_xcoder_params::staticMmapThreshold
int staticMmapThreshold
Definition: ni_device_api.h:2810
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:2404
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1956
NI_ENC_PARAM_COLOR_SPACE
#define NI_ENC_PARAM_COLOR_SPACE
Definition: ni_device_api.h:2186
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC2
Definition: ni_device_api.h:1880
_ni_session_context::low_delay_sync_cond
ni_pthread_cond_t low_delay_sync_cond
Definition: ni_device_api.h:1668
NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
#define NI_ENC_PARAM_STILL_IMAGE_DETECT_LEVEL
Definition: ni_device_api.h:2179
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC1
Definition: ni_device_api.h:1923
_ni_encoder_cfg_params::motionConstrainedMode
int motionConstrainedMode
Definition: ni_device_api.h:2446
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:13696
NI_ENC_GOP_PARAMS_G4_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G4_POC_OFFSET
Definition: ni_device_api.h:1900
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO_API
Definition: ni_device_api.h:1780
_ni_session_context::ready_to_close
uint32_t ready_to_close
Definition: ni_device_api.h:1546
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC2_USED
Definition: ni_device_api.h:1896
_ni_session_context::thread_event_handle
ni_event_handle_t thread_event_handle
Definition: ni_device_api.h:1577
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:2374
NI_XCODER_LOG_NAME_ERROR
#define NI_XCODER_LOG_NAME_ERROR
Definition: ni_device_api.h:2913
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:3112
_ni_load_query::fw_load
uint32_t fw_load
Definition: ni_device_api.h:1202
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:18220
_ni_encoder_cfg_params::crop_width
int crop_width
Definition: ni_device_api.h:2409
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:1259
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:2474
_ni_encoder_cfg_params::slice_mode
int slice_mode
Definition: ni_device_api.h:2371
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:10556
NI_ENC_PARAM_FRAME_RATE_DENOM
#define NI_ENC_PARAM_FRAME_RATE_DENOM
Definition: ni_device_api.h:2110
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:10033
NI_ENC_PARAM_AVCC_HVCC
#define NI_ENC_PARAM_AVCC_HVCC
Definition: ni_device_api.h:2195
_ni_resolution::height
int32_t height
Definition: ni_device_api_priv.h:683
_ni_encoder_cfg_params::HDR10minluma
int HDR10minluma
Definition: ni_device_api.h:2297
NI_DEC_PARAM_SURVIVE_STREAM_ERR
#define NI_DEC_PARAM_SURVIVE_STREAM_ERR
Definition: ni_device_api.h:2516
NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G3_NUM_REF_PIC0
Definition: ni_device_api.h:1891
NI_ENC_PARAM_QCOMP
#define NI_ENC_PARAM_QCOMP
Definition: ni_device_api.h:2211
NI_MAX_PPU_PARAM_EXPR_CHAR
#define NI_MAX_PPU_PARAM_EXPR_CHAR
Definition: ni_defs.h:259
XCODER_TEST_RECONF_LTR_API
@ XCODER_TEST_RECONF_LTR_API
Definition: ni_device_api.h:1770
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:18133
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:15537
_ni_session_context::codec_format
uint32_t codec_format
Definition: ni_device_api.h:1488
_ni_session_context::max_frame_size
int32_t max_frame_size
Definition: ni_device_api.h:1657
_ni_device_capability
device capability type
Definition: ni_device_api.h:1155
NI_MAX_NUM_OF_DECODER_OUTPUTS
#define NI_MAX_NUM_OF_DECODER_OUTPUTS
Definition: ni_defs.h:255
_ni_rc_min_max_qp::maxQpPB
int32_t maxQpPB
Definition: ni_device_api.h:712
XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_API
Definition: ni_device_api.h:1775
NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
#define NI_ENC_PARAM_SPATIAL_LAYERS_REF_BASE_LAYER
Definition: ni_device_api.h:2241
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:534
NI_DEC_PARAM_ENABLE_USR_DATA_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:2501
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:1930
_ni_decoder_input_params_t::scale_wh
int scale_wh[NI_MAX_NUM_OF_DECODER_OUTPUTS][2]
Definition: ni_device_api.h:2532
_ni_encoder_cfg_params::colorPrimaries
int colorPrimaries
Definition: ni_device_api.h:2326
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:9032
NI_DEC_PARAM_FORCE_8BIT_0
#define NI_DEC_PARAM_FORCE_8BIT_0
Definition: ni_device_api.h:2471
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:2906
NI_DISABLE_USR_DATA_SEI_PASSTHRU
#define NI_DISABLE_USR_DATA_SEI_PASSTHRU
Definition: ni_device_api.h:317
_ni_encoder_cfg_params::forceBframeQpfactor
float forceBframeQpfactor
Definition: ni_device_api.h:2441
NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
#define NI_DEC_PARAM_MAX_EXTRA_HW_FRAME_CNT
Definition: ni_device_api.h:2510
_ni_load_query
Definition: ni_device_api.h:1198
XCODER_TEST_CRF_FLOAT_API
@ XCODER_TEST_CRF_FLOAT_API
Definition: ni_device_api.h:1778
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:9230
_ni_session_context::is_auto_dl
uint8_t is_auto_dl
Definition: ni_device_api.h:1472
XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
@ XCODER_TEST_RECONF_MAX_FRAME_SIZE_RATIO
Definition: ni_device_api.h:1764
NI_DEC_PARAM_REDUCE_DPB_DELAY
#define NI_DEC_PARAM_REDUCE_DPB_DELAY
Definition: ni_device_api.h:2517
QUERY_GET_TEMPERATURE_R
#define QUERY_GET_TEMPERATURE_R
Definition: ni_nvme.h:796
_ni_thread_arg_struct_t::session_id
uint32_t session_id
Definition: ni_device_api.h:1262
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:10142
_ni_encoder_cfg_params::crfFloat
float crfFloat
Definition: ni_device_api.h:2424
_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:2306
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:2485
_niFrameSurface1::ui16width
uint16_t ui16width
Definition: ni_device_api.h:2827
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:10785
NI_ENC_GOP_PARAMS_G3_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G3_POC_OFFSET
Definition: ni_device_api.h:1885
_ni_resolution::bit_depth_factor
int32_t bit_depth_factor
Definition: ni_device_api_priv.h:686
NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
#define NI_ENC_PARAM_FORCE_PIC_QP_DEMO_MODE
Definition: ni_device_api.h:2074
NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
#define NI_ENC_PARAM_ENABLE_8X8_TRANSFORM
Definition: ni_device_api.h:2115
_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:1267
NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PICS
Definition: ni_device_api.h:1950
_ni_session_context::keep_alive_thread
ni_pthread_t keep_alive_thread
Definition: ni_device_api.h:1558
_ni_session_context::load_query
ni_load_query_t load_query
Definition: ni_device_api.h:1502
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:2900
NI_ENC_GOP_PARAMS_G3_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G3_PIC_TYPE
Definition: ni_device_api.h:1889
NI_ENC_PARAM_CROP_WIDTH
#define NI_ENC_PARAM_CROP_WIDTH
Definition: ni_device_api.h:2206
_ni_decoder_input_params_t::enable_out2
int enable_out2
Definition: ni_device_api.h:2522
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC2
Definition: ni_device_api.h:1925
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:11664
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:2263
NI_ENC_PARAM_ENABLE_AI_HVSPLUS
#define NI_ENC_PARAM_ENABLE_AI_HVSPLUS
Definition: ni_device_api.h:2201
_ni_encoder_cfg_params::HDR10dy2
int HDR10dy2
Definition: ni_device_api.h:2293
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:2111
NI_SCALER_FLAG_P2
#define NI_SCALER_FLAG_P2
Definition: ni_device_api.h:295
NI_ENC_RC_QP_DELTA_RANGE
#define NI_ENC_RC_QP_DELTA_RANGE
Definition: ni_device_api.h:2168
_ni_thread_arg_struct_t::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1263
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1907
NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G6_TEMPORAL_ID
Definition: ni_device_api.h:1933
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:1898
NI_FRAME_AUX_DATA_LTR_INTERVAL
@ NI_FRAME_AUX_DATA_LTR_INTERVAL
Definition: ni_device_api.h:555
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:3162
NI_MAX_NUM_SW_FRAME_DATA_POINTERS
#define NI_MAX_NUM_SW_FRAME_DATA_POINTERS
Definition: ni_defs.h:246
NI_ENC_GOP_PARAMS_G2_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G2_QP_OFFSET
Definition: ni_device_api.h:1871
NI_ENC_PARAM_SAR_DENOM
#define NI_ENC_PARAM_SAR_DENOM
Definition: ni_device_api.h:2189
NI_MAX_QP_INFO
#define NI_MAX_QP_INFO
Definition: ni_device_api.h:173
_ni_encoder_cfg_params::preIntraHandling
int preIntraHandling
Definition: ni_device_api.h:2459
NI_DEC_PARAM_SAVE_PKT
#define NI_DEC_PARAM_SAVE_PKT
Definition: ni_device_api.h:2496
NI_INVALID_SVCT_DECODING_LAYER
#define NI_INVALID_SVCT_DECODING_LAYER
Definition: ni_device_api.h:319
NI_ENC_PARAM_LEVEL
#define NI_ENC_PARAM_LEVEL
Definition: ni_device_api.h:2079
NI_RETCODE_PARAM_INVALID_NAME
@ NI_RETCODE_PARAM_INVALID_NAME
Definition: ni_defs.h:448
_ni_session_context::keep_alive_thread_args
ni_thread_arg_struct_t * keep_alive_thread_args
Definition: ni_device_api.h:1559
NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PICS
Definition: ni_device_api.h:1905
_ni_xcoder_params::color_space
int color_space
Definition: ni_device_api.h:2788
netint_iocmd_issue_request
Definition: ni_p2p_ioctl.h:72
_ni_encoder_cfg_params::baseLayerOnly
int baseLayerOnly
Definition: ni_device_api.h:2460
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:2704
NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PICS
Definition: ni_device_api.h:1935
_ni_session_context::reconfig_crf
int reconfig_crf
Definition: ni_device_api.h:1687
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC2
Definition: ni_device_api.h:1910
_ni_encoder_cfg_params::maxFrameSize
int maxFrameSize
Definition: ni_device_api.h:2257
_ni_encoder_cfg_params::hvs_qp_scale
int hvs_qp_scale
Definition: ni_device_api.h:2389
NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G5_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1922
_ni_encoder_cfg_params::cplxDecay
float cplxDecay
Definition: ni_device_api.h:2420
_ni_instance_mgr_general_status
Definition: ni_device_api_priv.h:79
atoi
#define atoi(p_str)
Definition: ni_device_api.c:7263
_ni_encoder_change_params_t::minQpI
int32_t minQpI
Definition: ni_device_api.h:1000
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:2562
_ni_instance_mgr_detail_status
Definition: ni_device_api.h:1232
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:850
END
#define END
Definition: ni_defs.h:336
_ni_decoder_input_params_t::enable_follow_iframe
int enable_follow_iframe
Definition: ni_device_api.h:2557
_ni_encoder_cfg_params::enable_hvs_qp
int enable_hvs_qp
Definition: ni_device_api.h:2388
_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:2637
NI_DEC_PARAM_SCALE_1_ROUND
#define NI_DEC_PARAM_SCALE_1_ROUND
Definition: ni_device_api.h:2493
_ni_decoder_input_params_t::pkt_pts_unchange
int pkt_pts_unchange
Definition: ni_device_api.h:2550
_ni_network_data::inset
ni_network_layer_offset_t * inset
Definition: ni_device_api.h:1371
_ni_packet::p_buffer
void * p_buffer
Definition: ni_device_api.h:2871
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:3808
NI_ENC_PARAM_VERTICAL_OFFSET
#define NI_ENC_PARAM_VERTICAL_OFFSET
Definition: ni_device_api.h:2209
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:10339
NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
#define NI_ENC_PARAM_GET_RECONSTRUCTED_MODE
Definition: ni_device_api.h:2242
_ni_decoder_input_params_t::force_8_bit
int force_8_bit[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2525
NI_ENC_PARAM_SLICE_ARG
#define NI_ENC_PARAM_SLICE_ARG
Definition: ni_device_api.h:2119
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:670
_ni_encoder_cfg_params::qcomp
float qcomp
Definition: ni_device_api.h:2414
_ni_session_context::low_delay_sync_flag
int low_delay_sync_flag
Definition: ni_device_api.h:1666
NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
#define NI_CUSTOMIZE_ROI_QPOFFSET_LEVEL
Max number of lines supported for qpoffset level.
Definition: ni_device_api.h:481
_ni_encoder_cfg_params::avcc_hvcc
int avcc_hvcc
Definition: ni_device_api.h:2454
_ni_decoder_input_params_t::custom_sei_passthru
int custom_sei_passthru
Definition: ni_device_api.h:2542
_ni_xcoder_params::ddr_priority_mode
ni_ddr_priority_mode_t ddr_priority_mode
Definition: ni_device_api.h:2817
_ni_encoder_cfg_params::colorTrc
int colorTrc
Definition: ni_device_api.h:2327
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:3751
_ni_session_context::active_video_height
uint32_t active_video_height
Definition: ni_device_api.h:1553
NI_ENC_PARAM_INTRA_PERIOD
#define NI_ENC_PARAM_INTRA_PERIOD
Definition: ni_device_api.h:2107
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:8381
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:12962
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:18537
NI_FRAME_AUX_DATA_LONG_TERM_REF
@ NI_FRAME_AUX_DATA_LONG_TERM_REF
Definition: ni_device_api.h:550
NI_ENC_PARAM_VBV_BUFFER_SIZE
#define NI_ENC_PARAM_VBV_BUFFER_SIZE
Definition: ni_device_api.h:2148
NI_MAX_SEI_DATA
#define NI_MAX_SEI_DATA
Definition: ni_device_api.h:428
_ni_session_context::pkt_delay_cnt
uint32_t pkt_delay_cnt
Definition: ni_device_api.h:1704
_ni_encoder_cfg_params::av1_error_resilient_mode
int av1_error_resilient_mode
Definition: ni_device_api.h:2402
_ni_encoder_cfg_params::tune_bframe_visual
int tune_bframe_visual
Definition: ni_device_api.h:2442
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:13148
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:12845
_ni_encoder_cfg_params::conf_win_left
int conf_win_left
Definition: ni_device_api.h:2313
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:2423
_ni_encoder_cfg_params::conf_win_right
int conf_win_right
Definition: ni_device_api.h:2314
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:860
_ni_session_context::blk_dev_name
char blk_dev_name[NI_MAX_DEVICE_NAME_LEN]
Definition: ni_device_api.h:1661
_ni_decoder_input_params_t::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:2540
NI_POOL_TYPE_NONE
@ NI_POOL_TYPE_NONE
Definition: ni_device_api.h:493
NI_ENC_PARAM_RC_INIT_DELAY
#define NI_ENC_PARAM_RC_INIT_DELAY
Definition: ni_device_api.h:2128
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1549
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:689
_ni_session_context::enable_low_delay_check
int enable_low_delay_check
Definition: ni_device_api.h:1597
NI_ENC_PARAM_HVS_QP_SCALE
#define NI_ENC_PARAM_HVS_QP_SCALE
Definition: ni_device_api.h:2097
NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
#define NI_DEC_PARAM_ENABLE_ALL_SEI_PASSTHRU
Definition: ni_device_api.h:2513
_niFrameSurface1::device_handle
int32_t device_handle
Definition: ni_device_api.h:2830
_ni_encoder_cfg_params::crfMax
int crfMax
Definition: ni_device_api.h:2413
_niFrameSurface1::bit_depth
int8_t bit_depth
Definition: ni_device_api.h:2831
NI_ENC_PARAM_DECODING_REFRESH_TYPE
#define NI_ENC_PARAM_DECODING_REFRESH_TYPE
Definition: ni_device_api.h:2112
NI_ENC_GOP_PARAMS_G1_PIC_TYPE
#define NI_ENC_GOP_PARAMS_G1_PIC_TYPE
Definition: ni_device_api.h:1859
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:2417
_ni_network_layer_info::out_param
ni_network_layer_params_t * out_param
Definition: ni_device_api.h:1357
XCODER_TEST_INVALID_REF_FRAME_API
@ XCODER_TEST_INVALID_REF_FRAME_API
Definition: ni_device_api.h:1773
_ni_encoder_cfg_params::enableipRatio
int enableipRatio
Definition: ni_device_api.h:2434
_ni_enc_quad_roi_custom_map
encoder AVC ROI custom map (1 MB = 8bits)
Definition: ni_device_api.h:885
_ni_decoder_input_params_t::scale_resolution_ceil
int scale_resolution_ceil[NI_MAX_NUM_OF_DECODER_OUTPUTS]
Definition: ni_device_api.h:2555
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:1163
NI_ENC_PARAM_LOW_DELAY
#define NI_ENC_PARAM_LOW_DELAY
Definition: ni_device_api.h:2084
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC0
Definition: ni_device_api.h:1951
NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
#define NI_ENC_PARAM_ENABLE_ACQUIRE_LIMIT
Definition: ni_device_api.h:2232
_ni_session_context::meta_size
uint32_t meta_size
Params used in VFR mode Done///.
Definition: ni_device_api.h:1640
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:8572
_ni_encoder_cfg_params::vbv_min_rate
int vbv_min_rate
Definition: ni_device_api.h:2438
NI_ENC_PARAM_PPS_INIT_QP
#define NI_ENC_PARAM_PPS_INIT_QP
Definition: ni_device_api.h:2219
_ni_encoder_cfg_params::HDR10MaxLight
int HDR10MaxLight
Definition: ni_device_api.h:2284
_ni_xcoder_params::cacheRoi
int cacheRoi
Definition: ni_device_api.h:2777
_ni_session_context::session_timestamp
uint64_t session_timestamp
Definition: ni_device_api.h:1484
_ni_encoder_cfg_params::still_image_detect_level
int still_image_detect_level
Definition: ni_device_api.h:2447
_ni_encoder_change_params_t::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:1001
_ni_encoder_cfg_params::crop_height
int crop_height
Definition: ni_device_api.h:2410
NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
#define NI_ENC_GOP_PARAMS_G6_NUM_REF_PIC0_USED
Definition: ni_device_api.h:1937
_ni_session_context::max_nvme_io_size
uint32_t max_nvme_io_size
Definition: ni_device_api.h:1478
_ni_encoder_cfg_params::aspectRatioHeight
int aspectRatioHeight
Definition: ni_device_api.h:2255
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:440
NI_ENC_PARAM_GEN_HDRS
#define NI_ENC_PARAM_GEN_HDRS
Definition: ni_device_api.h:2075
_ni_encoder_cfg_params::HDR10dx1
int HDR10dx1
Definition: ni_device_api.h:2290
NI_ENC_PARAM_PSNR_INTERVAL
#define NI_ENC_PARAM_PSNR_INTERVAL
Definition: ni_device_api.h:2234
XCODER_TEST_RECONF_BR
@ XCODER_TEST_RECONF_BR
Definition: ni_device_api.h:1749
_ni_aux_data::type
ni_aux_data_type_t type
Definition: ni_device_api.h:622
NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
#define NI_ENC_GOP_PARAMS_G4_TEMPORAL_ID
Definition: ni_device_api.h:1903
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:17699
NI_ENC_PARAM_ROI_ENABLE
#define NI_ENC_PARAM_ROI_ENABLE
Definition: ni_device_api.h:2102
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:2098
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:2835
_ni_encoder_cfg_params::planar
int planar
Definition: ni_device_api.h:2256
NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G4_NUM_REF_PIC1
Definition: ni_device_api.h:1908
_ni_buf_t::buf
void * buf
Definition: ni_device_api.h:1276
_ni_session_context::reconfigCount
int reconfigCount
Definition: ni_device_api.h:1700
NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PICS
Definition: ni_device_api.h:1875
_ni_packet::buffer_size
uint32_t buffer_size
Definition: ni_device_api.h:2872
_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:512
_ni_vui_hrd::videoFullRange
int32_t videoFullRange
Definition: ni_device_api.h:681
NI_ENC_PARAM_VBV_MINRATE
#define NI_ENC_PARAM_VBV_MINRATE
Definition: ni_device_api.h:2227
_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:677
_ni_session_context::hdr_buf_size
uint8_t hdr_buf_size
Definition: ni_device_api.h:1514
_ni_instance_mgr_detail_status_v1
Definition: ni_device_api.h:1254
_ni_xcoder_params::enable_vfr
int enable_vfr
Definition: ni_device_api.h:2808
_ni_frame::inconsecutive_transfer
uint8_t inconsecutive_transfer
Definition: ni_device_api.h:2734
_ni_session_context::last_framerate
ni_framerate_t last_framerate
Definition: ni_device_api.h:1677
NI_ENC_PARAM_FRAME_RATE
#define NI_ENC_PARAM_FRAME_RATE
Definition: ni_device_api.h:2109
_ni_session_context::ltr_frame_ref_invalid
int32_t ltr_frame_ref_invalid
Definition: ni_device_api.h:1605
NI_SCALER_FLAG_PC
#define NI_SCALER_FLAG_PC
Definition: ni_device_api.h:293
_ni_encoder_cfg_params::rdoLevel
int rdoLevel
Definition: ni_device_api.h:2282
_ni_encoder_cfg_params::long_term_ref_enable
int long_term_ref_enable
Definition: ni_device_api.h:2273
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:502
_ni_encoder_cfg_params::get_psnr_mode
int get_psnr_mode
Definition: ni_device_api.h:2444
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:1697
_ni_encoder_cfg_params::ltrNextInterval
int ltrNextInterval
Definition: ni_device_api.h:2302
_ni_decoder_input_params_t::survive_stream_err
int survive_stream_err
Definition: ni_device_api.h:2560
NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PIC2
Definition: ni_device_api.h:1865
NI_ENC_PARAM_LOG_LEVEL
#define NI_ENC_PARAM_LOG_LEVEL
Definition: ni_device_api.h:2081
COMPARE
#define COMPARE(STR1, STR2, STR3)
NI_ENC_PARAM_GOP_SIZE
#define NI_ENC_PARAM_GOP_SIZE
Definition: ni_device_api.h:2143
_ni_encoder_cfg_params::videoFullRange
int videoFullRange
Definition: ni_device_api.h:2304
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:8295
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:8128
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:15979
_ni_encoder_cfg_params::intra_reset_refresh
int intra_reset_refresh
Definition: ni_device_api.h:2403
NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
#define NI_ENC_PARAM_FORCE_BFRAME_QPFACTOR
Definition: ni_device_api.h:2230
_ni_scaler_input_params_t::in_rec_height
int32_t in_rec_height
Definition: ni_device_api.h:2571
NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_ENC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2228
_ni_encoder_cfg_params::slice_arg
int slice_arg
Definition: ni_device_api.h:2372
NI_ENC_PARAM_ENABLE_TIMECODE
#define NI_ENC_PARAM_ENABLE_TIMECODE
Definition: ni_device_api.h:2240
_ni_frame::p_metadata_buffer
uint8_t * p_metadata_buffer
Definition: ni_device_api.h:2721
TOTAL_CPU_LOG_BUFFER_SIZE
#define TOTAL_CPU_LOG_BUFFER_SIZE
Definition: ni_defs.h:372
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:2202
_ni_rc_min_max_qp::maxQpI
int32_t maxQpI
Definition: ni_device_api.h:709
lower_pixel_rate
int lower_pixel_rate(const ni_load_query_t *pQuery, uint32_t ui32CurrentLowest)
Definition: ni_device_api_priv.c:18679
NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
#define NI_ENC_GOP_PARAMS_G7_NUM_REF_PIC1
Definition: ni_device_api.h:1953
NI_ENC_CTB_ROW_QP_STEP
#define NI_ENC_CTB_ROW_QP_STEP
Definition: ni_device_api.h:2169
_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:2281
NI_RETCODE_ERROR_INVALID_HANDLE
@ NI_RETCODE_ERROR_INVALID_HANDLE
Definition: ni_defs.h:523
NI_XCODER_LOG_NAME_DEBUG
#define NI_XCODER_LOG_NAME_DEBUG
Definition: ni_device_api.h:2916
NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
#define NI_ENC_PARAM_ENABLE_MB_LEVEL_RC
Definition: ni_device_api.h:2124
NI_FRAME_AUX_DATA_CRF_FLOAT
@ NI_FRAME_AUX_DATA_CRF_FLOAT
Definition: ni_device_api.h:580
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:1591
_ni_custom_gop_params::pic_param
ni_gop_params_t pic_param[NI_MAX_GOP_NUM]
Definition: ni_device_api.h:2060
NI_ENC_PARAM_ENABLE_PIC_SKIP
#define NI_ENC_PARAM_ENABLE_PIC_SKIP
Definition: ni_device_api.h:2151
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:4583
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:1623
_ni_decoder_input_params_t::decoder_low_delay
int decoder_low_delay
Definition: ni_device_api.h:2538
_ni_xcoder_params::low_delay_mode
int low_delay_mode
Definition: ni_device_api.h:2763
_ni_decoder_input_params_t::nb_save_pkt
int nb_save_pkt
Definition: ni_device_api.h:2524
_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:11012
NI_ENC_PARAM_ENABLE_COMPENSATE_QP
#define NI_ENC_PARAM_ENABLE_COMPENSATE_QP
Definition: ni_device_api.h:2182
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:504
_ni_session_context::pkt_num
uint64_t pkt_num
Definition: ni_device_api.h:1534
NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
#define NI_ENC_GOP_PARAMS_G2_NUM_REF_PIC1_USED
Definition: ni_device_api.h:1879
NI_ENC_ENABLE_SSIM
#define NI_ENC_ENABLE_SSIM
Definition: ni_device_api.h:2194
_ni_encoder_cfg_params::enable_cu_level_rate_control
int enable_cu_level_rate_control
Definition: ni_device_api.h:2387
_ni_decoder_input_params_t::disable_adaptive_buffers
int disable_adaptive_buffers
Definition: ni_device_api.h:2558
NI_CODEC_FORMAT_H264
@ NI_CODEC_FORMAT_H264
Definition: ni_device_api.h:913
_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:17893
NI_ENC_GOP_PARAMS_G6_QP_OFFSET
#define NI_ENC_GOP_PARAMS_G6_QP_OFFSET
Definition: ni_device_api.h:1931
NI_FRAME_AUX_DATA_INVALID_REF_FRAME
@ NI_FRAME_AUX_DATA_INVALID_REF_FRAME
Definition: ni_device_api.h:560
_ni_thread_arg_struct_t::plast_access_time
volatile uint64_t * plast_access_time
Definition: ni_device_api.h:1271
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:2729
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:1845
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:505
NI_ENC_GOP_PARAMS_G1_POC_OFFSET
#define NI_ENC_GOP_PARAMS_G1_POC_OFFSET
Definition: ni_device_api.h:1855
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2636
_ni_session_context::initial_frame_delay
int initial_frame_delay
Definition: ni_device_api.h:1694
_ni_input_frame
Definition: ni_device_api.h:1398
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:2759
_ni_encoder_cfg_params::HDR10wy
int HDR10wy
Definition: ni_device_api.h:2295
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:2498
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:3029
_ni_encoder_cfg_params::preferred_transfer_characteristics
int preferred_transfer_characteristics
Definition: ni_device_api.h:2279
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:8649
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1618
_ni_xcoder_params::use_low_delay_poc_type
int use_low_delay_poc_type
Definition: ni_device_api.h:2766
_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:2311
NI_ENC_PARAM_TOTAL_CUTREE_DEPTH
#define NI_ENC_PARAM_TOTAL_CUTREE_DEPTH
Definition: ni_device_api.h:2244
QUADRA
#define QUADRA
Definition: ni_defs.h:123
NI_ENC_PARAM_PASS1_QP
#define NI_ENC_PARAM_PASS1_QP
Definition: ni_device_api.h:2222
_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:1843
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:2504
MAX_CHAR_IN_DEVICE_NAME
#define MAX_CHAR_IN_DEVICE_NAME
Definition: ni_device_api.h:185
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:2236
_ni_encoder_cfg_params::bitrateMode
int bitrateMode
Definition: ni_device_api.h:2422
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:12918
NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
#define NI_DEC_PARAM_ENABLE_LOW_DELAY_CHECK
Definition: ni_device_api.h:2500
_ni_aux_data
Definition: ni_device_api.h:620
_ni_scaler_input_params_t::in_rec_width
int32_t in_rec_width
Definition: ni_device_api.h:2570
NI_PIXEL_PLANAR_FORMAT_TILED4X4
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
Definition: ni_device_api.h:924
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:62
_ni_framerate
Definition: ni_device_api.h:697
_ni_vui_hrd::aspectRatioWidth
int32_t aspectRatioWidth
Definition: ni_device_api.h:674
NI_ENC_PARAM_SLICE_MODE
#define NI_ENC_PARAM_SLICE_MODE
Definition: ni_device_api.h:2118
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:10957
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:541
NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
#define NI_ENC_REPEAT_HEADERS_ALL_I_FRAMES
Definition: ni_device_api.h:2064
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:3695
_ni_xcoder_params::dec_input_params
ni_decoder_input_params_t dec_input_params
Definition: ni_device_api.h:2796
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:239
_ni_xcoder_params::color_transfer_characteristic
int color_transfer_characteristic
Definition: ni_device_api.h:2787
_ni_custom_gop_params
Definition: ni_device_api.h:2057
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:2508
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:891
_ni_gop_params::temporal_id
int temporal_id
Definition: ni_device_api.h:1971
NI_PIXEL_PLANAR_FORMAT_PLANAR
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
Definition: ni_device_api.h:923
_ni_rc_min_max_qp::maxDeltaQp
int32_t maxDeltaQp
Definition: ni_device_api.h:710
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:5019
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:251
NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
#define NI_ENC_PARAM_ENABLE_CU_LEVEL_RATE_CONTROL
Definition: ni_device_api.h:2094
NI_DEC_PARAM_SEMI_PLANAR_2
#define NI_DEC_PARAM_SEMI_PLANAR_2
Definition: ni_device_api.h:2476
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:10114
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:3645
_ni_session_context::roi_avg_qp
uint32_t roi_avg_qp
Definition: ni_device_api.h:1499
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:1614
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:10629
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:475
_ni_session_context::force_low_delay_cnt
uint32_t force_low_delay_cnt
Definition: ni_device_api.h:1702
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:2806
NI_DMABUF_WRITE_TO_DEVICE
@ NI_DMABUF_WRITE_TO_DEVICE
Definition: ni_p2p_ioctl.h:40
NI_ENC_PARAM_HVSPLUS_LEVEL
#define NI_ENC_PARAM_HVSPLUS_LEVEL
Definition: ni_device_api.h:2205
NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
#define NI_ENC_GOP_PARAMS_G1_NUM_REF_PICS
Definition: ni_device_api.h:1860
_ni_session_context::p_master_display_meta_data
void * p_master_display_meta_data
Definition: ni_device_api.h:1434
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:1811
NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
#define NI_DEC_PARAM_DISABLE_ADAPTIVE_BUFFERS
Definition: ni_device_api.h:2515
_ni_encoder_cfg_params::forced_header_enable
int forced_header_enable
Definition: ni_device_api.h:2272
NI_DEC_PARAM_MIN_PACKETS_DELAY
#define NI_DEC_PARAM_MIN_PACKETS_DELAY
Definition: ni_device_api.h:2499
_ni_encoder_cfg_params::spatial_layers_ref_base_layer
int spatial_layers_ref_base_layer
Definition: ni_device_api.h:2455
_ni_session_context::async_mode
int async_mode
Definition: ni_device_api.h:1665
NI_FRAME_AUX_DATA_BITRATE
@ NI_FRAME_AUX_DATA_BITRATE
Definition: ni_device_api.h:537
NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
@ NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
Definition: ni_defs.h:519
NI_ENC_PARAM_ADAPTIVE_CUTREE
#define NI_ENC_PARAM_ADAPTIVE_CUTREE
Definition: ni_device_api.h:2245
IDENTIFY_DEVICE_R
#define IDENTIFY_DEVICE_R
Definition: ni_nvme.h:686
NI_DEC_PARAM_SCALE_1_LONG_SHORT_ADAPT
#define NI_DEC_PARAM_SCALE_1_LONG_SHORT_ADAPT
Definition: ni_device_api.h:2487
_ni_scaler_input_params_t::output_format
int output_format
Definition: ni_device_api.h:2575
NI_RETCODE_ERROR_OPEN_DEVICE
@ NI_RETCODE_ERROR_OPEN_DEVICE
Definition: ni_defs.h:522
NI_CODEC_FORMAT_H265
@ NI_CODEC_FORMAT_H265
Definition: ni_device_api.h:914
_ni_scaler_input_params_t::output_width
int32_t output_width
Definition: ni_device_api.h:2576
NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
#define NI_ENC_PARAM_MAX_CONSUTIVE_SKIP_FRAME_NUMBER
Definition: ni_device_api.h:2176
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:4116
_ni_session_context::last_access_time
volatile uint64_t last_access_time
Definition: ni_device_api.h:1685
_ni_packet::data_len
uint32_t data_len
Definition: ni_device_api.h:2868
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:2478