spa: don't use typedef for struct and enum

This commit is contained in:
Wim Taymans 2017-05-25 13:28:15 +02:00
parent 83964cec87
commit 11f23a3ffa
163 changed files with 6510 additions and 8264 deletions

View file

@ -34,11 +34,13 @@
#include <spa/format-builder.h>
#include <lib/props.h>
#define IMPL_NAME "audiotestsrc"
#define SAMPLES_TO_TIME(this,s) ((s) * SPA_NSEC_PER_SEC / (this)->current_format.info.raw.rate)
#define BYTES_TO_SAMPLES(this,b) ((b)/(this)->bpf)
#define BYTES_TO_TIME(this,b) SAMPLES_TO_TIME(this, BYTES_TO_SAMPLES (this, b))
typedef struct {
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
@ -49,20 +51,20 @@ typedef struct {
uint32_t prop_volume;
uint32_t wave_sine;
uint32_t wave_square;
SpaTypeMeta meta;
SpaTypeData data;
SpaTypeMediaType media_type;
SpaTypeMediaSubtype media_subtype;
SpaTypeFormatAudio format_audio;
SpaTypeAudioFormat audio_format;
SpaTypeEventNode event_node;
SpaTypeCommandNode command_node;
SpaTypeParamAllocBuffers param_alloc_buffers;
SpaTypeParamAllocMetaEnable param_alloc_meta_enable;
} Type;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_media_type media_type;
struct spa_type_media_subtype media_subtype;
struct spa_type_format_audio format_audio;
struct spa_type_audio_format audio_format;
struct spa_type_event_node event_node;
struct spa_type_command_node command_node;
struct spa_type_param_alloc_buffers param_alloc_buffers;
struct spa_type_param_alloc_meta_enable param_alloc_meta_enable;
};
static inline void
init_type (Type *type, SpaTypeMap *map)
init_type (struct type *type, struct spa_type_map *map)
{
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
type->clock = spa_type_map_get_id (map, SPA_TYPE__Clock);
@ -86,61 +88,59 @@ init_type (Type *type, SpaTypeMap *map)
spa_type_param_alloc_meta_enable_map (map, &type->param_alloc_meta_enable);
}
typedef struct _SpaAudioTestSrc SpaAudioTestSrc;
typedef struct {
struct props {
bool live;
uint32_t wave;
double freq;
double volume;
} SpaAudioTestSrcProps;
};
#define MAX_BUFFERS 16
typedef struct _ATSBuffer ATSBuffer;
struct _ATSBuffer {
SpaBuffer *outbuf;
struct buffer {
struct spa_buffer *outbuf;
bool outstanding;
SpaMetaHeader *h;
SpaMetaRingbuffer *rb;
SpaList link;
struct spa_meta_header *h;
struct spa_meta_ringbuffer *rb;
struct spa_list link;
};
typedef SpaResult (*RenderFunc) (SpaAudioTestSrc *this, void *samples, size_t n_samples);
struct impl;
struct _SpaAudioTestSrc {
SpaHandle handle;
SpaNode node;
SpaClock clock;
typedef int (*render_func_t) (struct impl *this, void *samples, size_t n_samples);
Type type;
SpaTypeMap *map;
SpaLog *log;
SpaLoop *data_loop;
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
struct type type;
struct spa_type_map *map;
struct spa_log *log;
struct spa_loop *data_loop;
uint8_t props_buffer[512];
SpaAudioTestSrcProps props;
struct props props;
SpaNodeCallbacks callbacks;
struct spa_node_callbacks callbacks;
void *user_data;
SpaSource timer_source;
struct spa_source timer_source;
struct itimerspec timerspec;
SpaPortInfo info;
struct spa_port_info info;
uint32_t params[2];
uint8_t params_buffer[1024];
SpaPortIO *io;
struct spa_port_io *io;
bool have_format;
SpaAudioInfo current_format;
struct spa_audio_info current_format;
uint8_t format_buffer[1024];
size_t bpf;
RenderFunc render_func;
render_func_t render_func;
double accumulator;
ATSBuffer buffers[MAX_BUFFERS];
struct buffer buffers[MAX_BUFFERS];
uint32_t n_buffers;
bool started;
@ -148,7 +148,7 @@ struct _SpaAudioTestSrc {
uint64_t elapsed_time;
uint64_t sample_count;
SpaList empty;
struct spa_list empty;
};
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
@ -159,7 +159,7 @@ struct _SpaAudioTestSrc {
#define DEFAULT_VOLUME 1.0
static void
reset_audiotestsrc_props (SpaAudioTestSrc *this, SpaAudioTestSrcProps *props)
impl_reset_props (struct impl *this, struct props *props)
{
props->live = DEFAULT_LIVE;
props->wave = this->type. DEFAULT_WAVE;
@ -180,18 +180,18 @@ reset_audiotestsrc_props (SpaAudioTestSrc *this, SpaAudioTestSrcProps *props)
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
static SpaResult
spa_audiotestsrc_node_get_props (SpaNode *node,
SpaProps **props)
static int
impl_node_get_props (struct spa_node *node,
struct spa_props **props)
{
SpaAudioTestSrc *this;
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
struct impl *this;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (props != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
spa_pod_builder_props (&b, &f[0], this->type.props,
@ -204,23 +204,23 @@ spa_audiotestsrc_node_get_props (SpaNode *node,
PROP_MM (&f[1], this->type.prop_volume, SPA_POD_TYPE_DOUBLE, this->props.volume,
0.0, 10.0));
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_props);
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_set_props (SpaNode *node,
const SpaProps *props)
static int
impl_node_set_props (struct spa_node *node,
const struct spa_props *props)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
if (props == NULL) {
reset_audiotestsrc_props (this, &this->props);
impl_reset_props (this, &this->props);
} else {
spa_props_query (props,
this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live,
@ -238,8 +238,8 @@ spa_audiotestsrc_node_set_props (SpaNode *node,
return SPA_RESULT_OK;
}
static inline SpaResult
send_have_output (SpaAudioTestSrc *this)
static inline int
send_have_output (struct impl *this)
{
if (this->callbacks.have_output)
this->callbacks.have_output (&this->node, this->user_data);
@ -249,7 +249,7 @@ send_have_output (SpaAudioTestSrc *this)
#include "render.c"
static void
set_timer (SpaAudioTestSrc *this, bool enabled)
set_timer (struct impl *this, bool enabled)
{
if (this->callbacks.have_output || this->props.live) {
if (enabled) {
@ -270,7 +270,7 @@ set_timer (SpaAudioTestSrc *this, bool enabled)
}
static void
read_timer (SpaAudioTestSrc *this)
read_timer (struct impl *this)
{
uint64_t expirations;
@ -280,11 +280,11 @@ read_timer (SpaAudioTestSrc *this)
}
}
static SpaResult
audiotestsrc_make_buffer (SpaAudioTestSrc *this)
static int
make_buffer (struct impl *this)
{
ATSBuffer *b;
SpaPortIO *io = this->io;
struct buffer *b;
struct spa_port_io *io = this->io;
int n_bytes, n_samples;
read_timer (this);
@ -293,7 +293,7 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this)
set_timer (this, false);
return SPA_RESULT_OUT_OF_BUFFERS;
}
b = spa_list_first (&this->empty, ATSBuffer, link);
b = spa_list_first (&this->empty, struct buffer, link);
spa_list_remove (&b->link);
b->outstanding = true;
@ -304,7 +304,7 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this)
n_bytes = io->range.max_size;
}
spa_log_trace (this->log, "audiotestsrc %p: dequeue buffer %d %d %d", this, b->outbuf->id,
spa_log_trace (this->log, IMPL_NAME " %p: dequeue buffer %d %d %d", this, b->outbuf->id,
b->outbuf->datas[0].maxsize, n_bytes);
if (b->rb) {
@ -348,31 +348,31 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this)
io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_HAVE_BUFFER;
return SPA_RESULT_HAVE_BUFFER;
return io->status;
}
static void
audiotestsrc_on_output (SpaSource *source)
on_output (struct spa_source *source)
{
SpaAudioTestSrc *this = source->data;
SpaResult res;
struct impl *this = source->data;
int res;
res = audiotestsrc_make_buffer (this);
res = make_buffer (this);
if (res == SPA_RESULT_HAVE_BUFFER)
send_have_output (this);
}
static SpaResult
spa_audiotestsrc_node_send_command (SpaNode *node,
SpaCommand *command)
static int
impl_node_send_command (struct spa_node *node,
struct spa_command *command)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
struct timespec now;
@ -416,17 +416,17 @@ spa_audiotestsrc_node_send_command (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_set_callbacks (SpaNode *node,
const SpaNodeCallbacks *callbacks,
static int
impl_node_set_callbacks (struct spa_node *node,
const struct spa_node_callbacks *callbacks,
size_t callbacks_size,
void *user_data)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
if (this->data_loop == NULL && callbacks->have_output) {
spa_log_error (this->log, "a data_loop is needed for async operation");
@ -439,8 +439,8 @@ spa_audiotestsrc_node_set_callbacks (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_get_n_ports (SpaNode *node,
static int
impl_node_get_n_ports (struct spa_node *node,
uint32_t *n_input_ports,
uint32_t *max_input_ports,
uint32_t *n_output_ports,
@ -460,8 +460,8 @@ spa_audiotestsrc_node_get_n_ports (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_get_port_ids (SpaNode *node,
static int
impl_node_get_port_ids (struct spa_node *node,
uint32_t n_input_ports,
uint32_t *input_ids,
uint32_t n_output_ports,
@ -475,42 +475,42 @@ spa_audiotestsrc_node_get_port_ids (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_add_port (SpaNode *node,
SpaDirection direction,
static int
impl_node_add_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_node_remove_port (SpaNode *node,
SpaDirection direction,
static int
impl_node_remove_port (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
SpaDirection direction,
static int
impl_node_port_enum_formats (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
SpaFormat **format,
const SpaFormat *filter,
struct spa_format **format,
const struct spa_format *filter,
uint32_t index)
{
SpaAudioTestSrc *this;
SpaResult res;
SpaFormat *fmt;
struct impl *this;
int res;
struct spa_format *fmt;
uint8_t buffer[256];
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2];
uint32_t count, match;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -534,23 +534,23 @@ next:
default:
return SPA_RESULT_ENUM_END;
}
fmt = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat);
fmt = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_format);
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
goto next;
*format = SPA_POD_BUILDER_DEREF (&b, 0, SpaFormat);
*format = SPA_POD_BUILDER_DEREF (&b, 0, struct spa_format);
return SPA_RESULT_OK;
}
static SpaResult
clear_buffers (SpaAudioTestSrc *this)
static int
clear_buffers (struct impl *this)
{
if (this->n_buffers > 0) {
spa_log_info (this->log, "audiotestsrc %p: clear buffers", this);
spa_log_info (this->log, IMPL_NAME " %p: clear buffers", this);
this->n_buffers = 0;
spa_list_init (&this->empty);
this->started = false;
@ -559,18 +559,18 @@ clear_buffers (SpaAudioTestSrc *this)
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_set_format (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
uint32_t flags,
const SpaFormat *format)
static int
impl_node_port_set_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t flags,
const struct spa_format *format)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -578,8 +578,8 @@ spa_audiotestsrc_node_port_set_format (SpaNode *node,
this->have_format = false;
clear_buffers (this);
} else {
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
SPA_FORMAT_MEDIA_SUBTYPE (format), };
struct spa_audio_info info = { SPA_FORMAT_MEDIA_TYPE (format),
SPA_FORMAT_MEDIA_SUBTYPE (format), };
int idx;
int sizes[4] = { 2, 4, 4, 8 };
@ -614,20 +614,20 @@ spa_audiotestsrc_node_port_set_format (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_get_format (SpaNode *node,
SpaDirection direction,
static int
impl_node_port_get_format (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const SpaFormat **format)
const struct spa_format **format)
{
SpaAudioTestSrc *this;
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
struct impl *this;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -641,23 +641,23 @@ spa_audiotestsrc_node_port_get_format (SpaNode *node,
PROP (&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT, this->current_format.info.raw.rate),
PROP (&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT, this->current_format.info.raw.channels));
*format = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat);
*format = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_format);
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_get_info (SpaNode *node,
SpaDirection direction,
static int
impl_node_port_get_info (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const SpaPortInfo **info)
const struct spa_port_info **info)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -666,21 +666,21 @@ spa_audiotestsrc_node_port_get_info (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_enum_params (SpaNode *node,
SpaDirection direction,
static int
impl_node_port_enum_params (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t index,
SpaParam **param)
struct spa_param **param)
{
SpaAudioTestSrc *this;
SpaPODBuilder b = { NULL, };
SpaPODFrame f[2];
struct impl *this;
struct spa_pod_builder b = { NULL, };
struct spa_pod_frame f[2];
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -698,40 +698,40 @@ spa_audiotestsrc_node_port_enum_params (SpaNode *node,
case 1:
spa_pod_builder_object (&b, &f[0], 0, this->type.param_alloc_meta_enable.MetaEnable,
PROP (&f[1], this->type.param_alloc_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header),
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader)));
PROP (&f[1], this->type.param_alloc_meta_enable.size, SPA_POD_TYPE_INT, sizeof (struct spa_meta_header)));
break;
default:
return SPA_RESULT_NOT_IMPLEMENTED;
}
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaParam);
*param = SPA_POD_BUILDER_DEREF (&b, f[0].ref, struct spa_param);
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_set_param (SpaNode *node,
SpaDirection direction,
static int
impl_node_port_set_param (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
const SpaParam *param)
const struct spa_param *param)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaBuffer **buffers,
uint32_t n_buffers)
static int
impl_node_port_use_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_buffer **buffers,
uint32_t n_buffers)
{
SpaAudioTestSrc *this;
struct impl *this;
uint32_t i;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -741,8 +741,8 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
clear_buffers (this);
for (i = 0; i < n_buffers; i++) {
ATSBuffer *b;
SpaData *d = buffers[i]->datas;
struct buffer *b;
struct spa_data *d = buffers[i]->datas;
b = &this->buffers[i];
b->outbuf = buffers[i];
@ -754,7 +754,7 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
d[0].type == this->type.data.MemFd ||
d[0].type == this->type.data.DmaBuf) &&
d[0].data == NULL) {
spa_log_error (this->log, "audiotestsrc %p: invalid memory on buffer %p", this, buffers[i]);
spa_log_error (this->log, IMPL_NAME " %p: invalid memory on buffer %p", this, buffers[i]);
}
spa_list_insert (this->empty.prev, &b->link);
}
@ -763,20 +763,20 @@ spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaParam **params,
uint32_t n_params,
SpaBuffer **buffers,
uint32_t *n_buffers)
static int
impl_node_port_alloc_buffers (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_param **params,
uint32_t n_params,
struct spa_buffer **buffers,
uint32_t *n_buffers)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -786,17 +786,17 @@ spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_node_port_set_io (SpaNode *node,
SpaDirection direction,
static int
impl_node_port_set_io (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
SpaPortIO *io)
struct spa_port_io *io)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
@ -806,12 +806,12 @@ spa_audiotestsrc_node_port_set_io (SpaNode *node,
}
static inline void
reuse_buffer (SpaAudioTestSrc *this, uint32_t id)
reuse_buffer (struct impl *this, uint32_t id)
{
ATSBuffer *b = &this->buffers[id];
struct buffer *b = &this->buffers[id];
spa_return_if_fail (b->outstanding);
spa_log_trace (this->log, "audiotestsrc %p: reuse buffer %d", this, id);
spa_log_trace (this->log, IMPL_NAME " %p: reuse buffer %d", this, id);
b->outstanding = false;
spa_list_insert (this->empty.prev, &b->link);
@ -820,16 +820,16 @@ reuse_buffer (SpaAudioTestSrc *this, uint32_t id)
set_timer (this, true);
}
static SpaResult
spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
static int
impl_node_port_reuse_buffer (struct spa_node *node,
uint32_t port_id,
uint32_t buffer_id)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
spa_return_val_if_fail (port_id == 0, SPA_RESULT_INVALID_PORT);
spa_return_val_if_fail (this->n_buffers > 0, SPA_RESULT_NO_BUFFERS);
@ -840,30 +840,30 @@ spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
return SPA_RESULT_OK;
}
static SpaResult
spa_audiotestsrc_node_port_send_command (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaCommand *command)
static int
impl_node_port_send_command (struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
struct spa_command *command)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_node_process_input (SpaNode *node)
static int
impl_node_process_input (struct spa_node *node)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_node_process_output (SpaNode *node)
static int
impl_node_process_output (struct spa_node *node)
{
SpaAudioTestSrc *this;
SpaPortIO *io;
struct impl *this;
struct spa_port_io *io;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
this = SPA_CONTAINER_OF (node, struct impl, node);
io = this->io;
spa_return_val_if_fail (io != NULL, SPA_RESULT_WRONG_STATE);
@ -876,53 +876,53 @@ spa_audiotestsrc_node_process_output (SpaNode *node)
}
if (!this->callbacks.have_output && (io->status == SPA_RESULT_NEED_BUFFER))
return audiotestsrc_make_buffer (this);
return make_buffer (this);
else
return SPA_RESULT_OK;
}
static const SpaNode audiotestsrc_node = {
sizeof (SpaNode),
static const struct spa_node impl_node = {
sizeof (struct spa_node),
NULL,
spa_audiotestsrc_node_get_props,
spa_audiotestsrc_node_set_props,
spa_audiotestsrc_node_send_command,
spa_audiotestsrc_node_set_callbacks,
spa_audiotestsrc_node_get_n_ports,
spa_audiotestsrc_node_get_port_ids,
spa_audiotestsrc_node_add_port,
spa_audiotestsrc_node_remove_port,
spa_audiotestsrc_node_port_enum_formats,
spa_audiotestsrc_node_port_set_format,
spa_audiotestsrc_node_port_get_format,
spa_audiotestsrc_node_port_get_info,
spa_audiotestsrc_node_port_enum_params,
spa_audiotestsrc_node_port_set_param,
spa_audiotestsrc_node_port_use_buffers,
spa_audiotestsrc_node_port_alloc_buffers,
spa_audiotestsrc_node_port_set_io,
spa_audiotestsrc_node_port_reuse_buffer,
spa_audiotestsrc_node_port_send_command,
spa_audiotestsrc_node_process_input,
spa_audiotestsrc_node_process_output,
impl_node_get_props,
impl_node_set_props,
impl_node_send_command,
impl_node_set_callbacks,
impl_node_get_n_ports,
impl_node_get_port_ids,
impl_node_add_port,
impl_node_remove_port,
impl_node_port_enum_formats,
impl_node_port_set_format,
impl_node_port_get_format,
impl_node_port_get_info,
impl_node_port_enum_params,
impl_node_port_set_param,
impl_node_port_use_buffers,
impl_node_port_alloc_buffers,
impl_node_port_set_io,
impl_node_port_reuse_buffer,
impl_node_port_send_command,
impl_node_process_input,
impl_node_process_output,
};
static SpaResult
spa_audiotestsrc_clock_get_props (SpaClock *clock,
SpaProps **props)
static int
impl_clock_get_props (struct spa_clock *clock,
struct spa_props **props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_clock_set_props (SpaClock *clock,
const SpaProps *props)
static int
impl_clock_set_props (struct spa_clock *clock,
const struct spa_props *props)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_audiotestsrc_clock_get_time (SpaClock *clock,
static int
impl_clock_get_time (struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
@ -946,26 +946,26 @@ spa_audiotestsrc_clock_get_time (SpaClock *clock,
return SPA_RESULT_OK;
}
static const SpaClock audiotestsrc_clock = {
sizeof (SpaClock),
static const struct spa_clock impl_clock = {
sizeof (struct spa_clock),
NULL,
SPA_CLOCK_STATE_STOPPED,
spa_audiotestsrc_clock_get_props,
spa_audiotestsrc_clock_set_props,
spa_audiotestsrc_clock_get_time,
impl_clock_get_props,
impl_clock_set_props,
impl_clock_get_time,
};
static SpaResult
spa_audiotestsrc_get_interface (SpaHandle *handle,
static int
impl_get_interface (struct spa_handle *handle,
uint32_t interface_id,
void **interface)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (SpaAudioTestSrc *) handle;
this = (struct impl *) handle;
if (interface_id == this->type.node)
*interface = &this->node;
@ -977,14 +977,14 @@ spa_audiotestsrc_get_interface (SpaHandle *handle,
return SPA_RESULT_OK;
}
static SpaResult
audiotestsrc_clear (SpaHandle *handle)
static int
impl_clear (struct spa_handle *handle)
{
SpaAudioTestSrc *this;
struct impl *this;
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = (SpaAudioTestSrc *) handle;
this = (struct impl *) handle;
if (this->data_loop)
spa_loop_remove_source (this->data_loop, &this->timer_source);
@ -993,23 +993,23 @@ audiotestsrc_clear (SpaHandle *handle)
return SPA_RESULT_OK;
}
static SpaResult
audiotestsrc_init (const SpaHandleFactory *factory,
SpaHandle *handle,
const SpaDict *info,
const SpaSupport *support,
uint32_t n_support)
static int
impl_init (const struct spa_handle_factory *factory,
struct spa_handle *handle,
const struct spa_dict *info,
const struct spa_support *support,
uint32_t n_support)
{
SpaAudioTestSrc *this;
struct impl *this;
uint32_t i;
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
handle->get_interface = spa_audiotestsrc_get_interface;
handle->clear = audiotestsrc_clear;
handle->get_interface = impl_get_interface;
handle->clear = impl_clear;
this = (SpaAudioTestSrc *) handle;
this = (struct impl *) handle;
for (i = 0; i < n_support; i++) {
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
@ -1025,13 +1025,13 @@ audiotestsrc_init (const SpaHandleFactory *factory,
}
init_type (&this->type, this->map);
this->node = audiotestsrc_node;
this->clock = audiotestsrc_clock;
reset_audiotestsrc_props (this, &this->props);
this->node = impl_node;
this->clock = impl_clock;
impl_reset_props (this, &this->props);
spa_list_init (&this->empty);
this->timer_source.func = audiotestsrc_on_output;
this->timer_source.func = on_output;
this->timer_source.data = this;
this->timer_source.fd = timerfd_create (CLOCK_MONOTONIC, TFD_CLOEXEC);
this->timer_source.mask = SPA_IO_IN;
@ -1049,28 +1049,27 @@ audiotestsrc_init (const SpaHandleFactory *factory,
if (this->props.live)
this->info.flags |= SPA_PORT_INFO_FLAG_LIVE;
spa_log_info (this->log, "audiotestsrc %p: initialized", this);
spa_log_info (this->log, IMPL_NAME " %p: initialized", this);
return SPA_RESULT_OK;
}
static const SpaInterfaceInfo audiotestsrc_interfaces[] =
{
static const struct spa_interface_info impl_interfaces[] = {
{ SPA_TYPE__Node, },
{ SPA_TYPE__Clock, },
};
static SpaResult
audiotestsrc_enum_interface_info (const SpaHandleFactory *factory,
const SpaInterfaceInfo **info,
uint32_t index)
static int
impl_enum_interface_info (const struct spa_handle_factory *factory,
const struct spa_interface_info **info,
uint32_t index)
{
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:
*info = &audiotestsrc_interfaces[index];
*info = &impl_interfaces[index];
break;
default:
return SPA_RESULT_ENUM_END;
@ -1078,10 +1077,10 @@ audiotestsrc_enum_interface_info (const SpaHandleFactory *factory,
return SPA_RESULT_OK;
}
const SpaHandleFactory spa_audiotestsrc_factory =
{ "audiotestsrc",
const struct spa_handle_factory spa_audiotestsrc_factory = {
IMPL_NAME,
NULL,
sizeof (SpaAudioTestSrc),
audiotestsrc_init,
audiotestsrc_enum_interface_info,
sizeof (struct impl),
impl_init,
impl_enum_interface_info,
};

View file

@ -20,20 +20,21 @@
#include <spa/plugin.h>
#include <spa/node.h>
extern const SpaHandleFactory spa_audiotestsrc_factory;
extern const struct spa_handle_factory spa_audiotestsrc_factory;
SpaResult
spa_enum_handle_factory (const SpaHandleFactory **factory,
uint32_t index)
int
spa_handle_factory_enum(const struct spa_handle_factory **factory,
uint32_t index)
{
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
spa_return_val_if_fail(factory != NULL,
SPA_RESULT_INVALID_ARGUMENTS);
switch (index) {
case 0:
*factory = &spa_audiotestsrc_factory;
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
switch (index) {
case 0:
*factory = &spa_audiotestsrc_factory;
break;
default:
return SPA_RESULT_ENUM_END;
}
return SPA_RESULT_OK;
}

View file

@ -21,11 +21,9 @@
#define M_PI_M2 ( M_PI + M_PI )
typedef SpaResult (*RenderFunc) (SpaAudioTestSrc *this, void *samples, size_t n_samples);
#define DEFINE_SINE(type,scale) \
static void \
audio_test_src_create_sine_##type (SpaAudioTestSrc *this, type * samples, size_t n_samples) \
audio_test_src_create_sine_##type (struct impl *this, type * samples, size_t n_samples) \
{ \
int i, c, channels; \
double step, amp; \
@ -48,9 +46,9 @@ DEFINE_SINE (int32_t, 2147483647.0);
DEFINE_SINE (float, 1.0);
DEFINE_SINE (double, 1.0);
static const RenderFunc sine_funcs[] = {
(RenderFunc) audio_test_src_create_sine_int16_t,
(RenderFunc) audio_test_src_create_sine_int32_t,
(RenderFunc) audio_test_src_create_sine_float,
(RenderFunc) audio_test_src_create_sine_double
static const render_func_t sine_funcs[] = {
(render_func_t) audio_test_src_create_sine_int16_t,
(render_func_t) audio_test_src_create_sine_int32_t,
(render_func_t) audio_test_src_create_sine_float,
(render_func_t) audio_test_src_create_sine_double
};