[asterisk-commits] rizzo: branch group/video_console r89627 - /team/group/video_console/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Nov 27 06:13:12 CST 2007
Author: rizzo
Date: Tue Nov 27 06:13:12 2007
New Revision: 89627
URL: http://svn.digium.com/view/asterisk?view=rev&rev=89627
Log:
rearrange code and some minor cleanup
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=89627&r1=89626&r2=89627
==============================================================================
--- team/group/video_console/channels/console_video.c (original)
+++ team/group/video_console/channels/console_video.c Tue Nov 27 06:13:12 2007
@@ -2120,28 +2120,44 @@
return v->enc->enc_encap(v, tail);
}
-/* The following functions process events on the console keypad.
+/*
+ * GUI layout, structure and management
*
- * For the console keypad we use two images,
- * one to be displayed on the screen and another
- * representing a mask with buttons we want to associate
- * to a specific function.
+
+For the GUI we use SDL to create a large surface (env->screen)
+containing tree sections: remote video on the left, local video
+on the right, and the keypad with all controls and text windows
+in the center.
+The central section is built using two images: one is the skin,
+the other one is a mask where the sensitive areas of the skin
+are colored in different grayscale levels according to their
+functions. The mapping between colors and function is defined
+in the 'enum pixel_value' below.
+
+Mouse and keyboard events are detected on the whole surface, and
+handled differently according to their location, as follows:
+
+- drag on the local video window are used to move the captured
+ area (in the case of X11 grabber) or the picture-in-picture
+ location (in case of camera included on the X11 grab).
+- click on the keypad are mapped to the corresponding key;
+- drag on some keypad areas (sliders etc.) are mapped to the
+ corresponding functions;
+- keystrokes are used as keypad functions, or as text input
+ if we are in text-input mode.
+
+Configuration options control the appeareance of the gui:
+
+ keypad = /tmp/phone.jpg ; the keypad on the screen
+ keypad_mask = /tmp/phone.png ; the grayscale mask
+ keypad_font = /tmp/font.ttf ; the font to use for output
+
*
- * These two images are specified in the console channel
- * configuration file (oss or alsa) by adding the following
- * 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
- * (keys between 0 and 127 correspond to characters).
- */
-
-/* enumerate for the pixel value */
+ */
+
+/* enumerate for the pixel value. 0..127 correspond to ascii chars */
enum pixel_value {
- /* answer/close function */
+ /* answer/close functions */
KEY_PICK_UP = 128,
KEY_HANG_UP = 129,
@@ -2152,57 +2168,32 @@
KEY_LOCALVIDEO = 133,
KEY_REMOTEVIDEO = 134,
KEY_WRITEMESSAGE = 135,
-
- /* press outside the keypad */
+ KEY_GUI_CLOSE = 136, /* close gui */
+
+ /* other areas within the keypad */
+ KEY_DIGIT_BACKGROUND = 255,
+
+ /* areas outside the keypad - simulated */
KEY_OUT_OF_KEYPAD = 251,
KEY_REM_DPY = 252,
KEY_LOC_DPY = 253,
-
- /* close gui */
- KEY_GUI_CLOSE = 254,
- KEY_DIGIT_BACKGROUND = 255,
};
/*
- * For each event we read the x, y coordinates and get the pixel value.
- */
-static uint8_t get_color(struct SDL_Surface *keymask, int x, int y)
-{
- uint8_t *pixel = keymask->pixels; /* pixel data pointer */
- uint8_t pixel_value; /* palette index */
- int has_palette = 0;
- SDL_Color col1;
- SDL_Color *col = &col1;
-
- SDL_LockSurface(keymask); /* Do we really need to lock the surface ? */
- pixel_value = pixel[(y*keymask->pitch) + x]; /* pitch takes care of alignment */
- if (keymask->format->palette && keymask->format->BitsPerPixel <= 8) {
- has_palette = 1;
- col = &keymask->format->palette->colors[pixel_value];
- }
-
- SDL_UnlockSurface(keymask);
-
- ast_log(LOG_WARNING, "pixel %d %d bpp %d palette %d value %d colors %d %d %d\n",
- x, y, keymask->format->BitsPerPixel,
- has_palette, pixel_value, col->r, col->g, col->b);
-
- return pixel_value;
-}
+ * Handlers for the various keypad functions
+ */
/* accumulate digits, possibly call dial if in connected mode */
static void keypad_digit(struct video_desc *env, int digit)
{
struct chan_oss_pvt *o = find_desc(oss_active);
- if (o->owner) {
- /* we have a call, send the digit */
+ 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 */
+ } 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';
@@ -2210,6 +2201,7 @@
}
}
+/* this is a wrapper for actions that are available through the cli */
static void keypad_send_command(struct video_desc *env, char *command)
{
ast_log(LOG_WARNING, "keypad_send_command(%s) called\n", command);
@@ -2217,15 +2209,12 @@
return;
}
-/* function used to switch on/off the status of some variables */
-static char *keypad_switch(int index)
+/* function used to toggle on/off the status of some variables */
+static char *keypad_toggle(int index)
{
struct chan_oss_pvt *o = find_desc(oss_active);
- ast_log(LOG_WARNING, "keypad_switch(%i) called\n", index);
-
- if ( o == NULL )
- return NULL;
-
+ ast_log(LOG_WARNING, "keypad_toggle(%i) called\n", index);
+
switch (index) {
case KEY_MUTE:
o->mute = !o->mute;
@@ -2304,64 +2293,32 @@
ast_log(LOG_WARNING, "keypad_write_message called\n");
}
-static attribute_unused void keypad_test(struct video_desc *env)
-{
- ast_log(LOG_WARNING, "keypad_test called\n");
-}
-
-static SDL_Surface *get_keypad(const char *file)
-{
- SDL_Surface *temp;
-
-#ifdef HAVE_SDL_IMAGE
- temp = IMG_Load(file);
-#else
- temp = SDL_LoadBMP(file);
-#endif
- if (temp == NULL)
- fprintf(stderr, "Unable to load image %s: %s\n",
- file, SDL_GetError());
- return temp;
-}
-
-/* TODO: consistency checks, check for bpp, widht and height */
-/* Init the mask image used to grab the action. */
-static int gui_init(struct video_desc *env)
-{
- /* Load the keypad mask image */
- env->keypad_bg = get_keypad(env->keypad_mask);
- if (env->keypad_bg == NULL)
- return -1;
-
- env->inbuf_pos = 0;
- env->inbuf[env->inbuf_pos] = '\0';
-
-#ifdef HAVE_SDL_TTF
- /* 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);
-#endif
-
- env->outfd = open ("/dev/null", O_WRONLY); /* discard output, temporary */
- if ( env->outfd < 0 ) {
- ast_log(LOG_WARNING, "Unable output fd\n");
- return -1;
- }
-
- ast_log(LOG_WARNING,"w %i, h %i, pitch %i\n", \
- env->keypad_bg->w, env->keypad_bg->h, env->keypad_bg->pitch);
-
- return 0;
+
+/*
+ * Map the x, y coordinates to a keypad event according to
+ * the mask.
+ */
+static uint8_t map_click(struct SDL_Surface *keymask, int x, int y)
+{
+ uint8_t *pixel = keymask->pixels; /* pixel data pointer */
+ uint8_t pixel_value; /* palette index */
+ int has_palette = 0;
+ SDL_Color col1;
+ SDL_Color *col = &col1;
+
+ SDL_LockSurface(keymask); /* Do we really need to lock the surface ? */
+ pixel_value = pixel[(y*keymask->pitch) + x]; /* pitch takes care of alignment */
+ SDL_UnlockSurface(keymask);
+ if (keymask->format->palette && keymask->format->BitsPerPixel <= 8) {
+ has_palette = 1;
+ col = &keymask->format->palette->colors[pixel_value];
+ }
+
+ ast_log(LOG_WARNING, "pixel %d %d bpp %d palette %d value %d colors %d %d %d\n",
+ x, y, keymask->format->BitsPerPixel,
+ has_palette, pixel_value, col->r, col->g, col->b);
+
+ return pixel_value;
}
/*
@@ -2382,7 +2339,7 @@
else if (y > env->out.keypad_dpy.h)
index = KEY_OUT_OF_KEYPAD; /* click outside the keypad */
else
- index = get_color(env->keypad_bg, x - env->in.rem_dpy.w, y);
+ index = map_click(env->keypad_bg, x - env->in.rem_dpy.w, y);
/* exec the function */
if (index < 128) {
@@ -2402,7 +2359,7 @@
case KEY_MUTE:
case KEY_AUTOANSWER:
case KEY_SENDVIDEO:
- keypad_switch(index);
+ keypad_toggle(index);
break;
case KEY_LOCALVIDEO:
@@ -2473,6 +2430,61 @@
fprintf(stderr, "-------- SDL_PumpEvents took %dms\n", i);
//SDL_Unlock_EventThread();
}
+}
+
+static SDL_Surface *get_keypad(const char *file)
+{
+ SDL_Surface *temp;
+
+#ifdef HAVE_SDL_IMAGE
+ temp = IMG_Load(file);
+#else
+ temp = SDL_LoadBMP(file);
+#endif
+ if (temp == NULL)
+ fprintf(stderr, "Unable to load image %s: %s\n",
+ file, SDL_GetError());
+ return temp;
+}
+
+/* TODO: consistency checks, check for bpp, widht and height */
+/* Init the mask image used to grab the action. */
+static int gui_init(struct video_desc *env)
+{
+ /* Load the keypad mask image */
+ env->keypad_bg = get_keypad(env->keypad_mask);
+ if (env->keypad_bg == NULL)
+ return -1;
+
+ env->inbuf_pos = 0;
+ env->inbuf[env->inbuf_pos] = '\0';
+
+#ifdef HAVE_SDL_TTF
+ /* Initialize SDL_ttf library and load font */
+ if (TTF_Init() == -1) {
+ ast_log(LOG_WARNING, "Unable to init SDL_ttf, no output available\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 available\n", env->keypad_font);
+ return -1;
+ }
+ ast_log(LOG_WARNING, "Loaded font %s\n", env->keypad_font);
+#endif
+
+ env->outfd = open ("/dev/null", O_WRONLY); /* discard output, temporary */
+ if ( env->outfd < 0 ) {
+ ast_log(LOG_WARNING, "Unable output fd\n");
+ return -1;
+ }
+
+ ast_log(LOG_WARNING,"w %i, h %i, pitch %i\n", \
+ env->keypad_bg->w, env->keypad_bg->h, env->keypad_bg->pitch);
+
+ return 0;
}
static void sdl_setup(struct video_desc *env);
More information about the asterisk-commits
mailing list