Commits

zeroth  committed 8480a42

Finished small stats package for checking render times. Surface
rendering is much more consistent than Overlay rendering. Why?

  • Participants
  • Parent commits ebe7aa0
  • Branches tylerthemovie

Comments (0)

Files changed (4)

File movie_test.py

 # 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(-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 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)
+##
+##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
 #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(3)
-#And now we restart playing.
-print "Playing again..." 
-m.play(-1)
-print "done restart play..."
-time.sleep(10)
+##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(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((640, 348))
 #This will move the movie player from overlay mode to blitting to the surface 
 m=movie.Movie(filename, screen)
 counter = 0
 actions = {1: lambda x: x.paused, 6: lambda x:x.pause(), 11: lambda x:x.pause(), 15: lambda x: x.resize(int(x.width*0.9), int(x.height*0.9)), 2000:lambda x: x.stop(), 3000: lambda x: x.play(-1)}
-m.play(-1)
+m.play(0)
 prev_time = time.time()
 #m.resize(m.width*2, m.height*2)
 #m.surface = screen
 print "About to do surface gymnastics..."
-##while 1:
-##    time.sleep(0.1)
-##    pygame.display.update()
-
+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/_gmovie.c

 #endif
 
     if (!q->last_pkt)
-
         q->first_pkt = pkt1;
     else
         q->last_pkt->next = pkt1;
         video_open(movie, movie->pictq_windex);
     }
     dst_pix_fmt = PIX_FMT_YUV420P;
+    #ifdef PROFILE
+    	int64_t before = av_gettime();
+    #endif
     if (vp->dest_overlay && vp->overlay>0)
     {
         /* get a pointer on the bitmap */
         exit(1);
     }
     movie->img_convert_ctx = img_convert_ctx;
+	
     if(movie->resize_w||movie->resize_h)
     {
         sws_scale(img_convert_ctx, 
                   pict.data, 
                   pict.linesize);
     }
+    
     if (vp->dest_overlay && vp->overlay>0)
     {
         SDL_UnlockYUVOverlay(vp->dest_overlay);
         SDL_UnlockSurface(vp->dest_surface);
         avpicture_free(&pict);
     }
+    #ifdef PROFILE
+    	TimeSampleNode *sample = (TimeSampleNode *)PyMem_Malloc(sizeof(TimeSampleNode));
+    	sample->next=NULL;
+	    sample->sample = av_gettime()-before;
+	    if (!movie->istats->last || movie->istats->first->sample==0)
+	        movie->istats->first = sample;
+	    else
+	        movie->istats->last->next = sample;
+	    movie->istats->last = sample;
+    	movie->istats->n_samples++;
+    #endif
     vp->pts = movie->pts;
     movie->pictq_windex = (movie->pictq_windex+1)%VIDEO_PICTURE_QUEUE_SIZE;
     movie->pictq_size++;
 /* pause or resume the video */
 void stream_pause(PyMovie *movie)
 {
-    Py_INCREF( movie);
+    if(movie->ob_refcnt !=0)Py_INCREF( movie);
     int paused=movie->paused;
     movie->paused = !movie->paused;
     if (!movie->paused)
         movie->frame_timer += (av_gettime() - movie->video_current_pts_time) / 1000000.0;
     }
     movie->last_paused=paused;
-    Py_DECREF( movie);
+    if(movie->ob_refcnt !=0) {Py_DECREF( movie);}
 }
 
 int audio_thread(void *arg)
     PyMovie *movie = arg;
     DECLAREGIL
     GRABGIL
+	#ifdef PROFILE
+		movie->istats = (ImageScaleStats *)PyMem_Malloc(sizeof(ImageScaleStats));
+	#endif
     Py_INCREF( movie);
     RELEASEGIL
     AVFormatContext *ic;
     movie->pictq_size=movie->pictq_rindex=movie->pictq_windex=0;
     packet_queue_flush(&movie->videoq);
 	movie->finished=1;
+    
     GRABGIL
+    #ifdef PROFILE
+    	//mean
+    	int64_t sum =0;
+    	int64_t max = 0;
+    	int64_t min = 2<<24;
+    	TimeSampleNode *cur = movie->istats->first;
+    	while(cur!=NULL) 
+    	{
+    		sum+= cur->sample;
+    		if(cur->sample>max) max=cur->sample;
+    		if(cur->sample<min) min=cur->sample;
+    		if(cur->next==NULL) break; 
+    		cur=cur->next;
+    	}
+    	movie->istats->mean = (double)sum/movie->istats->n_samples;
+    	movie->istats->max = max;
+    	movie->istats->min = min;
+    	double total = 0;
+    	double mean = movie->istats->mean;
+    	cur = movie->istats->first;
+    	while(cur->next!=NULL) 
+    	{
+    		total+= pow(((double)cur->sample-mean), (double)2);
+    		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);
+    #endif
     Py_DECREF( movie);
     RELEASEGIL
     if(movie->abort_request)

File src/_gmovie.h

 /*constant definitions */
 #define MAX_VIDEOQ_SIZE (5 * 256 * 1024)
 #define MAX_AUDIOQ_SIZE (5 * 16 * 1024)
+#define MAX_SUBTITLEQ_SIZE (5 * 16 * 1024)
 
 /* no AV sync correction is done if below the AV sync threshold */
 #define AV_SYNC_THRESHOLD 0.01
 
 #define BPP 1
 
+//enables profiling info to be gathered
+#define PROFILE 1
+
+#ifdef PROFILE
+#include <math.h>
+	typedef struct TimeSampleNode
+	{
+		int64_t sample;
+		struct TimeSampleNode *next;
+	}TimeSampleNode;
+	typedef struct ImageScaleStats
+	{
+		double mean;
+		int64_t max;
+		int64_t min;
+		double stdev;
+		double median;
+		double firstqu;
+		double thirdqu;
+		double serror;
+		int64_t n_samples;
+		struct TimeSampleNode *first;
+		struct TimeSampleNode *last;
+	}ImageScaleStats;
+#endif
 //included from ffmpeg header files, as the header file is not publically available.
 #if defined(__ICC) || defined(__SUNPRO_C)
     #define DECLARE_ALIGNED(n,t,v)      t v __attribute__ ((aligned (n)))
 	int subpq_rindex, subpq_windex, subpq_size;
 	SDL_mutex *subpq_mutex;
 	int subtitle_disable;
+#ifdef PROFILE
+	ImageScaleStats *istats;
+#endif
+
 }
 PyMovie;
 /* end of struct definitions */

File src/gmovie.c

 
 void _movie_dealloc(PyMovie *movie)
 {
-	PySys_WriteStdout("Deleting\n");
+	//PySys_WriteStdout("Deleting\n");
 	if(movie->_tstate)
 	{
 		PyThreadState_Clear(movie->_tstate);
-		//PyThreadState_Delete(movie->_tstate);
 	}
 	if(!movie->stop)
-		movie=(PyMovie *)_movie_stop(movie);
+	{
+		Py_BEGIN_ALLOW_THREADS
+	    SDL_LockMutex(movie->dest_mutex);
+	    stream_pause(movie);
+	    movie->stop = 1;
+	    Py_END_ALLOW_THREADS
+	    SDL_UnlockMutex(movie->dest_mutex);
+	}
+	#ifdef PROFILE
+		TimeSampleNode *cur = movie->istats->first;
+		TimeSampleNode *prev;
+		while(cur!=NULL) 
+    	{
+    		prev=cur;
+    		cur=cur->next;
+			PyMem_Free(prev);
+    	}
+    	PyMem_Free(movie->istats);
+    #endif
 	stream_close(movie, 0);
     movie->ob_type->tp_free((PyObject *) movie);
 }