28#if __linux__ || __APPLE__
151 SYSTEMTIME system_time;
152 ULARGE_INTEGER ularge;
154 static const unsigned __int64 epoch =
155 ((
unsigned __int64)116444736000000000ULL);
161 GetSystemTime(&system_time);
162 SystemTimeToFileTime(&system_time, &file_time);
163 ularge.LowPart = file_time.dwLowDateTime;
164 ularge.HighPart = file_time.dwHighDateTime;
166 (void)ularge.LowPart;
167 (void)ularge.HighPart;
168 p_tp->tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L);
169 p_tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
173 return gettimeofday(p_tp, p_tzp);
181 return number_to_round;
184 uint32_t remainder = number_to_round % multiple;
187 return number_to_round;
190 return (number_to_round + multiple - remainder);
209 *memptr = _aligned_malloc(size, alignment);
215 ZeroMemory(*memptr, size);
219 return posix_memalign(memptr, alignment, size);
231uint32_t ni_get_kernel_max_io_size(
const char * p_dev)
234 char file_name[KERNEL_NVME_FILE_NAME_MAX_SZ];
235 int max_segments = 0, min_io_size = 0, max_hw_sectors_kb = 0;
236 uint32_t io_size = DEFAULT_IO_TRANSFER_SIZE;
240 memset(file_name, 0, KERNEL_NVME_FILE_NAME_MAX_SZ);
248 len = strlen(p_dev) - 5;
249 if (len < MIN_NVME_DEV_NAME_LEN)
256 memset(file_name, 0,
sizeof(file_name));
257 ni_strcpy(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, SYS_PARAMS_PREFIX_PATH);
258#if defined(_ANDROID) || defined(__OPENHARMONY__)
260 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 11),
sizeof(file_name) - SYS_PREFIX_SZ);
263 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 5),
sizeof(file_name) - SYS_PREFIX_SZ);
265 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, KERNEL_NVME_MAX_SEG_PATH,
266 sizeof(file_name) - SYS_PREFIX_SZ - len);
275 err =
ni_fscanf(p_file,
"%d", &max_segments);
282 (void)fclose(p_file);
285 memset(file_name, 0,
sizeof(file_name));
286 ni_strcpy(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, SYS_PARAMS_PREFIX_PATH);
287#if defined(_ANDROID) || defined(__OPENHARMONY__)
289 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 11),
sizeof(file_name) - SYS_PREFIX_SZ);
292 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 5),
sizeof(file_name) - SYS_PREFIX_SZ);
294 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, KERNEL_NVME_MIN_IO_SZ_PATH,
295 sizeof(file_name) - SYS_PREFIX_SZ - len);
304 err =
ni_fscanf(p_file,
"%d", &min_io_size);
311 (void)fclose(p_file);
314 memset(file_name, 0,
sizeof(file_name));
315 ni_strcpy(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, SYS_PARAMS_PREFIX_PATH);
316#if defined(_ANDROID) || defined(__OPENHARMONY__)
318 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 11),
sizeof(file_name) - SYS_PREFIX_SZ);
321 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 5),
sizeof(file_name) - SYS_PREFIX_SZ);
323 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, KERNEL_NVME_MAX_HW_SEC_KB_PATH,
324 sizeof(file_name) - SYS_PREFIX_SZ - len);
333 err =
ni_fscanf(p_file,
"%d", &max_hw_sectors_kb);
340 if (ni_min(min_io_size * max_segments, max_hw_sectors_kb * 1024) >
341 MAX_IO_TRANSFER_SIZE)
343 io_size = MAX_IO_TRANSFER_SIZE;
347 io_size = ni_min(min_io_size * max_segments, max_hw_sectors_kb * 1024);
352 (void)fflush(stdout);
358 (void)fclose(p_file);
371 LARGE_INTEGER StartCount;
372 LARGE_INTEGER StopCount;
373 LARGE_INTEGER Frequency;
374 QueryPerformanceCounter(&StartCount);
375 QueryPerformanceFrequency(&Frequency);
377 StartCount.QuadPart + usec * (Frequency.QuadPart / 1000000);
380 QueryPerformanceCounter(&StartCount);
381 }
while (StartCount.QuadPart < StopCount.QuadPart);
385 LARGE_INTEGER ft = {0};
392 timer = CreateWaitableTimer(NULL, TRUE, NULL);
395 retval = SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
398 WaitForSingleObject(timer, INFINITE);
404 LARGE_INTEGER StartCount;
405 LARGE_INTEGER StopCount;
406 LARGE_INTEGER Frequency;
407 QueryPerformanceCounter(&StartCount);
408 QueryPerformanceFrequency(&Frequency);
410 StartCount.QuadPart + usec * (Frequency.QuadPart / 1000000);
413 QueryPerformanceCounter(&StartCount);
414 }
while (StartCount.QuadPart < StopCount.QuadPart);
418 if (usec < 0xFFFFFFFF)
423 struct timespec ts = {(time_t)(usec >> 32), 0};
424 nanosleep(&ts, NULL);
429char *
ni_strtok(
char *s,
const char *delim,
char **saveptr)
439 s += strspn(s, delim);
449 s += strcspn(s, delim);
463 if(strcpy_s(dest, dmax, src))
468 if (!dest || !dmax || !src)
476 const char *overlap_bumper;
482 overlap_bumper = src;
484 if (dest == overlap_bumper) {
498 overlap_bumper = dest;
500 if (src == overlap_bumper) {
526 const char *src,
size_t slen)
529 if(strncpy_s(dest, dmax, src, slen))
534 if (slen == 0 && dest && dmax) {
539 if (!dest || !dmax || !src)
543 const char *overlap_bumper;
549 overlap_bumper = src;
552 if (dest == overlap_bumper) {
563#ifdef SAFECLIB_STR_NULL_SLACK
565 memset(dest, 0, dmax);
581#ifdef SAFECLIB_STR_NULL_SLACK
583 memset(dest, 0, dmax);
601 overlap_bumper = dest;
604 if (src == overlap_bumper) {
615#ifdef SAFECLIB_STR_NULL_SLACK
617 memset(dest, 0, dmax);
633#ifdef SAFECLIB_STR_NULL_SLACK
635 memset(dest, 0, dmax);
666 if(strerror_s(dest, dmax, errnum))
671 if (!dest || !dmax || (dmax >= (
size_t)(-1)))
674 char strerr_buf[256];
675#if defined(_GNU_SOURCE)
677 const char *strerr_str = strerror_r(errnum, strerr_buf,
sizeof(strerr_buf));
681 (void)strerror_r(errnum, strerr_buf,
sizeof(strerr_buf));
687 len = strerrorlen_s(errnum);
689 const char *tmpbuf = strerror(errnum);
691 }
else if (dmax > 3) {
692 const char *tmpbuf = strerror(errnum);
707 if(strcat_s(dest, dmax, src))
712 if (!dest || !dmax || !src)
717 const char *overlap_bumper;
723 overlap_bumper = src;
725 while (*dest !=
'\0') {
726 if (dest == overlap_bumper) {
741 if (dest == overlap_bumper) {
749#ifdef SAFECLIB_STR_NULL_SLACK
751 memset(dest, 0, dmax);
768 overlap_bumper = dest;
771 while (*dest !=
'\0') {
786 if (src == overlap_bumper) {
795#ifdef SAFECLIB_STR_NULL_SLACK
797 memset(dest, 0, dmax);
823 const char *src,
size_t slen)
827 const char *overlap_bumper;
829 if (slen == 0 && !dest && !dmax) {
833 if (!dest || !dmax || !src)
835 else if (slen == 0) {
848 overlap_bumper = src;
851 while (*dest !=
'\0') {
853 if (dest == overlap_bumper) {
869 if (dest == overlap_bumper) {
879#ifdef SAFECLIB_STR_NULL_SLACK
882 memset(dest, 0, dmax);
898#ifdef SAFECLIB_STR_NULL_SLACK
901 memset(dest, 0, dmax);
919 overlap_bumper = dest;
922 while (*dest !=
'\0') {
938 if (src == overlap_bumper) {
948#ifdef SAFECLIB_STR_NULL_SLACK
951 memset(dest, 0, dmax);
967#ifdef SAFECLIB_STR_NULL_SLACK
970 memset(dest, 0, dmax);
1000#if defined(_MSC_VER)
1001 if(fopen_s(fp, filename, mode))
1006 if (!fp || !filename || !mode)
1009 *fp = fopen(filename, mode);
1021 if (localtime_s(dest, src))
1031 return localtime_r(src, dest);
1038#if defined(_MSC_VER)
1040 va_start(args, fmt);
1041 ret = vfscanf_s(stream, fmt, args);
1044 if (!stream || !fmt)
1047 va_start(args, fmt);
1048 ret = vfscanf(stream, fmt, args);
1054int ni_vsprintf(
char *dest,
const size_t dmax,
const char *fmt, va_list args)
1056#if defined(_MSC_VER)
1057 int ret = vsprintf_s(dest, dmax, fmt, args);
1060 if (!dest || !dmax || !fmt)
1063 int ret = vsnprintf(dest, dmax, fmt, args);
1067 }
else if ((
size_t)ret >= dmax) {
1069 char *overrun = dest + dmax - 1;
1080 va_start(args, fmt);
1109 if (NULL == p_buffer_pool)
1228 if (NULL != p_buffer_pool)
1230 if (NULL != p_buffer_pool && p_buffer != NULL)
1233 memset(p_buffer, 0,
sizeof(
ni_buf_t));
1241 p_buffer->
buf = p_buf;
1242 p_buffer->
pool = p_buffer_pool;
1265 int32_t number_of_buffers,
1266 int width,
int height,
1267 int height_align,
int factor)
1277 width_aligned = ((((width * factor) + 127) / 128) * 128) / factor;
1278 height_aligned = height;
1281 width_aligned = ((width + 31) / 32) * 32;
1282 height_aligned = ((height + 7) / 8) * 8;
1285 height_aligned = ((height + 15) / 16) * 16;
1289 int luma_size = width_aligned * height_aligned * factor;
1294 int chroma_width_aligned =
1295 ((((width / 2 * factor) + 127) / 128) * 128) / factor;
1296 int chroma_height_aligned = height_aligned / 2;
1297 chroma_b_size = chroma_r_size =
1298 chroma_width_aligned * chroma_height_aligned * factor;
1301 chroma_b_size = luma_size / 4;
1302 chroma_r_size = chroma_b_size;
1304 uint32_t buffer_size = luma_size + chroma_b_size + chroma_r_size +
1317 "Warning init dec_fme Buf pool already with size %u\n",
1323 "Warning resolution %dx%d memory buffer size %u "
1324 "> %u (existing buffer size), re-allocating !\n",
1325 width, height, buffer_size,
1332 "INFO resolution %dx%d memory buffer size %u <= "
1333 "%u (existing buffer size), continue !\n",
1334 width, height, buffer_size,
1353 "ni_dec_fme_buffer_pool_initialize: entries %d entry size "
1355 number_of_buffers, buffer_size);
1358 for (i = 0; i < number_of_buffers; i++)
1400 int32_t count_free = 0;
1419 free(p_buffer_pool);
1463 free(p_buffer_pool);
1475 if (NULL != p_buffer_pool)
1477 if (NULL != p_buffer_pool && p_buffer != NULL)
1529 for (i = 0; i < number_of_buffers; i++)
1546 for (i = 0; i < 200; i++)
1551 "FATAL ERROR: Failed to allocate pool buffer for pool :%p\n",
1564 if (NULL == p_buffer_pool)
1616 if (!buf || !p_buffer_pool)
1681static ni_retcode_t ni_search_file(
const char *p_dev,
char *cmd,
char *cmd_ret,
1687 if (access(p_dev, F_OK) == -1)
1693 cmd_fp = popen(cmd,
"r");
1699 if (fgets(cmd_ret, cmd_ret_len, cmd_fp) == 0)
1727NI_UNUSED static uint32_t remove_substring_pattern(
char *main_str,
const char *pattern)
1730 uint32_t match_length;
1731 uint32_t matched_chr;
1732 char char_match_pattern[11] =
"";
1733 uint32_t pattern_matched = 0;
1734 uint32_t pattern_start = 0;
1735 const char digit_match_pattern[11] =
"0123456789";
1738 if (!main_str || !pattern || !*main_str || !*pattern)
1744 for (i = 0; i < strlen(main_str) && !pattern_matched; i++)
1746 pattern_matched = 0;
1749 for (j = 0; j < strlen(pattern); j++)
1753 if (pattern[j] ==
'+')
1758 else if (pattern[j] ==
'#')
1760 memcpy(char_match_pattern, digit_match_pattern, strlen(digit_match_pattern) + 1);
1764 memcpy(char_match_pattern, pattern + j, 1);
1765 memset(char_match_pattern + 1, 0, 1);
1768 if (pattern[j+1] ==
'+')
1770 while (main_str[i + match_length] && strchr(char_match_pattern, (
int) main_str[i + match_length]))
1777 else if (main_str[i + match_length] && strchr(char_match_pattern, (
int) main_str[i + match_length]))
1788 else if ((j + 1) >= strlen(pattern))
1790 pattern_matched = 1;
1797 if (pattern_matched)
1799 uint32_t orig_main_str_len = (uint32_t)strlen(main_str);
1800 memmove(main_str + pattern_start, main_str + pattern_start + match_length,
1801 strlen(main_str + pattern_start + match_length));
1802 main_str[orig_main_str_len - match_length] = 0;
1823 if (!p_dev || !p_out_buf)
1830 "Automatic namespaceID discovery not supported in Windows. Using "
1832 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1843 char cmd_ret[60] = {0};
1844 char command[128] = {0};
1845 snprintf(command,
sizeof(command) - 1,
1846 "diskutil info %s | grep 'Media Name'", p_dev);
1848 cmd_fp = popen(command,
"r");
1854 if (fgets(cmd_ret,
sizeof(cmd_ret) - 1, cmd_fp) == NULL)
1863 if (strcasestr(cmd_ret,
"Quadra") != NULL)
1865 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1873#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
1874 ni_log(
NI_LOG_TRACE,
"The device is already considered as a block divice in Linux virtual machine with VirtIO driver.\n");
1875 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1879 (void)snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1908 char cmd_ret[60] = {0};
1909 char command[128] = {0};
1910 snprintf(command,
sizeof(command) - 1,
1911 "diskutil info %s | grep 'Media Name'", p_dev);
1913 cmd_fp = popen(command,
"r");
1919 if (fgets(cmd_ret,
sizeof(cmd_ret) - 1, cmd_fp) == NULL)
1928 if (strcasestr(cmd_ret,
"Quadra") != NULL)
1954 if (*pp_table != NULL)
2015 int64_t timestamp, uint64_t data_info)
2041 uint64_t frame_info, int64_t *p_timestamp,
2042 int32_t threshold, int32_t print,
2048 __func__, frame_info);
2051 print, p_buffer_pool);
2058 "%s: timestamp=%" PRId64
", frame_info=%" PRId64
", err=%d\n",
2059 __func__, *p_timestamp, frame_info, err);
2069 threshold, print, p_buffer_pool);
2076 if (!pts_list || !dts_list)
2085 time_t now = time(NULL);
2117 uint64_t frame_offset, int64_t *p_timestamp,
2123 if (!p_table || !p_timestamp || !p_buffer_pool)
2130 __func__, frame_offset);
2132 err =
ni_queue_pop(&p_table->
list, frame_offset, p_timestamp, threshold, 0, p_buffer_pool);
2139 "%s: timestamp=%" PRId64
", frame_offset=%" PRId64
", err=%d\n",
2140 __func__, *p_timestamp, frame_offset, err);
2158 if (!p_queue || !name)
2228 "%s: queue overflow, remove oldest entry, count=%u\n",
2229 __func__, p_queue->
count);
2253 int64_t *p_timestamp, int32_t threshold,
2263 if (!p_queue || !p_timestamp)
2293 while (temp && !found)
2295 if (frame_info < temp->frame_info)
2300 *p_timestamp = (int64_t)temp->
timestamp;
2314 temp_prev = temp->
p_prev;
2324 p_queue->
p_last = temp_prev;
2345 p_queue->
name, count);
2359 int64_t *p_timestamp, int32_t threshold,
2369 if (!p_queue || !p_timestamp)
2398 while ((temp) && (!found))
2400 if (llabs((
int)frame_info - (
int)temp->
frame_info) <= threshold)
2402 *p_timestamp = (int64_t)temp->
timestamp;
2411 p_queue->
p_last = temp_prev;
2433 p_queue->
name, count);
2470 temp_next = temp->
p_next;
2477 left, p_queue->
count);
2496 char buff[20] = {0};
2515 struct tm *ltime = NULL;
2516 struct tm temp_time;
2522 (void)strftime(buff, 20,
"%Y-%m-%d %H:%M:%S", ltime);
2552 if (!strcmp(p_str,
"1") || !strcmp(p_str,
"true") || !strcmp(p_str,
"yes"))
2557 if (!strcmp(p_str,
"0") || !strcmp(p_str,
"false") || !strcmp(p_str,
"no"))
2582 if (!str || !out_val || *str ==
'\0')
2586 v = strtol(str, &end, 10);
2588 if (end == str || errno == ERANGE ||
2589 v < INT32_MIN || v > INT32_MAX)
2592 while (*end !=
'\0' && isspace((
unsigned char)*end))
2597 *out_val = (int32_t)v;
2616 if (!str || !out_val || *str ==
'\0')
2620 *out_val = strtod(str, &end);
2622 if (end == str || errno == ERANGE)
2625 while (*end !=
'\0' && isspace((
unsigned char)*end))
2636 int32_t v = (int32_t)strtol(p_str, &end, 0);
2638 if (end == p_str || *end !=
'\0')
2656 double v = strtod(p_str, &end);
2658 if (end == p_str || *end !=
'\0')
2676 for (i = 0; names[i]; i++)
2678 if (!strcmp(arg, names[i]))
2698 return (tv.tv_sec * 1000000LL + tv.tv_usec);
2704 LARGE_INTEGER frequency;
2705 LARGE_INTEGER count;
2706 uint64_t time_sec, time_nsec;
2709 QueryPerformanceFrequency(&frequency);
2711 QueryPerformanceCounter(&count);
2713 time_sec = count.QuadPart / frequency.QuadPart;
2714 time_nsec = (count.QuadPart - time_sec * frequency.QuadPart) *
2715 1000000000LL / frequency.QuadPart;
2717 return (time_sec * 1000000000LL + time_nsec);
2721 clock_gettime(CLOCK_MONOTONIC, &ts);
2723 clock_gettime(CLOCK_REALTIME, &ts);
2725 return ts.tv_sec * 1000000000LL + ts.tv_nsec;
2755 plane_stride[0] = ((
NI_MIN_WIDTH * factor + 127) / 128) * 128;
2757 (((
NI_MIN_WIDTH / (is_semiplanar ? 1 : 2) * factor) + 127) /
2760 plane_stride[2] = (is_semiplanar ? 0 : plane_stride[1]);
2763 width = ((width + 1) / 2) * 2;
2764 plane_stride[0] = ((width * factor + 127) / 128) * 128;
2766 (((width / (is_semiplanar ? 1 : 2) * factor) + 127) / 128) *
2768 plane_stride[2] = (is_semiplanar ? 0 : plane_stride[1]);
2777 plane_height[0] = ((height + 1) / 2) * 2;
2779 plane_height[1] = plane_height[2] = plane_height[0] / 2;
2804 plane_height[0] = ((height + 1) / 2) * 2;
2805 plane_height[1] = plane_height[2] = plane_height[0] / 2;
2813 plane_stride[2] = plane_stride[1];
2814 plane_stride[3] = 0;
2820 plane_stride[2] = plane_stride[1];
2821 plane_stride[3] = 0;
2826 plane_stride[1] = plane_stride[0];
2827 plane_stride[2] = 0;
2828 plane_stride[3] = 0;
2833 plane_stride[1] = plane_stride[0];
2834 plane_stride[2] = 0;
2835 plane_stride[3] = 0;
2841 plane_stride[1] = 0;
2842 plane_stride[2] = 0;
2843 plane_stride[3] = 0;
2848 plane_stride[1] = plane_stride[0];
2849 plane_stride[2] = 0;
2850 plane_stride[3] = 0;
2858 plane_height[1] = plane_height[2] = 0;
2861 plane_stride[1] = 0;
2862 plane_stride[2] = 0;
2863 plane_stride[3] = 0;
2904 width = ((width + 1) / 2) * 2;
2910 "%s dst_stride %d/%d/%d height %d/%d/%d pix_fmt %d\n",
2911 __func__, plane_stride[0], plane_stride[1], plane_stride[2],
2912 plane_height[0], plane_height[1], plane_height[2], pix_fmt);
2938 int frame_width,
int frame_height,
int factor,
2939 int is_semiplanar,
int conf_win_right,
2953 if (p_dst[i] == p_src[i])
2960 (src_height[i] < dst_height[i] ? src_height[i] : dst_height[i]);
2961 uint8_t *dst = p_dst[i];
2962 const uint8_t *src = (
const uint8_t *)p_src[i];
2967 if (0 == i || is_semiplanar)
2969 pad_len_bytes = dst_stride[i] - frame_width * factor;
2974 pad_len_bytes = dst_stride[i] - frame_width / 2 * factor;
2977 if (0 == pad_len_bytes && conf_win_right > 0)
2981 pad_len_bytes = conf_win_right * factor;
2986 pad_len_bytes = conf_win_right * factor / 2;
2991 "%s plane %d stride padding: %d pixel (%d bytes), copy height: "
2993 __func__, i, pad_len_bytes / factor, pad_len_bytes,
2996 for (; height > 0; height--)
2999 (src_stride[i] < dst_stride[i] ? src_stride[i] : dst_stride[i]));
3000 dst += dst_stride[i];
3010 uint8_t *tmp_dst = dst - pad_len_bytes;
3011 for (j = 0; j < pad_len_bytes / factor; j++)
3013 memcpy(tmp_dst, dst - pad_len_bytes - factor, factor);
3019 memset(dst - pad_len_bytes, *(dst - pad_len_bytes - 1),
3023 src += src_stride[i];
3027 int padding_height = dst_height[i] - src_height[i];
3028 if (padding_height > 0)
3032 src = dst - dst_stride[i];
3033 for (; padding_height > 0; padding_height--)
3035 memcpy(dst, src, dst_stride[i]);
3036 dst += dst_stride[i];
3062 int frame_width,
int frame_height,
int factor,
3063 int is_semiplanar,
int conf_win_right,
3070 "%s dst_stride %d/%d/%d src_stride %d/%d/%d dst_height "
3071 "%d/%d/%d src_height %d/%d/%d\n",
3072 __func__, dst_stride[0], dst_stride[1], dst_stride[2], src_stride[0],
3073 src_stride[1], src_stride[2], dst_height[0], dst_height[1],
3074 dst_height[2], src_height[0], src_height[1], src_height[2]);
3081 is_semiplanar, conf_win_right, dst_stride,
3082 dst_height, src_stride, src_height, i);
3108 int frame_width,
int frame_height,
3117 "%s frame_width %d frame_height %d factor %d conf_win_right %d "
3118 "dst_stride %d/%d/%d src_stride %d/%d/%d dst_height "
3119 "%d/%d/%d src_height %d/%d/%d pix_fmt %d\n",
3120 __func__, frame_width, frame_height, factor, conf_win_right,
3121 dst_stride[0], dst_stride[1], dst_stride[2], src_stride[0],
3122 src_stride[1], src_stride[2], dst_height[0], dst_height[1],
3123 dst_height[2], src_height[0], src_height[1], src_height[2],
3127 int is_semiplanar = 0;
3147 frame_width, frame_height, 4,
3148 is_semiplanar, conf_win_right,
3149 dst_stride, dst_height,
3150 src_stride, src_height,
3156 is_semiplanar, conf_win_right, dst_stride,
3157 dst_height, src_stride, src_height);
3189 int frame_width,
int frame_height,
3190 int factor,
int mode)
3193 int y_444p_linesize = frame_width * factor;
3194 int uv_444p_linesize = y_444p_linesize;
3199 if (p_dst0[0] == p_dst1[0] && p_dst0[1] == p_dst1[1] &&
3200 p_dst0[2] == p_dst1[2])
3207 for (i = 0; i < frame_height; i++)
3209 memcpy(&p_dst0[0][(ptrdiff_t)i * y_420p_linesize], &p_src[0][(ptrdiff_t)i * y_444p_linesize],
3218 for (i = 0; i < frame_height; i++)
3220 memcpy(&p_dst1[0][(ptrdiff_t)i * y_420p_linesize],
3221 &p_src[1][(ptrdiff_t)i * y_444p_linesize], y_444p_linesize);
3224 for (i = 0; i < frame_height / 2; i++)
3226 for (j = 0; j < frame_width * factor / 2; j += factor)
3230 memcpy(&p_dst0[1][i * uv_420p_linesize + j],
3231 &p_src[2][2 * i * uv_444p_linesize + 2 * j],
3233 memcpy(&p_dst0[2][i * uv_420p_linesize + j],
3234 &p_src[2][2 * i * uv_444p_linesize + (2 * j + factor)],
3237 memcpy(&p_dst1[1][i * uv_420p_linesize + j],
3238 &p_src[2][(2 * i + 1) * uv_444p_linesize + 2 * j],
3240 memcpy(&p_dst1[2][i * uv_420p_linesize + j],
3241 &p_src[2][(2 * i + 1) * uv_444p_linesize + (2 * j + factor)],
3249 for (i = 0; i < frame_height / 2; i++)
3251 for (j = 0; j < frame_width * factor / 2; j += factor)
3255 memcpy(&p_dst1[1][i * uv_420p_linesize + j],
3256 &p_src[1][2 * i * uv_444p_linesize + (2 * j + factor)],
3259 memcpy(&p_dst1[0][2 * i * uv_444p_linesize + 2 * j],
3260 &p_src[1][(2 * i + 1) * uv_444p_linesize + 2 * j],
3261 (ptrdiff_t)factor * 2);
3263 memcpy(&p_dst0[1][i * uv_420p_linesize + j],
3264 &p_src[1][2 * i * uv_444p_linesize + 2 * j],
3269 memcpy(&p_dst1[2][i * uv_420p_linesize + j],
3270 &p_src[2][2 * i * uv_444p_linesize + (2 * j + factor)],
3273 memcpy(&p_dst1[0][(2 * i + 1) * uv_444p_linesize + 2 * j],
3274 &p_src[2][(2 * i + 1) * uv_444p_linesize + 2 * j],
3275 (ptrdiff_t)factor * 2);
3277 memcpy(&p_dst0[2][i * uv_420p_linesize + j],
3278 &p_src[2][2 * i * uv_444p_linesize + 2 * j],
3301 int insert_bytes = 0;
3302 uint8_t *buf_curr = buf;
3303 uint8_t *buf_end = buf + size - 1;
3304 int zeros = 0, insert_ep3_byte;
3308 for (; buf_curr <= buf_end; buf_curr++)
3312 insert_ep3_byte = (*buf_curr <= 3);
3313 if (insert_ep3_byte)
3316 memmove(buf_curr + 1, buf_curr, buf_end - buf_curr + 1);
3337 return insert_bytes;
3354 int remove_bytes = 0;
3355 uint8_t *buf_curr = buf;
3356 uint8_t *buf_end = buf + size - 1;
3357 int zeros = 0, remove_ep3_byte;
3361 for (; buf_curr < buf_end; buf_curr++)
3365 remove_ep3_byte = (*buf_curr == 0x03 && *(buf_curr + 1) <= 3);
3366 if (remove_ep3_byte)
3369 memmove(buf_curr, buf_curr + 1, buf_end - buf_curr);
3389 return remove_bytes;
3397static uint32_t ni_ai_type_get_bytes(
const uint32_t type)
3423static void ni_ai_integer_convert(
const void *src,
void *dest,
3427 unsigned char all_zeros[] = {0x00, 0x00, 0x00, 0x00,
3428 0x00, 0x00, 0x00, 0x00};
3429 unsigned char all_ones[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3430 uint32_t src_sz = ni_ai_type_get_bytes(src_dtype);
3431 uint32_t dest_sz = ni_ai_type_get_bytes(dst_dtype);
3432 unsigned char *buffer = all_zeros;
3434 if (((int8_t *)src)[src_sz - 1] & 0x80)
3438 memcpy(buffer, src, src_sz);
3439 memcpy(dest, buffer, dest_sz);
3442static float ni_ai_int8_to_fp32(
signed char val,
signed char fixedPointPos)
3444 float result = 0.0f;
3446 if (fixedPointPos > 0)
3448 result = (float)val * (1.0f / ((
float)(1 << fixedPointPos)));
3451 result = (float)val * ((
float)(1 << -fixedPointPos));
3457static float ni_ai_int16_to_fp32(int16_t val,
signed char fixedPointPos)
3459 float result = 0.0f;
3461 if (fixedPointPos > 0)
3463 result = (float)val * (1.0f / ((
float)(1 << fixedPointPos)));
3466 result = (float)val * ((
float)(1 << -fixedPointPos));
3472static float ni_ai_uint8_to_fp32(uint8_t val, int32_t zeroPoint,
float scale)
3474 float result = 0.0f;
3476 result = (float)(val - (uint8_t)zeroPoint) * scale;
3481static float ni_ai_fp16_to_fp32(
const short in)
3489 const _fp32_t magic = {(254 - 15) << 23};
3490 const _fp32_t infnan = {(127 + 16) << 23};
3493 o.u = (in & 0x7fff) << 13;
3495 if (o.f >= infnan.f)
3500 o.u |= (in & 0x8000) << 16;
3504static float ni_ai_affine_to_fp32(int32_t val, int32_t zeroPoint,
float scale)
3506 float result = 0.0f;
3507 result = ((float)val - (
float)zeroPoint) * scale;
3511static uint32_t ni_ai_get_tensor_size(int32_t *shape, uint32_t dim_num,
3517 if (NULL == shape || 0 == dim_num)
3522 for (i = 0; i < dim_num; i++)
3526 sz *= ni_ai_type_get_bytes(type);
3531static uint32_t ni_ai_get_element_num(int32_t *sizes, uint32_t num_of_dims,
3532 int32_t data_format)
3538 sz = ni_ai_get_tensor_size(sizes, num_of_dims, data_format);
3539 dsize = ni_ai_type_get_bytes(data_format);
3542 num = (uint32_t)(sz / dsize);
3551static int32_t ni_ai_type_is_integer(
const int32_t type)
3571static int32_t ni_ai_type_is_signed(
const int32_t type)
3591static void ni_ai_type_get_range(int32_t type,
double *max_range,
3598 bits = (int32_t)(ni_ai_type_get_bytes(type) * 8);
3599 if (ni_ai_type_is_integer(type))
3601 if (ni_ai_type_is_signed(type))
3603 from = (double)(-(1L << (bits - 1)));
3604 to = (double)((1UL << (bits - 1)) - 1);
3608 to = (double)((1UL << bits) - 1);
3611 if (NULL != max_range)
3615 if (NULL != min_range)
3621static inline double ni_abs(
double x)
3623 return x < 0 ? -x : x;
3626static double ni_ai_copy_sign(
double number,
double sign)
3628 double value = ni_abs(number);
3629 return (sign > 0) ? value : (-value);
3632static inline int ni_ai_math_floorf(
double x)
3634 return x >= 0 ? (int)x : (int)x - 1;
3637static double ni_ai_rint(
double x)
3639#define NI_AI_EPSILON 1e-8
3645 decimal = x - intpart;
3646 inter = (double)intpart;
3650 inter += (int32_t)(inter) % 2;
3653 return ni_ai_copy_sign(ni_ai_math_floorf(ni_abs(x) + 0.5f), x);
3659static int32_t ni_ai_fp32_to_dfp(
const float in,
const signed char fl,
3665 ni_ai_type_get_range(type, &max_range, &min_range);
3668 data = (int32_t)ni_ai_rint(in * (
float)(1 << fl));
3671 data = (int32_t)ni_ai_rint(in * (1.0f / (
float)(1 << -fl)));
3673 data = ni_min(data, (int32_t)max_range);
3674 data = ni_max(data, (int32_t)min_range);
3679static int32_t ni_ai_fp32_to_affine(
const float in,
const float scale,
3680 const int zero_point,
const int32_t type)
3685 ni_ai_type_get_range(type, &max_range, &min_range);
3686 data = (int32_t)(ni_ai_rint(in / scale) + zero_point);
3687 data = ni_max((int32_t)min_range, ni_min((int32_t)max_range, data));
3691static unsigned short ni_ai_fp32_to_bfp16_rtne(
float in)
3699 memcpy(&fp32, &in,
sizeof(uint32_t));
3703 uint32_t rounding_bias = 0x7fff + lsb;
3705 if ((
float)0x7FC00000 == in)
3710 fp32 += rounding_bias;
3711 out = (
unsigned short)(fp32 >> 16);
3717static unsigned short ni_ai_fp32_to_fp16(
float in)
3725 memcpy((uint8_t *)&fp32, (uint8_t *)&in,
sizeof(uint32_t));
3727 t1 = (fp32 & 0x80000000u) >> 16;
3728 t2 = (fp32 & 0x7F800000u) >> 13;
3729 t3 = (fp32 & 0x007FE000u) >> 13;
3731 if (t2 >= 0x023c00u)
3734 }
else if (t2 <= 0x01c000u)
3740 fp16 = t1 | t2 | t3;
3743 return (
unsigned short)fp16;
3746static void ni_ai_float32_to_dtype(
float src,
unsigned char *dst,
3747 const int32_t data_type,
3748 const int32_t quant_format,
3749 signed char fixed_point_pos,
float tf_scale,
3755 memcpy(dst, &src,
sizeof(
float));
3758 *(int16_t *)dst = (int16_t)ni_ai_fp32_to_fp16(src);
3761 *(int16_t *)dst = (int16_t)ni_ai_fp32_to_bfp16_rtne(src);
3767 int32_t dst_value = 0;
3768 switch (quant_format)
3772 ni_ai_fp32_to_dfp(src, fixed_point_pos, data_type);
3775 dst_value = ni_ai_fp32_to_affine(src, tf_scale, tf_zerop,
3779 dst_value = (int32_t)src;
3801 if (!p_network || !dst || dst_len == 0 || !p_packet || !p_packet->
p_data)
3825static int open_tensor_rsrc_file(
struct tensor_rsrc *rsrc,
void *data,
3830 ni_fopen(&f, (
const char *)data,
"r");
3832 return rsrc->
private ? 0 : -1;
3835static int get_tensor_rsrc_from_file(
struct tensor_rsrc *rsrc,
float *value)
3837 FILE *fp = (FILE *)rsrc->
private;
3849static void close_tensor_rsrc_file(
struct tensor_rsrc *rsrc)
3851 FILE *fp = (FILE *)rsrc->
private;
3855static int open_tensor_rsrc_rawdata(
struct tensor_rsrc *rsrc,
void *data,
3864static int get_tensor_rsrc_from_rawdata(
struct tensor_rsrc *rsrc,
float *value)
3866 float *tensors = (
float *)rsrc->
private;
3868 if (rsrc->next_idx < rsrc->total_num)
3870 *value = tensors[rsrc->next_idx];
3878static void close_tensor_rsrc_rawdata(
struct tensor_rsrc *rsrc)
3883 uint8_t *dst, uint32_t dst_len,
void *tensor, uint32_t src_len,
3885 int (*open_tensor_rsrc)(
struct tensor_rsrc *,
void *, uint32_t),
3886 int (*get_tensor_rsrc)(
struct tensor_rsrc *,
float *),
3889 uint8_t *tensor_data;
3893 int32_t data_format;
3894 int32_t quant_format;
3895 int32_t fixed_point_pos;
3906 sz = ni_ai_get_element_num((int32_t *)p_param->
sizes, p_param->
num_of_dims,
3908 stride = ni_ai_type_get_bytes(data_format);
3910 if ((
size_t)sz * stride *
sizeof(uint8_t) != dst_len)
3921 if (open_tensor_rsrc(rsrc, tensor, src_len) != 0)
3927 memset(dst, 0, (
size_t)sz * stride *
sizeof(uint8_t));
3929 for (i = 0; i < sz; i++)
3931 if (get_tensor_rsrc(rsrc, &fval) == 0)
3933 ni_ai_float32_to_dtype(fval, &tensor_data[(ptrdiff_t)stride * i], data_format,
3934 quant_format, (int8_t)fixed_point_pos, tf_scale,
3942 close_tensor_rsrc(rsrc);
3948 const char *tensor_file,
3951 return ni_network_tensor_to_data(
3952 dst, dst_len, (
void *)tensor_file, 0, p_param, open_tensor_rsrc_file,
3953 get_tensor_rsrc_from_file, close_tensor_rsrc_file);
3961 return ni_network_tensor_to_data(
3962 dst, dst_len, src, src_len, p_param, open_tensor_rsrc_rawdata,
3963 get_tensor_rsrc_from_rawdata, close_tensor_rsrc_rawdata);
3974 float *dst_float = dst;
3977 if (!src || src_len == 0 || !dst || dst_len == 0 || !p_param)
3982 type_size = ni_ai_type_get_bytes(p_param->
data_format);
3989 ele_size *= p_param->
sizes[i];
3992 if (dst_len != ele_size *
sizeof(
float))
4010 for (i = 0; i < ele_size; i++, data += type_size)
4012 dst_float[i] = ni_ai_int8_to_fp32((int8_t)*data, (int8_t)fix_pos);
4019 for (i = 0; i < ele_size; i++, data += type_size)
4021 int32_t src_value = 0;
4022 ni_ai_integer_convert(data, &src_value,
4026 ni_ai_affine_to_fp32(src_value, zero_point, scale);
4030 for (i = 0; i < ele_size; i++, data += type_size)
4032 void *float_data = (
void *)data;
4033 dst_float[i] = *((
float *)float_data);
4038 for (i = 0; i < ele_size; i++, data += type_size)
4040 dst_float[i] = ni_ai_fp16_to_fp32(*((
short *)data));
4047 for (i = 0; i < ele_size; i++, data += type_size)
4049 dst_float[i] = ni_ai_uint8_to_fp32(*data, zero_point, scale);
4055 for (i = 0; i < ele_size; i++, data += type_size)
4057 dst_float[i] = ni_ai_int16_to_fp32(*((
short *)data), (int8_t)fix_pos);
4061 for (i = 0; i < ele_size; i++, data += type_size)
4063 void *float_data = (
void *)data;
4064 dst_float[i] = *((
float *)float_data);
4076 return ni_ai_get_tensor_size((int32_t *)p_param->
sizes,
4082 uint32_t i, dims = 1;
4086 dims *= p_param->
sizes[i];
4094#define SHA256_BLOCK_SIZE 32
4104#define ROTLEFT(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
4105#define ROTRIGHT(a, b) (((a) >> (b)) | ((a) << (32 - (b))))
4107#define CH(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
4108#define MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
4109#define EP0(x) (ROTRIGHT(x, 2) ^ ROTRIGHT(x, 13) ^ ROTRIGHT(x, 22))
4110#define EP1(x) (ROTRIGHT(x, 6) ^ ROTRIGHT(x, 11) ^ ROTRIGHT(x, 25))
4111#define SIG0(x) (ROTRIGHT(x, 7) ^ ROTRIGHT(x, 18) ^ ((x) >> 3))
4112#define SIG1(x) (ROTRIGHT(x, 17) ^ ROTRIGHT(x, 19) ^ ((x) >> 10))
4114static const uint32_t ui32k[64] = {
4115 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
4116 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
4117 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
4118 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
4119 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
4120 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
4121 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
4122 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
4123 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
4124 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
4125 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
4129 uint32_t ui32a, ui32b, ui32c, ui32d, ui32e, ui32f, ui32g, ui32h, ui32i,
4130 ui32j, ui32t1, ui32t2, ui32m[64];
4132 for (ui32i = 0, ui32j = 0; ui32i < 16; ++ui32i, ui32j += 4)
4133 ui32m[ui32i] = (aui8Data[ui32j] << 24) | (aui8Data[ui32j + 1] << 16) |
4134 (aui8Data[ui32j + 2] << 8) | (aui8Data[ui32j + 3]);
4135 for (; ui32i < 64; ++ui32i)
4136 ui32m[ui32i] =
SIG1(ui32m[ui32i - 2]) + ui32m[ui32i - 7] +
4137 SIG0(ui32m[ui32i - 15]) + ui32m[ui32i - 16];
4148 for (ui32i = 0; ui32i < 64; ++ui32i)
4150 ui32t1 = ui32h +
EP1(ui32e) +
CH(ui32e, ui32f, ui32g) + ui32k[ui32i] +
4152 ui32t2 =
EP0(ui32a) +
MAJ(ui32a, ui32b, ui32c);
4156 ui32e = ui32d + ui32t1;
4160 ui32a = ui32t1 + ui32t2;
4192 for (ui32i = 0; ui32i < ui32Length; ++ui32i)
4240 for (ui32i = 0; ui32i < 4; ++ui32i)
4243 (psCtx->
aui32State[0] >> (24 - ui32i * 8)) & 0x000000ff;
4244 aui8Hash[ui32i + 4] =
4245 (psCtx->
aui32State[1] >> (24 - ui32i * 8)) & 0x000000ff;
4246 aui8Hash[ui32i + 8] =
4247 (psCtx->
aui32State[2] >> (24 - ui32i * 8)) & 0x000000ff;
4248 aui8Hash[ui32i + 12] =
4249 (psCtx->
aui32State[3] >> (24 - ui32i * 8)) & 0x000000ff;
4250 aui8Hash[ui32i + 16] =
4251 (psCtx->
aui32State[4] >> (24 - ui32i * 8)) & 0x000000ff;
4252 aui8Hash[ui32i + 20] =
4253 (psCtx->
aui32State[5] >> (24 - ui32i * 8)) & 0x000000ff;
4254 aui8Hash[ui32i + 24] =
4255 (psCtx->
aui32State[6] >> (24 - ui32i * 8)) & 0x000000ff;
4256 aui8Hash[ui32i + 28] =
4257 (psCtx->
aui32State[7] >> (24 - ui32i * 8)) & 0x000000ff;
4291 if (p_dst[0] == p_src[0] && p_dst[1] == p_src[1] && p_dst[2] == p_src[2] &&
4292 p_dst[3] == p_src[3])
4314 return libxcoder_api_ver;
4317#ifndef DEPRECATION_AS_ERROR
4326 static char compat_fw_api_ver_str[5] =
"";
4328 if (!compat_fw_api_ver_str[0])
4330 compat_fw_api_ver_str[0] = \
4332 compat_fw_api_ver_str[1] =
'.';
4333 compat_fw_api_ver_str[2] = \
4336 compat_fw_api_ver_str[3] = \
4339 compat_fw_api_ver_str[3] = 0;
4340 compat_fw_api_ver_str[4] = 0;
4342 return &compat_fw_api_ver_str[0];
4359 if (!ver_str || !fmt_str) {
4363 fmt_str[0] = ver_str[0];
4365 fmt_str[2] = ver_str[1];
4367 if ((ver_str[0] <
'6' || (ver_str[0] ==
'6' && ver_str[1] <=
'q')) ||
4368 (ver_str[2] == 0)) {
4371 fmt_str[3] = ver_str[2];
4393 if (ver1[index] > ver2[index])
4395 else if (ver1[index] < ver2[index])
4400 if (ver1[index] > ver2[index])
4402 else if (ver1[index] < ver2[index])
4405 if ((ver1[index - 1] <
'6') || ((ver1[index - 1] ==
'6') && (ver1[index] <=
'q')))
4410 if (ver1[index] > ver2[index])
4412 else if (ver1[index] < ver2[index])
4425 static char release_ver_str[6] =
"";
4427 if (!release_ver_str[0])
4430 release_ver_str[1] =
'.';
4432 release_ver_str[3] =
'.';
4434 release_ver_str[5] = 0;
4436 return &release_ver_str[0];
4450 if (rc == ni_err_rc_description[i].rc)
4452 return ni_err_rc_description[i].
txt;
4455 return "rc not supported";
4470 if (!p_str || !key || !value)
4475 char *p = strchr(p_str,
'=');
4484 int64_t key_len = p - p_str;
4505 char key[64], value[64];
4506 char *curr = xcoderParams, *colon_pos;
4511 colon_pos = strchr(curr,
':');
4518 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4522 "Error: xcoder-params p_config key/value not "
4551 curr = colon_pos + 1;
4554 curr += strlen(curr);
4580 char key[64], value[64];
4581 char *curr = xcoderGop, *colon_pos;
4586 colon_pos = strchr(curr,
':');
4593 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4597 "Error: xcoder-params p_config key/value not "
4626 curr = colon_pos + 1;
4629 curr += strlen(curr);
4650 char key[64], value[64];
4651 char *curr = xcoderParams, *colon_pos;
4656 colon_pos = strchr(curr,
':');
4663 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4667 "Error: decoder-params p_config key/value not "
4696 curr = colon_pos + 1;
4699 curr += strlen(curr);
4721 rc = InitializeCriticalSectionEx(mutex, 0, CRITICAL_SECTION_NO_DEBUG_INFO);
4732 ni_pthread_mutexattr_t attr;
4734 rc = pthread_mutexattr_init(&attr);
4740 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
4742 return pthread_mutex_init(mutex, &attr);
4757 DeleteCriticalSection(mutex);
4760 return pthread_mutex_destroy(mutex);
4778 EnterCriticalSection(mutex);
4780 rc = pthread_mutex_lock(mutex);
4804 LeaveCriticalSection(mutex);
4806 rc = pthread_mutex_unlock(mutex);
4817static unsigned __stdcall __thread_worker(
void *arg)
4819 ni_pthread_t *t = (ni_pthread_t *)arg;
4820 t->rc = t->start_routine(t->arg);
4837 void *(*start_routine)(
void *),
void *arg)
4840 thread->start_routine = start_routine;
4844 (
void *)CreateThread(NULL, 0, win32thread_worker, thread, 0, NULL);
4846 (
void *)_beginthreadex(NULL, 0, __thread_worker, thread, 0, NULL);
4848 return !thread->handle;
4850 return pthread_create(thread, attr, start_routine, arg);
4866 DWORD rc = WaitForSingleObject(thread.handle, INFINITE);
4867 if (rc != WAIT_OBJECT_0)
4869 if (rc == WAIT_ABANDONED)
4875 *value_ptr = thread.rc;
4876 CloseHandle(thread.handle);
4879 return pthread_join(thread, value_ptr);
4893 const ni_pthread_condattr_t *attr)
4896 InitializeConditionVariable(cond);
4899 return pthread_cond_init(cond, attr);
4917 return pthread_cond_destroy(cond);
4932 WakeAllConditionVariable(cond);
4935 return pthread_cond_broadcast(cond);
4951 SleepConditionVariableCS(cond, mutex, INFINITE);
4954 return pthread_cond_wait(cond, mutex);
4969 WakeConditionVariable(cond);
4972 return pthread_cond_signal(cond);
4987 ni_pthread_mutex_t *mutex,
4988 const struct timespec *abstime)
4991 int64_t abs_ns = abstime->tv_sec * 1000000000LL + abstime->tv_nsec;
4994 if (!SleepConditionVariableCS(cond, mutex, t))
4996 DWORD err = GetLastError();
4997 if (err == ERROR_TIMEOUT)
5004 return pthread_cond_timedwait(cond, mutex, abstime);
5025 return pthread_sigmask(how, set, oldset);
5043 return "General Error";
5045 return "Not Initialized";
5047 return "Already Initialized";
5051 return "Resource Not Available";
5053 return "Create Network Failed";
5055 return "Input Buffer Full";
5057 return "Output Buffer Empty";
5059 return "Invalid Params";
5061 return "Error Start Network";
5063 return "Erorr Set Inout";
5065 return "Bad Option";
5069 return "Context Not Available";
5071 return "Model Not Found";
5075 return "Invalid Address";
5077 return "Out Of Memory";
5081 return "Invalid Instance";
5083 return "IO Not Allowed";
5085 return "Network Not Ready";
5087 return "Other Error";
5102 float current_ma,voltage_mv;
5109 (void)snprintf(pcb_config,
sizeof(pcb_config),
"%.2s", &serial_number[2]);
5111 float current_value = (float)current_data;
5112 voltage_mv = 12000.0f;
5113 if (strncmp(pcb_config,
"A1", 2) == 0)
5117 else if ((strncmp(pcb_config,
"A2", 2) == 0) || (strncmp(pcb_config,
"A3", 2) == 0))
5121 else if ((strncmp(pcb_config,
"AA", 2) == 0) || (strncmp(pcb_config,
"AB", 2) == 0))
5125 else if (strncmp(pcb_config,
"U0", 2) == 0)
5130 else if ((strncmp(pcb_config,
"U1", 2) == 0) || (strncmp(pcb_config,
"U2", 2) == 0) || (strncmp(pcb_config,
"U3", 2) == 0))
5134 else if (strncmp(pcb_config,
"UA", 2) == 0)
5138 else if (strncmp(pcb_config,
"S0", 2) == 0)
5142 else if ((strncmp(pcb_config,
"M0", 2) == 0) || (strncmp(pcb_config,
"M1", 2) == 0))
5145 voltage_mv = 3300.0f;
5147 else if (strncmp(pcb_config,
"M", 1) == 0)
5150 voltage_mv = 3300.0f;
5156 power_mw = (uint32_t)((voltage_mv * current_ma) / 1000.0);
5179static int ni_device_size_precheck_ioctl(
const char *p_dev,
const uint64_t size_needed)
5181#if defined(_WIN32) || !defined(BLKGETSIZE64)
5196 fd = open(p_dev, O_RDONLY);
5203 call_ret = ioctl(fd, BLKGETSIZE64, &bytes);
5208 else if (bytes < size_needed)
5240static int ni_device_vendor_id_precheck(
const char *p_dev)
5254 const char *vendor_path_devs[] = {
"/sys/class/block/%s/device/vendor",
"/sys/class/block/%s/device/device/vendor"};
5256 const char *last_slash = strrchr(p_dev,
'/');
5257 const char *device_name = (last_slash ? (last_slash + 1) : p_dev);
5259 const size_t path_len = strlen(p_dev);
5261 for (
size_t i = 0; i <
sizeof(vendor_path_devs)/
sizeof(vendor_path_devs[0]); ++i)
5263 size_t template_len = strlen(vendor_path_devs[i]);
5264 char *vendor_path = (
char *)calloc(1, template_len + path_len);
5269 (void)snprintf(vendor_path, template_len + path_len, vendor_path_devs[i], device_name);
5271 int fd = open(vendor_path, O_RDONLY);
5274 char vendor_id[10] = {0};
5275 ssize_t read_size = read(fd, vendor_id,
sizeof(vendor_id));
5276 if (read_size >= 4 && (
size_t)read_size <
sizeof(vendor_id))
5278 char *find_1d82 = strstr(vendor_id,
"1d82");
5285 ni_log2(NULL,
NI_LOG_DEBUG,
"%s() vendor check failed. vendor id: %s", __func__, vendor_id);
5327static int ni_device_size_precheck_system_information(
const char *p_dev,
const uint64_t size_needed)
5342 const char block_path_dev[] =
"/sys/class/block/%s/size";
5343 const char logical_block_size_path_dev[] =
"/sys/class/block/%s/queue/logical_block_size";
5345 const char *last_slash = strrchr(p_dev,
'/');
5346 const char *device_name = (last_slash ? (last_slash + 1) : p_dev);
5348 const size_t path_len = strlen(p_dev);
5351 int logical_block_fd = -1;
5353 char *block_path = (
char *)calloc(1,
sizeof(block_path_dev) + path_len);
5354 char *logical_block_size_path = (
char *)calloc(1,
sizeof(logical_block_size_path_dev) + path_len);
5356 if (!block_path || !logical_block_size_path)
5361 (void)snprintf(block_path,
sizeof(block_path_dev) + path_len, block_path_dev, device_name);
5362 (void)snprintf(logical_block_size_path,
sizeof(logical_block_size_path_dev) + path_len, logical_block_size_path_dev, device_name);
5364 size_fd = open(block_path, O_RDONLY);
5365 logical_block_fd = open(logical_block_size_path, O_RDONLY);
5367 if (size_fd < 0 || logical_block_fd < 0)
5372 char this_size_str [20] = {0};
5373 char this_block_size_str [20] = {0};
5375 if (read(size_fd, this_size_str,
sizeof(this_size_str)) <= 0 || read(logical_block_fd, this_block_size_str,
sizeof(this_block_size_str)) <= 0)
5381 char *endptr1 = NULL;
5382 char *endptr2 = NULL;
5384 unsigned long long this_size = strtoull(this_size_str, &endptr1, 10);
5385 unsigned long long this_block_size = strtoull(this_block_size_str, &endptr2, 10);
5387 if (errno == 0 && endptr1 != this_size_str && endptr2 != this_block_size_str)
5389 if (this_size * this_block_size >= size_needed)
5395 ni_log2(NULL,
NI_LOG_DEBUG,
"%s() read size check failed. size: %" PRIu64
"\n", __func__, this_size * this_block_size);
5406 if (logical_block_size_path)
5408 free(logical_block_size_path);
5415 if (logical_block_fd >= 0)
5417 close(logical_block_fd);
5454 const size_t path_len = strlen(p_dev);
5461 ret = ni_device_size_precheck_ioctl(p_dev, SIZE_NEEDED);
5471 ret = ni_device_vendor_id_precheck(p_dev);
5481 ret = ni_device_size_precheck_system_information(p_dev, SIZE_NEEDED);
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_XCODER_REVISION
#define LIBXCODER_API_VERSION
#define NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_DEVICE_NAME_LEN
#define ni_assert(expression)
#define NI_MEM_PAGE_ALIGNMENT
#define NI_FW_META_DATA_SZ
@ NI_AI_STATUS_CREATE_NETWORK_FAILED
@ NI_AI_STATUS_IO_NOT_ALLOWED
@ NI_AI_STATUS_NETWORK_NOT_READY
@ NI_AI_STATUS_GENERIC_ERROR
@ NI_AI_STATUS_CONTEXT_NOT_AVAILABLE
@ NI_AI_STATUS_OUT_OF_MEMORY
@ NI_AI_STATUS_INVALID_ADDRESS
@ NI_AI_STATUS_RESOURCE_NOT_AVAILABLE
@ NI_AI_STATUS_ALREADY_INITIALIZED
@ NI_AI_STATUS_MODEL_NOT_FOUND
@ NI_AI_STATUS_INVALID_PARAMS
@ NI_AI_STATUS_NOT_INITIALIZED
@ NI_AI_STATUS_INPUT_BUFFER_FULL
@ NI_AI_STATUS_BAD_OPTION
@ NI_AI_STATUS_ERROR_START_NETWORK
@ NI_AI_STATUS_ERROR_SET_INOUT
@ NI_AI_STATUS_INVALID_INSTANCE
@ NI_AI_STATUS_OUTPUT_BUFFER_EMPTY
@ NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
@ NI_RETCODE_PARAM_ERROR_MX_NUM_MERGE
@ NI_RETCODE_PARAM_ERROR_INTRA_PERIOD
@ NI_RETCODE_PARAM_ERROR_TRATE
@ NI_RETCODE_PARAM_WARNING_DEPRECATED
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_BRATE
@ NI_RETCODE_NVME_SC_STREAM_ERROR
@ NI_RETCODE_PARAM_ERROR_ZERO
@ NI_RETCODE_PARAM_ERROR_HVS_QP_EN
@ NI_RETCODE_PARAM_ERROR_VBV_BUFFER_SIZE
@ NI_RETCODE_PARAM_ERROR_PICSKIP
@ NI_RETCODE_NVME_SC_INTERLACED_NOT_SUPPORTED
@ NI_RETCODE_PARAM_ERROR_HVS_QP_SCL
@ NI_RETCODE_NVME_SC_REQUEST_NOT_COMPLETED
@ NI_RETCODE_PARAM_ERROR_CUSIZE_MODE_8X8_EN
@ NI_RETCODE_PARAM_ERROR_FILLER
@ NI_RETCODE_PARAM_ERROR_CUSIZE_MODE_32X32_EN
@ NI_RETCODE_PARAM_ERROR_RCENABLE
@ NI_RETCODE_PARAM_ERROR_MX_DELTA_QP
@ NI_RETCODE_PARAM_ERROR_LOOK_AHEAD_DEPTH
@ NI_RETCODE_PARAM_ERROR_CONF_WIN_R
@ NI_RETCODE_NVME_SC_RESOURCE_NOT_FOUND
@ NI_RETCODE_ERROR_INVALID_SESSION
@ NI_RETCODE_PARAM_ERROR_CU_SIZE_MODE
@ NI_RETCODE_PARAM_ERROR_CONF_WIN_BOT
@ NI_RETCODE_PARAM_ERROR_MN_QP
@ NI_RETCODE_NVME_SC_INVALID_PARAMETER
@ NI_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_RETCODE_PARAM_ERROR_PIC_WIDTH
@ NI_RETCODE_PARAM_ERROR_CONF_WIN_TOP
@ NI_RETCODE_PARAM_ERROR_CONF_WIN_L
@ NI_RETCODE_PARAM_ERROR_DECODING_REFRESH_TYPE
@ NI_RETCODE_ERROR_UNLOCK_DEVICE
@ NI_RETCODE_PARAM_INVALID_NAME
@ NI_RETCODE_PARAM_ERROR_AREA_TOO_BIG
@ NI_RETCODE_PARAM_ERROR_FRATE
@ NI_RETCODE_NVME_SC_WRITE_BUFFER_FULL
@ NI_RETCODE_PARAM_ERROR_BRATE_LT_TRATE
@ NI_RETCODE_NVME_SC_VPU_RECOVERY
@ NI_RETCODE_ERROR_STREAM_ERROR
@ NI_RETCODE_PARAM_ERROR_HEIGHT_TOO_SMALL
@ NI_RETCODE_ERROR_INVALID_HANDLE
@ NI_RETCODE_PARAM_ERROR_TOO_BIG
@ NI_RETCODE_PARAM_INVALID_VALUE
@ NI_RETCODE_ERROR_RESOURCE_UNAVAILABLE
@ NI_RETCODE_PARAM_ERROR_CU_LVL_RC_EN
@ NI_RETCODE_PARAM_ERROR_INTRA_QP
@ NI_RETCODE_ERROR_EXCEED_MAX_NUM_SESSIONS
@ NI_RETCODE_PARAM_ERROR_MAXNUMMERGE
@ NI_RETCODE_NVME_SC_RESOURCE_IS_EMPTY
@ NI_RETCODE_PARAM_ERROR_DY_MERGE_32X32_EN
@ NI_RETCODE_NVME_SC_RESOURCE_UNAVAILABLE
@ NI_RETCODE_PARAM_ERROR_DY_MERGE_16X16_EN
@ NI_RETCODE_NVME_SC_VPU_GENERAL_ERROR
@ NI_RETCODE_PARAM_ERROR_GOP_PRESET
@ NI_RETCODE_ERROR_INVALID_ALLOCATION_METHOD
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
@ NI_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_RETCODE_PARAM_ERROR_USR_RMD_ENC_PARAM
@ NI_RETCODE_PARAM_ERROR_PIC_HEIGHT
@ NI_RETCODE_NVME_SC_VPU_RSRC_INSUFFICIENT
@ NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_PARAM_ERROR_OOR
@ NI_RETCODE_PARAM_ERROR_CUSIZE_MODE_16X16_EN
@ NI_RETCODE_PARAM_ERROR_DY_MERGE_8X8_EN
@ NI_RETCODE_ERROR_VPU_RECOVERY
@ NI_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
@ NI_RETCODE_PARAM_ERROR_CUSTOM_GOP
@ NI_RETCODE_INVALID_PARAM
@ NI_RETCODE_PARAM_ERROR_TOO_SMALL
@ NI_RETCODE_NVME_SC_REQUEST_IN_PROGRESS
@ NI_RETCODE_ERROR_OPEN_DEVICE
@ NI_RETCODE_PARAM_ERROR_MX_QP
#define NI_XCODER_REVISION_API_MINOR_VER_IDX
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.
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.
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.
#define NI_VPU_ALIGN16(_x)
#define NI_VPU_ALIGN128(_x)
@ NI_AI_BUFFER_QUANTIZE_DYNAMIC_FIXED_POINT
@ NI_AI_BUFFER_QUANTIZE_NONE
@ NI_AI_BUFFER_QUANTIZE_TF_ASYMM
enum _ni_ai_buffer_format_e ni_ai_buffer_format_e
@ NI_AI_BUFFER_FORMAT_INT8
@ NI_AI_BUFFER_FORMAT_FP64
@ NI_AI_BUFFER_FORMAT_FP32
@ NI_AI_BUFFER_FORMAT_UINT16
@ NI_AI_BUFFER_FORMAT_UINT8
@ NI_AI_BUFFER_FORMAT_BFP16
@ NI_AI_BUFFER_FORMAT_FP16
@ NI_AI_BUFFER_FORMAT_INT64
@ NI_AI_BUFFER_FORMAT_UINT32
@ NI_AI_BUFFER_FORMAT_INT32
@ NI_AI_BUFFER_FORMAT_INT16
@ NI_AI_BUFFER_FORMAT_UINT64
#define NI_VPU_ALIGN64(_x)
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,
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Private definitions for interfacing with NETINT video processing devices over NVMe.
#define IDENTIFY_DEVICE_R
#define NI_NVME_IDENTITY_CMD_DATA_SZ
ni_queue_node_t * ni_buffer_pool_get_queue_buffer(ni_queue_buffer_pool_t *p_buffer_pool)
int ni_pthread_cond_init(ni_pthread_cond_t *cond, const ni_pthread_condattr_t *attr)
initialize condition variables
ni_retcode_t ni_timestamp_register(ni_queue_buffer_pool_t *p_buffer_pool, ni_timestamp_table_t *p_table, int64_t timestamp, uint64_t data_info)
Register timestamp in timestamp/frameoffset table.
ni_retcode_t ni_queue_pop(ni_queue_t *p_queue, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
Pop from the xcoder queue.
int ni_pthread_mutex_lock(ni_pthread_mutex_t *mutex)
thread mutex lock
int ni_remove_emulation_prevent_bytes(uint8_t *buf, int size)
Remove emulation prevention byte(s) as needed from the data buffer.
ni_retcode_t ni_queue_pop_threshold(ni_queue_t *p_queue, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
int ni_pthread_cond_destroy(ni_pthread_cond_t *cond)
destroy condition variables
void ni_SHA256Update(SHA256CTX *psCtx, const uint8_t aui8Data[], size_t ui32Length)
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....
void ni_buffer_pool_free(ni_queue_buffer_pool_t *p_buffer_pool)
uint32_t ni_ai_network_layer_dims(ni_network_layer_params_t *p_param)
void ni_dec_fme_buffer_pool_free(ni_buf_pool_t *p_buffer_pool)
int32_t ni_parse_name(const char *arg, const char *const *names, bool *b_error)
Parse name.
ni_retcode_t ni_quadra_card_identify_precheck(const char *p_dev)
precheck a device can be read by ni_device_capability_query() INFO OR ERROR logs will not be printed ...
ni_retcode_t ni_strncpy(char *dest, size_t dmax, const char *src, size_t slen)
void ni_SHA256Transform(SHA256CTX *psCtx, const uint8_t aui8Data[])
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...
ni_retcode_t ni_queue_init(ni_session_context_t *p_ctx, ni_queue_t *p_queue, const char *name)
Initialize xcoder queue.
void ni_SHA256Final(SHA256CTX *psCtx, uint8_t aui8Hash[])
ni_retcode_t ni_queue_print(ni_queue_t *p_queue)
Print xcoder queue info.
ni_queue_node_t * ni_buffer_pool_allocate_buffer(ni_queue_buffer_pool_t *p_buffer_pool)
uint64_t ni_get_utime(void)
Get system time for log.
void ni_copy_plane_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, int is_semiplanar, 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], int i)
Copy RGBA or YUV data to Netint HW frame layout to be sent to encoder for encoding....
int ni_pthread_cond_signal(ni_pthread_cond_t *cond)
signal a condition
int ni_retrieve_xcoder_params(char xcoderParams[], ni_xcoder_params_t *params, ni_session_context_t *ctx)
retrieve encoder config parameter values from –xcoder-params
ni_buf_t * ni_buf_pool_allocate_buffer(ni_buf_pool_t *p_buffer_pool, int buffer_size)
int32_t ni_get_frame_index(uint32_t *value)
Get xcoder instance id.
int ni_posix_memalign(void **memptr, size_t alignment, size_t size)
Allocate aligned memory.
int ni_fscanf(FILE *stream, const char *fmt,...)
int ni_pthread_create(ni_pthread_t *thread, const ni_pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
create a new thread
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 ...
ni_retcode_t ni_strncat(char *dest, size_t dmax, const char *src, size_t slen)
ni_buf_t * ni_buf_pool_get_buffer(ni_buf_pool_t *p_buffer_pool)
void ni_fmt_fw_api_ver_str(const char ver_str[], char fmt_str[])
Get formatted FW API version string from unformatted FW API version string.
const char * ni_ai_errno_to_str(int rc)
return error string according to error code from firmware
int ni_pthread_cond_broadcast(ni_pthread_cond_t *cond)
broadcast a condition
int32_t ni_gettimeofday(struct timeval *p_tp, void *p_tzp)
Get time for logs with microsecond timestamps.
ni_retcode_t ni_strtod_val(const char *str, double *out_val)
Safely convert a decimal string to a double with full validation. Trailing whitespace is tolerated.
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
ni_retcode_t ni_network_convert_tensor_to_data(uint8_t *dst, uint32_t dst_len, float *src, uint32_t src_len, ni_network_layer_params_t *p_param)
int ni_param_get_key_value(char *p_str, char *key, char *value)
retrieve key and value from 'key=value' pair
void ni_calculate_sha256(const uint8_t aui8Data[], size_t ui32DataLength, uint8_t aui8Hash[])
int ni_pthread_mutex_destroy(ni_pthread_mutex_t *mutex)
destory a mutex
int32_t ni_dec_fme_buffer_pool_initialize(ni_session_context_t *p_ctx, int32_t number_of_buffers, int width, int height, int height_align, int factor)
ni_retcode_t ni_timestamp_get_with_threshold(ni_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
void ni_copy_hw_descriptors(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS])
Copy Descriptor data to Netint HW descriptor frame layout to be sent to encoder for encoding....
int32_t ni_atobool(const char *p_str, bool *b_error)
Convert string to boolean.
uint32_t ni_round_up(uint32_t number_to_round, uint32_t multiple)
ni_retcode_t ni_strcat(char *dest, size_t dmax, const char *src)
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....
char * ni_strtok(char *s, const char *delim, char **saveptr)
void ni_SHA256Init(SHA256CTX *psCtx)
ni_retcode_t ni_fopen(FILE **fp, const char *filename, const char *mode)
ni_retcode_t ni_network_layer_convert_output(float *dst, uint32_t dst_len, ni_packet_t *p_packet, ni_network_data_t *p_network, uint32_t layer)
ni_retcode_t ni_queue_push(ni_queue_buffer_pool_t *p_buffer_pool, ni_queue_t *p_queue, uint64_t frame_info, int64_t timestamp)
Push into xcoder queue.
int ni_pthread_sigmask(int how, const ni_sigset_t *set, ni_sigset_t *oldset)
examine and change mask of blocked signals
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
uint32_t ni_ai_network_layer_size(ni_network_layer_params_t *p_param)
struct ni_err_rc_txt_entry ni_err_rc_txt_entry_t
const char * ni_get_rc_txt(ni_retcode_t rc)
Get text string for the provided error.
ni_retcode_t ni_timestamp_get(ni_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frameoffset info.
ni_buf_t * ni_buf_pool_expand(ni_buf_pool_t *pool)
int ni_pthread_cond_timedwait(ni_pthread_cond_t *cond, ni_pthread_mutex_t *mutex, const struct timespec *abstime)
wait on a condition
int32_t ni_atoi(const char *p_str, bool *b_error)
ni_retcode_t ni_timestamp_init(ni_session_context_t *p_ctx, ni_timestamp_table_t **pp_table, const char *name)
Initialize timestamp handling.
int ni_retrieve_decoder_params(char xcoderParams[], ni_xcoder_params_t *params, ni_session_context_t *ctx)
retrieve decoder config parameter values from –decoder-params
int32_t ni_buffer_pool_initialize(ni_session_context_t *p_ctx, int32_t number_of_buffers)
int ni_retrieve_xcoder_gop(char xcoderGop[], ni_xcoder_params_t *params, ni_session_context_t *ctx)
Retrieve custom gop config values from –xcoder-gop.
void ni_usleep(int64_t usec)
struct tm * ni_localtime(struct tm *dest, const time_t *src)
ni_retcode_t ni_find_blk_name(const char *p_dev, char *p_out_buf, int out_buf_len)
Find NVMe name space block from device name If none is found, assume nvme multi-pathing is disabled a...
int ni_vsprintf(char *dest, const size_t dmax, const char *fmt, va_list args)
char * ni_get_libxcoder_api_ver(void)
Get libxcoder API version.
void ni_buf_pool_return_buffer(ni_buf_t *buf, ni_buf_pool_t *p_buffer_pool)
double ni_atof(const char *p_str, bool *b_error)
Convert string to floating.
ni_retcode_t ni_queue_free(ni_queue_t *p_queue, ni_queue_buffer_pool_t *p_buffer_pool)
Free xcoder queue.
NI_DEPRECATED char * ni_get_compat_fw_api_ver(void)
Get FW API version libxcoder is compatible with. Deprecated in favour of ni_fmt_fw_api_ver_str(&NI_XC...
uint64_t ni_gettime_ns(void)
void ni_timestamp_scan_cleanup(ni_timestamp_table_t *pts_list, ni_timestamp_table_t *dts_list, ni_queue_buffer_pool_t *p_buffer_pool)
int ni_pthread_join(ni_pthread_t thread, void **value_ptr)
join with a terminated thread
ni_retcode_t ni_network_layer_convert_tensor(uint8_t *dst, uint32_t dst_len, const char *tensor_file, ni_network_layer_params_t *p_param)
int ni_insert_emulation_prevent_bytes(uint8_t *buf, int size)
Insert emulation prevention byte(s) as needed into the data buffer.
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 ...
int ni_pthread_mutex_unlock(ni_pthread_mutex_t *mutex)
thread mutex unlock
int ni_sprintf(char *dest, size_t dmax, const char *fmt,...)
char * ni_get_libxcoder_release_ver(void)
Get libxcoder SW release version.
int ni_pthread_mutex_init(ni_pthread_mutex_t *mutex)
initialize a mutex
ni_retcode_t ni_check_dev_name(const char *p_dev)
check dev name
ni_retcode_t ni_network_convert_data_to_tensor(float *dst, uint32_t dst_len, uint8_t *src, uint32_t src_len, ni_network_layer_params_t *p_param)
int ni_pthread_cond_wait(ni_pthread_cond_t *cond, ni_pthread_mutex_t *mutex)
wait on a condition
ni_retcode_t ni_strtoi(const char *str, int32_t *out_val)
Safely convert a decimal string to a 32-bit integer with full validation. Trailing whitespace is tole...
ni_queue_node_t * ni_buffer_pool_expand(ni_queue_buffer_pool_t *pool)
void ni_copy_hw_yuv420p(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, int is_semiplanar, 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 YUV data to Netint HW YUV420p frame layout to be sent to encoder for encoding....
void ni_buffer_pool_return_buffer(ni_queue_node_t *buf, ni_queue_buffer_pool_t *p_buffer_pool)
ni_retcode_t ni_timestamp_done(ni_timestamp_table_t *p_table, ni_queue_buffer_pool_t *p_buffer_pool)
Clean up timestamp handling.
ni_retcode_t ni_timestamp_get_v2(ni_timestamp_table_t *p_table, uint64_t frame_offset, int64_t *p_timestamp, int32_t threshold, ni_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frameoffset info.
uint32_t ni_decode_power_measurement(uint32_t current_data, const uint8_t *serial_number)
decode the raw current obtained and determine power
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...
#define TPS25946_R_IMON_T1U_UA
#define BUFFER_POOL_SZ_PER_CONTEXT
#define TPS25946_GAIN_IMON
#define TPS25946_R_IMON_T1S
#define NI_DEC_FRAME_BUF_POOL_SIZE_EXPAND
#define TPS25940_GAIN_IMON
#define TPS25946_R_IMON_T2A
#define ni_aligned_free(p_memptr)
#define TPS25974_R_IMON_T1M
#define XCODER_MAX_NUM_QUEUE_ENTRIES
#define MAX17613B_R_ISET_TOTAL
#define MAX15162AAWE_C_IRATIO
#define MAX17613B_R_ISET_R2
#define MAX15162AAWE_R_IMON
#define MAX17613B_C_IRATIO
#define TPS25974_GAIN_IMON
uint32_t number_of_buffers
struct _ni_buf_t * p_previous_buffer
struct _ni_buf_pool_t * pool
struct _ni_buf_t * p_next
struct _ni_buf_t * p_prev
struct _ni_buf_t * p_next_buffer
ni_network_layer_info_t linfo
ni_network_layer_offset_t * outset
ni_network_layer_params_t * out_param
union _ni_network_layer_params_t::@13 quant_data
struct _ni_network_layer_params_t::@13::@15 affine
struct _ni_network_layer_params_t::@13::@14 dfp
ni_queue_node_t * p_used_tail
uint32_t number_of_buffers
ni_queue_node_t * p_free_head
ni_queue_node_t * p_used_head
ni_queue_node_t * p_free_tail
struct _ni_queue_node_t * p_previous_buffer
time_t checkout_timestamp
struct _ni_queue_node_t * p_next_buffer
struct _ni_queue_node_t * p_next
struct _ni_queue_node_t * p_prev
ni_queue_node_t * p_first
ni_queue_buffer_pool_t * buffer_pool
uint32_t keep_alive_timeout
ni_buf_pool_t * dec_fme_buf_pool
ni_encoder_cfg_params_t cfg_enc_params
ni_decoder_input_params_t dec_input_params