Commits

Anonymous committed bc27074

Error is either an unpredicted code-path, or somehow a length of zero...
mix->alen==0 causes the error.

  • Participants
  • Parent commits f75b7bb
  • Branches tylerthemovie

Comments (0)

Files changed (4)

 class DebugDependency(Dependency):
     def __init__(self, name, checkhead, checklib, libs):
         Dependency.__init__(self, name, checkhead, checklib, libs)
-        self.cflags=""
+        self.cflags="-Xcompiler -O0"
 
 class DependencyPython:
     def __init__(self, name, module, header):
     int filled =0;
     len1=0;
     int co = 0;
-    int state = 0;
+    if(movie->replay)
+        {
+        	GRABGIL
+        	PySys_WriteStdout("Before loop\n");
+        	RELEASEGIL
+        }
     for(;co<2;co++)
     {
-    	state=0;
         if      (!movie->paused && movie->audio_paused)
         {
             pauseBuffer(movie->channel);
             movie->audio_paused = 1;
             goto closing;
         }
-        state|=1;
        
         //check if the movie has ended
         if(movie->stop)
             stopBuffer(movie->channel);
             goto closing;
         }
-        state |=2;
-       
+        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;
 
         }
-        state |= 4;
-       
+        if(movie->replay)
+        {
+        	GRABGIL
+        	PySys_WriteStdout("after while loop\n");
+        	RELEASEGIL
+        }
 		if(filled)
         {
-            //GRABGIL
-            //PySys_WriteStdout("movie->audio_pts: %i\n", (int)movie->audio_pts);
-            //RELEASEGIL
             /* 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);
-            /*if(movie->replay)
-	    	{
+            //SDL_CondWait(movie->audio_sig, movie->audio_mutex);
+            int channel = ainfo.channel;
+            if(movie->replay)
+	        {
 	        	GRABGIL
-	        	PySys_WriteStdout("Preprint\n");
-	        	PySys_WriteStdout("Data_Size: %i\tChannel %i\tPTS: %i\n", data_size, movie->channel, (int)movie->audio_pts);
-	    		RELEASEGIL
-	    	}*/
-            //SDL_CondWait(movie->audio_sig, movie->audio_mutex);
+	        	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);
-            if(movie->replay)
-	    	{
+			SDL_LockMutex(movie->audio_mutex);
+			if(chan==-1)
+			{
+				GRABGIL
+				PySys_WriteStdout("%s\n", Mix_GetError());
+				RELEASEGIL	
+			}
+			if(movie->replay)
+	        {
 	        	GRABGIL
-	        	PySys_WriteStdout("State-K: %i\n", state);
-	    		RELEASEGIL
-	    	}
+	        	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;
         }
-		state|=8;
 		
         //either buffer filled or no packets yet
         /* free the current packet */
         if (pkt->data)
             av_free_packet(pkt);
-		state|=16;
 		
         /* read next packet */
         if (packet_queue_get(&movie->audioq, pkt, 1) <= 0)
         {
             goto closing;
         }
-        state|=32;
         
         if(pkt->data == flush_pkt.data)
         {
             avcodec_flush_buffers(dec);
             goto closing;
         }
-        state|=64;
       
         movie->audio_pts      = pkt->pts;
         movie->audio_pkt_data = pkt->data;
         movie->audio_pkt_size = pkt->size;
-		state |=128;
 
-
+		if(movie->replay)
+        {
+        	GRABGIL
+        	PySys_WriteStdout("after packet load...\n");
+        	RELEASEGIL
+        }
     }
 closing:
     GRABGIL
     Py_DECREF(movie);
     RELEASEGIL
-    if(movie->replay)
-    	{
-        	GRABGIL
-        	PySys_WriteStdout("StateF: %i\n", state);
-    		RELEASEGIL
-    	}
     return 0;
 }
 
         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_stream, 1);
         if(movie->audio_st)
             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);
         {
             break;
         }
-        state |= 1;
         if(movie->stop)
         {
             break;
         }
-		state |= 2;
         if (movie->paused != movie->last_paused)
         {
             movie->last_paused = movie->paused;
                 av_read_play(ic);
             }
         }
-        state |=4;
         if(movie->paused)
         {
             SDL_Delay(10);
             continue;
         }
-        state|=8;
         if (movie->seek_req)
         {
             int stream_index= -1;
             }
             movie->seek_req = 0;
         }
-        state|=16;
         /* if the queue are full, no need to read more */
         if ((movie->audioq.size > MAX_AUDIOQ_SIZE) || //yay for short circuit logic testing
                 (movie->videoq.size > MAX_VIDEOQ_SIZE ))
             continue;
         }
         
-        state|=32;
         if(url_feof(ic->pb))
         {
             av_init_packet(pkt);
             packet_queue_put(&movie->videoq, pkt);
             continue;
         }
-        state|=64;
         if(movie->pictq_size<VIDEO_PICTURE_QUEUE_SIZE)
         {
             ret = av_read_frame(ic, pkt);
                 av_free_packet(pkt);
             }
         }
-		state|=128;
+        if(movie->replay)
+        {
+        	GRABGIL
+        	PySys_WriteStdout("Before Video Render\n");
+        	RELEASEGIL
+        }
         if(movie->video_st)
             video_render(movie);
-        state |= 256;
+        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);
-        state |= 512;
-        if(movie->replay)
-    	{
+       	if(movie->replay)
+        {
         	GRABGIL
-        	PySys_WriteStdout("State: %i\n", state);
-    		RELEASEGIL
-    	}
+        	PySys_WriteStdout("after audio Render\n");
+        	RELEASEGIL
+        }
         if(co<2)
             video_refresh_timer(movie);
         if(movie->timing>0)
                 }
             }
         }
-        state |= 1024;
-        if(movie->replay)
-    	{
-        	GRABGIL
-        	PySys_WriteStdout("State: %i\n", state);
-    		RELEASEGIL
-    	}
     	
     }
 
 #define _MIXER_DEFAULT_CHANNELS 2
 #define _MIXER_DEFAULT_CHUNKSIZE 4096
 
-AudioInfo ainfo;
+
 
 int queue_get(BufferQueue *q, BufferNode **pkt1)
 {
 /* Play a sound buffer, with a given length */
 int playBuffer (uint8_t *buf, uint32_t len, int channel, int64_t pts)
 {
+	
 	//temp
 	PyThreadState *_oldtstate;
+	AudioInfo *info = &ainfo;
+	
+	
+	if(channel>info->channels-1)
+	{
+		channel=0;
+	}
+	if(info->channel<0 || info->channel >info->channels-1)
+	{
+		info->channel=0;
+	}
+	
     Mix_Chunk *mix;
-    //temp
-    if(ainfo.restart)
+    //SDL_mutexP(info->mutex);
+    
+    int allocated=0;
+    if(info->restart && len==0)
+	{
+		//PySys_WriteStdout("blah\n");
+	}
+    
+    if(!info->ended && (info->queue.size>0||info->playing))
     {
-    	PyEval_AcquireLock();_oldtstate = PyThreadState_Swap(ainfo._tstate);
-    	//PySys_WriteStdout("Inside playBuffer\n");
-    	PyThreadState_Swap(_oldtstate); PyEval_ReleaseLock();
-    }
-    SDL_mutexP(ainfo.mutex);
-    int allocated=0;
-    if(!ainfo.ended && (ainfo.queue.size>0||ainfo.playing))
-    {
+    	if(info->restart && len==0)
+		{
+			//PySys_WriteStdout("blah\n");
+		}
+    	
         if(buf)
-        {
-        	if(ainfo.restart)
-		    {
-		    	PyEval_AcquireLock();_oldtstate = PyThreadState_Swap(ainfo._tstate);
-		    	PySys_WriteStdout("Inside queue>0 and a buffer exists\n");
-		    	PyThreadState_Swap(_oldtstate); PyEval_ReleaseLock();
-		    }
-            //not a callback call, so we copy the buffer into a buffernode and add it to the queue.
+        {   
+        	
+        	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->buf = (uint8_t *)PyMem_Malloc((size_t)len);
             node->next =NULL;
             node->pts = pts;
             queue_put(&ainfo.queue, node);
-            SDL_mutexV(ainfo.mutex);
-            if(ainfo.restart)
-		    {
-		    	PyEval_AcquireLock();_oldtstate = PyThreadState_Swap(ainfo._tstate);
-		    	PySys_WriteStdout("returning from queue>0 and a buffer exists\n");
-		    	PyThreadState_Swap(_oldtstate); PyEval_ReleaseLock();
-		    }
-            return ainfo.channel;
+            //SDL_mutexV(info->mutex);
+            if(info->restart && len==0)
+			{
+				PySys_WriteStdout("blah\n");
+			}
+            return info->channel;
         }
-        else if(!buf && ainfo.queue.size==0)
-        {
+        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);
-            ainfo.current_frame_size=1;
+            
+            info->current_frame_size=1;
+            
             len=128;
+            
             allocated =1;
+        	if(info->restart && len==128)
+			{
+				PySys_WriteStdout("blah\n");
+			}
+        	
         }
         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(!new)
             {
-                SDL_mutexV(ainfo.mutex);
+                //SDL_mutexV(info->mutex);
                 return -1;
             }
-            ainfo.current_frame_size=new->len;
+            info->current_frame_size=new->len;
             /*if (new->pts != AV_NOPTS_VALUE)
             {
                 ainfo.audio_clock = (1.0/(double)ainfo.sample_rate) *new->pts;
             allocated=1;
         }
     }
+    
     //we assume that if stopped is true, then
-    if(ainfo.ended)
+    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);
-        ainfo.current_frame_size=1;
+        info->current_frame_size=1;
         len=128;
         allocated =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);
+    
+	mix->abuf = (Uint8 *)PyMem_Malloc((size_t)len);
+    
     memcpy(mix->abuf, buf, len);
+    
+    
     mix->alen = (Uint32 )len;
     mix->volume = 127;
     ainfo.playing = 1;
 	}
     ainfo.current_frame_size =len;
     int chan = ainfo.channel;
+    
+    //SDL_mutexV(ainfo.mutex);
+    
+    char s[1024];
+    char *s2;
     int ret = Mix_PlayChannel(chan, mix, 0);
+    if(ret==-1)
+    {
+    	s2 = Mix_GetError();
+    	int i;
+    	for(i=0;i<1024;i++)
+    	{
+    		s[i]=*s2;
+    		s2++;
+    	}
+    	PySys_WriteStdout("causing an error...\n");
+    }
     ainfo.channel = ret;
     //if buffer was allocated, we gotta clean it up.
     if(allocated)
     {
         PyMem_Free(buf);
     }
-    SDL_mutexV(ainfo.mutex);
     return ret;
 }
 int stopBuffer (int channel)
 }
 AudioInfo;
 
+AudioInfo ainfo;
+
 int soundInit     (int freq, int size, int channels, int chunksize, PyThreadState *_tstate);
 int soundQuit     (void);
 int soundStart    (void);