#ifndef WASAPI_LOOPBACK_CAPTURER_H
#define WASAPI_LOOPBACK_CAPTURER_H

#include <QObject>
#include <atomic>
#include <condition_variable>
#include <mutex>
#include <thread>
#include <vector>

#include "iaudiocapturer.h"

class WASAPILoopbackCapturer : public QObject, public IAudioCapturer
{
    Q_OBJECT
public:
    explicit WASAPILoopbackCapturer(QObject* parent = nullptr);
    ~WASAPILoopbackCapturer() override;

    bool Init(Type deviceType) override;
    bool Start() override;
    void Stop() override;
    const AudioFormat& GetFormat() const override;
    int readAudioData(char* buf, int maxLen) override;

private:
    void captureThreadFunc();

    std::atomic<bool> m_running{false};
    std::thread m_captureThread;
    std::vector<char> m_buffer;
    std::mutex m_mutex;
    std::condition_variable m_cv;
    AudioFormat m_audioFormat;
    Type m_deviceType;

    class WASAPILoopbackCapturerPrivate* d;
};

#endif // WASAPI_LOOPBACK_CAPTURER_H
