[asterisk-commits] russell: branch russell/chan_console r49016 - /team/russell/chan_console/chan...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Dec 27 19:50:57 MST 2006


Author: russell
Date: Wed Dec 27 20:50:56 2006
New Revision: 49016

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49016
Log:
Bidirectional audio is now functional!  Yay!

Modified:
    team/russell/chan_console/channels/chan_console.c

Modified: team/russell/chan_console/channels/chan_console.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_console/channels/chan_console.c?view=diff&rev=49016&r1=49015&r2=49016
==============================================================================
--- team/russell/chan_console/channels/chan_console.c (original)
+++ team/russell/chan_console/channels/chan_console.c Wed Dec 27 20:50:56 2006
@@ -291,55 +291,57 @@
 	unsigned long frame_count, const PaStreamCallbackTimeInfo *time_info,
 	PaStreamCallbackFlags flags, void *userData)
 {
-	unsigned int src = 0;
-	struct ast_frame *fr = &pvt.fr;
-	unsigned int num_samples;
-
 	//ast_log(LOG_NOTICE, "console_callback, frame_count: %lu ...\n", frame_count);
 
-	ast_mutex_lock(&console_lock);
-	if (pvt.write_dst) {
-		num_samples = (pvt.write_dst * 2) > frame_count ? pvt.write_dst * 2 : frame_count;
-		//ast_log(LOG_NOTICE, "writing %d samples from write_buf\n", num_samples);
-		memcpy(output, &pvt.write_buf, num_samples * 2);
-		pvt.write_dst -= num_samples * 2;
-		src += num_samples * 2;
-		frame_count -= num_samples;
-	}
-	while (frame_count) { 
-		while (!(fr = AST_LIST_REMOVE_HEAD(&pvt.frames, frame_list)))
-			ast_cond_wait(&pvt.cond, &console_lock);
-		num_samples = fr->samples > frame_count ? frame_count : fr->samples;
-		//ast_log(LOG_NOTICE, "Writing %d samples from frame\n", num_samples);
-		memcpy(output + src, fr->data, num_samples * 2);
-		frame_count -= num_samples;
-		if (num_samples != fr->samples) {
-			memcpy(&pvt.write_buf + pvt.write_dst, fr->data + num_samples * 2, (fr->samples - num_samples) * 2);
-			pvt.write_dst += (fr->samples - num_samples) * 2;
-			//ast_log(LOG_NOTICE, "Saving %d bytes (%d samples) left over in frame\n", 
-				//(fr->samples - num_samples) * 2, (fr->samples - num_samples) * 2);
+	if (output) {
+		unsigned int src = 0;
+		unsigned int num_samples;
+		struct ast_frame *fr;
+		ast_mutex_lock(&console_lock);
+		if (pvt.write_dst) {
+			num_samples = (pvt.write_dst * 2) > frame_count ? pvt.write_dst * 2 : frame_count;
+			//ast_log(LOG_NOTICE, "writing %d samples from write_buf\n", num_samples);
+			memcpy(output, &pvt.write_buf, num_samples * 2);
+			pvt.write_dst -= num_samples * 2;
+			src += num_samples * 2;
+			frame_count -= num_samples;
 		}
-		ast_frfree(fr);
-	}
-	ast_mutex_unlock(&console_lock);
-
-	if (frame_count) {
-		ast_log(LOG_WARNING, "console_callback didn't get %lu of the samples it wanted :(\n", frame_count);
-		memset(output + src, 0, frame_count * 2);
-	}
-
-	memset(fr, 0, sizeof(*fr));
-	memset(pvt.read_buf, 0, NUM_SAMPLES * 2 + AST_FRIENDLY_OFFSET);
-	fr->data = pvt.read_buf + AST_FRIENDLY_OFFSET;
-	fr->offset = AST_FRIENDLY_OFFSET;
-	fr->frametype = AST_FRAME_VOICE;
-	fr->subclass = AST_FORMAT_SLINEAR;
-	fr->samples = NUM_SAMPLES;
-	fr->datalen = NUM_SAMPLES * 2;
-
-	memcpy(fr->data, input, NUM_SAMPLES * 2);
-
-	ast_queue_frame(pvt.owner, fr);
+		while (frame_count) { 
+			while (!(fr = AST_LIST_REMOVE_HEAD(&pvt.frames, frame_list)))
+				ast_cond_wait(&pvt.cond, &console_lock);
+			num_samples = fr->samples > frame_count ? frame_count : fr->samples;
+			//ast_log(LOG_NOTICE, "Writing %d samples from frame\n", num_samples);
+			memcpy(output + src, fr->data, num_samples * 2);
+			frame_count -= num_samples;
+			if (num_samples != fr->samples) {
+				memcpy(&pvt.write_buf + pvt.write_dst, fr->data + num_samples * 2, (fr->samples - num_samples) * 2);
+				pvt.write_dst += (fr->samples - num_samples) * 2;
+				//ast_log(LOG_NOTICE, "Saving %d bytes (%d samples) left over in frame\n", 
+					//(fr->samples - num_samples) * 2, (fr->samples - num_samples) * 2);
+			}
+			ast_frfree(fr);
+		}
+		ast_mutex_unlock(&console_lock);
+
+		if (frame_count) {
+			ast_log(LOG_WARNING, "console_callback didn't get %lu of the samples it wanted :(\n", frame_count);
+			memset(output + src, 0, frame_count * 2);
+		}
+	}
+
+	if (input) {
+		struct ast_frame *fr = &pvt.fr;
+		memset(fr, 0, sizeof(*fr));
+		memset(pvt.read_buf, 0, NUM_SAMPLES * 2 + AST_FRIENDLY_OFFSET);
+		fr->data = pvt.read_buf + AST_FRIENDLY_OFFSET;
+		fr->offset = AST_FRIENDLY_OFFSET;
+		fr->frametype = AST_FRAME_VOICE;
+		fr->subclass = AST_FORMAT_SLINEAR;
+		fr->samples = NUM_SAMPLES;
+		fr->datalen = NUM_SAMPLES * 2;
+		memcpy(fr->data, input, NUM_SAMPLES * 2);
+		ast_queue_frame(pvt.owner, fr);
+	}
 
 	return paContinue;
 }



More information about the asterisk-commits mailing list