2015-06-30 18:06:36 +02:00
|
|
|
/* Pinos
|
2015-04-16 16:58:33 +02:00
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2015-05-14 17:46:12 +02:00
|
|
|
#include <string.h>
|
2015-04-16 16:58:33 +02:00
|
|
|
#include <gio/gunixfdlist.h>
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
#include "server/daemon.h"
|
2015-06-30 18:06:36 +02:00
|
|
|
#include "client/pinos.h"
|
2015-07-07 16:46:23 +02:00
|
|
|
#include "client/context.h"
|
|
|
|
|
#include "client/stream.h"
|
|
|
|
|
#include "client/enumtypes.h"
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
#include "client/private.h"
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
struct _PinosStreamPrivate
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosContext *context;
|
2015-04-16 16:58:33 +02:00
|
|
|
gchar *name;
|
2015-07-17 16:57:01 +02:00
|
|
|
PinosProperties *properties;
|
2015-05-27 18:16:52 +02:00
|
|
|
|
2015-06-04 16:34:47 +02:00
|
|
|
guint id;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamState state;
|
2015-04-29 17:51:51 +02:00
|
|
|
GError *error;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-09 17:58:54 +02:00
|
|
|
gchar *source_path;
|
2015-05-14 17:46:12 +02:00
|
|
|
GBytes *accepted_formats;
|
2015-05-27 18:16:52 +02:00
|
|
|
gboolean provide;
|
|
|
|
|
|
2015-05-14 17:46:12 +02:00
|
|
|
GBytes *possible_formats;
|
|
|
|
|
GBytes *format;
|
2015-05-27 18:16:52 +02:00
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
GDBusProxy *source_output;
|
2015-08-25 16:36:01 +02:00
|
|
|
gboolean disconnecting;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamMode mode;
|
2015-05-14 17:46:12 +02:00
|
|
|
GSocket *socket;
|
|
|
|
|
GSource *socket_source;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
PinosStackBuffer buffer;
|
2015-04-16 16:58:33 +02:00
|
|
|
};
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
#define PINOS_STREAM_GET_PRIVATE(obj) \
|
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), PINOS_TYPE_STREAM, PinosStreamPrivate))
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
G_DEFINE_TYPE (PinosStream, pinos_stream, G_TYPE_OBJECT);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_CONTEXT,
|
|
|
|
|
PROP_NAME,
|
2015-04-28 17:36:44 +02:00
|
|
|
PROP_PROPERTIES,
|
2015-04-16 16:58:33 +02:00
|
|
|
PROP_STATE,
|
2015-05-14 17:46:12 +02:00
|
|
|
PROP_POSSIBLE_FORMATS,
|
|
|
|
|
PROP_FORMAT,
|
|
|
|
|
PROP_SOCKET,
|
2015-04-16 16:58:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
SIGNAL_NEW_BUFFER,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_get_property (GObject *_object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = PINOS_STREAM (_object);
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_CONTEXT:
|
|
|
|
|
g_value_set_object (value, priv->context);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_NAME:
|
|
|
|
|
g_value_set_string (value, priv->name);
|
|
|
|
|
break;
|
|
|
|
|
|
2015-04-28 17:36:44 +02:00
|
|
|
case PROP_PROPERTIES:
|
2015-07-17 16:57:01 +02:00
|
|
|
g_value_set_boxed (value, priv->properties);
|
2015-04-28 17:36:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
case PROP_STATE:
|
|
|
|
|
g_value_set_enum (value, priv->state);
|
|
|
|
|
break;
|
|
|
|
|
|
2015-05-14 17:46:12 +02:00
|
|
|
case PROP_POSSIBLE_FORMATS:
|
|
|
|
|
g_value_set_boxed (value, priv->possible_formats);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_FORMAT:
|
|
|
|
|
g_value_set_boxed (value, priv->format);
|
|
|
|
|
break;
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
case PROP_SOCKET:
|
|
|
|
|
g_value_set_object (value, priv->socket);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (stream, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_set_property (GObject *_object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = PINOS_STREAM (_object);
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_CONTEXT:
|
|
|
|
|
priv->context = g_value_dup_object (value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case PROP_NAME:
|
|
|
|
|
priv->name = g_value_dup_string (value);
|
|
|
|
|
break;
|
|
|
|
|
|
2015-04-28 17:36:44 +02:00
|
|
|
case PROP_PROPERTIES:
|
|
|
|
|
if (priv->properties)
|
2015-07-17 16:57:01 +02:00
|
|
|
pinos_properties_free (priv->properties);
|
|
|
|
|
priv->properties = g_value_dup_boxed (value);
|
2015-04-28 17:36:44 +02:00
|
|
|
break;
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (stream, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-12 12:10:27 +02:00
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
do_notify_state (PinosStream *stream)
|
2015-06-12 12:10:27 +02:00
|
|
|
{
|
|
|
|
|
g_object_notify (G_OBJECT (stream), "state");
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-04 16:34:47 +02:00
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (PinosStream *stream,
|
|
|
|
|
PinosStreamState state)
|
2015-06-04 16:34:47 +02:00
|
|
|
{
|
|
|
|
|
if (stream->priv->state != state) {
|
|
|
|
|
stream->priv->state = state;
|
2015-06-12 12:10:27 +02:00
|
|
|
g_main_context_invoke (stream->priv->context->priv->context,
|
|
|
|
|
(GSourceFunc) do_notify_state,
|
|
|
|
|
g_object_ref (stream));
|
2015-06-04 16:34:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
subscription_cb (PinosSubscribe *subscribe,
|
|
|
|
|
PinosSubscriptionEvent event,
|
|
|
|
|
PinosSubscriptionFlags flags,
|
|
|
|
|
GDBusProxy *object,
|
|
|
|
|
gpointer user_data)
|
2015-06-04 16:34:47 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = PINOS_STREAM (user_data);
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-06-04 16:34:47 +02:00
|
|
|
|
|
|
|
|
switch (flags) {
|
2015-08-04 17:34:11 +02:00
|
|
|
case PINOS_SUBSCRIPTION_FLAG_SOURCE_OUTPUT:
|
2015-07-07 16:46:23 +02:00
|
|
|
if (event == PINOS_SUBSCRIPTION_EVENT_REMOVE) {
|
2015-08-25 16:36:01 +02:00
|
|
|
if (object == priv->source_output && !priv->disconnecting) {
|
2015-06-04 16:34:47 +02:00
|
|
|
priv->error = g_error_new_literal (G_IO_ERROR, G_IO_ERROR_CLOSED, "output disappeared");
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-06-04 16:34:47 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_constructed (GObject * object)
|
2015-06-04 16:34:47 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = PINOS_STREAM (object);
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-06-04 16:34:47 +02:00
|
|
|
|
|
|
|
|
priv->id = g_signal_connect (priv->context->priv->subscribe,
|
|
|
|
|
"subscription-event",
|
|
|
|
|
(GCallback) subscription_cb,
|
|
|
|
|
stream);
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
G_OBJECT_CLASS (pinos_stream_parent_class)->constructed (object);
|
2015-06-04 16:34:47 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_finalize (GObject * object)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = PINOS_STREAM (object);
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
g_clear_object (&priv->source_output);
|
|
|
|
|
|
|
|
|
|
if (priv->possible_formats)
|
|
|
|
|
g_bytes_unref (priv->possible_formats);
|
|
|
|
|
if (priv->format)
|
|
|
|
|
g_bytes_unref (priv->format);
|
|
|
|
|
|
2015-07-09 17:58:54 +02:00
|
|
|
g_free (priv->source_path);
|
2015-05-27 18:16:52 +02:00
|
|
|
if (priv->accepted_formats)
|
|
|
|
|
g_bytes_unref (priv->accepted_formats);
|
|
|
|
|
|
|
|
|
|
g_clear_error (&priv->error);
|
|
|
|
|
|
|
|
|
|
if (priv->properties)
|
2015-07-17 16:57:01 +02:00
|
|
|
pinos_properties_free (priv->properties);
|
2015-06-04 16:34:47 +02:00
|
|
|
g_signal_handler_disconnect (priv->context->priv->subscribe, priv->id);
|
2015-05-27 18:16:52 +02:00
|
|
|
g_clear_object (&priv->context);
|
2015-04-16 16:58:33 +02:00
|
|
|
g_free (priv->name);
|
|
|
|
|
|
2015-08-24 16:55:29 +02:00
|
|
|
g_free (priv->buffer.data);
|
2015-08-24 16:41:04 +02:00
|
|
|
if (priv->buffer.message)
|
|
|
|
|
g_object_unref (priv->buffer.message);
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
G_OBJECT_CLASS (pinos_stream_parent_class)->finalize (object);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_class_init (PinosStreamClass * klass)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_type_class_add_private (klass, sizeof (PinosStreamPrivate));
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
gobject_class->constructed = pinos_stream_constructed;
|
|
|
|
|
gobject_class->finalize = pinos_stream_finalize;
|
|
|
|
|
gobject_class->set_property = pinos_stream_set_property;
|
|
|
|
|
gobject_class->get_property = pinos_stream_get_property;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:context
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* The context of the stream.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_CONTEXT,
|
|
|
|
|
g_param_spec_object ("context",
|
|
|
|
|
"Context",
|
|
|
|
|
"The context",
|
2015-07-07 16:46:23 +02:00
|
|
|
PINOS_TYPE_CONTEXT,
|
2015-04-16 16:58:33 +02:00
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:name
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* The name of the stream as specified at construction time.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_NAME,
|
|
|
|
|
g_param_spec_string ("name",
|
|
|
|
|
"Name",
|
|
|
|
|
"The name of the stream",
|
|
|
|
|
NULL,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2015-04-28 17:36:44 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:properties
|
2015-04-28 17:36:44 +02:00
|
|
|
*
|
|
|
|
|
* The properties of the stream as specified at construction time.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_PROPERTIES,
|
2015-07-17 16:57:01 +02:00
|
|
|
g_param_spec_boxed ("properties",
|
|
|
|
|
"Properties",
|
|
|
|
|
"The properties of the stream",
|
|
|
|
|
PINOS_TYPE_PROPERTIES,
|
|
|
|
|
G_PARAM_READWRITE |
|
|
|
|
|
G_PARAM_CONSTRUCT_ONLY |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:state
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* The state of the stream. Use the notify::state signal to be notified
|
|
|
|
|
* of state changes.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_STATE,
|
|
|
|
|
g_param_spec_enum ("state",
|
|
|
|
|
"State",
|
|
|
|
|
"The stream state",
|
2015-07-07 16:46:23 +02:00
|
|
|
PINOS_TYPE_STREAM_STATE,
|
|
|
|
|
PINOS_STREAM_STATE_UNCONNECTED,
|
2015-04-16 16:58:33 +02:00
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2015-05-14 17:46:12 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:possible-formats
|
2015-05-14 17:46:12 +02:00
|
|
|
*
|
|
|
|
|
* The possible formats for the stream. this can only be used after connecting
|
|
|
|
|
* the stream for capture or provide.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_POSSIBLE_FORMATS,
|
|
|
|
|
g_param_spec_boxed ("possible-formats",
|
|
|
|
|
"Possible Formats",
|
|
|
|
|
"The possbile formats of the stream",
|
|
|
|
|
G_TYPE_BYTES,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:formats
|
2015-05-14 17:46:12 +02:00
|
|
|
*
|
|
|
|
|
* The format of the stream. This will be set after starting the stream.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_FORMAT,
|
|
|
|
|
g_param_spec_boxed ("format",
|
|
|
|
|
"Format",
|
|
|
|
|
"The format of the stream",
|
|
|
|
|
G_TYPE_BYTES,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:socket
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* The socket of the stream. When doing pinos_stream_start() with
|
|
|
|
|
* #PINOS_STREAM_MODE_SOCKET, the socket will contain a data stream with
|
2015-04-16 16:58:33 +02:00
|
|
|
* meta data and anciliary data containing fds with the data.
|
|
|
|
|
*/
|
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
|
PROP_SOCKET,
|
|
|
|
|
g_param_spec_object ("socket",
|
|
|
|
|
"Socket",
|
|
|
|
|
"The stream socket",
|
|
|
|
|
G_TYPE_SOCKET,
|
|
|
|
|
G_PARAM_READABLE |
|
|
|
|
|
G_PARAM_STATIC_STRINGS));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* PinosStream:new-buffer
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* When doing pinos_stream_start() with #PINOS_STREAM_MODE_BUFFER, this signal
|
2015-04-16 16:58:33 +02:00
|
|
|
* will be fired whenever a new buffer can be obtained with
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_capture_buffer().
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
|
|
|
|
signals[SIGNAL_NEW_BUFFER] = g_signal_new ("new-buffer",
|
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
g_cclosure_marshal_generic,
|
|
|
|
|
G_TYPE_NONE,
|
|
|
|
|
0,
|
|
|
|
|
G_TYPE_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_init (PinosStream * stream)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv = PINOS_STREAM_GET_PRIVATE (stream);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
priv->state = PINOS_STREAM_STATE_UNCONNECTED;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_new:
|
|
|
|
|
* @context: a #PinosContext
|
2015-04-16 16:58:33 +02:00
|
|
|
* @name: a stream name
|
2015-04-28 17:36:44 +02:00
|
|
|
* @properties: stream properties
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* Make a new unconnected #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* Returns: a new unconnected #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *
|
2015-07-17 16:57:01 +02:00
|
|
|
pinos_stream_new (PinosContext *context,
|
|
|
|
|
const gchar *name,
|
|
|
|
|
PinosProperties *props)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_CONTEXT (context), NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
2015-07-28 17:05:03 +02:00
|
|
|
if (props == NULL) {
|
|
|
|
|
props = pinos_properties_new ("media.name", name, NULL);
|
|
|
|
|
} else if (!pinos_properties_get (props, "media.name")) {
|
|
|
|
|
pinos_properties_set (props, "media.name", name);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-17 16:57:01 +02:00
|
|
|
return g_object_new (PINOS_TYPE_STREAM,
|
|
|
|
|
"context", context,
|
|
|
|
|
"name", name,
|
|
|
|
|
"properties", props,
|
|
|
|
|
NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_get_state:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Get the state of @stream.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the state of @stream
|
|
|
|
|
*/
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamState
|
|
|
|
|
pinos_stream_get_state (PinosStream *stream)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), PINOS_STREAM_STATE_ERROR);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return stream->priv->state;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_get_error:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-04-29 17:51:51 +02:00
|
|
|
*
|
|
|
|
|
* Get the error of @stream.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the error of @stream or %NULL when there is no error
|
|
|
|
|
*/
|
|
|
|
|
const GError *
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_get_error (PinosStream *stream)
|
2015-04-29 17:51:51 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), NULL);
|
2015-04-29 17:51:51 +02:00
|
|
|
|
|
|
|
|
return stream->priv->error;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
on_source_output_proxy (GObject *source_object,
|
2015-05-04 10:38:26 +02:00
|
|
|
GAsyncResult *res,
|
2015-07-07 16:46:23 +02:00
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = user_data;
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
|
|
|
|
PinosContext *context = priv->context;
|
2015-05-14 17:46:12 +02:00
|
|
|
GVariant *v;
|
|
|
|
|
gchar *str;
|
2015-04-16 16:58:33 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
priv->source_output = pinos_subscribe_get_proxy_finish (context->priv->subscribe,
|
2015-05-04 12:16:30 +02:00
|
|
|
res,
|
|
|
|
|
&error);
|
2015-04-17 17:27:26 +02:00
|
|
|
if (priv->source_output == NULL)
|
|
|
|
|
goto source_output_failed;
|
|
|
|
|
|
2015-05-14 17:46:12 +02:00
|
|
|
v = g_dbus_proxy_get_cached_property (priv->source_output, "PossibleFormats");
|
|
|
|
|
if (v) {
|
2015-07-09 17:31:31 +02:00
|
|
|
gsize len;
|
|
|
|
|
str = g_variant_dup_string (v, &len);
|
2015-05-14 17:46:12 +02:00
|
|
|
g_variant_unref (v);
|
|
|
|
|
|
|
|
|
|
if (priv->possible_formats)
|
|
|
|
|
g_bytes_unref (priv->possible_formats);
|
2015-07-09 17:31:31 +02:00
|
|
|
priv->possible_formats = g_bytes_new_take (str, len + 1);
|
2015-05-14 17:46:12 +02:00
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (stream), "possible-formats");
|
|
|
|
|
}
|
2015-08-13 11:37:10 +02:00
|
|
|
v = g_dbus_proxy_get_cached_property (priv->source_output, "Properties");
|
|
|
|
|
if (v) {
|
|
|
|
|
if (priv->properties)
|
|
|
|
|
pinos_properties_free (priv->properties);
|
|
|
|
|
priv->properties = pinos_properties_from_variant (v);
|
|
|
|
|
g_variant_unref (v);
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (stream), "properties");
|
|
|
|
|
}
|
2015-05-14 17:46:12 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_READY);
|
2015-05-27 18:16:52 +02:00
|
|
|
g_object_unref (stream);
|
2015-05-04 10:38:26 +02:00
|
|
|
|
2015-04-17 17:27:26 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
source_output_failed:
|
|
|
|
|
{
|
2015-04-29 17:51:51 +02:00
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-06-12 12:10:27 +02:00
|
|
|
g_warning ("failed to get source output proxy: %s", error->message);
|
2015-05-27 18:16:52 +02:00
|
|
|
g_object_unref (stream);
|
2015-04-16 16:58:33 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
on_source_output_created (GObject *source_object,
|
2015-04-16 16:58:33 +02:00
|
|
|
GAsyncResult *res,
|
2015-07-07 16:46:23 +02:00
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = user_data;
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
|
|
|
|
PinosContext *context = priv->context;
|
2015-05-04 10:38:26 +02:00
|
|
|
GVariant *ret;
|
2015-04-16 16:58:33 +02:00
|
|
|
GError *error = NULL;
|
2015-05-27 18:16:52 +02:00
|
|
|
const gchar *source_output_path;
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-08-25 16:36:01 +02:00
|
|
|
g_assert (context->priv->client == G_DBUS_PROXY (source_object));
|
|
|
|
|
|
2015-05-11 16:08:34 +02:00
|
|
|
ret = g_dbus_proxy_call_finish (context->priv->client, res, &error);
|
2015-05-04 10:38:26 +02:00
|
|
|
if (ret == NULL)
|
2015-04-17 17:27:26 +02:00
|
|
|
goto create_failed;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
g_variant_get (ret, "(o)", &source_output_path);
|
2015-05-04 10:38:26 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_subscribe_get_proxy (context->priv->subscribe,
|
|
|
|
|
PINOS_DBUS_SERVICE,
|
2015-05-27 18:16:52 +02:00
|
|
|
source_output_path,
|
2015-06-30 18:06:36 +02:00
|
|
|
"org.pinos.SourceOutput1",
|
2015-05-04 12:16:30 +02:00
|
|
|
NULL,
|
|
|
|
|
on_source_output_proxy,
|
|
|
|
|
stream);
|
2015-05-27 18:16:52 +02:00
|
|
|
g_variant_unref (ret);
|
2015-04-20 15:03:14 +02:00
|
|
|
|
2015-04-17 17:27:26 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
|
create_failed:
|
|
|
|
|
{
|
2015-04-29 17:51:51 +02:00
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-05-21 10:18:21 +02:00
|
|
|
g_warning ("failed to get connect capture: %s", error->message);
|
2015-05-27 18:16:52 +02:00
|
|
|
g_object_unref (stream);
|
2015-04-17 17:27:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
do_connect_capture (PinosStream *stream)
|
2015-04-29 17:51:51 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
|
|
|
|
PinosContext *context = priv->context;
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-05-11 16:08:34 +02:00
|
|
|
g_dbus_proxy_call (context->priv->client,
|
2015-05-04 10:38:26 +02:00
|
|
|
"CreateSourceOutput",
|
2015-07-28 17:05:03 +02:00
|
|
|
g_variant_new ("(ss@a{sv})",
|
2015-07-09 17:58:54 +02:00
|
|
|
(priv->source_path ? priv->source_path : ""),
|
2015-07-28 17:05:03 +02:00
|
|
|
g_bytes_get_data (priv->accepted_formats, NULL),
|
|
|
|
|
pinos_properties_to_variant (priv->properties)),
|
2015-05-04 10:38:26 +02:00
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL, /* GCancellable *cancellable */
|
|
|
|
|
on_source_output_created,
|
|
|
|
|
stream);
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_connect_capture:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-07-09 17:58:54 +02:00
|
|
|
* @source_path: the source path to connect to
|
2015-07-07 16:46:23 +02:00
|
|
|
* @flags: a #PinosStreamFlags
|
2015-07-17 16:57:01 +02:00
|
|
|
* @accepted_formats: a #GBytes with accepted formats
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
2015-07-09 17:58:54 +02:00
|
|
|
* Connect @stream for capturing from @source_path.
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_connect_capture (PinosStream *stream,
|
2015-07-09 17:58:54 +02:00
|
|
|
const gchar *source_path,
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamFlags flags,
|
|
|
|
|
GBytes *accepted_formats)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
|
|
|
|
PinosContext *context;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-05-14 17:46:12 +02:00
|
|
|
g_return_val_if_fail (accepted_formats != NULL, FALSE);
|
2015-04-28 17:36:44 +02:00
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
priv = stream->priv;
|
|
|
|
|
context = priv->context;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (pinos_context_get_state (context) == PINOS_CONTEXT_STATE_READY, FALSE);
|
2015-08-25 16:36:01 +02:00
|
|
|
g_return_val_if_fail (pinos_stream_get_state (stream) == PINOS_STREAM_STATE_UNCONNECTED, FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-09 17:58:54 +02:00
|
|
|
g_free (priv->source_path);
|
|
|
|
|
priv->source_path = g_strdup (source_path);
|
2015-05-27 18:16:52 +02:00
|
|
|
if (priv->accepted_formats)
|
|
|
|
|
g_bytes_unref (priv->accepted_formats);
|
2015-05-14 17:46:12 +02:00
|
|
|
priv->accepted_formats = g_bytes_ref (accepted_formats);
|
|
|
|
|
priv->provide = FALSE;
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_CONNECTING);
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
g_main_context_invoke (context->priv->context,
|
|
|
|
|
(GSourceFunc) do_connect_capture,
|
|
|
|
|
g_object_ref (stream));
|
2015-04-27 09:05:14 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-11 18:23:24 +02:00
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
do_connect_provide (PinosStream *stream)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
|
|
|
|
PinosContext *context = priv->context;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
g_dbus_proxy_call (context->priv->client,
|
|
|
|
|
"CreateSourceInput",
|
2015-07-28 17:05:03 +02:00
|
|
|
g_variant_new ("(s@a{sv})",
|
|
|
|
|
g_bytes_get_data (priv->possible_formats, NULL),
|
|
|
|
|
pinos_properties_to_variant (priv->properties)),
|
2015-05-11 18:23:24 +02:00
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL, /* GCancellable *cancellable */
|
|
|
|
|
on_source_output_created,
|
|
|
|
|
stream);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_connect_provide:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
* @flags: a #PinosStreamFlags
|
2015-07-17 16:57:01 +02:00
|
|
|
* @possible_formats: a #GBytes
|
2015-05-11 18:23:24 +02:00
|
|
|
*
|
|
|
|
|
* Connect @stream for providing data for a new source.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_connect_provide (PinosStream *stream,
|
|
|
|
|
PinosStreamFlags flags,
|
|
|
|
|
GBytes *possible_formats)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
|
|
|
|
PinosContext *context;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-05-14 17:46:12 +02:00
|
|
|
g_return_val_if_fail (possible_formats != NULL, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
context = priv->context;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (pinos_context_get_state (context) == PINOS_CONTEXT_STATE_READY, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
if (priv->possible_formats)
|
|
|
|
|
g_bytes_unref (priv->possible_formats);
|
2015-05-14 17:46:12 +02:00
|
|
|
priv->possible_formats = g_bytes_ref (possible_formats);
|
|
|
|
|
priv->provide = TRUE;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_CONNECTING);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_main_context_invoke (context->priv->context,
|
2015-05-27 18:16:52 +02:00
|
|
|
(GSourceFunc) do_connect_provide,
|
|
|
|
|
g_object_ref (stream));
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
on_source_output_removed (GObject *source_object,
|
2015-05-04 10:38:26 +02:00
|
|
|
GAsyncResult *res,
|
2015-07-07 16:46:23 +02:00
|
|
|
gpointer user_data)
|
2015-05-04 10:38:26 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = user_data;
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-05-04 10:38:26 +02:00
|
|
|
GVariant *ret;
|
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2015-08-25 16:36:01 +02:00
|
|
|
g_assert (priv->source_output == G_DBUS_PROXY (source_object));
|
|
|
|
|
|
|
|
|
|
priv->disconnecting = FALSE;
|
|
|
|
|
g_clear_object (&priv->source_output);
|
|
|
|
|
|
|
|
|
|
ret = g_dbus_proxy_call_finish (G_DBUS_PROXY (source_object), res, &error);
|
|
|
|
|
if (ret == NULL)
|
|
|
|
|
goto proxy_failed;
|
|
|
|
|
|
|
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_UNCONNECTED);
|
|
|
|
|
g_object_unref (stream);
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
|
proxy_failed:
|
|
|
|
|
{
|
2015-05-04 10:38:26 +02:00
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-05-21 10:18:21 +02:00
|
|
|
g_warning ("failed to disconnect: %s", error->message);
|
2015-05-27 18:16:52 +02:00
|
|
|
g_object_unref (stream);
|
2015-05-04 10:38:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
do_disconnect (PinosStream *stream)
|
2015-05-04 10:38:26 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-05-04 10:38:26 +02:00
|
|
|
|
|
|
|
|
g_dbus_proxy_call (priv->source_output,
|
|
|
|
|
"Remove",
|
|
|
|
|
g_variant_new ("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL, /* GCancellable *cancellable */
|
|
|
|
|
on_source_output_removed,
|
|
|
|
|
stream);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_disconnect:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Disconnect @stream.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_disconnect (PinosStream *stream)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
|
|
|
|
PinosContext *context;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
priv = stream->priv;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (priv->state >= PINOS_STREAM_STATE_READY, FALSE);
|
2015-04-17 17:27:26 +02:00
|
|
|
g_return_val_if_fail (priv->source_output != NULL, FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
context = priv->context;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (pinos_context_get_state (context) >= PINOS_CONTEXT_STATE_READY, FALSE);
|
2015-08-25 16:36:01 +02:00
|
|
|
g_return_val_if_fail (!priv->disconnecting, FALSE);
|
|
|
|
|
|
|
|
|
|
priv->disconnecting = TRUE;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-05-27 18:16:52 +02:00
|
|
|
g_main_context_invoke (context->priv->context,
|
|
|
|
|
(GSourceFunc) do_disconnect,
|
|
|
|
|
g_object_ref (stream));
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
on_socket_condition (GSocket *socket,
|
|
|
|
|
GIOCondition condition,
|
|
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = user_data;
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
switch (condition) {
|
|
|
|
|
case G_IO_IN:
|
|
|
|
|
{
|
|
|
|
|
gssize len;
|
|
|
|
|
GInputVector ivec;
|
2015-08-24 16:41:04 +02:00
|
|
|
PinosStackHeader *hdr;
|
2015-04-16 16:58:33 +02:00
|
|
|
GSocketControlMessage **messages = NULL;
|
|
|
|
|
gint num_messages = 0;
|
|
|
|
|
gint flags = 0;
|
2015-08-24 16:41:04 +02:00
|
|
|
gsize need;
|
2015-04-16 16:58:33 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
need = sizeof (PinosStackHeader);
|
|
|
|
|
|
|
|
|
|
if (priv->buffer.allocated_size < need) {
|
|
|
|
|
priv->buffer.allocated_size = need;
|
|
|
|
|
priv->buffer.data = g_realloc (priv->buffer.data, need);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hdr = priv->buffer.data;
|
|
|
|
|
|
|
|
|
|
ivec.buffer = hdr;
|
|
|
|
|
ivec.size = sizeof (PinosStackHeader);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
len = g_socket_receive_message (socket,
|
|
|
|
|
NULL,
|
|
|
|
|
&ivec,
|
|
|
|
|
1,
|
|
|
|
|
&messages,
|
|
|
|
|
&num_messages,
|
|
|
|
|
&flags,
|
|
|
|
|
NULL,
|
|
|
|
|
&error);
|
|
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
g_assert (len == sizeof (PinosStackHeader));
|
2015-04-21 16:57:09 +02:00
|
|
|
|
2015-05-15 15:58:13 +02:00
|
|
|
if (num_messages == 0)
|
|
|
|
|
break;
|
|
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
need += hdr->length;
|
|
|
|
|
|
|
|
|
|
if (priv->buffer.allocated_size < need) {
|
|
|
|
|
priv->buffer.allocated_size = need;
|
|
|
|
|
hdr = priv->buffer.data = g_realloc (priv->buffer.data, need);
|
|
|
|
|
}
|
|
|
|
|
priv->buffer.size = need;
|
|
|
|
|
|
|
|
|
|
if (priv->buffer.message)
|
|
|
|
|
g_object_unref (priv->buffer.message);
|
|
|
|
|
priv->buffer.message = messages[0];
|
|
|
|
|
|
|
|
|
|
len = g_socket_receive (socket,
|
|
|
|
|
(gchar *)priv->buffer.data + sizeof (PinosStackHeader),
|
|
|
|
|
hdr->length,
|
|
|
|
|
NULL,
|
|
|
|
|
&error);
|
|
|
|
|
g_assert (len == hdr->length);
|
|
|
|
|
|
|
|
|
|
priv->buffer.magic = PSB_MAGIC;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-04-28 17:36:44 +02:00
|
|
|
g_signal_emit (stream, signals[SIGNAL_NEW_BUFFER], 0, NULL);
|
2015-04-16 16:58:33 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2015-05-14 17:46:12 +02:00
|
|
|
case G_IO_OUT:
|
2015-05-21 10:18:21 +02:00
|
|
|
g_warning ("can do IO\n");
|
2015-05-14 17:46:12 +02:00
|
|
|
break;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
handle_socket (PinosStream *stream, gint fd)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
|
|
priv->socket = g_socket_new_from_fd (fd, &error);
|
2015-04-17 17:27:26 +02:00
|
|
|
if (priv->socket == NULL)
|
|
|
|
|
goto socket_failed;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
switch (priv->mode) {
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_STREAM_MODE_SOCKET:
|
2015-04-16 16:58:33 +02:00
|
|
|
g_object_notify (G_OBJECT (stream), "socket");
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_STREAM_MODE_BUFFER:
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-05-14 17:46:12 +02:00
|
|
|
if (!priv->provide) {
|
|
|
|
|
priv->socket_source = g_socket_create_source (priv->socket, G_IO_IN, NULL);
|
|
|
|
|
g_source_set_callback (priv->socket_source, (GSourceFunc) on_socket_condition, stream, NULL);
|
|
|
|
|
g_source_attach (priv->socket_source, priv->context->priv->context);
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-04-17 17:27:26 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
|
socket_failed:
|
|
|
|
|
{
|
2015-04-29 17:51:51 +02:00
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-06-12 12:10:27 +02:00
|
|
|
g_warning ("failed to create socket: %s", error->message);
|
2015-04-17 17:27:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
unhandle_socket (PinosStream *stream)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
switch (priv->mode) {
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_STREAM_MODE_SOCKET:
|
2015-04-16 16:58:33 +02:00
|
|
|
g_clear_object (&priv->socket);
|
|
|
|
|
g_object_notify (G_OBJECT (stream), "socket");
|
|
|
|
|
break;
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
case PINOS_STREAM_MODE_BUFFER:
|
2015-05-14 17:46:12 +02:00
|
|
|
if (priv->socket_source) {
|
|
|
|
|
g_source_destroy (priv->socket_source);
|
|
|
|
|
g_clear_pointer (&priv->socket_source, g_source_unref);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
on_stream_started (GObject *source_object,
|
2015-04-17 17:27:26 +02:00
|
|
|
GAsyncResult *res,
|
2015-07-07 16:46:23 +02:00
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = user_data;
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
GUnixFDList *out_fd_list;
|
|
|
|
|
gint fd_idx, fd;
|
2015-05-14 17:46:12 +02:00
|
|
|
gchar *format;
|
2015-04-16 16:58:33 +02:00
|
|
|
GError *error = NULL;
|
2015-08-21 11:45:38 +02:00
|
|
|
GVariant *result, *properties;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
result = g_dbus_proxy_call_with_unix_fd_list_finish (priv->source_output,
|
2015-04-17 17:27:26 +02:00
|
|
|
&out_fd_list,
|
|
|
|
|
res,
|
|
|
|
|
&error);
|
|
|
|
|
if (result == NULL)
|
|
|
|
|
goto start_failed;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
g_variant_get (result,
|
2015-08-21 11:45:38 +02:00
|
|
|
"(hs@a{sv})",
|
2015-04-16 16:58:33 +02:00
|
|
|
&fd_idx,
|
2015-08-21 11:45:38 +02:00
|
|
|
&format,
|
|
|
|
|
&properties);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
g_variant_unref (result);
|
2015-05-14 17:46:12 +02:00
|
|
|
|
|
|
|
|
if (priv->format)
|
|
|
|
|
g_bytes_unref (priv->format);
|
2015-08-21 11:45:38 +02:00
|
|
|
priv->format = g_bytes_new_take (format, strlen (format) + 1);
|
2015-05-14 17:46:12 +02:00
|
|
|
g_object_notify (G_OBJECT (stream), "format");
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-08-21 11:45:38 +02:00
|
|
|
if (priv->properties)
|
|
|
|
|
pinos_properties_free (priv->properties);
|
|
|
|
|
priv->properties = pinos_properties_from_variant (properties);
|
|
|
|
|
g_variant_unref (properties);
|
|
|
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (stream), "properties");
|
|
|
|
|
|
2015-04-17 17:27:26 +02:00
|
|
|
if ((fd = g_unix_fd_list_get (out_fd_list, fd_idx, &error)) < 0)
|
|
|
|
|
goto fd_failed;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
handle_socket (stream, fd);
|
|
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_STREAMING);
|
2015-04-17 17:27:26 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
|
start_failed:
|
|
|
|
|
{
|
2015-06-12 12:10:27 +02:00
|
|
|
g_warning ("failed to start: %s", error->message);
|
2015-04-17 17:27:26 +02:00
|
|
|
goto exit_error;
|
|
|
|
|
}
|
|
|
|
|
fd_failed:
|
|
|
|
|
{
|
2015-06-12 12:10:27 +02:00
|
|
|
g_warning ("failed to get FD: %s", error->message);
|
2015-04-17 17:27:26 +02:00
|
|
|
goto exit_error;
|
|
|
|
|
}
|
|
|
|
|
exit_error:
|
|
|
|
|
{
|
2015-04-29 17:51:51 +02:00
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-04-17 17:27:26 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
do_start (PinosStream *stream)
|
2015-04-29 17:51:51 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
g_dbus_proxy_call (priv->source_output,
|
|
|
|
|
"Start",
|
2015-05-14 17:46:12 +02:00
|
|
|
g_variant_new ("(s)", g_bytes_get_data (priv->format, NULL)),
|
2015-05-04 10:38:26 +02:00
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL, /* GCancellable *cancellable */
|
|
|
|
|
on_stream_started,
|
|
|
|
|
stream);
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_start:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
* @mode: a #PinosStreamMode
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Start capturing from @stream.
|
|
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* When @mode is #PINOS_STREAM_MODE_SOCKET, you should connect to the notify::socket
|
2015-04-16 16:58:33 +02:00
|
|
|
* signal to obtain a readable socket with metadata and data.
|
|
|
|
|
*
|
2015-07-07 16:46:23 +02:00
|
|
|
* When @mode is #PINOS_STREAM_MODE_BUFFER, you should connect to the new-buffer
|
|
|
|
|
* signal and use pinos_stream_capture_buffer() to get the latest metadata and
|
2015-04-16 16:58:33 +02:00
|
|
|
* data.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_start (PinosStream *stream,
|
|
|
|
|
GBytes *format,
|
|
|
|
|
PinosStreamMode mode)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
priv = stream->priv;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_READY, FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
priv->mode = mode;
|
2015-05-14 17:46:12 +02:00
|
|
|
priv->format = g_bytes_ref (format);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_STARTING);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
g_main_context_invoke (priv->context->priv->context, (GSourceFunc) do_start, stream);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2015-07-07 16:46:23 +02:00
|
|
|
on_stream_stopped (GObject *source_object,
|
2015-04-17 17:27:26 +02:00
|
|
|
GAsyncResult *res,
|
2015-07-07 16:46:23 +02:00
|
|
|
gpointer user_data)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStream *stream = user_data;
|
|
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-05-04 10:38:26 +02:00
|
|
|
GVariant *ret;
|
2015-04-16 16:58:33 +02:00
|
|
|
GError *error = NULL;
|
|
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
ret = g_dbus_proxy_call_finish (priv->source_output, res, &error);
|
|
|
|
|
if (ret == NULL)
|
2015-04-17 17:27:26 +02:00
|
|
|
goto call_failed;
|
|
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
g_variant_unref (ret);
|
|
|
|
|
|
2015-04-17 17:27:26 +02:00
|
|
|
unhandle_socket (stream);
|
2015-05-14 17:46:12 +02:00
|
|
|
g_clear_pointer (&priv->format, g_free);
|
|
|
|
|
g_object_notify (G_OBJECT (stream), "format");
|
2015-04-17 17:27:26 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_READY);
|
2015-04-17 17:27:26 +02:00
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
|
call_failed:
|
|
|
|
|
{
|
2015-04-29 17:51:51 +02:00
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-06-12 12:10:27 +02:00
|
|
|
g_warning ("failed to release: %s", error->message);
|
2015-04-16 16:58:33 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
static gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
do_stop (PinosStream *stream)
|
2015-04-29 17:51:51 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv = stream->priv;
|
2015-04-29 17:51:51 +02:00
|
|
|
|
2015-05-04 10:38:26 +02:00
|
|
|
g_dbus_proxy_call (priv->source_output,
|
|
|
|
|
"Stop",
|
|
|
|
|
g_variant_new ("()"),
|
|
|
|
|
G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
|
-1,
|
|
|
|
|
NULL, /* GCancellable *cancellable */
|
|
|
|
|
on_stream_stopped,
|
|
|
|
|
stream);
|
|
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2015-04-16 16:58:33 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_stop:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Stop capturing from @stream.
|
|
|
|
|
*
|
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-07-07 16:46:23 +02:00
|
|
|
pinos_stream_stop (PinosStream *stream)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
priv = stream->priv;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_STREAMING, FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-04-29 17:51:51 +02:00
|
|
|
g_main_context_invoke (priv->context->priv->context, (GSourceFunc) do_stop, stream);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_capture_buffer:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-08-24 16:41:04 +02:00
|
|
|
* @buffer: a #PinosBuffer
|
2015-04-16 16:58:33 +02:00
|
|
|
*
|
|
|
|
|
* Capture the next buffer from @stream. This function should be called every
|
|
|
|
|
* time after the new-buffer callback has been emitted.
|
|
|
|
|
*
|
2015-08-24 16:41:04 +02:00
|
|
|
* Returns: %TRUE when @buffer contains valid information
|
2015-04-16 16:58:33 +02:00
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-08-24 16:41:04 +02:00
|
|
|
pinos_stream_capture_buffer (PinosStream *stream,
|
|
|
|
|
PinosBuffer *buffer)
|
2015-04-16 16:58:33 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-08-24 16:41:04 +02:00
|
|
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
priv = stream->priv;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_STREAMING, FALSE);
|
2015-08-24 16:55:29 +02:00
|
|
|
g_return_val_if_fail (is_valid_buffer (&priv->buffer), FALSE);
|
2015-04-16 16:58:33 +02:00
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
memcpy (buffer, &priv->buffer, sizeof (PinosStackBuffer));
|
|
|
|
|
|
|
|
|
|
priv->buffer.data = NULL;
|
|
|
|
|
priv->buffer.allocated_size = 0;
|
|
|
|
|
priv->buffer.size = 0;
|
|
|
|
|
priv->buffer.message = NULL;
|
2015-08-24 16:55:29 +02:00
|
|
|
priv->buffer.magic = 0;
|
2015-04-16 16:58:33 +02:00
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
/**
|
|
|
|
|
* pinos_stream_release_buffer:
|
|
|
|
|
* @stream: a #PinosStream
|
|
|
|
|
* @buffer: a #PinosBuffer
|
|
|
|
|
*
|
|
|
|
|
* Release @buffer back to @stream. This function should be called whenever the
|
2015-08-24 16:55:29 +02:00
|
|
|
* buffer is processed. @buffer should not be used anymore after calling this
|
|
|
|
|
* function.
|
2015-08-24 16:41:04 +02:00
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
pinos_stream_release_buffer (PinosStream *stream,
|
|
|
|
|
PinosBuffer *buffer)
|
|
|
|
|
{
|
|
|
|
|
PinosStackBuffer *sb = (PinosStackBuffer *) buffer;
|
|
|
|
|
PinosStreamPrivate *priv;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
|
|
|
|
g_return_val_if_fail (is_valid_buffer (buffer), FALSE);
|
|
|
|
|
|
|
|
|
|
priv = stream->priv;
|
|
|
|
|
|
|
|
|
|
if (priv->buffer.data == NULL) {
|
|
|
|
|
priv->buffer.data = sb->data;
|
|
|
|
|
priv->buffer.allocated_size = sb->allocated_size;
|
|
|
|
|
priv->buffer.size = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
g_free (sb->data);
|
|
|
|
|
|
|
|
|
|
if (sb->message)
|
|
|
|
|
g_object_unref (sb->message);
|
2015-08-24 16:55:29 +02:00
|
|
|
|
|
|
|
|
sb->magic = 0;
|
2015-08-24 16:41:04 +02:00
|
|
|
}
|
|
|
|
|
|
2015-05-11 18:23:24 +02:00
|
|
|
/**
|
2015-07-07 16:46:23 +02:00
|
|
|
* pinos_stream_provide_buffer:
|
|
|
|
|
* @stream: a #PinosStream
|
2015-08-24 16:41:04 +02:00
|
|
|
* @buffer: a #PinosBuffer
|
2015-05-11 18:23:24 +02:00
|
|
|
*
|
|
|
|
|
* Provide the next buffer from @stream. This function should be called every
|
|
|
|
|
* time a new frame becomes available.
|
|
|
|
|
*
|
2015-08-24 16:41:04 +02:00
|
|
|
* Returns: %TRUE when @buffer was handled
|
2015-05-11 18:23:24 +02:00
|
|
|
*/
|
|
|
|
|
gboolean
|
2015-08-24 16:41:04 +02:00
|
|
|
pinos_stream_provide_buffer (PinosStream *stream,
|
|
|
|
|
PinosBuffer *buffer)
|
2015-05-11 18:23:24 +02:00
|
|
|
{
|
2015-07-07 16:46:23 +02:00
|
|
|
PinosStreamPrivate *priv;
|
2015-05-14 17:46:12 +02:00
|
|
|
gssize len;
|
2015-08-24 16:41:04 +02:00
|
|
|
PinosStackBuffer *sb = (PinosStackBuffer *) buffer;
|
|
|
|
|
GOutputVector ovec[1];
|
2015-05-14 17:46:12 +02:00
|
|
|
gint flags = 0;
|
|
|
|
|
GError *error = NULL;
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (PINOS_IS_STREAM (stream), FALSE);
|
2015-08-24 16:41:04 +02:00
|
|
|
g_return_val_if_fail (buffer != NULL, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
|
|
|
|
priv = stream->priv;
|
2015-07-07 16:46:23 +02:00
|
|
|
g_return_val_if_fail (priv->state == PINOS_STREAM_STATE_STREAMING, FALSE);
|
2015-05-11 18:23:24 +02:00
|
|
|
|
2015-08-24 16:41:04 +02:00
|
|
|
ovec[0].buffer = sb->data;
|
|
|
|
|
ovec[0].size = sb->size;
|
2015-05-14 17:46:12 +02:00
|
|
|
|
|
|
|
|
len = g_socket_send_message (priv->socket,
|
|
|
|
|
NULL,
|
2015-08-24 16:41:04 +02:00
|
|
|
ovec,
|
2015-05-14 17:46:12 +02:00
|
|
|
1,
|
2015-08-24 16:41:04 +02:00
|
|
|
&sb->message,
|
2015-05-14 17:46:12 +02:00
|
|
|
1,
|
|
|
|
|
flags,
|
|
|
|
|
NULL,
|
|
|
|
|
&error);
|
2015-08-24 16:41:04 +02:00
|
|
|
if (sb->message) {
|
|
|
|
|
g_object_unref (sb->message);
|
|
|
|
|
sb->message = NULL;
|
2015-06-12 12:10:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (len == -1)
|
|
|
|
|
goto send_error;
|
|
|
|
|
|
2015-08-26 12:46:28 +02:00
|
|
|
g_assert (len == (gssize) sb->size);
|
2015-05-14 17:46:12 +02:00
|
|
|
|
2015-05-11 18:23:24 +02:00
|
|
|
return TRUE;
|
2015-06-12 12:10:27 +02:00
|
|
|
|
|
|
|
|
send_error:
|
|
|
|
|
{
|
|
|
|
|
priv->error = error;
|
2015-07-07 16:46:23 +02:00
|
|
|
stream_set_state (stream, PINOS_STREAM_STATE_ERROR);
|
2015-06-12 12:10:27 +02:00
|
|
|
g_warning ("failed to send_message: %s", error->message);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2015-05-11 18:23:24 +02:00
|
|
|
}
|
|
|
|
|
|