libxcoder  5.2.0
ni_generic_utils.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 generic_utils.c
24  *
25  * \brief Miscellaneous utility functions shared by Libxcoder API examples
26  ******************************************************************************/
27 
28 #if __linux__ || __APPLE__
29 #include <sys/types.h>
30 #endif
31 
32 #include "ni_generic_utils.h"
33 #include "ni_filter_utils.h"
34 #include "ni_log.h"
35 #include "ni_util.h"
36 
37 static const ni_pix_fmt_name_t g_ni_pix_fmt_name_list[] = {
38  {"yuv420p", NI_PIX_FMT_YUV420P}, /* 8-bit YUV420 planar */
39  {"yuv420p10le", NI_PIX_FMT_YUV420P10LE}, /* 10-bit YUV420 planar */
40  {"nv12", NI_PIX_FMT_NV12}, /* 8-bit YUV420 semi-planar */
41  {"p010le", NI_PIX_FMT_P010LE}, /* 10-bit YUV420 semi-planar */
42  {"rgba", NI_PIX_FMT_RGBA}, /* 32-bit RGBA packed */
43  {"bgra", NI_PIX_FMT_BGRA}, /* 32-bit BGRA packed */
44  {"argb", NI_PIX_FMT_ARGB}, /* 32-bit ARGB packed */
45  {"abgr", NI_PIX_FMT_ABGR}, /* 32-bit ABGR packed */
46  {"bgr0", NI_PIX_FMT_BGR0}, /* 32-bit RGB packed */
47  {"bgrp", NI_PIX_FMT_BGRP}, /* 24bit RGB packed */
48  {"nv16", NI_PIX_FMT_NV16}, /* 8-bit YUV422 semi-planar */
49  {"yuyv422", NI_PIX_FMT_YUYV422}, /* 8-bit YUV422 */
50  {"uyvy422", NI_PIX_FMT_UYVY422}, /* 8-bit YUV422 */
51  {"null", NI_PIX_FMT_NONE}, /* invalid format */
52 };
53 
54 static const ni_gc620_pix_fmt_t g_ni_gc620_pix_fmt_list[] = {
68 };
69 
70 void print_version(void)
71 {
73  "Release ver: %s\n"
74  "API ver: %s\n"
75  "Date: %s\n"
76  "ID: %s\n",
79 }
80 
82 {
83  return pix_fmt == NI_PIX_FMT_YUV420P || pix_fmt == NI_PIX_FMT_NV12 ||
84  pix_fmt == NI_PIX_FMT_YUV420P10LE || pix_fmt == NI_PIX_FMT_P010LE;
85 }
86 
88 {
89  int i;
90 
91  for (i = 0; i < sizeof(g_ni_pix_fmt_name_list)/sizeof(ni_pix_fmt_name_t); i++)
92  {
93  if (!strcmp(name, g_ni_pix_fmt_name_list[i].name))
94  {
95  return g_ni_pix_fmt_name_list[i].pix_fmt;
96  }
97  }
98 
99  return NI_PIX_FMT_NONE;
100 }
101 
102 const char *ni_pixel_format_name(ni_pix_fmt_t pix_fmt)
103 {
104  int i;
105 
106  for (i = 0; i < sizeof(g_ni_pix_fmt_name_list)/sizeof(ni_pix_fmt_name_t); i++)
107  {
108  if (pix_fmt == g_ni_pix_fmt_name_list[i].pix_fmt)
109  {
110  return g_ni_pix_fmt_name_list[i].name;
111  }
112  }
113 
114  return NULL;
115 }
116 
118 {
119  int i;
120 
121  for (i = 0; i < sizeof(g_ni_gc620_pix_fmt_list)/sizeof(ni_gc620_pix_fmt_t); i++)
122  {
123  if (g_ni_gc620_pix_fmt_list[i].pix_fmt_ni == pix_fmt)
124  {
125  return g_ni_gc620_pix_fmt_list[i].pix_fmt_gc620;
126  }
127  }
128 
129  return -1;
130 }
131 
133 {
134  int i;
135 
136  for (i = 0; i < sizeof(g_ni_gc620_pix_fmt_list)/sizeof(ni_gc620_pix_fmt_t); i++)
137  {
138  if (g_ni_gc620_pix_fmt_list[i].pix_fmt_gc620 == pix_fmt)
139  {
140  return g_ni_gc620_pix_fmt_list[i].pix_fmt_ni;
141  }
142  }
143 
144  return -1;
145 }
146 
148 {
149  ni_pixel_planar_format ret = -1;
150  switch (pix_fmt)
151  {
152  case NI_PIX_FMT_NV12:
153  case NI_PIX_FMT_P010LE:
155  break;
159  break;
160  case NI_PIX_FMT_YUV420P:
162  case NI_PIX_FMT_ABGR: /* 32-bit ABGR packed */
163  case NI_PIX_FMT_ARGB:
164  case NI_PIX_FMT_RGBA:
165  case NI_PIX_FMT_BGRA:
167  break;
168  default:
169  break;
170  }
171 
172  return ret;
173 }
174 
176 {
177  return (list->head == list->tail);
178 }
179 
181 {
182  return (list->head == ((list->tail + 1) % NI_MAX_BUFFERED_FRAME));
183 }
184 
186 {
187  // There are two types of pixel formats for hw uploading. One is those
188  // supported by the NI encoder such as yuv420p nv12 etc. The other is those
189  // unsupported by the NI encoder such as rgba bgr0 etc. Such formats should
190  // be restricted by the hw scaler pool size in number because they have to
191  // be converted into the formats as former.
192  if (is_ni_enc_pix_fmt(pix_fmt))
193  {
194  return frame_list_is_full(list);
195  } else
196  {
197  return frame_list_length(list) >=
200  }
201 }
202 
204 {
205  return ((list->tail - list->head + NI_MAX_BUFFERED_FRAME) %
207 }
208 
210 {
211  if (frame_list_is_full(list))
212  {
213  return -1;
214  }
215  list->tail = (list->tail + 1) % NI_MAX_BUFFERED_FRAME;
216  return 0;
217 }
218 
220 {
221  if (frame_list_is_empty(list))
222  {
223  return -1;
224  }
225  list->head = (list->head + 1) % NI_MAX_BUFFERED_FRAME;
226  return 0;
227 }
228 
229 //Applies only to hwframe where recycling HW frame to FW is needed
230 //Loop through unsent frames to set in tracking list for cleanup
232 {
233  int i;
234 
235  // store the unsent frames in the tracker to be cleared out by scan at end
236  while (!frame_list_is_empty(list))
237  {
238  ni_frame_t *p_frame = &list->frames[list->head].data.frame;
239  niFrameSurface1_t *p_surface = (niFrameSurface1_t *)p_frame->p_data[3];
240  ni_hw_frame_ref(p_surface);
241  frame_list_drain(list);
242  }
243 
244  for (i = 0; i < NI_MAX_BUFFERED_FRAME; i++)
245  {
247  }
248 }
249 
250 uint64_t get_total_file_size(FILE *fp)
251 {
252  uint64_t total_file_size;
253  fseek(fp, 0, SEEK_END);
254  total_file_size = ftell(fp);
255  fseek(fp, 0, SEEK_SET);
256  return total_file_size;
257 }
258 
259 int read_and_cache_file(ni_demo_context_t *ctx, char *filename)
260 {
261  FILE *fp;
262  uint64_t total_file_size;
263  size_t read_chunk = 4096;
264  size_t read_rc;
265  uint64_t file_size_left;
266 
267  fp = fopen(filename, "rb");
268  if (!fp)
269  {
270  ni_log(NI_LOG_ERROR, "Error: Failed to open file %s\n", filename);
271  return -1;
272  }
275  file_size_left = total_file_size;
276 
277  //try to allocate memory for input file buffer, quit if failure
278  if (total_file_size > 0 && !(ctx->file_cache = malloc(total_file_size)))
279  {
281  "Error: Failed to allocate memory of size %llu for file cache\n",
282  (unsigned long long)total_file_size);
283  fclose(fp);
284  return -1;
285  }
286 
287  ctx->curr_file_offset = 0;
288  ni_log(NI_LOG_INFO, "Reading %llu bytes into memory\n", (unsigned long long)total_file_size);
289 
290  while (file_size_left)
291  {
292  if (read_chunk > file_size_left)
293  {
294  read_chunk = file_size_left;
295  }
296  read_rc = fread(ctx->file_cache + ctx->curr_file_offset, read_chunk, 1, fp);
297  if (read_rc != 1)
298  {
299  ni_log(NI_LOG_ERROR, "Error: Failure when reading file, bytes left to read %llu\n",
300  file_size_left);
301  fclose(fp);
302  return -1;
303  } else
304  {
305  file_size_left -= read_chunk;
306  ctx->curr_file_offset += read_chunk;
307  }
308  }
309 
310  ctx->curr_file_offset = 0;
311  fclose(fp);
312  return 0;
313 }
314 
315 // reset input data buffer position to the start
317 {
318  p_ctx->curr_file_offset = 0;
319 }
320 
321 // rewind input data buffer position by a number of bytes, if possible
322 void rewind_data_buf_pos_by(ni_demo_context_t *p_ctx, uint64_t nb_bytes)
323 {
324  // curr_found_pos (current input parser offset) could be equal to nb_bytes (NAL size) when offset jumps back to 0 due to repeat option
325  if (p_ctx->curr_file_offset >= nb_bytes)
326  {
327  p_ctx->curr_file_offset -= nb_bytes;
328  } else
329  {
330  ni_log(NI_LOG_ERROR, "Error %s %d bytes!\n", __func__, nb_bytes);
331  }
332 }
333 
334 // Note we do not need to consider padding bytes from yuv/rgba file reading
335 int frame_read_buffer_size(int w, int h, ni_pix_fmt_t pix_fmt,
336  ni_sw_pix_fmt_t sw_pix_fmt)
337 {
338  int data_len = 0;
339 
340  if (sw_pix_fmt == NI_SW_PIX_FMT_YUV444P)
341  {
342  data_len = w * h * 3;
343  } else if (sw_pix_fmt == NI_SW_PIX_FMT_YUV444P10LE)
344  {
345  data_len = w * h * 6;
346  } else
347  {
348  switch (pix_fmt)
349  {
350  case NI_PIX_FMT_NV12:
351  case NI_PIX_FMT_YUV420P:
352  data_len = w * h * 3 / 2;
353  break;
354  case NI_PIX_FMT_P010LE:
356  data_len = w * h * 3;
357  break;
358  case NI_PIX_FMT_RGBA:
359  case NI_PIX_FMT_BGRA:
360  case NI_PIX_FMT_ARGB:
361  case NI_PIX_FMT_ABGR:
362  case NI_PIX_FMT_BGR0:
363  case NI_PIX_FMT_BGRP:
364  data_len = w * 4 * h;
365  break;
366  default:
367  break;
368  }
369  }
370 
371  return data_len;
372 }
373 
374 // return actual bytes read from file, in requested size
375 uint32_t read_next_chunk_from_file(ni_demo_context_t *p_ctx, FILE *fp,
376  uint8_t *p_dst, uint32_t to_read)
377 {
378  uint64_t data_left_size = p_ctx->total_file_size - p_ctx->curr_file_offset;
379 
380  ni_log(NI_LOG_DEBUG, "%s: p_dst %p len %u total size %llu current offset %llu\n",
381  __func__, p_dst, to_read, p_ctx->total_file_size, p_ctx->curr_file_offset);
382 
383  if (data_left_size == 0)
384  {
385  if (p_ctx->loops_left > 1)
386  {
387  p_ctx->loops_left--;
388  ni_log(NI_LOG_DEBUG, "input processed %d left\n", p_ctx->loops_left);
389  fseek(fp, 0, SEEK_SET); //back to beginning
391  p_ctx->curr_file_offset = 0;
392  } else
393  {
394  return 0;
395  }
396  } else if (data_left_size < to_read)
397  {
398  to_read = data_left_size;
399  }
400 
401  int read_rc = fread(p_dst, to_read, 1, fp);
402  if (read_rc != 1)
403  {
404  ni_log(NI_LOG_ERROR, "Error: Failed to read input file, %lu bytes left to read\n",
406  return -1;
407  }
408  p_ctx->curr_file_offset += to_read;
409 
410  return to_read;
411 }
412 
413 int read_yuv_from_file(ni_demo_context_t *p_ctx, FILE *pfs, void *yuv_buf, int width, int height,
414  ni_pix_fmt_t pix_fmt, ni_sw_pix_fmt_t sw_pix_fmt,
415  int *eos, ni_session_run_state_t run_state)
416 {
417  int chunk_size, frame_size;
418 
419  if (run_state == SESSION_RUN_STATE_SEQ_CHANGE_DRAINING)
420  {
421  // The first YUV frame was consumed on sequence change. Reset the file
422  // pointer until the end of encoded packet is read.
423  ni_log(NI_LOG_DEBUG, "read_yuv_from_file wait sequence change finish\n");
424  p_ctx->total_file_size = get_total_file_size(pfs);
425  p_ctx->curr_file_offset = 0;
426  return 0;
427  }
428 
429  frame_size = frame_read_buffer_size(width, height, pix_fmt, sw_pix_fmt);
430 
431  chunk_size = read_next_chunk_from_file(p_ctx, pfs, yuv_buf, frame_size);
432  if (chunk_size < 0)
433  {
434  ni_log(NI_LOG_ERROR, "Error: could not read file!");
435  return -1;
436  } else if (chunk_size == 0)
437  {
438  *eos = 1;
439  ni_log(NI_LOG_DEBUG, "%s: read chunk size 0, eos!\n", __func__);
440  return 0;
441  } else
442  {
443  *eos = 0;
444  return chunk_size;
445  }
446 }
447 
449  void *yuv_buf, int width, int height,
450  ni_sw_pix_fmt_t sw_pix_fmt, int mode,
451  ni_codec_format_t codec_format)
452 {
453  int i, factor;
454  uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS] = { NULL };
455  int dst_stride[NI_MAX_NUM_DATA_POINTERS] = { 0 };
456  int height_aligned[NI_MAX_NUM_DATA_POINTERS] = { 0 };
457 
458  if (yuv_buf == NULL)
459  {
460  // EOS
461  return 0;
462  }
463 
464  switch (sw_pix_fmt)
465  {
467  factor = 1;
468  break;
470  factor = 2;
471  break;
472  default:
473  ni_log(NI_LOG_ERROR, "Error: invalid sw pix fmt %d\n", sw_pix_fmt);
474  return -1;
475  }
476 
477  ni_get_hw_yuv420p_dim(width, height, factor, 0, dst_stride, height_aligned);
478 
479  for (i = 0; i < 2; i++)
480  {
481  ni_frame_t *frame = &p_frame[i].data.frame;
482  ni_encoder_frame_buffer_alloc(frame, width, height, dst_stride,
483  codec_format == NI_CODEC_FORMAT_H264,
485  if (frame->p_data[0] == NULL)
486  {
487  ni_log(NI_LOG_ERROR, "Error: could not allocate YUV frame buffer!\n");
488  return -1;
489  }
490  }
491 
492  p_src[0] = yuv_buf;
493  p_src[1] = p_src[0] + width * factor * height;
494  p_src[2] = p_src[1] + width * factor * height;
495 
496  ni_copy_yuv_444p_to_420p(p_frame[0].data.frame.p_data,
497  p_frame[1].data.frame.p_data,
498  p_src, width, height, factor, mode);
499 
500  return 0;
501 }
502 
503 /*!*****************************************************************************
504  * \brief Write hwdl data to files.
505  *
506  * \param
507  *
508  * \return 0 if successful, < 0 otherwise
509  ******************************************************************************/
510 int write_rawvideo_data(FILE *p_file, int input_aligned_width, int input_aligned_height,
511  int output_width, int output_height, int format, ni_frame_t *p_out_frame)
512 {
513  int i, j;
514  uint8_t *src;
515  int plane_width, plane_height, write_width, write_height, bit_depth_factor;
516 
517  if (p_file && p_out_frame)
518  {
519  switch (format)
520  {
521  case NI_PIX_FMT_YUV420P:
523  case NI_PIX_FMT_NV12:
524  case NI_PIX_FMT_P010LE:
525  {
526  for (i = 0; i < 3; i++)
527  {
528  src = p_out_frame->p_data[i];
529 
530  plane_width = input_aligned_width;
531  plane_height = input_aligned_height;
532  write_width = output_width;
533  write_height = output_height;
534 
535  // support for 8/10 bit depth
536  bit_depth_factor = 1;
537  if (format == NI_PIX_FMT_YUV420P10LE || format == NI_PIX_FMT_P010LE) {
538  bit_depth_factor = 2;
539  }
540  write_width *= bit_depth_factor;
541 
542  if (i == 1 || i == 2)
543  {
544  plane_height /= 2;
545  // U/V stride size is multiple of 128, following the calculation
546  // in ni_decoder_frame_buffer_alloc
547  plane_width = ((output_width / 2 * bit_depth_factor + 127) / 128) * 128;
548 
549  if (format == NI_PIX_FMT_NV12 || format == NI_PIX_FMT_P010LE)
550  {
551  plane_width = (((output_width * bit_depth_factor + 127) / 128) * 128);
552  // for semi-planar format, output UV at same time (data[1]) and skip data[2]
553  if (i == 1)
554  {
555  write_width *= 2;
556  }
557  if (i == 2)
558  {
559  plane_height = 0;
560  }
561  }
562 
563  write_height /= 2;
564  write_width /= 2;
565  }
566 
567  // apply the cropping window in writing out the YUV frame
568  // for now the window is usually crop-left = crop-top = 0, and we
569  // use this to simplify the cropping logic
570  for (j = 0; j < plane_height; j++)
571  {
572  if (j < write_height &&
573  fwrite(src, write_width, 1, p_file) != 1)
574  {
576  "Error: writing data plane %d: height %d error!\n",
577  i, plane_height);
578  ni_log(NI_LOG_ERROR, "Error: ferror rc = %d\n", ferror(p_file));
579  return NI_RETCODE_FAILURE;
580  }
581  src += plane_width;
582  }
583  }
584  break;
585  }
586  case NI_PIX_FMT_RGBA:
587  case NI_PIX_FMT_BGRA:
588  case NI_PIX_FMT_ARGB:
589  case NI_PIX_FMT_ABGR:
590  case NI_PIX_FMT_BGR0:
591  {
592  src = p_out_frame->p_data[0];
593  if (fwrite(src, output_width * output_height * 4, 1, p_file) != 1)
594  {
595  ni_log(NI_LOG_ERROR, "Error: ferror rc = %d\n", ferror(p_file));
596  return NI_RETCODE_FAILURE;
597  }
598  break;
599  }
600  case NI_PIX_FMT_BGRP:
601  {
602  for (i = 0; i < 3; i++)
603  {
604  src = p_out_frame->p_data[i];
605  if (fwrite(src, output_width * output_height, 1, p_file) != 1)
606  {
607  ni_log(NI_LOG_ERROR, "Error: ferror rc = %d\n", ferror(p_file));
608  return NI_RETCODE_FAILURE;
609  }
610  }
611  break;
612  }
613  default:
614  {
615  ni_log(NI_LOG_ERROR, "Unsupported format %d\n", format);
616  return NI_RETCODE_FAILURE;
617  }
618  }
619 
620  if (fflush(p_file))
621  {
623  "Error: writing data frame flush failed! errno %d\n",
624  errno);
625  return NI_RETCODE_FAILURE;
626  }
627  }
628  return NI_RETCODE_SUCCESS;
629 }
630 
631 static ni_hwframe_ref_t g_hwframe_pool[NI_MAX_DR_HWDESC_FRAME_INDEX];
632 
633 // final scan clean up of ref counted HW frame pool, return number of recycled
634 // HW frames.
636 {
637  int i;
638  int recycled = 0;
639 
640  for (i = 0; i < NI_MAX_DR_HWDESC_FRAME_INDEX; i++)
641  {
642  if (g_hwframe_pool[i].ref_cnt &&
643  g_hwframe_pool[i].surface.ui16FrameIdx)
644  {
645  ni_log(NI_LOG_DEBUG, "clean/recycle frame idx %u ref_cnt %d\n,",
646  g_hwframe_pool[i].surface.ui16FrameIdx,
647  g_hwframe_pool[i].ref_cnt);
648  ni_hwframe_buffer_recycle2(&g_hwframe_pool[i].surface);
649  g_hwframe_pool[i].ref_cnt = 0;
650  recycled++;
651  }
652  }
653 
654  return recycled;
655 }
656 
657 // reference HW frame
658 void ni_hw_frame_ref(const niFrameSurface1_t *p_surface)
659 {
660  uint16_t hwframe_index;
661 
662  if (!p_surface)
663  {
664  return;
665  }
666 
667  hwframe_index = p_surface->ui16FrameIdx;
668  g_hwframe_pool[hwframe_index].ref_cnt++;
669  if (1 == g_hwframe_pool[hwframe_index].ref_cnt)
670  {
671  memcpy(&g_hwframe_pool[hwframe_index].surface, p_surface,
672  sizeof(niFrameSurface1_t));
673  }
674  ni_log(NI_LOG_TRACE, "%s frame idx %u ref_cnt %d ..\n", __func__,
675  hwframe_index, g_hwframe_pool[hwframe_index].ref_cnt);
676 }
677 
678 // unref HW frame
679 void ni_hw_frame_unref(uint16_t hwframe_index)
680 {
681  if (g_hwframe_pool[hwframe_index].ref_cnt > 0)
682  {
683  g_hwframe_pool[hwframe_index].ref_cnt--;
684  if (0 == g_hwframe_pool[hwframe_index].ref_cnt &&
685  g_hwframe_pool[hwframe_index].surface.ui16FrameIdx)
686  {
687  ni_log(NI_LOG_TRACE, "%s frame idx recycing frame idx %u\n", __func__,
688  g_hwframe_pool[hwframe_index].surface.ui16FrameIdx);
689 
690  ni_hwframe_buffer_recycle2(&g_hwframe_pool[hwframe_index].surface);
691  }
692  ni_log(NI_LOG_TRACE, "%s frame idx %u ref_cnt now: %d\n", __func__,
693  hwframe_index, g_hwframe_pool[hwframe_index].ref_cnt);
694  } else
695  {
696  ni_log(NI_LOG_ERROR, "%s error frame idx %u ref_cnt %d <= 0\n",
697  __func__, hwframe_index,
698  g_hwframe_pool[hwframe_index].ref_cnt);
699  }
700 }
701 
702 /*!*****************************************************************************
703  * \brief Download hw frames by HwDesc.
704  *
705  * \param
706  *
707  * \return number of bytes downloaded if successful, <= 0 if failed
708  ******************************************************************************/
710  ni_session_data_io_t *p_session_data, ni_frame_t *p_src_frame,
711  int output_format)
712 {
713  niFrameSurface1_t *src_surf = (niFrameSurface1_t *)(p_src_frame->p_data[3]);
714  int ret = 0;
715 
716  ret = ni_frame_buffer_alloc_dl(&(p_session_data->data.frame),
717  src_surf->ui16width, src_surf->ui16height,
718  output_format);
719 
720  if (ret != NI_RETCODE_SUCCESS)
721  {
723  }
724 
725  p_ctx->is_auto_dl = false;
726  ret = ni_device_session_hwdl(p_ctx, p_session_data, src_surf);
727  if (ret <= 0)
728  {
729  ni_frame_buffer_free(&p_session_data->data.frame);
730  return ret;
731  }
732  return ret;
733 }
734 
735 /*!*****************************************************************************
736  * \brief Read from input file, upload to encoder, retrieve HW descriptor
737  *
738  * \param
739  *
740  * \return
741  ******************************************************************************/
743  ni_session_data_io_t *p_swin_data, //intermediate for swf
744  ni_session_data_io_t *p_in_data,
745  int input_video_width, int input_video_height,
746  void *yuv_buf)
747 {
748  int retval, is_semiplanar;
749  ni_frame_t *p_in_frame = &p_in_data->data.frame; //hwframe
750  ni_frame_t *p_swin_frame = &p_swin_data->data.frame; //swframe
751  niFrameSurface1_t *dst_surf = NULL;
752 
753  ni_log(NI_LOG_DEBUG, "===> upload_send_data <===\n");
754 
755  p_in_frame->start_of_stream = 0;
756  p_in_frame->end_of_stream = yuv_buf == NULL;
757  p_in_frame->force_key_frame = 0;
758  p_in_frame->video_width = p_swin_frame->video_width = input_video_width;
759  p_in_frame->video_height = p_swin_frame->video_height = input_video_height;
760  // only metadata header for now
763 
764  int dst_stride[NI_MAX_NUM_DATA_POINTERS] = {0};
765  int dst_height_aligned[NI_MAX_NUM_DATA_POINTERS] = {0};
767  input_video_width, input_video_height,
768  p_upl_ctx->pixel_format, dst_stride,
769  dst_height_aligned);
770  is_semiplanar = (
773  !is_semiplanar, p_swin_frame, input_video_width,
774  dst_height_aligned[0], dst_stride, 0,
775  (int)p_swin_frame->extra_data_len, false);
776  if (!p_swin_frame->p_data[0])
777  {
778  ni_log(NI_LOG_ERROR, "Error: could not allocate YUV frame buffer!");
779  return -1;
780  }
781 
782  //can also be ni_frame_buffer_alloc()
783  ni_frame_buffer_alloc_hwenc(p_in_frame, input_video_width,
784  input_video_height,
785  (int)p_in_frame->extra_data_len);
786  if (!p_in_frame->p_data[3])
787  {
788  ni_log(NI_LOG_ERROR, "Error: could not allocate hw frame buffer!");
789  return -1;
790  }
791 
792  dst_surf = (niFrameSurface1_t *)p_in_frame->p_data[3];
793 
794  ni_log(NI_LOG_DEBUG, "p_dst alloc linesize = %d/%d/%d src height=%d "
795  "dst height aligned = %d/%d/%d\n",
796  dst_stride[0], dst_stride[1], dst_stride[2],
797  input_video_height, dst_height_aligned[0],
798  dst_height_aligned[1], dst_height_aligned[2]);
799 
800  if (p_in_frame->end_of_stream)
801  {
802  goto hwupload;
803  }
804 
805  uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS] = {NULL};
806  int src_stride[NI_MAX_NUM_DATA_POINTERS] = {0};
807  int src_height[NI_MAX_NUM_DATA_POINTERS] = {0};
808  src_height[0] = input_video_height;
809  src_height[1] = input_video_height / 2;
810  src_height[2] = (is_semiplanar) ? 0 : (input_video_height / 2);
811  uint32_t conf_win_right = 0;
812 
813  switch (p_upl_ctx->pixel_format)
814  {
815  case NI_PIX_FMT_RGBA:
816  case NI_PIX_FMT_BGRA:
817  case NI_PIX_FMT_ABGR:
818  case NI_PIX_FMT_ARGB:
819  case NI_PIX_FMT_BGR0:
820  src_stride[0] = input_video_width * p_upl_ctx->bit_depth_factor;
821  src_height[0] = input_video_height;
822  src_height[1] = 0;
823  src_height[2] = 0;
824  p_src[0] = yuv_buf;
825  break;
826  case NI_PIX_FMT_NV12:
827  case NI_PIX_FMT_P010LE:
828  case NI_PIX_FMT_YUV420P:
830  src_stride[0] = input_video_width * p_upl_ctx->bit_depth_factor;
831  src_stride[1] = is_semiplanar ? src_stride[0] : src_stride[0] / 2;
832  src_stride[2] = is_semiplanar ? 0 : src_stride[0] / 2;
833 
834  p_src[0] = yuv_buf;
835  p_src[1] = p_src[0] + src_stride[0] * src_height[0];
836  p_src[2] = p_src[1] + src_stride[1] * src_height[1];
837  if (input_video_width < NI_MIN_WIDTH)
838  {
839  conf_win_right += (NI_MIN_WIDTH - input_video_width) / 2 * 2;
840  } else
841  {
842  conf_win_right += (NI_VPU_CEIL(input_video_width, 2) - input_video_width) / 2 * 2;
843  }
844  break;
845  default:
846  ni_log(NI_LOG_ERROR, "%s: Error Invalid pixel format %s\n", __func__,
847  ni_pixel_format_name(p_upl_ctx->pixel_format));
848  return -1;
849  }
850 
852  (uint8_t **)(p_swin_frame->p_data),
853  p_src, input_video_width,
854  input_video_height, p_upl_ctx->bit_depth_factor,
855  p_upl_ctx->pixel_format, conf_win_right, dst_stride,
856  dst_height_aligned, src_stride, src_height);
857 
858 hwupload:
859  retval = ni_device_session_hwup(p_upl_ctx, p_swin_data, dst_surf);
860  if (retval < 0)
861  {
862  ni_log(NI_LOG_ERROR, "Error: ni_device_session_hwup():%d, frameNum %u\n",
863  retval, p_ctx->num_frames_received);
864  return -1;
865  } else
866  {
867  p_ctx->dec_total_bytes_sent += p_swin_frame->data_len[0] + p_swin_frame->data_len[1] +
868  p_swin_frame->data_len[2] + p_swin_frame->data_len[3];
869  ni_log(NI_LOG_DEBUG, "upload_send_data: total sent data size=%lu\n",
870  p_ctx->dec_total_bytes_sent);
871 
872  dst_surf->ui16width = input_video_width;
873  dst_surf->ui16height = input_video_height;
874  dst_surf->encoding_type = is_semiplanar ?
877 
878  p_ctx->num_frames_received++;
879 
880  ni_log(NI_LOG_DEBUG, "upload_send_data: FID = %d success, number:%u\n",
881  dst_surf->ui16FrameIdx, p_ctx->num_frames_received);
882  }
883 
884  return 0;
885 }
886 
887 /*!*****************************************************************************
888  * \brief Uploader session open
889  *
890  * \param
891  *
892  * \return 0 if successful, < 0 otherwise
893  ******************************************************************************/
894 int uploader_open_session(ni_session_context_t *p_upl_ctx, int iXcoderGUID,
895  int width, int height, ni_pix_fmt_t pix_fmt,
896  int is_p2p, int pool_size)
897 {
898  int ret = 0;
899  p_upl_ctx->session_id = NI_INVALID_SESSION_ID;
900 
901  // assign the card GUID in the encoder context and let session open
902  // take care of the rest
903  p_upl_ctx->device_handle = NI_INVALID_DEVICE_HANDLE;
904  p_upl_ctx->blk_io_handle = NI_INVALID_DEVICE_HANDLE;
905  p_upl_ctx->hw_id = iXcoderGUID;
906 
907  // Set the input frame format of the upload session
908  ret = ni_uploader_set_frame_format(p_upl_ctx, width, height, pix_fmt, is_p2p);
909  if(ret != NI_RETCODE_SUCCESS)
910  {
911  ni_log(NI_LOG_ERROR, "Error: %s failure. Failed to set uploader format!\n", __func__);
912  return ret;
913  }
914 
916  if (ret != NI_RETCODE_SUCCESS)
917  {
918  ni_log(NI_LOG_ERROR, "Error: %s failure!\n", __func__);
919  return ret;
920  } else
921  {
922  ni_log(NI_LOG_INFO, "Uploader device %d session open successful.\n", iXcoderGUID);
923  }
924 
925  ret = ni_device_session_init_framepool(p_upl_ctx, pool_size, 0);
926  if (ret < 0)
927  {
928  ni_log(NI_LOG_ERROR, "Error: %s failure!\n", __func__);
929  } else
930  {
931  ni_log(NI_LOG_INFO, "Uploader device %d configured successful.\n", iXcoderGUID);
932  }
933 
934  return ret;
935 }
936 
938  ni_session_context_t *p_upl_ctx,
939  ni_session_context_t *p_sca_ctx,
940  ni_session_data_io_t *p_sw_data,
941  ni_session_data_io_t *p_hw_data,
942  ni_session_data_io_t *p_scale_data,
943  ni_pix_fmt_t pix_fmt, int width,
944  int height, FILE *pfs, void *yuv_buf, int *eos)
945 {
946  int ret, chunk_size;
947  niFrameSurface1_t *p_hwframe = NULL;
948 
949  chunk_size = read_yuv_from_file(p_ctx, pfs, yuv_buf, width, height, pix_fmt,
950  NI_SW_PIX_FMT_NONE, eos,
951  p_upl_ctx->session_run_state);
952  if (chunk_size < 0)
953  {
954  ni_log(NI_LOG_ERROR, "Error: read yuv file error\n");
955  return NULL;
956  }
957 
958  // need to have the hwframe before open encoder
959  ret = upload_send_data_get_desc(p_ctx, p_upl_ctx, p_sw_data, p_hw_data, width,
960  height, *eos ? NULL : yuv_buf);
962  {
963  ni_log(NI_LOG_DEBUG, "No space to write to, try to read a packet\n");
964  //file was read so reset read pointer and try again
965  rewind_data_buf_pos_by(p_ctx, chunk_size);
966  fseek(pfs, p_ctx->curr_file_offset, SEEK_SET);
967  return NULL;
968  } else if (ret)
969  {
970  ni_log(NI_LOG_ERROR, "Error: upload frame error\n");
971  return NULL;
972  }
973 
974  p_hwframe = (niFrameSurface1_t *)p_hw_data->data.frame.p_data[3];
975  if (p_hw_data->data.frame.end_of_stream)
976  {
977  // reach eos
978  return p_hwframe;
979  }
980 
981  // need to convert into pixel format for NI encoding
982  if (!is_ni_enc_pix_fmt(pix_fmt))
983  {
984  ni_hw_frame_ref(p_hwframe);
985  ret = scale_filter(p_sca_ctx, &p_hw_data->data.frame, p_scale_data,
986  p_upl_ctx->hw_id, width, height,
987  ni_to_gc620_pix_fmt(pix_fmt), GC620_I420);
988  ni_hw_frame_unref(p_hwframe->ui16FrameIdx);
989  if (ret)
990  {
991  ni_log(NI_LOG_ERROR, "Error: upload frame error\n");
992  return NULL;
993  }
994  p_hwframe = (niFrameSurface1_t *)p_scale_data->data.frame.p_data[3];
995  }
996 
997  return p_hwframe;
998 }
GC620_RGB888_PLANAR
#define GC620_RGB888_PLANAR
Definition: ni_device_api.h:207
uploader_open_session
int uploader_open_session(ni_session_context_t *p_upl_ctx, int iXcoderGUID, int width, int height, ni_pix_fmt_t pix_fmt, int is_p2p, int pool_size)
Uploader session open.
Definition: ni_generic_utils.c:894
NI_PIX_FMT_UYVY422
@ NI_PIX_FMT_UYVY422
Definition: ni_device_api.h:274
NI_PIX_FMT_BGRA
@ NI_PIX_FMT_BGRA
Definition: ni_device_api.h:267
write_rawvideo_data
int write_rawvideo_data(FILE *p_file, int input_aligned_width, int input_aligned_height, int output_width, int output_height, int format, ni_frame_t *p_out_frame)
Write hwdl data to files.
Definition: ni_generic_utils.c:510
frame_list_is_full
bool frame_list_is_full(ni_test_frame_list_t *list)
Definition: ni_generic_utils.c:180
_ni_gc620_pix_fmt
Definition: ni_generic_utils.h:89
gc620_to_ni_pix_fmt
ni_pix_fmt_t gc620_to_ni_pix_fmt(int pix_fmt)
Definition: ni_generic_utils.c:132
_ni_demo_context::loops_left
uint64_t loops_left
Definition: ni_generic_utils.h:117
reset_data_buf_pos
void reset_data_buf_pos(ni_demo_context_t *p_ctx)
Definition: ni_generic_utils.c:316
ni_pix_fmt_t
ni_pix_fmt_t
Definition: ni_device_api.h:260
get_total_file_size
uint64_t get_total_file_size(FILE *fp)
Definition: ni_generic_utils.c:250
ni_frame_buffer_free
ni_retcode_t ni_frame_buffer_free(ni_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_frame_buffer_alloc or ni_encoder_frame...
Definition: ni_device_api.c:3561
_ni_gc620_pix_fmt::pix_fmt_ni
ni_pix_fmt_t pix_fmt_ni
Definition: ni_generic_utils.h:91
GC620_ABGR8888
#define GC620_ABGR8888
Definition: ni_device_api.h:202
ni_hw_frame_ref
void ni_hw_frame_ref(const niFrameSurface1_t *p_surface)
Definition: ni_generic_utils.c:658
_ni_gc620_pix_fmt::pix_fmt_gc620
int pix_fmt_gc620
Definition: ni_generic_utils.h:92
_niFrameSurface1::ui16height
uint16_t ui16height
Definition: ni_device_api.h:2798
_ni_pix_fmt_name
Definition: ni_generic_utils.h:83
_ni_session_context::session_id
uint32_t session_id
Definition: ni_device_api.h:1480
ni_hw_frame_unref
void ni_hw_frame_unref(uint16_t hwframe_index)
Definition: ni_generic_utils.c:679
ni_generic_utils.h
print_version
void print_version(void)
Definition: ni_generic_utils.c:70
_ni_demo_context::total_file_size
uint64_t total_file_size
Definition: ni_generic_utils.h:116
frame_list_length
int frame_list_length(ni_test_frame_list_t *list)
Definition: ni_generic_utils.c:203
NI_SW_RELEASE_ID
#define NI_SW_RELEASE_ID
Definition: ni_release_info.h:29
NI_PIX_FMT_YUV420P
@ NI_PIX_FMT_YUV420P
Definition: ni_device_api.h:262
_ni_hwframe_ref_t
Definition: ni_generic_utils.h:96
NI_RETCODE_SUCCESS
@ NI_RETCODE_SUCCESS
Definition: ni_defs.h:427
total_file_size
unsigned long total_file_size
Definition: ni_p2p_test.c:70
NI_DEVICE_TYPE_UPLOAD
@ NI_DEVICE_TYPE_UPLOAD
Definition: ni_defs.h:353
_ni_session_context::status
int status
Definition: ni_device_api.h:1524
ni_encoder_sw_frame_buffer_alloc
ni_retcode_t ni_encoder_sw_frame_buffer_alloc(bool planar, ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
This API is a wrapper for ni_encoder_frame_buffer_alloc(), used for planar pixel formats,...
Definition: ni_device_api.c:3531
NI_INVALID_SESSION_ID
#define NI_INVALID_SESSION_ID
Definition: ni_device_api.h:111
GC620_ARGB8888
#define GC620_ARGB8888
Definition: ni_device_api.h:203
NI_PIX_FMT_BGR0
@ NI_PIX_FMT_BGR0
Definition: ni_device_api.h:270
GC620_YUYV
#define GC620_YUYV
Definition: ni_device_api.h:196
NI_MAX_FILTER_POOL_SIZE
#define NI_MAX_FILTER_POOL_SIZE
Definition: ni_defs.h:315
NI_XCODER_REVISION
#define NI_XCODER_REVISION
Definition: ni_defs.h:95
is_ni_enc_pix_fmt
int is_ni_enc_pix_fmt(ni_pix_fmt_t pix_fmt)
Definition: ni_generic_utils.c:81
_ni_session_context::blk_io_handle
ni_device_handle_t blk_io_handle
Definition: ni_device_api.h:1465
NI_PIX_FMT_BGRP
@ NI_PIX_FMT_BGRP
Definition: ni_device_api.h:271
NI_PIX_FMT_NONE
@ NI_PIX_FMT_NONE
Definition: ni_device_api.h:277
_ni_demo_context::curr_file_offset
uint64_t curr_file_offset
Definition: ni_generic_utils.h:115
NI_PIX_FMT_8_TILED4X4
@ NI_PIX_FMT_8_TILED4X4
Definition: ni_device_api.h:275
_ni_session_context::bit_depth_factor
int bit_depth_factor
Definition: ni_device_api.h:1494
scan_and_clean_hwdescriptors
int scan_and_clean_hwdescriptors(void)
Definition: ni_generic_utils.c:635
_ni_session_context::hw_id
int hw_id
Definition: ni_device_api.h:1478
_ni_test_frame_list
Definition: ni_generic_utils.h:102
NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_MEM_ALOC
Definition: ni_defs.h:431
SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
Definition: ni_device_api.h:1178
frame_list_is_empty
bool frame_list_is_empty(ni_test_frame_list_t *list)
Definition: ni_generic_utils.c:175
NI_SW_PIX_FMT_NONE
@ NI_SW_PIX_FMT_NONE
Definition: ni_generic_utils.h:78
ni_log.h
Logging definitions.
frame_list_enqueue
int frame_list_enqueue(ni_test_frame_list_t *list)
Definition: ni_generic_utils.c:209
_niFrameSurface1::ui16FrameIdx
uint16_t ui16FrameIdx
Definition: ni_device_api.h:2795
_ni_demo_context
Definition: ni_generic_utils.h:109
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:61
NI_APP_ENC_FRAME_META_DATA_SIZE
#define NI_APP_ENC_FRAME_META_DATA_SIZE
Definition: ni_defs.h:308
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:60
ni_to_gc620_pix_fmt
int ni_to_gc620_pix_fmt(ni_pix_fmt_t pix_fmt)
Definition: ni_generic_utils.c:117
ni_pixel_format_name
const char * ni_pixel_format_name(ni_pix_fmt_t pix_fmt)
Definition: ni_generic_utils.c:102
GC620_NV16
#define GC620_NV16
Definition: ni_device_api.h:198
read_and_cache_file
int read_and_cache_file(ni_demo_context_t *ctx, char *filename)
Definition: ni_generic_utils.c:259
NI_PIX_FMT_NV12
@ NI_PIX_FMT_NV12
Definition: ni_device_api.h:264
ni_filter_utils.h
_ni_test_frame_list::tail
int tail
Definition: ni_generic_utils.h:106
_ni_frame::data_len
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2664
_ni_frame::extra_data_len
unsigned int extra_data_len
Definition: ni_device_api.h:2657
_ni_demo_context::num_frames_received
uint64_t num_frames_received
Definition: ni_generic_utils.h:128
ni_device_session_hwup
int ni_device_session_hwup(ni_session_context_t *p_ctx, ni_session_data_io_t *p_src_data, niFrameSurface1_t *hwdesc)
Sends raw YUV input to uploader instance and retrieves a HW descriptor to represent it.
Definition: ni_device_api.c:8363
_ni_test_frame_list::head
int head
Definition: ni_generic_utils.h:105
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:63
_ni_frame::end_of_stream
uint32_t end_of_stream
Definition: ni_device_api.h:2608
_niFrameSurface1::encoding_type
int8_t encoding_type
Definition: ni_device_api.h:2802
NI_PIX_FMT_NV16
@ NI_PIX_FMT_NV16
Definition: ni_device_api.h:272
_ni_session_context::device_handle
ni_device_handle_t device_handle
Definition: ni_device_api.h:1462
uploader_frame_list_full
bool uploader_frame_list_full(ni_test_frame_list_t *list, ni_pix_fmt_t pix_fmt)
Definition: ni_generic_utils.c:185
get_pixel_planar
ni_pixel_planar_format get_pixel_planar(ni_pix_fmt_t pix_fmt)
Definition: ni_generic_utils.c:147
NI_SW_RELEASE_TIME
#define NI_SW_RELEASE_TIME
Definition: ni_release_info.h:28
hwframe_list_release
void hwframe_list_release(ni_test_frame_list_t *list)
Definition: ni_generic_utils.c:231
_ni_session_data_io
Definition: ni_device_api.h:2866
NI_PIX_FMT_YUV420P10LE
@ NI_PIX_FMT_YUV420P10LE
Definition: ni_device_api.h:263
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_pix_fmt_name::name
const char * name
Definition: ni_generic_utils.h:85
GC620_BGRX8888
#define GC620_BGRX8888
Definition: ni_device_api.h:201
ni_uploader_set_frame_format
ni_retcode_t ni_uploader_set_frame_format(ni_session_context_t *p_upl_ctx, int width, int height, ni_pix_fmt_t pixel_format, int isP2P)
Set the outgoing frame format for the uploader.
Definition: ni_device_api.c:11171
GC620_I420
#define GC620_I420
Definition: ni_device_api.h:193
GC620_RGBA8888
#define GC620_RGBA8888
Definition: ni_device_api.h:199
_ni_frame::force_key_frame
int force_key_frame
Definition: ni_device_api.h:2624
NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
Definition: ni_device_api.h:920
ni_pixel_format_search
ni_pix_fmt_t ni_pixel_format_search(const char *name)
Definition: ni_generic_utils.c:87
hwupload_frame
niFrameSurface1_t * hwupload_frame(ni_demo_context_t *p_ctx, ni_session_context_t *p_upl_ctx, ni_session_context_t *p_sca_ctx, ni_session_data_io_t *p_sw_data, ni_session_data_io_t *p_hw_data, ni_session_data_io_t *p_scale_data, ni_pix_fmt_t pix_fmt, int width, int height, FILE *pfs, void *yuv_buf, int *eos)
Definition: ni_generic_utils.c:937
_ni_test_frame_list::frames
ni_session_data_io_t frames[NI_MAX_BUFFERED_FRAME]
Definition: ni_generic_utils.h:104
GC620_P010_MSB
#define GC620_P010_MSB
Definition: ni_device_api.h:194
convert_yuv_444p_to_420p
int convert_yuv_444p_to_420p(ni_session_data_io_t *p_frame, void *yuv_buf, int width, int height, ni_sw_pix_fmt_t sw_pix_fmt, int mode, ni_codec_format_t codec_format)
Definition: ni_generic_utils.c:448
_ni_frame::p_data
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
Definition: ni_device_api.h:2663
NI_VPU_CEIL
#define NI_VPU_CEIL(_data, _align)
Definition: ni_device_api.h:328
ni_hwframe_buffer_recycle2
ni_retcode_t ni_hwframe_buffer_recycle2(niFrameSurface1_t *surface)
Recycle a frame buffer on card, only hwframe descriptor is needed.
Definition: ni_device_api.c:8517
NI_SW_PIX_FMT_YUV444P10LE
@ NI_SW_PIX_FMT_YUV444P10LE
Definition: ni_generic_utils.h:80
data_left_size
uint64_t data_left_size
Definition: ni_p2p_test.c:59
_ni_session_context
Definition: ni_device_api.h:1408
NI_PIX_FMT_P010LE
@ NI_PIX_FMT_P010LE
Definition: ni_device_api.h:265
_niFrameSurface1
Definition: ni_device_api.h:2793
ni_frame_buffer_alloc_hwenc
ni_retcode_t ni_frame_buffer_alloc_hwenc(ni_frame_t *p_frame, int video_width, int video_height, int extra_len)
Allocate memory for the hwDescriptor buffer based on provided parameters taking into account pic size...
Definition: ni_device_api.c:8399
NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_NUM_DATA_POINTERS
Definition: ni_defs.h:232
NI_MAX_BUFFERED_FRAME
#define NI_MAX_BUFFERED_FRAME
Definition: ni_generic_utils.h:67
_ni_session_data_io::data
union _ni_session_data_io::@19 data
_ni_frame
Definition: ni_device_api.h:2601
NI_PIX_FMT_YUYV422
@ NI_PIX_FMT_YUYV422
Definition: ni_device_api.h:273
NI_PIX_FMT_RGBA
@ NI_PIX_FMT_RGBA
Definition: ni_device_api.h:266
ni_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
GC620_NV12
#define GC620_NV12
Definition: ni_device_api.h:191
NI_PIX_FMT_ABGR
@ NI_PIX_FMT_ABGR
Definition: ni_device_api.h:269
hwdl_frame
int hwdl_frame(ni_session_context_t *p_ctx, ni_session_data_io_t *p_session_data, ni_frame_t *p_src_frame, int output_format)
Download hw frames by HwDesc.
Definition: ni_generic_utils.c:709
ni_pixel_planar_format
enum _ni_pixel_planar_format ni_pixel_planar_format
ni_session_run_state_t
enum _ni_session_run_state ni_session_run_state_t
Session running state type.
NI_PIX_FMT_ARGB
@ NI_PIX_FMT_ARGB
Definition: ni_device_api.h:268
GC620_BGRA8888
#define GC620_BGRA8888
Definition: ni_device_api.h:200
GC620_UYVY
#define GC620_UYVY
Definition: ni_device_api.h:197
frame_list_drain
int frame_list_drain(ni_test_frame_list_t *list)
Definition: ni_generic_utils.c:219
ni_get_min_frame_dim
void ni_get_min_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:2181
_ni_demo_context::file_cache
uint8_t * file_cache
Definition: ni_generic_utils.h:114
_ni_demo_context::dec_total_bytes_sent
uint64_t dec_total_bytes_sent
Definition: ni_generic_utils.h:124
read_next_chunk_from_file
uint32_t read_next_chunk_from_file(ni_demo_context_t *p_ctx, FILE *fp, uint8_t *p_dst, uint32_t to_read)
Definition: ni_generic_utils.c:375
NI_SW_PIX_FMT_YUV444P
@ NI_SW_PIX_FMT_YUV444P
Definition: ni_generic_utils.h:79
ni_sw_pix_fmt_t
ni_sw_pix_fmt_t
Definition: ni_generic_utils.h:76
_ni_hwframe_ref_t::ref_cnt
int ref_cnt
Definition: ni_generic_utils.h:98
ni_copy_frame_data
void ni_copy_frame_data(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int factor, ni_pix_fmt_t pix_fmt, int conf_win_right, int dst_stride[NI_MAX_NUM_DATA_POINTERS], int dst_height[NI_MAX_NUM_DATA_POINTERS], int src_stride[NI_MAX_NUM_DATA_POINTERS], int src_height[NI_MAX_NUM_DATA_POINTERS])
Copy RGBA or YUV data to Netint HW frame layout to be sent to encoder for encoding....
Definition: ni_util.c:2398
read_yuv_from_file
int read_yuv_from_file(ni_demo_context_t *p_ctx, FILE *pfs, void *yuv_buf, int width, int height, ni_pix_fmt_t pix_fmt, ni_sw_pix_fmt_t sw_pix_fmt, int *eos, ni_session_run_state_t run_state)
Definition: ni_generic_utils.c:413
GC620_I010
#define GC620_I010
Definition: ni_device_api.h:195
scale_filter
int scale_filter(ni_session_context_t *p_ctx, ni_frame_t *p_frame_in, ni_session_data_io_t *p_data_out, int iXcoderGUID, int scale_width, int scale_height, int in_format, int out_format)
Do a scale and/or format-change operation.
Definition: ni_filter_utils.c:513
_ni_session_context::is_auto_dl
uint8_t is_auto_dl
Definition: ni_device_api.h:1470
_niFrameSurface1::ui16width
uint16_t ui16width
Definition: ni_device_api.h:2797
_ni_session_data_io::frame
ni_frame_t frame
Definition: ni_device_api.h:2870
NI_MAX_DR_HWDESC_FRAME_INDEX
#define NI_MAX_DR_HWDESC_FRAME_INDEX
Definition: ni_defs.h:253
ni_encoder_frame_buffer_alloc
ni_retcode_t ni_encoder_frame_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
Allocate memory for the frame buffer for encoding based on given parameters, taking into account pic ...
Definition: ni_device_api.c:3161
ni_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_frame::video_height
uint32_t video_height
Definition: ni_device_api.h:2611
LIBXCODER_API_VERSION
#define LIBXCODER_API_VERSION
Definition: ni_defs.h:112
_ni_session_context::session_run_state
ni_session_run_state_t session_run_state
Definition: ni_device_api.h:1547
_ni_pix_fmt_name::pix_fmt
ni_pix_fmt_t pix_fmt
Definition: ni_generic_utils.h:86
NI_RETCODE_FAILURE
@ NI_RETCODE_FAILURE
Definition: ni_defs.h:428
_ni_frame::start_of_stream
uint32_t start_of_stream
Definition: ni_device_api.h:2609
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_device_session_hwdl
int ni_device_session_hwdl(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, niFrameSurface1_t *hwdesc)
Reads YUV data from hw descriptor stored location on device.
Definition: ni_device_api.c:8210
NI_PIX_FMT_10_TILED4X4
@ NI_PIX_FMT_10_TILED4X4
Definition: ni_device_api.h:276
rewind_data_buf_pos_by
void rewind_data_buf_pos_by(ni_demo_context_t *p_ctx, uint64_t nb_bytes)
Definition: ni_generic_utils.c:322
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_RETCODE_NVME_SC_WRITE_BUFFER_FULL
@ NI_RETCODE_NVME_SC_WRITE_BUFFER_FULL
Definition: ni_defs.h:534
NI_CODEC_FORMAT_H264
@ NI_CODEC_FORMAT_H264
Definition: ni_device_api.h:911
_ni_frame::video_width
uint32_t video_width
Definition: ni_device_api.h:2610
NI_MIN_WIDTH
#define NI_MIN_WIDTH
Definition: ni_device_api.h:124
upload_send_data_get_desc
int upload_send_data_get_desc(ni_demo_context_t *p_ctx, ni_session_context_t *p_upl_ctx, ni_session_data_io_t *p_swin_data, ni_session_data_io_t *p_in_data, int input_video_width, int input_video_height, void *yuv_buf)
Read from input file, upload to encoder, retrieve HW descriptor.
Definition: ni_generic_utils.c:742
ni_device_session_init_framepool
int ni_device_session_init_framepool(ni_session_context_t *p_ctx, uint32_t pool_size, uint32_t pool)
Sends frame pool setup info to device.
Definition: ni_device_api.c:8564
_ni_session_context::pixel_format
int pixel_format
Definition: ni_device_api.h:1616
frame_read_buffer_size
int frame_read_buffer_size(int w, int h, ni_pix_fmt_t pix_fmt, ni_sw_pix_fmt_t sw_pix_fmt)
Definition: ni_generic_utils.c:335
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:62
NI_PIXEL_PLANAR_FORMAT_TILED4X4
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
Definition: ni_device_api.h:922
ni_copy_yuv_444p_to_420p
void ni_copy_yuv_444p_to_420p(uint8_t *p_dst0[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_dst1[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int factor, int mode)
Copy yuv444p data to yuv420p frame layout to be sent to encoder for encoding. Data buffer (dst) is us...
Definition: ni_util.c:2478
NI_PIXEL_PLANAR_FORMAT_PLANAR
@ NI_PIXEL_PLANAR_FORMAT_PLANAR
Definition: ni_device_api.h:921