44 size_t (*
read)(
struct FFFILE *,
unsigned char *, size_t);
54 #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf)) 66 char *end = memchr(src, 0, k);
70 memcpy(buf, src, len);
71 f->
rpos = (
void *)(src+len);
72 f->
rend = (
void *)(src+k);
99 ptrdiff_t cnt =
shcnt(f);
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;
144 if (base > 36 || base == 1) {
149 if (c==
'+' || c==
'-') {
153 if ((base == 0 || base == 16) && c==
'0') {
164 }
else if (base == 0) {
168 if (base == 0) base = 10;
169 if (val[c] >= base) {
177 for (x=0; c-
'0'<10
U && x<=UINT_MAX/10-1; c=
shgetc(f))
179 for (y=x; c-
'0'<10
U && y<=ULLONG_MAX/10 && 10*y<=ULLONG_MAX-(c-
'0'); c=
shgetc(f))
181 if (c-
'0'>=10
U)
goto done;
182 }
else if (!(base & base-1)) {
183 int bs =
"\0\1\2\4\7\3\6\5"[(0x17*
base)>>5&7];
184 for (x=0; val[
c]<base && x<=UINT_MAX/32; c=
shgetc(f))
186 for (y=x; val[
c]<base && y<=ULLONG_MAX>>bs; c=
shgetc(f))
189 for (x=0; val[
c]<base && x<=UINT_MAX/36-1; c=
shgetc(f))
191 for (y=x; val[
c]<base && y<=ULLONG_MAX/base && base*y<=ULLONG_MAX-val[
c]; c=
shgetc(f))
203 if (!(lim&1) && !neg) {
222 if (c==
'+' || c==
'-') {
231 for (x=0; c-
'0'<10
U && x<INT_MAX/10; c =
shgetc(f))
233 for (y=x; c-
'0'<10
U && y<LLONG_MAX/100; c =
shgetc(f))
235 for (; c-
'0'<10
U; 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 };
268 for (; c==
'0'; c =
shgetc(f)) gotdig=1;
271 for (c =
shgetc(f); c==
'0'; c =
shgetc(f)) gotdig=1, lrp--;
275 for (; c-
'0'<10
U || c==
'.'; c =
shgetc(f)) {
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;
325 if (lrp==
dc &&
dc<10 && (bits>30 || x[0]>>bits==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];
353 bitlim = bits-3*(
int)(rp-9);
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]) {
416 if (x[a+i &
MASK] > th[i])
break;
418 if (i==LD_B1B_DIG && rp==9*LD_B1B_DIG)
break;
420 if (rp > 9+9*LD_B1B_DIG) sh = 9;
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) {
457 bias =
copysign(scalbn(1, 2*DBL_MANT_DIG-bits-1), y);
458 frac = fmod(y, scalbn(1, DBL_MANT_DIG-bits));
464 if ((a+i &
MASK) != z) {
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) {
471 if ((a+i+1 & MASK) == z)
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;
513 for (; c==
'0'; c =
shgetc(f))
520 for (rp=0; c==
'0'; c =
shgetc(f), rp--) gotdig = 1;
523 for (; c-
'0'<10
U || (c|32)-
'a'<6
U || 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)) {
647 if (pok)
for (; i>3; i--)
shunget(f);
651 if (!i)
for (i=0; i<3 && (c|32)==
"nan"[i]; i++)
660 if (c-
'0'<10
U || c-
'A'<26
U || c-
'a'<26
U || c==
'_')
662 if (c==
')')
return NAN;
685 return hexfloat(f, bits, emin, sign, pok);
690 return decfloat(f, c, bits, emin, sign, pok);
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 *);
781 width = 10*width + *p -
'0';
792 if (*p ==
'h') p++, size =
SIZE_hh;
796 if (*p ==
'l') p++, size =
SIZE_ll;
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 '[':
831 if (width < 1) width = 1;
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++)
875 scanset[1+c] = 1-invert;
882 while (scanset[(c=
shgetc(f))+1])
885 while (scanset[(c=
shgetc(f))+1]);
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,
966 va_start(ap, format);
static av_const int av_isdigit(int c)
Locale-independent conversion of ASCII isdigit.
Memory handling functions.
static long long scanexp(FFFILE *f, int pok)
static double hexfloat(FFFILE *f, int bits, int emin, int sign, int pok)
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
static int ff_vsscanf(const char *s, const char *fmt, va_list ap)
static int fftoread(FFFILE *f)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate.The lists are not just lists
#define va_copy(dst, src)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static __device__ float fabs(float a)
simple assert() macros that are a bit more flexible than ISO C assert().
int av_sscanf(const char *string, const char *format,...)
See libc sscanf manual for more information.
static int ffuflow(FFFILE *f)
static void * arg_n(va_list ap, unsigned int n)
static unsigned long long ffintscan(FFFILE *f, unsigned base, int pok, unsigned long long lim)
static int ff_vfscanf(FFFILE *f, const char *fmt, va_list ap)
static const unsigned char table[]
static void invert(float *h, int n)
static void store_int(void *dest, int size, unsigned long long i)
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2]...the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so...,+,-,+,-,+,+,-,+,-,+,...hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32-hcoeff[1]-hcoeff[2]-...a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2}an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||.........intra?||||:Block01:yes no||||:Block02:.................||||:Block03::y DC::ref index:||||:Block04::cb DC::motion x:||||.........:cr DC::motion y:||||.................|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------------------------------|||Y subbands||Cb subbands||Cr subbands||||------||------||------|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||------||------||------||||------||------||------|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||------||------||------||||------||------||------|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||------||------||------||||------||------||------|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------------------------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction------------|\Dequantization-------------------\||Reference frames|\IDWT|--------------|Motion\|||Frame 0||Frame 1||Compensation.OBMC v-------|--------------|--------------.\------> Frame n output Frame Frame<----------------------------------/|...|-------------------Range Coder:============Binary Range Coder:-------------------The implemented range coder is an adapted version based upon"Range encoding: an algorithm for removing redundancy from a digitised message."by G.N.N.Martin.The symbols encoded by the Snow range coder are bits(0|1).The associated probabilities are not fix but change depending on the symbol mix seen so far.bit seen|new state---------+-----------------------------------------------0|256-state_transition_table[256-old_state];1|state_transition_table[old_state];state_transition_table={0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:-------------------------FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1.the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled top and top right vectors is used as motion vector prediction the used motion vector is the sum of the predictor and(mvx_diff, mvy_diff)*mv_scale Intra DC Prediction block[y][x] dc[1]
static av_always_inline double copysign(double x, double y)
static double decfloat(FFFILE *f, int c, int bits, int emin, int sign, int pok)
static size_t ffstring_read(FFFILE *f, unsigned char *buf, size_t len)
size_t(* read)(struct FFFILE *, unsigned char *, size_t)
static double fffloatscan(FFFILE *f, int prec, int pok)
common internal and external API header
static int ffshgetc(FFFILE *f)
static void ffshlim(FFFILE *f, ptrdiff_t lim)
static double val(void *priv, double ch)