#ifndef MINI_AUDIO_PLAYER_H
#define MINI_AUDIO_PLAYER_H


#include <string>
#include <vector>
#include <queue>
#include <shared_mutex>
#include <memory>

#include "mini_audio.h"
#include "dubbing_global.h"

namespace DUBBING
{
    class DUBBING_CLIENT_EXPORT MiniAudioPlayer
    {
    public:
        static void playDataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount);
        static void stopDataCallback(ma_device* pDevice);

        static void recordDataCallback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount);
        static void stopRecordDataCallback(ma_device* pDevice);

    public:
        MiniAudioPlayer();
        ~MiniAudioPlayer();

        bool play(ma_device_id& deviceId, const std::wstring& audioFile, uint64_t startPos = 0);
        void stop();
        bool seek(uint64_t curPos);
        uint64_t curPos();
        void setMute(bool mute = true);
        bool startRecordWav(ma_device_id& deviceId, const std::wstring& wavFile);
        void stopRecordWav();
        bool getFileDuration(const std::wstring& audioFile, uint64_t& duration);
        bool isQualifiedAudioFile(const std::wstring& audioFile);

        void onProcessPlayDataEvent(void* pOutput, ma_uint32 frameCount);
        void onProcessRecordDataEvent(const void* pInput, ma_uint32 frameCount);

    private:
        ma_device m_playDevice;
        ma_decoder m_playDecoder;
        ma_device m_recordDevice;
        ma_encoder m_recordEncoder;
        bool m_isPlayerMute = false;
    };
}

#endif // MINI_AUDIO_PLAYER_H
