You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
avformat/aiffdec: avoid double and ldexp()
There is no support for non integer sample rates, using doubles/floats currently could only lead to rounding differences between platforms Previous version Reviewed-by: Mark Harris <mark.hsj@gmail.com> Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
@@ -91,7 +91,7 @@ static void get_meta(AVFormatContext *s, const char *key, int size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Returns the number of sound data frames or negative on error */
|
/* Returns the number of sound data frames or negative on error */
|
||||||
static unsigned int get_aiff_header(AVFormatContext *s, int size,
|
static int get_aiff_header(AVFormatContext *s, int size,
|
||||||
unsigned version)
|
unsigned version)
|
||||||
{
|
{
|
||||||
AVIOContext *pb = s->pb;
|
AVIOContext *pb = s->pb;
|
||||||
@@ -99,7 +99,7 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
|
|||||||
AIFFInputContext *aiff = s->priv_data;
|
AIFFInputContext *aiff = s->priv_data;
|
||||||
int exp;
|
int exp;
|
||||||
uint64_t val;
|
uint64_t val;
|
||||||
double sample_rate;
|
int sample_rate;
|
||||||
unsigned int num_frames;
|
unsigned int num_frames;
|
||||||
|
|
||||||
if (size & 1)
|
if (size & 1)
|
||||||
@@ -109,9 +109,16 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
|
|||||||
num_frames = avio_rb32(pb);
|
num_frames = avio_rb32(pb);
|
||||||
codec->bits_per_coded_sample = avio_rb16(pb);
|
codec->bits_per_coded_sample = avio_rb16(pb);
|
||||||
|
|
||||||
exp = avio_rb16(pb);
|
exp = avio_rb16(pb) - 16383 - 63;
|
||||||
val = avio_rb64(pb);
|
val = avio_rb64(pb);
|
||||||
sample_rate = ldexp(val, exp - 16383 - 63);
|
if (exp <-63 || exp >63) {
|
||||||
|
av_log(s, AV_LOG_ERROR, "exp %d is out of range\n", exp);
|
||||||
|
return AVERROR_INVALIDDATA;
|
||||||
|
}
|
||||||
|
if (exp >= 0)
|
||||||
|
sample_rate = val << exp;
|
||||||
|
else
|
||||||
|
sample_rate = (val + (1ULL<<(-exp-1))) >> -exp;
|
||||||
codec->sample_rate = sample_rate;
|
codec->sample_rate = sample_rate;
|
||||||
size -= 18;
|
size -= 18;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user