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
327 h263dec.o h263.o ituh263dec.o \327 h263dec.o h263.o ituh263dec.o \
328 mpeg4videodec.o328 mpeg4videodec.o
329OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o329OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o
330OBJS-$(CONFIG_MSA1_DECODER) += mss3.o330OBJS-$(CONFIG_MSA1_DECODER) += mss3.o mss34dsp.o
331OBJS-$(CONFIG_MSS1_DECODER) += mss1.o331OBJS-$(CONFIG_MSS1_DECODER) += mss1.o
332OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o332OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
333OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o333OBJS-$(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
175 x4->params.b_tff = frame->top_field_first;175 x4->params.b_tff = frame->top_field_first;
176 x264_encoder_reconfig(x4->enc, &x4->params);176 x264_encoder_reconfig(x4->enc, &x4->params);
177 }177 }
178 if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den178 if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ||
179 || x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {179 x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
180 x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den;180 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;
182 x264_encoder_reconfig(x4->enc, &x4->params);182 x264_encoder_reconfig(x4->enc, &x4->params);
183 }183 }
184 }184 }
libavcodec/motion-test.c+3−9
@@ -119,15 +119,9 @@ int main(int argc, char **argv) · 118 unmodified lines
119 int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };119 int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };
120 int flags_size = HAVE_MMX2 ? 2 : 1;120 int flags_size = HAVE_MMX2 ? 2 : 1;
121 121
122 for(;;) {122 if (argc > 1) {
123 c = getopt(argc, argv, "h");123 help();
124 if (c == -1)124 return 1;
125 break;
126 switch(c) {
127 case 'h':
128 help();
129 return 1;
130 }
131 }125 }
132 126
133 printf("ffmpeg motion test\n");127 printf("ffmpeg motion test\n");
libavcodec/mss3.c+5−103
@@ -26,6 +26,8 @@ · 25 unmodified lines
26 26
27#include "avcodec.h"27#include "avcodec.h"
28#include "bytestream.h"28#include "bytestream.h"
29#include "dsputil.h"
30#include "mss34dsp.h"
29 31
30#define HEADER_SIZE 2732#define HEADER_SIZE 27
31 33
@@ -119,39 +121,6 @@ typedef struct MSS3Context { · 87 unmodified lines
119 int hblock[16 * 16];121 int hblock[16 * 16];
120} MSS3Context;122} MSS3Context;
121 123
122static 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
133static 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
144static 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
155 124
156static void model2_reset(Model2 *m)125static void model2_reset(Model2 *m)
157{126{
@@ -578,7 +547,7 @@ static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block, · 420 unmodified lines
578 if (!sign)547 if (!sign)
579 val = -val;548 val = -val;
580 549
581 zz_pos = zigzag_scan[pos];550 zz_pos = ff_zigzag_direct[pos];
582 block[zz_pos] = val * bc->qmat[zz_pos];551 block[zz_pos] = val * bc->qmat[zz_pos];
583 pos++;552 pos++;
584 }553 }
@@ -586,58 +555,6 @@ static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block, · 1 unmodified line
586 return pos == 64 ? 0 : -1;555 return pos == 64 ? 0 : -1;
587}556}
588 557
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
615static 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
641static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc,558static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc,
642 uint8_t *dst, int stride, int block_size,559 uint8_t *dst, int stride, int block_size,
643 int *block, int mb_x, int mb_y)560 int *block, int mb_x, int mb_y)
@@ -655,7 +572,7 @@ static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc, · 11 unmodified lines
655 c->got_error = 1;572 c->got_error = 1;
656 return;573 return;
657 }574 }
658 dct_put(dst + i * 8, stride, block);575 ff_mss34_dct_put(dst + i * 8, stride, block);
659 }576 }
660 dst += 8 * stride;577 dst += 8 * stride;
661 }578 }
@@ -702,14 +619,6 @@ static void decode_haar_block(RangeCoder *c, HaarBlockCoder *hc, · 40 unmodified lines
702 }619 }
703}620}
704 621
705static 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
713static void reset_coders(MSS3Context *ctx, int quality)622static void reset_coders(MSS3Context *ctx, int quality)
714{623{
715 int i, j;624 int i, j;
@@ -726,15 +635,8 @@ static void reset_coders(MSS3Context *ctx, int quality) · 10 unmodified lines
726 for (j = 0; j < 125; j++)635 for (j = 0; j < 125; j++)
727 model_reset(&ctx->image_coder[i].vq_model[j]);636 model_reset(&ctx->image_coder[i].vq_model[j]);
728 if (ctx->dct_coder[i].quality != quality) {637 if (ctx->dct_coder[i].quality != quality) {
729 float scale;
730 ctx->dct_coder[i].quality = quality;638 ctx->dct_coder[i].quality = quality;
731 if (quality > 50)639 ff_mss34_gen_quant_mat(ctx->dct_coder[i].qmat, quality, !i);
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);
738 }640 }
739 memset(ctx->dct_coder[i].prev_dc, 0,641 memset(ctx->dct_coder[i].prev_dc, 0,
740 sizeof(*ctx->dct_coder[i].prev_dc) *642 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
26static 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
37static 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
48void 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
90void 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 */
34void 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 */
43void 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
135 return 0;135 return 0;
136}136}
137 137
138static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)138static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
139{139{
140 AConvertContext *aconvert = inlink->dst->priv;140 AConvertContext *aconvert = inlink->dst->priv;
141 const int n = insamplesref->audio->nb_samples;141 const int n = insamplesref->audio->nb_samples;
142 AVFilterLink *const outlink = inlink->dst->outputs[0];142 AVFilterLink *const outlink = inlink->dst->outputs[0];
143 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);143 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
144 int ret;
144 145
145 swr_convert(aconvert->swr, outsamplesref->data, n,146 swr_convert(aconvert->swr, outsamplesref->data, n,
146 (void *)insamplesref->data, n);147 (void *)insamplesref->data, n);
@@ -148,8 +149,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref · 1 unmodified line
148 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);149 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);
149 outsamplesref->audio->channel_layout = outlink->channel_layout;150 outsamplesref->audio->channel_layout = outlink->channel_layout;
150 151
151 ff_filter_samples(outlink, outsamplesref);152 ret = ff_filter_samples(outlink, outsamplesref);
152 avfilter_unref_buffer(insamplesref);153 avfilter_unref_buffer(insamplesref);
154 return ret;
153}155}
154 156
155AVFilter avfilter_af_aconvert = {157AVFilter 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
212 }212 }
213}213}
214 214
215static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)215static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
216{216{
217 AVFilterContext *ctx = inlink->dst;217 AVFilterContext *ctx = inlink->dst;
218 AMergeContext *am = ctx->priv;218 AMergeContext *am = ctx->priv;
@@ -232,7 +232,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 13 unmodified lines
232 for (i = 1; i < am->nb_inputs; i++)232 for (i = 1; i < am->nb_inputs; i++)
233 nb_samples = FFMIN(nb_samples, am->in[i].nb_samples);233 nb_samples = FFMIN(nb_samples, am->in[i].nb_samples);
234 if (!nb_samples)234 if (!nb_samples)
235 return;235 return 0;
236 236
237 outbuf = ff_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE, nb_samples);237 outbuf = ff_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE, nb_samples);
238 outs = outbuf->data[0];238 outs = outbuf->data[0];
@@ -285,7 +285,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 46 unmodified lines
285 }285 }
286 }286 }
287 }287 }
288 ff_filter_samples(ctx->outputs[0], outbuf);288 return ff_filter_samples(ctx->outputs[0], outbuf);
289}289}
290 290
291static av_cold int init(AVFilterContext *ctx, const char *args)291static 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
305 if (s->next_pts != AV_NOPTS_VALUE)305 if (s->next_pts != AV_NOPTS_VALUE)
306 s->next_pts += nb_samples;306 s->next_pts += nb_samples;
307 307
308 ff_filter_samples(outlink, out_buf);308 return ff_filter_samples(outlink, out_buf);
309
310 return 0;
311}309}
312 310
313/**311/**
@@ -448,31 +446,37 @@ static int request_frame(AVFilterLink *outlink) · 134 unmodified lines
448 return output_frame(outlink, available_samples);446 return output_frame(outlink, available_samples);
449}447}
450 448
451static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)449static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
452{450{
453 AVFilterContext *ctx = inlink->dst;451 AVFilterContext *ctx = inlink->dst;
454 MixContext *s = ctx->priv;452 MixContext *s = ctx->priv;
455 AVFilterLink *outlink = ctx->outputs[0];453 AVFilterLink *outlink = ctx->outputs[0];
456 int i;454 int i, ret = 0;
457 455
458 for (i = 0; i < ctx->nb_inputs; i++)456 for (i = 0; i < ctx->nb_inputs; i++)
459 if (ctx->inputs[i] == inlink)457 if (ctx->inputs[i] == inlink)
460 break;458 break;
461 if (i >= ctx->nb_inputs) {459 if (i >= ctx->nb_inputs) {
462 av_log(ctx, AV_LOG_ERROR, "unknown input link\n");460 av_log(ctx, AV_LOG_ERROR, "unknown input link\n");
463 return;461 ret = AVERROR(EINVAL);
462 goto fail;
464 }463 }
465 464
466 if (i == 0) {465 if (i == 0) {
467 int64_t pts = av_rescale_q(buf->pts, inlink->time_base,466 int64_t pts = av_rescale_q(buf->pts, inlink->time_base,
468 outlink->time_base);467 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;
470 }471 }
471 472
472 av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data,473 ret = av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data,
473 buf->audio->nb_samples);474 buf->audio->nb_samples);
474 475
476fail:
475 avfilter_unref_buffer(buf);477 avfilter_unref_buffer(buf);
478
479 return ret;
476}480}
477 481
478static int init(AVFilterContext *ctx, const char *args)482static 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
168 return 0;168 return 0;
169}169}
170 170
171static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)171static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
172{172{
173 AResampleContext *aresample = inlink->dst->priv;173 AResampleContext *aresample = inlink->dst->priv;
174 const int n_in = insamplesref->audio->nb_samples;174 const int n_in = insamplesref->audio->nb_samples;
175 int n_out = n_in * aresample->ratio * 2 ;175 int n_out = n_in * aresample->ratio * 2 ;
176 AVFilterLink *const outlink = inlink->dst->outputs[0];176 AVFilterLink *const outlink = inlink->dst->outputs[0];
177 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out);177 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out);
178 int ret;
178 179
179 180
180 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);181 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);
@@ -193,15 +194,16 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref · 12 unmodified lines
193 if (n_out <= 0) {194 if (n_out <= 0) {
194 avfilter_unref_buffer(outsamplesref);195 avfilter_unref_buffer(outsamplesref);
195 avfilter_unref_buffer(insamplesref);196 avfilter_unref_buffer(insamplesref);
196 return;197 return 0;
197 }198 }
198 199
199 outsamplesref->audio->sample_rate = outlink->sample_rate;200 outsamplesref->audio->sample_rate = outlink->sample_rate;
200 outsamplesref->audio->nb_samples = n_out;201 outsamplesref->audio->nb_samples = n_out;
201 202
202 ff_filter_samples(outlink, outsamplesref);203 ret = ff_filter_samples(outlink, outsamplesref);
203 aresample->req_fullfilled= 1;204 aresample->req_fullfilled= 1;
204 avfilter_unref_buffer(insamplesref);205 avfilter_unref_buffer(insamplesref);
206 return ret;
205}207}
206 208
207static int request_frame(AVFilterLink *outlink)209static int request_frame(AVFilterLink *outlink)
libavfilter/af_asetnsamples.c+3−2
@@ -131,7 +131,7 @@ static int push_samples(AVFilterLink *outlink) · 130 unmodified lines
131 return nb_out_samples;131 return nb_out_samples;
132}132}
133 133
134static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)134static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
135{135{
136 AVFilterContext *ctx = inlink->dst;136 AVFilterContext *ctx = inlink->dst;
137 ASNSContext *asns = ctx->priv;137 ASNSContext *asns = ctx->priv;
@@ -145,7 +145,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 7 unmodified lines
145 if (ret < 0) {145 if (ret < 0) {
146 av_log(ctx, AV_LOG_ERROR,146 av_log(ctx, AV_LOG_ERROR,
147 "Stretching audio fifo failed, discarded %d samples\n", nb_samples);147 "Stretching audio fifo failed, discarded %d samples\n", nb_samples);
148 return;148 return -1;
149 }149 }
150 }150 }
151 av_audio_fifo_write(asns->fifo, (void **)insamples->extended_data, nb_samples);151 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
155 155
156 if (av_audio_fifo_size(asns->fifo) >= asns->nb_out_samples)156 if (av_audio_fifo_size(asns->fifo) >= asns->nb_out_samples)
157 push_samples(outlink);157 push_samples(outlink);
158 return 0;
158}159}
159 160
160static int request_frame(AVFilterLink *outlink)161static 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
40 return 0;40 return 0;
41}41}
42 42
43static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)43static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
44{44{
45 AVFilterContext *ctx = inlink->dst;45 AVFilterContext *ctx = inlink->dst;
46 ShowInfoContext *showinfo = ctx->priv;46 ShowInfoContext *showinfo = ctx->priv;
@@ -83,7 +83,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) · 36 unmodified lines
83 av_log(ctx, AV_LOG_INFO, "]\n");83 av_log(ctx, AV_LOG_INFO, "]\n");
84 84
85 showinfo->frame++;85 showinfo->frame++;
86 ff_filter_samples(inlink->dst->outputs[0], samplesref);86 return ff_filter_samples(inlink->dst->outputs[0], samplesref);
87}87}
88 88
89AVFilter avfilter_af_ashowinfo = {89AVFilter avfilter_af_ashowinfo = {
libavfilter/af_astreamsync.c+6−3
@@ -107,11 +107,12 @@ static int config_output(AVFilterLink *outlink) · 106 unmodified lines
107 return 0;107 return 0;
108}108}
109 109
110static void send_out(AVFilterContext *ctx, int out_id)110static int send_out(AVFilterContext *ctx, int out_id)
111{111{
112 AStreamSyncContext *as = ctx->priv;112 AStreamSyncContext *as = ctx->priv;
113 struct buf_queue *queue = &as->queue[out_id];113 struct buf_queue *queue = &as->queue[out_id];
114 AVFilterBufferRef *buf = queue->buf[queue->tail];114 AVFilterBufferRef *buf = queue->buf[queue->tail];
115 int ret;
115 116
116 queue->buf[queue->tail] = NULL;117 queue->buf[queue->tail] = NULL;
117 as->var_values[VAR_B1 + out_id]++;118 as->var_values[VAR_B1 + out_id]++;
@@ -121,11 +122,12 @@ static void send_out(AVFilterContext *ctx, int out_id) · 3 unmodified lines
121 av_q2d(ctx->outputs[out_id]->time_base) * buf->pts;122 av_q2d(ctx->outputs[out_id]->time_base) * buf->pts;
122 as->var_values[VAR_T1 + out_id] += buf->audio->nb_samples /123 as->var_values[VAR_T1 + out_id] += buf->audio->nb_samples /
123 (double)ctx->inputs[out_id]->sample_rate;124 (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);
125 queue->nb--;126 queue->nb--;
126 queue->tail = (queue->tail + 1) % QUEUE_SIZE;127 queue->tail = (queue->tail + 1) % QUEUE_SIZE;
127 if (as->req[out_id])128 if (as->req[out_id])
128 as->req[out_id]--;129 as->req[out_id]--;
130 return ret;
129}131}
130 132
131static void send_next(AVFilterContext *ctx)133static void send_next(AVFilterContext *ctx)
@@ -165,7 +167,7 @@ static int request_frame(AVFilterLink *outlink) · 33 unmodified lines
165 return 0;167 return 0;
166}168}
167 169
168static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)170static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
169{171{
170 AVFilterContext *ctx = inlink->dst;172 AVFilterContext *ctx = inlink->dst;
171 AStreamSyncContext *as = ctx->priv;173 AStreamSyncContext *as = ctx->priv;
@@ -175,6 +177,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 3 unmodified lines
175 insamples;177 insamples;
176 as->eof &= ~(1 << id);178 as->eof &= ~(1 << id);
177 send_next(ctx);179 send_next(ctx);
180 return 0;
178}181}
179 182
180AVFilter avfilter_af_astreamsync = {183AVFilter avfilter_af_astreamsync = {
libavfilter/af_asyncts.c+31−17
@@ -37,6 +37,9 @@ typedef struct ASyncContext { · 36 unmodified lines
37 int resample;37 int resample;
38 float min_delta_sec;38 float min_delta_sec;
39 int max_comp;39 int max_comp;
40
41 /* set by filter_samples() to signal an output frame to request_frame() */
42 int got_output;
40} ASyncContext;43} ASyncContext;
41 44
42#define OFFSET(x) offsetof(ASyncContext, x)45#define OFFSET(x) offsetof(ASyncContext, x)
@@ -112,9 +115,13 @@ static int request_frame(AVFilterLink *link) · 69 unmodified lines
112{115{
113 AVFilterContext *ctx = link->src;116 AVFilterContext *ctx = link->src;
114 ASyncContext *s = ctx->priv;117 ASyncContext *s = ctx->priv;
115 int ret = ff_request_frame(ctx->inputs[0]);118 int ret = 0;
116 int nb_samples;119 int nb_samples;
117 120
121 s->got_output = 0;
122 while (ret >= 0 && !s->got_output)
123 ret = ff_request_frame(ctx->inputs[0]);
124
118 /* flush the fifo */125 /* flush the fifo */
119 if (ret == AVERROR_EOF && (nb_samples = avresample_get_delay(s->avr))) {126 if (ret == AVERROR_EOF && (nb_samples = avresample_get_delay(s->avr))) {
120 AVFilterBufferRef *buf = ff_get_audio_buffer(link, AV_PERM_WRITE,127 AVFilterBufferRef *buf = ff_get_audio_buffer(link, AV_PERM_WRITE,
@@ -124,18 +131,18 @@ static int request_frame(AVFilterLink *link) · 3 unmodified lines
124 avresample_convert(s->avr, (void**)buf->extended_data, buf->linesize[0],131 avresample_convert(s->avr, (void**)buf->extended_data, buf->linesize[0],
125 nb_samples, NULL, 0, 0);132 nb_samples, NULL, 0, 0);
126 buf->pts = s->pts;133 buf->pts = s->pts;
127 ff_filter_samples(link, buf);134 return ff_filter_samples(link, buf);
128 return 0;
129 }135 }
130 136
131 return ret;137 return ret;
132}138}
133 139
134static void write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf)140static int write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf)
135{141{
136 avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,142 int ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
137 buf->linesize[0], buf->audio->nb_samples);143 buf->linesize[0], buf->audio->nb_samples);
138 avfilter_unref_buffer(buf);144 avfilter_unref_buffer(buf);
145 return ret;
139}146}
140 147
141/* get amount of data currently buffered, in samples */148/* get amount of data currently buffered, in samples */
@@ -144,7 +151,7 @@ static int64_t get_delay(ASyncContext *s) · 2 unmodified lines
144 return avresample_available(s->avr) + avresample_get_delay(s->avr);151 return avresample_available(s->avr) + avresample_get_delay(s->avr);
145}152}
146 153
147static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)154static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
148{155{
149 AVFilterContext *ctx = inlink->dst;156 AVFilterContext *ctx = inlink->dst;
150 ASyncContext *s = ctx->priv;157 ASyncContext *s = ctx->priv;
@@ -152,7 +159,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 1 unmodified line
152 int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);159 int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);
153 int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :160 int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :
154 av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);161 av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
155 int out_size;162 int out_size, ret;
156 int64_t delta;163 int64_t delta;
157 164
158 /* buffer data until we get the first timestamp */165 /* buffer data until we get the first timestamp */
@@ -160,14 +167,12 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 1 unmodified line
160 if (pts != AV_NOPTS_VALUE) {167 if (pts != AV_NOPTS_VALUE) {
161 s->pts = pts - get_delay(s);168 s->pts = pts - get_delay(s);
162 }169 }
163 write_to_fifo(s, buf);170 return write_to_fifo(s, buf);
164 return;
165 }171 }
166 172
167 /* now wait for the next timestamp */173 /* now wait for the next timestamp */
168 if (pts == AV_NOPTS_VALUE) {174 if (pts == AV_NOPTS_VALUE) {
169 write_to_fifo(s, buf);175 return write_to_fifo(s, buf);
170 return;
171 }176 }
172 177
173 /* when we have two timestamps, compute how many samples would we have178 /* 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
190 if (out_size > 0) {195 if (out_size > 0) {
191 AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,196 AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,
192 out_size);197 out_size);
193 if (!buf_out)198 if (!buf_out) {
194 return;199 ret = AVERROR(ENOMEM);
200 goto fail;
201 }
195 202
196 avresample_read(s->avr, (void**)buf_out->extended_data, out_size);203 avresample_read(s->avr, (void**)buf_out->extended_data, out_size);
197 buf_out->pts = s->pts;204 buf_out->pts = s->pts;
@@ -200,7 +207,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 2 unmodified lines
200 av_samples_set_silence(buf_out->extended_data, out_size - delta,207 av_samples_set_silence(buf_out->extended_data, out_size - delta,
201 delta, nb_channels, buf->format);208 delta, nb_channels, buf->format);
202 }209 }
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;
204 } else {214 } else {
205 av_log(ctx, AV_LOG_WARNING, "Non-monotonous timestamps, dropping "215 av_log(ctx, AV_LOG_WARNING, "Non-monotonous timestamps, dropping "
206 "whole buffer.\n");216 "whole buffer.\n");
@@ -210,9 +220,13 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 3 unmodified lines
210 avresample_read(s->avr, NULL, avresample_available(s->avr));220 avresample_read(s->avr, NULL, avresample_available(s->avr));
211 221
212 s->pts = pts - avresample_get_delay(s->avr);222 s->pts = pts - avresample_get_delay(s->avr);
213 avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,223 ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
214 buf->linesize[0], buf->audio->nb_samples);224 buf->linesize[0], buf->audio->nb_samples);
225
226fail:
215 avfilter_unref_buffer(buf);227 avfilter_unref_buffer(buf);
228
229 return ret;
216}230}
217 231
218AVFilter avfilter_af_asyncts = {232AVFilter avfilter_af_asyncts = {
libavfilter/af_atempo.c+2−1
@@ -1040,7 +1040,7 @@ static void push_samples(ATempoContext *atempo, · 1039 unmodified lines
1040 atempo->nsamples_out += n_out;1040 atempo->nsamples_out += n_out;
1041}1041}
1042 1042
1043static void filter_samples(AVFilterLink *inlink,1043static int filter_samples(AVFilterLink *inlink,
1044 AVFilterBufferRef *src_buffer)1044 AVFilterBufferRef *src_buffer)
1045{1045{
1046 AVFilterContext *ctx = inlink->dst;1046 AVFilterContext *ctx = inlink->dst;
@@ -1074,6 +1074,7 @@ static void filter_samples(AVFilterLink *inlink, · 27 unmodified lines
1074 1074
1075 atempo->nsamples_in += n_in;1075 atempo->nsamples_in += n_in;
1076 avfilter_unref_bufferp(&src_buffer);1076 avfilter_unref_bufferp(&src_buffer);
1077 return 0;
1077}1078}
1078 1079
1079static int request_frame(AVFilterLink *outlink)1080static 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
313 return 0;313 return 0;
314}314}
315 315
316static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)316static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
317{317{
318 AVFilterContext *ctx = inlink->dst;318 AVFilterContext *ctx = inlink->dst;
319 AVFilterLink *outlink = ctx->outputs[0];319 AVFilterLink *outlink = ctx->outputs[0];
@@ -330,8 +330,10 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b · 10 unmodified lines
330 if (nch_out > FF_ARRAY_ELEMS(buf->data)) {330 if (nch_out > FF_ARRAY_ELEMS(buf->data)) {
331 uint8_t **new_extended_data =331 uint8_t **new_extended_data =
332 av_mallocz(nch_out * sizeof(*buf->extended_data));332 av_mallocz(nch_out * sizeof(*buf->extended_data));
333 if (!new_extended_data)333 if (!new_extended_data) {
334 return;334 avfilter_unref_buffer(buf);
335 return AVERROR(ENOMEM);
336 }
335 if (buf->extended_data == buf->data) {337 if (buf->extended_data == buf->data) {
336 buf->extended_data = new_extended_data;338 buf->extended_data = new_extended_data;
337 } else {339 } else {
@@ -353,7 +355,7 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b · 15 unmodified lines
353 memcpy(buf->data, buf->extended_data,355 memcpy(buf->data, buf->extended_data,
354 FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));356 FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0]));
355 357
356 ff_filter_samples(outlink, buf);358 return ff_filter_samples(outlink, buf);
357}359}
358 360
359static int channelmap_config_input(AVFilterLink *inlink)361static 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
105 return 0;105 return 0;
106}106}
107 107
108static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)108static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
109{109{
110 AVFilterContext *ctx = inlink->dst;110 AVFilterContext *ctx = inlink->dst;
111 int i;111 int i, ret = 0;
112 112
113 for (i = 0; i < ctx->nb_outputs; i++) {113 for (i = 0; i < ctx->nb_outputs; i++) {
114 AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE);114 AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE);
115 115
116 if (!buf_out)116 if (!buf_out) {
117 return;117 ret = AVERROR(ENOMEM);
118 break;
119 }
118 120
119 buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i];121 buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i];
120 buf_out->audio->channel_layout =122 buf_out->audio->channel_layout =
121 av_channel_layout_extract_channel(buf->audio->channel_layout, i);123 av_channel_layout_extract_channel(buf->audio->channel_layout, i);
122 124
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;
124 }128 }
125 avfilter_unref_buffer(buf);129 avfilter_unref_buffer(buf);
130 return ret;
126}131}
127 132
128AVFilter avfilter_af_channelsplit = {133AVFilter 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
120 return out;120 return out;
121}121}
122 122
123static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)123static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
124{124{
125 AVFilterLink *outlink = inlink->dst->outputs[0];125 AVFilterLink *outlink = inlink->dst->outputs[0];
126 int16_t *taps, *endin, *in, *out;126 int16_t *taps, *endin, *in, *out;
127 AVFilterBufferRef *outsamples =127 AVFilterBufferRef *outsamples =
128 ff_get_audio_buffer(inlink, AV_PERM_WRITE,128 ff_get_audio_buffer(inlink, AV_PERM_WRITE,
129 insamples->audio->nb_samples);129 insamples->audio->nb_samples);
130 int ret;
131
130 avfilter_copy_buffer_ref_props(outsamples, insamples);132 avfilter_copy_buffer_ref_props(outsamples, insamples);
131 133
132 taps = ((EarwaxContext *)inlink->dst->priv)->taps;134 taps = ((EarwaxContext *)inlink->dst->priv)->taps;
@@ -144,8 +146,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 11 unmodified lines
144 // save part of input for next round146 // save part of input for next round
145 memcpy(taps, endin, NUMTAPS * sizeof(*taps));147 memcpy(taps, endin, NUMTAPS * sizeof(*taps));
146 148
147 ff_filter_samples(outlink, outsamples);149 ret = ff_filter_samples(outlink, outsamples);
148 avfilter_unref_buffer(insamples);150 avfilter_unref_buffer(insamples);
151 return ret;
149}152}
150 153
151AVFilter avfilter_af_earwax = {154AVFilter avfilter_af_earwax = {
libavfilter/af_join.c+5−3
@@ -92,7 +92,7 @@ static const AVClass join_class = { · 91 unmodified lines
92 .version = LIBAVUTIL_VERSION_INT,92 .version = LIBAVUTIL_VERSION_INT,
93};93};
94 94
95static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)95static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
96{96{
97 AVFilterContext *ctx = link->dst;97 AVFilterContext *ctx = link->dst;
98 JoinContext *s = ctx->priv;98 JoinContext *s = ctx->priv;
@@ -104,6 +104,8 @@ static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) · 5 unmodified lines
104 av_assert0(i < ctx->nb_inputs);104 av_assert0(i < ctx->nb_inputs);
105 av_assert0(!s->input_frames[i]);105 av_assert0(!s->input_frames[i]);
106 s->input_frames[i] = buf;106 s->input_frames[i] = buf;
107
108 return 0;
107}109}
108 110
109static int parse_maps(AVFilterContext *ctx)111static int parse_maps(AVFilterContext *ctx)
@@ -468,11 +470,11 @@ static int join_request_frame(AVFilterLink *outlink) · 358 unmodified lines
468 priv->nb_in_buffers = ctx->nb_inputs;470 priv->nb_in_buffers = ctx->nb_inputs;
469 buf->buf->priv = priv;471 buf->buf->priv = priv;
470 472
471 ff_filter_samples(outlink, buf);473 ret = ff_filter_samples(outlink, buf);
472 474
473 memset(s->input_frames, 0, sizeof(*s->input_frames) * ctx->nb_inputs);475 memset(s->input_frames, 0, sizeof(*s->input_frames) * ctx->nb_inputs);
474 476
475 return 0;477 return ret;
476 478
477fail:479fail:
478 avfilter_unref_buffer(buf);480 avfilter_unref_buffer(buf);
libavfilter/af_pan.c+4−2
@@ -343,8 +343,9 @@ static int config_props(AVFilterLink *link) · 342 unmodified lines
343 return 0;343 return 0;
344}344}
345 345
346static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)346static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
347{347{
348 int ret;
348 int n = insamples->audio->nb_samples;349 int n = insamples->audio->nb_samples;
349 AVFilterLink *const outlink = inlink->dst->outputs[0];350 AVFilterLink *const outlink = inlink->dst->outputs[0];
350 AVFilterBufferRef *outsamples = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);351 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
354 avfilter_copy_buffer_ref_props(outsamples, insamples);355 avfilter_copy_buffer_ref_props(outsamples, insamples);
355 outsamples->audio->channel_layout = outlink->channel_layout;356 outsamples->audio->channel_layout = outlink->channel_layout;
356 357
357 ff_filter_samples(outlink, outsamples);358 ret = ff_filter_samples(outlink, outsamples);
358 avfilter_unref_buffer(insamples);359 avfilter_unref_buffer(insamples);
360 return ret;
359}361}
360 362
361static av_cold void uninit(AVFilterContext *ctx)363static av_cold void uninit(AVFilterContext *ctx)
libavfilter/af_resample.c+31−14
@@ -38,6 +38,9 @@ typedef struct ResampleContext { · 37 unmodified lines
38 AVAudioResampleContext *avr;38 AVAudioResampleContext *avr;
39 39
40 int64_t next_pts;40 int64_t next_pts;
41
42 /* set by filter_samples() to signal an output frame to request_frame() */
43 int got_output;
41} ResampleContext;44} ResampleContext;
42 45
43static av_cold void uninit(AVFilterContext *ctx)46static av_cold void uninit(AVFilterContext *ctx)
@@ -102,12 +105,6 @@ static int config_output(AVFilterLink *outlink) · 58 unmodified lines
102 av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);105 av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);
103 av_opt_set_int(s->avr, "out_sample_rate", outlink->sample_rate, 0);106 av_opt_set_int(s->avr, "out_sample_rate", outlink->sample_rate, 0);
104 107
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
111 if ((ret = avresample_open(s->avr)) < 0)108 if ((ret = avresample_open(s->avr)) < 0)
112 return ret;109 return ret;
113 110
@@ -130,7 +127,11 @@ static int request_frame(AVFilterLink *outlink) · 16 unmodified lines
130{127{
131 AVFilterContext *ctx = outlink->src;128 AVFilterContext *ctx = outlink->src;
132 ResampleContext *s = ctx->priv;129 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]);
134 135
135 /* flush the lavr delay buffer */136 /* flush the lavr delay buffer */
136 if (ret == AVERROR_EOF && s->avr) {137 if (ret == AVERROR_EOF && s->avr) {
@@ -156,21 +157,21 @@ static int request_frame(AVFilterLink *outlink) · 19 unmodified lines
156 }157 }
157 158
158 buf->pts = s->next_pts;159 buf->pts = s->next_pts;
159 ff_filter_samples(outlink, buf);160 return ff_filter_samples(outlink, buf);
160 return 0;
161 }161 }
162 return ret;162 return ret;
163}163}
164 164
165static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)165static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
166{166{
167 AVFilterContext *ctx = inlink->dst;167 AVFilterContext *ctx = inlink->dst;
168 ResampleContext *s = ctx->priv;168 ResampleContext *s = ctx->priv;
169 AVFilterLink *outlink = ctx->outputs[0];169 AVFilterLink *outlink = ctx->outputs[0];
170 int ret;
170 171
171 if (s->avr) {172 if (s->avr) {
172 AVFilterBufferRef *buf_out;173 AVFilterBufferRef *buf_out;
173 int delay, nb_samples, ret;174 int delay, nb_samples;
174 175
175 /* maximum possible samples lavr can output */176 /* maximum possible samples lavr can output */
176 delay = avresample_get_delay(s->avr);177 delay = avresample_get_delay(s->avr);
@@ -179,10 +180,19 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 2 unmodified lines
179 AV_ROUND_UP);180 AV_ROUND_UP);
180 181
181 buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples);182 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
182 ret = avresample_convert(s->avr, (void**)buf_out->extended_data,188 ret = avresample_convert(s->avr, (void**)buf_out->extended_data,
183 buf_out->linesize[0], nb_samples,189 buf_out->linesize[0], nb_samples,
184 (void**)buf->extended_data, buf->linesize[0],190 (void**)buf->extended_data, buf->linesize[0],
185 buf->audio->nb_samples);191 buf->audio->nb_samples);
192 if (ret < 0) {
193 avfilter_unref_buffer(buf_out);
194 goto fail;
195 }
186 196
187 av_assert0(!avresample_available(s->avr));197 av_assert0(!avresample_available(s->avr));
188 198
@@ -208,11 +218,18 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 19 unmodified lines
208 218
209 s->next_pts = buf_out->pts + buf_out->audio->nb_samples;219 s->next_pts = buf_out->pts + buf_out->audio->nb_samples;
210 220
211 ff_filter_samples(outlink, buf_out);221 ret = ff_filter_samples(outlink, buf_out);
222 s->got_output = 1;
212 }223 }
224
225fail:
213 avfilter_unref_buffer(buf);226 avfilter_unref_buffer(buf);
214 } else227 } else {
215 ff_filter_samples(outlink, buf);228 ret = ff_filter_samples(outlink, buf);
229 s->got_output = 1;
230 }
231
232 return ret;
216}233}
217 234
218AVFilter avfilter_af_resample = {235AVFilter 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
78 return 0;78 return 0;
79}79}
80 80
81static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)81static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
82{82{
83 int i;83 int i;
84 SilenceDetectContext *silence = inlink->dst->priv;84 SilenceDetectContext *silence = inlink->dst->priv;
@@ -118,7 +118,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 33 unmodified lines
118 }118 }
119 }119 }
120 120
121 ff_filter_samples(inlink->dst->outputs[0], insamples);121 return ff_filter_samples(inlink->dst->outputs[0], insamples);
122}122}
123 123
124static int query_formats(AVFilterContext *ctx)124static int query_formats(AVFilterContext *ctx)
libavfilter/af_volume.c+2−2
@@ -110,7 +110,7 @@ static int query_formats(AVFilterContext *ctx) · 109 unmodified lines
110 return 0;110 return 0;
111}111}
112 112
113static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)113static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
114{114{
115 VolumeContext *vol = inlink->dst->priv;115 VolumeContext *vol = inlink->dst->priv;
116 AVFilterLink *outlink = inlink->dst->outputs[0];116 AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -169,7 +169,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 52 unmodified lines
169 }169 }
170 }170 }
171 }171 }
172 ff_filter_samples(outlink, insamples);172 return ff_filter_samples(outlink, insamples);
173}173}
174 174
175AVFilter avfilter_af_volume = {175AVFilter avfilter_af_volume = {
libavfilter/asink_anullsink.c+4−1
@@ -21,7 +21,10 @@ · 20 unmodified lines
21#include "avfilter.h"21#include "avfilter.h"
22#include "internal.h"22#include "internal.h"
23 23
24static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { }24static int null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
25{
26 return 0;
27}
25 28
26AVFilter avfilter_asink_anullsink = {29AVFilter avfilter_asink_anullsink = {
27 .name = "anullsink",30 .name = "anullsink",
libavfilter/audio.c+14−12
@@ -150,19 +150,19 @@ fail: · 149 unmodified lines
150 return NULL;150 return NULL;
151}151}
152 152
153static void default_filter_samples(AVFilterLink *link,153static int default_filter_samples(AVFilterLink *link,
154 AVFilterBufferRef *samplesref)154 AVFilterBufferRef *samplesref)
155{155{
156 ff_filter_samples(link->dst->outputs[0], samplesref);156 return ff_filter_samples(link->dst->outputs[0], samplesref);
157}157}
158 158
159void ff_filter_samples_framed(AVFilterLink *link,159int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref)
160 AVFilterBufferRef *samplesref)
161{160{
162 void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);161 int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
163 AVFilterPad *dst = link->dstpad;162 AVFilterPad *dst = link->dstpad;
164 int64_t pts;163 int64_t pts;
165 AVFilterBufferRef *buf_out;164 AVFilterBufferRef *buf_out;
165 int ret;
166 166
167 FF_TPRINTF_START(NULL, filter_samples); ff_tlog_link(NULL, link, 1);167 FF_TPRINTF_START(NULL, filter_samples); ff_tlog_link(NULL, link, 1);
168 168
@@ -193,21 +193,22 @@ void ff_filter_samples_framed(AVFilterLink *link, · 24 unmodified lines
193 193
194 link->cur_buf = buf_out;194 link->cur_buf = buf_out;
195 pts = buf_out->pts;195 pts = buf_out->pts;
196 filter_samples(link, buf_out);196 ret = filter_samples(link, buf_out);
197 ff_update_link_current_pts(link, pts);197 ff_update_link_current_pts(link, pts);
198 return ret;
198}199}
199 200
200void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)201int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
201{202{
202 int insamples = samplesref->audio->nb_samples, inpos = 0, nb_samples;203 int insamples = samplesref->audio->nb_samples, inpos = 0, nb_samples;
203 AVFilterBufferRef *pbuf = link->partial_buf;204 AVFilterBufferRef *pbuf = link->partial_buf;
204 int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);205 int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
206 int ret = 0;
205 207
206 if (!link->min_samples ||208 if (!link->min_samples ||
207 (!pbuf &&209 (!pbuf &&
208 insamples >= link->min_samples && insamples <= link->max_samples)) {210 insamples >= link->min_samples && insamples <= link->max_samples)) {
209 ff_filter_samples_framed(link, samplesref);211 return ff_filter_samples_framed(link, samplesref);
210 return;
211 }212 }
212 /* Handle framing (min_samples, max_samples) */213 /* Handle framing (min_samples, max_samples) */
213 while (insamples) {214 while (insamples) {
@@ -218,7 +219,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 4 unmodified lines
218 if (!pbuf) {219 if (!pbuf) {
219 av_log(link->dst, AV_LOG_WARNING,220 av_log(link->dst, AV_LOG_WARNING,
220 "Samples dropped due to memory allocation failure.\n");221 "Samples dropped due to memory allocation failure.\n");
221 return;222 return 0;
222 }223 }
223 avfilter_copy_buffer_ref_props(pbuf, samplesref);224 avfilter_copy_buffer_ref_props(pbuf, samplesref);
224 pbuf->pts = samplesref->pts +225 pbuf->pts = samplesref->pts +
@@ -234,10 +235,11 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 9 unmodified lines
234 insamples -= nb_samples;235 insamples -= nb_samples;
235 pbuf->audio->nb_samples += nb_samples;236 pbuf->audio->nb_samples += nb_samples;
236 if (pbuf->audio->nb_samples >= link->min_samples) {237 if (pbuf->audio->nb_samples >= link->min_samples) {
237 ff_filter_samples_framed(link, pbuf);238 ret = ff_filter_samples_framed(link, pbuf);
238 pbuf = NULL;239 pbuf = NULL;
239 }240 }
240 }241 }
241 avfilter_unref_buffer(samplesref);242 avfilter_unref_buffer(samplesref);
242 link->partial_buf = pbuf;243 link->partial_buf = pbuf;
244 return ret;
243}245}
libavfilter/audio.h+5−2
@@ -70,14 +70,17 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 69 unmodified lines
70 * @param samplesref a reference to the buffer of audio samples being sent. The70 * @param samplesref a reference to the buffer of audio samples being sent. The
71 * receiving filter will free this reference when it no longer71 * receiving filter will free this reference when it no longer
72 * needs it or pass it on to the next filter.72 * 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.
73 */76 */
74void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);77int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref);
75 78
76/**79/**
77 * Send a buffer of audio samples to the next link, without checking80 * Send a buffer of audio samples to the next link, without checking
78 * min_samples.81 * min_samples.
79 */82 */
80void ff_filter_samples_framed(AVFilterLink *link,83int ff_filter_samples_framed(AVFilterLink *link,
81 AVFilterBufferRef *samplesref);84 AVFilterBufferRef *samplesref);
82 85
83#endif /* AVFILTER_AUDIO_H */86#endif /* AVFILTER_AUDIO_H */
libavfilter/avf_showwaves.c+2−1
@@ -180,7 +180,7 @@ static int request_frame(AVFilterLink *outlink) · 179 unmodified lines
180 180
181#define MAX_INT16 ((1<<15) -1)181#define MAX_INT16 ((1<<15) -1)
182 182
183static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)183static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
184{184{
185 AVFilterContext *ctx = inlink->dst;185 AVFilterContext *ctx = inlink->dst;
186 AVFilterLink *outlink = ctx->outputs[0];186 AVFilterLink *outlink = ctx->outputs[0];
@@ -225,6 +225,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 38 unmodified lines
225 }225 }
226 226
227 avfilter_unref_buffer(insamples);227 avfilter_unref_buffer(insamples);
228 return 0;
228}229}
229 230
230AVFilter avfilter_avf_showwaves = {231AVFilter avfilter_avf_showwaves = {
libavfilter/avfilter.h+5−1
@@ -301,8 +301,12 @@ struct AVFilterPad { · 300 unmodified lines
301 * and should do its processing.301 * and should do its processing.
302 *302 *
303 * Input audio pads only.303 * 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.
304 */308 */
305 void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);309 int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
306 310
307 /**311 /**
308 * Frame poll callback. This returns the number of immediately available312 * 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
56 link->cur_buf = NULL;56 link->cur_buf = NULL;
57};57};
58 58
59static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
60{
61 start_frame(link, buf);
62 return 0;
63}
64
59int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)65int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
60{66{
61 BufferSinkContext *s = ctx->priv;67 BufferSinkContext *s = ctx->priv;
@@ -160,7 +166,7 @@ AVFilter avfilter_asink_abuffer = { · 98 unmodified lines
160 166
161 .inputs = (AVFilterPad[]) {{ .name = "default",167 .inputs = (AVFilterPad[]) {{ .name = "default",
162 .type = AVMEDIA_TYPE_AUDIO,168 .type = AVMEDIA_TYPE_AUDIO,
163 .filter_samples = start_frame,169 .filter_samples = filter_samples,
164 .min_perms = AV_PERM_READ,170 .min_perms = AV_PERM_READ,
165 .needs_fifo = 1 },171 .needs_fifo = 1 },
166 { .name = NULL }},172 { .name = NULL }},
libavfilter/buffersrc.c+3−2
@@ -408,6 +408,7 @@ static int request_frame(AVFilterLink *link) · 407 unmodified lines
408{408{
409 BufferSourceContext *c = link->src->priv;409 BufferSourceContext *c = link->src->priv;
410 AVFilterBufferRef *buf;410 AVFilterBufferRef *buf;
411 int ret = 0;
411 412
412 if (!av_fifo_size(c->fifo)) {413 if (!av_fifo_size(c->fifo)) {
413 if (c->eof)414 if (c->eof)
@@ -424,7 +425,7 @@ static int request_frame(AVFilterLink *link) · 10 unmodified lines
424 ff_end_frame(link);425 ff_end_frame(link);
425 break;426 break;
426 case AVMEDIA_TYPE_AUDIO:427 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));
428 break;429 break;
429 default:430 default:
430 return AVERROR(EINVAL);431 return AVERROR(EINVAL);
@@ -432,7 +433,7 @@ static int request_frame(AVFilterLink *link) · 1 unmodified line
432 433
433 avfilter_unref_buffer(buf);434 avfilter_unref_buffer(buf);
434 435
435 return 0;436 return ret;
436}437}
437 438
438static int poll_frame(AVFilterLink *link)439static 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
117 ff_start_frame(outlink, picref2);117 ff_start_frame(outlink, picref2);
118}118}
119 119
120static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)120static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
121{121{
122 AVFilterContext *ctx = inlink->dst;122 AVFilterContext *ctx = inlink->dst;
123 AVFilterLink *outlink = ctx->outputs[0];123 AVFilterLink *outlink = ctx->outputs[0];
@@ -132,7 +132,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 8 unmodified lines
132 avfilter_unref_buffer(insamples);132 avfilter_unref_buffer(insamples);
133 }133 }
134 134
135 ff_filter_samples(outlink, outsamples);135 return ff_filter_samples(outlink, outsamples);
136}136}
137 137
138#if CONFIG_SETTB_FILTER138#if CONFIG_SETTB_FILTER
libavfilter/fifo.c+18−8
@@ -72,13 +72,25 @@ static av_cold void uninit(AVFilterContext *ctx) · 71 unmodified lines
72 avfilter_unref_buffer(fifo->buf_out);72 avfilter_unref_buffer(fifo->buf_out);
73}73}
74 74
75static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)75static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf)
76{76{
77 FifoContext *fifo = inlink->dst->priv;77 FifoContext *fifo = inlink->dst->priv;
78 78
79 fifo->last->next = av_mallocz(sizeof(Buf));79 fifo->last->next = av_mallocz(sizeof(Buf));
80 if (!fifo->last->next) {
81 avfilter_unref_buffer(buf);
82 return AVERROR(ENOMEM);
83 }
84
80 fifo->last = fifo->last->next;85 fifo->last = fifo->last->next;
81 fifo->last->buf = buf;86 fifo->last->buf = buf;
87
88 return 0;
89}
90
91static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *buf)
92{
93 add_to_queue(inlink, buf);
82}94}
83 95
84static void queue_pop(FifoContext *s)96static void queue_pop(FifoContext *s)
@@ -210,15 +222,13 @@ static int return_audio_frame(AVFilterContext *ctx) · 125 unmodified lines
210 buf_out = s->buf_out;222 buf_out = s->buf_out;
211 s->buf_out = NULL;223 s->buf_out = NULL;
212 }224 }
213 ff_filter_samples(link, buf_out);225 return ff_filter_samples(link, buf_out);
214
215 return 0;
216}226}
217 227
218static int request_frame(AVFilterLink *outlink)228static int request_frame(AVFilterLink *outlink)
219{229{
220 FifoContext *fifo = outlink->src->priv;230 FifoContext *fifo = outlink->src->priv;
221 int ret;231 int ret = 0;
222 232
223 if (!fifo->root.next) {233 if (!fifo->root.next) {
224 if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0)234 if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0)
@@ -238,7 +248,7 @@ static int request_frame(AVFilterLink *outlink) · 13 unmodified lines
238 if (outlink->request_samples) {248 if (outlink->request_samples) {
239 return return_audio_frame(outlink->src);249 return return_audio_frame(outlink->src);
240 } else {250 } else {
241 ff_filter_samples(outlink, fifo->root.next->buf);251 ret = ff_filter_samples(outlink, fifo->root.next->buf);
242 queue_pop(fifo);252 queue_pop(fifo);
243 }253 }
244 break;254 break;
@@ -246,7 +256,7 @@ static int request_frame(AVFilterLink *outlink) · 1 unmodified line
246 return AVERROR(EINVAL);256 return AVERROR(EINVAL);
247 }257 }
248 258
249 return 0;259 return ret;
250}260}
251 261
252AVFilter avfilter_vf_fifo = {262AVFilter avfilter_vf_fifo = {
@@ -261,7 +271,7 @@ AVFilter avfilter_vf_fifo = { · 8 unmodified lines
261 .inputs = (const AVFilterPad[]) {{ .name = "default",271 .inputs = (const AVFilterPad[]) {{ .name = "default",
262 .type = AVMEDIA_TYPE_VIDEO,272 .type = AVMEDIA_TYPE_VIDEO,
263 .get_video_buffer= ff_null_get_video_buffer,273 .get_video_buffer= ff_null_get_video_buffer,
264 .start_frame = add_to_queue,274 .start_frame = start_frame,
265 .draw_slice = draw_slice,275 .draw_slice = draw_slice,
266 .end_frame = end_frame,276 .end_frame = end_frame,
267 .rej_perms = AV_PERM_REUSE2, },277 .rej_perms = AV_PERM_REUSE2, },
libavfilter/internal.h+5−1
@@ -135,8 +135,12 @@ struct AVFilterPad { · 134 unmodified lines
135 * and should do its processing.135 * and should do its processing.
136 *136 *
137 * Input audio pads only.137 * 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.
138 */142 */
139 void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);143 int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref);
140 144
141 /**145 /**
142 * Frame poll callback. This returns the number of immediately available146 * 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
244 244
245#if CONFIG_ABUFFERSINK_FILTER245#if CONFIG_ABUFFERSINK_FILTER
246 246
247static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)247static int filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
248{248{
249 end_frame(link);249 end_frame(link);
250 return 0;
250}251}
251 252
252static av_cold int asink_init(AVFilterContext *ctx, const char *args)253static 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
110 .outputs = (AVFilterPad[]) {{ .name = NULL}},110 .outputs = (AVFilterPad[]) {{ .name = NULL}},
111};111};
112 112
113static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)113static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
114{114{
115 AVFilterContext *ctx = inlink->dst;115 AVFilterContext *ctx = inlink->dst;
116 int i;116 int i, ret = 0;
117 117
118 for (i = 0; i < ctx->nb_outputs; i++)118 for (i = 0; i < ctx->nb_outputs; i++) {
119 ff_filter_samples(inlink->dst->outputs[i],119 ret = ff_filter_samples(inlink->dst->outputs[i],
120 avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));120 avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE));
121 if (ret < 0)
122 break;
123 }
121 avfilter_unref_buffer(samplesref);124 avfilter_unref_buffer(samplesref);
125 return ret;
122}126}
123 127
124AVFilter avfilter_af_asplit = {128AVFilter avfilter_af_asplit = {
libavformat/matroskadec.c+4−1
@@ -842,8 +842,11 @@ static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, · 841 unmodified lines
842 matroska->num_levels > 0 &&842 matroska->num_levels > 0 &&
843 matroska->levels[matroska->num_levels-1].length == 0xffffffffffffff)843 matroska->levels[matroska->num_levels-1].length == 0xffffffffffffff)
844 return 0; // we reached the end of an unknown size cluster844 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) {
846 av_log(matroska->ctx, AV_LOG_INFO, "Unknown entry 0x%X\n", id);846 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 }
847 return ebml_parse_elem(matroska, &syntax[i], data);850 return ebml_parse_elem(matroska, &syntax[i], data);
848}851}
849 852
libavformat/tcp.c+10−1
@@ -43,7 +43,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 42 unmodified lines
43 char buf[256];43 char buf[256];
44 int ret;44 int ret;
45 socklen_t optlen;45 socklen_t optlen;
46 int timeout = 50;46 int timeout = 50, listen_timeout = -1;
47 char hostname[1024],proto[1024],path[1024];47 char hostname[1024],proto[1024],path[1024];
48 char portstr[10];48 char portstr[10];
49 49
@@ -59,6 +59,9 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 9 unmodified lines
59 if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {59 if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) {
60 timeout = strtol(buf, NULL, 10);60 timeout = strtol(buf, NULL, 10);
61 }61 }
62 if (av_find_info_tag(buf, sizeof(buf), "listen_timeout", p)) {
63 listen_timeout = strtol(buf, NULL, 10);
64 }
62 }65 }
63 hints.ai_family = AF_UNSPEC;66 hints.ai_family = AF_UNSPEC;
64 hints.ai_socktype = SOCK_STREAM;67 hints.ai_socktype = SOCK_STREAM;
@@ -87,6 +90,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 22 unmodified lines
87 if (listen_socket) {90 if (listen_socket) {
88 int fd1;91 int fd1;
89 int reuse = 1;92 int reuse = 1;
93 struct pollfd lp = { fd, POLLIN, 0 };
90 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));94 setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse));
91 ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);95 ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen);
92 if (ret) {96 if (ret) {
@@ -98,6 +102,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 5 unmodified lines
98 ret = ff_neterrno();102 ret = ff_neterrno();
99 goto fail1;103 goto fail1;
100 }104 }
105 ret = poll(&lp, 1, listen_timeout >= 0 ? listen_timeout : -1);
106 if (ret <= 0) {
107 ret = AVERROR(ETIMEDOUT);
108 goto fail1;
109 }
101 fd1 = accept(fd, NULL, NULL);110 fd1 = accept(fd, NULL, NULL);
102 if (fd1 < 0) {111 if (fd1 < 0) {
103 ret = ff_neterrno();112 ret = ff_neterrno();
libavresample/audio_mix.c+8−0
@@ -305,6 +305,14 @@ int ff_audio_mix_init(AVAudioResampleContext *avr) · 304 unmodified lines
305{305{
306 int ret;306 int ret;
307 307
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
308 /* build matrix if the user did not already set one */316 /* build matrix if the user did not already set one */
309 if (!avr->am->matrix) {317 if (!avr->am->matrix) {
310 int i, j;318 int i, j;
libavresample/avresample.h+7−0
@@ -45,6 +45,13 @@ enum AVMixCoeffType { · 44 unmodified lines
45 AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */45 AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */
46};46};
47 47
48/** Resampling Filter Types */
49enum 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
48/**55/**
49 * Return the LIBAVRESAMPLE_VERSION_INT constant.56 * Return the LIBAVRESAMPLE_VERSION_INT constant.
50 */57 */
libavresample/internal.h+2−0
@@ -50,6 +50,8 @@ struct AVAudioResampleContext { · 49 unmodified lines
50 int phase_shift; /**< log2 of the number of entries in the resampling polyphase filterbank */50 int phase_shift; /**< log2 of the number of entries in the resampling polyphase filterbank */
51 int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */51 int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */
52 double cutoff; /**< resampling cutoff frequency. 1.0 corresponds to half the output sample rate */52 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) */
53 55
54 int in_channels; /**< number of input channels */56 int in_channels; /**< number of input channels */
55 int out_channels; /**< number of output channels */57 int out_channels; /**< number of output channels */
libavresample/options.c+6−1
@@ -39,7 +39,7 @@ static const AVOption options[] = { · 38 unmodified lines
39 { "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM },39 { "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM },
40 { "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 },40 { "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 },
41 { "out_sample_rate", "Output Sample Rate", OFFSET(out_sample_rate), AV_OPT_TYPE_INT, { 48000 }, 1, INT_MAX, PARAM },41 { "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 },
43 { "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" },43 { "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" },
44 { "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" },44 { "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" },
45 { "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" },45 { "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
56 { "none", "None", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },56 { "none", "None", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
57 { "dolby", "Dolby", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },57 { "dolby", "Dolby", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },
58 { "dplii", "Dolby Pro Logic II", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DPLII }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" },58 { "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 },
59 { NULL },64 { NULL },
60};65};
61 66
libavresample/resample.c+85−95
@@ -24,37 +24,10 @@ · 23 unmodified lines
24#include "internal.h"24#include "internal.h"
25#include "audio_data.h"25#include "audio_data.h"
26 26
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
54struct ResampleContext {27struct ResampleContext {
55 AVAudioResampleContext *avr;28 AVAudioResampleContext *avr;
56 AudioData *buffer;29 AudioData *buffer;
57 FELEM *filter_bank;30 uint8_t *filter_bank;
58 int filter_length;31 int filter_length;
59 int ideal_dst_incr;32 int ideal_dst_incr;
60 int dst_incr;33 int dst_incr;
@@ -65,9 +38,35 @@ struct ResampleContext { · 4 unmodified lines
65 int phase_shift;38 int phase_shift;
66 int phase_mask;39 int phase_mask;
67 int linear;40 int linear;
41 enum AVResampleFilterType filter_type;
42 int kaiser_beta;
68 double factor;43 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);
69};48};
70 49
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
71/**70/**
72 * 0th order modified bessel function of the first kind.71 * 0th order modified bessel function of the first kind.
73 */72 */
@@ -95,17 +94,17 @@ static double bessel(double x) · 21 unmodified lines
95 * @param tap_count tap count94 * @param tap_count tap count
96 * @param phase_count phase count95 * @param phase_count phase count
97 * @param scale wanted sum of coefficients for each filter96 * @param scale wanted sum of coefficients for each filter
98 * @param type 0->cubic97 * @param filter_type filter type
99 * 1->blackman nuttall windowed sinc98 * @param kaiser_beta kaiser window beta
100 * 2..16->kaiser windowed sinc beta=2..16
101 * @return 0 on success, negative AVERROR code on failure99 * @return 0 on success, negative AVERROR code on failure
102 */100 */
103static int build_filter(FELEM *filter, double factor, int tap_count,101static int build_filter(ResampleContext *c)
104 int phase_count, int scale, int type)
105{102{
106 int ph, i;103 int ph, i;
107 double x, y, w;104 double x, y, w, factor;
108 double *tab;105 double *tab;
106 int tap_count = c->filter_length;
107 int phase_count = 1 << c->phase_shift;
109 const int center = (tap_count - 1) / 2;108 const int center = (tap_count - 1) / 2;
110 109
111 tab = av_malloc(tap_count * sizeof(*tab));110 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
113 return AVERROR(ENOMEM);112 return AVERROR(ENOMEM);
114 113
115 /* if upsampling, only need to interpolate, no filter */114 /* if upsampling, only need to interpolate, no filter */
116 if (factor > 1.0)115 factor = FFMIN(c->factor, 1.0);
117 factor = 1.0;
118 116
119 for (ph = 0; ph < phase_count; ph++) {117 for (ph = 0; ph < phase_count; ph++) {
120 double norm = 0;118 double norm = 0;
@@ -122,39 +120,34 @@ static int build_filter(FELEM *filter, double factor, int tap_count, · 1 unmodified line
122 x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;120 x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor;
123 if (x == 0) y = 1.0;121 if (x == 0) y = 1.0;
124 else y = sin(x) / x;122 else y = sin(x) / x;
125 switch (type) {123 switch (c->filter_type) {
126 case 0: {124 case AV_RESAMPLE_FILTER_TYPE_CUBIC: {
127 const float d = -0.5; //first order derivative = -0.5125 const float d = -0.5; //first order derivative = -0.5
128 x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);126 x = fabs(((double)(i - center) - (double)ph / phase_count) * factor);
129 if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);127 if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x);
130 else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);128 else y = d * (-4 + 8 * x - 5 * x*x + x*x*x);
131 break;129 break;
132 }130 }
133 case 1:131 case AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL:
134 w = 2.0 * x / (factor * tap_count) + M_PI;132 w = 2.0 * x / (factor * tap_count) + M_PI;
135 y *= 0.3635819 - 0.4891775 * cos( w) +133 y *= 0.3635819 - 0.4891775 * cos( w) +
136 0.1365995 * cos(2 * w) -134 0.1365995 * cos(2 * w) -
137 0.0106411 * cos(3 * w);135 0.0106411 * cos(3 * w);
138 break;136 break;
139 default:137 case AV_RESAMPLE_FILTER_TYPE_KAISER:
140 w = 2.0 * x / (factor * tap_count * M_PI);138 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)));
142 break;140 break;
143 }141 }
144 142
145 tab[i] = y;143 tab[i] = y;
146 norm += y;144 norm += y;
147 }145 }
148
149 /* normalize so that an uniform color remains the same */146 /* normalize so that an uniform color remains the same */
150 for (i = 0; i < tap_count; i++) {147 for (i = 0; i < tap_count; i++)
151#ifdef CONFIG_RESAMPLE_FLT148 tab[i] = tab[i] / norm;
152 filter[ph * tap_count + i] = tab[i] / norm;149
153#else150 c->set_filter(c->filter_bank, tab, ph, tap_count);
154 filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm),
155 FELEM_MIN, FELEM_MAX);
156#endif
157 }
158 }151 }
159 152
160 av_free(tab);153 av_free(tab);
@@ -168,9 +161,12 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr) · 7 unmodified lines
168 int in_rate = avr->in_sample_rate;161 int in_rate = avr->in_sample_rate;
169 double factor = FFMIN(out_rate * avr->cutoff / in_rate, 1.0);162 double factor = FFMIN(out_rate * avr->cutoff / in_rate, 1.0);
170 int phase_count = 1 << avr->phase_shift;163 int phase_count = 1 << avr->phase_shift;
164 int felem_size;
171 165
172 /* TODO: add support for s32 and float internal formats */166 if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&
173 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) {
174 av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "170 av_log(avr, AV_LOG_ERROR, "Unsupported internal format for "
175 "resampling: %s\n",171 "resampling: %s\n",
176 av_get_sample_fmt_name(avr->internal_sample_fmt));172 av_get_sample_fmt_name(avr->internal_sample_fmt));
@@ -186,18 +182,40 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr) · 9 unmodified lines
186 c->linear = avr->linear_interp;182 c->linear = avr->linear_interp;
187 c->factor = factor;183 c->factor = factor;
188 c->filter_length = FFMAX((int)ceil(avr->filter_size / factor), 1);184 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 }
189 206
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);
191 if (!c->filter_bank)209 if (!c->filter_bank)
192 goto error;210 goto error;
193 211
194 if (build_filter(c->filter_bank, factor, c->filter_length, phase_count,212 if (build_filter(c) < 0)
195 1 << FILTER_SHIFT, WINDOW_TYPE) < 0)
196 goto error;213 goto error;
197 214
198 memcpy(&c->filter_bank[c->filter_length * phase_count + 1],215 memcpy(&c->filter_bank[(c->filter_length * phase_count + 1) * felem_size],
199 c->filter_bank, (c->filter_length - 1) * sizeof(FELEM));216 c->filter_bank, (c->filter_length - 1) * felem_size);
200 c->filter_bank[c->filter_length * phase_count] = c->filter_bank[c->filter_length - 1];217 memcpy(&c->filter_bank[c->filter_length * phase_count * felem_size],
218 &c->filter_bank[(c->filter_length - 1) * felem_size], felem_size);
201 219
202 c->compensation_distance = 0;220 c->compensation_distance = 0;
203 if (!av_reduce(&c->src_incr, &c->dst_incr, out_rate,221 if (!av_reduce(&c->src_incr, &c->dst_incr, out_rate,
@@ -311,10 +329,10 @@ reinit_fail: · 107 unmodified lines
311 return ret;329 return ret;
312}330}
313 331
314static int resample(ResampleContext *c, int16_t *dst, const int16_t *src,332static int resample(ResampleContext *c, void *dst, const void *src,
315 int *consumed, int src_size, int dst_size, int update_ctx)333 int *consumed, int src_size, int dst_size, int update_ctx)
316{334{
317 int dst_index, i;335 int dst_index;
318 int index = c->index;336 int index = c->index;
319 int frac = c->frac;337 int frac = c->frac;
320 int dst_incr_frac = c->dst_incr % c->src_incr;338 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
334 352
335 if (dst) {353 if (dst) {
336 for(dst_index = 0; dst_index < dst_size; dst_index++) {354 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);
338 index2 += incr;356 index2 += incr;
339 }357 }
340 } else {358 } else {
@@ -345,42 +363,14 @@ static int resample(ResampleContext *c, int16_t *dst, const int16_t *src, · 4 unmodified lines
345 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;363 frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr;
346 } else {364 } else {
347 for (dst_index = 0; dst_index < dst_size; dst_index++) {365 for (dst_index = 0; dst_index < dst_size; dst_index++) {
348 FELEM *filter = c->filter_bank +
349 c->filter_length * (index & c->phase_mask);
350 int sample_index = index >> c->phase_shift;366 int sample_index = index >> c->phase_shift;
351 367
352 if (!dst && (sample_index + c->filter_length > src_size ||368 if (sample_index + c->filter_length > src_size ||
353 -sample_index >= src_size))369 -sample_index >= src_size)
354 break;370 break;
355 371
356 if (dst) {372 if (dst)
357 FELEM2 val = 0;373 c->resample_one(c, 0, dst, dst_index, src, src_size, index, frac);
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 }
384 374
385 frac += dst_incr_frac;375 frac += dst_incr_frac;
386 index += dst_incr;376 index += dst_incr;
@@ -451,8 +441,8 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src, · 64 unmodified lines
451 441
452 /* resample each channel plane */442 /* resample each channel plane */
453 for (ch = 0; ch < c->buffer->channels; ch++) {443 for (ch = 0; ch < c->buffer->channels; ch++) {
454 out_samples = resample(c, (int16_t *)dst->data[ch],444 out_samples = resample(c, (void *)dst->data[ch],
455 (const int16_t *)c->buffer->data[ch], consumed,445 (const void *)c->buffer->data[ch], consumed,
456 c->buffer->nb_samples, dst->allocated_samples,446 c->buffer->nb_samples, dst->allocated_samples,
457 ch + 1 == c->buffer->channels);447 ch + 1 == c->buffer->channels);
458 }448 }
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
51static 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
87static 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
57 avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate ||57 avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate ||
58 avr->force_resampling;58 avr->force_resampling;
59 59
60 /* set sample format conversion parameters */60 /* select internal sample format if not specified by the user */
61 /* override user-requested internal format to avoid unexpected failures61 if (avr->internal_sample_fmt == AV_SAMPLE_FMT_NONE &&
62 TODO: support more internal formats */62 (avr->mixing_needed || avr->resample_needed)) {
63 if (avr->resample_needed && avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) {63 enum AVSampleFormat in_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
64 av_log(avr, AV_LOG_WARNING, "Using s16p as internal sample format\n");64 enum AVSampleFormat out_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
65 avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;65 int max_bps = FFMAX(av_get_bytes_per_sample(in_fmt),
66 } else if (avr->mixing_needed &&66 av_get_bytes_per_sample(out_fmt));
67 avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P &&67 if (max_bps <= 2) {
68 avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) {68 avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;
69 av_log(avr, AV_LOG_WARNING, "Using fltp as internal sample format\n");69 } else if (avr->mixing_needed) {
70 avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;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));
71 }94 }
95
96 /* set sample format conversion parameters */
72 if (avr->in_channels == 1)97 if (avr->in_channels == 1)
73 avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);98 avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
74 if (avr->out_channels == 1)99 if (avr->out_channels == 1)
tests/fate-run.sh+7−1
@@ -75,7 +75,13 @@ probefmt(){ · 74 unmodified lines
75}75}
76 76
77ffmpeg(){77ffmpeg(){
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}
79}85}
80 86
81framecrc(){87framecrc(){

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