This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
laforge gerrit-no-reply at lists.osmocom.orglaforge has uploaded this change for review. ( https://gerrit.osmocom.org/c/gapk/+/19494 ) Change subject: gapk: Implemnet optional looping/rewinding of input files ...................................................................... gapk: Implemnet optional looping/rewinding of input files Together with the recently-added throttling, this can be useful to generate a continuous stream of RTP data from an input file. Change-Id: I2d552695dfb4cc96039838e79e0f5ae25a6737c8 --- M include/osmocom/gapk/procqueue.h M src/app_osmo_gapk.c M src/pq_file.c 3 files changed, 22 insertions(+), 7 deletions(-) git pull ssh://gerrit.osmocom.org:29418/gapk refs/changes/94/19494/1 diff --git a/include/osmocom/gapk/procqueue.h b/include/osmocom/gapk/procqueue.h index 82c1cf9..be10f7a 100644 --- a/include/osmocom/gapk/procqueue.h +++ b/include/osmocom/gapk/procqueue.h @@ -20,6 +20,7 @@ #pragma once #include <stdint.h> +#include <stdbool.h> #include <stdio.h> /* for FILE */ #include <osmocom/core/linuxlist.h> @@ -85,7 +86,7 @@ struct osmo_gapk_pq_item *osmo_gapk_pq_add_item(struct osmo_gapk_pq *pq); /* File */ -int osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int block_len); +int osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int block_len, bool loop); int osmo_gapk_pq_queue_file_output(struct osmo_gapk_pq *pq, FILE *dst, unsigned int block_len); /* RTP */ diff --git a/src/app_osmo_gapk.c b/src/app_osmo_gapk.c index 1e4e9a0..5e85548 100644 --- a/src/app_osmo_gapk.c +++ b/src/app_osmo_gapk.c @@ -68,6 +68,7 @@ /* RTP payload type */ uint8_t rtp_pt_in, rtp_pt_out; + bool loop_input; int throttle; int benchmark; int verbose; @@ -144,6 +145,7 @@ fprintf(stdout, " -P --rtp-pt-out=TYPE\t\tRTP payload type for outgoing frames\n"); fprintf(stdout, " -b, --enable-benchmark\tEnable codec benchmarking\n"); fprintf(stdout, " -t, --throttle\tEnable throttling (one codec frame every 20ms)\n"); + fprintf(stdout, " -l, --loop-input\tEnable looping of the input file\n"); fprintf(stdout, " -v, --verbose\t\t\tEnable debug messages\n"); fprintf(stdout, "\n"); @@ -217,10 +219,11 @@ {"rtp-pt-out", 1, 0, 'P'}, {"enable-benchmark", 0, 0, 'b'}, {"throttle", 0, 0, 't'}, + {"loop-input", 0, 0, 'l'}, {"verbose", 0, 0, 'v'}, {"help", 0, 0, 'h'}, }; - const char *short_options = "i:o:I:O:f:g:p:P:btvh" + const char *short_options = "i:o:I:O:f:g:p:P:btlvh" #ifdef HAVE_ALSA "a:A:" #endif @@ -322,6 +325,10 @@ opt->throttle = 1; break; + case 'l': + opt->loop_input = true; + break; + case 'v': log_parse_category_mask(osmo_stderr_target, "DAPP"); opt->verbose = 1; @@ -577,7 +584,7 @@ /* File read */ if (gs->in.file.fh) - osmo_gapk_pq_queue_file_input(gs->pq, gs->in.file.fh, fmt_in->frame_len); + osmo_gapk_pq_queue_file_input(gs->pq, gs->in.file.fh, fmt_in->frame_len, gs->opts.loop_input); else if (gs->in.rtp.fd != -1) osmo_gapk_pq_queue_rtp_input(gs->pq, gs->in.rtp.fd, fmt_in->frame_len, gs->opts.rtp_pt_in); diff --git a/src/pq_file.c b/src/pq_file.c index d496eec..d214096 100644 --- a/src/pq_file.c +++ b/src/pq_file.c @@ -19,6 +19,7 @@ #include <errno.h> #include <stdint.h> +#include <stdbool.h> #include <talloc.h> #include <osmocom/gapk/logging.h> @@ -30,6 +31,7 @@ struct pq_state_file { FILE *fh; unsigned int blk_len; + bool loop_input; }; @@ -39,6 +41,10 @@ struct pq_state_file *state = _state; int rv; rv = fread(out, state->blk_len, 1, state->fh); + if (rv == 0 && state->loop_input && feof(state->fh)) { + rewind(state->fh); + rv = fread(out, state->blk_len, 1, state->fh); + } if (rv <= 0) return -1; return rv * state->blk_len; @@ -60,7 +66,7 @@ } static int -pq_queue_file_op(struct osmo_gapk_pq *pq, FILE *fh, unsigned int blk_len, int in_out_n) +pq_queue_file_op(struct osmo_gapk_pq *pq, FILE *fh, unsigned int blk_len, int in_out_n, bool loop_input) { struct osmo_gapk_pq_item *item; struct pq_state_file *state; @@ -71,6 +77,7 @@ state->fh = fh; state->blk_len = blk_len; + state->loop_input = loop_input; item = osmo_gapk_pq_add_item(pq); if (!item) { @@ -105,11 +112,11 @@ * \param[in] blk_len block length to be read from file * \returns 0 on success; negative on error */ int -osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int blk_len) +osmo_gapk_pq_queue_file_input(struct osmo_gapk_pq *pq, FILE *src, unsigned int blk_len, bool loop) { LOGPGAPK(LOGL_DEBUG, "PQ '%s': Adding file input (blk_len=%u)\n", pq->name, blk_len); - return pq_queue_file_op(pq, src, blk_len, 1); + return pq_queue_file_op(pq, src, blk_len, 1, loop); } /*! Add file output to given processing queue @@ -123,5 +130,5 @@ { LOGPGAPK(LOGL_DEBUG, "PQ '%s': Adding file output (blk_len=%u)\n", pq->name, blk_len); - return pq_queue_file_op(pq, dst, blk_len, 0); + return pq_queue_file_op(pq, dst, blk_len, 0, false); } -- To view, visit https://gerrit.osmocom.org/c/gapk/+/19494 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: gapk Gerrit-Branch: master Gerrit-Change-Id: I2d552695dfb4cc96039838e79e0f5ae25a6737c8 Gerrit-Change-Number: 19494 Gerrit-PatchSet: 1 Gerrit-Owner: laforge <laforge at osmocom.org> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200801/e57e54ad/attachment.htm>