Re: [libav-devel] [PATCH 01/12] lavc: Add support for increasing hardware frame pool sizes

2018-01-29 Thread wm4
On Mon, 29 Jan 2018 23:01:18 +
Mark Thompson  wrote:

> AVCodecContext.extra_hw_frames is added to the size of hardware frame
> pools created by libavcodec for APIs which require fixed-size pools.
> This allows the user to keep references to a greater number of frames
> after decode, which may be necessary for some use-cases.
> 
> It is also added to the initial_pool_size value returned by
> avcodec_get_hw_frames_parameters() if a fixed-size pool is required.
> ---
> On 26/01/18 23:39, wm4 wrote:
> > On Fri, 26 Jan 2018 23:30:48 +
> > Mark Thompson  wrote:
> >   
> >> On 26/01/18 23:13, Mark Thompson wrote:  
> >>> AVFilterContext.extra_hw_frames functions identically to the field of
> >>> the same name in AVCodecContext.
> >>
> >> Of course, that field doesn't actually exist before this patch now.  
> >> Updated to reflect that.
> >>
> >> Still, should the field be in AVCodecContext as well?  (The 
> >> hw_frames_parameters API can do this for library users, but it isn't 
> >> usable in avconv.)  
> > 
> > Probably makes sense. How else would avconv control this? (Although in
> > theory avconv could use the avcodec_get_hw_frames_parameters() API.)
> > 
> > I assume actually this field would just be added to the frames context
> > returned by avcodec_get_hw_frames_parameters(), since that is used
> > internally by most hwaccels to allocate a frames context if
> > hw_device_ctx is used.  
> 
> Yep, that sounds like a good way to do it.
> 
> Here is new series with that change and some other minor fixups.  (Not tested 
> on Windows yet.)
> 
> Thanks,
> 
> - Mark
> 
> 
>  doc/APIchanges |  3 +++
>  libavcodec/avcodec.h   | 14 ++
>  libavcodec/options_table.h |  1 +
>  3 files changed, 18 insertions(+)
> 
> diff --git a/doc/APIchanges b/doc/APIchanges
> index 0bde3a052..62c7a17e5 100644
> --- a/doc/APIchanges
> +++ b/doc/APIchanges
> @@ -13,6 +13,9 @@ libavutil: 2017-03-23
>  
>  API changes, most recent first:
>  
> +2018-xx-xx - xxx - lavc 58.x+1.0 - avcodec.h
> +  Add AVCodecContext.extra_hw_frames.
> +
>  2017-xx-xx - xxx - lavc 58.8.0 - avcodec.h
>Add const to AVCodecContext.hwaccel.
>  
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 7eaa0c927..03a3d5bd6 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2739,6 +2739,20 @@ typedef struct AVCodecContext {
>   * AVCodecContext.get_format callback)
>   */
>  int hwaccel_flags;
> +
> +/**
> + * Video decoding only.  Sets the number of extra hardware frames which
> + * the decoder will allocate for use by the caller.  This must be set
> + * before avcodec_open2() is called.
> + *
> + * Some hardware decoders require all frames that they will use for
> + * output to be defined in advance before decoding starts.  For such
> + * decoders, the hardware frame pool must therefore be of a fixed size.
> + * The extra frames set here are on top of any number that the decoder
> + * needs internally in order to operate normally (for example, frames
> + * used as reference pictures).
> + */
> +int extra_hw_frames;
>  } AVCodecContext;
>  
>  /**
> diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
> index 925ef376f..4b0a8344d 100644
> --- a/libavcodec/options_table.h
> +++ b/libavcodec/options_table.h
> @@ -419,6 +419,7 @@ static const AVOption avcodec_options[] = {
>  {"side_data_only_packets", NULL, OFFSET(side_data_only_packets), 
> AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, A|V|E },
>  #endif
>  {"apply_cropping", NULL, OFFSET(apply_cropping), AV_OPT_TYPE_INT, { .i64 = 1 
> }, 0, 1, V | D },
> +{"extra_hw_frames", "Number of extra hardware frames to allocate for the 
> user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
> V|D },
>  {NULL},
>  };
>  

Why not do this in generic code instead of every hwaccel backend?

Why not set this to the default of 4 ff_decode_get_hw_frames_ctx()
implies?

Otherwise generally LGTM.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 08/12] vf_hwupload/hwmap: Support setting a fixed pool size

2018-01-29 Thread wm4
On Mon, 29 Jan 2018 23:01:25 +
Mark Thompson  wrote:

> These filters do not directly know whether the API they are using will
> support dynamic frame pools, so this is somewhat tricky.  If the user
> set extra_hw_frames, we assume that they are aware of the problem and
> set a fixed size based on that.  If not, most cases use dynamic sizing
> just like they did previously.  The hardware-reverse-mapping case for
> hwmap previously had a large fixed size (64) here, primarily as a hack
> for QSV use - this is removed and extra_hw_frames will need to be set
> for QSV to work since it requires fixed-size pools (as the other cases
> do, and which didn't work before).
> ---
>  libavfilter/vf_hwmap.c| 7 ++-
>  libavfilter/vf_hwupload.c | 3 +++
>  2 files changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c
> index b28cb2145..d5ad2768f 100644
> --- a/libavfilter/vf_hwmap.c
> +++ b/libavfilter/vf_hwmap.c
> @@ -138,7 +138,9 @@ static int hwmap_config_output(AVFilterLink *outlink)
>  frames->sw_format = hwfc->sw_format;
>  frames->width = hwfc->width;
>  frames->height= hwfc->height;
> -frames->initial_pool_size = 64;
> +
> +if (avctx->extra_hw_frames >= 0)
> +frames->initial_pool_size = 2 + avctx->extra_hw_frames;
>  
>  err = av_hwframe_ctx_init(ctx->hwframes_ref);
>  if (err < 0) {
> @@ -218,6 +220,9 @@ static int hwmap_config_output(AVFilterLink *outlink)
>  hwfc->width = inlink->w;
>  hwfc->height= inlink->h;
>  
> +if (avctx->extra_hw_frames >= 0)
> +hwfc->initial_pool_size = 2 + avctx->extra_hw_frames;
> +
>  err = av_hwframe_ctx_init(ctx->hwframes_ref);
>  if (err < 0) {
>  av_log(avctx, AV_LOG_ERROR, "Failed to create frame "
> diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c
> index 8cca9f42e..af4ff9b81 100644
> --- a/libavfilter/vf_hwupload.c
> +++ b/libavfilter/vf_hwupload.c
> @@ -133,6 +133,9 @@ static int hwupload_config_output(AVFilterLink *outlink)
>  ctx->hwframes->width = inlink->w;
>  ctx->hwframes->height= inlink->h;
>  
> +if (avctx->extra_hw_frames >= 0)
> +ctx->hwframes->initial_pool_size = 2 + avctx->extra_hw_frames;
> +
>  err = av_hwframe_ctx_init(ctx->hwframes_ref);
>  if (err < 0)
>  goto fail;

Should we have a hwcontext flag that informs the API user whether the
frame pools require a fixed size?
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 04/12] lavc/dxva2: Don't add per-thread surfaces twice

2018-01-29 Thread wm4
On Mon, 29 Jan 2018 23:01:21 +
Mark Thompson  wrote:

> This is already accounted for in the generic code, so it shouldn't also
> be added here.
> ---
>  libavcodec/dxva2.c | 4 
>  1 file changed, 4 deletions(-)
> 
> diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
> index edc8ade96..f111d0b79 100644
> --- a/libavcodec/dxva2.c
> +++ b/libavcodec/dxva2.c
> @@ -611,10 +611,6 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx,
>  if (avctx->extra_hw_frames > 0)
>  num_surfaces += avctx->extra_hw_frames;
>  
> -/* 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);

OK, but after this change it's still not correct.

It looks like the adding of thread surfaces should be moved from the
ff_decode_get_hw_frames_ctx() to avcodec_get_hw_frames_parameters().

The public API is supposed to always add them (because it's pretty much
an implementation detail). If we don't want to have them in the hwaccel
impls. (like dxva2 in this case), then the public API function must add
them, or it'd break API users (and require them to know about the
additional frame threading requirements).
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 09/12] hwcontext: Fix documentation for av_hwdevice_ctx_alloc()

2018-01-29 Thread Luca Barbato

On 30/01/2018 00:01, Mark Thompson wrote:

From: Jun Zhao 

 From ffmpeg commit 9365dfcbf665b83b2e60c5ec5e2abf1f0a49e2c3.

Signed-off-by: Jun Zhao 
Signed-off-by: Mark Thompson 
---
  libavutil/hwcontext.h | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 203ea510e..ba293d72e 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -252,8 +252,9 @@ const char *av_hwdevice_get_type_name(enum AVHWDeviceType 
type);
  enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
  
  /**

- * Allocate an AVHWDeviceContext for a given pixel format.
+ * Allocate an AVHWDeviceContext for a given hardware type.
   *
+ * @param type the type of the hardware device to allocate.
   * @return a reference to the newly created AVHWDeviceContext on success or 
NULL
   * on failure.
   */



Sure.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure issue

2018-01-29 Thread Luca Barbato

On 30/01/2018 04:33, Song, Ruiling wrote:

-Original Message-
From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of Luca
Barbato
Sent: Friday, January 26, 2018 9:26 PM
To: libav-devel@libav.org
Subject: Re: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure issue

On 26/01/2018 12:04, Mark Thompson wrote:

Thoughts?  I can send the set again if that would be helpful.


Please do :)

I'm still afraid that we should add yet another call to query the number
of surfaces needed by each component and then call the setup with the
actual value once we have it...

It sounds like a good idea. But I don't know too much about Libav internals.
So I am not sure if you can share more idea on this. How far we are from it?
And what kind of problems that need to be addressed before we arrive at that 
situation?


Mark last set should address most of it :). (Thank you Mark!)

Testing it is more than welcome.

lu

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 12/12] hwcontext: Fix memory leak on derived frame allocation failure

2018-01-29 Thread Luca Barbato

On 30/01/2018 00:01, Mark Thompson wrote:

---
  libavutil/hwcontext.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 3ac17572b..34fb720a7 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -467,8 +467,10 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
AVFrame *frame, int flags)
  
  ret = av_hwframe_get_buffer(ctx->internal->source_frames,

  src_frame, 0);
-if (ret < 0)
+if (ret < 0) {
+av_frame_free(_frame);
  return ret;
+}
  
  ret = av_hwframe_map(frame, src_frame,

   ctx->internal->source_allocation_map_flags);



Ok.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure issue

2018-01-29 Thread Song, Ruiling


> -Original Message-
> From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of wm4
> Sent: Friday, January 26, 2018 5:15 PM
> To: libav-devel@libav.org
> Subject: Re: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure 
> issue
> 
> On Fri, 26 Jan 2018 05:56:46 +
> "Li, Zhong"  wrote:
> 
> > > From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
> > > Ruiling Song
> > > Sent: Friday, January 26, 2018 9:17 AM
> > > To: libav-devel@libav.org
> > > Subject: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure 
> > > issue
> > >
> > > From: "Ruiling, Song" 
> > >
> > > 1.) the initial_pool_size need to be set instead of zero.
> > > 2.) the PicStruct is required by MediaSDK, so give a default value.
> > >
> > > A simple command to reproduce the issue:
> > > avconv -i INPUT -init_hw_device qsv=foo -filter_hw_device foo -vf
> > > format=nv12,hwupload -c:v h264_qsv ... OUTPUT
> > >
> > > Signed-off-by: Ruiling Song 
> > > ---
> > >  libavutil/hwcontext_qsv.c | 4 ++--
> > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index
> > > 9270b22..14f26c6 100644
> > > --- a/libavutil/hwcontext_qsv.c
> > > +++ b/libavutil/hwcontext_qsv.c
> > > @@ -313,6 +313,7 @@ static int qsv_init_surface(AVHWFramesContext *ctx,
> > > mfxFrameSurface1 *surf)
> > >  surf->Info.CropH  = ctx->height;
> > >  surf->Info.FrameRateExtN  = 25;
> > >  surf->Info.FrameRateExtD  = 1;
> > > +surf->Info.PicStruct  = MFX_PICSTRUCT_PROGRESSIVE;
> > >
> > >  return 0;
> > >  }
> > > @@ -325,8 +326,7 @@ static int qsv_init_pool(AVHWFramesContext *ctx,
> > > uint32_t fourcc)
> > >  int i, ret = 0;
> > >
> > >  if (ctx->initial_pool_size <= 0) {
> > > -av_log(ctx, AV_LOG_ERROR, "QSV requires a fixed frame pool
> > > size\n");
> >
> > Should keep this log message as a warning be better?
> >
> > > -return AVERROR(EINVAL);
> > > +ctx->initial_pool_size = 64;
> 
> That doesn't really feel appropriate. If a fixed size pool is required,
> the user should simply be forced to specify a size. Making it use a
> random value doesn't make too much sense to me, and the required size
> is going to depend on the caller's use cases. In addition 64 by default
> sounds like a huge waste of memory.

Thanks for your comment!
But I think it is better if we don't force the user to explicitly setup a value 
to get it work.
Less parameters means less burden for end-users. If this rule is not applicable 
here, please correct me.
I am not sure why a default workable value is not as good here. Could you share 
me more thought?
And there are more places that set default values to initial_pool_size:
Inside libavfilter/qsvvpp.c it also sets initial_pool_size to 64.
Inside avtools/avcov_qsv.c, it sets initial_pool_size to 32.
I am not sure do you have any comment on this? Will be 32 looks a little better?

Ruiling

> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure issue

2018-01-29 Thread Song, Ruiling
> -Original Message-
> From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of Luca
> Barbato
> Sent: Friday, January 26, 2018 9:26 PM
> To: libav-devel@libav.org
> Subject: Re: [libav-devel] [PATCH] hwcontext_qsv: Fix qsv hwupload failure 
> issue
> 
> On 26/01/2018 12:04, Mark Thompson wrote:
> > Thoughts?  I can send the set again if that would be helpful.
> 
> Please do :)
> 
> I'm still afraid that we should add yet another call to query the number
> of surfaces needed by each component and then call the setup with the
> actual value once we have it...
It sounds like a good idea. But I don't know too much about Libav internals.
So I am not sure if you can share more idea on this. How far we are from it?
And what kind of problems that need to be addressed before we arrive at that 
situation?

Ruiling
> 
> lu
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 06/12] vf_*_vaapi: Support increasing hardware frame pool size

2018-01-29 Thread Mark Thompson
Defaults to 10 frames to preserve compatibility, but can allocate
fewer if extra_hw_frames is set explicitly.
---
 libavfilter/vf_deinterlace_vaapi.c | 39 +++
 libavfilter/vf_scale_vaapi.c   | 42 +++---
 2 files changed, 33 insertions(+), 48 deletions(-)

diff --git a/libavfilter/vf_deinterlace_vaapi.c 
b/libavfilter/vf_deinterlace_vaapi.c
index 95a0f4041..082df8914 100644
--- a/libavfilter/vf_deinterlace_vaapi.c
+++ b/libavfilter/vf_deinterlace_vaapi.c
@@ -53,8 +53,6 @@ typedef struct DeintVAAPIContext {
 AVBufferRef   *input_frames_ref;
 AVHWFramesContext *input_frames;
 
-AVBufferRef   *output_frames_ref;
-AVHWFramesContext *output_frames;
 intoutput_height;
 intoutput_width;
 
@@ -236,6 +234,7 @@ static int deint_vaapi_config_output(AVFilterLink *outlink)
 DeintVAAPIContext*ctx = avctx->priv;
 AVVAAPIHWConfig *hwconfig = NULL;
 AVHWFramesConstraints *constraints = NULL;
+AVHWFramesContext *output_frames;
 AVVAAPIFramesContext *va_frames;
 VAStatus vas;
 int err;
@@ -287,34 +286,35 @@ static int deint_vaapi_config_output(AVFilterLink 
*outlink)
 goto fail;
 }
 
-ctx->output_frames_ref = av_hwframe_ctx_alloc(ctx->device_ref);
-if (!ctx->output_frames_ref) {
+outlink->hw_frames_ctx = av_hwframe_ctx_alloc(ctx->device_ref);
+if (!outlink->hw_frames_ctx) {
 av_log(avctx, AV_LOG_ERROR, "Failed to create HW frame context "
"for output.\n");
 err = AVERROR(ENOMEM);
 goto fail;
 }
 
-ctx->output_frames = (AVHWFramesContext*)ctx->output_frames_ref->data;
+output_frames = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
 
-ctx->output_frames->format= AV_PIX_FMT_VAAPI;
-ctx->output_frames->sw_format = ctx->input_frames->sw_format;
-ctx->output_frames->width = ctx->output_width;
-ctx->output_frames->height= ctx->output_height;
+output_frames->format= AV_PIX_FMT_VAAPI;
+output_frames->sw_format = ctx->input_frames->sw_format;
+output_frames->width = ctx->output_width;
+output_frames->height= ctx->output_height;
 
-// The number of output frames we need is determined by what follows
-// the filter.  If it's an encoder with complex frame reference
-// structures then this could be very high.
-ctx->output_frames->initial_pool_size = 10;
+output_frames->initial_pool_size = 4;
+
+err = ff_filter_init_hw_frames(avctx, outlink, 10);
+if (err < 0)
+goto fail;
 
-err = av_hwframe_ctx_init(ctx->output_frames_ref);
+err = av_hwframe_ctx_init(outlink->hw_frames_ctx);
 if (err < 0) {
 av_log(avctx, AV_LOG_ERROR, "Failed to initialise VAAPI frame "
"context for output: %d\n", err);
 goto fail;
 }
 
-va_frames = ctx->output_frames->hwctx;
+va_frames = output_frames->hwctx;
 
 av_assert0(ctx->va_context == VA_INVALID_ID);
 vas = vaCreateContext(ctx->hwctx->display, ctx->va_config,
@@ -340,18 +340,12 @@ static int deint_vaapi_config_output(AVFilterLink 
*outlink)
 outlink->frame_rate = av_mul_q(inlink->frame_rate,
(AVRational) { ctx->field_rate, 1 });
 
-outlink->hw_frames_ctx = av_buffer_ref(ctx->output_frames_ref);
-if (!outlink->hw_frames_ctx) {
-err = AVERROR(ENOMEM);
-goto fail;
-}
-
 av_freep();
 av_hwframe_constraints_free();
 return 0;
 
 fail:
-av_buffer_unref(>output_frames_ref);
+av_buffer_unref(>hw_frames_ctx);
 av_freep();
 av_hwframe_constraints_free();
 return err;
@@ -601,7 +595,6 @@ static av_cold void deint_vaapi_uninit(AVFilterContext 
*avctx)
 deint_vaapi_pipeline_uninit(avctx);
 
 av_buffer_unref(>input_frames_ref);
-av_buffer_unref(>output_frames_ref);
 av_buffer_unref(>device_ref);
 }
 
diff --git a/libavfilter/vf_scale_vaapi.c b/libavfilter/vf_scale_vaapi.c
index 4c8f2cf4e..0ab5518b5 100644
--- a/libavfilter/vf_scale_vaapi.c
+++ b/libavfilter/vf_scale_vaapi.c
@@ -22,6 +22,7 @@
 #include 
 
 #include "libavutil/avassert.h"
+#include "libavutil/common.h"
 #include "libavutil/hwcontext.h"
 #include "libavutil/hwcontext_vaapi.h"
 #include "libavutil/mem.h"
@@ -46,9 +47,6 @@ typedef struct ScaleVAAPIContext {
 AVBufferRef   *input_frames_ref;
 AVHWFramesContext *input_frames;
 
-AVBufferRef   *output_frames_ref;
-AVHWFramesContext *output_frames;
-
 char *output_format_string;
 enum AVPixelFormat output_format;
 int output_width;
@@ -83,7 +81,6 @@ static int scale_vaapi_pipeline_uninit(ScaleVAAPIContext *ctx)
 ctx->va_config = VA_INVALID_ID;
 }
 
-av_buffer_unref(>output_frames_ref);
 av_buffer_unref(>device_ref);
 ctx->hwctx = 0;
 
@@ -115,6 +112,7 @@ static int scale_vaapi_config_output(AVFilterLink *outlink)
 ScaleVAAPIContext *ctx = 

[libav-devel] [PATCH 04/12] lavc/dxva2: Don't add per-thread surfaces twice

2018-01-29 Thread Mark Thompson
This is already accounted for in the generic code, so it shouldn't also
be added here.
---
 libavcodec/dxva2.c | 4 
 1 file changed, 4 deletions(-)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index edc8ade96..f111d0b79 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -611,10 +611,6 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx,
 if (avctx->extra_hw_frames > 0)
 num_surfaces += avctx->extra_hw_frames;
 
-/* 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);
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 02/12] lavc/vaapi: Support increasing hardware frame pool size

2018-01-29 Thread Mark Thompson
---
 libavcodec/vaapi_decode.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/vaapi_decode.c b/libavcodec/vaapi_decode.c
index cc79875ef..7ff42317e 100644
--- a/libavcodec/vaapi_decode.c
+++ b/libavcodec/vaapi_decode.c
@@ -452,6 +452,9 @@ static int vaapi_decode_make_config(AVCodecContext *avctx,
 default:
 frames->initial_pool_size += 2;
 }
+
+if (avctx->extra_hw_frames > 0)
+frames->initial_pool_size += avctx->extra_hw_frames;
 }
 
 av_hwframe_constraints_free();
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 09/12] hwcontext: Fix documentation for av_hwdevice_ctx_alloc()

2018-01-29 Thread Mark Thompson
From: Jun Zhao 

From ffmpeg commit 9365dfcbf665b83b2e60c5ec5e2abf1f0a49e2c3.

Signed-off-by: Jun Zhao 
Signed-off-by: Mark Thompson 
---
 libavutil/hwcontext.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext.h b/libavutil/hwcontext.h
index 203ea510e..ba293d72e 100644
--- a/libavutil/hwcontext.h
+++ b/libavutil/hwcontext.h
@@ -252,8 +252,9 @@ const char *av_hwdevice_get_type_name(enum AVHWDeviceType 
type);
 enum AVHWDeviceType av_hwdevice_iterate_types(enum AVHWDeviceType prev);
 
 /**
- * Allocate an AVHWDeviceContext for a given pixel format.
+ * Allocate an AVHWDeviceContext for a given hardware type.
  *
+ * @param type the type of the hardware device to allocate.
  * @return a reference to the newly created AVHWDeviceContext on success or 
NULL
  * on failure.
  */
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 01/12] lavc: Add support for increasing hardware frame pool sizes

2018-01-29 Thread Mark Thompson
AVCodecContext.extra_hw_frames is added to the size of hardware frame
pools created by libavcodec for APIs which require fixed-size pools.
This allows the user to keep references to a greater number of frames
after decode, which may be necessary for some use-cases.

It is also added to the initial_pool_size value returned by
avcodec_get_hw_frames_parameters() if a fixed-size pool is required.
---
On 26/01/18 23:39, wm4 wrote:
> On Fri, 26 Jan 2018 23:30:48 +
> Mark Thompson  wrote:
> 
>> On 26/01/18 23:13, Mark Thompson wrote:
>>> AVFilterContext.extra_hw_frames functions identically to the field of
>>> the same name in AVCodecContext.  
>>
>> Of course, that field doesn't actually exist before this patch now.  Updated 
>> to reflect that.
>>
>> Still, should the field be in AVCodecContext as well?  (The 
>> hw_frames_parameters API can do this for library users, but it isn't usable 
>> in avconv.)
> 
> Probably makes sense. How else would avconv control this? (Although in
> theory avconv could use the avcodec_get_hw_frames_parameters() API.)
> 
> I assume actually this field would just be added to the frames context
> returned by avcodec_get_hw_frames_parameters(), since that is used
> internally by most hwaccels to allocate a frames context if
> hw_device_ctx is used.

Yep, that sounds like a good way to do it.

Here is new series with that change and some other minor fixups.  (Not tested 
on Windows yet.)

Thanks,

- Mark


 doc/APIchanges |  3 +++
 libavcodec/avcodec.h   | 14 ++
 libavcodec/options_table.h |  1 +
 3 files changed, 18 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index 0bde3a052..62c7a17e5 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2017-03-23
 
 API changes, most recent first:
 
+2018-xx-xx - xxx - lavc 58.x+1.0 - avcodec.h
+  Add AVCodecContext.extra_hw_frames.
+
 2017-xx-xx - xxx - lavc 58.8.0 - avcodec.h
   Add const to AVCodecContext.hwaccel.
 
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 7eaa0c927..03a3d5bd6 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -2739,6 +2739,20 @@ typedef struct AVCodecContext {
  * AVCodecContext.get_format callback)
  */
 int hwaccel_flags;
+
+/**
+ * Video decoding only.  Sets the number of extra hardware frames which
+ * the decoder will allocate for use by the caller.  This must be set
+ * before avcodec_open2() is called.
+ *
+ * Some hardware decoders require all frames that they will use for
+ * output to be defined in advance before decoding starts.  For such
+ * decoders, the hardware frame pool must therefore be of a fixed size.
+ * The extra frames set here are on top of any number that the decoder
+ * needs internally in order to operate normally (for example, frames
+ * used as reference pictures).
+ */
+int extra_hw_frames;
 } AVCodecContext;
 
 /**
diff --git a/libavcodec/options_table.h b/libavcodec/options_table.h
index 925ef376f..4b0a8344d 100644
--- a/libavcodec/options_table.h
+++ b/libavcodec/options_table.h
@@ -419,6 +419,7 @@ static const AVOption avcodec_options[] = {
 {"side_data_only_packets", NULL, OFFSET(side_data_only_packets), 
AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, A|V|E },
 #endif
 {"apply_cropping", NULL, OFFSET(apply_cropping), AV_OPT_TYPE_INT, { .i64 = 1 
}, 0, 1, V | D },
+{"extra_hw_frames", "Number of extra hardware frames to allocate for the 
user", OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
V|D },
 {NULL},
 };
 
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 03/12] lavc/dxva2: Support increasing hardware frame pool size

2018-01-29 Thread Mark Thompson
---
 libavcodec/dxva2.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c
index e34409d44..edc8ade96 100644
--- a/libavcodec/dxva2.c
+++ b/libavcodec/dxva2.c
@@ -608,6 +608,9 @@ int ff_dxva2_common_frame_params(AVCodecContext *avctx,
 else
 num_surfaces += 2;
 
+if (avctx->extra_hw_frames > 0)
+num_surfaces += avctx->extra_hw_frames;
+
 /* add extra surfaces for frame threading */
 if (avctx->active_thread_type & FF_THREAD_FRAME)
 num_surfaces += avctx->thread_count;
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 08/12] vf_hwupload/hwmap: Support setting a fixed pool size

2018-01-29 Thread Mark Thompson
These filters do not directly know whether the API they are using will
support dynamic frame pools, so this is somewhat tricky.  If the user
set extra_hw_frames, we assume that they are aware of the problem and
set a fixed size based on that.  If not, most cases use dynamic sizing
just like they did previously.  The hardware-reverse-mapping case for
hwmap previously had a large fixed size (64) here, primarily as a hack
for QSV use - this is removed and extra_hw_frames will need to be set
for QSV to work since it requires fixed-size pools (as the other cases
do, and which didn't work before).
---
 libavfilter/vf_hwmap.c| 7 ++-
 libavfilter/vf_hwupload.c | 3 +++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/libavfilter/vf_hwmap.c b/libavfilter/vf_hwmap.c
index b28cb2145..d5ad2768f 100644
--- a/libavfilter/vf_hwmap.c
+++ b/libavfilter/vf_hwmap.c
@@ -138,7 +138,9 @@ static int hwmap_config_output(AVFilterLink *outlink)
 frames->sw_format = hwfc->sw_format;
 frames->width = hwfc->width;
 frames->height= hwfc->height;
-frames->initial_pool_size = 64;
+
+if (avctx->extra_hw_frames >= 0)
+frames->initial_pool_size = 2 + avctx->extra_hw_frames;
 
 err = av_hwframe_ctx_init(ctx->hwframes_ref);
 if (err < 0) {
@@ -218,6 +220,9 @@ static int hwmap_config_output(AVFilterLink *outlink)
 hwfc->width = inlink->w;
 hwfc->height= inlink->h;
 
+if (avctx->extra_hw_frames >= 0)
+hwfc->initial_pool_size = 2 + avctx->extra_hw_frames;
+
 err = av_hwframe_ctx_init(ctx->hwframes_ref);
 if (err < 0) {
 av_log(avctx, AV_LOG_ERROR, "Failed to create frame "
diff --git a/libavfilter/vf_hwupload.c b/libavfilter/vf_hwupload.c
index 8cca9f42e..af4ff9b81 100644
--- a/libavfilter/vf_hwupload.c
+++ b/libavfilter/vf_hwupload.c
@@ -133,6 +133,9 @@ static int hwupload_config_output(AVFilterLink *outlink)
 ctx->hwframes->width = inlink->w;
 ctx->hwframes->height= inlink->h;
 
+if (avctx->extra_hw_frames >= 0)
+ctx->hwframes->initial_pool_size = 2 + avctx->extra_hw_frames;
+
 err = av_hwframe_ctx_init(ctx->hwframes_ref);
 if (err < 0)
 goto fail;
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 07/12] vf_scale_qsv: Support increasing hardware frame pool size

2018-01-29 Thread Mark Thompson
The deinterlacer does not change, because it does not allocate any new
frames (for output it uses the same pool as the input).
---
 libavfilter/vf_scale_qsv.c | 26 +++---
 1 file changed, 11 insertions(+), 15 deletions(-)

diff --git a/libavfilter/vf_scale_qsv.c b/libavfilter/vf_scale_qsv.c
index 8ef77835d..c568e9625 100644
--- a/libavfilter/vf_scale_qsv.c
+++ b/libavfilter/vf_scale_qsv.c
@@ -71,7 +71,6 @@ enum var_name {
 typedef struct QSVScaleContext {
 const AVClass *class;
 
-AVBufferRef *out_frames_ref;
 /* a clone of the main session, used internally for scaling */
 mfxSession   session;
 
@@ -134,7 +133,6 @@ static void qsvscale_uninit(AVFilterContext *ctx)
 MFXClose(s->session);
 s->session = NULL;
 }
-av_buffer_unref(>out_frames_ref);
 
 av_freep(>mem_ids_in);
 av_freep(>mem_ids_out);
@@ -163,6 +161,7 @@ static int init_out_pool(AVFilterContext *ctx,
  int out_width, int out_height)
 {
 QSVScaleContext *s = ctx->priv;
+AVFilterLink *outlink = ctx->outputs[0];
 
 AVHWFramesContext *in_frames_ctx;
 AVHWFramesContext *out_frames_ctx;
@@ -183,21 +182,25 @@ static int init_out_pool(AVFilterContext *ctx,
 in_format = in_frames_ctx->sw_format;
 out_format= (s->format == AV_PIX_FMT_NONE) ? in_format : s->format;
 
-s->out_frames_ref = av_hwframe_ctx_alloc(in_frames_ctx->device_ref);
-if (!s->out_frames_ref)
+outlink->hw_frames_ctx = av_hwframe_ctx_alloc(in_frames_ctx->device_ref);
+if (!outlink->hw_frames_ctx)
 return AVERROR(ENOMEM);
-out_frames_ctx   = (AVHWFramesContext*)s->out_frames_ref->data;
+out_frames_ctx   = (AVHWFramesContext*)outlink->hw_frames_ctx->data;
 out_frames_hwctx = out_frames_ctx->hwctx;
 
 out_frames_ctx->format= AV_PIX_FMT_QSV;
 out_frames_ctx->width = FFALIGN(out_width,  32);
 out_frames_ctx->height= FFALIGN(out_height, 32);
 out_frames_ctx->sw_format = out_format;
-out_frames_ctx->initial_pool_size = 32;
+out_frames_ctx->initial_pool_size = 4;
 
 out_frames_hwctx->frame_type = in_frames_hwctx->frame_type;
 
-ret = av_hwframe_ctx_init(s->out_frames_ref);
+ret = ff_filter_init_hw_frames(ctx, outlink, 32);
+if (ret < 0)
+return ret;
+
+ret = av_hwframe_ctx_init(outlink->hw_frames_ctx);
 if (ret < 0)
 return ret;
 
@@ -264,7 +267,7 @@ static int init_out_session(AVFilterContext *ctx)
 
 QSVScaleContext   *s = ctx->priv;
 AVHWFramesContext *in_frames_ctx = 
(AVHWFramesContext*)ctx->inputs[0]->hw_frames_ctx->data;
-AVHWFramesContext*out_frames_ctx = 
(AVHWFramesContext*)s->out_frames_ref->data;
+AVHWFramesContext*out_frames_ctx = 
(AVHWFramesContext*)ctx->outputs[0]->hw_frames_ctx->data;
 AVQSVFramesContext  *in_frames_hwctx = in_frames_ctx->hwctx;
 AVQSVFramesContext *out_frames_hwctx = out_frames_ctx->hwctx;
 AVQSVDeviceContext *device_hwctx = in_frames_ctx->device_ctx->hwctx;
@@ -405,8 +408,6 @@ static int init_out_session(AVFilterContext *ctx)
 static int init_scale_session(AVFilterContext *ctx, int in_width, int 
in_height,
   int out_width, int out_height)
 {
-QSVScaleContext *s = ctx->priv;
-
 int ret;
 
 qsvscale_uninit(ctx);
@@ -419,11 +420,6 @@ static int init_scale_session(AVFilterContext *ctx, int 
in_width, int in_height,
 if (ret < 0)
 return ret;
 
-av_buffer_unref(>outputs[0]->hw_frames_ctx);
-ctx->outputs[0]->hw_frames_ctx = av_buffer_ref(s->out_frames_ref);
-if (!ctx->outputs[0]->hw_frames_ctx)
-return AVERROR(ENOMEM);
-
 return 0;
 }
 
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 11/12] hwcontext: Perform usual uninitialisation on derived frames contexts

2018-01-29 Thread Mark Thompson
---
 libavutil/hwcontext.c | 17 +++--
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 157b73872..3ac17572b 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -205,19 +205,16 @@ static void hwframe_ctx_free(void *opaque, uint8_t *data)
 {
 AVHWFramesContext *ctx = (AVHWFramesContext*)data;
 
-if (ctx->internal->source_frames) {
-av_buffer_unref(>internal->source_frames);
+if (ctx->internal->pool_internal)
+av_buffer_pool_uninit(>internal->pool_internal);
 
-} else {
-if (ctx->internal->pool_internal)
-av_buffer_pool_uninit(>internal->pool_internal);
+if (ctx->internal->hw_type->frames_uninit)
+ctx->internal->hw_type->frames_uninit(ctx);
 
-if (ctx->internal->hw_type->frames_uninit)
-ctx->internal->hw_type->frames_uninit(ctx);
+if (ctx->free)
+ctx->free(ctx);
 
-if (ctx->free)
-ctx->free(ctx);
-}
+av_buffer_unref(>internal->source_frames);
 
 av_buffer_unref(>device_ref);
 
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 12/12] hwcontext: Fix memory leak on derived frame allocation failure

2018-01-29 Thread Mark Thompson
---
 libavutil/hwcontext.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 3ac17572b..34fb720a7 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -467,8 +467,10 @@ int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, 
AVFrame *frame, int flags)
 
 ret = av_hwframe_get_buffer(ctx->internal->source_frames,
 src_frame, 0);
-if (ret < 0)
+if (ret < 0) {
+av_frame_free(_frame);
 return ret;
+}
 
 ret = av_hwframe_map(frame, src_frame,
  ctx->internal->source_allocation_map_flags);
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 10/12] hwcontext: Perform usual initialisation on derived device contexts

2018-01-29 Thread Mark Thompson
The initialisation should be common.  For libmfx, it was previously
happening in the derivation function and this moves it out.
---
 libavutil/hwcontext.c |  4 
 libavutil/hwcontext_qsv.c | 11 ---
 2 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/libavutil/hwcontext.c b/libavutil/hwcontext.c
index 6dc95bba1..157b73872 100644
--- a/libavutil/hwcontext.c
+++ b/libavutil/hwcontext.c
@@ -643,6 +643,10 @@ int av_hwdevice_ctx_create_derived(AVBufferRef 
**dst_ref_ptr,
 goto fail;
 
 done:
+ret = av_hwdevice_ctx_init(dst_ref);
+if (ret < 0)
+goto fail;
+
 *dst_ref_ptr = dst_ref;
 return 0;
 
diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index 9270b2258..9fa603c35 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -989,7 +989,6 @@ static int qsv_device_derive_from_child(AVHWDeviceContext 
*ctx,
 int flags)
 {
 AVQSVDeviceContext *hwctx = ctx->hwctx;
-QSVDeviceContext   *s = ctx->internal->priv;
 
 mfxVersionver = { { 3, 1 } };
 mfxHDLhandle;
@@ -1058,16 +1057,6 @@ static int 
qsv_device_derive_from_child(AVHWDeviceContext *ctx,
 goto fail;
 }
 
-ret = qsv_device_init(ctx);
-if (ret < 0)
-goto fail;
-if (s->handle_type != handle_type) {
-av_log(ctx, AV_LOG_ERROR, "Error in child device handle setup: "
-   "type mismatch (%d != %d).\n", s->handle_type, handle_type);
-err = AVERROR_UNKNOWN;
-goto fail;
-}
-
 return 0;
 
 fail:
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

[libav-devel] [PATCH 05/12] lavfi: Add support for increasing hardware frame pool sizes

2018-01-29 Thread Mark Thompson
AVFilterContext.extra_hw_frames functions identically to the field of
the same name in AVCodecContext.
---
 doc/APIchanges |  3 +++
 libavfilter/avfilter.c | 23 +++
 libavfilter/avfilter.h | 16 
 libavfilter/internal.h | 16 
 4 files changed, 58 insertions(+)

diff --git a/doc/APIchanges b/doc/APIchanges
index 62c7a17e5..824333b9a 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@ libavutil: 2017-03-23
 
 API changes, most recent first:
 
+2018-xx-xx - xxx - lavfi 7.x+1.0 - avfilter.h
+  Add AVFilterContext.extra_hw_frames.
+
 2018-xx-xx - xxx - lavc 58.x+1.0 - avcodec.h
   Add AVCodecContext.extra_hw_frames.
 
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 83c1a7c20..2c4a385ea 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -368,6 +368,8 @@ static const AVOption avfilter_options[] = {
 { "thread_type", "Allowed thread types", OFFSET(thread_type), 
AV_OPT_TYPE_FLAGS,
 { .i64 = AVFILTER_THREAD_SLICE }, 0, INT_MAX, FLAGS, "thread_type" },
 { "slice", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = AVFILTER_THREAD_SLICE 
}, .unit = "thread_type" },
+{ "extra_hw_frames", "Number of extra hardware frames to allocate for the 
user",
+OFFSET(extra_hw_frames), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, INT_MAX, 
FLAGS },
 { NULL },
 };
 
@@ -707,3 +709,24 @@ const AVClass *avfilter_get_class(void)
 {
 return _class;
 }
+
+int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
+ int default_pool_size)
+{
+AVHWFramesContext *frames;
+
+// Must already be set by caller.
+av_assert0(link->hw_frames_ctx);
+
+frames = (AVHWFramesContext*)link->hw_frames_ctx->data;
+
+if (frames->initial_pool_size == 0) {
+// Dynamic allocation is necessarily supported.
+} else if (avctx->extra_hw_frames >= 0) {
+frames->initial_pool_size += avctx->extra_hw_frames;
+} else {
+frames->initial_pool_size = default_pool_size;
+}
+
+return 0;
+}
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 6df69dbbb..66cc23ce8 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -311,6 +311,22 @@ struct AVFilterContext {
  * hardware context information.
  */
 AVBufferRef *hw_device_ctx;
+
+/**
+ * Sets the number of extra hardware frames which the filter will
+ * allocate on its output links for use in following filters or by
+ * the caller.
+ *
+ * Some hardware filters require all frames that they will use for
+ * output to be defined in advance before filtering starts.  For such
+ * filters, any hardware frame pools used for output must therefore be
+ * of fixed size.  The extra frames set here are on top of any number
+ * that the filter needs internally in order to operate normally.
+ *
+ * This field must be set before the graph containing this filer is
+ * configured.
+ */
+int extra_hw_frames;
 };
 
 /**
diff --git a/libavfilter/internal.h b/libavfilter/internal.h
index a377f9b2b..d17f917c6 100644
--- a/libavfilter/internal.h
+++ b/libavfilter/internal.h
@@ -226,4 +226,20 @@ void ff_filter_graph_remove_filter(AVFilterGraph *graph, 
AVFilterContext *filter
  */
 #define FF_FILTER_FLAG_HWFRAME_AWARE (1 << 0)
 
+/**
+ * Perform any additional setup required for hardware frames.
+ *
+ * link->hw_frames_ctx must be set before calling this function.
+ * Inside link->hw_frames_ctx, the fields format, sw_format, width and
+ * height must be set.  If dynamically allocated pools are not supported,
+ * then initial_pool_size must also be set, to the minimum hardware frame
+ * pool size necessary for decode (taking into account reference frames
+ * and delay as appropriate).  If default_pool_size is nonzero, then it
+ * will be used as the pool size if no other modification takes place
+ * (this can be used to preserve compatibility).
+ */
+int ff_filter_init_hw_frames(AVFilterContext *avctx, AVFilterLink *link,
+ int default_pool_size);
+
+
 #endif /* AVFILTER_INTERNAL_H */
-- 
2.11.0

___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] lavc/qsvdec: expose frame pic_type and key_frame

2018-01-29 Thread Maxym Dmytrychenko
LGTM as well,
will take care of it this week.

On Mon, Jan 29, 2018 at 9:20 AM, Luca Barbato  wrote:

> On 29/01/2018 08:31, Zhong Li wrote:
>
>> Currently key_frame and pict_type are unset.
>> Add an extra param to fetch the picture type from qsv decoder
>>
>> Signed-off-by: ChaoX A Liu 
>> Signed-off-by: Zhong Li 
>> ---
>>   libavcodec/qsv.c  | 24 
>>   libavcodec/qsv_internal.h |  3 +++
>>   libavcodec/qsvdec.c   |  7 +++
>>   3 files changed, 34 insertions(+)
>>
>> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
>> index e78633d..9639bf7 100644
>> --- a/libavcodec/qsv.c
>> +++ b/libavcodec/qsv.c
>> @@ -195,6 +195,30 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx,
>> QSVFrame *frame)
>>   return AVERROR_BUG;
>>   }
>>   +enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)
>> +{
>> +enum AVPictureType type = AV_PICTURE_TYPE_NONE;
>> +switch (mfx_pic_type & 0x7) {
>> +case MFX_FRAMETYPE_I:
>> +if (mfx_pic_type & MFX_FRAMETYPE_S)
>> +type = AV_PICTURE_TYPE_SI;
>> +else
>> +type = AV_PICTURE_TYPE_I;
>> +break;
>> +case MFX_FRAMETYPE_B:
>> +type = AV_PICTURE_TYPE_B;
>> +break;
>> +case MFX_FRAMETYPE_P:
>> + if (mfx_pic_type & MFX_FRAMETYPE_S)
>> +type = AV_PICTURE_TYPE_SP;
>> +else
>> +type = AV_PICTURE_TYPE_P;
>> +break;
>> +}
>> +
>> +return type;
>> +}
>> +
>>   static int qsv_load_plugins(mfxSession session, const char
>> *load_plugins,
>>   void *logctx)
>>   {
>> diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
>> index 975c8de..07ddc59 100644
>> --- a/libavcodec/qsv_internal.h
>> +++ b/libavcodec/qsv_internal.h
>> @@ -48,6 +48,8 @@ typedef struct QSVMid {
>>   typedef struct QSVFrame {
>>   AVFrame *frame;
>>   mfxFrameSurface1 surface;
>> +mfxExtDecodedFrameInfo dec_info;
>> +mfxExtBuffer *ext_param;
>> int queued;
>>   int used;
>> @@ -83,6 +85,7 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
>>   int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile);
>> int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);
>> +enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
>> int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession
>> *session,
>>const char *load_plugins);
>> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
>> index f31172d..9ee4177 100644
>> --- a/libavcodec/qsvdec.c
>> +++ b/libavcodec/qsvdec.c
>> @@ -232,6 +232,11 @@ static int alloc_frame(AVCodecContext *avctx,
>> QSVContext *q, QSVFrame *frame)
>> frame->surface.Data.MemId = >frames_ctx.mids[ret];
>>   }
>> +frame->surface.Data.ExtParam = >ext_param;
>> +frame->surface.Data.NumExtParam = 1;
>> +frame->ext_param = (mfxExtBuffer*)>dec_info;
>> +frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
>> +frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
>> frame->used = 1;
>>   @@ -416,6 +421,8 @@ FF_ENABLE_DEPRECATION_WARNINGS
>>   outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
>>   frame->interlaced_frame =
>>   !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
>> +frame->pict_type = ff_qsv_map_pictype(out_frame->
>> dec_info.FrameType);
>> +frame->key_frame = !!(out_frame->dec_info.FrameType &
>> MFX_FRAMETYPE_IDR);
>> /* update the surface properties */
>>   if (avctx->pix_fmt == AV_PIX_FMT_QSV)
>>
>>
> Seems fine to me.
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] vc1: skip motion compensation when data for last picture is invalid

2018-01-29 Thread Luca Barbato

On 28/01/2018 17:46, Sean McGovern wrote:

Bug-Id: 1101
Cc: libav-sta...@libav.org
---
  libavcodec/vc1_mc.c | 5 +
  1 file changed, 5 insertions(+)

diff --git a/libavcodec/vc1_mc.c b/libavcodec/vc1_mc.c
index f4632d6..abdc9e3 100644
--- a/libavcodec/vc1_mc.c
+++ b/libavcodec/vc1_mc.c
@@ -689,6 +689,11 @@ void ff_vc1_mc_4mv_chroma4(VC1Context *v, int
dir, int dir2, int avg)
  if (s->avctx->flags & AV_CODEC_FLAG_GRAY)
  return;

+if (s->last_picture.f 


This should be unnecessary.

&& !s->last_picture.f->data[1]) {

+  av_log(s->avctx, AV_LOG_ERROR, "Bad data in last picture frame.\n");
+  return;
+}
+
  for (i = 0; i < 4; i++) {
  int d = i < 2 ? dir: dir2;
  tx = s->mv[d][i][0];



Patch ok to me.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] lavc/qsvdec: expose frame pic_type and key_frame

2018-01-29 Thread Luca Barbato

On 29/01/2018 08:31, Zhong Li wrote:

Currently key_frame and pict_type are unset.
Add an extra param to fetch the picture type from qsv decoder

Signed-off-by: ChaoX A Liu 
Signed-off-by: Zhong Li 
---
  libavcodec/qsv.c  | 24 
  libavcodec/qsv_internal.h |  3 +++
  libavcodec/qsvdec.c   |  7 +++
  3 files changed, 34 insertions(+)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e78633d..9639bf7 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -195,6 +195,30 @@ int ff_qsv_find_surface_idx(QSVFramesContext *ctx, 
QSVFrame *frame)
  return AVERROR_BUG;
  }
  
+enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type)

+{
+enum AVPictureType type = AV_PICTURE_TYPE_NONE;
+switch (mfx_pic_type & 0x7) {
+case MFX_FRAMETYPE_I:
+if (mfx_pic_type & MFX_FRAMETYPE_S)
+type = AV_PICTURE_TYPE_SI;
+else
+type = AV_PICTURE_TYPE_I;
+break;
+case MFX_FRAMETYPE_B:
+type = AV_PICTURE_TYPE_B;
+break;
+case MFX_FRAMETYPE_P:
+ if (mfx_pic_type & MFX_FRAMETYPE_S)
+type = AV_PICTURE_TYPE_SP;
+else
+type = AV_PICTURE_TYPE_P;
+break;
+}
+
+return type;
+}
+
  static int qsv_load_plugins(mfxSession session, const char *load_plugins,
  void *logctx)
  {
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 975c8de..07ddc59 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -48,6 +48,8 @@ typedef struct QSVMid {
  typedef struct QSVFrame {
  AVFrame *frame;
  mfxFrameSurface1 surface;
+mfxExtDecodedFrameInfo dec_info;
+mfxExtBuffer *ext_param;
  
  int queued;

  int used;
@@ -83,6 +85,7 @@ int ff_qsv_codec_id_to_mfx(enum AVCodecID codec_id);
  int ff_qsv_profile_to_mfx(enum AVCodecID codec_id, int profile);
  
  int ff_qsv_map_pixfmt(enum AVPixelFormat format, uint32_t *fourcc);

+enum AVPictureType ff_qsv_map_pictype(int mfx_pic_type);
  
  int ff_qsv_init_internal_session(AVCodecContext *avctx, mfxSession *session,

   const char *load_plugins);
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index f31172d..9ee4177 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -232,6 +232,11 @@ static int alloc_frame(AVCodecContext *avctx, QSVContext 
*q, QSVFrame *frame)
  
  frame->surface.Data.MemId = >frames_ctx.mids[ret];

  }
+frame->surface.Data.ExtParam = >ext_param;
+frame->surface.Data.NumExtParam = 1;
+frame->ext_param = (mfxExtBuffer*)>dec_info;
+frame->dec_info.Header.BufferId = MFX_EXTBUFF_DECODED_FRAME_INFO;
+frame->dec_info.Header.BufferSz = sizeof(frame->dec_info);
  
  frame->used = 1;
  
@@ -416,6 +421,8 @@ FF_ENABLE_DEPRECATION_WARNINGS

  outsurf->Info.PicStruct & MFX_PICSTRUCT_FIELD_TFF;
  frame->interlaced_frame =
  !(outsurf->Info.PicStruct & MFX_PICSTRUCT_PROGRESSIVE);
+frame->pict_type = ff_qsv_map_pictype(out_frame->dec_info.FrameType);
+frame->key_frame = !!(out_frame->dec_info.FrameType & 
MFX_FRAMETYPE_IDR);
  
  /* update the surface properties */

  if (avctx->pix_fmt == AV_PIX_FMT_QSV)



Seems fine to me.
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel