From 1f6f807bb35228f7d6f50cf61283b9ceb8f46eee Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 7 Sep 2017 18:42:49 +0300 Subject: [PATCH] procqueue: add processing state callback In some cases it's required to wait for some queue items to finish processing. For example, the ALSA sink writes the audio samples to the buffer in non-blocking mode, so as soon as all of them will be written, a program may finish execution, causing the playback abort. To prevent that, this change extends the library's API, allowing each queue item to have a processing state callback that returns a positive integer if processing is not finished yet, and 0 otherwise. --- include/osmocom/gapk/procqueue.h | 1 + src/pq_alsa.c | 1 + src/pq_codec.c | 1 + src/pq_file.c | 1 + src/pq_format.c | 1 + src/pq_rtp.c | 1 + 6 files changed, 6 insertions(+) diff --git a/include/osmocom/gapk/procqueue.h b/include/osmocom/gapk/procqueue.h index a72fd61..9b049a5 100644 --- a/include/osmocom/gapk/procqueue.h +++ b/include/osmocom/gapk/procqueue.h @@ -40,6 +40,7 @@ struct osmo_gapk_pq_item { * \param[in] in_len length of input data \a in * \returns number of output bytes written to \a out; negative on error */ int (*proc)(void *state, uint8_t *out, const uint8_t *in, unsigned int in_len); + int (*wait)(void *state); void (*exit)(void *state); /*! \brief link to a processing queue */ diff --git a/src/pq_alsa.c b/src/pq_alsa.c index b91457e..779dd96 100644 --- a/src/pq_alsa.c +++ b/src/pq_alsa.c @@ -138,6 +138,7 @@ pq_queue_alsa_op(struct osmo_gapk_pq *pq, const char *alsa_dev, unsigned int blk item->len_out = in_out_n ? blk_len : 0; item->state = state; item->proc = in_out_n ? pq_cb_alsa_input : pq_cb_alsa_output; + item->wait = NULL; item->exit = pq_cb_alsa_exit; return 0; diff --git a/src/pq_codec.c b/src/pq_codec.c index f5da628..e033a7d 100644 --- a/src/pq_codec.c +++ b/src/pq_codec.c @@ -71,6 +71,7 @@ osmo_gapk_pq_queue_codec(struct osmo_gapk_pq *pq, const struct osmo_gapk_codec_d } item->exit = codec->codec_exit; + item->wait = NULL; LOGPGAPK(LOGL_DEBUG, "PQ: Adding codec %s, %s format %s\n", codec->name, enc_dec_n ? "encoding to" : "decoding from", fmt->name); diff --git a/src/pq_file.c b/src/pq_file.c index b31ef52..d05f82a 100644 --- a/src/pq_file.c +++ b/src/pq_file.c @@ -83,6 +83,7 @@ pq_queue_file_op(struct osmo_gapk_pq *pq, FILE *fh, unsigned int blk_len, int in item->len_out = in_out_n ? blk_len : 0; item->state = state; item->proc = in_out_n ? pq_cb_file_input : pq_cb_file_output; + item->wait = NULL; item->exit = pq_cb_file_exit; return 0; diff --git a/src/pq_format.c b/src/pq_format.c index ae5386e..8ea8b86 100644 --- a/src/pq_format.c +++ b/src/pq_format.c @@ -70,6 +70,7 @@ osmo_gapk_pq_queue_fmt_convert(struct osmo_gapk_pq *pq, const struct osmo_gapk_f } item->proc = pq_cb_fmt_convert; + item->wait = NULL; return 0; } diff --git a/src/pq_rtp.c b/src/pq_rtp.c index 6e7a87d..1c37475 100644 --- a/src/pq_rtp.c +++ b/src/pq_rtp.c @@ -229,6 +229,7 @@ pq_queue_rtp_op(struct osmo_gapk_pq *pq, int udp_fd, unsigned int blk_len, int i item->len_out = in_out_n ? blk_len : 0; item->state = state; item->proc = in_out_n ? pq_cb_rtp_input : pq_cb_rtp_output; + item->wait = NULL; item->exit = pq_cb_rtp_exit; return 0;