Implement negotiation

Use generic byte blobs for formats. We currently use them to store
gstreamer caps but we could also use them to exchange serialized
GVariants if we want.

Make properties a variant dictionary
This commit is contained in:
Wim Taymans 2015-05-14 17:46:12 +02:00
parent ca7e4602f6
commit 4bc308835a
21 changed files with 620 additions and 582 deletions

View file

@ -138,8 +138,10 @@ pv_context_finalize (GObject * object)
PvContext *context = PV_CONTEXT (object);
PvContextPrivate *priv = context->priv;
g_object_unref (priv->server_manager);
g_free (priv->name);
g_clear_error (&priv->error);
if (priv->properties)
g_variant_unref (priv->properties);
G_OBJECT_CLASS (pv_context_parent_class)->finalize (object);
}
@ -192,7 +194,7 @@ pv_context_class_init (PvContextClass * klass)
g_param_spec_variant ("properties",
"Properties",
"Extra properties",
G_VARIANT_TYPE_VARIANT,
G_VARIANT_TYPE_DICTIONARY,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
@ -267,7 +269,6 @@ pv_context_init (PvContext * context)
PvContextPrivate *priv = context->priv = PV_CONTEXT_GET_PRIVATE (context);
priv->state = PV_CONTEXT_STATE_UNCONNECTED;
priv->server_manager = g_dbus_object_manager_server_new (PV_DBUS_OBJECT_PREFIX);
priv->subscribe = pv_subscribe_new ();
g_object_set (priv->subscribe, "subscription-mask", PV_SUBSCRIPTION_FLAGS_ALL, NULL);
g_signal_connect (priv->subscribe, "subscription-event", (GCallback) subscription_cb, context);
@ -286,6 +287,15 @@ pv_context_init (PvContext * context)
PvContext *
pv_context_new (GMainContext *context, const gchar *name, GVariant *properties)
{
g_return_val_if_fail (name != NULL, NULL);
if (properties == NULL) {
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string (name));
properties = g_variant_builder_end (&builder);
}
return g_object_new (PV_TYPE_CONTEXT, "main-context", context, "name", name, "properties", properties, NULL);
}
@ -330,18 +340,14 @@ on_daemon_connected (GObject *source_object,
{
PvContext *context = user_data;
PvContextPrivate *priv = context->priv;
GVariantBuilder builder;
g_assert (g_main_context_get_thread_default () == priv->context);
context_set_state (context, PV_CONTEXT_STATE_REGISTERING);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string ("hello"));
g_dbus_proxy_call (priv->daemon,
"ConnectClient",
g_variant_new ("(@a{sv})", g_variant_builder_end (&builder)),
g_variant_new ("(@a{sv})", priv->properties),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
@ -436,7 +442,6 @@ on_name_appeared (GDBusConnection *connection,
g_print ("context: on name appeared\n");
priv->connection = connection;
g_dbus_object_manager_server_set_connection (priv->server_manager, connection);
g_object_set (priv->subscribe, "connection", priv->connection,
"service", name, NULL);
@ -455,7 +460,6 @@ on_name_vanished (GDBusConnection *connection,
g_print ("context: on name vanished\n");
priv->connection = connection;
g_dbus_object_manager_server_set_connection (priv->server_manager, connection);
g_object_set (priv->subscribe, "connection", connection, NULL);

View file

@ -41,6 +41,4 @@ struct _PvContextPrivate
PvSubscribe *subscribe;
GList *sources;
GDBusObjectManagerServer *server_manager;
};

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <gio/gunixfdlist.h>
#include "server/pv-daemon.h"
@ -35,14 +36,17 @@ struct _PvStreamPrivate
gchar *target;
PvStreamState state;
GError *error;
gboolean provide;
GBytes *accepted_formats;
GBytes *possible_formats;
GBytes *format;
gchar *source_output_path;
GVariant *spec;
GDBusProxy *source_output;
GSocket *socket;
PvStreamMode mode;
guint socket_id;
GSocket *socket;
GSource *socket_source;
PvBufferInfo info;
};
@ -59,7 +63,9 @@ enum
PROP_NAME,
PROP_PROPERTIES,
PROP_STATE,
PROP_SOCKET
PROP_POSSIBLE_FORMATS,
PROP_FORMAT,
PROP_SOCKET,
};
enum
@ -96,6 +102,14 @@ pv_stream_get_property (GObject *_object,
g_value_set_enum (value, priv->state);
break;
case PROP_POSSIBLE_FORMATS:
g_value_set_boxed (value, priv->possible_formats);
break;
case PROP_FORMAT:
g_value_set_boxed (value, priv->format);
break;
case PROP_SOCKET:
g_value_set_object (value, priv->socket);
break;
@ -216,7 +230,33 @@ pv_stream_class_init (PvStreamClass * klass)
PV_STREAM_STATE_UNCONNECTED,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
* PvStream:possible-formats
*
* 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));
/**
* PvStream:formats
*
* 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));
/**
* PvStream:socket
*
@ -329,7 +369,7 @@ on_source_output_signal (GDBusProxy *proxy,
GVariant *parameters,
gpointer user_data)
{
g_print ("on source output signal\n");
g_print ("on source output signal %s %s\n", sender_name, signal_name);
}
static void
@ -340,6 +380,8 @@ on_source_output_proxy (GObject *source_object,
PvStream *stream = user_data;
PvStreamPrivate *priv = stream->priv;
PvContext *context = priv->context;
GVariant *v;
gchar *str;
GError *error = NULL;
priv->source_output = pv_subscribe_get_proxy_finish (context->priv->subscribe,
@ -348,6 +390,22 @@ on_source_output_proxy (GObject *source_object,
if (priv->source_output == NULL)
goto source_output_failed;
g_print ("got source-output %s\n", priv->source_output_path);
v = g_dbus_proxy_get_cached_property (priv->source_output, "PossibleFormats");
if (v) {
str = g_variant_dup_string (v, NULL);
g_variant_unref (v);
g_print ("got possible formats %s\n", str);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
priv->possible_formats = g_bytes_new_take (str, strlen (str) + 1);
g_object_notify (G_OBJECT (stream), "possible-formats");
}
g_signal_connect (priv->source_output,
"g-signal",
(GCallback) on_source_output_signal,
@ -384,7 +442,6 @@ on_source_output_created (GObject *source_object,
goto create_failed;
g_variant_get (ret, "(o)", &priv->source_output_path);
g_print ("got source-output %s\n", priv->source_output_path);
g_variant_unref (ret);
pv_subscribe_get_proxy (context->priv->subscribe,
@ -417,9 +474,9 @@ do_connect_capture (PvStream *stream)
g_dbus_proxy_call (context->priv->client,
"CreateSourceOutput",
g_variant_new ("(o@a{sv})",
g_variant_new ("(os)",
(priv->target ? priv->target : "/"),
priv->spec),
g_bytes_get_data (priv->accepted_formats, NULL)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
@ -444,20 +501,21 @@ gboolean
pv_stream_connect_capture (PvStream *stream,
const gchar *source,
PvStreamFlags flags,
GVariant *spec)
GBytes *accepted_formats)
{
PvStreamPrivate *priv;
PvContext *context;
g_return_val_if_fail (PV_IS_STREAM (stream), FALSE);
g_return_val_if_fail (spec != NULL, FALSE);
g_return_val_if_fail (accepted_formats != NULL, FALSE);
priv = stream->priv;
context = priv->context;
g_return_val_if_fail (pv_context_get_state (context) == PV_CONTEXT_STATE_READY, FALSE);
priv->target = g_strdup (source);
priv->spec = spec;
priv->accepted_formats = g_bytes_ref (accepted_formats);
priv->provide = FALSE;
stream_set_state (stream, PV_STREAM_STATE_CONNECTING);
@ -476,8 +534,7 @@ do_connect_provide (PvStream *stream)
g_dbus_proxy_call (context->priv->client,
"CreateSourceInput",
g_variant_new ("(@a{sv})",
priv->spec),
g_variant_new ("(s)", g_bytes_get_data (priv->possible_formats, NULL)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
@ -498,21 +555,22 @@ do_connect_provide (PvStream *stream)
* Returns: %TRUE on success.
*/
gboolean
pv_stream_connect_provide (PvStream *stream,
PvStreamFlags flags,
GVariant *spec)
pv_stream_connect_provide (PvStream *stream,
PvStreamFlags flags,
GBytes *possible_formats)
{
PvStreamPrivate *priv;
PvContext *context;
g_return_val_if_fail (PV_IS_STREAM (stream), FALSE);
g_return_val_if_fail (spec != NULL, FALSE);
g_return_val_if_fail (possible_formats != NULL, FALSE);
priv = stream->priv;
context = priv->context;
g_return_val_if_fail (pv_context_get_state (context) == PV_CONTEXT_STATE_READY, FALSE);
priv->spec = spec;
priv->possible_formats = g_bytes_ref (possible_formats);
priv->provide = TRUE;
stream_set_state (stream, PV_STREAM_STATE_CONNECTING);
@ -588,16 +646,15 @@ pv_stream_disconnect (PvStream *stream)
g_main_context_invoke (context->priv->context, (GSourceFunc) do_disconnect, stream);
return TRUE;
}
#include <gst/wire-protocol.h>
static gboolean
on_socket_data (GSocket *socket,
GIOCondition condition,
gpointer user_data)
on_socket_condition (GSocket *socket,
GIOCondition condition,
gpointer user_data)
{
PvStream *stream = user_data;
PvStreamPrivate *priv = stream->priv;
@ -642,6 +699,9 @@ on_socket_data (GSocket *socket,
g_signal_emit (stream, signals[SIGNAL_NEW_BUFFER], 0, NULL);
break;
}
case G_IO_OUT:
g_print ("can do IO\n");
break;
default:
break;
@ -668,12 +728,11 @@ handle_socket (PvStream *stream, gint fd)
case PV_STREAM_MODE_BUFFER:
{
GSource *source;
source = g_socket_create_source (priv->socket, G_IO_IN, NULL);
g_source_set_callback (source, (GSourceFunc) on_socket_data, stream, NULL);
priv->socket_id = g_source_attach (source, priv->context->priv->context);
g_source_unref (source);
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);
}
break;
}
@ -703,6 +762,13 @@ unhandle_socket (PvStream *stream)
g_object_notify (G_OBJECT (stream), "socket");
break;
case PV_STREAM_MODE_BUFFER:
if (priv->socket_source) {
g_source_destroy (priv->socket_source);
g_clear_pointer (&priv->socket_source, g_source_unref);
}
break;
default:
break;
}
@ -717,7 +783,7 @@ on_stream_started (GObject *source_object,
PvStreamPrivate *priv = stream->priv;
GUnixFDList *out_fd_list;
gint fd_idx, fd;
GVariant *out_props;
gchar *format;
GError *error = NULL;
GVariant *result;
@ -729,12 +795,17 @@ on_stream_started (GObject *source_object,
goto start_failed;
g_variant_get (result,
"(h@a{sv})",
"(hs)",
&fd_idx,
&out_props);
&format);
g_variant_unref (result);
g_variant_unref (out_props);
if (priv->format)
g_bytes_unref (priv->format);
priv->format = g_bytes_new (format, strlen (format) + 1);
g_object_notify (G_OBJECT (stream), "format");
if ((fd = g_unix_fd_list_get (out_fd_list, fd_idx, &error)) < 0)
goto fd_failed;
@ -768,14 +839,10 @@ static gboolean
do_start (PvStream *stream)
{
PvStreamPrivate *priv = stream->priv;
GVariantBuilder builder;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "name", g_variant_new_string ("hello"));
g_dbus_proxy_call (priv->source_output,
"Start",
g_variant_new ("(@a{sv})", g_variant_builder_end (&builder)),
g_variant_new ("(s)", g_bytes_get_data (priv->format, NULL)),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL, /* GCancellable *cancellable */
@ -802,7 +869,7 @@ do_start (PvStream *stream)
* Returns: %TRUE on success.
*/
gboolean
pv_stream_start (PvStream *stream, PvStreamMode mode)
pv_stream_start (PvStream *stream, GBytes *format, PvStreamMode mode)
{
PvStreamPrivate *priv;
@ -812,6 +879,7 @@ pv_stream_start (PvStream *stream, PvStreamMode mode)
g_return_val_if_fail (priv->state == PV_STREAM_STATE_READY, FALSE);
priv->mode = mode;
priv->format = g_bytes_ref (format);
stream_set_state (stream, PV_STREAM_STATE_STARTING);
@ -837,6 +905,8 @@ on_stream_stopped (GObject *source_object,
g_variant_unref (ret);
unhandle_socket (stream);
g_clear_pointer (&priv->format, g_free);
g_object_notify (G_OBJECT (stream), "format");
stream_set_state (stream, PV_STREAM_STATE_READY);
@ -932,6 +1002,11 @@ gboolean
pv_stream_provide_buffer (PvStream *stream, PvBufferInfo *info)
{
PvStreamPrivate *priv;
gssize len;
GOutputVector ovec;
FDMessage msg;
gint flags = 0;
GError *error = NULL;
g_return_val_if_fail (PV_IS_STREAM (stream), FALSE);
g_return_val_if_fail (info != NULL, FALSE);
@ -939,6 +1014,30 @@ pv_stream_provide_buffer (PvStream *stream, PvBufferInfo *info)
priv = stream->priv;
g_return_val_if_fail (priv->state == PV_STREAM_STATE_STREAMING, FALSE);
msg.flags = info->flags;
msg.seq = info->seq;
msg.pts = info->pts;
msg.dts_offset = info->dts_offset;
msg.offset = info->offset;
msg.size = info->size;
ovec.buffer = &msg;
ovec.size = sizeof (msg);
len = g_socket_send_message (priv->socket,
NULL,
&ovec,
1,
&info->message,
1,
flags,
NULL,
&error);
g_assert (len == sizeof (msg));
if (info->message)
g_object_unref (info->message);
return TRUE;
}

View file

@ -103,13 +103,15 @@ const GError * pv_stream_get_error (PvStream *stream);
gboolean pv_stream_connect_capture (PvStream *stream,
const gchar *source,
PvStreamFlags flags,
GVariant *spec);
GBytes *accepted_formats);
gboolean pv_stream_connect_provide (PvStream *stream,
PvStreamFlags flags,
GVariant *spec);
GBytes *possible_formats);
gboolean pv_stream_disconnect (PvStream *stream);
gboolean pv_stream_start (PvStream *stream, PvStreamMode mode);
gboolean pv_stream_start (PvStream *stream,
GBytes *format,
PvStreamMode mode);
gboolean pv_stream_stop (PvStream *stream);
gboolean pv_stream_capture_buffer (PvStream *stream,

View file

@ -142,6 +142,8 @@ on_proxy_created (GObject *source_object,
return;
}
g_print ("got proxy for %s:%s\n", data->object_path, data->interface_name);
g_signal_connect (data->proxy,
"g-properties-changed",
(GCallback) on_proxy_properties_changed,
@ -180,6 +182,8 @@ add_interface (PvSubscribe *subscribe,
priv->objects = g_list_prepend (priv->objects, data);
priv->pending_proxies++;
g_print ("making proxy for %s:%s\n", object_path, interface_name);
g_dbus_proxy_new (priv->connection,
G_DBUS_PROXY_FLAGS_NONE,
NULL, /* GDBusInterfaceInfo* */

View file

@ -53,25 +53,24 @@
<method name='Disconnect'/>
<!-- CreateSourceOutput:
@source: the Source1 object path or / for default
@props: input properties
@incaps: input capabilities
@output: the SourceOutput1 object path
Create a new output for @source with given @props
Create a new output for @source with given @incaps
-->
<method name='CreateSourceOutput'>
<arg type='o' name='source' direction='in'/>
<arg type='a{sv}' name='props' direction='in'/>
<arg type='s' name='accepted_formats' direction='in'/>
<arg type='o' name='output' direction='out'/>
</method>
<!-- CreateSourceInput:
@props: input properties
@source: the new Source1 object path
@incaps: input capabilities
@input: the SourceInput1 object path
Create a new source and input object with given @props
Create a new source and input object with given @incaps
-->
<method name='CreateSourceInput'>
<arg type='a{sv}' name='props' direction='in'/>
<arg type='s' name='possible_formats' direction='in'/>
<arg type='o' name='input' direction='out'/>
</method>
</interface>
@ -122,18 +121,12 @@
4 = the source is running
-->
<property name='State' type='u' access='read' />
<!-- GetCapabilities:
@props: input properties
@caps: result capabilities
<!-- Capabilities:
Get a list of capabilities of this source. This includes
supported data formats and transports. @props is used to
filter the amount of output capabilities
The capabilities of this source. This includes
supported data formats and transports.
-->
<method name='GetCapabilities'>
<arg type='a{sv}' name='props' direction='in'/>
<arg type='aa{sv}' name='caps' direction='out'/>
</method>
<property name='PossibleFormats' type='s' access='read' />
</interface>
<!--
@ -144,34 +137,28 @@
start/stop the media transport.
-->
<interface name='org.pulsevideo.SourceOutput1'>
<!-- Client: the owner client of this source output -->
<property name='Client' type='o' access='read' />
<!-- Source: the source of this source output -->
<property name='Source' type='o' access='read' />
<!-- Capabilities: capabilities of the source output -->
<property name='PossibleFormats' type='s' access='read' />
<!-- Start:
@props: input properties
@incaps: input capabilities
@fd: output file descriptor
@props: output properties
@outcaps: output capabilities
Start the datatransfer of the source with @props.
Start the datatransfer of the source with @incaps.
The result is a file descriptor that can be used to get metadata
and media. @props contains the final media format and transport
and media. @outcaps contains the final media format and transport
properties.
-->
<method name='Start'>
<arg type='a{sv}' name='props' direction='in'/>
<arg type='s' name='requested_format' direction='in'/>
<arg type='h' name='fd' direction='out'/>
<arg type='a{sv}' name='props' direction='out'/>
<arg type='s' name='format' direction='out'/>
</method>
<!-- RequestReconfigure:
@props: new properties
This signal is fired when the source wants to change the format
or transport. The client should Stop and Start the source output
with new properties
-->
<signal name='RequestReconfigure'>
<arg type='a{sv}' name='props' direction='in'/>
</signal>
<!-- Stop:
Stop data transport

View file

@ -80,8 +80,6 @@ static gboolean gst_pulsevideo_sink_setcaps (GstBaseSink * bsink, GstCaps * caps
static GstCaps *gst_pulsevideo_sink_sink_fixate (GstBaseSink * bsink,
GstCaps * caps);
static gboolean gst_pulsevideo_sink_propose_allocation (GstBaseSink * bsink,
GstQuery * query);
static GstFlowReturn gst_pulsevideo_sink_render (GstBaseSink * psink,
GstBuffer * buffer);
static gboolean gst_pulsevideo_sink_start (GstBaseSink * basesink);
@ -116,7 +114,6 @@ gst_pulsevideo_sink_class_init (GstPulsevideoSinkClass * klass)
gstbasesink_class->start = gst_pulsevideo_sink_start;
gstbasesink_class->stop = gst_pulsevideo_sink_stop;
gstbasesink_class->render = gst_pulsevideo_sink_render;
gstbasesink_class->propose_allocation = gst_pulsevideo_sink_propose_allocation;
GST_DEBUG_CATEGORY_INIT (pulsevideo_sink_debug, "pulsevideosink", 0,
"Pulsevideo Sink");
@ -189,59 +186,6 @@ gst_pulsevideo_sink_get_property (GObject * object, guint prop_id,
}
}
static gboolean
gst_pulsevideo_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
{
GstPulsevideoSink *pvsink;
GstBufferPool *pool;
gboolean update;
guint size, min, max;
GstStructure *config;
GstCaps *caps = NULL;
pvsink = GST_PULSEVIDEO_SINK (bsink);
if (gst_query_get_n_allocation_pools (query) > 0) {
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
/* adjust size */
size = MAX (size, pvsink->info.size);
update = TRUE;
} else {
pool = NULL;
size = pvsink->info.size;
min = max = 0;
update = FALSE;
}
/* no downstream pool, make our own */
if (pool == NULL) {
pool = gst_video_buffer_pool_new ();
}
config = gst_buffer_pool_get_config (pool);
gst_query_parse_allocation (query, &caps, NULL);
if (caps)
gst_buffer_pool_config_set_params (config, caps, size, min, max);
if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
gst_buffer_pool_config_add_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_META);
}
gst_buffer_pool_set_config (pool, config);
if (update)
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
else
gst_query_add_allocation_pool (query, pool, size, min, max);
if (pool)
gst_object_unref (pool);
return GST_BASE_SINK_CLASS (parent_class)->propose_allocation (bsink, query);
}
static void
on_new_buffer (GObject *gobject,
gpointer user_data)
@ -283,46 +227,20 @@ gst_pulsevideo_sink_getcaps (GstBaseSink * bsink, GstCaps * filter)
static gboolean
gst_pulsevideo_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
{
const GstStructure *structure;
GstPulsevideoSink *pvsink;
GstVideoInfo info;
GVariantBuilder builder;
gchar *str;
GBytes *format;
pvsink = GST_PULSEVIDEO_SINK (bsink);
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw")) {
/* we can use the parsing code */
if (!gst_video_info_from_caps (&info, caps))
goto parse_failed;
} else {
goto unsupported_caps;
}
/* looks ok here */
pvsink->info = info;
pvsink->stream = pv_stream_new (pvsink->ctx, "test", NULL);
g_signal_connect (pvsink->stream, "notify::state", (GCallback) on_stream_notify, pvsink);
g_signal_connect (pvsink->stream, "new-buffer", (GCallback) on_new_buffer, pvsink);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "format.encoding", g_variant_new_string ("video/x-raw"));
g_variant_builder_add (&builder, "{sv}", "format.format",
g_variant_new_string (gst_video_format_to_string (info.finfo->format)));
g_variant_builder_add (&builder, "{sv}", "format.width", g_variant_new_int32 (info.width));
g_variant_builder_add (&builder, "{sv}", "format.height", g_variant_new_int32 (info.height));
g_variant_builder_add (&builder, "{sv}", "format.views", g_variant_new_int32 (info.views));
// g_variant_builder_add (&builder, "{sv}", "format.chroma-site",
// g_variant_new_string (gst_video_chroma_to_string (info.chroma_site)));
// g_variant_builder_add (&builder, "{sv}", "format.colorimetry",
// g_variant_new_take_string (gst_video_colorimetry_to_string (&info.colorimetry)));
// g_variant_builder_add (&builder, "{sv}", "format.interlace-mode",
// g_variant_new_string (gst_video_interlace_mode_to_string (info.interlace_mode)));
str = gst_caps_to_string (caps);
format = g_bytes_new_take (str, strlen (str) + 1);
pv_stream_connect_provide (pvsink->stream, 0, g_variant_builder_end (&builder));
pv_stream_connect_provide (pvsink->stream, 0, format);
g_mutex_lock (&pvsink->lock);
while (TRUE) {
@ -338,24 +256,11 @@ gst_pulsevideo_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
}
g_mutex_unlock (&pvsink->lock);
pv_stream_start (pvsink->stream, PV_STREAM_MODE_BUFFER);
GST_DEBUG_OBJECT (pvsink, "size %dx%d, %d/%d fps",
info.width, info.height, info.fps_n, info.fps_d);
pv_stream_start (pvsink->stream, format, PV_STREAM_MODE_BUFFER);
pvsink->negotiated = TRUE;
return TRUE;
/* ERRORS */
parse_failed:
{
GST_DEBUG_OBJECT (bsink, "failed to parse caps");
return FALSE;
}
unsupported_caps:
{
GST_DEBUG_OBJECT (bsink, "unsupported caps: %" GST_PTR_FORMAT, caps);
return FALSE;
}
connect_error:
{
g_mutex_unlock (&pvsink->lock);
@ -373,8 +278,7 @@ gst_pulsevideo_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
pvsink = GST_PULSEVIDEO_SINK (bsink);
if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&pvsink->info) ==
GST_VIDEO_FORMAT_UNKNOWN))
if (!pvsink->negotiated)
goto not_negotiated;
info.flags = 0;
@ -424,7 +328,7 @@ gst_pulsevideo_sink_start (GstBaseSink * basesink)
{
GstPulsevideoSink *sink = GST_PULSEVIDEO_SINK (basesink);
gst_video_info_init (&sink->info);
sink->negotiated = FALSE;
return TRUE;
}
@ -432,6 +336,10 @@ gst_pulsevideo_sink_start (GstBaseSink * basesink)
static gboolean
gst_pulsevideo_sink_stop (GstBaseSink * basesink)
{
GstPulsevideoSink *sink = GST_PULSEVIDEO_SINK (basesink);
sink->negotiated = FALSE;
return TRUE;
}

View file

@ -58,7 +58,7 @@ struct _GstPulsevideoSink {
/*< private >*/
/* video state */
GstVideoInfo info;
gboolean negotiated;
GMainContext *context;
GMainLoop *loop;

View file

@ -80,10 +80,6 @@ static gboolean gst_pulsevideo_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps);
static GstCaps *gst_pulsevideo_src_src_fixate (GstBaseSrc * bsrc,
GstCaps * caps);
static gboolean gst_pulsevideo_src_query (GstBaseSrc * bsrc, GstQuery * query);
static gboolean gst_pulsevideo_src_decide_allocation (GstBaseSrc * bsrc,
GstQuery * query);
static GstFlowReturn gst_pulsevideo_src_create (GstPushSrc * psrc,
GstBuffer ** buffer);
static gboolean gst_pulsevideo_src_start (GstBaseSrc * basesrc);
@ -118,10 +114,8 @@ gst_pulsevideo_src_class_init (GstPulsevideoSrcClass * klass)
gstbasesrc_class->get_caps = gst_pulsevideo_src_getcaps;
gstbasesrc_class->set_caps = gst_pulsevideo_src_setcaps;
gstbasesrc_class->fixate = gst_pulsevideo_src_src_fixate;
gstbasesrc_class->query = gst_pulsevideo_src_query;
gstbasesrc_class->start = gst_pulsevideo_src_start;
gstbasesrc_class->stop = gst_pulsevideo_src_stop;
gstbasesrc_class->decide_allocation = gst_pulsevideo_src_decide_allocation;
gstpushsrc_class->create = gst_pulsevideo_src_create;
@ -200,59 +194,6 @@ gst_pulsevideo_src_get_property (GObject * object, guint prop_id,
}
}
static gboolean
gst_pulsevideo_src_decide_allocation (GstBaseSrc * bsrc, GstQuery * query)
{
GstPulsevideoSrc *pvsrc;
GstBufferPool *pool;
gboolean update;
guint size, min, max;
GstStructure *config;
GstCaps *caps = NULL;
pvsrc = GST_PULSEVIDEO_SRC (bsrc);
if (gst_query_get_n_allocation_pools (query) > 0) {
gst_query_parse_nth_allocation_pool (query, 0, &pool, &size, &min, &max);
/* adjust size */
size = MAX (size, pvsrc->info.size);
update = TRUE;
} else {
pool = NULL;
size = pvsrc->info.size;
min = max = 0;
update = FALSE;
}
/* no downstream pool, make our own */
if (pool == NULL) {
pool = gst_video_buffer_pool_new ();
}
config = gst_buffer_pool_get_config (pool);
gst_query_parse_allocation (query, &caps, NULL);
if (caps)
gst_buffer_pool_config_set_params (config, caps, size, min, max);
if (gst_query_find_allocation_meta (query, GST_VIDEO_META_API_TYPE, NULL)) {
gst_buffer_pool_config_add_option (config,
GST_BUFFER_POOL_OPTION_VIDEO_META);
}
gst_buffer_pool_set_config (pool, config);
if (update)
gst_query_set_nth_allocation_pool (query, 0, pool, size, min, max);
else
gst_query_add_allocation_pool (query, pool, size, min, max);
if (pool)
gst_object_unref (pool);
return GST_BASE_SRC_CLASS (parent_class)->decide_allocation (bsrc, query);
}
static void
on_new_buffer (GObject *gobject,
gpointer user_data)
@ -284,117 +225,108 @@ on_stream_notify (GObject *gobject,
g_mutex_unlock (&pvsrc->lock);
}
static gboolean
source_info_callback (PvContext *c, const PvSourceInfo *info, gpointer user_data)
{
GstPulsevideoSrc *pvsrc = user_data;
if (info == NULL) {
return TRUE;
}
g_print ("source %s %p\n", info->name, pvsrc);
return TRUE;
}
static gboolean
gst_pulsevideo_src_negotiate (GstBaseSrc * basesrc)
{
GstPulsevideoSrc *pvsrc = GST_PULSEVIDEO_SRC (basesrc);
GstCaps *thiscaps;
GstCaps *caps = NULL;
GstCaps *peercaps = NULL;
gboolean result = FALSE;
pv_context_list_source_info (pvsrc->ctx,
PV_SOURCE_INFO_FLAGS_CAPABILITIES,
source_info_callback,
NULL,
pvsrc);
/* first see what is possible on our source pad */
thiscaps = gst_pad_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
GST_DEBUG_OBJECT (basesrc, "caps of src: %" GST_PTR_FORMAT, thiscaps);
/* nothing or anything is allowed, we're done */
if (thiscaps == NULL || gst_caps_is_any (thiscaps))
goto no_nego_needed;
return GST_BASE_SRC_CLASS (parent_class)->negotiate (basesrc);
}
static GstCaps *
gst_pulsevideo_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
{
return GST_BASE_SRC_CLASS (parent_class)->get_caps (bsrc, filter);
}
static gboolean
gst_pulsevideo_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
{
const GstStructure *structure;
GstPulsevideoSrc *pvsrc;
GstVideoInfo info;
GVariantBuilder builder;
pvsrc = GST_PULSEVIDEO_SRC (bsrc);
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_name (structure, "video/x-raw")) {
/* we can use the parsing code */
if (!gst_video_info_from_caps (&info, caps))
goto parse_failed;
if (G_UNLIKELY (gst_caps_is_empty (thiscaps)))
goto no_caps;
/* get the peer caps */
peercaps = gst_pad_peer_query_caps (GST_BASE_SRC_PAD (basesrc), thiscaps);
GST_DEBUG_OBJECT (basesrc, "caps of peer: %" GST_PTR_FORMAT, peercaps);
if (peercaps) {
/* The result is already a subset of our caps */
caps = peercaps;
gst_caps_unref (thiscaps);
} else {
goto unsupported_caps;
/* no peer, work with our own caps then */
caps = thiscaps;
}
if (caps && !gst_caps_is_empty (caps)) {
GBytes *accepted, *possible;
gchar *str;
/* looks ok here */
pvsrc->info = info;
GST_DEBUG_OBJECT (basesrc, "have caps: %" GST_PTR_FORMAT, caps);
/* open a connection with these caps */
str = gst_caps_to_string (caps);
accepted = g_bytes_new_take (str, strlen (str) + 1);
pv_stream_connect_capture (pvsrc->stream, NULL, 0, accepted);
pvsrc->stream = pv_stream_new (pvsrc->ctx, "test", NULL);
g_signal_connect (pvsrc->stream, "notify::state", (GCallback) on_stream_notify, pvsrc);
g_signal_connect (pvsrc->stream, "new-buffer", (GCallback) on_new_buffer, pvsrc);
g_mutex_lock (&pvsrc->lock);
while (TRUE) {
PvStreamState state = pv_stream_get_state (pvsrc->stream);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&builder, "{sv}", "format.encoding", g_variant_new_string ("video/x-raw"));
g_variant_builder_add (&builder, "{sv}", "format.format",
g_variant_new_string (gst_video_format_to_string (info.finfo->format)));
g_variant_builder_add (&builder, "{sv}", "format.width", g_variant_new_int32 (info.width));
g_variant_builder_add (&builder, "{sv}", "format.height", g_variant_new_int32 (info.height));
g_variant_builder_add (&builder, "{sv}", "format.views", g_variant_new_int32 (info.views));
// g_variant_builder_add (&builder, "{sv}", "format.chroma-site",
// g_variant_new_string (gst_video_chroma_to_string (info.chroma_site)));
// g_variant_builder_add (&builder, "{sv}", "format.colorimetry",
// g_variant_new_take_string (gst_video_colorimetry_to_string (&info.colorimetry)));
// g_variant_builder_add (&builder, "{sv}", "format.interlace-mode",
// g_variant_new_string (gst_video_interlace_mode_to_string (info.interlace_mode)));
if (state == PV_STREAM_STATE_READY)
break;
pv_stream_connect_capture (pvsrc->stream, NULL, 0, g_variant_builder_end (&builder));
if (state == PV_STREAM_STATE_ERROR)
goto connect_error;
g_mutex_lock (&pvsrc->lock);
while (TRUE) {
PvStreamState state = pv_stream_get_state (pvsrc->stream);
g_cond_wait (&pvsrc->cond, &pvsrc->lock);
}
g_mutex_unlock (&pvsrc->lock);
if (state == PV_STREAM_STATE_READY)
break;
g_object_get (pvsrc->stream, "possible-formats", &possible, NULL);
if (possible) {
GstCaps *newcaps;
if (state == PV_STREAM_STATE_ERROR)
goto connect_error;
g_cond_wait (&pvsrc->cond, &pvsrc->lock);
newcaps = gst_caps_from_string (g_bytes_get_data (possible, NULL));
if (newcaps)
caps = newcaps;
}
/* now fixate */
GST_DEBUG_OBJECT (basesrc, "server fixated caps: %" GST_PTR_FORMAT, caps);
if (gst_caps_is_any (caps)) {
GST_DEBUG_OBJECT (basesrc, "any caps, we stop");
/* hmm, still anything, so element can do anything and
* nego is not needed */
result = TRUE;
} else {
caps = gst_pulsevideo_src_src_fixate (basesrc, caps);
GST_DEBUG_OBJECT (basesrc, "fixated to: %" GST_PTR_FORMAT, caps);
if (gst_caps_is_fixed (caps)) {
/* yay, fixed caps, use those then, it's possible that the subclass does
* not accept this caps after all and we have to fail. */
result = gst_base_src_set_caps (basesrc, caps);
}
}
gst_caps_unref (caps);
} else {
if (caps)
gst_caps_unref (caps);
GST_DEBUG_OBJECT (basesrc, "no common caps");
}
g_mutex_unlock (&pvsrc->lock);
pvsrc->negotiated = result;
return result;
pv_stream_start (pvsrc->stream, PV_STREAM_MODE_BUFFER);
GST_DEBUG_OBJECT (pvsrc, "size %dx%d, %d/%d fps",
info.width, info.height, info.fps_n, info.fps_d);
return TRUE;
/* ERRORS */
parse_failed:
no_nego_needed:
{
GST_DEBUG_OBJECT (bsrc, "failed to parse caps");
return FALSE;
GST_DEBUG_OBJECT (basesrc, "no negotiation needed");
if (thiscaps)
gst_caps_unref (thiscaps);
return TRUE;
}
unsupported_caps:
no_caps:
{
GST_DEBUG_OBJECT (bsrc, "unsupported caps: %" GST_PTR_FORMAT, caps);
return FALSE;
GST_ELEMENT_ERROR (basesrc, STREAM, FORMAT,
("No supported formats found"),
("This element did not produce valid caps"));
if (thiscaps)
gst_caps_unref (thiscaps);
return TRUE;
}
connect_error:
{
@ -403,74 +335,25 @@ connect_error:
}
}
static gboolean
gst_pulsevideo_src_query (GstBaseSrc * bsrc, GstQuery * query)
static GstCaps *
gst_pulsevideo_src_getcaps (GstBaseSrc * bsrc, GstCaps * filter)
{
gboolean res = FALSE;
GstPulsevideoSrc *src;
return GST_BASE_SRC_CLASS (parent_class)->get_caps (bsrc, filter);
}
src = GST_PULSEVIDEO_SRC (bsrc);
static gboolean
gst_pulsevideo_src_setcaps (GstBaseSrc * bsrc, GstCaps * caps)
{
GstPulsevideoSrc *pvsrc;
gchar *str;
GBytes *format;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_CONVERT:
{
GstFormat src_fmt, dest_fmt;
gint64 src_val, dest_val;
pvsrc = GST_PULSEVIDEO_SRC (bsrc);
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
res =
gst_video_info_convert (&src->info, src_fmt, src_val, dest_fmt,
&dest_val);
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
break;
}
case GST_QUERY_LATENCY:
{
if (src->info.fps_n > 0) {
GstClockTime latency;
str = gst_caps_to_string (caps);
format = g_bytes_new_take (str, strlen (str) + 1);
latency =
gst_util_uint64_scale (GST_SECOND, src->info.fps_d,
src->info.fps_n);
gst_query_set_latency (query,
gst_base_src_is_live (GST_BASE_SRC_CAST (src)), latency,
GST_CLOCK_TIME_NONE);
GST_DEBUG_OBJECT (src, "Reporting latency of %" GST_TIME_FORMAT,
GST_TIME_ARGS (latency));
res = TRUE;
}
break;
}
case GST_QUERY_DURATION:{
if (bsrc->num_buffers != -1) {
GstFormat format;
gst_query_parse_duration (query, &format, NULL);
switch (format) {
case GST_FORMAT_TIME:{
gint64 dur = gst_util_uint64_scale_int_round (bsrc->num_buffers
* GST_SECOND, src->info.fps_d, src->info.fps_n);
res = TRUE;
gst_query_set_duration (query, GST_FORMAT_TIME, dur);
goto done;
}
case GST_FORMAT_BYTES:
res = TRUE;
gst_query_set_duration (query, GST_FORMAT_BYTES,
bsrc->num_buffers * src->info.size);
goto done;
default:
break;
}
}
/* fall through */
}
default:
res = GST_BASE_SRC_CLASS (parent_class)->query (bsrc, query);
break;
}
done:
return res;
return pv_stream_start (pvsrc->stream, format, PV_STREAM_MODE_BUFFER);
}
static GstFlowReturn
@ -481,8 +364,7 @@ gst_pulsevideo_src_create (GstPushSrc * psrc, GstBuffer ** buffer)
pvsrc = GST_PULSEVIDEO_SRC (psrc);
if (G_UNLIKELY (GST_VIDEO_INFO_FORMAT (&pvsrc->info) ==
GST_VIDEO_FORMAT_UNKNOWN))
if (!pvsrc->negotiated)
goto not_negotiated;
g_mutex_lock (&pvsrc->lock);
@ -516,10 +398,6 @@ not_negotiated:
static gboolean
gst_pulsevideo_src_start (GstBaseSrc * basesrc)
{
GstPulsevideoSrc *src = GST_PULSEVIDEO_SRC (basesrc);
gst_video_info_init (&src->info);
return TRUE;
}
@ -585,6 +463,10 @@ gst_pulsevideo_src_open (GstPulsevideoSrc * pvsrc)
}
g_mutex_unlock (&pvsrc->lock);
pvsrc->stream = pv_stream_new (pvsrc->ctx, "test", NULL);
g_signal_connect (pvsrc->stream, "notify::state", (GCallback) on_stream_notify, pvsrc);
g_signal_connect (pvsrc->stream, "new-buffer", (GCallback) on_new_buffer, pvsrc);
return TRUE;
/* ERRORS */
@ -607,13 +489,13 @@ gst_pulsevideo_src_change_state (GstElement * element, GstStateChange transition
g_print ("context %p\n", this->context);
this->loop = g_main_loop_new (this->context, FALSE);
this->thread = g_thread_new ("pulsevideo", (GThreadFunc) handle_mainloop, this);
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
if (!gst_pulsevideo_src_open (this)) {
ret = GST_STATE_CHANGE_FAILURE;
goto exit;
}
break;
case GST_STATE_CHANGE_READY_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
/* uncork and start recording */
break;
@ -630,6 +512,7 @@ gst_pulsevideo_src_change_state (GstElement * element, GstStateChange transition
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
this->negotiated = FALSE;
break;
case GST_STATE_CHANGE_READY_TO_NULL:
g_main_loop_quit (this->loop);

View file

@ -57,8 +57,7 @@ struct _GstPulsevideoSrc {
/*< private >*/
/* video state */
GstVideoInfo info;
gboolean negotiated;
GMainContext *context;
GMainLoop *loop;

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <gst/gst.h>
#include <gio/gio.h>
@ -32,6 +33,8 @@ struct _PvV4l2SourcePrivate
GstElement *filter;
GstElement *sink;
GstCaps *possible_formats;
GSocket *socket;
};
@ -90,18 +93,20 @@ setup_pipeline (PvV4l2Source *source)
gst_object_unref (bus);
}
static void
collect_capabilities (PvSource * source)
static GstCaps *
collect_caps (PvSource * source, GstCaps *filter)
{
PvV4l2SourcePrivate *priv = PV_V4L2_SOURCE (source)->priv;
GstCaps *res;
GstQuery *query;
query = gst_query_new_caps (NULL);
query = gst_query_new_caps (filter);
gst_element_query (priv->src, query);
gst_query_parse_caps_result (query, &res);
g_print ("%s\n", gst_caps_to_string (res));
gst_caps_ref (res);
gst_query_unref (query);
return res;
}
static gboolean
@ -116,7 +121,6 @@ v4l2_set_state (PvSource *source, PvSourceState state)
case PV_SOURCE_STATE_INIT:
gst_element_set_state (priv->pipeline, GST_STATE_READY);
collect_capabilities (source);
break;
case PV_SOURCE_STATE_IDLE:
@ -134,8 +138,8 @@ v4l2_set_state (PvSource *source, PvSourceState state)
return TRUE;
}
static GVariant *
v4l2_get_capabilities (PvSource *source, GVariant *props)
static GBytes *
v4l2_get_capabilities (PvSource *source, GBytes *filter)
{
return NULL;
}
@ -149,6 +153,8 @@ on_socket_notify (GObject *gobject,
PvV4l2SourcePrivate *priv = source->priv;
GSocket *socket;
guint num_handles;
GstCaps *caps;
GBytes *requested_format;
g_object_get (gobject, "socket", &socket, NULL);
@ -162,6 +168,18 @@ on_socket_notify (GObject *gobject,
}
priv->socket = socket;
g_object_get (gobject, "requested-format", &requested_format, NULL);
g_assert (requested_format != NULL);
g_object_set (gobject, "format", requested_format, NULL);
g_print ("final format %s\n", g_bytes_get_data (requested_format, NULL));
caps = gst_caps_from_string (g_bytes_get_data (requested_format, NULL));
g_assert (caps != NULL);
g_object_set (priv->filter, "caps", caps, NULL);
gst_caps_unref (caps);
g_bytes_unref (requested_format);
g_object_get (priv->sink, "num-handles", &num_handles, NULL);
if (num_handles == 0) {
gst_element_set_state (priv->pipeline, GST_STATE_READY);
@ -171,53 +189,45 @@ on_socket_notify (GObject *gobject,
}
static PvSourceOutput *
v4l2_create_source_output (PvSource *source, GVariant *props, const gchar *prefix)
v4l2_create_source_output (PvSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix)
{
PvV4l2SourcePrivate *priv = PV_V4L2_SOURCE (source)->priv;
PvSourceOutput *output;
GVariantDict dict;
GstCaps *caps;
const gchar *str;
gint32 i32;
GstCaps *caps, *filtered;
gchar *str;
g_variant_dict_init (&dict, props);
if (!g_variant_dict_lookup (&dict, "format.encoding", "&s", &str))
goto invalid_encoding;
caps = gst_caps_new_empty_simple (str);
if (g_variant_dict_lookup (&dict, "format.format", "&s", &str))
gst_caps_set_simple (caps, "format", G_TYPE_STRING, str, NULL);
if (g_variant_dict_lookup (&dict, "format.width", "i", &i32))
gst_caps_set_simple (caps, "width", G_TYPE_INT, (gint) i32, NULL);
if (g_variant_dict_lookup (&dict, "format.height", "i", &i32))
gst_caps_set_simple (caps, "height", G_TYPE_INT, (gint) i32, NULL);
if (g_variant_dict_lookup (&dict, "format.views", "i", &i32))
gst_caps_set_simple (caps, "views", G_TYPE_INT, (gint) i32, NULL);
if (g_variant_dict_lookup (&dict, "format.chroma-site", "&s", &str))
gst_caps_set_simple (caps, "chroma-site", G_TYPE_STRING, str, NULL);
if (g_variant_dict_lookup (&dict, "format.colorimetry", "&s", &str))
gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, str, NULL);
if (g_variant_dict_lookup (&dict, "format.interlace-mode", "&s", &str))
gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING, str, NULL);
g_print ("caps %s\n", gst_caps_to_string (caps));
g_object_set (priv->filter, "caps", caps, NULL);
gst_caps_unref (caps);
output = PV_SOURCE_CLASS (pv_v4l2_source_parent_class)->create_source_output (source, props, prefix);
str = (gchar *) g_bytes_get_data (format_filter, NULL);
g_print ("input filter %s\n", str);
caps = gst_caps_from_string (str);
if (caps == NULL)
goto invalid_caps;
gst_element_set_state (priv->pipeline, GST_STATE_READY);
filtered = collect_caps (source, caps);
if (filtered == NULL || gst_caps_is_empty (filtered))
goto no_format;
str = gst_caps_to_string (filtered);
g_print ("output filter %s\n", str);
format_filter = g_bytes_new_take (str, strlen (str) + 1);
output = PV_SOURCE_CLASS (pv_v4l2_source_parent_class)->create_source_output (source, client_path, format_filter, prefix);
g_signal_connect (output, "notify::socket", (GCallback) on_socket_notify, source);
return output;
/* ERRORS */
invalid_encoding:
invalid_caps:
{
return NULL;
}
no_format:
{
g_variant_dict_clear (&dict);
return NULL;
}
}

View file

@ -20,7 +20,7 @@
#include <gst/gst.h>
#include <gio/gio.h>
#include "server/pv-daemon.h"
#include <server/pv-daemon.h>
#include "pv-client-source.h"
#define PV_CLIENT_SOURCE_GET_PRIVATE(obj) \
@ -102,7 +102,7 @@ collect_capabilities (PvSource * source)
query = gst_query_new_caps (NULL);
gst_element_query (priv->src, query);
gst_query_parse_caps_result (query, &res);
g_print ("%s\n", gst_caps_to_string (res));
g_print ("client source caps: %s\n", gst_caps_to_string (res));
gst_query_unref (query);
}
@ -136,8 +136,8 @@ client_set_state (PvSource *source, PvSourceState state)
return TRUE;
}
static GVariant *
client_get_capabilities (PvSource *source, GVariant *props)
static GBytes *
client_get_capabilities (PvSource *source, GBytes *filter)
{
return NULL;
}
@ -151,6 +151,7 @@ on_socket_notify (GObject *gobject,
PvClientSourcePrivate *priv = source->priv;
GSocket *socket;
guint num_handles;
GBytes *requested_format;
g_object_get (gobject, "socket", &socket, NULL);
@ -164,6 +165,13 @@ on_socket_notify (GObject *gobject,
}
priv->socket = socket;
/* force format on input */
g_object_get (priv->input, "format", &requested_format, NULL);
g_assert (requested_format != NULL);
g_print ("final format %s\n", (gchar *) g_bytes_get_data (requested_format, NULL));
g_object_set (gobject, "format", requested_format, NULL);
g_bytes_unref (requested_format);
g_object_get (priv->sink, "num-handles", &num_handles, NULL);
if (num_handles == 0) {
gst_element_set_state (priv->pipeline, GST_STATE_READY);
@ -173,55 +181,24 @@ on_socket_notify (GObject *gobject,
}
static PvSourceOutput *
client_create_source_output (PvSource *source, GVariant *props, const gchar *prefix)
client_create_source_output (PvSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix)
{
PvClientSourcePrivate *priv = PV_CLIENT_SOURCE (source)->priv;
PvSourceOutput *output;
GVariantDict dict;
GstCaps *caps;
const gchar *str;
gint32 i32;
g_variant_dict_init (&dict, props);
if (!g_variant_dict_lookup (&dict, "format.encoding", "&s", &str))
goto invalid_encoding;
/* propose format of input */
g_object_get (priv->input, "format", &format_filter, NULL);
caps = gst_caps_new_empty_simple (str);
if (g_variant_dict_lookup (&dict, "format.format", "&s", &str))
gst_caps_set_simple (caps, "format", G_TYPE_STRING, str, NULL);
if (g_variant_dict_lookup (&dict, "format.width", "i", &i32))
gst_caps_set_simple (caps, "width", G_TYPE_INT, (gint) i32, NULL);
if (g_variant_dict_lookup (&dict, "format.height", "i", &i32))
gst_caps_set_simple (caps, "height", G_TYPE_INT, (gint) i32, NULL);
if (g_variant_dict_lookup (&dict, "format.views", "i", &i32))
gst_caps_set_simple (caps, "views", G_TYPE_INT, (gint) i32, NULL);
if (g_variant_dict_lookup (&dict, "format.chroma-site", "&s", &str))
gst_caps_set_simple (caps, "chroma-site", G_TYPE_STRING, str, NULL);
if (g_variant_dict_lookup (&dict, "format.colorimetry", "&s", &str))
gst_caps_set_simple (caps, "colorimetry", G_TYPE_STRING, str, NULL);
if (g_variant_dict_lookup (&dict, "format.interlace-mode", "&s", &str))
gst_caps_set_simple (caps, "interlace-mode", G_TYPE_STRING, str, NULL);
g_print ("caps %s\n", gst_caps_to_string (caps));
g_object_set (priv->filter, "caps", caps, NULL);
gst_caps_unref (caps);
output = PV_SOURCE_CLASS (pv_client_source_parent_class)->create_source_output (source, props, prefix);
output = PV_SOURCE_CLASS (pv_client_source_parent_class)->create_source_output (source, client_path, format_filter, prefix);
gst_element_set_state (priv->pipeline, GST_STATE_READY);
g_signal_connect (output, "notify::socket", (GCallback) on_socket_notify, source);
return output;
/* ERRORS */
invalid_encoding:
{
g_variant_dict_clear (&dict);
return NULL;
}
}
static gboolean
@ -245,14 +222,31 @@ on_input_socket_notify (GObject *gobject,
PvClientSource *source = user_data;
PvClientSourcePrivate *priv = source->priv;
GSocket *socket;
GBytes *requested_format;
GstCaps *caps;
g_object_get (gobject, "socket", &socket, NULL);
g_print ("input socket %p\n", socket);
g_object_get (gobject, "requested-format", &requested_format, NULL);
g_assert (requested_format != NULL);
g_print ("final format %s\n", (gchar *) g_bytes_get_data (requested_format, NULL));
g_object_set (gobject, "format", requested_format, NULL);
caps = gst_caps_from_string (g_bytes_get_data (requested_format, NULL));
g_assert (caps != NULL);
g_object_set (priv->filter, "caps", caps, NULL);
gst_caps_unref (caps);
g_bytes_unref (requested_format);
g_object_set (priv->src, "socket", socket, NULL);
}
PvSourceOutput *
pv_client_source_get_source_input (PvClientSource *source, GVariant *props, const gchar *prefix)
pv_client_source_get_source_input (PvClientSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix)
{
PvClientSourcePrivate *priv;
@ -260,7 +254,7 @@ pv_client_source_get_source_input (PvClientSource *source, GVariant *props, cons
priv = source->priv;
if (priv->input == NULL) {
priv->input = PV_SOURCE_CLASS (pv_client_source_parent_class)->create_source_output (PV_SOURCE (source), props, prefix);
priv->input = PV_SOURCE_CLASS (pv_client_source_parent_class)->create_source_output (PV_SOURCE (source), client_path, format_filter, prefix);
g_signal_connect (priv->input, "notify::socket", (GCallback) on_input_socket_notify, source);
}
return priv->input;

View file

@ -66,8 +66,9 @@ GType pv_client_source_get_type (void);
PvSource * pv_client_source_new (PvDaemon *daemon);
PvSourceOutput * pv_client_source_get_source_input (PvClientSource *source,
GVariant *props,
const gchar *prefix);
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix);
G_END_DECLS

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include "client/pulsevideo.h"
#include "client/pv-enumtypes.h"
@ -31,6 +32,7 @@ struct _PvClientPrivate
PvDaemon *daemon;
gchar *sender;
gchar *object_path;
GVariant *properties;
PvClient1 *client1;
};
@ -46,6 +48,7 @@ enum
PROP_DAEMON,
PROP_SENDER,
PROP_OBJECT_PATH,
PROP_PROPERTIES,
};
static void
@ -70,6 +73,10 @@ pv_client_get_property (GObject *_object,
g_value_set_string (value, priv->object_path);
break;
case PROP_PROPERTIES:
g_value_set_variant (value, priv->properties);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (client, prop_id, pspec);
break;
@ -98,6 +105,12 @@ pv_client_set_property (GObject *_object,
priv->object_path = g_value_dup_string (value);
break;
case PROP_PROPERTIES:
if (priv->properties)
g_variant_unref (priv->properties);
priv->properties = g_value_dup_variant (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (client, prop_id, pspec);
break;
@ -108,7 +121,7 @@ static gboolean
handle_create_source_output (PvClient1 *interface,
GDBusMethodInvocation *invocation,
const gchar *arg_source,
GVariant *arg_properties,
const gchar *arg_accepted_formats,
gpointer user_data)
{
PvClient *client = user_data;
@ -116,12 +129,15 @@ handle_create_source_output (PvClient1 *interface,
PvSource *source;
PvSourceOutput *output;
const gchar *object_path, *sender;
GBytes *formats;
source = pv_daemon_find_source (priv->daemon, arg_source, arg_properties);
formats = g_bytes_new (arg_accepted_formats, strlen (arg_accepted_formats) + 1);
source = pv_daemon_find_source (priv->daemon, arg_source, priv->properties, formats);
if (source == NULL)
goto no_source;
output = pv_source_create_source_output (source, arg_properties, priv->object_path);
output = pv_source_create_source_output (source, priv->object_path, formats, priv->object_path);
if (output == NULL)
goto no_output;
@ -153,7 +169,7 @@ no_output:
static gboolean
handle_create_source_input (PvClient1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
const gchar *arg_possible_formats,
gpointer user_data)
{
PvClient *client = user_data;
@ -161,6 +177,7 @@ handle_create_source_input (PvClient1 *interface,
PvSource *source;
PvSourceOutput *input;
const gchar *source_input_path, *sender;
GBytes *formats;
source = pv_client_source_new (priv->daemon);
if (source == NULL)
@ -170,7 +187,12 @@ handle_create_source_input (PvClient1 *interface,
pv_daemon_track_object (priv->daemon, sender, G_OBJECT (source));
input = pv_client_source_get_source_input (PV_CLIENT_SOURCE (source), arg_properties, priv->object_path);
formats = g_bytes_new (arg_possible_formats, strlen (arg_possible_formats) + 1);
input = pv_client_source_get_source_input (PV_CLIENT_SOURCE (source),
priv->object_path,
formats,
priv->object_path);
if (input == NULL)
goto no_input;
@ -179,7 +201,7 @@ handle_create_source_input (PvClient1 *interface,
source_input_path = pv_source_output_get_object_path (input);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(o)",
source_input_path));
source_input_path));
return TRUE;
@ -240,9 +262,13 @@ static void
pv_client_finalize (GObject * object)
{
PvClient *client = PV_CLIENT (object);
PvClientPrivate *priv = client->priv;
client_unregister_object (client);
if (priv->properties)
g_variant_unref (priv->properties);
G_OBJECT_CLASS (pv_client_parent_class)->finalize (object);
}
@ -298,6 +324,15 @@ pv_client_class_init (PvClientClass * klass)
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_PROPERTIES,
g_param_spec_variant ("properties",
"Properties",
"Client properties",
G_VARIANT_TYPE_DICTIONARY,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
}
static void
@ -317,12 +352,19 @@ pv_client_init (PvClient * client)
* Returns: a new #PvClient
*/
PvClient *
pv_client_new (PvDaemon * daemon, const gchar *sender, const gchar *prefix)
pv_client_new (PvDaemon *daemon,
const gchar *sender,
const gchar *prefix,
GVariant *properties)
{
g_return_val_if_fail (PV_IS_DAEMON (daemon), NULL);
g_return_val_if_fail (g_variant_is_object_path (prefix), NULL);
return g_object_new (PV_TYPE_CLIENT, "daemon", daemon, "sender", sender, "object-path", prefix, NULL);
return g_object_new (PV_TYPE_CLIENT, "daemon", daemon,
"sender", sender,
"object-path", prefix,
"properties", properties,
NULL);
}
/**

View file

@ -62,7 +62,10 @@ struct _PvClientClass {
/* normal GObject stuff */
GType pv_client_get_type (void);
PvClient * pv_client_new (PvDaemon *daemon, const gchar *sender, const gchar *prefix);
PvClient * pv_client_new (PvDaemon *daemon,
const gchar *sender,
const gchar *prefix,
GVariant *properties);
const gchar * pv_client_get_object_path (PvClient *client);

View file

@ -150,7 +150,7 @@ handle_connect_client (PvDaemon1 *interface,
sender = g_dbus_method_invocation_get_sender (invocation);
g_print ("connect client %s\n", sender);
client = pv_client_new (daemon, sender, PV_DBUS_OBJECT_PREFIX);
client = pv_client_new (daemon, sender, PV_DBUS_OBJECT_PREFIX, arg_properties);
pv_daemon_track_object (daemon, sender, G_OBJECT (client));
@ -368,7 +368,10 @@ pv_daemon_remove_source (PvDaemon *daemon, PvSource *source)
}
PvSource *
pv_daemon_find_source (PvDaemon *daemon, const gchar *name, GVariant *props)
pv_daemon_find_source (PvDaemon *daemon,
const gchar *name,
GVariant *props,
GBytes *format_filter)
{
PvDaemonPrivate *priv;

View file

@ -75,7 +75,10 @@ void pv_daemon_track_object (PvDaemon *daemon, const gchar *sen
void pv_daemon_add_source (PvDaemon *daemon, PvSource *source);
void pv_daemon_remove_source (PvDaemon *daemon, PvSource *source);
PvSource * pv_daemon_find_source (PvDaemon *daemon, const gchar *name, GVariant *props);
PvSource * pv_daemon_find_source (PvDaemon *daemon,
const gchar *name,
GVariant *props,
GBytes *format_filter);
G_END_DECLS

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <sys/socket.h>
#include <gio/gunixfdlist.h>
@ -31,9 +32,15 @@
struct _PvSourceOutputPrivate
{
PvDaemon *daemon;
PvSourceOutput1 *iface;
gchar *object_path;
gchar *source;
gchar *client_path;
gchar *source_path;
GBytes *possible_formats;
GBytes *requested_format;
GBytes *format;
GSocket *socket;
};
@ -48,7 +55,11 @@ enum
PROP_0,
PROP_DAEMON,
PROP_OBJECT_PATH,
PROP_SOURCE,
PROP_CLIENT_PATH,
PROP_SOURCE_PATH,
PROP_POSSIBLE_FORMATS,
PROP_REQUESTED_FORMAT,
PROP_FORMAT,
PROP_SOCKET,
};
@ -70,8 +81,24 @@ pv_source_output_get_property (GObject *_object,
g_value_set_string (value, priv->object_path);
break;
case PROP_SOURCE:
g_value_set_string (value, priv->source);
case PROP_CLIENT_PATH:
g_value_set_string (value, priv->client_path);
break;
case PROP_SOURCE_PATH:
g_value_set_string (value, priv->source_path);
break;
case PROP_POSSIBLE_FORMATS:
g_value_set_boxed (value, priv->possible_formats);
break;
case PROP_REQUESTED_FORMAT:
g_value_set_boxed (value, priv->requested_format);
break;
case PROP_FORMAT:
g_value_set_boxed (value, priv->format);
break;
case PROP_SOCKET:
@ -102,8 +129,28 @@ pv_source_output_set_property (GObject *_object,
priv->object_path = g_value_dup_string (value);
break;
case PROP_SOURCE:
priv->source = g_value_dup_string (value);
case PROP_CLIENT_PATH:
priv->client_path = g_value_dup_string (value);
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);
break;
case PROP_POSSIBLE_FORMATS:
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
priv->possible_formats = g_value_dup_boxed (value);
g_object_set (priv->iface, "possible-formats",
g_bytes_get_data (priv->possible_formats, NULL), NULL);
break;
case PROP_FORMAT:
if (priv->format)
g_bytes_unref (priv->format);
priv->format = g_value_dup_boxed (value);
break;
default:
@ -115,32 +162,45 @@ pv_source_output_set_property (GObject *_object,
static gboolean
handle_start (PvSourceOutput1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
const gchar *arg_requested_format,
gpointer user_data)
{
PvSourceOutput *output = user_data;
PvSourceOutputPrivate *priv = output->priv;
GUnixFDList *fdlist;
GVariantBuilder props;
gint fd[2];
priv->requested_format = g_bytes_new (arg_requested_format, strlen (arg_requested_format) + 1);
socketpair (AF_UNIX, SOCK_STREAM, 0, fd);
priv->socket = g_socket_new_from_fd (fd[0], NULL);
g_object_notify (G_OBJECT (output), "socket");
g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}"));
g_variant_builder_add (&props, "{sv}", "name", g_variant_new_string ("hello"));
if (priv->format == NULL)
goto no_format;
fdlist = g_unix_fd_list_new ();
g_unix_fd_list_append (fdlist, fd[1], NULL);
g_dbus_method_invocation_return_value_with_unix_fd_list (invocation,
g_variant_new ("(h@a{sv})",
g_variant_new ("(hs)",
0,
g_variant_builder_end (&props)),
g_bytes_get_data (priv->format, NULL)),
fdlist);
return TRUE;
/* error */
no_format:
{
g_dbus_method_invocation_return_dbus_error (invocation,
"org.pulsevideo.Error", "No format");
close (fd[0]);
close (fd[1]);
g_clear_pointer (&priv->requested_format, g_bytes_unref);
g_clear_object (&priv->socket);
return TRUE;
}
}
static void
@ -150,6 +210,8 @@ stop_transfer (PvSourceOutput *output)
if (priv->socket) {
g_clear_object (&priv->socket);
g_clear_pointer (&priv->requested_format, g_bytes_unref);
g_clear_pointer (&priv->format, g_bytes_unref);
g_object_notify (G_OBJECT (output), "socket");
}
}
@ -193,17 +255,7 @@ output_register_object (PvSourceOutput *output, const gchar *prefix)
skel = pv_object_skeleton_new (name);
g_free (name);
{
PvSourceOutput1 *iface;
iface = pv_source_output1_skeleton_new ();
g_object_set (iface, "source", priv->source, NULL);
g_signal_connect (iface, "handle-start", (GCallback) handle_start, output);
g_signal_connect (iface, "handle-stop", (GCallback) handle_stop, output);
g_signal_connect (iface, "handle-remove", (GCallback) handle_remove, output);
pv_object_skeleton_set_source_output1 (skel, iface);
g_object_unref (iface);
}
pv_object_skeleton_set_source_output1 (skel, priv->iface);
g_free (priv->object_path);
priv->object_path = pv_daemon_export_uniquely (priv->daemon, G_DBUS_OBJECT_SKELETON (skel));
@ -228,8 +280,10 @@ pv_source_output_finalize (GObject * object)
output_unregister_object (output);
g_object_unref (priv->daemon);
g_object_unref (priv->iface);
g_free (priv->client_path);
g_free (priv->object_path);
g_free (priv->source);
g_free (priv->source_path);
G_OBJECT_CLASS (pv_source_output_parent_class)->finalize (object);
}
@ -278,15 +332,52 @@ pv_source_output_class_init (PvSourceOutputClass * klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SOURCE,
g_param_spec_string ("source",
"Source",
PROP_CLIENT_PATH,
g_param_spec_string ("client-path",
"Client Path",
"The client object path",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
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",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
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_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_REQUESTED_FORMAT,
g_param_spec_boxed ("requested-format",
"Requested Format",
"The requested format of the stream",
G_TYPE_BYTES,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
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_READWRITE |
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (gobject_class,
PROP_SOCKET,
g_param_spec_object ("socket",
@ -300,7 +391,12 @@ pv_source_output_class_init (PvSourceOutputClass * klass)
static void
pv_source_output_init (PvSourceOutput * output)
{
output->priv = PV_SOURCE_OUTPUT_GET_PRIVATE (output);
PvSourceOutputPrivate *priv = output->priv = PV_SOURCE_OUTPUT_GET_PRIVATE (output);
priv->iface = pv_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);
}
const gchar *

View file

@ -128,24 +128,6 @@ pv_source_set_property (GObject *_object,
}
}
static gboolean
handle_get_capabilities (PvSource1 *interface,
GDBusMethodInvocation *invocation,
GVariant *arg_properties,
gpointer user_data)
{
PvSource *source = user_data;
GVariant *out_caps;
out_caps = pv_source_get_capabilities (source, arg_properties);
g_dbus_method_invocation_return_value (invocation,
g_variant_new ("(@aa{sv})", out_caps));
return TRUE;
}
static void
source_register_object (PvSource *source)
{
@ -160,9 +142,6 @@ source_register_object (PvSource *source)
"state", priv->state,
"properties", priv->properties,
NULL);
g_signal_connect (priv->iface, "handle-get-capabilities",
(GCallback) handle_get_capabilities,
source);
pv_object_skeleton_set_source1 (skel, priv->iface);
g_free (priv->object_path);
@ -202,19 +181,26 @@ pv_source_finalize (GObject * object)
g_free (priv->object_path);
g_free (priv->name);
g_variant_unref (priv->properties);
if (priv->properties)
g_variant_unref (priv->properties);
G_OBJECT_CLASS (pv_source_parent_class)->finalize (object);
}
static PvSourceOutput *
default_create_source_output (PvSource *source, GVariant *props, const gchar *prefix)
default_create_source_output (PvSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix)
{
PvSourcePrivate *priv = source->priv;
return g_object_new (PV_TYPE_SOURCE_OUTPUT, "daemon", priv->daemon,
"object-path", prefix,
"source", priv->object_path, NULL);
"client-path", client_path,
"source-path", priv->object_path,
"possible-formats", format_filter,
NULL);
}
static gboolean
@ -281,7 +267,7 @@ pv_source_class_init (PvSourceClass * klass)
g_param_spec_variant ("properties",
"Properties",
"The properties of the source",
G_VARIANT_TYPE_VARIANT,
G_VARIANT_TYPE_DICTIONARY,
NULL,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
@ -297,18 +283,18 @@ pv_source_init (PvSource * source)
source->priv = PV_SOURCE_GET_PRIVATE (source);
}
GVariant *
pv_source_get_capabilities (PvSource *source, GVariant *props)
GBytes *
pv_source_get_capabilities (PvSource *source, GBytes *filter)
{
PvSourceClass *klass;
GVariant *res;
GBytes *res;
g_return_val_if_fail (PV_IS_SOURCE (source), NULL);
klass = PV_SOURCE_GET_CLASS (source);
if (klass->get_capabilities)
res = klass->get_capabilities (source, props);
res = klass->get_capabilities (source, filter);
else
res = NULL;
@ -365,7 +351,10 @@ pv_source_report_error (PvSource *source, GError *error)
}
PvSourceOutput *
pv_source_create_source_output (PvSource *source, GVariant *props, const gchar *prefix)
pv_source_create_source_output (PvSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix)
{
PvSourceClass *klass;
PvSourceOutput *res;
@ -375,7 +364,7 @@ pv_source_create_source_output (PvSource *source, GVariant *props, const gchar *
klass = PV_SOURCE_GET_CLASS (source);
if (klass->create_source_output)
res = klass->create_source_output (source, props, prefix);
res = klass->create_source_output (source, client_path, format_filter, prefix);
else
res = NULL;

View file

@ -64,12 +64,16 @@ struct _PvSource {
struct _PvSourceClass {
GObjectClass parent_class;
GVariant * (*get_capabilities) (PvSource *source, GVariant *props);
GBytes * (*get_capabilities) (PvSource *source, GBytes *filter);
gboolean (*set_state) (PvSource *source, PvSourceState);
PvSourceOutput * (*create_source_output) (PvSource *source, GVariant *props, const gchar *prefix);
gboolean (*release_source_output) (PvSource *source, PvSourceOutput *output);
PvSourceOutput * (*create_source_output) (PvSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix);
gboolean (*release_source_output) (PvSource *source,
PvSourceOutput *output);
};
/* normal GObject stuff */
@ -77,13 +81,16 @@ GType pv_source_get_type (void);
const gchar * pv_source_get_object_path (PvSource *source);
GVariant * pv_source_get_capabilities (PvSource *source, GVariant *props);
GBytes * pv_source_get_capabilities (PvSource *source, GBytes *filter);
gboolean pv_source_set_state (PvSource *source, PvSourceState state);
void pv_source_update_state (PvSource *source, PvSourceState state);
void pv_source_report_error (PvSource *source, GError *error);
PvSourceOutput * pv_source_create_source_output (PvSource *source, GVariant *props, const gchar *prefix);
PvSourceOutput * pv_source_create_source_output (PvSource *source,
const gchar *client_path,
GBytes *format_filter,
const gchar *prefix);
gboolean pv_source_release_source_output (PvSource *source, PvSourceOutput *output);
G_END_DECLS

View file

@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <gst/gst.h>
#include <gio/gio.h>
@ -61,8 +62,13 @@ on_stream_notify (GObject *gobject,
g_main_loop_quit (loop);
break;
case PV_STREAM_STATE_READY:
pv_stream_start (s, PV_STREAM_MODE_SOCKET);
{
GBytes *format;
format = g_bytes_new_static (CAPS, strlen (CAPS) + 1);
pv_stream_start (s, format, PV_STREAM_MODE_SOCKET);
break;
}
case PV_STREAM_STATE_STREAMING:
{
PvBufferInfo info;
@ -93,14 +99,14 @@ on_state_notify (GObject *gobject,
case PV_CONTEXT_STATE_READY:
{
PvStream *stream;
GVariantBuilder builder;
GBytes *format;
stream = pv_stream_new (c, "test", NULL);
g_signal_connect (stream, "notify::state", (GCallback) on_stream_notify, stream);
g_signal_connect (stream, "notify::socket", (GCallback) on_socket_notify, stream);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("a{sv}"));
pv_stream_connect_capture (stream, NULL, 0, g_variant_builder_end (&builder));
format = g_bytes_new_static (CAPS, strlen (CAPS) + 1);
pv_stream_connect_capture (stream, NULL, 0, format);
break;
}
default: