mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04: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
5 changed files with 39 additions and 21 deletions
|
|
@ -40,7 +40,7 @@
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/base/gstbasetransform.h>
|
#include <gst/base/gstbasetransform.h>
|
||||||
#include <gst/allocators/gstdmabuf.h>
|
#include <gst/allocators/gstfdmemory.h>
|
||||||
#include <gio/gunixfdmessage.h>
|
#include <gio/gunixfdmessage.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
@ -115,7 +115,7 @@ gst_fddepay_class_init (GstFddepayClass * klass)
|
||||||
static void
|
static void
|
||||||
gst_fddepay_init (GstFddepay * fddepay)
|
gst_fddepay_init (GstFddepay * fddepay)
|
||||||
{
|
{
|
||||||
fddepay->dmabuf_allocator = gst_dmabuf_allocator_new ();
|
fddepay->fd_allocator = gst_fd_allocator_new ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -126,9 +126,9 @@ gst_fddepay_dispose (GObject * object)
|
||||||
GST_DEBUG_OBJECT (fddepay, "dispose");
|
GST_DEBUG_OBJECT (fddepay, "dispose");
|
||||||
|
|
||||||
/* clean up as possible. may be called multiple times */
|
/* clean up as possible. may be called multiple times */
|
||||||
if (fddepay->dmabuf_allocator != NULL) {
|
if (fddepay->fd_allocator != NULL) {
|
||||||
g_object_unref (G_OBJECT (fddepay->dmabuf_allocator));
|
g_object_unref (G_OBJECT (fddepay->fd_allocator));
|
||||||
fddepay->dmabuf_allocator = NULL;
|
fddepay->fd_allocator = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (gst_fddepay_parent_class)->dispose (object);
|
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);
|
GstFddepay *fddepay = GST_FDDEPAY (trans);
|
||||||
FDMessage msg;
|
FDMessage msg;
|
||||||
GstMemory *dmabufmem = NULL;
|
GstMemory *fdmem = NULL;
|
||||||
GstNetControlMessageMeta * meta;
|
GstNetControlMessageMeta * meta;
|
||||||
int *fds = NULL;
|
int *fds = NULL;
|
||||||
int fds_len = 0;
|
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
|
/* 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. */
|
* size we've been told is the true size for safety and security. */
|
||||||
dmabufmem = gst_dmabuf_allocator_alloc (fddepay->dmabuf_allocator, fd,
|
fdmem = gst_fd_allocator_alloc (fddepay->fd_allocator, fd,
|
||||||
msg.offset + msg.size);
|
msg.offset + msg.size, GST_FD_MEMORY_FLAG_NONE);
|
||||||
gst_memory_resize (dmabufmem, msg.offset, msg.size);
|
gst_memory_resize (fdmem, msg.offset, msg.size);
|
||||||
|
|
||||||
gst_buffer_remove_all_memory (buf);
|
gst_buffer_remove_all_memory (buf);
|
||||||
gst_buffer_remove_meta (buf,
|
gst_buffer_remove_meta (buf,
|
||||||
gst_buffer_get_meta (buf, GST_NET_CONTROL_MESSAGE_META_API_TYPE));
|
gst_buffer_get_meta (buf, GST_NET_CONTROL_MESSAGE_META_API_TYPE));
|
||||||
gst_buffer_append_memory (buf, dmabufmem);
|
gst_buffer_append_memory (buf, fdmem);
|
||||||
dmabufmem = NULL;
|
fdmem = NULL;
|
||||||
|
|
||||||
|
GST_BUFFER_OFFSET (buf) = msg.seq;
|
||||||
|
|
||||||
return GST_FLOW_OK;
|
return GST_FLOW_OK;
|
||||||
error:
|
error:
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ typedef struct _GstFddepayClass GstFddepayClass;
|
||||||
struct _GstFddepay
|
struct _GstFddepay
|
||||||
{
|
{
|
||||||
GstBaseTransform base_fddepay;
|
GstBaseTransform base_fddepay;
|
||||||
GstAllocator *dmabuf_allocator;
|
GstAllocator *fd_allocator;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstFddepayClass
|
struct _GstFddepayClass
|
||||||
|
|
|
||||||
|
|
@ -40,8 +40,6 @@
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wire-protocol.h"
|
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <gst/allocators/gstfdmemory.h>
|
#include <gst/allocators/gstfdmemory.h>
|
||||||
#include <gst/base/gstbasetransform.h>
|
#include <gst/base/gstbasetransform.h>
|
||||||
|
|
@ -55,6 +53,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "wire-protocol.h"
|
||||||
|
|
||||||
GST_DEBUG_CATEGORY_STATIC (gst_fdpay_debug_category);
|
GST_DEBUG_CATEGORY_STATIC (gst_fdpay_debug_category);
|
||||||
#define GST_CAT_DEFAULT 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;
|
GstMapInfo info;
|
||||||
GError *err = NULL;
|
GError *err = NULL;
|
||||||
GSocketControlMessage *fdmsg = NULL;
|
GSocketControlMessage *fdmsg = NULL;
|
||||||
FDMessage msg = { 0, 0 };
|
FDMessage msg = { 0, };
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (fdpay, "transform_ip");
|
GST_DEBUG_OBJECT (fdpay, "transform_ip");
|
||||||
|
|
||||||
fdmem = gst_fdpay_get_fd_memory (fdpay, inbuf);
|
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.size = fdmem->size;
|
||||||
msg.offset = fdmem->offset;
|
msg.offset = fdmem->offset;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,8 +83,6 @@ gst_tmpfile_allocator_alloc (GstAllocator * allocator, gsize size,
|
||||||
GstAllocationParams * params)
|
GstAllocationParams * params)
|
||||||
{
|
{
|
||||||
GstTmpFileAllocator *alloc = (GstTmpFileAllocator *) allocator;
|
GstTmpFileAllocator *alloc = (GstTmpFileAllocator *) allocator;
|
||||||
GstFdAllocator *fdalloc = GST_FD_ALLOCATOR_CAST (allocator);
|
|
||||||
GstFdAllocatorClass *klass = GST_FD_ALLOCATOR_GET_CLASS (alloc);
|
|
||||||
GstMemory *mem;
|
GstMemory *mem;
|
||||||
int fd;
|
int fd;
|
||||||
gsize maxsize;
|
gsize maxsize;
|
||||||
|
|
@ -99,7 +97,7 @@ gst_tmpfile_allocator_alloc (GstAllocator * allocator, gsize size,
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return NULL;
|
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);
|
gst_memory_resize (mem, pad (params->prefix, params->align), size);
|
||||||
|
|
||||||
return mem;
|
return mem;
|
||||||
|
|
@ -121,6 +119,8 @@ gst_tmpfile_allocator_init (GstTmpFileAllocator * allocator)
|
||||||
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
|
GstAllocator *alloc = GST_ALLOCATOR_CAST (allocator);
|
||||||
|
|
||||||
alloc->mem_type = GST_ALLOCATOR_TMPFILE;
|
alloc->mem_type = GST_ALLOCATOR_TMPFILE;
|
||||||
|
|
||||||
|
GST_OBJECT_FLAG_UNSET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
GstAllocator *
|
GstAllocator *
|
||||||
|
|
|
||||||
|
|
@ -22,12 +22,24 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#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
|
* a file-descriptor attached which should be mmapable. The data in the FD can
|
||||||
* be found at offset and is size bytes long. */
|
* be found at offset and is size bytes long. */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t offset;
|
guint32 flags;
|
||||||
uint64_t size;
|
guint32 seq;
|
||||||
|
gint64 pts;
|
||||||
|
gint64 dts_offset;
|
||||||
|
guint64 offset;
|
||||||
|
guint64 size;
|
||||||
} FDMessage;
|
} FDMessage;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue