source-output -> channel

Rename the source-output object to channel because it is used for both
input and output.
Start the beginnings of sink support. This will make it possible to make
pinos consume data as well as provide data.
This commit is contained in:
Wim Taymans 2016-05-03 18:00:56 +02:00
parent 76afc1e330
commit 7597e48e02
23 changed files with 954 additions and 633 deletions

View file

@ -44,7 +44,7 @@ struct _PinosSourcePrivate
GError *error;
guint idle_timeout;
GList *outputs;
GList *channels;
};
G_DEFINE_ABSTRACT_TYPE (PinosSource, pinos_source, G_TYPE_OBJECT);
@ -191,10 +191,10 @@ pinos_source_constructed (GObject * object)
}
static void
do_remove_output (PinosSourceOutput *output,
gpointer user_data)
do_remove_channel (PinosChannel *channel,
gpointer user_data)
{
pinos_source_output_remove (output);
pinos_channel_remove (channel);
}
static void
@ -203,7 +203,7 @@ pinos_source_dispose (GObject * object)
PinosSource *source = PINOS_SOURCE (object);
PinosSourcePrivate *priv = source->priv;
g_list_foreach (priv->outputs, (GFunc) do_remove_output, source);
g_list_foreach (priv->channels, (GFunc) do_remove_channel, source);
source_unregister_object (source);
G_OBJECT_CLASS (pinos_source_parent_class)->dispose (object);
@ -232,75 +232,75 @@ default_set_state (PinosSource *source,
}
static void
handle_remove_output (PinosSourceOutput *output,
gpointer user_data)
handle_remove_channel (PinosChannel *channel,
gpointer user_data)
{
PinosSource *source = user_data;
pinos_source_release_source_output (source, output);
pinos_source_release_channel (source, channel);
}
static PinosSourceOutput *
default_create_source_output (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
static PinosChannel *
default_create_channel (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
{
PinosSourcePrivate *priv = source->priv;
PinosSourceOutput *output;
PinosChannel *channel;
GBytes *possible_formats;
possible_formats = pinos_source_get_formats (source, format_filter, error);
if (possible_formats == NULL)
return NULL;
output = g_object_new (PINOS_TYPE_SOURCE_OUTPUT, "daemon", priv->daemon,
"object-path", prefix,
"client-path", client_path,
"source-path", priv->object_path,
"possible-formats", possible_formats,
"properties", props,
NULL);
channel = g_object_new (PINOS_TYPE_CHANNEL, "daemon", priv->daemon,
"object-path", prefix,
"client-path", client_path,
"owner-path", priv->object_path,
"possible-formats", possible_formats,
"properties", props,
NULL);
g_bytes_unref (possible_formats);
if (output == NULL)
goto no_output;
if (channel == NULL)
goto no_channel;
g_signal_connect (output,
g_signal_connect (channel,
"remove",
(GCallback) handle_remove_output,
(GCallback) handle_remove_channel,
source);
priv->outputs = g_list_prepend (priv->outputs, output);
priv->channels = g_list_prepend (priv->channels, channel);
return g_object_ref (output);
return g_object_ref (channel);
/* ERRORS */
no_output:
no_channel:
{
if (error)
*error = g_error_new (G_IO_ERROR,
G_IO_ERROR_FAILED,
"Could not create a source output");
"Could not create channel");
return NULL;
}
}
static gboolean
default_release_source_output (PinosSource *source,
PinosSourceOutput *output)
default_release_channel (PinosSource *source,
PinosChannel *channel)
{
PinosSourcePrivate *priv = source->priv;
GList *find;
find = g_list_find (priv->outputs, output);
find = g_list_find (priv->channels, channel);
if (find == NULL)
return FALSE;
priv->outputs = g_list_delete_link (priv->outputs, find);
g_object_unref (output);
priv->channels = g_list_delete_link (priv->channels, find);
g_object_unref (channel);
return TRUE;
}
@ -370,8 +370,8 @@ pinos_source_class_init (PinosSourceClass * klass)
klass->set_state = default_set_state;
klass->create_source_output = default_create_source_output;
klass->release_source_output = default_release_source_output;
klass->create_channel = default_create_channel;
klass->release_channel = default_release_channel;
}
static void
@ -562,7 +562,7 @@ pinos_source_report_busy (PinosSource *source)
* @formats: a #GBytes
*
* Update the possible formats in @source to @formats. This function also
* updates the possible formats of the outputs.
* updates the possible formats of the channels.
*/
void
pinos_source_update_possible_formats (PinosSource *source, GBytes *formats)
@ -578,7 +578,7 @@ pinos_source_update_possible_formats (PinosSource *source, GBytes *formats)
g_bytes_get_data (formats, NULL),
NULL);
for (walk = priv->outputs; walk; walk = g_list_next (walk))
for (walk = priv->channels; walk; walk = g_list_next (walk))
g_object_set (walk->data, "possible-formats", formats, NULL);
}
@ -588,7 +588,7 @@ pinos_source_update_possible_formats (PinosSource *source, GBytes *formats)
* @format: a #GBytes
*
* Update the current format in @source to @format. This function also
* updates the current format of the outputs.
* updates the current format of the channels.
*/
void
pinos_source_update_format (PinosSource *source, GBytes *format)
@ -599,12 +599,12 @@ pinos_source_update_format (PinosSource *source, GBytes *format)
g_return_if_fail (PINOS_IS_SOURCE (source));
priv = source->priv;
for (walk = priv->outputs; walk; walk = g_list_next (walk))
for (walk = priv->channels; walk; walk = g_list_next (walk))
g_object_set (walk->data, "format", format, NULL);
}
/**
* pinos_source_create_source_output:
* pinos_source_create_channel:
* @source: a #PinosSource
* @client_path: the client path
* @format_filter: a #GBytes
@ -612,33 +612,33 @@ pinos_source_update_format (PinosSource *source, GBytes *format)
* @prefix: a prefix
* @error: a #GError or %NULL
*
* Create a new #PinosSourceOutput for @source.
* Create a new #PinosChannel for @source.
*
* Returns: a new #PinosSourceOutput or %NULL, in wich case @error will contain
* Returns: a new #PinosChannel or %NULL, in wich case @error will contain
* more information about the error.
*/
PinosSourceOutput *
pinos_source_create_source_output (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
PinosChannel *
pinos_source_create_channel (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
{
PinosSourceClass *klass;
PinosSourceOutput *res;
PinosChannel *res;
g_return_val_if_fail (PINOS_IS_SOURCE (source), NULL);
klass = PINOS_SOURCE_GET_CLASS (source);
if (klass->create_source_output) {
res = klass->create_source_output (source, client_path, format_filter, props, prefix, error);
if (klass->create_channel) {
res = klass->create_channel (source, client_path, format_filter, props, prefix, error);
} else {
if (error) {
*error = g_error_new (G_IO_ERROR,
G_IO_ERROR_NOT_SUPPORTED,
"Create SourceOutput not implemented");
"CreateChannel not implemented");
}
res = NULL;
}
@ -647,28 +647,28 @@ pinos_source_create_source_output (PinosSource *source,
}
/**
* pinos_source_release_source_output:
* pinos_source_release_channel:
* @source: a #PinosSource
* @output: a #PinosSourceOutput
* @channel: a #PinosChannel
*
* Release the @output in @source.
* Release the @channel in @source.
*
* Returns: %TRUE on success.
*/
gboolean
pinos_source_release_source_output (PinosSource *source,
PinosSourceOutput *output)
pinos_source_release_channel (PinosSource *source,
PinosChannel *channel)
{
PinosSourceClass *klass;
gboolean res;
g_return_val_if_fail (PINOS_IS_SOURCE (source), FALSE);
g_return_val_if_fail (PINOS_IS_SOURCE_OUTPUT (output), FALSE);
g_return_val_if_fail (PINOS_IS_CHANNEL (channel), FALSE);
klass = PINOS_SOURCE_GET_CLASS (source);
if (klass->release_source_output)
res = klass->release_source_output (source, output);
if (klass->release_channel)
res = klass->release_channel (source, channel);
else
res = FALSE;