#ifndef _OPUS_ENCODER_WRAPPER_H_ #define _OPUS_ENCODER_WRAPPER_H_ #include #include #include #include #include #include "opus.h" #define MAX_OPUS_PACKET_SIZE 1000 class OpusEncoderWrapper { public: OpusEncoderWrapper(int sample_rate, int channels, int duration_ms = 60); ~OpusEncoderWrapper(); inline int sample_rate() const { return sample_rate_; } inline int duration_ms() const { return duration_ms_; } void SetDtx(bool enable); void SetComplexity(int complexity); void Encode(std::vector&& pcm, std::function&& opus)> handler); bool IsBufferEmpty() const { return in_buffer_.empty(); } void ResetState(); private: std::mutex mutex_; struct OpusEncoder* audio_enc_ = nullptr; int sample_rate_; int duration_ms_; int frame_size_; std::vector in_buffer_; }; #endif // _OPUS_ENCODER_H_