[FFmpeg-devel] lavf/matroska*: add support for signed integers

Michael Niedermayer michaelni at gmx.at
Thu Nov 14 22:53:08 CET 2013


On Thu, Nov 14, 2013 at 12:58:05PM +0100, Jan Gerber wrote:
> ---
>  libavformat/matroskadec.c | 31 +++++++++++++++++++++++++++++++
>  libavformat/matroskaenc.c | 21 +++++++++++++++++++++
>  2 files changed, 52 insertions(+)
> 
> 

>  matroskadec.c |   31 +++++++++++++++++++++++++++++++
>  matroskaenc.c |   21 +++++++++++++++++++++
>  2 files changed, 52 insertions(+)
> f892cbde186622b325d98822946410b91e8b354f  0001-lavf-matroska-add-support-for-signed-integers.patch
> diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
> index f770d67..78580fc 100644
> --- a/libavformat/matroskadec.c
> +++ b/libavformat/matroskadec.c
> @@ -55,6 +55,7 @@
>  typedef enum {
>      EBML_NONE,
>      EBML_UINT,
> +    EBML_SINT,
>      EBML_FLOAT,
>      EBML_STR,
>      EBML_UTF8,


> @@ -759,6 +760,35 @@ static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num)
>  }
>  
>  /*
> + * Read the next element as a signed int.
> + * 0 is success, < 0 is failure.
> + */
> +static int ebml_read_sint(AVIOContext *pb, int size, int64_t *num)
> +{
> +    int n = 0;
> +    int negative = 0;
> +
> +    if (size > 8)
> +        return AVERROR_INVALIDDATA;
> +
> +    *num = avio_r8(pb);
> +    if (*num & 0x80) {
> +        negative = 1;
> +        *num = *num & ~0x80;
> +    }
> +    n++;
> +
> +    /* big-endian ordering; build up number */
> +    while (n++ < size)
> +        *num = (*num << 8) | avio_r8(pb);
> +
> +    if (negative)
> +        *num = 0 - *num;

if i try the example from http://matroska.org/technical/specs/index.html
0xFE & 0x80
    negative = 1
    0x7E

if(negative)
    num = 0 - 0x7E

this does nt seem to reach the expected -2 which is 0xFE

but maybe iam missing something


[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I do not agree with what you have to say, but I'll defend to the death your
right to say it. -- Voltaire
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20131114/ffafec94/attachment.asc>


More information about the ffmpeg-devel mailing list