[MPlayer-cvslog] CVS: main/libmpdemux muxer_mpeg.c,1.58,1.59

Nico Sabbi CVS syncmail at mplayerhq.hu
Mon Apr 24 11:48:59 CEST 2006


CVS change done by Nico Sabbi CVS

Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var2/tmp/cvs-serv1096

Modified Files:
	muxer_mpeg.c 
Log Message:
simplified parse_audio()

Index: muxer_mpeg.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/muxer_mpeg.c,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- muxer_mpeg.c	22 Apr 2006 18:15:23 -0000	1.58
+++ muxer_mpeg.c	24 Apr 2006 09:48:57 -0000	1.59
@@ -2046,57 +2046,50 @@
 static int parse_audio(muxer_stream_t *s, int finalize, unsigned int *nf, double *timer, double delay, int drop)
 {
 	int i, j, len, chans, srate, spf, layer, dummy, tot, num, frm_idx;
+	int finished;
 	unsigned int frames;
 	uint64_t idur;
 	double dur;
 	muxer_headers_t *spriv = (muxer_headers_t *) s->priv;
 
 	i = tot = frames = 0;
-	switch(s->wf->wFormatTag)
+	finished = 0;
+	while(1)
 	{
+		len = 0;
+		switch(s->wf->wFormatTag)
+		{
 		case AUDIO_MP2:
 		case AUDIO_MP3:
-		{
-			while(i + 3 < s->b_buffer_len)
 			{
+				if(i + 3 >= s->b_buffer_len)
+				{
+					finished = 1;
+					break;
+				}
+			
 				if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xE0) == 0xE0))
 				{
 					len = mp_get_mp3_header(&(s->b_buffer[i]), &chans, &srate, &spf, &layer, NULL);
 					if(len > 0 && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
 					{
 						dur = (double) spf / (double) srate;
-						spriv->timer += dur;
-						if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
-						{
-							i += len;
-							tot = i;
-							continue;
-						}
-						frames++;
-						fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
-
 						idur = (27000000ULL * spf) / srate;
-						frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
-						if(frm_idx < 0)
-							continue;
-						for(j = frm_idx; j < spriv->framebuf_cnt; j++)
-							spriv->framebuf[j].pts = spriv->last_pts;
-						spriv->last_pts += idur;
-
-						i += len;
-						tot = i;
-						continue;
 					}
+					else
+						len = 0;
 				}
-				i++;
 			}
-		}
 		break;
 
 		case AUDIO_A52:
-		{
-			while(i + 6 < s->b_buffer_len)
 			{
+				if(i + 6 >= s->b_buffer_len)
+				{
+					finished = 1;
+					break;
+				}
+	
 				if(s->b_buffer[i] == 0x0B && s->b_buffer[i+1] == 0x77)
 				{
 					srate = 0;
@@ -2108,73 +2101,71 @@
 					if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
 					{
 						dur = (double) 1536 / (double) srate;
-						spriv->timer += dur;
-						if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
-						{
-							i += len;
-							tot = i;
-							continue;
-						}
-						frames++;
-						fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
-
 						idur = (27000000ULL * 1536) / srate;
-						frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
-						if(frm_idx < 0)
-							continue;
-						for(j = frm_idx; j < spriv->framebuf_cnt; j++)
-							spriv->framebuf[j].pts = spriv->last_pts;
-						spriv->last_pts += idur;
-
-						i += len;
-						tot = i;
-						continue;
 					}
+					else
+						len = 0;
 				}
-				i++;
 			}
-		}
 		break;
 
 		case AUDIO_AAC1:
 		case AUDIO_AAC2:
-		{
-			while(i + 7 < s->b_buffer_len)
 			{
+				if(i + 7 >= s->b_buffer_len)
+				{
+					finished = 1;
+					break;
+				}
+	
 				if(s->b_buffer[i] == 0xFF && ((s->b_buffer[i+1] & 0xF6) == 0xF0))
 				{
 					len = aac_parse_frame(&(s->b_buffer[i]), &srate, &num);
 					if((len > 0) && (srate == s->wf->nSamplesPerSec) && (i + len <= s->b_buffer_len))
 					{
 						dur = (double) 1024 / (double) srate;
-						spriv->timer += dur;
-						if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
-						{
-							i += len;
-							tot = i;
-							continue;
-						}
-						frames++;
-						fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
-
 						idur = (27000000ULL * 1024 * num) / srate;
-						frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
-						if(frm_idx < 0)
-							continue;
-						for(j = frm_idx; j < spriv->framebuf_cnt; j++)
-							spriv->framebuf[j].pts = spriv->last_pts;
-						spriv->last_pts += idur;
-
-						i += len;
-						tot = i;
-						continue;
 					}
+					else
+						len = 0;
 				}
-				i++;
 			}
 		}
+
+		if(finished)
+			break;
+
+		if(!len)
+		{
+			i++;
+			continue;
+		}
+		
+		spriv->timer += dur;
+		if(spriv->drop_delayed_frames && delay < 0 && spriv->timer <= -delay)
+		{
+			i += len;
+			tot = i;
+			continue;
+		}
+
+		frames++;
+		fill_last_frame(spriv, &(s->b_buffer[tot]), i - tot);
+		frm_idx = add_frame(spriv, idur, &(s->b_buffer[i]), len, 0, spriv->last_pts, spriv->last_pts);
+		if(frm_idx < 0)
+		{
+			mp_msg(MSGT_MUXER, MSGL_FATAL, "Couldn't add audio frame buffer(frame), abort\n");
+			goto audio_exit;
+		}
+		for(j = frm_idx; j < spriv->framebuf_cnt; j++)
+			spriv->framebuf[j].pts = spriv->last_pts;
+		spriv->last_pts += idur;
+
+		i += len;
+		tot = i;
 	}
 
+audio_exit:
 	if(tot)
 	{
 		memmove(s->b_buffer, &(s->b_buffer[tot]), s->b_buffer_len - tot);




More information about the MPlayer-cvslog mailing list