[asterisk-commits] rizzo: branch group/video_console r90549 - /team/group/video_console/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 3 12:41:29 CST 2007


Author: rizzo
Date: Mon Dec  3 12:41:28 2007
New Revision: 90549

URL: http://svn.digium.com/view/asterisk?view=rev&rev=90549
Log:
Enable dynamic resizing of local and remote window using the
center and right mouse keys.


Modified:
    team/group/video_console/channels/console_video.c

Modified: team/group/video_console/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/group/video_console/channels/console_video.c?view=diff&rev=90549&r1=90548&r2=90549
==============================================================================
--- team/group/video_console/channels/console_video.c (original)
+++ team/group/video_console/channels/console_video.c Mon Dec  3 12:41:28 2007
@@ -2353,6 +2353,8 @@
 
         return pixel_value;
 }
+static int video_geom(struct fbuf_t *b, const char *s);
+static void sdl_setup(struct video_desc *env);
 
 /*
  * Handle SDL_MOUSEBUTTONDOWN type, finding the palette
@@ -2360,25 +2362,25 @@
  *
  * x, y are referred to the upper left corner of the main SDL window.
  */
-static void handle_button_event(struct video_desc *env, uint16_t x, uint16_t y)
-{
-	uint8_t index;
+static void handle_button_event(struct video_desc *env, SDL_MouseButtonEvent button)
+{
+	uint8_t index;	/* the key or region of the display we clicked on */
 
 	/* for each click we come back in normal mode */
 	env->gui.text_mode = 0;
 
 	/* define keypad boundary */
-	if (x < env->in.rem_dpy.w)
+	if (button.x < env->in.rem_dpy.w)
 		index = KEY_REM_DPY; /* click on remote video */
-	else if (x > env->in.rem_dpy.w + env->out.keypad_dpy.w)
+	else if (button.x > env->in.rem_dpy.w + env->out.keypad_dpy.w)
 		index = KEY_LOC_DPY; /* click on local video */
-	else if (y > env->out.keypad_dpy.h)
+	else if (button.y > env->out.keypad_dpy.h)
 		index = KEY_OUT_OF_KEYPAD; /* click outside the keypad */
 	else
-		index = map_click(env->gui.keypad_bg, x - env->in.rem_dpy.w, y);
+		index = map_click(env->gui.keypad_bg, button.x - env->in.rem_dpy.w, button.y);
 
 	/* exec the function */
-	if (index < 128) {
+	if (index < 128) {	/* surely clicked on the keypad, don't care which key */
 		keypad_digit(env, index);
 		return;
 	}
@@ -2408,15 +2410,26 @@
 		break;
 
 
-	/* press outside the keypad */
+	/* press outside the keypad. right increases size, center decreases, left drags */
+	case KEY_LOC_DPY:
 	case KEY_REM_DPY:
-		break;
-	case KEY_LOC_DPY:
-		/* store points where the drag start
-		* and switch in drag mode */
-		env->gui.x_drag = x;
-		env->gui.y_drag = y;
-		env->gui.drag_mode = 1;
+		if (button.button == SDL_BUTTON_LEFT) {
+			if (index == KEY_LOC_DPY) {
+				/* store points where the drag start
+				* and switch in drag mode */
+				env->gui.x_drag = button.x;
+				env->gui.y_drag = button.y;
+				env->gui.drag_mode = 1;
+			}
+			break;
+		} else {
+			char buf[128];
+			struct fbuf_t *fb = index == KEY_LOC_DPY ? &env->out.loc_dpy : &env->in.rem_dpy;
+			sprintf(buf, "%c%dx%d", button.button == SDL_BUTTON_RIGHT ? '>' : '<',
+				fb->w, fb->h);
+			video_geom(fb, buf);
+			sdl_setup(env);
+		}
 		break;
 	case KEY_OUT_OF_KEYPAD:
 		break;
@@ -2533,7 +2546,7 @@
 					move_capture_source(env, ev[i].motion.x, ev[i].motion.y);
 				break;
 			case SDL_MOUSEBUTTONDOWN:
-				handle_button_event(env, ev[i].button.x, ev[i].button.y);
+				handle_button_event(env, ev[i].button);
 				break;
 			case SDL_MOUSEBUTTONUP:
 				if (env->gui.drag_mode != 0) {
@@ -2635,7 +2648,22 @@
 	struct video_desc *env = arg;
 	int count = 0;
 
-	sdl_setup(env);
+	env->screen = NULL;
+	bzero(env->win, sizeof(env->win));
+
+	if (SDL_Init(SDL_INIT_VIDEO)) {
+		ast_log(LOG_WARNING, "Could not initialize SDL - %s\n",
+			SDL_GetError());
+		/* again not fatal, just we won't display anything */
+	} else {
+		sdl_setup(env);
+		if (env->sdl_ok)
+			ast_mutex_init(&env->in.dec_in_lock);
+		/* TODO, segfault if not X display present */
+		env->gui_ok = !gui_init(env);
+		if (!env->gui_ok)
+			ast_log(LOG_WARNING, "cannot init console gui\n");
+	}
 	if (video_open(&env->out)) {
 		ast_log(LOG_WARNING, "cannot open local video source\n");
 	} else {
@@ -2646,11 +2674,6 @@
 			ast_channel_set_fd(env->owner, 1, env->out.fd);
 		video_out_init(env);
 	}
-
-	/* TODO, segfault if not X display present */
-	env->gui_ok = !gui_init(env);
-	if (!env->gui_ok)
-		ast_log(LOG_WARNING, "cannot init console gui\n");
 
 	for (;;) {
 		/* XXX 20 times/sec */
@@ -2834,6 +2857,7 @@
 	ast_pthread_create_background(&env->vthread, NULL, video_thread, env);
 }
 
+/* [re]set the main sdl window, useful in case of resize */
 static void sdl_setup(struct video_desc *env)
 {
 	int dpy_fmt = SDL_IYUV_OVERLAY;	/* YV12 causes flicker in SDL */
@@ -2847,20 +2871,10 @@
 	 * - on the center, the keypad
 	 * - on the right, the local video
 	 */
-	ast_log(LOG_WARNING, "prepare SDL initialization\n");
-
-	env->screen = NULL;
-	bzero(env->win, sizeof(env->win));
-
-	if (SDL_Init(SDL_INIT_VIDEO)) {
-		ast_log(LOG_WARNING, "Could not initialize SDL - %s\n",
-			SDL_GetError());
-		/* again not fatal, just we won't display anything */
-		goto no_sdl;
-	}
 
 	/* Fetch the keypad now, we need it to know its size */
-	env->gui.keypad = get_keypad(env->keypad_file);
+	if (!env->gui.keypad)
+		env->gui.keypad = get_keypad(env->keypad_file);
 	if (env->gui.keypad) {
 		env->out.keypad_dpy.w = env->gui.keypad->w;
 		env->out.keypad_dpy.h = env->gui.keypad->h;
@@ -2875,6 +2889,7 @@
 		ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
 		goto no_sdl;
 	}
+
 	SDL_WM_SetCaption("Asterisk console Video Output", NULL);
 	if (set_win(env->screen, &env->win[WIN_REMOTE], dpy_fmt,
 			env->in.rem_dpy.w, env->in.rem_dpy.h, BORDER, BORDER))
@@ -2896,7 +2911,6 @@
 		SDL_BlitSurface(env->gui.keypad, NULL, env->screen, dest);
 		SDL_UpdateRects(env->screen, 1, dest);
 	}
-	ast_mutex_init(&env->in.dec_in_lock);
 	env->in.dec_in_cur = &env->in.dec_in[0];
 	env->in.dec_in_dpy = NULL;	/* nothing to display */
 	env->sdl_ok = 1;
@@ -2904,7 +2918,6 @@
 no_sdl:
 	if (env->sdl_ok == 0)	/* free resources in case of errors */
 		cleanup_sdl(env);
-
 }
 
 /* see chan_oss.c for these macros */
@@ -2920,28 +2933,49 @@
 #endif
 
 /*
- * Parse a geometry string, accepting also common names for the formats
+ * Parse a geometry string, accepting also common names for the formats.
+ * Trick: if we have a leading > or < and a numeric geometry,
+ * we return the larger or smaller one.
+ * E.g. <352x288 gives the smaller one, 320x240
  */
 static int video_geom(struct fbuf_t *b, const char *s)
 {
+	int mode = 0;
+	int w = 0, h = 0;
+
 	static struct {
 		const char *s; int w; int h;
 	} *fp, formats[] = {
+		{"vga",		640, 480 },
 		{"cif",		352, 288 },
+		{"qvga",	320, 240 },
 		{"qcif",	176, 144 },
 		{"sqcif",	128, 96 },
-		{"vga",		640, 480 },
-		{"qvga",	320, 240 },
 		{NULL,		0, 0 },
 	};
+	if (s[0] == '<')
+		mode = -1;
+	else if (s[0] == '>')
+		mode = 1;
+	if (mode)
+		sscanf(s+1,"%dx%d", &w, &h);
 	for (fp = formats; fp->s; fp++) {
-		if (!strcasecmp(s, fp->s)) {
-			b->w = fp->w;
-			b->h = fp->h;
-			return 0;
+		if (mode > 0 && fp->w <= w) {	/* look for a larger one */
+			if (fp > formats)	/* back one step if possible */
+				fp--;
+			break;
+		} else if (mode < 0 && fp->w < w) { /* look for a smaller one */
+			if (fp->w == 0)		/* back one if reached the end */
+				fp--;
+			break;
+		} else if (mode == 0 && !strcasecmp(s, fp->s)) { /* look for a string match */
+			break;
 		}
 	}
-	if (sscanf(s, "%dx%d", &b->w, &b->h) != 2) {
+	if (fp) {
+		b->w = fp->w;
+		b->h = fp->h;
+	} else if (sscanf(s, "%dx%d", &b->w, &b->h) != 2) {
 		ast_log(LOG_WARNING, "Invalid video_size %s, using 352x288\n", s);
 		b->w = 352;
 		b->h = 288;




More information about the asterisk-commits mailing list