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);
996 #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__OPEN_HARMONY__) && !defined(_ANDROID)
997 #define MAX_BDF_LEN 16
1001 static int find_pci_address(
const char *dev_name,
char *pci_addr) {
1002 char sys_block_path[256];
1004 snprintf(sys_block_path,
sizeof(sys_block_path),
"/sys/class/block/%s/device", dev_name);
1006 char *real_sysfs_path = realpath(sys_block_path, NULL);
1007 if (!real_sysfs_path) {
1008 perror(
"realpath failed");
1013 char *p = real_sysfs_path + strlen(real_sysfs_path);
1015 while (p > real_sysfs_path) {
1016 p = strrchr(real_sysfs_path,
'/');
1023 unsigned domain, bus, dev, func;
1024 if (sscanf(segment,
"%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) {
1027 free(real_sysfs_path);
1034 free(real_sysfs_path);
1042 #if defined(_WIN32) || defined(__APPLE__) || defined(__OPEN_HARMONY__)
1050 char *dom, *bus, *dev, *fnc;
1062 p_ctx->
netint_fd = open(
"/dev/netint", O_RDWR);
1070 if (stat(p_dev, &bstat) < 0)
1076 if ((bstat.st_mode & S_IFMT) != S_IFBLK)
1083 ret = snprintf(syspath,
sizeof(syspath) - 1,
1084 "/sys/block/%s/device/address",
1086 syspath[ret] =
'\0';
1088 fp = fopen(syspath,
"r");
1095 if (fgets(pci_addr,
sizeof(pci_addr), fp) == NULL)
1104 ret = find_pci_address(p_dev + 5, pci_addr);
1115 p_ctx->
domain = strtoul(pci_addr, &dom, 16);
1123 p_ctx->
bus = strtoul(dom + 1, &bus, 16);
1131 p_ctx->
dev = strtoul(bus + 1, &dev, 16);
1140 p_ctx->
fn = strtoul(dev + 1, &fnc, 16);
1155 #if __linux__ || __APPLE__
1156 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
1157 #ifndef DISABLE_BACKTRACE_PRINT
1158 void ni_print_backtrace() {
1159 void* callstack[128];
1160 int frames = backtrace(callstack, 128);
1161 char** strs = backtrace_symbols(callstack, frames);
1164 for (
int i = 0; i < frames; ++i) {
1185 void* p_buffer = NULL;
1186 uint32_t ui32LBA = 0;
1187 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
1230 "ERROR %d: %s() alloc decoder all zero buffer failed\n",
1271 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1280 uint64_t keep_alive_timeout =
1283 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
1285 keep_alive_timeout);
1296 "ERROR %s(): nvme write keep_alive_timeout command "
1297 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1313 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
1324 "ERROR %s(): nvme write sw_version command "
1325 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
1348 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __func__,
1356 "%s(): p_ctx->device_handle=0x%" PRIx64
", p_ctx->hw_id=%d, "
1357 "p_ctx->session_id=%d\n",
1420 ni_log2(p_ctx,
NI_LOG_INFO,
"Warn %s(): forceLowDelay is not available for fw < 6r3\n",
1431 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1432 "p_ctx->session_id=%d\n",
1438 decoder_dump_dir_open(p_ctx);
1441 #ifdef XCODER_DUMP_DATA
1442 char dir_name[256] = {0};
1444 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-dec-fme", (
long)getpid(),
1446 DIR *dir = opendir(dir_name);
1449 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
1475 uint32_t ui32LBA = 0;
1486 if (NI_INVALID_DEVICE_HANDLE == device_handle)
1499 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1505 "SUCCESS %s(): device_handle=%" PRIx64
" , "
1506 "session_id=%d\n", __func__, (int64_t)device_handle, session_id);
1617 void* p_buffer = NULL;
1618 uint32_t ui32LBA = 0;
1650 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1651 "buffered: %u completed: %u output: %u dropped: %u error: %u corrupted: %u\n",
1662 "Decoder_complete_info:session_id 0x%x, total frames input:%u "
1663 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
1710 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
1711 "p_ctx->session_id=%d, close_mode=1\n",
1780 low_delay_signal(p_ctx);
1797 uint32_t sent_size = 0;
1798 uint32_t packet_size = 0;
1799 int current_pkt_size;
1804 int query_retry = 0;
1805 uint32_t ui32LBA = 0;
1809 if ((!p_ctx) || (!p_packet))
1826 low_delay_wait(p_ctx);
1828 #ifdef MEASURE_LATENCY
1833 abs_time_ns, p_packet->
dts);
1839 current_pkt_size = packet_size;
1842 int max_retry = 200;
1920 "Warning: dec write query fail rc %d or available buf size %u < "
1921 "pkt size %u , retry: %d max_retry_fail_count %d\n",
1924 if (query_retry > max_retry ||
1933 if (query_retry > max_retry)
1952 "size %u >= pkt size %u !\n",
1995 "%s() had data to send: packet_size=%u, "
1996 "p_packet->sent_size=%d, p_packet->data_len=%u, "
1997 "p_packet->start_of_stream=%u, p_packet->end_of_stream=%u, "
1998 "p_packet->video_width=%u, p_packet->video_height=%u\n",
2003 uint8_t *p_data = (uint8_t *)p_packet->
p_data;
2014 p_data, packet_size, ui32LBA);
2034 char dump_file[512] = {0};
2037 snprintf(dump_file,
sizeof(dump_file),
"%s/pkt-%04ld.bin",
2039 FILE *f = fopen(dump_file,
"wb");
2042 fwrite(p_packet->
p_data, sent_size, 1, f);
2083 "%s: (first packet) pkt_index %d i %u "
2084 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2085 " pts_offsets %" PRId64
"\n",
2097 "%s: pkt_index %d i %u pkt_offsets_index_min "
2098 "%" PRIu64
" pkt_offsets_index %" PRIu64
" pts_offsets %" PRId64
2111 "%s: (wrap) pkt_index %d i %u "
2112 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index %" PRIu64
2113 " pts_offsets %" PRId64
"\n",
2136 "Error %s: failed to allocate custom SEI buffer for pkt.\n",
2152 "ERROR %s(): ni_timestamp_register() for dts returned %d\n",
2162 "%s(): exit: packets: %" PRIu64
" offset %" PRIx64
""
2163 " sent_size = %u, status=%d\n",
2164 __func__, p_ctx->
pkt_num, (uint64_t)p_packet->
pos, sent_size,
2170 "ERROR %s(): exit: returnErr: %d, p_ctx->status: %d\n", __func__,
2176 static int64_t guess_correct_pts(
ni_session_context_t* p_ctx, int64_t reordered_pts, int64_t dts)
2184 "%s: pts_correction_last_dts %" PRId64
" "
2185 "pts_correction_num_faulty_dts %d\n",
2200 "%s: pts_correction_last_pts %" PRId64
" "
2201 "pts_correction_num_faulty_pts %d\n",
2214 pts = reordered_pts;
2226 pts = reordered_pts;
2234 static int rotated_array_binary_search(uint64_t *lefts, uint64_t *rights,
2235 int32_t size, uint64_t target)
2241 int mid = lo + (hi - lo) / 2;
2242 if (lefts[mid] <= target && target < rights[mid])
2247 if (rights[mid] == 0)
2254 if (rights[lo] <= rights[mid])
2256 if (lefts[lo] <= target && target < lefts[mid])
2267 if (rights[mid] <= target && target < rights[hi])
2293 uint64_t frame_offset = 0;
2294 uint8_t *p_data_buffer = NULL;
2300 uint32_t total_bytes_to_read = 0;
2301 uint32_t read_size_bytes = 0;
2306 int query_retry = 0;
2307 uint32_t ui32LBA = 0;
2308 unsigned int bytes_read_so_far = 0;
2310 int low_delay_notify = 0;
2311 uint32_t frames_dropped = 0;
2312 uint8_t get_first_metadata = 0;
2313 uint8_t sequence_change = 0;
2317 if ((!p_ctx) || (!p_frame))
2335 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
2340 p_frame->
data_len[2] + metadata_hdr_size;
2391 ni_log2(p_ctx,
NI_LOG_TRACE,
"Warning: dec read query fail rc %d retry %d max_retry_fail_count %d\n",
2394 if (query_retry >= 1000)
2397 low_delay_notify = 1;
2414 total_bytes_to_read = metadata_hdr_size;
2415 sequence_change = 1;
2438 "WARNING: Dec eos reached but also exceeded max dec read query "
2439 "retries. is_flushed=%u try=%d.\n",
2444 "Dec eos reached. is_flushed=%u try=%d.\n",
2448 low_delay_notify = 1;
2454 " retrying ..\n", query_retry);
2468 query_retry < 1000 / 2)
2475 low_delay_signal(p_ctx);
2483 "size %u >= required size %u !\n",
2500 low_delay_signal(p_ctx);
2503 "Warning: ceased using low delay decoding mode after "
2504 "excessively long decoder read query.\n");
2507 low_delay_signal(p_ctx);
2517 if(query_retry <= 2000)
2526 "Warning: decoder pkt_num %u frame_num %u "
2527 "timeout, increasing pkt_delay_cnt to %u\n",
2551 "At least %d packets should be sent before reading the "
2568 "%ux%u frame-rate %u is_flushed %u\n",
2602 #ifdef XCODER_SELF_KILL_ERR
2607 kill(getpid(), SIGTERM);
2624 p_frame->
data_len[2] + metadata_hdr_size;
2625 p_data_buffer = (uint8_t*) p_frame->
p_buffer;
2637 "%u cb len %u hdr %d\n",
2640 p_frame->
data_len[2], metadata_hdr_size);
2646 "ERROR %s() avaliable size(%u)"
2647 "less than needed (%u)\n",
2659 void *p_metadata_buffer = NULL;
2665 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
2670 p_data_buffer = (uint8_t *)p_metadata_buffer;
2671 get_first_metadata = 1;
2673 sequence_change = 0;
2694 p_data_buffer, read_size_bytes, ui32LBA);
2703 }
else if (get_first_metadata) {
2711 get_first_metadata = 0;
2725 low_delay_notify = 1;
2738 total_bytes_to_read = total_bytes_to_read + sei_size;
2740 "include sei %u sei_size %d\n",
2741 retval, total_bytes_to_read, sei_size);
2744 bytes_read_so_far = total_bytes_to_read ;
2748 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset,
false);
2763 "is cancelled due to has_b_frames, frame_num %u\n",
2774 int64_t tmp_dts, prev_dts = INT64_MIN, ts_diff = 0;
2783 "%s(): First frame : session_id 0x%x, pic_reorder_delay: %d "
2784 "total frames input:%u buffered: %u completed: %u output: %u "
2785 "dropped: %u error: %u\n",
2804 "decoder dts queue %d %ld failed !\n",
2805 __func__, i, tmp_dts);
2810 "decoder dts queue %d %ld success !\n",
2811 __func__, i, tmp_dts);
2812 if (prev_dts != INT64_MIN) {
2813 ts_diff += labs(tmp_dts - prev_dts);
2821 ts_diff = ts_diff / nb_diff;
2825 "average diff: %ld\n", __func__, ts_diff);
2840 "decoder dts queue %d %ld failed !\n",
2841 __func__, i, tmp_dts);
2875 if (p_frame->
pts >= p_frame->
dts &&
2876 p_frame->
pts - p_frame->
dts < 1000)
2892 "decoder dts queue %d %ld success !\n",
2893 __func__, i, p_frame->
dts);
2928 "%s: (found pts) dts %" PRId64
" pts "
2929 "%" PRId64
" frame_offset %" PRIu64
" i %d "
2930 "pkt_offsets_index_min %" PRIu64
" pkt_offsets_index "
2931 "%" PRIu64
" pkt_pos %" PRIu64
" \n",
2932 __func__, p_frame->
dts, p_frame->
pts, frame_offset, i,
2947 while (p_frame->
dts < p_frame->
pts &&
2948 labs(p_frame->
pts - p_frame->
dts) > ts_diff)
2951 "dts %ld diff. %ld > ts_diff %ld\n",
2952 __func__, p_frame->
pts, p_frame->
dts,
2953 labs(p_frame->
pts - p_frame->
dts), ts_diff);
2960 "pop decoder dts queue error.\n", __func__);
2983 "ERROR: Frame pts %" PRId64
" not found for offset "
2984 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
2986 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
2988 __func__, p_frame->
dts, p_frame->
pts);
3000 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
3008 __func__, p_frame->
pts);
3018 #ifdef MEASURE_LATENCY
3025 #ifdef XCODER_DUMP_DATA
3026 char dump_file[256];
3027 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-dec-fme/fme-%04ld.yuv",
3029 FILE *f = fopen(dump_file,
"wb");
3040 "%s(): p_frame->start_of_stream=%u, "
3041 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
3042 "p_frame->video_height=%u\n",
3051 "Decoder pts queue size = %u dts queue size = %u\n\n",
3058 #ifdef MEASURE_LATENCY
3074 if (get_first_metadata && p_data_buffer)
3076 if (sequence_change && p_ctx->
frame_num)
3091 low_delay_signal(p_ctx);
3097 if (low_delay_notify)
3099 low_delay_signal(p_ctx);
3119 device_type, g_device_type_str[device_type]);
3142 switch (device_type)
3164 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 "
3165 "total_contexts:%u fw_video_mem_usage:%u "
3166 "fw_video_shared_mem_usage:%u fw_share_mem_usage:%u "
3167 "fw_p2p_mem_usage:%u active_hwuploaders:%u\n", __func__,
3183 "Overall load %u, model load %u, instance count %u\n",
3210 device_type, g_device_type_str[device_type]);
3241 void *p_buffer = NULL;
3243 uint32_t ui32LBA = 0;
3244 uint32_t max_cu_size;
3245 uint32_t block_size;
3246 int32_t width, height;
3247 int m_threshold = 0;
3248 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
3266 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() RGBA / BGRA / ARGB / AGBR resolution invalid, return\n",
3285 width = (width / 8) * 8;
3286 height = (height / 8) * 8;
3290 ((width + max_cu_size - 1) & (~(max_cu_size - 1))) *
3291 ((height + max_cu_size - 1) & (~(max_cu_size - 1))) /
3293 p_ctx->
roi_len = ((block_size + 63) & (~63));
3371 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3372 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3383 uint64_t keep_alive_timeout =
3386 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
3388 keep_alive_timeout);
3399 "ERROR %s(): nvme write keep_alive_timeout command "
3400 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3416 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
3427 "ERROR %s(): nvme write sw_version command "
3428 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
3468 ni_log2(p_ctx,
NI_LOG_ERROR,
"The bit depth or resoultion is not supported on ai enhance mode\n");
3482 "ERROR %s(): p_ctx->device_handle=%" PRIx64
", "
3483 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3518 if (m_threshold > 4 * 1024 * 1024 *
sizeof(
long))
3521 "DEFAULT_MMAP_THRESHOLD_MAX, use default value (%d)\n",
3522 m_threshold, 4 * 1024 * 1024 *
sizeof(
long));
3523 m_threshold = 4 * 1024 * 1024 *
sizeof(long);
3528 #if defined(__linux__) && !defined(_ANDROID) && !defined(__OPENHARMONY__)
3532 if (mallopt(M_MMAP_THRESHOLD, m_threshold) == 0)
3545 if (mallopt(M_TRIM_THRESHOLD, 3 * m_threshold) == 0)
3554 "Warning: this platform does not support staticMmapThreshold\n");
3561 m_threshold = (int) (m_threshold * 1.25);
3562 void *temp_buf = malloc((
size_t) m_threshold);
3563 ni_log2(p_ctx,
NI_LOG_TRACE,
"trigger a pre-mature increase in mmap&trim threshold: 0x%p = malloc(%d)\n",
3564 temp_buf, m_threshold);
3571 bool device_in_ctxt =
true;
3587 for (uint8_t ui8Index = 0; ui8Index < 20; ui8Index++)
3610 "p_ctx->sender_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3619 "p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%u\n",
3625 if ((sender_vf_ns_id.
ns_id != curr_vf_ns_id.
ns_id) ||
3626 (sender_vf_ns_id.
vf_id != curr_vf_ns_id.
vf_id))
3643 "p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
3654 "ERROR: ni_ai_query_network_ready returned %d\n", retval);
3687 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d return %d\n", __func__, __LINE__, retval);
3703 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3704 "p_ctx->session_id=%d\n",
3708 #ifdef XCODER_DUMP_DATA
3709 char dir_name[256] = {0};
3710 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-pkt", (
long)getpid(),
3712 DIR *dir = opendir(dir_name);
3715 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3723 snprintf(dir_name,
sizeof(dir_name),
"%ld-%u-enc-fme", (
long)getpid(),
3725 dir = opendir(dir_name);
3728 mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO);
3799 void* p_buffer = NULL;
3800 uint32_t ui32LBA = 0;
3825 "Encoder_complete_info:session_id 0x%x, total frames input:%u "
3826 "buffered: %u completed: %u output: %u dropped: %u error: %u\n",
3866 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
3867 "p_ctx->session_id=%d, close_mode=1\n",
3935 for (i = 0; i < 120 ; i++)
3949 low_delay_signal(p_ctx);
3960 int32_t width_stride[4] = {0};
3961 int32_t height_stride[4] = {0};
3976 width_stride, height_stride);
3979 for (
int i = 0; i < 120; i++)
4000 for (
int j = 0; j < source_height; j++)
4003 ni_frame->
p_data[0] + j * width_stride[0],
4006 for (
int j = 0; j < (source_height + 1) / 2; j++)
4009 ni_frame->
p_data[1] + j * width_stride[1],
4012 for (
int j = 0; j < (source_height + 1) / 2; j++)
4015 ni_frame->
p_data[2] + j * width_stride[2],
4031 for (
int j = 0; j < source_height; j++)
4034 ni_frame->
p_data[0] + j * width_stride[0],
4037 for (
int j = 0; j < (source_height + 1) / 2; j++)
4040 ni_frame->
p_data[1] + j * width_stride[1],
4043 for (
int j = 0; j < (source_height + 1) / 2; j++)
4046 ni_frame->
p_data[2] + j * width_stride[2],
4069 bool ishwframe =
false;
4071 uint32_t send_count = 0;
4073 uint32_t sent_size = 0;
4074 uint32_t frame_size_bytes = 0;
4079 if (!p_ctx || !p_frame)
4098 if (!((input_frame_idx > 0 &&
4104 __func__, input_frame_idx);
4123 low_delay_wait(p_ctx);
4125 #ifdef MEASURE_LATENCY
4152 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: passed video_height and video_width are not valid!, return\n");
4164 "%s: data_len[0] %u data_len[1] %u "
4165 "data_len[2] %u extra_data_len %u frame_size_bytes %u\n",
4199 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() line-%d retrun %d\n", __func__, __LINE__, retval);
4206 "Enc write query retry %d. rc=%d. Available buf size %u < "
4207 "frame size %u\n", retval, send_count,
4211 int retval_backup = retval;
4224 "Enc write query buf info exceeded max retries: "
4225 "%d, rc=%d. Available buf size %u < frame size %u\n",
4239 "Info enc write query success, available buf "
4240 "size %u >= frame size %u !\n",
4249 if (separate_metadata)
4255 p_frame->
p_data[2 + ishwframe] +
4270 "use_cur_src_as_long_term_pic %d use_long_term_ref %d\n",
4285 "%s(): ctx->force_frame_type"
4286 " %d frame->force_key_frame %d force frame_num %" PRIu64
""
4328 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
4329 "p_frame->start_of_stream=%u, p_frame->end_of_stream=%u, "
4330 "p_frame->video_width=%u, p_frame->video_height=%u, pts=0x%08x 0x%08x, "
4331 "dts=0x%08x 0x%08x, sei_len=%u, roi size=%u avg_qp=%u reconf_len=%u "
4332 "force_pic_qp=%u use_cur_src_as_long_term_pic %u use_long_term_ref "
4333 "%u start_len [%u,%u,%u] inconsecutive_transfer %u "
4334 "get_recon_frame_mode %u\n",
4338 (uint32_t)(p_frame->
pts & 0xFFFFFFFF),
4339 (uint32_t)((p_frame->
dts >> 32) & 0xFFFFFFFF),
4386 "ni_timestamp_register() for dts returned: %d\n",
4390 if (separate_metadata)
4392 uint32_t ui32LBA_metadata =
4395 "%s: p_metadata_buffer = %p, metadata_buffer_size "
4396 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4425 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
4426 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4454 "%s: p_data = %p, p_frame->buffer_size "
4455 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4487 "%s: p_data = %p, p_frame->buffer_size "
4488 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
4492 sent_size = frame_size_bytes;
4493 if (separate_metadata)
4526 int ret =
hwdl_frame(p_ctx, &hwdl_session_data, p_frame,
4547 "%s(): session=0x%x ui16FrameIdx=%u\n",
4555 size = frame_size_bytes;
4558 #ifdef XCODER_DUMP_DATA
4559 char dump_file[256];
4560 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-fme/fme-%04ld.yuv",
4563 FILE *f = fopen(dump_file,
"wb");
4586 uint32_t actual_read_size = 0;
4587 uint32_t to_read_size = 0;
4589 static long long encq_count = 0LL;
4591 int query_retry = 0;
4593 uint32_t ui32LBA = 0;
4598 int low_delay_notify = 0;
4601 if (!p_ctx || !p_packet || !p_packet->
p_data)
4621 ni_log2(p_ctx,
NI_LOG_DEBUG,
"frame_num=%" PRIu64
", pkt_num=%" PRIu64
", av1_pkt_num=%" PRIu64
"\n",
4634 low_delay_notify = 1;
4666 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: initial_frame_delay %d max_frame_delay %d ui8AdditionalFramesDelay %u current_frame_delay %d\n",
4680 "Info enc read query rc %d, available buf size %u, "
4681 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
4718 "%" PRIu64
" >= %" PRIu64
" pkt_num, keep querying p_ctx->status %d\n",
4726 low_delay_notify = 1;
4743 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",
4744 __FUNCTION__, p_ctx->
frame_num, pkt_num,
4774 actual_read_size = to_read_size;
4787 "ERROR %s(): packet buffer size %u allocation "
4789 __func__, actual_read_size);
4796 p_packet->
p_data, actual_read_size, ui32LBA);
4818 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s MetaDataSize %d FrameType %d AvgFrameQp %d ssim %d %d %d\n",
4836 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",
4860 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",
4870 if (p_meta->
ssimY != 0)
4878 #ifdef NI_LOG_SSIM_AT_INFO
4883 "%s: pkt #%" PRId64
" pts %" PRId64
" ssim "
4884 "Y %.4f U %.4f V %.4f\n", __FUNCTION__, p_ctx->
pkt_num,
4885 p_packet->
pts, (
float)p_meta->
ssimY/10000,
4886 (float)p_meta->
ssimU/10000, (
float)p_meta->
ssimV/10000);
4931 low_delay_notify = 1;
4936 #ifdef MEASURE_LATENCY
4943 #ifdef XCODER_DUMP_DATA
4944 char dump_file[256];
4945 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-enc-pkt/pkt-%04ld.bin",
4948 FILE *f = fopen(dump_file,
"wb");
4958 "%s(): %d.%u p_packet->start_of_stream=%u, "
4959 "p_packet->end_of_stream=%u, p_packet->video_width=%u, "
4960 "p_packet->video_height=%u, p_packet->dts=0x%08x 0x%08x, "
4961 "p_packet->pts=0x%08x 0x%08x, type=%u, avg_frame_qp=%u, show_frame=%d\n",
4964 (uint32_t)((p_packet->
dts >> 32) & 0xFFFFFFFF),
4965 (uint32_t)(p_packet->
dts & 0xFFFFFFFF),
4966 (uint32_t)((p_packet->
pts >> 32) & 0xFFFFFFFF),
4967 (uint32_t)(p_packet->
pts & 0xFFFFFFFF), p_packet->
frame_type,
4973 if (encq_count % 500 == 0)
4976 "Encoder pts queue size = %u dts queue size = %u\n\n",
4982 #ifdef MEASURE_LATENCY
5002 if (low_delay_notify)
5004 low_delay_signal(p_ctx);
5028 p_ctx->
last_gop_size = g_map_preset_to_gopsize[lookAheadEnable][gop_preset_index + 1];
5040 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): config encoder sequence change command failed\n",
5065 void* p_buffer = NULL;
5066 uint32_t ui32LBA = 0;
5067 char fmt_fw_api_ver1[5], fmt_fw_api_ver2[5];
5082 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use stack filter on device with FW API version < 6.4\n");
5092 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use rotate filter on device with FW API version < 6.7\n");
5102 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Cannot use in-place overlay filter on device with FW API version < 6.L\n");
5169 "ERROR %s(): p_ctx->device_handle=%" PRIx64
5170 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5178 "%s(): p_ctx->device_handle=%" PRIx64
5179 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
5184 uint64_t keep_alive_timeout =
5187 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
5189 keep_alive_timeout);
5200 "ERROR %s(): nvme write keep_alive_timeout command "
5201 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5217 __func__, fmt_fw_api_ver1, fmt_fw_api_ver2);
5228 "ERROR %s(): nvme write sw_version command "
5229 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
5248 retval = p2p_fill_pcie_address(p_ctx);
5275 void * p_buffer = NULL;
5276 uint32_t ui32LBA = 0;
5310 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
5311 "p_ctx->session_id=%d, close_mode=1\n",
5363 void *p_scaler_config = NULL;
5367 uint32_t ui32LBA = 0;
5371 if (!p_ctx || !p_params)
5397 memset(p_scaler_config, 0, buffer_size);
5418 "on device with FW API version < 6s1\n", __func__);
5424 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5425 "hw_id, %d, xcoder_inst_id: %d\n",
5438 "be in [0 , 1]. scaler_params_b is %lf, scaler_params_c is %lf\n",
5445 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5446 "hw_id, %d, xcoder_inst_id: %d\n",
5460 p_scaler_config, buffer_size, ui32LBA);
5461 if ((int32_t)retval < 0)
5464 "ERROR: ni_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
5465 ", hw_id, %d, xcoder_inst_id: %d\n",
5472 "ERROR: %s failed: blk_io_handle: %" PRIx64
","
5473 "hw_id, %d, xcoder_inst_id: %d\n",
5518 int rectangle_width,
5519 int rectangle_height,
5528 uint32_t ui32LBA = 0;
5529 uint32_t query_retry = 0;
5534 dataLen = dataLen & 0xFFFFF000;
5551 if (rgba_color == 0)
5558 "WARNING: Allocate framepool size 0 for session 0x%x\n", p_ctx->
session_id);
5564 "ERROR: %s() try to free session 0x%x framepool while it's not allocated\n",
5575 "ERROR: %s() try to free session 0x%x framepool of type %u while "
5576 "passing type %u\n",
5591 "ERROR: allocate framepool multiple times for session 0x%x "
5592 "not supported in FW API version < 6r3\n",
5599 "Expand frame pool of scaler 0x%x with %u more frames\n",
5605 "ERROR: try to expand session 0x%x framepool with type %u "
5606 "while pool type is %u\n",
5621 memset(p_data, 0x00, dataLen);
5623 p_data->picture_width = width;
5624 p_data->picture_height = height;
5625 p_data->picture_format = format;
5626 p_data->options = options;
5627 p_data->rectangle_width = rectangle_width;
5628 p_data->rectangle_height = rectangle_height;
5629 p_data->rectangle_x = rectangle_x;
5630 p_data->rectangle_y = rectangle_y;
5631 p_data->rgba_color = rgba_color;
5632 p_data->frame_index = frame_index;
5643 p_data->frame_index = frame_index;
5650 p_data->rgba_color = 0;
5680 ni_log2(p_ctx,
NI_LOG_ERROR,
"Resolution %d x %d not supported for %d format!\n", width, height, format);
5685 "Session=0x%x: Dev alloc frame: FrameIndex=%d; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5687 p_data->picture_width, p_data->picture_height,
5688 p_data->picture_format, p_data->rectangle_width,
5689 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5699 p_data, dataLen, ui32LBA);
5726 "ERROR: ni_nvme_send_admin_cmd failed: "
5727 "blk_io_handle: %" PRIx64
", hw_id, %u, xcoder_inst_id: %d\n",
5756 uint32_t ui32LBA = 0;
5761 dataLen = dataLen & 0xFFFFF000;
5763 if (!p_ctx || !p_cfg)
5782 memset(p_data, 0x00, dataLen);
5787 p_data->options = p_cfg->
options;
5806 p_data->orientation = 3;
5809 p_data->orientation = 1;
5821 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);
5827 "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",
5829 p_data->picture_width, p_data->picture_height,
5830 p_data->picture_format, p_data->rectangle_width,
5831 p_data->rectangle_height, p_data->rectangle_x,
5832 p_data->rectangle_y, p_data->orientation);
5838 p_data, dataLen, ui32LBA);
5844 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
5845 ", hw_id, %u, xcoder_inst_id: %d\n",
5849 "ERROR ni_scaler_config(): nvme command failed!\n");
5880 uint32_t ui32LBA = 0;
5886 dataLen = dataLen & 0xFFFFF000;
5888 if (!p_ctx || (!p_cfg_in && numInCfgs))
5907 memset(p_data, 0x00, dataLen);
5909 p_data_orig = p_data;
5911 for (i = 0; i < numInCfgs; i++)
5928 "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",
5930 p_data->frame_index, p_data->session_id,
5931 p_data->picture_width, p_data->picture_height,
5932 p_data->picture_format, p_data->rectangle_width,
5933 p_data->rectangle_height, p_data->rectangle_x, p_data->rectangle_y);
5953 "Session=0x%x: Dev out config frame: FrameIndex=%u; W=%d; H=%d; C=%d; RW=%d; RH=%d; RX=%d; RY=%d\n",
5955 p_data->picture_width, p_data->picture_height,
5956 p_data->picture_format, p_data->rectangle_width,
5957 p_data->rectangle_height, p_data->rectangle_x,
5958 p_data->rectangle_y);
5962 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);
5971 p_data_orig, dataLen, ui32LBA);
5977 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
5978 ", hw_id, %u, xcoder_inst_id: %d\n",
5982 "ERROR ni_scaler_config(): nvme command failed!\n");
6004 void* p_buffer = NULL;
6006 uint32_t ui32LBA = 0;
6011 if ((!p_ctx) || (!p_gen_status))
6022 __func__, device_type);
6037 memset(p_buffer, 0, dataLen);
6050 p_gen_status->fw_model_load, p_gen_status->cmd_queue_count,
6051 p_gen_status->process_load_percent);
6072 void* p_buffer = NULL;
6074 uint32_t ui32LBA = 0;
6075 uint32_t dataLen = 0;
6076 uint32_t copyLen = 0;
6097 if ((!p_ctx) || (!p_detail_status))
6108 __func__, device_type);
6121 memset(p_buffer, 0, dataLen);
6131 memcpy(p_detail_status, p_buffer, copyLen);
6154 void* p_buffer = NULL;
6156 uint32_t ui32LBA = 0;
6161 if ((!p_ctx) || (!p_stream_info))
6173 __func__, device_type);
6195 memset(p_buffer, 0, dataLen);
6207 p_stream_info->picture_width = ni_htons(p_stream_info->picture_width);
6208 p_stream_info->picture_height = ni_htons(p_stream_info->picture_height);
6209 p_stream_info->frame_rate = ni_htons(p_stream_info->frame_rate);
6210 p_stream_info->is_flushed = ni_htons(p_stream_info->is_flushed);
6211 p_stream_info->transfer_frame_stride = ni_htons(p_stream_info->transfer_frame_stride);
6213 p_stream_info->pix_format);
6241 void* p_buffer = NULL;
6242 uint64_t session_timestamp;
6243 uint32_t ui32LBA = 0;
6252 if ((!p_ctx) || (!p_session_stats))
6263 __func__, device_type);
6285 memset(p_buffer, 0, dataLen);
6305 p_session_stats->ui16SessionId = ni_htons(p_session_stats->ui16SessionId);
6306 p_session_stats->ui16ErrorCount = ni_htons(p_session_stats->ui16ErrorCount);
6307 p_session_stats->ui32LastTransactionId =
6308 ni_htonl(p_session_stats->ui32LastTransactionId);
6309 p_session_stats->ui32LastTransactionCompletionStatus =
6310 ni_htonl(p_session_stats->ui32LastTransactionCompletionStatus);
6311 p_session_stats->ui32LastErrorTransactionId = ni_htonl(p_session_stats->ui32LastErrorTransactionId);
6312 p_session_stats->ui32LastErrorStatus = ni_htonl(p_session_stats->ui32LastErrorStatus);
6313 p_session_stats->ui32Session_timestamp_high = ni_htonl(p_session_stats->ui32Session_timestamp_high);
6314 p_session_stats->ui32Session_timestamp_low = ni_htonl(p_session_stats->ui32Session_timestamp_low);
6316 session_timestamp = p_session_stats->ui32Session_timestamp_high;
6317 session_timestamp <<= 32;
6318 session_timestamp |= p_session_stats->ui32Session_timestamp_low;
6326 p_session_stats->ui32LastErrorStatus =
6329 "query timestamp:%" PRIu64
"\n", p_ctx->
session_id,
6338 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 "
6339 "ready_to_close %u session_run_state %d active_video_width %u active_video_height %u\n",
6353 #if __linux__ || __APPLE__
6354 #if !defined(_ANDROID) && !defined(__OPENHARMONY__)
6355 #ifndef DISABLE_BACKTRACE_PRINT
6356 ni_print_backtrace();
6361 p_session_stats->ui32LastTransactionCompletionStatus =
6365 }
else if (p_ctx->
session_id != p_session_stats->ui16SessionId)
6370 "%s(): device 0x%" PRIx64
" last command Failed due to wrong "
6371 "session ID. Expected 0x%x, got 0x%x keep alive last access "
6372 "time %" PRIu64
", current %" PRIu64
"\n", __func__,
6375 if (dt > 1000000000)
6378 "%s():long delay between last command dt = %" PRId64
" ns, "
6379 "process was possibly blocked.\n", __func__, dt);
6388 __func__, p_session_stats->ui16ErrorCount,
6389 p_session_stats->ui32LastTransactionCompletionStatus,
6390 p_session_stats->ui32LastErrorStatus);
6413 void* p_buffer = NULL;
6415 uint32_t ui32LBA = 0;
6420 if (!p_ctx || !p_stream_complete)
6432 __func__, device_type);
6454 memset(p_buffer, 0, dataLen);
6466 p_stream_complete->is_flushed = ni_htons(p_stream_complete->is_flushed);
6476 static const char* ni_get_device_type_str(
int type)
6480 return "Invalid device type";
6482 return g_device_type_str[type];
6490 memcpy((
void *)p_session_statistic, p_buffer,
6494 p_session_statistic->ui32RdBufAvailSize =
6495 ni_htonl(p_session_statistic->ui32RdBufAvailSize);
6496 p_session_statistic->ui32WrBufAvailSize =
6497 ni_htonl(p_session_statistic->ui32WrBufAvailSize);
6499 p_session_statistic->ui32FramesInput =
6500 ni_htonl(p_session_statistic->ui32FramesInput);
6501 p_session_statistic->ui32FramesBuffered =
6502 ni_htonl(p_session_statistic->ui32FramesBuffered);
6503 p_session_statistic->ui32FramesCompleted =
6504 ni_htonl(p_session_statistic->ui32FramesCompleted);
6505 p_session_statistic->ui32FramesOutput =
6506 ni_htonl(p_session_statistic->ui32FramesOutput);
6507 p_session_statistic->ui32FramesDropped =
6508 ni_htonl(p_session_statistic->ui32FramesDropped);
6509 p_session_statistic->ui32InstErrors =
6510 ni_htonl(p_session_statistic->ui32InstErrors);
6512 p_session_statistic->ui16SessionId =
6513 ni_htons(p_session_statistic->ui16SessionId);
6514 p_session_statistic->ui16ErrorCount =
6515 ni_htons(p_session_statistic->ui16ErrorCount);
6516 p_session_statistic->ui32LastTransactionId =
6517 ni_htonl(p_session_statistic->ui32LastTransactionId);
6518 p_session_statistic->ui32LastTransactionCompletionStatus =
6519 ni_htonl(p_session_statistic->ui32LastTransactionCompletionStatus);
6520 p_session_statistic->ui32LastErrorTransactionId =
6521 ni_htonl(p_session_statistic->ui32LastErrorTransactionId);
6522 p_session_statistic->ui32LastErrorStatus =
6523 ni_htonl(p_session_statistic->ui32LastErrorStatus);
6524 p_session_statistic->ui32Session_timestamp_high =
6525 ni_htonl(p_session_statistic->ui32Session_timestamp_high);
6526 p_session_statistic->ui32Session_timestamp_low =
6527 ni_htonl(p_session_statistic->ui32Session_timestamp_low);
6531 if (p_ctx->
session_id != p_session_statistic->ui16SessionId)
6536 "%s(): %s device 0x%" PRIx64
" last command Failed due to wrong "
6537 "session ID. Expected 0x%x, got 0x%x w_r <%u %u> keep alive "
6538 "last access time %" PRIu64
", current %" PRIu64
"\n", __func__,
6541 p_session_statistic->ui16SessionId,
6542 p_session_statistic->ui32WrBufAvailSize,
6545 if (dt > 1000000000)
6548 "%s():long delay between last command dt = %" PRId64
" ns, "
6549 "process was possibly blocked.\n", __func__, dt);
6551 p_session_statistic->ui32LastErrorStatus =
6561 __func__, p_session_statistic->ui16ErrorCount,
6562 p_session_statistic->ui32LastTransactionCompletionStatus,
6563 p_session_statistic->ui32LastErrorStatus);
6583 void *p_buffer = NULL;
6585 uint32_t ui32LBA = 0;
6591 if (!p_ctx || !p_session_statistic)
6594 "ERROR: %s() passed parameters are null!, return\n", __func__);
6602 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: %s() not supported on device with FW api version < 6.5\n", __func__);
6611 __func__, device_type);
6633 memset(p_buffer, 0, dataLen);
6642 p_buffer, dataLen, ui32LBA) < 0)
6653 ni_parse_session_statistic_info(p_ctx, p_session_statistic, p_buffer);
6658 __func__, ni_get_device_type_str(p_ctx->
device_type));
6687 void* p_buffer = NULL;
6689 uint32_t ui32LBA = 0;
6697 if (!p_ctx || !p_inst_buf_info)
6711 __func__, device_type);
6778 memset(p_buffer, 0, dataLen);
6789 p_inst_buf_info->buf_avail_size = ni_htonl(p_inst_buf_info->buf_avail_size);
6815 uint8_t enable, uint8_t hw_action,
6819 uint32_t ui32LBA = 0;
6820 void * p_buffer = NULL;
6821 uint32_t buffer_size = 0;
6850 memset(p_buffer, 0, buffer_size);
6909 uint32_t ui32LBA = 0;
6925 __func__, device_type);
6963 uint32_t ui32LBA = 0;
6979 __func__, device_type);
7018 uint32_t ui32LBA = 0;
7033 __func__, device_type);
7080 uint32_t ui32LBA = 0;
7081 void * p_buffer = NULL;
7082 uint32_t buffer_size = 0;
7098 __func__, device_type);
7119 memset(p_buffer, 0, buffer_size);
7120 memcpy(p_buffer, &len,
sizeof(len));
7150 uint32_t ui32LBA = 0;
7151 void * p_buffer = NULL;
7152 uint32_t buffer_size = 0;
7166 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR: Seq Change not supported for device type %d, return\n", device_type);
7187 memset(p_buffer, 0, buffer_size);
7215 void* p_encoder_config = NULL;
7216 void* p_encoder_roi_qp_map = NULL;
7218 uint32_t buffer_size = 0;
7220 uint32_t ui32LBA = 0;
7246 if (
ni_posix_memalign(&p_encoder_roi_qp_map, sysconf(_SC_PAGESIZE), buffer_size))
7253 memset(p_encoder_roi_qp_map, 0, buffer_size);
7257 p_encoder_roi_qp_map, buffer_size, ui32LBA);
7286 memset(p_encoder_config, 0, buffer_size);
7347 p_encoder_config, buffer_size, ui32LBA);
7384 uint32_t ui32LBA = 0;
7388 if (!p_ctx || !p_params)
7422 buffer_size, ui32LBA) < 0)
7453 if (!p_frame || !p_frame_offset)
7460 *p_frame_offset = 0;
7464 unsigned int video_data_size = p_frame->
data_len[0] + p_frame->
data_len[1] +
7471 if (rx_size == metadata_size)
7473 video_data_size = 0;
7476 if (rx_size > video_data_size)
7483 rx_size -= metadata_size;
7495 "%s: [metadata] cropRight=%u, cropLeft=%u, "
7496 "cropBottom=%u, cropTop=%u, frame_offset=%" PRIu64
", pic=%ux%u, "
7497 "pict_type=%d, crop=%ux%u, sei header: 0x%0x number %u size %u\n",
7521 #if 1 // QUADRA_SEI_FMT
7522 ni_log(
NI_LOG_DEBUG,
"ui32SeiHeader 0x%x ui16SeiNumber %d ui16SeiSize %d SEI 0x%02x%02x\n",
7524 *((uint8_t*)p_meta + metadata_size),
7525 *((uint8_t*)p_meta + metadata_size+1));
7528 uint16_t ui16SeiProcessed = 0;
7530 uint32_t ui32Offset = 0;
7539 if (pEntryHeader->
status)
7541 ui32Size = pEntryHeader->
size;
7549 ui16SeiProcessed, pEntryHeader->
status,
7550 pEntryHeader->
size, pEntryHeader->
type, ui32Size,
7552 *((uint8_t *)p_meta + metadata_size + ui32Offset),
7553 *((uint8_t *)p_meta + metadata_size + ui32Offset + 1));
7560 switch(pEntryHeader->
type)
7564 "%s: SEI message dropped (unsupported - check "
7565 "decoder SEI bitmap settings);"
7566 " type %u size %u status %u offset %u payload bytes %u\n",
7567 __func__, pEntryHeader->
type, pEntryHeader->
size,
7568 pEntryHeader->
status, ui32Offset, ui32Size);
7573 uint8_t *ptr = (uint8_t*)p_meta + metadata_size + ui32Offset;
7580 video_data_size + metadata_size + ui32Offset;
7607 "%s: close caption size %u ,"
7608 "offset %u = video size %u meta size %d off "
7611 video_data_size, metadata_size, ui32Offset);
7616 "%s: unsupported T35; type %u size %u status %u "
7618 __func__, pEntryHeader->
type, pEntryHeader->
size,
7619 pEntryHeader->
status, ui32Offset);
7625 "Error %s: T35 SEI dropped due to %s; type %u size %u status %u offset %u\n",
7626 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7627 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7644 "Error %s: User Data Unreg dropped due to %s; type %u size %u status %u offset %u\n",
7645 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7646 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7655 video_data_size + metadata_size + ui32Offset;
7660 *)((uint8_t *)p_meta + metadata_size + ui32Offset);
7682 "Error %s: mastering display info dropped due to %s; type %u size %u status %u offset %u\n",
7683 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7684 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7693 video_data_size + metadata_size + ui32Offset;
7699 (uint8_t*)p_meta + metadata_size + ui32Offset);
7708 "Error %s: content light level info dropped due to %s; type %u size %u status %u offset %u\n",
7709 __func__, pEntryHeader->
status ?
"missing payload" :
"payload size exceeded SEI buffer size",
7710 pEntryHeader->
type, pEntryHeader->
size, pEntryHeader->
status, ui32Offset);
7719 video_data_size + metadata_size + ui32Offset;
7728 "Warning %s: SEI message dropped (unsupported - check "
7729 "decoder SEI bitmap settings);"
7730 " type %u size %u status %u offset %u payload bytes %u\n",
7731 __func__, pEntryHeader->
type, pEntryHeader->
size,
7732 pEntryHeader->
status, ui32Offset, ui32Size);
7735 ui32Offset += ui32Size;
7736 pEntryHeader = (
ni_sei_header_t *)((uint8_t*)p_meta + metadata_size + ui32Offset);
7738 }
while (ui32Offset <= p_meta->sei_size && ui16SeiProcessed < p_meta->sei_number);
7744 "Error %s: number of SEI messages reported %u != processed %u\n",
7745 __func__, p_meta->
sei_number, ui16SeiProcessed);
7749 #else // QUADRA_SEI_FMT
7754 ni_sei_user_data_entry_t *pEntry;
7755 uint32_t ui32CCOffset = 0, ui32CCSize = 0;
7759 pEntry = (ni_sei_user_data_entry_t *)((uint8_t*)p_meta + metadata_size);
7762 &ui32CCOffset, &ui32CCSize))
7766 video_data_size + metadata_size + ui32CCOffset;
7779 &ui32CCOffset, &ui32CCSize))
7783 ptr = (uint8_t*)pEntry + ui32CCOffset;
7786 ui32CCSize = (ptr[8] & 0x1F) * 3;
7792 + ui32CCOffset + 10;
7797 "%s: close caption size %u ,"
7798 "offset %u = video size %u meta size %u off "
7801 video_data_size, metadata_size, ui32CCOffset);
7811 &ui32CCOffset, &ui32CCSize))
7815 video_data_size + metadata_size + ui32CCOffset;
7819 ni_dec_mastering_display_colour_volume_t* pColourVolume =
7820 (ni_dec_mastering_display_colour_volume_t*)((uint8_t*)pEntry + ui32CCOffset);
7823 pColourVolume->display_primaries_x[0],
7824 pColourVolume->display_primaries_y[0]);
7826 pColourVolume->display_primaries_x[1],
7827 pColourVolume->display_primaries_y[1]);
7829 pColourVolume->display_primaries_x[2],
7830 pColourVolume->display_primaries_y[2]);
7833 pColourVolume->white_point_x,
7834 pColourVolume->white_point_y);
7836 pColourVolume->max_display_mastering_luminance, pColourVolume->min_display_mastering_luminance);
7840 &ui32CCOffset, &ui32CCSize))
7844 video_data_size + metadata_size + ui32CCOffset;
7848 ni_content_light_level_info_t* pLightLevel =
7849 (ni_content_light_level_info_t*)((uint8_t*)pEntry + ui32CCOffset);
7851 pLightLevel->max_content_light_level, pLightLevel->max_pic_average_light_level);
7856 &ui32CCOffset, &ui32CCSize) ||
7859 &ui32CCOffset, &ui32CCSize))
7863 video_data_size + metadata_size + ui32CCOffset;
7870 #endif // QUADRA_SEI_FMT
7905 ni_device_handle_t device_handle,
bool device_in_ctxt)
7907 int i, total_types = 0, total_modules = 0;
7915 if (!p_cap || !p_data)
7928 "ERROR: Previously in context device got an invalid vendor ID 0x%X SSVID 0x%X. Netint "
7929 "ID 0x%X. Retrying\n",
7933 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
7935 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
7937 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
7941 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
7952 "ERROR: %s(): Retry got an invalid vendor ID too 0x%X SSVID "
7957 (
int)
sizeof(p_id_data->
ai8Sn), p_id_data->
ai8Sn);
7959 (
int)
sizeof(p_id_data->
ai8Mn), p_id_data->
ai8Mn);
7961 (
int)
sizeof(p_id_data->
ai8Fr), p_id_data->
ai8Fr);
7969 "Retry got valid a vendor ID 0x%X SSVID 0x%X. Netint ID 0x%X\n",
8008 "Error: mismatch; xcoder_num_elements: %d (calculated: %d) "
8009 "xcoder_num_devices: %d (calculated: %d)\n",
8066 "ERROR: Previously in context device is not a xcoder device "
8086 if (total_modules >= 1)
8101 if (total_modules >= 2)
8116 if (total_modules >= 3)
8131 if (total_modules >= 4)
8199 static uint32_t presetGopSize[] = {
8219 int pos_byte = (pos/8);
8220 int pos_in_byte = pos%8;
8221 int remaining_bytes_in_current_byte = 8 - pos_in_byte;
8223 if (pos_in_byte == 0)
8225 vui[pos_byte] = (uint8_t)(value >> 24);
8226 vui[pos_byte+1] = (uint8_t)(value >> 16);
8227 vui[pos_byte+2] = (uint8_t)(value >> 8);
8228 vui[pos_byte+3] = (uint8_t)(value);
8232 vui[pos_byte] = vui[pos_byte] + (uint8_t)(value >> (32-remaining_bytes_in_current_byte));
8233 vui[pos_byte+1] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-8));
8234 vui[pos_byte+2] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-16));
8235 vui[pos_byte+3] = (uint8_t)(value >> (32-remaining_bytes_in_current_byte-24));
8236 vui[pos_byte+4] = vui[pos_byte+4] + ((uint8_t)(value << remaining_bytes_in_current_byte));
8251 uint32_t max_pkt_size)
8255 if ((!p_ctx) || (!p_cfg) || (!p_src))
8264 bool shift_params =
false;
8292 ni_log2(p_ctx,
NI_LOG_INFO,
"%s height %d width %d fps_number %d fps_denominator %d\n",
8302 shift_params =
true;
8303 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Output 2 used before output 1, Shifting output2 settings to output1 and disabling output 2\n");
8308 if (!shift_params || i == 0)
8314 j = (i == 1) ? 2 : 1;
8320 (uint16_t)((p_dec->
crop_whxy[j][0]) & 0xFFFE);
8322 (uint16_t)((p_dec->
crop_whxy[j][1]) & 0xFFFE);
8324 (uint16_t)((p_dec->
crop_whxy[j][2]) & 0xFFFE);
8326 (uint16_t)((p_dec->
crop_whxy[j][3]) & 0xFFFE);
8378 (uint16_t)((p_dec->
scale_wh[j][0]+1) & 0xFFFE);
8380 (uint16_t)((p_dec->
scale_wh[j][1]+1) & 0xFFFE);
8397 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): maxExtraHwFrameCnt is not support for FW < 6rB\n", __func__);
8405 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (enableAdvancedEc == 2) is not support for FW < 6rO\n", __func__);
8412 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (EcPolicy == limited_error) not supported for FW < 6ri\n", __func__);
8419 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): setting ecErrThreshold not supported for FW < 6ri\n", __func__);
8426 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): (EcPolicy == best_effort_out_dc) not supported for FW < 6s1\n", __func__);
8434 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): surviveStreamErr is not supported for FW < 6rl\n", __func__);
8443 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s():Not support to reduce dpb delay and reset.\n", __func__);
8502 if ((!p_ctx) || (!p_cfg) || (!p_src))
8553 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_bitrate %d. assigned bitrate %d\n",
8571 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");
8621 ni_log2(p_ctx,
NI_LOG_DEBUG,
"### %s: Slow sequence happened retain last_framerate num %d den %d. assigned num %d den %d\n",
8639 uint32_t numUnitsInTick = 1000;
8704 "ERROR: %s() unknown value for p_t408->decoding_refresh_type: %d\n",
8728 ni_log2(p_ctx,
NI_LOG_DEBUG,
"force intraRefreshMode to 1 because quadra only supports intra refresh by rows\n");
8738 int mbRows = (p_cfg->
i32picHeight + mbHeight - 1) / mbHeight;
8773 "for profile 3 (extended) or 1 (baseline)\n");
8782 "force EnableRdoQuant 0 to accommodate HW limiation\n");
8902 if (p_enc->
crf != -1)
9050 "Turning off strongIntraSmoothing because hvsQPEnable=1 "
9051 "for better subjective VQ\n");
9063 "Turning off strongIntraSmoothing because hvsQPEnable=1 for "
9064 "better subjective VQ\n");
9098 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): spatialLayers is not supported for FW < 6rw\n", __func__);
9106 ni_log2(p_ctx,
NI_LOG_INFO,
"Warning %s(): spatialLayers is not supported for FW < 6s0\n", __func__);
9124 ni_log(
NI_LOG_INFO,
"Warning h.265 psnr_y is only supported for YUV420P, YUV420P10LE, NV12, and P010LE\n");
9134 ni_log(
NI_LOG_INFO,
"Warning reconstructed frames only supported for YUV420P, NV12\n");
9144 ni_log(
NI_LOG_INFO,
"Warning get psnr feature only support YUV420P (except for h.265 psnr_y)\n");
9150 ni_log(
NI_LOG_INFO,
"Warning get psnr feature is not supported when cropWidth x cropHeight are set\n");
9186 int gopSize = g_map_preset_to_gopsize[lookAheadEnable][p_t408->
gop_preset_index + 1];
9192 if (lookAheadEnable)
9194 int firstGopEnd = gopSize + 1 + mulitcoreDelay;
9195 int lookaheadGopEnd = mulitcoreDelay ?
9198 int initialDelayNum = (firstGopEnd > lookaheadGopEnd) ? firstGopEnd : lookaheadGopEnd;
9200 int maxLookaheadQueue = initialDelayNum + (gopSize - 1) + mulitcoreDelay;
9203 p_ctx->
max_frame_delay = ((maxDelayNum > maxLookaheadQueue) ? maxDelayNum : maxLookaheadQueue) + (mulitcoreDelay ? 4 : 0);
9226 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: firstGopEnd %d lookaheadGopEnd %d initialDelayNum %d maxDelayNum %d maxLookaheadQueue %d\n",
9227 __FUNCTION__, firstGopEnd, lookaheadGopEnd, initialDelayNum, maxDelayNum, maxLookaheadQueue);
9235 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: preset %d lookAheadDepth %d gopSize %d mulitcoreDelay %d "
9236 "last_gop_size %d linitial_frame_delay %d current_frame_delay %d max_frame_delay %d\n",
9253 if (p_enc->
qcomp != (
float)0.6)
9273 if (p_enc->
ipRatio != (
float)1.4)
9278 if (p_enc->
pbRatio != (
float)1.3)
9303 if (p_enc->
crfFloat != (
float)-1.0)
9497 for (i = 0; i < 8; i++)
9737 if( (!p_ctx) || (!p_config) )
10009 p_config->
i8crf = -1;
10068 p_config->
i8crfMax = (int8_t)(-1) + 1;
10069 p_config->
i32qcomp = (int32_t)(0.6 * 1000) + 1000;
10073 p_config->
i32ipRatio = (int32_t)(1.4 * 1000) + 1000;
10074 p_config->
i32pbRatio = (int32_t)(1.3 * 1000) + 1000;
10075 p_config->
i32cplxDecay = (int32_t)(0.5 * 1000) + 1000;
10079 p_config->
i8pass1Qp = (int8_t)(-1) + 1;
10129 uint32_t max_err_len)
10135 char *p_param_warn = NULL;
10138 if (!p_ctx || !p_cfg || !p_param_err)
10156 memset(p_param_err, 0, max_err_len);
10157 memset(p_param_warn, 0, max_err_len);
10170 strncpy(p_param_err,
"Incompatible output format: hw frame must be used if out1 or out2 used", max_err_len);
10180 strncpy(p_param_err,
"ddr_priority_mode not supported on device with FW api version < 6.e",
10189 strncpy(p_param_err,
"LowDelay is not supported on jpeg/vp9 decoder",
10203 strncpy(p_param_err,
"Invalid crop offset: extends past 48x48 minimum window", max_err_len);
10210 strncpy(p_param_err,
"Invalid crop w or h: must be at least 48x48 minimum window", max_err_len);
10217 strncpy(p_param_err,
"Invalid crop w or h: must be smaller than input", max_err_len);
10224 strncpy(p_param_err,
"Invalid crop rect: must fit in input", max_err_len);
10233 strncpy(p_param_err,
"Invalid crop value: even values only", max_err_len);
10239 strncpy(p_param_warn,
"crop param used but output not enabled!", max_err_len);
10254 strncpy(p_param_err,
"Invalid scale dimensions: zero", max_err_len);
10262 strncpy(p_param_err,
"Invalid scale value: even values only", max_err_len);
10272 strncpy(p_param_err,
"Invalid scale value: downscale only", max_err_len);
10284 strncpy(p_param_err,
"Invalid scale dimensions: downscale only after cropping", max_err_len);
10291 strncpy(p_param_warn,
"scale param used but output not enabled!", max_err_len);
10299 strncpy(p_param_warn,
"force8bit or semiPlanar used but output not enabled!", max_err_len);
10313 strncpy(p_param_err,
10314 "Invalid pairing: out=HW must be set with tiled format",
10321 strncpy(p_param_err,
"Invalid pairing: VP9 not compatible with tiled format",
10332 strncpy(p_param_err,
10333 "Invalid scale height: mult of 4 only, >= 128",
10342 strncpy(p_param_err,
10343 "Invalid scale width: mult of 128 only, >= 144",
10354 strncpy(p_param_err,
10355 "Invalid crop height: mult of 4 only, >= 128",
10364 strncpy(p_param_err,
10365 "Invalid crop width: mult of 128 only, >= 144",
10373 strncpy(p_param_err,
"Force 8 bit: not supported with tiled format\n",
10384 strncpy(p_param_err, p_param_warn, max_err_len);
10389 free(p_param_warn);
10394 static ni_retcode_t ni_check_level(
int level,
int codec_id)
10396 const int l_levels_264[] = {10, 11, 12, 13, 20, 21, 22, 30, 31, 32,
10397 40, 41, 42, 50, 51, 52, 60, 61, 62, 0};
10398 const int l_levels_265[] = {10, 20, 21, 30, 31, 40, 41,
10399 50, 51, 52, 60, 61, 62, 0};
10400 const int l_levels_av1[] = {20, 21, 30, 31, 40, 41, 50, 51, 0};
10401 const int *l_levels = l_levels_264;
10410 l_levels = l_levels_265;
10413 l_levels = l_levels_av1;
10416 while (*l_levels != 0)
10418 if (*l_levels == level)
10439 uint32_t max_err_len)
10447 if( (!p_ctx) || (!p_cfg) || (!p_src) || (!p_param_err) )
10457 memset(p_param_err, 0, max_err_len);
10458 memset(p_param_warn, 0, max_err_len);
10462 strncpy(p_param_err,
"Invalid frame_rate of 0 value", max_err_len);
10470 strncpy(p_param_err,
"Invalid i32frameRateInfo: too big", max_err_len);
10477 strncpy(p_param_err,
"Invalid i32bitRate: smaller than or equal to frame rate", max_err_len);
10484 strncpy(p_param_err,
"Invalid i32bitRate: too big", max_err_len);
10491 strncpy(p_param_err,
"Invalid i32bitRate: too low", max_err_len);
10498 strncpy(p_param_err,
"Invalid Picture Width: too small", max_err_len);
10505 strncpy(p_param_err,
"Invalid Picture Width: too big", max_err_len);
10512 strncpy(p_param_err,
"Invalid Picture Height: too small", max_err_len);
10519 strncpy(p_param_err,
"Invalid Picture Height: too big", max_err_len);
10529 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %u): both need to be specified",
10537 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height (%u x %uu): must be even",
10545 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: less than %d",
10552 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: less than %d",
10559 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10566 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10573 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10583 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: exceeds %d",
10590 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: exceeds %d",
10597 snprintf(p_param_err, max_err_len,
"Invalid Crop Width x Height: exceeds %d",
10607 snprintf(p_param_err, max_err_len,
"Invalid Crop horOffset %u and/or verOffset %u: must be even",
10615 snprintf(p_param_err, max_err_len,
"Invalid Crop Width: offset %u + crop width %u too big > %d",
10622 snprintf(p_param_err, max_err_len,
"Invalid Crop Height: offset %u + crop height %u too big > %d",
10634 snprintf(p_param_err, max_err_len,
"Invalid Picture Width: exceeds %d",
10641 snprintf(p_param_err, max_err_len,
"Invalid Picture Height: exceeds %d",
10648 snprintf(p_param_err, max_err_len,
"Invalid Picture Width x Height: exceeds %d",
10658 strncpy(p_param_err,
"Invalid input planar format: out of range", max_err_len);
10667 strncpy(p_param_err,
"Invalid input planar format for device with FW api version < 6.8",
10674 strncpy(p_param_err,
"Invalid Encoder Selected: Tiled format must be on same device",
10681 strncpy(p_param_err,
10682 "Invalid Picture Height: tiled format only supports "
10690 strncpy(p_param_err,
10691 "Invalid Picture Width: tiled format only supports "
10706 strncpy(p_param_err,
"zeroCopyMode must not be disabled for RGBA / BGRA / ABGR / ARGB pixel formats", max_err_len);
10716 strncpy(p_param_err,
"RGBA / BGRA pixel formats not supported on device with FW api version < 6.Y",
10730 snprintf(p_param_err, max_err_len,
"Unsupported pixel format %d in encoder", p_cfg->
ui8PixelFormat);
10740 strncpy(p_param_err,
"ddr_priority_mode not supported on device with FW api version < 6.e",
10750 strncpy(p_param_err,
"Invalid Encoder Level: out of range", max_err_len);
10760 strncpy(p_param_err,
"Invalid intra_mb_refresh_mode: out of range",
10772 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
10779 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
10791 strncpy(p_param_err,
10792 "Invalid custom GOP paramaters: custom gop size must > 0",
10803 strncpy(p_param_err,
10804 "Invalid custom GOP paramaters: selected gopPresetIdx is "
10805 "not compatible with custom gop",
10812 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
10819 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
10829 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset larger"
10830 " than GOP size", max_err_len);
10842 strncpy(p_param_warn,
"useLowDelayPocType is only supported for H.264. Change useLowDelayPocType to 0", max_err_len);
10850 strncpy(p_param_err,
10851 "entropyCodingMode is only supported for H.264.",
10861 strncpy(p_param_err,
10862 "av1ErrorResilientMode is only supported for AV1.",
10872 snprintf(p_param_err, max_err_len,
"%s is not supported for JPEG.",
10882 strncpy(p_param_err,
"qLevel is only supported for JPEG.",
10895 strncpy(p_param_warn,
"enableSSIM only supported on device with FW api version < 6.2 "
10896 "and the encoder is not av1_ni_quadra_enc. Reported ssim will be 0.", max_err_len);
10905 strncpy(p_param_err,
"sliceMode/sliceArg is only supported for H.264 or H.265.",
10914 int max_num_ctu_mb_row = (p_src->
source_height + ctu_mb_size - 1) / ctu_mb_size;
10918 snprintf(p_param_err, max_err_len,
"Invalid number of rows per slice: should be between 1 and %d",
10929 strncpy(p_param_err,
"useLowDelayPocType is only supported for H.264.",
10942 strncpy(p_param_warn,
"ui8enableCompensateQp only supported when device with FW api version < 6rt "
10943 "and the encoder is not av1_ni_quadra_enc and ui16maxFrameSize > 0. Reported enableCompensateQp will be 0.", max_err_len);
10955 strncpy(p_param_warn,
"enableTimecode does not need to be set for H.265. Use ni_enc_insert_timecode API"
10956 "from libxcoder directly to insert time code SEI", max_err_len);
10960 strncpy(p_param_warn,
"enableTimecode not supported for the codec used. Forcing value to 0.", max_err_len);
10977 strncpy(p_param_err,
10978 "this gopPreset is not supported for lookahead and/or CRF",
10986 bool bIsgopLowdelay =
true;
10994 bIsgopLowdelay =
false;
11000 bIsgopLowdelay =
false;
11004 if (bIsgopLowdelay)
11006 strncpy(p_param_err,
"B-frames low delay custom gop is not supported for "
11007 "lookahead and/or CRF", max_err_len);
11015 strncpy(p_param_err,
11016 "bitrateMode is invalid when lookahead is enabled (or in CRF mode)",
11027 strncpy(p_param_err,
11028 "totalCuTreeDepth is invalid without lookahead",
11036 strncpy(p_param_warn,
"totalCuTreeDepth does not take effects when its value <= lookahead depth", max_err_len);
11044 strncpy(p_param_err,
11045 "totalCuTreeDepth is not supported in multicoreJointMode",
11068 strncpy(p_param_err,
11069 "gopPresetIdx 2 is obsolete, suggest to use gopPresetIdx 9 "
11092 strncpy(p_param_err,
11093 "gopPresetIdx 6 is obsolete, suggest to use gopPresetIdx 7 "
11131 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");
11151 strncpy(p_param_warn,
"StillImageDetect or SceneChangeDetect only support gopPresetIdx=9 with FW > 6rm\n", max_err_len);
11161 strncpy(p_param_err,
11162 "currently do not support gop preset in multi spatial layers encode",
11175 strncpy(p_param_err,
11176 "higher spatial layers referencing base layer is only supported in multi spatial layers encode",
11194 strncpy(p_param_err,
"spatialLayerBitrate should only be used in multi spatial layers encode", max_err_len);
11200 strncpy(p_param_err,
"number of values specified in spatialLayerBitrate must match the total number of spatial layers", max_err_len);
11206 strncpy(p_param_err,
"spatialLayerBitrate is not supported in multicoreJointMode", max_err_len);
11216 strncpy(p_param_err,
11217 "crfMaxIframeEnable is only supported in Capped CRF mode with lookahead enabled",
11233 strncpy(p_param_err,
"Invalid profile: must be 5 (high10)",
11243 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
11244 " 3 (extended), 4 (high), or 5 (high10)", max_err_len);
11255 strncpy(p_param_err,
"Invalid gopPresetIdx for H.264 baseline profile:"
11256 " must be 1, 2, 6 or 0 (custom with no B frames)", max_err_len);
11268 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
11269 "have B frames", max_err_len);
11280 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
11281 " 4 (high), or 5 (high10)", max_err_len);
11287 strncpy(p_param_warn,
"AVC Baseline/Main/High Profile do not support 10-bit, auto convert to 8-bit", max_err_len);
11298 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
11299 "have B frames", max_err_len);
11313 strncpy(p_param_err,
11314 "Must use gopPresetIdx 1,9,10 (no "
11315 "B frames) for profile 1",
11325 strncpy(p_param_err,
"Tier is not supported for H.264", max_err_len);
11331 strncpy(p_param_err,
11332 "spatialLayers is not supported for h.264 encode",
11347 strncpy(p_param_err,
"Invalid profile: must be 2 (main10)",
11357 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
11368 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
11375 strncpy(p_param_warn,
"HEVC Main Profile does not support 10-bit, auto convert to 8-bit", max_err_len);
11380 strncpy(p_param_err,
11381 "spatialLayers is not supported for h.265 encode",
11391 strncpy(p_param_err,
"TuneBframeVisual MEDIUM is not supported for AV1", max_err_len);
11397 strncpy(p_param_err,
"Invalid profile: must be 1 (main)",
11407 strncpy(p_param_warn,
11408 "AV1 level < 2.0 is not supported, change to level 2.0",
11414 strncpy(p_param_warn,
11415 "AV1 level > 5.1 is not supported, change to level 5.1",
11425 strncpy(p_param_warn,
"confWinTop is not supported in AV1",
11433 strncpy(p_param_warn,
"confWinBottom is not supported in AV1",
11441 strncpy(p_param_warn,
"confWinLeft is not supported in AV1",
11449 strncpy(p_param_warn,
"confWinRight is not supported in AV1",
11455 strncpy(p_param_err,
11456 "masterDisplay not supported for AV1",
11462 strncpy(p_param_err,
"hrdEnable is not supported on av1 encoder",
11469 strncpy(p_param_err,
"enableAUD is not supported on av1 encoder",
11476 strncpy(p_param_err,
"maxCLL is not supported on av1 encoder",
11483 strncpy(p_param_err,
"repeatHeaders is not supported on av1 encoder",
11489 strncpy(p_param_err,
"enableSSIM is not supported on av1 encoder",
11496 strncpy(p_param_err,
"EnableRdoQuant is not supported on av1 encoder",
11503 strncpy(p_param_err,
"fillerEnable is not supported on av1 encoder",
11510 strncpy(p_param_err,
"ppsInitQp is not supported for av1 encoder",
11517 strncpy(p_param_err,
"vbvBufferReencode is not supported for av1 multicoreJointMode",
11526 strncpy(p_param_err,
"crop Parameters not supported for JPEG", max_err_len);
11532 strncpy(p_param_err,
"Tier is not supported for JPEG", max_err_len);
11538 strncpy(p_param_err,
"TuneBframeVisual is not supported for JPEG", max_err_len);
11544 strncpy(p_param_err,
11545 "masterDisplay not supported for jpeg",
11551 strncpy(p_param_err,
"confWinTop is not supported in jpeg",
11558 strncpy(p_param_err,
"confWinBottom is not supported in jpeg",
11565 strncpy(p_param_err,
"confWinLeft is not supported in jpeg",
11572 strncpy(p_param_err,
"confWinRight is not supported in jpeg",
11579 strncpy(p_param_err,
"hrdEnable is not supported on jpeg encoder",
11586 strncpy(p_param_err,
"enableAUD is not supported on jpeg encoder",
11593 strncpy(p_param_err,
"repeatHeaders is not supported on jpeg encoder",
11600 strncpy(p_param_err,
"prefTRC is not supported on jpeg encoder",
11607 strncpy(p_param_err,
"maxCLL is not supported on jpeg encoder",
11614 strncpy(p_param_err,
"colorPri is not supported on jpeg encoder",
11621 strncpy(p_param_err,
"colorTrc is not supported on jpeg encoder",
11628 strncpy(p_param_err,
"colorSpc is not supported on jpeg encoder",
11635 strncpy(p_param_err,
"sarNum is not supported on jpeg encoder",
11642 strncpy(p_param_err,
"sarDenom is not supported on jpeg encoder",
11649 strncpy(p_param_err,
11650 "videoFullRangeFlag is not supported on jpeg encoder",
11657 strncpy(p_param_err,
11658 "temporalLayersEnable is not supported on jpeg encoder",
11665 strncpy(p_param_err,
11666 "spatialLayers is not supported for jpeg encode",
11673 strncpy(p_param_err,
"LowDelay is not supported on jpeg encoder",
11680 strncpy(p_param_err,
"rdoLevel is not supported on jpeg encoder",
11687 strncpy(p_param_err,
"EnableRdoQuant is not supported on jpeg encoder",
11694 strncpy(p_param_err,
11695 "enable2PassGop is not supported on jpeg encoder",
11702 strncpy(p_param_err,
11703 "lookAheadDepth is not supported on jpeg encoder",
11710 strncpy(p_param_err,
11711 "gopPresetIdx is not supported on jpeg encoder",
11718 strncpy(p_param_err,
"roiEnable is not supported on jpeg encoder",
11725 strncpy(p_param_err,
11726 "RoiDemoMode is not supported on jpeg encoder",
11733 strncpy(p_param_err,
"cacheRoi is not supported on jpeg encoder",
11740 strncpy(p_param_err,
11741 "ReconfDemoMode is not supported on jpeg encoder",
11748 strncpy(p_param_err,
11749 "intraRefreshMode is not supported on jpeg encoder",
11756 strncpy(p_param_err,
11757 "intraRefreshArg is not supported on jpeg encoder",
11764 strncpy(p_param_err,
11765 "intraPeriod is not supported on jpeg encoder",
11774 "IntraRefreshResetOnForceIDR is not supported on jpeg encoder",
11781 strncpy(p_param_err,
11782 "longTermReferenceEnable is not supported on jpeg encoder",
11789 strncpy(p_param_err,
11790 "longTermReferenceInterval is not supported on jpeg encoder",
11797 strncpy(p_param_err,
11798 "longTermReferenceCount is not supported on jpeg encoder",
11805 strncpy(p_param_err,
11806 "multicoreJointMode is not supported on jpeg encoder",
11813 strncpy(p_param_err,
"enableSSIM is not supported on jpeg encoder",
11820 strncpy(p_param_err,
11821 "vbvBufferSize is not supported on jpeg encoder",
11828 strncpy(p_param_err,
11829 "fillerEnable is not supported on jpeg encoder",
11836 strncpy(p_param_err,
"picSkip is not supported on jpeg encoder",
11843 strncpy(p_param_err,
"maxFrameSize is not supported on jpeg encoder",
11850 strncpy(p_param_err,
11851 "cuLevelRCEnable is not supported on jpeg encoder",
11858 strncpy(p_param_err,
"hvsQPEnable is not supported on jpeg encoder",
11865 strncpy(p_param_err,
"profile is not supported on jpeg encoder",
11872 strncpy(p_param_err,
"intraRefreshMode or intraRefreshArg is not supported on jpeg encoder",
11877 if (p_cfg->
i8crf != -1)
11879 strncpy(p_param_err,
"crf is not supported on jpeg encoder",
11886 strncpy(p_param_err,
"tolCtbRcInter is not supported on jpeg encoder",
11893 strncpy(p_param_err,
"tolCtbRcIntra is not supported on jpeg encoder",
11900 strncpy(p_param_err,
11901 "rcQpDeltaRange is not supported on jpeg encoder",
11908 strncpy(p_param_err,
"bitrateWindow is not supported on jpeg encoder",
11915 strncpy(p_param_err,
"ctbRowQpStep is not supported on jpeg encoder",
11922 strncpy(p_param_err,
11923 "enableAIEnhance is not supported on jpeg encoder",
11930 strncpy(p_param_err,
"ppsInitQp is not supported for jpeg encoder",
11937 strncpy(p_param_err,
"pass1Qp is not supported for jpeg encoder",
11944 strncpy(p_param_err,
"bitrateMode is not supported for jpeg encoder",
11951 strncpy(p_param_err,
11952 "vbvBufferReencode is not supported on jpeg encoder",
11961 strncpy(p_param_err,
"Invalid forceFrameType: out of range",
11969 strncpy(p_param_err,
"Invalid forcedHeaderEnable: out of range",
11978 strncpy(p_param_err,
"Invalid decoding_refresh_type: out of range", max_err_len);
11988 strcpy(p_param_err,
"Invalid gop_preset_index: out of range");
12001 strcpy(p_param_err,
"GOP size must be 1 when lowDelay is enabled");
12010 strncpy(p_param_err,
"Invalid gopSize out of range", max_err_len);
12018 strncpy(p_param_err,
"GOP size must be <= 4 for low delay GOP", max_err_len);
12027 strncpy(p_param_err,
"Invalid LookAheadDepth: out of range. <[4-40]>", max_err_len);
12033 strncpy(p_param_err,
"2-pass encode does not support low delay GOP", max_err_len);
12039 strncpy(p_param_err,
"2-pass encode does not support tile4x4 format",
12046 strncpy(p_param_err,
"currently do not support lookahead encode with multi spatial layers", max_err_len);
12061 strncpy(p_param_err,
"Custom GOP must not include backward prediction when lowDelay is enabled", max_err_len);
12063 strncpy(p_param_err,
"Custom GOP must not include backward prediction when picSkip is enabled", max_err_len);
12076 strncpy(p_param_err,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when lowDelay is enabled", max_err_len);
12083 strncpy(p_param_err,
"Must use low delay GOP (gopPresetIdx 1,3,7,9,10) when picSkip is enabled", max_err_len);
12090 strncpy(p_param_err,
"lookAheadDepth must be 0 when lowDelay is enabled", max_err_len);
12092 strncpy(p_param_err,
"lookAheadDepth must be 0 when picSkip is enabled", max_err_len);
12100 strncpy(p_param_err,
12101 "Cannot use multicoreJointMode when lowDelay is enabled",
12104 strncpy(p_param_err,
12105 "Cannot use multicoreJointMode when picSkip is enabled",
12114 strncpy(p_param_err,
12115 "Cannot enable minFramesDelay when lowDelay is enabled",
12118 strncpy(p_param_err,
12119 "Cannot enable minFramesDelay when picSkip is enabled",
12136 strncpy(p_param_err,
"Custom GOP size must be 1 when useLowDelayPocType is enabled", max_err_len);
12142 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);
12165 "minimum frame size %d bytes in low delay mode\n", __func__,
12171 "mode. Set it to half of the maximum frame size %d bytes\n",
12178 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: maxFrameSize %u is too small. Changed to minimum value (bitrate/framerate in byte): %u\n",
12187 strncpy(p_param_err,
"maxFrameSize can only be used when lowDelay is enabled", max_err_len);
12204 strncpy(p_param_err,
"Custom GOP can not have B frames for intra refresh", max_err_len);
12214 strncpy(p_param_err,
12215 "Must use gopPresetIdx 9 (consecutive P frame) for intra refresh",
12220 strncpy(p_param_warn,
"GOP size forced to 1 and low delay GOP force disabled (no B frames) for intra refresh", max_err_len);
12227 strncpy(p_param_err,
12228 "intra refresh cycle (height / intraRefreshArg MB or CTU) must > 1",
12235 strncpy(p_param_err,
"lookaheadDepth must be 0 for intra refresh", max_err_len);
12244 strncpy(p_param_warn,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len);
12253 strncpy(p_param_warn,
"intraPeriod forced to match intra refersh cycle (intraPeriod must >= intra refersh cycle)", max_err_len);
12264 strncpy(p_param_warn,
"HRD conformance is not guaranteed in multicoreJointMode", max_err_len);
12273 snprintf(p_param_err, max_err_len,
"HRD conformance with multiple temporal layers is currently not supported");
12299 snprintf(p_param_err, max_err_len,
"vbvMaxRate %u cannot be smaller than bitrate %d",
12311 snprintf(p_param_err, max_err_len,
"vbvMinRate %u cannot be larger than bitrate %d",
12326 snprintf(p_param_err, max_err_len,
"vbvBufferSize must be greater than the average frame size. Minimum is %u msec for framerate %d fps",
12338 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",
12350 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",
12362 snprintf(p_param_warn, max_err_len,
"vbvMaxRate %u vbvMinRate %u does not take effect when vbvBufferSize is 0, force vbvMaxRate vbvMinRate to 0",
12374 strncpy(p_param_err,
12375 "Can't enable ltrRefInterval and longTermReferenceEnable "
12386 strncpy(p_param_err,
"Custom GOP size can not be > 1 for long term reference", max_err_len);
12395 strncpy(p_param_err,
12396 "Must use low delay GOP (gopPresetIdx 1,3,7,9) for long term reference",
12401 strncpy(p_param_warn,
"GOP size forced to 1 for long term reference", max_err_len);
12408 strncpy(p_param_err,
"lookaheadDepth must be 0 for long term reference", max_err_len);
12412 if (p_cfg->
i8crf >= 0)
12414 strncpy(p_param_err,
"crf must < 0 for long term reference", max_err_len);
12424 "Must set longTermReferenceEnable for longTermReferenceInterval",
12434 strncpy(p_param_warn,
"AV1 err resilient mode forced to 0 when using other codecs", max_err_len);
12444 strncpy(p_param_warn,
"Motion Constrained mode force disabled for codecs other than HEVC", max_err_len);
12454 "rdoLevel must be 1 for Motion Constrained mode 1 or 2",
12466 "multicoreJointMode must be 0 for Motion Constrained mode 2",
12478 "input resolution (or cropping window) must be 64x64 aligned for Motion Constrained mode 2",
12492 strncpy(p_param_warn,
"AVCC HVCC forced to 0 for codecs other than AVC HEVC", max_err_len);
12502 strncpy(p_param_err,
"Invalid cu_size_mode: out of range", max_err_len);
12512 strncpy(p_param_err,
"Invalid use_recommend_enc_params: out of range", max_err_len);
12530 strncpy(p_param_err,
"Invalid max_num_merge: out of range", max_err_len);
12544 strncpy(p_param_err,
"Invalid intra_qp: out of range", max_err_len);
12551 if (p_cfg->
i8crf >= 0 && p_cfg->
i8crf <= 51)
12558 strncpy(p_param_err,
"CRF requres LookAheadDepth <[4-40]>", max_err_len);
12566 strncpy(p_param_warn,
"enable lookahead of current frame", max_err_len);
12573 strncpy(p_param_err,
"CRF requires RcEnable 0", max_err_len);
12580 strncpy(p_param_warn,
"Lookahead with cuLevelRCEnable or hvsQPEnable may degrade quality", max_err_len);
12591 strncpy(p_param_err,
"tuneBframeVisual level 1 (medium) requires lookahead or crf encode", max_err_len);
12601 strncpy(p_param_err,
"Invalid enable_mb_level_rc: out of range", max_err_len);
12610 strncpy(p_param_err,
"Invalid min_qp: out of range", max_err_len);
12618 strncpy(p_param_err,
"Invalid max_qp: out of range", max_err_len);
12626 strncpy(p_param_err,
"Invalid enable_cu_level_rate_control: out of range", max_err_len);
12636 strncpy(p_param_err,
"Invalid enable_hvs_qp: out of range", max_err_len);
12646 strncpy(p_param_err,
"Invalid max_delta_qp: out of range", max_err_len);
12655 strncpy(p_param_err,
"Invalid i32vbvBufferSize: out of range", max_err_len);
12678 strncpy(p_param_err, p_param_warn, max_err_len);
12682 free(p_param_warn);
12688 char *p_param_err, uint32_t max_err_len)
12691 int32_t low_delay = 0;
12692 int32_t intra_period_gop_step_size;
12695 if (!p_param || !p_src || !p_param_err)
12704 memset(p_param_err, 0, max_err_len);
12738 intra_period_gop_step_size = 1;
12755 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: gop structure is larger than intra period", max_err_len);
12760 if (((!low_delay) && (p_param->
intra_period != 0) && ((p_param->
intra_period % intra_period_gop_step_size) != 0)) ||
12763 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: intra period is not a multiple of gop structure size", max_err_len);
12776 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
12783 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is zero or negative", max_err_len);
12788 if (min_poc > temp_poc[i])
12790 min_poc = temp_poc[i];
12798 if (temp_poc[j] == min_poc)
12807 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
12823 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
12830 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is negative", max_err_len);
12839 strncpy(p_param_err,
"Invalid custom gop parameters: ref pic delta cannot be 0", max_err_len);
12850 ni_log(
NI_LOG_ERROR,
"g%drefPic%d specified without g%drefPic%dUsed specified!\n", i, j, i, j);
12857 if (min_poc > temp_poc[i])
12859 min_poc = temp_poc[i];
12867 if (temp_poc[j] == min_poc)
12876 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
12894 if (((p_param->
cu_size_mode & 0x1) == 0) && ((align_8_width_flag != 0) || (align_8_height_flag != 0)))
12896 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);
12900 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)))
12902 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);
12906 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)))
12908 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);
12917 strncpy(p_param_err,
"Invalid conf_win_top: out of range", max_err_len);
12923 strncpy(p_param_err,
"Invalid conf_win_top: not multiple of 2", max_err_len);
12930 strncpy(p_param_err,
"Invalid conf_win_bottom: out of range", max_err_len);
12936 strncpy(p_param_err,
"Invalid conf_win_bottom: not multiple of 2", max_err_len);
12943 strncpy(p_param_err,
"Invalid conf_win_left: out of range", max_err_len);
12949 strncpy(p_param_err,
"Invalid conf_win_left: not multiple of 2", max_err_len);
12956 strncpy(p_param_err,
"Invalid conf_win_right: out of range", max_err_len);
12962 strncpy(p_param_err,
"Invalid conf_win_right: not multiple of 2", max_err_len);
12976 if( (!p_cfg) || (!p_param_err) )
12986 memset(p_param_err, 0, max_err_len);
12990 strncpy(p_param_err,
"Invalid roiEnable: out of range", max_err_len);
12997 strncpy(p_param_err,
"hvsQPEnable and roiEnable: not mutually exclusive", max_err_len);
13006 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);
13027 if (!p_encoder_params)
13156 ni_pthread_mutex_t *p_mutex;
13161 struct sched_param sched_param;
13167 sigfillset(&signal);
13178 if (((sched_param.sched_priority = sched_get_priority_max(SCHED_RR)) ==
13180 sched_setscheduler(syscall(SYS_gettid), SCHED_RR, &sched_param) < 0)
13184 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
13191 #elif defined(_WIN32)
13196 if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) ==
13207 char name[16] = {0};
13208 snprintf(name,
sizeof(name),
"%s%.2x%.4x",
"KAT", args->
hw_id, args->
session_id);
13210 prctl(PR_SET_NAME, name);
13212 pthread_setname_np(name);
13231 "%s creation timeout. session_id=0x%X requested timeout: %" PRIu64
13232 "ns, ping time delta: %" PRIu64
"ns\n ",
13284 "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u "
13285 "inst_err_no %u\n",
13298 "%s was possibly blocked. session_id=0x%X requested timeout: %" PRIu64
13299 "ns, ping time delta: %" PRIu64
"ns\n ",
13320 endtime += interval;
13365 void * p_buffer = NULL;
13366 uint32_t ui32LBA = 0;
13367 uint32_t modelled_load;
13441 "ERROR %s(): p_ctx->device_handle=%" PRIx64
13442 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
13450 "Uploader open session ID:0x%x,timestamp:%" PRIu64
"\n",
13454 uint64_t keep_alive_timeout =
13457 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
13459 keep_alive_timeout);
13470 "ERROR %s(): nvme write keep_alive_timeout command "
13471 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
13495 modelled_load >>= 10;
13500 memcpy(p_buffer, &modelled_load, 4);
13531 "%s(): p_ctx->device_handle=%" PRIx64
", p_ctx->hw_id=%d, "
13532 "p_ctx->session_id=%d\n",
13541 retval = p2p_fill_pcie_address(p_ctx);
13565 if (!src_p_ctx || !dst_p_ctx)
13567 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null!, return\n", __func__);
13578 if (src_p_ctx->
isP2P)
13583 dst_p_ctx->
bus = src_p_ctx->
bus;
13584 dst_p_ctx->
dev = src_p_ctx->
dev;
13585 dst_p_ctx->
fn = src_p_ctx->
fn;
13608 int query_retry = 0;
13620 "Session=0x%x: %s buffered_frame_index=%d return %d\n",
13630 query_sleep(p_ctx);
13631 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: query by ni_query_instance_buf_info INST_BUF_INFO_RW_UPLOAD\n", __func__);
13642 if (query_retry >=500)
13645 "scaler write exceeded max query retries. rc=%d try=%d\n",
13646 retval, query_retry);
13668 "Session=0x%x: %s got FrameIndex=%u buffered_frame_index=%d\n",
13678 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
13700 uint32_t frame_size_bytes = 0;
13701 uint32_t retry_count = 0;
13720 abs_time_ns, p_frame->pts);
13731 query_sleep(p_ctx);
13740 if (retry_count >= 500)
13743 "hwupload write exceeded max query retries. rc=%d try=%d"
13745 retval, retry_count);
13769 "size %u >= frame size %u , retry %u\n",
13808 uint32_t sent_size = 0;
13809 uint32_t frame_size_bytes = 0;
13810 uint32_t retry_count = 0;
13819 if (!p_ctx || !p_frame)
13838 #ifdef MEASURE_LATENCY
13843 abs_time_ns, p_frame->
pts);
13867 query_sleep(p_ctx);
13876 if (retry_count >= 500)
13879 "hwupload write exceeded max query retries. rc=%d try=%d"
13881 retval, retry_count);
13902 "size %u >= frame size %u , retry %u\n",
13907 #ifdef XCODER_TIMESTAMP_DTS_ENABLED
13913 "ERROR %s(): ni_timestamp_register() for dts "
13926 if (separate_metadata)
13931 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): uploader separated metadata not supported on device with FW api version < 6.S\n",
13939 ni_log2(p_ctx,
NI_LOG_ERROR,
"ERROR %s(): p_metadata_buffer is NULL, allocation failed?\n",
13949 if (separate_start)
13962 "%s(): %d.%u p_ctx->frame_num=%" PRIu64
", "
13963 "p_frame->video_width=%u, p_frame->video_height=%u, "
13964 "start_len [%u,%u,%u] inconsecutive_transfer %u\n",
13970 uint32_t ui32LBA_metadata =
13973 "%s: p_metadata_buffer = %p, metadata_buffer_size "
13974 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
13998 if (separate_start)
14011 "%s: p_start_buffer = %p, p_frame->start_buffer_size "
14012 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14040 "%s: p_data = %p, p_frame->buffer_size "
14041 "= %u, p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14048 if (separate_start)
14073 "%s: p_data = %p, p_frame->buffer_size = %u, "
14074 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
14078 sent_size = frame_size_bytes;
14079 if (separate_start)
14107 size = frame_size_bytes;
14109 #ifdef XCODER_DUMP_DATA
14110 char dump_file[256];
14111 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-hwup-fme/fme-%04ld.yuv",
14114 FILE *f = fopen(dump_file,
"wb");
14123 #ifdef MEASURE_LATENCY
14162 int query_retry = 0;
14166 if (!p_ctx || !hwdesc)
14184 query_sleep(p_ctx);
14203 if (query_retry >= 1000)
14245 void* p_buffer = NULL;
14247 uint32_t ui32LBA = 0;
14272 NI_INVALID_DEVICE_HANDLE, p_buffer,
14301 uint64_t frame_offset = 0;
14302 uint8_t *p_data_buffer = NULL;
14308 uint32_t total_bytes_to_read = 0;
14309 uint32_t total_yuv_met_size = 0;
14310 uint32_t read_size_bytes = 0;
14312 int query_retry = 0;
14313 uint32_t ui32LBA = 0;
14314 unsigned int bytes_read_so_far = 0;
14316 int low_delay_notify = 0;
14318 uint32_t frames_dropped = 0;
14320 uint8_t get_first_metadata = 0;
14321 uint8_t sequence_change = 0;
14325 if (!p_ctx || !p_frame)
14344 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
14349 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
14352 "Total bytes to read %u total_yuv_met_size %u, low_delay %u\n",
14373 query_sleep(p_ctx);
14382 &sessionStatistic);
14406 if (query_retry >= 1000)
14409 "\n", query_retry, retval);
14411 low_delay_notify = 1;
14426 "Dec read desc only hdr metadata is available. Seq change may "
14427 "have occured.\n");
14428 total_bytes_to_read = metadata_hdr_size;
14429 sequence_change = 1;
14433 ni_log2(p_ctx,
NI_LOG_TRACE,
"Dec read desc buf_size < frame_size. Retry %d\n", query_retry);
14439 "Dec read desc query, ready_to_close %u, query eos\n",
14454 "WARNING: Dec read desc query eos reached but exceeded max "
14455 "retries. is_flushed=%u try=%d.\n",
14460 "Dec read desc query eos reached. is_flushed=%u try=%d"
14465 low_delay_notify = 1;
14472 "Dec read desc available buf size == %d, query try %d, "
14486 query_retry < 1000 / 2)
14493 low_delay_signal(p_ctx);
14501 "size %u >= required size %u !\n",
14519 low_delay_signal(p_ctx);
14522 "input (B frames)? Just cancel the low delay mode then\n");
14525 low_delay_signal(p_ctx);
14535 if(query_retry <= 2000)
14544 "Warning: decoder pkt_num %u frame_num %u "
14545 "timeout, increasing pkt_delay_cnt to %u\n",
14552 "\n", query_retry, retval);
14568 "At least %d packets should be sent before reading the "
14585 "%ux%u frame-rate %u is_flushed %u\n",
14613 total_bytes_to_read = p_frame->
data_len[3] + metadata_hdr_size;
14614 p_data_buffer = (uint8_t*)p_frame->
p_buffer;
14624 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
14625 "%u cb len %u hdr %d\n",
14628 p_frame->
data_len[2], metadata_hdr_size);
14636 "ERROR %s() avaliable size(%u) less than "
14640 }
else if (total_bytes_to_read == metadata_hdr_size && !p_ctx->
frame_num)
14647 void *p_metadata_buffer = NULL;
14657 p_data_buffer = (uint8_t *)p_metadata_buffer;
14658 get_first_metadata = 1;
14659 sequence_change = 0;
14670 read_size_bytes = total_bytes_to_read;
14678 p_data_buffer, read_size_bytes, ui32LBA);
14687 }
else if (get_first_metadata) {
14695 get_first_metadata = 0;
14711 low_delay_notify = 1;
14714 p_data_buffer = (uint8_t *)p_frame->
p_buffer +
14716 memcpy(p_meta, p_data_buffer, metadata_hdr_size);
14721 metadata_hdr_size);
14753 "p_data3_1:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
14757 "p_data3_1: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
14762 "p_data3_2:sei_size=%d device_handle=%d == hw_id=%d ses_id=%d\n",
14766 "p_data3_2: ui16FrameIdx=%d NodeAddre=0x%x planar=%d bd=%d\n",
14771 "%s:sei_size=%d device_handle=%d == hw_id=%d "
14776 "%s: session=0x%x ui16FrameIdx=%u NodeAddress=0x%x, "
14777 "planar=%d bd=%d\n",
14792 total_bytes_to_read = total_bytes_to_read + sei_size;
14794 "%s decoder read desc success, retval %d "
14795 "total_bytes_to_read include sei %u sei_size %d\n",
14796 __func__, retval, total_bytes_to_read, sei_size);
14810 bytes_read_so_far = total_bytes_to_read;
14812 rx_size =
ni_create_frame(p_frame, bytes_read_so_far, &frame_offset,
true);
14827 "is cancelled due to has_b_frames, frame_num %u\n",
14838 int64_t tmp_dts, prev_dts = INT64_MIN, ts_diff = 0;
14843 "%s(): First frame : session_id 0x%x, pic_reorder_delay: %d "
14844 "total frames input:%u buffered: %u completed: %u output: %u "
14845 "dropped: %u error: %u\n",
14864 "decoder dts queue %d %ld failed !\n",
14865 __func__, i, tmp_dts);
14870 "decoder dts queue %d %ld success !\n",
14871 __func__, i, tmp_dts);
14872 if (prev_dts != INT64_MIN) {
14873 ts_diff += labs(tmp_dts - prev_dts);
14876 prev_dts = tmp_dts;
14881 ts_diff = ts_diff / nb_diff;
14885 "average diff: %ld\n", __func__, ts_diff);
14900 "decoder dts queue %d %ld failed !\n",
14901 __func__, i, tmp_dts);
14935 if (p_frame->
pts >= p_frame->
dts &&
14936 p_frame->
pts - p_frame->
dts < 1000)
14952 "decoder dts queue %d %ld success !\n",
14953 __func__, i, p_frame->
dts);
14988 "%s: (found pts) dts %" PRId64
" pts "
14989 "%" PRId64
" frame_offset %" PRIu64
" i %d "
14990 "pkt_offsets_index_min %" PRIu64
" "
14991 "pkt_offsets_index %" PRIu64
" pkt_pos %" PRIu64
"\n",
14992 __func__, p_frame->
dts, p_frame->
pts, frame_offset, i,
15007 while (p_frame->
dts < p_frame->
pts &&
15008 labs(p_frame->
pts - p_frame->
dts) > ts_diff)
15011 "dts %ld diff. %ld > ts_diff %ld\n",
15012 __func__, p_frame->
pts, p_frame->
dts,
15013 labs(p_frame->
pts - p_frame->
dts), ts_diff);
15020 "pop decoder dts queue error.\n", __func__);
15043 "ERROR: Frame pts %" PRId64
" not found for offset "
15044 "%" PRIu64
"\n", p_frame->
pts, frame_offset);
15046 "%s: (not found use default) dts %" PRId64
" pts %" PRId64
15048 __func__, p_frame->
dts, p_frame->
pts);
15061 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts);
15069 __func__, p_frame->
pts);
15079 #ifdef MEASURE_LATENCY
15090 "%s(): p_frame->start_of_stream=%u, "
15091 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
15092 "p_frame->video_height=%u\n",
15101 "Decoder pts queue size = %d dts queue size = %d\n\n",
15108 #ifdef MEASURE_LATENCY
15113 ni_log2(p_ctx,
NI_LOG_INFO,
"DTS:%" PRId64
",DELTA:%" PRId64
",dLAT:%" PRIu64
";\n",
15124 if (get_first_metadata && p_data_buffer)
15126 if (sequence_change && p_ctx->
frame_num)
15140 low_delay_signal(p_ctx);
15147 if (low_delay_notify)
15149 low_delay_signal(p_ctx);
15167 uint64_t frame_offset = 0;
15168 uint8_t *p_data_buffer;
15171 uint32_t total_bytes_to_read = 0;
15172 uint32_t read_size_bytes = 0;
15173 uint32_t ui32LBA = 0;
15182 if ((!p_ctx) || (!p_frame))
15197 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
15199 if (!p_frame->
p_data[0] || !p_data_buffer)
15221 "ERROR %s(): NI_PIXEL_PLANAR_FORMAT_TILED4X4 not supported in download.\n",
15228 unsigned int bytes_read_so_far = 0;
15231 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Total bytes to download %u, start offset = %u, chunkOffset "
15232 "%u, minorOffset %u\n",
15234 output_chunk_offset, output_minor_offset);
15236 ni_log2(p_ctx,
NI_LOG_DEBUG,
"total_bytes_to_read %u max_nvme_io_size %u ylen %u cr len "
15237 "%u cb len %u hdr %d\n",
15240 p_frame->
data_len[2], metadata_hdr_size);
15259 "Config HW download read desc success, retval %d total_bytes_to_read %u\n",
15260 retval, total_bytes_to_read);
15263 read_size_bytes = total_bytes_to_read;
15265 ui32LBA += output_chunk_offset;
15273 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
15285 "HW download read desc success, retval %d total_bytes_to_read %u\n",
15286 retval, total_bytes_to_read);
15303 "Unconfig HW download read desc success, retval %d total_bytes_to_read %u\n",
15304 retval, total_bytes_to_read);
15307 bytes_read_so_far = total_bytes_to_read;
15312 rx_size = (int)bytes_read_so_far;
15321 __func__, rx_size);
15323 "%s(): p_frame->start_of_stream=%u, "
15324 "p_frame->end_of_stream=%u, p_frame->video_width=%u, "
15325 "p_frame->video_height=%u\n",
15329 "%s(): p_ctx->frame_num %" PRIu64
", "
15330 "p_frame->data_len[0/1/2]=%u/%u/%u\n",
15359 uint64_t frame_offset = 0;
15360 uint8_t *p_data_buffer;
15363 uint32_t total_bytes_to_read = 0;
15364 uint32_t read_size_bytes = 0;
15365 uint32_t ui32LBA = 0;
15367 const char *error_flag =
"NetintQuadraErr";
15371 p_data_buffer = (uint8_t *)p_frame->
p_buffer;
15373 if (!p_frame->
p_data[0] || !p_data_buffer || 0 == p_frame->
data_len[0])
15375 ni_log(
NI_LOG_ERROR,
"ERROR %s(): passed parameters are null or p_frame->data_len is 0.\n",
15387 "ERROR %s(): Unsupported format %d for hw download.\n",
15394 unsigned int bytes_read_so_far = 0;
15399 "%u cb len %u hdr %d\n",
15400 total_bytes_to_read,
15402 p_frame->
data_len[2], metadata_hdr_size);
15407 memcpy(global_state->
error_flag, error_flag, strlen(error_flag)+1);
15411 read_size_bytes = total_bytes_to_read;
15413 ui32LBA += output_chunk_offset;
15419 "%u, minorOffset %u hwdesc->ui16FrameIdx %d ui32LBA 0x%x\n",
15421 output_chunk_offset, output_minor_offset, hwdesc->
ui16FrameIdx, ui32LBA);
15425 NI_INVALID_DEVICE_HANDLE, p_data_buffer, read_size_bytes, ui32LBA);
15434 if (!strcmp(global_state->
error_flag, error_flag) &&
15438 "size %u + offset %u out of range\n",
15439 __func__, hwdesc->
ui16FrameIdx, read_size_bytes, output_chunk_offset);
15444 bytes_read_so_far = total_bytes_to_read;
15449 rx_size = (int)bytes_read_so_far;
15457 "HW download read desc success, retval %d total_bytes_to_read %u\n",
15458 retval, total_bytes_to_read);
15477 uint8_t *p_data = NULL;
15479 uint32_t ui32LBA = 0;
15500 memset(p_data, 0, dataLen);
15502 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s(): ui16DstIdx %u, ui16SrcIdx %u, size %u, offset %u\n", __func__,
15508 p_data, dataLen, ui32LBA);
15565 uint32_t pool_size,
15568 void* p_uploader_config = NULL;
15572 uint32_t ui32LBA = 0;
15600 memset(p_uploader_config, 0, buffer_size);
15622 ni_log2(p_ctx,
NI_LOG_DEBUG,
"ni_config_instance_set_uploader_params():%d x %d x Format %d with %d framepool\n",
15630 p_uploader_config, buffer_size, ui32LBA);
15669 void* p_decoder_config = NULL;
15672 uint32_t ui32LBA = 0;
15693 ni_log2(p_ctx,
NI_LOG_INFO,
"%s() FW rev %s < 6rT-- load balancing might be affected\n", __func__,
15705 memset(p_decoder_config, 0, buffer_size);
15758 p_decoder_config, buffer_size, ui32LBA);
15801 int query_retry = 0;
15803 if (!p_ctx || !p_frame || !p_frame->
p_data[3])
15837 ni_log2(p_ctx,
NI_LOG_DEBUG,
"%s: query by ni_query_instance_buf_info INST_BUF_INFO_RW_UPLOAD\n",
15848 if (query_retry >= 1000)
15871 if (query_retry >= 1000)
15882 "Session=0x%x: %s got FrameIndex=%u\n",
15898 "%s Warning scalar read hwdesc fail rc %d or ind !\n",
15980 uint32_t *p_offset)
15992 "FrameIdx %d OOR (%d,%d]. DDR config %d \n", __func__, hwdesc->
ui16FrameIdx,
16007 void *nb_data, uint32_t nb_size)
16009 void *p_ai_config = NULL;
16010 void *p_nb_data = NULL;
16011 uint32_t buffer_size;
16015 uint32_t ui32LBA = 0;
16016 uint32_t config_size;
16017 void *p_buffer = NULL;
16020 int retry_count = 0;
16031 if (!nb_data || nb_size == 0) {
16033 __func__, nb_data, nb_size);
16056 ((
ni_ai_config_t *)p_ai_config)->ui32NetworkBinarySize = nb_size;
16069 memcpy(p_nb_data, nb_data, nb_size);
16077 p_ai_config, config_size, ui32LBA);
16083 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16084 ", hw_id, %u, xcoder_inst_id: %d\n",
16091 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16092 ", hw_id, %u, xcoder_inst_id: %d\n",
16113 memset(p_buffer, 0, dataLen);
16126 p_buffer, dataLen, ui32LBA);
16158 "AI write query failed or buf_size %u < "
16164 "Info ai write query success, available buf "
16165 "size %u >= frame size %u !\n",
16189 p_nb_data, buffer_size, ui32LBA);
16196 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16197 ", hw_id, %u, xcoder_inst_id: %d\n",
16204 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16205 ", hw_id, %u, xcoder_inst_id: %d\n",
16217 for (transferred = 0; transferred < buffer_size; transferred += this_size)
16221 (buffer_size - transferred);
16223 if (this_size & (4096 - 1))
16225 this_size = (this_size + (4096 - 1)) & ~(4096 - 1);
16229 (transferred >> 12);
16231 "%s(): write nb LBA 0x%x, this_size %u, page_offset %u\n",
16232 __func__, ui32LBA, this_size, (transferred >> 12));
16233 p_data = (uint8_t *)p_nb_data + transferred;
16236 (uint8_t *)p_nb_data + transferred, this_size, ui32LBA);
16244 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16245 ", hw_id, %u, xcoder_inst_id: %d\n",
16253 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16254 ", hw_id, %u, xcoder_inst_id: %d\n",
16280 void *p_stream_info = NULL;
16281 void *p_ai_config = NULL;
16282 void *p_nb_data = NULL;
16284 uint32_t ui32LBA = 0;
16285 uint32_t config_size;
16324 "### %s: width %d %d height %d model type %d level %d pix_format %d\n", __func__,
16335 p_stream_info, config_size, ui32LBA);
16341 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16342 ", hw_id, %u, xcoder_inst_id: %d\n",
16349 "ERROR: ni_ai_session_close failed: blk_io_handle: %" PRIx64
16350 ", hw_id, %u, xcoder_inst_id: %d\n",
16374 void *p_buffer = NULL;
16375 uint32_t ui32LBA = 0;
16376 int retry_count = 0;
16387 memset(p_buffer, 0, dataLen);
16392 p_buffer, dataLen, ui32LBA);
16430 uint32_t ui32LBA = 0;
16432 uint32_t frame_size_bytes;
16433 uint32_t sent_size = 0;
16434 int32_t query_retry = 0;
16440 if (!p_ctx || !p_frame)
16467 frame_size_bytes = p_frame->
data_len[0];
16478 "Info ai write query success, available buf "
16479 "size %u >= frame size %u !\n",
16506 "AI write query failed or buf_size < frame_size. Retry %d\n",
16512 "AI write query exceeded max retries: %d\n",
16529 if (!p_frame->
iovec) {
16546 ni_log2(p_ctx,
NI_LOG_DEBUG,
"Ai session write: p_data = %p, p_frame->buffer_size = %u, "
16547 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
16551 sent_size = frame_size_bytes;
16559 p_data, sent_size, ui32LBA);
16588 uint32_t rel_offset = 0;
16589 int32_t iovec_index = 0;
16590 int32_t iovec_left;
16592 if (!p_frame->
iovec) {
16598 for (i = 0; i < p_frame->
iovec_num; i++) {
16602 this_iovec->
ptr, this_iovec->
size);
16603 if ((this_iovec->
ptr == NULL) || (this_iovec->
size == 0) ||
16606 (
unsigned long)this_iovec->
ptr, this_iovec->
size);
16621 memset(buffer_info, 0x00, dataLen);
16627 uint32_t rel_lba = 0;
16632 for (i = 0; i < iovec_batch; i++) {
16638 rel_offset += iovec->
size;
16648 buffer_info, dataLen, ui32LBA);
16656 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
16657 ", hw_id, %u, xcoder_inst_id: %d\n",
16666 for (i = 0; i < iovec_batch; i++) {
16671 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
16684 for (i = 0; i < iovec_batch; i++) {
16688 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
16695 iovec->
ptr, sent_size, ui32LBA);
16704 iovec_index += iovec_batch;
16705 iovec_left -= iovec_batch;
16706 }
while (iovec_left);
16737 retval = frame_size_bytes;
16753 uint32_t actual_read_size = 0;
16755 uint32_t ui32LBA = 0;
16760 if (!p_ctx || !p_packet || !p_packet->
p_data)
16785 "Info ai read query success, available buf "
16786 "size %u >= frame size %u !\n",
16809 "Info ai read query rc %d, available buf size %u, "
16810 "frame_num=%" PRIu64
", pkt_num=%" PRIu64
"\n",
16831 actual_read_size = p_packet->
data_len;
16839 p_packet->
p_data, actual_read_size, ui32LBA);
16889 void *p_buffer = NULL;
16890 void *p_info = NULL;
16892 uint32_t ui32LBA = 0;
16894 int32_t query_retry = 0;
16897 uint32_t buffer_size;
16898 uint32_t this_size;
16900 uint32_t total_io_num;
16904 if (!p_ctx || !p_network)
16916 "ERROR: %s(): network parameters data is already initialized\n",
16942 memset(p_buffer, 0, dataLen);
16958 p_buffer, dataLen, ui32LBA);
16974 if (query_retry > 50000)
16977 __func__, query_retry - 1);
17022 if (!network_data->
inset)
17045 memset(p_info, 0, dataLen);
17049 p_info, dataLen, ui32LBA);
17050 if ((int32_t)retval < 0)
17072 memset(p_info, 0, dataLen);
17076 p_info, dataLen, ui32LBA);
17077 if ((int32_t)retval < 0)
17087 for (l = 0, network_data->
input_num = 0; l < 4; l++)
17097 for (l = 0, network_data->
output_num = 0; l < 4; l++)
17108 for (l = 0, buffer_size = 0; l < network_data->
input_num; l++)
17115 buffer_size += this_size;
17119 "%s(): network input layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
17125 for (l = 0, buffer_size = 0; l < network_data->
output_num; l++)
17132 buffer_size += this_size;
17136 "%s(): network output layer %d: dims %u, %u/%u/%u/%u, f %d, q %d\n",
17151 ni_unreference_network_data(network_data);
17162 void *p_buffer = NULL;
17163 uint32_t ui32LBA = 0;
17243 "ERROR %s(): p_ctx->device_handle=%" PRIx64
17244 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
17261 "%s(): p_ctx->device_handle=%" PRIx64
17262 ", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
17267 uint64_t keep_alive_timeout =
17270 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
17272 keep_alive_timeout);
17284 "ERROR %s(): nvme write keep_alive_timeout command "
17285 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n",
17296 "ERROR %s(): Unable to allocate network_data memory\n");
17311 if (!p_ctx->
iocbs) {
17318 p_ctx->
iocbs[i] = (ni_iocb_t *)malloc(
sizeof(ni_iocb_t));
17319 if (!p_ctx->
iocbs[i]) {
17353 void *p_buffer = NULL;
17354 uint32_t ui32LBA = 0;
17390 "%s(): p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
17391 "p_ctx->session_id=%d, close_mode=1\n",
17436 if (p_ctx->
iocbs) {
17475 void *p_read_data = NULL;
17477 uint32_t ui32LBA = 0;
17494 int32_t query_retry = 0;
17502 "Info ai write query success, available buf "
17519 "AI write query failed or buf_size < frame_size. Retry %d\n",
17525 "AI write query exceeded max retries: %d\n",
17548 memset(p_data, 0x00, dataLen);
17554 for(
int i = 0; i < numInCfgs; i++){
17566 p_data, dataLen, ui32LBA);
17574 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
17575 ", hw_id, %u, xcoder_inst_id: %d\n",
17586 if (p_read_data != NULL)
17598 void *p_read_data = NULL;
17600 uint32_t ui32LBA = 0;
17621 "Error: %s function not supported on device with FW API version < 6rL\n",
17628 int query_retry = 0;
17639 memset(p_read_data, 0, dataLen);
17647 p_read_data, dataLen, ui32LBA);
17671 if (query_retry > 2000)
17674 __func__, query_retry - 1);
17692 if (p_read_data != NULL)
17700 int height,
int options,
int pool_size,
17705 void *p_read_data = NULL;
17707 uint32_t ui32LBA = 0;
17727 int query_retry = 0;
17738 memset(p_read_data, 0, dataLen);
17746 p_read_data, dataLen, ui32LBA);
17763 if (query_retry > 2000)
17766 __func__, query_retry - 1);
17784 int32_t query_retry = 0;
17792 "Info ai write query success, available buf "
17809 "AI write query failed or buf_size < frame_size. Retry %d\n",
17815 "AI write query exceeded max retries: %d\n",
17838 memset(p_data, 0x00, dataLen);
17853 p_data, dataLen, ui32LBA);
17861 "ERROR: ni_nvme_send_admin_cmd failed: blk_io_handle: %" PRIx64
17862 ", hw_id, %u, xcoder_inst_id: %d\n",
17874 if (p_read_data != NULL)
17897 int retry_count = 0;
17924 if (retry_count >= 500)
17950 if (retry_count >= 500)
17987 void *p_buffer = NULL;
17990 ni_event_handle_t event_handle = NI_INVALID_EVENT_HANDLE;
17996 if (NI_INVALID_DEVICE_HANDLE == device_handle)
18071 uint8_t ddr_priority_mode)
18073 void *p_buffer = NULL;
18082 ddr_priority_mode);
18084 if (NI_INVALID_DEVICE_HANDLE == device_handle)
18103 p_cfg->
ddr_mode = ddr_priority_mode;
18108 ddr_priority_mode);
18136 void *metadata_buffer = NULL;
18139 if ((!p_frame) || (extra_len <= 0))
18142 "ERROR: %s passed parameters are null or not supported, "
18143 "p_frame %p, extra_len %d",
18144 __func__, p_frame, extra_len);
18148 int buffer_size = extra_len;
18160 "%s: free current p_frame metadata buffer, "
18161 "p_frame->buffer_size=%u\n",
18174 "ERROR %d: %s() Cannot allocate metadata buffer.\n",
18181 memset(metadata_buffer, 0, buffer_size);
18192 "%s: success: p_frame->p_metadata_buffer %p "
18193 "p_frame->metadata_buffer_size=%u\n",
18222 void *start_buffer = NULL;
18228 "ERROR: %s passed parameters are null or not supported, "
18230 __func__, p_frame);
18241 "ERROR %d: %s() Cannot allocate start buffer.\n",
18259 "%s: success: p_frame->p_start_buffer %p "
18260 "p_frame->start_buffer_size=%u\n",
18277 void *p_buffer = NULL;
18279 uint32_t ui32LBA = 0;
18282 if (!p_ctx || !p_metrics)
18285 "ERROR: %s() passed parameters are null!, return\n", __func__);
18309 p_buffer, dataLen, ui32LBA);
18352 uint32_t *u32_buf = (uint32_t *)buf;
18354 u32_buf[1] = value;
18367 CoreName = (
char *)
"all";
18370 CoreName = (
char *)
"np";
18373 CoreName = (
char *)
"ep";
18376 CoreName = (
char *)
"dp";
18379 CoreName = (
char *)
"tp";
18382 CoreName = (
char *)
"fp";
18385 CoreName = (
char *)
"Not Found";
18425 char *core_name = NULL;
18426 FILE *p_file = NULL;
18429 if (!p_ctx || !p_data)
18432 __func__, __LINE__, p_ctx, p_data);
18437 *(uint8_t *)p_data = 0x55;
18443 __func__, __LINE__, core_id);
18454 __func__, __LINE__, rc, core_name);
18456 else if (gen_log_file)
18459 char filename[32] =
"raw_";
18460 strcat(filename, core_name);
18461 strcat(filename,
"_slot_");
18463 bool pcie_id_name =
false;
18464 char devFilePath[1024] = {0};
18465 char devFDPath[1024] = {0};
18466 char pcie[64] = {0};
18467 char domain[5] = {0}, slot[3] = {0}, dev[3] = {0}, func[2] = {0};
18469 snprintf(devFDPath,
sizeof(devFDPath),
"/proc/self/fd/%d", p_ctx->
blk_io_handle);
18470 ssize_t len = readlink(devFDPath, devFilePath,
sizeof(devFilePath)-1);
18472 devFilePath[len] =
'\0';
18474 if (strstr(devFilePath,
"/dev/nvme") != NULL)
18477 if (strlen(pcie) > 0 && strlen(slot) > 0 && strlen(domain) > 0)
18479 strcat(filename, slot);
18480 strcat(filename,
"_");
18481 strcat(filename, domain);
18482 pcie_id_name =
true;
18487 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",
18490 snprintf(num, 4,
"%d", p_ctx->
hw_id);
18491 strcat(filename, num);
18492 strcat(filename,
"_0000");
18494 strcat(filename,
".bin");
18499 snprintf(num, 4,
"%02x", p_ctx->
hw_id);
18500 strcat(filename, num);
18501 strcat(filename,
"_0000");
18502 strcat(filename,
".bin");
18506 p_file = fopen(filename,
"wb");
18510 if (fwrite((uint8_t *)p_data ,
18511 data_len, 1, p_file) != 1)
18514 __func__, __LINE__, data_len);
18518 if (fflush(p_file))
18529 __func__, __LINE__, filename);
18541 if (!p_ctx || !p_data)
18544 __func__, __LINE__, p_ctx, p_data);
18559 uint64_t ui64DestAddr,
18560 uint32_t ui32FrameSize)
18562 void *p_buffer = NULL;
18578 p_data = (uint8_t *) p_buffer;
18581 memcpy(p_data, &ui64DestAddr,
sizeof(uint64_t));
18582 memcpy(p_data + 8, &ui32FrameSize,
sizeof(uint32_t));
18583 memcpy(p_data + 12, &source->
ui16FrameIdx,
sizeof(uint16_t));
18585 memcpy(p_data + 18, &ui16Direction,
sizeof(uint16_t));
18590 NI_INVALID_DEVICE_HANDLE, p_buffer,
18602 if (p_buffer != NULL)
18612 void *p_buffer = NULL;
18614 uint32_t ui32LBA = 0;
18618 uint32_t ui32Dummy = 0;
18640 p_data = (uint8_t *) p_buffer;
18644 memcpy(p_data + 8, &ui32Dummy, 4);
18647 memcpy(p_data + 18, &ui16Direction, 2);
18652 memcpy(&p_data[24] + (i*8), &dmaAddrs->
ui64DMAAddr[i], 8);
18674 if (p_buffer != NULL)