aboutsummaryrefslogtreecommitdiff
path: root/sandbox_ui.lv2
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-05-20 10:36:32 +0200
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2018-05-20 10:36:32 +0200
commit44ab584cb87620eb8c5705b89221bc93b8f9723b (patch)
treec4b0a24dd4ec96232fdbc3270df0e1899dec7eba /sandbox_ui.lv2
parent5a49da5adc55a82ebf5d81324203ac3164454fef (diff)
downloadsynthpod-44ab584cb87620eb8c5705b89221bc93b8f9723b.zip
synthpod-44ab584cb87620eb8c5705b89221bc93b8f9723b.tar.gz
synthpod-44ab584cb87620eb8c5705b89221bc93b8f9723b.tar.bz2
synthpod-44ab584cb87620eb8c5705b89221bc93b8f9723b.tar.xz
sbox: implement variable ringbuffer size.
Diffstat (limited to 'sandbox_ui.lv2')
-rw-r--r--sandbox_ui.lv2/sandbox_io.h56
-rw-r--r--sandbox_ui.lv2/sandbox_master.c4
-rw-r--r--sandbox_ui.lv2/sandbox_master.h2
-rw-r--r--sandbox_ui.lv2/sandbox_slave.c14
4 files changed, 44 insertions, 32 deletions
diff --git a/sandbox_ui.lv2/sandbox_io.h b/sandbox_ui.lv2/sandbox_io.h
index 11b5e6b..5f0d93b 100644
--- a/sandbox_ui.lv2/sandbox_io.h
+++ b/sandbox_ui.lv2/sandbox_io.h
@@ -58,17 +58,13 @@ struct _sandbox_io_subscription_t {
int32_t state;
};
-#define SANDBOX_BUFFER_SIZE 0x1000000 // 16M
-
struct _sandbox_io_shm_body_t {
sem_t sem;
varchunk_t varchunk;
- uint8_t buf [SANDBOX_BUFFER_SIZE];
};
struct _sandbox_io_shm_t {
- sandbox_io_shm_body_t to_master;
- sandbox_io_shm_body_t from_master;
+ atomic_size_t minimum;
};
struct _sandbox_io_t {
@@ -100,6 +96,8 @@ struct _sandbox_io_t {
char *name;
sandbox_io_shm_t *shm;
+ sandbox_io_shm_body_t *from_master;
+ sandbox_io_shm_body_t *to_master;
bool again;
};
@@ -112,8 +110,8 @@ _sandbox_io_recv(sandbox_io_t *io, _sandbox_io_recv_cb_t recv_cb,
bool close_request = false;
sandbox_io_shm_body_t *rx = io->is_master
- ? &io->shm->to_master
- : &io->shm->from_master;
+ ? io->to_master
+ : io->from_master;
while((buf = varchunk_read_request(&rx->varchunk, &sz)))
{
@@ -250,8 +248,8 @@ _sandbox_io_send(sandbox_io_t *io, uint32_t index,
uint32_t size, uint32_t protocol, const void *buf)
{
sandbox_io_shm_body_t *tx = io->is_master
- ? &io->shm->from_master
- : &io->shm->to_master;
+ ? io->from_master
+ : io->to_master;
// reserve 8192 additional bytes for the parent atom and dictionary
const size_t req_sz = size + 8192; //FIXME is this enough?
@@ -359,8 +357,8 @@ static inline void
_sandbox_io_wait(sandbox_io_t *io)
{
sandbox_io_shm_body_t *rx = io->is_master
- ? &io->shm->to_master
- : &io->shm->from_master;
+ ? io->to_master
+ : io->from_master;
int s;
while((s = sem_wait(&rx->sem)) == -1)
@@ -382,8 +380,8 @@ static inline bool
_sandbox_io_timedwait(sandbox_io_t *io, const struct timespec *abs_timeout)
{
sandbox_io_shm_body_t *rx = io->is_master
- ? &io->shm->to_master
- : &io->shm->from_master;
+ ? io->to_master
+ : io->from_master;
int s;
while((s = sem_timedwait(&rx->sem, abs_timeout)) == -1)
@@ -408,8 +406,8 @@ static inline void
_sandbox_io_signal_rx(sandbox_io_t *io)
{
sandbox_io_shm_body_t *rx = io->is_master
- ? &io->shm->to_master
- : &io->shm->from_master;
+ ? io->to_master
+ : io->from_master;
sem_post(&rx->sem);
}
@@ -418,15 +416,15 @@ static inline void
_sandbox_io_signal_tx(sandbox_io_t *io)
{
sandbox_io_shm_body_t *tx = io->is_master
- ? &io->shm->from_master
- : &io->shm->to_master;
+ ? io->from_master
+ : io->to_master;
sem_post(&tx->sem);
}
static inline int
_sandbox_io_init(sandbox_io_t *io, LV2_URID_Map *map, LV2_URID_Unmap *unmap,
- const char *socket_path, bool is_master, bool drop_messages)
+ const char *socket_path, bool is_master, bool drop_messages, size_t minimum)
{
io->map = map;
io->unmap = unmap;
@@ -441,7 +439,9 @@ _sandbox_io_init(sandbox_io_t *io, LV2_URID_Map *map, LV2_URID_Unmap *unmap,
if(!(io->netatom = netatom_new(io->map, io->unmap, swap)))
return -1;
- const size_t total_size = sizeof(sandbox_io_shm_t);
+ minimum = varchunk_body_size(minimum);
+ const size_t body_size = sizeof(sandbox_io_shm_body_t) + minimum;
+ const size_t total_size = sizeof(sandbox_io_shm_t) + 2*body_size;
const char *name = is_shm
? &socket_path[6]
@@ -470,15 +470,21 @@ _sandbox_io_init(sandbox_io_t *io, LV2_URID_Map *map, LV2_URID_Unmap *unmap,
}
close(fd);
+ fprintf(stderr, "%i %p\n", io->is_master, io->shm);
+
+ void *offset = (void *)io->shm + sizeof(sandbox_io_shm_t);
+ io->from_master = offset;
+ io->to_master = offset + body_size;
+
if(io->is_master)
{
- if(sem_init(&io->shm->from_master.sem, 1, 0) == -1)
+ if(sem_init(&io->from_master->sem, 1, 0) == -1)
return -1;
- if(sem_init(&io->shm->to_master.sem, 1, 0) == -1)
+ if(sem_init(&io->to_master->sem, 1, 0) == -1)
return -1;
- varchunk_init(&io->shm->from_master.varchunk, SANDBOX_BUFFER_SIZE, true);
- varchunk_init(&io->shm->to_master.varchunk, SANDBOX_BUFFER_SIZE, true);
+ varchunk_init(&io->from_master->varchunk, minimum, true);
+ varchunk_init(&io->to_master->varchunk, minimum, true);
}
lv2_atom_forge_init(&io->forge, map);
@@ -516,8 +522,8 @@ _sandbox_io_deinit(sandbox_io_t *io, bool terminate)
{
if(io->is_master)
{
- sem_destroy(&io->shm->from_master.sem);
- sem_destroy(&io->shm->to_master.sem);
+ sem_destroy(&io->from_master->sem);
+ sem_destroy(&io->to_master->sem);
}
munmap(io->shm, total_size);
diff --git a/sandbox_ui.lv2/sandbox_master.c b/sandbox_ui.lv2/sandbox_master.c
index 5d7e762..16010bf 100644
--- a/sandbox_ui.lv2/sandbox_master.c
+++ b/sandbox_ui.lv2/sandbox_master.c
@@ -35,7 +35,7 @@ struct _sandbox_master_t {
};
sandbox_master_t *
-sandbox_master_new(sandbox_master_driver_t *driver, void *data)
+sandbox_master_new(sandbox_master_driver_t *driver, void *data, size_t minimum)
{
sandbox_master_t *sb = calloc(1, sizeof(sandbox_master_t));
if(!sb)
@@ -44,7 +44,7 @@ sandbox_master_new(sandbox_master_driver_t *driver, void *data)
sb->driver = driver;
sb->data = data;
- if(_sandbox_io_init(&sb->io, driver->map, driver->unmap, driver->socket_path, true, true))
+ if(_sandbox_io_init(&sb->io, driver->map, driver->unmap, driver->socket_path, true, true, minimum))
goto fail;
return sb;
diff --git a/sandbox_ui.lv2/sandbox_master.h b/sandbox_ui.lv2/sandbox_master.h
index 2fc2cd8..0246116 100644
--- a/sandbox_ui.lv2/sandbox_master.h
+++ b/sandbox_ui.lv2/sandbox_master.h
@@ -40,7 +40,7 @@ struct _sandbox_master_driver_t {
};
sandbox_master_t *
-sandbox_master_new(sandbox_master_driver_t *driver, void *data);
+sandbox_master_new(sandbox_master_driver_t *driver, void *data, size_t minimum);
void
sandbox_master_free(sandbox_master_t *sb);
diff --git a/sandbox_ui.lv2/sandbox_slave.c b/sandbox_ui.lv2/sandbox_slave.c
index 7d04682..76608fe 100644
--- a/sandbox_ui.lv2/sandbox_slave.c
+++ b/sandbox_ui.lv2/sandbox_slave.c
@@ -88,6 +88,7 @@ struct _sandbox_slave_t {
const char *ui_bundle_path;
const char *socket_path;
const char *window_title;
+ uint32_t minimum;
float sample_rate;
float update_rate;
};
@@ -293,6 +294,7 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver, v
sb->plugin_urn = NULL;
sb->window_title = "Untitled"; // fall-back
+ sb->minimum = 0x100000; // fall-back
sb->sample_rate = 44100.f; // fall-back
sb->update_rate = 25.f; // fall-back
@@ -302,7 +304,7 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver, v
"Released under Artistic License 2.0 by Open Music Kontrollers\n");
int c;
- while((c = getopt(argc, argv, "vhn:p:P:u:U:s:w:r:f:")) != -1)
+ while((c = getopt(argc, argv, "vhn:p:P:u:U:s:w:m:r:f:")) != -1)
{
switch(c)
{
@@ -338,7 +340,8 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver, v
" [-U] ui-bundle Plugin UI bundle path\n"
" [-s] socket-path Socket path\n"
" [-w] window-title Window title\n"
- " [-r] sample-rate Sample rate\n"
+ " [-m] minimum-size Minimum ringbuffer size\n"
+ " [-r] sample-rate Sample rate (44100)\n"
" [-f] update-rate GUI update rate (25)\n\n"
, argv[0]);
return 0;
@@ -363,6 +366,9 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver, v
case 'w':
sb->window_title = optarg;
break;
+ case 'm':
+ sb->minimum = atoi(optarg);
+ break;
case 'r':
sb->sample_rate = atof(optarg);
break;
@@ -370,7 +376,7 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver, v
sb->update_rate = atof(optarg);
break;
case '?':
- if( (optopt == 'n') || (optopt == 'p') || (optopt == 'P') || (optopt == 'u') || (optopt == 'U') || (optopt == 's') || (optopt == 'w') || (optopt == 'r') || (optopt == 'f') )
+ if( (optopt == 'n') || (optopt == 'p') || (optopt == 'P') || (optopt == 'u') || (optopt == 'U') || (optopt == 's') || (optopt == 'w') || (optopt == 'm') || (optopt == 'r') || (optopt == 'f') )
fprintf(stderr, "Option `-%c' requires an argument.\n", optopt);
else if(isprint(optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
@@ -541,7 +547,7 @@ sandbox_slave_new(int argc, char **argv, const sandbox_slave_driver_t *driver, v
goto fail;
}
- if(_sandbox_io_init(&sb->io, sb->map, sb->unmap, sb->socket_path, false, false))
+ if(_sandbox_io_init(&sb->io, sb->map, sb->unmap, sb->socket_path, false, false, sb->minimum))
{
fprintf(stderr, "_sandbox_io_init failed: are you sure that the host is running?\n");
goto fail;