44 size_t (*
read)(
struct FFFILE *,
unsigned char *, size_t);
54 #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf))
58 f->rpos =
f->rend =
f->buf +
f->buf_size;
64 char *
src =
f->cookie;
66 char *end = memchr(
src, 0, k);
72 f->rend = (
void *)(
src+k);
88 f->shcnt =
f->buf -
f->rpos;
90 if (lim &&
f->rend -
f->rpos > lim)
91 f->shend =
f->rpos + lim;
100 if (
f->shlim && cnt >=
f->shlim || (
c=
ffuflow(
f)) < 0) {
101 f->shcnt =
f->buf -
f->rpos + cnt;
106 if (
f->shlim &&
f->rend -
f->rpos >
f->shlim - cnt)
107 f->shend =
f->rpos + (
f->shlim - cnt);
110 f->shcnt =
f->buf -
f->rpos + cnt;
111 if (
f->rpos[-1] !=
c)
f->rpos[-1] =
c;
115 #define shlim(f, lim) ffshlim((f), (lim))
116 #define shgetc(f) (((f)->rpos < (f)->shend) ? *(f)->rpos++ : ffshgetc(f))
117 #define shunget(f) ((f)->shend ? (void)(f)->rpos-- : (void)0)
119 static const unsigned char table[] = { -1,
120 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
121 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
122 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
123 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
124 -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
125 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
126 -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,
127 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1,
128 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
129 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
130 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
131 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
132 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
133 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
134 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
135 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
143 unsigned long long y;
149 if (
c==
'+' ||
c==
'-') {
153 if ((
base == 0 ||
base == 16) &&
c==
'0') {
164 }
else if (
base == 0) {
177 for (x=0;
c-
'0'<10U && x<=UINT_MAX/10-1;
c=
shgetc(
f))
179 for (y=x;
c-
'0'<10U && y<=ULLONG_MAX/10 && 10*y<=ULLONG_MAX-(
c-
'0');
c=
shgetc(
f))
181 if (
c-
'0'>=10U)
goto done;
183 int bs =
"\0\1\2\4\7\3\6\5"[(0x17*
base)>>5&7];
203 if (!(lim&1) && !neg) {
222 if (
c==
'+' ||
c==
'-') {
231 for (x=0;
c-
'0'<10U && x<INT_MAX/10;
c =
shgetc(
f))
233 for (y=x;
c-
'0'<10U && y<LLONG_MAX/100;
c =
shgetc(
f))
241 #define LD_B1B_MAX 9007199, 254740991
243 #define MASK (KMAX-1)
250 long long lrp=0,
dc=0;
253 int gotdig = 0, gotrad = 0;
256 int emax = -emin-
bits+3;
261 static const int p10s[] = { 10, 100, 1000, 10000,
262 100000, 1000000, 10000000, 100000000 };
280 }
else if (k <
KMAX-3) {
282 if (
c!=
'0') lnz =
dc;
283 if (j) x[k] = x[k]*10 +
c-
'0';
300 if (gotdig && (
c|32)==
'e') {
302 if (e10 == LLONG_MIN) {
322 if (!x[0])
return sign * 0.0;
326 return sign * (double)x[0];
329 return sign * DBL_MAX * DBL_MAX;
331 if (lrp < emin-2*DBL_MANT_DIG) {
333 return sign * DBL_MIN * DBL_MIN;
338 for (; j<9; j++) x[k]*=10;
349 if (lnz<9 && lnz<=rp && rp < 18) {
351 if (rp == 9)
return sign * (double)x[0];
352 if (rp < 9)
return sign * (double)x[0] / p10s[8-rp];
354 if (bitlim>30 || x[0]>>bitlim==0)
355 return sign * (double)x[0] * p10s[rp-10];
359 for (; !x[z-1]; z--);
363 int rpm9 = rp>=0 ? rp%9 : rp%9+9;
364 int p10 = p10s[8-rpm9];
366 for (k=
a; k!=z; k++) {
367 uint32_t
tmp = x[k] % p10;
368 x[k] = x[k]/p10 + carry;
369 carry = 1000000000/p10 *
tmp;
375 if (carry) x[z++] = carry;
383 for (k=(z-1 &
MASK); ; k=(k-1 &
MASK)) {
384 uint64_t
tmp = ((uint64_t)x[k] << 29) + carry;
385 if (
tmp > 1000000000) {
386 carry =
tmp / 1000000000;
387 x[k] =
tmp % 1000000000;
392 if (k==(z-1 &
MASK) && k!=
a && !x[k]) z = k;
400 x[z-1 &
MASK] |= x[z];
412 if (k == z || x[k] <
th[
i]) {
422 for (k=
a; k!=z; k=(k+1 &
MASK)) {
423 uint32_t
tmp = x[k] & (1<<sh)-1;
424 x[k] = (x[k]>>sh) + carry;
425 carry = (1000000000>>sh) *
tmp;
433 if ((z+1 &
MASK) !=
a) {
436 }
else x[z-1 &
MASK] |= 1;
442 if ((
a+
i &
MASK)==z) x[(z=(z+1 &
MASK))-1] = 0;
443 y = 1000000000.0L * y + x[
a+
i &
MASK];
449 if (
bits > DBL_MANT_DIG+e2-emin) {
450 bits = DBL_MANT_DIG+e2-emin;
456 if (
bits < DBL_MANT_DIG) {
458 frac = fmod(y, scalbn(1, DBL_MANT_DIG-
bits));
465 uint32_t t = x[
a+
i &
MASK];
466 if (t < 500000000 && (t || (
a+
i+1 &
MASK) != z))
468 else if (t > 500000000)
470 else if (t == 500000000) {
476 if (DBL_MANT_DIG-
bits >= 2 && !fmod(frac, 1))
483 if ((e2+DBL_MANT_DIG & INT_MAX) > emax-5) {
484 if (
fabs(y) >= pow(2, DBL_MANT_DIG)) {
485 if (denormal &&
bits==DBL_MANT_DIG+e2-emin)
490 if (e2+DBL_MANT_DIG>emax || (denormal && frac))
494 return scalbn(y, e2);
503 int gottail = 0, gotrad = 0, gotdig = 0;
520 for (rp=0;
c==
'0';
c =
shgetc(
f), rp--) gotdig = 1;
523 for (;
c-
'0'<10U || (
c|32)-
'a'<6U ||
c==
'.';
c =
shgetc(
f)) {
530 if (
c >
'9') d = (
c|32)+10-
'a';
534 }
else if (
dc < DBL_MANT_DIG/4+1) {
536 }
else if (d && !gottail) {
553 if (!gotrad) rp =
dc;
554 while (
dc<8) x *= 16,
dc++;
557 if (e2 == LLONG_MIN) {
571 if (!x)
return sign * 0.0;
574 return sign * DBL_MAX * DBL_MAX;
576 if (e2 < emin-2*DBL_MANT_DIG) {
578 return sign * DBL_MIN * DBL_MIN;
581 while (x < 0x80000000) {
592 if (
bits > 32+e2-emin) {
597 if (
bits < DBL_MANT_DIG)
598 bias =
copysign(scalbn(1, 32+DBL_MANT_DIG-
bits-1), sign);
600 if (
bits<32 && y && !(x&1)) x++, y=0;
602 y = bias + sign*(double)x + sign*y;
605 if (!y) errno = ERANGE;
607 return scalbn(y, e2);
621 emin = FLT_MIN_EXP-
bits;
625 emin = DBL_MIN_EXP-
bits;
629 emin = DBL_MIN_EXP-
bits;
637 if (
c==
'+' ||
c==
'-') {
642 for (
i=0;
i<8 && (
c|32)==
"infinity"[
i];
i++)
644 if (
i==3 ||
i==8 || (
i>3 && pok)) {
651 if (!
i)
for (
i=0;
i<3 && (
c|32)==
"nan"[
i];
i++)
660 if (
c-
'0'<10U ||
c-
'A'<26U ||
c-
'a'<26U ||
c==
'_')
662 if (
c==
')')
return NAN;
693 static void *
arg_n(va_list ap,
unsigned int n)
699 for (
i=n;
i>1;
i--) va_arg(ap2,
void *);
700 p = va_arg(ap2,
void *);
722 *(
long long *)dest =
i;
732 const unsigned char *p;
738 unsigned long long x;
741 unsigned char scanset[257];
744 for (p=(
const unsigned char *)fmt; *p; p++) {
754 if (*p !=
'%' || p[1] ==
'%') {
764 if (
c<0)
goto input_fail;
775 dest =
arg_n(ap, *p-
'0'); p+=2;
777 dest = va_arg(ap,
void *);
809 case 'd':
case 'i':
case 'o':
case 'u':
case 'x':
810 case 'a':
case 'e':
case 'f':
case 'g':
811 case 'A':
case 'E':
case 'F':
case 'G':
case 'X':
812 case 's':
case 'c':
case '[':
846 if (
shgetc(
f) < 0)
goto input_fail;
853 if (t ==
'c' || t ==
's') {
854 memset(scanset, -1,
sizeof scanset);
857 scanset[1 +
'\t'] = 0;
858 scanset[1 +
'\n'] = 0;
859 scanset[1 +
'\v'] = 0;
860 scanset[1 +
'\f'] = 0;
861 scanset[1 +
'\r'] = 0;
862 scanset[1 +
' ' ] = 0;
865 if (*++p ==
'^') p++,
invert = 1;
867 memset(scanset,
invert,
sizeof scanset);
869 if (*p ==
'-') p++, scanset[1+
'-'] = 1-
invert;
870 else if (*p ==
']') p++, scanset[1+
']'] = 1-
invert;
871 for (; *p !=
']'; p++) {
872 if (!*p)
goto fmt_fail;
873 if (*p==
'-' && p[1] && p[1] !=
']')
874 for (
c=p++[-1];
c<*p;
c++)
888 if (!
shcnt(
f))
goto match_fail;
889 if (t ==
'c' &&
shcnt(
f) !=
width)
goto match_fail;
913 *(
void **)dest = (
void *)(uintptr_t)x;
946 if (!matches) matches--;
955 .buf = (
void *)
s, .
cookie = (
void *)
s,
static double val(void *priv, double ch)
static const char *const format[]
static void invert(float *h, int n)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) #define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac) { } void ff_audio_convert_free(AudioConvert **ac) { if(! *ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);} AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map) { AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method !=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2) { ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc) { av_free(ac);return NULL;} return ac;} in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar) { ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar ? ac->channels :1;} else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;} int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in) { int use_generic=1;int len=in->nb_samples;int p;if(ac->dc) { av_log(ac->avr, AV_LOG_TRACE, "%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> dc
simple assert() macros that are a bit more flexible than ISO C assert().
static unsigned long long ffintscan(FFFILE *f, unsigned base, int pok, unsigned long long lim)
static int ffshgetc(FFFILE *f)
static int fftoread(FFFILE *f)
static double hexfloat(FFFILE *f, int bits, int emin, int sign, int pok)
static void store_int(void *dest, int size, unsigned long long i)
static long long scanexp(FFFILE *f, int pok)
static int ff_vsscanf(const char *s, const char *fmt, va_list ap)
static double fffloatscan(FFFILE *f, int prec, int pok)
static int ffuflow(FFFILE *f)
static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
static void * arg_n(va_list ap, unsigned int n)
static const unsigned char table[]
static size_t ffstring_read(FFFILE *f, unsigned char *buf, size_t len)
static void ffshlim(FFFILE *f, ptrdiff_t lim)
static int ff_vfscanf(FFFILE *f, const char *fmt, va_list ap)
common internal and external API header
static __device__ float fabs(float a)
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
static av_always_inline double copysign(double x, double y)
Memory handling functions.
size_t(* read)(struct FFFILE *, unsigned char *, size_t)
#define va_copy(dst, src)