xref: /OK3568_Linux_fs/external/rknpu2/examples/rknn_yolov5_demo/utils/mpp_decoder.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 #ifndef __MPP_DECODER_H__
2 #define __MPP_DECODER_H__
3 
4 #include <string.h>
5 #include "rockchip/rk_mpi.h"
6 #include "rockchip/mpp_frame.h"
7 #include <string.h>
8 #include <pthread.h>
9 
10 #define MPI_DEC_STREAM_SIZE         (SZ_4K)
11 #define MPI_DEC_LOOP_COUNT          4
12 #define MAX_FILE_NAME_LENGTH        256
13 
14 typedef void (*MppDecoderFrameCallback)(void* userdata, int width_stride, int height_stride, int width, int height, int format, int fd, void* data);
15 
16 typedef struct
17 {
18     MppCtx          ctx;
19     MppApi          *mpi;
20     RK_U32          eos;
21     char            *buf;
22 
23     MppBufferGroup  frm_grp;
24     MppBufferGroup  pkt_grp;
25     MppPacket       packet;
26     size_t          packet_size;
27     MppFrame        frame;
28 
29     RK_S32          frame_count;
30     RK_S32          frame_num;
31     size_t          max_usage;
32 } MpiDecLoopData;
33 
34 class MppDecoder
35 {
36 public:
37     MppCtx mpp_ctx          = NULL;
38     MppApi *mpp_mpi         = NULL;
39     MppDecoder();
40     ~MppDecoder();
41     int Init(int video_type, int fps, void* userdata);
42     int SetCallback(MppDecoderFrameCallback callback);
43     int Decode(uint8_t* pkt_data, int pkt_size, int pkt_eos);
44     int Reset();
45 private:
46     // base flow context
47     MpiCmd mpi_cmd      = MPP_CMD_BASE;
48     MppParam mpp_param1      = NULL;
49     RK_U32 need_split   = 1;
50     RK_U32 width_mpp       ;
51     RK_U32 height_mpp      ;
52     MppCodingType mpp_type;
53     size_t packet_size  = 2400*1300*3/2;
54     MpiDecLoopData loop_data;
55     // bool vedio_type;//判断vedio是h264/h265
56     MppPacket packet = NULL;
57     MppFrame  frame  = NULL;
58     pthread_t th=NULL;
59     MppDecoderFrameCallback callback;
60     int fps = -1;
61     unsigned long last_frame_time_ms = 0;
62 
63     void* userdata = NULL;
64 };
65 
66 size_t mpp_frame_get_buf_size(const MppFrame s);
67 size_t mpp_buffer_group_usage(MppBufferGroup group);
68 
69 #endif //__MPP_DECODER_H__
70