Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

Merged-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information...
commit f8911b987de4a84ff8ae92f41ff492ece4acadb9 2 parents bf53863 + 5467742
Michael Niedermayer michaelni authored

Showing 45 changed files with 648 additions and 339 deletions. Show diff stats Hide diff stats

  1. +1 1  libavcodec/Makefile
  2. +3 3 libavcodec/libx264.c
  3. +3 9 libavcodec/motion-test.c
  4. +5 103 libavcodec/mss3.c
  5. +114 0 libavcodec/mss34dsp.c
  6. +45 0 libavcodec/mss34dsp.h
  7. +4 2 libavfilter/af_aconvert.c
  8. +3 3 libavfilter/af_amerge.c
  9. +13 9 libavfilter/af_amix.c
  10. +5 3 libavfilter/af_aresample.c
  11. +3 2 libavfilter/af_asetnsamples.c
  12. +2 2 libavfilter/af_ashowinfo.c
  13. +6 3 libavfilter/af_astreamsync.c
  14. +31 17 libavfilter/af_asyncts.c
  15. +2 1  libavfilter/af_atempo.c
  16. +6 4 libavfilter/af_channelmap.c
  17. +10 5 libavfilter/af_channelsplit.c
  18. +5 2 libavfilter/af_earwax.c
  19. +5 3 libavfilter/af_join.c
  20. +4 2 libavfilter/af_pan.c
  21. +31 14 libavfilter/af_resample.c
  22. +2 2 libavfilter/af_silencedetect.c
  23. +2 2 libavfilter/af_volume.c
  24. +4 1 libavfilter/asink_anullsink.c
  25. +14 12 libavfilter/audio.c
  26. +5 2 libavfilter/audio.h
  27. +2 1  libavfilter/avf_showwaves.c
  28. +5 1 libavfilter/avfilter.h
  29. +7 1 libavfilter/buffersink.c
  30. +3 2 libavfilter/buffersrc.c
  31. +2 2 libavfilter/f_settb.c
  32. +18 8 libavfilter/fifo.c
  33. +5 1 libavfilter/internal.h
  34. +2 1  libavfilter/sink_buffer.c
  35. +9 5 libavfilter/split.c
  36. +4 1 libavformat/matroskadec.c
  37. +10 1 libavformat/tcp.c
  38. +8 0 libavresample/audio_mix.c
  39. +7 0 libavresample/avresample.h
  40. +2 0  libavresample/internal.h
  41. +6 1 libavresample/options.c
  42. +85 95 libavresample/resample.c
  43. +102 0 libavresample/resample_template.c
  44. +36 11 libavresample/utils.c
  45. +7 1 tests/fate-run.sh
2  libavcodec/Makefile
@@ -327,7 +327,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \
327 327 h263dec.o h263.o ituh263dec.o \
328 328 mpeg4videodec.o
329 329 OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o
330   -OBJS-$(CONFIG_MSA1_DECODER) += mss3.o
  330 +OBJS-$(CONFIG_MSA1_DECODER) += mss3.o mss34dsp.o
331 331 OBJS-$(CONFIG_MSS1_DECODER) += mss1.o
332 332 OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o
333 333 OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o
6 libavcodec/libx264.c
@@ -175,10 +175,10 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame,
175 175 x4->params.b_tff = frame->top_field_first;
176 176 x264_encoder_reconfig(x4->enc, &x4->params);
177 177 }
178   - if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den
179   - || x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
  178 + if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ||
  179 + x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) {
180 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 182 x264_encoder_reconfig(x4->enc, &x4->params);
183 183 }
184 184 }
12 libavcodec/motion-test.c
@@ -119,15 +119,9 @@ int main(int argc, char **argv)
119 119 int flags[2] = { AV_CPU_FLAG_MMX, AV_CPU_FLAG_MMX2 };
120 120 int flags_size = HAVE_MMX2 ? 2 : 1;
121 121
122   - for(;;) {
123   - c = getopt(argc, argv, "h");
124   - if (c == -1)
125   - break;
126   - switch(c) {
127   - case 'h':
128   - help();
129   - return 1;
130   - }
  122 + if (argc > 1) {
  123 + help();
  124 + return 1;
131 125 }
132 126
133 127 printf("ffmpeg motion test\n");
108 libavcodec/mss3.c
@@ -26,6 +26,8 @@
26 26
27 27 #include "avcodec.h"
28 28 #include "bytestream.h"
  29 +#include "dsputil.h"
  30 +#include "mss34dsp.h"
29 31
30 32 #define HEADER_SIZE 27
31 33
@@ -119,39 +121,6 @@ typedef struct MSS3Context {
119 121 int hblock[16 * 16];
120 122 } MSS3Context;
121 123
122   -static const uint8_t mss3_luma_quant[64] = {
123   - 16, 11, 10, 16, 24, 40, 51, 61,
124   - 12, 12, 14, 19, 26, 58, 60, 55,
125   - 14, 13, 16, 24, 40, 57, 69, 56,
126   - 14, 17, 22, 29, 51, 87, 80, 62,
127   - 18, 22, 37, 56, 68, 109, 103, 77,
128   - 24, 35, 55, 64, 81, 104, 113, 92,
129   - 49, 64, 78, 87, 103, 121, 120, 101,
130   - 72, 92, 95, 98, 112, 100, 103, 99
131   -};
132   -
133   -static const uint8_t mss3_chroma_quant[64] = {
134   - 17, 18, 24, 47, 99, 99, 99, 99,
135   - 18, 21, 26, 66, 99, 99, 99, 99,
136   - 24, 26, 56, 99, 99, 99, 99, 99,
137   - 47, 66, 99, 99, 99, 99, 99, 99,
138   - 99, 99, 99, 99, 99, 99, 99, 99,
139   - 99, 99, 99, 99, 99, 99, 99, 99,
140   - 99, 99, 99, 99, 99, 99, 99, 99,
141   - 99, 99, 99, 99, 99, 99, 99, 99
142   -};
143   -
144   -static const uint8_t zigzag_scan[64] = {
145   - 0, 1, 8, 16, 9, 2, 3, 10,
146   - 17, 24, 32, 25, 18, 11, 4, 5,
147   - 12, 19, 26, 33, 40, 48, 41, 34,
148   - 27, 20, 13, 6, 7, 14, 21, 28,
149   - 35, 42, 49, 56, 57, 50, 43, 36,
150   - 29, 22, 15, 23, 30, 37, 44, 51,
151   - 58, 59, 52, 45, 38, 31, 39, 46,
152   - 53, 60, 61, 54, 47, 55, 62, 63
153   -};
154   -
155 124
156 125 static void model2_reset(Model2 *m)
157 126 {
@@ -578,7 +547,7 @@ static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block,
578 547 if (!sign)
579 548 val = -val;
580 549
581   - zz_pos = zigzag_scan[pos];
  550 + zz_pos = ff_zigzag_direct[pos];
582 551 block[zz_pos] = val * bc->qmat[zz_pos];
583 552 pos++;
584 553 }
@@ -586,58 +555,6 @@ static int decode_dct(RangeCoder *c, DCTBlockCoder *bc, int *block,
586 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   -
615   -static void dct_put(uint8_t *dst, int stride, int *block)
616   -{
617   - int i, j;
618   - int *ptr;
619   -
620   - ptr = block;
621   - for (i = 0; i < 8; i++) {
622   - DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
623   - ptr += 8;
624   - }
625   -
626   - ptr = block;
627   - for (i = 0; i < 8; i++) {
628   - DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
629   - ptr++;
630   - }
631   -
632   - ptr = block;
633   - for (j = 0; j < 8; j++) {
634   - for (i = 0; i < 8; i++)
635   - dst[i] = av_clip_uint8(ptr[i] + 128);
636   - dst += stride;
637   - ptr += 8;
638   - }
639   -}
640   -
641 558 static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc,
642 559 uint8_t *dst, int stride, int block_size,
643 560 int *block, int mb_x, int mb_y)
@@ -655,7 +572,7 @@ static void decode_dct_block(RangeCoder *c, DCTBlockCoder *bc,
655 572 c->got_error = 1;
656 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 577 dst += 8 * stride;
661 578 }
@@ -702,14 +619,6 @@ static void decode_haar_block(RangeCoder *c, HaarBlockCoder *hc,
702 619 }
703 620 }
704 621
705   -static void gen_quant_mat(uint16_t *qmat, const uint8_t *ref, float scale)
706   -{
707   - int i;
708   -
709   - for (i = 0; i < 64; i++)
710   - qmat[i] = (uint16_t)(ref[i] * scale + 50.0) / 100;
711   -}
712   -
713 622 static void reset_coders(MSS3Context *ctx, int quality)
714 623 {
715 624 int i, j;
@@ -726,15 +635,8 @@ static void reset_coders(MSS3Context *ctx, int quality)
726 635 for (j = 0; j < 125; j++)
727 636 model_reset(&ctx->image_coder[i].vq_model[j]);
728 637 if (ctx->dct_coder[i].quality != quality) {
729   - float scale;
730 638 ctx->dct_coder[i].quality = quality;
731   - if (quality > 50)
732   - scale = 200.0f - 2 * quality;
733   - else
734   - scale = 5000.0f / quality;
735   - gen_quant_mat(ctx->dct_coder[i].qmat,
736   - i ? mss3_chroma_quant : mss3_luma_quant,
737   - scale);
  639 + ff_mss34_gen_quant_mat(ctx->dct_coder[i].qmat, quality, !i);
738 640 }
739 641 memset(ctx->dct_coder[i].prev_dc, 0,
740 642 sizeof(*ctx->dct_coder[i].prev_dc) *
114 libavcodec/mss34dsp.c
... ... @@ -0,0 +1,114 @@
  1 +/*
  2 + * Common stuff for some Microsoft Screen codecs
  3 + * Copyright (C) 2012 Konstantin Shishkov
  4 + *
  5 + * This file is part of FFmpeg.
  6 + *
  7 + * FFmpeg is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public
  9 + * License as published by the Free Software Foundation; either
  10 + * version 2.1 of the License, or (at your option) any later version.
  11 + *
  12 + * FFmpeg is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15 + * Lesser General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU Lesser General Public
  18 + * License along with FFmpeg; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20 + */
  21 +
  22 +#include <stdint.h>
  23 +#include "libavutil/common.h"
  24 +#include "mss34dsp.h"
  25 +
  26 +static const uint8_t luma_quant[64] = {
  27 + 16, 11, 10, 16, 24, 40, 51, 61,
  28 + 12, 12, 14, 19, 26, 58, 60, 55,
  29 + 14, 13, 16, 24, 40, 57, 69, 56,
  30 + 14, 17, 22, 29, 51, 87, 80, 62,
  31 + 18, 22, 37, 56, 68, 109, 103, 77,
  32 + 24, 35, 55, 64, 81, 104, 113, 92,
  33 + 49, 64, 78, 87, 103, 121, 120, 101,
  34 + 72, 92, 95, 98, 112, 100, 103, 99
  35 +};
  36 +
  37 +static const uint8_t chroma_quant[64] = {
  38 + 17, 18, 24, 47, 99, 99, 99, 99,
  39 + 18, 21, 26, 66, 99, 99, 99, 99,
  40 + 24, 26, 56, 99, 99, 99, 99, 99,
  41 + 47, 66, 99, 99, 99, 99, 99, 99,
  42 + 99, 99, 99, 99, 99, 99, 99, 99,
  43 + 99, 99, 99, 99, 99, 99, 99, 99,
  44 + 99, 99, 99, 99, 99, 99, 99, 99,
  45 + 99, 99, 99, 99, 99, 99, 99, 99
  46 +};
  47 +
  48 +void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma)
  49 +{
  50 + int i;
  51 + const uint8_t *qsrc = luma ? luma_quant : chroma_quant;
  52 +
  53 + if (quality >= 50) {
  54 + int scale = 200 - 2 * quality;
  55 +
  56 + for (i = 0; i < 64; i++)
  57 + qmat[i] = (qsrc[i] * scale + 50) / 100;
  58 + } else {
  59 + for (i = 0; i < 64; i++)
  60 + qmat[i] = (5000 * qsrc[i] / quality + 50) / 100;
  61 + }
  62 +}
  63 +
  64 +#define DCT_TEMPLATE(blk, step, SOP, shift) \
  65 + const int t0 = -39409 * blk[7 * step] - 58980 * blk[1 * step]; \
  66 + const int t1 = 39410 * blk[1 * step] - 58980 * blk[7 * step]; \
  67 + const int t2 = -33410 * blk[5 * step] - 167963 * blk[3 * step]; \
  68 + const int t3 = 33410 * blk[3 * step] - 167963 * blk[5 * step]; \
  69 + const int t4 = blk[3 * step] + blk[7 * step]; \
  70 + const int t5 = blk[1 * step] + blk[5 * step]; \
  71 + const int t6 = 77062 * t4 + 51491 * t5; \
  72 + const int t7 = 77062 * t5 - 51491 * t4; \
  73 + const int t8 = 35470 * blk[2 * step] - 85623 * blk[6 * step]; \
  74 + const int t9 = 35470 * blk[6 * step] + 85623 * blk[2 * step]; \
  75 + const int tA = SOP(blk[0 * step] - blk[4 * step]); \
  76 + const int tB = SOP(blk[0 * step] + blk[4 * step]); \
  77 + \
  78 + blk[0 * step] = ( t1 + t6 + t9 + tB) >> shift; \
  79 + blk[1 * step] = ( t3 + t7 + t8 + tA) >> shift; \
  80 + blk[2 * step] = ( t2 + t6 - t8 + tA) >> shift; \
  81 + blk[3 * step] = ( t0 + t7 - t9 + tB) >> shift; \
  82 + blk[4 * step] = (-(t0 + t7) - t9 + tB) >> shift; \
  83 + blk[5 * step] = (-(t2 + t6) - t8 + tA) >> shift; \
  84 + blk[6 * step] = (-(t3 + t7) + t8 + tA) >> shift; \
  85 + blk[7 * step] = (-(t1 + t6) + t9 + tB) >> shift; \
  86 +
  87 +#define SOP_ROW(a) ((a) << 16) + 0x2000
  88 +#define SOP_COL(a) ((a + 32) << 16)
  89 +
  90 +void ff_mss34_dct_put(uint8_t *dst, int stride, int *block)
  91 +{
  92 + int i, j;
  93 + int *ptr;
  94 +
  95 + ptr = block;
  96 + for (i = 0; i < 8; i++) {
  97 + DCT_TEMPLATE(ptr, 1, SOP_ROW, 13);
  98 + ptr += 8;
  99 + }
  100 +
  101 + ptr = block;
  102 + for (i = 0; i < 8; i++) {
  103 + DCT_TEMPLATE(ptr, 8, SOP_COL, 22);
  104 + ptr++;
  105 + }
  106 +
  107 + ptr = block;
  108 + for (j = 0; j < 8; j++) {
  109 + for (i = 0; i < 8; i++)
  110 + dst[i] = av_clip_uint8(ptr[i] + 128);
  111 + dst += stride;
  112 + ptr += 8;
  113 + }
  114 +}
45 libavcodec/mss34dsp.h
... ... @@ -0,0 +1,45 @@
  1 +/*
  2 + * Common stuff for some Microsoft Screen codecs
  3 + * Copyright (C) 2012 Konstantin Shishkov
  4 + *
  5 + * This file is part of FFmpeg.
  6 + *
  7 + * FFmpeg is free software; you can redistribute it and/or
  8 + * modify it under the terms of the GNU Lesser General Public
  9 + * License as published by the Free Software Foundation; either
  10 + * version 2.1 of the License, or (at your option) any later version.
  11 + *
  12 + * FFmpeg is distributed in the hope that it will be useful,
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15 + * Lesser General Public License for more details.
  16 + *
  17 + * You should have received a copy of the GNU Lesser General Public
  18 + * License along with FFmpeg; if not, write to the Free Software
  19 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20 + */
  21 +
  22 +#ifndef AVCODEC_MSS34DSP_H
  23 +#define AVCODEC_MSS34DSP_H
  24 +
  25 +#include <stdint.h>
  26 +
  27 +/**
  28 + * Generate quantisation matrix for given quality.
  29 + *
  30 + * @param qmat destination matrix
  31 + * @param quality quality setting (1-100)
  32 + * @param luma generate quantisation matrix for luma or chroma
  33 + */
  34 +void ff_mss34_gen_quant_mat(uint16_t *qmat, int quality, int luma);
  35 +
  36 +/**
  37 + * Transform and output DCT block.
  38 + *
  39 + * @param dst output plane
  40 + * @param stride output plane stride
  41 + * @param block block to transform and output
  42 + */
  43 +void ff_mss34_dct_put(uint8_t *dst, int stride, int *block);
  44 +
  45 +#endif /* AVCODEC_MSS34DSP_H */
6 libavfilter/af_aconvert.c
@@ -135,12 +135,13 @@ static int config_output(AVFilterLink *outlink)
135 135 return 0;
136 136 }
137 137
138   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
  138 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
139 139 {
140 140 AConvertContext *aconvert = inlink->dst->priv;
141 141 const int n = insamplesref->audio->nb_samples;
142 142 AVFilterLink *const outlink = inlink->dst->outputs[0];
143 143 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
  144 + int ret;
144 145
145 146 swr_convert(aconvert->swr, outsamplesref->data, n,
146 147 (void *)insamplesref->data, n);
@@ -148,8 +149,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
148 149 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);
149 150 outsamplesref->audio->channel_layout = outlink->channel_layout;
150 151
151   - ff_filter_samples(outlink, outsamplesref);
  152 + ret = ff_filter_samples(outlink, outsamplesref);
152 153 avfilter_unref_buffer(insamplesref);
  154 + return ret;
153 155 }
154 156
155 157 AVFilter avfilter_af_aconvert = {
6 libavfilter/af_amerge.c
@@ -212,7 +212,7 @@ static inline void copy_samples(int nb_inputs, struct amerge_input in[],
212 212 }
213 213 }
214 214
215   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  215 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
216 216 {
217 217 AVFilterContext *ctx = inlink->dst;
218 218 AMergeContext *am = ctx->priv;
@@ -232,7 +232,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
232 232 for (i = 1; i < am->nb_inputs; i++)
233 233 nb_samples = FFMIN(nb_samples, am->in[i].nb_samples);
234 234 if (!nb_samples)
235   - return;
  235 + return 0;
236 236
237 237 outbuf = ff_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE, nb_samples);
238 238 outs = outbuf->data[0];
@@ -285,7 +285,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
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
291 291 static av_cold int init(AVFilterContext *ctx, const char *args)
22 libavfilter/af_amix.c
@@ -305,9 +305,7 @@ static int output_frame(AVFilterLink *outlink, int nb_samples)
305 305 if (s->next_pts != AV_NOPTS_VALUE)
306 306 s->next_pts += nb_samples;
307 307
308   - ff_filter_samples(outlink, out_buf);
309   -
310   - return 0;
  308 + return ff_filter_samples(outlink, out_buf);
311 309 }
312 310
313 311 /**
@@ -448,31 +446,37 @@ static int request_frame(AVFilterLink *outlink)
448 446 return output_frame(outlink, available_samples);
449 447 }
450 448
451   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
  449 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
452 450 {
453 451 AVFilterContext *ctx = inlink->dst;
454 452 MixContext *s = ctx->priv;
455 453 AVFilterLink *outlink = ctx->outputs[0];
456   - int i;
  454 + int i, ret = 0;
457 455
458 456 for (i = 0; i < ctx->nb_inputs; i++)
459 457 if (ctx->inputs[i] == inlink)
460 458 break;
461 459 if (i >= ctx->nb_inputs) {
462 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 465 if (i == 0) {
467 466 int64_t pts = av_rescale_q(buf->pts, inlink->time_base,
468 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   - buf->audio->nb_samples);
  473 + ret = av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data,
  474 + buf->audio->nb_samples);
474 475
  476 +fail:
475 477 avfilter_unref_buffer(buf);
  478 +
  479 + return ret;
476 480 }
477 481
478 482 static int init(AVFilterContext *ctx, const char *args)
8 libavfilter/af_aresample.c
@@ -168,13 +168,14 @@ static int config_output(AVFilterLink *outlink)
168 168 return 0;
169 169 }
170 170
171   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
  171 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref)
172 172 {
173 173 AResampleContext *aresample = inlink->dst->priv;
174 174 const int n_in = insamplesref->audio->nb_samples;
175 175 int n_out = n_in * aresample->ratio * 2 ;
176 176 AVFilterLink *const outlink = inlink->dst->outputs[0];
177 177 AVFilterBufferRef *outsamplesref = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n_out);
  178 + int ret;
178 179
179 180
180 181 avfilter_copy_buffer_ref_props(outsamplesref, insamplesref);
@@ -193,15 +194,16 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref
193 194 if (n_out <= 0) {
194 195 avfilter_unref_buffer(outsamplesref);
195 196 avfilter_unref_buffer(insamplesref);
196   - return;
  197 + return 0;
197 198 }
198 199
199 200 outsamplesref->audio->sample_rate = outlink->sample_rate;
200 201 outsamplesref->audio->nb_samples = n_out;
201 202
202   - ff_filter_samples(outlink, outsamplesref);
  203 + ret = ff_filter_samples(outlink, outsamplesref);
203 204 aresample->req_fullfilled= 1;
204 205 avfilter_unref_buffer(insamplesref);
  206 + return ret;
205 207 }
206 208
207 209 static int request_frame(AVFilterLink *outlink)
5 libavfilter/af_asetnsamples.c
@@ -131,7 +131,7 @@ static int push_samples(AVFilterLink *outlink)
131 131 return nb_out_samples;
132 132 }
133 133
134   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  134 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
135 135 {
136 136 AVFilterContext *ctx = inlink->dst;
137 137 ASNSContext *asns = ctx->priv;
@@ -145,7 +145,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
145 145 if (ret < 0) {
146 146 av_log(ctx, AV_LOG_ERROR,
147 147 "Stretching audio fifo failed, discarded %d samples\n", nb_samples);
148   - return;
  148 + return -1;
149 149 }
150 150 }
151 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)
155 155
156 156 if (av_audio_fifo_size(asns->fifo) >= asns->nb_out_samples)
157 157 push_samples(outlink);
  158 + return 0;
158 159 }
159 160
160 161 static int request_frame(AVFilterLink *outlink)
4 libavfilter/af_ashowinfo.c
@@ -40,7 +40,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
40 40 return 0;
41 41 }
42 42
43   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
  43 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
44 44 {
45 45 AVFilterContext *ctx = inlink->dst;
46 46 ShowInfoContext *showinfo = ctx->priv;
@@ -83,7 +83,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref)
83 83 av_log(ctx, AV_LOG_INFO, "]\n");
84 84
85 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
89 89 AVFilter avfilter_af_ashowinfo = {
9 libavfilter/af_astreamsync.c
@@ -107,11 +107,12 @@ static int config_output(AVFilterLink *outlink)
107 107 return 0;
108 108 }
109 109
110   -static void send_out(AVFilterContext *ctx, int out_id)
  110 +static int send_out(AVFilterContext *ctx, int out_id)
111 111 {
112 112 AStreamSyncContext *as = ctx->priv;
113 113 struct buf_queue *queue = &as->queue[out_id];
114 114 AVFilterBufferRef *buf = queue->buf[queue->tail];
  115 + int ret;
115 116
116 117 queue->buf[queue->tail] = NULL;
117 118 as->var_values[VAR_B1 + out_id]++;
@@ -121,11 +122,12 @@ static void send_out(AVFilterContext *ctx, int out_id)
121 122 av_q2d(ctx->outputs[out_id]->time_base) * buf->pts;
122 123 as->var_values[VAR_T1 + out_id] += buf->audio->nb_samples /
123 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 126 queue->nb--;
126 127 queue->tail = (queue->tail + 1) % QUEUE_SIZE;
127 128 if (as->req[out_id])
128 129 as->req[out_id]--;
  130 + return ret;
129 131 }
130 132
131 133 static void send_next(AVFilterContext *ctx)
@@ -165,7 +167,7 @@ static int request_frame(AVFilterLink *outlink)
165 167 return 0;
166 168 }
167 169
168   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  170 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
169 171 {
170 172 AVFilterContext *ctx = inlink->dst;
171 173 AStreamSyncContext *as = ctx->priv;
@@ -175,6 +177,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
175 177 insamples;
176 178 as->eof &= ~(1 << id);
177 179 send_next(ctx);
  180 + return 0;
178 181 }
179 182
180 183 AVFilter avfilter_af_astreamsync = {
48 libavfilter/af_asyncts.c
@@ -37,6 +37,9 @@ typedef struct ASyncContext {
37 37 int resample;
38 38 float min_delta_sec;
39 39 int max_comp;
  40 +
  41 + /* set by filter_samples() to signal an output frame to request_frame() */
  42 + int got_output;
40 43 } ASyncContext;
41 44
42 45 #define OFFSET(x) offsetof(ASyncContext, x)
@@ -112,9 +115,13 @@ static int request_frame(AVFilterLink *link)
112 115 {
113 116 AVFilterContext *ctx = link->src;
114 117 ASyncContext *s = ctx->priv;
115   - int ret = ff_request_frame(ctx->inputs[0]);
  118 + int ret = 0;
116 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 125 /* flush the fifo */
119 126 if (ret == AVERROR_EOF && (nb_samples = avresample_get_delay(s->avr))) {
120 127 AVFilterBufferRef *buf = ff_get_audio_buffer(link, AV_PERM_WRITE,
@@ -124,18 +131,18 @@ static int request_frame(AVFilterLink *link)
124 131 avresample_convert(s->avr, (void**)buf->extended_data, buf->linesize[0],
125 132 nb_samples, NULL, 0, 0);
126 133 buf->pts = s->pts;
127   - ff_filter_samples(link, buf);
128   - return 0;
  134 + return ff_filter_samples(link, buf);
129 135 }
130 136
131 137 return ret;
132 138 }
133 139
134   -static void write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf)
  140 +static int write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf)
135 141 {
136   - avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
137   - buf->linesize[0], buf->audio->nb_samples);
  142 + int ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
  143 + buf->linesize[0], buf->audio->nb_samples);
138 144 avfilter_unref_buffer(buf);
  145 + return ret;
139 146 }
140 147
141 148 /* get amount of data currently buffered, in samples */
@@ -144,7 +151,7 @@ static int64_t get_delay(ASyncContext *s)
144 151 return avresample_available(s->avr) + avresample_get_delay(s->avr);
145 152 }
146 153
147   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
  154 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
148 155 {
149 156 AVFilterContext *ctx = inlink->dst;
150 157 ASyncContext *s = ctx->priv;
@@ -152,7 +159,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
152 159 int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout);
153 160 int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts :
154 161 av_rescale_q(buf->pts, inlink->time_base, outlink->time_base);
155   - int out_size;
  162 + int out_size, ret;
156 163 int64_t delta;
157 164
158 165 /* buffer data until we get the first timestamp */
@@ -160,14 +167,12 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
160 167 if (pts != AV_NOPTS_VALUE) {
161 168 s->pts = pts - get_delay(s);
162 169 }
163   - write_to_fifo(s, buf);
164   - return;
  170 + return write_to_fifo(s, buf);
165 171 }
166 172
167 173 /* now wait for the next timestamp */
168 174 if (pts == AV_NOPTS_VALUE) {
169   - write_to_fifo(s, buf);
170   - return;
  175 + return write_to_fifo(s, buf);
171 176 }
172 177
173 178 /* when we have two timestamps, compute how many samples would we have
@@ -190,8 +195,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
190 195 if (out_size > 0) {
191 196 AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE,
192 197 out_size);
193   - if (!buf_out)
194   - return;
  198 + if (!buf_out) {
  199 + ret = AVERROR(ENOMEM);
  200 + goto fail;
  201 + }
195 202
196 203 avresample_read(s->avr, (void**)buf_out->extended_data, out_size);
197 204 buf_out->pts = s->pts;
@@ -200,7 +207,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
200 207 av_samples_set_silence(buf_out->extended_data, out_size - delta,
201 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 214 } else {
205 215 av_log(ctx, AV_LOG_WARNING, "Non-monotonous timestamps, dropping "
206 216 "whole buffer.\n");
@@ -210,9 +220,13 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
210 220 avresample_read(s->avr, NULL, avresample_available(s->avr));
211 221
212 222 s->pts = pts - avresample_get_delay(s->avr);
213   - avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
214   - buf->linesize[0], buf->audio->nb_samples);
  223 + ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data,
  224 + buf->linesize[0], buf->audio->nb_samples);
  225 +
  226 +fail:
215 227 avfilter_unref_buffer(buf);
  228 +
  229 + return ret;
216 230 }
217 231
218 232 AVFilter avfilter_af_asyncts = {
3  libavfilter/af_atempo.c
@@ -1040,7 +1040,7 @@ static void push_samples(ATempoContext *atempo,
1040 1040 atempo->nsamples_out += n_out;
1041 1041 }
1042 1042
1043   -static void filter_samples(AVFilterLink *inlink,
  1043 +static int filter_samples(AVFilterLink *inlink,
1044 1044 AVFilterBufferRef *src_buffer)
1045 1045 {
1046 1046 AVFilterContext *ctx = inlink->dst;
@@ -1074,6 +1074,7 @@ static void filter_samples(AVFilterLink *inlink,
1074 1074
1075 1075 atempo->nsamples_in += n_in;
1076 1076 avfilter_unref_bufferp(&src_buffer);
  1077 + return 0;
1077 1078 }
1078 1079
1079 1080 static int request_frame(AVFilterLink *outlink)
10 libavfilter/af_channelmap.c
@@ -313,7 +313,7 @@ static int channelmap_query_formats(AVFilterContext *ctx)
313 313 return 0;
314 314 }
315 315
316   -static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
  316 +static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
317 317 {
318 318 AVFilterContext *ctx = inlink->dst;
319 319 AVFilterLink *outlink = ctx->outputs[0];
@@ -330,8 +330,10 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b
330 330 if (nch_out > FF_ARRAY_ELEMS(buf->data)) {
331 331 uint8_t **new_extended_data =
332 332 av_mallocz(nch_out * sizeof(*buf->extended_data));
333   - if (!new_extended_data)
334   - return;
  333 + if (!new_extended_data) {
  334 + avfilter_unref_buffer(buf);
  335 + return AVERROR(ENOMEM);
  336 + }
335 337 if (buf->extended_data == buf->data) {
336 338 buf->extended_data = new_extended_data;
337 339 } else {
@@ -353,7 +355,7 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b
353 355 memcpy(buf->data, buf->extended_data,
354 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
359 361 static int channelmap_config_input(AVFilterLink *inlink)
15 libavfilter/af_channelsplit.c
@@ -105,24 +105,29 @@ static int query_formats(AVFilterContext *ctx)
105 105 return 0;
106 106 }
107 107
108   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
  108 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
109 109 {
110 110 AVFilterContext *ctx = inlink->dst;
111   - int i;
  111 + int i, ret = 0;
112 112
113 113 for (i = 0; i < ctx->nb_outputs; i++) {
114 114 AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE);
115 115
116   - if (!buf_out)
117   - return;
  116 + if (!buf_out) {
  117 + ret = AVERROR(ENOMEM);
  118 + break;
  119 + }
118 120
119 121 buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i];
120 122 buf_out->audio->channel_layout =
121 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 129 avfilter_unref_buffer(buf);
  130 + return ret;
126 131 }
127 132
128 133 AVFilter avfilter_af_channelsplit = {
7 libavfilter/af_earwax.c
@@ -120,13 +120,15 @@ static inline int16_t *scalarproduct(const int16_t *in, const int16_t *endin, in
120 120 return out;
121 121 }
122 122
123   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  123 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
124 124 {
125 125 AVFilterLink *outlink = inlink->dst->outputs[0];
126 126 int16_t *taps, *endin, *in, *out;
127 127 AVFilterBufferRef *outsamples =
128 128 ff_get_audio_buffer(inlink, AV_PERM_WRITE,
129 129 insamples->audio->nb_samples);
  130 + int ret;
  131 +
130 132 avfilter_copy_buffer_ref_props(outsamples, insamples);
131 133
132 134 taps = ((EarwaxContext *)inlink->dst->priv)->taps;
@@ -144,8 +146,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
144 146 // save part of input for next round
145 147 memcpy(taps, endin, NUMTAPS * sizeof(*taps));
146 148
147   - ff_filter_samples(outlink, outsamples);
  149 + ret = ff_filter_samples(outlink, outsamples);
148 150 avfilter_unref_buffer(insamples);
  151 + return ret;
149 152 }
150 153
151 154 AVFilter avfilter_af_earwax = {
8 libavfilter/af_join.c
@@ -92,7 +92,7 @@ static const AVClass join_class = {
92 92 .version = LIBAVUTIL_VERSION_INT,
93 93 };
94 94
95   -static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
  95 +static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
96 96 {
97 97 AVFilterContext *ctx = link->dst;
98 98 JoinContext *s = ctx->priv;
@@ -104,6 +104,8 @@ static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf)
104 104 av_assert0(i < ctx->nb_inputs);
105 105 av_assert0(!s->input_frames[i]);
106 106 s->input_frames[i] = buf;
  107 +
  108 + return 0;
107 109 }
108 110
109 111 static int parse_maps(AVFilterContext *ctx)
@@ -468,11 +470,11 @@ static int join_request_frame(AVFilterLink *outlink)
468 470 priv->nb_in_buffers = ctx->nb_inputs;
469 471 buf->buf->priv = priv;
470 472
471   - ff_filter_samples(outlink, buf);
  473 + ret = ff_filter_samples(outlink, buf);
472 474
473 475 memset(s->input_frames, 0, sizeof(*s->input_frames) * ctx->nb_inputs);
474 476
475   - return 0;
  477 + return ret;
476 478
477 479 fail:
478 480 avfilter_unref_buffer(buf);
6 libavfilter/af_pan.c
@@ -343,8 +343,9 @@ static int config_props(AVFilterLink *link)
343 343 return 0;
344 344 }
345 345
346   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  346 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
347 347 {
  348 + int ret;
348 349 int n = insamples->audio->nb_samples;
349 350 AVFilterLink *const outlink = inlink->dst->outputs[0];
350 351 AVFilterBufferRef *outsamples = ff_get_audio_buffer(outlink, AV_PERM_WRITE, n);
@@ -354,8 +355,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
354 355 avfilter_copy_buffer_ref_props(outsamples, insamples);
355 356 outsamples->audio->channel_layout = outlink->channel_layout;
356 357
357   - ff_filter_samples(outlink, outsamples);
  358 + ret = ff_filter_samples(outlink, outsamples);
358 359 avfilter_unref_buffer(insamples);
  360 + return ret;
359 361 }
360 362
361 363 static av_cold void uninit(AVFilterContext *ctx)
45 libavfilter/af_resample.c
@@ -38,6 +38,9 @@ typedef struct ResampleContext {
38 38 AVAudioResampleContext *avr;
39 39
40 40 int64_t next_pts;
  41 +
  42 + /* set by filter_samples() to signal an output frame to request_frame() */
  43 + int got_output;
41 44 } ResampleContext;
42 45
43 46 static av_cold void uninit(AVFilterContext *ctx)
@@ -102,12 +105,6 @@ static int config_output(AVFilterLink *outlink)
102 105 av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0);
103 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 108 if ((ret = avresample_open(s->avr)) < 0)
112 109 return ret;
113 110
@@ -130,7 +127,11 @@ static int request_frame(AVFilterLink *outlink)
130 127 {
131 128 AVFilterContext *ctx = outlink->src;
132 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 136 /* flush the lavr delay buffer */
136 137 if (ret == AVERROR_EOF && s->avr) {
@@ -156,21 +157,21 @@ static int request_frame(AVFilterLink *outlink)
156 157 }
157 158
158 159 buf->pts = s->next_pts;
159   - ff_filter_samples(outlink, buf);
160   - return 0;
  160 + return ff_filter_samples(outlink, buf);
161 161 }
162 162 return ret;
163 163 }
164 164
165   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
  165 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
166 166 {
167 167 AVFilterContext *ctx = inlink->dst;
168 168 ResampleContext *s = ctx->priv;
169 169 AVFilterLink *outlink = ctx->outputs[0];
  170 + int ret;
170 171
171 172 if (s->avr) {
172 173 AVFilterBufferRef *buf_out;
173   - int delay, nb_samples, ret;
  174 + int delay, nb_samples;
174 175
175 176 /* maximum possible samples lavr can output */
176 177 delay = avresample_get_delay(s->avr);
@@ -179,10 +180,19 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
179 180 AV_ROUND_UP);
180 181
181 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 188 ret = avresample_convert(s->avr, (void**)buf_out->extended_data,
183 189 buf_out->linesize[0], nb_samples,
184 190 (void**)buf->extended_data, buf->linesize[0],
185 191 buf->audio->nb_samples);
  192 + if (ret < 0) {
  193 + avfilter_unref_buffer(buf_out);
  194 + goto fail;
  195 + }
186 196
187 197 av_assert0(!avresample_available(s->avr));
188 198
@@ -208,11 +218,18 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf)
208 218
209 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 +
  225 +fail:
213 226 avfilter_unref_buffer(buf);
214   - } else
215   - ff_filter_samples(outlink, buf);
  227 + } else {
  228 + ret = ff_filter_samples(outlink, buf);
  229 + s->got_output = 1;
  230 + }
  231 +
  232 + return ret;
216 233 }
217 234
218 235 AVFilter avfilter_af_resample = {
4 libavfilter/af_silencedetect.c
@@ -78,7 +78,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args)
78 78 return 0;
79 79 }
80 80
81   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  81 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
82 82 {
83 83 int i;
84 84 SilenceDetectContext *silence = inlink->dst->priv;
@@ -118,7 +118,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
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
124 124 static int query_formats(AVFilterContext *ctx)
4 libavfilter/af_volume.c
@@ -110,7 +110,7 @@ static int query_formats(AVFilterContext *ctx)
110 110 return 0;
111 111 }
112 112
113   -static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
  113 +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
114 114 {
115 115 VolumeContext *vol = inlink->dst->priv;
116 116 AVFilterLink *outlink = inlink->dst->outputs[0];
@@ -169,7 +169,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples)
169 169 }
170 170 }
171 171 }
172   - ff_filter_samples(outlink, insamples);
  172 + return ff_filter_samples(outlink, insamples);
173 173 }
174 174
175 175 AVFilter avfilter_af_volume = {
5 libavfilter/asink_anullsink.c
@@ -21,7 +21,10 @@
21 21 #include "avfilter.h"
22 22 #include "internal.h"
23 23
24   -static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { }
  24 +static int null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
  25 +{
  26 + return 0;
  27 +}
25 28
26 29 AVFilter avfilter_asink_anullsink = {
27 30 .name = "anullsink",
26 libavfilter/audio.c
@@ -150,19 +150,19 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
150 150 return NULL;
151 151 }
152 152
153   -static void default_filter_samples(AVFilterLink *link,
154   - AVFilterBufferRef *samplesref)
  153 +static int default_filter_samples(AVFilterLink *link,
  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
159   -void ff_filter_samples_framed(AVFilterLink *link,
160   - AVFilterBufferRef *samplesref)
  159 +int ff_filter_samples_framed(AVFilterLink *link, AVFilterBufferRef *samplesref)
161 160 {
162   - void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
  161 + int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
163 162 AVFilterPad *dst = link->dstpad;
164 163 int64_t pts;
165 164 AVFilterBufferRef *buf_out;
  165 + int ret;
166 166
167 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,
193 193
194 194 link->cur_buf = buf_out;
195 195 pts = buf_out->pts;
196   - filter_samples(link, buf_out);
  196 + ret = filter_samples(link, buf_out);
197 197 ff_update_link_current_pts(link, pts);
  198 + return ret;
198 199 }
199 200
200   -void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
  201 +int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
201 202 {
202 203 int insamples = samplesref->audio->nb_samples, inpos = 0, nb_samples;
203 204 AVFilterBufferRef *pbuf = link->partial_buf;
204 205 int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
  206 + int ret = 0;
205 207
206 208 if (!link->min_samples ||
207 209 (!pbuf &&
208 210 insamples >= link->min_samples && insamples <= link->max_samples)) {
209   - ff_filter_samples_framed(link, samplesref);
210   - return;
  211 + return ff_filter_samples_framed(link, samplesref);
211 212 }
212 213 /* Handle framing (min_samples, max_samples) */
213 214 while (insamples) {
@@ -218,7 +219,7 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
218 219 if (!pbuf) {
219 220 av_log(link->dst, AV_LOG_WARNING,
220 221 "Samples dropped due to memory allocation failure.\n");
221   - return;
  222 + return 0;
222 223 }
223 224 avfilter_copy_buffer_ref_props(pbuf, samplesref);
224 225 pbuf->pts = samplesref->pts +
@@ -234,10 +235,11 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
234 235 insamples -= nb_samples;
235 236 pbuf->audio->nb_samples += nb_samples;
236 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 239 pbuf = NULL;
239 240 }
240 241 }
241 242 avfilter_unref_buffer(samplesref);
242 243 link->partial_buf = pbuf;
  244 + return ret;
243 245 }
7 libavfilter/audio.h