Commits

Anonymous committed 3d4d167

Tested expansion of command queue to all interactions, fixed several
bugs. Also cleared flickering bug... which was a bug in the python test,
not my module. Apparently if you don't change the movie to surface mode,
and then call pygame.display.update() you get flickering! Silly me. But
I did find a bug with the surface application, and determined that
things look 100% smoother with RGB24 vs RGBA.

So surfaces work, just need to figure out the desync issue...

  • Participants
  • Parent commits ad8a925
  • Branches tylerthemovie

Comments (0)

Files changed (8)

File config_unix.py

 class DebugDependency(Dependency):
     def __init__(self, name, checkhead, checklib, libs):
         Dependency.__init__(self, name, checkhead, checklib, libs)
-        self.cflags=""
+        self.cflags="-Xcompiler -O0"
 
 class DependencyPython:
     def __init__(self, name, module, header):

File movie_test.py

 # Without a surface argument, the ffmpeg-wrapper uses the sdl_overlay library. 
 #screen=pygame.display.set_mode((640, 368))
 
-m = movie.Movie(filename)
-print m.paused  #always False, unless .pause has been called
-print m.playing #False until play has been called. Will return to false when
-print m.finished# .stop() has been called.
-                
-print m.width   #default size values of the video file
-print m.height  # They can be modified on the fly, as will be demonstrated.
-
-print m         #calls __repr__, which will show the filename, and the current 
-                # timestamp. 
-#print "repeated looping plays.."#
-#m.play(10)
-#time.sleep(10*30)
-
-
-print "Playing infinitely"
-
-m.play(-1)       #We're going to use infinite play, so we can demonstrate all 
-                # the features.
-time.sleep(2)  #sleep for ten seconds to let one see the video play, and hear 
-                # the audio
-##print "Paused:",m.paused
-##print "Playing:",m.playing
-##print "Movie:",m
-##print "Y Top:",m.ytop
-##print "X Left:",m.xleft
+##m = movie.Movie(filename)
+##print m.paused  #always False, unless .pause has been called
+##print m.playing #False until play has been called. Will return to false when
+##print m.finished# .stop() has been called.
+##                
+##print m.width   #default size values of the video file
+##print m.height  # They can be modified on the fly, as will be demonstrated.
+##
+##print m         #calls __repr__, which will show the filename, and the current 
+##                # timestamp. 
+###print "repeated looping plays.."#
+###m.play(10)
+###time.sleep(10*30)
+##
+##
+##print "Playing infinitely"
+##
+##m.play(-1)       #We're going to use infinite play, so we can demonstrate all 
+##                # the features.
+##time.sleep(2)  #sleep for ten seconds to let one see the video play, and hear 
+##                # the audio
+####print "Paused:",m.paused
+####print "Playing:",m.playing
+####print "Movie:",m
+####print "Y Top:",m.ytop
+####print "X Left:",m.xleft
 ##time.sleep(30)
-##print "Testing seek..."
-##m.easy_seek(second=10, minute=5, reverse=0)
-##time.sleep(5)
-##m.easy_seek(second=10, minute=5, reverse=0)
-##time.sleep(1)
-##m.pause()
-##time.sleep(5)
-##m.pause()
-##time.sleep(10)
+####print "Testing seek..."
+####m.easy_seek(second=10, minute=5, reverse=0)
+####time.sleep(5)
+####m.easy_seek(second=10, minute=5, reverse=0)
+####time.sleep(1)
+####m.pause()
+####time.sleep(5)
+####m.pause()
+####time.sleep(10)
 ##
 ##print "Altering xleft and ytop..."
-##m.xleft += 10
-##m.ytop  +=10
+##m.shift(10, 10)
 ##time.sleep(10)
-##m.xleft -= 10
-##m.ytop -=10
-#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.
+##m.shift(0, 0)
+###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..."
 ##print "sleeping again" 
 ##time.sleep(10)
 ##print "Back to normal!"
-##m.width=m.width/2
-##m.height = m.height/2
+##m.resize(m.width/2, m.height/2)
 ##print "and again, sleeping..."
-#back to our original size
+###back to our original size
 ##time.sleep(10)
-
-
-#Here we demonstrate the use of pause. You pause, then call pause again to play
+##
+##
+###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)
-#Here is the stop function. Right now, rewind is the exact same as stop.
-print "Stopping..., sleeping for 3 seconds"
-m.stop()
-time.sleep(5)
-#And now we restart playing.
-del m
-print "Playing again..." 
-m=movie.Movie(filename)
-m.play(-1)
-print "done restart play..."
-time.sleep(10)
-print "Surface time..."
+###Here is the stop function. Right now, rewind is the exact same as stop.
+##print "Stopping..., sleeping for 3 seconds"
+##m.stop()
+##time.sleep(5)
+###And now we restart playing.
+##del m
+##print "Playing again..." 
+##m=movie.Movie(filename)
+##m.play(-1)
+##print "done restart play..."
+##time.sleep(10)
+##print "Surface time..."
 screen = pygame.display.set_mode((640, 348))
+##m.surface=screen
+##time.sleep(1)
 #This will move the movie player from overlay mode to blitting to the surface 
 # we've given it. This means it is our responsibility to update the display on 
 # time.
-while not m.finished:
-    time.sleep(0.1)
-    pygame.display.update()
+#while not m.finished:
+#    time.sleep(0.1)
+#    pygame.display.update()
 
 
 
 #m.resize(m.width*2, m.height*2)
 #m.surface = screen
 print "About to do surface gymnastics..."
-while not m.finished:
-    time.sleep(0.1)
-    pygame.display.update()
-time.sleep(1000)
+##while not m.finished:
+##    time.sleep(0.1)
+##    pygame.display.update()
+##time.sleep(1000)
 while(1):
     new_time=time.time()
     diff = int(new_time-prev_time)

File src/_gcommand.c

 void addCommand(CommandQueue *q, Command *comm)
 {
 	SDL_LockMutex(q->q_mutex);
+	comm->next=NULL;
 	q->registry[comm->type]++;
 	if(!q->size)
 	{

File src/_gcommand.h

 
 #define FULL_COMMAND \
 	int type;\
-	Command *next;
+	struct Command *next;
 
 typedef struct CommandQueue
 {

File src/_gmovie.c

 
 int video_display(PyMovie *movie)
 {
-    DECLAREGIL
-    GRABGIL
-    Py_INCREF(movie);
     double ret=1;
-    RELEASEGIL
-#if THREADFREE!=1
     SDL_LockMutex(movie->dest_mutex);
-#endif
 
     VidPicture *vp = &movie->pictq[movie->pictq_rindex];
     if((!vp->dest_overlay&& vp->overlay>0)||(!vp->dest_surface && vp->overlay<=0))
     {
         ret=0;
     }
-#if THREADFREE !=1
     SDL_UnlockMutex(movie->dest_mutex);
-#endif
 
-    GRABGIL
-    Py_DECREF(movie);
-    RELEASEGIL
     /* If we didn't actually display the image, we need to not clear our timer out in decoder */
     return ret;
 }
 {
     /* Wrapped by video_display, which has a lock on the movie object */
     DECLAREGIL
-    GRABGIL
-    Py_INCREF( movie);
-    RELEASEGIL
     VidPicture *vp;
     //SubPicture *sp;
     float aspect_ratio;
     movie->pictq_rindex= (movie->pictq_rindex+1)%VIDEO_PICTURE_QUEUE_SIZE;
     movie->pictq_size--;
     video_refresh_timer(movie);
-    GRABGIL
-    Py_DECREF( movie);
-    RELEASEGIL
 }
 
 int video_open(PyMovie *movie, int index)
     int w=0;
     int h=0;
     DECLAREGIL
-    GRABGIL
-    Py_INCREF( movie);
-    RELEASEGIL
     get_height_width(movie, &h, &w);
     VidPicture *vp;
     vp = &movie->pictq[index];
 	        {
 	            GRABGIL
 	            RAISE(PyExc_SDLError,"cannot create overlay without pygame.display initialized");
-	            Py_DECREF(movie);
 	            RELEASEGIL
 	            return -1;
 	        }
 	            {
 	                GRABGIL
 	                RAISE(PyExc_SDLError, "Could not initialize a new video surface.");
-	                Py_DECREF(movie);
 	                RELEASEGIL
 	                return -1;
 	            }
 	        {
 	            GRABGIL
 	            RAISE (PyExc_SDLError, "Cannot create overlay");
-	            Py_DECREF(movie);
 	            RELEASEGIL
 	            return -1;
 	        }
 	        {
 	            GRABGIL
 	            RAISE(PyExc_SDLError,"cannot create surfaces without pygame.display initialized");
-	            Py_DECREF(movie);
 	            RELEASEGIL
 	            return -1;
 	        }
 	        {
 	            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;
 	        }
 	            {
 	                GRABGIL
 	                RAISE(PyExc_SDLError, "Could not initialize a new video surface.");
-	                Py_DECREF(movie);
 	                RELEASEGIL
 	                return -1;
 	            }
 	        {
 	            GRABGIL
 	            RAISE (PyExc_SDLError, "Cannot create new surface.");
-	            Py_DECREF(movie);
 	            RELEASEGIL
 	            return -1;
 	        }
     vp->height = h;
     vp->ytop=movie->ytop;
     vp->xleft=movie->xleft;
-    GRABGIL
-    Py_DECREF( movie);
-    RELEASEGIL
     return 0;
 }
 
 void video_refresh_timer(PyMovie* movie)
 {
     DECLAREGIL
-    GRABGIL
-    Py_INCREF(movie);
-    RELEASEGIL
     double actual_delay, delay, sync_threshold, ref_clock, diff;
     VidPicture *vp;
 
         movie->timing = (actual_delay*1000.0)+1;
         RELEASEGIL
     }
-    GRABGIL
-    Py_DECREF(movie);
-    RELEASEGIL
 }
 
 int queue_picture(PyMovie *movie, AVFrame *src_frame)
 {
     DECLAREGIL
-    GRABGIL
-    Py_INCREF(movie);
-    RELEASEGIL
     int dst_pix_fmt;
     AVPicture pict;
     VidPicture *vp;
 	    {
 	    	dst_pix_fmt = PIX_FMT_RGBA;
 	    }
-	    //pict.data = (uint8_t *)vp->dest_surface->pixels;
         avpicture_alloc(&pict, dst_pix_fmt, w, h);
         SDL_LockSurface(vp->dest_surface);
     }
     movie->pictq_windex = (movie->pictq_windex+1)%VIDEO_PICTURE_QUEUE_SIZE;
     movie->pictq_size++;
     vp->ready=1;
-    GRABGIL
-    Py_DECREF(movie);
-    RELEASEGIL
     return 0;
 }
 
 
 void update_video_clock(PyMovie *movie, AVFrame* frame, double pts1)
 {
-    DECLAREGIL
-    GRABGIL
-    Py_INCREF(movie);
-    RELEASEGIL
     double frame_delay, pts;
 
     pts = pts1;
     movie->video_clock += frame_delay;
 
     movie->pts = pts;
-    GRABGIL
-    Py_DECREF(movie);
-    RELEASEGIL
 }
 
 /* get the current audio clock value */
 double get_master_clock(PyMovie *movie)
 {
     DECLAREGIL
-    GRABGIL
-    Py_INCREF( movie);
-    RELEASEGIL
     double val;
 
     if (movie->av_sync_type == AV_SYNC_VIDEO_MASTER)
     {
         val = get_external_clock(movie);
     }
-    GRABGIL
-    Py_DECREF( movie);
-    RELEASEGIL
     return val;
 }
 
     self->stopCommandType=registerCommand(self->commands);
     self->resizeCommandType=registerCommand(self->commands);
     self->shiftCommandType = registerCommand(self->commands);
+	self->surfaceCommandType = registerCommand(self->commands);
 }
 
 /* seek in the stream */
     		else if (comm->type == movie->resizeCommandType)
     		{
     			resizeCommand *resize=(resizeCommand *)comm;
-    			if (resize->h)
+    			if (resize->h!=0)
     			{
     				movie->resize_h=1;
     				movie->height=resize->h;
     			}
-    			if(resize->w)
+    			if(resize->w!=0)
     			{
     				movie->resize_w=1;
     				movie->width= resize->w;
     		else if (comm->type == movie->shiftCommandType)
     		{
     			shiftCommand *shift = (shiftCommand *)comm;
-    			if(shift->ytop)
-    			{
-    				movie->ytop=shift->ytop;
-    			}
-    			if(shift->xleft)
-    			{
-    				movie->xleft=shift->xleft;
-    			}
+    			
+				movie->xleft=shift->xleft;
+    			movie->ytop=shift->ytop;
     			comm=NULL;
     			PyMem_Free(shift);
     			
         }
         if (movie->seek_req)
         {
+            movie->working=0;
             int64_t seek_target= movie->seek_pos;
 			seek_target-=1*AV_TIME_BASE;
 			int aud_stream_index=-1;
          		}
          		av_free_packet(pkt);
          	}
-         	movie->working=0;
+         	
         }
         /* if the queue are full, no need to read more */
         if ( //yay for short circuit logic testing
     movie->pictq_size=movie->pictq_rindex=movie->pictq_windex=0;
     packet_queue_flush(&movie->videoq);
 	movie->finished=1;
-    
+    movie->working=0;
     GRABGIL
     #ifdef PROFILE
     	//mean
 int video_render(PyMovie *movie)
 {
     DECLAREGIL
-    GRABGIL
-    Py_INCREF( movie);
-    RELEASEGIL
     AVPacket pkt1, *pkt = &pkt1;
     int len1, got_picture;
     AVFrame *frame= avcodec_alloc_frame();
     while(0);
 
 the_end:
-    GRABGIL
-    Py_DECREF(movie);
-    RELEASEGIL
     av_free(frame);
     return 0;
 }

File src/_gmovie.h

 #define SUBPICTURE_QUEUE_SIZE    4
 /* RGB24 or RGBA... */
 /* In this case I've chosen RGB24 because its smaller */
-#define RGB24 0
-#define RGBA  1
+#define RGB24 1
+#define RGBA  0
 
 #if RGB24
 	#define RGBSTEP 3
 typedef struct shiftCommand
 {
 	FULL_COMMAND
+	int barrier;
 	int ytop;
 	int xleft;	
 } shiftCommand;

File src/gmovie.c

 
 }
 
+PyObject *_movie_shift(PyMovie *movie, PyObject*args)
+{
+	int x=0;
+	int y=0;
+	if(PyArg_ParseTuple(args, "ii", &x, &y)<0)
+	{
+		return NULL;	
+	}
+	shiftCommand *shift = (shiftCommand *)PyMem_Malloc(sizeof(shiftCommand));
+	shift->type = movie->shiftCommandType;
+	shift->xleft=x;
+	shift->ytop=y;
+	addCommand(movie->commands, (Command *)shift);
+	Py_RETURN_NONE;
+}
+
 PyObject* _movie_easy_seek (PyMovie *movie, PyObject* args, PyObject *kwds)
 {
 	int64_t pos=0;
     {
         y = (int)PyInt_AsLong(ytop);
         shiftCommand *shift = (shiftCommand *)PyMem_Malloc(sizeof(shiftCommand));
+        shift->type = movie->shiftCommandType;
         shift->ytop = y;
         shift->xleft = 0;
         addCommand(movie->commands, (Command *)shift);
     {
         x = (int)PyInt_AsLong(xleft);
         shiftCommand *shift = (shiftCommand *)PyMem_Malloc(sizeof(shiftCommand));
+        shift->type = movie->shiftCommandType;
         shift->ytop = 0;
         shift->xleft = x;
         addCommand(movie->commands, (Command *)shift);
 int _movie_set_surface(PyObject *mov, PyObject *surface, void *closure)
 {
     PyMovie *movie = (PyMovie *)mov;
+    surfaceCommand *surf;
     if(PySurface_Check(surface))
     {
         /*movie->canon_surf=PySurface_AsSurface(surface);
         movie->overlay=0;*/
-        surfaceCommand *surf = (surfaceCommand *)PyMem_Malloc(sizeof(surfaceCommand));
+        surf = (surfaceCommand *)PyMem_Malloc(sizeof(surfaceCommand));
+        surf->type = movie->surfaceCommandType;
         surf->surface = PySurface_AsSurface(surface);
         addCommand(movie->commands, (Command *)surf);
         return 0;
     }
     else if(surface == Py_None)
     {
-    	surfaceCommand *surf = (surfaceCommand *)PyMem_Malloc(sizeof(surfaceCommand));
+    	surf = (surfaceCommand *)PyMem_Malloc(sizeof(surfaceCommand));
+        surf->type = movie->surfaceCommandType;
         surf->surface = NULL;
         addCommand(movie->commands, (Command *)surf);
     	return 0;
                                           { "rewind",    (PyCFunction) _movie_rewind,    METH_VARARGS,               DOC_GMOVIEMOVIEREWIND},
                                           { "resize",    (PyCFunction) _movie_resize,    METH_VARARGS,               DOC_GMOVIEMOVIERESIZE},
                                           { "easy_seek", (PyCFunction) _movie_easy_seek, METH_VARARGS|METH_KEYWORDS, NULL},
+                                          { "shift",     (PyCFunction) _movie_shift, METH_VARARGS, NULL},
                                           { NULL,     NULL,                        0,            NULL }
                                       };
 

File src/gmovie.h

 PyObject* _movie_resize       (PyMovie *movie, PyObject* args);
 PyObject* _movie_seek         (PyMovie *movie, PyObject* args);
 PyObject* _movie_easy_seek    (PyMovie *movie, PyObject* args, PyObject *kwds);
+PyObject *_movie_shift(PyMovie *movie, PyObject*args);
 
 /* Getters/setters */
 PyObject* _movie_get_paused  (PyMovie *movie, void *closure);