35#if __linux__ || __APPLE__
46#include <sys/syslimits.h>
53static const char *ni_codec_format_str[] = {
"H.264",
"H.265",
"VP9",
"JPEG",
55static const char *ni_dec_name_str[] = {
"h264_ni_quadra_dec",
"h265_ni_quadra_dec",
56 "vp9_ni_quadra_dec",
"jpeg_ni_quadra_dec"};
57static const char *ni_enc_name_str[] = {
"h264_ni_quadra_enc",
"h265_ni_quadra_enc",
"empty",
58 "jpeg_ni_quadra_enc",
"av1_ni_quadra_enc"};
60#ifndef DEPRECATION_AS_ERROR
68static bool is_str_in_str_array(
const char key[],
74 for (i = 0; i < array_size; i++)
76 if (0 == strcmp(key, arr[i]))
93 for (
int xcoder_index_1 = 0;
115 "no, possible missing features" :
"yes");
132 for (
int xcoder_index_2 = 0;
164 int xcoder_dev_count = 0;
166 int curr_dev_count = 0;
169 char **xcoder_refresh_dev_names = NULL;
170 int xcoder_refresh_dev_count = 0;
192 ni_strcpy(xcoder_dev_names[i],
sizeof(xcoder_dev_names[i]),
213 if (xcoder_dev_count > 0)
215 xcoder_refresh_dev_names = (
char **)malloc(xcoder_dev_count *
217 for (i = 0; i < xcoder_dev_count; i++)
222 xcoder_refresh_dev_count = xcoder_dev_count;
226 xcoder_refresh_dev_names, xcoder_refresh_dev_count);
227 if (0 == curr_dev_count)
231 int devices_removed = 0;
232 int devices_added = 0;
234 for (i = 0; i < xcoder_dev_count; i++)
236 if (!is_str_in_str_array(xcoder_dev_names[i], curr_dev_names,
240 "\n\n%d. %s NOT in current scanned list, removing !\n", i,
241 xcoder_dev_names[i]);
246 xcoder_dev_names[i]);
251 xcoder_dev_names[i]);
257 for (i = 0; i < curr_dev_count; i++)
259 if (!is_str_in_str_array(curr_dev_names[i], xcoder_dev_names,
276 if (devices_added != devices_removed)
280 for (i = 0; i < xcoder_dev_count; i++)
284 for (i = 0; i < curr_dev_count; i++)
289 if (xcoder_refresh_dev_names) {
290 for (i = 0; i < xcoder_refresh_dev_count; i++)
291 free(xcoder_refresh_dev_names[i]);
292 free(xcoder_refresh_dev_names);
293 xcoder_refresh_dev_names = NULL;
300#include <utils/Mutex.h>
303android::sp<INidec>
service = NULL;
304static android::Mutex gLock;
316 android::Mutex::Autolock _l(gLock);
319 service = INidec::tryGetService();
333#ifndef DEPRECATION_AS_ERROR
354 if ((ni_devices == NULL)||(max_handles == 0))
380 int max_handles,
char **xcoder_refresh_dev_names,
381 int xcoder_refresh_dev_count)
383 if ((ni_devices == NULL)||(max_handles == 0))
402 HANDLE map_file_handle = NULL;
403 HANDLE mutex_handle = NULL;
406 mutex_handle = CreateMutex(NULL,
411 if (NULL == mutex_handle)
418 if (WAIT_ABANDONED == WaitForSingleObject(mutex_handle, INFINITE))
423 map_file_handle = OpenFileMapping(
429 if (NULL == map_file_handle)
431 ReleaseMutex(mutex_handle);
432 CloseHandle(mutex_handle);
446 if (NULL == p_device_queue)
448 ReleaseMutex(mutex_handle);
449 CloseHandle(mutex_handle);
450 CloseHandle(map_file_handle);
455 if (NULL == p_device_pool)
461 UnmapViewOfFile(p_device_queue);
465 p_device_pool->
lock = mutex_handle;
469 ReleaseMutex(mutex_handle);
470 CloseHandle(map_file_handle);
471 return p_device_pool;
492int ni_rsrc_init(
int should_match_rev,
int timeout_seconds)
496 int number_of_devices = 0;
497 uint32_t runtime = 0;
498 while (0 == number_of_devices)
508 else if (0 == number_of_devices)
516 if (timeout_seconds == 0) {
518 "and exit without wait\n");
523 if (runtime >= (uint32_t)timeout_seconds)
557 char shm_name[32] = { 0 };
558 char lck_name[32] = { 0 };
561 HANDLE map_file_handle = NULL;
562 HANDLE mutex_handle = NULL;
568 mutex_handle = CreateMutex(NULL,
572 if (NULL == mutex_handle)
575 p_device_context = NULL;
579 if (WAIT_ABANDONED == WaitForSingleObject(mutex_handle, INFINITE))
582 "obtain mutex: %p\n", mutex_handle);
585 map_file_handle = OpenFileMapping(
591 if (NULL == map_file_handle)
595 p_device_context = NULL;
607 if (NULL == p_device_queue)
612 p_device_context = NULL;
617 if (NULL == p_device_context)
623 p_device_context = NULL;
628 p_device_context->
lock = mutex_handle;
633 if (NULL == p_device_context)
635 if (NULL != p_device_queue)
637 UnmapViewOfFile(p_device_queue);
639 if (NULL != mutex_handle)
641 ReleaseMutex(mutex_handle);
642 CloseHandle(mutex_handle);
645 if (NULL != map_file_handle)
647 CloseHandle(map_file_handle);
651 ReleaseMutex(mutex_handle);
652 CloseHandle(map_file_handle);
655 return p_device_context;
658#elif __linux__ || __APPLE__
660#define DEV_NAME_PREFIX "rdisk"
661#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
662#define DEV_NAME_PREFIX "vd"
664#define DEV_NAME_PREFIX "nvme"
667#ifndef DEPRECATION_AS_ERROR
686#if defined(_ANDROID) || defined(__OPENHARMONY__)
687#define ANDROID_MAX_DIR_NUM 2
688 int android_dir_num = 0;
689 const char* dir_name_array[ANDROID_MAX_DIR_NUM];
690 dir_name_array[0] =
"/dev";
691 dir_name_array[1] =
"/dev/block";
693 const char* dir_name =
"/dev";
695 int i, xcoder_device_cnt = 0;
697 struct dirent* in_file;
700 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE;
704 if ((ni_devices == NULL)||(max_handles == 0))
710 int nvme_dev_cnt = 0;
716 const char *pattern =
"^rdisk[0-9]+$";
717#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
718 const char *pattern =
"^vd[a-z]$";
720 const char *pattern =
"^nvme[0-9]+(c[0-9]+)?n[0-9]+$";
723 if(regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB)) {
728#if defined(_ANDROID) || defined(__OPENHARMONY__)
731 while(xcoder_device_cnt == 0 && android_dir_num < ANDROID_MAX_DIR_NUM)
733 const char *dir_name = dir_name_array[android_dir_num];
738 dev_handle = NI_INVALID_DEVICE_HANDLE;
740 size_t size_of_nvme_devices_x =
sizeof(nvme_devices)/
sizeof(nvme_devices[0]);
741 for(
size_t dimx = 0; dimx < size_of_nvme_devices_x; ++dimx)
743 memset(nvme_devices[dimx], 0,
sizeof(nvme_devices[0]));
748 if (NULL == (FD = opendir(dir_name)))
751#if defined(_ANDROID) || defined(__OPENHARMONY__)
753 if(android_dir_num < ANDROID_MAX_DIR_NUM)
767 while ((in_file = readdir(FD)))
770 if (!strcmp(in_file->d_name,
".") || !strcmp(in_file->d_name,
".."))
777 if (!strncmp(in_file->d_name, DEV_NAME_PREFIX, strlen(DEV_NAME_PREFIX)))
779 if (nvme_dev_cnt < 200)
781 int write_len = snprintf(nvme_devices[nvme_dev_cnt],
783 dir_name, in_file->d_name);
787 "ERROR: failed to copy device %d name %s\n",
788 nvme_dev_cnt, in_file->d_name);
793 skip_this = regexec(®ex, in_file->d_name, 0, NULL, 0);
800 "%s/%s", dir_name, in_file->d_name) < 0)
803 "ERROR: failed an snprintf() in "
804 "ni_rsrc_get_local_device_list()\n");
832 if (NI_INVALID_DEVICE_HANDLE != dev_handle)
836 &device_capabilites);
839 if (is_supported_xcoder(
842 ni_devices[xcoder_device_cnt][0] =
'\0';
855 (max_handles <= xcoder_device_cnt))
858 "Disregarding some Netint devices on system over "
859 "limit of NI_MAX_DEVICE_CNT(%d) or max_handles(%d)\n",
866#if defined(_ANDROID) || defined(__OPENHARMONY__)
874 if (0 == xcoder_device_cnt)
876 ni_log(
NI_LOG_INFO,
"Found %d NVMe devices on system, none of them xcoder\n", nvme_dev_cnt);
877 for (i = 0; i < nvme_dev_cnt; i++)
885 return xcoder_device_cnt;
906 int max_handles,
char **xcoder_refresh_dev_names,
907 int xcoder_refresh_dev_count)
911#define ANDROID_MAX_DIR_NUM 2
912 int android_dir_num = 0;
913 const char* dir_name_array[ANDROID_MAX_DIR_NUM];
914 dir_name_array[0] =
"/dev";
915 dir_name_array[1] =
"/dev/block";
917 const char* dir_name =
"/dev";
919 int i, xcoder_device_cnt = 0;
921 struct dirent* in_file;
924 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE;
926 bool device_in_ctxt =
false;
928 if ((ni_devices == NULL)||(max_handles == 0))
934 int nvme_dev_cnt = 0;
940 const char *pattern =
"^rdisk[0-9]+$";
941#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
942 const char *pattern =
"^vd[a-z]$";
944 const char *pattern =
"^nvme[0-9]+(c[0-9]+)?n[0-9]+$";
947 if(regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB)) {
955 while(xcoder_device_cnt == 0 && android_dir_num < ANDROID_MAX_DIR_NUM)
957 const char *dir_name = dir_name_array[android_dir_num];
961 device_in_ctxt =
false;
962 dev_handle = NI_INVALID_DEVICE_HANDLE;
964 size_t size_of_nvme_devices_x =
sizeof(nvme_devices)/
sizeof(nvme_devices[0]);
965 for(
size_t dimx = 0; dimx < size_of_nvme_devices_x; ++dimx)
967 memset(nvme_devices[dimx], 0,
sizeof(nvme_devices[0]));
972 if (NULL == (FD = opendir(dir_name)))
977 if(android_dir_num < ANDROID_MAX_DIR_NUM)
991 while ((in_file = readdir(FD)))
994 if (!strcmp(in_file->d_name,
".") || !strcmp(in_file->d_name,
".."))
1001 if (!strncmp(in_file->d_name, DEV_NAME_PREFIX, strlen(DEV_NAME_PREFIX)))
1003 if (nvme_dev_cnt < 200)
1005 int write_len = snprintf(nvme_devices[nvme_dev_cnt],
1007 dir_name, in_file->d_name);
1011 "ERROR: failed to copy device %d name %s\n",
1012 nvme_dev_cnt, in_file->d_name);
1017 skip_this = regexec(®ex, in_file->d_name, 0, NULL, 0);
1024 "%s/%s", dir_name, in_file->d_name) < 0)
1027 "ERROR: failed an snprintf() in "
1028 "ni_rsrc_get_local_device_list2()\n");
1035 device_in_ctxt =
false;
1036 for (
int j = 0; j < xcoder_refresh_dev_count; j++)
1040 xcoder_refresh_dev_names[j]))
1042 device_in_ctxt =
true;
1056 if (NI_INVALID_DEVICE_HANDLE != dev_handle)
1059 &device_capabilites, device_in_ctxt);
1062 if (is_supported_xcoder(
1065 ni_devices[xcoder_device_cnt][0] =
'\0';
1068 xcoder_device_cnt++;
1077 (max_handles <= xcoder_device_cnt))
1080 "Disregarding some Netint devices on system over "
1081 "limit of NI_MAX_DEVICE_CNT(%d) or max_handles(%d)\n",
1096 if (0 == xcoder_device_cnt)
1098 ni_log(
NI_LOG_INFO,
"Found %d NVMe devices on system, none of them xcoder\n", nvme_dev_cnt);
1099 for (i = 0; i < nvme_dev_cnt; i++)
1105 return xcoder_device_cnt;
1118 ni_rsrc_shm_state state = NI_RSRC_SHM_IS_INVALID;
1119 int flags = O_RDWR | O_CLOEXEC;
1120 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
1122 ni_lock_handle_t lock;
1126 flags, mode, (
int *)&lock) < 0) {
1134 (
int *)&shm_fd) < 0) {
1142 (
void **)&p_device_queue)) < 0) {
1148 if (! p_device_pool) {
1155 p_device_pool->
lock = lock;
1160 lockf(lock, F_ULOCK, 0);
1162 if (NULL == p_device_pool) {
1166#ifndef __OPENHARMONY__
1172 return p_device_pool;
1193int ni_rsrc_init(
int should_match_rev,
int timeout_seconds)
1196 char api_version[5];
1197 int number_of_devices;
1199 int limit_depth = 3;
1208 if (number_of_devices > 0)
1220 if (timeout_seconds == 0) {
1222 "and exit without wait\n");
1227 if (runtime >= (uint32_t)timeout_seconds)
1230 "Timeout exceeded/reached after %u seconds!\n",
1241 ret =
ni_rsrc_init_priv(should_match_rev, number_of_devices, device_names, limit_depth);
1274 ni_rsrc_shm_state state = NI_RSRC_SHM_IS_INVALID;
1276 int flags = O_RDWR | O_CLOEXEC;
1277 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
1278 char shm_name[32] = { 0 };
1279 char lck_name[32] = { 0 };
1286 if (ni_rsrc_try_get_shm_lock(lck_name, flags, mode, &lock) < 0) {
1291 if (ni_rsrc_open_shm(shm_name,
1294 (
int *)&shm_fd) < 0) {
1299 if ((ni_rsrc_mmap_shm(shm_name,
1302 (
void **)&p_device_queue)) < 0) {
1308 if (!p_device_context) {
1318 p_device_context->
lock = lock;
1322 lockf(lock, F_ULOCK, 0);
1324#ifndef __OPENHARMONY__
1330 return p_device_context;
1343 if (p_device_context)
1347 ReleaseMutex(p_device_context->
lock);
1348#elif __linux__ || __APPLE__
1349 close(p_device_context->
lock);
1353 free(p_device_context);
1379 bool b_release_pool_mtx =
false;
1381 if ( (NULL == p_device_info) || (NULL == p_device_count) )
1388 if (NULL == p_device_pool)
1395 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
1398 "mutex: %p\n", p_device_pool->
lock);
1402#elif __linux__ || __APPLE__
1403 lockf(p_device_pool->
lock, F_LOCK, 0);
1406 b_release_pool_mtx =
true;
1409 count = p_device_queue->
xcoder_cnt[device_type];
1412 for (i = 0; i < count; i++)
1415 guid = p_device_queue->
xcoders[device_type][i];
1417 if (p_device_context)
1420 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1423 "mutex: %p\n", p_device_context->
lock);
1424 ReleaseMutex(p_device_pool->
lock);
1430 ReleaseMutex(p_device_context->
lock);
1431#elif __linux__ || __APPLE__
1432 lockf(p_device_context->
lock, F_LOCK, 0);
1434 lockf(p_device_context->
lock, F_ULOCK, 0);
1439 (*p_device_count)++;
1449 if (b_release_pool_mtx)
1452 ReleaseMutex(p_device_pool->
lock);
1453#elif __linux__ || __APPLE__
1454 lockf(p_device_pool->
lock, F_ULOCK, 0);
1481 if (NULL == p_device)
1531 if (list_uninitialized)
1538 if (!list_uninitialized)
1550 for (
int dev_index = 0;
1564 ni_device_handle_t fd;
1566 for (
int dev_index = 0; dev_index < dev_count; dev_index++)
1568 if (is_str_in_str_array(dev_names[dev_index],
1575 if (NI_INVALID_DEVICE_HANDLE == fd)
1578 dev_names[dev_index]);
1587 dev_names[dev_index]);
1595 p_dev_info = &p_device->
xcoders[dev_type][dev_index];
1601 sizeof(capability.
fw_rev));
1650 " Operations: Crop (ni_quadra_crop), Scale (ni_quadra_scale), Pad "
1651 "(ni_quadra_pad), Overlay (ni_quadra_overlay)\n"
1652 " Drawbox (ni_quadra_drawbox), Rotate (ni_quadra_rotate), XStack (ni_quadra_xstack)\n");
1658 " Operations: ROI (ni_quadra_roi), Background Replace (ni_quadra_bg)\n");
1668 ni_codec_format_str[p_device_info->
dev_cap[i]
1673 ni_dec_name_str[p_device_info->
dev_cap[i]
1675 ni_enc_name_str[p_device_info->
dev_cap[i]
1788 if (NULL == p_device_context)
1794 if (NULL == p_device_info)
1800 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1803 "mutex: %p\n", p_device_context->
lock);
1804 free(p_device_info);
1809 ReleaseMutex(p_device_context->
lock);
1811 lockf(p_device_context->
lock, F_LOCK, 0);
1815 lockf(p_device_context->
lock, F_ULOCK, 0);
1822 return p_device_info;
1857 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
1860 __FUNCTION__, p_device_pool->
lock);
1864#elif __linux__ || __APPLE__
1865 lockf(p_device_pool->
lock, F_LOCK, 0);
1870 for (i = 0; i < num_coders; i++)
1875 if (p_device_context &&
1887 ReleaseMutex(p_device_pool->
lock);
1888#elif __linux__ || __APPLE__
1889 lockf(p_device_pool->
lock, F_ULOCK, 0);
1916 if (!p_device_context || !sw_instance_info)
1923 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1926 __func__, p_device_context->
lock);
1929#elif __linux__ || __APPLE__
1930 lockf(p_device_context->
lock, F_LOCK, 0);
1935 for (i = 0; i < sw_instance_cnt; i++)
1941 ReleaseMutex(p_device_context->
lock);
1942#elif __linux__ || __APPLE__
1943 lockf(p_device_context->
lock, F_ULOCK, 0);
1973 return p_device_context;
1992 (void) p_device_context;
1997 if (!p_device_context)
2004 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
2007 __func__, p_device_context->
lock);
2009#elif __linux__ || __APPLE__
2010 lockf(p_device_context->
lock, F_LOCK, 0);
2015 ni_log(
NI_LOG_INFO,
"Warning: releasing resource load %lu > current load %lu\n", load,
2023#if __linux__ || __APPLE__
2029 "p_device_info: %s\n", __func__, errmsg);
2035 ReleaseMutex(p_device_context->
lock);
2036#elif __linux__ || __APPLE__
2037 lockf(p_device_context->
lock, F_ULOCK, 0);
2058 bool b_release_pool_mtx =
false;
2076 if (!p_session_ctx || !p_api_param)
2083 p_session_ctx->
hw_id = guid;
2124 if (WAIT_ABANDONED ==
2125 WaitForSingleObject(p_device_pool->
lock,
2129 "ERROR: ni_rsrc_list_devices() failed to obtain mutex: %p\n",
2130 p_device_pool->
lock);
2135 lockf(p_device_pool->
lock, F_LOCK, 0);
2137 b_release_pool_mtx =
true;
2146 if (NI_INVALID_DEVICE_HANDLE == p_session_ctx->
device_handle)
2154 if (NI_INVALID_EVENT_HANDLE == p_session_ctx->
event_handle)
2165 "guid %d. %s is not avaiable, type: %d, retval:%d\n",
2167 device_type, retval);
2187 "vpu recovery happened on guid %d. %s, retry "
2198 "session open error guid %d. %s, type: %d, "
2201 device_type, retval);
2211 "Error get device resource: guid %d, device_ctx %p\n", guid,
2218 if (b_release_pool_mtx)
2221 ReleaseMutex(p_device_pool->
lock);
2223 lockf(p_device_pool->
lock, F_ULOCK, 0);
2252#if __linux__ || __APPLE__
2258 unsigned int guid_index_i, guid_index_j, ui_device_type;
2283 rValue = WaitForSingleObject(p_device_pool->
lock, INFINITE);
2284 if (rValue != WAIT_OBJECT_0)
2287 "ERROR: %s() Failed to obtain mutex %p\n",
2289 p_device_pool->
lock);
2293#elif __linux__ || __APPLE__
2294 lockf(p_device_pool->
lock, F_LOCK, 0);
2304 guid = p_device_queue->
xcoders[ui_device_type][guid_index_i];
2311 if (!p_device_context)
2314 "ERROR: %s() Failed to obtain device context for "
2315 "%s with GUID %u! Undefined behavior!\n",
2330 "ERROR: %s() Devicename format mismatch %s %s\n",
2338 CloseHandle(p_device_context->
lock);
2339#elif __linux__ || __APPLE__
2343 "%s %s %s deleted\n",
2352 "ERROR: %s(): %s %s %s failed to delete %s\n",
2364#if __linux__ || __APPLE__
2366 if (!unlink(lck_name))
2369 "%s %s %s deleted\n",
2378 "ERROR: %s(): %s %s %s failed to delete %s\n",
2393 p_device_queue->
xcoders[ui_device_type][guid_index_i] = -1;
2394 p_device_queue->
xcoder_cnt[ui_device_type]--;
2405 memset(guids, -1,
sizeof(guids));
2409 guid = p_device_queue->
xcoders[ui_device_type][guid_index_i];
2412 guids[guid_index_j] = guid;
2414 if (guid_index_j == p_device_queue->
xcoder_cnt[ui_device_type])
2420 memcpy(p_device_queue->
xcoders[ui_device_type], guids,
sizeof(guids));
2423#if __linux__ || __APPLE__
2425 if (!msync((
void *)p_device_queue,
2427 MS_SYNC|MS_INVALIDATE))
2435 "ERROR: %s(): msync() failed to delete %s: %s\n",
2445 ReleaseMutex(p_device_pool->
lock);
2446#elif __linux__ || __APPLE__
2447 lockf(p_device_pool->
lock, F_ULOCK, 0);
2453 return return_value;
2468 int xcoder_dev_count = 0;
2496 xcoder_dev_names[i]);
2502 "%d devices retrieved from current pool at start up\n",
2506 "%d devices retrieved from current pool at start up\n",
2517 for (i = 0; i < xcoder_dev_count; i++)
2520 xcoder_dev_names[i]);
2525 xcoder_dev_names[i]);
2529 xcoder_dev_names[i]);
2533#if __linux__ || __APPLE__
2545 if (0 == unlink(XCODERS_RETRY_LCK_NAME[i]))
2548 i, XCODERS_RETRY_LCK_NAME[i]);
2553 i, XCODERS_RETRY_LCK_NAME[i]);
2585 uint32_t i, existing_number_of_devices;
2606 if (WAIT_ABANDONED == WaitForSingleObject(device_pool->
lock, INFINITE))
2609 "ERROR: %s(): Failed to obtain lock %p\n",
2614#elif __linux__ || __APPLE__
2615 lockf(device_pool->
lock, F_LOCK, 0);
2622 existing_number_of_devices = device_queue->
xcoder_cnt[device_type];
2627 "ERROR: %s(): Limit of NI_MAX_DEVICE_CNT(%d) existing Quadra "
2628 "devices previously reached. Not adding %s.\n",
2636 for (i = 0; i < existing_number_of_devices; i++)
2640 device_queue->
xcoders[device_type][i]);
2647 "ERROR: %s(): %s already exists in resource pool\n",
2666 ReleaseMutex(device_pool->
lock);
2667#elif __linux__ || __APPLE__
2668 lockf(device_pool->
lock, F_ULOCK, 0);
2685 if (NI_INVALID_LOCK_HANDLE != p_device_pool->
lock)
2688 CloseHandle(p_device_pool->
lock);
2689#elif __linux__ || __APPLE__
2690 close(p_device_pool->
lock);
2700 free(p_device_pool);
2719 *lock = CreateMutex(NULL, FALSE, XCODERS_RETRY_LCK_NAME[device_type]);
2725 __func__, XCODERS_RETRY_LCK_NAME[device_type],
2734 open(XCODERS_RETRY_LCK_NAME[device_type], O_RDWR | O_CLOEXEC);
2756 DWORD ret = WaitForSingleObject(*lock, 1);
2757 if (WAIT_OBJECT_0 == ret)
2760 }
else if (WAIT_TIMEOUT != ret)
2767 status = lockf(*lock, F_LOCK, 0);
2784 while (status != 0);
2799 if (lock == NI_INVALID_LOCK_HANDLE)
2805 ni_lock_handle_t status = NI_INVALID_LOCK_HANDLE;
2813 if (ReleaseMutex(lock))
2815 status = (ni_lock_handle_t)(0);
2818 status = lockf(lock, F_ULOCK, 0);
2831 }
while (status != (ni_lock_handle_t)(0));
2875 char cmd[128] = {0};
2876 char cmd_ret[64] = {0};
2882 ptr = device_name + 5;
2883 snprintf(cmd,
sizeof(cmd) - 1,
"cat /sys/block/%s/device/*/numa_node",ptr);
2884 cmd_fp = popen(cmd,
"r");
2889 if (fgets(cmd_ret,
sizeof(cmd_ret)/
sizeof(cmd_ret[0]), cmd_fp) == 0)
2891 goto get_numa_node_ret;
2893 ret =
atoi(cmd_ret);
2901static int int_cmp(
const void *a,
const void *b)
2903 const int *ia = (
const int *)a;
2904 const int *ib = (
const int *)b;
2905 return (*ia == *ib) ? 0 : ((*ia > *ib) ? 1 : -1);
2909static int ni_hw_device_info_quadra_threshold_param_t_compare(
const void *pl,
const void *pr)
2932 int factor_8_10 = 1;
2933 uint32_t resolution = decoder_param->
h * decoder_param->
w;
2938 return resolution >= 1920*1080 ?
2939 (int)(((uint64_t)(resolution)*(uint64_t)(decoder_param->
fps)*(uint64_t)(factor_8_10)*100)/1440/1920/1080) :
2940 (int)((uint64_t)(resolution)*(uint64_t)(decoder_param->fps)*(uint64_t)(factor_8_10)*100/2880/1280/720);
2954 double factor = 1.0;
2955 double factor_codec = 1.0;
2956 double factor_rdoq = 1.0;
2957 double factor_rdoLevel = 1.0;
2958 double factor_lookahead = 1.0;
2959 double factor_8_10_bit = 1.0;
2960 double factor_720p = 1.0;
2962 int resolution = (int)(encoder_param->
w * encoder_param->
h);
2967 factor_codec = 0.67;
2979 factor_rdoLevel = (encoder_param->
rdoLevel == 2) ? 1.91 : 3.28;
2984 factor_lookahead = (double)(encoder_param->
lookaheadDepth * 0.0014 + 1.012);
2990 factor_8_10_bit = 2;
2993 factor_720p = 1.125;
2994 factor = factor_codec * factor_8_10_bit * factor_rdoq * factor_rdoLevel
2995 * factor_lookahead * factor_720p;
3001 ((uint32_t)((uint32_t)factor*encoder_param->
fps * resolution)) /
3002 ((3840 * 2160 * 60ULL) / 100 * 4));
3017static int check_hw_info_shared_mem_calculate_b_scale(
int h,
int w,
int bit_8_10,
int rgba)
3019 const int stride = 128;
3020 int estimated_yuv_size = rgba ?
3023 ( ((w + stride - 1)/stride)*stride + ((w/2 + stride - 1)/stride)*stride ) * h:
3024 ( ((w * 2 + stride - 1)/stride)*stride + ((w + stride - 1)/stride)*stride ) * h;
3025 const int b_unit = 1601536;
3026 int b_scale = (estimated_yuv_size + b_unit -1) / b_unit;
3058 const int v32_ofCores_calculate = 0;
3060 int b_counts = (int)(v32_ofCores_calculate +
3063 (encoder_param->uploader ? 1 : 0) * 3 +
3065 int b_scale = check_hw_info_shared_mem_calculate_b_scale(encoder_param->
h, encoder_param->
w,
3067 return b_scale * b_counts;
3091 const int hw_frame = decoder_param->
hw_frame;
3093 const int v30_xlsx = 0;
3094 int b_counts = 1 * (v30_xlsx +
3095 (hw_frame ? 0 : 1)*3 +
3097 int b_scale = check_hw_info_shared_mem_calculate_b_scale(decoder_param->
h, decoder_param->
w,
3099 return b_scale * b_counts;
3126 const int v30_xlsx = 0;
3127 int b_counts = 1 * (v30_xlsx +
3130 int b_scale = check_hw_info_shared_mem_calculate_b_scale(scaler_param->
h, scaler_param->
w,
3132 return b_scale * b_counts;
3150 const int total = 2456;
3151 int task_mem_usage = 0;
3152 int task_mem_precentage = 0;
3158 for(i = 0; i < card_num; ++i)
3167 task_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16);
3171 task_mem_usage = check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param);
3175 task_mem_usage = check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3179 int decoder_shared_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16);
3180 int encoder_shared_mem_usage = check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param);
3181 int scaler_shared_mem_usage = check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3182 task_mem_usage = decoder_shared_mem_usage + ((encoder_shared_mem_usage > scaler_shared_mem_usage) ?
3183 encoder_shared_mem_usage : scaler_shared_mem_usage);
3188 task_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16) +
3189 check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param)+
3190 check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3193 task_mem_precentage = 100 * task_mem_usage / total;
3195 if(task_mem_precentage > 90)
3198 task_mem_precentage = 90;
3201 for(i = 0;i<card_num;++i)
3203 if(card_remove[i] == 1)
3228 if(p_coder_param == NULL)
3230 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_coder_param\n");
3231 return p_coder_param;
3240 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_decoder_param\n");
3241 free(p_coder_param);
3242 p_coder_param = NULL;
3243 return p_coder_param;
3251 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_encoder_param\n");
3252 free(p_coder_param);
3253 p_coder_param = NULL;
3254 return p_coder_param;
3262 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_scaler_param\n");
3263 free(p_coder_param);
3264 p_coder_param = NULL;
3265 return p_coder_param;
3271 if(p_coder_param->
ai_param == NULL)
3273 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_ai_param\n");
3274 free(p_coder_param);
3275 p_coder_param = NULL;
3276 return p_coder_param;
3284 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_encoder_param\n");
3285 free(p_coder_param);
3286 p_coder_param = NULL;
3287 return p_coder_param;
3292 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_decoder_param\n");
3295 free(p_coder_param);
3296 p_coder_param = NULL;
3297 return p_coder_param;
3302 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_scaler_param\n");
3307 free(p_coder_param);
3308 p_coder_param = NULL;
3309 return p_coder_param;
3312 if(p_coder_param->
ai_param == NULL)
3314 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_ai_param\n");
3321 free(p_coder_param);
3322 p_coder_param = NULL;
3323 return p_coder_param;
3363 return p_coder_param;
3379 if(p_hw_device_info_quadra_coder_param == NULL)
3395 free(p_hw_device_info_quadra_coder_param->
scaler_param);
3396 p_hw_device_info_quadra_coder_param->
scaler_param = NULL;
3398 if(p_hw_device_info_quadra_coder_param->
ai_param)
3400 free(p_hw_device_info_quadra_coder_param->
ai_param);
3401 p_hw_device_info_quadra_coder_param->
ai_param = NULL;
3403 free(p_hw_device_info_quadra_coder_param);
3420 if(!p_hw_device_info)
3422 ni_log(
NI_LOG_ERROR,
"ERROR: Failed to allocate memory for p_hw_device_info_quadra_t\n");
3423 goto p_hw_device_info_end;
3430 ni_log(
NI_LOG_ERROR,
"ERROR: Failed to allocate memory for p_hw_device_info_quadra_t->device_type\n");
3431 goto device_type_end;
3449 if(p_hw_device_info->
card_info[i] == NULL)
3452 goto card_info_i_end;
3456 return p_hw_device_info;
3473 free(p_hw_device_info);
3474 p_hw_device_info = NULL;
3475p_hw_device_info_end:
3490 if(!p_hw_device_info)
3503 free(p_hw_device_info);
3520 int should_match_rev = 1;
3521 int module_count = 1;
3523 int32_t *module_id_arr = NULL;
3529 int *card_remove = NULL;
3532 uint64_t decoder_need_load = 0;
3533 uint64_t encoder_need_load = 0;
3536 int hw_info_param_num = hw_mode ? 4 : 1;
3537 int device_type_num = 1;
3538 const int all_device_type_num = 4;
3546 bool b_valid =
false;
3552 bool pool_locked =
false;
3555 if(!pointer_to_p_hw_device_info)
3557 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: pointer_to_p_hw_device_info is NULL.\n");
3561 if(*pointer_to_p_hw_device_info)
3563 p_hw_device_info = *pointer_to_p_hw_device_info;
3575 }
else if(hw_mode && hw_mode != coder_param->
hw_mode)
3577 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: hw_mode = %d, coder_param->hw_mode = %d\n",
3578 hw_mode,coder_param->
hw_mode);
3584 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_ENCODER but coder_param->encoder_param == NULL\n");
3589 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_DECODER but coder_param->decoder_param == NULL\n");
3594 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_SCALER but coder_param->scaler_param == NULL\n");
3599 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_AI but coder_param->ai_param == NULL\n");
3605 if((task_mode != 0 && task_mode != 1) ||
3614 task_mode, preferential_device_type);
3618 if(!hw_info_threshold_param)
3624 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: hw_info_threshold_param is NULL.\n");
3627 for(i = 0;i < hw_info_param_num; ++i)
3629 if(hw_info_threshold_param[i].load_threshold < 0||
3630 hw_info_threshold_param[i].load_threshold > 100 ||
3631 hw_info_threshold_param[i].task_num_threshold < 0 ||
3642 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: In %s, hw_info_threshold_param[%d].device_type = %d, hw_info_threshold_param[%d].load_threshold = %d, hw_info_threshold_param[%d].task_num_threshold = %d\n",
3643 (hw_mode ?
"hardware_mode":
"software_mode"), i, hw_info_threshold_param[i].device_type, i, hw_info_threshold_param[i].load_threshold, i, hw_info_threshold_param[i].task_num_threshold);
3708 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3714#elif defined(__linux__)
3715 if (lockf(p_device_pool->
lock, F_LOCK, 0))
3742 for(i = 0; i < all_device_type_num; ++i)
3744 if(all_need_device_type[i] == preferential_device_type)
3747 all_need_device_type[i] = all_need_device_type[0];
3748 all_need_device_type[0] = tmp;
3753 qsort(&all_need_device_type[1], all_device_type_num - 1,
sizeof(
ni_device_type_t), int_cmp);
3759 device_type_num = 4;
3761 for(i = 0; i < device_type_num; ++i)
3763 if(hw_info_threshold_param[i].device_type == preferential_device_type)
3766 hw_info_threshold_param[i] = hw_info_threshold_param[0];
3767 hw_info_threshold_param[0] = tmp;
3771 qsort(&hw_info_threshold_param[1], device_type_num - 1,
3775 if(!(*pointer_to_p_hw_device_info))
3778 if(!p_hw_device_info)
3783 *pointer_to_p_hw_device_info = p_hw_device_info;
3794 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->device_type is NULL\n");
3800 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->card_info is NULL\n");
3804 for(i = 0; i < device_type_num; ++i)
3808 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->card_info[%d] is NULL\n", i);
3822 p_hw_device_info->
device_type[i] = all_need_device_type[i];
3860 card_remove = (int32_t *)malloc(
sizeof(int32_t) * p_hw_device_info->
available_card_num);
3870 module_count = coders->
xcoder_cnt[preferential_device_type];
3878 module_id_arr = (int32_t *)malloc(
sizeof(int32_t) * module_count);
3887 memcpy(module_id_arr, coders->
xcoders[preferential_device_type],
sizeof(int32_t) * module_count);
3891 qsort(module_id_arr, module_count,
sizeof(int32_t), int_cmp);
3897 memset(p_xCtxt, 0,
sizeof(*p_xCtxt));
3899 if (p_device_context)
3933 for(
int j = 0; j < device_type_num; ++j)
3937 if(p_device_context)
3983 p_device_context = NULL;
4004 decoder_need_load = check_hw_info_decoder_need_load(coder_param->
decoder_param);
4008 encoder_need_load = check_hw_info_encoder_need_load(coder_param->
encoder_param);
4023 ni_log(
NI_LOG_DEBUG,
"%s Card[%3d], load: %3d, task_num: %3d, firmware_load: %3d, model_load: %3d, shared_mem_usage: %3d\n",
4025 ni_log(
NI_LOG_INFO,
"%s Card[%3d], load: %3d, task_num: %3d, firmware_load: %3d, model_load: %3d, shared_mem_usage: %3d\n",
4037 if(card_remove[i] == 1)
4092 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,10);
4094 else if(preferential_device_type == 0)
4096 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,0);
4098 else if(preferential_device_type == 1)
4100 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,1);
4102 else if(preferential_device_type == 2)
4104 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,2);
4116 card_remove[i] == 0)
4126 card_remove[i] == 0 &&
4142 card_remove[i] == 0)
4156 if (p_device_pool && pool_locked)
4159 ReleaseMutex((HANDLE)p_device_pool->
lock);
4161#elif defined(__linux__)
4162 if (lockf(p_device_pool->
lock, F_ULOCK,0))
4165 if(p_hw_device_info)
4176 p_device_context = NULL;
4181 free(module_id_arr);
4182 module_id_arr = NULL;
4187 dev_ctxt_arr = NULL;
4213 ni_log(
NI_LOG_DEBUG,
"In sw_mode select device_type %s card_current_card %d retval %d\n",
4215 ni_log(
NI_LOG_INFO,
"In sw_mode select device_type %s card_current_card %d retval %d\n",
4217 ((preferential_device_type == 0) ?
"decode" : (preferential_device_type == 1 ?
"encode" : (preferential_device_type == 2 ?
"scaler" :
"ai "))), p_hw_device_info->
card_current_card, retval);
4249 int width,
int height,
4261 uint32_t num_sw_instances = 0;
4262 int least_model_load = 0;
4263 uint64_t job_mload = 0;
4282 if (!p_session_context)
4288 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
4292#elif __linux__ || __APPLE__
4293 lockf(p_device_pool->
lock, F_LOCK, 0);
4299 for (i = 0; i < count; i++)
4303 if (!p_device_context)
4306 "ERROR: %s() ni_rsrc_get_device_context() failed\n", __func__);
4315 if (NI_INVALID_DEVICE_HANDLE == p_session_context->
device_handle)
4334 g_device_type_str[device_type],
4342 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
4345 __func__, p_device_context->
lock);
4347#elif __linux__ || __APPLE__
4348 lockf(p_device_context->
lock, F_LOCK, 0);
4356 load = p_device_info->
load;
4357 least_model_load = p_device_info->
model_load;
4361 ni_log(
NI_LOG_INFO,
"Coder [%d]: %d , load: %d (%d), activ_inst: %d , max_inst %d\n",
4382 if (p_device_info->
model_load < least_model_load)
4385 least_model_load = p_device_info->
model_load;
4388 else if (p_device_info->
load < load)
4391 load = p_device_info->
load;
4398 ReleaseMutex(p_device_context->
lock);
4399#elif __linux__ || __APPLE__
4400 lockf(p_device_context->
lock, F_ULOCK, 0);
4408 if (!p_device_context)
4411 "ERROR: %s() ni_rsrc_get_device_context() failed\n", __func__);
4417 job_mload = width * height * frame_rate;
4423 p_device_context = NULL;
4428 ReleaseMutex(p_device_pool->
lock);
4429#elif __linux__ || __APPLE__
4430 lockf(p_device_pool->
lock, F_ULOCK, 0);
4437 *p_load = job_mload;
4439 return p_device_context;
#define NI_XCODER_REVISION_API_MAJOR_VER_IDX
#define NI_MAX_DEVICE_CNT
#define NI_XCODER_REVISION
#define NI_MAX_DEVICE_NAME_LEN
#define NI_MAX_CONTEXTS_PER_HW_INSTANCE
@ NI_DEVICE_TYPE_XCODER_MAX
#define GET_XCODER_DEVICE_TYPE_STR(t)
@ NI_RETCODE_ERROR_LOCK_DOWN_DEVICE
@ NI_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_RETCODE_ERROR_UNLOCK_DEVICE
@ NI_RETCODE_ERROR_INVALID_HANDLE
@ NI_RETCODE_PARAM_INVALID_VALUE
@ NI_RETCODE_ERROR_RESOURCE_UNAVAILABLE
@ NI_RETCODE_ERROR_MEM_ALOC
@ NI_RETCODE_ERROR_VPU_RECOVERY
@ NI_RETCODE_INVALID_PARAM
#define IS_XCODER_DEVICE_TYPE(t)
void ni_device_session_context_free(ni_session_context_t *p_ctx)
Free previously allocated session context.
ni_retcode_t ni_device_session_close(ni_session_context_t *p_ctx, int eos_recieved, ni_device_type_t device_type)
Close device session that was previously opened by calling ni_device_session_open() If device_type is...
NI_DEPRECATED ni_retcode_t ni_device_capability_query(ni_device_handle_t device_handle, ni_device_capability_t *p_cap)
Query device and return device capability structure This function had been replaced by ni_device_capa...
ni_retcode_t ni_device_session_open(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Open a new device session depending on the device_type parameter If device_type is NI_DEVICE_TYPE_DEC...
ni_event_handle_t ni_create_event(void)
Create event and return event handle if successful (Windows only)
ni_retcode_t ni_query_fl_fw_versions(ni_device_handle_t device_handle, ni_device_info_t *p_dev_info)
Query firmware loader and firmware versions from the device.
ni_retcode_t ni_encoder_init_default_params(ni_xcoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height, ni_codec_format_t codec_format)
Initialize default encoder parameters.
ni_retcode_t ni_device_capability_query2(ni_device_handle_t device_handle, ni_device_capability_t *p_cap, bool device_in_ctxt)
Query device and return device capability structure This function had replaced ni_device_capability_q...
ni_retcode_t ni_device_session_query(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Query session data from the device - If device_type is valid, will query session data from specified ...
ni_session_context_t * ni_device_session_context_alloc_init(void)
Allocate and initialize a new ni_session_context_t struct.
ni_retcode_t ni_decoder_init_default_params(ni_xcoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height)
Initialize default decoder parameters.
void ni_close_event(ni_event_handle_t event_handle)
Close event and release resources (Windows only)
void ni_device_close(ni_device_handle_t device_handle)
Close device and release resources.
ni_device_handle_t ni_device_open2(const char *p_dev, ni_device_mode_t mode)
Open device and return device device_handle if successful.
#define NI_DEFAULT_KEEP_ALIVE_TIMEOUT
ni_log_level_t ni_log_get_level(void)
Get ni_log_level.
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_set_level(ni_log_level_t level)
Set ni_log_level.
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
int ni_rsrc_unlock(int device_type, ni_lock_handle_t lock)
unlock a file lock
int ni_rsrc_get_numa_node(char *device_name)
get linux numa_node
NI_DEPRECATED bool g_device_in_ctxt
ni_device_context_t * ni_rsrc_allocate_simple_direct(ni_device_type_t device_type, int guid)
Allocate resources for decoding/encoding, by designating explicitly the device to use....
void ni_destory_hw_device_info_quadra_coder_param(ni_hw_device_info_quadra_coder_param_t *p_hw_device_info_quadra_coder_param)
Free resource in p_hw_device_info_quadra_coder_param This function is used for ni_check_hw_info()
ni_retcode_t ni_rsrc_list_devices(ni_device_type_t device_type, ni_device_info_t *p_device_info, int *p_device_count)
List device(s) based on device type with full information including s/w instances on the system.
ni_hw_device_info_quadra_coder_param_t * ni_create_hw_device_info_quadra_coder_param(int mode)
Create and alloc a pointer to ni_hw_device_info_quadra_coder_param_t This function is used for ni_che...
void ni_rsrc_print_device_info(const ni_device_info_t *p_device_info)
Print the content of the ni_device_info_t struct.
void print_device(ni_device_t *p_device)
NI_DEPRECATED int g_xcoder_refresh_dev_count
int ni_rsrc_lock_and_open(int device_type, ni_lock_handle_t *lock)
lock a file lock and open a session on a device
NI_DEPRECATED char ** g_xcoder_refresh_dev_names
ni_retcode_t ni_rsrc_list_all_devices2(ni_device_t *p_device, bool list_uninitialized)
Grabs information for every initialized and uninitialized device.
void ni_rsrc_release_resource(ni_device_context_t *p_device_context, uint64_t load)
Release resources allocated for decoding/encoding. function This must be called at the end of transco...
void ni_rsrc_print_all_devices_capability2(bool list_uninitialized)
Prints detailed capability information for all initialized devices and general information about unin...
void ni_rsrc_free_device_context(ni_device_context_t *p_device_context)
Free previously allocated device context.
int ni_rsrc_remove_all_devices(void)
Remove all NetInt h/w devices from resource pool on the host.
int ni_rsrc_add_device(const char *dev, int should_match_rev)
Add an NetInt h/w device into resource pool on the host.
ni_retcode_t ni_rsrc_refresh(int should_match_rev)
Scan and refresh all resources on the host, taking into account hot-plugged and pulled out cards.
int ni_rsrc_update_device_load(ni_device_context_t *p_device_context, int load, int sw_instance_cnt, const ni_sw_instance_info_t sw_instance_info[])
Update the load value and s/w instances info of a specific decoder or encoder. This is used by resour...
int ni_rsrc_is_fw_compat(uint8_t fw_rev[8])
check if device FW revision is compatible with SW API
void ni_hw_device_info_free_quadra(ni_hw_device_info_quadra_t *p_hw_device_info)
Free resource in a pointer of ni_hw_device_info_quadra_t This function is used for ni_check_hw_info()
int ni_rsrc_get_device_by_block_name(const char *blk_name, ni_device_type_t device_type)
Get GUID of the device by block device name and type.
void ni_rsrc_free_device_pool(ni_device_pool_t *p_device_pool)
Free all resources taken by the device pool.
int ni_rsrc_remove_device(const char *dev)
Remove an NetInt h/w device from resource pool on the host.
int ni_rsrc_check_hw_available(int guid, ni_device_type_t device_type)
check the NetInt h/w device in resource pool on the host.
ni_retcode_t ni_rsrc_list_all_devices(ni_device_t *p_device)
List all devices with full information including s/w instances on the system.
ni_device_context_t * ni_rsrc_allocate_auto(ni_device_type_t device_type, ni_alloc_rule_t rule, ni_codec_t codec, int width, int height, int frame_rate, uint64_t *p_load)
Allocate resources for decoding/encoding, based on the provided rule.
void ni_rsrc_print_all_devices_capability(void)
Print detailed capability information of all devices on the system.
int ni_check_hw_info(ni_hw_device_info_quadra_t **pointer_to_p_hw_device_info, int task_mode, ni_hw_device_info_quadra_threshold_param_t *hw_info_threshold_param, ni_device_type_t preferential_device_type, ni_hw_device_info_quadra_coder_param_t *coder_param, int hw_mode, int consider_mem)
check hw info, return the appropriate card number to use depends on the load&task_num&used resource
ni_hw_device_info_quadra_t * ni_hw_device_info_alloc_quadra(int device_type_num, int avaliable_card_num)
Create a ni_hw_device_info_quadra_t This function is used for ni_check_hw_info()
NI_DEPRECATED ni_device_handle_t g_dev_handle
ni_device_info_t * ni_rsrc_get_device_info(ni_device_type_t device_type, int guid)
Query a specific device with detailed information on the system.
Public definitions for managing NETINT video processing devices.
LIB_API NI_DEPRECATED int ni_rsrc_get_local_device_list(char ni_devices[][NI_MAX_DEVICE_NAME_LEN], int max_handles)
Scans system for all NVMe devices and returns the system device names to the user which were identifi...
LIB_API int ni_rsrc_get_local_device_list2(char ni_devices[][NI_MAX_DEVICE_NAME_LEN], int max_handles, char **xcoder_refresh_dev_names, int xcoder_refresh_dev_count)
Scans system for all NVMe devices and returns the system device names to the user which were identifi...
LIB_API ni_device_context_t * ni_rsrc_get_device_context(ni_device_type_t type, int guid)
Allocates and returns a pointer to ni_device_context_t struct based on provided device_type and guid....
@ EN_ALLOC_LEAST_INSTANCE
LIB_API ni_device_pool_t * ni_rsrc_get_device_pool(void)
Create and return the allocated ni_device_pool_t struct.
LIB_API int ni_rsrc_init(int should_match_rev, int timeout_seconds)
Initialize and create all resources required to work with NETINT NVMe transcoder devices....
Public definitions for managing NETINT video processing devices on Android.
android::sp< INidec > service
int ni_rsrc_android_init()
Init android net.int.SharedBuffer service for binder using.
uint32_t g_xcoder_stop_process
void ni_rsrc_get_shm_name(ni_device_type_t device_type, int32_t guid, char *p_name, size_t max_name_len)
ni_retcode_t ni_rsrc_create_retry_lck()
void ni_rsrc_get_lock_name(ni_device_type_t device_type, int32_t guid, char *p_name, size_t max_name_len)
bool add_to_shared_memory(const char device_name[NI_MAX_DEVICE_NAME_LEN], const bool device_open_should_succeed, const int should_match_rev, ni_device_queue_t *device_queue)
int ni_rsrc_strcmp(const void *p_str, const void *p_str1)
Private definitions used by ni_rsrc_api.cpp for management of NETINT video processing devices.
void ni_rsrc_update_record(ni_device_context_t *p_device_context, ni_session_context_t *p_session_ctx)
int ni_rsrc_enumerate_devices(char ni_devices[][NI_MAX_DEVICE_NAME_LEN], int max_handles)
int ni_rsrc_init_priv(const int should_match_rev, const int existing_number_of_devices, const char device_names[NI_MAX_DEVICE_CNT][NI_MAX_DEVICE_NAME_LEN], int limit_depth)
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_fmt_fw_api_ver_str(const char ver_str[], char fmt_str[])
Get formatted FW API version string from unformatted FW API version string.
ni_retcode_t ni_strerror(char *dest, size_t dmax, int errnum)
ni_retcode_t ni_strcat(char *dest, size_t dmax, const char *src)
ni_retcode_t ni_strcpy(char *dest, size_t dmax, const char *src)
void ni_usleep(int64_t usec)
ni_retcode_t ni_check_dev_name(const char *p_dev)
check dev name
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 XCODER_MIN_ENC_PIC_WIDTH
#define XCODER_MIN_ENC_PIC_HEIGHT
uint8_t fw_commit_time[26]
uint8_t serial_number[20]
uint8_t fw_commit_hash[41]
uint8_t fw_branch_name[256]
uint8_t fw_build_time[26]
ni_device_info_t * p_device_info
char shm_name[NI_MAX_DEVICE_NAME_LEN]
uint8_t fw_commit_time[26]
uint8_t serial_number[20]
char dev_name[NI_MAX_DEVICE_NAME_LEN]
uint8_t fw_commit_hash[41]
char blk_name[NI_MAX_DEVICE_NAME_LEN]
ni_sw_instance_info_t sw_instance[NI_MAX_CONTEXTS_PER_HW_INSTANCE]
uint64_t xcode_load_pixel
int fw_ver_compat_warning
ni_device_type_t device_type
uint8_t fl_ver_last_ran[8]
uint8_t fw_branch_name[256]
uint8_t fw_rev_nor_flash[8]
uint8_t fw_build_time[26]
uint8_t fl_ver_nor_flash[8]
ni_device_video_capability_t dev_cap[EN_CODEC_MAX]
ni_device_queue_t * p_device_queue
int32_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
uint32_t xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
char level[NI_LEVELS_SUPP_STR_LEN]
char profiles_supported[NI_PROFILES_SUPP_STR_LEN]
ni_device_info_t xcoders[NI_DEVICE_TYPE_XCODER_MAX][NI_MAX_DEVICE_CNT]
int xcoder_cnt[NI_DEVICE_TYPE_XCODER_MAX]
ni_hw_device_info_quadra_encoder_param_t * encoder_param
ni_hw_device_info_quadra_ai_param_t * ai_param
ni_hw_device_info_quadra_decoder_param_t * decoder_param
ni_hw_device_info_quadra_scaler_param_t * scaler_param
uint32_t ui8enableRdoQuant
ni_device_type_t device_type
ni_card_info_quadra_t ** card_info
ni_device_type_t * device_type
uint32_t fw_share_mem_usage
uint32_t keep_alive_timeout
ni_device_handle_t device_handle
ni_load_query_t load_query
ni_event_handle_t event_handle
ni_device_handle_t blk_io_handle
uint32_t scaler_operation