Commits

Anonymous committed 7386f74

Trying to find why looping causes crashes... yet again.

Comments (0)

Files changed (4)

 
 print "Please give an (absolute)filename of a movie file you'd like to play: ",
 #filename = raw_input()
-filename="/home/tyler/dhs1.avi"
+filename="/home/tyler/War3.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.
 print m         #calls __repr__, which will show the filename, and the current 
                 # timestamp. 
 #print "repeated looping plays.."
-#m.play(10)
-#time.sleep(10*30)
+m.play(10)
+time.sleep(10*30)
 
 
 print "Playing infinitely"
 print m.playing
 time.sleep(20)
 #Here is the stop function. Right now, rewind is the exact same as stop.
-print "Stopping..."
+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((m.width, m.height))
     AVFormatContext *ic = movie->ic;
     AVCodecContext *enc;
 
-    ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
+    //ic->streams[stream_index]->discard = AVDISCARD_DEFAULT;
 
     if (stream_index < 0 || stream_index >= ic->nb_streams)
     {
         soundEnd();
         memset(&movie->audio_buf1, 0, sizeof(movie->audio_buf1));
         movie->replay=1;
+        packet_queue_flush(&movie->audioq);
         break;
     case CODEC_TYPE_VIDEO:
         for(i=0;i<VIDEO_PICTURE_QUEUE_SIZE;i++)
         }
         movie->replay = 1;
         packet_queue_abort(&movie->videoq);
+        packet_queue_flush(&movie->videoq);
         break;
     default:
         break;
         movie->paused=0;
         if(movie->replay)
             initialize_context(movie, 1);
+        GRABGIL
+        PySys_WriteStdout("Video Stream: %i\nAudio Stream: %i\n", movie->video_stream, movie->audio_stream);
+        RELEASEGIL
         if(movie->video_st)
-            stream_component_start(movie, movie->video_st->index, 1);
+            stream_component_start(movie, movie->video_stream, 1);
         if(movie->audio_st)
-            stream_component_start(movie, movie->audio_st->index, 1);
+            stream_component_start(movie, movie->audio_stream, 1);
+        GRABGIL
+        PySys_WriteStdout("Video Stream: %i\nAudio Stream: %i\n", movie->video_stream, movie->audio_stream);
+        RELEASEGIL
         state =decoder(movie);
         if(movie->video_st)
             stream_component_end(movie, movie->video_st->index);
     for(;;)
     {
         co++;
-
+		GRABGIL
+		PySys_WriteStdout("Counter: %i\n", co);
+		RELEASEGIL
         if (movie->abort_request)
         {
             break;
     ainfo.ended=0;
     ainfo.audio_clock =0.0;
     ainfo.playing=0;
+    ainfo.channel=0;
     ainfo.current_frame_size=1;
     //playBuffer(NULL, 0, 0, 0);
     return 0;
 int soundEnd   (void)
 {
     ainfo.ended = 1;
+    queue_flush(&ainfo.queue);
     return 0;
 }
 
     mix->alen = (Uint32 )len;
     mix->volume = 127;
     ainfo.playing = 1;
- 	if(!ainfo.paused)
+ 	if(!ainfo.ended)
 	{
     	int bytes_per_sec = ainfo.channels*ainfo.sample_rate*2;
     	ainfo.audio_clock+= (double) len/(double) bytes_per_sec;
 	}
     ainfo.current_frame_size =len;
-    int ret = Mix_PlayChannel(ainfo.channel, mix, 0);
+    int chan = ainfo.channel;
+    int ret = Mix_PlayChannel(chan, mix, 0);
     ainfo.channel = ret;
     //if buffer was allocated, we gotta clean it up.
     if(allocated)
     int paused = Mix_Paused(channel);
     if(paused)
     {
-    	ainfo.paused=0;
+    	ainfo.ended=0;
         Mix_Resume(-1);
     }
     else
     {
-    	ainfo.paused=1;
+    	ainfo.ended=1;
         Mix_Pause(-1);
     }
     return 0;
     }
     self->start_time = AV_NOPTS_VALUE;
     stream_open(self, filename, NULL, 0);
-    PySys_WriteStdout("Time-base-a: %f\n", av_q2d(self->audio_st->codec->time_base));
+    //PySys_WriteStdout("Time-base-a: %f\n", av_q2d(self->audio_st->codec->time_base));
     if(!self)
     {
         PyErr_SetString(PyExc_IOError, "stream_open failed");