
#ifndef AUDIOCONVERTER_H
#define AUDIOCONVERTER_H

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

#include "../MFSPublic.h"

#define SAMPLERATE_AUDIO  8000
#define CHANNELS_AUDIO      1

namespace mfs
{
    class AudioConverterAAC
    {
    private:
        AVCodecContext* _c = NULL;
        AVFrame* _frame = NULL;
        SwrContext* _actx = NULL;
        std::vector<uint8_t> _samplesBuffer;                     // 重采样时使用
        int _perSampleBytes = 0;
    public:
        AudioConverterAAC();
        ~AudioConverterAAC();
        
        int Start();
        int Stop();
        int ConvertData(const uint8_t* data, int dataLength, std::vector<uint8_t>& outdata); 
    private:
        void AddADTS(char* outdata, int packetLen);
        void InitCodec();
        AVCodecID GetCodecIDByFormat();
    };
}
#endif