Commits

Anonymous committed 9c90743

Fixed overlay release and surface resizing bug. Surface however remains
corrupted. Need to test changes with full test...

Comments (0)

Files changed (2)

 
 m.play(-1)       #We're going to use infinite play, so we can demonstrate all 
                 # the features.
-time.sleep(10)  #sleep for ten seconds to let one see the video play, and hear 
+time.sleep(2)  #sleep for ten seconds to let one see the video play, and hear 
                 # the audio
 print m.paused
 print m.playing
 print m
 
-m.pause()
-time.sleep(4)
-m.pause()
-time.sleep(4)
-m.pause()
-time.sleep(4)
-m.pause()
-
 #Now we're going to play with the size of the window, affecting the video on 
 # the fly. resize(width, height) is the main function, changes them both at
 # the same time.
-print "Resizing..."
-m.resize(m.width/2, m.height*2)
-print "sleeping..."
-time.sleep(10) #another ten second nap.
-print "Resizing again..."
-m.width = m.width*4
-print "sleeping again" 
-time.sleep(10)
-print "Back to normal!"
-m.width=m.width/2
-m.height = m.height/2
-print "and again, sleeping..."
-#back to our original size
-time.sleep(10)
-#Here we demonstrate the use of pause. You pause, then call pause again to play
-print "Pausing..."
-m.pause()
-print "done pausing..."
-print m.paused
-print m.playing
-time.sleep(10)
-print "Unpausing..."
-m.pause()
-print m.paused
-print m.playing
-time.sleep(20)
+##print "Resizing..."
+##m.resize(m.width/2, m.height*2)
+##print "sleeping..."
+##time.sleep(10) #another ten second nap.
+##print "Resizing again..."
+##m.width = m.width*4
+##print "sleeping again" 
+##time.sleep(10)
+##print "Back to normal!"
+##m.width=m.width/2
+##m.height = m.height/2
+##print "and again, sleeping..."
+###back to our original size
+##time.sleep(10)
+###Here we demonstrate the use of pause. You pause, then call pause again to play
+##print "Pausing..."
+##m.pause()
+##print "done pausing..."
+##print m.paused
+##print m.playing
+##time.sleep(10)
+##print "Unpausing..."
+##m.pause()
+##print m.paused
+##print m.playing
+##time.sleep(20)
 #Here is the stop function. Right now, rewind is the exact same as stop.
-print "Stopping..., sleeping for 3 seconds"
-m.stop()
-time.sleep(3)
-#And now we restart playing.
-print "Playing again..." 
-m.play(-1)
-print "done restart play..."
-time.sleep(10)
+##print "Stopping..., sleeping for 3 seconds"
+##m.stop()
+##time.sleep(3)
+###And now we restart playing.
+##print "Playing again..." 
+##m.play(-1)
+##print "done restart play..."
+##time.sleep(10)
 print "Surface time..."
 screen = pygame.display.set_mode((m.width, m.height))
 #This will move the movie player from overlay mode to blitting to the surface 
 # time.
 
 counter = 0
-actions = {1: lambda x: x.paused, 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..."
-##while(1):
-##    new_time=time.time()
-##    diff = int(new_time-prev_time)
-##    if(diff>=1):
-##        counter+=1
-##        print counter
-##        prev_time=new_time
-##    #print "testing counter"
-##    if counter==30:
-##        #print "breaking"
-##        break
-##    #print "has_key"
-##    if actions.has_key(counter):
-##        print "Performing action at counter value: %d" % counter
-##        actions[counter](m)
-##        counter +=1
-##    #print "updating"
-##    time.sleep(0.1) #we need to let go of the gil occassionally...
-##    if(not screen.get_locked()):
-##        try:
-##            pygame.display.update() #we can do this because we're blitting each frame of the movie to the main screen we instantiated.
-##        except pygame.error:
-##            break
-##        
-##print "Ending trial one..."
+actions = {1: lambda x: x.paused, 6: lambda x:x.pause(), 11: lambda x:x.pause(), 15: lambda x: x.resize(x.width/2, x.height/2), 2000:lambda x: x.stop(), 3000: lambda x: x.play(-1)}
+prev_time = time.time()
+m.surface = screen
+print "About to do surface gymnastics..."
+while(1):
+    new_time=time.time()
+    diff = int(new_time-prev_time)
+    if(diff>=1):
+        counter+=1
+        print counter
+        prev_time=new_time
+    #print "testing counter"
+    if counter==3100:
+        #print "breaking"
+        break
+    #print "has_key"
+    if actions.has_key(counter):
+        print "Performing action at counter value: %d" % counter
+        actions[counter](m)
+        counter +=1
+    #print "updating"
+    time.sleep(0.1) #we need to let go of the gil occassionally...
+    if(not screen.get_locked()):
+        try:
+            pygame.display.update() #we can do this because we're blitting each frame of the movie to the main screen we instantiated.
+        except pygame.error:
+            break
+        
+print "Ending trial one..."
 m.stop()
 del m
 #the end
         {
             SDL_FreeYUVOverlay(vp->dest_overlay);
         }
-        //now we have to open an overlay up
-        SDL_Surface *screen;
-        if (!SDL_WasInit (SDL_INIT_VIDEO))
-        {
-            GRABGIL
-            RAISE(PyExc_SDLError,"cannot create overlay without pygame.display initialized");
-            Py_DECREF(movie);
-            RELEASEGIL
-            return -1;
-        }
-        screen = SDL_GetVideoSurface ();
-        if (!screen || (screen && (screen->w!=w || screen->h !=h)))
-        {
-            screen = SDL_SetVideoMode(w, h, 0, SDL_SWSURFACE);
-            if(!screen)
-            {
-                GRABGIL
-                RAISE(PyExc_SDLError, "Could not initialize a new video surface.");
-                Py_DECREF(movie);
-                RELEASEGIL
-                return -1;
-            }
-        }
-
-
-        vp->dest_overlay = SDL_CreateYUVOverlay (w, h, SDL_YV12_OVERLAY, screen);
-        if (!vp->dest_overlay)
-        {
-            GRABGIL
-            RAISE (PyExc_SDLError, "Cannot create overlay");
-            Py_DECREF(movie);
-            RELEASEGIL
-            return -1;
-        }
-        vp->overlay = movie->overlay;
+        if(movie->overlay>0)
+    	{
+	        //now we have to open an overlay up
+	        SDL_Surface *screen;
+	        if (!SDL_WasInit (SDL_INIT_VIDEO))
+	        {
+	            GRABGIL
+	            RAISE(PyExc_SDLError,"cannot create overlay without pygame.display initialized");
+	            Py_DECREF(movie);
+	            RELEASEGIL
+	            return -1;
+	        }
+	        screen = SDL_GetVideoSurface ();
+	        if (!screen || (screen && (screen->w!=w || screen->h !=h)))
+	        {
+	            screen = SDL_SetVideoMode(w, h, 0, SDL_SWSURFACE);
+	            if(!screen)
+	            {
+	                GRABGIL
+	                RAISE(PyExc_SDLError, "Could not initialize a new video surface.");
+	                Py_DECREF(movie);
+	                RELEASEGIL
+	                return -1;
+	            }
+	        }
+	
+	        vp->dest_overlay = SDL_CreateYUVOverlay (w, h, SDL_YV12_OVERLAY, screen);
+	        if (!vp->dest_overlay)
+	        {
+	            GRABGIL
+	            RAISE (PyExc_SDLError, "Cannot create overlay");
+	            Py_DECREF(movie);
+	            RELEASEGIL
+	            return -1;
+	        }
+	        vp->overlay = movie->overlay;
+    	}
     }
-    else if ((!vp->dest_surface && movie->overlay<=0) || ((movie->resize_w||movie->resize_h) && vp->dest_surface && (vp->height!=h || vp->width!=w)))
+    if ((!vp->dest_surface && movie->overlay<=0) || ((movie->resize_w||movie->resize_h) && vp->dest_surface && (vp->height!=h || vp->width!=w)))
     {
         //now we have to open an overlay up
         if(movie->resize_w||movie->resize_h)
         {
             SDL_FreeSurface(vp->dest_surface);
         }
-        SDL_Surface *screen = movie->canon_surf;
-        if (!SDL_WasInit (SDL_INIT_VIDEO))
-        {
-            GRABGIL
-            RAISE(PyExc_SDLError,"cannot create surfaces without pygame.display initialized");
-            Py_DECREF(movie);
-            RELEASEGIL
-            return -1;
-        }
-        if (!screen)
-        {
-            GRABGIL
-            RAISE(PyExc_SDLError, "No video surface given."); //ideally this should have
-            Py_DECREF(movie);									  //been caught at init, but this could feasibly
-            RELEASEGIL										  // happen if there's some cleaning up.
-            return -1;
-        }
-        int tw=w;
-        int th=h;
-        if(!movie->resize_w)
-        {
-            tw=screen->w;
-        }
-        if(!movie->resize_h)
-        {
-            th=screen->h;
-        }
-        /*GRABGIL
-        PySys_WriteStdout("screen->BitsPerPixel: %i\nscreen->RMask: %i\nscreen->Gmask: %i\nscreen->Bmask: %i\nscreen->Amask: %i\n",
-         screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
-        RELEASEGIL*/
-        vp->dest_surface = SDL_CreateRGBSurface(screen->flags,
-                                                tw,
-                                                th,
-                                                screen->format->BitsPerPixel,
-                                                screen->format->Rmask,
-                                                screen->format->Gmask,
-                                                screen->format->Bmask,
-                                                screen->format->Amask);
-        if (!vp->dest_surface)
-        {
-            GRABGIL
-            RAISE (PyExc_SDLError, "Cannot create new surface.");
-            Py_DECREF(movie);
-            RELEASEGIL
-            return -1;
-        }
-        vp->overlay = movie->overlay;
+        if(movie->overlay<=0)
+		{
+	        SDL_Surface *screen = movie->canon_surf;
+	        if (!SDL_WasInit (SDL_INIT_VIDEO))
+	        {
+	            GRABGIL
+	            RAISE(PyExc_SDLError,"cannot create surfaces without pygame.display initialized");
+	            Py_DECREF(movie);
+	            RELEASEGIL
+	            return -1;
+	        }
+	        if (!screen)
+	        {
+	            GRABGIL
+	            RAISE(PyExc_SDLError, "No video surface given."); //ideally this should have
+	            Py_DECREF(movie);									  //been caught at init, but this could feasibly
+	            RELEASEGIL										  // happen if there's some cleaning up.
+	            return -1;
+	        }
+	        SDL_Surface *display = SDL_GetVideoSurface ();
+	        if (!display || (display && (display->w!=w || display->h !=h)))
+	        {
+	            display = SDL_SetVideoMode(w, h, 0, SDL_SWSURFACE);
+	            if(!display)
+	            {
+	                GRABGIL
+	                RAISE(PyExc_SDLError, "Could not initialize a new video surface.");
+	                Py_DECREF(movie);
+	                RELEASEGIL
+	                return -1;
+	            }
+	        }
+	        int tw=w;
+	        int th=h;
+	        if(!movie->resize_w)
+	        {
+	            tw=screen->w;
+	        }
+	        if(!movie->resize_h)
+	        {
+	            th=screen->h;
+	        }
+	        /*GRABGIL
+	        PySys_WriteStdout("screen->BitsPerPixel: %i\nscreen->RMask: %i\nscreen->Gmask: %i\nscreen->Bmask: %i\nscreen->Amask: %i\n",
+	         screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
+	        RELEASEGIL*/
+	        vp->dest_surface = SDL_CreateRGBSurface(screen->flags,
+	                                                tw,
+	                                                th,
+	                                                screen->format->BitsPerPixel,
+	                                                screen->format->Rmask,
+	                                                screen->format->Gmask,
+	                                                screen->format->Bmask,
+	                                                screen->format->Amask);
+	        if (!vp->dest_surface)
+	        {
+	            GRABGIL
+	            RAISE (PyExc_SDLError, "Cannot create new surface.");
+	            Py_DECREF(movie);
+	            RELEASEGIL
+	            return -1;
+	        }
+	        vp->overlay = movie->overlay;
+		}
     }
     vp->width = w;
     vp->height = h;
             /* if video is slave, we try to correct big delays by
                duplicating or deleting a frame */
             ref_clock = get_master_clock(movie);
-            GRABGIL
-			PySys_WriteStdout("Audio Clock: %f\n", ref_clock);
+            //GRABGIL
+			//PySys_WriteStdout("Audio Clock: %f\n", ref_clock);
             diff = movie->video_current_pts - ref_clock;
-            PySys_WriteStdout("diff at call %i: %f\n", movie->diff_co, diff);
-            RELEASEGIL
+            //PySys_WriteStdout("diff at call %i: %f\n", movie->diff_co, diff);
+            //RELEASEGIL
             /* skip or repeat frame. We take into account the
                delay to compute the threshold. I still don't know
                if it is the best guess */
             actual_delay = 0.010;
         }
         GRABGIL
-        PySys_WriteStdout("frame_timer: %f\ndelay: %f\n",movie->frame_timer, delay);
+        //PySys_WriteStdout("frame_timer: %f\ndelay: %f\n",movie->frame_timer, delay);
         movie->timing = (actual_delay*1000.0)+0.5;
         RELEASEGIL
     }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.