diff options
author | David Robillard <d@drobilla.net> | 2024-11-18 17:53:09 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-11-24 19:10:58 -0500 |
commit | 54918d00fbad75374a11780e081a634ed94a3054 (patch) | |
tree | 523eb6b52f7bdbfd8b636095b6be9cd54f881d48 | |
parent | 5bbc72296d650cca75b0344efcae4658a14c9c62 (diff) | |
download | jalv-54918d00fbad75374a11780e081a634ed94a3054.tar.gz jalv-54918d00fbad75374a11780e081a634ed94a3054.tar.bz2 jalv-54918d00fbad75374a11780e081a634ed94a3054.zip |
Move Jack internal client to a separate compilation unit
Aside from keeping things tidy and independent, this removes this unused code
from the program builds, instead only including it in the Jack internal module.
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | src/jack.c | 100 | ||||
-rw-r--r-- | src/jack_impl.h | 23 | ||||
-rw-r--r-- | src/jack_internal.c | 109 |
4 files changed, 134 insertions, 100 deletions
diff --git a/meson.build b/meson.build index 588622e..0c9db25 100644 --- a/meson.build +++ b/meson.build @@ -451,7 +451,7 @@ common_c_args = c_suppressions + platform_defines + suil_defines if jack_dep.found() shared_library( 'jalv', - sources + files('src/jalv_console.c'), + sources + files('src/jack_internal.c', 'src/jalv_console.c'), c_args: c_suppressions + platform_defines + ['-DHAVE_SUIL=0'], dependencies: common_dependencies, install: true, @@ -5,6 +5,7 @@ #include "comm.h" #include "frontend.h" +#include "jack_impl.h" #include "jalv.h" #include "jalv_config.h" #include "log.h" @@ -30,7 +31,6 @@ # include <jack/metadata.h> #endif -#include <ctype.h> #include <stdbool.h> #include <stdint.h> #include <stdio.h> @@ -43,22 +43,9 @@ # define REALTIME #endif -struct JalvBackendImpl { - jack_client_t* client; ///< Jack client - bool is_internal_client; ///< Running inside jackd -}; - /// Maximum supported latency in frames (at most 2^24 so all integers work) static const float max_latency = 16777216.0f; -/// Internal Jack client initialization entry point -int -jack_initialize(jack_client_t* client, const char* load_init); - -/// Internal Jack client finalization entry point -void -jack_finish(void* arg); - /// Jack buffer size callback static int jack_buffer_size_cb(jack_nframes_t nframes, void* data) @@ -492,88 +479,3 @@ jalv_backend_recompute_latencies(Jalv* const jalv) { jack_recompute_total_latencies(jalv->backend->client); } - -int -jack_initialize(jack_client_t* const client, const char* const load_init) -{ -#ifndef E2BIG -# define E2BIG 7 -#endif -#ifndef ENOMEM -# define ENOMEM 12 -#endif - - const size_t args_len = strlen(load_init); - if (args_len > JACK_LOAD_INIT_LIMIT) { - jalv_log(JALV_LOG_ERR, "Too many arguments given\n"); - return E2BIG; - } - - Jalv* const jalv = (Jalv*)calloc(1, sizeof(Jalv)); - if (!jalv) { - return ENOMEM; - } - - if (!(jalv->backend = jalv_backend_allocate())) { - free(jalv); - return ENOMEM; - } - - jalv->backend->client = client; - jalv->backend->is_internal_client = true; - - // Build full command line with "program" name for building argv - const size_t cmd_len = strlen("jalv ") + args_len; - char* const cmd = (char*)calloc(cmd_len + 1, 1); - memcpy(cmd, "jalv ", strlen("jalv ") + 1); - memcpy(cmd + 5, load_init, args_len + 1); - - // Build argv - int argc = 0; - char** argv = NULL; - char* tok = cmd; - int err = 0; - for (size_t i = 0; !err && i <= cmd_len; ++i) { - if (isspace(cmd[i]) || !cmd[i]) { - char** const new_argv = (char**)realloc(argv, sizeof(char*) * ++argc); - if (!new_argv) { - err = ENOMEM; - break; - } - - argv = new_argv; - cmd[i] = '\0'; - argv[argc - 1] = tok; - tok = cmd + i + 1; - } - } - - if (err || (err = jalv_open(jalv, &argc, &argv))) { - jalv_close(jalv); - free(jalv); - } else { - jalv_activate(jalv); - } - - free(argv); - free(cmd); - return err; - -#undef ENOMEM -#undef E2BIG -} - -void -jack_finish(void* const arg) -{ - Jalv* const jalv = (Jalv*)arg; - if (jalv) { - jalv_deactivate(jalv); - if (jalv_close(jalv)) { - jalv_log(JALV_LOG_ERR, "Failed to close Jalv\n"); - } - - jalv_backend_free(jalv->backend); - free(jalv); - } -} diff --git a/src/jack_impl.h b/src/jack_impl.h new file mode 100644 index 0000000..0ecd3eb --- /dev/null +++ b/src/jack_impl.h @@ -0,0 +1,23 @@ +// Copyright 2007-2024 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#ifndef JALV_JACK_IMPL_H +#define JALV_JACK_IMPL_H + +#include "attributes.h" + +#include <jack/jack.h> + +#include <stdbool.h> + +// Definition of Jack backend structure (private to implementation) +JALV_BEGIN_DECLS + +struct JalvBackendImpl { + jack_client_t* client; ///< Jack client + bool is_internal_client; ///< Running inside jackd +}; + +JALV_END_DECLS + +#endif // JALV_JACK_IMPL_H diff --git a/src/jack_internal.c b/src/jack_internal.c new file mode 100644 index 0000000..5157e43 --- /dev/null +++ b/src/jack_internal.c @@ -0,0 +1,109 @@ +// Copyright 2007-2024 David Robillard <d@drobilla.net> +// SPDX-License-Identifier: ISC + +#include "backend.h" +#include "jack_impl.h" +#include "jalv.h" +#include "log.h" +#include "types.h" + +#include <jack/types.h> + +#include <ctype.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +/// Internal Jack client initialization entry point +int +jack_initialize(jack_client_t* client, const char* load_init); + +/// Internal Jack client finalization entry point +void +jack_finish(void* arg); + +int +jack_initialize(jack_client_t* const client, const char* const load_init) +{ +#ifndef E2BIG +# define E2BIG 7 +#endif +#ifndef ENOMEM +# define ENOMEM 12 +#endif + + const size_t args_len = strlen(load_init); + if (args_len > JACK_LOAD_INIT_LIMIT) { + jalv_log(JALV_LOG_ERR, "Too many arguments given\n"); + return E2BIG; + } + + Jalv* const jalv = (Jalv*)calloc(1, sizeof(Jalv)); + if (!jalv) { + return ENOMEM; + } + + if (!(jalv->backend = jalv_backend_allocate())) { + free(jalv); + return ENOMEM; + } + + jalv->backend->client = client; + jalv->backend->is_internal_client = true; + + // Build full command line with "program" name for building argv + const size_t cmd_len = strlen("jalv ") + args_len; + char* const cmd = (char*)calloc(cmd_len + 1, 1); + memcpy(cmd, "jalv ", strlen("jalv ") + 1); + memcpy(cmd + 5, load_init, args_len + 1); + + // Build argv + int argc = 0; + char** argv = NULL; + char* tok = cmd; + int err = 0; + for (size_t i = 0; !err && i <= cmd_len; ++i) { + if (isspace(cmd[i]) || !cmd[i]) { + char** const new_argv = (char**)realloc(argv, sizeof(char*) * ++argc); + if (!new_argv) { + err = ENOMEM; + break; + } + + argv = new_argv; + cmd[i] = '\0'; + argv[argc - 1] = tok; + tok = cmd + i + 1; + } + } + + if (err || (err = jalv_open(jalv, &argc, &argv))) { + jalv_close(jalv); + free(jalv); + } else { + jalv_activate(jalv); + } + + free(argv); + free(cmd); + return err; + +#undef ENOMEM +#undef E2BIG +} + +void +jack_finish(void* const arg) +{ + Jalv* const jalv = (Jalv*)arg; + if (jalv) { + jalv_deactivate(jalv); + if (jalv_close(jalv)) { + jalv_log(JALV_LOG_ERR, "Failed to close Jalv\n"); + } + + jalv_backend_free(jalv->backend); + free(jalv); + } +} |