Commits

Anonymous committed 71090b3

Fixed a few more small bugs, created a macro which makes command
allocation much more forgetfulness-proof. (Never be idiot proof... this
IS C after all...)

Comments (0)

Files changed (5)

 # 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
-##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 "Altering xleft and ytop..."
-##m.shift(10, 10)
-##time.sleep(10)
-##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..."
-##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.resize(m.width/2, 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(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..."
+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(10, 5, 0, 0)
+time.sleep(5)
+m.easy_seek(10, 5, 0, 0)
+time.sleep(1)
+m.pause()
+time.sleep(5)
+m.pause()
+time.sleep(10)
+
+print "Altering xleft and ytop..."
+m.shift(10, 10)
+time.sleep(10)
+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..."
+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.resize(m.width/2, 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(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..."
 screen = pygame.display.set_mode((640, 348))
-##m.surface=screen
-##time.sleep(1)
+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.
 Command *getCommand(CommandQueue *q);
 int hasCommand(CommandQueue *q);
 void flushCommands(CommandQueue *q);
-
 int registerCommand(CommandQueue *q);
 
+#define ALLOC_COMMAND(command, name) command* name = (command *)PyMem_Malloc(sizeof(command)); name->type=movie->command##Type;
+
 #endif /*_GCOMMAND_H_*/
 /* seek in the stream */
 void stream_seek(PyMovie *movie, int64_t pos, int rel)
 {
-    seekCommand *seek = (seekCommand *) PyMem_Malloc(sizeof(seekCommand));
-    seek->type = movie->seekCommandType;
+    /*seekCommand *seek = (seekCommand *) PyMem_Malloc(sizeof(seekCommand));
+    seek->type = movie->seekCommandType;*/
+    //int type = movie->seekCommandType;
+    ALLOC_COMMAND(seekCommand, seek)
     seek->pos = pos;
     seek->rel = rel;
     addCommand(movie->commands, (Command *)seek);
 /* pause or resume the video */
 void stream_pause(PyMovie *movie)
 {
-	pauseCommand *pause = (pauseCommand *) PyMem_Malloc(sizeof(pauseCommand));
-	pause->type = movie->pauseCommandType;
+	ALLOC_COMMAND(pauseCommand, pause);
 	addCommand(movie->commands, (Command *)pause);
 }
 
 #include "gmovie.h"
 
-
 void _movie_init_internal(PyMovie *self, const char *filename, SDL_Surface *surf)
 {
     Py_INCREF(self);
 PyObject* _movie_stop(PyMovie *movie)
 {
     stream_pause(movie);
-    stopCommand *stop = (stopCommand *)PyMem_Malloc(sizeof(stopCommand));
-    stop->type = movie->stopCommandType;
+    ALLOC_COMMAND(stopCommand, stop);
     addCommand(movie->commands, (Command *)stop);
     Py_RETURN_NONE;
 }
     {
         return RAISE (PyExc_SDLError, "Cannot set negative sized display mode");
     }
-    resizeCommand *resize = (resizeCommand *)PyMem_Malloc(sizeof(resizeCommand));
-    resize->type = movie->resizeCommandType;
+    ALLOC_COMMAND(resizeCommand, resize);
     
     resize->h = h;
     resize->w  = w;
 	{
 		return NULL;	
 	}
-	shiftCommand *shift = (shiftCommand *)PyMem_Malloc(sizeof(shiftCommand));
-	shift->type = movie->shiftCommandType;
+	ALLOC_COMMAND(shiftCommand, shift);
 	shift->xleft=x;
 	shift->ytop=y;
 	addCommand(movie->commands, (Command *)shift);
 	Py_RETURN_NONE;
 }
 
-PyObject* _movie_easy_seek (PyMovie *movie, PyObject* args, PyObject *kwds)
+PyObject* _movie_easy_seek (PyMovie *movie, PyObject* args)
 {
 	int64_t pos=0;
 	int hour=0;
 	int second=0;
 	int reverse=0;
 	//int relative=0;
-	char *keywords[4] = {"second", "minute", "hour", "reverse"};
-	if(!PyArg_ParseTupleAndKeywords(args, kwds, "|iiii", keywords, &second, &minute, &hour, &reverse))
+	//char *keywords[4] = {"second", "minute", "hour", "reverse"};
+	if(!PyArg_ParseTuple(args, "iiii", &second, &minute, &hour, &reverse))
 	{
 		Py_RETURN_NONE;
 	}
     if(PyInt_Check(width))
     {
         w = (int)PyInt_AsLong(width);
-        resizeCommand *resize = (resizeCommand *)PyMem_Malloc(sizeof(resizeCommand));
-    	resize->type = movie->resizeCommandType;
+        ALLOC_COMMAND(resizeCommand, resize);
     
     	resize->h = 0;
     	resize->w  = w;
     if(PyInt_Check(height))
     {
         h = (int)PyInt_AsLong(height);
-    	resizeCommand *resize = (resizeCommand *)PyMem_Malloc(sizeof(resizeCommand));
-    	resize->type = movie->resizeCommandType;
-    
+    	
+        ALLOC_COMMAND(resizeCommand, resize);
     	resize->h = h;
     	resize->w  = 0;
 		addCommand(movie->commands, (Command *)resize);
     if(PyInt_Check(ytop))
     {
         y = (int)PyInt_AsLong(ytop);
-        shiftCommand *shift = (shiftCommand *)PyMem_Malloc(sizeof(shiftCommand));
-        shift->type = movie->shiftCommandType;
+        ALLOC_COMMAND(shiftCommand, shift);
         shift->ytop = y;
         shift->xleft = 0;
         addCommand(movie->commands, (Command *)shift);
     if(PyInt_Check(xleft))
     {
         x = (int)PyInt_AsLong(xleft);
-        shiftCommand *shift = (shiftCommand *)PyMem_Malloc(sizeof(shiftCommand));
-        shift->type = movie->shiftCommandType;
+        ALLOC_COMMAND(shiftCommand, shift);
         shift->ytop = 0;
         shift->xleft = x;
         addCommand(movie->commands, (Command *)shift);
                                           { "pause",     (PyCFunction) _movie_pause,     METH_NOARGS,                DOC_GMOVIEMOVIEPAUSE},
                                           { "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},
+                                          { "easy_seek", (PyCFunction) _movie_easy_seek, METH_VARARGS, NULL},
                                           { "shift",     (PyCFunction) _movie_shift, METH_VARARGS, NULL},
                                           { NULL,     NULL,                        0,            NULL }
                                       };
 PyObject* _movie_rewind       (PyMovie *movie, PyObject* args);
 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_easy_seek    (PyMovie *movie, PyObject* args);
 PyObject *_movie_shift(PyMovie *movie, PyObject*args);
 
 /* Getters/setters */