mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-29 05:40:23 -04:00
pulse: introspect sink state
This commit is contained in:
parent
f83111dd17
commit
9c4f8e627a
6 changed files with 103 additions and 28 deletions
|
|
@ -613,6 +613,35 @@ typedef enum pa_sink_flags {
|
|||
#define PA_SINK_DECIBEL_VOLUME PA_SINK_DECIBEL_VOLUME
|
||||
/** \endcond */
|
||||
|
||||
/** Sink state. \since 0.9.15 */
|
||||
typedef enum pa_sink_state { /* enum serialized in u8 */
|
||||
PA_SINK_INVALID_STATE = -1,
|
||||
/**< This state is used when the server does not support sink state introspection \since 0.9.15 */
|
||||
|
||||
PA_SINK_RUNNING = 0,
|
||||
/**< Running, sink is playing and used by at least one non-corked sink-input \since 0.9.15 */
|
||||
|
||||
PA_SINK_IDLE = 1,
|
||||
/**< When idle, the sink is playing but there is no non-corked sink-input attached to it \since 0.9.15 */
|
||||
|
||||
PA_SINK_SUSPENDED = 2
|
||||
/**< When suspended, actual sink access can be closed, for instance \since 0.9.15 */
|
||||
|
||||
} pa_sink_state_t;
|
||||
|
||||
/** Returns non-zero if sink is playing: running or idle. \since 0.9.15 */
|
||||
static inline int PA_SINK_IS_OPENED(pa_sink_state_t x) {
|
||||
return x == PA_SINK_RUNNING || x == PA_SINK_IDLE;
|
||||
}
|
||||
|
||||
/** \cond fulldocs */
|
||||
#define PA_SINK_INVALID_STATE PA_SINK_INVALID_STATE
|
||||
#define PA_SINK_RUNNING PA_SINK_RUNNING
|
||||
#define PA_SINK_IDLE PA_SINK_IDLE
|
||||
#define PA_SINK_SUSPENDED PA_SINK_SUSPENDED
|
||||
#define PA_SINK_IS_OPENED PA_SINK_IS_OPENED
|
||||
/** \endcond */
|
||||
|
||||
/** Special source flags. */
|
||||
typedef enum pa_source_flags {
|
||||
PA_SOURCE_HW_VOLUME_CTRL = 0x0001U,
|
||||
|
|
@ -626,7 +655,7 @@ typedef enum pa_source_flags {
|
|||
* "virtual"/software source \since 0.9.3 */
|
||||
|
||||
PA_SOURCE_NETWORK = 0x0008U,
|
||||
/**< Is a networked sink of some kind. \since 0.9.7 */
|
||||
/**< Is a networked source of some kind. \since 0.9.7 */
|
||||
|
||||
PA_SOURCE_HW_MUTE_CTRL = 0x0010U,
|
||||
/**< Supports hardware mute control \since 0.9.11 */
|
||||
|
|
@ -645,6 +674,35 @@ typedef enum pa_source_flags {
|
|||
#define PA_SOURCE_DECIBEL_VOLUME PA_SOURCE_DECIBEL_VOLUME
|
||||
/** \endcond */
|
||||
|
||||
/** Source state. \since 0.9.15 */
|
||||
typedef enum pa_source_state {
|
||||
PA_SOURCE_INVALID_STATE = -1,
|
||||
/**< This state is used when the server does not support source state introspection \since 0.9.15 */
|
||||
|
||||
PA_SOURCE_RUNNING = 0,
|
||||
/**< Running, source is recording and used by at least one non-corked source-output \since 0.9.15 */
|
||||
|
||||
PA_SOURCE_IDLE = 1,
|
||||
/**< When idle, the source is still recording but there is no non-corked source-output \since 0.9.15 */
|
||||
|
||||
PA_SOURCE_SUSPENDED = 2
|
||||
/**< When suspended, actual source access can be closed, for instance \since 0.9.15 */
|
||||
|
||||
} pa_source_state_t;
|
||||
|
||||
/** Returns non-zero if source is recording: running or idle. \since 0.9.15 */
|
||||
static inline int PA_SOURCE_IS_OPENED(pa_source_state_t x) {
|
||||
return x == PA_SOURCE_RUNNING || x == PA_SOURCE_IDLE;
|
||||
}
|
||||
|
||||
/** \cond fulldocs */
|
||||
#define PA_SOURCE_INVALID_STATE PA_SOURCE_INVALID_STATE
|
||||
#define PA_SOURCE_RUNNING PA_SOURCE_RUNNING
|
||||
#define PA_SOURCE_IDLE PA_SOURCE_IDLE
|
||||
#define PA_SOURCE_SUSPENDED PA_SOURCE_SUSPENDED
|
||||
#define PA_SOURCE_IS_OPENED PA_SOURCE_IS_OPENED
|
||||
/** \endcond */
|
||||
|
||||
/** A generic free() like callback prototype */
|
||||
typedef void (*pa_free_cb_t)(void *p);
|
||||
|
||||
|
|
|
|||
|
|
@ -146,15 +146,18 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, u
|
|||
|
||||
eol = -1;
|
||||
} else {
|
||||
uint32_t flags;
|
||||
|
||||
while (!pa_tagstruct_eof(t)) {
|
||||
pa_sink_info i;
|
||||
pa_bool_t mute = FALSE;
|
||||
pa_bool_t mute;
|
||||
uint32_t flags;
|
||||
uint32_t state;
|
||||
|
||||
memset(&i, 0, sizeof(i));
|
||||
i.proplist = pa_proplist_new();
|
||||
i.base_volume = PA_VOLUME_NORM;
|
||||
mute = FALSE;
|
||||
state = PA_SINK_INVALID_STATE;
|
||||
|
||||
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
|
||||
pa_tagstruct_gets(t, &i.name) < 0 ||
|
||||
|
|
@ -173,7 +176,8 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, u
|
|||
(pa_tagstruct_get_proplist(t, i.proplist) < 0 ||
|
||||
pa_tagstruct_get_usec(t, &i.configured_latency) < 0)) ||
|
||||
(o->context->version >= 15 &&
|
||||
pa_tagstruct_get_volume(t, &i.base_volume) < 0)) {
|
||||
(pa_tagstruct_get_volume(t, &i.base_volume) < 0 ||
|
||||
pa_tagstruct_getu32(t, &state) < 0))) {
|
||||
|
||||
pa_context_fail(o->context, PA_ERR_PROTOCOL);
|
||||
pa_proplist_free(i.proplist);
|
||||
|
|
@ -182,6 +186,7 @@ static void context_get_sink_info_callback(pa_pdispatch *pd, uint32_t command, u
|
|||
|
||||
i.mute = (int) mute;
|
||||
i.flags = (pa_sink_flags_t) flags;
|
||||
i.state = (pa_sink_state_t) state;
|
||||
|
||||
if (o->callback) {
|
||||
pa_sink_info_cb_t cb = (pa_sink_info_cb_t) o->callback;
|
||||
|
|
@ -273,12 +278,15 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
|
|||
|
||||
while (!pa_tagstruct_eof(t)) {
|
||||
pa_source_info i;
|
||||
pa_bool_t mute;
|
||||
uint32_t flags;
|
||||
pa_bool_t mute = FALSE;
|
||||
uint32_t state;
|
||||
|
||||
memset(&i, 0, sizeof(i));
|
||||
i.proplist = pa_proplist_new();
|
||||
i.base_volume = PA_VOLUME_NORM;
|
||||
mute = FALSE;
|
||||
state = PA_SOURCE_INVALID_STATE;
|
||||
|
||||
if (pa_tagstruct_getu32(t, &i.index) < 0 ||
|
||||
pa_tagstruct_gets(t, &i.name) < 0 ||
|
||||
|
|
@ -297,7 +305,8 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
|
|||
(pa_tagstruct_get_proplist(t, i.proplist) < 0 ||
|
||||
pa_tagstruct_get_usec(t, &i.configured_latency) < 0)) ||
|
||||
(o->context->version >= 15 &&
|
||||
pa_tagstruct_get_volume(t, &i.base_volume) < 0)) {
|
||||
(pa_tagstruct_get_volume(t, &i.base_volume) < 0 ||
|
||||
pa_tagstruct_getu32(t, &state) < 0))) {
|
||||
|
||||
pa_context_fail(o->context, PA_ERR_PROTOCOL);
|
||||
pa_proplist_free(i.proplist);
|
||||
|
|
@ -306,6 +315,7 @@ static void context_get_source_info_callback(pa_pdispatch *pd, uint32_t command,
|
|||
|
||||
i.mute = (int) mute;
|
||||
i.flags = (pa_source_flags_t) flags;
|
||||
i.state = (pa_source_state_t) state;
|
||||
|
||||
if (o->callback) {
|
||||
pa_source_info_cb_t cb = (pa_source_info_cb_t) o->callback;
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ typedef struct pa_sink_info {
|
|||
pa_proplist *proplist; /**< Property list \since 0.9.11 */
|
||||
pa_usec_t configured_latency; /**< The latency this device has been configured to. \since 0.9.11 */
|
||||
pa_volume_t base_volume; /**< Some kind of "base" volume that refers to unamplified/unattenuated volume in the context of the output device. \since 0.9.15 */
|
||||
pa_sink_state_t state; /**< State \since 0.9.15 */
|
||||
} pa_sink_info;
|
||||
|
||||
/** Callback prototype for pa_context_get_sink_info_by_name() and friends */
|
||||
|
|
@ -268,6 +269,7 @@ typedef struct pa_source_info {
|
|||
pa_proplist *proplist; /**< Property list \since 0.9.11 */
|
||||
pa_usec_t configured_latency; /**< The latency this device has been configured to. \since 0.9.11 */
|
||||
pa_volume_t base_volume; /**< Some kind of "base" volume that refers to unamplified/unattenuated volume in the context of the input device. \since 0.9.15 */
|
||||
pa_source_state_t state; /**< State \since 0.9.15 */
|
||||
} pa_source_info;
|
||||
|
||||
/** Callback prototype for pa_context_get_source_info_by_name() and friends */
|
||||
|
|
|
|||
|
|
@ -2679,8 +2679,12 @@ static void sink_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_sin
|
|||
pa_tagstruct_put_usec(t, pa_sink_get_requested_latency(sink));
|
||||
}
|
||||
|
||||
if (c->version >= 15)
|
||||
if (c->version >= 15) {
|
||||
pa_tagstruct_put_volume(t, sink->base_volume);
|
||||
if (PA_UNLIKELY(pa_sink_get_state(sink) == PA_SINK_INVALID_STATE))
|
||||
pa_log_error("Internal sink state is invalid.");
|
||||
pa_tagstruct_putu32(t, pa_sink_get_state(sink));
|
||||
}
|
||||
}
|
||||
|
||||
static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_source *source) {
|
||||
|
|
@ -2713,8 +2717,12 @@ static void source_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_s
|
|||
pa_tagstruct_put_usec(t, pa_source_get_requested_latency(source));
|
||||
}
|
||||
|
||||
if (c->version >= 15)
|
||||
if (c->version >= 15) {
|
||||
pa_tagstruct_put_volume(t, source->base_volume);
|
||||
if (PA_UNLIKELY(pa_source_get_state(source) == PA_SOURCE_INVALID_STATE))
|
||||
pa_log_error("Internal source state is invalid.");
|
||||
pa_tagstruct_putu32(t, pa_source_get_state(source));
|
||||
}
|
||||
}
|
||||
|
||||
static void client_fill_tagstruct(pa_native_connection *c, pa_tagstruct *t, pa_client *client) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ typedef struct pa_sink pa_sink;
|
|||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <pulse/def.h>
|
||||
#include <pulse/sample.h>
|
||||
#include <pulse/channelmap.h>
|
||||
#include <pulse/volume.h>
|
||||
|
|
@ -42,18 +43,16 @@ typedef struct pa_sink pa_sink;
|
|||
|
||||
#define PA_MAX_INPUTS_PER_SINK 32
|
||||
|
||||
typedef enum pa_sink_state {
|
||||
PA_SINK_INIT,
|
||||
PA_SINK_RUNNING,
|
||||
PA_SINK_SUSPENDED,
|
||||
PA_SINK_IDLE,
|
||||
PA_SINK_UNLINKED
|
||||
} pa_sink_state_t;
|
||||
/* anonymous enum extending pa_sink_state_t */
|
||||
enum {
|
||||
PA_SINK_INIT = -2,
|
||||
/* Initialization state */
|
||||
|
||||
static inline pa_bool_t PA_SINK_IS_OPENED(pa_sink_state_t x) {
|
||||
return x == PA_SINK_RUNNING || x == PA_SINK_IDLE;
|
||||
}
|
||||
PA_SINK_UNLINKED = -3
|
||||
/* The state when the sink is getting unregistered and removed from client access */
|
||||
};
|
||||
|
||||
/* Returns true if sink is linked: registered and accessible from client side. */
|
||||
static inline pa_bool_t PA_SINK_IS_LINKED(pa_sink_state_t x) {
|
||||
return x == PA_SINK_RUNNING || x == PA_SINK_IDLE || x == PA_SINK_SUSPENDED;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,18 +45,16 @@ typedef struct pa_source pa_source;
|
|||
|
||||
#define PA_MAX_OUTPUTS_PER_SOURCE 32
|
||||
|
||||
typedef enum pa_source_state {
|
||||
PA_SOURCE_INIT,
|
||||
PA_SOURCE_RUNNING,
|
||||
PA_SOURCE_SUSPENDED,
|
||||
PA_SOURCE_IDLE,
|
||||
PA_SOURCE_UNLINKED
|
||||
} pa_source_state_t;
|
||||
/* anonymous enum extending pa_source_state_t */
|
||||
enum {
|
||||
PA_SOURCE_INIT = -2,
|
||||
/* Initialization state */
|
||||
|
||||
static inline pa_bool_t PA_SOURCE_IS_OPENED(pa_source_state_t x) {
|
||||
return x == PA_SOURCE_RUNNING || x == PA_SOURCE_IDLE;
|
||||
}
|
||||
PA_SOURCE_UNLINKED = -3
|
||||
/* The state when the source is getting unregistered and removed from client access */
|
||||
};
|
||||
|
||||
/* Returns true if source is linked: registered and accessible from client side. */
|
||||
static inline pa_bool_t PA_SOURCE_IS_LINKED(pa_source_state_t x) {
|
||||
return x == PA_SOURCE_RUNNING || x == PA_SOURCE_IDLE || x == PA_SOURCE_SUSPENDED;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue