mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
remove module-jack
It's better to make a replacement client library
This commit is contained in:
parent
20e0d8b4ea
commit
5f92c152e3
12 changed files with 0 additions and 5770 deletions
|
|
@ -102,20 +102,6 @@ pipewire_module_audio_dsp = shared_library('pipewire-module-audio-dsp',
|
|||
dependencies : [mathlib, dl_lib, rt_lib, pipewire_dep],
|
||||
)
|
||||
|
||||
if jack_dep.found()
|
||||
pipewire_module_jack = shared_library('pipewire-module-jack',
|
||||
[ 'module-jack.c',
|
||||
'module-jack/shm.c',
|
||||
'module-jack/jack-node.c' ],
|
||||
c_args : pipewire_module_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
link_with : spalib,
|
||||
install : true,
|
||||
install_dir : modules_install_dir,
|
||||
dependencies : [jack_dep, mathlib, dl_lib, rt_lib, pipewire_dep],
|
||||
)
|
||||
endif
|
||||
|
||||
pipewire_module_suspend_on_idle = shared_library('pipewire-module-suspend-on-idle', [ 'module-suspend-on-idle.c' ],
|
||||
c_args : pipewire_module_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,144 +0,0 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2017 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 "pipewire/log.h"
|
||||
|
||||
#define USE_POSIX_SHM
|
||||
#undef JACK_MONITOR
|
||||
|
||||
#define JACK_DEFAULT_SERVER_NAME "default"
|
||||
#define JACK_SOCKET_DIR "/dev/shm"
|
||||
#define JACK_SHM_DIR "/dev/shm"
|
||||
#define JACK_SERVER_NAME_SIZE 256
|
||||
#define JACK_CLIENT_NAME_SIZE 64
|
||||
#define JACK_PORT_NAME_SIZE 256
|
||||
#define JACK_PORT_TYPE_SIZE 32
|
||||
#define JACK_PROTOCOL_VERSION 8
|
||||
#define JACK_MESSAGE_SIZE 256
|
||||
|
||||
#define PORT_NUM_MAX 4096
|
||||
#define PORT_NUM_FOR_CLIENT 2048
|
||||
#define CONNECTION_NUM_FOR_PORT PORT_NUM_FOR_CLIENT
|
||||
|
||||
#define REAL_JACK_PORT_NAME_SIZE JACK_CLIENT_NAME_SIZE + JACK_PORT_NAME_SIZE
|
||||
|
||||
#define BUFFER_SIZE_MAX 8192
|
||||
|
||||
#define CLIENT_NUM 256
|
||||
|
||||
#define JACK_ENGINE_ROLLING_COUNT 32
|
||||
#define JACK_ENGINE_ROLLING_INTERVAL 1024
|
||||
|
||||
#define TIME_POINTS 100000
|
||||
#define FAILURE_TIME_POINTS 10000
|
||||
#define FAILURE_WINDOW 10
|
||||
#define MEASURED_CLIENTS 32
|
||||
|
||||
#define SYNC_MAX_NAME_SIZE 256
|
||||
|
||||
#define JACK_UUID_SIZE 36
|
||||
#define JACK_UUID_STRING_SIZE (JACK_UUID_SIZE+1)
|
||||
|
||||
#define JACK_SESSION_COMMAND_SIZE 256
|
||||
|
||||
#define NO_PORT 0xFFFE
|
||||
#define EMPTY 0xFFFD
|
||||
#define FREE 0xFFFC
|
||||
|
||||
typedef enum {
|
||||
JACK_TIMER_SYSTEM_CLOCK,
|
||||
JACK_TIMER_HPET,
|
||||
} jack_timer_type_t;
|
||||
|
||||
enum jack_request_type {
|
||||
jack_request_RegisterPort = 1,
|
||||
jack_request_UnRegisterPort = 2,
|
||||
jack_request_ConnectPorts = 3,
|
||||
jack_request_DisconnectPorts = 4,
|
||||
jack_request_SetTimeBaseClient = 5,
|
||||
jack_request_ActivateClient = 6,
|
||||
jack_request_DeactivateClient = 7,
|
||||
jack_request_DisconnectPort = 8,
|
||||
jack_request_SetClientCapabilities = 9,
|
||||
jack_request_GetPortConnections = 10,
|
||||
jack_request_GetPortNConnections = 11,
|
||||
jack_request_ReleaseTimebase = 12,
|
||||
jack_request_SetTimebaseCallback = 13,
|
||||
jack_request_SetBufferSize = 20,
|
||||
jack_request_SetFreeWheel = 21,
|
||||
jack_request_ClientCheck = 22,
|
||||
jack_request_ClientOpen = 23,
|
||||
jack_request_ClientClose = 24,
|
||||
jack_request_ConnectNamePorts = 25,
|
||||
jack_request_DisconnectNamePorts = 26,
|
||||
jack_request_GetInternalClientName = 27,
|
||||
jack_request_InternalClientHandle = 28,
|
||||
jack_request_InternalClientLoad = 29,
|
||||
jack_request_InternalClientUnload = 30,
|
||||
jack_request_PortRename = 31,
|
||||
jack_request_Notification = 32,
|
||||
jack_request_SessionNotify = 33,
|
||||
jack_request_SessionReply = 34,
|
||||
jack_request_GetClientByUUID = 35,
|
||||
jack_request_ReserveClientName = 36,
|
||||
jack_request_GetUUIDByClient = 37,
|
||||
jack_request_ClientHasSessionCallback = 38,
|
||||
jack_request_ComputeTotalLatencies = 39
|
||||
};
|
||||
|
||||
enum jack_notification_type {
|
||||
jack_notify_AddClient = 0,
|
||||
jack_notify_RemoveClient = 1,
|
||||
jack_notify_ActivateClient = 2,
|
||||
jack_notify_XRunCallback = 3,
|
||||
jack_notify_GraphOrderCallback = 4,
|
||||
jack_notify_BufferSizeCallback = 5,
|
||||
jack_notify_SampleRateCallback = 6,
|
||||
jack_notify_StartFreewheelCallback = 7,
|
||||
jack_notify_StopFreewheelCallback = 8,
|
||||
jack_notify_PortRegistrationOnCallback = 9,
|
||||
jack_notify_PortRegistrationOffCallback = 10,
|
||||
jack_notify_PortConnectCallback = 11,
|
||||
jack_notify_PortDisconnectCallback = 12,
|
||||
jack_notify_PortRenameCallback = 13,
|
||||
jack_notify_RealTimeCallback = 14,
|
||||
jack_notify_ShutDownCallback = 15,
|
||||
jack_notify_QUIT = 16,
|
||||
jack_notify_SessionCallback = 17,
|
||||
jack_notify_LatencyCallback = 18,
|
||||
jack_notify_max = 64 // To keep some room in JackClientControl fCallback table
|
||||
};
|
||||
|
||||
#define kActivateClient_size (2*sizeof(int))
|
||||
#define kDeactivateClient_size (sizeof(int))
|
||||
#define kSetTimebaseCallback_size (sizeof(int) + sizeof(int))
|
||||
#define kRegisterPort_size (sizeof(int) + JACK_PORT_NAME_SIZE+1 + JACK_PORT_TYPE_SIZE+1 + 2*sizeof(unsigned int))
|
||||
#define kClientCheck_size (JACK_CLIENT_NAME_SIZE+1 + 4 * sizeof(int))
|
||||
#define kClientOpen_size (JACK_CLIENT_NAME_SIZE+1 + 2 * sizeof(int))
|
||||
#define kClientClose_size (sizeof(int))
|
||||
#define kConnectNamePorts_size (sizeof(int) + REAL_JACK_PORT_NAME_SIZE+1 + REAL_JACK_PORT_NAME_SIZE+1)
|
||||
#define kDisconnectNamePorts_size (sizeof(int) + REAL_JACK_PORT_NAME_SIZE+1 + REAL_JACK_PORT_NAME_SIZE+1)
|
||||
#define kGetUUIDByClient_size (JACK_CLIENT_NAME_SIZE+1)
|
||||
|
||||
#define CheckRead(var,size) if(read(client->fd,var,size)!=size) {pw_log_error("read error"); return -1; }
|
||||
#define CheckWrite(var,size) if(send(client->fd,var,size,MSG_NOSIGNAL)!=size) {pw_log_error("write error"); return -1; }
|
||||
#define CheckSize(expected) { int __size; CheckRead(&__size, sizeof(int)); if (__size != expected) { pw_log_error("CheckSize error size %d != %d", __size, (int)expected); return -1; } }
|
||||
|
||||
#define jack_error pw_log_error
|
||||
#define jack_log pw_log_info
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,134 +0,0 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 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 __PIPEWIRE_JACK_NODE_H__
|
||||
#define __PIPEWIRE_JACK_NODE_H__
|
||||
|
||||
#include <pipewire/node.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct pw_jack_port;
|
||||
|
||||
struct pw_jack_node {
|
||||
struct pw_node *node;
|
||||
|
||||
struct pw_core *core;
|
||||
struct jack_server *server;
|
||||
|
||||
struct jack_client_control *control;
|
||||
|
||||
struct pw_jack_port *driver_out;
|
||||
struct pw_jack_port *driver_in;
|
||||
|
||||
struct spa_list graph_link;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
struct pw_jack_node_events {
|
||||
#define PW_VERSION_JACK_NODE_EVENTS 0
|
||||
uint32_t version;
|
||||
|
||||
void (*destroy) (void *data);
|
||||
|
||||
void (*free) (void *data);
|
||||
|
||||
/** the state of the node changed */
|
||||
void (*state_changed) (void *data, enum pw_node_state old,
|
||||
enum pw_node_state state, const char *error);
|
||||
|
||||
void (*pull) (void *data);
|
||||
|
||||
void (*push) (void *data);
|
||||
};
|
||||
|
||||
struct pw_jack_port {
|
||||
struct pw_jack_node *node;
|
||||
|
||||
enum pw_direction direction;
|
||||
struct pw_port *port;
|
||||
|
||||
jack_port_id_t port_id;
|
||||
struct jack_port *jack_port;
|
||||
float *ptr;
|
||||
|
||||
void *user_data;
|
||||
};
|
||||
|
||||
struct pw_jack_port_events {
|
||||
#define PW_VERSION_JACK_PORT_EVENTS 0
|
||||
uint32_t version;
|
||||
|
||||
void (*destroy) (void *data);
|
||||
|
||||
void (*free) (void *data);
|
||||
};
|
||||
|
||||
struct pw_jack_node *
|
||||
pw_jack_node_new(struct pw_core *core,
|
||||
struct pw_global *parent,
|
||||
struct jack_server *server,
|
||||
const char *name,
|
||||
int pid,
|
||||
struct pw_properties *properties,
|
||||
size_t user_data_size);
|
||||
|
||||
struct pw_jack_node *
|
||||
pw_jack_driver_new(struct pw_core *core,
|
||||
struct pw_global *parent,
|
||||
struct jack_server *server,
|
||||
const char *name,
|
||||
int n_capture_channels,
|
||||
int n_playback_channels,
|
||||
struct pw_properties *properties,
|
||||
size_t user_data_size);
|
||||
|
||||
void
|
||||
pw_jack_node_destroy(struct pw_jack_node *node);
|
||||
|
||||
void pw_jack_node_add_listener(struct pw_jack_node *node,
|
||||
struct spa_hook *listener,
|
||||
const struct pw_jack_node_events *events,
|
||||
void *data);
|
||||
|
||||
struct pw_jack_port *
|
||||
pw_jack_node_add_port(struct pw_jack_node *node,
|
||||
const char *name,
|
||||
const char *type,
|
||||
unsigned int flags,
|
||||
size_t user_data_size);
|
||||
|
||||
void pw_jack_port_add_listener(struct pw_jack_port *port,
|
||||
struct spa_hook *listener,
|
||||
const struct pw_jack_port_events *events,
|
||||
void *data);
|
||||
|
||||
struct pw_jack_port *
|
||||
pw_jack_node_find_port(struct pw_jack_node *node,
|
||||
enum pw_direction direction,
|
||||
jack_port_id_t port_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PIPEWIRE_JACK_NODE_H__ */
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 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 <jack/jack.h>
|
||||
#include <jack/session.h>
|
||||
|
||||
#include "modules/module-jack/defs.h"
|
||||
#include "modules/module-jack/synchro.h"
|
||||
#include "modules/module-jack/shm.h"
|
||||
#include "modules/module-jack/shared.h"
|
||||
#include "modules/module-jack/port.h"
|
||||
#include "modules/module-jack/server.h"
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2017 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.
|
||||
*/
|
||||
|
||||
static inline jack_port_type_id_t
|
||||
jack_port_get_type_id(const char *type)
|
||||
{
|
||||
if (strcmp(type, JACK_DEFAULT_AUDIO_TYPE) == 0)
|
||||
return 0;
|
||||
else if (strcmp(type, JACK_DEFAULT_MIDI_TYPE) == 0)
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
|
@ -1,67 +0,0 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2017 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.
|
||||
*/
|
||||
|
||||
struct jack_server;
|
||||
|
||||
struct jack_client {
|
||||
struct spa_list link;
|
||||
void *data;
|
||||
struct client *owner;
|
||||
struct pw_jack_node *node;
|
||||
int fd; /* notify fd */
|
||||
struct spa_hook node_listener;
|
||||
struct spa_list client_link;
|
||||
bool activated;
|
||||
bool realtime;
|
||||
};
|
||||
|
||||
struct jack_server {
|
||||
pthread_mutex_t lock;
|
||||
|
||||
bool promiscuous;
|
||||
|
||||
struct jack_graph_manager *graph_manager;
|
||||
struct jack_engine_control *engine_control;
|
||||
|
||||
struct jack_client* client_table[CLIENT_NUM];
|
||||
struct jack_synchro synchro_table[CLIENT_NUM];
|
||||
|
||||
int audio_ref_num;
|
||||
int freewheel_ref_num;
|
||||
|
||||
struct pw_jack_node *audio_node;
|
||||
int audio_used;
|
||||
};
|
||||
|
||||
static inline int
|
||||
jack_server_allocate_ref_num(struct jack_server *server)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < CLIENT_NUM; i++)
|
||||
if (server->client_table[i] == NULL)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static inline void
|
||||
jack_server_free_ref_num(struct jack_server *server, int ref_num)
|
||||
{
|
||||
server->client_table[ref_num] = NULL;
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,216 +0,0 @@
|
|||
/* This module provides a set of abstract shared memory interfaces
|
||||
* with support using both System V and POSIX shared memory
|
||||
* implementations. The code is divided into three sections:
|
||||
*
|
||||
* - common (interface-independent) code
|
||||
* - POSIX implementation
|
||||
* - System V implementation
|
||||
* - Windows implementation
|
||||
*
|
||||
* The implementation used is determined by whether USE_POSIX_SHM was
|
||||
* set in the ./configure step.
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 2001-2003 Paul Davis
|
||||
Copyright (C) 2005-2012 Grame
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef __jack_shm_h__
|
||||
#define __jack_shm_h__
|
||||
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <jack/types.h>
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define MAX_SERVERS 8 /* maximum concurrent servers */
|
||||
#define MAX_SHM_ID 256 /* generally about 16 per server */
|
||||
#define JACK_SHM_MAGIC 0x4a41434b /* shm magic number: "JACK" */
|
||||
#define JACK_SHM_NULL_INDEX -1 /* NULL SHM index */
|
||||
#define JACK_SHM_REGISTRY_INDEX -2 /* pseudo SHM index for registry */
|
||||
|
||||
|
||||
/* On Mac OS X, SHM_NAME_MAX is the maximum length of a shared memory
|
||||
* segment name (instead of NAME_MAX or PATH_MAX as defined by the
|
||||
* standard).
|
||||
*/
|
||||
#ifdef USE_POSIX_SHM
|
||||
|
||||
#ifndef NAME_MAX
|
||||
#define NAME_MAX 255
|
||||
#endif
|
||||
|
||||
#ifndef SHM_NAME_MAX
|
||||
#define SHM_NAME_MAX NAME_MAX
|
||||
#endif
|
||||
typedef char shm_name_t[SHM_NAME_MAX];
|
||||
typedef shm_name_t jack_shm_id_t;
|
||||
|
||||
#elif WIN32
|
||||
#define NAME_MAX 255
|
||||
#ifndef SHM_NAME_MAX
|
||||
#define SHM_NAME_MAX NAME_MAX
|
||||
#endif
|
||||
typedef char shm_name_t[SHM_NAME_MAX];
|
||||
typedef shm_name_t jack_shm_id_t;
|
||||
|
||||
#elif __ANDROID__
|
||||
|
||||
#ifndef NAME_MAX
|
||||
#define NAME_MAX 255
|
||||
#endif
|
||||
|
||||
#ifndef SHM_NAME_MAX
|
||||
#define SHM_NAME_MAX NAME_MAX
|
||||
#endif
|
||||
typedef char shm_name_t[SHM_NAME_MAX];
|
||||
typedef shm_name_t jack_shm_id_t;
|
||||
typedef int jack_shm_fd_t;
|
||||
|
||||
#else
|
||||
/* System V SHM */
|
||||
typedef int jack_shm_id_t;
|
||||
#endif /* SHM type */
|
||||
|
||||
/* shared memory type */
|
||||
typedef enum {
|
||||
shm_POSIX = 1, /* POSIX shared memory */
|
||||
shm_SYSV = 2, /* System V shared memory */
|
||||
shm_WIN32 = 3, /* Windows 32 shared memory */
|
||||
shm_ANDROID = 4 /* Android shared memory */
|
||||
} jack_shmtype_t;
|
||||
|
||||
typedef int16_t jack_shm_registry_index_t;
|
||||
|
||||
/**
|
||||
* A structure holding information about shared memory allocated by
|
||||
* JACK. this persists across invocations of JACK, and can be used by
|
||||
* multiple JACK servers. It contains no pointers and is valid across
|
||||
* address spaces.
|
||||
*
|
||||
* The registry consists of two parts: a header including an array of
|
||||
* server names, followed by an array of segment registry entries.
|
||||
*/
|
||||
typedef struct _jack_shm_server {
|
||||
#ifdef WIN32
|
||||
int pid; /* process ID */
|
||||
#else
|
||||
pid_t pid; /* process ID */
|
||||
#endif
|
||||
|
||||
char name[JACK_SERVER_NAME_SIZE];
|
||||
}
|
||||
jack_shm_server_t;
|
||||
|
||||
typedef struct _jack_shm_header {
|
||||
uint32_t magic; /* magic number */
|
||||
uint16_t protocol; /* JACK protocol version */
|
||||
jack_shmtype_t type; /* shm type */
|
||||
jack_shmsize_t size; /* total registry segment size */
|
||||
jack_shmsize_t hdr_len; /* size of header */
|
||||
jack_shmsize_t entry_len; /* size of registry entry */
|
||||
jack_shm_server_t server[MAX_SERVERS]; /* current server array */
|
||||
}
|
||||
jack_shm_header_t;
|
||||
|
||||
typedef struct _jack_shm_registry {
|
||||
jack_shm_registry_index_t index; /* offset into the registry */
|
||||
|
||||
#ifdef WIN32
|
||||
int allocator; /* PID that created shm segment */
|
||||
#else
|
||||
pid_t allocator; /* PID that created shm segment */
|
||||
#endif
|
||||
|
||||
jack_shmsize_t size; /* for POSIX unattach */
|
||||
jack_shm_id_t id; /* API specific, see above */
|
||||
#ifdef __ANDROID__
|
||||
jack_shm_fd_t fd;
|
||||
#endif
|
||||
}
|
||||
jack_shm_registry_t;
|
||||
|
||||
#define JACK_SHM_REGISTRY_SIZE (sizeof (jack_shm_header_t) \
|
||||
+ sizeof (jack_shm_registry_t) * MAX_SHM_ID)
|
||||
|
||||
/**
|
||||
* a structure holding information about shared memory
|
||||
* allocated by JACK. this version is valid only
|
||||
* for a given address space. It contains a pointer
|
||||
* indicating where the shared memory has been
|
||||
* attached to the address space.
|
||||
*/
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct _jack_shm_info {
|
||||
jack_shm_registry_index_t index; /* offset into the registry */
|
||||
uint32_t size;
|
||||
#ifdef __ANDROID__
|
||||
jack_shm_fd_t fd;
|
||||
#endif
|
||||
union {
|
||||
void *attached_at; /* address where attached */
|
||||
char ptr_size[8];
|
||||
} ptr; /* a "pointer" that has the same 8 bytes size when compling in 32 or 64 bits */
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
typedef struct _jack_shm_info jack_shm_info_t;
|
||||
|
||||
/* utility functions used only within JACK */
|
||||
|
||||
void jack_shm_copy_from_registry (jack_shm_info_t*,
|
||||
jack_shm_registry_index_t);
|
||||
void jack_shm_copy_to_registry (jack_shm_info_t*,
|
||||
jack_shm_registry_index_t*);
|
||||
int jack_release_shm_info (jack_shm_registry_index_t);
|
||||
char* jack_shm_addr (jack_shm_info_t* si);
|
||||
|
||||
// here begin the API
|
||||
int jack_register_server (const char *server_name, int new_registry);
|
||||
int jack_unregister_server (const char *server_name);
|
||||
|
||||
int jack_initialize_shm (const char *server_name);
|
||||
int jack_initialize_shm_server (void);
|
||||
int jack_initialize_shm_client (void);
|
||||
int jack_cleanup_shm (void);
|
||||
|
||||
int jack_shmalloc (const char *shm_name, jack_shmsize_t size,
|
||||
jack_shm_info_t* result);
|
||||
void jack_release_shm (jack_shm_info_t*);
|
||||
void jack_release_lib_shm (jack_shm_info_t*);
|
||||
void jack_destroy_shm (jack_shm_info_t*);
|
||||
int jack_attach_shm (jack_shm_info_t*);
|
||||
int jack_attach_lib_shm (jack_shm_info_t*);
|
||||
int jack_attach_shm_read (jack_shm_info_t*);
|
||||
int jack_attach_lib_shm_read (jack_shm_info_t*);
|
||||
int jack_resize_shm (jack_shm_info_t*, jack_shmsize_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __jack_shm_h__ */
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2017 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 <semaphore.h>
|
||||
|
||||
struct jack_synchro {
|
||||
char name[SYNC_MAX_NAME_SIZE];
|
||||
bool flush;
|
||||
sem_t *semaphore;
|
||||
};
|
||||
|
||||
#define JACK_SYNCHRO_INIT (struct jack_synchro) { { 0, }, false, NULL }
|
||||
|
||||
static inline int
|
||||
jack_synchro_init(struct jack_synchro *synchro,
|
||||
const char *client_name,
|
||||
const char *server_name,
|
||||
int value,
|
||||
bool promiscuous)
|
||||
{
|
||||
char cname[SYNC_MAX_NAME_SIZE+1];
|
||||
int i;
|
||||
for (i = 0; client_name[i] != '\0'; i++) {
|
||||
if (client_name[i] == '/' || client_name[i] == '\\')
|
||||
cname[i] = '_';
|
||||
else
|
||||
cname[i] = client_name[i];
|
||||
}
|
||||
cname[i] = client_name[i];
|
||||
|
||||
if (promiscuous)
|
||||
snprintf(synchro->name, sizeof(synchro->name),
|
||||
"jack_sem.%s_%s", server_name, cname);
|
||||
else
|
||||
snprintf(synchro->name, sizeof(synchro->name),
|
||||
"jack_sem.%d_%s_%s", getuid(), server_name, cname);
|
||||
|
||||
synchro->flush = false;
|
||||
if ((synchro->semaphore = sem_open(synchro->name, O_CREAT | O_RDWR, 0777, value)) == (sem_t*)SEM_FAILED) {
|
||||
pw_log_error("can't check semaphore %s: %s", synchro->name, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
jack_synchro_close(struct jack_synchro *synchro)
|
||||
{
|
||||
if (synchro->semaphore == NULL)
|
||||
return true;
|
||||
|
||||
if (sem_close(synchro->semaphore) < 0) {
|
||||
pw_log_warn("can't close semaphore %s: %s", synchro->name, strerror(errno));
|
||||
}
|
||||
synchro->semaphore = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
jack_synchro_signal(struct jack_synchro *synchro)
|
||||
{
|
||||
int res;
|
||||
if (synchro->flush)
|
||||
return true;
|
||||
if ((res = sem_post(synchro->semaphore)) < 0)
|
||||
pw_log_error("semaphore %s post err = %s", synchro->name, strerror(errno));
|
||||
|
||||
return res == 0;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
jack_synchro_wait(struct jack_synchro *synchro)
|
||||
{
|
||||
int res;
|
||||
while ((res = sem_wait(synchro->semaphore)) < 0) {
|
||||
if (errno != EINTR)
|
||||
continue;
|
||||
|
||||
pw_log_error("semaphore %s wait err = %s", synchro->name, strerror(errno));
|
||||
break;
|
||||
}
|
||||
return res == 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue