From d85e18e6e342bf58f8e13a95f601082e5d70803a Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 2 Apr 2011 20:26:39 +0200 Subject: yadif: Fix assert() failure Signed-off-by: Anton Khirnov --- libavfilter/vf_yadif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 7a488d6aaa..0396fe416a 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -274,7 +274,7 @@ static int poll_frame(AVFilterLink *link) return ret; val = avfilter_poll_frame(link->src->inputs[0]); } - assert(yadif->next); + assert(yadif->next || !val); return val * ((yadif->mode&1)+1); } -- cgit v1.2.3 From 88312a4de3708cdd8f0ca4121546ec882777b7fa Mon Sep 17 00:00:00 2001 From: James Darnley Date: Tue, 5 Apr 2011 02:45:10 +0200 Subject: yadif: support more than yuv420p. and correctly support grey8 Signed-off-by: Anton Khirnov --- libavfilter/vf_yadif.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 0396fe416a..59b5ac7046 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -20,6 +20,7 @@ #include "libavutil/cpu.h" #include "libavutil/common.h" +#include "libavutil/pixdesc.h" #include "avfilter.h" #include "yadif.h" @@ -51,6 +52,8 @@ typedef struct { void (*filter_line)(uint8_t *dst, uint8_t *prev, uint8_t *cur, uint8_t *next, int w, int prefs, int mrefs, int parity, int mode); + + const AVPixFmtDescriptor *csp; } YADIFContext; static void filter_line_c(uint8_t *dst, @@ -121,12 +124,17 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, YADIFContext *yadif = ctx->priv; int y, i; - for (i = 0; i < 3; i++) { - int is_chroma = !!i; - int w = dstpic->video->w >> is_chroma; - int h = dstpic->video->h >> is_chroma; + for (i = 0; i < yadif->csp->nb_components; i++) { + int w = dstpic->video->w; + int h = dstpic->video->h; int refs = yadif->cur->linesize[i]; + if (i) { + /* Why is this not part of the per-plane description thing? */ + w >>= yadif->csp->log2_chroma_w; + h >>= yadif->csp->log2_chroma_h; + } + for (y = 0; y < h; y++) { if ((y ^ parity) & 1) { uint8_t *prev = &yadif->prev->data[i][y*refs]; @@ -181,6 +189,9 @@ static void return_frame(AVFilterContext *ctx, int is_second) yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | AV_PERM_REUSE, link->w, link->h); + if (!yadif->csp) + yadif->csp = &av_pix_fmt_descriptors[link->format]; + filter(ctx, yadif->out, tff ^ !is_second, tff); if (is_second) { @@ -292,7 +303,16 @@ static int query_formats(AVFilterContext *ctx) { static const enum PixelFormat pix_fmts[] = { PIX_FMT_YUV420P, + PIX_FMT_YUV422P, + PIX_FMT_YUV444P, + PIX_FMT_YUV410P, + PIX_FMT_YUV411P, PIX_FMT_GRAY8, + PIX_FMT_YUVJ420P, + PIX_FMT_YUVJ422P, + PIX_FMT_YUVJ444P, + PIX_FMT_YUV440P, + PIX_FMT_YUVJ440P, PIX_FMT_NONE }; @@ -308,6 +328,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) yadif->mode = 0; yadif->parity = -1; + yadif->csp = NULL; if (args) sscanf(args, "%d:%d", &yadif->mode, &yadif->parity); -- cgit v1.2.3 From b137bf7df35b3cc792d8cd645a47c4f1d8f1d58f Mon Sep 17 00:00:00 2001 From: James Darnley Date: Wed, 24 Nov 2010 21:25:09 +0100 Subject: yadif: support 16-bit Fixes by Michael Niedermayer Signed-off-by: Anton Khirnov --- libavfilter/vf_yadif.c | 116 ++++++++++++++++++++++++++++--------------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/libavfilter/vf_yadif.c b/libavfilter/vf_yadif.c index 59b5ac7046..42a7219d26 100644 --- a/libavfilter/vf_yadif.c +++ b/libavfilter/vf_yadif.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2006-2010 Michael Niedermayer + * 2010 James Darnley * * This file is part of Libav. * @@ -56,25 +57,6 @@ typedef struct { const AVPixFmtDescriptor *csp; } YADIFContext; -static void filter_line_c(uint8_t *dst, - uint8_t *prev, uint8_t *cur, uint8_t *next, - int w, int prefs, int mrefs, int parity, int mode) -{ - int x; - uint8_t *prev2 = parity ? prev : cur ; - uint8_t *next2 = parity ? cur : next; - for (x = 0; x < w; x++) { - int c = cur[mrefs]; - int d = (prev2[0] + next2[0])>>1; - int e = cur[prefs]; - int temporal_diff0 = FFABS(prev2[0] - next2[0]); - int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; - int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; - int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); - int spatial_pred = (c+e)>>1; - int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) - + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; - #define CHECK(j)\ { int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\ + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\ @@ -83,39 +65,68 @@ static void filter_line_c(uint8_t *dst, spatial_score= score;\ spatial_pred= (cur[mrefs +(j)] + cur[prefs -(j)])>>1;\ - CHECK(-1) CHECK(-2) }} }} - CHECK( 1) CHECK( 2) }} }} - - if (mode < 2) { - int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; - int f = (prev2[2*prefs] + next2[2*prefs])>>1; -#if 0 - int a = cur[-3*refs]; - int g = cur[+3*refs]; - int max = FFMAX3(d-e, d-c, FFMIN3(FFMAX(b-c,f-e),FFMAX(b-c,b-a),FFMAX(f-g,f-e)) ); - int min = FFMIN3(d-e, d-c, FFMAX3(FFMIN(b-c,f-e),FFMIN(b-c,b-a),FFMIN(f-g,f-e)) ); -#else - int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); - int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); -#endif +#define FILTER \ + for (x = 0; x < w; x++) { \ + int c = cur[mrefs]; \ + int d = (prev2[0] + next2[0])>>1; \ + int e = cur[prefs]; \ + int temporal_diff0 = FFABS(prev2[0] - next2[0]); \ + int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \ + int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \ + int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); \ + int spatial_pred = (c+e)>>1; \ + int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) \ + + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; \ + \ + CHECK(-1) CHECK(-2) }} }} \ + CHECK( 1) CHECK( 2) }} }} \ + \ + if (mode < 2) { \ + int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; \ + int f = (prev2[2*prefs] + next2[2*prefs])>>1; \ + int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); \ + int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); \ + \ + diff = FFMAX3(diff, min, -max); \ + } \ + \ + if (spatial_pred > d + diff) \ + spatial_pred = d + diff; \ + else if (spatial_pred < d - diff) \ + spatial_pred = d - diff; \ + \ + dst[0] = spatial_pred; \ + \ + dst++; \ + cur++; \ + prev++; \ + next++; \ + prev2++; \ + next2++; \ + } - diff = FFMAX3(diff, min, -max); - } +static void filter_line_c(uint8_t *dst, + uint8_t *prev, uint8_t *cur, uint8_t *next, + int w, int prefs, int mrefs, int parity, int mode) +{ + int x; + uint8_t *prev2 = parity ? prev : cur ; + uint8_t *next2 = parity ? cur : next; - if (spatial_pred > d + diff) - spatial_pred = d + diff; - else if (spatial_pred < d - diff) - spatial_pred = d - diff; + FILTER +} - dst[0] = spatial_pred; +static void filter_line_c_16bit(uint16_t *dst, + uint16_t *prev, uint16_t *cur, uint16_t *next, + int w, int prefs, int mrefs, int parity, int mode) +{ + int x; + uint16_t *prev2 = parity ? prev : cur ; + uint16_t *next2 = parity ? cur : next; + mrefs /= 2; + prefs /= 2; - dst++; - cur++; - prev++; - next++; - prev2++; - next2++; - } + FILTER } static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, @@ -128,6 +139,7 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, int w = dstpic->video->w; int h = dstpic->video->h; int refs = yadif->cur->linesize[i]; + int df = (yadif->csp->comp[i].depth_minus1+1) / 8; if (i) { /* Why is this not part of the per-plane description thing? */ @@ -145,7 +157,7 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, yadif->filter_line(dst, prev, cur, next, w, y+1data[i][y*dstpic->linesize[i]], - &yadif->cur->data[i][y*refs], w); + &yadif->cur->data[i][y*refs], w*df); } } } @@ -191,6 +203,8 @@ static void return_frame(AVFilterContext *ctx, int is_second) if (!yadif->csp) yadif->csp = &av_pix_fmt_descriptors[link->format]; + if (yadif->csp->comp[0].depth_minus1 == 15) + yadif->filter_line = filter_line_c_16bit; filter(ctx, yadif->out, tff ^ !is_second, tff); @@ -311,8 +325,12 @@ static int query_formats(AVFilterContext *ctx) PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, + AV_NE( PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE ), PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, + AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ), + AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ), + AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ), PIX_FMT_NONE }; -- cgit v1.2.3 From 68e23c083a5d907748481e962ee38abbcb167174 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 27 Mar 2011 22:58:08 +0200 Subject: scale: make the filter parametric Make the filter accept parametric expressions for the output video size. Signed-off-by: Stefano Sabatini Signed-off-by: Anton Khirnov --- doc/filters.texi | 60 +++++++++++++++++++++++++++++--- libavfilter/vf_scale.c | 93 +++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 139 insertions(+), 14 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 1a26f10c59..669a334eca 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -772,13 +772,33 @@ can be used to test the monowhite pixel format descriptor definition. Scale the input video to @var{width}:@var{height} and/or convert the image format. -For example the command: +The parameters @var{width} and @var{height} are expressions containing +the following constants: -@example -./ffmpeg -i in.avi -vf "scale=200:100" out.avi -@end example +@table @option +@item E, PI, PHI +the corresponding mathematical approximated values for e +(euler number), pi (greek PI), phi (golden ratio) + +@item in_w, in_h +the input width and heigth + +@item iw, ih +same as @var{in_w} and @var{in_h} + +@item out_w, out_h +the output (cropped) width and heigth + +@item ow, oh +same as @var{out_w} and @var{out_h} -will scale the input video to a size of 200x100. +@item a +input display aspect ratio, same as @var{iw} / @var{ih} + +@item hsub, vsub +horizontal and vertical chroma subsample values. For example for the +pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. +@end table If the input image format is different from the format requested by the next filter, the scale filter will convert the input to the @@ -793,6 +813,36 @@ ratio of the input image. The default value of @var{width} and @var{height} is 0. +Some examples follow: +@example +# scale the input video to a size of 200x100. +scale=200:100 + +# scale the input to 2x +scale=2*iw:2*ih +# the above is the same as +scale=2*in_w:2*in_h + +# scale the input to half size +scale=iw/2:ih/2 + +# increase the width, and set the height to the same size +scale=3/2*iw:ow + +# seek for Greek harmony +scale=iw:1/PHI*iw +scale=ih*PHI:ih + +# increase the height, and set the width to 3/2 of the height +scale=3/2*oh:3/5*ih + +# increase the size, but make the size a multiple of the chroma +scale="trunc(3/2*iw/hsub)*hsub:trunc(3/2*ih/vsub)*vsub" + +# increase the width to a maximum of 500 pixels, keep the same input aspect ratio +scale='min(500\, iw*3/2):-1' +@end example + @anchor{setdar} @section setdar diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index b2b0b636c5..65fe01c9ae 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -24,9 +24,39 @@ */ #include "avfilter.h" +#include "libavutil/avstring.h" +#include "libavutil/eval.h" #include "libavutil/pixdesc.h" #include "libswscale/swscale.h" +static const char *var_names[] = { + "PI", + "PHI", + "E", + "in_w", "iw", + "in_h", "ih", + "out_w", "ow", + "out_h", "oh", + "a", + "hsub", + "vsub", + NULL +}; + +enum var_name { + VAR_PI, + VAR_PHI, + VAR_E, + VAR_IN_W, VAR_IW, + VAR_IN_H, VAR_IH, + VAR_OUT_W, VAR_OW, + VAR_OUT_H, VAR_OH, + VAR_A, + VAR_HSUB, + VAR_VSUB, + VARS_NB +}; + typedef struct { struct SwsContext *sws; ///< software scaler context @@ -41,6 +71,9 @@ typedef struct { int hsub, vsub; ///< chroma subsampling int slice_y; ///< top of current output slice int input_is_pal; ///< set to 1 if the input format is paletted + + char w_expr[256]; ///< width expression string + char h_expr[256]; ///< height expression string } ScaleContext; static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) @@ -48,21 +81,16 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ScaleContext *scale = ctx->priv; const char *p; + av_strlcpy(scale->w_expr, "iw", sizeof(scale->w_expr)); + av_strlcpy(scale->h_expr, "ih", sizeof(scale->h_expr)); + scale->flags = SWS_BILINEAR; if (args) { - sscanf(args, "%d:%d", &scale->w, &scale->h); + sscanf(args, "%255[^:]:%255[^:]", scale->w_expr, scale->h_expr); p = strstr(args,"flags="); if (p) scale->flags = strtoul(p+6, NULL, 0); } - /* sanity check params */ - if (scale->w < -1 || scale->h < -1) { - av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); - return AVERROR(EINVAL); - } - if (scale->w == -1 && scale->h == -1) - scale->w = scale->h = 0; - return 0; } @@ -109,6 +137,48 @@ static int config_props(AVFilterLink *outlink) AVFilterLink *inlink = outlink->src->inputs[0]; ScaleContext *scale = ctx->priv; int64_t w, h; + double var_values[VARS_NB], res; + char *expr; + int ret; + + var_values[VAR_PI] = M_PI; + var_values[VAR_PHI] = M_PHI; + var_values[VAR_E] = M_E; + var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; + var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; + var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; + var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; + var_values[VAR_A] = (float) inlink->w / inlink->h; + var_values[VAR_HSUB] = 1<format].log2_chroma_w; + var_values[VAR_VSUB] = 1<format].log2_chroma_h; + + /* evaluate width and height */ + av_expr_parse_and_eval(&res, (expr = scale->w_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx); + scale->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; + if ((ret = av_expr_parse_and_eval(&res, (expr = scale->h_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) + goto fail; + scale->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; + /* evaluate again the width, as it may depend on the output height */ + if ((ret = av_expr_parse_and_eval(&res, (expr = scale->w_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) + goto fail; + scale->w = res; + + w = scale->w; + h = scale->h; + + /* sanity check params */ + if (w < -1 || h < -1) { + av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); + return AVERROR(EINVAL); + } + if (w == -1 && h == -1) + scale->w = scale->h = 0; if (!(w = scale->w)) w = inlink->w; @@ -142,6 +212,11 @@ static int config_props(AVFilterLink *outlink) return AVERROR(EINVAL); return 0; + +fail: + av_log(NULL, AV_LOG_ERROR, + "Error when evaluating the expression '%s'\n", expr); + return ret; } static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) -- cgit v1.2.3 From 2f84bb4236accadffdfad30a5ec0d80e72449f15 Mon Sep 17 00:00:00 2001 From: Mark Himsley Date: Sun, 10 Apr 2011 19:18:03 +0200 Subject: lavfi: add fieldorder filter Signed-off-by: Stefano Sabatini Signed-off-by: Anton Khirnov --- Changelog | 1 + doc/filters.texi | 33 +++++++ libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/avfilter.h | 2 +- libavfilter/vf_fieldorder.c | 235 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_fieldorder.c diff --git a/Changelog b/Changelog index 00777e4e6a..cfa87549f8 100644 --- a/Changelog +++ b/Changelog @@ -90,6 +90,7 @@ version 0.7_beta1: - AAC encoding via libvo-aacenc - AMR-WB encoding via libvo-amrwbenc - xWMA demuxer +- fieldorder video filter added version 0.6: diff --git a/doc/filters.texi b/doc/filters.texi index 669a334eca..8f949221a8 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -386,6 +386,39 @@ fade=in:0:25, fade=out:975:25 fade=in:5:20 @end example +@section fieldorder + +Transform the field order of the input video. + +It accepts one parameter which specifies the required field order that +the input interlaced video will be transformed to. The parameter can +assume one of the following values: + +@table @option +@item 0 or bff +output bottom field first +@item 1 or tff +output top field first +@end table + +Default value is "tff". + +Transformation is achieved by shifting the picture content up or down +by one line, and filling the remaining line with appropriate picture content. +This method is consistent with most broadcast field order converters. + +If the input video is not flagged as being interlaced, or it is already +flagged as being of the required output field order then this filter does +not alter the incoming video. + +This filter is very useful when converting to or from PAL DV material, +which is bottom field first. + +For example: +@example +./ffmpeg -i in.vob -vf "fieldorder=bff" out.dv +@end example + @section fifo Buffer input images and send them when they are requested. diff --git a/libavfilter/Makefile b/libavfilter/Makefile index f7bc98df98..0683af3564 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -27,6 +27,7 @@ OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o OBJS-$(CONFIG_CROPDETECT_FILTER) += vf_cropdetect.o OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o +OBJS-$(CONFIG_FIELDORDER_FILTER) += vf_fieldorder.o OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index 34e87f5fd9..9801d9281e 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -46,6 +46,7 @@ void avfilter_register_all(void) REGISTER_FILTER (CROPDETECT, cropdetect, vf); REGISTER_FILTER (DRAWBOX, drawbox, vf); REGISTER_FILTER (FADE, fade, vf); + REGISTER_FILTER (FIELDORDER, fieldorder, vf); REGISTER_FILTER (FIFO, fifo, vf); REGISTER_FILTER (FORMAT, format, vf); REGISTER_FILTER (FREI0R, frei0r, vf); diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 7505c2eecd..19f9f6923a 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 0 +#define LIBAVFILTER_VERSION_MINOR 1 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/vf_fieldorder.c b/libavfilter/vf_fieldorder.c new file mode 100644 index 0000000000..59ca77821a --- /dev/null +++ b/libavfilter/vf_fieldorder.c @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2011 Mark Himsley + * + * This file is part of FFmpeg. + * + * FFmpeg 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. + * + * FFmpeg 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 FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/** + * @file + * video field order filter, heavily influenced by vf_pad.c + */ + +/* #define DEBUG */ + +#include "libavutil/imgutils.h" +#include "libavutil/pixdesc.h" +#include "avfilter.h" + +typedef struct +{ + unsigned int dst_tff; ///< output bff/tff + int line_size[4]; ///< bytes of pixel data per line for each plane +} FieldOrderContext; + +static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +{ + FieldOrderContext *fieldorder = ctx->priv; + + const char *tff = "tff"; + const char *bff = "bff"; + + if (!args) { + fieldorder->dst_tff = 1; + } else if (sscanf(args, "%u", &fieldorder->dst_tff) == 1) { + fieldorder->dst_tff = !!fieldorder->dst_tff; + } else if (!strcmp(tff, args)) { + fieldorder->dst_tff = 1; + } else if (!strcmp(bff, args)) { + fieldorder->dst_tff = 0; + } else { + av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'.\n", args); + return AVERROR(EINVAL); + } + + av_log(ctx, AV_LOG_INFO, "output field order: %s\n", + fieldorder->dst_tff ? tff : bff); + + return 0; +} + +static int query_formats(AVFilterContext *ctx) +{ + AVFilterFormats *formats; + enum PixelFormat pix_fmt; + int ret; + + /** accept any input pixel format that is not hardware accelerated, not + * a bitstream format, and does not have vertically sub-sampled chroma */ + if (ctx->inputs[0]) { + formats = NULL; + for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) + if (!( av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL + || av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BITSTREAM) + && av_pix_fmt_descriptors[pix_fmt].nb_components + && !av_pix_fmt_descriptors[pix_fmt].log2_chroma_h + && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { + avfilter_formats_unref(&formats); + return ret; + } + avfilter_formats_ref(formats, &ctx->inputs[0]->out_formats); + avfilter_formats_ref(formats, &ctx->outputs[0]->in_formats); + } + + return 0; +} + +static int config_input(AVFilterLink *inlink) +{ + AVFilterContext *ctx = inlink->dst; + FieldOrderContext *fieldorder = ctx->priv; + int plane; + + /** full an array with the number of bytes that the video + * data occupies per line for each plane of the input video */ + for (plane = 0; plane < 4; plane++) { + fieldorder->line_size[plane] = av_image_get_linesize( + inlink->format, + inlink->w, + plane); + } + + return 0; +} + +static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int w, int h) +{ + AVFilterContext *ctx = inlink->dst; + AVFilterLink *outlink = ctx->outputs[0]; + + return avfilter_get_video_buffer(outlink, perms, w, h); +} + +static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) +{ + AVFilterContext *ctx = inlink->dst; + AVFilterLink *outlink = ctx->outputs[0]; + + AVFilterBufferRef *outpicref; + + outpicref = avfilter_ref_buffer(inpicref, ~0); + outlink->out_buf = outpicref; + + avfilter_start_frame(outlink, outpicref); +} + +static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) +{ + AVFilterContext *ctx = inlink->dst; + FieldOrderContext *fieldorder = ctx->priv; + AVFilterLink *outlink = ctx->outputs[0]; + + AVFilterBufferRef *inpicref = inlink->cur_buf; + + /** can only currently do slices if this filter is doing nothing + * because this filter is moving picture content, the output + * slice will contain different video lines than the input slice + * and that complexity will be added later */ + if ( !inpicref->video->interlaced + || inpicref->video->top_field_first == fieldorder->dst_tff) { + avfilter_draw_slice(outlink, y, h, slice_dir); + } +} + +static void end_frame(AVFilterLink *inlink) +{ + AVFilterContext *ctx = inlink->dst; + FieldOrderContext *fieldorder = ctx->priv; + AVFilterLink *outlink = ctx->outputs[0]; + + AVFilterBufferRef *inpicref = inlink->cur_buf; + AVFilterBufferRef *outpicref = outlink->out_buf; + + int h, w, plane, line_step, line_size, line; + uint8_t *cpy_src, *cpy_dst; + + if ( inpicref->video->interlaced + && inpicref->video->top_field_first != fieldorder->dst_tff) { + av_dlog(ctx, + "picture will move %s one line\n", + fieldorder->dst_tff ? "up" : "down"); + h = inpicref->video->h; + w = inpicref->video->w; + for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) { + line_step = inpicref->linesize[plane]; + line_size = fieldorder->line_size[plane]; + cpy_src = inpicref->data[plane]; + cpy_dst = outpicref->data[plane]; + if (fieldorder->dst_tff) { + /** Move every line up one line, working from + * the top to the bottom of the frame. + * The original top line is lost. + * The new last line is created as a copy of the + * penultimate line from that field. */ + for (line = 0; line < h; line++) { + if (1 + line < outpicref->video->h) { + memcpy(cpy_dst, cpy_src + line_step, line_size); + } else { + memcpy(cpy_dst, cpy_src - line_step - line_step, line_size); + } + cpy_src += line_step; + cpy_dst += line_step; + } + } else { + /** Move every line down one line, working from + * the bottom to the top of the frame. + * The original bottom line is lost. + * The new first line is created as a copy of the + * second line from that field. */ + cpy_src += (h - 1) * line_step; + cpy_dst += (h - 1) * line_step; + for (line = h - 1; line >= 0 ; line--) { + if (line > 0) { + memcpy(cpy_dst, cpy_src - line_step, line_size); + } else { + memcpy(cpy_dst, cpy_src + line_step + line_step, line_size); + } + cpy_src -= line_step; + cpy_dst -= line_step; + } + } + } + outpicref->video->top_field_first = fieldorder->dst_tff; + avfilter_draw_slice(outlink, 0, h, 1); + } else { + av_dlog(ctx, + "not interlaced or field order already correct\n"); + } + + avfilter_end_frame(outlink); + avfilter_unref_buffer(inpicref); +} + +AVFilter avfilter_vf_fieldorder = { + .name = "fieldorder", + .description = NULL_IF_CONFIG_SMALL("Set the field order."), + .init = init, + .priv_size = sizeof(FieldOrderContext), + .query_formats = query_formats, + .inputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .start_frame = start_frame, + .get_video_buffer = get_video_buffer, + .draw_slice = draw_slice, + .end_frame = end_frame, + .min_perms = AV_PERM_READ, + .rej_perms = AV_PERM_REUSE2|AV_PERM_PRESERVE,}, + { .name = NULL}}, + .outputs = (AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, +}; -- cgit v1.2.3 From 7a11c82fb760619d0e17ca234381b50d6c675cc0 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 31 Jan 2011 20:48:35 +0100 Subject: vsrc_buffer: add sample_aspect_ratio fields to arguments. This fixes aspect handling in ffmpeg. This is based on a patch by Baptiste. Signed-off-by: Anton Khirnov --- doc/APIchanges | 3 +++ doc/filters.texi | 11 ++++++++--- ffmpeg.c | 18 ++++++++++++++++-- libavfilter/avfilter.h | 2 +- libavfilter/vsrc_buffer.c | 7 +++++-- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 5c7b6775c4..6347233dc4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-04-xx - xxxxxx - lavfi 2.2.0 - vsrc_buffer + Add sample_aspect_ratio fields to vsrc_buffer arguments + 2011-04-21 - 94f7451 - lavc 53.1.0 - avcodec.h Add CODEC_CAP_SLICE_THREADS for codecs supporting sliced threading. diff --git a/doc/filters.texi b/doc/filters.texi index 8f949221a8..48c03f1ed8 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -1190,7 +1190,7 @@ This source is mainly intended for a programmatic use, in particular through the interface defined in @file{libavfilter/vsrc_buffer.h}. It accepts the following parameters: -@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den} +@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den} All the parameters need to be explicitely defined. @@ -1209,15 +1209,20 @@ name. @item timebase_num, timebase_den Specify numerator and denomitor of the timebase assumed by the timestamps of the buffered frames. + +@item sample_aspect_ratio.num, sample_aspect_ratio.den +Specify numerator and denominator of the sample aspect ratio assumed +by the video frames. @end table For example: @example -buffer=320:240:yuv410p:1:24 +buffer=320:240:yuv410p:1:24:1:1 @end example will instruct the source to accept video frames with size 320x240 and -with format "yuv410p" and assuming 1/24 as the timestamps timebase. +with format "yuv410p", assuming 1/24 as the timestamps timebase and +square pixels (1:1 sample aspect ratio). Since the pixel format with name "yuv410p" corresponds to the number 6 (check the enum PixelFormat definition in @file{libavutil/pixfmt.h}), this example corresponds to: diff --git a/ffmpeg.c b/ffmpeg.c index d54785d597..d3a85dde89 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -344,13 +344,21 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) AVCodecContext *codec = ost->st->codec; AVCodecContext *icodec = ist->st->codec; FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt }; + AVRational sample_aspect_ratio; char args[255]; int ret; graph = avfilter_graph_alloc(); - snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width, - ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE); + if (ist->st->sample_aspect_ratio.num){ + sample_aspect_ratio = ist->st->sample_aspect_ratio; + }else + sample_aspect_ratio = ist->st->codec->sample_aspect_ratio; + + snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width, + ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE, + sample_aspect_ratio.num, sample_aspect_ratio.den); + ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"), "src", args, NULL, graph); if (ret < 0) @@ -404,6 +412,8 @@ static int configure_filters(AVInputStream *ist, AVOutputStream *ost) codec->width = ist->output_video_filter->inputs[0]->w; codec->height = ist->output_video_filter->inputs[0]->h; + codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = + ist->output_video_filter->inputs[0]->sample_aspect_ratio; return 0; } @@ -2784,6 +2794,10 @@ static void opt_frame_aspect_ratio(const char *arg) ffmpeg_exit(1); } frame_aspect_ratio = ar; + + x = vfilters ? strlen(vfilters) : 0; + vfilters = av_realloc(vfilters, x+100); + snprintf(vfilters+x, x+100, "%csetdar=%f\n", x?',':' ', ar); } static int opt_metadata(const char *opt, const char *arg) diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 19f9f6923a..a1eff6e739 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 1 +#define LIBAVFILTER_VERSION_MINOR 2 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index 93f2367ab8..dea41de721 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -68,8 +68,10 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) int n = 0; if (!args || - (n = sscanf(args, "%d:%d:%127[^:]:%d:%d", &c->w, &c->h, pix_fmt_str, &c->time_base.num, &c->time_base.den)) != 5) { - av_log(ctx, AV_LOG_ERROR, "Expected 5 arguments, but only %d found in '%s'\n", n, args); + (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d", &c->w, &c->h, pix_fmt_str, + &c->time_base.num, &c->time_base.den, + &c->pixel_aspect.num, &c->pixel_aspect.den)) != 7) { + av_log(ctx, AV_LOG_ERROR, "Expected 7 arguments, but only %d found in '%s'\n", n, args); return AVERROR(EINVAL); } if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) { @@ -100,6 +102,7 @@ static int config_props(AVFilterLink *link) link->w = c->w; link->h = c->h; + link->sample_aspect_ratio = c->pixel_aspect; link->time_base = c->time_base; return 0; -- cgit v1.2.3 From 10d39405fa82473367e1ba1ed3c4ecbeca2a7986 Mon Sep 17 00:00:00 2001 From: Roger Pau Monné Date: Sat, 16 Apr 2011 10:09:15 +0200 Subject: lavfi: add key_frame and pict_type to AVFilterBufferRefVideo. Signed-off-by: Anton Khirnov --- cmdutils.c | 2 ++ doc/APIchanges | 3 +++ libavfilter/avfilter.h | 4 +++- libavfilter/vsrc_buffer.c | 4 ++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmdutils.c b/cmdutils.c index d15aba0635..9da07223f5 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -922,6 +922,8 @@ int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize)); frame->interlaced_frame = picref->video->interlaced; frame->top_field_first = picref->video->top_field_first; + frame->key_frame = picref->video->key_frame; + frame->pict_type = picref->video->pict_type; return 1; } diff --git a/doc/APIchanges b/doc/APIchanges index 6347233dc4..3c20e91b4c 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-04-xx - xxxxxx - lavfi 2.3.0 - avfilter.h + Add pict_type and key_frame fields to AVFilterBufferRefVideo. + 2011-04-xx - xxxxxx - lavfi 2.2.0 - vsrc_buffer Add sample_aspect_ratio fields to vsrc_buffer arguments diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index a1eff6e739..cbc0238aa3 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -26,7 +26,7 @@ #include "libavutil/samplefmt.h" #define LIBAVFILTER_VERSION_MAJOR 2 -#define LIBAVFILTER_VERSION_MINOR 2 +#define LIBAVFILTER_VERSION_MINOR 3 #define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ @@ -115,6 +115,8 @@ typedef struct AVFilterBufferRefVideoProps { AVRational pixel_aspect; ///< pixel aspect ratio int interlaced; ///< is frame interlaced int top_field_first; ///< field order + int pict_type; ///< Picture type of the frame + int key_frame; ///< 1 -> keyframe, 0-> not } AVFilterBufferRefVideoProps; /** diff --git a/libavfilter/vsrc_buffer.c b/libavfilter/vsrc_buffer.c index dea41de721..6567279667 100644 --- a/libavfilter/vsrc_buffer.c +++ b/libavfilter/vsrc_buffer.c @@ -54,6 +54,8 @@ int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); c->frame.interlaced_frame= frame->interlaced_frame; c->frame.top_field_first = frame->top_field_first; + c->frame.key_frame = frame->key_frame; + c->frame.pict_type = frame->pict_type; c->pts = pts; c->pixel_aspect = pixel_aspect; c->has_frame = 1; @@ -133,6 +135,8 @@ static int request_frame(AVFilterLink *link) picref->video->pixel_aspect = c->pixel_aspect; picref->video->interlaced = c->frame.interlaced_frame; picref->video->top_field_first = c->frame.top_field_first; + picref->video->key_frame = c->frame.key_frame; + picref->video->pict_type = c->frame.pict_type; avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); avfilter_draw_slice(link, 0, link->h, 1); avfilter_end_frame(link); -- cgit v1.2.3 From 5eb901cfec4a1bca4d961c6eb6889a91a87031ca Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Mon, 18 Apr 2011 19:21:25 +0200 Subject: vsrc_movie: fix leak in request_frame() Also set movie->picref to NULL, in order to avoid a crash in uninit() when movie->picref is unreffed again and it was already freed. Signed-off-by: Stefano Sabatini Signed-off-by: Anton Khirnov --- libavfilter/vsrc_movie.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index 25bbd4736c..92eb0ecfe0 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -290,6 +290,8 @@ static int request_frame(AVFilterLink *outlink) avfilter_start_frame(outlink, outpicref); avfilter_draw_slice(outlink, 0, outlink->h, 1); avfilter_end_frame(outlink); + avfilter_unref_buffer(movie->picref); + movie->picref = NULL; return 0; } -- cgit v1.2.3 From 0bbb28c75bcce950221aa4d9c30b972aab9201f3 Mon Sep 17 00:00:00 2001 From: royger Date: Mon, 18 Apr 2011 17:50:16 +0200 Subject: vsrc_movie: add key_frame and pict_type. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Roger Pau Monné Signed-off-by: Michael Niedermayer Signed-off-by: Anton Khirnov --- libavfilter/vsrc_movie.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavfilter/vsrc_movie.c b/libavfilter/vsrc_movie.c index 92eb0ecfe0..88220bc4fd 100644 --- a/libavfilter/vsrc_movie.c +++ b/libavfilter/vsrc_movie.c @@ -252,6 +252,8 @@ static int movie_get_frame(AVFilterLink *outlink) st->sample_aspect_ratio : movie->codec_ctx->sample_aspect_ratio; movie->picref->video->interlaced = movie->frame->interlaced_frame; movie->picref->video->top_field_first = movie->frame->top_field_first; + movie->picref->video->key_frame = movie->frame->key_frame; + movie->picref->video->pict_type = movie->frame->pict_type; av_dlog(outlink->src, "movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n", movie->file_name, movie->picref->pts, -- cgit v1.2.3 From 73a4f7c21bbb179f7542d8a5fedf55fd894fa9da Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sun, 17 Apr 2011 17:19:05 +0200 Subject: pad: make the filter parametric Signed-off-by: Stefano Sabatini Signed-off-by: Anton Khirnov --- doc/filters.texi | 57 +++++++++++++++++++++++++- libavfilter/vf_pad.c | 114 +++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 162 insertions(+), 9 deletions(-) diff --git a/doc/filters.texi b/doc/filters.texi index 48c03f1ed8..35b61d170d 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -753,6 +753,39 @@ given coordinates @var{x}, @var{y}. It accepts the following parameters: @var{width}:@var{height}:@var{x}:@var{y}:@var{color}. +The parameters @var{width}, @var{height}, @var{x}, and @var{y} are +expressions containing the following constants: + +@table @option +@item E, PI, PHI +the corresponding mathematical approximated values for e +(euler number), pi (greek PI), phi (golden ratio) + +@item in_w, in_h +the input video width and heigth + +@item iw, ih +same as @var{in_w} and @var{in_h} + +@item out_w, out_h +the output width and heigth, that is the size of the padded area as +specified by the @var{width} and @var{height} expressions + +@item ow, oh +same as @var{out_w} and @var{out_h} + +@item x, y +x and y offsets as specified by the @var{x} and @var{y} +expressions, or NAN if not yet specified + +@item a +input display aspect ratio, same as @var{iw} / @var{ih} + +@item hsub, vsub +horizontal and vertical chroma subsample values. For example for the +pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. +@end table + Follows the description of the accepted parameters. @table @option @@ -762,6 +795,9 @@ Specify the size of the output image with the paddings added. If the value for @var{width} or @var{height} is 0, the corresponding input size is used for the output. +The @var{width} expression can reference the value set by the +@var{height} expression, and viceversa. + The default value of @var{width} and @var{height} is 0. @item x, y @@ -769,6 +805,9 @@ The default value of @var{width} and @var{height} is 0. Specify the offsets where to place the input image in the padded area with respect to the top/left border of the output image. +The @var{x} expression can reference the value set by the @var{y} +expression, and viceversa. + The default value of @var{x} and @var{y} is 0. @item color @@ -780,13 +819,29 @@ The default value of @var{color} is "black". @end table -For example: +Some examples follow: @example # Add paddings with color "violet" to the input video. Output video # size is 640x480, the top-left corner of the input video is placed at # column 0, row 40. pad=640:480:0:40:violet + +# pad the input to get an output with dimensions increased bt 3/2, +# and put the input video at the center of the padded area +pad="3/2*iw:3/2*ih:(ow-iw)/2:(oh-ih)/2" + +# pad the input to get a squared output with size equal to the maximum +# value between the input width and height, and put the input video at +# the center of the padded area +pad="max(iw\,ih):ow:(ow-iw)/2:(oh-ih)/2" + +# pad the input to get a final w/h ratio of 16:9 +pad="ih*16/9:ih:(ow-iw)/2:(oh-ih)/2" + +# double output size and put the input video in the bottom-right +# corner of the output padded area +pad="2*iw:2*ih:ow-iw:oh-ih" @end example @section pixdesctest diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index 4f8e6450e3..18873b8837 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -25,6 +25,8 @@ */ #include "avfilter.h" +#include "libavutil/avstring.h" +#include "libavutil/eval.h" #include "libavutil/pixdesc.h" #include "libavutil/colorspace.h" #include "libavutil/avassert.h" @@ -32,6 +34,38 @@ #include "libavutil/parseutils.h" #include "drawutils.h" +static const char *var_names[] = { + "PI", + "PHI", + "E", + "in_w", "iw", + "in_h", "ih", + "out_w", "ow", + "out_h", "oh", + "x", + "y", + "a", + "hsub", + "vsub", + NULL +}; + +enum var_name { + VAR_PI, + VAR_PHI, + VAR_E, + VAR_IN_W, VAR_IW, + VAR_IN_H, VAR_IH, + VAR_OUT_W, VAR_OW, + VAR_OUT_H, VAR_OH, + VAR_X, + VAR_Y, + VAR_A, + VAR_HSUB, + VAR_VSUB, + VARS_NB +}; + static int query_formats(AVFilterContext *ctx) { static const enum PixelFormat pix_fmts[] = { @@ -58,6 +92,11 @@ typedef struct { int x, y; ///< offsets of the input area with respect to the padded area int in_w, in_h; ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues + char w_expr[256]; ///< width expression string + char h_expr[256]; ///< height expression string + char x_expr[256]; ///< width expression string + char y_expr[256]; ///< height expression string + uint8_t color[4]; ///< color expressed either in YUVA or RGBA colorspace for the padding area uint8_t *line[4]; int line_step[4]; @@ -70,18 +109,18 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) PadContext *pad = ctx->priv; char color_string[128] = "black"; + av_strlcpy(pad->w_expr, "iw", sizeof(pad->w_expr)); + av_strlcpy(pad->h_expr, "ih", sizeof(pad->h_expr)); + av_strlcpy(pad->x_expr, "0" , sizeof(pad->w_expr)); + av_strlcpy(pad->y_expr, "0" , sizeof(pad->h_expr)); + if (args) - sscanf(args, "%d:%d:%d:%d:%s", &pad->w, &pad->h, &pad->x, &pad->y, color_string); + sscanf(args, "%255[^:]:%255[^:]:%255[^:]:%255[^:]:%255s", + pad->w_expr, pad->h_expr, pad->x_expr, pad->y_expr, color_string); if (av_parse_color(pad->color, color_string, -1, ctx) < 0) return AVERROR(EINVAL); - /* sanity check params */ - if (pad->w < 0 || pad->h < 0) { - av_log(ctx, AV_LOG_ERROR, "Negative size values are not acceptable.\n"); - return AVERROR(EINVAL); - } - return 0; } @@ -102,11 +141,64 @@ static int config_input(AVFilterLink *inlink) PadContext *pad = ctx->priv; const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; uint8_t rgba_color[4]; - int is_packed_rgba; + int ret, is_packed_rgba; + double var_values[VARS_NB], res; + char *expr; pad->hsub = pix_desc->log2_chroma_w; pad->vsub = pix_desc->log2_chroma_h; + var_values[VAR_PI] = M_PI; + var_values[VAR_PHI] = M_PHI; + var_values[VAR_E] = M_E; + var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; + var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; + var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; + var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; + var_values[VAR_A] = (float) inlink->w / inlink->h; + var_values[VAR_HSUB] = 1<hsub; + var_values[VAR_VSUB] = 2<vsub; + + /* evaluate width and height */ + av_expr_parse_and_eval(&res, (expr = pad->w_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx); + pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; + if ((ret = av_expr_parse_and_eval(&res, (expr = pad->h_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) + goto eval_fail; + pad->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; + /* evaluate the width again, as it may depend on the evaluated output height */ + if ((ret = av_expr_parse_and_eval(&res, (expr = pad->w_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) + goto eval_fail; + pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; + + /* evaluate x and y */ + av_expr_parse_and_eval(&res, (expr = pad->x_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx); + pad->x = var_values[VAR_X] = res; + if ((ret = av_expr_parse_and_eval(&res, (expr = pad->y_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) + goto eval_fail; + pad->y = var_values[VAR_Y] = res; + /* evaluate x again, as it may depend on the evaluated y value */ + if ((ret = av_expr_parse_and_eval(&res, (expr = pad->x_expr), + var_names, var_values, + NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) + goto eval_fail; + pad->x = var_values[VAR_X] = res; + + /* sanity check params */ + if (pad->w < 0 || pad->h < 0 || pad->x < 0 || pad->y < 0) { + av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n"); + return AVERROR(EINVAL); + } + if (!pad->w) pad->w = inlink->w; if (!pad->h) @@ -140,6 +232,12 @@ static int config_input(AVFilterLink *inlink) } return 0; + +eval_fail: + av_log(NULL, AV_LOG_ERROR, + "Error when evaluating the expression '%s'\n", expr); + return ret; + } static int config_output(AVFilterLink *outlink) -- cgit v1.2.3 From e7021c0ed5d1265d5b4f0f01a01f840196a70415 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Apr 2011 20:51:40 +0200 Subject: lavc: remove FF_API_HURRY_UP cruft --- libavcodec/avcodec.h | 10 ---------- libavcodec/h261dec.c | 4 ---- libavcodec/h263dec.c | 8 -------- libavcodec/h264.c | 18 ++---------------- libavcodec/mpeg12.c | 8 -------- libavcodec/mpegvideo.c | 6 ------ libavcodec/mpegvideo.h | 5 ----- libavcodec/options.c | 3 --- libavcodec/pthread.c | 3 --- libavcodec/rv34.c | 9 --------- libavcodec/svq1dec.c | 3 --- libavcodec/svq3.c | 8 -------- libavcodec/vc1dec.c | 10 ---------- libavcodec/version.h | 3 --- 14 files changed, 2 insertions(+), 96 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index ec31f666d1..c0f842ec7c 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1314,16 +1314,6 @@ typedef struct AVCodecContext { int b_frame_strategy; -#if FF_API_HURRY_UP - /** - * hurry up amount - * - encoding: unused - * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header - * @deprecated Deprecated in favor of skip_idct and skip_frame. - */ - attribute_deprecated int hurry_up; -#endif - struct AVCodec *codec; void *priv_data; diff --git a/libavcodec/h261dec.c b/libavcodec/h261dec.c index 93c5cb402d..a5ede3e691 100644 --- a/libavcodec/h261dec.c +++ b/libavcodec/h261dec.c @@ -599,10 +599,6 @@ retry: s->current_picture.pict_type= s->pict_type; s->current_picture.key_frame= s->pict_type == FF_I_TYPE; -#if FF_API_HURRY_UP - /* skip everything if we are in a hurry>=5 */ - if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); -#endif if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 86ad0bad18..afc7c9035a 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -597,18 +597,10 @@ retry: /* skip B-frames if we don't have reference frames */ if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)) return get_consumed_bytes(s, buf_size); -#if FF_API_HURRY_UP - /* skip b frames if we are in a hurry */ - if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return get_consumed_bytes(s, buf_size); -#endif if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) return get_consumed_bytes(s, buf_size); -#if FF_API_HURRY_UP - /* skip everything if we are in a hurry>=5 */ - if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); -#endif if(s->next_p_frame_damaged){ if(s->pict_type==FF_B_TYPE) diff --git a/libavcodec/h264.c b/libavcodec/h264.c index cd7dccc172..264afe5b4e 100644 --- a/libavcodec/h264.c +++ b/libavcodec/h264.c @@ -2821,11 +2821,7 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ buf_index += consumed; //FIXME do not discard SEI id - if( -#if FF_API_HURRY_UP - (s->hurry_up == 1 && h->nal_ref_idc == 0) || -#endif - (avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) + if(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0) continue; again: @@ -2857,9 +2853,6 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ (hx->nal_unit_type == NAL_IDR_SLICE) || (h->sei_recovery_frame_cnt >= 0); if(hx->redundant_pic_count==0 -#if FF_API_HURRY_UP - && hx->s.hurry_up < 5 -#endif && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE) && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE) @@ -2897,9 +2890,6 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning && s->context_initialized -#if FF_API_HURRY_UP - && s->hurry_up < 5 -#endif && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE) && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE) @@ -3020,11 +3010,7 @@ static int decode_frame(AVCodecContext *avctx, } if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){ - if (avctx->skip_frame >= AVDISCARD_NONREF -#if FF_API_HURRY_UP - || s->hurry_up -#endif - ) + if (avctx->skip_frame >= AVDISCARD_NONREF) return 0; av_log(avctx, AV_LOG_ERROR, "no frame!\n"); return -1; diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 0676f18157..02d3e6602a 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -2398,18 +2398,10 @@ static int decode_chunks(AVCodecContext *avctx, /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ if(s2->pict_type==FF_P_TYPE && !s->sync) break; } -#if FF_API_HURRY_UP - /* Skip B-frames if we are in a hurry. */ - if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; -#endif if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) break; -#if FF_API_HURRY_UP - /* Skip everything if we are in a hurry>=5. */ - if(avctx->hurry_up>=5) break; -#endif if (!s->mpeg_enc_ctx_allocated) break; diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index b6cc459631..c48b30ff2b 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1025,9 +1025,6 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) } } -#if FF_API_HURRY_UP - s->hurry_up= s->avctx->hurry_up; -#endif s->error_recognition= avctx->error_recognition; /* set dequantizer, we can't do it during init as it might change for mpeg4 @@ -1964,9 +1961,6 @@ void MPV_decode_mb_internal(MpegEncContext *s, DCTELEM block[12][64], } /* skip dequant / idct if we are really late ;) */ -#if FF_API_HURRY_UP - if(s->hurry_up>1) goto skip_idct; -#endif if(s->avctx->skip_idct){ if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE) ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 0ff08d2eb6..8ea7a5b798 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -387,11 +387,6 @@ typedef struct MpegEncContext { int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0 */ -#if FF_API_HURRY_UP - int hurry_up; /**< when set to 1 during decoding, b frames will be skipped - when set to 2 idct/dequant will be skipped too */ -#endif - /* macroblock layer */ int mb_x, mb_y; int mb_skip_run; diff --git a/libavcodec/options.c b/libavcodec/options.c index 9a9ed7bf34..5d7534921e 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -124,9 +124,6 @@ static const AVOption options[]={ {"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E}, {"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E}, -#if FF_API_HURRY_UP -{"hurry_up", "deprecated, use skip_idct/skip_frame instead", OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D}, -#endif {"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, {"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 0311dcd7e9..0de876087b 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -380,9 +380,6 @@ static void update_context_from_user(AVCodecContext *dst, AVCodecContext *src) dst->release_buffer = src->release_buffer; dst->opaque = src->opaque; -#if FF_API_HURRY_UP - dst->hurry_up = src->hurry_up; -#endif dst->dsp_mask = src->dsp_mask; dst->debug = src->debug; dst->debug_mv = src->debug_mv; diff --git a/libavcodec/rv34.c b/libavcodec/rv34.c index 8122b66087..30dbcf821f 100644 --- a/libavcodec/rv34.c +++ b/libavcodec/rv34.c @@ -1454,19 +1454,10 @@ int ff_rv34_decode_frame(AVCodecContext *avctx, } if((!s->last_picture_ptr || !s->last_picture_ptr->data[0]) && si.type == FF_B_TYPE) return -1; -#if FF_API_HURRY_UP - /* skip b frames if we are in a hurry */ - if(avctx->hurry_up && si.type==FF_B_TYPE) return buf_size; -#endif if( (avctx->skip_frame >= AVDISCARD_NONREF && si.type==FF_B_TYPE) || (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) return buf_size; -#if FF_API_HURRY_UP - /* skip everything if we are in a hurry>=5 */ - if(avctx->hurry_up>=5) - return buf_size; -#endif for(i=0; ipict_type==FF_B_TYPE && s->last_picture_ptr==NULL) return buf_size; -#if FF_API_HURRY_UP - if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return buf_size; -#endif if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 50c5d22fe4..827a408d31 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -952,14 +952,6 @@ static int svq3_decode_frame(AVCodecContext *avctx, /* Skip B-frames if we do not have reference frames. */ if (s->last_picture_ptr == NULL && s->pict_type == FF_B_TYPE) return 0; -#if FF_API_HURRY_UP - /* Skip B-frames if we are in a hurry. */ - if (avctx->hurry_up && s->pict_type == FF_B_TYPE) - return 0; - /* Skip everything if we are in a hurry >= 5. */ - if (avctx->hurry_up >= 5) - return 0; -#endif if ( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE) ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) diff --git a/libavcodec/vc1dec.c b/libavcodec/vc1dec.c index 6e73317451..28f77c0d80 100644 --- a/libavcodec/vc1dec.c +++ b/libavcodec/vc1dec.c @@ -3510,21 +3510,11 @@ static int vc1_decode_frame(AVCodecContext *avctx, if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)){ goto err; } -#if FF_API_HURRY_UP - /* skip b frames if we are in a hurry */ - if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return -1;//buf_size; -#endif if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) || avctx->skip_frame >= AVDISCARD_ALL) { goto end; } -#if FF_API_HURRY_UP - /* skip everything if we are in a hurry>=5 */ - if(avctx->hurry_up>=5) { - goto err; - } -#endif if(s->next_p_frame_damaged){ if(s->pict_type==FF_B_TYPE) diff --git a/libavcodec/version.h b/libavcodec/version.h index 487e7a5136..fee57b1815 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -47,9 +47,6 @@ #ifndef FF_API_OLD_AUDIOCONVERT #define FF_API_OLD_AUDIOCONVERT (LIBAVCODEC_VERSION_MAJOR < 54) #endif -#ifndef FF_API_HURRY_UP -#define FF_API_HURRY_UP (LIBAVCODEC_VERSION_MAJOR < 53) -#endif #ifndef FF_API_RATE_EMU #define FF_API_RATE_EMU (LIBAVCODEC_VERSION_MAJOR < 53) #endif -- cgit v1.2.3 From 694c142434f1b775c93cb2586eebf7ddd5ef6aa8 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Apr 2011 20:53:21 +0200 Subject: lavc: remove FF_API_RATE_EMU cruft --- libavcodec/avcodec.h | 10 ---------- libavcodec/options.c | 3 --- libavcodec/version.h | 3 --- 3 files changed, 16 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index c0f842ec7c..e8578a9327 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1203,16 +1203,6 @@ typedef struct AVCodecContext { */ enum PixelFormat pix_fmt; -#if FF_API_RATE_EMU - /** - * Frame rate emulation. If not zero, the lower layer (i.e. format handler) - * has to read frames at native frame rate. - * - encoding: Set by user. - * - decoding: unused - */ - attribute_deprecated int rate_emu; -#endif - /** * If non NULL, 'draw_horiz_band' is called by the libavcodec * decoder to draw a horizontal band. It improves cache usage. Not diff --git a/libavcodec/options.c b/libavcodec/options.c index 5d7534921e..d664d41aa8 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -105,9 +105,6 @@ static const AVOption options[]={ {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX}, {"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E}, -#if FF_API_RATE_EMU -{"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, -#endif {"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, {"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E}, diff --git a/libavcodec/version.h b/libavcodec/version.h index fee57b1815..90402ffff7 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -47,9 +47,6 @@ #ifndef FF_API_OLD_AUDIOCONVERT #define FF_API_OLD_AUDIOCONVERT (LIBAVCODEC_VERSION_MAJOR < 54) #endif -#ifndef FF_API_RATE_EMU -#define FF_API_RATE_EMU (LIBAVCODEC_VERSION_MAJOR < 53) -#endif #ifndef FF_API_MB_Q #define FF_API_MB_Q (LIBAVCODEC_VERSION_MAJOR < 53) #endif -- cgit v1.2.3 From 6deae83e555982d86ef8cc68b804495092216fc4 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 12 Apr 2011 20:54:16 +0200 Subject: lavc: remove FF_API_MB_Q cruft --- libavcodec/avcodec.h | 16 ---------------- libavcodec/options.c | 4 ---- libavcodec/version.h | 3 --- 3 files changed, 23 deletions(-) diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index e8578a9327..91edaf0d51 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1768,22 +1768,6 @@ typedef struct AVCodecContext { */ uint64_t error[4]; -#if FF_API_MB_Q - /** - * minimum MB quantizer - * - encoding: unused - * - decoding: unused - */ - attribute_deprecated int mb_qmin; - - /** - * maximum MB quantizer - * - encoding: unused - * - decoding: unused - */ - attribute_deprecated int mb_qmax; -#endif - /** * motion estimation comparison function * - encoding: Set by user. diff --git a/libavcodec/options.c b/libavcodec/options.c index d664d41aa8..2f44185f36 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -247,10 +247,6 @@ static const AVOption options[]={ {"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"}, {"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"}, {"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"}, -#if FF_API_MB_Q -{"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, -{"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, -#endif {"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, {"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, {"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, diff --git a/libavcodec/version.h b/libavcodec/version.h index 90402ffff7..d384d54a24 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -47,9 +47,6 @@ #ifndef FF_API_OLD_AUDIOCONVERT #define FF_API_OLD_AUDIOCONVERT (LIBAVCODEC_VERSION_MAJOR < 54) #endif -#ifndef FF_API_MB_Q -#define FF_API_MB_Q (LIBAVCODEC_VERSION_MAJOR < 53) -#endif #ifndef FF_API_ANTIALIAS_ALGO #define FF_API_ANTIALIAS_ALGO (LIBAVCODEC_VERSION_MAJOR < 54) #endif -- cgit v1.2.3 From 30fe9719344f01a147628e07a8e79a9ccc7e0835 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 23 Apr 2011 10:44:21 +0200 Subject: aac: add headers needed for log2f() Signed-off-by: Anton Khirnov --- libavcodec/aaccoder.c | 1 + libavcodec/aacsbr.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index e7f8cb0ed3..bc59ac5052 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -36,6 +36,7 @@ #include "aac.h" #include "aacenc.h" #include "aactab.h" +#include "libavutil/libm.h" /** bits needed to code codebook run value for long windows */ static const uint8_t run_value_bits_long[64] = { diff --git a/libavcodec/aacsbr.c b/libavcodec/aacsbr.c index 0df52490a4..7a217abfda 100644 --- a/libavcodec/aacsbr.c +++ b/libavcodec/aacsbr.c @@ -32,6 +32,7 @@ #include "aacsbrdata.h" #include "fft.h" #include "aacps.h" +#include "libavutil/libm.h" #include #include -- cgit v1.2.3 From bebe72f4a05d338e04ae9ca1e9c6b72749b488aa Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 23 Apr 2011 13:38:50 +0200 Subject: lavc: deprecate FF_*_TYPE macros in favor of AV_PICTURE_TYPE_* enums Also deprecate av_get_pict_type_char() in favor of av_get_picture_type_char(). The new enum and av_get_picture_type_char() are defined in libavutil. This allows the use in libavfilter without the need to link against libavcodec. Signed-off-by: Stefano Sabatini Signed-off-by: Anton Khirnov --- doc/APIchanges | 5 +++++ libavcodec/avcodec.h | 24 +++++++++++++++--------- libavcodec/utils.c | 13 +++---------- libavcodec/version.h | 5 ++++- libavfilter/avfilter.h | 4 ++-- libavutil/avutil.h | 21 ++++++++++++++++++++- libavutil/utils.c | 14 ++++++++++++++ 7 files changed, 63 insertions(+), 23 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 3c20e91b4c..1e29aebad4 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,11 @@ libavutil: 2011-04-18 API changes, most recent first: +2011-04-XX - XXXXXXX - lavu 51.1.0 - avutil.h + Add AVPictureType enum and av_get_picture_type_char(), deprecate + FF_*_TYPE defines and av_get_pict_type_char() defined in + libavcodec/avcodec.h. + 2011-04-xx - xxxxxx - lavfi 2.3.0 - avfilter.h Add pict_type and key_frame fields to AVFilterBufferRefVideo. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 91edaf0d51..eb5c5b3b64 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -762,7 +762,7 @@ typedef struct AVPanScan{ * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ * - decoding: Set by libavcodec.\ */\ - int pict_type;\ + enum AVPictureType pict_type;\ \ /**\ * presentation timestamp in time_base units (time when frame should be shown to user)\ @@ -1004,14 +1004,16 @@ typedef struct AVPanScan{ #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared. #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything. - -#define FF_I_TYPE 1 ///< Intra -#define FF_P_TYPE 2 ///< Predicted -#define FF_B_TYPE 3 ///< Bi-dir predicted -#define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4 -#define FF_SI_TYPE 5 ///< Switching Intra -#define FF_SP_TYPE 6 ///< Switching Predicted -#define FF_BI_TYPE 7 +#if FF_API_OLD_FF_PICT_TYPES +/* DEPRECATED, directly use the AV_PICTURE_TYPE_* enum values */ +#define FF_I_TYPE AV_PICTURE_TYPE_I ///< Intra +#define FF_P_TYPE AV_PICTURE_TYPE_P ///< Predicted +#define FF_B_TYPE AV_PICTURE_TYPE_B ///< Bi-dir predicted +#define FF_S_TYPE AV_PICTURE_TYPE_S ///< S(GMC)-VOP MPEG4 +#define FF_SI_TYPE AV_PICTURE_TYPE_SI ///< Switching Intra +#define FF_SP_TYPE AV_PICTURE_TYPE_SP ///< Switching Predicted +#define FF_BI_TYPE AV_PICTURE_TYPE_BI +#endif #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore). #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer. @@ -3766,13 +3768,17 @@ void avcodec_default_free_buffers(AVCodecContext *s); /* misc useful functions */ +#if FF_API_OLD_FF_PICT_TYPES /** * Return a single letter to describe the given picture type pict_type. * * @param[in] pict_type the picture type * @return A single character representing the picture type. + * @deprecated Use av_get_picture_type_char() instead. */ +attribute_deprecated char av_get_pict_type_char(int pict_type); +#endif /** * Return codec bits per sample. diff --git a/libavcodec/utils.c b/libavcodec/utils.c index d60e236952..7e2847afb1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1030,18 +1030,11 @@ void avcodec_default_free_buffers(AVCodecContext *s){ s->internal_buffer_count=0; } +#if FF_API_OLD_FF_PICT_TYPES char av_get_pict_type_char(int pict_type){ - switch(pict_type){ - case FF_I_TYPE: return 'I'; - case FF_P_TYPE: return 'P'; - case FF_B_TYPE: return 'B'; - case FF_S_TYPE: return 'S'; - case FF_SI_TYPE:return 'i'; - case FF_SP_TYPE:return 'p'; - case FF_BI_TYPE:return 'b'; - default: return '?'; - } + return av_get_picture_type_char(pict_type); } +#endif int av_get_bits_per_sample(enum CodecID codec_id){ switch(codec_id){ diff --git a/libavcodec/version.h b/libavcodec/version.h index d384d54a24..418e2756b9 100644 --- a/libavcodec/version.h +++ b/libavcodec/version.h @@ -22,7 +22,7 @@ #define LIBAVCODEC_VERSION_MAJOR 53 #define LIBAVCODEC_VERSION_MINOR 1 -#define LIBAVCODEC_VERSION_MICRO 0 +#define LIBAVCODEC_VERSION_MICRO 1 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ LIBAVCODEC_VERSION_MINOR, \ @@ -59,5 +59,8 @@ #ifndef FF_API_THREAD_INIT #define FF_API_THREAD_INIT (LIBAVCODEC_VERSION_MAJOR < 54) #endif +#ifndef FF_API_OLD_FF_PICT_TYPES +#define FF_API_OLD_FF_PICT_TYPES (LIBAVCODEC_VERSION_MAJOR < 54) +#endif #endif /* AVCODEC_VERSION_H */ diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index cbc0238aa3..8947baadbe 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -27,7 +27,7 @@ #define LIBAVFILTER_VERSION_MAJOR 2 #define LIBAVFILTER_VERSION_MINOR 3 -#define LIBAVFILTER_VERSION_MICRO 0 +#define LIBAVFILTER_VERSION_MICRO 1 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ LIBAVFILTER_VERSION_MINOR, \ @@ -115,7 +115,7 @@ typedef struct AVFilterBufferRefVideoProps { AVRational pixel_aspect; ///< pixel aspect ratio int interlaced; ///< is frame interlaced int top_field_first; ///< field order - int pict_type; ///< Picture type of the frame + enum AVPictureType pict_type; ///< picture type of the frame int key_frame; ///< 1 -> keyframe, 0-> not } AVFilterBufferRefVideoProps; diff --git a/libavutil/avutil.h b/libavutil/avutil.h index abbdd0642a..43f0815fd2 100644 --- a/libavutil/avutil.h +++ b/libavutil/avutil.h @@ -40,7 +40,7 @@ #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) #define LIBAVUTIL_VERSION_MAJOR 51 -#define LIBAVUTIL_VERSION_MINOR 0 +#define LIBAVUTIL_VERSION_MINOR 1 #define LIBAVUTIL_VERSION_MICRO 0 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ @@ -94,6 +94,25 @@ enum AVMediaType { #define AV_TIME_BASE 1000000 #define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE} +enum AVPictureType { + AV_PICTURE_TYPE_I = 1, ///< Intra + AV_PICTURE_TYPE_P, ///< Predicted + AV_PICTURE_TYPE_B, ///< Bi-dir predicted + AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG4 + AV_PICTURE_TYPE_SI, ///< Switching Intra + AV_PICTURE_TYPE_SP, ///< Switching Predicted + AV_PICTURE_TYPE_BI, ///< BI type +}; + +/** + * Return a single letter to describe the given picture type + * pict_type. + * + * @param[in] pict_type the picture type @return a single character + * representing the picture type, '?' if pict_type is unknown + */ +char av_get_picture_type_char(enum AVPictureType pict_type); + #include "common.h" #include "error.h" #include "mathematics.h" diff --git a/libavutil/utils.c b/libavutil/utils.c index 042e735631..9b18c97908 100644 --- a/libavutil/utils.c +++ b/libavutil/utils.c @@ -39,3 +39,17 @@ const char *avutil_license(void) #define LICENSE_PREFIX "libavutil license: " return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1; } + +char av_get_picture_type_char(enum AVPictureType pict_type) +{ + switch (pict_type) { + case AV_PICTURE_TYPE_I: return 'I'; + case AV_PICTURE_TYPE_P: return 'P'; + case AV_PICTURE_TYPE_B: return 'B'; + case AV_PICTURE_TYPE_S: return 'S'; + case AV_PICTURE_TYPE_SI: return 'i'; + case AV_PICTURE_TYPE_SP: return 'p'; + case AV_PICTURE_TYPE_BI: return 'b'; + default: return '?'; + } +} -- cgit v1.2.3 From 893722ceeb709fcb301a87f07b952d30633bcb06 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 26 Apr 2011 08:51:54 +0200 Subject: APIChanges: update commit hashes for recent additions. --- doc/APIchanges | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 1e29aebad4..87ea7eb83d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,15 +13,15 @@ libavutil: 2011-04-18 API changes, most recent first: -2011-04-XX - XXXXXXX - lavu 51.1.0 - avutil.h +2011-04-XX - bebe72f - lavu 51.1.0 - avutil.h Add AVPictureType enum and av_get_picture_type_char(), deprecate FF_*_TYPE defines and av_get_pict_type_char() defined in libavcodec/avcodec.h. -2011-04-xx - xxxxxx - lavfi 2.3.0 - avfilter.h +2011-04-xx - 10d3940 - lavfi 2.3.0 - avfilter.h Add pict_type and key_frame fields to AVFilterBufferRefVideo. -2011-04-xx - xxxxxx - lavfi 2.2.0 - vsrc_buffer +2011-04-xx - 7a11c82 - lavfi 2.2.0 - vsrc_buffer Add sample_aspect_ratio fields to vsrc_buffer arguments 2011-04-21 - 94f7451 - lavc 53.1.0 - avcodec.h -- cgit v1.2.3 From 4bc282322ba1c03ed98737740f6b5e17b604ffa1 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Sat, 9 Apr 2011 13:49:49 +0200 Subject: documentation: extend documentation for ffmpeg -aspect option Signed-off-by: Anton Khirnov --- doc/ffmpeg.texi | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/ffmpeg.texi b/doc/ffmpeg.texi index 0d12f65f02..cabf395582 100644 --- a/doc/ffmpeg.texi +++ b/doc/ffmpeg.texi @@ -230,7 +230,13 @@ The following abbreviations are recognized: @end table @item -aspect @var{aspect} -Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777). +Set the video display aspect ratio specified by @var{aspect}. + +@var{aspect} can be a floating point number string, or a string of the +form @var{num}:@var{den}, where @var{num} and @var{den} are the +numerator and denominator of the aspect ratio. For example "4:3", +"16:9", "1.3333", and "1.7777" are valid argument values. + @item -croptop @var{size} @item -cropbottom @var{size} @item -cropleft @var{size} -- cgit v1.2.3 From 76cd98b445c5a1608e9a5974bef0b0be6b35f1ce Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Thu, 21 Apr 2011 22:03:24 +0200 Subject: mjpeg: Detect overreads in mjpeg_decode_scan() and error out. Signed-off-by: Michael Niedermayer Signed-off-by: Ronald S. Bultje --- libavcodec/mjpegdec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 6f29e466eb..fa2c505837 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -826,6 +826,10 @@ static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, i if (s->restart_interval && !s->restart_count) s->restart_count = s->restart_interval; + if(get_bits_count(&s->gb)>s->gb.size_in_bits){ + av_log(s->avctx, AV_LOG_ERROR, "overread %d\n", get_bits_count(&s->gb) - s->gb.size_in_bits); + return -1; + } for(i=0;i Date: Sat, 23 Apr 2011 19:24:06 +0200 Subject: Update x86inc.asm from x264 to allow AVX emulation using SSE and MMX. Signed-off-by: Reinhard Tartler --- libavcodec/x86/x86inc.asm | 249 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 248 insertions(+), 1 deletion(-) diff --git a/libavcodec/x86/x86inc.asm b/libavcodec/x86/x86inc.asm index b7d17742e4..53091c14c9 100644 --- a/libavcodec/x86/x86inc.asm +++ b/libavcodec/x86/x86inc.asm @@ -1,10 +1,11 @@ ;***************************************************************************** ;* x86inc.asm ;***************************************************************************** -;* Copyright (C) 2005-2008 x264 project +;* Copyright (C) 2005-2011 x264 project ;* ;* Authors: Loren Merritt ;* Anton Mitrofanov +;* Jason Garrett-Glaser ;* ;* Permission to use, copy, modify, and/or distribute this software for any ;* purpose with or without fee is hereby granted, provided that the above @@ -499,6 +500,7 @@ SECTION .note.GNU-stack noalloc noexec nowrite progbits %endmacro %macro INIT_MMX 0 + %assign avx_enabled 0 %define RESET_MM_PERMUTATION INIT_MMX %define mmsize 8 %define num_mmregs 8 @@ -520,6 +522,7 @@ SECTION .note.GNU-stack noalloc noexec nowrite progbits %endmacro %macro INIT_XMM 0 + %assign avx_enabled 0 %define RESET_MM_PERMUTATION INIT_XMM %define mmsize 16 %define num_mmregs 8 @@ -538,6 +541,31 @@ SECTION .note.GNU-stack noalloc noexec nowrite progbits %endrep %endmacro +%macro INIT_AVX 0 + INIT_XMM + %assign avx_enabled 1 + %define PALIGNR PALIGNR_SSSE3 + %define RESET_MM_PERMUTATION INIT_AVX +%endmacro + +%macro INIT_YMM 0 + %assign avx_enabled 1 + %define RESET_MM_PERMUTATION INIT_YMM + %define mmsize 32 + %define num_mmregs 8 + %ifdef ARCH_X86_64 + %define num_mmregs 16 + %endif + %define mova vmovaps + %define movu vmovups + %assign %%i 0 + %rep num_mmregs + CAT_XDEFINE m, %%i, ymm %+ %%i + CAT_XDEFINE nymm, %%i, %%i + %assign %%i %%i+1 + %endrep +%endmacro + INIT_MMX ; I often want to use macros that permute their arguments. e.g. there's no @@ -645,3 +673,222 @@ INIT_MMX sub %1, %2 %endif %endmacro + +;============================================================================= +; AVX abstraction layer +;============================================================================= + +%assign i 0 +%rep 16 + %if i < 8 + CAT_XDEFINE sizeofmm, i, 8 + %endif + CAT_XDEFINE sizeofxmm, i, 16 + CAT_XDEFINE sizeofymm, i, 32 +%assign i i+1 +%endrep +%undef i + +;%1 == instruction +;%2 == 1 if float, 0 if int +;%3 == 0 if 3-operand (xmm, xmm, xmm), 1 if 4-operand (xmm, xmm, xmm, imm) +;%4 == number of operands given +;%5+: operands +%macro RUN_AVX_INSTR 6-7+ + %if sizeof%5==32 + v%1 %5, %6, %7 + %else + %if sizeof%5==8 + %define %%regmov movq + %elif %2 + %define %%regmov movaps + %else + %define %%regmov movdqa + %endif + + %if %4>=3+%3 + %ifnidn %5, %6 + %if avx_enabled && sizeof%5==16 + v%1 %5, %6, %7 + %else + %%regmov %5, %6 + %1 %5, %7 + %endif + %else + %1 %5, %7 + %endif + %elif %3 + %1 %5, %6, %7 + %else + %1 %5, %6 + %endif + %endif +%endmacro + +;%1 == instruction +;%2 == 1 if float, 0 if int +;%3 == 0 if 3-operand (xmm, xmm, xmm), 1 if 4-operand (xmm, xmm, xmm, imm) +%macro AVX_INSTR 3 + %macro %1 2-8 fnord, fnord, fnord, %1, %2, %3 + %ifidn %3, fnord + RUN_AVX_INSTR %6, %7, %8, 2, %1, %2 + %elifidn %4, fnord + RUN_AVX_INSTR %6, %7, %8, 3, %1, %2, %3 + %elifidn %5, fnord + RUN_AVX_INSTR %6, %7, %8, 4, %1, %2, %3, %4 + %else + RUN_AVX_INSTR %6, %7, %8, 5, %1, %2, %3, %4, %5 + %endif + %endmacro +%endmacro + +AVX_INSTR addpd, 1, 0 +AVX_INSTR addps, 1, 0 +AVX_INSTR addsd, 1, 0 +AVX_INSTR addss, 1, 0 +AVX_INSTR addsubpd, 1, 0 +AVX_INSTR addsubps, 1, 0 +AVX_INSTR andpd, 1, 0 +AVX_INSTR andps, 1, 0 +AVX_INSTR andnpd, 1, 0 +AVX_INSTR andnps, 1, 0 +AVX_INSTR blendpd, 1, 0 +AVX_INSTR blendps, 1, 0 +AVX_INSTR blendvpd, 1, 0 +AVX_INSTR blendvps, 1, 0 +AVX_INSTR cmppd, 1, 0 +AVX_INSTR cmpps, 1, 0 +AVX_INSTR cmpsd, 1, 0 +AVX_INSTR cmpss, 1, 0 +AVX_INSTR divpd, 1, 0 +AVX_INSTR divps, 1, 0 +AVX_INSTR divsd, 1, 0 +AVX_INSTR divss, 1, 0 +AVX_INSTR dppd, 1, 0 +AVX_INSTR dpps, 1, 0 +AVX_INSTR haddpd, 1, 0 +AVX_INSTR haddps, 1, 0 +AVX_INSTR hsubpd, 1, 0 +AVX_INSTR hsubps, 1, 0 +AVX_INSTR maxpd, 1, 0 +AVX_INSTR maxps, 1, 0 +AVX_INSTR maxsd, 1, 0 +AVX_INSTR maxss, 1, 0 +AVX_INSTR minpd, 1, 0 +AVX_INSTR minps, 1, 0 +AVX_INSTR minsd, 1, 0 +AVX_INSTR minss, 1, 0 +AVX_INSTR mpsadbw, 0, 1 +AVX_INSTR mulpd, 1, 0 +AVX_INSTR mulps, 1, 0 +AVX_INSTR mulsd, 1, 0 +AVX_INSTR mulss, 1, 0 +AVX_INSTR orpd, 1, 0 +AVX_INSTR orps, 1, 0 +AVX_INSTR packsswb, 0, 0 +AVX_INSTR packssdw, 0, 0 +AVX_INSTR packuswb, 0, 0 +AVX_INSTR packusdw, 0, 0 +AVX_INSTR paddb, 0, 0 +AVX_INSTR paddw, 0, 0 +AVX_INSTR paddd, 0, 0 +AVX_INSTR paddq, 0, 0 +AVX_INSTR paddsb, 0, 0 +AVX_INSTR paddsw, 0, 0 +AVX_INSTR paddusb, 0, 0 +AVX_INSTR paddusw, 0, 0 +AVX_INSTR palignr, 0, 1 +AVX_INSTR pand, 0, 0 +AVX_INSTR pandn, 0, 0 +AVX_INSTR pavgb, 0, 0 +AVX_INSTR pavgw, 0, 0 +AVX_INSTR pblendvb, 0, 0 +AVX_INSTR pblendw, 0, 1 +AVX_INSTR pcmpestri, 0, 0 +AVX_INSTR pcmpestrm, 0, 0 +AVX_INSTR pcmpistri, 0, 0 +AVX_INSTR pcmpistrm, 0, 0 +AVX_INSTR pcmpeqb, 0, 0 +AVX_INSTR pcmpeqw, 0, 0 +AVX_INSTR pcmpeqd, 0, 0 +AVX_INSTR pcmpeqq, 0, 0 +AVX_INSTR pcmpgtb, 0, 0 +AVX_INSTR pcmpgtw, 0, 0 +AVX_INSTR pcmpgtd, 0, 0 +AVX_INSTR pcmpgtq, 0, 0 +AVX_INSTR phaddw, 0, 0 +AVX_INSTR phaddd, 0, 0 +AVX_INSTR phaddsw, 0, 0 +AVX_INSTR phsubw, 0, 0 +AVX_INSTR phsubd, 0, 0 +AVX_INSTR phsubsw, 0, 0 +AVX_INSTR pmaddwd, 0, 0 +AVX_INSTR pmaddubsw, 0, 0 +AVX_INSTR pmaxsb, 0, 0 +AVX_INSTR pmaxsw, 0, 0 +AVX_INSTR pmaxsd, 0, 0 +AVX_INSTR pmaxub, 0, 0 +AVX_INSTR pmaxuw, 0, 0 +AVX_INSTR pmaxud, 0, 0 +AVX_INSTR pminsb, 0, 0 +AVX_INSTR pminsw, 0, 0 +AVX_INSTR pminsd, 0, 0 +AVX_INSTR pminub, 0, 0 +AVX_INSTR pminuw, 0, 0 +AVX_INSTR pminud, 0, 0 +AVX_INSTR pmulhuw, 0, 0 +AVX_INSTR pmulhrsw, 0, 0 +AVX_INSTR pmulhw, 0, 0 +AVX_INSTR pmullw, 0, 0 +AVX_INSTR pmulld, 0, 0 +AVX_INSTR pmuludq, 0, 0 +AVX_INSTR pmuldq, 0, 0 +AVX_INSTR por, 0, 0 +AVX_INSTR psadbw, 0, 0 +AVX_INSTR pshufb, 0, 0 +AVX_INSTR psignb, 0, 0 +AVX_INSTR psignw, 0, 0 +AVX_INSTR psignd, 0, 0 +AVX_INSTR psllw, 0, 0 +AVX_INSTR pslld, 0, 0 +AVX_INSTR psllq, 0, 0 +AVX_INSTR pslldq, 0, 0 +AVX_INSTR psraw, 0, 0 +AVX_INSTR psrad, 0, 0 +AVX_INSTR psrlw, 0, 0 +AVX_INSTR psrld, 0, 0 +AVX_INSTR psrlq, 0, 0 +AVX_INSTR psrldq, 0, 0 +AVX_INSTR psubb, 0, 0 +AVX_INSTR psubw, 0, 0 +AVX_INSTR psubd, 0, 0 +AVX_INSTR psubq, 0, 0 +AVX_INSTR psubsb, 0, 0 +AVX_INSTR psubsw, 0, 0 +AVX_INSTR psubusb, 0, 0 +AVX_INSTR psubusw, 0, 0 +AVX_INSTR punpckhbw, 0, 0 +AVX_INSTR punpckhwd, 0, 0 +AVX_INSTR punpckhdq, 0, 0 +AVX_INSTR punpckhqdq, 0, 0 +AVX_INSTR punpcklbw, 0, 0 +AVX_INSTR punpcklwd, 0, 0 +AVX_INSTR punpckldq, 0, 0 +AVX_INSTR punpcklqdq, 0, 0 +AVX_INSTR pxor, 0, 0 +AVX_INSTR shufps, 0, 1 +AVX_INSTR subpd, 1, 0 +AVX_INSTR subps, 1, 0 +AVX_INSTR subsd, 1, 0 +AVX_INSTR subss, 1, 0 +AVX_INSTR unpckhpd, 1, 0 +AVX_INSTR unpckhps, 1, 0 +AVX_INSTR unpcklpd, 1, 0 +AVX_INSTR unpcklps, 1, 0 +AVX_INSTR xorpd, 1, 0 +AVX_INSTR xorps, 1, 0 + +; 3DNow instructions, for sharing code between AVX, SSE and 3DN +AVX_INSTR pfadd, 1, 0 +AVX_INSTR pfsub, 1, 0 +AVX_INSTR pfmul, 1, 0 -- cgit v1.2.3 From 13dfce3d44f99a2d7df71aba8ae003d58db726f7 Mon Sep 17 00:00:00 2001 From: Vitor Sessak Date: Sat, 23 Apr 2011 19:24:31 +0200 Subject: Increase alignment of av_malloc() as needed by AVX ASM. Signed-off-by: Reinhard Tartler --- libavutil/mem.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/libavutil/mem.c b/libavutil/mem.c index 2aef9b0a1b..27bb30b8ef 100644 --- a/libavutil/mem.c +++ b/libavutil/mem.c @@ -69,21 +69,21 @@ void *av_malloc(size_t size) #endif /* let's disallow possible ambiguous cases */ - if(size > (INT_MAX-16) ) + if(size > (INT_MAX-32) ) return NULL; #if CONFIG_MEMALIGN_HACK - ptr = malloc(size+16); + ptr = malloc(size+32); if(!ptr) return ptr; - diff= ((-(long)ptr - 1)&15) + 1; + diff= ((-(long)ptr - 1)&31) + 1; ptr = (char*)ptr + diff; ((char*)ptr)[-1]= diff; #elif HAVE_POSIX_MEMALIGN - if (posix_memalign(&ptr,16,size)) + if (posix_memalign(&ptr,32,size)) ptr = NULL; #elif HAVE_MEMALIGN - ptr = memalign(16,size); + ptr = memalign(32,size); /* Why 64? Indeed, we should align it: on 4 for 386 @@ -93,10 +93,8 @@ void *av_malloc(size_t size) Because L1 and L2 caches are aligned on those values. But I don't want to code such logic here! */ - /* Why 16? - Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs - it will just trigger an exception and the unaligned load will be done in the - exception handler or it will just segfault (SSE2 on P4). + /* Why 32? + For AVX ASM. SSE / NEON needs only 16. Why not larger? Because I did not see a difference in benchmarks ... */ /* benchmarks with P3 -- cgit v1.2.3 From 9d35fa520e3b27f7dd9fe12c433eb596f1271515 Mon Sep 17 00:00:00 2001 From: Vitor Sessak Date: Mon, 25 Apr 2011 11:39:01 +0200 Subject: Add AVX FFT implementation. Signed-off-by: Reinhard Tartler --- Changelog | 2 +- libavcodec/aac.h | 10 +- libavcodec/aacenc.h | 2 +- libavcodec/ac3dec.h | 10 +- libavcodec/ac3enc.c | 2 +- libavcodec/atrac1.c | 20 +- libavcodec/atrac3.c | 6 +- libavcodec/binkaudio.c | 2 +- libavcodec/cook.c | 2 +- libavcodec/dca.c | 10 +- libavcodec/fft.c | 53 ++++- libavcodec/fft.h | 3 +- libavcodec/imc.c | 2 +- libavcodec/nellymoserdec.c | 4 +- libavcodec/nellymoserenc.c | 6 +- libavcodec/qdm2.c | 2 +- libavcodec/wma.h | 8 +- libavcodec/wmaprodec.c | 4 +- libavcodec/wmavoice.c | 6 +- libavcodec/x86/fft.c | 9 +- libavcodec/x86/fft.h | 2 + libavcodec/x86/fft_mmx.asm | 484 +++++++++++++++++++++++++++++++-------------- libavcodec/x86/fft_sse.c | 8 +- 23 files changed, 450 insertions(+), 207 deletions(-) diff --git a/Changelog b/Changelog index cfa87549f8..144f55c12f 100644 --- a/Changelog +++ b/Changelog @@ -5,7 +5,7 @@ releases are sorted from youngest to oldest. version : - Lots of deprecated API cruft removed - +- fft and imdct optimizations for AVX (Sandy Bridge) processors version 0.7_beta1: diff --git a/libavcodec/aac.h b/libavcodec/aac.h index e3385e21f8..bbe7912517 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -223,9 +223,9 @@ typedef struct { float sf[120]; ///< scalefactors int sf_idx[128]; ///< scalefactor indices (used by encoder) uint8_t zeroes[128]; ///< band is not coded (used by encoder) - DECLARE_ALIGNED(16, float, coeffs)[1024]; ///< coefficients for IMDCT - DECLARE_ALIGNED(16, float, saved)[1024]; ///< overlap - DECLARE_ALIGNED(16, float, ret)[2048]; ///< PCM output + DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT + DECLARE_ALIGNED(32, float, saved)[1024]; ///< overlap + DECLARE_ALIGNED(32, float, ret)[2048]; ///< PCM output DECLARE_ALIGNED(16, int16_t, ltp_state)[3072]; ///< time signal for LTP PredictorState predictor_state[MAX_PREDICTORS]; } SingleChannelElement; @@ -272,7 +272,7 @@ typedef struct { * @defgroup temporary aligned temporary buffers (We do not want to have these on the stack.) * @{ */ - DECLARE_ALIGNED(16, float, buf_mdct)[1024]; + DECLARE_ALIGNED(32, float, buf_mdct)[1024]; /** @} */ /** @@ -296,7 +296,7 @@ typedef struct { int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 /** @} */ - DECLARE_ALIGNED(16, float, temp)[128]; + DECLARE_ALIGNED(32, float, temp)[128]; enum OCStatus output_configured; } AACContext; diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h index 3d584d210e..7e08db24c0 100644 --- a/libavcodec/aacenc.h +++ b/libavcodec/aacenc.h @@ -64,7 +64,7 @@ typedef struct AACEncContext { int last_frame; float lambda; DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients - DECLARE_ALIGNED(16, float, scoefs)[1024]; ///< scaled coefficients + DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients } AACEncContext; #endif /* AVCODEC_AACENC_H */ diff --git a/libavcodec/ac3dec.h b/libavcodec/ac3dec.h index 3459441bbd..6cba95b495 100644 --- a/libavcodec/ac3dec.h +++ b/libavcodec/ac3dec.h @@ -200,11 +200,11 @@ typedef struct { ///@defgroup arrays aligned arrays DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///> fixed-point transform coefficients - DECLARE_ALIGNED(16, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients - DECLARE_ALIGNED(16, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block - DECLARE_ALIGNED(16, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients - DECLARE_ALIGNED(16, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing - DECLARE_ALIGNED(16, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing + DECLARE_ALIGNED(32, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients + DECLARE_ALIGNED(32, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block + DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients + DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing + DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing ///@} } AC3DecodeContext; diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 04e8b4fb0b..77647d40e1 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -201,7 +201,7 @@ typedef struct AC3EncodeContext { uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies - DECLARE_ALIGNED(16, SampleType, windowed_samples)[AC3_WINDOW_SIZE]; + DECLARE_ALIGNED(32, SampleType, windowed_samples)[AC3_WINDOW_SIZE]; } AC3EncodeContext; typedef struct AC3Mant { diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c index d6c7053d7b..0ba2cf6bdd 100644 --- a/libavcodec/atrac1.c +++ b/libavcodec/atrac1.c @@ -60,11 +60,11 @@ typedef struct { int log2_block_count[AT1_QMF_BANDS]; ///< log2 number of blocks in a band int num_bfus; ///< number of Block Floating Units float* spectrum[2]; - DECLARE_ALIGNED(16, float, spec1)[AT1_SU_SAMPLES]; ///< mdct buffer - DECLARE_ALIGNED(16, float, spec2)[AT1_SU_SAMPLES]; ///< mdct buffer - DECLARE_ALIGNED(16, float, fst_qmf_delay)[46]; ///< delay line for the 1st stacked QMF filter - DECLARE_ALIGNED(16, float, snd_qmf_delay)[46]; ///< delay line for the 2nd stacked QMF filter - DECLARE_ALIGNED(16, float, last_qmf_delay)[256+23]; ///< delay line for the last stacked QMF filter + DECLARE_ALIGNED(32, float, spec1)[AT1_SU_SAMPLES]; ///< mdct buffer + DECLARE_ALIGNED(32, float, spec2)[AT1_SU_SAMPLES]; ///< mdct buffer + DECLARE_ALIGNED(32, float, fst_qmf_delay)[46]; ///< delay line for the 1st stacked QMF filter + DECLARE_ALIGNED(32, float, snd_qmf_delay)[46]; ///< delay line for the 2nd stacked QMF filter + DECLARE_ALIGNED(32, float, last_qmf_delay)[256+23]; ///< delay line for the last stacked QMF filter } AT1SUCtx; /** @@ -72,13 +72,13 @@ typedef struct { */ typedef struct { AT1SUCtx SUs[AT1_MAX_CHANNELS]; ///< channel sound unit - DECLARE_ALIGNED(16, float, spec)[AT1_SU_SAMPLES]; ///< the mdct spectrum buffer + DECLARE_ALIGNED(32, float, spec)[AT1_SU_SAMPLES]; ///< the mdct spectrum buffer - DECLARE_ALIGNED(16, float, low)[256]; - DECLARE_ALIGNED(16, float, mid)[256]; - DECLARE_ALIGNED(16, float, high)[512]; + DECLARE_ALIGNED(32, float, low)[256]; + DECLARE_ALIGNED(32, float, mid)[256]; + DECLARE_ALIGNED(32, float, high)[512]; float* bands[3]; - DECLARE_ALIGNED(16, float, out_samples)[AT1_MAX_CHANNELS][AT1_SU_SAMPLES]; + DECLARE_ALIGNED(32, float, out_samples)[AT1_MAX_CHANNELS][AT1_SU_SAMPLES]; FFTContext mdct_ctx[3]; int channels; DSPContext dsp; diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 78df5f1fb3..accaae3d65 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -74,8 +74,8 @@ typedef struct { int gcBlkSwitch; gain_block gainBlock[2]; - DECLARE_ALIGNED(16, float, spectrum)[1024]; - DECLARE_ALIGNED(16, float, IMDCT_buf)[1024]; + DECLARE_ALIGNED(32, float, spectrum)[1024]; + DECLARE_ALIGNED(32, float, IMDCT_buf)[1024]; float delayBuf1[46]; ///= 16; + else if (i < n/2) + return is_second_half_of_fft32(i, n/2); + else if (i < 3*n/4) + return is_second_half_of_fft32(i - n/2, n/4); + else + return is_second_half_of_fft32(i - 3*n/4, n/4); +} + +static av_cold void fft_perm_avx(FFTContext *s) +{ + int i; + int n = 1 << s->nbits; + + for (i = 0; i < n; i += 16) { + int k; + if (is_second_half_of_fft32(i, n)) { + for (k = 0; k < 16; k++) + s->revtab[-split_radix_permutation(i + k, n, s->inverse) & (n - 1)] = + i + avx_tab[k]; + + } else { + for (k = 0; k < 16; k++) { + int j = i + k; + j = (j & ~7) | ((j >> 1) & 3) | ((j << 2) & 4); + s->revtab[-split_radix_permutation(i + k, n, s->inverse) & (n - 1)] = j; + } + } + } +} + av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) { int i, j, n; @@ -132,11 +170,16 @@ av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) for(j=4; j<=nbits; j++) { ff_init_ff_cos_tabs(j); } - for(i=0; ifft_permutation == FF_FFT_PERM_SWAP_LSBS) - j = (j&~3) | ((j>>1)&1) | ((j<<1)&2); - s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = j; + + if (s->fft_permutation == FF_FFT_PERM_AVX) { + fft_perm_avx(s); + } else { + for(i=0; ifft_permutation == FF_FFT_PERM_SWAP_LSBS) + j = (j&~3) | ((j>>1)&1) | ((j<<1)&2); + s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = j; + } } return 0; diff --git a/libavcodec/fft.h b/libavcodec/fft.h index a4fee0033b..dc3c1909b0 100644 --- a/libavcodec/fft.h +++ b/libavcodec/fft.h @@ -85,6 +85,7 @@ struct FFTContext { int fft_permutation; #define FF_FFT_PERM_DEFAULT 0 #define FF_FFT_PERM_SWAP_LSBS 1 +#define FF_FFT_PERM_AVX 2 int mdct_permutation; #define FF_MDCT_PERM_NONE 0 #define FF_MDCT_PERM_INTERLEAVE 1 @@ -97,7 +98,7 @@ struct FFTContext { #endif #define COSTABLE(size) \ - COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, FFT_NAME(ff_cos_##size))[size/2] + COSTABLE_CONST DECLARE_ALIGNED(32, FFTSample, FFT_NAME(ff_cos_##size))[size/2] extern COSTABLE(16); extern COSTABLE(32); diff --git a/libavcodec/imc.c b/libavcodec/imc.c index e48a7094ba..07d6cadcfd 100644 --- a/libavcodec/imc.c +++ b/libavcodec/imc.c @@ -88,7 +88,7 @@ typedef struct { DSPContext dsp; FFTContext fft; - DECLARE_ALIGNED(16, FFTComplex, samples)[COEFFS/2]; + DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS/2]; float *out_samples; } IMCContext; diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c index 5ad49abceb..59c1b3bdd8 100644 --- a/libavcodec/nellymoserdec.c +++ b/libavcodec/nellymoserdec.c @@ -47,7 +47,7 @@ typedef struct NellyMoserDecodeContext { AVCodecContext* avctx; - DECLARE_ALIGNED(16, float,float_buf)[NELLY_SAMPLES]; + DECLARE_ALIGNED(32, float, float_buf)[NELLY_SAMPLES]; float state[128]; AVLFG random_state; GetBitContext gb; @@ -55,7 +55,7 @@ typedef struct NellyMoserDecodeContext { DSPContext dsp; FFTContext imdct_ctx; FmtConvertContext fmt_conv; - DECLARE_ALIGNED(16, float,imdct_out)[NELLY_BUF_LEN * 2]; + DECLARE_ALIGNED(32, float, imdct_out)[NELLY_BUF_LEN * 2]; } NellyMoserDecodeContext; static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *audio, float *a_in) diff --git a/libavcodec/nellymoserenc.c b/libavcodec/nellymoserenc.c index 676e30670a..0f94e75c92 100644 --- a/libavcodec/nellymoserenc.c +++ b/libavcodec/nellymoserenc.c @@ -55,9 +55,9 @@ typedef struct NellyMoserEncodeContext { int have_saved; DSPContext dsp; FFTContext mdct_ctx; - DECLARE_ALIGNED(16, float, mdct_out)[NELLY_SAMPLES]; - DECLARE_ALIGNED(16, float, in_buff)[NELLY_SAMPLES]; - DECLARE_ALIGNED(16, float, buf)[2][3 * NELLY_BUF_LEN]; ///< sample buffer + DECLARE_ALIGNED(32, float, mdct_out)[NELLY_SAMPLES]; + DECLARE_ALIGNED(32, float, in_buff)[NELLY_SAMPLES]; + DECLARE_ALIGNED(32, float, buf)[2][3 * NELLY_BUF_LEN]; ///< sample buffer float (*opt )[NELLY_BANDS]; uint8_t (*path)[NELLY_BANDS]; } NellyMoserEncodeContext; diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c index 3ef712cc97..198f11f271 100644 --- a/libavcodec/qdm2.c +++ b/libavcodec/qdm2.c @@ -120,7 +120,7 @@ typedef struct { } FFTCoefficient; typedef struct { - DECLARE_ALIGNED(16, QDM2Complex, complex)[MPA_MAX_CHANNELS][256]; + DECLARE_ALIGNED(32, QDM2Complex, complex)[MPA_MAX_CHANNELS][256]; } QDM2FFT; /** diff --git a/libavcodec/wma.h b/libavcodec/wma.h index d12c55ce2a..f11d5507dc 100644 --- a/libavcodec/wma.h +++ b/libavcodec/wma.h @@ -113,15 +113,15 @@ typedef struct WMACodecContext { uint8_t ms_stereo; ///< true if mid/side stereo mode uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length - DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE]; + DECLARE_ALIGNED(32, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE]; float max_exponent[MAX_CHANNELS]; WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; - DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; - DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2]; + DECLARE_ALIGNED(32, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; + DECLARE_ALIGNED(32, FFTSample, output)[BLOCK_MAX_SIZE * 2]; FFTContext mdct_ctx[BLOCK_NB_SIZES]; float *windows[BLOCK_NB_SIZES]; /* output buffer for one frame and the last for IMDCT windowing */ - DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; + DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; /* last frame info */ uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ int last_bitoffset; diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index c9048a91d7..ab2cd5c596 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -145,7 +145,7 @@ typedef struct { uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block float* coeffs; ///< pointer to the subframe decode buffer uint16_t num_vec_coeffs; ///< number of vector coded coefficients - DECLARE_ALIGNED(16, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer + DECLARE_ALIGNED(32, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer } WMAProChannelCtx; /** @@ -170,7 +170,7 @@ typedef struct WMAProDecodeCtx { FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data PutBitContext pb; ///< context for filling the frame_data buffer FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]; ///< MDCT context per block size - DECLARE_ALIGNED(16, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer + DECLARE_ALIGNED(32, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer float* windows[WMAPRO_BLOCK_SIZES]; ///< windows for the different block sizes /* frame size dependent frame information (set during initialization) */ diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 33c34a0882..8dea30c9f1 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -275,11 +275,11 @@ typedef struct { ///< by postfilter float denoise_filter_cache[MAX_FRAMESIZE]; int denoise_filter_cache_size; ///< samples in #denoise_filter_cache - DECLARE_ALIGNED(16, float, tilted_lpcs_pf)[0x80]; + DECLARE_ALIGNED(32, float, tilted_lpcs_pf)[0x80]; ///< aligned buffer for LPC tilting - DECLARE_ALIGNED(16, float, denoise_coeffs_pf)[0x80]; + DECLARE_ALIGNED(32, float, denoise_coeffs_pf)[0x80]; ///< aligned buffer for denoise coefficients - DECLARE_ALIGNED(16, float, synth_filter_out_buf)[0x80 + MAX_LSPS_ALIGN16]; + DECLARE_ALIGNED(32, float, synth_filter_out_buf)[0x80 + MAX_LSPS_ALIGN16]; ///< aligned buffer for postfilter speech ///< synthesis /** diff --git a/libavcodec/x86/fft.c b/libavcodec/x86/fft.c index 2426a3df0f..b29412c1dc 100644 --- a/libavcodec/x86/fft.c +++ b/libavcodec/x86/fft.c @@ -25,7 +25,14 @@ av_cold void ff_fft_init_mmx(FFTContext *s) { #if HAVE_YASM int has_vectors = av_get_cpu_flags(); - if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) { + if (has_vectors & AV_CPU_FLAG_AVX && HAVE_AVX && s->nbits >= 5) { + /* AVX for SB */ + s->imdct_calc = ff_imdct_calc_sse; + s->imdct_half = ff_imdct_half_avx; + s->fft_permute = ff_fft_permute_sse; + s->fft_calc = ff_fft_calc_avx; + s->fft_permutation = FF_FFT_PERM_AVX; + } else if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) { /* SSE for P3/P4/K8 */ s->imdct_calc = ff_imdct_calc_sse; s->imdct_half = ff_imdct_half_sse; diff --git a/libavcodec/x86/fft.h b/libavcodec/x86/fft.h index 073d408350..e6eace235d 100644 --- a/libavcodec/x86/fft.h +++ b/libavcodec/x86/fft.h @@ -22,6 +22,7 @@ #include "libavcodec/fft.h" void ff_fft_permute_sse(FFTContext *s, FFTComplex *z); +void ff_fft_calc_avx(FFTContext *s, FFTComplex *z); void ff_fft_calc_sse(FFTContext *s, FFTComplex *z); void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z); void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z); @@ -32,6 +33,7 @@ void ff_imdct_calc_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input void ff_imdct_half_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input); void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input); void ff_imdct_half_sse(FFTContext *s, FFTSample *output, const FFTSample *input); +void ff_imdct_half_avx(FFTContext *s, FFTSample *output, const FFTSample *input); void ff_dct32_float_sse(FFTSample *out, const FFTSample *in); #endif diff --git a/libavcodec/x86/fft_mmx.asm b/libavcodec/x86/fft_mmx.asm index e3829b8c0c..bd79fc1423 100644 --- a/libavcodec/x86/fft_mmx.asm +++ b/libavcodec/x86/fft_mmx.asm @@ -1,6 +1,7 @@ ;****************************************************************************** ;* FFT transform with SSE/3DNow optimizations ;* Copyright (c) 2008 Loren Merritt +;* Copyright (c) 2011 Vitor Sessak ;* ;* This algorithm (though not any of the implementation details) is ;* based on libdjbfft by D. J. Bernstein. @@ -49,9 +50,21 @@ endstruc SECTION_RODATA %define M_SQRT1_2 0.70710678118654752440 -ps_root2: times 4 dd M_SQRT1_2 -ps_root2mppm: dd -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 -ps_p1p1m1p1: dd 0, 0, 1<<31, 0 +%define M_COS_PI_1_8 0.923879532511287 +%define M_COS_PI_3_8 0.38268343236509 + +align 32 +ps_cos16_1: dd 1.0, M_COS_PI_1_8, M_SQRT1_2, M_COS_PI_3_8, 1.0, M_COS_PI_1_8, M_SQRT1_2, M_COS_PI_3_8 +ps_cos16_2: dd 0, M_COS_PI_3_8, M_SQRT1_2, M_COS_PI_1_8, 0, -M_COS_PI_3_8, -M_SQRT1_2, -M_COS_PI_1_8 + +ps_root2: times 8 dd M_SQRT1_2 +ps_root2mppm: dd -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 +ps_p1p1m1p1: dd 0, 0, 1<<31, 0, 0, 0, 1<<31, 0 + +perm1: dd 0x00, 0x02, 0x03, 0x01, 0x03, 0x00, 0x02, 0x01 +perm2: dd 0x00, 0x01, 0x02, 0x03, 0x01, 0x00, 0x02, 0x03 +ps_p1p1m1p1root2: dd 1.0, 1.0, -1.0, 1.0, M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, M_SQRT1_2 +ps_m1m1p1m1p1m1m1m1: dd 1<<31, 1<<31, 0, 1<<31, 0, 1<<31, 1<<31, 1<<31 ps_m1p1: dd 1<<31, 0 %assign i 16 @@ -96,51 +109,80 @@ section .text align=16 SWAP %3, %6 %endmacro +; in: %1 = {r0,i0,r2,i2,r4,i4,r6,i6} +; %2 = {r1,i1,r3,i3,r5,i5,r7,i7} +; %3, %4, %5 tmp +; out: %1 = {r0,r1,r2,r3,i0,i1,i2,i3} +; %2 = {r4,r5,r6,r7,i4,i5,i6,i7} +%macro T8_AVX 5 + vsubps %5, %1, %2 ; v = %1 - %2 + vaddps %3, %1, %2 ; w = %1 + %2 + vmulps %2, %5, [ps_p1p1m1p1root2] ; v *= vals1 + vpermilps %2, %2, [perm1] + vblendps %1, %2, %3, 0x33 ; q = {w1,w2,v4,v2,w5,w6,v7,v6} + vshufps %5, %3, %2, 0x4e ; r = {w3,w4,v1,v3,w7,w8,v8,v5} + vsubps %4, %5, %1 ; s = r - q + vaddps %1, %5, %1 ; u = r + q + vpermilps %1, %1, [perm2] ; k = {u1,u2,u3,u4,u6,u5,u7,u8} + vshufps %5, %4, %1, 0xbb + vshufps %3, %4, %1, 0xee + vperm2f128 %3, %3, %5, 0x13 + vxorps %4, %4, [ps_m1m1p1m1p1m1m1m1] ; s *= {1,1,-1,-1,1,-1,-1,-1} + vshufps %2, %1, %4, 0xdd + vshufps %1, %1, %4, 0x88 + vperm2f128 %4, %2, %1, 0x02 ; v = {k1,k3,s1,s3,k2,k4,s2,s4} + vperm2f128 %1, %1, %2, 0x13 ; w = {k6,k8,s6,s8,k5,k7,s5,s7} + vsubps %5, %1, %3 + vblendps %1, %5, %1, 0x55 ; w -= {0,s7,0,k7,0,s8,0,k8} + vsubps %2, %4, %1 ; %2 = v - w + vaddps %1, %4, %1 ; %1 = v + w +%endmacro + +; In SSE mode do one fft4 transforms ; in: %1={r0,i0,r2,i2} %2={r1,i1,r3,i3} ; out: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} +; +; In AVX mode do two fft4 transforms +; in: %1={r0,i0,r2,i2,r4,i4,r6,i6} %2={r1,i1,r3,i3,r5,i5,r7,i7} +; out: %1={r0,r1,r2,r3,r4,r5,r6,r7} %2={i0,i1,i2,i3,i4,i5,i6,i7} %macro T4_SSE 3 - mova %3, %1 - addps %1, %2 ; {t1,t2,t6,t5} - subps %3, %2 ; {t3,t4,-t8,t7} - xorps %3, [ps_p1p1m1p1] - mova %2, %1 - shufps %1, %3, 0x44 ; {t1,t2,t3,t4} - shufps %2, %3, 0xbe ; {t6,t5,t7,t8} - mova %3, %1 - addps %1, %2 ; {r0,i0,r1,i1} - subps %3, %2 ; {r2,i2,r3,i3} - mova %2, %1 - shufps %1, %3, 0x88 ; {r0,r1,r2,r3} - shufps %2, %3, 0xdd ; {i0,i1,i2,i3} + subps %3, %1, %2 ; {t3,t4,-t8,t7} + addps %1, %1, %2 ; {t1,t2,t6,t5} + xorps %3, %3, [ps_p1p1m1p1] + shufps %2, %1, %3, 0xbe ; {t6,t5,t7,t8} + shufps %1, %1, %3, 0x44 ; {t1,t2,t3,t4} + subps %3, %1, %2 ; {r2,i2,r3,i3} + addps %1, %1, %2 ; {r0,i0,r1,i1} + shufps %2, %1, %3, 0xdd ; {i0,i1,i2,i3} + shufps %1, %1, %3, 0x88 ; {r0,r1,r2,r3} %endmacro +; In SSE mode do one FFT8 ; in: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} %3={r4,i4,r6,i6} %4={r5,i5,r7,i7} ; out: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} %1={r4,r5,r6,r7} %2={i4,i5,i6,i7} +; +; In AVX mode do two FFT8 +; in: %1={r0,i0,r2,i2,r8, i8, r10,i10} %2={r1,i1,r3,i3,r9, i9, r11,i11} +; %3={r4,i4,r6,i6,r12,i12,r14,i14} %4={r5,i5,r7,i7,r13,i13,r15,i15} +; out: %1={r0,r1,r2,r3,r8, r9, r10,r11} %2={i0,i1,i2,i3,i8, i9, i10,i11} +; %3={r4,r5,r6,r7,r12,r13,r14,r15} %4={i4,i5,i6,i7,i12,i13,i14,i15} %macro T8_SSE 6 - mova %6, %3 - subps %3, %4 ; {r5,i5,r7,i7} - addps %6, %4 ; {t1,t2,t3,t4} - mova %4, %3 - shufps %4, %4, 0xb1 ; {i5,r5,i7,r7} - mulps %3, [ps_root2mppm] ; {-r5,i5,r7,-i7} - mulps %4, [ps_root2] - addps %3, %4 ; {t8,t7,ta,t9} - mova %4, %6 - shufps %6, %3, 0x36 ; {t3,t2,t9,t8} - shufps %4, %3, 0x9c ; {t1,t4,t7,ta} - mova %3, %6 - addps %6, %4 ; {t1,t2,t9,ta} - subps %3, %4 ; {t6,t5,tc,tb} - mova %4, %6 - shufps %6, %3, 0xd8 ; {t1,t9,t5,tb} - shufps %4, %3, 0x8d ; {t2,ta,t6,tc} - mova %3, %1 - mova %5, %2 - addps %1, %6 ; {r0,r1,r2,r3} - addps %2, %4 ; {i0,i1,i2,i3} - subps %3, %6 ; {r4,r5,r6,r7} - subps %5, %4 ; {i4,i5,i6,i7} - SWAP %4, %5 + addps %6, %3, %4 ; {t1,t2,t3,t4} + subps %3, %3, %4 ; {r5,i5,r7,i7} + shufps %4, %3, %3, 0xb1 ; {i5,r5,i7,r7} + mulps %3, %3, [ps_root2mppm] ; {-r5,i5,r7,-i7} + mulps %4, %4, [ps_root2] + addps %3, %3, %4 ; {t8,t7,ta,t9} + shufps %4, %6, %3, 0x9c ; {t1,t4,t7,ta} + shufps %6, %6, %3, 0x36 ; {t3,t2,t9,t8} + subps %3, %6, %4 ; {t6,t5,tc,tb} + addps %6, %6, %4 ; {t1,t2,t9,ta} + shufps %5, %6, %3, 0x8d ; {t2,ta,t6,tc} + shufps %6, %6, %3, 0xd8 ; {t1,t9,t5,tb} + subps %3, %1, %6 ; {r4,r5,r6,r7} + addps %1, %1, %6 ; {r0,r1,r2,r3} + subps %4, %2, %5 ; {i4,i5,i6,i7} + addps %2, %2, %5 ; {i0,i1,i2,i3} %endmacro ; scheduled for cpu-bound sizes @@ -148,52 +190,44 @@ section .text align=16 IF%1 mova m4, Z(4) IF%1 mova m5, Z(5) mova m0, %2 ; wre - mova m2, m4 mova m1, %3 ; wim - mova m3, m5 - mulps m2, m0 ; r2*wre + mulps m2, m4, m0 ; r2*wre IF%1 mova m6, Z2(6) - mulps m3, m1 ; i2*wim + mulps m3, m5, m1 ; i2*wim IF%1 mova m7, Z2(7) - mulps m4, m1 ; r2*wim - mulps m5, m0 ; i2*wre - addps m2, m3 ; r2*wre + i2*wim - mova m3, m1 - mulps m1, m6 ; r3*wim - subps m5, m4 ; i2*wre - r2*wim - mova m4, m0 - mulps m3, m7 ; i3*wim - mulps m4, m6 ; r3*wre - mulps m0, m7 ; i3*wre - subps m4, m3 ; r3*wre - i3*wim + mulps m4, m4, m1 ; r2*wim + mulps m5, m5, m0 ; i2*wre + addps m2, m2, m3 ; r2*wre + i2*wim + mulps m3, m1, m7 ; i3*wim + subps m5, m5, m4 ; i2*wre - r2*wim + mulps m1, m1, m6 ; r3*wim + mulps m4, m0, m6 ; r3*wre + mulps m0, m0, m7 ; i3*wre + subps m4, m4, m3 ; r3*wre - i3*wim mova m3, Z(0) - addps m0, m1 ; i3*wre + r3*wim - mova m1, m4 - addps m4, m2 ; t5 - subps m1, m2 ; t3 - subps m3, m4 ; r2 - addps m4, Z(0) ; r0 + addps m0, m0, m1 ; i3*wre + r3*wim + subps m1, m4, m2 ; t3 + addps m4, m4, m2 ; t5 + subps m3, m3, m4 ; r2 + addps m4, m4, Z(0) ; r0 mova m6, Z(2) mova Z(4), m3 mova Z(0), m4 - mova m3, m5 - subps m5, m0 ; t4 - mova m4, m6 - subps m6, m5 ; r3 - addps m5, m4 ; r1 - mova Z2(6), m6 - mova Z(2), m5 + subps m3, m5, m0 ; t4 + subps m4, m6, m3 ; r3 + addps m3, m3, m6 ; r1 + mova Z2(6), m4 + mova Z(2), m3 mova m2, Z(3) - addps m3, m0 ; t6 - subps m2, m1 ; i3 + addps m3, m5, m0 ; t6 + subps m2, m2, m1 ; i3 mova m7, Z(1) - addps m1, Z(3) ; i1 + addps m1, m1, Z(3) ; i1 mova Z2(7), m2 mova Z(3), m1 - mova m4, m7 - subps m7, m3 ; i2 - addps m3, m4 ; i0 - mova Z(5), m7 + subps m4, m7, m3 ; i2 + addps m3, m3, m7 ; i0 + mova Z(5), m4 mova Z(1), m3 %endmacro @@ -201,77 +235,55 @@ IF%1 mova m7, Z2(7) %macro PASS_BIG 1 ; (!interleave) mova m4, Z(4) ; r2 mova m5, Z(5) ; i2 - mova m2, m4 mova m0, [wq] ; wre - mova m3, m5 mova m1, [wq+o1q] ; wim - mulps m2, m0 ; r2*wre + mulps m2, m4, m0 ; r2*wre mova m6, Z2(6) ; r3 - mulps m3, m1 ; i2*wim + mulps m3, m5, m1 ; i2*wim mova m7, Z2(7) ; i3 - mulps m4, m1 ; r2*wim - mulps m5, m0 ; i2*wre - addps m2, m3 ; r2*wre + i2*wim - mova m3, m1 - mulps m1, m6 ; r3*wim - subps m5, m4 ; i2*wre - r2*wim - mova m4, m0 - mulps m3, m7 ; i3*wim - mulps m4, m6 ; r3*wre - mulps m0, m7 ; i3*wre - subps m4, m3 ; r3*wre - i3*wim + mulps m4, m4, m1 ; r2*wim + mulps m5, m5, m0 ; i2*wre + addps m2, m2, m3 ; r2*wre + i2*wim + mulps m3, m1, m7 ; i3*wim + mulps m1, m1, m6 ; r3*wim + subps m5, m5, m4 ; i2*wre - r2*wim + mulps m4, m0, m6 ; r3*wre + mulps m0, m0, m7 ; i3*wre + subps m4, m4, m3 ; r3*wre - i3*wim mova m3, Z(0) - addps m0, m1 ; i3*wre + r3*wim - mova m1, m4 - addps m4, m2 ; t5 - subps m1, m2 ; t3 - subps m3, m4 ; r2 - addps m4, Z(0) ; r0 + addps m0, m0, m1 ; i3*wre + r3*wim + subps m1, m4, m2 ; t3 + addps m4, m4, m2 ; t5 + subps m3, m3, m4 ; r2 + addps m4, m4, Z(0) ; r0 mova m6, Z(2) mova Z(4), m3 mova Z(0), m4 - mova m3, m5 - subps m5, m0 ; t4 - mova m4, m6 - subps m6, m5 ; r3 - addps m5, m4 ; r1 -IF%1 mova Z2(6), m6 -IF%1 mova Z(2), m5 + subps m3, m5, m0 ; t4 + subps m4, m6, m3 ; r3 + addps m3, m3, m6 ; r1 +IF%1 mova Z2(6), m4 +IF%1 mova Z(2), m3 mova m2, Z(3) - addps m3, m0 ; t6 - subps m2, m1 ; i3 + addps m5, m5, m0 ; t6 + subps m2, m2, m1 ; i3 mova m7, Z(1) - addps m1, Z(3) ; i1 + addps m1, m1, Z(3) ; i1 IF%1 mova Z2(7), m2 IF%1 mova Z(3), m1 - mova m4, m7 - subps m7, m3 ; i2 - addps m3, m4 ; i0 -IF%1 mova Z(5), m7 -IF%1 mova Z(1), m3 + subps m6, m7, m5 ; i2 + addps m5, m5, m7 ; i0 +IF%1 mova Z(5), m6 +IF%1 mova Z(1), m5 %if %1==0 - mova m4, m5 ; r1 - mova m0, m6 ; r3 - unpcklps m5, m1 - unpckhps m4, m1 - unpcklps m6, m2 - unpckhps m0, m2 + INTERL m1, m3, m7, Z, 2 + INTERL m2, m4, m0, Z2, 6 + mova m1, Z(0) mova m2, Z(4) - mova Z(2), m5 - mova Z(3), m4 - mova Z2(6), m6 - mova Z2(7), m0 - mova m5, m1 ; r0 - mova m4, m2 ; r2 - unpcklps m1, m3 - unpckhps m5, m3 - unpcklps m2, m7 - unpckhps m4, m7 - mova Z(0), m1 - mova Z(1), m5 - mova Z(4), m2 - mova Z(5), m4 + + INTERL m5, m1, m3, Z, 0 + INTERL m6, m2, m7, Z, 4 %endif %endmacro @@ -281,13 +293,106 @@ IF%1 mova Z(1), m3 punpckhdq %3, %2 %endmacro -INIT_XMM -%define mova movaps - %define Z(x) [r0+mmsize*x] %define Z2(x) [r0+mmsize*x] +%define ZH(x) [r0+mmsize*x+mmsize/2] + +INIT_YMM + +align 16 +fft8_avx: + mova m0, Z(0) + mova m1, Z(1) + T8_AVX m0, m1, m2, m3, m4 + mova Z(0), m0 + mova Z(1), m1 + ret + + +align 16 +fft16_avx: + mova m2, Z(2) + mova m3, Z(3) + T4_SSE m2, m3, m7 + + mova m0, Z(0) + mova m1, Z(1) + T8_AVX m0, m1, m4, m5, m7 + + mova m4, [ps_cos16_1] + mova m5, [ps_cos16_2] + vmulps m6, m2, m4 + vmulps m7, m3, m5 + vaddps m7, m7, m6 + vmulps m2, m2, m5 + vmulps m3, m3, m4 + vsubps m3, m3, m2 + vblendps m2, m7, m3, 0xf0 + vperm2f128 m3, m7, m3, 0x21 + vaddps m4, m2, m3 + vsubps m2, m3, m2 + vperm2f128 m2, m2, m2, 0x01 + vsubps m3, m1, m2 + vaddps m1, m1, m2 + vsubps m5, m0, m4 + vaddps m0, m0, m4 + vextractf128 Z(0), m0, 0 + vextractf128 ZH(0), m1, 0 + vextractf128 Z(1), m0, 1 + vextractf128 ZH(1), m1, 1 + vextractf128 Z(2), m5, 0 + vextractf128 ZH(2), m3, 0 + vextractf128 Z(3), m5, 1 + vextractf128 ZH(3), m3, 1 + ret + +align 16 +fft32_avx: + call fft16_avx + + mova m0, Z(4) + mova m1, Z(5) + + T4_SSE m0, m1, m4 + + mova m2, Z(6) + mova m3, Z(7) + + T8_SSE m0, m1, m2, m3, m4, m6 + ; m0={r0,r1,r2,r3,r8, r9, r10,r11} m1={i0,i1,i2,i3,i8, i9, i10,i11} + ; m2={r4,r5,r6,r7,r12,r13,r14,r15} m3={i4,i5,i6,i7,i12,i13,i14,i15} + + vperm2f128 m4, m0, m2, 0x20 + vperm2f128 m5, m1, m3, 0x20 + vperm2f128 m6, m0, m2, 0x31 + vperm2f128 m7, m1, m3, 0x31 + + PASS_SMALL 0, [cos_32], [cos_32+32] + + ret + +fft32_interleave_avx: + call fft32_avx + mov r2d, 32 +.deint_loop: + mova m2, Z(0) + mova m3, Z(1) + vunpcklps m0, m2, m3 + vunpckhps m1, m2, m3 + vextractf128 Z(0), m0, 0 + vextractf128 ZH(0), m1, 0 + vextractf128 Z(1), m0, 1 + vextractf128 ZH(1), m1, 1 + add r0, mmsize*2 + sub r2d, mmsize/4 + jg .deint_loop + ret + +INIT_XMM +%define movdqa movaps align 16 +fft4_avx: fft4_sse: mova m0, Z(0) mova m1, Z(1) @@ -406,6 +511,8 @@ FFT48_3DN _3dn %define Z(x) [zq + o1q*(x&6) + mmsize*(x&1)] %define Z2(x) [zq + o3q + mmsize*(x&1)] +%define ZH(x) [zq + o1q*(x&6) + mmsize*(x&1) + mmsize/2] +%define Z2H(x) [zq + o3q + mmsize*(x&1) + mmsize/2] %macro DECL_PASS 2+ ; name, payload align 16 @@ -423,8 +530,34 @@ DEFINE_ARGS z, w, n, o1, o3 rep ret %endmacro +INIT_YMM + +%macro INTERL_AVX 5 + vunpckhps %3, %2, %1 + vunpcklps %2, %2, %1 + vextractf128 %4(%5), %2, 0 + vextractf128 %4 %+ H(%5), %3, 0 + vextractf128 %4(%5 + 1), %2, 1 + vextractf128 %4 %+ H(%5 + 1), %3, 1 +%endmacro + +%define INTERL INTERL_AVX + +DECL_PASS pass_avx, PASS_BIG 1 +DECL_PASS pass_interleave_avx, PASS_BIG 0 + INIT_XMM -%define mova movaps + +%macro INTERL_SSE 5 + mova %3, %2 + unpcklps %2, %1 + unpckhps %3, %1 + mova %4(%5), %2 + mova %4(%5+1), %3 +%endmacro + +%define INTERL INTERL_SSE + DECL_PASS pass_sse, PASS_BIG 1 DECL_PASS pass_interleave_sse, PASS_BIG 0 @@ -457,9 +590,12 @@ DECL_PASS pass_interleave_3dn, PASS_BIG 0 %macro DECL_FFT 2-3 ; nbits, cpu, suffix %xdefine list_of_fft fft4%2 SECTION_REL, fft8%2 SECTION_REL -%if %1==5 +%if %1>=5 %xdefine list_of_fft list_of_fft, fft16%2 SECTION_REL %endif +%if %1>=6 +%xdefine list_of_fft list_of_fft, fft32%3%2 SECTION_REL +%endif %assign n 1<<%1 %rep 17-%1 @@ -492,9 +628,14 @@ section .text ; The others pass args in registers and don't spill anything. cglobal fft_dispatch%3%2, 2,5,8, z, nbits FFT_DISPATCH %3%2, nbits +%ifidn %2, _avx + vzeroupper +%endif RET %endmacro ; DECL_FFT +DECL_FFT 6, _avx +DECL_FFT 6, _avx, _interleave DECL_FFT 5, _sse DECL_FFT 5, _sse, _interleave DECL_FFT 4, _3dn @@ -533,21 +674,53 @@ INIT_XMM %endmacro %macro CMUL 6 ;j, xmm0, xmm1, 3, 4, 5 - movaps xmm6, [%4+%1*2] - movaps %2, [%4+%1*2+0x10] - movaps %3, xmm6 - movaps xmm7, %2 - mulps xmm6, [%5+%1] - mulps %2, [%6+%1] - mulps %3, [%6+%1] - mulps xmm7, [%5+%1] - subps %2, xmm6 - addps %3, xmm7 + mulps m6, %3, [%5+%1] + mulps m7, %2, [%5+%1] + mulps %2, %2, [%6+%1] + mulps %3, %3, [%6+%1] + subps %2, %2, m6 + addps %3, %3, m7 +%endmacro + +%macro POSROTATESHUF_AVX 5 ;j, k, z+n8, tcos+n8, tsin+n8 +.post: + vmovaps ymm1, [%3+%1*2] + vmovaps ymm0, [%3+%1*2+0x20] + vmovaps ymm3, [%3+%2*2] + vmovaps ymm2, [%3+%2*2+0x20] + + CMUL %1, ymm0, ymm1, %3, %4, %5 + CMUL %2, ymm2, ymm3, %3, %4, %5 + vshufps ymm1, ymm1, ymm1, 0x1b + vshufps ymm3, ymm3, ymm3, 0x1b + vperm2f128 ymm1, ymm1, ymm1, 0x01 + vperm2f128 ymm3, ymm3, ymm3, 0x01 + vunpcklps ymm6, ymm2, ymm1 + vunpckhps ymm4, ymm2, ymm1 + vunpcklps ymm7, ymm0, ymm3 + vunpckhps ymm5, ymm0, ymm3 + + vextractf128 [%3+%1*2], ymm7, 0 + vextractf128 [%3+%1*2+0x10], ymm5, 0 + vextractf128 [%3+%1*2+0x20], ymm7, 1 + vextractf128 [%3+%1*2+0x30], ymm5, 1 + + vextractf128 [%3+%2*2], ymm6, 0 + vextractf128 [%3+%2*2+0x10], ymm4, 0 + vextractf128 [%3+%2*2+0x20], ymm6, 1 + vextractf128 [%3+%2*2+0x30], ymm4, 1 + sub %2, 0x20 + add %1, 0x20 + jl .post %endmacro %macro POSROTATESHUF 5 ;j, k, z+n8, tcos+n8, tsin+n8 .post: + movaps xmm1, [%3+%1*2] + movaps xmm0, [%3+%1*2+0x10] CMUL %1, xmm0, xmm1, %3, %4, %5 + movaps xmm5, [%3+%2*2] + movaps xmm4, [%3+%2*2+0x10] CMUL %2, xmm4, xmm5, %3, %4, %5 shufps xmm1, xmm1, 0x1b shufps xmm5, xmm5, 0x1b @@ -566,7 +739,8 @@ INIT_XMM jl .post %endmacro -cglobal imdct_half_sse, 3,7,8; FFTContext *s, FFTSample *output, const FFTSample *input +%macro DECL_IMDCT 2 +cglobal imdct_half%1, 3,7,8; FFTContext *s, FFTSample *output, const FFTSample *input %ifdef ARCH_X86_64 %define rrevtab r10 %define rtcos r11 @@ -641,7 +815,7 @@ cglobal imdct_half_sse, 3,7,8; FFTContext *s, FFTSample *output, const FFTSample mov r0, r1 mov r1d, [r5+FFTContext.nbits] - FFT_DISPATCH _sse, r1 + FFT_DISPATCH %1, r1 mov r0d, [r5+FFTContext.mdctsize] add r6, r0 @@ -653,14 +827,24 @@ cglobal imdct_half_sse, 3,7,8; FFTContext *s, FFTSample *output, const FFTSample mov rtsin, [esp+4] %endif neg r0 - mov r1, -16 + mov r1, -mmsize sub r1, r0 - POSROTATESHUF r0, r1, r6, rtcos, rtsin + %2 r0, r1, r6, rtcos, rtsin %ifdef ARCH_X86_64 pop r14 pop r13 pop r12 %else add esp, 12 +%endif +%ifidn avx_enabled, 1 + vzeroupper %endif RET +%endmacro + +DECL_IMDCT _sse, POSROTATESHUF + +INIT_YMM + +DECL_IMDCT _avx, POSROTATESHUF_AVX diff --git a/libavcodec/x86/fft_sse.c b/libavcodec/x86/fft_sse.c index 9de4e4c080..5b52988d09 100644 --- a/libavcodec/x86/fft_sse.c +++ b/libavcodec/x86/fft_sse.c @@ -28,6 +28,12 @@ DECLARE_ASM_CONST(16, int, ff_m1m1m1m1)[4] = void ff_fft_dispatch_sse(FFTComplex *z, int nbits); void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits); +void ff_fft_dispatch_interleave_avx(FFTComplex *z, int nbits); + +void ff_fft_calc_avx(FFTContext *s, FFTComplex *z) +{ + ff_fft_dispatch_interleave_avx(z, s->nbits); +} void ff_fft_calc_sse(FFTContext *s, FFTComplex *z) { @@ -77,7 +83,7 @@ void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input) long n = s->mdct_size; long n4 = n >> 2; - ff_imdct_half_sse(s, output+n4, input); + s->imdct_half(s, output + n4, input); j = -n; k = n-16; -- cgit v1.2.3 From e6ff064845d02c43526c8a56dab121c219f16659 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Tue, 26 Apr 2011 13:52:12 +0200 Subject: Eliminate pointless '#if 1' statements without matching '#else'. --- ffserver.c | 2 -- libavcodec/dct-test.c | 5 +---- libavcodec/dsputil.c | 2 -- libavcodec/error_resilience.c | 17 +++++------------ libavcodec/h264.h | 2 -- libavcodec/motion_est_template.c | 2 -- libavcodec/msmpeg4.c | 7 +++---- libavcodec/sh4/qpel.c | 2 -- libavcodec/snow.c | 2 -- libavformat/nutenc.c | 2 -- libavutil/pca.c | 3 +-- 11 files changed, 10 insertions(+), 36 deletions(-) diff --git a/ffserver.c b/ffserver.c index 829eb2ef7e..fe030b94c0 100644 --- a/ffserver.c +++ b/ffserver.c @@ -2185,10 +2185,8 @@ static int open_input_stream(HTTPContext *c, const char *info) } } -#if 1 if (c->fmt_in->iformat->read_seek) av_seek_frame(c->fmt_in, -1, stream_pos, 0); -#endif /* set the start time (needed for maxtime and RTP packet timing) */ c->start_time = cur_time; c->first_pts = AV_NOPTS_VALUE; diff --git a/libavcodec/dct-test.c b/libavcodec/dct-test.c index e943d6a54f..c3c376e79f 100644 --- a/libavcodec/dct-test.c +++ b/libavcodec/dct-test.c @@ -312,18 +312,16 @@ static void dct_error(const char *name, int is_idct, } for(i=0; i<64; i++) sysErrMax= FFMAX(sysErrMax, FFABS(sysErr[i])); -#if 1 // dump systematic errors for(i=0; i<64; i++){ if(i%8==0) printf("\n"); printf("%7d ", (int)sysErr[i]); } printf("\n"); -#endif printf("%s %s: err_inf=%d err2=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", is_idct ? "IDCT" : "DCT", name, err_inf, (double)err2 / NB_ITS / 64.0, (double)sysErrMax / NB_ITS, maxout, blockSumErrMax); -#if 1 //Speed test + /* speed test */ for(i=0;i<64;i++) block1[i] = 0; @@ -376,7 +374,6 @@ static void dct_error(const char *name, int is_idct, printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", name, (double)it1 * 1000.0 / (double)ti1); -#endif } DECLARE_ALIGNED(8, static uint8_t, img_dest)[64]; diff --git a/libavcodec/dsputil.c b/libavcodec/dsputil.c index 215c1e4241..dbfc8ce162 100644 --- a/libavcodec/dsputil.c +++ b/libavcodec/dsputil.c @@ -2100,7 +2100,6 @@ QPEL_MC(0, avg_ , _ , op_avg) #define put_no_rnd_qpel8_mc00_c ff_put_pixels8x8_c #define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_c -#if 1 #define H264_LOWPASS(OPNAME, OP, OP2) \ static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ const int h=2;\ @@ -2522,7 +2521,6 @@ H264_MC(avg_, 16) #undef op_put #undef op2_avg #undef op2_put -#endif #define put_h264_qpel8_mc00_c ff_put_pixels8x8_c #define avg_h264_qpel8_mc00_c ff_avg_pixels8x8_c diff --git a/libavcodec/error_resilience.c b/libavcodec/error_resilience.c index d4d5839fcf..e0b64b0336 100644 --- a/libavcodec/error_resilience.c +++ b/libavcodec/error_resilience.c @@ -786,7 +786,6 @@ void ff_er_frame_end(MpegEncContext *s){ } } -#if 1 /* handle overlapping slices */ for(error_type=1; error_type<=3; error_type++){ int end_ok=0; @@ -807,8 +806,7 @@ void ff_er_frame_end(MpegEncContext *s){ end_ok=0; } } -#endif -#if 1 + /* handle slices with partitions of different length */ if(s->partitioned_frame){ int end_ok=0; @@ -829,7 +827,7 @@ void ff_er_frame_end(MpegEncContext *s){ end_ok=0; } } -#endif + /* handle missing slices */ if(s->error_recognition>=4){ int end_ok=1; @@ -853,7 +851,6 @@ void ff_er_frame_end(MpegEncContext *s){ } } -#if 1 /* backward mark errors */ distance=9999999; for(error_type=1; error_type<=3; error_type++){ @@ -878,7 +875,6 @@ void ff_er_frame_end(MpegEncContext *s){ distance= 9999999; } } -#endif /* forward mark errors */ error=0; @@ -893,7 +889,7 @@ void ff_er_frame_end(MpegEncContext *s){ s->error_status_table[mb_xy]|= error; } } -#if 1 + /* handle not partitioned case */ if(!s->partitioned_frame){ for(i=0; imb_num; i++){ @@ -904,7 +900,6 @@ void ff_er_frame_end(MpegEncContext *s){ s->error_status_table[mb_xy]= error; } } -#endif dc_error= ac_error= mv_error=0; for(i=0; imb_num; i++){ @@ -1065,16 +1060,15 @@ void ff_er_frame_end(MpegEncContext *s){ s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3; } } -#if 1 + /* guess DC for damaged blocks */ guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1); guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0); guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0); -#endif + /* filter luma DC */ filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride); -#if 1 /* render DC only intra */ for(mb_y=0; mb_ymb_height; mb_y++){ for(mb_x=0; mb_xmb_width; mb_x++){ @@ -1094,7 +1088,6 @@ void ff_er_frame_end(MpegEncContext *s){ put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y); } } -#endif if(s->avctx->error_concealment&FF_EC_DEBLOCK){ /* filter horizontal block boundaries */ diff --git a/libavcodec/h264.h b/libavcodec/h264.h index 96720acf94..f22454b436 100644 --- a/libavcodec/h264.h +++ b/libavcodec/h264.h @@ -997,7 +997,6 @@ static void fill_decode_caches(H264Context *h, int mb_type){ } } -#if 1 if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ int list; for(list=0; listlist_count; list++){ @@ -1172,7 +1171,6 @@ static void fill_decode_caches(H264Context *h, int mb_type){ } } } -#endif h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); } diff --git a/libavcodec/motion_est_template.c b/libavcodec/motion_est_template.c index faf03d22d6..09ec9f79c4 100644 --- a/libavcodec/motion_est_template.c +++ b/libavcodec/motion_est_template.c @@ -158,7 +158,6 @@ static int hpel_motion_search(MpegEncContext * s, const int b= score_map[(index+(1<penalty_factor; -#if 1 int key; int map_generation= c->map_generation; #ifndef NDEBUG @@ -172,7 +171,6 @@ static int hpel_motion_search(MpegEncContext * s, assert(map[(index+1)&(ME_MAP_SIZE-1)] == key); key= ((my)<ac_stats[s->mb_intra][n>3][level][run][last]++; } -#if 0 -else - s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like -#endif + + s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like + code = get_rl_index(rl, last, run, level); put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); if (code == rl->n) { diff --git a/libavcodec/sh4/qpel.c b/libavcodec/sh4/qpel.c index ff88b76faf..3242872e47 100644 --- a/libavcodec/sh4/qpel.c +++ b/libavcodec/sh4/qpel.c @@ -897,7 +897,6 @@ QPEL_MC(0, avg_ , _ , op_avg) #undef op_put #undef op_put_no_rnd -#if 1 #define H264_LOWPASS(OPNAME, OP, OP2) \ static inline void OPNAME ## h264_qpel_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,int w,int h){\ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ @@ -1298,7 +1297,6 @@ H264_MC(avg_, 16) #undef op_put #undef op2_avg #undef op2_put -#endif static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; diff --git a/libavcodec/snow.c b/libavcodec/snow.c index 42145f5ce3..7e862f24b0 100644 --- a/libavcodec/snow.c +++ b/libavcodec/snow.c @@ -3299,10 +3299,8 @@ static void iterative_me(SnowContext *s){ } best_rd= ref_rd; *block= ref_b; -#if 1 check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd); //FIXME RD style color selection -#endif if(!same_block(block, &backup)){ if(tb ) tb ->type &= ~BLOCK_OPT; if(lb ) lb ->type &= ~BLOCK_OPT; diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c index c17a15dbf3..df5dc6fdf7 100644 --- a/libavformat/nutenc.c +++ b/libavformat/nutenc.c @@ -175,7 +175,6 @@ static void build_frame_code(AVFormatContext *s){ } key_frame= intra_only; -#if 1 if(is_audio){ int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate); int pts; @@ -199,7 +198,6 @@ static void build_frame_code(AVFormatContext *s){ ft->pts_delta=1; start2++; } -#endif if(codec->has_b_frames){ pred_count=5; diff --git a/libavutil/pca.c b/libavutil/pca.c index 770dc8dfd9..56bf707421 100644 --- a/libavutil/pca.c +++ b/libavutil/pca.c @@ -218,7 +218,6 @@ int main(void){ printf("\n"); } -#if 1 for(i=0; i Date: Tue, 5 Apr 2011 12:55:42 -0400 Subject: ac3enc: correct the flipped sign in the ac3_fixed encoder --- libavcodec/ac3enc_fixed.c | 2 +- tests/ref/acodec/ac3_fixed | 2 +- tests/ref/lavf/rm | 2 +- tests/ref/seek/ac3_rm | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c index e64384122a..800ef8f92c 100644 --- a/libavcodec/ac3enc_fixed.c +++ b/libavcodec/ac3enc_fixed.c @@ -47,7 +47,7 @@ static av_cold void mdct_end(AC3MDCTContext *mdct) static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, int nbits) { - int ret = ff_mdct_init(&mdct->fft, nbits, 0, 1.0); + int ret = ff_mdct_init(&mdct->fft, nbits, 0, -1.0); mdct->window = ff_ac3_window; return ret; } diff --git a/tests/ref/acodec/ac3_fixed b/tests/ref/acodec/ac3_fixed index a3032d0380..ca8a082c75 100644 --- a/tests/ref/acodec/ac3_fixed +++ b/tests/ref/acodec/ac3_fixed @@ -1,2 +1,2 @@ -5ddb6d25dd117db29627f9d286153a7a *./tests/data/acodec/ac3.rm +0f14801e166819dd4a58981aea36e08b *./tests/data/acodec/ac3.rm 98751 ./tests/data/acodec/ac3.rm diff --git a/tests/ref/lavf/rm b/tests/ref/lavf/rm index a85c7630b4..eae422ae4d 100644 --- a/tests/ref/lavf/rm +++ b/tests/ref/lavf/rm @@ -1,2 +1,2 @@ -a1c71456f21d5459d2824d75bbdcc80c *./tests/data/lavf/lavf.rm +2e3d6b1944c6cd2cf14e13055aecf82a *./tests/data/lavf/lavf.rm 346706 ./tests/data/lavf/lavf.rm diff --git a/tests/ref/seek/ac3_rm b/tests/ref/seek/ac3_rm index 4705447293..05772fcf98 100644 --- a/tests/ref/seek/ac3_rm +++ b/tests/ref/seek/ac3_rm @@ -11,7 +11,8 @@ ret:-1 st:-1 flags:1 ts: 1.470835 ret:-1 st: 0 flags:0 ts: 0.365000 ret: 0 st: 0 flags:1 ts:-0.741000 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 -ret:-1 st:-1 flags:0 ts: 2.153336 +ret: 0 st:-1 flags:0 ts: 2.153336 +ret: 0 st: 0 flags:1 dts: 2.159000 pts: 2.159000 pos: 35567 size: 556 ret:-1 st:-1 flags:1 ts: 1.047503 ret: 0 st: 0 flags:0 ts:-0.058000 ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 -- cgit v1.2.3