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;
302android::sp<INidec>
service = NULL;
316 service = INidec::tryGetService();
330#ifndef DEPRECATION_AS_ERROR
351 if ((ni_devices == NULL)||(max_handles == 0))
377 int max_handles,
char **xcoder_refresh_dev_names,
378 int xcoder_refresh_dev_count)
380 if ((ni_devices == NULL)||(max_handles == 0))
399 HANDLE map_file_handle = NULL;
400 HANDLE mutex_handle = NULL;
403 mutex_handle = CreateMutex(NULL,
408 if (NULL == mutex_handle)
415 if (WAIT_ABANDONED == WaitForSingleObject(mutex_handle, INFINITE))
420 map_file_handle = OpenFileMapping(
426 if (NULL == map_file_handle)
428 ReleaseMutex(mutex_handle);
429 CloseHandle(mutex_handle);
443 if (NULL == p_device_queue)
445 ReleaseMutex(mutex_handle);
446 CloseHandle(mutex_handle);
447 CloseHandle(map_file_handle);
452 if (NULL == p_device_pool)
458 UnmapViewOfFile(p_device_queue);
462 p_device_pool->
lock = mutex_handle;
466 ReleaseMutex(mutex_handle);
467 CloseHandle(map_file_handle);
468 return p_device_pool;
489int ni_rsrc_init(
int should_match_rev,
int timeout_seconds)
493 int number_of_devices = 0;
494 uint32_t runtime = 0;
495 while (0 == number_of_devices)
505 else if (0 == number_of_devices)
513 if (timeout_seconds == 0) {
515 "and exit without wait\n");
520 if (runtime >= (uint32_t)timeout_seconds)
554 char shm_name[32] = { 0 };
555 char lck_name[32] = { 0 };
558 HANDLE map_file_handle = NULL;
559 HANDLE mutex_handle = NULL;
565 mutex_handle = CreateMutex(NULL,
569 if (NULL == mutex_handle)
572 p_device_context = NULL;
576 if (WAIT_ABANDONED == WaitForSingleObject(mutex_handle, INFINITE))
579 "obtain mutex: %p\n", mutex_handle);
582 map_file_handle = OpenFileMapping(
588 if (NULL == map_file_handle)
592 p_device_context = NULL;
604 if (NULL == p_device_queue)
609 p_device_context = NULL;
614 if (NULL == p_device_context)
620 p_device_context = NULL;
625 p_device_context->
lock = mutex_handle;
630 if (NULL == p_device_context)
632 if (NULL != p_device_queue)
634 UnmapViewOfFile(p_device_queue);
636 if (NULL != mutex_handle)
638 ReleaseMutex(mutex_handle);
639 CloseHandle(mutex_handle);
642 if (NULL != map_file_handle)
644 CloseHandle(map_file_handle);
648 ReleaseMutex(mutex_handle);
649 CloseHandle(map_file_handle);
652 return p_device_context;
655#elif __linux__ || __APPLE__
657#define DEV_NAME_PREFIX "rdisk"
658#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
659#define DEV_NAME_PREFIX "vd"
661#define DEV_NAME_PREFIX "nvme"
664#ifndef DEPRECATION_AS_ERROR
683#if defined(_ANDROID) || defined(__OPENHARMONY__)
684#define ANDROID_MAX_DIR_NUM 2
685 int android_dir_num = 0;
686 const char* dir_name_array[ANDROID_MAX_DIR_NUM];
687 dir_name_array[0] =
"/dev";
688 dir_name_array[1] =
"/dev/block";
690 const char* dir_name =
"/dev";
692 int i, xcoder_device_cnt = 0;
694 struct dirent* in_file;
697 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE;
701 if ((ni_devices == NULL)||(max_handles == 0))
707 int nvme_dev_cnt = 0;
713 const char *pattern =
"^rdisk[0-9]+$";
714#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
715 const char *pattern =
"^vd[a-z]$";
717 const char *pattern =
"^nvme[0-9]+(c[0-9]+)?n[0-9]+$";
720 if(regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB)) {
725#if defined(_ANDROID) || defined(__OPENHARMONY__)
728 while(xcoder_device_cnt == 0 && android_dir_num < ANDROID_MAX_DIR_NUM)
730 const char *dir_name = dir_name_array[android_dir_num];
735 dev_handle = NI_INVALID_DEVICE_HANDLE;
737 size_t size_of_nvme_devices_x =
sizeof(nvme_devices)/
sizeof(nvme_devices[0]);
738 for(
size_t dimx = 0; dimx < size_of_nvme_devices_x; ++dimx)
740 memset(nvme_devices[dimx], 0,
sizeof(nvme_devices[0]));
745 if (NULL == (FD = opendir(dir_name)))
748#if defined(_ANDROID) || defined(__OPENHARMONY__)
750 if(android_dir_num < ANDROID_MAX_DIR_NUM)
764 while ((in_file = readdir(FD)))
767 if (!strcmp(in_file->d_name,
".") || !strcmp(in_file->d_name,
".."))
774 if (!strncmp(in_file->d_name, DEV_NAME_PREFIX, strlen(DEV_NAME_PREFIX)))
776 if (nvme_dev_cnt < 200)
778 int write_len = snprintf(nvme_devices[nvme_dev_cnt],
780 dir_name, in_file->d_name);
784 "ERROR: failed to copy device %d name %s\n",
785 nvme_dev_cnt, in_file->d_name);
790 skip_this = regexec(®ex, in_file->d_name, 0, NULL, 0);
797 "%s/%s", dir_name, in_file->d_name) < 0)
800 "ERROR: failed an snprintf() in "
801 "ni_rsrc_get_local_device_list()\n");
829 if (NI_INVALID_DEVICE_HANDLE != dev_handle)
833 &device_capabilites);
836 if (is_supported_xcoder(
839 ni_devices[xcoder_device_cnt][0] =
'\0';
852 (max_handles <= xcoder_device_cnt))
855 "Disregarding some Netint devices on system over "
856 "limit of NI_MAX_DEVICE_CNT(%d) or max_handles(%d)\n",
863#if defined(_ANDROID) || defined(__OPENHARMONY__)
871 if (0 == xcoder_device_cnt)
873 ni_log(
NI_LOG_INFO,
"Found %d NVMe devices on system, none of them xcoder\n", nvme_dev_cnt);
874 for (i = 0; i < nvme_dev_cnt; i++)
882 return xcoder_device_cnt;
903 int max_handles,
char **xcoder_refresh_dev_names,
904 int xcoder_refresh_dev_count)
908#define ANDROID_MAX_DIR_NUM 2
909 int android_dir_num = 0;
910 const char* dir_name_array[ANDROID_MAX_DIR_NUM];
911 dir_name_array[0] =
"/dev";
912 dir_name_array[1] =
"/dev/block";
914 const char* dir_name =
"/dev";
916 int i, xcoder_device_cnt = 0;
918 struct dirent* in_file;
921 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE;
923 bool device_in_ctxt =
false;
925 if ((ni_devices == NULL)||(max_handles == 0))
931 int nvme_dev_cnt = 0;
937 const char *pattern =
"^rdisk[0-9]+$";
938#elif defined(XCODER_LINUX_VIRTIO_DRIVER_ENABLED)
939 const char *pattern =
"^vd[a-z]$";
941 const char *pattern =
"^nvme[0-9]+(c[0-9]+)?n[0-9]+$";
944 if(regcomp(®ex, pattern, REG_EXTENDED | REG_NOSUB)) {
952 while(xcoder_device_cnt == 0 && android_dir_num < ANDROID_MAX_DIR_NUM)
954 const char *dir_name = dir_name_array[android_dir_num];
958 device_in_ctxt =
false;
959 dev_handle = NI_INVALID_DEVICE_HANDLE;
961 size_t size_of_nvme_devices_x =
sizeof(nvme_devices)/
sizeof(nvme_devices[0]);
962 for(
size_t dimx = 0; dimx < size_of_nvme_devices_x; ++dimx)
964 memset(nvme_devices[dimx], 0,
sizeof(nvme_devices[0]));
969 if (NULL == (FD = opendir(dir_name)))
974 if(android_dir_num < ANDROID_MAX_DIR_NUM)
988 while ((in_file = readdir(FD)))
991 if (!strcmp(in_file->d_name,
".") || !strcmp(in_file->d_name,
".."))
998 if (!strncmp(in_file->d_name, DEV_NAME_PREFIX, strlen(DEV_NAME_PREFIX)))
1000 if (nvme_dev_cnt < 200)
1002 int write_len = snprintf(nvme_devices[nvme_dev_cnt],
1004 dir_name, in_file->d_name);
1008 "ERROR: failed to copy device %d name %s\n",
1009 nvme_dev_cnt, in_file->d_name);
1014 skip_this = regexec(®ex, in_file->d_name, 0, NULL, 0);
1021 "%s/%s", dir_name, in_file->d_name) < 0)
1024 "ERROR: failed an snprintf() in "
1025 "ni_rsrc_get_local_device_list2()\n");
1032 device_in_ctxt =
false;
1033 for (
int j = 0; j < xcoder_refresh_dev_count; j++)
1037 xcoder_refresh_dev_names[j]))
1039 device_in_ctxt =
true;
1053 if (NI_INVALID_DEVICE_HANDLE != dev_handle)
1056 &device_capabilites, device_in_ctxt);
1059 if (is_supported_xcoder(
1062 ni_devices[xcoder_device_cnt][0] =
'\0';
1065 xcoder_device_cnt++;
1074 (max_handles <= xcoder_device_cnt))
1077 "Disregarding some Netint devices on system over "
1078 "limit of NI_MAX_DEVICE_CNT(%d) or max_handles(%d)\n",
1093 if (0 == xcoder_device_cnt)
1095 ni_log(
NI_LOG_INFO,
"Found %d NVMe devices on system, none of them xcoder\n", nvme_dev_cnt);
1096 for (i = 0; i < nvme_dev_cnt; i++)
1102 return xcoder_device_cnt;
1115 ni_rsrc_shm_state state = NI_RSRC_SHM_IS_INVALID;
1116 int flags = O_RDWR | O_CLOEXEC;
1117 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
1119 ni_lock_handle_t lock;
1123 flags, mode, (
int *)&lock) < 0) {
1131 (
int *)&shm_fd) < 0) {
1139 (
void **)&p_device_queue)) < 0) {
1145 if (! p_device_pool) {
1152 p_device_pool->
lock = lock;
1157 lockf(lock, F_ULOCK, 0);
1159 if (NULL == p_device_pool) {
1163#ifndef __OPENHARMONY__
1169 return p_device_pool;
1190int ni_rsrc_init(
int should_match_rev,
int timeout_seconds)
1193 char api_version[5];
1194 int number_of_devices;
1196 int limit_depth = 3;
1205 if (number_of_devices > 0)
1217 if (timeout_seconds == 0) {
1219 "and exit without wait\n");
1224 if (runtime >= (uint32_t)timeout_seconds)
1227 "Timeout exceeded/reached after %u seconds!\n",
1238 ret =
ni_rsrc_init_priv(should_match_rev, number_of_devices, device_names, limit_depth);
1271 ni_rsrc_shm_state state = NI_RSRC_SHM_IS_INVALID;
1273 int flags = O_RDWR | O_CLOEXEC;
1274 mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP;
1275 char shm_name[32] = { 0 };
1276 char lck_name[32] = { 0 };
1283 if (ni_rsrc_try_get_shm_lock(lck_name, flags, mode, &lock) < 0) {
1288 if (ni_rsrc_open_shm(shm_name,
1291 (
int *)&shm_fd) < 0) {
1296 if ((ni_rsrc_mmap_shm(shm_name,
1299 (
void **)&p_device_queue)) < 0) {
1305 if (!p_device_context) {
1315 p_device_context->
lock = lock;
1319 lockf(lock, F_ULOCK, 0);
1321#ifndef __OPENHARMONY__
1327 return p_device_context;
1340 if (p_device_context)
1344 ReleaseMutex(p_device_context->
lock);
1345#elif __linux__ || __APPLE__
1346 close(p_device_context->
lock);
1350 free(p_device_context);
1376 bool b_release_pool_mtx =
false;
1378 if ( (NULL == p_device_info) || (NULL == p_device_count) )
1385 if (NULL == p_device_pool)
1392 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
1395 "mutex: %p\n", p_device_pool->
lock);
1399#elif __linux__ || __APPLE__
1400 lockf(p_device_pool->
lock, F_LOCK, 0);
1403 b_release_pool_mtx =
true;
1406 count = p_device_queue->
xcoder_cnt[device_type];
1409 for (i = 0; i < count; i++)
1412 guid = p_device_queue->
xcoders[device_type][i];
1414 if (p_device_context)
1417 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1420 "mutex: %p\n", p_device_context->
lock);
1421 ReleaseMutex(p_device_pool->
lock);
1427 ReleaseMutex(p_device_context->
lock);
1428#elif __linux__ || __APPLE__
1429 lockf(p_device_context->
lock, F_LOCK, 0);
1431 lockf(p_device_context->
lock, F_ULOCK, 0);
1436 (*p_device_count)++;
1446 if (b_release_pool_mtx)
1449 ReleaseMutex(p_device_pool->
lock);
1450#elif __linux__ || __APPLE__
1451 lockf(p_device_pool->
lock, F_ULOCK, 0);
1478 if (NULL == p_device)
1528 if (list_uninitialized)
1535 if (!list_uninitialized)
1547 for (
int dev_index = 0;
1561 ni_device_handle_t fd;
1563 for (
int dev_index = 0; dev_index < dev_count; dev_index++)
1565 if (is_str_in_str_array(dev_names[dev_index],
1572 if (NI_INVALID_DEVICE_HANDLE == fd)
1575 dev_names[dev_index]);
1584 dev_names[dev_index]);
1592 p_dev_info = &p_device->
xcoders[dev_type][dev_index];
1598 sizeof(capability.
fw_rev));
1647 " Operations: Crop (ni_quadra_crop), Scale (ni_quadra_scale), Pad "
1648 "(ni_quadra_pad), Overlay (ni_quadra_overlay)\n"
1649 " Drawbox (ni_quadra_drawbox), Rotate (ni_quadra_rotate), XStack (ni_quadra_xstack)\n");
1655 " Operations: ROI (ni_quadra_roi), Background Replace (ni_quadra_bg)\n");
1665 ni_codec_format_str[p_device_info->
dev_cap[i]
1670 ni_dec_name_str[p_device_info->
dev_cap[i]
1672 ni_enc_name_str[p_device_info->
dev_cap[i]
1785 if (NULL == p_device_context)
1791 if (NULL == p_device_info)
1797 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1800 "mutex: %p\n", p_device_context->
lock);
1801 free(p_device_info);
1806 ReleaseMutex(p_device_context->
lock);
1808 lockf(p_device_context->
lock, F_LOCK, 0);
1812 lockf(p_device_context->
lock, F_ULOCK, 0);
1819 return p_device_info;
1854 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
1857 __FUNCTION__, p_device_pool->
lock);
1861#elif __linux__ || __APPLE__
1862 lockf(p_device_pool->
lock, F_LOCK, 0);
1867 for (i = 0; i < num_coders; i++)
1872 if (p_device_context &&
1884 ReleaseMutex(p_device_pool->
lock);
1885#elif __linux__ || __APPLE__
1886 lockf(p_device_pool->
lock, F_ULOCK, 0);
1913 if (!p_device_context || !sw_instance_info)
1920 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
1923 __func__, p_device_context->
lock);
1926#elif __linux__ || __APPLE__
1927 lockf(p_device_context->
lock, F_LOCK, 0);
1932 for (i = 0; i < sw_instance_cnt; i++)
1938 ReleaseMutex(p_device_context->
lock);
1939#elif __linux__ || __APPLE__
1940 lockf(p_device_context->
lock, F_ULOCK, 0);
1970 return p_device_context;
1989 (void) p_device_context;
1994 if (!p_device_context)
2001 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
2004 __func__, p_device_context->
lock);
2006#elif __linux__ || __APPLE__
2007 lockf(p_device_context->
lock, F_LOCK, 0);
2012 ni_log(
NI_LOG_INFO,
"Warning: releasing resource load %lu > current load %lu\n", load,
2020#if __linux__ || __APPLE__
2026 "p_device_info: %s\n", __func__, errmsg);
2032 ReleaseMutex(p_device_context->
lock);
2033#elif __linux__ || __APPLE__
2034 lockf(p_device_context->
lock, F_ULOCK, 0);
2055 bool b_release_pool_mtx =
false;
2074 session_ctx.
hw_id = guid;
2113 if (WAIT_ABANDONED ==
2114 WaitForSingleObject(p_device_pool->
lock,
2118 "ERROR: ni_rsrc_list_devices() failed to obtain mutex: %p\n",
2119 p_device_pool->
lock);
2124 lockf(p_device_pool->
lock, F_LOCK, 0);
2126 b_release_pool_mtx =
true;
2143 if (NI_INVALID_EVENT_HANDLE == session_ctx.
event_handle)
2154 "guid %d. %s is not avaiable, type: %d, retval:%d\n",
2156 device_type, retval);
2176 "vpu recovery happened on guid %d. %s, retry "
2187 "session open error guid %d. %s, type: %d, "
2190 device_type, retval);
2200 "Error get device resource: guid %d, device_ctx %p\n", guid,
2207 if (b_release_pool_mtx)
2210 ReleaseMutex(p_device_pool->
lock);
2212 lockf(p_device_pool->
lock, F_ULOCK, 0);
2237#if __linux__ || __APPLE__
2243 unsigned int guid_index_i, guid_index_j, ui_device_type;
2268 rValue = WaitForSingleObject(p_device_pool->
lock, INFINITE);
2269 if (rValue != WAIT_OBJECT_0)
2272 "ERROR: %s() Failed to obtain mutex %p\n",
2274 p_device_pool->
lock);
2278#elif __linux__ || __APPLE__
2279 lockf(p_device_pool->
lock, F_LOCK, 0);
2289 guid = p_device_queue->
xcoders[ui_device_type][guid_index_i];
2296 if (!p_device_context)
2299 "ERROR: %s() Failed to obtain device context for "
2300 "%s with GUID %u! Undefined behavior!\n",
2315 "ERROR: %s() Devicename format mismatch %s %s\n",
2323 CloseHandle(p_device_context->
lock);
2324#elif __linux__ || __APPLE__
2328 "%s %s %s deleted\n",
2337 "ERROR: %s(): %s %s %s failed to delete %s\n",
2349#if __linux__ || __APPLE__
2351 if (!unlink(lck_name))
2354 "%s %s %s deleted\n",
2363 "ERROR: %s(): %s %s %s failed to delete %s\n",
2378 p_device_queue->
xcoders[ui_device_type][guid_index_i] = -1;
2379 p_device_queue->
xcoder_cnt[ui_device_type]--;
2390 memset(guids, -1,
sizeof(guids));
2394 guid = p_device_queue->
xcoders[ui_device_type][guid_index_i];
2397 guids[guid_index_j] = guid;
2399 if (guid_index_j == p_device_queue->
xcoder_cnt[ui_device_type])
2405 memcpy(p_device_queue->
xcoders[ui_device_type], guids,
sizeof(guids));
2408#if __linux__ || __APPLE__
2410 if (!msync((
void *)p_device_queue,
2412 MS_SYNC|MS_INVALIDATE))
2420 "ERROR: %s(): msync() failed to delete %s: %s\n",
2430 ReleaseMutex(p_device_pool->
lock);
2431#elif __linux__ || __APPLE__
2432 lockf(p_device_pool->
lock, F_ULOCK, 0);
2438 return return_value;
2453 int xcoder_dev_count = 0;
2481 xcoder_dev_names[i]);
2487 "%d devices retrieved from current pool at start up\n",
2491 "%d devices retrieved from current pool at start up\n",
2502 for (i = 0; i < xcoder_dev_count; i++)
2505 xcoder_dev_names[i]);
2510 xcoder_dev_names[i]);
2514 xcoder_dev_names[i]);
2518#if __linux__ || __APPLE__
2530 if (0 == unlink(XCODERS_RETRY_LCK_NAME[i]))
2533 i, XCODERS_RETRY_LCK_NAME[i]);
2538 i, XCODERS_RETRY_LCK_NAME[i]);
2570 uint32_t i, existing_number_of_devices;
2591 if (WAIT_ABANDONED == WaitForSingleObject(device_pool->
lock, INFINITE))
2594 "ERROR: %s(): Failed to obtain lock %p\n",
2599#elif __linux__ || __APPLE__
2600 lockf(device_pool->
lock, F_LOCK, 0);
2607 existing_number_of_devices = device_queue->
xcoder_cnt[device_type];
2612 "ERROR: %s(): Limit of NI_MAX_DEVICE_CNT(%d) existing Quadra "
2613 "devices previously reached. Not adding %s.\n",
2621 for (i = 0; i < existing_number_of_devices; i++)
2625 device_queue->
xcoders[device_type][i]);
2632 "ERROR: %s(): %s already exists in resource pool\n",
2651 ReleaseMutex(device_pool->
lock);
2652#elif __linux__ || __APPLE__
2653 lockf(device_pool->
lock, F_ULOCK, 0);
2670 if (NI_INVALID_LOCK_HANDLE != p_device_pool->
lock)
2673 CloseHandle(p_device_pool->
lock);
2674#elif __linux__ || __APPLE__
2675 close(p_device_pool->
lock);
2685 free(p_device_pool);
2704 *lock = CreateMutex(NULL, FALSE, XCODERS_RETRY_LCK_NAME[device_type]);
2710 __func__, XCODERS_RETRY_LCK_NAME[device_type],
2719 open(XCODERS_RETRY_LCK_NAME[device_type], O_RDWR | O_CLOEXEC);
2741 DWORD ret = WaitForSingleObject(*lock, 1);
2742 if (WAIT_OBJECT_0 == ret)
2745 }
else if (WAIT_TIMEOUT != ret)
2752 status = lockf(*lock, F_LOCK, 0);
2769 while (status != 0);
2784 if (lock == NI_INVALID_LOCK_HANDLE)
2790 ni_lock_handle_t status = NI_INVALID_LOCK_HANDLE;
2798 if (ReleaseMutex(lock))
2800 status = (ni_lock_handle_t)(0);
2803 status = lockf(lock, F_ULOCK, 0);
2816 }
while (status != (ni_lock_handle_t)(0));
2860 char cmd[128] = {0};
2861 char cmd_ret[64] = {0};
2867 ptr = device_name + 5;
2868 snprintf(cmd,
sizeof(cmd) - 1,
"cat /sys/block/%s/device/*/numa_node",ptr);
2869 cmd_fp = popen(cmd,
"r");
2874 if (fgets(cmd_ret,
sizeof(cmd_ret)/
sizeof(cmd_ret[0]), cmd_fp) == 0)
2876 goto get_numa_node_ret;
2878 ret =
atoi(cmd_ret);
2886static int int_cmp(
const void *a,
const void *b)
2888 const int *ia = (
const int *)a;
2889 const int *ib = (
const int *)b;
2890 return (*ia == *ib) ? 0 : ((*ia > *ib) ? 1 : -1);
2894static int ni_hw_device_info_quadra_threshold_param_t_compare(
const void *pl,
const void *pr)
2917 int factor_8_10 = 1;
2918 uint32_t resolution = decoder_param->
h * decoder_param->
w;
2923 return resolution >= 1920*1080 ?
2924 (int)(((uint64_t)(resolution)*(uint64_t)(decoder_param->
fps)*(uint64_t)(factor_8_10)*100)/1440/1920/1080) :
2925 (int)((uint64_t)(resolution)*(uint64_t)(decoder_param->fps)*(uint64_t)(factor_8_10)*100/2880/1280/720);
2939 double factor = 1.0;
2940 double factor_codec = 1.0;
2941 double factor_rdoq = 1.0;
2942 double factor_rdoLevel = 1.0;
2943 double factor_lookahead = 1.0;
2944 double factor_8_10_bit = 1.0;
2945 double factor_720p = 1.0;
2947 int resolution = (int)(encoder_param->
w * encoder_param->
h);
2952 factor_codec = 0.67;
2964 factor_rdoLevel = (encoder_param->
rdoLevel == 2) ? 1.91 : 3.28;
2969 factor_lookahead = (double)(encoder_param->
lookaheadDepth * 0.0014 + 1.012);
2975 factor_8_10_bit = 2;
2978 factor_720p = 1.125;
2979 factor = factor_codec * factor_8_10_bit * factor_rdoq * factor_rdoLevel
2980 * factor_lookahead * factor_720p;
2986 ((uint32_t)((uint32_t)factor*encoder_param->
fps * resolution)) /
2987 ((3840 * 2160 * 60ULL) / 100 * 4));
3002static int check_hw_info_shared_mem_calculate_b_scale(
int h,
int w,
int bit_8_10,
int rgba)
3004 const int stride = 128;
3005 int estimated_yuv_size = rgba ?
3008 ( ((w + stride - 1)/stride)*stride + ((w/2 + stride - 1)/stride)*stride ) * h:
3009 ( ((w * 2 + stride - 1)/stride)*stride + ((w + stride - 1)/stride)*stride ) * h;
3010 const int b_unit = 1601536;
3011 int b_scale = (estimated_yuv_size + b_unit -1) / b_unit;
3043 const int v32_ofCores_calculate = 0;
3045 int b_counts = (int)(v32_ofCores_calculate +
3048 (encoder_param->uploader ? 1 : 0) * 3 +
3050 int b_scale = check_hw_info_shared_mem_calculate_b_scale(encoder_param->
h, encoder_param->
w,
3052 return b_scale * b_counts;
3076 const int hw_frame = decoder_param->
hw_frame;
3078 const int v30_xlsx = 0;
3079 int b_counts = 1 * (v30_xlsx +
3080 (hw_frame ? 0 : 1)*3 +
3082 int b_scale = check_hw_info_shared_mem_calculate_b_scale(decoder_param->
h, decoder_param->
w,
3084 return b_scale * b_counts;
3111 const int v30_xlsx = 0;
3112 int b_counts = 1 * (v30_xlsx +
3115 int b_scale = check_hw_info_shared_mem_calculate_b_scale(scaler_param->
h, scaler_param->
w,
3117 return b_scale * b_counts;
3135 const int total = 2456;
3136 int task_mem_usage = 0;
3137 int task_mem_precentage = 0;
3143 for(i = 0; i < card_num; ++i)
3152 task_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16);
3156 task_mem_usage = check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param);
3160 task_mem_usage = check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3164 int decoder_shared_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16);
3165 int encoder_shared_mem_usage = check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param);
3166 int scaler_shared_mem_usage = check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3167 task_mem_usage = decoder_shared_mem_usage + ((encoder_shared_mem_usage > scaler_shared_mem_usage) ?
3168 encoder_shared_mem_usage : scaler_shared_mem_usage);
3173 task_mem_usage = check_hw_info_decoder_shared_mem_usage(coder_param->
decoder_param,16) +
3174 check_hw_info_encoder_shared_mem_usage(coder_param->
encoder_param)+
3175 check_hw_info_scaler_shared_mem_usage(coder_param->
scaler_param,16);
3178 task_mem_precentage = 100 * task_mem_usage / total;
3180 if(task_mem_precentage > 90)
3183 task_mem_precentage = 90;
3186 for(i = 0;i<card_num;++i)
3188 if(card_remove[i] == 1)
3213 if(p_coder_param == NULL)
3215 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_coder_param\n");
3216 return p_coder_param;
3225 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_decoder_param\n");
3226 free(p_coder_param);
3227 p_coder_param = NULL;
3228 return p_coder_param;
3236 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_encoder_param\n");
3237 free(p_coder_param);
3238 p_coder_param = NULL;
3239 return p_coder_param;
3247 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_scaler_param\n");
3248 free(p_coder_param);
3249 p_coder_param = NULL;
3250 return p_coder_param;
3256 if(p_coder_param->
ai_param == NULL)
3258 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_ai_param\n");
3259 free(p_coder_param);
3260 p_coder_param = NULL;
3261 return p_coder_param;
3269 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_encoder_param\n");
3270 free(p_coder_param);
3271 p_coder_param = NULL;
3272 return p_coder_param;
3277 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_decoder_param\n");
3280 free(p_coder_param);
3281 p_coder_param = NULL;
3282 return p_coder_param;
3287 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_scaler_param\n");
3292 free(p_coder_param);
3293 p_coder_param = NULL;
3294 return p_coder_param;
3297 if(p_coder_param->
ai_param == NULL)
3299 ni_log(
NI_LOG_ERROR,
"Error: Failed to allocate memory for hw_device_info_quadra_ai_param\n");
3306 free(p_coder_param);
3307 p_coder_param = NULL;
3308 return p_coder_param;
3348 return p_coder_param;
3364 if(p_hw_device_info_quadra_coder_param == NULL)
3380 free(p_hw_device_info_quadra_coder_param->
scaler_param);
3381 p_hw_device_info_quadra_coder_param->
scaler_param = NULL;
3383 if(p_hw_device_info_quadra_coder_param->
ai_param)
3385 free(p_hw_device_info_quadra_coder_param->
ai_param);
3386 p_hw_device_info_quadra_coder_param->
ai_param = NULL;
3388 free(p_hw_device_info_quadra_coder_param);
3405 if(!p_hw_device_info)
3407 ni_log(
NI_LOG_ERROR,
"ERROR: Failed to allocate memory for p_hw_device_info_quadra_t\n");
3408 goto p_hw_device_info_end;
3415 ni_log(
NI_LOG_ERROR,
"ERROR: Failed to allocate memory for p_hw_device_info_quadra_t->device_type\n");
3416 goto device_type_end;
3434 if(p_hw_device_info->
card_info[i] == NULL)
3437 goto card_info_i_end;
3441 return p_hw_device_info;
3458 free(p_hw_device_info);
3459 p_hw_device_info = NULL;
3460p_hw_device_info_end:
3475 if(!p_hw_device_info)
3488 free(p_hw_device_info);
3505 int should_match_rev = 1;
3506 int module_count = 1;
3508 int32_t *module_id_arr = NULL;
3514 int *card_remove = NULL;
3517 uint64_t decoder_need_load = 0;
3518 uint64_t encoder_need_load = 0;
3521 int hw_info_param_num = hw_mode ? 4 : 1;
3522 int device_type_num = 1;
3523 const int all_device_type_num = 4;
3531 bool b_valid =
false;
3539 if(!pointer_to_p_hw_device_info)
3541 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: pointer_to_p_hw_device_info is NULL.\n");
3545 if(*pointer_to_p_hw_device_info)
3547 p_hw_device_info = *pointer_to_p_hw_device_info;
3559 }
else if(hw_mode && hw_mode != coder_param->
hw_mode)
3561 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: hw_mode = %d, coder_param->hw_mode = %d\n",
3562 hw_mode,coder_param->
hw_mode);
3568 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_ENCODER but coder_param->encoder_param == NULL\n");
3573 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_DECODER but coder_param->decoder_param == NULL\n");
3578 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_SCALER but coder_param->scaler_param == NULL\n");
3583 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: preferential_device_type == NI_DEVICE_TYPE_AI but coder_param->ai_param == NULL\n");
3589 if((task_mode != 0 && task_mode != 1) ||
3598 task_mode, preferential_device_type);
3602 if(!hw_info_threshold_param)
3608 ni_log(
NI_LOG_ERROR,
"Error: Invalid input params: hw_info_threshold_param is NULL.\n");
3611 for(i = 0;i < hw_info_param_num; ++i)
3613 if(hw_info_threshold_param[i].load_threshold < 0||
3614 hw_info_threshold_param[i].load_threshold > 100 ||
3615 hw_info_threshold_param[i].task_num_threshold < 0 ||
3626 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",
3627 (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);
3682 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
3687#elif defined(__linux__)
3688 if (lockf(p_device_pool->
lock, F_LOCK, 0))
3714 for(i = 0; i < all_device_type_num; ++i)
3716 if(all_need_device_type[i] == preferential_device_type)
3719 all_need_device_type[i] = all_need_device_type[0];
3720 all_need_device_type[0] = tmp;
3725 qsort(&all_need_device_type[1], all_device_type_num - 1,
sizeof(
ni_device_type_t), int_cmp);
3731 device_type_num = 4;
3733 for(i = 0; i < device_type_num; ++i)
3735 if(hw_info_threshold_param[i].device_type == preferential_device_type)
3738 hw_info_threshold_param[i] = hw_info_threshold_param[0];
3739 hw_info_threshold_param[0] = tmp;
3743 qsort(&hw_info_threshold_param[1], device_type_num - 1,
3747 if(!(*pointer_to_p_hw_device_info))
3750 if(!p_hw_device_info)
3755 *pointer_to_p_hw_device_info = p_hw_device_info;
3766 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->device_type is NULL\n");
3772 ni_log(
NI_LOG_ERROR,
"ERROR: pointer_to_p_hw_device_info is not a pointer to NULL, but ->card_info is NULL\n");
3776 for(i = 0; i < device_type_num; ++i)
3780 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);
3794 p_hw_device_info->
device_type[i] = all_need_device_type[i];
3832 card_remove = (int32_t *)malloc(
sizeof(int32_t) * p_hw_device_info->
available_card_num);
3842 module_count = coders->
xcoder_cnt[preferential_device_type];
3850 module_id_arr = (int32_t *)malloc(
sizeof(int32_t) * module_count);
3859 memcpy(module_id_arr, coders->
xcoders[preferential_device_type],
sizeof(int32_t) * module_count);
3863 qsort(module_id_arr, module_count,
sizeof(int32_t), int_cmp);
3869 memset(&xCtxt, 0,
sizeof(xCtxt));
3871 if (p_device_context)
3905 for(
int j = 0; j < device_type_num; ++j)
3909 if(p_device_context)
3955 p_device_context = NULL;
3976 decoder_need_load = check_hw_info_decoder_need_load(coder_param->
decoder_param);
3980 encoder_need_load = check_hw_info_encoder_need_load(coder_param->
encoder_param);
3995 ni_log(
NI_LOG_DEBUG,
"%s Card[%3d], load: %3d, task_num: %3d, firmware_load: %3d, model_load: %3d, shared_mem_usage: %3d\n",
3997 ni_log(
NI_LOG_INFO,
"%s Card[%3d], load: %3d, task_num: %3d, firmware_load: %3d, model_load: %3d, shared_mem_usage: %3d\n",
4009 if(card_remove[i] == 1)
4064 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,10);
4066 else if(preferential_device_type == 0)
4068 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,0);
4070 else if(preferential_device_type == 1)
4072 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,1);
4074 else if(preferential_device_type == 2)
4076 check_hw_info_remove_card_with_memory(card_remove,p_hw_device_info,p_hw_device_info->
available_card_num,coder_param,2);
4088 card_remove[i] == 0)
4098 card_remove[i] == 0 &&
4114 card_remove[i] == 0)
4129 ReleaseMutex((HANDLE)p_device_pool->
lock);
4131#elif defined(__linux__)
4132 if (lockf(p_device_pool->
lock, F_ULOCK,0))
4135 if(p_hw_device_info)
4142 p_device_context = NULL;
4147 free(module_id_arr);
4148 module_id_arr = NULL;
4153 dev_ctxt_arr = NULL;
4174 ni_log(
NI_LOG_DEBUG,
"In sw_mode select device_type %s card_current_card %d retval %d\n",
4176 ni_log(
NI_LOG_INFO,
"In sw_mode select device_type %s card_current_card %d retval %d\n",
4178 ((preferential_device_type == 0) ?
"decode" : (preferential_device_type == 1 ?
"encode" : (preferential_device_type == 2 ?
"scaler" :
"ai "))), p_hw_device_info->
card_current_card, retval);
4210 int width,
int height,
4222 uint32_t num_sw_instances = 0;
4223 int least_model_load = 0;
4224 uint64_t job_mload = 0;
4244 if (WAIT_ABANDONED == WaitForSingleObject(p_device_pool->
lock, INFINITE))
4248#elif __linux__ || __APPLE__
4249 lockf(p_device_pool->
lock, F_LOCK, 0);
4255 for (i = 0; i < count; i++)
4259 if (!p_device_context)
4262 "ERROR: %s() ni_rsrc_get_device_context() failed\n", __func__);
4271 if (NI_INVALID_DEVICE_HANDLE == p_session_context.
device_handle)
4290 g_device_type_str[device_type],
4298 if (WAIT_ABANDONED == WaitForSingleObject(p_device_context->
lock, INFINITE))
4301 __func__, p_device_context->
lock);
4303#elif __linux__ || __APPLE__
4304 lockf(p_device_context->
lock, F_LOCK, 0);
4312 load = p_device_info->
load;
4313 least_model_load = p_device_info->
model_load;
4317 ni_log(
NI_LOG_INFO,
"Coder [%d]: %d , load: %d (%d), activ_inst: %d , max_inst %d\n",
4338 if (p_device_info->
model_load < least_model_load)
4341 least_model_load = p_device_info->
model_load;
4344 else if (p_device_info->
load < load)
4347 load = p_device_info->
load;
4354 ReleaseMutex(p_device_context->
lock);
4355#elif __linux__ || __APPLE__
4356 lockf(p_device_context->
lock, F_ULOCK, 0);
4364 if (!p_device_context)
4367 "ERROR: %s() ni_rsrc_get_device_context() failed\n", __func__);
4373 job_mload = width * height * frame_rate;
4379 p_device_context = NULL;
4384 ReleaseMutex(p_device_pool->
lock);
4385#elif __linux__ || __APPLE__
4386 lockf(p_device_pool->
lock, F_ULOCK, 0);
4393 *p_load = job_mload;
4395 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)
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_retcode_t ni_device_session_context_init(ni_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
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.
void ni_device_session_context_clear(ni_session_context_t *p_ctx)
Clear already allocated session context.
#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