introspect: add state and format for output source

Add state and negotiated format to output source properties.
This commit is contained in:
Wim Taymans 2015-08-04 15:59:36 +02:00
parent 95f479a760
commit 51f18b540a
5 changed files with 77 additions and 8 deletions

View file

@ -339,6 +339,20 @@ source_output_fill_info (PinosSourceOutputInfo *info, GDBusProxy *proxy)
} else {
info->possible_formats = NULL;
}
if ((variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "State"))) {
info->state = g_variant_get_uint32 (variant);
g_variant_unref (variant);
} else {
info->state = PINOS_SOURCE_OUTPUT_STATE_ERROR;
}
if ((variant = g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "Format"))) {
gsize len;
gchar *format = g_variant_dup_string (variant, &len);
info->format = g_bytes_new_take (format, len + 1);
g_variant_unref (variant);
} else {
info->format = NULL;
}
info->properties = pinos_properties_from_variant (
g_dbus_proxy_get_cached_property (G_DBUS_PROXY (proxy), "Properties"));

View file

@ -164,12 +164,30 @@ void pinos_context_get_source_info_by_id (PinosContext *context,
GCancellable *cancellable,
gpointer user_data);
/**
* PinosSourceState:
* @PINOS_SOURCE_OUTPUT_STATE_ERROR: the source output is in error
* @PINOS_SOURCE_OUTPUT_STATE_IDLE: the source output is idle
* @PINOS_SOURCE_OUTPUT_STATE_STARTING: the source output is starting
* @PINOS_SOURCE_OUTPUT_STATE_STREAMING: the source output is streaming
*
* The different source output states
*/
typedef enum {
PINOS_SOURCE_OUTPUT_STATE_ERROR = -1,
PINOS_SOURCE_OUTPUT_STATE_IDLE = 0,
PINOS_SOURCE_OUTPUT_STATE_STARTING = 1,
PINOS_SOURCE_OUTPUT_STATE_STREAMING = 2,
} PinosSourceOutputState;
/**
* PinosSourceOutputInfo:
* @id: generic id of the output
* @client_path: the owner client
* @source_path: the source path
* @possible_formats: the possible formats
* @state: the state
* @format: when streaming, the current format
* @properties: the properties of the source
*
* The source information. Extra information can be added in later
@ -180,6 +198,8 @@ typedef struct {
const char *client_path;
const char *source_path;
GBytes *possible_formats;
PinosSourceOutputState state;
GBytes *format;
PinosProperties *properties;
} PinosSourceOutputInfo;

View file

@ -93,12 +93,12 @@
<!-- Properties: extra source properties -->
<property name='Properties' type='a{sv}' access='read' />
<!-- state: state of the source
0 = the source is in error
-1 = the source is in error
0 = the source is suspended, this means the device is closed
1 = the source is initializing
2 = the source is suspended, this means the device is closed
3 = the source is idle, this means the device is opened but
2 = the source is idle, this means the device is opened but
no source-output is consuming the data
4 = the source is running
3 = the source is running
-->
<property name='State' type='u' access='read' />
<!-- PossibleFormats:
@ -128,6 +128,17 @@
<!-- Properties: extra source output properties -->
<property name='Properties' type='a{sv}' access='read' />
<!-- state: state of the source output
-1 = the source output is in error
0 = the source output is idle
1 = the source output is starting
2 = the source output is streaming
-->
<property name='State' type='u' access='read' />
<!-- Format: the current streaming format -->
<property name='Format' type='s' access='read' />
<!-- Start:
@requested_format: requested formats
@fd: output file descriptor

View file

@ -41,6 +41,7 @@ struct _PinosSourceOutputPrivate
GBytes *possible_formats;
PinosProperties *properties;
GBytes *requested_format;
PinosSourceOutputState state;
GBytes *format;
GSocket *socket;
@ -63,6 +64,7 @@ enum
PROP_REQUESTED_FORMAT,
PROP_FORMAT,
PROP_SOCKET,
PROP_STATE,
};
enum
@ -119,6 +121,10 @@ pinos_source_output_get_property (GObject *_object,
g_value_set_object (value, priv->socket);
break;
case PROP_STATE:
g_value_set_uint (value, priv->state);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (output, prop_id, pspec);
break;
@ -192,6 +198,8 @@ handle_start (PinosSourceOutput1 *interface,
GUnixFDList *fdlist;
gint fd[2];
priv->state = PINOS_SOURCE_OUTPUT_STATE_STARTING;
priv->requested_format = g_bytes_new (arg_requested_format, strlen (arg_requested_format) + 1);
socketpair (AF_UNIX, SOCK_STREAM, 0, fd);
@ -201,6 +209,8 @@ handle_start (PinosSourceOutput1 *interface,
if (priv->format == NULL)
goto no_format;
priv->state = PINOS_SOURCE_OUTPUT_STATE_STREAMING;
fdlist = g_unix_fd_list_new ();
g_unix_fd_list_append (fdlist, fd[1], NULL);
@ -210,6 +220,11 @@ handle_start (PinosSourceOutput1 *interface,
g_bytes_get_data (priv->format, NULL)),
fdlist);
g_object_set (priv->iface,
"format", g_bytes_get_data (priv->format, NULL),
"state", priv->state,
NULL);
return TRUE;
/* error */
@ -245,6 +260,10 @@ stop_transfer (PinosSourceOutput *output)
clear_socket (output);
g_object_notify (G_OBJECT (output), "socket");
}
priv->state = PINOS_SOURCE_OUTPUT_STATE_IDLE;
g_object_set (priv->iface,
"state", priv->state,
NULL);
}
static gboolean
@ -461,6 +480,9 @@ pinos_source_output_init (PinosSourceOutput * output)
g_signal_connect (priv->iface, "handle-start", (GCallback) handle_start, output);
g_signal_connect (priv->iface, "handle-stop", (GCallback) handle_stop, output);
g_signal_connect (priv->iface, "handle-remove", (GCallback) handle_remove, output);
priv->state = PINOS_SOURCE_OUTPUT_STATE_IDLE;
g_object_set (priv->iface, "state", priv->state, NULL);
}
void

View file

@ -34,12 +34,12 @@ print_field (GQuark field, const GValue * value, gpointer user_data)
}
static void
print_formats (GBytes *formats)
print_formats (const gchar *name, GBytes *formats)
{
GstCaps *caps = gst_caps_from_string (g_bytes_get_data (formats, NULL));
guint i;
g_print ("\tformats:\n");
g_print ("\t%s:\n", name);
if (gst_caps_is_any (caps)) {
g_print ("\t\tANY\n");
@ -120,7 +120,7 @@ dump_source_info (PinosContext *c, const PinosSourceInfo *info, gpointer userdat
g_print ("\tsource-path: \"%s\"\n", info->source_path);
g_print ("\tname: \"%s\"\n", info->name);
g_print ("\tstate: %d\n", info->state);
print_formats (info->formats);
print_formats ("formats", info->formats);
print_properties (info->properties);
return TRUE;
@ -135,7 +135,9 @@ dump_source_output_info (PinosContext *c, const PinosSourceOutputInfo *info, gpo
g_print ("\tid: %p\n", info->id);
g_print ("\tclient-path: \"%s\"\n", info->client_path);
g_print ("\tsource-path: \"%s\"\n", info->source_path);
print_formats (info->possible_formats);
print_formats ("possible-formats", info->possible_formats);
g_print ("\tstate: \"%d\"\n", info->state);
print_formats ("format", info->format);
print_properties (info->properties);
return TRUE;