Skip to content

Commit

Permalink
debug_cmd: command aufileinfo return answer
Browse files Browse the repository at this point in the history
- If the chosen audio source supports blocking mode, the result is returned now
  directly with the given print function.
- Otherwise the result is printed to the log like before.
  • Loading branch information
cspiel1 committed May 17, 2024
1 parent 8c1f3a3 commit d7bb75d
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions modules/debug_cmd/debug_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
*/


enum {
AUFILE_TIMEOUT = 5000,
};


static uint64_t start_ticks; /**< Ticks when app started */
static time_t start_time; /**< Start time of application */
static struct play *g_play;
Expand Down Expand Up @@ -172,7 +177,9 @@ struct fileinfo_st {
struct ausrc_prm prm;
size_t sampc;
struct tmr tmr;
bool finished;
RE_ATOMIC bool finished;
struct re_printf *pf;
uint64_t t0;
};


Expand All @@ -193,18 +200,23 @@ static void fileinfo_timeout(void *arg)
if (st->prm.ch && st->prm.srate)
s = ((double) st->sampc) / st->prm.ch / st->prm.srate;

if (st->finished) {
info("debug_cmd: length = %1.3lf seconds\n", s);
if (re_atomic_rlx(&st->finished)) {
re_hprintf(st->pf, "debug_cmd: length = %1.3lf seconds\n", s);
module_event("debug_cmd", "aufileinfo", NULL, NULL,
"length = %lf seconds", s);
}
else if (tmr_jiffies() - st->t0 < AUFILE_TIMEOUT) {
tmr_start(&st->tmr, 5, fileinfo_timeout, st);
return;
}
else if (s > 0.) {
warning("debug_cmd: timeout, length > %1.3lf seconds\n", s);
re_hprintf(st->pf,
"debug_cmd: timeout, length > %1.3lf seconds\n", s);
module_event("debug_cmd", "aufileinfo", NULL, NULL,
"timeout length = %lf seconds", s);
}
else {
info("debug_cmd: timeout\n");
re_hprintf(st->pf, "debug_cmd: timeout\n");
module_event("debug_cmd", "aufileinfo", NULL, NULL,
"timeout", s);
}
Expand All @@ -229,8 +241,7 @@ static void fileinfo_err_handler(int err, const char *str, void *arg)
struct fileinfo_st *st = arg;
(void) str;

st->finished = err ? false : true;
tmr_start(&st->tmr, 0, fileinfo_timeout, st);
re_atomic_rlx_set(&st->finished, err ? false : true);
}


Expand Down Expand Up @@ -288,6 +299,8 @@ static int cmd_aufileinfo(struct re_printf *pf, void *arg)
goto out;
}

st->pf = pf;
st->t0 = tmr_jiffies();
err = ausrc_alloc(&st->ausrc, baresip_ausrcl(),
aumod,
&st->prm, path,
Expand All @@ -299,11 +312,16 @@ static int cmd_aufileinfo(struct re_printf *pf, void *arg)
goto out;
}

if (st->finished)
if (re_atomic_rlx(&st->finished)) {
/* the ausrc supports blocking mode */
fileinfo_timeout(st);
else
tmr_start(&st->tmr, 5000, fileinfo_timeout, st);
}
else {
/* use a timer to detect finish */
tmr_start(&st->tmr, 5, fileinfo_timeout, st);
}
out:
st->pf = NULL;
if (err)
mem_deref(st);

Expand Down

0 comments on commit d7bb75d

Please sign in to comment.