mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
Rework transport protocol
Use a more simple tranport protocol for the realtime data. Use a piece of shared memory and a socket where we use a 1byte read/write to trigger remote actions. Also use a ringbuffer for events.
This commit is contained in:
parent
7e46f9e3ad
commit
b774b99db5
22 changed files with 797 additions and 364 deletions
|
|
@ -1,111 +0,0 @@
|
|||
/* Pinos
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "memfd-wrappers.h"
|
||||
|
||||
#include <pinos/client/log.h>
|
||||
#include <pinos/server/utils.h>
|
||||
|
||||
#undef USE_MEMFD
|
||||
|
||||
gboolean
|
||||
pinos_memblock_alloc (PinosMemblockFlags flags,
|
||||
gsize size,
|
||||
PinosMemblock *mem)
|
||||
{
|
||||
g_return_val_if_fail (mem != NULL, FALSE);
|
||||
g_return_val_if_fail (size > 0, FALSE);
|
||||
|
||||
mem->flags = flags;
|
||||
mem->size = size;
|
||||
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_WITH_FD) {
|
||||
#ifdef USE_MEMFD
|
||||
mem->fd = memfd_create ("pinos-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||
if (mem->fd == -1) {
|
||||
pinos_log_error ("Failed to create memfd: %s\n", strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
char filename[] = "/dev/shm/spa-tmpfile.XXXXXX";
|
||||
mem->fd = mkostemp (filename, O_CLOEXEC);
|
||||
if (mem->fd == -1) {
|
||||
pinos_log_error ("Failed to create temporary file: %s\n", strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
unlink (filename);
|
||||
#endif
|
||||
|
||||
if (ftruncate (mem->fd, size) < 0) {
|
||||
pinos_log_warn ("Failed to truncate temporary file: %s", strerror (errno));
|
||||
close (mem->fd);
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef USE_MEMFD
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_SEAL) {
|
||||
unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
|
||||
if (fcntl (mem->fd, F_ADD_SEALS, seals) == -1) {
|
||||
pinos_log_warn ("Failed to add seals: %s", strerror (errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_MAP_READWRITE) {
|
||||
int prot = 0;
|
||||
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_MAP_READ)
|
||||
prot |= PROT_READ;
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_MAP_WRITE)
|
||||
prot |= PROT_WRITE;
|
||||
|
||||
mem->ptr = mmap (NULL, size, prot, MAP_SHARED, mem->fd, 0);
|
||||
} else {
|
||||
mem->ptr = NULL;
|
||||
}
|
||||
} else {
|
||||
mem->ptr = g_malloc (size);
|
||||
mem->fd = -1;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
pinos_memblock_free (PinosMemblock *mem)
|
||||
{
|
||||
g_return_if_fail (mem != NULL);
|
||||
|
||||
if (mem->flags & PINOS_MEMBLOCK_FLAG_WITH_FD) {
|
||||
if (mem->ptr)
|
||||
munmap (mem->ptr, mem->size);
|
||||
if (mem->fd != -1)
|
||||
close (mem->fd);
|
||||
} else {
|
||||
g_free (mem->ptr);
|
||||
}
|
||||
mem->ptr = NULL;
|
||||
mem->fd = -1;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue