Commits

zeroth  committed db1a1b8

Fixed reference issue, deleting works properly, except fifth time in a
row.

  • Participants
  • Parent commits a8850fe
  • Branches tylerthemovie

Comments (0)

Files changed (6)

File movie_test.py

 
 print "Please give an (absolute)filename of a movie file you'd like to play: ",
 #filename = raw_input()
-filename="/home/tyler/War3.avi"
+filename="/home/tyler/avatar.avi"
 #initialization. It could also have a surface as a second argument, and every 
 # frame will be blitted to that surface. It is the programmer's responsibility
 # 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
-##                # .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. 
+
+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
+                # .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
-##
+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..."
+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)
+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 "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)
+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..."
+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 
 # we've given it. This means it is our responsibility to update the display on 

File src/_gmovie.c

     return 0;
 }
 
-void stream_component_end(PyMovie *movie, int stream_index)
+void stream_component_end(PyMovie *movie, int stream_index, int threaded)
 {
     DECLAREGIL
-    GRABGIL
+    if(threaded) GRABGIL
     if(movie->ob_refcnt!=0)
         Py_INCREF( movie);
-    RELEASEGIL
+    if(threaded) RELEASEGIL
     AVFormatContext *ic = movie->ic;
     AVCodecContext *enc;
 
     if (stream_index < 0 || stream_index >= ic->nb_streams)
     {
-        GRABGIL
+        if(threaded) GRABGIL
         if(movie->ob_refcnt!=0)
         {
             Py_DECREF(movie);
         }
-        RELEASEGIL
+        if(threaded) RELEASEGIL
         return;
     }
     movie->replay=1;
     }
     ic->streams[stream_index]->discard = AVDISCARD_ALL;
 
-    GRABGIL
+    if(threaded) GRABGIL
     if(movie->ob_refcnt!=0)
     {
         Py_DECREF( movie);
     }
-    RELEASEGIL
+    if(threaded) RELEASEGIL
 }
-void stream_component_close(PyMovie *movie, int stream_index)
+void stream_component_close(PyMovie *movie, int stream_index, int threaded)
 {
     DECLAREGIL
-    GRABGIL
+    if(threaded) GRABGIL
     if(movie->ob_refcnt!=0)
         Py_INCREF( movie);
-    RELEASEGIL
+    if(threaded) RELEASEGIL
     AVFormatContext *ic = movie->ic;
     AVCodecContext *enc;
 
     if (stream_index < 0 || stream_index >= ic->nb_streams)
     {
-        GRABGIL
+        if(threaded) GRABGIL
         if(movie->ob_refcnt!=0)
         {
             Py_DECREF(movie);
         }
-        RELEASEGIL
+        if(threaded) RELEASEGIL
         return;
     }
     enc = ic->streams[stream_index]->codec;
         break;
     }
 
-    GRABGIL
+	if(threaded) GRABGIL
     if(movie->ob_refcnt!=0)
     {
         Py_DECREF( movie);
     }
-    RELEASEGIL
+    if(threaded) RELEASEGIL
 }
 
 void stream_open(PyMovie *movie, const char *filename, AVInputFormat *iformat, int threaded)
     }
     return 0;
 }
-void stream_close(PyMovie *movie)
+void stream_close(PyMovie *movie, int threaded)
 {
     DECLAREGIL
     GRABGIL
                 SDL_FreeSurface(vp->dest_surface);
                 vp->dest_surface=NULL;
             }
+            
         }
         SDL_DestroyMutex(movie->dest_mutex);
         if(movie->img_convert_ctx)
     /* close each stream */
     if (movie->audio_stream >= 0)
     {
-        stream_component_close(movie, movie->audio_stream);
+        stream_component_close(movie, movie->audio_stream, threaded);
     }
     if (movie->video_stream >= 0)
     {
-        stream_component_close(movie, movie->video_stream);
+        stream_component_close(movie, movie->video_stream, threaded);
     }
     if (movie->sub_stream >= 0)
     {
-        stream_component_close(movie, movie->sub_stream);
+        stream_component_close(movie, movie->sub_stream, threaded);
     }
     if (movie->ic)
     {
         }
     }
 the_end:
-    stream_component_close(movie, start_index);
+    stream_component_close(movie, start_index, 1);
     stream_component_open(movie, stream_index, 1);
     GRABGIL
     Py_DECREF(movie);
             stream_component_start(movie, movie->video_stream, 1);
         if(movie->audio_st)
             stream_component_start(movie, movie->audio_stream, 1);
+        if(movie->sub_st)
+        	stream_component_start(movie, movie->sub_stream, 1);
         /* Now we call the function that does the ACTUAL work. Just like us to loaf 
          * around while we make decoder work so hard...
          */
          * electronic tree saved!
          */  
         if(movie->video_st)
-            stream_component_end(movie, movie->video_st->index);
+            stream_component_end(movie, movie->video_st->index, 1);
         if(movie->audio_st)
-            stream_component_end(movie, movie->audio_st->index);
+            stream_component_end(movie, movie->audio_st->index, 1);
+    	if(movie->sub_st)
+    		stream_component_end(movie, movie->sub_st->index, 1);
     }
     GRABGIL
-    Py_INCREF(movie);
+    Py_DECREF(movie);
     RELEASEGIL
     movie->playing=0;
     movie->paused=0;

File src/_gmovie.h

 void stream_pause           (PyMovie *is);
 int  stream_component_open  (PyMovie *is, int stream_index, int threaded); //TODO: break down into separate functions
 int  stream_component_start (PyMovie *is, int stream_index, int threaded);
-void stream_component_end   (PyMovie *is, int stream_index);
-void stream_component_close (PyMovie *is, int stream_index);
+void stream_component_end   (PyMovie *is, int stream_index, int threaded);
+void stream_component_close (PyMovie *is, int stream_index, int threaded);
 int  decoder                (void *arg);
 void stream_open            (PyMovie *is, const char *filename, AVInputFormat *iformat, int threaded);
-void stream_close           (PyMovie *is);
+void stream_close           (PyMovie *is, int threaded);
 void stream_cycle_channel   (PyMovie *is, int codec_type);
 int  decoder_wrapper        (void *arg);
 

File src/_gsound.c

 }
 
 //initialize the mixer audio subsystem, code cribbed from mixer.c
-int soundInit  (int freq, int size, int channels, int chunksize, PyThreadState *_tstate)
+int soundInit  (int freq, int size, int channels, int chunksize)
 {
     Uint16 fmt = 0;
     int i;
     ainfo.mutex = SDL_CreateMutex();
     ainfo.queue.mutex = SDL_CreateMutex();
     ainfo.ended=1;
-    ainfo._tstate = _tstate;
+    //ainfo._tstate = _tstate;
     return 0;
 }
 

File src/_gsound.h

 	int			paused;
     BufferQueue queue;              //queue of our buffers
     SDL_mutex   *mutex;
-	PyThreadState *_tstate;
+	//PyThreadState *_tstate;
 	int restart;
 }
 AudioInfo;
 
 AudioInfo ainfo;
 
-int soundInit     (int freq, int size, int channels, int chunksize, PyThreadState *_tstate);
+int soundInit     (int freq, int size, int channels, int chunksize);
 int soundQuit     (void);
 int soundStart    (void);
 int soundEnd      (void);

File src/gmovie.c

 
 void _movie_dealloc(PyMovie *movie)
 {
-    stream_close(movie);
+	PySys_WriteStdout("Deleting\n");
+	if(movie->_tstate)
+	{
+		PyThreadState_Clear(movie->_tstate);
+		//PyThreadState_Delete(movie->_tstate);
+	}
+	if(!movie->stop)
+		movie=(PyMovie *)_movie_stop(movie);
+	stream_close(movie, 0);
     movie->ob_type->tp_free((PyObject *) movie);
 }
 
     char buf2[50];
     PyOS_snprintf(buf, sizeof(buf), "(Movie: %s, %s)", movie->filename, format_timestamp(movie->pts, buf2));
     PyObject *buffer = PyString_FromString(buf);
+    Py_DECREF(movie);
     return buffer;
 }
 PyObject* _movie_play(PyMovie *movie, PyObject* args)
         }
         //indicating we've called play again before its finished
     }
-    else
+    else if(movie->_tstate==NULL)
     {
         PyInterpreterState *interp;
         PyThreadState *thread;
     	//first we release the GIL, then we release all the resources associated with the streams, if they exist.
     	PyEval_ReleaseLock();
         if(movie->video_st)
-            stream_component_end(movie, movie->video_st->index);
+            stream_component_end(movie, movie->video_st->index, 0);
         if(movie->audio_st)
-            stream_component_end(movie, movie->audio_st->index);
+            stream_component_end(movie, movie->audio_st->index, 0);
         PyEval_AcquireLock();
         movie->stop = 0;
     }