mirror of
https://gitlab.freedesktop.org/pipewire/pipewire
synced 2024-10-01 13:44:40 +00:00
Add beginnings of jack module
Update spec and makefile a bit
This commit is contained in:
parent
bc56c59597
commit
2c6b2f0b74
25
Makefile
25
Makefile
|
@ -1,25 +0,0 @@
|
|||
all:
|
||||
ninja-build -C build
|
||||
|
||||
install:
|
||||
ninja-build -C build install
|
||||
|
||||
clean:
|
||||
ninja-build -C build clean
|
||||
|
||||
run:
|
||||
SPA_PLUGIN_DIR=build/spa/plugins \
|
||||
PIPEWIRE_MODULE_DIR=build \
|
||||
PIPEWIRE_CONFIG_FILE=build/pipewire/daemon/pipewire.conf \
|
||||
build/pipewire/daemon/pipewire
|
||||
|
||||
monitor:
|
||||
SPA_PLUGIN_DIR=build/spa/plugins \
|
||||
PIPEWIRE_MODULE_DIR=build/pipewire/modules/ \
|
||||
build/pipewire/tools/pipewire-monitor
|
||||
|
||||
dist:
|
||||
git archive --prefix=pipewire-0.1.0/ -o pipewire-0.1.0.tar.gz HEAD
|
||||
|
||||
rpm: dist
|
||||
rpmbuild -ta pipewire-0.1.0.tar.gz
|
|
@ -20,3 +20,4 @@
|
|||
rm -rf ./build
|
||||
mkdir build
|
||||
meson build $@
|
||||
ln -s build/Makefile Makefile
|
||||
|
|
12
meson.build
12
meson.build
|
@ -122,6 +122,18 @@ configure_file(input : 'config.h.meson',
|
|||
|
||||
configinc = include_directories('.')
|
||||
|
||||
makedata = configuration_data()
|
||||
makedata.set('VERSION', pipewire_version)
|
||||
if version_arr.length() == 4
|
||||
makedata.set('TAG', 'HEAD')
|
||||
else
|
||||
makedata.set('TAG', pipewire_version)
|
||||
endif
|
||||
|
||||
configure_file(input : 'Makefile.in',
|
||||
output : 'Makefile',
|
||||
configuration : makedata)
|
||||
|
||||
# Find dependencies
|
||||
glib_dep = dependency('glib-2.0', version : '>=2.32.0')
|
||||
gobject_dep = dependency('gobject-2.0')
|
||||
|
|
|
@ -31,6 +31,7 @@ Source0: http://freedesktop.org/software/pipewire/releases/pipewire-%{ver
|
|||
|
||||
BuildRequires: meson >= 0.35.0
|
||||
BuildRequires: pkgconfig
|
||||
BuildRequires: pkgconfig(dbus-1)
|
||||
BuildRequires: pkgconfig(glib-2.0) >= 2.32
|
||||
BuildRequires: pkgconfig(gio-unix-2.0) >= 2.32
|
||||
BuildRequires: pkgconfig(gstreamer-1.0) >= 1.10.0
|
||||
|
@ -57,11 +58,11 @@ License: LGPLv2+
|
|||
This package contains the runtime libraries for any application that wishes
|
||||
to interface with a PipeWire media server.
|
||||
|
||||
%package libs-devel
|
||||
%package devel
|
||||
Summary: Headers and libraries for PipeWire client development
|
||||
License: LGPLv2+
|
||||
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
|
||||
%description libs-devel
|
||||
%description devel
|
||||
Headers and libraries for developing applications that can communicate with
|
||||
a PipeWire media server.
|
||||
|
||||
|
|
|
@ -8,3 +8,4 @@ load-module libpipewire-module-autolink
|
|||
#load-module libpipewire-module-mixer
|
||||
load-module libpipewire-module-client-node
|
||||
load-module libpipewire-module-flatpak
|
||||
#load-module libpipewire-module-jack
|
||||
|
|
|
@ -66,6 +66,17 @@ pipewire_module_protocol_native = shared_library('pipewire-module-protocol-nativ
|
|||
dependencies : [mathlib, dl_lib, pipewire_dep, pipewirecore_dep],
|
||||
)
|
||||
|
||||
pipewire_module_jack = shared_library('pipewire-module-jack',
|
||||
[ 'module-jack.c',
|
||||
'module-jack/shm.c' ],
|
||||
c_args : pipewire_module_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
link_with : spalib,
|
||||
install : true,
|
||||
install_dir : modules_install_dir,
|
||||
dependencies : [mathlib, dl_lib, rt_lib, pipewire_dep, pipewirecore_dep],
|
||||
)
|
||||
|
||||
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],
|
||||
|
|
701
pipewire/modules/module-jack.c
Normal file
701
pipewire/modules/module-jack.c
Normal file
|
@ -0,0 +1,701 @@
|
|||
/* 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 <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/mman.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <jack/jack.h>
|
||||
#include <jack/session.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "pipewire/client/pipewire.h"
|
||||
#include "pipewire/client/log.h"
|
||||
#include "pipewire/client/interfaces.h"
|
||||
|
||||
#include "pipewire/server/core.h"
|
||||
#include "pipewire/server/node.h"
|
||||
#include "pipewire/server/module.h"
|
||||
#include "pipewire/server/client.h"
|
||||
#include "pipewire/server/resource.h"
|
||||
#include "pipewire/server/link.h"
|
||||
#include "pipewire/server/node-factory.h"
|
||||
#include "pipewire/server/data-loop.h"
|
||||
#include "pipewire/server/main-loop.h"
|
||||
|
||||
#include "pipewire/modules/module-jack/defs.h"
|
||||
#include "pipewire/modules/module-jack/shm.h"
|
||||
#include "pipewire/modules/module-jack/shared.h"
|
||||
#include "pipewire/modules/module-jack/synchro.h"
|
||||
#include "pipewire/modules/module-jack/server.h"
|
||||
|
||||
#ifndef UNIX_PATH_MAX
|
||||
#define UNIX_PATH_MAX 108
|
||||
#endif
|
||||
|
||||
#define LOCK_SUFFIX ".lock"
|
||||
#define LOCK_SUFFIXLEN 5
|
||||
|
||||
static int segment_num = 0;
|
||||
|
||||
typedef bool(*demarshal_func_t) (void *object, void *data, size_t size);
|
||||
|
||||
struct socket {
|
||||
int fd;
|
||||
struct sockaddr_un addr;
|
||||
char lock_addr[UNIX_PATH_MAX + LOCK_SUFFIXLEN];
|
||||
|
||||
struct pw_loop *loop;
|
||||
struct spa_source *source;
|
||||
char *core_name;
|
||||
struct spa_list link;
|
||||
};
|
||||
|
||||
struct impl {
|
||||
struct pw_core *core;
|
||||
struct spa_list link;
|
||||
|
||||
struct pw_properties *properties;
|
||||
|
||||
struct spa_list socket_list;
|
||||
struct spa_list client_list;
|
||||
|
||||
struct spa_loop_control_hooks hooks;
|
||||
|
||||
struct jack_server server;
|
||||
};
|
||||
|
||||
struct client {
|
||||
struct impl *impl;
|
||||
struct spa_list link;
|
||||
struct pw_client *client;
|
||||
int fd;
|
||||
struct spa_source *source;
|
||||
struct pw_listener busy_changed;
|
||||
};
|
||||
|
||||
static int process_messages(struct client *client);
|
||||
|
||||
static void client_destroy(void *data)
|
||||
{
|
||||
struct pw_client *client = data;
|
||||
struct client *this = client->user_data;
|
||||
|
||||
pw_loop_destroy_source(this->impl->core->main_loop->loop, this->source);
|
||||
spa_list_remove(&this->link);
|
||||
|
||||
close(this->fd);
|
||||
}
|
||||
|
||||
static int
|
||||
handle_register_port(struct client *client)
|
||||
{
|
||||
int result = 0;
|
||||
int ref_num;
|
||||
char name[JACK_PORT_NAME_SIZE + 1];
|
||||
char port_type[JACK_PORT_TYPE_SIZE + 1];
|
||||
unsigned int flags;
|
||||
unsigned int buffer_size;
|
||||
static jack_port_id_t port_index = 0;
|
||||
|
||||
CheckSize(kRegisterPort_size);
|
||||
CheckRead(&ref_num, sizeof(int));
|
||||
CheckRead(name, sizeof(name));
|
||||
CheckRead(port_type, sizeof(port_type));
|
||||
CheckRead(&flags, sizeof(unsigned int));
|
||||
CheckRead(&buffer_size, sizeof(unsigned int));
|
||||
|
||||
pw_log_error("protocol-jack %p: kRegisterPort %d %s %s %u %u", client->impl,
|
||||
ref_num, name, port_type, flags, buffer_size);
|
||||
port_index++;
|
||||
|
||||
CheckWrite(&result, sizeof(int));
|
||||
CheckWrite(&port_index, sizeof(jack_port_id_t));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_activate_client(struct client *client)
|
||||
{
|
||||
int result = 0;
|
||||
int ref_num;
|
||||
int is_real_time;
|
||||
|
||||
CheckSize(kActivateClient_size);
|
||||
CheckRead(&ref_num, sizeof(int));
|
||||
CheckRead(&is_real_time, sizeof(int));
|
||||
|
||||
pw_log_error("protocol-jack %p: kActivateClient %d %d", client->impl,
|
||||
ref_num, is_real_time);
|
||||
|
||||
CheckWrite(&result, sizeof(int));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_deactivate_client(struct client *client)
|
||||
{
|
||||
int result = 0;
|
||||
int ref_num;
|
||||
|
||||
CheckSize(kDeactivateClient_size);
|
||||
CheckRead(&ref_num, sizeof(int));
|
||||
|
||||
pw_log_error("protocol-jack %p: kDeactivateClient %d", client->impl,
|
||||
ref_num);
|
||||
|
||||
CheckWrite(&result, sizeof(int));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_client_check(struct client *client)
|
||||
{
|
||||
char name[JACK_CLIENT_NAME_SIZE+1];
|
||||
int protocol;
|
||||
int options;
|
||||
int UUID;
|
||||
int open;
|
||||
int result = 0;
|
||||
int status;
|
||||
|
||||
CheckSize(kClientCheck_size);
|
||||
CheckRead(name, sizeof(name));
|
||||
CheckRead(&protocol, sizeof(int));
|
||||
CheckRead(&options, sizeof(int));
|
||||
CheckRead(&UUID, sizeof(int));
|
||||
CheckRead(&open, sizeof(int));
|
||||
|
||||
pw_log_error("protocol-jack %p: kClientCheck %s %d %d %d %d", client->impl,
|
||||
name, protocol, options, UUID, open);
|
||||
|
||||
status = 0;
|
||||
if (protocol != JACK_PROTOCOL_VERSION) {
|
||||
status |= (JackFailure | JackVersionError);
|
||||
pw_log_error("protocol-jack: protocol mismatch (%d vs %d)", protocol, JACK_PROTOCOL_VERSION);
|
||||
result = -1;
|
||||
goto reply;
|
||||
}
|
||||
/* TODO check client name and uuid */
|
||||
|
||||
reply:
|
||||
CheckWrite(&result, sizeof(int));
|
||||
CheckWrite(name, sizeof(name));
|
||||
CheckWrite(&status, sizeof(int));
|
||||
|
||||
if (open)
|
||||
return process_messages(client);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_client_open(struct client *client)
|
||||
{
|
||||
struct impl *impl = client->impl;
|
||||
struct jack_server *server = &impl->server;
|
||||
int PID, UUID;
|
||||
char name[JACK_CLIENT_NAME_SIZE+1];
|
||||
int result, ref_num, shared_engine, shared_client, shared_graph;
|
||||
struct jack_client *jc;
|
||||
size_t size;
|
||||
jack_shm_info_t info;
|
||||
|
||||
CheckSize(kClientOpen_size);
|
||||
CheckRead(&PID, sizeof(int));
|
||||
CheckRead(&UUID, sizeof(int));
|
||||
CheckRead(name, sizeof(name));
|
||||
|
||||
ref_num = jack_server_allocate_ref_num(server);
|
||||
if (ref_num == -1) {
|
||||
result = -1;
|
||||
goto reply;
|
||||
}
|
||||
|
||||
jc = calloc(1,sizeof(struct jack_client));
|
||||
jc->owner = client;
|
||||
jc->ref_num = ref_num;
|
||||
|
||||
if (jack_synchro_alloc(&server->synchro_table[ref_num],
|
||||
name,
|
||||
server->engine_control->server_name,
|
||||
0,
|
||||
false,
|
||||
server->promiscuous) < 0) {
|
||||
result = -1;
|
||||
goto reply;
|
||||
}
|
||||
|
||||
size = sizeof(struct jack_client_control);
|
||||
|
||||
if (jack_shm_alloc(size, &info, segment_num++) < 0) {
|
||||
result = -1;
|
||||
goto reply;
|
||||
}
|
||||
|
||||
jc->control = (struct jack_client_control *)jack_shm_addr(&info);
|
||||
jc->control->info = info;
|
||||
|
||||
server->client_table[ref_num] = jc;
|
||||
|
||||
result = 0;
|
||||
shared_engine = impl->server.engine_control->info.index;
|
||||
shared_client = jc->control->info.index;
|
||||
shared_graph = impl->server.graph_manager->info.index;
|
||||
|
||||
reply:
|
||||
CheckWrite(&result, sizeof(int));
|
||||
CheckWrite(&shared_engine, sizeof(int));
|
||||
CheckWrite(&shared_client, sizeof(int));
|
||||
CheckWrite(&shared_graph, sizeof(int));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_client_close(struct client *client)
|
||||
{
|
||||
int ref_num;
|
||||
CheckSize(kClientClose_size);
|
||||
CheckRead(&ref_num, sizeof(int));
|
||||
int result = 0;
|
||||
|
||||
CheckWrite(&result, sizeof(int));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_connect_name_ports(struct client *client)
|
||||
{
|
||||
int ref_num;
|
||||
char src[REAL_JACK_PORT_NAME_SIZE+1];
|
||||
char dst[REAL_JACK_PORT_NAME_SIZE+1];
|
||||
int result = 0;
|
||||
|
||||
CheckSize(kConnectNamePorts_size);
|
||||
CheckRead(&ref_num, sizeof(int));
|
||||
CheckRead(src, sizeof(src));
|
||||
CheckRead(dst, sizeof(dst));
|
||||
|
||||
CheckWrite(&result, sizeof(int));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
handle_get_UUID_by_client(struct client *client)
|
||||
{
|
||||
char name[JACK_CLIENT_NAME_SIZE+1];
|
||||
char UUID[JACK_UUID_SIZE];
|
||||
int result = 0;
|
||||
|
||||
CheckSize(kGetUUIDByClient_size);
|
||||
CheckRead(name, sizeof(name));
|
||||
|
||||
CheckWrite(&result, sizeof(int));
|
||||
CheckWrite(UUID, sizeof(UUID));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
process_messages(struct client *client)
|
||||
{
|
||||
struct pw_client *c = client->client;
|
||||
int type, res = -1;
|
||||
|
||||
if (read(client->fd, &type, sizeof(enum jack_request_type)) != sizeof(enum jack_request_type)) {
|
||||
pw_log_error("protocol-jack %p: failed to read type", client->impl);
|
||||
goto error;
|
||||
}
|
||||
pw_log_info("protocol-jack %p: got type %d", client->impl, type);
|
||||
|
||||
switch(type) {
|
||||
case jack_request_RegisterPort:
|
||||
res = handle_register_port(client);
|
||||
break;
|
||||
case jack_request_UnRegisterPort:
|
||||
case jack_request_ConnectPorts:
|
||||
case jack_request_DisconnectPorts:
|
||||
case jack_request_SetTimeBaseClient:
|
||||
case jack_request_ActivateClient:
|
||||
res = handle_activate_client(client);
|
||||
break;
|
||||
case jack_request_DeactivateClient:
|
||||
res = handle_deactivate_client(client);
|
||||
break;
|
||||
case jack_request_DisconnectPort:
|
||||
case jack_request_SetClientCapabilities:
|
||||
case jack_request_GetPortConnections:
|
||||
case jack_request_GetPortNConnections:
|
||||
case jack_request_ReleaseTimebase:
|
||||
case jack_request_SetTimebaseCallback:
|
||||
case jack_request_SetBufferSize:
|
||||
case jack_request_SetFreeWheel:
|
||||
break;
|
||||
case jack_request_ClientCheck:
|
||||
res = handle_client_check(client);
|
||||
break;
|
||||
case jack_request_ClientOpen:
|
||||
res = handle_client_open(client);
|
||||
break;
|
||||
case jack_request_ClientClose:
|
||||
res = handle_client_close(client);
|
||||
break;
|
||||
case jack_request_ConnectNamePorts:
|
||||
res = handle_connect_name_ports(client);
|
||||
break;
|
||||
case jack_request_DisconnectNamePorts:
|
||||
case jack_request_GetInternalClientName:
|
||||
case jack_request_InternalClientHandle:
|
||||
case jack_request_InternalClientLoad:
|
||||
case jack_request_InternalClientUnload:
|
||||
case jack_request_PortRename:
|
||||
case jack_request_Notification:
|
||||
case jack_request_SessionNotify:
|
||||
case jack_request_SessionReply:
|
||||
case jack_request_GetClientByUUID:
|
||||
case jack_request_ReserveClientName:
|
||||
break;
|
||||
case jack_request_GetUUIDByClient:
|
||||
res = handle_get_UUID_by_client(client);
|
||||
break;
|
||||
case jack_request_ClientHasSessionCallback:
|
||||
case jack_request_ComputeTotalLatencies:
|
||||
break;
|
||||
default:
|
||||
pw_log_error("protocol-jack %p: invalid type %d", client->impl, type);
|
||||
goto error;
|
||||
}
|
||||
if (res != 0)
|
||||
goto error;
|
||||
|
||||
return res;
|
||||
|
||||
error:
|
||||
pw_log_error("protocol-jack %p: error handling type %d", client->impl, type);
|
||||
pw_client_destroy(c);
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
on_busy_changed(struct pw_listener *listener,
|
||||
struct pw_client *client)
|
||||
{
|
||||
struct client *c = SPA_CONTAINER_OF(listener, struct client, busy_changed);
|
||||
enum spa_io mask = SPA_IO_ERR | SPA_IO_HUP;
|
||||
|
||||
if (!client->busy)
|
||||
mask |= SPA_IO_IN;
|
||||
|
||||
pw_loop_update_io(c->impl->core->main_loop->loop, c->source, mask);
|
||||
|
||||
if (!client->busy)
|
||||
process_messages(c);
|
||||
}
|
||||
|
||||
static void
|
||||
connection_data(struct spa_loop_utils *utils,
|
||||
struct spa_source *source, int fd, enum spa_io mask, void *data)
|
||||
{
|
||||
struct client *client = data;
|
||||
|
||||
if (mask & (SPA_IO_ERR | SPA_IO_HUP)) {
|
||||
pw_log_error("protocol-native %p: got connection error", client->impl);
|
||||
pw_client_destroy(client->client);
|
||||
return;
|
||||
}
|
||||
|
||||
if (mask & SPA_IO_IN)
|
||||
process_messages(client);
|
||||
}
|
||||
|
||||
static struct client *client_new(struct impl *impl, int fd)
|
||||
{
|
||||
struct client *this;
|
||||
struct pw_client *client;
|
||||
socklen_t len;
|
||||
struct ucred ucred, *ucredp;
|
||||
|
||||
len = sizeof(ucred);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) < 0) {
|
||||
pw_log_error("no peercred: %m");
|
||||
ucredp = NULL;
|
||||
} else {
|
||||
ucredp = &ucred;
|
||||
}
|
||||
|
||||
client = pw_client_new(impl->core, ucredp, NULL, sizeof(struct client));
|
||||
if (client == NULL)
|
||||
goto no_client;
|
||||
|
||||
client->destroy = client_destroy;
|
||||
|
||||
this = client->user_data;
|
||||
this->impl = impl;
|
||||
this->fd = fd;
|
||||
this->source = pw_loop_add_io(impl->core->main_loop->loop,
|
||||
this->fd,
|
||||
SPA_IO_ERR | SPA_IO_HUP, false, connection_data, this);
|
||||
if (this->source == NULL)
|
||||
goto no_source;
|
||||
|
||||
this->client = client;
|
||||
|
||||
spa_list_insert(impl->client_list.prev, &this->link);
|
||||
|
||||
pw_signal_add(&client->busy_changed, &this->busy_changed, on_busy_changed);
|
||||
|
||||
pw_log_error("module-jack %p: added new client", impl);
|
||||
|
||||
return this;
|
||||
|
||||
no_source:
|
||||
free(this);
|
||||
no_client:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct socket *create_socket(void)
|
||||
{
|
||||
struct socket *s;
|
||||
|
||||
if ((s = calloc(1, sizeof(struct socket))) == NULL)
|
||||
return NULL;
|
||||
|
||||
s->fd = -1;
|
||||
return s;
|
||||
}
|
||||
|
||||
static void destroy_socket(struct socket *s)
|
||||
{
|
||||
if (s->source)
|
||||
pw_loop_destroy_source(s->loop, s->source);
|
||||
if (s->addr.sun_path[0])
|
||||
unlink(s->addr.sun_path);
|
||||
if (s->fd >= 0)
|
||||
close(s->fd);
|
||||
if (s->lock_addr[0])
|
||||
unlink(s->lock_addr);
|
||||
free(s);
|
||||
}
|
||||
|
||||
static bool init_socket_name(struct socket *s, const char *name, bool promiscuous, int which)
|
||||
{
|
||||
int name_size;
|
||||
const char *runtime_dir;
|
||||
|
||||
runtime_dir = JACK_SOCKET_DIR;
|
||||
|
||||
s->addr.sun_family = AF_UNIX;
|
||||
if (promiscuous) {
|
||||
name_size = snprintf(s->addr.sun_path, sizeof(s->addr.sun_path),
|
||||
"%s/jack_%s_%d", runtime_dir, name, which) + 1;
|
||||
} else {
|
||||
name_size = snprintf(s->addr.sun_path, sizeof(s->addr.sun_path),
|
||||
"%s/jack_%s_%d_%d", runtime_dir, name, getuid(), which) + 1;
|
||||
}
|
||||
|
||||
s->core_name = (s->addr.sun_path + name_size - 1) - strlen(name);
|
||||
|
||||
if (name_size > (int) sizeof(s->addr.sun_path)) {
|
||||
pw_log_error("socket path \"%s/%s\" plus null terminator exceeds 108 bytes",
|
||||
runtime_dir, name);
|
||||
*s->addr.sun_path = 0;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
socket_data(struct spa_loop_utils *utils,
|
||||
struct spa_source *source, int fd, enum spa_io mask, void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
struct client *client;
|
||||
struct sockaddr_un name;
|
||||
socklen_t length;
|
||||
int client_fd;
|
||||
|
||||
length = sizeof(name);
|
||||
client_fd = accept4(fd, (struct sockaddr *) &name, &length, SOCK_CLOEXEC);
|
||||
if (client_fd < 0) {
|
||||
pw_log_error("failed to accept: %m");
|
||||
return;
|
||||
}
|
||||
|
||||
client = client_new(impl, client_fd);
|
||||
if (client == NULL) {
|
||||
pw_log_error("failed to create client");
|
||||
close(client_fd);
|
||||
return;
|
||||
}
|
||||
|
||||
pw_loop_update_io(impl->core->main_loop->loop,
|
||||
client->source, SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP);
|
||||
}
|
||||
|
||||
static bool add_socket(struct impl *impl, struct socket *s)
|
||||
{
|
||||
socklen_t size;
|
||||
|
||||
if ((s->fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0)) < 0)
|
||||
return false;
|
||||
|
||||
size = offsetof(struct sockaddr_un, sun_path) + strlen(s->addr.sun_path);
|
||||
if (bind(s->fd, (struct sockaddr *) &s->addr, size) < 0) {
|
||||
pw_log_error("bind() failed with error: %m");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (listen(s->fd, 100) < 0) {
|
||||
pw_log_error("listen() failed with error: %m");
|
||||
return false;
|
||||
}
|
||||
|
||||
s->loop = impl->core->main_loop->loop;
|
||||
s->source = pw_loop_add_io(s->loop, s->fd, SPA_IO_IN, false, socket_data, impl);
|
||||
if (s->source == NULL)
|
||||
return false;
|
||||
|
||||
spa_list_insert(impl->socket_list.prev, &s->link);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int init_server(struct impl *impl, const char *name, bool promiscuous)
|
||||
{
|
||||
struct jack_server *server = &impl->server;
|
||||
jack_shm_info_t info;
|
||||
size_t size;
|
||||
int i;
|
||||
struct socket *s;
|
||||
|
||||
pthread_mutex_init(&server->lock, NULL);
|
||||
|
||||
if (jack_register_server(name, 1) != 0)
|
||||
return -1;
|
||||
|
||||
jack_cleanup_shm();
|
||||
|
||||
/* graph manager */
|
||||
size = sizeof(struct jack_graph_manager) + 2048 * sizeof(struct jack_port);
|
||||
|
||||
if (jack_shm_alloc(size, &info, segment_num++) < 0)
|
||||
return -1;
|
||||
|
||||
server->graph_manager = (struct jack_graph_manager *)jack_shm_addr(&info);
|
||||
server->graph_manager->info = info;
|
||||
|
||||
/* engine control */
|
||||
size = sizeof(struct jack_engine_control);
|
||||
|
||||
if (jack_shm_alloc(size, &info, segment_num++) < 0)
|
||||
return -1;
|
||||
|
||||
server->engine_control = (struct jack_engine_control *)jack_shm_addr(&info);
|
||||
server->engine_control->info = info;
|
||||
|
||||
strcpy(server->engine_control->server_name, name);
|
||||
|
||||
for (i = 0; i < CLIENT_NUM; i++)
|
||||
server->synchro_table[i] = JACK_SYNCHRO_INIT;
|
||||
|
||||
s = create_socket();
|
||||
|
||||
if (!init_socket_name(s, name, promiscuous, 0))
|
||||
goto error;
|
||||
|
||||
if (!add_socket(impl, s))
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
destroy_socket(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
|
||||
{
|
||||
struct impl *impl;
|
||||
const char *name, *str;
|
||||
bool promiscuous;
|
||||
|
||||
impl = calloc(1, sizeof(struct impl));
|
||||
pw_log_debug("protocol-jack %p: new", impl);
|
||||
|
||||
impl->core = core;
|
||||
impl->properties = properties;
|
||||
|
||||
spa_list_init(&impl->socket_list);
|
||||
spa_list_init(&impl->client_list);
|
||||
|
||||
str = NULL;
|
||||
if (impl->properties)
|
||||
str = pw_properties_get(impl->properties, "jack.default.server");
|
||||
if (str == NULL)
|
||||
str = getenv("JACK_DEFAULT_SERVER");
|
||||
|
||||
name = str ? str : JACK_DEFAULT_SERVER_NAME;
|
||||
|
||||
str = NULL;
|
||||
if (impl->properties)
|
||||
str = pw_properties_get(impl->properties, "jack.promiscuous.server");
|
||||
if (str == NULL)
|
||||
str = getenv("JACK_PROMISCUOUS_SERVER");
|
||||
|
||||
promiscuous = str ? atoi(str) != 0 : false;
|
||||
|
||||
if (init_server(impl, name, promiscuous) < 0)
|
||||
goto error;
|
||||
|
||||
return impl;
|
||||
|
||||
error:
|
||||
free(impl);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void module_destroy(struct impl *impl)
|
||||
{
|
||||
struct impl *object, *tmp;
|
||||
|
||||
pw_log_debug("module %p: destroy", impl);
|
||||
|
||||
free(impl);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
module_new(module->core, NULL);
|
||||
return true;
|
||||
}
|
136
pipewire/modules/module-jack/defs.h
Normal file
136
pipewire/modules/module-jack/defs.h
Normal file
|
@ -0,0 +1,136 @@
|
|||
/* 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/client/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 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 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
|
||||
|
||||
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 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 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(write(client->fd,var,size)!=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
|
53
pipewire/modules/module-jack/server.h
Normal file
53
pipewire/modules/module-jack/server.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/* 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_client {
|
||||
int ref_num;
|
||||
struct client *owner;
|
||||
struct jack_client_control *control;
|
||||
};
|
||||
|
||||
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];
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
304
pipewire/modules/module-jack/shared.h
Normal file
304
pipewire/modules/module-jack/shared.h
Normal file
|
@ -0,0 +1,304 @@
|
|||
/* 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.
|
||||
*/
|
||||
|
||||
typedef uint16_t jack_int_t; // Internal type for ports and refnum
|
||||
|
||||
typedef enum {
|
||||
NotTriggered,
|
||||
Triggered,
|
||||
Running,
|
||||
Finished,
|
||||
} jack_client_state_t;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_client_timing {
|
||||
jack_time_t signaled_at;
|
||||
jack_time_t awake_at;
|
||||
jack_time_t finished_at;
|
||||
jack_client_state_t status;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
#define JACK_CLIENT_TIMING_INIT (struct jack_client_timing) { 0, 0, 0, NotTriggered }
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_port {
|
||||
int type_id;
|
||||
enum JackPortFlags flags;
|
||||
char name[REAL_JACK_PORT_NAME_SIZE];
|
||||
char alias1[REAL_JACK_PORT_NAME_SIZE];
|
||||
char alias2[REAL_JACK_PORT_NAME_SIZE];
|
||||
int ref_num;
|
||||
|
||||
jack_nframes_t latency;
|
||||
jack_nframes_t total_latency;
|
||||
jack_latency_range_t playback_latency;
|
||||
jack_latency_range_t capture_latency;
|
||||
uint8_t monitor_requests;
|
||||
|
||||
bool in_use;
|
||||
jack_port_id_t tied;
|
||||
jack_default_audio_sample_t buffer[BUFFER_SIZE_MAX + 8];
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
#define MAKE_FIXED_ARRAY(size) \
|
||||
PRE_PACKED_STRUCTURE \
|
||||
struct { \
|
||||
jack_int_t table[size]; \
|
||||
uint32_t counter; \
|
||||
} POST_PACKED_STRUCTURE
|
||||
|
||||
#define MAKE_FIXED_ARRAY1(size) \
|
||||
PRE_PACKED_STRUCTURE \
|
||||
struct { \
|
||||
MAKE_FIXED_ARRAY(size) array; \
|
||||
bool used; \
|
||||
} POST_PACKED_STRUCTURE
|
||||
|
||||
#define MAKE_FIXED_MATRIX(size) \
|
||||
PRE_PACKED_STRUCTURE \
|
||||
struct { \
|
||||
jack_int_t table[size][size]; \
|
||||
} POST_PACKED_STRUCTURE
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_activation_count {
|
||||
int32_t value;
|
||||
int32_t count;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
#define MAKE_LOOP_FEEDBACK(size) \
|
||||
PRE_PACKED_STRUCTURE \
|
||||
struct { \
|
||||
int table[size][3]; \
|
||||
} POST_PACKED_STRUCTURE
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_connection_manager {
|
||||
MAKE_FIXED_ARRAY(CONNECTION_NUM_FOR_PORT) connections[PORT_NUM_MAX];
|
||||
MAKE_FIXED_ARRAY1(PORT_NUM_FOR_CLIENT) input_port[CLIENT_NUM];
|
||||
MAKE_FIXED_ARRAY(PORT_NUM_FOR_CLIENT) output_port[CLIENT_NUM];
|
||||
MAKE_FIXED_MATRIX(CLIENT_NUM) connection_ref;
|
||||
struct jack_activation_count input_counter[CLIENT_NUM];
|
||||
MAKE_LOOP_FEEDBACK(CONNECTION_NUM_FOR_PORT) loop_feedback;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_atomic_counter {
|
||||
union {
|
||||
struct {
|
||||
uint16_t short_val1; // Cur
|
||||
uint16_t short_val2; // Next
|
||||
} scounter;
|
||||
uint32_t long_val;
|
||||
} info;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
#define MAKE_ATOMIC_STATE(type) \
|
||||
PRE_PACKED_STRUCTURE \
|
||||
struct { \
|
||||
type state[2]; \
|
||||
volatile struct jack_atomic_counter counter; \
|
||||
int32_t call_write_counter; \
|
||||
} POST_PACKED_STRUCTURE
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_atomic_array_counter {
|
||||
union {
|
||||
struct {
|
||||
unsigned char byte_val[4];
|
||||
} scounter;
|
||||
uint32_t long_val;
|
||||
} info;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
#define MAKE_ATOMIC_ARRAY_STATE(type) \
|
||||
PRE_PACKED_STRUCTURE \
|
||||
struct { \
|
||||
type state[3]; \
|
||||
volatile struct jack_atomic_array_counter counter; \
|
||||
} POST_PACKED_STRUCTURE
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_graph_manager {
|
||||
jack_shm_info_t info;
|
||||
MAKE_ATOMIC_STATE(struct jack_connection_manager) state;
|
||||
unsigned int port_max;
|
||||
struct jack_client_timing client_timing[CLIENT_NUM];
|
||||
struct jack_port port_array[0];
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
typedef enum {
|
||||
TransportCommandNone = 0,
|
||||
TransportCommandStart = 1,
|
||||
TransportCommandStop = 2,
|
||||
} transport_command_t;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_transport_engine {
|
||||
MAKE_ATOMIC_ARRAY_STATE(jack_position_t) state;
|
||||
jack_transport_state_t transport_state;
|
||||
volatile transport_command_t transport_cmd;
|
||||
transport_command_t previous_cmd; /* previous transport_cmd */
|
||||
jack_time_t sync_timeout;
|
||||
int sync_time_left;
|
||||
int time_base_master;
|
||||
bool pending_pos;
|
||||
bool network_sync;
|
||||
bool conditionnal;
|
||||
int32_t write_counter;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_timer {
|
||||
jack_nframes_t frames;
|
||||
jack_time_t current_wakeup;
|
||||
jack_time_t current_callback;
|
||||
jack_time_t next_wakeup;
|
||||
float period_usecs;
|
||||
float filter_omega; /* set once, never altered */
|
||||
bool initialized;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_frame_timer {
|
||||
MAKE_ATOMIC_STATE(struct jack_timer) state;
|
||||
bool first_wakeup;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
#ifdef JACK_MONITOR
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_timing_measure_client {
|
||||
int ref_num;
|
||||
jack_time_t signaled_at;
|
||||
jack_time_t awake_at;
|
||||
jack_time_t finished_at;
|
||||
jack_client_state_t status;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_timing_client_interval {
|
||||
int ref_num;
|
||||
char name[JACK_CLIENT_NAME_SIZE+1];
|
||||
int begin_interval;
|
||||
int end_interval;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_timing_measure {
|
||||
unsigned int audio_cycle;
|
||||
jack_time_t period_usecs;
|
||||
jack_time_t cur_cycle_begin;
|
||||
jack_time_t prev_cycle_end;
|
||||
struct jack_timing_measure_client client_table[CLIENT_NUM];
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_engine_profiling {
|
||||
struct jack_timing_measure profile_table[TIME_POINTS];
|
||||
struct jack_timing_client_interval interval_table[MEASURED_CLIENTS];
|
||||
|
||||
unsigned int audio_cycle;
|
||||
unsigned int measured_client;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
#endif
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_engine_control {
|
||||
jack_shm_info_t info;
|
||||
jack_nframes_t buffer_size;
|
||||
jack_nframes_t sample_rate;
|
||||
bool sync_node;
|
||||
bool temporary;
|
||||
jack_time_t period_usecs;
|
||||
jack_time_t timeout_usecs;
|
||||
float max_delayed_usecs;
|
||||
float xrun_delayed_usecs;
|
||||
bool timeout;
|
||||
bool real_time;
|
||||
bool saved_real_time;
|
||||
int server_priority;
|
||||
int client_priority;
|
||||
int max_client_priority;
|
||||
char server_name[JACK_SERVER_NAME_SIZE];
|
||||
struct jack_transport_engine transport;
|
||||
jack_timer_type_t clock_source;
|
||||
int driver_num;
|
||||
bool verbose;
|
||||
|
||||
// CPU Load
|
||||
jack_time_t prev_cycle_time;
|
||||
jack_time_t cur_cycle_time;
|
||||
jack_time_t spare_usecs;
|
||||
jack_time_t max_usecs;
|
||||
jack_time_t rolling_client_usecs[JACK_ENGINE_ROLLING_COUNT];
|
||||
unsigned int rolling_client_usecs_cnt;
|
||||
int rolling_client_usecs_index;
|
||||
int rolling_interval;
|
||||
float CPU_load;
|
||||
|
||||
// For OSX thread
|
||||
uint64_t period;
|
||||
uint64_t computation;
|
||||
uint64_t constraint;
|
||||
|
||||
// Timer
|
||||
struct jack_frame_timer frame_timer;
|
||||
|
||||
#ifdef JACK_MONITOR
|
||||
struct jack_engine_profiling profiler;
|
||||
#endif
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
PRE_PACKED_STRUCTURE
|
||||
struct jack_client_control {
|
||||
jack_shm_info_t info;
|
||||
char name[JACK_CLIENT_NAME_SIZE+1];
|
||||
bool callback[jack_notify_max];
|
||||
volatile jack_transport_state_t transport_state;
|
||||
volatile bool transport_sync;
|
||||
volatile bool transport_timebase;
|
||||
int ref_num;
|
||||
int PID;
|
||||
bool active;
|
||||
|
||||
int session_ID;
|
||||
char session_command[JACK_SESSION_COMMAND_SIZE];
|
||||
jack_session_flags_t session_flags;
|
||||
} POST_PACKED_STRUCTURE;
|
||||
|
||||
|
||||
static inline int jack_shm_alloc(size_t size, jack_shm_info_t *info, int num)
|
||||
{
|
||||
char name[64];
|
||||
|
||||
snprintf(name, sizeof(name), "/jack_shared%d", num);
|
||||
|
||||
if (jack_shmalloc(name, size, info)) {
|
||||
pw_log_error("Cannot create shared memory segment of size = %zd (%s)", size, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (jack_attach_shm(info)) {
|
||||
jack_error("Cannot attach shared memory segment name = %s err = %s", name, strerror(errno));
|
||||
jack_destroy_shm(info);
|
||||
return -1;
|
||||
}
|
||||
info->size = size;
|
||||
return 0;
|
||||
}
|
1303
pipewire/modules/module-jack/shm.c
Normal file
1303
pipewire/modules/module-jack/shm.c
Normal file
File diff suppressed because it is too large
Load diff
216
pipewire/modules/module-jack/shm.h
Normal file
216
pipewire/modules/module-jack/shm.h
Normal file
|
@ -0,0 +1,216 @@
|
|||
/* 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__ */
|
47
pipewire/modules/module-jack/synchro.h
Normal file
47
pipewire/modules/module-jack/synchro.h
Normal file
|
@ -0,0 +1,47 @@
|
|||
/* 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_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_alloc(struct jack_synchro *synchro,
|
||||
const char *client_name,
|
||||
const char *server_name,
|
||||
int value, bool internal,
|
||||
bool promiscuous)
|
||||
{
|
||||
if (promiscuous)
|
||||
snprintf(synchro->name, sizeof(synchro->name),
|
||||
"jack_sem.%s_%s", server_name, client_name);
|
||||
else
|
||||
snprintf(synchro->name, sizeof(synchro->name),
|
||||
"jack_sem.%d_%s_%s", getuid(), server_name, client_name);
|
||||
|
||||
if ((synchro->semaphore = sem_open(synchro->name, O_CREAT | O_RDWR, 0777, value)) == (sem_t*)SEM_FAILED) {
|
||||
pw_log_error("can't check in named semaphore name = %s err = %s", synchro->name, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return true;
|
||||
}
|
|
@ -6,6 +6,6 @@ moduledir=@moduledir@
|
|||
|
||||
Name: libpipewire
|
||||
Description: PipeWire Client Interface
|
||||
Version: @PACKAGE_VERSION@
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lpipewire-@PIPEWIRE_API_VERSION@
|
||||
Cflags: -I${includedir} -D_REENTRANT
|
||||
|
|
|
@ -6,6 +6,6 @@ moduledir=@moduledir@
|
|||
|
||||
Name: libpipewirecore
|
||||
Description: PipeWire Core
|
||||
Version: @PACKAGE_VERSION@
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lpipewirecore-@PIPEWIRE_API_VERSION@
|
||||
Cflags: -I${includedir} -D_REENTRANT
|
||||
|
|
|
@ -5,6 +5,6 @@ includedir=@includedir@/
|
|||
|
||||
Name: libspa
|
||||
Description: Simple Plugin API
|
||||
Version: @PACKAGE_VERSION@
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lspa-lib
|
||||
Cflags: -I${includedir} -D_REENTRANT
|
||||
|
|
Loading…
Reference in a new issue