43 #define RND0 65536 // 1 << (COL_SHIFT + ROW_SHIFT - 1); 44 #define RND1 3597 // FIX (1.75683487303); 45 #define RND2 2260 // FIX (1.10355339059); 46 #define RND3 1203 // FIX (0.587788325588); 48 #define RND5 120 // FIX (0.058658283817); 49 #define RND6 512 // FIX (0.25); 50 #define RND7 512 // FIX (0.25); 52 static const int TAB04[] = { 22725, 21407, 19266, 16384, 12873, 8867, 4520 };
53 static const int TAB17[] = { 31521, 29692, 26722, 22725, 17855, 12299, 6270 };
54 static const int TAB26[] = { 29692, 27969, 25172, 21407, 16819, 11585, 5906 };
55 static const int TAB35[] = { 26722, 25172, 22654, 19266, 15137, 10426, 5315 };
59 const int c1 = tab[0];
60 const int c2 = tab[1];
61 const int c3 = tab[2];
62 const int c4 = tab[3];
63 const int c5 = tab[4];
64 const int c6 = tab[5];
65 const int c7 = tab[6];
67 const int right = in[5] | in[6] | in[7];
68 const int left = in[1] | in[2] | in[3];
69 if (!(right | in[4])) {
70 const int k = c4 * in[0] +
rnd;
72 const int a0 = k + c2 * in[2];
73 const int a1 = k + c6 * in[2];
74 const int a2 = k - c6 * in[2];
75 const int a3 = k - c2 * in[2];
77 const int b0 = c1 * in[1] + c3 * in[3];
78 const int b1 = c3 * in[1] - c7 * in[3];
79 const int b2 = c5 * in[1] - c1 * in[3];
80 const int b3 = c7 * in[1] - c5 * in[3];
104 }
else if (!(left | right)) {
105 const int a0 = (rnd + c4 * (in[0] + in[4])) >>
ROW_SHIFT;
106 const int a1 = (rnd + c4 * (in[0] - in[4])) >>
ROW_SHIFT;
117 const int k = c4 * in[0] +
rnd;
118 const unsigned int a0 = k + c2 * in[2] + c4 * in[4] + c6 * in[6];
119 const unsigned int a1 = k + c6 * in[2] - c4 * in[4] - c2 * in[6];
120 const unsigned int a2 = k - c6 * in[2] - c4 * in[4] + c2 * in[6];
121 const unsigned int a3 = k - c2 * in[2] + c4 * in[4] - c6 * in[6];
123 const unsigned int b0 = c1 * in[1] + c3 * in[3] + c5 * in[5] + c7 * in[7];
124 const unsigned int b1 = c3 * in[1] - c7 * in[3] - c1 * in[5] - c5 * in[7];
125 const unsigned int b2 = c5 * in[1] - c1 * in[3] + c7 * in[5] + c3 * in[7];
126 const unsigned int b3 = c7 * in[1] - c5 * in[3] + c3 * in[5] - c1 * in[7];
145 #define MULT(c, x, n) ((unsigned)((int)((c) * (unsigned)(x)) >> (n))) 149 #define BUTTERFLY(a, b, tmp) \ 154 #define LOAD_BUTTERFLY(m1, m2, a, b, tmp, s) \ 155 (m1) = (s)[(a)] + (s)[(b)]; \ 156 (m2) = (s)[(a)] - (s)[(b)] 160 int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, spill;
164 mm4 = (
int) in[7 * 8];
165 mm5 = (
int) in[5 * 8];
166 mm6 = (
int) in[3 * 8];
167 mm7 = (
int) in[1 * 8];
186 mm1 = (
int) in[2 * 8];
187 mm2 = (
int) in[6 * 8];
195 in[8 * 0] = (int16_t) (mm0 >>
COL_SHIFT);
196 in[8 * 7] = (int16_t) (mm7 >>
COL_SHIFT);
198 in[8 * 3] = (int16_t) (mm3 >>
COL_SHIFT);
199 in[8 * 4] = (int16_t) (mm4 >>
COL_SHIFT);
203 in[8 * 1] = (int16_t) (mm1 >>
COL_SHIFT);
204 in[8 * 6] = (int16_t) (mm6 >>
COL_SHIFT);
206 in[8 * 2] = (int16_t) (mm2 >>
COL_SHIFT);
207 in[8 * 5] = (int16_t) (mm5 >>
COL_SHIFT);
212 int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, spill;
216 mm0 = (
int) in[1 * 8];
217 mm2 = (
int) in[3 * 8];
233 mm0 = mm1 = (
int) in[0 * 8];
234 mm3 = (
int) in[2 * 8];
239 in[8 * 0] = (int16_t) (mm0 >>
COL_SHIFT);
240 in[8 * 7] = (int16_t) (mm7 >>
COL_SHIFT);
242 in[8 * 3] = (int16_t) (mm3 >>
COL_SHIFT);
243 in[8 * 4] = (int16_t) (mm4 >>
COL_SHIFT);
247 in[8 * 1] = (int16_t) (mm1 >>
COL_SHIFT);
248 in[8 * 6] = (int16_t) (mm6 >>
COL_SHIFT);
250 in[8 * 2] = (int16_t) (mm2 >>
COL_SHIFT);
251 in[8 * 5] = (int16_t) (mm5 >>
COL_SHIFT);
256 int mm0, mm1, mm2, mm3, mm4, mm5, mm6, mm7, spill;
260 mm7 = (
int) in[1 * 8];
270 mm0 = mm1 = (
int) in[0 * 8];
271 mm3 = (
int) in[2 * 8];
276 in[8 * 0] = (int16_t) (mm0 >>
COL_SHIFT);
277 in[8 * 7] = (int16_t) (mm7 >>
COL_SHIFT);
279 in[8 * 3] = (int16_t) (mm3 >>
COL_SHIFT);
280 in[8 * 4] = (int16_t) (mm4 >>
COL_SHIFT);
284 in[8 * 1] = (int16_t) (mm1 >>
COL_SHIFT);
285 in[8 * 6] = (int16_t) (mm6 >>
COL_SHIFT);
287 in[8 * 2] = (int16_t) (mm2 >>
COL_SHIFT);
288 in[8 * 5] = (int16_t) (mm5 >>
COL_SHIFT);
310 for (i = 0; i < 8; i++)
312 }
else if (rows & 0x08) {
313 for (i = 0; i < 8; i++)
316 for (i = 0; i < 8; i++)
337 if (high_bit_depth || avctx->
lowres ||
static void xvid_idct_put(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
static void idct_col_4(short *const in)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
av_cold void ff_xvid_idct_init_mips(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
Macro definitions for various function/variable attributes.
The exact code depends on how similar the blocks are and how related they are to the block
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
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
void ff_add_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
av_cold void ff_xvid_idct_init(IDCTDSPContext *c, AVCodecContext *avctx)
static int idct_row(short *in, const int *const tab, int rnd)
av_cold void ff_init_scantable_permutation(uint8_t *idct_permutation, enum idct_permutation_type perm_type)
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
static double b0(void *priv, double x, double y)
void(* idct_add)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> add dest -> clip to unsigned 8 bit -> dest.
uint8_t idct_permutation[64]
IDCT input permutation.
av_cold void ff_xvid_idct_init_x86(IDCTDSPContext *c, AVCodecContext *avctx, unsigned high_bit_depth)
void(* idct_put)(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
block -> idct -> clip to unsigned 8 bit -> dest.
void ff_put_pixels_clamped_c(const int16_t *block, uint8_t *av_restrict pixels, ptrdiff_t line_size)
static double b1(void *priv, double x, double y)
static void idct_col_8(short *const in)
static void idct_col_3(short *const in)
Libavcodec external API header.
main external API structure.
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 left
#define BUTTERFLY(a, b, tmp)
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-> in
static double b3(void *priv, double x, double y)
void ff_xvid_idct(int16_t *const in)
#define LOAD_BUTTERFLY(m1, m2, a, b, tmp, s)
static const struct twinvq_data tab
void(* idct)(int16_t *block)
enum idct_permutation_type perm_type
static void xvid_idct_add(uint8_t *dest, ptrdiff_t line_size, int16_t *block)
static double b2(void *priv, double x, double y)