From 3b55a12a42cfa909f4ef7c0882cd2d3cb929afac Mon Sep 17 00:00:00 2001 From: Edmunt Pienkowsky Date: Fri, 14 Jun 2024 11:55:32 +0200 Subject: [PATCH] Improve statistics Fix ALSA capturing. --- src/at_queue.c | 3 --- src/channel.c | 20 +++++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/at_queue.c b/src/at_queue.c index 061c16cc..69c39109 100644 --- a/src/at_queue.c +++ b/src/at_queue.c @@ -95,9 +95,6 @@ at_queue_task_t* at_queue_add(struct cpvt* cpvt, const at_queue_cmd_t* cmds, uns PVT_STATE(pvt, at_tasks)++; PVT_STATE(pvt, at_cmds) += cmdsno; - PVT_STAT(pvt, at_tasks)++; - PVT_STAT(pvt, at_cmds) += cmdsno; - if (e->cmdsno == 1u) { ast_debug(4, "[%s][%s] \xE2\x86\xB5 [%s][%s] %s%s\n", PVT_ID(pvt), at_cmd2str(e->cmds[0].cmd), at_res2str(e->cmds[0].res), tmp_esc_nstr(e->cmds[0].data, e->cmds[0].length), prio ? "after head" : "at tail", at_once ? " at once" : ""); diff --git a/src/channel.c b/src/channel.c index 7a17ec94..3c7b403b 100644 --- a/src/channel.c +++ b/src/channel.c @@ -563,7 +563,7 @@ static struct ast_frame* channel_read_uac(struct cpvt* cpvt, struct pvt* pvt, si if (avail_frames < 0) { ast_log(LOG_ERROR, "[%s][ALSA][CAPTURE] Cannot determine available samples: %s\n", PVT_ID(pvt), snd_strerror((int)avail_frames)); return NULL; - } else if (frames < (size_t)avail_frames) { + } else if (frames > (size_t)avail_frames) { ast_log(LOG_WARNING, "[%s][ALSA][CAPTURE] Not enough samples: %d/%d\n", PVT_ID(pvt), (int)avail_frames, (int)frames); return NULL; } @@ -732,8 +732,15 @@ static int channel_write_tty(struct ast_channel* channel, struct ast_frame* f, s iov.iov_base = f->data.ptr; iov.iov_len = f->datalen; - if (iov_write(pvt, pvt->audio_fd, &iov, 1) >= 0) { - PVT_STAT(pvt, write_frames)++; + ssize_t res = iov_write(pvt, pvt->audio_fd, &iov, 1); + + if (res >= 0) { + PVT_STAT(pvt, write_frames) += 1; + PVT_STAT(pvt, a_write_bytes) += res; + if (res != f->datalen) { + PVT_STAT(pvt, write_tframes)++; + ast_log(LOG_WARNING, "[%s][TTY][PLAYBACK] Write: %d/%d\n", PVT_ID(pvt), (int)res, f->datalen); + } } } @@ -799,12 +806,11 @@ static int channel_write_uac(struct ast_channel* attribute_unused(channel), stru default: if (res >= 0) { + PVT_STAT(pvt, write_frames) += 1; + PVT_STAT(pvt, a_write_bytes) += res * sizeof(short); if (res != samples) { - PVT_STAT(pvt, write_frames)++; - PVT_STAT(pvt, write_sframes)++; + PVT_STAT(pvt, write_tframes)++; ast_log(LOG_WARNING, "[%s][ALSA][PLAYBACK] Write: %d/%d\n", PVT_ID(pvt), res, samples); - } else { - PVT_STAT(pvt, write_frames)++; } } break;