![]() |
libxcoder
5.2.0
|
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 <sys/mman.h>
#include "ni_device_api.h"
#include "ni_util.h"
#include <sys/ioctl.h>
#include "ni_p2p_ioctl.h"
Go to the source code of this file.
Data Structures | |
struct | swapchain_t |
Macros | |
#define | _POSIX_C_SOURCE 200809L |
#define | MAX_YUV_FRAME_SIZE (7680 * 4320 * 3 / 2) |
#define | MAX_ABGR_FRAME_SIZE (7680 * 4320 * 4) |
#define | MAX_FRAME_SIZE MAX_ABGR_FRAME_SIZE |
#define | FILE_NAME_LEN 256 |
#define | MAX_SWAP_SIZE 3 |
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 | get_file_size (const char *filename, unsigned long *bytes_read) |
Get file size. More... | |
int | recycle_frame (ni_frame_t *p2p_frame) |
Recycle hw frame back to Quadra. More... | |
int | gpu_render_frame (ni_session_context_t *p_ctx, int fd, uint8_t **pp_data, ni_frame_t *p_in_frame, int input_video_width, int input_video_height, unsigned long *bytes_sent, int *input_exhausted) |
Reads video data from input file then calls a special libxcoder API function to transfer the video data into the hardware frame on the proxy GPU Quadra device. More... | |
int | gpu_prepare_frame (ni_session_context_t *p_gpu_ctx, int input_video_width, int input_video_height, ni_frame_t *gpu_frame) |
Prepare frame on the proxy GPU Quadra device. More... | |
int | enc_prepare_frame (ni_session_context_t *p_upl_ctx, int input_video_width, int input_video_height, ni_frame_t *p2p_frame) |
Prepare frame on the encoding Quadra device. More... | |
int | encoder_encode_frame (ni_session_context_t *p_enc_ctx, ni_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_session_context_t *p_enc_ctx, ni_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_session_context_t *p_enc_ctx, int dst_codec_format, int iXcoderGUID, ni_xcoder_params_t *p_enc_params, int width, int height, ni_frame_t *p_frame) |
Open an encoder session to Quadra. More... | |
int | uploader_open_session (ni_session_context_t *p_upl_ctx, int *iXcoderGUID, int width, int height, int poolsize, int p2p) |
Open an upload session to Quadra. 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 *iGpuGUID, 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_raw_frame = NULL |
uint8_t | g_rgb2yuv_csc = 0 |
int | g_swapchain_size = 1 |
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.
This test program requires TWO Quadra devices. One Quadra device acts as a proxy for the GPU card. The other Quadra device reads frames from the proxy GPU Quadra device via peer-to-peer then encodes the frame.
Definition in file ni_p2p_read_test.c.
#define _POSIX_C_SOURCE 200809L |
Definition at line 40 of file ni_p2p_read_test.c.
#define FILE_NAME_LEN 256 |
Definition at line 66 of file ni_p2p_read_test.c.
#define MAX_ABGR_FRAME_SIZE (7680 * 4320 * 4) |
Definition at line 58 of file ni_p2p_read_test.c.
#define MAX_FRAME_SIZE MAX_ABGR_FRAME_SIZE |
Definition at line 61 of file ni_p2p_read_test.c.
#define MAX_SWAP_SIZE 3 |
Definition at line 67 of file ni_p2p_read_test.c.
#define MAX_YUV_FRAME_SIZE (7680 * 4320 * 3 / 2) |
Definition at line 57 of file ni_p2p_read_test.c.
void arg_error_exit | ( | char * | arg_name, |
char * | param | ||
) |
Exit on argument error.
[in] | arg_name | pointer to argument name [in] param pointer to provided parameter |
Definition at line 107 of file ni_p2p_read_test.c.
int enc_prepare_frame | ( | ni_session_context_t * | p_upl_ctx, |
int | input_video_width, | ||
int | input_video_height, | ||
ni_frame_t * | p2p_frame | ||
) |
Prepare frame on the encoding Quadra device.
[in] | p_upl_ctx | pointer to caller allocated upload session context [in] input_video_width video width [in] input_video_height video height [out] p2p_frame p2p frame |
Definition at line 518 of file ni_p2p_read_test.c.
int encoder_encode_frame | ( | ni_session_context_t * | p_enc_ctx, |
ni_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.
[in] | p_enc_ctx | pointer 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 |
Definition at line 567 of file ni_p2p_read_test.c.
int encoder_open_session | ( | ni_session_context_t * | p_enc_ctx, |
int | dst_codec_format, | ||
int | iXcoderGUID, | ||
ni_xcoder_params_t * | p_enc_params, | ||
int | width, | ||
int | height, | ||
ni_frame_t * | p_frame | ||
) |
Open an encoder session to Quadra.
[out] | p_enc_ctx | pointer to an encoder session context [in] dst_codec_format AVC or HEVC [in] iXcoderGUID id to identify the Quadra device [in] p_enc_params sets the encoder parameters [in] width width of frames to encode [in] height height of frames to encode |
Definition at line 809 of file ni_p2p_read_test.c.
int encoder_receive_data | ( | ni_session_context_t * | p_enc_ctx, |
ni_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.
[in] | p_enc_ctx | pointer 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 |
Definition at line 650 of file ni_p2p_read_test.c.
int get_file_size | ( | const char * | filename, |
unsigned long * | bytes_read | ||
) |
Get file size.
[in] | filename | name of input file [out] bytes_read number of bytes in file |
Definition at line 171 of file ni_p2p_read_test.c.
int gpu_prepare_frame | ( | ni_session_context_t * | p_gpu_ctx, |
int | input_video_width, | ||
int | input_video_height, | ||
ni_frame_t * | gpu_frame | ||
) |
Prepare frame on the proxy GPU Quadra device.
[in] | p_gpu_ctx | pointer to caller allocated gpu session context [in] input_video_width video width [in] input_video_height video height [out] gpu_frame gpu frame |
Definition at line 467 of file ni_p2p_read_test.c.
int gpu_render_frame | ( | ni_session_context_t * | p_ctx, |
int | fd, | ||
uint8_t ** | pp_data, | ||
ni_frame_t * | p_in_frame, | ||
int | input_video_width, | ||
int | input_video_height, | ||
unsigned long * | bytes_sent, | ||
int * | input_exhausted | ||
) |
Reads video data from input file then calls a special libxcoder API function to transfer the video data into the hardware frame on the proxy GPU Quadra device.
[in] | p_ctx | pointer to upload session context [in] fd file descriptor of input file [in] pp_data address of pointer to frame 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 |
Definition at line 309 of file ni_p2p_read_test.c.
int main | ( | int | argc, |
char * | argv[] | ||
) |
Definition at line 1124 of file ni_p2p_read_test.c.
void parse_arguments | ( | int | argc, |
char * | argv[], | ||
char * | input_filename, | ||
char * | output_filename, | ||
int * | iXcoderGUID, | ||
int * | iGpuGUID, | ||
int * | arg_width, | ||
int * | arg_height, | ||
int * | dst_codec_format | ||
) |
Parse user command line arguments.
[in] | argc | argument count [in] argv argument vector [out] input_filename input filename [out] output_filename output filename [out] iXcoderGUID Quadra device [out] iGpuGUID Quadra device (GPU proxy device) [out] arg_width resolution width [out] arg_height resolution height [out] dst_codec_format codec (AVC vs HEVC) |
Definition at line 970 of file ni_p2p_read_test.c.
void print_usage | ( | void | ) |
Print usage information.
none |
Definition at line 920 of file ni_p2p_read_test.c.
int read_next_chunk_from_file | ( | int | fd, |
uint8_t * | p_dst, | ||
uint32_t | to_read | ||
) |
Read the next frame.
[in] | fd | file descriptor of input file |
[out] | p_dst | pointer to place the frame |
[in] | to_read | number of bytes to copy to the pointer |
Definition at line 123 of file ni_p2p_read_test.c.
int recycle_frame | ( | ni_frame_t * | p2p_frame | ) |
Recycle hw frame back to Quadra.
[in] | p2p_frame | - hw frame to recycle |
Definition at line 201 of file ni_p2p_read_test.c.
int uploader_open_session | ( | ni_session_context_t * | p_upl_ctx, |
int * | iXcoderGUID, | ||
int | width, | ||
int | height, | ||
int | poolsize, | ||
int | p2p | ||
) |
Open an upload session to Quadra.
[out] | p_upl_ctx | pointer to an upload context of the open session [in] iXcoderGUID pointer to Quadra card hw id [in] width width of the frames [in] height height of the frames [in] poolsize pool size to create on session [in] p2p p2p session |
Definition at line 865 of file ni_p2p_read_test.c.
struct timeval current_time |
Definition at line 80 of file ni_p2p_read_test.c.
time_t current_timestamp = 0 |
Definition at line 84 of file ni_p2p_read_test.c.
uint64_t data_left_size = 0 |
Definition at line 75 of file ni_p2p_read_test.c.
int enc_eos_sent = 0 |
Definition at line 71 of file ni_p2p_read_test.c.
uint8_t* g_curr_cache_pos = NULL |
Definition at line 88 of file ni_p2p_read_test.c.
uint8_t* g_raw_frame = NULL |
Definition at line 89 of file ni_p2p_read_test.c.
int g_repeat = 1 |
Definition at line 76 of file ni_p2p_read_test.c.
uint8_t g_rgb2yuv_csc = 0 |
Definition at line 91 of file ni_p2p_read_test.c.
int g_swapchain_size = 1 |
Definition at line 93 of file ni_p2p_read_test.c.
uint32_t number_of_frames = 0 |
Definition at line 73 of file ni_p2p_read_test.c.
uint32_t number_of_packets = 0 |
Definition at line 74 of file ni_p2p_read_test.c.
struct timeval previous_time |
Definition at line 79 of file ni_p2p_read_test.c.
time_t previous_timestamp = 0 |
Definition at line 83 of file ni_p2p_read_test.c.
int receive_fin_flag = 0 |
Definition at line 70 of file ni_p2p_read_test.c.
int send_fin_flag = 0 |
Definition at line 69 of file ni_p2p_read_test.c.
struct timeval start_time |
Definition at line 78 of file ni_p2p_read_test.c.
time_t start_timestamp = 0 |
Definition at line 82 of file ni_p2p_read_test.c.
unsigned long total_file_size = 0 |
Definition at line 86 of file ni_p2p_read_test.c.