DxDecoderWrap.h 1.83 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>


#include "cuda_kernels.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 DxGetFrameCount();


	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 
									  );

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]; 

};

#endif