fix: audio 模块的初始化状态不要暴露给外部

This commit is contained in:
2026-03-08 03:03:02 +08:00
parent 5b41eb97cd
commit 850221793f
2 changed files with 6 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ struct pulse_context_t {
pa_cvolume volume;
pulse_t pulse;
uint32_t index;
bool inited;
};
static void clean_pulse_context(pulse_context_t *context, bool full_cleanup);
@@ -49,7 +50,7 @@ pulse_context_t *init_pulse(GMainContext *context, pulse_notify_t callback) {
}
void change_pulse_volume(pulse_context_t *context, int step) {
if (!context->pulse.inited || !step || step > 100 || step < -100) return;
if (!context->inited || !step || step > 100 || step < -100) return;
pa_cvolume vol = context->volume;
if (step > 0) {
@@ -69,7 +70,7 @@ void change_pulse_volume(pulse_context_t *context, int step) {
}
void toggle_pulse_mute(pulse_context_t *context) {
if (!context->pulse.inited) return;
if (!context->inited) return;
pa_context *ctx = context->context;
uint32_t index = context->index;
@@ -92,7 +93,7 @@ void clean_pulse_context(pulse_context_t *context, bool full_cleanup) {
pa_context_unref(context->context);
context->context = nullptr;
}
context->pulse.inited = false;
context->inited = false;
if (full_cleanup && context->loop) {
pa_glib_mainloop_free(context->loop);
context->loop = nullptr;
@@ -146,7 +147,7 @@ void sink_info_callback(pa_context *context, const pa_sink_info *info, int eol,
if (eol != 0 || !info) return;
pulse_context_t *ctx = userdata;
ctx->pulse.inited = true;
ctx->inited = true;
ctx->volume = info->volume;
ctx->index = info->index;
parse_sink(info, &ctx->pulse);

View File

@@ -8,8 +8,7 @@ typedef struct pulse_context_t pulse_context_t;
typedef struct pulse_t {
int volume_percent;
bool mute;
bool inited;
char device_name[254];
char device_name[255];
} pulse_t;
typedef void (*pulse_notify_t)(pulse_t *pulse);