mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-29 05:40:27 -04: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 mix *mix;
|
||||
void *data;
|
||||
|
|
@ -5016,7 +5025,7 @@ jack_port_t * jack_port_register (jack_client_t *client,
|
|||
goto error_free;
|
||||
}
|
||||
|
||||
return (jack_port_t *) o;
|
||||
return object_to_port(o);
|
||||
|
||||
error_free:
|
||||
free_port(c, p, true);
|
||||
|
|
@ -5048,7 +5057,7 @@ SPA_EXPORT
|
|||
int jack_port_unregister (jack_client_t *client, jack_port_t *port)
|
||||
{
|
||||
struct client *c = (struct client *) client;
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
struct port *p;
|
||||
int res;
|
||||
|
||||
|
|
@ -5225,26 +5234,26 @@ static void *get_buffer_input_empty(struct port *p, jack_nframes_t frames)
|
|||
SPA_EXPORT
|
||||
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;
|
||||
void *ptr;
|
||||
void *ptr = NULL;
|
||||
|
||||
return_val_if_fail(o != NULL, NULL);
|
||||
|
||||
if (o->type != INTERFACE_Port || o->client == NULL)
|
||||
return NULL;
|
||||
goto done;
|
||||
|
||||
if ((p = o->port.port) == NULL) {
|
||||
struct mix *mix;
|
||||
struct buffer *b;
|
||||
|
||||
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);
|
||||
|
||||
if ((b = get_mix_buffer(mix, frames)) == NULL)
|
||||
return NULL;
|
||||
goto done;
|
||||
|
||||
if (o->port.type_id == TYPE_ID_MIDI) {
|
||||
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];
|
||||
if ((pod = spa_pod_from_data(d->data, d->maxsize,
|
||||
d->chunk->offset, d->chunk->size)) == NULL)
|
||||
return NULL;
|
||||
goto done;
|
||||
if (!spa_pod_is_sequence(pod))
|
||||
return NULL;
|
||||
goto done;
|
||||
seq[0] = pod;
|
||||
convert_to_midi(seq, 1, ptr, o->client->fix_midi_events);
|
||||
} else {
|
||||
ptr = get_buffer_data(b, frames);
|
||||
}
|
||||
return ptr;
|
||||
} else if (p->valid) {
|
||||
ptr = p->get_buffer(p, frames);
|
||||
}
|
||||
if (!p->valid)
|
||||
return NULL;
|
||||
|
||||
ptr = p->get_buffer(p, frames);
|
||||
pw_log_trace_fp("%p: port %p buffer %p empty:%u", p->client, p, ptr, p->empty_out);
|
||||
done:
|
||||
pw_log_trace_fp("%p: port %p buffer %p: %s", p->client, p, ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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 jack_port_uuid_generate(o->serial);
|
||||
}
|
||||
|
|
@ -5299,47 +5306,57 @@ static const char *port_name(struct object *o)
|
|||
SPA_EXPORT
|
||||
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);
|
||||
if (o->type != INTERFACE_Port)
|
||||
return NULL;
|
||||
return port_name(o);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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);
|
||||
if (o->type != INTERFACE_Port)
|
||||
return NULL;
|
||||
return strchr(port_name(o), ':') + 1;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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);
|
||||
if (o->type != INTERFACE_Port)
|
||||
return 0;
|
||||
return o->port.flags;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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);
|
||||
if (o->type != INTERFACE_Port)
|
||||
return NULL;
|
||||
return type_to_string(o->port.type_id);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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);
|
||||
if (o->type != INTERFACE_Port)
|
||||
return TYPE_ID_OTHER;
|
||||
return o->port.type_id;
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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 o->type == INTERFACE_Port &&
|
||||
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
|
||||
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 object *l;
|
||||
int res = 0;
|
||||
|
|
@ -5379,7 +5396,7 @@ SPA_EXPORT
|
|||
int jack_port_connected_to (const jack_port_t *port,
|
||||
const char *port_name)
|
||||
{
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
struct client *c;
|
||||
struct object *p, *l;
|
||||
int res = 0;
|
||||
|
|
@ -5419,7 +5436,7 @@ int jack_port_connected_to (const jack_port_t *port,
|
|||
SPA_EXPORT
|
||||
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);
|
||||
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)
|
||||
{
|
||||
struct client *c = (struct client *) client;
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
struct object *p, *l;
|
||||
const char **res;
|
||||
int count = 0;
|
||||
|
|
@ -5476,8 +5493,8 @@ const char ** jack_port_get_all_connections (const jack_client_t *client,
|
|||
SPA_EXPORT
|
||||
int jack_port_tie (jack_port_t *src, jack_port_t *dst)
|
||||
{
|
||||
struct object *s = (struct object *) src;
|
||||
struct object *d = (struct object *) dst;
|
||||
struct object *s = port_to_object(src);
|
||||
struct object *d = port_to_object(dst);
|
||||
struct port *sp, *dp;
|
||||
|
||||
sp = s->port.port;
|
||||
|
|
@ -5494,7 +5511,7 @@ int jack_port_tie (jack_port_t *src, jack_port_t *dst)
|
|||
SPA_EXPORT
|
||||
int jack_port_untie (jack_port_t *port)
|
||||
{
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
struct port *p;
|
||||
|
||||
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)
|
||||
{
|
||||
struct client *c = (struct client *) client;
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
struct port *p;
|
||||
int res = 0;
|
||||
|
||||
|
|
@ -5557,7 +5574,7 @@ done:
|
|||
SPA_EXPORT
|
||||
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 port *p;
|
||||
const char *key;
|
||||
|
|
@ -5613,7 +5630,7 @@ done:
|
|||
SPA_EXPORT
|
||||
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 port *p;
|
||||
const char *key;
|
||||
|
|
@ -5664,7 +5681,7 @@ done:
|
|||
SPA_EXPORT
|
||||
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;
|
||||
|
||||
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
|
||||
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);
|
||||
|
||||
|
|
@ -5718,13 +5735,13 @@ int jack_port_request_monitor_by_name (jack_client_t *client,
|
|||
return -1;
|
||||
}
|
||||
|
||||
return jack_port_request_monitor((jack_port_t*)p, onoff);
|
||||
return jack_port_request_monitor(object_to_port(p), onoff);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
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);
|
||||
|
||||
|
|
@ -5741,7 +5758,7 @@ int jack_port_ensure_monitor (jack_port_t *port, int onoff)
|
|||
SPA_EXPORT
|
||||
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 o->port.monitor_requests > 0;
|
||||
}
|
||||
|
|
@ -5919,7 +5936,7 @@ SPA_EXPORT
|
|||
int jack_port_disconnect (jack_client_t *client, jack_port_t *port)
|
||||
{
|
||||
struct client *c = (struct client *) client;
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
struct object *l;
|
||||
int res;
|
||||
|
||||
|
|
@ -5980,7 +5997,7 @@ size_t jack_port_type_get_buffer_size (jack_client_t *client, const char *port_t
|
|||
SPA_EXPORT
|
||||
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;
|
||||
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
|
||||
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;
|
||||
jack_nframes_t nframes, rate;
|
||||
int direction;
|
||||
struct spa_latency_info *info;
|
||||
|
||||
return_if_fail(o != NULL);
|
||||
if (o->type != INTERFACE_Port || o->client == NULL)
|
||||
return;
|
||||
c = o->client;
|
||||
|
||||
if (o->type != INTERFACE_Port || c == NULL) {
|
||||
range->min = range->max = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (mode == JackCaptureLatency)
|
||||
direction = SPA_DIRECTION_OUTPUT;
|
||||
else
|
||||
|
|
@ -6042,7 +6062,7 @@ do_port_check_latency(struct spa_loop *loop,
|
|||
SPA_EXPORT
|
||||
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;
|
||||
enum spa_direction direction;
|
||||
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)
|
||||
{
|
||||
struct object *o = (struct object *) port;
|
||||
struct object *o = port_to_object(port);
|
||||
jack_latency_range_t range = { 0, 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)
|
||||
pw_log_info("%p: port \"%s\" not found", c, port_name);
|
||||
|
||||
return (jack_port_t *)res;
|
||||
return object_to_port(res);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
@ -6317,7 +6337,7 @@ jack_port_t * jack_port_by_id (jack_client_t *client,
|
|||
if (res == NULL)
|
||||
pw_log_info("%p: port %d not found", c, port_id);
|
||||
|
||||
return (jack_port_t *)res;
|
||||
return object_to_port(res);
|
||||
}
|
||||
|
||||
SPA_EXPORT
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue