[svn-commits] rizzo: branch rizzo/video_v2 r89181 - /team/rizzo/video_v2/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Nov 12 09:53:49 CST 2007


Author: rizzo
Date: Mon Nov 12 09:53:48 2007
New Revision: 89181

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89181
Log:
rearrange the code that handles display of images, to
make room for a keypad.


Modified:
    team/rizzo/video_v2/channels/console_video.c

Modified: team/rizzo/video_v2/channels/console_video.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/video_v2/channels/console_video.c?view=diff&rev=89181&r1=89180&r2=89181
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Mon Nov 12 09:53:48 2007
@@ -272,6 +272,16 @@
 	decoder_decode_f	dec_run;
 };
 
+/* 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 };
+
+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.
@@ -286,11 +296,10 @@
 	struct video_in_desc	in;		/* remote video descriptor */
 	struct video_out_desc	out;		/* local video descriptor */
 
-	SDL_Surface             *screen;
 	int                     sdl_ok;
 	ast_mutex_t		sdl_lock;
-	SDL_Overlay             *bmp[2];
-	SDL_Rect		rect[2];	/* loc. of images */
+	SDL_Surface             *screen;
+	struct display_window	win[WIN_MAX];
 };
 
 /*! The list of video formats we support. */
@@ -1804,6 +1813,21 @@
 	return 0;
 }
 
+static void cleanup_sdl(struct video_desc *env)  
+{
+	/* uninitialize the SDL environment */
+	int i;
+	for (i = 0; i < WIN_MAX; i++) {
+		if (env->win[i].bmp)
+			SDL_FreeYUVOverlay(env->win[i].bmp);
+	}
+	SDL_Quit();
+	env->screen = NULL; /* XXX check reference */
+	bzero(env->win, sizeof(env->win));
+	if (env->sdl_ok)
+		ast_mutex_destroy(&(env->sdl_lock));
+}
+
 /*! \brief uninitialize the entire environment. */
 static void console_video_uninit(struct video_desc *env)
 {
@@ -1826,19 +1850,9 @@
 	video_in_uninit(&env->in);
 	video_out_uninit(&env->out);
 
-	/* uninitialize the SDL environment */
-	if (env->sdl_ok) {
-		if (env->bmp[0])
-			SDL_FreeYUVOverlay(env->bmp[0]);
-		if (env->bmp[1])
-			SDL_FreeYUVOverlay(env->bmp[1]);
-		SDL_Quit();
-		env->bmp[0] = env->bmp[1] = NULL;
-		env->screen = NULL; /* XXX check reference */
-		bzero(env->rect, sizeof(env->rect));
-		ast_mutex_destroy(&(env->sdl_lock));
-		
-	}
+	if (env->sdl_ok)
+		cleanup_sdl(env);
+
 	env->owner = NULL;
 }
 
@@ -1941,7 +1955,7 @@
 	if (!env->sdl_ok)
 		return;
 
-	if (out) {	/* webcam/x11 to sdl */
+	if (out == WIN_LOCAL) {	/* webcam/x11 to sdl */
 		b_in = &env->out.enc_in;
 		b_out = &env->out.loc_dpy;
 		p_in = NULL;
@@ -1956,7 +1970,7 @@
 		b_out = &env->in.rem_dpy;
 		p_in = (AVPicture *)env->in.d_frame;
 	}
-	bmp = env->bmp[out];
+	bmp = env->win[out].bmp;
 	SDL_LockYUVOverlay(bmp);
 	/* output picture info - this is sdl, YUV420P */
 	bzero(&p_out, sizeof(p_out));
@@ -1971,7 +1985,7 @@
 
 	/* lock to protect access to Xlib by different threads. */
 	ast_mutex_lock(&env->sdl_lock);
-	SDL_DisplayYUVOverlay(bmp, &env->rect[out]);
+	SDL_DisplayYUVOverlay(bmp, &env->win[out].rect);
 	ast_mutex_unlock(&env->sdl_lock);
 	SDL_UnlockYUVOverlay(bmp);
 }
@@ -2059,7 +2073,7 @@
 	}
 	if (f->subclass & 0x01) {	// RTP Marker
 		if (v->dec->dec_run(v, &v->dec_in))
-			show_frame(env, 0);
+			show_frame(env, WIN_REMOTE);
 	}
 	return 0;
 }
@@ -2092,7 +2106,7 @@
 	 * so we will see the same as the remote party.
 	 */
 	my_scale(&v->loc_src, NULL, &v->enc_in, NULL);
-	show_frame(env, 1);
+	show_frame(env, WIN_LOCAL);
 	if (!v->sendvideo)
 		return NULL;
 	if (v->enc_out.data == NULL) {
@@ -2226,6 +2240,20 @@
 	copy_geometry(rd, ld);	/* local display inherits from remote display */
 }
 
+/* setup an sdl overlay and associated info, return 0 on success, != 0 on error */
+static int set_win(SDL_Surface *screen, struct display_window *win, int fmt,
+	int w, int h, int x, int y)
+{
+	win->bmp = SDL_CreateYUVOverlay(w, h, fmt, screen);
+	if (win->bmp == NULL)
+		return -1;	/* error */
+	win->rect.x = x;
+	win->rect.y = y;
+	win->rect.w = w;
+	win->rect.h = h;
+	return 0;
+}
+
 /*!
  * The first call to the video code, called by oss_new() or similar.
  * Here we initialize the various components we use, namely SDL for display,
@@ -2237,8 +2265,7 @@
 	struct ast_channel *owner)
 {
 	int dpy_fmt = SDL_IYUV_OVERLAY;	/* YV12 causes flicker in SDL */
-	struct fbuf_t *b;
-	int h;
+	int maxw, maxh;
 
 	if (env == NULL)	/* video not initialized */
 		return;
@@ -2260,12 +2287,17 @@
 	av_log_set_level(AV_LOG_ERROR);	/* only report errors */
 
 	/*
-	 * initialize the SDL environment
+	 * initialize the SDL environment. We have one large window
+	 * with local and remote video, and a keypad.
+	 * At the moment we arrange them statically, as follows:
+	 * - on the left, the remote video;
+	 * - on the center, the keypad
+	 * - on the right, the local video
 	 */
 	ast_log(LOG_WARNING, "prepare SDL initialization\n");
 
 	env->screen = NULL;
-	env->bmp[0] = env->bmp[1] = NULL;
+	bzero(env->win, sizeof(env->win));
 
 	if (SDL_Init(SDL_INIT_VIDEO)) {
 		ast_log(LOG_WARNING, "Could not initialize SDL - %s\n",
@@ -2273,35 +2305,30 @@
 		/* again not fatal, just we won't display anything */
 		goto no_sdl;
 	}
-	h =  MAX(env->in.rem_dpy.h, env->out.loc_dpy.h);
-	env->screen = SDL_SetVideoMode(env->in.rem_dpy.w + env->out.loc_dpy.w,
-		h, 0, 0);
+	maxw = env->in.rem_dpy.w + env->out.loc_dpy.w + 200;
+	maxh = MAX( MAX(env->in.rem_dpy.h, env->out.loc_dpy.h), 200);
+	env->screen = SDL_SetVideoMode(maxw, maxh, 0, 0);
 	if (!env->screen) {
 		ast_log(LOG_ERROR, "SDL: could not set video mode - exiting\n");
 		goto no_sdl;
 	}
 	SDL_WM_SetCaption("Asterisk console Video Output", NULL);
-	b = &env->in.rem_dpy;
-	env->bmp[0] = SDL_CreateYUVOverlay(b->w, b->h, dpy_fmt, env->screen);
-	b = &env->out.loc_dpy;
-	env->bmp[1] = SDL_CreateYUVOverlay(b->w, b->h, dpy_fmt, env->screen);
-	if (env->bmp[0] == NULL || env->bmp[1] == NULL) {
-		/* otherwise should release the screen */
+	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;
-	}
+	if (set_win(env->screen, &env->win[WIN_KEYPAD], dpy_fmt,
+			200, 200, env->in.rem_dpy.w, 0))
+		goto no_sdl;
+	/* XXX later we redefine local ? */
+	if (set_win(env->screen, &env->win[WIN_LOCAL], dpy_fmt,
+			env->out.loc_dpy.w, env->out.loc_dpy.h, env->in.rem_dpy.w + 200, 0))
+		goto no_sdl;
 	ast_mutex_init(&env->sdl_lock);
-	/* position of video windows on the output */
-	env->rect[0].x = 0;
-	env->rect[0].y = 0;
-	env->rect[0].w = env->in.rem_dpy.w;
-	env->rect[0].h = env->in.rem_dpy.h;
-	env->rect[1].x = env->in.rem_dpy.w;
-	env->rect[1].y = 0;
-	env->rect[1].w = env->out.loc_dpy.w;
-	env->rect[1].h = env->out.loc_dpy.h;
 	env->sdl_ok = 1;
 
 no_sdl:
+	if (env->sdl_ok == 0)	/* free resources in case of errors */
+		cleanup_sdl(env);
 	/*
 	 * now handle the local video source
 	 */




More information about the svn-commits mailing list