
#ifndef MEDIAFORWARDSERVICE_FileWriterFFmpeg_H
#define MEDIAFORWARDSERVICE_FileWriterFFmpeg_H

#if __cplusplus
extern "C"
{
#endif
	#include <libavformat/avformat.h>
	#include <libswscale/swscale.h>
	#include <libswresample/swresample.h>
#if __cplusplus
}
#endif

#include "../MFSPublic.h"

namespace mfs
{
    class FileWriterFFmpeg
    {
    private:
        std::string _fileFullName;
        
        AVFormatContext* _oc = NULL;
        AVCodecContext* _c = NULL;
        AVFrame* _frame = NULL;
	    AVPacket* _packet = NULL;
        SwrContext* _actx = NULL;
	    int64_t _pts = 0;
        std::vector<uint8_t> _samplesBuffer;                     // 重采样时使用
        int _perSampleBytes = 0;
    public:
        FileWriterFFmpeg(const std::string& fileFullName);
        ~FileWriterFFmpeg();
        
        int OpenFile();
        int CloseFile();
        int WriteData(const uint8_t* data, int dataLength); 
    private:
        void InitCodec();
        AVCodecID GetCodecIDByFormat();
    };
    
}

#endif