[asterisk-commits] rizzo: branch group/video_console r89628 - /team/group/video_console/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Nov 27 06:29:29 CST 2007
Author: rizzo
Date: Tue Nov 27 06:29:28 2007
New Revision: 89628
URL: http://svn.digium.com/view/asterisk?view=rev&rev=89628
Log:
pack most gui-related fields in the same structure
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=89628&r1=89627&r2=89628
==============================================================================
--- team/group/video_console/channels/console_video.c (original)
+++ team/group/video_console/channels/console_video.c Tue Nov 27 06:29:28 2007
@@ -239,42 +239,48 @@
/* our representation of a displayed window. SDL can only do one main
* window so we map everything within that one
*/
-enum { WIN_LOCAL, WIN_REMOTE, WIN_KEYPAD, WIN_ALL, WIN_MAX };
+enum { WIN_LOCAL, WIN_REMOTE, WIN_KEYPAD, WIN_MAX };
struct display_window {
SDL_Overlay *bmp;
SDL_Rect rect; /* loc. of images */
};
-
-/*
- * The overall descriptor, with room for config info, video source and
- * received data descriptors, SDL info, etc.
- */
-struct video_desc {
- char codec_name[64]; /* the codec we use */
-
- pthread_t vthread; /* video thread */
- int shutdown; /* set to shutdown vthread */
- struct ast_channel *owner; /* owner channel */
-
- struct video_in_desc in; /* remote video descriptor */
- struct video_out_desc out; /* local video descriptor */
-
- /* 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 */
- SDL_Surface *keypad_bg; /* the keypad background, mapping locations to keys */
- char keypad_mask[256]; /* background for the keypad */
+
+/*! \brief info related to the gui: button status, mouse coords, etc. */
+struct gui_info {
char inbuf[256]; /* buffer for keypad input */
int inbuf_pos; /* next free position in inbuf */
#ifdef HAVE_SDL_TTF
TTF_Font *font; /* font to be used */
#endif
+ int outfd; /* fd for output */
+ SDL_Surface *keypad; /* the pixmap for the keypad */
+ SDL_Surface *keypad_bg; /* the keypad background, mapping locations to keys */
+};
+
+/*
+ * The overall descriptor, with room for config info, video source and
+ * received data descriptors, SDL info, etc.
+ */
+struct video_desc {
+ char codec_name[64]; /* the codec we use */
+
+ pthread_t vthread; /* video thread */
+ int shutdown; /* set to shutdown vthread */
+ struct ast_channel *owner; /* owner channel */
+
+ struct video_in_desc in; /* remote video descriptor */
+ struct video_out_desc out; /* local video descriptor */
+
+ struct gui_info gui;
+
+ /* support for display. */
+ int sdl_ok;
+ int gui_ok;
+ SDL_Surface *screen; /* the main window */
+ char keypad_file[256]; /* image for the keypad */
+ char keypad_mask[256]; /* background for the keypad */
char keypad_font[256]; /* font for the keypad */
- int outfd; /* fd for output */
struct display_window win[WIN_MAX];
};
@@ -1802,9 +1808,9 @@
#ifdef HAVE_SDL_TTF
/* unload font file */
- if (env->font) {
- TTF_CloseFont(env->font);
- env->font = NULL;
+ if (env->gui.font) {
+ TTF_CloseFont(env->gui.font);
+ env->gui.font = NULL;
}
/* uninitialize SDL_ttf library */
@@ -1817,11 +1823,11 @@
if (env->win[i].bmp)
SDL_FreeYUVOverlay(env->win[i].bmp);
}
- if (env->keypad)
- SDL_FreeSurface(env->keypad);
- if (env->keypad_bg)
- SDL_FreeSurface(env->keypad_bg);
- env->keypad = env->keypad_bg = NULL;
+ if (env->gui.keypad)
+ SDL_FreeSurface(env->gui.keypad);
+ if (env->gui.keypad_bg)
+ SDL_FreeSurface(env->gui.keypad_bg);
+ env->gui.keypad = env->gui.keypad_bg = NULL;
SDL_Quit();
env->screen = NULL; /* XXX check reference */
bzero(env->win, sizeof(env->win));
@@ -2183,6 +2189,20 @@
* Handlers for the various keypad functions
*/
+/*! \brief append a character, or reset if '\0' */
+static void append_char(struct video_desc *env, const char c)
+{
+ int i = env->gui.inbuf_pos;
+ if (c == '\0')
+ i = 0;
+ else if (i < sizeof(env->gui.inbuf) - 1)
+ env->gui.inbuf[i++] = c;
+ else
+ i = sizeof(env->gui.inbuf) - 1; /* unnecessary, i think */
+ env->gui.inbuf[i] = '\0';
+ env->gui.inbuf_pos = i;
+}
+
/* accumulate digits, possibly call dial if in connected mode */
static void keypad_digit(struct video_desc *env, int digit)
{
@@ -2194,10 +2214,7 @@
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';
- }
+ append_char(env, digit);
}
}
@@ -2205,7 +2222,7 @@
static void keypad_send_command(struct video_desc *env, char *command)
{
ast_log(LOG_WARNING, "keypad_send_command(%s) called\n", command);
- ast_cli_command(env->outfd, command);
+ ast_cli_command(env->gui.outfd, command);
return;
}
@@ -2251,13 +2268,12 @@
o->cursound = -1;
o->nosound = 0;
ast_queue_frame(o->owner, &f);
- } else if (env->inbuf_pos) {
+ } else if (env->gui.inbuf_pos) {
/* we have someone to call */
- ast_cli_command(env->outfd, env->inbuf);
- }
-
- env->inbuf_pos = 0;
- env->inbuf[env->inbuf_pos] = '\0';
+ ast_cli_command(env->gui.outfd, env->gui.inbuf);
+ }
+
+ append_char(env, '\0'); /* clear buffer */
}
/* Print given text on the gui */
@@ -2274,7 +2290,7 @@
/* clean surface each rewrite */
SDL_BlitSurface(env->keypad, NULL, env->screen, &env->win[WIN_KEYPAD].rect);
- output = TTF_RenderText_Solid(env->font, text, color);
+ output = TTF_RenderText_Solid(env->gui.font, text, color);
if (output == NULL) {
ast_log(LOG_WARNING, "Cannot render text on gui - %s\n", TTF_GetError());
return 1;
@@ -2339,7 +2355,7 @@
else if (y > env->out.keypad_dpy.h)
index = KEY_OUT_OF_KEYPAD; /* click outside the keypad */
else
- index = map_click(env->keypad_bg, x - env->in.rem_dpy.w, y);
+ index = map_click(env->gui.keypad_bg, x - env->in.rem_dpy.w, y);
/* exec the function */
if (index < 128) {
@@ -2452,12 +2468,11 @@
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)
+ env->gui.keypad_bg = get_keypad(env->keypad_mask);
+ if (env->gui.keypad_bg == NULL)
return -1;
- env->inbuf_pos = 0;
- env->inbuf[env->inbuf_pos] = '\0';
+ append_char(env, '\0');
#ifdef HAVE_SDL_TTF
/* Initialize SDL_ttf library and load font */
@@ -2467,22 +2482,22 @@
}
#define GUI_FONTSIZE 28
- env->font = TTF_OpenFont( env->keypad_font, GUI_FONTSIZE);
- if (!env->font) {
+ env->gui.font = TTF_OpenFont( env->keypad_font, GUI_FONTSIZE);
+ if (!env->gui.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 ) {
+ env->gui.outfd = open ("/dev/null", O_WRONLY); /* discard output, temporary */
+ if ( env->gui.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);
+ env->gui.keypad_bg->w, env->gui.keypad_bg->h, env->gui.keypad_bg->pitch);
return 0;
}
@@ -2722,10 +2737,10 @@
goto no_sdl;
}
- env->keypad = get_keypad(env->keypad_file);
- if (env->keypad) {
- env->out.keypad_dpy.w = env->keypad->w;
- env->out.keypad_dpy.h = env->keypad->h;
+ 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;
}
maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + env->out.keypad_dpy.w;
@@ -2736,8 +2751,6 @@
goto no_sdl;
}
SDL_WM_SetCaption("Asterisk console Video Output", NULL);
- if (set_win(env->screen, &env->win[WIN_ALL], dpy_fmt,
- maxw, maxh, 0, 0))
if (set_win(env->screen, &env->win[WIN_REMOTE], dpy_fmt,
env->in.rem_dpy.w, env->in.rem_dpy.h, 0, 0))
goto no_sdl;
@@ -2745,15 +2758,15 @@
env->out.loc_dpy.w, env->out.loc_dpy.h, env->in.rem_dpy.w + env->out.keypad_dpy.w, 0))
goto no_sdl;
- if (env->keypad) {
+ if (env->gui.keypad) {
struct SDL_Rect dest;
dest.x = env->in.rem_dpy.w;
dest.y = 0;
- dest.w = env->keypad->w;
- dest.h = env->keypad->h;
+ dest.w = env->gui.keypad->w;
+ dest.h = env->gui.keypad->h;
env->win[WIN_KEYPAD].rect = dest;
- SDL_BlitSurface(env->keypad, NULL, env->screen, &dest);
+ SDL_BlitSurface(env->gui.keypad, NULL, env->screen, &dest);
SDL_UpdateRects(env->screen, 1, &dest);
}
ast_mutex_init(&env->in.dec_in_lock);
More information about the asterisk-commits
mailing list