mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
avformat/matroska: simplify signed int access code
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
d03eea36b2
commit
cddd15ba5c
@ -773,11 +773,7 @@ static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num)
|
|||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
*num = 0;
|
*num = 0;
|
||||||
} else {
|
} else {
|
||||||
*num = avio_r8(pb);
|
*num = sign_extend(avio_r8(pb), 8);
|
||||||
/* negative value */
|
|
||||||
if (*num & 0x80) {
|
|
||||||
*num = (-1 << 8) | *num;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* big-endian ordering; build up number */
|
/* big-endian ordering; build up number */
|
||||||
while (n++ < size)
|
while (n++ < size)
|
||||||
|
@ -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)
|
static void put_ebml_sint(AVIOContext *pb, unsigned int elementid, int64_t val)
|
||||||
{
|
{
|
||||||
int i, bytes = 1;
|
int i, bytes = 1;
|
||||||
uint64_t uval = (val < 0 ? (-val - 1) << 1 : val << 1);
|
uint64_t tmp = 2*(val < 0 ? val^-1 : val);
|
||||||
while (uval>>=8) bytes++;
|
|
||||||
|
|
||||||
/* make unsigned */
|
while (tmp>>=8) bytes++;
|
||||||
if (val >= 0) {
|
|
||||||
uval = val;
|
|
||||||
} else {
|
|
||||||
uval = 0x80 << (bytes - 1);
|
|
||||||
uval += val;
|
|
||||||
uval |= 0x80 << (bytes - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
put_ebml_id(pb, elementid);
|
put_ebml_id(pb, elementid);
|
||||||
put_ebml_num(pb, bytes, 0);
|
put_ebml_num(pb, bytes, 0);
|
||||||
for (i = bytes - 1; i >= 0; i--)
|
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)
|
static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user