libxcoder  3.4.0
ni_p2p_test.c File Reference

Application for performing video processing using libxcoder API and P2P DMA. Its code provides examples on how to programatically use libxcoder API in conjunction with P2P DMA. More...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <getopt.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <time.h>
#include "ni_device_api_logan.h"
#include "ni_util_logan.h"
#include "ni_av_codec_logan.h"

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200809L
 
#define MAX_YUV_FRAME_SIZE   (7680 * 4320 * 3 / 2)
 
#define POOL_SIZE   2
 
#define FILE_NAME_LEN   256
 

Functions

void arg_error_exit (char *arg_name, char *param)
 Exit on argument error. More...
 
int read_next_chunk_from_file (int fd, uint8_t *p_dst, uint32_t to_read)
 Read the next frame. More...
 
int load_input_file (const char *filename, unsigned long *bytes_read)
 Load the input file into memory. More...
 
int p2p_upload_send_data (ni_logan_session_context_t *p_upl_ctx, int fd, uint8_t **p_yuv420p_frame, ni_logan_frame_t *p_in_frame, int input_video_width, int input_video_height, unsigned long *bytes_sent, int *input_exhausted)
 Recycle hw frames back to T408. More...
 
int p2p_prepare_frames (ni_logan_session_context_t *p_upl_ctx, int input_video_width, int input_video_height, ni_logan_frame_t p2p_frame[])
 Prepare frames to simulate P2P transfers. More...
 
int encoder_encode_frame (ni_logan_session_context_t *p_enc_ctx, ni_logan_frame_t *p_in_frame, int input_exhausted, int *need_to_resend)
 Send the Quadra encoder a hardware frame which triggers Quadra to encode the frame. More...
 
int encoder_receive_data (ni_logan_session_context_t *p_enc_ctx, ni_logan_session_data_io_t *p_out_data, FILE *p_file, unsigned long long *total_bytes_received, int print_time)
 Receive output packet data from the Quadra encoder. More...
 
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, ni_logan_frame_t *p_frame)
 Encoder session open. More...
 
int uploader_open_session (ni_logan_session_context_t *p_upl_ctx, int *iXcoderGUID, int width, int height)
 Open an upload session to T408. More...
 
void print_usage (void)
 Print usage information. More...
 
void parse_arguments (int argc, char *argv[], char *input_filename, char *output_filename, int *iXcoderGUID, int *arg_width, int *arg_height, int *dst_codec_format)
 Parse user command line arguments. More...
 
int main (int argc, char *argv[])
 

Variables

int send_fin_flag = 0
 
int receive_fin_flag = 0
 
int enc_eos_sent = 0
 
uint32_t number_of_frames = 0
 
uint32_t number_of_packets = 0
 
uint64_t data_left_size = 0
 
int g_repeat = 1
 
struct timeval start_time
 
struct timeval previous_time
 
struct timeval current_time
 
time_t start_timestamp = 0
 
time_t previous_timestamp = 0
 
time_t current_timestamp = 0
 
unsigned long total_file_size = 0
 
uint8_t * g_curr_cache_pos = NULL
 
uint8_t * g_yuv_frame [POOL_SIZE] = {NULL, NULL}
 

Detailed Description

Application for performing video processing using libxcoder API and P2P DMA. Its code provides examples on how to programatically use libxcoder API in conjunction with P2P DMA.


Definition in file ni_p2p_test.c.

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

Definition at line 35 of file ni_p2p_test.c.

◆ FILE_NAME_LEN

#define FILE_NAME_LEN   256

Definition at line 51 of file ni_p2p_test.c.

◆ MAX_YUV_FRAME_SIZE

#define MAX_YUV_FRAME_SIZE   (7680 * 4320 * 3 / 2)

Definition at line 49 of file ni_p2p_test.c.

◆ POOL_SIZE

#define POOL_SIZE   2

Definition at line 50 of file ni_p2p_test.c.

Function Documentation

◆ arg_error_exit()

void arg_error_exit ( char *  arg_name,
char *  param 
)

Exit on argument error.


Parameters
[in]arg_namepointer to argument name [in] param pointer to provided parameter
Returns
None program exit

Definition at line 109 of file ni_p2p_test.c.

◆ encoder_encode_frame()

int encoder_encode_frame ( ni_logan_session_context_t p_enc_ctx,
ni_logan_frame_t p_in_frame,
int  input_exhausted,
int *  need_to_resend 
)

Send the Quadra encoder a hardware frame which triggers Quadra to encode the frame.


Parameters
[in]p_enc_ctxpointer to encoder context [in] p_in_frame pointer to hw frame [in] input_exhausted flag indicating this is the last frame [in/out] need_to_resend flag indicating need to re-send
Returns
0 on success -1 on failure

Definition at line 419 of file ni_p2p_test.c.

◆ encoder_open_session()

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,
ni_logan_frame_t p_frame 
)

Encoder session open.


Parameters

Definition at line 656 of file ni_p2p_test.c.

◆ encoder_receive_data()

int encoder_receive_data ( ni_logan_session_context_t p_enc_ctx,
ni_logan_session_data_io_t p_out_data,
FILE *  p_file,
unsigned long long *  total_bytes_received,
int  print_time 
)

Receive output packet data from the Quadra encoder.


Parameters
[in]p_enc_ctxpointer to encoder session context [in] p_out_data pointer to output data session [in] p_file pointer to file to write the packet [out] total_bytes_received running counter of bytes read [in] print_time 1 = print the time
Returns
0 - success got packet 1 - received eos 2 - got nothing, need retry -1 - failure

Definition at line 502 of file ni_p2p_test.c.

◆ load_input_file()

int load_input_file ( const char *  filename,
unsigned long *  bytes_read 
)

Load the input file into memory.


Parameters
[in]filenamename of input file [out] bytes_read number of bytes read from file
Returns
0 on success < 0 on error

Definition at line 173 of file ni_p2p_test.c.

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 977 of file ni_p2p_test.c.

◆ p2p_prepare_frames()

int p2p_prepare_frames ( ni_logan_session_context_t p_upl_ctx,
int  input_video_width,
int  input_video_height,
ni_logan_frame_t  p2p_frame[] 
)

Prepare frames to simulate P2P transfers.


Parameters
[in]p_upl_ctxpointer to caller allocated uploader session context [in] input_video_width video width [in] input_video_height video height [out] p2p_frame array of hw frames
Returns
0 on success -1 on error

Definition at line 352 of file ni_p2p_test.c.

◆ p2p_upload_send_data()

int p2p_upload_send_data ( ni_logan_session_context_t p_upl_ctx,
int  fd,
uint8_t **  p_yuv420p_frame,
ni_logan_frame_t p_in_frame,
int  input_video_width,
int  input_video_height,
unsigned long *  bytes_sent,
int *  input_exhausted 
)

Recycle hw frames back to T408.


Parameters
[in]p2p_frame- array of hw frames to recycle
Returns
Returns the number of hw frames that have been recycled

Reads YUV data from input file then calls a special libxcoder API function to transfer the YUV data into the hardware frame on the Quadra device.

Parameters
[in]p_upl_ctxpointer to upload session context [in] fd file descriptor of input file [in] p_yuv420p_frame address of pointer to YUV data [in] p_in_frame pointer to hardware frame [in] input_video_width video width [in] input_video_height video height [out] bytes_sent updated byte count of total data read [out] input_exhausted set to 1 when we reach end-of-file
Returns
0 on success -1 on error

Definition at line 242 of file ni_p2p_test.c.

◆ parse_arguments()

void parse_arguments ( int  argc,
char *  argv[],
char *  input_filename,
char *  output_filename,
int *  iXcoderGUID,
int *  arg_width,
int *  arg_height,
int *  dst_codec_format 
)

Parse user command line arguments.


Parameters
[in]argcargument count [in] argv argument vector [out] input_filename input filename [out] output_filename output filename [out] iXcoderGUID T408 device [out] arg_width resolution width [out] arg_height resolution height [out] dst_codec_format codec (AVC vs HEVC)
Returns
nothing program exit on error

Definition at line 862 of file ni_p2p_test.c.

◆ print_usage()

void print_usage ( void  )

Print usage information.


Parameters
none
Returns
none

Definition at line 817 of file ni_p2p_test.c.

◆ read_next_chunk_from_file()

int read_next_chunk_from_file ( int  fd,
uint8_t *  p_dst,
uint32_t  to_read 
)

Read the next frame.


Parameters
[in]fdfile descriptor of input file
[out]p_dstpointer to place the frame
[in]to_readnumber of bytes to copy to the pointer
Returns
bytes copied

Definition at line 125 of file ni_p2p_test.c.

◆ uploader_open_session()

int uploader_open_session ( ni_logan_session_context_t p_upl_ctx,
int *  iXcoderGUID,
int  width,
int  height 
)

Open an upload session to T408.


Parameters
[out]p_upl_ctxpointer to an upload context of the open session [in] iXcoderGUID pointer to T408 card hw id [in] width width of the frames [in] height height of the frames
Returns
0 if successful, < 0 otherwise

Definition at line 762 of file ni_p2p_test.c.

Variable Documentation

◆ current_time

struct timeval current_time

Definition at line 60 of file ni_p2p_test.c.

◆ current_timestamp

time_t current_timestamp = 0

Definition at line 68 of file ni_p2p_test.c.

◆ data_left_size

uint64_t data_left_size = 0

Definition at line 59 of file ni_p2p_test.c.

◆ enc_eos_sent

int enc_eos_sent = 0

Definition at line 55 of file ni_p2p_test.c.

◆ g_curr_cache_pos

uint8_t* g_curr_cache_pos = NULL

Definition at line 72 of file ni_p2p_test.c.

◆ g_repeat

int g_repeat = 1

Definition at line 60 of file ni_p2p_test.c.

◆ g_yuv_frame

uint8_t* g_yuv_frame[POOL_SIZE] = {NULL, NULL}

Definition at line 73 of file ni_p2p_test.c.

◆ number_of_frames

uint32_t number_of_frames = 0

Definition at line 57 of file ni_p2p_test.c.

◆ number_of_packets

uint32_t number_of_packets = 0

Definition at line 58 of file ni_p2p_test.c.

◆ previous_time

struct timeval previous_time

Definition at line 60 of file ni_p2p_test.c.

◆ previous_timestamp

time_t previous_timestamp = 0

Definition at line 67 of file ni_p2p_test.c.

◆ receive_fin_flag

int receive_fin_flag = 0

Definition at line 54 of file ni_p2p_test.c.

◆ send_fin_flag

int send_fin_flag = 0

Definition at line 53 of file ni_p2p_test.c.

◆ start_time

struct timeval start_time

Definition at line 60 of file ni_p2p_test.c.

◆ start_timestamp

time_t start_timestamp = 0

Definition at line 66 of file ni_p2p_test.c.

◆ total_file_size

unsigned long total_file_size = 0

Definition at line 70 of file ni_p2p_test.c.