Commits

Anonymous committed 176569d

Fixed crashes on loops.

  • Participants
  • Parent commits bc27074
  • Branches tylerthemovie

Comments (0)

Files changed (2)

     int filled =0;
     len1=0;
     int co = 0;
-    if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("Before loop\n");
-        	RELEASEGIL
-        }
     for(;co<2;co++)
     {
         if      (!movie->paused && movie->audio_paused)
             stopBuffer(movie->channel);
             goto closing;
         }
-        if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("after pause and stop checks...\n");
-        	RELEASEGIL
-        }
         //fill up the buffer
         while(movie->audio_pkt_size > 0)
         {
-        	if(movie->replay)
-	        {
-	        	GRABGIL
-	        	PySys_WriteStdout("inside while loop\n");
-	        	RELEASEGIL
-	        }
             data_size = sizeof(movie->audio_buf1);
             len1 += avcodec_decode_audio2(dec, (int16_t *)movie->audio_buf1, &data_size, movie->audio_pkt_data, movie->audio_pkt_size);
             if (len1 < 0)
             filled=1;
 
         }
-        if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("after while loop\n");
-        	RELEASEGIL
-        }
 		if(filled)
         {
             /* Buffer is filled up with a new frame, we spin lock/wait for a signal, where we then call playBuffer */
-            if(movie->replay)
-	        {
-	        	GRABGIL
-	        	PySys_WriteStdout("inside filled\n");
-	        	RELEASEGIL
-	        }
             SDL_LockMutex(movie->audio_mutex);
             //SDL_CondWait(movie->audio_sig, movie->audio_mutex);
-            int channel = ainfo.channel;
-            if(movie->replay)
-	        {
-	        	GRABGIL
-	        	PySys_WriteStdout("before playBuffer... %i\n", movie->channel);
-	        	RELEASEGIL
-	        }
 	        SDL_UnlockMutex(movie->audio_mutex);
             int chan = playBuffer(movie->audio_buf1, data_size, movie->channel, movie->audio_pts);
 			SDL_LockMutex(movie->audio_mutex);
 				PySys_WriteStdout("%s\n", Mix_GetError());
 				RELEASEGIL	
 			}
-			if(movie->replay)
-	        {
-	        	GRABGIL
-	        	PySys_WriteStdout("after playBuffer... %i\n", channel);
-	        	RELEASEGIL
-	        }
             movie->channel = chan;
             filled=0;
             len1=0;
             SDL_UnlockMutex(movie->audio_mutex);
-            if(movie->replay)
-	        {
-	        	GRABGIL
-	        	PySys_WriteStdout("after playBuffer... %i\n", chan);
-	        	RELEASEGIL
-	        }
             goto closing;
         }
 		
         movie->audio_pkt_data = pkt->data;
         movie->audio_pkt_size = pkt->size;
 
-		if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("after packet load...\n");
-        	RELEASEGIL
-        }
     }
 closing:
     GRABGIL
                 av_free_packet(pkt);
             }
         }
-        if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("Before Video Render\n");
-        	RELEASEGIL
-        }
         if(movie->video_st)
             video_render(movie);
-        if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("After Video Render\n");
-        	RELEASEGIL
-        }
-        if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("Before audio Render\n");
-        	RELEASEGIL
-        }
         if(movie->audio_st)
             audio_thread(movie);
-       	if(movie->replay)
-        {
-        	GRABGIL
-        	PySys_WriteStdout("after audio Render\n");
-        	RELEASEGIL
-        }
         if(co<2)
             video_refresh_timer(movie);
         if(movie->timing>0)
 {
 	
 	//temp
-	PyThreadState *_oldtstate;
 	AudioInfo *info = &ainfo;
 	
-	
 	if(channel>info->channels-1)
 	{
 		channel=0;
 	{
 		info->channel=0;
 	}
-	
+	//SDL_mutexP(info->mutex);
     Mix_Chunk *mix;
-    //SDL_mutexP(info->mutex);
-    
+    int false=0;
     int allocated=0;
-    if(info->restart && len==0)
-	{
-		//PySys_WriteStdout("blah\n");
-	}
     
     if(!info->ended && (info->queue.size>0||info->playing))
     {
-    	if(info->restart && len==0)
-		{
-			//PySys_WriteStdout("blah\n");
-		}
-    	
         if(buf)
         {   
-        	
-        	if(info->restart && len==0)
-			{
-				PySys_WriteStdout("blah\n");
-			}
         	//not a callback call, so we copy the buffer into a buffernode and add it to the queue.
             BufferNode *node;
             node = (BufferNode *)PyMem_Malloc(sizeof(BufferNode));
             node->pts = pts;
             queue_put(&ainfo.queue, node);
             //SDL_mutexV(info->mutex);
-            if(info->restart && len==0)
-			{
-				PySys_WriteStdout("blah\n");
-			}
             return info->channel;
         }
         else if(!buf && info->queue.size==0)
         {  
             
-            
             //callback call but when the queue is empty, so we just load a short empty sound.
-            buf = (uint8_t *) PyMem_Malloc((size_t)128);
-            
-            memset(buf, 0, (size_t)128);
-            
+            buf = (uint8_t *) PyMem_Malloc((size_t)1024);
+            memset(buf, 0, (size_t)1024);
             info->current_frame_size=1;
-            
-            len=128;
-            
+            len=1024;
             allocated =1;
-        	if(info->restart && len==128)
-			{
-				PySys_WriteStdout("blah\n");
-			}
-        	
+        	false=1;
         }
         else
         {
-        	if(info->restart && len==0)
-			{
-				PySys_WriteStdout("blah\n");
-			}
             //callback call, and convenienty enough, the queue has a buffer ready to go, so we copy it into buf
             BufferNode *new;
             queue_get(&ainfo.queue, &new);
     if(info->ended && !buf)
     {
         //callback call but when the queue is empty, so we just load a short empty sound.
-        buf = (uint8_t *) PyMem_Malloc((size_t)128);
-        memset(buf, 0, (size_t)128);
+        buf = (uint8_t *) PyMem_Malloc((size_t)1024);
+        memset(buf, 0, (size_t)1024);
         info->current_frame_size=1;
-        len=128;
+        len=1024;
         allocated =1;
+        false=1;
     }
     
     //regardless of 1st call, or a callback, we load the data from buf into a newly allocated block.
     mix= (Mix_Chunk *)PyMem_Malloc(sizeof(Mix_Chunk));
-   
     mix->allocated=0;
-    
 	mix->abuf = (Uint8 *)PyMem_Malloc((size_t)len);
-    
     memcpy(mix->abuf, buf, len);
-    
-    
     mix->alen = (Uint32 )len;
     mix->volume = 127;
     ainfo.playing = 1;
+    if(mix->alen==0)
+    {
+    	PySys_WriteStdout("hahahah");	
+    }
  	if(!ainfo.ended)
 	{
     	int bytes_per_sec = ainfo.channels*ainfo.sample_rate*2;
     
     char s[1024];
     char *s2;
+    int playing = Mix_Playing(chan);
+    if(playing && allocated &&false)
+    {
+    	return chan;
+    }
     int ret = Mix_PlayChannel(chan, mix, 0);
     if(ret==-1)
     {
     		s[i]=*s2;
     		s2++;
     	}
-    	PySys_WriteStdout("causing an error...\n");
+    	PySys_WriteStdout(s2);
     }
     ainfo.channel = ret;
     //if buffer was allocated, we gotta clean it up.