Skip to content

Instantly share code, notes, and snippets.

@oneman
Created November 21, 2010 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oneman/708718 to your computer and use it in GitHub Desktop.
Save oneman/708718 to your computer and use it in GitHub Desktop.
--- /home/oneman/Desktop/temp2/asterisk-1.8.0/apps/app_jack.c 2010-01-15 13:21:50.000000000 -0500
+++ /home/oneman/kode/asterisk-1.8.0/apps/app_jack.c 2010-11-21 07:36:58.000000000 -0500
@@ -60,7 +60,7 @@
#define RESAMPLE_QUALITY 1
-#define RINGBUFFER_SIZE 16384
+#define RINGBUFFER_SIZE 65536
/*! \brief Common options between the Jack() app and JACK_HOOK() function */
#define COMMON_OPTIONS \
@@ -288,7 +288,7 @@
res = jack_ringbuffer_write(jack_data->input_rb, (const char *) s_buf, write_len);
if (res != write_len) {
- ast_debug(2, "Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
+ ast_log(LOG_ERROR, "handle_input Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
(int) sizeof(s_buf), (int) res);
}
}
@@ -302,16 +302,18 @@
static void handle_output(void *buf, jack_nframes_t nframes,
struct jack_data *jack_data)
{
- size_t res, len;
+ size_t res, len, avail, availafter;
len = nframes * sizeof(float);
-
+ avail = jack_ringbuffer_read_space(jack_data->output_rb);
res = jack_ringbuffer_read(jack_data->output_rb, buf, len);
-
+ availafter = jack_ringbuffer_read_space(jack_data->output_rb);
if (len != res) {
- ast_debug(2, "Wanted %d bytes to send to the output port, "
+ ast_log(LOG_ERROR, "Wanted %d bytes to send to the output port, "
"but only got %d\n", (int) len, (int) res);
}
+ ast_log(LOG_ERROR, "HO: %d bytes were avail for R before, "
+ "bytes where avail after %d\n", (int) avail, (int) availafter);
}
static int jack_process(jack_nframes_t nframes, void *arg)
@@ -405,6 +407,14 @@
if (!(jack_data->input_rb = jack_ringbuffer_create(RINGBUFFER_SIZE)))
return -1;
+ memset(jack_data->output_rb->buf, 0, jack_data->output_rb->size);
+ memset(jack_data->input_rb->buf, 0, jack_data->input_rb->size);
+
+ if (jack_ringbuffer_mlock(jack_data->output_rb))
+ ast_log(LOG_ERROR, "oh now did not lock output rb");
+ if (jack_ringbuffer_mlock(jack_data->input_rb))
+ ast_log(LOG_ERROR, "oh now did not lock input rb");
+
if (jack_data->no_start_server)
jack_options |= JackNoStartServer;
@@ -520,7 +530,7 @@
int i;
int16_t *s_buf = f->data.ptr;
size_t res;
-
+ //ast_log(LOG_ERROR, "number of samples inputted is %d\n", f->samples);
memset(f_buf, 0, sizeof(f_buf));
if (!jack_data->output_resample_factor)
@@ -561,6 +571,7 @@
f_buf_used = total_out_buf_used;
if (f_buf_used > ARRAY_LEN(f_buf))
f_buf_used = ARRAY_LEN(f_buf);
+
} else {
/* No resampling needed */
@@ -570,11 +581,25 @@
f_buf_used = f->samples;
}
- res = jack_ringbuffer_write(jack_data->output_rb, (const char *) f_buf, f_buf_used * sizeof(float));
- if (res != (f_buf_used * sizeof(float))) {
- ast_debug(2, "Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
- (int) (f_buf_used * sizeof(float)), (int) res);
- }
+ int availreadbytes, availwritebytes, availreadbytesafter, availwritebytesafter;
+
+ availwritebytes = jack_ringbuffer_write_space(jack_data->output_rb);
+ availreadbytes = jack_ringbuffer_read_space(jack_data->output_rb);
+ //ast_log(LOG_ERROR, "queue_voice_frame knows %d bytes are free to write to in the ringbuffer\n", availbytes);
+ if (availwritebytes > (f_buf_used * 4)) {
+ res = jack_ringbuffer_write(jack_data->output_rb, (const char *) f_buf, f_buf_used * sizeof(float));
+ availwritebytesafter = jack_ringbuffer_write_space(jack_data->output_rb);
+ availreadbytesafter = jack_ringbuffer_read_space(jack_data->output_rb);
+ ast_log(LOG_ERROR, "QVF: Before: %d/%d ba for r/w After: %d/%d ba for rw\n", availreadbytes, availwritebytes, availreadbytesafter, availwritebytesafter);
+ if (res != (f_buf_used * sizeof(float))) {
+ ast_log(LOG_ERROR, "queue_voice_frame Tried to write %d bytes to the ringbuffer, but only wrote %d\n",
+ (int) (f_buf_used * sizeof(float)), (int) res);
+ } else {
+ // ast_log(LOG_ERROR, "queue_voice_frame did write %d bytes to the ringbuffer\n", (int) (f_buf_used * sizeof(float)));
+ }
+ } else {
+ ast_log(LOG_ERROR, "skipped writing %d bytes to the ringbuffer, not nuff space\n", (int) (f_buf_used * sizeof(float)));
+ }
return 0;
}
@oneman
Copy link
Author

oneman commented Nov 21, 2010

For: https://issues.asterisk.org/view.php?id=17659

For some reason the upload of things here is a bit jacked up so to speak.

Here is my patch. The license to which is whatever you want it to be, however it was developed with the help of satan himself, so if you use it lets just say its not going to win you any points with the big man.

And just as importantly my debug output and commentary: http://media.rawdod.com/asterisk_debug_version0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment