DxDecoderWrap.h 1.65 KB
#ifndef __DX__DxDecoderWrap__
#define __DX__DxDecoderWrap__

#include <memory>
#include <queue>
#include <string>
#include <mutex>

#include "cuda_kernels.h"

#include "FFNvDecoder.h"


#define DX_GPU_FRAME_DEFAULT_SIZE   1

typedef struct DxConfig
{
	int devId;                       // 设备(GPU)ID
	int decMode;                     // 解码模式: 0 全解码; 1 关键帧解码
	int colorFmt;                    // 颜色空间
	bool forceTcp;                   // 对于实时流,是否强制为TCP取流
	std::string name;
}DxConfig;

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;
}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();
	int DxLockFrame(DxGPUFrame& frame );
	
	int PauseDecoder();
	int ResumeDecoder();

public:
	string GetName() {return m_name;};
	void post_decode_callback(GPUFrame * gpuFrame);
	void decode_finished_callback();

private:
	bool m_bClose;

	FFDecConfig m_cfg;
	string m_name;
	FFNvDecoder* m_pDec;

	std::queue<DxGPUFrame> m_queue_frames;
	std::mutex m_queue_frames_mutex;

	int m_decMode{0};
};

#endif