/*
 * Copyright (C) 2022, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 * Authors: Xin Li <lixin@kylinos.cn>
 */
#ifndef FFUTIL_H
#define FFUTIL_H

#include <QObject>

struct AVCodec;
struct AVCodecContext;
struct AVFormatContext;
struct AVOutputFormat;

class FFUtil : public QObject
{
    Q_OBJECT
public:
    enum AudioFormatType { AudioFormat_WAV, AudioFormat_MP3, AudioFormat_M4A };

    explicit FFUtil(QObject *parent = nullptr);
    int open(QString _file);
    int getDuration(QString path);
    void close();

    void generateAudioFile(AudioFormatType formatType, QString fileName, QByteArray pcmData);

private:
    AVOutputFormat *pOutputFormat = nullptr;
    AVFormatContext *pFormatCtx = nullptr;
    AVCodecContext *pCodecCtx = nullptr;
    int audioStream;
    int audioDuration;

    AVCodec *m_AudioCodec = nullptr;
    AVCodecContext *m_AudioCodecContext = nullptr;
    AVFormatContext *m_FormatContext = nullptr;
    AVOutputFormat *m_OutputFormat = nullptr;

    // init Format
    bool initFormat(QString audioFileName);

signals:
};

#endif // FFUTIL_H
