mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
work on stream negotiation and start
Add more buffer types to add and remove memory shared memory between the server and client. We would like to send buffers only once and then simply reference them by index. Do format negotiation and stream start with a START message.
This commit is contained in:
parent
31041a4e16
commit
af3de36416
23 changed files with 1246 additions and 349 deletions
|
|
@ -45,7 +45,7 @@
|
|||
#include <gst/video/video.h>
|
||||
|
||||
|
||||
static GQuark fdpayload_data_quark;
|
||||
static GQuark process_mem_data_quark;
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (pinos_src_debug);
|
||||
#define GST_CAT_DEFAULT pinos_src_debug
|
||||
|
|
@ -183,6 +183,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_OBJECT_CLASS (parent_class)->finalize (object);
|
||||
}
|
||||
|
|
@ -254,7 +255,7 @@ gst_pinos_src_class_init (GstPinosSrcClass * klass)
|
|||
GST_DEBUG_CATEGORY_INIT (pinos_src_debug, "pinossrc", 0,
|
||||
"Pinos Source");
|
||||
|
||||
fdpayload_data_quark = g_quark_from_static_string ("GstPinosSrcFDPayloadQuark");
|
||||
process_mem_data_quark = g_quark_from_static_string ("GstPinosSrcProcessMemQuark");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -269,6 +270,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);
|
||||
}
|
||||
|
||||
static GstCaps *
|
||||
|
|
@ -320,16 +322,16 @@ gst_pinos_src_src_fixate (GstBaseSrc * bsrc, GstCaps * caps)
|
|||
|
||||
typedef struct {
|
||||
GstPinosSrc *src;
|
||||
PinosPacketFDPayload p;
|
||||
} FDPayloadData;
|
||||
PinosPacketProcessMem p;
|
||||
} ProcessMemData;
|
||||
|
||||
static void
|
||||
fdpayload_data_destroy (gpointer user_data)
|
||||
process_mem_data_destroy (gpointer user_data)
|
||||
{
|
||||
FDPayloadData *data = user_data;
|
||||
ProcessMemData *data = user_data;
|
||||
GstPinosSrc *pinossrc = data->src;
|
||||
PinosBufferBuilder b;
|
||||
PinosPacketReleaseFDPayload r;
|
||||
PinosPacketReuseMem r;
|
||||
PinosBuffer pbuf;
|
||||
|
||||
r.id = data->p.id;
|
||||
|
|
@ -339,7 +341,7 @@ fdpayload_data_destroy (gpointer user_data)
|
|||
GST_OBJECT_LOCK (pinossrc);
|
||||
if (pinossrc->stream_state == PINOS_STREAM_STATE_STREAMING) {
|
||||
pinos_stream_buffer_builder_init (pinossrc->stream, &b);
|
||||
pinos_buffer_builder_add_release_fd_payload (&b, &r);
|
||||
pinos_buffer_builder_add_reuse_mem (&b, &r);
|
||||
pinos_buffer_builder_end (&b, &pbuf);
|
||||
|
||||
GST_DEBUG_OBJECT (pinossrc, "send release-fd for %d", r.id);
|
||||
|
|
@ -349,7 +351,7 @@ fdpayload_data_destroy (gpointer user_data)
|
|||
GST_OBJECT_UNLOCK (pinossrc);
|
||||
|
||||
gst_object_unref (pinossrc);
|
||||
g_slice_free (FDPayloadData, data);
|
||||
g_slice_free (ProcessMemData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -390,33 +392,59 @@ on_new_buffer (GObject *gobject,
|
|||
GST_BUFFER_OFFSET (buf) = hdr.seq;
|
||||
break;
|
||||
}
|
||||
case PINOS_PACKET_TYPE_FD_PAYLOAD:
|
||||
case PINOS_PACKET_TYPE_ADD_MEM:
|
||||
{
|
||||
GstMemory *fdmem = NULL;
|
||||
FDPayloadData data;
|
||||
PinosPacketAddMem p;
|
||||
int fd;
|
||||
|
||||
if (!pinos_buffer_iter_parse_fd_payload (&it, &data.p))
|
||||
if (!pinos_buffer_iter_parse_add_mem (&it, &p))
|
||||
goto parse_failed;
|
||||
|
||||
GST_DEBUG ("got fd payload id %d", data.p.id);
|
||||
fd = pinos_buffer_get_fd (pbuf, data.p.fd_index);
|
||||
fd = pinos_buffer_get_fd (pbuf, p.fd_index);
|
||||
if (fd == -1)
|
||||
goto no_fds;
|
||||
goto parse_failed;
|
||||
|
||||
fdmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (fd),
|
||||
p.offset + p.size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (fdmem, p.offset, p.size);
|
||||
|
||||
g_hash_table_insert (pinossrc->mem_ids, GINT_TO_POINTER (p.id), fdmem);
|
||||
break;
|
||||
}
|
||||
case PINOS_PACKET_TYPE_REMOVE_MEM:
|
||||
{
|
||||
PinosPacketRemoveMem p;
|
||||
|
||||
if (!pinos_buffer_iter_parse_remove_mem (&it, &p))
|
||||
goto parse_failed;
|
||||
|
||||
g_hash_table_remove (pinossrc->mem_ids, GINT_TO_POINTER (p.id));
|
||||
break;
|
||||
}
|
||||
case PINOS_PACKET_TYPE_PROCESS_MEM:
|
||||
{
|
||||
GstMemory *fdmem = NULL;
|
||||
ProcessMemData data;
|
||||
|
||||
if (!pinos_buffer_iter_parse_process_mem (&it, &data.p))
|
||||
goto parse_failed;
|
||||
|
||||
GST_DEBUG ("got mem id %d", data.p.id);
|
||||
if (!(fdmem = g_hash_table_lookup (pinossrc->mem_ids, GINT_TO_POINTER (data.p.id))))
|
||||
goto parse_failed;
|
||||
|
||||
if (buf == NULL)
|
||||
buf = gst_buffer_new ();
|
||||
|
||||
fdmem = gst_fd_allocator_alloc (pinossrc->fd_allocator, dup (fd),
|
||||
data.p.offset + data.p.size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (fdmem, data.p.offset, data.p.size);
|
||||
fdmem = gst_memory_share (fdmem, data.p.offset, data.p.size);
|
||||
gst_buffer_append_memory (buf, fdmem);
|
||||
|
||||
data.src = gst_object_ref (pinossrc);
|
||||
gst_mini_object_set_qdata (GST_MINI_OBJECT_CAST (fdmem),
|
||||
fdpayload_data_quark,
|
||||
g_slice_dup (FDPayloadData, &data),
|
||||
fdpayload_data_destroy);
|
||||
process_mem_data_quark,
|
||||
g_slice_dup (ProcessMemData, &data),
|
||||
process_mem_data_destroy);
|
||||
break;
|
||||
}
|
||||
case PINOS_PACKET_TYPE_FORMAT_CHANGE:
|
||||
|
|
@ -456,16 +484,6 @@ parse_failed:
|
|||
pinos_main_loop_signal (pinossrc->loop, FALSE);
|
||||
return;
|
||||
}
|
||||
no_fds:
|
||||
{
|
||||
pinos_buffer_iter_end (&it);
|
||||
pinos_buffer_unref (pbuf);
|
||||
gst_buffer_unref (buf);
|
||||
GST_ELEMENT_ERROR (pinossrc, RESOURCE, FAILED, ("fd not found in buffer"), (NULL));
|
||||
pinos_main_loop_signal (pinossrc->loop, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue