mixer-control: Expose stream state

The state can be used to determine whether audio is currently playing
or not, which can be useful information.

https://gitlab.gnome.org/GNOME/libgnome-volume-control/merge_requests/8
This commit is contained in:
Florian Müllner 2019-11-22 18:09:21 +01:00
parent 647e24625a
commit ec5cf3e0de
4 changed files with 73 additions and 4 deletions

View File

@ -1452,6 +1452,21 @@ set_icon_name_from_proplist (GvcMixerStream *stream,
gvc_mixer_stream_set_icon_name (stream, t); gvc_mixer_stream_set_icon_name (stream, t);
} }
static GvcMixerStreamState
translate_pa_state (pa_sink_state_t state) {
switch (state) {
case PA_SINK_RUNNING:
return GVC_STREAM_STATE_RUNNING;
case PA_SINK_IDLE:
return GVC_STREAM_STATE_IDLE;
case PA_SINK_SUSPENDED:
return GVC_STREAM_STATE_SUSPENDED;
case PA_SINK_INVALID_STATE:
default:
return GVC_STREAM_STATE_INVALID;
}
}
/* /*
* Called when anything changes with a sink. * Called when anything changes with a sink.
*/ */
@ -1521,6 +1536,7 @@ update_sink (GvcMixerControl *control,
gvc_mixer_stream_set_is_muted (stream, info->mute); gvc_mixer_stream_set_is_muted (stream, info->mute);
gvc_mixer_stream_set_can_decibel (stream, !!(info->flags & PA_SINK_DECIBEL_VOLUME)); gvc_mixer_stream_set_can_decibel (stream, !!(info->flags & PA_SINK_DECIBEL_VOLUME));
gvc_mixer_stream_set_base_volume (stream, (guint32) info->base_volume); gvc_mixer_stream_set_base_volume (stream, (guint32) info->base_volume);
gvc_mixer_stream_set_state (stream, translate_pa_state (info->state));
/* Messy I know but to set the port everytime regardless of whether it has changed will cost us a /* Messy I know but to set the port everytime regardless of whether it has changed will cost us a
* port change notify signal which causes the frontend to resync. * port change notify signal which causes the frontend to resync.

View File

@ -32,6 +32,7 @@
#include "gvc-mixer-stream.h" #include "gvc-mixer-stream.h"
#include "gvc-mixer-stream-private.h" #include "gvc-mixer-stream-private.h"
#include "gvc-channel-map-private.h" #include "gvc-channel-map-private.h"
#include "gvc-enum-types.h"
static guint32 stream_serial = 1; static guint32 stream_serial = 1;
@ -57,6 +58,7 @@ struct GvcMixerStreamPrivate
char *port; char *port;
char *human_port; char *human_port;
GList *ports; GList *ports;
GvcMixerStreamState state;
}; };
enum enum
@ -80,6 +82,7 @@ enum
PROP_IS_VIRTUAL, PROP_IS_VIRTUAL,
PROP_CARD_INDEX, PROP_CARD_INDEX,
PROP_PORT, PROP_PORT,
PROP_STATE,
}; };
static void gvc_mixer_stream_finalize (GObject *object); static void gvc_mixer_stream_finalize (GObject *object);
@ -580,6 +583,27 @@ gvc_mixer_stream_get_ports (GvcMixerStream *stream)
return stream->priv->ports; return stream->priv->ports;
} }
gboolean
gvc_mixer_stream_set_state (GvcMixerStream *stream,
GvcMixerStreamState state)
{
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), FALSE);
if (stream->priv->state != state) {
stream->priv->state = state;
g_object_notify (G_OBJECT (stream), "state");
}
return TRUE;
}
GvcMixerStreamState
gvc_mixer_stream_get_state (GvcMixerStream *stream)
{
g_return_val_if_fail (GVC_IS_MIXER_STREAM (stream), GVC_STREAM_STATE_INVALID);
return stream->priv->state;
}
static int static int
sort_ports (GvcMixerStreamPort *a, sort_ports (GvcMixerStreamPort *a,
GvcMixerStreamPort *b) GvcMixerStreamPort *b)
@ -686,6 +710,9 @@ gvc_mixer_stream_set_property (GObject *object,
case PROP_PORT: case PROP_PORT:
gvc_mixer_stream_set_port (self, g_value_get_string (value)); gvc_mixer_stream_set_port (self, g_value_get_string (value));
break; break;
case PROP_STATE:
gvc_mixer_stream_set_state (self, g_value_get_enum (value));
break;
case PROP_CARD_INDEX: case PROP_CARD_INDEX:
self->priv->card_index = g_value_get_long (value); self->priv->card_index = g_value_get_long (value);
break; break;
@ -757,6 +784,9 @@ gvc_mixer_stream_get_property (GObject *object,
case PROP_PORT: case PROP_PORT:
g_value_set_string (value, self->priv->port); g_value_set_string (value, self->priv->port);
break; break;
case PROP_STATE:
g_value_set_enum (value, self->priv->state);
break;
case PROP_CARD_INDEX: case PROP_CARD_INDEX:
g_value_set_long (value, self->priv->card_index); g_value_set_long (value, self->priv->card_index);
break; break;
@ -986,6 +1016,14 @@ gvc_mixer_stream_class_init (GvcMixerStreamClass *klass)
"The name of the current port for this stream", "The name of the current port for this stream",
NULL, NULL,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
g_object_class_install_property (gobject_class,
PROP_STATE,
g_param_spec_enum ("state",
"State",
"The current state of this stream",
GVC_TYPE_MIXER_STREAM_STATE,
GVC_STREAM_STATE_INVALID,
G_PARAM_READWRITE));
g_object_class_install_property (gobject_class, g_object_class_install_property (gobject_class,
PROP_CARD_INDEX, PROP_CARD_INDEX,
g_param_spec_long ("card-index", g_param_spec_long ("card-index",

View File

@ -64,6 +64,14 @@ typedef struct
gboolean available; gboolean available;
} GvcMixerStreamPort; } GvcMixerStreamPort;
typedef enum
{
GVC_STREAM_STATE_INVALID,
GVC_STREAM_STATE_RUNNING,
GVC_STREAM_STATE_IDLE,
GVC_STREAM_STATE_SUSPENDED
} GvcMixerStreamState;
GType gvc_mixer_stream_port_get_type (void) G_GNUC_CONST; GType gvc_mixer_stream_port_get_type (void) G_GNUC_CONST;
GType gvc_mixer_stream_get_type (void) G_GNUC_CONST; GType gvc_mixer_stream_get_type (void) G_GNUC_CONST;
@ -95,6 +103,7 @@ const char * gvc_mixer_stream_get_application_id (GvcMixerStream *stream)
gboolean gvc_mixer_stream_is_event_stream (GvcMixerStream *stream); gboolean gvc_mixer_stream_is_event_stream (GvcMixerStream *stream);
gboolean gvc_mixer_stream_is_virtual (GvcMixerStream *stream); gboolean gvc_mixer_stream_is_virtual (GvcMixerStream *stream);
guint gvc_mixer_stream_get_card_index (GvcMixerStream *stream); guint gvc_mixer_stream_get_card_index (GvcMixerStream *stream);
GvcMixerStreamState gvc_mixer_stream_get_state (GvcMixerStream *stream);
/* private */ /* private */
gboolean gvc_mixer_stream_set_volume (GvcMixerStream *stream, gboolean gvc_mixer_stream_set_volume (GvcMixerStream *stream,
@ -129,6 +138,8 @@ gboolean gvc_mixer_stream_set_ports (GvcMixerStream *stream,
GList *ports); GList *ports);
gboolean gvc_mixer_stream_set_card_index (GvcMixerStream *stream, gboolean gvc_mixer_stream_set_card_index (GvcMixerStream *stream,
guint card_index); guint card_index);
gboolean gvc_mixer_stream_set_state (GvcMixerStream *stream,
GvcMixerStreamState state);
G_END_DECLS G_END_DECLS

View File

@ -1,5 +1,5 @@
project('gvc', 'c', project('gvc', 'c',
meson_version: '>= 0.38.0', meson_version: '>= 0.42.0',
default_options: ['static=true'] default_options: ['static=true']
) )
@ -27,6 +27,10 @@ libgvc_gir_headers = [
'gvc-mixer-ui-device.h' 'gvc-mixer-ui-device.h'
] ]
libgvc_enums = gnome.mkenums_simple('gvc-enum-types',
sources: libgvc_gir_headers
)
libgvc_gir_sources = [ libgvc_gir_sources = [
'gvc-channel-map.c', 'gvc-channel-map.c',
'gvc-mixer-card.c', 'gvc-mixer-card.c',
@ -75,7 +79,7 @@ endif
if enable_static if enable_static
libgvc_static = static_library('gvc', libgvc_static = static_library('gvc',
sources: libgvc_gir_sources + libgvc_no_gir_sources, sources: libgvc_gir_sources + libgvc_no_gir_sources + libgvc_enums,
dependencies: libgvc_deps, dependencies: libgvc_deps,
c_args: c_args c_args: c_args
) )
@ -87,7 +91,7 @@ else
endif endif
libgvc_shared = shared_library('gvc', libgvc_shared = shared_library('gvc',
sources: libgvc_gir_sources + libgvc_no_gir_sources, sources: libgvc_gir_sources + libgvc_no_gir_sources + libgvc_enums,
dependencies: libgvc_deps, dependencies: libgvc_deps,
c_args: c_args, c_args: c_args,
install_dir: pkglibdir, install_dir: pkglibdir,
@ -101,7 +105,7 @@ if enable_introspection
assert(pkgdatadir != '', 'Installing introspection, but pkgdatadir is unset!') assert(pkgdatadir != '', 'Installing introspection, but pkgdatadir is unset!')
libgvc_gir = gnome.generate_gir(libgvc, libgvc_gir = gnome.generate_gir(libgvc,
sources: libgvc_gir_sources + libgvc_gir_headers, sources: libgvc_gir_sources + libgvc_gir_headers + libgvc_enums,
nsversion: '1.0', nsversion: '1.0',
namespace: 'Gvc', namespace: 'Gvc',
includes: ['Gio-2.0', 'GObject-2.0'], includes: ['Gio-2.0', 'GObject-2.0'],