mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
jack: Add jack_port_t* <-> object helpers
Improve get_buffer debug. Add some extra checks for the type before we try to use the object as a port. Set latency range to 0 when called with wrong port. Ardour seems to call into us with ports from a previous jack_client..
This commit is contained in:
parent
ee811307cd
commit
e2598b3242
1 changed files with 66 additions and 46 deletions
|
|
@ -536,6 +536,15 @@ static void free_object(struct client *c, struct object *o)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct object *port_to_object(const jack_port_t *port)
|
||||||
|
{
|
||||||
|
return (struct object*)port;
|
||||||
|
}
|
||||||
|
static inline jack_port_t *object_to_port(struct object *o)
|
||||||
|
{
|
||||||
|
return (jack_port_t*)o;
|
||||||
|
}
|
||||||
|
|
||||||
struct io_info {
|
struct io_info {
|
||||||
struct mix *mix;
|
struct mix *mix;
|
||||||
void *data;
|
void *data;
|
||||||
|
|
@ -5016,7 +5025,7 @@ jack_port_t * jack_port_register (jack_client_t *client,
|
||||||
goto error_free;
|
goto error_free;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (jack_port_t *) o;
|
return object_to_port(o);
|
||||||
|
|
||||||
error_free:
|
error_free:
|
||||||
free_port(c, p, true);
|
free_port(c, p, true);
|
||||||
|
|
@ -5048,7 +5057,7 @@ SPA_EXPORT
|
||||||
int jack_port_unregister (jack_client_t *client, jack_port_t *port)
|
int jack_port_unregister (jack_client_t *client, jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct client *c = (struct client *) client;
|
struct client *c = (struct client *) client;
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct port *p;
|
struct port *p;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
|
@ -5225,26 +5234,26 @@ static void *get_buffer_input_empty(struct port *p, jack_nframes_t frames)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t frames)
|
void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t frames)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct port *p;
|
struct port *p;
|
||||||
void *ptr;
|
void *ptr = NULL;
|
||||||
|
|
||||||
return_val_if_fail(o != NULL, NULL);
|
return_val_if_fail(o != NULL, NULL);
|
||||||
|
|
||||||
if (o->type != INTERFACE_Port || o->client == NULL)
|
if (o->type != INTERFACE_Port || o->client == NULL)
|
||||||
return NULL;
|
goto done;
|
||||||
|
|
||||||
if ((p = o->port.port) == NULL) {
|
if ((p = o->port.port) == NULL) {
|
||||||
struct mix *mix;
|
struct mix *mix;
|
||||||
struct buffer *b;
|
struct buffer *b;
|
||||||
|
|
||||||
if ((mix = find_mix_peer(o->client, o->id)) == NULL)
|
if ((mix = find_mix_peer(o->client, o->id)) == NULL)
|
||||||
return NULL;
|
goto done;
|
||||||
|
|
||||||
pw_log_trace("peer mix: %p %d", mix, mix->peer_id);
|
pw_log_trace("peer mix: %p %d", mix, mix->peer_id);
|
||||||
|
|
||||||
if ((b = get_mix_buffer(mix, frames)) == NULL)
|
if ((b = get_mix_buffer(mix, frames)) == NULL)
|
||||||
return NULL;
|
goto done;
|
||||||
|
|
||||||
if (o->port.type_id == TYPE_ID_MIDI) {
|
if (o->port.type_id == TYPE_ID_MIDI) {
|
||||||
struct spa_pod_sequence *seq[1];
|
struct spa_pod_sequence *seq[1];
|
||||||
|
|
@ -5257,28 +5266,26 @@ void * jack_port_get_buffer (jack_port_t *port, jack_nframes_t frames)
|
||||||
d = &b->datas[0];
|
d = &b->datas[0];
|
||||||
if ((pod = spa_pod_from_data(d->data, d->maxsize,
|
if ((pod = spa_pod_from_data(d->data, d->maxsize,
|
||||||
d->chunk->offset, d->chunk->size)) == NULL)
|
d->chunk->offset, d->chunk->size)) == NULL)
|
||||||
return NULL;
|
goto done;
|
||||||
if (!spa_pod_is_sequence(pod))
|
if (!spa_pod_is_sequence(pod))
|
||||||
return NULL;
|
goto done;
|
||||||
seq[0] = pod;
|
seq[0] = pod;
|
||||||
convert_to_midi(seq, 1, ptr, o->client->fix_midi_events);
|
convert_to_midi(seq, 1, ptr, o->client->fix_midi_events);
|
||||||
} else {
|
} else {
|
||||||
ptr = get_buffer_data(b, frames);
|
ptr = get_buffer_data(b, frames);
|
||||||
}
|
}
|
||||||
return ptr;
|
} else if (p->valid) {
|
||||||
|
ptr = p->get_buffer(p, frames);
|
||||||
}
|
}
|
||||||
if (!p->valid)
|
done:
|
||||||
return NULL;
|
pw_log_trace_fp("%p: port %p buffer %p: %s", p->client, p, ptr);
|
||||||
|
|
||||||
ptr = p->get_buffer(p, frames);
|
|
||||||
pw_log_trace_fp("%p: port %p buffer %p empty:%u", p->client, p, ptr, p->empty_out);
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
jack_uuid_t jack_port_uuid (const jack_port_t *port)
|
jack_uuid_t jack_port_uuid (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, 0);
|
return_val_if_fail(o != NULL, 0);
|
||||||
return jack_port_uuid_generate(o->serial);
|
return jack_port_uuid_generate(o->serial);
|
||||||
}
|
}
|
||||||
|
|
@ -5299,47 +5306,57 @@ static const char *port_name(struct object *o)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
const char * jack_port_name (const jack_port_t *port)
|
const char * jack_port_name (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, NULL);
|
return_val_if_fail(o != NULL, NULL);
|
||||||
|
if (o->type != INTERFACE_Port)
|
||||||
|
return NULL;
|
||||||
return port_name(o);
|
return port_name(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
const char * jack_port_short_name (const jack_port_t *port)
|
const char * jack_port_short_name (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, NULL);
|
return_val_if_fail(o != NULL, NULL);
|
||||||
|
if (o->type != INTERFACE_Port)
|
||||||
|
return NULL;
|
||||||
return strchr(port_name(o), ':') + 1;
|
return strchr(port_name(o), ':') + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_flags (const jack_port_t *port)
|
int jack_port_flags (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, 0);
|
return_val_if_fail(o != NULL, 0);
|
||||||
|
if (o->type != INTERFACE_Port)
|
||||||
|
return 0;
|
||||||
return o->port.flags;
|
return o->port.flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
const char * jack_port_type (const jack_port_t *port)
|
const char * jack_port_type (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, NULL);
|
return_val_if_fail(o != NULL, NULL);
|
||||||
|
if (o->type != INTERFACE_Port)
|
||||||
|
return NULL;
|
||||||
return type_to_string(o->port.type_id);
|
return type_to_string(o->port.type_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
jack_port_type_id_t jack_port_type_id (const jack_port_t *port)
|
jack_port_type_id_t jack_port_type_id (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, 0);
|
return_val_if_fail(o != NULL, 0);
|
||||||
|
if (o->type != INTERFACE_Port)
|
||||||
|
return TYPE_ID_OTHER;
|
||||||
return o->port.type_id;
|
return o->port.type_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_is_mine (const jack_client_t *client, const jack_port_t *port)
|
int jack_port_is_mine (const jack_client_t *client, const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, 0);
|
return_val_if_fail(o != NULL, 0);
|
||||||
return o->type == INTERFACE_Port &&
|
return o->type == INTERFACE_Port &&
|
||||||
o->port.port != NULL &&
|
o->port.port != NULL &&
|
||||||
|
|
@ -5349,7 +5366,7 @@ int jack_port_is_mine (const jack_client_t *client, const jack_port_t *port)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_connected (const jack_port_t *port)
|
int jack_port_connected (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct object *l;
|
struct object *l;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
@ -5379,7 +5396,7 @@ SPA_EXPORT
|
||||||
int jack_port_connected_to (const jack_port_t *port,
|
int jack_port_connected_to (const jack_port_t *port,
|
||||||
const char *port_name)
|
const char *port_name)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct object *p, *l;
|
struct object *p, *l;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
@ -5419,7 +5436,7 @@ int jack_port_connected_to (const jack_port_t *port,
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
const char ** jack_port_get_connections (const jack_port_t *port)
|
const char ** jack_port_get_connections (const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
|
|
||||||
return_val_if_fail(o != NULL, NULL);
|
return_val_if_fail(o != NULL, NULL);
|
||||||
if (o->type != INTERFACE_Port || o->client == NULL)
|
if (o->type != INTERFACE_Port || o->client == NULL)
|
||||||
|
|
@ -5433,7 +5450,7 @@ const char ** jack_port_get_all_connections (const jack_client_t *client,
|
||||||
const jack_port_t *port)
|
const jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct client *c = (struct client *) client;
|
struct client *c = (struct client *) client;
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct object *p, *l;
|
struct object *p, *l;
|
||||||
const char **res;
|
const char **res;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
@ -5476,8 +5493,8 @@ const char ** jack_port_get_all_connections (const jack_client_t *client,
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_tie (jack_port_t *src, jack_port_t *dst)
|
int jack_port_tie (jack_port_t *src, jack_port_t *dst)
|
||||||
{
|
{
|
||||||
struct object *s = (struct object *) src;
|
struct object *s = port_to_object(src);
|
||||||
struct object *d = (struct object *) dst;
|
struct object *d = port_to_object(dst);
|
||||||
struct port *sp, *dp;
|
struct port *sp, *dp;
|
||||||
|
|
||||||
sp = s->port.port;
|
sp = s->port.port;
|
||||||
|
|
@ -5494,7 +5511,7 @@ int jack_port_tie (jack_port_t *src, jack_port_t *dst)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_untie (jack_port_t *port)
|
int jack_port_untie (jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct port *p;
|
struct port *p;
|
||||||
|
|
||||||
p = o->port.port;
|
p = o->port.port;
|
||||||
|
|
@ -5515,7 +5532,7 @@ SPA_EXPORT
|
||||||
int jack_port_rename (jack_client_t* client, jack_port_t *port, const char *port_name)
|
int jack_port_rename (jack_client_t* client, jack_port_t *port, const char *port_name)
|
||||||
{
|
{
|
||||||
struct client *c = (struct client *) client;
|
struct client *c = (struct client *) client;
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct port *p;
|
struct port *p;
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
|
|
@ -5557,7 +5574,7 @@ done:
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_set_alias (jack_port_t *port, const char *alias)
|
int jack_port_set_alias (jack_port_t *port, const char *alias)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct port *p;
|
struct port *p;
|
||||||
const char *key;
|
const char *key;
|
||||||
|
|
@ -5613,7 +5630,7 @@ done:
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_unset_alias (jack_port_t *port, const char *alias)
|
int jack_port_unset_alias (jack_port_t *port, const char *alias)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
struct port *p;
|
struct port *p;
|
||||||
const char *key;
|
const char *key;
|
||||||
|
|
@ -5664,7 +5681,7 @@ done:
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2])
|
int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2])
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
int res = 0;
|
int res = 0;
|
||||||
|
|
||||||
return_val_if_fail(o != NULL, -EINVAL);
|
return_val_if_fail(o != NULL, -EINVAL);
|
||||||
|
|
@ -5687,7 +5704,7 @@ int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2])
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_request_monitor (jack_port_t *port, int onoff)
|
int jack_port_request_monitor (jack_port_t *port, int onoff)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
|
|
||||||
return_val_if_fail(o != NULL, -EINVAL);
|
return_val_if_fail(o != NULL, -EINVAL);
|
||||||
|
|
||||||
|
|
@ -5718,13 +5735,13 @@ int jack_port_request_monitor_by_name (jack_client_t *client,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return jack_port_request_monitor((jack_port_t*)p, onoff);
|
return jack_port_request_monitor(object_to_port(p), onoff);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_ensure_monitor (jack_port_t *port, int onoff)
|
int jack_port_ensure_monitor (jack_port_t *port, int onoff)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
|
|
||||||
return_val_if_fail(o != NULL, -EINVAL);
|
return_val_if_fail(o != NULL, -EINVAL);
|
||||||
|
|
||||||
|
|
@ -5741,7 +5758,7 @@ int jack_port_ensure_monitor (jack_port_t *port, int onoff)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
int jack_port_monitoring_input (jack_port_t *port)
|
int jack_port_monitoring_input (jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
return_val_if_fail(o != NULL, -EINVAL);
|
return_val_if_fail(o != NULL, -EINVAL);
|
||||||
return o->port.monitor_requests > 0;
|
return o->port.monitor_requests > 0;
|
||||||
}
|
}
|
||||||
|
|
@ -5919,7 +5936,7 @@ SPA_EXPORT
|
||||||
int jack_port_disconnect (jack_client_t *client, jack_port_t *port)
|
int jack_port_disconnect (jack_client_t *client, jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct client *c = (struct client *) client;
|
struct client *c = (struct client *) client;
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct object *l;
|
struct object *l;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
|
@ -5980,7 +5997,7 @@ size_t jack_port_type_get_buffer_size (jack_client_t *client, const char *port_t
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void jack_port_set_latency (jack_port_t *port, jack_nframes_t frames)
|
void jack_port_set_latency (jack_port_t *port, jack_nframes_t frames)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
jack_latency_range_t range = { frames, frames };
|
jack_latency_range_t range = { frames, frames };
|
||||||
|
|
||||||
|
|
@ -6000,17 +6017,20 @@ void jack_port_set_latency (jack_port_t *port, jack_nframes_t frames)
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void jack_port_get_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
|
void jack_port_get_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
jack_nframes_t nframes, rate;
|
jack_nframes_t nframes, rate;
|
||||||
int direction;
|
int direction;
|
||||||
struct spa_latency_info *info;
|
struct spa_latency_info *info;
|
||||||
|
|
||||||
return_if_fail(o != NULL);
|
return_if_fail(o != NULL);
|
||||||
if (o->type != INTERFACE_Port || o->client == NULL)
|
|
||||||
return;
|
|
||||||
c = o->client;
|
c = o->client;
|
||||||
|
|
||||||
|
if (o->type != INTERFACE_Port || c == NULL) {
|
||||||
|
range->min = range->max = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == JackCaptureLatency)
|
if (mode == JackCaptureLatency)
|
||||||
direction = SPA_DIRECTION_OUTPUT;
|
direction = SPA_DIRECTION_OUTPUT;
|
||||||
else
|
else
|
||||||
|
|
@ -6042,7 +6062,7 @@ do_port_check_latency(struct spa_loop *loop,
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
void jack_port_set_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
|
void jack_port_set_latency_range (jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
struct client *c;
|
struct client *c;
|
||||||
enum spa_direction direction;
|
enum spa_direction direction;
|
||||||
struct spa_latency_info latency;
|
struct spa_latency_info latency;
|
||||||
|
|
@ -6095,7 +6115,7 @@ int jack_recompute_total_latencies (jack_client_t *client)
|
||||||
|
|
||||||
static jack_nframes_t port_get_latency (jack_port_t *port)
|
static jack_nframes_t port_get_latency (jack_port_t *port)
|
||||||
{
|
{
|
||||||
struct object *o = (struct object *) port;
|
struct object *o = port_to_object(port);
|
||||||
jack_latency_range_t range = { 0, 0 };
|
jack_latency_range_t range = { 0, 0 };
|
||||||
|
|
||||||
return_val_if_fail(o != NULL, 0);
|
return_val_if_fail(o != NULL, 0);
|
||||||
|
|
@ -6295,7 +6315,7 @@ jack_port_t * jack_port_by_name (jack_client_t *client, const char *port_name)
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
pw_log_info("%p: port \"%s\" not found", c, port_name);
|
pw_log_info("%p: port \"%s\" not found", c, port_name);
|
||||||
|
|
||||||
return (jack_port_t *)res;
|
return object_to_port(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
@ -6317,7 +6337,7 @@ jack_port_t * jack_port_by_id (jack_client_t *client,
|
||||||
if (res == NULL)
|
if (res == NULL)
|
||||||
pw_log_info("%p: port %d not found", c, port_id);
|
pw_log_info("%p: port %d not found", c, port_id);
|
||||||
|
|
||||||
return (jack_port_t *)res;
|
return object_to_port(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPA_EXPORT
|
SPA_EXPORT
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue