[Mplayer-cvslog] CVS: main dec_audio.c,1.78,1.79

Arpi of Ize arpi at mplayer.dev.hu
Thu Jan 17 02:11:23 CET 2002


Update of /cvsroot/mplayer/main
In directory mplayer:/var/tmp.root/cvs-serv3049

Modified Files:
	dec_audio.c 
Log Message:
libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere at acunia.com>

Index: dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/dec_audio.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -r1.78 -r1.79
--- dec_audio.c	14 Jan 2002 16:27:55 -0000	1.78
+++ dec_audio.c	17 Jan 2002 01:11:21 -0000	1.79
@@ -101,9 +101,14 @@
 
 #ifdef USE_LIBMAD
 #include <mad.h>
+
+#define MAD_SINGLE_BUFFER_SIZE 8192
+#define MAD_TOTAL_BUFFER_SIZE  ((MAD_SINGLE_BUFFER_SIZE)*3)
+
 static struct mad_stream mad_stream;
 static struct mad_frame  mad_frame;
 static struct mad_synth  mad_synth;
+static char*  mad_in_buffer = 0; /* base pointer of buffer */
 
 // ensure buffer is filled with some data
 static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length)
@@ -117,14 +122,19 @@
 
 static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms)
 {
+  /* rotate buffer while possible, in order to reduce the overhead of endless memcpy */
   int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer;
-  if(delta != 0) {
+  if((unsigned long)(sh_audio->a_in_buffer) - (unsigned long)mad_in_buffer < 
+     (MAD_TOTAL_BUFFER_SIZE - MAD_SINGLE_BUFFER_SIZE - delta)) {
+    sh_audio->a_in_buffer += delta;
+    sh_audio->a_in_buffer_len -= delta;
+  } else {
+    sh_audio->a_in_buffer = mad_in_buffer;
     sh_audio->a_in_buffer_len -= delta;
     memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len);
   }
 }
 
-
 static inline
 signed short mad_scale(mad_fixed_t sample)
 {
@@ -449,9 +459,9 @@
  case AFM_MAD:
    printf(__FILE__ ":%d:mad: setting minimum outputsize\n", __LINE__);
    sh_audio->audio_out_minsize=4608;
-   if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192;
+   if(sh_audio->audio_in_minsize<MAD_SINGLE_BUFFER_SIZE) sh_audio->audio_in_minsize=MAD_SINGLE_BUFFER_SIZE;
    sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize;
-   sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size);
+   mad_in_buffer = sh_audio->a_in_buffer = malloc(MAD_TOTAL_BUFFER_SIZE);
    sh_audio->a_in_buffer_len=0;
    break;
 #endif




More information about the MPlayer-cvslog mailing list