clock: remove clock interface

Remove the clock interface, we need to get timing information with an io
area to get the required precision and performance.
This commit is contained in:
Wim Taymans 2018-07-17 09:50:51 +02:00
parent 83bb8dc599
commit fba00fb791
22 changed files with 31 additions and 516 deletions

View file

@ -556,6 +556,8 @@ impl_node_port_set_io(struct spa_node *node,
this->io = data;
else if (id == t->io.ControlRange)
this->range = data;
else if (id == t->io.Clock)
this->clock = data;
else
return -ENOENT;

View file

@ -577,6 +577,8 @@ impl_node_port_set_io(struct spa_node *node,
if (id == t->io.Buffers)
this->io = data;
else if (id == t->io.Clock)
this->clock = data;
else
return -ENOENT;
@ -678,50 +680,6 @@ static const struct spa_node impl_node = {
impl_node_process,
};
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return -ENOTSUP;
}
static int impl_clock_get_time(struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
{
struct state *this;
spa_return_val_if_fail(clock != NULL, -EINVAL);
this = SPA_CONTAINER_OF(clock, struct state, clock);
if (rate)
*rate = SPA_USEC_PER_SEC;
if (ticks)
*ticks = this->last_ticks;
if (monotonic_time)
*monotonic_time = this->last_monotonic;
return 0;
}
static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct state *this;
@ -733,8 +691,6 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
if (interface_id == this->type.node)
*interface = &this->node;
else if (interface_id == this->type.clock)
*interface = &this->clock;
else
return -ENOENT;
@ -796,7 +752,6 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&this->type, this->map);
this->node = impl_node;
this->clock = impl_clock;
this->stream = SND_PCM_STREAM_CAPTURE;
reset_props(&this->props);
@ -818,7 +773,6 @@ impl_init(const struct spa_handle_factory *factory,
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_TYPE__Clock,},
};
static int

View file

@ -487,7 +487,7 @@ push_frames(struct state *state,
if (b->h) {
b->h->seq = state->sample_count;
b->h->pts = state->last_monotonic;
b->h->pts = SPA_TIMESPEC_TO_TIME(&state->now);
b->h->dts_offset = 0;
}
@ -562,8 +562,11 @@ static void alsa_on_playback_timeout_event(struct spa_source *source)
state->filled = state->buffer_frames - avail;
state->last_ticks = state->sample_count - state->filled;
state->last_monotonic = (int64_t) state->now.tv_sec * SPA_NSEC_PER_SEC + (int64_t) state->now.tv_nsec;
if (state->clock) {
state->clock->nsec = SPA_TIMESPEC_TO_TIME(&state->now);
state->clock->rate = SPA_FRACTION(state->rate, 1);
state->clock->position = state->sample_count - state->filled;
}
spa_log_trace(state->log, "timeout %ld %d %ld %ld %ld", state->filled, state->threshold,
state->sample_count, state->now.tv_sec, state->now.tv_nsec);
@ -616,7 +619,6 @@ static void alsa_on_capture_timeout_event(struct spa_source *source)
snd_pcm_status_t *status;
struct timespec now;
if (state->started && read(state->timerfd, &exp, sizeof(uint64_t)) != sizeof(uint64_t))
spa_log_warn(state->log, "error reading timerfd: %s", strerror(errno));
@ -631,8 +633,11 @@ static void alsa_on_capture_timeout_event(struct spa_source *source)
snd_pcm_status_get_htstamp(status, &state->now);
clock_gettime(CLOCK_MONOTONIC, &now);
state->last_ticks = state->sample_count + avail;
state->last_monotonic = (int64_t) state->now.tv_sec * SPA_NSEC_PER_SEC + (int64_t) state->now.tv_nsec;
if (state->clock) {
state->clock->nsec = SPA_TIMESPEC_TO_TIME(&state->now);
state->clock->rate = SPA_FRACTION(state->rate, 1);
state->clock->position = state->sample_count + avail;
}
spa_log_trace(state->log, "timeout %ld %d %ld %ld %ld %ld %ld", avail, state->threshold,
state->sample_count, state->now.tv_sec, state->now.tv_nsec,

View file

@ -33,7 +33,6 @@ extern "C" {
#include <spa/support/log.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/buffers.h>
@ -63,7 +62,6 @@ struct buffer {
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_device;
@ -89,7 +87,6 @@ struct type {
static inline void 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);
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_device = spa_type_map_get_id(map, SPA_TYPE_PROPS__device);
@ -116,7 +113,6 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
struct state {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
uint32_t seq;
@ -150,6 +146,7 @@ struct state {
struct spa_port_info info;
struct spa_io_buffers *io;
struct spa_io_control_range *range;
struct spa_io_clock *clock;
struct buffer buffers[MAX_BUFFERS];
unsigned int n_buffers;
@ -168,8 +165,6 @@ struct state {
snd_htimestamp_t now;
int64_t sample_count;
int64_t filled;
int64_t last_ticks;
int64_t last_monotonic;
uint64_t underrun;
};

View file

@ -28,7 +28,6 @@
#include <spa/support/log.h>
#include <spa/support/loop.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/audio/format-utils.h>
@ -46,7 +45,6 @@
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_live;
@ -74,7 +72,6 @@ struct type {
static inline void 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);
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);
@ -141,7 +138,6 @@ typedef int (*render_func_t) (struct impl *this, void *samples, size_t n_samples
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
struct type type;
struct spa_type_map *map;
@ -1069,52 +1065,6 @@ static const struct spa_node impl_node = {
impl_node_process,
};
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod **param, struct spa_pod_builder *builder)
{
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return -ENOTSUP;
}
static int
impl_clock_get_time(struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
{
struct timespec now;
uint64_t tnow;
spa_return_val_if_fail(clock != NULL, -EINVAL);
if (rate)
*rate = SPA_NSEC_PER_SEC;
clock_gettime(CLOCK_MONOTONIC, &now);
tnow = SPA_TIMESPEC_TO_TIME(&now);
if (ticks)
*ticks = tnow;
if (monotonic_time)
*monotonic_time = tnow;
return 0;
}
static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
@ -1126,8 +1076,6 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
if (interface_id == this->type.node)
*interface = &this->node;
else if (interface_id == this->type.clock)
*interface = &this->clock;
else
return -ENOENT;
@ -1189,7 +1137,6 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&this->type, this->map);
this->node = impl_node;
this->clock = impl_clock;
reset_props(&this->props);
this->io_wave = &this->props.wave;
@ -1222,7 +1169,6 @@ impl_init(const struct spa_handle_factory *factory,
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_TYPE__Clock,},
};
static int

View file

@ -29,7 +29,6 @@
#include <spa/support/log.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/buffers.h>
@ -62,7 +61,6 @@ struct buffer {
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_min_latency;
@ -85,7 +83,6 @@ struct type {
static inline void 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);
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency);
@ -109,7 +106,6 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
uint32_t seq;

View file

@ -28,7 +28,6 @@
#include <spa/support/log.h>
#include <spa/support/loop.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/buffers.h>
@ -42,7 +41,6 @@
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_live;
@ -59,7 +57,6 @@ struct type {
static inline void 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);
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);
@ -90,7 +87,6 @@ struct buffer {
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
struct type type;
struct spa_type_map *map;
@ -763,52 +759,6 @@ static const struct spa_node impl_node = {
impl_node_process,
};
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod **param, struct spa_pod_builder *builder)
{
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return -ENOTSUP;
}
static int
impl_clock_get_time(struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
{
struct timespec now;
uint64_t tnow;
spa_return_val_if_fail(clock != NULL, -EINVAL);
if (rate)
*rate = SPA_NSEC_PER_SEC;
clock_gettime(CLOCK_MONOTONIC, &now);
tnow = SPA_TIMESPEC_TO_TIME(&now);
if (ticks)
*ticks = tnow;
if (monotonic_time)
*monotonic_time = tnow;
return 0;
}
static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
@ -820,8 +770,6 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
if (interface_id == this->type.node)
*interface = &this->node;
else if (interface_id == this->type.clock)
*interface = &this->clock;
else
return -ENOENT;
@ -883,7 +831,6 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&this->type, this->map);
this->node = impl_node;
this->clock = impl_clock;
reset_props(this, &this->props);
spa_list_init(&this->ready);
@ -912,7 +859,6 @@ impl_init(const struct spa_handle_factory *factory,
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_TYPE__Clock,},
};
static int

View file

@ -28,7 +28,6 @@
#include <spa/support/log.h>
#include <spa/support/loop.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/buffers.h>
@ -42,7 +41,6 @@
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_live;
@ -60,7 +58,6 @@ struct type {
static inline void 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);
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);
@ -93,7 +90,6 @@ struct buffer {
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
struct type type;
struct spa_type_map *map;
@ -795,52 +791,6 @@ static const struct spa_node impl_node = {
impl_node_process,
};
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod **param, struct spa_pod_builder *builder)
{
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return -ENOTSUP;
}
static int
impl_clock_get_time(struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
{
struct timespec now;
uint64_t tnow;
spa_return_val_if_fail(clock != NULL, -EINVAL);
if (rate)
*rate = SPA_NSEC_PER_SEC;
clock_gettime(CLOCK_MONOTONIC, &now);
tnow = SPA_TIMESPEC_TO_TIME(&now);
if (ticks)
*ticks = tnow;
if (monotonic_time)
*monotonic_time = tnow;
return 0;
}
static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
@ -852,8 +802,6 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
if (interface_id == this->type.node)
*interface = &this->node;
else if (interface_id == this->type.clock)
*interface = &this->clock;
else
return -ENOENT;
@ -915,7 +863,6 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&this->type, this->map);
this->node = impl_node;
this->clock = impl_clock;
reset_props(this, &this->props);
spa_list_init(&this->empty);
@ -944,7 +891,6 @@ impl_init(const struct spa_handle_factory *factory,
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_TYPE__Clock,},
};
static int

View file

@ -28,7 +28,6 @@
#include <spa/support/log.h>
#include <spa/support/loop.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/video/format-utils.h>
@ -71,7 +70,6 @@ struct buffer {
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_unknown;
@ -105,7 +103,6 @@ struct type {
static inline void 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);
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_unknown = spa_type_map_get_id(map, SPA_TYPE_PROPS__unknown);
@ -189,7 +186,6 @@ struct port {
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
struct spa_type_map *map;
struct spa_log *log;
@ -905,52 +901,6 @@ static const struct spa_node impl_node = {
impl_node_process,
};
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock,
uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return -ENOTSUP;
}
static int impl_clock_get_time(struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
{
struct impl *this;
struct port *port;
spa_return_val_if_fail(clock != NULL, -EINVAL);
this = SPA_CONTAINER_OF(clock, struct impl, clock);
port = GET_OUT_PORT(this, 0);
if (rate)
*rate = SPA_USEC_PER_SEC;
if (ticks)
*ticks = port->last_ticks;
if (monotonic_time)
*monotonic_time = port->last_monotonic;
return 0;
}
static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
@ -962,8 +912,6 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
if (interface_id == this->type.node)
*interface = &this->node;
else if (interface_id == this->type.clock)
*interface = &this->clock;
else
return -ENOENT;
@ -1028,7 +976,6 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&this->type, this->map);
this->node = impl_node;
this->clock = impl_clock;
reset_props(&this->props);
@ -1053,7 +1000,6 @@ impl_init(const struct spa_handle_factory *factory,
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_TYPE__Clock,},
};
static int impl_enum_interface_info(const struct spa_handle_factory *factory,

View file

@ -29,7 +29,6 @@
#include <spa/support/log.h>
#include <spa/support/loop.h>
#include <spa/utils/list.h>
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/video/format-utils.h>
@ -45,7 +44,6 @@
struct type {
uint32_t node;
uint32_t clock;
uint32_t format;
uint32_t props;
uint32_t prop_live;
@ -67,7 +65,6 @@ struct type {
static inline void 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);
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);
@ -118,7 +115,6 @@ struct buffer {
struct impl {
struct spa_handle handle;
struct spa_node node;
struct spa_clock clock;
struct type type;
struct spa_type_map *map;
@ -908,53 +904,6 @@ static const struct spa_node impl_node = {
impl_node_process,
};
static int impl_clock_enum_params(struct spa_clock *clock, uint32_t id, uint32_t *index,
struct spa_pod **param,
struct spa_pod_builder *builder)
{
return -ENOTSUP;
}
static int impl_clock_set_param(struct spa_clock *clock, uint32_t id, uint32_t flags,
const struct spa_pod *param)
{
return -ENOTSUP;
}
static int
impl_clock_get_time(struct spa_clock *clock,
int32_t *rate,
int64_t *ticks,
int64_t *monotonic_time)
{
struct timespec now;
uint64_t tnow;
spa_return_val_if_fail(clock != NULL, -EINVAL);
if (rate)
*rate = SPA_NSEC_PER_SEC;
clock_gettime(CLOCK_MONOTONIC, &now);
tnow = SPA_TIMESPEC_TO_TIME(&now);
if (ticks)
*ticks = tnow;
if (monotonic_time)
*monotonic_time = tnow;
return 0;
}
static const struct spa_clock impl_clock = {
SPA_VERSION_CLOCK,
NULL,
SPA_CLOCK_STATE_STOPPED,
impl_clock_enum_params,
impl_clock_set_param,
impl_clock_get_time,
};
static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id, void **interface)
{
struct impl *this;
@ -966,8 +915,6 @@ static int impl_get_interface(struct spa_handle *handle, uint32_t interface_id,
if (interface_id == this->type.node)
*interface = &this->node;
else if (interface_id == this->type.clock)
*interface = &this->clock;
else
return -ENOENT;
@ -1029,7 +976,6 @@ impl_init(const struct spa_handle_factory *factory,
init_type(&this->type, this->map);
this->node = impl_node;
this->clock = impl_clock;
reset_props(&this->props);
spa_list_init(&this->empty);
@ -1058,7 +1004,6 @@ impl_init(const struct spa_handle_factory *factory,
static const struct spa_interface_info impl_interfaces[] = {
{SPA_TYPE__Node,},
{SPA_TYPE__Clock,},
};
static int