31 #elif __linux__ || __APPLE__
33 #include <linux/types.h>
35 #include <sys/prctl.h>
38 #include <sys/ioctl.h>
42 #include <sys/types.h>
47 #include <semaphore.h>
52 #include <sys/syscall.h>
53 #include <sys/resource.h>
54 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
77 #if defined(__linux__) && defined(XCODER_ENABLE_CPU_AFFINITY)
86 static const int g_map_preset_to_gopsize[2][18] = {{8, 0, 1, -1, 1, 2, 4, -1, 4, 8, 1, 4, -1, -1, -1, -1, 16},
87 {8, 0, -1, -1, -1, 2, 4, -1, -1, 8, 1, -1, -1, -1, -1, -1, -1}};
88 #define MAGIC_P2P_VALUE "p2p"
89 #define AI_MODEL_TYPE_HVSPLUS_FILTER 3
126 0x00, 0x00, 0x00, 0x01,
144 0x00, 0x00, 0x00, 0x01,
160 0x00, 0x00, 0x00, 0x01,
176 0x00, 0x00, 0x00, 0x01,
194 #define NI_XCODER_FAILURES_MAX 25
195 #define DP_IPC_PASSTHRU 0xFFFFFFFF
198 #ifdef XCODER_SELF_KILL_ERR
199 #undef XCODER_SELF_KILL_ERR
206 for (i = 0; i < bytes; i += 2)
208 uint8_t val = buf[i];
216 uint32_t i, words = (bytes + 1) / 2;
218 for (i = 0; i < words; i += 2)
220 uint16_t val = buf[i];
228 uint32_t i, words = (bytes + 3) / 4;
229 for (i = 0; i < words; i += 2)
231 uint32_t val = buf[i];
239 uint64_t i, words = (bytes + 7) / 8;
240 for (i = 0; i < words; i += 2)
242 uint64_t val = buf[i];
248 static void memcpyToPelByBits (uint8_t *dst_u8, uint8_t *src,
int width,
int height,
int dst_stride,
int src_stride,
int srcValidBitsDepth)
251 uint8_t bitsDepth = srcValidBitsDepth;
252 uint32_t mask = (1<<bitsDepth)-1;
253 uint16_t *dst = (uint16_t *)dst_u8;
258 for (j = 0; j < height; j ++)
260 for (i = 0; i< width; i ++)
261 dst_u8[i] = src[i] & 0xff;
264 dst_u8 += dst_stride;
270 for (j = 0; j < height; j ++)
272 uint8_t *src_line = src;
273 uint32_t cache = 0, cache_bits = 0;
274 for (i = 0; i< width; i ++)
276 while(cache_bits < bitsDepth)
278 cache |= ((*src_line++) << cache_bits);
282 if (cache_bits >= bitsDepth)
284 dst[i] = cache & mask;
286 cache_bits -= bitsDepth;
311 static void trace_recon_tile2raster_y(FILE *fRecon, uint8_t *mem,
int width,
int height,
312 int leftOffset,
int topOffset,
313 int src_stride,
int pixDepth, uint8_t *luma_mem_temp)
316 int write_data_len = 0;
317 int bytesPerPix = (pixDepth == 8 ? 1 : 2);
318 uint8_t *tmp_mem = (uint8_t *)malloc(bytesPerPix*src_stride);
319 int num_tiles = (leftOffset + width + 3) / 4 - leftOffset/4;
322 mem += topOffset/4*4*src_stride + leftOffset/4*16*pixDepth/8;
323 for(i = topOffset/4*4; i < topOffset + height; i += 4) {
324 memcpyToPelByBits(tmp_mem, mem, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
325 if(i >= topOffset && i < topOffset + height){
327 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
328 write_data_len += width * bytesPerPix;
330 memcpyToPelByBits(tmp_mem, mem+4*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
331 if(i+1 >= topOffset && i+1 < topOffset + height)
334 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
335 write_data_len += width * bytesPerPix;
337 memcpyToPelByBits(tmp_mem, mem+8*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
338 if(i+2 >= topOffset && i+2 < topOffset + height)
341 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
342 write_data_len += width * bytesPerPix;
344 memcpyToPelByBits(tmp_mem, mem+12*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
345 if(i+3 >= topOffset && i+3 < topOffset + height)
348 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
349 write_data_len += width * bytesPerPix;
356 static void trace_recon_tile2raster_uv(FILE *fRecon, uint8_t *mem_uv,
int width,
int height,
357 int leftOffset,
int topOffset,
358 int src_stride,
int pixDepth, uint8_t *ch_mem_temp)
361 int bytesPerPix = (pixDepth == 8 ? 1 : 2);
362 uint8_t *tmp_mem = (uint8_t *)malloc(bytesPerPix*src_stride*2);
363 int num_tiles = 2*((leftOffset + width + 3) / 4 - leftOffset/4);
368 int write_data_len = 0;
369 memset(tmp_mem, 0x00, bytesPerPix * src_stride * 2);
370 for(uv = 0; uv <= 1; uv ++) {
371 mem = mem_uv + topOffset/4*8*src_stride + leftOffset/4*32*pixDepth/8;
372 for(i = topOffset/4*4; i < topOffset + height; i += 4) {
373 if(i >= topOffset && i < topOffset + height) {
374 memcpyToPelByBits(tmp_mem, mem, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
375 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
377 tmp_mem[k] = tmp_mem[j];
379 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
382 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
383 write_data_len += width * bytesPerPix;
385 if(i+1 >= topOffset && i+1 < topOffset + height) {
386 memcpyToPelByBits(tmp_mem, mem+4*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
387 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
389 tmp_mem[k] = tmp_mem[j];
391 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
394 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
395 write_data_len += width * bytesPerPix;
397 if(i+2 >= topOffset && i+2 < topOffset + height) {
398 memcpyToPelByBits(tmp_mem, mem+8*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
399 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
401 tmp_mem[k] = tmp_mem[j];
403 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
406 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
407 write_data_len += width * bytesPerPix;
409 memcpyToPelByBits(tmp_mem, mem+12*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
410 if(i+3 >= topOffset && i+3 < topOffset + height) {
411 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
413 tmp_mem[k] = tmp_mem[j];
415 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
418 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
419 write_data_len += width * bytesPerPix;
427 static double calc_noise(uint8_t *p1, uint8_t *p2,
int size)
434 for (i = 0; i < size; i++)
436 diff = p1[i] - p2[i];
481 FILE *fout_raster = NULL;
499 uint8_t *luma_mem_temp = NULL;
500 uint8_t *ch_mem_temp = NULL;
513 luma_mem_temp = (uint8_t *)malloc(luma_size);
514 memset(luma_mem_temp, 0x00, luma_size);
519 ch_mem_temp = (uint8_t *)malloc(ch_size);
520 memset(ch_mem_temp, 0x00, ch_size);
528 SwapSW16((uint16_t *)luma_mem, lum_sz);
529 SwapSW32((uint32_t *)luma_mem, lum_sz);
530 SwapSW64((uint64_t *)luma_mem, lum_sz);
531 trace_recon_tile2raster_y (fout_raster, luma_mem, width, height,
542 SwapSW16((uint16_t *)ch_mem, chr_sz);
543 SwapSW32((uint32_t *)ch_mem, chr_sz);
544 SwapSW64((uint64_t *)ch_mem, chr_sz);
545 trace_recon_tile2raster_uv(fout_raster, ch_mem, width / 2, height / 2,
564 double noise_y = 0.0, noise_u = 0.0, noise_v = 0.0, noise_yuv = 0.0;
565 double power_y = 0.0, power_u = 0.0, power_v = 0.0, power_yuv = 0.0;
566 double psnr_y = 0.0, psnr_u = 0.0, psnr_v = 0.0, psnr_yuv = 0.0;
576 power_y = 1.0 * max * max * width * height;
577 power_u = power_y / 4.0;
578 power_v = power_y / 4.0;
579 power_yuv = power_y * 3.0 / 2.0;
581 uint8_t *p_y_src_buf = NULL;
582 uint8_t *p_u_src_buf = NULL;
583 uint8_t *p_v_src_buf = NULL;
584 for (
int i = 0; i < 120; i++)
599 if (p_y_src_buf != NULL)
603 noise_y = calc_noise(p_y_src_buf, luma_mem_temp, width * height);
607 noise_y = power_y / pow(10, p_ctx->
psnr_y / 10);
612 noise_u = calc_noise(p_u_src_buf, ch_mem_temp, (width / 2) * (height / 2));
613 noise_v = calc_noise(p_v_src_buf, ch_mem_temp + (width / 2) * (height / 2), (width / 2) * (height / 2));
615 noise_yuv = noise_y + noise_u + noise_v;
619 noise_y = noise_y < 1 ? 1 : noise_y;
620 noise_u = noise_u < 1 ? 1 : noise_u;
621 noise_v = noise_v < 1 ? 1 : noise_v;
622 noise_yuv = noise_yuv < 1 ? 1 : noise_yuv;
626 psnr_y = 10 * log10(power_y / noise_y);
635 psnr_u = 10 * log10(power_u / noise_u);
636 psnr_v = 10 * log10(power_v / noise_v);
638 psnr_yuv = 10 * log10(power_yuv / noise_yuv);
666 luma_mem_temp = NULL;
692 ni_log2(p_ctx,
NI_LOG_DEBUG,
"pkt_num %d psnr_y %.4f psnr_u %.4f psnr_v %.4f psnr_yuv %.4f reconLumaWidth %d width %d height %d reconLumaSize 0x%x reconChromaSize 0x%x\n",
698 #if 0 // CU info parsing (currently not used)
703 if (!p_ctx || !cuInfoBuf || !pEncCuInfo)
715 if (pEncCuInfo->
cuMode == 1)
730 pEncCuInfo->
cuSize = 8 * (1 << cuSizeId);
732 if (pEncCuInfo->
cuMode == 1)
750 uint16_t ui16ErrorCount = 0;
751 uint32_t ui32LastErrorStatus = 0;
773 else if(opt ==
OPT_2){
783 ui16ErrorCount > 0 && !retval &&
789 else if(opt ==
OPT_3)
798 "Persistent failures detected, %s() line-%d: session_no 0x%x "
799 "sess_err_count %u inst_err_no %u\n",
800 func, line, *(inst_id), ui16ErrorCount,
801 ui32LastErrorStatus);
802 #ifdef XCODER_SELF_KILL_ERR
805 kill(getpid(), SIGTERM);
817 #define CHECK_ERR_RC(ctx, rc, info, opcode, type, hw_id, inst_id, opt) \
819 (rc) = check_err_rc(ctx, rc, info, opcode, type, hw_id, inst_id, opt, __func__, __LINE__); \
820 if((rc) && ((opt) != OPT_3)) LRETURN; \
823 #define CHECK_VPU_RECOVERY(ret) \
825 if (NI_RETCODE_NVME_SC_VPU_RECOVERY == (ret)) \
827 ni_log(NI_LOG_ERROR, "Error, vpu reset.\n"); \
828 (ret) = NI_RETCODE_ERROR_VPU_RECOVERY; \
838 "decoder" :
"encoder";
842 uint64_t abs_time_ns;
849 ts.tv_sec = abs_time_ns / 1000000000LL;
850 ts.tv_nsec = abs_time_ns % 1000000000LL;
860 if (ret == ETIMEDOUT)
872 "decoder" :
"encoder";
902 #elif __linux__ || __APPLE__
904 char dir_name[128] = {0};
905 char file_name[512] = {0};
908 struct dirent *stream_folder;
909 int curr_stream_idx = 0;
910 int earliest_stream_idx = 0;
911 int max_exist_idx = 0;
912 time_t earliest_time = 0;
913 struct stat file_stat;
917 if (!p_device_context)
924 flock(p_device_context->lock, LOCK_EX);
927 if (0 != access(dir_name, F_OK))
929 if (0 != mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO))
939 if (NULL == (dir = opendir(dir_name)))
948 while ((stream_folder = readdir(dir)))
950 if (!strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
953 atoi(&(stream_folder->d_name[strlen(
"stream")]));
954 if (curr_stream_idx > 0)
956 if (curr_stream_idx > max_exist_idx)
958 max_exist_idx = curr_stream_idx;
973 curr_stream_idx = max_exist_idx + 1;
977 while ((stream_folder = readdir(dir)))
981 if (!strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
983 snprintf(file_name,
sizeof(file_name),
"%s/%s/pkt-0001.bin",
984 dir_name, stream_folder->d_name);
987 atoi(&(stream_folder->d_name[strlen(
"stream")]));
989 if (curr_stream_idx > 0 && 0 == access(file_name, F_OK))
992 if (stat(file_name, &file_stat))
999 if (0 == earliest_stream_idx ||
1000 file_stat.st_mtime < earliest_time)
1002 earliest_stream_idx = curr_stream_idx;
1003 earliest_time = file_stat.st_mtime;
1010 curr_stream_idx = earliest_stream_idx;
1014 snprintf(file_name,
sizeof(file_name),
"%s/stream%03d/pkt-0001.bin",
1015 dir_name, curr_stream_idx);
1016 if (utime(file_name, NULL))
1025 "%s/stream%03d", dir_name, curr_stream_idx);
1044 flock(p_device_context->lock, LOCK_UN);
1047 snprintf(file_name,
sizeof(file_name),
"%s/process_session_id.txt",
1053 char number[64] = {
'\0'};
1055 snprintf(number,
sizeof(number),
"proc id: %ld\nsession id: %u\n",
1057 fwrite(number, strlen(number), 1, fp);
1066 #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OPEN_HARMONY__) && !defined(_ANDROID)
1067 #define MAX_BDF_LEN 16
1071 static int find_pci_address(
const char *dev_name,
char *pci_addr) {
1072 char sys_block_path[256];
1074 snprintf(sys_block_path,
sizeof(sys_block_path),
"/sys/class/block/%s/device", dev_name);
1076 char *real_sysfs_path = realpath(sys_block_path, NULL);
1077 if (!real_sysfs_path) {
1078 perror(
"realpath failed");
1083 char *p = real_sysfs_path + strlen(real_sysfs_path);
1085 while (p > real_sysfs_path) {
1086 p = strrchr(real_sysfs_path,
'/');
1093 unsigned domain, bus, dev, func;
1094 if (sscanf(segment,
"%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) {
1097 free(real_sysfs_path);
1104 free(real_sysfs_path);
1111 #if defined(_WIN32) || defined(__APPLE__) || defined(__OPEN_HARMONY__)
1119 char *dom, *bus, *dev, *fnc;
1131 p_ctx->
netint_fd = open(
"/dev/netint", O_RDWR);
1139 if (stat(p_dev, &bstat) < 0)
1145 if ((bstat.st_mode & S_IFMT) != S_IFBLK)
1152 ret = snprintf(syspath,
sizeof(syspath) - 1,
1153 "/sys/block/%s/device/address",
1155 syspath[ret] =
'\0';
1165 if (fgets(pci_addr,
sizeof(pci_addr), fp) == NULL)
1174 ret = find_pci_address(p_dev + 5, pci_addr);
1185 p_ctx->
domain = strtoul(pci_addr, &dom, 16);
1193 p_ctx->
bus = strtoul(dom + 1, &bus, 16);
1201 p_ctx->
dev = strtoul(bus + 1, &dev, 16);
1210 p_ctx->
fn = strtoul(dev + 1, &fnc, 16);
1226 #if __linux__ || __APPLE__
1227 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
1228 #ifndef DISABLE_BACKTRACE_PRINT
1229 void ni_print_backtrace() {
1230 void* callstack[128];
1231 int frames = backtrace(callstack, 128);
1232 char** strs = backtrace_symbols(callstack, frames);
1235 for (
int i = 0; i < frames; ++i) {
1256 void* p_buffer = NULL;
1257 uint32_t ui32LBA = 0;
1258 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
1278 #if defined(__linux__) && defined(XCODER_ENABLE_CPU_AFFINITY)
1287 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): not support enableCpuAffinity parameter, "
1288 "enable with [./build.sh -c] on linux\n", __func__);
1325 "ERROR %d: %s() alloc decoder all zero buffer failed\n",
1366 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1375 uint64_t keep_alive_timeout =
1378 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
1380 keep_alive_timeout);
1391 "ERROR %s(): nvme write keep_alive_timeout command "
1392 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1408 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
1419 "ERROR %s(): nvme write sw_version command "
1420 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1443 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1451 "%s(): p_ctx->device_handle=0x%" PRIx64
", p_ctx->hw_id=%d, "
1452 "p_ctx->session_id=%d\n",
1511 ni_log2(p_ctx,
NI_LOG_INFO,
"Warn %s(): forceLowDelay is not available for fw < 6r3\n",
1522 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1523 "p_ctx->session_id=%d\n",
1529 decoder_dump_dir_open(p_ctx);
1532 #ifdef XCODER_DUMP_DATA
1533 char dir_name[256] = {0};
1535 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-dec-fme", (
long)getpid(),
1537 DIR *dir = opendir(dir_name);
1540 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
1566 uint32_t ui32LBA = 0;
1577 if (NI_INVALID_DEVICE_HANDLE == device_handle)
1590 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1596 "SUCCESS %s(): device_handle=%" PRIx64
" , "
1597 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1708 void* p_buffer = NULL;
1709 uint32_t ui32LBA = 0;
1741 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1742 "buffered: %u completed: %u output: %u dropped: %u error: %u corrupted: %u\n",
1753 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1754 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
1803 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1804 "p_ctx->session_id=%d, close_mode=1\n",
1873 low_delay_signal(p_ctx);
1890 uint32_t sent_size = 0;
1891 uint32_t packet_size = 0;
1892 int current_pkt_size;
1897 int query_retry = 0;
1898 uint32_t ui32LBA = 0;
1902 if ((!p_ctx) || (!p_packet))
1919 low_delay_wait(p_ctx);
1921 #ifdef MEASURE_LATENCY
1926 abs_time_ns, p_packet->
dts);
1932 current_pkt_size = packet_size;
1935 int max_retry = 200;
2013 "Warning: dec write query fail rc %d or available buf size %u < "
2014 "pkt size %u , retry: %d max_retry_fail_count %d\n",
2017 if (query_retry > max_retry ||
2026 if (query_retry > max_retry)
2045 "size %u >= pkt size %u !\n",
2088 "%s() had data to send: packet_size=%u, "
2089 "p_packet->sent_size=%d, p_packet->data_len=%u, "
2090 "p_packet->start_of_stream=%u, p_packet->end_of_stream=%u, "
2091 "p_packet->video_width=%u, p_packet->video_height=%u\n",
2096 uint8_t *p_data = (uint8_t *)p_packet->
p_data;
2107 p_data, packet_size, ui32LBA);
2127 char dump_file[512] = {0};
2130 snprintf(dump_file,
sizeof(dump_file),
"%s/pkt-%04ld.bin",
2137 fwrite(p_packet->
p_data, sent_size, 1, f);
2178 "%s: (first packet) pkt_index %d i %u "
2179 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2180 " pts_offsets %" PRId64
"\n",
2192 "%s: pkt_index %d i %u pkt_offsets_index_min "
2193 "%" PRIu64
" pkt_offsets_index %" PRIu64
" pts_offsets %" PRId64
2206 "%s: (wrap) pkt_index %d i %u "
2207 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2208 " pts_offsets %" PRId64
"\n",
2231 "Error %s: failed to allocate custom SEI buffer for pkt.\n",
2247 "ERROR %s(): ni_timestamp_register() for dts returned %d\n",
2257 "%s(): exit: packets: %" PRIu64
" offset %" PRIx64
""
2258 " sent_size = %u, status=%d\n",
2259 __func__, p_ctx->
pkt_num, (uint64_t)p_packet->
pos, sent_size,
2265 "ERROR %s(): exit: returnErr: %d, p_ctx->status: %d\n", __func__,
2271 static int64_t guess_correct_pts(
ni_session_context_t* p_ctx, int64_t reordered_pts, int64_t dts)
2279 "%s: pts_correction_last_dts %" PRId64
" "
2280 "pts_correction_num_faulty_dts %d\n",
2295 "%s: pts_correction_last_pts %" PRId64
" "
2296 "pts_correction_num_faulty_pts %d\n",
2309 pts = reordered_pts;
2321 pts = reordered_pts;
2329 static int rotated_array_binary_search(uint64_t *lefts, uint64_t *rights,
2330 int32_t size, uint64_t target)
2336 int mid = lo + (hi - lo) / 2;
2337 if (lefts[mid] <= target && target < rights[mid])
2342 if (rights[mid] == 0)
2349 if (rights[lo] <= rights[mid])
2351 if (lefts[lo] <= target && target < lefts[mid])
2362 if (rights[mid] <= target && target < rights[hi])
2388 uint64_t frame_offset = 0;
2389 uint32_t frame_dropped = 0;
2390 uint8_t *p_data_buffer = NULL;
2396 uint32_t total_bytes_to_read = 0;
2397 uint32_t read_size_bytes = 0;
2402 int query_retry = 0;
2403 uint32_t ui32LBA = 0;
2404 unsigned int bytes_read_so_far = 0;
2406 int low_delay_notify = 0;
2407 uint32_t frames_dropped = 0;
2408 uint8_t get_first_metadata = 0;
2409 uint8_t sequence_change = 0;
2413 if ((!p_ctx) || (!p_frame))
2431 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
2436 p_frame->
data_len[2] + metadata_hdr_size;
2487 ni_log2(p_ctx,
NI_LOG_TRACE,
"Warning: dec read query fail rc %d retry %d max_retry_fail_count %d\n",
2490 if (query_retry >= 1000)
2493 low_delay_notify = 1;
2510 total_bytes_to_read = metadata_hdr_size;
2511 sequence_change = 1;
2534 "WARNING: Dec eos reached but also exceeded max dec read query "
2535 "retries. is_flushed=%u try=%d.\n",
2540 "Dec eos reached. is_flushed=%u try=%d.\n",
2544 low_delay_notify = 1;
2550 " retrying ..\n", query_retry);
2564 query_retry < 1000 / 2)
2571 low_delay_signal(p_ctx);
2579 "size %u >= required size %u !\n",
2596 low_delay_signal(p_ctx);
2599 "Warning: ceased using low delay decoding mode after "
2600 "excessively long decoder read query.\n");
2603 low_delay_signal(p_ctx);
2613 if(query_retry <= 2000)
2622 "Warning: decoder pkt_num %u frame_num %u "
2623 "timeout, increasing pkt_delay_cnt to %u\n",
2647 "At least %d packets should be sent before reading the "
2664 "%ux%u frame-rate %u is_flushed %u\n",
2698 #ifdef XCODER_SELF_KILL_ERR
2703 kill(getpid(), SIGTERM);
2720 p_frame->
data_len[2] + metadata_hdr_size;
2721 p_data_buffer = (uint8_t*) p_frame->
p_buffer;
2733 "%u cb len %u hdr %d\n",
2736 p_frame->
data_len[2], metadata_hdr_size);
2742 "ERROR %s() avaliable size(%u)"
2743 "less than needed (%u)\n",
2755 void *p_metadata_buffer = NULL;
2761 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
2766 p_data_buffer = (uint8_t *)p_metadata_buffer;
2767 get_first_metadata = 1;
2769 sequence_change = 0;
2790 p_data_buffer, read_size_bytes, ui32LBA);
2799 }
else if (get_first_metadata) {
2807 get_first_metadata = 0;
2821 low_delay_notify = 1;
2834 total_bytes_to_read = total_bytes_to_read + sei_size;
2836 "include sei %u sei_size %d\n",
2837 retval, total_bytes_to_read, sei_size);
2840 bytes_read_so_far = total_bytes_to_read ;
2847 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset, &frame_dropped,
false);
2851 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset, 0,
false);
2867 "is cancelled due to has_b_frames, frame_num %u\n",
2878 int64_t tmp_dts, prev_dts = INT64_MIN, ts_diff = 0;
2887 "### %s(): Warning: ui32FramesDropped %u should be %u + %u\n",
2904 "%s(): First frame : session_id 0x%x, pic_reorder_delay: %d "
2905 "total frames input:%u buffered: %u completed: %u output: %u "
2906 "dropped: %u (%u %u) error: %u\n",
2926 "decoder dts queue %d %ld failed !\n",
2927 __func__, i, tmp_dts);
2932 "decoder dts queue %d %ld success !\n",
2933 __func__, i, tmp_dts);
2934 if (prev_dts != INT64_MIN) {
2935 ts_diff += llabs(tmp_dts - prev_dts);
2943 ts_diff = ts_diff / nb_diff;
2947 "average diff: %ld\n", __func__, ts_diff);
2962 "decoder dts queue %d %ld failed !\n",
2963 __func__, i, tmp_dts);
2990 for (i = 0; (int)i < p_ctx->pic_reorder_delay; i++)
2997 if (p_frame->
pts >= p_frame->
dts &&
2998 p_frame->
pts - p_frame->
dts < 1000)
3014 "decoder dts queue %d %ld success !\n",
3015 __func__, i, p_frame->
dts);
3051 "%s: (found pts) dts %" PRId64
" pts "
3052 "%" PRId64
" frame_offset %" PRIu64
" j %d "
3053 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index "
3054 "%" PRIu64
" pkt_pos %" PRIu64
" \n",
3055 __func__, p_frame->
dts, p_frame->
pts, frame_offset, j,
3070 while (p_frame->
dts < p_frame->
pts &&
3071 llabs(p_frame->
pts - p_frame->
dts) > ts_diff)
3074 "dts %lld diff. %lld > ts_diff %lld\n",
3075 __func__, p_frame->
pts, p_frame->
dts,
3076 llabs(p_frame->
pts - p_frame->
dts), ts_diff);
3083 "pop decoder dts queue error.\n", __func__);
3106 "ERROR: Frame pts %" PRId64
" not found for offset "
3107 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
3109 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
3111 __func__, p_frame->
dts, p_frame->
pts);
3123 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
3131 __func__, p_frame->
pts);
3141 #ifdef MEASURE_LATENCY
3148 #ifdef XCODER_DUMP_DATA
3149 char dump_file[256];
3150 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-dec-fme/fme-%04ld.yuv",
3164 "%s(): p_frame->start_of_stream=%u, "
3165 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
3166 "p_frame->video_height=%u\n",
3175 "Decoder pts queue size = %u dts queue size = %u\n\n",
3182 #ifdef MEASURE_LATENCY
3198 if (get_first_metadata && p_data_buffer)
3200 if (sequence_change && p_ctx->
frame_num)
3215 low_delay_signal(p_ctx);
3221 if (low_delay_notify)
3223 low_delay_signal(p_ctx);
3243 device_type, g_device_type_str[device_type]);
3266 switch (device_type)
3288 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s blk_dev %s blk_xcoder %s dev_xcoder %s current_load:%u model_load:%u fw_load:%u "
3289 "total_contexts:%u fw_video_mem_usage:%u "
3290 "fw_video_shared_mem_usage:%u fw_share_mem_usage:%u "
3291 "fw_p2p_mem_usage:%u active_hwuploaders:%u\n", __func__,
3307 "Overall load %u, model load %u, instance count %u\n",
3334 device_type, g_device_type_str[device_type]);
3365 void *p_buffer = NULL;
3367 uint32_t ui32LBA = 0;
3368 uint32_t max_cu_size;
3369 uint32_t block_size;
3370 int32_t width, height;
3371 int m_threshold = 0;
3372 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
3390 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() RGBA / BGRA / ARGB / AGBR resolution invalid, return\n",
3403 #if defined(__linux__) && defined(XCODER_ENABLE_CPU_AFFINITY)
3412 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): not support enableCpuAffinity parameter, "
3413 "enable with [./build.sh -c] on linux\n", __func__);
3426 width = (width / 8) * 8;
3427 height = (height / 8) * 8;
3431 ((width + max_cu_size - 1) & (~(max_cu_size - 1))) *
3432 ((height + max_cu_size - 1) & (~(max_cu_size - 1))) /
3434 p_ctx->
roi_len = ((block_size + 63) & (~63));
3512 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3513 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3524 uint64_t keep_alive_timeout =
3527 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
3529 keep_alive_timeout);
3540 "ERROR %s(): nvme write keep_alive_timeout command "
3541 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3557 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
3568 "ERROR %s(): nvme write sw_version command "
3569 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3614 ni_log2(p_ctx,
NI_LOG_ERROR,
"The bit depth or resoultion is not supported on ai enhance mode\n");
3628 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3629 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3666 if (m_threshold > 4 * 1024 * 1024 *
sizeof(
long))
3669 "DEFAULT_MMAP_THRESHOLD_MAX, use default value (%d)\n",
3670 m_threshold, 4 * 1024 * 1024 *
sizeof(
long));
3671 m_threshold = 4 * 1024 * 1024 *
sizeof(long);
3676 #if defined(__linux__) && !defined(_ANDROID) && !defined(__OPENHARMONY__)
3680 if (mallopt(M_MMAP_THRESHOLD, m_threshold) == 0)
3693 if (mallopt(M_TRIM_THRESHOLD, 3 * m_threshold) == 0)
3702 "Warning: this platform does not support staticMmapThreshold\n");
3709 m_threshold = (int) (m_threshold * 1.25);
3710 void *temp_buf = malloc((
size_t) m_threshold);
3711 ni_log2(p_ctx,
NI_LOG_TRACE,
"trigger a pre-mature increase in mmap&trim threshold: 0x%p = malloc(%d)\n",
3712 temp_buf, m_threshold);
3719 bool device_in_ctxt =
true;
3735 for (uint8_t ui8Index = 0; ui8Index < 20; ui8Index++)
3758 "p_ctx->sender_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3767 "p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3773 if ((sender_vf_ns_id.
ns_id != curr_vf_ns_id.
ns_id) ||
3774 (sender_vf_ns_id.
vf_id != curr_vf_ns_id.
vf_id))
3791 "p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3802 "ERROR: ni_ai_query_network_ready returned %d\n", retval);
3835 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d return %d\n", __func__, __LINE__, retval);
3851 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3852 "p_ctx->session_id=%d\n",
3856 #ifdef XCODER_DUMP_DATA
3857 char dir_name[256] = {0};
3858 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-pkt", (
long)getpid(),
3860 DIR *dir = opendir(dir_name);
3863 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3871 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-fme", (
long)getpid(),
3873 dir = opendir(dir_name);
3876 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3947 void* p_buffer = NULL;
3948 uint32_t ui32LBA = 0;
3973 "Encoder_complete_info:session_id 0x%x, total frames input:%u "
3974 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
4016 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
4017 "p_ctx->session_id=%d, close_mode=1\n",
4085 for (i = 0; i < 120 ; i++)
4099 low_delay_signal(p_ctx);
4110 int32_t width_stride[4] = {0};
4111 int32_t height_stride[4] = {0};
4126 width_stride, height_stride);
4129 for (
int i = 0; i < 120; i++)
4150 for (
int j = 0; j < source_height; j++)
4153 ni_frame->
p_data[0] + j * width_stride[0],
4156 for (
int j = 0; j < (source_height + 1) / 2; j++)
4159 ni_frame->
p_data[1] + j * width_stride[1],
4162 for (
int j = 0; j < (source_height + 1) / 2; j++)
4165 ni_frame->
p_data[2] + j * width_stride[2],
4181 for (
int j = 0; j < source_height; j++)
4184 ni_frame->
p_data[0] + j * width_stride[0],
4187 for (
int j = 0; j < (source_height + 1) / 2; j++)
4190 ni_frame->
p_data[1] + j * width_stride[1],
4193 for (
int j = 0; j < (source_height + 1) / 2; j++)
4196 ni_frame->
p_data[2] + j * width_stride[2],
4219 bool ishwframe =
false;
4221 uint32_t send_count = 0;
4223 uint32_t sent_size = 0;
4224 uint32_t frame_size_bytes = 0;
4229 if (!p_ctx || !p_frame)
4248 if (!((input_frame_idx > 0 &&
4254 __func__, input_frame_idx);
4273 low_delay_wait(p_ctx);
4275 #ifdef MEASURE_LATENCY
4302 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: passed video_height and video_width are not valid!, return\n");
4314 "%s: data_len[0] %u data_len[1] %u "
4315 "data_len[2] %u extra_data_len %u frame_size_bytes %u\n",
4349 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d retrun %d\n", __func__, __LINE__, retval);
4356 "Enc write query retry %d. rc=%d. Available buf size %u < "
4357 "frame size %u\n", retval, send_count,
4361 int retval_backup = retval;
4374 "Enc write query buf info exceeded max retries: "
4375 "%d, rc=%d. Available buf size %u < frame size %u\n",
4389 "Info enc write query success, available buf "
4390 "size %u >= frame size %u !\n",
4399 if (separate_metadata)
4405 p_frame->
p_data[2 + ishwframe] +
4420 "use_cur_src_as_long_term_pic %d use_long_term_ref %d\n",
4435 "%s(): ctx->force_frame_type"
4436 " %d frame->force_key_frame %d force frame_num %" PRIu64
""
4478 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
4479 "p_frame->start_of_stream=%u, p_frame->end_of_stream=%u, "
4480 "p_frame->video_width=%u, p_frame->video_height=%u, pts=0x%08x 0x%08x, "
4481 "dts=0x%08x 0x%08x, sei_len=%u, roi size=%u avg_qp=%u reconf_len=%u "
4482 "force_pic_qp=%u use_cur_src_as_long_term_pic %u use_long_term_ref "
4483 "%u start_len [%u,%u,%u] inconsecutive_transfer %u "
4484 "get_recon_frame_mode %u\n",
4488 (uint32_t)(p_frame->
pts & 0xFFFFFFFF),
4489 (uint32_t)((p_frame->
dts >> 32) & 0xFFFFFFFF),
4536 "ni_timestamp_register() for dts returned: %d\n",
4540 if (separate_metadata)
4542 uint32_t ui32LBA_metadata =
4545 "%s: p_metadata_buffer = %p, metadata_buffer_size "
4546 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4575 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
4576 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4604 "%s: p_data = %p, p_frame->buffer_size "
4605 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4637 "%s: p_data = %p, p_frame->buffer_size "
4638 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4642 sent_size = frame_size_bytes;
4643 if (separate_metadata)
4676 int ret =
hwdl_frame(p_ctx, &hwdl_session_data, p_frame,
4697 "%s(): session=0x%x ui16FrameIdx=%u\n",
4705 size = frame_size_bytes;
4708 #ifdef XCODER_DUMP_DATA
4709 char dump_file[256];
4710 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-fme/fme-%04ld.yuv",
4736 uint32_t actual_read_size = 0;
4737 uint32_t to_read_size = 0;
4739 static long long encq_count = 0LL;
4741 int query_retry = 0;
4743 uint32_t ui32LBA = 0;
4748 int low_delay_notify = 0;
4751 if (!p_ctx || !p_packet || !p_packet->
p_data)
4771 ni_log2(p_ctx,
NI_LOG_DEBUG,
"frame_num=%" PRIu64
", pkt_num=%" PRIu64
", av1_pkt_num=%" PRIu64
"\n",
4784 low_delay_notify = 1;
4816 if(query_retry == 0)
4817 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: initial_frame_delay %d max_frame_delay %d ui8AdditionalFramesDelay %u current_frame_delay %d\n",
4831 "Info enc read query rc %d, available buf size %u, "
4832 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
4869 "%" PRIu64
" >= %" PRIu64
" pkt_num, keep querying p_ctx->status %d\n",
4877 low_delay_notify = 1;
4894 ni_log2(p_ctx,
NI_LOG_TRACE,
"%s: low delay mode 2, keep reading send frame %d receive pkt %d gop %d current_frame_delay %d\n",
4895 __FUNCTION__, p_ctx->
frame_num, pkt_num,
4925 actual_read_size = to_read_size;
4938 "ERROR %s(): packet buffer size %u allocation "
4940 __func__, actual_read_size);
4947 p_packet->
p_data, actual_read_size, ui32LBA);
4969 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s MetaDataSize %d FrameType %d AvgFrameQp %d ssim %d %d %d\n",
4987 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: current gop_size %u last_gop_size %d initial_frame_delay %d max_frame_delay %d current_frame_delay %d\n",
5011 ni_log2(p_ctx,
NI_LOG_DEBUG,
"pkt_num %d max_mv x[0] %d x[1] %d y[0] %d y[1] %d min_mv x[0] %d x[1] %d y[0] %d y[1] %d frame_size %u inter_total_count %u intra_total_count %u stillImage %d scenechange %d\n",
5028 if (p_meta->
ssimY != 0)
5036 #ifdef NI_LOG_SSIM_AT_INFO
5041 "%s: pkt #%" PRId64
" pts %" PRId64
" ssim "
5042 "Y %.4f U %.4f V %.4f\n", __FUNCTION__, p_ctx->
pkt_num,
5043 p_packet->
pts, (
float)p_meta->
ssimY/10000,
5044 (float)p_meta->
ssimU/10000, (
float)p_meta->
ssimV/10000);
5110 low_delay_notify = 1;
5115 #ifdef MEASURE_LATENCY
5122 #ifdef XCODER_DUMP_DATA
5123 char dump_file[256];
5124 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-pkt/pkt-%04ld.bin",
5138 "%s(): %d.%u p_packet->start_of_stream=%u, "
5139 "p_packet->end_of_stream=%u, p_packet->video_width=%u, "
5140 "p_packet->video_height=%u, p_packet->dts=0x%08x 0x%08x, "
5141 "p_packet->pts=0x%08x 0x%08x, type=%u, avg_frame_qp=%u, show_frame=%d\n",
5144 (uint32_t)((p_packet->
dts >> 32) & 0xFFFFFFFF),
5145 (uint32_t)(p_packet->
dts & 0xFFFFFFFF),
5146 (uint32_t)((p_packet->
pts >> 32) & 0xFFFFFFFF),
5147 (uint32_t)(p_packet->
pts & 0xFFFFFFFF), p_packet->
frame_type,
5153 if (encq_count % 500 == 0)
5156 "Encoder pts queue size = %u dts queue size = %u\n\n",
5162 #ifdef MEASURE_LATENCY
5182 if (low_delay_notify)
5184 low_delay_signal(p_ctx);
5208 p_ctx->
last_gop_size = g_map_preset_to_gopsize[lookAheadEnable][gop_preset_index + 1];
5220 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): config encoder sequence change command failed\n",
5245 void* p_buffer = NULL;
5246 uint32_t ui32LBA = 0;
5247 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
5262 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use stack filter on device with FW API version < 6.4\n");
5272 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use rotate filter on device with FW API version < 6.7\n");
5282 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use in-place overlay filter on device with FW API version < 6.L\n");
5292 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use ai align filter on device with FW API version < 6.sI\n");
5359 "ERROR %s(): p_ctx->device_handle=%" PRIx64
5360 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5368 "%s(): p_ctx->device_handle=%" PRIx64
5369 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5374 uint64_t keep_alive_timeout =
5377 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
5379 keep_alive_timeout);
5390 "ERROR %s(): nvme write keep_alive_timeout command "
5391 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5407 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
5418 "ERROR %s(): nvme write sw_version command "
5419 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5435 #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OPEN_HARMONY__) && !defined(_ANDROID)
5438 retval = p2p_fill_pcie_address(p_ctx);
5465 void * p_buffer = NULL;
5466 uint32_t ui32LBA = 0;
5500 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
5501 "p_ctx->session_id=%d, close_mode=1\n",
5553 void *p_scaler_config = NULL;
5557 uint32_t ui32LBA = 0;
5561 if (!p_ctx || !p_params)
5587 memset(p_scaler_config, 0, buffer_size);
5605 "on device with FW API version < 6rL\n", __func__);
5611 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5612 "hw_id, %d, xcoder_inst_id: %d\n",
5639 "on device with FW API version < 6s1\n", __func__);
5645 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5646 "hw_id, %d, xcoder_inst_id: %d\n",
5659 "be in [0 , 5]. scaler_params_b is %lf, scaler_params_c is %lf\n",
5666 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5667 "hw_id, %d, xcoder_inst_id: %d\n",
5681 p_scaler_config, buffer_size, ui32LBA);
5682 if ((int32_t)retval < 0)
5685 "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
5686 ", hw_id, %d, xcoder_inst_id: %d\n",
5693 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5694 "hw_id, %d, xcoder_inst_id: %d\n",
5739 int rectangle_width,
5740 int rectangle_height,
5749 uint32_t ui32LBA = 0;
5750 uint32_t query_retry = 0;
5755 dataLen = dataLen & 0xFFFFF000;
5772 if (rgba_color == 0)
5779 "WARNING: Allocate framepool size 0 for session 0x%x\n", p_ctx->
session_id);
5785 "ERROR: %s() try to free session 0x%x framepool while it's not allocated\n",
5796 "ERROR: %s() try to free session 0x%x framepool of type %u while "
5797 "passing type %u\n",
5812 "ERROR: allocate framepool multiple times for session 0x%x "
5813 "not supported in FW API version < 6r3\n",
5820 "Expand frame pool of scaler 0x%x with %u more frames\n",
5826 "ERROR: try to expand session 0x%x framepool with type %u "
5827 "while pool type is %u\n",
5842 memset(p_data, 0x00, dataLen);
5844 p_data->picture_width = width;
5845 p_data->picture_height = height;
5846 p_data->picture_format = format;
5847 p_data->options = options;
5848 p_data->rectangle_width = rectangle_width;
5849 p_data->rectangle_height = rectangle_height;
5850 p_data->rectangle_x = rectangle_x;
5851 p_data->rectangle_y = rectangle_y;
5852 p_data->rgba_color = rgba_color;
5853 p_data->frame_index = frame_index;
5864 p_data->frame_index = frame_index;
5871 p_data->rgba_color = 0;
5901 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", width, height, format);
5906 "Session=0x%x: Dev alloc frame: FrameIndex=%d; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5908 p_data->picture_width, p_data->picture_height,
5909 p_data->picture_format, p_data->rectangle_width,
5910 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5920 p_data, dataLen, ui32LBA);
5947 "ERROR: ni_nvme_send_admin_cmd failed: "
5948 "blk_io_handle: %" PRIx64
", hw_id, %u, xcoder_inst_id: %d\n",
5977 uint32_t ui32LBA = 0;
5982 dataLen = dataLen & 0xFFFFF000;
5984 if (!p_ctx || !p_cfg)
6003 memset(p_data, 0x00, dataLen);
6008 p_data->options = p_cfg->
options;
6027 p_data->orientation = 3;
6030 p_data->orientation = 1;
6042 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", p_data->picture_width, p_data->picture_height, p_data->picture_format);
6048 "Session=0x%x: Dev config frame: FrameIndex=%u; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d; O=%d\n",
6050 p_data->picture_width, p_data->picture_height,
6051 p_data->picture_format, p_data->rectangle_width,
6052 p_data->rectangle_height, p_data->rectangle_x,
6053 p_data->rectangle_y, p_data->orientation);
6059 p_data, dataLen, ui32LBA);
6065 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
6066 ", hw_id, %u, xcoder_inst_id: %d\n",
6070 "ERROR ni_scaler_config(): nvme command failed!\n");
6101 uint32_t ui32LBA = 0;
6107 dataLen = dataLen & 0xFFFFF000;
6109 if (!p_ctx || (!p_cfg_in && numInCfgs))
6128 memset(p_data, 0x00, dataLen);
6130 p_data_orig = p_data;
6132 for (i = 0; i < numInCfgs; i++)
6149 "Session=0x%x: Dev in config frame %d: FrameIndex=%u; Session=0x%x; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
6151 p_data->frame_index, p_data->session_id,
6152 p_data->picture_width, p_data->picture_height,
6153 p_data->picture_format, p_data->rectangle_width,
6154 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
6174 "Session=0x%x: Dev out config frame: FrameIndex=%u; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
6176 p_data->picture_width, p_data->picture_height,
6177 p_data->picture_format, p_data->rectangle_width,
6178 p_data->rectangle_height, p_data->rectangle_x,
6179 p_data->rectangle_y);
6183 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", p_data->picture_width, p_data->picture_height, p_data->picture_format);
6192 p_data_orig, dataLen, ui32LBA);
6198 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
6199 ", hw_id, %u, xcoder_inst_id: %d\n",
6203 "ERROR ni_scaler_config(): nvme command failed!\n");
6225 void* p_buffer = NULL;
6227 uint32_t ui32LBA = 0;
6232 if ((!p_ctx) || (!p_gen_status))
6243 __func__, device_type);
6258 memset(p_buffer, 0, dataLen);
6271 p_gen_status->fw_model_load, p_gen_status->cmd_queue_count,
6272 p_gen_status->process_load_percent);
6293 void* p_buffer = NULL;
6295 uint32_t ui32LBA = 0;
6296 uint32_t dataLen = 0;
6297 uint32_t copyLen = 0;
6318 if ((!p_ctx) || (!p_detail_status))
6329 __func__, device_type);
6342 memset(p_buffer, 0, dataLen);
6352 memcpy(p_detail_status, p_buffer, copyLen);
6375 void* p_buffer = NULL;
6377 uint32_t ui32LBA = 0;
6382 if ((!p_ctx) || (!p_stream_info))
6394 __func__, device_type);
6416 memset(p_buffer, 0, dataLen);
6428 p_stream_info->picture_width = ni_htons(p_stream_info->picture_width);
6429 p_stream_info->picture_height = ni_htons(p_stream_info->picture_height);
6430 p_stream_info->frame_rate = ni_htons(p_stream_info->frame_rate);
6431 p_stream_info->is_flushed = ni_htons(p_stream_info->is_flushed);
6432 p_stream_info->transfer_frame_stride = ni_htons(p_stream_info->transfer_frame_stride);
6434 p_stream_info->pix_format);
6462 void* p_buffer = NULL;
6463 uint64_t session_timestamp;
6464 uint32_t ui32LBA = 0;
6473 if ((!p_ctx) || (!p_session_stats))
6484 __func__, device_type);
6506 memset(p_buffer, 0, dataLen);
6526 p_session_stats->ui16SessionId = ni_htons(p_session_stats->ui16SessionId);
6527 p_session_stats->ui16ErrorCount = ni_htons(p_session_stats->ui16ErrorCount);
6528 p_session_stats->ui32LastTransactionId =
6529 ni_htonl(p_session_stats->ui32LastTransactionId);
6530 p_session_stats->ui32LastTransactionCompletionStatus =
6531 ni_htonl(p_session_stats->ui32LastTransactionCompletionStatus);
6532 p_session_stats->ui32LastErrorTransactionId = ni_htonl(p_session_stats->ui32LastErrorTransactionId);
6533 p_session_stats->ui32LastErrorStatus = ni_htonl(p_session_stats->ui32LastErrorStatus);
6534 p_session_stats->ui32Session_timestamp_high = ni_htonl(p_session_stats->ui32Session_timestamp_high);
6535 p_session_stats->ui32Session_timestamp_low = ni_htonl(p_session_stats->ui32Session_timestamp_low);
6537 session_timestamp = p_session_stats->ui32Session_timestamp_high;
6538 session_timestamp <<= 32;
6539 session_timestamp |= p_session_stats->ui32Session_timestamp_low;
6547 p_session_stats->ui32LastErrorStatus =
6550 "query timestamp:%" PRIu64
"\n", p_ctx->
session_id,
6559 ni_log2(p_ctx,
NI_LOG_ERROR,
"%s(): session id %u ts %lu hw_id %d device_type %u codec_format %u frame_num %lu pkt_num %lu "
6560 "ready_to_close %u session_run_state %d active_video_width %u active_video_height %u\n",
6574 #if __linux__ || __APPLE__
6575 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
6576 #ifndef DISABLE_BACKTRACE_PRINT
6577 ni_print_backtrace();
6582 p_session_stats->ui32LastTransactionCompletionStatus =
6586 }
else if (p_ctx->
session_id != p_session_stats->ui16SessionId)
6591 "%s(): device 0x%" PRIx64
" last command Failed due to wrong "
6592 "session ID. Expected 0x%x, got 0x%x keep alive last access "
6593 "time %" PRIu64
", current %" PRIu64
"\n", __func__,
6596 if (dt > 1000000000)
6599 "%s():long delay between last command dt = %" PRId64
" ns, "
6600 "process was possibly blocked.\n", __func__, dt);
6609 __func__, p_session_stats->ui16ErrorCount,
6610 p_session_stats->ui32LastTransactionCompletionStatus,
6611 p_session_stats->ui32LastErrorStatus);
6634 void* p_buffer = NULL;
6636 uint32_t ui32LBA = 0;
6641 if (!p_ctx || !p_stream_complete)
6653 __func__, device_type);
6675 memset(p_buffer, 0, dataLen);
6687 p_stream_complete->is_flushed = ni_htons(p_stream_complete->is_flushed);
6697 static const char* ni_get_device_type_str(
int type)
6701 return "Invalid device type";
6703 return g_device_type_str[type];
6711 memcpy((
void *)p_session_statistic, p_buffer,
6715 p_session_statistic->ui32RdBufAvailSize =
6716 ni_htonl(p_session_statistic->ui32RdBufAvailSize);
6717 p_session_statistic->ui32WrBufAvailSize =
6718 ni_htonl(p_session_statistic->ui32WrBufAvailSize);
6720 p_session_statistic->ui32FramesInput =
6721 ni_htonl(p_session_statistic->ui32FramesInput);
6722 p_session_statistic->ui32FramesBuffered =
6723 ni_htonl(p_session_statistic->ui32FramesBuffered);
6724 p_session_statistic->ui32FramesCompleted =
6725 ni_htonl(p_session_statistic->ui32FramesCompleted);
6726 p_session_statistic->ui32FramesOutput =
6727 ni_htonl(p_session_statistic->ui32FramesOutput);
6728 p_session_statistic->ui32FramesDropped =
6729 ni_htonl(p_session_statistic->ui32FramesDropped);
6730 p_session_statistic->ui32InstErrors =
6731 ni_htonl(p_session_statistic->ui32InstErrors);
6733 p_session_statistic->ui16SessionId =
6734 ni_htons(p_session_statistic->ui16SessionId);
6735 p_session_statistic->ui16ErrorCount =
6736 ni_htons(p_session_statistic->ui16ErrorCount);
6737 p_session_statistic->ui32LastTransactionId =
6738 ni_htonl(p_session_statistic->ui32LastTransactionId);
6739 p_session_statistic->ui32LastTransactionCompletionStatus =
6740 ni_htonl(p_session_statistic->ui32LastTransactionCompletionStatus);
6741 p_session_statistic->ui32LastErrorTransactionId =
6742 ni_htonl(p_session_statistic->ui32LastErrorTransactionId);
6743 p_session_statistic->ui32LastErrorStatus =
6744 ni_htonl(p_session_statistic->ui32LastErrorStatus);
6745 p_session_statistic->ui32Session_timestamp_high =
6746 ni_htonl(p_session_statistic->ui32Session_timestamp_high);
6747 p_session_statistic->ui32Session_timestamp_low =
6748 ni_htonl(p_session_statistic->ui32Session_timestamp_low);
6752 if (p_ctx->
session_id != p_session_statistic->ui16SessionId)
6757 "%s(): %s device 0x%" PRIx64
" last command Failed due to wrong "
6758 "session ID. Expected 0x%x, got 0x%x w_r <%u %u> keep alive "
6759 "last access time %" PRIu64
", current %" PRIu64
"\n", __func__,
6762 p_session_statistic->ui16SessionId,
6763 p_session_statistic->ui32WrBufAvailSize,
6766 if (dt > 1000000000)
6769 "%s():long delay between last command dt = %" PRId64
" ns, "
6770 "process was possibly blocked.\n", __func__, dt);
6772 p_session_statistic->ui32LastErrorStatus =
6782 __func__, p_session_statistic->ui16ErrorCount,
6783 p_session_statistic->ui32LastTransactionCompletionStatus,
6784 p_session_statistic->ui32LastErrorStatus);
6804 void *p_buffer = NULL;
6806 uint32_t ui32LBA = 0;
6812 if (!p_ctx || !p_session_statistic)
6815 "ERROR: %s() passed parameters are null!, return\n", __func__);
6823 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() not supported on device with FW api version < 6.5\n", __func__);
6832 __func__, device_type);
6854 memset(p_buffer, 0, dataLen);
6863 p_buffer, dataLen, ui32LBA) < 0)
6874 ni_parse_session_statistic_info(p_ctx, p_session_statistic, p_buffer);
6879 __func__, ni_get_device_type_str(p_ctx->
device_type));
6908 void* p_buffer = NULL;
6910 uint32_t ui32LBA = 0;
6918 if (!p_ctx || !p_inst_buf_info)
6932 __func__, device_type);
6999 memset(p_buffer, 0, dataLen);
7010 p_inst_buf_info->buf_avail_size = ni_htonl(p_inst_buf_info->buf_avail_size);
7036 uint8_t enable, uint8_t hw_action,
7040 uint32_t ui32LBA = 0;
7041 void * p_buffer = NULL;
7042 uint32_t buffer_size = 0;
7071 memset(p_buffer, 0, buffer_size);
7130 uint32_t ui32LBA = 0;
7146 __func__, device_type);
7184 uint32_t ui32LBA = 0;
7200 __func__, device_type);
7239 uint32_t ui32LBA = 0;
7254 __func__, device_type);
7301 uint32_t ui32LBA = 0;
7302 void * p_buffer = NULL;
7303 uint32_t buffer_size = 0;
7319 __func__, device_type);
7340 memset(p_buffer, 0, buffer_size);
7341 memcpy(p_buffer, &len,
sizeof(len));
7371 uint32_t ui32LBA = 0;
7372 void * p_buffer = NULL;
7373 uint32_t buffer_size = 0;
7387 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Seq Change not supported for device type %d, return\n", device_type);
7408 memset(p_buffer, 0, buffer_size);
7436 void* p_encoder_config = NULL;
7437 void* p_encoder_roi_qp_map = NULL;
7439 uint32_t buffer_size = 0;
7441 uint32_t ui32LBA = 0;
7467 if (
ni_posix_memalign(&p_encoder_roi_qp_map, sysconf(_SC_PAGESIZE), buffer_size))
7474 memset(p_encoder_roi_qp_map, 0, buffer_size);
7478 p_encoder_roi_qp_map, buffer_size, ui32LBA);
7496 ni_log2(p_ctx,
NI_LOG_INFO,
"customizeQpMapFile is ignored since customizeQpLevel=0");
7510 memset(p_encoder_config, 0, buffer_size);
7571 p_encoder_config, buffer_size, ui32LBA);
7608 uint32_t ui32LBA = 0;
7612 if (!p_ctx || !p_params)
7646 buffer_size, ui32LBA) < 0)
7673 p_frame_offset, uint32_t* p_frame_dropped,
bool is_hw_frame)
7678 if (!p_frame || !p_frame_offset)
7685 *p_frame_offset = 0;
7686 if (p_frame_dropped)
7687 *p_frame_dropped = 0;
7691 unsigned int video_data_size = p_frame->
data_len[0] + p_frame->
data_len[1] +
7698 if (rx_size == metadata_size)
7700 video_data_size = 0;
7703 if (rx_size > video_data_size)
7710 rx_size -= metadata_size;
7722 "%s: [metadata] cropRight=%u, cropLeft=%u, "
7723 "cropBottom=%u, cropTop=%u, frame_offset=%" PRIu64
", pic=%ux%u, "
7724 "pict_type=%d, crop=%ux%u, sei header: 0x%0x number %u size %u num_frame_dropped %u\n",
7746 if (p_frame_dropped)
7753 #if 1 // QUADRA_SEI_FMT
7754 ni_log(
NI_LOG_DEBUG,
"ui32SeiHeader 0x%x ui16SeiNumber %d ui16SeiSize %d SEI 0x%02x%02x\n",
7756 *((uint8_t*)p_meta + metadata_size),
7757 *((uint8_t*)p_meta + metadata_size+1));
7760 uint16_t ui16SeiProcessed = 0;
7762 uint32_t ui32Offset = 0;
7771 if (pEntryHeader->
status)
7773 ui32Size = pEntryHeader->
size;
7781 ui16SeiProcessed, pEntryHeader->
status,
7782 pEntryHeader->
size, pEntryHeader->
type, ui32Size,
7784 *((uint8_t *)p_meta + metadata_size + ui32Offset),
7785 *((uint8_t *)p_meta + metadata_size + ui32Offset + 1));
7792 switch(pEntryHeader->
type)
7797 uint8_t *ptr = (uint8_t*)p_meta + metadata_size + ui32Offset;
7804 video_data_size + metadata_size + ui32Offset;
7831 "%s: close caption size %u ,"
7832 "offset %u = video size %u meta size %d off "
7835 video_data_size, metadata_size, ui32Offset);
7840 "%s: unsupported T35; type %u size %u status %u "
7842 __func__, pEntryHeader->
type, pEntryHeader->
size,
7843 pEntryHeader->
status, ui32Offset);
7849 "Error %s: T35 SEI dropped due to %s; type %u size %u status %u offset %u\n",
7850 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7851 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7868 "Error %s: User Data Unreg dropped due to %s; type %u size %u status %u offset %u\n",
7869 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7870 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7879 video_data_size + metadata_size + ui32Offset;
7884 *)((uint8_t *)p_meta + metadata_size + ui32Offset);
7906 "Error %s: mastering display info dropped due to %s; type %u size %u status %u offset %u\n",
7907 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7908 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7917 video_data_size + metadata_size + ui32Offset;
7923 (uint8_t*)p_meta + metadata_size + ui32Offset);
7932 "Error %s: content light level info dropped due to %s; type %u size %u status %u offset %u\n",
7933 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7934 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7943 video_data_size + metadata_size + ui32Offset;
7952 "Warning %s: SEI message dropped (unsupported - check "
7953 "decoder SEI bitmap settings);"
7954 " type %u size %u status %u offset %u payload bytes %u\n",
7955 __func__, pEntryHeader->
type, pEntryHeader->
size,
7956 pEntryHeader->
status, ui32Offset, ui32Size);
7959 ui32Offset += ui32Size;
7960 pEntryHeader = (
ni_sei_header_t *)((uint8_t*)p_meta + metadata_size + ui32Offset);
7962 }
while (ui32Offset <= p_meta->sei_size && ui16SeiProcessed < p_meta->sei_number);
7968 "Error %s: number of SEI messages reported %u != processed %u\n",
7969 __func__, p_meta->
sei_number, ui16SeiProcessed);
7973 #else // QUADRA_SEI_FMT
7978 ni_sei_user_data_entry_t *pEntry;
7979 uint32_t ui32CCOffset = 0, ui32CCSize = 0;
7983 pEntry = (ni_sei_user_data_entry_t *)((uint8_t*)p_meta + metadata_size);
7986 &ui32CCOffset, &ui32CCSize))
7990 video_data_size + metadata_size + ui32CCOffset;
8003 &ui32CCOffset, &ui32CCSize))
8007 ptr = (uint8_t*)pEntry + ui32CCOffset;
8010 ui32CCSize = (ptr[8] & 0x1F) * 3;
8016 + ui32CCOffset + 10;
8021 "%s: close caption size %u ,"
8022 "offset %u = video size %u meta size %u off "
8025 video_data_size, metadata_size, ui32CCOffset);
8035 &ui32CCOffset, &ui32CCSize))
8039 video_data_size + metadata_size + ui32CCOffset;
8043 ni_dec_mastering_display_colour_volume_t* pColourVolume =
8044 (ni_dec_mastering_display_colour_volume_t*)((uint8_t*)pEntry + ui32CCOffset);
8047 pColourVolume->display_primaries_x[0],
8048 pColourVolume->display_primaries_y[0]);
8050 pColourVolume->display_primaries_x[1],
8051 pColourVolume->display_primaries_y[1]);
8053 pColourVolume->display_primaries_x[2],
8054 pColourVolume->display_primaries_y[2]);
8057 pColourVolume->white_point_x,
8058 pColourVolume->white_point_y);
8060 pColourVolume->max_display_mastering_luminance, pColourVolume->min_display_mastering_luminance);
8064 &ui32CCOffset, &ui32CCSize))
8068 video_data_size + metadata_size + ui32CCOffset;
8072 ni_content_light_level_info_t* pLightLevel =
8073 (ni_content_light_level_info_t*)((uint8_t*)pEntry + ui32CCOffset);
8075 pLightLevel->max_content_light_level, pLightLevel->max_pic_average_light_level);
8080 &ui32CCOffset, &ui32CCSize) ||
8083 &ui32CCOffset, &ui32CCSize))
8087 video_data_size + metadata_size + ui32CCOffset;
8094 #endif // QUADRA_SEI_FMT
8129 ni_device_handle_t device_handle,
bool device_in_ctxt)
8131 int i, total_types = 0, total_modules = 0;
8139 if (!p_cap || !p_data)
8152 "ERROR: Previously in context device got an invalid vendor ID 0x%X SSVID 0x%X. Netint "
8153 "ID 0x%X. Retrying\n",
8157 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
8159 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
8161 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
8165 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
8176 "ERROR: %s(): Retry got an invalid vendor ID too 0x%X SSVID "
8181 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
8183 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
8185 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
8193 "Retry got valid a vendor ID 0x%X SSVID 0x%X. Netint ID 0x%X\n",
8232 "Error: mismatch; xcoder_num_elements: %d (calculated: %d) "
8233 "xcoder_num_devices: %d (calculated: %d)\n",
8290 "ERROR: Previously in context device is not a xcoder device "
8310 if (total_modules >= 1)
8325 if (total_modules >= 2)
8340 if (total_modules >= 3)
8355 if (total_modules >= 4)
8423 static uint32_t presetGopSize[] = {
8443 int pos_byte = (pos/8);
8444 int pos_in_byte = pos%8;
8445 int remaining_bytes_in_current_byte = 8 - pos_in_byte;
8447 if (pos_in_byte == 0)
8449 vui[pos_byte] = (uint8_t)(value >> 24);
8450 vui[pos_byte+1] = (uint8_t)(value >> 16);
8451 vui[pos_byte+2] = (uint8_t)(value >> 8);
8452 vui[pos_byte+3] = (uint8_t)(value);
8456 vui[pos_byte] = vui[pos_byte] + (uint8_t)(value >> (32-remaining_bytes_in_current_byte));
8457 vui[pos_byte+1] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-8));
8458 vui[pos_byte+2] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-16));
8459 vui[pos_byte+3] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-24));
8460 vui[pos_byte+4] = vui[pos_byte+4] + ((uint8_t)(value << remaining_bytes_in_current_byte));
8475 uint32_t max_pkt_size)
8479 if ((!p_ctx) || (!p_cfg) || (!p_src))
8488 bool shift_params =
false;
8516 ni_log2(p_ctx,
NI_LOG_INFO,
"%s height %d width %d fps_number %d fps_denominator %d\n",
8526 shift_params =
true;
8527 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Output 2 used before output 1, Shifting output2 settings to output1 and disabling output 2\n");
8532 if (!shift_params || i == 0)
8538 j = (i == 1) ? 2 : 1;
8544 (uint16_t)((p_dec->
crop_whxy[j][0]) & 0xFFFE);
8546 (uint16_t)((p_dec->
crop_whxy[j][1]) & 0xFFFE);
8548 (uint16_t)((p_dec->
crop_whxy[j][2]) & 0xFFFE);
8550 (uint16_t)((p_dec->
crop_whxy[j][3]) & 0xFFFE);
8602 (uint16_t)((p_dec->
scale_wh[j][0]+1) & 0xFFFE);
8604 (uint16_t)((p_dec->
scale_wh[j][1]+1) & 0xFFFE);
8621 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): maxExtraHwFrameCnt is not support for FW < 6rB\n", __func__);
8629 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (enableAdvancedEc == 2) is not support for FW < 6rO\n", __func__);
8636 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (EcPolicy == limited_error) not supported for FW < 6ri\n", __func__);
8643 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): setting ecErrThreshold not supported for FW < 6ri\n", __func__);
8650 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (EcPolicy == best_effort_out_dc) not supported for FW < 6s1\n", __func__);
8658 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): surviveStreamErr is not supported for FW < 6rl\n", __func__);
8667 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s():Not support to reduce dpb delay and reset.\n", __func__);
8726 if ((!p_ctx) || (!p_cfg) || (!p_src))
8779 ni_log2(p_ctx,
NI_LOG_DEBUG,
"force enable_mb_level_rc & enable_cu_level_rate_control to 0 because rate control is disabled\n");
8783 ni_log2(p_ctx,
NI_LOG_TRACE,
"### %s: b preset_index %d bitrate %d rcEnable %d %d EnableRdoQuant %d lookAheadDepth %d gop_preset_index %d rdoLevel %d vbv_buffer_size %d crf %d %f\n", __func__,
8795 if (p_enc->
crf != -1 || p_enc->
crfFloat != -1.0f) {
8798 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): CRF disabled due to preset enabled\n", __func__);
8837 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_bitrate %d. assigned bitrate %d\n",
8849 ni_log2(p_ctx,
NI_LOG_TRACE,
"### %s: a bitrate %d rcEnable %d %d EnableRdoQuant %d lookAheadDepth %d gop_preset_index %d rdoLevel %d vbv_buffer_size %d enable_cu_level_rate_control %d\n", __func__,
8903 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_framerate num %d den %d. assigned num %d den %d\n",
8920 uint32_t numUnitsInTick = 1000;
8990 "ERROR: %s() unknown value for p_t408->decoding_refresh_type: %d\n",
9014 ni_log2(p_ctx,
NI_LOG_DEBUG,
"force intraRefreshMode to 1 because quadra only supports intra refresh by rows\n");
9024 int mbRows = (p_cfg->
i32picHeight + mbHeight - 1) / mbHeight;
9059 "for profile 3 (extended) or 1 (baseline)\n");
9069 "force EnableRdoQuant 0 to accommodate HW limiation\n");
9189 if (p_enc->
crf != -1)
9337 "Turning off strongIntraSmoothing because hvsQPEnable=1 "
9338 "for better subjective VQ\n");
9350 "Turning off strongIntraSmoothing because hvsQPEnable=1 for "
9351 "better subjective VQ\n");
9385 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): spatialLayers is not supported for FW < 6rw\n", __func__);
9393 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): spatialLayers is not supported for FW < 6s0\n", __func__);
9411 ni_log(
NI_LOG_INFO,
"Warning h.265 psnr_y is only supported for YUV420P, YUV420P10LE, NV12, and P010LE\n");
9421 ni_log(
NI_LOG_INFO,
"Warning reconstructed frames only supported for YUV420P, NV12\n");
9427 ni_log(
NI_LOG_INFO,
"Warning reconstructed frames feature is not supported when cropWidth x cropHeight are set\n");
9437 ni_log(
NI_LOG_INFO,
"Warning get psnr feature only support YUV420P (except for h.265 psnr_y)\n");
9443 ni_log(
NI_LOG_INFO,
"Warning get psnr feature is not supported when cropWidth x cropHeight are set\n");
9480 int gopSize = g_map_preset_to_gopsize[lookAheadEnable][p_t408->
gop_preset_index + 1];
9486 if (lookAheadEnable)
9488 int firstGopEnd = gopSize + 1 + mulitcoreDelay;
9489 int lookaheadGopEnd = mulitcoreDelay ?
9492 int initialDelayNum = (firstGopEnd > lookaheadGopEnd) ? firstGopEnd : lookaheadGopEnd;
9494 int maxLookaheadQueue = initialDelayNum + (gopSize - 1) + mulitcoreDelay;
9497 p_ctx->
max_frame_delay = ((maxDelayNum > maxLookaheadQueue) ? maxDelayNum : maxLookaheadQueue) + (mulitcoreDelay ? 4 : 0);
9520 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: firstGopEnd %d lookaheadGopEnd %d initialDelayNum %d maxDelayNum %d maxLookaheadQueue %d\n",
9521 __FUNCTION__, firstGopEnd, lookaheadGopEnd, initialDelayNum, maxDelayNum, maxLookaheadQueue);
9529 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: preset %d lookAheadDepth %d gopSize %d mulitcoreDelay %d "
9530 "last_gop_size %d linitial_frame_delay %d current_frame_delay %d max_frame_delay %d\n",
9547 if (p_enc->
qcomp != (
float)0.6)
9567 if (p_enc->
ipRatio != (
float)1.4)
9572 if (p_enc->
pbRatio != (
float)1.3)
9597 if (p_enc->
crfFloat != (
float)-1.0)
9800 for (i = 0; i < 8; i++)
10046 if( (!p_ctx) || (!p_config) )
10318 p_config->
i8crf = -1;
10377 p_config->
i8crfMax = (int8_t)(-1) + 1;
10378 p_config->
i32qcomp = (int32_t)(0.6 * 1000) + 1000;
10382 p_config->
i32ipRatio = (int32_t)(1.4 * 1000) + 1000;
10383 p_config->
i32pbRatio = (int32_t)(1.3 * 1000) + 1000;
10384 p_config->
i32cplxDecay = (int32_t)(0.5 * 1000) + 1000;
10388 p_config->
i8pass1Qp = (int8_t)(-1) + 1;
10443 uint32_t max_err_len)
10449 char *p_param_warn = NULL;
10452 if (!p_ctx || !p_cfg || !p_param_err)
10470 memset(p_param_err, 0, max_err_len);
10471 memset(p_param_warn, 0, max_err_len);
10484 ni_strncpy(p_param_err, max_err_len,
"Incompatible output format: hw frame must be used if out1 or out2 used", max_err_len - 1);
10494 ni_strncpy(p_param_err, max_err_len,
"ddr_priority_mode not supported on device with FW api version < 6.e",
10503 ni_strncpy(p_param_err, max_err_len,
"LowDelay is not supported on jpeg/vp9 decoder",
10517 ni_strncpy(p_param_err, max_err_len,
"Invalid crop offset: extends past 48x48 minimum window", max_err_len - 1);
10524 ni_strncpy(p_param_err, max_err_len,
"Invalid crop w or h: must be at least 48x48 minimum window", max_err_len - 1);
10531 ni_strncpy(p_param_err, max_err_len,
"Invalid crop w or h: must be smaller than input", max_err_len - 1);
10538 ni_strncpy(p_param_err, max_err_len,
"Invalid crop rect: must fit in input", max_err_len - 1);
10547 ni_strncpy(p_param_err, max_err_len,
"Invalid crop value: even values only", max_err_len - 1);
10553 ni_strncpy(p_param_warn, max_err_len,
"crop param used but output not enabled!", max_err_len - 1);
10568 ni_strncpy(p_param_err, max_err_len,
"Invalid scale dimensions: zero", max_err_len - 1);
10576 ni_strncpy(p_param_err, max_err_len,
"Invalid scale value: even values only", max_err_len - 1);
10586 ni_strncpy(p_param_err, max_err_len,
"Invalid scale value: downscale only", max_err_len - 1);
10598 ni_strncpy(p_param_err, max_err_len,
"Invalid scale dimensions: downscale only after cropping", max_err_len - 1);
10605 ni_strncpy(p_param_warn, max_err_len,
"scale param used but output not enabled!", max_err_len - 1);
10613 ni_strncpy(p_param_warn, max_err_len,
"force8bit or semiPlanar used but output not enabled!", max_err_len - 1);
10628 "Invalid pairing: out=HW must be set with tiled format",
10635 ni_strncpy(p_param_err, max_err_len,
"Invalid pairing: VP9 not compatible with tiled format",
10647 "Invalid scale height: mult of 4 only, >= 128",
10657 "Invalid scale width: mult of 128 only, >= 144",
10669 "Invalid crop height: mult of 4 only, >= 128",
10679 "Invalid crop width: mult of 128 only, >= 144",
10687 ni_strncpy(p_param_err, max_err_len,
"Force 8 bit: not supported with tiled format\n", max_err_len - 1);
10697 ni_strncpy(p_param_err, max_err_len, p_param_warn, max_err_len - 1);
10702 free(p_param_warn);
10707 static ni_retcode_t ni_check_level(
int level,
int codec_id)
10709 const int l_levels_264[] = {10, 11, 12, 13, 20, 21, 22, 30, 31, 32,
10710 40, 41, 42, 50, 51, 52, 60, 61, 62, 0};
10711 const int l_levels_265[] = {10, 20, 21, 30, 31, 40, 41,
10712 50, 51, 52, 60, 61, 62, 0};
10713 const int l_levels_av1[] = {20, 21, 30, 31, 40, 41, 50, 51, 52, 53, 60, 61, 62, 63, 0};
10714 const int *l_levels = l_levels_264;
10723 l_levels = l_levels_265;
10726 l_levels = l_levels_av1;
10729 while (*l_levels != 0)
10731 if (*l_levels == level)
10752 uint32_t max_err_len)
10760 if( (!p_ctx) || (!p_cfg) || (!p_src) || (!p_param_err) )
10770 memset(p_param_err, 0, max_err_len);
10771 memset(p_param_warn, 0, max_err_len);
10775 ni_strncpy(p_param_err, max_err_len,
"Invalid frame_rate of 0 value", max_err_len - 1);
10783 ni_strncpy(p_param_err, max_err_len,
"Invalid i32frameRateInfo: too big", max_err_len - 1);
10790 ni_strncpy(p_param_err, max_err_len,
"Invalid i32bitRate: smaller than or equal to frame rate", max_err_len - 1);
10797 ni_strncpy(p_param_err, max_err_len,
"Invalid i32bitRate: too big", max_err_len - 1);
10804 ni_strncpy(p_param_err, max_err_len,
"Invalid i32bitRate: too low", max_err_len - 1);
10811 ni_strncpy(p_param_err, max_err_len,
"Invalid Picture Width: too small", max_err_len - 1);
10818 ni_strncpy(p_param_err, max_err_len,
"Invalid Picture Width: too big", max_err_len - 1);
10825 ni_strncpy(p_param_err, max_err_len,
"Invalid Picture Height: too small", max_err_len - 1);
10832 ni_strncpy(p_param_err, max_err_len,
"Invalid Picture Height: too big", max_err_len - 1);
10842 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %u): both need to be specified",
10850 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %uu): must be even",
10858 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: less than %d",
10865 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: less than %d",
10872 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10879 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10886 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10896 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10903 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10910 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10920 snprintf(p_param_err, max_err_len,
"Invalid Crop horOffset %u and/or verOffset %u: must be even",
10928 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: offset %u + crop width %u too big > %d",
10935 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: offset %u + crop height %u too big > %d",
10942 snprintf(p_param_err, max_err_len,
"roiEnable must disabled when Crop Width > 0 || Crop Height > 0");
10953 snprintf(p_param_err, max_err_len,
"Invalid Picture Width: exceeds %d",
10960 snprintf(p_param_err, max_err_len,
"Invalid Picture Height: exceeds %d",
10967 snprintf(p_param_err, max_err_len,
"Invalid Picture Width x Height: exceeds %d",
10977 ni_strncpy(p_param_err, max_err_len,
"Invalid input planar format: out of range", max_err_len - 1);
10986 ni_strncpy(p_param_err, max_err_len,
"Invalid input planar format for device with FW api version < 6.8",
10993 ni_strncpy(p_param_err, max_err_len,
"Invalid Encoder Selected: Tiled format must be on same device",
11001 "Invalid Picture Height: tiled format only supports "
11010 "Invalid Picture Width: tiled format only supports "
11025 ni_strncpy(p_param_err, max_err_len,
"zeroCopyMode must not be disabled for RGBA / BGRA / ABGR / ARGB pixel formats", max_err_len - 1);
11035 ni_strncpy(p_param_err, max_err_len,
"RGBA / BGRA pixel formats not supported on device with FW api version < 6.Y",
11049 snprintf(p_param_err, max_err_len,
"Unsupported pixel format %d in encoder", p_cfg->
ui8PixelFormat);
11059 ni_strncpy(p_param_err, max_err_len,
"ddr_priority_mode not supported on device with FW api version < 6.e",
11069 ni_strncpy(p_param_err, max_err_len,
"Invalid Encoder Level: out of range", max_err_len - 1);
11079 ni_strncpy(p_param_err, max_err_len,
"Invalid intra_mb_refresh_mode: out of range",
11091 ni_strncpy(p_param_err, max_err_len,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len - 1);
11098 ni_strncpy(p_param_err, max_err_len,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len - 1);
11111 "Invalid custom GOP paramaters: custom gop size must > 0",
11123 "Invalid custom GOP paramaters: selected gopPresetIdx is "
11124 "not compatible with custom gop",
11131 ni_strncpy(p_param_err, max_err_len,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len - 1);
11138 ni_strncpy(p_param_err, max_err_len,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len - 1);
11148 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: poc_offset larger"
11149 " than GOP size", max_err_len - 1);
11161 ni_strncpy(p_param_warn, max_err_len,
"useLowDelayPocType is only supported for H.264. Change useLowDelayPocType to 0", max_err_len - 1);
11170 "entropyCodingMode is only supported for H.264.",
11181 "av1ErrorResilientMode is only supported for AV1.",
11191 snprintf(p_param_err, max_err_len,
"%s is not supported for JPEG.",
11201 ni_strncpy(p_param_err, max_err_len,
"qLevel is only supported for JPEG.",
11214 ni_strncpy(p_param_warn, max_err_len,
"enableSSIM only supported on device with FW api version < 6.2 "
11215 "and the encoder is not av1_ni_quadra_enc. Reported ssim will be 0.", max_err_len - 1);
11224 ni_strncpy(p_param_err, max_err_len,
"sliceMode/sliceArg is only supported for H.264 or H.265.",
11233 int max_num_ctu_mb_row = (p_src->
source_height + ctu_mb_size - 1) / ctu_mb_size;
11237 snprintf(p_param_err, max_err_len,
"Invalid number of rows per slice: should be between 1 and %d",
11248 ni_strncpy(p_param_err, max_err_len,
"useLowDelayPocType is only supported for H.264.",
11261 ni_strncpy(p_param_warn, max_err_len,
"ui8enableCompensateQp only supported when device with FW api version < 6rt "
11262 "and the encoder is not av1_ni_quadra_enc and ui16maxFrameSize > 0. Reported enableCompensateQp will be 0.", max_err_len - 1);
11274 ni_strncpy(p_param_warn, max_err_len,
"enableTimecode does not need to be set for H.265. Use ni_enc_insert_timecode API"
11275 "from libxcoder directly to insert time code SEI", max_err_len - 1);
11279 ni_strncpy(p_param_warn, max_err_len,
"enableTimecode not supported for the codec used. Forcing value to 0.", max_err_len - 1);
11297 "this gopPreset is not supported for lookahead and/or CRF",
11305 bool bIsgopLowdelay =
true;
11313 bIsgopLowdelay =
false;
11319 bIsgopLowdelay =
false;
11323 if (bIsgopLowdelay)
11325 ni_strncpy(p_param_err, max_err_len,
"B-frames low delay custom gop is not supported for "
11326 "lookahead and/or CRF", max_err_len - 1);
11335 "bitrateMode is invalid when lookahead is enabled (or in CRF mode)",
11347 "totalCuTreeDepth is invalid without lookahead",
11355 ni_strncpy(p_param_warn, max_err_len,
"totalCuTreeDepth does not take effects when its value <= lookahead depth", max_err_len - 1);
11364 "totalCuTreeDepth is not supported in multicoreJointMode",
11388 "gopPresetIdx 2 is obsolete, suggest to use gopPresetIdx 9 "
11412 "gopPresetIdx 6 is obsolete, suggest to use gopPresetIdx 7 "
11450 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Force newRcEnable to 0 in 2-pass encode or in 1-pass average bitrate mode, with ipRatio, VbvMaxRate, or VbvMinRate\n");
11462 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Set newRcEnable to 0 in spatial layer separated rate control mode\n");
11475 ni_strncpy(p_param_warn, max_err_len,
"StillImageDetect or SceneChangeDetect only support gopPresetIdx=9 with FW > 6rm\n", max_err_len - 1);
11486 "currently do not support gop preset in multi spatial layers encode or spatial layer separated rate control mode",
11500 "higher spatial layers referencing base layer is only supported in multi spatial layers encode",
11518 ni_strncpy(p_param_err, max_err_len,
"number of values specified in spatialLayerBitrate must match the total number of spatial layers", max_err_len - 1);
11528 ni_strncpy(p_param_err, max_err_len,
"spatialLayerBitrate is not supported in multicoreJointMode for FW api version < 6sD", max_err_len - 1);
11544 ni_strncpy(p_param_err, max_err_len,
"Invalid av1OpLevel: out of range", max_err_len - 1);
11553 ni_strncpy(p_param_err, max_err_len,
"av1OpLevel and level cannot be both specified", max_err_len - 1);
11560 ni_strncpy(p_param_err, max_err_len,
"number of values specified in av1OpLevel must match the total number of spatial layers", max_err_len - 1);
11571 "crfMaxIframeEnable is only supported in Capped CRF mode with lookahead enabled",
11587 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 5 (high10)",
11597 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 1 (baseline), 2 (main),"
11598 " 3 (extended), 4 (high), or 5 (high10)", max_err_len - 1);
11609 ni_strncpy(p_param_err, max_err_len,
"Invalid gopPresetIdx for H.264 baseline profile:"
11610 " must be 1, 2, 6 or 0 (custom with no B frames)", max_err_len - 1);
11622 ni_strncpy(p_param_err, max_err_len,
"H.264 baseline profile: custom GOP can not "
11623 "have B frames", max_err_len - 1);
11634 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 1 (baseline), 2 (main),"
11635 " 4 (high), or 5 (high10)", max_err_len - 1);
11641 ni_strncpy(p_param_warn, max_err_len,
"AVC Baseline/Main/High Profile do not support 10-bit, auto convert to 8-bit", max_err_len - 1);
11652 ni_strncpy(p_param_err, max_err_len,
"H.264 baseline profile: custom GOP can not "
11653 "have B frames", max_err_len - 1);
11668 "Must use gopPresetIdx 1,9,10 (no "
11669 "B frames) for profile 1",
11679 ni_strncpy(p_param_err, max_err_len,
"Tier is not supported for H.264", max_err_len - 1);
11686 "spatialLayers is not supported for h.264 encode",
11693 ni_strncpy(p_param_err, max_err_len,
"disableAv1TimingInfo is not supported for h.264",
11700 ni_strncpy(p_param_err, max_err_len,
"av1OpLevel is not supported for h.264",
11715 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 2 (main10)",
11725 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 1 (main) or 2 (main10)",
11736 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 1 (main) or 2 (main10)",
11743 ni_strncpy(p_param_warn, max_err_len,
"HEVC Main Profile does not support 10-bit, auto convert to 8-bit", max_err_len - 1);
11749 "spatialLayers is not supported for h.265 encode",
11756 ni_strncpy(p_param_err, max_err_len,
"disableAv1TimingInfo is not supported for h.265",
11763 ni_strncpy(p_param_err, max_err_len,
"av1OpLevel is not supported for h.265",
11773 ni_strncpy(p_param_err, max_err_len,
"TuneBframeVisual MEDIUM is not supported for AV1", max_err_len - 1);
11779 ni_strncpy(p_param_err, max_err_len,
"Invalid profile: must be 1 (main)",
11790 "AV1 level < 2.0 is not supported, change to level 2.0",
11797 "AV1 level > 6.3 is not supported, change to level 6.3",
11807 ni_strncpy(p_param_warn, max_err_len,
"confWinTop is not supported in AV1",
11815 ni_strncpy(p_param_warn, max_err_len,
"confWinBottom is not supported in AV1",
11823 ni_strncpy(p_param_warn, max_err_len,
"confWinLeft is not supported in AV1",
11831 ni_strncpy(p_param_warn, max_err_len,
"confWinRight is not supported in AV1",
11838 "masterDisplay not supported for AV1",
11844 ni_strncpy(p_param_err, max_err_len,
"hrdEnable is not supported on av1 encoder",
11851 ni_strncpy(p_param_err, max_err_len,
"enableAUD is not supported on av1 encoder",
11858 ni_strncpy(p_param_err, max_err_len,
"maxCLL is not supported on av1 encoder",
11865 ni_strncpy(p_param_err, max_err_len,
"repeatHeaders is not supported on av1 encoder",
11871 ni_strncpy(p_param_err, max_err_len,
"enableSSIM is not supported on av1 encoder",
11878 ni_strncpy(p_param_err, max_err_len,
"EnableRdoQuant is not supported on av1 encoder",
11885 ni_strncpy(p_param_err, max_err_len,
"fillerEnable is not supported on av1 encoder",
11892 ni_strncpy(p_param_err, max_err_len,
"ppsInitQp is not supported for av1 encoder",
11899 ni_strncpy(p_param_err, max_err_len,
"vbvBufferReencode is not supported for av1 multicoreJointMode", max_err_len - 1);
11907 ni_strncpy(p_param_err, max_err_len,
"crop Parameters not supported for JPEG", max_err_len - 1);
11913 ni_strncpy(p_param_err, max_err_len,
"Tier is not supported for JPEG", max_err_len - 1);
11919 ni_strncpy(p_param_err, max_err_len,
"TuneBframeVisual is not supported for JPEG", max_err_len - 1);
11926 "masterDisplay not supported for jpeg",
11932 ni_strncpy(p_param_err, max_err_len,
"confWinTop is not supported in jpeg",
11939 ni_strncpy(p_param_err, max_err_len,
"confWinBottom is not supported in jpeg",
11946 ni_strncpy(p_param_err, max_err_len,
"confWinLeft is not supported in jpeg",
11953 ni_strncpy(p_param_err, max_err_len,
"confWinRight is not supported in jpeg",
11960 ni_strncpy(p_param_err, max_err_len,
"hrdEnable is not supported on jpeg encoder",
11967 ni_strncpy(p_param_err, max_err_len,
"enableAUD is not supported on jpeg encoder",
11974 ni_strncpy(p_param_err, max_err_len,
"repeatHeaders is not supported on jpeg encoder",
11981 ni_strncpy(p_param_err, max_err_len,
"prefTRC is not supported on jpeg encoder",
11988 ni_strncpy(p_param_err, max_err_len,
"maxCLL is not supported on jpeg encoder",
11995 ni_strncpy(p_param_err, max_err_len,
"colorPri is not supported on jpeg encoder",
12002 ni_strncpy(p_param_err, max_err_len,
"colorTrc is not supported on jpeg encoder",
12009 ni_strncpy(p_param_err, max_err_len,
"colorSpc is not supported on jpeg encoder",
12016 ni_strncpy(p_param_err, max_err_len,
"sarNum is not supported on jpeg encoder",
12023 ni_strncpy(p_param_err, max_err_len,
"sarDenom is not supported on jpeg encoder",
12031 "videoFullRangeFlag is not supported on jpeg encoder",
12039 "temporalLayersEnable is not supported on jpeg encoder",
12047 "spatialLayers is not supported for jpeg encode",
12054 ni_strncpy(p_param_err, max_err_len,
"LowDelay is not supported on jpeg encoder",
12061 ni_strncpy(p_param_err, max_err_len,
"rdoLevel is not supported on jpeg encoder",
12068 ni_strncpy(p_param_err, max_err_len,
"EnableRdoQuant is not supported on jpeg encoder",
12076 "enable2PassGop is not supported on jpeg encoder",
12084 "lookAheadDepth is not supported on jpeg encoder",
12092 "gopPresetIdx is not supported on jpeg encoder",
12099 ni_strncpy(p_param_err, max_err_len,
"roiEnable is not supported on jpeg encoder",
12107 "RoiDemoMode is not supported on jpeg encoder",
12114 ni_strncpy(p_param_err, max_err_len,
"cacheRoi is not supported on jpeg encoder",
12122 "ReconfDemoMode is not supported on jpeg encoder",
12130 "intraRefreshMode is not supported on jpeg encoder",
12138 "intraRefreshArg is not supported on jpeg encoder",
12146 "intraPeriod is not supported on jpeg encoder",
12154 p_param_err, max_err_len,
12155 "IntraRefreshResetOnForceIDR is not supported on jpeg encoder",
12163 "longTermReferenceEnable is not supported on jpeg encoder",
12171 "longTermReferenceInterval is not supported on jpeg encoder",
12179 "longTermReferenceCount is not supported on jpeg encoder",
12187 "multicoreJointMode is not supported on jpeg encoder",
12194 ni_strncpy(p_param_err, max_err_len,
"enableSSIM is not supported on jpeg encoder",
12202 "vbvBufferSize is not supported on jpeg encoder",
12210 "fillerEnable is not supported on jpeg encoder",
12217 ni_strncpy(p_param_err, max_err_len,
"picSkip is not supported on jpeg encoder",
12224 ni_strncpy(p_param_err, max_err_len,
"maxFrameSize is not supported on jpeg encoder",
12232 "cuLevelRCEnable is not supported on jpeg encoder",
12239 ni_strncpy(p_param_err, max_err_len,
"hvsQPEnable is not supported on jpeg encoder",
12246 ni_strncpy(p_param_err, max_err_len,
"profile is not supported on jpeg encoder",
12253 ni_strncpy(p_param_err, max_err_len,
"intraRefreshMode or intraRefreshArg is not supported on jpeg encoder",
12258 if (p_cfg->
i8crf != -1)
12260 ni_strncpy(p_param_err, max_err_len,
"crf is not supported on jpeg encoder",
12267 ni_strncpy(p_param_err, max_err_len,
"tolCtbRcInter is not supported on jpeg encoder",
12274 ni_strncpy(p_param_err, max_err_len,
"tolCtbRcIntra is not supported on jpeg encoder",
12282 "rcQpDeltaRange is not supported on jpeg encoder",
12289 ni_strncpy(p_param_err, max_err_len,
"bitrateWindow is not supported on jpeg encoder",
12296 ni_strncpy(p_param_err, max_err_len,
"ctbRowQpStep is not supported on jpeg encoder",
12304 "enableAIEnhance is not supported on jpeg encoder",
12311 ni_strncpy(p_param_err, max_err_len,
"ppsInitQp is not supported for jpeg encoder",
12318 ni_strncpy(p_param_err, max_err_len,
"pass1Qp is not supported for jpeg encoder",
12325 ni_strncpy(p_param_err, max_err_len,
"bitrateMode is not supported for jpeg encoder",
12333 "vbvBufferReencode is not supported on jpeg encoder",
12341 "getPsnrMode or getReconstructedMode is not supported on jpeg encoder",
12349 "spatialLayers is not supported for Jpeg encode",
12356 ni_strncpy(p_param_err, max_err_len,
"disableAv1TimingInfo is not supported for Jpeg",
12363 ni_strncpy(p_param_err, max_err_len,
"av1OpLevel is not supported for Jpeg",
12372 ni_strncpy(p_param_err, max_err_len,
"Invalid forceFrameType: out of range",
12380 ni_strncpy(p_param_err, max_err_len,
"Invalid forcedHeaderEnable: out of range",
12389 ni_strncpy(p_param_err, max_err_len,
"Invalid decoding_refresh_type: out of range", max_err_len - 1);
12399 ni_strcpy(p_param_err, max_err_len,
"Invalid gop_preset_index: out of range");
12412 ni_strcpy(p_param_err, max_err_len,
"GOP size must be 1 when lowDelay is enabled");
12421 ni_strncpy(p_param_err, max_err_len,
"Invalid gopSize out of range", max_err_len - 1);
12429 ni_strncpy(p_param_err, max_err_len,
"GOP size must be <= 4 for low delay GOP", max_err_len - 1);
12438 ni_strncpy(p_param_err, max_err_len,
"Invalid LookAheadDepth: out of range. <[4-40]>", max_err_len - 1);
12444 ni_strncpy(p_param_err, max_err_len,
"2-pass encode does not support low delay GOP", max_err_len - 1);
12450 ni_strncpy(p_param_err, max_err_len,
"2-pass encode does not support tile4x4 format",
12457 ni_strncpy(p_param_err, max_err_len,
"currently do not support lookahead encode with multi spatial layers", max_err_len - 1);
12472 ni_strncpy(p_param_err, max_err_len,
"Custom GOP must not include backward prediction when lowDelay is enabled", max_err_len - 1);
12474 ni_strncpy(p_param_err, max_err_len,
"Custom GOP must not include backward prediction when picSkip is enabled", max_err_len - 1);
12487 ni_strncpy(p_param_err, max_err_len,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when lowDelay is enabled", max_err_len - 1);
12494 ni_strncpy(p_param_err, max_err_len,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when picSkip is enabled", max_err_len - 1);
12501 ni_strncpy(p_param_err, max_err_len,
"lookAheadDepth must be 0 when lowDelay is enabled", max_err_len - 1);
12503 ni_strncpy(p_param_err, max_err_len,
"lookAheadDepth must be 0 when picSkip is enabled", max_err_len - 1);
12512 "Cannot use multicoreJointMode when lowDelay is enabled",
12516 "Cannot use multicoreJointMode when picSkip is enabled",
12526 "Cannot enable minFramesDelay when lowDelay is enabled",
12530 "Cannot enable minFramesDelay when picSkip is enabled",
12547 ni_strncpy(p_param_err, max_err_len,
"Custom GOP size must be 1 when useLowDelayPocType is enabled", max_err_len - 1);
12553 ni_strncpy(p_param_err, max_err_len,
"Must use GOP with all frames as reference frames (gopPresetIdx 1,3,7,9) when useLowDelayPocType is enabled", max_err_len - 1);
12576 "minimum frame size %d bytes in low delay mode\n", __func__,
12582 "mode. Set it to half of the maximum frame size %d bytes\n",
12589 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: maxFrameSize %u is too small. Changed to minimum value (bitrate/framerate in byte): %u\n",
12598 ni_strncpy(p_param_err, max_err_len,
"maxFrameSize can only be used when lowDelay is enabled", max_err_len - 1);
12615 ni_strncpy(p_param_err, max_err_len,
"Custom GOP can not have B frames for intra refresh", max_err_len - 1);
12626 "Must use gopPresetIdx 9 (consecutive P frame) for intra refresh",
12631 ni_strncpy(p_param_warn, max_err_len,
"GOP size forced to 1 and low delay GOP force disabled (no B frames) for intra refresh", max_err_len - 1);
12639 "intra refresh cycle (height / intraRefreshArg MB or CTU) must > 1",
12646 ni_strncpy(p_param_err, max_err_len,
"lookaheadDepth must be 0 for intra refresh", max_err_len - 1);
12655 ni_strncpy(p_param_warn, max_err_len,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len - 1);
12664 ni_strncpy(p_param_warn, max_err_len,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len - 1);
12675 ni_strncpy(p_param_warn, max_err_len,
"HRD conformance is not guaranteed in multicoreJointMode", max_err_len - 1);
12684 snprintf(p_param_err, max_err_len,
"HRD conformance with multiple temporal layers is currently not supported");
12710 snprintf(p_param_err, max_err_len,
"vbvMaxRate %u cannot be smaller than bitrate %d",
12722 snprintf(p_param_err, max_err_len,
"vbvMinRate %u cannot be larger than bitrate %d",
12737 snprintf(p_param_err, max_err_len,
"vbvBufferSize must be greater than the average frame size. Minimum is %d msec for framerate %d fps",
12749 snprintf(p_param_warn, max_err_len,
"vbvBufferSize cannot be smaller than one frame size based on vbvMaxRate, force vbvBufferSize to %d msec for bitrate %d vbvMaxRate %u and framerate %d fps",
12761 snprintf(p_param_warn, max_err_len,
"vbvBufferSize cannot be smaller than one frame size based on vbvMinRate, force vbvBufferSize to %d msec for bitrate %d vbvMinRate %u and framerate %d fps",
12773 snprintf(p_param_warn, max_err_len,
"vbvMaxRate %u vbvMinRate %u does not take effect when vbvBufferSize is 0, force vbvMaxRate vbvMinRate to 0",
12786 "Can't enable ltrRefInterval and longTermReferenceEnable "
12797 ni_strncpy(p_param_err, max_err_len,
"Custom GOP size can not be > 1 for long term reference", max_err_len - 1);
12807 "Must use low delay GOP (gopPresetIdx 1,3,7,9) for long term reference",
12812 ni_strncpy(p_param_warn, max_err_len,
"GOP size forced to 1 for long term reference", max_err_len - 1);
12819 ni_strncpy(p_param_err, max_err_len,
"lookaheadDepth must be 0 for long term reference", max_err_len - 1);
12823 if (p_cfg->
i8crf >= 0)
12825 ni_strncpy(p_param_err, max_err_len,
"crf must < 0 for long term reference", max_err_len - 1);
12834 p_param_err, max_err_len,
12835 "Must set longTermReferenceEnable for longTermReferenceInterval",
12845 ni_strncpy(p_param_warn, max_err_len,
"AV1 err resilient mode forced to 0 when using other codecs", max_err_len - 1);
12855 ni_strncpy(p_param_warn, max_err_len,
"Motion Constrained mode force disabled for codecs other than HEVC", max_err_len - 1);
12864 p_param_err, max_err_len,
12865 "rdoLevel must be 1 for Motion Constrained mode 1 or 2",
12876 p_param_err, max_err_len,
12877 "multicoreJointMode must be 0 for Motion Constrained mode 2",
12888 p_param_err, max_err_len,
12889 "input resolution (or cropping window) must be 64x64 aligned for Motion Constrained mode 2",
12903 ni_strncpy(p_param_warn, max_err_len,
"AVCC HVCC forced to 0 for codecs other than AVC HEVC", max_err_len - 1);
12913 ni_strncpy(p_param_err, max_err_len,
"Invalid cu_size_mode: out of range", max_err_len - 1);
12923 ni_strncpy(p_param_err, max_err_len,
"Invalid use_recommend_enc_params: out of range", max_err_len - 1);
12941 ni_strncpy(p_param_err, max_err_len,
"Invalid max_num_merge: out of range", max_err_len - 1);
12955 ni_strncpy(p_param_err, max_err_len,
"Invalid intra_qp: out of range", max_err_len - 1);
12962 if (p_cfg->
i8crf >= 0 && p_cfg->
i8crf <= 51)
12969 ni_strncpy(p_param_err, max_err_len,
"CRF requres LookAheadDepth <[4-40]>", max_err_len - 1);
12977 ni_strncpy(p_param_warn, max_err_len,
"enable lookahead of current frame", max_err_len - 1);
12984 ni_strncpy(p_param_err, max_err_len,
"CRF requires RcEnable 0", max_err_len - 1);
12991 ni_strncpy(p_param_warn,
sizeof(p_param_warn),
"Lookahead with cuLevelRCEnable or hvsQPEnable may degrade quality", max_err_len - 1);
13002 ni_strncpy(p_param_err, max_err_len,
"tuneBframeVisual level 1 (medium) requires lookahead or crf encode", max_err_len - 1);
13012 ni_strncpy(p_param_err, max_err_len,
"Invalid enable_mb_level_rc: out of range", max_err_len - 1);
13021 ni_strncpy(p_param_err, max_err_len,
"Invalid min_qp: out of range", max_err_len - 1);
13029 ni_strncpy(p_param_err, max_err_len,
"Invalid max_qp: out of range", max_err_len - 1);
13037 ni_strncpy(p_param_err, max_err_len,
"Invalid enable_cu_level_rate_control: out of range", max_err_len - 1);
13047 ni_strncpy(p_param_err, max_err_len,
"Invalid enable_hvs_qp: out of range", max_err_len - 1);
13057 ni_strncpy(p_param_err, max_err_len,
"Invalid max_delta_qp: out of range", max_err_len - 1);
13066 ni_strncpy(p_param_err, max_err_len,
"Invalid i32vbvBufferSize: out of range", max_err_len - 1);
13089 ni_strncpy(p_param_err, max_err_len, p_param_warn, max_err_len - 1);
13093 free(p_param_warn);
13099 char *p_param_err, uint32_t max_err_len)
13102 int32_t low_delay = 0;
13103 int32_t intra_period_gop_step_size;
13106 if (!p_param || !p_src || !p_param_err)
13115 memset(p_param_err, 0, max_err_len - 1);
13149 intra_period_gop_step_size = 1;
13166 ni_strncpy(p_param_err, max_err_len,
"Invalid intra_period and gop_preset_index: gop structure is larger than intra period", max_err_len - 1);
13171 if (((!low_delay) && (p_param->
intra_period != 0) && ((p_param->
intra_period % intra_period_gop_step_size) != 0)) ||
13174 ni_strncpy(p_param_err, max_err_len,
"Invalid intra_period and gop_preset_index: intra period is not a multiple of gop structure size", max_err_len - 1);
13187 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len - 1);
13194 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: temporal_id is zero or negative", max_err_len - 1);
13199 if (min_poc > temp_poc[i])
13201 min_poc = temp_poc[i];
13209 if (temp_poc[j] == min_poc)
13218 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len - 1);
13234 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len - 1);
13241 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: temporal_id is negative", max_err_len - 1);
13250 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: ref pic delta cannot be 0", max_err_len - 1);
13261 ni_log(
NI_LOG_ERROR,
"g%drefPic%d specified without g%drefPic%dUsed specified!\n", i, j, i, j);
13268 if (min_poc > temp_poc[i])
13270 min_poc = temp_poc[i];
13278 if (temp_poc[j] == min_poc)
13287 ni_strncpy(p_param_err, max_err_len,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len - 1);
13305 if (((p_param->
cu_size_mode & 0x1) == 0) && ((align_8_width_flag != 0) || (align_8_height_flag != 0)))
13307 ni_strncpy(p_param_err, max_err_len,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be aligned with 8 pixels when enable CU8x8 of cu_size_mode. Recommend to set cu_size_mode |= 0x1 (CU8x8)", max_err_len - 1);
13311 else if (((p_param->
cu_size_mode & 0x1) == 0) && ((p_param->
cu_size_mode & 0x2) == 0) && ((align_16_width_flag != 0) || (align_16_height_flag != 0)))
13313 ni_strncpy(p_param_err, max_err_len,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be aligned with 16 pixels when enable CU16x16 of cu_size_mode. Recommend to set cu_size_mode |= 0x2 (CU16x16)", max_err_len - 1);
13317 else if (((p_param->
cu_size_mode & 0x1) == 0) && ((p_param->
cu_size_mode & 0x2) == 0) && ((p_param->
cu_size_mode & 0x4) == 0) && ((align_32_width_flag != 0) || (align_32_height_flag != 0)))
13319 ni_strncpy(p_param_err, max_err_len,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be aligned with 32 pixels when enable CU32x32 of cu_size_mode. Recommend to set cu_size_mode |= 0x4 (CU32x32)", max_err_len - 1);
13328 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_top: out of range", max_err_len - 1);
13334 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_top: not multiple of 2", max_err_len - 1);
13341 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_bottom: out of range", max_err_len - 1);
13347 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_bottom: not multiple of 2", max_err_len - 1);
13354 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_left: out of range", max_err_len - 1);
13360 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_left: not multiple of 2", max_err_len - 1);
13367 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_right: out of range", max_err_len - 1);
13373 ni_strncpy(p_param_err, max_err_len,
"Invalid conf_win_right: not multiple of 2", max_err_len - 1);
13387 if( (!p_cfg) || (!p_param_err) )
13397 memset(p_param_err, 0, max_err_len - 1);
13401 ni_strncpy(p_param_err, max_err_len,
"Invalid roiEnable: out of range", max_err_len - 1);
13408 ni_strncpy(p_param_err, max_err_len,
"hvsQPEnable and roiEnable: not mutually exclusive", max_err_len - 1);
13417 ni_strncpy(p_param_err, max_err_len,
"Invalid min_qp(P/B) and max_qp(P/B): min_qp cannot be larger than max_qp", max_err_len - 1);
13438 if (!p_encoder_params)
13567 ni_pthread_mutex_t *p_mutex;
13572 struct sched_param sched_param;
13578 sigfillset(&signal);
13589 if (((sched_param.sched_priority = sched_get_priority_max(SCHED_RR)) ==
13591 sched_setscheduler(syscall(SYS_gettid), SCHED_RR, &sched_param) < 0)
13597 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
13605 #elif defined(_WIN32)
13610 if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) ==
13621 char name[16] = {0};
13622 snprintf(name,
sizeof(name),
"%s%.2x%.4x",
"KAT", args->
hw_id, args->
session_id);
13624 prctl(PR_SET_NAME, name);
13626 pthread_setname_np(name);
13645 "%s creation timeout. session_id=0x%X requested timeout: %" PRIu64
13646 "ns, ping time delta: %" PRIu64
"ns\n ",
13698 "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u "
13699 "inst_err_no %u\n",
13712 "%s was possibly blocked. session_id=0x%X requested timeout: %" PRIu64
13713 "ns, ping time delta: %" PRIu64
"ns\n ",
13734 endtime += interval;
13779 void * p_buffer = NULL;
13780 uint32_t ui32LBA = 0;
13781 uint32_t modelled_load;
13855 "ERROR %s(): p_ctx->device_handle=%" PRIx64
13856 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
13864 "Uploader open session ID:0x%x,timestamp:%" PRIu64
"\n",
13868 uint64_t keep_alive_timeout =
13871 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
13873 keep_alive_timeout);
13884 "ERROR %s(): nvme write keep_alive_timeout command "
13885 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
13909 modelled_load >>= 10;
13914 memcpy(p_buffer, &modelled_load, 4);
13945 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
13946 "p_ctx->session_id=%d\n",
13951 #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OPEN_HARMONY__) && !defined(_ANDROID)
13955 retval = p2p_fill_pcie_address(p_ctx);
13979 if (!src_p_ctx || !dst_p_ctx)
13981 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null!, return\n", __func__);
13992 if (src_p_ctx->
isP2P)
13997 dst_p_ctx->
bus = src_p_ctx->
bus;
13998 dst_p_ctx->
dev = src_p_ctx->
dev;
13999 dst_p_ctx->
fn = src_p_ctx->
fn;
14022 int query_retry = 0;
14034 "Session=0x%x: %s buffered_frame_index=%d return %d\n",
14044 query_sleep(p_ctx);
14045 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: query by ni_query_instance_buf_info INST_BUF_INFO_RW_UPLOAD\n", __func__);
14056 if (query_retry >=500)
14059 "scaler write exceeded max query retries. rc=%d try=%d\n",
14060 retval, query_retry);
14082 "Session=0x%x: %s got FrameIndex=%u buffered_frame_index=%d\n",
14092 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
14114 uint32_t frame_size_bytes = 0;
14115 uint32_t retry_count = 0;
14134 abs_time_ns, p_frame->pts);
14145 query_sleep(p_ctx);
14154 if (retry_count >= 500)
14157 "hwupload write exceeded max query retries. rc=%d try=%d"
14159 retval, retry_count);
14183 "size %u >= frame size %u , retry %u\n",
14222 uint32_t sent_size = 0;
14223 uint32_t frame_size_bytes = 0;
14224 uint32_t retry_count = 0;
14233 if (!p_ctx || !p_frame)
14252 #ifdef MEASURE_LATENCY
14257 abs_time_ns, p_frame->
pts);
14281 query_sleep(p_ctx);
14290 if (retry_count >= 500)
14293 "hwupload write exceeded max query retries. rc=%d try=%d"
14295 retval, retry_count);
14316 "size %u >= frame size %u , retry %u\n",
14321 #ifdef XCODER_TIMESTAMP_DTS_ENABLED
14327 "ERROR %s(): ni_timestamp_register() for dts "
14340 if (separate_metadata)
14345 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): uploader separated metadata not supported on device with FW api version < 6.S\n",
14353 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): p_metadata_buffer is NULL, allocation failed?\n",
14363 if (separate_start)
14376 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
14377 "p_frame->video_width=%u, p_frame->video_height=%u, "
14378 "start_len [%u,%u,%u] inconsecutive_transfer %u\n",
14384 uint32_t ui32LBA_metadata =
14387 "%s: p_metadata_buffer = %p, metadata_buffer_size "
14388 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14412 if (separate_start)
14425 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
14426 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14454 "%s: p_data = %p, p_frame->buffer_size "
14455 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14462 if (separate_start)
14487 "%s: p_data = %p, p_frame->buffer_size = %u, "
14488 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14492 sent_size = frame_size_bytes;
14493 if (separate_start)
14521 size = frame_size_bytes;
14523 #ifdef XCODER_DUMP_DATA
14524 char dump_file[256];
14525 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-hwup-fme/fme-%04ld.yuv",
14538 #ifdef MEASURE_LATENCY
14577 int query_retry = 0;
14581 if (!p_ctx || !hwdesc)
14599 query_sleep(p_ctx);
14618 if (query_retry >= 1000)
14660 void* p_buffer = NULL;
14662 uint32_t ui32LBA = 0;
14687 NI_INVALID_DEVICE_HANDLE, p_buffer,
14716 uint64_t frame_offset = 0;
14717 uint32_t frame_dropped = 0;
14718 uint8_t *p_data_buffer = NULL;
14724 uint32_t total_bytes_to_read = 0;
14725 uint32_t total_yuv_met_size = 0;
14726 uint32_t read_size_bytes = 0;
14728 int query_retry = 0;
14729 uint32_t ui32LBA = 0;
14730 unsigned int bytes_read_so_far = 0;
14732 int low_delay_notify = 0;
14734 uint32_t frames_dropped = 0;
14736 uint8_t get_first_metadata = 0;
14737 uint8_t sequence_change = 0;
14741 if (!p_ctx || !p_frame)
14760 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
14765 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
14768 "Total bytes to read %u total_yuv_met_size %u, low_delay %u\n",
14789 query_sleep(p_ctx);
14798 &sessionStatistic);
14822 if (query_retry >= 1000)
14825 "\n", query_retry, retval);
14827 low_delay_notify = 1;
14842 "Dec read desc only hdr metadata is available. Seq change may "
14843 "have occured.\n");
14844 total_bytes_to_read = metadata_hdr_size;
14845 sequence_change = 1;
14849 ni_log2(p_ctx,
NI_LOG_TRACE,
"Dec read desc buf_size < frame_size. Retry %d\n", query_retry);
14855 "Dec read desc query, ready_to_close %u, query eos\n",
14870 "WARNING: Dec read desc query eos reached but exceeded max "
14871 "retries. is_flushed=%u try=%d.\n",
14876 "Dec read desc query eos reached. is_flushed=%u try=%d"
14881 low_delay_notify = 1;
14888 "Dec read desc available buf size == %d, query try %d, "
14902 query_retry < 1000 / 2)
14909 low_delay_signal(p_ctx);
14917 "size %u >= required size %u !\n",
14935 low_delay_signal(p_ctx);
14938 "input (B frames)? Just cancel the low delay mode then\n");
14941 low_delay_signal(p_ctx);
14951 if(query_retry <= 2000)
14960 "Warning: decoder pkt_num %u frame_num %u "
14961 "timeout, increasing pkt_delay_cnt to %u\n",
14968 "\n", query_retry, retval);
14984 "At least %d packets should be sent before reading the "
15001 "%ux%u frame-rate %u is_flushed %u\n",
15029 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
15030 p_data_buffer = (uint8_t*)p_frame->
p_buffer;
15040 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
15041 "%u cb len %u hdr %d\n",
15044 p_frame->
data_len[2], metadata_hdr_size);
15052 "ERROR %s() avaliable size(%u) less than "
15056 }
else if (total_bytes_to_read == metadata_hdr_size && !p_ctx->
frame_num)
15063 void *p_metadata_buffer = NULL;
15073 p_data_buffer = (uint8_t *)p_metadata_buffer;
15074 get_first_metadata = 1;
15075 sequence_change = 0;
15086 read_size_bytes = total_bytes_to_read;
15094 p_data_buffer, read_size_bytes, ui32LBA);
15103 }
else if (get_first_metadata) {
15111 get_first_metadata = 0;
15127 low_delay_notify = 1;
15130 p_data_buffer = (uint8_t *)p_frame->
p_buffer +
15132 memcpy(p_meta, p_data_buffer, metadata_hdr_size);
15137 metadata_hdr_size);
15169 "p_data3_1:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
15173 "p_data3_1: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
15178 "p_data3_2:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
15182 "p_data3_2: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
15187 "%s:sei_size=%d device_handle=%d == hw_id=%d "
15192 "%s: session=0x%x ui16FrameIdx=%u NodeAddress=0x%x, "
15193 "planar=%d bd=%d\n",
15208 total_bytes_to_read = total_bytes_to_read + sei_size;
15210 "%s decoder read desc success, retval %d "
15211 "total_bytes_to_read include sei %u sei_size %d\n",
15212 __func__, retval, total_bytes_to_read, sei_size);
15226 bytes_read_so_far = total_bytes_to_read;
15231 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset, &frame_dropped,
true);
15235 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset, 0,
true);
15251 "is cancelled due to has_b_frames, frame_num %u\n",
15262 int64_t tmp_dts, prev_dts = INT64_MIN, ts_diff = 0;
15271 "### %s(): Warning: ui32FramesDropped %u should be %u + %u\n",
15284 "%s(): First frame : session_id 0x%x, pic_reorder_delay: %d "
15285 "total frames input:%u buffered: %u completed: %u output: %u "
15286 "dropped: %u (%u %u) error: %u\n",
15306 "decoder dts queue %d %ld failed !\n",
15307 __func__, i, tmp_dts);
15312 "decoder dts queue %d %ld success !\n",
15313 __func__, i, tmp_dts);
15314 if (prev_dts != INT64_MIN) {
15315 ts_diff += llabs(tmp_dts - prev_dts);
15318 prev_dts = tmp_dts;
15323 ts_diff = ts_diff / nb_diff;
15327 "average diff: %ld\n", __func__, ts_diff);
15342 "decoder dts queue %d %ld failed !\n",
15343 __func__, i, tmp_dts);
15370 for (i = 0; (int)i < p_ctx->pic_reorder_delay; i++)
15377 if (p_frame->
pts >= p_frame->
dts &&
15378 p_frame->
pts - p_frame->
dts < 1000)
15394 "decoder dts queue %d %ld success !\n",
15395 __func__, i, p_frame->
dts);
15431 "%s: (found pts) dts %" PRId64
" pts "
15432 "%" PRId64
" frame_offset %" PRIu64
" j %d "
15433 "pkt_offsets_index_min %" PRIu64
" "
15434 "pkt_offsets_index %" PRIu64
" pkt_pos %" PRIu64
"\n",
15435 __func__, p_frame->
dts, p_frame->
pts, frame_offset, j,
15450 while (p_frame->
dts < p_frame->
pts &&
15451 llabs(p_frame->
pts - p_frame->
dts) > ts_diff)
15454 "dts %ld diff. %ld > ts_diff %ld\n",
15455 __func__, p_frame->
pts, p_frame->
dts,
15456 llabs(p_frame->
pts - p_frame->
dts), ts_diff);
15463 "pop decoder dts queue error.\n", __func__);
15486 "ERROR: Frame pts %" PRId64
" not found for offset "
15487 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
15489 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
15491 __func__, p_frame->
dts, p_frame->
pts);
15504 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
15512 __func__, p_frame->
pts);
15525 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: ppu reconfig done. ppu_reconfig_pkt_pos = %u, frame_num = %u droped = %u\n",
15529 #ifdef MEASURE_LATENCY
15540 "%s(): p_frame->start_of_stream=%u, "
15541 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
15542 "p_frame->video_height=%u\n",
15551 "Decoder pts queue size = %d dts queue size = %d\n\n",
15558 #ifdef MEASURE_LATENCY
15563 ni_log2(p_ctx,
NI_LOG_INFO,
"DTS:%" PRId64
",DELTA:%" PRId64
",dLAT:%" PRIu64
";\n",
15574 if (get_first_metadata && p_data_buffer)
15576 if (sequence_change && p_ctx->
frame_num)
15590 low_delay_signal(p_ctx);
15597 if (low_delay_notify)
15599 low_delay_signal(p_ctx);
15617 uint64_t frame_offset = 0;
15618 uint8_t *p_data_buffer;
15621 uint32_t total_bytes_to_read = 0;
15622 uint32_t read_size_bytes = 0;
15623 uint32_t ui32LBA = 0;
15632 if ((!p_ctx) || (!p_frame))
15647 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
15649 if (!p_frame->
p_data[0] || !p_data_buffer)
15671 "ERROR %s(): NI_PIXEL_PLANAR_FORMAT_TILED4X4 not supported in download.\n",
15678 unsigned int bytes_read_so_far = 0;
15681 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Total bytes to download %u, start offset = %u, chunkOffset "
15682 "%u, minorOffset %u\n",
15684 output_chunk_offset, output_minor_offset);
15686 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
15687 "%u cb len %u hdr %d\n",
15690 p_frame->
data_len[2], metadata_hdr_size);
15709 "Config HW download read desc success, retval %d total_bytes_to_read %u\n",
15710 retval, total_bytes_to_read);
15713 read_size_bytes = total_bytes_to_read;
15715 ui32LBA += output_chunk_offset;
15723 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
15735 "HW download read desc success, retval %d total_bytes_to_read %u\n",
15736 retval, total_bytes_to_read);
15753 "Unconfig HW download read desc success, retval %d total_bytes_to_read %u\n",
15754 retval, total_bytes_to_read);
15757 bytes_read_so_far = total_bytes_to_read;
15762 rx_size = (int)bytes_read_so_far;
15766 ni_create_frame(p_frame, bytes_read_so_far, &frame_offset, 0,
false);
15771 __func__, rx_size);
15773 "%s(): p_frame->start_of_stream=%u, "
15774 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
15775 "p_frame->video_height=%u\n",
15779 "%s(): p_ctx->frame_num %" PRIu64
", "
15780 "p_frame->data_len[0/1/2]=%u/%u/%u\n",
15809 uint64_t frame_offset = 0;
15810 uint8_t *p_data_buffer;
15813 uint32_t total_bytes_to_read = 0;
15814 uint32_t read_size_bytes = 0;
15815 uint32_t ui32LBA = 0;
15817 const char *error_flag =
"NetintQuadraErr";
15821 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
15823 if (!p_frame->
p_data[0] || !p_data_buffer || 0 == p_frame->
data_len[0])
15825 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null or p_frame->data_len is 0.\n",
15837 "ERROR %s(): Unsupported format %d for hw download.\n",
15844 unsigned int bytes_read_so_far = 0;
15849 "%u cb len %u hdr %d\n",
15850 total_bytes_to_read,
15852 p_frame->
data_len[2], metadata_hdr_size);
15857 memcpy(global_state->
error_flag, error_flag, strlen(error_flag)+1);
15861 read_size_bytes = total_bytes_to_read;
15863 ui32LBA += output_chunk_offset;
15869 "%u, minorOffset %u hwdesc->ui16FrameIdx %d ui32LBA 0x%x\n",
15871 output_chunk_offset, output_minor_offset, hwdesc->
ui16FrameIdx, ui32LBA);
15875 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
15884 if (!strcmp(global_state->
error_flag, error_flag) &&
15888 "size %u + offset %u out of range\n",
15889 __func__, hwdesc->
ui16FrameIdx, read_size_bytes, output_chunk_offset);
15894 bytes_read_so_far = total_bytes_to_read;
15899 rx_size = (int)bytes_read_so_far;
15903 ni_create_frame(p_frame, bytes_read_so_far, &frame_offset, 0,
false);
15907 "HW download read desc success, retval %d total_bytes_to_read %u\n",
15908 retval, total_bytes_to_read);
15927 uint8_t *p_data = NULL;
15929 uint32_t ui32LBA = 0;
15950 memset(p_data, 0, dataLen);
15952 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s(): ui16DstIdx %u, ui16SrcIdx %u, size %u, offset %u\n", __func__,
15958 p_data, dataLen, ui32LBA);
16015 uint32_t pool_size,
16018 void* p_uploader_config = NULL;
16022 uint32_t ui32LBA = 0;
16050 memset(p_uploader_config, 0, buffer_size);
16072 ni_log2(p_ctx,
NI_LOG_DEBUG,
"ni_config_instance_set_uploader_params():%d x %d x Format %d with %d framepool\n",
16080 p_uploader_config, buffer_size, ui32LBA);
16119 void* p_decoder_config = NULL;
16122 uint32_t ui32LBA = 0;
16143 ni_log2(p_ctx,
NI_LOG_INFO,
"%s() FW rev %s < 6rT-- load balancing might be affected\n", __func__,
16155 memset(p_decoder_config, 0, buffer_size);
16208 p_decoder_config, buffer_size, ui32LBA);
16241 void *p_dec_ppu_config,
int buffer_size)
16243 void* p_ppu_config = NULL;
16245 uint32_t tmp_buffer_size = buffer_size;
16247 uint32_t ui32LBA = 0;
16251 if (!p_ctx || !p_dec_ppu_config)
16271 ni_log2(p_ctx,
NI_LOG_INFO,
"%s() FW rev %s < 6rT-- load balancing might be affected\n", __func__,
16283 memset(p_ppu_config, 0, tmp_buffer_size);
16285 memcpy(p_ppu_config, p_dec_ppu_config, buffer_size);
16290 p_ppu_config, tmp_buffer_size, ui32LBA);
16335 int query_retry = 0;
16337 if (!p_ctx || !p_frame || !p_frame->
p_data[3])
16371 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: query by ni_query_instance_buf_info INST_BUF_INFO_RW_UPLOAD\n",
16382 if (query_retry >= 1000)
16405 if (query_retry >= 1000)
16416 "Session=0x%x: %s got FrameIndex=%u\n",
16432 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
16514 uint32_t *p_offset)
16526 "FrameIdx %d OOR (%d,%d]. DDR config %d \n", __func__, hwdesc->
ui16FrameIdx,
16541 void *nb_data, uint32_t nb_size)
16543 void *p_ai_config = NULL;
16544 void *p_nb_data = NULL;
16545 uint32_t buffer_size;
16549 uint32_t ui32LBA = 0;
16550 uint32_t config_size;
16551 void *p_buffer = NULL;
16554 int retry_count = 0;
16565 if (!nb_data || nb_size == 0) {
16567 __func__, nb_data, nb_size);
16590 ((
ni_ai_config_t *)p_ai_config)->ui32NetworkBinarySize = nb_size;
16603 memcpy(p_nb_data, nb_data, nb_size);
16611 p_ai_config, config_size, ui32LBA);
16617 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16618 ", hw_id, %u, xcoder_inst_id: %d\n",
16625 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16626 ", hw_id, %u, xcoder_inst_id: %d\n",
16647 memset(p_buffer, 0, dataLen);
16660 p_buffer, dataLen, ui32LBA);
16692 "AI write query failed or buf_size %u < "
16698 "Info ai write query success, available buf "
16699 "size %u >= frame size %u !\n",
16723 p_nb_data, buffer_size, ui32LBA);
16730 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16731 ", hw_id, %u, xcoder_inst_id: %d\n",
16738 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16739 ", hw_id, %u, xcoder_inst_id: %d\n",
16751 for (transferred = 0; transferred < buffer_size; transferred += this_size)
16755 (buffer_size - transferred);
16757 if (this_size & (4096 - 1))
16759 this_size = (this_size + (4096 - 1)) & ~(4096 - 1);
16763 (transferred >> 12);
16765 "%s(): write nb LBA 0x%x, this_size %u, page_offset %u\n",
16766 __func__, ui32LBA, this_size, (transferred >> 12));
16767 p_data = (uint8_t *)p_nb_data + transferred;
16770 (uint8_t *)p_nb_data + transferred, this_size, ui32LBA);
16778 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16779 ", hw_id, %u, xcoder_inst_id: %d\n",
16787 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16788 ", hw_id, %u, xcoder_inst_id: %d\n",
16814 void *p_stream_info = NULL;
16815 void *p_ai_config = NULL;
16816 void *p_nb_data = NULL;
16818 uint32_t ui32LBA = 0;
16819 uint32_t config_size;
16858 "### %s: width %d %d height %d model type %d level %d pix_format %d\n", __func__,
16869 p_stream_info, config_size, ui32LBA);
16875 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16876 ", hw_id, %u, xcoder_inst_id: %d\n",
16883 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16884 ", hw_id, %u, xcoder_inst_id: %d\n",
16908 void *p_buffer = NULL;
16909 uint32_t ui32LBA = 0;
16910 int retry_count = 0;
16921 memset(p_buffer, 0, dataLen);
16926 p_buffer, dataLen, ui32LBA);
16964 uint32_t ui32LBA = 0;
16966 uint32_t frame_size_bytes;
16967 uint32_t sent_size = 0;
16968 int32_t query_retry = 0;
16974 if (!p_ctx || !p_frame)
17001 frame_size_bytes = p_frame->
data_len[0];
17012 "Info ai write query success, available buf "
17013 "size %u >= frame size %u !\n",
17040 "AI write query failed or buf_size < frame_size. Retry %d\n",
17046 "AI write query exceeded max retries: %d\n",
17063 if (!p_frame->
iovec) {
17080 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Ai session write: p_data = %p, p_frame->buffer_size = %u, "
17081 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
17085 sent_size = frame_size_bytes;
17093 p_data, sent_size, ui32LBA);
17122 uint32_t rel_offset = 0;
17123 int32_t iovec_index = 0;
17124 int32_t iovec_left;
17126 if (!p_frame->
iovec) {
17132 for (i = 0; i < p_frame->
iovec_num; i++) {
17136 this_iovec->
ptr, this_iovec->
size);
17137 if ((this_iovec->
ptr == NULL) || (this_iovec->
size == 0) ||
17140 (int64_t)this_iovec->
ptr, this_iovec->
size);
17155 memset(buffer_info, 0x00, dataLen);
17161 uint32_t rel_lba = 0;
17166 for (i = 0; (int)i < iovec_batch; i++) {
17172 rel_offset += iovec->
size;
17182 buffer_info, dataLen, ui32LBA);
17190 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
17191 ", hw_id, %u, xcoder_inst_id: %d\n",
17200 for (i = 0; (int)i < iovec_batch; i++) {
17205 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
17218 for (i = 0; (int)i < iovec_batch; i++) {
17222 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
17229 iovec->
ptr, sent_size, ui32LBA);
17238 iovec_index += iovec_batch;
17239 iovec_left -= iovec_batch;
17240 }
while (iovec_left);
17271 retval = frame_size_bytes;
17287 uint32_t actual_read_size = 0;
17289 uint32_t ui32LBA = 0;
17294 if (!p_ctx || !p_packet || !p_packet->
p_data)
17319 "Info ai read query success, available buf "
17320 "size %u >= frame size %u !\n",
17343 "Info ai read query rc %d, available buf size %u, "
17344 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
17365 actual_read_size = p_packet->
data_len;
17373 p_packet->
p_data, actual_read_size, ui32LBA);
17423 void *p_buffer = NULL;
17424 void *p_info = NULL;
17426 uint32_t ui32LBA = 0;
17428 int32_t query_retry = 0;
17431 uint32_t buffer_size;
17432 uint32_t this_size;
17434 uint32_t total_io_num;
17438 if (!p_ctx || !p_network)
17450 "ERROR: %s(): network parameters data is already initialized\n",
17476 memset(p_buffer, 0, dataLen);
17492 p_buffer, dataLen, ui32LBA);
17508 if (query_retry > 50000)
17511 __func__, query_retry - 1);
17556 if (!network_data->
inset)
17579 memset(p_info, 0, dataLen);
17583 p_info, dataLen, ui32LBA);
17584 if ((int32_t)retval < 0)
17606 memset(p_info, 0, dataLen);
17610 p_info, dataLen, ui32LBA);
17611 if ((int32_t)retval < 0)
17621 for (l = 0, network_data->
input_num = 0; l < 4; l++)
17631 for (l = 0, network_data->
output_num = 0; l < 4; l++)
17642 for (l = 0, buffer_size = 0; l < network_data->
input_num; l++)
17649 buffer_size += this_size;
17653 "%s(): network input layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
17659 for (l = 0, buffer_size = 0; l < network_data->
output_num; l++)
17666 buffer_size += this_size;
17670 "%s(): network output layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
17685 ni_unreference_network_data(network_data);
17696 void *p_buffer = NULL;
17697 uint32_t ui32LBA = 0;
17777 "ERROR %s(): p_ctx->device_handle=%" PRIx64
17778 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
17795 "%s(): p_ctx->device_handle=%" PRIx64
17796 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
17801 uint64_t keep_alive_timeout =
17804 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
17806 keep_alive_timeout);
17818 "ERROR %s(): nvme write keep_alive_timeout command "
17819 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
17830 "ERROR %s(): Unable to allocate network_data memory\n");
17845 if (!p_ctx->
iocbs) {
17852 p_ctx->
iocbs[i] = (ni_iocb_t *)malloc(
sizeof(ni_iocb_t));
17853 if (!p_ctx->
iocbs[i]) {
17887 void *p_buffer = NULL;
17888 uint32_t ui32LBA = 0;
17924 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
17925 "p_ctx->session_id=%d, close_mode=1\n",
17970 if (p_ctx->
iocbs) {
18009 void *p_read_data = NULL;
18011 uint32_t ui32LBA = 0;
18028 int32_t query_retry = 0;
18036 "Info ai write query success, available buf "
18053 "AI write query failed or buf_size < frame_size. Retry %d\n",
18059 "AI write query exceeded max retries: %d\n",
18082 memset(p_data, 0x00, dataLen);
18088 for(
int i = 0; i < numInCfgs; i++){
18100 p_data, dataLen, ui32LBA);
18108 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
18109 ", hw_id, %u, xcoder_inst_id: %d\n",
18120 if (p_read_data != NULL)
18132 void *p_read_data = NULL;
18134 uint32_t ui32LBA = 0;
18155 "Error: %s function not supported on device with FW API version < 6rL\n",
18162 int query_retry = 0;
18173 memset(p_read_data, 0, dataLen);
18181 p_read_data, dataLen, ui32LBA);
18205 if (query_retry > 2000)
18208 __func__, query_retry - 1);
18226 if (p_read_data != NULL)
18234 int height,
int options,
int pool_size,
18239 void *p_read_data = NULL;
18241 uint32_t ui32LBA = 0;
18261 int query_retry = 0;
18272 memset(p_read_data, 0, dataLen);
18280 p_read_data, dataLen, ui32LBA);
18297 if (query_retry > 2000)
18300 __func__, query_retry - 1);
18318 int32_t query_retry = 0;
18326 "Info ai write query success, available buf "
18343 "AI write query failed or buf_size < frame_size. Retry %d\n",
18349 "AI write query exceeded max retries: %d\n",
18372 memset(p_data, 0x00, dataLen);
18387 p_data, dataLen, ui32LBA);
18395 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
18396 ", hw_id, %u, xcoder_inst_id: %d\n",
18408 if (p_read_data != NULL)
18431 int retry_count = 0;
18458 if (retry_count >= 500)
18484 if (retry_count >= 500)
18521 void *p_buffer = NULL;
18524 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
18530 if (NI_INVALID_DEVICE_HANDLE == device_handle)
18605 uint8_t ddr_priority_mode)
18607 void *p_buffer = NULL;
18616 ddr_priority_mode);
18618 if (NI_INVALID_DEVICE_HANDLE == device_handle)
18637 p_cfg->
ddr_mode = ddr_priority_mode;
18642 ddr_priority_mode);
18670 void *metadata_buffer = NULL;
18673 if ((!p_frame) || (extra_len <= 0))
18676 "ERROR: %s passed parameters are null or not supported, "
18677 "p_frame %p, extra_len %d",
18678 __func__, p_frame, extra_len);
18682 int buffer_size = extra_len;
18694 "%s: free current p_frame metadata buffer, "
18695 "p_frame->buffer_size=%u\n",
18708 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
18715 memset(metadata_buffer, 0, buffer_size);
18726 "%s: success: p_frame->p_metadata_buffer %p "
18727 "p_frame->metadata_buffer_size=%u\n",
18756 void *start_buffer = NULL;
18762 "ERROR: %s passed parameters are null or not supported, "
18764 __func__, p_frame);
18775 "ERROR %d: %s() Cannot allocate start buffer.\n",
18793 "%s: success: p_frame->p_start_buffer %p "
18794 "p_frame->start_buffer_size=%u\n",
18811 void *p_buffer = NULL;
18813 uint32_t ui32LBA = 0;
18816 if (!p_ctx || !p_metrics)
18819 "ERROR: %s() passed parameters are null!, return\n", __func__);
18843 p_buffer, dataLen, ui32LBA);
18886 uint32_t *u32_buf = (uint32_t *)buf;
18888 u32_buf[1] = value;
18901 CoreName = (
char *)
"all";
18904 CoreName = (
char *)
"np";
18907 CoreName = (
char *)
"ep";
18910 CoreName = (
char *)
"dp";
18913 CoreName = (
char *)
"tp";
18916 CoreName = (
char *)
"fp";
18919 CoreName = (
char *)
"Not Found";
18959 char *core_name = NULL;
18960 FILE *p_file = NULL;
18963 if (!p_ctx || !p_data)
18966 __func__, __LINE__, p_ctx, p_data);
18971 *(uint8_t *)p_data = 0x55;
18977 __func__, __LINE__, core_id);
18988 __func__, __LINE__, rc, core_name);
18990 else if (gen_log_file)
18993 char filename[32] =
"raw_";
18997 bool pcie_id_name =
false;
18998 char devFilePath[1024] = {0};
18999 char devFDPath[1024] = {0};
19000 char pcie[64] = {0};
19001 char domain[5] = {0}, slot[3] = {0}, dev[3] = {0}, func[2] = {0};
19003 snprintf(devFDPath,
sizeof(devFDPath),
"/proc/self/fd/%d", p_ctx->
blk_io_handle);
19004 ssize_t len = readlink(devFDPath, devFilePath,
sizeof(devFilePath)-1);
19006 devFilePath[len] =
'\0';
19008 if (strstr(devFilePath,
"/dev/nvme") != NULL)
19011 if (strlen(pcie) > 0 && strlen(slot) > 0 && strlen(domain) > 0)
19016 pcie_id_name =
true;
19021 ni_log2(p_ctx,
NI_LOG_INFO,
"%s:():%d: For dev %d can't look up PCI domain and slot info. Defaulting to slot=hw_id and domain=0000\n",
19024 snprintf(num, 4,
"%d", p_ctx->
hw_id);
19033 snprintf(num, 4,
"%02x", p_ctx->
hw_id);
19040 ni_fopen(&p_file, filename,
"wb");
19044 if (fwrite((uint8_t *)p_data ,
19045 data_len, 1, p_file) != 1)
19048 __func__, __LINE__, data_len);
19052 if (fflush(p_file))
19063 __func__, __LINE__, filename);
19075 if (!p_ctx || !p_data)
19078 __func__, __LINE__, p_ctx, p_data);
19093 uint64_t ui64DestAddr,
19094 uint32_t ui32FrameSize)
19096 void *p_buffer = NULL;
19112 p_data = (uint8_t *) p_buffer;
19115 memcpy(p_data, &ui64DestAddr,
sizeof(uint64_t));
19116 memcpy(p_data + 8, &ui32FrameSize,
sizeof(uint32_t));
19117 memcpy(p_data + 12, &source->
ui16FrameIdx,
sizeof(uint16_t));
19119 memcpy(p_data + 18, &ui16Direction,
sizeof(uint16_t));
19124 NI_INVALID_DEVICE_HANDLE, p_buffer,
19136 if (p_buffer != NULL)
19146 void *p_buffer = NULL;
19148 uint32_t ui32LBA = 0;
19152 uint32_t ui32Dummy = 0;
19174 p_data = (uint8_t *) p_buffer;
19178 memcpy(p_data + 8, &ui32Dummy, 4);
19181 memcpy(p_data + 18, &ui16Direction, 2);
19186 memcpy(&p_data[24] + (i*8), &dmaAddrs->
ui64DMAAddr[i], 8);
19208 if (p_buffer != NULL)
19228 #if defined(__linux__) && defined(XCODER_ENABLE_CPU_AFFINITY)
19230 if (numa_available() == -1) {
19248 #if defined(LIBNUMA_API_VERSION) && (LIBNUMA_API_VERSION == 2)
19249 struct bitmask *node_mask = numa_allocate_nodemask();
19256 numa_bitmask_setbit(node_mask, numa_node);
19257 numa_bind(node_mask);
19258 numa_bitmask_free(node_mask);
19260 nodemask_t node_mask;
19261 nodemask_zero(&node_mask);
19262 nodemask_set(&node_mask, numa_node);
19263 numa_bind(&node_mask);