Merge pipewire-jack subtree

This commit is contained in:
Arun Raghavan 2019-11-03 15:20:56 +01:00
commit 863a642e08
9 changed files with 5648 additions and 0 deletions

View file

@ -0,0 +1,33 @@
pipewire_jack_sources = [
'pipewire-jack.c',
'metadata.c',
'ringbuffer.c',
'uuid.c',
]
pipewire_jack_c_args = [
'-DHAVE_CONFIG_H',
'-D_GNU_SOURCE',
'-DPIC',
]
#optional dependencies
jack_dep = dependency('jack', version : '>= 1.9.10', required : false)
pipewire_jack = shared_library('jack',
pipewire_jack_sources,
soversion : 0,
c_args : pipewire_jack_c_args,
include_directories : [configinc],
dependencies : [pipewire_dep, jack_dep, mathlib],
install : false,
)
if sdl_dep.found()
executable('video-dsp-play',
'../examples/video-dsp-play.c',
c_args : [ '-D_GNU_SOURCE' ],
install: false,
dependencies : [jack_dep, sdl_dep, mathlib],
)
endif

View file

@ -0,0 +1,173 @@
/* PipeWire
* Copyright (C) 2018 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <jack/metadata.h>
#include <jack/uuid.h>
#include <pipewire/pipewire.h>
static struct pw_properties * get_properties(void)
{
static struct pw_properties *properties = NULL;
if (properties == NULL) {
properties = pw_properties_new(NULL, NULL);
}
return properties;
}
static void make_key(char *dst, jack_uuid_t subject, const char *key, int keylen)
{
int len;
jack_uuid_unparse (subject, dst);
len = strlen(dst);
dst[len] = '@';
memcpy(&dst[len+1], key, keylen+1);
}
SPA_EXPORT
int jack_set_property(jack_client_t*client,
jack_uuid_t subject,
const char* key,
const char* value,
const char* type)
{
int keylen = strlen(key);
char *dst = alloca(JACK_UUID_STRING_SIZE + keylen);
struct pw_properties * props = get_properties();
make_key(dst, subject, key, keylen);
pw_properties_setf(props, dst, "%s@%s", value, type);
pw_log_debug("set '%s' to '%s@%s'", dst, value, type);
return 0;
}
SPA_EXPORT
int jack_get_property(jack_uuid_t subject,
const char* key,
char** value,
char** type)
{
int keylen = strlen(key);
char *dst = alloca(JACK_UUID_STRING_SIZE + keylen);
struct pw_properties * props = get_properties();
const char *str, *at;
make_key(dst, subject, key, keylen);
if ((str = pw_properties_get(props, dst)) == NULL) {
pw_log_warn("no property '%s'", dst);
return -1;
}
at = strrchr(str, '@');
if (at == NULL) {
pw_log_warn("property '%s' invalid value '%s'", dst, str);
return -1;
}
*value = strndup(str, at - str);
*type = strdup(at + 1);
pw_log_debug("got '%s' with value:'%s' type:'%s'", dst, *value, *type);
return 0;
}
SPA_EXPORT
void jack_free_description (jack_description_t* desc, int free_description_itself)
{
pw_log_warn("not implemented");
}
SPA_EXPORT
int jack_get_properties (jack_uuid_t subject,
jack_description_t* desc)
{
pw_log_warn("not implemented");
return -1;
}
SPA_EXPORT
int jack_get_all_properties (jack_description_t** descs)
{
pw_log_warn("not implemented");
return -1;
}
SPA_EXPORT
int jack_remove_property (jack_client_t* client, jack_uuid_t subject, const char* key)
{
int keylen = strlen(key);
char *dst = alloca(JACK_UUID_STRING_SIZE + keylen);
struct pw_properties * props = get_properties();
make_key(dst, subject, key, keylen);
pw_properties_set(props, dst, NULL);
pw_log_debug("removed %s", dst);
return 0;
}
SPA_EXPORT
int jack_remove_properties (jack_client_t* client, jack_uuid_t subject)
{
pw_log_warn("not implemented");
return -1;
}
SPA_EXPORT
int jack_remove_all_properties (jack_client_t* client)
{
pw_log_warn("not implemented");
return -1;
}
SPA_EXPORT
int jack_set_property_change_callback (jack_client_t* client,
JackPropertyChangeCallback callback,
void* arg)
{
pw_log_warn("not implemented");
return -1;
}
SPA_EXPORT
const char* JACK_METADATA_PRETTY_NAME = "http://jackaudio.org/metadata/pretty-name";
SPA_EXPORT
const char* JACK_METADATA_HARDWARE = "http://jackaudio.org/metadata/hardware";
SPA_EXPORT
const char* JACK_METADATA_CONNECTED = "http://jackaudio.org/metadata/connected";
SPA_EXPORT
const char* JACK_METADATA_PORT_GROUP = "http://jackaudio.org/metadata/port-group";
SPA_EXPORT
const char* JACK_METADATA_ICON_SMALL = "http://jackaudio.org/metadata/icon-small";
SPA_EXPORT
const char* JACK_METADATA_ICON_LARGE = "http://jackaudio.org/metadata/icon-large";

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,299 @@
/* PipeWire
* Copyright (C) 2018 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <spa/utils/defs.h>
#include <jack/ringbuffer.h>
SPA_EXPORT
jack_ringbuffer_t *jack_ringbuffer_create(size_t sz)
{
size_t power_of_two;
jack_ringbuffer_t *rb;
rb = calloc(1, sizeof(jack_ringbuffer_t));
if (rb == NULL)
return NULL;
for (power_of_two = 1; 1u << power_of_two < sz; power_of_two++);
rb->size = 1 << power_of_two;
rb->size_mask = rb->size - 1;
if ((rb->buf = calloc(1, rb->size)) == NULL) {
free (rb);
return NULL;
}
rb->mlocked = 0;
return rb;
}
SPA_EXPORT
void jack_ringbuffer_free(jack_ringbuffer_t *rb)
{
#ifdef USE_MLOCK
if (rb->mlocked)
munlock (rb->buf, rb->size);
#endif /* USE_MLOCK */
free (rb->buf);
free (rb);
}
SPA_EXPORT
void jack_ringbuffer_get_read_vector(const jack_ringbuffer_t *rb,
jack_ringbuffer_data_t *vec)
{
size_t free_cnt;
size_t cnt2;
size_t w, r;
w = rb->write_ptr;
r = rb->read_ptr;
if (w > r)
free_cnt = w - r;
else
free_cnt = (w - r + rb->size) & rb->size_mask;
cnt2 = r + free_cnt;
if (cnt2 > rb->size) {
vec[0].buf = &(rb->buf[r]);
vec[0].len = rb->size - r;
vec[1].buf = rb->buf;
vec[1].len = cnt2 & rb->size_mask;
} else {
vec[0].buf = &(rb->buf[r]);
vec[0].len = free_cnt;
vec[1].len = 0;
}
}
SPA_EXPORT
void jack_ringbuffer_get_write_vector(const jack_ringbuffer_t *rb,
jack_ringbuffer_data_t *vec)
{
size_t free_cnt;
size_t cnt2;
size_t w, r;
w = rb->write_ptr;
r = rb->read_ptr;
if (w > r)
free_cnt = ((r - w + rb->size) & rb->size_mask) - 1;
else if (w < r)
free_cnt = (r - w) - 1;
else
free_cnt = rb->size - 1;
cnt2 = w + free_cnt;
if (cnt2 > rb->size) {
vec[0].buf = &(rb->buf[w]);
vec[0].len = rb->size - w;
vec[1].buf = rb->buf;
vec[1].len = cnt2 & rb->size_mask;
} else {
vec[0].buf = &(rb->buf[w]);
vec[0].len = free_cnt;
vec[1].len = 0;
}
}
SPA_EXPORT
size_t jack_ringbuffer_read(jack_ringbuffer_t *rb, char *dest, size_t cnt)
{
size_t free_cnt;
size_t cnt2;
size_t to_read;
size_t n1, n2;
if ((free_cnt = jack_ringbuffer_read_space (rb)) == 0)
return 0;
to_read = cnt > free_cnt ? free_cnt : cnt;
cnt2 = rb->read_ptr + to_read;
if (cnt2 > rb->size) {
n1 = rb->size - rb->read_ptr;
n2 = cnt2 & rb->size_mask;
} else {
n1 = to_read;
n2 = 0;
}
memcpy (dest, &(rb->buf[rb->read_ptr]), n1);
rb->read_ptr = (rb->read_ptr + n1) & rb->size_mask;
if (n2) {
memcpy (dest + n1, &(rb->buf[rb->read_ptr]), n2);
rb->read_ptr = (rb->read_ptr + n2) & rb->size_mask;
}
return to_read;
}
SPA_EXPORT
size_t jack_ringbuffer_peek(jack_ringbuffer_t *rb, char *dest, size_t cnt)
{
size_t free_cnt;
size_t cnt2;
size_t to_read;
size_t n1, n2;
size_t tmp_read_ptr;
tmp_read_ptr = rb->read_ptr;
if ((free_cnt = jack_ringbuffer_read_space (rb)) == 0)
return 0;
to_read = cnt > free_cnt ? free_cnt : cnt;
cnt2 = tmp_read_ptr + to_read;
if (cnt2 > rb->size) {
n1 = rb->size - tmp_read_ptr;
n2 = cnt2 & rb->size_mask;
} else {
n1 = to_read;
n2 = 0;
}
memcpy (dest, &(rb->buf[tmp_read_ptr]), n1);
tmp_read_ptr = (tmp_read_ptr + n1) & rb->size_mask;
if (n2)
memcpy (dest + n1, &(rb->buf[tmp_read_ptr]), n2);
return to_read;
}
SPA_EXPORT
void jack_ringbuffer_read_advance(jack_ringbuffer_t *rb, size_t cnt)
{
size_t tmp = (rb->read_ptr + cnt) & rb->size_mask;
rb->read_ptr = tmp;
}
SPA_EXPORT
size_t jack_ringbuffer_read_space(const jack_ringbuffer_t *rb)
{
size_t w, r;
w = rb->write_ptr;
r = rb->read_ptr;
if (w > r)
return w - r;
else
return (w - r + rb->size) & rb->size_mask;
}
SPA_EXPORT
int jack_ringbuffer_mlock(jack_ringbuffer_t *rb)
{
#ifdef USE_MLOCK
if (mlock (rb->buf, rb->size))
return -1;
#endif /* USE_MLOCK */
rb->mlocked = 1;
return 0;
}
SPA_EXPORT
void jack_ringbuffer_reset(jack_ringbuffer_t *rb)
{
rb->read_ptr = 0;
rb->write_ptr = 0;
memset(rb->buf, 0, rb->size);
}
SPA_EXPORT
void jack_ringbuffer_reset_size (jack_ringbuffer_t * rb, size_t sz)
{
rb->size = sz;
rb->size_mask = rb->size - 1;
rb->read_ptr = 0;
rb->write_ptr = 0;
}
SPA_EXPORT
size_t jack_ringbuffer_write(jack_ringbuffer_t *rb, const char *src,
size_t cnt)
{
size_t free_cnt;
size_t cnt2;
size_t to_write;
size_t n1, n2;
if ((free_cnt = jack_ringbuffer_write_space (rb)) == 0)
return 0;
to_write = cnt > free_cnt ? free_cnt : cnt;
cnt2 = rb->write_ptr + to_write;
if (cnt2 > rb->size) {
n1 = rb->size - rb->write_ptr;
n2 = cnt2 & rb->size_mask;
} else {
n1 = to_write;
n2 = 0;
}
memcpy (&(rb->buf[rb->write_ptr]), src, n1);
rb->write_ptr = (rb->write_ptr + n1) & rb->size_mask;
if (n2) {
memcpy (&(rb->buf[rb->write_ptr]), src + n1, n2);
rb->write_ptr = (rb->write_ptr + n2) & rb->size_mask;
}
return to_write;
}
SPA_EXPORT
void jack_ringbuffer_write_advance(jack_ringbuffer_t *rb, size_t cnt)
{
size_t tmp = (rb->write_ptr + cnt) & rb->size_mask;
rb->write_ptr = tmp;
}
SPA_EXPORT
size_t jack_ringbuffer_write_space(const jack_ringbuffer_t *rb)
{
size_t w, r;
w = rb->write_ptr;
r = rb->read_ptr;
if (w > r)
return ((r - w + rb->size) & rb->size_mask) - 1;
else if (w < r)
return (r - w) - 1;
else
return rb->size - 1;
}

View file

@ -0,0 +1,54 @@
/* PipeWire
* Copyright (C) 2018 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/statistics.h>
SPA_EXPORT
float jack_get_max_delayed_usecs (jack_client_t *client)
{
struct client *c = (struct client *) client;
float res = 0.0f;
if (c->driver_activation)
res = (float)c->driver_activation->max_delay / SPA_USEC_PER_SEC;
pw_log_trace(NAME" %p: max delay %f", client, res);
return res;
}
SPA_EXPORT
float jack_get_xrun_delayed_usecs (jack_client_t *client)
{
struct client *c = (struct client *) client;
float res = 0.0f;
if (c->driver_activation)
res = (float)c->driver_activation->xrun_delay / SPA_USEC_PER_SEC;
pw_log_trace(NAME" %p: xrun delay %f", client, res);
return res;
}
SPA_EXPORT
void jack_reset_max_delayed_usecs (jack_client_t *client)
{
struct client *c = (struct client *) client;
if (c->driver_activation)
c->driver_activation->max_delay = 0;
}

102
pipewire-jack/src/uuid.c Normal file
View file

@ -0,0 +1,102 @@
/* PipeWire
* Copyright (C) 2018 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <jack/uuid.h>
#include <pipewire/pipewire.h>
SPA_EXPORT
jack_uuid_t jack_client_uuid_generate ()
{
static uint32_t uuid_cnt = 0;
jack_uuid_t uuid = 0x2; /* JackUUIDClient */;
uuid = (uuid << 32) | ++uuid_cnt;
pw_log_debug("uuid %"PRIu64, uuid);
return uuid;
}
SPA_EXPORT
jack_uuid_t jack_port_uuid_generate (uint32_t port_id)
{
jack_uuid_t uuid = 0x1; /* JackUUIDPort */
uuid = (uuid << 32) | (port_id + 1);
pw_log_debug("uuid %d -> %"PRIu64, port_id, uuid);
return uuid;
}
SPA_EXPORT
uint32_t jack_uuid_to_index (jack_uuid_t id)
{
return (id & 0xffff) - 1;
}
SPA_EXPORT
int jack_uuid_compare (jack_uuid_t id1, jack_uuid_t id2)
{
if (id1 == id2)
return 0;
if (id1 < id2)
return -1;
return 1;
}
SPA_EXPORT
void jack_uuid_copy (jack_uuid_t* dst, jack_uuid_t src)
{
*dst = src;
}
SPA_EXPORT
void jack_uuid_clear (jack_uuid_t *id)
{
*id = 0;
}
SPA_EXPORT
int jack_uuid_parse (const char *buf, jack_uuid_t *id)
{
if (sscanf (buf, "%" PRIu64, id) == 1) {
if (*id < (0x1LL << 32)) {
/* has not type bits set - not legal */
return -1;
}
return 0;
}
return -1;
}
SPA_EXPORT
void jack_uuid_unparse (jack_uuid_t id, char buf[JACK_UUID_STRING_SIZE])
{
snprintf (buf, JACK_UUID_STRING_SIZE, "%" PRIu64, id);
}
SPA_EXPORT
int jack_uuid_empty (jack_uuid_t id)
{
return id == 0;
}