From 404410a53ac9490d2c74369f7aab18afcc578bc3 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Sat, 12 May 2012 07:21:32 -0700 Subject: [PATCH 01/19] sws: fix planar RGB input conversions for 9/10/16 bpp. Fixes bug 282. Signed-off-by: Anton Khirnov --- libswscale/input.c | 156 ++++++++++++++++++++++++++++++--------------- 1 file changed, 106 insertions(+), 50 deletions(-) diff --git a/libswscale/input.c b/libswscale/input.c index afc515608d..40ed122427 100644 --- a/libswscale/input.c +++ b/libswscale/input.c @@ -553,34 +553,6 @@ static void planar_rgb_to_y(uint8_t *dst, const uint8_t *src[4], int width) } } -static void planar_rgb16le_to_y(uint8_t *_dst, const uint8_t *_src[4], int width) -{ - int i; - const uint16_t **src = (const uint16_t **)_src; - uint16_t *dst = (uint16_t *)_dst; - for (i = 0; i < width; i++) { - int g = AV_RL16(src[0] + i); - int b = AV_RL16(src[1] + i); - int r = AV_RL16(src[2] + i); - - dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); - } -} - -static void planar_rgb16be_to_y(uint8_t *_dst, const uint8_t *_src[4], int width) -{ - int i; - const uint16_t **src = (const uint16_t **)_src; - uint16_t *dst = (uint16_t *)_dst; - for (i = 0; i < width; i++) { - int g = AV_RB16(src[0] + i); - int b = AV_RB16(src[1] + i); - int r = AV_RB16(src[2] + i); - - dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); - } -} - static void planar_rgb_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], int width) { int i; @@ -589,43 +561,111 @@ static void planar_rgb_to_uv(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4] int b = src[1][i]; int r = src[2][i]; - dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); - dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); + dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; + dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT; } } -static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV, - const uint8_t *_src[4], int width) +#define rdpx(src) \ + is_be ? AV_RB16(src) : AV_RL16(src) +static av_always_inline void planar_rgb16_to_y(uint8_t *_dst, const uint8_t *_src[4], + int width, int bpc, int is_be) +{ + int i; + const uint16_t **src = (const uint16_t **)_src; + uint16_t *dst = (uint16_t *)_dst; + for (i = 0; i < width; i++) { + int g = rdpx(src[0] + i); + int b = rdpx(src[1] + i); + int r = rdpx(src[2] + i); + + dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT); + } +} + +static void planar_rgb9le_to_y(uint8_t *dst, const uint8_t *src[4], int w) +{ + planar_rgb16_to_y(dst, src, w, 9, 0); +} + +static void planar_rgb9be_to_y(uint8_t *dst, const uint8_t *src[4], int w) +{ + planar_rgb16_to_y(dst, src, w, 9, 1); +} + +static void planar_rgb10le_to_y(uint8_t *dst, const uint8_t *src[4], int w) +{ + planar_rgb16_to_y(dst, src, w, 10, 0); +} + +static void planar_rgb10be_to_y(uint8_t *dst, const uint8_t *src[4], int w) +{ + planar_rgb16_to_y(dst, src, w, 10, 1); +} + +static void planar_rgb16le_to_y(uint8_t *dst, const uint8_t *src[4], int w) +{ + planar_rgb16_to_y(dst, src, w, 16, 0); +} + +static void planar_rgb16be_to_y(uint8_t *dst, const uint8_t *src[4], int w) +{ + planar_rgb16_to_y(dst, src, w, 16, 1); +} + +static av_always_inline void planar_rgb16_to_uv(uint8_t *_dstU, uint8_t *_dstV, + const uint8_t *_src[4], int width, + int bpc, int is_be) { int i; const uint16_t **src = (const uint16_t **)_src; uint16_t *dstU = (uint16_t *)_dstU; uint16_t *dstV = (uint16_t *)_dstV; for (i = 0; i < width; i++) { - int g = AV_RL16(src[0] + i); - int b = AV_RL16(src[1] + i); - int r = AV_RL16(src[2] + i); + int g = rdpx(src[0] + i); + int b = rdpx(src[1] + i); + int r = rdpx(src[2] + i); - dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); - dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); + dstU[i] = (RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT; + dstV[i] = (RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT + bpc - 9))) >> RGB2YUV_SHIFT; } } +#undef rdpx -static void planar_rgb16be_to_uv(uint8_t *_dstU, uint8_t *_dstV, - const uint8_t *_src[4], int width) +static void planar_rgb9le_to_uv(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src[4], int w) { - int i; - const uint16_t **src = (const uint16_t **)_src; - uint16_t *dstU = (uint16_t *)_dstU; - uint16_t *dstV = (uint16_t *)_dstV; - for (i = 0; i < width; i++) { - int g = AV_RB16(src[0] + i); - int b = AV_RB16(src[1] + i); - int r = AV_RB16(src[2] + i); + planar_rgb16_to_uv(dstU, dstV, src, w, 9, 0); +} - dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); - dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); - } +static void planar_rgb9be_to_uv(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src[4], int w) +{ + planar_rgb16_to_uv(dstU, dstV, src, w, 9, 1); +} + +static void planar_rgb10le_to_uv(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src[4], int w) +{ + planar_rgb16_to_uv(dstU, dstV, src, w, 10, 0); +} + +static void planar_rgb10be_to_uv(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src[4], int w) +{ + planar_rgb16_to_uv(dstU, dstV, src, w, 10, 1); +} + +static void planar_rgb16le_to_uv(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src[4], int w) +{ + planar_rgb16_to_uv(dstU, dstV, src, w, 16, 0); +} + +static void planar_rgb16be_to_uv(uint8_t *dstU, uint8_t *dstV, + const uint8_t *src[4], int w) +{ + planar_rgb16_to_uv(dstU, dstV, src, w, 16, 1); } av_cold void ff_sws_init_input_funcs(SwsContext *c) @@ -654,12 +694,20 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) c->chrToYV12 = palToUV_c; break; case PIX_FMT_GBRP9LE: + c->readChrPlanar = planar_rgb9le_to_uv; + break; case PIX_FMT_GBRP10LE: + c->readChrPlanar = planar_rgb10le_to_uv; + break; case PIX_FMT_GBRP16LE: c->readChrPlanar = planar_rgb16le_to_uv; break; case PIX_FMT_GBRP9BE: + c->readChrPlanar = planar_rgb9be_to_uv; + break; case PIX_FMT_GBRP10BE: + c->readChrPlanar = planar_rgb10be_to_uv; + break; case PIX_FMT_GBRP16BE: c->readChrPlanar = planar_rgb16be_to_uv; break; @@ -836,12 +884,20 @@ av_cold void ff_sws_init_input_funcs(SwsContext *c) c->alpToYV12 = NULL; switch (srcFormat) { case PIX_FMT_GBRP9LE: + c->readLumPlanar = planar_rgb9le_to_y; + break; case PIX_FMT_GBRP10LE: + c->readLumPlanar = planar_rgb10le_to_y; + break; case PIX_FMT_GBRP16LE: c->readLumPlanar = planar_rgb16le_to_y; break; case PIX_FMT_GBRP9BE: + c->readLumPlanar = planar_rgb9be_to_y; + break; case PIX_FMT_GBRP10BE: + c->readLumPlanar = planar_rgb10be_to_y; + break; case PIX_FMT_GBRP16BE: c->readLumPlanar = planar_rgb16be_to_y; break; From 4795362660a526a38a7a60f06826bce97a092b59 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Mon, 11 Jun 2012 10:29:57 -0400 Subject: [PATCH 02/19] golomb: check remaining bits during unary decoding in get_ur_golomb_jpegls() Fixes infinite loop in FLAC decoding in case of a truncated bitstream due to the safe bitstream reader returning 0's at the end. Fixes Bug 310. CC:libav-stable@libav.org --- libavcodec/golomb.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index 1712540fd3..b6b8cc8412 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -301,7 +301,7 @@ static inline int get_ur_golomb_jpegls(GetBitContext *gb, int k, int limit, int return buf; }else{ int i; - for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) { + for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0 && HAVE_BITS_REMAINING(re, gb); i++) { LAST_SKIP_BITS(re, gb, 1); UPDATE_CACHE(re, gb); } From d6251368772a170987387bdc508433c8fcf54cda Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 30 May 2012 13:59:30 +0200 Subject: [PATCH 03/19] lavfi: add channelsplit audio filter. --- Changelog | 1 + doc/filters.texi | 25 ++++++ libavfilter/Makefile | 1 + libavfilter/af_channelsplit.c | 146 ++++++++++++++++++++++++++++++++++ libavfilter/allfilters.c | 1 + libavfilter/formats.c | 12 +++ libavfilter/formats.h | 5 ++ libavfilter/version.h | 2 +- 8 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 libavfilter/af_channelsplit.c diff --git a/Changelog b/Changelog index 898a2473e8..b80ff8885e 100644 --- a/Changelog +++ b/Changelog @@ -24,6 +24,7 @@ version : - avprobe output is now standard INI or JSON. The old format can still be used with -of old. - Indeo Audio decoder +- channelsplit audio filter version 0.8: diff --git a/doc/filters.texi b/doc/filters.texi index 0179682918..f17dad8051 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -207,6 +207,31 @@ Maximum compensation in samples per second. @end table +@section channelsplit +Split each channel in input audio stream into a separate output stream. + +This filter accepts the following named parameters: +@table @option +@item channel_layout +Channel layout of the input stream. Default is "stereo". +@end table + +For example, assuming a stereo input MP3 file +@example +avconv -i in.mp3 -filter_complex channelsplit out.mkv +@end example +will create an output Matroska file with two audio streams, one containing only +the left channel and the other the right channel. + +To split a 5.1 WAV file into per-channel files +@example +avconv -i in.wav -filter_complex +'channelsplit=channel_layout=5.1[FL][FR][FC][LFE][SL][SR]' +-map '[FL]' front_left.wav -map '[FR]' front_right.wav -map '[FC]' +front_center.wav -map '[LFE]' lfe.wav -map '[SL]' side_left.wav -map '[SR]' +side_right.wav +@end example + @section resample Convert the audio sample format, sample rate and channel layout. This filter is not meant to be used directly, it is inserted automatically by libavfilter diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 914f0c6b8e..7e1a6d1209 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -29,6 +29,7 @@ OBJS-$(CONFIG_AMIX_FILTER) += af_amix.o OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o OBJS-$(CONFIG_ASPLIT_FILTER) += split.o OBJS-$(CONFIG_ASYNCTS_FILTER) += af_asyncts.o +OBJS-$(CONFIG_CHANNELSPLIT_FILTER) += af_channelsplit.o OBJS-$(CONFIG_RESAMPLE_FILTER) += af_resample.o OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c new file mode 100644 index 0000000000..c3e7ccfc69 --- /dev/null +++ b/libavfilter/af_channelsplit.c @@ -0,0 +1,146 @@ +/* + * This file is part of Libav. + * + * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * Libav is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * Channel split filter + * + * Split an audio stream into per-channel streams. + */ + +#include "libavutil/audioconvert.h" +#include "libavutil/opt.h" + +#include "audio.h" +#include "avfilter.h" +#include "formats.h" +#include "internal.h" + +typedef struct ChannelSplitContext { + const AVClass *class; + + uint64_t channel_layout; + char *channel_layout_str; +} ChannelSplitContext; + +#define OFFSET(x) offsetof(ChannelSplitContext, x) +#define A AV_OPT_FLAG_AUDIO_PARAM +static const AVOption options[] = { + { "channel_layout", "Input channel layout.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, { .str = "stereo" }, .flags = A }, + { NULL }, +}; + +static const AVClass channelsplit_class = { + .class_name = "channelsplit filter", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +static int init(AVFilterContext *ctx, const char *arg, void *opaque) +{ + ChannelSplitContext *s = ctx->priv; + int nb_channels; + int ret = 0, i; + + s->class = &channelsplit_class; + av_opt_set_defaults(s); + if ((ret = av_set_options_string(s, arg, "=", ":")) < 0) { + av_log(ctx, AV_LOG_ERROR, "Error parsing options string '%s'.\n", arg); + return ret; + } + if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) { + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", + s->channel_layout_str); + ret = AVERROR(EINVAL); + goto fail; + } + + nb_channels = av_get_channel_layout_nb_channels(s->channel_layout); + for (i = 0; i < nb_channels; i++) { + uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); + AVFilterPad pad = { 0 }; + + pad.type = AVMEDIA_TYPE_AUDIO; + pad.name = av_get_channel_name(channel); + + ff_insert_outpad(ctx, i, &pad); + } + +fail: + av_opt_free(s); + return ret; +} + +static int query_formats(AVFilterContext *ctx) +{ + ChannelSplitContext *s = ctx->priv; + AVFilterChannelLayouts *in_layouts = NULL; + int i; + + ff_set_common_formats (ctx, ff_planar_sample_fmts()); + ff_set_common_samplerates(ctx, ff_all_samplerates()); + + ff_add_channel_layout(&in_layouts, s->channel_layout); + ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts); + + for (i = 0; i < ctx->output_count; i++) { + AVFilterChannelLayouts *out_layouts = NULL; + uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); + + ff_add_channel_layout(&out_layouts, channel); + ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts); + } + + return 0; +} + +static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) +{ + AVFilterContext *ctx = inlink->dst; + int i; + + for (i = 0; i < ctx->output_count; i++) { + AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE); + + if (!buf_out) + return; + + buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i]; + buf_out->audio->channel_layout = + av_channel_layout_extract_channel(buf->audio->channel_layout, i); + + ff_filter_samples(ctx->outputs[i], buf_out); + } + avfilter_unref_buffer(buf); +} + +AVFilter avfilter_af_channelsplit = { + .name = "channelsplit", + .description = NULL_IF_CONFIG_SMALL("Split audio into per-channel streams"), + .priv_size = sizeof(ChannelSplitContext), + + .init = init, + .query_formats = query_formats, + + .inputs = (const AVFilterPad[]){{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .filter_samples = filter_samples, }, + { NULL }}, + .outputs = (const AVFilterPad[]){{ NULL }}, +}; diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 941ca6a20d..681487118b 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -39,6 +39,7 @@ void avfilter_register_all(void) REGISTER_FILTER (ANULL, anull, af); REGISTER_FILTER (ASPLIT, asplit, af); REGISTER_FILTER (ASYNCTS, asyncts, af); + REGISTER_FILTER (CHANNELSPLIT,channelsplit,af); REGISTER_FILTER (RESAMPLE, resample, af); REGISTER_FILTER (ANULLSRC, anullsrc, asrc); diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 83bdcd7a7a..1d58d95b8e 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -220,6 +220,18 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type) return ret; } +AVFilterFormats *ff_planar_sample_fmts(void) +{ + AVFilterFormats *ret = NULL; + int fmt; + + for (fmt = 0; fmt < AV_SAMPLE_FMT_NB; fmt++) + if (av_sample_fmt_is_planar(fmt)) + ff_add_format(&ret, fmt); + + return ret; +} + AVFilterFormats *ff_all_samplerates(void) { AVFilterFormats *ret = av_mallocz(sizeof(*ret)); diff --git a/libavfilter/formats.h b/libavfilter/formats.h index 8961cb1a65..c3e9522c89 100644 --- a/libavfilter/formats.h +++ b/libavfilter/formats.h @@ -159,6 +159,11 @@ int ff_add_format(AVFilterFormats **avff, int fmt); */ AVFilterFormats *ff_all_formats(enum AVMediaType type); +/** + * Construct a formats list containing all planar sample formats. + */ +AVFilterFormats *ff_planar_sample_fmts(void); + /** * Return a format list which contains the intersection of the formats of * a and b. Also, all the references of a, all the references of b, and diff --git a/libavfilter/version.h b/libavfilter/version.h index 9a64316949..09cf4c69e5 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -29,7 +29,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 20 +#define LIBAVFILTER_VERSION_MINOR 21 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ From af10feadc23de2c9c876d4cd86abf3d75813cef1 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Sun, 3 Jun 2012 17:20:30 +0200 Subject: [PATCH 04/19] ppc: Rename H.264 optimization template file for consistency. --- libavcodec/ppc/h264_altivec.c | 4 ++-- .../ppc/{h264_template_altivec.c => h264_altivec_template.c} | 0 libavcodec/ppc/vc1dsp_altivec.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename libavcodec/ppc/{h264_template_altivec.c => h264_altivec_template.c} (100%) diff --git a/libavcodec/ppc/h264_altivec.c b/libavcodec/ppc/h264_altivec.c index 92bfd454a4..05a5c51d38 100644 --- a/libavcodec/ppc/h264_altivec.c +++ b/libavcodec/ppc/h264_altivec.c @@ -39,7 +39,7 @@ #define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num #define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec #define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num -#include "h264_template_altivec.c" +#include "h264_altivec_template.c" #undef OP_U8_ALTIVEC #undef PREFIX_h264_chroma_mc8_altivec #undef PREFIX_h264_chroma_mc8_num @@ -59,7 +59,7 @@ #define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num #define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec #define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num -#include "h264_template_altivec.c" +#include "h264_altivec_template.c" #undef OP_U8_ALTIVEC #undef PREFIX_h264_chroma_mc8_altivec #undef PREFIX_h264_chroma_mc8_num diff --git a/libavcodec/ppc/h264_template_altivec.c b/libavcodec/ppc/h264_altivec_template.c similarity index 100% rename from libavcodec/ppc/h264_template_altivec.c rename to libavcodec/ppc/h264_altivec_template.c diff --git a/libavcodec/ppc/vc1dsp_altivec.c b/libavcodec/ppc/vc1dsp_altivec.c index 38a7da23f5..6c110dba47 100644 --- a/libavcodec/ppc/vc1dsp_altivec.c +++ b/libavcodec/ppc/vc1dsp_altivec.c @@ -325,13 +325,13 @@ static void vc1_inv_trans_8x4_altivec(uint8_t *dest, int stride, DCTELEM *block) #define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC #define PREFIX_no_rnd_vc1_chroma_mc8_altivec put_no_rnd_vc1_chroma_mc8_altivec -#include "h264_template_altivec.c" +#include "h264_altivec_template.c" #undef OP_U8_ALTIVEC #undef PREFIX_no_rnd_vc1_chroma_mc8_altivec #define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC #define PREFIX_no_rnd_vc1_chroma_mc8_altivec avg_no_rnd_vc1_chroma_mc8_altivec -#include "h264_template_altivec.c" +#include "h264_altivec_template.c" #undef OP_U8_ALTIVEC #undef PREFIX_no_rnd_vc1_chroma_mc8_altivec From 053386864219eccbcca1886c55f902f9555428a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 13 Jun 2012 10:51:22 +0300 Subject: [PATCH 05/19] rtmp: Tokenize the AMF connection parameters manually instead of using strtok_r MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes builds on platforms without strtok_r (windows). Signed-off-by: Martin Storsjö --- libavformat/rtmpproto.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 56011f1cde..2b15d80846 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -115,7 +115,7 @@ static const uint8_t rtmp_server_key[] = { static int rtmp_write_amf_data(URLContext *s, char *param, uint8_t **p) { - char *field, *value, *saveptr; + char *field, *value; char type; /* The type must be B for Boolean, N for number, S for string, O for @@ -130,8 +130,12 @@ static int rtmp_write_amf_data(URLContext *s, char *param, uint8_t **p) value = param + 2; } else if (param[0] == 'N' && param[1] && param[2] == ':') { type = param[1]; - field = strtok_r(param + 3, ":", &saveptr); - value = strtok_r(NULL, ":", &saveptr); + field = param + 3; + value = strchr(field, ':'); + if (!value) + goto fail; + *value = '\0'; + value++; if (!field || !value) goto fail; @@ -226,18 +230,27 @@ static int gen_connect(URLContext *s, RTMPContext *rt) ff_amf_write_object_end(&p); if (rt->conn) { - char *param, *saveptr; + char *param = rt->conn; // Write arbitrary AMF data to the Connect message. - param = strtok_r(rt->conn, " ", &saveptr); while (param != NULL) { + char *sep; + param += strspn(param, " "); + if (!*param) + break; + sep = strchr(param, ' '); + if (sep) + *sep = '\0'; if ((ret = rtmp_write_amf_data(s, param, &p)) < 0) { // Invalid AMF parameter. ff_rtmp_packet_destroy(&pkt); return ret; } - param = strtok_r(NULL, " ", &saveptr); + if (sep) + param = sep + 1; + else + break; } } From 8772997d102024b23fc820e3e5d9b96b4d309092 Mon Sep 17 00:00:00 2001 From: Sean McGovern Date: Mon, 11 Jun 2012 18:22:31 -0400 Subject: [PATCH 06/19] jack: update to new latency range API as the old one has been deprecated Fixes Bugzilla #279. Signed-off-by: Diego Biurrun --- configure | 4 +++- libavdevice/jack_audio.c | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/configure b/configure index fbb71b6e16..5f9eed3cad 100755 --- a/configure +++ b/configure @@ -1087,6 +1087,7 @@ HAVE_LIST=" inet_aton inline_asm isatty + jack_port_get_latency_range ldbrx libdc1394_1 libdc1394_2 @@ -2982,7 +2983,8 @@ check_header soundcard.h enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound -enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack +enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && + check_func jack_port_get_latency_range -ljack enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio diff --git a/libavdevice/jack_audio.c b/libavdevice/jack_audio.c index 9f1bb23c3b..85f9f09740 100644 --- a/libavdevice/jack_audio.c +++ b/libavdevice/jack_audio.c @@ -91,7 +91,13 @@ static int process_callback(jack_nframes_t nframes, void *arg) /* Copy and interleave audio data from the JACK buffer into the packet */ for (i = 0; i < self->nports; i++) { + #if HAVE_JACK_PORT_GET_LATENCY_RANGE + jack_latency_range_t range; + jack_port_get_latency_range(self->ports[i], JackCaptureLatency, &range); + latency += range.max; + #else latency += jack_port_get_total_latency(self->client, self->ports[i]); + #endif buffer = jack_port_get_buffer(self->ports[i], self->buffer_size); for (j = 0; j < self->buffer_size; j++) pkt_data[j * self->nports + i] = buffer[j]; From 6d58358a3a3274e84a4e34a348165fbb3f484587 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 30 May 2012 10:31:48 +0200 Subject: [PATCH 07/19] lavfi: make avfilter_get_video_buffer() private on next bump. They are only useful inside filters and we don't allow user filters for now. --- libavfilter/avfilter.h | 14 +++----------- libavfilter/buffersrc.c | 4 ++-- libavfilter/vf_delogo.c | 4 ++-- libavfilter/vf_fieldorder.c | 2 +- libavfilter/vf_frei0r.c | 2 +- libavfilter/vf_gradfun.c | 2 +- libavfilter/vf_overlay.c | 2 +- libavfilter/vf_pad.c | 12 ++++++------ libavfilter/vf_pixdesctest.c | 4 ++-- libavfilter/vf_scale.c | 2 +- libavfilter/vf_transpose.c | 4 ++-- libavfilter/vf_vflip.c | 2 +- libavfilter/vf_yadif.c | 8 ++++---- libavfilter/video.c | 12 ++++++++---- libavfilter/video.h | 14 ++++++++++++++ libavfilter/vsrc_color.c | 2 +- libavfilter/vsrc_movie.c | 4 ++-- libavfilter/vsrc_testsrc.c | 3 +-- 18 files changed, 53 insertions(+), 44 deletions(-) diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index c592372ced..7fbc160cbe 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -573,19 +573,11 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, */ int avfilter_config_links(AVFilterContext *filter); -/** - * Request a picture buffer with a specific set of permissions. - * - * @param link the output link to the filter from which the buffer will - * be requested - * @param perms the required access permissions - * @param w the minimum width of the buffer to allocate - * @param h the minimum height of the buffer to allocate - * @return A reference to the buffer. This must be unreferenced with - * avfilter_unref_buffer when you are finished with it. - */ +#if FF_API_FILTERS_PUBLIC +attribute_deprecated AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h); +#endif /** * Create a buffer reference wrapped around an already allocated image diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 7af9f6c571..3ffab60398 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -109,8 +109,8 @@ int av_buffersrc_write_frame(AVFilterContext *buffer_filter, AVFrame *frame) case AVMEDIA_TYPE_VIDEO: CHECK_VIDEO_PARAM_CHANGE(buffer_filter, c, frame->width, frame->height, frame->format); - buf = avfilter_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE, - c->w, c->h); + buf = ff_get_video_buffer(buffer_filter->outputs[0], AV_PERM_WRITE, + c->w, c->h); av_image_copy(buf->data, buf->linesize, frame->data, frame->linesize, c->pix_fmt, c->w, c->h); break; diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 6fe47306ea..70aa12a5d1 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -219,8 +219,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) AVFilterBufferRef *outpicref; if (inpicref->perms & AV_PERM_PRESERVE) { - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); + outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, + outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outpicref, inpicref); outpicref->video->w = outlink->w; outpicref->video->h = outlink->h; diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index ff1e332572..67a69587bf 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -112,7 +112,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; - return avfilter_get_video_buffer(outlink, perms, w, h); + return ff_get_video_buffer(outlink, perms, w, h); } static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index 85b4205559..2a72fcc6a0 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -432,7 +432,7 @@ static int source_config_props(AVFilterLink *outlink) static int source_request_frame(AVFilterLink *outlink) { Frei0rContext *frei0r = outlink->src->priv; - AVFilterBufferRef *picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + AVFilterBufferRef *picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); picref->video->pixel_aspect = (AVRational) {1, 1}; picref->pts = frei0r->pts++; picref->pos = -1; diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c index 7fde16d41b..88872b3e25 100644 --- a/libavfilter/vf_gradfun.c +++ b/libavfilter/vf_gradfun.c @@ -190,7 +190,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) AVFilterBufferRef *outpicref; if (inpicref->perms & AV_PERM_PRESERVE) { - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outpicref, inpicref); outpicref->video->w = outlink->w; outpicref->video->h = outlink->h; diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index 55f1cc3a14..ff7c348e52 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -205,7 +205,7 @@ static int config_output(AVFilterLink *outlink) static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h) { - return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); + return ff_get_video_buffer(link->dst->outputs[0], perms, w, h); } static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 2e98aea028..11c59b9f69 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -256,9 +256,9 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int { PadContext *pad = inlink->dst->priv; - AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0], perms, - w + (pad->w - pad->in_w), - h + (pad->h - pad->in_h)); + AVFilterBufferRef *picref = ff_get_video_buffer(inlink->dst->outputs[0], perms, + w + (pad->w - pad->in_w), + h + (pad->h - pad->in_h)); int plane; picref->video->w = w; @@ -327,9 +327,9 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) if(pad->needs_copy){ av_log(inlink->dst, AV_LOG_DEBUG, "Direct padding impossible allocating new frame\n"); avfilter_unref_buffer(outpicref); - outpicref = avfilter_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES, - FFMAX(inlink->w, pad->w), - FFMAX(inlink->h, pad->h)); + outpicref = ff_get_video_buffer(inlink->dst->outputs[0], AV_PERM_WRITE | AV_PERM_NEG_LINESIZES, + FFMAX(inlink->w, pad->w), + FFMAX(inlink->h, pad->h)); avfilter_copy_buffer_ref_props(outpicref, inpicref); } diff --git a/libavfilter/vf_pixdesctest.c b/libavfilter/vf_pixdesctest.c index 7eecdc0bb1..353c57b8a6 100644 --- a/libavfilter/vf_pixdesctest.c +++ b/libavfilter/vf_pixdesctest.c @@ -57,8 +57,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) AVFilterBufferRef *outpicref; int i; - outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); + outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, + outlink->w, outlink->h); outpicref = outlink->out_buf; avfilter_copy_buffer_ref_props(outpicref, picref); diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 6f33848f20..68ff84532d 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -265,7 +265,7 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w; scale->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h; - outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + outpicref = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outpicref, picref); outpicref->video->w = outlink->w; outpicref->video->h = outlink->h; diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index 5e5feda85f..aa5c0156a3 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -120,8 +120,8 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { AVFilterLink *outlink = inlink->dst->outputs[0]; - outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - outlink->w, outlink->h); + outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, + outlink->w, outlink->h); outlink->out_buf->pts = picref->pts; if (picref->video->pixel_aspect.num == 0) { diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c index 6d2f42ed5d..bece2b26ac 100644 --- a/libavfilter/vf_vflip.c +++ b/libavfilter/vf_vflip.c @@ -50,7 +50,7 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, if (!(perms & AV_PERM_NEG_LINESIZES)) return ff_default_get_video_buffer(link, perms, w, h); - picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); + picref = ff_get_video_buffer(link->dst->outputs[0], perms, w, h); for (i = 0; i < 4; i ++) { int vsub = i == 1 || i == 2 ? flip->vsub : 0; diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index b498ab9d39..baf8b7aca4 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -208,8 +208,8 @@ static void return_frame(AVFilterContext *ctx, int is_second) } if (is_second) { - yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE, link->w, link->h); + yadif->out = ff_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | + AV_PERM_REUSE, link->w, link->h); avfilter_copy_buffer_ref_props(yadif->out, yadif->cur); yadif->out->video->interlaced = 0; } @@ -268,8 +268,8 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) if (!yadif->prev) yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ); - yadif->out = avfilter_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE, link->w, link->h); + yadif->out = ff_get_video_buffer(ctx->outputs[0], AV_PERM_WRITE | AV_PERM_PRESERVE | + AV_PERM_REUSE, link->w, link->h); avfilter_copy_buffer_ref_props(yadif->out, yadif->cur); yadif->out->video->interlaced = 0; diff --git a/libavfilter/video.c b/libavfilter/video.c index 33082a1482..0e10bb7dad 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -67,7 +67,7 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end) AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h) { - return avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); + return ff_get_video_buffer(link->dst->outputs[0], perms, w, h); } /* TODO: set the buffer's priv member to a context structure for the whole @@ -138,7 +138,7 @@ fail: return NULL; } -AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h) +AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, int w, int h) { AVFilterBufferRef *ret = NULL; @@ -173,7 +173,7 @@ static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) outlink = inlink->dst->outputs[0]; if (outlink) { - outlink->out_buf = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); + outlink->out_buf = ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); avfilter_copy_buffer_ref_props(outlink->out_buf, picref); ff_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0)); } @@ -201,7 +201,7 @@ void ff_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) picref->perms, link->dstpad->min_perms, link->dstpad->rej_perms); - link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h); + link->cur_buf = ff_get_video_buffer(link, dst->min_perms, link->w, link->h); link->src_buf = picref; avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf); } @@ -354,4 +354,8 @@ void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { ff_draw_slice(link, y, h, slice_dir); } +AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h) +{ + return ff_get_video_buffer(link, perms, w, h); +} #endif diff --git a/libavfilter/video.h b/libavfilter/video.h index 7c9f9a0d28..ce4e9c2992 100644 --- a/libavfilter/video.h +++ b/libavfilter/video.h @@ -25,6 +25,20 @@ AVFilterBufferRef *ff_default_get_video_buffer(AVFilterLink *link, int perms, int w, int h); AVFilterBufferRef *ff_null_get_video_buffer(AVFilterLink *link, int perms, int w, int h); +/** + * Request a picture buffer with a specific set of permissions. + * + * @param link the output link to the filter from which the buffer will + * be requested + * @param perms the required access permissions + * @param w the minimum width of the buffer to allocate + * @param h the minimum height of the buffer to allocate + * @return A reference to the buffer. This must be unreferenced with + * avfilter_unref_buffer when you are finished with it. + */ +AVFilterBufferRef *ff_get_video_buffer(AVFilterLink *link, int perms, + int w, int h); + void ff_null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref); void ff_null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir); void ff_null_end_frame(AVFilterLink *link); diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c index 99ea0ad5c1..bfd8493761 100644 --- a/libavfilter/vsrc_color.c +++ b/libavfilter/vsrc_color.c @@ -140,7 +140,7 @@ static int color_config_props(AVFilterLink *inlink) static int color_request_frame(AVFilterLink *link) { ColorContext *color = link->src->priv; - AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); + AVFilterBufferRef *picref = ff_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); picref->video->pixel_aspect = (AVRational) {1, 1}; picref->pts = color->pts++; picref->pos = -1; diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index ff3022cdd6..f887e95c86 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -237,8 +237,8 @@ static int movie_get_frame(AVFilterLink *outlink) if (frame_decoded) { /* FIXME: avoid the memcpy */ - movie->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE | - AV_PERM_REUSE2, outlink->w, outlink->h); + movie->picref = ff_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE | + AV_PERM_REUSE2, outlink->w, outlink->h); av_image_copy(movie->picref->data, movie->picref->linesize, movie->frame->data, movie->frame->linesize, movie->picref->format, outlink->w, outlink->h); diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index 7187241136..a6159ef6e1 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -132,8 +132,7 @@ static int request_frame(AVFilterLink *outlink) if (test->max_pts >= 0 && test->pts > test->max_pts) return AVERROR_EOF; - picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, - test->w, test->h); + picref = ff_get_video_buffer(outlink, AV_PERM_WRITE, test->w, test->h); picref->pts = test->pts++; picref->pos = -1; picref->video->key_frame = 1; From 84b9fbe05578c8b4058e72bb0b203665a446a95a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jun 2012 19:57:57 +0200 Subject: [PATCH 08/19] lavfi: add avfilter_pad_get_type() and avfilter_pad_get_name(). This will allow making AVFilterPad opaque for the calling apps, since those are the only two fields that can be useful to the users. --- doc/APIchanges | 5 +++++ libavfilter/avfilter.c | 10 ++++++++++ libavfilter/avfilter.h | 22 ++++++++++++++++++++++ libavfilter/version.h | 2 +- 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index 729bddc853..e0fec3c692 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,11 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-xx-xx - xxxxxxx - lavfi 2.22.0 - avfilter.h + Add avfilter_pad_get_type() and avfilter_pad_get_name(). Those + should now be used instead of accessing AVFilterPad members + directly. + 2012-xx-xx - xxxxxxx - lavu 51.32.0 - audioconvert.h Add av_get_channel_layout_channel_index(), av_get_channel_name() and av_channel_layout_extract_channel(). diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 9b62be33ca..0507b2acbd 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -429,6 +429,16 @@ int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque return ret; } +const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx) +{ + return pads[pad_idx].name; +} + +enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx) +{ + return pads[pad_idx].type; +} + #if FF_API_DEFAULT_CONFIG_OUTPUT_LINK int avfilter_default_config_output_link(AVFilterLink *link) { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7fbc160cbe..7ee18fbce6 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -359,6 +359,28 @@ struct AVFilterPad { int (*config_props)(AVFilterLink *link); }; +/** + * Get the name of an AVFilterPad. + * + * @param pads an array of AVFilterPads + * @param pad_idx index of the pad in the array it; is the caller's + * responsibility to ensure the index is valid + * + * @return name of the pad_idx'th pad in pads + */ +const char *avfilter_pad_get_name(AVFilterPad *pads, int pad_idx); + +/** + * Get the type of an AVFilterPad. + * + * @param pads an array of AVFilterPads + * @param pad_idx index of the pad in the array; it is the caller's + * responsibility to ensure the index is valid + * + * @return type of the pad_idx'th pad in pads + */ +enum AVMediaType avfilter_pad_get_type(AVFilterPad *pads, int pad_idx); + #if FF_API_FILTERS_PUBLIC /** default handler for start_frame() for video inputs */ attribute_deprecated diff --git a/libavfilter/version.h b/libavfilter/version.h index 09cf4c69e5..d8baf0eaa9 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -29,7 +29,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 21 +#define LIBAVFILTER_VERSION_MINOR 22 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ From 9d0bfc5052fa73ac8df89ec9992d77b07840fdf0 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jun 2012 20:12:42 +0200 Subject: [PATCH 09/19] lavfi: make AVFilterPad opaque after two major bumps. It will allow adding new fields to it without ABI breaks. --- avconv.c | 14 ++-- libavfilter/af_anull.c | 1 + libavfilter/asink_anullsink.c | 1 + libavfilter/asrc_anullsrc.c | 1 + libavfilter/avfilter.h | 7 ++ libavfilter/buffersrc.c | 1 + libavfilter/internal.h | 126 ++++++++++++++++++++++++++++++++++ libavfilter/version.h | 3 + libavfilter/vf_aspect.c | 1 + libavfilter/vf_blackframe.c | 1 + libavfilter/vf_boxblur.c | 1 + libavfilter/vf_copy.c | 1 + libavfilter/vf_crop.c | 1 + libavfilter/vf_cropdetect.c | 1 + libavfilter/vf_delogo.c | 1 + libavfilter/vf_drawbox.c | 1 + libavfilter/vf_drawtext.c | 1 + libavfilter/vf_fade.c | 1 + libavfilter/vf_fieldorder.c | 1 + libavfilter/vf_format.c | 1 + libavfilter/vf_frei0r.c | 1 + libavfilter/vf_gradfun.c | 1 + libavfilter/vf_hflip.c | 1 + libavfilter/vf_hqdn3d.c | 1 + libavfilter/vf_null.c | 1 + libavfilter/vf_pad.c | 1 + libavfilter/vf_pixdesctest.c | 1 + libavfilter/vf_scale.c | 1 + libavfilter/vf_setpts.c | 1 + libavfilter/vf_showinfo.c | 1 + libavfilter/vf_slicify.c | 1 + libavfilter/vf_transpose.c | 1 + libavfilter/vf_unsharp.c | 1 + libavfilter/vf_vflip.c | 1 + libavfilter/vsink_nullsink.c | 1 + libavfilter/vsrc_color.c | 1 + libavfilter/vsrc_movie.c | 1 + libavfilter/vsrc_nullsrc.c | 1 + libavfilter/vsrc_testsrc.c | 1 + 39 files changed, 179 insertions(+), 6 deletions(-) diff --git a/avconv.c b/avconv.c index 293f839ee5..2ed590d086 100644 --- a/avconv.c +++ b/avconv.c @@ -548,7 +548,7 @@ static FilterGraph *init_simple_filtergraph(InputStream *ist, OutputStream *ost) static void init_input_filter(FilterGraph *fg, AVFilterInOut *in) { InputStream *ist; - enum AVMediaType type = in->filter_ctx->input_pads[in->pad_idx].type; + enum AVMediaType type = avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx); int i; // TODO: support other filter types @@ -789,7 +789,7 @@ static int configure_output_audio_filter(FilterGraph *fg, OutputFilter *ofilter, \ avio_printf(pb, "%s", ctx->filter->name); \ if (nb_pads > 1) \ - avio_printf(pb, ":%s", pads[inout->pad_idx].name); \ + avio_printf(pb, ":%s", avfilter_pad_get_name(pads, inout->pad_idx));\ avio_w8(pb, 0); \ avio_close_dyn_buf(pb, &f->name); \ } @@ -799,7 +799,7 @@ static int configure_output_filter(FilterGraph *fg, OutputFilter *ofilter, AVFil av_freep(&ofilter->name); DESCRIBE_FILTER_LINK(ofilter, out, 0); - switch (out->filter_ctx->output_pads[out->pad_idx].type) { + switch (avfilter_pad_get_type(out->filter_ctx->output_pads, out->pad_idx)) { case AVMEDIA_TYPE_VIDEO: return configure_output_video_filter(fg, ofilter, out); case AVMEDIA_TYPE_AUDIO: return configure_output_audio_filter(fg, ofilter, out); default: av_assert0(0); @@ -913,7 +913,7 @@ static int configure_input_filter(FilterGraph *fg, InputFilter *ifilter, av_freep(&ifilter->name); DESCRIBE_FILTER_LINK(ifilter, in, 1); - switch (in->filter_ctx->input_pads[in->pad_idx].type) { + switch (avfilter_pad_get_type(in->filter_ctx->input_pads, in->pad_idx)) { case AVMEDIA_TYPE_VIDEO: return configure_input_video_filter(fg, ifilter, in); case AVMEDIA_TYPE_AUDIO: return configure_input_audio_filter(fg, ifilter, in); default: av_assert0(0); @@ -4112,7 +4112,8 @@ static void init_output_filter(OutputFilter *ofilter, OptionsContext *o, { OutputStream *ost; - switch (ofilter->out_tmp->filter_ctx->output_pads[ofilter->out_tmp->pad_idx].type) { + switch (avfilter_pad_get_type(ofilter->out_tmp->filter_ctx->output_pads, + ofilter->out_tmp->pad_idx)) { case AVMEDIA_TYPE_VIDEO: ost = new_video_stream(o, oc); break; case AVMEDIA_TYPE_AUDIO: ost = new_audio_stream(o, oc); break; default: @@ -4191,7 +4192,8 @@ static void opt_output_file(void *optctx, const char *filename) if (!ofilter->out_tmp || ofilter->out_tmp->name) continue; - switch (ofilter->out_tmp->filter_ctx->output_pads[ofilter->out_tmp->pad_idx].type) { + switch (avfilter_pad_get_type(ofilter->out_tmp->filter_ctx->output_pads, + ofilter->out_tmp->pad_idx)) { case AVMEDIA_TYPE_VIDEO: o->video_disable = 1; break; case AVMEDIA_TYPE_AUDIO: o->audio_disable = 1; break; case AVMEDIA_TYPE_SUBTITLE: o->subtitle_disable = 1; break; diff --git a/libavfilter/af_anull.c b/libavfilter/af_anull.c index 59b275c767..294586e1f3 100644 --- a/libavfilter/af_anull.c +++ b/libavfilter/af_anull.c @@ -23,6 +23,7 @@ #include "audio.h" #include "avfilter.h" +#include "internal.h" AVFilter avfilter_af_anull = { .name = "anull", diff --git a/libavfilter/asink_anullsink.c b/libavfilter/asink_anullsink.c index 3a505e79f2..b527850d4a 100644 --- a/libavfilter/asink_anullsink.c +++ b/libavfilter/asink_anullsink.c @@ -17,6 +17,7 @@ */ #include "avfilter.h" +#include "internal.h" static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { } diff --git a/libavfilter/asrc_anullsrc.c b/libavfilter/asrc_anullsrc.c index 8e99012faf..6f1c1e78a4 100644 --- a/libavfilter/asrc_anullsrc.c +++ b/libavfilter/asrc_anullsrc.c @@ -22,6 +22,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "libavutil/audioconvert.h" typedef struct { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7ee18fbce6..157e72fe2a 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -235,8 +235,14 @@ void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) */ #endif +#if FF_API_AVFILTERPAD_PUBLIC /** * A filter pad used for either input or output. + * + * @warning this struct will be removed from public API. + * users should call avfilter_pad_get_name() and avfilter_pad_get_type() + * to access the name and type fields; there should be no need to access + * any other fields from outside of libavfilter. */ struct AVFilterPad { /** @@ -358,6 +364,7 @@ struct AVFilterPad { */ int (*config_props)(AVFilterLink *link); }; +#endif /** * Get the name of an AVFilterPad. diff --git a/libavfilter/buffersrc.c b/libavfilter/buffersrc.c index 3ffab60398..ad9f45bd5d 100644 --- a/libavfilter/buffersrc.c +++ b/libavfilter/buffersrc.c @@ -27,6 +27,7 @@ #include "avfilter.h" #include "buffersrc.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "vsrc_buffer.h" diff --git a/libavfilter/internal.h b/libavfilter/internal.h index 4b53831063..f6dc74b082 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -26,6 +26,132 @@ #include "avfilter.h" +#if !FF_API_AVFILTERPAD_PUBLIC +/** + * A filter pad used for either input or output. + */ +struct AVFilterPad { + /** + * Pad name. The name is unique among inputs and among outputs, but an + * input may have the same name as an output. This may be NULL if this + * pad has no need to ever be referenced by name. + */ + const char *name; + + /** + * AVFilterPad type. + */ + enum AVMediaType type; + + /** + * Minimum required permissions on incoming buffers. Any buffer with + * insufficient permissions will be automatically copied by the filter + * system to a new buffer which provides the needed access permissions. + * + * Input pads only. + */ + int min_perms; + + /** + * Permissions which are not accepted on incoming buffers. Any buffer + * which has any of these permissions set will be automatically copied + * by the filter system to a new buffer which does not have those + * permissions. This can be used to easily disallow buffers with + * AV_PERM_REUSE. + * + * Input pads only. + */ + int rej_perms; + + /** + * Callback called before passing the first slice of a new frame. If + * NULL, the filter layer will default to storing a reference to the + * picture inside the link structure. + * + * Input video pads only. + */ + void (*start_frame)(AVFilterLink *link, AVFilterBufferRef *picref); + + /** + * Callback function to get a video buffer. If NULL, the filter system will + * use avfilter_default_get_video_buffer(). + * + * Input video pads only. + */ + AVFilterBufferRef *(*get_video_buffer)(AVFilterLink *link, int perms, int w, int h); + + /** + * Callback function to get an audio buffer. If NULL, the filter system will + * use avfilter_default_get_audio_buffer(). + * + * Input audio pads only. + */ + AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, + int nb_samples); + + /** + * Callback called after the slices of a frame are completely sent. If + * NULL, the filter layer will default to releasing the reference stored + * in the link structure during start_frame(). + * + * Input video pads only. + */ + void (*end_frame)(AVFilterLink *link); + + /** + * Slice drawing callback. This is where a filter receives video data + * and should do its processing. + * + * Input video pads only. + */ + void (*draw_slice)(AVFilterLink *link, int y, int height, int slice_dir); + + /** + * Samples filtering callback. This is where a filter receives audio data + * and should do its processing. + * + * Input audio pads only. + */ + void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref); + + /** + * Frame poll callback. This returns the number of immediately available + * samples. It should return a positive value if the next request_frame() + * is guaranteed to return one frame (with no delay). + * + * Defaults to just calling the source poll_frame() method. + * + * Output pads only. + */ + int (*poll_frame)(AVFilterLink *link); + + /** + * Frame request callback. A call to this should result in at least one + * frame being output over the given link. This should return zero on + * success, and another value on error. + * + * Output pads only. + */ + int (*request_frame)(AVFilterLink *link); + + /** + * Link configuration callback. + * + * For output pads, this should set the link properties such as + * width/height. This should NOT set the format property - that is + * negotiated between filters by the filter system using the + * query_formats() callback before this function is called. + * + * For input pads, this should check the properties of the link, and update + * the filter's internal state as necessary. + * + * For both input and output filters, this should return zero on success, + * and another value on error. + */ + int (*config_props)(AVFilterLink *link); +}; +#endif + /** default handler for freeing audio/video buffer when there are no references left */ void ff_avfilter_default_free_buffer(AVFilterBuffer *buf); diff --git a/libavfilter/version.h b/libavfilter/version.h index d8baf0eaa9..76fe1664a7 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -59,5 +59,8 @@ #ifndef FF_API_FILTERS_PUBLIC #define FF_API_FILTERS_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 3) #endif +#ifndef FF_API_AVFILTERPAD_PUBLIC +#define FF_API_AVFILTERPAD_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 4) +#endif #endif // AVFILTER_VERSION_H diff --git a/libavfilter/vf_aspect.c b/libavfilter/vf_aspect.c index 0555afe4c0..44bef91fbc 100644 --- a/libavfilter/vf_aspect.c +++ b/libavfilter/vf_aspect.c @@ -25,6 +25,7 @@ #include "libavutil/mathematics.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_blackframe.c b/libavfilter/vf_blackframe.c index 1d9a75d502..a1f97328d0 100644 --- a/libavfilter/vf_blackframe.c +++ b/libavfilter/vf_blackframe.c @@ -29,6 +29,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_boxblur.c b/libavfilter/vf_boxblur.c index 21a0173ccb..06917ecf07 100644 --- a/libavfilter/vf_boxblur.c +++ b/libavfilter/vf_boxblur.c @@ -30,6 +30,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" static const char *const var_names[] = { diff --git a/libavfilter/vf_copy.c b/libavfilter/vf_copy.c index 271a729211..9ceb2f8a42 100644 --- a/libavfilter/vf_copy.c +++ b/libavfilter/vf_copy.c @@ -22,6 +22,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "video.h" AVFilter avfilter_vf_copy = { diff --git a/libavfilter/vf_crop.c b/libavfilter/vf_crop.c index f25278e79e..c884ce1f2a 100644 --- a/libavfilter/vf_crop.c +++ b/libavfilter/vf_crop.c @@ -27,6 +27,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/eval.h" #include "libavutil/avstring.h" diff --git a/libavfilter/vf_cropdetect.c b/libavfilter/vf_cropdetect.c index 38fd5c1355..c890dab5b9 100644 --- a/libavfilter/vf_cropdetect.c +++ b/libavfilter/vf_cropdetect.c @@ -26,6 +26,7 @@ #include "libavutil/imgutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_delogo.c b/libavfilter/vf_delogo.c index 70aa12a5d1..77382c99b5 100644 --- a/libavfilter/vf_delogo.c +++ b/libavfilter/vf_delogo.c @@ -30,6 +30,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" /** diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index 47db0490a7..eb129a23d8 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -29,6 +29,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" enum { Y, U, V, A }; diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index 411bcbc781..db66ad618d 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -42,6 +42,7 @@ #include "avfilter.h" #include "drawutils.h" #include "formats.h" +#include "internal.h" #include "video.h" #undef time diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 6b9cb66fe6..00501dd53c 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -28,6 +28,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c index 67a69587bf..89218560c6 100644 --- a/libavfilter/vf_fieldorder.c +++ b/libavfilter/vf_fieldorder.c @@ -29,6 +29,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct diff --git a/libavfilter/vf_format.c b/libavfilter/vf_format.c index fff616b06a..1a50118519 100644 --- a/libavfilter/vf_format.c +++ b/libavfilter/vf_format.c @@ -26,6 +26,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index 2a72fcc6a0..54881571af 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -32,6 +32,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height); diff --git a/libavfilter/vf_gradfun.c b/libavfilter/vf_gradfun.c index 88872b3e25..303e54c7f9 100644 --- a/libavfilter/vf_gradfun.c +++ b/libavfilter/vf_gradfun.c @@ -38,6 +38,7 @@ #include "avfilter.h" #include "formats.h" #include "gradfun.h" +#include "internal.h" #include "video.h" DECLARE_ALIGNED(16, static const uint16_t, dither)[8][8] = { diff --git a/libavfilter/vf_hflip.c b/libavfilter/vf_hflip.c index aff0f8c5d3..af167e142d 100644 --- a/libavfilter/vf_hflip.c +++ b/libavfilter/vf_hflip.c @@ -26,6 +26,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" #include "libavutil/intreadwrite.h" diff --git a/libavfilter/vf_hqdn3d.c b/libavfilter/vf_hqdn3d.c index 0a26dd0017..f9b864e9ea 100644 --- a/libavfilter/vf_hqdn3d.c +++ b/libavfilter/vf_hqdn3d.c @@ -28,6 +28,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_null.c b/libavfilter/vf_null.c index 470c3d28a5..26545dc843 100644 --- a/libavfilter/vf_null.c +++ b/libavfilter/vf_null.c @@ -22,6 +22,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "video.h" AVFilter avfilter_vf_null = { diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 11c59b9f69..098fc806c8 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -26,6 +26,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/avstring.h" #include "libavutil/eval.h" diff --git a/libavfilter/vf_pixdesctest.c b/libavfilter/vf_pixdesctest.c index 353c57b8a6..37dbe2d08a 100644 --- a/libavfilter/vf_pixdesctest.c +++ b/libavfilter/vf_pixdesctest.c @@ -25,6 +25,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index 68ff84532d..58daf38376 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -25,6 +25,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/avstring.h" #include "libavutil/eval.h" diff --git a/libavfilter/vf_setpts.c b/libavfilter/vf_setpts.c index d303851686..77eef60679 100644 --- a/libavfilter/vf_setpts.c +++ b/libavfilter/vf_setpts.c @@ -29,6 +29,7 @@ #include "libavutil/eval.h" #include "libavutil/mathematics.h" #include "avfilter.h" +#include "internal.h" #include "video.h" static const char *const var_names[] = { diff --git a/libavfilter/vf_showinfo.c b/libavfilter/vf_showinfo.c index 1a8f16e2c3..dbb67e91a2 100644 --- a/libavfilter/vf_showinfo.c +++ b/libavfilter/vf_showinfo.c @@ -26,6 +26,7 @@ #include "libavutil/imgutils.h" #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_slicify.c b/libavfilter/vf_slicify.c index fdc10bea9d..636912dbdc 100644 --- a/libavfilter/vf_slicify.c +++ b/libavfilter/vf_slicify.c @@ -24,6 +24,7 @@ */ #include "avfilter.h" +#include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" diff --git a/libavfilter/vf_transpose.c b/libavfilter/vf_transpose.c index aa5c0156a3..5bcee9d32e 100644 --- a/libavfilter/vf_transpose.c +++ b/libavfilter/vf_transpose.c @@ -30,6 +30,7 @@ #include "libavutil/imgutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vf_unsharp.c b/libavfilter/vf_unsharp.c index a5d301cd72..8010f2dc17 100644 --- a/libavfilter/vf_unsharp.c +++ b/libavfilter/vf_unsharp.c @@ -38,6 +38,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/common.h" #include "libavutil/mem.h" diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c index bece2b26ac..0f528f137a 100644 --- a/libavfilter/vf_vflip.c +++ b/libavfilter/vf_vflip.c @@ -25,6 +25,7 @@ #include "libavutil/pixdesc.h" #include "avfilter.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vsink_nullsink.c b/libavfilter/vsink_nullsink.c index bdfcb8a2e4..6f11158c3a 100644 --- a/libavfilter/vsink_nullsink.c +++ b/libavfilter/vsink_nullsink.c @@ -17,6 +17,7 @@ */ #include "avfilter.h" +#include "internal.h" static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { diff --git a/libavfilter/vsrc_color.c b/libavfilter/vsrc_color.c index bfd8493761..de1f340b01 100644 --- a/libavfilter/vsrc_color.c +++ b/libavfilter/vsrc_color.c @@ -25,6 +25,7 @@ #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" #include "libavutil/pixdesc.h" #include "libavutil/colorspace.h" diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index f887e95c86..64f6e18301 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -37,6 +37,7 @@ #include "libavformat/avformat.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { diff --git a/libavfilter/vsrc_nullsrc.c b/libavfilter/vsrc_nullsrc.c index d145b0b277..71094dc95b 100644 --- a/libavfilter/vsrc_nullsrc.c +++ b/libavfilter/vsrc_nullsrc.c @@ -27,6 +27,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" static const char *const var_names[] = { "E", diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index a6159ef6e1..36f18b6213 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -38,6 +38,7 @@ #include "libavutil/parseutils.h" #include "avfilter.h" #include "formats.h" +#include "internal.h" #include "video.h" typedef struct { From 9baeff9506a890c8f9f27c08cf331f827c24726a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Jun 2012 21:25:10 +0200 Subject: [PATCH 10/19] lavfi: replace AVFilterContext.input/output_count with nb_inputs/outputs This is more consistent with naming in the rest of Libav. --- doc/APIchanges | 4 +++ libavfilter/af_amix.c | 6 ++-- libavfilter/af_channelsplit.c | 4 +-- libavfilter/audio.c | 2 +- libavfilter/avfilter.c | 58 ++++++++++++++++++++--------------- libavfilter/avfilter.h | 11 +++++-- libavfilter/avfiltergraph.c | 34 ++++++++++---------- libavfilter/formats.c | 4 +-- libavfilter/graphparser.c | 4 +-- libavfilter/internal.h | 10 ++++-- libavfilter/split.c | 10 +++--- libavfilter/version.h | 5 ++- libavfilter/video.c | 6 ++-- 13 files changed, 94 insertions(+), 64 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index e0fec3c692..50cc787bad 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,10 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-xx-xx - xxxxxxx - lavfi 2.23.0 - avfilter.h + Add AVFilterContext.nb_inputs/outputs. Deprecate + AVFilterContext.input/output_count. + 2012-xx-xx - xxxxxxx - lavfi 2.22.0 - avfilter.h Add avfilter_pad_get_type() and avfilter_pad_get_name(). Those should now be used instead of accessing AVFilterPad members diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index 3fc2e8499a..003a8e8e62 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -454,10 +454,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) AVFilterLink *outlink = ctx->outputs[0]; int i; - for (i = 0; i < ctx->input_count; i++) + for (i = 0; i < ctx->nb_inputs; i++) if (ctx->inputs[i] == inlink) break; - if (i >= ctx->input_count) { + if (i >= ctx->nb_inputs) { av_log(ctx, AV_LOG_ERROR, "unknown input link\n"); return; } @@ -518,7 +518,7 @@ static void uninit(AVFilterContext *ctx) av_freep(&s->input_state); av_freep(&s->input_scale); - for (i = 0; i < ctx->input_count; i++) + for (i = 0; i < ctx->nb_inputs; i++) av_freep(&ctx->input_pads[i].name); } diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c index c3e7ccfc69..c9b31fa791 100644 --- a/libavfilter/af_channelsplit.c +++ b/libavfilter/af_channelsplit.c @@ -99,7 +99,7 @@ static int query_formats(AVFilterContext *ctx) ff_add_channel_layout(&in_layouts, s->channel_layout); ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts); - for (i = 0; i < ctx->output_count; i++) { + for (i = 0; i < ctx->nb_outputs; i++) { AVFilterChannelLayouts *out_layouts = NULL; uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); @@ -115,7 +115,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) { + for (i = 0; i < ctx->nb_outputs; i++) { AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE); if (!buf_out) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 81a042b6bc..31839bb34b 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -156,7 +156,7 @@ void ff_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesr { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; if (outlink) { diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 0507b2acbd..bf76997aae 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -70,8 +70,8 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, { AVFilterLink *link; - if (src->output_count <= srcpad || dst->input_count <= dstpad || - src->outputs[srcpad] || dst->inputs[dstpad]) + if (src->nb_outputs <= srcpad || dst->nb_inputs <= dstpad || + src->outputs[srcpad] || dst->inputs[dstpad]) return -1; if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) { @@ -138,7 +138,7 @@ int avfilter_config_links(AVFilterContext *filter) unsigned i; int ret; - for (i = 0; i < filter->input_count; i ++) { + for (i = 0; i < filter->nb_inputs; i ++) { AVFilterLink *link = filter->inputs[i]; if (!link) continue; @@ -156,7 +156,7 @@ int avfilter_config_links(AVFilterContext *filter) return ret; if (!(config_link = link->srcpad->config_props)) { - if (link->src->input_count != 1) { + if (link->src->nb_inputs != 1) { av_log(link->src, AV_LOG_ERROR, "Source filters and filters " "with more than one input " "must set config_props() " @@ -171,15 +171,15 @@ int avfilter_config_links(AVFilterContext *filter) } if (link->time_base.num == 0 && link->time_base.den == 0) - link->time_base = link->src && link->src->input_count ? + link->time_base = link->src && link->src->nb_inputs ? link->src->inputs[0]->time_base : AV_TIME_BASE_Q; if (link->type == AVMEDIA_TYPE_VIDEO) { if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den) - link->sample_aspect_ratio = link->src->input_count ? + link->sample_aspect_ratio = link->src->nb_inputs ? link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1}; - if (link->src->input_count) { + if (link->src->nb_inputs) { if (!link->w) link->w = link->src->inputs[0]->w; if (!link->h) @@ -249,7 +249,7 @@ int ff_poll_frame(AVFilterLink *link) if (link->srcpad->poll_frame) return link->srcpad->poll_frame(link); - for (i = 0; i < link->src->input_count; i++) { + for (i = 0; i < link->src->nb_inputs; i++) { int val; if (!link->src->inputs[i]) return -1; @@ -339,27 +339,31 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in goto err; } - ret->input_count = pad_count(filter->inputs); - if (ret->input_count) { - ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count); + ret->nb_inputs = pad_count(filter->inputs); + if (ret->nb_inputs ) { + ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_inputs); if (!ret->input_pads) goto err; - memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count); - ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count); + memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->nb_inputs); + ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_inputs); if (!ret->inputs) goto err; } - ret->output_count = pad_count(filter->outputs); - if (ret->output_count) { - ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count); + ret->nb_outputs = pad_count(filter->outputs); + if (ret->nb_outputs) { + ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->nb_outputs); if (!ret->output_pads) goto err; - memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count); - ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count); + memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->nb_outputs); + ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->nb_outputs); if (!ret->outputs) goto err; } +#if FF_API_FOO_COUNT + ret->output_count = ret->nb_outputs; + ret->input_count = ret->nb_inputs; +#endif *filter_ctx = ret; return 0; @@ -367,10 +371,10 @@ int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *in err: av_freep(&ret->inputs); av_freep(&ret->input_pads); - ret->input_count = 0; + ret->nb_inputs = 0; av_freep(&ret->outputs); av_freep(&ret->output_pads); - ret->output_count = 0; + ret->nb_outputs = 0; av_freep(&ret->priv); av_free(ret); return AVERROR(ENOMEM); @@ -384,7 +388,7 @@ void avfilter_free(AVFilterContext *filter) if (filter->filter->uninit) filter->filter->uninit(filter); - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { if ((link = filter->inputs[i])) { if (link->src) link->src->outputs[link->srcpad - link->src->output_pads] = NULL; @@ -397,7 +401,7 @@ void avfilter_free(AVFilterContext *filter) } av_freep(&link); } - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { if ((link = filter->outputs[i])) { if (link->dst) link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL; @@ -453,14 +457,20 @@ void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, void avfilter_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad), + ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad), &f->input_pads, &f->inputs, p); +#if FF_API_FOO_COUNT + f->input_count = f->nb_inputs; +#endif } void avfilter_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad), + ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad), &f->output_pads, &f->outputs, p); +#if FF_API_FOO_COUNT + f->output_count = f->nb_outputs; +#endif } int avfilter_poll_frame(AVFilterLink *link) { diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 157e72fe2a..aff662f8f6 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -488,15 +488,22 @@ struct AVFilterContext { char *name; ///< name of this filter instance - unsigned input_count; ///< number of input pads +#if FF_API_FOO_COUNT + unsigned input_count; ///< @deprecated use nb_inputs +#endif AVFilterPad *input_pads; ///< array of input pads AVFilterLink **inputs; ///< array of pointers to input links - unsigned output_count; ///< number of output pads +#if FF_API_FOO_COUNT + unsigned output_count; ///< @deprecated use nb_outputs +#endif AVFilterPad *output_pads; ///< array of output pads AVFilterLink **outputs; ///< array of pointers to output links void *priv; ///< private data for use by the filter + + unsigned nb_inputs; ///< number of input pads + unsigned nb_outputs; ///< number of output pads }; /** diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 42bf1f7547..4521f790f7 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -109,7 +109,7 @@ static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx) for (i = 0; i < graph->filter_count; i++) { filt = graph->filters[i]; - for (j = 0; j < filt->input_count; j++) { + for (j = 0; j < filt->nb_inputs; j++) { if (!filt->inputs[j] || !filt->inputs[j]->src) { av_log(log_ctx, AV_LOG_ERROR, "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n", @@ -118,7 +118,7 @@ static int graph_check_validity(AVFilterGraph *graph, AVClass *log_ctx) } } - for (j = 0; j < filt->output_count; j++) { + for (j = 0; j < filt->nb_outputs; j++) { if (!filt->outputs[j] || !filt->outputs[j]->dst) { av_log(log_ctx, AV_LOG_ERROR, "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n", @@ -144,7 +144,7 @@ static int graph_config_links(AVFilterGraph *graph, AVClass *log_ctx) for (i=0; i < graph->filter_count; i++) { filt = graph->filters[i]; - if (!filt->output_count) { + if (!filt->nb_outputs) { if ((ret = avfilter_config_links(filt))) return ret; } @@ -181,7 +181,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) for (i = 0; i < graph->filter_count; i++) { AVFilterContext *filter = graph->filters[i]; - for (j = 0; j < filter->input_count; j++) { + for (j = 0; j < filter->nb_inputs; j++) { AVFilterLink *link = filter->inputs[j]; int convert_needed = 0; @@ -315,7 +315,7 @@ static int pick_format(AVFilterLink *link) #define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \ do { \ - for (i = 0; i < filter->input_count; i++) { \ + for (i = 0; i < filter->nb_inputs; i++) { \ AVFilterLink *link = filter->inputs[i]; \ fmt_type fmt; \ \ @@ -323,7 +323,7 @@ do { \ continue; \ fmt = link->out_ ## list->var[0]; \ \ - for (j = 0; j < filter->output_count; j++) { \ + for (j = 0; j < filter->nb_outputs; j++) { \ AVFilterLink *out_link = filter->outputs[j]; \ list_type *fmts; \ \ @@ -380,19 +380,19 @@ static void swap_samplerates_on_filter(AVFilterContext *filter) int sample_rate; int i, j; - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_samplerates->format_count == 1) break; } - if (i == filter->input_count) + if (i == filter->nb_inputs) return; sample_rate = link->out_samplerates->formats[0]; - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_diff = INT_MAX; @@ -427,19 +427,19 @@ static void swap_channel_layouts_on_filter(AVFilterContext *filter) uint64_t chlayout; int i, j; - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_channel_layouts->nb_channel_layouts == 1) break; } - if (i == filter->input_count) + if (i == filter->nb_inputs) return; chlayout = link->out_channel_layouts->channel_layouts[0]; - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_score = INT_MIN; @@ -480,20 +480,20 @@ static void swap_sample_fmts_on_filter(AVFilterContext *filter) int format, bps; int i, j; - for (i = 0; i < filter->input_count; i++) { + for (i = 0; i < filter->nb_inputs; i++) { link = filter->inputs[i]; if (link->type == AVMEDIA_TYPE_AUDIO && link->out_formats->format_count == 1) break; } - if (i == filter->input_count) + if (i == filter->nb_inputs) return; format = link->out_formats->formats[0]; bps = av_get_bytes_per_sample(format); - for (i = 0; i < filter->output_count; i++) { + for (i = 0; i < filter->nb_outputs; i++) { AVFilterLink *outlink = filter->outputs[i]; int best_idx, best_score = INT_MIN; @@ -549,10 +549,10 @@ static int pick_formats(AVFilterGraph *graph) for (i = 0; i < graph->filter_count; i++) { AVFilterContext *filter = graph->filters[i]; - for (j = 0; j < filter->input_count; j++) + for (j = 0; j < filter->nb_inputs; j++) if ((ret = pick_format(filter->inputs[j])) < 0) return ret; - for (j = 0; j < filter->output_count; j++) + for (j = 0; j < filter->nb_outputs; j++) if ((ret = pick_format(filter->outputs[j])) < 0) return ret; } diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 1d58d95b8e..36af528c67 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -330,13 +330,13 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref) { \ int count = 0, i; \ \ - for (i = 0; i < ctx->input_count; i++) { \ + for (i = 0; i < ctx->nb_inputs; i++) { \ if (ctx->inputs[i]) { \ ref(fmts, &ctx->inputs[i]->out_fmts); \ count++; \ } \ } \ - for (i = 0; i < ctx->output_count; i++) { \ + for (i = 0; i < ctx->nb_outputs; i++) { \ if (ctx->outputs[i]) { \ ref(fmts, &ctx->outputs[i]->in_fmts); \ count++; \ diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index b3f295f933..5f77084020 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -226,7 +226,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx, { int pad, ret; - for (pad = 0; pad < filt_ctx->input_count; pad++) { + for (pad = 0; pad < filt_ctx->nb_inputs; pad++) { AVFilterInOut *p = *curr_inputs; if (p) { @@ -254,7 +254,7 @@ static int link_filter_inouts(AVFilterContext *filt_ctx, return AVERROR(EINVAL); } - pad = filt_ctx->output_count; + pad = filt_ctx->nb_outputs; while (pad--) { AVFilterInOut *currlinkn = av_mallocz(sizeof(AVFilterInOut)); if (!currlinkn) diff --git a/libavfilter/internal.h b/libavfilter/internal.h index f6dc74b082..01b8f664f8 100644 --- a/libavfilter/internal.h +++ b/libavfilter/internal.h @@ -183,16 +183,22 @@ void ff_insert_pad(unsigned idx, unsigned *count, size_t padidx_off, static inline void ff_insert_inpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->input_count, offsetof(AVFilterLink, dstpad), + ff_insert_pad(index, &f->nb_inputs, offsetof(AVFilterLink, dstpad), &f->input_pads, &f->inputs, p); +#if FF_API_FOO_COUNT + f->input_count = f->nb_inputs; +#endif } /** Insert a new output pad for the filter. */ static inline void ff_insert_outpad(AVFilterContext *f, unsigned index, AVFilterPad *p) { - ff_insert_pad(index, &f->output_count, offsetof(AVFilterLink, srcpad), + ff_insert_pad(index, &f->nb_outputs, offsetof(AVFilterLink, srcpad), &f->output_pads, &f->outputs, p); +#if FF_API_FOO_COUNT + f->output_count = f->nb_outputs; +#endif } /** diff --git a/libavfilter/split.c b/libavfilter/split.c index 95c1b9aa1f..b7d037804a 100644 --- a/libavfilter/split.c +++ b/libavfilter/split.c @@ -59,7 +59,7 @@ static void split_uninit(AVFilterContext *ctx) { int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) av_freep(&ctx->output_pads[i].name); } @@ -68,7 +68,7 @@ static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_start_frame(ctx->outputs[i], avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); } @@ -78,7 +78,7 @@ static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_draw_slice(ctx->outputs[i], y, h, slice_dir); } @@ -87,7 +87,7 @@ static void end_frame(AVFilterLink *inlink) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_end_frame(ctx->outputs[i]); avfilter_unref_buffer(inlink->cur_buf); @@ -115,7 +115,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) AVFilterContext *ctx = inlink->dst; int i; - for (i = 0; i < ctx->output_count; i++) + for (i = 0; i < ctx->nb_outputs; i++) ff_filter_samples(inlink->dst->outputs[i], avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE)); } diff --git a/libavfilter/version.h b/libavfilter/version.h index 76fe1664a7..562147b657 100644 --- a/libavfilter/version.h +++ b/libavfilter/version.h @@ -29,7 +29,7 @@ #include "libavutil/avutil.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 22 +#define LIBAVFILTER_VERSION_MINOR 23 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ @@ -62,5 +62,8 @@ #ifndef FF_API_AVFILTERPAD_PUBLIC #define FF_API_AVFILTERPAD_PUBLIC (LIBAVFILTER_VERSION_MAJOR < 4) #endif +#ifndef FF_API_FOO_COUNT +#define FF_API_FOO_COUNT (LIBAVFILTER_VERSION_MAJOR < 4) +#endif #endif // AVFILTER_VERSION_H diff --git a/libavfilter/video.c b/libavfilter/video.c index 0e10bb7dad..a00f8c1cb2 100644 --- a/libavfilter/video.c +++ b/libavfilter/video.c @@ -169,7 +169,7 @@ static void default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; if (outlink) { @@ -220,7 +220,7 @@ static void default_end_frame(AVFilterLink *inlink) { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; avfilter_unref_buffer(inlink->cur_buf); @@ -261,7 +261,7 @@ static void default_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir { AVFilterLink *outlink = NULL; - if (inlink->dst->output_count) + if (inlink->dst->nb_outputs) outlink = inlink->dst->outputs[0]; if (outlink) From a48802836261082be8fe3d809e9e788f50620536 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 13 Jun 2012 12:17:06 +0200 Subject: [PATCH 11/19] build: Do not delete tests/vsynth2 directory, which is no longer created. --- .gitignore | 1 - tests/Makefile | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 7450234dec..b7f063f99b 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,6 @@ tests/rotozoom tests/tiny_psnr tests/videogen tests/vsynth1 -tests/vsynth2 tools/aviocat tools/cws2fws tools/graph2dot diff --git a/tests/Makefile b/tests/Makefile index 01ff711a37..429762be7c 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -126,7 +126,7 @@ fate-list: clean:: testclean testclean: - $(RM) -r tests/vsynth1 tests/vsynth2 tests/data + $(RM) -r tests/vsynth1 tests/data $(RM) $(CLEANSUFFIXES:%=tests/%) $(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF)) From 2f296e39a17cd947c6675c20ff61a2d993ff0de2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:10:31 +0200 Subject: [PATCH 12/19] lavfi: allow building without swscale. --- configure | 4 ++-- libavfilter/Makefile | 4 +++- libavfilter/allfilters.c | 5 +---- libavfilter/avfiltergraph.c | 9 +++++++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 5f9eed3cad..31c437c808 100755 --- a/configure +++ b/configure @@ -1531,16 +1531,16 @@ frei0r_src_filter_extralibs='$ldl' hqdn3d_filter_deps="gpl" resample_filter_deps="avresample" ocv_filter_deps="libopencv" +scale_filter_deps="swscale" yadif_filter_deps="gpl" # libraries avdevice_deps="avcodec avformat" -avfilter_deps="swscale" avformat_deps="avcodec" # programs avconv_deps="avcodec avfilter avformat avresample swscale format_filter - setpts_filter" + scale_filter setpts_filter" avplay_deps="avcodec avformat swscale sdl" avplay_select="rdft" avprobe_deps="avcodec avformat" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 7e1a6d1209..955a97cafb 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -1,8 +1,9 @@ NAME = avfilter -FFLIBS = avutil swscale +FFLIBS = avutil FFLIBS-$(CONFIG_ASYNCTS_FILTER) += avresample FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec FFLIBS-$(CONFIG_RESAMPLE_FILTER) += avresample +FFLIBS-$(CONFIG_SCALE_FILTER) += swscale HEADERS = avfilter.h \ avfiltergraph.h \ @@ -63,6 +64,7 @@ OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o OBJS-$(CONFIG_OVERLAY_FILTER) += vf_overlay.o OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o +OBJS-$(CONFIG_SCALE_FILTER) += vf_scale.o OBJS-$(CONFIG_SELECT_FILTER) += vf_select.o OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o OBJS-$(CONFIG_SETPTS_FILTER) += vf_setpts.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 681487118b..118f09d057 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -73,6 +73,7 @@ void avfilter_register_all(void) REGISTER_FILTER (OVERLAY, overlay, vf); REGISTER_FILTER (PAD, pad, vf); REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf); + REGISTER_FILTER (SCALE, scale, vf); REGISTER_FILTER (SELECT, select, vf); REGISTER_FILTER (SETDAR, setdar, vf); REGISTER_FILTER (SETPTS, setpts, vf); @@ -113,8 +114,4 @@ void avfilter_register_all(void) extern AVFilter avfilter_asink_abuffer; avfilter_register(&avfilter_asink_abuffer); } - { - extern AVFilter avfilter_vf_scale; - avfilter_register(&avfilter_vf_scale); - } } diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 4521f790f7..0a863e569c 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -213,11 +213,16 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) /* couldn't merge format lists. auto-insert conversion filter */ switch (link->type) { case AVMEDIA_TYPE_VIDEO: + if (!(filter = avfilter_get_by_name("scale"))) { + av_log(log_ctx, AV_LOG_ERROR, "'scale' filter " + "not present, cannot convert pixel formats.\n"); + return AVERROR(EINVAL); + } + snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d", scaler_count++); snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts); - if ((ret = avfilter_graph_create_filter(&convert, - avfilter_get_by_name("scale"), + if ((ret = avfilter_graph_create_filter(&convert, filter, inst_name, scale_args, NULL, graph)) < 0) return ret; From 24b2f4ed21e463a4bd3beec16f2bdef4a15241c1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:12:08 +0200 Subject: [PATCH 13/19] avfiltergraph: remove a redundant call to avfilter_get_by_name(). --- libavfilter/avfiltergraph.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 0a863e569c..3d463a84d5 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -236,8 +236,7 @@ static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) snprintf(inst_name, sizeof(inst_name), "auto-inserted resampler %d", resampler_count++); - if ((ret = avfilter_graph_create_filter(&convert, - avfilter_get_by_name("resample"), + if ((ret = avfilter_graph_create_filter(&convert, filter, inst_name, NULL, NULL, graph)) < 0) return ret; break; From ce03b0881a941b64c8478aaf7ff759a7fb43a382 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:17:28 +0200 Subject: [PATCH 14/19] configure: add all filters hardcoded into avconv to avconv_deps --- configure | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 31c437c808..4bb20301e7 100755 --- a/configure +++ b/configure @@ -1539,8 +1539,9 @@ avdevice_deps="avcodec avformat" avformat_deps="avcodec" # programs -avconv_deps="avcodec avfilter avformat avresample swscale format_filter - scale_filter setpts_filter" +avconv_deps="avcodec avfilter avformat avresample swscale + aformat_filter asyncts_filter + format_filter fps_filter scale_filter setpts_filter" avplay_deps="avcodec avformat swscale sdl" avplay_select="rdft" avprobe_deps="avcodec avformat" From 9cdf74f904f76b2a1da474a2290c7e9ed34dd431 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 13 Jun 2012 10:52:35 +0200 Subject: [PATCH 15/19] lavfi/audio: use av_samples_copy() instead of custom code. Fixes a possible invalid write, found by Nicolas George. --- libavfilter/audio.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libavfilter/audio.c b/libavfilter/audio.c index 31839bb34b..a6fef9d273 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -185,10 +185,6 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) /* prepare to copy the samples if the buffer has insufficient permissions */ if ((dst->min_perms & samplesref->perms) != dst->min_perms || dst->rej_perms & samplesref->perms) { - int i, planar = av_sample_fmt_is_planar(samplesref->format); - int planes = !planar ? 1: - av_get_channel_layout_nb_channels(samplesref->audio->channel_layout); - av_log(link->dst, AV_LOG_DEBUG, "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n", samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms); @@ -199,8 +195,10 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate; /* Copy actual data into new samples buffer */ - for (i = 0; i < planes; i++) - memcpy(link->cur_buf->extended_data[i], samplesref->extended_data[i], samplesref->linesize[0]); + av_samples_copy(link->cur_buf->extended_data, samplesref->extended_data, + 0, 0, samplesref->audio->nb_samples, + av_get_channel_layout_nb_channels(link->channel_layout), + link->format); avfilter_unref_buffer(samplesref); } else From 9ff930aace0d61a355f14e49f9fa1d95b8c0e5be Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 13 Jun 2012 14:45:57 +0200 Subject: [PATCH 16/19] rtmp: Display a verbose message when an unknown packet type is received MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtmpproto.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 2b15d80846..945ad49faa 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -937,6 +937,9 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) return ret; } break; + default: + av_log(s, AV_LOG_VERBOSE, "Unknown packet type received 0x%02X\n", pkt->type); + break; } return 0; } From c2d38beab2858307f76b01070e7044f2577b8600 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 13 Jun 2012 14:47:26 +0200 Subject: [PATCH 17/19] rtmp: Handle server bandwidth packets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/rtmpproto.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 945ad49faa..729e2d7af4 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -88,6 +88,7 @@ typedef struct RTMPContext { char* tcurl; ///< url of the target stream char* flashver; ///< version of the flash plugin char* swfurl; ///< url of the swf player + int server_bw; ///< server bandwidth } RTMPContext; #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing @@ -523,7 +524,7 @@ static int gen_server_bw(URLContext *s, RTMPContext *rt) return ret; p = pkt.data; - bytestream_put_be32(&p, 2500000); + bytestream_put_be32(&p, rt->server_bw); ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); @@ -851,6 +852,14 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data)); rt->client_report_size = AV_RB32(pkt->data) >> 1; break; + case RTMP_PT_SERVER_BW: + rt->server_bw = AV_RB32(pkt->data); + if (rt->server_bw <= 0) { + av_log(s, AV_LOG_ERROR, "Incorrect server bandwidth %d\n", rt->server_bw); + return AVERROR(EINVAL); + } + av_log(s, AV_LOG_DEBUG, "Server bandwidth = %d\n", rt->server_bw); + break; case RTMP_PT_INVOKE: //TODO: check for the messages sent for wrong state? if (!memcmp(pkt->data, "\002\000\006_error", 9)) { @@ -1198,6 +1207,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) rt->client_report_size = 1048576; rt->bytes_read = 0; rt->last_bytes_read = 0; + rt->server_bw = 2500000; av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", proto, path, rt->app, rt->playpath); From 9477c035a768261e54c50404c0f3746bf023f7a4 Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 13 Jun 2012 14:48:02 +0200 Subject: [PATCH 18/19] rtmp: Set the client buffer time to 3s instead of 0.26s MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This factorizes existing code into a new function gen_buffer_time(), which generates the client buffer time message and sends it to the server. Signed-off-by: Martin Storsjö --- libavformat/rtmpproto.c | 46 ++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 729e2d7af4..0407ad32f8 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -89,6 +89,7 @@ typedef struct RTMPContext { char* flashver; ///< version of the flash plugin char* swfurl; ///< url of the swf player int server_bw; ///< server bandwidth + int client_buffer_time; ///< client buffer time in ms } RTMPContext; #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing @@ -407,6 +408,31 @@ static int gen_delete_stream(URLContext *s, RTMPContext *rt) return ret; } +/** + * Generate client buffer time and send it to the server. + */ +static int gen_buffer_time(URLContext *s, RTMPContext *rt) +{ + RTMPPacket pkt; + uint8_t *p; + int ret; + + if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, + 1, 10)) < 0) + return ret; + + p = pkt.data; + bytestream_put_be16(&p, 3); + bytestream_put_be32(&p, rt->main_channel_id); + bytestream_put_be32(&p, rt->client_buffer_time); + + ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, + rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); + + return ret; +} + /** * Generate 'play' call and send it to the server, then ping the server * to start actual playing. @@ -436,23 +462,6 @@ static int gen_play(URLContext *s, RTMPContext *rt) rt->prev_pkt[1]); ff_rtmp_packet_destroy(&pkt); - if (ret < 0) - return ret; - - // set client buffer time disguised in ping packet - if ((ret = ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, - 1, 10)) < 0) - return ret; - - p = pkt.data; - bytestream_put_be16(&p, 3); - bytestream_put_be32(&p, 1); - bytestream_put_be32(&p, 256); //TODO: what is a good value here? - - ret = ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, - rt->prev_pkt[1]); - ff_rtmp_packet_destroy(&pkt); - return ret; } @@ -910,6 +919,8 @@ static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt) if (rt->is_input) { if ((ret = gen_play(s, rt)) < 0) return ret; + if ((ret = gen_buffer_time(s, rt)) < 0) + return ret; } else { if ((ret = gen_publish(s, rt)) < 0) return ret; @@ -1208,6 +1219,7 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) rt->bytes_read = 0; rt->last_bytes_read = 0; rt->server_bw = 2500000; + rt->client_buffer_time = 3000; av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", proto, path, rt->app, rt->playpath); From 8517e9c476e8cf92d9ed25b6486bb43d3dc2c49d Mon Sep 17 00:00:00 2001 From: Samuel Pitoiset Date: Wed, 13 Jun 2012 15:02:03 +0200 Subject: [PATCH 19/19] rtmp: Add a new option 'rtmp_buffer', for setting the client buffer time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- doc/protocols.texi | 3 +++ libavformat/rtmpproto.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/protocols.texi b/doc/protocols.texi index 66beff634c..84920332f6 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -198,6 +198,9 @@ Additionally, the following parameters can be set via command line options Name of application to connect on the RTMP server. This option overrides the parameter specified in the URI. +@item rtmp_buffer +Set the client buffer time in milliseconds. The default is 3000. + @item rtmp_conn Extra arbitrary AMF connection parameters, parsed from a string, e.g. like @code{B:1 S:authMe O:1 NN:code:1.23 NS:flag:ok O:0}. diff --git a/libavformat/rtmpproto.c b/libavformat/rtmpproto.c index 0407ad32f8..e64e2a322b 100644 --- a/libavformat/rtmpproto.c +++ b/libavformat/rtmpproto.c @@ -1219,7 +1219,6 @@ static int rtmp_open(URLContext *s, const char *uri, int flags) rt->bytes_read = 0; rt->last_bytes_read = 0; rt->server_bw = 2500000; - rt->client_buffer_time = 3000; av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", proto, path, rt->app, rt->playpath); @@ -1366,6 +1365,7 @@ static int rtmp_write(URLContext *s, const uint8_t *buf, int size) static const AVOption rtmp_options[] = { {"rtmp_app", "Name of application to connect to on the RTMP server", OFFSET(app), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, + {"rtmp_buffer", "Set buffer time in milliseconds. The default is 3000.", OFFSET(client_buffer_time), AV_OPT_TYPE_INT, {3000}, 0, INT_MAX, DEC|ENC}, {"rtmp_conn", "Append arbitrary AMF data to the Connect message", OFFSET(conn), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"rtmp_flashver", "Version of the Flash plugin used to run the SWF player.", OFFSET(flashver), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC|ENC}, {"rtmp_live", "Specify that the media is a live stream.", OFFSET(live), AV_OPT_TYPE_INT, {-2}, INT_MIN, INT_MAX, DEC, "rtmp_live"},