mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-12-16 08:56:45 -05:00
plugins: small cleanups
This commit is contained in:
parent
b05d82d514
commit
032cc69f2f
5 changed files with 62 additions and 41 deletions
|
|
@ -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
|
static void
|
||||||
do_logv (SpaLog *log,
|
do_logv (SpaLog *log,
|
||||||
|
|
|
||||||
|
|
@ -408,15 +408,10 @@ calc_timeout (size_t target,
|
||||||
snd_htimestamp_t *now,
|
snd_htimestamp_t *now,
|
||||||
struct timespec *ts)
|
struct timespec *ts)
|
||||||
{
|
{
|
||||||
size_t to_sleep_nsec;
|
|
||||||
|
|
||||||
ts->tv_sec = now->tv_sec;
|
ts->tv_sec = now->tv_sec;
|
||||||
|
ts->tv_nsec = now->tv_nsec;
|
||||||
if (target > current)
|
if (target > current)
|
||||||
to_sleep_nsec = (target - current) * SPA_NSEC_PER_SEC / rate;
|
ts->tv_nsec += (target - current) * SPA_NSEC_PER_SEC / rate;
|
||||||
else
|
|
||||||
to_sleep_nsec = 0;
|
|
||||||
|
|
||||||
ts->tv_nsec = to_sleep_nsec + now->tv_nsec;
|
|
||||||
|
|
||||||
while (ts->tv_nsec > SPA_NSEC_PER_SEC) {
|
while (ts->tv_nsec > SPA_NSEC_PER_SEC) {
|
||||||
ts->tv_sec++;
|
ts->tv_sec++;
|
||||||
|
|
@ -458,7 +453,7 @@ alsa_on_playback_timeout_event (SpaSource *source)
|
||||||
state->last_ticks = state->sample_count - filled;
|
state->last_ticks = state->sample_count - filled;
|
||||||
state->last_monotonic = (int64_t)htstamp.tv_sec * SPA_NSEC_PER_SEC + (int64_t)htstamp.tv_nsec;
|
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) {
|
if (snd_pcm_state (hndl) == SND_PCM_STATE_SUSPENDED) {
|
||||||
spa_log_error (state->log, "suspended: try resume");
|
spa_log_error (state->log, "suspended: try resume");
|
||||||
if ((res = alsa_try_resume (state)) < 0)
|
if ((res = alsa_try_resume (state)) < 0)
|
||||||
|
|
@ -495,7 +490,7 @@ alsa_on_playback_timeout_event (SpaSource *source)
|
||||||
state->sample_count += total_written;
|
state->sample_count += total_written;
|
||||||
}
|
}
|
||||||
if (!state->alsa_started && total_written > 0) {
|
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) {
|
if ((res = snd_pcm_start (state->hndl)) < 0) {
|
||||||
spa_log_error (state->log, "snd_pcm_start: %s", snd_strerror (res));
|
spa_log_error (state->log, "snd_pcm_start: %s", snd_strerror (res));
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -248,20 +248,33 @@ send_have_output (SpaAudioTestSrc *this)
|
||||||
static void
|
static void
|
||||||
set_timer (SpaAudioTestSrc *this, bool enabled)
|
set_timer (SpaAudioTestSrc *this, bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (this->async || this->props.live) {
|
||||||
if (this->props.live) {
|
if (enabled) {
|
||||||
uint64_t next_time = this->start_time + this->elapsed_time;
|
if (this->props.live) {
|
||||||
this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
|
uint64_t next_time = this->start_time + this->elapsed_time;
|
||||||
this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
|
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 {
|
} else {
|
||||||
this->timerspec.it_value.tv_sec = 0;
|
this->timerspec.it_value.tv_sec = 0;
|
||||||
this->timerspec.it_value.tv_nsec = 1;
|
this->timerspec.it_value.tv_nsec = 0;
|
||||||
}
|
}
|
||||||
} else {
|
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||||
this->timerspec.it_value.tv_sec = 0;
|
}
|
||||||
this->timerspec.it_value.tv_nsec = 0;
|
}
|
||||||
|
|
||||||
|
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
|
static SpaResult
|
||||||
|
|
@ -269,11 +282,9 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this)
|
||||||
{
|
{
|
||||||
ATSBuffer *b;
|
ATSBuffer *b;
|
||||||
SpaPortIO *io = this->io;
|
SpaPortIO *io = this->io;
|
||||||
uint64_t expirations;
|
|
||||||
int n_bytes, n_samples;
|
int n_bytes, n_samples;
|
||||||
|
|
||||||
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
read_timer (this);
|
||||||
perror ("read timerfd");
|
|
||||||
|
|
||||||
if (spa_list_is_empty (&this->empty)) {
|
if (spa_list_is_empty (&this->empty)) {
|
||||||
set_timer (this, false);
|
set_timer (this, false);
|
||||||
|
|
@ -942,7 +953,8 @@ audiotestsrc_clear (SpaHandle *handle)
|
||||||
|
|
||||||
this = (SpaAudioTestSrc *) 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);
|
close (this->timer_source.fd);
|
||||||
|
|
||||||
return SPA_RESULT_OK;
|
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_sec = 0;
|
||||||
this->timerspec.it_interval.tv_nsec = 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);
|
spa_loop_add_source (this->data_loop, &this->timer_source);
|
||||||
|
|
||||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||||
|
|
|
||||||
|
|
@ -236,20 +236,33 @@ fill_buffer (SpaVideoTestSrc *this, VTSBuffer *b)
|
||||||
static void
|
static void
|
||||||
set_timer (SpaVideoTestSrc *this, bool enabled)
|
set_timer (SpaVideoTestSrc *this, bool enabled)
|
||||||
{
|
{
|
||||||
if (enabled) {
|
if (this->async || this->props.live) {
|
||||||
if (this->props.live) {
|
if (enabled) {
|
||||||
uint64_t next_time = this->start_time + this->elapsed_time;
|
if (this->props.live) {
|
||||||
this->timerspec.it_value.tv_sec = next_time / SPA_NSEC_PER_SEC;
|
uint64_t next_time = this->start_time + this->elapsed_time;
|
||||||
this->timerspec.it_value.tv_nsec = next_time % SPA_NSEC_PER_SEC;
|
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 {
|
} else {
|
||||||
this->timerspec.it_value.tv_sec = 0;
|
this->timerspec.it_value.tv_sec = 0;
|
||||||
this->timerspec.it_value.tv_nsec = 1;
|
this->timerspec.it_value.tv_nsec = 0;
|
||||||
}
|
}
|
||||||
} else {
|
timerfd_settime (this->timer_source.fd, TFD_TIMER_ABSTIME, &this->timerspec, NULL);
|
||||||
this->timerspec.it_value.tv_sec = 0;
|
}
|
||||||
this->timerspec.it_value.tv_nsec = 0;
|
}
|
||||||
|
|
||||||
|
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
|
static SpaResult
|
||||||
|
|
@ -257,11 +270,9 @@ videotestsrc_make_buffer (SpaVideoTestSrc *this)
|
||||||
{
|
{
|
||||||
VTSBuffer *b;
|
VTSBuffer *b;
|
||||||
SpaPortIO *io = this->io;
|
SpaPortIO *io = this->io;
|
||||||
uint64_t expirations;
|
|
||||||
int n_bytes;
|
int n_bytes;
|
||||||
|
|
||||||
if (read (this->timer_source.fd, &expirations, sizeof (uint64_t)) < sizeof (uint64_t))
|
read_timer (this);
|
||||||
perror ("read timerfd");
|
|
||||||
|
|
||||||
if (spa_list_is_empty (&this->empty)) {
|
if (spa_list_is_empty (&this->empty)) {
|
||||||
set_timer (this, false);
|
set_timer (this, false);
|
||||||
|
|
@ -927,7 +938,8 @@ videotestsrc_clear (SpaHandle *handle)
|
||||||
|
|
||||||
this = (SpaVideoTestSrc *) 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);
|
close (this->timer_source.fd);
|
||||||
|
|
||||||
return SPA_RESULT_OK;
|
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_sec = 0;
|
||||||
this->timerspec.it_interval.tv_nsec = 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);
|
spa_loop_add_source (this->data_loop, &this->timer_source);
|
||||||
|
|
||||||
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
this->info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS |
|
||||||
|
|
|
||||||
|
|
@ -302,7 +302,7 @@ make_nodes (AppData *data)
|
||||||
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
spa_pod_builder_init (&b, buffer, sizeof (buffer));
|
||||||
spa_pod_builder_props (&b, &f[0], data->type.props,
|
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_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));
|
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);
|
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.remove_source = do_remove_source;
|
||||||
data.data_loop.invoke = do_invoke;
|
data.data_loop.invoke = do_invoke;
|
||||||
|
|
||||||
|
// data.log->level = SPA_LOG_LEVEL_TRACE;
|
||||||
|
|
||||||
data.support[0].type = SPA_TYPE__TypeMap;
|
data.support[0].type = SPA_TYPE__TypeMap;
|
||||||
data.support[0].data = data.map;
|
data.support[0].data = data.map;
|
||||||
data.support[1].type = SPA_TYPE__Log;
|
data.support[1].type = SPA_TYPE__Log;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue