diff --git a/channels/console_gui.c b/channels/console_gui.c index e25a52c3d908de8fe14a51ba160052ef5da5f69a..d13ab42ef9ea43f45f7da3c23d14a29f344db9bf 100644 --- a/channels/console_gui.c +++ b/channels/console_gui.c @@ -18,6 +18,17 @@ struct keypad_entry { enum kp_type type; }; +/* 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_MAX }; +/* our representation of a displayed window. SDL can only do one main + * window so we map everything within that one + */ +struct display_window { + SDL_Overlay *bmp; + SDL_Rect rect; /* location of the window */ +}; #define GUI_BUFFER_LEN 256 /* buffer lenght used for input buffers */ struct keypad_entry; /* defined in console_gui.c */ @@ -39,6 +50,8 @@ struct gui_info { SDL_Surface *keypad; /* the pixmap for the keypad */ int kp_size, kp_used; struct keypad_entry *kp; + + struct display_window win[WIN_MAX]; }; static void cleanup_sdl(struct video_desc *env) @@ -61,19 +74,19 @@ static void cleanup_sdl(struct video_desc *env) if (gui->keypad) SDL_FreeSurface(gui->keypad); gui->keypad = NULL; - /* XXX free the keys entries */ - ast_free(gui); - env->gui = NULL; - } /* uninitialize the SDL environment */ for (i = 0; i < WIN_MAX; i++) { - if (env->win[i].bmp) - SDL_FreeYUVOverlay(env->win[i].bmp); + if (gui->win[i].bmp) + SDL_FreeYUVOverlay(gui->win[i].bmp); } + bzero(gui->win, sizeof(gui->win)); + /* XXX free the keys entries */ + ast_free(gui); + env->gui = NULL; + } SDL_Quit(); env->screen = NULL; /* XXX check reference */ - bzero(env->win, sizeof(env->win)); if (env->sdl_ok) ast_mutex_destroy(&(env->in.dec_in_lock)); } @@ -93,6 +106,7 @@ static void show_frame(struct video_desc *env, int out) AVPicture *p_in, p_out; struct fbuf_t *b_in, *b_out; SDL_Overlay *bmp; + struct gui_info *gui = env->gui; if (!env->sdl_ok) return; @@ -112,7 +126,7 @@ static void show_frame(struct video_desc *env, int out) b_out = &env->in.rem_dpy; p_in = (AVPicture *)env->in.d_frame; } - bmp = env->win[out].bmp; + bmp = gui->win[out].bmp; SDL_LockYUVOverlay(bmp); /* output picture info - this is sdl, YUV420P */ bzero(&p_out, sizeof(p_out)); @@ -126,7 +140,7 @@ static void show_frame(struct video_desc *env, int out) my_scale(b_in, p_in, b_out, &p_out); /* lock to protect access to Xlib by different threads. */ - SDL_DisplayYUVOverlay(bmp, &env->win[out].rect); + SDL_DisplayYUVOverlay(bmp, &gui->win[out].rect); SDL_UnlockYUVOverlay(bmp); } @@ -311,11 +325,11 @@ static int gui_output(struct video_desc *env, const char *text) int x = 30, y = 20; /* XXX change */ SDL_Surface *output = NULL; SDL_Color color = {0, 0, 0}; /* text color */ - SDL_Rect dest = {env->win[WIN_KEYPAD].rect.x + x, y}; struct gui_info *gui = env->gui; + SDL_Rect dest = {gui->win[WIN_KEYPAD].rect.x + x, y}; /* clean surface each rewrite */ - SDL_BlitSurface(gui->keypad, NULL, env->screen, &env->win[WIN_KEYPAD].rect); + SDL_BlitSurface(gui->keypad, NULL, env->screen, &gui->win[WIN_KEYPAD].rect); output = TTF_RenderText_Solid(gui->font, text, color); if (output == NULL) { @@ -325,7 +339,7 @@ static int gui_output(struct video_desc *env, const char *text) SDL_BlitSurface(output, NULL, env->screen, &dest); - SDL_UpdateRects(gui->keypad, 1, &env->win[WIN_KEYPAD].rect); + SDL_UpdateRects(gui->keypad, 1, &gui->win[WIN_KEYPAD].rect); SDL_FreeSurface(output); return 0; /* success */ #endif @@ -356,9 +370,9 @@ static void handle_button_event(struct video_desc *env, SDL_MouseButtonEvent but /* define keypad boundary */ if (button.x < env->in.rem_dpy.w) index = KEY_REM_DPY; /* click on remote video */ - else if (button.x > env->in.rem_dpy.w + env->out.keypad_dpy.w) + else if (button.x > env->in.rem_dpy.w + env->gui->keypad->w) index = KEY_LOC_DPY; /* click on local video */ - else if (button.y > env->out.keypad_dpy.h) + else if (button.y > env->gui->keypad->h) index = KEY_OUT_OF_KEYPAD; /* click outside the keypad */ else if (env->gui->kp) { int i; @@ -653,8 +667,6 @@ static void keypad_setup(struct video_desc *env) if (!env->gui->keypad) return; - env->out.keypad_dpy.w = env->gui->keypad->w; - env->out.keypad_dpy.h = env->gui->keypad->h; /* * If the keypad image has a comment field, try to read * the button location from there. The block must be @@ -729,6 +741,7 @@ static void sdl_setup(struct video_desc *env) int dpy_fmt = SDL_IYUV_OVERLAY; /* YV12 causes flicker in SDL */ int depth, maxw, maxh; const SDL_VideoInfo *info = SDL_GetVideoInfo(); + int kp_w = 0, kp_h = 0; /* keypad width and height */ /* We want at least 16bpp to support YUV overlays. * E.g with SDL_VIDEODRIVER = aalib the default is 8 @@ -753,10 +766,14 @@ static void sdl_setup(struct video_desc *env) keypad_setup(env); ast_log(LOG_WARNING, "keypad_setup returned %p %d\n", env->gui->keypad, env->gui->kp_used); + if (env->gui->keypad) { + kp_w = env->gui->keypad->w; + kp_h = env->gui->keypad->h; + } } #define BORDER 5 /* border around our windows */ - maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + env->out.keypad_dpy.w; - maxh = MAX( MAX(env->in.rem_dpy.h, env->out.loc_dpy.h), env->out.keypad_dpy.h); + maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + kp_w; + maxh = MAX( MAX(env->in.rem_dpy.h, env->out.loc_dpy.h), kp_h); maxw += 4 * BORDER; maxh += 2 * BORDER; env->screen = SDL_SetVideoMode(maxw, maxh, depth, 0); @@ -766,19 +783,19 @@ static void sdl_setup(struct video_desc *env) } SDL_WM_SetCaption("Asterisk console Video Output", NULL); - if (set_win(env->screen, &env->win[WIN_REMOTE], dpy_fmt, + if (set_win(env->screen, &env->gui->win[WIN_REMOTE], dpy_fmt, env->in.rem_dpy.w, env->in.rem_dpy.h, BORDER, BORDER)) goto no_sdl; - if (set_win(env->screen, &env->win[WIN_LOCAL], dpy_fmt, + if (set_win(env->screen, &env->gui->win[WIN_LOCAL], dpy_fmt, env->out.loc_dpy.w, env->out.loc_dpy.h, - 3*BORDER+env->in.rem_dpy.w + env->out.keypad_dpy.w, BORDER)) + 3*BORDER+env->in.rem_dpy.w + kp_w, BORDER)) goto no_sdl; /* display the skin, but do not free it as we need it later to * restore text areas and maybe sliders too. */ if (env->gui && env->gui->keypad) { - struct SDL_Rect *dest = &env->win[WIN_KEYPAD].rect; + struct SDL_Rect *dest = &env->gui->win[WIN_KEYPAD].rect; dest->x = 2*BORDER + env->in.rem_dpy.w; dest->y = BORDER; dest->w = env->gui->keypad->w; diff --git a/channels/console_video.c b/channels/console_video.c index 9284da9994d15aef22e4189efec8d46afe7c810d..857cfc6e5e9dec720b41971e6beb01026ea1df6e 100644 --- a/channels/console_video.c +++ b/channels/console_video.c @@ -196,7 +196,6 @@ struct video_out_desc { struct fbuf_t enc_in; /* encoder input buffer, allocated in video_out_init() */ struct fbuf_t enc_out; /* encoder output buffer, allocated in video_out_init() */ struct fbuf_t loc_dpy; /* display source buffer, no buffer (managed by SDL in bmp[1]) */ - struct fbuf_t keypad_dpy; /* keypad source buffer, XXX */ struct video_codec_desc *enc; /* encoder */ void *enc_ctx; /* encoding context */ @@ -273,7 +272,6 @@ struct video_desc { char keypad_font[256]; /* font for the keypad */ char sdl_videodriver[256]; - struct display_window win[WIN_MAX]; }; static AVPicture *fill_pict(struct fbuf_t *b, AVPicture *p); @@ -1086,7 +1084,6 @@ static void *video_thread(void *arg) char save_display[128] = ""; env->screen = NULL; - bzero(env->win, sizeof(env->win)); /* if sdl_videodriver is set, override the environment. Also, * if it contains 'console' override DISPLAY around the call to SDL_Init @@ -1153,7 +1150,8 @@ static void *video_thread(void *arg) /* sleep for a while */ ast_select(0, NULL, NULL, NULL, &t); - SDL_UpdateRects(env->screen, 1, &env->win[WIN_KEYPAD].rect);// XXX inefficient + if (env->gui) + SDL_UpdateRects(env->screen, 1, &env->gui->win[WIN_KEYPAD].rect);// XXX inefficient /* * While there is something to display, call the decoder and free * the buffer, possibly enabling the receiver to store new data. diff --git a/channels/console_video.h b/channels/console_video.h index 312bfe2e095e965930a6b46a12df1bb8cf8db4ae..330e179ba2d74060ae72a81dc19c20f9147be1ec 100644 --- a/channels/console_video.h +++ b/channels/console_video.h @@ -45,17 +45,6 @@ #include <SDL/SDL_ttf.h> /* render text on sdl surfaces */ #endif -/* 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_MAX }; -/* our representation of a displayed window. SDL can only do one main - * window so we map everything within that one - */ -struct display_window { - SDL_Overlay *bmp; - SDL_Rect rect; /* location of the window */ -}; #define CONSOLE_VIDEO_CMDS \