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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Nov 14 02:32:26 CST 2007


Author: rizzo
Date: Wed Nov 14 02:32:26 2007
New Revision: 89267

URL: http://svn.digium.com/view/asterisk?view=rev&rev=89267
Log:
give some time to the video_thread to terminate
before the channel is destroyed.
The real solution is moving ast_channel to astobj2 so
we have reference counts that protect us from these issues.


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=89267&r1=89266&r2=89267
==============================================================================
--- team/rizzo/video_v2/channels/console_video.c (original)
+++ team/rizzo/video_v2/channels/console_video.c Wed Nov 14 02:32:26 2007
@@ -1845,12 +1845,25 @@
 		ast_mutex_destroy(&(env->in.dec_in_lock));
 }
 
-/*! \brief uninitialize the entire environment. */
+/*! \brief uninitialize the entire environment.
+ * In practice, signal the thread and give it a bit of time to
+ * complete, giving up if it gets stuck. Because uninit
+ * is called from hangup with the channel locked, and the thread
+ * uses the chan lock, we need to unlock here. This is unsafe,
+ * and we should really use refcounts for the channels.
+ */
 static void console_video_uninit(struct video_desc *env)
 {
+	int i, t = 100;	/* initial wait is shorter, than make it longer */
 	env->shutdown = 1;
-}
-
+	for (i=0; env->shutdown && i < 10; i++) {
+                ast_channel_unlock(env->owner);
+                usleep(t);
+		t = 1000000;
+                ast_channel_lock(env->owner);
+        }
+	env->owner = NULL;
+}
 
 /*! fill an AVPicture from our fbuf info, as it is required by
  * the image conversion routines in ffmpeg.
@@ -2126,8 +2139,8 @@
 /*
  * I am seeing some kind of deadlock or stall around
  * SDL_PumpEvents() while moving the window on a remote X server
- * (Xfree86-4.4.0), but it is unclear what causes it.
- * Could well be a problem on the X server I am using.
+ * (both xfree-4.4.0 and xorg 7.2)
+ * and windowmaker. It is unclear what causes it.
  */
 
 /* grab a bunch of events */
@@ -2138,21 +2151,21 @@
 	SDL_Event ev[N_EVENTS];
 
 #define MY_EV (SDL_MOUSEBUTTONDOWN|SDL_KEYDOWN)
-	while ( (n = SDL_PeepEvents(ev, N_EVENTS, SDL_GETEVENT, MY_EV)) > 0) {
+	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",
+			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);
-	if (0) {
-		struct timeval a = ast_tvnow();
+	if (1) {
+		struct timeval b, a = ast_tvnow();
+		int i;
 		//SDL_Lock_EventThread();
-		a = ast_tvnow();
-		fprintf(stderr, "before Pump at %ld.%06lu\n", a.tv_sec, a.tv_usec);
 		SDL_PumpEvents();
-		a = ast_tvnow();
-		fprintf(stderr, "after Pump at %ld.%06lu\n", a.tv_sec, a.tv_usec);
+		b = ast_tvnow();
+		i = ast_tvdiff_ms(b, a);
+		if (i > 3)
+			fprintf(stderr, "-------- SDL_PumpEvents took %dms\n", i);
 		//SDL_Unlock_EventThread();
 	}
 }
@@ -2189,10 +2202,6 @@
 		struct ast_channel *chan = env->owner;
 		int fd = chan->alertpipe[1];
 
-		if (env->shutdown) {
-			ast_log(LOG_WARNING, "video_thread shutting down\n");
-			break;
-		}
 		/* determine if video format changed */
 		if (count++ % 10 == 0) {
 			char buf[160];
@@ -2207,10 +2216,7 @@
 		}
 		eventhandler(env);
 		/* sleep for a while */
-		if (1)
-			SDL_Delay(50);
-		else
-			ast_select(0, NULL, NULL, NULL, &t);
+		ast_select(0, NULL, NULL, NULL, &t);
 
 		SDL_UpdateRects(env->screen, 1, &env->win[WIN_KEYPAD].rect);// XXX inefficient
 		/*
@@ -2239,6 +2245,8 @@
 		f = get_video_frames(env, &p);	/* read and display */
 		if (!f)
 			continue;
+		if (env->shutdown)
+			break;
 		chan = env->owner;
 		ast_channel_lock(chan);
 
@@ -2271,7 +2279,6 @@
 	if (env->sdl_ok)
 		cleanup_sdl(env);
 
-	env->owner = NULL;
 	env->shutdown = 0;
 	return NULL;
 }




More information about the asterisk-commits mailing list