- u_async.c: process immediate_queue BEFORE epoll_wait in uasync_poll - stcp_link.c: defensive NULL etcp_conn/etcp_link in stcp_link_close - utun_instance.c: move stcp_server_list_destroy_all to Phase J (before ETCP), add deferred drain in both Phase J and L - stcp.h/c: STCP_HS_ENC_CLIENT 6→38, STCP_HS_ENC_SERVER 7→39, exchange ed25519_pubkey in both handshake directions - etcp_connections.c: copy peer_ed25519 from STCP to ETCP_CONN in etcp_link_enter_ready_tcp; guard link->etcp in tcp_link_close_cb - chat_sync.c: fix lk->conn NULL dereference for TCP links - test_stcp.c: update stcp_server_create/stcp_client_connect callsites - tools/chat_tcp_test: change transport udp→tcp
67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QString>
|
|
#include <QTimer>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
struct ma_device;
|
|
struct audio_compressor;
|
|
|
|
class AudioRecorder : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
explicit AudioRecorder(QObject* parent = nullptr);
|
|
~AudioRecorder() override;
|
|
|
|
bool init();
|
|
void shutdown();
|
|
bool isInitialized() const { return m_initialized; }
|
|
|
|
void setCaptureDeviceIndex(int index) { m_captureDeviceIndex = index; }
|
|
int captureDeviceIndex() const { return m_captureDeviceIndex; }
|
|
|
|
void startRecording();
|
|
void stopRecording();
|
|
bool isRecording() const { return m_recording; }
|
|
|
|
float peakLevel() const;
|
|
|
|
const int16_t* bufferData() const;
|
|
size_t bufferSize() const;
|
|
const std::vector<float>& waveformLevels() const { return m_waveformLevels; }
|
|
int durationMs() const;
|
|
|
|
struct audio_compressor* compressor() const { return m_compressor; }
|
|
void setCompressorEnabled(bool enabled);
|
|
bool isCompressorEnabled() const { return m_compressorEnabled; }
|
|
|
|
signals:
|
|
void recordingStarted();
|
|
void recordingStopped(int durationMs);
|
|
void durationChanged(int ms);
|
|
|
|
private:
|
|
ma_device* m_device = nullptr;
|
|
bool m_initialized = false;
|
|
bool m_recording = false;
|
|
bool m_deviceStarted = false;
|
|
int m_sampleRate = 48000;
|
|
int m_channels = 1;
|
|
int m_captureDeviceIndex = -1;
|
|
|
|
std::vector<int16_t> m_pcmBuffer;
|
|
mutable float m_peakLevel = 0.0f;
|
|
std::vector<float> m_recentRms = std::vector<float>(5, 0.0f);
|
|
int m_rmsIdx = 0;
|
|
std::vector<float> m_waveformLevels;
|
|
QTimer m_durationTimer;
|
|
int m_elapsedMs = 0;
|
|
|
|
struct audio_compressor* m_compressor = nullptr;
|
|
bool m_compressorEnabled = false;
|
|
|
|
friend void audioCaptureCallback(ma_device* pDevice, void* pOutput, const void* pInput, unsigned int frameCount);
|
|
};
|