From 0ccabeeaef77e240f2a44f78271a8914a23e239b Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 27 Dec 2010 15:10:21 +0000 Subject: [PATCH] Support filters and decoders that dont support negative linesizes. This patch is based on work by stefano. Originally committed as revision 26108 to svn://svn.ffmpeg.org/ffmpeg/trunk --- ffplay.c | 3 +++ libavfilter/avfilter.c | 11 +++++++---- libavfilter/avfilter.h | 1 + libavfilter/vf_vflip.c | 6 ++++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/ffplay.c b/ffplay.c index 9c48e60e6..e49951b93 100644 --- a/ffplay.c +++ b/ffplay.c @@ -1616,6 +1616,9 @@ static int input_get_buffer(AVCodecContext *codec, AVFrame *pic) int i, w, h, stride[4]; unsigned edge; + if (codec->codec->capabilities & CODEC_CAP_NEG_LINESIZES) + perms |= AV_PERM_NEG_LINESIZES; + if(pic->buffer_hints & FF_BUFFER_HINTS_VALID) { if(pic->buffer_hints & FF_BUFFER_HINTS_READABLE) perms |= AV_PERM_READ; if(pic->buffer_hints & FF_BUFFER_HINTS_PRESERVE) perms |= AV_PERM_PRESERVE; diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 362d53701..104a3b495 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -197,12 +197,13 @@ int avfilter_config_links(AVFilterContext *filter) char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms) { - snprintf(buf, buf_size, "%s%s%s%s%s", + snprintf(buf, buf_size, "%s%s%s%s%s%s", perms & AV_PERM_READ ? "r" : "", perms & AV_PERM_WRITE ? "w" : "", perms & AV_PERM_PRESERVE ? "p" : "", perms & AV_PERM_REUSE ? "u" : "", - perms & AV_PERM_REUSE2 ? "U" : ""); + perms & AV_PERM_REUSE2 ? "U" : "", + perms & AV_PERM_NEG_LINESIZES ? "n" : ""); return buf; } @@ -360,15 +361,17 @@ void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { void (*start_frame)(AVFilterLink *, AVFilterBufferRef *); AVFilterPad *dst = link->dstpad; + int perms = picref->perms; FF_DPRINTF_START(NULL, start_frame); ff_dprintf_link(NULL, link, 0); dprintf(NULL, " "); ff_dprintf_ref(NULL, picref, 1); if (!(start_frame = dst->start_frame)) start_frame = avfilter_default_start_frame; + if (picref->linesize[0] < 0) + perms |= AV_PERM_NEG_LINESIZES; /* prepare to copy the picture if it has insufficient permissions */ - if ((dst->min_perms & picref->perms) != dst->min_perms || - dst->rej_perms & picref->perms) { + if ((dst->min_perms & perms) != dst->min_perms || dst->rej_perms & perms) { av_log(link->dst, AV_LOG_DEBUG, "frame copy needed (have perms %x, need %x, reject %x)\n", picref->perms, diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 6d5d8787c..a13ccbdac 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -87,6 +87,7 @@ typedef struct AVFilterBuffer { #define AV_PERM_PRESERVE 0x04 ///< nobody else can overwrite the buffer #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time +#define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes /** * Audio specific properties in a reference to an AVFilterBuffer. Since diff --git a/libavfilter/vf_vflip.c b/libavfilter/vf_vflip.c index 2ff44411b..e5cede81b 100644 --- a/libavfilter/vf_vflip.c +++ b/libavfilter/vf_vflip.c @@ -43,11 +43,13 @@ static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, int w, int h) { FlipContext *flip = link->dst->priv; + AVFilterBufferRef *picref; int i; - AVFilterBufferRef *picref = avfilter_get_video_buffer(link->dst->outputs[0], - perms, w, h); + if (!(perms & AV_PERM_NEG_LINESIZES)) + return avfilter_default_get_video_buffer(link, perms, w, h); + picref = avfilter_get_video_buffer(link->dst->outputs[0], perms, w, h); for (i = 0; i < 4; i ++) { int vsub = i == 1 || i == 2 ? flip->vsub : 0; -- 2.11.0