#ifndef VDR_EM84XX_IFRAME_H
#define VDR_EM84XX_IFRAME_H

#include <stddef.h>
#include <inttypes.h>

extern "C"
{
#ifdef HAVE_NEW_FFMPEG_HEADER
# include <libavcodec/avcodec.h>
#else
# include <ffmpeg/avcodec.h>
#endif
}

class cIFrameDecoder
{
private:
	AVCodec * mMpeg2Codec;
	AVCodecContext * mCodecContext;
	AVFrame * mDecodedFrame;
	AVFrame * mDecodedYUVFrame;
	unsigned char* mYUVFrameBuffer;
	int mFrameWidth;
	int mFrameHeight;
	bool mFrameValid;

	//AVFrame * mResizeFrame;
	//AVFrame * mResultFrame;
	//unsigned char * mBufferResize;
	bool mInitialized;

public:
	static void InitFFMpeg(void);
	static void GetVideoES(unsigned char* Data, size_t buffersize, unsigned char* outbuffer, size_t* outbuffersize);

	cIFrameDecoder();

	bool Init(void);
	void Release(void);

	bool DecodeFrame(unsigned char * data, int length);

	bool FrameValid() { return mFrameValid; };
	int FrameWidth() { return mFrameWidth; };
	int FrameHeight() { return mFrameHeight; };
	unsigned char* FrameBuffer() { return mYUVFrameBuffer; };
};

#endif //#ifndef VDR_EM84XX_IFRAME_H
