[FFmpeg-cvslog] huffyuvdec: use unsafe bitstream reader

Christophe Gisquet git at videolan.org
Mon Jun 16 01:03:16 CEST 2014


ffmpeg | branch: master | Christophe Gisquet <christophe.gisquet at gmail.com> | Sun Jun 15 12:04:36 2014 +0200| [f6577bd9cf3e49d522242771184834d6b0c157fd] | committer: Michael Niedermayer

huffyuvdec: use unsafe bitstream reader

The reader reads in chunks of 11 bits at most, and at most 3 times. The unsafe
reader therefore may read 6 chunks instead of 1 in worst case, ie 8 bytes,
which is within the padding tolerance.

The reader ends up being ~10% faster. Cumulative effect of unsafe reading and
code block swapping on 3 sequences is for 1 thread, decoding time goes from
23.3s to 19.0s.

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f6577bd9cf3e49d522242771184834d6b0c157fd
---

 libavcodec/huffyuvdec.c |   16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/libavcodec/huffyuvdec.c b/libavcodec/huffyuvdec.c
index 6691149..7bb9b2d 100644
--- a/libavcodec/huffyuvdec.c
+++ b/libavcodec/huffyuvdec.c
@@ -30,6 +30,8 @@
  * huffyuv decoder
  */
 
+#define UNCHECKED_BITSTREAM_READER 1
+
 #include "avcodec.h"
 #include "get_bits.h"
 #include "huffyuv.h"
@@ -613,15 +615,21 @@ static av_cold int decode_init_thread_copy(AVCodecContext *avctx)
 
 static void decode_422_bitstream(HYuvContext *s, int count)
 {
-    int i;
+    int i, icount;
     OPEN_READER(re, &s->gb);
     count /= 2;
 
-    if (count >= (get_bits_left(&s->gb)) / (32 * 4)) {
-        for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) {
+    icount = get_bits_left(&s->gb) / (32 * 4);
+    if (count >= icount) {
+        for (i = 0; i < icount; i++) {
             READ_2PIX(s->temp[0][2 * i    ], s->temp[1][i], 1);
             READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2);
         }
+        for (; i < count && get_bits_left(&s->gb) > 0; i++) {
+            READ_2PIX(s->temp[0][2 * i    ], s->temp[1][i], 1);
+            if (get_bits_left(&s->gb) <= 0) break;
+            READ_2PIX(s->temp[0][2 * i + 1], s->temp[2][i], 2);
+        }
         for (; i < count; i++)
             s->temp[0][2 * i    ] = s->temp[1][i] =
             s->temp[0][2 * i + 1] = s->temp[2][i] = 128;
@@ -716,7 +724,7 @@ static av_always_inline void decode_bgr_1(HYuvContext *s, int count,
     int i;
     OPEN_READER(re, &s->gb);
 
-    for (i = 0; i < count; i++) {
+    for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) {
         unsigned int index;
         int code, n;
 



More information about the ffmpeg-cvslog mailing list