Skip to content

Commit

Permalink
spa: use static inline for interfaces instead of macro
Browse files Browse the repository at this point in the history
It gives better typechecking and a path to make a library of functions.
  • Loading branch information
wtay committed Nov 26, 2024
1 parent 5e0e120 commit 84bd4b7
Show file tree
Hide file tree
Showing 32 changed files with 1,087 additions and 581 deletions.
75 changes: 53 additions & 22 deletions spa/include/spa/filter-graph/filter-graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,59 @@ struct spa_filter_graph_methods {
struct spa_filter_graph_chunk out[], uint32_t n_out);
};

#define spa_filter_graph_method_r(o,method,version,...) \
({ \
volatile int _res = -ENOTSUP; \
struct spa_filter_graph *_o = o; \
spa_interface_call_fast_res(&_o->iface, \
struct spa_filter_graph_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})

#define spa_filter_graph_add_listener(o,...) spa_filter_graph_method_r(o,add_listener,0,__VA_ARGS__)

#define spa_filter_graph_enum_prop_info(o,...) spa_filter_graph_method_r(o,enum_prop_info,0,__VA_ARGS__)
#define spa_filter_graph_get_props(o,...) spa_filter_graph_method_r(o,get_props,0,__VA_ARGS__)
#define spa_filter_graph_set_props(o,...) spa_filter_graph_method_r(o,set_props,0,__VA_ARGS__)

#define spa_filter_graph_activate(o,...) spa_filter_graph_method_r(o,activate,0,__VA_ARGS__)
#define spa_filter_graph_deactivate(o) spa_filter_graph_method_r(o,deactivate,0)

#define spa_filter_graph_reset(o) spa_filter_graph_method_r(o,reset,0)

#define spa_filter_graph_process(o,...) spa_filter_graph_method_r(o,process,0,__VA_ARGS__)
static inline int spa_filter_graph_add_listener(struct spa_filter_graph *object,
struct spa_hook *listener,
const struct spa_filter_graph_events *events, void *data)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, add_listener, 0, listener,
events, data);
}

static inline int spa_filter_graph_enum_prop_info(struct spa_filter_graph *object,
uint32_t idx, struct spa_pod_builder *b)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, enum_prop_info, 0, idx, b);
}
static inline int spa_filter_graph_get_props(struct spa_filter_graph *object,
struct spa_pod_builder *b, const struct spa_pod **props)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, get_props, 0, b, props);
}

static inline int spa_filter_graph_set_props(struct spa_filter_graph *object,
enum spa_direction direction, const struct spa_pod *props)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, set_props, 0, direction, props);
}

static inline int spa_filter_graph_activate(struct spa_filter_graph *object, const struct spa_fraction *rate)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, activate, 0, rate);
}
static inline int spa_filter_graph_deactivate(struct spa_filter_graph *object)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, deactivate, 0);
}

static inline int spa_filter_graph_reset(struct spa_filter_graph *object)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, reset, 0);
}

static inline int spa_filter_graph_process(struct spa_filter_graph *object,
const struct spa_filter_graph_chunk in[], uint32_t n_in,
struct spa_filter_graph_chunk out[], uint32_t n_out)
{
return spa_api_method_r(int, -ENOTSUP,
spa_filter_graph, &object->iface, process, 0, in, n_in, out, n_out);
}

/**
* \}
Expand Down
83 changes: 63 additions & 20 deletions spa/include/spa/interfaces/audio/aec.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,69 @@ struct spa_audio_aec_methods {
struct spa_audio_info_raw *out_info);
};

#define spa_audio_aec_method(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_audio_aec *_o = (o); \
spa_interface_call_res(&_o->iface, \
struct spa_audio_aec_methods, _res, \
method, (version), ##__VA_ARGS__); \
_res; \
})

#define spa_audio_aec_add_listener(o,...) spa_audio_aec_method(o, add_listener, 0, __VA_ARGS__)
#define spa_audio_aec_init(o,...) spa_audio_aec_method(o, init, 0, __VA_ARGS__)
#define spa_audio_aec_run(o,...) spa_audio_aec_method(o, run, 0, __VA_ARGS__)
#define spa_audio_aec_set_props(o,...) spa_audio_aec_method(o, set_props, 0, __VA_ARGS__)
#define spa_audio_aec_activate(o) spa_audio_aec_method(o, activate, 1)
#define spa_audio_aec_deactivate(o) spa_audio_aec_method(o, deactivate, 1)
#define spa_audio_aec_enum_props(o,...) spa_audio_aec_method(o, enum_props, 2, __VA_ARGS__)
#define spa_audio_aec_get_params(o,...) spa_audio_aec_method(o, get_params, 2, __VA_ARGS__)
#define spa_audio_aec_set_params(o,...) spa_audio_aec_method(o, set_params, 2, __VA_ARGS__)
#define spa_audio_aec_init2(o,...) spa_audio_aec_method(o, init2, 3, __VA_ARGS__)
static inline int spa_audio_aec_add_listener(struct spa_audio_aec *object,
struct spa_hook *listener,
const struct spa_audio_aec_events *events,
void *data)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, add_listener, 0, listener, events, data);
}

static inline int spa_audio_aec_init(struct spa_audio_aec *object,
const struct spa_dict *args, const struct spa_audio_info_raw *info)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, init, 0, args, info);
}
static inline int spa_audio_aec_run(struct spa_audio_aec *object,
const float *rec[], const float *play[], float *out[], uint32_t n_samples)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, run, 0, rec, play, out, n_samples);
}
static inline int spa_audio_aec_set_props(struct spa_audio_aec *object, const struct spa_dict *args)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, set_props, 0, args);
}
static inline int spa_audio_aec_activate(struct spa_audio_aec *object)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, activate, 1);
}
static inline int spa_audio_aec_deactivate(struct spa_audio_aec *object)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, deactivate, 1);
}
static inline int spa_audio_aec_enum_props(struct spa_audio_aec *object,
int index, struct spa_pod_builder* builder)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, enum_props, 2, index, builder);
}
static inline int spa_audio_aec_get_params(struct spa_audio_aec *object,
struct spa_pod_builder* builder)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, get_params, 2, builder);
}
static inline int spa_audio_aec_set_params(struct spa_audio_aec *object,
const struct spa_pod *args)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, set_params, 2, args);
}
static inline int spa_audio_aec_init2(struct spa_audio_aec *object,
const struct spa_dict *args,
struct spa_audio_info_raw *play_info,
struct spa_audio_info_raw *rec_info,
struct spa_audio_info_raw *out_info)
{
return spa_api_method_r(int, -ENOTSUP,
spa_audio_aec, &object->iface, init2, 3, args, play_info, rec_info, out_info);
}

#ifdef __cplusplus
} /* extern "C" */
Expand Down
42 changes: 28 additions & 14 deletions spa/include/spa/monitor/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,20 +220,34 @@ struct spa_device_methods {
const struct spa_pod *param);
};

#define spa_device_method(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_device *_o = (o); \
spa_interface_call_res(&_o->iface, \
struct spa_device_methods, _res, \
method, (version), ##__VA_ARGS__); \
_res; \
})

#define spa_device_add_listener(d,...) spa_device_method(d, add_listener, 0, __VA_ARGS__)
#define spa_device_sync(d,...) spa_device_method(d, sync, 0, __VA_ARGS__)
#define spa_device_enum_params(d,...) spa_device_method(d, enum_params, 0, __VA_ARGS__)
#define spa_device_set_param(d,...) spa_device_method(d, set_param, 0, __VA_ARGS__)
static inline int spa_device_add_listener(struct spa_device *object,
struct spa_hook *listener,
const struct spa_device_events *events,
void *data)
{
return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, add_listener, 0,
listener, events, data);

}
static inline int spa_device_sync(struct spa_device *object, int seq)
{
return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, sync, 0,
seq);
}
static inline int spa_device_enum_params(struct spa_device *object, int seq,
uint32_t id, uint32_t index, uint32_t max,
const struct spa_pod *filter)
{
return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, enum_params, 0,
seq, id, index, max, filter);
}
static inline int spa_device_set_param(struct spa_device *object,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return spa_api_method_r(int, -ENOTSUP, spa_device, &object->iface, set_param, 0,
id, flags, param);
}

#define SPA_KEY_DEVICE_ENUM_API "device.enum.api" /**< the api used to discover this
* device */
Expand Down
152 changes: 114 additions & 38 deletions spa/include/spa/node/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,44 +633,120 @@ struct spa_node_methods {
int (*process) (void *object);
};

#define spa_node_method(o,method,version,...) \
({ \
int _res = -ENOTSUP; \
struct spa_node *_n = o; \
spa_interface_call_res(&_n->iface, \
struct spa_node_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})

#define spa_node_method_fast(o,method,version,...) \
({ \
int _res; \
struct spa_node *_n = o; \
spa_interface_call_fast_res(&_n->iface, \
struct spa_node_methods, _res, \
method, version, ##__VA_ARGS__); \
_res; \
})

#define spa_node_add_listener(n,...) spa_node_method(n, add_listener, 0, __VA_ARGS__)
#define spa_node_set_callbacks(n,...) spa_node_method(n, set_callbacks, 0, __VA_ARGS__)
#define spa_node_sync(n,...) spa_node_method(n, sync, 0, __VA_ARGS__)
#define spa_node_enum_params(n,...) spa_node_method(n, enum_params, 0, __VA_ARGS__)
#define spa_node_set_param(n,...) spa_node_method(n, set_param, 0, __VA_ARGS__)
#define spa_node_set_io(n,...) spa_node_method(n, set_io, 0, __VA_ARGS__)
#define spa_node_send_command(n,...) spa_node_method(n, send_command, 0, __VA_ARGS__)
#define spa_node_add_port(n,...) spa_node_method(n, add_port, 0, __VA_ARGS__)
#define spa_node_remove_port(n,...) spa_node_method(n, remove_port, 0, __VA_ARGS__)
#define spa_node_port_enum_params(n,...) spa_node_method(n, port_enum_params, 0, __VA_ARGS__)
#define spa_node_port_set_param(n,...) spa_node_method(n, port_set_param, 0, __VA_ARGS__)
#define spa_node_port_use_buffers(n,...) spa_node_method(n, port_use_buffers, 0, __VA_ARGS__)
#define spa_node_port_set_io(n,...) spa_node_method(n, port_set_io, 0, __VA_ARGS__)

#define spa_node_port_reuse_buffer(n,...) spa_node_method(n, port_reuse_buffer, 0, __VA_ARGS__)
#define spa_node_port_reuse_buffer_fast(n,...) spa_node_method_fast(n, port_reuse_buffer, 0, __VA_ARGS__)
#define spa_node_process(n) spa_node_method(n, process, 0)
#define spa_node_process_fast(n) spa_node_method_fast(n, process, 0)

static inline int spa_node_add_listener(struct spa_node *object,
struct spa_hook *listener,
const struct spa_node_events *events,
void *data)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, add_listener, 0,
listener, events, data);
}
static inline int spa_node_set_callbacks(struct spa_node *object,
const struct spa_node_callbacks *callbacks,
void *data)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_callbacks, 0,
callbacks, data);
}
static inline int spa_node_sync(struct spa_node *object, int seq)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, sync, 0,
seq);
}
static inline int spa_node_enum_params(struct spa_node *object, int seq,
uint32_t id, uint32_t start, uint32_t max,
const struct spa_pod *filter)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, enum_params, 0,
seq, id, start, max, filter);
}
static inline int spa_node_set_param(struct spa_node *object,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_param, 0,
id, flags, param);
}
static inline int spa_node_set_io(struct spa_node *object,
uint32_t id, void *data, size_t size)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, set_io, 0,
id, data, size);
}
static inline int spa_node_send_command(struct spa_node *object,
const struct spa_command *command)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, send_command, 0,
command);
}
static inline int spa_node_add_port(struct spa_node *object,
enum spa_direction direction, uint32_t port_id,
const struct spa_dict *props)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, add_port, 0,
direction, port_id, props);
}
static inline int spa_node_remove_port(struct spa_node *object,
enum spa_direction direction, uint32_t port_id)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, remove_port, 0,
direction, port_id);
}
static inline int spa_node_port_enum_params(struct spa_node *object, int seq,
enum spa_direction direction, uint32_t port_id,
uint32_t id, uint32_t start, uint32_t max,
const struct spa_pod *filter)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_enum_params, 0,
seq, direction, port_id, id, start, max, filter);
}
static inline int spa_node_port_set_param(struct spa_node *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_set_param, 0,
direction, port_id, id, flags, param);
}
static inline int spa_node_port_use_buffers(struct spa_node *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_use_buffers, 0,
direction, port_id, flags, buffers, n_buffers);
}
static inline int spa_node_port_set_io(struct spa_node *object,
enum spa_direction direction,
uint32_t port_id,
uint32_t id, void *data, size_t size)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_set_io, 0,
direction, port_id, id, data, size);
}

static inline int spa_node_port_reuse_buffer(struct spa_node *object, uint32_t port_id, uint32_t buffer_id)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, port_reuse_buffer, 0,
port_id, buffer_id);
}
static inline int spa_node_port_reuse_buffer_fast(struct spa_node *object, uint32_t port_id, uint32_t buffer_id)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_node, &object->iface, port_reuse_buffer, 0,
port_id, buffer_id);
}
static inline int spa_node_process(struct spa_node *object)
{
return spa_api_method_r(int, -ENOTSUP, spa_node, &object->iface, process, 0);
}
static inline int spa_node_process_fast(struct spa_node *object)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_node, &object->iface, process, 0);
}

/**
* \}
Expand Down
Loading

0 comments on commit 84bd4b7

Please sign in to comment.