[asterisk-commits] russell: branch russell/jack r93169 - /team/russell/jack/apps/app_jack.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Dec 16 11:30:44 CST 2007


Author: russell
Date: Sun Dec 16 11:30:44 2007
New Revision: 93169

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93169
Log:
Add some stubs for handling I/O in the jack callback.  Create a second
ringbuffer for data coming in from jack.  Significantly simplify the method
used to write data into a ringbuffer.

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=93169&r1=93168&r2=93169
==============================================================================
--- team/russell/jack/apps/app_jack.c (original)
+++ team/russell/jack/apps/app_jack.c Sun Dec 16 11:30:44 2007
@@ -52,6 +52,8 @@
 #include "libresample.h"
 
 #define RESAMPLE_QUALITY 0
+
+#define RINGBUFFER_SIZE 16384
 
 static char *jack_app = "Jack";
 static char *jack_synopsis = 
@@ -64,7 +66,8 @@
 	jack_client_t *client;
 	jack_port_t *input_port;
 	jack_port_t *output_port;
-	jack_ringbuffer_t *rb;
+	jack_ringbuffer_t *input_rb;
+	jack_ringbuffer_t *output_rb;
 	struct ast_smoother *smoother;
 	void *output_resampler;
 	double output_resample_factor;
@@ -165,17 +168,43 @@
 	return 0;
 }
 
+/*!
+ * \brief Handle jack input port
+ *
+ * Read nframes number of samples from the input buffer, resample it
+ * if necessary, and write it into the appropriate ringbuffer. 
+ */
+static void handle_input(void *buf, jack_nframes_t nframes, 
+	struct jack_data *jack_data)
+{
+
+}
+
+/*!
+ * \brief Handle jack output port
+ *
+ * Read nframes number of samples from the ringbuffer and write it out to the
+ * output port buffer.
+ */
+static void handle_output(void *buf, jack_nframes_t nframes, 
+	struct jack_data *jack_data)
+{
+
+}
+
 static int jack_process(jack_nframes_t nframes, void *arg)
 {
 	struct jack_data *jack_data = arg;
+	void *input_port_buf, *output_port_buf;
 
 	if (!jack_data->input_resample_factor)
 		alloc_resampler(jack_data, 1);
 
-	/* XXX Here we need to attempt to read nframes number of samples from the
-	 * ringbuffer and write it to the output port.  Then, we need to read nframes
-	 * samples from the input port, resample it, put them through a 20 ms smoother,
-	 * and write them to the Asterisk channel. */
+	input_port_buf = jack_port_get_buffer(jack_data->input_port, nframes);
+	handle_input(input_port_buf, nframes, jack_data);
+
+	output_port_buf = jack_port_get_buffer(jack_data->output_port, nframes);
+	handle_output(output_port_buf, nframes, jack_data);
 
 	return 0;
 }
@@ -205,9 +234,14 @@
 		jack_data->client = NULL;
 	}
 
-	if (jack_data->rb) {
-		jack_ringbuffer_free(jack_data->rb);
-		jack_data->rb = NULL;
+	if (jack_data->input_rb) {
+		jack_ringbuffer_free(jack_data->input_rb);
+		jack_data->input_rb = NULL;
+	}
+
+	if (jack_data->output_rb) {
+		jack_ringbuffer_free(jack_data->output_rb);
+		jack_data->output_rb = NULL;
 	}
 
 	if (jack_data->smoother) {
@@ -240,7 +274,12 @@
 		return -1;
 	}
 
-	if (!(jack_data->rb = jack_ringbuffer_create(16384))) {
+	if (!(jack_data->output_rb = jack_ringbuffer_create(RINGBUFFER_SIZE))) {
+		destroy_jack_data(jack_data);
+		return -1;
+	}
+
+	if (!(jack_data->input_rb = jack_ringbuffer_create(RINGBUFFER_SIZE))) {
 		destroy_jack_data(jack_data);
 		return -1;
 	}
@@ -292,7 +331,7 @@
 	size_t f_buf_used = 0;
 	int i;
 	uint16_t *s_buf = f->data;
-	jack_ringbuffer_data_t write_vector[2];
+	size_t res;
 
 	if (!jack_data->output_resample_factor)
 		alloc_resampler(jack_data, 0);
@@ -337,29 +376,10 @@
 		f_buf_used = sizeof(f_buf[0]) * f->samples;
 	}
 
-	jack_ringbuffer_get_write_vector(jack_data->rb, write_vector);
-
-	if (!write_vector[1].len) {
-		ast_log(LOG_WARNING, "Not enough room in ringbuffer to write frame data\n");
-		return 0;
-	}
-
-	if (write_vector[1].len >= f_buf_used) {
-		memcpy(write_vector[1].buf, f_buf, f_buf_used);	
-	} else {
-		char *out_buf = (char *) f_buf;
-		size_t len_left;
-
-		memcpy(write_vector[1].buf, f_buf, write_vector[1].len);
-
-		len_left = f_buf_used - write_vector[1].len;
-
-		if (write_vector[2].len < len_left) {
-			ast_log(LOG_WARNING, "Not enough room in ringbuffer to write frame data\n");
-			return 0;
-		}
-
-		memcpy(write_vector[2].buf, out_buf + write_vector[1].len, len_left);
+	res = jack_ringbuffer_write(jack_data->output_rb, (const char *) f_buf, f_buf_used);
+	if (res != f_buf_used) {
+		ast_log(LOG_WARNING, "Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
+			f_buf_used, res);
 	}
 
 	return 0;




More information about the asterisk-commits mailing list