Anonymous avatar Anonymous committed b2de91d

Fixed slowdown issue that happened on odd-numbered playthroughs

Comments (0)

Files changed (5)

 # to be on time for rendering that surface.
 # 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(0)       #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 m.paused
-##print m.playing
-##print m
-##
-###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)
-##while not m.finished:
-##    time.sleep(1)
-##
-##del m
+
+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(2)
+print "Altering xleft and ytop..."
+#m.xleft += 10
+#m.ytop  +=10
+time.sleep(100)
+
+#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()
     }
     vp->width = w;
     vp->height = h;
+    vp->ytop=movie->ytop;
+    vp->xleft=movie->xleft;
     GRABGIL
     Py_DECREF( movie);
     RELEASEGIL
             stopBuffer(movie->channel);
             goto closing;
         }
-        
+        if(getBufferQueueSize()>100)
+        {
+        	SDL_Delay(100);
+        	continue;
+        }
         
         //fill up the buffer
         while(movie->audio_pkt_size > 0)
 			if(chan==-1)
 			{
 				GRABGIL
-				PySys_WriteStdout("%s\n", Mix_GetError());
+				char *s = Mix_GetError();
+				PySys_WriteStdout("%s\n", s);
 				RELEASEGIL	
 			}
             movie->channel = chan;
 
     int wanted_video_stream=1;
     int wanted_audio_stream=1;
-    int wanted_subti_stream=1;
+    int wanted_subti_stream=-1;
     /* if seeking requested, we execute it */
     if (movie->start_time != AV_NOPTS_VALUE)
     {
     DECLAREGIL
     GRABGIL
 	#ifdef PROFILE
-		movie->istats = (ImageScaleStats *)PyMem_Malloc(sizeof(ImageScaleStats));
+		if(movie->istats==NULL)
+			movie->istats = (ImageScaleStats *)PyMem_Malloc(sizeof(ImageScaleStats));
 	#endif
     Py_INCREF( movie);
     RELEASEGIL
     		cur=cur->next;
     	}
     	movie->istats->stdev = sqrt(total/mean);	
-    	PySys_WriteStdout("Mean: %f\nMin: %i\nMax: %i\nStDev: %f\n", mean, (int)min, (int)max, movie->istats->stdev);
+    	PySys_WriteStdout("# Samples: %i\nMean: %f\nMin: %i\nMax: %i\nStDev: %f\n", (int)movie->istats->n_samples, mean, (int)min, (int)max, movie->istats->stdev);
+    	cur = movie->istats->first;
+    	TimeSampleNode *prev;
+    	while(cur->next!=NULL) 
+    	{
+    		prev=cur;
+    		cur=cur->next;
+    		PyMem_Free(prev);
+    	}
+    	movie->istats->first=NULL;
+    	movie->istats->last=NULL;
+    	movie->istats->n_samples=0;
     #endif
     Py_DECREF( movie);
     RELEASEGIL
     ainfo.mutex = SDL_CreateMutex();
     ainfo.queue.mutex = SDL_CreateMutex();
     ainfo.ended=1;
+    Mix_VolumeMusic (127);
+    
     //ainfo._tstate = _tstate;
     return 0;
 }
 
 int soundStart (void)
 {
-    Mix_VolumeMusic (127);
     Mix_ChannelFinished(&cb_mixer);
     ainfo.ended=0;
     ainfo.audio_clock =0.0;
 /* Play a sound buffer, with a given length */
 int playBuffer (uint8_t *buf, uint32_t len, int channel, int64_t pts)
 {
-	SDL_mutexP(ainfo.mutex);
+	//SDL_mutexP(ainfo.mutex);
     Mix_Chunk *mix;
     int false=0;
     int allocated=0;
             node->next =NULL;
             node->pts = pts;
             queue_put(&ainfo.queue, node);
-            SDL_mutexV(ainfo.mutex);
+            //SDL_mutexV(ainfo.mutex);
+            if(ainfo.channel<0)
+            	ainfo.channel=channel;
             return ainfo.channel;
         }
         else if(!buf && ainfo.queue.size==0)
             queue_get(&ainfo.queue, &new);
             if(!new)
             {
-                SDL_mutexV(ainfo.mutex);
+                //SDL_mutexV(ainfo.mutex);
                 return -1;
             }
             ainfo.current_frame_size=new->len;
     ainfo.current_frame_size =len;
     int chan = ainfo.channel;
     
-    SDL_mutexV(ainfo.mutex);
+    //SDL_mutexV(ainfo.mutex);
     
     int playing = Mix_Playing(chan);
     if(playing && allocated &&false)
     {
     	return chan;
     }
+    if(mix==NULL)
+    {
+    	return chan;
+    }
     int ret = Mix_PlayChannel(chan, mix, 0);
-
+	if(ret<0)
+	{
+		ainfo.holder+=10;
+		char *s = SDL_GetError();
+		ainfo.error = s;
+	}
     ainfo.channel = ret;
     if(allocated)
     {
     return pts;
 }
 
+int getBufferQueueSize(void)
+{
+	return ainfo.queue.size;
+}
     SDL_mutex   *mutex;
 	//PyThreadState *_tstate;
 	int restart;
+	int holder;
+	char *error;
 }
 AudioInfo;
 
 int pauseBuffer   (int channel);
 int getPaused     (int channel);
 double getAudioClock (void);
+int getBufferQueueSize(void);
 int seekBuffer    (uint8_t *buf, uint32_t len, int channel );
 int setCallback   (void (*callback) (int channel));
 int resetAudioInfo(void);
 
 }
 
+PyObject* _movie_get_ytop (PyMovie *movie, void *closure)
+{
+    PyObject *pyo;
+    if(movie->video_st)
+    {
+        pyo= PyInt_FromLong((long)movie->ytop);
+    }
+    else
+    {
+        pyo = PyInt_FromLong((long)0);
+    }
+    return pyo;
+}
+int _movie_set_ytop (PyMovie *movie, PyObject *ytop, void *closure)
+{
+    int y;
+    if(PyInt_Check(ytop))
+    {
+        y = (int)PyInt_AsLong(ytop);
+        movie->ytop=y;
+        return 0;
+    }
+    else
+    {
+        return -1;
+    }
+
+}
+
+PyObject* _movie_get_xleft (PyMovie *movie, void *closure)
+{
+    PyObject *pyo;
+    if(movie->video_st)
+    {
+        pyo= PyInt_FromLong((long)movie->xleft);
+    }
+    else
+    {
+        pyo = PyInt_FromLong((long)0);
+    }
+    return pyo;
+}
+int _movie_set_xleft (PyMovie *movie, PyObject *xleft, void *closure)
+{
+    int x;
+    if(PyInt_Check(xleft))
+    {
+        x = (int)PyInt_AsLong(xleft);
+        movie->xleft=x;
+        return 0;
+    }
+    else
+    {
+        return -1;
+    }
+
+}
 
 PyObject *_movie_get_surface(PyMovie *movie, void *closure)
 {
         { "height",   (getter) _movie_get_height,  (setter) _movie_set_height,  DOC_GMOVIEMOVIEHEIGHT,  NULL },
         { "width",    (getter) _movie_get_width,   (setter) _movie_set_width,   DOC_GMOVIEMOVIEWIDTH,   NULL },
         { "surface",  (getter) _movie_get_surface, (setter) _movie_set_surface, DOC_GMOVIEMOVIESURFACE, NULL },
+        { "ytop",     (getter) _movie_get_ytop,    (setter) _movie_set_ytop,    NULL,                   NULL },
+        { "xleft",    (getter) _movie_get_xleft,   (setter) _movie_set_xleft,   NULL,                   NULL },
         { NULL,       NULL,                        NULL,                        NULL,                   NULL }
     };
 
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.