History

Merge remote-tracking branch 'qatar/master'

* qatar/master: mss3: use standard zigzag table mss3: split DSP functions that are used in MTS2(MSS4) into separate file motion-test: do not use getopt() tcp: add initial timeout limit for incoming connections configure: Change the rdtsc check to a linker check avconv: propagate fatal errors from lavfi. lavfi: add error handling to filter_samples(). fate-run: make avconv() properly deal with multiple inputs. asplit: don't leak the input buffer. af_resample: fix request_frame() behavior. af_asyncts: fix request_frame() behavior. libx264: support aspect ratio switching matroskadec: honor error_recognition when encountering unknown elements. lavr: resampling: add support for s32p, fltp, and dblp internal sample formats lavr: resampling: add filter type and Kaiser window beta to AVOptions lavr: Use AV_SAMPLE_FMT_NONE to auto-select the internal sample format lavr: mix: validate internal sample format in ff_audio_mix_init() Conflicts: ffmpeg.c ffplay.c libavcodec/libx264.c libavfilter/audio.c libavfilter/split.c libavformat/tcp.c tests/fate-run.sh

Michael Niedermayer committed 14 years ago

Commit f8911b92 parents bf53863 546774245 files · +648 −339Browse files

Unified · Split

45 files
  1. libavcodec/Makefile +1 −1
  2. libavcodec/libx264.c +3 −3
  3. libavcodec/motion-test.c +3 −9
  4. libavcodec/mss3.c +5 −103
  5. libavcodec/mss34dsp.c +114 −0
  6. libavcodec/mss34dsp.h +45 −0
  7. libavfilter/af_aconvert.c +4 −2
  8. libavfilter/af_amerge.c +3 −3
  9. libavfilter/af_amix.c +13 −9
  10. libavfilter/af_aresample.c +5 −3
  11. libavfilter/af_asetnsamples.c +3 −2
  12. libavfilter/af_ashowinfo.c +2 −2
  13. libavfilter/af_astreamsync.c +6 −3
  14. libavfilter/af_asyncts.c +31 −17
  15. libavfilter/af_atempo.c +2 −1
  16. libavfilter/af_channelmap.c +6 −4
  17. libavfilter/af_channelsplit.c +10 −5
  18. libavfilter/af_earwax.c +5 −2
  19. libavfilter/af_join.c +5 −3
  20. libavfilter/af_pan.c +4 −2
  21. libavfilter/af_resample.c +31 −14
  22. libavfilter/af_silencedetect.c +2 −2
  23. libavfilter/af_volume.c +2 −2
  24. libavfilter/asink_anullsink.c +4 −1
  25. libavfilter/audio.c +14 −12
  26. libavfilter/audio.h +5 −2
  27. libavfilter/avf_showwaves.c +2 −1
  28. libavfilter/avfilter.h +5 −1
  29. libavfilter/buffersink.c +7 −1
  30. libavfilter/buffersrc.c +3 −2
  31. libavfilter/f_settb.c +2 −2
  32. libavfilter/fifo.c +18 −8
  33. libavfilter/internal.h +5 −1
  34. libavfilter/sink_buffer.c +2 −1
  35. libavfilter/split.c +9 −5
  36. libavformat/matroskadec.c +4 −1
  37. libavformat/tcp.c +10 −1
  38. libavresample/audio_mix.c +8 −0
  39. libavresample/avresample.h +7 −0
  40. libavresample/internal.h +2 −0
  41. libavresample/options.c +6 −1
  42. libavresample/resample.c +85 −95
  43. libavresample/resample_template.c +102 −0
  44. libavresample/utils.c +36 −11
  45. tests/fate-run.sh +7 −1
libavcodec/Makefile+1−1
@@ -327,7 +327,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \ · 326 unmodified lines
327327 h263dec.o h263.o ituh263dec.o \
328328 mpeg4videodec.o
329329 OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o
330−OBJS-$(CONFIG_MSA1_DECODER) += mss3.o
330+OBJS-$(CONFIG_MSA1_DECODER) += mss3.o mss34dsp.o
331331 OBJS-$(CONFIG_MSS1_DECODER) += mss1.o
332332 OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
333333 OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o
libavcodec/libx264.c+3−3
@@ -175,10 +175,10 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, · 174 unmodified lines
175175 x4->params.b_tff = frame->top_field_first;
176176 x264_encoder_reconfig(x4->enc, &x4->params);
177177 }
178− if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den
179− || x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
178+ if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ||
179+ x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
180180 x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;
181− x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
181+ x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num;
182182 x264_encoder_reconfig(x4->enc, &x4->params);
183183 }
184184 }
libavcodec/motion-test.c+3−9
@@ -119,15 +119,9 @@ int main(int argc, char **argv) · 118 unmodified lines
119119 int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };
120120 int flags_size = HAVE_MMX2 ? 2 : 1;
121121
122− for(;;) {
123− c = getopt(argc, argv, "h");
124− if (c == -1)
125− break;
126− switch(c) {
127− case 'h':
128− help();
129− return 1;
130− }
122+ if (argc > 1) {
123+ help();
124+ return 1;
131125 }
132126
133127 printf("ffmpeg motion test\n");
libavcodec/mss3.c+5−103
@@ -26,6 +26,8 @@ · 25 unmodified lines
2626
2727 #include "avcodec.h"
2828 #include "bytestream.h"
29+#include "dsputil.h"
30+#include "mss34dsp.h"
2931
3032 #define HEADER_SIZE 27
3133
@@ -119,39 +121,6 @@ typedef struct MSS3Context { · 87 unmodified lines
119121 int hblock[16 * 16];
120122 } MSS3Context;
121123
122−static const uint8_t mss3_luma_quant[64] = {
123− 16, 11, 10, 16, 24, 40, 51, 61,
124− 12, 12, 14, 19, 26, 58, 60, 55,
125− 14, 13, 16, 24, 40, 57, 69, 56,
126− 14, 17, 22, 29, 51, 87, 80, 62,
127− 18, 22, 37, 56, 68, 109, 103, 77,
128− 24, 35, 55, 64, 81, 104, 113, 92,
129− 49, 64, 78, 87, 103, 121, 120, 101,
130− 72, 92, 95, 98, 112, 100, 103, 99
131−};
132−
133−static const uint8_t mss3_chroma_quant[64] = {
134− 17, 18, 24, 47, 99, 99, 99, 99,
135− 18, 21, 26, 66, 99, 99, 99, 99,
136− 24, 26, 56, 99, 99, 99, 99, 99,
137− 47, 66, 99, 99, 99, 99, 99, 99,
138− 99, 99, 99, 99, 99, 99, 99, 99,
139− 99, 99, 99, 99, 99, 99, 99, 99,
140− 99, 99, 99, 99, 99, 99, 99, 99,
141− 99, 99, 99, 99, 99, 99, 99, 99
142−};
143−
144−static const uint8_t zigzag_scan[64] = {
145− 0, 1, 8, 16, 9, 2, 3, 10,
146− 17, 24, 32, 25, 18, 11, 4, 5,
147− 12, 19, 26, 33, 40, 48, 41, 34,
148− 27, 20, 13, 6, 7, 14, 21, 28,
149− 35, 42, 49, 56, 57, 50, 43, 36,
150− 29, 22, 15, 23, 30, 37, 44, 51,
151− 58, 59, 52, 45, 38, 31, 39, 46,
152− 53, 60, 61, 54, 47, 55, 62, 63
153−};
154−
155124
156125 static void model2_reset(Model2 *m)
157126 {
@@ -578,7 +547,7 @@ static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block, · 420 unmodified lines
578547 if (!sign)
579548 val = -val;
580549
581− zz_pos = zigzag_scan[pos];
550+ zz_pos = ff_zigzag_direct[pos];
582551 block[zz_pos] = val * bc->qmat[zz_pos];
583552 pos++;
584553 }
@@ -586,58 +555,6 @@ static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block, · 1 unmodified line
586555 return pos == 64 ? 0 : -1;
587556 }
588557
589−#define DCT_TEMPLATE(blk, step, SOP, shift) \
590− const int t0 = -39409 * blk[7 * step] - 58980 * blk[1 * step]; \
591− const int t1 = 39410 * blk[1 * step] - 58980 * blk[7 * step]; \
592− const int t2 = -33410 * blk[5 * step] - 167963 * blk[3 * step]; \
593− const int t3 = 33410 * blk[3 * step] - 167963 * blk[5 * step]; \
594− const int t4 = blk[3 * step] + blk[7 * step]; \
595− const int t5 = blk[1 * step] + blk[5 * step]; \
596− const int t6 = 77062 * t4 + 51491 * t5; \
597− const int t7 = 77062 * t5 - 51491 * t4; \
598− const int t8 = 35470 * blk[2 * step] - 85623 * blk[6 * step]; \
599− const int t9 = 35470 * blk[6 * step] + 85623 * blk[2 * step]; \
600− const int tA = SOP(blk[0 * step] - blk[4 * step]); \
601− const int tB = SOP(blk[0 * step] + blk[4 * step]); \
602− \
603− blk[0 * step] = ( t1 + t6 + t9 + tB) >> shift; \
604− blk[1 * step] = ( t3 + t7 + t8 + tA) >> shift; \
605− blk[2 * step] = ( t2 + t6 - t8 + tA) >> shift; \
606− blk[3 * step] = ( t0 + t7 - t9 + tB) >> shift; \
607− blk[4 * step] = (-(t0 + t7) - t9 + tB) >> shift; \
608− blk[5 * step] = (-(t2 + t6) - t8 + tA) >> shift; \
609− blk[6 * step] = (-(t3 + t7) + t8 + tA) >> shift; \
610− blk[7 * step] = (-(t1 + t6) + t9 + tB) >> shift; \
611−
612−#define SOP_ROW(a) ((a) << 16) + 0x2000
613−#define SOP_COL(a) ((a + 32) << 16)
614−
615−static void dct_put(uint8_t *dst, int stride, int *block)
616−{
617− int i, j;
618− int *ptr;
619−
620− ptr = block;
621− for (i = 0; i < 8; i++) {
622− DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
623− ptr += 8;
624− }
625−
626− ptr = block;
627− for (i = 0; i < 8; i++) {
628− DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
629− ptr++;
630− }
631−
632− ptr = block;
633− for (j = 0; j < 8; j++) {
634− for (i = 0; i < 8; i++)
635− dst[i] = av_clip_uint8(ptr[i] + 128);
636− dst += stride;
637− ptr += 8;
638− }
639−}
640−
641558 static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc,
642559 uint8_t *dst, int stride, int block_size,
643560 int *block, int mb_x, int mb_y)
@@ -655,7 +572,7 @@ static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc, · 11 unmodified lines
655572 c->got_error = 1;
656573 return;
657574 }
658− dct_put(dst + i * 8, stride, block);
575+ ff_mss34_dct_put(dst + i * 8, stride, block);
659576 }
660577 dst += 8 * stride;
661578 }
@@ -702,14 +619,6 @@ static void decode_haar_block(RangeCoder *c, HaarBlockCoder *hc, · 40 unmodified lines
702619 }
703620 }
704621
705−static void gen_quant_mat(uint16_t *qmat, const uint8_t *ref, float scale)
706−{
707− int i;
708−
709− for (i = 0; i < 64; i++)
710− qmat[i] = (uint16_t)(ref[i] * scale + 50.0) / 100;
711−}
712−
713622 static void reset_coders(MSS3Context *ctx, int quality)
714623 {
715624 int i, j;
@@ -726,15 +635,8 @@ static void reset_coders(MSS3Context *ctx, int quality) · 10 unmodified lines
726635 for (j = 0; j < 125; j++)
727636 model_reset(&ctx->image_coder[i].vq_model[j]);
728637 if (ctx->dct_coder[i].quality != quality) {
729− float scale;
730638 ctx->dct_coder[i].quality = quality;
731− if (quality > 50)
732− scale = 200.0f - 2 * quality;
733− else
734− scale = 5000.0f / quality;
735− gen_quant_mat(ctx->dct_coder[i].qmat,
736− i ? mss3_chroma_quant : mss3_luma_quant,
737− scale);
639+ ff_mss34_gen_quant_mat(ctx->dct_coder[i].qmat, quality, !i);
738640 }
739641 memset(ctx->dct_coder[i].prev_dc, 0,
740642 sizeof(*ctx->dct_coder[i].prev_dc) *
libavcodec/mss34dsp.c+114−0
@@ -0,0 +1,114 @@
1+/*
2+ * Common stuff for some Microsoft Screen codecs
3+ * Copyright (C) 2012 Konstantin Shishkov
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+#include <stdint.h>
23+#include "libavutil/common.h"
24+#include "mss34dsp.h"
25+
26+static const uint8_t luma_quant[64] = {
27+ 16, 11, 10, 16, 24, 40, 51, 61,
28+ 12, 12, 14, 19, 26, 58, 60, 55,
29+ 14, 13, 16, 24, 40, 57, 69, 56,
30+ 14, 17, 22, 29, 51, 87, 80, 62,
31+ 18, 22, 37, 56, 68, 109, 103, 77,
32+ 24, 35, 55, 64, 81, 104, 113, 92,
33+ 49, 64, 78, 87, 103, 121, 120, 101,
34+ 72, 92, 95, 98, 112, 100, 103, 99
35+};
36+
37+static const uint8_t chroma_quant[64] = {
38+ 17, 18, 24, 47, 99, 99, 99, 99,
39+ 18, 21, 26, 66, 99, 99, 99, 99,
40+ 24, 26, 56, 99, 99, 99, 99, 99,
41+ 47, 66, 99, 99, 99, 99, 99, 99,
42+ 99, 99, 99, 99, 99, 99, 99, 99,
43+ 99, 99, 99, 99, 99, 99, 99, 99,
44+ 99, 99, 99, 99, 99, 99, 99, 99,
45+ 99, 99, 99, 99, 99, 99, 99, 99
46+};
47+
48+void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
49+{
50+ int i;
51+ const uint8_t *qsrc = luma ? luma_quant : chroma_quant;
52+
53+ if (quality >= 50) {
54+ int scale = 200 - 2 * quality;
55+
56+ for (i = 0; i < 64; i++)
57+ qmat[i] = (qsrc[i] * scale + 50) / 100;
58+ } else {
59+ for (i = 0; i < 64; i++)
60+ qmat[i] = (5000 * qsrc[i] / quality + 50) / 100;
61+ }
62+}
63+
64+#define DCT_TEMPLATE(blk, step, SOP, shift) \
65+ const int t0 = -39409 * blk[7 * step] - 58980 * blk[1 * step]; \
66+ const int t1 = 39410 * blk[1 * step] - 58980 * blk[7 * step]; \
67+ const int t2 = -33410 * blk[5 * step] - 167963 * blk[3 * step]; \
68+ const int t3 = 33410 * blk[3 * step] - 167963 * blk[5 * step]; \
69+ const int t4 = blk[3 * step] + blk[7 * step]; \
70+ const int t5 = blk[1 * step] + blk[5 * step]; \
71+ const int t6 = 77062 * t4 + 51491 * t5; \
72+ const int t7 = 77062 * t5 - 51491 * t4; \
73+ const int t8 = 35470 * blk[2 * step] - 85623 * blk[6 * step]; \
74+ const int t9 = 35470 * blk[6 * step] + 85623 * blk[2 * step]; \
75+ const int tA = SOP(blk[0 * step] - blk[4 * step]); \
76+ const int tB = SOP(blk[0 * step] + blk[4 * step]); \
77+ \
78+ blk[0 * step] = ( t1 + t6 + t9 + tB) >> shift; \
79+ blk[1 * step] = ( t3 + t7 + t8 + tA) >> shift; \
80+ blk[2 * step] = ( t2 + t6 - t8 + tA) >> shift; \
81+ blk[3 * step] = ( t0 + t7 - t9 + tB) >> shift; \
82+ blk[4 * step] = (-(t0 + t7) - t9 + tB) >> shift; \
83+ blk[5 * step] = (-(t2 + t6) - t8 + tA) >> shift; \
84+ blk[6 * step] = (-(t3 + t7) + t8 + tA) >> shift; \
85+ blk[7 * step] = (-(t1 + t6) + t9 + tB) >> shift; \
86+
87+#define SOP_ROW(a) ((a) << 16) + 0x2000
88+#define SOP_COL(a) ((a + 32) << 16)
89+
90+void ff_mss34_dct_put(uint8_t *dst, int stride, int *block)
91+{
92+ int i, j;
93+ int *ptr;
94+
95+ ptr = block;
96+ for (i = 0; i < 8; i++) {
97+ DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
98+ ptr += 8;
99+ }
100+
101+ ptr = block;
102+ for (i = 0; i < 8; i++) {
103+ DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
104+ ptr++;
105+ }
106+
107+ ptr = block;
108+ for (j = 0; j < 8; j++) {
109+ for (i = 0; i < 8; i++)
110+ dst[i] = av_clip_uint8(ptr[i] + 128);
111+ dst += stride;
112+ ptr += 8;
113+ }
114+}
libavcodec/mss34dsp.h+45−0
@@ -0,0 +1,45 @@
1+/*
2+ * Common stuff for some Microsoft Screen codecs
3+ * Copyright (C) 2012 Konstantin Shishkov
4+ *
5+ * This file is part of FFmpeg.
6+ *
7+ * FFmpeg is free software; you can redistribute it and/or
8+ * modify it under the terms of the GNU Lesser General Public
9+ * License as published by the Free Software Foundation; either
10+ * version 2.1 of the License, or (at your option) any later version.
11+ *
12+ * FFmpeg is distributed in the hope that it will be useful,
13+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+ * Lesser General Public License for more details.
16+ *
17+ * You should have received a copy of the GNU Lesser General Public
18+ * License along with FFmpeg; if not, write to the Free Software
19+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20+ */
21+
22+#ifndef AVCODEC_MSS34DSP_H
23+#define AVCODEC_MSS34DSP_H
24+
25+#include <stdint.h>
26+
27+/**
28+ * Generate quantisation matrix for given quality.
29+ *
30+ * @param qmat destination matrix
31+ * @param quality quality setting (1-100)
32+ * @param luma generate quantisation matrix for luma or chroma
33+ */
34+void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma);
35+
36+/**
37+ * Transform and output DCT block.
38+ *
39+ * @param dst output plane
40+ * @param stride output plane stride
41+ * @param block block to transform and output
42+ */
43+void ff_mss34_dct_put(uint8_t *dst, int stride, int *block);
44+
45+#endif /* AVCODEC_MSS34DSP_H */
libavfilter/af_aconvert.c+4−2
@@ -135,12 +135,13 @@ static int config_output(AVFilterLink *outlink) · 134 unmodified lines
135135 return 0;
136136 }
137137
138−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
138+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
139139 {
140140 AConvertContext *aconvert = inlink->dst->priv;
141141 const int n = insamplesref->audio->nb_samples;
142142 AVFilterLink *const outlink = inlink->dst->outputs[0];
143143 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
144+ int ret;
144145
145146 swr_convert(aconvert->swr, outsamplesref->data, n,
146147 (void *)insamplesref->data, n);
@@ -148,8 +149,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref · 1 unmodified line
148149 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);
149150 outsamplesref->audio->channel_layout = outlink->channel_layout;
150151
151− ff_filter_samples(outlink, outsamplesref);
152+ ret = ff_filter_samples(outlink, outsamplesref);
152153 avfilter_unref_buffer(insamplesref);
154+ return ret;
153155 }
154156
155157 AVFilter avfilter_af_aconvert = {
libavfilter/af_amerge.c+3−3
@@ -212,7 +212,7 @@ static inline void copy_samples(int nb_inputs, struct amerge_input in[], · 211 unmodified lines
212212 }
213213 }
214214
215−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
215+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
216216 {
217217 AVFilterContext *ctx = inlink->dst;
218218 AMergeContext *am = ctx->priv;
@@ -232,7 +232,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 13 unmodified lines
232232 for (i = 1; i < am->nb_inputs; i++)
233233 nb_samples = FFMIN(nb_samples, am->in[i].nb_samples);
234234 if (!nb_samples)
235− return;
235+ return 0;
236236
237237 outbuf = ff_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE, nb_samples);
238238 outs = outbuf->data[0];
@@ -285,7 +285,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 46 unmodified lines
285285 }
286286 }
287287 }
288− ff_filter_samples(ctx->outputs[0], outbuf);
288+ return ff_filter_samples(ctx->outputs[0], outbuf);
289289 }
290290
291291 static av_cold int init(AVFilterContext *ctx, const char *args)
libavfilter/af_amix.c+13−9
@@ -305,9 +305,7 @@ static int output_frame(AVFilterLink *outlink, int nb_samples) · 304 unmodified lines
305305 if (s->next_pts != AV_NOPTS_VALUE)
306306 s->next_pts += nb_samples;
307307
308− ff_filter_samples(outlink, out_buf);
309−
310− return 0;
308+ return ff_filter_samples(outlink, out_buf);
311309 }
312310
313311 /**
@@ -448,31 +446,37 @@ static int request_frame(AVFilterLink *outlink) · 134 unmodified lines
448446 return output_frame(outlink, available_samples);
449447 }
450448
451−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
449+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
452450 {
453451 AVFilterContext *ctx = inlink->dst;
454452 MixContext *s = ctx->priv;
455453 AVFilterLink *outlink = ctx->outputs[0];
456− int i;
454+ int i, ret = 0;
457455
458456 for (i = 0; i < ctx->nb_inputs; i++)
459457 if (ctx->inputs[i] == inlink)
460458 break;
461459 if (i >= ctx->nb_inputs) {
462460 av_log(ctx, AV_LOG_ERROR, "unknown input link\n");
463− return;
461+ ret = AVERROR(EINVAL);
462+ goto fail;
464463 }
465464
466465 if (i == 0) {
467466 int64_t pts = av_rescale_q(buf->pts, inlink->time_base,
468467 outlink->time_base);
469− frame_list_add_frame(s->frame_list, buf->audio->nb_samples, pts);
468+ ret = frame_list_add_frame(s->frame_list, buf->audio->nb_samples, pts);
469+ if (ret < 0)
470+ goto fail;
470471 }
471472
472− av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data,
473− buf->audio->nb_samples);
473+ ret = av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data,
474+ buf->audio->nb_samples);
474475
476+fail:
475477 avfilter_unref_buffer(buf);
478+
479+ return ret;
476480 }
477481
478482 static int init(AVFilterContext *ctx, const char *args)
libavfilter/af_aresample.c+5−3
@@ -168,13 +168,14 @@ static int config_output(AVFilterLink *outlink) · 167 unmodified lines
168168 return 0;
169169 }
170170
171−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
171+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
172172 {
173173 AResampleContext *aresample = inlink->dst->priv;
174174 const int n_in = insamplesref->audio->nb_samples;
175175 int n_out = n_in * aresample->ratio * 2 ;
176176 AVFilterLink *const outlink = inlink->dst->outputs[0];
177177 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out);
178+ int ret;
178179
179180
180181 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);
@@ -193,15 +194,16 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref · 12 unmodified lines
193194 if (n_out <= 0) {
194195 avfilter_unref_buffer(outsamplesref);
195196 avfilter_unref_buffer(insamplesref);
196− return;
197+ return 0;
197198 }
198199
199200 outsamplesref->audio->sample_rate = outlink->sample_rate;
200201 outsamplesref->audio->nb_samples = n_out;
201202
202− ff_filter_samples(outlink, outsamplesref);
203+ ret = ff_filter_samples(outlink, outsamplesref);
203204 aresample->req_fullfilled= 1;
204205 avfilter_unref_buffer(insamplesref);
206+ return ret;
205207 }
206208
207209 static int request_frame(AVFilterLink *outlink)
libavfilter/af_asetnsamples.c+3−2
@@ -131,7 +131,7 @@ static int push_samples(AVFilterLink *outlink) · 130 unmodified lines
131131 return nb_out_samples;
132132 }
133133
134−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
134+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
135135 {
136136 AVFilterContext *ctx = inlink->dst;
137137 ASNSContext *asns = ctx->priv;
@@ -145,7 +145,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 7 unmodified lines
145145 if (ret < 0) {
146146 av_log(ctx, AV_LOG_ERROR,
147147 "Stretching audio fifo failed, discarded %d samples\n", nb_samples);
148− return;
148+ return -1;
149149 }
150150 }
151151 av_audio_fifo_write(asns->fifo, (void **)insamples->extended_data, nb_samples);
@@ -155,6 +155,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 3 unmodified lines
155155
156156 if (av_audio_fifo_size(asns->fifo) >= asns->nb_out_samples)
157157 push_samples(outlink);
158+ return 0;
158159 }
159160
160161 static int request_frame(AVFilterLink *outlink)
libavfilter/af_ashowinfo.c+2−2
@@ -40,7 +40,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 39 unmodified lines
4040 return 0;
4141 }
4242
43−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
43+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
4444 {
4545 AVFilterContext *ctx = inlink->dst;
4646 ShowInfoContext *showinfo = ctx->priv;
@@ -83,7 +83,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) · 36 unmodified lines
8383 av_log(ctx, AV_LOG_INFO, "]\n");
8484
8585 showinfo->frame++;
86− ff_filter_samples(inlink->dst->outputs[0], samplesref);
86+ return ff_filter_samples(inlink->dst->outputs[0], samplesref);
8787 }
8888
8989 AVFilter avfilter_af_ashowinfo = {
libavfilter/af_astreamsync.c+6−3
@@ -107,11 +107,12 @@ static int config_output(AVFilterLink *outlink) · 106 unmodified lines
107107 return 0;
108108 }
109109
110−static void send_out(AVFilterContext *ctx, int out_id)
110+static int send_out(AVFilterContext *ctx, int out_id)
111111 {
112112 AStreamSyncContext *as = ctx->priv;
113113 struct buf_queue *queue = &as->queue[out_id];
114114 AVFilterBufferRef *buf = queue->buf[queue->tail];
115+ int ret;
115116
116117 queue->buf[queue->tail] = NULL;
117118 as->var_values[VAR_B1 + out_id]++;
@@ -121,11 +122,12 @@ static void send_out(AVFilterContext *ctx, int out_id) · 3 unmodified lines
121122 av_q2d(ctx->outputs[out_id]->time_base) * buf->pts;
122123 as->var_values[VAR_T1 + out_id] += buf->audio->nb_samples /
123124 (double)ctx->inputs[out_id]->sample_rate;
124− ff_filter_samples(ctx->outputs[out_id], buf);
125+ ret = ff_filter_samples(ctx->outputs[out_id], buf);
125126 queue->nb--;
126127 queue->tail = (queue->tail + 1) % QUEUE_SIZE;
127128 if (as->req[out_id])
128129 as->req[out_id]--;
130+ return ret;
129131 }
130132
131133 static void send_next(AVFilterContext *ctx)
@@ -165,7 +167,7 @@ static int request_frame(AVFilterLink *outlink) · 33 unmodified lines
165167 return 0;
166168 }
167169
168−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
170+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
169171 {
170172 AVFilterContext *ctx = inlink->dst;
171173 AStreamSyncContext *as = ctx->priv;
@@ -175,6 +177,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 3 unmodified lines
175177 insamples;
176178 as->eof &= ~(1 << id);
177179 send_next(ctx);
180+ return 0;
178181 }
179182
180183 AVFilter avfilter_af_astreamsync = {
libavfilter/af_asyncts.c+31−17
@@ -37,6 +37,9 @@ typedef struct ASyncContext { · 36 unmodified lines
3737 int resample;
3838 float min_delta_sec;
3939 int max_comp;
40+
41+ /* set by filter_samples() to signal an output frame to request_frame() */
42+ int got_output;
4043 } ASyncContext;
4144
4245 #define OFFSET(x) offsetof(ASyncContext, x)
@@ -112,9 +115,13 @@ static int request_frame(AVFilterLink *link) · 69 unmodified lines
112115 {
113116 AVFilterContext *ctx = link->src;
114117 ASyncContext *s = ctx->priv;
115− int ret = ff_request_frame(ctx->inputs[0]);
118+ int ret = 0;
116119 int nb_samples;
117120
121+ s->got_output = 0;
122+ while (ret >= 0 && !s->got_output)
123+ ret = ff_request_frame(ctx->inputs[0]);
124+
118125 /* flush the fifo */
119126 if (ret == AVERROR_EOF && (nb_samples = avresample_get_delay(s->avr))) {
120127 AVFilterBufferRef *buf = ff_get_audio_buffer(link, AV_PERM_WRITE,
@@ -124,18 +131,18 @@ static int request_frame(AVFilterLink *link) · 3 unmodified lines
124131 avresample_convert(s->avr, (void**)buf->extended_data, buf->linesize[0],
125132 nb_samples, NULL, 0, 0);
126133 buf->pts = s->pts;
127− ff_filter_samples(link, buf);
128− return 0;
134+ return ff_filter_samples(link, buf);
129135 }
130136
131137 return ret;
132138 }
133139
134−static void write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf)
140+static int write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf)
135141 {
136− avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
137− buf->linesize[0], buf->audio->nb_samples);
142+ int ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
143+ buf->linesize[0], buf->audio->nb_samples);
138144 avfilter_unref_buffer(buf);
145+ return ret;
139146 }
140147
141148 /* get amount of data currently buffered, in samples */
@@ -144,7 +151,7 @@ static int64_t get_delay(ASyncContext *s) · 2 unmodified lines
144151 return avresample_available(s->avr) + avresample_get_delay(s->avr);
145152 }
146153
147−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
154+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
148155 {
149156 AVFilterContext *ctx = inlink->dst;
150157 ASyncContext *s = ctx->priv;
@@ -152,7 +159,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 1 unmodified line
152159 int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);
153160 int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :
154161 av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
155− int out_size;
162+ int out_size, ret;
156163 int64_t delta;
157164
158165 /* buffer data until we get the first timestamp */
@@ -160,14 +167,12 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 1 unmodified line
160167 if (pts != AV_NOPTS_VALUE) {
161168 s->pts = pts - get_delay(s);
162169 }
163− write_to_fifo(s, buf);
164− return;
170+ return write_to_fifo(s, buf);
165171 }
166172
167173 /* now wait for the next timestamp */
168174 if (pts == AV_NOPTS_VALUE) {
169− write_to_fifo(s, buf);
170− return;
175+ return write_to_fifo(s, buf);
171176 }
172177
173178 /* when we have two timestamps, compute how many samples would we have
@@ -190,8 +195,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 16 unmodified lines
190195 if (out_size > 0) {
191196 AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,
192197 out_size);
193− if (!buf_out)
194− return;
198+ if (!buf_out) {
199+ ret = AVERROR(ENOMEM);
200+ goto fail;
201+ }
195202
196203 avresample_read(s->avr, (void**)buf_out->extended_data, out_size);
197204 buf_out->pts = s->pts;
@@ -200,7 +207,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 2 unmodified lines
200207 av_samples_set_silence(buf_out->extended_data, out_size - delta,
201208 delta, nb_channels, buf->format);
202209 }
203− ff_filter_samples(outlink, buf_out);
210+ ret = ff_filter_samples(outlink, buf_out);
211+ if (ret < 0)
212+ goto fail;
213+ s->got_output = 1;
204214 } else {
205215 av_log(ctx, AV_LOG_WARNING, "Non-monotonous timestamps, dropping "
206216 "whole buffer.\n");
@@ -210,9 +220,13 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 3 unmodified lines
210220 avresample_read(s->avr, NULL, avresample_available(s->avr));
211221
212222 s->pts = pts - avresample_get_delay(s->avr);
213− avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
214− buf->linesize[0], buf->audio->nb_samples);
223+ ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
224+ buf->linesize[0], buf->audio->nb_samples);
225+
226+fail:
215227 avfilter_unref_buffer(buf);
228+
229+ return ret;
216230 }
217231
218232 AVFilter avfilter_af_asyncts = {
libavfilter/af_atempo.c+2−1
@@ -1040,7 +1040,7 @@ static void push_samples(ATempoContext *atempo, · 1039 unmodified lines
10401040 atempo->nsamples_out += n_out;
10411041 }
10421042
1043−static void filter_samples(AVFilterLink *inlink,
1043+static int filter_samples(AVFilterLink *inlink,
10441044 AVFilterBufferRef *src_buffer)
10451045 {
10461046 AVFilterContext *ctx = inlink->dst;
@@ -1074,6 +1074,7 @@ static void filter_samples(AVFilterLink *inlink, · 27 unmodified lines
10741074
10751075 atempo->nsamples_in += n_in;
10761076 avfilter_unref_bufferp(&src_buffer);
1077+ return 0;
10771078 }
10781079
10791080 static int request_frame(AVFilterLink *outlink)
libavfilter/af_channelmap.c+6−4
@@ -313,7 +313,7 @@ static int channelmap_query_formats(AVFilterContext *ctx) · 312 unmodified lines
313313 return 0;
314314 }
315315
316−static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
316+static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
317317 {
318318 AVFilterContext *ctx = inlink->dst;
319319 AVFilterLink *outlink = ctx->outputs[0];
@@ -330,8 +330,10 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b · 10 unmodified lines
330330 if (nch_out > FF_ARRAY_ELEMS(buf->data)) {
331331 uint8_t **new_extended_data =
332332 av_mallocz(nch_out * sizeof(*buf->extended_data));
333− if (!new_extended_data)
334− return;
333+ if (!new_extended_data) {
334+ avfilter_unref_buffer(buf);
335+ return AVERROR(ENOMEM);
336+ }
335337 if (buf->extended_data == buf->data) {
336338 buf->extended_data = new_extended_data;
337339 } else {
@@ -353,7 +355,7 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b · 15 unmodified lines
353355 memcpy(buf->data, buf->extended_data,
354356 FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));
355357
356− ff_filter_samples(outlink, buf);
358+ return ff_filter_samples(outlink, buf);
357359 }
358360
359361 static int channelmap_config_input(AVFilterLink *inlink)
libavfilter/af_channelsplit.c+10−5
@@ -105,24 +105,29 @@ static int query_formats(AVFilterContext *ctx) · 104 unmodified lines
105105 return 0;
106106 }
107107
108−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
108+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
109109 {
110110 AVFilterContext *ctx = inlink->dst;
111− int i;
111+ int i, ret = 0;
112112
113113 for (i = 0; i < ctx->nb_outputs; i++) {
114114 AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE);
115115
116− if (!buf_out)
117− return;
116+ if (!buf_out) {
117+ ret = AVERROR(ENOMEM);
118+ break;
119+ }
118120
119121 buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i];
120122 buf_out->audio->channel_layout =
121123 av_channel_layout_extract_channel(buf->audio->channel_layout, i);
122124
123− ff_filter_samples(ctx->outputs[i], buf_out);
125+ ret = ff_filter_samples(ctx->outputs[i], buf_out);
126+ if (ret < 0)
127+ break;
124128 }
125129 avfilter_unref_buffer(buf);
130+ return ret;
126131 }
127132
128133 AVFilter avfilter_af_channelsplit = {
libavfilter/af_earwax.c+5−2
@@ -120,13 +120,15 @@ static inline int16_t *scalarproduct(const int16_t *in, const int16_t *endin, in · 119 unmodified lines
120120 return out;
121121 }
122122
123−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
123+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
124124 {
125125 AVFilterLink *outlink = inlink->dst->outputs[0];
126126 int16_t *taps, *endin, *in, *out;
127127 AVFilterBufferRef *outsamples =
128128 ff_get_audio_buffer(inlink, AV_PERM_WRITE,
129129 insamples->audio->nb_samples);
130+ int ret;
131+
130132 avfilter_copy_buffer_ref_props(outsamples, insamples);
131133
132134 taps = ((EarwaxContext *)inlink->dst->priv)->taps;
@@ -144,8 +146,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 11 unmodified lines
144146 // save part of input for next round
145147 memcpy(taps, endin, NUMTAPS * sizeof(*taps));
146148
147− ff_filter_samples(outlink, outsamples);
149+ ret = ff_filter_samples(outlink, outsamples);
148150 avfilter_unref_buffer(insamples);
151+ return ret;
149152 }
150153
151154 AVFilter avfilter_af_earwax = {
libavfilter/af_join.c+5−3
@@ -92,7 +92,7 @@ static const AVClass join_class = { · 91 unmodified lines
9292 .version = LIBAVUTIL_VERSION_INT,
9393 };
9494
95−static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
95+static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
9696 {
9797 AVFilterContext *ctx = link->dst;
9898 JoinContext *s = ctx->priv;
@@ -104,6 +104,8 @@ static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) · 5 unmodified lines
104104 av_assert0(i < ctx->nb_inputs);
105105 av_assert0(!s->input_frames[i]);
106106 s->input_frames[i] = buf;
107+
108+ return 0;
107109 }
108110
109111 static int parse_maps(AVFilterContext *ctx)
@@ -468,11 +470,11 @@ static int join_request_frame(AVFilterLink *outlink) · 358 unmodified lines
468470 priv->nb_in_buffers = ctx->nb_inputs;
469471 buf->buf->priv = priv;
470472
471− ff_filter_samples(outlink, buf);
473+ ret = ff_filter_samples(outlink, buf);
472474
473475 memset(s->input_frames, 0, sizeof(*s->input_frames) * ctx->nb_inputs);
474476
475− return 0;
477+ return ret;
476478
477479 fail:
478480 avfilter_unref_buffer(buf);
libavfilter/af_pan.c+4−2
@@ -343,8 +343,9 @@ static int config_props(AVFilterLink *link) · 342 unmodified lines
343343 return 0;
344344 }
345345
346−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
346+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
347347 {
348+ int ret;
348349 int n = insamples->audio->nb_samples;
349350 AVFilterLink *const outlink = inlink->dst->outputs[0];
350351 AVFilterBufferRef *outsamples = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
@@ -354,8 +355,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 3 unmodified lines
354355 avfilter_copy_buffer_ref_props(outsamples, insamples);
355356 outsamples->audio->channel_layout = outlink->channel_layout;
356357
357− ff_filter_samples(outlink, outsamples);
358+ ret = ff_filter_samples(outlink, outsamples);
358359 avfilter_unref_buffer(insamples);
360+ return ret;
359361 }
360362
361363 static av_cold void uninit(AVFilterContext *ctx)
libavfilter/af_resample.c+31−14
@@ -38,6 +38,9 @@ typedef struct ResampleContext { · 37 unmodified lines
3838 AVAudioResampleContext *avr;
3939
4040 int64_t next_pts;
41+
42+ /* set by filter_samples() to signal an output frame to request_frame() */
43+ int got_output;
4144 } ResampleContext;
4245
4346 static av_cold void uninit(AVFilterContext *ctx)
@@ -102,12 +105,6 @@ static int config_output(AVFilterLink *outlink) · 58 unmodified lines
102105 av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);
103106 av_opt_set_int(s->avr, "out_sample_rate", outlink->sample_rate, 0);
104107
105− /* if both the input and output formats are s16 or u8, use s16 as
106− the internal sample format */
107− if (av_get_bytes_per_sample(inlink->format) <= 2 &&
108− av_get_bytes_per_sample(outlink->format) <= 2)
109− av_opt_set_int(s->avr, "internal_sample_fmt", AV_SAMPLE_FMT_S16P, 0);
110−
111108 if ((ret = avresample_open(s->avr)) < 0)
112109 return ret;
113110
@@ -130,7 +127,11 @@ static int request_frame(AVFilterLink *outlink) · 16 unmodified lines
130127 {
131128 AVFilterContext *ctx = outlink->src;
132129 ResampleContext *s = ctx->priv;
133− int ret = ff_request_frame(ctx->inputs[0]);
130+ int ret = 0;
131+
132+ s->got_output = 0;
133+ while (ret >= 0 && !s->got_output)
134+ ret = ff_request_frame(ctx->inputs[0]);
134135
135136 /* flush the lavr delay buffer */
136137 if (ret == AVERROR_EOF && s->avr) {
@@ -156,21 +157,21 @@ static int request_frame(AVFilterLink *outlink) · 19 unmodified lines
156157 }
157158
158159 buf->pts = s->next_pts;
159− ff_filter_samples(outlink, buf);
160− return 0;
160+ return ff_filter_samples(outlink, buf);
161161 }
162162 return ret;
163163 }
164164
165−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
165+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
166166 {
167167 AVFilterContext *ctx = inlink->dst;
168168 ResampleContext *s = ctx->priv;
169169 AVFilterLink *outlink = ctx->outputs[0];
170+ int ret;
170171
171172 if (s->avr) {
172173 AVFilterBufferRef *buf_out;
173− int delay, nb_samples, ret;
174+ int delay, nb_samples;
174175
175176 /* maximum possible samples lavr can output */
176177 delay = avresample_get_delay(s->avr);
@@ -179,10 +180,19 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 2 unmodified lines
179180 AV_ROUND_UP);
180181
181182 buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);
183+ if (!buf_out) {
184+ ret = AVERROR(ENOMEM);
185+ goto fail;
186+ }
187+
182188 ret = avresample_convert(s->avr, (void**)buf_out->extended_data,
183189 buf_out->linesize[0], nb_samples,
184190 (void**)buf->extended_data, buf->linesize[0],
185191 buf->audio->nb_samples);
192+ if (ret < 0) {
193+ avfilter_unref_buffer(buf_out);
194+ goto fail;
195+ }
186196
187197 av_assert0(!avresample_available(s->avr));
188198
@@ -208,11 +218,18 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 19 unmodified lines
208218
209219 s->next_pts = buf_out->pts + buf_out->audio->nb_samples;
210220
211− ff_filter_samples(outlink, buf_out);
221+ ret = ff_filter_samples(outlink, buf_out);
222+ s->got_output = 1;
212223 }
224+
225+fail:
213226 avfilter_unref_buffer(buf);
214− } else
215− ff_filter_samples(outlink, buf);
227+ } else {
228+ ret = ff_filter_samples(outlink, buf);
229+ s->got_output = 1;
230+ }
231+
232+ return ret;
216233 }
217234
218235 AVFilter avfilter_af_resample = {
libavfilter/af_silencedetect.c+2−2
@@ -78,7 +78,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 77 unmodified lines
7878 return 0;
7979 }
8080
81−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
81+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
8282 {
8383 int i;
8484 SilenceDetectContext *silence = inlink->dst->priv;
@@ -118,7 +118,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 33 unmodified lines
118118 }
119119 }
120120
121− ff_filter_samples(inlink->dst->outputs[0], insamples);
121+ return ff_filter_samples(inlink->dst->outputs[0], insamples);
122122 }
123123
124124 static int query_formats(AVFilterContext *ctx)
libavfilter/af_volume.c+2−2
@@ -110,7 +110,7 @@ static int query_formats(AVFilterContext *ctx) · 109 unmodified lines
110110 return 0;
111111 }
112112
113−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
113+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
114114 {
115115 VolumeContext *vol = inlink->dst->priv;
116116 AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -169,7 +169,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 52 unmodified lines
169169 }
170170 }
171171 }
172− ff_filter_samples(outlink, insamples);
172+ return ff_filter_samples(outlink, insamples);
173173 }
174174
175175 AVFilter avfilter_af_volume = {
libavfilter/asink_anullsink.c+4−1
@@ -21,7 +21,10 @@ · 20 unmodified lines
2121 #include "avfilter.h"
2222 #include "internal.h"
2323
24−static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { }
24+static int null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
25+{
26+ return 0;
27+}
2528
2629 AVFilter avfilter_asink_anullsink = {
2730 .name = "anullsink",
libavfilter/audio.c+14−12
@@ -150,19 +150,19 @@ fail: · 149 unmodified lines
150150 return NULL;
151151 }
152152
153−static void default_filter_samples(AVFilterLink *link,
154− AVFilterBufferRef *samplesref)
153+static int default_filter_samples(AVFilterLink *link,
154+ AVFilterBufferRef *samplesref)
155155 {
156− ff_filter_samples(link->dst->outputs[0], samplesref);
156+ return ff_filter_samples(link->dst->outputs[0], samplesref);
157157 }
158158
159−void ff_filter_samples_framed(AVFilterLink *link,
160− AVFilterBufferRef *samplesref)
159+int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref)
161160 {
162− void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
161+ int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
163162 AVFilterPad *dst = link->dstpad;
164163 int64_t pts;
165164 AVFilterBufferRef *buf_out;
165+ int ret;
166166
167167 FF_TPRINTF_START(NULL, filter_samples); ff_tlog_link(NULL, link, 1);
168168
@@ -193,21 +193,22 @@ void ff_filter_samples_framed(AVFilterLink *link, · 24 unmodified lines
193193
194194 link->cur_buf = buf_out;
195195 pts = buf_out->pts;
196− filter_samples(link, buf_out);
196+ ret = filter_samples(link, buf_out);
197197 ff_update_link_current_pts(link, pts);
198+ return ret;
198199 }
199200
200−void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
201+int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
201202 {
202203 int insamples = samplesref->audio->nb_samples, inpos = 0, nb_samples;
203204 AVFilterBufferRef *pbuf = link->partial_buf;
204205 int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
206+ int ret = 0;
205207
206208 if (!link->min_samples ||
207209 (!pbuf &&
208210 insamples >= link->min_samples && insamples <= link->max_samples)) {
209− ff_filter_samples_framed(link, samplesref);
210− return;
211+ return ff_filter_samples_framed(link, samplesref);
211212 }
212213 /* Handle framing (min_samples, max_samples) */
213214 while (insamples) {
@@ -218,7 +219,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 4 unmodified lines
218219 if (!pbuf) {
219220 av_log(link->dst, AV_LOG_WARNING,
220221 "Samples dropped due to memory allocation failure.\n");
221− return;
222+ return 0;
222223 }
223224 avfilter_copy_buffer_ref_props(pbuf, samplesref);
224225 pbuf->pts = samplesref->pts +
@@ -234,10 +235,11 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 9 unmodified lines
234235 insamples -= nb_samples;
235236 pbuf->audio->nb_samples += nb_samples;
236237 if (pbuf->audio->nb_samples >= link->min_samples) {
237− ff_filter_samples_framed(link, pbuf);
238+ ret = ff_filter_samples_framed(link, pbuf);
238239 pbuf = NULL;
239240 }
240241 }
241242 avfilter_unref_buffer(samplesref);
242243 link->partial_buf = pbuf;
244+ return ret;
243245 }
libavfilter/audio.h+5−2
@@ -70,14 +70,17 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 69 unmodified lines
7070 * @param samplesref a reference to the buffer of audio samples being sent. The
7171 * receiving filter will free this reference when it no longer
7272 * needs it or pass it on to the next filter.
73+ *
74+ * @return >= 0 on success, a negative AVERROR on error. The receiving filter
75+ * is responsible for unreferencing samplesref in case of error.
7376 */
74−void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
77+int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
7578
7679 /**
7780 * Send a buffer of audio samples to the next link, without checking
7881 * min_samples.
7982 */
80−void ff_filter_samples_framed(AVFilterLink *link,
83+int ff_filter_samples_framed(AVFilterLink *link,
8184 AVFilterBufferRef *samplesref);
8285
8386 #endif /* AVFILTER_AUDIO_H */
libavfilter/avf_showwaves.c+2−1
@@ -180,7 +180,7 @@ static int request_frame(AVFilterLink *outlink) · 179 unmodified lines
180180
181181 #define MAX_INT16 ((1<<15) -1)
182182
183−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
183+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
184184 {
185185 AVFilterContext *ctx = inlink->dst;
186186 AVFilterLink *outlink = ctx->outputs[0];
@@ -225,6 +225,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 38 unmodified lines
225225 }
226226
227227 avfilter_unref_buffer(insamples);
228+ return 0;
228229 }
229230
230231 AVFilter avfilter_avf_showwaves = {
libavfilter/avfilter.h+5−1
@@ -301,8 +301,12 @@ struct AVFilterPad { · 300 unmodified lines
301301 * and should do its processing.
302302 *
303303 * Input audio pads only.
304+ *
305+ * @return >= 0 on success, a negative AVERROR on error. This function
306+ * must ensure that samplesref is properly unreferenced on error if it
307+ * hasn't been passed on to another filter.
304308 */
305− void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
309+ int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
306310
307311 /**
308312 * Frame poll callback. This returns the number of immediately available
libavfilter/buffersink.c+7−1
@@ -56,6 +56,12 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *buf) · 55 unmodified lines
5656 link->cur_buf = NULL;
5757 };
5858
59+static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
60+{
61+ start_frame(link, buf);
62+ return 0;
63+}
64+
5965 int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
6066 {
6167 BufferSinkContext *s = ctx->priv;
@@ -160,7 +166,7 @@ AVFilter avfilter_asink_abuffer = { · 98 unmodified lines
160166
161167 .inputs = (AVFilterPad[]) {{ .name = "default",
162168 .type = AVMEDIA_TYPE_AUDIO,
163− .filter_samples = start_frame,
169+ .filter_samples = filter_samples,
164170 .min_perms = AV_PERM_READ,
165171 .needs_fifo = 1 },
166172 { .name = NULL }},
libavfilter/buffersrc.c+3−2
@@ -408,6 +408,7 @@ static int request_frame(AVFilterLink *link) · 407 unmodified lines
408408 {
409409 BufferSourceContext *c = link->src->priv;
410410 AVFilterBufferRef *buf;
411+ int ret = 0;
411412
412413 if (!av_fifo_size(c->fifo)) {
413414 if (c->eof)
@@ -424,7 +425,7 @@ static int request_frame(AVFilterLink *link) · 10 unmodified lines
424425 ff_end_frame(link);
425426 break;
426427 case AVMEDIA_TYPE_AUDIO:
427− ff_filter_samples(link, avfilter_ref_buffer(buf, ~0));
428+ ret = ff_filter_samples(link, avfilter_ref_buffer(buf, ~0));
428429 break;
429430 default:
430431 return AVERROR(EINVAL);
@@ -432,7 +433,7 @@ static int request_frame(AVFilterLink *link) · 1 unmodified line
432433
433434 avfilter_unref_buffer(buf);
434435
435− return 0;
436+ return ret;
436437 }
437438
438439 static int poll_frame(AVFilterLink *link)
libavfilter/f_settb.c+2−2
@@ -117,7 +117,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) · 116 unmodified lines
117117 ff_start_frame(outlink, picref2);
118118 }
119119
120−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
120+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
121121 {
122122 AVFilterContext *ctx = inlink->dst;
123123 AVFilterLink *outlink = ctx->outputs[0];
@@ -132,7 +132,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 8 unmodified lines
132132 avfilter_unref_buffer(insamples);
133133 }
134134
135− ff_filter_samples(outlink, outsamples);
135+ return ff_filter_samples(outlink, outsamples);
136136 }
137137
138138 #if CONFIG_SETTB_FILTER
libavfilter/fifo.c+18−8
@@ -72,13 +72,25 @@ static av_cold void uninit(AVFilterContext *ctx) · 71 unmodified lines
7272 avfilter_unref_buffer(fifo->buf_out);
7373 }
7474
75−static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
75+static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
7676 {
7777 FifoContext *fifo = inlink->dst->priv;
7878
7979 fifo->last->next = av_mallocz(sizeof(Buf));
80+ if (!fifo->last->next) {
81+ avfilter_unref_buffer(buf);
82+ return AVERROR(ENOMEM);
83+ }
84+
8085 fifo->last = fifo->last->next;
8186 fifo->last->buf = buf;
87+
88+ return 0;
89+}
90+
91+static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
92+{
93+ add_to_queue(inlink, buf);
8294 }
8395
8496 static void queue_pop(FifoContext *s)
@@ -210,15 +222,13 @@ static int return_audio_frame(AVFilterContext *ctx) · 125 unmodified lines
210222 buf_out = s->buf_out;
211223 s->buf_out = NULL;
212224 }
213− ff_filter_samples(link, buf_out);
214−
215− return 0;
225+ return ff_filter_samples(link, buf_out);
216226 }
217227
218228 static int request_frame(AVFilterLink *outlink)
219229 {
220230 FifoContext *fifo = outlink->src->priv;
221− int ret;
231+ int ret = 0;
222232
223233 if (!fifo->root.next) {
224234 if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0)
@@ -238,7 +248,7 @@ static int request_frame(AVFilterLink *outlink) · 13 unmodified lines
238248 if (outlink->request_samples) {
239249 return return_audio_frame(outlink->src);
240250 } else {
241− ff_filter_samples(outlink, fifo->root.next->buf);
251+ ret = ff_filter_samples(outlink, fifo->root.next->buf);
242252 queue_pop(fifo);
243253 }
244254 break;
@@ -246,7 +256,7 @@ static int request_frame(AVFilterLink *outlink) · 1 unmodified line
246256 return AVERROR(EINVAL);
247257 }
248258
249− return 0;
259+ return ret;
250260 }
251261
252262 AVFilter avfilter_vf_fifo = {
@@ -261,7 +271,7 @@ AVFilter avfilter_vf_fifo = { · 8 unmodified lines
261271 .inputs = (const AVFilterPad[]) {{ .name = "default",
262272 .type = AVMEDIA_TYPE_VIDEO,
263273 .get_video_buffer= ff_null_get_video_buffer,
264− .start_frame = add_to_queue,
274+ .start_frame = start_frame,
265275 .draw_slice = draw_slice,
266276 .end_frame = end_frame,
267277 .rej_perms = AV_PERM_REUSE2, },
libavfilter/internal.h+5−1
@@ -135,8 +135,12 @@ struct AVFilterPad { · 134 unmodified lines
135135 * and should do its processing.
136136 *
137137 * Input audio pads only.
138+ *
139+ * @return >= 0 on success, a negative AVERROR on error. This function
140+ * must ensure that samplesref is properly unreferenced on error if it
141+ * hasn't been passed on to another filter.
138142 */
139− void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
143+ int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
140144
141145 /**
142146 * Frame poll callback. This returns the number of immediately available
libavfilter/sink_buffer.c+2−1
@@ -244,9 +244,10 @@ AVFilter avfilter_vsink_buffersink = { · 243 unmodified lines
244244
245245 #if CONFIG_ABUFFERSINK_FILTER
246246
247−static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
247+static int filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
248248 {
249249 end_frame(link);
250+ return 0;
250251 }
251252
252253 static av_cold int asink_init(AVFilterContext *ctx, const char *args)
libavfilter/split.c+9−5
@@ -110,15 +110,19 @@ AVFilter avfilter_vf_split = { · 109 unmodified lines
110110 .outputs = (AVFilterPad[]) {{ .name = NULL}},
111111 };
112112
113−static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
113+static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
114114 {
115115 AVFilterContext *ctx = inlink->dst;
116− int i;
116+ int i, ret = 0;
117117
118− for (i = 0; i < ctx->nb_outputs; i++)
119− ff_filter_samples(inlink->dst->outputs[i],
120− avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
118+ for (i = 0; i < ctx->nb_outputs; i++) {
119+ ret = ff_filter_samples(inlink->dst->outputs[i],
120+ avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
121+ if (ret < 0)
122+ break;
123+ }
121124 avfilter_unref_buffer(samplesref);
125+ return ret;
122126 }
123127
124128 AVFilter avfilter_af_asplit = {
libavformat/matroskadec.c+4−1
@@ -842,8 +842,11 @@ static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, · 841 unmodified lines
842842 matroska->num_levels > 0 &&
843843 matroska->levels[matroska->num_levels-1].length == 0xffffffffffffff)
844844 return 0; // we reached the end of an unknown size cluster
845− if (!syntax[i].id && id != EBML_ID_VOID && id != EBML_ID_CRC32)
845+ if (!syntax[i].id && id != EBML_ID_VOID && id != EBML_ID_CRC32) {
846846 av_log(matroska->ctx, AV_LOG_INFO, "Unknown entry 0x%X\n", id);
847+ if (matroska->ctx->error_recognition & AV_EF_EXPLODE)
848+ return AVERROR_INVALIDDATA;
849+ }
847850 return ebml_parse_elem(matroska, &syntax[i], data);
848851 }
849852
libavformat/tcp.c+10−1
@@ -43,7 +43,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 42 unmodified lines
4343 char buf[256];
4444 int ret;
4545 socklen_t optlen;
46− int timeout = 50;
46+ int timeout = 50, listen_timeout = -1;
4747 char hostname[1024],proto[1024],path[1024];
4848 char portstr[10];
4949
@@ -59,6 +59,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 9 unmodified lines
5959 if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
6060 timeout = strtol(buf, NULL, 10);
6161 }
62+ if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
63+ listen_timeout = strtol(buf, NULL, 10);
64+ }
6265 }
6366 hints.ai_family = AF_UNSPEC;
6467 hints.ai_socktype = SOCK_STREAM;
@@ -87,6 +90,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 22 unmodified lines
8790 if (listen_socket) {
8891 int fd1;
8992 int reuse = 1;
93+ struct pollfd lp = { fd, POLLIN, 0 };
9094 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
9195 ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
9296 if (ret) {
@@ -98,6 +102,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 5 unmodified lines
98102 ret = ff_neterrno();
99103 goto fail1;
100104 }
105+ ret = poll(&lp, 1, listen_timeout >= 0 ? listen_timeout : -1);
106+ if (ret <= 0) {
107+ ret = AVERROR(ETIMEDOUT);
108+ goto fail1;
109+ }
101110 fd1 = accept(fd, NULL, NULL);
102111 if (fd1 < 0) {
103112 ret = ff_neterrno();
libavresample/audio_mix.c+8−0
@@ -305,6 +305,14 @@ int ff_audio_mix_init(AVAudioResampleContext *avr) · 304 unmodified lines
305305 {
306306 int ret;
307307
308+ if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
309+ avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {
310+ av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "
311+ "mixing: %s\n",
312+ av_get_sample_fmt_name(avr->internal_sample_fmt));
313+ return AVERROR(EINVAL);
314+ }
315+
308316 /* build matrix if the user did not already set one */
309317 if (!avr->am->matrix) {
310318 int i, j;
libavresample/avresample.h+7−0
@@ -45,6 +45,13 @@ enum AVMixCoeffType { · 44 unmodified lines
4545 AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */
4646 };
4747
48+/** Resampling Filter Types */
49+enum AVResampleFilterType {
50+ AV_RESAMPLE_FILTER_TYPE_CUBIC, /**< Cubic */
51+ AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall Windowed Sinc */
52+ AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */
53+};
54+
4855 /**
4956 * Return the LIBAVRESAMPLE_VERSION_INT constant.
5057 */
libavresample/internal.h+2−0
@@ -50,6 +50,8 @@ struct AVAudioResampleContext { · 49 unmodified lines
5050 int phase_shift; /**< log2 of the number of entries in the resampling polyphase filterbank */
5151 int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */
5252 double cutoff; /**< resampling cutoff frequency. 1.0 corresponds to half the output sample rate */
53+ enum AVResampleFilterType filter_type; /**< resampling filter type */
54+ int kaiser_beta; /**< beta value for Kaiser window (only applicable if filter_type == AV_FILTER_TYPE_KAISER) */
5355
5456 int in_channels; /**< number of input channels */
5557 int out_channels; /**< number of output channels */
libavresample/options.c+6−1
@@ -39,7 +39,7 @@ static const AVOption options[] = { · 38 unmodified lines
3939 { "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM },
4040 { "out_sample_fmt", "Output Sample Format", OFFSET(out_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_S16 }, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_NB-1, PARAM },
4141 { "out_sample_rate", "Output Sample Rate", OFFSET(out_sample_rate), AV_OPT_TYPE_INT, { 48000 }, 1, INT_MAX, PARAM },
42− { "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_FLTP }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, PARAM },
42+ { "internal_sample_fmt", "Internal Sample Format", OFFSET(internal_sample_fmt), AV_OPT_TYPE_INT, { AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, PARAM },
4343 { "mix_coeff_type", "Mixing Coefficient Type", OFFSET(mix_coeff_type), AV_OPT_TYPE_INT, { AV_MIX_COEFF_TYPE_FLT }, AV_MIX_COEFF_TYPE_Q8, AV_MIX_COEFF_TYPE_NB-1, PARAM, "mix_coeff_type" },
4444 { "q8", "16-bit 8.8 Fixed-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_Q8 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
4545 { "q15", "32-bit 17.15 Fixed-Point", 0, AV_OPT_TYPE_CONST, { AV_MIX_COEFF_TYPE_Q15 }, INT_MIN, INT_MAX, PARAM, "mix_coeff_type" },
@@ -56,6 +56,11 @@ static const AVOption options[] = { · 10 unmodified lines
5656 { "none", "None", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
5757 { "dolby", "Dolby", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
5858 { "dplii", "Dolby Pro Logic II", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DPLII }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
59+ { "filter_type", "Filter Type", OFFSET(filter_type), AV_OPT_TYPE_INT, { AV_RESAMPLE_FILTER_TYPE_KAISER }, AV_RESAMPLE_FILTER_TYPE_CUBIC, AV_RESAMPLE_FILTER_TYPE_KAISER, PARAM, "filter_type" },
60+ { "cubic", "Cubic", 0, AV_OPT_TYPE_CONST, { AV_RESAMPLE_FILTER_TYPE_CUBIC }, INT_MIN, INT_MAX, PARAM, "filter_type" },
61+ { "blackman_nuttall", "Blackman Nuttall Windowed Sinc", 0, AV_OPT_TYPE_CONST, { AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL }, INT_MIN, INT_MAX, PARAM, "filter_type" },
62+ { "kaiser", "Kaiser Windowed Sinc", 0, AV_OPT_TYPE_CONST, { AV_RESAMPLE_FILTER_TYPE_KAISER }, INT_MIN, INT_MAX, PARAM, "filter_type" },
63+ { "kaiser_beta", "Kaiser Window Beta", OFFSET(kaiser_beta), AV_OPT_TYPE_INT, { 9 }, 2, 16, PARAM },
5964 { NULL },
6065 };
6166
libavresample/resample.c+85−95
@@ -24,37 +24,10 @@ · 23 unmodified lines
2424 #include "internal.h"
2525 #include "audio_data.h"
2626
27−#ifdef CONFIG_RESAMPLE_FLT
28−/* float template */
29−#define FILTER_SHIFT 0
30−#define FELEM float
31−#define FELEM2 float
32−#define FELEML float
33−#define WINDOW_TYPE 24
34−#elifdef CONFIG_RESAMPLE_S32
35−/* s32 template */
36−#define FILTER_SHIFT 30
37−#define FELEM int32_t
38−#define FELEM2 int64_t
39−#define FELEML int64_t
40−#define FELEM_MAX INT32_MAX
41−#define FELEM_MIN INT32_MIN
42−#define WINDOW_TYPE 12
43−#else
44−/* s16 template */
45−#define FILTER_SHIFT 15
46−#define FELEM int16_t
47−#define FELEM2 int32_t
48−#define FELEML int64_t
49−#define FELEM_MAX INT16_MAX
50−#define FELEM_MIN INT16_MIN
51−#define WINDOW_TYPE 9
52−#endif
53−
5427 struct ResampleContext {
5528 AVAudioResampleContext *avr;
5629 AudioData *buffer;
57− FELEM *filter_bank;
30+ uint8_t *filter_bank;
5831 int filter_length;
5932 int ideal_dst_incr;
6033 int dst_incr;
@@ -65,9 +38,35 @@ struct ResampleContext { · 4 unmodified lines
6538 int phase_shift;
6639 int phase_mask;
6740 int linear;
41+ enum AVResampleFilterType filter_type;
42+ int kaiser_beta;
6843 double factor;
44+ void (*set_filter)(void *filter, double *tab, int phase, int tap_count);
45+ void (*resample_one)(struct ResampleContext *c, int no_filter, void *dst0,
46+ int dst_index, const void *src0, int src_size,
47+ int index, int frac);
6948 };
7049
50+
51+/* double template */
52+#define CONFIG_RESAMPLE_DBL
53+#include "resample_template.c"
54+#undef CONFIG_RESAMPLE_DBL
55+
56+/* float template */
57+#define CONFIG_RESAMPLE_FLT
58+#include "resample_template.c"
59+#undef CONFIG_RESAMPLE_FLT
60+
61+/* s32 template */
62+#define CONFIG_RESAMPLE_S32
63+#include "resample_template.c"
64+#undef CONFIG_RESAMPLE_S32
65+
66+/* s16 template */
67+#include "resample_template.c"
68+
69+
7170 /**
7271 * 0th order modified bessel function of the first kind.
7372 */
@@ -95,17 +94,17 @@ static double bessel(double x) · 21 unmodified lines
9594 * @param tap_count tap count
9695 * @param phase_count phase count
9796 * @param scale wanted sum of coefficients for each filter
98− * @param type 0->cubic
99− * 1->blackman nuttall windowed sinc
100− * 2..16->kaiser windowed sinc beta=2..16
97+ * @param filter_type filter type
98+ * @param kaiser_beta kaiser window beta
10199 * @return 0 on success, negative AVERROR code on failure
102100 */
103−static int build_filter(FELEM *filter, double factor, int tap_count,
104− int phase_count, int scale, int type)
101+static int build_filter(ResampleContext *c)
105102 {
106103 int ph, i;
107− double x, y, w;
104+ double x, y, w, factor;
108105 double *tab;
106+ int tap_count = c->filter_length;
107+ int phase_count = 1 << c->phase_shift;
109108 const int center = (tap_count - 1) / 2;
110109
111110 tab = av_malloc(tap_count * sizeof(*tab));
@@ -113,8 +112,7 @@ static int build_filter(FELEM *filter, double factor, int tap_count, · 1 unmodified line
113112 return AVERROR(ENOMEM);
114113
115114 /* if upsampling, only need to interpolate, no filter */
116− if (factor > 1.0)
117− factor = 1.0;
115+ factor = FFMIN(c->factor, 1.0);
118116
119117 for (ph = 0; ph < phase_count; ph++) {
120118 double norm = 0;
@@ -122,39 +120,34 @@ static int build_filter(FELEM *filter, double factor, int tap_count, · 1 unmodified line
122120 x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
123121 if (x == 0) y = 1.0;
124122 else y = sin(x) / x;
125− switch (type) {
126− case 0: {
123+ switch (c->filter_type) {
124+ case AV_RESAMPLE_FILTER_TYPE_CUBIC: {
127125 const float d = -0.5; //first order derivative = -0.5
128126 x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
129127 if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);
130128 else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);
131129 break;
132130 }
133− case 1:
131+ case AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL:
134132 w = 2.0 * x / (factor * tap_count) + M_PI;
135133 y *= 0.3635819 - 0.4891775 * cos( w) +
136134 0.1365995 * cos(2 * w) -
137135 0.0106411 * cos(3 * w);
138136 break;
139− default:
137+ case AV_RESAMPLE_FILTER_TYPE_KAISER:
140138 w = 2.0 * x / (factor * tap_count * M_PI);
141− y *= bessel(type * sqrt(FFMAX(1 - w * w, 0)));
139+ y *= bessel(c->kaiser_beta * sqrt(FFMAX(1 - w * w, 0)));
142140 break;
143141 }
144142
145143 tab[i] = y;
146144 norm += y;
147145 }
148−
149146 /* normalize so that an uniform color remains the same */
150− for (i = 0; i < tap_count; i++) {
151−#ifdef CONFIG_RESAMPLE_FLT
152− filter[ph * tap_count + i] = tab[i] / norm;
153−#else
154− filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm),
155− FELEM_MIN, FELEM_MAX);
156−#endif
157− }
147+ for (i = 0; i < tap_count; i++)
148+ tab[i] = tab[i] / norm;
149+
150+ c->set_filter(c->filter_bank, tab, ph, tap_count);
158151 }
159152
160153 av_free(tab);
@@ -168,9 +161,12 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr) · 7 unmodified lines
168161 int in_rate = avr->in_sample_rate;
169162 double factor = FFMIN(out_rate * avr->cutoff / in_rate, 1.0);
170163 int phase_count = 1 << avr->phase_shift;
164+ int felem_size;
171165
172− /* TODO: add support for s32 and float internal formats */
173− if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) {
166+ if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
167+ avr->internal_sample_fmt != AV_SAMPLE_FMT_S32P &&
168+ avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP &&
169+ avr->internal_sample_fmt != AV_SAMPLE_FMT_DBLP) {
174170 av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "
175171 "resampling: %s\n",
176172 av_get_sample_fmt_name(avr->internal_sample_fmt));
@@ -186,18 +182,40 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr) · 9 unmodified lines
186182 c->linear = avr->linear_interp;
187183 c->factor = factor;
188184 c->filter_length = FFMAX((int)ceil(avr->filter_size / factor), 1);
185+ c->filter_type = avr->filter_type;
186+ c->kaiser_beta = avr->kaiser_beta;
187+
188+ switch (avr->internal_sample_fmt) {
189+ case AV_SAMPLE_FMT_DBLP:
190+ c->resample_one = resample_one_dbl;
191+ c->set_filter = set_filter_dbl;
192+ break;
193+ case AV_SAMPLE_FMT_FLTP:
194+ c->resample_one = resample_one_flt;
195+ c->set_filter = set_filter_flt;
196+ break;
197+ case AV_SAMPLE_FMT_S32P:
198+ c->resample_one = resample_one_s32;
199+ c->set_filter = set_filter_s32;
200+ break;
201+ case AV_SAMPLE_FMT_S16P:
202+ c->resample_one = resample_one_s16;
203+ c->set_filter = set_filter_s16;
204+ break;
205+ }
189206
190− c->filter_bank = av_mallocz(c->filter_length * (phase_count + 1) * sizeof(FELEM));
207+ felem_size = av_get_bytes_per_sample(avr->internal_sample_fmt);
208+ c->filter_bank = av_mallocz(c->filter_length * (phase_count + 1) * felem_size);
191209 if (!c->filter_bank)
192210 goto error;
193211
194− if (build_filter(c->filter_bank, factor, c->filter_length, phase_count,
195− 1 << FILTER_SHIFT, WINDOW_TYPE) < 0)
212+ if (build_filter(c) < 0)
196213 goto error;
197214
198− memcpy(&c->filter_bank[c->filter_length * phase_count + 1],
199− c->filter_bank, (c->filter_length - 1) * sizeof(FELEM));
200− c->filter_bank[c->filter_length * phase_count] = c->filter_bank[c->filter_length - 1];
215+ memcpy(&c->filter_bank[(c->filter_length * phase_count + 1) * felem_size],
216+ c->filter_bank, (c->filter_length - 1) * felem_size);
217+ memcpy(&c->filter_bank[c->filter_length * phase_count * felem_size],
218+ &c->filter_bank[(c->filter_length - 1) * felem_size], felem_size);
201219
202220 c->compensation_distance = 0;
203221 if (!av_reduce(&c->src_incr, &c->dst_incr, out_rate,
@@ -311,10 +329,10 @@ reinit_fail: · 107 unmodified lines
311329 return ret;
312330 }
313331
314−static int resample(ResampleContext *c, int16_t *dst, const int16_t *src,
332+static int resample(ResampleContext *c, void *dst, const void *src,
315333 int *consumed, int src_size, int dst_size, int update_ctx)
316334 {
317− int dst_index, i;
335+ int dst_index;
318336 int index = c->index;
319337 int frac = c->frac;
320338 int dst_incr_frac = c->dst_incr % c->src_incr;
@@ -334,7 +352,7 @@ static int resample(ResampleContext *c, int16_t *dst, const int16_t *src, · 13 unmodified lines
334352
335353 if (dst) {
336354 for(dst_index = 0; dst_index < dst_size; dst_index++) {
337− dst[dst_index] = src[index2 >> 32];
355+ c->resample_one(c, 1, dst, dst_index, src, 0, index2 >> 32, 0);
338356 index2 += incr;
339357 }
340358 } else {
@@ -345,42 +363,14 @@ static int resample(ResampleContext *c, int16_t *dst, const int16_t *src, · 4 unmodified lines
345363 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
346364 } else {
347365 for (dst_index = 0; dst_index < dst_size; dst_index++) {
348− FELEM *filter = c->filter_bank +
349− c->filter_length * (index & c->phase_mask);
350366 int sample_index = index >> c->phase_shift;
351367
352− if (!dst && (sample_index + c->filter_length > src_size ||
353− -sample_index >= src_size))
368+ if (sample_index + c->filter_length > src_size ||
369+ -sample_index >= src_size)
354370 break;
355371
356− if (dst) {
357− FELEM2 val = 0;
358−
359− if (sample_index < 0) {
360− for (i = 0; i < c->filter_length; i++)
361− val += src[FFABS(sample_index + i) % src_size] *
362− (FELEM2)filter[i];
363− } else if (sample_index + c->filter_length > src_size) {
364− break;
365− } else if (c->linear) {
366− FELEM2 v2 = 0;
367− for (i = 0; i < c->filter_length; i++) {
368− val += src[abs(sample_index + i)] * (FELEM2)filter[i];
369− v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
370− }
371− val += (v2 - val) * (FELEML)frac / c->src_incr;
372− } else {
373− for (i = 0; i < c->filter_length; i++)
374− val += src[sample_index + i] * (FELEM2)filter[i];
375− }
376−
377−#ifdef CONFIG_RESAMPLE_FLT
378− dst[dst_index] = av_clip_int16(lrintf(val));
379−#else
380− val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT;
381− dst[dst_index] = av_clip_int16(val);
382−#endif
383− }
372+ if (dst)
373+ c->resample_one(c, 0, dst, dst_index, src, src_size, index, frac);
384374
385375 frac += dst_incr_frac;
386376 index += dst_incr;
@@ -451,8 +441,8 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src, · 64 unmodified lines
451441
452442 /* resample each channel plane */
453443 for (ch = 0; ch < c->buffer->channels; ch++) {
454− out_samples = resample(c, (int16_t *)dst->data[ch],
455− (const int16_t *)c->buffer->data[ch], consumed,
444+ out_samples = resample(c, (void *)dst->data[ch],
445+ (const void *)c->buffer->data[ch], consumed,
456446 c->buffer->nb_samples, dst->allocated_samples,
457447 ch + 1 == c->buffer->channels);
458448 }
libavresample/resample_template.c+102−0
@@ -0,0 +1,102 @@
1+/*
2+ * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at>
3+ *
4+ * This file is part of FFmpeg.
5+ *
6+ * FFmpeg is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2.1 of the License, or (at your option) any later version.
10+ *
11+ * FFmpeg is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+ * Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with FFmpeg; if not, write to the Free Software
18+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19+ */
20+
21+#if defined(CONFIG_RESAMPLE_DBL)
22+#define SET_TYPE(func) func ## _dbl
23+#define FELEM double
24+#define FELEM2 double
25+#define FELEML double
26+#define OUT(d, v) d = v
27+#define DBL_TO_FELEM(d, v) d = v
28+#elif defined(CONFIG_RESAMPLE_FLT)
29+#define SET_TYPE(func) func ## _flt
30+#define FELEM float
31+#define FELEM2 float
32+#define FELEML float
33+#define OUT(d, v) d = v
34+#define DBL_TO_FELEM(d, v) d = v
35+#elif defined(CONFIG_RESAMPLE_S32)
36+#define SET_TYPE(func) func ## _s32
37+#define FELEM int32_t
38+#define FELEM2 int64_t
39+#define FELEML int64_t
40+#define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30)
41+#define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30)));
42+#else
43+#define SET_TYPE(func) func ## _s16
44+#define FELEM int16_t
45+#define FELEM2 int32_t
46+#define FELEML int64_t
47+#define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15)
48+#define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15)))
49+#endif
50+
51+static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter,
52+ void *dst0, int dst_index, const void *src0,
53+ int src_size, int index, int frac)
54+{
55+ FELEM *dst = dst0;
56+ const FELEM *src = src0;
57+
58+ if (no_filter) {
59+ dst[dst_index] = src[index];
60+ } else {
61+ int i;
62+ int sample_index = index >> c->phase_shift;
63+ FELEM2 val = 0;
64+ FELEM *filter = ((FELEM *)c->filter_bank) +
65+ c->filter_length * (index & c->phase_mask);
66+
67+ if (sample_index < 0) {
68+ for (i = 0; i < c->filter_length; i++)
69+ val += src[FFABS(sample_index + i) % src_size] *
70+ (FELEM2)filter[i];
71+ } else if (c->linear) {
72+ FELEM2 v2 = 0;
73+ for (i = 0; i < c->filter_length; i++) {
74+ val += src[abs(sample_index + i)] * (FELEM2)filter[i];
75+ v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length];
76+ }
77+ val += (v2 - val) * (FELEML)frac / c->src_incr;
78+ } else {
79+ for (i = 0; i < c->filter_length; i++)
80+ val += src[sample_index + i] * (FELEM2)filter[i];
81+ }
82+
83+ OUT(dst[dst_index], val);
84+ }
85+}
86+
87+static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase,
88+ int tap_count)
89+{
90+ int i;
91+ FELEM *filter = ((FELEM *)filter0) + phase * tap_count;
92+ for (i = 0; i < tap_count; i++) {
93+ DBL_TO_FELEM(filter[i], tab[i]);
94+ }
95+}
96+
97+#undef SET_TYPE
98+#undef FELEM
99+#undef FELEM2
100+#undef FELEML
101+#undef OUT
102+#undef DBL_TO_FELEM
libavresample/utils.c+36−11
@@ -57,18 +57,43 @@ int avresample_open(AVAudioResampleContext *avr) · 56 unmodified lines
5757 avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate ||
5858 avr->force_resampling;
5959
60− /* set sample format conversion parameters */
61− /* override user-requested internal format to avoid unexpected failures
62− TODO: support more internal formats */
63− if (avr->resample_needed && avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) {
64− av_log(avr, AV_LOG_WARNING, "Using s16p as internal sample format\n");
65− avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;
66− } else if (avr->mixing_needed &&
67− avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
68− avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {
69− av_log(avr, AV_LOG_WARNING, "Using fltp as internal sample format\n");
70− avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
60+ /* select internal sample format if not specified by the user */
61+ if (avr->internal_sample_fmt == AV_SAMPLE_FMT_NONE &&
62+ (avr->mixing_needed || avr->resample_needed)) {
63+ enum AVSampleFormat in_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
64+ enum AVSampleFormat out_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
65+ int max_bps = FFMAX(av_get_bytes_per_sample(in_fmt),
66+ av_get_bytes_per_sample(out_fmt));
67+ if (max_bps <= 2) {
68+ avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;
69+ } else if (avr->mixing_needed) {
70+ avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
71+ } else {
72+ if (max_bps <= 4) {
73+ if (in_fmt == AV_SAMPLE_FMT_S32P ||
74+ out_fmt == AV_SAMPLE_FMT_S32P) {
75+ if (in_fmt == AV_SAMPLE_FMT_FLTP ||
76+ out_fmt == AV_SAMPLE_FMT_FLTP) {
77+ /* if one is s32 and the other is flt, use dbl */
78+ avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP;
79+ } else {
80+ /* if one is s32 and the other is s32, s16, or u8, use s32 */
81+ avr->internal_sample_fmt = AV_SAMPLE_FMT_S32P;
82+ }
83+ } else {
84+ /* if one is flt and the other is flt, s16 or u8, use flt */
85+ avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
86+ }
87+ } else {
88+ /* if either is dbl, use dbl */
89+ avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP;
90+ }
91+ }
92+ av_log(avr, AV_LOG_DEBUG, "Using %s as internal sample format\n",
93+ av_get_sample_fmt_name(avr->internal_sample_fmt));
7194 }
95+
96+ /* set sample format conversion parameters */
7297 if (avr->in_channels == 1)
7398 avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
7499 if (avr->out_channels == 1)
tests/fate-run.sh+7−1
@@ -75,7 +75,13 @@ probefmt(){ · 74 unmodified lines
7575 }
7676
7777 ffmpeg(){
78− run ffmpeg -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@"
78+ dec_opts="-threads $threads -thread_type $thread_type"
79+ ffmpeg_args="-nostats -cpuflags $cpuflags"
80+ for arg in $@; do
81+ [ ${arg} = -i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}"
82+ ffmpeg_args="${ffmpeg_args} ${arg}"
83+ done
84+ run ffmpeg ${ffmpeg_args}
7985 }
8086
8187 framecrc(){

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t