mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-04 15:10:20 +00:00
fdpay: use fd allocator
Use the fd allocator instead of the dmabuf allocator. Update the wire protocol
This commit is contained in:
parent
8b02c9040a
commit
75d5fa91e2
|
@ -40,7 +40,7 @@
|
|||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/base/gstbasetransform.h>
|
||||
#include <gst/allocators/gstdmabuf.h>
|
||||
#include <gst/allocators/gstfdmemory.h>
|
||||
#include <gio/gunixfdmessage.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
|
@ -115,7 +115,7 @@ gst_fddepay_class_init (GstFddepayClass * klass)
|
|||
static void
|
||||
gst_fddepay_init (GstFddepay * fddepay)
|
||||
{
|
||||
fddepay->dmabuf_allocator = gst_dmabuf_allocator_new ();
|
||||
fddepay->fd_allocator = gst_fd_allocator_new ();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -126,9 +126,9 @@ gst_fddepay_dispose (GObject * object)
|
|||
GST_DEBUG_OBJECT (fddepay, "dispose");
|
||||
|
||||
/* clean up as possible. may be called multiple times */
|
||||
if (fddepay->dmabuf_allocator != NULL) {
|
||||
g_object_unref (G_OBJECT (fddepay->dmabuf_allocator));
|
||||
fddepay->dmabuf_allocator = NULL;
|
||||
if (fddepay->fd_allocator != NULL) {
|
||||
g_object_unref (G_OBJECT (fddepay->fd_allocator));
|
||||
fddepay->fd_allocator = NULL;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gst_fddepay_parent_class)->dispose (object);
|
||||
|
@ -169,7 +169,7 @@ gst_fddepay_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
{
|
||||
GstFddepay *fddepay = GST_FDDEPAY (trans);
|
||||
FDMessage msg;
|
||||
GstMemory *dmabufmem = NULL;
|
||||
GstMemory *fdmem = NULL;
|
||||
GstNetControlMessageMeta * meta;
|
||||
int *fds = NULL;
|
||||
int fds_len = 0;
|
||||
|
@ -215,15 +215,17 @@ gst_fddepay_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
|
|||
|
||||
/* FIXME: Use stat to find out the size of the file, to make sure that the
|
||||
* size we've been told is the true size for safety and security. */
|
||||
dmabufmem = gst_dmabuf_allocator_alloc (fddepay->dmabuf_allocator, fd,
|
||||
msg.offset + msg.size);
|
||||
gst_memory_resize (dmabufmem, msg.offset, msg.size);
|
||||
fdmem = gst_fd_allocator_alloc (fddepay->fd_allocator, fd,
|
||||
msg.offset + msg.size, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (fdmem, msg.offset, msg.size);
|
||||
|
||||
gst_buffer_remove_all_memory (buf);
|
||||
gst_buffer_remove_meta (buf,
|
||||
gst_buffer_get_meta (buf, GST_NET_CONTROL_MESSAGE_META_API_TYPE));
|
||||
gst_buffer_append_memory (buf, dmabufmem);
|
||||
dmabufmem = NULL;
|
||||
gst_buffer_append_memory (buf, fdmem);
|
||||
fdmem = NULL;
|
||||
|
||||
GST_BUFFER_OFFSET (buf) = msg.seq;
|
||||
|
||||
return GST_FLOW_OK;
|
||||
error:
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef struct _GstFddepayClass GstFddepayClass;
|
|||
struct _GstFddepay
|
||||
{
|
||||
GstBaseTransform base_fddepay;
|
||||
GstAllocator *dmabuf_allocator;
|
||||
GstAllocator *fd_allocator;
|
||||
};
|
||||
|
||||
struct _GstFddepayClass
|
||||
|
|
|
@ -40,8 +40,6 @@
|
|||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "wire-protocol.h"
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <gst/allocators/gstfdmemory.h>
|
||||
#include <gst/base/gstbasetransform.h>
|
||||
|
@ -55,6 +53,8 @@
|
|||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wire-protocol.h"
|
||||
|
||||
GST_DEBUG_CATEGORY_STATIC (gst_fdpay_debug_category);
|
||||
#define GST_CAT_DEFAULT gst_fdpay_debug_category
|
||||
|
||||
|
@ -242,12 +242,16 @@ gst_fdpay_transform (GstBaseTransform * trans, GstBuffer * inbuf,
|
|||
GstMapInfo info;
|
||||
GError *err = NULL;
|
||||
GSocketControlMessage *fdmsg = NULL;
|
||||
FDMessage msg = { 0, 0 };
|
||||
FDMessage msg = { 0, };
|
||||
|
||||
GST_DEBUG_OBJECT (fdpay, "transform_ip");
|
||||
|
||||
fdmem = gst_fdpay_get_fd_memory (fdpay, inbuf);
|
||||
|
||||
msg.flags = 0;
|
||||
msg.seq = GST_BUFFER_OFFSET (inbuf);
|
||||
msg.pts = GST_BUFFER_TIMESTAMP (inbuf);
|
||||
msg.dts_offset = 0;
|
||||
msg.size = fdmem->size;
|
||||
msg.offset = fdmem->offset;
|
||||
|
||||
|
|
|
@ -83,8 +83,6 @@ gst_tmpfile_allocator_alloc (GstAllocator * allocator, gsize size,
|
|||
GstAllocationParams * params)
|
||||
{
|
||||
GstTmpFileAllocator *alloc = (GstTmpFileAllocator *) allocator;
|
||||
GstFdAllocator *fdalloc = GST_FD_ALLOCATOR_CAST (allocator);
|
||||
GstFdAllocatorClass *klass = GST_FD_ALLOCATOR_GET_CLASS (alloc);
|
||||
GstMemory *mem;
|
||||
int fd;
|
||||
gsize maxsize;
|
||||
|
@ -99,7 +97,7 @@ gst_tmpfile_allocator_alloc (GstAllocator * allocator, gsize size,
|
|||
if (fd < 0)
|
||||
return NULL;
|
||||
|
||||
mem = klass->alloc (fdalloc, fd, maxsize, GST_FD_MEMORY_FLAG_NONE);
|
||||
mem = gst_fd_allocator_alloc (allocator, fd, maxsize, GST_FD_MEMORY_FLAG_NONE);
|
||||
gst_memory_resize (mem, pad (params->prefix, params->align), size);
|
||||
|
||||
return mem;
|
||||
|
@ -121,6 +119,8 @@ gst_tmpfile_allocator_init (GstTmpFileAllocator * allocator)
|
|||
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
|
||||
|
||||
alloc->mem_type = GST_ALLOCATOR_TMPFILE;
|
||||
|
||||
GST_OBJECT_FLAG_UNSET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
|
||||
}
|
||||
|
||||
GstAllocator *
|
||||
|
|
|
@ -22,12 +22,24 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
/* Almost the simplest possible FD passing protocol. Each message should have
|
||||
/**
|
||||
* @flags: possible flags
|
||||
* @seq: a sequence number
|
||||
* @pts: a PTS or presentation timestamp
|
||||
* @dts_offset: an offset to @pts to get the DTS
|
||||
* @offset: offset in fd
|
||||
* @size: size of data in fd
|
||||
*
|
||||
* Almost the simplest possible FD passing protocol. Each message should have
|
||||
* a file-descriptor attached which should be mmapable. The data in the FD can
|
||||
* be found at offset and is size bytes long. */
|
||||
typedef struct {
|
||||
uint64_t offset;
|
||||
uint64_t size;
|
||||
guint32 flags;
|
||||
guint32 seq;
|
||||
gint64 pts;
|
||||
gint64 dts_offset;
|
||||
guint64 offset;
|
||||
guint64 size;
|
||||
} FDMessage;
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue