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__)
82 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},
83 {8, 0, -1, -1, -1, 2, 4, -1, -1, 8, 1, -1, -1, -1, -1, -1, -1}};
84 #define MAGIC_P2P_VALUE "p2p"
85 #define AI_MODEL_TYPE_HVSPLUS_FILTER 3
101 0x00, 0x00, 0x00, 0x01,
119 0x00, 0x00, 0x00, 0x01,
135 0x00, 0x00, 0x00, 0x01,
151 0x00, 0x00, 0x00, 0x01,
169 #define NI_XCODER_FAILURES_MAX 25
170 #define DP_IPC_PASSTHRU 0xFFFFFFFF
173 #ifdef XCODER_SELF_KILL_ERR
174 #undef XCODER_SELF_KILL_ERR
181 for (i = 0; i < bytes; i += 2)
183 uint8_t val = buf[i];
191 uint32_t i, words = (bytes + 1) / 2;
193 for (i = 0; i < words; i += 2)
195 uint16_t val = buf[i];
203 uint32_t i, words = (bytes + 3) / 4;
204 for (i = 0; i < words; i += 2)
206 uint32_t val = buf[i];
214 uint64_t i, words = (bytes + 7) / 8;
215 for (i = 0; i < words; i += 2)
217 uint64_t val = buf[i];
223 static void memcpyToPelByBits (uint8_t *dst_u8, uint8_t *src,
int width,
int height,
int dst_stride,
int src_stride,
int srcValidBitsDepth)
226 uint8_t bitsDepth = srcValidBitsDepth;
227 uint32_t mask = (1<<bitsDepth)-1;
228 uint16_t *dst = (uint16_t *)dst_u8;
233 for (j = 0; j < height; j ++)
235 for (i = 0; i< width; i ++)
236 dst_u8[i] = src[i] & 0xff;
239 dst_u8 += dst_stride;
245 for (j = 0; j < height; j ++)
247 uint8_t *src_line = src;
248 uint32_t cache = 0, cache_bits = 0;
249 for (i = 0; i< width; i ++)
251 while(cache_bits < bitsDepth)
253 cache |= ((*src_line++) << cache_bits);
257 if (cache_bits >= bitsDepth)
259 dst[i] = cache & mask;
261 cache_bits -= bitsDepth;
286 static void trace_recon_tile2raster_y(FILE *fRecon, uint8_t *mem,
int width,
int height,
287 int leftOffset,
int topOffset,
288 int src_stride,
int pixDepth, uint8_t *luma_mem_temp)
291 int write_data_len = 0;
292 int bytesPerPix = (pixDepth == 8 ? 1 : 2);
293 uint8_t *tmp_mem = (uint8_t *)malloc(bytesPerPix*src_stride);
294 int num_tiles = (leftOffset + width + 3) / 4 - leftOffset/4;
297 mem += topOffset/4*4*src_stride + leftOffset/4*16*pixDepth/8;
298 for(i = topOffset/4*4; i < topOffset + height; i += 4) {
299 memcpyToPelByBits(tmp_mem, mem, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
300 if(i >= topOffset && i < topOffset + height){
302 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
303 write_data_len += width * bytesPerPix;
305 memcpyToPelByBits(tmp_mem, mem+4*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
306 if(i+1 >= topOffset && i+1 < topOffset + height)
309 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
310 write_data_len += width * bytesPerPix;
312 memcpyToPelByBits(tmp_mem, mem+8*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
313 if(i+2 >= topOffset && i+2 < topOffset + height)
316 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
317 write_data_len += width * bytesPerPix;
319 memcpyToPelByBits(tmp_mem, mem+12*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
320 if(i+3 >= topOffset && i+3 < topOffset + height)
323 memcpy(luma_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
324 write_data_len += width * bytesPerPix;
331 static void trace_recon_tile2raster_uv(FILE *fRecon, uint8_t *mem_uv,
int width,
int height,
332 int leftOffset,
int topOffset,
333 int src_stride,
int pixDepth, uint8_t *ch_mem_temp)
336 int bytesPerPix = (pixDepth == 8 ? 1 : 2);
337 uint8_t *tmp_mem = (uint8_t *)malloc(bytesPerPix*src_stride*2);
338 int num_tiles = 2*((leftOffset + width + 3) / 4 - leftOffset/4);
343 int write_data_len = 0;
344 memset(tmp_mem, 0x00, bytesPerPix * src_stride * 2);
345 for(uv = 0; uv <= 1; uv ++) {
346 mem = mem_uv + topOffset/4*8*src_stride + leftOffset/4*32*pixDepth/8;
347 for(i = topOffset/4*4; i < topOffset + height; i += 4) {
348 if(i >= topOffset && i < topOffset + height) {
349 memcpyToPelByBits(tmp_mem, mem, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
350 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
352 tmp_mem[k] = tmp_mem[j];
354 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
357 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
358 write_data_len += width * bytesPerPix;
360 if(i+1 >= topOffset && i+1 < topOffset + height) {
361 memcpyToPelByBits(tmp_mem, mem+4*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
362 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
364 tmp_mem[k] = tmp_mem[j];
366 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
369 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
370 write_data_len += width * bytesPerPix;
372 if(i+2 >= topOffset && i+2 < topOffset + height) {
373 memcpyToPelByBits(tmp_mem, mem+8*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
374 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
376 tmp_mem[k] = tmp_mem[j];
378 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
381 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
382 write_data_len += width * bytesPerPix;
384 memcpyToPelByBits(tmp_mem, mem+12*pixDepth/8, 4, num_tiles, 4, 16*pixDepth/8, pixDepth);
385 if(i+3 >= topOffset && i+3 < topOffset + height) {
386 for(j = uv, k = 0; j < 4 * num_tiles; j += 2, k++) {
388 tmp_mem[k] = tmp_mem[j];
390 ((uint16_t*)tmp_mem)[k] = ((uint16_t*)tmp_mem)[j];
393 memcpy(ch_mem_temp + write_data_len, tmp_mem + (leftOffset & 3) * bytesPerPix, width * bytesPerPix);
394 write_data_len += width * bytesPerPix;
402 static double calc_noise(uint8_t *p1, uint8_t *p2,
int size)
409 for (i = 0; i < size; i++)
411 diff = p1[i] - p2[i];
456 FILE *fout_raster = NULL;
474 uint8_t *luma_mem_temp = NULL;
475 uint8_t *ch_mem_temp = NULL;
488 luma_mem_temp = (uint8_t *)malloc(luma_size);
489 memset(luma_mem_temp, 0x00, luma_size);
494 ch_mem_temp = (uint8_t *)malloc(ch_size);
495 memset(ch_mem_temp, 0x00, ch_size);
503 SwapSW16((uint16_t *)luma_mem, lum_sz);
504 SwapSW32((uint32_t *)luma_mem, lum_sz);
505 SwapSW64((uint64_t *)luma_mem, lum_sz);
506 trace_recon_tile2raster_y (fout_raster, luma_mem, width, height,
517 SwapSW16((uint16_t *)ch_mem, chr_sz);
518 SwapSW32((uint32_t *)ch_mem, chr_sz);
519 SwapSW64((uint64_t *)ch_mem, chr_sz);
520 trace_recon_tile2raster_uv(fout_raster, ch_mem, width / 2, height / 2,
539 double noise_y = 0.0, noise_u = 0.0, noise_v = 0.0, noise_yuv = 0.0;
540 double power_y = 0.0, power_u = 0.0, power_v = 0.0, power_yuv = 0.0;
541 double psnr_y = 0.0, psnr_u = 0.0, psnr_v = 0.0, psnr_yuv = 0.0;
551 power_y = 1.0 * max * max * width * height;
552 power_u = power_y / 4.0;
553 power_v = power_y / 4.0;
554 power_yuv = power_y * 3.0 / 2.0;
556 uint8_t *p_y_src_buf = NULL;
557 uint8_t *p_u_src_buf = NULL;
558 uint8_t *p_v_src_buf = NULL;
559 for (
int i = 0; i < 120; i++)
574 if (p_y_src_buf != NULL)
578 noise_y = calc_noise(p_y_src_buf, luma_mem_temp, width * height);
582 noise_y = power_y / pow(10, p_ctx->
psnr_y / 10);
587 noise_u = calc_noise(p_u_src_buf, ch_mem_temp, (width / 2) * (height / 2));
588 noise_v = calc_noise(p_v_src_buf, ch_mem_temp + (width / 2) * (height / 2), (width / 2) * (height / 2));
590 noise_yuv = noise_y + noise_u + noise_v;
594 noise_y = noise_y < 1 ? 1 : noise_y;
595 noise_u = noise_u < 1 ? 1 : noise_u;
596 noise_v = noise_v < 1 ? 1 : noise_v;
597 noise_yuv = noise_yuv < 1 ? 1 : noise_yuv;
601 psnr_y = 10 * log10(power_y / noise_y);
610 psnr_u = 10 * log10(power_u / noise_u);
611 psnr_v = 10 * log10(power_v / noise_v);
613 psnr_yuv = 10 * log10(power_yuv / noise_yuv);
641 luma_mem_temp = NULL;
667 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",
680 uint16_t ui16ErrorCount = 0;
681 uint32_t ui32LastErrorStatus = 0;
703 else if(opt ==
OPT_2){
713 ui16ErrorCount > 0 && !retval &&
719 else if(opt ==
OPT_3)
728 "Persistent failures detected, %s() line-%d: session_no 0x%x "
729 "sess_err_count %u inst_err_no %u\n",
730 func, line, *(inst_id), ui16ErrorCount,
731 ui32LastErrorStatus);
732 #ifdef XCODER_SELF_KILL_ERR
735 kill(getpid(), SIGTERM);
747 #define CHECK_ERR_RC(ctx, rc, info, opcode, type, hw_id, inst_id, opt) \
749 (rc) = check_err_rc(ctx, rc, info, opcode, type, hw_id, inst_id, opt, __func__, __LINE__); \
750 if((rc) && ((opt) != OPT_3)) LRETURN; \
753 #define CHECK_VPU_RECOVERY(ret) \
755 if (NI_RETCODE_NVME_SC_VPU_RECOVERY == (ret)) \
757 ni_log(NI_LOG_ERROR, "Error, vpu reset.\n"); \
758 (ret) = NI_RETCODE_ERROR_VPU_RECOVERY; \
768 "decoder" :
"encoder";
772 uint64_t abs_time_ns;
779 ts.tv_sec = abs_time_ns / 1000000000LL;
780 ts.tv_nsec = abs_time_ns % 1000000000LL;
790 if (ret == ETIMEDOUT)
802 "decoder" :
"encoder";
832 #elif __linux__ || __APPLE__
834 char dir_name[128] = {0};
835 char file_name[512] = {0};
838 struct dirent *stream_folder;
839 int curr_stream_idx = 0;
840 int earliest_stream_idx = 0;
841 int max_exist_idx = 0;
842 time_t earliest_time = 0;
843 struct stat file_stat;
847 if (!p_device_context)
854 flock(p_device_context->lock, LOCK_EX);
857 if (0 != access(dir_name, F_OK))
859 if (0 != mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO))
869 if (NULL == (dir = opendir(dir_name)))
878 while ((stream_folder = readdir(dir)))
880 if (!strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
883 atoi(&(stream_folder->d_name[strlen(
"stream")]));
884 if (curr_stream_idx > 0)
886 if (curr_stream_idx > max_exist_idx)
888 max_exist_idx = curr_stream_idx;
903 curr_stream_idx = max_exist_idx + 1;
907 while ((stream_folder = readdir(dir)))
911 if (!strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
913 snprintf(file_name,
sizeof(file_name),
"%s/%s/pkt-0001.bin",
914 dir_name, stream_folder->d_name);
917 atoi(&(stream_folder->d_name[strlen(
"stream")]));
919 if (curr_stream_idx > 0 && 0 == access(file_name, F_OK))
922 if (stat(file_name, &file_stat))
929 if (0 == earliest_stream_idx ||
930 file_stat.st_mtime < earliest_time)
932 earliest_stream_idx = curr_stream_idx;
933 earliest_time = file_stat.st_mtime;
940 curr_stream_idx = earliest_stream_idx;
944 snprintf(file_name,
sizeof(file_name),
"%s/stream%03d/pkt-0001.bin",
945 dir_name, curr_stream_idx);
946 if (utime(file_name, NULL))
955 "%s/stream%03d", dir_name, curr_stream_idx);
974 flock(p_device_context->lock, LOCK_UN);
977 snprintf(file_name,
sizeof(file_name),
"%s/process_session_id.txt",
980 fp = fopen(file_name,
"wb");
983 char number[64] = {
'\0'};
985 snprintf(number,
sizeof(number),
"proc id: %ld\nsession id: %u\n",
987 fwrite(number, strlen(number), 1, fp);
1009 char *dom, *bus, *dev, *fnc;
1018 p_ctx->
netint_fd = open(
"/dev/netint", O_RDWR);
1026 if (stat(p_dev, &bstat) < 0)
1032 if ((bstat.st_mode & S_IFMT) != S_IFBLK)
1039 ret = snprintf(syspath,
sizeof(syspath) - 1,
1040 "/sys/block/%s/device/address",
1042 syspath[ret] =
'\0';
1044 fp = fopen(syspath,
"r");
1046 ret = snprintf(syspath,
sizeof(syspath) - 1,
1047 "udevadm info -q path -n %s | perl -nle'print $& "
1048 "while m{(?<=/)[0-9a-f]{4}:[0-9a-f]{2}:[0-9a-f]{2}\\.[0-9a-f]}g' | tail -n 1",
1050 syspath[ret] =
'\0';
1052 fp = popen(syspath,
"r");
1061 if (fgets(line, 256, fp) == NULL)
1079 p_ctx->
domain = strtoul(line, &dom, 16);
1087 p_ctx->
bus = strtoul(dom + 1, &bus, 16);
1095 p_ctx->
dev = strtoul(bus + 1, &dev, 16);
1104 p_ctx->
fn = strtoul(dev + 1, &fnc, 16);
1113 p_ctx->
bus, p_ctx->
dev, p_ctx->
fn);
1120 #if __linux__ || __APPLE__
1121 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
1122 #ifndef DISABLE_BACKTRACE_PRINT
1123 void ni_print_backtrace() {
1124 void* callstack[128];
1125 int frames = backtrace(callstack, 128);
1126 char** strs = backtrace_symbols(callstack, frames);
1129 for (
int i = 0; i < frames; ++i) {
1150 void* p_buffer = NULL;
1151 uint32_t ui32LBA = 0;
1152 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
1195 "ERROR %d: %s() alloc decoder all zero buffer failed\n",
1236 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1245 uint64_t keep_alive_timeout =
1248 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
1250 keep_alive_timeout);
1261 "ERROR %s(): nvme write keep_alive_timeout command "
1262 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1278 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
1289 "ERROR %s(): nvme write sw_version command "
1290 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1313 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1321 "%s(): p_ctx->device_handle=0x%" PRIx64
", p_ctx->hw_id=%d, "
1322 "p_ctx->session_id=%d\n",
1385 ni_log2(p_ctx,
NI_LOG_INFO,
"Warn %s(): forceLowDelay is not available for fw < 6r3\n",
1396 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1397 "p_ctx->session_id=%d\n",
1403 decoder_dump_dir_open(p_ctx);
1406 #ifdef XCODER_DUMP_DATA
1407 char dir_name[256] = {0};
1409 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-dec-fme", (
long)getpid(),
1411 DIR *dir = opendir(dir_name);
1414 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
1440 uint32_t ui32LBA = 0;
1451 if (NI_INVALID_DEVICE_HANDLE == device_handle)
1464 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1470 "SUCCESS %s(): device_handle=%" PRIx64
" , "
1471 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1582 void* p_buffer = NULL;
1583 uint32_t ui32LBA = 0;
1615 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1616 "buffered: %u completed: %u output: %u dropped: %u error: %u corrupted: %u\n",
1627 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1628 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
1675 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1676 "p_ctx->session_id=%d, close_mode=1\n",
1745 low_delay_signal(p_ctx);
1762 uint32_t sent_size = 0;
1763 uint32_t packet_size = 0;
1764 int current_pkt_size;
1769 int query_retry = 0;
1770 uint32_t ui32LBA = 0;
1774 if ((!p_ctx) || (!p_packet))
1791 low_delay_wait(p_ctx);
1793 #ifdef MEASURE_LATENCY
1798 abs_time_ns, p_packet->
dts);
1804 current_pkt_size = packet_size;
1807 int max_retry = 200;
1885 "Warning: dec write query fail rc %d or available buf size %u < "
1886 "pkt size %u , retry: %d max_retry_fail_count %d\n",
1889 if (query_retry > max_retry ||
1898 if (query_retry > max_retry)
1917 "size %u >= pkt size %u !\n",
1960 "%s() had data to send: packet_size=%u, "
1961 "p_packet->sent_size=%d, p_packet->data_len=%u, "
1962 "p_packet->start_of_stream=%u, p_packet->end_of_stream=%u, "
1963 "p_packet->video_width=%u, p_packet->video_height=%u\n",
1968 uint8_t *p_data = (uint8_t *)p_packet->
p_data;
1979 p_data, packet_size, ui32LBA);
1999 char dump_file[512] = {0};
2002 snprintf(dump_file,
sizeof(dump_file),
"%s/pkt-%04ld.bin",
2004 FILE *f = fopen(dump_file,
"wb");
2007 fwrite(p_packet->
p_data, sent_size, 1, f);
2048 "%s: (first packet) pkt_index %d i %u "
2049 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2050 " pts_offsets %" PRId64
"\n",
2062 "%s: pkt_index %d i %u pkt_offsets_index_min "
2063 "%" PRIu64
" pkt_offsets_index %" PRIu64
" pts_offsets %" PRId64
2076 "%s: (wrap) pkt_index %d i %u "
2077 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2078 " pts_offsets %" PRId64
"\n",
2101 "Error %s: failed to allocate custom SEI buffer for pkt.\n",
2117 "ERROR %s(): ni_timestamp_register() for dts returned %d\n",
2127 "%s(): exit: packets: %" PRIu64
" offset %" PRIx64
""
2128 " sent_size = %u, status=%d\n",
2129 __func__, p_ctx->
pkt_num, (uint64_t)p_packet->
pos, sent_size,
2135 "ERROR %s(): exit: returnErr: %d, p_ctx->status: %d\n", __func__,
2141 static int64_t guess_correct_pts(
ni_session_context_t* p_ctx, int64_t reordered_pts, int64_t dts)
2149 "%s: pts_correction_last_dts %" PRId64
" "
2150 "pts_correction_num_faulty_dts %d\n",
2165 "%s: pts_correction_last_pts %" PRId64
" "
2166 "pts_correction_num_faulty_pts %d\n",
2179 pts = reordered_pts;
2191 pts = reordered_pts;
2199 static int rotated_array_binary_search(uint64_t *lefts, uint64_t *rights,
2200 int32_t size, uint64_t target)
2206 int mid = lo + (hi - lo) / 2;
2207 if (lefts[mid] <= target && target < rights[mid])
2212 if (rights[mid] == 0)
2219 if (rights[lo] <= rights[mid])
2221 if (lefts[lo] <= target && target < lefts[mid])
2232 if (rights[mid] <= target && target < rights[hi])
2258 uint64_t frame_offset = 0;
2259 uint8_t *p_data_buffer = NULL;
2265 uint32_t total_bytes_to_read = 0;
2266 uint32_t read_size_bytes = 0;
2271 int query_retry = 0;
2272 uint32_t ui32LBA = 0;
2273 unsigned int bytes_read_so_far = 0;
2275 int low_delay_notify = 0;
2276 uint32_t frames_dropped = 0;
2277 uint8_t get_first_metadata = 0;
2278 uint8_t sequence_change = 0;
2282 if ((!p_ctx) || (!p_frame))
2300 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
2305 p_frame->
data_len[2] + metadata_hdr_size;
2356 ni_log2(p_ctx,
NI_LOG_TRACE,
"Warning: dec read query fail rc %d retry %d max_retry_fail_count %d\n",
2359 if (query_retry >= 1000)
2362 low_delay_notify = 1;
2379 total_bytes_to_read = metadata_hdr_size;
2380 sequence_change = 1;
2403 "WARNING: Dec eos reached but also exceeded max dec read query "
2404 "retries. is_flushed=%u try=%d.\n",
2409 "Dec eos reached. is_flushed=%u try=%d.\n",
2413 low_delay_notify = 1;
2419 " retrying ..\n", query_retry);
2433 query_retry < 1000 / 2)
2440 low_delay_signal(p_ctx);
2448 "size %u >= required size %u !\n",
2465 low_delay_signal(p_ctx);
2468 "Warning: ceased using low delay decoding mode after "
2469 "excessively long decoder read query.\n");
2472 low_delay_signal(p_ctx);
2482 if(query_retry <= 2000)
2491 "Warning: decoder pkt_num %u frame_num %u "
2492 "timeout, increasing pkt_delay_cnt to %u\n",
2516 "At least %d packets should be sent before reading the "
2533 "%ux%u frame-rate %u is_flushed %u\n",
2567 #ifdef XCODER_SELF_KILL_ERR
2572 kill(getpid(), SIGTERM);
2589 p_frame->
data_len[2] + metadata_hdr_size;
2590 p_data_buffer = (uint8_t*) p_frame->
p_buffer;
2602 "%u cb len %u hdr %d\n",
2605 p_frame->
data_len[2], metadata_hdr_size);
2611 "ERROR %s() avaliable size(%u)"
2612 "less than needed (%u)\n",
2624 void *p_metadata_buffer = NULL;
2630 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
2635 p_data_buffer = (uint8_t *)p_metadata_buffer;
2636 get_first_metadata = 1;
2638 sequence_change = 0;
2659 p_data_buffer, read_size_bytes, ui32LBA);
2668 }
else if (get_first_metadata) {
2676 get_first_metadata = 0;
2690 low_delay_notify = 1;
2703 total_bytes_to_read = total_bytes_to_read + sei_size;
2705 "include sei %u sei_size %d\n",
2706 retval, total_bytes_to_read, sei_size);
2709 bytes_read_so_far = total_bytes_to_read ;
2713 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset,
false);
2728 "is cancelled due to has_b_frames, frame_num %u\n",
2739 int64_t tmp_dts, prev_dts = INT64_MIN, ts_diff = 0;
2748 "%s(): First frame : session_id 0x%x, pic_reorder_delay: %d "
2749 "total frames input:%u buffered: %u completed: %u output: %u "
2750 "dropped: %u error: %u\n",
2769 "decoder dts queue %d %ld failed !\n",
2770 __func__, i, tmp_dts);
2775 "decoder dts queue %d %ld success !\n",
2776 __func__, i, tmp_dts);
2777 if (prev_dts != INT64_MIN) {
2778 ts_diff += labs(tmp_dts - prev_dts);
2786 ts_diff = ts_diff / nb_diff;
2790 "average diff: %ld\n", __func__, ts_diff);
2805 "decoder dts queue %d %ld failed !\n",
2806 __func__, i, tmp_dts);
2840 if (p_frame->
pts >= p_frame->
dts &&
2841 p_frame->
pts - p_frame->
dts < 1000)
2857 "decoder dts queue %d %ld success !\n",
2858 __func__, i, p_frame->
dts);
2893 "%s: (found pts) dts %" PRId64
" pts "
2894 "%" PRId64
" frame_offset %" PRIu64
" i %d "
2895 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index "
2896 "%" PRIu64
" pkt_pos %" PRIu64
" \n",
2897 __func__, p_frame->
dts, p_frame->
pts, frame_offset, i,
2912 while (p_frame->
dts < p_frame->
pts &&
2913 labs(p_frame->
pts - p_frame->
dts) > ts_diff)
2916 "dts %ld diff. %ld > ts_diff %ld\n",
2917 __func__, p_frame->
pts, p_frame->
dts,
2918 labs(p_frame->
pts - p_frame->
dts), ts_diff);
2925 "pop decoder dts queue error.\n", __func__);
2948 "ERROR: Frame pts %" PRId64
" not found for offset "
2949 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
2951 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
2953 __func__, p_frame->
dts, p_frame->
pts);
2965 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
2973 __func__, p_frame->
pts);
2983 #ifdef MEASURE_LATENCY
2990 #ifdef XCODER_DUMP_DATA
2991 char dump_file[256];
2992 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-dec-fme/fme-%04ld.yuv",
2994 FILE *f = fopen(dump_file,
"wb");
3005 "%s(): p_frame->start_of_stream=%u, "
3006 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
3007 "p_frame->video_height=%u\n",
3016 "Decoder pts queue size = %u dts queue size = %u\n\n",
3023 #ifdef MEASURE_LATENCY
3039 if (get_first_metadata && p_data_buffer)
3041 if (sequence_change && p_ctx->
frame_num)
3056 low_delay_signal(p_ctx);
3062 if (low_delay_notify)
3064 low_delay_signal(p_ctx);
3084 device_type, g_device_type_str[device_type]);
3107 switch (device_type)
3129 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 "
3130 "total_contexts:%u fw_video_mem_usage:%u "
3131 "fw_video_shared_mem_usage:%u fw_share_mem_usage:%u "
3132 "fw_p2p_mem_usage:%u active_hwuploaders:%u\n", __func__,
3148 "Overall load %u, model load %u, instance count %u\n",
3175 device_type, g_device_type_str[device_type]);
3206 void *p_buffer = NULL;
3208 uint32_t ui32LBA = 0;
3209 uint32_t max_cu_size;
3210 uint32_t block_size;
3211 int32_t width, height;
3212 int m_threshold = 0;
3213 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
3231 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() RGBA / BGRA / ARGB / AGBR resolution invalid, return\n",
3250 width = (width / 8) * 8;
3251 height = (height / 8) * 8;
3255 ((width + max_cu_size - 1) & (~(max_cu_size - 1))) *
3256 ((height + max_cu_size - 1) & (~(max_cu_size - 1))) /
3258 p_ctx->
roi_len = ((block_size + 63) & (~63));
3336 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3337 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3348 uint64_t keep_alive_timeout =
3351 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
3353 keep_alive_timeout);
3364 "ERROR %s(): nvme write keep_alive_timeout command "
3365 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3381 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
3392 "ERROR %s(): nvme write sw_version command "
3393 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3433 ni_log2(p_ctx,
NI_LOG_ERROR,
"The bit depth or resoultion is not supported on ai enhance mode\n");
3447 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3448 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3483 if (m_threshold > 4 * 1024 * 1024 *
sizeof(
long))
3486 "DEFAULT_MMAP_THRESHOLD_MAX, use default value (%d)\n",
3487 m_threshold, 4 * 1024 * 1024 *
sizeof(
long));
3488 m_threshold = 4 * 1024 * 1024 *
sizeof(long);
3493 #if defined(__linux__) && !defined(_ANDROID) && !defined(__OPENHARMONY__)
3497 if (mallopt(M_MMAP_THRESHOLD, m_threshold) == 0)
3510 if (mallopt(M_TRIM_THRESHOLD, 3 * m_threshold) == 0)
3519 "Warning: this platform does not support staticMmapThreshold\n");
3526 m_threshold = (int) (m_threshold * 1.25);
3527 void *temp_buf = malloc((
size_t) m_threshold);
3528 ni_log2(p_ctx,
NI_LOG_TRACE,
"trigger a pre-mature increase in mmap&trim threshold: 0x%p = malloc(%d)\n",
3529 temp_buf, m_threshold);
3536 bool device_in_ctxt =
true;
3552 for (uint8_t ui8Index = 0; ui8Index < 20; ui8Index++)
3575 "p_ctx->sender_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3584 "p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3590 if ((sender_vf_ns_id.
ns_id != curr_vf_ns_id.
ns_id) ||
3591 (sender_vf_ns_id.
vf_id != curr_vf_ns_id.
vf_id))
3608 "p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3619 "ERROR: ni_ai_query_network_ready returned %d\n", retval);
3652 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d return %d\n", __func__, __LINE__, retval);
3668 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3669 "p_ctx->session_id=%d\n",
3673 #ifdef XCODER_DUMP_DATA
3674 char dir_name[256] = {0};
3675 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-pkt", (
long)getpid(),
3677 DIR *dir = opendir(dir_name);
3680 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3688 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-fme", (
long)getpid(),
3690 dir = opendir(dir_name);
3693 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3764 void* p_buffer = NULL;
3765 uint32_t ui32LBA = 0;
3790 "Encoder_complete_info:session_id 0x%x, total frames input:%u "
3791 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
3831 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3832 "p_ctx->session_id=%d, close_mode=1\n",
3900 for (i = 0; i < 120 ; i++)
3914 low_delay_signal(p_ctx);
3925 int32_t width_stride[4] = {0};
3926 int32_t height_stride[4] = {0};
3941 width_stride, height_stride);
3944 for (
int i = 0; i < 120; i++)
3965 for (
int j = 0; j < source_height; j++)
3968 ni_frame->
p_data[0] + j * width_stride[0],
3971 for (
int j = 0; j < (source_height + 1) / 2; j++)
3974 ni_frame->
p_data[1] + j * width_stride[1],
3977 for (
int j = 0; j < (source_height + 1) / 2; j++)
3980 ni_frame->
p_data[2] + j * width_stride[2],
3996 for (
int j = 0; j < source_height; j++)
3999 ni_frame->
p_data[0] + j * width_stride[0],
4002 for (
int j = 0; j < (source_height + 1) / 2; j++)
4005 ni_frame->
p_data[1] + j * width_stride[1],
4008 for (
int j = 0; j < (source_height + 1) / 2; j++)
4011 ni_frame->
p_data[2] + j * width_stride[2],
4034 bool ishwframe =
false;
4036 uint32_t send_count = 0;
4038 uint32_t sent_size = 0;
4039 uint32_t frame_size_bytes = 0;
4044 if (!p_ctx || !p_frame)
4063 if (!((input_frame_idx > 0 &&
4069 __func__, input_frame_idx);
4088 low_delay_wait(p_ctx);
4090 #ifdef MEASURE_LATENCY
4117 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: passed video_height and video_width are not valid!, return\n");
4129 "%s: data_len[0] %u data_len[1] %u "
4130 "data_len[2] %u extra_data_len %u frame_size_bytes %u\n",
4164 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d retrun %d\n", __func__, __LINE__, retval);
4171 "Enc write query retry %d. rc=%d. Available buf size %u < "
4172 "frame size %u\n", retval, send_count,
4176 int retval_backup = retval;
4189 "Enc write query buf info exceeded max retries: "
4190 "%d, rc=%d. Available buf size %u < frame size %u\n",
4204 "Info enc write query success, available buf "
4205 "size %u >= frame size %u !\n",
4214 if (separate_metadata)
4220 p_frame->
p_data[2 + ishwframe] +
4235 "use_cur_src_as_long_term_pic %d use_long_term_ref %d\n",
4250 "%s(): ctx->force_frame_type"
4251 " %d frame->force_key_frame %d force frame_num %" PRIu64
""
4293 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
4294 "p_frame->start_of_stream=%u, p_frame->end_of_stream=%u, "
4295 "p_frame->video_width=%u, p_frame->video_height=%u, pts=0x%08x 0x%08x, "
4296 "dts=0x%08x 0x%08x, sei_len=%u, roi size=%u avg_qp=%u reconf_len=%u "
4297 "force_pic_qp=%u use_cur_src_as_long_term_pic %u use_long_term_ref "
4298 "%u start_len [%u,%u,%u] inconsecutive_transfer %u "
4299 "get_recon_frame_mode %u\n",
4303 (uint32_t)(p_frame->
pts & 0xFFFFFFFF),
4304 (uint32_t)((p_frame->
dts >> 32) & 0xFFFFFFFF),
4351 "ni_timestamp_register() for dts returned: %d\n",
4355 if (separate_metadata)
4357 uint32_t ui32LBA_metadata =
4360 "%s: p_metadata_buffer = %p, metadata_buffer_size "
4361 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4390 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
4391 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4419 "%s: p_data = %p, p_frame->buffer_size "
4420 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4452 "%s: p_data = %p, p_frame->buffer_size "
4453 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4457 sent_size = frame_size_bytes;
4458 if (separate_metadata)
4491 int ret =
hwdl_frame(p_ctx, &hwdl_session_data, p_frame,
4512 "%s(): session=0x%x ui16FrameIdx=%u\n",
4520 size = frame_size_bytes;
4523 #ifdef XCODER_DUMP_DATA
4524 char dump_file[256];
4525 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-fme/fme-%04ld.yuv",
4528 FILE *f = fopen(dump_file,
"wb");
4551 uint32_t actual_read_size = 0;
4552 uint32_t to_read_size = 0;
4554 static long long encq_count = 0LL;
4556 int query_retry = 0;
4558 uint32_t ui32LBA = 0;
4563 int low_delay_notify = 0;
4566 if (!p_ctx || !p_packet || !p_packet->
p_data)
4586 ni_log2(p_ctx,
NI_LOG_DEBUG,
"frame_num=%" PRIu64
", pkt_num=%" PRIu64
", av1_pkt_num=%" PRIu64
"\n",
4599 low_delay_notify = 1;
4631 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: initial_frame_delay %d max_frame_delay %d ui8AdditionalFramesDelay %u current_frame_delay %d\n",
4645 "Info enc read query rc %d, available buf size %u, "
4646 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
4683 "%" PRIu64
" >= %" PRIu64
" pkt_num, keep querying p_ctx->status %d\n",
4691 low_delay_notify = 1;
4708 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",
4709 __FUNCTION__, p_ctx->
frame_num, pkt_num,
4739 actual_read_size = to_read_size;
4752 "ERROR %s(): packet buffer size %u allocation "
4754 __func__, actual_read_size);
4761 p_packet->
p_data, actual_read_size, ui32LBA);
4783 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s MetaDataSize %d FrameType %d AvgFrameQp %d ssim %d %d %d\n",
4801 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",
4825 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",
4835 if (p_meta->
ssimY != 0)
4843 #ifdef NI_LOG_SSIM_AT_INFO
4848 "%s: pkt #%" PRId64
" pts %" PRId64
" ssim "
4849 "Y %.4f U %.4f V %.4f\n", __FUNCTION__, p_ctx->
pkt_num,
4850 p_packet->
pts, (
float)p_meta->
ssimY/10000,
4851 (float)p_meta->
ssimU/10000, (
float)p_meta->
ssimV/10000);
4896 low_delay_notify = 1;
4901 #ifdef MEASURE_LATENCY
4908 #ifdef XCODER_DUMP_DATA
4909 char dump_file[256];
4910 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-pkt/pkt-%04ld.bin",
4913 FILE *f = fopen(dump_file,
"wb");
4923 "%s(): %d.%u p_packet->start_of_stream=%u, "
4924 "p_packet->end_of_stream=%u, p_packet->video_width=%u, "
4925 "p_packet->video_height=%u, p_packet->dts=0x%08x 0x%08x, "
4926 "p_packet->pts=0x%08x 0x%08x, type=%u, avg_frame_qp=%u, show_frame=%d\n",
4929 (uint32_t)((p_packet->
dts >> 32) & 0xFFFFFFFF),
4930 (uint32_t)(p_packet->
dts & 0xFFFFFFFF),
4931 (uint32_t)((p_packet->
pts >> 32) & 0xFFFFFFFF),
4932 (uint32_t)(p_packet->
pts & 0xFFFFFFFF), p_packet->
frame_type,
4938 if (encq_count % 500 == 0)
4941 "Encoder pts queue size = %u dts queue size = %u\n\n",
4947 #ifdef MEASURE_LATENCY
4967 if (low_delay_notify)
4969 low_delay_signal(p_ctx);
4993 p_ctx->
last_gop_size = g_map_preset_to_gopsize[lookAheadEnable][gop_preset_index + 1];
5005 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): config encoder sequence change command failed\n",
5030 void* p_buffer = NULL;
5031 uint32_t ui32LBA = 0;
5032 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
5047 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use stack filter on device with FW API version < 6.4\n");
5057 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use rotate filter on device with FW API version < 6.7\n");
5067 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use in-place overlay filter on device with FW API version < 6.L\n");
5134 "ERROR %s(): p_ctx->device_handle=%" PRIx64
5135 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5143 "%s(): p_ctx->device_handle=%" PRIx64
5144 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5149 uint64_t keep_alive_timeout =
5152 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
5154 keep_alive_timeout);
5165 "ERROR %s(): nvme write keep_alive_timeout command "
5166 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5182 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
5193 "ERROR %s(): nvme write sw_version command "
5194 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5213 retval = p2p_fill_pcie_address(p_ctx);
5240 void * p_buffer = NULL;
5241 uint32_t ui32LBA = 0;
5275 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
5276 "p_ctx->session_id=%d, close_mode=1\n",
5328 void *p_scaler_config = NULL;
5332 uint32_t ui32LBA = 0;
5336 if (!p_ctx || !p_params)
5362 memset(p_scaler_config, 0, buffer_size);
5383 "on device with FW API version < 6s1\n", __func__);
5389 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5390 "hw_id, %d, xcoder_inst_id: %d\n",
5403 "be in [0 , 1]. scaler_params_b is %lf, scaler_params_c is %lf\n",
5410 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5411 "hw_id, %d, xcoder_inst_id: %d\n",
5425 p_scaler_config, buffer_size, ui32LBA);
5426 if ((int32_t)retval < 0)
5429 "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
5430 ", hw_id, %d, xcoder_inst_id: %d\n",
5437 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5438 "hw_id, %d, xcoder_inst_id: %d\n",
5483 int rectangle_width,
5484 int rectangle_height,
5493 uint32_t ui32LBA = 0;
5494 uint32_t query_retry = 0;
5499 dataLen = dataLen & 0xFFFFF000;
5516 if (rgba_color == 0)
5523 "WARNING: Allocate framepool size 0 for session 0x%x\n", p_ctx->
session_id);
5529 "ERROR: %s() try to free session 0x%x framepool while it's not allocated\n",
5540 "ERROR: %s() try to free session 0x%x framepool of type %u while "
5541 "passing type %u\n",
5556 "ERROR: allocate framepool multiple times for session 0x%x "
5557 "not supported in FW API version < 6r3\n",
5564 "Expand frame pool of scaler 0x%x with %u more frames\n",
5570 "ERROR: try to expand session 0x%x framepool with type %u "
5571 "while pool type is %u\n",
5586 memset(p_data, 0x00, dataLen);
5588 p_data->picture_width = width;
5589 p_data->picture_height = height;
5590 p_data->picture_format = format;
5591 p_data->options = options;
5592 p_data->rectangle_width = rectangle_width;
5593 p_data->rectangle_height = rectangle_height;
5594 p_data->rectangle_x = rectangle_x;
5595 p_data->rectangle_y = rectangle_y;
5596 p_data->rgba_color = rgba_color;
5597 p_data->frame_index = frame_index;
5608 p_data->frame_index = frame_index;
5615 p_data->rgba_color = 0;
5645 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", width, height, format);
5650 "Session=0x%x: Dev alloc frame: FrameIndex=%d; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5652 p_data->picture_width, p_data->picture_height,
5653 p_data->picture_format, p_data->rectangle_width,
5654 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5664 p_data, dataLen, ui32LBA);
5691 "ERROR: ni_nvme_send_admin_cmd failed: "
5692 "blk_io_handle: %" PRIx64
", hw_id, %u, xcoder_inst_id: %d\n",
5721 uint32_t ui32LBA = 0;
5726 dataLen = dataLen & 0xFFFFF000;
5728 if (!p_ctx || !p_cfg)
5747 memset(p_data, 0x00, dataLen);
5752 p_data->options = p_cfg->
options;
5771 p_data->orientation = 3;
5774 p_data->orientation = 1;
5786 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);
5792 "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",
5794 p_data->picture_width, p_data->picture_height,
5795 p_data->picture_format, p_data->rectangle_width,
5796 p_data->rectangle_height, p_data->rectangle_x,
5797 p_data->rectangle_y, p_data->orientation);
5803 p_data, dataLen, ui32LBA);
5809 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
5810 ", hw_id, %u, xcoder_inst_id: %d\n",
5814 "ERROR ni_scaler_config(): nvme command failed!\n");
5845 uint32_t ui32LBA = 0;
5851 dataLen = dataLen & 0xFFFFF000;
5853 if (!p_ctx || (!p_cfg_in && numInCfgs))
5872 memset(p_data, 0x00, dataLen);
5874 p_data_orig = p_data;
5876 for (i = 0; i < numInCfgs; i++)
5893 "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",
5895 p_data->frame_index, p_data->session_id,
5896 p_data->picture_width, p_data->picture_height,
5897 p_data->picture_format, p_data->rectangle_width,
5898 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5918 "Session=0x%x: Dev out config frame: FrameIndex=%u; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5920 p_data->picture_width, p_data->picture_height,
5921 p_data->picture_format, p_data->rectangle_width,
5922 p_data->rectangle_height, p_data->rectangle_x,
5923 p_data->rectangle_y);
5927 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);
5936 p_data_orig, dataLen, ui32LBA);
5942 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
5943 ", hw_id, %u, xcoder_inst_id: %d\n",
5947 "ERROR ni_scaler_config(): nvme command failed!\n");
5969 void* p_buffer = NULL;
5971 uint32_t ui32LBA = 0;
5976 if ((!p_ctx) || (!p_gen_status))
5987 __func__, device_type);
6002 memset(p_buffer, 0, dataLen);
6015 p_gen_status->fw_model_load, p_gen_status->cmd_queue_count,
6016 p_gen_status->process_load_percent);
6037 void* p_buffer = NULL;
6039 uint32_t ui32LBA = 0;
6040 uint32_t dataLen = 0;
6041 uint32_t copyLen = 0;
6062 if ((!p_ctx) || (!p_detail_status))
6073 __func__, device_type);
6086 memset(p_buffer, 0, dataLen);
6096 memcpy(p_detail_status, p_buffer, copyLen);
6119 void* p_buffer = NULL;
6121 uint32_t ui32LBA = 0;
6126 if ((!p_ctx) || (!p_stream_info))
6138 __func__, device_type);
6160 memset(p_buffer, 0, dataLen);
6172 p_stream_info->picture_width = ni_htons(p_stream_info->picture_width);
6173 p_stream_info->picture_height = ni_htons(p_stream_info->picture_height);
6174 p_stream_info->frame_rate = ni_htons(p_stream_info->frame_rate);
6175 p_stream_info->is_flushed = ni_htons(p_stream_info->is_flushed);
6176 p_stream_info->transfer_frame_stride = ni_htons(p_stream_info->transfer_frame_stride);
6178 p_stream_info->pix_format);
6206 void* p_buffer = NULL;
6207 uint64_t session_timestamp;
6208 uint32_t ui32LBA = 0;
6217 if ((!p_ctx) || (!p_session_stats))
6228 __func__, device_type);
6250 memset(p_buffer, 0, dataLen);
6270 p_session_stats->ui16SessionId = ni_htons(p_session_stats->ui16SessionId);
6271 p_session_stats->ui16ErrorCount = ni_htons(p_session_stats->ui16ErrorCount);
6272 p_session_stats->ui32LastTransactionId =
6273 ni_htonl(p_session_stats->ui32LastTransactionId);
6274 p_session_stats->ui32LastTransactionCompletionStatus =
6275 ni_htonl(p_session_stats->ui32LastTransactionCompletionStatus);
6276 p_session_stats->ui32LastErrorTransactionId = ni_htonl(p_session_stats->ui32LastErrorTransactionId);
6277 p_session_stats->ui32LastErrorStatus = ni_htonl(p_session_stats->ui32LastErrorStatus);
6278 p_session_stats->ui32Session_timestamp_high = ni_htonl(p_session_stats->ui32Session_timestamp_high);
6279 p_session_stats->ui32Session_timestamp_low = ni_htonl(p_session_stats->ui32Session_timestamp_low);
6281 session_timestamp = p_session_stats->ui32Session_timestamp_high;
6282 session_timestamp <<= 32;
6283 session_timestamp |= p_session_stats->ui32Session_timestamp_low;
6291 p_session_stats->ui32LastErrorStatus =
6294 "query timestamp:%" PRIu64
"\n", p_ctx->
session_id,
6303 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 "
6304 "ready_to_close %u session_run_state %d active_video_width %u active_video_height %u\n",
6318 #if __linux__ || __APPLE__
6319 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
6320 #ifndef DISABLE_BACKTRACE_PRINT
6321 ni_print_backtrace();
6326 p_session_stats->ui32LastTransactionCompletionStatus =
6330 }
else if (p_ctx->
session_id != p_session_stats->ui16SessionId)
6335 "%s(): device 0x%" PRIx64
" last command Failed due to wrong "
6336 "session ID. Expected 0x%x, got 0x%x keep alive last access "
6337 "time %" PRIu64
", current %" PRIu64
"\n", __func__,
6340 if (dt > 1000000000)
6343 "%s():long delay between last command dt = %" PRId64
" ns, "
6344 "process was possibly blocked.\n", __func__, dt);
6353 __func__, p_session_stats->ui16ErrorCount,
6354 p_session_stats->ui32LastTransactionCompletionStatus,
6355 p_session_stats->ui32LastErrorStatus);
6378 void* p_buffer = NULL;
6380 uint32_t ui32LBA = 0;
6385 if (!p_ctx || !p_stream_complete)
6397 __func__, device_type);
6419 memset(p_buffer, 0, dataLen);
6431 p_stream_complete->is_flushed = ni_htons(p_stream_complete->is_flushed);
6441 static const char* ni_get_device_type_str(
int type)
6445 return "Invalid device type";
6447 return g_device_type_str[type];
6455 memcpy((
void *)p_session_statistic, p_buffer,
6459 p_session_statistic->ui32RdBufAvailSize =
6460 ni_htonl(p_session_statistic->ui32RdBufAvailSize);
6461 p_session_statistic->ui32WrBufAvailSize =
6462 ni_htonl(p_session_statistic->ui32WrBufAvailSize);
6464 p_session_statistic->ui32FramesInput =
6465 ni_htonl(p_session_statistic->ui32FramesInput);
6466 p_session_statistic->ui32FramesBuffered =
6467 ni_htonl(p_session_statistic->ui32FramesBuffered);
6468 p_session_statistic->ui32FramesCompleted =
6469 ni_htonl(p_session_statistic->ui32FramesCompleted);
6470 p_session_statistic->ui32FramesOutput =
6471 ni_htonl(p_session_statistic->ui32FramesOutput);
6472 p_session_statistic->ui32FramesDropped =
6473 ni_htonl(p_session_statistic->ui32FramesDropped);
6474 p_session_statistic->ui32InstErrors =
6475 ni_htonl(p_session_statistic->ui32InstErrors);
6477 p_session_statistic->ui16SessionId =
6478 ni_htons(p_session_statistic->ui16SessionId);
6479 p_session_statistic->ui16ErrorCount =
6480 ni_htons(p_session_statistic->ui16ErrorCount);
6481 p_session_statistic->ui32LastTransactionId =
6482 ni_htonl(p_session_statistic->ui32LastTransactionId);
6483 p_session_statistic->ui32LastTransactionCompletionStatus =
6484 ni_htonl(p_session_statistic->ui32LastTransactionCompletionStatus);
6485 p_session_statistic->ui32LastErrorTransactionId =
6486 ni_htonl(p_session_statistic->ui32LastErrorTransactionId);
6487 p_session_statistic->ui32LastErrorStatus =
6488 ni_htonl(p_session_statistic->ui32LastErrorStatus);
6489 p_session_statistic->ui32Session_timestamp_high =
6490 ni_htonl(p_session_statistic->ui32Session_timestamp_high);
6491 p_session_statistic->ui32Session_timestamp_low =
6492 ni_htonl(p_session_statistic->ui32Session_timestamp_low);
6496 if (p_ctx->
session_id != p_session_statistic->ui16SessionId)
6501 "%s(): %s device 0x%" PRIx64
" last command Failed due to wrong "
6502 "session ID. Expected 0x%x, got 0x%x w_r <%u %u> keep alive "
6503 "last access time %" PRIu64
", current %" PRIu64
"\n", __func__,
6506 p_session_statistic->ui16SessionId,
6507 p_session_statistic->ui32WrBufAvailSize,
6510 if (dt > 1000000000)
6513 "%s():long delay between last command dt = %" PRId64
" ns, "
6514 "process was possibly blocked.\n", __func__, dt);
6516 p_session_statistic->ui32LastErrorStatus =
6526 __func__, p_session_statistic->ui16ErrorCount,
6527 p_session_statistic->ui32LastTransactionCompletionStatus,
6528 p_session_statistic->ui32LastErrorStatus);
6548 void *p_buffer = NULL;
6550 uint32_t ui32LBA = 0;
6556 if (!p_ctx || !p_session_statistic)
6559 "ERROR: %s() passed parameters are null!, return\n", __func__);
6567 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() not supported on device with FW api version < 6.5\n", __func__);
6576 __func__, device_type);
6598 memset(p_buffer, 0, dataLen);
6607 p_buffer, dataLen, ui32LBA) < 0)
6618 ni_parse_session_statistic_info(p_ctx, p_session_statistic, p_buffer);
6623 __func__, ni_get_device_type_str(p_ctx->
device_type));
6652 void* p_buffer = NULL;
6654 uint32_t ui32LBA = 0;
6662 if (!p_ctx || !p_inst_buf_info)
6676 __func__, device_type);
6743 memset(p_buffer, 0, dataLen);
6754 p_inst_buf_info->buf_avail_size = ni_htonl(p_inst_buf_info->buf_avail_size);
6780 uint8_t enable, uint8_t hw_action,
6784 uint32_t ui32LBA = 0;
6785 void * p_buffer = NULL;
6786 uint32_t buffer_size = 0;
6815 memset(p_buffer, 0, buffer_size);
6874 uint32_t ui32LBA = 0;
6890 __func__, device_type);
6928 uint32_t ui32LBA = 0;
6944 __func__, device_type);
6983 uint32_t ui32LBA = 0;
6998 __func__, device_type);
7045 uint32_t ui32LBA = 0;
7046 void * p_buffer = NULL;
7047 uint32_t buffer_size = 0;
7063 __func__, device_type);
7084 memset(p_buffer, 0, buffer_size);
7085 memcpy(p_buffer, &len,
sizeof(len));
7115 uint32_t ui32LBA = 0;
7116 void * p_buffer = NULL;
7117 uint32_t buffer_size = 0;
7131 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Seq Change not supported for device type %d, return\n", device_type);
7152 memset(p_buffer, 0, buffer_size);
7180 void* p_encoder_config = NULL;
7181 void* p_encoder_roi_qp_map = NULL;
7183 uint32_t buffer_size = 0;
7185 uint32_t ui32LBA = 0;
7211 if (
ni_posix_memalign(&p_encoder_roi_qp_map, sysconf(_SC_PAGESIZE), buffer_size))
7218 memset(p_encoder_roi_qp_map, 0, buffer_size);
7222 p_encoder_roi_qp_map, buffer_size, ui32LBA);
7251 memset(p_encoder_config, 0, buffer_size);
7312 p_encoder_config, buffer_size, ui32LBA);
7349 uint32_t ui32LBA = 0;
7353 if (!p_ctx || !p_params)
7387 buffer_size, ui32LBA) < 0)
7418 if (!p_frame || !p_frame_offset)
7425 *p_frame_offset = 0;
7429 unsigned int video_data_size = p_frame->
data_len[0] + p_frame->
data_len[1] +
7436 if (rx_size == metadata_size)
7438 video_data_size = 0;
7441 if (rx_size > video_data_size)
7448 rx_size -= metadata_size;
7460 "%s: [metadata] cropRight=%u, cropLeft=%u, "
7461 "cropBottom=%u, cropTop=%u, frame_offset=%" PRIu64
", pic=%ux%u, "
7462 "pict_type=%d, crop=%ux%u, sei header: 0x%0x number %u size %u\n",
7486 #if 1 // QUADRA_SEI_FMT
7487 ni_log(
NI_LOG_DEBUG,
"ui32SeiHeader 0x%x ui16SeiNumber %d ui16SeiSize %d SEI 0x%02x%02x\n",
7489 *((uint8_t*)p_meta + metadata_size),
7490 *((uint8_t*)p_meta + metadata_size+1));
7493 uint16_t ui16SeiProcessed = 0;
7495 uint32_t ui32Offset = 0;
7504 if (pEntryHeader->
status)
7506 ui32Size = pEntryHeader->
size;
7514 ui16SeiProcessed, pEntryHeader->
status,
7515 pEntryHeader->
size, pEntryHeader->
type, ui32Size,
7517 *((uint8_t *)p_meta + metadata_size + ui32Offset),
7518 *((uint8_t *)p_meta + metadata_size + ui32Offset + 1));
7525 switch(pEntryHeader->
type)
7530 uint8_t *ptr = (uint8_t*)p_meta + metadata_size + ui32Offset;
7537 video_data_size + metadata_size + ui32Offset;
7564 "%s: close caption size %u ,"
7565 "offset %u = video size %u meta size %d off "
7568 video_data_size, metadata_size, ui32Offset);
7573 "%s: unsupported T35; type %u size %u status %u "
7575 __func__, pEntryHeader->
type, pEntryHeader->
size,
7576 pEntryHeader->
status, ui32Offset);
7582 "Error %s: T35 (missing payload); type %u size %u "
7583 "status %u offset %u\n",
7584 __func__, pEntryHeader->
type, pEntryHeader->
size,
7585 pEntryHeader->
status, ui32Offset);
7602 "Error %s: User Data Unreg dropped (missing payload); "
7603 "type %u size %u status %u offset %u\n",
7604 __func__, pEntryHeader->
type, pEntryHeader->
size,
7605 pEntryHeader->
status, ui32Offset);
7614 video_data_size + metadata_size + ui32Offset;
7619 *)((uint8_t *)p_meta + metadata_size + ui32Offset);
7641 "Error %s: mastering display info dropped (missing "
7642 "payload); type %u size %u status %u offset %u\n",
7643 __func__, pEntryHeader->
type, pEntryHeader->
size,
7644 pEntryHeader->
status, ui32Offset);
7653 video_data_size + metadata_size + ui32Offset;
7659 (uint8_t*)p_meta + metadata_size + ui32Offset);
7668 "Error %s: content light level info dropped (missing "
7669 "payload); type %u size %u status %u offset %u\n",
7670 __func__, pEntryHeader->
type, pEntryHeader->
size,
7671 pEntryHeader->
status, ui32Offset);
7680 video_data_size + metadata_size + ui32Offset;
7689 "Warning %s: SEI message dropped (unsupported - check "
7690 "decoder SEI bitmap settings);"
7691 " type %u size %u status %u offset %u payload bytes %u\n",
7692 __func__, pEntryHeader->
type, pEntryHeader->
size,
7693 pEntryHeader->
status, ui32Offset, ui32Size);
7696 ui32Offset += ui32Size;
7697 pEntryHeader = (
ni_sei_header_t *)((uint8_t*)p_meta + metadata_size + ui32Offset);
7699 }
while (ui32Offset <= p_meta->sei_size && ui16SeiProcessed < p_meta->sei_number);
7705 "Error %s: number of SEI messages reported %u != processed %u\n",
7706 __func__, p_meta->
sei_number, ui16SeiProcessed);
7710 #else // QUADRA_SEI_FMT
7715 ni_sei_user_data_entry_t *pEntry;
7716 uint32_t ui32CCOffset = 0, ui32CCSize = 0;
7720 pEntry = (ni_sei_user_data_entry_t *)((uint8_t*)p_meta + metadata_size);
7723 &ui32CCOffset, &ui32CCSize))
7727 video_data_size + metadata_size + ui32CCOffset;
7740 &ui32CCOffset, &ui32CCSize))
7744 ptr = (uint8_t*)pEntry + ui32CCOffset;
7747 ui32CCSize = (ptr[8] & 0x1F) * 3;
7753 + ui32CCOffset + 10;
7758 "%s: close caption size %u ,"
7759 "offset %u = video size %u meta size %u off "
7762 video_data_size, metadata_size, ui32CCOffset);
7772 &ui32CCOffset, &ui32CCSize))
7776 video_data_size + metadata_size + ui32CCOffset;
7780 ni_dec_mastering_display_colour_volume_t* pColourVolume =
7781 (ni_dec_mastering_display_colour_volume_t*)((uint8_t*)pEntry + ui32CCOffset);
7784 pColourVolume->display_primaries_x[0],
7785 pColourVolume->display_primaries_y[0]);
7787 pColourVolume->display_primaries_x[1],
7788 pColourVolume->display_primaries_y[1]);
7790 pColourVolume->display_primaries_x[2],
7791 pColourVolume->display_primaries_y[2]);
7794 pColourVolume->white_point_x,
7795 pColourVolume->white_point_y);
7797 pColourVolume->max_display_mastering_luminance, pColourVolume->min_display_mastering_luminance);
7801 &ui32CCOffset, &ui32CCSize))
7805 video_data_size + metadata_size + ui32CCOffset;
7809 ni_content_light_level_info_t* pLightLevel =
7810 (ni_content_light_level_info_t*)((uint8_t*)pEntry + ui32CCOffset);
7812 pLightLevel->max_content_light_level, pLightLevel->max_pic_average_light_level);
7817 &ui32CCOffset, &ui32CCSize) ||
7820 &ui32CCOffset, &ui32CCSize))
7824 video_data_size + metadata_size + ui32CCOffset;
7831 #endif // QUADRA_SEI_FMT
7866 ni_device_handle_t device_handle,
bool device_in_ctxt)
7868 int i, total_types = 0, total_modules = 0;
7876 if (!p_cap || !p_data)
7889 "ERROR: Previously in context device got an invalid vendor ID 0x%X SSVID 0x%X. Netint "
7890 "ID 0x%X. Retrying\n",
7894 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
7896 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
7898 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
7902 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
7913 "ERROR: %s(): Retry got an invalid vendor ID too 0x%X SSVID "
7918 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
7920 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
7922 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
7930 "Retry got valid a vendor ID 0x%X SSVID 0x%X. Netint ID 0x%X\n",
7969 "Error: mismatch; xcoder_num_elements: %d (calculated: %d) "
7970 "xcoder_num_devices: %d (calculated: %d)\n",
8027 "ERROR: Previously in context device is not a xcoder device "
8047 if (total_modules >= 1)
8062 if (total_modules >= 2)
8077 if (total_modules >= 3)
8092 if (total_modules >= 4)
8160 static uint32_t presetGopSize[] = {
8180 int pos_byte = (pos/8);
8181 int pos_in_byte = pos%8;
8182 int remaining_bytes_in_current_byte = 8 - pos_in_byte;
8184 if (pos_in_byte == 0)
8186 vui[pos_byte] = (uint8_t)(value >> 24);
8187 vui[pos_byte+1] = (uint8_t)(value >> 16);
8188 vui[pos_byte+2] = (uint8_t)(value >> 8);
8189 vui[pos_byte+3] = (uint8_t)(value);
8193 vui[pos_byte] = vui[pos_byte] + (uint8_t)(value >> (32-remaining_bytes_in_current_byte));
8194 vui[pos_byte+1] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-8));
8195 vui[pos_byte+2] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-16));
8196 vui[pos_byte+3] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-24));
8197 vui[pos_byte+4] = vui[pos_byte+4] + ((uint8_t)(value << remaining_bytes_in_current_byte));
8212 uint32_t max_pkt_size)
8216 if ((!p_ctx) || (!p_cfg) || (!p_src))
8225 bool shift_params =
false;
8253 ni_log2(p_ctx,
NI_LOG_INFO,
"%s height %d width %d fps_number %d fps_denominator %d\n",
8263 shift_params =
true;
8264 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Output 2 used before output 1, Shifting output2 settings to output1 and disabling output 2\n");
8269 if (!shift_params || i == 0)
8275 j = (i == 1) ? 2 : 1;
8281 (uint16_t)((p_dec->
crop_whxy[j][0]) & 0xFFFE);
8283 (uint16_t)((p_dec->
crop_whxy[j][1]) & 0xFFFE);
8285 (uint16_t)((p_dec->
crop_whxy[j][2]) & 0xFFFE);
8287 (uint16_t)((p_dec->
crop_whxy[j][3]) & 0xFFFE);
8339 (uint16_t)((p_dec->
scale_wh[j][0]+1) & 0xFFFE);
8341 (uint16_t)((p_dec->
scale_wh[j][1]+1) & 0xFFFE);
8358 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): maxExtraHwFrameCnt is not support for FW < 6rB\n", __func__);
8366 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (enableAdvancedEc == 2) is not support for FW < 6rO\n", __func__);
8373 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (EcPolicy == limited_error) not supported for FW < 6ri\n", __func__);
8380 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): setting ecErrThreshold not supported for FW < 6ri\n", __func__);
8387 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (EcPolicy == best_effort_out_dc) not supported for FW < 6s1\n", __func__);
8395 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): surviveStreamErr is not supported for FW < 6rl\n", __func__);
8404 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s():Not support to reduce dpb delay and reset.\n", __func__);
8463 if ((!p_ctx) || (!p_cfg) || (!p_src))
8514 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_bitrate %d. assigned bitrate %d\n",
8532 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");
8582 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_framerate num %d den %d. assigned num %d den %d\n",
8600 uint32_t numUnitsInTick = 1000;
8665 "ERROR: %s() unknown value for p_t408->decoding_refresh_type: %d\n",
8689 ni_log2(p_ctx,
NI_LOG_DEBUG,
"force intraRefreshMode to 1 because quadra only supports intra refresh by rows\n");
8699 int mbRows = (p_cfg->
i32picHeight + mbHeight - 1) / mbHeight;
8734 "for profile 3 (extended) or 1 (baseline)\n");
8743 "force EnableRdoQuant 0 to accommodate HW limiation\n");
8863 if (p_enc->
crf != -1)
9011 "Turning off strongIntraSmoothing because hvsQPEnable=1 "
9012 "for better subjective VQ\n");
9024 "Turning off strongIntraSmoothing because hvsQPEnable=1 for "
9025 "better subjective VQ\n");
9059 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): spatialLayers is not supported for FW < 6rw\n", __func__);
9067 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): spatialLayers is not supported for FW < 6s0\n", __func__);
9085 ni_log(
NI_LOG_INFO,
"Warning h.265 psnr_y is only supported for YUV420P, YUV420P10LE, NV12, and P010LE\n");
9095 ni_log(
NI_LOG_INFO,
"Warning reconstructed frames only supported for YUV420P, NV12\n");
9105 ni_log(
NI_LOG_INFO,
"Warning get psnr feature only support YUV420P (except for h.265 psnr_y)\n");
9111 ni_log(
NI_LOG_INFO,
"Warning get psnr feature is not supported when cropWidth x cropHeight are set\n");
9147 int gopSize = g_map_preset_to_gopsize[lookAheadEnable][p_t408->
gop_preset_index + 1];
9153 if (lookAheadEnable)
9155 int firstGopEnd = gopSize + 1 + mulitcoreDelay;
9156 int lookaheadGopEnd = mulitcoreDelay ?
9159 int initialDelayNum = (firstGopEnd > lookaheadGopEnd) ? firstGopEnd : lookaheadGopEnd;
9161 int maxLookaheadQueue = initialDelayNum + (gopSize - 1) + mulitcoreDelay;
9164 p_ctx->
max_frame_delay = ((maxDelayNum > maxLookaheadQueue) ? maxDelayNum : maxLookaheadQueue) + (mulitcoreDelay ? 4 : 0);
9187 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: firstGopEnd %d lookaheadGopEnd %d initialDelayNum %d maxDelayNum %d maxLookaheadQueue %d\n",
9188 __FUNCTION__, firstGopEnd, lookaheadGopEnd, initialDelayNum, maxDelayNum, maxLookaheadQueue);
9196 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: preset %d lookAheadDepth %d gopSize %d mulitcoreDelay %d "
9197 "last_gop_size %d linitial_frame_delay %d current_frame_delay %d max_frame_delay %d\n",
9214 if (p_enc->
qcomp != (
float)0.6)
9234 if (p_enc->
ipRatio != (
float)1.4)
9239 if (p_enc->
pbRatio != (
float)1.3)
9264 if (p_enc->
crfFloat != (
float)-1.0)
9420 for (i = 0; i < 8; i++)
9652 if( (!p_ctx) || (!p_config) )
9924 p_config->
i8crf = -1;
9983 p_config->
i8crfMax = (int8_t)(-1) + 1;
9984 p_config->
i32qcomp = (int32_t)(0.6 * 1000) + 1000;
9988 p_config->
i32ipRatio = (int32_t)(1.4 * 1000) + 1000;
9989 p_config->
i32pbRatio = (int32_t)(1.3 * 1000) + 1000;
10034 uint32_t max_err_len)
10040 char *p_param_warn = NULL;
10043 if (!p_ctx || !p_cfg || !p_param_err)
10061 memset(p_param_err, 0, max_err_len);
10062 memset(p_param_warn, 0, max_err_len);
10075 strncpy(p_param_err,
"Incompatible output format: hw frame must be used if out1 or out2 used", max_err_len);
10085 strncpy(p_param_err,
"ddr_priority_mode not supported on device with FW api version < 6.e",
10100 strncpy(p_param_err,
"Invalid crop offset: extends past 48x48 minimum window", max_err_len);
10107 strncpy(p_param_err,
"Invalid crop w or h: must be at least 48x48 minimum window", max_err_len);
10114 strncpy(p_param_err,
"Invalid crop w or h: must be smaller than input", max_err_len);
10121 strncpy(p_param_err,
"Invalid crop rect: must fit in input", max_err_len);
10130 strncpy(p_param_err,
"Invalid crop value: even values only", max_err_len);
10136 strncpy(p_param_warn,
"crop param used but output not enabled!", max_err_len);
10151 strncpy(p_param_err,
"Invalid scale dimensions: zero", max_err_len);
10159 strncpy(p_param_err,
"Invalid scale value: even values only", max_err_len);
10169 strncpy(p_param_err,
"Invalid scale value: downscale only", max_err_len);
10181 strncpy(p_param_err,
"Invalid scale dimensions: downscale only after cropping", max_err_len);
10188 strncpy(p_param_warn,
"scale param used but output not enabled!", max_err_len);
10196 strncpy(p_param_warn,
"force8bit or semiPlanar used but output not enabled!", max_err_len);
10210 strncpy(p_param_err,
10211 "Invalid pairing: out=HW must be set with tiled format",
10218 strncpy(p_param_err,
"Invalid pairing: VP9 not compatible with tiled format",
10229 strncpy(p_param_err,
10230 "Invalid scale height: mult of 4 only, >= 128",
10239 strncpy(p_param_err,
10240 "Invalid scale width: mult of 128 only, >= 144",
10251 strncpy(p_param_err,
10252 "Invalid crop height: mult of 4 only, >= 128",
10261 strncpy(p_param_err,
10262 "Invalid crop width: mult of 128 only, >= 144",
10270 strncpy(p_param_err,
"Force 8 bit: not supported with tiled format\n",
10281 strncpy(p_param_err, p_param_warn, max_err_len);
10286 free(p_param_warn);
10291 static ni_retcode_t ni_check_level(
int level,
int codec_id)
10293 const int l_levels_264[] = {10, 11, 12, 13, 20, 21, 22, 30, 31, 32,
10294 40, 41, 42, 50, 51, 52, 60, 61, 62, 0};
10295 const int l_levels_265[] = {10, 20, 21, 30, 31, 40, 41,
10296 50, 51, 52, 60, 61, 62, 0};
10297 const int l_levels_av1[] = {20, 21, 30, 31, 40, 41, 50, 51, 0};
10298 const int *l_levels = l_levels_264;
10307 l_levels = l_levels_265;
10310 l_levels = l_levels_av1;
10313 while (*l_levels != 0)
10315 if (*l_levels == level)
10336 uint32_t max_err_len)
10344 if( (!p_ctx) || (!p_cfg) || (!p_src) || (!p_param_err) )
10354 memset(p_param_err, 0, max_err_len);
10355 memset(p_param_warn, 0, max_err_len);
10359 strncpy(p_param_err,
"Invalid frame_rate of 0 value", max_err_len);
10367 strncpy(p_param_err,
"Invalid i32frameRateInfo: too big", max_err_len);
10374 strncpy(p_param_err,
"Invalid i32bitRate: smaller than or equal to frame rate", max_err_len);
10381 strncpy(p_param_err,
"Invalid i32bitRate: too big", max_err_len);
10388 strncpy(p_param_err,
"Invalid i32bitRate: too low", max_err_len);
10395 strncpy(p_param_err,
"Invalid Picture Width: too small", max_err_len);
10402 strncpy(p_param_err,
"Invalid Picture Width: too big", max_err_len);
10409 strncpy(p_param_err,
"Invalid Picture Height: too small", max_err_len);
10416 strncpy(p_param_err,
"Invalid Picture Height: too big", max_err_len);
10426 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %u): both need to be specified",
10434 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %uu): must be even",
10442 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: less than %d",
10449 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: less than %d",
10456 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10463 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10470 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10480 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10487 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10494 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10503 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: offset %u + crop width %u too big > %d",
10510 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: offset %u + crop height %u too big > %d",
10522 snprintf(p_param_err, max_err_len,
"Invalid Picture Width: exceeds %d",
10529 snprintf(p_param_err, max_err_len,
"Invalid Picture Height: exceeds %d",
10536 snprintf(p_param_err, max_err_len,
"Invalid Picture Width x Height: exceeds %d",
10546 strncpy(p_param_err,
"Invalid input planar format: out of range", max_err_len);
10555 strncpy(p_param_err,
"Invalid input planar format for device with FW api version < 6.8",
10562 strncpy(p_param_err,
"Invalid Encoder Selected: Tiled format must be on same device",
10569 strncpy(p_param_err,
10570 "Invalid Picture Height: tiled format only supports "
10578 strncpy(p_param_err,
10579 "Invalid Picture Width: tiled format only supports "
10594 strncpy(p_param_err,
"zeroCopyMode must not be disabled for RGBA / BGRA / ABGR / ARGB pixel formats", max_err_len);
10604 strncpy(p_param_err,
"RGBA / BGRA pixel formats not supported on device with FW api version < 6.Y",
10617 strncpy(p_param_err,
"ddr_priority_mode not supported on device with FW api version < 6.e",
10627 strncpy(p_param_err,
"Invalid Encoder Level: out of range", max_err_len);
10637 strncpy(p_param_err,
"Invalid intra_mb_refresh_mode: out of range",
10649 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
10656 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
10668 strncpy(p_param_err,
10669 "Invalid custom GOP paramaters: custom gop size must > 0",
10680 strncpy(p_param_err,
10681 "Invalid custom GOP paramaters: selected gopPresetIdx is "
10682 "not compatible with custom gop",
10689 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
10696 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
10706 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset larger"
10707 " than GOP size", max_err_len);
10719 strncpy(p_param_warn,
"useLowDelayPocType is only supported for H.264. Change useLowDelayPocType to 0", max_err_len);
10727 strncpy(p_param_err,
10728 "entropyCodingMode is only supported for H.264.",
10738 strncpy(p_param_err,
10739 "av1ErrorResilientMode is only supported for AV1.",
10749 strncpy(p_param_err,
"qLevel is only supported for JPEG.",
10762 strncpy(p_param_warn,
"enableSSIM only supported on device with FW api version < 6.2 "
10763 "and the encoder is not av1_ni_quadra_enc. Reported ssim will be 0.", max_err_len);
10772 strncpy(p_param_err,
"sliceMode/sliceArg is only supported for H.264 or H.265.",
10781 int max_num_ctu_mb_row = (p_src->
source_height + ctu_mb_size - 1) / ctu_mb_size;
10785 snprintf(p_param_err, max_err_len,
"Invalid number of rows per slice: should be between 1 and %d",
10796 strncpy(p_param_err,
"useLowDelayPocType is only supported for H.264.",
10809 strncpy(p_param_warn,
"ui8enableCompensateQp only supported when device with FW api version < 6rt "
10810 "and the encoder is not av1_ni_quadra_enc and ui16maxFrameSize > 0. Reported enableCompensateQp will be 0.", max_err_len);
10822 strncpy(p_param_warn,
"enableTimecode does not need to be set for H.265. Use ni_enc_insert_timecode API"
10823 "from libxcoder directly to insert time code SEI", max_err_len);
10827 strncpy(p_param_warn,
"enableTimecode not supported for the codec used. Forcing value to 0.", max_err_len);
10844 strncpy(p_param_err,
10845 "this gopPreset is not supported for lookahead and/or CRF",
10853 bool bIsgopLowdelay =
true;
10861 bIsgopLowdelay =
false;
10867 bIsgopLowdelay =
false;
10871 if (bIsgopLowdelay)
10873 strncpy(p_param_err,
"B-frames low delay custom gop is not supported for "
10874 "lookahead and/or CRF", max_err_len);
10882 strncpy(p_param_err,
10883 "bitrateMode is invalid when lookahead is enabled (or in CRF mode)",
10905 strncpy(p_param_err,
10906 "gopPresetIdx 2 is obsolete, suggest to use gopPresetIdx 9 "
10929 strncpy(p_param_err,
10930 "gopPresetIdx 6 is obsolete, suggest to use gopPresetIdx 7 "
10968 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");
10988 strncpy(p_param_warn,
"StillImageDetect or SceneChangeDetect only support gopPresetIdx=9 with FW > 6rm\n", max_err_len);
10998 strncpy(p_param_err,
10999 "currently do not support gop preset in multi spatial layers encode",
11012 strncpy(p_param_err,
11013 "higher spatial layers referencing base layer is only supported in multi spatial layers encode",
11029 strncpy(p_param_err,
"Invalid profile: must be 5 (high10)",
11039 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
11040 " 3 (extended), 4 (high), or 5 (high10)", max_err_len);
11051 strncpy(p_param_err,
"Invalid gopPresetIdx for H.264 baseline profile:"
11052 " must be 1, 2, 6 or 0 (custom with no B frames)", max_err_len);
11064 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
11065 "have B frames", max_err_len);
11076 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
11077 " 4 (high), or 5 (high10)", max_err_len);
11083 strncpy(p_param_warn,
"AVC Baseline/Main/High Profile do not support 10-bit, auto convert to 8-bit", max_err_len);
11094 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
11095 "have B frames", max_err_len);
11109 strncpy(p_param_err,
11110 "Must use gopPresetIdx 1,9,10 (no "
11111 "B frames) for profile 1",
11121 strncpy(p_param_err,
"Tier is not supported for H.264", max_err_len);
11127 strncpy(p_param_err,
11128 "spatialLayers is not supported for h.264 encode",
11143 strncpy(p_param_err,
"Invalid profile: must be 2 (main10)",
11153 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
11164 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
11171 strncpy(p_param_warn,
"HEVC Main Profile does not support 10-bit, auto convert to 8-bit", max_err_len);
11176 strncpy(p_param_err,
11177 "spatialLayers is not supported for h.265 encode",
11187 strncpy(p_param_err,
"Invalid profile: must be 1 (main)",
11197 strncpy(p_param_warn,
11198 "AV1 level < 2.0 is not supported, change to level 2.0",
11204 strncpy(p_param_warn,
11205 "AV1 level > 5.1 is not supported, change to level 5.1",
11215 strncpy(p_param_warn,
"confWinTop is not supported in AV1",
11223 strncpy(p_param_warn,
"confWinBottom is not supported in AV1",
11231 strncpy(p_param_warn,
"confWinLeft is not supported in AV1",
11239 strncpy(p_param_warn,
"confWinRight is not supported in AV1",
11245 strncpy(p_param_err,
11246 "masterDisplay not supported for AV1",
11252 strncpy(p_param_err,
"hrdEnable is not supported on av1 encoder",
11259 strncpy(p_param_err,
"enableAUD is not supported on av1 encoder",
11266 strncpy(p_param_err,
"maxCLL is not supported on av1 encoder",
11273 strncpy(p_param_err,
"repeatHeaders is not supported on av1 encoder",
11279 strncpy(p_param_err,
"enableSSIM is not supported on av1 encoder",
11286 strncpy(p_param_err,
"EnableRdoQuant is not supported on av1 encoder",
11293 strncpy(p_param_err,
"fillerEnable is not supported on av1 encoder",
11300 strncpy(p_param_err,
"ppsInitQp is not supported for av1 encoder",
11307 strncpy(p_param_err,
"vbvBufferReencode is not supported for av1 multicoreJointMode",
11316 strncpy(p_param_err,
11317 "masterDisplay not supported for jpeg",
11323 strncpy(p_param_err,
"confWinTop is not supported in jpeg",
11330 strncpy(p_param_err,
"confWinBottom is not supported in jpeg",
11337 strncpy(p_param_err,
"confWinLeft is not supported in jpeg",
11344 strncpy(p_param_err,
"confWinRight is not supported in jpeg",
11351 strncpy(p_param_err,
"hrdEnable is not supported on jpeg encoder",
11358 strncpy(p_param_err,
"enableAUD is not supported on jpeg encoder",
11365 strncpy(p_param_err,
"repeatHeaders is not supported on jpeg encoder",
11372 strncpy(p_param_err,
"prefTRC is not supported on jpeg encoder",
11379 strncpy(p_param_err,
"maxCLL is not supported on jpeg encoder",
11386 strncpy(p_param_err,
"colorPri is not supported on jpeg encoder",
11393 strncpy(p_param_err,
"colorTrc is not supported on jpeg encoder",
11400 strncpy(p_param_err,
"colorSpc is not supported on jpeg encoder",
11407 strncpy(p_param_err,
"sarNum is not supported on jpeg encoder",
11414 strncpy(p_param_err,
"sarDenom is not supported on jpeg encoder",
11421 strncpy(p_param_err,
11422 "videoFullRangeFlag is not supported on jpeg encoder",
11429 strncpy(p_param_err,
11430 "temporalLayersEnable is not supported on jpeg encoder",
11437 strncpy(p_param_err,
11438 "spatialLayers is not supported for jpeg encode",
11445 strncpy(p_param_err,
"LowDelay is not supported on jpeg encoder",
11452 strncpy(p_param_err,
"rdoLevel is not supported on jpeg encoder",
11459 strncpy(p_param_err,
"EnableRdoQuant is not supported on jpeg encoder",
11466 strncpy(p_param_err,
11467 "enable2PassGop is not supported on jpeg encoder",
11474 strncpy(p_param_err,
11475 "lookAheadDepth is not supported on jpeg encoder",
11482 strncpy(p_param_err,
11483 "gopPresetIdx is not supported on jpeg encoder",
11490 strncpy(p_param_err,
"roiEnable is not supported on jpeg encoder",
11497 strncpy(p_param_err,
11498 "RoiDemoMode is not supported on jpeg encoder",
11505 strncpy(p_param_err,
"cacheRoi is not supported on jpeg encoder",
11512 strncpy(p_param_err,
11513 "ReconfDemoMode is not supported on jpeg encoder",
11520 strncpy(p_param_err,
11521 "intraRefreshMode is not supported on jpeg encoder",
11528 strncpy(p_param_err,
11529 "intraRefreshArg is not supported on jpeg encoder",
11536 strncpy(p_param_err,
11537 "intraPeriod is not supported on jpeg encoder",
11546 "IntraRefreshResetOnForceIDR is not supported on jpeg encoder",
11553 strncpy(p_param_err,
11554 "longTermReferenceEnable is not supported on jpeg encoder",
11561 strncpy(p_param_err,
11562 "longTermReferenceInterval is not supported on jpeg encoder",
11569 strncpy(p_param_err,
11570 "longTermReferenceCount is not supported on jpeg encoder",
11577 strncpy(p_param_err,
11578 "multicoreJointMode is not supported on jpeg encoder",
11585 strncpy(p_param_err,
"enableSSIM is not supported on jpeg encoder",
11592 strncpy(p_param_err,
11593 "vbvBufferSize is not supported on jpeg encoder",
11600 strncpy(p_param_err,
11601 "fillerEnable is not supported on jpeg encoder",
11608 strncpy(p_param_err,
"picSkip is not supported on jpeg encoder",
11615 strncpy(p_param_err,
"maxFrameSize is not supported on jpeg encoder",
11622 strncpy(p_param_err,
11623 "cuLevelRCEnable is not supported on jpeg encoder",
11630 strncpy(p_param_err,
"hvsQPEnable is not supported on jpeg encoder",
11637 strncpy(p_param_err,
"profile is not supported on jpeg encoder",
11644 strncpy(p_param_err,
"intraRefreshMode or intraRefreshArg is not supported on jpeg encoder",
11649 if (p_cfg->
i8crf != -1)
11651 strncpy(p_param_err,
"crf is not supported on jpeg encoder",
11658 strncpy(p_param_err,
"tolCtbRcInter is not supported on jpeg encoder",
11665 strncpy(p_param_err,
"tolCtbRcIntra is not supported on jpeg encoder",
11672 strncpy(p_param_err,
11673 "rcQpDeltaRange is not supported on jpeg encoder",
11680 strncpy(p_param_err,
"bitrateWindow is not supported on jpeg encoder",
11687 strncpy(p_param_err,
"ctbRowQpStep is not supported on jpeg encoder",
11694 strncpy(p_param_err,
11695 "enableAIEnhance is not supported on jpeg encoder",
11702 strncpy(p_param_err,
"ppsInitQp is not supported for jpeg encoder",
11709 strncpy(p_param_err,
"pass1Qp is not supported for jpeg encoder",
11716 strncpy(p_param_err,
"bitrateMode is not supported for jpeg encoder",
11723 strncpy(p_param_err,
11724 "vbvBufferReencode is not supported on jpeg encoder",
11733 strncpy(p_param_err,
"Invalid forceFrameType: out of range",
11741 strncpy(p_param_err,
"Invalid forcedHeaderEnable: out of range",
11750 strncpy(p_param_err,
"Invalid decoding_refresh_type: out of range", max_err_len);
11760 strcpy(p_param_err,
"Invalid gop_preset_index: out of range");
11773 strcpy(p_param_err,
"GOP size must be 1 when lowDelay is enabled");
11782 strncpy(p_param_err,
"Invalid gopSize out of range", max_err_len);
11790 strncpy(p_param_err,
"GOP size must be <= 4 for low delay GOP", max_err_len);
11799 strncpy(p_param_err,
"Invalid LookAheadDepth: out of range. <[4-40]>", max_err_len);
11805 strncpy(p_param_err,
"2-pass encode does not support low delay GOP", max_err_len);
11811 strncpy(p_param_err,
"2-pass encode does not support tile4x4 format",
11818 strncpy(p_param_err,
"currently do not support lookahead encode with multi spatial layers", max_err_len);
11833 strncpy(p_param_err,
"Custom GOP must not include backward prediction when lowDelay is enabled", max_err_len);
11835 strncpy(p_param_err,
"Custom GOP must not include backward prediction when picSkip is enabled", max_err_len);
11848 strncpy(p_param_err,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when lowDelay is enabled", max_err_len);
11855 strncpy(p_param_err,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when picSkip is enabled", max_err_len);
11862 strncpy(p_param_err,
"lookAheadDepth must be 0 when lowDelay is enabled", max_err_len);
11864 strncpy(p_param_err,
"lookAheadDepth must be 0 when picSkip is enabled", max_err_len);
11872 strncpy(p_param_err,
11873 "Cannot use multicoreJointMode when lowDelay is enabled",
11876 strncpy(p_param_err,
11877 "Cannot use multicoreJointMode when picSkip is enabled",
11886 strncpy(p_param_err,
11887 "Cannot enable minFramesDelay when lowDelay is enabled",
11890 strncpy(p_param_err,
11891 "Cannot enable minFramesDelay when picSkip is enabled",
11902 strncpy(p_param_err,
"intra period must be divisible by the number of spatial layers", max_err_len);
11912 strncpy(p_param_err,
"Custom GOP size must be 1 when useLowDelayPocType is enabled", max_err_len);
11918 strncpy(p_param_err,
"Must use GOP with all frames as reference frames (gopPresetIdx 1,3,7,9) when useLowDelayPocType is enabled", max_err_len);
11941 "minimum frame size %d bytes in low delay mode\n", __func__,
11947 "mode. Set it to half of the maximum frame size %d bytes\n",
11954 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: maxFrameSize %u is too small. Changed to minimum value (bitrate/framerate in byte): %u\n",
11963 strncpy(p_param_err,
"maxFrameSize can only be used when lowDelay is enabled", max_err_len);
11980 strncpy(p_param_err,
"Custom GOP can not have B frames for intra refresh", max_err_len);
11990 strncpy(p_param_err,
11991 "Must use gopPresetIdx 9 (consecutive P frame) for intra refresh",
11996 strncpy(p_param_warn,
"GOP size forced to 1 and low delay GOP force disabled (no B frames) for intra refresh", max_err_len);
12003 strncpy(p_param_err,
12004 "intra refresh cycle (height / intraRefreshArg MB or CTU) must > 1",
12011 strncpy(p_param_err,
"lookaheadDepth must be 0 for intra refresh", max_err_len);
12020 strncpy(p_param_warn,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len);
12029 strncpy(p_param_warn,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len);
12040 strncpy(p_param_warn,
"HRD conformance is not guaranteed in multicoreJointMode", max_err_len);
12065 snprintf(p_param_err, max_err_len,
"vbvMaxRate %u cannot be smaller than bitrate %d",
12077 snprintf(p_param_err, max_err_len,
"vbvMinRate %u cannot be larger than bitrate %d",
12092 snprintf(p_param_err, max_err_len,
"vbvBufferSize must be greater than the average frame size. Minimum is %u msec for framerate %d fps",
12104 snprintf(p_param_warn, max_err_len,
"vbvBufferSize cannot be smaller than one frame size based on vbvMaxRate, force vbvBufferSize to %u msec for bitrate %d vbvMaxRate %u and framerate %d fps",
12116 snprintf(p_param_warn, max_err_len,
"vbvBufferSize cannot be smaller than one frame size based on vbvMinRate, force vbvBufferSize to %u msec for bitrate %d vbvMinRate %u and framerate %d fps",
12128 snprintf(p_param_warn, max_err_len,
"vbvMaxRate %u vbvMinRate %u does not take effect when vbvBufferSize is 0, force vbvMaxRate vbvMinRate to 0",
12140 strncpy(p_param_err,
12141 "Can't enable ltrRefInterval and longTermReferenceEnable "
12152 strncpy(p_param_err,
"Custom GOP size can not be > 1 for long term reference", max_err_len);
12161 strncpy(p_param_err,
12162 "Must use low delay GOP (gopPresetIdx 1,3,7,9) for long term reference",
12167 strncpy(p_param_warn,
"GOP size forced to 1 for long term reference", max_err_len);
12174 strncpy(p_param_err,
"lookaheadDepth must be 0 for long term reference", max_err_len);
12184 "Must set longTermReferenceEnable for longTermReferenceInterval",
12194 strncpy(p_param_warn,
"AV1 err resilient mode forced to 0 when using other codecs", max_err_len);
12204 strncpy(p_param_warn,
"Motion Constrained mode force disabled for codecs other than HEVC", max_err_len);
12214 "rdoLevel must be 1 for Motion Constrained mode 1 or 2",
12226 "multicoreJointMode must be 0 for Motion Constrained mode 2",
12238 "input resolution (or cropping window) must be 64x64 aligned for Motion Constrained mode 2",
12252 strncpy(p_param_warn,
"AVCC HVCC forced to 0 for codecs other than AVC HEVC", max_err_len);
12262 strncpy(p_param_err,
"Invalid cu_size_mode: out of range", max_err_len);
12272 strncpy(p_param_err,
"Invalid use_recommend_enc_params: out of range", max_err_len);
12290 strncpy(p_param_err,
"Invalid max_num_merge: out of range", max_err_len);
12304 strncpy(p_param_err,
"Invalid intra_qp: out of range", max_err_len);
12311 if (p_cfg->
i8crf >= 0 && p_cfg->
i8crf <= 51)
12318 strncpy(p_param_err,
"CRF requres LookAheadDepth <[4-40]>", max_err_len);
12326 strncpy(p_param_warn,
"enable lookahead of current frame", max_err_len);
12333 strncpy(p_param_err,
"CRF requires RcEnable 0", max_err_len);
12340 strncpy(p_param_warn,
"Lookahead with cuLevelRCEnable or hvsQPEnable may degrade quality", max_err_len);
12351 strncpy(p_param_err,
"tuneBframeVisual level 1 (medium) requires lookahead or crf encode", max_err_len);
12361 strncpy(p_param_err,
"Invalid enable_mb_level_rc: out of range", max_err_len);
12370 strncpy(p_param_err,
"Invalid min_qp: out of range", max_err_len);
12378 strncpy(p_param_err,
"Invalid max_qp: out of range", max_err_len);
12386 strncpy(p_param_err,
"Invalid enable_cu_level_rate_control: out of range", max_err_len);
12396 strncpy(p_param_err,
"Invalid enable_hvs_qp: out of range", max_err_len);
12406 strncpy(p_param_err,
"Invalid max_delta_qp: out of range", max_err_len);
12415 strncpy(p_param_err,
"Invalid i32vbvBufferSize: out of range", max_err_len);
12438 strncpy(p_param_err, p_param_warn, max_err_len);
12442 free(p_param_warn);
12448 char *p_param_err, uint32_t max_err_len)
12451 int32_t low_delay = 0;
12452 int32_t intra_period_gop_step_size;
12455 if (!p_param || !p_src || !p_param_err)
12464 memset(p_param_err, 0, max_err_len);
12498 intra_period_gop_step_size = 1;
12515 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: gop structure is larger than intra period", max_err_len);
12520 if (((!low_delay) && (p_param->
intra_period != 0) && ((p_param->
intra_period % intra_period_gop_step_size) != 0)) ||
12523 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: intra period is not a multiple of gop structure size", max_err_len);
12536 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
12543 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is zero or negative", max_err_len);
12548 if (min_poc > temp_poc[i])
12550 min_poc = temp_poc[i];
12558 if (temp_poc[j] == min_poc)
12567 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
12583 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
12590 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is negative", max_err_len);
12599 strncpy(p_param_err,
"Invalid custom gop parameters: ref pic delta cannot be 0", max_err_len);
12610 ni_log(
NI_LOG_ERROR,
"g%drefPic%d specified without g%drefPic%dUsed specified!\n", i, j, i, j);
12617 if (min_poc > temp_poc[i])
12619 min_poc = temp_poc[i];
12627 if (temp_poc[j] == min_poc)
12636 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
12654 if (((p_param->
cu_size_mode & 0x1) == 0) && ((align_8_width_flag != 0) || (align_8_height_flag != 0)))
12656 strncpy(p_param_err,
"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);
12660 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)))
12662 strncpy(p_param_err,
"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);
12666 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)))
12668 strncpy(p_param_err,
"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);
12677 strncpy(p_param_err,
"Invalid conf_win_top: out of range", max_err_len);
12683 strncpy(p_param_err,
"Invalid conf_win_top: not multiple of 2", max_err_len);
12690 strncpy(p_param_err,
"Invalid conf_win_bottom: out of range", max_err_len);
12696 strncpy(p_param_err,
"Invalid conf_win_bottom: not multiple of 2", max_err_len);
12703 strncpy(p_param_err,
"Invalid conf_win_left: out of range", max_err_len);
12709 strncpy(p_param_err,
"Invalid conf_win_left: not multiple of 2", max_err_len);
12716 strncpy(p_param_err,
"Invalid conf_win_right: out of range", max_err_len);
12722 strncpy(p_param_err,
"Invalid conf_win_right: not multiple of 2", max_err_len);
12736 if( (!p_cfg) || (!p_param_err) )
12746 memset(p_param_err, 0, max_err_len);
12750 strncpy(p_param_err,
"Invalid roiEnable: out of range", max_err_len);
12757 strncpy(p_param_err,
"hvsQPEnable and roiEnable: not mutually exclusive", max_err_len);
12766 strncpy(p_param_err,
"Invalid min_qp(P/B) and max_qp(P/B): min_qp cannot be larger than max_qp", max_err_len);
12787 if (!p_encoder_params)
12916 ni_pthread_mutex_t *p_mutex;
12921 struct sched_param sched_param;
12927 sigfillset(&signal);
12938 if (((sched_param.sched_priority = sched_get_priority_max(SCHED_RR)) ==
12940 sched_setscheduler(syscall(SYS_gettid), SCHED_RR, &sched_param) < 0)
12944 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
12951 #elif defined(_WIN32)
12956 if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) ==
12967 char name[16] = {0};
12968 snprintf(name,
sizeof(name),
"%s%.2x%.4x",
"KAT", args->
hw_id, args->
session_id);
12970 prctl(PR_SET_NAME, name);
12972 pthread_setname_np(name);
12991 "%s creation timeout. session_id=0x%X requested timeout: %" PRIu64
12992 "ns, ping time delta: %" PRIu64
"ns\n ",
13044 "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u "
13045 "inst_err_no %u\n",
13058 "%s was possibly blocked. session_id=0x%X requested timeout: %" PRIu64
13059 "ns, ping time delta: %" PRIu64
"ns\n ",
13080 endtime += interval;
13125 void * p_buffer = NULL;
13126 uint32_t ui32LBA = 0;
13127 uint32_t modelled_load;
13201 "ERROR %s(): p_ctx->device_handle=%" PRIx64
13202 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
13210 "Uploader open session ID:0x%x,timestamp:%" PRIu64
"\n",
13214 uint64_t keep_alive_timeout =
13217 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
13219 keep_alive_timeout);
13230 "ERROR %s(): nvme write keep_alive_timeout command "
13231 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
13255 modelled_load >>= 10;
13260 memcpy(p_buffer, &modelled_load, 4);
13291 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
13292 "p_ctx->session_id=%d\n",
13301 retval = p2p_fill_pcie_address(p_ctx);
13325 if (!src_p_ctx || !dst_p_ctx)
13327 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null!, return\n", __func__);
13338 if (src_p_ctx->
isP2P)
13343 dst_p_ctx->
bus = src_p_ctx->
bus;
13344 dst_p_ctx->
dev = src_p_ctx->
dev;
13345 dst_p_ctx->
fn = src_p_ctx->
fn;
13368 int query_retry = 0;
13380 "Session=0x%x: %s buffered_frame_index=%d return %d\n",
13390 query_sleep(p_ctx);
13391 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: query by ni_query_instance_buf_info INST_BUF_INFO_RW_UPLOAD\n", __func__);
13402 if (query_retry >=500)
13405 "scaler write exceeded max query retries. rc=%d try=%d\n",
13406 retval, query_retry);
13428 "Session=0x%x: %s got FrameIndex=%u buffered_frame_index=%d\n",
13438 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
13460 uint32_t frame_size_bytes = 0;
13461 uint32_t retry_count = 0;
13480 abs_time_ns, p_frame->pts);
13491 query_sleep(p_ctx);
13500 if (retry_count >= 500)
13503 "hwupload write exceeded max query retries. rc=%d try=%d"
13505 retval, retry_count);
13529 "size %u >= frame size %u , retry %u\n",
13568 uint32_t sent_size = 0;
13569 uint32_t frame_size_bytes = 0;
13570 uint32_t retry_count = 0;
13579 if (!p_ctx || !p_frame)
13598 #ifdef MEASURE_LATENCY
13603 abs_time_ns, p_frame->
pts);
13627 query_sleep(p_ctx);
13636 if (retry_count >= 500)
13639 "hwupload write exceeded max query retries. rc=%d try=%d"
13641 retval, retry_count);
13662 "size %u >= frame size %u , retry %u\n",
13667 #ifdef XCODER_TIMESTAMP_DTS_ENABLED
13673 "ERROR %s(): ni_timestamp_register() for dts "
13686 if (separate_metadata)
13691 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): uploader separated metadata not supported on device with FW api version < 6.S\n",
13699 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): p_metadata_buffer is NULL, allocation failed?\n",
13709 if (separate_start)
13722 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
13723 "p_frame->video_width=%u, p_frame->video_height=%u, "
13724 "start_len [%u,%u,%u] inconsecutive_transfer %u\n",
13730 uint32_t ui32LBA_metadata =
13733 "%s: p_metadata_buffer = %p, metadata_buffer_size "
13734 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13758 if (separate_start)
13771 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
13772 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13800 "%s: p_data = %p, p_frame->buffer_size "
13801 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13808 if (separate_start)
13833 "%s: p_data = %p, p_frame->buffer_size = %u, "
13834 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13838 sent_size = frame_size_bytes;
13839 if (separate_start)
13867 size = frame_size_bytes;
13869 #ifdef XCODER_DUMP_DATA
13870 char dump_file[256];
13871 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-hwup-fme/fme-%04ld.yuv",
13874 FILE *f = fopen(dump_file,
"wb");
13883 #ifdef MEASURE_LATENCY
13922 int query_retry = 0;
13926 if (!p_ctx || !hwdesc)
13944 query_sleep(p_ctx);
13963 if (query_retry >= 1000)
14005 void* p_buffer = NULL;
14007 uint32_t ui32LBA = 0;
14032 NI_INVALID_DEVICE_HANDLE, p_buffer,
14061 uint64_t frame_offset = 0;
14062 uint8_t *p_data_buffer = NULL;
14068 uint32_t total_bytes_to_read = 0;
14069 uint32_t total_yuv_met_size = 0;
14070 uint32_t read_size_bytes = 0;
14072 int query_retry = 0;
14073 uint32_t ui32LBA = 0;
14074 unsigned int bytes_read_so_far = 0;
14076 int low_delay_notify = 0;
14078 uint32_t frames_dropped = 0;
14080 uint8_t get_first_metadata = 0;
14081 uint8_t sequence_change = 0;
14085 if (!p_ctx || !p_frame)
14104 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
14109 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
14112 "Total bytes to read %u total_yuv_met_size %u, low_delay %u\n",
14133 query_sleep(p_ctx);
14142 &sessionStatistic);
14166 if (query_retry >= 1000)
14169 "\n", query_retry, retval);
14171 low_delay_notify = 1;
14186 "Dec read desc only hdr metadata is available. Seq change may "
14187 "have occured.\n");
14188 total_bytes_to_read = metadata_hdr_size;
14189 sequence_change = 1;
14193 ni_log2(p_ctx,
NI_LOG_TRACE,
"Dec read desc buf_size < frame_size. Retry %d\n", query_retry);
14199 "Dec read desc query, ready_to_close %u, query eos\n",
14214 "WARNING: Dec read desc query eos reached but exceeded max "
14215 "retries. is_flushed=%u try=%d.\n",
14220 "Dec read desc query eos reached. is_flushed=%u try=%d"
14225 low_delay_notify = 1;
14232 "Dec read desc available buf size == %d, query try %d, "
14246 query_retry < 1000 / 2)
14253 low_delay_signal(p_ctx);
14261 "size %u >= required size %u !\n",
14279 low_delay_signal(p_ctx);
14282 "input (B frames)? Just cancel the low delay mode then\n");
14285 low_delay_signal(p_ctx);
14295 if(query_retry <= 2000)
14304 "Warning: decoder pkt_num %u frame_num %u "
14305 "timeout, increasing pkt_delay_cnt to %u\n",
14312 "\n", query_retry, retval);
14328 "At least %d packets should be sent before reading the "
14345 "%ux%u frame-rate %u is_flushed %u\n",
14373 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
14374 p_data_buffer = (uint8_t*)p_frame->
p_buffer;
14384 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
14385 "%u cb len %u hdr %d\n",
14388 p_frame->
data_len[2], metadata_hdr_size);
14396 "ERROR %s() avaliable size(%u) less than "
14400 }
else if (total_bytes_to_read == metadata_hdr_size && !p_ctx->
frame_num)
14407 void *p_metadata_buffer = NULL;
14417 p_data_buffer = (uint8_t *)p_metadata_buffer;
14418 get_first_metadata = 1;
14419 sequence_change = 0;
14430 read_size_bytes = total_bytes_to_read;
14438 p_data_buffer, read_size_bytes, ui32LBA);
14447 }
else if (get_first_metadata) {
14455 get_first_metadata = 0;
14471 low_delay_notify = 1;
14474 p_data_buffer = (uint8_t *)p_frame->
p_buffer +
14476 memcpy(p_meta, p_data_buffer, metadata_hdr_size);
14481 metadata_hdr_size);
14513 "p_data3_1:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
14517 "p_data3_1: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
14522 "p_data3_2:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
14526 "p_data3_2: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
14531 "%s:sei_size=%d device_handle=%d == hw_id=%d "
14536 "%s: session=0x%x ui16FrameIdx=%u NodeAddress=0x%x, "
14537 "planar=%d bd=%d\n",
14552 total_bytes_to_read = total_bytes_to_read + sei_size;
14554 "%s decoder read desc success, retval %d "
14555 "total_bytes_to_read include sei %u sei_size %d\n",
14556 __func__, retval, total_bytes_to_read, sei_size);
14570 bytes_read_so_far = total_bytes_to_read;
14572 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset,
true);
14587 "is cancelled due to has_b_frames, frame_num %u\n",
14598 int64_t tmp_dts, prev_dts = INT64_MIN, ts_diff = 0;
14603 "%s(): First frame : session_id 0x%x, pic_reorder_delay: %d "
14604 "total frames input:%u buffered: %u completed: %u output: %u "
14605 "dropped: %u error: %u\n",
14624 "decoder dts queue %d %ld failed !\n",
14625 __func__, i, tmp_dts);
14630 "decoder dts queue %d %ld success !\n",
14631 __func__, i, tmp_dts);
14632 if (prev_dts != INT64_MIN) {
14633 ts_diff += labs(tmp_dts - prev_dts);
14636 prev_dts = tmp_dts;
14641 ts_diff = ts_diff / nb_diff;
14645 "average diff: %ld\n", __func__, ts_diff);
14660 "decoder dts queue %d %ld failed !\n",
14661 __func__, i, tmp_dts);
14695 if (p_frame->
pts >= p_frame->
dts &&
14696 p_frame->
pts - p_frame->
dts < 1000)
14712 "decoder dts queue %d %ld success !\n",
14713 __func__, i, p_frame->
dts);
14748 "%s: (found pts) dts %" PRId64
" pts "
14749 "%" PRId64
" frame_offset %" PRIu64
" i %d "
14750 "pkt_offsets_index_min %" PRIu64
" "
14751 "pkt_offsets_index %" PRIu64
" pkt_pos %" PRIu64
"\n",
14752 __func__, p_frame->
dts, p_frame->
pts, frame_offset, i,
14767 while (p_frame->
dts < p_frame->
pts &&
14768 labs(p_frame->
pts - p_frame->
dts) > ts_diff)
14771 "dts %ld diff. %ld > ts_diff %ld\n",
14772 __func__, p_frame->
pts, p_frame->
dts,
14773 labs(p_frame->
pts - p_frame->
dts), ts_diff);
14780 "pop decoder dts queue error.\n", __func__);
14803 "ERROR: Frame pts %" PRId64
" not found for offset "
14804 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
14806 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
14808 __func__, p_frame->
dts, p_frame->
pts);
14821 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
14829 __func__, p_frame->
pts);
14839 #ifdef MEASURE_LATENCY
14850 "%s(): p_frame->start_of_stream=%u, "
14851 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
14852 "p_frame->video_height=%u\n",
14861 "Decoder pts queue size = %d dts queue size = %d\n\n",
14868 #ifdef MEASURE_LATENCY
14873 ni_log2(p_ctx,
NI_LOG_INFO,
"DTS:%" PRId64
",DELTA:%" PRId64
",dLAT:%" PRIu64
";\n",
14884 if (get_first_metadata && p_data_buffer)
14886 if (sequence_change && p_ctx->
frame_num)
14900 low_delay_signal(p_ctx);
14907 if (low_delay_notify)
14909 low_delay_signal(p_ctx);
14927 uint64_t frame_offset = 0;
14928 uint8_t *p_data_buffer;
14931 uint32_t total_bytes_to_read = 0;
14932 uint32_t read_size_bytes = 0;
14933 uint32_t ui32LBA = 0;
14942 if ((!p_ctx) || (!p_frame))
14957 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
14959 if (!p_frame->
p_data[0] || !p_data_buffer)
14981 "ERROR %s(): NI_PIXEL_PLANAR_FORMAT_TILED4X4 not supported in download.\n",
14988 unsigned int bytes_read_so_far = 0;
14991 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Total bytes to download %u, start offset = %u, chunkOffset "
14992 "%u, minorOffset %u\n",
14994 output_chunk_offset, output_minor_offset);
14996 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
14997 "%u cb len %u hdr %d\n",
15000 p_frame->
data_len[2], metadata_hdr_size);
15019 "Config HW download read desc success, retval %d total_bytes_to_read %u\n",
15020 retval, total_bytes_to_read);
15023 read_size_bytes = total_bytes_to_read;
15025 ui32LBA += output_chunk_offset;
15033 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
15045 "HW download read desc success, retval %d total_bytes_to_read %u\n",
15046 retval, total_bytes_to_read);
15063 "Unconfig HW download read desc success, retval %d total_bytes_to_read %u\n",
15064 retval, total_bytes_to_read);
15067 bytes_read_so_far = total_bytes_to_read;
15072 rx_size = (int)bytes_read_so_far;
15081 __func__, rx_size);
15083 "%s(): p_frame->start_of_stream=%u, "
15084 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
15085 "p_frame->video_height=%u\n",
15089 "%s(): p_ctx->frame_num %" PRIu64
", "
15090 "p_frame->data_len[0/1/2]=%u/%u/%u\n",
15119 uint64_t frame_offset = 0;
15120 uint8_t *p_data_buffer;
15123 uint32_t total_bytes_to_read = 0;
15124 uint32_t read_size_bytes = 0;
15125 uint32_t ui32LBA = 0;
15127 const char *error_flag =
"NetintQuadraErr";
15131 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
15133 if (!p_frame->
p_data[0] || !p_data_buffer || 0 == p_frame->
data_len[0])
15135 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null or p_frame->data_len is 0.\n",
15147 "ERROR %s(): Unsupported format %d for hw download.\n",
15154 unsigned int bytes_read_so_far = 0;
15159 "%u cb len %u hdr %d\n",
15160 total_bytes_to_read,
15162 p_frame->
data_len[2], metadata_hdr_size);
15167 memcpy(global_state->
error_flag, error_flag, strlen(error_flag)+1);
15171 read_size_bytes = total_bytes_to_read;
15173 ui32LBA += output_chunk_offset;
15179 "%u, minorOffset %u hwdesc->ui16FrameIdx %d ui32LBA 0x%x\n",
15181 output_chunk_offset, output_minor_offset, hwdesc->
ui16FrameIdx, ui32LBA);
15185 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
15194 if (!strcmp(global_state->
error_flag, error_flag) &&
15198 "size %u + offset %u out of range\n",
15199 __func__, hwdesc->
ui16FrameIdx, read_size_bytes, output_chunk_offset);
15204 bytes_read_so_far = total_bytes_to_read;
15209 rx_size = (int)bytes_read_so_far;
15217 "HW download read desc success, retval %d total_bytes_to_read %u\n",
15218 retval, total_bytes_to_read);
15237 uint8_t *p_data = NULL;
15239 uint32_t ui32LBA = 0;
15260 memset(p_data, 0, dataLen);
15262 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s(): ui16DstIdx %u, ui16SrcIdx %u, size %u, offset %u\n", __func__,
15268 p_data, dataLen, ui32LBA);
15325 uint32_t pool_size,
15328 void* p_uploader_config = NULL;
15332 uint32_t ui32LBA = 0;
15360 memset(p_uploader_config, 0, buffer_size);
15382 ni_log2(p_ctx,
NI_LOG_DEBUG,
"ni_config_instance_set_uploader_params():%d x %d x Format %d with %d framepool\n",
15390 p_uploader_config, buffer_size, ui32LBA);
15429 void* p_decoder_config = NULL;
15432 uint32_t ui32LBA = 0;
15453 ni_log2(p_ctx,
NI_LOG_INFO,
"%s() FW rev %s < 6rT-- load balancing might be affected\n", __func__,
15465 memset(p_decoder_config, 0, buffer_size);
15518 p_decoder_config, buffer_size, ui32LBA);
15561 int query_retry = 0;
15563 if (!p_ctx || !p_frame || !p_frame->
p_data[3])
15597 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: query by ni_query_instance_buf_info INST_BUF_INFO_RW_UPLOAD\n",
15608 if (query_retry >= 1000)
15631 if (query_retry >= 1000)
15642 "Session=0x%x: %s got FrameIndex=%u\n",
15658 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
15740 uint32_t *p_offset)
15752 "FrameIdx %d OOR (%d,%d]. DDR config %d \n", __func__, hwdesc->
ui16FrameIdx,
15767 void *nb_data, uint32_t nb_size)
15769 void *p_ai_config = NULL;
15770 void *p_nb_data = NULL;
15771 uint32_t buffer_size;
15775 uint32_t ui32LBA = 0;
15776 uint32_t config_size;
15777 void *p_buffer = NULL;
15780 int retry_count = 0;
15811 ((
ni_ai_config_t *)p_ai_config)->ui32NetworkBinarySize = nb_size;
15824 memcpy(p_nb_data, nb_data, nb_size);
15832 p_ai_config, config_size, ui32LBA);
15838 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
15839 ", hw_id, %u, xcoder_inst_id: %d\n",
15846 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
15847 ", hw_id, %u, xcoder_inst_id: %d\n",
15868 memset(p_buffer, 0, dataLen);
15881 p_buffer, dataLen, ui32LBA);
15913 "AI write query failed or buf_size %u < "
15919 "Info ai write query success, available buf "
15920 "size %u >= frame size %u !\n",
15944 p_nb_data, buffer_size, ui32LBA);
15951 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
15952 ", hw_id, %u, xcoder_inst_id: %d\n",
15959 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
15960 ", hw_id, %u, xcoder_inst_id: %d\n",
15972 for (transferred = 0; transferred < buffer_size; transferred += this_size)
15976 (buffer_size - transferred);
15978 if (this_size & (4096 - 1))
15980 this_size = (this_size + (4096 - 1)) & ~(4096 - 1);
15984 (transferred >> 12);
15986 "%s(): write nb LBA 0x%x, this_size %u, page_offset %u\n",
15987 __func__, ui32LBA, this_size, (transferred >> 12));
15988 p_data = (uint8_t *)p_nb_data + transferred;
15991 (uint8_t *)p_nb_data + transferred, this_size, ui32LBA);
15999 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16000 ", hw_id, %u, xcoder_inst_id: %d\n",
16008 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16009 ", hw_id, %u, xcoder_inst_id: %d\n",
16035 void *p_stream_info = NULL;
16036 void *p_ai_config = NULL;
16037 void *p_nb_data = NULL;
16039 uint32_t ui32LBA = 0;
16040 uint32_t config_size;
16079 "### %s: width %d %d height %d model type %d level %d pix_format %d\n", __func__,
16090 p_stream_info, config_size, ui32LBA);
16096 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16097 ", hw_id, %u, xcoder_inst_id: %d\n",
16104 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16105 ", hw_id, %u, xcoder_inst_id: %d\n",
16129 void *p_buffer = NULL;
16130 uint32_t ui32LBA = 0;
16131 int retry_count = 0;
16142 memset(p_buffer, 0, dataLen);
16147 p_buffer, dataLen, ui32LBA);
16185 uint32_t ui32LBA = 0;
16187 uint32_t frame_size_bytes;
16188 uint32_t sent_size = 0;
16189 int32_t query_retry = 0;
16193 if (!p_ctx || !p_frame)
16220 frame_size_bytes = p_frame->
data_len[0];
16231 "Info ai write query success, available buf "
16232 "size %u >= frame size %u !\n",
16259 "AI write query failed or buf_size < frame_size. Retry %d\n",
16265 "AI write query exceeded max retries: %d\n",
16279 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Ai session write: p_data = %p, p_frame->buffer_size = %u, "
16280 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
16284 sent_size = frame_size_bytes;
16292 p_frame->
p_buffer, sent_size, ui32LBA);
16321 retval = frame_size_bytes;
16335 uint32_t actual_read_size = 0;
16337 uint32_t ui32LBA = 0;
16342 if (!p_ctx || !p_packet || !p_packet->
p_data)
16367 "Info ai read query success, available buf "
16368 "size %u >= frame size %u !\n",
16391 "Info ai read query rc %d, available buf size %u, "
16392 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
16413 actual_read_size = p_packet->
data_len;
16421 p_packet->
p_data, actual_read_size, ui32LBA);
16471 void *p_buffer = NULL;
16472 void *p_info = NULL;
16474 uint32_t ui32LBA = 0;
16476 int32_t query_retry = 0;
16479 uint32_t buffer_size;
16480 uint32_t this_size;
16482 uint32_t total_io_num;
16486 if (!p_ctx || !p_network)
16498 "ERROR: %s(): network parameters data is already initialized\n",
16524 memset(p_buffer, 0, dataLen);
16540 p_buffer, dataLen, ui32LBA);
16556 if (query_retry > 50000)
16559 __func__, query_retry - 1);
16604 if (!network_data->
inset)
16627 memset(p_info, 0, dataLen);
16631 p_info, dataLen, ui32LBA);
16632 if ((int32_t)retval < 0)
16654 memset(p_info, 0, dataLen);
16658 p_info, dataLen, ui32LBA);
16659 if ((int32_t)retval < 0)
16669 for (l = 0, network_data->
input_num = 0; l < 4; l++)
16679 for (l = 0, network_data->
output_num = 0; l < 4; l++)
16690 for (l = 0, buffer_size = 0; l < network_data->
input_num; l++)
16697 buffer_size += this_size;
16701 "%s(): network input layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
16707 for (l = 0, buffer_size = 0; l < network_data->
output_num; l++)
16714 buffer_size += this_size;
16718 "%s(): network output layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
16733 ni_unreference_network_data(network_data);
16744 void *p_buffer = NULL;
16745 uint32_t ui32LBA = 0;
16825 "ERROR %s(): p_ctx->device_handle=%" PRIx64
16826 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
16843 "%s(): p_ctx->device_handle=%" PRIx64
16844 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
16849 uint64_t keep_alive_timeout =
16852 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
16854 keep_alive_timeout);
16866 "ERROR %s(): nvme write keep_alive_timeout command "
16867 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
16878 "ERROR %s(): Unable to allocate network_data memory\n");
16902 void *p_buffer = NULL;
16903 uint32_t ui32LBA = 0;
16939 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
16940 "p_ctx->session_id=%d, close_mode=1\n",
17007 void *p_read_data = NULL;
17009 uint32_t ui32LBA = 0;
17026 int32_t query_retry = 0;
17034 "Info ai write query success, available buf "
17051 "AI write query failed or buf_size < frame_size. Retry %d\n",
17057 "AI write query exceeded max retries: %d\n",
17080 memset(p_data, 0x00, dataLen);
17086 for(
int i = 0; i < numInCfgs; i++){
17098 p_data, dataLen, ui32LBA);
17106 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
17107 ", hw_id, %u, xcoder_inst_id: %d\n",
17118 if (p_read_data != NULL)
17130 void *p_read_data = NULL;
17132 uint32_t ui32LBA = 0;
17153 "Error: %s function not supported on device with FW API version < 6rL\n",
17160 int query_retry = 0;
17171 memset(p_read_data, 0, dataLen);
17179 p_read_data, dataLen, ui32LBA);
17203 if (query_retry > 2000)
17206 __func__, query_retry - 1);
17224 if (p_read_data != NULL)
17232 int height,
int options,
int pool_size,
17237 void *p_read_data = NULL;
17239 uint32_t ui32LBA = 0;
17259 int query_retry = 0;
17270 memset(p_read_data, 0, dataLen);
17278 p_read_data, dataLen, ui32LBA);
17295 if (query_retry > 2000)
17298 __func__, query_retry - 1);
17316 int32_t query_retry = 0;
17324 "Info ai write query success, available buf "
17341 "AI write query failed or buf_size < frame_size. Retry %d\n",
17347 "AI write query exceeded max retries: %d\n",
17370 memset(p_data, 0x00, dataLen);
17385 p_data, dataLen, ui32LBA);
17393 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
17394 ", hw_id, %u, xcoder_inst_id: %d\n",
17406 if (p_read_data != NULL)
17429 int retry_count = 0;
17456 if (retry_count >= 500)
17482 if (retry_count >= 500)
17519 void *p_buffer = NULL;
17522 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
17528 if (NI_INVALID_DEVICE_HANDLE == device_handle)
17603 uint8_t ddr_priority_mode)
17605 void *p_buffer = NULL;
17614 ddr_priority_mode);
17616 if (NI_INVALID_DEVICE_HANDLE == device_handle)
17635 p_cfg->
ddr_mode = ddr_priority_mode;
17640 ddr_priority_mode);
17668 void *metadata_buffer = NULL;
17671 if ((!p_frame) || (extra_len <= 0))
17674 "ERROR: %s passed parameters are null or not supported, "
17675 "p_frame %p, extra_len %d",
17676 __func__, p_frame, extra_len);
17680 int buffer_size = extra_len;
17692 "%s: free current p_frame metadata buffer, "
17693 "p_frame->buffer_size=%u\n",
17706 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
17713 memset(metadata_buffer, 0, buffer_size);
17724 "%s: success: p_frame->p_metadata_buffer %p "
17725 "p_frame->metadata_buffer_size=%u\n",
17754 void *start_buffer = NULL;
17760 "ERROR: %s passed parameters are null or not supported, "
17762 __func__, p_frame);
17773 "ERROR %d: %s() Cannot allocate start buffer.\n",
17791 "%s: success: p_frame->p_start_buffer %p "
17792 "p_frame->start_buffer_size=%u\n",
17809 void *p_buffer = NULL;
17811 uint32_t ui32LBA = 0;
17814 if (!p_ctx || !p_metrics)
17817 "ERROR: %s() passed parameters are null!, return\n", __func__);
17841 p_buffer, dataLen, ui32LBA);
17884 uint32_t *u32_buf = (uint32_t *)buf;
17886 u32_buf[1] = value;
17899 CoreName = (
char *)
"all";
17902 CoreName = (
char *)
"np";
17905 CoreName = (
char *)
"ep";
17908 CoreName = (
char *)
"dp";
17911 CoreName = (
char *)
"tp";
17914 CoreName = (
char *)
"fp";
17917 CoreName = (
char *)
"Not Found";
17957 char *core_name = NULL;
17958 FILE *p_file = NULL;
17961 if (!p_ctx || !p_data)
17964 __func__, __LINE__, p_ctx, p_data);
17969 *(uint8_t *)p_data = 0x55;
17975 __func__, __LINE__, core_id);
17986 __func__, __LINE__, rc, core_name);
17988 else if (gen_log_file)
17991 char filename[32] =
"raw_";
17992 strcat(filename, core_name);
17993 strcat(filename,
"_slot_");
17995 bool pcie_id_name =
false;
17996 char devFilePath[1024] = {0};
17997 char devFDPath[1024] = {0};
17998 char pcie[64] = {0};
17999 char domain[5] = {0}, slot[3] = {0}, dev[3] = {0}, func[2] = {0};
18001 snprintf(devFDPath,
sizeof(devFDPath),
"/proc/self/fd/%d", p_ctx->
blk_io_handle);
18002 ssize_t len = readlink(devFDPath, devFilePath,
sizeof(devFilePath)-1);
18004 devFilePath[len] =
'\0';
18006 if (strstr(devFilePath,
"/dev/nvme") != NULL)
18009 if (strlen(pcie) > 0 && strlen(slot) > 0 && strlen(domain) > 0)
18011 strcat(filename, slot);
18012 strcat(filename,
"_");
18013 strcat(filename, domain);
18014 pcie_id_name =
true;
18019 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",
18022 snprintf(num, 4,
"%d", p_ctx->
hw_id);
18023 strcat(filename, num);
18024 strcat(filename,
"_0000");
18026 strcat(filename,
".bin");
18031 snprintf(num, 4,
"%02x", p_ctx->
hw_id);
18032 strcat(filename, num);
18033 strcat(filename,
"_0000");
18034 strcat(filename,
".bin");
18038 p_file = fopen(filename,
"wb");
18042 if (fwrite((uint8_t *)p_data ,
18043 data_len, 1, p_file) != 1)
18046 __func__, __LINE__, data_len);
18050 if (fflush(p_file))
18061 __func__, __LINE__, filename);
18073 if (!p_ctx || !p_data)
18076 __func__, __LINE__, p_ctx, p_data);
18091 uint64_t ui64DestAddr,
18092 uint32_t ui32FrameSize)
18094 void *p_buffer = NULL;
18110 p_data = (uint8_t *) p_buffer;
18113 memcpy(p_data, &ui64DestAddr,
sizeof(uint64_t));
18114 memcpy(p_data + 8, &ui32FrameSize,
sizeof(uint32_t));
18115 memcpy(p_data + 12, &source->
ui16FrameIdx,
sizeof(uint16_t));
18117 memcpy(p_data + 18, &ui16Direction,
sizeof(uint16_t));
18122 NI_INVALID_DEVICE_HANDLE, p_buffer,
18134 if (p_buffer != NULL)
18144 void *p_buffer = NULL;
18146 uint32_t ui32LBA = 0;
18150 uint32_t ui32Dummy = 0;
18172 p_data = (uint8_t *) p_buffer;
18176 memcpy(p_data + 8, &ui32Dummy, 4);
18179 memcpy(p_data + 18, &ui16Direction, 2);
18184 memcpy(&p_data[24] + (i*8), &dmaAddrs->
ui64DMAAddr[i], 8);
18206 if (p_buffer != NULL)