28#if __linux__ || __APPLE__
147 SYSTEMTIME system_time;
148 ULARGE_INTEGER ularge;
150 static const unsigned __int64 epoch =
151 ((
unsigned __int64)116444736000000000ULL);
157 GetSystemTime(&system_time);
158 SystemTimeToFileTime(&system_time, &file_time);
159 ularge.LowPart = file_time.dwLowDateTime;
160 ularge.HighPart = file_time.dwHighDateTime;
162 (void)ularge.LowPart;
163 (void)ularge.HighPart;
164 p_tp->tv_sec = (long)((ularge.QuadPart - epoch) / 10000000L);
165 p_tp->tv_usec = (long)(system_time.wMilliseconds * 1000);
169 return gettimeofday(p_tp, p_tzp);
177 return number_to_round;
180 uint32_t remainder = number_to_round % multiple;
183 return number_to_round;
186 return (number_to_round + multiple - remainder);
205 *memptr = _aligned_malloc(size, alignment);
211 ZeroMemory(*memptr, size);
215 return posix_memalign(memptr, alignment, size);
227uint32_t ni_get_kernel_max_io_size(
const char * p_dev)
230 char file_name[KERNEL_NVME_FILE_NAME_MAX_SZ];
231 int max_segments = 0, min_io_size = 0, max_hw_sectors_kb = 0;
232 uint32_t io_size = DEFAULT_IO_TRANSFER_SIZE;
236 memset(file_name, 0, KERNEL_NVME_FILE_NAME_MAX_SZ);
244 len = strlen(p_dev) - 5;
245 if (len < MIN_NVME_DEV_NAME_LEN)
252 memset(file_name, 0,
sizeof(file_name));
253 ni_strcpy(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, SYS_PARAMS_PREFIX_PATH);
254#if defined(_ANDROID) || defined(__OPENHARMONY__)
256 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 11),
sizeof(file_name) - SYS_PREFIX_SZ);
259 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 5),
sizeof(file_name) - SYS_PREFIX_SZ);
261 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, KERNEL_NVME_MAX_SEG_PATH,
262 sizeof(file_name) - SYS_PREFIX_SZ - len);
271 err =
ni_fscanf(p_file,
"%d", &max_segments);
281 memset(file_name, 0,
sizeof(file_name));
282 ni_strcpy(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, SYS_PARAMS_PREFIX_PATH);
283#if defined(_ANDROID) || defined(__OPENHARMONY__)
285 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 11),
sizeof(file_name) - SYS_PREFIX_SZ);
288 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 5),
sizeof(file_name) - SYS_PREFIX_SZ);
290 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, KERNEL_NVME_MIN_IO_SZ_PATH,
291 sizeof(file_name) - SYS_PREFIX_SZ - len);
300 err =
ni_fscanf(p_file,
"%d", &min_io_size);
310 memset(file_name, 0,
sizeof(file_name));
311 ni_strcpy(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, SYS_PARAMS_PREFIX_PATH);
312#if defined(_ANDROID) || defined(__OPENHARMONY__)
314 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 11),
sizeof(file_name) - SYS_PREFIX_SZ);
317 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, (
char *)(p_dev + 5),
sizeof(file_name) - SYS_PREFIX_SZ);
319 ni_strncat(file_name, KERNEL_NVME_FILE_NAME_MAX_SZ, KERNEL_NVME_MAX_HW_SEC_KB_PATH,
320 sizeof(file_name) - SYS_PREFIX_SZ - len);
329 err =
ni_fscanf(p_file,
"%d", &max_hw_sectors_kb);
336 if (ni_min(min_io_size * max_segments, max_hw_sectors_kb * 1024) >
337 MAX_IO_TRANSFER_SIZE)
339 io_size = MAX_IO_TRANSFER_SIZE;
343 io_size = ni_min(min_io_size * max_segments, max_hw_sectors_kb * 1024);
367 LARGE_INTEGER StartCount;
368 LARGE_INTEGER StopCount;
369 LARGE_INTEGER Frequency;
370 QueryPerformanceCounter(&StartCount);
371 QueryPerformanceFrequency(&Frequency);
373 StartCount.QuadPart + usec * (Frequency.QuadPart / 1000000);
376 QueryPerformanceCounter(&StartCount);
377 }
while (StartCount.QuadPart < StopCount.QuadPart);
381 LARGE_INTEGER ft = {0};
388 timer = CreateWaitableTimer(NULL, TRUE, NULL);
391 retval = SetWaitableTimer(timer, &ft, 0, NULL, NULL, 0);
394 WaitForSingleObject(timer, INFINITE);
400 LARGE_INTEGER StartCount;
401 LARGE_INTEGER StopCount;
402 LARGE_INTEGER Frequency;
403 QueryPerformanceCounter(&StartCount);
404 QueryPerformanceFrequency(&Frequency);
406 StartCount.QuadPart + usec * (Frequency.QuadPart / 1000000);
409 QueryPerformanceCounter(&StartCount);
410 }
while (StartCount.QuadPart < StopCount.QuadPart);
414 if (usec < 0xFFFFFFFF)
424char *
ni_strtok(
char *s,
const char *delim,
char **saveptr)
428 if (!s && !(s = *saveptr))
432 s += strspn(s, delim);
442 s += strcspn(s, delim);
456 if(strcpy_s(dest, dmax, src))
461 if (!dest || !dmax || !src)
469 const char *overlap_bumper;
475 overlap_bumper = src;
477 if (dest == overlap_bumper) {
491 overlap_bumper = dest;
493 if (src == overlap_bumper) {
519 const char *src,
size_t slen)
522 if(strncpy_s(dest, dmax, src, slen))
527 if (slen == 0 && dest && dmax) {
532 if (!dest || !dmax || !src)
536 const char *overlap_bumper;
542 overlap_bumper = src;
545 if (dest == overlap_bumper) {
556#ifdef SAFECLIB_STR_NULL_SLACK
558 memset(dest, 0, dmax);
574#ifdef SAFECLIB_STR_NULL_SLACK
576 memset(dest, 0, dmax);
594 overlap_bumper = dest;
597 if (src == overlap_bumper) {
608#ifdef SAFECLIB_STR_NULL_SLACK
610 memset(dest, 0, dmax);
626#ifdef SAFECLIB_STR_NULL_SLACK
628 memset(dest, 0, dmax);
659 if(strerror_s(dest, dmax, errnum))
664 if (!dest || !dmax || (dmax >= (
size_t)(-1)))
667 const char *tmpbuf = strerror(errnum);
672 len = strerrorlen_s(errnum);
674 const char *tmpbuf = strerror(errnum);
676 }
else if (dmax > 3) {
677 const char *tmpbuf = strerror(errnum);
692 if(strcat_s(dest, dmax, src))
697 if (!dest || !dmax || !src)
702 const char *overlap_bumper;
708 overlap_bumper = src;
710 while (*dest !=
'\0') {
711 if (dest == overlap_bumper) {
726 if (dest == overlap_bumper) {
734#ifdef SAFECLIB_STR_NULL_SLACK
736 memset(dest, 0, dmax);
753 overlap_bumper = dest;
756 while (*dest !=
'\0') {
771 if (src == overlap_bumper) {
780#ifdef SAFECLIB_STR_NULL_SLACK
782 memset(dest, 0, dmax);
808 const char *src,
size_t slen)
812 const char *overlap_bumper;
814 if (slen == 0 && !dest && !dmax) {
818 if (!dest || !dmax || !src)
820 else if (slen == 0) {
833 overlap_bumper = src;
836 while (*dest !=
'\0') {
838 if (dest == overlap_bumper) {
854 if (dest == overlap_bumper) {
864#ifdef SAFECLIB_STR_NULL_SLACK
867 memset(dest, 0, dmax);
883#ifdef SAFECLIB_STR_NULL_SLACK
886 memset(dest, 0, dmax);
904 overlap_bumper = dest;
907 while (*dest !=
'\0') {
923 if (src == overlap_bumper) {
933#ifdef SAFECLIB_STR_NULL_SLACK
936 memset(dest, 0, dmax);
952#ifdef SAFECLIB_STR_NULL_SLACK
955 memset(dest, 0, dmax);
986 if(fopen_s(fp, filename, mode))
991 if (!fp || !filename || !mode)
994 *fp = fopen(filename, mode);
1005#if defined(_MSC_VER)
1006 if (localtime_s(dest, src))
1016 dest = localtime(src);
1024#if defined(_MSC_VER)
1026 va_start(args, fmt);
1027 ret = vfscanf_s(stream, fmt, args);
1030 if (!stream || !fmt)
1033 va_start(args, fmt);
1034 ret = vfscanf(stream, fmt, args);
1040int ni_vsprintf(
char *dest,
const size_t dmax,
const char *fmt, va_list args)
1042#if defined(_MSC_VER)
1043 int ret = vsprintf_s(dest, dmax, fmt, args);
1046 if (!dest || !dmax || !fmt)
1049 int ret = vsnprintf(dest, dmax, fmt, args);
1053 }
else if ((
size_t)ret >= dmax) {
1055 char *overrun = dest + dmax - 1;
1066 va_start(args, fmt);
1095 if (NULL == p_buffer_pool)
1214 if (NULL != p_buffer_pool &&
1218 memset(p_buffer, 0,
sizeof(
ni_buf_t));
1226 p_buffer->
buf = p_buf;
1227 p_buffer->
pool = p_buffer_pool;
1250 int32_t number_of_buffers,
1251 int width,
int height,
1252 int height_align,
int factor)
1262 width_aligned = ((((width * factor) + 127) / 128) * 128) / factor;
1263 height_aligned = height;
1266 width_aligned = ((width + 31) / 32) * 32;
1267 height_aligned = ((height + 7) / 8) * 8;
1270 height_aligned = ((height + 15) / 16) * 16;
1274 int luma_size = width_aligned * height_aligned * factor;
1279 int chroma_width_aligned =
1280 ((((width / 2 * factor) + 127) / 128) * 128) / factor;
1281 int chroma_height_aligned = height_aligned / 2;
1282 chroma_b_size = chroma_r_size =
1283 chroma_width_aligned * chroma_height_aligned * factor;
1286 chroma_b_size = luma_size / 4;
1287 chroma_r_size = chroma_b_size;
1289 uint32_t buffer_size = luma_size + chroma_b_size + chroma_r_size +
1302 "Warning init dec_fme Buf pool already with size %u\n",
1308 "Warning resolution %dx%d memory buffer size %u "
1309 "> %u (existing buffer size), re-allocating !\n",
1310 width, height, buffer_size,
1317 "INFO resolution %dx%d memory buffer size %u <= "
1318 "%u (existing buffer size), continue !\n",
1319 width, height, buffer_size,
1338 "ni_dec_fme_buffer_pool_initialize: entries %d entry size "
1340 number_of_buffers, buffer_size);
1343 for (i = 0; i < number_of_buffers; i++)
1385 int32_t count_free = 0;
1404 free(p_buffer_pool);
1448 free(p_buffer_pool);
1460 if (NULL != p_buffer_pool &&
1512 for (i = 0; i < number_of_buffers; i++)
1529 for (i = 0; i < 200; i++)
1534 "FATAL ERROR: Failed to allocate pool buffer for pool :%p\n",
1547 if (NULL == p_buffer_pool)
1599 if (!buf || !p_buffer_pool)
1664static ni_retcode_t ni_search_file(
const char *p_dev,
char *cmd,
char *cmd_ret,
1670 if (access(p_dev, F_OK) == -1)
1676 cmd_fp = popen(cmd,
"r");
1682 if (fgets(cmd_ret, cmd_ret_len, cmd_fp) == 0)
1710NI_UNUSED static uint32_t remove_substring_pattern(
char *main_str,
const char *pattern)
1713 uint32_t match_length;
1714 uint32_t matched_chr;
1715 char char_match_pattern[11] =
"";
1716 uint32_t pattern_matched = 0;
1717 uint32_t pattern_start = 0;
1718 const char digit_match_pattern[11] =
"0123456789";
1721 if (!main_str || !pattern || !*main_str || !*pattern)
1727 for (i = 0; i < strlen(main_str) && !pattern_matched; i++)
1729 pattern_matched = 0;
1732 for (j = 0; j < strlen(pattern); j++)
1736 if (pattern[j] ==
'+')
1741 else if (pattern[j] ==
'#')
1743 memcpy(char_match_pattern, digit_match_pattern, strlen(digit_match_pattern) + 1);
1747 memcpy(char_match_pattern, pattern + j, 1);
1748 memset(char_match_pattern + 1, 0, 1);
1751 if (pattern[j+1] ==
'+')
1753 while (main_str[i + match_length] && strchr(char_match_pattern, (
int) main_str[i + match_length]))
1760 else if (main_str[i + match_length] && strchr(char_match_pattern, (
int) main_str[i + match_length]))
1771 else if ((j + 1) >= strlen(pattern))
1773 pattern_matched = 1;
1780 if (pattern_matched)
1782 uint32_t orig_main_str_len = (uint32_t)strlen(main_str);
1783 memmove(main_str + pattern_start, main_str + pattern_start + match_length,
1784 strlen(main_str + pattern_start + match_length));
1785 main_str[orig_main_str_len - match_length] = 0;
1806 if (!p_dev || !p_out_buf)
1813 "Automatic namespaceID discovery not supported in Windows. Using "
1815 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1826 char cmd_ret[60] = {0};
1827 char command[128] = {0};
1828 snprintf(command,
sizeof(command) - 1,
1829 "diskutil info %s | grep 'Media Name'", p_dev);
1831 cmd_fp = popen(command,
"r");
1837 if (fgets(cmd_ret,
sizeof(cmd_ret) - 1, cmd_fp) == NULL)
1846 if (strcasestr(cmd_ret,
"Quadra") != NULL)
1848 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1856#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
1857 ni_log(
NI_LOG_TRACE,
"The device is already considered as a block divice in Linux virtual machine with VirtIO driver.\n");
1858 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1862 snprintf(p_out_buf, out_buf_len,
"%s", p_dev);
1891 char cmd_ret[60] = {0};
1892 char command[128] = {0};
1893 snprintf(command,
sizeof(command) - 1,
1894 "diskutil info %s | grep 'Media Name'", p_dev);
1896 cmd_fp = popen(command,
"r");
1902 if (fgets(cmd_ret,
sizeof(cmd_ret) - 1, cmd_fp) == NULL)
1911 if (strcasestr(cmd_ret,
"Quadra") != NULL)
1937 if (*pp_table != NULL)
1998 int64_t timestamp, uint64_t data_info)
2023 uint64_t frame_info, int64_t *p_timestamp,
2024 int32_t threshold, int32_t print,
2030 __func__, frame_info);
2033 print, p_buffer_pool);
2040 "%s: timestamp=%" PRId64
", frame_info=%" PRId64
", err=%d\n",
2041 __func__, *p_timestamp, frame_info, err);
2051 threshold, print, p_buffer_pool);
2058 if (!pts_list || !dts_list)
2067 time_t now = time(NULL);
2099 uint64_t frame_offset, int64_t *p_timestamp,
2105 if (!p_table || !p_timestamp || !p_buffer_pool)
2112 __func__, frame_offset);
2114 err =
ni_queue_pop(&p_table->
list, frame_offset, p_timestamp, threshold, 0, p_buffer_pool);
2121 "%s: timestamp=%" PRId64
", frame_offset=%" PRId64
", err=%d\n",
2122 __func__, *p_timestamp, frame_offset, err);
2140 if (!p_queue || !name)
2210 "%s: queue overflow, remove oldest entry, count=%u\n",
2211 __func__, p_queue->
count);
2235 int64_t *p_timestamp, int32_t threshold,
2244 if (!p_queue || !p_timestamp)
2274 while (temp && !found)
2276 if (frame_info < temp->frame_info)
2295 temp_prev = temp->
p_prev;
2305 p_queue->
p_last = temp_prev;
2326 p_queue->
name, count);
2340 int64_t *p_timestamp, int32_t threshold,
2350 if (!p_queue || !p_timestamp)
2379 while ((temp) && (!found))
2381 if (llabs((
int)frame_info - (
int)temp->
frame_info) <= threshold)
2392 p_queue->
p_last = temp_prev;
2414 p_queue->
name, count);
2451 temp_next = temp->
p_next;
2458 left, p_queue->
count);
2477 char buff[20] = {0};
2496 struct tm *ltime = NULL;
2497 struct tm temp_time;
2503 strftime(buff, 20,
"%Y-%m-%d %H:%M:%S", ltime);
2533 if (!strcmp(p_str,
"1") || !strcmp(p_str,
"true") || !strcmp(p_str,
"yes"))
2538 if (!strcmp(p_str,
"0") || !strcmp(p_str,
"false") || !strcmp(p_str,
"no"))
2557 int32_t v = strtol(p_str, &end, 0);
2559 if (end == p_str || *end !=
'\0')
2577 double v = strtod(p_str, &end);
2579 if (end == p_str || *end !=
'\0')
2597 for (i = 0; names[i]; i++)
2599 if (!strcmp(arg, names[i]))
2619 return (tv.tv_sec * 1000000LL + tv.tv_usec);
2625 LARGE_INTEGER frequency;
2626 LARGE_INTEGER count;
2627 uint64_t time_sec, time_nsec;
2630 QueryPerformanceFrequency(&frequency);
2632 QueryPerformanceCounter(&count);
2634 time_sec = count.QuadPart / frequency.QuadPart;
2635 time_nsec = (count.QuadPart - time_sec * frequency.QuadPart) *
2636 1000000000LL / frequency.QuadPart;
2638 return (time_sec * 1000000000LL + time_nsec);
2641 clock_gettime(CLOCK_REALTIME, &ts);
2642 return ts.tv_sec * 1000000000LL + ts.tv_nsec;
2672 plane_stride[0] = ((
NI_MIN_WIDTH * factor + 127) / 128) * 128;
2674 (((
NI_MIN_WIDTH / (is_semiplanar ? 1 : 2) * factor) + 127) /
2677 plane_stride[2] = (is_semiplanar ? 0 : plane_stride[1]);
2680 width = ((width + 1) / 2) * 2;
2681 plane_stride[0] = ((width * factor + 127) / 128) * 128;
2683 (((width / (is_semiplanar ? 1 : 2) * factor) + 127) / 128) *
2685 plane_stride[2] = (is_semiplanar ? 0 : plane_stride[1]);
2694 plane_height[0] = ((height + 1) / 2) * 2;
2696 plane_height[1] = plane_height[2] = plane_height[0] / 2;
2721 plane_height[0] = ((height + 1) / 2) * 2;
2722 plane_height[1] = plane_height[2] = plane_height[0] / 2;
2730 plane_stride[2] = plane_stride[1];
2731 plane_stride[3] = 0;
2737 plane_stride[2] = plane_stride[1];
2738 plane_stride[3] = 0;
2743 plane_stride[1] = plane_stride[0];
2744 plane_stride[2] = 0;
2745 plane_stride[3] = 0;
2750 plane_stride[1] = plane_stride[0];
2751 plane_stride[2] = 0;
2752 plane_stride[3] = 0;
2758 plane_stride[1] = 0;
2759 plane_stride[2] = 0;
2760 plane_stride[3] = 0;
2765 plane_stride[1] = plane_stride[0];
2766 plane_stride[2] = 0;
2767 plane_stride[3] = 0;
2775 plane_height[1] = plane_height[2] = 0;
2778 plane_stride[1] = 0;
2779 plane_stride[2] = 0;
2780 plane_stride[3] = 0;
2821 width = ((width + 1) / 2) * 2;
2827 "%s dst_stride %d/%d/%d height %d/%d/%d pix_fmt %d\n",
2828 __func__, plane_stride[0], plane_stride[1], plane_stride[2],
2829 plane_height[0], plane_height[1], plane_height[2], pix_fmt);
2855 int frame_width,
int frame_height,
int factor,
2856 int is_semiplanar,
int conf_win_right,
2869 if (p_dst[i] == p_src[i])
2876 (src_height[i] < dst_height[i] ? src_height[i] : dst_height[i]);
2877 uint8_t *dst = p_dst[i];
2878 const uint8_t *src = (
const uint8_t *)p_src[i];
2883 if (0 == i || is_semiplanar)
2885 pad_len_bytes = dst_stride[i] - frame_width * factor;
2890 pad_len_bytes = dst_stride[i] - frame_width / 2 * factor;
2893 if (0 == pad_len_bytes && conf_win_right > 0)
2897 pad_len_bytes = conf_win_right * factor;
2902 pad_len_bytes = conf_win_right * factor / 2;
2907 "%s plane %d stride padding: %d pixel (%d bytes), copy height: "
2909 __func__, i, pad_len_bytes / factor, pad_len_bytes,
2912 for (; height > 0; height--)
2915 (src_stride[i] < dst_stride[i] ? src_stride[i] : dst_stride[i]));
2916 dst += dst_stride[i];
2926 uint8_t *tmp_dst = dst - pad_len_bytes;
2927 for (j = 0; j < pad_len_bytes / factor; j++)
2929 memcpy(tmp_dst, dst - pad_len_bytes - factor, factor);
2935 memset(dst - pad_len_bytes, *(dst - pad_len_bytes - 1),
2939 src += src_stride[i];
2943 int padding_height = dst_height[i] - src_height[i];
2944 if (padding_height > 0)
2948 src = dst - dst_stride[i];
2949 for (; padding_height > 0; padding_height--)
2951 memcpy(dst, src, dst_stride[i]);
2952 dst += dst_stride[i];
2978 int frame_width,
int frame_height,
int factor,
2979 int is_semiplanar,
int conf_win_right,
2986 "%s dst_stride %d/%d/%d src_stride %d/%d/%d dst_height "
2987 "%d/%d/%d src_height %d/%d/%d\n",
2988 __func__, dst_stride[0], dst_stride[1], dst_stride[2], src_stride[0],
2989 src_stride[1], src_stride[2], dst_height[0], dst_height[1],
2990 dst_height[2], src_height[0], src_height[1], src_height[2]);
2997 is_semiplanar, conf_win_right, dst_stride,
2998 dst_height, src_stride, src_height, i);
3024 int frame_width,
int frame_height,
3033 "%s frame_width %d frame_height %d factor %d conf_win_right %d "
3034 "dst_stride %d/%d/%d src_stride %d/%d/%d dst_height "
3035 "%d/%d/%d src_height %d/%d/%d pix_fmt %d\n",
3036 __func__, frame_width, frame_height, factor, conf_win_right,
3037 dst_stride[0], dst_stride[1], dst_stride[2], src_stride[0],
3038 src_stride[1], src_stride[2], dst_height[0], dst_height[1],
3039 dst_height[2], src_height[0], src_height[1], src_height[2],
3043 int is_semiplanar = 0;
3063 frame_width, frame_height, 4,
3064 is_semiplanar, conf_win_right,
3065 dst_stride, dst_height,
3066 src_stride, src_height,
3072 is_semiplanar, conf_win_right, dst_stride,
3073 dst_height, src_stride, src_height);
3105 int frame_width,
int frame_height,
3106 int factor,
int mode)
3109 int y_444p_linesize = frame_width * factor;
3110 int uv_444p_linesize = y_444p_linesize;
3115 if (p_dst0[0] == p_dst1[0] && p_dst0[1] == p_dst1[1] &&
3116 p_dst0[2] == p_dst1[2])
3123 for (i = 0; i < frame_height; i++)
3125 memcpy(&p_dst0[0][i * y_420p_linesize], &p_src[0][i * y_444p_linesize],
3134 for (i = 0; i < frame_height; i++)
3136 memcpy(&p_dst1[0][i * y_420p_linesize],
3137 &p_src[1][i * y_444p_linesize], y_444p_linesize);
3140 for (i = 0; i < frame_height / 2; i++)
3142 for (j = 0; j < frame_width * factor / 2; j += factor)
3146 memcpy(&p_dst0[1][i * uv_420p_linesize + j],
3147 &p_src[2][2 * i * uv_444p_linesize + 2 * j],
3149 memcpy(&p_dst0[2][i * uv_420p_linesize + j],
3150 &p_src[2][2 * i * uv_444p_linesize + (2 * j + factor)],
3153 memcpy(&p_dst1[1][i * uv_420p_linesize + j],
3154 &p_src[2][(2 * i + 1) * uv_444p_linesize + 2 * j],
3156 memcpy(&p_dst1[2][i * uv_420p_linesize + j],
3157 &p_src[2][(2 * i + 1) * uv_444p_linesize + (2 * j + factor)],
3165 for (i = 0; i < frame_height / 2; i++)
3167 for (j = 0; j < frame_width * factor / 2; j += factor)
3171 memcpy(&p_dst1[1][i * uv_420p_linesize + j],
3172 &p_src[1][2 * i * uv_444p_linesize + (2 * j + factor)],
3175 memcpy(&p_dst1[0][2 * i * uv_444p_linesize + 2 * j],
3176 &p_src[1][(2 * i + 1) * uv_444p_linesize + 2 * j],
3179 memcpy(&p_dst0[1][i * uv_420p_linesize + j],
3180 &p_src[1][2 * i * uv_444p_linesize + 2 * j],
3185 memcpy(&p_dst1[2][i * uv_420p_linesize + j],
3186 &p_src[2][2 * i * uv_444p_linesize + (2 * j + factor)],
3189 memcpy(&p_dst1[0][(2 * i + 1) * uv_444p_linesize + 2 * j],
3190 &p_src[2][(2 * i + 1) * uv_444p_linesize + 2 * j],
3193 memcpy(&p_dst0[2][i * uv_420p_linesize + j],
3194 &p_src[2][2 * i * uv_444p_linesize + 2 * j],
3217 int insert_bytes = 0;
3218 uint8_t *buf_curr = buf;
3219 uint8_t *buf_end = buf + size - 1;
3220 int zeros = 0, insert_ep3_byte;
3224 for (; buf_curr <= buf_end; buf_curr++)
3228 insert_ep3_byte = (*buf_curr <= 3);
3229 if (insert_ep3_byte)
3232 memmove(buf_curr + 1, buf_curr, buf_end - buf_curr + 1);
3253 return insert_bytes;
3270 int remove_bytes = 0;
3271 uint8_t *buf_curr = buf;
3272 uint8_t *buf_end = buf + size - 1;
3273 int zeros = 0, remove_ep3_byte;
3277 for (; buf_curr < buf_end; buf_curr++)
3281 remove_ep3_byte = (*buf_curr == 0x03 && *(buf_curr + 1) <= 3);
3282 if (remove_ep3_byte)
3285 memmove(buf_curr, buf_curr + 1, buf_end - buf_curr);
3305 return remove_bytes;
3313static uint32_t ni_ai_type_get_bytes(
const uint32_t type)
3339static void ni_ai_integer_convert(
const void *src,
void *dest,
3343 unsigned char all_zeros[] = {0x00, 0x00, 0x00, 0x00,
3344 0x00, 0x00, 0x00, 0x00};
3345 unsigned char all_ones[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
3346 uint32_t src_sz = ni_ai_type_get_bytes(src_dtype);
3347 uint32_t dest_sz = ni_ai_type_get_bytes(dst_dtype);
3348 unsigned char *buffer = all_zeros;
3350 if (((int8_t *)src)[src_sz - 1] & 0x80)
3354 memcpy(buffer, src, src_sz);
3355 memcpy(dest, buffer, dest_sz);
3358static float ni_ai_int8_to_fp32(
signed char val,
signed char fixedPointPos)
3360 float result = 0.0f;
3362 if (fixedPointPos > 0)
3364 result = (float)val * (1.0f / ((
float)(1 << fixedPointPos)));
3367 result = (float)val * ((
float)(1 << -fixedPointPos));
3373static float ni_ai_int16_to_fp32(int16_t val,
signed char fixedPointPos)
3375 float result = 0.0f;
3377 if (fixedPointPos > 0)
3379 result = (float)val * (1.0f / ((
float)(1 << fixedPointPos)));
3382 result = (float)val * ((
float)(1 << -fixedPointPos));
3388static float ni_ai_uint8_to_fp32(uint8_t val, int32_t zeroPoint,
float scale)
3390 float result = 0.0f;
3392 result = (float)(val - (uint8_t)zeroPoint) * scale;
3397static float ni_ai_fp16_to_fp32(
const short in)
3405 const _fp32_t magic = {(254 - 15) << 23};
3406 const _fp32_t infnan = {(127 + 16) << 23};
3409 o.u = (in & 0x7fff) << 13;
3411 if (o.f >= infnan.f)
3416 o.u |= (in & 0x8000) << 16;
3420static float ni_ai_affine_to_fp32(int32_t val, int32_t zeroPoint,
float scale)
3422 float result = 0.0f;
3423 result = ((float)val - zeroPoint) * scale;
3427static uint32_t ni_ai_get_tensor_size(int32_t *shape, uint32_t dim_num,
3433 if (NULL == shape || 0 == dim_num)
3438 for (i = 0; i < dim_num; i++)
3442 sz *= ni_ai_type_get_bytes(type);
3447static uint32_t ni_ai_get_element_num(int32_t *sizes, uint32_t num_of_dims,
3448 int32_t data_format)
3454 sz = ni_ai_get_tensor_size(sizes, num_of_dims, data_format);
3455 dsize = ni_ai_type_get_bytes(data_format);
3458 num = (uint32_t)(sz / dsize);
3467static int32_t ni_ai_type_is_integer(
const int32_t type)
3487static int32_t ni_ai_type_is_signed(
const int32_t type)
3507static void ni_ai_type_get_range(int32_t type,
double *max_range,
3514 bits = ni_ai_type_get_bytes(type) * 8;
3515 if (ni_ai_type_is_integer(type))
3517 if (ni_ai_type_is_signed(type))
3519 from = (double)(-(1L << (bits - 1)));
3520 to = (double)((1UL << (bits - 1)) - 1);
3524 to = (double)((1UL << bits) - 1);
3527 if (NULL != max_range)
3531 if (NULL != min_range)
3537static inline double ni_abs(
double x)
3539 return x < 0 ? -x : x;
3542static double ni_ai_copy_sign(
double number,
double sign)
3544 double value = ni_abs(number);
3545 return (sign > 0) ? value : (-value);
3548static inline int ni_ai_math_floorf(
double x)
3550 return x >= 0 ? (int)x : (int)x - 1;
3553static double ni_ai_rint(
double x)
3555#define _EPSILON 1e-8
3561 decimal = x - intpart;
3562 inter = (double)intpart;
3564 if (ni_abs((ni_abs(decimal) - 0.5f)) <
_EPSILON)
3566 inter += (int32_t)(inter) % 2;
3569 return ni_ai_copy_sign(ni_ai_math_floorf(ni_abs(x) + 0.5f), x);
3575static int32_t ni_ai_fp32_to_dfp(
const float in,
const signed char fl,
3581 ni_ai_type_get_range(type, &max_range, &min_range);
3584 data = (int32_t)ni_ai_rint(in * (
float)(1 << fl));
3587 data = (int32_t)ni_ai_rint(in * (1.0f / (
float)(1 << -fl)));
3589 data = ni_min(data, (int32_t)max_range);
3590 data = ni_max(data, (int32_t)min_range);
3595static int32_t ni_ai_fp32_to_affine(
const float in,
const float scale,
3596 const int zero_point,
const int32_t type)
3601 ni_ai_type_get_range(type, &max_range, &min_range);
3602 data = (int32_t)(ni_ai_rint(in / scale) + zero_point);
3603 data = ni_max((int32_t)min_range, ni_min((int32_t)max_range, data));
3607static unsigned short ni_ai_fp32_to_bfp16_rtne(
float in)
3615 memcpy(&fp32, &in,
sizeof(uint32_t));
3619 uint32_t rounding_bias = 0x7fff + lsb;
3621 if ((
float)0x7FC00000 == in)
3626 fp32 += rounding_bias;
3627 out = (
unsigned short)(fp32 >> 16);
3633static unsigned short ni_ai_fp32_to_fp16(
float in)
3641 memcpy((uint8_t *)&fp32, (uint8_t *)&in,
sizeof(uint32_t));
3643 t1 = (fp32 & 0x80000000u) >> 16;
3644 t2 = (fp32 & 0x7F800000u) >> 13;
3645 t3 = (fp32 & 0x007FE000u) >> 13;
3647 if (t2 >= 0x023c00u)
3650 }
else if (t2 <= 0x01c000u)
3656 fp16 = t1 | t2 | t3;
3659 return (
unsigned short)fp16;
3662static void ni_ai_float32_to_dtype(
float src,
unsigned char *dst,
3663 const int32_t data_type,
3664 const int32_t quant_format,
3665 signed char fixed_point_pos,
float tf_scale,
3671 memcpy(dst, &src,
sizeof(
float));
3674 *(int16_t *)dst = ni_ai_fp32_to_fp16(src);
3677 *(int16_t *)dst = ni_ai_fp32_to_bfp16_rtne(src);
3683 int32_t dst_value = 0;
3684 switch (quant_format)
3688 ni_ai_fp32_to_dfp(src, fixed_point_pos, data_type);
3691 dst_value = ni_ai_fp32_to_affine(src, tf_scale, tf_zerop,
3695 dst_value = (int32_t)src;
3717 if (!p_network || !dst || dst_len == 0 || !p_packet || !p_packet->
p_data)
3741static int open_tensor_rsrc_file(
struct tensor_rsrc *rsrc,
void *data,
3745 ni_fopen(&f, (
const char *)data,
"r");
3747 return rsrc->
private ? 0 : -1;
3750static int get_tensor_rsrc_from_file(
struct tensor_rsrc *rsrc,
float *value)
3752 FILE *fp = (FILE *)rsrc->
private;
3764static void close_tensor_rsrc_file(
struct tensor_rsrc *rsrc)
3766 FILE *fp = (FILE *)rsrc->
private;
3770static int open_tensor_rsrc_rawdata(
struct tensor_rsrc *rsrc,
void *data,
3779static int get_tensor_rsrc_from_rawdata(
struct tensor_rsrc *rsrc,
float *value)
3781 float *tensors = (
float *)rsrc->
private;
3783 if (rsrc->next_idx < rsrc->total_num)
3785 *value = tensors[rsrc->next_idx];
3793static void close_tensor_rsrc_rawdata(
struct tensor_rsrc *rsrc)
3798 uint8_t *dst, uint32_t dst_len,
void *tensor, uint32_t src_len,
3800 int (*open_tensor_rsrc)(
struct tensor_rsrc *,
void *, uint32_t),
3801 int (*get_tensor_rsrc)(
struct tensor_rsrc *,
float *),
3804 uint8_t *tensor_data;
3808 int32_t data_format;
3809 int32_t quant_format;
3810 int32_t fixed_point_pos;
3821 sz = ni_ai_get_element_num((int32_t *)p_param->
sizes, p_param->
num_of_dims,
3823 stride = ni_ai_type_get_bytes(data_format);
3825 if (sz * stride *
sizeof(uint8_t) != dst_len)
3836 if (open_tensor_rsrc(rsrc, tensor, src_len) != 0)
3842 memset(dst, 0, sz * stride *
sizeof(uint8_t));
3844 for (i = 0; i < sz; i++)
3846 if (get_tensor_rsrc(rsrc, &fval) == 0)
3848 ni_ai_float32_to_dtype(fval, &tensor_data[stride * i], data_format,
3849 quant_format, fixed_point_pos, tf_scale,
3857 close_tensor_rsrc(rsrc);
3863 const char *tensor_file,
3866 return ni_network_tensor_to_data(
3867 dst, dst_len, (
void *)tensor_file, 0, p_param, open_tensor_rsrc_file,
3868 get_tensor_rsrc_from_file, close_tensor_rsrc_file);
3876 return ni_network_tensor_to_data(
3877 dst, dst_len, src, src_len, p_param, open_tensor_rsrc_rawdata,
3878 get_tensor_rsrc_from_rawdata, close_tensor_rsrc_rawdata);
3889 float *dst_float = dst;
3892 if (!src || src_len == 0 || !dst || dst_len == 0 || !p_param)
3897 type_size = ni_ai_type_get_bytes(p_param->
data_format);
3904 ele_size *= p_param->
sizes[i];
3907 if (dst_len != ele_size *
sizeof(
float))
3925 for (i = 0; i < ele_size; i++, data += type_size)
3927 dst_float[i] = ni_ai_int8_to_fp32(*data, fix_pos);
3934 for (i = 0; i < ele_size; i++, data += type_size)
3936 int32_t src_value = 0;
3937 ni_ai_integer_convert(data, &src_value,
3941 ni_ai_affine_to_fp32(src_value, zero_point, scale);
3945 for (i = 0; i < ele_size; i++, data += type_size)
3947 void *float_data = (
void *)data;
3948 dst_float[i] = *((
float *)float_data);
3953 for (i = 0; i < ele_size; i++, data += type_size)
3955 dst_float[i] = ni_ai_fp16_to_fp32(*((
short *)data));
3962 for (i = 0; i < ele_size; i++, data += type_size)
3964 dst_float[i] = ni_ai_uint8_to_fp32(*data, zero_point, scale);
3970 for (i = 0; i < ele_size; i++, data += type_size)
3972 dst_float[i] = ni_ai_int16_to_fp32(*((
short *)data), fix_pos);
3976 for (i = 0; i < ele_size; i++, data += type_size)
3978 void *float_data = (
void *)data;
3979 dst_float[i] = *((
float *)float_data);
3991 return ni_ai_get_tensor_size((int32_t *)p_param->
sizes,
3997 uint32_t i, dims = 1;
4001 dims *= p_param->
sizes[i];
4009#define SHA256_BLOCK_SIZE 32
4019#define ROTLEFT(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
4020#define ROTRIGHT(a, b) (((a) >> (b)) | ((a) << (32 - (b))))
4022#define CH(x, y, z) (((x) & (y)) ^ (~(x) & (z)))
4023#define MAJ(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
4024#define EP0(x) (ROTRIGHT(x, 2) ^ ROTRIGHT(x, 13) ^ ROTRIGHT(x, 22))
4025#define EP1(x) (ROTRIGHT(x, 6) ^ ROTRIGHT(x, 11) ^ ROTRIGHT(x, 25))
4026#define SIG0(x) (ROTRIGHT(x, 7) ^ ROTRIGHT(x, 18) ^ ((x) >> 3))
4027#define SIG1(x) (ROTRIGHT(x, 17) ^ ROTRIGHT(x, 19) ^ ((x) >> 10))
4029static const uint32_t ui32k[64] = {
4030 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1,
4031 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
4032 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, 0xe49b69c1, 0xefbe4786,
4033 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
4034 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147,
4035 0x06ca6351, 0x14292967, 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
4036 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b,
4037 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
4038 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a,
4039 0x5b9cca4f, 0x682e6ff3, 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
4040 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2};
4044 uint32_t ui32a, ui32b, ui32c, ui32d, ui32e, ui32f, ui32g, ui32h, ui32i,
4045 ui32j, ui32t1, ui32t2, ui32m[64];
4047 for (ui32i = 0, ui32j = 0; ui32i < 16; ++ui32i, ui32j += 4)
4048 ui32m[ui32i] = (aui8Data[ui32j] << 24) | (aui8Data[ui32j + 1] << 16) |
4049 (aui8Data[ui32j + 2] << 8) | (aui8Data[ui32j + 3]);
4050 for (; ui32i < 64; ++ui32i)
4051 ui32m[ui32i] =
SIG1(ui32m[ui32i - 2]) + ui32m[ui32i - 7] +
4052 SIG0(ui32m[ui32i - 15]) + ui32m[ui32i - 16];
4063 for (ui32i = 0; ui32i < 64; ++ui32i)
4065 ui32t1 = ui32h +
EP1(ui32e) +
CH(ui32e, ui32f, ui32g) + ui32k[ui32i] +
4067 ui32t2 =
EP0(ui32a) +
MAJ(ui32a, ui32b, ui32c);
4071 ui32e = ui32d + ui32t1;
4075 ui32a = ui32t1 + ui32t2;
4107 for (ui32i = 0; ui32i < ui32Length; ++ui32i)
4155 for (ui32i = 0; ui32i < 4; ++ui32i)
4158 (psCtx->
aui32State[0] >> (24 - ui32i * 8)) & 0x000000ff;
4159 aui8Hash[ui32i + 4] =
4160 (psCtx->
aui32State[1] >> (24 - ui32i * 8)) & 0x000000ff;
4161 aui8Hash[ui32i + 8] =
4162 (psCtx->
aui32State[2] >> (24 - ui32i * 8)) & 0x000000ff;
4163 aui8Hash[ui32i + 12] =
4164 (psCtx->
aui32State[3] >> (24 - ui32i * 8)) & 0x000000ff;
4165 aui8Hash[ui32i + 16] =
4166 (psCtx->
aui32State[4] >> (24 - ui32i * 8)) & 0x000000ff;
4167 aui8Hash[ui32i + 20] =
4168 (psCtx->
aui32State[5] >> (24 - ui32i * 8)) & 0x000000ff;
4169 aui8Hash[ui32i + 24] =
4170 (psCtx->
aui32State[6] >> (24 - ui32i * 8)) & 0x000000ff;
4171 aui8Hash[ui32i + 28] =
4172 (psCtx->
aui32State[7] >> (24 - ui32i * 8)) & 0x000000ff;
4206 if (p_dst[0] == p_src[0] && p_dst[1] == p_src[1] && p_dst[2] == p_src[2] &&
4207 p_dst[3] == p_src[3])
4229 return libxcoder_api_ver;
4232#ifndef DEPRECATION_AS_ERROR
4241 static char compat_fw_api_ver_str[5] =
"";
4243 if (!compat_fw_api_ver_str[0])
4245 compat_fw_api_ver_str[0] = \
4247 compat_fw_api_ver_str[1] =
'.';
4248 compat_fw_api_ver_str[2] = \
4251 compat_fw_api_ver_str[3] = \
4254 compat_fw_api_ver_str[3] = 0;
4255 compat_fw_api_ver_str[4] = 0;
4257 return &compat_fw_api_ver_str[0];
4274 if (!ver_str || !fmt_str) {
4278 fmt_str[0] = ver_str[0];
4280 fmt_str[2] = ver_str[1];
4282 if ((ver_str[0] <
'6' || (ver_str[0] ==
'6' && ver_str[1] <=
'q')) ||
4283 (ver_str[2] == 0)) {
4286 fmt_str[3] = ver_str[2];
4308 if (ver1[index] > ver2[index])
4310 else if (ver1[index] < ver2[index])
4315 if (ver1[index] > ver2[index])
4317 else if (ver1[index] < ver2[index])
4320 if ((ver1[index - 1] <
'6') || ((ver1[index - 1] ==
'6') && (ver1[index] <=
'q')))
4325 if (ver1[index] > ver2[index])
4327 else if (ver1[index] < ver2[index])
4340 static char release_ver_str[6] =
"";
4342 if (!release_ver_str[0])
4345 release_ver_str[1] =
'.';
4347 release_ver_str[3] =
'.';
4349 release_ver_str[5] = 0;
4351 return &release_ver_str[0];
4365 if (rc == ni_err_rc_description[i].rc)
4367 return ni_err_rc_description[i].
txt;
4370 return "rc not supported";
4385 if (!p_str || !key || !value)
4390 char *p = strchr(p_str,
'=');
4399 int64_t key_len = p - p_str;
4420 char key[64], value[64];
4421 char *curr = xcoderParams, *colon_pos;
4426 colon_pos = strchr(curr,
':');
4433 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4437 "Error: xcoder-params p_config key/value not "
4466 curr = colon_pos + 1;
4469 curr += strlen(curr);
4494 char key[64], value[64];
4495 char *curr = xcoderGop, *colon_pos;
4500 colon_pos = strchr(curr,
':');
4507 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4511 "Error: xcoder-params p_config key/value not "
4540 curr = colon_pos + 1;
4543 curr += strlen(curr);
4564 char key[64], value[64];
4565 char *curr = xcoderParams, *colon_pos;
4570 colon_pos = strchr(curr,
':');
4577 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
4581 "Error: decoder-params p_config key/value not "
4610 curr = colon_pos + 1;
4613 curr += strlen(curr);
4635 rc = InitializeCriticalSectionEx(mutex, 0, CRITICAL_SECTION_NO_DEBUG_INFO);
4646 ni_pthread_mutexattr_t attr;
4648 rc = pthread_mutexattr_init(&attr);
4654 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
4656 return pthread_mutex_init(mutex, &attr);
4671 DeleteCriticalSection(mutex);
4674 return pthread_mutex_destroy(mutex);
4692 EnterCriticalSection(mutex);
4694 rc = pthread_mutex_lock(mutex);
4718 LeaveCriticalSection(mutex);
4720 rc = pthread_mutex_unlock(mutex);
4731static unsigned __stdcall __thread_worker(
void *arg)
4733 ni_pthread_t *t = (ni_pthread_t *)arg;
4734 t->rc = t->start_routine(t->arg);
4751 void *(*start_routine)(
void *),
void *arg)
4754 thread->start_routine = start_routine;
4758 (
void *)CreateThread(NULL, 0, win32thread_worker, thread, 0, NULL);
4760 (
void *)_beginthreadex(NULL, 0, __thread_worker, thread, 0, NULL);
4762 return !thread->handle;
4764 return pthread_create(thread, attr, start_routine, arg);
4780 DWORD rc = WaitForSingleObject(thread.handle, INFINITE);
4781 if (rc != WAIT_OBJECT_0)
4783 if (rc == WAIT_ABANDONED)
4789 *value_ptr = thread.rc;
4790 CloseHandle(thread.handle);
4793 return pthread_join(thread, value_ptr);
4807 const ni_pthread_condattr_t *attr)
4810 InitializeConditionVariable(cond);
4813 return pthread_cond_init(cond, attr);
4831 return pthread_cond_destroy(cond);
4846 WakeAllConditionVariable(cond);
4849 return pthread_cond_broadcast(cond);
4865 SleepConditionVariableCS(cond, mutex, INFINITE);
4868 return pthread_cond_wait(cond, mutex);
4883 WakeConditionVariable(cond);
4886 return pthread_cond_signal(cond);
4901 ni_pthread_mutex_t *mutex,
4902 const struct timespec *abstime)
4905 int64_t abs_ns = abstime->tv_sec * 1000000000LL + abstime->tv_nsec;
4908 if (!SleepConditionVariableCS(cond, mutex, t))
4910 DWORD err = GetLastError();
4911 if (err == ERROR_TIMEOUT)
4918 return pthread_cond_timedwait(cond, mutex, abstime);
4939 return pthread_sigmask(how, set, oldset);
4957 return "General Error";
4959 return "Not Initialized";
4961 return "Already Initialized";
4965 return "Resource Not Available";
4967 return "Create Network Failed";
4969 return "Input Buffer Full";
4971 return "Output Buffer Empty";
4973 return "Invalid Params";
4975 return "Error Start Network";
4977 return "Erorr Set Inout";
4979 return "Bad Option";
4983 return "Context Not Available";
4985 return "Model Not Found";
4989 return "Invalid Address";
4991 return "Out Of Memory";
4995 return "Invalid Instance";
4997 return "IO Not Allowed";
4999 return "Network Not Ready";
5001 return "Other Error";
5016 float current_ma,voltage_mv;
5023 snprintf(pcb_config,
sizeof(pcb_config),
"%.2s", &serial_number[2]);
5025 float current_value = (float)current_data;
5026 voltage_mv = 12000.0f;
5027 if (strncmp(pcb_config,
"A1", 2) == 0)
5031 else if ((strncmp(pcb_config,
"A2", 2) == 0) || (strncmp(pcb_config,
"A3", 2) == 0))
5035 else if ((strncmp(pcb_config,
"AA", 2) == 0) || (strncmp(pcb_config,
"AB", 2) == 0))
5039 else if (strncmp(pcb_config,
"U0", 2) == 0)
5044 else if ((strncmp(pcb_config,
"U1", 2) == 0) || (strncmp(pcb_config,
"U2", 2) == 0) || (strncmp(pcb_config,
"U3", 2) == 0))
5048 else if (strncmp(pcb_config,
"UA", 2) == 0)
5052 else if (strncmp(pcb_config,
"S0", 2) == 0)
5056 else if ((strncmp(pcb_config,
"M0", 2) == 0) || (strncmp(pcb_config,
"M1", 2) == 0))
5059 voltage_mv = 3300.0f;
5061 else if (strncmp(pcb_config,
"M", 1) == 0)
5064 voltage_mv = 3300.0f;
5070 power_mw = (uint32_t)((voltage_mv * current_ma) / 1000.0);
5093static int ni_device_size_precheck_ioctl(
const char *p_dev,
const uint64_t size_needed)
5095#if defined(_WIN32) || !defined(BLKGETSIZE64)
5110 fd = open(p_dev, O_RDONLY);
5117 call_ret = ioctl(fd, BLKGETSIZE64, &bytes);
5122 else if (bytes < size_needed)
5154static int ni_device_vendor_id_precheck(
const char *p_dev)
5168 const char *vendor_path_devs[] = {
"/sys/class/block/%s/device/vendor",
"/sys/class/block/%s/device/device/vendor"};
5170 const char *last_slash = strrchr(p_dev,
'/');
5171 const char *device_name = (last_slash ? (last_slash + 1) : p_dev);
5173 const size_t path_len = strlen(p_dev);
5175 for (
size_t i = 0; i <
sizeof(vendor_path_devs)/
sizeof(vendor_path_devs[0]) && ret == 0; ++i)
5177 size_t template_len = strlen(vendor_path_devs[i]);
5178 char *vendor_path = (
char *)calloc(1, template_len + path_len);
5183 snprintf(vendor_path, template_len + path_len, vendor_path_devs[i], device_name);
5185 int fd = open(vendor_path, O_RDONLY);
5188 char vendor_id[10] = {0};
5189 int read_size = read(fd, vendor_id,
sizeof(vendor_id));
5190 if (read_size >= 4 && (
size_t)read_size <
sizeof(vendor_id))
5192 char *find_1d82 = strstr(vendor_id,
"1d82");
5236static int ni_device_size_precheck_system_information(
const char *p_dev,
const uint64_t size_needed)
5251 const char block_path_dev[] =
"/sys/class/block/%s/size";
5252 const char logical_block_size_path_dev[] =
"/sys/class/block/%s/queue/logical_block_size";
5254 const char *last_slash = strrchr(p_dev,
'/');
5255 const char *device_name = (last_slash ? (last_slash + 1) : p_dev);
5257 const size_t path_len = strlen(p_dev);
5260 int logical_block_fd = -1;
5262 char *block_path = (
char *)calloc(1,
sizeof(block_path_dev) + path_len);
5263 char *logical_block_size_path = (
char *)calloc(1,
sizeof(logical_block_size_path_dev) + path_len);
5265 if (!block_path || !logical_block_size_path)
5270 snprintf(block_path,
sizeof(block_path_dev) + path_len, block_path_dev, device_name);
5271 snprintf(logical_block_size_path,
sizeof(logical_block_size_path_dev) + path_len, logical_block_size_path_dev, device_name);
5273 size_fd = open(block_path, O_RDONLY);
5274 logical_block_fd = open(logical_block_size_path, O_RDONLY);
5276 if (size_fd < 0 || logical_block_fd < 0)
5281 char this_size_str [20] = {0};
5282 char this_block_size_str [20] = {0};
5284 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)
5290 char *endptr1 = NULL;
5291 char *endptr2 = NULL;
5293 unsigned long long this_size = strtoull(this_size_str, &endptr1, 10);
5294 unsigned long long this_block_size = strtoull(this_block_size_str, &endptr2, 10);
5296 if (errno == 0 && endptr1 != this_size_str && endptr2 != this_block_size_str)
5298 if (this_size * this_block_size >= size_needed)
5304 ni_log2(NULL,
NI_LOG_DEBUG,
"%s() read size check failed. size: %" PRIu64
"\n", __func__, this_size * this_block_size);
5315 if (logical_block_size_path)
5317 free(logical_block_size_path);
5324 if (logical_block_fd >= 0)
5326 close(logical_block_fd);
5363 const size_t path_len = strlen(p_dev);
5370 ret = ni_device_size_precheck_ioctl(p_dev, SIZE_NEEDED);
5380 ret = ni_device_vendor_id_precheck(p_dev);
5390 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_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)
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)
Convert string to integer.
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...
struct _ni_err_rc_txt_entry ni_err_rc_txt_entry_t
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_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