[MPlayer-dev-eng] [PATCH] simplify decode_audio function

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sun Nov 4 12:06:12 CET 2007


Hello,
I think attached patch makes it quite a bit simpler, at least it gets
rid of an inner loop with exactly the same conditions as the outer loop.
It should also make more proper EOF/error handling simpler due to having
only one filter_n_bytes call and thus only one place that must be
adjusted to that.
Better names for huge_filter_buffer are welcome.

Greetings,
Reimar Döffinger
-------------- next part --------------
Index: libmpcodecs/dec_audio.c
===================================================================
--- libmpcodecs/dec_audio.c	(revision 24954)
+++ libmpcodecs/dec_audio.c	(working copy)
@@ -417,6 +421,8 @@
  * Can reallocate sh_audio->a_out_buffer if needed to fit all filter output. */
 int decode_audio(sh_audio_t *sh_audio, int minlen)
 {
+    // Indicates that a filter seems to be buffering large amounts of data
+    int huge_filter_buffer = 0;
     // Decoded audio must be cut at boundaries of this many bytes
     int unitsize = sh_audio->channels * sh_audio->samplesize;
 
@@ -436,16 +442,7 @@
     while (sh_audio->a_out_buffer_len < minlen) {
 	int declen = (minlen - sh_audio->a_out_buffer_len) / filter_multiplier
 	    + (unitsize << 5); // some extra for possible filter buffering
-	if (declen > max_decode_len) {  // Do it in several steps
-	    if (filter_n_bytes(sh_audio, max_decode_len) < 0)
-		return -1;
-	    continue;
-	}
-	declen -= declen % unitsize;
-	if (filter_n_bytes(sh_audio, declen) < 0)
-	    return -1;
-	if (sh_audio->a_out_buffer_len >= minlen)
-	    return 0;
+	if (huge_filter_buffer)
 	/* Some filter must be doing significant buffering if the estimated
 	 * input length didn't produce enough output from filters.
 	 * Feed the filters 2k bytes at a time until we have enough output.
@@ -454,13 +451,16 @@
 	 * to get audio data and buffer video frames in memory while doing
 	 * so. However the performance impact of either is probably not too
 	 * significant as long as the value is not completely insane. */
-	declen = min(2000, max_decode_len);
+	    declen = min(2000, max_decode_len);
 	declen -= declen % unitsize;
-	while (sh_audio->a_out_buffer_len < minlen) {
-	    if (filter_n_bytes(sh_audio, declen) < 0)
-		return -1;
-	}
-	return 0;
+	if (declen > max_decode_len)
+	    declen = max_decode_len;
+	else
+	    /* if this iteration does not fill buffer, we must have lots
+	     * of buffering in filters */
+	    huge_filter_buffer = 1;
+	if (filter_n_bytes(sh_audio, declen) < 0)
+	    return -1;
     }
     return 0;
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20071104/03fed222/attachment.pgp>


More information about the MPlayer-dev-eng mailing list