[FFmpeg-devel] [RFC] How to fix DR+lavfi+vflip crash

Stefano Sabatini stefano.sabatini-lala
Tue Dec 14 23:17:47 CET 2010

On date Saturday 2010-12-11 20:31:02 +0100, Michael Niedermayer encoded:
> On Sat, Dec 11, 2010 at 06:15:36PM +0100, Stefano Sabatini wrote:
> > On date Saturday 2010-12-11 14:49:54 +0100, Michael Niedermayer encoded:
> > > in avfilter_start_frame()
> > > the linesize case can be added here:
> > >  /* prepare to copy the picture if it has insufficient permissions */
> > >     if ((dst->min_perms & picref->perms) != dst->min_perms ||
> > >          dst->rej_perms & picref->perms) {
> > 
> > how is this related? Also this will allow to save not more than 3
> > lines in the code (while making the core code more obscure).
> Its related in the way that if a filter does not support negative linesizes
> it will not receive frames with negative linesizes but rather a copy with
> positive linesizes.

A filter gets a frame from the filterchain through *_get_buffer, but
at this stage the received buffer doesn't contain any meaningful data,
so the obtained frame can't be a copy of anything.
> > > in vflips
> > > get_video_buffer()
> > > check if negative linesizes are permitted and if not return a buffer from
> > > default allocation or just skip the buffer flip
> > 
> > this is already implemented
> > 
> > The problem is how to integrate it with draw_slice()/end_frame(), and
> > support both the cases where the frame has to be inverted and not.
> sorry, i dont understand, if the code is working no changes should be required
> in draw_slice() or end_frame() unless iam missing something
> the linesize for input of draw_slice and end_frame of vflip
> is a mere cosmetic detail
> x + y*linesize is valid either way
> so what kind of problem do you see?

Have another look at my last patch. You see that most code is in the
vflip draw_slice() function. Now avfilter_draw_slice() has similar
code which copies the input slice to the output slice when this is
required for permission reasons.

Now we could try to move the vflipping code to
avfilter_draw_slice(). Now this is a problem because this way
avfilter_draw_slice() has to know *when* to vflip the frame, which is
not required when the code is in the vflip filter.

So if we want to implement the vflipping this way we also need to tell
avfilter_draw_slice() when to perform the vflipping, we could add a
property flag to the vflipping filter, and then add a block in

    if (!(inlink->cur_buf->perms & AV_PERM_NEG_LINESIZES) &&
        inlink->dst->flags & AVFILTER_VFLIP_SLICES) {
        /* vflip slice */

but I don't tend to like this solution too much.

Alternatively we could just create an inlined function for the
vflipping code if you're worried about possible code duplication
FFmpeg = Fierce and Freak Maxi Pitiless Embarassing Guru

More information about the ffmpeg-devel mailing list