[FFmpeg-cvslog] avformat/matroska: simplify signed int access code

Michael Niedermayer git at videolan.org
Fri Nov 15 21:42:20 CET 2013


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Fri Nov 15 21:30:30 2013 +0100| [cddd15ba5c9cd2e92d2f2942e0fc40bf3bf56115] | committer: Michael Niedermayer

avformat/matroska: simplify signed int access code

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

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

 libavformat/matroskadec.c |    6 +-----
 libavformat/matroskaenc.c |   14 +++-----------
 2 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6bb7545..685f783 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -773,11 +773,7 @@ static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num)
     if (size == 0) {
         *num = 0;
     } else {
-        *num = avio_r8(pb);
-        /* negative value */
-        if (*num & 0x80) {
-            *num = (-1 << 8) | *num;
-        }
+        *num = sign_extend(avio_r8(pb), 8);
 
         /* big-endian ordering; build up number */
         while (n++ < size)
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 8db4795..3f466d0 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -205,22 +205,14 @@ static void put_ebml_uint(AVIOContext *pb, unsigned int elementid, uint64_t val)
 static void put_ebml_sint(AVIOContext *pb, unsigned int elementid, int64_t val)
 {
     int i, bytes = 1;
-    uint64_t uval = (val < 0 ? (-val - 1) << 1 : val << 1);
-    while (uval>>=8) bytes++;
+    uint64_t tmp = 2*(val < 0 ? val^-1 : val);
 
-    /* make unsigned */
-    if (val >= 0) {
-        uval = val;
-    } else {
-        uval = 0x80 << (bytes - 1);
-        uval += val;
-        uval |= 0x80 << (bytes - 1);
-    }
+    while (tmp>>=8) bytes++;
 
     put_ebml_id(pb, elementid);
     put_ebml_num(pb, bytes, 0);
     for (i = bytes - 1; i >= 0; i--)
-        avio_w8(pb, (uint8_t)(uval >> i*8));
+        avio_w8(pb, (uint8_t)(val >> i*8));
 }
 
 static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val)



More information about the ffmpeg-cvslog mailing list