31 #elif defined(__linux__) || defined(__APPLE__)
32 #if defined(__linux__)
33 #include <sys/types.h>
36 #include <sys/ioctl.h>
39 #include <sys/ioctl.h>
48 #include <sys/syscall.h>
49 #include <sys/resource.h>
67 #ifdef XCODER_SIGNATURE_FILE
69 #include "../build/xcoder_signature_headers.h"
80 0x00, 0x00, 0x00, 0x01,
99 0x00, 0x00, 0x00, 0x01,
116 0x00, 0x00, 0x00, 0x01,
133 0x00, 0x00, 0x00, 0x01,
152 #define NI_LOGAN_XCODER_FAILURES_MAX 25
155 #define CHECK_ERR_RC(ctx, rc, opcode, type, hw_id, inst_id) \
157 ni_logan_instance_status_info_t err_rc_info = { 0 }; \
158 int err_rc = ni_logan_query_status_info(ctx, type, &err_rc_info, rc, opcode); \
159 rc = err_rc_info.inst_err_no; \
160 if (err_rc_info.sess_err_no || rc) ctx->rc_error_count++; else ctx->rc_error_count = 0; \
161 int tmp_rc = NI_LOGAN_RETCODE_FAILURE; \
162 if (err_rc_info.sess_err_no || ctx->rc_error_count >= NI_LOGAN_XCODER_FAILURES_MAX || \
163 (tmp_rc = ni_logan_nvme_check_error_code(rc, opcode, type, hw_id, inst_id))) { \
164 ni_log(NI_LOG_INFO, "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u " \
165 "inst_err_no %u rc_error_count: %d\n", __FUNCTION__, __LINE__, *inst_id, \
166 err_rc_info.sess_err_no, err_rc_info.inst_err_no, ctx->rc_error_count); \
172 #define CHECK_ERR_RC2(ctx, rc, info, opcode, type, hw_id, inst_id) \
174 rc = info.inst_err_no; \
175 if (info.sess_err_no || rc) ctx->rc_error_count++; else ctx->rc_error_count = 0; \
176 int tmp_rc = NI_LOGAN_RETCODE_FAILURE; \
177 if (info.sess_err_no || ctx->rc_error_count >= NI_LOGAN_XCODER_FAILURES_MAX || \
178 (tmp_rc = ni_logan_nvme_check_error_code(rc, opcode, type, hw_id, inst_id))) { \
179 ni_log(NI_LOG_INFO, "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u " \
180 "inst_err_no %u rc_error_count: %d\n", __FUNCTION__, __LINE__, *inst_id, \
181 info.sess_err_no, info.inst_err_no, ctx->rc_error_count); \
186 #elif defined(__linux__) || defined(__APPLE__)
187 static struct stat g_nvme_stat = {0};
189 #ifdef XCODER_SELF_KILL_ERR
190 #define CHECK_ERR_RC(ctx, rc, opcode, type, hw_id, inst_id) \
192 ni_logan_instance_status_info_t err_rc_info = { 0 }; \
193 int err_rc = ni_logan_query_status_info(ctx, type, &err_rc_info, rc, opcode); \
194 rc = err_rc_info.inst_err_no; \
195 if (err_rc_info.sess_err_no || rc) ctx->rc_error_count++; else ctx->rc_error_count = 0; \
196 if (err_rc_info.sess_err_no || ctx->rc_error_count >= NI_LOGAN_XCODER_FAILURES_MAX || \
197 ni_logan_nvme_check_error_code(rc, opcode, type, hw_id, inst_id)) { \
198 ni_log(NI_LOG_INFO, "Terminating due to persistent failures, %s() line-%d: session_no 0x%x " \
199 "sess_err_no %u inst_err_no %u rc_error_count: %d\n", __FUNCTION__, __LINE__, *inst_id, \
200 err_rc_info.sess_err_no, err_rc_info.inst_err_no, ctx->rc_error_count); \
201 kill(getpid(), SIGTERM); \
205 #define CHECK_ERR_RC2(ctx, rc, err_rc_info, opcode, type, hw_id, inst_id) \
207 rc = err_rc_info.inst_err_no; \
208 if (err_rc_info.sess_err_no || rc) ctx->rc_error_count++; else ctx->rc_error_count = 0; \
209 if (err_rc_info.sess_err_no || ctx->rc_error_count >= NI_LOGAN_XCODER_FAILURES_MAX || \
210 ni_logan_nvme_check_error_code(rc, opcode, type, hw_id, inst_id)) { \
211 ni_log(NI_LOG_INFO, "Terminating due to persistent failures, %s() line-%d: session_no 0x%x " \
212 "sess_err_no %u inst_err_no %u rc_error_count: %d\n", __FUNCTION__, __LINE__, *inst_id, \
213 err_rc_info.sess_err_no, err_rc_info.inst_err_no, ctx->rc_error_count); \
214 kill(getpid(), SIGTERM); \
218 #define CHECK_ERR_RC(ctx, rc, opcode, type, hw_id, inst_id) \
220 ni_logan_instance_status_info_t err_rc_info = { 0 }; \
221 int err_rc = ni_logan_query_status_info(ctx, type, &err_rc_info, rc, opcode); \
222 rc = err_rc_info.inst_err_no; \
223 if (err_rc_info.sess_err_no || rc) ctx->rc_error_count++; else ctx->rc_error_count = 0; \
224 int tmp_rc = NI_LOGAN_RETCODE_FAILURE; \
225 if (err_rc_info.sess_err_no || ctx->rc_error_count >= NI_LOGAN_XCODER_FAILURES_MAX || \
226 (tmp_rc = ni_logan_nvme_check_error_code(rc, opcode, type, hw_id, inst_id))) { \
227 ni_log(NI_LOG_INFO, "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u " \
228 "inst_err_no %u rc_error_count: %d\n", __FUNCTION__, __LINE__, *inst_id, \
229 err_rc_info.sess_err_no, err_rc_info.inst_err_no, ctx->rc_error_count); \
235 #define CHECK_ERR_RC2(ctx, rc, err_rc_info, opcode, type, hw_id, inst_id) \
237 rc = err_rc_info.inst_err_no; \
238 if (err_rc_info.sess_err_no || rc) ctx->rc_error_count++; else ctx->rc_error_count = 0; \
239 int tmp_rc = NI_LOGAN_RETCODE_FAILURE; \
240 if (err_rc_info.sess_err_no || ctx->rc_error_count >= NI_LOGAN_XCODER_FAILURES_MAX || \
241 (tmp_rc = ni_logan_nvme_check_error_code(rc, opcode, type, hw_id, inst_id))) { \
242 ni_log(NI_LOG_INFO, "Persistent failures detected, %s() line-%d: session_no 0x%x sess_err_no %u " \
243 "inst_err_no %u rc_error_count: %d\n", __FUNCTION__, __LINE__, *inst_id, \
244 err_rc_info.sess_err_no, err_rc_info.inst_err_no, ctx->rc_error_count); \
253 #define CHECK_VPU_RECOVERY(ret) \
255 if (NI_LOGAN_RETCODE_NVME_SC_VPU_RECOVERY == ret) { \
256 ni_log(NI_LOG_TRACE, "Error, vpu reset.\n"); \
257 ret = NI_LOGAN_RETCODE_ERROR_VPU_RECOVERY; \
262 static int rotated_array_binary_search(uint64_t *lefts, uint64_t *rights, uint32_t size, uint64_t target)
268 int mid = lo + (hi - lo) / 2;
269 if (lefts[mid] <= target && target < rights[mid])
274 if (rights[mid] == 0)
281 if (rights[lo] <= rights[mid])
283 if (lefts[lo] <= target && target < lefts[mid])
296 if (rights[mid] <= target && target < rights[hi])
320 #elif defined(__linux__) || defined(__APPLE__)
322 char dir_name[128] = { 0 };
323 char file_name[128] = { 0 };
326 struct dirent *stream_folder;
327 int curr_stream_idx = 0;
328 int earliest_stream_idx = 0;
329 int max_exist_idx = 0;
330 time_t earliest_time = 0;
331 struct stat file_stat;
335 if (! p_device_context)
342 flock(p_device_context->
lock, LOCK_EX);
345 if (0 != access(dir_name, F_OK))
347 if (0 != mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO))
358 if (NULL == (dir = opendir(dir_name)))
367 while ((stream_folder = readdir(dir)))
369 if (! strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
371 curr_stream_idx =
atoi(&(stream_folder->d_name[strlen(
"stream")]));
372 if (curr_stream_idx > 0)
374 if (curr_stream_idx > max_exist_idx)
376 max_exist_idx = curr_stream_idx;
378 if (32 == curr_stream_idx)
389 if (max_exist_idx < 32)
391 curr_stream_idx = max_exist_idx + 1;
397 while ((stream_folder = readdir(dir)))
401 if (! strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
403 snprintf(file_name,
sizeof(file_name),
"%s/%s/pkt-0001.bin",
404 dir_name, stream_folder->d_name);
406 curr_stream_idx =
atoi(&(stream_folder->d_name[strlen(
"stream")]));
408 if (curr_stream_idx > 0 && 0 == access(file_name, F_OK))
411 if (stat(file_name, &file_stat))
418 if (0 == earliest_stream_idx ||
419 file_stat.st_mtime < earliest_time)
421 earliest_stream_idx = curr_stream_idx;
422 earliest_time = file_stat.st_mtime;
429 curr_stream_idx = earliest_stream_idx;
433 snprintf(file_name,
sizeof(file_name),
"%s/stream%02d/pkt-0001.bin",
434 dir_name, curr_stream_idx);
435 if (utime(file_name, NULL))
444 "%s/stream%02d", dir_name, curr_stream_idx);
465 flock(p_device_context->
lock, LOCK_UN);
468 snprintf(file_name,
sizeof(file_name),
"%s/process_session_id.txt",
471 fp = fopen(file_name,
"wb");
474 char number[64] = {
'\0'};
476 snprintf(number,
sizeof(number),
"proc id: %ld\nsession id: %u\n",
478 fwrite(number, strlen(number), 1, fp);
493 #elif defined(__linux__)
495 char dir_name[128] = { 0 };
496 char file_name[128] = { 0 };
499 struct dirent *stream_folder;
500 int curr_stream_idx = 0;
501 int earliest_stream_idx = 0;
502 int max_exist_idx = 0;
503 time_t earliest_time = 0;
504 struct stat file_stat;
508 if (! p_device_context)
515 flock(p_device_context->
lock, LOCK_EX);
518 if (0 != access(dir_name, F_OK))
520 if (0 != mkdir(dir_name, S_IRWXU | S_IRWXG | S_IRWXO))
531 if (NULL == (dir = opendir(dir_name)))
540 while ((stream_folder = readdir(dir)))
542 if (! strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
544 curr_stream_idx =
atoi(&(stream_folder->d_name[strlen(
"stream")]));
545 if (curr_stream_idx > 0)
547 if (curr_stream_idx > max_exist_idx)
549 max_exist_idx = curr_stream_idx;
551 if (32 == curr_stream_idx)
562 if (max_exist_idx < 32)
564 curr_stream_idx = max_exist_idx + 1;
570 while ((stream_folder = readdir(dir)))
574 if (! strncmp(stream_folder->d_name,
"stream", strlen(
"stream")))
576 curr_stream_idx =
atoi(&(stream_folder->d_name[strlen(
"stream")]));
577 if (curr_stream_idx > 0)
579 if (0 == earliest_stream_idx ||
580 file_stat.st_mtime < earliest_time)
582 earliest_stream_idx = curr_stream_idx;
583 earliest_time = file_stat.st_mtime;
589 curr_stream_idx = earliest_stream_idx;
595 "%s/stream%02d", dir_name, curr_stream_idx);
619 flock(p_device_context->
lock, LOCK_UN);
634 uint32_t model_load = 0;
635 uint32_t low_delay_mode = 0;
636 void *p_signature = NULL;
637 uint32_t buffer_size = 0;
638 void* p_buffer = NULL;
640 uint32_t ui32LBA = 0;
646 ni_log(
NI_LOG_TRACE,
"ERROR %s(): passed parameters are null!, return\n", __FUNCTION__);
709 "Setting model load with guess of 30fps\n");
765 "%" PRIx64
", hw_id, %d\n", __FUNCTION__,
775 "p_ctx->blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, "
776 "p_ctx->session_id=%d\n", __FUNCTION__,
785 session_info.
model_load = ni_logan_htonl(model_load);
796 ni_log(
NI_LOG_ERROR,
"ERROR %s(): \"lowDelay\" must be specified in low_delay_mode %d\n",
818 ": %" PRIx64
", hw_id, %d\n", __FUNCTION__,
827 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
829 __FUNCTION__, keep_alive_timeout);
841 "failed, blk_io_handle: %" PRIx64
", hw_id, %d\n", __FUNCTION__,
848 ", p_ctx->session_id=%d\n", __FUNCTION__,
887 "p_ctx->session_id=%d\n", __FUNCTION__,
892 decoder_dump_dir_open(p_ctx);
913 ni_device_handle_t device_handle,
914 ni_event_handle_t event_handle,
918 uint32_t ui32LBA = 0;
929 if (NI_INVALID_DEVICE_HANDLE == device_handle)
940 __FUNCTION__, (int64_t) device_handle, session_id);
946 __FUNCTION__, (int64_t) device_handle, session_id);
1060 void* p_buffer = NULL;
1061 uint32_t ui32LBA = 0;
1081 ni_log(
NI_LOG_ERROR,
"Decoder_complete_info: session_id 0x%x, total frames input: %u "
1082 "buffered: %u completed: %u output: %u dropped: %u , "
1104 "p_ctx->hw_id=%d, p_ctx->session_id=%d, close_mode=1\n", __FUNCTION__,
1174 uint64_t codec_end_time = tv.tv_sec*1000000ULL + tv.tv_usec;
1191 ni_log(
NI_LOG_INFO,
"Warning Decoder HW[%d] INST[%d]-average usage equals to 0\n",
1196 "total_time:%" PRIu64
" us\n", p_ctx->
frame_num,
1218 uint32_t sent_size = 0;
1219 uint32_t packet_size = 0;
1220 uint32_t write_size_bytes = 0;
1221 uint32_t actual_sent_size = 0;
1222 uint32_t pkt_chunk_count = 0;
1225 int query_retry = 0;
1226 uint32_t ui32LBA = 0;
1227 #ifdef MEASURE_LATENCY
1228 struct timespec logtv;
1229 uint64_t abs_time_ns;
1234 if (!p_ctx || !p_packet)
1248 #ifdef MEASURE_LATENCY
1253 clock_gettime(CLOCK_REALTIME, &logtv);
1254 abs_time_ns = (logtv.tv_sec*1000000000LL+logtv.tv_nsec);
1256 ni_logan_lat_meas_q_add_entry(p_ctx->
frame_time_q, abs_time_ns, p_packet->
dts);
1261 int current_pkt_size = p_packet->
data_len;
1275 "buf size %u < pkt size %u , retry: %d\n", retval,
1284 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
1286 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
1318 "p_packet->sent_size=%d, p_packet->data_len=%d, "
1319 "p_packet->start_of_stream=%d, p_packet->end_of_stream=%d, "
1320 "p_packet->video_width=%d, p_packet->video_height=%d\n",
1325 uint32_t send_count = 0;
1326 uint8_t* p_data = (uint8_t*)p_packet->
p_data;
1333 p_dec_packet_info->packet_size = packet_size;
1355 p_data, packet_size, ui32LBA);
1375 char dump_file[128] = { 0 };
1376 long curr_pkt_num = ((long)p_ctx->
pkt_num %
1379 snprintf(dump_file,
sizeof(dump_file),
"%s/pkt-%04ld.bin",
1382 FILE *f = fopen(dump_file,
"wb");
1385 fwrite(p_packet->
p_data, sent_size, 1, f);
1465 "%d\n", __FUNCTION__, retval);
1473 "sent_size = %u, available_space = %u, status=%d\n", __FUNCTION__,
1474 p_ctx->
pkt_num, (uint64_t)p_packet->
pos, sent_size,
1481 __FUNCTION__, retval, p_ctx->
status);
1510 pts = reordered_pts;
1524 pts = reordered_pts;
1541 uint64_t frame_offset = 0;
1544 uint8_t* p_data_buffer = (uint8_t*) p_frame->
p_buffer;
1550 int frame_cycle = 0;
1551 uint32_t total_bytes_to_read = 0;
1552 uint32_t read_size_bytes = 0;
1553 uint32_t actual_read_size = 0;
1554 int keep_processing = 1;
1556 int query_retry = 0;
1561 uint32_t ui32LBA = 0;
1562 unsigned int bytes_read_so_far = 0;
1564 #ifdef MEASURE_LATENCY
1565 struct timespec logtv;
1566 uint64_t abs_time_ns;
1571 if (!p_ctx || !p_frame)
1588 p_frame->
data_len[2] + metadata_hdr_size;
1604 retval, query_retry);
1606 if (query_retry >= 1000)
1611 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
1613 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
1618 total_bytes_to_read = metadata_hdr_size;
1626 ni_log(
NI_LOG_TRACE,
"Info dec query, ready_to_close %u, ready_to_flush %u, ctx status %d,"
1641 ni_log(
NI_LOG_INFO,
"Info eos reached or flush buffers exceeding max retries: is_flushed %u try %d.\n",
1658 " retrying ..\n", query_retry);
1659 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
1661 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
1679 (query_retry < max_query_retries))
1685 "size %u >= required size %u !\n",
1692 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
1694 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
1698 else if (p_ctx->
frame_num + decoder_reorder_delay < p_ctx->pkt_num &&
1703 "from the decoder, increase reorder count: %d, received frame_num: "
1704 "%" PRIu64
", sent pkt_num: %" PRIu64
", sending another packet.\n",
1713 "from the decoder, assume dropped, received frame_num: "
1714 "%" PRIu64
", sent pkt_num: %" PRIu64
", pkt_num-frame_num: "
1715 "%d, sending another packet.\n", p_ctx->
frame_num,
1756 "to %ux%u, reorder_delay=%u\n",
1774 #ifdef XCODER_SELF_KILL_ERR
1778 kill(getpid(), SIGTERM);
1794 p_frame->
data_len[2] + metadata_hdr_size;
1795 p_data_buffer = (uint8_t*) p_frame->
p_buffer;
1799 "available: %u\n", p_frame->
buffer_size, total_bytes_to_read,
1807 "cr len %d cb len %d hdr %d\n", total_bytes_to_read,
1809 p_frame->
data_len[2], metadata_hdr_size);
1815 "or more than buffer allocated (%u)\n", __FUNCTION__,
1828 p_data_buffer, read_size_bytes, ui32LBA);
1860 total_bytes_to_read = total_bytes_to_read + sei_size;
1863 "sei %d sei_size %d frame_cycle %d\n", __FUNCTION__, retval,
1864 total_bytes_to_read, sei_size, frame_cycle);
1867 bytes_read_so_far = total_bytes_to_read;
1915 if (p_frame->
pts >= p_frame->
dts && p_frame->
pts - p_frame->
dts < 1000)
1965 p_frame->
pts = guess_correct_pts(p_ctx, p_frame->
pts, p_frame->
dts, p_ctx->
last_pts);
1978 "p_frame->end_of_stream=%d p_frame->video_width=%d "
1993 #ifdef MEASURE_LATENCY
1999 clock_gettime(CLOCK_REALTIME, &logtv);
2000 abs_time_ns = (logtv.tv_sec*1000000000LL+logtv.tv_nsec);
2005 ni_logan_lat_meas_q_check_latency(p_ctx->
frame_time_q, abs_time_ns, p_frame->
dts),
2015 ni_log(
NI_LOG_ERROR,
"ni_logan_decoder_session_read(): bad exit, retval = %d\n",retval);
2016 void* p_buffer = NULL;
2017 void* p_debug_data_buffer = NULL;
2020 uint32_t debug_dataLen;
2028 memset(p_buffer, 0, dataLen);
2043 ni_log(
NI_LOG_ERROR,
"DEBUG INFO(): Core[%d][%d] ErrInst 0x%x, PktTotal %d, PktSize 0x%x, BufAddr 0x%x, WrPtr 0x%x, RdPtr 0x%x, Size %d\n",
2067 char dump_info_file[128] = { 0 };
2068 char dump_data_file[128] = { 0 };
2069 char dump_info[256] = { 0 };
2076 localtime_s(&cur_tm, (time_t*)&tv.tv_sec);
2078 localtime_r((time_t*)&tv.tv_sec, &cur_tm);
2081 decoder_dump_dir_create(p_ctx);
2083 snprintf(cur_date,20,
"%d-%02d-%02d", cur_tm.tm_year+1900,cur_tm.tm_mon+1,cur_tm.tm_mday);
2084 snprintf(cur_time,20,
"%02d_%02d_%02d", cur_tm.tm_hour,cur_tm.tm_min,cur_tm.tm_sec);
2088 snprintf(dump_info_file,
sizeof(dump_info_file),
"%s/%s_%s_%u_%u_%u_DEBUG_INFO.txt",
2095 FILE *fp_info = fopen(dump_info_file,
"wb");
2102 snprintf(dump_info,
sizeof(dump_info),
"DEBUG INFO(): Core[%d][%d] ErrInst 0x%x, PktTotal %d, PktSize 0x%x, BufAddr 0x%x, WrPtr 0x%x, RdPtr 0x%x, Size %d\n",
2115 fwrite(dump_info, strlen(dump_info), 1, fp_info);
2121 snprintf(dump_data_file,
sizeof(dump_data_file),
"%s/%s_%s_%u_%u_%u_DEBUG_DATA.bin",
2128 FILE *fp_data = fopen(dump_data_file,
"wb");
2137 memset(p_buffer, 0, dataLen);
2153 ni_logan_instance_debugInfo.ui8DataPktSeqNum,
2154 ni_logan_instance_debugInfo.ui8DataPktSeqTotal - 1);
2158 memset(p_debug_data_buffer, 0, debug_dataLen);
2173 fwrite(p_debug_data_buffer, debug_dataLen, 1, fp_data);
2234 "active_contexts %d temperature %d\n", __FUNCTION__,
2253 uint32_t buffer_size = 0;
2254 void *p_signature = NULL;
2256 uint32_t model_load = 0;
2258 void* p_buffer = NULL;
2260 int query_retry = 0;
2261 uint32_t ui32LBA = 0;
2283 for (c = 0; c < 20; c++)
2384 "%" PRIx64
", hw_id, %d\n", __FUNCTION__,
2394 "blk_io_handle=%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
2407 session_info.
model_load = ni_logan_htonl(model_load);
2408 #ifdef ENCODER_SYNC_QUERY
2437 "%" PRIx64
", hw_id, %d\n", __FUNCTION__,
2447 memcpy(p_buffer, &keep_alive_timeout,
sizeof(keep_alive_timeout));
2449 __FUNCTION__, keep_alive_timeout);
2461 "failed blk_io_handle: %" PRIx64
", hw_id, %d\n", __FUNCTION__,
2472 ni_log(
NI_LOG_DEBUG,
"Warning: ni_logan_config_instance_set_encoder_params() vpu recovery\n");
2477 ni_log(
NI_LOG_ERROR,
"ERROR: calling ni_logan_config_instance_set_encoder_params(): p_ctx->device_handle="
2478 "%" PRIx64
", p_ctx->hw_id=%d, p_ctx->session_id=%d\n",
2525 "inst_err_no %u inst_info.wr_buf_avail_size %d retry ..\n",
2539 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __FUNCTION__,
2610 void* p_buffer = NULL;
2611 uint32_t ui32LBA = 0;
2631 ni_log(
NI_LOG_ERROR,
"Encoder_complete_info: session_id 0x%x, total frames input: %u "
2632 "buffered: %u completed: %u output: %u dropped: %u , "
2654 "p_ctx->session_id=%d, close_mode=1\n", __FUNCTION__,
2723 uint64_t codec_end_time = tv.tv_sec*1000000ULL + tv.tv_usec;
2735 ni_log(
NI_LOG_INFO,
"Warning Encoder HW[%d] INST[%d]-average usage equals to 0\n",
2764 uint32_t send_count = 0;
2766 uint32_t tx_size = 0, aligned_tx_size = 0;
2767 uint32_t sent_size = 0;
2768 uint32_t frame_size_bytes = 0;
2773 #ifdef MEASURE_LATENCY
2774 struct timespec logtv;
2775 uint64_t abs_time_ns;
2780 if (!p_ctx || !p_frame)
2796 #ifdef MEASURE_LATENCY
2801 clock_gettime(CLOCK_REALTIME, &logtv);
2802 abs_time_ns = (logtv.tv_sec*1000000000LL+logtv.tv_nsec);
2804 ni_logan_lat_meas_q_add_entry(p_ctx->
frame_time_q, abs_time_ns, p_frame->
dts);
2828 ni_log(
NI_LOG_TRACE,
"ERROR: passed video_height and video_width are not valid! return\n");
2860 "available buf size %u < frame size %u !\n", send_count, retval,
2872 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
2874 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
2922 "frame->force_key_frame %d force frame_num %" PRIu64
" type to %d"
2923 "p_param->intra_refresh_reset %d\n", __FUNCTION__,
2943 ni_log(
NI_LOG_TRACE,
"%s(): %d.%d p_ctx->frame_num=%" PRIu64
", p_frame->start_of_stream=%u, end_of_stream=%u, "
2944 "video_width=%u, video_height=%u, pts=0x%08x 0x%08x, dts=0x%08x 0x%08x, sei_len=%u, roi size=%u "
2945 "avg_qp=%u reconf_len=%u force_pic_qp=%u force_headers=%u frame_force_type_enable=%u frame_force_type=%u "
2946 "force_pic_qp_enable=%u force_pic_qp_i/p/b=%u use_cur_src_as_long_term_pic %u use_long_term_ref %u\n",
2950 (uint32_t)((p_frame->
pts >> 32) & 0xFFFFFFFF),
2951 (uint32_t)(p_frame->
pts & 0xFFFFFFFF),
2952 (uint32_t)((p_frame->
dts >> 32) & 0xFFFFFFFF),
2953 (uint32_t)(p_frame->
dts & 0xFFFFFFFF),
3000 ni_log(
NI_LOG_ERROR,
"ERROR %s(): ni_logan_timestamp_register() for dts returned: %d\n", __FUNCTION__, retval);
3003 if (isseparate_metadata)
3007 uint32_t ui32LBA_MetaData =
3010 "%s: separate_metadata case: "
3011 "p_data = %p, p_buffer = %p, "
3012 "p_data_len[3] = %u, extra_data_len = %u, "
3013 "p_ctx->frame_num = %" PRIu64
", ui32LBA_MetaData = 0x%x, ui32LBA = 0x%x\n",
3027 p_frame->
p_data[3], sent_size,
3041 "%s: separate_metadata case: "
3042 "p_data[0] = %p, data_len[0] = %x, "
3043 "p_data[1] = %p, data_len[1] = %x, "
3044 "p_data[2] = %p, data_len[2] = %x, "
3045 "p_ctx->frame_num = %" PRIu64
", LBA = 0x%x\n",
3058 p_frame->
p_data[0], sent_size,
3075 "p_ctx->frame_num = %"PRIu64
", LBA = 0x%x\n", __FUNCTION__,
3077 sent_size = frame_size_bytes;
3084 p_frame->
p_buffer, sent_size, ui32LBA);
3096 size = frame_size_bytes;
3115 uint32_t actual_read_size = 0, chunk_size, end_of_pkt;
3116 uint32_t actual_read_size_aligned = 0;
3117 int reading_partial_pkt = 0;
3118 uint32_t to_read_size = 0;
3120 uint32_t query_return_size = 0;
3121 uint8_t* p_data = NULL;
3123 uint32_t ui32LBA = 0;
3124 uint32_t query_retry = 0;
3129 #ifdef MEASURE_LATENCY
3130 struct timespec logtv;
3131 uint64_t abs_time_ns;
3136 if (!p_ctx || !p_packet || !p_packet->
p_data)
3168 "frame_num=%"PRIu64
", pkt_num=%"PRIu64
" reading_partial_pkt %d\n",
3170 p_ctx->
pkt_num, reading_partial_pkt);
3206 "latency mode %d, buf_full %d eos sent %d, frame_num %"PRIu64
" "
3207 ">= %"PRIu64
" pkt_num, retry limit exceeded and exit encoder "
3222 " %d, reading_partial_pkt %d, frame_num %"PRIu64
" >= %"PRIu64
" "
3223 "pkt_num, keep querying.\n",
3228 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
3230 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
3259 if ((to_read_size + actual_read_size_aligned) > p_packet->
buffer_size)
3263 to_read_size + actual_read_size_aligned, p_packet->
buffer_size);
3269 (uint8_t *)p_packet->
p_data + actual_read_size_aligned,
3270 to_read_size, ui32LBA);
3283 actual_read_size_aligned);
3296 if (0 == actual_read_size)
3302 memmove((uint8_t *)p_packet->
p_data + actual_read_size,
3303 (uint8_t*)p_packet->
p_data + actual_read_size_aligned +
3305 actual_read_size += chunk_size;
3308 actual_read_size_aligned = actual_read_size;
3316 __FUNCTION__, chunk_size, actual_read_size, actual_read_size_aligned,
3321 reading_partial_pkt = 1;
3322 goto enc_read_query;
3325 p_packet->
data_len = actual_read_size;
3352 "video_width=%d, video_height=%d, dts=0x%08x 0x%08x, pts=0x%08x 0x%08x, "
3353 "type=%u, avg_frame_qp=%u\n", __FUNCTION__, p_ctx->
hw_id,
3356 (uint32_t)((p_packet->
dts >> 32) & 0xFFFFFFFF),
3357 (uint32_t)(p_packet->
dts & 0xFFFFFFFF),
3358 (uint32_t)((p_packet->
pts >> 32) & 0xFFFFFFFF),
3359 (uint32_t)(p_packet->
pts & 0xFFFFFFFF), p_packet->
frame_type,
3363 __FUNCTION__, p_packet->
data_len, size);
3365 if (p_ctx->
pkt_num % 500 == 0)
3374 #ifdef MEASURE_LATENCY
3380 clock_gettime(CLOCK_REALTIME, &logtv);
3381 abs_time_ns = (logtv.tv_sec*1000000000LL+logtv.tv_nsec);
3386 ni_logan_lat_meas_q_check_latency(p_ctx->
frame_time_q, abs_time_ns, p_packet->
dts),
3431 "active_contexts %d temperature %d\n", __FUNCTION__,
3458 void* p_buffer = NULL;
3460 uint32_t ui32LBA = 0;
3466 if (!p_ctx || !p_gen_status)
3491 memset(p_buffer, 0, dataLen);
3531 void* p_buffer = NULL;
3533 uint32_t ui32LBA = 0;
3539 if (!p_ctx || !p_stream_info)
3570 memset(p_buffer, 0, dataLen);
3617 void* p_buffer = NULL;
3618 uint32_t ui32LBA = 0;
3624 if (!p_ctx || !p_status_info)
3655 memset(p_buffer, 0, dataLen);
3699 "query timestamp:%" PRIu64
", sess_err_no:%d\n",
3737 "completed: %u output: %u dropped: %u ,inst_errors: %u\n",
3779 void* p_buffer = NULL;
3781 uint32_t ui32LBA = 0;
3788 if (!p_ctx || !p_inst_buf_info)
3841 memset(p_buffer, 0, dataLen);
3885 uint32_t ui32LBA = 0;
3886 void * p_buffer = NULL;
3887 uint32_t buffer_size = 0;
3915 memset(p_buffer, 0, buffer_size);
3975 uint32_t ui32LBA = 0;
4031 uint32_t ui32LBA = 0;
4086 uint32_t ui32LBA = 0;
4136 void* p_encoder_config = NULL;
4140 uint32_t ui32LBA = 0;
4165 memset(p_encoder_config, 0, buffer_size);
4189 snprintf(&str_vui[i * 3], 4,
"%.2x ", p_cfg->
ui8VuiRbsp[i]);
4224 p_encoder_config, buffer_size, ui32LBA);
4231 ni_log(
NI_LOG_TRACE,
"ERROR: ni_logan_nvme_send_write_cmd failed: blk_io_handle: %" PRIx64
", "
4237 ni_log(
NI_LOG_TRACE,
"ERROR: ni_logan_encoder_session_close failed: blk_io_handle: %" PRIx64
", "
4254 static int find_sei(uint32_t sei_header,
4257 uint32_t *pSeiOffset,
4262 if ( (!pEntry) || (!pSeiOffset) || (!pSeiSize) )
4267 if (sei_header & (1 << type))
4269 *pSeiOffset = pEntry[type].
offset;
4270 *pSeiSize = pEntry[type].
size;
4272 __FUNCTION__, type, *pSeiOffset, *pSeiSize);
4280 static int find_prefix_suffix_t35(uint32_t sei_header,
4284 uint32_t *pCcOffset,
4290 if (!pEntry || !pCcOffset || !pCcSize)
4301 if (sei_header & (1 << type))
4303 ptr = (uint8_t*) pEntry + pEntry[type].offset;
4310 *pCcOffset = pEntry[type].
offset;
4311 *pCcSize = pEntry[type].
size;
4312 ni_log(
NI_LOG_TRACE,
"%s: close Caption SEI found in T.35 type %d, offset: %u size: %u\n",
4313 __FUNCTION__, type, *pCcOffset, *pCcSize);
4322 *pCcOffset = pEntry[type].
offset;
4323 *pCcSize = pEntry[type].
size;
4325 __FUNCTION__, type, *pCcOffset, *pCcSize);
4334 static int find_t35_sei(uint32_t sei_header,
4337 uint32_t *pCcOffset,
4342 if ( (!pEntry) || (!pCcOffset) || (!pCcSize) )
4347 *pCcOffset = *pCcSize = 0;
4350 if (find_prefix_suffix_t35(sei_header, t35_type, pEntry,
4352 pCcOffset, pCcSize) ||
4353 find_prefix_suffix_t35(sei_header, t35_type, pEntry,
4355 pCcOffset, pCcSize) ||
4356 find_prefix_suffix_t35(sei_header, t35_type, pEntry,
4358 pCcOffset, pCcSize) ||
4359 find_prefix_suffix_t35(sei_header, t35_type, pEntry,
4361 pCcOffset, pCcSize) ||
4362 find_prefix_suffix_t35(sei_header, t35_type, pEntry,
4364 pCcOffset, pCcSize) ||
4365 find_prefix_suffix_t35(sei_header, t35_type, pEntry,
4384 uint32_t rx_size = read_length;
4386 if (!p_frame || !p_frame_offset)
4392 uint8_t* p_buf = (uint8_t*) p_frame->
p_buffer;
4394 *p_frame_offset = 0;
4397 unsigned int video_data_size = p_frame->
data_len[0] + p_frame->
data_len[1] + \
4398 p_frame->data_len[2] + ((is_hw_frame) ? p_frame->
data_len[3] : 0);
4400 __FUNCTION__, rx_size, video_data_size, metadata_size);
4404 if (rx_size == metadata_size)
4406 video_data_size = 0;
4409 if (rx_size > video_data_size)
4415 rx_size -= metadata_size;
4426 "cropBottom=%u, cropTop=%u, frame_offset=%" PRIu64
", pic=%ux%u %dbits, pict_type=%d, "
4427 "crop=%ux%u, sei header: 0x%0x number %u size %u \n", __FUNCTION__,
4448 uint32_t ui32CCOffset = 0, ui32CCSize = 0;
4455 &ui32CCOffset, &ui32CCSize))
4459 video_data_size + metadata_size + ui32CCOffset;
4472 &ui32CCOffset, &ui32CCSize))
4476 ptr = (uint8_t*)pEntry + ui32CCOffset;
4479 ui32CCSize = (ptr[8] & 0x1F) * 3;
4485 + ui32CCOffset + 10;
4490 "size %u meta size %u off %u + 10\n", __FUNCTION__,
4492 metadata_size, ui32CCOffset);
4501 &ui32CCOffset, &ui32CCSize))
4505 video_data_size + metadata_size + ui32CCOffset;
4530 &ui32CCOffset, &ui32CCSize))
4534 video_data_size + metadata_size + ui32CCOffset;
4546 &ui32CCOffset, &ui32CCSize) ||
4549 &ui32CCOffset, &ui32CCSize))
4553 video_data_size + metadata_size + ui32CCOffset;
4556 ui32CCSize, ui32CCOffset);
4562 p_frame->
vui_len = ui32CCSize;
4563 p_frame->
vui_offset = video_data_size + metadata_size + ui32CCOffset;
4572 &ui32CCOffset, &ui32CCSize))
4576 video_data_size + metadata_size + ui32CCOffset;
4581 "bytes\n", *((uint8_t*)pEntry + ui32CCOffset), ui32CCSize);
4619 int i, total_modules;
4622 if ( (!p_cap) || (!p_data) )
4666 if (total_modules >= 1)
4681 if (total_modules >= 2)
4696 if (total_modules >= 3)
4711 if (total_modules >= 4)
4756 static uint32_t presetGopSize[] = {
4767 static uint32_t presetGopKeyFrameFactor[] = {
4794 if ( (!p_ctx) || (!p_cfg) || (!p_src) )
5083 "for profile 3 (extended) or 1 (baseline)\n");
5171 if (p_src->
crf >= 0)
5187 " hvsQPEnable=1, hvsQPScale=2, maxDeltaQP=51.\n",
5319 for (i = 0; i < 8; i++)
5440 if (!p_ctx || !p_config)
5693 uint32_t max_err_len)
5698 if ( (!p_ctx) || (!p_cfg) || (!p_src) || (!p_param_err) )
5705 memset(p_param_err, 0, max_err_len);
5709 strncpy(p_param_err,
"Invalid frame_rate of 0 value", max_err_len);
5716 strncpy(p_param_err,
"Invalid i32bitRate: smaller than or equal to frame rate", max_err_len);
5723 strncpy(p_param_err,
"Invalid i32bitRate: too big", max_err_len);
5730 strncpy(p_param_err,
"Invalid i32bitRate of 0 value", max_err_len);
5737 strncpy(p_param_err,
"Invalid Picture Width: too small", max_err_len);
5744 strncpy(p_param_err,
"Invalid Picture Width: too big", max_err_len);
5751 strncpy(p_param_err,
"Invalid Picture Height: too small", max_err_len);
5758 strncpy(p_param_err,
"Invalid Picture Height: too big", max_err_len);
5768 strncpy(p_param_err,
"Invalid cannot disable timing_info and "
5769 "enable hrd at the same time", max_err_len);
5775 int32_t num_mb_or_ctu_row = (p_src->
source_height + 16 - 1) / 16;
5776 int32_t num_mb_or_ctu_col = (p_src->
source_width + 16 - 1) / 16;
5780 num_mb_or_ctu_col = (p_src->
source_width + 64 - 1) / 64;
5786 strncpy(p_param_err,
"Invalid intraRefreshMode: 4 not supported for AVC",
5793 strncpy(p_param_err,
"Invalid crf not supported for AVC",
5801 strncpy(p_param_err,
"Invalid intraRefreshArg: should be greater than 0",
5808 strncpy(p_param_err,
"Invalid intraRefreshArg: should not be greater than "
5809 "number of MB/CTU of height when intraRefreshMode=1", max_err_len);
5815 strncpy(p_param_err,
"Invalid intraRefreshArg: should not be greater than "
5816 "number of MB/CTU of width when intraRefreshMode=2", max_err_len);
5822 num_mb_or_ctu_row * num_mb_or_ctu_col))
5824 strncpy(p_param_err,
"Invalid intraRefreshArg: should not be greater than "
5825 "number of MB/CTU of frame when intraRefreshMode=3/4", max_err_len);
5831 strncpy(p_param_err,
"Error: lossless coding should be disabled when "
5832 "intraRefreshMode=4", max_err_len);
5838 strncpy(p_param_err,
"Error: ROI should be disabled when "
5839 "intraRefreshMode=4", max_err_len);
5849 strncpy(p_param_err,
"Invalid profile: must be 5 (high10)",
5858 strncpy(p_param_err,
"Invalid profile: must be 1 (baseline), 2 (main),"
5859 " 3 (extended), 4 (high), or 5 (high10)", max_err_len);
5870 strncpy(p_param_err,
"Invalid gopPresetIdx for H.264 baseline profile:"
5871 " must be 1, 2, 6, 9 or 0 (custom with no B frames)", max_err_len);
5882 strncpy(p_param_err,
"H.264 baseline profile: custom GOP can not "
5883 "have B frames", max_err_len);
5893 int32_t numMbs = ((p_cfg->
i32picWidth + 16 - 1) >> 4) *
5898 strncpy(p_param_err,
"Invalid avcSliceArg: must be between 1 and number"
5899 " of 16x16 pixel MBs in a frame", max_err_len);
5906 int32_t numMbs = ((p_cfg->
i32picWidth + 16 - 1) >> 4) *
5911 strncpy(p_param_err,
"Invalid sliceArg: must be between 1 and number"
5912 " of 16x16 pixel MBs in a frame", max_err_len);
5923 strncpy(p_param_err,
"Invalid profile: must be 2 (main10)",
5932 strncpy(p_param_err,
"Invalid profile: must be 1 (main) or 2 (main10)",
5942 int32_t numCtus = ((p_cfg->
i32picWidth + 64 - 1) >> 6) *
5947 strncpy(p_param_err,
"Invalid sliceArg: must be between 1 and number"
5948 " of 64x64 pixel CTUs in a frame", max_err_len);
5955 strncpy(p_param_err,
"Invalid forceFrameType: out of range",
5963 strncpy(p_param_err,
"Invalid forcedHeaderEnable: out of range",
5972 strncpy(p_param_err,
"Invalid decoding_refresh_type: out of range", max_err_len);
5980 snprintf(p_param_err, max_err_len,
"Invalid gop_preset_index: out of range");
5989 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too small", max_err_len);
5996 strncpy(p_param_err,
"Invalid custom GOP paramaters: custom_gop_size too big", max_err_len);
6005 strncpy(p_param_err,
"Invalid use_recommend_enc_params: out of range", max_err_len);
6023 strncpy(p_param_err,
"Invalid max_num_merge: out of range", max_err_len);
6037 strncpy(p_param_err,
"Invalid intra_qp: out of range", max_err_len);
6045 strncpy(p_param_err,
"Invalid enable_mb_level_rc: out of range", max_err_len);
6055 strncpy(p_param_err,
"Invalid min_qp: out of range", max_err_len);
6063 strncpy(p_param_err,
"Invalid max_qp: out of range", max_err_len);
6072 strncpy(p_param_err,
"Invalid enable_cu_level_rate_control: out of range", max_err_len);
6082 strncpy(p_param_err,
"Invalid enable_hvs_qp: out of range", max_err_len);
6092 strncpy(p_param_err,
"Invalid max_delta_qp: out of range", max_err_len);
6098 if ( p_cfg->
niParamT408.enable_hvs_qp_scale != 1 &&
6101 snprintf(p_param_err, max_err_len,
6102 "Invalid enable_hvs_qp_scale: out of range");
6111 snprintf(p_param_err, max_err_len,
"Invalid hvs_qp_scale: out of range");
6121 strncpy(p_param_err,
"Invalid i32vbvBufferSize: out of range", max_err_len);
6137 strncpy(p_param_err,
"Error: intra_period and gop_preset_index are "
6138 "incompatible", max_err_len);
6177 ni_log(
NI_LOG_TRACE,
"ERROR: %s() unknown value for niParamT408.decoding_refresh_type: %d\n",
6234 uint32_t max_err_len)
6237 int32_t low_delay = 0;
6238 int32_t intra_period_gop_step_size;
6241 if (!p_param || !p_src || !p_param_err)
6249 memset(p_param_err, 0, max_err_len);
6284 strncpy(p_param_err,
"GOP size must be 1 or frames must be in sequence "
6285 "when lowDelay is enabled", max_err_len);
6292 intra_period_gop_step_size = 1;
6309 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: gop structure is larger than intra period",
6315 if (((!low_delay) && (p_param->
intra_period != 0) && ((p_param->
intra_period % intra_period_gop_step_size) != 0)) ||
6318 strncpy(p_param_err,
"Invalid intra_period and gop_preset_index: intra period is not a multiple of gop structure size",
6325 if (((!low_delay) && (p_param->
intra_period != 0) && ((p_param->
intra_period % intra_period_gop_step_size) == 1) &&
6330 strncpy(p_param_err,
"Invalid decoding_refresh_type: not support decoding refresh type I p_frame for closed gop structure",
6345 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset larger"
6346 " than GOP size", max_err_len);
6353 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id larger than 7", max_err_len);
6360 strncpy(p_param_err,
"Invalid custom gop parameters: temporal_id is zero or negative", max_err_len);
6365 if (min_poc > temp_poc[i])
6367 min_poc = temp_poc[i];
6375 if (temp_poc[j] == min_poc)
6384 strncpy(p_param_err,
"Invalid custom gop parameters: poc_offset is invalid", max_err_len);
6401 if (((p_param->
cu_size_mode & 0x1) == 0) && ((align_8_width_flag != 0) || (align_8_height_flag != 0)))
6403 strncpy(p_param_err,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be "
6404 "aligned with 8 pixels when enable CU8x8 of cu_size_mode. Recommend to set cu_size_mode |= 0x1 (CU8x8)",
6410 ((align_16_width_flag != 0) || (align_16_height_flag != 0)))
6412 strncpy(p_param_err,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be "
6413 "aligned with 16 pixels when enable CU16x16 of cu_size_mode. Recommend to set cu_size_mode |= 0x2 (CU16x16)",
6419 ((p_param->
cu_size_mode & 0x4) == 0) && ((align_32_width_flag != 0) || (align_32_height_flag != 0)))
6421 strncpy(p_param_err,
"Invalid use_recommend_enc_params and cu_size_mode: picture width and height must be "
6422 "aligned with 32 pixels when enable CU32x32 of cu_size_mode. Recommend to set cu_size_mode |= 0x4 (CU32x32)",
6432 strncpy(p_param_err,
"Invalid conf_win_top: out of range", max_err_len);
6438 strncpy(p_param_err,
"Invalid conf_win_top: not multiple of 2", max_err_len);
6445 strncpy(p_param_err,
"Invalid conf_win_bottom: out of range", max_err_len);
6451 strncpy(p_param_err,
"Invalid conf_win_bottom: not multiple of 2", max_err_len);
6458 strncpy(p_param_err,
"Invalid conf_win_left: out of range", max_err_len);
6464 strncpy(p_param_err,
"Invalid conf_win_left: not multiple of 2", max_err_len);
6471 strncpy(p_param_err,
"Invalid conf_win_right: out of range", max_err_len);
6477 strncpy(p_param_err,
"Invalid conf_win_right: not multiple of 2", max_err_len);
6488 uint32_t max_err_len)
6493 if (!p_cfg || !p_param_err)
6501 memset(p_param_err, 0, max_err_len);
6505 strncpy(p_param_err,
"Invalid roiEnable: out of range", max_err_len);
6515 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);
6536 if (!p_codec_params)
6677 struct sched_param sched_param;
6682 sigfillset(&signal);
6683 ni_logan_pthread_sigmask(SIG_BLOCK, &signal, NULL);
6690 if (((sched_param.sched_priority = sched_get_priority_max(SCHED_RR)) == -1) ||
6691 sched_setscheduler(syscall(SYS_gettid), SCHED_RR, &sched_param) < 0)
6694 __FUNCTION__, strerror(errno));
6695 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
6698 __FUNCTION__, strerror(errno));
6702 #elif defined(_WIN32)
6707 if (SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL) == 0)
6710 __FUNCTION__, GetLastError());
6746 endtime += interval;
6783 void * p_buffer = NULL;
6784 uint32_t ui32LBA = 0;
6785 uint32_t model_load = 0;
6786 uint32_t low_delay_mode = 0;
6787 uint32_t buffer_size = 0;
6850 ni_log(
NI_LOG_ERROR,
"ERROR %s(): alloc decoder packet info buffer failed\n", __FUNCTION__);
6880 "p_ctx->hw_id=%d, p_ctx->session_id=%d\n", __FUNCTION__,
6889 session_info.
model_load = ni_logan_htonl(model_load);
6904 ": %" PRIx64
" hw_id %d\n", __FUNCTION__,
6927 " p_ctx->session_id=%d\n", __FUNCTION__, (int64_t)p_ctx->
device_handle,
6941 char *dom, *bus, *dev, *fnc;
6944 p_ctx->
netint_fd = open(
"/dev/netint", O_RDWR);
6955 if (stat(block_dev, &bstat) < 0)
6962 if ((bstat.st_mode & S_IFMT) != S_IFBLK)
6969 ret = snprintf(syspath,
sizeof(syspath) - 1,
"/sys/block/%s/device/address", block_dev + 5);
6970 syspath[ret] =
'\0';
6971 fp = fopen(syspath,
"r");
6974 number[0] = block_dev[9];
6975 if(
'0' <= block_dev[10] && block_dev[10] <=
'9')
6977 number[1] = block_dev[10];
6982 ret = snprintf(syspath,
sizeof(syspath) - 1,
"/sys/block/%s/device/nvme%s/address", block_dev + 5, number);
6983 syspath[ret] =
'\0';
6984 fp = fopen(syspath,
"r");
6993 if (fgets(line, 256, fp) == NULL)
7004 p_ctx->
domain = strtoul(line, &dom, 16);
7014 p_ctx->
bus = strtoul(dom + 1, &bus, 16);
7024 p_ctx->
dev = strtoul(bus + 1, &dev, 16);
7034 p_ctx->
fn = strtoul(dev + 1, &fnc, 16);
7044 p_ctx->
dev, p_ctx->
fn);
7048 #ifdef XCODER_DUMP_ENABLED
7049 char dump_file[256] = { 0 };
7051 snprintf(dump_file,
sizeof dump_file,
"%s%d%s",
"decoder_in_id", p_ctx->
session_id,
".264");
7052 p_ctx->
p_dump[0] = fopen(dump_file,
"wb");
7055 snprintf(dump_file,
sizeof dump_file,
"%s%d%s",
"decoder_out_id", p_ctx->
session_id,
".yuv");
7056 p_ctx->
p_dump[1] = fopen(dump_file,
"wb");
7083 if (!src_p_ctx || !dst_p_ctx)
7113 uint32_t tx_size = 0, aligned_tx_size = 0;
7114 uint32_t sent_size = 0;
7115 uint32_t frame_size_bytes = 0;
7120 if (!p_ctx || !p_frame)
7136 __FUNCTION__, frame_size_bytes, 0);
7148 "buf size %u < frame size %u !\n", retval,
7155 "size %u >= frame size %u !\n",
7176 p_dec_packet_info->
packet_size = frame_size_bytes;
7194 "p_ctx->frame_num=%" PRIu64
", LBA=0x%x, Session ID=%d\n",
7197 sent_size = frame_size_bytes;
7204 p_frame->
p_buffer, sent_size, ui32LBA);
7216 size = frame_size_bytes;
7218 #ifdef XCODER_DUMP_DATA
7219 char dump_file[128];
7220 snprintf(dump_file,
sizeof(dump_file),
"%ld-%u-hwup-fme/fme-%04ld.yuv",
7223 FILE *f = fopen(dump_file,
"wb");
7257 if (!p_ctx || !hwdesc)
7326 ni_device_handle_t device_handle,
7327 ni_event_handle_t event_handle)
7329 void* p_buffer = NULL;
7331 uint32_t dataLen = 0;
7332 uint32_t ui32LBA = 0;
7335 __FUNCTION__, device_handle);
7390 if ((!p_serial_num) || (!p_data))
7403 memset(p_serial_num->
ai8Sn, 0,
sizeof(p_serial_num->
ai8Sn));
7404 memcpy(p_serial_num->
ai8Sn, p_id_data->
ai8Sn,
sizeof(p_serial_num->
ai8Sn));
7429 uint64_t frame_offset = 0;
7432 uint8_t* p_data_buffer = (uint8_t*)p_frame->
p_buffer;
7438 int frame_cycle = 0;
7439 uint32_t total_bytes_to_read = 0;
7440 uint32_t total_yuv_met_size = 0;
7441 uint32_t read_size_bytes = 0;
7442 uint32_t actual_read_size = 0;
7443 int keep_processing = 1;
7445 int query_retry = 0;
7446 uint32_t ui32LBA = 0;
7450 if (!p_ctx || !p_frame)
7466 total_bytes_to_read = p_frame->data_len[3] + metadata_hdr_size;
7467 total_yuv_met_size = p_frame->data_len[0] + p_frame->data_len[1] + p_frame->data_len[2] + metadata_hdr_size;
7468 ni_log(
NI_LOG_TRACE,
"Total bytes to read %d total_yuv_met_size %d \n", total_bytes_to_read, total_yuv_met_size);
7480 buf_info.buf_avail_size);
7485 retval, query_retry);
7487 if (query_retry >= 1000)
7492 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
7494 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
7500 total_bytes_to_read = metadata_hdr_size;
7503 else if (buf_info.buf_avail_size < total_yuv_met_size)
7508 ni_log(
NI_LOG_TRACE,
"Info dec query, ready_to_close %u, ready_to_flush %u, query eos\n",
7516 if (data.is_flushed ||
7522 ni_log(
NI_LOG_INFO,
"Info eos reached or flush buffers exceeding max retries: is_flushed %u try %d.\n",
7523 data.is_flushed, query_retry);
7527 p_frame->end_of_stream = 1;
7539 " retrying ..\n", query_retry);
7540 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
7542 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
7548 "eos %u nb try %d\n", p_frame->end_of_stream, query_retry);
7553 ni_logan_pthread_mutex_unlock(&p_ctx->
mutex);
7555 ni_logan_pthread_mutex_lock(&p_ctx->
mutex);
7585 "%ux%u frame-rate %u is_flushed %u\n",
7586 data.picture_width, data.picture_height,
7587 data.transfer_frame_stride, data.transfer_frame_height,
7588 data.frame_rate, data.is_flushed);
7610 total_bytes_to_read = p_frame->data_len[3] + metadata_hdr_size;
7612 p_data_buffer = (uint8_t*)p_frame->p_buffer;
7616 "available: %u\n", p_frame->buffer_size, total_bytes_to_read,
7617 buf_info.buf_avail_size);
7622 unsigned int bytes_read_so_far = 0;
7625 "cr len %d cb len %d hwdes len %d hdr %d\n", total_bytes_to_read,
7627 p_frame->data_len[2], p_frame->data_len[3], metadata_hdr_size);
7629 if (total_bytes_to_read == metadata_hdr_size)
7639 if (buf_info.buf_avail_size < total_bytes_to_read)
7642 __FUNCTION__, buf_info.buf_avail_size, total_bytes_to_read);
7646 read_size_bytes = buf_info.buf_avail_size;
7654 p_data_buffer, read_size_bytes, ui32LBA);
7669 + p_frame->data_len[0] + p_frame->data_len[1]
7670 + p_frame->data_len[2] + p_frame->data_len[3]);
7672 if (buf_info.buf_avail_size != metadata_hdr_size)
7678 + p_frame->data_len[1] + p_frame->data_len[2]);
7697 "ses_id=%d\n", __FUNCTION__, sei_size, p_data3->
device_handle,
7700 "bit_depth(in meta)=%d\n", __FUNCTION__, p_data3->
i8FrameIdx,
7706 ni_log(
NI_LOG_TRACE,
"%s: sequence change first frame, set seq_change\n", __FUNCTION__);
7712 total_bytes_to_read = total_bytes_to_read + sei_size;
7715 "sei %d sei_size %d frame_cycle %d\n", __FUNCTION__, retval,
7716 total_bytes_to_read, sei_size, frame_cycle);
7722 bytes_read_so_far = total_bytes_to_read;
7728 if (!p_frame->bit_depth)
7735 if (rx_size > 0 && total_bytes_to_read != metadata_hdr_size)
7767 if (p_frame->pts >= p_frame->dts && p_frame->pts - p_frame->dts < 1000)
7817 p_frame->pts = guess_correct_pts(p_ctx, p_frame->pts, p_frame->dts, p_ctx->
last_pts);
7828 #ifdef XCODER_DUMP_ENABLED
7829 fwrite(p_frame->data[0], rx_size, 1, p_ctx->
p_dump[1]);
7833 ni_log(
NI_LOG_TRACE,
"%s(): p_frame->start_of_stream=%d, p_frame->end_of_stream=%d, "
7834 "p_frame->video_width=%d, p_frame->""video_height=%d\n", __FUNCTION__,
7835 p_frame->start_of_stream, p_frame->end_of_stream,
7836 p_frame->video_width, p_frame->video_height);
7838 p_frame->data_len[0], p_frame->data_len[1], p_frame->data_len[2]);
7880 uint64_t frame_offset = 0;
7883 uint8_t* p_data_buffer = (uint8_t*)p_frame->
p_buffer;
7888 uint32_t total_bytes_to_read = 0;
7889 uint32_t read_size_bytes = 0;
7890 uint32_t actual_read_size = 0;
7891 int keep_processing = 1;
7893 int query_retry = 0;
7894 uint32_t ui32LBA = 0;
7895 unsigned int bytes_read_so_far = 0;
7899 if (!p_ctx || !p_frame)
7914 if (!p_frame->p_data[i])
7922 if (0 == p_frame->data_len[0])
7929 total_bytes_to_read = p_frame->data_len[0] + p_frame->data_len[1] + p_frame->data_len[2];
7932 "cr len %d cb len %d hdr %d\n", __FUNCTION__, total_bytes_to_read,
7934 p_frame->data_len[2], metadata_hdr_size);
7940 hwdesc->i8FrameIdx);
7946 read_size_bytes = total_bytes_to_read;
7955 int64_t handle = (((int64_t) hwdesc->device_handle_ext) << 32) | hwdesc->device_handle;
7957 p_data_buffer, read_size_bytes, ui32LBA);
7960 p_data_buffer, read_size_bytes, ui32LBA);
7974 "sei %d sei_size %d\n", __FUNCTION__, retval, total_bytes_to_read, sei_size);
7977 ni_log(
NI_LOG_TRACE,
"%s total_bytes_to_read %d ylen %d cr len %d cb len %d data0 0x%x data_end 0x%x idx %d\n", \
7978 __FUNCTION__, total_bytes_to_read, p_frame->data_len[0],
7979 p_frame->data_len[1], p_frame->data_len[2], p_data_buffer[0],
7980 p_data_buffer[total_bytes_to_read-1], total_bytes_to_read -1);
7982 bytes_read_so_far = total_bytes_to_read;
7991 "p_frame->end_of_stream=%d, p_frame->video_width=%d, "
7992 "p_frame->video_height=%d\n", __FUNCTION__, p_frame->start_of_stream,
7993 p_frame->end_of_stream, p_frame->video_width, p_frame->video_height);
7994 ni_log(
NI_LOG_TRACE,
"%s(): p_ctx->frame_num%ld, p_frame->data_len[0/1/2]=%d/%d/%d\n",
7995 __FUNCTION__, p_ctx->
frame_num, p_frame->data_len[0],
7996 p_frame->data_len[1], p_frame->data_len[2]);
8034 uint32_t pool_size, uint32_t p2p_pool)
8039 uint32_t ui32LBA = 0;
8065 memset((
void *)p_init_frames_param, 0, buffer_size);
8070 p_init_frames_param->
pool_size = ni_logan_ntohs(pool_size);
8071 p_init_frames_param->
p2p_pool = ni_logan_ntohs(p2p_pool);
8074 __FUNCTION__, p_init_frames_param->
width, p_init_frames_param->
height,
8080 p_init_frames_param, buffer_size, ui32LBA);
8108 struct sched_param sched_param;
8123 if (((sched_param.sched_priority = sched_get_priority_max(SCHED_RR)) == -1) ||
8124 sched_setscheduler(syscall(SYS_gettid), SCHED_RR, &sched_param) < 0)
8127 __FUNCTION__, strerror(errno));
8128 if (setpriority(PRIO_PROCESS, 0, -20) != 0)
8131 __FUNCTION__, strerror(errno));
8150 unsigned int *p_offset,
unsigned int hwaddress)
8158 *p_offset = hwaddress - 0xD0000000;
NETINT audio/video related utility functions.
#define NI_LOGAN_MAX_1080P_FPS
@ NI_LOGAN_RETCODE_PARAM_ERROR_MN_QP
@ NI_LOGAN_RETCODE_ERROR_INVALID_HANDLE
@ NI_LOGAN_RETCODE_NVME_SC_VPU_GENERAL_ERROR
@ NI_LOGAN_RETCODE_PARAM_ERROR_CONF_WIN_R
@ NI_LOGAN_RETCODE_ERROR_INVALID_SESSION
@ NI_LOGAN_RETCODE_PARAM_ERROR_FRATE
@ NI_LOGAN_RETCODE_PARAM_INVALID_VALUE
@ NI_LOGAN_RETCODE_PARAM_ERROR_CONF_WIN_TOP
@ NI_LOGAN_RETCODE_PARAM_ERROR_USR_RMD_ENC_PARAM
@ NI_LOGAN_RETCODE_PARAM_ERROR_GOP_PRESET
@ NI_LOGAN_RETCODE_PARAM_ERROR_RCENABLE
@ NI_LOGAN_RETCODE_DEFAULT_SESSION_ERR_NO
@ NI_LOGAN_RETCODE_PARAM_GOP_INTRA_INCOMPATIBLE
@ NI_LOGAN_RETCODE_PARAM_ERROR_CONF_WIN_L
@ NI_LOGAN_RETCODE_NVME_SC_REQUEST_IN_PROGRESS
@ NI_LOGAN_RETCODE_ERROR_RESOURCE_UNAVAILABLE
@ NI_LOGAN_RETCODE_PARAM_ERROR_MX_QP
@ NI_LOGAN_RETCODE_PARAM_ERROR_CUSIZE_MODE_8X8_EN
@ NI_LOGAN_RETCODE_PARAM_ERROR_CUSIZE_MODE_16X16_EN
@ NI_LOGAN_RETCODE_ERROR_NVME_CMD_FAILED
@ NI_LOGAN_RETCODE_INVALID_PARAM
@ NI_LOGAN_RETCODE_ERROR_MEM_ALOC
@ NI_LOGAN_RETCODE_PARAM_ERROR_PIC_HEIGHT
@ NI_LOGAN_RETCODE_PARAM_ERROR_INTRA_PERIOD
@ NI_LOGAN_RETCODE_ERROR_VPU_RECOVERY
@ NI_LOGAN_RETCODE_PARAM_ERROR_BRATE
@ NI_LOGAN_RETCODE_PARAM_ERROR_RCINITDELAY
@ NI_LOGAN_RETCODE_PARAM_ERROR_MAXNUMMERGE
@ NI_LOGAN_RETCODE_PARAM_ERROR_CONF_WIN_BOT
@ NI_LOGAN_RETCODE_PARAM_ERROR_HVS_QP_EN
@ NI_LOGAN_RETCODE_PARAM_ERROR_CUSTOM_GOP
@ NI_LOGAN_RETCODE_SUCCESS
@ NI_LOGAN_RETCODE_NVME_SC_WRITE_BUFFER_FULL
@ NI_LOGAN_RETCODE_FAILURE
@ NI_LOGAN_RETCODE_NVME_SC_VPU_RECOVERY
@ NI_LOGAN_RETCODE_PARAM_ERROR_PIC_WIDTH
@ NI_LOGAN_RETCODE_PARAM_ERROR_MX_DELTA_QP
@ NI_LOGAN_RETCODE_PARAM_ERROR_CUSIZE_MODE_32X32_EN
@ NI_LOGAN_RETCODE_PARAM_ERROR_HVS_QP_SCL
@ NI_LOGAN_RETCODE_PARAM_ERROR_INTRA_QP
@ NI_LOGAN_RETCODE_PARAM_ERROR_DECODING_REFRESH_TYPE
@ NI_LOGAN_RETCODE_PARAM_ERROR_CU_LVL_RC_EN
@ NI_LOGAN_RETCODE_NVME_SC_VPU_RSRC_INSUFFICIENT
struct _ni_logan_instance_status_info ni_logan_instance_status_info_t
#define NI_LOGAN_APP_ENC_FRAME_META_DATA_SIZE
#define NI_LOGAN_MAX_NUM_DATA_POINTERS
#define NI_LOGAN_MAX_CONTEXTS_PER_HW_INSTANCE
#define ni_logan_assert(expression)
#define NI_LOGAN_MAX_FORCE_FRAME_TABLE_SIZE
#define NI_LOGAN_MEM_PAGE_ALIGNMENT
#define NETINT_PCI_VENDOR_ID
@ NI_LOGAN_DEVICE_TYPE_UPLOAD
@ NI_LOGAN_DEVICE_TYPE_ENCODER
@ NI_LOGAN_DEVICE_TYPE_DECODER
#define NI_LOGAN_FW_META_DATA_SZ
@ NI_LOGAN_DECODE_BUFFERS_FLUSHING
@ NI_LOGAN_DECODE_FLUSH_BUFFER_OFF
#define NI_LOGAN_MAX_DEVICES_PER_HW_INSTANCE
ni_logan_retcode_t ni_logan_decoder_frame_buffer_alloc(ni_logan_buf_pool_t *p_pool, ni_logan_frame_t *p_frame, int alloc_mem, int video_width, int video_height, int alignment, int factor)
Allocate memory for decoder frame buffer based on provided parameters; the memory is retrieved from a...
ni_logan_retcode_t ni_logan_decoder_frame_buffer_free(ni_logan_frame_t *p_frame)
Free decoder frame buffer that was previously allocated with ni_logan_decoder_frame_buffer_alloc,...
void ni_logan_device_session_context_init(ni_logan_session_context_t *p_ctx)
Initialize already allocated session context to a known state.
void ni_logan_device_session_context_clear(ni_logan_session_context_t *p_ctx)
Clear already allocated session context to all zeros.
ni_logan_retcode_t ni_logan_device_handle_map_SN(ni_device_handle_t device_handle, ni_logan_serial_num_t *p_serial_num)
Queries device Serial number.
ni_logan_retcode_t ni_logan_frame_buffer_alloc(ni_logan_frame_t *p_frame, int video_width, int video_height, int alignment, int metadata_flag, int factor, int hw_frame_count)
Allocate preliminary memory for the frame buffer for encoding based on provided parameters....
ni_event_handle_t ni_logan_create_event(void)
Create event and returnes event handle if successful.
Main NETINT device API header file provides the ability to communicate with NI T-408 type hardware tr...
#define NI_LOGAN_DEFAULT_CU_SIZE_MODE
#define NI_LOGAN_MAX_INTRA_QP
#define NI_LOGAN_DEFAULT_INTRA_QP
#define NI_LOGAN_RETRY_INTERVAL_200US
#define NI_LOGAN_MIN_MAX_DELTA_QP
struct _ni_logan_hwframe_surface ni_logan_hwframe_surface_t
#define NI_CC_SEI_TRAILER_LEN
#define NI_HDR10P_SEI_BYTE2
#define NI_LOGAN_MAX_GOP_PRESET_IDX
#define NI_LOGAN_MAX_VUI_SIZE
#define NI_HDR10P_SEI_BYTE6
#define NI_LOGAN_PARAM_MAX_HEIGHT
#define NI_LOGAN_MAX_ENC_SESSION_OPEN_QUERY_RETRIES
@ NI_LOGAN_CODEC_HW_UPLOAD
@ NI_LOGAN_CODEC_HW_ENABLE
@ NI_LOGAN_CODEC_HW_DOWNLOAD
#define NI_CC_SEI_HDR_H264_LEN
#define NI_HDR10P_SEI_BYTE0
#define NI_LOGAN_MIN_INTRA_QP
#define NI_LOGAN_PARAM_MAX_WIDTH
ni_logan_h265_sei_user_data_type_t
@ NI_LOGAN_H265_USERDATA_FLAG_UNREGISTERED_SUF
@ NI_LOGAN_H265_USERDATA_FLAG_ITU_T_T35_SUF_1
@ NI_LOGAN_H265_USERDATA_FLAG_MASTERING_COLOR_VOL
@ NI_LOGAN_H265_USERDATA_FLAG_VUI
@ NI_LOGAN_H265_USERDATA_FLAG_ITU_T_T35_SUF_2
@ NI_LOGAN_H265_USERDATA_FLAG_UNREGISTERED_PRE
@ NI_LOGAN_H265_USERDATA_FLAG_ITU_T_T35_PRE_2
@ NI_LOGAN_H265_USERDATA_FLAG_ALTERNATIVE_TRANSFER_CHARACTERISTICS
@ NI_LOGAN_H265_USERDATA_FLAG_ITU_T_T35_SUF
@ NI_LOGAN_H265_USERDATA_FLAG_ITU_T_T35_PRE_1
@ NI_LOGAN_H265_USERDATA_FLAG_ITU_T_T35_PRE
@ NI_LOGAN_H265_USER_DATA_FLAG_CONTENT_LIGHT_LEVEL_INFO
#define NI_LOGAN_MAX_ENC_SESSION_READ_QUERY_RETRIES
#define NI_LOGAN_MAX_SESSION_CLOSE_RETRIES
#define NI_LOGAN_MAX_DEC_SESSION_READ_QUERY_EOS_RETRIES
#define NI_LOGAN_SESSION_CLOSE_RETRY_INTERVAL_US
#define NI_LOGAN_RETRY_INTERVAL_100US
#define NI_LOGAN_ENC_SESSION_OPEN_RETRY_INTERVAL_US
#define NI_HDR10P_SEI_HDR_H264_LEN
#define NI_LOGAN_ENC_REPEAT_HEADERS_ALL_I_FRAMES
#define NI_LOGAN_PARAM_MIN_WIDTH
#define NI_HDR10P_SEI_BYTE1
#define NI_LOGAN_MAX_DEC_SESSION_READ_QUERY_RETRIES
#define NI_LOGAN_NOPTS_VALUE
#define NI_LOGAN_MAX_MAX_DELTA_QP
#define NI_HDR10P_SEI_HDR_HEVC_LEN
#define NI_LOGAN_MAX_ENC_SESSION_WRITE_QUERY_RETRIES
#define NI_HDR10P_SEI_BYTE5
#define NI_LOGAN_MAX_GOP_NUM
@ LOGAN_SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
@ LOGAN_SESSION_RUN_STATE_NORMAL
#define NI_LOGAN_MAX_DEC_SESSION_WRITE_QUERY_RETRIES
#define NI_LOGAN_DEFAULT_MAX_DELTA_QP
#define NI_HDR10P_SEI_BYTE3
#define NI_LOGAN_ENC_REPEAT_HEADERS_ALL_KEY_FRAMES
@ NI_LOGAN_CODEC_FORMAT_H265
@ NI_LOGAN_CODEC_FORMAT_H264
#define NI_LOGAN_INVALID_SESSION_ID
#define NI_LOGAN_PARAM_MIN_HEIGHT
#define NI_HDR10P_SEI_BYTE4
#define NI_CC_SEI_HDR_HEVC_LEN
#define NI_LOGAN_MIN_GOP_PRESET_IDX
ni_logan_retcode_t ni_logan_decoder_session_query(ni_logan_session_context_t *p_ctx)
Query current decoder status.
ni_logan_retcode_t ni_logan_encoder_session_close(ni_logan_session_context_t *p_ctx, int eos_recieved)
Close a xcoder encoder instance.
ni_logan_retcode_t ni_logan_check_ratecontrol_params(ni_logan_encoder_config_t *p_cfg, char *p_param_err, uint32_t max_err_len)
check the range of rate control parameters
int ni_logan_encoder_session_read(ni_logan_session_context_t *p_ctx, ni_logan_packet_t *p_packet)
Retrieve an encoded packet from encoder.
ni_logan_retcode_t ni_logan_query_stream_info(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type, ni_logan_instance_mgr_stream_info_t *p_stream_info, bool is_hw)
Query a particular xcoder instance to get Stream Info data.
ni_logan_retcode_t ni_logan_config_instance_set_encoder_params(ni_logan_session_context_t *p_ctx)
Send a p_config command to configure encoding parameters.
_ni_logan_t35_sei_mesg_type
@ NI_LOGAN_T35_SEI_HDR10_PLUS
@ NI_LOGAN_T35_SEI_CLOSED_CAPTION
ni_logan_retcode_t ni_get_memory_offset(ni_logan_session_context_t *p_ctx, const ni_logan_hwframe_surface_t *hwdesc, unsigned int *p_offset, unsigned int hwaddress)
Get an address offset from a hw descriptor.
ni_logan_retcode_t ni_logan_config_instance_sos(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type)
Send a p_config command for Start Of Stream.
void ni_logan_params_print(void *const p_codec_params, ni_logan_device_type_t device_type)
Print xcoder user configurations.
ni_logan_retcode_t ni_logan_query_status_info(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type, ni_logan_instance_status_info_t *p_status_info, int rc, int opcode)
Query a particular xcoder instance to get status Info data.
int ni_logan_hwupload_session_write(ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_frame)
Send a YUV to hardware, hardware will store it.
int ni_logan_encoder_session_query(ni_logan_session_context_t *p_ctx)
Query current encoder status.
ni_logan_retcode_t ni_logan_validate_custom_template(ni_logan_session_context_t *p_ctx, ni_logan_encoder_config_t *p_cfg, ni_logan_encoder_params_t *p_src, char *p_param_err, uint32_t max_err_len)
Perform validation on custom parameters (Rev. B)
ni_logan_retcode_t ni_logan_config_instance_rw(ni_logan_session_context_t *p_ctx, ni_logan_inst_config_rw_type_t rw_type, uint8_t enable, uint8_t hw_action, uint16_t frame_id)
Configure the read/write pipe for a session Use HW frame index to read/write the YUV from/to HW.
int ni_logan_decoder_session_write(ni_logan_session_context_t *p_ctx, ni_logan_packet_t *p_packet)
Send a video p_packet to decoder.
ni_logan_retcode_t ni_logan_clear_instance_buf(ni_logan_hwframe_surface_t *surface, ni_device_handle_t device_handle, ni_event_handle_t event_handle)
clear a particular xcoder instance buffer/data The device handle is got from decoder or uploader,...
ni_logan_retcode_t ni_logan_encoder_session_open(ni_logan_session_context_t *p_ctx)
Open a xcoder encoder instance.
ni_logan_retcode_t ni_logan_encoder_session_flush(ni_logan_session_context_t *p_ctx)
Flush encoder output.
void ni_logan_set_default_template(ni_logan_session_context_t *p_ctx, ni_logan_encoder_config_t *p_config)
Setup and initialize all xcoder configuration to default (Rev. B)
int ni_logan_hwdownload_session_read(ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_frame, ni_logan_hwframe_surface_t *hwdesc)
Retrieve a YUV through HW descriptor from decoder.
void ni_logan_populate_serial_number(ni_logan_serial_num_t *p_serial_num, void *p_data)
Get Card Serial Number from received Nvme Indentify info.
int ni_logan_hwupload_session_read_hwdesc(ni_logan_session_context_t *p_ctx, ni_logan_hwframe_surface_t *hwdesc, unsigned int *hwaddress)
Retrieve a HW descriptor of uploaded frame The HW descriptor will contain the YUV frame index,...
ni_logan_retcode_t ni_logan_query_instance_buf_info(ni_logan_session_context_t *p_ctx, ni_logan_instance_buf_info_rw_type_t rw_type, ni_logan_device_type_t device_type, ni_logan_instance_buf_info_t *p_inst_buf_info, bool is_hw)
Query a particular xcoder instance to get buffer/data Info data.
int ni_logan_create_frame(ni_logan_frame_t *p_frame, uint32_t read_length, uint64_t *p_frame_offset, bool is_hw_frame)
Get info from received p_frame.
ni_logan_retcode_t ni_logan_uplosader_session_close(ni_logan_session_context_t *p_ctx)
Close an xcoder upload instance.
ni_logan_retcode_t ni_logan_hwupload_init_framepool(ni_logan_session_context_t *p_ctx, uint32_t pool_size, uint32_t p2p_pool)
Setup framepool for hwupload. Uses decoder framepool.
ni_logan_retcode_t ni_logan_decoder_session_copy_internal(ni_logan_session_context_t *src_p_ctx, ni_logan_session_context_t *dst_p_ctx)
Copy a xcoder decoder card info and create worker thread.
ni_logan_retcode_t ni_logan_send_session_keep_alive(uint32_t session_id, ni_device_handle_t device_handle, ni_event_handle_t event_handle, void *p_data)
send a keep alive message to firmware
void ni_logan_change_priority(void)
Set up schedule priority. First try to run with RR mode. If fails, try to set nice value....
void * ni_logan_session_keep_alive_thread(void *arguments)
decoder keep alive thread function triggers every 1 second
#define CHECK_VPU_RECOVERY(ret)
ni_logan_retcode_t ni_logan_decoder_session_close(ni_logan_session_context_t *p_ctx, int eos_recieved)
Close a xcoder decoder instance.
enum _ni_logan_t35_sei_mesg_type ni_logan_t35_sei_mesg_type_t
void ni_logan_populate_device_capability_struct(ni_logan_device_capability_t *p_cap, void *p_data)
Get info from received xcoder capability.
ni_logan_retcode_t ni_logan_decoder_session_flush_buffers(ni_logan_session_context_t *p_ctx)
Flush decoder output.
int ni_logan_query_general_status(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type, ni_logan_instance_mgr_general_status_t *p_gen_status)
Query a particular xcoder instance to get GeneralStatus data.
ni_logan_retcode_t ni_logan_check_common_params(ni_logan_t408_config_t *p_param, ni_logan_encoder_params_t *p_src, char *p_param_err, uint32_t max_err_len)
check the range of common parameters
ni_logan_retcode_t ni_logan_config_instance_eos(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type)
Send a p_config command for End Of Stream.
ni_logan_retcode_t ni_logan_decoder_session_flush(ni_logan_session_context_t *p_ctx)
Flush decoder output.
ni_logan_retcode_t ni_logan_decoder_session_open(ni_logan_session_context_t *p_ctx)
Open a xcoder decoder instance.
ni_logan_retcode_t ni_logan_uploader_session_open(ni_logan_session_context_t *p_ctx)
Open a xcoder uploader instance.
int ni_logan_decoder_session_read(ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_frame)
Retrieve a YUV p_frame from decoder.
ni_logan_retcode_t ni_logan_config_instance_flush(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type)
Send a p_config command for Flush Of Stream.
int ni_logan_encoder_session_write(ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_frame)
Send a YUV p_frame to encoder.
void ni_logan_set_custom_template(ni_logan_session_context_t *p_ctx, ni_logan_encoder_config_t *p_cfg, ni_logan_encoder_params_t *p_src)
Setup all xcoder configurations with custom parameters (Rev. B)
ni_logan_retcode_t ni_logan_decoder_session_read_desc(ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_frame)
Retrieve a hw desc p_frame from decoder When yuvbypass enabled, this is used for decoder to read hard...
Private definitions used by main ni_device_api_logan file.
struct _ni_logan_inst_config_rw ni_logan_inst_config_rw_t
ni_logan_inst_config_rw_type_t
struct _ni_logan_metadata_enc_bstream ni_logan_metadata_enc_bstream_t
struct _ni_logan_instance_debugInfo ni_logan_instance_debugInfo_t
@ ni_logan_xcoder_general_error
@ ni_logan_xcoder_resource_insufficient
@ ni_logan_xcoder_resource_recovery
@ ni_logan_xcoder_request_success
@ ni_logan_xcoder_request_pending
struct _ni_logan_instance_buf_info ni_logan_instance_buf_info_t
struct _ni_logan_instance_mgr_general_status ni_logan_instance_mgr_general_status_t
ni_logan_instance_buf_info_rw_type_t
@ INST_BUF_INFO_R_ACQUIRE
@ INST_BUF_INFO_RW_UPLOAD
struct _ni_logan_encoder_config_t ni_logan_encoder_config_t
struct _ni_logan_instance_mgr_stream_info ni_logan_instance_mgr_stream_info_t
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
int32_t ni_logan_nvme_send_write_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose a io write command.
int32_t ni_logan_nvme_send_read_cmd(ni_device_handle_t handle, ni_event_handle_t event_handle, void *p_data, uint32_t data_len, uint32_t lba)
Compose a io read command.
Definitions related to working with NI T-408 over NVME interface.
#define WRITE_INSTANCE_W(hw, sid, instance)
@ nvme_admin_cmd_xcoder_config
@ nvme_admin_cmd_xcoder_query
#define QUERY_INSTANCE_DEBUG_DATA_R(sid, instance)
#define CONFIG_INSTANCE_SetEOS_W(sid, instance)
#define CONFIG_INSTANCE_InitFramePool_W(sid, instance)
#define QUERY_INSTANCE_UPLOAD_ID_R(hw, sid, instance)
#define NI_LOGAN_NO_CHECK_TS_NVME_CMD_OP
#define CLOSE_SESSION_R(sid, instance)
#define QUERY_GENERAL_GET_STATUS_R(instance)
#define CONFIG_INSTANCE_SetFlush_W(sid, instance)
#define WRITE_METADATA_W(hw, sid, instance)
#define OPEN_GET_SID_R(hw, instance)
#define CONFIG_INSTANCE_FrameIdx_W(sid, instance)
#define QUERY_INSTANCE_RBUFF_SIZE_R(hw, sid, instance)
#define QUERY_INSTANCE_STREAM_INFO_R(hw, sid, instance)
#define CONFIG_SESSION_KeepAlive_W(sid)
#define QUERY_INSTANCE_CUR_STATUS_INFO_R(sid, instance)
#define OPEN_SESSION_W(hw, sid, instance)
#define QUERY_INSTANCE_ACQUIRE_BUF(hw, sid, instance)
#define CONFIG_SESSION_KeepAliveTimeout_W(sid)
#define CONFIG_INSTANCE_SetEncPara_W(sid, instance)
#define CONFIG_INSTANCE_SetPktSize_W(hw, sid, instance)
#define READ_INSTANCE_R(hw, sid, instance)
#define QUERY_INSTANCE_DEBUG_INFO_R(sid, instance)
#define CONFIG_SESSION_Write_W(sid)
#define CONFIG_INSTANCE_RecycleBuf_W(sid, instance)
#define CONFIG_INSTANCE_SetSOS_W(hw, sid, instance)
#define QUERY_INSTANCE_WBUFF_SIZE_R(hw, sid, instance)
#define NI_LOGAN_DATA_BUFFER_LEN
ni_logan_device_context_t * ni_logan_rsrc_get_device_context(ni_logan_device_type_t device_type, int guid)
Allocates and returns a pointer to ni_logan_device_context_t struct based on provided device_type and...
void ni_logan_rsrc_free_device_context(ni_logan_device_context_t *p_device_context)
Free previously allocated device context.
Exported definitions related to resource management of NI T-408 devices.
void ni_logan_timestamp_scan_cleanup(ni_logan_timestamp_table_t *pts_list, ni_logan_timestamp_table_t *dts_list, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Timestamp queue clean up.
int32_t ni_logan_dec_fme_buffer_pool_initialize(ni_logan_session_context_t *p_ctx, int32_t number_of_buffers, int width, int height, int height_align, int factor)
decoder frame buffer pool init & free
int32_t ni_logan_posix_memalign(void **pp_memptr, size_t alignment, size_t size)
ni_logan_retcode_t ni_logan_queue_free(ni_logan_queue_t *p_queue, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Free xcoder queue.
void ni_logan_buffer_pool_free(ni_logan_queue_buffer_pool_t *p_buffer_pool)
free buffer memory pool
uint64_t ni_logan_gettime_ns(void)
ni_logan_retcode_t ni_logan_timestamp_register(ni_logan_queue_buffer_pool_t *p_buffer_pool, ni_logan_timestamp_table_t *p_table, int64_t timestamp, uint64_t data_info)
Register timestamp in timestamp/frameoffset table.
void ni_logan_usleep(int64_t usec)
ni_logan_retcode_t ni_logan_timestamp_init(ni_logan_session_context_t *p_ctx, ni_logan_timestamp_table_t **pp_table, const char *name)
Initialize timestamp handling.
void ni_logan_dec_fme_buffer_pool_free(ni_logan_buf_pool_t *p_buffer_pool)
free decoder frame buffer pool
void ni_logan_overwrite_specified_pos(uint8_t *buf, int pos, int value)
overwrite the 32 bits of integer value at bit position pos
int32_t ni_logan_gettimeofday(struct timeval *p_tp, void *p_tzp)
ni_logan_retcode_t ni_logan_timestamp_get_with_threshold(ni_logan_timestamp_table_t *p_table, uint64_t frame_info, int64_t *p_timestamp, int32_t threshold, int32_t print, ni_logan_queue_buffer_pool_t *p_buffer_pool)
Retrieve timestamp from table based on frame offset info with respect to threshold.
Exported utility routines definition.
#define LOGAN_XCODER_MAX_ENC_PIC_WIDTH
#define NI_LOGAN_DEC_FRAME_BUF_POOL_SIZE_INIT
#define LOGAN_XCODER_MAX_ENC_PIC_HEIGHT
#define LOGAN_XCODER_MIN_ENC_PIC_WIDTH
#define ni_logan_aligned_free(p_memptr)
#define LOGAN_XCODER_MIN_ENC_PIC_HEIGHT
#define LOGAN_XCODER_MAX_NUM_TEMPORAL_LAYER
#define NI_LOGAN_VPU_FREQ
#define LOGAN_XCODER_FRAME_OFFSET_DIFF_THRES
payload format of HDR SEI content light level info
uint16_t max_content_light_level
uint16_t max_pic_average_light_level
ni_logan_gop_params_t pic_param[NI_LOGAN_MAX_GOP_NUM]
decoded payload format of HDR SEI mastering display colour volume
uint32_t min_display_mastering_luminance
uint32_t max_display_mastering_luminance
uint32_t display_primaries_y[3]
uint32_t display_primaries_x[3]
ni_logan_decoder_input_params_t dec_input_params
uint32_t set_high_priority
uint8_t h265_encoders_cnt
uint8_t h264_encoders_cnt
uint8_t fw_commit_time[26]
uint8_t fw_commit_hash[41]
uint8_t fw_branch_name[256]
uint8_t h265_decoders_cnt
uint8_t h264_decoders_cnt
ni_logan_hw_capability_t xcoder_devices[NI_LOGAN_MAX_DEVICES_PER_HW_INSTANCE]
int32_t i32userMinDeltaQp
int32_t i32userMaxDeltaQp
uint8_t ui8VuiRbsp[NI_LOGAN_MAX_VUI_SIZE]
uint32_t ui32minIntraRefreshCycle
uint8_t ui8lowLatencyMode
uint8_t ui8explicitRefListEnable
uint8_t ui8CrfPbRatioFraction
uint32_t ui32VuiDataSizeBytes
uint32_t ui32VuiDataSizeBits
uint32_t ui32sourceEndian
uint32_t ui32fillerEnable
uint8_t ui8CrfIpRatioFraction
ni_logan_t408_config_t niParamT408
uint8_t ui8bitstreamFormat
ni_logan_encoder_input_params_t enc_input_params
uint8_t ui8VuiRbsp[NI_LOGAN_MAX_VUI_SIZE]
uint32_t ui32minIntraRefreshCycle
uint32_t ui32VuiDataSizeBytes
int use_low_delay_poc_type
uint32_t ui32VuiDataSizeBits
int enable_vui_info_passthru
uint32_t pos_num_units_in_tick
uint32_t set_high_priority
uint32_t EncoderReadSyncQuery
unsigned int sei_hdr_mastering_display_color_vol_offset
unsigned int sei_hdr_content_light_level_info_offset
uint8_t separate_metadata
unsigned int sei_hdr_plus_len
uint32_t data_len[NI_LOGAN_MAX_NUM_DATA_POINTERS]
unsigned int sei_hdr_plus_offset
unsigned int extra_data_len
unsigned int sei_total_len
unsigned int sei_cc_offset
unsigned int sei_user_data_unreg_len
ni_logan_pic_type_t ni_logan_pict_type
uint8_t use_cur_src_as_long_term_pic
ni_logan_codec_format_t src_codec
unsigned int sei_hdr_content_light_level_info_len
void * p_data[NI_LOGAN_MAX_NUM_DATA_POINTERS]
unsigned int sei_hdr_mastering_display_color_vol_len
unsigned int sei_user_data_unreg_offset
uint8_t use_long_term_ref
unsigned int sei_alt_transfer_characteristics_len
unsigned int sei_alt_transfer_characteristics_offset
uint16_t min_video_height
uint16_t max_video_height
uint8_t max_number_of_contexts
int32_t device_handle_ext
uint16_t bit_depth_factor
uint16_t ui16WriteFrameId
union _ni_logan_inst_config_rw::@5 uHWAccessField
ni_logan_instance_upload_ret_hwdesc_t hw_inst_ind
uint8_t ui8DataPktSeqTotal
uint32_t ui32VpuInstError
uint8_t active_sub_instances_cnt
uint8_t process_load_percent
uint8_t composite_temperature
uint8_t fw_video_mem_usage
uint16_t transfer_frame_height
uint16_t transfer_frame_stride
uint32_t rd_buf_avail_size
uint32_t wr_buf_avail_size
uint32_t frames_completed
uint32_t fw_video_mem_usage
uint8_t hw2_video_profile
uint8_t xcoder_num_h264_decoder_hw
uint8_t xcoder_num_h264_encoder_hw
uint8_t fw_commit_time[26]
uint8_t xcoder_num_h265_decoder_hw
uint8_t fw_commit_hash[41]
uint8_t fw_branch_name[256]
uint8_t hw0_video_profile
uint8_t hw3_video_profile
uint8_t xcoder_num_h265_encoder_hw
uint8_t hw1_video_profile
ni_logan_all_custom_sei_t * p_all_custom_sei
uint8_t itu_t_t35_hdr10p_sei_hdr_hevc[NI_HDR10P_SEI_HDR_HEVC_LEN]
int64_t pts_offsets[NI_LOGAN_FIFO_SZ]
ni_logan_load_query_t load_query
ni_event_handle_t thread_event_handle
uint16_t decoder_reorder_delay
uint64_t prev_read_frame_time
uint32_t set_high_priority
uint32_t keep_alive_timeout
uint32_t active_bit_depth
uint64_t codec_total_ticks
ni_logan_serial_num_t d_serial_number
uint32_t ui32timing_scale
ni_device_handle_t sender_handle
ni_device_handle_t device_handle
uint64_t pkt_offsets_index_min[NI_LOGAN_FIFO_SZ]
ni_logan_lat_meas_q_t * frame_time_q
int pts_correction_num_faulty_dts
ni_device_handle_t auto_dl_handle
uint64_t pkt_offsets_index[NI_LOGAN_FIFO_SZ]
uint8_t sei_trailer[NI_CC_SEI_TRAILER_LEN]
uint64_t codec_start_time
int flags_array[NI_LOGAN_FIFO_SZ]
uint8_t itu_t_t35_cc_sei_hdr_hevc[NI_CC_SEI_HDR_HEVC_LEN]
ni_logan_session_run_state_t session_run_state
uint8_t itu_t_t35_cc_sei_hdr_h264[NI_CC_SEI_HDR_H264_LEN]
ni_event_handle_t event_handle
char blk_xcoder_name[LOGAN_MAX_CHAR_IN_DEVICE_NAME]
ni_device_handle_t blk_io_handle
ni_logan_queue_buffer_pool_t * buffer_pool
uint64_t force_frame_pkt_num
int64_t pts_correction_last_dts
uint32_t max_nvme_io_size
uint8_t composite_temperature
char stream_dir_name[128]
uint64_t frame_pkt_offset
Params used in VFR mode Done///.
void * p_dec_packet_inf_buf
uint32_t ui32num_unit_in_tick
ni_logan_buf_pool_t * dec_fme_buf_pool
int64_t pts_correction_last_pts
int64_t force_frame_pts_table[NI_LOGAN_MAX_FORCE_FRAME_TABLE_SIZE]
uint64_t session_timestamp
uint8_t itu_t_t35_hdr10p_sei_hdr_h264[NI_HDR10P_SEI_HDR_H264_LEN]
int64_t last_dts_interval
uint64_t decoder_drop_frame_num
ni_logan_instance_status_info_t session_stats
uint32_t active_video_width
uint32_t active_video_height
ni_logan_all_custom_sei_t * pkt_custom_sei[NI_LOGAN_FIFO_SZ]
int pts_correction_num_faulty_pts
char dev_xcoder_name[LOGAN_MAX_CHAR_IN_DEVICE_NAME]
ni_logan_serial_num_t e_serial_number
uint32_t required_buf_size
int32_t lambdaScalingEnable
int32_t constIntraPredFlag
int32_t pu08IntraAngleDeltaRate
uint32_t strongIntraSmoothEnable
int32_t cu16InterDeltaRate
int32_t pu16IntraDcDeltaRate
int32_t enable_cu_level_rate_control
int32_t intra_mb_refresh_arg
int32_t cu08MergeDeltaRate
int32_t intra_mb_refresh_mode
int32_t independSliceMode
int32_t dependSliceModeArg
int32_t use_recommend_enc_params
int32_t fixedBitRatio[NI_LOGAN_MAX_GOP_NUM]
int32_t pu08IntraDcDeltaRate
int32_t decoding_refresh_type
int32_t independSliceModeArg
int32_t enable_mb_level_rc
uint32_t monochromeEnable
int32_t lfCrossSliceBoundaryEnable
uint32_t forcedHeaderEnable
uint32_t customLambdaEnable
int32_t pu04IntraDcDeltaRate
int32_t pu04IntraAngleDeltaRate
int32_t cu32InterDeltaRate
int32_t pu16IntraAngleDeltaRate
int32_t pu08IntraPlanarDeltaRate
uint32_t nrNoiseEstEnable
int32_t scalingListEnable
int32_t pu16IntraPlanarDeltaRate
uint32_t numTicksPocDiffOne
int32_t pu04IntraPlanarDeltaRate
int32_t enable_transform_8x8
int32_t entropy_coding_mode
int32_t cu32MergeDeltaRate
int32_t cu16MergeDeltaRate
uint32_t weightPredEnable
int32_t pu32IntraAngleDeltaRate
int32_t cu16IntraDeltaRate
int32_t cu08IntraDeltaRate
int32_t cu08InterDeltaRate
int32_t cu32IntraDeltaRate
int32_t pu32IntraDcDeltaRate
ni_logan_custom_gop_params_t custom_gop_params
int32_t pu32IntraPlanarDeltaRate
ni_event_handle_t thread_event_handle
uint32_t keep_alive_timeout
ni_device_handle_t device_handle
uint64_t session_timestamp