avformat/matroska: simplify signed int access code

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Michael Niedermayer 2013-11-15 21:30:30 +01:00
parent d03eea36b2
commit cddd15ba5c
2 changed files with 4 additions and 16 deletions

View File

@ -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)

View File

@ -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)