[FFmpeg-cvslog] 8svx: avoid custom clip, avoid +128 for compressed data.

Michael Niedermayer git at videolan.org
Wed Oct 3 02:53:25 CEST 2012


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Wed Oct  3 02:35:27 2012 +0200| [26d1c7d9c3701a1c650ad8f5f4d65ec2326092a9] | committer: Michael Niedermayer

8svx: avoid custom clip, avoid +128 for compressed data.

Based on:
	commit e3718784160a5bfed8de9622afda19313ec7ca50
	Author: Justin Ruggles <justin.ruggles at gmail.com>
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

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

 libavcodec/8svx.c |   31 +++++++++++++++++--------------
 1 file changed, 17 insertions(+), 14 deletions(-)

diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c
index c034dd6..e6ad061 100644
--- a/libavcodec/8svx.c
+++ b/libavcodec/8svx.c
@@ -66,23 +66,28 @@ static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0,
  * @param table delta sequence table
  * @return size in bytes of the decoded data, must be src_size*2
  */
-static int delta_decode(int8_t *dst, const uint8_t *src, int src_size,
-                        int8_t val, const int8_t *table)
+static int delta_decode(uint8_t *dst, const uint8_t *src, int src_size,
+                         unsigned val, const int8_t *table)
 {
-    int n = src_size;
-    int8_t *dst0 = dst;
+    uint8_t *dst0 = dst;
 
-    while (n--) {
+    while (src_size--) {
         uint8_t d = *src++;
-        val = av_clip(val + table[d & 0x0f], -128, 127);
+        val = av_clip_uint8(val + table[d & 0xF]);
         *dst++ = val;
-        val = av_clip(val + table[d >> 4]  , -128, 127);
+        val = av_clip_uint8(val + table[d >> 4]);
         *dst++ = val;
     }
 
     return dst-dst0;
 }
 
+static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
+{
+    while (src_size--)
+        *dst++ = *src++ + 128;
+}
+
 /** decode a frame */
 static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame_ptr, AVPacket *avpkt)
@@ -90,7 +95,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
     EightSvxContext *esc = avctx->priv_data;
     int n, out_data_size;
     int ch, ret;
-    uint8_t *src, *dst;
+    uint8_t *src;
 
     /* decode and interleave the first packet */
     if (!esc->samples && avpkt) {
@@ -122,13 +127,13 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
             /* the uncompressed starting value is contained in the first byte */
             dst = esc->samples;
             for (i = 0; i < avctx->channels; i++) {
-                *(dst++) = buf[0];
-                delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, buf[0], esc->table);
+                *(dst++) = buf[0]+128;
+                delta_decode(dst, buf + 1, buf_size / avctx->channels - 1, (buf[0]+128)&0xFF, esc->table);
                 buf += buf_size / avctx->channels;
                 dst += n / avctx->channels - 1;
             }
         } else {
-            memcpy(esc->samples, avpkt->data, esc->samples_size);
+            raw_decode(esc->samples, avpkt->data, esc->samples_size);
         }
     }
 
@@ -145,10 +150,8 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
 
     out_data_size = esc->frame.nb_samples;
     for (ch = 0; ch<avctx->channels; ch++) {
-        dst = esc->frame.data[ch];
         src = esc->samples + esc->samples_idx / avctx->channels + ch * esc->samples_size / avctx->channels;
-        for (n = out_data_size; n > 0; n--)
-            *dst++ = *src++ + 128;
+        memcpy(esc->frame.data[ch], src, out_data_size);
     }
     out_data_size *= avctx->channels;
     esc->samples_idx += out_data_size;



More information about the ffmpeg-cvslog mailing list