 |
libxcoder
5.2.0
|
Go to the documentation of this file.
28 #if __linux__ || __APPLE__
29 #include <sys/types.h>
93 if (!strcmp(name, g_ni_pix_fmt_name_list[i].name))
95 return g_ni_pix_fmt_name_list[i].
pix_fmt;
108 if (pix_fmt == g_ni_pix_fmt_name_list[i].pix_fmt)
110 return g_ni_pix_fmt_name_list[i].
name;
123 if (g_ni_gc620_pix_fmt_list[i].pix_fmt_ni == pix_fmt)
138 if (g_ni_gc620_pix_fmt_list[i].pix_fmt_gc620 == pix_fmt)
253 fseek(fp, 0, SEEK_END);
255 fseek(fp, 0, SEEK_SET);
263 size_t read_chunk = 4096;
265 uint64_t file_size_left;
267 fp = fopen(filename,
"rb");
281 "Error: Failed to allocate memory of size %llu for file cache\n",
290 while (file_size_left)
292 if (read_chunk > file_size_left)
294 read_chunk = file_size_left;
305 file_size_left -= read_chunk;
342 data_len = w * h * 3;
345 data_len = w * h * 6;
352 data_len = w * h * 3 / 2;
356 data_len = w * h * 3;
364 data_len = w * 4 * h;
376 uint8_t *p_dst, uint32_t to_read)
389 fseek(fp, 0, SEEK_SET);
401 int read_rc = fread(p_dst, to_read, 1, fp);
417 int chunk_size, frame_size;
436 }
else if (chunk_size == 0)
449 void *yuv_buf,
int width,
int height,
479 for (i = 0; i < 2; i++)
485 if (frame->
p_data[0] == NULL)
493 p_src[1] = p_src[0] + width * factor * height;
494 p_src[2] = p_src[1] + width * factor * height;
498 p_src, width, height, factor, mode);
511 int output_width,
int output_height,
int format,
ni_frame_t *p_out_frame)
515 int plane_width, plane_height, write_width, write_height, bit_depth_factor;
517 if (p_file && p_out_frame)
526 for (i = 0; i < 3; i++)
528 src = p_out_frame->
p_data[i];
530 plane_width = input_aligned_width;
531 plane_height = input_aligned_height;
532 write_width = output_width;
533 write_height = output_height;
536 bit_depth_factor = 1;
538 bit_depth_factor = 2;
540 write_width *= bit_depth_factor;
542 if (i == 1 || i == 2)
547 plane_width = ((output_width / 2 * bit_depth_factor + 127) / 128) * 128;
551 plane_width = (((output_width * bit_depth_factor + 127) / 128) * 128);
570 for (j = 0; j < plane_height; j++)
572 if (j < write_height &&
573 fwrite(src, write_width, 1, p_file) != 1)
576 "Error: writing data plane %d: height %d error!\n",
592 src = p_out_frame->
p_data[0];
593 if (fwrite(src, output_width * output_height * 4, 1, p_file) != 1)
602 for (i = 0; i < 3; i++)
604 src = p_out_frame->
p_data[i];
605 if (fwrite(src, output_width * output_height, 1, p_file) != 1)
623 "Error: writing data frame flush failed! errno %d\n",
642 if (g_hwframe_pool[i].ref_cnt &&
643 g_hwframe_pool[i].surface.ui16FrameIdx)
646 g_hwframe_pool[i].surface.ui16FrameIdx,
660 uint16_t hwframe_index;
668 g_hwframe_pool[hwframe_index].
ref_cnt++;
669 if (1 == g_hwframe_pool[hwframe_index].ref_cnt)
671 memcpy(&g_hwframe_pool[hwframe_index].surface, p_surface,
675 hwframe_index, g_hwframe_pool[hwframe_index].ref_cnt);
681 if (g_hwframe_pool[hwframe_index].ref_cnt > 0)
683 g_hwframe_pool[hwframe_index].
ref_cnt--;
684 if (0 == g_hwframe_pool[hwframe_index].ref_cnt &&
685 g_hwframe_pool[hwframe_index].surface.ui16FrameIdx)
688 g_hwframe_pool[hwframe_index].surface.ui16FrameIdx);
693 hwframe_index, g_hwframe_pool[hwframe_index].ref_cnt);
697 __func__, hwframe_index,
698 g_hwframe_pool[hwframe_index].ref_cnt);
745 int input_video_width,
int input_video_height,
748 int retval, is_semiplanar;
767 input_video_width, input_video_height,
773 !is_semiplanar, p_swin_frame, input_video_width,
774 dst_height_aligned[0], dst_stride, 0,
776 if (!p_swin_frame->
p_data[0])
786 if (!p_in_frame->
p_data[3])
795 "dst height aligned = %d/%d/%d\n",
796 dst_stride[0], dst_stride[1], dst_stride[2],
797 input_video_height, dst_height_aligned[0],
798 dst_height_aligned[1], dst_height_aligned[2]);
808 src_height[0] = input_video_height;
809 src_height[1] = input_video_height / 2;
810 src_height[2] = (is_semiplanar) ? 0 : (input_video_height / 2);
811 uint32_t conf_win_right = 0;
821 src_height[0] = input_video_height;
831 src_stride[1] = is_semiplanar ? src_stride[0] : src_stride[0] / 2;
832 src_stride[2] = is_semiplanar ? 0 : src_stride[0] / 2;
835 p_src[1] = p_src[0] + src_stride[0] * src_height[0];
836 p_src[2] = p_src[1] + src_stride[1] * src_height[1];
839 conf_win_right += (
NI_MIN_WIDTH - input_video_width) / 2 * 2;
842 conf_win_right += (
NI_VPU_CEIL(input_video_width, 2) - input_video_width) / 2 * 2;
852 (uint8_t **)(p_swin_frame->
p_data),
853 p_src, input_video_width,
856 dst_height_aligned, src_stride, src_height);
896 int is_p2p,
int pool_size)
905 p_upl_ctx->
hw_id = iXcoderGUID;
911 ni_log(
NI_LOG_ERROR,
"Error: %s failure. Failed to set uploader format!\n", __func__);
922 ni_log(
NI_LOG_INFO,
"Uploader device %d session open successful.\n", iXcoderGUID);
944 int height, FILE *pfs,
void *yuv_buf,
int *eos)
960 height, *eos ? NULL : yuv_buf);
986 p_upl_ctx->
hw_id, width, height,
#define GC620_RGB888_PLANAR
int uploader_open_session(ni_session_context_t *p_upl_ctx, int iXcoderGUID, int width, int height, ni_pix_fmt_t pix_fmt, int is_p2p, int pool_size)
Uploader session open.
int write_rawvideo_data(FILE *p_file, int input_aligned_width, int input_aligned_height, int output_width, int output_height, int format, ni_frame_t *p_out_frame)
Write hwdl data to files.
bool frame_list_is_full(ni_test_frame_list_t *list)
ni_pix_fmt_t gc620_to_ni_pix_fmt(int pix_fmt)
void reset_data_buf_pos(ni_demo_context_t *p_ctx)
uint64_t get_total_file_size(FILE *fp)
ni_retcode_t ni_frame_buffer_free(ni_frame_t *p_frame)
Free frame buffer that was previously allocated with either ni_frame_buffer_alloc or ni_encoder_frame...
void ni_hw_frame_ref(const niFrameSurface1_t *p_surface)
void ni_hw_frame_unref(uint16_t hwframe_index)
int frame_list_length(ni_test_frame_list_t *list)
unsigned long total_file_size
ni_retcode_t ni_encoder_sw_frame_buffer_alloc(bool planar, ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
This API is a wrapper for ni_encoder_frame_buffer_alloc(), used for planar pixel formats,...
#define NI_INVALID_SESSION_ID
#define NI_MAX_FILTER_POOL_SIZE
#define NI_XCODER_REVISION
int is_ni_enc_pix_fmt(ni_pix_fmt_t pix_fmt)
ni_device_handle_t blk_io_handle
uint64_t curr_file_offset
int scan_and_clean_hwdescriptors(void)
@ NI_RETCODE_ERROR_MEM_ALOC
@ SESSION_RUN_STATE_SEQ_CHANGE_DRAINING
bool frame_list_is_empty(ni_test_frame_list_t *list)
int frame_list_enqueue(ni_test_frame_list_t *list)
#define NI_APP_ENC_FRAME_META_DATA_SIZE
int ni_to_gc620_pix_fmt(ni_pix_fmt_t pix_fmt)
const char * ni_pixel_format_name(ni_pix_fmt_t pix_fmt)
int read_and_cache_file(ni_demo_context_t *ctx, char *filename)
uint32_t data_len[NI_MAX_NUM_DATA_POINTERS]
unsigned int extra_data_len
uint64_t num_frames_received
int ni_device_session_hwup(ni_session_context_t *p_ctx, ni_session_data_io_t *p_src_data, niFrameSurface1_t *hwdesc)
Sends raw YUV input to uploader instance and retrieves a HW descriptor to represent it.
ni_device_handle_t device_handle
bool uploader_frame_list_full(ni_test_frame_list_t *list, ni_pix_fmt_t pix_fmt)
ni_pixel_planar_format get_pixel_planar(ni_pix_fmt_t pix_fmt)
#define NI_SW_RELEASE_TIME
void hwframe_list_release(ni_test_frame_list_t *list)
void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
ni_retcode_t ni_uploader_set_frame_format(ni_session_context_t *p_upl_ctx, int width, int height, ni_pix_fmt_t pixel_format, int isP2P)
Set the outgoing frame format for the uploader.
@ NI_PIXEL_PLANAR_FORMAT_SEMIPLANAR
ni_pix_fmt_t ni_pixel_format_search(const char *name)
niFrameSurface1_t * hwupload_frame(ni_demo_context_t *p_ctx, ni_session_context_t *p_upl_ctx, ni_session_context_t *p_sca_ctx, ni_session_data_io_t *p_sw_data, ni_session_data_io_t *p_hw_data, ni_session_data_io_t *p_scale_data, ni_pix_fmt_t pix_fmt, int width, int height, FILE *pfs, void *yuv_buf, int *eos)
ni_session_data_io_t frames[NI_MAX_BUFFERED_FRAME]
int convert_yuv_444p_to_420p(ni_session_data_io_t *p_frame, void *yuv_buf, int width, int height, ni_sw_pix_fmt_t sw_pix_fmt, int mode, ni_codec_format_t codec_format)
uint8_t * p_data[NI_MAX_NUM_DATA_POINTERS]
#define NI_VPU_CEIL(_data, _align)
ni_retcode_t ni_hwframe_buffer_recycle2(niFrameSurface1_t *surface)
Recycle a frame buffer on card, only hwframe descriptor is needed.
@ NI_SW_PIX_FMT_YUV444P10LE
ni_retcode_t ni_frame_buffer_alloc_hwenc(ni_frame_t *p_frame, int video_width, int video_height, int extra_len)
Allocate memory for the hwDescriptor buffer based on provided parameters taking into account pic size...
#define NI_MAX_NUM_DATA_POINTERS
#define NI_MAX_BUFFERED_FRAME
union _ni_session_data_io::@19 data
ni_retcode_t ni_device_session_open(ni_session_context_t *p_ctx, ni_device_type_t device_type)
Open a new device session depending on the device_type parameter If device_type is NI_DEVICE_TYPE_DEC...
int hwdl_frame(ni_session_context_t *p_ctx, ni_session_data_io_t *p_session_data, ni_frame_t *p_src_frame, int output_format)
Download hw frames by HwDesc.
enum _ni_pixel_planar_format ni_pixel_planar_format
enum _ni_session_run_state ni_session_run_state_t
Session running state type.
int frame_list_drain(ni_test_frame_list_t *list)
void ni_get_min_frame_dim(int width, int height, ni_pix_fmt_t pix_fmt, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of frame to be sent to encoder for encoding. Caller usually retrieves this ...
uint64_t dec_total_bytes_sent
uint32_t read_next_chunk_from_file(ni_demo_context_t *p_ctx, FILE *fp, uint8_t *p_dst, uint32_t to_read)
void ni_copy_frame_data(uint8_t *p_dst[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int factor, ni_pix_fmt_t pix_fmt, int conf_win_right, int dst_stride[NI_MAX_NUM_DATA_POINTERS], int dst_height[NI_MAX_NUM_DATA_POINTERS], int src_stride[NI_MAX_NUM_DATA_POINTERS], int src_height[NI_MAX_NUM_DATA_POINTERS])
Copy RGBA or YUV data to Netint HW frame layout to be sent to encoder for encoding....
int read_yuv_from_file(ni_demo_context_t *p_ctx, FILE *pfs, void *yuv_buf, int width, int height, ni_pix_fmt_t pix_fmt, ni_sw_pix_fmt_t sw_pix_fmt, int *eos, ni_session_run_state_t run_state)
int scale_filter(ni_session_context_t *p_ctx, ni_frame_t *p_frame_in, ni_session_data_io_t *p_data_out, int iXcoderGUID, int scale_width, int scale_height, int in_format, int out_format)
Do a scale and/or format-change operation.
#define NI_MAX_DR_HWDESC_FRAME_INDEX
ni_retcode_t ni_encoder_frame_buffer_alloc(ni_frame_t *p_frame, int video_width, int video_height, int linesize[], int alignment, int extra_len, bool alignment_2pass_wa)
Allocate memory for the frame buffer for encoding based on given parameters, taking into account pic ...
void ni_get_hw_yuv420p_dim(int width, int height, int factor, int is_semiplanar, int plane_stride[NI_MAX_NUM_DATA_POINTERS], int plane_height[NI_MAX_NUM_DATA_POINTERS])
Get dimension information of Netint HW YUV420p frame to be sent to encoder for encoding....
#define LIBXCODER_API_VERSION
ni_session_run_state_t session_run_state
enum _ni_codec_format ni_codec_format_t
This is an enumeration for supported codec formats.
int ni_device_session_hwdl(ni_session_context_t *p_ctx, ni_session_data_io_t *p_data, niFrameSurface1_t *hwdesc)
Reads YUV data from hw descriptor stored location on device.
void rewind_data_buf_pos_by(ni_demo_context_t *p_ctx, uint64_t nb_bytes)
ni_retcode_t ni_frame_buffer_alloc_dl(ni_frame_t *p_frame, int video_width, int video_height, int pixel_format)
Allocate preliminary memory for the frame buffer based on provided parameters.
@ NI_RETCODE_NVME_SC_WRITE_BUFFER_FULL
int upload_send_data_get_desc(ni_demo_context_t *p_ctx, ni_session_context_t *p_upl_ctx, ni_session_data_io_t *p_swin_data, ni_session_data_io_t *p_in_data, int input_video_width, int input_video_height, void *yuv_buf)
Read from input file, upload to encoder, retrieve HW descriptor.
int ni_device_session_init_framepool(ni_session_context_t *p_ctx, uint32_t pool_size, uint32_t pool)
Sends frame pool setup info to device.
int frame_read_buffer_size(int w, int h, ni_pix_fmt_t pix_fmt, ni_sw_pix_fmt_t sw_pix_fmt)
@ NI_PIXEL_PLANAR_FORMAT_TILED4X4
void ni_copy_yuv_444p_to_420p(uint8_t *p_dst0[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_dst1[NI_MAX_NUM_DATA_POINTERS], uint8_t *p_src[NI_MAX_NUM_DATA_POINTERS], int frame_width, int frame_height, int factor, int mode)
Copy yuv444p data to yuv420p frame layout to be sent to encoder for encoding. Data buffer (dst) is us...
@ NI_PIXEL_PLANAR_FORMAT_PLANAR