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);
2720 clock_gettime(CLOCK_REALTIME, &ts);
2721 return ts.tv_sec * 1000000000LL + ts.tv_nsec;
2751 plane_stride[0] = ((
NI_MIN_WIDTH * factor + 127) / 128) * 128;
2753 (((
NI_MIN_WIDTH / (is_semiplanar ? 1 : 2) * factor) + 127) /
2756 plane_stride[2] = (is_semiplanar ? 0 : plane_stride[1]);
2759 width = ((width + 1) / 2) * 2;
2760 plane_stride[0] = ((width * factor + 127) / 128) * 128;
2762 (((width / (is_semiplanar ? 1 : 2) * factor) + 127) / 128) *
2764 plane_stride[2] = (is_semiplanar ? 0 : plane_stride[1]);
2773 plane_height[0] = ((height + 1) / 2) * 2;
2775 plane_height[1] = plane_height[2] = plane_height[0] / 2;
2800 plane_height[0] = ((height + 1) / 2) * 2;
2801 plane_height[1] = plane_height[2] = plane_height[0] / 2;
2809 plane_stride[2] = plane_stride[1];
2810 plane_stride[3] = 0;
2816 plane_stride[2] = plane_stride[1];
2817 plane_stride[3] = 0;
2822 plane_stride[1] = plane_stride[0];
2823 plane_stride[2] = 0;
2824 plane_stride[3] = 0;
2829 plane_stride[1] = plane_stride[0];
2830 plane_stride[2] = 0;
2831 plane_stride[3] = 0;
2837 plane_stride[1] = 0;
2838 plane_stride[2] = 0;
2839 plane_stride[3] = 0;
2844 plane_stride[1] = plane_stride[0];
2845 plane_stride[2] = 0;
2846 plane_stride[3] = 0;
2854 plane_height[1] = plane_height[2] = 0;
2857 plane_stride[1] = 0;
2858 plane_stride[2] = 0;
2859 plane_stride[3] = 0;
2900 width = ((width + 1) / 2) * 2;
2906 "%s dst_stride %d/%d/%d height %d/%d/%d pix_fmt %d\n",
2907 __func__, plane_stride[0], plane_stride[1], plane_stride[2],
2908 plane_height[0], plane_height[1], plane_height[2], pix_fmt);
2934 int frame_width,
int frame_height,
int factor,
2935 int is_semiplanar,
int conf_win_right,
2949 if (p_dst[i] == p_src[i])
2956 (src_height[i] < dst_height[i] ? src_height[i] : dst_height[i]);
2957 uint8_t *dst = p_dst[i];
2958 const uint8_t *src = (
const uint8_t *)p_src[i];
2963 if (0 == i || is_semiplanar)
2965 pad_len_bytes = dst_stride[i] - frame_width * factor;
2970 pad_len_bytes = dst_stride[i] - frame_width / 2 * factor;
2973 if (0 == pad_len_bytes && conf_win_right > 0)
2977 pad_len_bytes = conf_win_right * factor;
2982 pad_len_bytes = conf_win_right * factor / 2;
2987 "%s plane %d stride padding: %d pixel (%d bytes), copy height: "
2989 __func__, i, pad_len_bytes / factor, pad_len_bytes,
2992 for (; height > 0; height--)
2995 (src_stride[i] < dst_stride[i] ? src_stride[i] : dst_stride[i]));
2996 dst += dst_stride[i];
3006 uint8_t *tmp_dst = dst - pad_len_bytes;
3007 for (j = 0; j < pad_len_bytes / factor; j++)
3009 memcpy(tmp_dst, dst - pad_len_bytes - factor, factor);
3015 memset(dst - pad_len_bytes, *(dst - pad_len_bytes - 1),
3019 src += src_stride[i];
3023 int padding_height = dst_height[i] - src_height[i];
3024 if (padding_height > 0)
3028 src = dst - dst_stride[i];
3029 for (; padding_height > 0; padding_height--)
3031 memcpy(dst, src, dst_stride[i]);
3032 dst += dst_stride[i];
3058 int frame_width,
int frame_height,
int factor,
3059 int is_semiplanar,
int conf_win_right,
3066 "%s dst_stride %d/%d/%d src_stride %d/%d/%d dst_height "
3067 "%d/%d/%d src_height %d/%d/%d\n",
3068 __func__, dst_stride[0], dst_stride[1], dst_stride[2], src_stride[0],
3069 src_stride[1], src_stride[2], dst_height[0], dst_height[1],
3070 dst_height[2], src_height[0], src_height[1], src_height[2]);
3077 is_semiplanar, conf_win_right, dst_stride,
3078 dst_height, src_stride, src_height, i);
3104 int frame_width,
int frame_height,
3113 "%s frame_width %d frame_height %d factor %d conf_win_right %d "
3114 "dst_stride %d/%d/%d src_stride %d/%d/%d dst_height "
3115 "%d/%d/%d src_height %d/%d/%d pix_fmt %d\n",
3116 __func__, frame_width, frame_height, factor, conf_win_right,
3117 dst_stride[0], dst_stride[1], dst_stride[2], src_stride[0],
3118 src_stride[1], src_stride[2], dst_height[0], dst_height[1],
3119 dst_height[2], src_height[0], src_height[1], src_height[2],
3123 int is_semiplanar = 0;
3143 frame_width, frame_height, 4,
3144 is_semiplanar, conf_win_right,
3145 dst_stride, dst_height,
3146 src_stride, src_height,
3152 is_semiplanar, conf_win_right, dst_stride,
3153 dst_height, src_stride, src_height);
3185 int frame_width,
int frame_height,
3186 int factor,
int mode)
3189 int y_444p_linesize = frame_width * factor;
3190 int uv_444p_linesize = y_444p_linesize;
3195 if (p_dst0[0] == p_dst1[0] && p_dst0[1] == p_dst1[1] &&
3196 p_dst0[2] == p_dst1[2])
3203 for (i = 0; i < frame_height; i++)
3205 memcpy(&p_dst0[0][(ptrdiff_t)i * y_420p_linesize], &p_src[0][(ptrdiff_t)i * y_444p_linesize],
3214 for (i = 0; i < frame_height; i++)
3216 memcpy(&p_dst1[0][(ptrdiff_t)i * y_420p_linesize],
3217 &p_src[1][(ptrdiff_t)i * y_444p_linesize], y_444p_linesize);
3220 for (i = 0; i < frame_height / 2; i++)
3222 for (j = 0; j < frame_width * factor / 2; j += factor)
3226 memcpy(&p_dst0[1][i * uv_420p_linesize + j],
3227 &p_src[2][2 * i * uv_444p_linesize + 2 * j],
3229 memcpy(&p_dst0[2][i * uv_420p_linesize + j],
3230 &p_src[2][2 * i * uv_444p_linesize + (2 * j + factor)],
3233 memcpy(&p_dst1[1][i * uv_420p_linesize + j],
3234 &p_src[2][(2 * i + 1) * uv_444p_linesize + 2 * j],
3236 memcpy(&p_dst1[2][i * uv_420p_linesize + j],
3237 &p_src[2][(2 * i + 1) * uv_444p_linesize + (2 * j + factor)],
3245 for (i = 0; i < frame_height / 2; i++)
3247 for (j = 0; j < frame_width * factor / 2; j += factor)
3251 memcpy(&p_dst1[1][i * uv_420p_linesize + j],
3252 &p_src[1][2 * i * uv_444p_linesize + (2 * j + factor)],
3255 memcpy(&p_dst1[0][2 * i * uv_444p_linesize + 2 * j],
3256 &p_src[1][(2 * i + 1) * uv_444p_linesize + 2 * j],
3257 (ptrdiff_t)factor * 2);
3259 memcpy(&p_dst0[1][i * uv_420p_linesize + j],
3260 &p_src[1][2 * i * uv_444p_linesize + 2 * j],
3265 memcpy(&p_dst1[2][i * uv_420p_linesize + j],
3266 &p_src[2][2 * i * uv_444p_linesize + (2 * j + factor)],
3269 memcpy(&p_dst1[0][(2 * i + 1) * uv_444p_linesize + 2 * j],
3270 &p_src[2][(2 * i + 1) * uv_444p_linesize + 2 * j],
3271 (ptrdiff_t)factor * 2);
3273 memcpy(&p_dst0[2][i * uv_420p_linesize + j],
3274 &p_src[2][2 * i * uv_444p_linesize + 2 * j],
3297 int insert_bytes = 0;
3298 uint8_t *buf_curr = buf;
3299 uint8_t *buf_end = buf + size - 1;
3300 int zeros = 0, insert_ep3_byte;
3304 for (; buf_curr <= buf_end; buf_curr++)
3308 insert_ep3_byte = (*buf_curr <= 3);
3309 if (insert_ep3_byte)
3312 memmove(buf_curr + 1, buf_curr, buf_end - buf_curr + 1);
3333 return insert_bytes;
3350 int remove_bytes = 0;
3351 uint8_t *buf_curr = buf;
3352 uint8_t *buf_end = buf + size - 1;
3353 int zeros = 0, remove_ep3_byte;
3357 for (; buf_curr < buf_end; buf_curr++)
3361 remove_ep3_byte = (*buf_curr == 0x03 && *(buf_curr + 1) <= 3);
3362 if (remove_ep3_byte)
3365 memmove(buf_curr, buf_curr + 1, buf_end - buf_curr);
3385 return remove_bytes;
3393static uint32_t ni_ai_type_get_bytes(
const uint32_t type)
3419static void ni_ai_integer_convert(
const void *src,
void *dest,
3423 unsigned char all_zeros[] = {0x00, 0x00, 0x00, 0x00,
3424 0x00, 0x00, 0x00, 0x00};
3425 unsigned char all_ones[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3426 uint32_t src_sz = ni_ai_type_get_bytes(src_dtype);
3427 uint32_t dest_sz = ni_ai_type_get_bytes(dst_dtype);
3428 unsigned char *buffer = all_zeros;
3430 if (((int8_t *)src)[src_sz - 1] & 0x80)
3434 memcpy(buffer, src, src_sz);
3435 memcpy(dest, buffer, dest_sz);
3438static float ni_ai_int8_to_fp32(
signed char val,
signed char fixedPointPos)
3440 float result = 0.0f;
3442 if (fixedPointPos > 0)
3444 result = (float)val * (1.0f / ((
float)(1 << fixedPointPos)));
3447 result = (float)val * ((
float)(1 << -fixedPointPos));
3453static float ni_ai_int16_to_fp32(int16_t val,
signed char fixedPointPos)
3455 float result = 0.0f;
3457 if (fixedPointPos > 0)
3459 result = (float)val * (1.0f / ((
float)(1 << fixedPointPos)));
3462 result = (float)val * ((
float)(1 << -fixedPointPos));
3468static float ni_ai_uint8_to_fp32(uint8_t val, int32_t zeroPoint,
float scale)
3470 float result = 0.0f;
3472 result = (float)(val - (uint8_t)zeroPoint) * scale;
3477static float ni_ai_fp16_to_fp32(
const short in)
3485 const _fp32_t magic = {(254 - 15) << 23};
3486 const _fp32_t infnan = {(127 + 16) << 23};
3489 o.u = (in & 0x7fff) << 13;
3491 if (o.f >= infnan.f)
3496 o.u |= (in & 0x8000) << 16;
3500static float ni_ai_affine_to_fp32(int32_t val, int32_t zeroPoint,
float scale)
3502 float result = 0.0f;
3503 result = ((float)val - (
float)zeroPoint) * scale;
3507static uint32_t ni_ai_get_tensor_size(int32_t *shape, uint32_t dim_num,
3513 if (NULL == shape || 0 == dim_num)
3518 for (i = 0; i < dim_num; i++)
3522 sz *= ni_ai_type_get_bytes(type);
3527static uint32_t ni_ai_get_element_num(int32_t *sizes, uint32_t num_of_dims,
3528 int32_t data_format)
3534 sz = ni_ai_get_tensor_size(sizes, num_of_dims, data_format);
3535 dsize = ni_ai_type_get_bytes(data_format);
3538 num = (uint32_t)(sz / dsize);
3547static int32_t ni_ai_type_is_integer(
const int32_t type)
3567static int32_t ni_ai_type_is_signed(
const int32_t type)
3587static void ni_ai_type_get_range(int32_t type,
double *max_range,
3594 bits = (int32_t)(ni_ai_type_get_bytes(type) * 8);
3595 if (ni_ai_type_is_integer(type))
3597 if (ni_ai_type_is_signed(type))
3599 from = (double)(-(1L << (bits - 1)));
3600 to = (double)((1UL << (bits - 1)) - 1);
3604 to = (double)((1UL << bits) - 1);
3607 if (NULL != max_range)
3611 if (NULL != min_range)
3617static inline double ni_abs(
double x)
3619 return x < 0 ? -x : x;
3622static double ni_ai_copy_sign(
double number,
double sign)
3624 double value = ni_abs(number);
3625 return (sign > 0) ? value : (-value);
3628static inline int ni_ai_math_floorf(
double x)
3630 return x >= 0 ? (int)x : (int)x - 1;
3633static double ni_ai_rint(
double x)
3635#define NI_AI_EPSILON 1e-8
3641 decimal = x - intpart;
3642 inter = (double)intpart;
3646 inter += (int32_t)(inter) % 2;
3649 return ni_ai_copy_sign(ni_ai_math_floorf(ni_abs(x) + 0.5f), x);
3655static int32_t ni_ai_fp32_to_dfp(
const float in,
const signed char fl,
3661 ni_ai_type_get_range(type, &max_range, &min_range);
3664 data = (int32_t)ni_ai_rint(in * (
float)(1 << fl));
3667 data = (int32_t)ni_ai_rint(in * (1.0f / (
float)(1 << -fl)));
3669 data = ni_min(data, (int32_t)max_range);
3670 data = ni_max(data, (int32_t)min_range);
3675static int32_t ni_ai_fp32_to_affine(
const float in,
const float scale,
3676 const int zero_point,
const int32_t type)
3681 ni_ai_type_get_range(type, &max_range, &min_range);
3682 data = (int32_t)(ni_ai_rint(in / scale) + zero_point);
3683 data = ni_max((int32_t)min_range, ni_min((int32_t)max_range, data));
3687static unsigned short ni_ai_fp32_to_bfp16_rtne(
float in)
3695 memcpy(&fp32, &in,
sizeof(uint32_t));
3699 uint32_t rounding_bias = 0x7fff + lsb;
3701 if ((
float)0x7FC00000 == in)
3706 fp32 += rounding_bias;
3707 out = (
unsigned short)(fp32 >> 16);
3713static unsigned short ni_ai_fp32_to_fp16(
float in)
3721 memcpy((uint8_t *)&fp32, (uint8_t *)&in,
sizeof(uint32_t));
3723 t1 = (fp32 & 0x80000000u) >> 16;
3724 t2 = (fp32 & 0x7F800000u) >> 13;
3725 t3 = (fp32 & 0x007FE000u) >> 13;
3727 if (t2 >= 0x023c00u)
3730 }
else if (t2 <= 0x01c000u)
3736 fp16 = t1 | t2 | t3;
3739 return (
unsigned short)fp16;
3742static void ni_ai_float32_to_dtype(
float src,
unsigned char *dst,
3743 const int32_t data_type,
3744 const int32_t quant_format,
3745 signed char fixed_point_pos,
float tf_scale,
3751 memcpy(dst, &src,
sizeof(
float));
3754 *(int16_t *)dst = (int16_t)ni_ai_fp32_to_fp16(src);
3757 *(int16_t *)dst = (int16_t)ni_ai_fp32_to_bfp16_rtne(src);
3763 int32_t dst_value = 0;
3764 switch (quant_format)
3768 ni_ai_fp32_to_dfp(src, fixed_point_pos, data_type);
3771 dst_value = ni_ai_fp32_to_affine(src, tf_scale, tf_zerop,
3775 dst_value = (int32_t)src;
3797 if (!p_network || !dst || dst_len == 0 || !p_packet || !p_packet->
p_data)
3821static int open_tensor_rsrc_file(
struct tensor_rsrc *rsrc,
void *data,
3826 ni_fopen(&f, (
const char *)data,
"r");
3828 return rsrc->
private ? 0 : -1;
3831static int get_tensor_rsrc_from_file(
struct tensor_rsrc *rsrc,
float *value)
3833 FILE *fp = (FILE *)rsrc->
private;
3845static void close_tensor_rsrc_file(
struct tensor_rsrc *rsrc)
3847 FILE *fp = (FILE *)rsrc->
private;
3851static int open_tensor_rsrc_rawdata(
struct tensor_rsrc *rsrc,
void *data,
3860static int get_tensor_rsrc_from_rawdata(
struct tensor_rsrc *rsrc,
float *value)
3862 float *tensors = (
float *)rsrc->
private;
3864 if (rsrc->next_idx < rsrc->total_num)
3866 *value = tensors[rsrc->next_idx];
3874static void close_tensor_rsrc_rawdata(
struct tensor_rsrc *rsrc)
3879 uint8_t *dst, uint32_t dst_len,
void *tensor, uint32_t src_len,
3881 int (*open_tensor_rsrc)(
struct tensor_rsrc *,
void *, uint32_t),
3882 int (*get_tensor_rsrc)(
struct tensor_rsrc *,
float *),
3885 uint8_t *tensor_data;
3889 int32_t data_format;
3890 int32_t quant_format;
3891 int32_t fixed_point_pos;
3902 sz = ni_ai_get_element_num((int32_t *)p_param->
sizes, p_param->
num_of_dims,
3904 stride = ni_ai_type_get_bytes(data_format);
3906 if ((
size_t)sz * stride *
sizeof(uint8_t) != dst_len)
3917 if (open_tensor_rsrc(rsrc, tensor, src_len) != 0)
3923 memset(dst, 0, (
size_t)sz * stride *
sizeof(uint8_t));
3925 for (i = 0; i < sz; i++)
3927 if (get_tensor_rsrc(rsrc, &fval) == 0)
3929 ni_ai_float32_to_dtype(fval, &tensor_data[(ptrdiff_t)stride * i], data_format,
3930 quant_format, (int8_t)fixed_point_pos, tf_scale,
3938 close_tensor_rsrc(rsrc);
3944 const char *tensor_file,
3947 return ni_network_tensor_to_data(
3948 dst, dst_len, (
void *)tensor_file, 0, p_param, open_tensor_rsrc_file,
3949 get_tensor_rsrc_from_file, close_tensor_rsrc_file);
3957 return ni_network_tensor_to_data(
3958 dst, dst_len, src, src_len, p_param, open_tensor_rsrc_rawdata,
3959 get_tensor_rsrc_from_rawdata, close_tensor_rsrc_rawdata);
3970 float *dst_float = dst;
3973 if (!src || src_len == 0 || !dst || dst_len == 0 || !p_param)
3978 type_size = ni_ai_type_get_bytes(p_param->
data_format);
3985 ele_size *= p_param->
sizes[i];
3988 if (dst_len != ele_size *
sizeof(
float))
4006 for (i = 0; i < ele_size; i++, data += type_size)
4008 dst_float[i] = ni_ai_int8_to_fp32((int8_t)*data, (int8_t)fix_pos);
4015 for (i = 0; i < ele_size; i++, data += type_size)
4017 int32_t src_value = 0;
4018 ni_ai_integer_convert(data, &src_value,
4022 ni_ai_affine_to_fp32(src_value, zero_point, scale);
4026 for (i = 0; i < ele_size; i++, data += type_size)
4028 void *float_data = (
void *)data;
4029 dst_float[i] = *((
float *)float_data);
4034 for (i = 0; i < ele_size; i++, data += type_size)
4036 dst_float[i] = ni_ai_fp16_to_fp32(*((
short *)data));
4043 for (i = 0; i < ele_size; i++, data += type_size)
4045 dst_float[i] = ni_ai_uint8_to_fp32(*data, zero_point, scale);
4051 for (i = 0; i < ele_size; i++, data += type_size)
4053 dst_float[i] = ni_ai_int16_to_fp32(*((
short *)data), (int8_t)fix_pos);
4057 for (i = 0; i < ele_size; i++, data += type_size)
4059 void *float_data = (
void *)data;
4060 dst_float[i] = *((
float *)float_data);
4072 return ni_ai_get_tensor_size((int32_t *)p_param->
sizes,
4078 uint32_t i, dims = 1;
4082 dims *= p_param->
sizes[i];
4090#define SHA256_BLOCK_SIZE 32
4100#define ROTLEFT(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
4101#define ROTRIGHT(a, b) (((a) >> (b)) | ((a) << (32 - (b))))
4103#define CH(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
4104#define MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
4105#define EP0(x) (ROTRIGHT(x, 2) ^ ROTRIGHT(x, 13) ^ ROTRIGHT(x, 22))
4106#define EP1(x) (ROTRIGHT(x, 6) ^ ROTRIGHT(x, 11) ^ ROTRIGHT(x, 25))
4107#define SIG0(x) (ROTRIGHT(x, 7) ^ ROTRIGHT(x, 18) ^ ((x) >> 3))
4108#define SIG1(x) (ROTRIGHT(x, 17) ^ ROTRIGHT(x, 19) ^ ((x) >> 10))
4110static const uint32_t ui32k[64] = {
4111 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
4112 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
4113 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
4114 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
4115 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
4116 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
4117 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
4118 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
4119 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
4120 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
4121 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
4125 uint32_t ui32a, ui32b, ui32c, ui32d, ui32e, ui32f, ui32g, ui32h, ui32i,
4126 ui32j, ui32t1, ui32t2, ui32m[64];
4128 for (ui32i = 0, ui32j = 0; ui32i < 16; ++ui32i, ui32j += 4)
4129 ui32m[ui32i] = (aui8Data[ui32j] << 24) | (aui8Data[ui32j + 1] << 16) |
4130 (aui8Data[ui32j + 2] << 8) | (aui8Data[ui32j + 3]);
4131 for (; ui32i < 64; ++ui32i)
4132 ui32m[ui32i] =
SIG1(ui32m[ui32i - 2]) + ui32m[ui32i - 7] +
4133 SIG0(ui32m[ui32i - 15]) + ui32m[ui32i - 16];
4144 for (ui32i = 0; ui32i < 64; ++ui32i)
4146 ui32t1 = ui32h +
EP1(ui32e) +
CH(ui32e, ui32f, ui32g) + ui32k[ui32i] +
4148 ui32t2 =
EP0(ui32a) +
MAJ(ui32a, ui32b, ui32c);
4152 ui32e = ui32d + ui32t1;
4156 ui32a = ui32t1 + ui32t2;
4188 for (ui32i = 0; ui32i < ui32Length; ++ui32i)
4236 for (ui32i = 0; ui32i < 4; ++ui32i)
4239 (psCtx->
aui32State[0] >> (24 - ui32i * 8)) & 0x000000ff;
4240 aui8Hash[ui32i + 4] =
4241 (psCtx->
aui32State[1] >> (24 - ui32i * 8)) & 0x000000ff;
4242 aui8Hash[ui32i + 8] =
4243 (psCtx->
aui32State[2] >> (24 - ui32i * 8)) & 0x000000ff;
4244 aui8Hash[ui32i + 12] =
4245 (psCtx->
aui32State[3] >> (24 - ui32i * 8)) & 0x000000ff;
4246 aui8Hash[ui32i + 16] =
4247 (psCtx->
aui32State[4] >> (24 - ui32i * 8)) & 0x000000ff;
4248 aui8Hash[ui32i + 20] =
4249 (psCtx->
aui32State[5] >> (24 - ui32i * 8)) & 0x000000ff;
4250 aui8Hash[ui32i + 24] =
4251 (psCtx->
aui32State[6] >> (24 - ui32i * 8)) & 0x000000ff;
4252 aui8Hash[ui32i + 28] =
4253 (psCtx->
aui32State[7] >> (24 - ui32i * 8)) & 0x000000ff;
4287 if (p_dst[0] == p_src[0] && p_dst[1] == p_src[1] && p_dst[2] == p_src[2] &&
4288 p_dst[3] == p_src[3])
4310 return libxcoder_api_ver;
4313#ifndef DEPRECATION_AS_ERROR
4322 static char compat_fw_api_ver_str[5] =
"";
4324 if (!compat_fw_api_ver_str[0])
4326 compat_fw_api_ver_str[0] = \
4328 compat_fw_api_ver_str[1] =
'.';
4329 compat_fw_api_ver_str[2] = \
4332 compat_fw_api_ver_str[3] = \
4335 compat_fw_api_ver_str[3] = 0;
4336 compat_fw_api_ver_str[4] = 0;
4338 return &compat_fw_api_ver_str[0];
4355 if (!ver_str || !fmt_str) {
4359 fmt_str[0] = ver_str[0];
4361 fmt_str[2] = ver_str[1];
4363 if ((ver_str[0] <
'6' || (ver_str[0] ==
'6' && ver_str[1] <=
'q')) ||
4364 (ver_str[2] == 0)) {
4367 fmt_str[3] = ver_str[2];
4389 if (ver1[index] > ver2[index])
4391 else if (ver1[index] < ver2[index])
4396 if (ver1[index] > ver2[index])
4398 else if (ver1[index] < ver2[index])
4401 if ((ver1[index - 1] <
'6') || ((ver1[index - 1] ==
'6') && (ver1[index] <=
'q')))
4406 if (ver1[index] > ver2[index])
4408 else if (ver1[index] < ver2[index])
4421 static char release_ver_str[6] =
"";
4423 if (!release_ver_str[0])
4426 release_ver_str[1] =
'.';
4428 release_ver_str[3] =
'.';
4430 release_ver_str[5] = 0;
4432 return &release_ver_str[0];
4446 if (rc == ni_err_rc_description[i].rc)
4448 return ni_err_rc_description[i].
txt;
4451 return "rc not supported";
4466 if (!p_str || !key || !value)
4471 char *p = strchr(p_str,
'=');
4480 int64_t key_len = p - p_str;
4501 char key[64], value[64];
4502 char *curr = xcoderParams, *colon_pos;
4507 colon_pos = strchr(curr,
':');
4514 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4518 "Error: xcoder-params p_config key/value not "
4547 curr = colon_pos + 1;
4550 curr += strlen(curr);
4576 char key[64], value[64];
4577 char *curr = xcoderGop, *colon_pos;
4582 colon_pos = strchr(curr,
':');
4589 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4593 "Error: xcoder-params p_config key/value not "
4622 curr = colon_pos + 1;
4625 curr += strlen(curr);
4646 char key[64], value[64];
4647 char *curr = xcoderParams, *colon_pos;
4652 colon_pos = strchr(curr,
':');
4659 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4663 "Error: decoder-params p_config key/value not "
4692 curr = colon_pos + 1;
4695 curr += strlen(curr);
4717 rc = InitializeCriticalSectionEx(mutex, 0, CRITICAL_SECTION_NO_DEBUG_INFO);
4728 ni_pthread_mutexattr_t attr;
4730 rc = pthread_mutexattr_init(&attr);
4736 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
4738 return pthread_mutex_init(mutex, &attr);
4753 DeleteCriticalSection(mutex);
4756 return pthread_mutex_destroy(mutex);
4774 EnterCriticalSection(mutex);
4776 rc = pthread_mutex_lock(mutex);
4800 LeaveCriticalSection(mutex);
4802 rc = pthread_mutex_unlock(mutex);
4813static unsigned __stdcall __thread_worker(
void *arg)
4815 ni_pthread_t *t = (ni_pthread_t *)arg;
4816 t->rc = t->start_routine(t->arg);
4833 void *(*start_routine)(
void *),
void *arg)
4836 thread->start_routine = start_routine;
4840 (
void *)CreateThread(NULL, 0, win32thread_worker, thread, 0, NULL);
4842 (
void *)_beginthreadex(NULL, 0, __thread_worker, thread, 0, NULL);
4844 return !thread->handle;
4846 return pthread_create(thread, attr, start_routine, arg);
4862 DWORD rc = WaitForSingleObject(thread.handle, INFINITE);
4863 if (rc != WAIT_OBJECT_0)
4865 if (rc == WAIT_ABANDONED)
4871 *value_ptr = thread.rc;
4872 CloseHandle(thread.handle);
4875 return pthread_join(thread, value_ptr);
4889 const ni_pthread_condattr_t *attr)
4892 InitializeConditionVariable(cond);
4895 return pthread_cond_init(cond, attr);
4913 return pthread_cond_destroy(cond);
4928 WakeAllConditionVariable(cond);
4931 return pthread_cond_broadcast(cond);
4947 SleepConditionVariableCS(cond, mutex, INFINITE);
4950 return pthread_cond_wait(cond, mutex);
4965 WakeConditionVariable(cond);
4968 return pthread_cond_signal(cond);
4983 ni_pthread_mutex_t *mutex,
4984 const struct timespec *abstime)
4987 int64_t abs_ns = abstime->tv_sec * 1000000000LL + abstime->tv_nsec;
4990 if (!SleepConditionVariableCS(cond, mutex, t))
4992 DWORD err = GetLastError();
4993 if (err == ERROR_TIMEOUT)
5000 return pthread_cond_timedwait(cond, mutex, abstime);
5021 return pthread_sigmask(how, set, oldset);
5039 return "General Error";
5041 return "Not Initialized";
5043 return "Already Initialized";
5047 return "Resource Not Available";
5049 return "Create Network Failed";
5051 return "Input Buffer Full";
5053 return "Output Buffer Empty";
5055 return "Invalid Params";
5057 return "Error Start Network";
5059 return "Erorr Set Inout";
5061 return "Bad Option";
5065 return "Context Not Available";
5067 return "Model Not Found";
5071 return "Invalid Address";
5073 return "Out Of Memory";
5077 return "Invalid Instance";
5079 return "IO Not Allowed";
5081 return "Network Not Ready";
5083 return "Other Error";
5098 float current_ma,voltage_mv;
5105 (void)snprintf(pcb_config,
sizeof(pcb_config),
"%.2s", &serial_number[2]);
5107 float current_value = (float)current_data;
5108 voltage_mv = 12000.0f;
5109 if (strncmp(pcb_config,
"A1", 2) == 0)
5113 else if ((strncmp(pcb_config,
"A2", 2) == 0) || (strncmp(pcb_config,
"A3", 2) == 0))
5117 else if ((strncmp(pcb_config,
"AA", 2) == 0) || (strncmp(pcb_config,
"AB", 2) == 0))
5121 else if (strncmp(pcb_config,
"U0", 2) == 0)
5126 else if ((strncmp(pcb_config,
"U1", 2) == 0) || (strncmp(pcb_config,
"U2", 2) == 0) || (strncmp(pcb_config,
"U3", 2) == 0))
5130 else if (strncmp(pcb_config,
"UA", 2) == 0)
5134 else if (strncmp(pcb_config,
"S0", 2) == 0)
5138 else if ((strncmp(pcb_config,
"M0", 2) == 0) || (strncmp(pcb_config,
"M1", 2) == 0))
5141 voltage_mv = 3300.0f;
5143 else if (strncmp(pcb_config,
"M", 1) == 0)
5146 voltage_mv = 3300.0f;
5152 power_mw = (uint32_t)((voltage_mv * current_ma) / 1000.0);
5175static int ni_device_size_precheck_ioctl(
const char *p_dev,
const uint64_t size_needed)
5177#if defined(_WIN32) || !defined(BLKGETSIZE64)
5192 fd = open(p_dev, O_RDONLY);
5199 call_ret = ioctl(fd, BLKGETSIZE64, &bytes);
5204 else if (bytes < size_needed)
5236static int ni_device_vendor_id_precheck(
const char *p_dev)
5250 const char *vendor_path_devs[] = {
"/sys/class/block/%s/device/vendor",
"/sys/class/block/%s/device/device/vendor"};
5252 const char *last_slash = strrchr(p_dev,
'/');
5253 const char *device_name = (last_slash ? (last_slash + 1) : p_dev);
5255 const size_t path_len = strlen(p_dev);
5257 for (
size_t i = 0; i <
sizeof(vendor_path_devs)/
sizeof(vendor_path_devs[0]); ++i)
5259 size_t template_len = strlen(vendor_path_devs[i]);
5260 char *vendor_path = (
char *)calloc(1, template_len + path_len);
5265 (void)snprintf(vendor_path, template_len + path_len, vendor_path_devs[i], device_name);
5267 int fd = open(vendor_path, O_RDONLY);
5270 char vendor_id[10] = {0};
5271 ssize_t read_size = read(fd, vendor_id,
sizeof(vendor_id));
5272 if (read_size >= 4 && (
size_t)read_size <
sizeof(vendor_id))
5274 char *find_1d82 = strstr(vendor_id,
"1d82");
5281 ni_log2(NULL,
NI_LOG_DEBUG,
"%s() vendor check failed. vendor id: %s", __func__, vendor_id);
5323static int ni_device_size_precheck_system_information(
const char *p_dev,
const uint64_t size_needed)
5338 const char block_path_dev[] =
"/sys/class/block/%s/size";
5339 const char logical_block_size_path_dev[] =
"/sys/class/block/%s/queue/logical_block_size";
5341 const char *last_slash = strrchr(p_dev,
'/');
5342 const char *device_name = (last_slash ? (last_slash + 1) : p_dev);
5344 const size_t path_len = strlen(p_dev);
5347 int logical_block_fd = -1;
5349 char *block_path = (
char *)calloc(1,
sizeof(block_path_dev) + path_len);
5350 char *logical_block_size_path = (
char *)calloc(1,
sizeof(logical_block_size_path_dev) + path_len);
5352 if (!block_path || !logical_block_size_path)
5357 (void)snprintf(block_path,
sizeof(block_path_dev) + path_len, block_path_dev, device_name);
5358 (void)snprintf(logical_block_size_path,
sizeof(logical_block_size_path_dev) + path_len, logical_block_size_path_dev, device_name);
5360 size_fd = open(block_path, O_RDONLY);
5361 logical_block_fd = open(logical_block_size_path, O_RDONLY);
5363 if (size_fd < 0 || logical_block_fd < 0)
5368 char this_size_str [20] = {0};
5369 char this_block_size_str [20] = {0};
5371 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)
5377 char *endptr1 = NULL;
5378 char *endptr2 = NULL;
5380 unsigned long long this_size = strtoull(this_size_str, &endptr1, 10);
5381 unsigned long long this_block_size = strtoull(this_block_size_str, &endptr2, 10);
5383 if (errno == 0 && endptr1 != this_size_str && endptr2 != this_block_size_str)
5385 if (this_size * this_block_size >= size_needed)
5391 ni_log2(NULL,
NI_LOG_DEBUG,
"%s() read size check failed. size: %" PRIu64
"\n", __func__, this_size * this_block_size);
5402 if (logical_block_size_path)
5404 free(logical_block_size_path);
5411 if (logical_block_fd >= 0)
5413 close(logical_block_fd);
5450 const size_t path_len = strlen(p_dev);
5457 ret = ni_device_size_precheck_ioctl(p_dev, SIZE_NEEDED);
5467 ret = ni_device_vendor_id_precheck(p_dev);
5477 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