DxDecoderWrap.h 2.48 KB
#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