summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/codecs/libwmavoice/Makefile65
-rw-r--r--apps/codecs/libwmavoice/README.rockbox23
-rw-r--r--apps/codecs/libwmavoice/acelp_filters.c2
-rw-r--r--apps/codecs/libwmavoice/acelp_vectors.c270
-rw-r--r--apps/codecs/libwmavoice/acelp_vectors.h264
-rw-r--r--apps/codecs/libwmavoice/avcodec.h14
-rw-r--r--apps/codecs/libwmavoice/bitstream.c2
-rw-r--r--apps/codecs/libwmavoice/dct.c226
-rw-r--r--apps/codecs/libwmavoice/dct32.c267
-rw-r--r--apps/codecs/libwmavoice/fft.c2
-rw-r--r--apps/codecs/libwmavoice/fft.h2
-rw-r--r--apps/codecs/libwmavoice/libavutil/avutil.h8
-rw-r--r--apps/codecs/libwmavoice/libavutil/mathematics.c2
-rw-r--r--apps/codecs/libwmavoice/libavutil/mathematics.h6
-rw-r--r--apps/codecs/libwmavoice/libavutil/mem.c2
-rw-r--r--apps/codecs/libwmavoice/lsp.c2
-rw-r--r--apps/codecs/libwmavoice/mathops.h182
-rw-r--r--apps/codecs/libwmavoice/mdct.c2
-rw-r--r--apps/codecs/libwmavoice/mdct_tablegen.h60
-rw-r--r--apps/codecs/libwmavoice/rdft.c133
-rw-r--r--apps/codecs/libwmavoice/utils.c1188
-rw-r--r--apps/codecs/libwmavoice/wmavoice.c8
22 files changed, 2709 insertions, 21 deletions
diff --git a/apps/codecs/libwmavoice/Makefile b/apps/codecs/libwmavoice/Makefile
new file mode 100644
index 0000000000..f1d987f40c
--- /dev/null
+++ b/apps/codecs/libwmavoice/Makefile
@@ -0,0 +1,65 @@
1CC = gcc -o
2INC = -I.
3OUTPUT = wmavoice
4STD = c99
5LIBS = -lm
6CFLAGS = -Wall -ggdb -std=$(STD) $(INC)
7
8SOURCES = \
9acelp_filters.c\
10acelp_vectors.c\
11avfft.c\
12bitstream.c\
13celp_filters.c\
14celp_math.c\
15dct.c\
16fft.c\
17lsp.c\
18mdct.c\
19rdft.c\
20utils.c\
21wmavoice.c\
22libavutil/log.c\
23libavutil/lzo.c\
24libavutil/mem.c\
25libavutil/mathematics.c
26
27HEADERS = \
28acelp_vectors.h\
29celp_math.h\
30get_bits.h\
31wmavoice_data.h\
32avcodec.h\
33fft.h\
34dsputil.h\
35acelp_filters.h\
36celp_filters.h\
37put_bits.h\
38lsp.h\
39internal.h\
40avfft.h\
41mathops.h\
42mdct_tablegen.h\
43dct32.c\
44libavutil/avutil.h\
45libavutil/attributes.h\
46libavutil/lzo.h\
47libavutil/mem.h\
48libavutil/log.h\
49libavutil/internal.h\
50libavutil/common.h\
51libavutil/intreadwrite.h\
52libavutil/bswap.h\
53libavutil/mathematics.h
54
55OBJECTS = $(SOURCES:.c=.o)
56
57all:$(OUTPUT)
58
59$(OUTPUT):$(SOURCES) $(HEADERS)
60 $(CC) $@ $(CFLAGS) $(SOURCES) $(LIBS)
61 @echo "Done."
62
63clean:
64 rm -f *.o $(OUTPUT) *~
65
diff --git a/apps/codecs/libwmavoice/README.rockbox b/apps/codecs/libwmavoice/README.rockbox
new file mode 100644
index 0000000000..4a21a9618b
--- /dev/null
+++ b/apps/codecs/libwmavoice/README.rockbox
@@ -0,0 +1,23 @@
1Library: libwmavoice
2Imported: 2010-08-07 by Mohamed Tarek
3
4This set of files form the files needed from ffmpeg's libavcodec and libavutil
5to build a standalone wma voice decoder.
6
7LICENSING INFORMATION
8
9ffmpeg is licensed under the Lesser GNU General Public License and the file
10wmavoice.c is copyright (c) 2009 Ronald S. Bultje.
11
12IMPORT DETAILS
13
14Based on ffmpeg svn r24734 dated 7 August 2010.
15
16As of 7 August 2010, libwmavoice contains just the files from ffmpeg with
17minimum modifications to comile standalone. The decoder isn't still used in
18rockbox in anyway.
19
20COMPILING
21
22the decoder can be compiled by issuing the "make" command from witin the
23libwmavoice directory in any unix-line environment.
diff --git a/apps/codecs/libwmavoice/acelp_filters.c b/apps/codecs/libwmavoice/acelp_filters.c
index 31f0e86f5b..c48c0e72ce 100644
--- a/apps/codecs/libwmavoice/acelp_filters.c
+++ b/apps/codecs/libwmavoice/acelp_filters.c
@@ -45,7 +45,7 @@ void ff_acelp_interpolate(int16_t* out, const int16_t* in,
45{ 45{
46 int n, i; 46 int n, i;
47 47
48 assert(frac_pos >= 0 && frac_pos < precision); 48 //assert(frac_pos >= 0 && frac_pos < precision);
49 49
50 for (n = 0; n < length; n++) { 50 for (n = 0; n < length; n++) {
51 int idx = 0; 51 int idx = 0;
diff --git a/apps/codecs/libwmavoice/acelp_vectors.c b/apps/codecs/libwmavoice/acelp_vectors.c
new file mode 100644
index 0000000000..e41e5facb6
--- /dev/null
+++ b/apps/codecs/libwmavoice/acelp_vectors.c
@@ -0,0 +1,270 @@
1/*
2 * adaptive and fixed codebook vector operations for ACELP-based codecs
3 *
4 * Copyright (c) 2008 Vladimir Voroshilov
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#include <inttypes.h>
24#include "avcodec.h"
25#include "acelp_vectors.h"
26#include "celp_math.h"
27
28const uint8_t ff_fc_2pulses_9bits_track1[16] =
29{
30 1, 3,
31 6, 8,
32 11, 13,
33 16, 18,
34 21, 23,
35 26, 28,
36 31, 33,
37 36, 38
38};
39const uint8_t ff_fc_2pulses_9bits_track1_gray[16] =
40{
41 1, 3,
42 8, 6,
43 18, 16,
44 11, 13,
45 38, 36,
46 31, 33,
47 21, 23,
48 28, 26,
49};
50
51const uint8_t ff_fc_2pulses_9bits_track2_gray[32] =
52{
53 0, 2,
54 5, 4,
55 12, 10,
56 7, 9,
57 25, 24,
58 20, 22,
59 14, 15,
60 19, 17,
61 36, 31,
62 21, 26,
63 1, 6,
64 16, 11,
65 27, 29,
66 32, 30,
67 39, 37,
68 34, 35,
69};
70
71const uint8_t ff_fc_4pulses_8bits_tracks_13[16] =
72{
73 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75,
74};
75
76const uint8_t ff_fc_4pulses_8bits_track_4[32] =
77{
78 3, 4,
79 8, 9,
80 13, 14,
81 18, 19,
82 23, 24,
83 28, 29,
84 33, 34,
85 38, 39,
86 43, 44,
87 48, 49,
88 53, 54,
89 58, 59,
90 63, 64,
91 68, 69,
92 73, 74,
93 78, 79,
94};
95
96#if 0
97static uint8_t gray_decode[32] =
98{
99 0, 1, 3, 2, 7, 6, 4, 5,
100 15, 14, 12, 13, 8, 9, 11, 10,
101 31, 30, 28, 29, 24, 25, 27, 26,
102 16, 17, 19, 18, 23, 22, 20, 21
103};
104#endif
105
106const float ff_pow_0_7[10] = {
107 0.700000, 0.490000, 0.343000, 0.240100, 0.168070,
108 0.117649, 0.082354, 0.057648, 0.040354, 0.028248
109};
110
111const float ff_pow_0_75[10] = {
112 0.750000, 0.562500, 0.421875, 0.316406, 0.237305,
113 0.177979, 0.133484, 0.100113, 0.075085, 0.056314
114};
115
116const float ff_pow_0_55[10] = {
117 0.550000, 0.302500, 0.166375, 0.091506, 0.050328,
118 0.027681, 0.015224, 0.008373, 0.004605, 0.002533
119};
120
121const float ff_b60_sinc[61] = {
122 0.898529 , 0.865051 , 0.769257 , 0.624054 , 0.448639 , 0.265289 ,
123 0.0959167 , -0.0412598 , -0.134338 , -0.178986 , -0.178528 , -0.142609 ,
124-0.0849304 , -0.0205078 , 0.0369568 , 0.0773926 , 0.0955200 , 0.0912781 ,
125 0.0689392 , 0.0357056 , 0. , -0.0305481 , -0.0504150 , -0.0570068 ,
126-0.0508423 , -0.0350037 , -0.0141602 , 0.00665283, 0.0230713 , 0.0323486 ,
127 0.0335388 , 0.0275879 , 0.0167847 , 0.00411987, -0.00747681, -0.0156860 ,
128-0.0193481 , -0.0183716 , -0.0137634 , -0.00704956, 0. , 0.00582886 ,
129 0.00939941, 0.0103760 , 0.00903320, 0.00604248, 0.00238037, -0.00109863 ,
130-0.00366211, -0.00497437, -0.00503540, -0.00402832, -0.00241089, -0.000579834,
131 0.00103760, 0.00222778, 0.00277710, 0.00271606, 0.00213623, 0.00115967 ,
132 0.
133};
134
135void ff_acelp_fc_pulse_per_track(
136 int16_t* fc_v,
137 const uint8_t *tab1,
138 const uint8_t *tab2,
139 int pulse_indexes,
140 int pulse_signs,
141 int pulse_count,
142 int bits)
143{
144 int mask = (1 << bits) - 1;
145 int i;
146
147 for(i=0; i<pulse_count; i++)
148 {
149 fc_v[i + tab1[pulse_indexes & mask]] +=
150 (pulse_signs & 1) ? 8191 : -8192; // +/-1 in (2.13)
151
152 pulse_indexes >>= bits;
153 pulse_signs >>= 1;
154 }
155
156 fc_v[tab2[pulse_indexes]] += (pulse_signs & 1) ? 8191 : -8192;
157}
158
159void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
160 AMRFixed *fixed_sparse,
161 const uint8_t *gray_decode,
162 int half_pulse_count, int bits)
163{
164 int i;
165 int mask = (1 << bits) - 1;
166
167 fixed_sparse->no_repeat_mask = 0;
168 fixed_sparse->n = 2 * half_pulse_count;
169 for (i = 0; i < half_pulse_count; i++) {
170 const int pos1 = gray_decode[fixed_index[2*i+1] & mask] + i;
171 const int pos2 = gray_decode[fixed_index[2*i ] & mask] + i;
172 const float sign = (fixed_index[2*i+1] & (1 << bits)) ? -1.0 : 1.0;
173 fixed_sparse->x[2*i+1] = pos1;
174 fixed_sparse->x[2*i ] = pos2;
175 fixed_sparse->y[2*i+1] = sign;
176 fixed_sparse->y[2*i ] = pos2 < pos1 ? -sign : sign;
177 }
178}
179
180void ff_acelp_weighted_vector_sum(
181 int16_t* out,
182 const int16_t *in_a,
183 const int16_t *in_b,
184 int16_t weight_coeff_a,
185 int16_t weight_coeff_b,
186 int16_t rounder,
187 int shift,
188 int length)
189{
190 int i;
191
192 // Clipping required here; breaks OVERFLOW test.
193 for(i=0; i<length; i++)
194 out[i] = av_clip_int16((
195 in_a[i] * weight_coeff_a +
196 in_b[i] * weight_coeff_b +
197 rounder) >> shift);
198}
199
200void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
201 float weight_coeff_a, float weight_coeff_b, int length)
202{
203 int i;
204
205 for(i=0; i<length; i++)
206 out[i] = weight_coeff_a * in_a[i]
207 + weight_coeff_b * in_b[i];
208}
209
210void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
211 int size, float alpha, float *gain_mem)
212{
213 int i;
214 float postfilter_energ = ff_dot_productf(in, in, size);
215 float gain_scale_factor = 1.0;
216 float mem = *gain_mem;
217
218 if (postfilter_energ)
219 gain_scale_factor = sqrt(speech_energ / postfilter_energ);
220
221 gain_scale_factor *= 1.0 - alpha;
222
223 for (i = 0; i < size; i++) {
224 mem = alpha * mem + gain_scale_factor;
225 out[i] = in[i] * mem;
226 }
227
228 *gain_mem = mem;
229}
230
231void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
232 float sum_of_squares, const int n)
233{
234 int i;
235 float scalefactor = ff_dot_productf(in, in, n);
236 if (scalefactor)
237 scalefactor = sqrt(sum_of_squares / scalefactor);
238 for (i = 0; i < n; i++)
239 out[i] = in[i] * scalefactor;
240}
241
242void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size)
243{
244 int i;
245
246 for (i=0; i < in->n; i++) {
247 int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
248 float y = in->y[i] * scale;
249
250 do {
251 out[x] += y;
252 y *= in->pitch_fac;
253 x += in->pitch_lag;
254 } while (x < size && repeats);
255 }
256}
257
258void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size)
259{
260 int i;
261
262 for (i=0; i < in->n; i++) {
263 int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1);
264
265 do {
266 out[x] = 0.0;
267 x += in->pitch_lag;
268 } while (x < size && repeats);
269 }
270}
diff --git a/apps/codecs/libwmavoice/acelp_vectors.h b/apps/codecs/libwmavoice/acelp_vectors.h
new file mode 100644
index 0000000000..f3bc781446
--- /dev/null
+++ b/apps/codecs/libwmavoice/acelp_vectors.h
@@ -0,0 +1,264 @@
1/*
2 * adaptive and fixed codebook vector operations for ACELP-based codecs
3 *
4 * Copyright (c) 2008 Vladimir Voroshilov
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#ifndef AVCODEC_ACELP_VECTORS_H
24#define AVCODEC_ACELP_VECTORS_H
25
26#include <stdint.h>
27
28/** Sparse representation for the algebraic codebook (fixed) vector */
29typedef struct {
30 int n;
31 int x[10];
32 float y[10];
33 int no_repeat_mask;
34 int pitch_lag;
35 float pitch_fac;
36} AMRFixed;
37
38/**
39 * Track|Pulse| Positions
40 * -------------------------------------------------------------------------
41 * 1 | 0 | 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75
42 * -------------------------------------------------------------------------
43 * 2 | 1 | 1, 6, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61, 66, 71, 76
44 * -------------------------------------------------------------------------
45 * 3 | 2 | 2, 7, 12, 17, 22, 27, 32, 37, 42, 47, 52, 57, 62, 67, 72, 77
46 * -------------------------------------------------------------------------
47 *
48 * Table contains only first the pulse indexes.
49 *
50 * Used in G.729 @@8k, G.729 @@4.4k, AMR @@7.95k, AMR @@7.40k
51 */
52extern const uint8_t ff_fc_4pulses_8bits_tracks_13[16];
53
54/**
55 * Track|Pulse| Positions
56 * -------------------------------------------------------------------------
57 * 4 | 3 | 3, 8, 13, 18, 23, 28, 33, 38, 43, 48, 53, 58, 63, 68, 73, 78
58 * | | 4, 9, 14, 19, 24, 29, 34, 39, 44, 49, 54, 59, 64, 69, 74, 79
59 * -------------------------------------------------------------------------
60 *
61 * @remark Track in the table should be read top-to-bottom, left-to-right.
62 *
63 * Used in G.729 @@8k, G.729 @@4.4k, AMR @@7.95k, AMR @@7.40k
64 */
65extern const uint8_t ff_fc_4pulses_8bits_track_4[32];
66
67/**
68 * Track|Pulse| Positions
69 * -----------------------------------------
70 * 1 | 0 | 1, 6, 11, 16, 21, 26, 31, 36
71 * | | 3, 8, 13, 18, 23, 28, 33, 38
72 * -----------------------------------------
73 *
74 * @remark Track in the table should be read top-to-bottom, left-to-right.
75 *
76 * @note (EE) Reference G.729D code also uses gray decoding for each
77 * pulse index before looking up the value in the table.
78 *
79 * Used in G.729 @@6.4k (with gray coding), AMR @@5.9k (without gray coding)
80 */
81extern const uint8_t ff_fc_2pulses_9bits_track1[16];
82extern const uint8_t ff_fc_2pulses_9bits_track1_gray[16];
83
84/**
85 * Track|Pulse| Positions
86 * -----------------------------------------
87 * 2 | 1 | 0, 7, 14, 20, 27, 34, 1, 21
88 * | | 2, 9, 15, 22, 29, 35, 6, 26
89 * | | 4,10, 17, 24, 30, 37, 11, 31
90 * | | 5,12, 19, 25, 32, 39, 16, 36
91 * -----------------------------------------
92 *
93 * @remark Track in the table should be read top-to-bottom, left-to-right.
94 *
95 * @note (EE.1) This table (from the reference code) does not comply with
96 * the specification.
97 * The specification contains the following table:
98 *
99 * Track|Pulse| Positions
100 * -----------------------------------------
101 * 2 | 1 | 0, 5, 10, 15, 20, 25, 30, 35
102 * | | 1, 6, 11, 16, 21, 26, 31, 36
103 * | | 2, 7, 12, 17, 22, 27, 32, 37
104 * | | 4, 9, 14, 19, 24, 29, 34, 39
105 *
106 * -----------------------------------------
107 *
108 * @note (EE.2) Reference G.729D code also uses gray decoding for each
109 * pulse index before looking up the value in the table.
110 *
111 * Used in G.729 @@6.4k (with gray coding)
112 */
113extern const uint8_t ff_fc_2pulses_9bits_track2_gray[32];
114
115/**
116 * b60 hamming windowed sinc function coefficients
117 */
118extern const float ff_b60_sinc[61];
119
120/**
121 * Table of pow(0.7,n)
122 */
123extern const float ff_pow_0_7[10];
124
125/**
126 * Table of pow(0.75,n)
127 */
128extern const float ff_pow_0_75[10];
129
130/**
131 * Table of pow(0.55,n)
132 */
133extern const float ff_pow_0_55[10];
134
135/**
136 * Decode fixed-codebook vector (3.8 and D.5.8 of G.729, 5.7.1 of AMR).
137 * @param[out] fc_v decoded fixed codebook vector (2.13)
138 * @param tab1 table used for first pulse_count pulses
139 * @param tab2 table used for last pulse
140 * @param pulse_indexes fixed codebook indexes
141 * @param pulse_signs signs of the excitation pulses (0 bit value
142 * means negative sign)
143 * @param bits number of bits per one pulse index
144 * @param pulse_count number of pulses decoded using first table
145 * @param bits length of one pulse index in bits
146 *
147 * Used in G.729 @@8k, G.729 @@4.4k, G.729 @@6.4k, AMR @@7.95k, AMR @@7.40k
148 */
149void ff_acelp_fc_pulse_per_track(int16_t* fc_v,
150 const uint8_t *tab1,
151 const uint8_t *tab2,
152 int pulse_indexes,
153 int pulse_signs,
154 int pulse_count,
155 int bits);
156
157/**
158 * Decode the algebraic codebook index to pulse positions and signs and
159 * construct the algebraic codebook vector for MODE_12k2.
160 *
161 * @note: The positions and signs are explicitly coded in MODE_12k2.
162 *
163 * @param fixed_index positions of the ten pulses
164 * @param fixed_sparse pointer to the algebraic codebook vector
165 * @param gray_decode gray decoding table
166 * @param half_pulse_count number of couples of pulses
167 * @param bits length of one pulse index in bits
168 */
169void ff_decode_10_pulses_35bits(const int16_t *fixed_index,
170 AMRFixed *fixed_sparse,
171 const uint8_t *gray_decode,
172 int half_pulse_count, int bits);
173
174
175/**
176 * weighted sum of two vectors with rounding.
177 * @param[out] out result of addition
178 * @param in_a first vector
179 * @param in_b second vector
180 * @param weight_coeff_a first vector weight coefficient
181 * @param weight_coeff_a second vector weight coefficient
182 * @param rounder this value will be added to the sum of the two vectors
183 * @param shift result will be shifted to right by this value
184 * @param length vectors length
185 *
186 * @note It is safe to pass the same buffer for out and in_a or in_b.
187 *
188 * out[i] = (in_a[i]*weight_a + in_b[i]*weight_b + rounder) >> shift
189 */
190void ff_acelp_weighted_vector_sum(int16_t* out,
191 const int16_t *in_a,
192 const int16_t *in_b,
193 int16_t weight_coeff_a,
194 int16_t weight_coeff_b,
195 int16_t rounder,
196 int shift,
197 int length);
198
199/**
200 * float implementation of weighted sum of two vectors.
201 * @param[out] out result of addition
202 * @param in_a first vector
203 * @param in_b second vector
204 * @param weight_coeff_a first vector weight coefficient
205 * @param weight_coeff_a second vector weight coefficient
206 * @param length vectors length
207 *
208 * @note It is safe to pass the same buffer for out and in_a or in_b.
209 */
210void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
211 float weight_coeff_a, float weight_coeff_b,
212 int length);
213
214/**
215 * Adaptive gain control (as used in AMR postfiltering)
216 *
217 * @param out output buffer for filtered speech data
218 * @param in the input speech buffer (may be the same as out)
219 * @param speech_energ input energy
220 * @param size the input buffer size
221 * @param alpha exponential filter factor
222 * @param gain_mem a pointer to the filter memory (single float of size)
223 */
224void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
225 int size, float alpha, float *gain_mem);
226
227/**
228 * Set the sum of squares of a signal by scaling
229 *
230 * @param out output samples
231 * @param in input samples
232 * @param sum_of_squares new sum of squares
233 * @param n number of samples
234 *
235 * @note If the input is zero (or its energy underflows), the output is zero.
236 * This is the behavior of AGC in the AMR reference decoder. The QCELP
237 * reference decoder seems to have undefined behavior.
238 *
239 * TIA/EIA/IS-733 2.4.8.3-2/3/4/5, 2.4.8.6
240 * 3GPP TS 26.090 6.1 (6)
241 */
242void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
243 float sum_of_squares, const int n);
244
245/**
246 * Add fixed vector to an array from a sparse representation
247 *
248 * @param out fixed vector with pitch sharpening
249 * @param in sparse fixed vector
250 * @param scale number to multiply the fixed vector by
251 * @param size the output vector size
252 */
253void ff_set_fixed_vector(float *out, const AMRFixed *in, float scale, int size);
254
255/**
256 * Clear array values set by set_fixed_vector
257 *
258 * @param out fixed vector to be cleared
259 * @param in sparse fixed vector
260 * @param size the output vector size
261 */
262void ff_clear_fixed_vector(float *out, const AMRFixed *in, int size);
263
264#endif /* AVCODEC_ACELP_VECTORS_H */
diff --git a/apps/codecs/libwmavoice/avcodec.h b/apps/codecs/libwmavoice/avcodec.h
index 9186bf52f3..db08ab3c5f 100644
--- a/apps/codecs/libwmavoice/avcodec.h
+++ b/apps/codecs/libwmavoice/avcodec.h
@@ -1114,7 +1114,7 @@ typedef struct AVCodecContext {
1114 * - encoding: MUST be set by user. 1114 * - encoding: MUST be set by user.
1115 * - decoding: Set by libavcodec. 1115 * - decoding: Set by libavcodec.
1116 */ 1116 */
1117 AVRational time_base; 1117 //AVRational time_base;
1118 1118
1119 /* video only */ 1119 /* video only */
1120 /** 1120 /**
@@ -1142,7 +1142,7 @@ typedef struct AVCodecContext {
1142 * - encoding: Set by user. 1142 * - encoding: Set by user.
1143 * - decoding: Set by user if known, overridden by libavcodec if known 1143 * - decoding: Set by user if known, overridden by libavcodec if known
1144 */ 1144 */
1145 enum PixelFormat pix_fmt; 1145 //enum PixelFormat pix_fmt;
1146 1146
1147 /** 1147 /**
1148 * Frame rate emulation. If not zero, the lower layer (i.e. format handler) 1148 * Frame rate emulation. If not zero, the lower layer (i.e. format handler)
@@ -1693,7 +1693,7 @@ typedef struct AVCodecContext {
1693 * - encoding: Set by user. 1693 * - encoding: Set by user.
1694 * - decoding: Set by libavcodec. 1694 * - decoding: Set by libavcodec.
1695 */ 1695 */
1696 AVRational sample_aspect_ratio; 1696 //AVRational sample_aspect_ratio;
1697 1697
1698 /** 1698 /**
1699 * the picture in the bitstream 1699 * the picture in the bitstream
@@ -2738,8 +2738,8 @@ typedef struct AVCodec {
2738 * Will be called when seeking 2738 * Will be called when seeking
2739 */ 2739 */
2740 void (*flush)(AVCodecContext *); 2740 void (*flush)(AVCodecContext *);
2741 const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0} 2741 //const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
2742 const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1 2742 //const enum PixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
2743 /** 2743 /**
2744 * Descriptive name for the codec, meant to be more human readable than name. 2744 * Descriptive name for the codec, meant to be more human readable than name.
2745 * You should use the NULL_IF_CONFIG_SMALL() macro to define it. 2745 * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
@@ -2781,7 +2781,7 @@ typedef struct AVHWAccel {
2781 * 2781 *
2782 * Only hardware accelerated formats are supported here. 2782 * Only hardware accelerated formats are supported here.
2783 */ 2783 */
2784 enum PixelFormat pix_fmt; 2784 //enum PixelFormat pix_fmt;
2785 2785
2786 /** 2786 /**
2787 * Hardware accelerated codec capabilities. 2787 * Hardware accelerated codec capabilities.
@@ -3976,7 +3976,7 @@ attribute_deprecated int av_parse_video_frame_size(int *width_ptr, int *height_p
3976 * 3976 *
3977 * @deprecated Deprecated in favor of av_parse_video_rate(). 3977 * @deprecated Deprecated in favor of av_parse_video_rate().
3978 */ 3978 */
3979attribute_deprecated int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); 3979//attribute_deprecated int av_parse_video_frame_rate(AVRational *frame_rate, const char *str);
3980#endif 3980#endif
3981 3981
3982/** 3982/**
diff --git a/apps/codecs/libwmavoice/bitstream.c b/apps/codecs/libwmavoice/bitstream.c
index 83f30f9799..d408f66650 100644
--- a/apps/codecs/libwmavoice/bitstream.c
+++ b/apps/codecs/libwmavoice/bitstream.c
@@ -66,7 +66,7 @@ void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
66 66
67 if(length==0) return; 67 if(length==0) return;
68 68
69 if(CONFIG_SMALL || words < 16 || put_bits_count(pb)&7){ 69 if(/*CONFIG_SMALL ||*/ words < 16 || put_bits_count(pb)&7){
70 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i)); 70 for(i=0; i<words; i++) put_bits(pb, 16, AV_RB16(src + 2*i));
71 }else{ 71 }else{
72 for(i=0; put_bits_count(pb)&31; i++) 72 for(i=0; put_bits_count(pb)&31; i++)
diff --git a/apps/codecs/libwmavoice/dct.c b/apps/codecs/libwmavoice/dct.c
new file mode 100644
index 0000000000..95aef5af6c
--- /dev/null
+++ b/apps/codecs/libwmavoice/dct.c
@@ -0,0 +1,226 @@
1/*
2 * (I)DCT Transforms
3 * Copyright (c) 2009 Peter Ross <pross@xvid.org>
4 * Copyright (c) 2010 Alex Converse <alex.converse@gmail.com>
5 * Copyright (c) 2010 Vitor Sessak
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 St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24/**
25 * @file
26 * (Inverse) Discrete Cosine Transforms. These are also known as the
27 * type II and type III DCTs respectively.
28 */
29
30#include <math.h>
31#include "libavutil/mathematics.h"
32#include "fft.h"
33//#include "x86/fft.h"
34
35#define DCT32_FLOAT
36#include "dct32.c"
37
38/* sin((M_PI * x / (2*n)) */
39#define SIN(s,n,x) (s->costab[(n) - (x)])
40
41/* cos((M_PI * x / (2*n)) */
42#define COS(s,n,x) (s->costab[x])
43
44static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data)
45{
46 int n = 1 << ctx->nbits;
47 int i;
48
49 data[0] = 0;
50 for(i = 1; i < n/2; i++) {
51 float tmp1 = data[i ];
52 float tmp2 = data[n - i];
53 float s = SIN(ctx, n, 2*i);
54
55 s *= tmp1 + tmp2;
56 tmp1 = (tmp1 - tmp2) * 0.5f;
57 data[i ] = s + tmp1;
58 data[n - i] = s - tmp1;
59 }
60
61 data[n/2] *= 2;
62 ff_rdft_calc(&ctx->rdft, data);
63
64 data[0] *= 0.5f;
65
66 for(i = 1; i < n-2; i += 2) {
67 data[i + 1] += data[i - 1];
68 data[i ] = -data[i + 2];
69 }
70
71 data[n-1] = 0;
72}
73
74static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data)
75{
76 int n = 1 << ctx->nbits;
77 int i;
78 float next = -0.5f * (data[0] - data[n]);
79
80 for(i = 0; i < n/2; i++) {
81 float tmp1 = data[i ];
82 float tmp2 = data[n - i];
83 float s = SIN(ctx, n, 2*i);
84 float c = COS(ctx, n, 2*i);
85
86 c *= tmp1 - tmp2;
87 s *= tmp1 - tmp2;
88
89 next += c;
90
91 tmp1 = (tmp1 + tmp2) * 0.5f;
92 data[i ] = tmp1 - s;
93 data[n - i] = tmp1 + s;
94 }
95
96 ff_rdft_calc(&ctx->rdft, data);
97 data[n] = data[1];
98 data[1] = next;
99
100 for(i = 3; i <= n; i += 2)
101 data[i] = data[i - 2] - data[i];
102}
103
104static void ff_dct_calc_III_c(DCTContext *ctx, FFTSample *data)
105{
106 int n = 1 << ctx->nbits;
107 int i;
108
109 float next = data[n - 1];
110 float inv_n = 1.0f / n;
111
112 for (i = n - 2; i >= 2; i -= 2) {
113 float val1 = data[i ];
114 float val2 = data[i - 1] - data[i + 1];
115 float c = COS(ctx, n, i);
116 float s = SIN(ctx, n, i);
117
118 data[i ] = c * val1 + s * val2;
119 data[i + 1] = s * val1 - c * val2;
120 }
121
122 data[1] = 2 * next;
123
124 ff_rdft_calc(&ctx->rdft, data);
125
126 for (i = 0; i < n / 2; i++) {
127 float tmp1 = data[i ] * inv_n;
128 float tmp2 = data[n - i - 1] * inv_n;
129 float csc = ctx->csc2[i] * (tmp1 - tmp2);
130
131 tmp1 += tmp2;
132 data[i ] = tmp1 + csc;
133 data[n - i - 1] = tmp1 - csc;
134 }
135}
136
137static void ff_dct_calc_II_c(DCTContext *ctx, FFTSample *data)
138{
139 int n = 1 << ctx->nbits;
140 int i;
141 float next;
142
143 for (i=0; i < n/2; i++) {
144 float tmp1 = data[i ];
145 float tmp2 = data[n - i - 1];
146 float s = SIN(ctx, n, 2*i + 1);
147
148 s *= tmp1 - tmp2;
149 tmp1 = (tmp1 + tmp2) * 0.5f;
150
151 data[i ] = tmp1 + s;
152 data[n-i-1] = tmp1 - s;
153 }
154
155 ff_rdft_calc(&ctx->rdft, data);
156
157 next = data[1] * 0.5;
158 data[1] *= -1;
159
160 for (i = n - 2; i >= 0; i -= 2) {
161 float inr = data[i ];
162 float ini = data[i + 1];
163 float c = COS(ctx, n, i);
164 float s = SIN(ctx, n, i);
165
166 data[i ] = c * inr + s * ini;
167
168 data[i+1] = next;
169
170 next += s * inr - c * ini;
171 }
172}
173
174static void dct32_func(DCTContext *ctx, FFTSample *data)
175{
176 ctx->dct32(data, data);
177}
178
179void ff_dct_calc(DCTContext *s, FFTSample *data)
180{
181 s->dct_calc(s, data);
182}
183
184av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
185{
186 int n = 1 << nbits;
187 int i;
188
189 s->nbits = nbits;
190 s->inverse = inverse;
191
192 ff_init_ff_cos_tabs(nbits+2);
193
194 s->costab = ff_cos_tabs[nbits+2];
195
196 s->csc2 = av_malloc(n/2 * sizeof(FFTSample));
197
198 if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) {
199 av_free(s->csc2);
200 return -1;
201 }
202
203 for (i = 0; i < n/2; i++)
204 s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1)));
205
206 switch(inverse) {
207 case DCT_I : s->dct_calc = ff_dct_calc_I_c; break;
208 case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break;
209 case DCT_III: s->dct_calc = ff_dct_calc_III_c; break;
210 case DST_I : s->dct_calc = ff_dst_calc_I_c; break;
211 }
212
213 if (inverse == DCT_II && nbits == 5)
214 s->dct_calc = dct32_func;
215
216 s->dct32 = dct32;
217 //if (HAVE_MMX) ff_dct_init_mmx(s);
218
219 return 0;
220}
221
222av_cold void ff_dct_end(DCTContext *s)
223{
224 ff_rdft_end(&s->rdft);
225 av_free(s->csc2);
226}
diff --git a/apps/codecs/libwmavoice/dct32.c b/apps/codecs/libwmavoice/dct32.c
new file mode 100644
index 0000000000..4e843ee832
--- /dev/null
+++ b/apps/codecs/libwmavoice/dct32.c
@@ -0,0 +1,267 @@
1/*
2 * Template for the Discrete Cosine Transform for 32 samples
3 * Copyright (c) 2001, 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#ifdef DCT32_FLOAT
23# define FIXHR(x) ((float)(x))
24# define MULH3(x, y, s) ((s)*(y)*(x))
25# define INTFLOAT float
26#endif
27
28
29/* tab[i][j] = 1.0 / (2.0 * cos(pi*(2*k+1) / 2^(6 - j))) */
30
31/* cos(i*pi/64) */
32
33#define COS0_0 FIXHR(0.50060299823519630134/2)
34#define COS0_1 FIXHR(0.50547095989754365998/2)
35#define COS0_2 FIXHR(0.51544730992262454697/2)
36#define COS0_3 FIXHR(0.53104259108978417447/2)
37#define COS0_4 FIXHR(0.55310389603444452782/2)
38#define COS0_5 FIXHR(0.58293496820613387367/2)
39#define COS0_6 FIXHR(0.62250412303566481615/2)
40#define COS0_7 FIXHR(0.67480834145500574602/2)
41#define COS0_8 FIXHR(0.74453627100229844977/2)
42#define COS0_9 FIXHR(0.83934964541552703873/2)
43#define COS0_10 FIXHR(0.97256823786196069369/2)
44#define COS0_11 FIXHR(1.16943993343288495515/4)
45#define COS0_12 FIXHR(1.48416461631416627724/4)
46#define COS0_13 FIXHR(2.05778100995341155085/8)
47#define COS0_14 FIXHR(3.40760841846871878570/8)
48#define COS0_15 FIXHR(10.19000812354805681150/32)
49
50#define COS1_0 FIXHR(0.50241928618815570551/2)
51#define COS1_1 FIXHR(0.52249861493968888062/2)
52#define COS1_2 FIXHR(0.56694403481635770368/2)
53#define COS1_3 FIXHR(0.64682178335999012954/2)
54#define COS1_4 FIXHR(0.78815462345125022473/2)
55#define COS1_5 FIXHR(1.06067768599034747134/4)
56#define COS1_6 FIXHR(1.72244709823833392782/4)
57#define COS1_7 FIXHR(5.10114861868916385802/16)
58
59#define COS2_0 FIXHR(0.50979557910415916894/2)
60#define COS2_1 FIXHR(0.60134488693504528054/2)
61#define COS2_2 FIXHR(0.89997622313641570463/2)
62#define COS2_3 FIXHR(2.56291544774150617881/8)
63
64#define COS3_0 FIXHR(0.54119610014619698439/2)
65#define COS3_1 FIXHR(1.30656296487637652785/4)
66
67#define COS4_0 FIXHR(0.70710678118654752439/2)
68
69/* butterfly operator */
70#define BF(a, b, c, s)\
71{\
72 tmp0 = val##a + val##b;\
73 tmp1 = val##a - val##b;\
74 val##a = tmp0;\
75 val##b = MULH3(tmp1, c, 1<<(s));\
76}
77
78#define BF0(a, b, c, s)\
79{\
80 tmp0 = tab[a] + tab[b];\
81 tmp1 = tab[a] - tab[b];\
82 val##a = tmp0;\
83 val##b = MULH3(tmp1, c, 1<<(s));\
84}
85
86#define BF1(a, b, c, d)\
87{\
88 BF(a, b, COS4_0, 1);\
89 BF(c, d,-COS4_0, 1);\
90 val##c += val##d;\
91}
92
93#define BF2(a, b, c, d)\
94{\
95 BF(a, b, COS4_0, 1);\
96 BF(c, d,-COS4_0, 1);\
97 val##c += val##d;\
98 val##a += val##c;\
99 val##c += val##b;\
100 val##b += val##d;\
101}
102
103#define ADD(a, b) val##a += val##b
104
105/* DCT32 without 1/sqrt(2) coef zero scaling. */
106static void dct32(INTFLOAT *out, const INTFLOAT *tab)
107{
108 INTFLOAT tmp0, tmp1;
109
110 INTFLOAT val0 , val1 , val2 , val3 , val4 , val5 , val6 , val7 ,
111 val8 , val9 , val10, val11, val12, val13, val14, val15,
112 val16, val17, val18, val19, val20, val21, val22, val23,
113 val24, val25, val26, val27, val28, val29, val30, val31;
114
115 /* pass 1 */
116 BF0( 0, 31, COS0_0 , 1);
117 BF0(15, 16, COS0_15, 5);
118 /* pass 2 */
119 BF( 0, 15, COS1_0 , 1);
120 BF(16, 31,-COS1_0 , 1);
121 /* pass 1 */
122 BF0( 7, 24, COS0_7 , 1);
123 BF0( 8, 23, COS0_8 , 1);
124 /* pass 2 */
125 BF( 7, 8, COS1_7 , 4);
126 BF(23, 24,-COS1_7 , 4);
127 /* pass 3 */
128 BF( 0, 7, COS2_0 , 1);
129 BF( 8, 15,-COS2_0 , 1);
130 BF(16, 23, COS2_0 , 1);
131 BF(24, 31,-COS2_0 , 1);
132 /* pass 1 */
133 BF0( 3, 28, COS0_3 , 1);
134 BF0(12, 19, COS0_12, 2);
135 /* pass 2 */
136 BF( 3, 12, COS1_3 , 1);
137 BF(19, 28,-COS1_3 , 1);
138 /* pass 1 */
139 BF0( 4, 27, COS0_4 , 1);
140 BF0(11, 20, COS0_11, 2);
141 /* pass 2 */
142 BF( 4, 11, COS1_4 , 1);
143 BF(20, 27,-COS1_4 , 1);
144 /* pass 3 */
145 BF( 3, 4, COS2_3 , 3);
146 BF(11, 12,-COS2_3 , 3);
147 BF(19, 20, COS2_3 , 3);
148 BF(27, 28,-COS2_3 , 3);
149 /* pass 4 */
150 BF( 0, 3, COS3_0 , 1);
151 BF( 4, 7,-COS3_0 , 1);
152 BF( 8, 11, COS3_0 , 1);
153 BF(12, 15,-COS3_0 , 1);
154 BF(16, 19, COS3_0 , 1);
155 BF(20, 23,-COS3_0 , 1);
156 BF(24, 27, COS3_0 , 1);
157 BF(28, 31,-COS3_0 , 1);
158
159
160
161 /* pass 1 */
162 BF0( 1, 30, COS0_1 , 1);
163 BF0(14, 17, COS0_14, 3);
164 /* pass 2 */
165 BF( 1, 14, COS1_1 , 1);
166 BF(17, 30,-COS1_1 , 1);
167 /* pass 1 */
168 BF0( 6, 25, COS0_6 , 1);
169 BF0( 9, 22, COS0_9 , 1);
170 /* pass 2 */
171 BF( 6, 9, COS1_6 , 2);
172 BF(22, 25,-COS1_6 , 2);
173 /* pass 3 */
174 BF( 1, 6, COS2_1 , 1);
175 BF( 9, 14,-COS2_1 , 1);
176 BF(17, 22, COS2_1 , 1);
177 BF(25, 30,-COS2_1 , 1);
178
179 /* pass 1 */
180 BF0( 2, 29, COS0_2 , 1);
181 BF0(13, 18, COS0_13, 3);
182 /* pass 2 */
183 BF( 2, 13, COS1_2 , 1);
184 BF(18, 29,-COS1_2 , 1);
185 /* pass 1 */
186 BF0( 5, 26, COS0_5 , 1);
187 BF0(10, 21, COS0_10, 1);
188 /* pass 2 */
189 BF( 5, 10, COS1_5 , 2);
190 BF(21, 26,-COS1_5 , 2);
191 /* pass 3 */
192 BF( 2, 5, COS2_2 , 1);
193 BF(10, 13,-COS2_2 , 1);
194 BF(18, 21, COS2_2 , 1);
195 BF(26, 29,-COS2_2 , 1);
196 /* pass 4 */
197 BF( 1, 2, COS3_1 , 2);
198 BF( 5, 6,-COS3_1 , 2);
199 BF( 9, 10, COS3_1 , 2);
200 BF(13, 14,-COS3_1 , 2);
201 BF(17, 18, COS3_1 , 2);
202 BF(21, 22,-COS3_1 , 2);
203 BF(25, 26, COS3_1 , 2);
204 BF(29, 30,-COS3_1 , 2);
205
206 /* pass 5 */
207 BF1( 0, 1, 2, 3);
208 BF2( 4, 5, 6, 7);
209 BF1( 8, 9, 10, 11);
210 BF2(12, 13, 14, 15);
211 BF1(16, 17, 18, 19);
212 BF2(20, 21, 22, 23);
213 BF1(24, 25, 26, 27);
214 BF2(28, 29, 30, 31);
215
216 /* pass 6 */
217
218 ADD( 8, 12);
219 ADD(12, 10);
220 ADD(10, 14);
221 ADD(14, 9);
222 ADD( 9, 13);
223 ADD(13, 11);
224 ADD(11, 15);
225
226 out[ 0] = val0;
227 out[16] = val1;
228 out[ 8] = val2;
229 out[24] = val3;
230 out[ 4] = val4;
231 out[20] = val5;
232 out[12] = val6;
233 out[28] = val7;
234 out[ 2] = val8;
235 out[18] = val9;
236 out[10] = val10;
237 out[26] = val11;
238 out[ 6] = val12;
239 out[22] = val13;
240 out[14] = val14;
241 out[30] = val15;
242
243 ADD(24, 28);
244 ADD(28, 26);
245 ADD(26, 30);
246 ADD(30, 25);
247 ADD(25, 29);
248 ADD(29, 27);
249 ADD(27, 31);
250
251 out[ 1] = val16 + val24;
252 out[17] = val17 + val25;
253 out[ 9] = val18 + val26;
254 out[25] = val19 + val27;
255 out[ 5] = val20 + val28;
256 out[21] = val21 + val29;
257 out[13] = val22 + val30;
258 out[29] = val23 + val31;
259 out[ 3] = val24 + val20;
260 out[19] = val25 + val21;
261 out[11] = val26 + val22;
262 out[27] = val27 + val23;
263 out[ 7] = val28 + val18;
264 out[23] = val29 + val19;
265 out[15] = val30 + val17;
266 out[31] = val31;
267}
diff --git a/apps/codecs/libwmavoice/fft.c b/apps/codecs/libwmavoice/fft.c
index 81765510e3..a030534a26 100644
--- a/apps/codecs/libwmavoice/fft.c
+++ b/apps/codecs/libwmavoice/fft.c
@@ -103,9 +103,11 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse)
103 s->mdct_calc = ff_mdct_calc_c; 103 s->mdct_calc = ff_mdct_calc_c;
104#endif 104#endif
105 105
106#if 0
106 if (ARCH_ARM) ff_fft_init_arm(s); 107 if (ARCH_ARM) ff_fft_init_arm(s);
107 if (HAVE_ALTIVEC) ff_fft_init_altivec(s); 108 if (HAVE_ALTIVEC) ff_fft_init_altivec(s);
108 if (HAVE_MMX) ff_fft_init_mmx(s); 109 if (HAVE_MMX) ff_fft_init_mmx(s);
110#endif
109 111
110 for(j=4; j<=nbits; j++) { 112 for(j=4; j<=nbits; j++) {
111 ff_init_ff_cos_tabs(j); 113 ff_init_ff_cos_tabs(j);
diff --git a/apps/codecs/libwmavoice/fft.h b/apps/codecs/libwmavoice/fft.h
index eb6714fe95..2c54b56658 100644
--- a/apps/codecs/libwmavoice/fft.h
+++ b/apps/codecs/libwmavoice/fft.h
@@ -23,7 +23,7 @@
23#define AVCODEC_FFT_H 23#define AVCODEC_FFT_H
24 24
25#include <stdint.h> 25#include <stdint.h>
26#include "config.h" 26//#include "config.h"
27#include "libavutil/mem.h" 27#include "libavutil/mem.h"
28#include "avfft.h" 28#include "avfft.h"
29 29
diff --git a/apps/codecs/libwmavoice/libavutil/avutil.h b/apps/codecs/libwmavoice/libavutil/avutil.h
index 50b29fc4a7..457829ac7f 100644
--- a/apps/codecs/libwmavoice/libavutil/avutil.h
+++ b/apps/codecs/libwmavoice/libavutil/avutil.h
@@ -79,11 +79,11 @@ enum AVMediaType {
79}; 79};
80 80
81#include "common.h" 81#include "common.h"
82#include "error.h" 82//#include "error.h"
83#include "mathematics.h" 83#include "mathematics.h"
84#include "rational.h" 84//#include "rational.h"
85#include "intfloat_readwrite.h" 85//#include "intfloat_readwrite.h"
86#include "log.h" 86#include "log.h"
87#include "pixfmt.h" 87//#include "pixfmt.h"
88 88
89#endif /* AVUTIL_AVUTIL_H */ 89#endif /* AVUTIL_AVUTIL_H */
diff --git a/apps/codecs/libwmavoice/libavutil/mathematics.c b/apps/codecs/libwmavoice/libavutil/mathematics.c
index c6851cb755..c4fbe3b7bc 100644
--- a/apps/codecs/libwmavoice/libavutil/mathematics.c
+++ b/apps/codecs/libwmavoice/libavutil/mathematics.c
@@ -130,6 +130,7 @@ int64_t av_rescale(int64_t a, int64_t b, int64_t c){
130 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); 130 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF);
131} 131}
132 132
133#if 0
133int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ 134int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){
134 int64_t b= bq.num * (int64_t)cq.den; 135 int64_t b= bq.num * (int64_t)cq.den;
135 int64_t c= cq.num * (int64_t)bq.den; 136 int64_t c= cq.num * (int64_t)bq.den;
@@ -143,6 +144,7 @@ int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){
143 if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1; 144 if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1;
144 return 0; 145 return 0;
145} 146}
147#endif
146 148
147int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){ 149int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod){
148 int64_t c= (a-b) & (mod-1); 150 int64_t c= (a-b) & (mod-1);
diff --git a/apps/codecs/libwmavoice/libavutil/mathematics.h b/apps/codecs/libwmavoice/libavutil/mathematics.h
index 882a516393..e07d4fe807 100644
--- a/apps/codecs/libwmavoice/libavutil/mathematics.h
+++ b/apps/codecs/libwmavoice/libavutil/mathematics.h
@@ -24,7 +24,7 @@
24#include <stdint.h> 24#include <stdint.h>
25#include <math.h> 25#include <math.h>
26#include "attributes.h" 26#include "attributes.h"
27#include "rational.h" 27//#include "rational.h"
28 28
29#ifndef M_E 29#ifndef M_E
30#define M_E 2.7182818284590452354 /* e */ 30#define M_E 2.7182818284590452354 /* e */
@@ -87,7 +87,7 @@ int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding) av_cons
87/** 87/**
88 * Rescale a 64-bit integer by 2 rational numbers. 88 * Rescale a 64-bit integer by 2 rational numbers.
89 */ 89 */
90int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const; 90//int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
91 91
92/** 92/**
93 * Compare 2 timestamps each in its own timebases. 93 * Compare 2 timestamps each in its own timebases.
@@ -95,7 +95,7 @@ int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) av_const;
95 * is outside the int64_t range when represented in the others timebase. 95 * is outside the int64_t range when represented in the others timebase.
96 * @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position 96 * @return -1 if ts_a is before ts_b, 1 if ts_a is after ts_b or 0 if they represent the same position
97 */ 97 */
98int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b); 98//int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b);
99 99
100/** 100/**
101 * Compare 2 integers modulo mod. 101 * Compare 2 integers modulo mod.
diff --git a/apps/codecs/libwmavoice/libavutil/mem.c b/apps/codecs/libwmavoice/libavutil/mem.c
index 8cad089a7d..a9a3283775 100644
--- a/apps/codecs/libwmavoice/libavutil/mem.c
+++ b/apps/codecs/libwmavoice/libavutil/mem.c
@@ -24,7 +24,7 @@
24 * default memory allocator for libavutil 24 * default memory allocator for libavutil
25 */ 25 */
26 26
27#include "config.h" 27//#include "config.h"
28 28
29#include <limits.h> 29#include <limits.h>
30#include <stdlib.h> 30#include <stdlib.h>
diff --git a/apps/codecs/libwmavoice/lsp.c b/apps/codecs/libwmavoice/lsp.c
index 7112492001..4dba9c1df9 100644
--- a/apps/codecs/libwmavoice/lsp.c
+++ b/apps/codecs/libwmavoice/lsp.c
@@ -150,7 +150,7 @@ void ff_acelp_lspd2lpc(const double *lsp, float *lpc, int lp_half_order)
150 double pa[MAX_LP_HALF_ORDER+1], qa[MAX_LP_HALF_ORDER+1]; 150 double pa[MAX_LP_HALF_ORDER+1], qa[MAX_LP_HALF_ORDER+1];
151 float *lpc2 = lpc + (lp_half_order << 1) - 1; 151 float *lpc2 = lpc + (lp_half_order << 1) - 1;
152 152
153 assert(lp_half_order <= MAX_LP_HALF_ORDER); 153 //assert(lp_half_order <= MAX_LP_HALF_ORDER);
154 154
155 ff_lsp2polyf(lsp, pa, lp_half_order); 155 ff_lsp2polyf(lsp, pa, lp_half_order);
156 ff_lsp2polyf(lsp + 1, qa, lp_half_order); 156 ff_lsp2polyf(lsp + 1, qa, lp_half_order);
diff --git a/apps/codecs/libwmavoice/mathops.h b/apps/codecs/libwmavoice/mathops.h
new file mode 100644
index 0000000000..4d88ed14c9
--- /dev/null
+++ b/apps/codecs/libwmavoice/mathops.h
@@ -0,0 +1,182 @@
1/*
2 * simple math operations
3 * Copyright (c) 2001, 2002 Fabrice Bellard
4 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> et al
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#ifndef AVCODEC_MATHOPS_H
23#define AVCODEC_MATHOPS_H
24
25#include "libavutil/common.h"
26
27#if ARCH_ARM
28# include "arm/mathops.h"
29#elif ARCH_AVR32
30# include "avr32/mathops.h"
31#elif ARCH_BFIN
32# include "bfin/mathops.h"
33#elif ARCH_MIPS
34# include "mips/mathops.h"
35#elif ARCH_PPC
36# include "ppc/mathops.h"
37#elif ARCH_X86
38# include "x86/mathops.h"
39#endif
40
41/* generic implementation */
42
43#ifndef MULL
44# define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s))
45#endif
46
47#ifndef MULH
48//gcc 3.4 creates an incredibly bloated mess out of this
49//# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32)
50
51static av_always_inline int MULH(int a, int b){
52 return ((int64_t)(a) * (int64_t)(b))>>32;
53}
54#endif
55
56#ifndef UMULH
57static av_always_inline unsigned UMULH(unsigned a, unsigned b){
58 return ((uint64_t)(a) * (uint64_t)(b))>>32;
59}
60#endif
61
62#ifndef MUL64
63# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b))
64#endif
65
66#ifndef MAC64
67# define MAC64(d, a, b) ((d) += MUL64(a, b))
68#endif
69
70#ifndef MLS64
71# define MLS64(d, a, b) ((d) -= MUL64(a, b))
72#endif
73
74/* signed 16x16 -> 32 multiply add accumulate */
75#ifndef MAC16
76# define MAC16(rt, ra, rb) rt += (ra) * (rb)
77#endif
78
79/* signed 16x16 -> 32 multiply */
80#ifndef MUL16
81# define MUL16(ra, rb) ((ra) * (rb))
82#endif
83
84#ifndef MLS16
85# define MLS16(rt, ra, rb) ((rt) -= (ra) * (rb))
86#endif
87
88/* median of 3 */
89#ifndef mid_pred
90#define mid_pred mid_pred
91static inline av_const int mid_pred(int a, int b, int c)
92{
93#if 0
94 int t= (a-b)&((a-b)>>31);
95 a-=t;
96 b+=t;
97 b-= (b-c)&((b-c)>>31);
98 b+= (a-b)&((a-b)>>31);
99
100 return b;
101#else
102 if(a>b){
103 if(c>b){
104 if(c>a) b=a;
105 else b=c;
106 }
107 }else{
108 if(b>c){
109 if(c>a) b=c;
110 else b=a;
111 }
112 }
113 return b;
114#endif
115}
116#endif
117
118#ifndef sign_extend
119static inline av_const int sign_extend(int val, unsigned bits)
120{
121 return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
122}
123#endif
124
125#ifndef zero_extend
126static inline av_const unsigned zero_extend(unsigned val, unsigned bits)
127{
128 return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits);
129}
130#endif
131
132#ifndef COPY3_IF_LT
133#define COPY3_IF_LT(x, y, a, b, c, d)\
134if ((y) < (x)) {\
135 (x) = (y);\
136 (a) = (b);\
137 (c) = (d);\
138}
139#endif
140
141#ifndef NEG_SSR32
142# define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
143#endif
144
145#ifndef NEG_USR32
146# define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
147#endif
148
149#if HAVE_BIGENDIAN
150# ifndef PACK_2U8
151# define PACK_2U8(a,b) (((a) << 8) | (b))
152# endif
153# ifndef PACK_4U8
154# define PACK_4U8(a,b,c,d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
155# endif
156# ifndef PACK_2U16
157# define PACK_2U16(a,b) (((a) << 16) | (b))
158# endif
159#else
160# ifndef PACK_2U8
161# define PACK_2U8(a,b) (((b) << 8) | (a))
162# endif
163# ifndef PACK_4U2
164# define PACK_4U8(a,b,c,d) (((d) << 24) | ((c) << 16) | ((b) << 8) | (a))
165# endif
166# ifndef PACK_2U16
167# define PACK_2U16(a,b) (((b) << 16) | (a))
168# endif
169#endif
170
171#ifndef PACK_2S8
172# define PACK_2S8(a,b) PACK_2U8((a)&255, (b)&255)
173#endif
174#ifndef PACK_4S8
175# define PACK_4S8(a,b,c,d) PACK_4U8((a)&255, (b)&255, (c)&255, (d)&255)
176#endif
177#ifndef PACK_2S16
178# define PACK_2S16(a,b) PACK_2U16((a)&0xffff, (b)&0xffff)
179#endif
180
181#endif /* AVCODEC_MATHOPS_H */
182
diff --git a/apps/codecs/libwmavoice/mdct.c b/apps/codecs/libwmavoice/mdct.c
index c511188d22..58bff3517b 100644
--- a/apps/codecs/libwmavoice/mdct.c
+++ b/apps/codecs/libwmavoice/mdct.c
@@ -39,7 +39,7 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n)
39 double local_window[FF_KBD_WINDOW_MAX]; 39 double local_window[FF_KBD_WINDOW_MAX];
40 double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); 40 double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n);
41 41
42 assert(n <= FF_KBD_WINDOW_MAX); 42 //assert(n <= FF_KBD_WINDOW_MAX);
43 43
44 for (i = 0; i < n; i++) { 44 for (i = 0; i < n; i++) {
45 tmp = i * (n - i) * alpha2; 45 tmp = i * (n - i) * alpha2;
diff --git a/apps/codecs/libwmavoice/mdct_tablegen.h b/apps/codecs/libwmavoice/mdct_tablegen.h
new file mode 100644
index 0000000000..51a0094221
--- /dev/null
+++ b/apps/codecs/libwmavoice/mdct_tablegen.h
@@ -0,0 +1,60 @@
1/*
2 * Header file for hardcoded MDCT tables
3 *
4 * Copyright (c) 2009 Reimar Döffinger <Reimar.Doeffinger@gmx.de>
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#include <assert.h>
24// do not use libavutil/libm.h since this is compiled both
25// for the host and the target and config.h is only valid for the target
26#include <math.h>
27#include "libavutil/attributes.h"
28
29#if !CONFIG_HARDCODED_TABLES
30SINETABLE( 32);
31SINETABLE( 64);
32SINETABLE( 128);
33SINETABLE( 256);
34SINETABLE( 512);
35SINETABLE(1024);
36SINETABLE(2048);
37SINETABLE(4096);
38#else
39#include "libavcodec/mdct_tables.h"
40#endif
41
42SINETABLE_CONST float * const ff_sine_windows[] = {
43 NULL, NULL, NULL, NULL, NULL, // unused
44 ff_sine_32 , ff_sine_64 ,
45 ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096
46};
47
48// Generate a sine window.
49av_cold void ff_sine_window_init(float *window, int n) {
50 int i;
51 for(i = 0; i < n; i++)
52 window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n)));
53}
54
55av_cold void ff_init_ff_sine_windows(int index) {
56 assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows));
57#if !CONFIG_HARDCODED_TABLES
58 ff_sine_window_init(ff_sine_windows[index], 1 << index);
59#endif
60}
diff --git a/apps/codecs/libwmavoice/rdft.c b/apps/codecs/libwmavoice/rdft.c
new file mode 100644
index 0000000000..bc44f5aef2
--- /dev/null
+++ b/apps/codecs/libwmavoice/rdft.c
@@ -0,0 +1,133 @@
1/*
2 * (I)RDFT transforms
3 * Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com>
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 <stdlib.h>
22#include <math.h>
23#include "libavutil/mathematics.h"
24#include "fft.h"
25
26/**
27 * @file
28 * (Inverse) Real Discrete Fourier Transforms.
29 */
30
31/* sin(2*pi*x/n) for 0<=x<n/4, followed by n/2<=x<3n/4 */
32#if !CONFIG_HARDCODED_TABLES
33SINTABLE(16);
34SINTABLE(32);
35SINTABLE(64);
36SINTABLE(128);
37SINTABLE(256);
38SINTABLE(512);
39SINTABLE(1024);
40SINTABLE(2048);
41SINTABLE(4096);
42SINTABLE(8192);
43SINTABLE(16384);
44SINTABLE(32768);
45SINTABLE(65536);
46#endif
47SINTABLE_CONST FFTSample * const ff_sin_tabs[] = {
48 NULL, NULL, NULL, NULL,
49 ff_sin_16, ff_sin_32, ff_sin_64, ff_sin_128, ff_sin_256, ff_sin_512, ff_sin_1024,
50 ff_sin_2048, ff_sin_4096, ff_sin_8192, ff_sin_16384, ff_sin_32768, ff_sin_65536,
51};
52
53/** Map one real FFT into two parallel real even and odd FFTs. Then interleave
54 * the two real FFTs into one complex FFT. Unmangle the results.
55 * ref: http://www.engineeringproductivitytools.com/stuff/T0001/PT10.HTM
56 */
57static void ff_rdft_calc_c(RDFTContext* s, FFTSample* data)
58{
59 int i, i1, i2;
60 FFTComplex ev, od;
61 const int n = 1 << s->nbits;
62 const float k1 = 0.5;
63 const float k2 = 0.5 - s->inverse;
64 const FFTSample *tcos = s->tcos;
65 const FFTSample *tsin = s->tsin;
66
67 if (!s->inverse) {
68 ff_fft_permute(&s->fft, (FFTComplex*)data);
69 ff_fft_calc(&s->fft, (FFTComplex*)data);
70 }
71 /* i=0 is a special case because of packing, the DC term is real, so we
72 are going to throw the N/2 term (also real) in with it. */
73 ev.re = data[0];
74 data[0] = ev.re+data[1];
75 data[1] = ev.re-data[1];
76 for (i = 1; i < (n>>2); i++) {
77 i1 = 2*i;
78 i2 = n-i1;
79 /* Separate even and odd FFTs */
80 ev.re = k1*(data[i1 ]+data[i2 ]);
81 od.im = -k2*(data[i1 ]-data[i2 ]);
82 ev.im = k1*(data[i1+1]-data[i2+1]);
83 od.re = k2*(data[i1+1]+data[i2+1]);
84 /* Apply twiddle factors to the odd FFT and add to the even FFT */
85 data[i1 ] = ev.re + od.re*tcos[i] - od.im*tsin[i];
86 data[i1+1] = ev.im + od.im*tcos[i] + od.re*tsin[i];
87 data[i2 ] = ev.re - od.re*tcos[i] + od.im*tsin[i];
88 data[i2+1] = -ev.im + od.im*tcos[i] + od.re*tsin[i];
89 }
90 data[2*i+1]=s->sign_convention*data[2*i+1];
91 if (s->inverse) {
92 data[0] *= k1;
93 data[1] *= k1;
94 ff_fft_permute(&s->fft, (FFTComplex*)data);
95 ff_fft_calc(&s->fft, (FFTComplex*)data);
96 }
97}
98
99av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
100{
101 int n = 1 << nbits;
102 int i;
103 const double theta = (trans == DFT_R2C || trans == DFT_C2R ? -1 : 1)*2*M_PI/n;
104
105 s->nbits = nbits;
106 s->inverse = trans == IDFT_C2R || trans == DFT_C2R;
107 s->sign_convention = trans == IDFT_R2C || trans == DFT_C2R ? 1 : -1;
108
109 if (nbits < 4 || nbits > 16)
110 return -1;
111
112 if (ff_fft_init(&s->fft, nbits-1, trans == IDFT_C2R || trans == IDFT_R2C) < 0)
113 return -1;
114
115 ff_init_ff_cos_tabs(nbits);
116 s->tcos = ff_cos_tabs[nbits];
117 s->tsin = ff_sin_tabs[nbits]+(trans == DFT_R2C || trans == DFT_C2R)*(n>>2);
118#if !CONFIG_HARDCODED_TABLES
119 for (i = 0; i < (n>>2); i++) {
120 s->tsin[i] = sin(i*theta);
121 }
122#endif
123 s->rdft_calc = ff_rdft_calc_c;
124
125 //if (ARCH_ARM) ff_rdft_init_arm(s);
126
127 return 0;
128}
129
130av_cold void ff_rdft_end(RDFTContext *s)
131{
132 ff_fft_end(&s->fft);
133}
diff --git a/apps/codecs/libwmavoice/utils.c b/apps/codecs/libwmavoice/utils.c
new file mode 100644
index 0000000000..ad098f4636
--- /dev/null
+++ b/apps/codecs/libwmavoice/utils.c
@@ -0,0 +1,1188 @@
1/*
2 * utils for libavcodec
3 * Copyright (c) 2001 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
25 * utils.
26 */
27
28//#include "libavutil/avstring.h"
29//#include "libavutil/integer.h"
30//#include "libavutil/crc.h"
31//#include "libavutil/pixdesc.h"
32//#include "libavcore/imgutils.h"
33#include "avcodec.h"
34//#include "dsputil.h"
35//#include "opt.h"
36//#include "imgconvert.h"
37//#include "audioconvert.h"
38#include "internal.h"
39#include <stdlib.h>
40#include <stdarg.h>
41#include <limits.h>
42#include <float.h>
43
44#if 0
45static int volatile entangled_thread_counter=0;
46int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
47static void *codec_mutex;
48
49void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
50{
51 if(min_size < *size)
52 return ptr;
53
54 *size= FFMAX(17*min_size/16 + 32, min_size);
55
56 ptr= av_realloc(ptr, *size);
57 if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
58 *size= 0;
59
60 return ptr;
61}
62
63void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size)
64{
65 void **p = ptr;
66 if (min_size < *size)
67 return;
68 *size= FFMAX(17*min_size/16 + 32, min_size);
69 av_free(*p);
70 *p = av_malloc(*size);
71 if (!*p) *size = 0;
72}
73
74/* encoder management */
75static AVCodec *first_avcodec = NULL;
76
77AVCodec *av_codec_next(AVCodec *c){
78 if(c) return c->next;
79 else return first_avcodec;
80}
81
82void avcodec_register(AVCodec *codec)
83{
84 AVCodec **p;
85 avcodec_init();
86 p = &first_avcodec;
87 while (*p != NULL) p = &(*p)->next;
88 *p = codec;
89 codec->next = NULL;
90}
91
92#if LIBAVCODEC_VERSION_MAJOR < 53
93void register_avcodec(AVCodec *codec)
94{
95 avcodec_register(codec);
96}
97#endif
98
99unsigned avcodec_get_edge_width(void)
100{
101 return EDGE_WIDTH;
102}
103
104void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
105 s->coded_width = width;
106 s->coded_height= height;
107 s->width = -((-width )>>s->lowres);
108 s->height= -((-height)>>s->lowres);
109}
110
111typedef struct InternalBuffer{
112 int last_pic_num;
113 uint8_t *base[4];
114 uint8_t *data[4];
115 int linesize[4];
116 int width, height;
117 enum PixelFormat pix_fmt;
118}InternalBuffer;
119
120#define INTERNAL_BUFFER_SIZE 32
121
122void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
123 int w_align= 1;
124 int h_align= 1;
125
126 switch(s->pix_fmt){
127 case PIX_FMT_YUV420P:
128 case PIX_FMT_YUYV422:
129 case PIX_FMT_UYVY422:
130 case PIX_FMT_YUV422P:
131 case PIX_FMT_YUV440P:
132 case PIX_FMT_YUV444P:
133 case PIX_FMT_GRAY8:
134 case PIX_FMT_GRAY16BE:
135 case PIX_FMT_GRAY16LE:
136 case PIX_FMT_YUVJ420P:
137 case PIX_FMT_YUVJ422P:
138 case PIX_FMT_YUVJ440P:
139 case PIX_FMT_YUVJ444P:
140 case PIX_FMT_YUVA420P:
141 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
142 h_align= 16;
143 if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP)
144 h_align= 32; // interlaced is rounded up to 2 MBs
145 break;
146 case PIX_FMT_YUV411P:
147 case PIX_FMT_UYYVYY411:
148 w_align=32;
149 h_align=8;
150 break;
151 case PIX_FMT_YUV410P:
152 if(s->codec_id == CODEC_ID_SVQ1){
153 w_align=64;
154 h_align=64;
155 }
156 case PIX_FMT_RGB555:
157 if(s->codec_id == CODEC_ID_RPZA){
158 w_align=4;
159 h_align=4;
160 }
161 case PIX_FMT_PAL8:
162 case PIX_FMT_BGR8:
163 case PIX_FMT_RGB8:
164 if(s->codec_id == CODEC_ID_SMC){
165 w_align=4;
166 h_align=4;
167 }
168 break;
169 case PIX_FMT_BGR24:
170 if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
171 w_align=4;
172 h_align=4;
173 }
174 break;
175 default:
176 w_align= 1;
177 h_align= 1;
178 break;
179 }
180
181 *width = FFALIGN(*width , w_align);
182 *height= FFALIGN(*height, h_align);
183 if(s->codec_id == CODEC_ID_H264)
184 *height+=2; // some of the optimized chroma MC reads one line too much
185
186 linesize_align[0] =
187 linesize_align[1] =
188 linesize_align[2] =
189 linesize_align[3] = STRIDE_ALIGN;
190//STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
191//we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
192//picture size unneccessarily in some cases. The solution here is not
193//pretty and better ideas are welcome!
194#if HAVE_MMX
195 if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
196 s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
197 s->codec_id == CODEC_ID_VP6A) {
198 linesize_align[0] =
199 linesize_align[1] =
200 linesize_align[2] = 16;
201 }
202#endif
203}
204
205void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
206 int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
207 int linesize_align[4];
208 int align;
209 avcodec_align_dimensions2(s, width, height, linesize_align);
210 align = FFMAX(linesize_align[0], linesize_align[3]);
211 linesize_align[1] <<= chroma_shift;
212 linesize_align[2] <<= chroma_shift;
213 align = FFMAX3(align, linesize_align[1], linesize_align[2]);
214 *width=FFALIGN(*width, align);
215}
216
217#if LIBAVCODEC_VERSION_MAJOR < 53
218int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
219 return av_check_image_size(w, h, 0, av_log_ctx);
220}
221#endif
222
223int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
224 int i;
225 int w= s->width;
226 int h= s->height;
227 InternalBuffer *buf;
228 int *picture_number;
229
230 if(pic->data[0]!=NULL) {
231 av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
232 return -1;
233 }
234 if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
235 av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
236 return -1;
237 }
238
239 if(av_check_image_size(w, h, 0, s))
240 return -1;
241
242 if(s->internal_buffer==NULL){
243 s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer));
244 }
245#if 0
246 s->internal_buffer= av_fast_realloc(
247 s->internal_buffer,
248 &s->internal_buffer_size,
249 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
250 );
251#endif
252
253 buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
254 picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
255 (*picture_number)++;
256
257 if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
258 for(i=0; i<4; i++){
259 av_freep(&buf->base[i]);
260 buf->data[i]= NULL;
261 }
262 }
263
264 if(buf->base[0]){
265 pic->age= *picture_number - buf->last_pic_num;
266 buf->last_pic_num= *picture_number;
267 }else{
268 int h_chroma_shift, v_chroma_shift;
269 int size[4] = {0};
270 int tmpsize;
271 int unaligned;
272 AVPicture picture;
273 int stride_align[4];
274
275 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
276
277 avcodec_align_dimensions2(s, &w, &h, stride_align);
278
279 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
280 w+= EDGE_WIDTH*2;
281 h+= EDGE_WIDTH*2;
282 }
283
284 do {
285 // NOTE: do not align linesizes individually, this breaks e.g. assumptions
286 // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
287 av_fill_image_linesizes(picture.linesize, s->pix_fmt, w);
288 // increase alignment of w for next try (rhs gives the lowest bit set in w)
289 w += w & ~(w-1);
290
291 unaligned = 0;
292 for (i=0; i<4; i++){
293 unaligned |= picture.linesize[i] % stride_align[i];
294 }
295 } while (unaligned);
296
297 tmpsize = av_fill_image_pointers(picture.data, s->pix_fmt, h, NULL, picture.linesize);
298 if (tmpsize < 0)
299 return -1;
300
301 for (i=0; i<3 && picture.data[i+1]; i++)
302 size[i] = picture.data[i+1] - picture.data[i];
303 size[i] = tmpsize - (picture.data[i] - picture.data[0]);
304
305 buf->last_pic_num= -256*256*256*64;
306 memset(buf->base, 0, sizeof(buf->base));
307 memset(buf->data, 0, sizeof(buf->data));
308
309 for(i=0; i<4 && size[i]; i++){
310 const int h_shift= i==0 ? 0 : h_chroma_shift;
311 const int v_shift= i==0 ? 0 : v_chroma_shift;
312
313 buf->linesize[i]= picture.linesize[i];
314
315 buf->base[i]= av_malloc(size[i]+16); //FIXME 16
316 if(buf->base[i]==NULL) return -1;
317 memset(buf->base[i], 128, size[i]);
318
319 // no edge if EDGE EMU or not planar YUV
320 if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
321 buf->data[i] = buf->base[i];
322 else
323 buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), stride_align[i]);
324 }
325 if(size[1] && !size[2])
326 ff_set_systematic_pal((uint32_t*)buf->data[1], s->pix_fmt);
327 buf->width = s->width;
328 buf->height = s->height;
329 buf->pix_fmt= s->pix_fmt;
330 pic->age= 256*256*256*64;
331 }
332 pic->type= FF_BUFFER_TYPE_INTERNAL;
333
334 for(i=0; i<4; i++){
335 pic->base[i]= buf->base[i];
336 pic->data[i]= buf->data[i];
337 pic->linesize[i]= buf->linesize[i];
338 }
339 s->internal_buffer_count++;
340
341 pic->reordered_opaque= s->reordered_opaque;
342
343 if(s->debug&FF_DEBUG_BUFFERS)
344 av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
345
346 return 0;
347}
348
349void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
350 int i;
351 InternalBuffer *buf, *last;
352
353 assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
354 assert(s->internal_buffer_count);
355
356 buf = NULL; /* avoids warning */
357 for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
358 buf= &((InternalBuffer*)s->internal_buffer)[i];
359 if(buf->data[0] == pic->data[0])
360 break;
361 }
362 assert(i < s->internal_buffer_count);
363 s->internal_buffer_count--;
364 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
365
366 FFSWAP(InternalBuffer, *buf, *last);
367
368 for(i=0; i<4; i++){
369 pic->data[i]=NULL;
370// pic->base[i]=NULL;
371 }
372//printf("R%X\n", pic->opaque);
373
374 if(s->debug&FF_DEBUG_BUFFERS)
375 av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
376}
377
378int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
379 AVFrame temp_pic;
380 int i;
381
382 /* If no picture return a new buffer */
383 if(pic->data[0] == NULL) {
384 /* We will copy from buffer, so must be readable */
385 pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
386 return s->get_buffer(s, pic);
387 }
388
389 /* If internal buffer type return the same buffer */
390 if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
391 pic->reordered_opaque= s->reordered_opaque;
392 return 0;
393 }
394
395 /*
396 * Not internal type and reget_buffer not overridden, emulate cr buffer
397 */
398 temp_pic = *pic;
399 for(i = 0; i < 4; i++)
400 pic->data[i] = pic->base[i] = NULL;
401 pic->opaque = NULL;
402 /* Allocate new frame */
403 if (s->get_buffer(s, pic))
404 return -1;
405 /* Copy image data from old buffer to new buffer */
406 av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
407 s->height);
408 s->release_buffer(s, &temp_pic); // Release old frame
409 return 0;
410}
411
412int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
413 int i;
414
415 for(i=0; i<count; i++){
416 int r= func(c, (char*)arg + i*size);
417 if(ret) ret[i]= r;
418 }
419 return 0;
420}
421
422int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
423 int i;
424
425 for(i=0; i<count; i++){
426 int r= func(c, arg, i, 0);
427 if(ret) ret[i]= r;
428 }
429 return 0;
430}
431
432enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
433 while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
434 ++fmt;
435 return fmt[0];
436}
437
438void avcodec_get_frame_defaults(AVFrame *pic){
439 memset(pic, 0, sizeof(AVFrame));
440
441 pic->pts= AV_NOPTS_VALUE;
442 pic->key_frame= 1;
443}
444
445AVFrame *avcodec_alloc_frame(void){
446 AVFrame *pic= av_malloc(sizeof(AVFrame));
447
448 if(pic==NULL) return NULL;
449
450 avcodec_get_frame_defaults(pic);
451
452 return pic;
453}
454
455int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
456{
457 int ret= -1;
458
459 /* If there is a user-supplied mutex locking routine, call it. */
460 if (ff_lockmgr_cb) {
461 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
462 return -1;
463 }
464
465 entangled_thread_counter++;
466 if(entangled_thread_counter != 1){
467 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
468 goto end;
469 }
470
471 if(avctx->codec || !codec)
472 goto end;
473
474 if (codec->priv_data_size > 0) {
475 avctx->priv_data = av_mallocz(codec->priv_data_size);
476 if (!avctx->priv_data) {
477 ret = AVERROR(ENOMEM);
478 goto end;
479 }
480 } else {
481 avctx->priv_data = NULL;
482 }
483
484 if(avctx->coded_width && avctx->coded_height)
485 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
486 else if(avctx->width && avctx->height)
487 avcodec_set_dimensions(avctx, avctx->width, avctx->height);
488
489#define SANE_NB_CHANNELS 128U
490 if (((avctx->coded_width || avctx->coded_height)
491 && av_check_image_size(avctx->coded_width, avctx->coded_height, 0, avctx))
492 || avctx->channels > SANE_NB_CHANNELS) {
493 ret = AVERROR(EINVAL);
494 goto free_and_end;
495 }
496
497 avctx->codec = codec;
498 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
499 avctx->codec_id == CODEC_ID_NONE) {
500 avctx->codec_type = codec->type;
501 avctx->codec_id = codec->id;
502 }
503 if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){
504 av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
505 goto free_and_end;
506 }
507 avctx->frame_number = 0;
508 if(avctx->codec->init){
509 if(avctx->codec_type == AVMEDIA_TYPE_VIDEO &&
510 avctx->codec->max_lowres < avctx->lowres){
511 av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n",
512 avctx->codec->max_lowres);
513 goto free_and_end;
514 }
515
516 ret = avctx->codec->init(avctx);
517 if (ret < 0) {
518 goto free_and_end;
519 }
520 }
521 ret=0;
522end:
523 entangled_thread_counter--;
524
525 /* Release any user-supplied mutex. */
526 if (ff_lockmgr_cb) {
527 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
528 }
529 return ret;
530free_and_end:
531 av_freep(&avctx->priv_data);
532 avctx->codec= NULL;
533 goto end;
534}
535
536int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
537 const short *samples)
538{
539 if(buf_size < FF_MIN_BUFFER_SIZE && 0){
540 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
541 return -1;
542 }
543 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
544 int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
545 avctx->frame_number++;
546 return ret;
547 }else
548 return 0;
549}
550
551int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
552 const AVFrame *pict)
553{
554 if(buf_size < FF_MIN_BUFFER_SIZE){
555 av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
556 return -1;
557 }
558 if(av_check_image_size(avctx->width, avctx->height, 0, avctx))
559 return -1;
560 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
561 int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
562 avctx->frame_number++;
563 emms_c(); //needed to avoid an emms_c() call before every return;
564
565 return ret;
566 }else
567 return 0;
568}
569
570int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
571 const AVSubtitle *sub)
572{
573 int ret;
574 if(sub->start_display_time) {
575 av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
576 return -1;
577 }
578 if(sub->num_rects == 0 || !sub->rects)
579 return -1;
580 ret = avctx->codec->encode(avctx, buf, buf_size, sub);
581 avctx->frame_number++;
582 return ret;
583}
584
585#if LIBAVCODEC_VERSION_MAJOR < 53
586int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
587 int *got_picture_ptr,
588 const uint8_t *buf, int buf_size)
589{
590 AVPacket avpkt;
591 av_init_packet(&avpkt);
592 avpkt.data = buf;
593 avpkt.size = buf_size;
594 // HACK for CorePNG to decode as normal PNG by default
595 avpkt.flags = AV_PKT_FLAG_KEY;
596
597 return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt);
598}
599#endif
600
601int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
602 int *got_picture_ptr,
603 AVPacket *avpkt)
604{
605 int ret;
606
607 *got_picture_ptr= 0;
608 if((avctx->coded_width||avctx->coded_height) && av_check_image_size(avctx->coded_width, avctx->coded_height, 0, avctx))
609 return -1;
610 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
611 ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
612 avpkt);
613
614 emms_c(); //needed to avoid an emms_c() call before every return;
615
616 if (*got_picture_ptr)
617 avctx->frame_number++;
618 }else
619 ret= 0;
620
621 return ret;
622}
623
624#if LIBAVCODEC_VERSION_MAJOR < 53
625int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
626 int *frame_size_ptr,
627 const uint8_t *buf, int buf_size)
628{
629 AVPacket avpkt;
630 av_init_packet(&avpkt);
631 avpkt.data = buf;
632 avpkt.size = buf_size;
633
634 return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt);
635}
636#endif
637
638int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
639 int *frame_size_ptr,
640 AVPacket *avpkt)
641{
642 int ret;
643
644 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
645 //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
646 if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
647 av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
648 return -1;
649 }
650 if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
651 *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
652 av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
653 return -1;
654 }
655
656 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt);
657 avctx->frame_number++;
658 }else{
659 ret= 0;
660 *frame_size_ptr=0;
661 }
662 return ret;
663}
664
665#if LIBAVCODEC_VERSION_MAJOR < 53
666int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
667 int *got_sub_ptr,
668 const uint8_t *buf, int buf_size)
669{
670 AVPacket avpkt;
671 av_init_packet(&avpkt);
672 avpkt.data = buf;
673 avpkt.size = buf_size;
674
675 return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt);
676}
677#endif
678
679int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
680 int *got_sub_ptr,
681 AVPacket *avpkt)
682{
683 int ret;
684
685 *got_sub_ptr = 0;
686 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
687 if (*got_sub_ptr)
688 avctx->frame_number++;
689 return ret;
690}
691
692void avsubtitle_free(AVSubtitle *sub)
693{
694 int i;
695
696 for (i = 0; i < sub->num_rects; i++)
697 {
698 av_freep(&sub->rects[i]->pict.data[0]);
699 av_freep(&sub->rects[i]->pict.data[1]);
700 av_freep(&sub->rects[i]->pict.data[2]);
701 av_freep(&sub->rects[i]->pict.data[3]);
702 av_freep(&sub->rects[i]->text);
703 av_freep(&sub->rects[i]->ass);
704 av_freep(&sub->rects[i]);
705 }
706
707 av_freep(&sub->rects);
708
709 memset(sub, 0, sizeof(AVSubtitle));
710}
711
712av_cold int avcodec_close(AVCodecContext *avctx)
713{
714 /* If there is a user-supplied mutex locking routine, call it. */
715 if (ff_lockmgr_cb) {
716 if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
717 return -1;
718 }
719
720 entangled_thread_counter++;
721 if(entangled_thread_counter != 1){
722 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
723 entangled_thread_counter--;
724 return -1;
725 }
726
727 if (HAVE_THREADS && avctx->thread_opaque)
728 avcodec_thread_free(avctx);
729 if (avctx->codec && avctx->codec->close)
730 avctx->codec->close(avctx);
731 avcodec_default_free_buffers(avctx);
732 avctx->coded_frame = NULL;
733 av_freep(&avctx->priv_data);
734 if(avctx->codec && avctx->codec->encode)
735 av_freep(&avctx->extradata);
736 avctx->codec = NULL;
737 entangled_thread_counter--;
738
739 /* Release any user-supplied mutex. */
740 if (ff_lockmgr_cb) {
741 (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
742 }
743 return 0;
744}
745
746AVCodec *avcodec_find_encoder(enum CodecID id)
747{
748 AVCodec *p, *experimental=NULL;
749 p = first_avcodec;
750 while (p) {
751 if (p->encode != NULL && p->id == id) {
752 if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) {
753 experimental = p;
754 } else
755 return p;
756 }
757 p = p->next;
758 }
759 return experimental;
760}
761
762AVCodec *avcodec_find_encoder_by_name(const char *name)
763{
764 AVCodec *p;
765 if (!name)
766 return NULL;
767 p = first_avcodec;
768 while (p) {
769 if (p->encode != NULL && strcmp(name,p->name) == 0)
770 return p;
771 p = p->next;
772 }
773 return NULL;
774}
775
776AVCodec *avcodec_find_decoder(enum CodecID id)
777{
778 AVCodec *p;
779 p = first_avcodec;
780 while (p) {
781 if (p->decode != NULL && p->id == id)
782 return p;
783 p = p->next;
784 }
785 return NULL;
786}
787
788AVCodec *avcodec_find_decoder_by_name(const char *name)
789{
790 AVCodec *p;
791 if (!name)
792 return NULL;
793 p = first_avcodec;
794 while (p) {
795 if (p->decode != NULL && strcmp(name,p->name) == 0)
796 return p;
797 p = p->next;
798 }
799 return NULL;
800}
801
802static int get_bit_rate(AVCodecContext *ctx)
803{
804 int bit_rate;
805 int bits_per_sample;
806
807 switch(ctx->codec_type) {
808 case AVMEDIA_TYPE_VIDEO:
809 case AVMEDIA_TYPE_DATA:
810 case AVMEDIA_TYPE_SUBTITLE:
811 case AVMEDIA_TYPE_ATTACHMENT:
812 bit_rate = ctx->bit_rate;
813 break;
814 case AVMEDIA_TYPE_AUDIO:
815 bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
816 bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
817 break;
818 default:
819 bit_rate = 0;
820 break;
821 }
822 return bit_rate;
823}
824
825size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag)
826{
827 int i, len, ret = 0;
828
829 for (i = 0; i < 4; i++) {
830 len = snprintf(buf, buf_size,
831 isprint(codec_tag&0xFF) ? "%c" : "[%d]", codec_tag&0xFF);
832 buf += len;
833 buf_size = buf_size > len ? buf_size - len : 0;
834 ret += len;
835 codec_tag>>=8;
836 }
837 return ret;
838}
839
840void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
841{
842 const char *codec_name;
843 AVCodec *p;
844 char buf1[32];
845 int bitrate;
846 AVRational display_aspect_ratio;
847
848 if (encode)
849 p = avcodec_find_encoder(enc->codec_id);
850 else
851 p = avcodec_find_decoder(enc->codec_id);
852
853 if (p) {
854 codec_name = p->name;
855 } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
856 /* fake mpeg2 transport stream codec (currently not
857 registered) */
858 codec_name = "mpeg2ts";
859 } else if (enc->codec_name[0] != '\0') {
860 codec_name = enc->codec_name;
861 } else {
862 /* output avi tags */
863 char tag_buf[32];
864 av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag);
865 snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag);
866 codec_name = buf1;
867 }
868
869 switch(enc->codec_type) {
870 case AVMEDIA_TYPE_VIDEO:
871 snprintf(buf, buf_size,
872 "Video: %s%s",
873 codec_name, enc->mb_decision ? " (hq)" : "");
874 if (enc->pix_fmt != PIX_FMT_NONE) {
875 snprintf(buf + strlen(buf), buf_size - strlen(buf),
876 ", %s",
877 avcodec_get_pix_fmt_name(enc->pix_fmt));
878 }
879 if (enc->width) {
880 snprintf(buf + strlen(buf), buf_size - strlen(buf),
881 ", %dx%d",
882 enc->width, enc->height);
883 if (enc->sample_aspect_ratio.num) {
884 av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
885 enc->width*enc->sample_aspect_ratio.num,
886 enc->height*enc->sample_aspect_ratio.den,
887 1024*1024);
888 snprintf(buf + strlen(buf), buf_size - strlen(buf),
889 " [PAR %d:%d DAR %d:%d]",
890 enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
891 display_aspect_ratio.num, display_aspect_ratio.den);
892 }
893 if(av_log_get_level() >= AV_LOG_DEBUG){
894 int g= av_gcd(enc->time_base.num, enc->time_base.den);
895 snprintf(buf + strlen(buf), buf_size - strlen(buf),
896 ", %d/%d",
897 enc->time_base.num/g, enc->time_base.den/g);
898 }
899 }
900 if (encode) {
901 snprintf(buf + strlen(buf), buf_size - strlen(buf),
902 ", q=%d-%d", enc->qmin, enc->qmax);
903 }
904 break;
905 case AVMEDIA_TYPE_AUDIO:
906 snprintf(buf, buf_size,
907 "Audio: %s",
908 codec_name);
909 if (enc->sample_rate) {
910 snprintf(buf + strlen(buf), buf_size - strlen(buf),
911 ", %d Hz", enc->sample_rate);
912 }
913 av_strlcat(buf, ", ", buf_size);
914 avcodec_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
915 if (enc->sample_fmt != SAMPLE_FMT_NONE) {
916 snprintf(buf + strlen(buf), buf_size - strlen(buf),
917 ", %s", avcodec_get_sample_fmt_name(enc->sample_fmt));
918 }
919 break;
920 case AVMEDIA_TYPE_DATA:
921 snprintf(buf, buf_size, "Data: %s", codec_name);
922 break;
923 case AVMEDIA_TYPE_SUBTITLE:
924 snprintf(buf, buf_size, "Subtitle: %s", codec_name);
925 break;
926 case AVMEDIA_TYPE_ATTACHMENT:
927 snprintf(buf, buf_size, "Attachment: %s", codec_name);
928 break;
929 default:
930 snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
931 return;
932 }
933 if (encode) {
934 if (enc->flags & CODEC_FLAG_PASS1)
935 snprintf(buf + strlen(buf), buf_size - strlen(buf),
936 ", pass 1");
937 if (enc->flags & CODEC_FLAG_PASS2)
938 snprintf(buf + strlen(buf), buf_size - strlen(buf),
939 ", pass 2");
940 }
941 bitrate = get_bit_rate(enc);
942 if (bitrate != 0) {
943 snprintf(buf + strlen(buf), buf_size - strlen(buf),
944 ", %d kb/s", bitrate / 1000);
945 }
946}
947
948unsigned avcodec_version( void )
949{
950 return LIBAVCODEC_VERSION_INT;
951}
952
953const char *avcodec_configuration(void)
954{
955 return FFMPEG_CONFIGURATION;
956}
957
958const char *avcodec_license(void)
959{
960#define LICENSE_PREFIX "libavcodec license: "
961 return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
962}
963
964void avcodec_init(void)
965{
966 static int initialized = 0;
967
968 if (initialized != 0)
969 return;
970 initialized = 1;
971
972 dsputil_static_init();
973}
974
975void avcodec_flush_buffers(AVCodecContext *avctx)
976{
977 if(avctx->codec->flush)
978 avctx->codec->flush(avctx);
979}
980
981void avcodec_default_free_buffers(AVCodecContext *s){
982 int i, j;
983
984 if(s->internal_buffer==NULL) return;
985
986 if (s->internal_buffer_count)
987 av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
988 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
989 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
990 for(j=0; j<4; j++){
991 av_freep(&buf->base[j]);
992 buf->data[j]= NULL;
993 }
994 }
995 av_freep(&s->internal_buffer);
996
997 s->internal_buffer_count=0;
998}
999
1000char av_get_pict_type_char(int pict_type){
1001 switch(pict_type){
1002 case FF_I_TYPE: return 'I';
1003 case FF_P_TYPE: return 'P';
1004 case FF_B_TYPE: return 'B';
1005 case FF_S_TYPE: return 'S';
1006 case FF_SI_TYPE:return 'i';
1007 case FF_SP_TYPE:return 'p';
1008 case FF_BI_TYPE:return 'b';
1009 default: return '?';
1010 }
1011}
1012
1013int av_get_bits_per_sample(enum CodecID codec_id){
1014 switch(codec_id){
1015 case CODEC_ID_ADPCM_SBPRO_2:
1016 return 2;
1017 case CODEC_ID_ADPCM_SBPRO_3:
1018 return 3;
1019 case CODEC_ID_ADPCM_SBPRO_4:
1020 case CODEC_ID_ADPCM_CT:
1021 case CODEC_ID_ADPCM_IMA_WAV:
1022 case CODEC_ID_ADPCM_MS:
1023 case CODEC_ID_ADPCM_YAMAHA:
1024 return 4;
1025 case CODEC_ID_PCM_ALAW:
1026 case CODEC_ID_PCM_MULAW:
1027 case CODEC_ID_PCM_S8:
1028 case CODEC_ID_PCM_U8:
1029 case CODEC_ID_PCM_ZORK:
1030 return 8;
1031 case CODEC_ID_PCM_S16BE:
1032 case CODEC_ID_PCM_S16LE:
1033 case CODEC_ID_PCM_S16LE_PLANAR:
1034 case CODEC_ID_PCM_U16BE:
1035 case CODEC_ID_PCM_U16LE:
1036 return 16;
1037 case CODEC_ID_PCM_S24DAUD:
1038 case CODEC_ID_PCM_S24BE:
1039 case CODEC_ID_PCM_S24LE:
1040 case CODEC_ID_PCM_U24BE:
1041 case CODEC_ID_PCM_U24LE:
1042 return 24;
1043 case CODEC_ID_PCM_S32BE:
1044 case CODEC_ID_PCM_S32LE:
1045 case CODEC_ID_PCM_U32BE:
1046 case CODEC_ID_PCM_U32LE:
1047 case CODEC_ID_PCM_F32BE:
1048 case CODEC_ID_PCM_F32LE:
1049 return 32;
1050 case CODEC_ID_PCM_F64BE:
1051 case CODEC_ID_PCM_F64LE:
1052 return 64;
1053 default:
1054 return 0;
1055 }
1056}
1057
1058int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
1059 switch (sample_fmt) {
1060 case SAMPLE_FMT_U8:
1061 return 8;
1062 case SAMPLE_FMT_S16:
1063 return 16;
1064 case SAMPLE_FMT_S32:
1065 case SAMPLE_FMT_FLT:
1066 return 32;
1067 case SAMPLE_FMT_DBL:
1068 return 64;
1069 default:
1070 return 0;
1071 }
1072}
1073
1074#if !HAVE_THREADS
1075int avcodec_thread_init(AVCodecContext *s, int thread_count){
1076 s->thread_count = thread_count;
1077 return -1;
1078}
1079#endif
1080
1081unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1082{
1083 unsigned int n = 0;
1084
1085 while(v >= 0xff) {
1086 *s++ = 0xff;
1087 v -= 0xff;
1088 n++;
1089 }
1090 *s = v;
1091 n++;
1092 return n;
1093}
1094
1095#if LIBAVCODEC_VERSION_MAJOR < 53
1096#include "libavcore/parseutils.h"
1097
1098int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
1099{
1100 return av_parse_video_size(width_ptr, height_ptr, str);
1101}
1102
1103int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
1104{
1105 return av_parse_video_rate(frame_rate, arg);
1106}
1107#endif
1108
1109int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
1110 int i;
1111 for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
1112 return i;
1113}
1114#endif
1115
1116void av_log_missing_feature(void *avc, const char *feature, int want_sample)
1117{
1118 av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
1119 "version to the newest one from SVN. If the problem still "
1120 "occurs, it means that your file has a feature which has not "
1121 "been implemented.", feature);
1122 if(want_sample)
1123 av_log_ask_for_sample(avc, NULL);
1124 else
1125 av_log(avc, AV_LOG_WARNING, "\n");
1126}
1127
1128void av_log_ask_for_sample(void *avc, const char *msg)
1129{
1130 if (msg)
1131 av_log(avc, AV_LOG_WARNING, "%s ", msg);
1132 av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
1133 "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
1134 "and contact the ffmpeg-devel mailing list.\n");
1135}
1136#if 0
1137static AVHWAccel *first_hwaccel = NULL;
1138
1139void av_register_hwaccel(AVHWAccel *hwaccel)
1140{
1141 AVHWAccel **p = &first_hwaccel;
1142 while (*p)
1143 p = &(*p)->next;
1144 *p = hwaccel;
1145 hwaccel->next = NULL;
1146}
1147
1148AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
1149{
1150 return hwaccel ? hwaccel->next : first_hwaccel;
1151}
1152
1153AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
1154{
1155 AVHWAccel *hwaccel=NULL;
1156
1157 while((hwaccel= av_hwaccel_next(hwaccel))){
1158 if ( hwaccel->id == codec_id
1159 && hwaccel->pix_fmt == pix_fmt)
1160 return hwaccel;
1161 }
1162 return NULL;
1163}
1164
1165int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1166{
1167 if (ff_lockmgr_cb) {
1168 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
1169 return -1;
1170 }
1171
1172 ff_lockmgr_cb = cb;
1173
1174 if (ff_lockmgr_cb) {
1175 if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
1176 return -1;
1177 }
1178 return 0;
1179}
1180
1181unsigned int ff_toupper4(unsigned int x)
1182{
1183 return toupper( x &0xFF)
1184 + (toupper((x>>8 )&0xFF)<<8 )
1185 + (toupper((x>>16)&0xFF)<<16)
1186 + (toupper((x>>24)&0xFF)<<24);
1187}
1188#endif
diff --git a/apps/codecs/libwmavoice/wmavoice.c b/apps/codecs/libwmavoice/wmavoice.c
index c4582f35cc..39bcb0e04e 100644
--- a/apps/codecs/libwmavoice/wmavoice.c
+++ b/apps/codecs/libwmavoice/wmavoice.c
@@ -2015,7 +2015,7 @@ static av_cold void wmavoice_flush(AVCodecContext *ctx)
2015 memset(s->denoise_filter_cache, 0, sizeof(s->denoise_filter_cache)); 2015 memset(s->denoise_filter_cache, 0, sizeof(s->denoise_filter_cache));
2016 } 2016 }
2017} 2017}
2018 2018#if 0
2019AVCodec wmavoice_decoder = { 2019AVCodec wmavoice_decoder = {
2020 "wmavoice", 2020 "wmavoice",
2021 AVMEDIA_TYPE_AUDIO, 2021 AVMEDIA_TYPE_AUDIO,
@@ -2029,3 +2029,9 @@ AVCodec wmavoice_decoder = {
2029 .flush = wmavoice_flush, 2029 .flush = wmavoice_flush,
2030 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"), 2030 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"),
2031}; 2031};
2032#endif
2033
2034int main(void)
2035{
2036 return 0;
2037}