#ifndef CIMAGEHANDLER_H
#define CIMAGEHANDLER_H

#include "FFmpegFunc.h"
#include <thread>
#include <mutex>
#include <opencv2/opencv.hpp>
#include "ImageIO.h"

#define GOPSIZE 20

class CImageHandler
{
public:
    CImageHandler(CImageIO *piCVMatIO);
    ~CImageHandler();
    int GetFrameData(uint8_t **pBuffer, int *nBufferLen);

private:
    int Init();
    int UnInit();
    bool CVMatToAVFrame(const cv::Mat &iMat,AVFrame *pFrame);
    AVFrame *AllocAVFrame(enum AVPixelFormat sPixFmt, int nWidth, int nHeight);
    int Encode(AVCodecContext *psCodecCtx,AVPacket *psPkt,AVFrame *frame);

private:
    AVCodecContext *m_psH264CodecCtx;

    AVPacket m_iOutputPkt;
    AVFrame *m_psYUVFrame;
    CImageIO *m_piCVMatIO;
};
#endif // CIMAGEHANDLER_H
