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

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


Author: russell
Date: Wed Dec 27 20:17:19 2006
New Revision: 49015

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49015
Log:
- add "console hangup"
- fix setting the exten and context when using "console dial"
- actually copy the audio into the frame

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=49015&r1=49014&r2=49015
==============================================================================
--- team/russell/chan_console/channels/chan_console.c (original)
+++ team/russell/chan_console/channels/chan_console.c Wed Dec 27 20:17:19 2006
@@ -59,6 +59,7 @@
 	PaStream *stream;
 	const char *name;
 	struct ast_frame fr;
+	char read_buf[NUM_SAMPLES * 2 + AST_FRIENDLY_OFFSET];
 	char write_buf[NUM_SAMPLES * 2];
 	unsigned int write_dst;
 	ast_cond_t cond;
@@ -105,7 +106,7 @@
 /*!
  * \note Called with console_lock locked
  */
-static struct ast_channel *console_new(struct console_pvt *pvt, int state)
+static struct ast_channel *console_new(struct console_pvt *pvt, const char *ext, const char *ctx, int state)
 {
 	struct ast_channel *chan;
 
@@ -119,6 +120,11 @@
 	chan->tech_pvt = pvt;
 	pvt->owner = chan;
 
+	if (!ast_strlen_zero(ext))
+		ast_copy_string(chan->exten, ext, sizeof(chan->exten));
+	if (!ast_strlen_zero(ctx))
+		ast_copy_string(chan->context, ctx, sizeof(chan->context));
+
 	if (state != AST_STATE_DOWN && ast_pbx_start(chan)) {
 		ast_log(LOG_WARNING, "Unable to start PBX on %s\n", chan->name);
 		chan->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
@@ -146,7 +152,7 @@
 	if (pvt.owner) {
 		ast_log(LOG_NOTICE, "Console channel already active!\n");
 		*cause = AST_CAUSE_BUSY;
-	} else if (!(chan = console_new(&pvt, AST_STATE_DOWN)))
+	} else if (!(chan = console_new(&pvt, NULL, NULL, AST_STATE_DOWN)))
 		ast_log(LOG_WARNING, "Unable to create new Console channel!\n");
 
 	ast_mutex_unlock(&console_lock);
@@ -233,9 +239,9 @@
 	PaError err;
 	int res = 0;
 
-	ast_log(LOG_NOTICE, "console_call...\n");
-
-	ast_verbose(" << Call to device '%s' dnid '%s' rdnis '%s' on console from '%s' <%s> >>\n", dest, c->cid.cid_dnid, c->cid.cid_rdnis, c->cid.cid_name, c->cid.cid_num);
+	ast_verbose(" << Call to device '%s' dnid '%s' rdnis '%s' on console "
+		"from '%s' <%s> >>\n", dest, c->cid.cid_dnid, 
+		c->cid.cid_rdnis, c->cid.cid_name, c->cid.cid_num);
 	ast_verbose(" << Auto-answered >> \n");
 	pvt.hookstate = 1;
 	f.frametype = AST_FRAME_CONTROL;
@@ -255,11 +261,10 @@
 {
 	struct ast_frame *fr = ast_frdup(f);
 
-	ast_log(LOG_NOTICE, "console_write...\n");
+	//ast_log(LOG_NOTICE, "console_write...\n");
 
 	if (!fr)
-		return -1;
-
+		return -1; 
 	ast_mutex_lock(&console_lock);
 	AST_LIST_INSERT_TAIL(&pvt.frames, fr, frame_list);
 	ast_cond_signal(&pvt.cond);
@@ -290,12 +295,12 @@
 	struct ast_frame *fr = &pvt.fr;
 	unsigned int num_samples;
 
-	ast_log(LOG_NOTICE, "console_callback, frame_count: %lu ...\n", frame_count);
+	//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);
+		//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;
@@ -305,14 +310,14 @@
 		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);
+		//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_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);
 	}
@@ -324,14 +329,15 @@
 	}
 
 	memset(fr, 0, sizeof(*fr));
-	fr->data = fr + sizeof(*fr) + AST_FRIENDLY_OFFSET;
+	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 = frame_count;
-	fr->datalen = frame_count * 2;
-
-	memcpy(fr->data, input, frame_count * 2);
+	fr->samples = NUM_SAMPLES;
+	fr->datalen = NUM_SAMPLES * 2;
+
+	memcpy(fr->data, input, NUM_SAMPLES * 2);
 
 	ast_queue_frame(pvt.owner, fr);
 
@@ -360,7 +366,7 @@
 	if (*ext == NULL)
 		return NULL;
 
-	if (pvt.overridecontext) {
+	if (!pvt.overridecontext) {
 		/* parse from the right */
 		*ctx = strrchr(*ext, '@');
 		if (*ctx)
@@ -370,7 +376,7 @@
 	return *ext;
 }
 
-static char *console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+static char *cli_console_dial(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char *s = NULL, *mye = NULL, *myc = NULL;
 
@@ -402,8 +408,11 @@
 		return CLI_SUCCESS;
 	}
 	/* if we have an argument split it into extension and context */
-	if (a->argc == e->args + 1)
+	if (a->argc == e->args + 1) {
 		s = ast_ext_ctx(a->argv[e->args], &mye, &myc);
+		ast_log(LOG_NOTICE, "provided '%s', exten '%s' context '%s'\n", a->argv[e->args], mye, myc);
+	} else
+		ast_log(LOG_NOTICE, "No exten?\n");
 	/* supply default values if needed */
 	if (mye == NULL)
 		mye = "s";
@@ -411,7 +420,7 @@
 		myc = "default";
 	if (ast_exists_extension(NULL, myc, mye, 1, NULL)) {
 		pvt.hookstate = 1;
-		console_new(&pvt, AST_STATE_RINGING);
+		console_new(&pvt, mye, myc, AST_STATE_RINGING);
 	} else
 		ast_cli(a->fd, "No such extension '%s' in context '%s'\n", mye, myc);
 	if (s)
@@ -419,8 +428,33 @@
 	return CLI_SUCCESS;
 }
 
+static char *cli_console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
+{
+	if (cmd == CLI_INIT) {
+		e->command = "console hangup";
+		e->usage =
+			"Usage: console hangup\n"
+			"       Hangs up any call currently placed on the console.\n";
+		return NULL;
+	} else if (cmd == CLI_GENERATE)
+		return NULL;
+
+	if (a->argc != e->args)
+		return CLI_SHOWUSAGE;
+	if (!pvt.owner && !pvt.hookstate) {
+		ast_cli(a->fd, "No call to hang up\n");
+		return CLI_FAILURE;
+	}
+	pvt.hookstate = 0;
+	if (pvt.owner)
+		ast_queue_hangup(pvt.owner);
+
+	return CLI_SUCCESS;
+}
+
 static struct ast_cli_entry cli_console[] = {
-	NEW_CLI(console_dial, "Dial an extension from the console"),
+	NEW_CLI(cli_console_dial, "Dial an extension from the console"),
+	NEW_CLI(cli_console_hangup, "Hangup a call on the console"),
 };
 
 static int unload_module(void)



More information about the asterisk-commits mailing list