[Ffmpeg-devel] [PATCH] aiff/aiff-c format encoder and decoder

Michael Niedermayer michaelni
Mon Jan 30 03:33:52 CET 2006


Hi

On Sun, Jan 29, 2006 at 03:36:41PM -0500, Patrick Guimond wrote:
[...]
> >> +void put_be754_80(ByteIOContext *s, double val)
> > [...]
> >> +double get_be754_80(ByteIOContext *s)
> > 
> > these 2 dont belong in here, they should be in libavutil/intfloat_readwrite.*
> > and also match the API for the float & double cases
> > 
> 
> Ok, tried with a buffer supplied by the caller. I hope this is ok, is
> there a better alternative?

the uint8_t buffer is ok, but i think the code should use ldexp/frexp like the
others


[...]
> +double av_ext2dbl(const uint8_t * ext){
> +    uint64_t result;
> +
> +    if (!*((uint64_t*)(ext+2))) {   /* Null mantissa */

segfault due to 64bit alignment on some architecture


> +        if (!ext[1]) {              /* May get a +/- 0 */
> +            if (!ext[0])
> +                return 0.0;
> +            else if (ext[0] == 0x80)
> +                return -0.0;
> +        } else if (ext[0] == 0x7f)  /* Infinities */
> +            return INFINITY;
> +        else if (ext[0] == 0xff)
> +            return -INFINITY;
> +    } else if ((ext[0] & 0x7f) == 0x7f && ext[1] == 0xff)   /* NaNs */
> +        return NAN;

IIRC NAN/INFINITY are not defined everywere, 0.0/0.0 is used by the others
so thats probably safer


> +
> +    result = ((uint64_t)(((((uint16_t)ext[0] & 0x7f)<<8) | ext[1]) -
> +                ((1<<14)-1) + 1023) | (uint64_t)(ext[0]&0x80)<<56) << 52;
> +    result |= ((uint64_t)ext[2]&0x7f) << 45;
> +    result |= ((uint64_t)ext[3]) << 37;
> +    result |= ((uint64_t)ext[4]) << 29;
> +    result |= ((unsigned int)ext[5]) << 21;
> +    result |= ((unsigned int)ext[6]) << 13;
> +    result |= ((unsigned int)ext[7]) << 5;
> +    result |= ext[8] >> 3;
> +
> +    return *((double*)(void*)&result);

breaks if the system doesnt use IEEE doubles or if the int and double byte 
ordering differs


[...]
> +void av_dbl2ext(uint8_t * ext, double d){
> +    uint64_t v = *(uint64_t*)((void*)&d);

same issue as above

[...]

-- 
Michael





More information about the ffmpeg-devel mailing list