aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2013-11-15 21:30:30 +0100
committerMichael Niedermayer <michaelni@gmx.at>2014-01-07 03:05:30 +0100
commitd86930b8ff2883ecf24ed3fa94beb73a50c00be2 (patch)
tree033196a729b94f08997f8719e9c55ddc32868038
parent95b5496dce829615ad7fac7dcdf6c781a72bcb8c (diff)
downloadffmpeg-d86930b8ff2883ecf24ed3fa94beb73a50c00be2.tar.gz
avformat/matroska: simplify signed int access code
Signed-off-by: Michael Niedermayer <michaelni@gmx.at> (cherry picked from commit cddd15ba5c9cd2e92d2f2942e0fc40bf3bf56115) Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavformat/matroskadec.c6
-rw-r--r--libavformat/matroskaenc.c14
2 files changed, 4 insertions, 16 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 6bc6d23243..09f7969236 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 021098bd8c..0263cbcad5 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)