1. pygame
  2. Untitled project
  3. pygame

Commits

zeroth  committed a9d93ed

Fixed up some play/stop/pause issues, used better thread primitives in
several functions, fixed a few deadlocks. Discovered for updating the
display, I need to let the GIL loose with a call to time.sleep before
updating, else we get a deadlock.

  • Participants
  • Parent commits 2031a59
  • Branches tylerthemovie

Comments (0)

Files changed (3)

File movie_test.py

View file
 # time.
 
 counter = 0
-actions = {5: lambda x: x.pause(), 10: lambda x: x.pause(), 15: lambda x: x.resize(x.width/2, x.height/2), 20:lambda x: x.stop(), 22: lambda x: x.play(-1)}
+actions = {1: lambda x: x.paused, 5: lambda x: x.pause(), 10: lambda x: x.pause(), 15: lambda x: x.resize(x.width/2, x.height/2), 20:lambda x: x.stop(), 22: lambda x: x.play(-1)}
 prev_time = time.time()
 m.surface = screen
 print "About to do surface gymnastics..."
         actions[counter](m)
         counter +=1
     #print "updating"
-    pygame.display.update() #we can do this because we're blitting each frame of the movie to the main screen we instantiated.
+    time.sleep(0.1) #we need to let go of the gil occassionally...
+    if(not screen.get_locked()):
+        pygame.display.update() #we can do this because we're blitting each frame of the movie to the main screen we instantiated.
     
 m.stop()
 del m

File src/_gmovie.c

View file
     movie->subpq_mutex = SDL_CreateMutex();
     //movie->subpq_cond = SDL_CreateCond();
     
-    movie->paused = 1;
+    //movie->paused = 1;
     //in case we've called stream open once before...
     movie->abort_request = 0;
     movie->av_sync_type = AV_SYNC_VIDEO_MASTER;

File src/gmovie.c

View file
 PyObject* _movie_play(PyMovie *movie, PyObject* args)
 {
 	PyEval_InitThreads();
-	PyInterpreterState *interp;
-	PyThreadState *thread;
-	thread=PyThreadState_Get();
-	interp = thread->interp;
-	movie->_tstate = PyThreadState_New(interp);
+	if(movie->playing)
+	{
+		if(movie->paused)
+		{
+			//if we've called this after we paused n times where n is odd, then we unpause the movie
+			_movie_pause(movie);
+		}
+		//indicating we've called play again before its finished		
+	}
+	else
+	{
+		PyInterpreterState *interp;
+		PyThreadState *thread;
+		thread=PyThreadState_Get();
+		interp = thread->interp;
+		movie->_tstate = PyThreadState_New(interp);
+	}
 	Py_INCREF(movie);
     //PySys_WriteStdout("Inside .play\n");
     int loops;