plugins: small cleanups

This commit is contained in:
Wim Taymans 2017-04-04 09:40:12 +02:00
parent b05d82d514
commit 032cc69f2f
5 changed files with 62 additions and 41 deletions

View file

@ -474,7 +474,7 @@ spa_debug_dict (const SpaDict *dict)
}
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_DEBUG
#define DEFAULT_LOG_LEVEL SPA_LOG_LEVEL_INFO
static void
do_logv (SpaLog *log,

View file

@ -408,15 +408,10 @@ calc_timeout (size_t target,
snd_htimestamp_t *now,
struct timespec *ts)
{
size_t to_sleep_nsec;
ts->tv_sec = now->tv_sec;
ts->tv_nsec = now->tv_nsec;
if (target > current)
to_sleep_nsec = (target - current) * SPA_NSEC_PER_SEC / rate;
else
to_sleep_nsec = 0;
ts->tv_nsec = to_sleep_nsec + now->tv_nsec;
ts->tv_nsec += (target - current) * SPA_NSEC_PER_SEC / rate;
while (ts->tv_nsec > SPA_NSEC_PER_SEC) {
ts->tv_sec++;
@ -458,7 +453,7 @@ alsa_on_playback_timeout_event (SpaSource *source)
state->last_ticks = state->sample_count - filled;
state->last_monotonic = (int64_t)htstamp.tv_sec * SPA_NSEC_PER_SEC + (int64_t)htstamp.tv_nsec;
if (filled > state->threshold + 16) {
if (filled > state->threshold) {
if (snd_pcm_state (hndl) == SND_PCM_STATE_SUSPENDED) {
spa_log_error (state->log, "suspended: try resume");
if ((res = alsa_try_resume (state)) < 0)
@ -495,7 +490,7 @@ alsa_on_playback_timeout_event (SpaSource *source)
state->sample_count += total_written;
}
if (!state->alsa_started && total_written > 0) {
spa_log_trace (state->log, "snd_pcm_start");
spa_log_debug (state->log, "snd_pcm_start");
if ((res = snd_pcm_start (state->hndl)) < 0) {
spa_log_error (state->log, "snd_pcm_start: %s", snd_strerror (res));
return;

View file

@ -248,20 +248,33 @@ send_have_output (SpaAudioTestSrc *this)
static void
set_timer (SpaAudioTestSrc *this, bool enabled)
{
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;
if (this->async || this->props.live) {
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;
}
} else {
this->timerspec.it_value.tv_sec = 0;
this->timerspec.it_value.tv_nsec = 1;
this->timerspec.it_value.tv_nsec = 0;
}
} else {
this->timerspec.it_value.tv_sec = 0;
this->timerspec.it_value.tv_nsec = 0;
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
}
}
static void
read_timer (SpaAudioTestSrc *this)
{
uint64_t expirations;
if (this->async || this->props.live) {
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
perror ("read timerfd");
}
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
}
static SpaResult
@ -269,11 +282,9 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this)
{
ATSBuffer *b;
SpaPortIO *io = this->io;
uint64_t expirations;
int n_bytes, n_samples;
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
perror ("read timerfd");
read_timer (this);
if (spa_list_is_empty (&this->empty)) {
set_timer (this, false);
@ -942,7 +953,8 @@ audiotestsrc_clear (SpaHandle *handle)
this = (SpaAudioTestSrc *) handle;
spa_loop_remove_source (this->data_loop, &this->timer_source);
if (this->data_loop)
spa_loop_remove_source (this->data_loop, &this->timer_source);
close (this->timer_source.fd);
return SPA_RESULT_OK;
@ -1006,7 +1018,7 @@ audiotestsrc_init (const SpaHandleFactory *factory,
this->timerspec.it_interval.tv_sec = 0;
this->timerspec.it_interval.tv_nsec = 0;
if (this->data_loop && this->async)
if (this->data_loop)
spa_loop_add_source (this->data_loop, &this->timer_source);
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |

View file

@ -236,20 +236,33 @@ fill_buffer (SpaVideoTestSrc *this, VTSBuffer *b)
static void
set_timer (SpaVideoTestSrc *this, bool enabled)
{
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;
if (this->async || this->props.live) {
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;
}
} else {
this->timerspec.it_value.tv_sec = 0;
this->timerspec.it_value.tv_nsec = 1;
this->timerspec.it_value.tv_nsec = 0;
}
} else {
this->timerspec.it_value.tv_sec = 0;
this->timerspec.it_value.tv_nsec = 0;
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
}
}
static void
read_timer (SpaVideoTestSrc *this)
{
uint64_t expirations;
if (this->async || this->props.live) {
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
perror ("read timerfd");
}
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
}
static SpaResult
@ -257,11 +270,9 @@ videotestsrc_make_buffer (SpaVideoTestSrc *this)
{
VTSBuffer *b;
SpaPortIO *io = this->io;
uint64_t expirations;
int n_bytes;
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
perror ("read timerfd");
read_timer (this);
if (spa_list_is_empty (&this->empty)) {
set_timer (this, false);
@ -927,7 +938,8 @@ videotestsrc_clear (SpaHandle *handle)
this = (SpaVideoTestSrc *) handle;
spa_loop_remove_source (this->data_loop, &this->timer_source);
if (this->data_loop)
spa_loop_remove_source (this->data_loop, &this->timer_source);
close (this->timer_source.fd);
return SPA_RESULT_OK;
@ -991,7 +1003,7 @@ videotestsrc_init (const SpaHandleFactory *factory,
this->timerspec.it_interval.tv_sec = 0;
this->timerspec.it_interval.tv_nsec = 0;
if (this->data_loop && this->async)
if (this->data_loop)
spa_loop_add_source (this->data_loop, &this->timer_source);
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |

View file

@ -302,7 +302,7 @@ make_nodes (AppData *data)
spa_pod_builder_init (&b, buffer, sizeof (buffer));
spa_pod_builder_props (&b, &f[0], data->type.props,
SPA_POD_PROP (&f[1], data->type.props_device, 0, SPA_POD_TYPE_STRING, 1, "hw:0"),
SPA_POD_PROP (&f[1], data->type.props_min_latency, 0, SPA_POD_TYPE_INT, 1, 1024),
SPA_POD_PROP (&f[1], data->type.props_min_latency, 0, SPA_POD_TYPE_INT, 1, 256),
SPA_POD_PROP (&f[1], data->type.props_live, 0, SPA_POD_TYPE_BOOL, 1, false));
props = SPA_POD_BUILDER_DEREF (&b, f[0].ref, SpaProps);
@ -557,6 +557,8 @@ main (int argc, char *argv[])
data.data_loop.remove_source = do_remove_source;
data.data_loop.invoke = do_invoke;
// data.log->level = SPA_LOG_LEVEL_TRACE;
data.support[0].type = SPA_TYPE__TypeMap;
data.support[0].data = data.map;
data.support[1].type = SPA_TYPE__Log;