[asterisk-commits] russell: branch russell/jack r96173 - /team/russell/jack/apps/app_jack.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 2 22:31:49 CST 2008
Author: russell
Date: Wed Jan 2 22:31:49 2008
New Revision: 96173
URL: http://svn.digium.com/view/asterisk?view=rev&rev=96173
Log:
Simplify the audio path from jack back to Asterisk. The smoother isn't really
necessary. Now, the code just waits until there is enough data in the ringbuffer
to fill a 20 ms frame before pulling it out.
Modified:
team/russell/jack/apps/app_jack.c
Modified: team/russell/jack/apps/app_jack.c
URL: http://svn.digium.com/view/asterisk/team/russell/jack/apps/app_jack.c?view=diff&rev=96173&r1=96172&r2=96173
==============================================================================
--- team/russell/jack/apps/app_jack.c (original)
+++ team/russell/jack/apps/app_jack.c Wed Jan 2 22:31:49 2008
@@ -77,7 +77,6 @@
jack_port_t *output_port;
jack_ringbuffer_t *input_rb;
jack_ringbuffer_t *output_rb;
- struct ast_smoother *smoother;
void *output_resampler;
double output_resample_factor;
void *input_resampler;
@@ -196,6 +195,8 @@
int total_out_buf_used = 0;
float f_buf[nframes + 1];
+ memset(f_buf, 0, sizeof(f_buf));
+
while (total_in_buf_used < nframes) {
int in_buf_used;
int out_buf_used;
@@ -307,11 +308,6 @@
jack_data->output_rb = NULL;
}
- if (jack_data->smoother) {
- ast_smoother_free(jack_data->smoother);
- jack_data->smoother = NULL;
- }
-
if (jack_data->output_resampler) {
resample_close(jack_data->output_resampler);
jack_data->output_resampler = NULL;
@@ -331,11 +327,6 @@
ast_channel_lock(chan);
chan_name = ast_strdupa(chan->name);
ast_channel_unlock(chan);
-
- if (!(jack_data->smoother = ast_smoother_new(320))) { /* 20 ms frames */
- destroy_jack_data(jack_data);
- return -1;
- }
if (!(jack_data->output_rb = jack_ringbuffer_create(RINGBUFFER_SIZE))) {
destroy_jack_data(jack_data);
@@ -458,37 +449,38 @@
* \brief handle jack audio
*
* Read data from the input ringbuffer, which is the properly resampled audio
- * that was read from the jack input port. Feed it through a smoother and write
- * frames to the channel.
+ * that was read from the jack input port. Write it to the channel in 20 ms frames.
*/
static void handle_jack_audio(struct ast_channel *chan, struct jack_data *jack_data)
{
short buf[160];
- int res;
- struct ast_frame *fr;
+ struct ast_frame f = {
+ .frametype = AST_FRAME_VOICE,
+ .subclass = AST_FORMAT_SLINEAR,
+ .src = "JACK",
+ .data = buf,
+ .datalen = sizeof(buf),
+ .samples = ARRAY_LEN(buf),
+ };
for (;;) {
- struct ast_frame f = {
- .frametype = AST_FRAME_VOICE,
- .subclass = AST_FORMAT_SLINEAR,
- .src = "JACK",
- .data = buf,
- };
+ size_t res;
+
+ res = jack_ringbuffer_read_space(jack_data->input_rb);
+
+ if (res < sizeof(buf)) {
+ /* Not enough data ready for another frame, move on ... */
+ break;
+ }
res = jack_ringbuffer_read(jack_data->input_rb, (char *) buf, sizeof(buf));
- if (!res)
+ if (res < sizeof(buf)) {
+ ast_log(LOG_ERROR, "Error reading from ringbuffer, even though it said there was enough data\n");
break;
-
- f.datalen = res;
- f.samples = res / sizeof(short);
-
- ast_smoother_feed(jack_data->smoother, &f);
- }
-
- while ((fr = ast_smoother_read(jack_data->smoother))) {
- ast_write(chan, fr);
- ast_frfree(fr);
+ }
+
+ ast_write(chan, &f);
}
}
More information about the asterisk-commits
mailing list