gst/matroska/: fix signed integer reading/writing.

Original commit message from CVS:
2004-01-02  Ronald Bultje  <rbultje@ronald.bitfreak.net>

* gst/matroska/ebml-read.c: (gst_ebml_read_sint):
* gst/matroska/ebml-write.c: (gst_ebml_write_sint):
fix signed integer reading/writing.
This commit is contained in:
Ronald S. Bultje 2004-01-02 20:38:59 +00:00
parent b4591e1182
commit 02029d218d
3 changed files with 23 additions and 6 deletions

View file

@ -1,3 +1,9 @@
2004-01-02 Ronald Bultje <rbultje@ronald.bitfreak.net>
* gst/matroska/ebml-read.c: (gst_ebml_read_sint):
* gst/matroska/ebml-write.c: (gst_ebml_write_sint):
fix signed integer reading/writing.
2004-01-02 Benjamin Otte <in7y118@public.uni-hamburg.de>
* ext/alsa/README:

View file

@ -464,7 +464,7 @@ gst_ebml_read_sint (GstEbmlRead *ebml,
{
GstBuffer *buf;
guint8 *data;
guint size;
guint size, negative = 0, n = 0;
if (!gst_ebml_read_buffer (ebml, id, &buf))
return FALSE;
@ -478,14 +478,19 @@ gst_ebml_read_sint (GstEbmlRead *ebml,
gst_buffer_unref (buf);
return FALSE;
}
if (data[0] & 0x80) {
negative = 1;
data[0] &= ~0x80;
}
*num = 0;
while (size > 0) {
*num = (*num << 8) | data[GST_BUFFER_SIZE (buf) - size];
size--;
while (n < size) {
*num = (*num << 8) | data[n++];
}
/* make signed */
*num -= (1LL << ((8 * GST_BUFFER_SIZE (buf)) - 1));
if (negative) {
*num = *num - (1LL << ((8 * size) - 1));
}
gst_buffer_unref (buf);

View file

@ -391,7 +391,13 @@ gst_ebml_write_sint (GstEbmlWrite *ebml,
guint size = gst_ebml_write_get_uint_size (unum);
/* make unsigned */
unum = (num < 0 ? -num : num) + (1LLU << ((8 * size) - 1));
if (num >= 0) {
unum = num;
} else {
unum = 0x80 << (size - 1);
unum += num;
unum |= 0x80 << (size - 1);
}
/* write */
gst_ebml_write_element_id (buf, id);