2016-06-28 12:21:56 +02:00
|
|
|
/* Spa
|
|
|
|
|
* Copyright (C) 2016 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2016-09-19 13:14:14 +02:00
|
|
|
#include <unistd.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
#include <string.h>
|
2016-09-05 16:23:40 +02:00
|
|
|
#include <stdio.h>
|
2016-09-19 13:14:14 +02:00
|
|
|
#include <sys/timerfd.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
#include <spa/type-map.h>
|
2017-03-22 10:04:24 +01:00
|
|
|
#include <spa/clock.h>
|
2016-10-07 13:14:32 +02:00
|
|
|
#include <spa/log.h>
|
2016-11-18 17:46:01 +01:00
|
|
|
#include <spa/loop.h>
|
2017-01-19 18:10:00 +01:00
|
|
|
#include <spa/node.h>
|
2016-11-09 12:57:51 +01:00
|
|
|
#include <spa/list.h>
|
2017-03-21 16:50:44 +01:00
|
|
|
#include <spa/audio/format-utils.h>
|
2017-02-24 09:28:18 +01:00
|
|
|
#include <spa/format-builder.h>
|
2016-11-03 19:41:53 +01:00
|
|
|
#include <lib/props.h>
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-09-20 11:20:43 +02:00
|
|
|
#define SAMPLES_TO_TIME(this,s) ((s) * SPA_NSEC_PER_SEC / (this)->current_format.info.raw.rate)
|
2016-09-19 19:17:59 +02:00
|
|
|
#define BYTES_TO_SAMPLES(this,b) ((b)/(this)->bpf)
|
|
|
|
|
#define BYTES_TO_TIME(this,b) SAMPLES_TO_TIME(this, BYTES_TO_SAMPLES (this, b))
|
|
|
|
|
|
2017-01-19 18:10:00 +01:00
|
|
|
typedef struct {
|
|
|
|
|
uint32_t node;
|
|
|
|
|
uint32_t clock;
|
2017-03-22 10:04:24 +01:00
|
|
|
uint32_t format;
|
2017-03-23 12:38:00 +01:00
|
|
|
uint32_t props;
|
|
|
|
|
uint32_t prop_live;
|
|
|
|
|
uint32_t prop_wave;
|
|
|
|
|
uint32_t prop_freq;
|
|
|
|
|
uint32_t prop_volume;
|
|
|
|
|
uint32_t wave_sine;
|
|
|
|
|
uint32_t wave_square;
|
2017-04-26 18:42:50 +02:00
|
|
|
SpaTypeMeta meta;
|
|
|
|
|
SpaTypeData data;
|
2017-03-24 11:40:58 +01:00
|
|
|
SpaTypeMediaType media_type;
|
|
|
|
|
SpaTypeMediaSubtype media_subtype;
|
2017-03-24 13:11:57 +01:00
|
|
|
SpaTypeFormatAudio format_audio;
|
2017-03-24 11:40:58 +01:00
|
|
|
SpaTypeAudioFormat audio_format;
|
|
|
|
|
SpaTypeEventNode event_node;
|
|
|
|
|
SpaTypeCommandNode command_node;
|
|
|
|
|
SpaTypeAllocParamBuffers alloc_param_buffers;
|
|
|
|
|
SpaTypeAllocParamMetaEnable alloc_param_meta_enable;
|
|
|
|
|
} Type;
|
2017-01-19 18:10:00 +01:00
|
|
|
|
2017-03-23 12:38:00 +01:00
|
|
|
static inline void
|
2017-03-24 11:40:58 +01:00
|
|
|
init_type (Type *type, SpaTypeMap *map)
|
|
|
|
|
{
|
|
|
|
|
type->node = spa_type_map_get_id (map, SPA_TYPE__Node);
|
|
|
|
|
type->clock = spa_type_map_get_id (map, SPA_TYPE__Clock);
|
|
|
|
|
type->format = spa_type_map_get_id (map, SPA_TYPE__Format);
|
|
|
|
|
type->props = spa_type_map_get_id (map, SPA_TYPE__Props);
|
|
|
|
|
type->prop_live = spa_type_map_get_id (map, SPA_TYPE_PROPS__live);
|
|
|
|
|
type->prop_wave = spa_type_map_get_id (map, SPA_TYPE_PROPS__waveType);
|
|
|
|
|
type->prop_freq = spa_type_map_get_id (map, SPA_TYPE_PROPS__frequency);
|
|
|
|
|
type->prop_volume = spa_type_map_get_id (map, SPA_TYPE_PROPS__volume);
|
|
|
|
|
type->wave_sine = spa_type_map_get_id (map, SPA_TYPE_PROPS__waveType ":sine");
|
|
|
|
|
type->wave_square = spa_type_map_get_id (map, SPA_TYPE_PROPS__waveType ":square");
|
2017-04-26 18:42:50 +02:00
|
|
|
spa_type_meta_map (map, &type->meta);
|
|
|
|
|
spa_type_data_map (map, &type->data);
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_type_media_type_map (map, &type->media_type);
|
|
|
|
|
spa_type_media_subtype_map (map, &type->media_subtype);
|
2017-03-24 13:11:57 +01:00
|
|
|
spa_type_format_audio_map (map, &type->format_audio);
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_type_audio_format_map (map, &type->audio_format);
|
|
|
|
|
spa_type_event_node_map (map, &type->event_node);
|
|
|
|
|
spa_type_command_node_map (map, &type->command_node);
|
|
|
|
|
spa_type_alloc_param_buffers_map (map, &type->alloc_param_buffers);
|
|
|
|
|
spa_type_alloc_param_meta_enable_map (map, &type->alloc_param_meta_enable);
|
2017-03-23 12:38:00 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
typedef struct _SpaAudioTestSrc SpaAudioTestSrc;
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
2017-02-28 10:48:53 +01:00
|
|
|
bool live;
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t wave;
|
|
|
|
|
double freq;
|
|
|
|
|
double volume;
|
|
|
|
|
} SpaAudioTestSrcProps;
|
|
|
|
|
|
2016-09-29 18:18:59 +02:00
|
|
|
#define MAX_BUFFERS 16
|
|
|
|
|
|
2016-09-05 16:23:40 +02:00
|
|
|
typedef struct _ATSBuffer ATSBuffer;
|
|
|
|
|
|
|
|
|
|
struct _ATSBuffer {
|
|
|
|
|
SpaBuffer *outbuf;
|
|
|
|
|
bool outstanding;
|
2016-09-19 13:14:14 +02:00
|
|
|
SpaMetaHeader *h;
|
2017-04-20 19:25:14 +02:00
|
|
|
SpaMetaRingbuffer *rb;
|
2016-12-20 18:10:50 +01:00
|
|
|
SpaList link;
|
2016-09-05 16:23:40 +02:00
|
|
|
};
|
|
|
|
|
|
2017-04-03 19:23:53 +02:00
|
|
|
typedef SpaResult (*RenderFunc) (SpaAudioTestSrc *this, void *samples, size_t n_samples);
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
struct _SpaAudioTestSrc {
|
|
|
|
|
SpaHandle handle;
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaNode node;
|
2016-09-19 19:17:59 +02:00
|
|
|
SpaClock clock;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
Type type;
|
|
|
|
|
SpaTypeMap *map;
|
2016-10-07 13:14:32 +02:00
|
|
|
SpaLog *log;
|
2016-11-18 17:46:01 +01:00
|
|
|
SpaLoop *data_loop;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2017-02-28 10:48:53 +01:00
|
|
|
uint8_t props_buffer[512];
|
|
|
|
|
SpaAudioTestSrcProps props;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-05-11 10:29:20 +02:00
|
|
|
SpaNodeCallbacks callbacks;
|
2016-06-28 12:21:56 +02:00
|
|
|
void *user_data;
|
|
|
|
|
|
2016-11-18 17:46:01 +01:00
|
|
|
SpaSource timer_source;
|
2016-09-19 13:14:14 +02:00
|
|
|
struct itimerspec timerspec;
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
SpaPortInfo info;
|
2016-09-19 19:29:35 +02:00
|
|
|
SpaAllocParam *params[2];
|
2017-03-17 11:58:09 +01:00
|
|
|
uint8_t params_buffer[1024];
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaPortIO *io;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
bool have_format;
|
2017-02-24 09:28:18 +01:00
|
|
|
SpaAudioInfo current_format;
|
|
|
|
|
uint8_t format_buffer[1024];
|
2016-09-19 13:14:14 +02:00
|
|
|
size_t bpf;
|
2017-04-03 19:23:53 +02:00
|
|
|
RenderFunc render_func;
|
|
|
|
|
double accumulator;
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2016-09-29 18:18:59 +02:00
|
|
|
ATSBuffer buffers[MAX_BUFFERS];
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_buffers;
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2016-09-19 13:14:14 +02:00
|
|
|
bool started;
|
|
|
|
|
uint64_t start_time;
|
|
|
|
|
uint64_t elapsed_time;
|
|
|
|
|
|
|
|
|
|
uint64_t sample_count;
|
2016-11-09 12:57:51 +01:00
|
|
|
SpaList empty;
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
#define CHECK_PORT(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) == 0)
|
|
|
|
|
|
2017-02-28 10:48:53 +01:00
|
|
|
#define DEFAULT_LIVE true
|
2017-03-23 12:38:00 +01:00
|
|
|
#define DEFAULT_WAVE wave_sine
|
2016-09-19 13:14:14 +02:00
|
|
|
#define DEFAULT_FREQ 440.0
|
2017-02-28 10:48:53 +01:00
|
|
|
#define DEFAULT_VOLUME 1.0
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-02-28 10:48:53 +01:00
|
|
|
static void
|
2017-03-23 12:38:00 +01:00
|
|
|
reset_audiotestsrc_props (SpaAudioTestSrc *this, SpaAudioTestSrcProps *props)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-02-28 10:48:53 +01:00
|
|
|
props->live = DEFAULT_LIVE;
|
2017-03-24 11:40:58 +01:00
|
|
|
props->wave = this->type. DEFAULT_WAVE;
|
2016-09-19 13:14:14 +02:00
|
|
|
props->freq = DEFAULT_FREQ;
|
|
|
|
|
props->volume = DEFAULT_VOLUME;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-17 11:58:09 +01:00
|
|
|
#define PROP(f,key,type,...) \
|
2017-03-31 11:48:24 +02:00
|
|
|
SPA_POD_PROP (f,key,0,type,1,__VA_ARGS__)
|
2017-03-17 11:58:09 +01:00
|
|
|
#define PROP_MM(f,key,type,...) \
|
2017-03-31 11:48:24 +02:00
|
|
|
SPA_POD_PROP (f,key,SPA_POD_PROP_RANGE_MIN_MAX,type,3,__VA_ARGS__)
|
2017-03-17 11:58:09 +01:00
|
|
|
#define PROP_U_MM(f,key,type,...) \
|
2017-03-31 11:48:24 +02:00
|
|
|
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \
|
2017-03-17 11:58:09 +01:00
|
|
|
SPA_POD_PROP_RANGE_MIN_MAX,type,3,__VA_ARGS__)
|
|
|
|
|
#define PROP_EN(f,key,type,n,...) \
|
2017-03-31 11:48:24 +02:00
|
|
|
SPA_POD_PROP (f,key,SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
|
2017-03-17 11:58:09 +01:00
|
|
|
#define PROP_U_EN(f,key,type,n,...) \
|
2017-03-31 11:48:24 +02:00
|
|
|
SPA_POD_PROP (f,key,SPA_POD_PROP_FLAG_UNSET | \
|
2017-03-17 11:58:09 +01:00
|
|
|
SPA_POD_PROP_RANGE_ENUM,type,n,__VA_ARGS__)
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_get_props (SpaNode *node,
|
2016-06-28 12:21:56 +02:00
|
|
|
SpaProps **props)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2017-02-28 10:48:53 +01:00
|
|
|
SpaPODBuilder b = { NULL, };
|
2017-03-17 11:58:09 +01:00
|
|
|
SpaPODFrame f[2];
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (props != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-03-01 14:07:02 +01:00
|
|
|
spa_pod_builder_init (&b, this->props_buffer, sizeof (this->props_buffer));
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_pod_builder_props (&b, &f[0], this->type.props,
|
|
|
|
|
PROP (&f[1], this->type.prop_live, SPA_POD_TYPE_BOOL, this->props.live),
|
2017-03-24 13:11:57 +01:00
|
|
|
PROP_EN (&f[1], this->type.prop_wave, SPA_POD_TYPE_ID, 3, this->props.wave,
|
2017-03-24 11:40:58 +01:00
|
|
|
this->type.wave_sine,
|
|
|
|
|
this->type.wave_square),
|
|
|
|
|
PROP_MM (&f[1], this->type.prop_freq, SPA_POD_TYPE_DOUBLE, this->props.freq,
|
2017-03-23 12:38:00 +01:00
|
|
|
0.0, 50000000.0),
|
2017-03-24 11:40:58 +01:00
|
|
|
PROP_MM (&f[1], this->type.prop_volume, SPA_POD_TYPE_DOUBLE, this->props.volume,
|
2017-03-23 12:38:00 +01:00
|
|
|
0.0, 10.0));
|
2017-03-17 11:58:09 +01:00
|
|
|
|
|
|
|
|
*props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_set_props (SpaNode *node,
|
2016-06-28 12:21:56 +02:00
|
|
|
const SpaProps *props)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
if (props == NULL) {
|
2017-03-23 12:38:00 +01:00
|
|
|
reset_audiotestsrc_props (this, &this->props);
|
2016-09-19 13:14:14 +02:00
|
|
|
} else {
|
2017-03-17 11:58:09 +01:00
|
|
|
spa_props_query (props,
|
2017-03-24 11:40:58 +01:00
|
|
|
this->type.prop_live, SPA_POD_TYPE_BOOL, &this->props.live,
|
2017-03-24 13:11:57 +01:00
|
|
|
this->type.prop_wave, SPA_POD_TYPE_ID, &this->props.wave,
|
2017-03-24 11:40:58 +01:00
|
|
|
this->type.prop_freq, SPA_POD_TYPE_DOUBLE, &this->props.freq,
|
|
|
|
|
this->type.prop_volume, SPA_POD_TYPE_DOUBLE, &this->props.volume,
|
2017-03-17 11:58:09 +01:00
|
|
|
0);
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2016-09-19 13:14:14 +02:00
|
|
|
|
2017-02-28 10:48:53 +01:00
|
|
|
if (this->props.live)
|
2016-09-19 13:14:14 +02:00
|
|
|
this->info.flags |= SPA_PORT_INFO_FLAG_LIVE;
|
|
|
|
|
else
|
|
|
|
|
this->info.flags &= ~SPA_PORT_INFO_FLAG_LIVE;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-02-28 10:48:53 +01:00
|
|
|
return SPA_RESULT_OK;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-11 10:29:20 +02:00
|
|
|
static inline SpaResult
|
2016-09-05 16:23:40 +02:00
|
|
|
send_have_output (SpaAudioTestSrc *this)
|
|
|
|
|
{
|
2017-05-11 10:29:20 +02:00
|
|
|
if (this->callbacks.have_output)
|
|
|
|
|
this->callbacks.have_output (&this->node, this->user_data);
|
2016-09-05 16:23:40 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 19:23:53 +02:00
|
|
|
#include "render.c"
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2017-01-19 18:10:00 +01:00
|
|
|
static void
|
|
|
|
|
set_timer (SpaAudioTestSrc *this, bool enabled)
|
|
|
|
|
{
|
2017-05-11 16:11:08 +02:00
|
|
|
if (this->callbacks.have_output || this->props.live) {
|
2017-04-04 09:40:12 +02:00
|
|
|
if (enabled) {
|
|
|
|
|
if (this->props.live) {
|
|
|
|
|
uint64_t next_time = this->start_time + this->elapsed_time;
|
|
|
|
|
this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
|
|
|
|
|
this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
|
|
|
|
|
} else {
|
|
|
|
|
this->timerspec.it_value.tv_sec = 0;
|
|
|
|
|
this->timerspec.it_value.tv_nsec = 1;
|
|
|
|
|
}
|
2017-01-19 18:10:00 +01:00
|
|
|
} else {
|
|
|
|
|
this->timerspec.it_value.tv_sec = 0;
|
2017-04-04 09:40:12 +02:00
|
|
|
this->timerspec.it_value.tv_nsec = 0;
|
2017-01-19 18:10:00 +01:00
|
|
|
}
|
2017-04-04 09:40:12 +02:00
|
|
|
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
read_timer (SpaAudioTestSrc *this)
|
|
|
|
|
{
|
|
|
|
|
uint64_t expirations;
|
|
|
|
|
|
2017-05-11 16:11:08 +02:00
|
|
|
if (this->callbacks.have_output || this->props.live) {
|
2017-04-04 09:40:12 +02:00
|
|
|
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
|
|
|
|
perror ("read timerfd");
|
2017-01-19 18:10:00 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
static SpaResult
|
|
|
|
|
audiotestsrc_make_buffer (SpaAudioTestSrc *this)
|
2016-09-19 19:17:59 +02:00
|
|
|
{
|
|
|
|
|
ATSBuffer *b;
|
2017-04-03 19:23:53 +02:00
|
|
|
SpaPortIO *io = this->io;
|
|
|
|
|
int n_bytes, n_samples;
|
2017-04-03 16:54:44 +02:00
|
|
|
|
2017-04-04 09:40:12 +02:00
|
|
|
read_timer (this);
|
2016-09-19 19:17:59 +02:00
|
|
|
|
2016-11-09 12:57:51 +01:00
|
|
|
if (spa_list_is_empty (&this->empty)) {
|
2017-01-19 18:10:00 +01:00
|
|
|
set_timer (this, false);
|
2017-04-03 14:56:04 +02:00
|
|
|
return SPA_RESULT_OUT_OF_BUFFERS;
|
2016-09-19 19:17:59 +02:00
|
|
|
}
|
2016-12-20 18:10:50 +01:00
|
|
|
b = spa_list_first (&this->empty, ATSBuffer, link);
|
|
|
|
|
spa_list_remove (&b->link);
|
2017-04-03 14:56:04 +02:00
|
|
|
b->outstanding = true;
|
2016-09-19 19:17:59 +02:00
|
|
|
|
2017-04-03 19:23:53 +02:00
|
|
|
n_bytes = b->outbuf->datas[0].maxsize;
|
2017-04-12 10:40:17 +02:00
|
|
|
if (io->range.min_size != 0) {
|
2017-04-20 19:25:14 +02:00
|
|
|
n_bytes = SPA_MIN (n_bytes, io->range.min_size);
|
2017-04-12 10:40:17 +02:00
|
|
|
if (io->range.max_size < n_bytes)
|
|
|
|
|
n_bytes = io->range.max_size;
|
|
|
|
|
}
|
2017-04-03 19:23:53 +02:00
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
spa_log_trace (this->log, "audiotestsrc %p: dequeue buffer %d %d %d", this, b->outbuf->id,
|
|
|
|
|
b->outbuf->datas[0].maxsize, n_bytes);
|
2017-04-03 19:23:53 +02:00
|
|
|
|
2017-04-20 19:25:14 +02:00
|
|
|
if (b->rb) {
|
|
|
|
|
int32_t filled, avail;
|
|
|
|
|
uint32_t index, offset;
|
2017-04-03 19:23:53 +02:00
|
|
|
|
2017-04-20 19:25:14 +02:00
|
|
|
filled = spa_ringbuffer_get_write_index (&b->rb->ringbuffer, &index);
|
|
|
|
|
avail = b->rb->ringbuffer.size - filled;
|
|
|
|
|
n_bytes = SPA_MIN (avail, n_bytes);
|
|
|
|
|
|
|
|
|
|
n_samples = n_bytes / this->bpf;
|
|
|
|
|
|
|
|
|
|
offset = index & b->rb->ringbuffer.mask;
|
|
|
|
|
|
|
|
|
|
if (offset + n_bytes > b->rb->ringbuffer.size) {
|
|
|
|
|
uint32_t l0 = b->rb->ringbuffer.size - offset;
|
|
|
|
|
this->render_func (this, SPA_MEMBER (b->outbuf->datas[0].data, offset, void), l0 / this->bpf);
|
|
|
|
|
this->render_func (this, b->outbuf->datas[0].data, (n_bytes - l0) / this->bpf);
|
|
|
|
|
} else {
|
|
|
|
|
this->render_func (this, SPA_MEMBER (b->outbuf->datas[0].data, offset, void), n_samples);
|
|
|
|
|
}
|
2017-04-24 13:18:57 +02:00
|
|
|
spa_ringbuffer_write_update (&b->rb->ringbuffer, index + n_bytes);
|
2017-04-20 19:25:14 +02:00
|
|
|
} else {
|
|
|
|
|
n_samples = n_bytes / this->bpf;
|
|
|
|
|
this->render_func (this, b->outbuf->datas[0].data, n_samples);
|
|
|
|
|
b->outbuf->datas[0].chunk->size = n_bytes;
|
|
|
|
|
b->outbuf->datas[0].chunk->offset = 0;
|
|
|
|
|
b->outbuf->datas[0].chunk->stride = 0;
|
|
|
|
|
}
|
2016-09-19 19:17:59 +02:00
|
|
|
|
2016-09-19 19:29:35 +02:00
|
|
|
if (b->h) {
|
|
|
|
|
b->h->seq = this->sample_count;
|
|
|
|
|
b->h->pts = this->start_time + this->elapsed_time;
|
|
|
|
|
b->h->dts_offset = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 19:23:53 +02:00
|
|
|
this->sample_count += n_samples;
|
2016-09-19 19:29:35 +02:00
|
|
|
this->elapsed_time = SAMPLES_TO_TIME (this, this->sample_count);
|
2017-01-19 18:10:00 +01:00
|
|
|
set_timer (this, true);
|
2016-09-19 19:17:59 +02:00
|
|
|
|
2017-04-03 19:23:53 +02:00
|
|
|
io->buffer_id = b->outbuf->id;
|
2017-04-28 11:49:13 +02:00
|
|
|
io->status = SPA_RESULT_HAVE_BUFFER;
|
2017-04-03 19:23:53 +02:00
|
|
|
|
2017-04-28 11:49:13 +02:00
|
|
|
return SPA_RESULT_HAVE_BUFFER;
|
2017-04-03 14:56:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
audiotestsrc_on_output (SpaSource *source)
|
|
|
|
|
{
|
|
|
|
|
SpaAudioTestSrc *this = source->data;
|
2017-04-03 16:54:44 +02:00
|
|
|
SpaResult res;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-04-03 16:54:44 +02:00
|
|
|
res = audiotestsrc_make_buffer (this);
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-04-28 11:49:13 +02:00
|
|
|
if (res == SPA_RESULT_HAVE_BUFFER)
|
2017-04-03 16:54:44 +02:00
|
|
|
send_have_output (this);
|
2016-09-19 19:17:59 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2017-03-22 10:04:24 +01:00
|
|
|
spa_audiotestsrc_node_send_command (SpaNode *node,
|
|
|
|
|
SpaCommand *command)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (command != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
if (SPA_COMMAND_TYPE (command) == this->type.command_node.Start) {
|
2017-03-22 10:04:24 +01:00
|
|
|
struct timespec now;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
if (!this->have_format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
2016-09-19 13:14:14 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
if (this->n_buffers == 0)
|
|
|
|
|
return SPA_RESULT_NO_BUFFERS;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
if (this->started)
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
clock_gettime (CLOCK_MONOTONIC, &now);
|
|
|
|
|
if (this->props.live)
|
|
|
|
|
this->start_time = SPA_TIMESPEC_TO_TIME (&now);
|
|
|
|
|
else
|
|
|
|
|
this->start_time = 0;
|
|
|
|
|
this->sample_count = 0;
|
|
|
|
|
this->elapsed_time = 0;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
this->started = true;
|
|
|
|
|
set_timer (this, true);
|
|
|
|
|
}
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (SPA_COMMAND_TYPE (command) == this->type.command_node.Pause) {
|
2017-03-22 10:04:24 +01:00
|
|
|
if (!this->have_format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
if (this->n_buffers == 0)
|
|
|
|
|
return SPA_RESULT_NO_BUFFERS;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
if (!this->started)
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
this->started = false;
|
|
|
|
|
set_timer (this, false);
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2017-03-22 10:04:24 +01:00
|
|
|
else
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2017-05-11 10:29:20 +02:00
|
|
|
spa_audiotestsrc_node_set_callbacks (SpaNode *node,
|
|
|
|
|
const SpaNodeCallbacks *callbacks,
|
|
|
|
|
size_t callbacks_size,
|
|
|
|
|
void *user_data)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-05-11 16:11:08 +02:00
|
|
|
if (this->data_loop == NULL && callbacks->have_output) {
|
|
|
|
|
spa_log_error (this->log, "a data_loop is needed for async operation");
|
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 10:29:20 +02:00
|
|
|
this->callbacks = *callbacks;
|
2016-06-28 12:21:56 +02:00
|
|
|
this->user_data = user_data;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_get_n_ports (SpaNode *node,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t *n_input_ports,
|
|
|
|
|
uint32_t *max_input_ports,
|
|
|
|
|
uint32_t *n_output_ports,
|
|
|
|
|
uint32_t *max_output_ports)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
if (n_input_ports)
|
|
|
|
|
*n_input_ports = 0;
|
|
|
|
|
if (n_output_ports)
|
|
|
|
|
*n_output_ports = 1;
|
|
|
|
|
if (max_input_ports)
|
|
|
|
|
*max_input_ports = 0;
|
|
|
|
|
if (max_output_ports)
|
|
|
|
|
*max_output_ports = 1;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_get_port_ids (SpaNode *node,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_input_ports,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t *input_ids,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_output_ports,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t *output_ids)
|
|
|
|
|
{
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-09-05 16:23:40 +02:00
|
|
|
if (n_output_ports > 0 && output_ids != NULL)
|
2016-06-28 12:21:56 +02:00
|
|
|
output_ids[0] = 0;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_add_port (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-07-30 20:35:34 +02:00
|
|
|
uint32_t port_id)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_remove_port (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_port_enum_formats (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
2016-07-15 18:22:29 +02:00
|
|
|
SpaFormat **format,
|
|
|
|
|
const SpaFormat *filter,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2017-02-10 10:17:07 +01:00
|
|
|
SpaResult res;
|
2017-02-24 09:28:18 +01:00
|
|
|
SpaFormat *fmt;
|
|
|
|
|
uint8_t buffer[256];
|
2017-03-01 14:07:02 +01:00
|
|
|
SpaPODBuilder b = { NULL, };
|
2017-03-07 19:40:51 +01:00
|
|
|
SpaPODFrame f[2];
|
2017-04-04 20:25:02 +02:00
|
|
|
uint32_t count, match;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 20:25:02 +02:00
|
|
|
count = match = filter ? 0 : index;
|
|
|
|
|
|
2017-03-01 14:07:02 +01:00
|
|
|
next:
|
|
|
|
|
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
|
|
|
|
|
2017-04-04 20:25:02 +02:00
|
|
|
switch (count++) {
|
2016-06-28 12:21:56 +02:00
|
|
|
case 0:
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_pod_builder_format (&b, &f[0], this->type.format,
|
|
|
|
|
this->type.media_type.audio, this->type.media_subtype.raw,
|
2017-04-03 19:23:53 +02:00
|
|
|
PROP_U_EN (&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID, 5, this->type.audio_format.S16,
|
2017-03-24 11:40:58 +01:00
|
|
|
this->type.audio_format.S16,
|
2017-04-03 19:23:53 +02:00
|
|
|
this->type.audio_format.S32,
|
|
|
|
|
this->type.audio_format.F32,
|
|
|
|
|
this->type.audio_format.F64),
|
2017-03-24 13:11:57 +01:00
|
|
|
PROP_U_MM (&f[1], this->type.format_audio.rate, SPA_POD_TYPE_INT, 44100, 1, INT32_MAX),
|
|
|
|
|
PROP_U_MM (&f[1], this->type.format_audio.channels, SPA_POD_TYPE_INT, 2, 1, INT32_MAX));
|
2016-06-28 12:21:56 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
}
|
2017-03-17 11:58:09 +01:00
|
|
|
fmt = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat);
|
2017-02-24 09:28:18 +01:00
|
|
|
|
2017-03-01 14:07:02 +01:00
|
|
|
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
|
2017-02-24 09:28:18 +01:00
|
|
|
|
2017-04-04 20:25:02 +02:00
|
|
|
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
|
2017-03-01 14:07:02 +01:00
|
|
|
goto next;
|
2017-02-10 10:17:07 +01:00
|
|
|
|
2017-02-28 10:48:53 +01:00
|
|
|
*format = SPA_POD_BUILDER_DEREF (&b, 0, SpaFormat);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-13 17:43:57 +02:00
|
|
|
static SpaResult
|
|
|
|
|
clear_buffers (SpaAudioTestSrc *this)
|
|
|
|
|
{
|
2016-10-04 19:37:44 +02:00
|
|
|
if (this->n_buffers > 0) {
|
2016-11-03 19:41:53 +01:00
|
|
|
spa_log_info (this->log, "audiotestsrc %p: clear buffers", this);
|
2016-09-13 17:43:57 +02:00
|
|
|
this->n_buffers = 0;
|
2016-11-09 12:57:51 +01:00
|
|
|
spa_list_init (&this->empty);
|
2017-03-01 14:07:02 +01:00
|
|
|
this->started = false;
|
|
|
|
|
set_timer (this, false);
|
2016-09-13 17:43:57 +02:00
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2017-05-11 10:29:20 +02:00
|
|
|
spa_audiotestsrc_node_port_set_format (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t flags,
|
|
|
|
|
const SpaFormat *format)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
if (format == NULL) {
|
|
|
|
|
this->have_format = false;
|
2016-09-13 17:43:57 +02:00
|
|
|
clear_buffers (this);
|
2016-09-05 16:23:40 +02:00
|
|
|
} else {
|
2017-03-24 18:11:11 +01:00
|
|
|
SpaAudioInfo info = { SPA_FORMAT_MEDIA_TYPE (format),
|
|
|
|
|
SPA_FORMAT_MEDIA_SUBTYPE (format), };
|
2017-04-03 19:23:53 +02:00
|
|
|
int idx;
|
|
|
|
|
int sizes[4] = { 2, 4, 4, 8 };
|
2017-03-24 18:11:11 +01:00
|
|
|
|
|
|
|
|
if (info.media_type != this->type.media_type.audio ||
|
|
|
|
|
info.media_subtype != this->type.media_subtype.raw)
|
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
|
|
|
|
|
|
|
|
|
if (!spa_format_audio_raw_parse (format, &info.info.raw, &this->type.format_audio))
|
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 19:23:53 +02:00
|
|
|
if (info.info.raw.format == this->type.audio_format.S16)
|
|
|
|
|
idx = 0;
|
|
|
|
|
else if (info.info.raw.format == this->type.audio_format.S32)
|
|
|
|
|
idx = 1;
|
|
|
|
|
else if (info.info.raw.format == this->type.audio_format.F32)
|
|
|
|
|
idx = 2;
|
|
|
|
|
else if (info.info.raw.format == this->type.audio_format.F64)
|
|
|
|
|
idx = 3;
|
|
|
|
|
else
|
|
|
|
|
return SPA_RESULT_INVALID_MEDIA_TYPE;
|
|
|
|
|
|
|
|
|
|
this->bpf = sizes[idx] * info.info.raw.channels;
|
2017-03-24 18:11:11 +01:00
|
|
|
this->current_format = info;
|
2016-09-05 16:23:40 +02:00
|
|
|
this->have_format = true;
|
2017-04-03 19:23:53 +02:00
|
|
|
this->render_func = sine_funcs[idx];
|
2016-09-05 16:23:40 +02:00
|
|
|
}
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-09-05 16:23:40 +02:00
|
|
|
if (this->have_format) {
|
2017-03-17 11:58:09 +01:00
|
|
|
SpaPODBuilder b = { NULL };
|
|
|
|
|
SpaPODFrame f[2];
|
|
|
|
|
|
2016-09-05 16:23:40 +02:00
|
|
|
this->info.maxbuffering = -1;
|
2016-09-19 19:17:59 +02:00
|
|
|
this->info.latency = BYTES_TO_TIME (this, 1024);
|
2016-09-19 13:14:14 +02:00
|
|
|
|
2016-09-19 19:29:35 +02:00
|
|
|
this->info.n_params = 2;
|
2016-09-05 16:23:40 +02:00
|
|
|
this->info.params = this->params;
|
2017-03-17 11:58:09 +01:00
|
|
|
|
|
|
|
|
spa_pod_builder_init (&b, this->params_buffer, sizeof (this->params_buffer));
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_buffers.Buffers,
|
2017-04-03 19:23:53 +02:00
|
|
|
PROP (&f[1], this->type.alloc_param_buffers.size, SPA_POD_TYPE_INT, 1024 * this->bpf),
|
|
|
|
|
PROP (&f[1], this->type.alloc_param_buffers.stride, SPA_POD_TYPE_INT, this->bpf),
|
2017-03-24 11:40:58 +01:00
|
|
|
PROP_U_MM (&f[1], this->type.alloc_param_buffers.buffers, SPA_POD_TYPE_INT, 32, 2, 32),
|
|
|
|
|
PROP (&f[1], this->type.alloc_param_buffers.align, SPA_POD_TYPE_INT, 16));
|
2017-03-17 11:58:09 +01:00
|
|
|
this->params[0] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
|
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_pod_builder_object (&b, &f[0], 0, this->type.alloc_param_meta_enable.MetaEnable,
|
2017-04-26 18:42:50 +02:00
|
|
|
PROP (&f[1], this->type.alloc_param_meta_enable.type, SPA_POD_TYPE_ID, this->type.meta.Header),
|
|
|
|
|
PROP (&f[1], this->type.alloc_param_meta_enable.size, SPA_POD_TYPE_INT, sizeof (SpaMetaHeader)));
|
2017-03-17 11:58:09 +01:00
|
|
|
this->params[1] = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaAllocParam);
|
|
|
|
|
|
2016-10-14 10:42:02 +02:00
|
|
|
this->info.extra = NULL;
|
2016-09-05 16:23:40 +02:00
|
|
|
}
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_port_get_format (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
const SpaFormat **format)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2017-02-24 09:28:18 +01:00
|
|
|
SpaPODBuilder b = { NULL, };
|
2017-03-17 11:58:09 +01:00
|
|
|
SpaPODFrame f[2];
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (format != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
if (!this->have_format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
2017-03-01 14:07:02 +01:00
|
|
|
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_pod_builder_format (&b, &f[0], this->type.format,
|
|
|
|
|
this->type.media_type.audio, this->type.media_subtype.raw,
|
2017-03-24 13:11:57 +01:00
|
|
|
PROP (&f[1], this->type.format_audio.format, SPA_POD_TYPE_ID, this->current_format.info.raw.format),
|
|
|
|
|
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));
|
2017-03-17 11:58:09 +01:00
|
|
|
|
|
|
|
|
*format = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaFormat);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_port_get_info (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
const SpaPortInfo **info)
|
|
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
*info = &this->info;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-10-03 19:43:42 +02:00
|
|
|
spa_audiotestsrc_node_port_get_props (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaProps **props)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_node_port_set_props (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-06-28 12:21:56 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
const SpaProps *props)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-02 16:34:44 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_node_port_use_buffers (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-08-02 16:34:44 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaBuffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
|
|
|
|
{
|
2016-09-05 16:23:40 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-09-05 16:23:40 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-09-05 16:23:40 +02:00
|
|
|
|
|
|
|
|
if (!this->have_format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
2016-09-13 17:43:57 +02:00
|
|
|
clear_buffers (this);
|
2016-09-29 18:18:59 +02:00
|
|
|
|
2016-10-04 19:37:44 +02:00
|
|
|
for (i = 0; i < n_buffers; i++) {
|
|
|
|
|
ATSBuffer *b;
|
|
|
|
|
SpaData *d = buffers[i]->datas;
|
2016-09-19 13:14:14 +02:00
|
|
|
|
2016-10-04 19:37:44 +02:00
|
|
|
b = &this->buffers[i];
|
|
|
|
|
b->outbuf = buffers[i];
|
2017-04-03 14:56:04 +02:00
|
|
|
b->outstanding = false;
|
2017-04-26 18:42:50 +02:00
|
|
|
b->h = spa_buffer_find_meta (buffers[i], this->type.meta.Header);
|
|
|
|
|
b->rb = spa_buffer_find_meta (buffers[i], this->type.meta.Ringbuffer);
|
|
|
|
|
|
|
|
|
|
if ((d[0].type == this->type.data.MemPtr ||
|
|
|
|
|
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]);
|
2016-09-05 16:23:40 +02:00
|
|
|
}
|
2016-12-20 18:10:50 +01:00
|
|
|
spa_list_insert (this->empty.prev, &b->link);
|
2016-09-05 16:23:40 +02:00
|
|
|
}
|
2016-10-04 19:37:44 +02:00
|
|
|
this->n_buffers = n_buffers;
|
2016-09-05 16:23:40 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_node_port_alloc_buffers (SpaNode *node,
|
2016-10-03 19:43:42 +02:00
|
|
|
SpaDirection direction,
|
2016-08-02 16:34:44 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaAllocParam **params,
|
|
|
|
|
uint32_t n_params,
|
|
|
|
|
SpaBuffer **buffers,
|
|
|
|
|
uint32_t *n_buffers)
|
|
|
|
|
{
|
2016-09-13 17:43:57 +02:00
|
|
|
SpaAudioTestSrc *this;
|
|
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-09-13 17:43:57 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-09-13 17:43:57 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-09-13 17:43:57 +02:00
|
|
|
|
|
|
|
|
if (!this->have_format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
2016-09-29 18:18:59 +02:00
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-08-02 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_audiotestsrc_node_port_set_io (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
SpaPortIO *io)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-07-30 20:35:34 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
this->io = io;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-03 16:54:44 +02:00
|
|
|
static inline void
|
|
|
|
|
reuse_buffer (SpaAudioTestSrc *this, uint32_t id)
|
|
|
|
|
{
|
|
|
|
|
ATSBuffer *b = &this->buffers[id];
|
|
|
|
|
spa_return_if_fail (b->outstanding);
|
|
|
|
|
|
|
|
|
|
spa_log_trace (this->log, "audiotestsrc %p: reuse buffer %d", this, id);
|
|
|
|
|
|
|
|
|
|
b->outstanding = false;
|
|
|
|
|
spa_list_insert (this->empty.prev, &b->link);
|
|
|
|
|
|
|
|
|
|
if (!this->props.live)
|
|
|
|
|
set_timer (this, true);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 19:43:42 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_node_port_reuse_buffer (SpaNode *node,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t buffer_id)
|
|
|
|
|
{
|
|
|
|
|
SpaAudioTestSrc *this;
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-10-03 19:43:42 +02:00
|
|
|
|
2016-10-12 17:27:29 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2016-10-03 19:43:42 +02:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
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);
|
|
|
|
|
spa_return_val_if_fail (buffer_id < this->n_buffers, SPA_RESULT_INVALID_BUFFER_ID);
|
2016-10-03 19:43:42 +02:00
|
|
|
|
2017-04-03 16:54:44 +02:00
|
|
|
reuse_buffer (this, buffer_id);
|
2016-10-03 19:43:42 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
static SpaResult
|
2016-10-21 14:57:01 +02:00
|
|
|
spa_audiotestsrc_node_port_send_command (SpaNode *node,
|
|
|
|
|
SpaDirection direction,
|
|
|
|
|
uint32_t port_id,
|
2017-03-22 10:04:24 +01:00
|
|
|
SpaCommand *command)
|
2016-07-30 20:35:34 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_node_process_input (SpaNode *node)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_node_process_output (SpaNode *node)
|
|
|
|
|
{
|
2017-04-03 14:56:04 +02:00
|
|
|
SpaAudioTestSrc *this;
|
2017-04-12 10:40:17 +02:00
|
|
|
SpaPortIO *io;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
|
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF (node, SpaAudioTestSrc, node);
|
2017-04-12 10:40:17 +02:00
|
|
|
io = this->io;
|
|
|
|
|
spa_return_val_if_fail (io != NULL, SPA_RESULT_WRONG_STATE);
|
|
|
|
|
|
2017-04-28 11:49:13 +02:00
|
|
|
if (io->status == SPA_RESULT_HAVE_BUFFER)
|
|
|
|
|
return SPA_RESULT_HAVE_BUFFER;
|
2017-04-03 14:56:04 +02:00
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
if (io->buffer_id != SPA_ID_INVALID) {
|
2017-04-03 16:54:44 +02:00
|
|
|
reuse_buffer (this, this->io->buffer_id);
|
2017-04-03 14:56:04 +02:00
|
|
|
this->io->buffer_id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-11 16:11:08 +02:00
|
|
|
if (!this->callbacks.have_output && (io->status == SPA_RESULT_NEED_BUFFER))
|
2017-04-03 16:54:44 +02:00
|
|
|
return audiotestsrc_make_buffer (this);
|
|
|
|
|
else
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-11-07 18:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static const SpaNode audiotestsrc_node = {
|
|
|
|
|
sizeof (SpaNode),
|
2016-09-15 17:51:34 +02:00
|
|
|
NULL,
|
2016-06-28 12:21:56 +02:00
|
|
|
spa_audiotestsrc_node_get_props,
|
|
|
|
|
spa_audiotestsrc_node_set_props,
|
|
|
|
|
spa_audiotestsrc_node_send_command,
|
2017-05-11 10:29:20 +02:00
|
|
|
spa_audiotestsrc_node_set_callbacks,
|
2016-06-28 12:21:56 +02:00
|
|
|
spa_audiotestsrc_node_get_n_ports,
|
|
|
|
|
spa_audiotestsrc_node_get_port_ids,
|
|
|
|
|
spa_audiotestsrc_node_add_port,
|
|
|
|
|
spa_audiotestsrc_node_remove_port,
|
2016-07-08 20:12:56 +02:00
|
|
|
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_get_props,
|
|
|
|
|
spa_audiotestsrc_node_port_set_props,
|
|
|
|
|
spa_audiotestsrc_node_port_use_buffers,
|
|
|
|
|
spa_audiotestsrc_node_port_alloc_buffers,
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_audiotestsrc_node_port_set_io,
|
2016-10-03 19:43:42 +02:00
|
|
|
spa_audiotestsrc_node_port_reuse_buffer,
|
2016-10-21 14:57:01 +02:00
|
|
|
spa_audiotestsrc_node_port_send_command,
|
2016-11-07 18:23:09 +01:00
|
|
|
spa_audiotestsrc_node_process_input,
|
|
|
|
|
spa_audiotestsrc_node_process_output,
|
2016-06-28 12:21:56 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-19 19:17:59 +02:00
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_clock_get_props (SpaClock *clock,
|
|
|
|
|
SpaProps **props)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_clock_set_props (SpaClock *clock,
|
|
|
|
|
const SpaProps *props)
|
|
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
spa_audiotestsrc_clock_get_time (SpaClock *clock,
|
|
|
|
|
int32_t *rate,
|
|
|
|
|
int64_t *ticks,
|
|
|
|
|
int64_t *monotonic_time)
|
|
|
|
|
{
|
|
|
|
|
struct timespec now;
|
|
|
|
|
uint64_t tnow;
|
|
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (clock != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-09-19 19:17:59 +02:00
|
|
|
|
|
|
|
|
if (rate)
|
2016-09-20 11:20:43 +02:00
|
|
|
*rate = SPA_NSEC_PER_SEC;
|
2016-09-19 19:17:59 +02:00
|
|
|
|
|
|
|
|
clock_gettime (CLOCK_MONOTONIC, &now);
|
2016-09-20 11:20:43 +02:00
|
|
|
tnow = SPA_TIMESPEC_TO_TIME (&now);
|
2016-09-19 19:17:59 +02:00
|
|
|
|
|
|
|
|
if (ticks)
|
|
|
|
|
*ticks = tnow;
|
|
|
|
|
if (monotonic_time)
|
|
|
|
|
*monotonic_time = tnow;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const SpaClock audiotestsrc_clock = {
|
|
|
|
|
sizeof (SpaClock),
|
|
|
|
|
NULL,
|
|
|
|
|
SPA_CLOCK_STATE_STOPPED,
|
|
|
|
|
spa_audiotestsrc_clock_get_props,
|
|
|
|
|
spa_audiotestsrc_clock_set_props,
|
|
|
|
|
spa_audiotestsrc_clock_get_time,
|
|
|
|
|
};
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
static SpaResult
|
2016-07-30 20:35:34 +02:00
|
|
|
spa_audiotestsrc_get_interface (SpaHandle *handle,
|
|
|
|
|
uint32_t interface_id,
|
|
|
|
|
void **interface)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
2016-07-30 20:35:34 +02:00
|
|
|
SpaAudioTestSrc *this;
|
|
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (interface != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this = (SpaAudioTestSrc *) handle;
|
|
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
if (interface_id == this->type.node)
|
2016-10-07 13:14:32 +02:00
|
|
|
*interface = &this->node;
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (interface_id == this->type.clock)
|
2016-10-07 13:14:32 +02:00
|
|
|
*interface = &this->clock;
|
|
|
|
|
else
|
|
|
|
|
return SPA_RESULT_UNKNOWN_INTERFACE;
|
|
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 10:04:25 +02:00
|
|
|
static SpaResult
|
|
|
|
|
audiotestsrc_clear (SpaHandle *handle)
|
|
|
|
|
{
|
2016-09-19 19:17:59 +02:00
|
|
|
SpaAudioTestSrc *this;
|
|
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-09-19 19:17:59 +02:00
|
|
|
|
|
|
|
|
this = (SpaAudioTestSrc *) handle;
|
|
|
|
|
|
2017-04-04 09:40:12 +02:00
|
|
|
if (this->data_loop)
|
|
|
|
|
spa_loop_remove_source (this->data_loop, &this->timer_source);
|
2016-11-18 17:46:01 +01:00
|
|
|
close (this->timer_source.fd);
|
2016-09-19 19:17:59 +02:00
|
|
|
|
2016-09-01 10:04:25 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-13 18:29:55 +02:00
|
|
|
static SpaResult
|
|
|
|
|
audiotestsrc_init (const SpaHandleFactory *factory,
|
2016-09-15 11:49:34 +02:00
|
|
|
SpaHandle *handle,
|
2016-10-05 17:43:11 +02:00
|
|
|
const SpaDict *info,
|
2016-10-07 13:14:32 +02:00
|
|
|
const SpaSupport *support,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_support)
|
2016-06-28 12:21:56 +02:00
|
|
|
{
|
|
|
|
|
SpaAudioTestSrc *this;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (handle != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2016-06-28 12:21:56 +02:00
|
|
|
handle->get_interface = spa_audiotestsrc_get_interface;
|
2016-09-01 10:04:25 +02:00
|
|
|
handle->clear = audiotestsrc_clear;
|
2016-06-28 12:21:56 +02:00
|
|
|
|
|
|
|
|
this = (SpaAudioTestSrc *) handle;
|
2016-10-07 13:14:32 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < n_support; i++) {
|
2017-03-24 11:40:58 +01:00
|
|
|
if (strcmp (support[i].type, SPA_TYPE__TypeMap) == 0)
|
2016-10-07 13:14:32 +02:00
|
|
|
this->map = support[i].data;
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
2016-10-07 13:14:32 +02:00
|
|
|
this->log = support[i].data;
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (strcmp (support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
|
2016-10-07 17:10:46 +02:00
|
|
|
this->data_loop = support[i].data;
|
2016-10-07 13:14:32 +02:00
|
|
|
}
|
|
|
|
|
if (this->map == NULL) {
|
2017-03-24 11:40:58 +01:00
|
|
|
spa_log_error (this->log, "a type-map is needed");
|
2016-10-07 13:14:32 +02:00
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
}
|
2017-03-24 11:40:58 +01:00
|
|
|
init_type (&this->type, this->map);
|
2016-10-07 13:14:32 +02:00
|
|
|
|
2016-07-30 20:35:34 +02:00
|
|
|
this->node = audiotestsrc_node;
|
2016-09-19 19:17:59 +02:00
|
|
|
this->clock = audiotestsrc_clock;
|
2017-03-23 12:38:00 +01:00
|
|
|
reset_audiotestsrc_props (this, &this->props);
|
2016-06-28 12:21:56 +02:00
|
|
|
|
2016-11-09 12:57:51 +01:00
|
|
|
spa_list_init (&this->empty);
|
2016-09-19 13:14:14 +02:00
|
|
|
|
2016-11-18 17:46:01 +01:00
|
|
|
this->timer_source.func = audiotestsrc_on_output;
|
|
|
|
|
this->timer_source.data = this;
|
2017-04-03 16:54:44 +02:00
|
|
|
this->timer_source.fd = timerfd_create (CLOCK_MONOTONIC, TFD_CLOEXEC);
|
2016-12-20 19:13:04 +01:00
|
|
|
this->timer_source.mask = SPA_IO_IN;
|
|
|
|
|
this->timer_source.rmask = 0;
|
2016-09-19 13:14:14 +02:00
|
|
|
this->timerspec.it_value.tv_sec = 0;
|
|
|
|
|
this->timerspec.it_value.tv_nsec = 0;
|
|
|
|
|
this->timerspec.it_interval.tv_sec = 0;
|
|
|
|
|
this->timerspec.it_interval.tv_nsec = 0;
|
|
|
|
|
|
2017-04-04 09:40:12 +02:00
|
|
|
if (this->data_loop)
|
2017-04-03 16:54:44 +02:00
|
|
|
spa_loop_add_source (this->data_loop, &this->timer_source);
|
|
|
|
|
|
2016-08-05 19:46:37 +02:00
|
|
|
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
2016-06-28 12:21:56 +02:00
|
|
|
SPA_PORT_INFO_FLAG_NO_REF;
|
2017-02-28 10:48:53 +01:00
|
|
|
if (this->props.live)
|
2016-09-19 13:14:14 +02:00
|
|
|
this->info.flags |= SPA_PORT_INFO_FLAG_LIVE;
|
|
|
|
|
|
2017-05-11 16:11:08 +02:00
|
|
|
spa_log_info (this->log, "audiotestsrc %p: initialized", this);
|
2017-04-03 16:54:44 +02:00
|
|
|
|
2016-07-13 18:29:55 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const SpaInterfaceInfo audiotestsrc_interfaces[] =
|
|
|
|
|
{
|
2017-03-23 21:15:52 +01:00
|
|
|
{ SPA_TYPE__Node, },
|
|
|
|
|
{ SPA_TYPE__Clock, },
|
2016-07-13 18:29:55 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static SpaResult
|
|
|
|
|
audiotestsrc_enum_interface_info (const SpaHandleFactory *factory,
|
2016-07-15 18:22:29 +02:00
|
|
|
const SpaInterfaceInfo **info,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-07-13 18:29:55 +02:00
|
|
|
{
|
2017-04-04 09:00:49 +02:00
|
|
|
spa_return_val_if_fail (factory != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (info != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
2016-07-13 18:29:55 +02:00
|
|
|
|
2016-07-15 18:22:29 +02:00
|
|
|
switch (index) {
|
|
|
|
|
case 0:
|
|
|
|
|
*info = &audiotestsrc_interfaces[index];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
}
|
2016-07-13 18:29:55 +02:00
|
|
|
return SPA_RESULT_OK;
|
2016-06-28 12:21:56 +02:00
|
|
|
}
|
2016-07-13 18:29:55 +02:00
|
|
|
|
|
|
|
|
const SpaHandleFactory spa_audiotestsrc_factory =
|
|
|
|
|
{ "audiotestsrc",
|
|
|
|
|
NULL,
|
|
|
|
|
sizeof (SpaAudioTestSrc),
|
|
|
|
|
audiotestsrc_init,
|
|
|
|
|
audiotestsrc_enum_interface_info,
|
|
|
|
|
};
|