diff --git a/pinos/client/stream.c b/pinos/client/stream.c index 78c36c89f..f87b9d326 100644 --- a/pinos/client/stream.c +++ b/pinos/client/stream.c @@ -1207,7 +1207,7 @@ pinos_stream_send_buffer (PinosStream *stream, bid->used = true; spa_list_remove (&bid->link); impl->trans->outputs[0].buffer_id = id; - impl->trans->outputs[0].status = SPA_RESULT_HAVE_OUTPUT; + impl->trans->outputs[0].status = SPA_RESULT_HAVE_BUFFER; pinos_log_trace ("stream %p: send buffer %d", stream, id); if (!impl->in_need_buffer) send_have_output (stream); diff --git a/pinos/server/client-node.c b/pinos/server/client-node.c index 6f8f301d7..c8cedda71 100644 --- a/pinos/server/client-node.c +++ b/pinos/server/client-node.c @@ -855,7 +855,7 @@ spa_proxy_node_process_output (SpaNode *node) pinos_log_trace ("%d %d %d %d", io->status, io->buffer_id, tmp.status, tmp.buffer_id); - if (io->status == SPA_RESULT_NEED_INPUT) + if (io->status == SPA_RESULT_NEED_BUFFER) send_need = true; *io = tmp; @@ -865,7 +865,7 @@ spa_proxy_node_process_output (SpaNode *node) else if (flush) do_flush (this); - return SPA_RESULT_HAVE_OUTPUT; + return SPA_RESULT_HAVE_BUFFER; } static SpaResult diff --git a/pinos/server/node.c b/pinos/server/node.c index f75d7a419..c82b68ca4 100644 --- a/pinos/server/node.c +++ b/pinos/server/node.c @@ -273,7 +273,7 @@ do_pull (PinosNode *this) pinos_log_trace ("node %p: need input port %d, %d %d", this, inport->port_id, pi->buffer_id, pi->status); - if (pi->status != SPA_RESULT_NEED_INPUT) + if (pi->status != SPA_RESULT_NEED_BUFFER) continue; spa_list_for_each (link, &inport->rt.links, rt.input_link) { @@ -291,15 +291,15 @@ do_pull (PinosNode *this) res = spa_node_process_output (outport->node->node); - if (res == SPA_RESULT_NEED_INPUT) { + if (res == SPA_RESULT_NEED_BUFFER) { res = do_pull (outport->node); pinos_log_trace ("node %p: pull return %d", outport->node, res); } - else if (res < 0 && res != SPA_RESULT_HAVE_OUTPUT) { + else if (res < 0 && res != SPA_RESULT_HAVE_BUFFER) { pinos_log_warn ("node %p: got process output %d", outport->node, res); } - if (res == SPA_RESULT_HAVE_OUTPUT) { + if (res == SPA_RESULT_HAVE_BUFFER) { *pi = *po; pinos_log_trace ("node %p: have output %d %d", this, pi->status, pi->buffer_id); have_output = true; @@ -360,7 +360,7 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data) } } res = spa_node_process_output (this->node); - if (res < 0 && res != SPA_RESULT_HAVE_OUTPUT) + if (res < 0 && res != SPA_RESULT_HAVE_BUFFER) pinos_log_warn ("node %p: got process output %d", this, res); } diff --git a/spa/include/spa/defs.h b/spa/include/spa/defs.h index 0c9c6cf16..706cc39c0 100644 --- a/spa/include/spa/defs.h +++ b/spa/include/spa/defs.h @@ -41,8 +41,8 @@ typedef enum { SPA_RESULT_NO_FORMAT = -4, SPA_RESULT_INVALID_COMMAND = -5, SPA_RESULT_INVALID_PORT = -6, - SPA_RESULT_HAVE_OUTPUT = -7, - SPA_RESULT_NEED_INPUT = -8, + SPA_RESULT_HAVE_BUFFER = -7, + SPA_RESULT_NEED_BUFFER = -8, SPA_RESULT_PORTS_CHANGED = -9, SPA_RESULT_FORMAT_CHANGED = -10, SPA_RESULT_PROPERTIES_CHANGED = -11, diff --git a/spa/plugins/alsa/alsa-utils.c b/spa/plugins/alsa/alsa-utils.c index 70e3940ec..7d00602ee 100644 --- a/spa/plugins/alsa/alsa-utils.c +++ b/spa/plugins/alsa/alsa-utils.c @@ -329,15 +329,16 @@ static inline snd_pcm_uframes_t pull_frames (SpaALSAState *state, const snd_pcm_channel_area_t *my_areas, snd_pcm_uframes_t offset, - snd_pcm_uframes_t frames) + snd_pcm_uframes_t frames, + bool do_pull) { snd_pcm_uframes_t total_frames = 0, to_write = frames; SpaPortIO *io = state->io; - if (spa_list_is_empty (&state->ready)) { + if (spa_list_is_empty (&state->ready) && do_pull) { SpaEvent event = SPA_EVENT_INIT (state->type.event_node.NeedInput); - io->status = SPA_RESULT_NEED_INPUT; + io->status = SPA_RESULT_NEED_BUFFER; io->range.offset = state->sample_count * state->frame_size; io->range.min_size = state->threshold * state->frame_size; io->range.max_size = frames * state->frame_size; @@ -401,9 +402,9 @@ pull_frames (SpaALSAState *state, total_frames += n_frames; to_write -= n_frames; } - if (total_frames == 0) { + if (total_frames == 0 && do_pull) { total_frames = SPA_MIN (frames, state->threshold); - spa_log_warn (state->log, "underrun, want %zd frames", total_frames); + spa_log_trace (state->log, "underrun, want %zd frames", total_frames); snd_pcm_areas_silence (my_areas, offset, state->channels, total_frames, state->format); } return total_frames; @@ -419,7 +420,7 @@ push_frames (SpaALSAState *state, SpaPortIO *io = state->io; if (spa_list_is_empty (&state->free)) { - spa_log_warn (state->log, "no more buffers"); + spa_log_trace (state->log, "no more buffers"); } else { uint8_t *src; @@ -529,6 +530,9 @@ 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; + spa_log_trace (state->log, "timeout %ld %d %ld %ld %ld", filled, state->threshold, + state->sample_count, htstamp.tv_sec, htstamp.tv_nsec); + if (filled > state->threshold) { if (snd_pcm_state (hndl) == SND_PCM_STATE_SUSPENDED) { spa_log_error (state->log, "suspended: try resume"); @@ -538,6 +542,7 @@ alsa_on_playback_timeout_event (SpaSource *source) } else { snd_pcm_uframes_t to_write = state->buffer_frames - filled; + bool do_pull = true; while (total_written < to_write) { snd_pcm_uframes_t written, frames, offset; @@ -547,9 +552,7 @@ alsa_on_playback_timeout_event (SpaSource *source) spa_log_error (state->log, "snd_pcm_mmap_begin error: %s", snd_strerror(res)); return; } - - written = pull_frames (state, my_areas, offset, frames); - + written = pull_frames (state, my_areas, offset, frames, do_pull); if (written < frames) to_write = 0; @@ -559,6 +562,7 @@ alsa_on_playback_timeout_event (SpaSource *source) return; } total_written += written; + do_pull = false; } state->sample_count += total_written; } @@ -573,10 +577,6 @@ alsa_on_playback_timeout_event (SpaSource *source) calc_timeout (total_written + filled, state->threshold, state->rate, &htstamp, &ts.it_value); - spa_log_trace (state->log, "timeout %ld %ld %ld %ld %ld", total_written, filled, - ts.it_value.tv_sec, ts.it_value.tv_nsec, - ts.it_value.tv_nsec - htstamp.tv_nsec); - ts.it_interval.tv_sec = 0; ts.it_interval.tv_nsec = 0; timerfd_settime (state->timerfd, TFD_TIMER_ABSTIME, &ts, NULL); diff --git a/spa/plugins/audiomixer/audiomixer.c b/spa/plugins/audiomixer/audiomixer.c index 8d00fb6a2..9fa8cc938 100644 --- a/spa/plugins/audiomixer/audiomixer.c +++ b/spa/plugins/audiomixer/audiomixer.c @@ -101,10 +101,7 @@ struct _SpaAudioMixer { uint8_t format_buffer[4096]; bool started; -#define STATE_ERROR 0 -#define STATE_IN 1 -#define STATE_OUT 2 - int state; + SpaResult state; }; #define CHECK_PORT_NUM(this,d,p) (((d) == SPA_DIRECTION_INPUT && (p) < MAX_PORTS) || \ @@ -666,16 +663,14 @@ mix_output (SpaAudioMixer *this, size_t n_bytes) add_port_data (this, outbuf, port, layer++); } output->buffer_id = outbuf->outbuf->id; - output->status = SPA_RESULT_HAVE_OUTPUT; - this->state = STATE_OUT; + output->status = SPA_RESULT_HAVE_BUFFER; - return SPA_RESULT_HAVE_OUTPUT; + return SPA_RESULT_HAVE_BUFFER; } static SpaResult spa_audiomixer_node_process_input (SpaNode *node) { - SpaResult res; SpaAudioMixer *this; uint32_t i; SpaAudioMixerPort *outport; @@ -690,8 +685,8 @@ spa_audiomixer_node_process_input (SpaNode *node) output = outport->io; spa_return_val_if_fail (output != NULL, SPA_RESULT_ERROR); - if (this->state == STATE_OUT) - return SPA_RESULT_HAVE_OUTPUT; + if (this->state == SPA_RESULT_HAVE_BUFFER) + return SPA_RESULT_HAVE_BUFFER; for (i = 0; i < MAX_PORTS; i++) { SpaAudioMixerPort *port = &this->in_ports[i]; @@ -701,7 +696,7 @@ spa_audiomixer_node_process_input (SpaNode *node) continue; if (port->queued_bytes == 0 && - input->status == SPA_RESULT_HAVE_OUTPUT && + input->status == SPA_RESULT_HAVE_BUFFER && input->buffer_id != SPA_ID_INVALID) { MixerBuffer *b = &port->buffers[input->buffer_id]; @@ -724,17 +719,16 @@ spa_audiomixer_node_process_input (SpaNode *node) } if (min_queued != SIZE_MAX && min_queued > 0) { - res = mix_output (this, min_queued); + this->state = mix_output (this, min_queued); } else { - res = SPA_RESULT_NEED_INPUT; + this->state = SPA_RESULT_NEED_BUFFER; } - return res; + return this->state; } static SpaResult spa_audiomixer_node_process_output (SpaNode *node) { - SpaResult res; SpaAudioMixer *this; SpaAudioMixerPort *port; SpaPortIO *output; @@ -753,9 +747,8 @@ spa_audiomixer_node_process_output (SpaNode *node) recycle_buffer (this, output->buffer_id); output->buffer_id = SPA_ID_INVALID; } - res = SPA_RESULT_NEED_INPUT; /* produce more output if possible */ - if (this->state == STATE_OUT) { + if (this->state == SPA_RESULT_HAVE_BUFFER) { size_t min_queued = SIZE_MAX; for (i = 0; i < MAX_PORTS; i++) { @@ -768,13 +761,13 @@ spa_audiomixer_node_process_output (SpaNode *node) min_queued = port->queued_bytes; } if (min_queued != SIZE_MAX && min_queued > 0) { - res = mix_output (this, min_queued); + this->state = mix_output (this, min_queued); } else { - this->state = STATE_IN; + this->state = SPA_RESULT_NEED_BUFFER; } } /* take requested output range and apply to input */ - if (this->state == STATE_IN) { + if (this->state == SPA_RESULT_NEED_BUFFER) { for (i = 0; i < MAX_PORTS; i++) { SpaAudioMixerPort *port = &this->in_ports[i]; SpaPortIO *input; @@ -784,7 +777,7 @@ spa_audiomixer_node_process_output (SpaNode *node) if (port->queued_bytes == 0) { input->range = output->range; - input->status = SPA_RESULT_NEED_INPUT; + input->status = SPA_RESULT_NEED_BUFFER; } else { input->status = SPA_RESULT_OK; @@ -793,7 +786,7 @@ spa_audiomixer_node_process_output (SpaNode *node) i, output->range.min_size, port->queued_bytes, input->status); } } - return res; + return this->state; } static const SpaNode audiomixer_node = { @@ -879,7 +872,7 @@ spa_audiomixer_init (const SpaHandleFactory *factory, init_type (&this->type, this->map); this->node = audiomixer_node; - this->state = STATE_IN; + this->state = SPA_RESULT_NEED_BUFFER; this->out_ports[0].io = NULL; this->out_ports[0].info.flags = SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS | diff --git a/spa/plugins/audiotestsrc/audiotestsrc.c b/spa/plugins/audiotestsrc/audiotestsrc.c index cc9e0d2b3..f26cb859e 100644 --- a/spa/plugins/audiotestsrc/audiotestsrc.c +++ b/spa/plugins/audiotestsrc/audiotestsrc.c @@ -348,9 +348,9 @@ audiotestsrc_make_buffer (SpaAudioTestSrc *this) set_timer (this, true); io->buffer_id = b->outbuf->id; - io->status = SPA_RESULT_HAVE_OUTPUT; + io->status = SPA_RESULT_HAVE_BUFFER; - return SPA_RESULT_HAVE_OUTPUT; + return SPA_RESULT_HAVE_BUFFER; } static void @@ -361,7 +361,7 @@ audiotestsrc_on_output (SpaSource *source) res = audiotestsrc_make_buffer (this); - if (res == SPA_RESULT_HAVE_OUTPUT) + if (res == SPA_RESULT_HAVE_BUFFER) send_have_output (this); } @@ -850,15 +850,15 @@ spa_audiotestsrc_node_process_output (SpaNode *node) io = this->io; spa_return_val_if_fail (io != NULL, SPA_RESULT_WRONG_STATE); - if (io->status == SPA_RESULT_HAVE_OUTPUT) - return SPA_RESULT_HAVE_OUTPUT; + if (io->status == SPA_RESULT_HAVE_BUFFER) + return SPA_RESULT_HAVE_BUFFER; if (io->buffer_id != SPA_ID_INVALID) { reuse_buffer (this, this->io->buffer_id); this->io->buffer_id = SPA_ID_INVALID; } - if (!this->async && (io->status == SPA_RESULT_NEED_INPUT)) + if (!this->async && (io->status == SPA_RESULT_NEED_BUFFER)) return audiotestsrc_make_buffer (this); else return SPA_RESULT_OK; diff --git a/spa/plugins/videotestsrc/videotestsrc.c b/spa/plugins/videotestsrc/videotestsrc.c index 4b6b9bb85..ad09b48aa 100644 --- a/spa/plugins/videotestsrc/videotestsrc.c +++ b/spa/plugins/videotestsrc/videotestsrc.c @@ -310,9 +310,9 @@ videotestsrc_make_buffer (SpaVideoTestSrc *this) set_timer (this, true); io->buffer_id = b->outbuf->id; - io->status = SPA_RESULT_HAVE_OUTPUT; + io->status = SPA_RESULT_HAVE_BUFFER; - return SPA_RESULT_HAVE_OUTPUT; + return SPA_RESULT_HAVE_BUFFER; } static void @@ -323,7 +323,7 @@ videotestsrc_on_output (SpaSource *source) res = videotestsrc_make_buffer (this); - if (res == SPA_RESULT_HAVE_OUTPUT) + if (res == SPA_RESULT_HAVE_BUFFER) send_have_output (this); } diff --git a/spa/plugins/volume/volume.c b/spa/plugins/volume/volume.c index 61730541e..04b54fbfc 100644 --- a/spa/plugins/volume/volume.c +++ b/spa/plugins/volume/volume.c @@ -725,13 +725,13 @@ spa_volume_node_process_input (SpaNode *node) if (sbuf != dbuf) release_buffer (this, sbuf); - return SPA_RESULT_HAVE_OUTPUT; + return SPA_RESULT_HAVE_BUFFER; } static SpaResult spa_volume_node_process_output (SpaNode *node) { - return SPA_RESULT_NEED_INPUT; + return SPA_RESULT_NEED_BUFFER; } static const SpaNode volume_node = { diff --git a/spa/tests/test-mixer.c b/spa/tests/test-mixer.c index 0c66ee511..f7ebd81aa 100644 --- a/spa/tests/test-mixer.c +++ b/spa/tests/test-mixer.c @@ -225,27 +225,27 @@ on_sink_event (SpaNode *node, SpaEvent *event, void *user_data) res = spa_node_process_output (data->mix); - if (res == SPA_RESULT_NEED_INPUT) { + if (res == SPA_RESULT_NEED_BUFFER) { - if (data->source1_mix_io[0].status == SPA_RESULT_NEED_INPUT) { + if (data->source1_mix_io[0].status == SPA_RESULT_NEED_BUFFER) { res = spa_node_process_output (data->source1); - if (res != SPA_RESULT_HAVE_OUTPUT) + if (res != SPA_RESULT_HAVE_BUFFER) printf ("got process_output error from source1 %d\n", res); } - if (data->source2_mix_io[0].status == SPA_RESULT_NEED_INPUT) { + if (data->source2_mix_io[0].status == SPA_RESULT_NEED_BUFFER) { res = spa_node_process_output (data->source2); - if (res != SPA_RESULT_HAVE_OUTPUT) + if (res != SPA_RESULT_HAVE_BUFFER) printf ("got process_output error from source2 %d\n", res); } res = spa_node_process_input (data->mix); - if (res == SPA_RESULT_HAVE_OUTPUT) + if (res == SPA_RESULT_HAVE_BUFFER) goto push; else printf ("got process_input error from mixer %d\n", res); - } else if (res == SPA_RESULT_HAVE_OUTPUT) { + } else if (res == SPA_RESULT_HAVE_BUFFER) { push: if ((res = spa_node_process_input (data->sink)) < 0) printf ("got process_input error from sink %d\n", res); diff --git a/spa/tests/test-ringbuffer.c b/spa/tests/test-ringbuffer.c index f6526cd0e..e47656311 100644 --- a/spa/tests/test-ringbuffer.c +++ b/spa/tests/test-ringbuffer.c @@ -215,7 +215,7 @@ on_sink_event (SpaNode *node, SpaEvent *event, void *user_data) if (SPA_EVENT_TYPE (event) == data->type.event_node.NeedInput) { res = spa_node_process_output (data->source); - if (res != SPA_RESULT_HAVE_OUTPUT) + if (res != SPA_RESULT_HAVE_BUFFER) printf ("got process_output error from source %d\n", res); if ((res = spa_node_process_input (data->sink)) < 0)