Skip to content

Commit

Permalink
audio: added tx aubuf statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
alfredh committed Nov 27, 2017
1 parent 56e6402 commit 4f1686a
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions src/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ struct autx {
enum aufmt src_fmt;
bool need_conv;

struct {
uint64_t aubuf_overrun;
uint64_t aubuf_underrun;
} stats;

#ifdef HAVE_PTHREAD
union {
struct {
Expand Down Expand Up @@ -285,6 +290,16 @@ static inline uint32_t calc_nsamp(uint32_t srate, uint8_t channels,
}


static inline double calc_ptime(size_t nsamp, uint32_t srate, uint8_t channels)
{
double ptime;

ptime = 1000.0 * (double)nsamp / (double)(srate * channels);

return ptime;
}


/**
* Get the DSP samplerate for an audio-codec (exception for G.722 and MPA)
*/
Expand Down Expand Up @@ -620,6 +635,14 @@ static void ausrc_read_handler(const void *sampv, size_t sampc, void *arg)
if (tx->muted)
memset((void *)sampv, 0, num_bytes);

if (aubuf_cur_size(tx->aubuf) >= tx->aubuf_maxsz) {

++tx->stats.aubuf_overrun;

debug("audio: tx aubuf overrun (total %llu)\n",
tx->stats.aubuf_overrun);
}

(void)aubuf_write(tx->aubuf, sampv, num_bytes);

if (a->cfg.txmode == AUDIO_MODE_POLL) {
Expand Down Expand Up @@ -1801,6 +1824,7 @@ int audio_debug(struct re_printf *pf, const struct audio *a)
{
const struct autx *tx;
const struct aurx *rx;
size_t sz;
int err;

if (!a)
Expand All @@ -1809,13 +1833,25 @@ int audio_debug(struct re_printf *pf, const struct audio *a)
tx = &a->tx;
rx = &a->rx;

sz = aufmt_sample_size(tx->src_fmt);

err = re_hprintf(pf, "\n--- Audio stream ---\n");

err |= re_hprintf(pf, " tx: %H ptime=%ums\n",
aucodec_print, tx->ac,
tx->ptime);
err |= re_hprintf(pf, " aubuf: %H\n",
aubuf_debug, tx->aubuf);
err |= re_hprintf(pf, " aubuf: %H"
" (cur %.2fms, max %.2fms, or %llu, ur %llu)\n",
aubuf_debug, tx->aubuf,
calc_ptime(aubuf_cur_size(tx->aubuf)/sz,
tx->ausrc_prm.srate,
tx->ausrc_prm.ch),
calc_ptime(tx->aubuf_maxsz/sz,
tx->ausrc_prm.srate,
tx->ausrc_prm.ch),
tx->stats.aubuf_overrun,
tx->stats.aubuf_underrun);

err |= re_hprintf(pf, " time = %.3f sec\n",
autx_calc_seconds(tx));

Expand Down

0 comments on commit 4f1686a

Please sign in to comment.