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

@ -25,32 +25,32 @@
#include "pinos/client/enumtypes.h"
#include "pinos/server/daemon.h"
#include "pinos/server/source-output.h"
#include "pinos/server/channel.h"
#include "pinos/dbus/org-pinos.h"
struct _PinosSourceOutputPrivate
struct _PinosChannelPrivate
{
PinosDaemon *daemon;
PinosSourceOutput1 *iface;
PinosChannel1 *iface;
gchar *object_path;
gchar *client_path;
gchar *source_path;
gchar *owner_path;
GBytes *possible_formats;
PinosProperties *properties;
GBytes *requested_format;
PinosSourceOutputState state;
PinosChannelState state;
GBytes *format;
GSocket *socket;
};
#define PINOS_SOURCE_OUTPUT_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_SOURCE_OUTPUT, PinosSourceOutputPrivate))
#define PINOS_CHANNEL_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_CHANNEL, PinosChannelPrivate))
G_DEFINE_TYPE (PinosSourceOutput, pinos_source_output, G_TYPE_OBJECT);
G_DEFINE_TYPE (PinosChannel, pinos_channel, G_TYPE_OBJECT);
enum
{
@ -58,7 +58,7 @@ enum
PROP_DAEMON,
PROP_OBJECT_PATH,
PROP_CLIENT_PATH,
PROP_SOURCE_PATH,
PROP_OWNER_PATH,
PROP_POSSIBLE_FORMATS,
PROP_PROPERTIES,
PROP_REQUESTED_FORMAT,
@ -76,13 +76,13 @@ enum
static guint signals[LAST_SIGNAL] = { 0 };
static void
pinos_source_output_get_property (GObject *_object,
pinos_channel_get_property (GObject *_object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
PinosSourceOutput *output = PINOS_SOURCE_OUTPUT (_object);
PinosSourceOutputPrivate *priv = output->priv;
PinosChannel *channel = PINOS_CHANNEL (_object);
PinosChannelPrivate *priv = channel->priv;
switch (prop_id) {
case PROP_DAEMON:
@ -97,8 +97,8 @@ pinos_source_output_get_property (GObject *_object,
g_value_set_string (value, priv->client_path);
break;
case PROP_SOURCE_PATH:
g_value_set_string (value, priv->source_path);
case PROP_OWNER_PATH:
g_value_set_string (value, priv->owner_path);
break;
case PROP_POSSIBLE_FORMATS:
@ -126,19 +126,19 @@ pinos_source_output_get_property (GObject *_object,
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (output, prop_id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (channel, prop_id, pspec);
break;
}
}
static void
pinos_source_output_set_property (GObject *_object,
pinos_channel_set_property (GObject *_object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
PinosSourceOutput *output = PINOS_SOURCE_OUTPUT (_object);
PinosSourceOutputPrivate *priv = output->priv;
PinosChannel *channel = PINOS_CHANNEL (_object);
PinosChannelPrivate *priv = channel->priv;
switch (prop_id) {
case PROP_DAEMON:
@ -154,9 +154,9 @@ pinos_source_output_set_property (GObject *_object,
g_object_set (priv->iface, "client", priv->client_path, NULL);
break;
case PROP_SOURCE_PATH:
priv->source_path = g_value_dup_string (value);
g_object_set (priv->iface, "source", priv->source_path, NULL);
case PROP_OWNER_PATH:
priv->owner_path = g_value_dup_string (value);
g_object_set (priv->iface, "owner", priv->owner_path, NULL);
break;
case PROP_POSSIBLE_FORMATS:
@ -184,67 +184,67 @@ pinos_source_output_set_property (GObject *_object,
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (output, prop_id, pspec);
G_OBJECT_WARN_INVALID_PROPERTY_ID (channel, prop_id, pspec);
break;
}
}
static void
clear_formats (PinosSourceOutput *output)
clear_formats (PinosChannel *channel)
{
PinosSourceOutputPrivate *priv = output->priv;
PinosChannelPrivate *priv = channel->priv;
g_debug ("source-output %p: clear format", output);
g_debug ("channel %p: clear format", channel);
g_clear_pointer (&priv->requested_format, g_bytes_unref);
g_clear_pointer (&priv->format, g_bytes_unref);
}
static void
stop_transfer (PinosSourceOutput *output)
stop_transfer (PinosChannel *channel)
{
PinosSourceOutputPrivate *priv = output->priv;
PinosChannelPrivate *priv = channel->priv;
g_debug ("source-output %p: stop transfer", output);
g_debug ("channel %p: stop transfer", channel);
if (priv->socket) {
g_clear_object (&priv->socket);
g_object_notify (G_OBJECT (output), "socket");
g_object_notify (G_OBJECT (channel), "socket");
}
clear_formats (output);
priv->state = PINOS_SOURCE_OUTPUT_STATE_IDLE;
clear_formats (channel);
priv->state = PINOS_CHANNEL_STATE_IDLE;
g_object_set (priv->iface,
"state", priv->state,
NULL);
}
static gboolean
handle_start (PinosSourceOutput1 *interface,
handle_start (PinosChannel1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_requested_format,
gpointer user_data)
{
PinosSourceOutput *output = user_data;
PinosSourceOutputPrivate *priv = output->priv;
PinosChannel *channel = user_data;
PinosChannelPrivate *priv = channel->priv;
GUnixFDList *fdlist;
gint fd[2];
const gchar *format;
priv->state = PINOS_SOURCE_OUTPUT_STATE_STARTING;
priv->state = PINOS_CHANNEL_STATE_STARTING;
priv->requested_format = g_bytes_new (arg_requested_format,
strlen (arg_requested_format) + 1);
socketpair (AF_UNIX, SOCK_STREAM, 0, fd);
g_debug ("source-output %p: handle start, fd[%d,%d]", output, fd[0], fd[1]);
g_debug ("channel %p: handle start, fd[%d,%d]", channel, fd[0], fd[1]);
g_clear_object (&priv->socket);
priv->socket = g_socket_new_from_fd (fd[0], NULL);
g_object_set_data (G_OBJECT (priv->socket), "pinos-client-path", priv->client_path);
g_debug ("source-output %p: notify socket %p, path %s", output, priv->socket, priv->client_path);
g_object_notify (G_OBJECT (output), "socket");
g_debug ("channel %p: notify socket %p, path %s", channel, priv->socket, priv->client_path);
g_object_notify (G_OBJECT (channel), "socket");
/* the notify of the socket above should configure the format */
if (priv->format == NULL)
@ -252,8 +252,8 @@ handle_start (PinosSourceOutput1 *interface,
format = g_bytes_get_data (priv->format, NULL);
priv->state = PINOS_SOURCE_OUTPUT_STATE_STREAMING;
g_debug ("source-output %p: we are now streaming in format \"%s\"", output, format);
priv->state = PINOS_CHANNEL_STATE_STREAMING;
g_debug ("channel %p: we are now streaming in format \"%s\"", channel, format);
fdlist = g_unix_fd_list_new ();
g_unix_fd_list_append (fdlist, fd[1], NULL);
@ -277,7 +277,7 @@ handle_start (PinosSourceOutput1 *interface,
/* error */
no_format:
{
g_debug ("source-output %p: no format configured", output);
g_debug ("channel %p: no format configured", channel);
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pinos.Error", "No format");
close (fd[0]);
@ -289,14 +289,14 @@ no_format:
}
static gboolean
handle_stop (PinosSourceOutput1 *interface,
handle_stop (PinosChannel1 *interface,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
PinosSourceOutput *output = user_data;
PinosChannel *channel = user_data;
g_debug ("source-output %p: handle stop", output);
stop_transfer (output);
g_debug ("channel %p: handle stop", channel);
stop_transfer (channel);
g_dbus_method_invocation_return_value (invocation, NULL);
@ -304,16 +304,16 @@ handle_stop (PinosSourceOutput1 *interface,
}
static gboolean
handle_remove (PinosSourceOutput1 *interface,
handle_remove (PinosChannel1 *interface,
GDBusMethodInvocation *invocation,
gpointer user_data)
{
PinosSourceOutput *output = user_data;
PinosChannel *channel = user_data;
g_debug ("source-output %p: handle remove", output);
stop_transfer (output);
g_debug ("channel %p: handle remove", channel);
stop_transfer (channel);
g_signal_emit (output, signals[SIGNAL_REMOVE], 0, NULL);
g_signal_emit (channel, signals[SIGNAL_REMOVE], 0, NULL);
g_dbus_method_invocation_return_value (invocation, NULL);
@ -321,54 +321,54 @@ handle_remove (PinosSourceOutput1 *interface,
}
static void
output_register_object (PinosSourceOutput *output,
channel_register_object (PinosChannel *channel,
const gchar *prefix)
{
PinosSourceOutputPrivate *priv = output->priv;
PinosChannelPrivate *priv = channel->priv;
PinosObjectSkeleton *skel;
gchar *name;
name = g_strdup_printf ("%s/output", prefix);
name = g_strdup_printf ("%s/channel", prefix);
skel = pinos_object_skeleton_new (name);
g_free (name);
pinos_object_skeleton_set_source_output1 (skel, priv->iface);
pinos_object_skeleton_set_channel1 (skel, priv->iface);
g_free (priv->object_path);
priv->object_path = pinos_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
g_debug ("source-output %p: register object %s", output, priv->object_path);
g_debug ("channel %p: register object %s", channel, priv->object_path);
}
static void
output_unregister_object (PinosSourceOutput *output)
channel_unregister_object (PinosChannel *channel)
{
PinosSourceOutputPrivate *priv = output->priv;
PinosChannelPrivate *priv = channel->priv;
g_debug ("source-output %p: unregister object", output);
g_debug ("channel %p: unregister object", channel);
pinos_daemon_unexport (priv->daemon, priv->object_path);
}
static void
pinos_source_output_dispose (GObject * object)
pinos_channel_dispose (GObject * object)
{
PinosSourceOutput *output = PINOS_SOURCE_OUTPUT (object);
PinosSourceOutputPrivate *priv = output->priv;
PinosChannel *channel = PINOS_CHANNEL (object);
PinosChannelPrivate *priv = channel->priv;
g_debug ("source-output %p: dispose", output);
clear_formats (output);
g_debug ("channel %p: dispose", channel);
clear_formats (channel);
g_clear_object (&priv->socket);
output_unregister_object (output);
channel_unregister_object (channel);
G_OBJECT_CLASS (pinos_source_output_parent_class)->dispose (object);
G_OBJECT_CLASS (pinos_channel_parent_class)->dispose (object);
}
static void
pinos_source_output_finalize (GObject * object)
pinos_channel_finalize (GObject * object)
{
PinosSourceOutput *output = PINOS_SOURCE_OUTPUT (object);
PinosSourceOutputPrivate *priv = output->priv;
PinosChannel *channel = PINOS_CHANNEL (object);
PinosChannelPrivate *priv = channel->priv;
g_debug ("source-output %p: finalize", output);
g_debug ("channel %p: finalize", channel);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
if (priv->properties)
@ -377,35 +377,35 @@ pinos_source_output_finalize (GObject * object)
g_clear_object (&priv->iface);
g_free (priv->client_path);
g_free (priv->object_path);
g_free (priv->source_path);
g_free (priv->owner_path);
G_OBJECT_CLASS (pinos_source_output_parent_class)->finalize (object);
G_OBJECT_CLASS (pinos_channel_parent_class)->finalize (object);
}
static void
pinos_source_output_constructed (GObject * object)
pinos_channel_constructed (GObject * object)
{
PinosSourceOutput *output = PINOS_SOURCE_OUTPUT (object);
PinosSourceOutputPrivate *priv = output->priv;
PinosChannel *channel = PINOS_CHANNEL (object);
PinosChannelPrivate *priv = channel->priv;
g_debug ("source-output %p: constructed", output);
output_register_object (output, priv->object_path);
g_debug ("channel %p: constructed", channel);
channel_register_object (channel, priv->object_path);
G_OBJECT_CLASS (pinos_source_output_parent_class)->constructed (object);
G_OBJECT_CLASS (pinos_channel_parent_class)->constructed (object);
}
static void
pinos_source_output_class_init (PinosSourceOutputClass * klass)
pinos_channel_class_init (PinosChannelClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (klass, sizeof (PinosSourceOutputPrivate));
g_type_class_add_private (klass, sizeof (PinosChannelPrivate));
gobject_class->constructed = pinos_source_output_constructed;
gobject_class->dispose = pinos_source_output_dispose;
gobject_class->finalize = pinos_source_output_finalize;
gobject_class->set_property = pinos_source_output_set_property;
gobject_class->get_property = pinos_source_output_get_property;
gobject_class->constructed = pinos_channel_constructed;
gobject_class->dispose = pinos_channel_dispose;
gobject_class->finalize = pinos_channel_finalize;
gobject_class->set_property = pinos_channel_set_property;
gobject_class->get_property = pinos_channel_get_property;
g_object_class_install_property (gobject_class,
PROP_DAEMON,
@ -438,10 +438,10 @@ pinos_source_output_class_init (PinosSourceOutputClass * klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SOURCE_PATH,
g_param_spec_string ("source-path",
"Source Path",
"The source object path",
PROP_OWNER_PATH,
g_param_spec_string ("owner-path",
"Owner Path",
"The owner object path",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
@ -507,52 +507,52 @@ pinos_source_output_class_init (PinosSourceOutputClass * klass)
}
static void
pinos_source_output_init (PinosSourceOutput * output)
pinos_channel_init (PinosChannel * channel)
{
PinosSourceOutputPrivate *priv = output->priv = PINOS_SOURCE_OUTPUT_GET_PRIVATE (output);
PinosChannelPrivate *priv = channel->priv = PINOS_CHANNEL_GET_PRIVATE (channel);
priv->iface = pinos_source_output1_skeleton_new ();
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->iface = pinos_channel1_skeleton_new ();
g_signal_connect (priv->iface, "handle-start", (GCallback) handle_start, channel);
g_signal_connect (priv->iface, "handle-stop", (GCallback) handle_stop, channel);
g_signal_connect (priv->iface, "handle-remove", (GCallback) handle_remove, channel);
priv->state = PINOS_SOURCE_OUTPUT_STATE_IDLE;
priv->state = PINOS_CHANNEL_STATE_IDLE;
g_object_set (priv->iface, "state", priv->state, NULL);
g_debug ("source-output %p: new", output);
g_debug ("channel %p: new", channel);
}
/**
* pinos_source_output_remove:
* @output: a #PinosSourceOutput
* pinos_channel_remove:
* @channel: a #PinosChannel
*
* Remove @output. This will stop the transfer on the output and
* free the resources allocated by @output.
* Remove @channel. This will stop the transfer on the channel and
* free the resources allocated by @channel.
*/
void
pinos_source_output_remove (PinosSourceOutput *output)
pinos_channel_remove (PinosChannel *channel)
{
g_debug ("source-output %p: remove", output);
stop_transfer (output);
g_debug ("channel %p: remove", channel);
stop_transfer (channel);
g_signal_emit (output, signals[SIGNAL_REMOVE], 0, NULL);
g_signal_emit (channel, signals[SIGNAL_REMOVE], 0, NULL);
}
/**
* pinos_source_output_get_object_path:
* @output: a #PinosSourceOutput
* pinos_channel_get_object_path:
* @channel: a #PinosChannel
*
* Get the object patch of @output
* Get the object patch of @channel
*
* Returns: the object path of @source.
*/
const gchar *
pinos_source_output_get_object_path (PinosSourceOutput *output)
pinos_channel_get_object_path (PinosChannel *channel)
{
PinosSourceOutputPrivate *priv;
PinosChannelPrivate *priv;
g_return_val_if_fail (PINOS_IS_SOURCE_OUTPUT (output), NULL);
priv = output->priv;
g_return_val_if_fail (PINOS_IS_CHANNEL (channel), NULL);
priv = channel->priv;
return priv->object_path;
}

69
pinos/server/channel.h Normal file
View file

@ -0,0 +1,69 @@
/* Pinos
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PINOS_CHANNEL_H__
#define __PINOS_CHANNEL_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define PINOS_TYPE_CHANNEL (pinos_channel_get_type ())
#define PINOS_IS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_CHANNEL))
#define PINOS_IS_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_CHANNEL))
#define PINOS_CHANNEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_CHANNEL, PinosChannelClass))
#define PINOS_CHANNEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_CHANNEL, PinosChannel))
#define PINOS_CHANNEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_CHANNEL, PinosChannelClass))
#define PINOS_CHANNEL_CAST(obj) ((PinosChannel*)(obj))
#define PINOS_CHANNEL_CLASS_CAST(klass) ((PinosChannelClass*)(klass))
typedef struct _PinosChannel PinosChannel;
typedef struct _PinosChannelClass PinosChannelClass;
typedef struct _PinosChannelPrivate PinosChannelPrivate;
/**
* PinosChannel:
*
* Pinos source channel object class.
*/
struct _PinosChannel {
GObject object;
PinosChannelPrivate *priv;
};
/**
* PinosChannelClass:
*
* Pinos source channel object class.
*/
struct _PinosChannelClass {
GObjectClass parent_class;
};
/* normal GObject stuff */
GType pinos_channel_get_type (void);
void pinos_channel_remove (PinosChannel *channel);
const gchar * pinos_channel_get_object_path (PinosChannel *channel);
G_END_DECLS
#endif /* __PINOS_CHANNEL_H__ */

View file

@ -37,7 +37,7 @@ struct _PinosClientSourcePrivate
GstCaps *format;
GBytes *possible_formats;
PinosSourceOutput *input;
PinosChannel *channel;
};
G_DEFINE_TYPE (PinosClientSource, pinos_client_source, PINOS_TYPE_SOURCE);
@ -128,7 +128,7 @@ bus_handler (GstBus *bus,
caps_str = gst_caps_to_string (caps);
format = g_bytes_new_take (caps_str, strlen (caps_str) + 1);
g_object_set (priv->input, "possible-formats", format, "format", format, NULL);
g_object_set (priv->channel, "possible-formats", format, "format", format, NULL);
pinos_source_update_possible_formats (source, format);
pinos_source_update_format (source, format);
g_bytes_unref (format);
@ -286,51 +286,51 @@ on_socket_notify (GObject *gobject,
GBytes *format;
/* suggest what we provide */
g_object_get (priv->input, "format", &format, NULL);
g_object_get (priv->channel, "format", &format, NULL);
g_object_set (gobject, "format", format, NULL);
g_bytes_unref (format);
}
}
static PinosSourceOutput *
client_create_source_output (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
static PinosChannel *
client_create_channel (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
{
PinosClientSourcePrivate *priv = PINOS_CLIENT_SOURCE (source)->priv;
PinosSourceOutput *output;
PinosChannel *channel;
/* propose format of input */
g_object_get (priv->input, "format", &format_filter, NULL);
g_object_get (priv->channel, "format", &format_filter, NULL);
output = PINOS_SOURCE_CLASS (pinos_client_source_parent_class)
->create_source_output (source,
client_path,
format_filter,
props,
prefix,
error);
channel = PINOS_SOURCE_CLASS (pinos_client_source_parent_class)
->create_channel (source,
client_path,
format_filter,
props,
prefix,
error);
g_bytes_unref (format_filter);
if (output == NULL)
if (channel == NULL)
return NULL;
g_debug ("client-source %p: create output %p", source, output);
g_debug ("client-source %p: create channel %p", source, channel);
g_signal_connect (output, "notify::socket", (GCallback) on_socket_notify, source);
g_signal_connect (channel, "notify::socket", (GCallback) on_socket_notify, source);
return output;
return channel;
}
static gboolean
client_release_source_output (PinosSource *source,
PinosSourceOutput *output)
client_release_channel (PinosSource *source,
PinosChannel *channel)
{
g_debug ("client-source %p: release output %p", source, output);
return PINOS_SOURCE_CLASS (pinos_client_source_parent_class)->release_source_output (source, output);
g_debug ("client-source %p: release channel %p", source, channel);
return PINOS_SOURCE_CLASS (pinos_client_source_parent_class)->release_channel (source, channel);
}
static void
@ -353,7 +353,7 @@ client_source_finalize (GObject * object)
g_debug ("client-source %p: finalize", object);
g_clear_object (&priv->input);
g_clear_object (&priv->channel);
g_clear_object (&priv->sink);
g_clear_object (&priv->src);
g_clear_object (&priv->pipeline);
@ -407,18 +407,18 @@ on_input_socket_notify (GObject *gobject,
}
static void
handle_remove_source_input (PinosSourceOutput *output,
gpointer user_data)
handle_remove_channel (PinosChannel *channel,
gpointer user_data)
{
PinosClientSource *source = user_data;
PinosClientSourcePrivate *priv = source->priv;
g_debug ("client-source %p: remove source input %p", source, priv->input);
g_clear_pointer (&priv->input, g_object_unref);
g_debug ("client-source %p: remove channel %p", source, priv->channel);
g_clear_pointer (&priv->channel, g_object_unref);
}
/**
* pinos_client_source_get_source_input:
* pinos_client_source_get_channel:
* @source: a #PinosClientSource
* @client_path: the client path
* @format_filter: a #GBytes
@ -426,48 +426,48 @@ handle_remove_source_input (PinosSourceOutput *output,
* @prefix: a path prefix
* @error: a #GError or %NULL
*
* Create a new #PinosSourceOutput that can be used to send data to
* Create a new #PinosChannel that can be used to send data to
* the pinos server.
*
* Returns: a new #PinosSourceOutput.
* Returns: a new #PinosChannel.
*/
PinosSourceOutput *
pinos_client_source_get_source_input (PinosClientSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
PinosChannel *
pinos_client_source_get_channel (PinosClientSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error)
{
PinosClientSourcePrivate *priv;
g_return_val_if_fail (PINOS_IS_CLIENT_SOURCE (source), NULL);
priv = source->priv;
if (priv->input == NULL) {
if (priv->channel == NULL) {
GstCaps *caps = gst_caps_from_string (g_bytes_get_data (format_filter, NULL));
gst_caps_take (&priv->format, caps);
priv->input = PINOS_SOURCE_CLASS (pinos_client_source_parent_class)
->create_source_output (PINOS_SOURCE (source),
client_path,
format_filter,
props,
prefix,
error);
if (priv->input == NULL)
priv->channel = PINOS_SOURCE_CLASS (pinos_client_source_parent_class)
->create_channel (PINOS_SOURCE (source),
client_path,
format_filter,
props,
prefix,
error);
if (priv->channel == NULL)
return NULL;
g_signal_connect (priv->input,
g_signal_connect (priv->channel,
"remove",
(GCallback) handle_remove_source_input,
(GCallback) handle_remove_channel,
source);
g_debug ("client-source %p: get source input %p", source, priv->input);
g_signal_connect (priv->input, "notify::socket", (GCallback) on_input_socket_notify, source);
g_debug ("client-source %p: get source input %p", source, priv->channel);
g_signal_connect (priv->channel, "notify::socket", (GCallback) on_input_socket_notify, source);
}
return g_object_ref (priv->input);
return g_object_ref (priv->channel);
}
static void
@ -496,8 +496,8 @@ pinos_client_source_class_init (PinosClientSourceClass * klass)
source_class->get_formats = client_get_formats;
source_class->set_state = client_set_state;
source_class->create_source_output = client_create_source_output;
source_class->release_source_output = client_release_source_output;
source_class->create_channel = client_create_channel;
source_class->release_channel = client_release_channel;
}
static void

View file

@ -65,7 +65,7 @@ GType pinos_client_source_get_type (void);
PinosSource * pinos_client_source_new (PinosDaemon *daemon,
GBytes *possible_formats);
PinosSourceOutput * pinos_client_source_get_source_input (PinosClientSource *source,
PinosChannel * pinos_client_source_get_channel (PinosClientSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,

View file

@ -35,7 +35,7 @@ struct _PinosClientPrivate
PinosClient1 *client1;
PinosFdManager *fdmanager;
GList *outputs;
GList *channels;
};
#define PINOS_CLIENT_GET_PRIVATE(obj) \
@ -127,29 +127,29 @@ pinos_client_set_property (GObject *_object,
}
static void
handle_remove_source_output (PinosSourceOutput *output,
gpointer user_data)
handle_remove_channel (PinosChannel *channel,
gpointer user_data)
{
PinosClient *client = user_data;
PinosClientPrivate *priv = client->priv;
g_debug ("client %p: remove source output %p", client, output);
priv->outputs = g_list_remove (priv->outputs, output);
g_object_unref (output);
g_debug ("client %p: remove channel %p", client, channel);
priv->channels = g_list_remove (priv->channels, channel);
g_object_unref (channel);
}
static gboolean
handle_create_source_output (PinosClient1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_source,
const gchar *arg_accepted_formats,
GVariant *arg_properties,
gpointer user_data)
handle_create_source_channel (PinosClient1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_source,
const gchar *arg_accepted_formats,
GVariant *arg_properties,
gpointer user_data)
{
PinosClient *client = user_data;
PinosClientPrivate *priv = client->priv;
PinosSource *source;
PinosSourceOutput *output;
PinosChannel *channel;
const gchar *object_path, *sender;
GBytes *formats;
PinosProperties *props;
@ -170,27 +170,27 @@ handle_create_source_output (PinosClient1 *interface,
if (source == NULL)
goto no_source;
output = pinos_source_create_source_output (source,
priv->object_path,
formats,
props,
priv->object_path,
&error);
channel = pinos_source_create_channel (source,
priv->object_path,
formats,
props,
priv->object_path,
&error);
pinos_properties_free (props);
g_bytes_unref (formats);
if (output == NULL)
goto no_output;
if (channel == NULL)
goto no_channel;
priv->outputs = g_list_prepend (priv->outputs, output);
priv->channels = g_list_prepend (priv->channels, channel);
g_signal_connect (output,
g_signal_connect (channel,
"remove",
(GCallback) handle_remove_source_output,
(GCallback) handle_remove_channel,
client);
object_path = pinos_source_output_get_object_path (output);
g_debug ("client %p: add source output %p, %s", client, output, object_path);
object_path = pinos_channel_get_object_path (channel);
g_debug ("client %p: add channel %p, %s", client, channel, object_path);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)", object_path));
@ -212,9 +212,9 @@ no_source:
g_clear_error (&error);
return TRUE;
}
no_output:
no_channel:
{
g_debug ("client %p: could not create output %s", client, error->message);
g_debug ("client %p: could not channel %s", client, error->message);
g_dbus_method_invocation_return_gerror (invocation, error);
g_clear_error (&error);
return TRUE;
@ -222,17 +222,17 @@ no_output:
}
static gboolean
handle_create_source_input (PinosClient1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_possible_formats,
GVariant *arg_properties,
gpointer user_data)
handle_create_upload_channel (PinosClient1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_possible_formats,
GVariant *arg_properties,
gpointer user_data)
{
PinosClient *client = user_data;
PinosClientPrivate *priv = client->priv;
PinosSource *source;
PinosSourceOutput *input;
const gchar *source_input_path, *sender;
PinosChannel *channel;
const gchar *channel_path, *sender;
GBytes *formats;
GError *error = NULL;
PinosProperties *props;
@ -250,34 +250,34 @@ handle_create_source_input (PinosClient1 *interface,
sender = g_dbus_method_invocation_get_sender (invocation);
props = pinos_properties_from_variant (arg_properties);
input = pinos_client_source_get_source_input (PINOS_CLIENT_SOURCE (source),
priv->object_path,
formats,
props,
priv->object_path,
&error);
channel = pinos_client_source_get_channel (PINOS_CLIENT_SOURCE (source),
priv->object_path,
formats,
props,
priv->object_path,
&error);
pinos_properties_free (props);
if (input == NULL)
goto no_input;
if (channel == NULL)
goto no_channel;
g_object_set_data_full (G_OBJECT (input),
"input-source",
g_object_set_data_full (G_OBJECT (channel),
"channel-owner",
source,
g_object_unref);
source_input_path = pinos_source_output_get_object_path (input);
g_debug ("client %p: add source input %p, %s", client, input, source_input_path);
priv->outputs = g_list_prepend (priv->outputs, input);
channel_path = pinos_channel_get_object_path (channel);
g_debug ("client %p: add source channel %p, %s", client, channel, channel_path);
priv->channels = g_list_prepend (priv->channels, channel);
g_signal_connect (input,
g_signal_connect (channel,
"remove",
(GCallback) handle_remove_source_output,
(GCallback) handle_remove_channel,
client);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)",
source_input_path));
channel_path));
return TRUE;
@ -296,9 +296,9 @@ no_source:
g_bytes_unref (formats);
return TRUE;
}
no_input:
no_channel:
{
g_debug ("client %p: could not create input %s", client, error->message);
g_debug ("client %p: could not create channel %s", client, error->message);
g_dbus_method_invocation_return_gerror (invocation, error);
g_object_unref (source);
g_clear_error (&error);
@ -337,11 +337,11 @@ client_register_object (PinosClient *client,
priv->client1 = pinos_client1_skeleton_new ();
pinos_client1_set_name (priv->client1, priv->sender);
pinos_client1_set_properties (priv->client1, pinos_properties_to_variant (priv->properties));
g_signal_connect (priv->client1, "handle-create-source-output",
(GCallback) handle_create_source_output,
g_signal_connect (priv->client1, "handle-create-source-channel",
(GCallback) handle_create_source_channel,
client);
g_signal_connect (priv->client1, "handle-create-source-input",
(GCallback) handle_create_source_input,
g_signal_connect (priv->client1, "handle-create-upload-channel",
(GCallback) handle_create_upload_channel,
client);
g_signal_connect (priv->client1, "handle-disconnect",
(GCallback) handle_disconnect,
@ -367,11 +367,11 @@ client_unregister_object (PinosClient *client)
}
static void
do_remove_output (PinosSourceOutput *output,
PinosClient *client)
do_remove_channel (PinosChannel *channel,
PinosClient *client)
{
g_debug ("client %p: remove output %p", client, output);
pinos_source_output_remove (output);
g_debug ("client %p: remove channel %p", client, channel);
pinos_channel_remove (channel);
}
static void
@ -384,7 +384,7 @@ pinos_client_dispose (GObject * object)
if (priv->object_path)
pinos_fd_manager_remove_all (priv->fdmanager, priv->object_path);
g_list_foreach (priv->outputs, (GFunc) do_remove_output, client);
g_list_foreach (priv->channels, (GFunc) do_remove_channel, client);
client_unregister_object (client);
g_clear_object (&priv->daemon);

View file

@ -1,69 +0,0 @@
/* Pinos
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PINOS_SOURCE_OUTPUT_H__
#define __PINOS_SOURCE_OUTPUT_H__
#include <glib-object.h>
G_BEGIN_DECLS
#define PINOS_TYPE_SOURCE_OUTPUT (pinos_source_output_get_type ())
#define PINOS_IS_SOURCE_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SOURCE_OUTPUT))
#define PINOS_IS_SOURCE_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PINOS_TYPE_SOURCE_OUTPUT))
#define PINOS_SOURCE_OUTPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PINOS_TYPE_SOURCE_OUTPUT, PinosSourceOutputClass))
#define PINOS_SOURCE_OUTPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), PINOS_TYPE_SOURCE_OUTPUT, PinosSourceOutput))
#define PINOS_SOURCE_OUTPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PINOS_TYPE_SOURCE_OUTPUT, PinosSourceOutputClass))
#define PINOS_SOURCE_OUTPUT_CAST(obj) ((PinosSourceOutput*)(obj))
#define PINOS_SOURCE_OUTPUT_CLASS_CAST(klass) ((PinosSourceOutputClass*)(klass))
typedef struct _PinosSourceOutput PinosSourceOutput;
typedef struct _PinosSourceOutputClass PinosSourceOutputClass;
typedef struct _PinosSourceOutputPrivate PinosSourceOutputPrivate;
/**
* PinosSourceOutput:
*
* Pinos source output object class.
*/
struct _PinosSourceOutput {
GObject object;
PinosSourceOutputPrivate *priv;
};
/**
* PinosSourceOutputClass:
*
* Pinos source output object class.
*/
struct _PinosSourceOutputClass {
GObjectClass parent_class;
};
/* normal GObject stuff */
GType pinos_source_output_get_type (void);
void pinos_source_output_remove (PinosSourceOutput *output);
const gchar * pinos_source_output_get_object_path (PinosSourceOutput *output);
G_END_DECLS
#endif /* __PINOS_SOURCE_OUTPUT_H__ */

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;

View file

@ -29,7 +29,7 @@ typedef struct _PinosSourceClass PinosSourceClass;
typedef struct _PinosSourcePrivate PinosSourcePrivate;
#include <pinos/client/introspect.h>
#include <pinos/server/source-output.h>
#include <pinos/server/channel.h>
#define PINOS_TYPE_SOURCE (pinos_source_get_type ())
#define PINOS_IS_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), PINOS_TYPE_SOURCE))
@ -55,8 +55,8 @@ struct _PinosSource {
* PinosSourceClass:
* @get_formats: called to get a list of supported formats from the source
* @set_state: called to change the current state of the source
* @create_source_output: called to create a new source-output object
* @release_source_output: called to release a source-output object
* @create_channel: called to create a new channel object
* @release_channel: called to release a channel object
*
* Pinos source object class.
*/
@ -69,14 +69,14 @@ struct _PinosSourceClass {
gboolean (*set_state) (PinosSource *source, PinosSourceState);
PinosSourceOutput * (*create_source_output) (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error);
gboolean (*release_source_output) (PinosSource *source,
PinosSourceOutput *output);
PinosChannel * (*create_channel) (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error);
gboolean (*release_channel) (PinosSource *source,
PinosChannel *channel);
};
/* normal GObject stuff */
@ -97,14 +97,14 @@ void pinos_source_report_busy (PinosSource *source);
void pinos_source_update_possible_formats (PinosSource *source, GBytes *formats);
void pinos_source_update_format (PinosSource *source, GBytes *format);
PinosSourceOutput * pinos_source_create_source_output (PinosSource *source,
PinosChannel * pinos_source_create_channel (PinosSource *source,
const gchar *client_path,
GBytes *format_filter,
PinosProperties *props,
const gchar *prefix,
GError **error);
gboolean pinos_source_release_source_output (PinosSource *source,
PinosSourceOutput *output);
gboolean pinos_source_release_channel (PinosSource *source,
PinosChannel *channel);
G_END_DECLS