summaryrefslogtreecommitdiff
path: root/libavformat/matroskaenc.c
diff options
context:
space:
mode:
authorJan Gerber <j@v2v.cc>2013-11-15 19:00:37 +0100
committerMichael Niedermayer <michaelni@gmx.at>2013-11-15 21:38:12 +0100
commitd03eea36b2c329241f63c8aca2d6adbb6ea81d9c (patch)
tree3c284e1187b4074b7a0d1d75c08b536b8767b5db /libavformat/matroskaenc.c
parent5592d1b741924d375a04470eda8e601715e0d04c (diff)
lavf/matroska*: add support for signed integers
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/matroskaenc.c')
-rw-r--r--libavformat/matroskaenc.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index d8355b23cc..8db4795d8c 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -202,6 +202,27 @@ static void put_ebml_uint(AVIOContext *pb, unsigned int elementid, uint64_t val)
avio_w8(pb, (uint8_t)(val >> i*8));
}
+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++;
+
+ /* make unsigned */
+ if (val >= 0) {
+ uval = val;
+ } else {
+ uval = 0x80 << (bytes - 1);
+ uval += val;
+ uval |= 0x80 << (bytes - 1);
+ }
+
+ 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));
+}
+
static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val)
{
put_ebml_id(pb, elementid);