[svn-commits] marta: branch group/video_console r89608 - /team/group/video_console/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Nov 26 14:33:07 CST 2007


Author: marta
Date: Mon Nov 26 14:33:06 2007
New Revision: 89608

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89608
Log:
Added functions for the gui.

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

Modified: team/group/video_console/channels/chan_oss.c
URL: http://svn.digium.com/view/asterisk/team/group/video_console/channels/chan_oss.c?view=diff&rev=89608&r1=89607&r2=89608
==============================================================================
--- team/group/video_console/channels/chan_oss.c (original)
+++ team/group/video_console/channels/chan_oss.c Mon Nov 26 14:33:06 2007
@@ -805,9 +805,21 @@
 	return 0;
 }
 
+/*
+ * Print received message on gui
+ * or on console if the gui is not avaiable.
+ */
 static int oss_text(struct ast_channel *c, const char *text)
 {
-	/* print received messages */
+	struct video_desc *env = get_video_desc(c);
+
+	/* print received messages on gui */
+	/* XXX move x,y in the video_desc structure,
+	 * add w,h for the output screen, add checks for boundary */
+	if ( (env->sdl_ok) && (gui_output(env, text, 30, 20)) )
+		return 0;
+
+	/* print on gui failed, go to console */
 	ast_verbose(" << Console Received text %s >> \n", text);
 	return 0;
 }

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=89608&r1=89607&r2=89608
==============================================================================
--- team/group/video_console/channels/console_video.c (original)
+++ team/group/video_console/channels/console_video.c Mon Nov 26 14:33:06 2007
@@ -94,6 +94,7 @@
 
 #include <SDL/SDL.h>
 #include <SDL/SDL_image.h>	/* for loading images */
+#include <SDL/SDL_ttf.h>	/* render text on sdl surfaces */
 
 /*
  * In many places we use buffers to store the raw frames (but not only),
@@ -252,6 +253,7 @@
 
 	/* support for display. */
 	int                     sdl_ok;
+	int			gui_ok;
 	SDL_Surface             *screen;	/* the main window */
 	SDL_Surface		*keypad;	/* the pixmap for the keypad */
 	char			keypad_file[256];	/* image for the keypad */
@@ -259,6 +261,8 @@
 	char			keypad_mask[256];	/* background for the keypad */
 	char			inbuf[256];		/* buffer for keypad input */
 	int			inbuf_pos;	/* next free position in inbuf */
+	TTF_Font                *font;          /* font to be used */ 
+	char                    keypad_font[256];       /* font for the keypad */
 	int			outfd;		/* fd for output */
 	struct display_window	win[WIN_MAX];
 };
@@ -1781,6 +1785,16 @@
 
 static void cleanup_sdl(struct video_desc *env)  
 {
+	/* unload font file */ 
+	if (env->font) {
+		TTF_CloseFont(env->font);
+		env->font = NULL; 
+	}       
+
+	/* uninitialize SDL_ttf library */
+	if ( TTF_WasInit() )
+		TTF_Quit();
+
 	/* uninitialize the SDL environment */
 	int i;
 	for (i = 0; i < WIN_MAX; i++) {
@@ -2102,6 +2116,7 @@
  * lines:
  *	keypad = /tmp/phone.jpg		; define the keypad on the screen
  *	keypad_mask = /tmp/phone.png	; define the grayscale mask
+ *	keypad_font = /tmp/font.ttf	; define the font to use for output
  *
  * The mask image should be an 8-bit image for which we interpret
  * the pixel image as the key pressed, according to the table below
@@ -2111,22 +2126,24 @@
 /* enumerate for the pixel value */
 enum pixel_value {
 	/* answer/close function */
-	KEY_PICK_UP = 127,
-	KEY_HANG_UP = 128,
-	KEY_CONSOLE_DIAL = 129,
+	KEY_PICK_UP = 128,
+	KEY_HANG_UP = 129,
 
 	/* other functions */
-	KEY_MUTE = 131,
-	KEY_AUTOANSWER = 132,
-	KEY_SENDVIDEO = 126,
-	KEY_LOCALVIDEO = 124,
-	KEY_REMOTEVIDEO = 125,
+	KEY_MUTE = 130,
+	KEY_AUTOANSWER = 131,
+	KEY_SENDVIDEO = 132,
+	KEY_LOCALVIDEO = 133,
+	KEY_REMOTEVIDEO = 134,
+	KEY_WRITEMESSAGE = 135,
 
 	/* press outside the keypad */
-	KEY_OUT_OF_KEYPAD = 252,
-	KEY_REM_DPY = 253,
-	KEY_LOC_DPY = 254,
-
+	KEY_OUT_OF_KEYPAD = 251,
+	KEY_REM_DPY = 252,
+	KEY_LOC_DPY = 253,
+
+	/* close gui */
+	KEY_GUI_CLOSE = 254,
 	KEY_DIGIT_BACKGROUND = 255,
 };
 
@@ -2160,25 +2177,21 @@
 /* accumulate digits, possibly call dial if in connected mode */
 static void keypad_digit(struct video_desc *env, int digit)
 {	
-	if (env->inbuf_pos < sizeof(env->inbuf_pos) - 1) {
-		env->inbuf[env->inbuf_pos++] = digit;
-		env->inbuf[env->inbuf_pos] = '\0';
-	}
-	/* XXX see if we should call dial */
-}
-
-static void audio_console_dial(struct video_desc *env, int digit)
-{	
-	char dial[256] = "console dial ";
-
-	/* call to a ring phone or call a number */
-	strncat(dial, env->inbuf, sizeof(dial));
-	ast_log(LOG_WARNING, "Calling number %s\n", dial);
-
-	ast_cli_command(env->outfd, dial);
-	env->inbuf_pos = 0;
-	env->inbuf[env->inbuf_pos] = '\0';
-	return;
+	struct chan_oss_pvt *o = find_desc(oss_active);
+
+	if (o->owner) {
+		/* we have a call, send the digit */
+		struct ast_frame f = { AST_FRAME_DTMF, 0 };
+
+		f.subclass = digit;
+		ast_queue_frame(o->owner, &f);
+	} else {
+		/* no call, accumulate digits */
+		if (env->inbuf_pos < sizeof(env->inbuf) - 1) {
+			env->inbuf[env->inbuf_pos++] = digit;
+			env->inbuf[env->inbuf_pos] = '\0';
+		}
+	}
 }
 
 static void keypad_send_command(struct video_desc *env, char *command)
@@ -2212,14 +2225,74 @@
 }
 
 /*
- * function called when the pick up button is pressed.
- * If no one is calling us the operation have no effects,
- * if someone is calling us we answer to the call.
- * if a call is in progress we send the digits to the console
- */
-static attribute_unused void keypad_pick_up(void)
-{
-
+ * Function called when the pick up button is pressed
+ * perform actions according the channel status:
+ *
+ *  - if no one is calling us and no digits was pressed,
+ *    the operation have no effects,
+ *  - if someone is calling us we answer to the call.
+ *  - if we have no call in progress and we pressed some
+ *    digit, send the digit to the console.
+ */
+static void keypad_pick_up(struct video_desc *env)
+{
+	struct chan_oss_pvt *o = find_desc(oss_active);
+	ast_log(LOG_WARNING, "keypad_pick_up called\n");
+
+	if (o->owner) {
+		/* someone is calling us */
+		struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
+		o->hookstate = 1;
+		o->cursound = -1;
+		o->nosound = 0;
+		ast_queue_frame(o->owner, &f);
+	} else if (env->inbuf_pos) {
+		/* we have someone to call */
+		ast_cli_command(env->outfd, env->inbuf);
+	}
+
+	env->inbuf_pos = 0;
+	env->inbuf[env->inbuf_pos] = '\0';
+}
+
+/* Print given text on the gui */
+static int gui_output(struct video_desc *env, const char *text, int x, int y)
+{
+	SDL_Surface *output;
+	SDL_Color color = {0, 0, 0};	/* text color */
+	SDL_Rect dest = {env->win[WIN_KEYPAD].rect.x + x, y};
+
+	/* clean surface each rewrite */
+	SDL_BlitSurface(env->keypad, NULL, env->screen, &env->win[WIN_KEYPAD].rect);
+
+	output = TTF_RenderText_Solid(env->font, text, color);
+	if (output == NULL) {
+		ast_log(LOG_WARNING, "Cannot render text on gui - %s\n", TTF_GetError());
+		return 0;
+	}
+
+	SDL_BlitSurface(output, NULL, env->screen, &dest);
+	
+	#if 0
+	if (SDL_Flip(env->screen) < 0) {
+		ast_log(LOG_WARNING, "Error updating gui screen\n");
+		return 0;
+	}
+	#endif
+
+	SDL_UpdateRects(env->keypad, 1, &env->win[WIN_KEYPAD].rect);
+	SDL_FreeSurface(output);
+	return 1;
+}
+
+static void keypad_write_message(struct video_desc *env)
+{
+	ast_log(LOG_WARNING, "keypad_write_message called\n");
+}
+
+static void keypad_test(struct video_desc *env)
+{
+	ast_log(LOG_WARNING, "keypad_test called\n");
 }
 
 static SDL_Surface *get_keypad(const char *file)
@@ -2239,7 +2312,7 @@
 
 /* TODO: consistency checks, check for bpp, widht and height */
 /* Init the mask image used to grab the action. */
-static int init_console_gui(struct video_desc *env)
+static int gui_init(struct video_desc *env)
 {
 	/* Load the keypad mask image */
 	env->keypad_bg = get_keypad(env->keypad_mask);
@@ -2248,6 +2321,21 @@
 
 	env->inbuf_pos = 0;
 	env->inbuf[env->inbuf_pos] = '\0';
+
+	/* Initialize SDL_ttf library and load font */
+	if (TTF_Init() == -1) {
+		ast_log(LOG_WARNING, "Unable to init SDL_ttf, no output avaiable\n");
+		return -1;
+	}
+
+#define GUI_FONTSIZE 28
+	env->font = TTF_OpenFont( env->keypad_font, GUI_FONTSIZE);
+	if (!env->font) {
+		ast_log(LOG_WARNING, "Unable to load font %s, no output avaiable\n", env->keypad_font);
+		return -1;
+	}
+	ast_log(LOG_WARNING, "Loaded font %s\n", env->keypad_font);
+
 	env->outfd = open ("/dev/null", O_WRONLY);	/* discard output, temporary */
 	if ( env->outfd < 0 ) {
 		ast_log(LOG_WARNING, "Unable output fd\n");
@@ -2288,13 +2376,10 @@
 	switch (index) {
 	/* answer/close function */
 	case KEY_PICK_UP:
-		keypad_send_command(env, "console answer");
+		keypad_pick_up(env);
 		break;
 	case KEY_HANG_UP:
 		keypad_send_command(env, "console hangup");
-		break;
-	case KEY_CONSOLE_DIAL:
-		audio_console_dial(env, index);
 		break;
 
 	/* other functions */
@@ -2308,6 +2393,10 @@
 		break;
 	case KEY_REMOTEVIDEO:
 		break;
+	case KEY_WRITEMESSAGE:
+		keypad_write_message(env);
+		break;
+
 
 	/* press outside the keypad */
 	case KEY_REM_DPY:
@@ -2317,6 +2406,9 @@
 	case KEY_OUT_OF_KEYPAD:
 		break;
 
+	case KEY_GUI_CLOSE:
+		cleanup_sdl(env);
+		break;
 	case KEY_DIGIT_BACKGROUND:
 		break;
 	default:
@@ -2393,7 +2485,8 @@
 	}
 
 	/* TODO, segfault if not X display present */
-	if (init_console_gui(env))
+	env->gui_ok = !gui_init(env);
+	if (!env->gui_ok)
 		ast_log(LOG_WARNING, "cannot init console gui\n");
 
 	for (;;) {
@@ -2418,7 +2511,7 @@
 		}
 
 		/* manage keypad events */
-		if (env->keypad_bg)
+		if (env->gui_ok)
 			eventhandler(env);
  
 		/* sleep for a while */
@@ -2764,6 +2857,7 @@
         M_F("remote_size", video_geom(&env->in.rem_dpy, val))
         M_STR("keypad", env->keypad_file)
         M_STR("keypad_mask", env->keypad_mask)
+	M_STR("keypad_font", env->keypad_font)
         M_UINT("fps", env->out.fps)
         M_UINT("bitrate", env->out.bitrate)
         M_UINT("qmin", env->out.qmin)




More information about the svn-commits mailing list