[FFmpeg-devel] [PATCH] lavfi/alphaextract: switch to filter_frame API
Clément Bœsch
ubitux at gmail.com
Fri Dec 7 02:49:37 CET 2012
On Fri, Dec 07, 2012 at 12:06:08AM +0100, Stefano Sabatini wrote:
> ---
> libavfilter/vf_alphaextract.c | 26 ++++++++++++++++----------
> 1 file changed, 16 insertions(+), 10 deletions(-)
>
> diff --git a/libavfilter/vf_alphaextract.c b/libavfilter/vf_alphaextract.c
> index 35402f6..766cc8c 100644
> --- a/libavfilter/vf_alphaextract.c
> +++ b/libavfilter/vf_alphaextract.c
> @@ -29,6 +29,7 @@
> #include "avfilter.h"
> #include "drawutils.h"
> #include "formats.h"
> +#include "internal.h"
> #include "video.h"
>
> enum { Y, U, V, A };
> @@ -59,16 +60,21 @@ static int config_input(AVFilterLink *inlink)
> return 0;
> }
>
> -static int draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
> +static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *cur_buf)
> {
> AlphaExtractContext *extract = inlink->dst->priv;
> - AVFilterBufferRef *cur_buf = inlink->cur_buf;
> - AVFilterBufferRef *out_buf = inlink->dst->outputs[0]->out_buf;
> + AVFilterLink *outlink = inlink->dst->outputs[0];
> + AVFilterBufferRef *out_buf =
> + ff_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h);
> +
> + if (!out_buf)
> + return AVERROR(ENOMEM);
I think you need to unref cur_buf this time.
> + avfilter_copy_buffer_ref_props(out_buf, cur_buf);
>
> if (extract->is_packed_rgb) {
> int x, y;
> uint8_t *pin, *pout;
> - for (y = y0; y < (y0 + h); y++) {
> + for (y = 0; y < inlink->h; y++) {
> pin = cur_buf->data[0] + y * cur_buf->linesize[0] + extract->rgba_map[A];
> pout = out_buf->data[0] + y * out_buf->linesize[0];
> for (x = 0; x < out_buf->video->w; x++) {
> @@ -79,19 +85,19 @@ static int draw_slice(AVFilterLink *inlink, int y0, int h, int slice_dir)
> }
> } else if (cur_buf->linesize[A] == out_buf->linesize[Y]) {
> const int linesize = cur_buf->linesize[A];
> - memcpy(out_buf->data[Y] + y0 * linesize,
> - cur_buf->data[A] + y0 * linesize,
> - linesize * h);
> + memcpy(out_buf->data[Y], cur_buf->data[A], linesize * inlink->h);
This code looks better than the previous one. Though there is something
that bugs me, but that's because I don't know the internals enough: can't
the padding between width and linesize be uninitialized data? It will work
but valgrind might complain. Also, second concern, and it's also somehow
unrelated to this patch but: if that padding is very large (like after a
crop filter), won't this be slower than a loop?
> } else {
> const int linesize = FFMIN(out_buf->linesize[Y], cur_buf->linesize[A]);
> int y;
> - for (y = y0; y < (y0 + h); y++) {
> + for (y = 0; y < inlink->h; y++) {
> memcpy(out_buf->data[Y] + y * out_buf->linesize[Y],
> cur_buf->data[A] + y * cur_buf->linesize[A],
> linesize);
...looks like it should be merged with this better code.
> }
> }
> - return ff_draw_slice(inlink->dst->outputs[0], y0, h, slice_dir);
> +
> + avfilter_unref_bufferp(&cur_buf);
avfilter_unref_buffer(cur_buf) should be enough but well.
> + return ff_filter_frame(outlink, out_buf);
> }
>
> static const AVFilterPad alphaextract_inputs[] = {
> @@ -99,7 +105,7 @@ static const AVFilterPad alphaextract_inputs[] = {
> .name = "default",
> .type = AVMEDIA_TYPE_VIDEO,
> .config_props = config_input,
> - .draw_slice = draw_slice,
> + .filter_frame = filter_frame,
> .min_perms = AV_PERM_READ,
> },
> { NULL }
LGTM otherwise, thanks!
--
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121207/30dd610e/attachment.asc>
More information about the ffmpeg-devel
mailing list