mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-24 07:00:05 -05:00
Work on sink
Remove _remove from properties, we can do the same with set of a NULL value. Add signals to the stream API to manage the buffers. Wrap those buffers in a GstBuffer in the pinossrc and pinossink elements and pool them in a bufferpool. Remove SPA_EVENT_TYPE_PULL_INPUT, we can do the same with NEED_INPUT and by using a ringbuffer. Do more complete allocation of buffers in the link. Use the buffer allocator if none of the nodes can allocate. Follow the node state to trigger negotiation and allocation. Remove offset and size when refering to buffers, we want to always deal with the complete buffer and use a ringbuffer for ranges or change the offset/size in the buffer data when needed. Serialize port_info structures as part of the port_update Print both the enum number and the name when debuging properties or formats.
This commit is contained in:
parent
a03352353f
commit
ca7d08c406
45 changed files with 1614 additions and 570 deletions
149
pinos/gst/gstpinospool.c
Normal file
149
pinos/gst/gstpinospool.c
Normal file
|
|
@ -0,0 +1,149 @@
|
|||
/* 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 Street, Suite 500,
|
||||
* Boston, MA 02110-1335, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include "gstpinospool.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_pinos_pool_debug_category);
|
||||
#define GST_CAT_DEFAULT gst_pinos_pool_debug_category
|
||||
|
||||
G_DEFINE_TYPE (GstPinosPool, gst_pinos_pool, GST_TYPE_BUFFER_POOL);
|
||||
|
||||
GstPinosPool *
|
||||
gst_pinos_pool_new (void)
|
||||
{
|
||||
GstPinosPool *pool;
|
||||
|
||||
pool = g_object_new (GST_TYPE_PINOS_POOL, NULL);
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_pinos_pool_add_buffer (GstPinosPool *pool, GstBuffer *buffer)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_PINOS_POOL (pool), FALSE);
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
||||
|
||||
GST_OBJECT_LOCK (pool);
|
||||
g_queue_push_tail (&pool->available, buffer);
|
||||
g_cond_signal (&pool->cond);
|
||||
GST_OBJECT_UNLOCK (pool);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_pinos_pool_remove_buffer (GstPinosPool *pool, GstBuffer *buffer)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_PINOS_POOL (pool), FALSE);
|
||||
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
|
||||
|
||||
GST_OBJECT_LOCK (pool);
|
||||
g_queue_remove (&pool->available, buffer);
|
||||
GST_OBJECT_UNLOCK (pool);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GstFlowReturn
|
||||
acquire_buffer (GstBufferPool * pool, GstBuffer ** buffer,
|
||||
GstBufferPoolAcquireParams * params)
|
||||
{
|
||||
GstPinosPool *p = GST_PINOS_POOL (pool);
|
||||
|
||||
GST_OBJECT_LOCK (pool);
|
||||
while (p->available.length == 0) {
|
||||
g_cond_wait (&p->cond, GST_OBJECT_GET_LOCK (pool));
|
||||
}
|
||||
*buffer = g_queue_pop_head (&p->available);
|
||||
GST_OBJECT_UNLOCK (pool);
|
||||
GST_DEBUG ("acquire buffer %p", *buffer);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
release_buffer (GstBufferPool * pool, GstBuffer *buffer)
|
||||
{
|
||||
GstPinosPool *p = GST_PINOS_POOL (pool);
|
||||
|
||||
GST_DEBUG ("release buffer %p", buffer);
|
||||
GST_OBJECT_LOCK (pool);
|
||||
g_queue_push_tail (&p->available, buffer);
|
||||
GST_OBJECT_UNLOCK (pool);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
do_start (GstBufferPool * pool)
|
||||
{
|
||||
GstPinosPool *p = GST_PINOS_POOL (pool);
|
||||
PinosProperties *props = NULL;
|
||||
GstStructure *config;
|
||||
GstCaps *caps;
|
||||
guint size;
|
||||
guint min_buffers;
|
||||
guint max_buffers;
|
||||
|
||||
config = gst_buffer_pool_get_config (pool);
|
||||
gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers, &max_buffers);
|
||||
|
||||
|
||||
pinos_stream_start_allocation (p->stream, props);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_pool_finalize (GObject * object)
|
||||
{
|
||||
GstPinosPool *pool = GST_PINOS_POOL (object);
|
||||
|
||||
GST_DEBUG_OBJECT (pool, "finalize");
|
||||
|
||||
G_OBJECT_CLASS (gst_pinos_pool_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_pool_class_init (GstPinosPoolClass * klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
||||
GstBufferPoolClass *bufferpool_class = GST_BUFFER_POOL_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = gst_pinos_pool_finalize;
|
||||
|
||||
bufferpool_class->start = do_start;
|
||||
bufferpool_class->acquire_buffer = acquire_buffer;
|
||||
bufferpool_class->release_buffer = release_buffer;
|
||||
|
||||
GST_DEBUG_CATEGORY_INIT (gst_pinos_pool_debug_category, "pinospool", 0,
|
||||
"debug category for pinospool object");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_pool_init (GstPinosPool * pool)
|
||||
{
|
||||
g_cond_init (&pool->cond);
|
||||
g_queue_init (&pool->available);
|
||||
}
|
||||
66
pinos/gst/gstpinospool.h
Normal file
66
pinos/gst/gstpinospool.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* 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_POOL_H__
|
||||
#define __GST_PINOS_POOL_H__
|
||||
|
||||
#include <gst/gst.h>
|
||||
|
||||
#include <client/pinos.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GST_TYPE_PINOS_POOL \
|
||||
(gst_pinos_pool_get_type())
|
||||
#define GST_PINOS_POOL(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PINOS_POOL,GstPinosPool))
|
||||
#define GST_PINOS_POOL_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PINOS_POOL,GstPinosPoolClass))
|
||||
#define GST_IS_PINOS_POOL(obj) \
|
||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PINOS_POOL))
|
||||
#define GST_IS_PINOS_POOL_CLASS(klass) \
|
||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PINOS_POOL))
|
||||
#define GST_PINOS_POOL_GET_CLASS(klass) \
|
||||
(G_TYPE_INSTANCE_GET_CLASS ((klass), GST_TYPE_PINOS_POOL, GstPinosPoolClass))
|
||||
|
||||
typedef struct _GstPinosPool GstPinosPool;
|
||||
typedef struct _GstPinosPoolClass GstPinosPoolClass;
|
||||
|
||||
struct _GstPinosPool {
|
||||
GstBufferPool parent;
|
||||
|
||||
PinosStream *stream;
|
||||
GQueue available;
|
||||
GCond cond;
|
||||
};
|
||||
|
||||
struct _GstPinosPoolClass {
|
||||
GstBufferPoolClass parent_class;
|
||||
};
|
||||
|
||||
GType gst_pinos_pool_get_type (void);
|
||||
|
||||
GstPinosPool * gst_pinos_pool_new (void);
|
||||
|
||||
gboolean gst_pinos_pool_add_buffer (GstPinosPool *pool, GstBuffer *buffer);
|
||||
gboolean gst_pinos_pool_remove_buffer (GstPinosPool *pool, GstBuffer *buffer);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GST_PINOS_POOL_H__ */
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
#include "gsttmpfileallocator.h"
|
||||
#include "gstpinosformat.h"
|
||||
|
||||
static GQuark process_mem_data_quark;
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (pinos_sink_debug);
|
||||
#define GST_CAT_DEFAULT pinos_sink_debug
|
||||
|
|
@ -120,8 +121,9 @@ gst_pinos_sink_finalize (GObject * object)
|
|||
|
||||
if (pinossink->properties)
|
||||
gst_structure_free (pinossink->properties);
|
||||
g_hash_table_unref (pinossink->mem_ids);
|
||||
g_object_unref (pinossink->allocator);
|
||||
g_object_unref (pinossink->pool);
|
||||
g_hash_table_unref (pinossink->buf_ids);
|
||||
g_free (pinossink->path);
|
||||
g_free (pinossink->client_name);
|
||||
|
||||
|
|
@ -133,7 +135,7 @@ gst_pinos_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
|
|||
{
|
||||
GstPinosSink *pinossink = GST_PINOS_SINK (bsink);
|
||||
|
||||
gst_query_add_allocation_param (query, pinossink->allocator, NULL);
|
||||
gst_query_add_allocation_pool (query, GST_BUFFER_POOL_CAST (pinossink->pool), 0, 0, 0);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -207,18 +209,22 @@ gst_pinos_sink_class_init (GstPinosSinkClass * klass)
|
|||
|
||||
GST_DEBUG_CATEGORY_INIT (pinos_sink_debug, "pinossink", 0,
|
||||
"Pinos Sink");
|
||||
|
||||
process_mem_data_quark = g_quark_from_static_string ("GstPinosSinkProcessMemQuark");
|
||||
}
|
||||
|
||||
static void
|
||||
gst_pinos_sink_init (GstPinosSink * sink)
|
||||
{
|
||||
sink->allocator = gst_tmpfile_allocator_new ();
|
||||
sink->fdmanager = pinos_fd_manager_get (PINOS_FD_MANAGER_DEFAULT);
|
||||
sink->pool = gst_pinos_pool_new ();
|
||||
sink->client_name = pinos_client_name();
|
||||
sink->mode = DEFAULT_PROP_MODE;
|
||||
g_queue_init (&sink->empty);
|
||||
g_queue_init (&sink->filled);
|
||||
|
||||
sink->mem_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
||||
(GDestroyNotify) gst_memory_unref);
|
||||
sink->buf_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
||||
(GDestroyNotify) gst_buffer_unref);
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
|
|
@ -327,58 +333,128 @@ gst_pinos_sink_get_property (GObject * object, guint prop_id,
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GstPinosSink *sink;
|
||||
guint id;
|
||||
SpaMetaHeader *header;
|
||||
guint flags;
|
||||
} ProcessMemData;
|
||||
|
||||
static void
|
||||
on_new_buffer (GObject *gobject,
|
||||
process_mem_data_destroy (gpointer user_data)
|
||||
{
|
||||
ProcessMemData *data = user_data;
|
||||
|
||||
gst_object_unref (data->sink);
|
||||
g_slice_free (ProcessMemData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
on_add_buffer (GObject *gobject,
|
||||
guint id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSink *pinossink = user_data;
|
||||
SpaBuffer *b;
|
||||
GstBuffer *buf;
|
||||
unsigned int i;
|
||||
ProcessMemData data;
|
||||
|
||||
GST_LOG_OBJECT (pinossink, "add buffer");
|
||||
|
||||
if (!(b = pinos_stream_peek_buffer (pinossink->stream, id))) {
|
||||
g_warning ("failed to peek buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
buf = gst_buffer_new ();
|
||||
|
||||
data.sink = gst_object_ref (pinossink);
|
||||
data.id = id;
|
||||
data.header = NULL;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++) {
|
||||
SpaMeta *m = &SPA_BUFFER_METAS(b)[i];
|
||||
|
||||
switch (m->type) {
|
||||
case SPA_META_TYPE_HEADER:
|
||||
data.header = SPA_MEMBER (b, m->offset, SpaMetaHeader);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < b->n_datas; i++) {
|
||||
SpaData *d = &SPA_BUFFER_DATAS (b)[i];
|
||||
SpaMemory *mem;
|
||||
|
||||
mem = spa_memory_find (&d->mem.mem);
|
||||
|
||||
if (mem->fd) {
|
||||
GstMemory *fdmem = NULL;
|
||||
|
||||
fdmem = gst_fd_allocator_alloc (pinossink->allocator, dup (mem->fd),
|
||||
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->mem.offset,
|
||||
d->mem.size, NULL, NULL));
|
||||
}
|
||||
}
|
||||
data.flags = GST_BUFFER_FLAGS (buf);
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (buf),
|
||||
process_mem_data_quark,
|
||||
g_slice_dup (ProcessMemData, &data),
|
||||
process_mem_data_destroy);
|
||||
|
||||
gst_pinos_pool_add_buffer (GST_PINOS_POOL (pinossink->pool), buf);
|
||||
g_hash_table_insert (pinossink->buf_ids, GINT_TO_POINTER (id), buf);
|
||||
|
||||
g_queue_push_tail (&pinossink->empty, buf);
|
||||
pinos_main_loop_signal (pinossink->loop, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
on_remove_buffer (GObject *gobject,
|
||||
guint id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSink *pinossink = user_data;
|
||||
GstBuffer *buf;
|
||||
|
||||
GST_LOG_OBJECT (pinossink, "remove buffer");
|
||||
buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id));
|
||||
GST_MINI_OBJECT_CAST (buf)->dispose = NULL;
|
||||
|
||||
gst_pinos_pool_remove_buffer (GST_PINOS_POOL (pinossink->pool), buf);
|
||||
g_queue_remove (&pinossink->empty, buf);
|
||||
g_queue_remove (&pinossink->filled, buf);
|
||||
g_hash_table_remove (pinossink->buf_ids, GINT_TO_POINTER (id));
|
||||
}
|
||||
|
||||
static void
|
||||
on_new_buffer (GObject *gobject,
|
||||
guint id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSink *pinossink = user_data;
|
||||
GstBuffer *buf;
|
||||
|
||||
GST_LOG_OBJECT (pinossink, "got new buffer");
|
||||
if (pinossink->stream == NULL) {
|
||||
GST_LOG_OBJECT (pinossink, "no stream");
|
||||
return;
|
||||
}
|
||||
buf = g_hash_table_lookup (pinossink->buf_ids, GINT_TO_POINTER (id));
|
||||
|
||||
if (!(b = pinos_stream_peek_buffer (pinossink->stream))) {
|
||||
g_warning ("failed to capture buffer");
|
||||
return;
|
||||
g_debug ("recycle buffer %d %p", id, buf);
|
||||
if (buf) {
|
||||
g_queue_remove (&pinossink->filled, buf);
|
||||
g_queue_push_tail (&pinossink->empty, buf);
|
||||
pinos_main_loop_signal (pinossink->loop, FALSE);
|
||||
}
|
||||
|
||||
#if 0
|
||||
pinos_buffer_iter_init (&it, pbuf);
|
||||
while (pinos_buffer_iter_next (&it)) {
|
||||
switch (pinos_buffer_iter_get_type (&it)) {
|
||||
case PINOS_PACKET_TYPE_REUSE_MEM:
|
||||
{
|
||||
PinosPacketReuseMem p;
|
||||
|
||||
if (!pinos_buffer_iter_parse_reuse_mem (&it, &p))
|
||||
continue;
|
||||
|
||||
GST_LOG ("mem index %d is reused", p.id);
|
||||
g_hash_table_remove (pinossink->mem_ids, GINT_TO_POINTER (p.id));
|
||||
break;
|
||||
}
|
||||
case PINOS_PACKET_TYPE_REFRESH_REQUEST:
|
||||
{
|
||||
PinosPacketRefreshRequest p;
|
||||
|
||||
if (!pinos_buffer_iter_parse_refresh_request (&it, &p))
|
||||
continue;
|
||||
|
||||
GST_LOG ("refresh request");
|
||||
gst_pad_push_event (GST_BASE_SINK_PAD (pinossink),
|
||||
gst_video_event_new_upstream_force_key_unit (p.pts,
|
||||
p.request_type == 1, 0));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
pinos_buffer_iter_end (&it);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -409,6 +485,19 @@ on_stream_notify (GObject *gobject,
|
|||
pinos_main_loop_signal (pinossink->loop, FALSE);
|
||||
}
|
||||
|
||||
static void
|
||||
on_format_notify (GObject *gobject,
|
||||
GParamSpec *pspec,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSink *pinossink = user_data;
|
||||
SpaFormat *format;
|
||||
PinosProperties *props = NULL;
|
||||
|
||||
g_object_get (gobject, "format", &format, NULL);
|
||||
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
||||
{
|
||||
|
|
@ -452,7 +541,9 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
|||
pinos_main_loop_wait (pinossink->loop);
|
||||
}
|
||||
}
|
||||
res = TRUE;
|
||||
|
||||
#if 0
|
||||
if (state != PINOS_STREAM_STATE_STREAMING) {
|
||||
res = pinos_stream_start (pinossink->stream);
|
||||
|
||||
|
|
@ -468,6 +559,7 @@ gst_pinos_sink_setcaps (GstBaseSink * bsink, GstCaps * caps)
|
|||
pinos_main_loop_wait (pinossink->loop);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
pinos_main_loop_unlock (pinossink->loop);
|
||||
|
||||
pinossink->negotiated = res;
|
||||
|
|
@ -483,115 +575,54 @@ start_error:
|
|||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
SpaBuffer buffer;
|
||||
SpaMeta metas[1];
|
||||
SpaMetaHeader header;
|
||||
SpaData datas[1];
|
||||
GstMemory *mem;
|
||||
GstPinosSink *pinossink;
|
||||
int fd;
|
||||
} SinkBuffer;
|
||||
|
||||
static GstFlowReturn
|
||||
gst_pinos_sink_render (GstBaseSink * bsink, GstBuffer * buffer)
|
||||
{
|
||||
GstPinosSink *pinossink;
|
||||
SinkBuffer *b;
|
||||
GstMemory *mem = NULL;
|
||||
GstClockTime pts, dts, base;
|
||||
gsize size;
|
||||
gboolean res;
|
||||
ProcessMemData *data;
|
||||
|
||||
pinossink = GST_PINOS_SINK (bsink);
|
||||
|
||||
if (!pinossink->negotiated)
|
||||
goto not_negotiated;
|
||||
|
||||
base = GST_ELEMENT_CAST (bsink)->base_time;
|
||||
|
||||
size = gst_buffer_get_size (buffer);
|
||||
|
||||
b = g_slice_new (SinkBuffer);
|
||||
b->buffer.id = pinos_fd_manager_get_id (pinossink->fdmanager);
|
||||
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;
|
||||
b->buffer.datas = offsetof (SinkBuffer, datas);
|
||||
|
||||
pts = GST_BUFFER_PTS (buffer);
|
||||
dts = GST_BUFFER_DTS (buffer);
|
||||
if (!GST_CLOCK_TIME_IS_VALID (pts))
|
||||
pts = dts;
|
||||
else if (!GST_CLOCK_TIME_IS_VALID (dts))
|
||||
dts = pts;
|
||||
|
||||
b->header.flags = 0;
|
||||
b->header.seq = GST_BUFFER_OFFSET (buffer);
|
||||
b->header.pts = GST_CLOCK_TIME_IS_VALID (pts) ? pts + base : base;
|
||||
b->header.dts_offset = GST_CLOCK_TIME_IS_VALID (dts) && GST_CLOCK_TIME_IS_VALID (pts) ? pts - dts : 0;
|
||||
b->metas[0].type = SPA_META_TYPE_HEADER;
|
||||
b->metas[0].offset = offsetof (SinkBuffer, header);
|
||||
b->metas[0].size = sizeof (b->header);
|
||||
|
||||
if (gst_buffer_n_memory (buffer) == 1
|
||||
&& gst_is_fd_memory (gst_buffer_peek_memory (buffer, 0))) {
|
||||
mem = gst_buffer_get_memory (buffer, 0);
|
||||
} else {
|
||||
GstMapInfo minfo;
|
||||
GstAllocationParams params = {0, 0, 0, 0, { NULL, }};
|
||||
|
||||
GST_INFO_OBJECT (bsink, "Buffer cannot be payloaded without copying");
|
||||
|
||||
mem = gst_allocator_alloc (pinossink->allocator, size, ¶ms);
|
||||
if (!gst_memory_map (mem, &minfo, GST_MAP_WRITE))
|
||||
goto map_error;
|
||||
gst_buffer_extract (buffer, 0, minfo.data, size);
|
||||
gst_memory_unmap (mem, &minfo);
|
||||
}
|
||||
|
||||
pinos_main_loop_lock (pinossink->loop);
|
||||
if (pinos_stream_get_state (pinossink->stream) != PINOS_STREAM_STATE_STREAMING)
|
||||
goto streaming_error;
|
||||
|
||||
b->mem = mem;
|
||||
b->fd = gst_fd_memory_get_fd (mem);
|
||||
if (buffer->pool != GST_BUFFER_POOL_CAST (pinossink->pool)) {
|
||||
GstBuffer *b = NULL;
|
||||
|
||||
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;
|
||||
while (TRUE) {
|
||||
b = g_queue_peek_head (&pinossink->empty);
|
||||
if (b)
|
||||
break;
|
||||
|
||||
if (!(res = pinos_stream_send_buffer (pinossink->stream, &b->buffer)))
|
||||
pinos_main_loop_wait (pinossink->loop);
|
||||
}
|
||||
g_queue_push_tail (&pinossink->filled, b);
|
||||
|
||||
buffer = b;
|
||||
}
|
||||
|
||||
data = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buffer),
|
||||
process_mem_data_quark);
|
||||
|
||||
if (!(res = pinos_stream_send_buffer (pinossink->stream, data->id)))
|
||||
g_warning ("can't send buffer");
|
||||
|
||||
pinos_main_loop_unlock (pinossink->loop);
|
||||
|
||||
/* keep the memory around until we get the reuse mem message */
|
||||
g_hash_table_insert (pinossink->mem_ids, GINT_TO_POINTER (b->buffer.id), b);
|
||||
|
||||
return GST_FLOW_OK;
|
||||
|
||||
not_negotiated:
|
||||
{
|
||||
return GST_FLOW_NOT_NEGOTIATED;
|
||||
}
|
||||
map_error:
|
||||
{
|
||||
GST_ELEMENT_ERROR (pinossink, RESOURCE, FAILED,
|
||||
("failed to map buffer"), (NULL));
|
||||
gst_memory_unref (mem);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
streaming_error:
|
||||
{
|
||||
pinos_main_loop_unlock (pinossink->loop);
|
||||
gst_memory_unref (mem);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
}
|
||||
|
|
@ -627,7 +658,11 @@ gst_pinos_sink_start (GstBaseSink * basesink)
|
|||
|
||||
pinos_main_loop_lock (pinossink->loop);
|
||||
pinossink->stream = pinos_stream_new (pinossink->ctx, pinossink->client_name, props);
|
||||
pinossink->pool->stream = pinossink->stream;
|
||||
g_signal_connect (pinossink->stream, "notify::state", (GCallback) on_stream_notify, pinossink);
|
||||
g_signal_connect (pinossink->stream, "notify::format", (GCallback) on_format_notify, pinossink);
|
||||
g_signal_connect (pinossink->stream, "add-buffer", (GCallback) on_add_buffer, pinossink);
|
||||
g_signal_connect (pinossink->stream, "remove-buffer", (GCallback) on_remove_buffer, pinossink);
|
||||
g_signal_connect (pinossink->stream, "new-buffer", (GCallback) on_new_buffer, pinossink);
|
||||
pinos_main_loop_unlock (pinossink->loop);
|
||||
|
||||
|
|
@ -644,6 +679,7 @@ gst_pinos_sink_stop (GstBaseSink * basesink)
|
|||
pinos_stream_stop (pinossink->stream);
|
||||
pinos_stream_disconnect (pinossink->stream);
|
||||
g_clear_object (&pinossink->stream);
|
||||
pinossink->pool->stream = NULL;
|
||||
}
|
||||
pinos_main_loop_unlock (pinossink->loop);
|
||||
|
||||
|
|
@ -787,10 +823,10 @@ gst_pinos_sink_change_state (GstElement * element, GstStateChange transition)
|
|||
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
||||
break;
|
||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
||||
g_hash_table_remove_all (this->mem_ids);
|
||||
g_hash_table_remove_all (this->buf_ids);
|
||||
break;
|
||||
case GST_STATE_CHANGE_READY_TO_NULL:
|
||||
g_hash_table_remove_all (this->mem_ids);
|
||||
g_hash_table_remove_all (this->buf_ids);
|
||||
gst_pinos_sink_close (this);
|
||||
break;
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include <gst/base/gstbasesink.h>
|
||||
|
||||
#include <client/pinos.h>
|
||||
#include <gst/gstpinospool.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -84,8 +85,11 @@ struct _GstPinosSink {
|
|||
GstStructure *properties;
|
||||
GstPinosSinkMode mode;
|
||||
|
||||
PinosFdManager *fdmanager;
|
||||
GHashTable *mem_ids;
|
||||
GstPinosPool *pool;
|
||||
GHashTable *buf_ids;
|
||||
|
||||
GQueue empty;
|
||||
GQueue filled;
|
||||
};
|
||||
|
||||
struct _GstPinosSinkClass {
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ gst_pinos_src_finalize (GObject * object)
|
|||
gst_object_unref (pinossrc->clock);
|
||||
g_free (pinossrc->path);
|
||||
g_free (pinossrc->client_name);
|
||||
g_hash_table_unref (pinossrc->mem_ids);
|
||||
g_hash_table_unref (pinossrc->buf_ids);
|
||||
|
||||
G_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -274,7 +274,7 @@ gst_pinos_src_init (GstPinosSrc * src)
|
|||
|
||||
src->fd_allocator = gst_fd_allocator_new ();
|
||||
src->client_name = pinos_client_name ();
|
||||
src->mem_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gst_memory_unref);
|
||||
src->buf_ids = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) gst_buffer_unref);
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
|
|
@ -326,7 +326,9 @@ gst_pinos_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
|
|||
|
||||
typedef struct {
|
||||
GstPinosSrc *src;
|
||||
SpaBuffer *buffer;
|
||||
guint id;
|
||||
SpaMetaHeader *header;
|
||||
guint flags;
|
||||
} ProcessMemData;
|
||||
|
||||
static void
|
||||
|
|
@ -338,8 +340,24 @@ process_mem_data_destroy (gpointer user_data)
|
|||
g_slice_free (ProcessMemData, data);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
buffer_recycle (GstMiniObject *obj)
|
||||
{
|
||||
ProcessMemData *data;
|
||||
|
||||
gst_mini_object_ref (obj);
|
||||
data = gst_mini_object_get_qdata (obj,
|
||||
process_mem_data_quark);
|
||||
GST_BUFFER_FLAGS (obj) = data->flags;
|
||||
|
||||
pinos_stream_recycle_buffer (data->src->stream, data->id);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
on_new_buffer (GObject *gobject,
|
||||
on_add_buffer (GObject *gobject,
|
||||
guint id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSrc *pinossrc = user_data;
|
||||
|
|
@ -348,39 +366,27 @@ on_new_buffer (GObject *gobject,
|
|||
unsigned int i;
|
||||
ProcessMemData data;
|
||||
|
||||
GST_LOG_OBJECT (pinossrc, "got new buffer");
|
||||
if (!(b = pinos_stream_peek_buffer (pinossrc->stream))) {
|
||||
g_warning ("failed to capture buffer");
|
||||
GST_LOG_OBJECT (pinossrc, "add buffer");
|
||||
|
||||
if (!(b = pinos_stream_peek_buffer (pinossrc->stream, id))) {
|
||||
g_warning ("failed to peek buffer");
|
||||
return;
|
||||
}
|
||||
|
||||
buf = gst_buffer_new ();
|
||||
GST_MINI_OBJECT_CAST (buf)->dispose = buffer_recycle;
|
||||
|
||||
data.src = gst_object_ref (pinossrc);
|
||||
data.buffer = b;
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (buf),
|
||||
process_mem_data_quark,
|
||||
g_slice_dup (ProcessMemData, &data),
|
||||
process_mem_data_destroy);
|
||||
data.id = id;
|
||||
data.header = NULL;
|
||||
|
||||
for (i = 0; i < b->n_metas; i++) {
|
||||
SpaMeta *m = &SPA_BUFFER_METAS(b)[i];
|
||||
|
||||
switch (m->type) {
|
||||
case SPA_META_TYPE_HEADER:
|
||||
{
|
||||
SpaMetaHeader *h = SPA_MEMBER (b, m->offset, SpaMetaHeader);
|
||||
|
||||
GST_INFO ("pts %" G_GUINT64_FORMAT ", dts_offset %"G_GUINT64_FORMAT, h->pts, h->dts_offset);
|
||||
|
||||
if (GST_CLOCK_TIME_IS_VALID (h->pts)) {
|
||||
GST_BUFFER_PTS (buf) = h->pts;
|
||||
if (GST_BUFFER_PTS (buf) + h->dts_offset > 0)
|
||||
GST_BUFFER_DTS (buf) = GST_BUFFER_PTS (buf) + h->dts_offset;
|
||||
}
|
||||
GST_BUFFER_OFFSET (buf) = h->seq;
|
||||
data.header = SPA_MEMBER (b, m->offset, SpaMetaHeader);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
@ -404,8 +410,59 @@ on_new_buffer (GObject *gobject,
|
|||
d->mem.size, NULL, NULL));
|
||||
}
|
||||
}
|
||||
data.flags = GST_BUFFER_FLAGS (buf);
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (buf),
|
||||
process_mem_data_quark,
|
||||
g_slice_dup (ProcessMemData, &data),
|
||||
process_mem_data_destroy);
|
||||
|
||||
g_hash_table_insert (pinossrc->buf_ids, GINT_TO_POINTER (id), buf);
|
||||
}
|
||||
|
||||
static void
|
||||
on_remove_buffer (GObject *gobject,
|
||||
guint id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSrc *pinossrc = user_data;
|
||||
GstBuffer *buf;
|
||||
|
||||
GST_LOG_OBJECT (pinossrc, "remove buffer");
|
||||
buf = g_hash_table_lookup (pinossrc->buf_ids, GINT_TO_POINTER (id));
|
||||
GST_MINI_OBJECT_CAST (buf)->dispose = NULL;
|
||||
|
||||
g_hash_table_remove (pinossrc->buf_ids, GINT_TO_POINTER (id));
|
||||
}
|
||||
|
||||
static void
|
||||
on_new_buffer (GObject *gobject,
|
||||
guint id,
|
||||
gpointer user_data)
|
||||
{
|
||||
GstPinosSrc *pinossrc = user_data;
|
||||
GstBuffer *buf;
|
||||
|
||||
GST_LOG_OBJECT (pinossrc, "got new buffer");
|
||||
buf = g_hash_table_lookup (pinossrc->buf_ids, GINT_TO_POINTER (id));
|
||||
|
||||
if (buf) {
|
||||
ProcessMemData *data;
|
||||
SpaMetaHeader *h;
|
||||
|
||||
data = gst_mini_object_get_qdata (GST_MINI_OBJECT_CAST (buf),
|
||||
process_mem_data_quark);
|
||||
h = data->header;
|
||||
if (h) {
|
||||
GST_INFO ("pts %" G_GUINT64_FORMAT ", dts_offset %"G_GUINT64_FORMAT, h->pts, h->dts_offset);
|
||||
|
||||
if (GST_CLOCK_TIME_IS_VALID (h->pts)) {
|
||||
GST_BUFFER_PTS (buf) = h->pts;
|
||||
if (GST_BUFFER_PTS (buf) + h->dts_offset > 0)
|
||||
GST_BUFFER_DTS (buf) = GST_BUFFER_PTS (buf) + h->dts_offset;
|
||||
}
|
||||
GST_BUFFER_OFFSET (buf) = h->seq;
|
||||
}
|
||||
|
||||
g_queue_push_tail (&pinossrc->queue, buf);
|
||||
|
||||
pinos_main_loop_signal (pinossrc->loop, FALSE);
|
||||
|
|
@ -486,7 +543,6 @@ parse_stream_properties (GstPinosSrc *pinossrc, PinosProperties *props)
|
|||
static gboolean
|
||||
gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
|
||||
{
|
||||
SpaFormat *format;
|
||||
gboolean res;
|
||||
PinosProperties *props;
|
||||
|
||||
|
|
@ -505,17 +561,8 @@ gst_pinos_src_stream_start (GstPinosSrc *pinossrc)
|
|||
}
|
||||
|
||||
g_object_get (pinossrc->stream, "properties", &props, NULL);
|
||||
g_object_get (pinossrc->stream, "format", &format, NULL);
|
||||
|
||||
pinos_main_loop_unlock (pinossrc->loop);
|
||||
|
||||
if (format) {
|
||||
GstCaps *caps = gst_caps_from_format (format);
|
||||
gst_base_src_set_caps (GST_BASE_SRC (pinossrc), caps);
|
||||
gst_caps_unref (caps);
|
||||
spa_format_unref (format);
|
||||
}
|
||||
|
||||
parse_stream_properties (pinossrc, props);
|
||||
pinos_properties_free (props);
|
||||
|
||||
|
|
@ -675,6 +722,11 @@ on_format_notify (GObject *gobject,
|
|||
caps = gst_caps_from_format (format);
|
||||
gst_base_src_set_caps (GST_BASE_SRC (pinossrc), caps);
|
||||
gst_caps_unref (caps);
|
||||
|
||||
|
||||
|
||||
|
||||
pinos_stream_start_allocation (pinossrc->stream, NULL);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
|
@ -944,6 +996,8 @@ gst_pinos_src_open (GstPinosSrc * pinossrc)
|
|||
pinossrc->stream = pinos_stream_new (pinossrc->ctx, pinossrc->client_name, props);
|
||||
g_signal_connect (pinossrc->stream, "notify::state", (GCallback) on_stream_notify, pinossrc);
|
||||
g_signal_connect (pinossrc->stream, "notify::format", (GCallback) on_format_notify, pinossrc);
|
||||
g_signal_connect (pinossrc->stream, "add-buffer", (GCallback) on_add_buffer, pinossrc);
|
||||
g_signal_connect (pinossrc->stream, "remove-buffer", (GCallback) on_remove_buffer, pinossrc);
|
||||
g_signal_connect (pinossrc->stream, "new-buffer", (GCallback) on_new_buffer, pinossrc);
|
||||
pinos_main_loop_unlock (pinossrc->loop);
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ struct _GstPinosSrc {
|
|||
GstAllocator *fd_allocator;
|
||||
GstStructure *properties;
|
||||
|
||||
GHashTable *mem_ids;
|
||||
GHashTable *buf_ids;
|
||||
GQueue queue;
|
||||
GstClock *clock;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue