#ifndef IMAGEIO_H
#define IMAGEIO_H

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

class CImageIO{
public:
    CImageIO(uint nFrame,uint nWidth,uint nHeight);
    ~CImageIO();

    uint GetFrameRate();
    uint GetWidth();
    uint GetHeight();

    cv::Mat ReadCVMat(bool &bKeyFrame);
    bool WriteCVMat(const cv::Mat &iMat);
    void SetKeyFrameFlag();

    bool StartRecording(const std::string &strFileName);
    bool HandleEncodeAVPacket(AVPacket *pPacket,bool bKeyFrame);
    bool SetFinishRecordFlag();

private:
    bool FinishRecording();

private:
    cv::Mat         m_iMat;

    uint m_nFrameRate;
    uint m_nWidth;
    uint m_nHeight;
    int  m_nNextStreamIskeyFrame;

    CMediaRecoder   *m_pRecoder;
    bool    m_bFinishFlag;
};

#endif // IMAGEIO_H
