Commits

Anonymous committed 024b565

Intermittent work on sound

Comments (0)

Files changed (2)

         	/* Buffer is filled up with a new frame, we spin lock/wait for a signal, where we then call playBuffer */
         	SDL_LockMutex(movie->audio_mutex);
         	//SDL_CondWait(movie->audio_sig, movie->audio_mutex);
-        	playBuffer(movie->audio_buf1, len1);
+        	playBuffer(movie->audio_buf1, data_size);
         	filled=0;
         	len1=0;
         	SDL_UnlockMutex(movie->audio_mutex);
         
         freq = enc->sample_rate;
         channels = enc->channels;
-        if (soundInit  (freq, (int)NULL, channels, 1024, movie->audio_sig) < 0) {
+        if (soundInit  (freq, -16, channels, 1024, NULL) < 0) {
             RAISE(PyExc_SDLError, SDL_GetError ());
         }
         movie->audio_hw_buf_size = 1024;
     }
 
     /* open the streams */
-    /*if (audio_index >= 0) {
+    if (audio_index >= 0) {
 		stream_component_open(is, audio_index);
-   	}*/
+   	}
 	
     if (video_index >= 0) {
     	stream_component_open(is, video_index);
             (is->videoq.size > MAX_VIDEOQ_SIZE )||
             (is->subtitleq.size > MAX_SUBTITLEQ_SIZE)) {
             /* wait 10 ms */
+            if(is->video_st)
+            	video_render(is);
+            if(is->audio_st)
+	            audio_thread(is);
             SDL_Delay(10);
             continue;
         }
 	                break;
 	            }
 	        }
-	        /*if (pkt->stream_index == is->audio_stream) {
+	        if (pkt->stream_index == is->audio_stream) {
 	            packet_queue_put(&is->audioq, pkt);
-	        } else*/ if (pkt->stream_index == is->video_stream) {
+	        } else if (pkt->stream_index == is->video_stream) {
 	            packet_queue_put(&is->videoq, pkt);
 	        //} else if (pkt->stream_index == is->subtitle_stream) {
 	        //    packet_queue_put(&is->subtitleq, pkt);
 	            av_free_packet(pkt);
 	        }
 		}
-		if(is->video_st)
-	        video_render(is);
-        //audio_thread(is);
+        if(is->video_st)
+        	video_render(is);
+        if(is->audio_st)
+            audio_thread(is);
         if(co<2)
         	video_refresh_timer(is);
         if(is->timing>0) {
 #define _MIXER_DEFAULT_CHUNKSIZE 4096
 
 SDL_cond *audio_sig;
-BufferQueue *queue;
+BufferQueue queue;
 int playing =0;
 int queue_get(BufferQueue *q, BufferNode *node)
 {
 	{
 		SDL_CondSignal(audio_sig);
 	}
-	if(!queue)
-	{
-		queue = (BufferQueue *)PyMem_Malloc(sizeof(BufferQueue));
-		queue->size=0;
-		queue->first=queue->last=NULL;	
-	}
+	
+	queue.size=0;
+	queue.first=queue.last=NULL;	
     return 0;
 }
 
 int playBuffer (uint8_t *buf, uint32_t len)
 {
 	Mix_Chunk *mix;
-	if(queue->size>0)
+	uint8_t *newbuf;
+	if(queue.size>0)
 	{
 		if(buf)
 		{
 			memcpy(&node->buf, &buf, (size_t)len);
 			node->len = len;
 			node->next =NULL;
-			queue_put(&queue, &node);
+			queue_put(&queue, node);
 		}
 		BufferNode *new;
-		queue_get(&queue, &new);
-		memcpy(&buf, &new->buf, new->len);
+		queue_get(&queue, new);
+		newbuf = (uint8_t *)PyMem_Malloc((size_t)new->len);
+		memcpy(&newbuf, &new->buf, new->len);
 		len=new->len;
 		PyMem_Free(&new->buf);
 		PyMem_Free(&new);
 			memcpy(&node->buf, &buf, (size_t)len);
 			node->len = len;
 			node->next =NULL;
-			queue_put(&queue, &node);
+			queue_put(&queue, node);
 		}
 		return 0;
 	}
 	mix= (Mix_Chunk *)PyMem_Malloc(sizeof(Mix_Chunk));
 	mix->allocated=1;
-	if(queue->size==0)
+	if(queue.size==0)
 	{
 		mix->abuf = (Uint8 *)PyMem_Malloc((size_t)len);
-		memcpy(&mix->abuf, &buf, len);
+		if(newbuf)
+			memcpy(&mix->abuf, &newbuf, len);
+		else
+			memcpy(&mix->abuf, &buf, len);
 	}
 	else
 	{