extern "C" { #include "libavutil/avstring.h" #include "libavutil/mathematics.h" #include "libavutil/pixdesc.h" #include "libavutil/imgutils.h" #include "libavutil/dict.h" #include "libavutil/parseutils.h" #include "libavutil/samplefmt.h" #include "libavutil/avassert.h" #include "libavutil/time.h" #include "libavformat/avformat.h" #include "libavdevice/avdevice.h" #include "libswscale/swscale.h" #include "libavutil/opt.h" #include "libavcodec/avfft.h" #include "libswresample/swresample.h" #include "libavfilter/avfiltergraph.h" #include "libavfilter/buffersink.h" #include "libavfilter/buffersrc.h" #include "libavutil/avutil.h" } #include "SDL/SDL.h" #include "SDL/SDL_thread.h" #pragma comment(lib, "SDL2.lib") #pragma comment(lib, "SDL2main.lib") #pragma comment(lib, "avcodec.lib") #pragma comment(lib, "avformat.lib") #pragma comment(lib, "avutil.lib") #pragma comment(lib, "avfilter.lib") #pragma comment(lib, "avdevice.lib") #pragma comment(lib, "postproc.lib") #pragma comment(lib, "swresample.lib") #pragma comment(lib, "swscale.lib") #include "ffmpeg_dxva2_d.h" #include "D3DVidRender.h" typedef void (*CallbackFun)(unsigned char* data,int width,int height); class Decoder_Hardware_D { public: Decoder_Hardware_D() { mSrcWth = 0; mSrcHth = 0; mDstWth = 0; mDstHth = 0; mPixFmt = 0; mOutBuf = NULL; mBufYUV = NULL; codec = NULL; codecctx = NULL; //pkt; img_convert_ctx = NULL ; scxt = NULL ; mFrameYUV = NULL; mSrcFrame = NULL; mDstFrame = NULL; s = NULL; bAccel = true; ipix_fmt = AV_PIX_FMT_YUV420P; opix_fmt = AV_PIX_FMT_YUV420P; decodingCallback = NULL; frameCount = 0; sTime = 0; eTime = 0; } ~Decoder_Hardware_D(){} bool decoder_hw_init(int srcWth,int srcHth,int dstWth,int dstHth,int oPixFmt,HWND hwnd); void decoder_hw_decoding(unsigned char* in_buf,int in_len); void decoder_hw_release(); void set_decoding_callback(CallbackFun fun){decodingCallback = fun;} protected: bool ffmpeg_ref_release(); void pic_ref_mem_release(); void decoder_sws_scale_callback(); private: CD3DVidRender m_D3DVidRender; int mSrcWth; int mSrcHth; int mDstWth; int mDstHth; int mPixFmt; uint8_t *mOutBuf; uint8_t *mBufYUV; AVCodec *codec; AVCodecContext *codecctx; AVPacket pkt; struct SwsContext *img_convert_ctx; struct SwsContext *scxt; AVFrame *mFrameYUV; AVFrame *mSrcFrame; AVFrame *mDstFrame; AVCodecParserContext *s; bool bAccel; AVPixelFormat ipix_fmt; AVPixelFormat opix_fmt; CallbackFun decodingCallback; DWORD frameCount; DWORD sTime,eTime; };