Work on negotiation

Add helpers to convert between pinos and gstreamer formats.
Use pinos formats in the API.
Work on removing some hardcoded stuff and instead use the real format
from the pinos server.
Use memfd and sealing.
This commit is contained in:
Wim Taymans 2016-08-05 16:39:26 +02:00
parent dd1fbef28f
commit ac5d22ec79
26 changed files with 638 additions and 199 deletions

View file

@ -166,6 +166,7 @@ pinosgstsource = gst/gsttmpfileallocator.h gst/gsttmpfileallocator.c
pinosinclude_HEADERS = \
client/context.h \
client/enumtypes.h \
client/format.h \
client/introspect.h \
client/mainloop.h \
client/pinos.h \
@ -180,6 +181,7 @@ lib_LTLIBRARIES = \
libpinos_@PINOS_MAJORMINOR@_la_SOURCES = \
client/context.h client/context.c \
client/enumtypes.h client/enumtypes.c \
client/format.h client/format.c \
client/introspect.h client/introspect.c \
client/mainloop.h client/mainloop.c \
client/properties.h client/properties.c \
@ -193,7 +195,7 @@ libpinos_@PINOS_MAJORMINOR@_la_SOURCES = \
libpinos_@PINOS_MAJORMINOR@_la_CFLAGS = $(AM_CFLAGS) $(GST_CFLAGS)
libpinos_@PINOS_MAJORMINOR@_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
libpinos_@PINOS_MAJORMINOR@_la_LIBADD = $(AM_LIBADD) $(LTLIBICONV) $(GST_LIBS) $(GST_BASE_LIBS) -lgstvideo-1.0
libpinos_@PINOS_MAJORMINOR@_la_LIBADD = $(AM_LIBADD) $(LTLIBICONV) $(GST_LIBS) $(GST_BASE_LIBS) -lgstvideo-1.0 -lgstaudio-1.0
###################################
# Daemon core library #
@ -235,6 +237,7 @@ plugin_LTLIBRARIES = libgstpinos.la
libgstpinos_la_SOURCES = \
gst/gstburstcache.c \
gst/gstpinos.c \
gst/gstpinosformat.c \
gst/gstpinosdeviceprovider.c \
gst/gstpinossrc.c \
gst/gstpinossink.c
@ -253,6 +256,7 @@ libgstpinos_la_LIBTOOLFLAGS = $(GST_PLUGIN_LIBTOOLFLAGS)
noinst_HEADERS = gst/gstburstcache.h gst/gstpinossrc.h \
gst/gstpinossocketsink.h gst/gstpinosportsink.h \
gst/gstpinosportsrc.h \
gst/gstpinosformat.h \
gst/gstpinossink.h gst/gstpinospay.h \
gst/gstpinosdepay.h gst/gstpinosdeviceprovider.h

44
pinos/client/format.c Normal file
View file

@ -0,0 +1,44 @@
/* Pinos
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <pinos/client/format.h>
static SpaFormat *
format_copy (SpaFormat *format)
{
SpaMemory *mem;
if (format == NULL)
return NULL;
mem = spa_memory_alloc_size (format->mem.mem.pool_id, format, format->mem.size);
return spa_memory_ensure_ptr (mem);
}
static void
format_free (SpaFormat *format)
{
g_return_if_fail (format != NULL);
spa_memory_unref (&format->mem.mem);
}
G_DEFINE_BOXED_TYPE (SpaFormat, spa_format,
format_copy, format_free);

37
pinos/client/format.h Normal file
View file

@ -0,0 +1,37 @@
/* Pinos
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __PINOS_FORMAT_H__
#define __PINOS_FORMAT_H__
#include <glib-object.h>
#include <spa/include/spa/format.h>
G_BEGIN_DECLS
#define SPA_TYPE_FORMAT (spa_format_get_type())
GType spa_format_get_type (void);
G_END_DECLS
#endif /* __PINOS_FORMAT_H__ */

View file

@ -21,6 +21,10 @@
#include <string.h>
#include <sys/mman.h>
#include "spa/include/spa/control.h"
#include "spa/include/spa/debug.h"
#include "spa/include/spa/memory.h"
#include <gio/gio.h>
#include <gio/gunixfdlist.h>
#include <gio/gunixfdmessage.h>
@ -30,11 +34,8 @@
#include "pinos/client/context.h"
#include "pinos/client/stream.h"
#include "pinos/client/enumtypes.h"
#include "pinos/client/format.h"
#include "pinos/client/private.h"
#include "spa/include/spa/control.h"
#include "spa/include/spa/debug.h"
#include "spa/include/spa/memory.h"
#define MAX_BUFFER_SIZE 1024
#define MAX_FDS 16
@ -70,10 +71,11 @@ struct _PinosStreamPrivate
PinosDirection direction;
gchar *path;
GBytes *possible_formats;
PinosStreamFlags flags;
GBytes *format;
GPtrArray *possible_formats;
SpaFormat *format;
PinosStreamFlags flags;
GDBusProxy *node;
gboolean disconnecting;
@ -188,7 +190,7 @@ pinos_stream_set_property (GObject *_object,
case PROP_FORMAT:
if (priv->format)
g_bytes_unref (priv->format);
spa_format_unref (priv->format);
priv->format = g_value_dup_boxed (value);
break;
@ -279,9 +281,9 @@ pinos_stream_finalize (GObject * object)
g_clear_object (&priv->node);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
g_ptr_array_unref (priv->possible_formats);
if (priv->format)
g_bytes_unref (priv->format);
spa_format_unref (priv->format);
g_free (priv->path);
g_clear_error (&priv->error);
@ -375,7 +377,7 @@ pinos_stream_class_init (PinosStreamClass * klass)
g_param_spec_boxed ("possible-formats",
"Possible Formats",
"The possbile formats of the stream",
G_TYPE_BYTES,
G_TYPE_PTR_ARRAY,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS));
/**
@ -388,7 +390,7 @@ pinos_stream_class_init (PinosStreamClass * klass)
g_param_spec_boxed ("format",
"Format",
"The format of the stream",
G_TYPE_BYTES,
SPA_TYPE_FORMAT,
G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS));
/**
@ -584,23 +586,17 @@ parse_control (PinosStream *stream,
SpaControlBuilder builder;
SpaControl control;
SpaControlCmdStateChange sc;
guint8 buffer[1024];
const gchar *str;
guint8 buffer[64];
if (spa_control_iter_parse_cmd (&it, &p) < 0)
break;
if (priv->format)
g_bytes_unref (priv->format);
str = "video/x-raw,"
" format=(string)YUY2,"
" width=(int)320,"
" height=(int)240,"
" framerate=(fraction)30/1";
priv->format = g_bytes_new_static (str, strlen (str)+1);
g_object_notify (G_OBJECT (stream), "format");
spa_format_unref (priv->format);
priv->format = p.format;
spa_format_unref (p.format);
spa_debug_format (p.format);
g_object_notify (G_OBJECT (stream), "format");
/* FIXME send update port status */
@ -650,12 +646,17 @@ parse_control (PinosStream *stream,
if (fd == -1)
break;
g_debug ("add mem %d,%d, %d, %d", p.mem.pool_id, p.mem.id, fd, p.flags);
mem = spa_memory_import (&p.mem);
mem->flags = p.flags;
mem->fd = fd;
mem->ptr = NULL;
mem->size = p.size;
if (mem->fd == -1) {
g_debug ("add mem %d,%d, %d, %d", p.mem.pool_id, p.mem.id, fd, p.flags);
mem->flags = p.flags;
mem->fd = fd;
mem->ptr = NULL;
mem->size = p.size;
} else {
g_debug ("duplicated mem %d,%d, %d, %d", p.mem.pool_id, p.mem.id, fd, p.flags);
close (fd);
}
break;
}
case SPA_CONTROL_CMD_REMOVE_MEM:
@ -681,13 +682,13 @@ parse_control (PinosStream *stream,
if (spa_control_iter_parse_cmd (&it, &p) < 0)
break;
g_debug ("add buffer %d", p.buffer_id);
mem = spa_memory_find (&p.mem);
g_debug ("add buffer %d, %d", p.buffer_id, p.mem.mem.id);
mem = spa_memory_find (&p.mem.mem);
bid.cleanup = false;
bid.id = p.buffer_id;
bid.offset = p.offset;
bid.size = p.size;
bid.buf = SPA_MEMBER (spa_memory_ensure_ptr (mem), p.offset, SpaBuffer);
bid.offset = p.mem.offset;
bid.size = p.mem.size;
bid.buf = SPA_MEMBER (spa_memory_ensure_ptr (mem), p.mem.offset, SpaBuffer);
g_array_append_val (priv->buffer_ids, bid);
break;
@ -957,7 +958,7 @@ do_connect (PinosStream *stream)
g_variant_builder_open (&b, G_VARIANT_TYPE ("(uusa{sv}s)"));
g_variant_builder_add (&b, "u", priv->direction);
g_variant_builder_add (&b, "u", 0);
g_variant_builder_add (&b, "s", g_bytes_get_data (priv->possible_formats, NULL));
g_variant_builder_add (&b, "s", "");
g_variant_builder_add_value (&b, pinos_properties_to_variant (priv->properties));
g_variant_builder_add (&b, "s", priv->path == NULL ? "" : priv->path);
g_variant_builder_close (&b);
@ -983,7 +984,7 @@ do_connect (PinosStream *stream)
* @direction: the stream direction
* @port_path: the port path to connect to or %NULL to get the default port
* @flags: a #PinosStreamFlags
* @possible_formats: (transfer full): a #GBytes with possible accepted formats
* @possible_formats: (transfer full): a #GPtrArray with possible accepted formats
*
* Connect @stream for input or output on @port_path.
*
@ -994,7 +995,7 @@ pinos_stream_connect (PinosStream *stream,
PinosDirection direction,
const gchar *port_path,
PinosStreamFlags flags,
GBytes *possible_formats)
GPtrArray *possible_formats)
{
PinosStreamPrivate *priv;
PinosContext *context;
@ -1011,7 +1012,7 @@ pinos_stream_connect (PinosStream *stream,
g_free (priv->path);
priv->path = g_strdup (port_path);
if (priv->possible_formats)
g_bytes_unref (priv->possible_formats);
g_ptr_array_unref (priv->possible_formats);
priv->flags = flags;
priv->possible_formats = possible_formats;
@ -1067,7 +1068,7 @@ do_start (PinosStream *stream)
/**
* pinos_stream_start:
* @stream: a #PinosStream
* @format: (transfer full): a #GBytes with format
* @format: (transfer full): a #SpaFormat with format
* @mode: a #PinosStreamMode
*
* Start capturing from @stream in @format.
@ -1083,7 +1084,7 @@ do_start (PinosStream *stream)
*/
gboolean
pinos_stream_start (PinosStream *stream,
GBytes *format,
SpaFormat *format,
PinosStreamMode mode)
{
PinosStreamPrivate *priv;

View file

@ -23,6 +23,7 @@
#include <glib-object.h>
#include <spa/include/spa/buffer.h>
#include <spa/include/spa/format.h>
#include <pinos/client/context.h>
@ -99,11 +100,11 @@ gboolean pinos_stream_connect (PinosStream *stream,
PinosDirection direction,
const gchar *port_path,
PinosStreamFlags flags,
GBytes *possible_formats);
GPtrArray *possible_formats);
gboolean pinos_stream_disconnect (PinosStream *stream);
gboolean pinos_stream_start (PinosStream *stream,
GBytes *format,
SpaFormat *format,
PinosStreamMode mode);
gboolean pinos_stream_stop (PinosStream *stream);

170
pinos/gst/gstpinosformat.c Normal file
View file

@ -0,0 +1,170 @@
/* GStreamer
* Copyright (C) 2016 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.
*/
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/audio/audio.h>
#include <spa/include/spa/video/format.h>
#include <spa/include/spa/audio/format.h>
#include <spa/include/spa/format.h>
#include "gstpinosformat.h"
static SpaFormat *
convert_1 (GstCapsFeatures *cf, GstStructure *cs)
{
SpaMemory *mem;
SpaFormat *res = NULL;
const gchar *s;
int i;
if (gst_structure_has_name (cs, "video/x-raw")) {
SpaVideoRawFormat *f;
mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL, NULL, sizeof (SpaVideoRawFormat));
f = spa_memory_ensure_ptr (mem);
f->format.mem.mem = mem->mem;
f->format.mem.offset = 0;
f->format.mem.size = mem->size;
spa_video_raw_format_init (f);
if (!(s = gst_structure_get_string (cs, "format")))
goto done;
f->info.format = gst_video_format_from_string (s);
if (!gst_structure_get_int (cs, "width", &i))
goto done;
f->info.size.width = i;
if (!gst_structure_get_int (cs, "height", &i))
goto done;
f->info.size.height = i;
f->unset_mask = 0;
res = &f->format;
} else if (gst_structure_has_name (cs, "audio/x-raw")) {
SpaAudioRawFormat *f;
mem = spa_memory_alloc_size (SPA_MEMORY_POOL_LOCAL, NULL, sizeof (SpaAudioRawFormat));
f = spa_memory_ensure_ptr (mem);
f->format.mem.mem = mem->mem;
f->format.mem.offset = 0;
f->format.mem.size = mem->size;
spa_audio_raw_format_init (f);
if (!(s = gst_structure_get_string (cs, "format")))
goto done;
f->info.format = gst_audio_format_from_string (s);
if (!(s = gst_structure_get_string (cs, "layout")))
goto done;
f->info.layout = 0;
if (!gst_structure_get_int (cs, "rate", &i))
goto done;
f->info.rate = i;
if (!gst_structure_get_int (cs, "channels", &i))
goto done;
f->info.channels = i;
f->unset_mask = 0;
res = &f->format;
}
done:
return res;
}
SpaFormat *
gst_caps_to_format (GstCaps *caps, guint index)
{
GstCapsFeatures *f;
GstStructure *s;
SpaFormat *res;
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
g_return_val_if_fail (gst_caps_is_fixed (caps), NULL);
f = gst_caps_get_features (caps, index);
s = gst_caps_get_structure (caps, index);
res = convert_1 (f, s);
return res;
}
static gboolean
foreach_func (GstCapsFeatures *features,
GstStructure *structure,
GPtrArray *array)
{
SpaFormat *fmt;
if ((fmt = convert_1 (features, structure)))
g_ptr_array_insert (array, -1, fmt);
return TRUE;
}
GPtrArray *
gst_caps_to_format_all (GstCaps *caps)
{
GPtrArray *res;
res = g_ptr_array_new_full (gst_caps_get_size (caps),
(GDestroyNotify)spa_format_unref);
gst_caps_foreach (caps, (GstCapsForeachFunc) foreach_func, res);
return res;
}
GstCaps *
gst_caps_from_format (SpaFormat *format)
{
GstCaps *res = NULL;
if (format->media_type == SPA_MEDIA_TYPE_VIDEO) {
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
SpaVideoRawFormat f;
spa_video_raw_format_parse (format, &f);
res = gst_caps_new_simple ("video/x-raw",
"format", G_TYPE_STRING, gst_video_format_to_string (f.info.format),
"width", G_TYPE_INT, f.info.size.width,
"height", G_TYPE_INT, f.info.size.height,
NULL);
}
} else if (format->media_type == SPA_MEDIA_TYPE_AUDIO) {
if (format->media_subtype == SPA_MEDIA_SUBTYPE_RAW) {
SpaAudioRawFormat f;
spa_audio_raw_format_parse (format, &f);
res = gst_caps_new_simple ("audio/x-raw",
"format", G_TYPE_STRING, gst_audio_format_to_string (f.info.format),
"layout", G_TYPE_STRING, "interleaved",
"rate", G_TYPE_INT, f.info.rate,
"channels", G_TYPE_INT, f.info.channels,
NULL);
}
}
return res;
}

View file

@ -0,0 +1,36 @@
/* GStreamer
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef _GST_PINOS_FORMAT_H_
#define _GST_PINOS_FORMAT_H_
#include <gst/gst.h>
#include <spa/include/spa/format.h>
G_BEGIN_DECLS
SpaFormat * gst_caps_to_format (GstCaps *caps, guint index);
GPtrArray * gst_caps_to_format_all (GstCaps *caps);
GstCaps * gst_caps_from_format (SpaFormat *format);
G_END_DECLS
#endif

View file

@ -46,6 +46,7 @@
#include <spa/include/spa/buffer.h>
#include "gsttmpfileallocator.h"
#include "gstpinosformat.h"
GST_DEBUG_CATEGORY_STATIC (pinos_sink_debug);
@ -412,15 +413,17 @@ static gboolean
gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
{
GstPinosSink *pinossink;
gchar *str;
GBytes *format;
GPtrArray *possible;
SpaFormat *format;
PinosStreamState state;
gboolean res = FALSE;
pinossink = GST_PINOS_SINK (bsink);
str = gst_caps_to_string (caps);
format = g_bytes_new_take (str, strlen (str) + 1);
format = gst_caps_to_format (caps, 0);
possible = g_ptr_array_new ();
spa_format_ref (format);
g_ptr_array_insert (possible, -1, format);
pinos_main_loop_lock (pinossink->loop);
state = pinos_stream_get_state (pinossink->stream);
@ -438,7 +441,7 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
PINOS_DIRECTION_OUTPUT,
pinossink->path,
flags,
g_bytes_ref (format));
possible);
while (TRUE) {
state = pinos_stream_get_state (pinossink->stream);
@ -455,7 +458,7 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
if (state != PINOS_STREAM_STATE_STREAMING) {
res = pinos_stream_start (pinossink->stream,
g_bytes_ref (format),
format,
PINOS_STREAM_MODE_BUFFER);
while (TRUE) {
@ -471,7 +474,6 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
}
}
pinos_main_loop_unlock (pinossink->loop);
g_bytes_unref (format);
pinossink->negotiated = res;
@ -481,7 +483,7 @@ start_error:
{
GST_ERROR ("could not start stream");
pinos_main_loop_unlock (pinossink->loop);
g_bytes_unref (format);
spa_format_unref (format);
return FALSE;
}
}
@ -517,10 +519,10 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
b = g_slice_new (SinkBuffer);
b->buffer.id = pinos_fd_manager_get_id (pinossink->fdmanager);
b->buffer.mem.pool_id = SPA_ID_INVALID;
b->buffer.mem.id = SPA_ID_INVALID;
b->buffer.offset = 0;
b->buffer.size = sizeof (SinkBuffer);
b->buffer.mem.mem.pool_id = SPA_ID_INVALID;
b->buffer.mem.mem.id = SPA_ID_INVALID;
b->buffer.mem.offset = 0;
b->buffer.mem.size = sizeof (SinkBuffer);
b->buffer.n_metas = 1;
b->buffer.metas = offsetof (SinkBuffer, metas);
b->buffer.n_datas = 1;
@ -564,10 +566,10 @@ gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
b->mem = mem;
b->fd = gst_fd_memory_get_fd (mem);
b->datas[0].mem.pool_id = SPA_ID_INVALID;
b->datas[0].mem.id = SPA_ID_INVALID;
b->datas[0].offset = mem->offset;
b->datas[0].size = mem->size;
b->datas[0].mem.mem.pool_id = SPA_ID_INVALID;
b->datas[0].mem.mem.id = SPA_ID_INVALID;
b->datas[0].mem.offset = mem->offset;
b->datas[0].mem.size = mem->size;
b->datas[0].stride = 0;
if (!(res = pinos_stream_send_buffer (pinossink->stream, &b->buffer)))

View file

@ -32,6 +32,7 @@
#include "config.h"
#endif
#include "gstpinossrc.h"
#include "gstpinosformat.h"
#include <string.h>
#include <stdlib.h>
@ -388,19 +389,19 @@ on_new_buffer (GObject *gobject,
SpaData *d = &SPA_BUFFER_DATAS (b)[i];
SpaMemory *mem;
mem = spa_memory_find (&d->mem);
mem = spa_memory_find (&d->mem.mem);
if (mem->fd) {
GstMemory *fdmem = NULL;
fdmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (mem->fd),
d->offset + d->size, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (fdmem, d->offset, d->size);
d->mem.offset + d->mem.size, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (fdmem, d->mem.offset, d->mem.size);
gst_buffer_append_memory (buf, fdmem);
} else {
gst_buffer_append_memory (buf,
gst_memory_new_wrapped (0, mem->ptr, mem->size, d->offset,
d->size, NULL, NULL));
gst_memory_new_wrapped (0, mem->ptr, mem->size, d->mem.offset,
d->mem.size, NULL, NULL));
}
}
@ -485,15 +486,14 @@ parse_stream_properties (GstPinosSrc *pinossrc, PinosProperties *props)
static gboolean
gst_pinos_src_stream_start (GstPinosSrc *pinossrc, GstCaps * caps)
{
gchar *str;
GBytes *format = NULL;
SpaFormat *format;
gboolean res;
PinosProperties *props;
if (caps) {
str = gst_caps_to_string (caps);
format = g_bytes_new_take (str, strlen (str) + 1);
}
if (caps)
format = gst_caps_to_format (caps, 0);
else
format = NULL;
pinos_main_loop_lock (pinossrc->loop);
res = pinos_stream_start (pinossrc->stream, format, PINOS_STREAM_MODE_BUFFER);
@ -515,9 +515,9 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc, GstCaps * caps)
pinos_main_loop_unlock (pinossrc->loop);
if (format) {
caps = gst_caps_from_string (g_bytes_get_data (format, NULL));
caps = gst_caps_from_format (format);
gst_base_src_set_caps (GST_BASE_SRC (pinossrc), caps);
g_bytes_unref (format);
spa_format_unref (format);
}
parse_stream_properties (pinossrc, props);
@ -555,8 +555,7 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
GstCaps *caps = NULL;
GstCaps *peercaps = NULL;
gboolean result = FALSE;
GBytes *possible;
gchar *str;
GPtrArray *possible;
/* first see what is possible on our source pad */
thiscaps = gst_pad_query_caps (GST_BASE_SRC_PAD (basesrc), NULL);
@ -585,8 +584,7 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
GST_DEBUG_OBJECT (basesrc, "have common caps: %" GST_PTR_FORMAT, caps);
/* open a connection with these caps */
str = gst_caps_to_string (caps);
possible = g_bytes_new_take (str, strlen (str) + 1);
possible = gst_caps_to_format_all (caps);
/* first disconnect */
pinos_main_loop_lock (pinossrc->loop);
@ -600,7 +598,7 @@ gst_pinos_src_negotiate (GstBaseSrc * basesrc)
break;
if (state == PINOS_STREAM_STATE_ERROR) {
g_bytes_unref (possible);
g_ptr_array_unref (possible);
goto connect_error;
}
@ -672,12 +670,12 @@ on_format_notify (GObject *gobject,
gpointer user_data)
{
GstPinosSrc *pinossrc = user_data;
GBytes *format;
SpaFormat *format;
GstCaps *caps;
g_object_get (gobject, "format", &format, NULL);
caps = gst_caps_from_string (g_bytes_get_data (format, NULL));
caps = gst_caps_from_format (format);
gst_base_src_set_caps (GST_BASE_SRC (pinossrc), caps);
gst_caps_unref (caps);
}

View file

@ -444,10 +444,10 @@ on_received_buffer (PinosPort *port,
uint8_t *data;
size_t size, towrite, total;
mem = spa_memory_find (&d[i].mem);
mem = spa_memory_find (&d[i].mem.mem);
size = d[i].size;
data = (guint8*)mem->ptr + d[i].offset;
size = d[i].mem.size;
data = SPA_MEMBER (mem->ptr, d[i].mem.offset, uint8_t);
pinos_ringbuffer_get_write_areas (priv->ringbuffer, areas);

View file

@ -269,8 +269,8 @@ do_negotiate (PinosLink *this)
value.type = SPA_PROP_TYPE_RECTANGLE;
value.size = sizeof (SpaRectangle);
value.value = &rect;
rect.width = 320;
rect.height = 240;
rect.width = 640;
rect.height = 480;
if ((res = spa_props_set_prop (props, spa_props_index_for_id (props, SPA_PROP_ID_VIDEO_SIZE), &value)) < 0)
return res;

View file

@ -81,17 +81,14 @@ on_stream_notify (GObject *gobject,
case PINOS_STREAM_STATE_READY:
{
GBytes *possible, *format;
GstCaps *caps;
GstStructure *structure;
gchar *str;
GPtrArray *possible;
SpaFormat *format;
g_object_get (s, "possible-formats", &possible, NULL);
caps = gst_caps_from_string (g_bytes_get_data (possible, NULL));
structure = gst_caps_get_structure (caps, 0);
format = g_ptr_array_index (possible, 0);
#if 0
/* set some reasonable defaults */
if (gst_structure_has_field (structure, "width"))
gst_structure_fixate_field_nearest_int (structure, "width", 320);
@ -104,8 +101,9 @@ on_stream_notify (GObject *gobject,
caps = gst_caps_fixate (caps);
str = gst_caps_to_string (caps);
gst_caps_unref (caps);
format = g_bytes_new_static (str, strlen (str) + 1);
#endif
pinos_stream_start (s, format, PINOS_STREAM_MODE_SOCKET);
break;
}
@ -136,14 +134,14 @@ on_state_notify (GObject *gobject,
case PINOS_CONTEXT_STATE_CONNECTED:
{
PinosStream *stream;
GBytes *format;
GPtrArray *possible;
stream = pinos_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);
format = g_bytes_new_static (ANY_CAPS, strlen (ANY_CAPS) + 1);
pinos_stream_connect (stream, PINOS_DIRECTION_OUTPUT, NULL, 0, format);
possible = NULL;
pinos_stream_connect (stream, PINOS_DIRECTION_OUTPUT, NULL, 0, possible);
break;
}
default: