- 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
78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
#pragma once
|
|
|
|
#include <QObject>
|
|
#include <QHash>
|
|
#include <QString>
|
|
#include <QByteArray>
|
|
#include <vector>
|
|
#include <cstdint>
|
|
|
|
struct ma_engine;
|
|
struct ma_context;
|
|
struct ma_decoder;
|
|
struct ma_sound;
|
|
|
|
class SoundManager : public QObject {
|
|
Q_OBJECT
|
|
public:
|
|
struct EventSettings {
|
|
bool enabled = true;
|
|
float volume = 0.8f;
|
|
};
|
|
|
|
static SoundManager* instance();
|
|
|
|
bool init();
|
|
void shutdown();
|
|
|
|
void setEnabled(bool enabled);
|
|
bool isEnabled() const;
|
|
void setVolume(float volume);
|
|
float volume() const;
|
|
|
|
void setEvent(const QString& name, bool enabled, float volume);
|
|
EventSettings eventSettings(const QString& name) const;
|
|
|
|
bool loadSound(const QString& name, const QString& filePath);
|
|
void play(const QString& name);
|
|
|
|
ma_context* context();
|
|
|
|
void playRawPcm(const int16_t* pcm, int sampleCount, int sampleRate, int channels);
|
|
void pauseCurrentPcm();
|
|
void resumeCurrentPcm();
|
|
void stopCurrentPcm();
|
|
void seekCurrentPcm(unsigned long long pcmFrame);
|
|
unsigned long long currentPcmCursor() const;
|
|
bool isCurrentPcmPlaying() const;
|
|
int currentPcmSampleRate() const { return m_currentPcmSampleRate; }
|
|
|
|
struct DeviceInfo {
|
|
QString name;
|
|
bool isDefault = false;
|
|
};
|
|
static QVector<DeviceInfo> enumeratePlaybackDevices();
|
|
static QVector<DeviceInfo> enumerateCaptureDevices();
|
|
|
|
private:
|
|
SoundManager() = default;
|
|
~SoundManager();
|
|
|
|
struct LoadedSound {
|
|
QByteArray mp3Data;
|
|
ma_decoder* decoder = nullptr;
|
|
ma_sound* sound = nullptr;
|
|
};
|
|
|
|
ma_engine* m_engine = nullptr;
|
|
ma_context* m_context = nullptr;
|
|
ma_sound* m_currentPcmSound = nullptr;
|
|
void* m_currentPcmBuffer = nullptr;
|
|
int m_currentPcmSampleRate = 0;
|
|
bool m_initialized = false;
|
|
bool m_enabled = true;
|
|
float m_volume = 0.8f;
|
|
QHash<QString, EventSettings> m_eventSettings;
|
|
QHash<QString, LoadedSound> m_sounds;
|
|
};
|