[asterisk-commits] dvossel: branch dvossel/hd_confbridge r309854 - /team/dvossel/hd_confbridge/b...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Mar 7 14:17:37 CST 2011
Author: dvossel
Date: Mon Mar 7 14:17:35 2011
New Revision: 309854
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=309854
Log:
Resync conference channel's buffer if mixing thread falls behind
Modified:
team/dvossel/hd_confbridge/bridges/bridge_softmix.c
Modified: team/dvossel/hd_confbridge/bridges/bridge_softmix.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/hd_confbridge/bridges/bridge_softmix.c?view=diff&rev=309854&r1=309853&r2=309854
==============================================================================
--- team/dvossel/hd_confbridge/bridges/bridge_softmix.c (original)
+++ team/dvossel/hd_confbridge/bridges/bridge_softmix.c Mon Mar 7 14:17:35 2011
@@ -181,6 +181,7 @@
static enum ast_bridge_write_result softmix_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
{
struct softmix_channel *sc = bridge_channel->bridge_pvt;
+ struct softmix_bridge_data *bridge_data = bridge->bridge_pvt;
/* Only accept audio frames, all others are unsupported */
if (frame->frametype != AST_FRAME_VOICE) {
@@ -188,6 +189,13 @@
}
ast_mutex_lock(&sc->lock);
+
+ /* Before adding audio in, make sure we haven't fallen behind. If audio has fallen
+ * behind 4 times the amount of samples mixed on every iteration of the mixer, Re-sync
+ * the audio by flushing the buffer before adding new audio in. */
+ if (ast_slinfactory_available(&sc->factory) > (4 * SOFTMIX_SAMPLES(bridge_data->internal_rate))) {
+ ast_slinfactory_flush(&sc->factory);
+ }
/* If a frame was provided add it to the smoother */
if (frame->frametype == AST_FRAME_VOICE && ast_format_is_slinear(&frame->subclass.format)) {
@@ -242,8 +250,10 @@
} stats;
struct softmix_bridge_data *bridge_data = bridge->bridge_pvt;
struct ast_timer *timer = bridge_data->timer;
+ short *data1, *data2;
int timingfd = ast_timer_fd(timer);
int update_all_rates = 0; /* set this when the internal sample rate has changed */
+ int channel_native_rate;
int i;
ast_timer_set_rate(timer, (1000 / SOFTMIX_INTERVAL));
@@ -252,6 +262,8 @@
struct ast_bridge_channel *bridge_channel = NULL;
short buf[MAX_DATALEN] = {0, };
int timeout = -1;
+ unsigned int softmix_samples = SOFTMIX_SAMPLES(bridge_data->internal_rate);
+ unsigned int softmix_datalen = SOFTMIX_DATALEN(bridge_data->internal_rate);
/* these variables help determine if a rate change is required */
memset(&stats, 0, sizeof(stats));
@@ -263,7 +275,6 @@
/* Go through pulling audio from each factory that has it available */
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
struct softmix_channel *sc = bridge_channel->bridge_pvt;
- int channel_native_rate;
ast_mutex_lock(&sc->lock);
@@ -272,13 +283,11 @@
}
/* Try to get audio from the factory if available */
- if (ast_slinfactory_available(&sc->factory) >= SOFTMIX_SAMPLES(bridge_data->internal_rate) &&
- ast_slinfactory_read(&sc->factory, sc->our_buf, SOFTMIX_SAMPLES(bridge_data->internal_rate))) {
- short *data1, *data2;
- int i;
+ if ((ast_slinfactory_available(&sc->factory) >= softmix_samples) &&
+ ast_slinfactory_read(&sc->factory, sc->our_buf, softmix_samples)) {
/* Put into the local final buffer */
- for (i = 0, data1 = buf, data2 = sc->our_buf; i < SOFTMIX_DATALEN(bridge_data->internal_rate); i++, data1++, data2++)
+ for (i = 0, data1 = buf, data2 = sc->our_buf; i < softmix_datalen; i++, data1++, data2++)
ast_slinear_saturated_add(data1, data2);
/* Yay we have our own audio */
sc->have_audio = 1;
@@ -316,14 +325,13 @@
/* Next step go through removing the channel's own audio and creating a good frame... */
AST_LIST_TRAVERSE(&bridge->channels, bridge_channel, entry) {
struct softmix_channel *sc = bridge_channel->bridge_pvt;
- int i = 0;
/* Copy from local final buffer to our final buffer */
memcpy(sc->final_buf, buf, sizeof(sc->final_buf));
/* If we provided audio then take it out */
if (sc->have_audio) {
- for (i = 0; i < SOFTMIX_DATALEN(bridge_data->internal_rate); i++) {
+ for (i = 0; i < softmix_datalen; i++) {
ast_slinear_saturated_subtract(&sc->final_buf[i], &sc->our_buf[i]);
}
}
More information about the asterisk-commits
mailing list