00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef V4L2_BACKEND_TEST_H
00029 #define V4L2_BACKEND_TEST_H
00030
00031 #include "NvVideoDecoder.h"
00032 #include "NvVideoConverter.h"
00033 #include "NvEglRenderer.h"
00034 #include "NvJpegEncoder.h"
00035 #include <queue>
00036 #include <utility>
00037 #include <map>
00038 #include <fstream>
00039 #include <pthread.h>
00040 #include <semaphore.h>
00041 #include "nvosd.h"
00042
00043 using namespace std;
00044
00045 #define JPEG_ENC_BUF_SIZE 5*1024*1024
00046
00047 enum slice_type_e
00048 {
00049 SLICE_TYPE_P = 0,
00050 SLICE_TYPE_B = 1,
00051 SLICE_TYPE_I = 2,
00052 };
00053
00054 enum nal_type_e
00055 {
00056 NAL_UNIT_EXTERNAL = 0,
00057 NAL_UNIT_CODED_SLICE = 1,
00058 NAL_UNIT_CODED_SLICE_DATAPART_A = 2,
00059 NAL_UNIT_CODED_SLICE_DATAPART_B = 3,
00060 NAL_UNIT_CODED_SLICE_DATAPART_C = 4,
00061 NAL_UNIT_CODED_SLICE_IDR = 5,
00062 NAL_UNIT_SEI = 6,
00063 NAL_UNIT_SPS = 7,
00064 NAL_UNIT_PPS = 8,
00065 NAL_UNIT_ACCESS_UNIT_DELIMITER = 9,
00066 NAL_UNIT_END_OF_SEQUENCE = 10,
00067 NAL_UNIT_END_OF_STREAM = 11,
00068 NAL_UNIT_FILLER_DATA = 12,
00069 NAL_UNIT_SUBSET_SPS = 15,
00070 NAL_UNIT_CODED_SLICE_PREFIX = 14,
00071 NAL_UNIT_CODED_SLICE_SCALABLE = 20,
00072 NAL_UNIT_CODED_SLICE_IDR_SCALABLE = 21
00073 };
00074
00075 typedef struct
00076 {
00077 uint32_t window_height;
00078 uint32_t window_width;
00079 } display_resolution_t;
00080
00081 typedef struct
00082 {
00083 uint32_t window_height;
00084 uint32_t window_width;
00085 uint32_t window_x;
00086 uint32_t window_y;
00087 uint32_t crop_height;
00088 uint32_t crop_width;
00089 uint32_t crop_x;
00090 uint32_t crop_y;
00091 float alpha;
00092 }window_t;
00093
00094 class GIE_Context;
00095
00096 #define WINDOW_NUM 4
00097 #define CHANNEL_NUM 4
00098
00099 #define PARSER_DECODER_VIC_RENDER 0
00100 #define PARSER 1
00101 #define PARSER_DECODER 2
00102 #define PARSER_DECODER_VIC 3
00103
00104 typedef struct
00105 {
00106 uint64_t timestamp;
00107 struct timeval input_time;
00108 struct timeval output_time;
00109 slice_type_e slice_type;
00110 nal_type_e nal_type;
00111 uint32_t ref;
00112 } frame_info_t;
00113
00114 typedef struct
00115 {
00116 NvOSD_RectParams *g_rect;
00117 int g_rect_num;
00118 } frame_bbox;
00119
00120 typedef struct
00121 {
00122 struct v4l2_buffer v4l2_buf;
00123 NvBuffer *buffer;
00124 NvBuffer *shared_buffer;
00125 void *arg;
00126 int bProcess;
00127 } Shared_Buffer;
00128
00129
00130 typedef struct
00131 {
00132 uint32_t channel;
00133 uint32_t dec_status;
00134 NvVideoDecoder *dec;
00135 NvVideoConverter *conv;
00136 #ifdef ENABLE_GIE
00137 NvVideoConverter *conv1;
00138 #endif
00139 uint32_t decoder_pixfmt;
00140
00141 NvEglRenderer *renderer;
00142
00143 EGLImageKHR egl_image;
00144
00145 char *in_file_path;
00146 std::ifstream *in_file;
00147
00148 char *out_file_path;
00149 std::ofstream *out_file;
00150
00151 bool fullscreen;
00152 bool do_stat;
00153
00154
00155 uint32_t cpu_occupation_option;
00156 uint32_t window_height;
00157 uint32_t window_width;
00158 uint32_t window_x;
00159 uint32_t window_y;
00160
00161 float fps;
00162
00163 bool disable_dpb;
00164
00165 bool input_nalu;
00166
00167 std::queue < NvBuffer * > *conv_output_plane_buf_queue;
00168 #ifdef ENABLE_GIE
00169 std::queue < NvBuffer * > *conv1_output_plane_buf_queue;
00170 #endif
00171 map< uint64_t, frame_info_t* > *frame_info_map;
00172 window_t window[WINDOW_NUM];
00173
00174 pthread_mutex_t queue_lock;
00175 pthread_cond_t queue_cond;
00176 #ifdef ENABLE_GIE
00177 pthread_mutex_t queue1_lock;
00178 pthread_cond_t queue1_cond;
00179 #endif
00180 pthread_mutex_t fps_lock;
00181 pthread_cond_t fps_cond;
00182 #ifdef ENABLE_GIE
00183 sem_t result_ready_sem;
00184
00185 uint32_t *parray;
00186 uint32_t rect_count;
00187 pthread_mutex_t osd_lock;
00188 std::queue<frame_bbox*> *osd_queue;
00189 #endif
00190 pthread_t dec_capture_loop;
00191 pthread_t dec_feed_handle;
00192 pthread_t render_feed_handle;
00193 std::queue<Shared_Buffer> *render_buf_queue;
00194 int stop_render;
00195
00196 pthread_mutex_t render_lock;
00197 pthread_cond_t render_cond;
00198
00199
00200 sem_t dec_run_sem;
00201 bool got_error;
00202 bool got_eos;
00203 void *nvosd_context;
00204 } context_t;
00205
00206
00207 typedef struct
00208 {
00209 pthread_mutex_t queue_lock;
00210 NvJPEGEncoder *JpegEnc;
00211 unsigned char *pbuf;
00212 long unsigned int buf_size;
00213 char filename[512];
00214 } jpeg_enc_context_t;
00215
00216
00217 typedef struct
00218 {
00219 int dump_jpeg;
00220 int channel_num;
00221 char *in_file_path[CHANNEL_NUM];
00222 #ifdef ENABLE_GIE
00223 string deployfile;
00224 string modelfile;
00225 #endif
00226 } global_cfg;
00227
00228 int parse_csv_args(context_t * ctx,
00229 #ifdef ENABLE_GIE
00230 GIE_Context *gie_ctx,
00231 #endif
00232 int argc, char *argv[]);
00233 void parse_global(global_cfg* cfg, int argc, char ***argv);
00234 void print_help(void);
00235 #endif