Blame view

DxDecoder/DxDecoder.h.bk 2.52 KB
85cc8cb9   Hu Chunming   ๅŽŸ็‰ˆไปฃ็ 
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 __DxDecoder__DxDecoder__
  #define __DxDecoder__DxDecoder__
  #include "DxDecoderInterface.h"
  #include <queue>
  #include <stdio.h>
  
  #ifdef _MSC_VER
  #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
  
  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>
  }
  
  
  
  #include <cuda.h>
  #include <cuda_runtime.h>
  #include <builtin_types.h>
  #include <cuviddec.h>
  
  #include <helper_functions.h>
  #include <helper_cuda_drvapi.h>    // helper file for CUDA Driver API calls and error checking
  
  #include "FrameQueue.h"
  #include "VideoParser.h"
  #include "VideoDecoder.h"
  
  #include "cuda_kernels.h"
  
  
  #define CUDA_UNKNOW_CODEC ( ( cudaVideoCodec )-1 )
  
  cudaVideoCreateFlags getDecodeMode(int iMode);
  cudaVideoCodec getCodecId( unsigned int id );
  cudaVideoChromaFormat getColorFmt( unsigned int fmt );
  
  
  typedef struct DxCUDAContext
  {
  	int width;
  	int height;
  	CUcontext cxt;
  	CUdevice devId;
  	DxVideoConfig cfg;
  	CUVIDEOFORMAT fmt;
  	CUvideoctxlock lock;
  	FrameQueue * frames;
  	VideoParser * parser;
  	VideoDecoder * decoder;
  	cudaVideoCreateFlags flags;
  }DxCUDAContext;
  
  typedef struct DxCUDACoreContext
  {
  	int devCount;
  	CUcontext * cxt;
  	unsigned int * refs;
  	CRITICAL_SECTION criCxt;
  }DxCUDACoreContext;
  
  class DxDecoder: public DxDecoderInterface
  {
  public:
  	DxDecoder( const DxDecoderConfig * cfg );
  	virtual ~DxDecoder();
  
  	virtual int OpenDecoder( const char * uri );
  	virtual int CloseDecoder();
   
   	static int InitDecoder();
  	static void UninitDecoder();
   
  private:
  	int InitCUDA();
  	int UninitCUDA();
  	int StreamProbe();
  	int CheckCUDAProperty( int devId );
  
  #ifdef DX_WINDOWS
  	static DWORD __stdcall StreamParseThread( void * params );
  	static DWORD __stdcall CUDAWorkThread( void * params );
  #endif
  
  #ifdef DX_LINUX
  	static void * __stdcall StreamParseThread( void * params );
  	static void * __stdcall CUDAWorkThread( void * params );
  #endif
  
  private:
  	BOOL m_bRun;
  	char m_uri[4096];
  	HANDLE m_hThread;
  	DxDecoderConfig m_cfg;
  	DxCUDAContext m_cudaCxt;
  	CRITICAL_SECTION m_criTms;
  	unsigned int m_parseFrame;
  	unsigned int m_decodeFrame;
  
  	std::queue < unsigned long long > m_tms;
   
   static DxCUDACoreContext * s_coreCxt;
  };
  
  #endif