* newdev/master:
mpegts: propagate avio EOF in read_packet()
configure: Initial support for --target-os=symbian
Fixed-point FFT and MDCT
Include dependencies for test programs
ac3enc: simplify sym_quant()
flvdec: read index stored in the 'keyframes' tag.
mov: Add support for zero-sized stsc runs.
Merged-by: Michael Niedermayer <michaelni@gmx.at>
| ... | ... |
@@ -89,7 +89,7 @@ FFLDFLAGS := $(addprefix -L$(BUILD_ROOT)/lib,$(ALLFFLIBS)) $(LDFLAGS) |
| 89 | 89 |
|
| 90 | 90 |
EXAMPLES := $(addprefix $(SUBDIR),$(addsuffix -example$(EXESUF),$(EXAMPLES))) |
| 91 | 91 |
OBJS := $(addprefix $(SUBDIR),$(sort $(OBJS))) |
| 92 |
-TESTOBJS := $(addprefix $(SUBDIR),$(TESTOBJS)) |
|
| 92 |
+TESTOBJS := $(addprefix $(SUBDIR),$(TESTOBJS) $(TESTPROGS:%=%-test.o)) |
|
| 93 | 93 |
TESTPROGS := $(addprefix $(SUBDIR),$(addsuffix -test$(EXESUF),$(TESTPROGS))) |
| 94 | 94 |
HOSTOBJS := $(addprefix $(SUBDIR),$(addsuffix .o,$(HOSTPROGS))) |
| 95 | 95 |
HOSTPROGS := $(addprefix $(SUBDIR),$(addsuffix $(HOSTEXESUF),$(HOSTPROGS))) |
| ... | ... |
@@ -111,4 +111,4 @@ CLEANSUFFIXES = *.d *.o *~ *.ho *.map *.ver |
| 111 | 111 |
DISTCLEANSUFFIXES = *.pc |
| 112 | 112 |
LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp |
| 113 | 113 |
|
| 114 |
--include $(wildcard $(OBJS:.o=.d)) |
|
| 114 |
+-include $(wildcard $(OBJS:.o=.d) $(TESTOBJS:.o=.d)) |
| ... | ... |
@@ -1845,7 +1845,7 @@ set_default host_cc |
| 1845 | 1845 |
|
| 1846 | 1846 |
exesuf() {
|
| 1847 | 1847 |
case $1 in |
| 1848 |
- mingw32*|cygwin*|*-dos|freedos|opendos|os/2*) echo .exe ;; |
|
| 1848 |
+ mingw32*|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;; |
|
| 1849 | 1849 |
esac |
| 1850 | 1850 |
} |
| 1851 | 1851 |
|
| ... | ... |
@@ -2506,6 +2506,11 @@ case $target_os in |
| 2506 | 2506 |
add_cppflags -D_QNX_SOURCE |
| 2507 | 2507 |
network_extralibs="-lsocket" |
| 2508 | 2508 |
;; |
| 2509 |
+ symbian) |
|
| 2510 |
+ SLIBSUF=".dll" |
|
| 2511 |
+ enable dos_paths |
|
| 2512 |
+ add_cflags --include=$sysinclude/gcce/gcce.h |
|
| 2513 |
+ ;; |
|
| 2509 | 2514 |
none) |
| 2510 | 2515 |
;; |
| 2511 | 2516 |
*) |
| ... | ... |
@@ -32,15 +32,16 @@ OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o |
| 32 | 32 |
OBJS-$(CONFIG_DCT) += dct.o |
| 33 | 33 |
OBJS-$(CONFIG_DWT) += dwt.o |
| 34 | 34 |
OBJS-$(CONFIG_DXVA2) += dxva2.o |
| 35 |
-FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o |
|
| 36 |
-OBJS-$(CONFIG_FFT) += avfft.o fft.o $(FFT-OBJS-yes) |
|
| 35 |
+FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o cos_fixed_tables.o |
|
| 36 |
+OBJS-$(CONFIG_FFT) += avfft.o fft_fixed.o fft_float.o \ |
|
| 37 |
+ $(FFT-OBJS-yes) |
|
| 37 | 38 |
OBJS-$(CONFIG_GOLOMB) += golomb.o |
| 38 | 39 |
OBJS-$(CONFIG_H264DSP) += h264dsp.o h264idct.o |
| 39 | 40 |
OBJS-$(CONFIG_H264PRED) += h264pred.o |
| 40 | 41 |
OBJS-$(CONFIG_HUFFMAN) += huffman.o |
| 41 | 42 |
OBJS-$(CONFIG_LPC) += lpc.o |
| 42 | 43 |
OBJS-$(CONFIG_LSP) += lsp.o |
| 43 |
-OBJS-$(CONFIG_MDCT) += mdct.o |
|
| 44 |
+OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o |
|
| 44 | 45 |
RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o |
| 45 | 46 |
OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) |
| 46 | 47 |
OBJS-$(CONFIG_SINEWIN) += sinewin.o |
| ... | ... |
@@ -676,6 +677,9 @@ $(SUBDIR)dct-test$(EXESUF): $(SUBDIR)dctref.o |
| 676 | 676 |
$(SUBDIR)cos_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) |
| 677 | 677 |
$(M)./$< > $@ |
| 678 | 678 |
|
| 679 |
+$(SUBDIR)cos_fixed_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) |
|
| 680 |
+ $(M)./$< cos fixed > $@ |
|
| 681 |
+ |
|
| 679 | 682 |
$(SUBDIR)sin_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) |
| 680 | 683 |
$(M)./$< sin > $@ |
| 681 | 684 |
|
| ... | ... |
@@ -1192,7 +1192,7 @@ static int compute_bit_allocation(AC3EncodeContext *s) |
| 1192 | 1192 |
*/ |
| 1193 | 1193 |
static inline int sym_quant(int c, int e, int levels) |
| 1194 | 1194 |
{
|
| 1195 |
- int v = ((((levels * c) >> (24 - e)) + 1) >> 1) + (levels >> 1); |
|
| 1195 |
+ int v = (((levels * c) >> (24 - e)) + levels) >> 1; |
|
| 1196 | 1196 |
av_assert2(v >= 0 && v < levels); |
| 1197 | 1197 |
return v; |
| 1198 | 1198 |
} |
| ... | ... |
@@ -29,14 +29,33 @@ |
| 29 | 29 |
#endif |
| 30 | 30 |
#define BITS 16 |
| 31 | 31 |
#define FLOATFMT "%.18e" |
| 32 |
+#define FIXEDFMT "%6d" |
|
| 33 |
+ |
|
| 34 |
+static int clip_f15(int v) |
|
| 35 |
+{
|
|
| 36 |
+ return v < -32767 ? -32767 : |
|
| 37 |
+ v > 32767 ? 32767 : |
|
| 38 |
+ v; |
|
| 39 |
+} |
|
| 40 |
+ |
|
| 41 |
+static void printval(double val, int fixed) |
|
| 42 |
+{
|
|
| 43 |
+ if (fixed) |
|
| 44 |
+ printf(" "FIXEDFMT",", clip_f15(lrint(val * (double)(1<<15))));
|
|
| 45 |
+ else |
|
| 46 |
+ printf(" "FLOATFMT",", val);
|
|
| 47 |
+ |
|
| 48 |
+} |
|
| 32 | 49 |
|
| 33 | 50 |
int main(int argc, char *argv[]) |
| 34 | 51 |
{
|
| 35 | 52 |
int i, j; |
| 36 |
- int do_sin = argc == 2 && !strcmp(argv[1], "sin"); |
|
| 53 |
+ int do_sin = argc > 1 && !strcmp(argv[1], "sin"); |
|
| 54 |
+ int fixed = argc > 2 && !strcmp(argv[2], "fixed"); |
|
| 37 | 55 |
double (*func)(double) = do_sin ? sin : cos; |
| 38 | 56 |
|
| 39 | 57 |
printf("/* This file was generated by libavcodec/costablegen */\n");
|
| 58 |
+ printf("#define CONFIG_FFT_FLOAT %d\n", !fixed);
|
|
| 40 | 59 |
printf("#include \"libavcodec/%s\"\n", do_sin ? "rdft.h" : "fft.h");
|
| 41 | 60 |
for (i = 4; i <= BITS; i++) {
|
| 42 | 61 |
int m = 1 << i; |
| ... | ... |
@@ -46,11 +65,12 @@ int main(int argc, char *argv[]) |
| 46 | 46 |
int idx = j > m/4 ? m/2 - j : j; |
| 47 | 47 |
if (do_sin && j >= m/4) |
| 48 | 48 |
idx = m/4 - j; |
| 49 |
- printf(" "FLOATFMT",", func(idx*freq));
|
|
| 49 |
+ printval(func(idx*freq), fixed); |
|
| 50 | 50 |
if ((j & 3) == 3) |
| 51 | 51 |
printf("\n ");
|
| 52 | 52 |
} |
| 53 |
- printf(" "FLOATFMT"\n};\n", func(do_sin ? -(m/4 - 1)*freq : freq));
|
|
| 53 |
+ printval(func(do_sin ? -(m/4 - 1)*freq : freq), fixed); |
|
| 54 |
+ printf("\n};\n");
|
|
| 54 | 55 |
} |
| 55 | 56 |
return 0; |
| 56 | 57 |
} |
| 57 | 58 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,67 @@ |
| 0 |
+/* |
|
| 1 |
+ * This file is part of FFmpeg. |
|
| 2 |
+ * |
|
| 3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 5 |
+ * License as published by the Free Software Foundation; either |
|
| 6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 11 |
+ * Lesser General Public License for more details. |
|
| 12 |
+ * |
|
| 13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 16 |
+ */ |
|
| 17 |
+ |
|
| 18 |
+#ifndef AVCODEC_FFT_INTERNAL_H |
|
| 19 |
+#define AVCODEC_FFT_INTERNAL_H |
|
| 20 |
+ |
|
| 21 |
+#if CONFIG_FFT_FLOAT |
|
| 22 |
+ |
|
| 23 |
+#define FIX15(v) (v) |
|
| 24 |
+#define sqrthalf (float)M_SQRT1_2 |
|
| 25 |
+ |
|
| 26 |
+#define BF(x, y, a, b) do { \
|
|
| 27 |
+ x = a - b; \ |
|
| 28 |
+ y = a + b; \ |
|
| 29 |
+ } while (0) |
|
| 30 |
+ |
|
| 31 |
+#define CMUL(dre, dim, are, aim, bre, bim) do { \
|
|
| 32 |
+ (dre) = (are) * (bre) - (aim) * (bim); \ |
|
| 33 |
+ (dim) = (are) * (bim) + (aim) * (bre); \ |
|
| 34 |
+ } while (0) |
|
| 35 |
+ |
|
| 36 |
+#else |
|
| 37 |
+ |
|
| 38 |
+#include "libavutil/intmath.h" |
|
| 39 |
+#include "mathops.h" |
|
| 40 |
+ |
|
| 41 |
+#define SCALE_FLOAT(a, bits) lrint((a) * (double)(1 << (bits))) |
|
| 42 |
+#define FIX15(a) av_clip(SCALE_FLOAT(a, 15), -32767, 32767) |
|
| 43 |
+ |
|
| 44 |
+#define sqrthalf ((int16_t)((1<<15)*M_SQRT1_2)) |
|
| 45 |
+ |
|
| 46 |
+#define BF(x, y, a, b) do { \
|
|
| 47 |
+ x = (a - b) >> 1; \ |
|
| 48 |
+ y = (a + b) >> 1; \ |
|
| 49 |
+ } while (0) |
|
| 50 |
+ |
|
| 51 |
+#define CMUL(dre, dim, are, aim, bre, bim) do { \
|
|
| 52 |
+ (dre) = (MUL16(are, bre) - MUL16(aim, bim)) >> 15; \ |
|
| 53 |
+ (dim) = (MUL16(are, bim) + MUL16(aim, bre)) >> 15; \ |
|
| 54 |
+ } while (0) |
|
| 55 |
+ |
|
| 56 |
+#endif /* CONFIG_FFT_FLOAT */ |
|
| 57 |
+ |
|
| 58 |
+#define ff_imdct_calc_c FFT_NAME(ff_imdct_calc_c) |
|
| 59 |
+#define ff_imdct_half_c FFT_NAME(ff_imdct_half_c) |
|
| 60 |
+#define ff_mdct_calc_c FFT_NAME(ff_mdct_calc_c) |
|
| 61 |
+ |
|
| 62 |
+void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); |
|
| 63 |
+void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input); |
|
| 64 |
+void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); |
|
| 65 |
+ |
|
| 66 |
+#endif /* AVCODEC_FFT_INTERNAL_H */ |
| ... | ... |
@@ -30,6 +30,7 @@ |
| 30 | 30 |
#include <string.h> |
| 31 | 31 |
#include "libavutil/mathematics.h" |
| 32 | 32 |
#include "fft.h" |
| 33 |
+#include "fft-internal.h" |
|
| 33 | 34 |
|
| 34 | 35 |
/* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ |
| 35 | 36 |
#if !CONFIG_HARDCODED_TABLES |
| ... | ... |
@@ -47,10 +48,21 @@ COSTABLE(16384); |
| 47 | 47 |
COSTABLE(32768); |
| 48 | 48 |
COSTABLE(65536); |
| 49 | 49 |
#endif |
| 50 |
-COSTABLE_CONST FFTSample * const ff_cos_tabs[] = {
|
|
| 50 |
+COSTABLE_CONST FFTSample * const FFT_NAME(ff_cos_tabs)[] = {
|
|
| 51 | 51 |
NULL, NULL, NULL, NULL, |
| 52 |
- ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024, |
|
| 53 |
- ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536, |
|
| 52 |
+ FFT_NAME(ff_cos_16), |
|
| 53 |
+ FFT_NAME(ff_cos_32), |
|
| 54 |
+ FFT_NAME(ff_cos_64), |
|
| 55 |
+ FFT_NAME(ff_cos_128), |
|
| 56 |
+ FFT_NAME(ff_cos_256), |
|
| 57 |
+ FFT_NAME(ff_cos_512), |
|
| 58 |
+ FFT_NAME(ff_cos_1024), |
|
| 59 |
+ FFT_NAME(ff_cos_2048), |
|
| 60 |
+ FFT_NAME(ff_cos_4096), |
|
| 61 |
+ FFT_NAME(ff_cos_8192), |
|
| 62 |
+ FFT_NAME(ff_cos_16384), |
|
| 63 |
+ FFT_NAME(ff_cos_32768), |
|
| 64 |
+ FFT_NAME(ff_cos_65536), |
|
| 54 | 65 |
}; |
| 55 | 66 |
|
| 56 | 67 |
static void ff_fft_permute_c(FFTContext *s, FFTComplex *z); |
| ... | ... |
@@ -73,9 +85,9 @@ av_cold void ff_init_ff_cos_tabs(int index) |
| 73 | 73 |
int i; |
| 74 | 74 |
int m = 1<<index; |
| 75 | 75 |
double freq = 2*M_PI/m; |
| 76 |
- FFTSample *tab = ff_cos_tabs[index]; |
|
| 76 |
+ FFTSample *tab = FFT_NAME(ff_cos_tabs)[index]; |
|
| 77 | 77 |
for(i=0; i<=m/4; i++) |
| 78 |
- tab[i] = cos(i*freq); |
|
| 78 |
+ tab[i] = FIX15(cos(i*freq)); |
|
| 79 | 79 |
for(i=1; i<m/4; i++) |
| 80 | 80 |
tab[m/2-i] = tab[i]; |
| 81 | 81 |
#endif |
| ... | ... |
@@ -107,9 +119,11 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) |
| 107 | 107 |
s->mdct_calc = ff_mdct_calc_c; |
| 108 | 108 |
#endif |
| 109 | 109 |
|
| 110 |
+#if CONFIG_FFT_FLOAT |
|
| 110 | 111 |
if (ARCH_ARM) ff_fft_init_arm(s); |
| 111 | 112 |
if (HAVE_ALTIVEC) ff_fft_init_altivec(s); |
| 112 | 113 |
if (HAVE_MMX) ff_fft_init_mmx(s); |
| 114 |
+#endif |
|
| 113 | 115 |
|
| 114 | 116 |
for(j=4; j<=nbits; j++) {
|
| 115 | 117 |
ff_init_ff_cos_tabs(j); |
| ... | ... |
@@ -144,13 +158,6 @@ av_cold void ff_fft_end(FFTContext *s) |
| 144 | 144 |
av_freep(&s->tmp_buf); |
| 145 | 145 |
} |
| 146 | 146 |
|
| 147 |
-#define sqrthalf (float)M_SQRT1_2 |
|
| 148 |
- |
|
| 149 |
-#define BF(x,y,a,b) {\
|
|
| 150 |
- x = a - b;\ |
|
| 151 |
- y = a + b;\ |
|
| 152 |
-} |
|
| 153 |
- |
|
| 154 | 147 |
#define BUTTERFLIES(a0,a1,a2,a3) {\
|
| 155 | 148 |
BF(t3, t5, t5, t1);\ |
| 156 | 149 |
BF(a2.re, a0.re, a0.re, t5);\ |
| ... | ... |
@@ -174,10 +181,8 @@ av_cold void ff_fft_end(FFTContext *s) |
| 174 | 174 |
} |
| 175 | 175 |
|
| 176 | 176 |
#define TRANSFORM(a0,a1,a2,a3,wre,wim) {\
|
| 177 |
- t1 = a2.re * wre + a2.im * wim;\ |
|
| 178 |
- t2 = a2.im * wre - a2.re * wim;\ |
|
| 179 |
- t5 = a3.re * wre - a3.im * wim;\ |
|
| 180 |
- t6 = a3.im * wre + a3.re * wim;\ |
|
| 177 |
+ CMUL(t1, t2, a2.re, a2.im, wre, -wim);\ |
|
| 178 |
+ CMUL(t5, t6, a3.re, a3.im, wre, wim);\ |
|
| 181 | 179 |
BUTTERFLIES(a0,a1,a2,a3)\ |
| 182 | 180 |
} |
| 183 | 181 |
|
| ... | ... |
@@ -193,7 +198,7 @@ av_cold void ff_fft_end(FFTContext *s) |
| 193 | 193 |
#define PASS(name)\ |
| 194 | 194 |
static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\ |
| 195 | 195 |
{\
|
| 196 |
- FFTSample t1, t2, t3, t4, t5, t6;\ |
|
| 196 |
+ FFTDouble t1, t2, t3, t4, t5, t6;\ |
|
| 197 | 197 |
int o1 = 2*n;\ |
| 198 | 198 |
int o2 = 4*n;\ |
| 199 | 199 |
int o3 = 6*n;\ |
| ... | ... |
@@ -222,12 +227,12 @@ static void fft##n(FFTComplex *z)\ |
| 222 | 222 |
fft##n2(z);\ |
| 223 | 223 |
fft##n4(z+n4*2);\ |
| 224 | 224 |
fft##n4(z+n4*3);\ |
| 225 |
- pass(z,ff_cos_##n,n4/2);\ |
|
| 225 |
+ pass(z,FFT_NAME(ff_cos_##n),n4/2);\ |
|
| 226 | 226 |
} |
| 227 | 227 |
|
| 228 | 228 |
static void fft4(FFTComplex *z) |
| 229 | 229 |
{
|
| 230 |
- FFTSample t1, t2, t3, t4, t5, t6, t7, t8; |
|
| 230 |
+ FFTDouble t1, t2, t3, t4, t5, t6, t7, t8; |
|
| 231 | 231 |
|
| 232 | 232 |
BF(t3, t1, z[0].re, z[1].re); |
| 233 | 233 |
BF(t8, t6, z[3].re, z[2].re); |
| ... | ... |
@@ -241,7 +246,7 @@ static void fft4(FFTComplex *z) |
| 241 | 241 |
|
| 242 | 242 |
static void fft8(FFTComplex *z) |
| 243 | 243 |
{
|
| 244 |
- FFTSample t1, t2, t3, t4, t5, t6, t7, t8; |
|
| 244 |
+ FFTDouble t1, t2, t3, t4, t5, t6, t7, t8; |
|
| 245 | 245 |
|
| 246 | 246 |
fft4(z); |
| 247 | 247 |
|
| ... | ... |
@@ -262,7 +267,9 @@ static void fft8(FFTComplex *z) |
| 262 | 262 |
#if !CONFIG_SMALL |
| 263 | 263 |
static void fft16(FFTComplex *z) |
| 264 | 264 |
{
|
| 265 |
- FFTSample t1, t2, t3, t4, t5, t6; |
|
| 265 |
+ FFTDouble t1, t2, t3, t4, t5, t6; |
|
| 266 |
+ FFTSample cos_16_1 = FFT_NAME(ff_cos_16)[1]; |
|
| 267 |
+ FFTSample cos_16_3 = FFT_NAME(ff_cos_16)[3]; |
|
| 266 | 268 |
|
| 267 | 269 |
fft8(z); |
| 268 | 270 |
fft4(z+8); |
| ... | ... |
@@ -270,8 +277,8 @@ static void fft16(FFTComplex *z) |
| 270 | 270 |
|
| 271 | 271 |
TRANSFORM_ZERO(z[0],z[4],z[8],z[12]); |
| 272 | 272 |
TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf); |
| 273 |
- TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]); |
|
| 274 |
- TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]); |
|
| 273 |
+ TRANSFORM(z[1],z[5],z[9],z[13],cos_16_1,cos_16_3); |
|
| 274 |
+ TRANSFORM(z[3],z[7],z[11],z[15],cos_16_3,cos_16_1); |
|
| 275 | 275 |
} |
| 276 | 276 |
#else |
| 277 | 277 |
DECL_FFT(16,8,4) |
| ... | ... |
@@ -22,11 +22,37 @@ |
| 22 | 22 |
#ifndef AVCODEC_FFT_H |
| 23 | 23 |
#define AVCODEC_FFT_H |
| 24 | 24 |
|
| 25 |
+#ifndef CONFIG_FFT_FLOAT |
|
| 26 |
+#define CONFIG_FFT_FLOAT 1 |
|
| 27 |
+#endif |
|
| 28 |
+ |
|
| 25 | 29 |
#include <stdint.h> |
| 26 | 30 |
#include "config.h" |
| 27 | 31 |
#include "libavutil/mem.h" |
| 32 |
+ |
|
| 33 |
+#if CONFIG_FFT_FLOAT |
|
| 34 |
+ |
|
| 28 | 35 |
#include "avfft.h" |
| 29 | 36 |
|
| 37 |
+#define FFT_NAME(x) x |
|
| 38 |
+ |
|
| 39 |
+typedef float FFTDouble; |
|
| 40 |
+ |
|
| 41 |
+#else |
|
| 42 |
+ |
|
| 43 |
+#define FFT_NAME(x) x ## _fixed |
|
| 44 |
+ |
|
| 45 |
+typedef int16_t FFTSample; |
|
| 46 |
+typedef int FFTDouble; |
|
| 47 |
+ |
|
| 48 |
+typedef struct FFTComplex {
|
|
| 49 |
+ int16_t re, im; |
|
| 50 |
+} FFTComplex; |
|
| 51 |
+ |
|
| 52 |
+typedef struct FFTContext FFTContext; |
|
| 53 |
+ |
|
| 54 |
+#endif /* CONFIG_FFT_FLOAT */ |
|
| 55 |
+ |
|
| 30 | 56 |
/* FFT computation */ |
| 31 | 57 |
|
| 32 | 58 |
struct FFTContext {
|
| ... | ... |
@@ -66,7 +92,7 @@ struct FFTContext {
|
| 66 | 66 |
#endif |
| 67 | 67 |
|
| 68 | 68 |
#define COSTABLE(size) \ |
| 69 |
- COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2] |
|
| 69 |
+ COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, FFT_NAME(ff_cos_##size))[size/2] |
|
| 70 | 70 |
|
| 71 | 71 |
extern COSTABLE(16); |
| 72 | 72 |
extern COSTABLE(32); |
| ... | ... |
@@ -81,7 +107,9 @@ extern COSTABLE(8192); |
| 81 | 81 |
extern COSTABLE(16384); |
| 82 | 82 |
extern COSTABLE(32768); |
| 83 | 83 |
extern COSTABLE(65536); |
| 84 |
-extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17]; |
|
| 84 |
+extern COSTABLE_CONST FFTSample* const FFT_NAME(ff_cos_tabs)[17]; |
|
| 85 |
+ |
|
| 86 |
+#define ff_init_ff_cos_tabs FFT_NAME(ff_init_ff_cos_tabs) |
|
| 85 | 87 |
|
| 86 | 88 |
/** |
| 87 | 89 |
* Initialize the cosine table in ff_cos_tabs[index] |
| ... | ... |
@@ -89,6 +117,9 @@ extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17]; |
| 89 | 89 |
*/ |
| 90 | 90 |
void ff_init_ff_cos_tabs(int index); |
| 91 | 91 |
|
| 92 |
+#define ff_fft_init FFT_NAME(ff_fft_init) |
|
| 93 |
+#define ff_fft_end FFT_NAME(ff_fft_end) |
|
| 94 |
+ |
|
| 92 | 95 |
/** |
| 93 | 96 |
* Set up a complex FFT. |
| 94 | 97 |
* @param nbits log2 of the length of the input array |
| ... | ... |
@@ -102,10 +133,10 @@ void ff_fft_init_arm(FFTContext *s); |
| 102 | 102 |
|
| 103 | 103 |
void ff_fft_end(FFTContext *s); |
| 104 | 104 |
|
| 105 |
+#define ff_mdct_init FFT_NAME(ff_mdct_init) |
|
| 106 |
+#define ff_mdct_end FFT_NAME(ff_mdct_end) |
|
| 107 |
+ |
|
| 105 | 108 |
int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale); |
| 106 |
-void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); |
|
| 107 |
-void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input); |
|
| 108 |
-void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); |
|
| 109 | 109 |
void ff_mdct_end(FFTContext *s); |
| 110 | 110 |
|
| 111 | 111 |
#endif /* AVCODEC_FFT_H */ |
| 112 | 112 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+/* |
|
| 1 |
+ * This file is part of FFmpeg. |
|
| 2 |
+ * |
|
| 3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 5 |
+ * License as published by the Free Software Foundation; either |
|
| 6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 11 |
+ * Lesser General Public License for more details. |
|
| 12 |
+ * |
|
| 13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 16 |
+ */ |
|
| 17 |
+ |
|
| 18 |
+#define CONFIG_FFT_FLOAT 0 |
|
| 19 |
+#include "fft.c" |
| 0 | 20 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+/* |
|
| 1 |
+ * This file is part of FFmpeg. |
|
| 2 |
+ * |
|
| 3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 5 |
+ * License as published by the Free Software Foundation; either |
|
| 6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 11 |
+ * Lesser General Public License for more details. |
|
| 12 |
+ * |
|
| 13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 16 |
+ */ |
|
| 17 |
+ |
|
| 18 |
+#define CONFIG_FFT_FLOAT 1 |
|
| 19 |
+#include "fft.c" |
| ... | ... |
@@ -24,12 +24,19 @@ |
| 24 | 24 |
#include "libavutil/common.h" |
| 25 | 25 |
#include "libavutil/mathematics.h" |
| 26 | 26 |
#include "fft.h" |
| 27 |
+#include "fft-internal.h" |
|
| 27 | 28 |
|
| 28 | 29 |
/** |
| 29 | 30 |
* @file |
| 30 | 31 |
* MDCT/IMDCT transforms. |
| 31 | 32 |
*/ |
| 32 | 33 |
|
| 34 |
+#if CONFIG_FFT_FLOAT |
|
| 35 |
+# define RSCALE(x) (x) |
|
| 36 |
+#else |
|
| 37 |
+# define RSCALE(x) ((x) >> 1) |
|
| 38 |
+#endif |
|
| 39 |
+ |
|
| 33 | 40 |
/** |
| 34 | 41 |
* init MDCT or IMDCT computation. |
| 35 | 42 |
*/ |
| ... | ... |
@@ -70,8 +77,8 @@ av_cold int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale) |
| 70 | 70 |
scale = sqrt(fabs(scale)); |
| 71 | 71 |
for(i=0;i<n4;i++) {
|
| 72 | 72 |
alpha = 2 * M_PI * (i + theta) / n; |
| 73 |
- s->tcos[i*tstep] = -cos(alpha) * scale; |
|
| 74 |
- s->tsin[i*tstep] = -sin(alpha) * scale; |
|
| 73 |
+ s->tcos[i*tstep] = FIX15(-cos(alpha) * scale); |
|
| 74 |
+ s->tsin[i*tstep] = FIX15(-sin(alpha) * scale); |
|
| 75 | 75 |
} |
| 76 | 76 |
return 0; |
| 77 | 77 |
fail: |
| ... | ... |
@@ -79,17 +86,6 @@ av_cold int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale) |
| 79 | 79 |
return -1; |
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 |
-/* complex multiplication: p = a * b */ |
|
| 83 |
-#define CMUL(pre, pim, are, aim, bre, bim) \ |
|
| 84 |
-{\
|
|
| 85 |
- FFTSample _are = (are);\ |
|
| 86 |
- FFTSample _aim = (aim);\ |
|
| 87 |
- FFTSample _bre = (bre);\ |
|
| 88 |
- FFTSample _bim = (bim);\ |
|
| 89 |
- (pre) = _are * _bre - _aim * _bim;\ |
|
| 90 |
- (pim) = _are * _bim + _aim * _bre;\ |
|
| 91 |
-} |
|
| 92 |
- |
|
| 93 | 82 |
/** |
| 94 | 83 |
* Compute the middle half of the inverse MDCT of size N = 2^nbits, |
| 95 | 84 |
* thus excluding the parts that can be derived by symmetry |
| ... | ... |
@@ -161,7 +157,7 @@ void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input) |
| 161 | 161 |
void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) |
| 162 | 162 |
{
|
| 163 | 163 |
int i, j, n, n8, n4, n2, n3; |
| 164 |
- FFTSample re, im; |
|
| 164 |
+ FFTDouble re, im; |
|
| 165 | 165 |
const uint16_t *revtab = s->revtab; |
| 166 | 166 |
const FFTSample *tcos = s->tcos; |
| 167 | 167 |
const FFTSample *tsin = s->tsin; |
| ... | ... |
@@ -175,13 +171,13 @@ void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) |
| 175 | 175 |
|
| 176 | 176 |
/* pre rotation */ |
| 177 | 177 |
for(i=0;i<n8;i++) {
|
| 178 |
- re = -input[2*i+n3] - input[n3-1-2*i]; |
|
| 179 |
- im = -input[n4+2*i] + input[n4-1-2*i]; |
|
| 178 |
+ re = RSCALE(-input[2*i+n3] - input[n3-1-2*i]); |
|
| 179 |
+ im = RSCALE(-input[n4+2*i] + input[n4-1-2*i]); |
|
| 180 | 180 |
j = revtab[i]; |
| 181 | 181 |
CMUL(x[j].re, x[j].im, re, im, -tcos[i], tsin[i]); |
| 182 | 182 |
|
| 183 |
- re = input[2*i] - input[n2-1-2*i]; |
|
| 184 |
- im = -(input[n2+2*i] + input[n-1-2*i]); |
|
| 183 |
+ re = RSCALE( input[2*i] - input[n2-1-2*i]); |
|
| 184 |
+ im = RSCALE(-input[n2+2*i] - input[ n-1-2*i]); |
|
| 185 | 185 |
j = revtab[n8 + i]; |
| 186 | 186 |
CMUL(x[j].re, x[j].im, re, im, -tcos[n8 + i], tsin[n8 + i]); |
| 187 | 187 |
} |
| 188 | 188 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+/* |
|
| 1 |
+ * This file is part of FFmpeg. |
|
| 2 |
+ * |
|
| 3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 5 |
+ * License as published by the Free Software Foundation; either |
|
| 6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 11 |
+ * Lesser General Public License for more details. |
|
| 12 |
+ * |
|
| 13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 16 |
+ */ |
|
| 17 |
+ |
|
| 18 |
+#define CONFIG_FFT_FLOAT 0 |
|
| 19 |
+#include "mdct.c" |
| 0 | 20 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,20 @@ |
| 0 |
+/* |
|
| 1 |
+ * This file is part of FFmpeg. |
|
| 2 |
+ * |
|
| 3 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 4 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 5 |
+ * License as published by the Free Software Foundation; either |
|
| 6 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 9 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 10 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 11 |
+ * Lesser General Public License for more details. |
|
| 12 |
+ * |
|
| 13 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 14 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 15 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 16 |
+ */ |
|
| 17 |
+ |
|
| 18 |
+#define CONFIG_FFT_FLOAT 1 |
|
| 19 |
+#include "mdct.c" |
| ... | ... |
@@ -31,6 +31,10 @@ |
| 31 | 31 |
#include "avio_internal.h" |
| 32 | 32 |
#include "flv.h" |
| 33 | 33 |
|
| 34 |
+#define KEYFRAMES_TAG "keyframes" |
|
| 35 |
+#define KEYFRAMES_TIMESTAMP_TAG "times" |
|
| 36 |
+#define KEYFRAMES_BYTEOFFSET_TAG "filepositions" |
|
| 37 |
+ |
|
| 34 | 38 |
typedef struct {
|
| 35 | 39 |
int wrong_dts; ///< wrong dts due to negative cts |
| 36 | 40 |
} FLVContext; |
| ... | ... |
@@ -125,6 +129,64 @@ static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize) {
|
| 125 | 125 |
return length; |
| 126 | 126 |
} |
| 127 | 127 |
|
| 128 |
+static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream *vstream, int64_t max_pos) {
|
|
| 129 |
+ unsigned int arraylen = 0, timeslen = 0, fileposlen = 0, i; |
|
| 130 |
+ double num_val; |
|
| 131 |
+ char str_val[256]; |
|
| 132 |
+ int64_t *times = NULL; |
|
| 133 |
+ int64_t *filepositions = NULL; |
|
| 134 |
+ int ret = 0; |
|
| 135 |
+ |
|
| 136 |
+ while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) {
|
|
| 137 |
+ int64_t* current_array; |
|
| 138 |
+ |
|
| 139 |
+ // Expect array object in context |
|
| 140 |
+ if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY) |
|
| 141 |
+ break; |
|
| 142 |
+ |
|
| 143 |
+ arraylen = avio_rb32(ioc); |
|
| 144 |
+ /* |
|
| 145 |
+ * Expect only 'times' or 'filepositions' sub-arrays in other case refuse to use such metadata |
|
| 146 |
+ * for indexing |
|
| 147 |
+ */ |
|
| 148 |
+ if (!strcmp(KEYFRAMES_TIMESTAMP_TAG, str_val) && !times) {
|
|
| 149 |
+ if (!(times = av_mallocz(sizeof(*times) * arraylen))) {
|
|
| 150 |
+ ret = AVERROR(ENOMEM); |
|
| 151 |
+ goto finish; |
|
| 152 |
+ } |
|
| 153 |
+ timeslen = arraylen; |
|
| 154 |
+ current_array = times; |
|
| 155 |
+ } else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) && !filepositions) {
|
|
| 156 |
+ if (!(filepositions = av_mallocz(sizeof(*filepositions) * arraylen))) {
|
|
| 157 |
+ ret = AVERROR(ENOMEM); |
|
| 158 |
+ goto finish; |
|
| 159 |
+ } |
|
| 160 |
+ fileposlen = arraylen; |
|
| 161 |
+ current_array = filepositions; |
|
| 162 |
+ } else // unexpected metatag inside keyframes, will not use such metadata for indexing |
|
| 163 |
+ break; |
|
| 164 |
+ |
|
| 165 |
+ for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) {
|
|
| 166 |
+ if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER) |
|
| 167 |
+ goto finish; |
|
| 168 |
+ num_val = av_int2dbl(avio_rb64(ioc)); |
|
| 169 |
+ current_array[i] = num_val; |
|
| 170 |
+ } |
|
| 171 |
+ } |
|
| 172 |
+ |
|
| 173 |
+ if (timeslen == fileposlen) |
|
| 174 |
+ for(i = 0; i < arraylen; i++) |
|
| 175 |
+ av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME); |
|
| 176 |
+ else |
|
| 177 |
+ av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n"); |
|
| 178 |
+ |
|
| 179 |
+finish: |
|
| 180 |
+ av_freep(×); |
|
| 181 |
+ av_freep(&filepositions); |
|
| 182 |
+ avio_seek(ioc, max_pos, SEEK_SET); |
|
| 183 |
+ return ret; |
|
| 184 |
+} |
|
| 185 |
+ |
|
| 128 | 186 |
static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth) {
|
| 129 | 187 |
AVCodecContext *acodec, *vcodec; |
| 130 | 188 |
AVIOContext *ioc; |
| ... | ... |
@@ -149,6 +211,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst |
| 149 | 149 |
case AMF_DATA_TYPE_OBJECT: {
|
| 150 | 150 |
unsigned int keylen; |
| 151 | 151 |
|
| 152 |
+ if (!strcmp(KEYFRAMES_TAG, key) && depth == 1) |
|
| 153 |
+ if (parse_keyframes_index(s, ioc, vstream, max_pos) < 0) |
|
| 154 |
+ return -1; |
|
| 155 |
+ |
|
| 152 | 156 |
while(avio_tell(ioc) < max_pos - 2 && (keylen = avio_rb16(ioc))) {
|
| 153 | 157 |
avio_skip(ioc, keylen); //skip key string |
| 154 | 158 |
if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0) |
| ... | ... |
@@ -1553,7 +1553,7 @@ static void mov_build_index(MOVContext *mov, AVStream *st) |
| 1553 | 1553 |
|
| 1554 | 1554 |
for (i = 0; i < sc->chunk_count; i++) {
|
| 1555 | 1555 |
current_offset = sc->chunk_offsets[i]; |
| 1556 |
- if (stsc_index + 1 < sc->stsc_count && |
|
| 1556 |
+ while (stsc_index + 1 < sc->stsc_count && |
|
| 1557 | 1557 |
i + 1 == sc->stsc_data[stsc_index + 1].first) |
| 1558 | 1558 |
stsc_index++; |
| 1559 | 1559 |
for (j = 0; j < sc->stsc_data[stsc_index].count; j++) {
|
| ... | ... |
@@ -1350,7 +1350,7 @@ static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size) |
| 1350 | 1350 |
for(;;) {
|
| 1351 | 1351 |
len = avio_read(pb, buf, TS_PACKET_SIZE); |
| 1352 | 1352 |
if (len != TS_PACKET_SIZE) |
| 1353 |
- return AVERROR(EIO); |
|
| 1353 |
+ return len < 0 ? len : AVERROR_EOF; |
|
| 1354 | 1354 |
/* check paquet sync byte */ |
| 1355 | 1355 |
if (buf[0] != 0x47) {
|
| 1356 | 1356 |
/* find a new packet start */ |