From 9c4f8e627a70fc610a81da2703eeddfde4a7e4fa Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Thu, 15 Jan 2009 17:16:31 +0200 Subject: pulse: introspect sink state --- src/pulse/def.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++- src/pulse/introspect.c | 20 ++++++++++++----- src/pulse/introspect.h | 2 ++ 3 files changed, 76 insertions(+), 6 deletions(-) (limited to 'src/pulse') diff --git a/src/pulse/def.h b/src/pulse/def.h index d43c070e..7dc753f9 100644 --- a/src/pulse/def.h +++ b/src/pulse/def.h @@ -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); diff --git a/src/pulse/introspect.c b/src/pulse/introspect.c index e7fa6d76..a6a228ec 100644 --- a/src/pulse/introspect.c +++ b/src/pulse/introspect.c @@ -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; diff --git a/src/pulse/introspect.h b/src/pulse/introspect.h index a656d1cf..07318c72 100644 --- a/src/pulse/introspect.h +++ b/src/pulse/introspect.h @@ -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 */ -- cgit