/** * Read samples from Audio Source * * @note This function has REAL-TIME properties * * @note This function may be called from any thread * * @param buf Buffer with audio samples * @param sz Number of bytes in buffer * @param arg Handler argument */ static void ausrc_read_handler(const int16_t *sampv, size_t sampc, void *arg) { struct audio *a = arg; struct autx *tx = &a->tx; if (tx->muted) memset((void *)sampv, 0, sampc*2); (void)aubuf_write_samp(tx->aubuf, sampv, sampc); if (a->cfg.txmode == AUDIO_MODE_POLL) { unsigned i; for (i=0; i<16; i++) { if (aubuf_cur_size(tx->aubuf) < tx->psize) break; poll_aubuf_tx(a); } } /* Exact timing: send Telephony-Events from here */ check_telev(a, tx); }
/** * Decode incoming packets using the Audio decoder * * NOTE: mb=NULL if no packet received */ static int aurx_stream_decode(struct aurx *rx, struct mbuf *mb) { size_t sampc = AUDIO_SAMPSZ; int16_t *sampv; struct le *le; int err = 0; /* No decoder set */ if (!rx->ac) return 0; if (mbuf_get_left(mb)) { err = rx->ac->dech(rx->dec, rx->sampv, &sampc, mbuf_buf(mb), mbuf_get_left(mb)); } else if (rx->ac->plch) { err = rx->ac->plch(rx->dec, rx->sampv, &sampc); } else { /* no PLC in the codec, might be done in filters below */ sampc = 0; } if (err) { DEBUG_WARNING("%s codec decode %u bytes: %m\n", rx->ac->name, mbuf_get_left(mb), err); goto out; } /* Process exactly one audio-frame in reverse list order */ for (le = rx->filtl.tail; le; le = le->prev) { struct aufilt_dec_st *st = le->data; if (st->af && st->af->dech) { err |= st->af->dech(st, rx->sampv, &sampc); } } if (!rx->ab) goto out; sampv = rx->sampv; /* optional resampler */ if (rx->resamp) { size_t sampc_rs = AUDIO_SAMPSZ; err = auresamp_process(rx->resamp, rx->sampv_rs, &sampc_rs, rx->sampv, sampc); if (err) return err; sampv = rx->sampv_rs; sampc = sampc_rs; } err = aubuf_write_samp(rx->ab, sampv, sampc); if (err) goto out; out: return err; }
static void read_handler(const int16_t *sampv, size_t sampc, void *arg) { struct audio_loop *al = arg; int err; ++al->n_read; err = aubuf_write_samp(al->ab, sampv, sampc); if (err) { warning("auloop: aubuf_write: %m\n", err); } }