gst: fix gstreamer elements

Handle new ringbuffer area on buffers
Set the id correctly for format enumerations.
This commit is contained in:
Wim Taymans 2017-11-20 11:04:02 +01:00
parent 4d0bab799c
commit 2fd5bcb623
5 changed files with 69 additions and 68 deletions

View file

@ -146,6 +146,18 @@ dbus_dep = dependency('dbus-1')
#optional dependencies #optional dependencies
jack_dep = dependency('jack', version : '>= 1.9.10', required : false) jack_dep = dependency('jack', version : '>= 1.9.10', required : false)
if get_option('enable_gstreamer')
glib_dep = dependency('glib-2.0', version : '>=2.32.0')
gobject_dep = dependency('gobject-2.0')
gmodule_dep = dependency('gmodule-2.0')
gio_dep = [dependency('gio-2.0'), dependency('gio-unix-2.0')]
gst_dep = [dependency('gstreamer-1.0'),
dependency('gstreamer-plugins-base-1.0'),
dependency('gstreamer-video-1.0'),
dependency('gstreamer-audio-1.0'),
dependency('gstreamer-allocators-1.0'),]
endif
subdir('spa') subdir('spa')
subdir('src') subdir('src')
subdir('pkgconfig') subdir('pkgconfig')
@ -163,15 +175,3 @@ if get_option('enable_man')
subdir('man') subdir('man')
endif endif
endif endif
if get_option('enable_gstreamer')
glib_dep = dependency('glib-2.0', version : '>=2.32.0')
gobject_dep = dependency('gobject-2.0')
gmodule_dep = dependency('gmodule-2.0')
gio_dep = [dependency('gio-2.0'), dependency('gio-unix-2.0')]
gst_dep = [dependency('gstreamer-1.0'),
dependency('gstreamer-plugins-base-1.0'),
dependency('gstreamer-video-1.0'),
dependency('gstreamer-audio-1.0'),
dependency('gstreamer-allocators-1.0'),]
endif

View file

@ -200,8 +200,10 @@ static const uint32_t *audio_format_map[] = {
typedef struct { typedef struct {
struct spa_pod_builder b; struct spa_pod_builder b;
const struct media_type *type; const struct media_type *type;
uint32_t id;
const GstCapsFeatures *cf; const GstCapsFeatures *cf;
const GstStructure *cs; const GstStructure *cs;
GPtrArray *array;
} ConvertData; } ConvertData;
static const struct media_type * static const struct media_type *
@ -544,38 +546,31 @@ write_pod (struct spa_pod_builder *b, const void *data, uint32_t size)
} }
static struct spa_pod * static struct spa_pod *
convert_1 (GstCapsFeatures *cf, GstStructure *cs) convert_1 (ConvertData *d)
{ {
ConvertData d; if (!(d->type = find_media_types (gst_structure_get_name (d->cs))))
spa_zero (d);
d.cf = cf;
d.cs = cs;
if (!(d.type = find_media_types (gst_structure_get_name (cs))))
return NULL; return NULL;
d.b.write = write_pod; d->b.write = write_pod;
spa_pod_builder_push_object (&d.b, 0, type.format); spa_pod_builder_push_object (&d->b, d->id, type.format);
spa_pod_builder_id(&d.b, *d.type->media_type); spa_pod_builder_id(&d->b, *d->type->media_type);
spa_pod_builder_id(&d.b, *d.type->media_subtype); spa_pod_builder_id(&d->b, *d->type->media_subtype);
if (*d.type->media_type == type.media_type.video) if (*d->type->media_type == type.media_type.video)
handle_video_fields (&d); handle_video_fields (d);
else if (*d.type->media_type == type.media_type.audio) else if (*d->type->media_type == type.media_type.audio)
handle_audio_fields (&d); handle_audio_fields (d);
spa_pod_builder_pop (&d.b); spa_pod_builder_pop (&d->b);
return SPA_MEMBER (d.b.data, 0, struct spa_pod); return SPA_MEMBER (d->b.data, 0, struct spa_pod);
} }
struct spa_pod * struct spa_pod *
gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map) gst_caps_to_format (GstCaps *caps, guint index, uint32_t id, struct spa_type_map *map)
{ {
GstCapsFeatures *f; ConvertData d;
GstStructure *s;
struct spa_pod *res; struct spa_pod *res;
g_return_val_if_fail (GST_IS_CAPS (caps), NULL); g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
@ -583,10 +578,12 @@ gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map)
ensure_types(map); ensure_types(map);
f = gst_caps_get_features (caps, index); spa_zero (d);
s = gst_caps_get_structure (caps, index); d.cf = gst_caps_get_features (caps, index);
d.cs = gst_caps_get_structure (caps, index);
d.id = id;
res = convert_1 (f, s); res = convert_1 (&d);
return res; return res;
} }
@ -594,28 +591,35 @@ gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map)
static gboolean static gboolean
foreach_func (GstCapsFeatures *features, foreach_func (GstCapsFeatures *features,
GstStructure *structure, GstStructure *structure,
GPtrArray *array) ConvertData *d)
{ {
struct spa_pod *fmt; struct spa_pod *fmt;
if ((fmt = convert_1 (features, structure))) spa_zero(d->b);
g_ptr_array_insert (array, -1, fmt); d->cf = features;
d->cs = structure;
if ((fmt = convert_1 (d)))
g_ptr_array_insert (d->array, -1, fmt);
return TRUE; return TRUE;
} }
GPtrArray * GPtrArray *
gst_caps_to_format_all (GstCaps *caps, struct spa_type_map *map) gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map)
{ {
GPtrArray *res; ConvertData d;
ensure_types(map); ensure_types(map);
res = g_ptr_array_new_full (gst_caps_get_size (caps), (GDestroyNotify)g_free); spa_zero (d);
gst_caps_foreach (caps, (GstCapsForeachFunc) foreach_func, res); d.id = id;
d.array = g_ptr_array_new_full (gst_caps_get_size (caps), (GDestroyNotify)g_free);
return res; gst_caps_foreach (caps, (GstCapsForeachFunc) foreach_func, &d);
return d.array;
} }
static void static void

View file

@ -27,8 +27,10 @@
G_BEGIN_DECLS G_BEGIN_DECLS
struct spa_pod * gst_caps_to_format (GstCaps *caps, guint index, struct spa_type_map *map); struct spa_pod * gst_caps_to_format (GstCaps *caps,
GPtrArray * gst_caps_to_format_all (GstCaps *caps, struct spa_type_map *map); guint index, uint32_t id,
struct spa_type_map *map);
GPtrArray * gst_caps_to_format_all (GstCaps *caps, uint32_t id, struct spa_type_map *map);
GstCaps * gst_caps_from_format (const struct spa_pod *format, struct spa_type_map *map); GstCaps * gst_caps_from_format (const struct spa_pod *format, struct spa_type_map *map);

View file

@ -224,7 +224,7 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
guint size; guint size;
guint min_buffers; guint min_buffers;
guint max_buffers; guint max_buffers;
struct spa_pod *port_params[3]; struct spa_pod *port_params[2];
struct spa_pod_builder b = { NULL }; struct spa_pod_builder b = { NULL };
uint8_t buffer[1024]; uint8_t buffer[1024];
@ -254,15 +254,6 @@ pool_activated (GstPipeWirePool *pool, GstPipeWireSink *sink)
":", t->param_meta.type, "I", t->meta.Header, ":", t->param_meta.type, "I", t->meta.Header,
":", t->param_meta.size, "i", sizeof (struct spa_meta_header)); ":", t->param_meta.size, "i", sizeof (struct spa_meta_header));
port_params[2] = spa_pod_builder_object (&b,
t->param.idMeta, t->param_meta.Meta,
":", t->param_meta.type, "I", t->meta.Ringbuffer,
":", t->param_meta.size, "i", sizeof (struct spa_meta_ringbuffer),
":", t->param_meta.ringbufferSize, "i", size * SPA_MAX (4,
SPA_MAX (min_buffers, max_buffers)),
":", t->param_meta.ringbufferStride, "i", 0,
":", t->param_meta.ringbufferBlocks, "i", 1,
":", t->param_meta.ringbufferAlign, "i", 16);
pw_thread_loop_lock (sink->main_loop); pw_thread_loop_lock (sink->main_loop);
pw_stream_finish_format (sink->stream, 0, 2, port_params); pw_stream_finish_format (sink->stream, 0, 2, port_params);
@ -448,12 +439,12 @@ on_add_buffer (void *_data,
d->type == t->data.DmaBuf) { d->type == t->data.DmaBuf) {
gmem = gst_fd_allocator_alloc (pwsink->allocator, dup (d->fd), gmem = gst_fd_allocator_alloc (pwsink->allocator, dup (d->fd),
d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE); d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, d->chunk->offset + d->mapoffset, d->chunk->size); gst_memory_resize (gmem, d->mapoffset, d->maxsize);
data.offset = d->mapoffset; data.offset = d->mapoffset;
} }
else if (d->type == t->data.MemPtr) { else if (d->type == t->data.MemPtr) {
gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, d->chunk->offset, gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, 0,
d->chunk->size, NULL, NULL); d->maxsize, NULL, NULL);
data.offset = 0; data.offset = 0;
} }
if (gmem) if (gmem)
@ -535,8 +526,8 @@ do_send_buffer (GstPipeWireSink *pwsink)
for (i = 0; i < data->buf->n_datas; i++) { for (i = 0; i < data->buf->n_datas; i++) {
struct spa_data *d = &data->buf->datas[i]; struct spa_data *d = &data->buf->datas[i];
GstMemory *mem = gst_buffer_peek_memory (buffer, i); GstMemory *mem = gst_buffer_peek_memory (buffer, i);
d->chunk->offset = mem->offset - data->offset; d->chunk->area.readindex = mem->offset - data->offset;
d->chunk->size = mem->size; d->chunk->area.writeindex = d->chunk->area.readindex + mem->size;
} }
if (!(res = pw_stream_send_buffer (pwsink->stream, data->id))) { if (!(res = pw_stream_send_buffer (pwsink->stream, data->id))) {
@ -596,10 +587,12 @@ gst_pipewire_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
enum pw_stream_state state; enum pw_stream_state state;
const char *error = NULL; const char *error = NULL;
gboolean res = FALSE; gboolean res = FALSE;
struct pw_type *t;
pwsink = GST_PIPEWIRE_SINK (bsink); pwsink = GST_PIPEWIRE_SINK (bsink);
t = pwsink->type;
possible = gst_caps_to_format_all (caps, pwsink->type->map); possible = gst_caps_to_format_all (caps, t->param.idEnumFormat, t->map);
pw_thread_loop_lock (pwsink->main_loop); pw_thread_loop_lock (pwsink->main_loop);
state = pw_stream_get_state (pwsink->stream, &error); state = pw_stream_get_state (pwsink->stream, &error);

View file

@ -384,12 +384,12 @@ on_add_buffer (void *_data, guint id)
if (d->type == t->data.MemFd || d->type == t->data.DmaBuf) { if (d->type == t->data.MemFd || d->type == t->data.DmaBuf) {
gmem = gst_fd_allocator_alloc (pwsrc->fd_allocator, dup (d->fd), gmem = gst_fd_allocator_alloc (pwsrc->fd_allocator, dup (d->fd),
d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE); d->mapoffset + d->maxsize, GST_FD_MEMORY_FLAG_NONE);
gst_memory_resize (gmem, d->chunk->offset + d->mapoffset, d->chunk->size); gst_memory_resize (gmem, d->mapoffset, d->maxsize);
data.offset = d->mapoffset; data.offset = d->mapoffset;
} }
else if (d->type == t->data.MemPtr) { else if (d->type == t->data.MemPtr) {
gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, d->chunk->offset + d->mapoffset, gmem = gst_memory_new_wrapped (0, d->data, d->maxsize, 0,
d->chunk->size, NULL, NULL); d->maxsize, NULL, NULL);
data.offset = 0; data.offset = 0;
} }
if (gmem) if (gmem)
@ -464,9 +464,11 @@ on_new_buffer (void *_data,
} }
for (i = 0; i < data->buf->n_datas; i++) { for (i = 0; i < data->buf->n_datas; i++) {
struct spa_data *d = &data->buf->datas[i]; struct spa_data *d = &data->buf->datas[i];
uint32_t index;
GstMemory *mem = gst_buffer_peek_memory (buf, i); GstMemory *mem = gst_buffer_peek_memory (buf, i);
mem->offset = d->chunk->offset + data->offset; mem->size = spa_ringbuffer_get_read_index(&d->chunk->area, &index);
mem->size = d->chunk->size; mem->offset = index % d->maxsize;
spa_ringbuffer_set_avail(&d->chunk->area, 0);
} }
if (pwsrc->always_copy) if (pwsrc->always_copy)
@ -633,7 +635,7 @@ gst_pipewire_src_negotiate (GstBaseSrc * basesrc)
GST_DEBUG_OBJECT (basesrc, "have common caps: %" GST_PTR_FORMAT, caps); GST_DEBUG_OBJECT (basesrc, "have common caps: %" GST_PTR_FORMAT, caps);
/* open a connection with these caps */ /* open a connection with these caps */
possible = gst_caps_to_format_all (caps, pwsrc->type->map); possible = gst_caps_to_format_all (caps, pwsrc->type->param.idEnumFormat, pwsrc->type->map);
gst_caps_unref (caps); gst_caps_unref (caps);
/* first disconnect */ /* first disconnect */