* 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
Unified · Split
| @@ -327,7 +327,7 @@ OBJS-$(CONFIG_MSMPEG4V3_ENCODER) += msmpeg4.o msmpeg4enc.o msmpeg4data.o \ · 326 unmodified lines | ||
| 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 |
| @@ -175,10 +175,10 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, · 174 unmodified lines | ||
| 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 | } |
| @@ -119,15 +119,9 @@ int main(int argc, char **argv) · 118 unmodified lines | ||
| 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"); |
| @@ -26,6 +26,8 @@ · 25 unmodified lines | ||
| 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 { · 87 unmodified lines | ||
| 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, · 420 unmodified lines | ||
| 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, · 1 unmodified line | ||
| 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, · 11 unmodified lines | ||
| 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, · 40 unmodified lines | ||
| 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) · 10 unmodified lines | ||
| 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) * |
| @@ -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 | +} | |
| @@ -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 */ | |
| @@ -135,12 +135,13 @@ static int config_output(AVFilterLink *outlink) · 134 unmodified lines | ||
| 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 · 1 unmodified line | ||
| 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 = { |
| @@ -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 | |
| 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) · 13 unmodified lines | ||
| 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) · 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 | |
| 291 | 291 | static av_cold int init(AVFilterContext *ctx, const char *args) |
| @@ -305,9 +305,7 @@ static int output_frame(AVFilterLink *outlink, int nb_samples) · 304 unmodified lines | ||
| 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) · 134 unmodified lines | ||
| 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) |
| @@ -168,13 +168,14 @@ static int config_output(AVFilterLink *outlink) · 167 unmodified lines | ||
| 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 · 12 unmodified lines | ||
| 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) |
| @@ -131,7 +131,7 @@ static int push_samples(AVFilterLink *outlink) · 130 unmodified lines | ||
| 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) · 7 unmodified lines | ||
| 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) · 3 unmodified lines | ||
| 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) |
| @@ -40,7 +40,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 39 unmodified lines | ||
| 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) · 36 unmodified lines | ||
| 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 = { |
| @@ -107,11 +107,12 @@ static int config_output(AVFilterLink *outlink) · 106 unmodified lines | ||
| 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) · 3 unmodified lines | ||
| 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) · 33 unmodified lines | ||
| 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) · 3 unmodified lines | ||
| 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 = { |
| @@ -37,6 +37,9 @@ typedef struct ASyncContext { · 36 unmodified lines | ||
| 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) · 69 unmodified lines | ||
| 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) · 3 unmodified lines | ||
| 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) · 2 unmodified lines | ||
| 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) · 1 unmodified line | ||
| 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) · 1 unmodified line | ||
| 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) · 16 unmodified lines | ||
| 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) · 2 unmodified lines | ||
| 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) · 3 unmodified lines | ||
| 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 = { |
| @@ -1040,7 +1040,7 @@ static void push_samples(ATempoContext *atempo, · 1039 unmodified lines | ||
| 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, · 27 unmodified lines | ||
| 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) |
| @@ -313,7 +313,7 @@ static int channelmap_query_formats(AVFilterContext *ctx) · 312 unmodified lines | ||
| 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 · 10 unmodified lines | ||
| 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 · 15 unmodified lines | ||
| 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) |
| @@ -105,24 +105,29 @@ static int query_formats(AVFilterContext *ctx) · 104 unmodified lines | ||
| 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 = { |
| @@ -120,13 +120,15 @@ static inline int16_t *scalarproduct(const int16_t *in, const int16_t *endin, in · 119 unmodified lines | ||
| 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) · 11 unmodified lines | ||
| 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 = { |
| @@ -92,7 +92,7 @@ static const AVClass join_class = { · 91 unmodified lines | ||
| 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) · 5 unmodified lines | ||
| 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) · 358 unmodified lines | ||
| 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); |
| @@ -343,8 +343,9 @@ static int config_props(AVFilterLink *link) · 342 unmodified lines | ||
| 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) · 3 unmodified lines | ||
| 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) |
| @@ -38,6 +38,9 @@ typedef struct ResampleContext { · 37 unmodified lines | ||
| 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) · 58 unmodified lines | ||
| 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) · 16 unmodified lines | ||
| 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) · 19 unmodified lines | ||
| 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) · 2 unmodified lines | ||
| 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) · 19 unmodified lines | ||
| 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 = { |
| @@ -78,7 +78,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args) · 77 unmodified lines | ||
| 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) · 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 | |
| 124 | 124 | static int query_formats(AVFilterContext *ctx) |
| @@ -110,7 +110,7 @@ static int query_formats(AVFilterContext *ctx) · 109 unmodified lines | ||
| 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) · 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 | |
| 175 | 175 | AVFilter avfilter_af_volume = { |
| @@ -21,7 +21,10 @@ · 20 unmodified lines | ||
| 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", |
| @@ -150,19 +150,19 @@ fail: · 149 unmodified lines | ||
| 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, · 24 unmodified lines | ||
| 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) · 4 unmodified lines | ||
| 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) · 9 unmodified lines | ||
| 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 | } |
| @@ -70,14 +70,17 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 69 unmodified lines | ||
| 70 | 70 | * @param samplesref a reference to the buffer of audio samples being sent. The |
| 71 | 71 | * receiving filter will free this reference when it no longer |
| 72 | 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 | */ |
| 74 | −void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 77 | +int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 75 | 78 | |
| 76 | 79 | /** |
| 77 | 80 | * Send a buffer of audio samples to the next link, without checking |
| 78 | 81 | * min_samples. |
| 79 | 82 | */ |
| 80 | −void ff_filter_samples_framed(AVFilterLink *link, | |
| 83 | +int ff_filter_samples_framed(AVFilterLink *link, | |
| 81 | 84 | AVFilterBufferRef *samplesref); |
| 82 | 85 | |
| 83 | 86 | #endif /* AVFILTER_AUDIO_H */ |
| @@ -180,7 +180,7 @@ static int request_frame(AVFilterLink *outlink) · 179 unmodified lines | ||
| 180 | 180 | |
| 181 | 181 | #define MAX_INT16 ((1<<15) -1) |
| 182 | 182 | |
| 183 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) | |
| 183 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) | |
| 184 | 184 | { |
| 185 | 185 | AVFilterContext *ctx = inlink->dst; |
| 186 | 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 | 227 | avfilter_unref_buffer(insamples); |
| 228 | + return 0; | |
| 228 | 229 | } |
| 229 | 230 | |
| 230 | 231 | AVFilter avfilter_avf_showwaves = { |
| @@ -301,8 +301,12 @@ struct AVFilterPad { · 300 unmodified lines | ||
| 301 | 301 | * and should do its processing. |
| 302 | 302 | * |
| 303 | 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 | 312 | * Frame poll callback. This returns the number of immediately available |
| @@ -56,6 +56,12 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *buf) · 55 unmodified lines | ||
| 56 | 56 | link->cur_buf = NULL; |
| 57 | 57 | }; |
| 58 | 58 | |
| 59 | +static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) | |
| 60 | +{ | |
| 61 | + start_frame(link, buf); | |
| 62 | + return 0; | |
| 63 | +} | |
| 64 | + | |
| 59 | 65 | int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf) |
| 60 | 66 | { |
| 61 | 67 | BufferSinkContext *s = ctx->priv; |
| @@ -160,7 +166,7 @@ AVFilter avfilter_asink_abuffer = { · 98 unmodified lines | ||
| 160 | 166 | |
| 161 | 167 | .inputs = (AVFilterPad[]) {{ .name = "default", |
| 162 | 168 | .type = AVMEDIA_TYPE_AUDIO, |
| 163 | − .filter_samples = start_frame, | |
| 169 | + .filter_samples = filter_samples, | |
| 164 | 170 | .min_perms = AV_PERM_READ, |
| 165 | 171 | .needs_fifo = 1 }, |
| 166 | 172 | { .name = NULL }}, |
| @@ -408,6 +408,7 @@ static int request_frame(AVFilterLink *link) · 407 unmodified lines | ||
| 408 | 408 | { |
| 409 | 409 | BufferSourceContext *c = link->src->priv; |
| 410 | 410 | AVFilterBufferRef *buf; |
| 411 | + int ret = 0; | |
| 411 | 412 | |
| 412 | 413 | if (!av_fifo_size(c->fifo)) { |
| 413 | 414 | if (c->eof) |
| @@ -424,7 +425,7 @@ static int request_frame(AVFilterLink *link) · 10 unmodified lines | ||
| 424 | 425 | ff_end_frame(link); |
| 425 | 426 | break; |
| 426 | 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 | 429 | break; |
| 429 | 430 | default: |
| 430 | 431 | return AVERROR(EINVAL); |
| @@ -432,7 +433,7 @@ static int request_frame(AVFilterLink *link) · 1 unmodified line | ||
| 432 | 433 | |
| 433 | 434 | avfilter_unref_buffer(buf); |
| 434 | 435 | |
| 435 | − return 0; | |
| 436 | + return ret; | |
| 436 | 437 | } |
| 437 | 438 | |
| 438 | 439 | static int poll_frame(AVFilterLink *link) |
| @@ -117,7 +117,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) · 116 unmodified lines | ||
| 117 | 117 | ff_start_frame(outlink, picref2); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) | |
| 120 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) | |
| 121 | 121 | { |
| 122 | 122 | AVFilterContext *ctx = inlink->dst; |
| 123 | 123 | AVFilterLink *outlink = ctx->outputs[0]; |
| @@ -132,7 +132,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) · 8 unmodified lines | ||
| 132 | 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 | 138 | #if CONFIG_SETTB_FILTER |
| @@ -72,13 +72,25 @@ static av_cold void uninit(AVFilterContext *ctx) · 71 unmodified lines | ||
| 72 | 72 | avfilter_unref_buffer(fifo->buf_out); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | −static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 75 | +static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 76 | 76 | { |
| 77 | 77 | FifoContext *fifo = inlink->dst->priv; |
| 78 | 78 | |
| 79 | 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 | 85 | fifo->last = fifo->last->next; |
| 81 | 86 | fifo->last->buf = buf; |
| 87 | + | |
| 88 | + return 0; | |
| 89 | +} | |
| 90 | + | |
| 91 | +static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 92 | +{ | |
| 93 | + add_to_queue(inlink, buf); | |
| 82 | 94 | } |
| 83 | 95 | |
| 84 | 96 | static void queue_pop(FifoContext *s) |
| @@ -210,15 +222,13 @@ static int return_audio_frame(AVFilterContext *ctx) · 125 unmodified lines | ||
| 210 | 222 | buf_out = s->buf_out; |
| 211 | 223 | s->buf_out = NULL; |
| 212 | 224 | } |
| 213 | − ff_filter_samples(link, buf_out); | |
| 214 | − | |
| 215 | − return 0; | |
| 225 | + return ff_filter_samples(link, buf_out); | |
| 216 | 226 | } |
| 217 | 227 | |
| 218 | 228 | static int request_frame(AVFilterLink *outlink) |
| 219 | 229 | { |
| 220 | 230 | FifoContext *fifo = outlink->src->priv; |
| 221 | − int ret; | |
| 231 | + int ret = 0; | |
| 222 | 232 | |
| 223 | 233 | if (!fifo->root.next) { |
| 224 | 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 | 248 | if (outlink->request_samples) { |
| 239 | 249 | return return_audio_frame(outlink->src); |
| 240 | 250 | } else { |
| 241 | − ff_filter_samples(outlink, fifo->root.next->buf); | |
| 251 | + ret = ff_filter_samples(outlink, fifo->root.next->buf); | |
| 242 | 252 | queue_pop(fifo); |
| 243 | 253 | } |
| 244 | 254 | break; |
| @@ -246,7 +256,7 @@ static int request_frame(AVFilterLink *outlink) · 1 unmodified line | ||
| 246 | 256 | return AVERROR(EINVAL); |
| 247 | 257 | } |
| 248 | 258 | |
| 249 | − return 0; | |
| 259 | + return ret; | |
| 250 | 260 | } |
| 251 | 261 | |
| 252 | 262 | AVFilter avfilter_vf_fifo = { |
| @@ -261,7 +271,7 @@ AVFilter avfilter_vf_fifo = { · 8 unmodified lines | ||
| 261 | 271 | .inputs = (const AVFilterPad[]) {{ .name = "default", |
| 262 | 272 | .type = AVMEDIA_TYPE_VIDEO, |
| 263 | 273 | .get_video_buffer= ff_null_get_video_buffer, |
| 264 | − .start_frame = add_to_queue, | |
| 274 | + .start_frame = start_frame, | |
| 265 | 275 | .draw_slice = draw_slice, |
| 266 | 276 | .end_frame = end_frame, |
| 267 | 277 | .rej_perms = AV_PERM_REUSE2, }, |
| @@ -135,8 +135,12 @@ struct AVFilterPad { · 134 unmodified lines | ||
| 135 | 135 | * and should do its processing. |
| 136 | 136 | * |
| 137 | 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 | 146 | * Frame poll callback. This returns the number of immediately available |
| @@ -244,9 +244,10 @@ AVFilter avfilter_vsink_buffersink = { · 243 unmodified lines | ||
| 244 | 244 | |
| 245 | 245 | #if CONFIG_ABUFFERSINK_FILTER |
| 246 | 246 | |
| 247 | −static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) | |
| 247 | +static int filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) | |
| 248 | 248 | { |
| 249 | 249 | end_frame(link); |
| 250 | + return 0; | |
| 250 | 251 | } |
| 251 | 252 | |
| 252 | 253 | static av_cold int asink_init(AVFilterContext *ctx, const char *args) |
| @@ -110,15 +110,19 @@ AVFilter avfilter_vf_split = { · 109 unmodified lines | ||
| 110 | 110 | .outputs = (AVFilterPad[]) {{ .name = NULL}}, |
| 111 | 111 | }; |
| 112 | 112 | |
| 113 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) | |
| 113 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) | |
| 114 | 114 | { |
| 115 | 115 | AVFilterContext *ctx = inlink->dst; |
| 116 | − int i; | |
| 116 | + int i, ret = 0; | |
| 117 | 117 | |
| 118 | − for (i = 0; i < ctx->nb_outputs; i++) | |
| 119 | − ff_filter_samples(inlink->dst->outputs[i], | |
| 120 | − avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE)); | |
| 118 | + for (i = 0; i < ctx->nb_outputs; i++) { | |
| 119 | + ret = ff_filter_samples(inlink->dst->outputs[i], | |
| 120 | + avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE)); | |
| 121 | + if (ret < 0) | |
| 122 | + break; | |
| 123 | + } | |
| 121 | 124 | avfilter_unref_buffer(samplesref); |
| 125 | + return ret; | |
| 122 | 126 | } |
| 123 | 127 | |
| 124 | 128 | AVFilter avfilter_af_asplit = { |
| @@ -842,8 +842,11 @@ static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, · 841 unmodified lines | ||
| 842 | 842 | matroska->num_levels > 0 && |
| 843 | 843 | matroska->levels[matroska->num_levels-1].length == 0xffffffffffffff) |
| 844 | 844 | 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 | 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 | 850 | return ebml_parse_elem(matroska, &syntax[i], data); |
| 848 | 851 | } |
| 849 | 852 | |
| @@ -43,7 +43,7 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 42 unmodified lines | ||
| 43 | 43 | char buf[256]; |
| 44 | 44 | int ret; |
| 45 | 45 | socklen_t optlen; |
| 46 | − int timeout = 50; | |
| 46 | + int timeout = 50, listen_timeout = -1; | |
| 47 | 47 | char hostname[1024],proto[1024],path[1024]; |
| 48 | 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 | 59 | if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { |
| 60 | 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 | 66 | hints.ai_family = AF_UNSPEC; |
| 64 | 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 | 90 | if (listen_socket) { |
| 88 | 91 | int fd1; |
| 89 | 92 | int reuse = 1; |
| 93 | + struct pollfd lp = { fd, POLLIN, 0 }; | |
| 90 | 94 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); |
| 91 | 95 | ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); |
| 92 | 96 | if (ret) { |
| @@ -98,6 +102,11 @@ static int tcp_open(URLContext *h, const char *uri, int flags) · 5 unmodified lines | ||
| 98 | 102 | ret = ff_neterrno(); |
| 99 | 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 | 110 | fd1 = accept(fd, NULL, NULL); |
| 102 | 111 | if (fd1 < 0) { |
| 103 | 112 | ret = ff_neterrno(); |
| @@ -305,6 +305,14 @@ int ff_audio_mix_init(AVAudioResampleContext *avr) · 304 unmodified lines | ||
| 305 | 305 | { |
| 306 | 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 | 316 | /* build matrix if the user did not already set one */ |
| 309 | 317 | if (!avr->am->matrix) { |
| 310 | 318 | int i, j; |
| @@ -45,6 +45,13 @@ enum AVMixCoeffType { · 44 unmodified lines | ||
| 45 | 45 | AV_MIX_COEFF_TYPE_NB, /** Number of coeff types. Not part of ABI */ |
| 46 | 46 | }; |
| 47 | 47 | |
| 48 | +/** Resampling Filter Types */ | |
| 49 | +enum AVResampleFilterType { | |
| 50 | + AV_RESAMPLE_FILTER_TYPE_CUBIC, /**< Cubic */ | |
| 51 | + AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL, /**< Blackman Nuttall Windowed Sinc */ | |
| 52 | + AV_RESAMPLE_FILTER_TYPE_KAISER, /**< Kaiser Windowed Sinc */ | |
| 53 | +}; | |
| 54 | + | |
| 48 | 55 | /** |
| 49 | 56 | * Return the LIBAVRESAMPLE_VERSION_INT constant. |
| 50 | 57 | */ |
| @@ -50,6 +50,8 @@ struct AVAudioResampleContext { · 49 unmodified lines | ||
| 50 | 50 | int phase_shift; /**< log2 of the number of entries in the resampling polyphase filterbank */ |
| 51 | 51 | int linear_interp; /**< if 1 then the resampling FIR filter will be linearly interpolated */ |
| 52 | 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 | 56 | int in_channels; /**< number of input channels */ |
| 55 | 57 | int out_channels; /**< number of output channels */ |
| @@ -39,7 +39,7 @@ static const AVOption options[] = { · 38 unmodified lines | ||
| 39 | 39 | { "out_channel_layout", "Output Channel Layout", OFFSET(out_channel_layout), AV_OPT_TYPE_INT64, { 0 }, INT64_MIN, INT64_MAX, PARAM }, |
| 40 | 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 | 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 | 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 | 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 | 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 | 56 | { "none", "None", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_NONE }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" }, |
| 57 | 57 | { "dolby", "Dolby", 0, AV_OPT_TYPE_CONST, { AV_MATRIX_ENCODING_DOLBY }, INT_MIN, INT_MAX, PARAM, "matrix_encoding" }, |
| 58 | 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 | 64 | { NULL }, |
| 60 | 65 | }; |
| 61 | 66 | |
| @@ -24,37 +24,10 @@ · 23 unmodified lines | ||
| 24 | 24 | #include "internal.h" |
| 25 | 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 | − | |
| 54 | 27 | struct ResampleContext { |
| 55 | 28 | AVAudioResampleContext *avr; |
| 56 | 29 | AudioData *buffer; |
| 57 | − FELEM *filter_bank; | |
| 30 | + uint8_t *filter_bank; | |
| 58 | 31 | int filter_length; |
| 59 | 32 | int ideal_dst_incr; |
| 60 | 33 | int dst_incr; |
| @@ -65,9 +38,35 @@ struct ResampleContext { · 4 unmodified lines | ||
| 65 | 38 | int phase_shift; |
| 66 | 39 | int phase_mask; |
| 67 | 40 | int linear; |
| 41 | + enum AVResampleFilterType filter_type; | |
| 42 | + int kaiser_beta; | |
| 68 | 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 | 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 | 94 | * @param tap_count tap count |
| 96 | 95 | * @param phase_count phase count |
| 97 | 96 | * @param scale wanted sum of coefficients for each filter |
| 98 | − * @param type 0->cubic | |
| 99 | − * 1->blackman nuttall windowed sinc | |
| 100 | − * 2..16->kaiser windowed sinc beta=2..16 | |
| 97 | + * @param filter_type filter type | |
| 98 | + * @param kaiser_beta kaiser window beta | |
| 101 | 99 | * @return 0 on success, negative AVERROR code on failure |
| 102 | 100 | */ |
| 103 | −static int build_filter(FELEM *filter, double factor, int tap_count, | |
| 104 | − int phase_count, int scale, int type) | |
| 101 | +static int build_filter(ResampleContext *c) | |
| 105 | 102 | { |
| 106 | 103 | int ph, i; |
| 107 | − double x, y, w; | |
| 104 | + double x, y, w, factor; | |
| 108 | 105 | double *tab; |
| 106 | + int tap_count = c->filter_length; | |
| 107 | + int phase_count = 1 << c->phase_shift; | |
| 109 | 108 | const int center = (tap_count - 1) / 2; |
| 110 | 109 | |
| 111 | 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 | 112 | return AVERROR(ENOMEM); |
| 114 | 113 | |
| 115 | 114 | /* if upsampling, only need to interpolate, no filter */ |
| 116 | − if (factor > 1.0) | |
| 117 | − factor = 1.0; | |
| 115 | + factor = FFMIN(c->factor, 1.0); | |
| 118 | 116 | |
| 119 | 117 | for (ph = 0; ph < phase_count; ph++) { |
| 120 | 118 | double norm = 0; |
| @@ -122,39 +120,34 @@ static int build_filter(FELEM *filter, double factor, int tap_count, · 1 unmodified line | ||
| 122 | 120 | x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor; |
| 123 | 121 | if (x == 0) y = 1.0; |
| 124 | 122 | else y = sin(x) / x; |
| 125 | − switch (type) { | |
| 126 | − case 0: { | |
| 123 | + switch (c->filter_type) { | |
| 124 | + case AV_RESAMPLE_FILTER_TYPE_CUBIC: { | |
| 127 | 125 | const float d = -0.5; //first order derivative = -0.5 |
| 128 | 126 | x = fabs(((double)(i - center) - (double)ph / phase_count) * factor); |
| 129 | 127 | if (x < 1.0) y = 1 - 3 * x*x + 2 * x*x*x + d * ( -x*x + x*x*x); |
| 130 | 128 | else y = d * (-4 + 8 * x - 5 * x*x + x*x*x); |
| 131 | 129 | break; |
| 132 | 130 | } |
| 133 | − case 1: | |
| 131 | + case AV_RESAMPLE_FILTER_TYPE_BLACKMAN_NUTTALL: | |
| 134 | 132 | w = 2.0 * x / (factor * tap_count) + M_PI; |
| 135 | 133 | y *= 0.3635819 - 0.4891775 * cos( w) + |
| 136 | 134 | 0.1365995 * cos(2 * w) - |
| 137 | 135 | 0.0106411 * cos(3 * w); |
| 138 | 136 | break; |
| 139 | − default: | |
| 137 | + case AV_RESAMPLE_FILTER_TYPE_KAISER: | |
| 140 | 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 | 140 | break; |
| 143 | 141 | } |
| 144 | 142 | |
| 145 | 143 | tab[i] = y; |
| 146 | 144 | norm += y; |
| 147 | 145 | } |
| 148 | − | |
| 149 | 146 | /* normalize so that an uniform color remains the same */ |
| 150 | − for (i = 0; i < tap_count; i++) { | |
| 151 | −#ifdef CONFIG_RESAMPLE_FLT | |
| 152 | − filter[ph * tap_count + i] = tab[i] / norm; | |
| 153 | −#else | |
| 154 | − filter[ph * tap_count + i] = av_clip(lrintf(tab[i] * scale / norm), | |
| 155 | − FELEM_MIN, FELEM_MAX); | |
| 156 | −#endif | |
| 157 | − } | |
| 147 | + for (i = 0; i < tap_count; i++) | |
| 148 | + tab[i] = tab[i] / norm; | |
| 149 | + | |
| 150 | + c->set_filter(c->filter_bank, tab, ph, tap_count); | |
| 158 | 151 | } |
| 159 | 152 | |
| 160 | 153 | av_free(tab); |
| @@ -168,9 +161,12 @@ ResampleContext *ff_audio_resample_init(AVAudioResampleContext *avr) · 7 unmodified lines | ||
| 168 | 161 | int in_rate = avr->in_sample_rate; |
| 169 | 162 | double factor = FFMIN(out_rate * avr->cutoff / in_rate, 1.0); |
| 170 | 163 | int phase_count = 1 << avr->phase_shift; |
| 164 | + int felem_size; | |
| 171 | 165 | |
| 172 | − /* TODO: add support for s32 and float internal formats */ | |
| 173 | − if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) { | |
| 166 | + if (avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P && | |
| 167 | + avr->internal_sample_fmt != AV_SAMPLE_FMT_S32P && | |
| 168 | + avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP && | |
| 169 | + avr->internal_sample_fmt != AV_SAMPLE_FMT_DBLP) { | |
| 174 | 170 | av_log(avr, AV_LOG_ERROR, "Unsupported internal format for " |
| 175 | 171 | "resampling: %s\n", |
| 176 | 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 | 182 | c->linear = avr->linear_interp; |
| 187 | 183 | c->factor = factor; |
| 188 | 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 | 209 | if (!c->filter_bank) |
| 192 | 210 | goto error; |
| 193 | 211 | |
| 194 | − if (build_filter(c->filter_bank, factor, c->filter_length, phase_count, | |
| 195 | − 1 << FILTER_SHIFT, WINDOW_TYPE) < 0) | |
| 212 | + if (build_filter(c) < 0) | |
| 196 | 213 | goto error; |
| 197 | 214 | |
| 198 | − memcpy(&c->filter_bank[c->filter_length * phase_count + 1], | |
| 199 | − c->filter_bank, (c->filter_length - 1) * sizeof(FELEM)); | |
| 200 | − c->filter_bank[c->filter_length * phase_count] = c->filter_bank[c->filter_length - 1]; | |
| 215 | + memcpy(&c->filter_bank[(c->filter_length * phase_count + 1) * felem_size], | |
| 216 | + c->filter_bank, (c->filter_length - 1) * felem_size); | |
| 217 | + memcpy(&c->filter_bank[c->filter_length * phase_count * felem_size], | |
| 218 | + &c->filter_bank[(c->filter_length - 1) * felem_size], felem_size); | |
| 201 | 219 | |
| 202 | 220 | c->compensation_distance = 0; |
| 203 | 221 | if (!av_reduce(&c->src_incr, &c->dst_incr, out_rate, |
| @@ -311,10 +329,10 @@ reinit_fail: · 107 unmodified lines | ||
| 311 | 329 | return ret; |
| 312 | 330 | } |
| 313 | 331 | |
| 314 | −static int resample(ResampleContext *c, int16_t *dst, const int16_t *src, | |
| 332 | +static int resample(ResampleContext *c, void *dst, const void *src, | |
| 315 | 333 | int *consumed, int src_size, int dst_size, int update_ctx) |
| 316 | 334 | { |
| 317 | − int dst_index, i; | |
| 335 | + int dst_index; | |
| 318 | 336 | int index = c->index; |
| 319 | 337 | int frac = c->frac; |
| 320 | 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 | 353 | if (dst) { |
| 336 | 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 | 356 | index2 += incr; |
| 339 | 357 | } |
| 340 | 358 | } else { |
| @@ -345,42 +363,14 @@ static int resample(ResampleContext *c, int16_t *dst, const int16_t *src, · 4 unmodified lines | ||
| 345 | 363 | frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr; |
| 346 | 364 | } else { |
| 347 | 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 | 366 | int sample_index = index >> c->phase_shift; |
| 351 | 367 | |
| 352 | − if (!dst && (sample_index + c->filter_length > src_size || | |
| 353 | − -sample_index >= src_size)) | |
| 368 | + if (sample_index + c->filter_length > src_size || | |
| 369 | + -sample_index >= src_size) | |
| 354 | 370 | break; |
| 355 | 371 | |
| 356 | − if (dst) { | |
| 357 | − FELEM2 val = 0; | |
| 358 | − | |
| 359 | − if (sample_index < 0) { | |
| 360 | − for (i = 0; i < c->filter_length; i++) | |
| 361 | − val += src[FFABS(sample_index + i) % src_size] * | |
| 362 | − (FELEM2)filter[i]; | |
| 363 | − } else if (sample_index + c->filter_length > src_size) { | |
| 364 | − break; | |
| 365 | − } else if (c->linear) { | |
| 366 | − FELEM2 v2 = 0; | |
| 367 | − for (i = 0; i < c->filter_length; i++) { | |
| 368 | − val += src[abs(sample_index + i)] * (FELEM2)filter[i]; | |
| 369 | − v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length]; | |
| 370 | − } | |
| 371 | − val += (v2 - val) * (FELEML)frac / c->src_incr; | |
| 372 | − } else { | |
| 373 | − for (i = 0; i < c->filter_length; i++) | |
| 374 | − val += src[sample_index + i] * (FELEM2)filter[i]; | |
| 375 | − } | |
| 376 | − | |
| 377 | −#ifdef CONFIG_RESAMPLE_FLT | |
| 378 | − dst[dst_index] = av_clip_int16(lrintf(val)); | |
| 379 | −#else | |
| 380 | − val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT; | |
| 381 | − dst[dst_index] = av_clip_int16(val); | |
| 382 | −#endif | |
| 383 | − } | |
| 372 | + if (dst) | |
| 373 | + c->resample_one(c, 0, dst, dst_index, src, src_size, index, frac); | |
| 384 | 374 | |
| 385 | 375 | frac += dst_incr_frac; |
| 386 | 376 | index += dst_incr; |
| @@ -451,8 +441,8 @@ int ff_audio_resample(ResampleContext *c, AudioData *dst, AudioData *src, · 64 unmodified lines | ||
| 451 | 441 | |
| 452 | 442 | /* resample each channel plane */ |
| 453 | 443 | for (ch = 0; ch < c->buffer->channels; ch++) { |
| 454 | − out_samples = resample(c, (int16_t *)dst->data[ch], | |
| 455 | − (const int16_t *)c->buffer->data[ch], consumed, | |
| 444 | + out_samples = resample(c, (void *)dst->data[ch], | |
| 445 | + (const void *)c->buffer->data[ch], consumed, | |
| 456 | 446 | c->buffer->nb_samples, dst->allocated_samples, |
| 457 | 447 | ch + 1 == c->buffer->channels); |
| 458 | 448 | } |
| @@ -0,0 +1,102 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> | |
| 3 | + * | |
| 4 | + * This file is part of FFmpeg. | |
| 5 | + * | |
| 6 | + * FFmpeg is free software; you can redistribute it and/or | |
| 7 | + * modify it under the terms of the GNU Lesser General Public | |
| 8 | + * License as published by the Free Software Foundation; either | |
| 9 | + * version 2.1 of the License, or (at your option) any later version. | |
| 10 | + * | |
| 11 | + * FFmpeg is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | + * Lesser General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public | |
| 17 | + * License along with FFmpeg; if not, write to the Free Software | |
| 18 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
| 19 | + */ | |
| 20 | + | |
| 21 | +#if defined(CONFIG_RESAMPLE_DBL) | |
| 22 | +#define SET_TYPE(func) func ## _dbl | |
| 23 | +#define FELEM double | |
| 24 | +#define FELEM2 double | |
| 25 | +#define FELEML double | |
| 26 | +#define OUT(d, v) d = v | |
| 27 | +#define DBL_TO_FELEM(d, v) d = v | |
| 28 | +#elif defined(CONFIG_RESAMPLE_FLT) | |
| 29 | +#define SET_TYPE(func) func ## _flt | |
| 30 | +#define FELEM float | |
| 31 | +#define FELEM2 float | |
| 32 | +#define FELEML float | |
| 33 | +#define OUT(d, v) d = v | |
| 34 | +#define DBL_TO_FELEM(d, v) d = v | |
| 35 | +#elif defined(CONFIG_RESAMPLE_S32) | |
| 36 | +#define SET_TYPE(func) func ## _s32 | |
| 37 | +#define FELEM int32_t | |
| 38 | +#define FELEM2 int64_t | |
| 39 | +#define FELEML int64_t | |
| 40 | +#define OUT(d, v) d = av_clipl_int32((v + (1 << 29)) >> 30) | |
| 41 | +#define DBL_TO_FELEM(d, v) d = av_clipl_int32(llrint(v * (1 << 30))); | |
| 42 | +#else | |
| 43 | +#define SET_TYPE(func) func ## _s16 | |
| 44 | +#define FELEM int16_t | |
| 45 | +#define FELEM2 int32_t | |
| 46 | +#define FELEML int64_t | |
| 47 | +#define OUT(d, v) d = av_clip_int16((v + (1 << 14)) >> 15) | |
| 48 | +#define DBL_TO_FELEM(d, v) d = av_clip_int16(lrint(v * (1 << 15))) | |
| 49 | +#endif | |
| 50 | + | |
| 51 | +static void SET_TYPE(resample_one)(ResampleContext *c, int no_filter, | |
| 52 | + void *dst0, int dst_index, const void *src0, | |
| 53 | + int src_size, int index, int frac) | |
| 54 | +{ | |
| 55 | + FELEM *dst = dst0; | |
| 56 | + const FELEM *src = src0; | |
| 57 | + | |
| 58 | + if (no_filter) { | |
| 59 | + dst[dst_index] = src[index]; | |
| 60 | + } else { | |
| 61 | + int i; | |
| 62 | + int sample_index = index >> c->phase_shift; | |
| 63 | + FELEM2 val = 0; | |
| 64 | + FELEM *filter = ((FELEM *)c->filter_bank) + | |
| 65 | + c->filter_length * (index & c->phase_mask); | |
| 66 | + | |
| 67 | + if (sample_index < 0) { | |
| 68 | + for (i = 0; i < c->filter_length; i++) | |
| 69 | + val += src[FFABS(sample_index + i) % src_size] * | |
| 70 | + (FELEM2)filter[i]; | |
| 71 | + } else if (c->linear) { | |
| 72 | + FELEM2 v2 = 0; | |
| 73 | + for (i = 0; i < c->filter_length; i++) { | |
| 74 | + val += src[abs(sample_index + i)] * (FELEM2)filter[i]; | |
| 75 | + v2 += src[abs(sample_index + i)] * (FELEM2)filter[i + c->filter_length]; | |
| 76 | + } | |
| 77 | + val += (v2 - val) * (FELEML)frac / c->src_incr; | |
| 78 | + } else { | |
| 79 | + for (i = 0; i < c->filter_length; i++) | |
| 80 | + val += src[sample_index + i] * (FELEM2)filter[i]; | |
| 81 | + } | |
| 82 | + | |
| 83 | + OUT(dst[dst_index], val); | |
| 84 | + } | |
| 85 | +} | |
| 86 | + | |
| 87 | +static void SET_TYPE(set_filter)(void *filter0, double *tab, int phase, | |
| 88 | + int tap_count) | |
| 89 | +{ | |
| 90 | + int i; | |
| 91 | + FELEM *filter = ((FELEM *)filter0) + phase * tap_count; | |
| 92 | + for (i = 0; i < tap_count; i++) { | |
| 93 | + DBL_TO_FELEM(filter[i], tab[i]); | |
| 94 | + } | |
| 95 | +} | |
| 96 | + | |
| 97 | +#undef SET_TYPE | |
| 98 | +#undef FELEM | |
| 99 | +#undef FELEM2 | |
| 100 | +#undef FELEML | |
| 101 | +#undef OUT | |
| 102 | +#undef DBL_TO_FELEM | |
| @@ -57,18 +57,43 @@ int avresample_open(AVAudioResampleContext *avr) · 56 unmodified lines | ||
| 57 | 57 | avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate || |
| 58 | 58 | avr->force_resampling; |
| 59 | 59 | |
| 60 | − /* set sample format conversion parameters */ | |
| 61 | − /* override user-requested internal format to avoid unexpected failures | |
| 62 | − TODO: support more internal formats */ | |
| 63 | − if (avr->resample_needed && avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P) { | |
| 64 | − av_log(avr, AV_LOG_WARNING, "Using s16p as internal sample format\n"); | |
| 65 | − avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P; | |
| 66 | − } else if (avr->mixing_needed && | |
| 67 | − avr->internal_sample_fmt != AV_SAMPLE_FMT_S16P && | |
| 68 | − avr->internal_sample_fmt != AV_SAMPLE_FMT_FLTP) { | |
| 69 | − av_log(avr, AV_LOG_WARNING, "Using fltp as internal sample format\n"); | |
| 70 | − avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP; | |
| 60 | + /* select internal sample format if not specified by the user */ | |
| 61 | + if (avr->internal_sample_fmt == AV_SAMPLE_FMT_NONE && | |
| 62 | + (avr->mixing_needed || avr->resample_needed)) { | |
| 63 | + enum AVSampleFormat in_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt); | |
| 64 | + enum AVSampleFormat out_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt); | |
| 65 | + int max_bps = FFMAX(av_get_bytes_per_sample(in_fmt), | |
| 66 | + av_get_bytes_per_sample(out_fmt)); | |
| 67 | + if (max_bps <= 2) { | |
| 68 | + avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P; | |
| 69 | + } else if (avr->mixing_needed) { | |
| 70 | + avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP; | |
| 71 | + } else { | |
| 72 | + if (max_bps <= 4) { | |
| 73 | + if (in_fmt == AV_SAMPLE_FMT_S32P || | |
| 74 | + out_fmt == AV_SAMPLE_FMT_S32P) { | |
| 75 | + if (in_fmt == AV_SAMPLE_FMT_FLTP || | |
| 76 | + out_fmt == AV_SAMPLE_FMT_FLTP) { | |
| 77 | + /* if one is s32 and the other is flt, use dbl */ | |
| 78 | + avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP; | |
| 79 | + } else { | |
| 80 | + /* if one is s32 and the other is s32, s16, or u8, use s32 */ | |
| 81 | + avr->internal_sample_fmt = AV_SAMPLE_FMT_S32P; | |
| 82 | + } | |
| 83 | + } else { | |
| 84 | + /* if one is flt and the other is flt, s16 or u8, use flt */ | |
| 85 | + avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP; | |
| 86 | + } | |
| 87 | + } else { | |
| 88 | + /* if either is dbl, use dbl */ | |
| 89 | + avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP; | |
| 90 | + } | |
| 91 | + } | |
| 92 | + av_log(avr, AV_LOG_DEBUG, "Using %s as internal sample format\n", | |
| 93 | + av_get_sample_fmt_name(avr->internal_sample_fmt)); | |
| 71 | 94 | } |
| 95 | + | |
| 96 | + /* set sample format conversion parameters */ | |
| 72 | 97 | if (avr->in_channels == 1) |
| 73 | 98 | avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt); |
| 74 | 99 | if (avr->out_channels == 1) |
| @@ -75,7 +75,13 @@ probefmt(){ · 74 unmodified lines | ||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | ffmpeg(){ |
| 78 | − run ffmpeg -nostats -threads $threads -thread_type $thread_type -cpuflags $cpuflags "$@" | |
| 78 | + dec_opts="-threads $threads -thread_type $thread_type" | |
| 79 | + ffmpeg_args="-nostats -cpuflags $cpuflags" | |
| 80 | + for arg in $@; do | |
| 81 | + [ ${arg} = -i ] && ffmpeg_args="${ffmpeg_args} ${dec_opts}" | |
| 82 | + ffmpeg_args="${ffmpeg_args} ${arg}" | |
| 83 | + done | |
| 84 | + run ffmpeg ${ffmpeg_args} | |
| 79 | 85 | } |
| 80 | 86 | |
| 81 | 87 | framecrc(){ |