DxDecoderWrap.h
2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef __DX__DxDecoderWrap__MODULE__
#define __DX__DxDecoderWrap__MODULE__
#include "../DxDecoder/DxDecoderInterface.h"
#include <cuda.h>
#include <cuda_runtime.h>
#include <builtin_types.h>
//#include <cuviddec.h>
#include <memory>
#ifdef DX_WINDOWS
#include <Windows.h>
#pragma comment( lib, "avcodec.lib" )
#pragma comment( lib, "avdevice.lib" )
#pragma comment( lib, "avfilter.lib" )
#pragma comment( lib, "avformat.lib" )
#pragma comment( lib, "avutil.lib" )
#pragma comment( lib, "postproc.lib" )
#pragma comment( lib, "swresample.lib" )
#pragma comment( lib, "swscale.lib" )
#endif
#include "cuda_kernels.h"
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavdevice/avdevice.h>
#include <libavformat/avformat.h>
#include <libavfilter/avfilter.h>
#include <libavutil/avutil.h>
#include <libswscale/swscale.h>
}
#define DX_GPU_FRAME_DEFAULT_SIZE 1
typedef struct DxGPUFrame
{
void * frame;
unsigned int size;
unsigned int width;
unsigned int height;
unsigned long long timestamp;
}DxGPUFrame;
typedef struct DxGPUFrames
{
unsigned int size;
unsigned int read;
unsigned int write;
unsigned int width;
unsigned int height;
unsigned int counts;
DxGPUFrame * frames;
CRITICAL_SECTION cir;
}DxGPUFrames;
class DxDecoderWrap
{
public:
DxDecoderWrap( const DxConfig * cfg );
virtual ~DxDecoderWrap();
int DxOpenDecoder( const char * uri, unsigned int skip );
int DxCloseDecoder();
BOOL DxDecoderIsRun() const;
int DxGetResolution( int * width, int * height );
BOOL DxFrameIsEmpty() const;
int DxLockFrame( DxGPUFrame * frame );
void DxUnlockFrame();
int PauseDecoder();
int ResumeDecoder();
private:
static int DxDecoderLogCallback(
const void * userPtr,
DxLogLevel level,
const char * log,
unsigned int logLen
);
static void DxCUDADecoderCallback(
const void * userPtr,
void * buf,
unsigned int size,
unsigned long long timestamp
);
static void DxCPUDecoderCallback(
const void * userPtr,
void * buf,
unsigned int size,
unsigned long long timestamp
);
private:
BOOL m_bRun;
BOOL m_bReal;
BOOL m_bPause;
unsigned int m_skip;
unsigned int m_nums;
DxGPUFrames m_frames;
DxDecoderConfig m_cfg;
DxDecoderInterface * m_pDec;
unsigned char * m_out;
unsigned int m_outSize;
uint8_t * m_src_data[4];
int m_src_linesize[4];
int m_dst_linesize[4];
uint8_t * m_dst_data[4];
struct SwsContext * m_img_convert_ctx;
};
#endif