On Mon, 8 May 2017 23:45:24 +0100
Mark Thompson <s...@jkqxz.net> wrote:

> On 04/05/17 07:44, wm4 wrote:
> > This also adds support to avconv (which is trivial due to the new
> > hwaccel API being generic enough). For now, this keeps avconv_dxva2.c as
> > "dxva2-old", although it doesn't work as avconv.c can't handle multiple
> > hwaccels with the same pixfmt.  
> 
> Is there any reason to keep it on in avconv?  It doesn't look like it offers 
> anything which isn't fully replaced.

I thought it'd be easier to remove it later, because removing it
obviously inflates the diff by 450 lines.

> > +// This must work before the decoder is created.
> > +// This somehow needs to be exported to the user.
> > +static void dxva_adjust_hwframes(AVCodecContext *avctx, AVHWFramesContext 
> > *frames_ctx)
> > +{
> > +    FFDXVASharedContext *sctx = DXVA_SHARED_CONTEXT(avctx);
> > +    int surface_alignment, num_surfaces;
> > +
> > +    frames_ctx->format = sctx->pix_fmt;
> > +
> > +    /* decoding MPEG-2 requires additional alignment on some Intel GPUs,
> > +    but it causes issues for H.264 on certain AMD GPUs..... */
> > +    if (avctx->codec_id == AV_CODEC_ID_MPEG2VIDEO)
> > +        surface_alignment = 32;
> > +    /* the HEVC DXVA2 spec asks for 128 pixel aligned surfaces to ensure
> > +    all coding features have enough room to work with */
> > +    else if (avctx->codec_id == AV_CODEC_ID_HEVC)
> > +        surface_alignment = 128;
> > +    else
> > +        surface_alignment = 16;
> > +
> > +    /* 4 base work surfaces */
> > +    num_surfaces = 4;
> > +
> > +    /* add surfaces based on number of possible refs */
> > +    if (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == 
> > AV_CODEC_ID_HEVC)
> > +        num_surfaces += 16;
> > +    else
> > +        num_surfaces += 2;
> > +
> > +    /* add extra surfaces for frame threading */
> > +    if (avctx->active_thread_type & FF_THREAD_FRAME)
> > +        num_surfaces += avctx->thread_count;
> > +
> > +    frames_ctx->sw_format = avctx->sw_pix_fmt == AV_PIX_FMT_YUV420P10 ?
> > +                            AV_PIX_FMT_P010 : AV_PIX_FMT_NV12;
> > +    frames_ctx->width = FFALIGN(avctx->coded_width, surface_alignment);
> > +    frames_ctx->height = FFALIGN(avctx->coded_height, surface_alignment);
> > +    frames_ctx->initial_pool_size = num_surfaces;
> > +
> > +    if (frames_ctx->format == AV_PIX_FMT_DXVA2_VLD) {
> > +        AVDXVA2FramesContext *frames_hwctx = frames_ctx->hwctx;
> > +
> > +        frames_hwctx->surface_type = DXVA2_VideoDecoderRenderTarget;
> > +    }
> > +
> > +    if (frames_ctx->format == AV_PIX_FMT_D3D11) {
> > +        AVD3D11VAFramesContext *frames_hwctx = frames_ctx->hwctx;
> > +
> > +        frames_hwctx->BindFlags |= D3D11_BIND_DECODER;
> > +    }
> > +}



> So the user configuration we want here is replacement of the 
> dxva_adjust_hwframes function?
> 
> AVCodecContext.init_hw_frames from 
> <https://lists.libav.org/pipermail/libav-devel/2017-March/083133.html> looks 
> like exactly this (ignoring all the other parts there) - I think we were both 
> loosely agreeing to something like it but the discussion tailed off without a 
> conclusion, so maybe we should reopen it now.

Yeah, I think that would work.

Your proposal would also work, but I'm somewhat nervous about the fact
that the user needs to be sure to call it in the "right" moment,
because the hwaccel specific setup code (like dxva_adjust_hwframes) is
going to rely on various parameters set by the actual decoder (in the
h264 case after parsing SPS etc.) - the init_hw_frames callback would
make me feel better about that.

Also thanks for the review.
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to