[FFmpeg-cvslog] 8svx: split delta decoding into a separate function.

Justin Ruggles git at videolan.org
Fri Sep 23 00:37:49 CEST 2011


ffmpeg | branch: master | Justin Ruggles <justin.ruggles at gmail.com> | Tue Sep  6 15:13:59 2011 -0400| [ac68607bfe62000520db2e1c2416c11c51b3b295] | committer: Justin Ruggles

8svx: split delta decoding into a separate function.

Based on a patch by Stefano Sabatini.
git.videolan.org/ffmpeg.git
commit e280a4da2ae6fd44f0079358ecc5aa08e388a5ed

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

 libavcodec/8svx.c |   30 +++++++++++++++++++++++-------
 1 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index 4b60377..dccaadd 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -41,6 +41,28 @@ static const int16_t fibonacci[16]   = { -34<<8, -21<<8, -13<<8,  -8<<8, -5<<8,
 static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8,
                                           0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 };
 
+/**
+ * Delta decode the compressed values in src, and put the resulting
+ * decoded samples in dst.
+ *
+ * @param[in,out] state starting value. it is saved for use in the next call.
+ */
+static void delta_decode(int16_t *dst, const uint8_t *src, int src_size,
+                         int16_t *state, const int16_t *table)
+{
+    int val = *state;
+
+    while (src_size--) {
+        uint8_t d = *src++;
+        val = av_clip_int16(val + table[d & 0xF]);
+        *dst++ = val;
+        val = av_clip_int16(val + table[d >> 4]);
+        *dst++ = val;
+    }
+
+    *state = val;
+}
+
 /** decode a frame */
 static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
                                  AVPacket *avpkt)
@@ -63,13 +85,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_si
 
     *data_size = buf_size << 2;
 
-    while(buf < buf_end) {
-        uint8_t d = *buf++;
-        esc->fib_acc += esc->table[d & 0x0f];
-        *out_data++ = esc->fib_acc;
-        esc->fib_acc += esc->table[d >> 4];
-        *out_data++ = esc->fib_acc;
-    }
+    delta_decode(out_data, buf, buf_size, &esc->fib_acc, esc->table);
 
     return consumed;
 }



More information about the ffmpeg-cvslog mailing list