[asterisk-commits] rizzo: branch rizzo/video_v2 r89188 - /team/rizzo/video_v2/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Nov 12 13:52:55 CST 2007


Author: rizzo
Date: Mon Nov 12 13:52:54 2007
New Revision: 89188

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89188
Log:
rearrange code a bit while trying to debug event handling.
The goal is to do all sdl-related action in a single thread,
to avoid possible deadlocks etc.


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=89188&r1=89187&r2=89188
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Mon Nov 12 13:52:54 2007
@@ -1998,7 +1998,6 @@
 	my_scale(b_in, p_in, b_out, &p_out);
 
 	/* lock to protect access to Xlib by different threads. */
-	SDL_UpdateRects(env->screen, 1, &env->win[WIN_KEYPAD].rect);// XXX inefficient
 	SDL_DisplayYUVOverlay(bmp, &env->win[out].rect);
 	SDL_UnlockYUVOverlay(bmp);
 }
@@ -2144,18 +2143,27 @@
 	return v->enc->enc_encap(v, tail);
 }
 
+/* grab a bunch of events */
 static void eventhandler(struct video_desc *env)
 {
-	SDL_Event event;
+#define N_EVENTS	32
+	int i, n;
+	SDL_Event ev[N_EVENTS];
+
 	return;
 
-	if (!SDL_PollEvent(&event)) {
-		fprintf(stderr, "-- no event\n");
-	} else {
-		fprintf(stderr, "-- event %d at %d %d\n",
-			event.type, event.button.x, event.button.y);
-	}
-}
+	while ( (n = SDL_PeepEvents(ev, N_EVENTS, SDL_GETEVENT, SDL_ALLEVENTS)) > 0) {
+		for (i = 0; i < n; i++) {
+			ast_log(LOG_WARNING, "-- event %d at %d %d\n",
+			 ev[i].type,  ev[i].button.x,  ev[i].button.y);
+		}
+	}
+	ast_log(LOG_WARNING, "-- no event, n %d\n", n);
+	SDL_PumpEvents();
+}
+
+static void sdl_setup(struct video_desc *env);
+
 /*
  * Helper thread to periodically poll the video source and enqueue the
  * generated frames to the channel's queue.
@@ -2167,6 +2175,7 @@
 	struct video_desc *env = arg;
 	int count = 0;
 
+	sdl_setup(env);
 	if (video_open(&env->out)) {
 		ast_log(LOG_WARNING, "cannot open local video source\n");
 	} else {
@@ -2182,7 +2191,6 @@
 		struct timeval t = { 0, 50000 };
 		struct ast_frame *p, *f;
 		struct video_in_desc *v = &env->in;
-
 		struct ast_channel *chan = env->owner;
 		int fd = chan->alertpipe[1];
 
@@ -2205,6 +2213,7 @@
 		/* sleep for a while */
 		ast_select(0, NULL, NULL, NULL, &t);
 
+		SDL_UpdateRects(env->screen, 1, &env->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.
@@ -2234,16 +2243,8 @@
 			continue;
 		chan = env->owner;
 		ast_channel_lock(chan);
-#if 0 /* loop back */
-		for (p = f; p; p = AST_LIST_NEXT(p, frame_list)) {
-			static uint16_t seqno = 10;
-			p->seqno = seqno++;
-			console_write_video(chan, p);
-		}
-		ast_frfree(f);
-#else
-			
-		/* AST_LIST_INSERT_TAIL is only good for one frame, cannot use */
+
+		/* AST_LIST_INSERT_TAIL is only good for one frame, cannot use here */
 		if (chan->readq.first == NULL) {
 			chan->readq.first = f;
 		} else {
@@ -2254,7 +2255,6 @@
 		 * more or less same as ast_queue_frame, but extra
 		 * write on the alertpipe to signal frames.
 		 */
-
 		if (fd > -1) {
 			int blah = 1, l = sizeof(blah);
 			for (p = f; p; p = AST_LIST_NEXT(p, frame_list)) {
@@ -2263,7 +2263,6 @@
 					    chan->name, f->frametype, f->subclass, strerror(errno));
 			}
 		}
-#endif
 		ast_channel_unlock(chan);
 	}
 	/* thread terminating, here could call the uninit */
@@ -2300,7 +2299,6 @@
 	copy_geometry(ei, c);	/* camera inherits from encoder input */
 	copy_geometry(ei, rd);	/* remote display inherits from encoder input */
 	copy_geometry(rd, ld);	/* local display inherits from remote display */
-	copy_geometry(rd, &env->out.keypad_dpy);	/* keypad inherits from remote display */
 }
 
 /* setup an sdl overlay and associated info, return 0 on success, != 0 on error */
@@ -2319,19 +2317,19 @@
 
 static SDL_Surface *get_keypad(struct video_desc *env)
 {
-	//SDL_Surface *image;
 	SDL_Surface *temp;
  
-	//temp = SDL_LoadBMP("/tmp/layer0.bmp");
+#if 0 /* if you don't have libSDL_image... */
+	temp = SDL_LoadBMP(env->keypad_file);
+#else
 	temp = IMG_Load(env->keypad_file);
+#endif
 	if (temp == NULL) {
-		fprintf(stderr, "Unable to load bitmap: %s\n", SDL_GetError());
+		fprintf(stderr, "Unable to load image %s: %s\n",
+			env->keypad_file, SDL_GetError());
 		return NULL;
 	}
 	return temp;
-	//image = SDL_DisplayFormat(temp);
-	//SDL_FreeSurface(temp);
-	//return image;
 }
 
 /*!
@@ -2344,10 +2342,6 @@
 static void console_video_start(struct video_desc *env,
 	struct ast_channel *owner)
 {
-	int dpy_fmt = SDL_IYUV_OVERLAY;	/* YV12 causes flicker in SDL */
-	int maxw, maxh;
-	SDL_Surface *keypad;
-
 	if (env == NULL)	/* video not initialized */
 		return;
 	if (owner == NULL)	/* nothing to do if we don't have a channel */
@@ -2367,6 +2361,24 @@
 	avcodec_register_all();
 	av_log_set_level(AV_LOG_ERROR);	/* only report errors */
 
+	if (env->out.fps == 0) {
+		env->out.fps = 15;
+		ast_log(LOG_WARNING, "fps unset, forcing to %d\n", env->out.fps);
+	}
+	if (env->out.bitrate == 0) {
+		env->out.bitrate = 65000;
+		ast_log(LOG_WARNING, "bitrate unset, forcing to %d\n", env->out.bitrate);
+	}
+
+	ast_pthread_create_background(&env->vthread, NULL, video_thread, env);
+}
+
+static void sdl_setup(struct video_desc *env)
+{
+	int dpy_fmt = SDL_IYUV_OVERLAY;	/* YV12 causes flicker in SDL */
+	int maxw, maxh;
+	SDL_Surface *keypad;
+
 	/*
 	 * initialize the SDL environment. We have one large window
 	 * with local and remote video, and a keypad.
@@ -2407,7 +2419,7 @@
 	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 + env->out.keypad_dpy.w, 0))
 		goto no_sdl;
-#if 1
+
 	if (keypad) { struct SDL_Rect dest;
 		dest.x = env->in.rem_dpy.w;
 		dest.y = 0;
@@ -2418,11 +2430,6 @@
 		SDL_BlitSurface(keypad, NULL, env->screen, &dest);
 		SDL_UpdateRects(env->screen, 1, &dest);
 	}
-#else
-	if (set_win(env->screen, &env->win[WIN_KEYPAD], dpy_fmt,
-			env->out.keypad_dpy.w, env->out.keypad_dpy.h, env->in.rem_dpy.w, 0))
-		goto no_sdl;
-#endif
 
 	ast_mutex_init(&env->in.dec_in_lock);
 	env->in.dec_in_cur = &env->in.dec_in[0];
@@ -2432,20 +2439,7 @@
 no_sdl:
 	if (env->sdl_ok == 0)	/* free resources in case of errors */
 		cleanup_sdl(env);
-	/*
-	 * now handle the local video source
-	 */
-	/* copy video source config from parent */
-	if (env->out.fps == 0) {
-		env->out.fps = 15;
-		ast_log(LOG_WARNING, "fps unset, forcing to %d\n", env->out.fps);
-	}
-	if (env->out.bitrate == 0) {
-		env->out.bitrate = 65000;
-		ast_log(LOG_WARNING, "bitrate unset, forcing to %d\n", env->out.bitrate);
-	}
-
-	ast_pthread_create_background(&env->vthread, NULL, video_thread, env);
+
 }
 
 /* see chan_oss.c for these macros */
@@ -2553,7 +2547,6 @@
         M_F("camera_size", video_geom(&env->out.loc_src, val))
         M_F("local_size", video_geom(&env->out.loc_dpy, val))
         M_F("remote_size", video_geom(&env->in.rem_dpy, val))
-        M_F("keypad_size", video_geom(&env->out.keypad_dpy, val))
         M_STR("keypad", env->keypad_file)
         M_UINT("fps", env->out.fps)
         M_UINT("bitrate", env->out.bitrate)




More information about the asterisk-commits mailing list