[MPlayer-dev-eng] Too big buffer in "libmpcodecs/ad_pcm.c"?

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Wed Aug 9 18:26:05 CEST 2006


Hello,
On Wed, Aug 09, 2006 at 02:30:58PM +0300, Uoti Urpala wrote:
> I think it would make sense to base the amount to decode on minlen and
> only have an explicit sanity check based on maxlen. Using minlen as the
> amount to decode is generally better; maxlen is just set to the maximum
> buffer space and might require demuxing the file unnecessarily far
> ahead.

Right, I misread the code in mplayer.c, this seems more like the way it
was intended.
How does the attached (untested) patch look to you?

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/ad_pcm.c
===================================================================
--- libmpcodecs/ad_pcm.c	(revision 19360)
+++ libmpcodecs/ad_pcm.c	(working copy)
@@ -119,8 +119,12 @@
 
 static int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen)
 {
-  unsigned len = sh_audio->channels*sh_audio->samplesize;
-  len = maxlen - maxlen % len; // sample align
+  unsigned align = sh_audio->channels*sh_audio->samplesize;
+  // sample align
+  unsigned len = minlen + align - 1;
+  len -= len % align;
+  if (len > maxlen)
+    len = maxlen - maxlen % align;
   len=demux_read_data(sh_audio->ds,buf,len);
   return len;
 }


More information about the MPlayer-dev-eng mailing list