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;
180 #define MAX_YUV_FRAME_SIZE (7680 * 4320 * 3 / 2)
182 static uint8_t *g_file_cache = NULL;
194 if (rc == ni_logan_err_rc_description[i].rc)
196 return ni_logan_err_rc_description[i].
txt;
199 return "rc not supported";
204 fprintf(stderr,
"Error: unrecognized argument for %s, \"%s\"\n",
212 int to_copy = to_read;
231 static int curr_nal_start = 0;
232 static int curr_found_pos = 0;
244 if (curr_found_pos > nb_bytes)
246 curr_found_pos -= nb_bytes;
260 int i = curr_found_pos;
312 data_size = i - curr_found_pos;
318 static const uint8_t default_scaling4[2][16] =
320 { 6, 13, 20, 28, 13, 20, 28, 32,
321 20, 28, 32, 37, 28, 32, 37, 42 },
322 { 10, 14, 20, 24, 14, 20, 24, 27,
323 20, 24, 27, 30, 24, 27, 30, 34 }
326 static const uint8_t default_scaling8[2][64] =
328 { 6, 10, 13, 16, 18, 23, 25, 27,
329 10, 11, 16, 18, 23, 25, 27, 29,
330 13, 16, 18, 23, 25, 27, 29, 31,
331 16, 18, 23, 25, 27, 29, 31, 33,
332 18, 23, 25, 27, 29, 31, 33, 36,
333 23, 25, 27, 29, 31, 33, 36, 38,
334 25, 27, 29, 31, 33, 36, 38, 40,
335 27, 29, 31, 33, 36, 38, 40, 42 },
336 { 9, 13, 15, 17, 19, 21, 22, 24,
337 13, 13, 17, 19, 21, 22, 24, 25,
338 15, 17, 19, 21, 22, 24, 25, 27,
339 17, 19, 21, 22, 24, 25, 27, 28,
340 19, 21, 22, 24, 25, 27, 28, 30,
341 21, 22, 24, 25, 27, 28, 30, 32,
342 22, 24, 25, 27, 28, 30, 32, 33,
343 24, 25, 27, 28, 30, 32, 33, 35 }
348 0, 1, 8, 16, 9, 2, 3, 10,
349 17, 24, 32, 25, 18, 11, 4, 5,
350 12, 19, 26, 33, 40, 48, 41, 34,
351 27, 20, 13, 6, 7, 14, 21, 28,
352 35, 42, 49, 56, 57, 50, 43, 36,
353 29, 22, 15, 23, 30, 37, 44, 51,
354 58, 59, 52, 45, 38, 31, 39, 46,
355 53, 60, 61, 54, 47, 55, 62, 63
360 0 + 0 * 4, 1 + 0 * 4, 0 + 1 * 4, 0 + 2 * 4,
361 1 + 1 * 4, 2 + 0 * 4, 3 + 0 * 4, 2 + 1 * 4,
362 1 + 2 * 4, 0 + 3 * 4, 1 + 3 * 4, 2 + 2 * 4,
363 3 + 1 * 4, 3 + 2 * 4, 2 + 3 * 4, 3 + 3 * 4,
381 for (i = 0; i < cpb_count; i++)
398 int ret = -1, aspect_ratio_info_present_flag;
399 unsigned int aspect_ratio_idc, dummy;
402 if (aspect_ratio_info_present_flag)
412 sps->
sar = ni_h264_pixel_aspect_list[aspect_ratio_idc];
417 __FUNCTION__, aspect_ratio_idc);
471 if (! num_units_in_tick || ! time_scale)
474 __FUNCTION__, num_units_in_tick, time_scale);
484 "parse_hrd !\n", __FUNCTION__);
492 "parse_hrd !\n", __FUNCTION__);
532 const uint8_t *jvt_list,
const uint8_t *fallback_list)
534 int i, last = 8, next = 8;
540 memcpy(factors, fallback_list, size *
sizeof(uint8_t));
544 for (i = 0; i < size; i++)
549 if (v < -128 || v > 127)
554 next = (last + v) & 0xff;
558 memcpy(factors, jvt_list, size *
sizeof(uint8_t));
561 last = (factors[scan[i]] = next ? next : last);
570 uint8_t(*scaling_matrix4)[16],
571 uint8_t(*scaling_matrix8)[64])
575 const uint8_t *fallback[4] = {
601 default_scaling8[0], fallback[2]);
603 default_scaling8[1], fallback[3]);
607 default_scaling8[0], scaling_matrix8[0]);
609 default_scaling8[1], scaling_matrix8[3]);
611 default_scaling8[0], scaling_matrix8[1]);
613 default_scaling8[1], scaling_matrix8[4]);
629 int profile_idc, level_idc, constraint_set_flags = 0;
631 int i, log2_max_frame_num_minus4;
660 if (100 == profile_idc || 110 == profile_idc || 122 == profile_idc ||
661 244 == profile_idc || 44 == profile_idc || 83 == profile_idc ||
662 86 == profile_idc || 118 == profile_idc || 128 == profile_idc ||
663 138 == profile_idc || 139 == profile_idc || 134 == profile_idc ||
664 135 == profile_idc || 144 == profile_idc )
678 "supported !\n", __FUNCTION__);
720 "range (0-12)!\n", __FUNCTION__, log2_max_frame_num_minus4);
790 int step_x = 1 << hsub;
831 int *sei_type,
int *is_interlaced)
847 int size = 0, tmp, next;
858 }
while (tmp == 0xFF);
871 }
while (tmp == 0xFF);
884 if (cpb_dpb_delays_present_flag)
896 __FUNCTION__, dummy);
925 uint8_t *p_buf = buf;
926 int nal_size, ep3_removed = 0, vcl_nal_count = 0;
927 int nal_type = -1, sei_type = -1;
928 int sps_parsed = 0, is_interlaced = 0;
938 while ((! sps_parsed || ! is_interlaced) && vcl_nal_count < 100 &&
945 while (! (p_buf[0] == 0x00 && p_buf[1] == 0x00 && p_buf[2] == 0x01) &&
961 nal_size -= ep3_removed;
965 if (vcl_nal_count > 0)
968 __FUNCTION__, vcl_nal_count);
980 parse_sei(p_buf, nal_size, sps, &sei_type, &is_interlaced);
992 ni_log(
NI_LOG_ERROR,
"probe_h264_stream_info interlaced NOT supported!\n", __FUNCTION__);
1000 vcl_nal_count, sps_parsed ?
"Yes":
"No", is_interlaced ?
"Yes":
"No");
1001 if (sps_parsed && ! is_interlaced)
1008 "probing failed.\n");
1011 static const char csp[4][5] = {
"Gray",
"420",
"422",
"444" };
1013 "profile:%d/%d poc %d ref:%d %dx%d [SAR: %d:%d] %s %s "
1014 "%"PRId32
"/%"PRId32
" %d bits max_reord:%d max_dec_buf:"
1036 int32_t *frame_num,
unsigned int *first_mb_in_slice)
1039 uint8_t *p_buf = buf;
1040 unsigned int slice_type, pps_id;
1043 while (! (p_buf[0] == 0x00 && p_buf[1] == 0x00 && p_buf[2] == 0x01) &&
1049 if (size_bytes <= 3)
1068 __FUNCTION__, slice_type, *first_mb_in_slice);
1074 ni_log(
NI_LOG_TRACE,
"%s slice type %u frame_num %d pps_id %u size %d first_mb %u\n",
1075 __FUNCTION__, slice_type, *frame_num, pps_id, size_bytes, *first_mb_in_slice);
1093 static int ni_find_next_non_vcl_nalu(
const uint8_t *in,
int in_size,
1101 if (i + 3 >= in_size)
1107 while ((in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x01) &&
1108 (in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x00 ||
1112 if (i + 3 > in_size)
1119 if (in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x01)
1129 *nal_type = (in[i] & 0x1f);
1137 *nal_type = (in[i] >> 1);
1145 while ((in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x00) &&
1146 (in[i] != 0x00 || in[i+1] != 0x00 || in[i+2] != 0x01))
1150 if (i + 3 > in_size)
1152 data_size = in_size;
1183 uint8_t stream_headers[4 * 1024];
1184 uint8_t *hdr_ptr = stream_headers;
1187 int nal_type = -1, nal_size, header_size = 0;
1188 int sps_found = 0, pps_found = 0, vps_found = 0, headers_found = 0;
1192 while (data_size > 3 && (nal_size = ni_find_next_non_vcl_nalu(
1199 headers_found = (headers_found || (sps_found && pps_found));
1206 headers_found = (headers_found || (vps_found && sps_found && pps_found));
1215 header_size += nal_size;
1216 memcpy(hdr_ptr, buf, nal_size);
1217 hdr_ptr += nal_size;
1221 data_size -= nal_size;
1226 p_ctx, stream_headers, header_size))
1245 int input_video_width,
1246 int input_video_height,
1248 unsigned long *total_bytes_sent,
1253 static int sos_flag = 1;
1255 uint8_t *tmp_buf_ptr = tmp_buf;
1257 int frame_pkt_size = 0, nal_size;
1262 int saved_prev_size = 0;
1263 int32_t frame_num = -1, curr_frame_num;
1264 unsigned int first_mb_in_slice = 0;
1277 if (dec_flush_cnt > 0 && dec_flush_pkt == p_dec_ctx->
pkt_num)
1280 "%" PRId64
"\n", p_dec_ctx->
pkt_num);
1298 frame_pkt_size += nal_size;
1299 tmp_buf_ptr += nal_size;
1301 nal_type, nal_size);
1307 p_dec_ctx, tmp_buf, frame_pkt_size))
1316 &curr_frame_num, &first_mb_in_slice))
1318 if (-1 == frame_num)
1321 frame_num = curr_frame_num;
1323 else if (curr_frame_num != frame_num || 0 == first_mb_in_slice)
1328 frame_pkt_size -= nal_size;
1337 "size %d, continue\n", __FUNCTION__, nal_type, nal_size);
1340 else if (-1 != frame_num)
1344 frame_pkt_size -= nal_size;
1357 p_in_pkt->
data_len = frame_pkt_size;
1359 if (frame_pkt_size + p_dec_ctx->
prev_size > 0)
1365 send_size = frame_pkt_size + p_dec_ctx->
prev_size;
1392 if (--g_file_loop > 0)
1412 p_in_pkt->
data_len += saved_prev_size;
1416 if (dec_flush_cnt > 0 || dec_flush_sec > 0) {
1430 fprintf(stderr,
"Error: sending data error. rc:%d\n", tx_size);
1434 else if (tx_size == 0)
1439 else if (tx_size < send_size)
1447 *total_bytes_sent += tx_size;
1456 printf(
"%s: success, total sent: %ld\n", __FUNCTION__, *total_bytes_sent);
1482 int output_video_width,
1483 int output_video_height,
1485 unsigned long long *total_bytes_received,
1533 fprintf(stderr,
"Error: receiving data error. rc:%d\n", rx_size);
1538 else if (rx_size > 0)
1548 if (rx_size > 0 && p_file)
1551 for (i = 0; i < 3; i++)
1553 uint8_t *src = p_out_frame->
p_data[i];
1556 int write_height = output_video_height;
1557 int write_width = output_video_width;
1558 if (i == 1 || i == 2)
1573 for (j = 0; j < plane_height; j++)
1575 if (j < write_height && fwrite(src, write_width, 1, p_file) != 1)
1577 fprintf(stderr,
"Error: writing data plane %d: height %d error!\n",
1579 fprintf(stderr,
"Error: ferror rc = %d\n", ferror(p_file));
1586 fprintf(stderr,
"Error: writing data frame flush failed! errno %d\n", errno);
1590 *total_bytes_received += rx_size;
1594 printf(
"[R] Got:%d Frames= %u fps=%lu Total bytes %llu\n", rx_size,
1597 (
unsigned long long) *total_bytes_received);
1602 printf(
"Decoder Receiving done.\n");
1606 else if (0 == rx_size)
1627 int input_video_width,
1628 int input_video_height,
1629 unsigned long *bytes_sent,
1633 volatile static int started = 0;
1634 volatile static int need_to_resend = 0;
1656 int frame_size = input_video_width * input_video_height * p_enc_ctx->
bit_depth_factor;
1658 frame_size += (video_width / 2) * (video_height / 2) * 2 * p_enc_ctx->
bit_depth_factor;
1670 if (chunk_size == 0)
1686 dst_stride, dst_height_aligned);
1694 if (! p_in_frame->
p_data[0])
1696 fprintf(stderr,
"Error: could not allocate YUV frame buffer!");
1701 "dst height aligned = %d/%d/%d \n",
1702 dst_stride[0], dst_stride[1], dst_stride[2], input_video_height,
1703 dst_height_aligned[0], dst_height_aligned[1], dst_height_aligned[2]);
1712 src_height[0] = input_video_height;
1714 src_height[2] = video_height / 2;
1716 p_src[1] = tmp_buf + src_stride[0] * src_height[0];
1717 p_src[2] = p_src[1] + src_stride[1] * src_height[1];
1720 input_video_width, input_video_height,
1722 dst_stride, dst_height_aligned,
1723 src_stride, src_height);
1729 fprintf(stderr,
"Error: failed ni_logan_device_session_write() for encoder\n");
1744 __FUNCTION__, *bytes_sent);
1771 int input_video_width,
int input_video_height,
1772 unsigned long *bytes_sent,
1775 volatile static int started = 0;
1776 volatile static int need_to_resend_2 = 0;
1793 if (need_to_resend_2)
1814 "source: %d, NO SEI, reusing the frame struct!\n",
1816 p_to_send = p_dec_out_data;
1840 p_to_send = p_enc_in_data;
1855 dst_stride, dst_height_aligned);
1872 mdcv_data, cll_data, cc_data, udu_data, hdrp_data);
1889 if (! p_in_frame->
p_data[0])
1891 fprintf(stderr,
"Error: cannot allocate YUV frame buffer!");
1896 "dst height aligned = %d/%d/%d force_key_frame=%d, extra_data_len=%d"
1897 " sei_size=%u (hdr_content_light_level %u hdr_mastering_display_"
1898 "color_vol %u hdr10+ %u hrd %u) reconf_size=%u roi_size=%u "
1899 "force_pic_qp=%u udu_sei_size=%u "
1900 "use_cur_src_as_long_term_pic %u use_long_term_ref %u \n",
1901 dst_stride[0], dst_stride[1], dst_stride[2], input_video_height,
1902 dst_height_aligned[0], dst_height_aligned[1], dst_height_aligned[2],
1920 src_stride[2] = src_stride[0] / 2;
1927 src_height[2] = src_height[0] / 2;
1931 input_video_width, input_video_height,
1933 dst_stride, dst_height_aligned,
1934 src_stride, src_height);
1939 udu_data, hdrp_data);
1964 goto end_encoder_send_data2;
1968 fprintf(stderr,
"Error: %s\n", __FUNCTION__);
1969 need_to_resend_2 = 1;
1972 else if (oneSent == 0)
1976 need_to_resend_2 = 0;
1981 need_to_resend_2 = 1;
1986 need_to_resend_2 = 0;
1994 end_encoder_send_data2:
2008 int output_video_width,
int output_video_height,
2010 unsigned long long *total_bytes_received,
2039 if (rx_size > meta_size)
2041 if (p_file && (fwrite((uint8_t*)p_out_pkt->
p_data + meta_size,
2042 p_out_pkt->
data_len - meta_size, 1, p_file) != 1))
2044 fprintf(stderr,
"Error: writing data %d bytes error!\n",
2046 fprintf(stderr,
"Error: ferror rc = %d\n", ferror(p_file));
2049 *total_bytes_received += rx_size - meta_size;
2061 else if (rx_size != 0)
2063 fprintf(stderr,
"Error: received %d bytes, <= metadata size %d!\n",
2064 rx_size, meta_size);
2080 printf(
"[R] Got:%d Packets= %u fps=%d Total bytes %lld\n",
2082 *total_bytes_received);
2087 printf(
"Encoder Receiving done.\n");
2105 int dst_codec_format,
int xcoder_id,
2106 const char *xcoder_name,
2108 int src_bit_depth,
int width,
int height,
2112 int video_full_range_flag,
2113 int sar_num,
int sar_den)
2125 p_enc_ctx->
hw_id = xcoder_id;
2126 p_enc_ctx->
hw_name = xcoder_name;
2140 int linesize_aligned = ((width + 7) / 8) * 8;
2143 linesize_aligned = ((width + 15) / 16) * 16;
2150 else if (linesize_aligned > width)
2156 int height_aligned = ((height + 7) / 8) * 8;
2159 height_aligned = ((height + 15) / 16) * 16;
2166 else if (height_aligned > height)
2173 ni_logan_set_vui(p_enc_params, p_enc_ctx, color_primaries, color_trc, color_space,
2174 video_full_range_flag, sar_num, sar_den, dst_codec_format);
2179 fprintf(stderr,
"Error: %s failure!\n", __FUNCTION__);
2183 if (xcoder_name != NULL)
2185 printf(
"Encoder device %s session open successful.\n", xcoder_name);
2189 printf(
"Encoder device %d session open successful.\n", xcoder_id);
2198 printf(
"Video decoder/encoder/transcoder application directly using Netint Libxcoder API v%s\n"
2199 "Usage: xcoder [options]\n"
2202 "-h | --help Show help.\n"
2203 "-l | --loglevel Set loglevel of libxcoder API.\n"
2204 " [none, fatal, error, info, debug, trace]\n"
2205 " (Default: info)\n"
2206 "-c | --card Set card index to use.\n"
2207 " See `ni_logan_rsrc_mon` for cards on system.\n"
2209 "-n | --devname Specify the xcoder device name to work.\n"
2210 "-i | --input Input file path.\n"
2211 "-s | --size Resolution of input file in format WIDTHxHEIGHT.\n"
2212 " (eg. '1920x1080')\n"
2213 "-m | --mode Input to output codec processing mode in format:\n"
2214 " INTYPE2OUTTYPE. [a2y, h2y, y2a, y2h, a2a, a2h, h2a, h2h]\n"
2215 " Type notation: y=YUV420P a=AVC, h=HEVC\n"
2216 "-b | --bitdepth Input and output bit depth. [8, 10]\n"
2218 "-x | --xcoder-params Encoding params. See \"Encoding Parameters\" chapter in\n"
2219 " IntegrationProgrammingGuideT408_T432_FW*.pdf for help.\n"
2220 " (Default: \"\")\n"
2221 "-o | --output Output file path.\n"
2222 "-p | --loop Number of times to repeat input file. (Default: 1)\n"
2223 "-a | --dec_async Decoding in asynchronous multi-threading.\n"
2224 "-e | --enc_async Encoding in asynchronous multi-threading.\n"
2225 "-t | --dec_flush_sec Flush decoder at the specified second\n"
2226 "-f | --dec_flush Flush decoder at the specific packet index. Prefix\n"
2227 " number with 'r' to repeatedly flush at packet period.\n"
2234 static int get_key_value(
char *p_str,
char *key,
char *value)
2236 if (! p_str || ! key || ! value)
2241 char *p = strchr(p_str,
'=');
2251 strncat(key, p_str, strlen(p_str));
2252 strncat(value, p+1, strlen(p+1));
2258 static int32_t log_str_to_level(
char *log_str)
2262 for (i = 0; i < strlen(log_str); i++)
2263 log_str[i] = tolower((
unsigned char) log_str[i]);
2265 if (strcmp(log_str,
"none") == 0)
2267 else if (strcmp(log_str,
"fatal") == 0)
2269 else if (strcmp(log_str,
"error") == 0)
2271 else if (strcmp(log_str,
"info") == 0)
2273 else if (strcmp(log_str,
"debug") == 0)
2275 else if (strcmp(log_str,
"trace") == 0)
2278 converted_log_level = -16;
2279 return converted_log_level;
2284 static int retrieve_xcoder_params(
char xcoderParams[],
2288 char key[64], value[64];
2289 char *p = xcoderParams;
2290 char *curr = xcoderParams, *colon_pos;
2295 colon_pos = strchr(curr,
':');
2302 if (strlen(curr) >
sizeof(key) +
sizeof(value) - 1 ||
2303 get_key_value(curr, key, value))
2305 fprintf(stderr,
"Error: xcoder-params p_config key/value not "
2306 "retrieved: %s\n", curr);
2314 fprintf(stderr,
"Error: unknown option: %s.\n", key);
2317 fprintf(stderr,
"Error: invalid value for %s: %s.\n", key, value);
2325 fprintf(stderr,
"Error: config parsing failed %d: %s\n", ret,
2326 ni_logan_get_rc_txt(ret));
2332 curr = colon_pos + 1;
2336 curr += strlen(curr);
2343 static void *decoder_send_routine(
void *arg)
2368 static void *decoder_receive_routine(
void *arg)
2385 else if (ret < 0 || p_frm->end_of_stream)
2404 static void *decoder_flush_routine(
void *arg)
2427 static void *encoder_send_routine(
void *arg)
2452 static void *encoder_receive_routine(
void *arg)
2492 int err = 0, pfs = 0, sos_flag = 0, edFlag = 0, bytes_sent = 0;
2494 char xcoder_name[32] = {
'\0'};
2495 unsigned long total_bytes_sent;
2496 unsigned long long total_bytes_received;
2497 unsigned long long xcodeRecvTotal;
2498 FILE *p_file = NULL;
2500 char mode_description[128];
2501 int input_video_width;
2502 int input_video_height;
2512 char encConfXcoderParams[2048] = { 0 };
2513 ni_device_handle_t dev_handle = NI_INVALID_DEVICE_HANDLE, dev_handle_1 = NI_INVALID_DEVICE_HANDLE;
2514 int src_codec_format = 0, dst_codec_format = 0;
2522 const char *opt_string =
"aehl:c:n:f:i:s:m:b:o:p:t:x:";
2523 static struct option long_options[] =
2543 while ((opt =
getopt_long(argc, argv, opt_string, long_options, &opt_index)) != -1)
2557 loglevel = log_str_to_level(
optarg);
2563 xcoder_id = strtol(
optarg, &n, 10);
2568 strcpy(xcoder_name,
optarg);
2574 arg_width = (int) strtol(
optarg, &n, 10);
2575 arg_height =
atoi(n + 1);
2576 if ((*n !=
'x') || (!arg_width || !arg_height))
2580 if (!(strlen(
optarg) == 3))
2583 for (i = 0; i < strlen(
optarg); i++)
2586 if (strcmp(
optarg,
"y2a") &&
2599 sprintf(mode_description,
"Encoding");
2602 else if (
optarg[2] ==
'y')
2604 sprintf(mode_description,
"Decoding");
2613 sprintf(mode_description,
"Transcoding");
2621 strcat(mode_description,
" from AVC");
2626 strcat(mode_description,
" from HEVC");
2631 strcat(mode_description,
" to AVC");
2636 strcat(mode_description,
" to HEVC");
2649 strcpy(encConfXcoderParams,
optarg);
2656 if (dec_flush_sec < 0)
2670 if (dec_flush_pkt < 0)
2682 printf(
"Error: missing argument for -i | --input\n");
2687 printf(
"Error: missing argument for -m | --mode\n");
2692 printf(
"Error: missing argument for -o | --output\n");
2700 printf(
"%s...\n", mode_description);
2706 pfs = open(sdPara.
fileName, O_RDONLY | O_BINARY);
2707 #elif defined(__linux__)
2708 pfs = open(sdPara.
fileName, O_RDONLY);
2713 fprintf(stderr,
"Error: cannot open %s\n", sdPara.
fileName);
2714 fprintf(stderr,
"Error: input file read failure\n");
2718 printf(
"SUCCESS: Opened input file: %s with file id = %d\n", sdPara.
fileName, pfs);
2720 lseek(pfs, 0, SEEK_END);
2722 lseek(pfs, 0, SEEK_SET);
2727 fprintf(stderr,
"Error: input file size %lu exceeding max malloc, quit\n",
2736 uint32_t chunk_size = tmpFileSize > 4096 ? 4096 : tmpFileSize;
2738 if (one_read_size == -1)
2740 fprintf(stderr,
"Error: reading file, quit! left-to-read %lu\n", tmpFileSize);
2745 tmpFileSize -= one_read_size;
2749 printf(
"read %lu bytes from input file into memory\n",
total_file_size);
2754 if (strcmp(rcPara.
fileName,
"null"))
2756 p_file = fopen(rcPara.
fileName,
"wb");
2759 fprintf(stderr,
"Error: cannot open %s\n", rcPara.
fileName);
2764 printf(
"SUCCESS: Opened output file: %s\n", rcPara.
fileName);
2772 fprintf(stderr,
"ERROR: H.264 file probing complete, source file format "
2773 "not supported !\n");
2780 arg_width = SPS.
width;
2791 arg_width, arg_height) < 0)
2793 fprintf(stderr,
"Error: decoder p_config set up error\n");
2832 dec_ctx.
hw_id = xcoder_id;
2833 dec_ctx.
hw_name = &xcoder_name[0];
2848 fprintf(stderr,
"Error: ni_logan_decoder_session_open() failure!\n");
2853 if (xcoder_name[0] !=
'\0')
2855 printf(
"Encoder device %s session open successful.\n", xcoder_name);
2859 printf(
"Encoder device %d session open successful.\n", xcoder_id);
2876 total_bytes_received = 0;
2878 total_bytes_sent = 0;
2880 printf(
"user video resolution: %dx%d\n", arg_width, arg_height);
2881 if (arg_width == 0 || arg_height == 0)
2883 input_video_width = 1280;
2884 input_video_height = 720;
2888 input_video_width = arg_width;
2889 input_video_height = arg_height;
2891 int output_video_width = input_video_width;
2892 int output_video_height = input_video_height;
2904 struct timespec start, end;
2905 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
2915 printf(
"Decoding Mode: %dx%d to %dx%d\n",
2916 input_video_width, input_video_height,
2917 output_video_width, output_video_height);
2928 ni_pthread_t send_tid, recv_tid, flush_tid;
2932 send_param.
p_ctx = &dec_ctx;
2933 send_param.
p_data = &in_pkt;
2940 send_param.
p_SPS = &SPS;
2942 recv_param.
p_ctx = &dec_ctx;
2943 recv_param.
p_data = &out_frame;
2947 recv_param.
p_file = p_file;
2951 if (ni_logan_pthread_create(&send_tid, NULL, decoder_send_routine, &send_param))
2953 fprintf(stderr,
"create send pkt thread failed in decoder mode\n");
2957 if (ni_logan_pthread_create(&recv_tid, NULL, decoder_receive_routine, &recv_param))
2959 fprintf(stderr,
"create recv frame thread failed in decoder mode\n");
2963 if (dec_flush_sec > 0 &&
2964 ni_logan_pthread_create(&flush_tid, NULL, decoder_flush_routine, &send_param))
2966 fprintf(stderr,
"create flush frame thread failed in decoder mode\n");
2970 ni_logan_pthread_join(send_tid, NULL);
2971 ni_logan_pthread_join(recv_tid, NULL);
2972 if (dec_flush_sec > 0)
2975 ni_logan_pthread_join(flush_tid, NULL);
2988 &dec_ctx, &in_pkt, input_video_width, input_video_height,
2989 pkt_size, &total_bytes_sent, print_time, &xcodeState, &SPS);
2993 fprintf(stderr,
"Error: decoder_send_data() failed, rc: %d\n",
3000 &dec_ctx, &out_frame, output_video_width, output_video_height,
3001 p_file, &total_bytes_received, print_time, &xcodeState);
3021 printf(
"[R] Got: Frames= %u fps=%d Total bytes %llu\n",
3034 printf(
"Encoding Mode: %dx%d to %dx%d\n",
3035 input_video_width, input_video_height,
3036 output_video_width, output_video_height);
3042 fprintf(stderr,
"Error: encoder init default set up error\n");
3047 if (retrieve_xcoder_params(encConfXcoderParams, &enc_api_param, &enc_ctx))
3049 fprintf(stderr,
"Error: encoder p_config parsing error\n");
3055 int video_full_range_flag = 0;
3066 &enc_api_param, bit_depth, arg_width, arg_height,
3070 video_full_range_flag,
3080 ni_pthread_t send_tid, recv_tid;
3082 send_param.
p_ctx = &enc_ctx;
3083 send_param.
p_data = &in_frame;
3090 recv_param.
p_ctx = &enc_ctx;
3091 recv_param.
p_data = &out_packet;
3095 recv_param.
p_file = p_file;
3099 if (ni_logan_pthread_create(&send_tid, NULL, encoder_send_routine, &send_param))
3101 fprintf(stderr,
"create send frame thread failed in encoder mode\n");
3105 if (ni_logan_pthread_create(&recv_tid, NULL, encoder_receive_routine, &recv_param))
3107 fprintf(stderr,
"create recv pkt thread failed in encoder mode\n");
3111 ni_logan_pthread_join(send_tid, NULL);
3112 ni_logan_pthread_join(recv_tid, NULL);
3123 &enc_ctx, &in_frame, input_video_width, input_video_height,
3124 &total_bytes_sent, &xcodeState);
3133 &enc_ctx, &out_packet, output_video_width, output_video_height,
3134 p_file, &total_bytes_received, print_time);
3155 printf(
"[R] Got: Packets= %u fps=%d Total bytes %lld\n",
3168 printf(
"Xcoding Mode: %dx%d to %dx%d\n", input_video_width,
3169 input_video_height, output_video_width, output_video_height);
3183 &dec_ctx, &in_pkt, input_video_width, input_video_height, pkt_size,
3184 &total_bytes_sent, print_time, &xcodeState, &SPS);
3194 &dec_ctx, &out_frame, output_video_width, output_video_height,
3195 p_file, &total_bytes_received, print_time, &xcodeState);
3220 int fps_num = 0, fps_den = 0;
3249 arg_width, arg_height) < 0)
3251 fprintf(stderr,
"Error: encoder init default set up error\n");
3259 if (retrieve_xcoder_params(encConfXcoderParams, &enc_api_param, &enc_ctx))
3261 fprintf(stderr,
"Error: encoder p_config parsing error\n");
3284 "overwrite source %d\n", enc_api_param.
color_space, color_space);
3296 sar_num = ni_h264_pixel_aspect_list[
3298 sar_den = ni_h264_pixel_aspect_list[
3303 xcoder_name, &enc_api_param, bit_depth, arg_width,
3304 arg_height, color_pri, color_trc, color_space,
3305 video_full_range_flag, sar_num, sar_den))
3314 &enc_ctx, &dec_ctx, &out_frame, &enc_in_frame,
3315 input_video_width, input_video_height,
3316 &total_bytes_sent, &xcodeState);
3329 &enc_ctx, &out_packet, output_video_width, output_video_height,
3330 p_file, &xcodeRecvTotal, print_time);
3348 printf(
"[R] Got: Frames= %u fps=%d Total bytes %llu\n",
3350 printf(
"[R] Got: Packets= %u fps=%d Total bytes %llu\n",
3379 g_file_cache = NULL;
3381 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...
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_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