diff options
author | Mohamed Tarek <mt@rockbox.org> | 2009-08-10 14:46:31 +0000 |
---|---|---|
committer | Mohamed Tarek <mt@rockbox.org> | 2009-08-10 14:46:31 +0000 |
commit | 519adfbaae5933ec18d2e3cb77e690e36cd49916 (patch) | |
tree | 8303456ddf72f2ff5da2b9a99802c73e1409fc28 /apps/codecs | |
parent | 1c0aeb18ca264e1f64e31f219189afab442676eb (diff) | |
download | rockbox-519adfbaae5933ec18d2e3cb77e690e36cd49916.tar.gz rockbox-519adfbaae5933ec18d2e3cb77e690e36cd49916.zip |
Import libatrac from ffmpeg and modify librm to support ATRAC3.
The decoder is still in floating point.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22235 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs')
25 files changed, 13440 insertions, 9 deletions
diff --git a/apps/codecs/libatrac/Makefile.test b/apps/codecs/libatrac/Makefile.test new file mode 100644 index 0000000000..56b50b90fa --- /dev/null +++ b/apps/codecs/libatrac/Makefile.test | |||
@@ -0,0 +1,11 @@ | |||
1 | CFLAGS = -Wall -O3 -DTEST -D"DEBUGF=printf" | ||
2 | OBJS = atrac3.o dsputil.o bitstream.o fft.o mdct.o libavutil/log.o libavutil/mem.o ../librm/rm.o | ||
3 | |||
4 | atractest: $(OBJS) | ||
5 | gcc -o atractest $(OBJS) -lm | ||
6 | |||
7 | .c.o : | ||
8 | $(CC) $(CFLAGS) -c -o $@ $< | ||
9 | |||
10 | clean: | ||
11 | rm -f atractest $(OBJS) *~ output.wav | ||
diff --git a/apps/codecs/libatrac/README.rockbox b/apps/codecs/libatrac/README.rockbox new file mode 100644 index 0000000000..7f62e10bb4 --- /dev/null +++ b/apps/codecs/libatrac/README.rockbox | |||
@@ -0,0 +1,20 @@ | |||
1 | Library: libatrac | ||
2 | Imported by : Mohamed Tarek | ||
3 | Import date : 10-August-2009 | ||
4 | |||
5 | LICENSING INFORMATION | ||
6 | |||
7 | ffmpeg is licensed under the Lesser GNU General Public License. | ||
8 | |||
9 | IMPORT DETAILS | ||
10 | |||
11 | The decoder is based on ffmpeg-svn r18079. It still uses floating | ||
12 | point math and not suitable to be used in rockbox. | ||
13 | |||
14 | TESTING | ||
15 | |||
16 | The test program should compile in any Unix-like environment using the | ||
17 | command "make -f Makefile.test". | ||
18 | |||
19 | Running "./atractest file.rm" will decode the audio data to a WAV file | ||
20 | called "output.wav" in the current directory. | ||
diff --git a/apps/codecs/libatrac/atrac3.c b/apps/codecs/libatrac/atrac3.c new file mode 100644 index 0000000000..a800511397 --- /dev/null +++ b/apps/codecs/libatrac/atrac3.c | |||
@@ -0,0 +1,1249 @@ | |||
1 | /* | ||
2 | * Atrac 3 compatible decoder | ||
3 | * Copyright (c) 2006-2008 Maxim Poliakovski | ||
4 | * Copyright (c) 2006-2008 Benjamin Larsson | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file libavcodec/atrac3.c | ||
25 | * Atrac 3 compatible decoder. | ||
26 | * This decoder handles Sony's ATRAC3 data. | ||
27 | * | ||
28 | * Container formats used to store atrac 3 data: | ||
29 | * RealMedia (.rm), RIFF WAV (.wav, .at3), Sony OpenMG (.oma, .aa3). | ||
30 | * | ||
31 | * To use this decoder, a calling application must supply the extradata | ||
32 | * bytes provided in the containers above. | ||
33 | */ | ||
34 | |||
35 | #include <math.h> | ||
36 | #include <stddef.h> | ||
37 | #include <stdio.h> | ||
38 | |||
39 | #include "avcodec.h" | ||
40 | #include "bitstream.h" | ||
41 | #include "dsputil.h" | ||
42 | #include "bytestream.h" | ||
43 | |||
44 | #include <stdint.h> | ||
45 | #include <sys/types.h> | ||
46 | #include <sys/stat.h> | ||
47 | #include <fcntl.h> | ||
48 | #include <unistd.h> | ||
49 | #include <string.h> | ||
50 | |||
51 | #include "../librm/rm.h" | ||
52 | #include "atrac3data.h" | ||
53 | |||
54 | #define JOINT_STEREO 0x12 | ||
55 | #define STEREO 0x2 | ||
56 | |||
57 | #define AVERROR(...) -1 | ||
58 | |||
59 | /* These structures are needed to store the parsed gain control data. */ | ||
60 | typedef struct { | ||
61 | int num_gain_data; | ||
62 | int levcode[8]; | ||
63 | int loccode[8]; | ||
64 | } gain_info; | ||
65 | |||
66 | typedef struct { | ||
67 | gain_info gBlock[4]; | ||
68 | } gain_block; | ||
69 | |||
70 | typedef struct { | ||
71 | int pos; | ||
72 | int numCoefs; | ||
73 | float coef[8]; | ||
74 | } tonal_component; | ||
75 | |||
76 | typedef struct { | ||
77 | int bandsCoded; | ||
78 | int numComponents; | ||
79 | tonal_component components[64]; | ||
80 | float prevFrame[1024]; | ||
81 | int gcBlkSwitch; | ||
82 | gain_block gainBlock[2]; | ||
83 | |||
84 | DECLARE_ALIGNED_16(float, spectrum[1024]); | ||
85 | DECLARE_ALIGNED_16(float, IMDCT_buf[1024]); | ||
86 | |||
87 | float delayBuf1[46]; ///<qmf delay buffers | ||
88 | float delayBuf2[46]; | ||
89 | float delayBuf3[46]; | ||
90 | } channel_unit; | ||
91 | |||
92 | typedef struct { | ||
93 | GetBitContext gb; | ||
94 | //@{ | ||
95 | /** stream data */ | ||
96 | int channels; | ||
97 | int codingMode; | ||
98 | int bit_rate; | ||
99 | int sample_rate; | ||
100 | int samples_per_channel; | ||
101 | int samples_per_frame; | ||
102 | |||
103 | int bits_per_frame; | ||
104 | int bytes_per_frame; | ||
105 | int pBs; | ||
106 | channel_unit* pUnits; | ||
107 | //@} | ||
108 | //@{ | ||
109 | /** joint-stereo related variables */ | ||
110 | int matrix_coeff_index_prev[4]; | ||
111 | int matrix_coeff_index_now[4]; | ||
112 | int matrix_coeff_index_next[4]; | ||
113 | int weighting_delay[6]; | ||
114 | //@} | ||
115 | //@{ | ||
116 | /** data buffers */ | ||
117 | float outSamples[2048]; | ||
118 | uint8_t* decoded_bytes_buffer; | ||
119 | float tempBuf[1070]; | ||
120 | //@} | ||
121 | //@{ | ||
122 | /** extradata */ | ||
123 | int atrac3version; | ||
124 | int delay; | ||
125 | int scrambled_stream; | ||
126 | int frame_factor; | ||
127 | //@} | ||
128 | } ATRAC3Context; | ||
129 | |||
130 | static DECLARE_ALIGNED_16(float,mdct_window[512]); | ||
131 | static float qmf_window[48]; | ||
132 | static VLC spectral_coeff_tab[7]; | ||
133 | static float SFTable[64]; | ||
134 | static float gain_tab1[16]; | ||
135 | static float gain_tab2[31]; | ||
136 | static MDCTContext mdct_ctx; | ||
137 | static DSPContext dsp; | ||
138 | |||
139 | |||
140 | /* quadrature mirror synthesis filter */ | ||
141 | |||
142 | /** | ||
143 | * Quadrature mirror synthesis filter. | ||
144 | * | ||
145 | * @param inlo lower part of spectrum | ||
146 | * @param inhi higher part of spectrum | ||
147 | * @param nIn size of spectrum buffer | ||
148 | * @param pOut out buffer | ||
149 | * @param delayBuf delayBuf buffer | ||
150 | * @param temp temp buffer | ||
151 | */ | ||
152 | |||
153 | |||
154 | static void iqmf (float *inlo, float *inhi, unsigned int nIn, float *pOut, float *delayBuf, float *temp) | ||
155 | { | ||
156 | int i, j; | ||
157 | float *p1, *p3; | ||
158 | |||
159 | memcpy(temp, delayBuf, 46*sizeof(float)); | ||
160 | |||
161 | p3 = temp + 46; | ||
162 | |||
163 | /* loop1 */ | ||
164 | for(i=0; i<nIn; i+=2){ | ||
165 | p3[2*i+0] = inlo[i ] + inhi[i ]; | ||
166 | p3[2*i+1] = inlo[i ] - inhi[i ]; | ||
167 | p3[2*i+2] = inlo[i+1] + inhi[i+1]; | ||
168 | p3[2*i+3] = inlo[i+1] - inhi[i+1]; | ||
169 | } | ||
170 | |||
171 | /* loop2 */ | ||
172 | p1 = temp; | ||
173 | for (j = nIn; j != 0; j--) { | ||
174 | float s1 = 0.0; | ||
175 | float s2 = 0.0; | ||
176 | |||
177 | for (i = 0; i < 48; i += 2) { | ||
178 | s1 += p1[i] * qmf_window[i]; | ||
179 | s2 += p1[i+1] * qmf_window[i+1]; | ||
180 | } | ||
181 | |||
182 | pOut[0] = s2; | ||
183 | pOut[1] = s1; | ||
184 | |||
185 | p1 += 2; | ||
186 | pOut += 2; | ||
187 | } | ||
188 | |||
189 | /* Update the delay buffer. */ | ||
190 | memcpy(delayBuf, temp + nIn*2, 46*sizeof(float)); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Regular 512 points IMDCT without overlapping, with the exception of the swapping of odd bands | ||
195 | * caused by the reverse spectra of the QMF. | ||
196 | * | ||
197 | * @param pInput float input | ||
198 | * @param pOutput float output | ||
199 | * @param odd_band 1 if the band is an odd band | ||
200 | */ | ||
201 | |||
202 | static void IMLT(float *pInput, float *pOutput, int odd_band) | ||
203 | { | ||
204 | int i; | ||
205 | |||
206 | if (odd_band) { | ||
207 | /** | ||
208 | * Reverse the odd bands before IMDCT, this is an effect of the QMF transform | ||
209 | * or it gives better compression to do it this way. | ||
210 | * FIXME: It should be possible to handle this in ff_imdct_calc | ||
211 | * for that to happen a modification of the prerotation step of | ||
212 | * all SIMD code and C code is needed. | ||
213 | * Or fix the functions before so they generate a pre reversed spectrum. | ||
214 | */ | ||
215 | |||
216 | for (i=0; i<128; i++) | ||
217 | FFSWAP(float, pInput[i], pInput[255-i]); | ||
218 | } | ||
219 | |||
220 | ff_imdct_calc(&mdct_ctx,pOutput,pInput); | ||
221 | |||
222 | /* Perform windowing on the output. */ | ||
223 | dsp.vector_fmul(pOutput,mdct_window,512); | ||
224 | |||
225 | } | ||
226 | |||
227 | |||
228 | /** | ||
229 | * Atrac 3 indata descrambling, only used for data coming from the rm container | ||
230 | * | ||
231 | * @param in pointer to 8 bit array of indata | ||
232 | * @param bits amount of bits | ||
233 | * @param out pointer to 8 bit array of outdata | ||
234 | */ | ||
235 | |||
236 | static int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ | ||
237 | int i, off; | ||
238 | uint32_t c; | ||
239 | const uint32_t* buf; | ||
240 | uint32_t* obuf = (uint32_t*) out; | ||
241 | |||
242 | #ifdef TEST | ||
243 | off = 0; //no check for memory alignment of inbuffer | ||
244 | #else | ||
245 | off = (intptr_t)inbuffer & 3; | ||
246 | #endif /* TEST */ | ||
247 | buf = (const uint32_t*) (inbuffer - off); | ||
248 | |||
249 | c = be2me_32((0x537F6103 >> (off*8)) | (0x537F6103 << (32-(off*8)))); | ||
250 | bytes += 3 + off; | ||
251 | for (i = 0; i < bytes/4; i++) | ||
252 | obuf[i] = c ^ buf[i]; | ||
253 | |||
254 | if (off) | ||
255 | av_log(NULL,AV_LOG_DEBUG,"Offset of %d not handled, post sample on ffmpeg-dev.\n",off); | ||
256 | |||
257 | return off; | ||
258 | } | ||
259 | |||
260 | |||
261 | static av_cold void init_atrac3_transforms(ATRAC3Context *q) { | ||
262 | float enc_window[256]; | ||
263 | float s; | ||
264 | int i; | ||
265 | |||
266 | /* Generate the mdct window, for details see | ||
267 | * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ | ||
268 | for (i=0 ; i<256; i++) | ||
269 | enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5; | ||
270 | |||
271 | if (!mdct_window[0]) | ||
272 | for (i=0 ; i<256; i++) { | ||
273 | mdct_window[i] = enc_window[i]/(enc_window[i]*enc_window[i] + enc_window[255-i]*enc_window[255-i]); | ||
274 | mdct_window[511-i] = mdct_window[i]; | ||
275 | } | ||
276 | |||
277 | /* Generate the QMF window. */ | ||
278 | for (i=0 ; i<24; i++) { | ||
279 | s = qmf_48tap_half[i] * 2.0; | ||
280 | qmf_window[i] = s; | ||
281 | qmf_window[47 - i] = s; | ||
282 | } | ||
283 | |||
284 | /* Initialize the MDCT transform. */ | ||
285 | ff_mdct_init(&mdct_ctx, 9, 1); | ||
286 | } | ||
287 | |||
288 | /** | ||
289 | * Atrac3 uninit, free all allocated memory | ||
290 | */ | ||
291 | |||
292 | static av_cold int atrac3_decode_close(ATRAC3Context *q) | ||
293 | { | ||
294 | //ATRAC3Context *q = rmctx->priv_data; | ||
295 | |||
296 | av_free(q->pUnits); | ||
297 | av_free(q->decoded_bytes_buffer); | ||
298 | |||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | /** | ||
303 | / * Mantissa decoding | ||
304 | * | ||
305 | * @param gb the GetBit context | ||
306 | * @param selector what table is the output values coded with | ||
307 | * @param codingFlag constant length coding or variable length coding | ||
308 | * @param mantissas mantissa output table | ||
309 | * @param numCodes amount of values to get | ||
310 | */ | ||
311 | |||
312 | static void readQuantSpectralCoeffs (GetBitContext *gb, int selector, int codingFlag, int* mantissas, int numCodes) | ||
313 | { | ||
314 | int numBits, cnt, code, huffSymb; | ||
315 | |||
316 | if (selector == 1) | ||
317 | numCodes /= 2; | ||
318 | |||
319 | if (codingFlag != 0) { | ||
320 | /* constant length coding (CLC) */ | ||
321 | numBits = CLCLengthTab[selector]; | ||
322 | |||
323 | if (selector > 1) { | ||
324 | for (cnt = 0; cnt < numCodes; cnt++) { | ||
325 | if (numBits) | ||
326 | code = get_sbits(gb, numBits); | ||
327 | else | ||
328 | code = 0; | ||
329 | mantissas[cnt] = code; | ||
330 | } | ||
331 | } else { | ||
332 | for (cnt = 0; cnt < numCodes; cnt++) { | ||
333 | if (numBits) | ||
334 | code = get_bits(gb, numBits); //numBits is always 4 in this case | ||
335 | else | ||
336 | code = 0; | ||
337 | mantissas[cnt*2] = seTab_0[code >> 2]; | ||
338 | mantissas[cnt*2+1] = seTab_0[code & 3]; | ||
339 | } | ||
340 | } | ||
341 | } else { | ||
342 | /* variable length coding (VLC) */ | ||
343 | if (selector != 1) { | ||
344 | for (cnt = 0; cnt < numCodes; cnt++) { | ||
345 | huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); | ||
346 | huffSymb += 1; | ||
347 | code = huffSymb >> 1; | ||
348 | if (huffSymb & 1) | ||
349 | code = -code; | ||
350 | mantissas[cnt] = code; | ||
351 | } | ||
352 | } else { | ||
353 | for (cnt = 0; cnt < numCodes; cnt++) { | ||
354 | huffSymb = get_vlc2(gb, spectral_coeff_tab[selector-1].table, spectral_coeff_tab[selector-1].bits, 3); | ||
355 | mantissas[cnt*2] = decTable1[huffSymb*2]; | ||
356 | mantissas[cnt*2+1] = decTable1[huffSymb*2+1]; | ||
357 | } | ||
358 | } | ||
359 | } | ||
360 | } | ||
361 | |||
362 | /** | ||
363 | * Restore the quantized band spectrum coefficients | ||
364 | * | ||
365 | * @param gb the GetBit context | ||
366 | * @param pOut decoded band spectrum | ||
367 | * @return outSubbands subband counter, fix for broken specification/files | ||
368 | */ | ||
369 | |||
370 | static int decodeSpectrum (GetBitContext *gb, float *pOut) | ||
371 | { | ||
372 | int numSubbands, codingMode, cnt, first, last, subbWidth, *pIn; | ||
373 | int subband_vlc_index[32], SF_idxs[32]; | ||
374 | int mantissas[128]; | ||
375 | float SF; | ||
376 | |||
377 | numSubbands = get_bits(gb, 5); // number of coded subbands | ||
378 | codingMode = get_bits1(gb); // coding Mode: 0 - VLC/ 1-CLC | ||
379 | |||
380 | /* Get the VLC selector table for the subbands, 0 means not coded. */ | ||
381 | for (cnt = 0; cnt <= numSubbands; cnt++) | ||
382 | subband_vlc_index[cnt] = get_bits(gb, 3); | ||
383 | |||
384 | /* Read the scale factor indexes from the stream. */ | ||
385 | for (cnt = 0; cnt <= numSubbands; cnt++) { | ||
386 | if (subband_vlc_index[cnt] != 0) | ||
387 | SF_idxs[cnt] = get_bits(gb, 6); | ||
388 | } | ||
389 | |||
390 | for (cnt = 0; cnt <= numSubbands; cnt++) { | ||
391 | first = subbandTab[cnt]; | ||
392 | last = subbandTab[cnt+1]; | ||
393 | |||
394 | subbWidth = last - first; | ||
395 | |||
396 | if (subband_vlc_index[cnt] != 0) { | ||
397 | /* Decode spectral coefficients for this subband. */ | ||
398 | /* TODO: This can be done faster is several blocks share the | ||
399 | * same VLC selector (subband_vlc_index) */ | ||
400 | readQuantSpectralCoeffs (gb, subband_vlc_index[cnt], codingMode, mantissas, subbWidth); | ||
401 | |||
402 | /* Decode the scale factor for this subband. */ | ||
403 | SF = SFTable[SF_idxs[cnt]] * iMaxQuant[subband_vlc_index[cnt]]; | ||
404 | |||
405 | /* Inverse quantize the coefficients. */ | ||
406 | for (pIn=mantissas ; first<last; first++, pIn++) | ||
407 | pOut[first] = *pIn * SF; | ||
408 | } else { | ||
409 | /* This subband was not coded, so zero the entire subband. */ | ||
410 | memset(pOut+first, 0, subbWidth*sizeof(float)); | ||
411 | } | ||
412 | } | ||
413 | |||
414 | /* Clear the subbands that were not coded. */ | ||
415 | first = subbandTab[cnt]; | ||
416 | memset(pOut+first, 0, (1024 - first) * sizeof(float)); | ||
417 | return numSubbands; | ||
418 | } | ||
419 | |||
420 | /** | ||
421 | * Restore the quantized tonal components | ||
422 | * | ||
423 | * @param gb the GetBit context | ||
424 | * @param pComponent tone component | ||
425 | * @param numBands amount of coded bands | ||
426 | */ | ||
427 | |||
428 | static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent, int numBands) | ||
429 | { | ||
430 | int i,j,k,cnt; | ||
431 | int components, coding_mode_selector, coding_mode, coded_values_per_component; | ||
432 | int sfIndx, coded_values, max_coded_values, quant_step_index, coded_components; | ||
433 | int band_flags[4], mantissa[8]; | ||
434 | float *pCoef; | ||
435 | float scalefactor; | ||
436 | int component_count = 0; | ||
437 | |||
438 | components = get_bits(gb,5); | ||
439 | |||
440 | /* no tonal components */ | ||
441 | if (components == 0) | ||
442 | return 0; | ||
443 | |||
444 | coding_mode_selector = get_bits(gb,2); | ||
445 | if (coding_mode_selector == 2) | ||
446 | return -1; | ||
447 | |||
448 | coding_mode = coding_mode_selector & 1; | ||
449 | |||
450 | for (i = 0; i < components; i++) { | ||
451 | for (cnt = 0; cnt <= numBands; cnt++) | ||
452 | band_flags[cnt] = get_bits1(gb); | ||
453 | |||
454 | coded_values_per_component = get_bits(gb,3); | ||
455 | |||
456 | quant_step_index = get_bits(gb,3); | ||
457 | if (quant_step_index <= 1) | ||
458 | return -1; | ||
459 | |||
460 | if (coding_mode_selector == 3) | ||
461 | coding_mode = get_bits1(gb); | ||
462 | |||
463 | for (j = 0; j < (numBands + 1) * 4; j++) { | ||
464 | if (band_flags[j >> 2] == 0) | ||
465 | continue; | ||
466 | |||
467 | coded_components = get_bits(gb,3); | ||
468 | |||
469 | for (k=0; k<coded_components; k++) { | ||
470 | sfIndx = get_bits(gb,6); | ||
471 | pComponent[component_count].pos = j * 64 + (get_bits(gb,6)); | ||
472 | max_coded_values = 1024 - pComponent[component_count].pos; | ||
473 | coded_values = coded_values_per_component + 1; | ||
474 | coded_values = FFMIN(max_coded_values,coded_values); | ||
475 | |||
476 | scalefactor = SFTable[sfIndx] * iMaxQuant[quant_step_index]; | ||
477 | |||
478 | readQuantSpectralCoeffs(gb, quant_step_index, coding_mode, mantissa, coded_values); | ||
479 | |||
480 | pComponent[component_count].numCoefs = coded_values; | ||
481 | |||
482 | /* inverse quant */ | ||
483 | pCoef = pComponent[component_count].coef; | ||
484 | for (cnt = 0; cnt < coded_values; cnt++) | ||
485 | pCoef[cnt] = mantissa[cnt] * scalefactor; | ||
486 | |||
487 | component_count++; | ||
488 | } | ||
489 | } | ||
490 | } | ||
491 | |||
492 | return component_count; | ||
493 | } | ||
494 | |||
495 | /** | ||
496 | * Decode gain parameters for the coded bands | ||
497 | * | ||
498 | * @param gb the GetBit context | ||
499 | * @param pGb the gainblock for the current band | ||
500 | * @param numBands amount of coded bands | ||
501 | */ | ||
502 | |||
503 | static int decodeGainControl (GetBitContext *gb, gain_block *pGb, int numBands) | ||
504 | { | ||
505 | int i, cf, numData; | ||
506 | int *pLevel, *pLoc; | ||
507 | |||
508 | gain_info *pGain = pGb->gBlock; | ||
509 | |||
510 | for (i=0 ; i<=numBands; i++) | ||
511 | { | ||
512 | numData = get_bits(gb,3); | ||
513 | pGain[i].num_gain_data = numData; | ||
514 | pLevel = pGain[i].levcode; | ||
515 | pLoc = pGain[i].loccode; | ||
516 | |||
517 | for (cf = 0; cf < numData; cf++){ | ||
518 | pLevel[cf]= get_bits(gb,4); | ||
519 | pLoc [cf]= get_bits(gb,5); | ||
520 | if(cf && pLoc[cf] <= pLoc[cf-1]) | ||
521 | return -1; | ||
522 | } | ||
523 | } | ||
524 | |||
525 | /* Clear the unused blocks. */ | ||
526 | for (; i<4 ; i++) | ||
527 | pGain[i].num_gain_data = 0; | ||
528 | |||
529 | return 0; | ||
530 | } | ||
531 | |||
532 | /** | ||
533 | * Apply gain parameters and perform the MDCT overlapping part | ||
534 | * | ||
535 | * @param pIn input float buffer | ||
536 | * @param pPrev previous float buffer to perform overlap against | ||
537 | * @param pOut output float buffer | ||
538 | * @param pGain1 current band gain info | ||
539 | * @param pGain2 next band gain info | ||
540 | */ | ||
541 | |||
542 | static void gainCompensateAndOverlap (float *pIn, float *pPrev, float *pOut, gain_info *pGain1, gain_info *pGain2) | ||
543 | { | ||
544 | /* gain compensation function */ | ||
545 | float gain1, gain2, gain_inc; | ||
546 | int cnt, numdata, nsample, startLoc, endLoc; | ||
547 | |||
548 | |||
549 | if (pGain2->num_gain_data == 0) | ||
550 | gain1 = 1.0; | ||
551 | else | ||
552 | gain1 = gain_tab1[pGain2->levcode[0]]; | ||
553 | |||
554 | if (pGain1->num_gain_data == 0) { | ||
555 | for (cnt = 0; cnt < 256; cnt++) | ||
556 | pOut[cnt] = pIn[cnt] * gain1 + pPrev[cnt]; | ||
557 | } else { | ||
558 | numdata = pGain1->num_gain_data; | ||
559 | pGain1->loccode[numdata] = 32; | ||
560 | pGain1->levcode[numdata] = 4; | ||
561 | |||
562 | nsample = 0; // current sample = 0 | ||
563 | |||
564 | for (cnt = 0; cnt < numdata; cnt++) { | ||
565 | startLoc = pGain1->loccode[cnt] * 8; | ||
566 | endLoc = startLoc + 8; | ||
567 | |||
568 | gain2 = gain_tab1[pGain1->levcode[cnt]]; | ||
569 | gain_inc = gain_tab2[(pGain1->levcode[cnt+1] - pGain1->levcode[cnt])+15]; | ||
570 | |||
571 | /* interpolate */ | ||
572 | for (; nsample < startLoc; nsample++) | ||
573 | pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2; | ||
574 | |||
575 | /* interpolation is done over eight samples */ | ||
576 | for (; nsample < endLoc; nsample++) { | ||
577 | pOut[nsample] = (pIn[nsample] * gain1 + pPrev[nsample]) * gain2; | ||
578 | gain2 *= gain_inc; | ||
579 | } | ||
580 | } | ||
581 | |||
582 | for (; nsample < 256; nsample++) | ||
583 | pOut[nsample] = (pIn[nsample] * gain1) + pPrev[nsample]; | ||
584 | } | ||
585 | |||
586 | /* Delay for the overlapping part. */ | ||
587 | memcpy(pPrev, &pIn[256], 256*sizeof(float)); | ||
588 | } | ||
589 | |||
590 | /** | ||
591 | * Combine the tonal band spectrum and regular band spectrum | ||
592 | * Return position of the last tonal coefficient | ||
593 | * | ||
594 | * @param pSpectrum output spectrum buffer | ||
595 | * @param numComponents amount of tonal components | ||
596 | * @param pComponent tonal components for this band | ||
597 | */ | ||
598 | |||
599 | static int addTonalComponents (float *pSpectrum, int numComponents, tonal_component *pComponent) | ||
600 | { | ||
601 | int cnt, i, lastPos = -1; | ||
602 | float *pIn, *pOut; | ||
603 | |||
604 | for (cnt = 0; cnt < numComponents; cnt++){ | ||
605 | lastPos = FFMAX(pComponent[cnt].pos + pComponent[cnt].numCoefs, lastPos); | ||
606 | pIn = pComponent[cnt].coef; | ||
607 | pOut = &(pSpectrum[pComponent[cnt].pos]); | ||
608 | |||
609 | for (i=0 ; i<pComponent[cnt].numCoefs ; i++) | ||
610 | pOut[i] += pIn[i]; | ||
611 | } | ||
612 | |||
613 | return lastPos; | ||
614 | } | ||
615 | |||
616 | |||
617 | #define INTERPOLATE(old,new,nsample) ((old) + (nsample)*0.125*((new)-(old))) | ||
618 | |||
619 | static void reverseMatrixing(float *su1, float *su2, int *pPrevCode, int *pCurrCode) | ||
620 | { | ||
621 | int i, band, nsample, s1, s2; | ||
622 | float c1, c2; | ||
623 | float mc1_l, mc1_r, mc2_l, mc2_r; | ||
624 | |||
625 | for (i=0,band = 0; band < 4*256; band+=256,i++) { | ||
626 | s1 = pPrevCode[i]; | ||
627 | s2 = pCurrCode[i]; | ||
628 | nsample = 0; | ||
629 | |||
630 | if (s1 != s2) { | ||
631 | /* Selector value changed, interpolation needed. */ | ||
632 | mc1_l = matrixCoeffs[s1*2]; | ||
633 | mc1_r = matrixCoeffs[s1*2+1]; | ||
634 | mc2_l = matrixCoeffs[s2*2]; | ||
635 | mc2_r = matrixCoeffs[s2*2+1]; | ||
636 | |||
637 | /* Interpolation is done over the first eight samples. */ | ||
638 | for(; nsample < 8; nsample++) { | ||
639 | c1 = su1[band+nsample]; | ||
640 | c2 = su2[band+nsample]; | ||
641 | c2 = c1 * INTERPOLATE(mc1_l,mc2_l,nsample) + c2 * INTERPOLATE(mc1_r,mc2_r,nsample); | ||
642 | su1[band+nsample] = c2; | ||
643 | su2[band+nsample] = c1 * 2.0 - c2; | ||
644 | } | ||
645 | } | ||
646 | |||
647 | /* Apply the matrix without interpolation. */ | ||
648 | switch (s2) { | ||
649 | case 0: /* M/S decoding */ | ||
650 | for (; nsample < 256; nsample++) { | ||
651 | c1 = su1[band+nsample]; | ||
652 | c2 = su2[band+nsample]; | ||
653 | su1[band+nsample] = c2 * 2.0; | ||
654 | su2[band+nsample] = (c1 - c2) * 2.0; | ||
655 | } | ||
656 | break; | ||
657 | |||
658 | case 1: | ||
659 | for (; nsample < 256; nsample++) { | ||
660 | c1 = su1[band+nsample]; | ||
661 | c2 = su2[band+nsample]; | ||
662 | su1[band+nsample] = (c1 + c2) * 2.0; | ||
663 | su2[band+nsample] = c2 * -2.0; | ||
664 | } | ||
665 | break; | ||
666 | case 2: | ||
667 | case 3: | ||
668 | for (; nsample < 256; nsample++) { | ||
669 | c1 = su1[band+nsample]; | ||
670 | c2 = su2[band+nsample]; | ||
671 | su1[band+nsample] = c1 + c2; | ||
672 | su2[band+nsample] = c1 - c2; | ||
673 | } | ||
674 | break; | ||
675 | default: | ||
676 | assert(0); | ||
677 | } | ||
678 | } | ||
679 | } | ||
680 | |||
681 | static void getChannelWeights (int indx, int flag, float ch[2]){ | ||
682 | |||
683 | if (indx == 7) { | ||
684 | ch[0] = 1.0; | ||
685 | ch[1] = 1.0; | ||
686 | } else { | ||
687 | ch[0] = (float)(indx & 7) / 7.0; | ||
688 | ch[1] = sqrt(2 - ch[0]*ch[0]); | ||
689 | if(flag) | ||
690 | FFSWAP(float, ch[0], ch[1]); | ||
691 | } | ||
692 | } | ||
693 | |||
694 | static void channelWeighting (float *su1, float *su2, int *p3) | ||
695 | { | ||
696 | int band, nsample; | ||
697 | /* w[x][y] y=0 is left y=1 is right */ | ||
698 | float w[2][2]; | ||
699 | |||
700 | if (p3[1] != 7 || p3[3] != 7){ | ||
701 | getChannelWeights(p3[1], p3[0], w[0]); | ||
702 | getChannelWeights(p3[3], p3[2], w[1]); | ||
703 | |||
704 | for(band = 1; band < 4; band++) { | ||
705 | /* scale the channels by the weights */ | ||
706 | for(nsample = 0; nsample < 8; nsample++) { | ||
707 | su1[band*256+nsample] *= INTERPOLATE(w[0][0], w[0][1], nsample); | ||
708 | su2[band*256+nsample] *= INTERPOLATE(w[1][0], w[1][1], nsample); | ||
709 | } | ||
710 | |||
711 | for(; nsample < 256; nsample++) { | ||
712 | su1[band*256+nsample] *= w[1][0]; | ||
713 | su2[band*256+nsample] *= w[1][1]; | ||
714 | } | ||
715 | } | ||
716 | } | ||
717 | } | ||
718 | |||
719 | |||
720 | /** | ||
721 | * Decode a Sound Unit | ||
722 | * | ||
723 | * @param gb the GetBit context | ||
724 | * @param pSnd the channel unit to be used | ||
725 | * @param pOut the decoded samples before IQMF in float representation | ||
726 | * @param channelNum channel number | ||
727 | * @param codingMode the coding mode (JOINT_STEREO or regular stereo/mono) | ||
728 | */ | ||
729 | |||
730 | |||
731 | static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode) | ||
732 | { | ||
733 | int band, result=0, numSubbands, lastTonal, numBands; | ||
734 | |||
735 | if (codingMode == JOINT_STEREO && channelNum == 1) { | ||
736 | if (get_bits(gb,2) != 3) { | ||
737 | av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n"); | ||
738 | return -1; | ||
739 | } | ||
740 | } else { | ||
741 | if (get_bits(gb,6) != 0x28) { | ||
742 | av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n"); | ||
743 | return -1; | ||
744 | } | ||
745 | } | ||
746 | |||
747 | /* number of coded QMF bands */ | ||
748 | pSnd->bandsCoded = get_bits(gb,2); | ||
749 | |||
750 | result = decodeGainControl (gb, &(pSnd->gainBlock[pSnd->gcBlkSwitch]), pSnd->bandsCoded); | ||
751 | if (result) return result; | ||
752 | |||
753 | pSnd->numComponents = decodeTonalComponents (gb, pSnd->components, pSnd->bandsCoded); | ||
754 | if (pSnd->numComponents == -1) return -1; | ||
755 | |||
756 | numSubbands = decodeSpectrum (gb, pSnd->spectrum); | ||
757 | |||
758 | /* Merge the decoded spectrum and tonal components. */ | ||
759 | lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); | ||
760 | |||
761 | |||
762 | /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */ | ||
763 | numBands = (subbandTab[numSubbands] - 1) >> 8; | ||
764 | if (lastTonal >= 0) | ||
765 | numBands = FFMAX((lastTonal + 256) >> 8, numBands); | ||
766 | |||
767 | |||
768 | /* Reconstruct time domain samples. */ | ||
769 | for (band=0; band<4; band++) { | ||
770 | /* Perform the IMDCT step without overlapping. */ | ||
771 | if (band <= numBands) { | ||
772 | IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1); | ||
773 | } else | ||
774 | memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); | ||
775 | |||
776 | /* gain compensation and overlapping */ | ||
777 | gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), | ||
778 | &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]), | ||
779 | &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band])); | ||
780 | } | ||
781 | |||
782 | /* Swap the gain control buffers for the next frame. */ | ||
783 | pSnd->gcBlkSwitch ^= 1; | ||
784 | |||
785 | return 0; | ||
786 | } | ||
787 | |||
788 | /** | ||
789 | * Frame handling | ||
790 | * | ||
791 | * @param q Atrac3 private context | ||
792 | * @param databuf the input data | ||
793 | */ | ||
794 | |||
795 | static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf) | ||
796 | { | ||
797 | int result, i; | ||
798 | float *p1, *p2, *p3, *p4; | ||
799 | uint8_t *ptr1; | ||
800 | |||
801 | if (q->codingMode == JOINT_STEREO) { | ||
802 | |||
803 | /* channel coupling mode */ | ||
804 | /* decode Sound Unit 1 */ | ||
805 | init_get_bits(&q->gb,databuf,q->bits_per_frame); | ||
806 | |||
807 | result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO); | ||
808 | if (result != 0) | ||
809 | return (result); | ||
810 | |||
811 | /* Framedata of the su2 in the joint-stereo mode is encoded in | ||
812 | * reverse byte order so we need to swap it first. */ | ||
813 | if (databuf == q->decoded_bytes_buffer) { | ||
814 | uint8_t *ptr2 = q->decoded_bytes_buffer+q->bytes_per_frame-1; | ||
815 | ptr1 = q->decoded_bytes_buffer; | ||
816 | for (i = 0; i < (q->bytes_per_frame/2); i++, ptr1++, ptr2--) { | ||
817 | FFSWAP(uint8_t,*ptr1,*ptr2); | ||
818 | } | ||
819 | } else { | ||
820 | const uint8_t *ptr2 = databuf+q->bytes_per_frame-1; | ||
821 | for (i = 0; i < q->bytes_per_frame; i++) | ||
822 | q->decoded_bytes_buffer[i] = *ptr2--; | ||
823 | } | ||
824 | |||
825 | /* Skip the sync codes (0xF8). */ | ||
826 | ptr1 = q->decoded_bytes_buffer; | ||
827 | for (i = 4; *ptr1 == 0xF8; i++, ptr1++) { | ||
828 | if (i >= q->bytes_per_frame) | ||
829 | return -1; | ||
830 | } | ||
831 | |||
832 | |||
833 | /* set the bitstream reader at the start of the second Sound Unit*/ | ||
834 | init_get_bits(&q->gb,ptr1,q->bits_per_frame); | ||
835 | |||
836 | /* Fill the Weighting coeffs delay buffer */ | ||
837 | memmove(q->weighting_delay,&(q->weighting_delay[2]),4*sizeof(int)); | ||
838 | q->weighting_delay[4] = get_bits1(&q->gb); | ||
839 | q->weighting_delay[5] = get_bits(&q->gb,3); | ||
840 | |||
841 | for (i = 0; i < 4; i++) { | ||
842 | q->matrix_coeff_index_prev[i] = q->matrix_coeff_index_now[i]; | ||
843 | q->matrix_coeff_index_now[i] = q->matrix_coeff_index_next[i]; | ||
844 | q->matrix_coeff_index_next[i] = get_bits(&q->gb,2); | ||
845 | } | ||
846 | |||
847 | /* Decode Sound Unit 2. */ | ||
848 | result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO); | ||
849 | if (result != 0) | ||
850 | return (result); | ||
851 | |||
852 | /* Reconstruct the channel coefficients. */ | ||
853 | reverseMatrixing(q->outSamples, &q->outSamples[1024], q->matrix_coeff_index_prev, q->matrix_coeff_index_now); | ||
854 | |||
855 | channelWeighting(q->outSamples, &q->outSamples[1024], q->weighting_delay); | ||
856 | |||
857 | } else { | ||
858 | /* normal stereo mode or mono */ | ||
859 | /* Decode the channel sound units. */ | ||
860 | for (i=0 ; i<q->channels ; i++) { | ||
861 | |||
862 | /* Set the bitstream reader at the start of a channel sound unit. */ | ||
863 | init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels); | ||
864 | |||
865 | result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode); | ||
866 | if (result != 0) | ||
867 | return (result); | ||
868 | } | ||
869 | } | ||
870 | |||
871 | /* Apply the iQMF synthesis filter. */ | ||
872 | p1= q->outSamples; | ||
873 | for (i=0 ; i<q->channels ; i++) { | ||
874 | p2= p1+256; | ||
875 | p3= p2+256; | ||
876 | p4= p3+256; | ||
877 | iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf); | ||
878 | iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); | ||
879 | iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); | ||
880 | p1 +=1024; | ||
881 | } | ||
882 | |||
883 | return 0; | ||
884 | } | ||
885 | |||
886 | |||
887 | /** | ||
888 | * Atrac frame decoding | ||
889 | * | ||
890 | * @param rmctx pointer to the AVCodecContext | ||
891 | */ | ||
892 | |||
893 | static int atrac3_decode_frame(RMContext *rmctx, ATRAC3Context *q, | ||
894 | void *data, int *data_size, | ||
895 | const uint8_t *buf, int buf_size) { | ||
896 | //ATRAC3Context *q = rmctx->priv_data; | ||
897 | int result = 0, i; | ||
898 | const uint8_t* databuf; | ||
899 | int16_t* samples = data; | ||
900 | |||
901 | if (buf_size < rmctx->block_align) | ||
902 | return buf_size; | ||
903 | |||
904 | /* Check if we need to descramble and what buffer to pass on. */ | ||
905 | if (q->scrambled_stream) { | ||
906 | decode_bytes(buf, q->decoded_bytes_buffer, rmctx->block_align); | ||
907 | databuf = q->decoded_bytes_buffer; | ||
908 | } else { | ||
909 | databuf = buf; | ||
910 | } | ||
911 | |||
912 | result = decodeFrame(q, databuf); | ||
913 | |||
914 | if (result != 0) { | ||
915 | av_log(NULL,AV_LOG_ERROR,"Frame decoding error!\n"); | ||
916 | return -1; | ||
917 | } | ||
918 | |||
919 | if (q->channels == 1) { | ||
920 | /* mono */ | ||
921 | for (i = 0; i<1024; i++) | ||
922 | samples[i] = av_clip_int16(round(q->outSamples[i])); | ||
923 | *data_size = 1024 * sizeof(int16_t); | ||
924 | } else { | ||
925 | /* stereo */ | ||
926 | for (i = 0; i < 1024; i++) { | ||
927 | samples[i*2] = av_clip_int16(round(q->outSamples[i])); | ||
928 | samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i])); | ||
929 | } | ||
930 | *data_size = 2048 * sizeof(int16_t); | ||
931 | } | ||
932 | |||
933 | return rmctx->block_align; | ||
934 | } | ||
935 | |||
936 | |||
937 | /** | ||
938 | * Atrac3 initialization | ||
939 | * | ||
940 | * @param rmctx pointer to the RMContext | ||
941 | */ | ||
942 | |||
943 | static av_cold int atrac3_decode_init(ATRAC3Context *q, RMContext *rmctx) | ||
944 | { | ||
945 | int i; | ||
946 | const uint8_t *edata_ptr = rmctx->codec_extradata; | ||
947 | //ATRAC3Context *q = rmctx->priv_data; | ||
948 | static VLC_TYPE atrac3_vlc_table[4096][2]; | ||
949 | static int vlcs_initialized = 0; | ||
950 | |||
951 | /* Take data from the AVCodecContext (RM container). */ | ||
952 | q->sample_rate = rmctx->sample_rate; | ||
953 | q->channels = rmctx->nb_channels; | ||
954 | q->bit_rate = rmctx->bit_rate; | ||
955 | q->bits_per_frame = rmctx->block_align * 8; | ||
956 | q->bytes_per_frame = rmctx->block_align; | ||
957 | |||
958 | /* Take care of the codec-specific extradata. */ | ||
959 | if (rmctx->extradata_size == 14) { | ||
960 | /* Parse the extradata, WAV format */ | ||
961 | av_log(rmctx,AV_LOG_DEBUG,"[0-1] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown value always 1 | ||
962 | q->samples_per_channel = bytestream_get_le32(&edata_ptr); | ||
963 | q->codingMode = bytestream_get_le16(&edata_ptr); | ||
964 | av_log(rmctx,AV_LOG_DEBUG,"[8-9] %d\n",bytestream_get_le16(&edata_ptr)); //Dupe of coding mode | ||
965 | q->frame_factor = bytestream_get_le16(&edata_ptr); //Unknown always 1 | ||
966 | av_log(rmctx,AV_LOG_DEBUG,"[12-13] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown always 0 | ||
967 | |||
968 | /* setup */ | ||
969 | q->samples_per_frame = 1024 * q->channels; | ||
970 | q->atrac3version = 4; | ||
971 | q->delay = 0x88E; | ||
972 | if (q->codingMode) | ||
973 | q->codingMode = JOINT_STEREO; | ||
974 | else | ||
975 | q->codingMode = STEREO; | ||
976 | q->scrambled_stream = 0; | ||
977 | |||
978 | if ((q->bytes_per_frame == 96*q->channels*q->frame_factor) || (q->bytes_per_frame == 152*q->channels*q->frame_factor) || (q->bytes_per_frame == 192*q->channels*q->frame_factor)) { | ||
979 | } else { | ||
980 | av_log(rmctx,AV_LOG_ERROR,"Unknown frame/channel/frame_factor configuration %d/%d/%d\n", q->bytes_per_frame, q->channels, q->frame_factor); | ||
981 | return -1; | ||
982 | } | ||
983 | |||
984 | } else if (rmctx->extradata_size == 10) { | ||
985 | /* Parse the extradata, RM format. */ | ||
986 | q->atrac3version = bytestream_get_be32(&edata_ptr); | ||
987 | q->samples_per_frame = bytestream_get_be16(&edata_ptr); | ||
988 | q->delay = bytestream_get_be16(&edata_ptr); | ||
989 | q->codingMode = bytestream_get_be16(&edata_ptr); | ||
990 | |||
991 | q->samples_per_channel = q->samples_per_frame / q->channels; | ||
992 | q->scrambled_stream = 1; | ||
993 | |||
994 | } else { | ||
995 | av_log(NULL,AV_LOG_ERROR,"Unknown extradata size %d.\n",rmctx->extradata_size); | ||
996 | } | ||
997 | /* Check the extradata. */ | ||
998 | |||
999 | if (q->atrac3version != 4) { | ||
1000 | av_log(rmctx,AV_LOG_ERROR,"Version %d != 4.\n",q->atrac3version); | ||
1001 | return -1; | ||
1002 | } | ||
1003 | |||
1004 | if (q->samples_per_frame != 1024 && q->samples_per_frame != 2048) { | ||
1005 | av_log(rmctx,AV_LOG_ERROR,"Unknown amount of samples per frame %d.\n",q->samples_per_frame); | ||
1006 | return -1; | ||
1007 | } | ||
1008 | |||
1009 | if (q->delay != 0x88E) { | ||
1010 | av_log(rmctx,AV_LOG_ERROR,"Unknown amount of delay %x != 0x88E.\n",q->delay); | ||
1011 | return -1; | ||
1012 | } | ||
1013 | |||
1014 | if (q->codingMode == STEREO) { | ||
1015 | av_log(rmctx,AV_LOG_DEBUG,"Normal stereo detected.\n"); | ||
1016 | } else if (q->codingMode == JOINT_STEREO) { | ||
1017 | av_log(rmctx,AV_LOG_DEBUG,"Joint stereo detected.\n"); | ||
1018 | } else { | ||
1019 | av_log(rmctx,AV_LOG_ERROR,"Unknown channel coding mode %x!\n",q->codingMode); | ||
1020 | return -1; | ||
1021 | } | ||
1022 | |||
1023 | if (rmctx->nb_channels <= 0 || rmctx->nb_channels > 2 /*|| ((rmctx->channels * 1024) != q->samples_per_frame)*/) { | ||
1024 | av_log(rmctx,AV_LOG_ERROR,"Channel configuration error!\n"); | ||
1025 | return -1; | ||
1026 | } | ||
1027 | |||
1028 | |||
1029 | if(rmctx->block_align >= UINT16_MAX/2) | ||
1030 | return -1; | ||
1031 | |||
1032 | /* Pad the data buffer with FF_INPUT_BUFFER_PADDING_SIZE, | ||
1033 | * this is for the bitstream reader. */ | ||
1034 | if ((q->decoded_bytes_buffer = av_mallocz((rmctx->block_align+(4-rmctx->block_align%4) + FF_INPUT_BUFFER_PADDING_SIZE))) == NULL) | ||
1035 | return AVERROR(ENOMEM); | ||
1036 | |||
1037 | |||
1038 | /* Initialize the VLC tables. */ | ||
1039 | if (!vlcs_initialized) { | ||
1040 | for (i=0 ; i<7 ; i++) { | ||
1041 | spectral_coeff_tab[i].table = &atrac3_vlc_table[atrac3_vlc_offs[i]]; | ||
1042 | spectral_coeff_tab[i].table_allocated = atrac3_vlc_offs[i + 1] - atrac3_vlc_offs[i]; | ||
1043 | init_vlc (&spectral_coeff_tab[i], 9, huff_tab_sizes[i], | ||
1044 | huff_bits[i], 1, 1, | ||
1045 | huff_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); | ||
1046 | } | ||
1047 | |||
1048 | vlcs_initialized = 1; | ||
1049 | |||
1050 | } | ||
1051 | |||
1052 | init_atrac3_transforms(q); | ||
1053 | |||
1054 | /* Generate the scale factors. */ | ||
1055 | for (i=0 ; i<64 ; i++) | ||
1056 | SFTable[i] = pow(2.0, (i - 15) / 3.0); | ||
1057 | |||
1058 | /* Generate gain tables. */ | ||
1059 | for (i=0 ; i<16 ; i++) | ||
1060 | gain_tab1[i] = powf (2.0, (4 - i)); | ||
1061 | |||
1062 | for (i=-15 ; i<16 ; i++) | ||
1063 | gain_tab2[i+15] = powf (2.0, i * -0.125); | ||
1064 | |||
1065 | /* init the joint-stereo decoding data */ | ||
1066 | q->weighting_delay[0] = 0; | ||
1067 | q->weighting_delay[1] = 7; | ||
1068 | q->weighting_delay[2] = 0; | ||
1069 | q->weighting_delay[3] = 7; | ||
1070 | q->weighting_delay[4] = 0; | ||
1071 | q->weighting_delay[5] = 7; | ||
1072 | |||
1073 | for (i=0; i<4; i++) { | ||
1074 | q->matrix_coeff_index_prev[i] = 3; | ||
1075 | q->matrix_coeff_index_now[i] = 3; | ||
1076 | q->matrix_coeff_index_next[i] = 3; | ||
1077 | } | ||
1078 | |||
1079 | dsputil_init(&dsp); | ||
1080 | |||
1081 | q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels); | ||
1082 | if (!q->pUnits) { | ||
1083 | av_free(q->decoded_bytes_buffer); | ||
1084 | return AVERROR(ENOMEM); | ||
1085 | } | ||
1086 | |||
1087 | return 0; | ||
1088 | } | ||
1089 | |||
1090 | /*************************************************************** | ||
1091 | * Following is a test program to convert from atrac/rm to wav * | ||
1092 | ***************************************************************/ | ||
1093 | static unsigned char wav_header[44]={ | ||
1094 | 'R','I','F','F',// 0 - ChunkID | ||
1095 | 0,0,0,0, // 4 - ChunkSize (filesize-8) | ||
1096 | 'W','A','V','E',// 8 - Format | ||
1097 | 'f','m','t',' ',// 12 - SubChunkID | ||
1098 | 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM | ||
1099 | 1,0, // 20 - AudioFormat (1=Uncompressed) | ||
1100 | 2,0, // 22 - NumChannels | ||
1101 | 0,0,0,0, // 24 - SampleRate in Hz | ||
1102 | 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8) | ||
1103 | 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8) | ||
1104 | 16,0, // 34 - BitsPerSample | ||
1105 | 'd','a','t','a',// 36 - Subchunk2ID | ||
1106 | 0,0,0,0 // 40 - Subchunk2Size | ||
1107 | }; | ||
1108 | |||
1109 | int open_wav(char* filename) { | ||
1110 | int fd,res; | ||
1111 | |||
1112 | fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR); | ||
1113 | if (fd >= 0) { | ||
1114 | res = write(fd,wav_header,sizeof(wav_header)); | ||
1115 | } | ||
1116 | |||
1117 | return(fd); | ||
1118 | } | ||
1119 | |||
1120 | void close_wav(int fd, RMContext *rmctx, ATRAC3Context *q) { | ||
1121 | int x,res; | ||
1122 | int filesize; | ||
1123 | int bytes_per_sample = 2; | ||
1124 | int samples_per_frame = q->samples_per_frame; | ||
1125 | int nb_channels = rmctx->nb_channels; | ||
1126 | int sample_rate = rmctx->sample_rate; | ||
1127 | int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output | ||
1128 | |||
1129 | filesize= samples_per_frame*bytes_per_sample*nb_frames +44; | ||
1130 | printf("Filesize = %d\n",filesize); | ||
1131 | |||
1132 | // ChunkSize | ||
1133 | x=filesize-8; | ||
1134 | wav_header[4]=(x&0xff); | ||
1135 | wav_header[5]=(x&0xff00)>>8; | ||
1136 | wav_header[6]=(x&0xff0000)>>16; | ||
1137 | wav_header[7]=(x&0xff000000)>>24; | ||
1138 | |||
1139 | // Number of channels | ||
1140 | wav_header[22]=nb_channels; | ||
1141 | |||
1142 | // Samplerate | ||
1143 | wav_header[24]=sample_rate&0xff; | ||
1144 | wav_header[25]=(sample_rate&0xff00)>>8; | ||
1145 | wav_header[26]=(sample_rate&0xff0000)>>16; | ||
1146 | wav_header[27]=(sample_rate&0xff000000)>>24; | ||
1147 | |||
1148 | // ByteRate | ||
1149 | x=sample_rate*bytes_per_sample*nb_channels; | ||
1150 | wav_header[28]=(x&0xff); | ||
1151 | wav_header[29]=(x&0xff00)>>8; | ||
1152 | wav_header[30]=(x&0xff0000)>>16; | ||
1153 | wav_header[31]=(x&0xff000000)>>24; | ||
1154 | |||
1155 | // BlockAlign | ||
1156 | wav_header[32]=rmctx->block_align;//2*rmctx->nb_channels; | ||
1157 | |||
1158 | // Bits per sample | ||
1159 | wav_header[34]=16; | ||
1160 | |||
1161 | // Subchunk2Size | ||
1162 | x=filesize-44; | ||
1163 | wav_header[40]=(x&0xff); | ||
1164 | wav_header[41]=(x&0xff00)>>8; | ||
1165 | wav_header[42]=(x&0xff0000)>>16; | ||
1166 | wav_header[43]=(x&0xff000000)>>24; | ||
1167 | |||
1168 | lseek(fd,0,SEEK_SET); | ||
1169 | res = write(fd,wav_header,sizeof(wav_header)); | ||
1170 | close(fd); | ||
1171 | } | ||
1172 | |||
1173 | int main(int argc, char *argv[]) | ||
1174 | { | ||
1175 | int fd, fd_dec; | ||
1176 | int res, i, datasize = 0; | ||
1177 | |||
1178 | #ifdef DUMP_RAW_FRAMES | ||
1179 | char filename[15]; | ||
1180 | int fd_out; | ||
1181 | #endif | ||
1182 | int16_t outbuf[2048]; | ||
1183 | uint16_t fs,sps,h; | ||
1184 | uint32_t packet_count; | ||
1185 | ATRAC3Context q; | ||
1186 | RMContext rmctx; | ||
1187 | RMPacket pkt; | ||
1188 | |||
1189 | memset(&q,0,sizeof(ATRAC3Context)); | ||
1190 | memset(&rmctx,0,sizeof(RMContext)); | ||
1191 | memset(&pkt,0,sizeof(RMPacket)); | ||
1192 | |||
1193 | if (argc != 2) { | ||
1194 | DEBUGF("Incorrect number of arguments\n"); | ||
1195 | return -1; | ||
1196 | } | ||
1197 | |||
1198 | fd = open(argv[1],O_RDONLY); | ||
1199 | if (fd < 0) { | ||
1200 | DEBUGF("Error opening file %s\n", argv[1]); | ||
1201 | return -1; | ||
1202 | } | ||
1203 | |||
1204 | /* copy the input rm file to a memory buffer */ | ||
1205 | uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t)); | ||
1206 | res = read(fd,filebuf,filesize(fd)); | ||
1207 | |||
1208 | fd_dec = open_wav("output.wav"); | ||
1209 | if (fd_dec < 0) { | ||
1210 | DEBUGF("Error creating output file\n"); | ||
1211 | return -1; | ||
1212 | } | ||
1213 | res = real_parse_header(fd, &rmctx); | ||
1214 | packet_count = rmctx.nb_packets; | ||
1215 | rmctx.audio_framesize = rmctx.block_align; | ||
1216 | rmctx.block_align = rmctx.sub_packet_size; | ||
1217 | fs = rmctx.audio_framesize; | ||
1218 | sps= rmctx.block_align; | ||
1219 | h = rmctx.sub_packet_h; | ||
1220 | atrac3_decode_init(&q,&rmctx); | ||
1221 | |||
1222 | /* change the buffer pointer to point at the first audio frame */ | ||
1223 | advance_buffer(&filebuf, rmctx.data_offset + DATA_HEADER_SIZE); | ||
1224 | while(packet_count) | ||
1225 | { | ||
1226 | rm_get_packet(&filebuf, &rmctx, &pkt); | ||
1227 | for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) | ||
1228 | { | ||
1229 | /* output raw audio frames that are sent to the decoder into separate files */ | ||
1230 | #ifdef DUMP_RAW_FRAMES | ||
1231 | snprintf(filename,sizeof(filename),"dump%d.raw",++x); | ||
1232 | fd_out = open(filename,O_WRONLY|O_CREAT|O_APPEND); | ||
1233 | write(fd_out,pkt.frames[i],sps); | ||
1234 | close(fd_out); | ||
1235 | #endif | ||
1236 | if(pkt.length > 0) | ||
1237 | res = atrac3_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align); | ||
1238 | rmctx.frame_number++; | ||
1239 | res = write(fd_dec,outbuf,datasize); | ||
1240 | } | ||
1241 | packet_count -= rmctx.audio_pkt_cnt; | ||
1242 | rmctx.audio_pkt_cnt = 0; | ||
1243 | } | ||
1244 | atrac3_decode_close(&q); | ||
1245 | close_wav(fd_dec, &rmctx, &q); | ||
1246 | close(fd); | ||
1247 | |||
1248 | return 0; | ||
1249 | } | ||
diff --git a/apps/codecs/libatrac/atrac3data.h b/apps/codecs/libatrac/atrac3data.h new file mode 100644 index 0000000000..e71dc35560 --- /dev/null +++ b/apps/codecs/libatrac/atrac3data.h | |||
@@ -0,0 +1,144 @@ | |||
1 | /* | ||
2 | * Atrac 3 compatible decoder data | ||
3 | * Copyright (c) 2006-2007 Maxim Poliakovski | ||
4 | * Copyright (c) 2006-2007 Benjamin Larsson | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file libavcodec/atrac3data.h | ||
25 | * Atrac 3 AKA RealAudio 8 compatible decoder data | ||
26 | */ | ||
27 | |||
28 | #ifndef AVCODEC_ATRAC3DATA_H | ||
29 | #define AVCODEC_ATRAC3DATA_H | ||
30 | |||
31 | #include <stdint.h> | ||
32 | |||
33 | /* VLC tables */ | ||
34 | |||
35 | static const uint8_t huffcode1[9] = { | ||
36 | 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, | ||
37 | }; | ||
38 | |||
39 | static const uint8_t huffbits1[9] = { | ||
40 | 1,3,3,4,4,5,5,5,5, | ||
41 | }; | ||
42 | |||
43 | static const uint8_t huffcode2[5] = { | ||
44 | 0x0,0x4,0x5,0x6,0x7, | ||
45 | }; | ||
46 | |||
47 | static const uint8_t huffbits2[5] = { | ||
48 | 1,3,3,3,3, | ||
49 | }; | ||
50 | |||
51 | static const uint8_t huffcode3[7] = { | ||
52 | 0x0,0x4,0x5,0xC,0xD,0xE,0xF, | ||
53 | }; | ||
54 | |||
55 | static const uint8_t huffbits3[7] = { | ||
56 | 1,3,3,4,4,4,4, | ||
57 | }; | ||
58 | |||
59 | static const uint8_t huffcode4[9] = { | ||
60 | 0x0,0x4,0x5,0xC,0xD,0x1C,0x1D,0x1E,0x1F, | ||
61 | }; | ||
62 | |||
63 | static const uint8_t huffbits4[9] = { | ||
64 | 1,3,3,4,4,5,5,5,5, | ||
65 | }; | ||
66 | |||
67 | static const uint8_t huffcode5[15] = { | ||
68 | 0x0,0x2,0x3,0x8,0x9,0xA,0xB,0x1C,0x1D,0x3C,0x3D,0x3E,0x3F,0xC,0xD, | ||
69 | }; | ||
70 | |||
71 | static const uint8_t huffbits5[15] = { | ||
72 | 2,3,3,4,4,4,4,5,5,6,6,6,6,4,4 | ||
73 | }; | ||
74 | |||
75 | static const uint8_t huffcode6[31] = { | ||
76 | 0x0,0x2,0x3,0x4,0x5,0x6,0x7,0x14,0x15,0x16,0x17,0x18,0x19,0x34,0x35, | ||
77 | 0x36,0x37,0x38,0x39,0x3A,0x3B,0x78,0x79,0x7A,0x7B,0x7C,0x7D,0x7E,0x7F,0x8,0x9, | ||
78 | }; | ||
79 | |||
80 | static const uint8_t huffbits6[31] = { | ||
81 | 3,4,4,4,4,4,4,5,5,5,5,5,5,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,4,4 | ||
82 | }; | ||
83 | |||
84 | static const uint8_t huffcode7[63] = { | ||
85 | 0x0,0x8,0x9,0xA,0xB,0xC,0xD,0xE,0xF,0x10,0x11,0x24,0x25,0x26,0x27,0x28, | ||
86 | 0x29,0x2A,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x68,0x69,0x6A,0x6B,0x6C, | ||
87 | 0x6D,0x6E,0x6F,0x70,0x71,0x72,0x73,0x74,0x75,0xEC,0xED,0xEE,0xEF,0xF0,0xF1,0xF2, | ||
88 | 0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x2,0x3, | ||
89 | }; | ||
90 | |||
91 | static const uint8_t huffbits7[63] = { | ||
92 | 3,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7, | ||
93 | 7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,4,4 | ||
94 | }; | ||
95 | |||
96 | static const uint8_t huff_tab_sizes[7] = { | ||
97 | 9, 5, 7, 9, 15, 31, 63, | ||
98 | }; | ||
99 | |||
100 | static const uint8_t* const huff_codes[7] = { | ||
101 | huffcode1,huffcode2,huffcode3,huffcode4,huffcode5,huffcode6,huffcode7, | ||
102 | }; | ||
103 | |||
104 | static const uint8_t* const huff_bits[7] = { | ||
105 | huffbits1,huffbits2,huffbits3,huffbits4,huffbits5,huffbits6,huffbits7, | ||
106 | }; | ||
107 | |||
108 | static const uint16_t atrac3_vlc_offs[] = { | ||
109 | 0,512,1024,1536,2048,2560,3072,3584,4096 | ||
110 | }; | ||
111 | |||
112 | /* selector tables */ | ||
113 | |||
114 | static const uint8_t CLCLengthTab[8] = {0, 4, 3, 3, 4, 4, 5, 6}; | ||
115 | static const int8_t seTab_0[4] = {0, 1, -2, -1}; | ||
116 | static const int8_t decTable1[18] = {0,0, 0,1, 0,-1, 1,0, -1,0, 1,1, 1,-1, -1,1, -1,-1}; | ||
117 | |||
118 | |||
119 | /* tables for the scalefactor decoding */ | ||
120 | |||
121 | static const float iMaxQuant[8] = { | ||
122 | 0.0, 1.0/1.5, 1.0/2.5, 1.0/3.5, 1.0/4.5, 1.0/7.5, 1.0/15.5, 1.0/31.5 | ||
123 | }; | ||
124 | |||
125 | static const uint16_t subbandTab[33] = { | ||
126 | 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, | ||
127 | 256, 288, 320, 352, 384, 416, 448, 480, 512, 576, 640, 704, 768, 896, 1024 | ||
128 | }; | ||
129 | |||
130 | /* transform data */ | ||
131 | |||
132 | static const float qmf_48tap_half[24] = { | ||
133 | -0.00001461907, -0.00009205479, -0.000056157569, 0.00030117269, | ||
134 | 0.0002422519,-0.00085293897, -0.0005205574, 0.0020340169, | ||
135 | 0.00078333891, -0.0042153862, -0.00075614988, 0.0078402944, | ||
136 | -0.000061169922, -0.01344162, 0.0024626821, 0.021736089, | ||
137 | -0.007801671, -0.034090221, 0.01880949, 0.054326009, | ||
138 | -0.043596379, -0.099384367, 0.13207909, 0.46424159 | ||
139 | }; | ||
140 | |||
141 | /* joint stereo related tables */ | ||
142 | static const float matrixCoeffs[8] = {0.0, 2.0, 2.0, 2.0, 0.0, 0.0, 1.0, 1.0}; | ||
143 | |||
144 | #endif /* AVCODEC_ATRAC3DATA_H */ | ||
diff --git a/apps/codecs/libatrac/avcodec.h b/apps/codecs/libatrac/avcodec.h new file mode 100644 index 0000000000..ed1bdecfce --- /dev/null +++ b/apps/codecs/libatrac/avcodec.h | |||
@@ -0,0 +1,3433 @@ | |||
1 | /* | ||
2 | * copyright (c) 2001 Fabrice Bellard | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #ifndef AVCODEC_AVCODEC_H | ||
22 | #define AVCODEC_AVCODEC_H | ||
23 | |||
24 | /** | ||
25 | * @file libavcodec/avcodec.h | ||
26 | * external API header | ||
27 | */ | ||
28 | |||
29 | #include <errno.h> | ||
30 | #include "libavutil/avutil.h" | ||
31 | |||
32 | #define LIBAVCODEC_VERSION_MAJOR 52 | ||
33 | #define LIBAVCODEC_VERSION_MINOR 22 | ||
34 | #define LIBAVCODEC_VERSION_MICRO 0 | ||
35 | |||
36 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | ||
37 | LIBAVCODEC_VERSION_MINOR, \ | ||
38 | LIBAVCODEC_VERSION_MICRO) | ||
39 | #define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \ | ||
40 | LIBAVCODEC_VERSION_MINOR, \ | ||
41 | LIBAVCODEC_VERSION_MICRO) | ||
42 | #define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT | ||
43 | |||
44 | #define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) | ||
45 | |||
46 | #define AV_NOPTS_VALUE INT64_C(0x8000000000000000) | ||
47 | #define AV_TIME_BASE 1000000 | ||
48 | #define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE} | ||
49 | |||
50 | /** | ||
51 | * Identifies the syntax and semantics of the bitstream. | ||
52 | * The principle is roughly: | ||
53 | * Two decoders with the same ID can decode the same streams. | ||
54 | * Two encoders with the same ID can encode compatible streams. | ||
55 | * There may be slight deviations from the principle due to implementation | ||
56 | * details. | ||
57 | * | ||
58 | * If you add a codec ID to this list, add it so that | ||
59 | * 1. no value of a existing codec ID changes (that would break ABI), | ||
60 | * 2. it is as close as possible to similar codecs. | ||
61 | */ | ||
62 | enum CodecID { | ||
63 | CODEC_ID_NONE, | ||
64 | |||
65 | /* video codecs */ | ||
66 | CODEC_ID_MPEG1VIDEO, | ||
67 | CODEC_ID_MPEG2VIDEO, ///< preferred ID for MPEG-1/2 video decoding | ||
68 | CODEC_ID_MPEG2VIDEO_XVMC, | ||
69 | CODEC_ID_H261, | ||
70 | CODEC_ID_H263, | ||
71 | CODEC_ID_RV10, | ||
72 | CODEC_ID_RV20, | ||
73 | CODEC_ID_MJPEG, | ||
74 | CODEC_ID_MJPEGB, | ||
75 | CODEC_ID_LJPEG, | ||
76 | CODEC_ID_SP5X, | ||
77 | CODEC_ID_JPEGLS, | ||
78 | CODEC_ID_MPEG4, | ||
79 | CODEC_ID_RAWVIDEO, | ||
80 | CODEC_ID_MSMPEG4V1, | ||
81 | CODEC_ID_MSMPEG4V2, | ||
82 | CODEC_ID_MSMPEG4V3, | ||
83 | CODEC_ID_WMV1, | ||
84 | CODEC_ID_WMV2, | ||
85 | CODEC_ID_H263P, | ||
86 | CODEC_ID_H263I, | ||
87 | CODEC_ID_FLV1, | ||
88 | CODEC_ID_SVQ1, | ||
89 | CODEC_ID_SVQ3, | ||
90 | CODEC_ID_DVVIDEO, | ||
91 | CODEC_ID_HUFFYUV, | ||
92 | CODEC_ID_CYUV, | ||
93 | CODEC_ID_H264, | ||
94 | CODEC_ID_INDEO3, | ||
95 | CODEC_ID_VP3, | ||
96 | CODEC_ID_THEORA, | ||
97 | CODEC_ID_ASV1, | ||
98 | CODEC_ID_ASV2, | ||
99 | CODEC_ID_FFV1, | ||
100 | CODEC_ID_4XM, | ||
101 | CODEC_ID_VCR1, | ||
102 | CODEC_ID_CLJR, | ||
103 | CODEC_ID_MDEC, | ||
104 | CODEC_ID_ROQ, | ||
105 | CODEC_ID_INTERPLAY_VIDEO, | ||
106 | CODEC_ID_XAN_WC3, | ||
107 | CODEC_ID_XAN_WC4, | ||
108 | CODEC_ID_RPZA, | ||
109 | CODEC_ID_CINEPAK, | ||
110 | CODEC_ID_WS_VQA, | ||
111 | CODEC_ID_MSRLE, | ||
112 | CODEC_ID_MSVIDEO1, | ||
113 | CODEC_ID_IDCIN, | ||
114 | CODEC_ID_8BPS, | ||
115 | CODEC_ID_SMC, | ||
116 | CODEC_ID_FLIC, | ||
117 | CODEC_ID_TRUEMOTION1, | ||
118 | CODEC_ID_VMDVIDEO, | ||
119 | CODEC_ID_MSZH, | ||
120 | CODEC_ID_ZLIB, | ||
121 | CODEC_ID_QTRLE, | ||
122 | CODEC_ID_SNOW, | ||
123 | CODEC_ID_TSCC, | ||
124 | CODEC_ID_ULTI, | ||
125 | CODEC_ID_QDRAW, | ||
126 | CODEC_ID_VIXL, | ||
127 | CODEC_ID_QPEG, | ||
128 | CODEC_ID_XVID, | ||
129 | CODEC_ID_PNG, | ||
130 | CODEC_ID_PPM, | ||
131 | CODEC_ID_PBM, | ||
132 | CODEC_ID_PGM, | ||
133 | CODEC_ID_PGMYUV, | ||
134 | CODEC_ID_PAM, | ||
135 | CODEC_ID_FFVHUFF, | ||
136 | CODEC_ID_RV30, | ||
137 | CODEC_ID_RV40, | ||
138 | CODEC_ID_VC1, | ||
139 | CODEC_ID_WMV3, | ||
140 | CODEC_ID_LOCO, | ||
141 | CODEC_ID_WNV1, | ||
142 | CODEC_ID_AASC, | ||
143 | CODEC_ID_INDEO2, | ||
144 | CODEC_ID_FRAPS, | ||
145 | CODEC_ID_TRUEMOTION2, | ||
146 | CODEC_ID_BMP, | ||
147 | CODEC_ID_CSCD, | ||
148 | CODEC_ID_MMVIDEO, | ||
149 | CODEC_ID_ZMBV, | ||
150 | CODEC_ID_AVS, | ||
151 | CODEC_ID_SMACKVIDEO, | ||
152 | CODEC_ID_NUV, | ||
153 | CODEC_ID_KMVC, | ||
154 | CODEC_ID_FLASHSV, | ||
155 | CODEC_ID_CAVS, | ||
156 | CODEC_ID_JPEG2000, | ||
157 | CODEC_ID_VMNC, | ||
158 | CODEC_ID_VP5, | ||
159 | CODEC_ID_VP6, | ||
160 | CODEC_ID_VP6F, | ||
161 | CODEC_ID_TARGA, | ||
162 | CODEC_ID_DSICINVIDEO, | ||
163 | CODEC_ID_TIERTEXSEQVIDEO, | ||
164 | CODEC_ID_TIFF, | ||
165 | CODEC_ID_GIF, | ||
166 | CODEC_ID_FFH264, | ||
167 | CODEC_ID_DXA, | ||
168 | CODEC_ID_DNXHD, | ||
169 | CODEC_ID_THP, | ||
170 | CODEC_ID_SGI, | ||
171 | CODEC_ID_C93, | ||
172 | CODEC_ID_BETHSOFTVID, | ||
173 | CODEC_ID_PTX, | ||
174 | CODEC_ID_TXD, | ||
175 | CODEC_ID_VP6A, | ||
176 | CODEC_ID_AMV, | ||
177 | CODEC_ID_VB, | ||
178 | CODEC_ID_PCX, | ||
179 | CODEC_ID_SUNRAST, | ||
180 | CODEC_ID_INDEO4, | ||
181 | CODEC_ID_INDEO5, | ||
182 | CODEC_ID_MIMIC, | ||
183 | CODEC_ID_RL2, | ||
184 | CODEC_ID_8SVX_EXP, | ||
185 | CODEC_ID_8SVX_FIB, | ||
186 | CODEC_ID_ESCAPE124, | ||
187 | CODEC_ID_DIRAC, | ||
188 | CODEC_ID_BFI, | ||
189 | CODEC_ID_CMV, | ||
190 | CODEC_ID_MOTIONPIXELS, | ||
191 | CODEC_ID_TGV, | ||
192 | CODEC_ID_TGQ, | ||
193 | CODEC_ID_TQI, | ||
194 | |||
195 | /* various PCM "codecs" */ | ||
196 | CODEC_ID_PCM_S16LE= 0x10000, | ||
197 | CODEC_ID_PCM_S16BE, | ||
198 | CODEC_ID_PCM_U16LE, | ||
199 | CODEC_ID_PCM_U16BE, | ||
200 | CODEC_ID_PCM_S8, | ||
201 | CODEC_ID_PCM_U8, | ||
202 | CODEC_ID_PCM_MULAW, | ||
203 | CODEC_ID_PCM_ALAW, | ||
204 | CODEC_ID_PCM_S32LE, | ||
205 | CODEC_ID_PCM_S32BE, | ||
206 | CODEC_ID_PCM_U32LE, | ||
207 | CODEC_ID_PCM_U32BE, | ||
208 | CODEC_ID_PCM_S24LE, | ||
209 | CODEC_ID_PCM_S24BE, | ||
210 | CODEC_ID_PCM_U24LE, | ||
211 | CODEC_ID_PCM_U24BE, | ||
212 | CODEC_ID_PCM_S24DAUD, | ||
213 | CODEC_ID_PCM_ZORK, | ||
214 | CODEC_ID_PCM_S16LE_PLANAR, | ||
215 | CODEC_ID_PCM_DVD, | ||
216 | CODEC_ID_PCM_F32BE, | ||
217 | CODEC_ID_PCM_F32LE, | ||
218 | CODEC_ID_PCM_F64BE, | ||
219 | CODEC_ID_PCM_F64LE, | ||
220 | |||
221 | /* various ADPCM codecs */ | ||
222 | CODEC_ID_ADPCM_IMA_QT= 0x11000, | ||
223 | CODEC_ID_ADPCM_IMA_WAV, | ||
224 | CODEC_ID_ADPCM_IMA_DK3, | ||
225 | CODEC_ID_ADPCM_IMA_DK4, | ||
226 | CODEC_ID_ADPCM_IMA_WS, | ||
227 | CODEC_ID_ADPCM_IMA_SMJPEG, | ||
228 | CODEC_ID_ADPCM_MS, | ||
229 | CODEC_ID_ADPCM_4XM, | ||
230 | CODEC_ID_ADPCM_XA, | ||
231 | CODEC_ID_ADPCM_ADX, | ||
232 | CODEC_ID_ADPCM_EA, | ||
233 | CODEC_ID_ADPCM_G726, | ||
234 | CODEC_ID_ADPCM_CT, | ||
235 | CODEC_ID_ADPCM_SWF, | ||
236 | CODEC_ID_ADPCM_YAMAHA, | ||
237 | CODEC_ID_ADPCM_SBPRO_4, | ||
238 | CODEC_ID_ADPCM_SBPRO_3, | ||
239 | CODEC_ID_ADPCM_SBPRO_2, | ||
240 | CODEC_ID_ADPCM_THP, | ||
241 | CODEC_ID_ADPCM_IMA_AMV, | ||
242 | CODEC_ID_ADPCM_EA_R1, | ||
243 | CODEC_ID_ADPCM_EA_R3, | ||
244 | CODEC_ID_ADPCM_EA_R2, | ||
245 | CODEC_ID_ADPCM_IMA_EA_SEAD, | ||
246 | CODEC_ID_ADPCM_IMA_EA_EACS, | ||
247 | CODEC_ID_ADPCM_EA_XAS, | ||
248 | CODEC_ID_ADPCM_EA_MAXIS_XA, | ||
249 | CODEC_ID_ADPCM_IMA_ISS, | ||
250 | |||
251 | /* AMR */ | ||
252 | CODEC_ID_AMR_NB= 0x12000, | ||
253 | CODEC_ID_AMR_WB, | ||
254 | |||
255 | /* RealAudio codecs*/ | ||
256 | CODEC_ID_RA_144= 0x13000, | ||
257 | CODEC_ID_RA_288, | ||
258 | |||
259 | /* various DPCM codecs */ | ||
260 | CODEC_ID_ROQ_DPCM= 0x14000, | ||
261 | CODEC_ID_INTERPLAY_DPCM, | ||
262 | CODEC_ID_XAN_DPCM, | ||
263 | CODEC_ID_SOL_DPCM, | ||
264 | |||
265 | /* audio codecs */ | ||
266 | CODEC_ID_MP2= 0x15000, | ||
267 | CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3 | ||
268 | CODEC_ID_AAC, | ||
269 | CODEC_ID_AC3, | ||
270 | CODEC_ID_DTS, | ||
271 | CODEC_ID_VORBIS, | ||
272 | CODEC_ID_DVAUDIO, | ||
273 | CODEC_ID_WMAV1, | ||
274 | CODEC_ID_WMAV2, | ||
275 | CODEC_ID_MACE3, | ||
276 | CODEC_ID_MACE6, | ||
277 | CODEC_ID_VMDAUDIO, | ||
278 | CODEC_ID_SONIC, | ||
279 | CODEC_ID_SONIC_LS, | ||
280 | CODEC_ID_FLAC, | ||
281 | CODEC_ID_MP3ADU, | ||
282 | CODEC_ID_MP3ON4, | ||
283 | CODEC_ID_SHORTEN, | ||
284 | CODEC_ID_ALAC, | ||
285 | CODEC_ID_WESTWOOD_SND1, | ||
286 | CODEC_ID_GSM, ///< as in Berlin toast format | ||
287 | CODEC_ID_QDM2, | ||
288 | CODEC_ID_COOK, | ||
289 | CODEC_ID_TRUESPEECH, | ||
290 | CODEC_ID_TTA, | ||
291 | CODEC_ID_SMACKAUDIO, | ||
292 | CODEC_ID_QCELP, | ||
293 | CODEC_ID_WAVPACK, | ||
294 | CODEC_ID_DSICINAUDIO, | ||
295 | CODEC_ID_IMC, | ||
296 | CODEC_ID_MUSEPACK7, | ||
297 | CODEC_ID_MLP, | ||
298 | CODEC_ID_GSM_MS, /* as found in WAV */ | ||
299 | CODEC_ID_ATRAC3, | ||
300 | CODEC_ID_VOXWARE, | ||
301 | CODEC_ID_APE, | ||
302 | CODEC_ID_NELLYMOSER, | ||
303 | CODEC_ID_MUSEPACK8, | ||
304 | CODEC_ID_SPEEX, | ||
305 | CODEC_ID_WMAVOICE, | ||
306 | CODEC_ID_WMAPRO, | ||
307 | CODEC_ID_WMALOSSLESS, | ||
308 | CODEC_ID_ATRAC3P, | ||
309 | CODEC_ID_EAC3, | ||
310 | CODEC_ID_SIPR, | ||
311 | CODEC_ID_MP1, | ||
312 | CODEC_ID_TWINVQ, | ||
313 | CODEC_ID_TRUEHD, | ||
314 | |||
315 | /* subtitle codecs */ | ||
316 | CODEC_ID_DVD_SUBTITLE= 0x17000, | ||
317 | CODEC_ID_DVB_SUBTITLE, | ||
318 | CODEC_ID_TEXT, ///< raw UTF-8 text | ||
319 | CODEC_ID_XSUB, | ||
320 | CODEC_ID_SSA, | ||
321 | CODEC_ID_MOV_TEXT, | ||
322 | |||
323 | /* other specific kind of codecs (generally used for attachments) */ | ||
324 | CODEC_ID_TTF= 0x18000, | ||
325 | |||
326 | CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it | ||
327 | |||
328 | CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS | ||
329 | * stream (only used by libavformat) */ | ||
330 | }; | ||
331 | |||
332 | enum CodecType { | ||
333 | CODEC_TYPE_UNKNOWN = -1, | ||
334 | CODEC_TYPE_VIDEO, | ||
335 | CODEC_TYPE_AUDIO, | ||
336 | CODEC_TYPE_DATA, | ||
337 | CODEC_TYPE_SUBTITLE, | ||
338 | CODEC_TYPE_ATTACHMENT, | ||
339 | CODEC_TYPE_NB | ||
340 | }; | ||
341 | |||
342 | /** | ||
343 | * all in native-endian format | ||
344 | */ | ||
345 | enum SampleFormat { | ||
346 | SAMPLE_FMT_NONE = -1, | ||
347 | SAMPLE_FMT_U8, ///< unsigned 8 bits | ||
348 | SAMPLE_FMT_S16, ///< signed 16 bits | ||
349 | SAMPLE_FMT_S32, ///< signed 32 bits | ||
350 | SAMPLE_FMT_FLT, ///< float | ||
351 | SAMPLE_FMT_DBL, ///< double | ||
352 | SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcodec | ||
353 | }; | ||
354 | |||
355 | /* Audio channel masks */ | ||
356 | #define CH_FRONT_LEFT 0x00000001 | ||
357 | #define CH_FRONT_RIGHT 0x00000002 | ||
358 | #define CH_FRONT_CENTER 0x00000004 | ||
359 | #define CH_LOW_FREQUENCY 0x00000008 | ||
360 | #define CH_BACK_LEFT 0x00000010 | ||
361 | #define CH_BACK_RIGHT 0x00000020 | ||
362 | #define CH_FRONT_LEFT_OF_CENTER 0x00000040 | ||
363 | #define CH_FRONT_RIGHT_OF_CENTER 0x00000080 | ||
364 | #define CH_BACK_CENTER 0x00000100 | ||
365 | #define CH_SIDE_LEFT 0x00000200 | ||
366 | #define CH_SIDE_RIGHT 0x00000400 | ||
367 | #define CH_TOP_CENTER 0x00000800 | ||
368 | #define CH_TOP_FRONT_LEFT 0x00001000 | ||
369 | #define CH_TOP_FRONT_CENTER 0x00002000 | ||
370 | #define CH_TOP_FRONT_RIGHT 0x00004000 | ||
371 | #define CH_TOP_BACK_LEFT 0x00008000 | ||
372 | #define CH_TOP_BACK_CENTER 0x00010000 | ||
373 | #define CH_TOP_BACK_RIGHT 0x00020000 | ||
374 | #define CH_STEREO_LEFT 0x20000000 ///< Stereo downmix. | ||
375 | #define CH_STEREO_RIGHT 0x40000000 ///< See CH_STEREO_LEFT. | ||
376 | |||
377 | /* Audio channel convenience macros */ | ||
378 | #define CH_LAYOUT_MONO (CH_FRONT_CENTER) | ||
379 | #define CH_LAYOUT_STEREO (CH_FRONT_LEFT|CH_FRONT_RIGHT) | ||
380 | #define CH_LAYOUT_SURROUND (CH_LAYOUT_STEREO|CH_FRONT_CENTER) | ||
381 | #define CH_LAYOUT_QUAD (CH_LAYOUT_STEREO|CH_BACK_LEFT|CH_BACK_RIGHT) | ||
382 | #define CH_LAYOUT_5POINT0 (CH_LAYOUT_SURROUND|CH_SIDE_LEFT|CH_SIDE_RIGHT) | ||
383 | #define CH_LAYOUT_5POINT1 (CH_LAYOUT_5POINT0|CH_LOW_FREQUENCY) | ||
384 | #define CH_LAYOUT_7POINT1 (CH_LAYOUT_5POINT1|CH_BACK_LEFT|CH_BACK_RIGHT) | ||
385 | #define CH_LAYOUT_7POINT1_WIDE (CH_LAYOUT_SURROUND|CH_LOW_FREQUENCY|\ | ||
386 | CH_BACK_LEFT|CH_BACK_RIGHT|\ | ||
387 | CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) | ||
388 | #define CH_LAYOUT_STEREO_DOWNMIX (CH_STEREO_LEFT|CH_STEREO_RIGHT) | ||
389 | |||
390 | /* in bytes */ | ||
391 | #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio | ||
392 | |||
393 | /** | ||
394 | * Required number of additionally allocated bytes at the end of the input bitstream for decoding. | ||
395 | * This is mainly needed because some optimized bitstream readers read | ||
396 | * 32 or 64 bit at once and could read over the end.<br> | ||
397 | * Note: If the first 23 bits of the additional bytes are not 0, then damaged | ||
398 | * MPEG bitstreams could cause overread and segfault. | ||
399 | */ | ||
400 | #define FF_INPUT_BUFFER_PADDING_SIZE 8 | ||
401 | |||
402 | /** | ||
403 | * minimum encoding buffer size | ||
404 | * Used to avoid some checks during header writing. | ||
405 | */ | ||
406 | #define FF_MIN_BUFFER_SIZE 16384 | ||
407 | |||
408 | #if 0/* MT : DELETE THIS LINE.*/ | ||
409 | /** | ||
410 | * motion estimation type. | ||
411 | */ | ||
412 | enum Motion_Est_ID { | ||
413 | ME_ZERO = 1, ///< no search, that is use 0,0 vector whenever one is needed | ||
414 | ME_FULL, | ||
415 | ME_LOG, | ||
416 | ME_PHODS, | ||
417 | ME_EPZS, ///< enhanced predictive zonal search | ||
418 | ME_X1, ///< reserved for experiments | ||
419 | ME_HEX, ///< hexagon based search | ||
420 | ME_UMH, ///< uneven multi-hexagon search | ||
421 | ME_ITER, ///< iterative search | ||
422 | ME_TESA, ///< transformed exhaustive search algorithm | ||
423 | }; | ||
424 | |||
425 | enum AVDiscard{ | ||
426 | /* We leave some space between them for extensions (drop some | ||
427 | * keyframes for intra-only or drop just some bidir frames). */ | ||
428 | AVDISCARD_NONE =-16, ///< discard nothing | ||
429 | AVDISCARD_DEFAULT= 0, ///< discard useless packets like 0 size packets in avi | ||
430 | AVDISCARD_NONREF = 8, ///< discard all non reference | ||
431 | AVDISCARD_BIDIR = 16, ///< discard all bidirectional frames | ||
432 | AVDISCARD_NONKEY = 32, ///< discard all frames except keyframes | ||
433 | AVDISCARD_ALL = 48, ///< discard all | ||
434 | }; | ||
435 | |||
436 | typedef struct RcOverride{ | ||
437 | int start_frame; | ||
438 | int end_frame; | ||
439 | int qscale; // If this is 0 then quality_factor will be used instead. | ||
440 | float quality_factor; | ||
441 | } RcOverride; | ||
442 | |||
443 | #define FF_MAX_B_FRAMES 16 | ||
444 | |||
445 | /* encoding support | ||
446 | These flags can be passed in AVCodecContext.flags before initialization. | ||
447 | Note: Not everything is supported yet. | ||
448 | */ | ||
449 | |||
450 | #define CODEC_FLAG_QSCALE 0x0002 ///< Use fixed qscale. | ||
451 | #define CODEC_FLAG_4MV 0x0004 ///< 4 MV per MB allowed / advanced prediction for H.263. | ||
452 | #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC. | ||
453 | #define CODEC_FLAG_GMC 0x0020 ///< Use GMC. | ||
454 | #define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>. | ||
455 | #define CODEC_FLAG_PART 0x0080 ///< Use data partitioning. | ||
456 | /** | ||
457 | * The parent program guarantees that the input for B-frames containing | ||
458 | * streams is not written to for at least s->max_b_frames+1 frames, if | ||
459 | * this is not set the input will be copied. | ||
460 | */ | ||
461 | #define CODEC_FLAG_INPUT_PRESERVED 0x0100 | ||
462 | #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode. | ||
463 | #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode. | ||
464 | #define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG). | ||
465 | #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale. | ||
466 | #define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges. | ||
467 | #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding. | ||
468 | #define CODEC_FLAG_TRUNCATED 0x00010000 /** Input bitstream might be truncated at a random | ||
469 | location instead of only at frame boundaries. */ | ||
470 | #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization. | ||
471 | #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT. | ||
472 | #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay. | ||
473 | #define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan. | ||
474 | #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe. | ||
475 | #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT). | ||
476 | /* Fx : Flag for h263+ extra options */ | ||
477 | #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction | ||
478 | #define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector | ||
479 | #define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. | ||
480 | #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon. | ||
481 | #define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC | ||
482 | #define CODEC_FLAG_OBMC 0x00000001 ///< OBMC | ||
483 | #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter | ||
484 | #define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 | ||
485 | #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation | ||
486 | #define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data. | ||
487 | #define CODEC_FLAG_CLOSED_GOP 0x80000000 | ||
488 | #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks. | ||
489 | #define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size. | ||
490 | #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding. | ||
491 | #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata. | ||
492 | #define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references. | ||
493 | #define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames | ||
494 | #define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock | ||
495 | #define CODEC_FLAG2_8X8DCT 0x00000080 ///< H.264 high profile 8x8 transform | ||
496 | #define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip | ||
497 | #define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters | ||
498 | #define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization | ||
499 | #define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table. | ||
500 | #define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC). | ||
501 | #define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. | ||
502 | #define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping | ||
503 | #define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries. | ||
504 | #define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer. | ||
505 | #define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible | ||
506 | |||
507 | /* Unsupported options : | ||
508 | * Syntax Arithmetic coding (SAC) | ||
509 | * Reference Picture Selection | ||
510 | * Independent Segment Decoding */ | ||
511 | /* /Fx */ | ||
512 | /* codec capabilities */ | ||
513 | |||
514 | #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 ///< Decoder can use draw_horiz_band callback. | ||
515 | /** | ||
516 | * Codec uses get_buffer() for allocating buffers. | ||
517 | * direct rendering method 1 | ||
518 | */ | ||
519 | #define CODEC_CAP_DR1 0x0002 | ||
520 | /* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */ | ||
521 | #define CODEC_CAP_PARSE_ONLY 0x0004 | ||
522 | #define CODEC_CAP_TRUNCATED 0x0008 | ||
523 | /* Codec can export data for HW decoding (XvMC). */ | ||
524 | #define CODEC_CAP_HWACCEL 0x0010 | ||
525 | /** | ||
526 | * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data. | ||
527 | * If this is not set, the codec is guaranteed to never be fed with NULL data. | ||
528 | */ | ||
529 | #define CODEC_CAP_DELAY 0x0020 | ||
530 | /** | ||
531 | * Codec can be fed a final frame with a smaller size. | ||
532 | * This can be used to prevent truncation of the last audio samples. | ||
533 | */ | ||
534 | #define CODEC_CAP_SMALL_LAST_FRAME 0x0040 | ||
535 | /** | ||
536 | * Codec can export data for HW decoding (VDPAU). | ||
537 | */ | ||
538 | #define CODEC_CAP_HWACCEL_VDPAU 0x0080 | ||
539 | |||
540 | //The following defines may change, don't expect compatibility if you use them. | ||
541 | #define MB_TYPE_INTRA4x4 0x0001 | ||
542 | #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific | ||
543 | #define MB_TYPE_INTRA_PCM 0x0004 //FIXME H.264-specific | ||
544 | #define MB_TYPE_16x16 0x0008 | ||
545 | #define MB_TYPE_16x8 0x0010 | ||
546 | #define MB_TYPE_8x16 0x0020 | ||
547 | #define MB_TYPE_8x8 0x0040 | ||
548 | #define MB_TYPE_INTERLACED 0x0080 | ||
549 | #define MB_TYPE_DIRECT2 0x0100 //FIXME | ||
550 | #define MB_TYPE_ACPRED 0x0200 | ||
551 | #define MB_TYPE_GMC 0x0400 | ||
552 | #define MB_TYPE_SKIP 0x0800 | ||
553 | #define MB_TYPE_P0L0 0x1000 | ||
554 | #define MB_TYPE_P1L0 0x2000 | ||
555 | #define MB_TYPE_P0L1 0x4000 | ||
556 | #define MB_TYPE_P1L1 0x8000 | ||
557 | #define MB_TYPE_L0 (MB_TYPE_P0L0 | MB_TYPE_P1L0) | ||
558 | #define MB_TYPE_L1 (MB_TYPE_P0L1 | MB_TYPE_P1L1) | ||
559 | #define MB_TYPE_L0L1 (MB_TYPE_L0 | MB_TYPE_L1) | ||
560 | #define MB_TYPE_QUANT 0x00010000 | ||
561 | #define MB_TYPE_CBP 0x00020000 | ||
562 | //Note bits 24-31 are reserved for codec specific use (h264 ref0, mpeg1 0mv, ...) | ||
563 | |||
564 | /** | ||
565 | * Pan Scan area. | ||
566 | * This specifies the area which should be displayed. | ||
567 | * Note there may be multiple such areas for one frame. | ||
568 | */ | ||
569 | typedef struct AVPanScan{ | ||
570 | /** | ||
571 | * id | ||
572 | * - encoding: Set by user. | ||
573 | * - decoding: Set by libavcodec. | ||
574 | */ | ||
575 | int id; | ||
576 | |||
577 | /** | ||
578 | * width and height in 1/16 pel | ||
579 | * - encoding: Set by user. | ||
580 | * - decoding: Set by libavcodec. | ||
581 | */ | ||
582 | int width; | ||
583 | int height; | ||
584 | |||
585 | /** | ||
586 | * position of the top left corner in 1/16 pel for up to 3 fields/frames | ||
587 | * - encoding: Set by user. | ||
588 | * - decoding: Set by libavcodec. | ||
589 | */ | ||
590 | int16_t position[3][2]; | ||
591 | }AVPanScan; | ||
592 | |||
593 | #define FF_COMMON_FRAME \ | ||
594 | /**\ | ||
595 | * pointer to the picture planes.\ | ||
596 | * This might be different from the first allocated byte\ | ||
597 | * - encoding: \ | ||
598 | * - decoding: \ | ||
599 | */\ | ||
600 | uint8_t *data[4];\ | ||
601 | int linesize[4];\ | ||
602 | /**\ | ||
603 | * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\ | ||
604 | * This isn't used by libavcodec unless the default get/release_buffer() is used.\ | ||
605 | * - encoding: \ | ||
606 | * - decoding: \ | ||
607 | */\ | ||
608 | uint8_t *base[4];\ | ||
609 | /**\ | ||
610 | * 1 -> keyframe, 0-> not\ | ||
611 | * - encoding: Set by libavcodec.\ | ||
612 | * - decoding: Set by libavcodec.\ | ||
613 | */\ | ||
614 | int key_frame;\ | ||
615 | \ | ||
616 | /**\ | ||
617 | * Picture type of the frame, see ?_TYPE below.\ | ||
618 | * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ | ||
619 | * - decoding: Set by libavcodec.\ | ||
620 | */\ | ||
621 | int pict_type;\ | ||
622 | \ | ||
623 | /**\ | ||
624 | * presentation timestamp in time_base units (time when frame should be shown to user)\ | ||
625 | * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\ | ||
626 | * - encoding: MUST be set by user.\ | ||
627 | * - decoding: Set by libavcodec.\ | ||
628 | */\ | ||
629 | int64_t pts;\ | ||
630 | \ | ||
631 | /**\ | ||
632 | * picture number in bitstream order\ | ||
633 | * - encoding: set by\ | ||
634 | * - decoding: Set by libavcodec.\ | ||
635 | */\ | ||
636 | int coded_picture_number;\ | ||
637 | /**\ | ||
638 | * picture number in display order\ | ||
639 | * - encoding: set by\ | ||
640 | * - decoding: Set by libavcodec.\ | ||
641 | */\ | ||
642 | int display_picture_number;\ | ||
643 | \ | ||
644 | /**\ | ||
645 | * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \ | ||
646 | * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ | ||
647 | * - decoding: Set by libavcodec.\ | ||
648 | */\ | ||
649 | int quality; \ | ||
650 | \ | ||
651 | /**\ | ||
652 | * buffer age (1->was last buffer and dint change, 2->..., ...).\ | ||
653 | * Set to INT_MAX if the buffer has not been used yet.\ | ||
654 | * - encoding: unused\ | ||
655 | * - decoding: MUST be set by get_buffer().\ | ||
656 | */\ | ||
657 | int age;\ | ||
658 | \ | ||
659 | /**\ | ||
660 | * is this picture used as reference\ | ||
661 | * The values for this are the same as the MpegEncContext.picture_structure\ | ||
662 | * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\ | ||
663 | * Set to 4 for delayed, non-reference frames.\ | ||
664 | * - encoding: unused\ | ||
665 | * - decoding: Set by libavcodec. (before get_buffer() call)).\ | ||
666 | */\ | ||
667 | int reference;\ | ||
668 | \ | ||
669 | /**\ | ||
670 | * QP table\ | ||
671 | * - encoding: unused\ | ||
672 | * - decoding: Set by libavcodec.\ | ||
673 | */\ | ||
674 | int8_t *qscale_table;\ | ||
675 | /**\ | ||
676 | * QP store stride\ | ||
677 | * - encoding: unused\ | ||
678 | * - decoding: Set by libavcodec.\ | ||
679 | */\ | ||
680 | int qstride;\ | ||
681 | \ | ||
682 | /**\ | ||
683 | * mbskip_table[mb]>=1 if MB didn't change\ | ||
684 | * stride= mb_width = (width+15)>>4\ | ||
685 | * - encoding: unused\ | ||
686 | * - decoding: Set by libavcodec.\ | ||
687 | */\ | ||
688 | uint8_t *mbskip_table;\ | ||
689 | \ | ||
690 | /**\ | ||
691 | * motion vector table\ | ||
692 | * @code\ | ||
693 | * example:\ | ||
694 | * int mv_sample_log2= 4 - motion_subsample_log2;\ | ||
695 | * int mb_width= (width+15)>>4;\ | ||
696 | * int mv_stride= (mb_width << mv_sample_log2) + 1;\ | ||
697 | * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\ | ||
698 | * @endcode\ | ||
699 | * - encoding: Set by user.\ | ||
700 | * - decoding: Set by libavcodec.\ | ||
701 | */\ | ||
702 | int16_t (*motion_val[2])[2];\ | ||
703 | \ | ||
704 | /**\ | ||
705 | * macroblock type table\ | ||
706 | * mb_type_base + mb_width + 2\ | ||
707 | * - encoding: Set by user.\ | ||
708 | * - decoding: Set by libavcodec.\ | ||
709 | */\ | ||
710 | uint32_t *mb_type;\ | ||
711 | \ | ||
712 | /**\ | ||
713 | * log2 of the size of the block which a single vector in motion_val represents: \ | ||
714 | * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\ | ||
715 | * - encoding: unused\ | ||
716 | * - decoding: Set by libavcodec.\ | ||
717 | */\ | ||
718 | uint8_t motion_subsample_log2;\ | ||
719 | \ | ||
720 | /**\ | ||
721 | * for some private data of the user\ | ||
722 | * - encoding: unused\ | ||
723 | * - decoding: Set by user.\ | ||
724 | */\ | ||
725 | void *opaque;\ | ||
726 | \ | ||
727 | /**\ | ||
728 | * error\ | ||
729 | * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\ | ||
730 | * - decoding: unused\ | ||
731 | */\ | ||
732 | uint64_t error[4];\ | ||
733 | \ | ||
734 | /**\ | ||
735 | * type of the buffer (to keep track of who has to deallocate data[*])\ | ||
736 | * - encoding: Set by the one who allocates it.\ | ||
737 | * - decoding: Set by the one who allocates it.\ | ||
738 | * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\ | ||
739 | */\ | ||
740 | int type;\ | ||
741 | \ | ||
742 | /**\ | ||
743 | * When decoding, this signals how much the picture must be delayed.\ | ||
744 | * extra_delay = repeat_pict / (2*fps)\ | ||
745 | * - encoding: unused\ | ||
746 | * - decoding: Set by libavcodec.\ | ||
747 | */\ | ||
748 | int repeat_pict;\ | ||
749 | \ | ||
750 | /**\ | ||
751 | * \ | ||
752 | */\ | ||
753 | int qscale_type;\ | ||
754 | \ | ||
755 | /**\ | ||
756 | * The content of the picture is interlaced.\ | ||
757 | * - encoding: Set by user.\ | ||
758 | * - decoding: Set by libavcodec. (default 0)\ | ||
759 | */\ | ||
760 | int interlaced_frame;\ | ||
761 | \ | ||
762 | /**\ | ||
763 | * If the content is interlaced, is top field displayed first.\ | ||
764 | * - encoding: Set by user.\ | ||
765 | * - decoding: Set by libavcodec.\ | ||
766 | */\ | ||
767 | int top_field_first;\ | ||
768 | \ | ||
769 | /**\ | ||
770 | * Pan scan.\ | ||
771 | * - encoding: Set by user.\ | ||
772 | * - decoding: Set by libavcodec.\ | ||
773 | */\ | ||
774 | AVPanScan *pan_scan;\ | ||
775 | \ | ||
776 | /**\ | ||
777 | * Tell user application that palette has changed from previous frame.\ | ||
778 | * - encoding: ??? (no palette-enabled encoder yet)\ | ||
779 | * - decoding: Set by libavcodec. (default 0).\ | ||
780 | */\ | ||
781 | int palette_has_changed;\ | ||
782 | \ | ||
783 | /**\ | ||
784 | * codec suggestion on buffer type if != 0\ | ||
785 | * - encoding: unused\ | ||
786 | * - decoding: Set by libavcodec. (before get_buffer() call)).\ | ||
787 | */\ | ||
788 | int buffer_hints;\ | ||
789 | \ | ||
790 | /**\ | ||
791 | * DCT coefficients\ | ||
792 | * - encoding: unused\ | ||
793 | * - decoding: Set by libavcodec.\ | ||
794 | */\ | ||
795 | short *dct_coeff;\ | ||
796 | \ | ||
797 | /**\ | ||
798 | * motion referece frame index\ | ||
799 | * - encoding: Set by user.\ | ||
800 | * - decoding: Set by libavcodec.\ | ||
801 | */\ | ||
802 | int8_t *ref_index[2];\ | ||
803 | \ | ||
804 | /**\ | ||
805 | * reordered opaque 64bit number (generally a PTS) from AVCodecContext.reordered_opaque\ | ||
806 | * output in AVFrame.reordered_opaque\ | ||
807 | * - encoding: unused\ | ||
808 | * - decoding: Read by user.\ | ||
809 | */\ | ||
810 | int64_t reordered_opaque;\ | ||
811 | \ | ||
812 | /**\ | ||
813 | * hardware accelerator private data (FFmpeg allocated)\ | ||
814 | * - encoding: unused\ | ||
815 | * - decoding: Set by libavcodec\ | ||
816 | */\ | ||
817 | void *hwaccel_picture_private;\ | ||
818 | |||
819 | |||
820 | #define FF_QSCALE_TYPE_MPEG1 0 | ||
821 | #define FF_QSCALE_TYPE_MPEG2 1 | ||
822 | #define FF_QSCALE_TYPE_H264 2 | ||
823 | |||
824 | #define FF_BUFFER_TYPE_INTERNAL 1 | ||
825 | #define FF_BUFFER_TYPE_USER 2 ///< direct rendering buffers (image is (de)allocated by user) | ||
826 | #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared. | ||
827 | #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything. | ||
828 | |||
829 | |||
830 | #define FF_I_TYPE 1 ///< Intra | ||
831 | #define FF_P_TYPE 2 ///< Predicted | ||
832 | #define FF_B_TYPE 3 ///< Bi-dir predicted | ||
833 | #define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4 | ||
834 | #define FF_SI_TYPE 5 ///< Switching Intra | ||
835 | #define FF_SP_TYPE 6 ///< Switching Predicted | ||
836 | #define FF_BI_TYPE 7 | ||
837 | |||
838 | #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore). | ||
839 | #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer. | ||
840 | #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content. | ||
841 | #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update). | ||
842 | |||
843 | /** | ||
844 | * Audio Video Frame. | ||
845 | * New fields can be added to the end of FF_COMMON_FRAME with minor version | ||
846 | * bumps. | ||
847 | * Removal, reordering and changes to existing fields require a major | ||
848 | * version bump. No fields should be added into AVFrame before or after | ||
849 | * FF_COMMON_FRAME! | ||
850 | * sizeof(AVFrame) must not be used outside libav*. | ||
851 | */ | ||
852 | typedef struct AVFrame { | ||
853 | FF_COMMON_FRAME | ||
854 | } AVFrame; | ||
855 | #endif/* MT : DELETE THIS LINE.*/ | ||
856 | /** | ||
857 | * main external API structure. | ||
858 | * New fields can be added to the end with minor version bumps. | ||
859 | * Removal, reordering and changes to existing fields require a major | ||
860 | * version bump. | ||
861 | * sizeof(AVCodecContext) must not be used outside libav*. | ||
862 | */ | ||
863 | typedef struct AVCodecContext { | ||
864 | /** | ||
865 | * information on struct for av_log | ||
866 | * - set by avcodec_alloc_context | ||
867 | */ | ||
868 | const AVClass *av_class; | ||
869 | /** | ||
870 | * the average bitrate | ||
871 | * - encoding: Set by user; unused for constant quantizer encoding. | ||
872 | * - decoding: Set by libavcodec. 0 or some bitrate if this info is available in the stream. | ||
873 | */ | ||
874 | int bit_rate; | ||
875 | |||
876 | /** | ||
877 | * number of bits the bitstream is allowed to diverge from the reference. | ||
878 | * the reference can be CBR (for CBR pass1) or VBR (for pass2) | ||
879 | * - encoding: Set by user; unused for constant quantizer encoding. | ||
880 | * - decoding: unused | ||
881 | */ | ||
882 | //MT: int bit_rate_tolerance; | ||
883 | |||
884 | /** | ||
885 | * CODEC_FLAG_*. | ||
886 | * - encoding: Set by user. | ||
887 | * - decoding: Set by user. | ||
888 | */ | ||
889 | //MT: int flags; | ||
890 | |||
891 | /** | ||
892 | * Some codecs need additional format info. It is stored here. | ||
893 | * If any muxer uses this then ALL demuxers/parsers AND encoders for the | ||
894 | * specific codec MUST set it correctly otherwise stream copy breaks. | ||
895 | * In general use of this field by muxers is not recommanded. | ||
896 | * - encoding: Set by libavcodec. | ||
897 | * - decoding: Set by libavcodec. (FIXME: Is this OK?) | ||
898 | */ | ||
899 | //MT: int sub_id; | ||
900 | |||
901 | /** | ||
902 | * Motion estimation algorithm used for video coding. | ||
903 | * 1 (zero), 2 (full), 3 (log), 4 (phods), 5 (epzs), 6 (x1), 7 (hex), | ||
904 | * 8 (umh), 9 (iter), 10 (tesa) [7, 8, 10 are x264 specific, 9 is snow specific] | ||
905 | * - encoding: MUST be set by user. | ||
906 | * - decoding: unused | ||
907 | */ | ||
908 | //MT: int me_method; | ||
909 | |||
910 | /** | ||
911 | * some codecs need / can use extradata like Huffman tables. | ||
912 | * mjpeg: Huffman tables | ||
913 | * rv10: additional flags | ||
914 | * mpeg4: global headers (they can be in the bitstream or here) | ||
915 | * The allocated memory should be FF_INPUT_BUFFER_PADDING_SIZE bytes larger | ||
916 | * than extradata_size to avoid prolems if it is read with the bitstream reader. | ||
917 | * The bytewise contents of extradata must not depend on the architecture or CPU endianness. | ||
918 | * - encoding: Set/allocated/freed by libavcodec. | ||
919 | * - decoding: Set/allocated/freed by user. | ||
920 | */ | ||
921 | uint8_t *extradata; | ||
922 | int extradata_size; | ||
923 | |||
924 | /** | ||
925 | * This is the fundamental unit of time (in seconds) in terms | ||
926 | * of which frame timestamps are represented. For fixed-fps content, | ||
927 | * timebase should be 1/framerate and timestamp increments should be | ||
928 | * identically 1. | ||
929 | * - encoding: MUST be set by user. | ||
930 | * - decoding: Set by libavcodec. | ||
931 | */ | ||
932 | //MT: AVRational time_base; | ||
933 | |||
934 | /* video only */ | ||
935 | /** | ||
936 | * picture width / height. | ||
937 | * - encoding: MUST be set by user. | ||
938 | * - decoding: Set by libavcodec. | ||
939 | * Note: For compatibility it is possible to set this instead of | ||
940 | * coded_width/height before decoding. | ||
941 | */ | ||
942 | //MT: int width, height; | ||
943 | |||
944 | //MT:#define FF_ASPECT_EXTENDED 15 | ||
945 | |||
946 | /** | ||
947 | * the number of pictures in a group of pictures, or 0 for intra_only | ||
948 | * - encoding: Set by user. | ||
949 | * - decoding: unused | ||
950 | */ | ||
951 | //MT: int gop_size; | ||
952 | |||
953 | /** | ||
954 | * Pixel format, see PIX_FMT_xxx. | ||
955 | * - encoding: Set by user. | ||
956 | * - decoding: Set by libavcodec. | ||
957 | */ | ||
958 | //MT: enum PixelFormat pix_fmt; | ||
959 | |||
960 | /** | ||
961 | * Frame rate emulation. If not zero, the lower layer (i.e. format handler) | ||
962 | * has to read frames at native frame rate. | ||
963 | * - encoding: Set by user. | ||
964 | * - decoding: unused | ||
965 | */ | ||
966 | //MT: int rate_emu; | ||
967 | |||
968 | /** | ||
969 | * If non NULL, 'draw_horiz_band' is called by the libavcodec | ||
970 | * decoder to draw a horizontal band. It improves cache usage. Not | ||
971 | * all codecs can do that. You must check the codec capabilities | ||
972 | * beforehand. | ||
973 | * The function is also used by hardware acceleration APIs. | ||
974 | * It is called at least once during frame decoding to pass | ||
975 | * the data needed for hardware render. | ||
976 | * In that mode instead of pixel data, AVFrame points to | ||
977 | * a structure specific to the acceleration API. The application | ||
978 | * reads the structure and can change some fields to indicate progress | ||
979 | * or mark state. | ||
980 | * - encoding: unused | ||
981 | * - decoding: Set by user. | ||
982 | * @param height the height of the slice | ||
983 | * @param y the y position of the slice | ||
984 | * @param type 1->top field, 2->bottom field, 3->frame | ||
985 | * @param offset offset into the AVFrame.data from which the slice should be read | ||
986 | */ | ||
987 | //MT: void (*draw_horiz_band)(struct AVCodecContext *s, | ||
988 | //Mt: const AVFrame *src, int offset[4], | ||
989 | //MT: int y, int type, int height); | ||
990 | |||
991 | /* audio only */ | ||
992 | int sample_rate; ///< samples per second | ||
993 | int channels; ///< number of audio channels | ||
994 | |||
995 | /** | ||
996 | * audio sample format | ||
997 | * - encoding: Set by user. | ||
998 | * - decoding: Set by libavcodec. | ||
999 | */ | ||
1000 | enum SampleFormat sample_fmt; ///< sample format, currently unused | ||
1001 | |||
1002 | /* The following data should not be initialized. */ | ||
1003 | /** | ||
1004 | * Samples per packet, initialized when calling 'init'. | ||
1005 | */ | ||
1006 | int frame_size; | ||
1007 | int frame_number; ///< audio or video frame number | ||
1008 | //MT: int real_pict_num; ///< Returns the real picture number of previous encoded frame. | ||
1009 | |||
1010 | /** | ||
1011 | * Number of frames the decoded output will be delayed relative to | ||
1012 | * the encoded input. | ||
1013 | * - encoding: Set by libavcodec. | ||
1014 | * - decoding: unused | ||
1015 | */ | ||
1016 | //MT: int delay; | ||
1017 | |||
1018 | /* - encoding parameters */ | ||
1019 | //MT: float qcompress; ///< amount of qscale change between easy & hard scenes (0.0-1.0) | ||
1020 | //MT: float qblur; ///< amount of qscale smoothing over time (0.0-1.0) | ||
1021 | |||
1022 | /** | ||
1023 | * minimum quantizer | ||
1024 | * - encoding: Set by user. | ||
1025 | * - decoding: unused | ||
1026 | */ | ||
1027 | //MT: int qmin; | ||
1028 | |||
1029 | /** | ||
1030 | * maximum quantizer | ||
1031 | * - encoding: Set by user. | ||
1032 | * - decoding: unused | ||
1033 | */ | ||
1034 | //MT: int qmax; | ||
1035 | |||
1036 | /** | ||
1037 | * maximum quantizer difference between frames | ||
1038 | * - encoding: Set by user. | ||
1039 | * - decoding: unused | ||
1040 | */ | ||
1041 | //MT: int max_qdiff; | ||
1042 | |||
1043 | /** | ||
1044 | * maximum number of B-frames between non-B-frames | ||
1045 | * Note: The output will be delayed by max_b_frames+1 relative to the input. | ||
1046 | * - encoding: Set by user. | ||
1047 | * - decoding: unused | ||
1048 | */ | ||
1049 | //MT: int max_b_frames; | ||
1050 | |||
1051 | /** | ||
1052 | * qscale factor between IP and B-frames | ||
1053 | * If > 0 then the last P-frame quantizer will be used (q= lastp_q*factor+offset). | ||
1054 | * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). | ||
1055 | * - encoding: Set by user. | ||
1056 | * - decoding: unused | ||
1057 | */ | ||
1058 | //MT: float b_quant_factor; | ||
1059 | |||
1060 | /** obsolete FIXME remove */ | ||
1061 | //MT: int rc_strategy; | ||
1062 | //MT:#define FF_RC_STRATEGY_XVID 1 | ||
1063 | |||
1064 | //MT: int b_frame_strategy; | ||
1065 | |||
1066 | /** | ||
1067 | * hurry up amount | ||
1068 | * - encoding: unused | ||
1069 | * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header | ||
1070 | * @deprecated Deprecated in favor of skip_idct and skip_frame. | ||
1071 | */ | ||
1072 | //MT: int hurry_up; | ||
1073 | |||
1074 | struct AVCodec *codec; | ||
1075 | |||
1076 | void *priv_data; | ||
1077 | |||
1078 | //MT: int rtp_payload_size; /* The size of the RTP payload: the coder will */ | ||
1079 | /* do its best to deliver a chunk with size */ | ||
1080 | /* below rtp_payload_size, the chunk will start */ | ||
1081 | /* with a start code on some codecs like H.263. */ | ||
1082 | /* This doesn't take account of any particular */ | ||
1083 | /* headers inside the transmitted RTP payload. */ | ||
1084 | |||
1085 | |||
1086 | /* The RTP callback: This function is called */ | ||
1087 | /* every time the encoder has a packet to send. */ | ||
1088 | /* It depends on the encoder if the data starts */ | ||
1089 | /* with a Start Code (it should). H.263 does. */ | ||
1090 | /* mb_nb contains the number of macroblocks */ | ||
1091 | /* encoded in the RTP payload. */ | ||
1092 | //MT: void (*rtp_callback)(struct AVCodecContext *avctx, void *data, int size, int mb_nb); | ||
1093 | |||
1094 | /* statistics, used for 2-pass encoding */ | ||
1095 | //MT: int mv_bits; | ||
1096 | //MT: int header_bits; | ||
1097 | //MT: int i_tex_bits; | ||
1098 | //MT: int p_tex_bits; | ||
1099 | //MT: int i_count; | ||
1100 | //MT: int p_count; | ||
1101 | //MT: int skip_count; | ||
1102 | //MT: int misc_bits; | ||
1103 | |||
1104 | /** | ||
1105 | * number of bits used for the previously encoded frame | ||
1106 | * - encoding: Set by libavcodec. | ||
1107 | * - decoding: unused | ||
1108 | */ | ||
1109 | //MT: int frame_bits; | ||
1110 | |||
1111 | /** | ||
1112 | * Private data of the user, can be used to carry app specific stuff. | ||
1113 | * - encoding: Set by user. | ||
1114 | * - decoding: Set by user. | ||
1115 | */ | ||
1116 | //MT: void *opaque; | ||
1117 | |||
1118 | char codec_name[32]; | ||
1119 | enum CodecType codec_type; /* see CODEC_TYPE_xxx */ | ||
1120 | enum CodecID codec_id; /* see CODEC_ID_xxx */ | ||
1121 | |||
1122 | /** | ||
1123 | * fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). | ||
1124 | * This is used to work around some encoder bugs. | ||
1125 | * A demuxer should set this to what is stored in the field used to identify the codec. | ||
1126 | * If there are multiple such fields in a container then the demuxer should choose the one | ||
1127 | * which maximizes the information about the used codec. | ||
1128 | * If the codec tag field in a container is larger then 32 bits then the demuxer should | ||
1129 | * remap the longer ID to 32 bits with a table or other structure. Alternatively a new | ||
1130 | * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated | ||
1131 | * first. | ||
1132 | * - encoding: Set by user, if not then the default based on codec_id will be used. | ||
1133 | * - decoding: Set by user, will be converted to uppercase by libavcodec during init. | ||
1134 | */ | ||
1135 | //MT: unsigned int codec_tag; | ||
1136 | |||
1137 | /** | ||
1138 | * Work around bugs in encoders which sometimes cannot be detected automatically. | ||
1139 | * - encoding: Set by user | ||
1140 | * - decoding: Set by user | ||
1141 | */ | ||
1142 | //MT: int workaround_bugs; | ||
1143 | #define FF_BUG_AUTODETECT 1 ///< autodetection | ||
1144 | #define FF_BUG_OLD_MSMPEG4 2 | ||
1145 | #define FF_BUG_XVID_ILACE 4 | ||
1146 | #define FF_BUG_UMP4 8 | ||
1147 | #define FF_BUG_NO_PADDING 16 | ||
1148 | #define FF_BUG_AMV 32 | ||
1149 | #define FF_BUG_AC_VLC 0 ///< Will be removed, libavcodec can now handle these non-compliant files by default. | ||
1150 | #define FF_BUG_QPEL_CHROMA 64 | ||
1151 | #define FF_BUG_STD_QPEL 128 | ||
1152 | #define FF_BUG_QPEL_CHROMA2 256 | ||
1153 | #define FF_BUG_DIRECT_BLOCKSIZE 512 | ||
1154 | #define FF_BUG_EDGE 1024 | ||
1155 | #define FF_BUG_HPEL_CHROMA 2048 | ||
1156 | #define FF_BUG_DC_CLIP 4096 | ||
1157 | #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. | ||
1158 | //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. | ||
1159 | |||
1160 | /** | ||
1161 | * luma single coefficient elimination threshold | ||
1162 | * - encoding: Set by user. | ||
1163 | * - decoding: unused | ||
1164 | */ | ||
1165 | //MT: int luma_elim_threshold; | ||
1166 | |||
1167 | /** | ||
1168 | * chroma single coeff elimination threshold | ||
1169 | * - encoding: Set by user. | ||
1170 | * - decoding: unused | ||
1171 | */ | ||
1172 | //MT: int chroma_elim_threshold; | ||
1173 | |||
1174 | /** | ||
1175 | * strictly follow the standard (MPEG4, ...). | ||
1176 | * - encoding: Set by user. | ||
1177 | * - decoding: Set by user. | ||
1178 | * Setting this to STRICT or higher means the encoder and decoder will | ||
1179 | * generally do stupid things. While setting it to inofficial or lower | ||
1180 | * will mean the encoder might use things that are not supported by all | ||
1181 | * spec compliant decoders. Decoders make no difference between normal, | ||
1182 | * inofficial and experimental, that is they always try to decode things | ||
1183 | * when they can unless they are explicitly asked to behave stupid | ||
1184 | * (=strictly conform to the specs) | ||
1185 | */ | ||
1186 | //MT: int strict_std_compliance; | ||
1187 | #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to a older more strict version of the spec or reference software. | ||
1188 | #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences. | ||
1189 | #define FF_COMPLIANCE_NORMAL 0 | ||
1190 | #define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions. | ||
1191 | #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things. | ||
1192 | |||
1193 | /** | ||
1194 | * qscale offset between IP and B-frames | ||
1195 | * - encoding: Set by user. | ||
1196 | * - decoding: unused | ||
1197 | */ | ||
1198 | //MT: float b_quant_offset; | ||
1199 | |||
1200 | /** | ||
1201 | * Error recognization; higher values will detect more errors but may | ||
1202 | * misdetect some more or less valid parts as errors. | ||
1203 | * - encoding: unused | ||
1204 | * - decoding: Set by user. | ||
1205 | */ | ||
1206 | //MT: int error_recognition; | ||
1207 | #define FF_ER_CAREFUL 1 | ||
1208 | #define FF_ER_COMPLIANT 2 | ||
1209 | #define FF_ER_AGGRESSIVE 3 | ||
1210 | #define FF_ER_VERY_AGGRESSIVE 4 | ||
1211 | |||
1212 | /** | ||
1213 | * Called at the beginning of each frame to get a buffer for it. | ||
1214 | * If pic.reference is set then the frame will be read later by libavcodec. | ||
1215 | * avcodec_align_dimensions() should be used to find the required width and | ||
1216 | * height, as they normally need to be rounded up to the next multiple of 16. | ||
1217 | * - encoding: unused | ||
1218 | * - decoding: Set by libavcodec., user can override. | ||
1219 | */ | ||
1220 | //MT: int (*get_buffer)(struct AVCodecContext *c, AVFrame *pic); | ||
1221 | |||
1222 | /** | ||
1223 | * Called to release buffers which were allocated with get_buffer. | ||
1224 | * A released buffer can be reused in get_buffer(). | ||
1225 | * pic.data[*] must be set to NULL. | ||
1226 | * - encoding: unused | ||
1227 | * - decoding: Set by libavcodec., user can override. | ||
1228 | */ | ||
1229 | //MT: void (*release_buffer)(struct AVCodecContext *c, AVFrame *pic); | ||
1230 | |||
1231 | /** | ||
1232 | * Size of the frame reordering buffer in the decoder. | ||
1233 | * For MPEG-2 it is 1 IPB or 0 low delay IP. | ||
1234 | * - encoding: Set by libavcodec. | ||
1235 | * - decoding: Set by libavcodec. | ||
1236 | */ | ||
1237 | //MT: int has_b_frames; | ||
1238 | |||
1239 | /** | ||
1240 | * number of bytes per packet if constant and known or 0 | ||
1241 | * Used by some WAV based audio codecs. | ||
1242 | */ | ||
1243 | int block_align; | ||
1244 | |||
1245 | //MT: int parse_only; /* - decoding only: If true, only parsing is done | ||
1246 | /*(function avcodec_parse_frame()). The frame | ||
1247 | data is returned. Only MPEG codecs support this now. */ | ||
1248 | |||
1249 | /** | ||
1250 | * 0-> h263 quant 1-> mpeg quant | ||
1251 | * - encoding: Set by user. | ||
1252 | * - decoding: unused | ||
1253 | */ | ||
1254 | //MT: int mpeg_quant; | ||
1255 | |||
1256 | /** | ||
1257 | * pass1 encoding statistics output buffer | ||
1258 | * - encoding: Set by libavcodec. | ||
1259 | * - decoding: unused | ||
1260 | */ | ||
1261 | //MT: char *stats_out; | ||
1262 | |||
1263 | /** | ||
1264 | * pass2 encoding statistics input buffer | ||
1265 | * Concatenated stuff from stats_out of pass1 should be placed here. | ||
1266 | * - encoding: Allocated/set/freed by user. | ||
1267 | * - decoding: unused | ||
1268 | */ | ||
1269 | //MT: char *stats_in; | ||
1270 | |||
1271 | /** | ||
1272 | * ratecontrol qmin qmax limiting method | ||
1273 | * 0-> clipping, 1-> use a nice continous function to limit qscale wthin qmin/qmax. | ||
1274 | * - encoding: Set by user. | ||
1275 | * - decoding: unused | ||
1276 | */ | ||
1277 | //MT: float rc_qsquish; | ||
1278 | |||
1279 | //MT: float rc_qmod_amp; | ||
1280 | //MT: int rc_qmod_freq; | ||
1281 | |||
1282 | /** | ||
1283 | * ratecontrol override, see RcOverride | ||
1284 | * - encoding: Allocated/set/freed by user. | ||
1285 | * - decoding: unused | ||
1286 | */ | ||
1287 | //MT: RcOverride *rc_override; | ||
1288 | //MT: int rc_override_count; | ||
1289 | |||
1290 | /** | ||
1291 | * rate control equation | ||
1292 | * - encoding: Set by user | ||
1293 | * - decoding: unused | ||
1294 | */ | ||
1295 | //MT: const char *rc_eq; | ||
1296 | |||
1297 | /** | ||
1298 | * maximum bitrate | ||
1299 | * - encoding: Set by user. | ||
1300 | * - decoding: unused | ||
1301 | */ | ||
1302 | //MT: int rc_max_rate; | ||
1303 | |||
1304 | /** | ||
1305 | * minimum bitrate | ||
1306 | * - encoding: Set by user. | ||
1307 | * - decoding: unused | ||
1308 | */ | ||
1309 | //MT: int rc_min_rate; | ||
1310 | |||
1311 | /** | ||
1312 | * decoder bitstream buffer size | ||
1313 | * - encoding: Set by user. | ||
1314 | * - decoding: unused | ||
1315 | */ | ||
1316 | //MT: int rc_buffer_size; | ||
1317 | //MT: float rc_buffer_aggressivity; | ||
1318 | |||
1319 | /** | ||
1320 | * qscale factor between P and I-frames | ||
1321 | * If > 0 then the last p frame quantizer will be used (q= lastp_q*factor+offset). | ||
1322 | * If < 0 then normal ratecontrol will be done (q= -normal_q*factor+offset). | ||
1323 | * - encoding: Set by user. | ||
1324 | * - decoding: unused | ||
1325 | */ | ||
1326 | //MT: float i_quant_factor; | ||
1327 | |||
1328 | /** | ||
1329 | * qscale offset between P and I-frames | ||
1330 | * - encoding: Set by user. | ||
1331 | * - decoding: unused | ||
1332 | */ | ||
1333 | //MT: float i_quant_offset; | ||
1334 | |||
1335 | /** | ||
1336 | * initial complexity for pass1 ratecontrol | ||
1337 | * - encoding: Set by user. | ||
1338 | * - decoding: unused | ||
1339 | */ | ||
1340 | //MT: float rc_initial_cplx; | ||
1341 | |||
1342 | /** | ||
1343 | * DCT algorithm, see FF_DCT_* below | ||
1344 | * - encoding: Set by user. | ||
1345 | * - decoding: unused | ||
1346 | */ | ||
1347 | //MT: int dct_algo; | ||
1348 | #define FF_DCT_AUTO 0 | ||
1349 | #define FF_DCT_FASTINT 1 | ||
1350 | #define FF_DCT_INT 2 | ||
1351 | #define FF_DCT_MMX 3 | ||
1352 | #define FF_DCT_MLIB 4 | ||
1353 | #define FF_DCT_ALTIVEC 5 | ||
1354 | #define FF_DCT_FAAN 6 | ||
1355 | |||
1356 | /** | ||
1357 | * luminance masking (0-> disabled) | ||
1358 | * - encoding: Set by user. | ||
1359 | * - decoding: unused | ||
1360 | */ | ||
1361 | //MT: float lumi_masking; | ||
1362 | |||
1363 | /** | ||
1364 | * temporary complexity masking (0-> disabled) | ||
1365 | * - encoding: Set by user. | ||
1366 | * - decoding: unused | ||
1367 | */ | ||
1368 | //MT: float temporal_cplx_masking; | ||
1369 | |||
1370 | /** | ||
1371 | * spatial complexity masking (0-> disabled) | ||
1372 | * - encoding: Set by user. | ||
1373 | * - decoding: unused | ||
1374 | */ | ||
1375 | //MT: float spatial_cplx_masking; | ||
1376 | |||
1377 | /** | ||
1378 | * p block masking (0-> disabled) | ||
1379 | * - encoding: Set by user. | ||
1380 | * - decoding: unused | ||
1381 | */ | ||
1382 | //MT: float p_masking; | ||
1383 | |||
1384 | /** | ||
1385 | * darkness masking (0-> disabled) | ||
1386 | * - encoding: Set by user. | ||
1387 | * - decoding: unused | ||
1388 | */ | ||
1389 | //MT: float dark_masking; | ||
1390 | |||
1391 | /** | ||
1392 | * IDCT algorithm, see FF_IDCT_* below. | ||
1393 | * - encoding: Set by user. | ||
1394 | * - decoding: Set by user. | ||
1395 | */ | ||
1396 | //MT: int idct_algo; | ||
1397 | #define FF_IDCT_AUTO 0 | ||
1398 | #define FF_IDCT_INT 1 | ||
1399 | #define FF_IDCT_SIMPLE 2 | ||
1400 | #define FF_IDCT_SIMPLEMMX 3 | ||
1401 | #define FF_IDCT_LIBMPEG2MMX 4 | ||
1402 | #define FF_IDCT_PS2 5 | ||
1403 | #define FF_IDCT_MLIB 6 | ||
1404 | #define FF_IDCT_ARM 7 | ||
1405 | #define FF_IDCT_ALTIVEC 8 | ||
1406 | #define FF_IDCT_SH4 9 | ||
1407 | #define FF_IDCT_SIMPLEARM 10 | ||
1408 | #define FF_IDCT_H264 11 | ||
1409 | #define FF_IDCT_VP3 12 | ||
1410 | #define FF_IDCT_IPP 13 | ||
1411 | #define FF_IDCT_XVIDMMX 14 | ||
1412 | #define FF_IDCT_CAVS 15 | ||
1413 | #define FF_IDCT_SIMPLEARMV5TE 16 | ||
1414 | #define FF_IDCT_SIMPLEARMV6 17 | ||
1415 | #define FF_IDCT_SIMPLEVIS 18 | ||
1416 | #define FF_IDCT_WMV2 19 | ||
1417 | #define FF_IDCT_FAAN 20 | ||
1418 | #define FF_IDCT_EA 21 | ||
1419 | #define FF_IDCT_SIMPLENEON 22 | ||
1420 | #define FF_IDCT_SIMPLEALPHA 23 | ||
1421 | |||
1422 | /** | ||
1423 | * slice count | ||
1424 | * - encoding: Set by libavcodec. | ||
1425 | * - decoding: Set by user (or 0). | ||
1426 | */ | ||
1427 | //MT: int slice_count; | ||
1428 | /** | ||
1429 | * slice offsets in the frame in bytes | ||
1430 | * - encoding: Set/allocated by libavcodec. | ||
1431 | * - decoding: Set/allocated by user (or NULL). | ||
1432 | */ | ||
1433 | //MT: int *slice_offset; | ||
1434 | |||
1435 | /** | ||
1436 | * error concealment flags | ||
1437 | * - encoding: unused | ||
1438 | * - decoding: Set by user. | ||
1439 | */ | ||
1440 | //MT: int error_concealment; | ||
1441 | #define FF_EC_GUESS_MVS 1 | ||
1442 | #define FF_EC_DEBLOCK 2 | ||
1443 | |||
1444 | /** | ||
1445 | * dsp_mask could be add used to disable unwanted CPU features | ||
1446 | * CPU features (i.e. MMX, SSE. ...) | ||
1447 | * | ||
1448 | * With the FORCE flag you may instead enable given CPU features. | ||
1449 | * (Dangerous: Usable in case of misdetection, improper usage however will | ||
1450 | * result into program crash.) | ||
1451 | */ | ||
1452 | //MT: unsigned dsp_mask; | ||
1453 | #define FF_MM_FORCE 0x80000000 /* Force usage of selected flags (OR) */ | ||
1454 | /* lower 16 bits - CPU features */ | ||
1455 | #define FF_MM_MMX 0x0001 ///< standard MMX | ||
1456 | #define FF_MM_3DNOW 0x0004 ///< AMD 3DNOW | ||
1457 | #define FF_MM_MMXEXT 0x0002 ///< SSE integer functions or AMD MMX ext | ||
1458 | #define FF_MM_SSE 0x0008 ///< SSE functions | ||
1459 | #define FF_MM_SSE2 0x0010 ///< PIV SSE2 functions | ||
1460 | #define FF_MM_3DNOWEXT 0x0020 ///< AMD 3DNowExt | ||
1461 | #define FF_MM_SSE3 0x0040 ///< Prescott SSE3 functions | ||
1462 | #define FF_MM_SSSE3 0x0080 ///< Conroe SSSE3 functions | ||
1463 | #define FF_MM_IWMMXT 0x0100 ///< XScale IWMMXT | ||
1464 | #define FF_MM_ALTIVEC 0x0001 ///< standard AltiVec | ||
1465 | |||
1466 | /** | ||
1467 | * bits per sample/pixel from the demuxer (needed for huffyuv). | ||
1468 | * - encoding: Set by libavcodec. | ||
1469 | * - decoding: Set by user. | ||
1470 | */ | ||
1471 | //MT: int bits_per_coded_sample; | ||
1472 | |||
1473 | /** | ||
1474 | * prediction method (needed for huffyuv) | ||
1475 | * - encoding: Set by user. | ||
1476 | * - decoding: unused | ||
1477 | */ | ||
1478 | //MT: int prediction_method; | ||
1479 | #define FF_PRED_LEFT 0 | ||
1480 | #define FF_PRED_PLANE 1 | ||
1481 | #define FF_PRED_MEDIAN 2 | ||
1482 | |||
1483 | /** | ||
1484 | * sample aspect ratio (0 if unknown) | ||
1485 | * That is the width of a pixel divided by the height of the pixel. | ||
1486 | * Numerator and denominator must be relatively prime and smaller than 256 for some video standards. | ||
1487 | * - encoding: Set by user. | ||
1488 | * - decoding: Set by libavcodec. | ||
1489 | */ | ||
1490 | //MT: AVRational sample_aspect_ratio; | ||
1491 | |||
1492 | /** | ||
1493 | * the picture in the bitstream | ||
1494 | * - encoding: Set by libavcodec. | ||
1495 | * - decoding: Set by libavcodec. | ||
1496 | */ | ||
1497 | //MT: AVFrame *coded_frame; | ||
1498 | |||
1499 | /** | ||
1500 | * debug | ||
1501 | * - encoding: Set by user. | ||
1502 | * - decoding: Set by user. | ||
1503 | */ | ||
1504 | //MT: int debug; | ||
1505 | #define FF_DEBUG_PICT_INFO 1 | ||
1506 | #define FF_DEBUG_RC 2 | ||
1507 | #define FF_DEBUG_BITSTREAM 4 | ||
1508 | #define FF_DEBUG_MB_TYPE 8 | ||
1509 | #define FF_DEBUG_QP 16 | ||
1510 | #define FF_DEBUG_MV 32 | ||
1511 | #define FF_DEBUG_DCT_COEFF 0x00000040 | ||
1512 | #define FF_DEBUG_SKIP 0x00000080 | ||
1513 | #define FF_DEBUG_STARTCODE 0x00000100 | ||
1514 | #define FF_DEBUG_PTS 0x00000200 | ||
1515 | #define FF_DEBUG_ER 0x00000400 | ||
1516 | #define FF_DEBUG_MMCO 0x00000800 | ||
1517 | #define FF_DEBUG_BUGS 0x00001000 | ||
1518 | #define FF_DEBUG_VIS_QP 0x00002000 | ||
1519 | #define FF_DEBUG_VIS_MB_TYPE 0x00004000 | ||
1520 | #define FF_DEBUG_BUFFERS 0x00008000 | ||
1521 | |||
1522 | /** | ||
1523 | * debug | ||
1524 | * - encoding: Set by user. | ||
1525 | * - decoding: Set by user. | ||
1526 | */ | ||
1527 | //MT: int debug_mv; | ||
1528 | #define FF_DEBUG_VIS_MV_P_FOR 0x00000001 //visualize forward predicted MVs of P frames | ||
1529 | #define FF_DEBUG_VIS_MV_B_FOR 0x00000002 //visualize forward predicted MVs of B frames | ||
1530 | #define FF_DEBUG_VIS_MV_B_BACK 0x00000004 //visualize backward predicted MVs of B frames | ||
1531 | |||
1532 | /** | ||
1533 | * error | ||
1534 | * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR. | ||
1535 | * - decoding: unused | ||
1536 | */ | ||
1537 | uint64_t error[4]; | ||
1538 | |||
1539 | /** | ||
1540 | * minimum MB quantizer | ||
1541 | * - encoding: unused | ||
1542 | * - decoding: unused | ||
1543 | */ | ||
1544 | //MT: int mb_qmin; | ||
1545 | |||
1546 | /** | ||
1547 | * maximum MB quantizer | ||
1548 | * - encoding: unused | ||
1549 | * - decoding: unused | ||
1550 | */ | ||
1551 | //MT: int mb_qmax; | ||
1552 | |||
1553 | /** | ||
1554 | * motion estimation comparison function | ||
1555 | * - encoding: Set by user. | ||
1556 | * - decoding: unused | ||
1557 | */ | ||
1558 | //MT: int me_cmp; | ||
1559 | /** | ||
1560 | * subpixel motion estimation comparison function | ||
1561 | * - encoding: Set by user. | ||
1562 | * - decoding: unused | ||
1563 | */ | ||
1564 | //MT: int me_sub_cmp; | ||
1565 | /** | ||
1566 | * macroblock comparison function (not supported yet) | ||
1567 | * - encoding: Set by user. | ||
1568 | * - decoding: unused | ||
1569 | */ | ||
1570 | //MT: int mb_cmp; | ||
1571 | /** | ||
1572 | * interlaced DCT comparison function | ||
1573 | * - encoding: Set by user. | ||
1574 | * - decoding: unused | ||
1575 | */ | ||
1576 | //MT: int ildct_cmp; | ||
1577 | #define FF_CMP_SAD 0 | ||
1578 | #define FF_CMP_SSE 1 | ||
1579 | #define FF_CMP_SATD 2 | ||
1580 | #define FF_CMP_DCT 3 | ||
1581 | #define FF_CMP_PSNR 4 | ||
1582 | #define FF_CMP_BIT 5 | ||
1583 | #define FF_CMP_RD 6 | ||
1584 | #define FF_CMP_ZERO 7 | ||
1585 | #define FF_CMP_VSAD 8 | ||
1586 | #define FF_CMP_VSSE 9 | ||
1587 | #define FF_CMP_NSSE 10 | ||
1588 | #define FF_CMP_W53 11 | ||
1589 | #define FF_CMP_W97 12 | ||
1590 | #define FF_CMP_DCTMAX 13 | ||
1591 | #define FF_CMP_DCT264 14 | ||
1592 | #define FF_CMP_CHROMA 256 | ||
1593 | |||
1594 | /** | ||
1595 | * ME diamond size & shape | ||
1596 | * - encoding: Set by user. | ||
1597 | * - decoding: unused | ||
1598 | */ | ||
1599 | //MT: int dia_size; | ||
1600 | |||
1601 | /** | ||
1602 | * amount of previous MV predictors (2a+1 x 2a+1 square) | ||
1603 | * - encoding: Set by user. | ||
1604 | * - decoding: unused | ||
1605 | */ | ||
1606 | //MT: int last_predictor_count; | ||
1607 | |||
1608 | /** | ||
1609 | * prepass for motion estimation | ||
1610 | * - encoding: Set by user. | ||
1611 | * - decoding: unused | ||
1612 | */ | ||
1613 | //MT: int pre_me; | ||
1614 | |||
1615 | /** | ||
1616 | * motion estimation prepass comparison function | ||
1617 | * - encoding: Set by user. | ||
1618 | * - decoding: unused | ||
1619 | */ | ||
1620 | //MT: int me_pre_cmp; | ||
1621 | |||
1622 | /** | ||
1623 | * ME prepass diamond size & shape | ||
1624 | * - encoding: Set by user. | ||
1625 | * - decoding: unused | ||
1626 | */ | ||
1627 | //MT: int pre_dia_size; | ||
1628 | |||
1629 | /** | ||
1630 | * subpel ME quality | ||
1631 | * - encoding: Set by user. | ||
1632 | * - decoding: unused | ||
1633 | */ | ||
1634 | //MT: int me_subpel_quality; | ||
1635 | |||
1636 | /** | ||
1637 | * callback to negotiate the pixelFormat | ||
1638 | * @param fmt is the list of formats which are supported by the codec, | ||
1639 | * it is terminated by -1 as 0 is a valid format, the formats are ordered by quality. | ||
1640 | * The first is always the native one. | ||
1641 | * @return the chosen format | ||
1642 | * - encoding: unused | ||
1643 | * - decoding: Set by user, if not set the native format will be chosen. | ||
1644 | */ | ||
1645 | //MT: enum PixelFormat (*get_format)(struct AVCodecContext *s, const enum PixelFormat * fmt); | ||
1646 | |||
1647 | /** | ||
1648 | * DTG active format information (additional aspect ratio | ||
1649 | * information only used in DVB MPEG-2 transport streams) | ||
1650 | * 0 if not set. | ||
1651 | * | ||
1652 | * - encoding: unused | ||
1653 | * - decoding: Set by decoder. | ||
1654 | */ | ||
1655 | //MT: int dtg_active_format; | ||
1656 | #define FF_DTG_AFD_SAME 8 | ||
1657 | #define FF_DTG_AFD_4_3 9 | ||
1658 | #define FF_DTG_AFD_16_9 10 | ||
1659 | #define FF_DTG_AFD_14_9 11 | ||
1660 | #define FF_DTG_AFD_4_3_SP_14_9 13 | ||
1661 | #define FF_DTG_AFD_16_9_SP_14_9 14 | ||
1662 | #define FF_DTG_AFD_SP_4_3 15 | ||
1663 | |||
1664 | /** | ||
1665 | * maximum motion estimation search range in subpel units | ||
1666 | * If 0 then no limit. | ||
1667 | * | ||
1668 | * - encoding: Set by user. | ||
1669 | * - decoding: unused | ||
1670 | */ | ||
1671 | //MT: int me_range; | ||
1672 | |||
1673 | /** | ||
1674 | * intra quantizer bias | ||
1675 | * - encoding: Set by user. | ||
1676 | * - decoding: unused | ||
1677 | */ | ||
1678 | //MT: int intra_quant_bias; | ||
1679 | #define FF_DEFAULT_QUANT_BIAS 999999 | ||
1680 | |||
1681 | /** | ||
1682 | * inter quantizer bias | ||
1683 | * - encoding: Set by user. | ||
1684 | * - decoding: unused | ||
1685 | */ | ||
1686 | //MT: int inter_quant_bias; | ||
1687 | |||
1688 | /** | ||
1689 | * color table ID | ||
1690 | * - encoding: unused | ||
1691 | * - decoding: Which clrtable should be used for 8bit RGB images. | ||
1692 | * Tables have to be stored somewhere. FIXME | ||
1693 | */ | ||
1694 | //MT: int color_table_id; | ||
1695 | |||
1696 | /** | ||
1697 | * internal_buffer count | ||
1698 | * Don't touch, used by libavcodec default_get_buffer(). | ||
1699 | */ | ||
1700 | //MT: int internal_buffer_count; | ||
1701 | |||
1702 | /** | ||
1703 | * internal_buffers | ||
1704 | * Don't touch, used by libavcodec default_get_buffer(). | ||
1705 | */ | ||
1706 | void *internal_buffer; | ||
1707 | |||
1708 | #define FF_LAMBDA_SHIFT 7 | ||
1709 | #define FF_LAMBDA_SCALE (1<<FF_LAMBDA_SHIFT) | ||
1710 | #define FF_QP2LAMBDA 118 ///< factor to convert from H.263 QP to lambda | ||
1711 | #define FF_LAMBDA_MAX (256*128-1) | ||
1712 | |||
1713 | #define FF_QUALITY_SCALE FF_LAMBDA_SCALE //FIXME maybe remove | ||
1714 | /** | ||
1715 | * Global quality for codecs which cannot change it per frame. | ||
1716 | * This should be proportional to MPEG-1/2/4 qscale. | ||
1717 | * - encoding: Set by user. | ||
1718 | * - decoding: unused | ||
1719 | */ | ||
1720 | //MT: int global_quality; | ||
1721 | |||
1722 | #define FF_CODER_TYPE_VLC 0 | ||
1723 | #define FF_CODER_TYPE_AC 1 | ||
1724 | #define FF_CODER_TYPE_RAW 2 | ||
1725 | #define FF_CODER_TYPE_RLE 3 | ||
1726 | #define FF_CODER_TYPE_DEFLATE 4 | ||
1727 | /** | ||
1728 | * coder type | ||
1729 | * - encoding: Set by user. | ||
1730 | * - decoding: unused | ||
1731 | */ | ||
1732 | //MT: int coder_type; | ||
1733 | |||
1734 | /** | ||
1735 | * context model | ||
1736 | * - encoding: Set by user. | ||
1737 | * - decoding: unused | ||
1738 | */ | ||
1739 | //MT: int context_model; | ||
1740 | #if 0 | ||
1741 | /** | ||
1742 | * | ||
1743 | * - encoding: unused | ||
1744 | * - decoding: Set by user. | ||
1745 | */ | ||
1746 | uint8_t * (*realloc)(struct AVCodecContext *s, uint8_t *buf, int buf_size); | ||
1747 | #endif | ||
1748 | |||
1749 | /** | ||
1750 | * slice flags | ||
1751 | * - encoding: unused | ||
1752 | * - decoding: Set by user. | ||
1753 | */ | ||
1754 | //MT: int slice_flags; | ||
1755 | #define SLICE_FLAG_CODED_ORDER 0x0001 ///< draw_horiz_band() is called in coded order instead of display | ||
1756 | #define SLICE_FLAG_ALLOW_FIELD 0x0002 ///< allow draw_horiz_band() with field slices (MPEG2 field pics) | ||
1757 | #define SLICE_FLAG_ALLOW_PLANE 0x0004 ///< allow draw_horiz_band() with 1 component at a time (SVQ1) | ||
1758 | |||
1759 | /** | ||
1760 | * XVideo Motion Acceleration | ||
1761 | * - encoding: forbidden | ||
1762 | * - decoding: set by decoder | ||
1763 | */ | ||
1764 | //MT: int xvmc_acceleration; | ||
1765 | |||
1766 | /** | ||
1767 | * macroblock decision mode | ||
1768 | * - encoding: Set by user. | ||
1769 | * - decoding: unused | ||
1770 | */ | ||
1771 | //MT: int mb_decision; | ||
1772 | #define FF_MB_DECISION_SIMPLE 0 ///< uses mb_cmp | ||
1773 | #define FF_MB_DECISION_BITS 1 ///< chooses the one which needs the fewest bits | ||
1774 | #define FF_MB_DECISION_RD 2 ///< rate distortion | ||
1775 | |||
1776 | /** | ||
1777 | * custom intra quantization matrix | ||
1778 | * - encoding: Set by user, can be NULL. | ||
1779 | * - decoding: Set by libavcodec. | ||
1780 | */ | ||
1781 | //MT: uint16_t *intra_matrix; | ||
1782 | |||
1783 | /** | ||
1784 | * custom inter quantization matrix | ||
1785 | * - encoding: Set by user, can be NULL. | ||
1786 | * - decoding: Set by libavcodec. | ||
1787 | */ | ||
1788 | //MT: uint16_t *inter_matrix; | ||
1789 | |||
1790 | /** | ||
1791 | * fourcc from the AVI stream header (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A'). | ||
1792 | * This is used to work around some encoder bugs. | ||
1793 | * - encoding: unused | ||
1794 | * - decoding: Set by user, will be converted to uppercase by libavcodec during init. | ||
1795 | */ | ||
1796 | //MT: unsigned int stream_codec_tag; | ||
1797 | |||
1798 | /** | ||
1799 | * scene change detection threshold | ||
1800 | * 0 is default, larger means fewer detected scene changes. | ||
1801 | * - encoding: Set by user. | ||
1802 | * - decoding: unused | ||
1803 | */ | ||
1804 | //MT: int scenechange_threshold; | ||
1805 | |||
1806 | /** | ||
1807 | * minimum Lagrange multipler | ||
1808 | * - encoding: Set by user. | ||
1809 | * - decoding: unused | ||
1810 | */ | ||
1811 | //MT: int lmin; | ||
1812 | |||
1813 | /** | ||
1814 | * maximum Lagrange multipler | ||
1815 | * - encoding: Set by user. | ||
1816 | * - decoding: unused | ||
1817 | */ | ||
1818 | //MT: int lmax; | ||
1819 | |||
1820 | /** | ||
1821 | * palette control structure | ||
1822 | * - encoding: ??? (no palette-enabled encoder yet) | ||
1823 | * - decoding: Set by user. | ||
1824 | */ | ||
1825 | //MT: struct AVPaletteControl *palctrl; | ||
1826 | |||
1827 | /** | ||
1828 | * noise reduction strength | ||
1829 | * - encoding: Set by user. | ||
1830 | * - decoding: unused | ||
1831 | */ | ||
1832 | //MT: int noise_reduction; | ||
1833 | |||
1834 | /** | ||
1835 | * Called at the beginning of a frame to get cr buffer for it. | ||
1836 | * Buffer type (size, hints) must be the same. libavcodec won't check it. | ||
1837 | * libavcodec will pass previous buffer in pic, function should return | ||
1838 | * same buffer or new buffer with old frame "painted" into it. | ||
1839 | * If pic.data[0] == NULL must behave like get_buffer(). | ||
1840 | * - encoding: unused | ||
1841 | * - decoding: Set by libavcodec., user can override | ||
1842 | */ | ||
1843 | //MT: int (*reget_buffer)(struct AVCodecContext *c, AVFrame *pic); | ||
1844 | |||
1845 | /** | ||
1846 | * Number of bits which should be loaded into the rc buffer before decoding starts. | ||
1847 | * - encoding: Set by user. | ||
1848 | * - decoding: unused | ||
1849 | */ | ||
1850 | //MT: int rc_initial_buffer_occupancy; | ||
1851 | |||
1852 | /** | ||
1853 | * | ||
1854 | * - encoding: Set by user. | ||
1855 | * - decoding: unused | ||
1856 | */ | ||
1857 | //MT: int inter_threshold; | ||
1858 | |||
1859 | /** | ||
1860 | * CODEC_FLAG2_* | ||
1861 | * - encoding: Set by user. | ||
1862 | * - decoding: Set by user. | ||
1863 | */ | ||
1864 | //MT: int flags2; | ||
1865 | |||
1866 | /** | ||
1867 | * Simulates errors in the bitstream to test error concealment. | ||
1868 | * - encoding: Set by user. | ||
1869 | * - decoding: unused | ||
1870 | */ | ||
1871 | //MT: int error_rate; | ||
1872 | |||
1873 | /** | ||
1874 | * MP3 antialias algorithm, see FF_AA_* below. | ||
1875 | * - encoding: unused | ||
1876 | * - decoding: Set by user. | ||
1877 | */ | ||
1878 | //MT: int antialias_algo; | ||
1879 | #define FF_AA_AUTO 0 | ||
1880 | #define FF_AA_FASTINT 1 //not implemented yet | ||
1881 | #define FF_AA_INT 2 | ||
1882 | #define FF_AA_FLOAT 3 | ||
1883 | /** | ||
1884 | * quantizer noise shaping | ||
1885 | * - encoding: Set by user. | ||
1886 | * - decoding: unused | ||
1887 | */ | ||
1888 | //MT: int quantizer_noise_shaping; | ||
1889 | |||
1890 | /** | ||
1891 | * thread count | ||
1892 | * is used to decide how many independent tasks should be passed to execute() | ||
1893 | * - encoding: Set by user. | ||
1894 | * - decoding: Set by user. | ||
1895 | */ | ||
1896 | //MT: int thread_count; | ||
1897 | |||
1898 | /** | ||
1899 | * The codec may call this to execute several independent things. | ||
1900 | * It will return only after finishing all tasks. | ||
1901 | * The user may replace this with some multithreaded implementation, | ||
1902 | * the default implementation will execute the parts serially. | ||
1903 | * @param count the number of things to execute | ||
1904 | * - encoding: Set by libavcodec, user can override. | ||
1905 | * - decoding: Set by libavcodec, user can override. | ||
1906 | */ | ||
1907 | //MT: int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size); | ||
1908 | |||
1909 | /** | ||
1910 | * thread opaque | ||
1911 | * Can be used by execute() to store some per AVCodecContext stuff. | ||
1912 | * - encoding: set by execute() | ||
1913 | * - decoding: set by execute() | ||
1914 | */ | ||
1915 | //MT: void *thread_opaque; | ||
1916 | |||
1917 | /** | ||
1918 | * Motion estimation threshold below which no motion estimation is | ||
1919 | * performed, but instead the user specified motion vectors are used. | ||
1920 | * | ||
1921 | * - encoding: Set by user. | ||
1922 | * - decoding: unused | ||
1923 | */ | ||
1924 | //MT: int me_threshold; | ||
1925 | |||
1926 | /** | ||
1927 | * Macroblock threshold below which the user specified macroblock types will be used. | ||
1928 | * - encoding: Set by user. | ||
1929 | * - decoding: unused | ||
1930 | */ | ||
1931 | //MT: int mb_threshold; | ||
1932 | |||
1933 | /** | ||
1934 | * precision of the intra DC coefficient - 8 | ||
1935 | * - encoding: Set by user. | ||
1936 | * - decoding: unused | ||
1937 | */ | ||
1938 | //MT: int intra_dc_precision; | ||
1939 | |||
1940 | /** | ||
1941 | * noise vs. sse weight for the nsse comparsion function | ||
1942 | * - encoding: Set by user. | ||
1943 | * - decoding: unused | ||
1944 | */ | ||
1945 | //MT: int nsse_weight; | ||
1946 | |||
1947 | /** | ||
1948 | * Number of macroblock rows at the top which are skipped. | ||
1949 | * - encoding: unused | ||
1950 | * - decoding: Set by user. | ||
1951 | */ | ||
1952 | //MT: int skip_top; | ||
1953 | |||
1954 | /** | ||
1955 | * Number of macroblock rows at the bottom which are skipped. | ||
1956 | * - encoding: unused | ||
1957 | * - decoding: Set by user. | ||
1958 | */ | ||
1959 | //MT: int skip_bottom; | ||
1960 | |||
1961 | /** | ||
1962 | * profile | ||
1963 | * - encoding: Set by user. | ||
1964 | * - decoding: Set by libavcodec. | ||
1965 | */ | ||
1966 | //MT: int profile; | ||
1967 | #define FF_PROFILE_UNKNOWN -99 | ||
1968 | #define FF_PROFILE_AAC_MAIN 0 | ||
1969 | #define FF_PROFILE_AAC_LOW 1 | ||
1970 | #define FF_PROFILE_AAC_SSR 2 | ||
1971 | #define FF_PROFILE_AAC_LTP 3 | ||
1972 | |||
1973 | /** | ||
1974 | * level | ||
1975 | * - encoding: Set by user. | ||
1976 | * - decoding: Set by libavcodec. | ||
1977 | */ | ||
1978 | //MT: int level; | ||
1979 | #define FF_LEVEL_UNKNOWN -99 | ||
1980 | |||
1981 | /** | ||
1982 | * low resolution decoding, 1-> 1/2 size, 2->1/4 size | ||
1983 | * - encoding: unused | ||
1984 | * - decoding: Set by user. | ||
1985 | */ | ||
1986 | //MT: int lowres; | ||
1987 | |||
1988 | /** | ||
1989 | * Bitstream width / height, may be different from width/height if lowres | ||
1990 | * or other things are used. | ||
1991 | * - encoding: unused | ||
1992 | * - decoding: Set by user before init if known. Codec should override / dynamically change if needed. | ||
1993 | */ | ||
1994 | //MT: int coded_width, coded_height; | ||
1995 | |||
1996 | /** | ||
1997 | * frame skip threshold | ||
1998 | * - encoding: Set by user. | ||
1999 | * - decoding: unused | ||
2000 | */ | ||
2001 | //MT: int frame_skip_threshold; | ||
2002 | |||
2003 | /** | ||
2004 | * frame skip factor | ||
2005 | * - encoding: Set by user. | ||
2006 | * - decoding: unused | ||
2007 | */ | ||
2008 | //MT: int frame_skip_factor; | ||
2009 | |||
2010 | /** | ||
2011 | * frame skip exponent | ||
2012 | * - encoding: Set by user. | ||
2013 | * - decoding: unused | ||
2014 | */ | ||
2015 | //MT: int frame_skip_exp; | ||
2016 | |||
2017 | /** | ||
2018 | * frame skip comparison function | ||
2019 | * - encoding: Set by user. | ||
2020 | * - decoding: unused | ||
2021 | */ | ||
2022 | //MT: int frame_skip_cmp; | ||
2023 | |||
2024 | /** | ||
2025 | * Border processing masking, raises the quantizer for mbs on the borders | ||
2026 | * of the picture. | ||
2027 | * - encoding: Set by user. | ||
2028 | * - decoding: unused | ||
2029 | */ | ||
2030 | //MT: float border_masking; | ||
2031 | |||
2032 | /** | ||
2033 | * minimum MB lagrange multipler | ||
2034 | * - encoding: Set by user. | ||
2035 | * - decoding: unused | ||
2036 | */ | ||
2037 | //MT: int mb_lmin; | ||
2038 | |||
2039 | /** | ||
2040 | * maximum MB lagrange multipler | ||
2041 | * - encoding: Set by user. | ||
2042 | * - decoding: unused | ||
2043 | */ | ||
2044 | //MT: int mb_lmax; | ||
2045 | |||
2046 | /** | ||
2047 | * | ||
2048 | * - encoding: Set by user. | ||
2049 | * - decoding: unused | ||
2050 | */ | ||
2051 | //MT: int me_penalty_compensation; | ||
2052 | |||
2053 | /** | ||
2054 | * | ||
2055 | * - encoding: unused | ||
2056 | * - decoding: Set by user. | ||
2057 | */ | ||
2058 | //MT: enum AVDiscard skip_loop_filter; | ||
2059 | |||
2060 | /** | ||
2061 | * | ||
2062 | * - encoding: unused | ||
2063 | * - decoding: Set by user. | ||
2064 | */ | ||
2065 | //MT: enum AVDiscard skip_idct; | ||
2066 | |||
2067 | /** | ||
2068 | * | ||
2069 | * - encoding: unused | ||
2070 | * - decoding: Set by user. | ||
2071 | */ | ||
2072 | //MT: enum AVDiscard skip_frame; | ||
2073 | |||
2074 | /** | ||
2075 | * | ||
2076 | * - encoding: Set by user. | ||
2077 | * - decoding: unused | ||
2078 | */ | ||
2079 | //MT: int bidir_refine; | ||
2080 | |||
2081 | /** | ||
2082 | * | ||
2083 | * - encoding: Set by user. | ||
2084 | * - decoding: unused | ||
2085 | */ | ||
2086 | //MT: int brd_scale; | ||
2087 | |||
2088 | /** | ||
2089 | * constant rate factor - quality-based VBR - values ~correspond to qps | ||
2090 | * - encoding: Set by user. | ||
2091 | * - decoding: unused | ||
2092 | */ | ||
2093 | //MT: float crf; | ||
2094 | |||
2095 | /** | ||
2096 | * constant quantization parameter rate control method | ||
2097 | * - encoding: Set by user. | ||
2098 | * - decoding: unused | ||
2099 | */ | ||
2100 | //MT: int cqp; | ||
2101 | |||
2102 | /** | ||
2103 | * minimum GOP size | ||
2104 | * - encoding: Set by user. | ||
2105 | * - decoding: unused | ||
2106 | */ | ||
2107 | //MT: int keyint_min; | ||
2108 | |||
2109 | /** | ||
2110 | * number of reference frames | ||
2111 | * - encoding: Set by user. | ||
2112 | * - decoding: Set by lavc. | ||
2113 | */ | ||
2114 | //MT: int refs; | ||
2115 | |||
2116 | /** | ||
2117 | * chroma qp offset from luma | ||
2118 | * - encoding: Set by user. | ||
2119 | * - decoding: unused | ||
2120 | */ | ||
2121 | //MT: int chromaoffset; | ||
2122 | |||
2123 | /** | ||
2124 | * Influences how often B-frames are used. | ||
2125 | * - encoding: Set by user. | ||
2126 | * - decoding: unused | ||
2127 | */ | ||
2128 | //MT: int bframebias; | ||
2129 | |||
2130 | /** | ||
2131 | * trellis RD quantization | ||
2132 | * - encoding: Set by user. | ||
2133 | * - decoding: unused | ||
2134 | */ | ||
2135 | //MT: int trellis; | ||
2136 | |||
2137 | /** | ||
2138 | * Reduce fluctuations in qp (before curve compression). | ||
2139 | * - encoding: Set by user. | ||
2140 | * - decoding: unused | ||
2141 | */ | ||
2142 | //MT: float complexityblur; | ||
2143 | |||
2144 | /** | ||
2145 | * in-loop deblocking filter alphac0 parameter | ||
2146 | * alpha is in the range -6...6 | ||
2147 | * - encoding: Set by user. | ||
2148 | * - decoding: unused | ||
2149 | */ | ||
2150 | //MT: int deblockalpha; | ||
2151 | |||
2152 | /** | ||
2153 | * in-loop deblocking filter beta parameter | ||
2154 | * beta is in the range -6...6 | ||
2155 | * - encoding: Set by user. | ||
2156 | * - decoding: unused | ||
2157 | */ | ||
2158 | //MT: int deblockbeta; | ||
2159 | |||
2160 | /** | ||
2161 | * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4 | ||
2162 | * - encoding: Set by user. | ||
2163 | * - decoding: unused | ||
2164 | */ | ||
2165 | //MT: int partitions; | ||
2166 | #define X264_PART_I4X4 0x001 /* Analyze i4x4 */ | ||
2167 | #define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */ | ||
2168 | #define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */ | ||
2169 | #define X264_PART_P4X4 0x020 /* Analyze p8x4, p4x8, p4x4 */ | ||
2170 | #define X264_PART_B8X8 0x100 /* Analyze b16x8, b8x16 and b8x8 */ | ||
2171 | |||
2172 | /** | ||
2173 | * direct MV prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto) | ||
2174 | * - encoding: Set by user. | ||
2175 | * - decoding: unused | ||
2176 | */ | ||
2177 | //MT: int directpred; | ||
2178 | |||
2179 | /** | ||
2180 | * Audio cutoff bandwidth (0 means "automatic") | ||
2181 | * - encoding: Set by user. | ||
2182 | * - decoding: unused | ||
2183 | */ | ||
2184 | //MT: int cutoff; | ||
2185 | |||
2186 | /** | ||
2187 | * Multiplied by qscale for each frame and added to scene_change_score. | ||
2188 | * - encoding: Set by user. | ||
2189 | * - decoding: unused | ||
2190 | */ | ||
2191 | //MT: int scenechange_factor; | ||
2192 | |||
2193 | /** | ||
2194 | * | ||
2195 | * Note: Value depends upon the compare function used for fullpel ME. | ||
2196 | * - encoding: Set by user. | ||
2197 | * - decoding: unused | ||
2198 | */ | ||
2199 | //MT: int mv0_threshold; | ||
2200 | |||
2201 | /** | ||
2202 | * Adjusts sensitivity of b_frame_strategy 1. | ||
2203 | * - encoding: Set by user. | ||
2204 | * - decoding: unused | ||
2205 | */ | ||
2206 | //MT: int b_sensitivity; | ||
2207 | |||
2208 | /** | ||
2209 | * - encoding: Set by user. | ||
2210 | * - decoding: unused | ||
2211 | */ | ||
2212 | //MT: int compression_level; | ||
2213 | #define FF_COMPRESSION_DEFAULT -1 | ||
2214 | |||
2215 | /** | ||
2216 | * Sets whether to use LPC mode - used by FLAC encoder. | ||
2217 | * - encoding: Set by user. | ||
2218 | * - decoding: unused | ||
2219 | */ | ||
2220 | //MT: int use_lpc; | ||
2221 | |||
2222 | /** | ||
2223 | * LPC coefficient precision - used by FLAC encoder | ||
2224 | * - encoding: Set by user. | ||
2225 | * - decoding: unused | ||
2226 | */ | ||
2227 | //MT: int lpc_coeff_precision; | ||
2228 | |||
2229 | /** | ||
2230 | * - encoding: Set by user. | ||
2231 | * - decoding: unused | ||
2232 | */ | ||
2233 | //MT: int min_prediction_order; | ||
2234 | |||
2235 | /** | ||
2236 | * - encoding: Set by user. | ||
2237 | * - decoding: unused | ||
2238 | */ | ||
2239 | //MT: int max_prediction_order; | ||
2240 | |||
2241 | /** | ||
2242 | * search method for selecting prediction order | ||
2243 | * - encoding: Set by user. | ||
2244 | * - decoding: unused | ||
2245 | */ | ||
2246 | //MT: int prediction_order_method; | ||
2247 | |||
2248 | /** | ||
2249 | * - encoding: Set by user. | ||
2250 | * - decoding: unused | ||
2251 | */ | ||
2252 | //MT: int min_partition_order; | ||
2253 | |||
2254 | /** | ||
2255 | * - encoding: Set by user. | ||
2256 | * - decoding: unused | ||
2257 | */ | ||
2258 | //MT: int max_partition_order; | ||
2259 | |||
2260 | /** | ||
2261 | * GOP timecode frame start number, in non drop frame format | ||
2262 | * - encoding: Set by user. | ||
2263 | * - decoding: unused | ||
2264 | */ | ||
2265 | //MT: int64_t timecode_frame_start; | ||
2266 | |||
2267 | #if LIBAVCODEC_VERSION_MAJOR < 53 | ||
2268 | /** | ||
2269 | * Decoder should decode to this many channels if it can (0 for default) | ||
2270 | * - encoding: unused | ||
2271 | * - decoding: Set by user. | ||
2272 | * @deprecated Deprecated in favor of request_channel_layout. | ||
2273 | */ | ||
2274 | //MT: int request_channels; | ||
2275 | #endif | ||
2276 | |||
2277 | /** | ||
2278 | * Percentage of dynamic range compression to be applied by the decoder. | ||
2279 | * The default value is 1.0, corresponding to full compression. | ||
2280 | * - encoding: unused | ||
2281 | * - decoding: Set by user. | ||
2282 | */ | ||
2283 | //MT: float drc_scale; | ||
2284 | |||
2285 | /** | ||
2286 | * opaque 64bit number (generally a PTS) that will be reordered and | ||
2287 | * output in AVFrame.reordered_opaque | ||
2288 | * - encoding: unused | ||
2289 | * - decoding: Set by user. | ||
2290 | */ | ||
2291 | //MT: int64_t reordered_opaque; | ||
2292 | |||
2293 | /** | ||
2294 | * Bits per sample/pixel of internal libavcodec pixel/sample format. | ||
2295 | * This field is applicable only when sample_fmt is SAMPLE_FMT_S32. | ||
2296 | * - encoding: set by user. | ||
2297 | * - decoding: set by libavcodec. | ||
2298 | */ | ||
2299 | //MT: int bits_per_raw_sample; | ||
2300 | |||
2301 | /** | ||
2302 | * Audio channel layout. | ||
2303 | * - encoding: set by user. | ||
2304 | * - decoding: set by libavcodec. | ||
2305 | */ | ||
2306 | int64_t channel_layout; | ||
2307 | |||
2308 | /** | ||
2309 | * Request decoder to use this channel layout if it can (0 for default) | ||
2310 | * - encoding: unused | ||
2311 | * - decoding: Set by user. | ||
2312 | */ | ||
2313 | //MT: int64_t request_channel_layout; | ||
2314 | |||
2315 | /** | ||
2316 | * Ratecontrol attempt to use, at maximum, <value> of what can be used without an underflow. | ||
2317 | * - encoding: Set by user. | ||
2318 | * - decoding: unused. | ||
2319 | */ | ||
2320 | //MT: float rc_max_available_vbv_use; | ||
2321 | |||
2322 | /** | ||
2323 | * Ratecontrol attempt to use, at least, <value> times the amount needed to prevent a vbv overflow. | ||
2324 | * - encoding: Set by user. | ||
2325 | * - decoding: unused. | ||
2326 | */ | ||
2327 | //MT: float rc_min_vbv_overflow_use; | ||
2328 | |||
2329 | /** | ||
2330 | * Hardware accelerator in use | ||
2331 | * - encoding: unused. | ||
2332 | * - decoding: Set by libavcodec | ||
2333 | */ | ||
2334 | //MT: struct AVHWAccel *hwaccel; | ||
2335 | |||
2336 | /** | ||
2337 | * For some codecs, the time base is closer to the field rate than the frame rate. | ||
2338 | * Most notably, H.264 and MPEG-2 specify time_base as half of frame duration | ||
2339 | * if no telecine is used ... | ||
2340 | * | ||
2341 | * Set to time_base ticks per frame. Default 1, e.g., H.264/MPEG-2 set it to 2. | ||
2342 | */ | ||
2343 | //MT: int ticks_per_frame; | ||
2344 | |||
2345 | /** | ||
2346 | * Hardware accelerator context. | ||
2347 | * For some hardware accelerators, a global context needs to be | ||
2348 | * provided by the user. In that case, this holds display-dependent | ||
2349 | * data FFmpeg cannot instantiate itself. Please refer to the | ||
2350 | * FFmpeg HW accelerator documentation to know how to fill this | ||
2351 | * is. e.g. for VA API, this is a struct vaapi_context. | ||
2352 | * - encoding: unused | ||
2353 | * - decoding: Set by user | ||
2354 | */ | ||
2355 | //MT: void *hwaccel_context; | ||
2356 | } AVCodecContext; | ||
2357 | |||
2358 | /** | ||
2359 | * AVCodec. | ||
2360 | */ | ||
2361 | typedef struct AVCodec { | ||
2362 | /** | ||
2363 | * Name of the codec implementation. | ||
2364 | * The name is globally unique among encoders and among decoders (but an | ||
2365 | * encoder and a decoder can share the same name). | ||
2366 | * This is the primary way to find a codec from the user perspective. | ||
2367 | */ | ||
2368 | const char *name; | ||
2369 | enum CodecType type; | ||
2370 | enum CodecID id; | ||
2371 | int priv_data_size; | ||
2372 | int (*init)(AVCodecContext *); | ||
2373 | int (*encode)(AVCodecContext *, uint8_t *buf, int buf_size, void *data); | ||
2374 | int (*close)(AVCodecContext *); | ||
2375 | int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, | ||
2376 | const uint8_t *buf, int buf_size); | ||
2377 | /** | ||
2378 | * Codec capabilities. | ||
2379 | * see CODEC_CAP_* | ||
2380 | */ | ||
2381 | //MT: int capabilities; | ||
2382 | //MT: struct AVCodec *next; | ||
2383 | /** | ||
2384 | * Flush buffers. | ||
2385 | * Will be called when seeking | ||
2386 | */ | ||
2387 | //MT: void (*flush)(AVCodecContext *); | ||
2388 | //MT: const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0} | ||
2389 | //MT: const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 | ||
2390 | /** | ||
2391 | * Descriptive name for the codec, meant to be more human readable than \p name. | ||
2392 | * You \e should use the NULL_IF_CONFIG_SMALL() macro to define it. | ||
2393 | */ | ||
2394 | const char *long_name; | ||
2395 | const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0 | ||
2396 | const enum SampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 | ||
2397 | const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0 | ||
2398 | } AVCodec; | ||
2399 | |||
2400 | #if 0 /* MT : DELETE THIS LINE ONLY. */ | ||
2401 | /** | ||
2402 | * AVHWAccel. | ||
2403 | */ | ||
2404 | typedef struct AVHWAccel { | ||
2405 | /** | ||
2406 | * Name of the hardware accelerated codec. | ||
2407 | * The name is globally unique among encoders and among decoders (but an | ||
2408 | * encoder and a decoder can share the same name). | ||
2409 | */ | ||
2410 | const char *name; | ||
2411 | |||
2412 | /** | ||
2413 | * Type of codec implemented by the hardware accelerator. | ||
2414 | * | ||
2415 | * See CODEC_TYPE_xxx | ||
2416 | */ | ||
2417 | enum CodecType type; | ||
2418 | |||
2419 | /** | ||
2420 | * Codec implemented by the hardware accelerator. | ||
2421 | * | ||
2422 | * See CODEC_ID_xxx | ||
2423 | */ | ||
2424 | enum CodecID id; | ||
2425 | |||
2426 | /** | ||
2427 | * Supported pixel format. | ||
2428 | * | ||
2429 | * Only hardware accelerated formats are supported here. | ||
2430 | */ | ||
2431 | enum PixelFormat pix_fmt; | ||
2432 | |||
2433 | /** | ||
2434 | * Hardware accelerated codec capabilities. | ||
2435 | * see FF_HWACCEL_CODEC_CAP_* | ||
2436 | */ | ||
2437 | int capabilities; | ||
2438 | |||
2439 | struct AVHWAccel *next; | ||
2440 | |||
2441 | /** | ||
2442 | * Called at the beginning of each frame or field picture. | ||
2443 | * | ||
2444 | * Meaningful frame information (codec specific) is guaranteed to | ||
2445 | * be parsed at this point. This function is mandatory. | ||
2446 | * | ||
2447 | * Note that \p buf can be NULL along with \p buf_size set to 0. | ||
2448 | * Otherwise, this means the whole frame is available at this point. | ||
2449 | * | ||
2450 | * @param avctx the codec context | ||
2451 | * @param buf the frame data buffer base | ||
2452 | * @param buf_size the size of the frame in bytes | ||
2453 | * @return zero if successful, a negative value otherwise | ||
2454 | */ | ||
2455 | int (*start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size); | ||
2456 | |||
2457 | /** | ||
2458 | * Callback for each slice. | ||
2459 | * | ||
2460 | * Meaningful slice information (codec specific) is guaranteed to | ||
2461 | * be parsed at this point. This function is mandatory. | ||
2462 | * | ||
2463 | * @param avctx the codec context | ||
2464 | * @param buf the slice data buffer base | ||
2465 | * @param buf_size the size of the slice in bytes | ||
2466 | * @return zero if successful, a negative value otherwise | ||
2467 | */ | ||
2468 | int (*decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size); | ||
2469 | |||
2470 | /** | ||
2471 | * Called at the end of each frame or field picture. | ||
2472 | * | ||
2473 | * The whole picture is parsed at this point and can now be sent | ||
2474 | * to the hardware accelerator. This function is mandatory. | ||
2475 | * | ||
2476 | * @param avctx the codec context | ||
2477 | * @return zero if successful, a negative value otherwise | ||
2478 | */ | ||
2479 | int (*end_frame)(AVCodecContext *avctx); | ||
2480 | |||
2481 | /** | ||
2482 | * Size of HW accelerator private data. | ||
2483 | * | ||
2484 | * Private data is allocated with av_mallocz() before | ||
2485 | * AVCodecContext.get_buffer() and deallocated after | ||
2486 | * AVCodecContext.release_buffer(). | ||
2487 | */ | ||
2488 | int priv_data_size; | ||
2489 | } AVHWAccel; | ||
2490 | |||
2491 | /** | ||
2492 | * four components are given, that's all. | ||
2493 | * the last component is alpha | ||
2494 | */ | ||
2495 | typedef struct AVPicture { | ||
2496 | uint8_t *data[4]; | ||
2497 | int linesize[4]; ///< number of bytes per line | ||
2498 | } AVPicture; | ||
2499 | |||
2500 | /** | ||
2501 | * AVPaletteControl | ||
2502 | * This structure defines a method for communicating palette changes | ||
2503 | * between and demuxer and a decoder. | ||
2504 | * | ||
2505 | * @deprecated Use AVPacket to send palette changes instead. | ||
2506 | * This is totally broken. | ||
2507 | */ | ||
2508 | #define AVPALETTE_SIZE 1024 | ||
2509 | #define AVPALETTE_COUNT 256 | ||
2510 | typedef struct AVPaletteControl { | ||
2511 | |||
2512 | /* Demuxer sets this to 1 to indicate the palette has changed; | ||
2513 | * decoder resets to 0. */ | ||
2514 | int palette_changed; | ||
2515 | |||
2516 | /* 4-byte ARGB palette entries, stored in native byte order; note that | ||
2517 | * the individual palette components should be on a 8-bit scale; if | ||
2518 | * the palette data comes from an IBM VGA native format, the component | ||
2519 | * data is probably 6 bits in size and needs to be scaled. */ | ||
2520 | unsigned int palette[AVPALETTE_COUNT]; | ||
2521 | |||
2522 | } AVPaletteControl attribute_deprecated; | ||
2523 | |||
2524 | enum AVSubtitleType { | ||
2525 | SUBTITLE_NONE, | ||
2526 | |||
2527 | SUBTITLE_BITMAP, ///< A bitmap, pict will be set | ||
2528 | |||
2529 | /** | ||
2530 | * Plain text, the text field must be set by the decoder and is | ||
2531 | * authoritative. ass and pict fields may contain approximations. | ||
2532 | */ | ||
2533 | SUBTITLE_TEXT, | ||
2534 | |||
2535 | /** | ||
2536 | * Formatted text, the ass field must be set by the decoder and is | ||
2537 | * authoritative. pict and text fields may contain approximations. | ||
2538 | */ | ||
2539 | SUBTITLE_ASS, | ||
2540 | }; | ||
2541 | |||
2542 | typedef struct AVSubtitleRect { | ||
2543 | int x; ///< top left corner of pict, undefined when pict is not set | ||
2544 | int y; ///< top left corner of pict, undefined when pict is not set | ||
2545 | int w; ///< width of pict, undefined when pict is not set | ||
2546 | int h; ///< height of pict, undefined when pict is not set | ||
2547 | int nb_colors; ///< number of colors in pict, undefined when pict is not set | ||
2548 | |||
2549 | /** | ||
2550 | * data+linesize for the bitmap of this subtitle. | ||
2551 | * can be set for text/ass as well once they where rendered | ||
2552 | */ | ||
2553 | AVPicture pict; | ||
2554 | enum AVSubtitleType type; | ||
2555 | |||
2556 | char *text; ///< 0 terminated plain UTF-8 text | ||
2557 | |||
2558 | /** | ||
2559 | * 0 terminated ASS/SSA compatible event line. | ||
2560 | * The pressentation of this is unaffected by the other values in this | ||
2561 | * struct. | ||
2562 | */ | ||
2563 | char *ass; | ||
2564 | } AVSubtitleRect; | ||
2565 | |||
2566 | typedef struct AVSubtitle { | ||
2567 | uint16_t format; /* 0 = graphics */ | ||
2568 | uint32_t start_display_time; /* relative to packet pts, in ms */ | ||
2569 | uint32_t end_display_time; /* relative to packet pts, in ms */ | ||
2570 | unsigned num_rects; | ||
2571 | AVSubtitleRect **rects; | ||
2572 | } AVSubtitle; | ||
2573 | |||
2574 | |||
2575 | /* resample.c */ | ||
2576 | |||
2577 | struct ReSampleContext; | ||
2578 | struct AVResampleContext; | ||
2579 | |||
2580 | typedef struct ReSampleContext ReSampleContext; | ||
2581 | |||
2582 | #if LIBAVCODEC_VERSION_MAJOR < 53 | ||
2583 | /** | ||
2584 | * @deprecated Use av_audio_resample_init() instead. | ||
2585 | */ | ||
2586 | attribute_deprecated ReSampleContext *audio_resample_init(int output_channels, int input_channels, | ||
2587 | int output_rate, int input_rate); | ||
2588 | #endif | ||
2589 | /** | ||
2590 | * Initializes audio resampling context | ||
2591 | * | ||
2592 | * @param output_channels number of output channels | ||
2593 | * @param input_channels number of input channels | ||
2594 | * @param output_rate output sample rate | ||
2595 | * @param input_rate input sample rate | ||
2596 | * @param sample_fmt_out requested output sample format | ||
2597 | * @param sample_fmt_in input sample format | ||
2598 | * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq | ||
2599 | * @param log2_phase_count log2 of the number of entries in the polyphase filterbank | ||
2600 | * @param linear If 1 then the used FIR filter will be linearly interpolated | ||
2601 | between the 2 closest, if 0 the closest will be used | ||
2602 | * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate | ||
2603 | * @return allocated ReSampleContext, NULL if error occured | ||
2604 | */ | ||
2605 | ReSampleContext *av_audio_resample_init(int output_channels, int input_channels, | ||
2606 | int output_rate, int input_rate, | ||
2607 | enum SampleFormat sample_fmt_out, | ||
2608 | enum SampleFormat sample_fmt_in, | ||
2609 | int filter_length, int log2_phase_count, | ||
2610 | int linear, double cutoff); | ||
2611 | |||
2612 | int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples); | ||
2613 | void audio_resample_close(ReSampleContext *s); | ||
2614 | |||
2615 | |||
2616 | /** | ||
2617 | * Initializes an audio resampler. | ||
2618 | * Note, if either rate is not an integer then simply scale both rates up so they are. | ||
2619 | * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq | ||
2620 | * @param log2_phase_count log2 of the number of entries in the polyphase filterbank | ||
2621 | * @param linear If 1 then the used FIR filter will be linearly interpolated | ||
2622 | between the 2 closest, if 0 the closest will be used | ||
2623 | * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate | ||
2624 | */ | ||
2625 | struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear, double cutoff); | ||
2626 | |||
2627 | /** | ||
2628 | * resamples. | ||
2629 | * @param src an array of unconsumed samples | ||
2630 | * @param consumed the number of samples of src which have been consumed are returned here | ||
2631 | * @param src_size the number of unconsumed samples available | ||
2632 | * @param dst_size the amount of space in samples available in dst | ||
2633 | * @param update_ctx If this is 0 then the context will not be modified, that way several channels can be resampled with the same context. | ||
2634 | * @return the number of samples written in dst or -1 if an error occurred | ||
2635 | */ | ||
2636 | int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx); | ||
2637 | |||
2638 | |||
2639 | /** | ||
2640 | * Compensates samplerate/timestamp drift. The compensation is done by changing | ||
2641 | * the resampler parameters, so no audible clicks or similar distortions occur | ||
2642 | * @param compensation_distance distance in output samples over which the compensation should be performed | ||
2643 | * @param sample_delta number of output samples which should be output less | ||
2644 | * | ||
2645 | * example: av_resample_compensate(c, 10, 500) | ||
2646 | * here instead of 510 samples only 500 samples would be output | ||
2647 | * | ||
2648 | * note, due to rounding the actual compensation might be slightly different, | ||
2649 | * especially if the compensation_distance is large and the in_rate used during init is small | ||
2650 | */ | ||
2651 | void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance); | ||
2652 | void av_resample_close(struct AVResampleContext *c); | ||
2653 | |||
2654 | /** | ||
2655 | * Allocate memory for a picture. Call avpicture_free to free it. | ||
2656 | * | ||
2657 | * @param picture the picture to be filled in | ||
2658 | * @param pix_fmt the format of the picture | ||
2659 | * @param width the width of the picture | ||
2660 | * @param height the height of the picture | ||
2661 | * @return zero if successful, a negative value if not | ||
2662 | */ | ||
2663 | int avpicture_alloc(AVPicture *picture, int pix_fmt, int width, int height); | ||
2664 | |||
2665 | /** | ||
2666 | * Free a picture previously allocated by avpicture_alloc(). | ||
2667 | * | ||
2668 | * @param picture the AVPicture to be freed | ||
2669 | */ | ||
2670 | void avpicture_free(AVPicture *picture); | ||
2671 | |||
2672 | /** | ||
2673 | * Fill in the AVPicture fields. | ||
2674 | * The fields of the given AVPicture are filled in by using the 'ptr' address | ||
2675 | * which points to the image data buffer. Depending on the specified picture | ||
2676 | * format, one or multiple image data pointers and line sizes will be set. | ||
2677 | * If a planar format is specified, several pointers will be set pointing to | ||
2678 | * the different picture planes and the line sizes of the different planes | ||
2679 | * will be stored in the lines_sizes array. | ||
2680 | * | ||
2681 | * @param picture AVPicture whose fields are to be filled in | ||
2682 | * @param ptr Buffer which will contain or contains the actual image data | ||
2683 | * @param pix_fmt The format in which the picture data is stored. | ||
2684 | * @param width the width of the image in pixels | ||
2685 | * @param height the height of the image in pixels | ||
2686 | * @return size of the image data in bytes | ||
2687 | */ | ||
2688 | int avpicture_fill(AVPicture *picture, uint8_t *ptr, | ||
2689 | int pix_fmt, int width, int height); | ||
2690 | int avpicture_layout(const AVPicture* src, int pix_fmt, int width, int height, | ||
2691 | unsigned char *dest, int dest_size); | ||
2692 | |||
2693 | /** | ||
2694 | * Calculate the size in bytes that a picture of the given width and height | ||
2695 | * would occupy if stored in the given picture format. | ||
2696 | * | ||
2697 | * @param pix_fmt the given picture format | ||
2698 | * @param width the width of the image | ||
2699 | * @param height the height of the image | ||
2700 | * @return Image data size in bytes | ||
2701 | */ | ||
2702 | int avpicture_get_size(int pix_fmt, int width, int height); | ||
2703 | void avcodec_get_chroma_sub_sample(int pix_fmt, int *h_shift, int *v_shift); | ||
2704 | const char *avcodec_get_pix_fmt_name(int pix_fmt); | ||
2705 | void avcodec_set_dimensions(AVCodecContext *s, int width, int height); | ||
2706 | enum PixelFormat avcodec_get_pix_fmt(const char* name); | ||
2707 | unsigned int avcodec_pix_fmt_to_codec_tag(enum PixelFormat p); | ||
2708 | |||
2709 | #define FF_LOSS_RESOLUTION 0x0001 /**< loss due to resolution change */ | ||
2710 | #define FF_LOSS_DEPTH 0x0002 /**< loss due to color depth change */ | ||
2711 | #define FF_LOSS_COLORSPACE 0x0004 /**< loss due to color space conversion */ | ||
2712 | #define FF_LOSS_ALPHA 0x0008 /**< loss of alpha bits */ | ||
2713 | #define FF_LOSS_COLORQUANT 0x0010 /**< loss due to color quantization */ | ||
2714 | #define FF_LOSS_CHROMA 0x0020 /**< loss of chroma (e.g. RGB to gray conversion) */ | ||
2715 | |||
2716 | /** | ||
2717 | * Computes what kind of losses will occur when converting from one specific | ||
2718 | * pixel format to another. | ||
2719 | * When converting from one pixel format to another, information loss may occur. | ||
2720 | * For example, when converting from RGB24 to GRAY, the color information will | ||
2721 | * be lost. Similarly, other losses occur when converting from some formats to | ||
2722 | * other formats. These losses can involve loss of chroma, but also loss of | ||
2723 | * resolution, loss of color depth, loss due to the color space conversion, loss | ||
2724 | * of the alpha bits or loss due to color quantization. | ||
2725 | * avcodec_get_fix_fmt_loss() informs you about the various types of losses | ||
2726 | * which will occur when converting from one pixel format to another. | ||
2727 | * | ||
2728 | * @param[in] dst_pix_fmt destination pixel format | ||
2729 | * @param[in] src_pix_fmt source pixel format | ||
2730 | * @param[in] has_alpha Whether the source pixel format alpha channel is used. | ||
2731 | * @return Combination of flags informing you what kind of losses will occur. | ||
2732 | */ | ||
2733 | int avcodec_get_pix_fmt_loss(int dst_pix_fmt, int src_pix_fmt, | ||
2734 | int has_alpha); | ||
2735 | |||
2736 | /** | ||
2737 | * Finds the best pixel format to convert to given a certain source pixel | ||
2738 | * format. When converting from one pixel format to another, information loss | ||
2739 | * may occur. For example, when converting from RGB24 to GRAY, the color | ||
2740 | * information will be lost. Similarly, other losses occur when converting from | ||
2741 | * some formats to other formats. avcodec_find_best_pix_fmt() searches which of | ||
2742 | * the given pixel formats should be used to suffer the least amount of loss. | ||
2743 | * The pixel formats from which it chooses one, are determined by the | ||
2744 | * \p pix_fmt_mask parameter. | ||
2745 | * | ||
2746 | * @code | ||
2747 | * src_pix_fmt = PIX_FMT_YUV420P; | ||
2748 | * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24); | ||
2749 | * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss); | ||
2750 | * @endcode | ||
2751 | * | ||
2752 | * @param[in] pix_fmt_mask bitmask determining which pixel format to choose from | ||
2753 | * @param[in] src_pix_fmt source pixel format | ||
2754 | * @param[in] has_alpha Whether the source pixel format alpha channel is used. | ||
2755 | * @param[out] loss_ptr Combination of flags informing you what kind of losses will occur. | ||
2756 | * @return The best pixel format to convert to or -1 if none was found. | ||
2757 | */ | ||
2758 | int avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, int src_pix_fmt, | ||
2759 | int has_alpha, int *loss_ptr); | ||
2760 | |||
2761 | |||
2762 | /** | ||
2763 | * Print in buf the string corresponding to the pixel format with | ||
2764 | * number pix_fmt, or an header if pix_fmt is negative. | ||
2765 | * | ||
2766 | * @param[in] buf the buffer where to write the string | ||
2767 | * @param[in] buf_size the size of buf | ||
2768 | * @param[in] pix_fmt the number of the pixel format to print the corresponding info string, or | ||
2769 | * a negative value to print the corresponding header. | ||
2770 | * Meaningful values for obtaining a pixel format info vary from 0 to PIX_FMT_NB -1. | ||
2771 | */ | ||
2772 | void avcodec_pix_fmt_string (char *buf, int buf_size, int pix_fmt); | ||
2773 | |||
2774 | #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */ | ||
2775 | #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */ | ||
2776 | |||
2777 | /** | ||
2778 | * Tell if an image really has transparent alpha values. | ||
2779 | * @return ored mask of FF_ALPHA_xxx constants | ||
2780 | */ | ||
2781 | int img_get_alpha_info(const AVPicture *src, | ||
2782 | int pix_fmt, int width, int height); | ||
2783 | |||
2784 | /* deinterlace a picture */ | ||
2785 | /* deinterlace - if not supported return -1 */ | ||
2786 | int avpicture_deinterlace(AVPicture *dst, const AVPicture *src, | ||
2787 | int pix_fmt, int width, int height); | ||
2788 | |||
2789 | /* external high level API */ | ||
2790 | |||
2791 | /** | ||
2792 | * If c is NULL, returns the first registered codec, | ||
2793 | * if c is non-NULL, returns the next registered codec after c, | ||
2794 | * or NULL if c is the last one. | ||
2795 | */ | ||
2796 | AVCodec *av_codec_next(AVCodec *c); | ||
2797 | |||
2798 | /** | ||
2799 | * Returns the LIBAVCODEC_VERSION_INT constant. | ||
2800 | */ | ||
2801 | unsigned avcodec_version(void); | ||
2802 | |||
2803 | /** | ||
2804 | * Initializes libavcodec. | ||
2805 | * | ||
2806 | * @warning This function \e must be called before any other libavcodec | ||
2807 | * function. | ||
2808 | */ | ||
2809 | void avcodec_init(void); | ||
2810 | |||
2811 | #if LIBAVCODEC_VERSION_MAJOR < 53 | ||
2812 | /** | ||
2813 | * @deprecated Deprecated in favor of avcodec_register(). | ||
2814 | */ | ||
2815 | attribute_deprecated void register_avcodec(AVCodec *codec); | ||
2816 | #endif | ||
2817 | |||
2818 | /** | ||
2819 | * Register the codec \p codec and initialize libavcodec. | ||
2820 | * | ||
2821 | * @see avcodec_init() | ||
2822 | */ | ||
2823 | void avcodec_register(AVCodec *codec); | ||
2824 | |||
2825 | /** | ||
2826 | * Finds a registered encoder with a matching codec ID. | ||
2827 | * | ||
2828 | * @param id CodecID of the requested encoder | ||
2829 | * @return An encoder if one was found, NULL otherwise. | ||
2830 | */ | ||
2831 | AVCodec *avcodec_find_encoder(enum CodecID id); | ||
2832 | |||
2833 | /** | ||
2834 | * Finds a registered encoder with the specified name. | ||
2835 | * | ||
2836 | * @param name name of the requested encoder | ||
2837 | * @return An encoder if one was found, NULL otherwise. | ||
2838 | */ | ||
2839 | AVCodec *avcodec_find_encoder_by_name(const char *name); | ||
2840 | |||
2841 | /** | ||
2842 | * Finds a registered decoder with a matching codec ID. | ||
2843 | * | ||
2844 | * @param id CodecID of the requested decoder | ||
2845 | * @return A decoder if one was found, NULL otherwise. | ||
2846 | */ | ||
2847 | AVCodec *avcodec_find_decoder(enum CodecID id); | ||
2848 | |||
2849 | /** | ||
2850 | * Finds a registered decoder with the specified name. | ||
2851 | * | ||
2852 | * @param name name of the requested decoder | ||
2853 | * @return A decoder if one was found, NULL otherwise. | ||
2854 | */ | ||
2855 | AVCodec *avcodec_find_decoder_by_name(const char *name); | ||
2856 | void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode); | ||
2857 | |||
2858 | /** | ||
2859 | * Sets the fields of the given AVCodecContext to default values. | ||
2860 | * | ||
2861 | * @param s The AVCodecContext of which the fields should be set to default values. | ||
2862 | */ | ||
2863 | void avcodec_get_context_defaults(AVCodecContext *s); | ||
2864 | |||
2865 | /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! | ||
2866 | * we WILL change its arguments and name a few times! */ | ||
2867 | void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType); | ||
2868 | |||
2869 | /** | ||
2870 | * Allocates an AVCodecContext and sets its fields to default values. The | ||
2871 | * resulting struct can be deallocated by simply calling av_free(). | ||
2872 | * | ||
2873 | * @return An AVCodecContext filled with default values or NULL on failure. | ||
2874 | * @see avcodec_get_context_defaults | ||
2875 | */ | ||
2876 | AVCodecContext *avcodec_alloc_context(void); | ||
2877 | |||
2878 | /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! | ||
2879 | * we WILL change its arguments and name a few times! */ | ||
2880 | AVCodecContext *avcodec_alloc_context2(enum CodecType); | ||
2881 | |||
2882 | /** | ||
2883 | * Sets the fields of the given AVFrame to default values. | ||
2884 | * | ||
2885 | * @param pic The AVFrame of which the fields should be set to default values. | ||
2886 | */ | ||
2887 | void avcodec_get_frame_defaults(AVFrame *pic); | ||
2888 | |||
2889 | /** | ||
2890 | * Allocates an AVFrame and sets its fields to default values. The resulting | ||
2891 | * struct can be deallocated by simply calling av_free(). | ||
2892 | * | ||
2893 | * @return An AVFrame filled with default values or NULL on failure. | ||
2894 | * @see avcodec_get_frame_defaults | ||
2895 | */ | ||
2896 | AVFrame *avcodec_alloc_frame(void); | ||
2897 | |||
2898 | int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic); | ||
2899 | void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic); | ||
2900 | int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic); | ||
2901 | void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height); | ||
2902 | |||
2903 | /** | ||
2904 | * Checks if the given dimension of a picture is valid, meaning that all | ||
2905 | * bytes of the picture can be addressed with a signed int. | ||
2906 | * | ||
2907 | * @param[in] w Width of the picture. | ||
2908 | * @param[in] h Height of the picture. | ||
2909 | * @return Zero if valid, a negative value if invalid. | ||
2910 | */ | ||
2911 | int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h); | ||
2912 | enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt); | ||
2913 | |||
2914 | int avcodec_thread_init(AVCodecContext *s, int thread_count); | ||
2915 | void avcodec_thread_free(AVCodecContext *s); | ||
2916 | int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); | ||
2917 | int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); | ||
2918 | //FIXME func typedef | ||
2919 | |||
2920 | /** | ||
2921 | * Initializes the AVCodecContext to use the given AVCodec. Prior to using this | ||
2922 | * function the context has to be allocated. | ||
2923 | * | ||
2924 | * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), | ||
2925 | * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for | ||
2926 | * retrieving a codec. | ||
2927 | * | ||
2928 | * @warning This function is not thread safe! | ||
2929 | * | ||
2930 | * @code | ||
2931 | * avcodec_register_all(); | ||
2932 | * codec = avcodec_find_decoder(CODEC_ID_H264); | ||
2933 | * if (!codec) | ||
2934 | * exit(1); | ||
2935 | * | ||
2936 | * context = avcodec_alloc_context(); | ||
2937 | * | ||
2938 | * if (avcodec_open(context, codec) < 0) | ||
2939 | * exit(1); | ||
2940 | * @endcode | ||
2941 | * | ||
2942 | * @param avctx The context which will be set up to use the given codec. | ||
2943 | * @param codec The codec to use within the context. | ||
2944 | * @return zero on success, a negative value on error | ||
2945 | * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder | ||
2946 | */ | ||
2947 | int avcodec_open(AVCodecContext *avctx, AVCodec *codec); | ||
2948 | |||
2949 | /** | ||
2950 | * Decodes an audio frame from \p buf into \p samples. | ||
2951 | * The avcodec_decode_audio2() function decodes an audio frame from the input | ||
2952 | * buffer \p buf of size \p buf_size. To decode it, it makes use of the | ||
2953 | * audio codec which was coupled with \p avctx using avcodec_open(). The | ||
2954 | * resulting decoded frame is stored in output buffer \p samples. If no frame | ||
2955 | * could be decompressed, \p frame_size_ptr is zero. Otherwise, it is the | ||
2956 | * decompressed frame size in \e bytes. | ||
2957 | * | ||
2958 | * @warning You \e must set \p frame_size_ptr to the allocated size of the | ||
2959 | * output buffer before calling avcodec_decode_audio2(). | ||
2960 | * | ||
2961 | * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than | ||
2962 | * the actual read bytes because some optimized bitstream readers read 32 or 64 | ||
2963 | * bits at once and could read over the end. | ||
2964 | * | ||
2965 | * @warning The end of the input buffer \p buf should be set to 0 to ensure that | ||
2966 | * no overreading happens for damaged MPEG streams. | ||
2967 | * | ||
2968 | * @note You might have to align the input buffer \p buf and output buffer \p | ||
2969 | * samples. The alignment requirements depend on the CPU: On some CPUs it isn't | ||
2970 | * necessary at all, on others it won't work at all if not aligned and on others | ||
2971 | * it will work but it will have an impact on performance. In practice, the | ||
2972 | * bitstream should have 4 byte alignment at minimum and all sample data should | ||
2973 | * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If | ||
2974 | * the linesize is not a multiple of 16 then there's no sense in aligning the | ||
2975 | * start of the buffer to 16. | ||
2976 | * | ||
2977 | * @param avctx the codec context | ||
2978 | * @param[out] samples the output buffer | ||
2979 | * @param[in,out] frame_size_ptr the output buffer size in bytes | ||
2980 | * @param[in] buf the input buffer | ||
2981 | * @param[in] buf_size the input buffer size in bytes | ||
2982 | * @return On error a negative value is returned, otherwise the number of bytes | ||
2983 | * used or zero if no frame could be decompressed. | ||
2984 | */ | ||
2985 | int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, | ||
2986 | int *frame_size_ptr, | ||
2987 | const uint8_t *buf, int buf_size); | ||
2988 | |||
2989 | /** | ||
2990 | * Decodes a video frame from \p buf into \p picture. | ||
2991 | * The avcodec_decode_video() function decodes a video frame from the input | ||
2992 | * buffer \p buf of size \p buf_size. To decode it, it makes use of the | ||
2993 | * video codec which was coupled with \p avctx using avcodec_open(). The | ||
2994 | * resulting decoded frame is stored in \p picture. | ||
2995 | * | ||
2996 | * @warning The input buffer must be \c FF_INPUT_BUFFER_PADDING_SIZE larger than | ||
2997 | * the actual read bytes because some optimized bitstream readers read 32 or 64 | ||
2998 | * bits at once and could read over the end. | ||
2999 | * | ||
3000 | * @warning The end of the input buffer \p buf should be set to 0 to ensure that | ||
3001 | * no overreading happens for damaged MPEG streams. | ||
3002 | * | ||
3003 | * @note You might have to align the input buffer \p buf and output buffer \p | ||
3004 | * samples. The alignment requirements depend on the CPU: on some CPUs it isn't | ||
3005 | * necessary at all, on others it won't work at all if not aligned and on others | ||
3006 | * it will work but it will have an impact on performance. In practice, the | ||
3007 | * bitstream should have 4 byte alignment at minimum and all sample data should | ||
3008 | * be 16 byte aligned unless the CPU doesn't need it (AltiVec and SSE do). If | ||
3009 | * the linesize is not a multiple of 16 then there's no sense in aligning the | ||
3010 | * start of the buffer to 16. | ||
3011 | * | ||
3012 | * @note Some codecs have a delay between input and output, these need to be | ||
3013 | * feeded with buf=NULL, buf_size=0 at the end to return the remaining frames. | ||
3014 | * | ||
3015 | * @param avctx the codec context | ||
3016 | * @param[out] picture The AVFrame in which the decoded video frame will be stored. | ||
3017 | * @param[in] buf the input buffer | ||
3018 | * @param[in] buf_size the size of the input buffer in bytes | ||
3019 | * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero. | ||
3020 | * @return On error a negative value is returned, otherwise the number of bytes | ||
3021 | * used or zero if no frame could be decompressed. | ||
3022 | */ | ||
3023 | int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, | ||
3024 | int *got_picture_ptr, | ||
3025 | const uint8_t *buf, int buf_size); | ||
3026 | |||
3027 | /* Decode a subtitle message. Return -1 if error, otherwise return the | ||
3028 | * number of bytes used. If no subtitle could be decompressed, | ||
3029 | * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ | ||
3030 | int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, | ||
3031 | int *got_sub_ptr, | ||
3032 | const uint8_t *buf, int buf_size); | ||
3033 | int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, | ||
3034 | int *data_size_ptr, | ||
3035 | uint8_t *buf, int buf_size); | ||
3036 | |||
3037 | /** | ||
3038 | * Encodes an audio frame from \p samples into \p buf. | ||
3039 | * The avcodec_encode_audio() function encodes an audio frame from the input | ||
3040 | * buffer \p samples. To encode it, it makes use of the audio codec which was | ||
3041 | * coupled with \p avctx using avcodec_open(). The resulting encoded frame is | ||
3042 | * stored in output buffer \p buf. | ||
3043 | * | ||
3044 | * @note The output buffer should be at least \c FF_MIN_BUFFER_SIZE bytes large. | ||
3045 | * | ||
3046 | * @param avctx the codec context | ||
3047 | * @param[out] buf the output buffer | ||
3048 | * @param[in] buf_size the output buffer size | ||
3049 | * @param[in] samples the input buffer containing the samples | ||
3050 | * The number of samples read from this buffer is frame_size*channels, | ||
3051 | * both of which are defined in \p avctx. | ||
3052 | * For PCM audio the number of samples read from \p samples is equal to | ||
3053 | * \p buf_size * input_sample_size / output_sample_size. | ||
3054 | * @return On error a negative value is returned, on success zero or the number | ||
3055 | * of bytes used to encode the data read from the input buffer. | ||
3056 | */ | ||
3057 | int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, | ||
3058 | const short *samples); | ||
3059 | |||
3060 | /** | ||
3061 | * Encodes a video frame from \p pict into \p buf. | ||
3062 | * The avcodec_encode_video() function encodes a video frame from the input | ||
3063 | * \p pict. To encode it, it makes use of the video codec which was coupled with | ||
3064 | * \p avctx using avcodec_open(). The resulting encoded bytes representing the | ||
3065 | * frame are stored in the output buffer \p buf. The input picture should be | ||
3066 | * stored using a specific format, namely \c avctx.pix_fmt. | ||
3067 | * | ||
3068 | * @param avctx the codec context | ||
3069 | * @param[out] buf the output buffer for the bitstream of encoded frame | ||
3070 | * @param[in] buf_size the size of the output buffer in bytes | ||
3071 | * @param[in] pict the input picture to encode | ||
3072 | * @return On error a negative value is returned, on success zero or the number | ||
3073 | * of bytes used from the output buffer. | ||
3074 | */ | ||
3075 | int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, | ||
3076 | const AVFrame *pict); | ||
3077 | int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, | ||
3078 | const AVSubtitle *sub); | ||
3079 | |||
3080 | int avcodec_close(AVCodecContext *avctx); | ||
3081 | |||
3082 | /** | ||
3083 | * Register all the codecs, parsers and bitstream filters which were enabled at | ||
3084 | * configuration time. If you do not call this function you can select exactly | ||
3085 | * which formats you want to support, by using the individual registration | ||
3086 | * functions. | ||
3087 | * | ||
3088 | * @see avcodec_register | ||
3089 | * @see av_register_codec_parser | ||
3090 | * @see av_register_bitstream_filter | ||
3091 | */ | ||
3092 | void avcodec_register_all(void); | ||
3093 | |||
3094 | /** | ||
3095 | * Flush buffers, should be called when seeking or when switching to a different stream. | ||
3096 | */ | ||
3097 | void avcodec_flush_buffers(AVCodecContext *avctx); | ||
3098 | |||
3099 | void avcodec_default_free_buffers(AVCodecContext *s); | ||
3100 | |||
3101 | /* misc useful functions */ | ||
3102 | |||
3103 | /** | ||
3104 | * Returns a single letter to describe the given picture type \p pict_type. | ||
3105 | * | ||
3106 | * @param[in] pict_type the picture type | ||
3107 | * @return A single character representing the picture type. | ||
3108 | */ | ||
3109 | char av_get_pict_type_char(int pict_type); | ||
3110 | |||
3111 | /** | ||
3112 | * Returns codec bits per sample. | ||
3113 | * | ||
3114 | * @param[in] codec_id the codec | ||
3115 | * @return Number of bits per sample or zero if unknown for the given codec. | ||
3116 | */ | ||
3117 | int av_get_bits_per_sample(enum CodecID codec_id); | ||
3118 | |||
3119 | /** | ||
3120 | * Returns sample format bits per sample. | ||
3121 | * | ||
3122 | * @param[in] sample_fmt the sample format | ||
3123 | * @return Number of bits per sample or zero if unknown for the given sample format. | ||
3124 | */ | ||
3125 | int av_get_bits_per_sample_format(enum SampleFormat sample_fmt); | ||
3126 | |||
3127 | /* frame parsing */ | ||
3128 | typedef struct AVCodecParserContext { | ||
3129 | void *priv_data; | ||
3130 | struct AVCodecParser *parser; | ||
3131 | int64_t frame_offset; /* offset of the current frame */ | ||
3132 | int64_t cur_offset; /* current offset | ||
3133 | (incremented by each av_parser_parse()) */ | ||
3134 | int64_t next_frame_offset; /* offset of the next frame */ | ||
3135 | /* video info */ | ||
3136 | int pict_type; /* XXX: Put it back in AVCodecContext. */ | ||
3137 | /** | ||
3138 | * This field is used for proper frame duration computation in lavf. | ||
3139 | * It signals, how much longer the frame duration of the current frame | ||
3140 | * is compared to normal frame duration. | ||
3141 | * | ||
3142 | * frame_duration = (1 + repeat_pict) * time_base | ||
3143 | * | ||
3144 | * It is used by codecs like H.264 to display telecined material. | ||
3145 | */ | ||
3146 | int repeat_pict; /* XXX: Put it back in AVCodecContext. */ | ||
3147 | int64_t pts; /* pts of the current frame */ | ||
3148 | int64_t dts; /* dts of the current frame */ | ||
3149 | |||
3150 | /* private data */ | ||
3151 | int64_t last_pts; | ||
3152 | int64_t last_dts; | ||
3153 | int fetch_timestamp; | ||
3154 | |||
3155 | #define AV_PARSER_PTS_NB 4 | ||
3156 | int cur_frame_start_index; | ||
3157 | int64_t cur_frame_offset[AV_PARSER_PTS_NB]; | ||
3158 | int64_t cur_frame_pts[AV_PARSER_PTS_NB]; | ||
3159 | int64_t cur_frame_dts[AV_PARSER_PTS_NB]; | ||
3160 | |||
3161 | int flags; | ||
3162 | #define PARSER_FLAG_COMPLETE_FRAMES 0x0001 | ||
3163 | |||
3164 | int64_t offset; ///< byte offset from starting packet start | ||
3165 | int64_t cur_frame_end[AV_PARSER_PTS_NB]; | ||
3166 | |||
3167 | /*! | ||
3168 | * Set by parser to 1 for key frames and 0 for non-key frames. | ||
3169 | * It is initialized to -1, so if the parser doesn't set this flag, | ||
3170 | * old-style fallback using FF_I_TYPE picture type as key frames | ||
3171 | * will be used. | ||
3172 | */ | ||
3173 | int key_frame; | ||
3174 | |||
3175 | /** | ||
3176 | * Time difference in stream time base units from the pts of this | ||
3177 | * packet to the point at which the output from the decoder has converged | ||
3178 | * independent from the availability of previous frames. That is, the | ||
3179 | * frames are virtually identical no matter if decoding started from | ||
3180 | * the very first frame or from this keyframe. | ||
3181 | * Is AV_NOPTS_VALUE if unknown. | ||
3182 | * This field is not the display duration of the current frame. | ||
3183 | * | ||
3184 | * The purpose of this field is to allow seeking in streams that have no | ||
3185 | * keyframes in the conventional sense. It corresponds to the | ||
3186 | * recovery point SEI in H.264 and match_time_delta in NUT. It is also | ||
3187 | * essential for some types of subtitle streams to ensure that all | ||
3188 | * subtitles are correctly displayed after seeking. | ||
3189 | */ | ||
3190 | int64_t convergence_duration; | ||
3191 | |||
3192 | // Timestamp generation support: | ||
3193 | /** | ||
3194 | * Synchronization point for start of timestamp generation. | ||
3195 | * | ||
3196 | * Set to >0 for sync point, 0 for no sync point and <0 for undefined | ||
3197 | * (default). | ||
3198 | * | ||
3199 | * For example, this corresponds to presence of H.264 buffering period | ||
3200 | * SEI message. | ||
3201 | */ | ||
3202 | int dts_sync_point; | ||
3203 | |||
3204 | /** | ||
3205 | * Offset of the current timestamp against last timestamp sync point in | ||
3206 | * units of AVCodecContext.time_base. | ||
3207 | * | ||
3208 | * Set to INT_MIN when dts_sync_point unused. Otherwise, it must | ||
3209 | * contain a valid timestamp offset. | ||
3210 | * | ||
3211 | * Note that the timestamp of sync point has usually a nonzero | ||
3212 | * dts_ref_dts_delta, which refers to the previous sync point. Offset of | ||
3213 | * the next frame after timestamp sync point will be usually 1. | ||
3214 | * | ||
3215 | * For example, this corresponds to H.264 cpb_removal_delay. | ||
3216 | */ | ||
3217 | int dts_ref_dts_delta; | ||
3218 | |||
3219 | /** | ||
3220 | * Presentation delay of current frame in units of AVCodecContext.time_base. | ||
3221 | * | ||
3222 | * Set to INT_MIN when dts_sync_point unused. Otherwise, it must | ||
3223 | * contain valid non-negative timestamp delta (presentation time of a frame | ||
3224 | * must not lie in the past). | ||
3225 | * | ||
3226 | * This delay represents the difference between decoding and presentation | ||
3227 | * time of the frame. | ||
3228 | * | ||
3229 | * For example, this corresponds to H.264 dpb_output_delay. | ||
3230 | */ | ||
3231 | int pts_dts_delta; | ||
3232 | |||
3233 | /** | ||
3234 | * Position of the packet in file. | ||
3235 | * | ||
3236 | * Analogous to cur_frame_pts/dts | ||
3237 | */ | ||
3238 | int64_t cur_frame_pos[AV_PARSER_PTS_NB]; | ||
3239 | |||
3240 | /** | ||
3241 | * Byte position of currently parsed frame in stream. | ||
3242 | */ | ||
3243 | int64_t pos; | ||
3244 | |||
3245 | /** | ||
3246 | * Previous frame byte position. | ||
3247 | */ | ||
3248 | int64_t last_pos; | ||
3249 | } AVCodecParserContext; | ||
3250 | |||
3251 | typedef struct AVCodecParser { | ||
3252 | int codec_ids[5]; /* several codec IDs are permitted */ | ||
3253 | int priv_data_size; | ||
3254 | int (*parser_init)(AVCodecParserContext *s); | ||
3255 | int (*parser_parse)(AVCodecParserContext *s, | ||
3256 | AVCodecContext *avctx, | ||
3257 | const uint8_t **poutbuf, int *poutbuf_size, | ||
3258 | const uint8_t *buf, int buf_size); | ||
3259 | void (*parser_close)(AVCodecParserContext *s); | ||
3260 | int (*split)(AVCodecContext *avctx, const uint8_t *buf, int buf_size); | ||
3261 | struct AVCodecParser *next; | ||
3262 | } AVCodecParser; | ||
3263 | |||
3264 | AVCodecParser *av_parser_next(AVCodecParser *c); | ||
3265 | |||
3266 | void av_register_codec_parser(AVCodecParser *parser); | ||
3267 | AVCodecParserContext *av_parser_init(int codec_id); | ||
3268 | |||
3269 | attribute_deprecated | ||
3270 | int av_parser_parse(AVCodecParserContext *s, | ||
3271 | AVCodecContext *avctx, | ||
3272 | uint8_t **poutbuf, int *poutbuf_size, | ||
3273 | const uint8_t *buf, int buf_size, | ||
3274 | int64_t pts, int64_t dts); | ||
3275 | |||
3276 | /** | ||
3277 | * Parse a packet. | ||
3278 | * | ||
3279 | * @param s parser context. | ||
3280 | * @param avctx codec context. | ||
3281 | * @param poutbuf set to pointer to parsed buffer or NULL if not yet finished. | ||
3282 | * @param poutbuf_size set to size of parsed buffer or zero if not yet finished. | ||
3283 | * @param buf input buffer. | ||
3284 | * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output). | ||
3285 | * @param pts input presentation timestamp. | ||
3286 | * @param dts input decoding timestamp. | ||
3287 | * @param pos input byte position in stream. | ||
3288 | * @return the number of bytes of the input bitstream used. | ||
3289 | * | ||
3290 | * Example: | ||
3291 | * @code | ||
3292 | * while(in_len){ | ||
3293 | * len = av_parser_parse2(myparser, AVCodecContext, &data, &size, | ||
3294 | * in_data, in_len, | ||
3295 | * pts, dts, pos); | ||
3296 | * in_data += len; | ||
3297 | * in_len -= len; | ||
3298 | * | ||
3299 | * if(size) | ||
3300 | * decode_frame(data, size); | ||
3301 | * } | ||
3302 | * @endcode | ||
3303 | */ | ||
3304 | int av_parser_parse2(AVCodecParserContext *s, | ||
3305 | AVCodecContext *avctx, | ||
3306 | uint8_t **poutbuf, int *poutbuf_size, | ||
3307 | const uint8_t *buf, int buf_size, | ||
3308 | int64_t pts, int64_t dts, | ||
3309 | int64_t pos); | ||
3310 | |||
3311 | int av_parser_change(AVCodecParserContext *s, | ||
3312 | AVCodecContext *avctx, | ||
3313 | uint8_t **poutbuf, int *poutbuf_size, | ||
3314 | const uint8_t *buf, int buf_size, int keyframe); | ||
3315 | void av_parser_close(AVCodecParserContext *s); | ||
3316 | |||
3317 | |||
3318 | typedef struct AVBitStreamFilterContext { | ||
3319 | void *priv_data; | ||
3320 | struct AVBitStreamFilter *filter; | ||
3321 | AVCodecParserContext *parser; | ||
3322 | struct AVBitStreamFilterContext *next; | ||
3323 | } AVBitStreamFilterContext; | ||
3324 | |||
3325 | |||
3326 | typedef struct AVBitStreamFilter { | ||
3327 | const char *name; | ||
3328 | int priv_data_size; | ||
3329 | int (*filter)(AVBitStreamFilterContext *bsfc, | ||
3330 | AVCodecContext *avctx, const char *args, | ||
3331 | uint8_t **poutbuf, int *poutbuf_size, | ||
3332 | const uint8_t *buf, int buf_size, int keyframe); | ||
3333 | void (*close)(AVBitStreamFilterContext *bsfc); | ||
3334 | struct AVBitStreamFilter *next; | ||
3335 | } AVBitStreamFilter; | ||
3336 | |||
3337 | void av_register_bitstream_filter(AVBitStreamFilter *bsf); | ||
3338 | AVBitStreamFilterContext *av_bitstream_filter_init(const char *name); | ||
3339 | int av_bitstream_filter_filter(AVBitStreamFilterContext *bsfc, | ||
3340 | AVCodecContext *avctx, const char *args, | ||
3341 | uint8_t **poutbuf, int *poutbuf_size, | ||
3342 | const uint8_t *buf, int buf_size, int keyframe); | ||
3343 | void av_bitstream_filter_close(AVBitStreamFilterContext *bsf); | ||
3344 | |||
3345 | AVBitStreamFilter *av_bitstream_filter_next(AVBitStreamFilter *f); | ||
3346 | |||
3347 | /* memory */ | ||
3348 | |||
3349 | /** | ||
3350 | * Reallocates the given block if it is not large enough, otherwise it | ||
3351 | * does nothing. | ||
3352 | * | ||
3353 | * @see av_realloc | ||
3354 | */ | ||
3355 | void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size); | ||
3356 | |||
3357 | /** | ||
3358 | * Copy image 'src' to 'dst'. | ||
3359 | */ | ||
3360 | void av_picture_copy(AVPicture *dst, const AVPicture *src, | ||
3361 | int pix_fmt, int width, int height); | ||
3362 | |||
3363 | /** | ||
3364 | * Crop image top and left side. | ||
3365 | */ | ||
3366 | int av_picture_crop(AVPicture *dst, const AVPicture *src, | ||
3367 | int pix_fmt, int top_band, int left_band); | ||
3368 | |||
3369 | /** | ||
3370 | * Pad image. | ||
3371 | */ | ||
3372 | int av_picture_pad(AVPicture *dst, const AVPicture *src, int height, int width, int pix_fmt, | ||
3373 | int padtop, int padbottom, int padleft, int padright, int *color); | ||
3374 | |||
3375 | unsigned int av_xiphlacing(unsigned char *s, unsigned int v); | ||
3376 | |||
3377 | /** | ||
3378 | * Parses \p str and put in \p width_ptr and \p height_ptr the detected values. | ||
3379 | * | ||
3380 | * @return 0 in case of a successful parsing, a negative value otherwise | ||
3381 | * @param[in] str the string to parse: it has to be a string in the format | ||
3382 | * <width>x<height> or a valid video frame size abbreviation. | ||
3383 | * @param[in,out] width_ptr pointer to the variable which will contain the detected | ||
3384 | * frame width value | ||
3385 | * @param[in,out] height_ptr pointer to the variable which will contain the detected | ||
3386 | * frame height value | ||
3387 | */ | ||
3388 | int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str); | ||
3389 | |||
3390 | /** | ||
3391 | * Parses \p str and put in \p frame_rate the detected values. | ||
3392 | * | ||
3393 | * @return 0 in case of a successful parsing, a negative value otherwise | ||
3394 | * @param[in] str the string to parse: it has to be a string in the format | ||
3395 | * <frame_rate_num>/<frame_rate_den>, a float number or a valid video rate abbreviation | ||
3396 | * @param[in,out] frame_rate pointer to the AVRational which will contain the detected | ||
3397 | * frame rate | ||
3398 | */ | ||
3399 | int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); | ||
3400 | |||
3401 | /* error handling */ | ||
3402 | #if EINVAL > 0 | ||
3403 | #define AVERROR(e) (-(e)) /**< Returns a negative error code from a POSIX error code, to return from library functions. */ | ||
3404 | #define AVUNERROR(e) (-(e)) /**< Returns a POSIX error code from a library function error return value. */ | ||
3405 | #else | ||
3406 | /* Some platforms have E* and errno already negated. */ | ||
3407 | #define AVERROR(e) (e) | ||
3408 | #define AVUNERROR(e) (e) | ||
3409 | #endif | ||
3410 | #define AVERROR_UNKNOWN AVERROR(EINVAL) /**< unknown error */ | ||
3411 | #define AVERROR_IO AVERROR(EIO) /**< I/O error */ | ||
3412 | #define AVERROR_NUMEXPECTED AVERROR(EDOM) /**< Number syntax expected in filename. */ | ||
3413 | #define AVERROR_INVALIDDATA AVERROR(EINVAL) /**< invalid data found */ | ||
3414 | #define AVERROR_NOMEM AVERROR(ENOMEM) /**< not enough memory */ | ||
3415 | #define AVERROR_NOFMT AVERROR(EILSEQ) /**< unknown format */ | ||
3416 | #define AVERROR_NOTSUPP AVERROR(ENOSYS) /**< Operation not supported. */ | ||
3417 | #define AVERROR_NOENT AVERROR(ENOENT) /**< No such file or directory. */ | ||
3418 | #define AVERROR_EOF AVERROR(EPIPE) /**< End of file. */ | ||
3419 | #define AVERROR_PATCHWELCOME -MKTAG('P','A','W','E') /**< Not yet implemented in FFmpeg. Patches welcome. */ | ||
3420 | |||
3421 | /** | ||
3422 | * Registers the hardware accelerator \p hwaccel. | ||
3423 | */ | ||
3424 | void av_register_hwaccel(AVHWAccel *hwaccel); | ||
3425 | |||
3426 | /** | ||
3427 | * If hwaccel is NULL, returns the first registered hardware accelerator, | ||
3428 | * if hwaccel is non-NULL, returns the next registered hardware accelerator | ||
3429 | * after hwaccel, or NULL if hwaccel is the last one. | ||
3430 | */ | ||
3431 | AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel); | ||
3432 | #endif /* MT : DELETE THIS LINE ONLY. */ | ||
3433 | #endif /* AVCODEC_AVCODEC_H */ | ||
diff --git a/apps/codecs/libatrac/bitstream.c b/apps/codecs/libatrac/bitstream.c new file mode 100644 index 0000000000..1375134b21 --- /dev/null +++ b/apps/codecs/libatrac/bitstream.c | |||
@@ -0,0 +1,276 @@ | |||
1 | /* | ||
2 | * Common bit i/o utils | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> | ||
7 | * | ||
8 | * This file is part of FFmpeg. | ||
9 | * | ||
10 | * FFmpeg is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU Lesser General Public | ||
12 | * License as published by the Free Software Foundation; either | ||
13 | * version 2.1 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * FFmpeg is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * Lesser General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU Lesser General Public | ||
21 | * License along with FFmpeg; if not, write to the Free Software | ||
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | */ | ||
24 | |||
25 | #include "bitstream.h" | ||
26 | |||
27 | #ifdef ROCKBOX | ||
28 | #undef DEBUGF | ||
29 | #define DEBUGF(...) | ||
30 | #endif | ||
31 | |||
32 | const uint8_t ff_log2_run[32]={ | ||
33 | 0, 0, 0, 0, 1, 1, 1, 1, | ||
34 | 2, 2, 2, 2, 3, 3, 3, 3, | ||
35 | 4, 4, 5, 5, 6, 6, 7, 7, | ||
36 | 8, 9,10,11,12,13,14,15 | ||
37 | }; | ||
38 | |||
39 | /** | ||
40 | * Same as av_mallocz_static(), but does a realloc. | ||
41 | * | ||
42 | * @param[in] ptr The block of memory to reallocate. | ||
43 | * @param[in] size The requested size. | ||
44 | * @return Block of memory of requested size. | ||
45 | * @deprecated. Code which uses ff_realloc_static is broken/misdesigned | ||
46 | * and should correctly use static arrays | ||
47 | */ | ||
48 | |||
49 | |||
50 | void ff_put_string(PutBitContext * pbc, const char *s, int put_zero) | ||
51 | { | ||
52 | while(*s){ | ||
53 | put_bits(pbc, 8, *s); | ||
54 | s++; | ||
55 | } | ||
56 | if(put_zero) | ||
57 | put_bits(pbc, 8, 0); | ||
58 | } | ||
59 | |||
60 | /* VLC decoding */ | ||
61 | |||
62 | //#define DEBUG_VLC | ||
63 | |||
64 | #define GET_DATA(v, table, i, wrap, size) \ | ||
65 | {\ | ||
66 | const uint8_t *ptr = (const uint8_t *)table + i * wrap;\ | ||
67 | switch(size) {\ | ||
68 | case 1:\ | ||
69 | v = *(const uint8_t *)ptr;\ | ||
70 | break;\ | ||
71 | case 2:\ | ||
72 | v = *(const uint16_t *)ptr;\ | ||
73 | break;\ | ||
74 | default:\ | ||
75 | v = *(const uint32_t *)ptr;\ | ||
76 | break;\ | ||
77 | }\ | ||
78 | } | ||
79 | |||
80 | |||
81 | static int alloc_table(VLC *vlc, int size, int use_static) | ||
82 | { | ||
83 | int index; | ||
84 | index = vlc->table_size; | ||
85 | vlc->table_size += size; | ||
86 | if (vlc->table_size > vlc->table_allocated) { | ||
87 | if(use_static>1){ | ||
88 | DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n"); | ||
89 | } | ||
90 | |||
91 | if (!vlc->table) | ||
92 | return -1; | ||
93 | } | ||
94 | return index; | ||
95 | } | ||
96 | |||
97 | static int build_table(VLC *vlc, int table_nb_bits, | ||
98 | int nb_codes, | ||
99 | const void *bits, int bits_wrap, int bits_size, | ||
100 | const void *codes, int codes_wrap, int codes_size, | ||
101 | const void *symbols, int symbols_wrap, int symbols_size, | ||
102 | uint32_t code_prefix, int n_prefix, int flags) | ||
103 | { | ||
104 | int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol; | ||
105 | uint32_t code; | ||
106 | VLC_TYPE (*table)[2]; | ||
107 | |||
108 | table_size = 1 << table_nb_bits; | ||
109 | table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); | ||
110 | #ifdef DEBUG_VLC | ||
111 | DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n", | ||
112 | table_index, table_size, code_prefix, n_prefix); | ||
113 | #endif | ||
114 | if (table_index < 0) | ||
115 | return -1; | ||
116 | table = &vlc->table[table_index]; | ||
117 | |||
118 | for(i=0;i<table_size;i++) { | ||
119 | table[i][1] = 0; //bits | ||
120 | table[i][0] = -1; //codes | ||
121 | } | ||
122 | |||
123 | /* first pass: map codes and compute auxillary table sizes */ | ||
124 | for(i=0;i<nb_codes;i++) { | ||
125 | GET_DATA(n, bits, i, bits_wrap, bits_size); | ||
126 | GET_DATA(code, codes, i, codes_wrap, codes_size); | ||
127 | /* we accept tables with holes */ | ||
128 | if (n <= 0) | ||
129 | continue; | ||
130 | if (!symbols) | ||
131 | symbol = i; | ||
132 | else | ||
133 | GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); | ||
134 | #if defined(DEBUG_VLC) && 0 | ||
135 | DEBUGF("i=%d n=%d code=0x%x\n", i, n, code); | ||
136 | #endif | ||
137 | /* if code matches the prefix, it is in the table */ | ||
138 | n -= n_prefix; | ||
139 | if(flags & INIT_VLC_LE) | ||
140 | code_prefix2= code & (n_prefix>=32 ? (int)0xffffffff : (1 << n_prefix)-1); | ||
141 | else | ||
142 | code_prefix2= code >> n; | ||
143 | if (n > 0 && code_prefix2 == (int)code_prefix) { | ||
144 | if (n <= table_nb_bits) { | ||
145 | /* no need to add another table */ | ||
146 | j = (code << (table_nb_bits - n)) & (table_size - 1); | ||
147 | nb = 1 << (table_nb_bits - n); | ||
148 | for(k=0;k<nb;k++) { | ||
149 | if(flags & INIT_VLC_LE) | ||
150 | j = (code >> n_prefix) + (k<<n); | ||
151 | #ifdef DEBUG_VLC | ||
152 | DEBUGF("%4x: code=%d n=%d\n", | ||
153 | j, i, n); | ||
154 | #endif | ||
155 | if (table[j][1] /*bits*/ != 0) { | ||
156 | DEBUGF("incorrect codes\n"); | ||
157 | return -1; | ||
158 | } | ||
159 | table[j][1] = n; //bits | ||
160 | table[j][0] = symbol; | ||
161 | j++; | ||
162 | } | ||
163 | } else { | ||
164 | n -= table_nb_bits; | ||
165 | j = (code >> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); | ||
166 | #ifdef DEBUG_VLC | ||
167 | DEBUGF("%4x: n=%d (subtable)\n", | ||
168 | j, n); | ||
169 | #endif | ||
170 | /* compute table size */ | ||
171 | n1 = -table[j][1]; //bits | ||
172 | if (n > n1) | ||
173 | n1 = n; | ||
174 | table[j][1] = -n1; //bits | ||
175 | } | ||
176 | } | ||
177 | } | ||
178 | |||
179 | /* second pass : fill auxillary tables recursively */ | ||
180 | for(i=0;i<table_size;i++) { | ||
181 | n = table[i][1]; //bits | ||
182 | if (n < 0) { | ||
183 | n = -n; | ||
184 | if (n > table_nb_bits) { | ||
185 | n = table_nb_bits; | ||
186 | table[i][1] = -n; //bits | ||
187 | } | ||
188 | index = build_table(vlc, n, nb_codes, | ||
189 | bits, bits_wrap, bits_size, | ||
190 | codes, codes_wrap, codes_size, | ||
191 | symbols, symbols_wrap, symbols_size, | ||
192 | (flags & INIT_VLC_LE) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i), | ||
193 | n_prefix + table_nb_bits, flags); | ||
194 | if (index < 0) | ||
195 | return -1; | ||
196 | /* note: realloc has been done, so reload tables */ | ||
197 | table = &vlc->table[table_index]; | ||
198 | table[i][0] = index; //code | ||
199 | } | ||
200 | } | ||
201 | return table_index; | ||
202 | } | ||
203 | |||
204 | |||
205 | /* Build VLC decoding tables suitable for use with get_vlc(). | ||
206 | |||
207 | 'nb_bits' set thee decoding table size (2^nb_bits) entries. The | ||
208 | bigger it is, the faster is the decoding. But it should not be too | ||
209 | big to save memory and L1 cache. '9' is a good compromise. | ||
210 | |||
211 | 'nb_codes' : number of vlcs codes | ||
212 | |||
213 | 'bits' : table which gives the size (in bits) of each vlc code. | ||
214 | |||
215 | 'codes' : table which gives the bit pattern of of each vlc code. | ||
216 | |||
217 | 'symbols' : table which gives the values to be returned from get_vlc(). | ||
218 | |||
219 | 'xxx_wrap' : give the number of bytes between each entry of the | ||
220 | 'bits' or 'codes' tables. | ||
221 | |||
222 | 'xxx_size' : gives the number of bytes of each entry of the 'bits' | ||
223 | or 'codes' tables. | ||
224 | |||
225 | 'wrap' and 'size' allows to use any memory configuration and types | ||
226 | (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables. | ||
227 | |||
228 | 'use_static' should be set to 1 for tables, which should be freed | ||
229 | with av_free_static(), 0 if free_vlc() will be used. | ||
230 | */ | ||
231 | int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | ||
232 | const void *bits, int bits_wrap, int bits_size, | ||
233 | const void *codes, int codes_wrap, int codes_size, | ||
234 | const void *symbols, int symbols_wrap, int symbols_size, | ||
235 | int flags) | ||
236 | { | ||
237 | vlc->bits = nb_bits; | ||
238 | if(flags & INIT_VLC_USE_NEW_STATIC){ | ||
239 | if(vlc->table_size && vlc->table_size == vlc->table_allocated){ | ||
240 | return 0; | ||
241 | }else if(vlc->table_size){ | ||
242 | return -1; // fatal error, we are called on a partially initialized table | ||
243 | } | ||
244 | }else if(!(flags & INIT_VLC_USE_STATIC)) { | ||
245 | vlc->table = NULL; | ||
246 | vlc->table_allocated = 0; | ||
247 | vlc->table_size = 0; | ||
248 | } else { | ||
249 | /* Static tables are initially always NULL, return | ||
250 | if vlc->table != NULL to avoid double allocation */ | ||
251 | if(vlc->table) | ||
252 | return 0; | ||
253 | } | ||
254 | |||
255 | #ifdef DEBUG_VLC | ||
256 | DEBUGF("build table nb_codes=%d\n", nb_codes); | ||
257 | #endif | ||
258 | |||
259 | if (build_table(vlc, nb_bits, nb_codes, | ||
260 | bits, bits_wrap, bits_size, | ||
261 | codes, codes_wrap, codes_size, | ||
262 | symbols, symbols_wrap, symbols_size, | ||
263 | 0, 0, flags) < 0) { | ||
264 | //free(&vlc->table); | ||
265 | return -1; | ||
266 | } | ||
267 | /* Changed the following condition to be true if table_size > table_allocated. * | ||
268 | * This would be more sensible for static tables since we want warnings for * | ||
269 | * memory shortages only. */ | ||
270 | #ifdef TEST | ||
271 | if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) | ||
272 | DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated); | ||
273 | #endif | ||
274 | return 0; | ||
275 | } | ||
276 | |||
diff --git a/apps/codecs/libatrac/bitstream.h b/apps/codecs/libatrac/bitstream.h new file mode 100644 index 0000000000..b4c3136be3 --- /dev/null +++ b/apps/codecs/libatrac/bitstream.h | |||
@@ -0,0 +1,963 @@ | |||
1 | /* | ||
2 | * copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #ifndef BITSTREAM_H | ||
22 | #define BITSTREAM_H | ||
23 | |||
24 | #include <inttypes.h> | ||
25 | #include <stdlib.h> | ||
26 | //#include <assert.h> | ||
27 | #include <string.h> | ||
28 | #include <stdio.h> | ||
29 | #include "bswap.h" | ||
30 | |||
31 | /* The following 2 defines are taken from libavutil/intreadwrite.h */ | ||
32 | #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ | ||
33 | (((const uint8_t*)(x))[1] << 16) | \ | ||
34 | (((const uint8_t*)(x))[2] << 8) | \ | ||
35 | ((const uint8_t*)(x))[3]) | ||
36 | #define AV_WB32(p, d) do { \ | ||
37 | ((uint8_t*)(p))[3] = (d); \ | ||
38 | ((uint8_t*)(p))[2] = (d)>>8; \ | ||
39 | ((uint8_t*)(p))[1] = (d)>>16; \ | ||
40 | ((uint8_t*)(p))[0] = (d)>>24; } while(0) | ||
41 | |||
42 | #if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) | ||
43 | # define ALT_BITSTREAM_READER | ||
44 | #endif | ||
45 | |||
46 | //#define ALT_BITSTREAM_WRITER | ||
47 | //#define ALIGNED_BITSTREAM_WRITER | ||
48 | #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) | ||
49 | # if defined(ARCH_ARM) | ||
50 | # define A32_BITSTREAM_READER | ||
51 | # else | ||
52 | # define ALT_BITSTREAM_READER | ||
53 | //#define LIBMPEG2_BITSTREAM_READER | ||
54 | //#define A32_BITSTREAM_READER | ||
55 | # endif | ||
56 | #endif | ||
57 | |||
58 | extern const uint8_t ff_reverse[256]; | ||
59 | |||
60 | #if defined(ARCH_X86) | ||
61 | // avoid +32 for shift optimization (gcc should do that ...) | ||
62 | static inline int32_t NEG_SSR32( int32_t a, int8_t s){ | ||
63 | __asm__ ("sarl %1, %0\n\t" | ||
64 | : "+r" (a) | ||
65 | : "ic" ((uint8_t)(-s)) | ||
66 | ); | ||
67 | return a; | ||
68 | } | ||
69 | static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ | ||
70 | __asm__ ("shrl %1, %0\n\t" | ||
71 | : "+r" (a) | ||
72 | : "ic" ((uint8_t)(-s)) | ||
73 | ); | ||
74 | return a; | ||
75 | } | ||
76 | #else | ||
77 | # define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) | ||
78 | # define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) | ||
79 | #endif | ||
80 | |||
81 | /* bit output */ | ||
82 | |||
83 | /* buf and buf_end must be present and used by every alternative writer. */ | ||
84 | typedef struct PutBitContext { | ||
85 | #ifdef ALT_BITSTREAM_WRITER | ||
86 | uint8_t *buf, *buf_end; | ||
87 | int index; | ||
88 | #else | ||
89 | uint32_t bit_buf; | ||
90 | int bit_left; | ||
91 | uint8_t *buf, *buf_ptr, *buf_end; | ||
92 | #endif | ||
93 | int size_in_bits; | ||
94 | } PutBitContext; | ||
95 | |||
96 | static inline void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size) | ||
97 | { | ||
98 | if(buffer_size < 0) { | ||
99 | buffer_size = 0; | ||
100 | buffer = NULL; | ||
101 | } | ||
102 | |||
103 | s->size_in_bits= 8*buffer_size; | ||
104 | s->buf = buffer; | ||
105 | s->buf_end = s->buf + buffer_size; | ||
106 | #ifdef ALT_BITSTREAM_WRITER | ||
107 | s->index=0; | ||
108 | ((uint32_t*)(s->buf))[0]=0; | ||
109 | // memset(buffer, 0, buffer_size); | ||
110 | #else | ||
111 | s->buf_ptr = s->buf; | ||
112 | s->bit_left=32; | ||
113 | s->bit_buf=0; | ||
114 | #endif | ||
115 | } | ||
116 | |||
117 | /* return the number of bits output */ | ||
118 | static inline int put_bits_count(PutBitContext *s) | ||
119 | { | ||
120 | #ifdef ALT_BITSTREAM_WRITER | ||
121 | return s->index; | ||
122 | #else | ||
123 | return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; | ||
124 | #endif | ||
125 | } | ||
126 | |||
127 | /* pad the end of the output stream with zeros */ | ||
128 | static inline void flush_put_bits(PutBitContext *s) | ||
129 | { | ||
130 | #ifdef ALT_BITSTREAM_WRITER | ||
131 | align_put_bits(s); | ||
132 | #else | ||
133 | #ifndef BITSTREAM_WRITER_LE | ||
134 | s->bit_buf<<= s->bit_left; | ||
135 | #endif | ||
136 | while (s->bit_left < 32) { | ||
137 | /* XXX: should test end of buffer */ | ||
138 | #ifdef BITSTREAM_WRITER_LE | ||
139 | *s->buf_ptr++=s->bit_buf; | ||
140 | s->bit_buf>>=8; | ||
141 | #else | ||
142 | *s->buf_ptr++=s->bit_buf >> 24; | ||
143 | s->bit_buf<<=8; | ||
144 | #endif | ||
145 | s->bit_left+=8; | ||
146 | } | ||
147 | s->bit_left=32; | ||
148 | s->bit_buf=0; | ||
149 | #endif | ||
150 | } | ||
151 | |||
152 | void align_put_bits(PutBitContext *s); | ||
153 | void ff_put_string(PutBitContext * pbc, const char *s, int put_zero); | ||
154 | void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); | ||
155 | |||
156 | /* bit input */ | ||
157 | /* buffer, buffer_end and size_in_bits must be present and used by every reader */ | ||
158 | typedef struct GetBitContext { | ||
159 | const uint8_t *buffer, *buffer_end; | ||
160 | #ifdef ALT_BITSTREAM_READER | ||
161 | int index; | ||
162 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
163 | uint8_t *buffer_ptr; | ||
164 | uint32_t cache; | ||
165 | int bit_count; | ||
166 | #elif defined A32_BITSTREAM_READER | ||
167 | uint32_t *buffer_ptr; | ||
168 | uint32_t cache0; | ||
169 | uint32_t cache1; | ||
170 | int bit_count; | ||
171 | #endif | ||
172 | int size_in_bits; | ||
173 | } GetBitContext; | ||
174 | |||
175 | #define VLC_TYPE int16_t | ||
176 | |||
177 | typedef struct VLC { | ||
178 | int bits; | ||
179 | VLC_TYPE (*table)[2]; ///< code, bits | ||
180 | int table_size, table_allocated; | ||
181 | } VLC; | ||
182 | |||
183 | typedef struct RL_VLC_ELEM { | ||
184 | int16_t level; | ||
185 | int8_t len; | ||
186 | uint8_t run; | ||
187 | } RL_VLC_ELEM; | ||
188 | |||
189 | #ifndef ALT_BITSTREAM_WRITER | ||
190 | static inline void put_bits(PutBitContext *s, int n, unsigned int value) | ||
191 | { | ||
192 | unsigned int bit_buf; | ||
193 | int bit_left; | ||
194 | |||
195 | // printf("put_bits=%d %x\n", n, value); | ||
196 | //assert(n == 32 || value < (1U << n)); | ||
197 | |||
198 | bit_buf = s->bit_buf; | ||
199 | bit_left = s->bit_left; | ||
200 | |||
201 | // printf("n=%d value=%x cnt=%d buf=%x\n", n, value, bit_cnt, bit_buf); | ||
202 | /* XXX: optimize */ | ||
203 | #ifdef BITSTREAM_WRITER_LE | ||
204 | bit_buf |= value << (32 - bit_left); | ||
205 | if (n >= bit_left) { | ||
206 | #if !HAVE_FAST_UNALIGNED | ||
207 | if (3 & (intptr_t) s->buf_ptr) { | ||
208 | AV_WL32(s->buf_ptr, bit_buf); | ||
209 | } else | ||
210 | #endif | ||
211 | *(uint32_t *)s->buf_ptr = le2me_32(bit_buf); | ||
212 | s->buf_ptr+=4; | ||
213 | bit_buf = (bit_left==32)?0:value >> bit_left; | ||
214 | bit_left+=32; | ||
215 | } | ||
216 | bit_left-=n; | ||
217 | #else | ||
218 | if (n < bit_left) { | ||
219 | bit_buf = (bit_buf<<n) | value; | ||
220 | bit_left-=n; | ||
221 | } else { | ||
222 | bit_buf<<=bit_left; | ||
223 | bit_buf |= value >> (n - bit_left); | ||
224 | #if !defined(HAVE_FAST_UNALIGNED) | ||
225 | if (3 & (intptr_t) s->buf_ptr) { | ||
226 | AV_WB32(s->buf_ptr, bit_buf); | ||
227 | } else | ||
228 | #endif | ||
229 | *(uint32_t *)s->buf_ptr = be2me_32(bit_buf); | ||
230 | //printf("bitbuf = %08x\n", bit_buf); | ||
231 | s->buf_ptr+=4; | ||
232 | bit_left+=32 - n; | ||
233 | bit_buf = value; | ||
234 | } | ||
235 | #endif | ||
236 | |||
237 | s->bit_buf = bit_buf; | ||
238 | s->bit_left = bit_left; | ||
239 | } | ||
240 | #endif | ||
241 | |||
242 | |||
243 | #ifdef ALT_BITSTREAM_WRITER | ||
244 | static inline void put_bits(PutBitContext *s, int n, unsigned int value) | ||
245 | { | ||
246 | # ifdef ALIGNED_BITSTREAM_WRITER | ||
247 | # if ARCH_X86 | ||
248 | __asm__ volatile( | ||
249 | "movl %0, %%ecx \n\t" | ||
250 | "xorl %%eax, %%eax \n\t" | ||
251 | "shrdl %%cl, %1, %%eax \n\t" | ||
252 | "shrl %%cl, %1 \n\t" | ||
253 | "movl %0, %%ecx \n\t" | ||
254 | "shrl $3, %%ecx \n\t" | ||
255 | "andl $0xFFFFFFFC, %%ecx \n\t" | ||
256 | "bswapl %1 \n\t" | ||
257 | "orl %1, (%2, %%ecx) \n\t" | ||
258 | "bswapl %%eax \n\t" | ||
259 | "addl %3, %0 \n\t" | ||
260 | "movl %%eax, 4(%2, %%ecx) \n\t" | ||
261 | : "=&r" (s->index), "=&r" (value) | ||
262 | : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) | ||
263 | : "%eax", "%ecx" | ||
264 | ); | ||
265 | # else | ||
266 | int index= s->index; | ||
267 | uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); | ||
268 | |||
269 | value<<= 32-n; | ||
270 | |||
271 | ptr[0] |= be2me_32(value>>(index&31)); | ||
272 | ptr[1] = be2me_32(value<<(32-(index&31))); | ||
273 | //if(n>24) printf("%d %d\n", n, value); | ||
274 | index+= n; | ||
275 | s->index= index; | ||
276 | # endif | ||
277 | # else //ALIGNED_BITSTREAM_WRITER | ||
278 | # if ARCH_X86 | ||
279 | __asm__ volatile( | ||
280 | "movl $7, %%ecx \n\t" | ||
281 | "andl %0, %%ecx \n\t" | ||
282 | "addl %3, %%ecx \n\t" | ||
283 | "negl %%ecx \n\t" | ||
284 | "shll %%cl, %1 \n\t" | ||
285 | "bswapl %1 \n\t" | ||
286 | "movl %0, %%ecx \n\t" | ||
287 | "shrl $3, %%ecx \n\t" | ||
288 | "orl %1, (%%ecx, %2) \n\t" | ||
289 | "addl %3, %0 \n\t" | ||
290 | "movl $0, 4(%%ecx, %2) \n\t" | ||
291 | : "=&r" (s->index), "=&r" (value) | ||
292 | : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) | ||
293 | : "%ecx" | ||
294 | ); | ||
295 | # else | ||
296 | int index= s->index; | ||
297 | uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); | ||
298 | |||
299 | ptr[0] |= be2me_32(value<<(32-n-(index&7) )); | ||
300 | ptr[1] = 0; | ||
301 | //if(n>24) printf("%d %d\n", n, value); | ||
302 | index+= n; | ||
303 | s->index= index; | ||
304 | # endif | ||
305 | # endif //!ALIGNED_BITSTREAM_WRITER | ||
306 | } | ||
307 | #endif | ||
308 | |||
309 | static inline void put_sbits(PutBitContext *pb, int bits, int32_t val) | ||
310 | { | ||
311 | //assert(bits >= 0 && bits <= 31); | ||
312 | |||
313 | put_bits(pb, bits, val & ((1<<bits)-1)); | ||
314 | } | ||
315 | |||
316 | |||
317 | static inline uint8_t* pbBufPtr(PutBitContext *s) | ||
318 | { | ||
319 | #ifdef ALT_BITSTREAM_WRITER | ||
320 | return s->buf + (s->index>>3); | ||
321 | #else | ||
322 | return s->buf_ptr; | ||
323 | #endif | ||
324 | } | ||
325 | |||
326 | /** | ||
327 | * | ||
328 | * PutBitContext must be flushed & aligned to a byte boundary before calling this. | ||
329 | */ | ||
330 | static inline void skip_put_bytes(PutBitContext *s, int n){ | ||
331 | //assert((put_bits_count(s)&7)==0); | ||
332 | #ifdef ALT_BITSTREAM_WRITER | ||
333 | FIXME may need some cleaning of the buffer | ||
334 | s->index += n<<3; | ||
335 | #else | ||
336 | //assert(s->bit_left==32); | ||
337 | s->buf_ptr += n; | ||
338 | #endif | ||
339 | } | ||
340 | |||
341 | /** | ||
342 | * Skips the given number of bits. | ||
343 | * Must only be used if the actual values in the bitstream do not matter. | ||
344 | */ | ||
345 | static inline void skip_put_bits(PutBitContext *s, int n){ | ||
346 | #ifdef ALT_BITSTREAM_WRITER | ||
347 | s->index += n; | ||
348 | #else | ||
349 | s->bit_left -= n; | ||
350 | s->buf_ptr-= s->bit_left>>5; | ||
351 | s->bit_left &= 31; | ||
352 | #endif | ||
353 | } | ||
354 | |||
355 | /** | ||
356 | * Changes the end of the buffer. | ||
357 | */ | ||
358 | static inline void set_put_bits_buffer_size(PutBitContext *s, int size){ | ||
359 | s->buf_end= s->buf + size; | ||
360 | } | ||
361 | |||
362 | /* Bitstream reader API docs: | ||
363 | name | ||
364 | arbitrary name which is used as prefix for the internal variables | ||
365 | |||
366 | gb | ||
367 | getbitcontext | ||
368 | |||
369 | OPEN_READER(name, gb) | ||
370 | loads gb into local variables | ||
371 | |||
372 | CLOSE_READER(name, gb) | ||
373 | stores local vars in gb | ||
374 | |||
375 | UPDATE_CACHE(name, gb) | ||
376 | refills the internal cache from the bitstream | ||
377 | after this call at least MIN_CACHE_BITS will be available, | ||
378 | |||
379 | GET_CACHE(name, gb) | ||
380 | will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) | ||
381 | |||
382 | SHOW_UBITS(name, gb, num) | ||
383 | will return the next num bits | ||
384 | |||
385 | SHOW_SBITS(name, gb, num) | ||
386 | will return the next num bits and do sign extension | ||
387 | |||
388 | SKIP_BITS(name, gb, num) | ||
389 | will skip over the next num bits | ||
390 | note, this is equivalent to SKIP_CACHE; SKIP_COUNTER | ||
391 | |||
392 | SKIP_CACHE(name, gb, num) | ||
393 | will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) | ||
394 | |||
395 | SKIP_COUNTER(name, gb, num) | ||
396 | will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) | ||
397 | |||
398 | LAST_SKIP_CACHE(name, gb, num) | ||
399 | will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing | ||
400 | |||
401 | LAST_SKIP_BITS(name, gb, num) | ||
402 | is equivalent to SKIP_LAST_CACHE; SKIP_COUNTER | ||
403 | |||
404 | for examples see get_bits, show_bits, skip_bits, get_vlc | ||
405 | */ | ||
406 | |||
407 | #ifdef ALT_BITSTREAM_READER | ||
408 | # define MIN_CACHE_BITS 25 | ||
409 | |||
410 | # define OPEN_READER(name, gb)\ | ||
411 | int name##_index= (gb)->index;\ | ||
412 | int name##_cache= 0;\ | ||
413 | |||
414 | # define CLOSE_READER(name, gb)\ | ||
415 | (gb)->index= name##_index;\ | ||
416 | |||
417 | # ifdef ALT_BITSTREAM_READER_LE | ||
418 | # define UPDATE_CACHE(name, gb)\ | ||
419 | name##_cache= AV_RL32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) >> (name##_index&0x07);\ | ||
420 | |||
421 | # define SKIP_CACHE(name, gb, num)\ | ||
422 | name##_cache >>= (num); | ||
423 | # else | ||
424 | # define UPDATE_CACHE(name, gb)\ | ||
425 | name##_cache= AV_RB32( ((const uint8_t *)(gb)->buffer)+(name##_index>>3) ) << (name##_index&0x07);\ | ||
426 | |||
427 | # define SKIP_CACHE(name, gb, num)\ | ||
428 | name##_cache <<= (num); | ||
429 | # endif | ||
430 | |||
431 | // FIXME name? | ||
432 | # define SKIP_COUNTER(name, gb, num)\ | ||
433 | name##_index += (num);\ | ||
434 | |||
435 | # define SKIP_BITS(name, gb, num)\ | ||
436 | {\ | ||
437 | SKIP_CACHE(name, gb, num)\ | ||
438 | SKIP_COUNTER(name, gb, num)\ | ||
439 | }\ | ||
440 | |||
441 | # define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) | ||
442 | # define LAST_SKIP_CACHE(name, gb, num) ; | ||
443 | |||
444 | # ifdef ALT_BITSTREAM_READER_LE | ||
445 | # define SHOW_UBITS(name, gb, num)\ | ||
446 | ((name##_cache) & (NEG_USR32(0xffffffff,num))) | ||
447 | |||
448 | # define SHOW_SBITS(name, gb, num)\ | ||
449 | NEG_SSR32((name##_cache)<<(32-(num)), num) | ||
450 | # else | ||
451 | # define SHOW_UBITS(name, gb, num)\ | ||
452 | NEG_USR32(name##_cache, num) | ||
453 | |||
454 | # define SHOW_SBITS(name, gb, num)\ | ||
455 | NEG_SSR32(name##_cache, num) | ||
456 | # endif | ||
457 | |||
458 | # define GET_CACHE(name, gb)\ | ||
459 | ((uint32_t)name##_cache) | ||
460 | |||
461 | static inline int get_bits_count(GetBitContext *s){ | ||
462 | return s->index; | ||
463 | } | ||
464 | |||
465 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
466 | s->index += n; | ||
467 | } | ||
468 | |||
469 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
470 | //libmpeg2 like reader | ||
471 | |||
472 | # define MIN_CACHE_BITS 17 | ||
473 | |||
474 | # define OPEN_READER(name, gb)\ | ||
475 | int name##_bit_count=(gb)->bit_count;\ | ||
476 | int name##_cache= (gb)->cache;\ | ||
477 | uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\ | ||
478 | |||
479 | # define CLOSE_READER(name, gb)\ | ||
480 | (gb)->bit_count= name##_bit_count;\ | ||
481 | (gb)->cache= name##_cache;\ | ||
482 | (gb)->buffer_ptr= name##_buffer_ptr;\ | ||
483 | |||
484 | # define UPDATE_CACHE(name, gb)\ | ||
485 | if(name##_bit_count >= 0){\ | ||
486 | name##_cache+= AV_RB16(name##_buffer_ptr) << name##_bit_count; \ | ||
487 | name##_buffer_ptr+=2;\ | ||
488 | name##_bit_count-= 16;\ | ||
489 | }\ | ||
490 | |||
491 | # define SKIP_CACHE(name, gb, num)\ | ||
492 | name##_cache <<= (num);\ | ||
493 | |||
494 | # define SKIP_COUNTER(name, gb, num)\ | ||
495 | name##_bit_count += (num);\ | ||
496 | |||
497 | # define SKIP_BITS(name, gb, num)\ | ||
498 | {\ | ||
499 | SKIP_CACHE(name, gb, num)\ | ||
500 | SKIP_COUNTER(name, gb, num)\ | ||
501 | }\ | ||
502 | |||
503 | # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) | ||
504 | # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) | ||
505 | |||
506 | # define SHOW_UBITS(name, gb, num)\ | ||
507 | NEG_USR32(name##_cache, num) | ||
508 | |||
509 | # define SHOW_SBITS(name, gb, num)\ | ||
510 | NEG_SSR32(name##_cache, num) | ||
511 | |||
512 | # define GET_CACHE(name, gb)\ | ||
513 | ((uint32_t)name##_cache) | ||
514 | |||
515 | static inline int get_bits_count(GetBitContext *s){ | ||
516 | return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; | ||
517 | } | ||
518 | |||
519 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
520 | OPEN_READER(re, s) | ||
521 | re_bit_count += n; | ||
522 | re_buffer_ptr += 2*(re_bit_count>>4); | ||
523 | re_bit_count &= 15; | ||
524 | re_cache = ((re_buffer_ptr[-2]<<8) + re_buffer_ptr[-1]) << (16+re_bit_count); | ||
525 | UPDATE_CACHE(re, s) | ||
526 | CLOSE_READER(re, s) | ||
527 | } | ||
528 | |||
529 | #elif defined A32_BITSTREAM_READER | ||
530 | |||
531 | # define MIN_CACHE_BITS 32 | ||
532 | |||
533 | # define OPEN_READER(name, gb)\ | ||
534 | int name##_bit_count=(gb)->bit_count;\ | ||
535 | uint32_t name##_cache0= (gb)->cache0;\ | ||
536 | uint32_t name##_cache1= (gb)->cache1;\ | ||
537 | uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\ | ||
538 | |||
539 | # define CLOSE_READER(name, gb)\ | ||
540 | (gb)->bit_count= name##_bit_count;\ | ||
541 | (gb)->cache0= name##_cache0;\ | ||
542 | (gb)->cache1= name##_cache1;\ | ||
543 | (gb)->buffer_ptr= name##_buffer_ptr;\ | ||
544 | |||
545 | # define UPDATE_CACHE(name, gb)\ | ||
546 | if(name##_bit_count > 0){\ | ||
547 | const uint32_t next= be2me_32( *name##_buffer_ptr );\ | ||
548 | name##_cache0 |= NEG_USR32(next,name##_bit_count);\ | ||
549 | name##_cache1 |= next<<name##_bit_count;\ | ||
550 | name##_buffer_ptr++;\ | ||
551 | name##_bit_count-= 32;\ | ||
552 | }\ | ||
553 | |||
554 | #if ARCH_X86 | ||
555 | # define SKIP_CACHE(name, gb, num)\ | ||
556 | __asm__(\ | ||
557 | "shldl %2, %1, %0 \n\t"\ | ||
558 | "shll %2, %1 \n\t"\ | ||
559 | : "+r" (name##_cache0), "+r" (name##_cache1)\ | ||
560 | : "Ic" ((uint8_t)(num))\ | ||
561 | ); | ||
562 | #else | ||
563 | # define SKIP_CACHE(name, gb, num)\ | ||
564 | name##_cache0 <<= (num);\ | ||
565 | name##_cache0 |= NEG_USR32(name##_cache1,num);\ | ||
566 | name##_cache1 <<= (num); | ||
567 | #endif | ||
568 | |||
569 | # define SKIP_COUNTER(name, gb, num)\ | ||
570 | name##_bit_count += (num);\ | ||
571 | |||
572 | # define SKIP_BITS(name, gb, num)\ | ||
573 | {\ | ||
574 | SKIP_CACHE(name, gb, num)\ | ||
575 | SKIP_COUNTER(name, gb, num)\ | ||
576 | }\ | ||
577 | |||
578 | # define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) | ||
579 | # define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) | ||
580 | |||
581 | # define SHOW_UBITS(name, gb, num)\ | ||
582 | NEG_USR32(name##_cache0, num) | ||
583 | |||
584 | # define SHOW_SBITS(name, gb, num)\ | ||
585 | NEG_SSR32(name##_cache0, num) | ||
586 | |||
587 | # define GET_CACHE(name, gb)\ | ||
588 | (name##_cache0) | ||
589 | |||
590 | static inline int get_bits_count(GetBitContext *s){ | ||
591 | return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count; | ||
592 | } | ||
593 | |||
594 | static inline void skip_bits_long(GetBitContext *s, int n){ | ||
595 | OPEN_READER(re, s) | ||
596 | re_bit_count += n; | ||
597 | re_buffer_ptr += re_bit_count>>5; | ||
598 | re_bit_count &= 31; | ||
599 | re_cache0 = be2me_32( re_buffer_ptr[-1] ) << re_bit_count; | ||
600 | re_cache1 = 0; | ||
601 | UPDATE_CACHE(re, s) | ||
602 | CLOSE_READER(re, s) | ||
603 | } | ||
604 | |||
605 | #endif | ||
606 | |||
607 | /** | ||
608 | * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). | ||
609 | * if MSB not set it is negative | ||
610 | * @param n length in bits | ||
611 | * @author BERO | ||
612 | */ | ||
613 | static inline int get_xbits(GetBitContext *s, int n){ | ||
614 | register int sign; | ||
615 | register int32_t cache; | ||
616 | OPEN_READER(re, s) | ||
617 | UPDATE_CACHE(re, s) | ||
618 | cache = GET_CACHE(re,s); | ||
619 | sign=(~cache)>>31; | ||
620 | LAST_SKIP_BITS(re, s, n) | ||
621 | CLOSE_READER(re, s) | ||
622 | return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; | ||
623 | } | ||
624 | |||
625 | static inline int get_sbits(GetBitContext *s, int n){ | ||
626 | register int tmp; | ||
627 | OPEN_READER(re, s) | ||
628 | UPDATE_CACHE(re, s) | ||
629 | tmp= SHOW_SBITS(re, s, n); | ||
630 | LAST_SKIP_BITS(re, s, n) | ||
631 | CLOSE_READER(re, s) | ||
632 | return tmp; | ||
633 | } | ||
634 | |||
635 | /** | ||
636 | * reads 1-17 bits. | ||
637 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
638 | */ | ||
639 | static inline unsigned int get_bits(GetBitContext *s, int n){ | ||
640 | register int tmp; | ||
641 | OPEN_READER(re, s) | ||
642 | UPDATE_CACHE(re, s) | ||
643 | tmp= SHOW_UBITS(re, s, n); | ||
644 | LAST_SKIP_BITS(re, s, n) | ||
645 | CLOSE_READER(re, s) | ||
646 | return tmp; | ||
647 | } | ||
648 | |||
649 | /** | ||
650 | * shows 1-17 bits. | ||
651 | * Note, the alt bitstream reader can read up to 25 bits, but the libmpeg2 reader can't | ||
652 | */ | ||
653 | static inline unsigned int show_bits(GetBitContext *s, int n){ | ||
654 | register int tmp; | ||
655 | OPEN_READER(re, s) | ||
656 | UPDATE_CACHE(re, s) | ||
657 | tmp= SHOW_UBITS(re, s, n); | ||
658 | // CLOSE_READER(re, s) | ||
659 | return tmp; | ||
660 | } | ||
661 | |||
662 | static inline void skip_bits(GetBitContext *s, int n){ | ||
663 | //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) | ||
664 | OPEN_READER(re, s) | ||
665 | UPDATE_CACHE(re, s) | ||
666 | LAST_SKIP_BITS(re, s, n) | ||
667 | CLOSE_READER(re, s) | ||
668 | } | ||
669 | |||
670 | static inline unsigned int get_bits1(GetBitContext *s){ | ||
671 | #ifdef ALT_BITSTREAM_READER | ||
672 | int index= s->index; | ||
673 | uint8_t result= s->buffer[ index>>3 ]; | ||
674 | #ifdef ALT_BITSTREAM_READER_LE | ||
675 | result>>= (index&0x07); | ||
676 | result&= 1; | ||
677 | #else | ||
678 | result<<= (index&0x07); | ||
679 | result>>= 8 - 1; | ||
680 | #endif | ||
681 | index++; | ||
682 | s->index= index; | ||
683 | |||
684 | return result; | ||
685 | #else | ||
686 | return get_bits(s, 1); | ||
687 | #endif | ||
688 | } | ||
689 | |||
690 | static inline unsigned int show_bits1(GetBitContext *s){ | ||
691 | return show_bits(s, 1); | ||
692 | } | ||
693 | |||
694 | static inline void skip_bits1(GetBitContext *s){ | ||
695 | skip_bits(s, 1); | ||
696 | } | ||
697 | |||
698 | /** | ||
699 | * reads 0-32 bits. | ||
700 | */ | ||
701 | static inline unsigned int get_bits_long(GetBitContext *s, int n){ | ||
702 | if(n<=17) return get_bits(s, n); | ||
703 | else{ | ||
704 | #ifdef ALT_BITSTREAM_READER_LE | ||
705 | int ret= get_bits(s, 16); | ||
706 | return ret | (get_bits(s, n-16) << 16); | ||
707 | #else | ||
708 | int ret= get_bits(s, 16) << (n-16); | ||
709 | return ret | get_bits(s, n-16); | ||
710 | #endif | ||
711 | } | ||
712 | } | ||
713 | |||
714 | #if 0 | ||
715 | /** | ||
716 | * reads 0-32 bits as a signed integer. | ||
717 | */ | ||
718 | static inline int get_sbits_long(GetBitContext *s, int n) { | ||
719 | return sign_extend(get_bits_long(s, n), n); | ||
720 | } | ||
721 | #endif | ||
722 | |||
723 | /** | ||
724 | * shows 0-32 bits. | ||
725 | */ | ||
726 | static inline unsigned int show_bits_long(GetBitContext *s, int n){ | ||
727 | if(n<=17) return show_bits(s, n); | ||
728 | else{ | ||
729 | GetBitContext gb= *s; | ||
730 | return get_bits_long(&gb, n); | ||
731 | } | ||
732 | } | ||
733 | |||
734 | #if 0 | ||
735 | static inline int check_marker(GetBitContext *s, const char *msg) | ||
736 | { | ||
737 | int bit= get_bits1(s); | ||
738 | if(!bit) | ||
739 | printf("Marker bit missing %s\n", msg); | ||
740 | |||
741 | return bit; | ||
742 | } | ||
743 | #endif | ||
744 | |||
745 | /** | ||
746 | * init GetBitContext. | ||
747 | * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits | ||
748 | * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | ||
749 | * @param bit_size the size of the buffer in bits | ||
750 | */ | ||
751 | static inline void init_get_bits(GetBitContext *s, | ||
752 | const uint8_t *buffer, int bit_size) | ||
753 | { | ||
754 | int buffer_size= (bit_size+7)>>3; | ||
755 | if(buffer_size < 0 || bit_size < 0) { | ||
756 | buffer_size = bit_size = 0; | ||
757 | buffer = NULL; | ||
758 | } | ||
759 | |||
760 | s->buffer= buffer; | ||
761 | s->size_in_bits= bit_size; | ||
762 | s->buffer_end= buffer + buffer_size; | ||
763 | #ifdef ALT_BITSTREAM_READER | ||
764 | s->index=0; | ||
765 | #elif defined LIBMPEG2_BITSTREAM_READER | ||
766 | s->buffer_ptr = (uint8_t*)((intptr_t)buffer&(~1)); | ||
767 | s->bit_count = 16 + 8*((intptr_t)buffer&1); | ||
768 | skip_bits_long(s, 0); | ||
769 | #elif defined A32_BITSTREAM_READER | ||
770 | s->buffer_ptr = (uint32_t*)((intptr_t)buffer&(~3)); | ||
771 | s->bit_count = 32 + 8*((intptr_t)buffer&3); | ||
772 | skip_bits_long(s, 0); | ||
773 | #endif | ||
774 | } | ||
775 | |||
776 | static inline void align_get_bits(GetBitContext *s) | ||
777 | { | ||
778 | int n= (-get_bits_count(s)) & 7; | ||
779 | if(n) skip_bits(s, n); | ||
780 | } | ||
781 | |||
782 | #define init_vlc(vlc, nb_bits, nb_codes,\ | ||
783 | bits, bits_wrap, bits_size,\ | ||
784 | codes, codes_wrap, codes_size,\ | ||
785 | flags)\ | ||
786 | init_vlc_sparse(vlc, nb_bits, nb_codes,\ | ||
787 | bits, bits_wrap, bits_size,\ | ||
788 | codes, codes_wrap, codes_size,\ | ||
789 | NULL, 0, 0, flags) | ||
790 | |||
791 | int init_vlc_sparse(VLC *vlc, int nb_bits, int nb_codes, | ||
792 | const void *bits, int bits_wrap, int bits_size, | ||
793 | const void *codes, int codes_wrap, int codes_size, | ||
794 | const void *symbols, int symbols_wrap, int symbols_size, | ||
795 | int flags); | ||
796 | #define INIT_VLC_USE_STATIC 1 ///< VERY strongly deprecated and forbidden | ||
797 | #define INIT_VLC_LE 2 | ||
798 | #define INIT_VLC_USE_NEW_STATIC 4 | ||
799 | void free_vlc(VLC *vlc); | ||
800 | |||
801 | #define INIT_VLC_STATIC(vlc, bits, a,b,c,d,e,f,g, static_size)\ | ||
802 | {\ | ||
803 | static VLC_TYPE table[static_size][2];\ | ||
804 | (vlc)->table= table;\ | ||
805 | (vlc)->table_allocated= static_size;\ | ||
806 | init_vlc(vlc, bits, a,b,c,d,e,f,g, INIT_VLC_USE_NEW_STATIC);\ | ||
807 | } | ||
808 | |||
809 | |||
810 | /** | ||
811 | * | ||
812 | * if the vlc code is invalid and max_depth=1 than no bits will be removed | ||
813 | * if the vlc code is invalid and max_depth>1 than the number of bits removed | ||
814 | * is undefined | ||
815 | */ | ||
816 | #define GET_VLC(code, name, gb, table, bits, max_depth)\ | ||
817 | {\ | ||
818 | int n, index, nb_bits;\ | ||
819 | \ | ||
820 | index= SHOW_UBITS(name, gb, bits);\ | ||
821 | code = table[index][0];\ | ||
822 | n = table[index][1];\ | ||
823 | \ | ||
824 | if(max_depth > 1 && n < 0){\ | ||
825 | LAST_SKIP_BITS(name, gb, bits)\ | ||
826 | UPDATE_CACHE(name, gb)\ | ||
827 | \ | ||
828 | nb_bits = -n;\ | ||
829 | \ | ||
830 | index= SHOW_UBITS(name, gb, nb_bits) + code;\ | ||
831 | code = table[index][0];\ | ||
832 | n = table[index][1];\ | ||
833 | if(max_depth > 2 && n < 0){\ | ||
834 | LAST_SKIP_BITS(name, gb, nb_bits)\ | ||
835 | UPDATE_CACHE(name, gb)\ | ||
836 | \ | ||
837 | nb_bits = -n;\ | ||
838 | \ | ||
839 | index= SHOW_UBITS(name, gb, nb_bits) + code;\ | ||
840 | code = table[index][0];\ | ||
841 | n = table[index][1];\ | ||
842 | }\ | ||
843 | }\ | ||
844 | SKIP_BITS(name, gb, n)\ | ||
845 | } | ||
846 | |||
847 | #define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)\ | ||
848 | {\ | ||
849 | int n, index, nb_bits;\ | ||
850 | \ | ||
851 | index= SHOW_UBITS(name, gb, bits);\ | ||
852 | level = table[index].level;\ | ||
853 | n = table[index].len;\ | ||
854 | \ | ||
855 | if(max_depth > 1 && n < 0){\ | ||
856 | SKIP_BITS(name, gb, bits)\ | ||
857 | if(need_update){\ | ||
858 | UPDATE_CACHE(name, gb)\ | ||
859 | }\ | ||
860 | \ | ||
861 | nb_bits = -n;\ | ||
862 | \ | ||
863 | index= SHOW_UBITS(name, gb, nb_bits) + level;\ | ||
864 | level = table[index].level;\ | ||
865 | n = table[index].len;\ | ||
866 | }\ | ||
867 | run= table[index].run;\ | ||
868 | SKIP_BITS(name, gb, n)\ | ||
869 | } | ||
870 | |||
871 | |||
872 | /** | ||
873 | * parses a vlc code, faster then get_vlc() | ||
874 | * @param bits is the number of bits which will be read at once, must be | ||
875 | * identical to nb_bits in init_vlc() | ||
876 | * @param max_depth is the number of times bits bits must be read to completely | ||
877 | * read the longest vlc code | ||
878 | * = (max_vlc_length + bits - 1) / bits | ||
879 | */ | ||
880 | static inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], | ||
881 | int bits, int max_depth) | ||
882 | { | ||
883 | int code; | ||
884 | |||
885 | OPEN_READER(re, s) | ||
886 | UPDATE_CACHE(re, s) | ||
887 | |||
888 | GET_VLC(code, re, s, table, bits, max_depth) | ||
889 | |||
890 | CLOSE_READER(re, s) | ||
891 | return code; | ||
892 | } | ||
893 | |||
894 | //#define TRACE | ||
895 | |||
896 | #ifdef TRACE | ||
897 | static inline void print_bin(int bits, int n){ | ||
898 | int i; | ||
899 | |||
900 | for(i=n-1; i>=0; i--){ | ||
901 | printf("%d", (bits>>i)&1); | ||
902 | } | ||
903 | for(i=n; i<24; i++) | ||
904 | printf(" "); | ||
905 | } | ||
906 | |||
907 | static inline int get_bits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | ||
908 | int r= get_bits(s, n); | ||
909 | |||
910 | print_bin(r, n); | ||
911 | printf("%5d %2d %3d bit @%5d in %s %s:%d\n", r, n, r, get_bits_count(s)-n, file, func, line); | ||
912 | return r; | ||
913 | } | ||
914 | static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], int bits, int max_depth, char *file, const char *func, int line){ | ||
915 | int show= show_bits(s, 24); | ||
916 | int pos= get_bits_count(s); | ||
917 | int r= get_vlc2(s, table, bits, max_depth); | ||
918 | int len= get_bits_count(s) - pos; | ||
919 | int bits2= show>>(24-len); | ||
920 | |||
921 | print_bin(bits2, len); | ||
922 | |||
923 | printf("%5d %2d %3d vlc @%5d in %s %s:%d\n", bits2, len, r, pos, file, func, line); | ||
924 | return r; | ||
925 | } | ||
926 | static inline int get_xbits_trace(GetBitContext *s, int n, char *file, const char *func, int line){ | ||
927 | int show= show_bits(s, n); | ||
928 | int r= get_xbits(s, n); | ||
929 | |||
930 | print_bin(show, n); | ||
931 | printf("%5d %2d %3d xbt @%5d in %s %s:%d\n", show, n, r, get_bits_count(s)-n, file, func, line); | ||
932 | return r; | ||
933 | } | ||
934 | |||
935 | #define get_bits(s, n) get_bits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
936 | #define get_bits1(s) get_bits_trace(s, 1, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
937 | #define get_xbits(s, n) get_xbits_trace(s, n, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
938 | #define get_vlc(s, vlc) get_vlc_trace(s, (vlc)->table, (vlc)->bits, 3, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
939 | #define get_vlc2(s, tab, bits, max) get_vlc_trace(s, tab, bits, max, __FILE__, __PRETTY_FUNCTION__, __LINE__) | ||
940 | |||
941 | #define tprintf(p, ...) printf | ||
942 | |||
943 | #else //TRACE | ||
944 | #define tprintf(p, ...) {} | ||
945 | #endif | ||
946 | |||
947 | static inline int decode012(GetBitContext *gb){ | ||
948 | int n; | ||
949 | n = get_bits1(gb); | ||
950 | if (n == 0) | ||
951 | return 0; | ||
952 | else | ||
953 | return get_bits1(gb) + 1; | ||
954 | } | ||
955 | |||
956 | static inline int decode210(GetBitContext *gb){ | ||
957 | if (get_bits1(gb)) | ||
958 | return 0; | ||
959 | else | ||
960 | return 2 - get_bits1(gb); | ||
961 | } | ||
962 | |||
963 | #endif /* BITSTREAM_H */ | ||
diff --git a/apps/codecs/libatrac/bswap.h b/apps/codecs/libatrac/bswap.h new file mode 100644 index 0000000000..ff807815a3 --- /dev/null +++ b/apps/codecs/libatrac/bswap.h | |||
@@ -0,0 +1,150 @@ | |||
1 | /** | ||
2 | * @file bswap.h | ||
3 | * byte swap. | ||
4 | */ | ||
5 | |||
6 | #ifndef __BSWAP_H__ | ||
7 | #define __BSWAP_H__ | ||
8 | |||
9 | #ifdef HAVE_BYTESWAP_H | ||
10 | #include <byteswap.h> | ||
11 | #else | ||
12 | |||
13 | #ifdef ROCKBOX | ||
14 | #include "codecs.h" | ||
15 | |||
16 | /* rockbox' optimised inline functions */ | ||
17 | #define bswap_16(x) swap16(x) | ||
18 | #define bswap_32(x) swap32(x) | ||
19 | |||
20 | static inline uint64_t ByteSwap64(uint64_t x) | ||
21 | { | ||
22 | union { | ||
23 | uint64_t ll; | ||
24 | struct { | ||
25 | uint32_t l,h; | ||
26 | } l; | ||
27 | } r; | ||
28 | r.l.l = bswap_32 (x); | ||
29 | r.l.h = bswap_32 (x>>32); | ||
30 | return r.ll; | ||
31 | } | ||
32 | #define bswap_64(x) ByteSwap64(x) | ||
33 | |||
34 | #elif defined(ARCH_X86) | ||
35 | static inline unsigned short ByteSwap16(unsigned short x) | ||
36 | { | ||
37 | __asm("xchgb %b0,%h0" : | ||
38 | "=q" (x) : | ||
39 | "0" (x)); | ||
40 | return x; | ||
41 | } | ||
42 | #define bswap_16(x) ByteSwap16(x) | ||
43 | |||
44 | static inline unsigned int ByteSwap32(unsigned int x) | ||
45 | { | ||
46 | #if __CPU__ > 386 | ||
47 | __asm("bswap %0": | ||
48 | "=r" (x) : | ||
49 | #else | ||
50 | __asm("xchgb %b0,%h0\n" | ||
51 | " rorl $16,%0\n" | ||
52 | " xchgb %b0,%h0": | ||
53 | "=q" (x) : | ||
54 | #endif | ||
55 | "0" (x)); | ||
56 | return x; | ||
57 | } | ||
58 | #define bswap_32(x) ByteSwap32(x) | ||
59 | |||
60 | static inline unsigned long long int ByteSwap64(unsigned long long int x) | ||
61 | { | ||
62 | register union { __extension__ uint64_t __ll; | ||
63 | uint32_t __l[2]; } __x; | ||
64 | asm("xchgl %0,%1": | ||
65 | "=r"(__x.__l[0]),"=r"(__x.__l[1]): | ||
66 | "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | ||
67 | return __x.__ll; | ||
68 | } | ||
69 | #define bswap_64(x) ByteSwap64(x) | ||
70 | |||
71 | #elif defined(ARCH_SH4) | ||
72 | |||
73 | static inline uint16_t ByteSwap16(uint16_t x) { | ||
74 | __asm__("swap.b %0,%0":"=r"(x):"0"(x)); | ||
75 | return x; | ||
76 | } | ||
77 | |||
78 | static inline uint32_t ByteSwap32(uint32_t x) { | ||
79 | __asm__( | ||
80 | "swap.b %0,%0\n" | ||
81 | "swap.w %0,%0\n" | ||
82 | "swap.b %0,%0\n" | ||
83 | :"=r"(x):"0"(x)); | ||
84 | return x; | ||
85 | } | ||
86 | |||
87 | #define bswap_16(x) ByteSwap16(x) | ||
88 | #define bswap_32(x) ByteSwap32(x) | ||
89 | |||
90 | static inline uint64_t ByteSwap64(uint64_t x) | ||
91 | { | ||
92 | union { | ||
93 | uint64_t ll; | ||
94 | struct { | ||
95 | uint32_t l,h; | ||
96 | } l; | ||
97 | } r; | ||
98 | r.l.l = bswap_32 (x); | ||
99 | r.l.h = bswap_32 (x>>32); | ||
100 | return r.ll; | ||
101 | } | ||
102 | #define bswap_64(x) ByteSwap64(x) | ||
103 | |||
104 | #else | ||
105 | |||
106 | #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) | ||
107 | |||
108 | |||
109 | // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | ||
110 | #define bswap_32(x) \ | ||
111 | ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | ||
112 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | ||
113 | |||
114 | /*static inline uint64_t ByteSwap64(uint64_t x) | ||
115 | { | ||
116 | union { | ||
117 | uint64_t ll; | ||
118 | uint32_t l[2]; | ||
119 | } w, r; | ||
120 | w.ll = x; | ||
121 | r.l[0] = bswap_32 (w.l[1]); | ||
122 | r.l[1] = bswap_32 (w.l[0]); | ||
123 | return r.ll; | ||
124 | }*/ | ||
125 | #define bswap_64(x) ByteSwap64(x) | ||
126 | |||
127 | #endif /* !ARCH_X86 */ | ||
128 | |||
129 | #endif /* !HAVE_BYTESWAP_H */ | ||
130 | |||
131 | // be2me ... BigEndian to MachineEndian | ||
132 | // le2me ... LittleEndian to MachineEndian | ||
133 | |||
134 | #ifdef WORDS_BIGENDIAN | ||
135 | #define be2me_16(x) (x) | ||
136 | #define be2me_32(x) (x) | ||
137 | #define be2me_64(x) (x) | ||
138 | #define le2me_16(x) bswap_16(x) | ||
139 | #define le2me_32(x) bswap_32(x) | ||
140 | #define le2me_64(x) bswap_64(x) | ||
141 | #else | ||
142 | #define be2me_16(x) bswap_16(x) | ||
143 | #define be2me_32(x) bswap_32(x) | ||
144 | #define be2me_64(x) bswap_64(x) | ||
145 | #define le2me_16(x) (x) | ||
146 | #define le2me_32(x) (x) | ||
147 | #define le2me_64(x) (x) | ||
148 | #endif | ||
149 | |||
150 | #endif /* __BSWAP_H__ */ | ||
diff --git a/apps/codecs/libatrac/bytestream.h b/apps/codecs/libatrac/bytestream.h new file mode 100644 index 0000000000..b56f6ce743 --- /dev/null +++ b/apps/codecs/libatrac/bytestream.h | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Bytestream functions | ||
3 | * copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@free.fr> | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | |||
22 | #ifndef AVCODEC_BYTESTREAM_H | ||
23 | #define AVCODEC_BYTESTREAM_H | ||
24 | |||
25 | #include <string.h> | ||
26 | #include "libavutil/common.h" | ||
27 | #include "libavutil/intreadwrite.h" | ||
28 | |||
29 | #define DEF_T(type, name, bytes, read, write) \ | ||
30 | static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\ | ||
31 | (*b) += bytes;\ | ||
32 | return read(*b - bytes);\ | ||
33 | }\ | ||
34 | static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\ | ||
35 | write(*b, value);\ | ||
36 | (*b) += bytes;\ | ||
37 | } | ||
38 | |||
39 | #define DEF(name, bytes, read, write) \ | ||
40 | DEF_T(unsigned int, name, bytes, read, write) | ||
41 | #define DEF64(name, bytes, read, write) \ | ||
42 | DEF_T(uint64_t, name, bytes, read, write) | ||
43 | |||
44 | DEF64(le64, 8, AV_RL64, AV_WL64) | ||
45 | DEF (le32, 4, AV_RL32, AV_WL32) | ||
46 | DEF (le24, 3, AV_RL24, AV_WL24) | ||
47 | DEF (le16, 2, AV_RL16, AV_WL16) | ||
48 | DEF64(be64, 8, AV_RB64, AV_WB64) | ||
49 | DEF (be32, 4, AV_RB32, AV_WB32) | ||
50 | DEF (be24, 3, AV_RB24, AV_WB24) | ||
51 | DEF (be16, 2, AV_RB16, AV_WB16) | ||
52 | DEF (byte, 1, AV_RB8 , AV_WB8 ) | ||
53 | |||
54 | #undef DEF | ||
55 | #undef DEF64 | ||
56 | #undef DEF_T | ||
57 | |||
58 | static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size) | ||
59 | { | ||
60 | memcpy(dst, *b, size); | ||
61 | (*b) += size; | ||
62 | return size; | ||
63 | } | ||
64 | |||
65 | static av_always_inline void bytestream_put_buffer(uint8_t **b, const uint8_t *src, unsigned int size) | ||
66 | { | ||
67 | memcpy(*b, src, size); | ||
68 | (*b) += size; | ||
69 | } | ||
70 | |||
71 | #endif /* AVCODEC_BYTESTREAM_H */ | ||
diff --git a/apps/codecs/libatrac/dsputil.c b/apps/codecs/libatrac/dsputil.c new file mode 100644 index 0000000000..412a934862 --- /dev/null +++ b/apps/codecs/libatrac/dsputil.c | |||
@@ -0,0 +1,4114 @@ | |||
1 | /* | ||
2 | * DSP utils | ||
3 | * Copyright (c) 2000, 2001 Fabrice Bellard | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer <michaelni@gmx.at> | ||
7 | * | ||
8 | * This file is part of FFmpeg. | ||
9 | * | ||
10 | * FFmpeg is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU Lesser General Public | ||
12 | * License as published by the Free Software Foundation; either | ||
13 | * version 2.1 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * FFmpeg is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * Lesser General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU Lesser General Public | ||
21 | * License along with FFmpeg; if not, write to the Free Software | ||
22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
23 | */ | ||
24 | |||
25 | /** | ||
26 | * @file libavcodec/dsputil.c | ||
27 | * DSP utils | ||
28 | */ | ||
29 | |||
30 | #include "avcodec.h" | ||
31 | #include "dsputil.h" | ||
32 | /*#include "simple_idct.h" | ||
33 | #include "faandct.h" | ||
34 | #include "faanidct.h" | ||
35 | #include "mathops.h" | ||
36 | #include "h263.h" | ||
37 | #include "snow.h" */ | ||
38 | |||
39 | /* snow.c */ | ||
40 | void ff_spatial_dwt(int *buffer, int width, int height, int stride, int type, int decomposition_count); | ||
41 | |||
42 | /* vorbis.c */ | ||
43 | void vorbis_inverse_coupling(float *mag, float *ang, int blocksize); | ||
44 | |||
45 | /* ac3dec.c */ | ||
46 | void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len); | ||
47 | |||
48 | /* flacenc.c */ | ||
49 | void ff_flac_compute_autocorr(const int32_t *data, int len, int lag, double *autoc); | ||
50 | |||
51 | /* pngdec.c */ | ||
52 | void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); | ||
53 | |||
54 | /* eaidct.c */ | ||
55 | void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block); | ||
56 | |||
57 | uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, }; | ||
58 | uint32_t ff_squareTbl[512] = {0, }; | ||
59 | |||
60 | // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size | ||
61 | #define pb_7f (~0UL/255 * 0x7f) | ||
62 | #define pb_80 (~0UL/255 * 0x80) | ||
63 | |||
64 | const uint8_t ff_zigzag_direct[64] = { | ||
65 | 0, 1, 8, 16, 9, 2, 3, 10, | ||
66 | 17, 24, 32, 25, 18, 11, 4, 5, | ||
67 | 12, 19, 26, 33, 40, 48, 41, 34, | ||
68 | 27, 20, 13, 6, 7, 14, 21, 28, | ||
69 | 35, 42, 49, 56, 57, 50, 43, 36, | ||
70 | 29, 22, 15, 23, 30, 37, 44, 51, | ||
71 | 58, 59, 52, 45, 38, 31, 39, 46, | ||
72 | 53, 60, 61, 54, 47, 55, 62, 63 | ||
73 | }; | ||
74 | |||
75 | /* Specific zigzag scan for 248 idct. NOTE that unlike the | ||
76 | specification, we interleave the fields */ | ||
77 | const uint8_t ff_zigzag248_direct[64] = { | ||
78 | 0, 8, 1, 9, 16, 24, 2, 10, | ||
79 | 17, 25, 32, 40, 48, 56, 33, 41, | ||
80 | 18, 26, 3, 11, 4, 12, 19, 27, | ||
81 | 34, 42, 49, 57, 50, 58, 35, 43, | ||
82 | 20, 28, 5, 13, 6, 14, 21, 29, | ||
83 | 36, 44, 51, 59, 52, 60, 37, 45, | ||
84 | 22, 30, 7, 15, 23, 31, 38, 46, | ||
85 | 53, 61, 54, 62, 39, 47, 55, 63, | ||
86 | }; | ||
87 | |||
88 | /* not permutated inverse zigzag_direct + 1 for MMX quantizer */ | ||
89 | DECLARE_ALIGNED_8(uint16_t, inv_zigzag_direct16[64]) = {0, }; | ||
90 | |||
91 | const uint8_t ff_alternate_horizontal_scan[64] = { | ||
92 | 0, 1, 2, 3, 8, 9, 16, 17, | ||
93 | 10, 11, 4, 5, 6, 7, 15, 14, | ||
94 | 13, 12, 19, 18, 24, 25, 32, 33, | ||
95 | 26, 27, 20, 21, 22, 23, 28, 29, | ||
96 | 30, 31, 34, 35, 40, 41, 48, 49, | ||
97 | 42, 43, 36, 37, 38, 39, 44, 45, | ||
98 | 46, 47, 50, 51, 56, 57, 58, 59, | ||
99 | 52, 53, 54, 55, 60, 61, 62, 63, | ||
100 | }; | ||
101 | |||
102 | const uint8_t ff_alternate_vertical_scan[64] = { | ||
103 | 0, 8, 16, 24, 1, 9, 2, 10, | ||
104 | 17, 25, 32, 40, 48, 56, 57, 49, | ||
105 | 41, 33, 26, 18, 3, 11, 4, 12, | ||
106 | 19, 27, 34, 42, 50, 58, 35, 43, | ||
107 | 51, 59, 20, 28, 5, 13, 6, 14, | ||
108 | 21, 29, 36, 44, 52, 60, 37, 45, | ||
109 | 53, 61, 22, 30, 7, 15, 23, 31, | ||
110 | 38, 46, 54, 62, 39, 47, 55, 63, | ||
111 | }; | ||
112 | |||
113 | /* a*inverse[b]>>32 == a/b for all 0<=a<=65536 && 2<=b<=255 */ | ||
114 | const uint32_t ff_inverse[256]={ | ||
115 | 0, 4294967295U,2147483648U,1431655766, 1073741824, 858993460, 715827883, 613566757, | ||
116 | 536870912, 477218589, 429496730, 390451573, 357913942, 330382100, 306783379, 286331154, | ||
117 | 268435456, 252645136, 238609295, 226050911, 214748365, 204522253, 195225787, 186737709, | ||
118 | 178956971, 171798692, 165191050, 159072863, 153391690, 148102321, 143165577, 138547333, | ||
119 | 134217728, 130150525, 126322568, 122713352, 119304648, 116080198, 113025456, 110127367, | ||
120 | 107374183, 104755300, 102261127, 99882961, 97612894, 95443718, 93368855, 91382283, | ||
121 | 89478486, 87652394, 85899346, 84215046, 82595525, 81037119, 79536432, 78090315, | ||
122 | 76695845, 75350304, 74051161, 72796056, 71582789, 70409300, 69273667, 68174085, | ||
123 | 67108864, 66076420, 65075263, 64103990, 63161284, 62245903, 61356676, 60492498, | ||
124 | 59652324, 58835169, 58040099, 57266231, 56512728, 55778797, 55063684, 54366675, | ||
125 | 53687092, 53024288, 52377650, 51746594, 51130564, 50529028, 49941481, 49367441, | ||
126 | 48806447, 48258060, 47721859, 47197443, 46684428, 46182445, 45691142, 45210183, | ||
127 | 44739243, 44278014, 43826197, 43383509, 42949673, 42524429, 42107523, 41698712, | ||
128 | 41297763, 40904451, 40518560, 40139882, 39768216, 39403370, 39045158, 38693400, | ||
129 | 38347923, 38008561, 37675152, 37347542, 37025581, 36709123, 36398028, 36092163, | ||
130 | 35791395, 35495598, 35204650, 34918434, 34636834, 34359739, 34087043, 33818641, | ||
131 | 33554432, 33294321, 33038210, 32786010, 32537632, 32292988, 32051995, 31814573, | ||
132 | 31580642, 31350127, 31122952, 30899046, 30678338, 30460761, 30246249, 30034737, | ||
133 | 29826162, 29620465, 29417585, 29217465, 29020050, 28825284, 28633116, 28443493, | ||
134 | 28256364, 28071682, 27889399, 27709467, 27531842, 27356480, 27183338, 27012373, | ||
135 | 26843546, 26676816, 26512144, 26349493, 26188825, 26030105, 25873297, 25718368, | ||
136 | 25565282, 25414008, 25264514, 25116768, 24970741, 24826401, 24683721, 24542671, | ||
137 | 24403224, 24265352, 24129030, 23994231, 23860930, 23729102, 23598722, 23469767, | ||
138 | 23342214, 23216040, 23091223, 22967740, 22845571, 22724695, 22605092, 22486740, | ||
139 | 22369622, 22253717, 22139007, 22025474, 21913099, 21801865, 21691755, 21582751, | ||
140 | 21474837, 21367997, 21262215, 21157475, 21053762, 20951060, 20849356, 20748635, | ||
141 | 20648882, 20550083, 20452226, 20355296, 20259280, 20164166, 20069941, 19976593, | ||
142 | 19884108, 19792477, 19701685, 19611723, 19522579, 19434242, 19346700, 19259944, | ||
143 | 19173962, 19088744, 19004281, 18920561, 18837576, 18755316, 18673771, 18592933, | ||
144 | 18512791, 18433337, 18354562, 18276457, 18199014, 18122225, 18046082, 17970575, | ||
145 | 17895698, 17821442, 17747799, 17674763, 17602325, 17530479, 17459217, 17388532, | ||
146 | 17318417, 17248865, 17179870, 17111424, 17043522, 16976156, 16909321, 16843010, | ||
147 | }; | ||
148 | |||
149 | /* Input permutation for the simple_idct_mmx */ | ||
150 | static const uint8_t simple_mmx_permutation[64]={ | ||
151 | 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, | ||
152 | 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, | ||
153 | 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, | ||
154 | 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, | ||
155 | 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, | ||
156 | 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, | ||
157 | 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, | ||
158 | 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, | ||
159 | }; | ||
160 | |||
161 | static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7}; | ||
162 | |||
163 | void ff_init_scantable(uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable){ | ||
164 | int i; | ||
165 | int end; | ||
166 | |||
167 | st->scantable= src_scantable; | ||
168 | |||
169 | for(i=0; i<64; i++){ | ||
170 | int j; | ||
171 | j = src_scantable[i]; | ||
172 | st->permutated[i] = permutation[j]; | ||
173 | #if ARCH_PPC | ||
174 | st->inverse[j] = i; | ||
175 | #endif | ||
176 | } | ||
177 | |||
178 | end=-1; | ||
179 | for(i=0; i<64; i++){ | ||
180 | int j; | ||
181 | j = st->permutated[i]; | ||
182 | if(j>end) end=j; | ||
183 | st->raster_end[i]= end; | ||
184 | } | ||
185 | } | ||
186 | |||
187 | #if CONFIG_SNOW_ENCODER //dwt is in snow.c | ||
188 | static inline int w_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int w, int h, int type){ | ||
189 | int s, i, j; | ||
190 | const int dec_count= w==8 ? 3 : 4; | ||
191 | int tmp[32*32]; | ||
192 | int level, ori; | ||
193 | static const int scale[2][2][4][4]={ | ||
194 | { | ||
195 | { | ||
196 | // 9/7 8x8 dec=3 | ||
197 | {268, 239, 239, 213}, | ||
198 | { 0, 224, 224, 152}, | ||
199 | { 0, 135, 135, 110}, | ||
200 | },{ | ||
201 | // 9/7 16x16 or 32x32 dec=4 | ||
202 | {344, 310, 310, 280}, | ||
203 | { 0, 320, 320, 228}, | ||
204 | { 0, 175, 175, 136}, | ||
205 | { 0, 129, 129, 102}, | ||
206 | } | ||
207 | },{ | ||
208 | { | ||
209 | // 5/3 8x8 dec=3 | ||
210 | {275, 245, 245, 218}, | ||
211 | { 0, 230, 230, 156}, | ||
212 | { 0, 138, 138, 113}, | ||
213 | },{ | ||
214 | // 5/3 16x16 or 32x32 dec=4 | ||
215 | {352, 317, 317, 286}, | ||
216 | { 0, 328, 328, 233}, | ||
217 | { 0, 180, 180, 140}, | ||
218 | { 0, 132, 132, 105}, | ||
219 | } | ||
220 | } | ||
221 | }; | ||
222 | |||
223 | for (i = 0; i < h; i++) { | ||
224 | for (j = 0; j < w; j+=4) { | ||
225 | tmp[32*i+j+0] = (pix1[j+0] - pix2[j+0])<<4; | ||
226 | tmp[32*i+j+1] = (pix1[j+1] - pix2[j+1])<<4; | ||
227 | tmp[32*i+j+2] = (pix1[j+2] - pix2[j+2])<<4; | ||
228 | tmp[32*i+j+3] = (pix1[j+3] - pix2[j+3])<<4; | ||
229 | } | ||
230 | pix1 += line_size; | ||
231 | pix2 += line_size; | ||
232 | } | ||
233 | |||
234 | ff_spatial_dwt(tmp, w, h, 32, type, dec_count); | ||
235 | |||
236 | s=0; | ||
237 | assert(w==h); | ||
238 | for(level=0; level<dec_count; level++){ | ||
239 | for(ori= level ? 1 : 0; ori<4; ori++){ | ||
240 | int size= w>>(dec_count-level); | ||
241 | int sx= (ori&1) ? size : 0; | ||
242 | int stride= 32<<(dec_count-level); | ||
243 | int sy= (ori&2) ? stride>>1 : 0; | ||
244 | |||
245 | for(i=0; i<size; i++){ | ||
246 | for(j=0; j<size; j++){ | ||
247 | int v= tmp[sx + sy + i*stride + j] * scale[type][dec_count-3][level][ori]; | ||
248 | s += FFABS(v); | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | assert(s>=0); | ||
254 | return s>>9; | ||
255 | } | ||
256 | |||
257 | static int w53_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ | ||
258 | return w_c(v, pix1, pix2, line_size, 8, h, 1); | ||
259 | } | ||
260 | |||
261 | static int w97_8_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ | ||
262 | return w_c(v, pix1, pix2, line_size, 8, h, 0); | ||
263 | } | ||
264 | |||
265 | static int w53_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ | ||
266 | return w_c(v, pix1, pix2, line_size, 16, h, 1); | ||
267 | } | ||
268 | |||
269 | static int w97_16_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ | ||
270 | return w_c(v, pix1, pix2, line_size, 16, h, 0); | ||
271 | } | ||
272 | |||
273 | int w53_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ | ||
274 | return w_c(v, pix1, pix2, line_size, 32, h, 1); | ||
275 | } | ||
276 | |||
277 | int w97_32_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h){ | ||
278 | return w_c(v, pix1, pix2, line_size, 32, h, 0); | ||
279 | } | ||
280 | #endif | ||
281 | |||
282 | /** | ||
283 | * Copies a rectangular area of samples to a temporary buffer and replicates the boarder samples. | ||
284 | * @param buf destination buffer | ||
285 | * @param src source buffer | ||
286 | * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers | ||
287 | * @param block_w width of block | ||
288 | * @param block_h height of block | ||
289 | * @param src_x x coordinate of the top left sample of the block in the source buffer | ||
290 | * @param src_y y coordinate of the top left sample of the block in the source buffer | ||
291 | * @param w width of the source buffer | ||
292 | * @param h height of the source buffer | ||
293 | */ | ||
294 | void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, int block_w, int block_h, | ||
295 | int src_x, int src_y, int w, int h){ | ||
296 | int x, y; | ||
297 | int start_y, start_x, end_y, end_x; | ||
298 | |||
299 | if(src_y>= h){ | ||
300 | src+= (h-1-src_y)*linesize; | ||
301 | src_y=h-1; | ||
302 | }else if(src_y<=-block_h){ | ||
303 | src+= (1-block_h-src_y)*linesize; | ||
304 | src_y=1-block_h; | ||
305 | } | ||
306 | if(src_x>= w){ | ||
307 | src+= (w-1-src_x); | ||
308 | src_x=w-1; | ||
309 | }else if(src_x<=-block_w){ | ||
310 | src+= (1-block_w-src_x); | ||
311 | src_x=1-block_w; | ||
312 | } | ||
313 | |||
314 | start_y= FFMAX(0, -src_y); | ||
315 | start_x= FFMAX(0, -src_x); | ||
316 | end_y= FFMIN(block_h, h-src_y); | ||
317 | end_x= FFMIN(block_w, w-src_x); | ||
318 | |||
319 | // copy existing part | ||
320 | for(y=start_y; y<end_y; y++){ | ||
321 | for(x=start_x; x<end_x; x++){ | ||
322 | buf[x + y*linesize]= src[x + y*linesize]; | ||
323 | } | ||
324 | } | ||
325 | |||
326 | //top | ||
327 | for(y=0; y<start_y; y++){ | ||
328 | for(x=start_x; x<end_x; x++){ | ||
329 | buf[x + y*linesize]= buf[x + start_y*linesize]; | ||
330 | } | ||
331 | } | ||
332 | |||
333 | //bottom | ||
334 | for(y=end_y; y<block_h; y++){ | ||
335 | for(x=start_x; x<end_x; x++){ | ||
336 | buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; | ||
337 | } | ||
338 | } | ||
339 | |||
340 | for(y=0; y<block_h; y++){ | ||
341 | //left | ||
342 | for(x=0; x<start_x; x++){ | ||
343 | buf[x + y*linesize]= buf[start_x + y*linesize]; | ||
344 | } | ||
345 | |||
346 | //right | ||
347 | for(x=end_x; x<block_w; x++){ | ||
348 | buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; | ||
349 | } | ||
350 | } | ||
351 | } | ||
352 | |||
353 | #if 0 | ||
354 | static void get_pixels_c(DCTELEM *restrict block, const uint8_t *pixels, int line_size) | ||
355 | { | ||
356 | int i; | ||
357 | |||
358 | /* read the pixels */ | ||
359 | for(i=0;i<8;i++) { | ||
360 | block[0] = pixels[0]; | ||
361 | block[1] = pixels[1]; | ||
362 | block[2] = pixels[2]; | ||
363 | block[3] = pixels[3]; | ||
364 | block[4] = pixels[4]; | ||
365 | block[5] = pixels[5]; | ||
366 | block[6] = pixels[6]; | ||
367 | block[7] = pixels[7]; | ||
368 | pixels += line_size; | ||
369 | block += 8; | ||
370 | } | ||
371 | } | ||
372 | |||
373 | static void diff_pixels_c(DCTELEM *restrict block, const uint8_t *s1, | ||
374 | const uint8_t *s2, int stride){ | ||
375 | int i; | ||
376 | |||
377 | /* read the pixels */ | ||
378 | for(i=0;i<8;i++) { | ||
379 | block[0] = s1[0] - s2[0]; | ||
380 | block[1] = s1[1] - s2[1]; | ||
381 | block[2] = s1[2] - s2[2]; | ||
382 | block[3] = s1[3] - s2[3]; | ||
383 | block[4] = s1[4] - s2[4]; | ||
384 | block[5] = s1[5] - s2[5]; | ||
385 | block[6] = s1[6] - s2[6]; | ||
386 | block[7] = s1[7] - s2[7]; | ||
387 | s1 += stride; | ||
388 | s2 += stride; | ||
389 | block += 8; | ||
390 | } | ||
391 | } | ||
392 | |||
393 | |||
394 | static void put_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels, | ||
395 | int line_size) | ||
396 | { | ||
397 | int i; | ||
398 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
399 | |||
400 | /* read the pixels */ | ||
401 | for(i=0;i<8;i++) { | ||
402 | pixels[0] = cm[block[0]]; | ||
403 | pixels[1] = cm[block[1]]; | ||
404 | pixels[2] = cm[block[2]]; | ||
405 | pixels[3] = cm[block[3]]; | ||
406 | pixels[4] = cm[block[4]]; | ||
407 | pixels[5] = cm[block[5]]; | ||
408 | pixels[6] = cm[block[6]]; | ||
409 | pixels[7] = cm[block[7]]; | ||
410 | |||
411 | pixels += line_size; | ||
412 | block += 8; | ||
413 | } | ||
414 | } | ||
415 | |||
416 | static void put_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels, | ||
417 | int line_size) | ||
418 | { | ||
419 | int i; | ||
420 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
421 | |||
422 | /* read the pixels */ | ||
423 | for(i=0;i<4;i++) { | ||
424 | pixels[0] = cm[block[0]]; | ||
425 | pixels[1] = cm[block[1]]; | ||
426 | pixels[2] = cm[block[2]]; | ||
427 | pixels[3] = cm[block[3]]; | ||
428 | |||
429 | pixels += line_size; | ||
430 | block += 8; | ||
431 | } | ||
432 | } | ||
433 | |||
434 | static void put_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels, | ||
435 | int line_size) | ||
436 | { | ||
437 | int i; | ||
438 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
439 | |||
440 | /* read the pixels */ | ||
441 | for(i=0;i<2;i++) { | ||
442 | pixels[0] = cm[block[0]]; | ||
443 | pixels[1] = cm[block[1]]; | ||
444 | |||
445 | pixels += line_size; | ||
446 | block += 8; | ||
447 | } | ||
448 | } | ||
449 | |||
450 | static void put_signed_pixels_clamped_c(const DCTELEM *block, | ||
451 | uint8_t *restrict pixels, | ||
452 | int line_size) | ||
453 | { | ||
454 | int i, j; | ||
455 | |||
456 | for (i = 0; i < 8; i++) { | ||
457 | for (j = 0; j < 8; j++) { | ||
458 | if (*block < -128) | ||
459 | *pixels = 0; | ||
460 | else if (*block > 127) | ||
461 | *pixels = 255; | ||
462 | else | ||
463 | *pixels = (uint8_t)(*block + 128); | ||
464 | block++; | ||
465 | pixels++; | ||
466 | } | ||
467 | pixels += (line_size - 8); | ||
468 | } | ||
469 | } | ||
470 | |||
471 | static void add_pixels_clamped_c(const DCTELEM *block, uint8_t *restrict pixels, | ||
472 | int line_size) | ||
473 | { | ||
474 | int i; | ||
475 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
476 | |||
477 | /* read the pixels */ | ||
478 | for(i=0;i<8;i++) { | ||
479 | pixels[0] = cm[pixels[0] + block[0]]; | ||
480 | pixels[1] = cm[pixels[1] + block[1]]; | ||
481 | pixels[2] = cm[pixels[2] + block[2]]; | ||
482 | pixels[3] = cm[pixels[3] + block[3]]; | ||
483 | pixels[4] = cm[pixels[4] + block[4]]; | ||
484 | pixels[5] = cm[pixels[5] + block[5]]; | ||
485 | pixels[6] = cm[pixels[6] + block[6]]; | ||
486 | pixels[7] = cm[pixels[7] + block[7]]; | ||
487 | pixels += line_size; | ||
488 | block += 8; | ||
489 | } | ||
490 | } | ||
491 | |||
492 | static void add_pixels_clamped4_c(const DCTELEM *block, uint8_t *restrict pixels, | ||
493 | int line_size) | ||
494 | { | ||
495 | int i; | ||
496 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
497 | |||
498 | /* read the pixels */ | ||
499 | for(i=0;i<4;i++) { | ||
500 | pixels[0] = cm[pixels[0] + block[0]]; | ||
501 | pixels[1] = cm[pixels[1] + block[1]]; | ||
502 | pixels[2] = cm[pixels[2] + block[2]]; | ||
503 | pixels[3] = cm[pixels[3] + block[3]]; | ||
504 | pixels += line_size; | ||
505 | block += 8; | ||
506 | } | ||
507 | } | ||
508 | |||
509 | static void add_pixels_clamped2_c(const DCTELEM *block, uint8_t *restrict pixels, | ||
510 | int line_size) | ||
511 | { | ||
512 | int i; | ||
513 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
514 | |||
515 | /* read the pixels */ | ||
516 | for(i=0;i<2;i++) { | ||
517 | pixels[0] = cm[pixels[0] + block[0]]; | ||
518 | pixels[1] = cm[pixels[1] + block[1]]; | ||
519 | pixels += line_size; | ||
520 | block += 8; | ||
521 | } | ||
522 | } | ||
523 | |||
524 | static void add_pixels8_c(uint8_t *restrict pixels, DCTELEM *block, int line_size) | ||
525 | { | ||
526 | int i; | ||
527 | for(i=0;i<8;i++) { | ||
528 | pixels[0] += block[0]; | ||
529 | pixels[1] += block[1]; | ||
530 | pixels[2] += block[2]; | ||
531 | pixels[3] += block[3]; | ||
532 | pixels[4] += block[4]; | ||
533 | pixels[5] += block[5]; | ||
534 | pixels[6] += block[6]; | ||
535 | pixels[7] += block[7]; | ||
536 | pixels += line_size; | ||
537 | block += 8; | ||
538 | } | ||
539 | } | ||
540 | |||
541 | static void add_pixels4_c(uint8_t *restrict pixels, DCTELEM *block, int line_size) | ||
542 | { | ||
543 | int i; | ||
544 | for(i=0;i<4;i++) { | ||
545 | pixels[0] += block[0]; | ||
546 | pixels[1] += block[1]; | ||
547 | pixels[2] += block[2]; | ||
548 | pixels[3] += block[3]; | ||
549 | pixels += line_size; | ||
550 | block += 4; | ||
551 | } | ||
552 | } | ||
553 | |||
554 | static int sum_abs_dctelem_c(DCTELEM *block) | ||
555 | { | ||
556 | int sum=0, i; | ||
557 | for(i=0; i<64; i++) | ||
558 | sum+= FFABS(block[i]); | ||
559 | return sum; | ||
560 | } | ||
561 | |||
562 | #if 0 | ||
563 | |||
564 | #define PIXOP2(OPNAME, OP) \ | ||
565 | static void OPNAME ## _pixels(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
566 | {\ | ||
567 | int i;\ | ||
568 | for(i=0; i<h; i++){\ | ||
569 | OP(*((uint64_t*)block), AV_RN64(pixels));\ | ||
570 | pixels+=line_size;\ | ||
571 | block +=line_size;\ | ||
572 | }\ | ||
573 | }\ | ||
574 | \ | ||
575 | static void OPNAME ## _no_rnd_pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
576 | {\ | ||
577 | int i;\ | ||
578 | for(i=0; i<h; i++){\ | ||
579 | const uint64_t a= AV_RN64(pixels );\ | ||
580 | const uint64_t b= AV_RN64(pixels+1);\ | ||
581 | OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\ | ||
582 | pixels+=line_size;\ | ||
583 | block +=line_size;\ | ||
584 | }\ | ||
585 | }\ | ||
586 | \ | ||
587 | static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
588 | {\ | ||
589 | int i;\ | ||
590 | for(i=0; i<h; i++){\ | ||
591 | const uint64_t a= AV_RN64(pixels );\ | ||
592 | const uint64_t b= AV_RN64(pixels+1);\ | ||
593 | OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\ | ||
594 | pixels+=line_size;\ | ||
595 | block +=line_size;\ | ||
596 | }\ | ||
597 | }\ | ||
598 | \ | ||
599 | static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
600 | {\ | ||
601 | int i;\ | ||
602 | for(i=0; i<h; i++){\ | ||
603 | const uint64_t a= AV_RN64(pixels );\ | ||
604 | const uint64_t b= AV_RN64(pixels+line_size);\ | ||
605 | OP(*((uint64_t*)block), (a&b) + (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\ | ||
606 | pixels+=line_size;\ | ||
607 | block +=line_size;\ | ||
608 | }\ | ||
609 | }\ | ||
610 | \ | ||
611 | static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
612 | {\ | ||
613 | int i;\ | ||
614 | for(i=0; i<h; i++){\ | ||
615 | const uint64_t a= AV_RN64(pixels );\ | ||
616 | const uint64_t b= AV_RN64(pixels+line_size);\ | ||
617 | OP(*((uint64_t*)block), (a|b) - (((a^b)&0xFEFEFEFEFEFEFEFEULL)>>1));\ | ||
618 | pixels+=line_size;\ | ||
619 | block +=line_size;\ | ||
620 | }\ | ||
621 | }\ | ||
622 | \ | ||
623 | static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
624 | {\ | ||
625 | int i;\ | ||
626 | const uint64_t a= AV_RN64(pixels );\ | ||
627 | const uint64_t b= AV_RN64(pixels+1);\ | ||
628 | uint64_t l0= (a&0x0303030303030303ULL)\ | ||
629 | + (b&0x0303030303030303ULL)\ | ||
630 | + 0x0202020202020202ULL;\ | ||
631 | uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ | ||
632 | + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ | ||
633 | uint64_t l1,h1;\ | ||
634 | \ | ||
635 | pixels+=line_size;\ | ||
636 | for(i=0; i<h; i+=2){\ | ||
637 | uint64_t a= AV_RN64(pixels );\ | ||
638 | uint64_t b= AV_RN64(pixels+1);\ | ||
639 | l1= (a&0x0303030303030303ULL)\ | ||
640 | + (b&0x0303030303030303ULL);\ | ||
641 | h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ | ||
642 | + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ | ||
643 | OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ | ||
644 | pixels+=line_size;\ | ||
645 | block +=line_size;\ | ||
646 | a= AV_RN64(pixels );\ | ||
647 | b= AV_RN64(pixels+1);\ | ||
648 | l0= (a&0x0303030303030303ULL)\ | ||
649 | + (b&0x0303030303030303ULL)\ | ||
650 | + 0x0202020202020202ULL;\ | ||
651 | h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ | ||
652 | + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ | ||
653 | OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ | ||
654 | pixels+=line_size;\ | ||
655 | block +=line_size;\ | ||
656 | }\ | ||
657 | }\ | ||
658 | \ | ||
659 | static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
660 | {\ | ||
661 | int i;\ | ||
662 | const uint64_t a= AV_RN64(pixels );\ | ||
663 | const uint64_t b= AV_RN64(pixels+1);\ | ||
664 | uint64_t l0= (a&0x0303030303030303ULL)\ | ||
665 | + (b&0x0303030303030303ULL)\ | ||
666 | + 0x0101010101010101ULL;\ | ||
667 | uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ | ||
668 | + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ | ||
669 | uint64_t l1,h1;\ | ||
670 | \ | ||
671 | pixels+=line_size;\ | ||
672 | for(i=0; i<h; i+=2){\ | ||
673 | uint64_t a= AV_RN64(pixels );\ | ||
674 | uint64_t b= AV_RN64(pixels+1);\ | ||
675 | l1= (a&0x0303030303030303ULL)\ | ||
676 | + (b&0x0303030303030303ULL);\ | ||
677 | h1= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ | ||
678 | + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ | ||
679 | OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ | ||
680 | pixels+=line_size;\ | ||
681 | block +=line_size;\ | ||
682 | a= AV_RN64(pixels );\ | ||
683 | b= AV_RN64(pixels+1);\ | ||
684 | l0= (a&0x0303030303030303ULL)\ | ||
685 | + (b&0x0303030303030303ULL)\ | ||
686 | + 0x0101010101010101ULL;\ | ||
687 | h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ | ||
688 | + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ | ||
689 | OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ | ||
690 | pixels+=line_size;\ | ||
691 | block +=line_size;\ | ||
692 | }\ | ||
693 | }\ | ||
694 | \ | ||
695 | CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\ | ||
696 | CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\ | ||
697 | CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\ | ||
698 | CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\ | ||
699 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\ | ||
700 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\ | ||
701 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8) | ||
702 | |||
703 | #define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) ) | ||
704 | #else // 64 bit variant | ||
705 | |||
706 | #define PIXOP2(OPNAME, OP) \ | ||
707 | static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
708 | int i;\ | ||
709 | for(i=0; i<h; i++){\ | ||
710 | OP(*((uint16_t*)(block )), AV_RN16(pixels ));\ | ||
711 | pixels+=line_size;\ | ||
712 | block +=line_size;\ | ||
713 | }\ | ||
714 | }\ | ||
715 | static void OPNAME ## _pixels4_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
716 | int i;\ | ||
717 | for(i=0; i<h; i++){\ | ||
718 | OP(*((uint32_t*)(block )), AV_RN32(pixels ));\ | ||
719 | pixels+=line_size;\ | ||
720 | block +=line_size;\ | ||
721 | }\ | ||
722 | }\ | ||
723 | static void OPNAME ## _pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
724 | int i;\ | ||
725 | for(i=0; i<h; i++){\ | ||
726 | OP(*((uint32_t*)(block )), AV_RN32(pixels ));\ | ||
727 | OP(*((uint32_t*)(block+4)), AV_RN32(pixels+4));\ | ||
728 | pixels+=line_size;\ | ||
729 | block +=line_size;\ | ||
730 | }\ | ||
731 | }\ | ||
732 | static inline void OPNAME ## _no_rnd_pixels8_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
733 | OPNAME ## _pixels8_c(block, pixels, line_size, h);\ | ||
734 | }\ | ||
735 | \ | ||
736 | static inline void OPNAME ## _no_rnd_pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \ | ||
737 | int src_stride1, int src_stride2, int h){\ | ||
738 | int i;\ | ||
739 | for(i=0; i<h; i++){\ | ||
740 | uint32_t a,b;\ | ||
741 | a= AV_RN32(&src1[i*src_stride1 ]);\ | ||
742 | b= AV_RN32(&src2[i*src_stride2 ]);\ | ||
743 | OP(*((uint32_t*)&dst[i*dst_stride ]), no_rnd_avg32(a, b));\ | ||
744 | a= AV_RN32(&src1[i*src_stride1+4]);\ | ||
745 | b= AV_RN32(&src2[i*src_stride2+4]);\ | ||
746 | OP(*((uint32_t*)&dst[i*dst_stride+4]), no_rnd_avg32(a, b));\ | ||
747 | }\ | ||
748 | }\ | ||
749 | \ | ||
750 | static inline void OPNAME ## _pixels8_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \ | ||
751 | int src_stride1, int src_stride2, int h){\ | ||
752 | int i;\ | ||
753 | for(i=0; i<h; i++){\ | ||
754 | uint32_t a,b;\ | ||
755 | a= AV_RN32(&src1[i*src_stride1 ]);\ | ||
756 | b= AV_RN32(&src2[i*src_stride2 ]);\ | ||
757 | OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\ | ||
758 | a= AV_RN32(&src1[i*src_stride1+4]);\ | ||
759 | b= AV_RN32(&src2[i*src_stride2+4]);\ | ||
760 | OP(*((uint32_t*)&dst[i*dst_stride+4]), rnd_avg32(a, b));\ | ||
761 | }\ | ||
762 | }\ | ||
763 | \ | ||
764 | static inline void OPNAME ## _pixels4_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \ | ||
765 | int src_stride1, int src_stride2, int h){\ | ||
766 | int i;\ | ||
767 | for(i=0; i<h; i++){\ | ||
768 | uint32_t a,b;\ | ||
769 | a= AV_RN32(&src1[i*src_stride1 ]);\ | ||
770 | b= AV_RN32(&src2[i*src_stride2 ]);\ | ||
771 | OP(*((uint32_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\ | ||
772 | }\ | ||
773 | }\ | ||
774 | \ | ||
775 | static inline void OPNAME ## _pixels2_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \ | ||
776 | int src_stride1, int src_stride2, int h){\ | ||
777 | int i;\ | ||
778 | for(i=0; i<h; i++){\ | ||
779 | uint32_t a,b;\ | ||
780 | a= AV_RN16(&src1[i*src_stride1 ]);\ | ||
781 | b= AV_RN16(&src2[i*src_stride2 ]);\ | ||
782 | OP(*((uint16_t*)&dst[i*dst_stride ]), rnd_avg32(a, b));\ | ||
783 | }\ | ||
784 | }\ | ||
785 | \ | ||
786 | static inline void OPNAME ## _pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \ | ||
787 | int src_stride1, int src_stride2, int h){\ | ||
788 | OPNAME ## _pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\ | ||
789 | OPNAME ## _pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\ | ||
790 | }\ | ||
791 | \ | ||
792 | static inline void OPNAME ## _no_rnd_pixels16_l2(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, int dst_stride, \ | ||
793 | int src_stride1, int src_stride2, int h){\ | ||
794 | OPNAME ## _no_rnd_pixels8_l2(dst , src1 , src2 , dst_stride, src_stride1, src_stride2, h);\ | ||
795 | OPNAME ## _no_rnd_pixels8_l2(dst+8, src1+8, src2+8, dst_stride, src_stride1, src_stride2, h);\ | ||
796 | }\ | ||
797 | \ | ||
798 | static inline void OPNAME ## _no_rnd_pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
799 | OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ | ||
800 | }\ | ||
801 | \ | ||
802 | static inline void OPNAME ## _pixels8_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
803 | OPNAME ## _pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ | ||
804 | }\ | ||
805 | \ | ||
806 | static inline void OPNAME ## _no_rnd_pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
807 | OPNAME ## _no_rnd_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ | ||
808 | }\ | ||
809 | \ | ||
810 | static inline void OPNAME ## _pixels8_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
811 | OPNAME ## _pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ | ||
812 | }\ | ||
813 | \ | ||
814 | static inline void OPNAME ## _pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ | ||
815 | int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ | ||
816 | int i;\ | ||
817 | for(i=0; i<h; i++){\ | ||
818 | uint32_t a, b, c, d, l0, l1, h0, h1;\ | ||
819 | a= AV_RN32(&src1[i*src_stride1]);\ | ||
820 | b= AV_RN32(&src2[i*src_stride2]);\ | ||
821 | c= AV_RN32(&src3[i*src_stride3]);\ | ||
822 | d= AV_RN32(&src4[i*src_stride4]);\ | ||
823 | l0= (a&0x03030303UL)\ | ||
824 | + (b&0x03030303UL)\ | ||
825 | + 0x02020202UL;\ | ||
826 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
827 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
828 | l1= (c&0x03030303UL)\ | ||
829 | + (d&0x03030303UL);\ | ||
830 | h1= ((c&0xFCFCFCFCUL)>>2)\ | ||
831 | + ((d&0xFCFCFCFCUL)>>2);\ | ||
832 | OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
833 | a= AV_RN32(&src1[i*src_stride1+4]);\ | ||
834 | b= AV_RN32(&src2[i*src_stride2+4]);\ | ||
835 | c= AV_RN32(&src3[i*src_stride3+4]);\ | ||
836 | d= AV_RN32(&src4[i*src_stride4+4]);\ | ||
837 | l0= (a&0x03030303UL)\ | ||
838 | + (b&0x03030303UL)\ | ||
839 | + 0x02020202UL;\ | ||
840 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
841 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
842 | l1= (c&0x03030303UL)\ | ||
843 | + (d&0x03030303UL);\ | ||
844 | h1= ((c&0xFCFCFCFCUL)>>2)\ | ||
845 | + ((d&0xFCFCFCFCUL)>>2);\ | ||
846 | OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
847 | }\ | ||
848 | }\ | ||
849 | \ | ||
850 | static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
851 | OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ | ||
852 | }\ | ||
853 | \ | ||
854 | static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
855 | OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ | ||
856 | }\ | ||
857 | \ | ||
858 | static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
859 | OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ | ||
860 | }\ | ||
861 | \ | ||
862 | static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
863 | OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ | ||
864 | }\ | ||
865 | \ | ||
866 | static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ | ||
867 | int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ | ||
868 | int i;\ | ||
869 | for(i=0; i<h; i++){\ | ||
870 | uint32_t a, b, c, d, l0, l1, h0, h1;\ | ||
871 | a= AV_RN32(&src1[i*src_stride1]);\ | ||
872 | b= AV_RN32(&src2[i*src_stride2]);\ | ||
873 | c= AV_RN32(&src3[i*src_stride3]);\ | ||
874 | d= AV_RN32(&src4[i*src_stride4]);\ | ||
875 | l0= (a&0x03030303UL)\ | ||
876 | + (b&0x03030303UL)\ | ||
877 | + 0x01010101UL;\ | ||
878 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
879 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
880 | l1= (c&0x03030303UL)\ | ||
881 | + (d&0x03030303UL);\ | ||
882 | h1= ((c&0xFCFCFCFCUL)>>2)\ | ||
883 | + ((d&0xFCFCFCFCUL)>>2);\ | ||
884 | OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
885 | a= AV_RN32(&src1[i*src_stride1+4]);\ | ||
886 | b= AV_RN32(&src2[i*src_stride2+4]);\ | ||
887 | c= AV_RN32(&src3[i*src_stride3+4]);\ | ||
888 | d= AV_RN32(&src4[i*src_stride4+4]);\ | ||
889 | l0= (a&0x03030303UL)\ | ||
890 | + (b&0x03030303UL)\ | ||
891 | + 0x01010101UL;\ | ||
892 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
893 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
894 | l1= (c&0x03030303UL)\ | ||
895 | + (d&0x03030303UL);\ | ||
896 | h1= ((c&0xFCFCFCFCUL)>>2)\ | ||
897 | + ((d&0xFCFCFCFCUL)>>2);\ | ||
898 | OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
899 | }\ | ||
900 | }\ | ||
901 | static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ | ||
902 | int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ | ||
903 | OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ | ||
904 | OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ | ||
905 | }\ | ||
906 | static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, uint8_t *src2, uint8_t *src3, uint8_t *src4,\ | ||
907 | int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ | ||
908 | OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ | ||
909 | OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ | ||
910 | }\ | ||
911 | \ | ||
912 | static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
913 | {\ | ||
914 | int i, a0, b0, a1, b1;\ | ||
915 | a0= pixels[0];\ | ||
916 | b0= pixels[1] + 2;\ | ||
917 | a0 += b0;\ | ||
918 | b0 += pixels[2];\ | ||
919 | \ | ||
920 | pixels+=line_size;\ | ||
921 | for(i=0; i<h; i+=2){\ | ||
922 | a1= pixels[0];\ | ||
923 | b1= pixels[1];\ | ||
924 | a1 += b1;\ | ||
925 | b1 += pixels[2];\ | ||
926 | \ | ||
927 | block[0]= (a1+a0)>>2; /* FIXME non put */\ | ||
928 | block[1]= (b1+b0)>>2;\ | ||
929 | \ | ||
930 | pixels+=line_size;\ | ||
931 | block +=line_size;\ | ||
932 | \ | ||
933 | a0= pixels[0];\ | ||
934 | b0= pixels[1] + 2;\ | ||
935 | a0 += b0;\ | ||
936 | b0 += pixels[2];\ | ||
937 | \ | ||
938 | block[0]= (a1+a0)>>2;\ | ||
939 | block[1]= (b1+b0)>>2;\ | ||
940 | pixels+=line_size;\ | ||
941 | block +=line_size;\ | ||
942 | }\ | ||
943 | }\ | ||
944 | \ | ||
945 | static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
946 | {\ | ||
947 | int i;\ | ||
948 | const uint32_t a= AV_RN32(pixels );\ | ||
949 | const uint32_t b= AV_RN32(pixels+1);\ | ||
950 | uint32_t l0= (a&0x03030303UL)\ | ||
951 | + (b&0x03030303UL)\ | ||
952 | + 0x02020202UL;\ | ||
953 | uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
954 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
955 | uint32_t l1,h1;\ | ||
956 | \ | ||
957 | pixels+=line_size;\ | ||
958 | for(i=0; i<h; i+=2){\ | ||
959 | uint32_t a= AV_RN32(pixels );\ | ||
960 | uint32_t b= AV_RN32(pixels+1);\ | ||
961 | l1= (a&0x03030303UL)\ | ||
962 | + (b&0x03030303UL);\ | ||
963 | h1= ((a&0xFCFCFCFCUL)>>2)\ | ||
964 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
965 | OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
966 | pixels+=line_size;\ | ||
967 | block +=line_size;\ | ||
968 | a= AV_RN32(pixels );\ | ||
969 | b= AV_RN32(pixels+1);\ | ||
970 | l0= (a&0x03030303UL)\ | ||
971 | + (b&0x03030303UL)\ | ||
972 | + 0x02020202UL;\ | ||
973 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
974 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
975 | OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
976 | pixels+=line_size;\ | ||
977 | block +=line_size;\ | ||
978 | }\ | ||
979 | }\ | ||
980 | \ | ||
981 | static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
982 | {\ | ||
983 | int j;\ | ||
984 | for(j=0; j<2; j++){\ | ||
985 | int i;\ | ||
986 | const uint32_t a= AV_RN32(pixels );\ | ||
987 | const uint32_t b= AV_RN32(pixels+1);\ | ||
988 | uint32_t l0= (a&0x03030303UL)\ | ||
989 | + (b&0x03030303UL)\ | ||
990 | + 0x02020202UL;\ | ||
991 | uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
992 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
993 | uint32_t l1,h1;\ | ||
994 | \ | ||
995 | pixels+=line_size;\ | ||
996 | for(i=0; i<h; i+=2){\ | ||
997 | uint32_t a= AV_RN32(pixels );\ | ||
998 | uint32_t b= AV_RN32(pixels+1);\ | ||
999 | l1= (a&0x03030303UL)\ | ||
1000 | + (b&0x03030303UL);\ | ||
1001 | h1= ((a&0xFCFCFCFCUL)>>2)\ | ||
1002 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
1003 | OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
1004 | pixels+=line_size;\ | ||
1005 | block +=line_size;\ | ||
1006 | a= AV_RN32(pixels );\ | ||
1007 | b= AV_RN32(pixels+1);\ | ||
1008 | l0= (a&0x03030303UL)\ | ||
1009 | + (b&0x03030303UL)\ | ||
1010 | + 0x02020202UL;\ | ||
1011 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
1012 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
1013 | OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
1014 | pixels+=line_size;\ | ||
1015 | block +=line_size;\ | ||
1016 | }\ | ||
1017 | pixels+=4-line_size*(h+1);\ | ||
1018 | block +=4-line_size*h;\ | ||
1019 | }\ | ||
1020 | }\ | ||
1021 | \ | ||
1022 | static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ | ||
1023 | {\ | ||
1024 | int j;\ | ||
1025 | for(j=0; j<2; j++){\ | ||
1026 | int i;\ | ||
1027 | const uint32_t a= AV_RN32(pixels );\ | ||
1028 | const uint32_t b= AV_RN32(pixels+1);\ | ||
1029 | uint32_t l0= (a&0x03030303UL)\ | ||
1030 | + (b&0x03030303UL)\ | ||
1031 | + 0x01010101UL;\ | ||
1032 | uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
1033 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
1034 | uint32_t l1,h1;\ | ||
1035 | \ | ||
1036 | pixels+=line_size;\ | ||
1037 | for(i=0; i<h; i+=2){\ | ||
1038 | uint32_t a= AV_RN32(pixels );\ | ||
1039 | uint32_t b= AV_RN32(pixels+1);\ | ||
1040 | l1= (a&0x03030303UL)\ | ||
1041 | + (b&0x03030303UL);\ | ||
1042 | h1= ((a&0xFCFCFCFCUL)>>2)\ | ||
1043 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
1044 | OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
1045 | pixels+=line_size;\ | ||
1046 | block +=line_size;\ | ||
1047 | a= AV_RN32(pixels );\ | ||
1048 | b= AV_RN32(pixels+1);\ | ||
1049 | l0= (a&0x03030303UL)\ | ||
1050 | + (b&0x03030303UL)\ | ||
1051 | + 0x01010101UL;\ | ||
1052 | h0= ((a&0xFCFCFCFCUL)>>2)\ | ||
1053 | + ((b&0xFCFCFCFCUL)>>2);\ | ||
1054 | OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ | ||
1055 | pixels+=line_size;\ | ||
1056 | block +=line_size;\ | ||
1057 | }\ | ||
1058 | pixels+=4-line_size*(h+1);\ | ||
1059 | block +=4-line_size*h;\ | ||
1060 | }\ | ||
1061 | }\ | ||
1062 | \ | ||
1063 | CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\ | ||
1064 | CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\ | ||
1065 | CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\ | ||
1066 | CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\ | ||
1067 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\ | ||
1068 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\ | ||
1069 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\ | ||
1070 | CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\ | ||
1071 | |||
1072 | #define op_avg(a, b) a = rnd_avg32(a, b) | ||
1073 | #endif | ||
1074 | #define op_put(a, b) a = b | ||
1075 | |||
1076 | PIXOP2(avg, op_avg) | ||
1077 | PIXOP2(put, op_put) | ||
1078 | #undef op_avg | ||
1079 | #undef op_put | ||
1080 | |||
1081 | #define avg2(a,b) ((a+b+1)>>1) | ||
1082 | #define avg4(a,b,c,d) ((a+b+c+d+2)>>2) | ||
1083 | |||
1084 | static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ | ||
1085 | put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h); | ||
1086 | } | ||
1087 | |||
1088 | static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ | ||
1089 | put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h); | ||
1090 | } | ||
1091 | |||
1092 | static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder) | ||
1093 | { | ||
1094 | const int A=(16-x16)*(16-y16); | ||
1095 | const int B=( x16)*(16-y16); | ||
1096 | const int C=(16-x16)*( y16); | ||
1097 | const int D=( x16)*( y16); | ||
1098 | int i; | ||
1099 | |||
1100 | for(i=0; i<h; i++) | ||
1101 | { | ||
1102 | dst[0]= (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + rounder)>>8; | ||
1103 | dst[1]= (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + rounder)>>8; | ||
1104 | dst[2]= (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + rounder)>>8; | ||
1105 | dst[3]= (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + rounder)>>8; | ||
1106 | dst[4]= (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + rounder)>>8; | ||
1107 | dst[5]= (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + rounder)>>8; | ||
1108 | dst[6]= (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + rounder)>>8; | ||
1109 | dst[7]= (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + rounder)>>8; | ||
1110 | dst+= stride; | ||
1111 | src+= stride; | ||
1112 | } | ||
1113 | } | ||
1114 | |||
1115 | void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, | ||
1116 | int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height) | ||
1117 | { | ||
1118 | int y, vx, vy; | ||
1119 | const int s= 1<<shift; | ||
1120 | |||
1121 | width--; | ||
1122 | height--; | ||
1123 | |||
1124 | for(y=0; y<h; y++){ | ||
1125 | int x; | ||
1126 | |||
1127 | vx= ox; | ||
1128 | vy= oy; | ||
1129 | for(x=0; x<8; x++){ //XXX FIXME optimize | ||
1130 | int src_x, src_y, frac_x, frac_y, index; | ||
1131 | |||
1132 | src_x= vx>>16; | ||
1133 | src_y= vy>>16; | ||
1134 | frac_x= src_x&(s-1); | ||
1135 | frac_y= src_y&(s-1); | ||
1136 | src_x>>=shift; | ||
1137 | src_y>>=shift; | ||
1138 | |||
1139 | if((unsigned)src_x < width){ | ||
1140 | if((unsigned)src_y < height){ | ||
1141 | index= src_x + src_y*stride; | ||
1142 | dst[y*stride + x]= ( ( src[index ]*(s-frac_x) | ||
1143 | + src[index +1]* frac_x )*(s-frac_y) | ||
1144 | + ( src[index+stride ]*(s-frac_x) | ||
1145 | + src[index+stride+1]* frac_x )* frac_y | ||
1146 | + r)>>(shift*2); | ||
1147 | }else{ | ||
1148 | index= src_x + av_clip(src_y, 0, height)*stride; | ||
1149 | dst[y*stride + x]= ( ( src[index ]*(s-frac_x) | ||
1150 | + src[index +1]* frac_x )*s | ||
1151 | + r)>>(shift*2); | ||
1152 | } | ||
1153 | }else{ | ||
1154 | if((unsigned)src_y < height){ | ||
1155 | index= av_clip(src_x, 0, width) + src_y*stride; | ||
1156 | dst[y*stride + x]= ( ( src[index ]*(s-frac_y) | ||
1157 | + src[index+stride ]* frac_y )*s | ||
1158 | + r)>>(shift*2); | ||
1159 | }else{ | ||
1160 | index= av_clip(src_x, 0, width) + av_clip(src_y, 0, height)*stride; | ||
1161 | dst[y*stride + x]= src[index ]; | ||
1162 | } | ||
1163 | } | ||
1164 | |||
1165 | vx+= dxx; | ||
1166 | vy+= dyx; | ||
1167 | } | ||
1168 | ox += dxy; | ||
1169 | oy += dyy; | ||
1170 | } | ||
1171 | } | ||
1172 | |||
1173 | static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1174 | switch(width){ | ||
1175 | case 2: put_pixels2_c (dst, src, stride, height); break; | ||
1176 | case 4: put_pixels4_c (dst, src, stride, height); break; | ||
1177 | case 8: put_pixels8_c (dst, src, stride, height); break; | ||
1178 | case 16:put_pixels16_c(dst, src, stride, height); break; | ||
1179 | } | ||
1180 | } | ||
1181 | |||
1182 | static inline void put_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1183 | int i,j; | ||
1184 | for (i=0; i < height; i++) { | ||
1185 | for (j=0; j < width; j++) { | ||
1186 | dst[j] = (683*(2*src[j] + src[j+1] + 1)) >> 11; | ||
1187 | } | ||
1188 | src += stride; | ||
1189 | dst += stride; | ||
1190 | } | ||
1191 | } | ||
1192 | |||
1193 | static inline void put_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1194 | int i,j; | ||
1195 | for (i=0; i < height; i++) { | ||
1196 | for (j=0; j < width; j++) { | ||
1197 | dst[j] = (683*(src[j] + 2*src[j+1] + 1)) >> 11; | ||
1198 | } | ||
1199 | src += stride; | ||
1200 | dst += stride; | ||
1201 | } | ||
1202 | } | ||
1203 | |||
1204 | static inline void put_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1205 | int i,j; | ||
1206 | for (i=0; i < height; i++) { | ||
1207 | for (j=0; j < width; j++) { | ||
1208 | dst[j] = (683*(2*src[j] + src[j+stride] + 1)) >> 11; | ||
1209 | } | ||
1210 | src += stride; | ||
1211 | dst += stride; | ||
1212 | } | ||
1213 | } | ||
1214 | |||
1215 | static inline void put_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1216 | int i,j; | ||
1217 | for (i=0; i < height; i++) { | ||
1218 | for (j=0; j < width; j++) { | ||
1219 | dst[j] = (2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15; | ||
1220 | } | ||
1221 | src += stride; | ||
1222 | dst += stride; | ||
1223 | } | ||
1224 | } | ||
1225 | |||
1226 | static inline void put_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1227 | int i,j; | ||
1228 | for (i=0; i < height; i++) { | ||
1229 | for (j=0; j < width; j++) { | ||
1230 | dst[j] = (2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15; | ||
1231 | } | ||
1232 | src += stride; | ||
1233 | dst += stride; | ||
1234 | } | ||
1235 | } | ||
1236 | |||
1237 | static inline void put_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1238 | int i,j; | ||
1239 | for (i=0; i < height; i++) { | ||
1240 | for (j=0; j < width; j++) { | ||
1241 | dst[j] = (683*(src[j] + 2*src[j+stride] + 1)) >> 11; | ||
1242 | } | ||
1243 | src += stride; | ||
1244 | dst += stride; | ||
1245 | } | ||
1246 | } | ||
1247 | |||
1248 | static inline void put_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1249 | int i,j; | ||
1250 | for (i=0; i < height; i++) { | ||
1251 | for (j=0; j < width; j++) { | ||
1252 | dst[j] = (2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15; | ||
1253 | } | ||
1254 | src += stride; | ||
1255 | dst += stride; | ||
1256 | } | ||
1257 | } | ||
1258 | |||
1259 | static inline void put_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1260 | int i,j; | ||
1261 | for (i=0; i < height; i++) { | ||
1262 | for (j=0; j < width; j++) { | ||
1263 | dst[j] = (2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15; | ||
1264 | } | ||
1265 | src += stride; | ||
1266 | dst += stride; | ||
1267 | } | ||
1268 | } | ||
1269 | |||
1270 | static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1271 | switch(width){ | ||
1272 | case 2: avg_pixels2_c (dst, src, stride, height); break; | ||
1273 | case 4: avg_pixels4_c (dst, src, stride, height); break; | ||
1274 | case 8: avg_pixels8_c (dst, src, stride, height); break; | ||
1275 | case 16:avg_pixels16_c(dst, src, stride, height); break; | ||
1276 | } | ||
1277 | } | ||
1278 | |||
1279 | static inline void avg_tpel_pixels_mc10_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1280 | int i,j; | ||
1281 | for (i=0; i < height; i++) { | ||
1282 | for (j=0; j < width; j++) { | ||
1283 | dst[j] = (dst[j] + ((683*(2*src[j] + src[j+1] + 1)) >> 11) + 1) >> 1; | ||
1284 | } | ||
1285 | src += stride; | ||
1286 | dst += stride; | ||
1287 | } | ||
1288 | } | ||
1289 | |||
1290 | static inline void avg_tpel_pixels_mc20_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1291 | int i,j; | ||
1292 | for (i=0; i < height; i++) { | ||
1293 | for (j=0; j < width; j++) { | ||
1294 | dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+1] + 1)) >> 11) + 1) >> 1; | ||
1295 | } | ||
1296 | src += stride; | ||
1297 | dst += stride; | ||
1298 | } | ||
1299 | } | ||
1300 | |||
1301 | static inline void avg_tpel_pixels_mc01_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1302 | int i,j; | ||
1303 | for (i=0; i < height; i++) { | ||
1304 | for (j=0; j < width; j++) { | ||
1305 | dst[j] = (dst[j] + ((683*(2*src[j] + src[j+stride] + 1)) >> 11) + 1) >> 1; | ||
1306 | } | ||
1307 | src += stride; | ||
1308 | dst += stride; | ||
1309 | } | ||
1310 | } | ||
1311 | |||
1312 | static inline void avg_tpel_pixels_mc11_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1313 | int i,j; | ||
1314 | for (i=0; i < height; i++) { | ||
1315 | for (j=0; j < width; j++) { | ||
1316 | dst[j] = (dst[j] + ((2731*(4*src[j] + 3*src[j+1] + 3*src[j+stride] + 2*src[j+stride+1] + 6)) >> 15) + 1) >> 1; | ||
1317 | } | ||
1318 | src += stride; | ||
1319 | dst += stride; | ||
1320 | } | ||
1321 | } | ||
1322 | |||
1323 | static inline void avg_tpel_pixels_mc12_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1324 | int i,j; | ||
1325 | for (i=0; i < height; i++) { | ||
1326 | for (j=0; j < width; j++) { | ||
1327 | dst[j] = (dst[j] + ((2731*(3*src[j] + 2*src[j+1] + 4*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1; | ||
1328 | } | ||
1329 | src += stride; | ||
1330 | dst += stride; | ||
1331 | } | ||
1332 | } | ||
1333 | |||
1334 | static inline void avg_tpel_pixels_mc02_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1335 | int i,j; | ||
1336 | for (i=0; i < height; i++) { | ||
1337 | for (j=0; j < width; j++) { | ||
1338 | dst[j] = (dst[j] + ((683*(src[j] + 2*src[j+stride] + 1)) >> 11) + 1) >> 1; | ||
1339 | } | ||
1340 | src += stride; | ||
1341 | dst += stride; | ||
1342 | } | ||
1343 | } | ||
1344 | |||
1345 | static inline void avg_tpel_pixels_mc21_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1346 | int i,j; | ||
1347 | for (i=0; i < height; i++) { | ||
1348 | for (j=0; j < width; j++) { | ||
1349 | dst[j] = (dst[j] + ((2731*(3*src[j] + 4*src[j+1] + 2*src[j+stride] + 3*src[j+stride+1] + 6)) >> 15) + 1) >> 1; | ||
1350 | } | ||
1351 | src += stride; | ||
1352 | dst += stride; | ||
1353 | } | ||
1354 | } | ||
1355 | |||
1356 | static inline void avg_tpel_pixels_mc22_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ | ||
1357 | int i,j; | ||
1358 | for (i=0; i < height; i++) { | ||
1359 | for (j=0; j < width; j++) { | ||
1360 | dst[j] = (dst[j] + ((2731*(2*src[j] + 3*src[j+1] + 3*src[j+stride] + 4*src[j+stride+1] + 6)) >> 15) + 1) >> 1; | ||
1361 | } | ||
1362 | src += stride; | ||
1363 | dst += stride; | ||
1364 | } | ||
1365 | } | ||
1366 | #if 0 | ||
1367 | #define TPEL_WIDTH(width)\ | ||
1368 | static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1369 | void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\ | ||
1370 | static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1371 | void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\ | ||
1372 | static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1373 | void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\ | ||
1374 | static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1375 | void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\ | ||
1376 | static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1377 | void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\ | ||
1378 | static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1379 | void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\ | ||
1380 | static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1381 | void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\ | ||
1382 | static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1383 | void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\ | ||
1384 | static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ | ||
1385 | void put_tpel_pixels_mc22_c(dst, src, stride, width, height);} | ||
1386 | #endif | ||
1387 | |||
1388 | #define H264_CHROMA_MC(OPNAME, OP)\ | ||
1389 | static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ | ||
1390 | const int A=(8-x)*(8-y);\ | ||
1391 | const int B=( x)*(8-y);\ | ||
1392 | const int C=(8-x)*( y);\ | ||
1393 | const int D=( x)*( y);\ | ||
1394 | int i;\ | ||
1395 | \ | ||
1396 | assert(x<8 && y<8 && x>=0 && y>=0);\ | ||
1397 | \ | ||
1398 | if(D){\ | ||
1399 | for(i=0; i<h; i++){\ | ||
1400 | OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\ | ||
1401 | OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\ | ||
1402 | dst+= stride;\ | ||
1403 | src+= stride;\ | ||
1404 | }\ | ||
1405 | }else{\ | ||
1406 | const int E= B+C;\ | ||
1407 | const int step= C ? stride : 1;\ | ||
1408 | for(i=0; i<h; i++){\ | ||
1409 | OP(dst[0], (A*src[0] + E*src[step+0]));\ | ||
1410 | OP(dst[1], (A*src[1] + E*src[step+1]));\ | ||
1411 | dst+= stride;\ | ||
1412 | src+= stride;\ | ||
1413 | }\ | ||
1414 | }\ | ||
1415 | }\ | ||
1416 | \ | ||
1417 | static void OPNAME ## h264_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ | ||
1418 | const int A=(8-x)*(8-y);\ | ||
1419 | const int B=( x)*(8-y);\ | ||
1420 | const int C=(8-x)*( y);\ | ||
1421 | const int D=( x)*( y);\ | ||
1422 | int i;\ | ||
1423 | \ | ||
1424 | assert(x<8 && y<8 && x>=0 && y>=0);\ | ||
1425 | \ | ||
1426 | if(D){\ | ||
1427 | for(i=0; i<h; i++){\ | ||
1428 | OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\ | ||
1429 | OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\ | ||
1430 | OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\ | ||
1431 | OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\ | ||
1432 | dst+= stride;\ | ||
1433 | src+= stride;\ | ||
1434 | }\ | ||
1435 | }else{\ | ||
1436 | const int E= B+C;\ | ||
1437 | const int step= C ? stride : 1;\ | ||
1438 | for(i=0; i<h; i++){\ | ||
1439 | OP(dst[0], (A*src[0] + E*src[step+0]));\ | ||
1440 | OP(dst[1], (A*src[1] + E*src[step+1]));\ | ||
1441 | OP(dst[2], (A*src[2] + E*src[step+2]));\ | ||
1442 | OP(dst[3], (A*src[3] + E*src[step+3]));\ | ||
1443 | dst+= stride;\ | ||
1444 | src+= stride;\ | ||
1445 | }\ | ||
1446 | }\ | ||
1447 | }\ | ||
1448 | \ | ||
1449 | static void OPNAME ## h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ | ||
1450 | const int A=(8-x)*(8-y);\ | ||
1451 | const int B=( x)*(8-y);\ | ||
1452 | const int C=(8-x)*( y);\ | ||
1453 | const int D=( x)*( y);\ | ||
1454 | int i;\ | ||
1455 | \ | ||
1456 | assert(x<8 && y<8 && x>=0 && y>=0);\ | ||
1457 | \ | ||
1458 | if(D){\ | ||
1459 | for(i=0; i<h; i++){\ | ||
1460 | OP(dst[0], (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1]));\ | ||
1461 | OP(dst[1], (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2]));\ | ||
1462 | OP(dst[2], (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3]));\ | ||
1463 | OP(dst[3], (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4]));\ | ||
1464 | OP(dst[4], (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5]));\ | ||
1465 | OP(dst[5], (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6]));\ | ||
1466 | OP(dst[6], (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7]));\ | ||
1467 | OP(dst[7], (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8]));\ | ||
1468 | dst+= stride;\ | ||
1469 | src+= stride;\ | ||
1470 | }\ | ||
1471 | }else{\ | ||
1472 | const int E= B+C;\ | ||
1473 | const int step= C ? stride : 1;\ | ||
1474 | for(i=0; i<h; i++){\ | ||
1475 | OP(dst[0], (A*src[0] + E*src[step+0]));\ | ||
1476 | OP(dst[1], (A*src[1] + E*src[step+1]));\ | ||
1477 | OP(dst[2], (A*src[2] + E*src[step+2]));\ | ||
1478 | OP(dst[3], (A*src[3] + E*src[step+3]));\ | ||
1479 | OP(dst[4], (A*src[4] + E*src[step+4]));\ | ||
1480 | OP(dst[5], (A*src[5] + E*src[step+5]));\ | ||
1481 | OP(dst[6], (A*src[6] + E*src[step+6]));\ | ||
1482 | OP(dst[7], (A*src[7] + E*src[step+7]));\ | ||
1483 | dst+= stride;\ | ||
1484 | src+= stride;\ | ||
1485 | }\ | ||
1486 | }\ | ||
1487 | } | ||
1488 | |||
1489 | #define op_avg(a, b) a = (((a)+(((b) + 32)>>6)+1)>>1) | ||
1490 | #define op_put(a, b) a = (((b) + 32)>>6) | ||
1491 | |||
1492 | H264_CHROMA_MC(put_ , op_put) | ||
1493 | H264_CHROMA_MC(avg_ , op_avg) | ||
1494 | #undef op_avg | ||
1495 | #undef op_put | ||
1496 | |||
1497 | static void put_no_rnd_h264_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ | ||
1498 | const int A=(8-x)*(8-y); | ||
1499 | const int B=( x)*(8-y); | ||
1500 | const int C=(8-x)*( y); | ||
1501 | const int D=( x)*( y); | ||
1502 | int i; | ||
1503 | |||
1504 | assert(x<8 && y<8 && x>=0 && y>=0); | ||
1505 | |||
1506 | for(i=0; i<h; i++) | ||
1507 | { | ||
1508 | dst[0] = (A*src[0] + B*src[1] + C*src[stride+0] + D*src[stride+1] + 32 - 4) >> 6; | ||
1509 | dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6; | ||
1510 | dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6; | ||
1511 | dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6; | ||
1512 | dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6; | ||
1513 | dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6; | ||
1514 | dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6; | ||
1515 | dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6; | ||
1516 | dst+= stride; | ||
1517 | src+= stride; | ||
1518 | } | ||
1519 | } | ||
1520 | |||
1521 | #define QPEL_MC(r, OPNAME, RND, OP) \ | ||
1522 | static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ | ||
1523 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
1524 | int i;\ | ||
1525 | for(i=0; i<h; i++)\ | ||
1526 | {\ | ||
1527 | OP(dst[0], (src[0]+src[1])*20 - (src[0]+src[2])*6 + (src[1]+src[3])*3 - (src[2]+src[4]));\ | ||
1528 | OP(dst[1], (src[1]+src[2])*20 - (src[0]+src[3])*6 + (src[0]+src[4])*3 - (src[1]+src[5]));\ | ||
1529 | OP(dst[2], (src[2]+src[3])*20 - (src[1]+src[4])*6 + (src[0]+src[5])*3 - (src[0]+src[6]));\ | ||
1530 | OP(dst[3], (src[3]+src[4])*20 - (src[2]+src[5])*6 + (src[1]+src[6])*3 - (src[0]+src[7]));\ | ||
1531 | OP(dst[4], (src[4]+src[5])*20 - (src[3]+src[6])*6 + (src[2]+src[7])*3 - (src[1]+src[8]));\ | ||
1532 | OP(dst[5], (src[5]+src[6])*20 - (src[4]+src[7])*6 + (src[3]+src[8])*3 - (src[2]+src[8]));\ | ||
1533 | OP(dst[6], (src[6]+src[7])*20 - (src[5]+src[8])*6 + (src[4]+src[8])*3 - (src[3]+src[7]));\ | ||
1534 | OP(dst[7], (src[7]+src[8])*20 - (src[6]+src[8])*6 + (src[5]+src[7])*3 - (src[4]+src[6]));\ | ||
1535 | dst+=dstStride;\ | ||
1536 | src+=srcStride;\ | ||
1537 | }\ | ||
1538 | }\ | ||
1539 | \ | ||
1540 | static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
1541 | const int w=8;\ | ||
1542 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
1543 | int i;\ | ||
1544 | for(i=0; i<w; i++)\ | ||
1545 | {\ | ||
1546 | const int src0= src[0*srcStride];\ | ||
1547 | const int src1= src[1*srcStride];\ | ||
1548 | const int src2= src[2*srcStride];\ | ||
1549 | const int src3= src[3*srcStride];\ | ||
1550 | const int src4= src[4*srcStride];\ | ||
1551 | const int src5= src[5*srcStride];\ | ||
1552 | const int src6= src[6*srcStride];\ | ||
1553 | const int src7= src[7*srcStride];\ | ||
1554 | const int src8= src[8*srcStride];\ | ||
1555 | OP(dst[0*dstStride], (src0+src1)*20 - (src0+src2)*6 + (src1+src3)*3 - (src2+src4));\ | ||
1556 | OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*6 + (src0+src4)*3 - (src1+src5));\ | ||
1557 | OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*6 + (src0+src5)*3 - (src0+src6));\ | ||
1558 | OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*6 + (src1+src6)*3 - (src0+src7));\ | ||
1559 | OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*6 + (src2+src7)*3 - (src1+src8));\ | ||
1560 | OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*6 + (src3+src8)*3 - (src2+src8));\ | ||
1561 | OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*6 + (src4+src8)*3 - (src3+src7));\ | ||
1562 | OP(dst[7*dstStride], (src7+src8)*20 - (src6+src8)*6 + (src5+src7)*3 - (src4+src6));\ | ||
1563 | dst++;\ | ||
1564 | src++;\ | ||
1565 | }\ | ||
1566 | }\ | ||
1567 | \ | ||
1568 | static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ | ||
1569 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
1570 | int i;\ | ||
1571 | \ | ||
1572 | for(i=0; i<h; i++)\ | ||
1573 | {\ | ||
1574 | OP(dst[ 0], (src[ 0]+src[ 1])*20 - (src[ 0]+src[ 2])*6 + (src[ 1]+src[ 3])*3 - (src[ 2]+src[ 4]));\ | ||
1575 | OP(dst[ 1], (src[ 1]+src[ 2])*20 - (src[ 0]+src[ 3])*6 + (src[ 0]+src[ 4])*3 - (src[ 1]+src[ 5]));\ | ||
1576 | OP(dst[ 2], (src[ 2]+src[ 3])*20 - (src[ 1]+src[ 4])*6 + (src[ 0]+src[ 5])*3 - (src[ 0]+src[ 6]));\ | ||
1577 | OP(dst[ 3], (src[ 3]+src[ 4])*20 - (src[ 2]+src[ 5])*6 + (src[ 1]+src[ 6])*3 - (src[ 0]+src[ 7]));\ | ||
1578 | OP(dst[ 4], (src[ 4]+src[ 5])*20 - (src[ 3]+src[ 6])*6 + (src[ 2]+src[ 7])*3 - (src[ 1]+src[ 8]));\ | ||
1579 | OP(dst[ 5], (src[ 5]+src[ 6])*20 - (src[ 4]+src[ 7])*6 + (src[ 3]+src[ 8])*3 - (src[ 2]+src[ 9]));\ | ||
1580 | OP(dst[ 6], (src[ 6]+src[ 7])*20 - (src[ 5]+src[ 8])*6 + (src[ 4]+src[ 9])*3 - (src[ 3]+src[10]));\ | ||
1581 | OP(dst[ 7], (src[ 7]+src[ 8])*20 - (src[ 6]+src[ 9])*6 + (src[ 5]+src[10])*3 - (src[ 4]+src[11]));\ | ||
1582 | OP(dst[ 8], (src[ 8]+src[ 9])*20 - (src[ 7]+src[10])*6 + (src[ 6]+src[11])*3 - (src[ 5]+src[12]));\ | ||
1583 | OP(dst[ 9], (src[ 9]+src[10])*20 - (src[ 8]+src[11])*6 + (src[ 7]+src[12])*3 - (src[ 6]+src[13]));\ | ||
1584 | OP(dst[10], (src[10]+src[11])*20 - (src[ 9]+src[12])*6 + (src[ 8]+src[13])*3 - (src[ 7]+src[14]));\ | ||
1585 | OP(dst[11], (src[11]+src[12])*20 - (src[10]+src[13])*6 + (src[ 9]+src[14])*3 - (src[ 8]+src[15]));\ | ||
1586 | OP(dst[12], (src[12]+src[13])*20 - (src[11]+src[14])*6 + (src[10]+src[15])*3 - (src[ 9]+src[16]));\ | ||
1587 | OP(dst[13], (src[13]+src[14])*20 - (src[12]+src[15])*6 + (src[11]+src[16])*3 - (src[10]+src[16]));\ | ||
1588 | OP(dst[14], (src[14]+src[15])*20 - (src[13]+src[16])*6 + (src[12]+src[16])*3 - (src[11]+src[15]));\ | ||
1589 | OP(dst[15], (src[15]+src[16])*20 - (src[14]+src[16])*6 + (src[13]+src[15])*3 - (src[12]+src[14]));\ | ||
1590 | dst+=dstStride;\ | ||
1591 | src+=srcStride;\ | ||
1592 | }\ | ||
1593 | }\ | ||
1594 | \ | ||
1595 | static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
1596 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
1597 | int i;\ | ||
1598 | const int w=16;\ | ||
1599 | for(i=0; i<w; i++)\ | ||
1600 | {\ | ||
1601 | const int src0= src[0*srcStride];\ | ||
1602 | const int src1= src[1*srcStride];\ | ||
1603 | const int src2= src[2*srcStride];\ | ||
1604 | const int src3= src[3*srcStride];\ | ||
1605 | const int src4= src[4*srcStride];\ | ||
1606 | const int src5= src[5*srcStride];\ | ||
1607 | const int src6= src[6*srcStride];\ | ||
1608 | const int src7= src[7*srcStride];\ | ||
1609 | const int src8= src[8*srcStride];\ | ||
1610 | const int src9= src[9*srcStride];\ | ||
1611 | const int src10= src[10*srcStride];\ | ||
1612 | const int src11= src[11*srcStride];\ | ||
1613 | const int src12= src[12*srcStride];\ | ||
1614 | const int src13= src[13*srcStride];\ | ||
1615 | const int src14= src[14*srcStride];\ | ||
1616 | const int src15= src[15*srcStride];\ | ||
1617 | const int src16= src[16*srcStride];\ | ||
1618 | OP(dst[ 0*dstStride], (src0 +src1 )*20 - (src0 +src2 )*6 + (src1 +src3 )*3 - (src2 +src4 ));\ | ||
1619 | OP(dst[ 1*dstStride], (src1 +src2 )*20 - (src0 +src3 )*6 + (src0 +src4 )*3 - (src1 +src5 ));\ | ||
1620 | OP(dst[ 2*dstStride], (src2 +src3 )*20 - (src1 +src4 )*6 + (src0 +src5 )*3 - (src0 +src6 ));\ | ||
1621 | OP(dst[ 3*dstStride], (src3 +src4 )*20 - (src2 +src5 )*6 + (src1 +src6 )*3 - (src0 +src7 ));\ | ||
1622 | OP(dst[ 4*dstStride], (src4 +src5 )*20 - (src3 +src6 )*6 + (src2 +src7 )*3 - (src1 +src8 ));\ | ||
1623 | OP(dst[ 5*dstStride], (src5 +src6 )*20 - (src4 +src7 )*6 + (src3 +src8 )*3 - (src2 +src9 ));\ | ||
1624 | OP(dst[ 6*dstStride], (src6 +src7 )*20 - (src5 +src8 )*6 + (src4 +src9 )*3 - (src3 +src10));\ | ||
1625 | OP(dst[ 7*dstStride], (src7 +src8 )*20 - (src6 +src9 )*6 + (src5 +src10)*3 - (src4 +src11));\ | ||
1626 | OP(dst[ 8*dstStride], (src8 +src9 )*20 - (src7 +src10)*6 + (src6 +src11)*3 - (src5 +src12));\ | ||
1627 | OP(dst[ 9*dstStride], (src9 +src10)*20 - (src8 +src11)*6 + (src7 +src12)*3 - (src6 +src13));\ | ||
1628 | OP(dst[10*dstStride], (src10+src11)*20 - (src9 +src12)*6 + (src8 +src13)*3 - (src7 +src14));\ | ||
1629 | OP(dst[11*dstStride], (src11+src12)*20 - (src10+src13)*6 + (src9 +src14)*3 - (src8 +src15));\ | ||
1630 | OP(dst[12*dstStride], (src12+src13)*20 - (src11+src14)*6 + (src10+src15)*3 - (src9 +src16));\ | ||
1631 | OP(dst[13*dstStride], (src13+src14)*20 - (src12+src15)*6 + (src11+src16)*3 - (src10+src16));\ | ||
1632 | OP(dst[14*dstStride], (src14+src15)*20 - (src13+src16)*6 + (src12+src16)*3 - (src11+src15));\ | ||
1633 | OP(dst[15*dstStride], (src15+src16)*20 - (src14+src16)*6 + (src13+src15)*3 - (src12+src14));\ | ||
1634 | dst++;\ | ||
1635 | src++;\ | ||
1636 | }\ | ||
1637 | }\ | ||
1638 | \ | ||
1639 | static void OPNAME ## qpel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){\ | ||
1640 | OPNAME ## pixels8_c(dst, src, stride, 8);\ | ||
1641 | }\ | ||
1642 | \ | ||
1643 | static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1644 | uint8_t half[64];\ | ||
1645 | put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\ | ||
1646 | OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\ | ||
1647 | }\ | ||
1648 | \ | ||
1649 | static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1650 | OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);\ | ||
1651 | }\ | ||
1652 | \ | ||
1653 | static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1654 | uint8_t half[64];\ | ||
1655 | put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\ | ||
1656 | OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\ | ||
1657 | }\ | ||
1658 | \ | ||
1659 | static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1660 | uint8_t full[16*9];\ | ||
1661 | uint8_t half[64];\ | ||
1662 | copy_block9(full, src, 16, stride, 9);\ | ||
1663 | put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\ | ||
1664 | OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\ | ||
1665 | }\ | ||
1666 | \ | ||
1667 | static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1668 | uint8_t full[16*9];\ | ||
1669 | copy_block9(full, src, 16, stride, 9);\ | ||
1670 | OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);\ | ||
1671 | }\ | ||
1672 | \ | ||
1673 | static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1674 | uint8_t full[16*9];\ | ||
1675 | uint8_t half[64];\ | ||
1676 | copy_block9(full, src, 16, stride, 9);\ | ||
1677 | put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\ | ||
1678 | OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\ | ||
1679 | }\ | ||
1680 | void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1681 | uint8_t full[16*9];\ | ||
1682 | uint8_t halfH[72];\ | ||
1683 | uint8_t halfV[64];\ | ||
1684 | uint8_t halfHV[64];\ | ||
1685 | copy_block9(full, src, 16, stride, 9);\ | ||
1686 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1687 | put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\ | ||
1688 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1689 | OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ | ||
1690 | }\ | ||
1691 | static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1692 | uint8_t full[16*9];\ | ||
1693 | uint8_t halfH[72];\ | ||
1694 | uint8_t halfHV[64];\ | ||
1695 | copy_block9(full, src, 16, stride, 9);\ | ||
1696 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1697 | put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\ | ||
1698 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1699 | OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\ | ||
1700 | }\ | ||
1701 | void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1702 | uint8_t full[16*9];\ | ||
1703 | uint8_t halfH[72];\ | ||
1704 | uint8_t halfV[64];\ | ||
1705 | uint8_t halfHV[64];\ | ||
1706 | copy_block9(full, src, 16, stride, 9);\ | ||
1707 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1708 | put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\ | ||
1709 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1710 | OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ | ||
1711 | }\ | ||
1712 | static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1713 | uint8_t full[16*9];\ | ||
1714 | uint8_t halfH[72];\ | ||
1715 | uint8_t halfHV[64];\ | ||
1716 | copy_block9(full, src, 16, stride, 9);\ | ||
1717 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1718 | put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\ | ||
1719 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1720 | OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\ | ||
1721 | }\ | ||
1722 | void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1723 | uint8_t full[16*9];\ | ||
1724 | uint8_t halfH[72];\ | ||
1725 | uint8_t halfV[64];\ | ||
1726 | uint8_t halfHV[64];\ | ||
1727 | copy_block9(full, src, 16, stride, 9);\ | ||
1728 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1729 | put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\ | ||
1730 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1731 | OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ | ||
1732 | }\ | ||
1733 | static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1734 | uint8_t full[16*9];\ | ||
1735 | uint8_t halfH[72];\ | ||
1736 | uint8_t halfHV[64];\ | ||
1737 | copy_block9(full, src, 16, stride, 9);\ | ||
1738 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1739 | put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\ | ||
1740 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1741 | OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\ | ||
1742 | }\ | ||
1743 | void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1744 | uint8_t full[16*9];\ | ||
1745 | uint8_t halfH[72];\ | ||
1746 | uint8_t halfV[64];\ | ||
1747 | uint8_t halfHV[64];\ | ||
1748 | copy_block9(full, src, 16, stride, 9);\ | ||
1749 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\ | ||
1750 | put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\ | ||
1751 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1752 | OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ | ||
1753 | }\ | ||
1754 | static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1755 | uint8_t full[16*9];\ | ||
1756 | uint8_t halfH[72];\ | ||
1757 | uint8_t halfHV[64];\ | ||
1758 | copy_block9(full, src, 16, stride, 9);\ | ||
1759 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1760 | put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\ | ||
1761 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1762 | OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\ | ||
1763 | }\ | ||
1764 | static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1765 | uint8_t halfH[72];\ | ||
1766 | uint8_t halfHV[64];\ | ||
1767 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\ | ||
1768 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1769 | OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\ | ||
1770 | }\ | ||
1771 | static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1772 | uint8_t halfH[72];\ | ||
1773 | uint8_t halfHV[64];\ | ||
1774 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\ | ||
1775 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1776 | OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\ | ||
1777 | }\ | ||
1778 | void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1779 | uint8_t full[16*9];\ | ||
1780 | uint8_t halfH[72];\ | ||
1781 | uint8_t halfV[64];\ | ||
1782 | uint8_t halfHV[64];\ | ||
1783 | copy_block9(full, src, 16, stride, 9);\ | ||
1784 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1785 | put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\ | ||
1786 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1787 | OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\ | ||
1788 | }\ | ||
1789 | static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1790 | uint8_t full[16*9];\ | ||
1791 | uint8_t halfH[72];\ | ||
1792 | copy_block9(full, src, 16, stride, 9);\ | ||
1793 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1794 | put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\ | ||
1795 | OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\ | ||
1796 | }\ | ||
1797 | void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1798 | uint8_t full[16*9];\ | ||
1799 | uint8_t halfH[72];\ | ||
1800 | uint8_t halfV[64];\ | ||
1801 | uint8_t halfHV[64];\ | ||
1802 | copy_block9(full, src, 16, stride, 9);\ | ||
1803 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1804 | put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\ | ||
1805 | put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ | ||
1806 | OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\ | ||
1807 | }\ | ||
1808 | static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1809 | uint8_t full[16*9];\ | ||
1810 | uint8_t halfH[72];\ | ||
1811 | copy_block9(full, src, 16, stride, 9);\ | ||
1812 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ | ||
1813 | put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\ | ||
1814 | OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\ | ||
1815 | }\ | ||
1816 | static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1817 | uint8_t halfH[72];\ | ||
1818 | put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\ | ||
1819 | OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\ | ||
1820 | }\ | ||
1821 | static void OPNAME ## qpel16_mc00_c (uint8_t *dst, uint8_t *src, int stride){\ | ||
1822 | OPNAME ## pixels16_c(dst, src, stride, 16);\ | ||
1823 | }\ | ||
1824 | \ | ||
1825 | static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1826 | uint8_t half[256];\ | ||
1827 | put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\ | ||
1828 | OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\ | ||
1829 | }\ | ||
1830 | \ | ||
1831 | static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1832 | OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);\ | ||
1833 | }\ | ||
1834 | \ | ||
1835 | static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1836 | uint8_t half[256];\ | ||
1837 | put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\ | ||
1838 | OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\ | ||
1839 | }\ | ||
1840 | \ | ||
1841 | static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1842 | uint8_t full[24*17];\ | ||
1843 | uint8_t half[256];\ | ||
1844 | copy_block17(full, src, 24, stride, 17);\ | ||
1845 | put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\ | ||
1846 | OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\ | ||
1847 | }\ | ||
1848 | \ | ||
1849 | static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1850 | uint8_t full[24*17];\ | ||
1851 | copy_block17(full, src, 24, stride, 17);\ | ||
1852 | OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);\ | ||
1853 | }\ | ||
1854 | \ | ||
1855 | static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1856 | uint8_t full[24*17];\ | ||
1857 | uint8_t half[256];\ | ||
1858 | copy_block17(full, src, 24, stride, 17);\ | ||
1859 | put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\ | ||
1860 | OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\ | ||
1861 | }\ | ||
1862 | void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1863 | uint8_t full[24*17];\ | ||
1864 | uint8_t halfH[272];\ | ||
1865 | uint8_t halfV[256];\ | ||
1866 | uint8_t halfHV[256];\ | ||
1867 | copy_block17(full, src, 24, stride, 17);\ | ||
1868 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1869 | put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\ | ||
1870 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1871 | OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ | ||
1872 | }\ | ||
1873 | static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1874 | uint8_t full[24*17];\ | ||
1875 | uint8_t halfH[272];\ | ||
1876 | uint8_t halfHV[256];\ | ||
1877 | copy_block17(full, src, 24, stride, 17);\ | ||
1878 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1879 | put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\ | ||
1880 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1881 | OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\ | ||
1882 | }\ | ||
1883 | void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1884 | uint8_t full[24*17];\ | ||
1885 | uint8_t halfH[272];\ | ||
1886 | uint8_t halfV[256];\ | ||
1887 | uint8_t halfHV[256];\ | ||
1888 | copy_block17(full, src, 24, stride, 17);\ | ||
1889 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1890 | put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\ | ||
1891 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1892 | OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ | ||
1893 | }\ | ||
1894 | static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1895 | uint8_t full[24*17];\ | ||
1896 | uint8_t halfH[272];\ | ||
1897 | uint8_t halfHV[256];\ | ||
1898 | copy_block17(full, src, 24, stride, 17);\ | ||
1899 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1900 | put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\ | ||
1901 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1902 | OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\ | ||
1903 | }\ | ||
1904 | void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1905 | uint8_t full[24*17];\ | ||
1906 | uint8_t halfH[272];\ | ||
1907 | uint8_t halfV[256];\ | ||
1908 | uint8_t halfHV[256];\ | ||
1909 | copy_block17(full, src, 24, stride, 17);\ | ||
1910 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1911 | put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\ | ||
1912 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1913 | OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ | ||
1914 | }\ | ||
1915 | static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1916 | uint8_t full[24*17];\ | ||
1917 | uint8_t halfH[272];\ | ||
1918 | uint8_t halfHV[256];\ | ||
1919 | copy_block17(full, src, 24, stride, 17);\ | ||
1920 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1921 | put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\ | ||
1922 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1923 | OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\ | ||
1924 | }\ | ||
1925 | void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1926 | uint8_t full[24*17];\ | ||
1927 | uint8_t halfH[272];\ | ||
1928 | uint8_t halfV[256];\ | ||
1929 | uint8_t halfHV[256];\ | ||
1930 | copy_block17(full, src, 24, stride, 17);\ | ||
1931 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\ | ||
1932 | put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\ | ||
1933 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1934 | OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ | ||
1935 | }\ | ||
1936 | static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1937 | uint8_t full[24*17];\ | ||
1938 | uint8_t halfH[272];\ | ||
1939 | uint8_t halfHV[256];\ | ||
1940 | copy_block17(full, src, 24, stride, 17);\ | ||
1941 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1942 | put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\ | ||
1943 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1944 | OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\ | ||
1945 | }\ | ||
1946 | static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1947 | uint8_t halfH[272];\ | ||
1948 | uint8_t halfHV[256];\ | ||
1949 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ | ||
1950 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1951 | OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\ | ||
1952 | }\ | ||
1953 | static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1954 | uint8_t halfH[272];\ | ||
1955 | uint8_t halfHV[256];\ | ||
1956 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ | ||
1957 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1958 | OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\ | ||
1959 | }\ | ||
1960 | void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1961 | uint8_t full[24*17];\ | ||
1962 | uint8_t halfH[272];\ | ||
1963 | uint8_t halfV[256];\ | ||
1964 | uint8_t halfHV[256];\ | ||
1965 | copy_block17(full, src, 24, stride, 17);\ | ||
1966 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1967 | put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\ | ||
1968 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1969 | OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\ | ||
1970 | }\ | ||
1971 | static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1972 | uint8_t full[24*17];\ | ||
1973 | uint8_t halfH[272];\ | ||
1974 | copy_block17(full, src, 24, stride, 17);\ | ||
1975 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1976 | put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\ | ||
1977 | OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ | ||
1978 | }\ | ||
1979 | void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1980 | uint8_t full[24*17];\ | ||
1981 | uint8_t halfH[272];\ | ||
1982 | uint8_t halfV[256];\ | ||
1983 | uint8_t halfHV[256];\ | ||
1984 | copy_block17(full, src, 24, stride, 17);\ | ||
1985 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1986 | put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\ | ||
1987 | put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ | ||
1988 | OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\ | ||
1989 | }\ | ||
1990 | static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1991 | uint8_t full[24*17];\ | ||
1992 | uint8_t halfH[272];\ | ||
1993 | copy_block17(full, src, 24, stride, 17);\ | ||
1994 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ | ||
1995 | put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\ | ||
1996 | OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ | ||
1997 | }\ | ||
1998 | static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
1999 | uint8_t halfH[272];\ | ||
2000 | put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ | ||
2001 | OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ | ||
2002 | } | ||
2003 | |||
2004 | #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1) | ||
2005 | #define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1) | ||
2006 | #define op_put(a, b) a = cm[((b) + 16)>>5] | ||
2007 | #define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5] | ||
2008 | |||
2009 | QPEL_MC(0, put_ , _ , op_put) | ||
2010 | QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd) | ||
2011 | QPEL_MC(0, avg_ , _ , op_avg) | ||
2012 | //QPEL_MC(1, avg_no_rnd , _ , op_avg) | ||
2013 | #undef op_avg | ||
2014 | #undef op_avg_no_rnd | ||
2015 | #undef op_put | ||
2016 | #undef op_put_no_rnd | ||
2017 | |||
2018 | #if 1 | ||
2019 | #define H264_LOWPASS(OPNAME, OP, OP2) \ | ||
2020 | static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2021 | const int h=2;\ | ||
2022 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2023 | int i;\ | ||
2024 | for(i=0; i<h; i++)\ | ||
2025 | {\ | ||
2026 | OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\ | ||
2027 | OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\ | ||
2028 | dst+=dstStride;\ | ||
2029 | src+=srcStride;\ | ||
2030 | }\ | ||
2031 | }\ | ||
2032 | \ | ||
2033 | static av_unused void OPNAME ## h264_qpel2_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2034 | const int w=2;\ | ||
2035 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2036 | int i;\ | ||
2037 | for(i=0; i<w; i++)\ | ||
2038 | {\ | ||
2039 | const int srcB= src[-2*srcStride];\ | ||
2040 | const int srcA= src[-1*srcStride];\ | ||
2041 | const int src0= src[0 *srcStride];\ | ||
2042 | const int src1= src[1 *srcStride];\ | ||
2043 | const int src2= src[2 *srcStride];\ | ||
2044 | const int src3= src[3 *srcStride];\ | ||
2045 | const int src4= src[4 *srcStride];\ | ||
2046 | OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\ | ||
2047 | OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\ | ||
2048 | dst++;\ | ||
2049 | src++;\ | ||
2050 | }\ | ||
2051 | }\ | ||
2052 | \ | ||
2053 | static av_unused void OPNAME ## h264_qpel2_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ | ||
2054 | const int h=2;\ | ||
2055 | const int w=2;\ | ||
2056 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2057 | int i;\ | ||
2058 | src -= 2*srcStride;\ | ||
2059 | for(i=0; i<h+5; i++)\ | ||
2060 | {\ | ||
2061 | tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\ | ||
2062 | tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\ | ||
2063 | tmp+=tmpStride;\ | ||
2064 | src+=srcStride;\ | ||
2065 | }\ | ||
2066 | tmp -= tmpStride*(h+5-2);\ | ||
2067 | for(i=0; i<w; i++)\ | ||
2068 | {\ | ||
2069 | const int tmpB= tmp[-2*tmpStride];\ | ||
2070 | const int tmpA= tmp[-1*tmpStride];\ | ||
2071 | const int tmp0= tmp[0 *tmpStride];\ | ||
2072 | const int tmp1= tmp[1 *tmpStride];\ | ||
2073 | const int tmp2= tmp[2 *tmpStride];\ | ||
2074 | const int tmp3= tmp[3 *tmpStride];\ | ||
2075 | const int tmp4= tmp[4 *tmpStride];\ | ||
2076 | OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\ | ||
2077 | OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\ | ||
2078 | dst++;\ | ||
2079 | tmp++;\ | ||
2080 | }\ | ||
2081 | }\ | ||
2082 | static void OPNAME ## h264_qpel4_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2083 | const int h=4;\ | ||
2084 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2085 | int i;\ | ||
2086 | for(i=0; i<h; i++)\ | ||
2087 | {\ | ||
2088 | OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]));\ | ||
2089 | OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]));\ | ||
2090 | OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]));\ | ||
2091 | OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]));\ | ||
2092 | dst+=dstStride;\ | ||
2093 | src+=srcStride;\ | ||
2094 | }\ | ||
2095 | }\ | ||
2096 | \ | ||
2097 | static void OPNAME ## h264_qpel4_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2098 | const int w=4;\ | ||
2099 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2100 | int i;\ | ||
2101 | for(i=0; i<w; i++)\ | ||
2102 | {\ | ||
2103 | const int srcB= src[-2*srcStride];\ | ||
2104 | const int srcA= src[-1*srcStride];\ | ||
2105 | const int src0= src[0 *srcStride];\ | ||
2106 | const int src1= src[1 *srcStride];\ | ||
2107 | const int src2= src[2 *srcStride];\ | ||
2108 | const int src3= src[3 *srcStride];\ | ||
2109 | const int src4= src[4 *srcStride];\ | ||
2110 | const int src5= src[5 *srcStride];\ | ||
2111 | const int src6= src[6 *srcStride];\ | ||
2112 | OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\ | ||
2113 | OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\ | ||
2114 | OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\ | ||
2115 | OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\ | ||
2116 | dst++;\ | ||
2117 | src++;\ | ||
2118 | }\ | ||
2119 | }\ | ||
2120 | \ | ||
2121 | static void OPNAME ## h264_qpel4_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ | ||
2122 | const int h=4;\ | ||
2123 | const int w=4;\ | ||
2124 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2125 | int i;\ | ||
2126 | src -= 2*srcStride;\ | ||
2127 | for(i=0; i<h+5; i++)\ | ||
2128 | {\ | ||
2129 | tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3]);\ | ||
2130 | tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4]);\ | ||
2131 | tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5]);\ | ||
2132 | tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6]);\ | ||
2133 | tmp+=tmpStride;\ | ||
2134 | src+=srcStride;\ | ||
2135 | }\ | ||
2136 | tmp -= tmpStride*(h+5-2);\ | ||
2137 | for(i=0; i<w; i++)\ | ||
2138 | {\ | ||
2139 | const int tmpB= tmp[-2*tmpStride];\ | ||
2140 | const int tmpA= tmp[-1*tmpStride];\ | ||
2141 | const int tmp0= tmp[0 *tmpStride];\ | ||
2142 | const int tmp1= tmp[1 *tmpStride];\ | ||
2143 | const int tmp2= tmp[2 *tmpStride];\ | ||
2144 | const int tmp3= tmp[3 *tmpStride];\ | ||
2145 | const int tmp4= tmp[4 *tmpStride];\ | ||
2146 | const int tmp5= tmp[5 *tmpStride];\ | ||
2147 | const int tmp6= tmp[6 *tmpStride];\ | ||
2148 | OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\ | ||
2149 | OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\ | ||
2150 | OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\ | ||
2151 | OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\ | ||
2152 | dst++;\ | ||
2153 | tmp++;\ | ||
2154 | }\ | ||
2155 | }\ | ||
2156 | \ | ||
2157 | static void OPNAME ## h264_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2158 | const int h=8;\ | ||
2159 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2160 | int i;\ | ||
2161 | for(i=0; i<h; i++)\ | ||
2162 | {\ | ||
2163 | OP(dst[0], (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]));\ | ||
2164 | OP(dst[1], (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]));\ | ||
2165 | OP(dst[2], (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]));\ | ||
2166 | OP(dst[3], (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]));\ | ||
2167 | OP(dst[4], (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]));\ | ||
2168 | OP(dst[5], (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]));\ | ||
2169 | OP(dst[6], (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]));\ | ||
2170 | OP(dst[7], (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]));\ | ||
2171 | dst+=dstStride;\ | ||
2172 | src+=srcStride;\ | ||
2173 | }\ | ||
2174 | }\ | ||
2175 | \ | ||
2176 | static void OPNAME ## h264_qpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2177 | const int w=8;\ | ||
2178 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2179 | int i;\ | ||
2180 | for(i=0; i<w; i++)\ | ||
2181 | {\ | ||
2182 | const int srcB= src[-2*srcStride];\ | ||
2183 | const int srcA= src[-1*srcStride];\ | ||
2184 | const int src0= src[0 *srcStride];\ | ||
2185 | const int src1= src[1 *srcStride];\ | ||
2186 | const int src2= src[2 *srcStride];\ | ||
2187 | const int src3= src[3 *srcStride];\ | ||
2188 | const int src4= src[4 *srcStride];\ | ||
2189 | const int src5= src[5 *srcStride];\ | ||
2190 | const int src6= src[6 *srcStride];\ | ||
2191 | const int src7= src[7 *srcStride];\ | ||
2192 | const int src8= src[8 *srcStride];\ | ||
2193 | const int src9= src[9 *srcStride];\ | ||
2194 | const int src10=src[10*srcStride];\ | ||
2195 | OP(dst[0*dstStride], (src0+src1)*20 - (srcA+src2)*5 + (srcB+src3));\ | ||
2196 | OP(dst[1*dstStride], (src1+src2)*20 - (src0+src3)*5 + (srcA+src4));\ | ||
2197 | OP(dst[2*dstStride], (src2+src3)*20 - (src1+src4)*5 + (src0+src5));\ | ||
2198 | OP(dst[3*dstStride], (src3+src4)*20 - (src2+src5)*5 + (src1+src6));\ | ||
2199 | OP(dst[4*dstStride], (src4+src5)*20 - (src3+src6)*5 + (src2+src7));\ | ||
2200 | OP(dst[5*dstStride], (src5+src6)*20 - (src4+src7)*5 + (src3+src8));\ | ||
2201 | OP(dst[6*dstStride], (src6+src7)*20 - (src5+src8)*5 + (src4+src9));\ | ||
2202 | OP(dst[7*dstStride], (src7+src8)*20 - (src6+src9)*5 + (src5+src10));\ | ||
2203 | dst++;\ | ||
2204 | src++;\ | ||
2205 | }\ | ||
2206 | }\ | ||
2207 | \ | ||
2208 | static void OPNAME ## h264_qpel8_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ | ||
2209 | const int h=8;\ | ||
2210 | const int w=8;\ | ||
2211 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ | ||
2212 | int i;\ | ||
2213 | src -= 2*srcStride;\ | ||
2214 | for(i=0; i<h+5; i++)\ | ||
2215 | {\ | ||
2216 | tmp[0]= (src[0]+src[1])*20 - (src[-1]+src[2])*5 + (src[-2]+src[3 ]);\ | ||
2217 | tmp[1]= (src[1]+src[2])*20 - (src[0 ]+src[3])*5 + (src[-1]+src[4 ]);\ | ||
2218 | tmp[2]= (src[2]+src[3])*20 - (src[1 ]+src[4])*5 + (src[0 ]+src[5 ]);\ | ||
2219 | tmp[3]= (src[3]+src[4])*20 - (src[2 ]+src[5])*5 + (src[1 ]+src[6 ]);\ | ||
2220 | tmp[4]= (src[4]+src[5])*20 - (src[3 ]+src[6])*5 + (src[2 ]+src[7 ]);\ | ||
2221 | tmp[5]= (src[5]+src[6])*20 - (src[4 ]+src[7])*5 + (src[3 ]+src[8 ]);\ | ||
2222 | tmp[6]= (src[6]+src[7])*20 - (src[5 ]+src[8])*5 + (src[4 ]+src[9 ]);\ | ||
2223 | tmp[7]= (src[7]+src[8])*20 - (src[6 ]+src[9])*5 + (src[5 ]+src[10]);\ | ||
2224 | tmp+=tmpStride;\ | ||
2225 | src+=srcStride;\ | ||
2226 | }\ | ||
2227 | tmp -= tmpStride*(h+5-2);\ | ||
2228 | for(i=0; i<w; i++)\ | ||
2229 | {\ | ||
2230 | const int tmpB= tmp[-2*tmpStride];\ | ||
2231 | const int tmpA= tmp[-1*tmpStride];\ | ||
2232 | const int tmp0= tmp[0 *tmpStride];\ | ||
2233 | const int tmp1= tmp[1 *tmpStride];\ | ||
2234 | const int tmp2= tmp[2 *tmpStride];\ | ||
2235 | const int tmp3= tmp[3 *tmpStride];\ | ||
2236 | const int tmp4= tmp[4 *tmpStride];\ | ||
2237 | const int tmp5= tmp[5 *tmpStride];\ | ||
2238 | const int tmp6= tmp[6 *tmpStride];\ | ||
2239 | const int tmp7= tmp[7 *tmpStride];\ | ||
2240 | const int tmp8= tmp[8 *tmpStride];\ | ||
2241 | const int tmp9= tmp[9 *tmpStride];\ | ||
2242 | const int tmp10=tmp[10*tmpStride];\ | ||
2243 | OP2(dst[0*dstStride], (tmp0+tmp1)*20 - (tmpA+tmp2)*5 + (tmpB+tmp3));\ | ||
2244 | OP2(dst[1*dstStride], (tmp1+tmp2)*20 - (tmp0+tmp3)*5 + (tmpA+tmp4));\ | ||
2245 | OP2(dst[2*dstStride], (tmp2+tmp3)*20 - (tmp1+tmp4)*5 + (tmp0+tmp5));\ | ||
2246 | OP2(dst[3*dstStride], (tmp3+tmp4)*20 - (tmp2+tmp5)*5 + (tmp1+tmp6));\ | ||
2247 | OP2(dst[4*dstStride], (tmp4+tmp5)*20 - (tmp3+tmp6)*5 + (tmp2+tmp7));\ | ||
2248 | OP2(dst[5*dstStride], (tmp5+tmp6)*20 - (tmp4+tmp7)*5 + (tmp3+tmp8));\ | ||
2249 | OP2(dst[6*dstStride], (tmp6+tmp7)*20 - (tmp5+tmp8)*5 + (tmp4+tmp9));\ | ||
2250 | OP2(dst[7*dstStride], (tmp7+tmp8)*20 - (tmp6+tmp9)*5 + (tmp5+tmp10));\ | ||
2251 | dst++;\ | ||
2252 | tmp++;\ | ||
2253 | }\ | ||
2254 | }\ | ||
2255 | \ | ||
2256 | static void OPNAME ## h264_qpel16_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2257 | OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\ | ||
2258 | OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\ | ||
2259 | src += 8*srcStride;\ | ||
2260 | dst += 8*dstStride;\ | ||
2261 | OPNAME ## h264_qpel8_v_lowpass(dst , src , dstStride, srcStride);\ | ||
2262 | OPNAME ## h264_qpel8_v_lowpass(dst+8, src+8, dstStride, srcStride);\ | ||
2263 | }\ | ||
2264 | \ | ||
2265 | static void OPNAME ## h264_qpel16_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ | ||
2266 | OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\ | ||
2267 | OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\ | ||
2268 | src += 8*srcStride;\ | ||
2269 | dst += 8*dstStride;\ | ||
2270 | OPNAME ## h264_qpel8_h_lowpass(dst , src , dstStride, srcStride);\ | ||
2271 | OPNAME ## h264_qpel8_h_lowpass(dst+8, src+8, dstStride, srcStride);\ | ||
2272 | }\ | ||
2273 | \ | ||
2274 | static void OPNAME ## h264_qpel16_hv_lowpass(uint8_t *dst, int16_t *tmp, uint8_t *src, int dstStride, int tmpStride, int srcStride){\ | ||
2275 | OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\ | ||
2276 | OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\ | ||
2277 | src += 8*srcStride;\ | ||
2278 | dst += 8*dstStride;\ | ||
2279 | OPNAME ## h264_qpel8_hv_lowpass(dst , tmp , src , dstStride, tmpStride, srcStride);\ | ||
2280 | OPNAME ## h264_qpel8_hv_lowpass(dst+8, tmp+8, src+8, dstStride, tmpStride, srcStride);\ | ||
2281 | }\ | ||
2282 | |||
2283 | #define H264_MC(OPNAME, SIZE) \ | ||
2284 | static void OPNAME ## h264_qpel ## SIZE ## _mc00_c (uint8_t *dst, uint8_t *src, int stride){\ | ||
2285 | OPNAME ## pixels ## SIZE ## _c(dst, src, stride, SIZE);\ | ||
2286 | }\ | ||
2287 | \ | ||
2288 | static void OPNAME ## h264_qpel ## SIZE ## _mc10_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2289 | uint8_t half[SIZE*SIZE];\ | ||
2290 | put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\ | ||
2291 | OPNAME ## pixels ## SIZE ## _l2(dst, src, half, stride, stride, SIZE, SIZE);\ | ||
2292 | }\ | ||
2293 | \ | ||
2294 | static void OPNAME ## h264_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2295 | OPNAME ## h264_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride);\ | ||
2296 | }\ | ||
2297 | \ | ||
2298 | static void OPNAME ## h264_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2299 | uint8_t half[SIZE*SIZE];\ | ||
2300 | put_h264_qpel ## SIZE ## _h_lowpass(half, src, SIZE, stride);\ | ||
2301 | OPNAME ## pixels ## SIZE ## _l2(dst, src+1, half, stride, stride, SIZE, SIZE);\ | ||
2302 | }\ | ||
2303 | \ | ||
2304 | static void OPNAME ## h264_qpel ## SIZE ## _mc01_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2305 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2306 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2307 | uint8_t half[SIZE*SIZE];\ | ||
2308 | copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\ | ||
2309 | put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\ | ||
2310 | OPNAME ## pixels ## SIZE ## _l2(dst, full_mid, half, stride, SIZE, SIZE, SIZE);\ | ||
2311 | }\ | ||
2312 | \ | ||
2313 | static void OPNAME ## h264_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2314 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2315 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2316 | copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\ | ||
2317 | OPNAME ## h264_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE);\ | ||
2318 | }\ | ||
2319 | \ | ||
2320 | static void OPNAME ## h264_qpel ## SIZE ## _mc03_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2321 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2322 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2323 | uint8_t half[SIZE*SIZE];\ | ||
2324 | copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\ | ||
2325 | put_h264_qpel ## SIZE ## _v_lowpass(half, full_mid, SIZE, SIZE);\ | ||
2326 | OPNAME ## pixels ## SIZE ## _l2(dst, full_mid+SIZE, half, stride, SIZE, SIZE, SIZE);\ | ||
2327 | }\ | ||
2328 | \ | ||
2329 | static void OPNAME ## h264_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2330 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2331 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2332 | uint8_t halfH[SIZE*SIZE];\ | ||
2333 | uint8_t halfV[SIZE*SIZE];\ | ||
2334 | put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\ | ||
2335 | copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\ | ||
2336 | put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\ | ||
2337 | OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\ | ||
2338 | }\ | ||
2339 | \ | ||
2340 | static void OPNAME ## h264_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2341 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2342 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2343 | uint8_t halfH[SIZE*SIZE];\ | ||
2344 | uint8_t halfV[SIZE*SIZE];\ | ||
2345 | put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\ | ||
2346 | copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\ | ||
2347 | put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\ | ||
2348 | OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\ | ||
2349 | }\ | ||
2350 | \ | ||
2351 | static void OPNAME ## h264_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2352 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2353 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2354 | uint8_t halfH[SIZE*SIZE];\ | ||
2355 | uint8_t halfV[SIZE*SIZE];\ | ||
2356 | put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\ | ||
2357 | copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\ | ||
2358 | put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\ | ||
2359 | OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\ | ||
2360 | }\ | ||
2361 | \ | ||
2362 | static void OPNAME ## h264_qpel ## SIZE ## _mc33_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2363 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2364 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2365 | uint8_t halfH[SIZE*SIZE];\ | ||
2366 | uint8_t halfV[SIZE*SIZE];\ | ||
2367 | put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\ | ||
2368 | copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\ | ||
2369 | put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\ | ||
2370 | OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfV, stride, SIZE, SIZE, SIZE);\ | ||
2371 | }\ | ||
2372 | \ | ||
2373 | static void OPNAME ## h264_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2374 | int16_t tmp[SIZE*(SIZE+5)];\ | ||
2375 | OPNAME ## h264_qpel ## SIZE ## _hv_lowpass(dst, tmp, src, stride, SIZE, stride);\ | ||
2376 | }\ | ||
2377 | \ | ||
2378 | static void OPNAME ## h264_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2379 | int16_t tmp[SIZE*(SIZE+5)];\ | ||
2380 | uint8_t halfH[SIZE*SIZE];\ | ||
2381 | uint8_t halfHV[SIZE*SIZE];\ | ||
2382 | put_h264_qpel ## SIZE ## _h_lowpass(halfH, src, SIZE, stride);\ | ||
2383 | put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\ | ||
2384 | OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\ | ||
2385 | }\ | ||
2386 | \ | ||
2387 | static void OPNAME ## h264_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2388 | int16_t tmp[SIZE*(SIZE+5)];\ | ||
2389 | uint8_t halfH[SIZE*SIZE];\ | ||
2390 | uint8_t halfHV[SIZE*SIZE];\ | ||
2391 | put_h264_qpel ## SIZE ## _h_lowpass(halfH, src + stride, SIZE, stride);\ | ||
2392 | put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\ | ||
2393 | OPNAME ## pixels ## SIZE ## _l2(dst, halfH, halfHV, stride, SIZE, SIZE, SIZE);\ | ||
2394 | }\ | ||
2395 | \ | ||
2396 | static void OPNAME ## h264_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2397 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2398 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2399 | int16_t tmp[SIZE*(SIZE+5)];\ | ||
2400 | uint8_t halfV[SIZE*SIZE];\ | ||
2401 | uint8_t halfHV[SIZE*SIZE];\ | ||
2402 | copy_block ## SIZE (full, src - stride*2, SIZE, stride, SIZE + 5);\ | ||
2403 | put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\ | ||
2404 | put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\ | ||
2405 | OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\ | ||
2406 | }\ | ||
2407 | \ | ||
2408 | static void OPNAME ## h264_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\ | ||
2409 | uint8_t full[SIZE*(SIZE+5)];\ | ||
2410 | uint8_t * const full_mid= full + SIZE*2;\ | ||
2411 | int16_t tmp[SIZE*(SIZE+5)];\ | ||
2412 | uint8_t halfV[SIZE*SIZE];\ | ||
2413 | uint8_t halfHV[SIZE*SIZE];\ | ||
2414 | copy_block ## SIZE (full, src - stride*2 + 1, SIZE, stride, SIZE + 5);\ | ||
2415 | put_h264_qpel ## SIZE ## _v_lowpass(halfV, full_mid, SIZE, SIZE);\ | ||
2416 | put_h264_qpel ## SIZE ## _hv_lowpass(halfHV, tmp, src, SIZE, SIZE, stride);\ | ||
2417 | OPNAME ## pixels ## SIZE ## _l2(dst, halfV, halfHV, stride, SIZE, SIZE, SIZE);\ | ||
2418 | }\ | ||
2419 | |||
2420 | #define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1) | ||
2421 | //#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) | ||
2422 | #define op_put(a, b) a = cm[((b) + 16)>>5] | ||
2423 | #define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1) | ||
2424 | #define op2_put(a, b) a = cm[((b) + 512)>>10] | ||
2425 | |||
2426 | H264_LOWPASS(put_ , op_put, op2_put) | ||
2427 | H264_LOWPASS(avg_ , op_avg, op2_avg) | ||
2428 | H264_MC(put_, 2) | ||
2429 | H264_MC(put_, 4) | ||
2430 | H264_MC(put_, 8) | ||
2431 | H264_MC(put_, 16) | ||
2432 | H264_MC(avg_, 4) | ||
2433 | H264_MC(avg_, 8) | ||
2434 | H264_MC(avg_, 16) | ||
2435 | |||
2436 | #undef op_avg | ||
2437 | #undef op_put | ||
2438 | #undef op2_avg | ||
2439 | #undef op2_put | ||
2440 | #endif | ||
2441 | |||
2442 | #define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom ) | ||
2443 | #define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1)) | ||
2444 | #define H264_WEIGHT(W,H) \ | ||
2445 | static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \ | ||
2446 | int y; \ | ||
2447 | offset <<= log2_denom; \ | ||
2448 | if(log2_denom) offset += 1<<(log2_denom-1); \ | ||
2449 | for(y=0; y<H; y++, block += stride){ \ | ||
2450 | op_scale1(0); \ | ||
2451 | op_scale1(1); \ | ||
2452 | if(W==2) continue; \ | ||
2453 | op_scale1(2); \ | ||
2454 | op_scale1(3); \ | ||
2455 | if(W==4) continue; \ | ||
2456 | op_scale1(4); \ | ||
2457 | op_scale1(5); \ | ||
2458 | op_scale1(6); \ | ||
2459 | op_scale1(7); \ | ||
2460 | if(W==8) continue; \ | ||
2461 | op_scale1(8); \ | ||
2462 | op_scale1(9); \ | ||
2463 | op_scale1(10); \ | ||
2464 | op_scale1(11); \ | ||
2465 | op_scale1(12); \ | ||
2466 | op_scale1(13); \ | ||
2467 | op_scale1(14); \ | ||
2468 | op_scale1(15); \ | ||
2469 | } \ | ||
2470 | } \ | ||
2471 | static void biweight_h264_pixels ## W ## x ## H ## _c(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset){ \ | ||
2472 | int y; \ | ||
2473 | offset = ((offset + 1) | 1) << log2_denom; \ | ||
2474 | for(y=0; y<H; y++, dst += stride, src += stride){ \ | ||
2475 | op_scale2(0); \ | ||
2476 | op_scale2(1); \ | ||
2477 | if(W==2) continue; \ | ||
2478 | op_scale2(2); \ | ||
2479 | op_scale2(3); \ | ||
2480 | if(W==4) continue; \ | ||
2481 | op_scale2(4); \ | ||
2482 | op_scale2(5); \ | ||
2483 | op_scale2(6); \ | ||
2484 | op_scale2(7); \ | ||
2485 | if(W==8) continue; \ | ||
2486 | op_scale2(8); \ | ||
2487 | op_scale2(9); \ | ||
2488 | op_scale2(10); \ | ||
2489 | op_scale2(11); \ | ||
2490 | op_scale2(12); \ | ||
2491 | op_scale2(13); \ | ||
2492 | op_scale2(14); \ | ||
2493 | op_scale2(15); \ | ||
2494 | } \ | ||
2495 | } | ||
2496 | |||
2497 | H264_WEIGHT(16,16) | ||
2498 | H264_WEIGHT(16,8) | ||
2499 | H264_WEIGHT(8,16) | ||
2500 | H264_WEIGHT(8,8) | ||
2501 | H264_WEIGHT(8,4) | ||
2502 | H264_WEIGHT(4,8) | ||
2503 | H264_WEIGHT(4,4) | ||
2504 | H264_WEIGHT(4,2) | ||
2505 | H264_WEIGHT(2,4) | ||
2506 | H264_WEIGHT(2,2) | ||
2507 | |||
2508 | #undef op_scale1 | ||
2509 | #undef op_scale2 | ||
2510 | #undef H264_WEIGHT | ||
2511 | |||
2512 | static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){ | ||
2513 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
2514 | int i; | ||
2515 | |||
2516 | for(i=0; i<h; i++){ | ||
2517 | dst[0]= cm[(9*(src[0] + src[1]) - (src[-1] + src[2]) + 8)>>4]; | ||
2518 | dst[1]= cm[(9*(src[1] + src[2]) - (src[ 0] + src[3]) + 8)>>4]; | ||
2519 | dst[2]= cm[(9*(src[2] + src[3]) - (src[ 1] + src[4]) + 8)>>4]; | ||
2520 | dst[3]= cm[(9*(src[3] + src[4]) - (src[ 2] + src[5]) + 8)>>4]; | ||
2521 | dst[4]= cm[(9*(src[4] + src[5]) - (src[ 3] + src[6]) + 8)>>4]; | ||
2522 | dst[5]= cm[(9*(src[5] + src[6]) - (src[ 4] + src[7]) + 8)>>4]; | ||
2523 | dst[6]= cm[(9*(src[6] + src[7]) - (src[ 5] + src[8]) + 8)>>4]; | ||
2524 | dst[7]= cm[(9*(src[7] + src[8]) - (src[ 6] + src[9]) + 8)>>4]; | ||
2525 | dst+=dstStride; | ||
2526 | src+=srcStride; | ||
2527 | } | ||
2528 | } | ||
2529 | |||
2530 | #if CONFIG_CAVS_DECODER | ||
2531 | /* AVS specific */ | ||
2532 | void ff_cavsdsp_init(DSPContext* c, AVCodecContext *avctx); | ||
2533 | |||
2534 | void ff_put_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) { | ||
2535 | put_pixels8_c(dst, src, stride, 8); | ||
2536 | } | ||
2537 | void ff_avg_cavs_qpel8_mc00_c(uint8_t *dst, uint8_t *src, int stride) { | ||
2538 | avg_pixels8_c(dst, src, stride, 8); | ||
2539 | } | ||
2540 | void ff_put_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) { | ||
2541 | put_pixels16_c(dst, src, stride, 16); | ||
2542 | } | ||
2543 | void ff_avg_cavs_qpel16_mc00_c(uint8_t *dst, uint8_t *src, int stride) { | ||
2544 | avg_pixels16_c(dst, src, stride, 16); | ||
2545 | } | ||
2546 | #endif /* CONFIG_CAVS_DECODER */ | ||
2547 | |||
2548 | #if CONFIG_VC1_DECODER || CONFIG_WMV3_DECODER | ||
2549 | /* VC-1 specific */ | ||
2550 | void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx); | ||
2551 | |||
2552 | void ff_put_vc1_mspel_mc00_c(uint8_t *dst, uint8_t *src, int stride, int rnd) { | ||
2553 | put_pixels8_c(dst, src, stride, 8); | ||
2554 | } | ||
2555 | #endif /* CONFIG_VC1_DECODER||CONFIG_WMV3_DECODER */ | ||
2556 | |||
2557 | void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx); | ||
2558 | |||
2559 | /* H264 specific */ | ||
2560 | void ff_h264dspenc_init(DSPContext* c, AVCodecContext *avctx); | ||
2561 | |||
2562 | #if CONFIG_RV30_DECODER | ||
2563 | void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx); | ||
2564 | #endif /* CONFIG_RV30_DECODER */ | ||
2565 | |||
2566 | #if CONFIG_RV40_DECODER | ||
2567 | static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2568 | put_pixels16_xy2_c(dst, src, stride, 16); | ||
2569 | } | ||
2570 | static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2571 | avg_pixels16_xy2_c(dst, src, stride, 16); | ||
2572 | } | ||
2573 | static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2574 | put_pixels8_xy2_c(dst, src, stride, 8); | ||
2575 | } | ||
2576 | static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2577 | avg_pixels8_xy2_c(dst, src, stride, 8); | ||
2578 | } | ||
2579 | |||
2580 | void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx); | ||
2581 | #endif /* CONFIG_RV40_DECODER */ | ||
2582 | |||
2583 | static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){ | ||
2584 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
2585 | int i; | ||
2586 | |||
2587 | for(i=0; i<w; i++){ | ||
2588 | const int src_1= src[ -srcStride]; | ||
2589 | const int src0 = src[0 ]; | ||
2590 | const int src1 = src[ srcStride]; | ||
2591 | const int src2 = src[2*srcStride]; | ||
2592 | const int src3 = src[3*srcStride]; | ||
2593 | const int src4 = src[4*srcStride]; | ||
2594 | const int src5 = src[5*srcStride]; | ||
2595 | const int src6 = src[6*srcStride]; | ||
2596 | const int src7 = src[7*srcStride]; | ||
2597 | const int src8 = src[8*srcStride]; | ||
2598 | const int src9 = src[9*srcStride]; | ||
2599 | dst[0*dstStride]= cm[(9*(src0 + src1) - (src_1 + src2) + 8)>>4]; | ||
2600 | dst[1*dstStride]= cm[(9*(src1 + src2) - (src0 + src3) + 8)>>4]; | ||
2601 | dst[2*dstStride]= cm[(9*(src2 + src3) - (src1 + src4) + 8)>>4]; | ||
2602 | dst[3*dstStride]= cm[(9*(src3 + src4) - (src2 + src5) + 8)>>4]; | ||
2603 | dst[4*dstStride]= cm[(9*(src4 + src5) - (src3 + src6) + 8)>>4]; | ||
2604 | dst[5*dstStride]= cm[(9*(src5 + src6) - (src4 + src7) + 8)>>4]; | ||
2605 | dst[6*dstStride]= cm[(9*(src6 + src7) - (src5 + src8) + 8)>>4]; | ||
2606 | dst[7*dstStride]= cm[(9*(src7 + src8) - (src6 + src9) + 8)>>4]; | ||
2607 | src++; | ||
2608 | dst++; | ||
2609 | } | ||
2610 | } | ||
2611 | |||
2612 | static void put_mspel8_mc00_c (uint8_t *dst, uint8_t *src, int stride){ | ||
2613 | put_pixels8_c(dst, src, stride, 8); | ||
2614 | } | ||
2615 | |||
2616 | static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2617 | uint8_t half[64]; | ||
2618 | wmv2_mspel8_h_lowpass(half, src, 8, stride, 8); | ||
2619 | put_pixels8_l2(dst, src, half, stride, stride, 8, 8); | ||
2620 | } | ||
2621 | |||
2622 | static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2623 | wmv2_mspel8_h_lowpass(dst, src, stride, stride, 8); | ||
2624 | } | ||
2625 | |||
2626 | static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2627 | uint8_t half[64]; | ||
2628 | wmv2_mspel8_h_lowpass(half, src, 8, stride, 8); | ||
2629 | put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8); | ||
2630 | } | ||
2631 | |||
2632 | static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2633 | wmv2_mspel8_v_lowpass(dst, src, stride, stride, 8); | ||
2634 | } | ||
2635 | |||
2636 | static void put_mspel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2637 | uint8_t halfH[88]; | ||
2638 | uint8_t halfV[64]; | ||
2639 | uint8_t halfHV[64]; | ||
2640 | wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); | ||
2641 | wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8); | ||
2642 | wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8); | ||
2643 | put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8); | ||
2644 | } | ||
2645 | static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2646 | uint8_t halfH[88]; | ||
2647 | uint8_t halfV[64]; | ||
2648 | uint8_t halfHV[64]; | ||
2649 | wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); | ||
2650 | wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8); | ||
2651 | wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8); | ||
2652 | put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8); | ||
2653 | } | ||
2654 | static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){ | ||
2655 | uint8_t halfH[88]; | ||
2656 | wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); | ||
2657 | wmv2_mspel8_v_lowpass(dst, halfH+8, stride, 8, 8); | ||
2658 | } | ||
2659 | |||
2660 | static void h263_v_loop_filter_c(uint8_t *src, int stride, int qscale){ | ||
2661 | if(CONFIG_ANY_H263) { | ||
2662 | int x; | ||
2663 | const int strength= ff_h263_loop_filter_strength[qscale]; | ||
2664 | |||
2665 | for(x=0; x<8; x++){ | ||
2666 | int d1, d2, ad1; | ||
2667 | int p0= src[x-2*stride]; | ||
2668 | int p1= src[x-1*stride]; | ||
2669 | int p2= src[x+0*stride]; | ||
2670 | int p3= src[x+1*stride]; | ||
2671 | int d = (p0 - p3 + 4*(p2 - p1)) / 8; | ||
2672 | |||
2673 | if (d<-2*strength) d1= 0; | ||
2674 | else if(d<- strength) d1=-2*strength - d; | ||
2675 | else if(d< strength) d1= d; | ||
2676 | else if(d< 2*strength) d1= 2*strength - d; | ||
2677 | else d1= 0; | ||
2678 | |||
2679 | p1 += d1; | ||
2680 | p2 -= d1; | ||
2681 | if(p1&256) p1= ~(p1>>31); | ||
2682 | if(p2&256) p2= ~(p2>>31); | ||
2683 | |||
2684 | src[x-1*stride] = p1; | ||
2685 | src[x+0*stride] = p2; | ||
2686 | |||
2687 | ad1= FFABS(d1)>>1; | ||
2688 | |||
2689 | d2= av_clip((p0-p3)/4, -ad1, ad1); | ||
2690 | |||
2691 | src[x-2*stride] = p0 - d2; | ||
2692 | src[x+ stride] = p3 + d2; | ||
2693 | } | ||
2694 | } | ||
2695 | } | ||
2696 | |||
2697 | static void h263_h_loop_filter_c(uint8_t *src, int stride, int qscale){ | ||
2698 | if(CONFIG_ANY_H263) { | ||
2699 | int y; | ||
2700 | const int strength= ff_h263_loop_filter_strength[qscale]; | ||
2701 | |||
2702 | for(y=0; y<8; y++){ | ||
2703 | int d1, d2, ad1; | ||
2704 | int p0= src[y*stride-2]; | ||
2705 | int p1= src[y*stride-1]; | ||
2706 | int p2= src[y*stride+0]; | ||
2707 | int p3= src[y*stride+1]; | ||
2708 | int d = (p0 - p3 + 4*(p2 - p1)) / 8; | ||
2709 | |||
2710 | if (d<-2*strength) d1= 0; | ||
2711 | else if(d<- strength) d1=-2*strength - d; | ||
2712 | else if(d< strength) d1= d; | ||
2713 | else if(d< 2*strength) d1= 2*strength - d; | ||
2714 | else d1= 0; | ||
2715 | |||
2716 | p1 += d1; | ||
2717 | p2 -= d1; | ||
2718 | if(p1&256) p1= ~(p1>>31); | ||
2719 | if(p2&256) p2= ~(p2>>31); | ||
2720 | |||
2721 | src[y*stride-1] = p1; | ||
2722 | src[y*stride+0] = p2; | ||
2723 | |||
2724 | ad1= FFABS(d1)>>1; | ||
2725 | |||
2726 | d2= av_clip((p0-p3)/4, -ad1, ad1); | ||
2727 | |||
2728 | src[y*stride-2] = p0 - d2; | ||
2729 | src[y*stride+1] = p3 + d2; | ||
2730 | } | ||
2731 | } | ||
2732 | } | ||
2733 | |||
2734 | static void h261_loop_filter_c(uint8_t *src, int stride){ | ||
2735 | int x,y,xy,yz; | ||
2736 | int temp[64]; | ||
2737 | |||
2738 | for(x=0; x<8; x++){ | ||
2739 | temp[x ] = 4*src[x ]; | ||
2740 | temp[x + 7*8] = 4*src[x + 7*stride]; | ||
2741 | } | ||
2742 | for(y=1; y<7; y++){ | ||
2743 | for(x=0; x<8; x++){ | ||
2744 | xy = y * stride + x; | ||
2745 | yz = y * 8 + x; | ||
2746 | temp[yz] = src[xy - stride] + 2*src[xy] + src[xy + stride]; | ||
2747 | } | ||
2748 | } | ||
2749 | |||
2750 | for(y=0; y<8; y++){ | ||
2751 | src[ y*stride] = (temp[ y*8] + 2)>>2; | ||
2752 | src[7+y*stride] = (temp[7+y*8] + 2)>>2; | ||
2753 | for(x=1; x<7; x++){ | ||
2754 | xy = y * stride + x; | ||
2755 | yz = y * 8 + x; | ||
2756 | src[xy] = (temp[yz-1] + 2*temp[yz] + temp[yz+1] + 8)>>4; | ||
2757 | } | ||
2758 | } | ||
2759 | } | ||
2760 | |||
2761 | static inline void h264_loop_filter_luma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0) | ||
2762 | { | ||
2763 | int i, d; | ||
2764 | for( i = 0; i < 4; i++ ) { | ||
2765 | if( tc0[i] < 0 ) { | ||
2766 | pix += 4*ystride; | ||
2767 | continue; | ||
2768 | } | ||
2769 | for( d = 0; d < 4; d++ ) { | ||
2770 | const int p0 = pix[-1*xstride]; | ||
2771 | const int p1 = pix[-2*xstride]; | ||
2772 | const int p2 = pix[-3*xstride]; | ||
2773 | const int q0 = pix[0]; | ||
2774 | const int q1 = pix[1*xstride]; | ||
2775 | const int q2 = pix[2*xstride]; | ||
2776 | |||
2777 | if( FFABS( p0 - q0 ) < alpha && | ||
2778 | FFABS( p1 - p0 ) < beta && | ||
2779 | FFABS( q1 - q0 ) < beta ) { | ||
2780 | |||
2781 | int tc = tc0[i]; | ||
2782 | int i_delta; | ||
2783 | |||
2784 | if( FFABS( p2 - p0 ) < beta ) { | ||
2785 | pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] ); | ||
2786 | tc++; | ||
2787 | } | ||
2788 | if( FFABS( q2 - q0 ) < beta ) { | ||
2789 | pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] ); | ||
2790 | tc++; | ||
2791 | } | ||
2792 | |||
2793 | i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | ||
2794 | pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */ | ||
2795 | pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ | ||
2796 | } | ||
2797 | pix += ystride; | ||
2798 | } | ||
2799 | } | ||
2800 | } | ||
2801 | static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) | ||
2802 | { | ||
2803 | h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0); | ||
2804 | } | ||
2805 | static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) | ||
2806 | { | ||
2807 | h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0); | ||
2808 | } | ||
2809 | |||
2810 | static inline void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) | ||
2811 | { | ||
2812 | int d; | ||
2813 | for( d = 0; d < 16; d++ ) { | ||
2814 | const int p2 = pix[-3*xstride]; | ||
2815 | const int p1 = pix[-2*xstride]; | ||
2816 | const int p0 = pix[-1*xstride]; | ||
2817 | |||
2818 | const int q0 = pix[ 0*xstride]; | ||
2819 | const int q1 = pix[ 1*xstride]; | ||
2820 | const int q2 = pix[ 2*xstride]; | ||
2821 | |||
2822 | if( FFABS( p0 - q0 ) < alpha && | ||
2823 | FFABS( p1 - p0 ) < beta && | ||
2824 | FFABS( q1 - q0 ) < beta ) { | ||
2825 | |||
2826 | if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ | ||
2827 | if( FFABS( p2 - p0 ) < beta) | ||
2828 | { | ||
2829 | const int p3 = pix[-4*xstride]; | ||
2830 | /* p0', p1', p2' */ | ||
2831 | pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; | ||
2832 | pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; | ||
2833 | pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; | ||
2834 | } else { | ||
2835 | /* p0' */ | ||
2836 | pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | ||
2837 | } | ||
2838 | if( FFABS( q2 - q0 ) < beta) | ||
2839 | { | ||
2840 | const int q3 = pix[3*xstride]; | ||
2841 | /* q0', q1', q2' */ | ||
2842 | pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; | ||
2843 | pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; | ||
2844 | pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; | ||
2845 | } else { | ||
2846 | /* q0' */ | ||
2847 | pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | ||
2848 | } | ||
2849 | }else{ | ||
2850 | /* p0', q0' */ | ||
2851 | pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; | ||
2852 | pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; | ||
2853 | } | ||
2854 | } | ||
2855 | pix += ystride; | ||
2856 | } | ||
2857 | } | ||
2858 | static void h264_v_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) | ||
2859 | { | ||
2860 | h264_loop_filter_luma_intra_c(pix, stride, 1, alpha, beta); | ||
2861 | } | ||
2862 | static void h264_h_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) | ||
2863 | { | ||
2864 | h264_loop_filter_luma_intra_c(pix, 1, stride, alpha, beta); | ||
2865 | } | ||
2866 | |||
2867 | static inline void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0) | ||
2868 | { | ||
2869 | int i, d; | ||
2870 | for( i = 0; i < 4; i++ ) { | ||
2871 | const int tc = tc0[i]; | ||
2872 | if( tc <= 0 ) { | ||
2873 | pix += 2*ystride; | ||
2874 | continue; | ||
2875 | } | ||
2876 | for( d = 0; d < 2; d++ ) { | ||
2877 | const int p0 = pix[-1*xstride]; | ||
2878 | const int p1 = pix[-2*xstride]; | ||
2879 | const int q0 = pix[0]; | ||
2880 | const int q1 = pix[1*xstride]; | ||
2881 | |||
2882 | if( FFABS( p0 - q0 ) < alpha && | ||
2883 | FFABS( p1 - p0 ) < beta && | ||
2884 | FFABS( q1 - q0 ) < beta ) { | ||
2885 | |||
2886 | int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); | ||
2887 | |||
2888 | pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */ | ||
2889 | pix[0] = av_clip_uint8( q0 - delta ); /* q0' */ | ||
2890 | } | ||
2891 | pix += ystride; | ||
2892 | } | ||
2893 | } | ||
2894 | } | ||
2895 | static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) | ||
2896 | { | ||
2897 | h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0); | ||
2898 | } | ||
2899 | static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) | ||
2900 | { | ||
2901 | h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0); | ||
2902 | } | ||
2903 | |||
2904 | static inline void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) | ||
2905 | { | ||
2906 | int d; | ||
2907 | for( d = 0; d < 8; d++ ) { | ||
2908 | const int p0 = pix[-1*xstride]; | ||
2909 | const int p1 = pix[-2*xstride]; | ||
2910 | const int q0 = pix[0]; | ||
2911 | const int q1 = pix[1*xstride]; | ||
2912 | |||
2913 | if( FFABS( p0 - q0 ) < alpha && | ||
2914 | FFABS( p1 - p0 ) < beta && | ||
2915 | FFABS( q1 - q0 ) < beta ) { | ||
2916 | |||
2917 | pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ | ||
2918 | pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ | ||
2919 | } | ||
2920 | pix += ystride; | ||
2921 | } | ||
2922 | } | ||
2923 | static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) | ||
2924 | { | ||
2925 | h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta); | ||
2926 | } | ||
2927 | static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) | ||
2928 | { | ||
2929 | h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta); | ||
2930 | } | ||
2931 | |||
2932 | static inline int pix_abs16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
2933 | { | ||
2934 | int s, i; | ||
2935 | |||
2936 | s = 0; | ||
2937 | for(i=0;i<h;i++) { | ||
2938 | s += abs(pix1[0] - pix2[0]); | ||
2939 | s += abs(pix1[1] - pix2[1]); | ||
2940 | s += abs(pix1[2] - pix2[2]); | ||
2941 | s += abs(pix1[3] - pix2[3]); | ||
2942 | s += abs(pix1[4] - pix2[4]); | ||
2943 | s += abs(pix1[5] - pix2[5]); | ||
2944 | s += abs(pix1[6] - pix2[6]); | ||
2945 | s += abs(pix1[7] - pix2[7]); | ||
2946 | s += abs(pix1[8] - pix2[8]); | ||
2947 | s += abs(pix1[9] - pix2[9]); | ||
2948 | s += abs(pix1[10] - pix2[10]); | ||
2949 | s += abs(pix1[11] - pix2[11]); | ||
2950 | s += abs(pix1[12] - pix2[12]); | ||
2951 | s += abs(pix1[13] - pix2[13]); | ||
2952 | s += abs(pix1[14] - pix2[14]); | ||
2953 | s += abs(pix1[15] - pix2[15]); | ||
2954 | pix1 += line_size; | ||
2955 | pix2 += line_size; | ||
2956 | } | ||
2957 | return s; | ||
2958 | } | ||
2959 | |||
2960 | static int pix_abs16_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
2961 | { | ||
2962 | int s, i; | ||
2963 | |||
2964 | s = 0; | ||
2965 | for(i=0;i<h;i++) { | ||
2966 | s += abs(pix1[0] - avg2(pix2[0], pix2[1])); | ||
2967 | s += abs(pix1[1] - avg2(pix2[1], pix2[2])); | ||
2968 | s += abs(pix1[2] - avg2(pix2[2], pix2[3])); | ||
2969 | s += abs(pix1[3] - avg2(pix2[3], pix2[4])); | ||
2970 | s += abs(pix1[4] - avg2(pix2[4], pix2[5])); | ||
2971 | s += abs(pix1[5] - avg2(pix2[5], pix2[6])); | ||
2972 | s += abs(pix1[6] - avg2(pix2[6], pix2[7])); | ||
2973 | s += abs(pix1[7] - avg2(pix2[7], pix2[8])); | ||
2974 | s += abs(pix1[8] - avg2(pix2[8], pix2[9])); | ||
2975 | s += abs(pix1[9] - avg2(pix2[9], pix2[10])); | ||
2976 | s += abs(pix1[10] - avg2(pix2[10], pix2[11])); | ||
2977 | s += abs(pix1[11] - avg2(pix2[11], pix2[12])); | ||
2978 | s += abs(pix1[12] - avg2(pix2[12], pix2[13])); | ||
2979 | s += abs(pix1[13] - avg2(pix2[13], pix2[14])); | ||
2980 | s += abs(pix1[14] - avg2(pix2[14], pix2[15])); | ||
2981 | s += abs(pix1[15] - avg2(pix2[15], pix2[16])); | ||
2982 | pix1 += line_size; | ||
2983 | pix2 += line_size; | ||
2984 | } | ||
2985 | return s; | ||
2986 | } | ||
2987 | |||
2988 | static int pix_abs16_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
2989 | { | ||
2990 | int s, i; | ||
2991 | uint8_t *pix3 = pix2 + line_size; | ||
2992 | |||
2993 | s = 0; | ||
2994 | for(i=0;i<h;i++) { | ||
2995 | s += abs(pix1[0] - avg2(pix2[0], pix3[0])); | ||
2996 | s += abs(pix1[1] - avg2(pix2[1], pix3[1])); | ||
2997 | s += abs(pix1[2] - avg2(pix2[2], pix3[2])); | ||
2998 | s += abs(pix1[3] - avg2(pix2[3], pix3[3])); | ||
2999 | s += abs(pix1[4] - avg2(pix2[4], pix3[4])); | ||
3000 | s += abs(pix1[5] - avg2(pix2[5], pix3[5])); | ||
3001 | s += abs(pix1[6] - avg2(pix2[6], pix3[6])); | ||
3002 | s += abs(pix1[7] - avg2(pix2[7], pix3[7])); | ||
3003 | s += abs(pix1[8] - avg2(pix2[8], pix3[8])); | ||
3004 | s += abs(pix1[9] - avg2(pix2[9], pix3[9])); | ||
3005 | s += abs(pix1[10] - avg2(pix2[10], pix3[10])); | ||
3006 | s += abs(pix1[11] - avg2(pix2[11], pix3[11])); | ||
3007 | s += abs(pix1[12] - avg2(pix2[12], pix3[12])); | ||
3008 | s += abs(pix1[13] - avg2(pix2[13], pix3[13])); | ||
3009 | s += abs(pix1[14] - avg2(pix2[14], pix3[14])); | ||
3010 | s += abs(pix1[15] - avg2(pix2[15], pix3[15])); | ||
3011 | pix1 += line_size; | ||
3012 | pix2 += line_size; | ||
3013 | pix3 += line_size; | ||
3014 | } | ||
3015 | return s; | ||
3016 | } | ||
3017 | |||
3018 | static int pix_abs16_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
3019 | { | ||
3020 | int s, i; | ||
3021 | uint8_t *pix3 = pix2 + line_size; | ||
3022 | |||
3023 | s = 0; | ||
3024 | for(i=0;i<h;i++) { | ||
3025 | s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1])); | ||
3026 | s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2])); | ||
3027 | s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3])); | ||
3028 | s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4])); | ||
3029 | s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5])); | ||
3030 | s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6])); | ||
3031 | s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7])); | ||
3032 | s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8])); | ||
3033 | s += abs(pix1[8] - avg4(pix2[8], pix2[9], pix3[8], pix3[9])); | ||
3034 | s += abs(pix1[9] - avg4(pix2[9], pix2[10], pix3[9], pix3[10])); | ||
3035 | s += abs(pix1[10] - avg4(pix2[10], pix2[11], pix3[10], pix3[11])); | ||
3036 | s += abs(pix1[11] - avg4(pix2[11], pix2[12], pix3[11], pix3[12])); | ||
3037 | s += abs(pix1[12] - avg4(pix2[12], pix2[13], pix3[12], pix3[13])); | ||
3038 | s += abs(pix1[13] - avg4(pix2[13], pix2[14], pix3[13], pix3[14])); | ||
3039 | s += abs(pix1[14] - avg4(pix2[14], pix2[15], pix3[14], pix3[15])); | ||
3040 | s += abs(pix1[15] - avg4(pix2[15], pix2[16], pix3[15], pix3[16])); | ||
3041 | pix1 += line_size; | ||
3042 | pix2 += line_size; | ||
3043 | pix3 += line_size; | ||
3044 | } | ||
3045 | return s; | ||
3046 | } | ||
3047 | |||
3048 | static inline int pix_abs8_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
3049 | { | ||
3050 | int s, i; | ||
3051 | |||
3052 | s = 0; | ||
3053 | for(i=0;i<h;i++) { | ||
3054 | s += abs(pix1[0] - pix2[0]); | ||
3055 | s += abs(pix1[1] - pix2[1]); | ||
3056 | s += abs(pix1[2] - pix2[2]); | ||
3057 | s += abs(pix1[3] - pix2[3]); | ||
3058 | s += abs(pix1[4] - pix2[4]); | ||
3059 | s += abs(pix1[5] - pix2[5]); | ||
3060 | s += abs(pix1[6] - pix2[6]); | ||
3061 | s += abs(pix1[7] - pix2[7]); | ||
3062 | pix1 += line_size; | ||
3063 | pix2 += line_size; | ||
3064 | } | ||
3065 | return s; | ||
3066 | } | ||
3067 | |||
3068 | static int pix_abs8_x2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
3069 | { | ||
3070 | int s, i; | ||
3071 | |||
3072 | s = 0; | ||
3073 | for(i=0;i<h;i++) { | ||
3074 | s += abs(pix1[0] - avg2(pix2[0], pix2[1])); | ||
3075 | s += abs(pix1[1] - avg2(pix2[1], pix2[2])); | ||
3076 | s += abs(pix1[2] - avg2(pix2[2], pix2[3])); | ||
3077 | s += abs(pix1[3] - avg2(pix2[3], pix2[4])); | ||
3078 | s += abs(pix1[4] - avg2(pix2[4], pix2[5])); | ||
3079 | s += abs(pix1[5] - avg2(pix2[5], pix2[6])); | ||
3080 | s += abs(pix1[6] - avg2(pix2[6], pix2[7])); | ||
3081 | s += abs(pix1[7] - avg2(pix2[7], pix2[8])); | ||
3082 | pix1 += line_size; | ||
3083 | pix2 += line_size; | ||
3084 | } | ||
3085 | return s; | ||
3086 | } | ||
3087 | |||
3088 | static int pix_abs8_y2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
3089 | { | ||
3090 | int s, i; | ||
3091 | uint8_t *pix3 = pix2 + line_size; | ||
3092 | |||
3093 | s = 0; | ||
3094 | for(i=0;i<h;i++) { | ||
3095 | s += abs(pix1[0] - avg2(pix2[0], pix3[0])); | ||
3096 | s += abs(pix1[1] - avg2(pix2[1], pix3[1])); | ||
3097 | s += abs(pix1[2] - avg2(pix2[2], pix3[2])); | ||
3098 | s += abs(pix1[3] - avg2(pix2[3], pix3[3])); | ||
3099 | s += abs(pix1[4] - avg2(pix2[4], pix3[4])); | ||
3100 | s += abs(pix1[5] - avg2(pix2[5], pix3[5])); | ||
3101 | s += abs(pix1[6] - avg2(pix2[6], pix3[6])); | ||
3102 | s += abs(pix1[7] - avg2(pix2[7], pix3[7])); | ||
3103 | pix1 += line_size; | ||
3104 | pix2 += line_size; | ||
3105 | pix3 += line_size; | ||
3106 | } | ||
3107 | return s; | ||
3108 | } | ||
3109 | |||
3110 | static int pix_abs8_xy2_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) | ||
3111 | { | ||
3112 | int s, i; | ||
3113 | uint8_t *pix3 = pix2 + line_size; | ||
3114 | |||
3115 | s = 0; | ||
3116 | for(i=0;i<h;i++) { | ||
3117 | s += abs(pix1[0] - avg4(pix2[0], pix2[1], pix3[0], pix3[1])); | ||
3118 | s += abs(pix1[1] - avg4(pix2[1], pix2[2], pix3[1], pix3[2])); | ||
3119 | s += abs(pix1[2] - avg4(pix2[2], pix2[3], pix3[2], pix3[3])); | ||
3120 | s += abs(pix1[3] - avg4(pix2[3], pix2[4], pix3[3], pix3[4])); | ||
3121 | s += abs(pix1[4] - avg4(pix2[4], pix2[5], pix3[4], pix3[5])); | ||
3122 | s += abs(pix1[5] - avg4(pix2[5], pix2[6], pix3[5], pix3[6])); | ||
3123 | s += abs(pix1[6] - avg4(pix2[6], pix2[7], pix3[6], pix3[7])); | ||
3124 | s += abs(pix1[7] - avg4(pix2[7], pix2[8], pix3[7], pix3[8])); | ||
3125 | pix1 += line_size; | ||
3126 | pix2 += line_size; | ||
3127 | pix3 += line_size; | ||
3128 | } | ||
3129 | return s; | ||
3130 | } | ||
3131 | |||
3132 | static int nsse16_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){ | ||
3133 | MpegEncContext *c = v; | ||
3134 | int score1=0; | ||
3135 | int score2=0; | ||
3136 | int x,y; | ||
3137 | |||
3138 | for(y=0; y<h; y++){ | ||
3139 | for(x=0; x<16; x++){ | ||
3140 | score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]); | ||
3141 | } | ||
3142 | if(y+1<h){ | ||
3143 | for(x=0; x<15; x++){ | ||
3144 | score2+= FFABS( s1[x ] - s1[x +stride] | ||
3145 | - s1[x+1] + s1[x+1+stride]) | ||
3146 | -FFABS( s2[x ] - s2[x +stride] | ||
3147 | - s2[x+1] + s2[x+1+stride]); | ||
3148 | } | ||
3149 | } | ||
3150 | s1+= stride; | ||
3151 | s2+= stride; | ||
3152 | } | ||
3153 | |||
3154 | if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight; | ||
3155 | else return score1 + FFABS(score2)*8; | ||
3156 | } | ||
3157 | |||
3158 | static int nsse8_c(void *v, uint8_t *s1, uint8_t *s2, int stride, int h){ | ||
3159 | MpegEncContext *c = v; | ||
3160 | int score1=0; | ||
3161 | int score2=0; | ||
3162 | int x,y; | ||
3163 | |||
3164 | for(y=0; y<h; y++){ | ||
3165 | for(x=0; x<8; x++){ | ||
3166 | score1+= (s1[x ] - s2[x ])*(s1[x ] - s2[x ]); | ||
3167 | } | ||
3168 | if(y+1<h){ | ||
3169 | for(x=0; x<7; x++){ | ||
3170 | score2+= FFABS( s1[x ] - s1[x +stride] | ||
3171 | - s1[x+1] + s1[x+1+stride]) | ||
3172 | -FFABS( s2[x ] - s2[x +stride] | ||
3173 | - s2[x+1] + s2[x+1+stride]); | ||
3174 | } | ||
3175 | } | ||
3176 | s1+= stride; | ||
3177 | s2+= stride; | ||
3178 | } | ||
3179 | |||
3180 | if(c) return score1 + FFABS(score2)*c->avctx->nsse_weight; | ||
3181 | else return score1 + FFABS(score2)*8; | ||
3182 | } | ||
3183 | |||
3184 | static int try_8x8basis_c(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale){ | ||
3185 | int i; | ||
3186 | unsigned int sum=0; | ||
3187 | |||
3188 | for(i=0; i<8*8; i++){ | ||
3189 | int b= rem[i] + ((basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT)); | ||
3190 | int w= weight[i]; | ||
3191 | b>>= RECON_SHIFT; | ||
3192 | assert(-512<b && b<512); | ||
3193 | |||
3194 | sum += (w*b)*(w*b)>>4; | ||
3195 | } | ||
3196 | return sum>>2; | ||
3197 | } | ||
3198 | |||
3199 | static void add_8x8basis_c(int16_t rem[64], int16_t basis[64], int scale){ | ||
3200 | int i; | ||
3201 | |||
3202 | for(i=0; i<8*8; i++){ | ||
3203 | rem[i] += (basis[i]*scale + (1<<(BASIS_SHIFT - RECON_SHIFT-1)))>>(BASIS_SHIFT - RECON_SHIFT); | ||
3204 | } | ||
3205 | } | ||
3206 | |||
3207 | /** | ||
3208 | * permutes an 8x8 block. | ||
3209 | * @param block the block which will be permuted according to the given permutation vector | ||
3210 | * @param permutation the permutation vector | ||
3211 | * @param last the last non zero coefficient in scantable order, used to speed the permutation up | ||
3212 | * @param scantable the used scantable, this is only used to speed the permutation up, the block is not | ||
3213 | * (inverse) permutated to scantable order! | ||
3214 | */ | ||
3215 | void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last) | ||
3216 | { | ||
3217 | int i; | ||
3218 | DCTELEM temp[64]; | ||
3219 | |||
3220 | if(last<=0) return; | ||
3221 | //if(permutation[1]==1) return; //FIXME it is ok but not clean and might fail for some permutations | ||
3222 | |||
3223 | for(i=0; i<=last; i++){ | ||
3224 | const int j= scantable[i]; | ||
3225 | temp[j]= block[j]; | ||
3226 | block[j]=0; | ||
3227 | } | ||
3228 | |||
3229 | for(i=0; i<=last; i++){ | ||
3230 | const int j= scantable[i]; | ||
3231 | const int perm_j= permutation[j]; | ||
3232 | block[perm_j]= temp[j]; | ||
3233 | } | ||
3234 | } | ||
3235 | |||
3236 | static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h){ | ||
3237 | return 0; | ||
3238 | } | ||
3239 | |||
3240 | void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type){ | ||
3241 | int i; | ||
3242 | |||
3243 | memset(cmp, 0, sizeof(void*)*6); | ||
3244 | |||
3245 | for(i=0; i<6; i++){ | ||
3246 | switch(type&0xFF){ | ||
3247 | case FF_CMP_SAD: | ||
3248 | cmp[i]= c->sad[i]; | ||
3249 | break; | ||
3250 | case FF_CMP_SATD: | ||
3251 | cmp[i]= c->hadamard8_diff[i]; | ||
3252 | break; | ||
3253 | case FF_CMP_SSE: | ||
3254 | cmp[i]= c->sse[i]; | ||
3255 | break; | ||
3256 | case FF_CMP_DCT: | ||
3257 | cmp[i]= c->dct_sad[i]; | ||
3258 | break; | ||
3259 | case FF_CMP_DCT264: | ||
3260 | cmp[i]= c->dct264_sad[i]; | ||
3261 | break; | ||
3262 | case FF_CMP_DCTMAX: | ||
3263 | cmp[i]= c->dct_max[i]; | ||
3264 | break; | ||
3265 | case FF_CMP_PSNR: | ||
3266 | cmp[i]= c->quant_psnr[i]; | ||
3267 | break; | ||
3268 | case FF_CMP_BIT: | ||
3269 | cmp[i]= c->bit[i]; | ||
3270 | break; | ||
3271 | case FF_CMP_RD: | ||
3272 | cmp[i]= c->rd[i]; | ||
3273 | break; | ||
3274 | case FF_CMP_VSAD: | ||
3275 | cmp[i]= c->vsad[i]; | ||
3276 | break; | ||
3277 | case FF_CMP_VSSE: | ||
3278 | cmp[i]= c->vsse[i]; | ||
3279 | break; | ||
3280 | case FF_CMP_ZERO: | ||
3281 | cmp[i]= zero_cmp; | ||
3282 | break; | ||
3283 | case FF_CMP_NSSE: | ||
3284 | cmp[i]= c->nsse[i]; | ||
3285 | break; | ||
3286 | #if CONFIG_SNOW_ENCODER | ||
3287 | case FF_CMP_W53: | ||
3288 | cmp[i]= c->w53[i]; | ||
3289 | break; | ||
3290 | case FF_CMP_W97: | ||
3291 | cmp[i]= c->w97[i]; | ||
3292 | break; | ||
3293 | #endif | ||
3294 | default: | ||
3295 | av_log(NULL, AV_LOG_ERROR,"internal error in cmp function selection\n"); | ||
3296 | } | ||
3297 | } | ||
3298 | } | ||
3299 | |||
3300 | static void clear_block_c(DCTELEM *block) | ||
3301 | { | ||
3302 | memset(block, 0, sizeof(DCTELEM)*64); | ||
3303 | } | ||
3304 | |||
3305 | /** | ||
3306 | * memset(blocks, 0, sizeof(DCTELEM)*6*64) | ||
3307 | */ | ||
3308 | static void clear_blocks_c(DCTELEM *blocks) | ||
3309 | { | ||
3310 | memset(blocks, 0, sizeof(DCTELEM)*6*64); | ||
3311 | } | ||
3312 | |||
3313 | static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){ | ||
3314 | long i; | ||
3315 | for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ | ||
3316 | long a = *(long*)(src+i); | ||
3317 | long b = *(long*)(dst+i); | ||
3318 | *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80); | ||
3319 | } | ||
3320 | for(; i<w; i++) | ||
3321 | dst[i+0] += src[i+0]; | ||
3322 | } | ||
3323 | |||
3324 | static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ | ||
3325 | long i; | ||
3326 | for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ | ||
3327 | long a = *(long*)(src1+i); | ||
3328 | long b = *(long*)(src2+i); | ||
3329 | *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80); | ||
3330 | } | ||
3331 | for(; i<w; i++) | ||
3332 | dst[i] = src1[i]+src2[i]; | ||
3333 | } | ||
3334 | |||
3335 | static void diff_bytes_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ | ||
3336 | long i; | ||
3337 | #if !HAVE_FAST_UNALIGNED | ||
3338 | if((long)src2 & (sizeof(long)-1)){ | ||
3339 | for(i=0; i+7<w; i+=8){ | ||
3340 | dst[i+0] = src1[i+0]-src2[i+0]; | ||
3341 | dst[i+1] = src1[i+1]-src2[i+1]; | ||
3342 | dst[i+2] = src1[i+2]-src2[i+2]; | ||
3343 | dst[i+3] = src1[i+3]-src2[i+3]; | ||
3344 | dst[i+4] = src1[i+4]-src2[i+4]; | ||
3345 | dst[i+5] = src1[i+5]-src2[i+5]; | ||
3346 | dst[i+6] = src1[i+6]-src2[i+6]; | ||
3347 | dst[i+7] = src1[i+7]-src2[i+7]; | ||
3348 | } | ||
3349 | }else | ||
3350 | #endif | ||
3351 | for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ | ||
3352 | long a = *(long*)(src1+i); | ||
3353 | long b = *(long*)(src2+i); | ||
3354 | *(long*)(dst+i) = ((a|pb_80) - (b&pb_7f)) ^ ((a^b^pb_80)&pb_80); | ||
3355 | } | ||
3356 | for(; i<w; i++) | ||
3357 | dst[i+0] = src1[i+0]-src2[i+0]; | ||
3358 | } | ||
3359 | |||
3360 | static void add_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *diff, int w, int *left, int *left_top){ | ||
3361 | int i; | ||
3362 | uint8_t l, lt; | ||
3363 | |||
3364 | l= *left; | ||
3365 | lt= *left_top; | ||
3366 | |||
3367 | for(i=0; i<w; i++){ | ||
3368 | l= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF) + diff[i]; | ||
3369 | lt= src1[i]; | ||
3370 | dst[i]= l; | ||
3371 | } | ||
3372 | |||
3373 | *left= l; | ||
3374 | *left_top= lt; | ||
3375 | } | ||
3376 | |||
3377 | static void sub_hfyu_median_prediction_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top){ | ||
3378 | int i; | ||
3379 | uint8_t l, lt; | ||
3380 | |||
3381 | l= *left; | ||
3382 | lt= *left_top; | ||
3383 | |||
3384 | for(i=0; i<w; i++){ | ||
3385 | const int pred= mid_pred(l, src1[i], (l + src1[i] - lt)&0xFF); | ||
3386 | lt= src1[i]; | ||
3387 | l= src2[i]; | ||
3388 | dst[i]= l - pred; | ||
3389 | } | ||
3390 | |||
3391 | *left= l; | ||
3392 | *left_top= lt; | ||
3393 | } | ||
3394 | |||
3395 | #define BUTTERFLY2(o1,o2,i1,i2) \ | ||
3396 | o1= (i1)+(i2);\ | ||
3397 | o2= (i1)-(i2); | ||
3398 | |||
3399 | #define BUTTERFLY1(x,y) \ | ||
3400 | {\ | ||
3401 | int a,b;\ | ||
3402 | a= x;\ | ||
3403 | b= y;\ | ||
3404 | x= a+b;\ | ||
3405 | y= a-b;\ | ||
3406 | } | ||
3407 | |||
3408 | #define BUTTERFLYA(x,y) (FFABS((x)+(y)) + FFABS((x)-(y))) | ||
3409 | |||
3410 | static int hadamard8_diff8x8_c(/*MpegEncContext*/ void *s, uint8_t *dst, uint8_t *src, int stride, int h){ | ||
3411 | int i; | ||
3412 | int temp[64]; | ||
3413 | int sum=0; | ||
3414 | |||
3415 | assert(h==8); | ||
3416 | |||
3417 | for(i=0; i<8; i++){ | ||
3418 | //FIXME try pointer walks | ||
3419 | BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0]-dst[stride*i+0],src[stride*i+1]-dst[stride*i+1]); | ||
3420 | BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2]-dst[stride*i+2],src[stride*i+3]-dst[stride*i+3]); | ||
3421 | BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4]-dst[stride*i+4],src[stride*i+5]-dst[stride*i+5]); | ||
3422 | BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6]-dst[stride*i+6],src[stride*i+7]-dst[stride*i+7]); | ||
3423 | |||
3424 | BUTTERFLY1(temp[8*i+0], temp[8*i+2]); | ||
3425 | BUTTERFLY1(temp[8*i+1], temp[8*i+3]); | ||
3426 | BUTTERFLY1(temp[8*i+4], temp[8*i+6]); | ||
3427 | BUTTERFLY1(temp[8*i+5], temp[8*i+7]); | ||
3428 | |||
3429 | BUTTERFLY1(temp[8*i+0], temp[8*i+4]); | ||
3430 | BUTTERFLY1(temp[8*i+1], temp[8*i+5]); | ||
3431 | BUTTERFLY1(temp[8*i+2], temp[8*i+6]); | ||
3432 | BUTTERFLY1(temp[8*i+3], temp[8*i+7]); | ||
3433 | } | ||
3434 | |||
3435 | for(i=0; i<8; i++){ | ||
3436 | BUTTERFLY1(temp[8*0+i], temp[8*1+i]); | ||
3437 | BUTTERFLY1(temp[8*2+i], temp[8*3+i]); | ||
3438 | BUTTERFLY1(temp[8*4+i], temp[8*5+i]); | ||
3439 | BUTTERFLY1(temp[8*6+i], temp[8*7+i]); | ||
3440 | |||
3441 | BUTTERFLY1(temp[8*0+i], temp[8*2+i]); | ||
3442 | BUTTERFLY1(temp[8*1+i], temp[8*3+i]); | ||
3443 | BUTTERFLY1(temp[8*4+i], temp[8*6+i]); | ||
3444 | BUTTERFLY1(temp[8*5+i], temp[8*7+i]); | ||
3445 | |||
3446 | sum += | ||
3447 | BUTTERFLYA(temp[8*0+i], temp[8*4+i]) | ||
3448 | +BUTTERFLYA(temp[8*1+i], temp[8*5+i]) | ||
3449 | +BUTTERFLYA(temp[8*2+i], temp[8*6+i]) | ||
3450 | +BUTTERFLYA(temp[8*3+i], temp[8*7+i]); | ||
3451 | } | ||
3452 | #if 0 | ||
3453 | static int maxi=0; | ||
3454 | if(sum>maxi){ | ||
3455 | maxi=sum; | ||
3456 | printf("MAX:%d\n", maxi); | ||
3457 | } | ||
3458 | #endif | ||
3459 | return sum; | ||
3460 | } | ||
3461 | |||
3462 | static int hadamard8_intra8x8_c(/*MpegEncContext*/ void *s, uint8_t *src, uint8_t *dummy, int stride, int h){ | ||
3463 | int i; | ||
3464 | int temp[64]; | ||
3465 | int sum=0; | ||
3466 | |||
3467 | assert(h==8); | ||
3468 | |||
3469 | for(i=0; i<8; i++){ | ||
3470 | //FIXME try pointer walks | ||
3471 | BUTTERFLY2(temp[8*i+0], temp[8*i+1], src[stride*i+0],src[stride*i+1]); | ||
3472 | BUTTERFLY2(temp[8*i+2], temp[8*i+3], src[stride*i+2],src[stride*i+3]); | ||
3473 | BUTTERFLY2(temp[8*i+4], temp[8*i+5], src[stride*i+4],src[stride*i+5]); | ||
3474 | BUTTERFLY2(temp[8*i+6], temp[8*i+7], src[stride*i+6],src[stride*i+7]); | ||
3475 | |||
3476 | BUTTERFLY1(temp[8*i+0], temp[8*i+2]); | ||
3477 | BUTTERFLY1(temp[8*i+1], temp[8*i+3]); | ||
3478 | BUTTERFLY1(temp[8*i+4], temp[8*i+6]); | ||
3479 | BUTTERFLY1(temp[8*i+5], temp[8*i+7]); | ||
3480 | |||
3481 | BUTTERFLY1(temp[8*i+0], temp[8*i+4]); | ||
3482 | BUTTERFLY1(temp[8*i+1], temp[8*i+5]); | ||
3483 | BUTTERFLY1(temp[8*i+2], temp[8*i+6]); | ||
3484 | BUTTERFLY1(temp[8*i+3], temp[8*i+7]); | ||
3485 | } | ||
3486 | |||
3487 | for(i=0; i<8; i++){ | ||
3488 | BUTTERFLY1(temp[8*0+i], temp[8*1+i]); | ||
3489 | BUTTERFLY1(temp[8*2+i], temp[8*3+i]); | ||
3490 | BUTTERFLY1(temp[8*4+i], temp[8*5+i]); | ||
3491 | BUTTERFLY1(temp[8*6+i], temp[8*7+i]); | ||
3492 | |||
3493 | BUTTERFLY1(temp[8*0+i], temp[8*2+i]); | ||
3494 | BUTTERFLY1(temp[8*1+i], temp[8*3+i]); | ||
3495 | BUTTERFLY1(temp[8*4+i], temp[8*6+i]); | ||
3496 | BUTTERFLY1(temp[8*5+i], temp[8*7+i]); | ||
3497 | |||
3498 | sum += | ||
3499 | BUTTERFLYA(temp[8*0+i], temp[8*4+i]) | ||
3500 | +BUTTERFLYA(temp[8*1+i], temp[8*5+i]) | ||
3501 | +BUTTERFLYA(temp[8*2+i], temp[8*6+i]) | ||
3502 | +BUTTERFLYA(temp[8*3+i], temp[8*7+i]); | ||
3503 | } | ||
3504 | |||
3505 | sum -= FFABS(temp[8*0] + temp[8*4]); // -mean | ||
3506 | |||
3507 | return sum; | ||
3508 | } | ||
3509 | |||
3510 | static int dct_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ | ||
3511 | MpegEncContext * const s= (MpegEncContext *)c; | ||
3512 | DECLARE_ALIGNED_16(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]); | ||
3513 | DCTELEM * const temp= (DCTELEM*)aligned_temp; | ||
3514 | |||
3515 | assert(h==8); | ||
3516 | |||
3517 | s->dsp.diff_pixels(temp, src1, src2, stride); | ||
3518 | s->dsp.fdct(temp); | ||
3519 | return s->dsp.sum_abs_dctelem(temp); | ||
3520 | } | ||
3521 | |||
3522 | #if CONFIG_GPL | ||
3523 | #define DCT8_1D {\ | ||
3524 | const int s07 = SRC(0) + SRC(7);\ | ||
3525 | const int s16 = SRC(1) + SRC(6);\ | ||
3526 | const int s25 = SRC(2) + SRC(5);\ | ||
3527 | const int s34 = SRC(3) + SRC(4);\ | ||
3528 | const int a0 = s07 + s34;\ | ||
3529 | const int a1 = s16 + s25;\ | ||
3530 | const int a2 = s07 - s34;\ | ||
3531 | const int a3 = s16 - s25;\ | ||
3532 | const int d07 = SRC(0) - SRC(7);\ | ||
3533 | const int d16 = SRC(1) - SRC(6);\ | ||
3534 | const int d25 = SRC(2) - SRC(5);\ | ||
3535 | const int d34 = SRC(3) - SRC(4);\ | ||
3536 | const int a4 = d16 + d25 + (d07 + (d07>>1));\ | ||
3537 | const int a5 = d07 - d34 - (d25 + (d25>>1));\ | ||
3538 | const int a6 = d07 + d34 - (d16 + (d16>>1));\ | ||
3539 | const int a7 = d16 - d25 + (d34 + (d34>>1));\ | ||
3540 | DST(0, a0 + a1 ) ;\ | ||
3541 | DST(1, a4 + (a7>>2)) ;\ | ||
3542 | DST(2, a2 + (a3>>1)) ;\ | ||
3543 | DST(3, a5 + (a6>>2)) ;\ | ||
3544 | DST(4, a0 - a1 ) ;\ | ||
3545 | DST(5, a6 - (a5>>2)) ;\ | ||
3546 | DST(6, (a2>>1) - a3 ) ;\ | ||
3547 | DST(7, (a4>>2) - a7 ) ;\ | ||
3548 | } | ||
3549 | |||
3550 | static int dct264_sad8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ | ||
3551 | MpegEncContext * const s= (MpegEncContext *)c; | ||
3552 | DCTELEM dct[8][8]; | ||
3553 | int i; | ||
3554 | int sum=0; | ||
3555 | |||
3556 | s->dsp.diff_pixels(dct[0], src1, src2, stride); | ||
3557 | |||
3558 | #define SRC(x) dct[i][x] | ||
3559 | #define DST(x,v) dct[i][x]= v | ||
3560 | for( i = 0; i < 8; i++ ) | ||
3561 | DCT8_1D | ||
3562 | #undef SRC | ||
3563 | #undef DST | ||
3564 | |||
3565 | #define SRC(x) dct[x][i] | ||
3566 | #define DST(x,v) sum += FFABS(v) | ||
3567 | for( i = 0; i < 8; i++ ) | ||
3568 | DCT8_1D | ||
3569 | #undef SRC | ||
3570 | #undef DST | ||
3571 | return sum; | ||
3572 | } | ||
3573 | #endif | ||
3574 | |||
3575 | static int dct_max8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ | ||
3576 | MpegEncContext * const s= (MpegEncContext *)c; | ||
3577 | DECLARE_ALIGNED_8(uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]); | ||
3578 | DCTELEM * const temp= (DCTELEM*)aligned_temp; | ||
3579 | int sum=0, i; | ||
3580 | |||
3581 | assert(h==8); | ||
3582 | |||
3583 | s->dsp.diff_pixels(temp, src1, src2, stride); | ||
3584 | s->dsp.fdct(temp); | ||
3585 | |||
3586 | for(i=0; i<64; i++) | ||
3587 | sum= FFMAX(sum, FFABS(temp[i])); | ||
3588 | |||
3589 | return sum; | ||
3590 | } | ||
3591 | |||
3592 | static int quant_psnr8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ | ||
3593 | MpegEncContext * const s= (MpegEncContext *)c; | ||
3594 | DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64*2/8]); | ||
3595 | DCTELEM * const temp= (DCTELEM*)aligned_temp; | ||
3596 | DCTELEM * const bak = ((DCTELEM*)aligned_temp)+64; | ||
3597 | int sum=0, i; | ||
3598 | |||
3599 | assert(h==8); | ||
3600 | s->mb_intra=0; | ||
3601 | |||
3602 | s->dsp.diff_pixels(temp, src1, src2, stride); | ||
3603 | |||
3604 | memcpy(bak, temp, 64*sizeof(DCTELEM)); | ||
3605 | |||
3606 | s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); | ||
3607 | s->dct_unquantize_inter(s, temp, 0, s->qscale); | ||
3608 | ff_simple_idct(temp); //FIXME | ||
3609 | |||
3610 | for(i=0; i<64; i++) | ||
3611 | sum+= (temp[i]-bak[i])*(temp[i]-bak[i]); | ||
3612 | |||
3613 | return sum; | ||
3614 | } | ||
3615 | |||
3616 | static int rd8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ | ||
3617 | MpegEncContext * const s= (MpegEncContext *)c; | ||
3618 | const uint8_t *scantable= s->intra_scantable.permutated; | ||
3619 | DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]); | ||
3620 | DECLARE_ALIGNED_8 (uint64_t, aligned_bak[stride]); | ||
3621 | DCTELEM * const temp= (DCTELEM*)aligned_temp; | ||
3622 | uint8_t * const bak= (uint8_t*)aligned_bak; | ||
3623 | int i, last, run, bits, level, distortion, start_i; | ||
3624 | const int esc_length= s->ac_esc_length; | ||
3625 | uint8_t * length; | ||
3626 | uint8_t * last_length; | ||
3627 | |||
3628 | assert(h==8); | ||
3629 | |||
3630 | for(i=0; i<8; i++){ | ||
3631 | ((uint32_t*)(bak + i*stride))[0]= ((uint32_t*)(src2 + i*stride))[0]; | ||
3632 | ((uint32_t*)(bak + i*stride))[1]= ((uint32_t*)(src2 + i*stride))[1]; | ||
3633 | } | ||
3634 | |||
3635 | s->dsp.diff_pixels(temp, src1, src2, stride); | ||
3636 | |||
3637 | s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); | ||
3638 | |||
3639 | bits=0; | ||
3640 | |||
3641 | if (s->mb_intra) { | ||
3642 | start_i = 1; | ||
3643 | length = s->intra_ac_vlc_length; | ||
3644 | last_length= s->intra_ac_vlc_last_length; | ||
3645 | bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma | ||
3646 | } else { | ||
3647 | start_i = 0; | ||
3648 | length = s->inter_ac_vlc_length; | ||
3649 | last_length= s->inter_ac_vlc_last_length; | ||
3650 | } | ||
3651 | |||
3652 | if(last>=start_i){ | ||
3653 | run=0; | ||
3654 | for(i=start_i; i<last; i++){ | ||
3655 | int j= scantable[i]; | ||
3656 | level= temp[j]; | ||
3657 | |||
3658 | if(level){ | ||
3659 | level+=64; | ||
3660 | if((level&(~127)) == 0){ | ||
3661 | bits+= length[UNI_AC_ENC_INDEX(run, level)]; | ||
3662 | }else | ||
3663 | bits+= esc_length; | ||
3664 | run=0; | ||
3665 | }else | ||
3666 | run++; | ||
3667 | } | ||
3668 | i= scantable[last]; | ||
3669 | |||
3670 | level= temp[i] + 64; | ||
3671 | |||
3672 | assert(level - 64); | ||
3673 | |||
3674 | if((level&(~127)) == 0){ | ||
3675 | bits+= last_length[UNI_AC_ENC_INDEX(run, level)]; | ||
3676 | }else | ||
3677 | bits+= esc_length; | ||
3678 | |||
3679 | } | ||
3680 | |||
3681 | if(last>=0){ | ||
3682 | if(s->mb_intra) | ||
3683 | s->dct_unquantize_intra(s, temp, 0, s->qscale); | ||
3684 | else | ||
3685 | s->dct_unquantize_inter(s, temp, 0, s->qscale); | ||
3686 | } | ||
3687 | |||
3688 | s->dsp.idct_add(bak, stride, temp); | ||
3689 | |||
3690 | distortion= s->dsp.sse[1](NULL, bak, src1, stride, 8); | ||
3691 | |||
3692 | return distortion + ((bits*s->qscale*s->qscale*109 + 64)>>7); | ||
3693 | } | ||
3694 | |||
3695 | static int bit8x8_c(/*MpegEncContext*/ void *c, uint8_t *src1, uint8_t *src2, int stride, int h){ | ||
3696 | MpegEncContext * const s= (MpegEncContext *)c; | ||
3697 | const uint8_t *scantable= s->intra_scantable.permutated; | ||
3698 | DECLARE_ALIGNED_8 (uint64_t, aligned_temp[sizeof(DCTELEM)*64/8]); | ||
3699 | DCTELEM * const temp= (DCTELEM*)aligned_temp; | ||
3700 | int i, last, run, bits, level, start_i; | ||
3701 | const int esc_length= s->ac_esc_length; | ||
3702 | uint8_t * length; | ||
3703 | uint8_t * last_length; | ||
3704 | |||
3705 | assert(h==8); | ||
3706 | |||
3707 | s->dsp.diff_pixels(temp, src1, src2, stride); | ||
3708 | |||
3709 | s->block_last_index[0/*FIXME*/]= last= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); | ||
3710 | |||
3711 | bits=0; | ||
3712 | |||
3713 | if (s->mb_intra) { | ||
3714 | start_i = 1; | ||
3715 | length = s->intra_ac_vlc_length; | ||
3716 | last_length= s->intra_ac_vlc_last_length; | ||
3717 | bits+= s->luma_dc_vlc_length[temp[0] + 256]; //FIXME chroma | ||
3718 | } else { | ||
3719 | start_i = 0; | ||
3720 | length = s->inter_ac_vlc_length; | ||
3721 | last_length= s->inter_ac_vlc_last_length; | ||
3722 | } | ||
3723 | |||
3724 | if(last>=start_i){ | ||
3725 | run=0; | ||
3726 | for(i=start_i; i<last; i++){ | ||
3727 | int j= scantable[i]; | ||
3728 | level= temp[j]; | ||
3729 | |||
3730 | if(level){ | ||
3731 | level+=64; | ||
3732 | if((level&(~127)) == 0){ | ||
3733 | bits+= length[UNI_AC_ENC_INDEX(run, level)]; | ||
3734 | }else | ||
3735 | bits+= esc_length; | ||
3736 | run=0; | ||
3737 | }else | ||
3738 | run++; | ||
3739 | } | ||
3740 | i= scantable[last]; | ||
3741 | |||
3742 | level= temp[i] + 64; | ||
3743 | |||
3744 | assert(level - 64); | ||
3745 | |||
3746 | if((level&(~127)) == 0){ | ||
3747 | bits+= last_length[UNI_AC_ENC_INDEX(run, level)]; | ||
3748 | }else | ||
3749 | bits+= esc_length; | ||
3750 | } | ||
3751 | |||
3752 | return bits; | ||
3753 | } | ||
3754 | |||
3755 | #define VSAD_INTRA(size) \ | ||
3756 | static int vsad_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \ | ||
3757 | int score=0; \ | ||
3758 | int x,y; \ | ||
3759 | \ | ||
3760 | for(y=1; y<h; y++){ \ | ||
3761 | for(x=0; x<size; x+=4){ \ | ||
3762 | score+= FFABS(s[x ] - s[x +stride]) + FFABS(s[x+1] - s[x+1+stride]) \ | ||
3763 | +FFABS(s[x+2] - s[x+2+stride]) + FFABS(s[x+3] - s[x+3+stride]); \ | ||
3764 | } \ | ||
3765 | s+= stride; \ | ||
3766 | } \ | ||
3767 | \ | ||
3768 | return score; \ | ||
3769 | } | ||
3770 | VSAD_INTRA(8) | ||
3771 | VSAD_INTRA(16) | ||
3772 | |||
3773 | static int vsad16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){ | ||
3774 | int score=0; | ||
3775 | int x,y; | ||
3776 | |||
3777 | for(y=1; y<h; y++){ | ||
3778 | for(x=0; x<16; x++){ | ||
3779 | score+= FFABS(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | ||
3780 | } | ||
3781 | s1+= stride; | ||
3782 | s2+= stride; | ||
3783 | } | ||
3784 | |||
3785 | return score; | ||
3786 | } | ||
3787 | |||
3788 | #define SQ(a) ((a)*(a)) | ||
3789 | #define VSSE_INTRA(size) \ | ||
3790 | static int vsse_intra##size##_c(/*MpegEncContext*/ void *c, uint8_t *s, uint8_t *dummy, int stride, int h){ \ | ||
3791 | int score=0; \ | ||
3792 | int x,y; \ | ||
3793 | \ | ||
3794 | for(y=1; y<h; y++){ \ | ||
3795 | for(x=0; x<size; x+=4){ \ | ||
3796 | score+= SQ(s[x ] - s[x +stride]) + SQ(s[x+1] - s[x+1+stride]) \ | ||
3797 | +SQ(s[x+2] - s[x+2+stride]) + SQ(s[x+3] - s[x+3+stride]); \ | ||
3798 | } \ | ||
3799 | s+= stride; \ | ||
3800 | } \ | ||
3801 | \ | ||
3802 | return score; \ | ||
3803 | } | ||
3804 | VSSE_INTRA(8) | ||
3805 | VSSE_INTRA(16) | ||
3806 | |||
3807 | static int vsse16_c(/*MpegEncContext*/ void *c, uint8_t *s1, uint8_t *s2, int stride, int h){ | ||
3808 | int score=0; | ||
3809 | int x,y; | ||
3810 | |||
3811 | for(y=1; y<h; y++){ | ||
3812 | for(x=0; x<16; x++){ | ||
3813 | score+= SQ(s1[x ] - s2[x ] - s1[x +stride] + s2[x +stride]); | ||
3814 | } | ||
3815 | s1+= stride; | ||
3816 | s2+= stride; | ||
3817 | } | ||
3818 | |||
3819 | return score; | ||
3820 | } | ||
3821 | |||
3822 | static int ssd_int8_vs_int16_c(const int8_t *pix1, const int16_t *pix2, | ||
3823 | int size){ | ||
3824 | int score=0; | ||
3825 | int i; | ||
3826 | for(i=0; i<size; i++) | ||
3827 | score += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]); | ||
3828 | return score; | ||
3829 | } | ||
3830 | |||
3831 | WRAPPER8_16_SQ(hadamard8_diff8x8_c, hadamard8_diff16_c) | ||
3832 | WRAPPER8_16_SQ(hadamard8_intra8x8_c, hadamard8_intra16_c) | ||
3833 | WRAPPER8_16_SQ(dct_sad8x8_c, dct_sad16_c) | ||
3834 | #if CONFIG_GPL | ||
3835 | WRAPPER8_16_SQ(dct264_sad8x8_c, dct264_sad16_c) | ||
3836 | #endif | ||
3837 | WRAPPER8_16_SQ(dct_max8x8_c, dct_max16_c) | ||
3838 | WRAPPER8_16_SQ(quant_psnr8x8_c, quant_psnr16_c) | ||
3839 | WRAPPER8_16_SQ(rd8x8_c, rd16_c) | ||
3840 | WRAPPER8_16_SQ(bit8x8_c, bit16_c) | ||
3841 | #endif | ||
3842 | static void vector_fmul_c(float *dst, const float *src, int len){ | ||
3843 | int i; | ||
3844 | for(i=0; i<len; i++) | ||
3845 | dst[i] *= src[i]; | ||
3846 | } | ||
3847 | |||
3848 | static void vector_fmul_reverse_c(float *dst, const float *src0, const float *src1, int len){ | ||
3849 | int i; | ||
3850 | src1 += len-1; | ||
3851 | for(i=0; i<len; i++) | ||
3852 | dst[i] = src0[i] * src1[-i]; | ||
3853 | } | ||
3854 | |||
3855 | void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step){ | ||
3856 | int i; | ||
3857 | for(i=0; i<len; i++) | ||
3858 | dst[i*step] = src0[i] * src1[i] + src2[i] + src3; | ||
3859 | } | ||
3860 | |||
3861 | void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len){ | ||
3862 | int i,j; | ||
3863 | dst += len; | ||
3864 | win += len; | ||
3865 | src0+= len; | ||
3866 | for(i=-len, j=len-1; i<0; i++, j--) { | ||
3867 | float s0 = src0[i]; | ||
3868 | float s1 = src1[j]; | ||
3869 | float wi = win[i]; | ||
3870 | float wj = win[j]; | ||
3871 | dst[i] = s0*wj - s1*wi + add_bias; | ||
3872 | dst[j] = s0*wi + s1*wj + add_bias; | ||
3873 | } | ||
3874 | } | ||
3875 | #if 0 | ||
3876 | static void int32_to_float_fmul_scalar_c(float *dst, const int *src, float mul, int len){ | ||
3877 | int i; | ||
3878 | for(i=0; i<len; i++) | ||
3879 | dst[i] = src[i] * mul; | ||
3880 | } | ||
3881 | |||
3882 | static av_always_inline int float_to_int16_one(const float *src){ | ||
3883 | int_fast32_t tmp = *(const int32_t*)src; | ||
3884 | if(tmp & 0xf0000){ | ||
3885 | tmp = (0x43c0ffff - tmp)>>31; | ||
3886 | // is this faster on some gcc/cpu combinations? | ||
3887 | // if(tmp > 0x43c0ffff) tmp = 0xFFFF; | ||
3888 | // else tmp = 0; | ||
3889 | } | ||
3890 | return tmp - 0x8000; | ||
3891 | } | ||
3892 | |||
3893 | void ff_float_to_int16_c(int16_t *dst, const float *src, long len){ | ||
3894 | int i; | ||
3895 | for(i=0; i<len; i++) | ||
3896 | dst[i] = float_to_int16_one(src+i); | ||
3897 | } | ||
3898 | |||
3899 | void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels){ | ||
3900 | int i,j,c; | ||
3901 | if(channels==2){ | ||
3902 | for(i=0; i<len; i++){ | ||
3903 | dst[2*i] = float_to_int16_one(src[0]+i); | ||
3904 | dst[2*i+1] = float_to_int16_one(src[1]+i); | ||
3905 | } | ||
3906 | }else{ | ||
3907 | for(c=0; c<channels; c++) | ||
3908 | for(i=0, j=c; i<len; i++, j+=channels) | ||
3909 | dst[j] = float_to_int16_one(src[c]+i); | ||
3910 | } | ||
3911 | } | ||
3912 | |||
3913 | static void add_int16_c(int16_t * v1, int16_t * v2, int order) | ||
3914 | { | ||
3915 | while (order--) | ||
3916 | *v1++ += *v2++; | ||
3917 | } | ||
3918 | |||
3919 | static void sub_int16_c(int16_t * v1, int16_t * v2, int order) | ||
3920 | { | ||
3921 | while (order--) | ||
3922 | *v1++ -= *v2++; | ||
3923 | } | ||
3924 | |||
3925 | static int32_t scalarproduct_int16_c(int16_t * v1, int16_t * v2, int order, int shift) | ||
3926 | { | ||
3927 | int res = 0; | ||
3928 | |||
3929 | while (order--) | ||
3930 | res += (*v1++ * *v2++) >> shift; | ||
3931 | |||
3932 | return res; | ||
3933 | } | ||
3934 | |||
3935 | #define W0 2048 | ||
3936 | #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ | ||
3937 | #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ | ||
3938 | #define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */ | ||
3939 | #define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */ | ||
3940 | #define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */ | ||
3941 | #define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */ | ||
3942 | #define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */ | ||
3943 | |||
3944 | static void wmv2_idct_row(short * b) | ||
3945 | { | ||
3946 | int s1,s2; | ||
3947 | int a0,a1,a2,a3,a4,a5,a6,a7; | ||
3948 | /*step 1*/ | ||
3949 | a1 = W1*b[1]+W7*b[7]; | ||
3950 | a7 = W7*b[1]-W1*b[7]; | ||
3951 | a5 = W5*b[5]+W3*b[3]; | ||
3952 | a3 = W3*b[5]-W5*b[3]; | ||
3953 | a2 = W2*b[2]+W6*b[6]; | ||
3954 | a6 = W6*b[2]-W2*b[6]; | ||
3955 | a0 = W0*b[0]+W0*b[4]; | ||
3956 | a4 = W0*b[0]-W0*b[4]; | ||
3957 | /*step 2*/ | ||
3958 | s1 = (181*(a1-a5+a7-a3)+128)>>8;//1,3,5,7, | ||
3959 | s2 = (181*(a1-a5-a7+a3)+128)>>8; | ||
3960 | /*step 3*/ | ||
3961 | b[0] = (a0+a2+a1+a5 + (1<<7))>>8; | ||
3962 | b[1] = (a4+a6 +s1 + (1<<7))>>8; | ||
3963 | b[2] = (a4-a6 +s2 + (1<<7))>>8; | ||
3964 | b[3] = (a0-a2+a7+a3 + (1<<7))>>8; | ||
3965 | b[4] = (a0-a2-a7-a3 + (1<<7))>>8; | ||
3966 | b[5] = (a4-a6 -s2 + (1<<7))>>8; | ||
3967 | b[6] = (a4+a6 -s1 + (1<<7))>>8; | ||
3968 | b[7] = (a0+a2-a1-a5 + (1<<7))>>8; | ||
3969 | } | ||
3970 | static void wmv2_idct_col(short * b) | ||
3971 | { | ||
3972 | int s1,s2; | ||
3973 | int a0,a1,a2,a3,a4,a5,a6,a7; | ||
3974 | /*step 1, with extended precision*/ | ||
3975 | a1 = (W1*b[8*1]+W7*b[8*7] + 4)>>3; | ||
3976 | a7 = (W7*b[8*1]-W1*b[8*7] + 4)>>3; | ||
3977 | a5 = (W5*b[8*5]+W3*b[8*3] + 4)>>3; | ||
3978 | a3 = (W3*b[8*5]-W5*b[8*3] + 4)>>3; | ||
3979 | a2 = (W2*b[8*2]+W6*b[8*6] + 4)>>3; | ||
3980 | a6 = (W6*b[8*2]-W2*b[8*6] + 4)>>3; | ||
3981 | a0 = (W0*b[8*0]+W0*b[8*4] )>>3; | ||
3982 | a4 = (W0*b[8*0]-W0*b[8*4] )>>3; | ||
3983 | /*step 2*/ | ||
3984 | s1 = (181*(a1-a5+a7-a3)+128)>>8; | ||
3985 | s2 = (181*(a1-a5-a7+a3)+128)>>8; | ||
3986 | /*step 3*/ | ||
3987 | b[8*0] = (a0+a2+a1+a5 + (1<<13))>>14; | ||
3988 | b[8*1] = (a4+a6 +s1 + (1<<13))>>14; | ||
3989 | b[8*2] = (a4-a6 +s2 + (1<<13))>>14; | ||
3990 | b[8*3] = (a0-a2+a7+a3 + (1<<13))>>14; | ||
3991 | |||
3992 | b[8*4] = (a0-a2-a7-a3 + (1<<13))>>14; | ||
3993 | b[8*5] = (a4-a6 -s2 + (1<<13))>>14; | ||
3994 | b[8*6] = (a4+a6 -s1 + (1<<13))>>14; | ||
3995 | b[8*7] = (a0+a2-a1-a5 + (1<<13))>>14; | ||
3996 | } | ||
3997 | void ff_wmv2_idct_c(short * block){ | ||
3998 | int i; | ||
3999 | |||
4000 | for(i=0;i<64;i+=8){ | ||
4001 | wmv2_idct_row(block+i); | ||
4002 | } | ||
4003 | for(i=0;i<8;i++){ | ||
4004 | wmv2_idct_col(block+i); | ||
4005 | } | ||
4006 | } | ||
4007 | /* XXX: those functions should be suppressed ASAP when all IDCTs are | ||
4008 | converted */ | ||
4009 | static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block) | ||
4010 | { | ||
4011 | ff_wmv2_idct_c(block); | ||
4012 | put_pixels_clamped_c(block, dest, line_size); | ||
4013 | } | ||
4014 | static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block) | ||
4015 | { | ||
4016 | ff_wmv2_idct_c(block); | ||
4017 | add_pixels_clamped_c(block, dest, line_size); | ||
4018 | } | ||
4019 | static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block) | ||
4020 | { | ||
4021 | j_rev_dct (block); | ||
4022 | put_pixels_clamped_c(block, dest, line_size); | ||
4023 | } | ||
4024 | static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block) | ||
4025 | { | ||
4026 | j_rev_dct (block); | ||
4027 | add_pixels_clamped_c(block, dest, line_size); | ||
4028 | } | ||
4029 | |||
4030 | static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block) | ||
4031 | { | ||
4032 | j_rev_dct4 (block); | ||
4033 | put_pixels_clamped4_c(block, dest, line_size); | ||
4034 | } | ||
4035 | static void ff_jref_idct4_add(uint8_t *dest, int line_size, DCTELEM *block) | ||
4036 | { | ||
4037 | j_rev_dct4 (block); | ||
4038 | add_pixels_clamped4_c(block, dest, line_size); | ||
4039 | } | ||
4040 | |||
4041 | static void ff_jref_idct2_put(uint8_t *dest, int line_size, DCTELEM *block) | ||
4042 | { | ||
4043 | j_rev_dct2 (block); | ||
4044 | put_pixels_clamped2_c(block, dest, line_size); | ||
4045 | } | ||
4046 | static void ff_jref_idct2_add(uint8_t *dest, int line_size, DCTELEM *block) | ||
4047 | { | ||
4048 | j_rev_dct2 (block); | ||
4049 | add_pixels_clamped2_c(block, dest, line_size); | ||
4050 | } | ||
4051 | |||
4052 | static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block) | ||
4053 | { | ||
4054 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
4055 | |||
4056 | dest[0] = cm[(block[0] + 4)>>3]; | ||
4057 | } | ||
4058 | static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block) | ||
4059 | { | ||
4060 | uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; | ||
4061 | |||
4062 | dest[0] = cm[dest[0] + ((block[0] + 4)>>3)]; | ||
4063 | } | ||
4064 | |||
4065 | static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; } | ||
4066 | #endif | ||
4067 | /* init static data */ | ||
4068 | void dsputil_static_init(void) | ||
4069 | { | ||
4070 | int i; | ||
4071 | |||
4072 | for(i=0;i<256;i++) ff_cropTbl[i + MAX_NEG_CROP] = i; | ||
4073 | for(i=0;i<MAX_NEG_CROP;i++) { | ||
4074 | ff_cropTbl[i] = 0; | ||
4075 | ff_cropTbl[i + MAX_NEG_CROP + 256] = 255; | ||
4076 | } | ||
4077 | |||
4078 | for(i=0;i<512;i++) { | ||
4079 | ff_squareTbl[i] = (i - 256) * (i - 256); | ||
4080 | } | ||
4081 | |||
4082 | for(i=0; i<64; i++) inv_zigzag_direct16[ff_zigzag_direct[i]]= i+1; | ||
4083 | } | ||
4084 | |||
4085 | int ff_check_alignment(void){ | ||
4086 | static int did_fail=0; | ||
4087 | DECLARE_ALIGNED_16(int, aligned); | ||
4088 | |||
4089 | if((long)&aligned & 15){ | ||
4090 | if(!did_fail){ | ||
4091 | #if HAVE_MMX || HAVE_ALTIVEC | ||
4092 | av_log(NULL, AV_LOG_ERROR, | ||
4093 | "Compiler did not align stack variables. Libavcodec has been miscompiled\n" | ||
4094 | "and may be very slow or crash. This is not a bug in libavcodec,\n" | ||
4095 | "but in the compiler. You may try recompiling using gcc >= 4.2.\n" | ||
4096 | "Do not report crashes to FFmpeg developers.\n"); | ||
4097 | #endif | ||
4098 | did_fail=1; | ||
4099 | } | ||
4100 | return -1; | ||
4101 | } | ||
4102 | return 0; | ||
4103 | } | ||
4104 | |||
4105 | void dsputil_init(DSPContext* c) | ||
4106 | { | ||
4107 | ff_check_alignment(); | ||
4108 | |||
4109 | c->vector_fmul = vector_fmul_c; | ||
4110 | c->vector_fmul_reverse = vector_fmul_reverse_c; | ||
4111 | c->vector_fmul_add_add = ff_vector_fmul_add_add_c; | ||
4112 | c->vector_fmul_window = ff_vector_fmul_window_c; | ||
4113 | } | ||
4114 | |||
diff --git a/apps/codecs/libatrac/dsputil.h b/apps/codecs/libatrac/dsputil.h new file mode 100644 index 0000000000..3bb0ff77a5 --- /dev/null +++ b/apps/codecs/libatrac/dsputil.h | |||
@@ -0,0 +1,898 @@ | |||
1 | /* | ||
2 | * DSP utils | ||
3 | * Copyright (c) 2000, 2001, 2002 Fabrice Bellard | ||
4 | * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | /** | ||
24 | * @file libavcodec/dsputil.h | ||
25 | * DSP utils. | ||
26 | * note, many functions in here may use MMX which trashes the FPU state, it is | ||
27 | * absolutely necessary to call emms_c() between dsp & float/double code | ||
28 | */ | ||
29 | |||
30 | #ifndef AVCODEC_DSPUTIL_H | ||
31 | #define AVCODEC_DSPUTIL_H | ||
32 | |||
33 | #include "libavutil/intreadwrite.h" | ||
34 | #include "avcodec.h" | ||
35 | |||
36 | |||
37 | //#define DEBUG | ||
38 | /* dct code */ | ||
39 | typedef short DCTELEM; | ||
40 | typedef int DWTELEM; | ||
41 | typedef short IDWTELEM; | ||
42 | |||
43 | void fdct_ifast (DCTELEM *data); | ||
44 | void fdct_ifast248 (DCTELEM *data); | ||
45 | void ff_jpeg_fdct_islow (DCTELEM *data); | ||
46 | void ff_fdct248_islow (DCTELEM *data); | ||
47 | |||
48 | void j_rev_dct (DCTELEM *data); | ||
49 | void j_rev_dct4 (DCTELEM *data); | ||
50 | void j_rev_dct2 (DCTELEM *data); | ||
51 | void j_rev_dct1 (DCTELEM *data); | ||
52 | void ff_wmv2_idct_c(DCTELEM *data); | ||
53 | |||
54 | void ff_fdct_mmx(DCTELEM *block); | ||
55 | void ff_fdct_mmx2(DCTELEM *block); | ||
56 | void ff_fdct_sse2(DCTELEM *block); | ||
57 | |||
58 | void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride); | ||
59 | void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride); | ||
60 | void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride); | ||
61 | void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride); | ||
62 | void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block); | ||
63 | void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block); | ||
64 | void ff_h264_idct_add16_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); | ||
65 | void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); | ||
66 | void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); | ||
67 | void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); | ||
68 | |||
69 | void ff_vector_fmul_add_add_c(float *dst, const float *src0, const float *src1, | ||
70 | const float *src2, int src3, int blocksize, int step); | ||
71 | void ff_vector_fmul_window_c(float *dst, const float *src0, const float *src1, | ||
72 | const float *win, float add_bias, int len); | ||
73 | void ff_float_to_int16_c(int16_t *dst, const float *src, long len); | ||
74 | void ff_float_to_int16_interleave_c(int16_t *dst, const float **src, long len, int channels); | ||
75 | |||
76 | /* encoding scans */ | ||
77 | extern const uint8_t ff_alternate_horizontal_scan[64]; | ||
78 | extern const uint8_t ff_alternate_vertical_scan[64]; | ||
79 | extern const uint8_t ff_zigzag_direct[64]; | ||
80 | extern const uint8_t ff_zigzag248_direct[64]; | ||
81 | |||
82 | /* pixel operations */ | ||
83 | #define MAX_NEG_CROP 1024 | ||
84 | |||
85 | /* temporary */ | ||
86 | extern uint32_t ff_squareTbl[512]; | ||
87 | extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP]; | ||
88 | |||
89 | /* VP3 DSP functions */ | ||
90 | void ff_vp3_idct_c(DCTELEM *block/* align 16*/); | ||
91 | void ff_vp3_idct_put_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); | ||
92 | void ff_vp3_idct_add_c(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); | ||
93 | |||
94 | void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values); | ||
95 | void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values); | ||
96 | |||
97 | /* VP6 DSP functions */ | ||
98 | void ff_vp6_filter_diag4_c(uint8_t *dst, uint8_t *src, int stride, | ||
99 | const int16_t *h_weights, const int16_t *v_weights); | ||
100 | |||
101 | /* 1/2^n downscaling functions from imgconvert.c */ | ||
102 | void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); | ||
103 | void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); | ||
104 | void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); | ||
105 | void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); | ||
106 | |||
107 | void ff_gmc_c(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, | ||
108 | int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); | ||
109 | |||
110 | /* minimum alignment rules ;) | ||
111 | If you notice errors in the align stuff, need more alignment for some ASM code | ||
112 | for some CPU or need to use a function with less aligned data then send a mail | ||
113 | to the ffmpeg-devel mailing list, ... | ||
114 | |||
115 | !warning These alignments might not match reality, (missing attribute((align)) | ||
116 | stuff somewhere possible). | ||
117 | I (Michael) did not check them, these are just the alignments which I think | ||
118 | could be reached easily ... | ||
119 | |||
120 | !future video codecs might need functions with less strict alignment | ||
121 | */ | ||
122 | |||
123 | /* | ||
124 | void get_pixels_c(DCTELEM *block, const uint8_t *pixels, int line_size); | ||
125 | void diff_pixels_c(DCTELEM *block, const uint8_t *s1, const uint8_t *s2, int stride); | ||
126 | void put_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size); | ||
127 | void add_pixels_clamped_c(const DCTELEM *block, uint8_t *pixels, int line_size); | ||
128 | void clear_blocks_c(DCTELEM *blocks); | ||
129 | */ | ||
130 | |||
131 | /* add and put pixel (decoding) */ | ||
132 | // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16 | ||
133 | //h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4 | ||
134 | typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h); | ||
135 | typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h); | ||
136 | typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); | ||
137 | typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y); | ||
138 | typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset); | ||
139 | typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset); | ||
140 | |||
141 | #define DEF_OLD_QPEL(name)\ | ||
142 | void ff_put_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\ | ||
143 | void ff_put_no_rnd_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride);\ | ||
144 | void ff_avg_ ## name (uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); | ||
145 | |||
146 | DEF_OLD_QPEL(qpel16_mc11_old_c) | ||
147 | DEF_OLD_QPEL(qpel16_mc31_old_c) | ||
148 | DEF_OLD_QPEL(qpel16_mc12_old_c) | ||
149 | DEF_OLD_QPEL(qpel16_mc32_old_c) | ||
150 | DEF_OLD_QPEL(qpel16_mc13_old_c) | ||
151 | DEF_OLD_QPEL(qpel16_mc33_old_c) | ||
152 | DEF_OLD_QPEL(qpel8_mc11_old_c) | ||
153 | DEF_OLD_QPEL(qpel8_mc31_old_c) | ||
154 | DEF_OLD_QPEL(qpel8_mc12_old_c) | ||
155 | DEF_OLD_QPEL(qpel8_mc32_old_c) | ||
156 | DEF_OLD_QPEL(qpel8_mc13_old_c) | ||
157 | DEF_OLD_QPEL(qpel8_mc33_old_c) | ||
158 | |||
159 | #define CALL_2X_PIXELS(a, b, n)\ | ||
160 | static void a(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ | ||
161 | b(block , pixels , line_size, h);\ | ||
162 | b(block+n, pixels+n, line_size, h);\ | ||
163 | } | ||
164 | |||
165 | /* motion estimation */ | ||
166 | // h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2 | ||
167 | // although currently h<4 is not used as functions with width <8 are neither used nor implemented | ||
168 | typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/; | ||
169 | |||
170 | |||
171 | // for snow slices | ||
172 | typedef struct slice_buffer_s slice_buffer; | ||
173 | |||
174 | /** | ||
175 | * Scantable. | ||
176 | */ | ||
177 | typedef struct ScanTable{ | ||
178 | const uint8_t *scantable; | ||
179 | uint8_t permutated[64]; | ||
180 | uint8_t raster_end[64]; | ||
181 | #if ARCH_PPC | ||
182 | /** Used by dct_quantize_altivec to find last-non-zero */ | ||
183 | DECLARE_ALIGNED(16, uint8_t, inverse[64]); | ||
184 | #endif | ||
185 | } ScanTable; | ||
186 | |||
187 | void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable); | ||
188 | |||
189 | void ff_emulated_edge_mc(uint8_t *buf, uint8_t *src, int linesize, | ||
190 | int block_w, int block_h, | ||
191 | int src_x, int src_y, int w, int h); | ||
192 | |||
193 | /** | ||
194 | * DSPContext. | ||
195 | */ | ||
196 | typedef struct DSPContext { | ||
197 | /* pixel ops : interface with DCT */ | ||
198 | void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); | ||
199 | void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); | ||
200 | void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); | ||
201 | void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); | ||
202 | void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); | ||
203 | void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size); | ||
204 | void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size); | ||
205 | int (*sum_abs_dctelem)(DCTELEM *block/*align 16*/); | ||
206 | /** | ||
207 | * translational global motion compensation. | ||
208 | */ | ||
209 | void (*gmc1)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x16, int y16, int rounder); | ||
210 | /** | ||
211 | * global motion compensation. | ||
212 | */ | ||
213 | void (*gmc )(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int ox, int oy, | ||
214 | int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height); | ||
215 | void (*clear_block)(DCTELEM *block/*align 16*/); | ||
216 | void (*clear_blocks)(DCTELEM *blocks/*align 16*/); | ||
217 | int (*pix_sum)(uint8_t * pix, int line_size); | ||
218 | int (*pix_norm1)(uint8_t * pix, int line_size); | ||
219 | // 16x16 8x8 4x4 2x2 16x8 8x4 4x2 8x16 4x8 2x4 | ||
220 | |||
221 | me_cmp_func sad[6]; /* identical to pix_absAxA except additional void * */ | ||
222 | me_cmp_func sse[6]; | ||
223 | me_cmp_func hadamard8_diff[6]; | ||
224 | me_cmp_func dct_sad[6]; | ||
225 | me_cmp_func quant_psnr[6]; | ||
226 | me_cmp_func bit[6]; | ||
227 | me_cmp_func rd[6]; | ||
228 | me_cmp_func vsad[6]; | ||
229 | me_cmp_func vsse[6]; | ||
230 | me_cmp_func nsse[6]; | ||
231 | me_cmp_func w53[6]; | ||
232 | me_cmp_func w97[6]; | ||
233 | me_cmp_func dct_max[6]; | ||
234 | me_cmp_func dct264_sad[6]; | ||
235 | |||
236 | me_cmp_func me_pre_cmp[6]; | ||
237 | me_cmp_func me_cmp[6]; | ||
238 | me_cmp_func me_sub_cmp[6]; | ||
239 | me_cmp_func mb_cmp[6]; | ||
240 | me_cmp_func ildct_cmp[6]; //only width 16 used | ||
241 | me_cmp_func frame_skip_cmp[6]; //only width 8 used | ||
242 | |||
243 | int (*ssd_int8_vs_int16)(const int8_t *pix1, const int16_t *pix2, | ||
244 | int size); | ||
245 | |||
246 | /** | ||
247 | * Halfpel motion compensation with rounding (a+b+1)>>1. | ||
248 | * this is an array[4][4] of motion compensation functions for 4 | ||
249 | * horizontal blocksizes (8,16) and the 4 halfpel positions<br> | ||
250 | * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] | ||
251 | * @param block destination where the result is stored | ||
252 | * @param pixels source | ||
253 | * @param line_size number of bytes in a horizontal line of block | ||
254 | * @param h height | ||
255 | */ | ||
256 | op_pixels_func put_pixels_tab[4][4]; | ||
257 | |||
258 | /** | ||
259 | * Halfpel motion compensation with rounding (a+b+1)>>1. | ||
260 | * This is an array[4][4] of motion compensation functions for 4 | ||
261 | * horizontal blocksizes (8,16) and the 4 halfpel positions<br> | ||
262 | * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] | ||
263 | * @param block destination into which the result is averaged (a+b+1)>>1 | ||
264 | * @param pixels source | ||
265 | * @param line_size number of bytes in a horizontal line of block | ||
266 | * @param h height | ||
267 | */ | ||
268 | op_pixels_func avg_pixels_tab[4][4]; | ||
269 | |||
270 | /** | ||
271 | * Halfpel motion compensation with no rounding (a+b)>>1. | ||
272 | * this is an array[2][4] of motion compensation functions for 2 | ||
273 | * horizontal blocksizes (8,16) and the 4 halfpel positions<br> | ||
274 | * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] | ||
275 | * @param block destination where the result is stored | ||
276 | * @param pixels source | ||
277 | * @param line_size number of bytes in a horizontal line of block | ||
278 | * @param h height | ||
279 | */ | ||
280 | op_pixels_func put_no_rnd_pixels_tab[4][4]; | ||
281 | |||
282 | /** | ||
283 | * Halfpel motion compensation with no rounding (a+b)>>1. | ||
284 | * this is an array[2][4] of motion compensation functions for 2 | ||
285 | * horizontal blocksizes (8,16) and the 4 halfpel positions<br> | ||
286 | * *pixels_tab[ 0->16xH 1->8xH ][ xhalfpel + 2*yhalfpel ] | ||
287 | * @param block destination into which the result is averaged (a+b)>>1 | ||
288 | * @param pixels source | ||
289 | * @param line_size number of bytes in a horizontal line of block | ||
290 | * @param h height | ||
291 | */ | ||
292 | op_pixels_func avg_no_rnd_pixels_tab[4][4]; | ||
293 | |||
294 | void (*put_no_rnd_pixels_l2[2])(uint8_t *block/*align width (8 or 16)*/, const uint8_t *a/*align 1*/, const uint8_t *b/*align 1*/, int line_size, int h); | ||
295 | |||
296 | /** | ||
297 | * Thirdpel motion compensation with rounding (a+b+1)>>1. | ||
298 | * this is an array[12] of motion compensation functions for the 9 thirdpe | ||
299 | * positions<br> | ||
300 | * *pixels_tab[ xthirdpel + 4*ythirdpel ] | ||
301 | * @param block destination where the result is stored | ||
302 | * @param pixels source | ||
303 | * @param line_size number of bytes in a horizontal line of block | ||
304 | * @param h height | ||
305 | */ | ||
306 | tpel_mc_func put_tpel_pixels_tab[11]; //FIXME individual func ptr per width? | ||
307 | tpel_mc_func avg_tpel_pixels_tab[11]; //FIXME individual func ptr per width? | ||
308 | |||
309 | qpel_mc_func put_qpel_pixels_tab[2][16]; | ||
310 | qpel_mc_func avg_qpel_pixels_tab[2][16]; | ||
311 | qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]; | ||
312 | qpel_mc_func avg_no_rnd_qpel_pixels_tab[2][16]; | ||
313 | qpel_mc_func put_mspel_pixels_tab[8]; | ||
314 | |||
315 | /** | ||
316 | * h264 Chroma MC | ||
317 | */ | ||
318 | h264_chroma_mc_func put_h264_chroma_pixels_tab[3]; | ||
319 | /* This is really one func used in VC-1 decoding */ | ||
320 | h264_chroma_mc_func put_no_rnd_h264_chroma_pixels_tab[3]; | ||
321 | h264_chroma_mc_func avg_h264_chroma_pixels_tab[3]; | ||
322 | |||
323 | qpel_mc_func put_h264_qpel_pixels_tab[4][16]; | ||
324 | qpel_mc_func avg_h264_qpel_pixels_tab[4][16]; | ||
325 | |||
326 | qpel_mc_func put_2tap_qpel_pixels_tab[4][16]; | ||
327 | qpel_mc_func avg_2tap_qpel_pixels_tab[4][16]; | ||
328 | |||
329 | h264_weight_func weight_h264_pixels_tab[10]; | ||
330 | h264_biweight_func biweight_h264_pixels_tab[10]; | ||
331 | |||
332 | /* AVS specific */ | ||
333 | qpel_mc_func put_cavs_qpel_pixels_tab[2][16]; | ||
334 | qpel_mc_func avg_cavs_qpel_pixels_tab[2][16]; | ||
335 | void (*cavs_filter_lv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); | ||
336 | void (*cavs_filter_lh)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); | ||
337 | void (*cavs_filter_cv)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); | ||
338 | void (*cavs_filter_ch)(uint8_t *pix, int stride, int alpha, int beta, int tc, int bs1, int bs2); | ||
339 | void (*cavs_idct8_add)(uint8_t *dst, DCTELEM *block, int stride); | ||
340 | |||
341 | me_cmp_func pix_abs[2][4]; | ||
342 | |||
343 | /* huffyuv specific */ | ||
344 | void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w); | ||
345 | void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w); | ||
346 | void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w); | ||
347 | /** | ||
348 | * subtract huffyuv's variant of median prediction | ||
349 | * note, this might read from src1[-1], src2[-1] | ||
350 | */ | ||
351 | void (*sub_hfyu_median_prediction)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w, int *left, int *left_top); | ||
352 | void (*add_hfyu_median_prediction)(uint8_t *dst, uint8_t *top, uint8_t *diff, int w, int *left, int *left_top); | ||
353 | /* this might write to dst[w] */ | ||
354 | void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); | ||
355 | void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w); | ||
356 | |||
357 | void (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0); | ||
358 | void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0); | ||
359 | /* v/h_loop_filter_luma_intra: align 16 */ | ||
360 | void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); | ||
361 | void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); | ||
362 | void (*h264_v_loop_filter_chroma)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0); | ||
363 | void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0); | ||
364 | void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); | ||
365 | void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); | ||
366 | // h264_loop_filter_strength: simd only. the C version is inlined in h264.c | ||
367 | void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], | ||
368 | int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field); | ||
369 | |||
370 | void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale); | ||
371 | void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale); | ||
372 | |||
373 | void (*h261_loop_filter)(uint8_t *src, int stride); | ||
374 | |||
375 | void (*x8_v_loop_filter)(uint8_t *src, int stride, int qscale); | ||
376 | void (*x8_h_loop_filter)(uint8_t *src, int stride, int qscale); | ||
377 | |||
378 | void (*vp3_v_loop_filter)(uint8_t *src, int stride, int *bounding_values); | ||
379 | void (*vp3_h_loop_filter)(uint8_t *src, int stride, int *bounding_values); | ||
380 | |||
381 | void (*vp6_filter_diag4)(uint8_t *dst, uint8_t *src, int stride, | ||
382 | const int16_t *h_weights,const int16_t *v_weights); | ||
383 | |||
384 | /* assume len is a multiple of 4, and arrays are 16-byte aligned */ | ||
385 | void (*vorbis_inverse_coupling)(float *mag, float *ang, int blocksize); | ||
386 | void (*ac3_downmix)(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len); | ||
387 | /* no alignment needed */ | ||
388 | void (*flac_compute_autocorr)(const int32_t *data, int len, int lag, double *autoc); | ||
389 | /* assume len is a multiple of 8, and arrays are 16-byte aligned */ | ||
390 | void (*vector_fmul)(float *dst, const float *src, int len); | ||
391 | void (*vector_fmul_reverse)(float *dst, const float *src0, const float *src1, int len); | ||
392 | /* assume len is a multiple of 8, and src arrays are 16-byte aligned */ | ||
393 | void (*vector_fmul_add_add)(float *dst, const float *src0, const float *src1, const float *src2, int src3, int len, int step); | ||
394 | /* assume len is a multiple of 4, and arrays are 16-byte aligned */ | ||
395 | void (*vector_fmul_window)(float *dst, const float *src0, const float *src1, const float *win, float add_bias, int len); | ||
396 | /* assume len is a multiple of 8, and arrays are 16-byte aligned */ | ||
397 | void (*int32_to_float_fmul_scalar)(float *dst, const int *src, float mul, int len); | ||
398 | |||
399 | /* C version: convert floats from the range [384.0,386.0] to ints in [-32768,32767] | ||
400 | * simd versions: convert floats from [-32768.0,32767.0] without rescaling and arrays are 16byte aligned */ | ||
401 | void (*float_to_int16)(int16_t *dst, const float *src, long len); | ||
402 | void (*float_to_int16_interleave)(int16_t *dst, const float **src, long len, int channels); | ||
403 | |||
404 | /* (I)DCT */ | ||
405 | void (*fdct)(DCTELEM *block/* align 16*/); | ||
406 | void (*fdct248)(DCTELEM *block/* align 16*/); | ||
407 | |||
408 | /* IDCT really*/ | ||
409 | void (*idct)(DCTELEM *block/* align 16*/); | ||
410 | |||
411 | /** | ||
412 | * block -> idct -> clip to unsigned 8 bit -> dest. | ||
413 | * (-1392, 0, 0, ...) -> idct -> (-174, -174, ...) -> put -> (0, 0, ...) | ||
414 | * @param line_size size in bytes of a horizontal line of dest | ||
415 | */ | ||
416 | void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); | ||
417 | |||
418 | /** | ||
419 | * block -> idct -> add dest -> clip to unsigned 8 bit -> dest. | ||
420 | * @param line_size size in bytes of a horizontal line of dest | ||
421 | */ | ||
422 | void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); | ||
423 | |||
424 | /** | ||
425 | * idct input permutation. | ||
426 | * several optimized IDCTs need a permutated input (relative to the normal order of the reference | ||
427 | * IDCT) | ||
428 | * this permutation must be performed before the idct_put/add, note, normally this can be merged | ||
429 | * with the zigzag/alternate scan<br> | ||
430 | * an example to avoid confusion: | ||
431 | * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...) | ||
432 | * - (x -> referece dct -> reference idct -> x) | ||
433 | * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x) | ||
434 | * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...) | ||
435 | */ | ||
436 | uint8_t idct_permutation[64]; | ||
437 | int idct_permutation_type; | ||
438 | #define FF_NO_IDCT_PERM 1 | ||
439 | #define FF_LIBMPEG2_IDCT_PERM 2 | ||
440 | #define FF_SIMPLE_IDCT_PERM 3 | ||
441 | #define FF_TRANSPOSE_IDCT_PERM 4 | ||
442 | #define FF_PARTTRANS_IDCT_PERM 5 | ||
443 | #define FF_SSE2_IDCT_PERM 6 | ||
444 | |||
445 | int (*try_8x8basis)(int16_t rem[64], int16_t weight[64], int16_t basis[64], int scale); | ||
446 | void (*add_8x8basis)(int16_t rem[64], int16_t basis[64], int scale); | ||
447 | #define BASIS_SHIFT 16 | ||
448 | #define RECON_SHIFT 6 | ||
449 | |||
450 | void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w); | ||
451 | #define EDGE_WIDTH 16 | ||
452 | |||
453 | /* h264 functions */ | ||
454 | /* NOTE!!! if you implement any of h264_idct8_add, h264_idct8_add4 then you must implement all of them | ||
455 | NOTE!!! if you implement any of h264_idct_add, h264_idct_add16, h264_idct_add16intra, h264_idct_add8 then you must implement all of them | ||
456 | The reason for above, is that no 2 out of one list may use a different permutation. | ||
457 | */ | ||
458 | void (*h264_idct_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); | ||
459 | void (*h264_idct8_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); | ||
460 | void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); | ||
461 | void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); | ||
462 | void (*h264_dct)(DCTELEM block[4][4]); | ||
463 | void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); | ||
464 | void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); | ||
465 | void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); | ||
466 | void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); | ||
467 | |||
468 | /* snow wavelet */ | ||
469 | void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); | ||
470 | void (*horizontal_compose97i)(IDWTELEM *b, int width); | ||
471 | void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); | ||
472 | |||
473 | void (*prefetch)(void *mem, int stride, int h); | ||
474 | |||
475 | void (*shrink[4])(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); | ||
476 | |||
477 | /* vc1 functions */ | ||
478 | void (*vc1_inv_trans_8x8)(DCTELEM *b); | ||
479 | void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block); | ||
480 | void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block); | ||
481 | void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block); | ||
482 | void (*vc1_v_overlap)(uint8_t* src, int stride); | ||
483 | void (*vc1_h_overlap)(uint8_t* src, int stride); | ||
484 | /* put 8x8 block with bicubic interpolation and quarterpel precision | ||
485 | * last argument is actually round value instead of height | ||
486 | */ | ||
487 | op_pixels_func put_vc1_mspel_pixels_tab[16]; | ||
488 | |||
489 | /* intrax8 functions */ | ||
490 | void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize); | ||
491 | void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize, | ||
492 | int * range, int * sum, int edges); | ||
493 | |||
494 | /* ape functions */ | ||
495 | /** | ||
496 | * Add contents of the second vector to the first one. | ||
497 | * @param len length of vectors, should be multiple of 16 | ||
498 | */ | ||
499 | void (*add_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len); | ||
500 | /** | ||
501 | * Add contents of the second vector to the first one. | ||
502 | * @param len length of vectors, should be multiple of 16 | ||
503 | */ | ||
504 | void (*sub_int16)(int16_t *v1/*align 16*/, int16_t *v2, int len); | ||
505 | /** | ||
506 | * Calculate scalar product of two vectors. | ||
507 | * @param len length of vectors, should be multiple of 16 | ||
508 | * @param shift number of bits to discard from product | ||
509 | */ | ||
510 | int32_t (*scalarproduct_int16)(int16_t *v1, int16_t *v2/*align 16*/, int len, int shift); | ||
511 | |||
512 | /* rv30 functions */ | ||
513 | qpel_mc_func put_rv30_tpel_pixels_tab[4][16]; | ||
514 | qpel_mc_func avg_rv30_tpel_pixels_tab[4][16]; | ||
515 | |||
516 | /* rv40 functions */ | ||
517 | qpel_mc_func put_rv40_qpel_pixels_tab[4][16]; | ||
518 | qpel_mc_func avg_rv40_qpel_pixels_tab[4][16]; | ||
519 | h264_chroma_mc_func put_rv40_chroma_pixels_tab[3]; | ||
520 | h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3]; | ||
521 | } DSPContext; | ||
522 | |||
523 | void dsputil_static_init(void); | ||
524 | void dsputil_init(DSPContext* p); | ||
525 | |||
526 | int ff_check_alignment(void); | ||
527 | |||
528 | /** | ||
529 | * permute block according to permuatation. | ||
530 | * @param last last non zero element in scantable order | ||
531 | */ | ||
532 | void ff_block_permute(DCTELEM *block, uint8_t *permutation, const uint8_t *scantable, int last); | ||
533 | |||
534 | void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type); | ||
535 | |||
536 | #define BYTE_VEC32(c) ((c)*0x01010101UL) | ||
537 | |||
538 | static inline uint32_t rnd_avg32(uint32_t a, uint32_t b) | ||
539 | { | ||
540 | return (a | b) - (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); | ||
541 | } | ||
542 | |||
543 | static inline uint32_t no_rnd_avg32(uint32_t a, uint32_t b) | ||
544 | { | ||
545 | return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); | ||
546 | } | ||
547 | |||
548 | static inline int get_penalty_factor(int lambda, int lambda2, int type){ | ||
549 | switch(type&0xFF){ | ||
550 | default: | ||
551 | case FF_CMP_SAD: | ||
552 | return lambda>>FF_LAMBDA_SHIFT; | ||
553 | case FF_CMP_DCT: | ||
554 | return (3*lambda)>>(FF_LAMBDA_SHIFT+1); | ||
555 | case FF_CMP_W53: | ||
556 | return (4*lambda)>>(FF_LAMBDA_SHIFT); | ||
557 | case FF_CMP_W97: | ||
558 | return (2*lambda)>>(FF_LAMBDA_SHIFT); | ||
559 | case FF_CMP_SATD: | ||
560 | case FF_CMP_DCT264: | ||
561 | return (2*lambda)>>FF_LAMBDA_SHIFT; | ||
562 | case FF_CMP_RD: | ||
563 | case FF_CMP_PSNR: | ||
564 | case FF_CMP_SSE: | ||
565 | case FF_CMP_NSSE: | ||
566 | return lambda2>>FF_LAMBDA_SHIFT; | ||
567 | case FF_CMP_BIT: | ||
568 | return 1; | ||
569 | } | ||
570 | } | ||
571 | |||
572 | /** | ||
573 | * Empty mmx state. | ||
574 | * this must be called between any dsp function and float/double code. | ||
575 | * for example sin(); dsp->idct_put(); emms_c(); cos() | ||
576 | */ | ||
577 | #define emms_c() | ||
578 | |||
579 | /* should be defined by architectures supporting | ||
580 | one or more MultiMedia extension */ | ||
581 | int mm_support(void); | ||
582 | |||
583 | void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); | ||
584 | void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx); | ||
585 | void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx); | ||
586 | void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx); | ||
587 | void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx); | ||
588 | void dsputil_init_mmx(DSPContext* c, AVCodecContext *avctx); | ||
589 | void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx); | ||
590 | void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx); | ||
591 | void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); | ||
592 | |||
593 | #define DECLARE_ALIGNED_16(t, v) DECLARE_ALIGNED(16, t, v) | ||
594 | |||
595 | #if HAVE_MMX | ||
596 | |||
597 | #undef emms_c | ||
598 | |||
599 | extern int mm_flags; | ||
600 | |||
601 | void add_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); | ||
602 | void put_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); | ||
603 | void put_signed_pixels_clamped_mmx(const DCTELEM *block, uint8_t *pixels, int line_size); | ||
604 | |||
605 | static inline void emms(void) | ||
606 | { | ||
607 | __asm__ volatile ("emms;":::"memory"); | ||
608 | } | ||
609 | |||
610 | |||
611 | #define emms_c() \ | ||
612 | {\ | ||
613 | if (mm_flags & FF_MM_MMX)\ | ||
614 | emms();\ | ||
615 | } | ||
616 | |||
617 | void dsputil_init_pix_mmx(DSPContext* c, AVCodecContext *avctx); | ||
618 | |||
619 | #elif ARCH_ARM | ||
620 | |||
621 | extern int mm_flags; | ||
622 | |||
623 | #if HAVE_NEON | ||
624 | # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) | ||
625 | # define STRIDE_ALIGN 16 | ||
626 | #endif | ||
627 | |||
628 | #elif ARCH_PPC | ||
629 | |||
630 | extern int mm_flags; | ||
631 | |||
632 | #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) | ||
633 | #define STRIDE_ALIGN 16 | ||
634 | |||
635 | #elif HAVE_MMI | ||
636 | |||
637 | #define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(16, t, v) | ||
638 | #define STRIDE_ALIGN 16 | ||
639 | |||
640 | #else | ||
641 | |||
642 | #define mm_flags 0 | ||
643 | #define mm_support() 0 | ||
644 | |||
645 | #endif | ||
646 | |||
647 | #ifndef DECLARE_ALIGNED_8 | ||
648 | # define DECLARE_ALIGNED_8(t, v) DECLARE_ALIGNED(8, t, v) | ||
649 | #endif | ||
650 | |||
651 | #ifndef STRIDE_ALIGN | ||
652 | # define STRIDE_ALIGN 8 | ||
653 | #endif | ||
654 | |||
655 | /* PSNR */ | ||
656 | void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3], | ||
657 | int orig_linesize[3], int coded_linesize, | ||
658 | AVCodecContext *avctx); | ||
659 | |||
660 | /* FFT computation */ | ||
661 | |||
662 | /* NOTE: soon integer code will be added, so you must use the | ||
663 | FFTSample type */ | ||
664 | typedef float FFTSample; | ||
665 | |||
666 | struct MDCTContext; | ||
667 | |||
668 | typedef struct FFTComplex { | ||
669 | FFTSample re, im; | ||
670 | } FFTComplex; | ||
671 | |||
672 | typedef struct FFTContext { | ||
673 | int nbits; | ||
674 | int inverse; | ||
675 | uint16_t *revtab; | ||
676 | FFTComplex *exptab; | ||
677 | FFTComplex *exptab1; /* only used by SSE code */ | ||
678 | FFTComplex *tmp_buf; | ||
679 | void (*fft_permute)(struct FFTContext *s, FFTComplex *z); | ||
680 | void (*fft_calc)(struct FFTContext *s, FFTComplex *z); | ||
681 | void (*imdct_calc)(struct MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
682 | void (*imdct_half)(struct MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
683 | } FFTContext; | ||
684 | |||
685 | extern FFTSample* ff_cos_tabs[13]; | ||
686 | |||
687 | /** | ||
688 | * Sets up a complex FFT. | ||
689 | * @param nbits log2 of the length of the input array | ||
690 | * @param inverse if 0 perform the forward transform, if 1 perform the inverse | ||
691 | */ | ||
692 | int ff_fft_init(FFTContext *s, int nbits, int inverse); | ||
693 | void ff_fft_permute_c(FFTContext *s, FFTComplex *z); | ||
694 | void ff_fft_permute_sse(FFTContext *s, FFTComplex *z); | ||
695 | void ff_fft_calc_c(FFTContext *s, FFTComplex *z); | ||
696 | void ff_fft_calc_sse(FFTContext *s, FFTComplex *z); | ||
697 | void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z); | ||
698 | void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z); | ||
699 | void ff_fft_calc_altivec(FFTContext *s, FFTComplex *z); | ||
700 | |||
701 | /** | ||
702 | * Do the permutation needed BEFORE calling ff_fft_calc(). | ||
703 | */ | ||
704 | static inline void ff_fft_permute(FFTContext *s, FFTComplex *z) | ||
705 | { | ||
706 | s->fft_permute(s, z); | ||
707 | } | ||
708 | /** | ||
709 | * Do a complex FFT with the parameters defined in ff_fft_init(). The | ||
710 | * input data must be permuted before. No 1.0/sqrt(n) normalization is done. | ||
711 | */ | ||
712 | static inline void ff_fft_calc(FFTContext *s, FFTComplex *z) | ||
713 | { | ||
714 | s->fft_calc(s, z); | ||
715 | } | ||
716 | void ff_fft_end(FFTContext *s); | ||
717 | |||
718 | /* MDCT computation */ | ||
719 | |||
720 | typedef struct MDCTContext { | ||
721 | int n; /* size of MDCT (i.e. number of input data * 2) */ | ||
722 | int nbits; /* n = 2^nbits */ | ||
723 | /* pre/post rotation tables */ | ||
724 | FFTSample *tcos; | ||
725 | FFTSample *tsin; | ||
726 | FFTContext fft; | ||
727 | } MDCTContext; | ||
728 | |||
729 | static inline void ff_imdct_calc(MDCTContext *s, FFTSample *output, const FFTSample *input) | ||
730 | { | ||
731 | s->fft.imdct_calc(s, output, input); | ||
732 | } | ||
733 | static inline void ff_imdct_half(MDCTContext *s, FFTSample *output, const FFTSample *input) | ||
734 | { | ||
735 | s->fft.imdct_half(s, output, input); | ||
736 | } | ||
737 | |||
738 | /** | ||
739 | * Generate a Kaiser-Bessel Derived Window. | ||
740 | * @param window pointer to half window | ||
741 | * @param alpha determines window shape | ||
742 | * @param n size of half window | ||
743 | */ | ||
744 | void ff_kbd_window_init(float *window, float alpha, int n); | ||
745 | |||
746 | /** | ||
747 | * Generate a sine window. | ||
748 | * @param window pointer to half window | ||
749 | * @param n size of half window | ||
750 | */ | ||
751 | void ff_sine_window_init(float *window, int n); | ||
752 | extern float ff_sine_128 [ 128]; | ||
753 | extern float ff_sine_256 [ 256]; | ||
754 | extern float ff_sine_512 [ 512]; | ||
755 | extern float ff_sine_1024[1024]; | ||
756 | extern float ff_sine_2048[2048]; | ||
757 | extern float ff_sine_4096[4096]; | ||
758 | extern float *ff_sine_windows[6]; | ||
759 | |||
760 | int ff_mdct_init(MDCTContext *s, int nbits, int inverse); | ||
761 | void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
762 | void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
763 | void ff_imdct_calc_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
764 | void ff_imdct_half_3dn(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
765 | void ff_imdct_calc_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
766 | void ff_imdct_half_3dn2(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
767 | void ff_imdct_calc_sse(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
768 | void ff_imdct_half_sse(MDCTContext *s, FFTSample *output, const FFTSample *input); | ||
769 | void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input); | ||
770 | void ff_mdct_end(MDCTContext *s); | ||
771 | |||
772 | /* Real Discrete Fourier Transform */ | ||
773 | |||
774 | enum RDFTransformType { | ||
775 | RDFT, | ||
776 | IRDFT, | ||
777 | RIDFT, | ||
778 | IRIDFT, | ||
779 | }; | ||
780 | |||
781 | typedef struct { | ||
782 | int nbits; | ||
783 | int inverse; | ||
784 | int sign_convention; | ||
785 | |||
786 | /* pre/post rotation tables */ | ||
787 | FFTSample *tcos; | ||
788 | FFTSample *tsin; | ||
789 | FFTContext fft; | ||
790 | } RDFTContext; | ||
791 | |||
792 | /** | ||
793 | * Sets up a real FFT. | ||
794 | * @param nbits log2 of the length of the input array | ||
795 | * @param trans the type of transform | ||
796 | */ | ||
797 | int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans); | ||
798 | void ff_rdft_calc(RDFTContext *s, FFTSample *data); | ||
799 | void ff_rdft_end(RDFTContext *s); | ||
800 | |||
801 | #define WRAPPER8_16(name8, name16)\ | ||
802 | static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ | ||
803 | return name8(s, dst , src , stride, h)\ | ||
804 | +name8(s, dst+8 , src+8 , stride, h);\ | ||
805 | } | ||
806 | |||
807 | #define WRAPPER8_16_SQ(name8, name16)\ | ||
808 | static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ | ||
809 | int score=0;\ | ||
810 | score +=name8(s, dst , src , stride, 8);\ | ||
811 | score +=name8(s, dst+8 , src+8 , stride, 8);\ | ||
812 | if(h==16){\ | ||
813 | dst += 8*stride;\ | ||
814 | src += 8*stride;\ | ||
815 | score +=name8(s, dst , src , stride, 8);\ | ||
816 | score +=name8(s, dst+8 , src+8 , stride, 8);\ | ||
817 | }\ | ||
818 | return score;\ | ||
819 | } | ||
820 | |||
821 | |||
822 | static inline void copy_block2(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) | ||
823 | { | ||
824 | int i; | ||
825 | for(i=0; i<h; i++) | ||
826 | { | ||
827 | AV_WN16(dst , AV_RN16(src )); | ||
828 | dst+=dstStride; | ||
829 | src+=srcStride; | ||
830 | } | ||
831 | } | ||
832 | |||
833 | static inline void copy_block4(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) | ||
834 | { | ||
835 | int i; | ||
836 | for(i=0; i<h; i++) | ||
837 | { | ||
838 | AV_WN32(dst , AV_RN32(src )); | ||
839 | dst+=dstStride; | ||
840 | src+=srcStride; | ||
841 | } | ||
842 | } | ||
843 | |||
844 | static inline void copy_block8(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) | ||
845 | { | ||
846 | int i; | ||
847 | for(i=0; i<h; i++) | ||
848 | { | ||
849 | AV_WN32(dst , AV_RN32(src )); | ||
850 | AV_WN32(dst+4 , AV_RN32(src+4 )); | ||
851 | dst+=dstStride; | ||
852 | src+=srcStride; | ||
853 | } | ||
854 | } | ||
855 | |||
856 | static inline void copy_block9(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) | ||
857 | { | ||
858 | int i; | ||
859 | for(i=0; i<h; i++) | ||
860 | { | ||
861 | AV_WN32(dst , AV_RN32(src )); | ||
862 | AV_WN32(dst+4 , AV_RN32(src+4 )); | ||
863 | dst[8]= src[8]; | ||
864 | dst+=dstStride; | ||
865 | src+=srcStride; | ||
866 | } | ||
867 | } | ||
868 | |||
869 | static inline void copy_block16(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) | ||
870 | { | ||
871 | int i; | ||
872 | for(i=0; i<h; i++) | ||
873 | { | ||
874 | AV_WN32(dst , AV_RN32(src )); | ||
875 | AV_WN32(dst+4 , AV_RN32(src+4 )); | ||
876 | AV_WN32(dst+8 , AV_RN32(src+8 )); | ||
877 | AV_WN32(dst+12, AV_RN32(src+12)); | ||
878 | dst+=dstStride; | ||
879 | src+=srcStride; | ||
880 | } | ||
881 | } | ||
882 | |||
883 | static inline void copy_block17(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h) | ||
884 | { | ||
885 | int i; | ||
886 | for(i=0; i<h; i++) | ||
887 | { | ||
888 | AV_WN32(dst , AV_RN32(src )); | ||
889 | AV_WN32(dst+4 , AV_RN32(src+4 )); | ||
890 | AV_WN32(dst+8 , AV_RN32(src+8 )); | ||
891 | AV_WN32(dst+12, AV_RN32(src+12)); | ||
892 | dst[16]= src[16]; | ||
893 | dst+=dstStride; | ||
894 | src+=srcStride; | ||
895 | } | ||
896 | } | ||
897 | |||
898 | #endif /* AVCODEC_DSPUTIL_H */ | ||
diff --git a/apps/codecs/libatrac/ffmpeg_config.h b/apps/codecs/libatrac/ffmpeg_config.h new file mode 100644 index 0000000000..707e14df52 --- /dev/null +++ b/apps/codecs/libatrac/ffmpeg_config.h | |||
@@ -0,0 +1,14 @@ | |||
1 | /* Automatically generated by configure - do not modify */ | ||
2 | #ifndef _FFMPEG_CONFIG_H | ||
3 | #define _FFMPEG_CONFIG_H | ||
4 | // CHECK THIS : #include "codecs.h" | ||
5 | |||
6 | #ifdef CPU_ARM | ||
7 | #define CONFIG_ALIGN 1 | ||
8 | #endif | ||
9 | |||
10 | #ifdef ROCKBOX_BIG_ENDIAN | ||
11 | #define WORDS_BIGENDIAN | ||
12 | #endif | ||
13 | |||
14 | #endif | ||
diff --git a/apps/codecs/libatrac/fft.c b/apps/codecs/libatrac/fft.c new file mode 100644 index 0000000000..a3f1151472 --- /dev/null +++ b/apps/codecs/libatrac/fft.c | |||
@@ -0,0 +1,374 @@ | |||
1 | /* | ||
2 | * FFT/IFFT transforms | ||
3 | * Copyright (c) 2008 Loren Merritt | ||
4 | * Copyright (c) 2002 Fabrice Bellard | ||
5 | * Partly based on libdjbfft by D. J. Bernstein | ||
6 | * | ||
7 | * This file is part of FFmpeg. | ||
8 | * | ||
9 | * FFmpeg is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU Lesser General Public | ||
11 | * License as published by the Free Software Foundation; either | ||
12 | * version 2.1 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * FFmpeg is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * Lesser General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU Lesser General Public | ||
20 | * License along with FFmpeg; if not, write to the Free Software | ||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
22 | */ | ||
23 | |||
24 | /** | ||
25 | * @file libavcodec/fft.c | ||
26 | * FFT/IFFT transforms. | ||
27 | */ | ||
28 | |||
29 | #include "dsputil.h" | ||
30 | |||
31 | /* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ | ||
32 | DECLARE_ALIGNED_16(FFTSample, ff_cos_16[8]); | ||
33 | DECLARE_ALIGNED_16(FFTSample, ff_cos_32[16]); | ||
34 | DECLARE_ALIGNED_16(FFTSample, ff_cos_64[32]); | ||
35 | DECLARE_ALIGNED_16(FFTSample, ff_cos_128[64]); | ||
36 | DECLARE_ALIGNED_16(FFTSample, ff_cos_256[128]); | ||
37 | DECLARE_ALIGNED_16(FFTSample, ff_cos_512[256]); | ||
38 | DECLARE_ALIGNED_16(FFTSample, ff_cos_1024[512]); | ||
39 | DECLARE_ALIGNED_16(FFTSample, ff_cos_2048[1024]); | ||
40 | DECLARE_ALIGNED_16(FFTSample, ff_cos_4096[2048]); | ||
41 | DECLARE_ALIGNED_16(FFTSample, ff_cos_8192[4096]); | ||
42 | DECLARE_ALIGNED_16(FFTSample, ff_cos_16384[8192]); | ||
43 | DECLARE_ALIGNED_16(FFTSample, ff_cos_32768[16384]); | ||
44 | DECLARE_ALIGNED_16(FFTSample, ff_cos_65536[32768]); | ||
45 | FFTSample *ff_cos_tabs[] = { | ||
46 | ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024, | ||
47 | ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536, | ||
48 | }; | ||
49 | |||
50 | static int split_radix_permutation(int i, int n, int inverse) | ||
51 | { | ||
52 | int m; | ||
53 | if(n <= 2) return i&1; | ||
54 | m = n >> 1; | ||
55 | if(!(i&m)) return split_radix_permutation(i, m, inverse)*2; | ||
56 | m >>= 1; | ||
57 | if(inverse == !(i&m)) return split_radix_permutation(i, m, inverse)*4 + 1; | ||
58 | else return split_radix_permutation(i, m, inverse)*4 - 1; | ||
59 | } | ||
60 | |||
61 | av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) | ||
62 | { | ||
63 | int i, j, m, n; | ||
64 | float alpha, c1, s1, s2; | ||
65 | int split_radix = 1; | ||
66 | int av_unused has_vectors; | ||
67 | |||
68 | if (nbits < 2 || nbits > 16) | ||
69 | goto fail; | ||
70 | s->nbits = nbits; | ||
71 | n = 1 << nbits; | ||
72 | |||
73 | s->tmp_buf = NULL; | ||
74 | s->exptab = av_malloc((n / 2) * sizeof(FFTComplex)); | ||
75 | if (!s->exptab) | ||
76 | goto fail; | ||
77 | s->revtab = av_malloc(n * sizeof(uint16_t)); | ||
78 | if (!s->revtab) | ||
79 | goto fail; | ||
80 | s->inverse = inverse; | ||
81 | |||
82 | s2 = inverse ? 1.0 : -1.0; | ||
83 | |||
84 | s->fft_permute = ff_fft_permute_c; | ||
85 | s->fft_calc = ff_fft_calc_c; | ||
86 | s->imdct_calc = ff_imdct_calc_c; | ||
87 | s->imdct_half = ff_imdct_half_c; | ||
88 | s->exptab1 = NULL; | ||
89 | |||
90 | #if HAVE_MMX && HAVE_YASM | ||
91 | has_vectors = mm_support(); | ||
92 | if (has_vectors & FF_MM_SSE && HAVE_SSE) { | ||
93 | /* SSE for P3/P4/K8 */ | ||
94 | s->imdct_calc = ff_imdct_calc_sse; | ||
95 | s->imdct_half = ff_imdct_half_sse; | ||
96 | s->fft_permute = ff_fft_permute_sse; | ||
97 | s->fft_calc = ff_fft_calc_sse; | ||
98 | } else if (has_vectors & FF_MM_3DNOWEXT && HAVE_AMD3DNOWEXT) { | ||
99 | /* 3DNowEx for K7 */ | ||
100 | s->imdct_calc = ff_imdct_calc_3dn2; | ||
101 | s->imdct_half = ff_imdct_half_3dn2; | ||
102 | s->fft_calc = ff_fft_calc_3dn2; | ||
103 | } else if (has_vectors & FF_MM_3DNOW && HAVE_AMD3DNOW) { | ||
104 | /* 3DNow! for K6-2/3 */ | ||
105 | s->imdct_calc = ff_imdct_calc_3dn; | ||
106 | s->imdct_half = ff_imdct_half_3dn; | ||
107 | s->fft_calc = ff_fft_calc_3dn; | ||
108 | } | ||
109 | #elif HAVE_ALTIVEC | ||
110 | has_vectors = mm_support(); | ||
111 | if (has_vectors & FF_MM_ALTIVEC) { | ||
112 | s->fft_calc = ff_fft_calc_altivec; | ||
113 | split_radix = 0; | ||
114 | } | ||
115 | #endif | ||
116 | |||
117 | if (split_radix) { | ||
118 | for(j=4; j<=nbits; j++) { | ||
119 | int m = 1<<j; | ||
120 | double freq = 2*M_PI/m; | ||
121 | FFTSample *tab = ff_cos_tabs[j-4]; | ||
122 | for(i=0; i<=m/4; i++) | ||
123 | tab[i] = cos(i*freq); | ||
124 | for(i=1; i<m/4; i++) | ||
125 | tab[m/2-i] = tab[i]; | ||
126 | } | ||
127 | for(i=0; i<n; i++) | ||
128 | s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i; | ||
129 | s->tmp_buf = av_malloc(n * sizeof(FFTComplex)); | ||
130 | } else { | ||
131 | int np, nblocks, np2, l; | ||
132 | FFTComplex *q; | ||
133 | |||
134 | for(i=0; i<(n/2); i++) { | ||
135 | alpha = 2 * M_PI * (float)i / (float)n; | ||
136 | c1 = cos(alpha); | ||
137 | s1 = sin(alpha) * s2; | ||
138 | s->exptab[i].re = c1; | ||
139 | s->exptab[i].im = s1; | ||
140 | } | ||
141 | |||
142 | np = 1 << nbits; | ||
143 | nblocks = np >> 3; | ||
144 | np2 = np >> 1; | ||
145 | s->exptab1 = av_malloc(np * 2 * sizeof(FFTComplex)); | ||
146 | if (!s->exptab1) | ||
147 | goto fail; | ||
148 | q = s->exptab1; | ||
149 | do { | ||
150 | for(l = 0; l < np2; l += 2 * nblocks) { | ||
151 | *q++ = s->exptab[l]; | ||
152 | *q++ = s->exptab[l + nblocks]; | ||
153 | |||
154 | q->re = -s->exptab[l].im; | ||
155 | q->im = s->exptab[l].re; | ||
156 | q++; | ||
157 | q->re = -s->exptab[l + nblocks].im; | ||
158 | q->im = s->exptab[l + nblocks].re; | ||
159 | q++; | ||
160 | } | ||
161 | nblocks = nblocks >> 1; | ||
162 | } while (nblocks != 0); | ||
163 | av_freep(&s->exptab); | ||
164 | |||
165 | /* compute bit reverse table */ | ||
166 | for(i=0;i<n;i++) { | ||
167 | m=0; | ||
168 | for(j=0;j<nbits;j++) { | ||
169 | m |= ((i >> j) & 1) << (nbits-j-1); | ||
170 | } | ||
171 | s->revtab[i]=m; | ||
172 | } | ||
173 | } | ||
174 | |||
175 | return 0; | ||
176 | fail: | ||
177 | av_freep(&s->revtab); | ||
178 | av_freep(&s->exptab); | ||
179 | av_freep(&s->exptab1); | ||
180 | av_freep(&s->tmp_buf); | ||
181 | return -1; | ||
182 | } | ||
183 | |||
184 | void ff_fft_permute_c(FFTContext *s, FFTComplex *z) | ||
185 | { | ||
186 | int j, k, np; | ||
187 | FFTComplex tmp; | ||
188 | const uint16_t *revtab = s->revtab; | ||
189 | np = 1 << s->nbits; | ||
190 | |||
191 | if (s->tmp_buf) { | ||
192 | /* TODO: handle split-radix permute in a more optimal way, probably in-place */ | ||
193 | for(j=0;j<np;j++) s->tmp_buf[revtab[j]] = z[j]; | ||
194 | memcpy(z, s->tmp_buf, np * sizeof(FFTComplex)); | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | /* reverse */ | ||
199 | for(j=0;j<np;j++) { | ||
200 | k = revtab[j]; | ||
201 | if (k < j) { | ||
202 | tmp = z[k]; | ||
203 | z[k] = z[j]; | ||
204 | z[j] = tmp; | ||
205 | } | ||
206 | } | ||
207 | } | ||
208 | |||
209 | av_cold void ff_fft_end(FFTContext *s) | ||
210 | { | ||
211 | av_freep(&s->revtab); | ||
212 | av_freep(&s->exptab); | ||
213 | av_freep(&s->exptab1); | ||
214 | av_freep(&s->tmp_buf); | ||
215 | } | ||
216 | |||
217 | #define sqrthalf (float)M_SQRT1_2 | ||
218 | |||
219 | #define BF(x,y,a,b) {\ | ||
220 | x = a - b;\ | ||
221 | y = a + b;\ | ||
222 | } | ||
223 | |||
224 | #define BUTTERFLIES(a0,a1,a2,a3) {\ | ||
225 | BF(t3, t5, t5, t1);\ | ||
226 | BF(a2.re, a0.re, a0.re, t5);\ | ||
227 | BF(a3.im, a1.im, a1.im, t3);\ | ||
228 | BF(t4, t6, t2, t6);\ | ||
229 | BF(a3.re, a1.re, a1.re, t4);\ | ||
230 | BF(a2.im, a0.im, a0.im, t6);\ | ||
231 | } | ||
232 | |||
233 | // force loading all the inputs before storing any. | ||
234 | // this is slightly slower for small data, but avoids store->load aliasing | ||
235 | // for addresses separated by large powers of 2. | ||
236 | #define BUTTERFLIES_BIG(a0,a1,a2,a3) {\ | ||
237 | FFTSample r0=a0.re, i0=a0.im, r1=a1.re, i1=a1.im;\ | ||
238 | BF(t3, t5, t5, t1);\ | ||
239 | BF(a2.re, a0.re, r0, t5);\ | ||
240 | BF(a3.im, a1.im, i1, t3);\ | ||
241 | BF(t4, t6, t2, t6);\ | ||
242 | BF(a3.re, a1.re, r1, t4);\ | ||
243 | BF(a2.im, a0.im, i0, t6);\ | ||
244 | } | ||
245 | |||
246 | #define TRANSFORM(a0,a1,a2,a3,wre,wim) {\ | ||
247 | t1 = a2.re * wre + a2.im * wim;\ | ||
248 | t2 = a2.im * wre - a2.re * wim;\ | ||
249 | t5 = a3.re * wre - a3.im * wim;\ | ||
250 | t6 = a3.im * wre + a3.re * wim;\ | ||
251 | BUTTERFLIES(a0,a1,a2,a3)\ | ||
252 | } | ||
253 | |||
254 | #define TRANSFORM_ZERO(a0,a1,a2,a3) {\ | ||
255 | t1 = a2.re;\ | ||
256 | t2 = a2.im;\ | ||
257 | t5 = a3.re;\ | ||
258 | t6 = a3.im;\ | ||
259 | BUTTERFLIES(a0,a1,a2,a3)\ | ||
260 | } | ||
261 | |||
262 | /* z[0...8n-1], w[1...2n-1] */ | ||
263 | #define PASS(name)\ | ||
264 | static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\ | ||
265 | {\ | ||
266 | FFTSample t1, t2, t3, t4, t5, t6;\ | ||
267 | int o1 = 2*n;\ | ||
268 | int o2 = 4*n;\ | ||
269 | int o3 = 6*n;\ | ||
270 | const FFTSample *wim = wre+o1;\ | ||
271 | n--;\ | ||
272 | \ | ||
273 | TRANSFORM_ZERO(z[0],z[o1],z[o2],z[o3]);\ | ||
274 | TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\ | ||
275 | do {\ | ||
276 | z += 2;\ | ||
277 | wre += 2;\ | ||
278 | wim -= 2;\ | ||
279 | TRANSFORM(z[0],z[o1],z[o2],z[o3],wre[0],wim[0]);\ | ||
280 | TRANSFORM(z[1],z[o1+1],z[o2+1],z[o3+1],wre[1],wim[-1]);\ | ||
281 | } while(--n);\ | ||
282 | } | ||
283 | |||
284 | PASS(pass) | ||
285 | #undef BUTTERFLIES | ||
286 | #define BUTTERFLIES BUTTERFLIES_BIG | ||
287 | PASS(pass_big) | ||
288 | |||
289 | #define DECL_FFT(n,n2,n4)\ | ||
290 | static void fft##n(FFTComplex *z)\ | ||
291 | {\ | ||
292 | fft##n2(z);\ | ||
293 | fft##n4(z+n4*2);\ | ||
294 | fft##n4(z+n4*3);\ | ||
295 | pass(z,ff_cos_##n,n4/2);\ | ||
296 | } | ||
297 | |||
298 | static void fft4(FFTComplex *z) | ||
299 | { | ||
300 | FFTSample t1, t2, t3, t4, t5, t6, t7, t8; | ||
301 | |||
302 | BF(t3, t1, z[0].re, z[1].re); | ||
303 | BF(t8, t6, z[3].re, z[2].re); | ||
304 | BF(z[2].re, z[0].re, t1, t6); | ||
305 | BF(t4, t2, z[0].im, z[1].im); | ||
306 | BF(t7, t5, z[2].im, z[3].im); | ||
307 | BF(z[3].im, z[1].im, t4, t8); | ||
308 | BF(z[3].re, z[1].re, t3, t7); | ||
309 | BF(z[2].im, z[0].im, t2, t5); | ||
310 | } | ||
311 | |||
312 | static void fft8(FFTComplex *z) | ||
313 | { | ||
314 | FFTSample t1, t2, t3, t4, t5, t6, t7, t8; | ||
315 | |||
316 | fft4(z); | ||
317 | |||
318 | BF(t1, z[5].re, z[4].re, -z[5].re); | ||
319 | BF(t2, z[5].im, z[4].im, -z[5].im); | ||
320 | BF(t3, z[7].re, z[6].re, -z[7].re); | ||
321 | BF(t4, z[7].im, z[6].im, -z[7].im); | ||
322 | BF(t8, t1, t3, t1); | ||
323 | BF(t7, t2, t2, t4); | ||
324 | BF(z[4].re, z[0].re, z[0].re, t1); | ||
325 | BF(z[4].im, z[0].im, z[0].im, t2); | ||
326 | BF(z[6].re, z[2].re, z[2].re, t7); | ||
327 | BF(z[6].im, z[2].im, z[2].im, t8); | ||
328 | |||
329 | TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf); | ||
330 | } | ||
331 | |||
332 | #if !CONFIG_SMALL | ||
333 | static void fft16(FFTComplex *z) | ||
334 | { | ||
335 | FFTSample t1, t2, t3, t4, t5, t6; | ||
336 | |||
337 | fft8(z); | ||
338 | fft4(z+8); | ||
339 | fft4(z+12); | ||
340 | |||
341 | TRANSFORM_ZERO(z[0],z[4],z[8],z[12]); | ||
342 | TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf); | ||
343 | TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]); | ||
344 | TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]); | ||
345 | } | ||
346 | #else | ||
347 | DECL_FFT(16,8,4) | ||
348 | #endif | ||
349 | DECL_FFT(32,16,8) | ||
350 | DECL_FFT(64,32,16) | ||
351 | DECL_FFT(128,64,32) | ||
352 | DECL_FFT(256,128,64) | ||
353 | DECL_FFT(512,256,128) | ||
354 | #if !CONFIG_SMALL | ||
355 | #define pass pass_big | ||
356 | #endif | ||
357 | DECL_FFT(1024,512,256) | ||
358 | DECL_FFT(2048,1024,512) | ||
359 | DECL_FFT(4096,2048,1024) | ||
360 | DECL_FFT(8192,4096,2048) | ||
361 | DECL_FFT(16384,8192,4096) | ||
362 | DECL_FFT(32768,16384,8192) | ||
363 | DECL_FFT(65536,32768,16384) | ||
364 | |||
365 | static void (*fft_dispatch[])(FFTComplex*) = { | ||
366 | fft4, fft8, fft16, fft32, fft64, fft128, fft256, fft512, fft1024, | ||
367 | fft2048, fft4096, fft8192, fft16384, fft32768, fft65536, | ||
368 | }; | ||
369 | |||
370 | void ff_fft_calc_c(FFTContext *s, FFTComplex *z) | ||
371 | { | ||
372 | fft_dispatch[s->nbits-2](z); | ||
373 | } | ||
374 | |||
diff --git a/apps/codecs/libatrac/libavutil/avutil.h b/apps/codecs/libatrac/libavutil/avutil.h new file mode 100644 index 0000000000..c07e44d660 --- /dev/null +++ b/apps/codecs/libatrac/libavutil/avutil.h | |||
@@ -0,0 +1,63 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #ifndef AVUTIL_AVUTIL_H | ||
22 | #define AVUTIL_AVUTIL_H | ||
23 | |||
24 | /** | ||
25 | * @file libavutil/avutil.h | ||
26 | * external API header | ||
27 | */ | ||
28 | |||
29 | |||
30 | #define AV_STRINGIFY(s) AV_TOSTRING(s) | ||
31 | #define AV_TOSTRING(s) #s | ||
32 | |||
33 | #define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c) | ||
34 | #define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c | ||
35 | #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) | ||
36 | |||
37 | #define LIBAVUTIL_VERSION_MAJOR 50 | ||
38 | #define LIBAVUTIL_VERSION_MINOR 0 | ||
39 | #define LIBAVUTIL_VERSION_MICRO 0 | ||
40 | |||
41 | #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ | ||
42 | LIBAVUTIL_VERSION_MINOR, \ | ||
43 | LIBAVUTIL_VERSION_MICRO) | ||
44 | #define LIBAVUTIL_VERSION AV_VERSION(LIBAVUTIL_VERSION_MAJOR, \ | ||
45 | LIBAVUTIL_VERSION_MINOR, \ | ||
46 | LIBAVUTIL_VERSION_MICRO) | ||
47 | #define LIBAVUTIL_BUILD LIBAVUTIL_VERSION_INT | ||
48 | |||
49 | #define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) | ||
50 | |||
51 | /** | ||
52 | * Returns the LIBAVUTIL_VERSION_INT constant. | ||
53 | */ | ||
54 | unsigned avutil_version(void); | ||
55 | |||
56 | #include "common.h" | ||
57 | //#include "mathematics.h" | ||
58 | //#include "rational.h" | ||
59 | //#include "intfloat_readwrite.h" | ||
60 | #include "log.h" | ||
61 | //#include "pixfmt.h" | ||
62 | |||
63 | #endif /* AVUTIL_AVUTIL_H */ | ||
diff --git a/apps/codecs/libatrac/libavutil/bswap.h b/apps/codecs/libatrac/libavutil/bswap.h new file mode 100644 index 0000000000..9175cb24a5 --- /dev/null +++ b/apps/codecs/libatrac/libavutil/bswap.h | |||
@@ -0,0 +1,99 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file libavutil/bswap.h | ||
23 | * byte swapping routines | ||
24 | */ | ||
25 | |||
26 | #ifndef AVUTIL_BSWAP_H | ||
27 | #define AVUTIL_BSWAP_H | ||
28 | |||
29 | #include <stdint.h> | ||
30 | //#include "ffmpeg_config.h" | ||
31 | #include "common.h" | ||
32 | |||
33 | #if ARCH_ARM | ||
34 | # include "arm/bswap.h" | ||
35 | #elif ARCH_BFIN | ||
36 | # include "bfin/bswap.h" | ||
37 | #elif ARCH_SH4 | ||
38 | # include "sh4/bswap.h" | ||
39 | #elif ARCH_X86 | ||
40 | # include "x86/bswap.h" | ||
41 | #endif | ||
42 | |||
43 | #ifndef bswap_16 | ||
44 | static av_always_inline av_const uint16_t bswap_16(uint16_t x) | ||
45 | { | ||
46 | x= (x>>8) | (x<<8); | ||
47 | return x; | ||
48 | } | ||
49 | #endif | ||
50 | |||
51 | #ifndef bswap_32 | ||
52 | static av_always_inline av_const uint32_t bswap_32(uint32_t x) | ||
53 | { | ||
54 | x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); | ||
55 | x= (x>>16) | (x<<16); | ||
56 | return x; | ||
57 | } | ||
58 | #endif | ||
59 | |||
60 | #ifndef bswap_64 | ||
61 | static inline uint64_t av_const bswap_64(uint64_t x) | ||
62 | { | ||
63 | #if 0 | ||
64 | x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); | ||
65 | x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); | ||
66 | return (x>>32) | (x<<32); | ||
67 | #else | ||
68 | union { | ||
69 | uint64_t ll; | ||
70 | uint32_t l[2]; | ||
71 | } w, r; | ||
72 | w.ll = x; | ||
73 | r.l[0] = bswap_32 (w.l[1]); | ||
74 | r.l[1] = bswap_32 (w.l[0]); | ||
75 | return r.ll; | ||
76 | #endif | ||
77 | } | ||
78 | #endif | ||
79 | |||
80 | // be2me ... big-endian to machine-endian | ||
81 | // le2me ... little-endian to machine-endian | ||
82 | |||
83 | #ifdef WORDS_BIGENDIAN | ||
84 | #define be2me_16(x) (x) | ||
85 | #define be2me_32(x) (x) | ||
86 | #define be2me_64(x) (x) | ||
87 | #define le2me_16(x) bswap_16(x) | ||
88 | #define le2me_32(x) bswap_32(x) | ||
89 | #define le2me_64(x) bswap_64(x) | ||
90 | #else | ||
91 | #define be2me_16(x) bswap_16(x) | ||
92 | #define be2me_32(x) bswap_32(x) | ||
93 | #define be2me_64(x) bswap_64(x) | ||
94 | #define le2me_16(x) (x) | ||
95 | #define le2me_32(x) (x) | ||
96 | #define le2me_64(x) (x) | ||
97 | #endif | ||
98 | |||
99 | #endif /* AVUTIL_BSWAP_H */ | ||
diff --git a/apps/codecs/libatrac/libavutil/common.h b/apps/codecs/libatrac/libavutil/common.h new file mode 100644 index 0000000000..949f093d35 --- /dev/null +++ b/apps/codecs/libatrac/libavutil/common.h | |||
@@ -0,0 +1,286 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file libavutil/common.h | ||
23 | * common internal and external API header | ||
24 | */ | ||
25 | |||
26 | #ifndef AVUTIL_COMMON_H | ||
27 | #define AVUTIL_COMMON_H | ||
28 | |||
29 | #include <ctype.h> | ||
30 | #include <errno.h> | ||
31 | #include <inttypes.h> | ||
32 | #include <limits.h> | ||
33 | #include <math.h> | ||
34 | #include <stdio.h> | ||
35 | #include <stdlib.h> | ||
36 | #include <string.h> | ||
37 | |||
38 | #ifdef __GNUC__ | ||
39 | # define AV_GCC_VERSION_AT_LEAST(x,y) (__GNUC__ > x || __GNUC__ == x && __GNUC_MINOR__ >= y) | ||
40 | #else | ||
41 | # define AV_GCC_VERSION_AT_LEAST(x,y) 0 | ||
42 | #endif | ||
43 | |||
44 | #ifndef av_always_inline | ||
45 | #if AV_GCC_VERSION_AT_LEAST(3,1) | ||
46 | # define av_always_inline __attribute__((always_inline)) inline | ||
47 | #else | ||
48 | # define av_always_inline inline | ||
49 | #endif | ||
50 | #endif | ||
51 | |||
52 | #ifndef av_noinline | ||
53 | #if AV_GCC_VERSION_AT_LEAST(3,1) | ||
54 | # define av_noinline __attribute__((noinline)) | ||
55 | #else | ||
56 | # define av_noinline | ||
57 | #endif | ||
58 | #endif | ||
59 | |||
60 | #ifndef av_pure | ||
61 | #if AV_GCC_VERSION_AT_LEAST(3,1) | ||
62 | # define av_pure __attribute__((pure)) | ||
63 | #else | ||
64 | # define av_pure | ||
65 | #endif | ||
66 | #endif | ||
67 | |||
68 | #ifndef av_const | ||
69 | #if AV_GCC_VERSION_AT_LEAST(2,6) | ||
70 | # define av_const __attribute__((const)) | ||
71 | #else | ||
72 | # define av_const | ||
73 | #endif | ||
74 | #endif | ||
75 | |||
76 | #ifndef av_cold | ||
77 | #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3) | ||
78 | # define av_cold __attribute__((cold)) | ||
79 | #else | ||
80 | # define av_cold | ||
81 | #endif | ||
82 | #endif | ||
83 | |||
84 | #ifndef av_flatten | ||
85 | #if AV_GCC_VERSION_AT_LEAST(4,1) | ||
86 | # define av_flatten __attribute__((flatten)) | ||
87 | #else | ||
88 | # define av_flatten | ||
89 | #endif | ||
90 | #endif | ||
91 | |||
92 | #ifndef attribute_deprecated | ||
93 | #if AV_GCC_VERSION_AT_LEAST(3,1) | ||
94 | # define attribute_deprecated __attribute__((deprecated)) | ||
95 | #else | ||
96 | # define attribute_deprecated | ||
97 | #endif | ||
98 | #endif | ||
99 | |||
100 | #ifndef av_unused | ||
101 | #if defined(__GNUC__) | ||
102 | # define av_unused __attribute__((unused)) | ||
103 | #else | ||
104 | # define av_unused | ||
105 | #endif | ||
106 | #endif | ||
107 | |||
108 | #ifndef av_uninit | ||
109 | #if defined(__GNUC__) && !defined(__ICC) | ||
110 | # define av_uninit(x) x=x | ||
111 | #else | ||
112 | # define av_uninit(x) x | ||
113 | #endif | ||
114 | #endif | ||
115 | |||
116 | //rounded division & shift | ||
117 | #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) | ||
118 | /* assume b>0 */ | ||
119 | #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) | ||
120 | #define FFABS(a) ((a) >= 0 ? (a) : (-(a))) | ||
121 | #define FFSIGN(a) ((a) > 0 ? 1 : -1) | ||
122 | |||
123 | #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) | ||
124 | #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c) | ||
125 | #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) | ||
126 | #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c) | ||
127 | |||
128 | #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) | ||
129 | #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) | ||
130 | |||
131 | /* misc math functions */ | ||
132 | extern const uint8_t ff_log2_tab[256]; | ||
133 | |||
134 | static inline av_const int av_log2(unsigned int v) | ||
135 | { | ||
136 | int n = 0; | ||
137 | if (v & 0xffff0000) { | ||
138 | v >>= 16; | ||
139 | n += 16; | ||
140 | } | ||
141 | if (v & 0xff00) { | ||
142 | v >>= 8; | ||
143 | n += 8; | ||
144 | } | ||
145 | n += ff_log2_tab[v]; | ||
146 | |||
147 | return n; | ||
148 | } | ||
149 | |||
150 | static inline av_const int av_log2_16bit(unsigned int v) | ||
151 | { | ||
152 | int n = 0; | ||
153 | if (v & 0xff00) { | ||
154 | v >>= 8; | ||
155 | n += 8; | ||
156 | } | ||
157 | n += ff_log2_tab[v]; | ||
158 | |||
159 | return n; | ||
160 | } | ||
161 | |||
162 | /** | ||
163 | * Clips a signed integer value into the amin-amax range. | ||
164 | * @param a value to clip | ||
165 | * @param amin minimum value of the clip range | ||
166 | * @param amax maximum value of the clip range | ||
167 | * @return clipped value | ||
168 | */ | ||
169 | static inline av_const int av_clip(int a, int amin, int amax) | ||
170 | { | ||
171 | if (a < amin) return amin; | ||
172 | else if (a > amax) return amax; | ||
173 | else return a; | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * Clips a signed integer value into the 0-255 range. | ||
178 | * @param a value to clip | ||
179 | * @return clipped value | ||
180 | */ | ||
181 | static inline av_const uint8_t av_clip_uint8(int a) | ||
182 | { | ||
183 | if (a&(~255)) return (-a)>>31; | ||
184 | else return a; | ||
185 | } | ||
186 | |||
187 | /** | ||
188 | * Clips a signed integer value into the -32768,32767 range. | ||
189 | * @param a value to clip | ||
190 | * @return clipped value | ||
191 | */ | ||
192 | static inline av_const int16_t av_clip_int16(int a) | ||
193 | { | ||
194 | if ((a+32768) & ~65535) return (a>>31) ^ 32767; | ||
195 | else return a; | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * Clips a float value into the amin-amax range. | ||
200 | * @param a value to clip | ||
201 | * @param amin minimum value of the clip range | ||
202 | * @param amax maximum value of the clip range | ||
203 | * @return clipped value | ||
204 | */ | ||
205 | static inline av_const float av_clipf(float a, float amin, float amax) | ||
206 | { | ||
207 | if (a < amin) return amin; | ||
208 | else if (a > amax) return amax; | ||
209 | else return a; | ||
210 | } | ||
211 | |||
212 | #define MKTAG(a,b,c,d) (a | (b << 8) | (c << 16) | (d << 24)) | ||
213 | #define MKBETAG(a,b,c,d) (d | (c << 8) | (b << 16) | (a << 24)) | ||
214 | |||
215 | /*! | ||
216 | * \def GET_UTF8(val, GET_BYTE, ERROR) | ||
217 | * Converts a UTF-8 character (up to 4 bytes long) to its 32-bit UCS-4 encoded form | ||
218 | * \param val is the output and should be of type uint32_t. It holds the converted | ||
219 | * UCS-4 character and should be a left value. | ||
220 | * \param GET_BYTE gets UTF-8 encoded bytes from any proper source. It can be | ||
221 | * a function or a statement whose return value or evaluated value is of type | ||
222 | * uint8_t. It will be executed up to 4 times for values in the valid UTF-8 range, | ||
223 | * and up to 7 times in the general case. | ||
224 | * \param ERROR action that should be taken when an invalid UTF-8 byte is returned | ||
225 | * from GET_BYTE. It should be a statement that jumps out of the macro, | ||
226 | * like exit(), goto, return, break, or continue. | ||
227 | */ | ||
228 | #define GET_UTF8(val, GET_BYTE, ERROR)\ | ||
229 | val= GET_BYTE;\ | ||
230 | {\ | ||
231 | int ones= 7 - av_log2(val ^ 255);\ | ||
232 | if(ones==1)\ | ||
233 | ERROR\ | ||
234 | val&= 127>>ones;\ | ||
235 | while(--ones > 0){\ | ||
236 | int tmp= GET_BYTE - 128;\ | ||
237 | if(tmp>>6)\ | ||
238 | ERROR\ | ||
239 | val= (val<<6) + tmp;\ | ||
240 | }\ | ||
241 | } | ||
242 | |||
243 | /*! | ||
244 | * \def PUT_UTF8(val, tmp, PUT_BYTE) | ||
245 | * Converts a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). | ||
246 | * \param val is an input-only argument and should be of type uint32_t. It holds | ||
247 | * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If | ||
248 | * val is given as a function it is executed only once. | ||
249 | * \param tmp is a temporary variable and should be of type uint8_t. It | ||
250 | * represents an intermediate value during conversion that is to be | ||
251 | * output by PUT_BYTE. | ||
252 | * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. | ||
253 | * It could be a function or a statement, and uses tmp as the input byte. | ||
254 | * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be | ||
255 | * executed up to 4 times for values in the valid UTF-8 range and up to | ||
256 | * 7 times in the general case, depending on the length of the converted | ||
257 | * Unicode character. | ||
258 | */ | ||
259 | #define PUT_UTF8(val, tmp, PUT_BYTE)\ | ||
260 | {\ | ||
261 | int bytes, shift;\ | ||
262 | uint32_t in = val;\ | ||
263 | if (in < 0x80) {\ | ||
264 | tmp = in;\ | ||
265 | PUT_BYTE\ | ||
266 | } else {\ | ||
267 | bytes = (av_log2(in) + 4) / 5;\ | ||
268 | shift = (bytes - 1) * 6;\ | ||
269 | tmp = (256 - (256 >> bytes)) | (in >> shift);\ | ||
270 | PUT_BYTE\ | ||
271 | while (shift >= 6) {\ | ||
272 | shift -= 6;\ | ||
273 | tmp = 0x80 | ((in >> shift) & 0x3f);\ | ||
274 | PUT_BYTE\ | ||
275 | }\ | ||
276 | }\ | ||
277 | } | ||
278 | |||
279 | #include "mem.h" | ||
280 | |||
281 | //#ifdef HAVE_AV_CONFIG_H | ||
282 | //# include "ffmpeg_config.h" | ||
283 | # include "internal.h" | ||
284 | //#endif /* HAVE_AV_CONFIG_H */ | ||
285 | |||
286 | #endif /* AVUTIL_COMMON_H */ | ||
diff --git a/apps/codecs/libatrac/libavutil/internal.h b/apps/codecs/libatrac/libavutil/internal.h new file mode 100644 index 0000000000..c28b6f9a5e --- /dev/null +++ b/apps/codecs/libatrac/libavutil/internal.h | |||
@@ -0,0 +1,328 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file libavutil/internal.h | ||
23 | * common internal API header | ||
24 | */ | ||
25 | |||
26 | #ifndef AVUTIL_INTERNAL_H | ||
27 | #define AVUTIL_INTERNAL_H | ||
28 | |||
29 | #if !defined(DEBUG) && !defined(NDEBUG) | ||
30 | # define NDEBUG | ||
31 | #endif | ||
32 | |||
33 | #include <limits.h> | ||
34 | #include <stdint.h> | ||
35 | #include <stddef.h> | ||
36 | #include <assert.h> | ||
37 | //#include "ffmpeg_config.h" | ||
38 | #include "common.h" | ||
39 | #include "mem.h" | ||
40 | //#include "timer.h" | ||
41 | |||
42 | #ifndef attribute_align_arg | ||
43 | #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,2) | ||
44 | # define attribute_align_arg __attribute__((force_align_arg_pointer)) | ||
45 | #else | ||
46 | # define attribute_align_arg | ||
47 | #endif | ||
48 | #endif | ||
49 | |||
50 | #ifndef attribute_used | ||
51 | #if AV_GCC_VERSION_AT_LEAST(3,1) | ||
52 | # define attribute_used __attribute__((used)) | ||
53 | #else | ||
54 | # define attribute_used | ||
55 | #endif | ||
56 | #endif | ||
57 | |||
58 | #ifndef INT16_MIN | ||
59 | #define INT16_MIN (-0x7fff-1) | ||
60 | #endif | ||
61 | |||
62 | #ifndef INT16_MAX | ||
63 | #define INT16_MAX 0x7fff | ||
64 | #endif | ||
65 | |||
66 | #ifndef INT32_MIN | ||
67 | #define INT32_MIN (-0x7fffffff-1) | ||
68 | #endif | ||
69 | |||
70 | #ifndef INT32_MAX | ||
71 | #define INT32_MAX 0x7fffffff | ||
72 | #endif | ||
73 | |||
74 | #ifndef UINT32_MAX | ||
75 | #define UINT32_MAX 0xffffffff | ||
76 | #endif | ||
77 | |||
78 | #ifndef INT64_MIN | ||
79 | #define INT64_MIN (-0x7fffffffffffffffLL-1) | ||
80 | #endif | ||
81 | |||
82 | #ifndef INT64_MAX | ||
83 | #define INT64_MAX INT64_C(9223372036854775807) | ||
84 | #endif | ||
85 | |||
86 | #ifndef UINT64_MAX | ||
87 | #define UINT64_MAX UINT64_C(0xFFFFFFFFFFFFFFFF) | ||
88 | #endif | ||
89 | |||
90 | #ifndef INT_BIT | ||
91 | # define INT_BIT (CHAR_BIT * sizeof(int)) | ||
92 | #endif | ||
93 | |||
94 | #if ( defined(__PIC__) || defined(__pic__) ) && ! defined(PIC) | ||
95 | # define PIC | ||
96 | #endif | ||
97 | |||
98 | #ifndef offsetof | ||
99 | # define offsetof(T,F) ((unsigned int)((char *)&((T *)0)->F)) | ||
100 | #endif | ||
101 | |||
102 | // Use rip-relative addressing if compiling PIC code on x86-64. | ||
103 | #if ARCH_X86_64 && defined(PIC) | ||
104 | # define LOCAL_MANGLE(a) #a "(%%rip)" | ||
105 | #else | ||
106 | # define LOCAL_MANGLE(a) #a | ||
107 | #endif | ||
108 | |||
109 | #define MANGLE(a) EXTERN_PREFIX LOCAL_MANGLE(a) | ||
110 | |||
111 | /* debug stuff */ | ||
112 | |||
113 | /* dprintf macros */ | ||
114 | #ifdef DEBUG | ||
115 | # define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) | ||
116 | #else | ||
117 | # define dprintf(pctx, ...) | ||
118 | #endif | ||
119 | |||
120 | #define av_abort() do { av_log(NULL, AV_LOG_ERROR, "Abort at %s:%d\n", __FILE__, __LINE__); abort(); } while (0) | ||
121 | |||
122 | /* math */ | ||
123 | |||
124 | extern const uint32_t ff_inverse[256]; | ||
125 | |||
126 | #if ARCH_X86 | ||
127 | # define FASTDIV(a,b) \ | ||
128 | ({\ | ||
129 | int ret,dmy;\ | ||
130 | __asm__ volatile(\ | ||
131 | "mull %3"\ | ||
132 | :"=d"(ret),"=a"(dmy)\ | ||
133 | :"1"(a),"g"(ff_inverse[b])\ | ||
134 | );\ | ||
135 | ret;\ | ||
136 | }) | ||
137 | #elif HAVE_ARMV6 && HAVE_INLINE_ASM | ||
138 | static inline av_const int FASTDIV(int a, int b) | ||
139 | { | ||
140 | int r, t; | ||
141 | __asm__ volatile("cmp %3, #2 \n\t" | ||
142 | "ldr %1, [%4, %3, lsl #2] \n\t" | ||
143 | "lsrle %0, %2, #1 \n\t" | ||
144 | "smmulgt %0, %1, %2 \n\t" | ||
145 | : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse)); | ||
146 | return r; | ||
147 | } | ||
148 | #elif ARCH_ARM && HAVE_INLINE_ASM | ||
149 | static inline av_const int FASTDIV(int a, int b) | ||
150 | { | ||
151 | int r, t; | ||
152 | __asm__ volatile ("umull %1, %0, %2, %3" | ||
153 | : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b])); | ||
154 | return r; | ||
155 | } | ||
156 | #elif CONFIG_FASTDIV | ||
157 | # define FASTDIV(a,b) ((uint32_t)((((uint64_t)a)*ff_inverse[b])>>32)) | ||
158 | #else | ||
159 | # define FASTDIV(a,b) ((a)/(b)) | ||
160 | #endif | ||
161 | |||
162 | extern const uint8_t ff_sqrt_tab[256]; | ||
163 | |||
164 | static inline av_const unsigned int ff_sqrt(unsigned int a) | ||
165 | { | ||
166 | unsigned int b; | ||
167 | |||
168 | if(a<255) return (ff_sqrt_tab[a+1]-1)>>4; | ||
169 | else if(a<(1<<12)) b= ff_sqrt_tab[a>>4 ]>>2; | ||
170 | #if !CONFIG_SMALL | ||
171 | else if(a<(1<<14)) b= ff_sqrt_tab[a>>6 ]>>1; | ||
172 | else if(a<(1<<16)) b= ff_sqrt_tab[a>>8 ] ; | ||
173 | #endif | ||
174 | else{ | ||
175 | int s= av_log2_16bit(a>>16)>>1; | ||
176 | unsigned int c= a>>(s+2); | ||
177 | b= ff_sqrt_tab[c>>(s+8)]; | ||
178 | b= FASTDIV(c,b) + (b<<s); | ||
179 | } | ||
180 | |||
181 | return b - (a<b*b); | ||
182 | } | ||
183 | |||
184 | #if ARCH_X86 | ||
185 | #define MASK_ABS(mask, level)\ | ||
186 | __asm__ volatile(\ | ||
187 | "cltd \n\t"\ | ||
188 | "xorl %1, %0 \n\t"\ | ||
189 | "subl %1, %0 \n\t"\ | ||
190 | : "+a" (level), "=&d" (mask)\ | ||
191 | ); | ||
192 | #else | ||
193 | #define MASK_ABS(mask, level)\ | ||
194 | mask= level>>31;\ | ||
195 | level= (level^mask)-mask; | ||
196 | #endif | ||
197 | |||
198 | #if HAVE_CMOV | ||
199 | #define COPY3_IF_LT(x,y,a,b,c,d)\ | ||
200 | __asm__ volatile (\ | ||
201 | "cmpl %0, %3 \n\t"\ | ||
202 | "cmovl %3, %0 \n\t"\ | ||
203 | "cmovl %4, %1 \n\t"\ | ||
204 | "cmovl %5, %2 \n\t"\ | ||
205 | : "+&r" (x), "+&r" (a), "+r" (c)\ | ||
206 | : "r" (y), "r" (b), "r" (d)\ | ||
207 | ); | ||
208 | #else | ||
209 | #define COPY3_IF_LT(x,y,a,b,c,d)\ | ||
210 | if((y)<(x)){\ | ||
211 | (x)=(y);\ | ||
212 | (a)=(b);\ | ||
213 | (c)=(d);\ | ||
214 | } | ||
215 | #endif | ||
216 | |||
217 | /* avoid usage of dangerous/inappropriate system functions */ | ||
218 | #undef malloc | ||
219 | #define malloc please_use_av_malloc | ||
220 | #undef free | ||
221 | #define free please_use_av_free | ||
222 | #undef realloc | ||
223 | #define realloc please_use_av_realloc | ||
224 | #undef time | ||
225 | #define time time_is_forbidden_due_to_security_issues | ||
226 | //#undef rand | ||
227 | //#define rand rand_is_forbidden_due_to_state_trashing_use_av_random | ||
228 | //#undef srand | ||
229 | //#define srand srand_is_forbidden_due_to_state_trashing_use_av_random_init | ||
230 | #undef random | ||
231 | #define random random_is_forbidden_due_to_state_trashing_use_av_random | ||
232 | #undef sprintf | ||
233 | #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf | ||
234 | #undef strcat | ||
235 | #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat | ||
236 | #undef exit | ||
237 | #define exit exit_is_forbidden | ||
238 | #ifndef LIBAVFORMAT_BUILD | ||
239 | //#undef printf | ||
240 | //#define printf please_use_av_log_instead_of_printf | ||
241 | #undef fprintf | ||
242 | #define fprintf please_use_av_log_instead_of_fprintf | ||
243 | #undef puts | ||
244 | #define puts please_use_av_log_instead_of_puts | ||
245 | #undef perror | ||
246 | #define perror please_use_av_log_instead_of_perror | ||
247 | #endif | ||
248 | |||
249 | #define CHECKED_ALLOCZ(p, size)\ | ||
250 | {\ | ||
251 | p= av_mallocz(size);\ | ||
252 | if(p==NULL && (size)!=0){\ | ||
253 | av_log(NULL, AV_LOG_ERROR, "Cannot allocate memory.");\ | ||
254 | goto fail;\ | ||
255 | }\ | ||
256 | } | ||
257 | |||
258 | #if defined(__ICC) || defined(__SUNPRO_C) | ||
259 | #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) | ||
260 | #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v | ||
261 | #elif defined(__GNUC__) | ||
262 | #define DECLARE_ALIGNED(n,t,v) t v __attribute__ ((aligned (n))) | ||
263 | #define DECLARE_ASM_CONST(n,t,v) static const t v attribute_used __attribute__ ((aligned (n))) | ||
264 | #elif defined(_MSC_VER) | ||
265 | #define DECLARE_ALIGNED(n,t,v) __declspec(align(n)) t v | ||
266 | #define DECLARE_ASM_CONST(n,t,v) __declspec(align(n)) static const t v | ||
267 | #elif HAVE_INLINE_ASM | ||
268 | #error The asm code needs alignment, but we do not know how to do it for this compiler. | ||
269 | #else | ||
270 | #define DECLARE_ALIGNED(n,t,v) t v | ||
271 | #define DECLARE_ASM_CONST(n,t,v) static const t v | ||
272 | #endif | ||
273 | |||
274 | |||
275 | #if !HAVE_LLRINT | ||
276 | static av_always_inline av_const long long llrint(double x) | ||
277 | { | ||
278 | return rint(x); | ||
279 | } | ||
280 | #endif /* HAVE_LLRINT */ | ||
281 | |||
282 | #if !HAVE_LRINT | ||
283 | static av_always_inline av_const long int lrint(double x) | ||
284 | { | ||
285 | return rint(x); | ||
286 | } | ||
287 | #endif /* HAVE_LRINT */ | ||
288 | |||
289 | #if !HAVE_LRINTF | ||
290 | static av_always_inline av_const long int lrintf(float x) | ||
291 | { | ||
292 | return (int)(rint(x)); | ||
293 | } | ||
294 | #endif /* HAVE_LRINTF */ | ||
295 | |||
296 | #if !HAVE_ROUND | ||
297 | static av_always_inline av_const double round(double x) | ||
298 | { | ||
299 | return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); | ||
300 | } | ||
301 | #endif /* HAVE_ROUND */ | ||
302 | |||
303 | #if !HAVE_ROUNDF | ||
304 | static av_always_inline av_const float roundf(float x) | ||
305 | { | ||
306 | return (x > 0) ? floor(x + 0.5) : ceil(x - 0.5); | ||
307 | } | ||
308 | #endif /* HAVE_ROUNDF */ | ||
309 | |||
310 | #if !HAVE_TRUNCF | ||
311 | static av_always_inline av_const float truncf(float x) | ||
312 | { | ||
313 | return (x > 0) ? floor(x) : ceil(x); | ||
314 | } | ||
315 | #endif /* HAVE_TRUNCF */ | ||
316 | |||
317 | /** | ||
318 | * Returns NULL if CONFIG_SMALL is true, otherwise the argument | ||
319 | * without modification. Used to disable the definition of strings | ||
320 | * (for example AVCodec long_names). | ||
321 | */ | ||
322 | #if CONFIG_SMALL | ||
323 | # define NULL_IF_CONFIG_SMALL(x) NULL | ||
324 | #else | ||
325 | # define NULL_IF_CONFIG_SMALL(x) x | ||
326 | #endif | ||
327 | |||
328 | #endif /* AVUTIL_INTERNAL_H */ | ||
diff --git a/apps/codecs/libatrac/libavutil/intreadwrite.h b/apps/codecs/libatrac/libavutil/intreadwrite.h new file mode 100644 index 0000000000..d27a50061e --- /dev/null +++ b/apps/codecs/libatrac/libavutil/intreadwrite.h | |||
@@ -0,0 +1,192 @@ | |||
1 | /* | ||
2 | * This file is part of FFmpeg. | ||
3 | * | ||
4 | * FFmpeg is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) any later version. | ||
8 | * | ||
9 | * FFmpeg is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
12 | * Lesser General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU Lesser General Public | ||
15 | * License along with FFmpeg; if not, write to the Free Software | ||
16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
17 | */ | ||
18 | |||
19 | #ifndef AVUTIL_INTREADWRITE_H | ||
20 | #define AVUTIL_INTREADWRITE_H | ||
21 | |||
22 | #include <stdint.h> | ||
23 | //#include "ffmpeg_config.h" | ||
24 | #include "bswap.h" | ||
25 | |||
26 | #ifdef __GNUC__ | ||
27 | |||
28 | struct unaligned_64 { uint64_t l; } __attribute__((packed)); | ||
29 | struct unaligned_32 { uint32_t l; } __attribute__((packed)); | ||
30 | struct unaligned_16 { uint16_t l; } __attribute__((packed)); | ||
31 | |||
32 | #define AV_RN16(a) (((const struct unaligned_16 *) (a))->l) | ||
33 | #define AV_RN32(a) (((const struct unaligned_32 *) (a))->l) | ||
34 | #define AV_RN64(a) (((const struct unaligned_64 *) (a))->l) | ||
35 | |||
36 | #define AV_WN16(a, b) (((struct unaligned_16 *) (a))->l) = (b) | ||
37 | #define AV_WN32(a, b) (((struct unaligned_32 *) (a))->l) = (b) | ||
38 | #define AV_WN64(a, b) (((struct unaligned_64 *) (a))->l) = (b) | ||
39 | |||
40 | #elif defined(__DECC) | ||
41 | |||
42 | #define AV_RN16(a) (*((const __unaligned uint16_t*)(a))) | ||
43 | #define AV_RN32(a) (*((const __unaligned uint32_t*)(a))) | ||
44 | #define AV_RN64(a) (*((const __unaligned uint64_t*)(a))) | ||
45 | |||
46 | #define AV_WN16(a, b) *((__unaligned uint16_t*)(a)) = (b) | ||
47 | #define AV_WN32(a, b) *((__unaligned uint32_t*)(a)) = (b) | ||
48 | #define AV_WN64(a, b) *((__unaligned uint64_t*)(a)) = (b) | ||
49 | |||
50 | #else | ||
51 | |||
52 | #define AV_RN16(a) (*((const uint16_t*)(a))) | ||
53 | #define AV_RN32(a) (*((const uint32_t*)(a))) | ||
54 | #define AV_RN64(a) (*((const uint64_t*)(a))) | ||
55 | |||
56 | #define AV_WN16(a, b) *((uint16_t*)(a)) = (b) | ||
57 | #define AV_WN32(a, b) *((uint32_t*)(a)) = (b) | ||
58 | #define AV_WN64(a, b) *((uint64_t*)(a)) = (b) | ||
59 | |||
60 | #endif /* !__GNUC__ */ | ||
61 | |||
62 | /* endian macros */ | ||
63 | #define AV_RB8(x) (((const uint8_t*)(x))[0]) | ||
64 | #define AV_WB8(p, d) do { ((uint8_t*)(p))[0] = (d); } while(0) | ||
65 | |||
66 | #define AV_RL8(x) AV_RB8(x) | ||
67 | #define AV_WL8(p, d) AV_WB8(p, d) | ||
68 | |||
69 | #if HAVE_FAST_UNALIGNED | ||
70 | # ifdef WORDS_BIGENDIAN | ||
71 | # define AV_RB16(x) AV_RN16(x) | ||
72 | # define AV_WB16(p, d) AV_WN16(p, d) | ||
73 | |||
74 | # define AV_RL16(x) bswap_16(AV_RN16(x)) | ||
75 | # define AV_WL16(p, d) AV_WN16(p, bswap_16(d)) | ||
76 | |||
77 | # define AV_RB32(x) AV_RN32(x) | ||
78 | # define AV_WB32(p, d) AV_WN32(p, d) | ||
79 | |||
80 | # define AV_RL32(x) bswap_32(AV_RN32(x)) | ||
81 | # define AV_WL32(p, d) AV_WN32(p, bswap_32(d)) | ||
82 | |||
83 | # define AV_RB64(x) AV_RN64(x) | ||
84 | # define AV_WB64(p, d) AV_WN64(p, d) | ||
85 | |||
86 | # define AV_RL64(x) bswap_64(AV_RN64(x)) | ||
87 | # define AV_WL64(p, d) AV_WN64(p, bswap_64(d)) | ||
88 | # else /* WORDS_BIGENDIAN */ | ||
89 | # define AV_RB16(x) bswap_16(AV_RN16(x)) | ||
90 | # define AV_WB16(p, d) AV_WN16(p, bswap_16(d)) | ||
91 | |||
92 | # define AV_RL16(x) AV_RN16(x) | ||
93 | # define AV_WL16(p, d) AV_WN16(p, d) | ||
94 | |||
95 | # define AV_RB32(x) bswap_32(AV_RN32(x)) | ||
96 | # define AV_WB32(p, d) AV_WN32(p, bswap_32(d)) | ||
97 | |||
98 | # define AV_RL32(x) AV_RN32(x) | ||
99 | # define AV_WL32(p, d) AV_WN32(p, d) | ||
100 | |||
101 | # define AV_RB64(x) bswap_64(AV_RN64(x)) | ||
102 | # define AV_WB64(p, d) AV_WN64(p, bswap_64(d)) | ||
103 | |||
104 | # define AV_RL64(x) AV_RN64(x) | ||
105 | # define AV_WL64(p, d) AV_WN64(p, d) | ||
106 | # endif | ||
107 | #else /* HAVE_FAST_UNALIGNED */ | ||
108 | #define AV_RB16(x) ((((const uint8_t*)(x))[0] << 8) | ((const uint8_t*)(x))[1]) | ||
109 | #define AV_WB16(p, d) do { \ | ||
110 | ((uint8_t*)(p))[1] = (d); \ | ||
111 | ((uint8_t*)(p))[0] = (d)>>8; } while(0) | ||
112 | |||
113 | #define AV_RL16(x) ((((const uint8_t*)(x))[1] << 8) | \ | ||
114 | ((const uint8_t*)(x))[0]) | ||
115 | #define AV_WL16(p, d) do { \ | ||
116 | ((uint8_t*)(p))[0] = (d); \ | ||
117 | ((uint8_t*)(p))[1] = (d)>>8; } while(0) | ||
118 | |||
119 | #define AV_RB32(x) ((((const uint8_t*)(x))[0] << 24) | \ | ||
120 | (((const uint8_t*)(x))[1] << 16) | \ | ||
121 | (((const uint8_t*)(x))[2] << 8) | \ | ||
122 | ((const uint8_t*)(x))[3]) | ||
123 | #define AV_WB32(p, d) do { \ | ||
124 | ((uint8_t*)(p))[3] = (d); \ | ||
125 | ((uint8_t*)(p))[2] = (d)>>8; \ | ||
126 | ((uint8_t*)(p))[1] = (d)>>16; \ | ||
127 | ((uint8_t*)(p))[0] = (d)>>24; } while(0) | ||
128 | |||
129 | #define AV_RL32(x) ((((const uint8_t*)(x))[3] << 24) | \ | ||
130 | (((const uint8_t*)(x))[2] << 16) | \ | ||
131 | (((const uint8_t*)(x))[1] << 8) | \ | ||
132 | ((const uint8_t*)(x))[0]) | ||
133 | #define AV_WL32(p, d) do { \ | ||
134 | ((uint8_t*)(p))[0] = (d); \ | ||
135 | ((uint8_t*)(p))[1] = (d)>>8; \ | ||
136 | ((uint8_t*)(p))[2] = (d)>>16; \ | ||
137 | ((uint8_t*)(p))[3] = (d)>>24; } while(0) | ||
138 | |||
139 | #define AV_RB64(x) (((uint64_t)((const uint8_t*)(x))[0] << 56) | \ | ||
140 | ((uint64_t)((const uint8_t*)(x))[1] << 48) | \ | ||
141 | ((uint64_t)((const uint8_t*)(x))[2] << 40) | \ | ||
142 | ((uint64_t)((const uint8_t*)(x))[3] << 32) | \ | ||
143 | ((uint64_t)((const uint8_t*)(x))[4] << 24) | \ | ||
144 | ((uint64_t)((const uint8_t*)(x))[5] << 16) | \ | ||
145 | ((uint64_t)((const uint8_t*)(x))[6] << 8) | \ | ||
146 | (uint64_t)((const uint8_t*)(x))[7]) | ||
147 | #define AV_WB64(p, d) do { \ | ||
148 | ((uint8_t*)(p))[7] = (d); \ | ||
149 | ((uint8_t*)(p))[6] = (d)>>8; \ | ||
150 | ((uint8_t*)(p))[5] = (d)>>16; \ | ||
151 | ((uint8_t*)(p))[4] = (d)>>24; \ | ||
152 | ((uint8_t*)(p))[3] = (d)>>32; \ | ||
153 | ((uint8_t*)(p))[2] = (d)>>40; \ | ||
154 | ((uint8_t*)(p))[1] = (d)>>48; \ | ||
155 | ((uint8_t*)(p))[0] = (d)>>56; } while(0) | ||
156 | |||
157 | #define AV_RL64(x) (((uint64_t)((const uint8_t*)(x))[7] << 56) | \ | ||
158 | ((uint64_t)((const uint8_t*)(x))[6] << 48) | \ | ||
159 | ((uint64_t)((const uint8_t*)(x))[5] << 40) | \ | ||
160 | ((uint64_t)((const uint8_t*)(x))[4] << 32) | \ | ||
161 | ((uint64_t)((const uint8_t*)(x))[3] << 24) | \ | ||
162 | ((uint64_t)((const uint8_t*)(x))[2] << 16) | \ | ||
163 | ((uint64_t)((const uint8_t*)(x))[1] << 8) | \ | ||
164 | (uint64_t)((const uint8_t*)(x))[0]) | ||
165 | #define AV_WL64(p, d) do { \ | ||
166 | ((uint8_t*)(p))[0] = (d); \ | ||
167 | ((uint8_t*)(p))[1] = (d)>>8; \ | ||
168 | ((uint8_t*)(p))[2] = (d)>>16; \ | ||
169 | ((uint8_t*)(p))[3] = (d)>>24; \ | ||
170 | ((uint8_t*)(p))[4] = (d)>>32; \ | ||
171 | ((uint8_t*)(p))[5] = (d)>>40; \ | ||
172 | ((uint8_t*)(p))[6] = (d)>>48; \ | ||
173 | ((uint8_t*)(p))[7] = (d)>>56; } while(0) | ||
174 | #endif /* HAVE_FAST_UNALIGNED */ | ||
175 | |||
176 | #define AV_RB24(x) ((((const uint8_t*)(x))[0] << 16) | \ | ||
177 | (((const uint8_t*)(x))[1] << 8) | \ | ||
178 | ((const uint8_t*)(x))[2]) | ||
179 | #define AV_WB24(p, d) do { \ | ||
180 | ((uint8_t*)(p))[2] = (d); \ | ||
181 | ((uint8_t*)(p))[1] = (d)>>8; \ | ||
182 | ((uint8_t*)(p))[0] = (d)>>16; } while(0) | ||
183 | |||
184 | #define AV_RL24(x) ((((const uint8_t*)(x))[2] << 16) | \ | ||
185 | (((const uint8_t*)(x))[1] << 8) | \ | ||
186 | ((const uint8_t*)(x))[0]) | ||
187 | #define AV_WL24(p, d) do { \ | ||
188 | ((uint8_t*)(p))[0] = (d); \ | ||
189 | ((uint8_t*)(p))[1] = (d)>>8; \ | ||
190 | ((uint8_t*)(p))[2] = (d)>>16; } while(0) | ||
191 | |||
192 | #endif /* AVUTIL_INTREADWRITE_H */ | ||
diff --git a/apps/codecs/libatrac/libavutil/log.c b/apps/codecs/libatrac/libavutil/log.c new file mode 100644 index 0000000000..4bb9652c2c --- /dev/null +++ b/apps/codecs/libatrac/libavutil/log.c | |||
@@ -0,0 +1,89 @@ | |||
1 | /* | ||
2 | * log functions | ||
3 | * Copyright (c) 2003 Michel Bardiaux | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | |||
22 | /** | ||
23 | * @file libavutil/log.c | ||
24 | * logging functions | ||
25 | */ | ||
26 | |||
27 | #include "avutil.h" | ||
28 | #include "log.h" | ||
29 | |||
30 | int av_log_level = AV_LOG_INFO; | ||
31 | |||
32 | void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) | ||
33 | { | ||
34 | static int print_prefix=1; | ||
35 | static int count; | ||
36 | static char line[1024], prev[1024]; | ||
37 | AVClass* avc= ptr ? *(AVClass**)ptr : NULL; | ||
38 | if(level>av_log_level) | ||
39 | return; | ||
40 | #undef fprintf | ||
41 | if(print_prefix && avc) { | ||
42 | snprintf(line, sizeof(line), "[%s @ %p]", avc->item_name(ptr), ptr); | ||
43 | }else | ||
44 | line[0]=0; | ||
45 | |||
46 | vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); | ||
47 | |||
48 | print_prefix= line[strlen(line)-1] == '\n'; | ||
49 | if(print_prefix && !strcmp(line, prev)){ | ||
50 | count++; | ||
51 | return; | ||
52 | } | ||
53 | if(count>0){ | ||
54 | fprintf(stderr, " Last message repeated %d times\n", count); | ||
55 | count=0; | ||
56 | } | ||
57 | fputs(line, stderr); | ||
58 | strcpy(prev, line); | ||
59 | } | ||
60 | |||
61 | static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; | ||
62 | |||
63 | void av_log(void* avcl, int level, const char *fmt, ...) | ||
64 | { | ||
65 | va_list vl; | ||
66 | va_start(vl, fmt); | ||
67 | av_vlog(avcl, level, fmt, vl); | ||
68 | va_end(vl); | ||
69 | } | ||
70 | |||
71 | void av_vlog(void* avcl, int level, const char *fmt, va_list vl) | ||
72 | { | ||
73 | av_log_callback(avcl, level, fmt, vl); | ||
74 | } | ||
75 | |||
76 | int av_log_get_level(void) | ||
77 | { | ||
78 | return av_log_level; | ||
79 | } | ||
80 | |||
81 | void av_log_set_level(int level) | ||
82 | { | ||
83 | av_log_level = level; | ||
84 | } | ||
85 | |||
86 | void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) | ||
87 | { | ||
88 | av_log_callback = callback; | ||
89 | } | ||
diff --git a/apps/codecs/libatrac/libavutil/log.h b/apps/codecs/libatrac/libavutil/log.h new file mode 100644 index 0000000000..1206a2fc38 --- /dev/null +++ b/apps/codecs/libatrac/libavutil/log.h | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #ifndef AVUTIL_LOG_H | ||
22 | #define AVUTIL_LOG_H | ||
23 | |||
24 | #include <stdarg.h> | ||
25 | #include "avutil.h" | ||
26 | |||
27 | /** | ||
28 | * Describes the class of an AVClass context structure. That is an | ||
29 | * arbitrary struct of which the first field is a pointer to an | ||
30 | * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.). | ||
31 | */ | ||
32 | typedef struct AVCLASS AVClass; | ||
33 | struct AVCLASS { | ||
34 | /** | ||
35 | * The name of the class; usually it is the same name as the | ||
36 | * context structure type to which the AVClass is associated. | ||
37 | */ | ||
38 | const char* class_name; | ||
39 | |||
40 | /** | ||
41 | * A pointer to a function which returns the name of a context | ||
42 | * instance \p ctx associated with the class. | ||
43 | */ | ||
44 | const char* (*item_name)(void* ctx); | ||
45 | |||
46 | /** | ||
47 | * a pointer to the first option specified in the class if any or NULL | ||
48 | * | ||
49 | * @see av_set_default_options() | ||
50 | */ | ||
51 | const struct AVOption *option; | ||
52 | }; | ||
53 | |||
54 | /* av_log API */ | ||
55 | |||
56 | #define AV_LOG_QUIET -8 | ||
57 | |||
58 | /** | ||
59 | * Something went really wrong and we will crash now. | ||
60 | */ | ||
61 | #define AV_LOG_PANIC 0 | ||
62 | |||
63 | /** | ||
64 | * Something went wrong and recovery is not possible. | ||
65 | * For example, no header was found for a format which depends | ||
66 | * on headers or an illegal combination of parameters is used. | ||
67 | */ | ||
68 | #define AV_LOG_FATAL 8 | ||
69 | |||
70 | /** | ||
71 | * Something went wrong and cannot losslessly be recovered. | ||
72 | * However, not all future data is affected. | ||
73 | */ | ||
74 | #define AV_LOG_ERROR 16 | ||
75 | |||
76 | /** | ||
77 | * Something somehow does not look correct. This may or may not | ||
78 | * lead to problems. An example would be the use of '-vstrict -2'. | ||
79 | */ | ||
80 | #define AV_LOG_WARNING 24 | ||
81 | |||
82 | #define AV_LOG_INFO 32 | ||
83 | #define AV_LOG_VERBOSE 40 | ||
84 | |||
85 | /** | ||
86 | * Stuff which is only useful for libav* developers. | ||
87 | */ | ||
88 | #define AV_LOG_DEBUG 48 | ||
89 | |||
90 | /** | ||
91 | * Sends the specified message to the log if the level is less than or equal | ||
92 | * to the current av_log_level. By default, all logging messages are sent to | ||
93 | * stderr. This behavior can be altered by setting a different av_vlog callback | ||
94 | * function. | ||
95 | * | ||
96 | * @param avcl A pointer to an arbitrary struct of which the first field is a | ||
97 | * pointer to an AVClass struct. | ||
98 | * @param level The importance level of the message, lower values signifying | ||
99 | * higher importance. | ||
100 | * @param fmt The format string (printf-compatible) that specifies how | ||
101 | * subsequent arguments are converted to output. | ||
102 | * @see av_vlog | ||
103 | */ | ||
104 | #ifdef __GNUC__ | ||
105 | void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); | ||
106 | #else | ||
107 | void av_log(void*, int level, const char *fmt, ...); | ||
108 | #endif | ||
109 | |||
110 | void av_vlog(void*, int level, const char *fmt, va_list); | ||
111 | int av_log_get_level(void); | ||
112 | void av_log_set_level(int); | ||
113 | void av_log_set_callback(void (*)(void*, int, const char*, va_list)); | ||
114 | void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl); | ||
115 | |||
116 | #endif /* AVUTIL_LOG_H */ | ||
diff --git a/apps/codecs/libatrac/libavutil/mem.c b/apps/codecs/libatrac/libavutil/mem.c new file mode 100644 index 0000000000..9721222e50 --- /dev/null +++ b/apps/codecs/libatrac/libavutil/mem.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /* | ||
2 | * default memory allocator for libavutil | ||
3 | * Copyright (c) 2002 Fabrice Bellard | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | |||
22 | /** | ||
23 | * @file libavutil/mem.c | ||
24 | * default memory allocator for libavutil | ||
25 | */ | ||
26 | |||
27 | //#include "ffmpeg_config.h" | ||
28 | |||
29 | #include <limits.h> | ||
30 | #include <stdlib.h> | ||
31 | #include <string.h> | ||
32 | #if HAVE_MALLOC_H | ||
33 | #include <malloc.h> | ||
34 | #endif | ||
35 | |||
36 | #include "mem.h" | ||
37 | |||
38 | /* here we can use OS-dependent allocation functions */ | ||
39 | #undef free | ||
40 | #undef malloc | ||
41 | #undef realloc | ||
42 | |||
43 | /* You can redefine av_malloc and av_free in your project to use your | ||
44 | memory allocator. You do not need to suppress this file because the | ||
45 | linker will do it automatically. */ | ||
46 | |||
47 | void *av_malloc(unsigned int size) | ||
48 | { | ||
49 | void *ptr = NULL; | ||
50 | #if CONFIG_MEMALIGN_HACK | ||
51 | long diff; | ||
52 | #endif | ||
53 | |||
54 | /* let's disallow possible ambiguous cases */ | ||
55 | if(size > (INT_MAX-16) ) | ||
56 | return NULL; | ||
57 | |||
58 | #if CONFIG_MEMALIGN_HACK | ||
59 | ptr = malloc(size+16); | ||
60 | if(!ptr) | ||
61 | return ptr; | ||
62 | diff= ((-(long)ptr - 1)&15) + 1; | ||
63 | ptr = (char*)ptr + diff; | ||
64 | ((char*)ptr)[-1]= diff; | ||
65 | #elif HAVE_POSIX_MEMALIGN | ||
66 | if (posix_memalign(&ptr,16,size)) | ||
67 | ptr = NULL; | ||
68 | #elif HAVE_MEMALIGN | ||
69 | ptr = memalign(16,size); | ||
70 | /* Why 64? | ||
71 | Indeed, we should align it: | ||
72 | on 4 for 386 | ||
73 | on 16 for 486 | ||
74 | on 32 for 586, PPro - K6-III | ||
75 | on 64 for K7 (maybe for P3 too). | ||
76 | Because L1 and L2 caches are aligned on those values. | ||
77 | But I don't want to code such logic here! | ||
78 | */ | ||
79 | /* Why 16? | ||
80 | Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs | ||
81 | it will just trigger an exception and the unaligned load will be done in the | ||
82 | exception handler or it will just segfault (SSE2 on P4). | ||
83 | Why not larger? Because I did not see a difference in benchmarks ... | ||
84 | */ | ||
85 | /* benchmarks with P3 | ||
86 | memalign(64)+1 3071,3051,3032 | ||
87 | memalign(64)+2 3051,3032,3041 | ||
88 | memalign(64)+4 2911,2896,2915 | ||
89 | memalign(64)+8 2545,2554,2550 | ||
90 | memalign(64)+16 2543,2572,2563 | ||
91 | memalign(64)+32 2546,2545,2571 | ||
92 | memalign(64)+64 2570,2533,2558 | ||
93 | |||
94 | BTW, malloc seems to do 8-byte alignment by default here. | ||
95 | */ | ||
96 | #else | ||
97 | ptr = malloc(size); | ||
98 | #endif | ||
99 | return ptr; | ||
100 | } | ||
101 | |||
102 | void *av_realloc(void *ptr, unsigned int size) | ||
103 | { | ||
104 | #if CONFIG_MEMALIGN_HACK | ||
105 | int diff; | ||
106 | #endif | ||
107 | |||
108 | /* let's disallow possible ambiguous cases */ | ||
109 | if(size > (INT_MAX-16) ) | ||
110 | return NULL; | ||
111 | |||
112 | #if CONFIG_MEMALIGN_HACK | ||
113 | //FIXME this isn't aligned correctly, though it probably isn't needed | ||
114 | if(!ptr) return av_malloc(size); | ||
115 | diff= ((char*)ptr)[-1]; | ||
116 | return (char*)realloc((char*)ptr - diff, size + diff) + diff; | ||
117 | #else | ||
118 | return realloc(ptr, size); | ||
119 | #endif | ||
120 | } | ||
121 | |||
122 | void av_free(void *ptr) | ||
123 | { | ||
124 | /* XXX: this test should not be needed on most libcs */ | ||
125 | if (ptr) | ||
126 | #if CONFIG_MEMALIGN_HACK | ||
127 | free((char*)ptr - ((char*)ptr)[-1]); | ||
128 | #else | ||
129 | free(ptr); | ||
130 | #endif | ||
131 | } | ||
132 | |||
133 | void av_freep(void *arg) | ||
134 | { | ||
135 | void **ptr= (void**)arg; | ||
136 | av_free(*ptr); | ||
137 | *ptr = NULL; | ||
138 | } | ||
139 | |||
140 | void *av_mallocz(unsigned int size) | ||
141 | { | ||
142 | void *ptr = av_malloc(size); | ||
143 | if (ptr) | ||
144 | memset(ptr, 0, size); | ||
145 | return ptr; | ||
146 | } | ||
147 | |||
148 | char *av_strdup(const char *s) | ||
149 | { | ||
150 | char *ptr= NULL; | ||
151 | if(s){ | ||
152 | int len = strlen(s) + 1; | ||
153 | ptr = av_malloc(len); | ||
154 | if (ptr) | ||
155 | memcpy(ptr, s, len); | ||
156 | } | ||
157 | return ptr; | ||
158 | } | ||
159 | |||
diff --git a/apps/codecs/libatrac/libavutil/mem.h b/apps/codecs/libatrac/libavutil/mem.h new file mode 100644 index 0000000000..e50553aefe --- /dev/null +++ b/apps/codecs/libatrac/libavutil/mem.h | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> | ||
3 | * | ||
4 | * This file is part of FFmpeg. | ||
5 | * | ||
6 | * FFmpeg is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU Lesser General Public | ||
8 | * License as published by the Free Software Foundation; either | ||
9 | * version 2.1 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * FFmpeg is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
14 | * Lesser General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU Lesser General Public | ||
17 | * License along with FFmpeg; if not, write to the Free Software | ||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file libavutil/mem.h | ||
23 | * memory handling functions | ||
24 | */ | ||
25 | |||
26 | #ifndef AVUTIL_MEM_H | ||
27 | #define AVUTIL_MEM_H | ||
28 | |||
29 | #include "common.h" | ||
30 | |||
31 | #if AV_GCC_VERSION_AT_LEAST(3,1) | ||
32 | #define av_malloc_attrib __attribute__((__malloc__)) | ||
33 | #else | ||
34 | #define av_malloc_attrib | ||
35 | #endif | ||
36 | |||
37 | #if (!defined(__ICC) || __ICC > 1100) && AV_GCC_VERSION_AT_LEAST(4,3) | ||
38 | #define av_alloc_size(n) __attribute__((alloc_size(n))) | ||
39 | #else | ||
40 | #define av_alloc_size(n) | ||
41 | #endif | ||
42 | |||
43 | /** | ||
44 | * Allocates a block of \p size bytes with alignment suitable for all | ||
45 | * memory accesses (including vectors if available on the CPU). | ||
46 | * @param size Size in bytes for the memory block to be allocated. | ||
47 | * @return Pointer to the allocated block, NULL if the block cannot | ||
48 | * be allocated. | ||
49 | * @see av_mallocz() | ||
50 | */ | ||
51 | void *av_malloc(unsigned int size) av_malloc_attrib av_alloc_size(1); | ||
52 | |||
53 | /** | ||
54 | * Allocates or reallocates a block of memory. | ||
55 | * If \p ptr is NULL and \p size > 0, allocates a new block. If \p | ||
56 | * size is zero, frees the memory block pointed to by \p ptr. | ||
57 | * @param size Size in bytes for the memory block to be allocated or | ||
58 | * reallocated. | ||
59 | * @param ptr Pointer to a memory block already allocated with | ||
60 | * av_malloc(z)() or av_realloc() or NULL. | ||
61 | * @return Pointer to a newly reallocated block or NULL if the block | ||
62 | * cannot be reallocated or the function is used to free the memory block. | ||
63 | * @see av_fast_realloc() | ||
64 | */ | ||
65 | void *av_realloc(void *ptr, unsigned int size) av_alloc_size(2); | ||
66 | |||
67 | /** | ||
68 | * Frees a memory block which has been allocated with av_malloc(z)() or | ||
69 | * av_realloc(). | ||
70 | * @param ptr Pointer to the memory block which should be freed. | ||
71 | * @note ptr = NULL is explicitly allowed. | ||
72 | * @note It is recommended that you use av_freep() instead. | ||
73 | * @see av_freep() | ||
74 | */ | ||
75 | void av_free(void *ptr); | ||
76 | |||
77 | /** | ||
78 | * Allocates a block of \p size bytes with alignment suitable for all | ||
79 | * memory accesses (including vectors if available on the CPU) and | ||
80 | * zeroes all the bytes of the block. | ||
81 | * @param size Size in bytes for the memory block to be allocated. | ||
82 | * @return Pointer to the allocated block, NULL if it cannot be allocated. | ||
83 | * @see av_malloc() | ||
84 | */ | ||
85 | void *av_mallocz(unsigned int size) av_malloc_attrib av_alloc_size(1); | ||
86 | |||
87 | /** | ||
88 | * Duplicates the string \p s. | ||
89 | * @param s string to be duplicated | ||
90 | * @return Pointer to a newly allocated string containing a | ||
91 | * copy of \p s or NULL if the string cannot be allocated. | ||
92 | */ | ||
93 | char *av_strdup(const char *s) av_malloc_attrib; | ||
94 | |||
95 | /** | ||
96 | * Frees a memory block which has been allocated with av_malloc(z)() or | ||
97 | * av_realloc() and set the pointer pointing to it to NULL. | ||
98 | * @param ptr Pointer to the pointer to the memory block which should | ||
99 | * be freed. | ||
100 | * @see av_free() | ||
101 | */ | ||
102 | void av_freep(void *ptr); | ||
103 | |||
104 | #endif /* AVUTIL_MEM_H */ | ||
diff --git a/apps/codecs/libatrac/mdct.c b/apps/codecs/libatrac/mdct.c new file mode 100644 index 0000000000..670b6d381e --- /dev/null +++ b/apps/codecs/libatrac/mdct.c | |||
@@ -0,0 +1,245 @@ | |||
1 | /* | ||
2 | * MDCT/IMDCT transforms | ||
3 | * Copyright (c) 2002 Fabrice Bellard | ||
4 | * | ||
5 | * This file is part of FFmpeg. | ||
6 | * | ||
7 | * FFmpeg is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU Lesser General Public | ||
9 | * License as published by the Free Software Foundation; either | ||
10 | * version 2.1 of the License, or (at your option) any later version. | ||
11 | * | ||
12 | * FFmpeg is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with FFmpeg; if not, write to the Free Software | ||
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
20 | */ | ||
21 | #include "dsputil.h" | ||
22 | |||
23 | #ifndef M_E | ||
24 | #define M_E 2.7182818284590452354 /* e */ | ||
25 | #endif | ||
26 | #ifndef M_LN2 | ||
27 | #define M_LN2 0.69314718055994530942 /* log_e 2 */ | ||
28 | #endif | ||
29 | #ifndef M_LN10 | ||
30 | #define M_LN10 2.30258509299404568402 /* log_e 10 */ | ||
31 | #endif | ||
32 | #ifndef M_PI | ||
33 | #define M_PI 3.14159265358979323846 /* pi */ | ||
34 | #endif | ||
35 | #ifndef M_SQRT1_2 | ||
36 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ | ||
37 | #endif | ||
38 | |||
39 | /** | ||
40 | * @file libavcodec/mdct.c | ||
41 | * MDCT/IMDCT transforms. | ||
42 | */ | ||
43 | |||
44 | // Generate a Kaiser-Bessel Derived Window. | ||
45 | #define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation | ||
46 | av_cold void ff_kbd_window_init(float *window, float alpha, int n) | ||
47 | { | ||
48 | int i, j; | ||
49 | double sum = 0.0, bessel, tmp; | ||
50 | double local_window[n]; | ||
51 | double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); | ||
52 | |||
53 | for (i = 0; i < n; i++) { | ||
54 | tmp = i * (n - i) * alpha2; | ||
55 | bessel = 1.0; | ||
56 | for (j = BESSEL_I0_ITER; j > 0; j--) | ||
57 | bessel = bessel * tmp / (j * j) + 1; | ||
58 | sum += bessel; | ||
59 | local_window[i] = sum; | ||
60 | } | ||
61 | |||
62 | sum++; | ||
63 | for (i = 0; i < n; i++) | ||
64 | window[i] = sqrt(local_window[i] / sum); | ||
65 | } | ||
66 | |||
67 | DECLARE_ALIGNED(16, float, ff_sine_128 [ 128]); | ||
68 | DECLARE_ALIGNED(16, float, ff_sine_256 [ 256]); | ||
69 | DECLARE_ALIGNED(16, float, ff_sine_512 [ 512]); | ||
70 | DECLARE_ALIGNED(16, float, ff_sine_1024[1024]); | ||
71 | DECLARE_ALIGNED(16, float, ff_sine_2048[2048]); | ||
72 | DECLARE_ALIGNED(16, float, ff_sine_4096[4096]); | ||
73 | float *ff_sine_windows[6] = { | ||
74 | ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 | ||
75 | }; | ||
76 | |||
77 | // Generate a sine window. | ||
78 | av_cold void ff_sine_window_init(float *window, int n) { | ||
79 | int i; | ||
80 | for(i = 0; i < n; i++) | ||
81 | window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); | ||
82 | } | ||
83 | |||
84 | /** | ||
85 | * init MDCT or IMDCT computation. | ||
86 | */ | ||
87 | av_cold int ff_mdct_init(MDCTContext *s, int nbits, int inverse) | ||
88 | { | ||
89 | int n, n4, i; | ||
90 | double alpha; | ||
91 | |||
92 | memset(s, 0, sizeof(*s)); | ||
93 | n = 1 << nbits; | ||
94 | s->nbits = nbits; | ||
95 | s->n = n; | ||
96 | n4 = n >> 2; | ||
97 | s->tcos = av_malloc(n4 * sizeof(FFTSample)); | ||
98 | if (!s->tcos) | ||
99 | goto fail; | ||
100 | s->tsin = av_malloc(n4 * sizeof(FFTSample)); | ||
101 | if (!s->tsin) | ||
102 | goto fail; | ||
103 | |||
104 | for(i=0;i<n4;i++) { | ||
105 | alpha = 2 * M_PI * (i + 1.0 / 8.0) / n; | ||
106 | s->tcos[i] = -cos(alpha); | ||
107 | s->tsin[i] = -sin(alpha); | ||
108 | } | ||
109 | if (ff_fft_init(&s->fft, s->nbits - 2, inverse) < 0) | ||
110 | goto fail; | ||
111 | return 0; | ||
112 | fail: | ||
113 | av_freep(&s->tcos); | ||
114 | av_freep(&s->tsin); | ||
115 | return -1; | ||
116 | } | ||
117 | |||
118 | /* complex multiplication: p = a * b */ | ||
119 | #define CMUL(pre, pim, are, aim, bre, bim) \ | ||
120 | {\ | ||
121 | FFTSample _are = (are);\ | ||
122 | FFTSample _aim = (aim);\ | ||
123 | FFTSample _bre = (bre);\ | ||
124 | FFTSample _bim = (bim);\ | ||
125 | (pre) = _are * _bre - _aim * _bim;\ | ||
126 | (pim) = _are * _bim + _aim * _bre;\ | ||
127 | } | ||
128 | |||
129 | /** | ||
130 | * Compute the middle half of the inverse MDCT of size N = 2^nbits, | ||
131 | * thus excluding the parts that can be derived by symmetry | ||
132 | * @param output N/2 samples | ||
133 | * @param input N/2 samples | ||
134 | */ | ||
135 | void ff_imdct_half_c(MDCTContext *s, FFTSample *output, const FFTSample *input) | ||
136 | { | ||
137 | int k, n8, n4, n2, n, j; | ||
138 | const uint16_t *revtab = s->fft.revtab; | ||
139 | const FFTSample *tcos = s->tcos; | ||
140 | const FFTSample *tsin = s->tsin; | ||
141 | const FFTSample *in1, *in2; | ||
142 | FFTComplex *z = (FFTComplex *)output; | ||
143 | |||
144 | n = 1 << s->nbits; | ||
145 | n2 = n >> 1; | ||
146 | n4 = n >> 2; | ||
147 | n8 = n >> 3; | ||
148 | |||
149 | /* pre rotation */ | ||
150 | in1 = input; | ||
151 | in2 = input + n2 - 1; | ||
152 | for(k = 0; k < n4; k++) { | ||
153 | j=revtab[k]; | ||
154 | CMUL(z[j].re, z[j].im, *in2, *in1, tcos[k], tsin[k]); | ||
155 | in1 += 2; | ||
156 | in2 -= 2; | ||
157 | } | ||
158 | ff_fft_calc(&s->fft, z); | ||
159 | |||
160 | /* post rotation + reordering */ | ||
161 | output += n4; | ||
162 | for(k = 0; k < n8; k++) { | ||
163 | FFTSample r0, i0, r1, i1; | ||
164 | CMUL(r0, i1, z[n8-k-1].im, z[n8-k-1].re, tsin[n8-k-1], tcos[n8-k-1]); | ||
165 | CMUL(r1, i0, z[n8+k ].im, z[n8+k ].re, tsin[n8+k ], tcos[n8+k ]); | ||
166 | z[n8-k-1].re = r0; | ||
167 | z[n8-k-1].im = i0; | ||
168 | z[n8+k ].re = r1; | ||
169 | z[n8+k ].im = i1; | ||
170 | } | ||
171 | } | ||
172 | |||
173 | /** | ||
174 | * Compute inverse MDCT of size N = 2^nbits | ||
175 | * @param output N samples | ||
176 | * @param input N/2 samples | ||
177 | */ | ||
178 | void ff_imdct_calc_c(MDCTContext *s, FFTSample *output, const FFTSample *input) | ||
179 | { | ||
180 | int k; | ||
181 | int n = 1 << s->nbits; | ||
182 | int n2 = n >> 1; | ||
183 | int n4 = n >> 2; | ||
184 | |||
185 | ff_imdct_half_c(s, output+n4, input); | ||
186 | |||
187 | for(k = 0; k < n4; k++) { | ||
188 | output[k] = -output[n2-k-1]; | ||
189 | output[n-k-1] = output[n2+k]; | ||
190 | } | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Compute MDCT of size N = 2^nbits | ||
195 | * @param input N samples | ||
196 | * @param out N/2 samples | ||
197 | */ | ||
198 | void ff_mdct_calc(MDCTContext *s, FFTSample *out, const FFTSample *input) | ||
199 | { | ||
200 | int i, j, n, n8, n4, n2, n3; | ||
201 | FFTSample re, im; | ||
202 | const uint16_t *revtab = s->fft.revtab; | ||
203 | const FFTSample *tcos = s->tcos; | ||
204 | const FFTSample *tsin = s->tsin; | ||
205 | FFTComplex *x = (FFTComplex *)out; | ||
206 | |||
207 | n = 1 << s->nbits; | ||
208 | n2 = n >> 1; | ||
209 | n4 = n >> 2; | ||
210 | n8 = n >> 3; | ||
211 | n3 = 3 * n4; | ||
212 | |||
213 | /* pre rotation */ | ||
214 | for(i=0;i<n8;i++) { | ||
215 | re = -input[2*i+3*n4] - input[n3-1-2*i]; | ||
216 | im = -input[n4+2*i] + input[n4-1-2*i]; | ||
217 | j = revtab[i]; | ||
218 | CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]); | ||
219 | |||
220 | re = input[2*i] - input[n2-1-2*i]; | ||
221 | im = -(input[n2+2*i] + input[n-1-2*i]); | ||
222 | j = revtab[n8 + i]; | ||
223 | CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]); | ||
224 | } | ||
225 | |||
226 | ff_fft_calc(&s->fft, x); | ||
227 | |||
228 | /* post rotation */ | ||
229 | for(i=0;i<n8;i++) { | ||
230 | FFTSample r0, i0, r1, i1; | ||
231 | CMUL(i1, r0, x[n8-i-1].re, x[n8-i-1].im, -tsin[n8-i-1], -tcos[n8-i-1]); | ||
232 | CMUL(i0, r1, x[n8+i ].re, x[n8+i ].im, -tsin[n8+i ], -tcos[n8+i ]); | ||
233 | x[n8-i-1].re = r0; | ||
234 | x[n8-i-1].im = i0; | ||
235 | x[n8+i ].re = r1; | ||
236 | x[n8+i ].im = i1; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | av_cold void ff_mdct_end(MDCTContext *s) | ||
241 | { | ||
242 | av_freep(&s->tcos); | ||
243 | av_freep(&s->tsin); | ||
244 | ff_fft_end(&s->fft); | ||
245 | } | ||
diff --git a/apps/codecs/librm/rm.c b/apps/codecs/librm/rm.c index 00ee37a2f2..7053e7d58c 100644 --- a/apps/codecs/librm/rm.c +++ b/apps/codecs/librm/rm.c | |||
@@ -29,7 +29,7 @@ | |||
29 | 29 | ||
30 | #define SWAP(a, b) do{uint8_t SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) | 30 | #define SWAP(a, b) do{uint8_t SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) |
31 | 31 | ||
32 | static void advance_buffer(uint8_t **buf, int val) | 32 | void advance_buffer(uint8_t **buf, int val) |
33 | { | 33 | { |
34 | *buf += val; | 34 | *buf += val; |
35 | } | 35 | } |
@@ -237,10 +237,40 @@ static int real_read_audio_stream_info(int fd, RMContext *rmctx) | |||
237 | skipped += 1; | 237 | skipped += 1; |
238 | } | 238 | } |
239 | 239 | ||
240 | read_uint32be(fd, &rmctx->extradata_size); | 240 | switch(fourcc) { |
241 | skipped += 4; | 241 | case FOURCC('c','o','o','k'): |
242 | read(fd, rmctx->codec_extradata, rmctx->extradata_size); | 242 | rmctx->codec_type = CODEC_COOK; |
243 | skipped += rmctx->extradata_size; | 243 | read_uint32be(fd, &rmctx->extradata_size); |
244 | skipped += 4; | ||
245 | read(fd, rmctx->codec_extradata, rmctx->extradata_size); | ||
246 | skipped += rmctx->extradata_size; | ||
247 | break; | ||
248 | |||
249 | case FOURCC('a','t','r','c'): | ||
250 | DEBUGF("WERE HERE\n"); | ||
251 | rmctx->codec_type = CODEC_ATRAC; | ||
252 | read_uint32be(fd, &rmctx->extradata_size); | ||
253 | skipped += 4; | ||
254 | read(fd, rmctx->codec_extradata, rmctx->extradata_size); | ||
255 | skipped += rmctx->extradata_size; | ||
256 | break; | ||
257 | |||
258 | case FOURCC('r','a','a','c'): | ||
259 | case FOURCC('r','a','c','p'): | ||
260 | rmctx->codec_type = CODEC_AAC; | ||
261 | read_uint32be(fd, &rmctx->extradata_size); | ||
262 | skipped += 4; | ||
263 | read(fd, rmctx->codec_extradata, rmctx->extradata_size); | ||
264 | skipped += rmctx->extradata_size; | ||
265 | break; | ||
266 | |||
267 | case FOURCC('d','n','e','t'): | ||
268 | rmctx->codec_type = CODEC_AC3; | ||
269 | break; | ||
270 | |||
271 | default: /* Not a supported codec */ | ||
272 | return -1; | ||
273 | } | ||
244 | 274 | ||
245 | 275 | ||
246 | DEBUGF(" flavor = %d\n",flavor); | 276 | DEBUGF(" flavor = %d\n",flavor); |
@@ -252,8 +282,10 @@ static int real_read_audio_stream_info(int fd, RMContext *rmctx) | |||
252 | DEBUGF(" channels= %d\n",rmctx->nb_channels); | 282 | DEBUGF(" channels= %d\n",rmctx->nb_channels); |
253 | DEBUGF(" fourcc = %s\n",fourcc2str(fourcc)); | 283 | DEBUGF(" fourcc = %s\n",fourcc2str(fourcc)); |
254 | DEBUGF(" codec_extra_data_length = %d\n",rmctx->extradata_size); | 284 | DEBUGF(" codec_extra_data_length = %d\n",rmctx->extradata_size); |
255 | DEBUGF(" codec_extradata :\n"); | 285 | if(rmctx->codec_type == CODEC_COOK) { |
256 | print_cook_extradata(rmctx); | 286 | DEBUGF(" cook_extradata :\n"); |
287 | print_cook_extradata(rmctx); | ||
288 | } | ||
257 | 289 | ||
258 | } | 290 | } |
259 | 291 | ||
@@ -530,7 +562,7 @@ int rm_get_packet(uint8_t **src,RMContext *rmctx, RMPacket *pkt) | |||
530 | 562 | ||
531 | advance_buffer(src,12); | 563 | advance_buffer(src,12); |
532 | consumed += 12; | 564 | consumed += 12; |
533 | if (rmctx->codec_type == CODEC_COOK) { | 565 | if (rmctx->codec_type == CODEC_COOK || rmctx->codec_type == CODEC_ATRAC) { |
534 | for(x = 0 ; x < w/sps; x++) | 566 | for(x = 0 ; x < w/sps; x++) |
535 | { | 567 | { |
536 | place = sps*(h*x+((h+1)/2)*(y&1)+(y>>1)); | 568 | place = sps*(h*x+((h+1)/2)*(y&1)+(y>>1)); |
diff --git a/apps/codecs/librm/rm.h b/apps/codecs/librm/rm.h index 86fe5e7f1a..be88701989 100644 --- a/apps/codecs/librm/rm.h +++ b/apps/codecs/librm/rm.h | |||
@@ -31,7 +31,8 @@ | |||
31 | enum codecs { | 31 | enum codecs { |
32 | CODEC_COOK, | 32 | CODEC_COOK, |
33 | CODEC_AAC, | 33 | CODEC_AAC, |
34 | CODEC_AC3 | 34 | CODEC_AC3, |
35 | CODEC_ATRAC | ||
35 | }; | 36 | }; |
36 | 37 | ||
37 | typedef struct rm_packet | 38 | typedef struct rm_packet |