35#if __linux__ || __APPLE__
46#include <sys/syslimits.h>
54const char *ni_codec_format_str[] = {
"H.264",
"H.265",
"VP9",
"JPEG",
56const char *ni_dec_name_str[] = {
"h264_ni_quadra_dec",
"h265_ni_quadra_dec",
57 "vp9_ni_quadra_dec",
"jpeg_ni_quadra_dec"};
58const char *ni_enc_name_str[] = {
"h264_ni_quadra_enc",
"h265_ni_quadra_enc",
"empty",
59 "jpeg_ni_quadra_enc",
"av1_ni_quadra_enc"};
62bool is_str_in_str_array(
const char key[],
68 for (i = 0; i < array_size; i++)
70 if (0 == strcmp(key, arr[i]))
79#ifndef DEPRECATION_AS_ERROR
95 for (
int xcoder_index_1 = 0;
117 "no, possible missing features" :
"yes");
134 for (
int xcoder_index_2 = 0;
166 int xcoder_dev_count = 0;
168 int curr_dev_count = 0;
171 char **xcoder_refresh_dev_names = NULL;
172 int xcoder_refresh_dev_count = 0;
194 ni_strcpy(xcoder_dev_names[i],
sizeof(xcoder_dev_names[i]),
215 if (xcoder_dev_count > 0)
217 xcoder_refresh_dev_names = (
char **)malloc(xcoder_dev_count *
219 for (i = 0; i < xcoder_dev_count; i++)
224 xcoder_refresh_dev_count = xcoder_dev_count;
228 xcoder_refresh_dev_names, xcoder_refresh_dev_count);
229 if (0 == curr_dev_count)
233 int devices_removed = 0;
234 int devices_added = 0;
236 for (i = 0; i < xcoder_dev_count; i++)
238 if (!is_str_in_str_array(xcoder_dev_names[i], curr_dev_names,
242 "\n\n%d. %s NOT in current scanned list, removing !\n", i,
243 xcoder_dev_names[i]);
248 xcoder_dev_names[i]);
253 xcoder_dev_names[i]);
259 for (i = 0; i < curr_dev_count; i++)
261 if (!is_str_in_str_array(curr_dev_names[i], xcoder_dev_names,
278 if (devices_added != devices_removed)
282 for (i = 0; i < xcoder_dev_count; i++)
286 for (i = 0; i < curr_dev_count; i++)
291 if (xcoder_refresh_dev_names) {
292 for (i = 0; i < xcoder_refresh_dev_count; i++)
293 free(xcoder_refresh_dev_names[i]);
294 free(
reinterpret_cast<void*
>(xcoder_refresh_dev_names));
295 xcoder_refresh_dev_names = NULL;
302#include <utils/Mutex.h>
305android::sp<INidec>
service = NULL;
306static android::Mutex gLock;
318 android::Mutex::Autolock _l(gLock);
321 service = INidec::tryGetService();
335#ifndef DEPRECATION_AS_ERROR
356 if ((ni_devices == NULL)||(max_handles == 0))
382 int max_handles,
char **xcoder_refresh_dev_names,
383 int xcoder_refresh_dev_count)
385 if ((ni_devices == NULL)||(max_handles == 0))
404 HANDLE map_file_handle = NULL;
405 HANDLE mutex_handle = NULL;
408 mutex_handle = CreateMutexA(NULL,
413 if (NULL == mutex_handle)
420 if (WAIT_ABANDONED == WaitForSingleObject(mutex_handle, INFINITE))
425 map_file_handle = OpenFileMappingA(
431 if (NULL == map_file_handle)
433 ReleaseMutex(mutex_handle);
434 CloseHandle(mutex_handle);
448 if (NULL == p_device_queue)
450 ReleaseMutex(mutex_handle);
451 CloseHandle(mutex_handle);
452 CloseHandle(map_file_handle);
457 if (NULL == p_device_pool)
463 UnmapViewOfFile(p_device_queue);
467 p_device_pool->
lock = mutex_handle;
471 ReleaseMutex(mutex_handle);
472 CloseHandle(map_file_handle);
473 return p_device_pool;
494int ni_rsrc_init(
int should_match_rev,
int timeout_seconds)
498 int number_of_devices = 0;
499 uint32_t runtime = 0;
500 while (0 == number_of_devices)
510 else if (0 == number_of_devices)
518 if (timeout_seconds == 0) {
520 "and exit without wait\n");
525 if (runtime >= (uint32_t)timeout_seconds)
559 char shm_name[32] = { 0 };
560 char lck_name[32] = { 0 };
563 HANDLE map_file_handle = NULL;
564 HANDLE mutex_handle = NULL;
570 mutex_handle = CreateMutexA(NULL,
574 if (NULL == mutex_handle)
577 p_device_context = NULL;
581 if (WAIT_ABANDONED == WaitForSingleObject(mutex_handle, INFINITE))
584 "obtain mutex: %p\n", mutex_handle);
587 map_file_handle = OpenFileMappingA(
593 if (NULL == map_file_handle)
597 p_device_context = NULL;
609 if (NULL == p_device_queue)
614 p_device_context = NULL;
619 if (NULL == p_device_context)
625 p_device_context = NULL;
630 p_device_context->
lock = mutex_handle;
635 if (NULL == p_device_context)
637 if (NULL != p_device_queue)
639 UnmapViewOfFile(p_device_queue);
641 if (NULL != mutex_handle)
643 ReleaseMutex(mutex_handle);
644 CloseHandle(mutex_handle);
647 if (NULL != map_file_handle)
649 CloseHandle(map_file_handle);
653 ReleaseMutex(mutex_handle);
654 CloseHandle(map_file_handle);
657 return p_device_context;
660#elif __linux__ || __APPLE__
662#define DEV_NAME_PREFIX "rdisk"
663#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
664#define DEV_NAME_PREFIX "vd"
666#define DEV_NAME_PREFIX "nvme"
669#ifndef DEPRECATION_AS_ERROR
688#if defined(_ANDROID) || defined(__OPENHARMONY__)
689#define ANDROID_MAX_DIR_NUM 2
690 int android_dir_num = 0;
691 const char* dir_name_array[ANDROID_MAX_DIR_NUM];
692 dir_name_array[0] =
"/dev";
693 dir_name_array[1] =
"/dev/block";
695 const char* dir_name =
"/dev";
697 int i, xcoder_device_cnt = 0;
699 struct dirent* in_file;
702 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE;
706 if ((ni_devices == NULL)||(max_handles == 0))
712 int nvme_dev_cnt = 0;
718 const char *pattern =
"^rdisk[0-9]+$";
719#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
720 const char *pattern =
"^vd[a-z]$";
722 const char *pattern =
"^nvme[0-9]+(c[0-9]+)?n[0-9]+$";
725 if(regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB)) {
730#if defined(_ANDROID) || defined(__OPENHARMONY__)
733 while(xcoder_device_cnt == 0 && android_dir_num < ANDROID_MAX_DIR_NUM)
735 const char *dir_name = dir_name_array[android_dir_num];
740 dev_handle = NI_INVALID_DEVICE_HANDLE;
742 size_t size_of_nvme_devices_x =
sizeof(nvme_devices)/
sizeof(nvme_devices[0]);
743 for(
size_t dimx = 0; dimx < size_of_nvme_devices_x; ++dimx)
745 memset(nvme_devices[dimx], 0,
sizeof(nvme_devices[0]));
750 FD = opendir(dir_name);
754#if defined(_ANDROID) || defined(__OPENHARMONY__)
756 if(android_dir_num < ANDROID_MAX_DIR_NUM)
770 while ((in_file = readdir(FD)))
773 if (!strcmp(in_file->d_name,
".") || !strcmp(in_file->d_name,
".."))
780 if (!strncmp(in_file->d_name, DEV_NAME_PREFIX, strlen(DEV_NAME_PREFIX)))
782 if (nvme_dev_cnt < 200)
784 const int write_len = snprintf(nvme_devices[nvme_dev_cnt],
786 dir_name, in_file->d_name);
790 "ERROR: failed to copy device %d name %s\n",
791 nvme_dev_cnt, in_file->d_name);
796 skip_this = regexec(®ex, in_file->d_name, 0, NULL, 0);
803 "%s/%s", dir_name, in_file->d_name) < 0)
806 "ERROR: failed an snprintf() in "
807 "ni_rsrc_get_local_device_list()\n");
835 if (NI_INVALID_DEVICE_HANDLE != dev_handle)
839 &device_capabilites);
842 if (is_supported_xcoder(
845 ni_devices[xcoder_device_cnt][0] =
'\0';
858 (max_handles <= xcoder_device_cnt))
861 "Disregarding some Netint devices on system over "
862 "limit of NI_MAX_DEVICE_CNT(%d) or max_handles(%d)\n",
869#if defined(_ANDROID) || defined(__OPENHARMONY__)
877 if (0 == xcoder_device_cnt)
879 ni_log(
NI_LOG_INFO,
"Found %d NVMe devices on system, none of them xcoder\n", nvme_dev_cnt);
880 for (i = 0; i < nvme_dev_cnt; i++)
888 return xcoder_device_cnt;
909 int max_handles,
char **xcoder_refresh_dev_names,
910 int xcoder_refresh_dev_count)
914#define ANDROID_MAX_DIR_NUM 2
915 int android_dir_num = 0;
916 const char* dir_name_array[ANDROID_MAX_DIR_NUM];
917 dir_name_array[0] =
"/dev";
918 dir_name_array[1] =
"/dev/block";
920 const char* dir_name =
"/dev";
922 int i, xcoder_device_cnt = 0;
924 struct dirent* in_file;
927 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE;
929 bool device_in_ctxt =
false;
931 if ((ni_devices == NULL)||(max_handles == 0))
937 int nvme_dev_cnt = 0;
943 const char *pattern =
"^rdisk[0-9]+$";
944#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
945 const char *pattern =
"^vd[a-z]$";
947 const char *pattern =
"^nvme[0-9]+(c[0-9]+)?n[0-9]+$";
950 if(regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB)) {
958 while(xcoder_device_cnt == 0 && android_dir_num < ANDROID_MAX_DIR_NUM)
960 const char *dir_name = dir_name_array[android_dir_num];
964 device_in_ctxt =
false;
965 dev_handle = NI_INVALID_DEVICE_HANDLE;
967 size_t size_of_nvme_devices_x =
sizeof(nvme_devices)/
sizeof(nvme_devices[0]);
968 for(
size_t dimx = 0; dimx < size_of_nvme_devices_x; ++dimx)
970 memset(nvme_devices[dimx], 0,
sizeof(nvme_devices[0]));
975 FD = opendir(dir_name);
981 if(android_dir_num < ANDROID_MAX_DIR_NUM)
995 while ((in_file = readdir(FD)))
998 if (!strcmp(in_file->d_name,
".") || !strcmp(in_file->d_name,
".."))
1005 if (!strncmp(in_file->d_name, DEV_NAME_PREFIX, strlen(DEV_NAME_PREFIX)))
1007 if (nvme_dev_cnt < 200)
1009 const int write_len = snprintf(nvme_devices[nvme_dev_cnt],
1011 dir_name, in_file->d_name);
1015 "ERROR: failed to copy device %d name %s\n",
1016 nvme_dev_cnt, in_file->d_name);
1021 skip_this = regexec(®ex, in_file->d_name, 0, NULL, 0);
1028 "%s/%s", dir_name, in_file->d_name) < 0)
1031 "ERROR: failed an snprintf() in "
1032 "ni_rsrc_get_local_device_list2()\n");
1039 device_in_ctxt =
false;
1040 for (
int j = 0; j < xcoder_refresh_dev_count; j++)
1044 xcoder_refresh_dev_names[j]))
1046 device_in_ctxt =
true;
1060 if (NI_INVALID_DEVICE_HANDLE != dev_handle)
1063 &device_capabilites, device_in_ctxt);
1066 if (is_supported_xcoder(
1069 ni_devices[xcoder_device_cnt][0] =
'\0';
1072 xcoder_device_cnt++;
1081 (max_handles <= xcoder_device_cnt))
1084 "Disregarding some Netint devices on system over "
1085 "limit of NI_MAX_DEVICE_CNT(%d) or max_handles(%d)\n",
1100 if (0 == xcoder_device_cnt)
1102 ni_log(
NI_LOG_INFO,
"Found %d NVMe devices on system, none of them xcoder\n", nvme_dev_cnt);
1103 for (i = 0; i < nvme_dev_cnt; i++)
1109 return xcoder_device_cnt;
1122 ni_rsrc_shm_state state = NI_RSRC_SHM_IS_INVALID;
1123 const int flags = O_RDWR | O_CLOEXEC;
1124 const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
1126 ni_lock_handle_t lock;
1130 flags, mode, (
int *)&lock) < 0) {
1138 (
int *)&shm_fd) < 0) {
1146 (
void **)&p_device_queue)) < 0) {
1152 if (! p_device_pool) {
1159 p_device_pool->
lock = lock;
1164 lockf(lock, F_ULOCK, 0);
1166 if (NULL == p_device_pool) {
1170#ifndef __OPENHARMONY__
1176 return p_device_pool;
1197int ni_rsrc_init(
int should_match_rev,
int timeout_seconds)
1200 char api_version[5];
1201 int number_of_devices;
1203 const int limit_depth = 3;
1212 if (number_of_devices > 0)
1224 if (timeout_seconds == 0) {
1226 "and exit without wait\n");
1232 if (timeout_seconds != -1 && runtime >= (uint32_t)timeout_seconds)
1235 "Timeout exceeded/reached after %u seconds!\n",
1246 ret =
ni_rsrc_init_priv(should_match_rev, number_of_devices, device_names, limit_depth);
1279 ni_rsrc_shm_state state = NI_RSRC_SHM_IS_INVALID;
1281 const int flags = O_RDWR | O_CLOEXEC;
1282 const mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
1283 char shm_name[32] = { 0 };
1284 char lck_name[32] = { 0 };
1291 if (ni_rsrc_try_get_shm_lock(lck_name, flags, mode, &lock) < 0) {
1296 if (ni_rsrc_open_shm(shm_name,
1299 (
int *)&shm_fd) < 0) {
1304 if ((ni_rsrc_mmap_shm(shm_name,
1307 (
void **)&p_device_queue)) < 0) {
1313 if (!p_device_context) {
1323 p_device_context->
lock = lock;
1327 lockf(lock, F_ULOCK, 0);
1329#ifndef __OPENHARMONY__
1335 return p_device_context;
1348 if (p_device_context)
1352 ReleaseMutex(p_device_context->
lock);
1353#elif __linux__ || __APPLE__
1354 close(p_device_context->
lock);
1358 free(p_device_context);
1384 bool b_release_pool_mtx =
false;
1386 if ( (NULL == p_device_info) || (NULL == p_device_count) )
1393 if (NULL == p_device_pool)
1400 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
1403 "mutex: %p\n", p_device_pool->
lock);
1407#elif __linux__ || __APPLE__
1408 lockf(p_device_pool->
lock, F_LOCK, 0);
1411 b_release_pool_mtx =
true;
1414 count = (int)p_device_queue->
xcoder_cnt[device_type];
1417 for (i = 0; i < count; i++)
1420 guid = p_device_queue->
xcoders[device_type][i];
1422 if (p_device_context)
1425 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1428 "mutex: %p\n", p_device_context->
lock);
1429 ReleaseMutex(p_device_pool->
lock);
1435 ReleaseMutex(p_device_context->
lock);
1436#elif __linux__ || __APPLE__
1437 lockf(p_device_context->
lock, F_LOCK, 0);
1439 lockf(p_device_context->
lock, F_ULOCK, 0);
1444 (*p_device_count)++;
1454 if (b_release_pool_mtx)
1457 ReleaseMutex(p_device_pool->
lock);
1458#elif __linux__ || __APPLE__
1459 lockf(p_device_pool->
lock, F_ULOCK, 0);
1486 if (NULL == p_device)
1536 if (list_uninitialized)
1543 if (!list_uninitialized)
1555 for (
int dev_index = 0;
1569 ni_device_handle_t fd;
1571 for (
int dev_index = 0; dev_index < dev_count; dev_index++)
1573 if (is_str_in_str_array(dev_names[dev_index],
1580 if (NI_INVALID_DEVICE_HANDLE == fd)
1583 dev_names[dev_index]);
1592 dev_names[dev_index]);
1600 p_dev_info = &p_device->
xcoders[dev_type][dev_index];
1606 sizeof(capability.
fw_rev));
1660 " Operations: Crop (ni_quadra_crop), Scale (ni_quadra_scale), Pad "
1661 "(ni_quadra_pad), Overlay (ni_quadra_overlay)\n"
1662 " Drawbox (ni_quadra_drawbox), Rotate (ni_quadra_rotate), XStack (ni_quadra_xstack)\n");
1668 " Operations: ROI (ni_quadra_roi), Background Replace (ni_quadra_bg)\n");
1678 ni_codec_format_str[p_device_info->
dev_cap[i]
1683 ni_dec_name_str[p_device_info->
dev_cap[i]
1685 ni_enc_name_str[p_device_info->
dev_cap[i]
1798 if (NULL == p_device_context)
1804 if (NULL == p_device_info)
1810 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1813 "mutex: %p\n", p_device_context->
lock);
1814 free(p_device_info);
1819 ReleaseMutex(p_device_context->
lock);
1821 lockf(p_device_context->
lock, F_LOCK, 0);
1825 lockf(p_device_context->
lock, F_ULOCK, 0);
1832 return p_device_info;
1867 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
1870 __FUNCTION__, p_device_pool->
lock);
1874#elif __linux__ || __APPLE__
1875 lockf(p_device_pool->
lock, F_LOCK, 0);
1880 for (i = 0; i < num_coders; i++)
1885 if (p_device_context &&
1897 ReleaseMutex(p_device_pool->
lock);
1898#elif __linux__ || __APPLE__
1899 lockf(p_device_pool->
lock, F_ULOCK, 0);
1926 if (!p_device_context || !sw_instance_info)
1933 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1936 __func__, p_device_context->
lock);
1939#elif __linux__ || __APPLE__
1940 lockf(p_device_context->
lock, F_LOCK, 0);
1945 for (i = 0; i < sw_instance_cnt; i++)
1951 ReleaseMutex(p_device_context->
lock);
1952#elif __linux__ || __APPLE__
1953 lockf(p_device_context->
lock, F_ULOCK, 0);
1983 return p_device_context;
2002 (void) p_device_context;
2007 if (!p_device_context)
2014 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
2017 __func__, p_device_context->
lock);
2019#elif __linux__ || __APPLE__
2020 lockf(p_device_context->
lock, F_LOCK, 0);
2025 ni_log(
NI_LOG_INFO,
"Warning: releasing resource load %lu > current load %lu\n", load,
2033#if __linux__ || __APPLE__
2039 "p_device_info: %s\n", __func__, errmsg);
2045 ReleaseMutex(p_device_context->
lock);
2046#elif __linux__ || __APPLE__
2047 lockf(p_device_context->
lock, F_ULOCK, 0);
2068 bool b_release_pool_mtx =
false;
2086 if (!p_session_ctx || !p_api_param)
2093 p_session_ctx->
hw_id = guid;
2134 if (WAIT_ABANDONED ==
2135 WaitForSingleObject(p_device_pool->
lock,
2139 "ERROR: ni_rsrc_list_devices() failed to obtain mutex: %p\n",
2140 p_device_pool->
lock);
2145 lockf(p_device_pool->
lock, F_LOCK, 0);
2147 b_release_pool_mtx =
true;
2156 if (NI_INVALID_DEVICE_HANDLE == p_session_ctx->
device_handle)
2164 if (NI_INVALID_EVENT_HANDLE == p_session_ctx->
event_handle)
2175 "guid %d. %s is not avaiable, type: %d, retval:%d\n",
2177 device_type, retval);
2197 "vpu recovery happened on guid %d. %s, retry "
2208 "session open error guid %d. %s, type: %d, "
2211 device_type, retval);
2221 "Error get device resource: guid %d, device_ctx %p\n", guid,
2228 if (b_release_pool_mtx)
2231 ReleaseMutex(p_device_pool->
lock);
2233 lockf(p_device_pool->
lock, F_ULOCK, 0);
2262#if __linux__ || __APPLE__
2268 unsigned int guid_index_i, guid_index_j, ui_device_type;
2293 rValue = WaitForSingleObject(p_device_pool->
lock, INFINITE);
2294 if (rValue != WAIT_OBJECT_0)
2297 "ERROR: %s() Failed to obtain mutex %p\n",
2299 p_device_pool->
lock);
2303#elif __linux__ || __APPLE__
2304 lockf(p_device_pool->
lock, F_LOCK, 0);
2314 guid = p_device_queue->
xcoders[ui_device_type][guid_index_i];
2321 if (!p_device_context)
2324 "ERROR: %s() Failed to obtain device context for "
2325 "%s with GUID %u! Undefined behavior!\n",
2340 "ERROR: %s() Devicename format mismatch %s %s\n",
2348 CloseHandle(p_device_context->
lock);
2349#elif __linux__ || __APPLE__
2353 "%s %s %s deleted\n",
2362 "ERROR: %s(): %s %s %s failed to delete %s\n",
2374#if __linux__ || __APPLE__
2376 if (!unlink(lck_name))
2379 "%s %s %s deleted\n",
2388 "ERROR: %s(): %s %s %s failed to delete %s\n",
2403 p_device_queue->
xcoders[ui_device_type][guid_index_i] = -1;
2404 p_device_queue->
xcoder_cnt[ui_device_type]--;
2415 memset(guids, -1,
sizeof(guids));
2419 guid = p_device_queue->
xcoders[ui_device_type][guid_index_i];
2422 guids[guid_index_j] = guid;
2424 if (guid_index_j == p_device_queue->
xcoder_cnt[ui_device_type])
2430 memcpy(p_device_queue->
xcoders[ui_device_type], guids,
sizeof(guids));
2433#if __linux__ || __APPLE__
2435 if (!msync((
void *)p_device_queue,
2437 MS_SYNC|MS_INVALIDATE))
2445 "ERROR: %s(): msync() failed to delete %s: %s\n",
2455 ReleaseMutex(p_device_pool->
lock);
2456#elif __linux__ || __APPLE__
2457 lockf(p_device_pool->
lock, F_ULOCK, 0);
2463 return return_value;
2478 int xcoder_dev_count = 0;
2506 xcoder_dev_names[i]);
2512 "%d devices retrieved from current pool at start up\n",
2516 "%d devices retrieved from current pool at start up\n",
2527 for (i = 0; i < xcoder_dev_count; i++)
2530 xcoder_dev_names[i]);
2535 xcoder_dev_names[i]);
2539 xcoder_dev_names[i]);
2543#if __linux__ || __APPLE__
2555 if (0 == unlink(XCODERS_RETRY_LCK_NAME[i]))
2558 i, XCODERS_RETRY_LCK_NAME[i]);
2563 i, XCODERS_RETRY_LCK_NAME[i]);
2595 uint32_t i, existing_number_of_devices;
2616 if (WAIT_ABANDONED == WaitForSingleObject(device_pool->
lock, INFINITE))
2619 "ERROR: %s(): Failed to obtain lock %p\n",
2624#elif __linux__ || __APPLE__
2625 lockf(device_pool->
lock, F_LOCK, 0);
2632 existing_number_of_devices = device_queue->
xcoder_cnt[device_type];
2637 "ERROR: %s(): Limit of NI_MAX_DEVICE_CNT(%d) existing Quadra "
2638 "devices previously reached. Not adding %s.\n",
2646 for (i = 0; i < existing_number_of_devices; i++)
2650 device_queue->
xcoders[device_type][i]);
2657 "ERROR: %s(): %s already exists in resource pool\n",
2676 ReleaseMutex(device_pool->
lock);
2677#elif __linux__ || __APPLE__
2678 lockf(device_pool->
lock, F_ULOCK, 0);
2695 if (NI_INVALID_LOCK_HANDLE != p_device_pool->
lock)
2698 CloseHandle(p_device_pool->
lock);
2699#elif __linux__ || __APPLE__
2700 close(p_device_pool->
lock);
2710 free(p_device_pool);
2729 *lock = CreateMutexA(NULL, FALSE, XCODERS_RETRY_LCK_NAME[device_type]);
2735 __func__, XCODERS_RETRY_LCK_NAME[device_type],
2744 open(XCODERS_RETRY_LCK_NAME[device_type], O_RDWR | O_CLOEXEC);
2766 DWORD ret = WaitForSingleObject(*lock, 1);
2767 if (WAIT_OBJECT_0 == ret)
2770 }
else if (WAIT_TIMEOUT != ret)
2777 status = lockf(*lock, F_LOCK, 0);
2794 while (status != 0);
2810 if (lock == NI_INVALID_LOCK_HANDLE)
2816 bool unlocked =
false;
2824 unlocked = (ReleaseMutex(lock) != 0);
2826 unlocked = (lockf(lock, F_ULOCK, 0) == 0);
2839 }
while (!unlocked);
2883 char cmd[128] = {0};
2884 char cmd_ret[64] = {0};
2890 ptr = device_name + 5;
2891 (void)snprintf(cmd,
sizeof(cmd) - 1,
"cat /sys/block/%s/device/*/numa_node",ptr);
2892 cmd_fp = popen(cmd,
"r");
2897 if (fgets(cmd_ret,
sizeof(cmd_ret)/
sizeof(cmd_ret[0]), cmd_fp) == NULL)
2899 goto get_numa_node_ret;
2907 goto get_numa_node_ret;
2909 ret = (int)tmp_numa;
2919int int_cmp(
const void *a,
const void *b)
2921 const int *ia = (
const int *)a;
2922 const int *ib = (
const int *)b;
2923 return (*ia == *ib) ? 0 : ((*ia > *ib) ? 1 : -1);
2927int ni_hw_device_info_quadra_threshold_param_t_compare(
const void *pl,
const void *pr)
2950 int factor_8_10 = 1;
2951 const uint32_t resolution = decoder_param->
h * decoder_param->
w;
2956 return resolution >= 1920*1080 ?
2957 (int)(((uint64_t)(resolution)*(uint64_t)(decoder_param->
fps)*(uint64_t)(factor_8_10)*100)/1440/1920/1080) :
2958 (int)((uint64_t)(resolution)*(uint64_t)(decoder_param->fps)*(uint64_t)(factor_8_10)*100/2880/1280/720);
2972 double factor = 1.0;
2973 double factor_codec = 1.0;
2974 double factor_rdoq = 1.0;
2975 double factor_rdoLevel = 1.0;
2976 double factor_lookahead = 1.0;
2977 double factor_8_10_bit = 1.0;
2978 double factor_720p = 1.0;
2980 const int resolution = (int)(encoder_param->
w * encoder_param->
h);
2985 factor_codec = 0.67;
2997 factor_rdoLevel = (encoder_param->
rdoLevel == 2) ? 1.91 : 3.28;
3002 factor_lookahead = (double)(encoder_param->
lookaheadDepth * 0.0014 + 1.012);
3008 factor_8_10_bit = 2;
3011 factor_720p = 1.125;
3012 factor = factor_codec * factor_8_10_bit * factor_rdoq * factor_rdoLevel
3013 * factor_lookahead * factor_720p;
3019 ((uint32_t)((uint32_t)factor*encoder_param->
fps * resolution)) /
3020 ((3840ULL * 2160 * 60) / 100 * 4));
3035int check_hw_info_shared_mem_calculate_b_scale(
int h,
int w,
int bit_8_10,
int rgba)
3037 const int stride = 128;
3038 const int estimated_yuv_size = rgba ?
3041 ( ((w + stride - 1)/stride)*stride + ((w/2 + stride - 1)/stride)*stride ) * h:
3042 ( ((w * 2 + stride - 1)/stride)*stride + ((w + stride - 1)/stride)*stride ) * h;
3043 const int b_unit = 1601536;
3044 const int b_scale = (estimated_yuv_size + b_unit -1) / b_unit;
3076 const int v32_ofCores_calculate = 0;
3078 const int b_counts = (int)(v32_ofCores_calculate +
3081 (encoder_param->uploader ? 1 : 0) * 3 +
3083 const int b_scale = check_hw_info_shared_mem_calculate_b_scale((
int)encoder_param->
h, (
int)encoder_param->
w,
3084 (
int)encoder_param->
bit_8_10, (
int)encoder_param->
rgba);
3085 return b_scale * b_counts;
3109 const int hw_frame = decoder_param->
hw_frame;
3111 const int v30_xlsx = 0;
3112 const int b_counts = 1 * (v30_xlsx +
3113 (hw_frame ? 0 : 1)*3 +
3115 const int b_scale = check_hw_info_shared_mem_calculate_b_scale((
int)decoder_param->
h, (
int)decoder_param->
w,
3116 (
int)decoder_param->
bit_8_10, (
int)decoder_param->
rgba);
3117 return b_scale * b_counts;
3144 const int v30_xlsx = 0;
3145 const int b_counts = 1 * (v30_xlsx +
3148 const int b_scale = check_hw_info_shared_mem_calculate_b_scale((
int)scaler_param->
h, (
int)scaler_param->
w,
3150 return b_scale * b_counts;
3168 const int total = 2456;
3169 int task_mem_usage = 0;
3170 int task_mem_precentage = 0;
3176 for(i = 0; i < card_num; ++i)
3185 task_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16);
3189 task_mem_usage = check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param);
3193 task_mem_usage = check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3197 const int decoder_shared_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16);
3198 const int encoder_shared_mem_usage = check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param);
3199 const int scaler_shared_mem_usage = check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3200 task_mem_usage = decoder_shared_mem_usage + ((encoder_shared_mem_usage > scaler_shared_mem_usage) ?
3201 encoder_shared_mem_usage : scaler_shared_mem_usage);
3206 task_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16) +
3207 check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param)+
3208 check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3211 task_mem_precentage = 100 * task_mem_usage / total;
3213 if(task_mem_precentage > 90)
3216 task_mem_precentage = 90;
3219 for(i = 0;i<card_num;++i)
3221 if(card_remove[i] == 1)
3247 if(p_coder_param == NULL)
3249 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_coder_param\n");
3250 return p_coder_param;
3259 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_decoder_param\n");
3260 free(p_coder_param);
3261 p_coder_param = NULL;
3262 return p_coder_param;
3270 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_encoder_param\n");
3271 free(p_coder_param);
3272 p_coder_param = NULL;
3273 return p_coder_param;
3281 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_scaler_param\n");
3282 free(p_coder_param);
3283 p_coder_param = NULL;
3284 return p_coder_param;
3290 if(p_coder_param->
ai_param == NULL)
3292 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_ai_param\n");
3293 free(p_coder_param);
3294 p_coder_param = NULL;
3295 return p_coder_param;
3303 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_encoder_param\n");
3304 free(p_coder_param);
3305 p_coder_param = NULL;
3306 return p_coder_param;
3311 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_decoder_param\n");
3314 free(p_coder_param);
3315 p_coder_param = NULL;
3316 return p_coder_param;
3321 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_scaler_param\n");
3326 free(p_coder_param);
3327 p_coder_param = NULL;
3328 return p_coder_param;
3331 if(p_coder_param->
ai_param == NULL)
3333 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_ai_param\n");
3340 free(p_coder_param);
3341 p_coder_param = NULL;
3342 return p_coder_param;
3382 return p_coder_param;
3398 if(p_hw_device_info_quadra_coder_param == NULL)
3414 free(p_hw_device_info_quadra_coder_param->
scaler_param);
3415 p_hw_device_info_quadra_coder_param->
scaler_param = NULL;
3417 if(p_hw_device_info_quadra_coder_param->
ai_param)
3419 free(p_hw_device_info_quadra_coder_param->
ai_param);
3420 p_hw_device_info_quadra_coder_param->
ai_param = NULL;
3422 free(p_hw_device_info_quadra_coder_param);
3439 if(!p_hw_device_info)
3441 ni_log(
NI_LOG_ERROR,
"ERROR: Failed to allocate memory for p_hw_device_info_quadra_t\n");
3442 goto p_hw_device_info_end;
3449 ni_log(
NI_LOG_ERROR,
"ERROR: Failed to allocate memory for p_hw_device_info_quadra_t->device_type\n");
3450 goto device_type_end;
3468 if(p_hw_device_info->
card_info[i] == NULL)
3471 goto card_info_i_end;
3475 return p_hw_device_info;
3486 free(
reinterpret_cast<void*
>(p_hw_device_info->
card_info));
3492 free(p_hw_device_info);
3493 p_hw_device_info = NULL;
3494p_hw_device_info_end:
3509 if(!p_hw_device_info)
3520 free(
reinterpret_cast<void*
>(p_hw_device_info->
card_info));
3522 free(p_hw_device_info);
3539 const int should_match_rev = 1;
3540 int module_count = 1;
3542 int32_t *module_id_arr = NULL;
3548 int *card_remove = NULL;
3551 uint64_t decoder_need_load = 0;
3552 uint64_t encoder_need_load = 0;
3555 const int hw_info_param_num = hw_mode ? 4 : 1;
3556 int device_type_num = 1;
3557 const int all_device_type_num = 4;
3565 bool b_valid =
false;
3571 bool pool_locked =
false;
3574 if(!pointer_to_p_hw_device_info)
3576 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: pointer_to_p_hw_device_info is NULL.\n");
3580 if(*pointer_to_p_hw_device_info)
3582 p_hw_device_info = *pointer_to_p_hw_device_info;
3594 }
else if(hw_mode && hw_mode != coder_param->
hw_mode)
3596 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: hw_mode = %d, coder_param->hw_mode = %d\n",
3597 hw_mode,coder_param->
hw_mode);
3603 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_ENCODER but coder_param->encoder_param == NULL\n");
3608 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_DECODER but coder_param->decoder_param == NULL\n");
3613 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_SCALER but coder_param->scaler_param == NULL\n");
3618 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_AI but coder_param->ai_param == NULL\n");
3624 if((task_mode != 0 && task_mode != 1) ||
3633 task_mode, preferential_device_type);
3637 if(!hw_info_threshold_param)
3643 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: hw_info_threshold_param is NULL.\n");
3646 for(i = 0;i < hw_info_param_num; ++i)
3648 if(hw_info_threshold_param[i].load_threshold < 0||
3649 hw_info_threshold_param[i].load_threshold > 100 ||
3650 hw_info_threshold_param[i].task_num_threshold < 0 ||
3661 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",
3662 (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);
3728 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3734#elif defined(__linux__)
3735 if (lockf(p_device_pool->
lock, F_LOCK, 0))
3762 for(i = 0; i < all_device_type_num; ++i)
3764 if(all_need_device_type[i] == preferential_device_type)
3767 all_need_device_type[i] = all_need_device_type[0];
3768 all_need_device_type[0] = tmp;
3773 qsort(&all_need_device_type[1], all_device_type_num - 1,
sizeof(
ni_device_type_t), int_cmp);
3779 device_type_num = 4;
3781 for(i = 0; i < device_type_num; ++i)
3783 if(hw_info_threshold_param[i].device_type == preferential_device_type)
3786 hw_info_threshold_param[i] = hw_info_threshold_param[0];
3787 hw_info_threshold_param[0] = tmp;
3791 qsort(&hw_info_threshold_param[1], device_type_num - 1,
3795 if(!(*pointer_to_p_hw_device_info))
3798 if(!p_hw_device_info)
3803 *pointer_to_p_hw_device_info = p_hw_device_info;
3814 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->device_type is NULL\n");
3820 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->card_info is NULL\n");
3824 for(i = 0; i < device_type_num; ++i)
3828 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);
3842 p_hw_device_info->
device_type[i] = all_need_device_type[i];
3880 card_remove = (int32_t *)malloc(
sizeof(int32_t) * p_hw_device_info->
available_card_num);
3890 module_count = (int)coders->
xcoder_cnt[preferential_device_type];
3898 module_id_arr = (int32_t *)malloc(
sizeof(int32_t) * module_count);
3907 memcpy(module_id_arr, coders->
xcoders[preferential_device_type],
sizeof(int32_t) * module_count);
3911 qsort(module_id_arr, module_count,
sizeof(int32_t), int_cmp);
3917 memset(p_xCtxt, 0,
sizeof(*p_xCtxt));
3919 if (p_device_context)
3953 for(
int j = 0; j < device_type_num; ++j)
3957 if(p_device_context)
4003 p_device_context = NULL;
4024 decoder_need_load = check_hw_info_decoder_need_load(coder_param->
decoder_param);
4028 encoder_need_load = check_hw_info_encoder_need_load(coder_param->
encoder_param);
4043 ni_log(
NI_LOG_DEBUG,
"%s Card[%3d], load: %3d, task_num: %3d, firmware_load: %3d, model_load: %3d, shared_mem_usage: %3d\n",
4045 ni_log(
NI_LOG_INFO,
"%s Card[%3d], load: %3d, task_num: %3d, firmware_load: %3d, model_load: %3d, shared_mem_usage: %3d\n",
4057 if(card_remove[i] == 1)
4112 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,10);
4114 else if(preferential_device_type == 0)
4116 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,0);
4118 else if(preferential_device_type == 1)
4120 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,1);
4122 else if(preferential_device_type == 2)
4124 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,2);
4136 card_remove[i] == 0)
4146 card_remove[i] == 0 &&
4162 card_remove[i] == 0)
4180 ReleaseMutex((HANDLE)p_device_pool->
lock);
4182#elif defined(__linux__)
4183 if (lockf(p_device_pool->
lock, F_ULOCK,0))
4186 if(p_hw_device_info)
4197 p_device_context = NULL;
4199 (void)fflush(stderr);
4202 free(module_id_arr);
4203 module_id_arr = NULL;
4208 dev_ctxt_arr = NULL;
4234 ni_log(
NI_LOG_DEBUG,
"In sw_mode select device_type %s card_current_card %d retval %d\n",
4236 ni_log(
NI_LOG_INFO,
"In sw_mode select device_type %s card_current_card %d retval %d\n",
4238 ((preferential_device_type == 0) ?
"decode" : (preferential_device_type == 1 ?
"encode" : (preferential_device_type == 2 ?
"scaler" :
"ai "))), p_hw_device_info->
card_current_card, retval);
4270 int width,
int height,
4283 uint32_t num_sw_instances = 0;
4284 int least_model_load = 0;
4285 uint64_t job_mload = 0;
4304 if (!p_session_context)
4310 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
4314#elif __linux__ || __APPLE__
4315 lockf(p_device_pool->
lock, F_LOCK, 0);
4321 for (i = 0; i < count; i++)
4325 if (!p_device_context)
4328 "ERROR: %s() ni_rsrc_get_device_context() failed\n", __func__);
4337 if (NI_INVALID_DEVICE_HANDLE == p_session_context->
device_handle)
4356 g_device_type_str[device_type],
4364 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
4367 __func__, p_device_context->
lock);
4369#elif __linux__ || __APPLE__
4370 lockf(p_device_context->
lock, F_LOCK, 0);
4378 load = p_device_info->
load;
4379 least_model_load = p_device_info->
model_load;
4383 ni_log(
NI_LOG_INFO,
"Coder [%d]: %d , load: %d (%d), activ_inst: %d , max_inst %d\n",
4404 if (p_device_info->
model_load < least_model_load)
4407 least_model_load = p_device_info->
model_load;
4410 else if (p_device_info->
load < load)
4413 load = p_device_info->
load;
4420 ReleaseMutex(p_device_context->
lock);
4421#elif __linux__ || __APPLE__
4422 lockf(p_device_context->
lock, F_ULOCK, 0);
4430 if (!p_device_context)
4433 "ERROR: %s() ni_rsrc_get_device_context() failed\n", __func__);
4439 job_mload = (uint64_t)width * height * frame_rate;
4445 p_device_context = NULL;
4450 ReleaseMutex(p_device_pool->
lock);
4451#elif __linux__ || __APPLE__
4452 lockf(p_device_pool->
lock, F_ULOCK, 0);
4459 *p_load = job_mload;
4461 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_retcode_t ni_query_extra_info(ni_device_handle_t device_handle, ni_device_extra_info_t *p_dev_extra_info, uint8_t fw_rev[])
Query CompositeTemp from device.
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
ni_retcode_t ni_strtoi(const char *str, int32_t *out_val)
Safely convert a decimal string to a 32-bit integer with full validation. Trailing whitespace is tole...
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