27 #elif defined(__linux__) || defined(__APPLE__)
28 #define _POSIX_C_SOURCE 200809L
31 #include <sys/ioctl.h>
33 #include <sys/types.h>
131 #define MAX_LOG2_MAX_FRAME_NUM (12 + 4)
132 #define MIN_LOG2_MAX_FRAME_NUM 4
133 #define EXTENDED_SAR 255
134 #define QP_MAX_NUM (51 + 6*6)
172 static volatile uint32_t dec_flush_sec = 0;
173 static volatile uint32_t dec_flush_cnt = 0;
174 static volatile uint32_t dec_flush_pkt = 0;
175 static int g_file_loop = 1;
178 static int g_reconfigCount = 0;
181 #define MAX_YUV_FRAME_SIZE (7680 * 4320 * 3 / 2)
183 static uint8_t *g_file_cache = NULL;
195 if (rc == ni_logan_err_rc_description[i].rc)
197 return ni_logan_err_rc_description[i].
txt;
200 return "rc not supported";
205 fprintf(stderr,
"Error: unrecognized argument for %s, \"%s\"\n",
213 int to_copy = to_read;
232 static int curr_nal_start = 0;
233 static int curr_found_pos = 0;
245 if (curr_found_pos > nb_bytes)
247 curr_found_pos -= nb_bytes;
261 int i = curr_found_pos;
313 data_size = i - curr_found_pos;
319 static const uint8_t default_scaling4[2][16] =
321 { 6, 13, 20, 28, 13, 20, 28, 32,
322 20, 28, 32, 37, 28, 32, 37, 42 },
323 { 10, 14, 20, 24, 14, 20, 24, 27,
324 20, 24, 27, 30, 24, 27, 30, 34 }
327 static const uint8_t default_scaling8[2][64] =
329 { 6, 10, 13, 16, 18, 23, 25, 27,
330 10, 11, 16, 18, 23, 25, 27, 29,
331 13, 16, 18, 23, 25, 27, 29, 31,
332 16, 18, 23, 25, 27, 29, 31, 33,
333 18, 23, 25, 27, 29, 31, 33, 36,
334 23, 25, 27, 29, 31, 33, 36, 38,
335 25, 27, 29, 31, 33, 36, 38, 40,
336 27, 29, 31, 33, 36, 38, 40, 42 },
337 { 9, 13, 15, 17, 19, 21, 22, 24,
338 13, 13, 17, 19, 21, 22, 24, 25,
339 15, 17, 19, 21, 22, 24, 25, 27,
340 17, 19, 21, 22, 24, 25, 27, 28,
341 19, 21, 22, 24, 25, 27, 28, 30,
342 21, 22, 24, 25, 27, 28, 30, 32,
343 22, 24, 25, 27, 28, 30, 32, 33,
344 24, 25, 27, 28, 30, 32, 33, 35 }
349 0, 1, 8, 16, 9, 2, 3, 10,
350 17, 24, 32, 25, 18, 11, 4, 5,
351 12, 19, 26, 33, 40, 48, 41, 34,
352 27, 20, 13, 6, 7, 14, 21, 28,
353 35, 42, 49, 56, 57, 50, 43, 36,
354 29, 22, 15, 23, 30, 37, 44, 51,
355 58, 59, 52, 45, 38, 31, 39, 46,
356 53, 60, 61, 54, 47, 55, 62, 63
361 0 + 0 * 4, 1 + 0 * 4, 0 + 1 * 4, 0 + 2 * 4,
362 1 + 1 * 4, 2 + 0 * 4, 3 + 0 * 4, 2 + 1 * 4,
363 1 + 2 * 4, 0 + 3 * 4, 1 + 3 * 4, 2 + 2 * 4,
364 3 + 1 * 4, 3 + 2 * 4, 2 + 3 * 4, 3 + 3 * 4,
382 for (i = 0; i < cpb_count; i++)
399 int ret = -1, aspect_ratio_info_present_flag;
400 unsigned int aspect_ratio_idc, dummy;
403 if (aspect_ratio_info_present_flag)
413 sps->
sar = ni_h264_pixel_aspect_list[aspect_ratio_idc];
418 __FUNCTION__, aspect_ratio_idc);
472 if (! num_units_in_tick || ! time_scale)
475 __FUNCTION__, num_units_in_tick, time_scale);
485 "parse_hrd !\n", __FUNCTION__);
493 "parse_hrd !\n", __FUNCTION__);
533 const uint8_t *jvt_list,
const uint8_t *fallback_list)
535 int i, last = 8, next = 8;
541 memcpy(factors, fallback_list, size *
sizeof(uint8_t));
545 for (i = 0; i < size; i++)
550 if (v < -128 || v > 127)
555 next = (last + v) & 0xff;
559 memcpy(factors, jvt_list, size *
sizeof(uint8_t));
562 last = (factors[scan[i]] = next ? next : last);
571 uint8_t(*scaling_matrix4)[16],
572 uint8_t(*scaling_matrix8)[64])
576 const uint8_t *fallback[4] = {
602 default_scaling8[0], fallback[2]);
604 default_scaling8[1], fallback[3]);
608 default_scaling8[0], scaling_matrix8[0]);
610 default_scaling8[1], scaling_matrix8[3]);
612 default_scaling8[0], scaling_matrix8[1]);
614 default_scaling8[1], scaling_matrix8[4]);
630 int profile_idc, level_idc, constraint_set_flags = 0;
632 int i, log2_max_frame_num_minus4;
661 if (100 == profile_idc || 110 == profile_idc || 122 == profile_idc ||
662 244 == profile_idc || 44 == profile_idc || 83 == profile_idc ||
663 86 == profile_idc || 118 == profile_idc || 128 == profile_idc ||
664 138 == profile_idc || 139 == profile_idc || 134 == profile_idc ||
665 135 == profile_idc || 144 == profile_idc )
679 "supported !\n", __FUNCTION__);
721 "range (0-12)!\n", __FUNCTION__, log2_max_frame_num_minus4);
791 int step_x = 1 << hsub;
832 int *sei_type,
int *is_interlaced)
848 int size = 0, tmp, next;
859 }
while (tmp == 0xFF);
872 }
while (tmp == 0xFF);
885 if (cpb_dpb_delays_present_flag)
897 __FUNCTION__, dummy);
926 uint8_t *p_buf = buf;
927 int nal_size, ep3_removed = 0, vcl_nal_count = 0;
928 int nal_type = -1, sei_type = -1;
929 int sps_parsed = 0, is_interlaced = 0;
939 while ((! sps_parsed || ! is_interlaced) && vcl_nal_count < 100 &&
946 while (! (p_buf[0] == 0x00 && p_buf[1] == 0x00 && p_buf[2] == 0x01) &&
962 nal_size -= ep3_removed;
966 if (vcl_nal_count > 0)
969 __FUNCTION__, vcl_nal_count);
981 parse_sei(p_buf, nal_size, sps, &sei_type, &is_interlaced);
993 ni_log(
NI_LOG_ERROR,
"probe_h264_stream_info interlaced NOT supported!\n", __FUNCTION__);
1001 vcl_nal_count, sps_parsed ?
"Yes":
"No", is_interlaced ?
"Yes":
"No");
1002 if (sps_parsed && ! is_interlaced)
1009 "probing failed.\n");
1012 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
1014 "profile:%d/%d poc %d ref:%d %dx%d [SAR: %d:%d] %s %s "
1015 "%"PRId32
"/%"PRId32
" %d bits max_reord:%d max_dec_buf:"
1037 int32_t *frame_num,
unsigned int *first_mb_in_slice)
1040 uint8_t *p_buf = buf;
1041 unsigned int slice_type, pps_id;
1044 while (! (p_buf[0] == 0x00 && p_buf[1] == 0x00 && p_buf[2] == 0x01) &&
1050 if (size_bytes <= 3)
1069 __FUNCTION__, slice_type, *first_mb_in_slice);
1075 ni_log(
NI_LOG_TRACE,
"%s slice type %u frame_num %d pps_id %u size %d first_mb %u\n",
1076 __FUNCTION__, slice_type, *frame_num, pps_id, size_bytes, *first_mb_in_slice);
1094 static int ni_find_next_non_vcl_nalu(
const uint8_t *in,
int in_size,
1102 if (i + 3 >= in_size)
1108 while ((in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x01) &&
1109 (in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x00 ||
1113 if (i + 3 > in_size)
1120 if (in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x01)
1130 *nal_type = (in[i] & 0x1f);
1138 *nal_type = (in[i] >> 1);
1146 while ((in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x00) &&
1147 (in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x01))
1151 if (i + 3 > in_size)
1153 data_size = in_size;
1184 uint8_t stream_headers[4 * 1024];
1185 uint8_t *hdr_ptr = stream_headers;
1188 int nal_type = -1, nal_size, header_size = 0;
1189 int sps_found = 0, pps_found = 0, vps_found = 0, headers_found = 0;
1193 while (data_size > 3 && (nal_size = ni_find_next_non_vcl_nalu(
1200 headers_found = (headers_found || (sps_found && pps_found));
1207 headers_found = (headers_found || (vps_found && sps_found && pps_found));
1216 header_size += nal_size;
1217 memcpy(hdr_ptr, buf, nal_size);
1218 hdr_ptr += nal_size;
1222 data_size -= nal_size;
1227 p_ctx, stream_headers, header_size))
1246 int input_video_width,
1247 int input_video_height,
1249 unsigned long *total_bytes_sent,
1254 static int sos_flag = 1;
1256 uint8_t *tmp_buf_ptr = tmp_buf;
1258 int frame_pkt_size = 0, nal_size;
1263 int saved_prev_size = 0;
1264 int32_t frame_num = -1, curr_frame_num;
1265 unsigned int first_mb_in_slice = 0;
1278 if (dec_flush_cnt > 0 && dec_flush_pkt == p_dec_ctx->
pkt_num)
1281 "%" PRId64
"\n", p_dec_ctx->
pkt_num);
1299 frame_pkt_size += nal_size;
1300 tmp_buf_ptr += nal_size;
1302 nal_type, nal_size);
1308 p_dec_ctx, tmp_buf, frame_pkt_size))
1317 &curr_frame_num, &first_mb_in_slice))
1319 if (-1 == frame_num)
1322 frame_num = curr_frame_num;
1324 else if (curr_frame_num != frame_num || 0 == first_mb_in_slice)
1329 frame_pkt_size -= nal_size;
1338 "size %d, continue\n", __FUNCTION__, nal_type, nal_size);
1341 else if (-1 != frame_num)
1345 frame_pkt_size -= nal_size;
1358 p_in_pkt->
data_len = frame_pkt_size;
1360 if (frame_pkt_size + p_dec_ctx->
prev_size > 0)
1366 send_size = frame_pkt_size + p_dec_ctx->
prev_size;
1393 if (--g_file_loop > 0)
1413 p_in_pkt->
data_len += saved_prev_size;
1417 if (dec_flush_cnt > 0 || dec_flush_sec > 0) {
1431 fprintf(stderr,
"Error: sending data error. rc:%d\n", tx_size);
1435 else if (tx_size == 0)
1440 else if (tx_size < send_size)
1448 *total_bytes_sent += tx_size;
1457 printf(
"%s: success, total sent: %ld\n", __FUNCTION__, *total_bytes_sent);
1483 int output_video_width,
1484 int output_video_height,
1486 unsigned long long *total_bytes_received,
1534 fprintf(stderr,
"Error: receiving data error. rc:%d\n", rx_size);
1539 else if (rx_size > 0)
1549 if (rx_size > 0 && p_file)
1552 for (i = 0; i < 3; i++)
1554 uint8_t *src = p_out_frame->
p_data[i];
1557 int write_height = output_video_height;
1558 int write_width = output_video_width;
1559 if (i == 1 || i == 2)
1574 for (j = 0; j < plane_height; j++)
1576 if (j < write_height && fwrite(src, write_width, 1, p_file) != 1)
1578 fprintf(stderr,
"Error: writing data plane %d: height %d error!\n",
1580 fprintf(stderr,
"Error: ferror rc = %d\n", ferror(p_file));
1587 fprintf(stderr,
"Error: writing data frame flush failed! errno %d\n", errno);
1591 *total_bytes_received += rx_size;
1595 printf(
"[R] Got:%d Frames= %u fps=%lu Total bytes %llu\n", rx_size,
1598 (
unsigned long long) *total_bytes_received);
1603 printf(
"Decoder Receiving done.\n");
1607 else if (0 == rx_size)
1628 int input_video_width,
1629 int input_video_height,
1630 unsigned long *bytes_sent,
1634 volatile static int started = 0;
1635 volatile static int need_to_resend = 0;
1660 int frame_size = input_video_width * input_video_height * p_enc_ctx->
bit_depth_factor;
1662 frame_size += (video_width / 2) * (video_height / 2) * 2 * p_enc_ctx->
bit_depth_factor;
1666 p_in_frame->start_of_stream = 0;
1670 p_in_frame->start_of_stream = 1;
1672 p_in_frame->end_of_stream = 0;
1673 p_in_frame->force_key_frame = 0;
1674 if (chunk_size == 0)
1676 p_in_frame->end_of_stream = 1;
1679 p_in_frame->video_width = video_width;
1680 p_in_frame->video_height = video_height;
1682 p_in_frame->ni_logan_pict_type = 0;
1683 p_in_frame->roi_len = 0;
1684 p_in_frame->reconf_len = 0;
1685 p_in_frame->force_pic_qp = 0;
1693 p_in_frame, g_reconfigCount);
1700 g_reconfigCount = ret;
1713 mdcv_data, cll_data, cc_data, udu_data, hdrp_data);
1717 "size %u.\n", __FUNCTION__, p_in_frame->sei_total_len,
1723 p_in_frame->extra_data_len += p_in_frame->sei_total_len;
1726 if ((p_in_frame->sei_total_len ||
1727 p_in_frame->roi_len)
1728 && !p_in_frame->reconf_len)
1738 dst_stride, dst_height_aligned);
1744 p_in_frame->extra_data_len,
1746 if (! p_in_frame->p_data[0])
1748 fprintf(stderr,
"Error: could not allocate YUV frame buffer!");
1753 "dst height aligned = %d/%d/%d \n",
1754 dst_stride[0], dst_stride[1], dst_stride[2], input_video_height,
1755 dst_height_aligned[0], dst_height_aligned[1], dst_height_aligned[2]);
1764 src_height[0] = input_video_height;
1766 src_height[2] = video_height / 2;
1768 p_src[1] = tmp_buf + src_stride[0] * src_height[0];
1769 p_src[2] = p_src[1] + src_stride[1] * src_height[1];
1772 input_video_width, input_video_height,
1774 dst_stride, dst_height_aligned,
1775 src_stride, src_height);
1779 cc_data, udu_data, hdrp_data);
1786 fprintf(stderr,
"Error: failed ni_logan_device_session_write() for encoder\n");
1798 *bytes_sent += p_in_frame->data_len[0] + p_in_frame->data_len[1] +
1799 p_in_frame->data_len[2];
1801 __FUNCTION__, *bytes_sent);
1828 int input_video_width,
int input_video_height,
1829 unsigned long *bytes_sent,
1832 volatile static int started = 0;
1833 volatile static int need_to_resend_2 = 0;
1850 if (need_to_resend_2)
1871 "source: %d, NO SEI, reusing the frame struct!\n",
1873 p_to_send = p_dec_out_data;
1897 p_to_send = p_enc_in_data;
1911 p_in_frame, g_reconfigCount);
1918 g_reconfigCount = ret;
1926 dst_stride, dst_height_aligned);
1943 mdcv_data, cll_data, cc_data, udu_data, hdrp_data);
1960 if (! p_in_frame->
p_data[0])
1962 fprintf(stderr,
"Error: cannot allocate YUV frame buffer!");
1967 "dst height aligned = %d/%d/%d force_key_frame=%d, extra_data_len=%d"
1968 " sei_size=%u (hdr_content_light_level %u hdr_mastering_display_"
1969 "color_vol %u hdr10+ %u hrd %u) reconf_size=%u roi_size=%u "
1970 "force_pic_qp=%u udu_sei_size=%u "
1971 "use_cur_src_as_long_term_pic %u use_long_term_ref %u \n",
1972 dst_stride[0], dst_stride[1], dst_stride[2], input_video_height,
1973 dst_height_aligned[0], dst_height_aligned[1], dst_height_aligned[2],
1991 src_stride[2] = src_stride[0] / 2;
1998 src_height[2] = src_height[0] / 2;
2002 input_video_width, input_video_height,
2004 dst_stride, dst_height_aligned,
2005 src_stride, src_height);
2010 udu_data, hdrp_data);
2035 goto end_encoder_send_data2;
2039 fprintf(stderr,
"Error: %s\n", __FUNCTION__);
2040 need_to_resend_2 = 1;
2043 else if (oneSent == 0)
2047 need_to_resend_2 = 0;
2052 need_to_resend_2 = 1;
2057 need_to_resend_2 = 0;
2065 end_encoder_send_data2:
2079 int output_video_width,
int output_video_height,
2081 unsigned long long *total_bytes_received,
2110 if (rx_size > meta_size)
2112 if (p_file && (fwrite((uint8_t*)p_out_pkt->
p_data + meta_size,
2113 p_out_pkt->
data_len - meta_size, 1, p_file) != 1))
2115 fprintf(stderr,
"Error: writing data %d bytes error!\n",
2117 fprintf(stderr,
"Error: ferror rc = %d\n", ferror(p_file));
2120 *total_bytes_received += rx_size - meta_size;
2132 else if (rx_size != 0)
2134 fprintf(stderr,
"Error: received %d bytes, <= metadata size %d!\n",
2135 rx_size, meta_size);
2151 printf(
"[R] Got:%d Packets= %u fps=%d Total bytes %lld\n",
2153 *total_bytes_received);
2158 printf(
"Encoder Receiving done.\n");
2176 int dst_codec_format,
int xcoder_id,
2177 const char *xcoder_name,
2179 int src_bit_depth,
int width,
int height,
2183 int video_full_range_flag,
2184 int sar_num,
int sar_den)
2196 p_enc_ctx->
hw_id = xcoder_id;
2197 p_enc_ctx->
hw_name = xcoder_name;
2211 int linesize_aligned = ((width + 7) / 8) * 8;
2214 linesize_aligned = ((width + 15) / 16) * 16;
2221 else if (linesize_aligned > width)
2227 int height_aligned = ((height + 7) / 8) * 8;
2230 height_aligned = ((height + 15) / 16) * 16;
2237 else if (height_aligned > height)
2244 ni_logan_set_vui(p_enc_params, p_enc_ctx, color_primaries, color_trc, color_space,
2245 video_full_range_flag, sar_num, sar_den, dst_codec_format);
2250 fprintf(stderr,
"Error: %s failure!\n", __FUNCTION__);
2254 if (xcoder_name != NULL)
2256 printf(
"Encoder device %s session open successful.\n", xcoder_name);
2260 printf(
"Encoder device %d session open successful.\n", xcoder_id);
2269 printf(
"Video decoder/encoder/transcoder application directly using Netint Libxcoder API v%s\n"
2270 "Usage: xcoder [options]\n"
2273 "-h | --help Show help.\n"
2274 "-l | --loglevel Set loglevel of libxcoder API.\n"
2275 " [none, fatal, error, info, debug, trace]\n"
2276 " (Default: info)\n"
2277 "-c | --card Set card index to use.\n"
2278 " See `ni_logan_rsrc_mon` for cards on system.\n"
2280 "-n | --devname Specify the xcoder device name to work.\n"
2281 "-i | --input Input file path.\n"
2282 "-s | --size Resolution of input file in format WIDTHxHEIGHT.\n"
2283 " (eg. '1920x1080')\n"
2284 "-m | --mode Input to output codec processing mode in format:\n"
2285 " INTYPE2OUTTYPE. [a2y, h2y, y2a, y2h, a2a, a2h, h2a, h2h]\n"
2286 " Type notation: y=YUV420P a=AVC, h=HEVC\n"
2287 "-b | --bitdepth Input and output bit depth. [8, 10]\n"
2289 "-x | --xcoder-params Encoding params. See \"Encoding Parameters\" chapter in\n"
2290 " IntegrationProgrammingGuideT408_T432_FW*.pdf for help.\n"
2291 " (Default: \"\")\n"
2292 "-o | --output Output file path.\n"
2293 "-p | --loop Number of times to repeat input file. (Default: 1)\n"
2294 "-a | --dec_async Decoding in asynchronous multi-threading.\n"
2295 "-e | --enc_async Encoding in asynchronous multi-threading.\n"
2296 "-t | --dec_flush_sec Flush decoder at the specified second\n"
2297 "-f | --dec_flush Flush decoder at the specific packet index. Prefix\n"
2298 " number with 'r' to repeatedly flush at packet period.\n"
2305 static int get_key_value(
char *p_str,
char *key,
char *value)
2307 if (! p_str || ! key || ! value)
2312 char *p = strchr(p_str,
'=');
2322 strncat(key, p_str, strlen(p_str));
2323 strncat(value, p+1, strlen(p+1));
2329 static int32_t log_str_to_level(
char *log_str)
2333 for (i = 0; i < strlen(log_str); i++)
2334 log_str[i] = tolower((
unsigned char) log_str[i]);
2336 if (strcmp(log_str,
"none") == 0)
2338 else if (strcmp(log_str,
"fatal") == 0)
2340 else if (strcmp(log_str,
"error") == 0)
2342 else if (strcmp(log_str,
"info") == 0)
2344 else if (strcmp(log_str,
"debug") == 0)
2346 else if (strcmp(log_str,
"trace") == 0)
2349 converted_log_level = -16;
2350 return converted_log_level;
2355 static int retrieve_xcoder_params(
char xcoderParams[],
2359 char key[64], value[64];
2360 char *p = xcoderParams;
2361 char *curr = xcoderParams, *colon_pos;
2366 colon_pos = strchr(curr,
':');
2373 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
2374 get_key_value(curr, key, value))
2376 fprintf(stderr,
"Error: xcoder-params p_config key/value not "
2377 "retrieved: %s\n", curr);
2385 fprintf(stderr,
"Error: unknown option: %s.\n", key);
2388 fprintf(stderr,
"Error: invalid value for %s: %s.\n", key, value);
2396 fprintf(stderr,
"Error: config parsing failed %d: %s\n", ret,
2397 ni_logan_get_rc_txt(ret));
2403 curr = colon_pos + 1;
2407 curr += strlen(curr);
2414 static void *decoder_send_routine(
void *arg)
2439 static void *decoder_receive_routine(
void *arg)
2456 else if (ret < 0 || p_frm->end_of_stream)
2475 static void *decoder_flush_routine(
void *arg)
2498 static void *encoder_send_routine(
void *arg)
2523 static void *encoder_receive_routine(
void *arg)
2563 int err = 0, pfs = 0, sos_flag = 0, edFlag = 0, bytes_sent = 0;
2565 char xcoder_name[32] = {
'\0'};
2566 unsigned long total_bytes_sent;
2567 unsigned long long total_bytes_received;
2568 unsigned long long xcodeRecvTotal;
2569 FILE *p_file = NULL;
2571 char mode_description[128];
2572 int input_video_width;
2573 int input_video_height;
2583 char encConfXcoderParams[2048] = { 0 };
2584 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE, dev_handle_1 = NI_INVALID_DEVICE_HANDLE;
2585 int src_codec_format = 0, dst_codec_format = 0;
2593 const char *opt_string =
"aehl:c:n:f:i:s:m:b:o:p:t:x:";
2594 static struct option long_options[] =
2614 while ((opt =
getopt_long(argc, argv, opt_string, long_options, &opt_index)) != -1)
2628 loglevel = log_str_to_level(
optarg);
2634 xcoder_id = strtol(
optarg, &n, 10);
2639 strcpy(xcoder_name,
optarg);
2645 arg_width = (int) strtol(
optarg, &n, 10);
2646 arg_height =
atoi(n + 1);
2647 if ((*n !=
'x') || (!arg_width || !arg_height))
2651 if (!(strlen(
optarg) == 3))
2654 for (i = 0; i < strlen(
optarg); i++)
2657 if (strcmp(
optarg,
"y2a") &&
2670 sprintf(mode_description,
"Encoding");
2673 else if (
optarg[2] ==
'y')
2675 sprintf(mode_description,
"Decoding");
2684 sprintf(mode_description,
"Transcoding");
2692 strcat(mode_description,
" from AVC");
2697 strcat(mode_description,
" from HEVC");
2702 strcat(mode_description,
" to AVC");
2707 strcat(mode_description,
" to HEVC");
2720 strcpy(encConfXcoderParams,
optarg);
2727 if (dec_flush_sec < 0)
2741 if (dec_flush_pkt < 0)
2753 printf(
"Error: missing argument for -i | --input\n");
2758 printf(
"Error: missing argument for -m | --mode\n");
2763 printf(
"Error: missing argument for -o | --output\n");
2771 printf(
"%s...\n", mode_description);
2777 pfs = open(sdPara.
fileName, O_RDONLY | O_BINARY);
2778 #elif defined(__linux__)
2779 pfs = open(sdPara.
fileName, O_RDONLY);
2784 fprintf(stderr,
"Error: cannot open %s\n", sdPara.
fileName);
2785 fprintf(stderr,
"Error: input file read failure\n");
2789 printf(
"SUCCESS: Opened input file: %s with file id = %d\n", sdPara.
fileName, pfs);
2791 lseek(pfs, 0, SEEK_END);
2793 lseek(pfs, 0, SEEK_SET);
2798 fprintf(stderr,
"Error: input file size %lu exceeding max malloc, quit\n",
2807 uint32_t chunk_size = tmpFileSize > 4096 ? 4096 : tmpFileSize;
2809 if (one_read_size == -1)
2811 fprintf(stderr,
"Error: reading file, quit! left-to-read %lu\n", tmpFileSize);
2816 tmpFileSize -= one_read_size;
2820 printf(
"read %lu bytes from input file into memory\n",
total_file_size);
2825 if (strcmp(rcPara.
fileName,
"null"))
2827 p_file = fopen(rcPara.
fileName,
"wb");
2830 fprintf(stderr,
"Error: cannot open %s\n", rcPara.
fileName);
2835 printf(
"SUCCESS: Opened output file: %s\n", rcPara.
fileName);
2843 fprintf(stderr,
"ERROR: H.264 file probing complete, source file format "
2844 "not supported !\n");
2851 arg_width = SPS.
width;
2862 arg_width, arg_height) < 0)
2864 fprintf(stderr,
"Error: decoder p_config set up error\n");
2903 dec_ctx.
hw_id = xcoder_id;
2904 dec_ctx.
hw_name = &xcoder_name[0];
2919 fprintf(stderr,
"Error: ni_logan_decoder_session_open() failure!\n");
2924 if (xcoder_name[0] !=
'\0')
2926 printf(
"Encoder device %s session open successful.\n", xcoder_name);
2930 printf(
"Encoder device %d session open successful.\n", xcoder_id);
2947 total_bytes_received = 0;
2949 total_bytes_sent = 0;
2951 printf(
"user video resolution: %dx%d\n", arg_width, arg_height);
2952 if (arg_width == 0 || arg_height == 0)
2954 input_video_width = 1280;
2955 input_video_height = 720;
2959 input_video_width = arg_width;
2960 input_video_height = arg_height;
2962 int output_video_width = input_video_width;
2963 int output_video_height = input_video_height;
2975 struct timespec start, end;
2976 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
2986 printf(
"Decoding Mode: %dx%d to %dx%d\n",
2987 input_video_width, input_video_height,
2988 output_video_width, output_video_height);
2999 ni_pthread_t send_tid, recv_tid, flush_tid;
3003 send_param.
p_ctx = &dec_ctx;
3004 send_param.
p_data = &in_pkt;
3011 send_param.
p_SPS = &SPS;
3013 recv_param.
p_ctx = &dec_ctx;
3014 recv_param.
p_data = &out_frame;
3018 recv_param.
p_file = p_file;
3022 if (ni_logan_pthread_create(&send_tid, NULL, decoder_send_routine, &send_param))
3024 fprintf(stderr,
"create send pkt thread failed in decoder mode\n");
3028 if (ni_logan_pthread_create(&recv_tid, NULL, decoder_receive_routine, &recv_param))
3030 fprintf(stderr,
"create recv frame thread failed in decoder mode\n");
3034 if (dec_flush_sec > 0 &&
3035 ni_logan_pthread_create(&flush_tid, NULL, decoder_flush_routine, &send_param))
3037 fprintf(stderr,
"create flush frame thread failed in decoder mode\n");
3041 ni_logan_pthread_join(send_tid, NULL);
3042 ni_logan_pthread_join(recv_tid, NULL);
3043 if (dec_flush_sec > 0)
3046 ni_logan_pthread_join(flush_tid, NULL);
3059 &dec_ctx, &in_pkt, input_video_width, input_video_height,
3060 pkt_size, &total_bytes_sent, print_time, &xcodeState, &SPS);
3064 fprintf(stderr,
"Error: decoder_send_data() failed, rc: %d\n",
3071 &dec_ctx, &out_frame, output_video_width, output_video_height,
3072 p_file, &total_bytes_received, print_time, &xcodeState);
3092 printf(
"[R] Got: Frames= %u fps=%d Total bytes %llu\n",
3105 printf(
"Encoding Mode: %dx%d to %dx%d\n",
3106 input_video_width, input_video_height,
3107 output_video_width, output_video_height);
3113 fprintf(stderr,
"Error: encoder init default set up error\n");
3118 if (retrieve_xcoder_params(encConfXcoderParams, &enc_api_param, &enc_ctx))
3120 fprintf(stderr,
"Error: encoder p_config parsing error\n");
3126 int video_full_range_flag = 0;
3137 &enc_api_param, bit_depth, arg_width, arg_height,
3141 video_full_range_flag,
3151 ni_pthread_t send_tid, recv_tid;
3153 send_param.
p_ctx = &enc_ctx;
3154 send_param.
p_data = &in_frame;
3161 recv_param.
p_ctx = &enc_ctx;
3162 recv_param.
p_data = &out_packet;
3166 recv_param.
p_file = p_file;
3170 if (ni_logan_pthread_create(&send_tid, NULL, encoder_send_routine, &send_param))
3172 fprintf(stderr,
"create send frame thread failed in encoder mode\n");
3176 if (ni_logan_pthread_create(&recv_tid, NULL, encoder_receive_routine, &recv_param))
3178 fprintf(stderr,
"create recv pkt thread failed in encoder mode\n");
3182 ni_logan_pthread_join(send_tid, NULL);
3183 ni_logan_pthread_join(recv_tid, NULL);
3194 &enc_ctx, &in_frame, input_video_width, input_video_height,
3195 &total_bytes_sent, &xcodeState);
3204 &enc_ctx, &out_packet, output_video_width, output_video_height,
3205 p_file, &total_bytes_received, print_time);
3226 printf(
"[R] Got: Packets= %u fps=%d Total bytes %lld\n",
3239 printf(
"Xcoding Mode: %dx%d to %dx%d\n", input_video_width,
3240 input_video_height, output_video_width, output_video_height);
3254 &dec_ctx, &in_pkt, input_video_width, input_video_height, pkt_size,
3255 &total_bytes_sent, print_time, &xcodeState, &SPS);
3265 &dec_ctx, &out_frame, output_video_width, output_video_height,
3266 p_file, &total_bytes_received, print_time, &xcodeState);
3291 int fps_num = 0, fps_den = 0;
3320 arg_width, arg_height) < 0)
3322 fprintf(stderr,
"Error: encoder init default set up error\n");
3330 if (retrieve_xcoder_params(encConfXcoderParams, &enc_api_param, &enc_ctx))
3332 fprintf(stderr,
"Error: encoder p_config parsing error\n");
3355 "overwrite source %d\n", enc_api_param.
color_space, color_space);
3367 sar_num = ni_h264_pixel_aspect_list[
3369 sar_den = ni_h264_pixel_aspect_list[
3374 xcoder_name, &enc_api_param, bit_depth, arg_width,
3375 arg_height, color_pri, color_trc, color_space,
3376 video_full_range_flag, sar_num, sar_den))
3385 &enc_ctx, &dec_ctx, &out_frame, &enc_in_frame,
3386 input_video_width, input_video_height,
3387 &total_bytes_sent, &xcodeState);
3400 &enc_ctx, &out_packet, output_video_width, output_video_height,
3401 p_file, &xcodeRecvTotal, print_time);
3419 printf(
"[R] Got: Frames= %u fps=%d Total bytes %llu\n",
3421 printf(
"[R] Got: Packets= %u fps=%d Total bytes %llu\n",
3450 g_file_cache = NULL;
3452 printf(
"All Done.\n");
void ni_logan_dec_retrieve_aux_data(ni_logan_frame_t *frame)
Retrieve auxiliary data (close caption, various SEI) associated with this frame that is returned by d...
int ni_logan_enc_fill_reconfig_params(ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, ni_logan_frame_t *p_api_fme, int reconfigCount)
Fill reconfig params.
void ni_logan_enc_copy_aux_data(ni_logan_session_context_t *p_enc_ctx, ni_logan_frame_t *p_enc_frame, ni_logan_frame_t *p_dec_frame, ni_logan_codec_format_t codec_format, const uint8_t *mdcv_data, const uint8_t *cll_data, const uint8_t *cc_data, const uint8_t *udu_data, const uint8_t *hdrp_data)
Copy auxiliary data that should be sent together with this frame to encoder.
void ni_logan_set_vui(ni_logan_encoder_params_t *p_param, ni_logan_session_context_t *p_ctx, ni_color_primaries_t color_primaries, ni_color_transfer_characteristic_t color_trc, ni_color_space_t color_space, int video_full_range_flag, int sar_num, int sar_den, ni_logan_codec_format_t codec_format)
Set SPS VUI part of encoded stream header.
int ni_logan_should_send_sei_with_frame(ni_logan_session_context_t *p_enc_ctx, ni_logan_pic_type_t pic_type, ni_logan_encoder_params_t *p_param)
Whether SEI (HDR) should be sent together with this frame to encoder.
void ni_logan_enc_prep_aux_data(ni_logan_session_context_t *p_enc_ctx, ni_logan_frame_t *p_enc_frame, ni_logan_frame_t *p_dec_frame, ni_logan_codec_format_t codec_format, int should_send_sei_with_frame, uint8_t *mdcv_data, uint8_t *cll_data, uint8_t *cc_data, uint8_t *udu_data, uint8_t *hdrp_data)
Prepare auxiliary data that should be sent together with this frame to encoder based on the auxiliary...
enum _ni_color_primaries ni_color_primaries_t
enum _ni_color_transfer_characteristic ni_color_transfer_characteristic_t
#define NI_NUM_PIXEL_ASPECT_RATIO
enum _ni_color_space ni_color_space_t
@ NI_LOGAN_H264_NAL_SLICE
@ NI_LOGAN_H264_NAL_IDR_SLICE
@ NI_H264_SEI_PIC_STRUCT_FRAME_TRIPLING
@ NI_H264_SEI_PIC_STRUCT_FRAME
@ NI_H264_SEI_TYPE_PIC_TIMING
int ni_bs_reader_bits_count(ni_bitstream_reader_t *br)
return the number of bits already parsed in stream
uint32_t ni_bs_reader_get_ue(ni_bitstream_reader_t *br)
read an unsigned Exp-Golomb code ue(v)
int32_t ni_bs_reader_get_se(ni_bitstream_reader_t *br)
read a signed Exp-Golomb code se(v)
void ni_bitstream_reader_init(ni_bitstream_reader_t *br, const uint8_t *data, int bit_size)
init a bitstream reader Note: bitstream_reader takes reading ownership of the data
uint32_t ni_bs_reader_get_bits(ni_bitstream_reader_t *br, int n)
read bits (up to 32) from the bitstream reader, after reader init
int ni_bs_reader_get_bits_left(ni_bitstream_reader_t *br)
return the number of bits left to parse in stream
void ni_bs_reader_skip_bits(ni_bitstream_reader_t *br, int n)
skip a number of bits ahead in the bitstream reader
Utility functions to operate on bits in a bitstream.
@ 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_PARAM_ERROR_HEIGHT_TOO_SMALL
@ NI_LOGAN_RETCODE_ERROR_INVALID_SESSION
@ NI_LOGAN_RETCODE_PARAM_ERROR_ZERO
@ NI_LOGAN_RETCODE_PARAM_ERROR_FRATE
@ NI_LOGAN_RETCODE_PARAM_INVALID_VALUE
@ NI_LOGAN_RETCODE_PARAM_ERROR_TOO_SMALL
@ NI_LOGAN_RETCODE_PARAM_ERROR_OOR
@ NI_LOGAN_RETCODE_PARAM_ERROR_CONF_WIN_TOP
@ NI_LOGAN_RETCODE_PARAM_ERROR_USR_RMD_ENC_PARAM
@ NI_LOGAN_RETCODE_PARAM_ERROR_CU_SIZE_MODE
@ NI_LOGAN_RETCODE_PARAM_ERROR_TRATE
@ NI_LOGAN_RETCODE_PARAM_ERROR_GOP_PRESET
@ NI_LOGAN_RETCODE_PARAM_ERROR_AREA_TOO_BIG
@ NI_LOGAN_RETCODE_PARAM_ERROR_RCENABLE
@ NI_LOGAN_RETCODE_PARAM_ERROR_WIDTH_TOO_SMALL
@ NI_LOGAN_RETCODE_NVME_SC_RESOURCE_IS_EMPTY
@ NI_LOGAN_RETCODE_ERROR_UNLOCK_DEVICE
@ 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_PARAM_ERROR_TOO_BIG
@ NI_LOGAN_RETCODE_ERROR_RESOURCE_UNAVAILABLE
@ NI_LOGAN_RETCODE_PARAM_ERROR_MX_QP
@ NI_LOGAN_RETCODE_PARAM_ERROR_BRATE_LT_TRATE
@ NI_LOGAN_RETCODE_PARAM_ERROR_CUSIZE_MODE_8X8_EN
@ NI_LOGAN_RETCODE_PARAM_ERROR_DY_MERGE_16X16_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_DY_MERGE_8X8_EN
@ NI_LOGAN_RETCODE_PARAM_ERROR_PIC_HEIGHT
@ NI_LOGAN_RETCODE_PARAM_ERROR_INTRA_PERIOD
@ NI_LOGAN_RETCODE_ERROR_VPU_RECOVERY
@ NI_LOGAN_RETCODE_PARAM_INVALID_NAME
@ NI_LOGAN_RETCODE_ERROR_GET_DEVICE_POOL
@ NI_LOGAN_RETCODE_PARAM_ERROR_BRATE
@ NI_LOGAN_RETCODE_PARAM_ERROR_HEIGHT_TOO_BIG
@ 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_DY_MERGE_32X32_EN
@ NI_LOGAN_RETCODE_PARAM_ERROR_MX_DELTA_QP
@ NI_LOGAN_RETCODE_NVME_SC_RESOURCE_UNAVAILABLE
@ 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_ERROR_LOCK_DOWN_DEVICE
@ NI_LOGAN_RETCODE_PARAM_ERROR_WIDTH_TOO_BIG
@ NI_LOGAN_RETCODE_ERROR_INVALID_ALLOCATION_METHOD
@ NI_LOGAN_RETCODE_ERROR_OPEN_DEVICE
@ NI_LOGAN_RETCODE_ERROR_EXCEED_MAX_NUM_SESSIONS
@ NI_LOGAN_RETCODE_PARAM_ERROR_RC_INIT_DELAY
@ NI_LOGAN_RETCODE_NVME_SC_VPU_RSRC_INSUFFICIENT
@ NI_LOGAN_RETCODE_PARAM_ERROR_MX_NUM_MERGE
@ NI_LOGAN_RETCODE_NVME_SC_INVALID_PARAMETER
@ NI_LOGAN_RETCODE_NVME_SC_REQUEST_NOT_COMPLETED
@ NI_LOGAN_RETCODE_NVME_SC_RESOURCE_NOT_FOUND
#define NI_LOGAN_APP_ENC_FRAME_META_DATA_SIZE
#define NI_LOGAN_FW_ENC_BITSTREAM_META_DATA_SIZE
#define NI_LOGAN_MAX_NUM_DATA_POINTERS
#define NI_LOGAN_XCODER_REVISION
@ NI_LOGAN_DEVICE_TYPE_ENCODER
@ NI_LOGAN_DEVICE_TYPE_DECODER
#define NI_LOGAN_MAX_TX_SZ
ni_logan_retcode_t ni_logan_packet_buffer_alloc(ni_logan_packet_t *p_packet, int packet_size)
Allocate memory for the packet buffer based on provided packet size.
ni_logan_retcode_t ni_logan_device_dec_session_save_hdrs(ni_logan_session_context_t *p_ctx, uint8_t *hdr_data, uint8_t hdr_size)
Save a stream's headers in a decoder session that can be used later for continuous decoding from the ...
ni_logan_retcode_t ni_logan_device_session_flush(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type)
Sends a flush command to the device ni_logan_device_session_open() If device_type is NI_LOGAN_DEVICE_...
ni_logan_retcode_t ni_logan_device_session_close(ni_logan_session_context_t *p_ctx, int eos_recieved, ni_logan_device_type_t device_type)
Closes device session that was previously opened by calling ni_logan_device_session_open() If device_...
ni_logan_retcode_t ni_logan_packet_buffer_free(ni_logan_packet_t *p_packet)
Free packet buffer that was previously allocated with either ni_logan_packet_buffer_alloc.
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...
LIB_API ni_logan_retcode_t ni_logan_device_dec_session_flush(ni_logan_session_context_t *p_ctx)
Flush a decoder session to get ready to continue decoding.
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.
ni_logan_retcode_t ni_logan_frame_buffer_free(ni_logan_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_logan_frame_buffer_alloc or ni_logan_e...
ni_logan_retcode_t ni_logan_encoder_frame_buffer_alloc(ni_logan_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, int factor)
Allocate memory for the frame buffer for encoding based on given parameters, taking into account pic ...
int ni_logan_packet_copy(void *p_destination, const void *const p_source, int cur_size, void *p_leftover, int *p_prev_size)
Copy video packet accounting for allighment.
int ni_logan_device_session_read(ni_logan_session_context_t *p_ctx, ni_logan_session_data_io_t *p_data, ni_logan_device_type_t device_type)
Reads data the device If device_type is NI_LOGAN_DEVICE_TYPE_DECODER reads data packet from decoder I...
ni_logan_retcode_t ni_logan_encoder_params_set_value(ni_logan_encoder_params_t *p_params, const char *name, const char *value, ni_logan_session_context_t *ctx)
Set value referenced by name in encoder parameters structure.
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_encoder_init_default_params(ni_logan_encoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height)
Initialize default encoder parameters.
ni_logan_retcode_t ni_logan_device_session_open(ni_logan_session_context_t *p_ctx, ni_logan_device_type_t device_type)
Opens a new device session depending on the device_type parameter If device_type is NI_LOGAN_DEVICE_T...
int ni_logan_device_session_write(ni_logan_session_context_t *p_ctx, ni_logan_session_data_io_t *p_data, ni_logan_device_type_t device_type)
Sends data the device If device_type is NI_LOGAN_DEVICE_TYPE_DECODER sends data packet to decoder If ...
ni_logan_retcode_t ni_logan_decoder_init_default_params(ni_logan_decoder_params_t *p_param, int fps_num, int fps_denom, long bit_rate, int width, int height)
Initialize default decoder parameters.
Main NETINT device API header file provides the ability to communicate with NI T-408 type hardware tr...
struct _ni_logan_encoder_change_params_t ni_logan_encoder_change_params_t
This is a data structure for encoding parameters that have changed.
#define NI_LOGAN_MIN_WIDTH
#define NI_LOGAN_MAX_SEI_DATA
#define NI_LOGAN_MIN_HEIGHT
#define NI_LOGAN_ENC_MAX_SEI_BUF_SIZE
#define NI_LOGAN_FRAME_LITTLE_ENDIAN
enum _ni_logan_codec_format ni_logan_codec_format_t
This is an enumeration for supported codec formats.
@ NI_LOGAN_CODEC_FORMAT_H265
@ NI_LOGAN_CODEC_FORMAT_H264
#define NI_LOGAN_INVALID_SESSION_ID
int parse_vui(ni_bitstream_reader_t *br, ni_logan_h264_sps_t *sps)
#define MAX_YUV_FRAME_SIZE
int parse_scaling_list(ni_bitstream_reader_t *br, uint8_t *factors, int size, const uint8_t *jvt_list, const uint8_t *fallback_list)
int main(int argc, char *argv[])
main
volatile int receive_fin_flag
ni_logan_retcode_t decoder_send_data(ni_logan_session_context_t *p_dec_ctx, ni_logan_session_data_io_t *p_in_data, int input_video_width, int input_video_height, int packet_size, unsigned long *total_bytes_sent, int print_time, device_state_t *p_device_state, ni_logan_h264_sps_t *sps)
Send decoder input data.
int probe_h264_stream_info(ni_logan_h264_sps_t *sps)
int parse_h264_slice_header(uint8_t *buf, int size_bytes, ni_logan_h264_sps_t *sps, int32_t *frame_num, unsigned int *first_mb_in_slice)
int parse_scaling_matrices(ni_bitstream_reader_t *br, const ni_logan_h264_sps_t *sps, const ni_logan_h264_pps_t *pps, int is_sps, uint8_t(*scaling_matrix4)[16], uint8_t(*scaling_matrix8)[64])
volatile uint32_t data_left_size
int find_h264_next_nalu(uint8_t *p_dst, int *nal_type)
#define MIN_LOG2_MAX_FRAME_NUM
int parse_hrd(ni_bitstream_reader_t *br, ni_logan_h264_sps_t *sps)
int encoder_receive_data(ni_logan_session_context_t *p_enc_ctx, ni_logan_session_data_io_t *p_out_data, int output_video_width, int output_video_height, FILE *p_file, unsigned long long *total_bytes_received, int print_time)
Receive output data from encoder.
int encoder_send_data(ni_logan_session_context_t *p_enc_ctx, ni_logan_session_data_io_t *p_in_data, int input_video_width, int input_video_height, unsigned long *bytes_sent, device_state_t *p_device_state)
Send encoder input data, read from input file.
int ni_logan_device_dec_session_write(ni_logan_session_context_t *p_ctx, ni_logan_session_data_io_t *p_data)
Sends data to decoder device. The data is assumed to be a full encoded frame that will be scanned,...
int parse_sps(uint8_t *buf, int size_bytes, ni_logan_h264_sps_t *sps)
int encoder_send_data2(ni_logan_session_context_t *p_enc_ctx, ni_logan_session_context_t *p_dec_ctx, ni_logan_session_data_io_t *p_dec_out_data, ni_logan_session_data_io_t *p_enc_in_data, int input_video_width, int input_video_height, unsigned long *bytes_sent, device_state_t *p_device_state)
int parse_sei(uint8_t *buf, int size_bytes, ni_logan_h264_sps_t *sps, int *sei_type, int *is_interlaced)
time_t privious_timestamp
void reset_data_buf_pos(void)
void rewind_data_buf_pos_by(int nb_bytes)
volatile uint32_t number_of_frames
const uint8_t ni_logan_zigzag_scan[16+1]
const uint8_t ni_logan_zigzag_direct[64]
struct _ni_logan_h264_pps_t ni_logan_h264_pps_t
int read_next_chunk(uint8_t *p_dst, uint32_t to_read)
volatile int send_fin_flag
struct timeval start_time previous_time current_time
struct _ni_logan_err_rc_txt_entry ni_logan_err_rc_txt_entry_t
volatile int flush_fin_flag
int decoder_receive_data(ni_logan_session_context_t *p_dec_ctx, ni_logan_session_data_io_t *p_out_data, int output_video_width, int output_video_height, FILE *p_file, unsigned long long *total_bytes_received, int print_time, device_state_t *p_device_state)
Receive decoded output data from decoder.
void arg_error_exit(char *arg_name, char *param)
volatile long total_file_size
#define MAX_LOG2_MAX_FRAME_NUM
volatile uint32_t number_of_packets
int encoder_open_session(ni_logan_session_context_t *p_enc_ctx, int dst_codec_format, int xcoder_id, const char *xcoder_name, ni_logan_encoder_params_t *p_enc_params, int src_bit_depth, int width, int height, ni_color_primaries_t color_primaries, ni_color_transfer_characteristic_t color_trc, ni_color_space_t color_space, int video_full_range_flag, int sar_num, int sar_den)
Encoder session open.
Example code on how to programmatically work with NI T-408 using libxcoder API.
#define XCODER_APP_ENCODE
#define XCODER_APP_TRANSCODE
#define XCODER_APP_DECODE
int getopt_long(int argc, char *argv[], const char *optstring, const struct option *longopts, int *longindex)
#define required_argument
void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
uint8_t * g_curr_cache_pos
struct timeval start_time
struct timeval previous_time
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_copy_hw_yuv420p(uint8_t *p_dst[NI_LOGAN_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_LOGAN_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int bit_depth_factor, int dst_stride[NI_LOGAN_MAX_NUM_DATA_POINTERS], int dst_height[NI_LOGAN_MAX_NUM_DATA_POINTERS], int src_stride[NI_LOGAN_MAX_NUM_DATA_POINTERS], int src_height[NI_LOGAN_MAX_NUM_DATA_POINTERS])
Copy YUV data to Netint HW YUV420p frame layout to be sent to encoder for encoding....
void ni_logan_get_hw_yuv420p_dim(int width, int height, int bit_depth_factor, int is_h264, int plane_stride[NI_LOGAN_MAX_NUM_DATA_POINTERS], int plane_height[NI_LOGAN_MAX_NUM_DATA_POINTERS])
Get dimension information of Netint HW YUV420p frame to be sent to encoder for encoding....
void ni_logan_usleep(int64_t usec)
LIB_API int ni_logan_remove_emulation_prevent_bytes(uint8_t *buf, int size)
Remove emulation prevention byte(s) as needed from the data buffer.
int32_t ni_logan_gettimeofday(struct timeval *p_tp, void *p_tzp)
Exported utility routines definition.
#define NI_LOGAN_ODD2EVEN(X)
ni_logan_encoder_input_params_t enc_input_params
int color_transfer_characteristic
int video_full_range_flag
unsigned int sei_hdr_mastering_display_color_vol_offset
unsigned int sei_hdr_content_light_level_info_offset
uint32_t vui_num_units_in_tick
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
int video_full_range_flag
uint8_t use_long_term_ref
int pic_order_present
pic_order_present_flag
int deblocking_filter_parameters_present
deblocking_filter_parameters_present_flag
int init_qs
pic_init_qs_minus26 + 26
int slice_group_count
num_slice_groups_minus1 + 1
int cabac
entropy_coding_mode_flag
int weighted_pred
weighted_pred_flag
uint8_t chroma_qp_table[2][QP_MAX_NUM+1]
pre-scaled (with chroma_qp_index_offset) version of qp_table
int constrained_intra_pred
constrained_intra_pred_flag
int init_qp
pic_init_qp_minus26 + 26
int mb_slice_group_map_type
uint32_t(*[6] dequant4_coeff)[16]
uint8_t scaling_matrix8[6][64]
uint32_t dequant8_buffer[6][QP_MAX_NUM+1][64]
int transform_8x8_mode
transform_8x8_mode_flag
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
int chroma_qp_index_offset[2]
uint8_t scaling_matrix4[6][16]
int redundant_pic_cnt_present
redundant_pic_cnt_present_flag
uint32_t(*[6] dequant8_coeff)[64]
uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]
int timing_info_present_flag
int pic_struct_present_flag
ni_color_transfer_characteristic_t color_trc
int colour_description_present_flag
ni_color_primaries_t color_primaries
int nal_hrd_parameters_present_flag
int log2_max_frame_num
log2_max_frame_num_minus4 + 4
unsigned int crop_left
frame_cropping_rect_left_offset
int cpb_removal_delay_length
cpb_removal_delay_length_minus1 + 1
int poc_type
pic_order_cnt_type
uint32_t num_units_in_tick
int direct_8x8_inference_flag
int constraint_set_flags
constraint_set[0-3]_flag
int bit_depth_luma
bit_depth_luma_minus8 + 8
int transform_bypass
qpprime_y_zero_transform_bypass_flag
int gaps_in_frame_num_allowed_flag
int bitstream_restriction_flag
uint8_t scaling_matrix8[6][64]
int initial_cpb_removal_delay_length
initial_cpb_removal_delay_length_minus1 + 1
unsigned int max_dec_frame_buffering
int offset_for_non_ref_pic
unsigned int crop_bottom
frame_cropping_rect_bottom_offset
int offset_for_top_to_bottom_field
int vui_parameters_present_flag
int delta_pic_order_always_zero_flag
ni_color_space_t colorspace
uint8_t scaling_matrix4[6][16]
int vcl_hrd_parameters_present_flag
int poc_cycle_length
num_ref_frames_in_pic_order_cnt_cycle
int residual_color_transform_flag
residual_colour_transform_flag
int fixed_frame_rate_flag
int video_signal_type_present_flag
int mb_aff
mb_adaptive_frame_field_flag
short offset_for_ref_frame[256]
int dpb_output_delay_length
dpb_output_delay_length_minus1 + 1
unsigned int crop_right
frame_cropping_rect_right_offset
unsigned int crop_top
frame_cropping_rect_top_offset
int cpb_cnt
See H.264 E.1.2.
int scaling_matrix_present
int crop
frame_cropping_flag
int ref_frame_count
num_ref_frames
int bit_depth_chroma
bit_depth_chroma_minus8 + 8
int log2_max_poc_lsb
log2_max_pic_order_cnt_lsb_minus4
int mb_width
(pic_height_in_map_units_minus1 + 1) * (2 - frame_mbs_only_flag)
uint32_t keep_alive_timeout
ni_device_handle_t device_handle
ni_device_handle_t blk_io_handle
ni_logan_buf_pool_t * dec_fme_buf_pool
ni_region_of_interest_t * av_rois
uint32_t active_video_width
uint32_t active_video_height
union _ni_logan_session_data_io::@4 data
char fileName[FILE_NAME_LEN]
ni_logan_session_context_t * p_enc_ctx
ni_logan_device_context_t * p_enc_rsrc_ctx
ni_logan_session_context_t * p_dec_ctx
ni_logan_device_context_t * p_dec_rsrc_ctx
char fileName[FILE_NAME_LEN]
ni_logan_session_context_t * p_enc_ctx
ni_logan_device_context_t * p_enc_rsrc_ctx
ni_logan_session_context_t * p_dec_ctx
ni_logan_device_context_t * p_dec_rsrc_ctx
device_state_t * p_xcodeState
unsigned long long * p_total_bytes_received
ni_logan_session_data_io_t * p_data
ni_logan_session_context_t * p_ctx
device_state_t * p_xcodeState
ni_logan_session_data_io_t * p_data
unsigned long * p_total_bytes_sent
ni_logan_session_context_t * p_ctx
ni_logan_h264_sps_t * p_SPS