Re: [libav-devel] [PATCH] qsvenc: AV_PIX_FMT_QSV path should release frame

2018-09-18 Thread Maxym Dmytrychenko
On Tue, Sep 18, 2018 at 6:45 PM Li, Zhong  wrote:

> > From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
> Luca
> > Barbato
> > Sent: Wednesday, September 19, 2018 12:11 AM
> > To: libav-devel@libav.org
> > Subject: Re: [libav-devel] [PATCH] qsvenc: AV_PIX_FMT_QSV path should
> > release frame
> >
> > On 18/09/2018 09:54, Maxym Dmytrychenko wrote:
> > > Fixes high memory usage, now is back to normal.
> > >
> > > Can be checked as:
> > > -hwaccel qsv -c:v h264_qsv -i ../h264-conformance/CANL2_Sony_E.jsv
> > > -c:v h264_qsv -b:v 2000k -y qsv.mp4
> > > ---
> > >  libavcodec/qsvenc.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
> > > 611449cbe..17a0559f3 100644
> > > --- a/libavcodec/qsvenc.c
> > > +++ b/libavcodec/qsvenc.c
> > > @@ -1028,6 +1028,9 @@ static void
> > clear_unused_frames(QSVEncContext *q)
> > >  QSVFrame *cur = q->work_frames;
> > >  while (cur) {
> > >  if (cur->used && !cur->surface.Data.Locked) {
> > > +if (cur->frame->format == AV_PIX_FMT_QSV) {
> > > +av_frame_unref(cur->frame);
> > > +}
> > >  cur->used = 0;
> > >  }
> > >  cur = cur->next;
> > >
> >
> > Please put a note about why this is needed (and safe to do).
> >
> > lu
>
> I am still confused by the original commit (
> https://patchwork.libav.org/patch/64323/ ) which introduce the regression:
>  if (cur->used && !cur->surface.Data.Locked) {
> -av_frame_unref(cur->frame);
>  cur->used = 0;
>  }
> It made sense for qsv decoding + qsv encoding pipeline(both GPU memory
> mode, thus format = AV_PIX_FMT_QSV, and system memory mode, thus format !=
> AV_PIX_FMT_QSV).
> Because if it is unlocked, qsv decoder doesn't need this surface any more,
> then we can release it.
> Removing "av_frame_unref(cur->frame)" is breaking qsv decoding + qsv
> encoding pipeline. The patch above just fix GPU memory mode case, but
> doesn’t work for system mode case of qsv decoding+ qsv encoding.
>
>
>
should be fixed by now for any case, or ?

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

[libav-devel] [PATCH] qsvenc: AV_PIX_FMT_QSV path should release frame

2018-09-18 Thread Maxym Dmytrychenko
Fixes high memory usage, now is back to normal.

Can be checked as:
-hwaccel qsv -c:v h264_qsv -i ../h264-conformance/CANL2_Sony_E.jsv -c:v
h264_qsv -b:v 2000k -y qsv.mp4
---
 libavcodec/qsvenc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index 611449cbe..17a0559f3 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1028,6 +1028,9 @@ static void clear_unused_frames(QSVEncContext *q)
 QSVFrame *cur = q->work_frames;
 while (cur) {
 if (cur->used && !cur->surface.Data.Locked) {
+if (cur->frame->format == AV_PIX_FMT_QSV) {
+av_frame_unref(cur->frame);
+}
 cur->used = 0;
 }
 cur = cur->next;
-- 
2.15.2 (Apple Git-101.1)

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

Re: [libav-devel] [PATCH v7] qsvvpp: Fix to perform full init only when needed

2018-09-03 Thread Maxym Dmytrychenko
On Mon, Sep 3, 2018 at 11:20 AM Li, Zhong  wrote:

> > From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
> > Maxym Dmytrychenko
> > Sent: Monday, September 3, 2018 2:07 AM
> > To: libav-devel@libav.org
> > Subject: [libav-devel] [PATCH v7] qsvvpp: Fix to perform full init only
> when
> > needed
> >
> > From: Joe Olivas 
> >
> > Removing unused VPP sessions by initializing only when used in order to
> help
> > reduce CPU utilization. Thanks to Maxym for the guidance.
> >
> > Signed-off-by: Joe Olivas 
> > Signed-off-by: Maxym Dmytrychenko 
>
> Patch LGTM. Just wonder how much CPU utilization can be reduced?
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel


thank you as well

5-10% of CPU utilization can be reduced

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

[libav-devel] [PATCH v7] qsvvpp: Fix to perform full init only when needed

2018-09-02 Thread Maxym Dmytrychenko
From: Joe Olivas 

Removing unused VPP sessions by initializing only when used in order to help 
reduce CPU utilization. Thanks to Maxym for the guidance.

Signed-off-by: Joe Olivas 
Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 83 +++
 1 file changed, 77 insertions(+), 6 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..0cfcc01fe 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -23,6 +23,10 @@
 
 #include "config.h"
 
+#if HAVE_PTHREADS
+#include 
+#endif
+
 #if CONFIG_VAAPI
 #include "hwcontext_vaapi.h"
 #endif
@@ -56,7 +60,13 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+int session_download_init;
 mfxSession session_upload;
+int session_upload_init;
+#if HAVE_PTHREADS
+pthread_mutex_t session_lock;
+pthread_cond_t session_cond;
+#endif
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -147,12 +157,19 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 MFXClose(s->session_download);
 }
 s->session_download = NULL;
+s->session_download_init = 0;
 
 if (s->session_upload) {
 MFXVideoVPP_Close(s->session_upload);
 MFXClose(s->session_upload);
 }
 s->session_upload = NULL;
+s->session_upload_init = 0;
+
+#if HAVE_PTHREADS
+pthread_mutex_destroy(>session_lock);
+pthread_cond_destroy(>session_cond);
+#endif
 
 av_freep(>mem_ids);
 av_freep(>surface_ptrs);
@@ -535,13 +552,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
+s->session_download = NULL;
+s->session_upload   = NULL;
 
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
+s->session_download_init = 0;
+s->session_upload_init   = 0;
+
+#if HAVE_PTHREADS
+pthread_mutex_init(>session_lock, NULL);
+pthread_cond_init(>session_cond, NULL);
+#endif
 
 return 0;
 }
@@ -740,6 +760,32 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = 0;
+
+while (!s->session_download_init && !s->session_download && !ret) {
+#if HAVE_PTHREADS
+   if (pthread_mutex_trylock(>session_lock) == 0) {
+#endif
+if (!s->session_download_init) {
+ret = qsv_init_internal_session(ctx, >session_download, 0);
+if (s->session_download)
+s->session_download_init = 1;
+}
+#if HAVE_PTHREADS
+pthread_mutex_unlock(>session_lock);
+pthread_cond_signal(>session_cond);
+} else {
+pthread_mutex_lock(>session_lock);
+while (!s->session_download_init && !s->session_download) {
+pthread_cond_wait(>session_cond, >session_lock);
+}
+pthread_mutex_unlock(>session_lock);
+}
+#endif
+}
+
+if (ret < 0)
+return ret;
 
 if (!s->session_download) {
 if (s->child_frames_ref)
@@ -787,6 +833,31 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret;
+
+while (!s->session_upload_init && !s->session_upload && !ret) {
+#if HAVE_PTHREADS
+   if (pthread_mutex_trylock(>session_lock) == 0) {
+#endif
+if (!s->session_upload_init) {
+ret = qsv_init_internal_session(ctx, >session_upload, 1);
+if (s->session_upload)
+s->session_upload_init = 1;
+}
+#if HAVE_PTHREADS
+pthread_mutex_unlock(>session_lock);
+pthread_cond_signal(>session_cond);
+} else {
+pthread_mutex_lock(>session_lock);
+while (!s->session_upload_init && !s->session_upload) {
+pthread_cond_wait(>session_cond, >session_lock);
+}
+pthread_mutex_unlock(>session_lock);
+}
+#endif
+}
+if (ret < 0)
+return ret;
 
 if (!s->session_upload) {
 if (s->child_frames_ref)
-- 
2.15.2 (Apple Git-101.1)

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

Re: [libav-devel] [PATCH v6] qsvvpp: Fix to perform full init only when needed

2018-08-24 Thread Maxym Dmytrychenko
On Thu, Jul 26, 2018 at 8:36 PM Rogozhkin, Dmitry V <
dmitry.v.rogozh...@intel.com> wrote:

> On Thu, 2018-07-26 at 15:48 +0200, Joe Olivas wrote:
> > Removing unused VPP sessions by initializing only when used in order
> > to help reduce CPU utilization. Thanks to Maxym for the guidance.
> >
> > Signed-off-by: Joe Olivas 
> Please, add:
> Cc: Maxym Dmytrychenko 
> Cc: Dmitry Rogozhkin 
>
> To keep us in the review loop.
> > ---
> >  libavutil/hwcontext_qsv.c | 78 -
> > --
> >  1 file changed, 72 insertions(+), 6 deletions(-)
> >
> > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> > index 250091c4e8..fc4a4127e3 100644
> > --- a/libavutil/hwcontext_qsv.c
> > +++ b/libavutil/hwcontext_qsv.c
> > @@ -23,6 +23,10 @@
> >
> >  #include "config.h"
> >
> > +#if HAVE_PTHREADS
> > +#include 
> > +#endif
> > +
> >  #if CONFIG_VAAPI
> >  #include "hwcontext_vaapi.h"
> >  #endif
> > @@ -56,7 +60,13 @@ typedef struct QSVDeviceContext {
> >
> >  typedef struct QSVFramesContext {
> >  mfxSession session_download;
> > +int session_download_init;
> >  mfxSession session_upload;
> > +int session_upload_init;
> > +#if HAVE_PTHREADS
> > +pthread_mutex_t session_lock;
> > +pthread_cond_t session_cond;
> > +#endif
> >
> >  AVBufferRef *child_frames_ref;
> >  mfxFrameSurface1 *surfaces_internal;
> > @@ -147,12 +157,19 @@ static void qsv_frames_uninit(AVHWFramesContext
> > *ctx)
> >  MFXClose(s->session_download);
> >  }
> >  s->session_download = NULL;
> > +s->session_download_init = 0;
> >
> >  if (s->session_upload) {
> >  MFXVideoVPP_Close(s->session_upload);
> >  MFXClose(s->session_upload);
> >  }
> >  s->session_upload = NULL;
> > +s->session_upload_init = 0;
> > +
> > +#if HAVE_PTHREADS
> > +pthread_mutex_destroy(>session_lock);
> > +pthread_cond_destroy(>session_cond);
> > +#endif
> >
> >  av_freep(>mem_ids);
> >  av_freep(>surface_ptrs);
> > @@ -535,13 +552,16 @@ static int qsv_frames_init(AVHWFramesContext
> > *ctx)
> >  s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
> >  }
> >
> > -ret = qsv_init_internal_session(ctx, >session_download, 0);
> > -if (ret < 0)
> > -return ret;
> > +s->session_download = NULL;
> > +s->session_upload   = NULL;
> >
> > -ret = qsv_init_internal_session(ctx, >session_upload, 1);
> > -if (ret < 0)
> > -return ret;
> > +s->session_download_init = 0;
> > +s->session_upload_init   = 0;
> > +
> > +#if HAVE_PTHREADS
> > +pthread_mutex_init(>session_lock, NULL);
> > +pthread_cond_init(>session_cond, NULL);
> > +#endif
> >
> >  return 0;
> >  }
> > @@ -741,6 +761,29 @@ static int
> > qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
> >  mfxSyncPoint sync = NULL;
> >  mfxStatus err;
> >
> > +while (!s->session_download_init && !s->session_download) {
>
> I don't think you need this while at all.
>
>
we should not leave this part unless init'ed


> > +#if HAVE_PTHREADS
> > + if (pthread_mutex_trylock(>session_lock) == 0) {
> > +#endif
> > +if (!s->session_download_init) {
> > +qsv_init_internal_session(ctx, >session_download,
> > 0);
>
> I can imagine the only one situation why you need the while above: this
> function fails and you need to try again, again and again. Is that
> possible or if function failed it failed permanently?
>
>
as above


> > +if (s->session_download)
> > +s->session_download_init = 1;
> > +}
> > +#if HAVE_PTHREADS
> > +pthread_mutex_unlock(>session_lock);
> > +pthread_cond_signal(>session_cond);
> > +}
> > + else {
> > +pthread_mutex_lock(>session_lock);
> > +while (!s->session_download_init && !s-
> > >session_download) {
> > +pthread_cond_wait(>session_cond, 
> > >session_lock);
> > +}
> > +pthread_mutex_unlock(>session_lock);
> > +}
> > +#endif
> > +

Re: [libav-devel] [PATCH v5] qsvvpp: Fix to perform full init only when needed

2018-08-23 Thread Maxym Dmytrychenko
On Wed, Jul 18, 2018 at 2:07 PM Maxym Dmytrychenko 
wrote:

> Not used VPP sessions, like for hwupload/hwdownload handling,
> can increase CPU utilization and this patch fixes it.
> thank you,Joe, for the contribution.
>
> Signed-off-by: Maxym Dmytrychenko 
> ---
>  libavutil/hwcontext_qsv.c | 72
> +--
>  1 file changed, 64 insertions(+), 8 deletions(-)
>
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index b3eb4a3ea..6bc2a38ff 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -23,6 +23,10 @@
>
>  #include "config.h"
>
> +#if HAVE_PTHREADS
> +#include 
> +#endif
> +
>  #if CONFIG_VAAPI
>  #include "hwcontext_vaapi.h"
>  #endif
> @@ -56,7 +60,13 @@ typedef struct QSVDeviceContext {
>
>  typedef struct QSVFramesContext {
>  mfxSession session_download;
> +int session_download_init;
>  mfxSession session_upload;
> +int session_upload_init;
> +#if HAVE_PTHREADS
> +pthread_mutex_t session_lock;
> +pthread_cond_t session_cond;
> +#endif
>
>  AVBufferRef *child_frames_ref;
>  mfxFrameSurface1 *surfaces_internal;
> @@ -146,13 +156,20 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
>  MFXVideoVPP_Close(s->session_download);
>  MFXClose(s->session_download);
>  }
> -s->session_download = NULL;
> +s->session_download  = NULL;
> +s->session_download_init = 0;
>
>  if (s->session_upload) {
>  MFXVideoVPP_Close(s->session_upload);
>  MFXClose(s->session_upload);
>  }
> -s->session_upload = NULL;
> +s->session_upload  = NULL;
> +s->session_upload_init = 0;
> +
> +#if HAVE_PTHREADS
> +pthread_mutex_destroy(>session_lock);
> +pthread_cond_destroy(>session_cond);
> +#endif
>
>  av_freep(>mem_ids);
>  av_freep(>surface_ptrs);
> @@ -535,13 +552,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
>  s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
>  }
>
> -ret = qsv_init_internal_session(ctx, >session_download, 0);
> -if (ret < 0)
> -return ret;
> +s->session_download = NULL;
> +s->session_upload   = NULL;
>
> -ret = qsv_init_internal_session(ctx, >session_upload, 1);
> -if (ret < 0)
> -return ret;
> +s->session_download_init = 0;
> +s->session_upload_init   = 0;
> +
> +#if HAVE_PTHREADS
> +pthread_mutex_init(>session_lock, NULL);
> +pthread_cond_init(>session_cond, NULL);
> +#endif
>
>  return 0;
>  }
> @@ -741,6 +761,24 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  mfxSyncPoint sync = NULL;
>  mfxStatus err;
>
> +while (!s->session_download_init && !s->session_download) {
> +#if HAVE_PTHREADS
> +if (pthread_mutex_trylock(>session_lock) == 0) {
> +#endif
> +qsv_init_internal_session(ctx, >session_download, 0);
> +s->session_download_init = 1;
> +#if HAVE_PTHREADS
> +pthread_cond_signal(>session_cond);
> +pthread_mutex_unlock(>session_lock);
> +}
> +else {
> +pthread_mutex_lock(>session_lock);
> +pthread_cond_wait(>session_cond, >session_lock);
> +pthread_mutex_unlock(>session_lock);
> +}
> +#endif
> +}
> +
>  if (!s->session_download) {
>  if (s->child_frames_ref)
>  return qsv_transfer_data_child(ctx, dst, src);
> @@ -788,6 +826,24 @@ static int qsv_transfer_data_to(AVHWFramesContext
> *ctx, AVFrame *dst,
>  mfxSyncPoint sync = NULL;
>  mfxStatus err;
>
> +while (!s->session_upload_init && !s->session_upload) {
> +#if HAVE_PTHREADS
> +if (pthread_mutex_trylock(>session_lock) == 0) {
> +#endif
> +qsv_init_internal_session(ctx, >session_upload, 1);
> +s->session_upload_init = 1;
> +#if HAVE_PTHREADS
> +pthread_cond_signal(>session_cond);
> +pthread_mutex_unlock(>session_lock);
> +}
> +else {
> +pthread_mutex_lock(>session_lock);
> +pthread_cond_wait(>session_cond, >session_lock);
> +pthread_mutex_unlock(>session_lock);
> +}
> +#endif
> +}
> +
>  if (!s->session_upload) {
>  if (s->child_frames_ref)
>  return qsv_transfer_data_child(ctx, dst, src);
> --
> 2.15.2 (Apple Git-101.1)
>
>
ping if any other comments

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

Re: [libav-devel] [PATCH 1/3] lavf/qsv: return an error if getting session handle failed

2018-08-22 Thread Maxym Dmytrychenko
On Wed, Aug 22, 2018 at 1:21 PM Luca Barbato  wrote:

> On 21/08/2018 09:15, Li, Zhong wrote:
> > Thank you. Luca. Will be applied?
>
> I was waiting for Maxym's feedback, but sure, it can.
>
> I'll push it this evening.
>
> lu
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel


was busy here but just fine!

thanks

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

Re: [libav-devel] [PATCH v2] qsv: enforcing continuous memory layout

2018-08-05 Thread Maxym Dmytrychenko
On Mon, Jul 30, 2018 at 6:15 PM Luca Barbato  wrote:

> On 30/07/2018 18:02, Maxym Dmytrychenko wrote:
> > we need to make sure that memory allocation for Y/UV planes is
> continuous and re-used from a
> > pool
> > ---
>
> I'm afraid this would break the already-proper-frame codepath.
>
> I would simplify the default avcoded allocator and call it directly.
>
>
Note that:

+if (!qf->frame->data[0]) {
+ret = av_frame_get_buffer(qf->frame, q->width_align);

would keep the pool running and dont see it leaking, or?




>
> >  libavcodec/qsvenc.c | 16 +++-
> >  1 file changed, 11 insertions(+), 5 deletions(-)
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index e349a075f..c74b3ae31 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -1014,7 +1014,6 @@ static void clear_unused_frames(QSVEncContext *q)
> >  QSVFrame *cur = q->work_frames;
> >  while (cur) {
> >  if (cur->used && !cur->surface.Data.Locked) {
> > -av_frame_unref(cur->frame);
> >  cur->used = 0;
> >  }
> >  cur = cur->next;
> > @@ -1082,16 +1081,23 @@ static int submit_frame(QSVEncContext *q, const
> AVFrame *frame,
> >  }
> >  } else {
> >  /* make a copy if the input is not padded as libmfx requires */
> > -if (frame->height & 31 || frame->linesize[0] & (q->width_align
> - 1)) {
> > +/* and to make allocation continious for data[0]/data[1] */
> > + if ((frame->height & 31 || frame->linesize[0] &
> (q->width_align - 1)) ||
> > +(frame->data[1] - frame->data[0] != frame->linesize[0] *
> FFALIGN(qf->frame->height, q->height_align))) {
> >  qf->frame->height = FFALIGN(frame->height, q->height_align);
> >  qf->frame->width  = FFALIGN(frame->width, q->width_align);
> >
> > -ret = ff_get_buffer(q->avctx, qf->frame,
> AV_GET_BUFFER_FLAG_REF);
> > -if (ret < 0)
> > -return ret;
> > +qf->frame->format = frame->format;
> > +
> > +if (!qf->frame->data[0]) {
> > +ret = av_frame_get_buffer(qf->frame, q->width_align);
> > +if (ret < 0)
> > +return ret;
> > +}
> >
> >  qf->frame->height = frame->height;
> >  qf->frame->width  = frame->width;
> > +
> >  ret = av_frame_copy(qf->frame, frame);
> >  if (ret < 0) {
> >  av_frame_unref(qf->frame);
> >
>
> ___
> 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] frame: Simplify the video allocation

2018-08-01 Thread Maxym Dmytrychenko
On Sat, Jul 28, 2018 at 7:19 AM Luca Barbato  wrote:

> And reduce the memory fragmentation.
>
> ---
>
>  libavutil/frame.c | 29 +
>  1 file changed, 9 insertions(+), 20 deletions(-)
>
> diff --git a/libavutil/frame.c b/libavutil/frame.c
> index db3897c299..f16b1d4d52 100644
> --- a/libavutil/frame.c
> +++ b/libavutil/frame.c
> @@ -89,12 +89,8 @@ void av_frame_free(AVFrame **frame)
>
>  static int get_video_buffer(AVFrame *frame, int align)
>  {
> -const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
>  int ret, i;
>
> -if (!desc)
> -return AVERROR(EINVAL);
> -
>  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL))
> < 0)
>  return ret;
>
> @@ -111,24 +107,17 @@ static int get_video_buffer(AVFrame *frame, int
> align)
>  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
>  }
>
> -for (i = 0; i < 4 && frame->linesize[i]; i++) {
> -int h = frame->height;
> -if (i == 1 || i == 2)
> -h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
> +if ((ret = av_image_fill_pointers(frame->data, frame->format,
> frame->height,
> +   NULL, frame->linesize)) < 0)
> +return ret;
>
> -frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
> -if (!frame->buf[i])
> -goto fail;
> +frame->buf[0] = av_buffer_alloc(ret);
> +if (!frame->buf[0])
> +goto fail;
>
> -frame->data[i] = frame->buf[i]->data;
> -}
> -if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags &
> AV_PIX_FMT_FLAG_PSEUDOPAL) {
> -av_buffer_unref(>buf[1]);
> -frame->buf[1] = av_buffer_alloc(1024);
> -if (!frame->buf[1])
> -goto fail;
> -frame->data[1] = frame->buf[1]->data;
> -}
> +if (av_image_fill_pointers(frame->data, frame->format, frame->height,
> +   frame->buf[0]->data, frame->linesize) < 0)
> +goto fail;
>
>  frame->extended_data = frame->data;
>
> --
> 2.12.2
>
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel


seems to be very reasonable

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

Re: [libav-devel] [PATCH] qsv: enforcing continuous memory layout

2018-07-30 Thread Maxym Dmytrychenko
On Sun, Jul 29, 2018 at 7:38 PM Diego Biurrun  wrote:

> On Sun, Jul 29, 2018 at 12:50:42AM +0200, Maxym Dmytrychenko wrote:
> > On Sat, Jul 28, 2018 at 12:20 PM Diego Biurrun  wrote:
> > > On Sat, Jul 28, 2018 at 10:53:54AM +0200, maxim_d33 wrote:
> > > > ---
> > > >  libavcodec/qsvenc.c | 34 --
> > > >  1 file changed, 24 insertions(+), 10 deletions(-)
> > >
> > > Looks like your Git is not set up properly.
> > >
> > >
> > what do you mean exactly, Diego?
> > I was squashing it before sending - may be because of this.
>
> The Git author name looks strange: maxim_d33. Probably because your
> Git user.name is not set and falls back on your username.
>
> Diego
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel


ok, should be fixed at v2

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

[libav-devel] [PATCH v2] qsv: enforcing continuous memory layout

2018-07-30 Thread Maxym Dmytrychenko
we need to make sure that memory allocation for Y/UV planes is continuous and 
re-used from a
pool
---
 libavcodec/qsvenc.c | 16 +++-
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index e349a075f..c74b3ae31 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -1014,7 +1014,6 @@ static void clear_unused_frames(QSVEncContext *q)
 QSVFrame *cur = q->work_frames;
 while (cur) {
 if (cur->used && !cur->surface.Data.Locked) {
-av_frame_unref(cur->frame);
 cur->used = 0;
 }
 cur = cur->next;
@@ -1082,16 +1081,23 @@ static int submit_frame(QSVEncContext *q, const AVFrame 
*frame,
 }
 } else {
 /* make a copy if the input is not padded as libmfx requires */
-if (frame->height & 31 || frame->linesize[0] & (q->width_align - 1)) {
+/* and to make allocation continious for data[0]/data[1] */
+ if ((frame->height & 31 || frame->linesize[0] & (q->width_align - 1)) 
||
+(frame->data[1] - frame->data[0] != frame->linesize[0] * 
FFALIGN(qf->frame->height, q->height_align))) {
 qf->frame->height = FFALIGN(frame->height, q->height_align);
 qf->frame->width  = FFALIGN(frame->width, q->width_align);
 
-ret = ff_get_buffer(q->avctx, qf->frame, AV_GET_BUFFER_FLAG_REF);
-if (ret < 0)
-return ret;
+qf->frame->format = frame->format;
+
+if (!qf->frame->data[0]) {
+ret = av_frame_get_buffer(qf->frame, q->width_align);
+if (ret < 0)
+return ret;
+}
 
 qf->frame->height = frame->height;
 qf->frame->width  = frame->width;
+
 ret = av_frame_copy(qf->frame, frame);
 if (ret < 0) {
 av_frame_unref(qf->frame);
-- 
2.14.2

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

Re: [libav-devel] [PATCH] qsv: enforcing continuous memory layout

2018-07-28 Thread Maxym Dmytrychenko
Hi Diego!

On Sat, Jul 28, 2018 at 12:20 PM Diego Biurrun  wrote:

> On Sat, Jul 28, 2018 at 10:53:54AM +0200, maxim_d33 wrote:
> > ---
> >  libavcodec/qsvenc.c | 34 --
> >  1 file changed, 24 insertions(+), 10 deletions(-)
>
> Looks like your Git is not set up properly.
>
>
what do you mean exactly, Diego?
I was squashing it before sending - may be because of this.


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


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

Re: [libav-devel] [PATCH v2] avcodec/qsv: fix async support

2018-07-27 Thread Maxym Dmytrychenko
thanks and will proceed with it

On Thu, Jul 26, 2018 at 9:06 PM Dmitry Rogozhkin <
dmitry.v.rogozh...@intel.com> wrote:

> Current implementations of qsv components incorrectly work with async
> level, they
> actually try to work in async+1 level stepping into MFX_WRN_DEVICE_BUSY
> and polling
> loop. This change address this misbehaviour.
>
> Signed-off-by: Dmitry Rogozhkin 
> Cc: Maxym Dmytrychenko 
> Cc: Zhong Li 
> ---
>  libavcodec/qsvdec.c   | 15 ---
>  libavcodec/qsvdec_h2645.c |  4 ++--
>  libavcodec/qsvdec_other.c |  2 +-
>  libavcodec/qsvenc.c   | 17 +
>  libavcodec/qsvenc.h   |  2 +-
>  5 files changed, 29 insertions(+), 11 deletions(-)
>
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 32f1fe7..22e7a46 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -110,6 +110,16 @@ static int qsv_init_session(AVCodecContext *avctx,
> QSVContext *q, mfxSession ses
>  return 0;
>  }
>
> +static inline unsigned int qsv_fifo_item_size(void)
> +{
> +return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
> +}
> +
> +static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
> +{
> +return av_fifo_size(fifo) / qsv_fifo_item_size();
> +}
> +
>  static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
>  {
>  const AVPixFmtDescriptor *desc;
> @@ -125,8 +135,7 @@ static int qsv_decode_init(AVCodecContext *avctx,
> QSVContext *q)
>  return AVERROR_BUG;
>
>  if (!q->async_fifo) {
> -q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
> -  (sizeof(mfxSyncPoint*) +
> sizeof(QSVFrame*)));
> +q->async_fifo = av_fifo_alloc(q->async_depth *
> qsv_fifo_item_size());
>  if (!q->async_fifo)
>  return AVERROR(ENOMEM);
>  }
> @@ -384,7 +393,7 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>  av_freep();
>  }
>
> -if (!av_fifo_space(q->async_fifo) ||
> +if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
>  (!avpkt->size && av_fifo_size(q->async_fifo))) {
>  AVFrame *src_frame;
>
> diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
> index 831252f..d9d2318 100644
> --- a/libavcodec/qsvdec_h2645.c
> +++ b/libavcodec/qsvdec_h2645.c
> @@ -186,7 +186,7 @@ static void qsv_decode_flush(AVCodecContext *avctx)
>
>  #if CONFIG_HEVC_QSV_DECODER
>  static const AVOption hevc_options[] = {
> -{ "async_depth", "Internal parallelization depth, the higher the
> value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, {
> .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
> +{ "async_depth", "Internal parallelization depth, the higher the
> value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, {
> .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
>
>  { "load_plugin", "A user plugin to load in an internal session",
> OFFSET(load_plugin), AV_OPT_TYPE_INT, { .i64 = LOAD_PLUGIN_DEFAULT },
> LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_HW, VD, "load_plugin" },
>  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE
> },0, 0, VD, "load_plugin" },
> @@ -229,7 +229,7 @@ AVCodec ff_hevc_qsv_decoder = {
>
>  #if CONFIG_H264_QSV_DECODER
>  static const AVOption options[] = {
> -{ "async_depth", "Internal parallelization depth, the higher the
> value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, {
> .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
> +{ "async_depth", "Internal parallelization depth, the higher the
> value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, {
> .i64 = ASYNC_DEPTH_DEFAULT }, 1, INT_MAX, VD },
>  { NULL },
>  };
>
> diff --git a/libavcodec/qsvdec_other.c b/libavcodec/qsvdec_other.c
> index 3c872dc..f6e08a2 100644
> --- a/libavcodec/qsvdec_other.c
> +++ b/libavcodec/qsvdec_other.c
> @@ -159,7 +159,7 @@ static void qsv_decode_flush(AVCodecContext *avctx)
>  #define OFFSET(x) offsetof(QSVOtherContext, x)
>  #define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM
>  static const AVOption options[] = {
> -{ "async_depth", "Internal parallelization depth, the higher the
> value the higher the latency.", OFFSET(qsv.async_depth), AV_OPT_TYPE_INT, {
> .i64 = ASYNC_DEPTH_DEFAULT }, 0, INT_MAX, VD },
> +{ "async_depth", "Internal parallelization depth, the higher the
> value the higher the latency.", OFFSET(qsv.async_depth

Re: [libav-devel] [PATCH] avcodec/qsv: fix async support

2018-07-26 Thread Maxym Dmytrychenko
On Thu, Jul 26, 2018 at 7:55 AM Li, Zhong  wrote:

> > -Original Message-
> > From: Rogozhkin, Dmitry V
> > Sent: Wednesday, July 25, 2018 1:36 AM
> > To: libav-devel@libav.org
> > Cc: Rogozhkin, Dmitry V ; Maxym
> > Dmytrychenko ; Li, Zhong 
> > Subject: [PATCH] avcodec/qsv: fix async support
> >
> > Current implementations of qsv components incorrectly work with async
> > level, they actually try to work in async+1 level stepping into
> > MFX_WRN_DEVICE_BUSY and polling loop. This change address this
> > misbehaviour.
> >
> > Signed-off-by: Dmitry Rogozhkin 
> > Cc: Maxym Dmytrychenko 
> > Cc: Zhong Li 
> > ---
> >  libavcodec/qsvdec.c | 15 ---  libavcodec/qsvenc.c | 17
> > +
> >  2 files changed, 25 insertions(+), 7 deletions(-)
> >
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > 32f1fe7..b9707f7 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -110,6 +110,16 @@ static int qsv_init_session(AVCodecContext *avctx,
> > QSVContext *q, mfxSession ses
> >  return 0;
> >  }
> >
> > +static inline unsigned int qsv_fifo_item_size(void) {
> > +return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*); }
> > +
> > +static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo) {
> > +return av_fifo_size(fifo)/qsv_fifo_item_size();
> > +}
> > +
> >  static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)  {
> >  const AVPixFmtDescriptor *desc;
> > @@ -125,8 +135,7 @@ static int qsv_decode_init(AVCodecContext *avctx,
> > QSVContext *q)
> >  return AVERROR_BUG;
> >
> >  if (!q->async_fifo) {
> > -q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
> > -  (sizeof(mfxSyncPoint*) +
> > sizeof(QSVFrame*)));
> > +q->async_fifo = av_fifo_alloc(q->async_depth *
> > + qsv_fifo_item_size());
> >  if (!q->async_fifo)
> >  return AVERROR(ENOMEM);
> >  }
> > @@ -384,7 +393,7 @@ static int qsv_decode(AVCodecContext *avctx,
> > QSVContext *q,
> >  av_freep();
> >  }
> >
> > -if (!av_fifo_space(q->async_fifo) ||
> > +if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
> >  (!avpkt->size && av_fifo_size(q->async_fifo))) {
> >  AVFrame *src_frame;
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index
> > 3ce5ffe..40ddb34 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -777,7 +777,7 @@ static int qsv_init_opaque_alloc(AVCodecContext
> > *avctx, QSVEncContext *q)
> >  mfxFrameSurface1 *surfaces;
> >  int nb_surfaces, i;
> >
> > -nb_surfaces = qsv->nb_opaque_surfaces +
> > q->req.NumFrameSuggested + q->async_depth;
> > +nb_surfaces = qsv->nb_opaque_surfaces +
> > q->req.NumFrameSuggested;
> >
> >  q->opaque_alloc_buf = av_buffer_allocz(sizeof(*surfaces) *
> > nb_surfaces);
> >  if (!q->opaque_alloc_buf)
> > @@ -848,6 +848,16 @@ static int qsvenc_init_session(AVCodecContext
> > *avctx, QSVEncContext *q)
> >  return 0;
> >  }
> >
> > +static inline unsigned int qsv_fifo_item_size(void) {
> > +return sizeof(AVPacket) + sizeof(mfxSyncPoint*) +
> > +sizeof(mfxBitstream*); }
> > +
> > +static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo) {
> > +return av_fifo_size(fifo)/qsv_fifo_item_size();
> > +}
> > +
> Add a blank before and after "/" is a unified coding style.
> Maybe better to move it to qsv.c since it is common for qsvdec/enc.
>
>
good point - agree.


> >  int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)  {
> >  int iopattern = 0;
> > @@ -856,8 +866,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> > QSVEncContext *q)
> >
> >  q->param.AsyncDepth = q->async_depth;
> >
> > -q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
> > -  (sizeof(AVPacket) +
> > sizeof(mfxSyncPoint*) + sizeof(mfxBitstream*)));
> > +q->async_fifo = av_fifo_alloc(q->async_depth *
> > + qsv_fifo_item_size());
>
> I agree with remove the "+1". And noted someone was also confused too:
> http://ffmpeg.org/pipermail/ffmpeg-devel/2017-November/219643.html
> Any historic reason to add "+1" in the initial implementation? If no, I
> would

Re: [libav-devel] [PATCH] avcodec/qsv: fix async support

2018-07-25 Thread Maxym Dmytrychenko
On Wed, Jul 25, 2018 at 10:24 PM Luca Barbato  wrote:

> On 25/07/2018 19:39, Rogozhkin, Dmitry V wrote:
> > So, I encourage to embrace this change and understand that there are
> > some changes in performance associated with it which aligns the
> > behavior with the expected usage models.
>
> I guess we could change the default so it is less surprising.
>
> lu
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel


ok, we can skip performance impact in favor of logical correctness
___
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] avcodec/qsv: fix async support

2018-07-25 Thread Maxym Dmytrychenko
On Wed, Jul 25, 2018 at 3:39 AM Dmitry Rogozhkin <
dmitry.v.rogozh...@intel.com> wrote:

> Current implementations of qsv components incorrectly work with async
> level, they
> actually try to work in async+1 level stepping into MFX_WRN_DEVICE_BUSY
> and polling
> loop. This change address this misbehaviour.
>
> Signed-off-by: Dmitry Rogozhkin 
> Cc: Maxym Dmytrychenko 
> Cc: Zhong Li 
> ---
>  libavcodec/qsvdec.c | 15 ---
>  libavcodec/qsvenc.c | 17 +
>  2 files changed, 25 insertions(+), 7 deletions(-)
>
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index 32f1fe7..b9707f7 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -110,6 +110,16 @@ static int qsv_init_session(AVCodecContext *avctx,
> QSVContext *q, mfxSession ses
>  return 0;
>  }
>
> +static inline unsigned int qsv_fifo_item_size(void)
> +{
> +return sizeof(mfxSyncPoint*) + sizeof(QSVFrame*);
> +}
> +
> +static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
> +{
> +return av_fifo_size(fifo)/qsv_fifo_item_size();
> +}
> +
>  static int qsv_decode_init(AVCodecContext *avctx, QSVContext *q)
>  {
>  const AVPixFmtDescriptor *desc;
> @@ -125,8 +135,7 @@ static int qsv_decode_init(AVCodecContext *avctx,
> QSVContext *q)
>  return AVERROR_BUG;
>
>  if (!q->async_fifo) {
> -q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
> -  (sizeof(mfxSyncPoint*) +
> sizeof(QSVFrame*)));
> +q->async_fifo = av_fifo_alloc(q->async_depth *
> qsv_fifo_item_size());
>  if (!q->async_fifo)
>  return AVERROR(ENOMEM);
>  }
> @@ -384,7 +393,7 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>  av_freep();
>  }
>
> -if (!av_fifo_space(q->async_fifo) ||
> +if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
>  (!avpkt->size && av_fifo_size(q->async_fifo))) {
>  AVFrame *src_frame;
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 3ce5ffe..40ddb34 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -777,7 +777,7 @@ static int qsv_init_opaque_alloc(AVCodecContext
> *avctx, QSVEncContext *q)
>  mfxFrameSurface1 *surfaces;
>  int nb_surfaces, i;
>
> -nb_surfaces = qsv->nb_opaque_surfaces + q->req.NumFrameSuggested +
> q->async_depth;
> +nb_surfaces = qsv->nb_opaque_surfaces + q->req.NumFrameSuggested;
>
>  q->opaque_alloc_buf = av_buffer_allocz(sizeof(*surfaces) *
> nb_surfaces);
>  if (!q->opaque_alloc_buf)
> @@ -848,6 +848,16 @@ static int qsvenc_init_session(AVCodecContext *avctx,
> QSVEncContext *q)
>  return 0;
>  }
>
> +static inline unsigned int qsv_fifo_item_size(void)
> +{
> +return sizeof(AVPacket) + sizeof(mfxSyncPoint*) +
> sizeof(mfxBitstream*);
> +}
> +
> +static inline unsigned int qsv_fifo_size(const AVFifoBuffer* fifo)
> +{
> +return av_fifo_size(fifo)/qsv_fifo_item_size();
> +}
> +
>  int ff_qsv_enc_init(AVCodecContext *avctx, QSVEncContext *q)
>  {
>  int iopattern = 0;
> @@ -856,8 +866,7 @@ int ff_qsv_enc_init(AVCodecContext *avctx,
> QSVEncContext *q)
>
>  q->param.AsyncDepth = q->async_depth;
>
> -q->async_fifo = av_fifo_alloc((1 + q->async_depth) *
> -  (sizeof(AVPacket) +
> sizeof(mfxSyncPoint*) + sizeof(mfxBitstream*)));
> +q->async_fifo = av_fifo_alloc(q->async_depth * qsv_fifo_item_size());
>  if (!q->async_fifo)
>  return AVERROR(ENOMEM);
>
> @@ -1214,7 +1223,7 @@ int ff_qsv_encode(AVCodecContext *avctx,
> QSVEncContext *q,
>  if (ret < 0)
>  return ret;
>
> -if (!av_fifo_space(q->async_fifo) ||
> +if ((qsv_fifo_size(q->async_fifo) >= q->async_depth) ||
>  (!frame && av_fifo_size(q->async_fifo))) {
>  AVPacket new_pkt;
>  mfxBitstream *bs;
> --
> 1.8.3.1
>

thanks for the patch.
any performance impact you see, depth == 1 and higher ?

our tests shows some drop when async_depth == 1.


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

[libav-devel] [PATCH v5] qsvvpp: Fix to perform full init only when needed

2018-07-18 Thread Maxym Dmytrychenko
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.
thank you,Joe, for the contribution.

Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 72 +--
 1 file changed, 64 insertions(+), 8 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..6bc2a38ff 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -23,6 +23,10 @@
 
 #include "config.h"
 
+#if HAVE_PTHREADS
+#include 
+#endif
+
 #if CONFIG_VAAPI
 #include "hwcontext_vaapi.h"
 #endif
@@ -56,7 +60,13 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+int session_download_init;
 mfxSession session_upload;
+int session_upload_init;
+#if HAVE_PTHREADS
+pthread_mutex_t session_lock;
+pthread_cond_t session_cond;
+#endif
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -146,13 +156,20 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 MFXVideoVPP_Close(s->session_download);
 MFXClose(s->session_download);
 }
-s->session_download = NULL;
+s->session_download  = NULL;
+s->session_download_init = 0;
 
 if (s->session_upload) {
 MFXVideoVPP_Close(s->session_upload);
 MFXClose(s->session_upload);
 }
-s->session_upload = NULL;
+s->session_upload  = NULL;
+s->session_upload_init = 0;
+
+#if HAVE_PTHREADS
+pthread_mutex_destroy(>session_lock);
+pthread_cond_destroy(>session_cond);
+#endif
 
 av_freep(>mem_ids);
 av_freep(>surface_ptrs);
@@ -535,13 +552,16 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
+s->session_download = NULL;
+s->session_upload   = NULL;
 
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
+s->session_download_init = 0;
+s->session_upload_init   = 0;
+
+#if HAVE_PTHREADS
+pthread_mutex_init(>session_lock, NULL);
+pthread_cond_init(>session_cond, NULL);
+#endif
 
 return 0;
 }
@@ -741,6 +761,24 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 mfxSyncPoint sync = NULL;
 mfxStatus err;
 
+while (!s->session_download_init && !s->session_download) {
+#if HAVE_PTHREADS
+if (pthread_mutex_trylock(>session_lock) == 0) {
+#endif
+qsv_init_internal_session(ctx, >session_download, 0);
+s->session_download_init = 1;
+#if HAVE_PTHREADS
+pthread_cond_signal(>session_cond);
+pthread_mutex_unlock(>session_lock);
+}
+else {
+pthread_mutex_lock(>session_lock);
+pthread_cond_wait(>session_cond, >session_lock);
+pthread_mutex_unlock(>session_lock);
+}
+#endif
+}
+
 if (!s->session_download) {
 if (s->child_frames_ref)
 return qsv_transfer_data_child(ctx, dst, src);
@@ -788,6 +826,24 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 mfxSyncPoint sync = NULL;
 mfxStatus err;
 
+while (!s->session_upload_init && !s->session_upload) {
+#if HAVE_PTHREADS
+if (pthread_mutex_trylock(>session_lock) == 0) {
+#endif
+qsv_init_internal_session(ctx, >session_upload, 1);
+s->session_upload_init = 1;
+#if HAVE_PTHREADS
+pthread_cond_signal(>session_cond);
+pthread_mutex_unlock(>session_lock);
+}
+else {
+pthread_mutex_lock(>session_lock);
+pthread_cond_wait(>session_cond, >session_lock);
+pthread_mutex_unlock(>session_lock);
+}
+#endif
+}
+
 if (!s->session_upload) {
 if (s->child_frames_ref)
 return qsv_transfer_data_child(ctx, dst, src);
-- 
2.15.2 (Apple Git-101.1)

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

Re: [libav-devel] [PATCH v4] qsvvpp: Fix to perform full init only when needed

2018-07-17 Thread Maxym Dmytrychenko
On Wed, Jul 18, 2018 at 1:34 AM Mark Thompson  wrote:

> On 18/07/18 00:25, Maxym Dmytrychenko wrote:
> > On Wed, Jul 18, 2018 at 12:48 AM Mark Thompson  wrote:
> >
> >> On 17/07/18 17:07, Maxym Dmytrychenko wrote:
> >>> Not used VPP sessions, like for hwupload/hwdownload handling,
> >>> can increase CPU utilization and this patch fixes it.
> >>> thank you,Joe, for the contribution.
> >>>
> >>> Signed-off-by: Maxym Dmytrychenko 
> >>> ---
> >>>  libavutil/hwcontext_qsv.c | 38 +-
> >>>  1 file changed, 29 insertions(+), 9 deletions(-)
> >>>
> >>> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> >>> index b3eb4a3ea..390c3aac4 100644
> >>> --- a/libavutil/hwcontext_qsv.c
> >>> +++ b/libavutil/hwcontext_qsv.c
> >>> @@ -18,6 +18,7 @@
> >>>
> >>>  #include 
> >>>  #include 
> >>> +#include 
> >>>
> >>>  #include 
> >>>
> >>> @@ -56,7 +57,9 @@ typedef struct QSVDeviceContext {
> >>>
> >>>  typedef struct QSVFramesContext {
> >>>  mfxSession session_download;
> >>> +atomic_int session_download_init;
> >>>  mfxSession session_upload;
> >>> +atomic_int session_upload_init;
> >>>
> >>>  AVBufferRef *child_frames_ref;
> >>>  mfxFrameSurface1 *surfaces_internal;
> >>> @@ -146,13 +149,15 @@ static void qsv_frames_uninit(AVHWFramesContext
> >> *ctx)
> >>>  MFXVideoVPP_Close(s->session_download);
> >>>  MFXClose(s->session_download);
> >>>  }
> >>> -s->session_download = NULL;
> >>> +s->session_download  = NULL;
> >>> +s->session_download_init = 0;
> >>>
> >>>  if (s->session_upload) {
> >>>  MFXVideoVPP_Close(s->session_upload);
> >>>  MFXClose(s->session_upload);
> >>>  }
> >>> -s->session_upload = NULL;
> >>> +s->session_upload  = NULL;
> >>> +s->session_upload_init = 0;
> >>>
> >>>  av_freep(>mem_ids);
> >>>  av_freep(>surface_ptrs);
> >>> @@ -535,13 +540,10 @@ static int qsv_frames_init(AVHWFramesContext
> *ctx)
> >>>  s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
> >>>  }
> >>>
> >>> -ret = qsv_init_internal_session(ctx, >session_download, 0);
> >>> -if (ret < 0)
> >>> -return ret;
> >>> -
> >>> -ret = qsv_init_internal_session(ctx, >session_upload, 1);
> >>> -if (ret < 0)
> >>> -return ret;
> >>> +s->session_download  = NULL;
> >>> +s->session_upload= NULL;
> >>> +s->session_download_init = 0;
> >>> +s->session_upload_init   = 0;
> >>>
> >>>  return 0;
> >>>  }
> >>> @@ -741,6 +743,15 @@ static int
> qsv_transfer_data_from(AVHWFramesContext
> >> *ctx, AVFrame *dst,
> >>>  mfxSyncPoint sync = NULL;
> >>>  mfxStatus err;
> >>>
> >>> +while (!s->session_download_init && !s->session_download) {
> >>> + if (atomic_fetch_add(>session_download_init, 1) == 0) {
> >>> +qsv_init_internal_session(ctx, >session_download, 0);
> >>> +}
> >>> + else {
> >>> +av_usleep(1);
> >>
> >> This races - consider what happens if the other thread is preempted for
> >> more than 1µs, or if the initialisation itself takes more than that
> long.
>
> (Apologies, I misread that the first time - with the spin loop it should
> only be a benign race on session_download, but it's still undefined
> behaviour by C11 and things like tsan will complain about it: read in the
> non-initialising thread against write in the initialising thread, after the
> flag has been set to 1.)
>
>
np,
let's fix it, sure.


> >>
> >> You need to actually do some synchronisation here (e.g. with a 'once'
> >> variable) - with only atomic flags there is no way to guarantee that the
> >> other thread has finished unless you spin, which isn't acceptable.
> >>
> >> pthread_once was considered but we need to pass  s->session_down

Re: [libav-devel] [PATCH v4] qsvvpp: Fix to perform full init only when needed

2018-07-17 Thread Maxym Dmytrychenko
On Wed, Jul 18, 2018 at 12:48 AM Mark Thompson  wrote:

> On 17/07/18 17:07, Maxym Dmytrychenko wrote:
> > Not used VPP sessions, like for hwupload/hwdownload handling,
> > can increase CPU utilization and this patch fixes it.
> > thank you,Joe, for the contribution.
> >
> > Signed-off-by: Maxym Dmytrychenko 
> > ---
> >  libavutil/hwcontext_qsv.c | 38 +-
> >  1 file changed, 29 insertions(+), 9 deletions(-)
> >
> > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> > index b3eb4a3ea..390c3aac4 100644
> > --- a/libavutil/hwcontext_qsv.c
> > +++ b/libavutil/hwcontext_qsv.c
> > @@ -18,6 +18,7 @@
> >
> >  #include 
> >  #include 
> > +#include 
> >
> >  #include 
> >
> > @@ -56,7 +57,9 @@ typedef struct QSVDeviceContext {
> >
> >  typedef struct QSVFramesContext {
> >  mfxSession session_download;
> > +atomic_int session_download_init;
> >  mfxSession session_upload;
> > +atomic_int session_upload_init;
> >
> >  AVBufferRef *child_frames_ref;
> >  mfxFrameSurface1 *surfaces_internal;
> > @@ -146,13 +149,15 @@ static void qsv_frames_uninit(AVHWFramesContext
> *ctx)
> >  MFXVideoVPP_Close(s->session_download);
> >  MFXClose(s->session_download);
> >  }
> > -s->session_download = NULL;
> > +s->session_download  = NULL;
> > +s->session_download_init = 0;
> >
> >  if (s->session_upload) {
> >  MFXVideoVPP_Close(s->session_upload);
> >  MFXClose(s->session_upload);
> >  }
> > -s->session_upload = NULL;
> > +s->session_upload  = NULL;
> > +s->session_upload_init = 0;
> >
> >  av_freep(>mem_ids);
> >  av_freep(>surface_ptrs);
> > @@ -535,13 +540,10 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
> >  s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
> >  }
> >
> > -ret = qsv_init_internal_session(ctx, >session_download, 0);
> > -if (ret < 0)
> > -return ret;
> > -
> > -ret = qsv_init_internal_session(ctx, >session_upload, 1);
> > -if (ret < 0)
> > -return ret;
> > +s->session_download  = NULL;
> > +s->session_upload= NULL;
> > +s->session_download_init = 0;
> > +s->session_upload_init   = 0;
> >
> >  return 0;
> >  }
> > @@ -741,6 +743,15 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
> >  mfxSyncPoint sync = NULL;
> >  mfxStatus err;
> >
> > +while (!s->session_download_init && !s->session_download) {
> > + if (atomic_fetch_add(>session_download_init, 1) == 0) {
> > +qsv_init_internal_session(ctx, >session_download, 0);
> > +}
> > + else {
> > +av_usleep(1);
>
> This races - consider what happens if the other thread is preempted for
> more than 1µs, or if the initialisation itself takes more than that long.
>
> You need to actually do some synchronisation here (e.g. with a 'once'
> variable) - with only atomic flags there is no way to guarantee that the
> other thread has finished unless you spin, which isn't acceptable.
>
> pthread_once was considered but we need to pass  s->session_download
adding mutex - can be overkill for each call of   qsv_transfer_data_*

what do you mean by 'once' variable?
dont really see it currently implemented somewhere...


> > +}
> > +}
> > +
> >  if (!s->session_download) {
> >  if (s->child_frames_ref)
> >  return qsv_transfer_data_child(ctx, dst, src);
> > @@ -788,6 +799,15 @@ static int qsv_transfer_data_to(AVHWFramesContext
> *ctx, AVFrame *dst,
> >  mfxSyncPoint sync = NULL;
> >  mfxStatus err;
> >
> > +while (!s->session_upload_init && !s->session_upload) {
> > + if (atomic_fetch_add(>session_upload_init, 1) == 0) {
> > +qsv_init_internal_session(ctx, >session_upload, 1);
> > +}
> > + else {
> > +av_usleep(1);
> > +}
> > +}
> > +
> >  if (!s->session_upload) {
> >  if (s->child_frames_ref)
> >  return qsv_transfer_data_child(ctx, dst, src);
> >
>
> Thanks,
>
> - Mark
> ___
> libav-devel mailing list
> libav-devel@libav.org
> https://lists.libav.org/mailman/listinfo/libav-devel


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

[libav-devel] [PATCH v4] qsvvpp: Fix to perform full init only when needed

2018-07-17 Thread Maxym Dmytrychenko
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.
thank you,Joe, for the contribution.

Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 38 +-
 1 file changed, 29 insertions(+), 9 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..390c3aac4 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -18,6 +18,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -56,7 +57,9 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+atomic_int session_download_init;
 mfxSession session_upload;
+atomic_int session_upload_init;
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -146,13 +149,15 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 MFXVideoVPP_Close(s->session_download);
 MFXClose(s->session_download);
 }
-s->session_download = NULL;
+s->session_download  = NULL;
+s->session_download_init = 0;
 
 if (s->session_upload) {
 MFXVideoVPP_Close(s->session_upload);
 MFXClose(s->session_upload);
 }
-s->session_upload = NULL;
+s->session_upload  = NULL;
+s->session_upload_init = 0;
 
 av_freep(>mem_ids);
 av_freep(>surface_ptrs);
@@ -535,13 +540,10 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
-
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
+s->session_download  = NULL;
+s->session_upload= NULL;
+s->session_download_init = 0;
+s->session_upload_init   = 0;
 
 return 0;
 }
@@ -741,6 +743,15 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 mfxSyncPoint sync = NULL;
 mfxStatus err;
 
+while (!s->session_download_init && !s->session_download) {
+   if (atomic_fetch_add(>session_download_init, 1) == 0) {
+qsv_init_internal_session(ctx, >session_download, 0);
+}
+   else {
+av_usleep(1);
+}
+}
+
 if (!s->session_download) {
 if (s->child_frames_ref)
 return qsv_transfer_data_child(ctx, dst, src);
@@ -788,6 +799,15 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 mfxSyncPoint sync = NULL;
 mfxStatus err;
 
+while (!s->session_upload_init && !s->session_upload) {
+   if (atomic_fetch_add(>session_upload_init, 1) == 0) {
+qsv_init_internal_session(ctx, >session_upload, 1);
+}
+   else {
+av_usleep(1);
+}
+}
+
 if (!s->session_upload) {
 if (s->child_frames_ref)
 return qsv_transfer_data_child(ctx, dst, src);
-- 
2.15.2 (Apple Git-101.1)

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

Re: [libav-devel] [PATCH v3] qsvvpp: Fix to perform full init only when needed

2018-07-16 Thread Maxym Dmytrychenko
On Tue, Jul 17, 2018 at 12:00 AM Mark Thompson  wrote:

> On 16/07/18 14:26, Maxym Dmytrychenko wrote:
> > Not used VPP sessions, like for hwupload/hwdownload handling,
> > can increase CPU utilization and this patch fixes it.
> > thank you,Joe, for the contribution.
> >
> > Signed-off-by: Maxym Dmytrychenko 
> > ---
> >  libavutil/hwcontext_qsv.c | 35 ++-
> >  1 file changed, 26 insertions(+), 9 deletions(-)
>
> This makes sense, but it looks like it might need some sort of 'once'
> construction for thread-safety?
>
> I believe the current API intent is that performing simultaneous transfer
> operations on different frames in the same frames context should be safe.
>
> good point!
So far, I see pretty much always the same thread, so like single threaded
usage, unless I am missing something.
should we consider this implementation ok and to remember: if
multithreading support - to be adjusted?


>
> > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> > index b3eb4a3ea..3e6c38037 100644
> > --- a/libavutil/hwcontext_qsv.c
> > +++ b/libavutil/hwcontext_qsv.c
> > @@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
> >
> >  typedef struct QSVFramesContext {
> >  mfxSession session_download;
> > +int session_download_init;
> >  mfxSession session_upload;
> > +int session_upload_init;
> >
> >  AVBufferRef *child_frames_ref;
> >  mfxFrameSurface1 *surfaces_internal;
> > @@ -146,13 +148,15 @@ static void qsv_frames_uninit(AVHWFramesContext
> *ctx)
> >  MFXVideoVPP_Close(s->session_download);
> >  MFXClose(s->session_download);
> >  }
> > -s->session_download = NULL;
> > +s->session_download  = NULL;
> > +s->session_download_init = 0;
> >
> >  if (s->session_upload) {
> >  MFXVideoVPP_Close(s->session_upload);
> >  MFXClose(s->session_upload);
> >  }
> > -s->session_upload = NULL;
> > +s->session_upload  = NULL;
> > +s->session_upload_init = 0;
> >
> >  av_freep(>mem_ids);
> >  av_freep(>surface_ptrs);
> > @@ -535,13 +539,10 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
> >  s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
> >  }
> >
> > -ret = qsv_init_internal_session(ctx, >session_download, 0);
> > -if (ret < 0)
> > -return ret;
> > -
> > -ret = qsv_init_internal_session(ctx, >session_upload, 1);
> > -if (ret < 0)
> > -return ret;
> > +s->session_download  = NULL;
> > +s->session_upload= NULL;
> > +s->session_download_init = 0;
> > +s->session_upload_init   = 0;
> >
> >  return 0;
> >  }
> > @@ -740,6 +741,14 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
> >
> >  mfxSyncPoint sync = NULL;
> >  mfxStatus err;
> > +int ret = -1;
>
> The initialisation is redundant?  The -1 confused me, but I don't think
> it's ever read anywhere.
>
> can change this, sure.


> > +
> > +if (!s->session_download_init) {
> > +s->session_download_init = 1;
> > +ret = qsv_init_internal_session(ctx, >session_download, 0);
> > +if (ret < 0)
> > +return ret;
> > +}
> >
> >  if (!s->session_download) {
> >  if (s->child_frames_ref)
> > @@ -787,6 +796,14 @@ static int qsv_transfer_data_to(AVHWFramesContext
> *ctx, AVFrame *dst,
> >
> >  mfxSyncPoint sync = NULL;
> >  mfxStatus err;
> > +int ret = -1;
> Likewise this one.
>
> as above as well - can change.


> > +
> > +if (!s->session_upload_init) {
> > +s->session_upload_init = 1;
> > +ret = qsv_init_internal_session(ctx, >session_upload, 1);
> > +if (ret < 0)
> > +return ret;
> > +}
> >
> >  if (!s->session_upload) {
> >  if (s->child_frames_ref)
> >
>
> Thanks,
>
> thank you for the review


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


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

[libav-devel] [PATCH v3] qsvvpp: Fix to perform full init only when needed

2018-07-16 Thread Maxym Dmytrychenko
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.
thank you,Joe, for the contribution.

Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 35 ++-
 1 file changed, 26 insertions(+), 9 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..3e6c38037 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+int session_download_init;
 mfxSession session_upload;
+int session_upload_init;
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -146,13 +148,15 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 MFXVideoVPP_Close(s->session_download);
 MFXClose(s->session_download);
 }
-s->session_download = NULL;
+s->session_download  = NULL;
+s->session_download_init = 0;
 
 if (s->session_upload) {
 MFXVideoVPP_Close(s->session_upload);
 MFXClose(s->session_upload);
 }
-s->session_upload = NULL;
+s->session_upload  = NULL;
+s->session_upload_init = 0;
 
 av_freep(>mem_ids);
 av_freep(>surface_ptrs);
@@ -535,13 +539,10 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
-
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
+s->session_download  = NULL;
+s->session_upload= NULL;
+s->session_download_init = 0;
+s->session_upload_init   = 0;
 
 return 0;
 }
@@ -740,6 +741,14 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_download_init) {
+s->session_download_init = 1;
+ret = qsv_init_internal_session(ctx, >session_download, 0);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_download) {
 if (s->child_frames_ref)
@@ -787,6 +796,14 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_upload_init) {
+s->session_upload_init = 1;
+ret = qsv_init_internal_session(ctx, >session_upload, 1);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_upload) {
 if (s->child_frames_ref)
-- 
2.15.2 (Apple Git-101.1)

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

[libav-devel] [PATCH v2] qsvvpp: Fix to perform full init only when needed

2018-07-16 Thread Maxym Dmytrychenko
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.
thank you,Joe, for the contribution.

Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..f92602a41 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+int session_download_init;
 mfxSession session_upload;
+int session_upload_init;
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -147,12 +149,14 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 MFXClose(s->session_download);
 }
 s->session_download = NULL;
+s->session_download_init = 0;
 
 if (s->session_upload) {
 MFXVideoVPP_Close(s->session_upload);
 MFXClose(s->session_upload);
 }
 s->session_upload = NULL;
+s->session_upload_init = 0;
 
 av_freep(>mem_ids);
 av_freep(>surface_ptrs);
@@ -535,13 +539,10 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
-
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
+s->session_download = NULL;
+s->session_upload = NULL;
+s->session_download_init = 0;
+s->session_upload_init = 0;
 
 return 0;
 }
@@ -740,6 +741,14 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_download_init) {
+s->session_download_init = 1;
+ret = qsv_init_internal_session(ctx, >session_download, 0);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_download) {
 if (s->child_frames_ref)
@@ -787,6 +796,14 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_upload_init) {
+s->session_upload_init = 1;
+ret = qsv_init_internal_session(ctx, >session_upload, 1);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_upload) {
 if (s->child_frames_ref)
-- 
2.15.2 (Apple Git-101.1)

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

[libav-devel] [PATCH] qsvvpp: Fix to perform full init only when needed

2018-07-16 Thread Maxym Dmytrychenko
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.
thank you,Joe, for the contribution.

Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..f92602a41 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+int session_download_init;
 mfxSession session_upload;
+int session_upload_init;
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -147,12 +149,14 @@ static void qsv_frames_uninit(AVHWFramesContext *ctx)
 MFXClose(s->session_download);
 }
 s->session_download = NULL;
+s->session_download_init = 0;
 
 if (s->session_upload) {
 MFXVideoVPP_Close(s->session_upload);
 MFXClose(s->session_upload);
 }
 s->session_upload = NULL;
+s->session_upload_init = 0;
 
 av_freep(>mem_ids);
 av_freep(>surface_ptrs);
@@ -535,13 +539,10 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
-
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
+s->session_download = NULL;
+s->session_upload = NULL;
+s->session_download_init = 0;
+s->session_upload_init = 0;
 
 return 0;
 }
@@ -740,6 +741,14 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_download_init) {
+s->session_download_init = 1;
+ret = qsv_init_internal_session(ctx, >session_download, 0);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_download) {
 if (s->child_frames_ref)
@@ -787,6 +796,14 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_upload_init) {
+s->session_upload_init = 1;
+ret = qsv_init_internal_session(ctx, >session_upload, 1);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_upload) {
 if (s->child_frames_ref)
-- 
2.15.2 (Apple Git-101.1)

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

[libav-devel] [PATCH] qsvvpp: Fix to perform full init only when needed

2018-07-13 Thread Maxym Dmytrychenko
Not used VPP sessions, like for hwupload/hwdownload handling,
can increase CPU utilization and this patch fixes it.

Signed-off-by: Maxym Dmytrychenko 
---
 libavutil/hwcontext_qsv.c | 26 ++
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
index b3eb4a3ea..c540208f9 100644
--- a/libavutil/hwcontext_qsv.c
+++ b/libavutil/hwcontext_qsv.c
@@ -56,7 +56,9 @@ typedef struct QSVDeviceContext {
 
 typedef struct QSVFramesContext {
 mfxSession session_download;
+int session_download_init;
 mfxSession session_upload;
+int session_upload_init;
 
 AVBufferRef *child_frames_ref;
 mfxFrameSurface1 *surfaces_internal;
@@ -535,14 +537,6 @@ static int qsv_frames_init(AVHWFramesContext *ctx)
 s->mem_ids[i] = frames_hwctx->surfaces[i].Data.MemId;
 }
 
-ret = qsv_init_internal_session(ctx, >session_download, 0);
-if (ret < 0)
-return ret;
-
-ret = qsv_init_internal_session(ctx, >session_upload, 1);
-if (ret < 0)
-return ret;
-
 return 0;
 }
 
@@ -740,6 +734,14 @@ static int qsv_transfer_data_from(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_download_init) {
+s->session_download_init = 1;
+ret = qsv_init_internal_session(ctx, >session_download, 0);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_download) {
 if (s->child_frames_ref)
@@ -787,6 +789,14 @@ static int qsv_transfer_data_to(AVHWFramesContext *ctx, 
AVFrame *dst,
 
 mfxSyncPoint sync = NULL;
 mfxStatus err;
+int ret = -1;
+
+if (!s->session_upload_init) {
+s->session_upload_init = 1;
+ret = qsv_init_internal_session(ctx, >session_upload, 1);
+if (ret < 0)
+return ret;
+}
 
 if (!s->session_upload) {
 if (s->child_frames_ref)
-- 
2.15.2 (Apple Git-101.1)

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

Re: [libav-devel] [PATCH] lavc/qsv_overlay: suppress code scan complain

2018-07-03 Thread Maxym Dmytrychenko
should it be AV_PIX_FMT_NONE ?

On Tue, Jul 3, 2018 at 9:53 AM Zhong Li  wrote:

> Suppress the complain "variables 'pix_fmt' is used but maybe
> uninitialized".
>
> Signed-off-by: Zhong Li 
> ---
>  libavfilter/vf_overlay_qsv.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/libavfilter/vf_overlay_qsv.c b/libavfilter/vf_overlay_qsv.c
> index 89f2fb1..33d50a5 100644
> --- a/libavfilter/vf_overlay_qsv.c
> +++ b/libavfilter/vf_overlay_qsv.c
> @@ -162,7 +162,7 @@ release:
>
>  static int have_alpha_planar(AVFilterLink *link)
>  {
> -enum AVPixelFormat pix_fmt;
> +enum AVPixelFormat pix_fmt = link->format;
>  const AVPixFmtDescriptor *desc;
>  AVHWFramesContext *fctx;
>
> --
> 2.7.4
>
> ___
> 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] qsvenc: remove vcm option on Linux

2018-06-07 Thread Maxym Dmytrychenko
agree, Luca.

will close it shortly.

On Thu, Jun 7, 2018 at 5:04 PM, Luca Barbato  wrote:

> On 07/06/2018 10:51, Zhong Li wrote:
> > 1. vcm mode is only available for H264.
> > 2. vcm is not supported on Linux, but it is shown when run "./avconv -h
> > encoder=h264_qsv |grep vcm". This shouldn't happen.
> >
> > Signed-off-by: Zhong Li 
> > ---
> >  libavcodec/qsvenc.h  | 1 -
> >  libavcodec/qsvenc_h264.c | 3 +++
> >  2 files changed, 3 insertions(+), 1 deletion(-)
> >
>
> Sure
>
> ___
> 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 V2] lavc/qsvenc: add an option to disable MFE mode

2018-05-22 Thread Maxym Dmytrychenko
thanks Luca,

this patch should be reasonable

On Mon, May 21, 2018 at 9:58 AM, Luca Barbato  wrote:

> On 21/05/2018 08:33, Zhong Li wrote:
> > Not convenient if using numerals to set MFE mode. It is ambiguous
> > and misleading (e.g: user may misunderstand setting mfmode to 1 is to
> > enable MFE but actually it is to disable MFE, and set it to be 5 or
> above is meaningless).
> >
> > V2: remove the manual option since it is not supported now.
> >
> > Signed-off-by: Zhong Li 
> > ---
> >  libavcodec/qsvenc_h264.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> > index ae00ff8..2ecdb10 100644
> > --- a/libavcodec/qsvenc_h264.c
> > +++ b/libavcodec/qsvenc_h264.c
> > @@ -94,7 +94,9 @@ static const AVOption options[] = {
> >  { "aud", "Insert the Access Unit Delimiter NAL", OFFSET(qsv.aud),
> AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE},
> >
> >  #if QSV_HAVE_MF
> > -{ "mfmode", "Multi-Frame Mode", OFFSET(qsv.mfmode),
> AV_OPT_TYPE_INT, { .i64 = MFX_MF_AUTO }, 0, INT_MAX, VE },
> > +{ "mfmode", "Multi-Frame Mode", OFFSET(qsv.mfmode),
> AV_OPT_TYPE_INT, { .i64 = MFX_MF_AUTO }, MFX_MF_DEFAULT, MFX_MF_AUTO, VE,
> "mfmode"},
> > +{ "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_DISABLED
> }, INT_MIN, INT_MAX, VE, "mfmode" },
> > +{ "auto"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_AUTO
>  }, INT_MIN, INT_MAX, VE, "mfmode" },
> >  #endif
> >
> >  { NULL },
> >
>
> Sounds fine to me, the previous iteration was on hold since Maxym wanted
> to test it.
>
> I guess this time it should work as intended on every current mfx release
> :)
>
> 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

Re: [libav-devel] [PATCH 2/2] lavc/qsvenc: add mf_max_num option for MFE

2018-05-07 Thread Maxym Dmytrychenko
looks ok for me as well

On Sat, May 5, 2018 at 12:06 AM, Zhong Li  wrote:

> Maximum number of frames to be used for combining.
> Each encoder in joined sessions has to be initialized with the same value.
>
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvenc.c  | 1 +
>  libavcodec/qsvenc.h  | 1 +
>  libavcodec/qsvenc_h264.c | 2 ++
>  3 files changed, 4 insertions(+)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index a8b446c..9dd1699 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -666,6 +666,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  q->extmfp.Header.BufferSz = sizeof(q->extmfp);
>
>  q->extmfp.MFMode = q->mfmode;
> +q->extmfp.MaxNumFrames = q->mf_max_num;
>  av_log(avctx,AV_LOG_VERBOSE,"MFMode:%d\n",
> q->extmfp.MFMode);
>  q->extparam_internal[q->nb_extparam_internal++] =
> (mfxExtBuffer *)>extmfp;
>  }
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index a7fc57b..2b1a349 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -163,6 +163,7 @@ typedef struct QSVEncContext {
>
>  #if QSV_HAVE_MF
>  int mfmode;
> +int mf_max_num;
>  #endif
>  char *load_plugins;
>  } QSVEncContext;
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index 7f3fd5a..aa40f8e 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -99,6 +99,8 @@ static const AVOption options[] = {
>  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_DISABLED },
> INT_MIN, INT_MAX, VE, "mfmode" },
>  { "auto"   , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_AUTO },
> INT_MIN, INT_MAX, VE, "mfmode" },
>  { "manual" , NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_MF_MANUAL   },
> INT_MIN, INT_MAX, VE, "mfmode" },
> +
> +{ "mf_max_num", "Maximum frame number of Multi-Frame encoding",
> OFFSET(qsv.mf_max_num), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 3, VE},
>  #endif
>
>  { NULL },
> --
> 2.7.4
>
> ___
> 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 v2] qsv: adding Multi Frame Encode support

2018-04-05 Thread Maxym Dmytrychenko
thanks, Luca

I see QSV_HAVE_MF as compile time definition
where QSV_RUNTIME_VERSION_ATLEAST reflects runtime version check

as it might be two different aspects and it would be more logical to check
both at proper time.

ok?

On Wed, Apr 4, 2018 at 12:07 PM, Luca Barbato <lu_z...@gentoo.org> wrote:

> On 02/04/2018 15:17, Maxym Dmytrychenko wrote:
> > +if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
>
> Maybe use QSV_HAVE_MF ?
>
> The rest looks fine to me.
>
> 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 v2] qsv: adding Multi Frame Encode support

2018-04-02 Thread Maxym Dmytrychenko
Starting from API 1.25 helps to improve performance of the simultaneous
encode, 1:N scenario, like:

./avconv  -y -hwaccel qsv -c:v h264_qsv -r 3/1001 -i
~/bbb_sunflower_1080p_60fps_normal.mp4  -vframes 600 -an \
-filter_complex "split=2[s1][s2]; [s1]scale_qsv=1280:720[o1];
[s2]scale_qsv=960:540[o2]" \
-map [o1] -c:v h264_qsv -b:v 3200k -minrate 3200k -maxrate 3200k -f
rawvideo /tmp/3200a.264 \
-map [o2] -c:v h264_qsv -b:v 1750k -minrate 1750k -maxrate 1750k -f
rawvideo /tmp/1750a.264
---
 libavcodec/qsv.c | 10 ++
 libavcodec/qsv_internal.h|  4 
 libavcodec/qsvenc.c  | 16 +++-
 libavcodec/qsvenc.h  | 12 ++--
 libavcodec/qsvenc_h264.c |  4 
 libavfilter/qsvvpp.c |  9 ++---
 libavfilter/qsvvpp.h |  8 
 libavfilter/vf_deinterlace_qsv.c |  7 +++
 libavfilter/vf_scale_qsv.c   |  7 +++
 libavutil/hwcontext_qsv.c|  5 +
 10 files changed, 72 insertions(+), 10 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e78633d62..bab32836e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -593,10 +593,12 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
   "Error setting a HW handle");
 }
 
-err = MFXJoinSession(parent_session, session);
-if (err != MFX_ERR_NONE)
-return ff_qsv_print_error(avctx, err,
-  "Error joining session");
+if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
+err = MFXJoinSession(parent_session, session);
+if (err != MFX_ERR_NONE)
+return ff_qsv_print_error(avctx, err,
+  "Error joining session");
+}
 
 ret = qsv_load_plugins(session, load_plugins, avctx);
 if (ret < 0) {
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 975c8de44..d2a18eb06 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -36,6 +36,10 @@
 (MFX_VERSION_MAJOR > (MAJOR) || \
  MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
 
+#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
+(MFX_VERSION.Major > (MAJOR)) ||   \
+(MFX_VERSION.Major == (MAJOR) && MFX_VERSION.Minor >= (MINOR))
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDL handle;
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f6b1a0d67..a8b446c5b 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -135,7 +135,7 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 #if QSV_HAVE_CO2
 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
 #endif
-#if QSV_HAVE_CO3
+#if QSV_HAVE_CO3 && QSV_HAVE_QVBR
 mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
 #endif
 
@@ -656,6 +656,20 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco2;
 }
+#endif
+#if QSV_HAVE_MF
+if (avctx->codec_id == AV_CODEC_ID_H264) {
+mfxVersionver;
+ret = MFXQueryVersion(q->session,);
+if (ret >= MFX_ERR_NONE && QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 
25)) {
+q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
+q->extmfp.Header.BufferSz = sizeof(q->extmfp);
+
+q->extmfp.MFMode = q->mfmode;
+av_log(avctx,AV_LOG_VERBOSE,"MFMode:%d\n", q->extmfp.MFMode);
+q->extparam_internal[q->nb_extparam_internal++] = 
(mfxExtBuffer *)>extmfp;
+}
+}
 #endif
 }
 
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index ab5579595..a7fc57bb4 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -50,11 +50,13 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_VCMQSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 11)
+#define QSV_HAVE_MF 0
 #else
 #define QSV_HAVE_AVBR   0
 #define QSV_HAVE_ICQ0
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   0
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
 #endif
 
 #if !QSV_HAVE_LA_DS
@@ -109,12 +111,15 @@ typedef struct QSVEncContext {
 #if QSV_HAVE_CO2
 mfxExtCodingOption2 extco2;
 #endif
-
+#if QSV_HAVE_MF
+mfxExtMultiFrameParam   extmfp;
+mfxExtMultiFrameControl extmfc;
+#endif
 mfxExtOpaqueSurfaceAlloc opaque_alloc;
 mfxFrameSurface1   **opaque_surfaces;
 AVBufferRef *opaque_alloc_buf;
 
-mfxExtBuffer  *extparam_internal[2 + QSV_HAVE_CO2];
+mfxExtBuffer  *extparam_internal[2 + QSV_HAVE_CO2 + (QSV_HAVE_MF * 2)];
 int nb_extparam_internal;
 
 mfxExtBuffer **extparam;
@@ -156,6 +161,9 @@ typedef struct QSVEncContext {
 int int_ref_qp_delta;
 int recovery_point_sei;
 
+#if QSV_HAVE_MF
+int mfmode;
+#endif
 char 

Re: [libav-devel] [PATCH] qsv: adding Multi Frame Encode support

2018-04-02 Thread Maxym Dmytrychenko
thanks for the feedbacks , below some answers and v2 is upcoming.

On Thu, Mar 29, 2018 at 1:03 AM, Mark Thompson <s...@jkqxz.net> wrote:

> On 27/03/18 23:07, Maxym Dmytrychenko wrote:
> > On Tue, Mar 27, 2018 at 12:47 AM, Mark Thompson <s...@jkqxz.net> wrote:
> >
> >> On 26/03/18 21:18, Maxym Dmytrychenko wrote:
> >>> Starting from API 1.25 helps to improve performance of the simultaneous
> >> encode,
> >>> 1:N scenario, like:
> >>>
> >>> ./avconv  -y -hwaccel qsv -c:v h264_qsv -r 3/1001 -i
> >>> ~/bbb_sunflower_1080p_60fps_normal.mp4  -vframes 600 -an \
> >>> -filter_complex "split=2[s1][s2]; [s1]scale_qsv=1280:720[o1];
> >>> [s2]scale_qsv=960:540[o2]" \
> >>> -map [o1] -c:v h264_qsv -b:v 3200k -minrate 3200k -maxrate 3200k -f
> >>> rawvideo /tmp/3200a.264 \
> >>> -map [o2] -c:v h264_qsv -b:v 1750k -minrate 1750k -maxrate 1750k -f
> >>> rawvideo /tmp/1750a.264
> >>
> >> Having seen this interface being added form the VAAPI side, I got the
> >> impression that this only makes sense if the parallel streams are
> actually
> >> in lock-step (as in your example).  What will happen if this isn't the
> case?
> >>
> > thanks for the points, Mark.
> > it is actually testing phase but can you share more details over
> example(s)
> > you mean?
>
> Well, your example has two streams which encode exactly in parallel - in
> every step both streams encode one frame.
>
> I don't know what the implementation inside libmfx is, but suppose the
> streams don't run at the same rate, e.g. if one stream is twice as fast as
> the other as in (with libx264):
>
> ./avconv -y -i in.mp4 -an -filter_complex 'split=2[a][b]' -map '[a]' -r 10
> -c:v libx264 out_10.mp4 -map '[b]' -r 20 -c:v libx264 out_20.mp4
>
> Does everything still work as expected?
>
> As a worse case, suppose you have multiple input streams with unknown
> properties (including framerate) which want to be encoded with low-latency,
> does setting this option affect that latency because some streams wait for
> new frames to appear on others?
>
>
this option in WIP now but expectations - latency should not be affected



> (These questions are primarily trying to assess whether this should be
> enabled by default.)
>
> >> I'm also curious what the gain from this is, if you happen to have some
> >> numbers...
> >>
> > Actually depends on exact HW SKU and resolution/scenario, however, can be
> > well above 10%
> >
> >
> >>> ---
> >>>  libavcodec/qsv.c | 10 ++
> >>>  libavcodec/qsv_internal.h|  3 +++
> >>>  libavcodec/qsvdec.c  |  1 -
> >>>  libavcodec/qsvenc.c  | 16 +++-
> >>>  libavcodec/qsvenc.h  | 12 ++--
> >>>  libavcodec/qsvenc_h264.c |  4 
> >>>  libavfilter/qsvvpp.c |  9 ++---
> >>>  libavfilter/qsvvpp.h |  7 +++
> >>>  libavfilter/vf_deinterlace_qsv.c |  6 ++
> >>>  libavfilter/vf_scale_qsv.c   |  6 ++
> >>>  libavutil/hwcontext_qsv.c|  5 +
> >>>  libavutil/hwcontext_qsv.h|  3 +++
> >>>  12 files changed, 71 insertions(+), 11 deletions(-)
> >>>
> >>> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> >>> index e78633d62..bab32836e 100644
> >>> --- a/libavcodec/qsv.c
> >>> +++ b/libavcodec/qsv.c
> >>> @@ -593,10 +593,12 @@ int ff_qsv_init_session_device(AVCodecContext
> >> *avctx, mfxSession *psession,
> >>>"Error setting a HW handle");
> >>>  }
> >>>
> >>> -err = MFXJoinSession(parent_session, session);
> >>> -if (err != MFX_ERR_NONE)
> >>> -return ff_qsv_print_error(avctx, err,
> >>> -  "Error joining session");
> >>> +if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
> >>> +err = MFXJoinSession(parent_session, session);
> >>> +if (err != MFX_ERR_NONE)
> >>> +return ff_qsv_print_error(avctx, err,
> >>> +  "Error joining session");
> >>> +}
> >>>
> >>>  ret = qsv_load_plugins(session, load_plugins, avctx);
> >>>  if (ret < 0) {
> >>> diff --git a/libavcodec/qsv_internal.

Re: [libav-devel] [PATCH V2 2/3] lavu/hwcontext_qsv: Add support for pix_fmt RGB32.

2018-04-02 Thread Maxym Dmytrychenko
how about second option :  temporary frame with the stricter alignment and
copy to that before uploading
but with log/INFO message included ?

On Mon, Apr 2, 2018 at 2:45 PM, Mark Thompson  wrote:

> On 02/04/18 10:32, Li, Zhong wrote:
> >>> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> >>> index 5018a05..0db446b 100644
> >>> --- a/libavutil/hwcontext_qsv.c
> >>> +++ b/libavutil/hwcontext_qsv.c
> >>> ...
> >>> +surface->Data.Y  = frame->data[0];
> >>> +surface->Data.UV = frame->data[1];
> >>> +break;
> >>> +
> >>> +case AV_PIX_FMT_YUV420P:
> >>> +surface->Data.Y = frame->data[0];
> >>> +surface->Data.U = frame->data[1];
> >>> +surface->Data.V = frame->data[2];
> >>> +break;
> >>> +
> >>> +case AV_PIX_FMT_RGB32:
> >>> +surface->Data.B = frame->data[0];
> >>> +surface->Data.G = frame->data[0] + 1;
> >>> +surface->Data.R = frame->data[0] + 2;
> >>> +surface->Data.A = frame->data[0] + 3;
> >>> +break;
> >>> +
> >>> +default:
> >>> +return MFX_ERR_UNSUPPORTED;
> >>> +}
> >>> +surface->Data.Pitch = frame->linesize[0];
> >>
> >> What happens if linesize[0] != linesize[1]?  (You aren't introducing
> that
> >> problem, but I hadn't seen it before.)
> >
> > I don't think MSDK can handle this case perfectly since there is only
> one pitch.
> > Take YUV420p as example, IMHO it is required linesize of Y must be twice
> of U and V.
>
> That isn't going to be true for a general frame in libav - the pitches for
> each plane are independent.  Since they are usually created by taking the
> width of the plane and rounding up to the appropriate alignment (usually
> 32, I think) it will work for widths which are multiples of large powers of
> two - e.g. 1920 width will work because both 1920 and 960 are already
> aligned to a 32-byte boundary.  It won't work for less aligned widths (e.g.
> 720 width from NTSC or PAL will give luma pitch = align(720, 32) = 736 but
> chroma pitch = align(360, 32) = 384), nor will it work for other ways of
> laying out the frame such as line-interleaving.
>
> This problem was preexisting, though, so I guess it isn't necessary to
> deal with it in this patch.  Not sure what the right answer is - maybe it
> could just reject non-matching pitches and return an error?  Or it could
> make a temporary frame with the stricter alignment and copy to that before
> uploading?  (Though that might be slow and defeat the point of this upload
> path.)
>
> - Mark
> ___
> 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 2/2] lavf/qsvvpp: bypass vpp if not needed.

2018-04-02 Thread Maxym Dmytrychenko
going to the right direction, can we see more details about " specific
case." ?

On Thu, Mar 29, 2018 at 4:01 PM, Zhong Li  wrote:

> It is benefit to performance for specific case.
>
> Signed-off-by: Zhong Li 
> ---
>  libavfilter/vf_vpp_qsv.c | 28 +---
>  1 file changed, 25 insertions(+), 3 deletions(-)
>
> diff --git a/libavfilter/vf_vpp_qsv.c b/libavfilter/vf_vpp_qsv.c
> index 610e821..568dee5 100644
> --- a/libavfilter/vf_vpp_qsv.c
> +++ b/libavfilter/vf_vpp_qsv.c
> @@ -27,6 +27,7 @@
>  #include "libavutil/eval.h"
>  #include "libavutil/avassert.h"
>  #include "libavutil/pixdesc.h"
> +#include "libavutil/mathematics.h"
>
>  #include "formats.h"
>  #include "internal.h"
> @@ -249,6 +250,7 @@ static int config_output(AVFilterLink *outlink)
>  QSVVPPParam param = { NULL };
>  QSVVPPCrop  crop  = { 0 };
>  mfxExtBuffer*ext_buf[ENH_FILTERS_COUNT];
> +AVFilterLink*inlink = ctx->inputs[0];
>
>  outlink->w  = vpp->out_width;
>  outlink->h  = vpp->out_height;
> @@ -320,14 +322,34 @@ static int config_output(AVFilterLink *outlink)
>  param.ext_buf[param.num_ext_buf++] =
> (mfxExtBuffer*)>procamp_conf;
>  }
>
> -return ff_qsvvpp_create(ctx, >qsv, );
> +if (vpp->use_frc || vpp->use_crop || vpp->deinterlace || vpp->denoise
> ||
> +vpp->detail || vpp->procamp || inlink->w != outlink->w ||
> inlink->h != outlink->h)
> +return ff_qsvvpp_create(ctx, >qsv, );
> +else {
> +av_log(ctx, AV_LOG_VERBOSE, "qsv vpp pass through mode.\n");
> +if (inlink->hw_frames_ctx)
> +outlink->hw_frames_ctx = av_buffer_ref(inlink->hw_
> frames_ctx);
> +}
> +
> +return 0;
>  }
>
>  static int filter_frame(AVFilterLink *inlink, AVFrame *picref)
>  {
> -VPPContext *vpp = inlink->dst->priv;
> +int  ret = 0;
> +AVFilterContext  *ctx = inlink->dst;
> +VPPContext   *vpp = inlink->dst->priv;
> +AVFilterLink *outlink = ctx->outputs[0];
> +
> +if (vpp->qsv)
> +ret = ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
> +else {
> +if (picref->pts != AV_NOPTS_VALUE)
> +picref->pts = av_rescale_q(picref->pts, inlink->time_base,
> outlink->time_base);
> +ret = ff_filter_frame(outlink, picref);
> +}
>
> -return ff_qsvvpp_filter_frame(vpp->qsv, inlink, picref);
> +return ret;
>  }
>
>  static int query_formats(AVFilterContext *ctx)
> --
> 1.8.3.1
>
> ___
> 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 V2 2/3] lavu/hwcontext_qsv: Add support for pix_fmt RGB32.

2018-03-29 Thread Maxym Dmytrychenko
should be ok,

will take care of it shotly

On Thu, Mar 29, 2018 at 4:05 PM, Li, Zhong  wrote:

> Ping?
>
> > -Original Message-
> > From: Li, Zhong
> > Sent: Thursday, March 22, 2018 10:42 PM
> > To: libav-devel@libav.org
> > Cc: Li, Zhong ; Liu, ChaoX A 
> > Subject: [PATCH V2 2/3] lavu/hwcontext_qsv: Add support for pix_fmt
> > RGB32.
> >
> > RGB32 format may be used as overlay with alpha blending.
> > So add RGB32 format support.
> >
> > Signed-off-by: ChaoX A Liu 
> > Signed-off-by: Zhong Li 
> > ---
> >  libavutil/hwcontext_qsv.c | 43
> > +--
> >  1 file changed, 33 insertions(+), 10 deletions(-)
> >
> > diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c index
> > 5018a05..0db446b 100644
> > --- a/libavutil/hwcontext_qsv.c
> > +++ b/libavutil/hwcontext_qsv.c
> > @@ -90,6 +90,7 @@ static const struct {
> >  uint32_t   fourcc;
> >  } supported_pixel_formats[] = {
> >  { AV_PIX_FMT_NV12, MFX_FOURCC_NV12 },
> > +{ AV_PIX_FMT_RGB32,MFX_FOURCC_RGB4 },
> >  { AV_PIX_FMT_P010, MFX_FOURCC_P010 },
> >  { AV_PIX_FMT_PAL8, MFX_FOURCC_P8   },
> >  };
> > @@ -730,6 +731,36 @@ static int
> > qsv_transfer_data_child(AVHWFramesContext *ctx, AVFrame *dst,
> >  return ret;
> >  }
> >
> > +static int map_frame_to_surface(const AVFrame *frame,
> > mfxFrameSurface1
> > +*surface) {
> > +switch (frame->format) {
> > +case AV_PIX_FMT_NV12:
> > +surface->Data.Y  = frame->data[0];
> > +surface->Data.UV = frame->data[1];
> > +break;
> > +
> > +case AV_PIX_FMT_YUV420P:
> > +surface->Data.Y = frame->data[0];
> > +surface->Data.U = frame->data[1];
> > +surface->Data.V = frame->data[2];
> > +break;
> > +
> > +case AV_PIX_FMT_RGB32:
> > +surface->Data.B = frame->data[0];
> > +surface->Data.G = frame->data[0] + 1;
> > +surface->Data.R = frame->data[0] + 2;
> > +surface->Data.A = frame->data[0] + 3;
> > +break;
> > +
> > +default:
> > +return MFX_ERR_UNSUPPORTED;
> > +}
> > +surface->Data.Pitch = frame->linesize[0];
> > +surface->Data.TimeStamp = frame->pts;
> > +
> > +return 0;
> > +}
> > +
> >  static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame
> > *dst,
> >const AVFrame *src)  { @@
> > -749,11 +780,7 @@ static int qsv_transfer_data_from(AVHWFramesContext
> > *ctx, AVFrame *dst,
> >  }
> >
> >  out.Info = in->Info;
> > -out.Data.PitchLow = dst->linesize[0];
> > -out.Data.Y= dst->data[0];
> > -out.Data.U= dst->data[1];
> > -out.Data.V= dst->data[2];
> > -out.Data.A= dst->data[3];
> > +map_frame_to_surface(dst, );
> >
> >  do {
> >  err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in,
> > , NULL, ); @@ -796,11 +823,7 @@ static int
> > qsv_transfer_data_to(AVHWFramesContext *ctx, AVFrame *dst,
> >  }
> >
> >  in.Info = out->Info;
> > -in.Data.PitchLow = src->linesize[0];
> > -in.Data.Y= src->data[0];
> > -in.Data.U= src->data[1];
> > -in.Data.V= src->data[2];
> > -in.Data.A= src->data[3];
> > +map_frame_to_surface(src, );
> >
> >  do {
> >  err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, ,
> > out, NULL, );
> > --
> > 1.8.3.1
>
> ___
> 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] qsv: adding Multi Frame Encode support

2018-03-27 Thread Maxym Dmytrychenko
On Tue, Mar 27, 2018 at 11:55 AM, Li, Zhong  wrote:

> > diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h index
> > 975c8de44..516994a64 100644
> > --- a/libavcodec/qsv_internal.h
> > +++ b/libavcodec/qsv_internal.h
> > @@ -36,6 +36,9 @@
> >  (MFX_VERSION_MAJOR > (MAJOR) || \
> >   MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >=
> > (MINOR))
> >
> > +#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR,
> > MINOR) \
> > +(MFX_VERSION.Major == MAJOR  && MFX_VERSION.Minor >=
> > MINOR)
> > +
>
> Should also be ok for "MFX_VERSION.Major > MAJOR"? Just like
> QSV_VERSION_ATLEAST.
>
> good point to be fixed!
thanks

>  typedef struct QSVMid {
> >  AVBufferRef *hw_frames_ref;
> >  mfxHDL handle;
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index
> > f31172de2..b45216291 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -332,7 +332,6 @@ static int qsv_decode(AVCodecContext *avctx,
> > QSVContext *q,
> >  av_freep();
> >  return ret;
> >  }
> > -
> >  ret = MFXVideoDECODE_DecodeFrameAsync(q->session,
> > avpkt->size ?  : NULL,
> >insurf, ,
> > sync);
> >  if (ret == MFX_WRN_DEVICE_BUSY) diff --git
> > a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index f6b1a0d67..a8b446c5b
> > 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -135,7 +135,7 @@ static void dump_video_param(AVCodecContext
> > *avctx, QSVEncContext *q,  #if QSV_HAVE_CO2
> >  mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
> >  #endif
> > -#if QSV_HAVE_CO3
> > +#if QSV_HAVE_CO3 && QSV_HAVE_QVBR
> >  mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
> >  #endif
> >
>
> Not sure why we need this change and how it impacts MFE.
>
see co3 used only when  QSV_HAVE_QVBR - so it is logical and fixes
compilation issue.

___
> 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] qsv: adding Multi Frame Encode support

2018-03-27 Thread Maxym Dmytrychenko
On Tue, Mar 27, 2018 at 12:47 AM, Mark Thompson <s...@jkqxz.net> wrote:

> On 26/03/18 21:18, Maxym Dmytrychenko wrote:
> > Starting from API 1.25 helps to improve performance of the simultaneous
> encode,
> > 1:N scenario, like:
> >
> > ./avconv  -y -hwaccel qsv -c:v h264_qsv -r 3/1001 -i
> > ~/bbb_sunflower_1080p_60fps_normal.mp4  -vframes 600 -an \
> > -filter_complex "split=2[s1][s2]; [s1]scale_qsv=1280:720[o1];
> > [s2]scale_qsv=960:540[o2]" \
> > -map [o1] -c:v h264_qsv -b:v 3200k -minrate 3200k -maxrate 3200k -f
> > rawvideo /tmp/3200a.264 \
> > -map [o2] -c:v h264_qsv -b:v 1750k -minrate 1750k -maxrate 1750k -f
> > rawvideo /tmp/1750a.264
>
> Having seen this interface being added form the VAAPI side, I got the
> impression that this only makes sense if the parallel streams are actually
> in lock-step (as in your example).  What will happen if this isn't the case?
>
> thanks for the points, Mark.
it is actually testing phase but can you share more details over example(s)
you mean?


> I'm also curious what the gain from this is, if you happen to have some
> numbers...
>
> Actually depends on exact HW SKU and resolution/scenario, however, can be
well above 10%


> > ---
> >  libavcodec/qsv.c | 10 ++
> >  libavcodec/qsv_internal.h|  3 +++
> >  libavcodec/qsvdec.c  |  1 -
> >  libavcodec/qsvenc.c  | 16 +++-
> >  libavcodec/qsvenc.h  | 12 ++--
> >  libavcodec/qsvenc_h264.c |  4 
> >  libavfilter/qsvvpp.c |  9 ++---
> >  libavfilter/qsvvpp.h |  7 +++
> >  libavfilter/vf_deinterlace_qsv.c |  6 ++
> >  libavfilter/vf_scale_qsv.c   |  6 ++
> >  libavutil/hwcontext_qsv.c|  5 +
> >  libavutil/hwcontext_qsv.h|  3 +++
> >  12 files changed, 71 insertions(+), 11 deletions(-)
> >
> > diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> > index e78633d62..bab32836e 100644
> > --- a/libavcodec/qsv.c
> > +++ b/libavcodec/qsv.c
> > @@ -593,10 +593,12 @@ int ff_qsv_init_session_device(AVCodecContext
> *avctx, mfxSession *psession,
> >"Error setting a HW handle");
> >  }
> >
> > -err = MFXJoinSession(parent_session, session);
> > -if (err != MFX_ERR_NONE)
> > -return ff_qsv_print_error(avctx, err,
> > -  "Error joining session");
> > +if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
> > +err = MFXJoinSession(parent_session, session);
> > +if (err != MFX_ERR_NONE)
> > +return ff_qsv_print_error(avctx, err,
> > +  "Error joining session");
> > +}
> >
> >  ret = qsv_load_plugins(session, load_plugins, avctx);
> >  if (ret < 0) {
> > diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
> > index 975c8de44..516994a64 100644
> > --- a/libavcodec/qsv_internal.h
> > +++ b/libavcodec/qsv_internal.h
> > @@ -36,6 +36,9 @@
> >  (MFX_VERSION_MAJOR > (MAJOR) || \
> >   MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
> >
> > +#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
> > +(MFX_VERSION.Major == MAJOR  && MFX_VERSION.Minor >= MINOR)
> > +
> >  typedef struct QSVMid {
> >  AVBufferRef *hw_frames_ref;
> >  mfxHDL handle;
> > diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> > index f31172de2..b45216291 100644
> > --- a/libavcodec/qsvdec.c
> > +++ b/libavcodec/qsvdec.c
> > @@ -332,7 +332,6 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
> >  av_freep();
> >  return ret;
> >  }
> > -
>
> Stray change.
>
+ per Luca's comment - will remove it.


>
> >  ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size
> ?  : NULL,
> >insurf, , sync);
> >  if (ret == MFX_WRN_DEVICE_BUSY)
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index f6b1a0d67..a8b446c5b 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -135,7 +135,7 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
> >  #if QSV_HAVE_CO2
> >  mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
> >  #endif
> > -#if QSV_HAVE_CO3
> > +#if QS

[libav-devel] [PATCH] qsv: adding Multi Frame Encode support

2018-03-26 Thread Maxym Dmytrychenko
Starting from API 1.25 helps to improve performance of the simultaneous encode,
1:N scenario, like:

./avconv  -y -hwaccel qsv -c:v h264_qsv -r 3/1001 -i
~/bbb_sunflower_1080p_60fps_normal.mp4  -vframes 600 -an \
-filter_complex "split=2[s1][s2]; [s1]scale_qsv=1280:720[o1];
[s2]scale_qsv=960:540[o2]" \
-map [o1] -c:v h264_qsv -b:v 3200k -minrate 3200k -maxrate 3200k -f
rawvideo /tmp/3200a.264 \
-map [o2] -c:v h264_qsv -b:v 1750k -minrate 1750k -maxrate 1750k -f
rawvideo /tmp/1750a.264
---
 libavcodec/qsv.c | 10 ++
 libavcodec/qsv_internal.h|  3 +++
 libavcodec/qsvdec.c  |  1 -
 libavcodec/qsvenc.c  | 16 +++-
 libavcodec/qsvenc.h  | 12 ++--
 libavcodec/qsvenc_h264.c |  4 
 libavfilter/qsvvpp.c |  9 ++---
 libavfilter/qsvvpp.h |  7 +++
 libavfilter/vf_deinterlace_qsv.c |  6 ++
 libavfilter/vf_scale_qsv.c   |  6 ++
 libavutil/hwcontext_qsv.c|  5 +
 libavutil/hwcontext_qsv.h|  3 +++
 12 files changed, 71 insertions(+), 11 deletions(-)

diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
index e78633d62..bab32836e 100644
--- a/libavcodec/qsv.c
+++ b/libavcodec/qsv.c
@@ -593,10 +593,12 @@ int ff_qsv_init_session_device(AVCodecContext *avctx, 
mfxSession *psession,
   "Error setting a HW handle");
 }
 
-err = MFXJoinSession(parent_session, session);
-if (err != MFX_ERR_NONE)
-return ff_qsv_print_error(avctx, err,
-  "Error joining session");
+if (QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 25)) {
+err = MFXJoinSession(parent_session, session);
+if (err != MFX_ERR_NONE)
+return ff_qsv_print_error(avctx, err,
+  "Error joining session");
+}
 
 ret = qsv_load_plugins(session, load_plugins, avctx);
 if (ret < 0) {
diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h
index 975c8de44..516994a64 100644
--- a/libavcodec/qsv_internal.h
+++ b/libavcodec/qsv_internal.h
@@ -36,6 +36,9 @@
 (MFX_VERSION_MAJOR > (MAJOR) || \
  MFX_VERSION_MAJOR == (MAJOR) && MFX_VERSION_MINOR >= (MINOR))
 
+#define QSV_RUNTIME_VERSION_ATLEAST(MFX_VERSION, MAJOR, MINOR) \
+(MFX_VERSION.Major == MAJOR  && MFX_VERSION.Minor >= MINOR)
+
 typedef struct QSVMid {
 AVBufferRef *hw_frames_ref;
 mfxHDL handle;
diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index f31172de2..b45216291 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -332,7 +332,6 @@ static int qsv_decode(AVCodecContext *avctx, QSVContext *q,
 av_freep();
 return ret;
 }
-
 ret = MFXVideoDECODE_DecodeFrameAsync(q->session, avpkt->size ?  : 
NULL,
   insurf, , sync);
 if (ret == MFX_WRN_DEVICE_BUSY)
diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
index f6b1a0d67..a8b446c5b 100644
--- a/libavcodec/qsvenc.c
+++ b/libavcodec/qsvenc.c
@@ -135,7 +135,7 @@ static void dump_video_param(AVCodecContext *avctx, 
QSVEncContext *q,
 #if QSV_HAVE_CO2
 mfxExtCodingOption2 *co2 = (mfxExtCodingOption2*)coding_opts[1];
 #endif
-#if QSV_HAVE_CO3
+#if QSV_HAVE_CO3 && QSV_HAVE_QVBR
 mfxExtCodingOption3 *co3 = (mfxExtCodingOption3*)coding_opts[2];
 #endif
 
@@ -656,6 +656,20 @@ FF_ENABLE_DEPRECATION_WARNINGS
 
 q->extparam_internal[q->nb_extparam_internal++] = (mfxExtBuffer 
*)>extco2;
 }
+#endif
+#if QSV_HAVE_MF
+if (avctx->codec_id == AV_CODEC_ID_H264) {
+mfxVersionver;
+ret = MFXQueryVersion(q->session,);
+if (ret >= MFX_ERR_NONE && QSV_RUNTIME_VERSION_ATLEAST(ver, 1, 
25)) {
+q->extmfp.Header.BufferId = MFX_EXTBUFF_MULTI_FRAME_PARAM;
+q->extmfp.Header.BufferSz = sizeof(q->extmfp);
+
+q->extmfp.MFMode = q->mfmode;
+av_log(avctx,AV_LOG_VERBOSE,"MFMode:%d\n", q->extmfp.MFMode);
+q->extparam_internal[q->nb_extparam_internal++] = 
(mfxExtBuffer *)>extmfp;
+}
+}
 #endif
 }
 
diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
index ab5579595..a7fc57bb4 100644
--- a/libavcodec/qsvenc.h
+++ b/libavcodec/qsvenc.h
@@ -50,11 +50,13 @@
 #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_VCMQSV_VERSION_ATLEAST(1, 8)
 #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 11)
+#define QSV_HAVE_MF 0
 #else
 #define QSV_HAVE_AVBR   0
 #define QSV_HAVE_ICQ0
 #define QSV_HAVE_VCM0
 #define QSV_HAVE_QVBR   0
+#define QSV_HAVE_MF QSV_VERSION_ATLEAST(1, 25)
 #endif
 
 #if !QSV_HAVE_LA_DS
@@ -109,12 +111,15 @@ typedef struct QSVEncContext {
 #if QSV_HAVE_CO2
 mfxExtCodingOption2 extco2;
 #endif
-
+#if QSV_HAVE_MF
+mfxExtMultiFrameParam   extmfp;
+mfxExtMultiFrameControl extmfc;
+#endif
 

Re: [libav-devel] [PATCH V3 3/3] lavc/qsvdec: expose frame pic_type

2018-03-26 Thread Maxym Dmytrychenko
aside of intend points at  frame->surface..., should be ok

On Thu, Mar 22, 2018 at 3:41 PM, Zhong Li  wrote:

> Currently pict_type are unset.
> Add an extra param to fetch the picture type from qsv decoder
>
> v2: fix the compile error since AV_PICTURE_TYPE_NONE is not existed in
> libav.
> v3: remove the key_frame setting because the judgement “key frame is equal
> to IDR frame” only suitable for H264.
> For HEVC, all IRAP frames are key frames, and other codecs have no IDR
> frame.
>
> Signed-off-by: ChaoX A Liu 
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsv.c  | 24 
>  libavcodec/qsv_internal.h |  3 +++
>  libavcodec/qsvdec.c   |  6 ++
>  3 files changed, 33 insertions(+)
>
> diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c
> index 96dca14..c7ba642 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 8148beb..c0ed4bd 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -235,6 +235,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;
>
> @@ -421,6 +426,7 @@ 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);
>
>  /* update the surface properties */
>  if (avctx->pix_fmt == AV_PIX_FMT_QSV)
> --
> 1.8.3.1
>
> ___
> 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 2/2] lavu/hwcontext_qsv: Add support for pix_fmt RGB32.

2018-03-21 Thread Maxym Dmytrychenko
Clean and specific patch is always good, agree with you on removal here.

On Tue, Mar 20, 2018 at 9:18 AM, Li, Zhong <zhong...@intel.com> wrote:

> > From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
> > Maxym Dmytrychenko
> > Sent: Monday, March 19, 2018 5:56 PM
> > To: libav development <libav-devel@libav.org>
> > Cc: Liu, ChaoX A <chaox.a@intel.com>
> > Subject: Re: [libav-devel] [PATCH 2/2] lavu/hwcontext_qsv: Add support
> for
> > pix_fmt RGB32.
> >
> > indentation can be adjusted ,
>
> It is to support RGB format overlay (e.g. lena-rgba.png).
>
> > AV_PIX_FMT_YUYV422  - we add it but dont use?
>
> If the overlay input movie format is 4:2:2, it will be used. But I prefer
> to remove it in this patch to make it clearer.
> How do you think?
> ___
> 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 2/2] lavu/hwcontext_qsv: Add support for pix_fmt RGB32.

2018-03-19 Thread Maxym Dmytrychenko
indentation can be adjusted ,
AV_PIX_FMT_YUYV422  - we add it but dont use?

On Mon, Mar 19, 2018 at 10:33 AM, Zhong Li  wrote:

> And support nv12/yuyv422/rgb32 formats for qsv_transfer_data
>
> Signed-off-by: ChaoX A Liu 
> Signed-off-by: Zhong Li 
> ---
>  libavutil/hwcontext_qsv.c | 49 ++
> +++--
>  1 file changed, 39 insertions(+), 10 deletions(-)
>
> diff --git a/libavutil/hwcontext_qsv.c b/libavutil/hwcontext_qsv.c
> index 5018a05..47afa48 100644
> --- a/libavutil/hwcontext_qsv.c
> +++ b/libavutil/hwcontext_qsv.c
> @@ -90,6 +90,7 @@ static const struct {
>  uint32_t   fourcc;
>  } supported_pixel_formats[] = {
>  { AV_PIX_FMT_NV12, MFX_FOURCC_NV12 },
> +{ AV_PIX_FMT_RGB32,MFX_FOURCC_RGB4 },
>  { AV_PIX_FMT_P010, MFX_FOURCC_P010 },
>  { AV_PIX_FMT_PAL8, MFX_FOURCC_P8   },
>  };
> @@ -730,6 +731,42 @@ static int qsv_transfer_data_child(AVHWFramesContext
> *ctx, AVFrame *dst,
>  return ret;
>  }
>
> +static int map_frame_to_surface(const AVFrame *frame, mfxFrameSurface1
> *surface)
> +{
> +switch (frame->format) {
> +case AV_PIX_FMT_NV12:
> +surface->Data.Y  = frame->data[0];
> +surface->Data.UV = frame->data[1];
> +break;
> +
> +case AV_PIX_FMT_YUV420P:
> +surface->Data.Y = frame->data[0];
> +surface->Data.U = frame->data[1];
> +surface->Data.V = frame->data[2];
> +break;
> +
> +case AV_PIX_FMT_YUYV422:
> +surface->Data.Y = frame->data[0];
> +surface->Data.U = frame->data[0] + 1;
> +surface->Data.V = frame->data[0] + 3;
> +break;
> +
> +case AV_PIX_FMT_RGB32:
> +surface->Data.B = frame->data[0];
> +surface->Data.G = frame->data[0] + 1;
> +surface->Data.R = frame->data[0] + 2;
> +surface->Data.A = frame->data[0] + 3;
> +break;
> +
> +default:
> +return MFX_ERR_UNSUPPORTED;
> +}
> +surface->Data.Pitch = frame->linesize[0];
> +surface->Data.TimeStamp = frame->pts;
> +
> +return 0;
> +}
> +
>  static int qsv_transfer_data_from(AVHWFramesContext *ctx, AVFrame *dst,
>const AVFrame *src)
>  {
> @@ -749,11 +786,7 @@ static int qsv_transfer_data_from(AVHWFramesContext
> *ctx, AVFrame *dst,
>  }
>
>  out.Info = in->Info;
> -out.Data.PitchLow = dst->linesize[0];
> -out.Data.Y= dst->data[0];
> -out.Data.U= dst->data[1];
> -out.Data.V= dst->data[2];
> -out.Data.A= dst->data[3];
> +map_frame_to_surface(dst, );
>
>  do {
>  err = MFXVideoVPP_RunFrameVPPAsync(s->session_download, in,
> , NULL, );
> @@ -796,11 +829,7 @@ static int qsv_transfer_data_to(AVHWFramesContext
> *ctx, AVFrame *dst,
>  }
>
>  in.Info = out->Info;
> -in.Data.PitchLow = src->linesize[0];
> -in.Data.Y= src->data[0];
> -in.Data.U= src->data[1];
> -in.Data.V= src->data[2];
> -in.Data.A= src->data[3];
> +map_frame_to_surface(src, );
>
>  do {
>  err = MFXVideoVPP_RunFrameVPPAsync(s->session_upload, , out,
> NULL, );
> --
> 1.8.3.1
>
> ___
> 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 1/2] lavc/qsvdec: set complete_frame flags for non-interlaced frames.

2018-03-19 Thread Maxym Dmytrychenko
 MFX_BITSTREAM_COMPLETE_FRAME support can be added as a param
 or can be only such if() conditions sufficient for all cases and streams ?

On Mon, Mar 19, 2018 at 10:33 AM, Zhong Li  wrote:

> Set the flag MFX_BITSTREAM_COMPLETE_FRAME when it is a completed frame.
> This can fix vc1 decoding segment fault issues because can't set the start
> code correctly.
> See: ./avconv -hwaccel qsv -c:v vc1_qsv -i /fate-suite/vc1/SA00040.vc1
> -vf "hwdownload, format=nv12" -f rawvideo /dev/null
>
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvdec.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
> index c74ec68..dc44865 100644
> --- a/libavcodec/qsvdec.c
> +++ b/libavcodec/qsvdec.c
> @@ -321,6 +321,9 @@ static int qsv_decode(AVCodecContext *avctx,
> QSVContext *q,
>  bs.DataLength = avpkt->size;
>  bs.MaxLength  = bs.DataLength;
>  bs.TimeStamp  = avpkt->pts;
> +if (avctx->field_order == AV_FIELD_UNKNOWN ||
> +avctx->field_order == AV_FIELD_PROGRESSIVE)
> +bs.DataFlag   |= MFX_BITSTREAM_COMPLETE_FRAME;
>  }
>
>  sync = av_mallocz(sizeof(*sync));
> --
> 1.8.3.1
>
> ___
> 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] AV1 support through libaom

2018-03-11 Thread Maxym Dmytrychenko
looks very promising, Luca !


On Thu, Mar 8, 2018 at 9:50 PM, Luca Barbato  wrote:

> [PATCH 1/3] ivf: Support VP9 and AV1 as well
> Unchanged
>
> [PATCH 2/3] Add AV1 video decoding support through libaom
> Now copies the 8bit highbitdepth variant to normal planar yuv correctly
>
> [PATCH 3/3] Support AV1 encoding using libaom
> Functional changes asked in review
>
> Documentation and other frills -> help welcome
>
> 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

Re: [libav-devel] [PATCH] lavc/qsvenc: provide detail error message if parameters invalid

2018-03-02 Thread Maxym Dmytrychenko
The same :)

> 2 марта 2018 г., в 5:11, Luca Barbato  написал(а):
> 
>> On 02/03/2018 04:26, Zhong Li wrote:
>> Currently always shows "Selected ratecontrol mode is not supported by
>> the QSV runtime. Choose a different mode", but sometimes it is not
>> accurate.
>> Signed-off-by: Zhong Li 
>> ---
>>  libavcodec/qsvenc.c | 31 +--
>>  1 file changed, 25 insertions(+), 6 deletions(-)
> 
> 
> Looks good, thank you :)
> 
> ___
> 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 6/8] vf_hwupload/hwmap: Support setting a fixed pool size

2018-02-11 Thread Maxym Dmytrychenko
On Mon, Feb 12, 2018 at 12:30 AM, wm4  wrote:

> On Sun, 11 Feb 2018 23:09:51 +
> Mark Thompson  wrote:
>
> > On 11/02/18 07:21, Song, Ruiling wrote:
> > > I have run some test against the patches. It works as described.
> >
> > Great - there is general agreement on that part now so I've applied that
> series.
> >
> > > Are you still against setting a default value within qsv_init_pool()?
> > > Users can easily override the default value through the interface you
> added.
> > > And if they did not set a value, the default value will be used.
> >
> > I don't mind the idea but I'm against the specificity of it, I guess.
> The single value will help in the isolated hwupload case, but it would be
> inconsistent with other APIs and doesn't suggest a sensible value to anyone
> who does need to set a fixed pool size.
> >
> > > If you are OK, I will re-submit the patch and add more comment on the
> magic value.
> > > If you are against, we can discuss it further for a better solution.
> >
> > Returning to suggestions made before, how would you feel about adding
> some way to determine from a device how big a frames context should be for
> it?
>

sounds like potential solution.


> > The simplest method to do that would be to add a new element to
> HWContextType containing a sensible value.  If it's zero, dynamic
> allocation is supported and noone needs to care any further.  If it's
> nonzero, then it becomes the default value for pool size used in the
> absence of any other choice.  It would be used in av_hwframe_ctx_init() if
> it's set on the type and initial_pool_size is zero, which would fix our
> hwupload case.  Probably it would want some way for the user to access it
> as well - new API for retrieving property values somehow, maybe?  (Not sure
> about that bit.)
> >
> > Would that work for you?  Anyone want to offer any criticism / other
> ideas which don't depend on semi-mythical rewrites of lavfi link
> negotiation?
>
> Still feels kind of arbitrary. What exactly determines the size the
> hwcontext will propose?
>

sort of HW specific value but with promise to be sufficient at most of the
cases.

Even if a constant value - HW has not much logic to find a better one
but pool will be sufficient.


> ___
> 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] lavc/qsv: default la_ds to MFX_LOOKAHEAD_DS_UNKNOWN

2018-02-11 Thread Maxym Dmytrychenko
looks reasonable.

On Sun, Feb 11, 2018 at 8:43 AM, Ruiling Song 
wrote:

> MFX_LOOKAHEAD_DS_UNKNOWN means auto.
> -1 is not a valid value.
>
> Signed-off-by: Ruiling Song 
> ---
>  libavcodec/qsvenc.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index 088a61d..6a8f119 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -71,8 +71,9 @@
>  { "slow",   NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> MFX_TARGETUSAGE_BEST_QUALITY  }, INT_MIN, INT_MAX, VE, "preset" },
>\
>  { "la_depth", "Number of frames to analyze before encoding.",
> OFFSET(qsv.la_depth), AV_OPT_TYPE_INT, { .i64 = 9 },   9, 100, VE,
> "la_depth" },  \
>  { "unset", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 9 }, INT_MIN, INT_MAX,
>VE, "la_depth" },  \
> -{ "la_ds", "Downscaling factor for the frames saved for the lookahead
> analysis", OFFSET(qsv.la_ds), AV_OPT_TYPE_INT, { .i64 = -1 },   -1,
> MFX_LOOKAHEAD_DS_4x, VE, "la_ds" }, \
> -{ "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, INT_MIN, INT_MAX,
>VE, "la_ds" }, \
> +{ "la_ds", "Downscaling factor for the frames saved for the lookahead
> analysis", OFFSET(qsv.la_ds), AV_OPT_TYPE_INT,\
> +{ .i64 = MFX_LOOKAHEAD_DS_UNKNOWN },
> MFX_LOOKAHEAD_DS_UNKNOWN, MFX_LOOKAHEAD_DS_4x, VE, "la_ds" },
> \
> +{ "auto", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_UNKNOWN
> }, INT_MIN, INT_MAX, VE, "la_ds" }, \
>  { "off", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_OFF },
> INT_MIN, INT_MAX,  VE, "la_ds" }, \
>  { "2x", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_2x },
> INT_MIN, INT_MAX,VE, "la_ds" },
> \
>  { "4x", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = MFX_LOOKAHEAD_DS_4x },
> INT_MIN, INT_MAX,VE, "la_ds" },
> \
> --
> 2.7.4
>
> ___
> 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] qsvenc: AVBR is not supported on non-windows OS

2018-02-01 Thread Maxym Dmytrychenko
it actually should fail-down to VBR but we have VBR already exposed.

LGTM , no other objection(s) ?

On Tue, Jan 30, 2018 at 11:07 AM, Zhong Li  wrote:

> AVBR is supported from API 1.3 but only available for Windows
>
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvenc.c | 17 ++---
>  libavcodec/qsvenc.h |  2 ++
>  2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 24d9ec4..16d942f 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -84,7 +84,9 @@ static const struct {
>  { MFX_RATECONTROL_CBR, "CBR" },
>  { MFX_RATECONTROL_VBR, "VBR" },
>  { MFX_RATECONTROL_CQP, "CQP" },
> +#if QSV_HAVE_AVBR
>  { MFX_RATECONTROL_AVBR,"AVBR" },
> +#endif
>  #if QSV_HAVE_LA
>  { MFX_RATECONTROL_LA,  "LA" },
>  #endif
> @@ -163,11 +165,14 @@ static void dump_video_param(AVCodecContext *avctx,
> QSVEncContext *q,
>  } else if (info->RateControlMethod == MFX_RATECONTROL_CQP) {
>  av_log(avctx, AV_LOG_VERBOSE, "QPI: %"PRIu16"; QPP: %"PRIu16";
> QPB: %"PRIu16"\n",
> info->QPI, info->QPP, info->QPB);
> -} else if (info->RateControlMethod == MFX_RATECONTROL_AVBR) {
> +}
> +#if QSV_HAVE_AVBR
> +else if (info->RateControlMethod == MFX_RATECONTROL_AVBR) {
>  av_log(avctx, AV_LOG_VERBOSE,
> "TargetKbps: %"PRIu16"; Accuracy: %"PRIu16"; Convergence:
> %"PRIu16"\n",
> info->TargetKbps, info->Accuracy, info->Convergence);
>  }
> +#endif
>  #if QSV_HAVE_LA
>  else if (info->RateControlMethod == MFX_RATECONTROL_LA
>  #if QSV_HAVE_LA_HRD
> @@ -333,10 +338,14 @@ static int select_rc_mode(AVCodecContext *avctx,
> QSVEncContext *q)
>  else if (avctx->rc_max_rate == avctx->bit_rate) {
>  rc_mode = MFX_RATECONTROL_CBR;
>  rc_desc = "constant bitrate (CBR)";
> -} else if (!avctx->rc_max_rate) {
> +}
> +#if QSV_HAVE_AVBR
> +else if (!avctx->rc_max_rate) {
>  rc_mode = MFX_RATECONTROL_AVBR;
>  rc_desc = "average variable bitrate (AVBR)";
> -} else {
> +}
> +#endif
> +else {
>  rc_mode = MFX_RATECONTROL_VBR;
>  rc_desc = "variable bitrate (VBR)";
>  }
> @@ -522,11 +531,13 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  q->param.mfx.QPB = av_clip(quant * fabs(avctx->b_quant_factor) +
> avctx->b_quant_offset, 0, 51);
>
>  break;
> +#if QSV_HAVE_AVBR
>  case MFX_RATECONTROL_AVBR:
>  q->param.mfx.TargetKbps  = avctx->bit_rate / 1000;
>  q->param.mfx.Convergence = q->avbr_convergence;
>  q->param.mfx.Accuracy= q->avbr_accuracy;
>  break;
> +#endif
>  #if QSV_HAVE_LA
>  case MFX_RATECONTROL_LA:
>  q->param.mfx.TargetKbps  = avctx->bit_rate / 1000;
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index 088a61d..725651e 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -46,10 +46,12 @@
>  #define QSV_HAVE_LA_HRD QSV_VERSION_ATLEAST(1, 11)
>
>  #if defined(_WIN32)
> +#define QSV_HAVE_AVBR   QSV_VERSION_ATLEAST(1, 3)
>  #define QSV_HAVE_ICQQSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_VCMQSV_VERSION_ATLEAST(1, 8)
>  #define QSV_HAVE_QVBR   QSV_VERSION_ATLEAST(1, 11)
>  #else
> +#define QSV_HAVE_AVBR   0
>  #define QSV_HAVE_ICQ0
>  #define QSV_HAVE_VCM0
>  #define QSV_HAVE_QVBR   0
> --
> 1.8.3.1
>
> ___
> 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] 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] qsv: How about replace software parsers with MFXVideoDECODE_DecodeHeader

2018-01-26 Thread Maxym Dmytrychenko
great conclusion and let's have the patches re-viewed.

On Fri, Jan 26, 2018 at 6:56 PM, Luca Barbato  wrote:

> On 26/01/2018 16:15, Li, Zhong wrote:
>
>> Thank you all for the comments! Currently I am inclined to keep
>> current libavcodec parser (i.e; just like wm4's suggested using as
>> much libavcodec parsing functionality as possible). And will fix the
>> decoder conformance issues (e.g: vp8) based on this. Qsv MJPEG
>> decoding should be added later based on mjpeg_parser.
>>
>>
> Thank you a lot :) I'm looking forward to your patches!
>
> 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

Re: [libav-devel] [PATCH] qsvdec: fix vp8 decoding failure issues

2018-01-26 Thread Maxym Dmytrychenko
LGTM as well

On Fri, Jan 26, 2018 at 9:37 AM, Luca Barbato  wrote:

> On 25/01/2018 11:19, Zhong Li wrote:
>
>> many vp8 clips decoding will be failed if hw_frames_ctx is enabled,
>> reporting "Error during QSV decoding.: incompatible video parameters
>> (-14)".
>> It is due to mfx.FrameInfo.Width/Height don't match coded_w/coded_h.
>>
>> Reproduce: -hwaccel qsv -init_hw_device qsv -c:v vp8_qsv -i
>> /fate-suit/vp8-test-vectors-r1/vp80-00-comprehensive-001.ivf
>> -vf "hwdownload,format=nv12" -pix_fmt yuv420p -f md5 -
>>
>> This patch also allows coded_w/h smaller than surface_w/h.
>>
>>
> Sounds ok. The surface may be larger than the coded dimension (that could
> be larger than the presentation dimension).
>
> 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

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

2018-01-26 Thread Maxym Dmytrychenko
+ as sort of default value is 32

I would check why frames_ctx->initial_pool_size or NumFrameSuggested
 cannot be used

log message as a warning is a good idea.




On Fri, Jan 26, 2018 at 9:42 AM, Luca Barbato  wrote:

> On 26/01/2018 02:16, Ruiling Song wrote:
>
>> +ctx->initial_pool_size = 64;
>>
>
> Maybe 64 could be defined with a self descriptive name or you might write
> a comment on why 64 is picked.
>
> The best solution would be adding the ability to query components before
> assembling the transcoding chain and get the minimum number of surfaces
> required before instantiating it, but it might take a little bit of time to
> appear...
>
> 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

Re: [libav-devel] [PATCH V2] lavc/qsv: skip the packet if decoding failure.

2018-01-25 Thread Maxym Dmytrychenko
just fine, thanks

On Thu, Jan 25, 2018 at 8:59 AM, Luca Barbato  wrote:

> On 25/01/2018 02:21, Song, Ruiling wrote:
>
>>
>>
>> -Original Message- From: libav-devel
>>> [mailto:libav-devel-boun...@libav.org] On Behalf Of Luca Barbato Sent:
>>> Wednesday, January 24, 2018 6:36 PM To:
>>> libav-devel@libav.org Subject: Re: [libav-devel] [PATCH V2]
>>> lavc/qsv: skip the packet if decoding failure.
>>>
>>> On 24/01/2018 03:14, Ruiling Song wrote:
>>>
 From: "Ruiling, Song" 

 MediaSDK may fail to decode some frame, just skip it. Otherwise,
 it will keep decoding the failure packet repeatedly without
 processing any packet afterwards.

 Signed-off-by: Ruiling Song  ---
 libavcodec/qsvdec_h2645.c | 6 +- 1 file changed, 5
 insertions(+), 1 deletion(-)

 diff --git a/libavcodec/qsvdec_h2645.c
 b/libavcodec/qsvdec_h2645.c index 83880dc..78a7b61 100644 ---
 a/libavcodec/qsvdec_h2645.c +++ b/libavcodec/qsvdec_h2645.c @@
 -153,8 +153,12 @@ static int qsv_decode_frame(AVCodecContext
 *avctx,

>>> void *data,
>>>
 }

 ret = ff_qsv_process_data(avctx, >qsv, frame, got_frame, 
 buffer_pkt); -if (ret < 0) +if (ret < 0){ +
 /* Drop buffer_pkt when failed to decode the packet. Otherwise, +
 the decoder will keep decoding the failure packet. */ +
 av_packet_unref(>buffer_pkt); return ret; +}

 s->buffer_pkt.size -= ret; s->buffer_pkt.data += ret;


>>> Looks better, do you have a specific test sample?
>>>
>> Sorry I don't have the original clip to hit the issue. But I tried to
>> decode fate-suite/h264/attachment631-small.mp4 (The video stream has
>> some broken frames) QSV keeps trying to decode one broken frame. With
>> this patch, qsv could move on to process all the frames. Even with
>> this patch, MediaSDK still fails to decode out any frame in that
>> stream, which I think the issue comes from MediaSDK itself.
>>
>
> Ok, I'd merge this if nobody is against then.
>
> 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

Re: [libav-devel] qsv: How about replace software parsers with MFXVideoDECODE_DecodeHeader

2018-01-22 Thread Maxym Dmytrychenko
Mark, libmfx supported D3D11 array textures too - approved for
implementation and should be there soon

On Mon, Jan 22, 2018 at 2:19 PM, Mark Thompson  wrote:

> On 22/01/18 11:20, Li, Zhong wrote:
> >   MSDK provides an API (MFXVideoDECODE_DecodeHeader) to parse video
> parameters. Currently it hasn't been used.
> > Instead, software parsers are used. It works well for h264 decoder, and
> basically works well for hevc decoder (some issues found by Mayxm due to
> width/height are unaligned, I also found some hevc clips without setting
> profile can be decoded by software but qsv failed) .
> > More issues found on other decoders such as VP8. The decoding
> conformance pass rate is low and looks like it is due to some
> missing/incompatible header information is passed to qsv decoder (though
> Mark provides a patch 182cf17 but still something is missing).
> >   Similar issues happens on MJPEG decoding which I am going to add.
>
> Have you looked into what is missing for VP8?  There shouldn't be much
> magic there, so I doubt that particular case is difficult to fix.
>
> I imagine MJPEG will be nastier, though, because there is a lot more
> variation in layout.
>
> >   Maybe we can continue to work on software parsers for qsv, but I
> believe replace software parser with MFXVideoDECODE_DecodeHeader is a
> better choice:
> >
> > 1.  It can remove the dependence on various software parsers, and
> just need a unified interface for all codes.
> >
> > 2.  It will be very easy to add new decoder such as MJPEG decoding
> support without any software parser patches.
> >
> > 3.  MFXVideoDECODE_DecodeHeader is used by MSDK sample decoder (i.e:
> sample_decode), so it is reliable for MSDK decoder. (As my test, it can
> effectively improve decoding conformance pass rate, especially for vp8
> decoding.)
> >
> > 4.  CUVID decoder is using CUVID parser instead of software parser,
> maybe qsv can align with it.
>
> The CUVID decoder only exists in ffmpeg and is considered deprecated in
> favour of the hwaccel (which is the only thing in libav).
>
> >Negative effect:
> >
> > 1.  May cause some regression since it will take effect to all
> codecs.
> >
> > 2.  Others?
>
> I believe a problem with this method is that you don't have any libmfx
> session at the point where you do the initial parsing (since you only get
> it after the get_format() callback, which needs information from that
> parsing).  How would you intend to get the session to use for this purpose?
>
> - Mark
>
>
> PS:  Feel free to ignore anything I say about qsvdec - I regard qsvdec as
> deprecated, because nowadays I find that using the platform API hwaccels
> (DXVA2/VAAPI) and mapping back if necessary is just more flexible and
> better supported.  (Though it would be nice if libmfx encode supported
> D3D11 array textures too...)
> ___
> 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] qsv: How about replace software parsers with MFXVideoDECODE_DecodeHeader

2018-01-22 Thread Maxym Dmytrychenko
IMHO - good reason(s)
plus : it will be more consistent approach to rely on QSV's
API/DecodeHeader functionality.
would not expect many regression(s), so patches would be good to have for
review.

On Mon, Jan 22, 2018 at 12:20 PM, Li, Zhong  wrote:

>   MSDK provides an API (MFXVideoDECODE_DecodeHeader) to parse video
> parameters. Currently it hasn't been used.
> Instead, software parsers are used. It works well for h264 decoder, and
> basically works well for hevc decoder (some issues found by Mayxm due to
> width/height are unaligned, I also found some hevc clips without setting
> profile can be decoded by software but qsv failed) .
> More issues found on other decoders such as VP8. The decoding conformance
> pass rate is low and looks like it is due to some missing/incompatible
> header information is passed to qsv decoder (though Mark provides a patch
> 182cf17 but still something is missing).
>   Similar issues happens on MJPEG decoding which I am going to add.
>   Maybe we can continue to work on software parsers for qsv, but I believe
> replace software parser with MFXVideoDECODE_DecodeHeader is a better choice:
>
> 1.  It can remove the dependence on various software parsers, and just
> need a unified interface for all codes.
>
> 2.  It will be very easy to add new decoder such as MJPEG decoding
> support without any software parser patches.
>
> 3.  MFXVideoDECODE_DecodeHeader is used by MSDK sample decoder (i.e:
> sample_decode), so it is reliable for MSDK decoder. (As my test, it can
> effectively improve decoding conformance pass rate, especially for vp8
> decoding.)
>
> 4.  CUVID decoder is using CUVID parser instead of software parser,
> maybe qsv can align with it.
>
>Negative effect:
>
> 1.  May cause some regression since it will take effect to all codecs.
>
> 2.  Others?
>
>   Appreciated for any comment. If we are agree with that, patches will be
> sent soon (about following next two weeks).
> Thanks
> Zhong
>
> ___
> 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] lavc/qsv: skip the packet if decoding failure.

2018-01-22 Thread Maxym Dmytrychenko
would be av_packet_unref() more appropriate ?

On Mon, Jan 22, 2018 at 9:53 AM, Ruiling, Song 
wrote:

> MediaSDK may fail to decode some frame, just skip it.
> Otherwise, it will keep decoding the failure packet repeatedly
> without processing any packet afterwards.
>
> Signed-off-by: Ruiling, Song 
> ---
>  libavcodec/qsvdec_h2645.c | 8 ++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/qsvdec_h2645.c b/libavcodec/qsvdec_h2645.c
> index 83880dc..aa8746d 100644
> --- a/libavcodec/qsvdec_h2645.c
> +++ b/libavcodec/qsvdec_h2645.c
> @@ -153,8 +153,12 @@ static int qsv_decode_frame(AVCodecContext *avctx,
> void *data,
>  }
>
>  ret = ff_qsv_process_data(avctx, >qsv, frame, got_frame,
> >buffer_pkt);
> -if (ret < 0)
> -return ret;
> +if (ret < 0){
> + /* force the buffer_pkt's size to 0 when failed to decode
> the packet,
> +otherwise, the decoder will keep decoding the failure
> packet. */
> + s->buffer_pkt.size = 0;
> + return ret;
> +}
>
>  s->buffer_pkt.size -= ret;
>  s->buffer_pkt.data += ret;
> --
> 2.7.4
>
> ___
> 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] qsv: better to use alignment by 16 and HEVC 10b requires alignment by 32

2018-01-08 Thread Maxym Dmytrychenko
---
 libavcodec/qsvdec.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c74ec6836..9741f3310 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -475,6 +475,7 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 uint8_t *dummy_data;
 int dummy_size;
 int ret;
+const AVPixFmtDescriptor *desc;
 
 if (!q->avctx_internal) {
 q->avctx_internal = avcodec_alloc_context3(NULL);
@@ -511,8 +512,8 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 
 /* TODO: flush delayed frames on reinit */
 if (q->parser->format   != q->orig_pix_fmt||
-q->parser->coded_width  != avctx->coded_width ||
-q->parser->coded_height != avctx->coded_height) {
+FFALIGN(q->parser->coded_width, 16)  != FFALIGN(avctx->coded_width, 
16) ||
+FFALIGN(q->parser->coded_height, 16) != FFALIGN(avctx->coded_height, 
16)) {
 enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
AV_PIX_FMT_NONE,
AV_PIX_FMT_NONE };
@@ -531,8 +532,8 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 avctx->pix_fmt  = pix_fmts[1] = qsv_format;
 avctx->width= q->parser->width;
 avctx->height   = q->parser->height;
-avctx->coded_width  = q->parser->coded_width;
-avctx->coded_height = q->parser->coded_height;
+avctx->coded_width  = FFALIGN(q->parser->coded_width, 16);
+avctx->coded_height = FFALIGN(q->parser->coded_height, 16);
 avctx->field_order  = q->parser->field_order;
 avctx->level= q->avctx_internal->level;
 avctx->profile  = q->avctx_internal->profile;
@@ -543,6 +544,15 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 
 avctx->pix_fmt = ret;
 
+desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+if (!desc)
+goto reinit_fail;
+
+ if (desc->comp[0].depth > 8) {
+avctx->coded_width =  FFALIGN(q->parser->coded_width, 32);
+avctx->coded_height = FFALIGN(q->parser->coded_height, 32);
+}
+
 ret = qsv_decode_init(avctx, q);
 if (ret < 0)
 goto reinit_fail;
-- 
2.14.3 (Apple Git-98)

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

[libav-devel] [PATCH] qsv: HW HEVC10b decode requires 32 bytes alignment

2018-01-08 Thread Maxym Dmytrychenko
---
 libavcodec/qsvdec.c | 18 ++
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c
index c74ec6836..9741f3310 100644
--- a/libavcodec/qsvdec.c
+++ b/libavcodec/qsvdec.c
@@ -475,6 +475,7 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 uint8_t *dummy_data;
 int dummy_size;
 int ret;
+const AVPixFmtDescriptor *desc;
 
 if (!q->avctx_internal) {
 q->avctx_internal = avcodec_alloc_context3(NULL);
@@ -511,8 +512,8 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 
 /* TODO: flush delayed frames on reinit */
 if (q->parser->format   != q->orig_pix_fmt||
-q->parser->coded_width  != avctx->coded_width ||
-q->parser->coded_height != avctx->coded_height) {
+FFALIGN(q->parser->coded_width, 16)  != FFALIGN(avctx->coded_width, 
16) ||
+FFALIGN(q->parser->coded_height, 16) != FFALIGN(avctx->coded_height, 
16)) {
 enum AVPixelFormat pix_fmts[3] = { AV_PIX_FMT_QSV,
AV_PIX_FMT_NONE,
AV_PIX_FMT_NONE };
@@ -531,8 +532,8 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 avctx->pix_fmt  = pix_fmts[1] = qsv_format;
 avctx->width= q->parser->width;
 avctx->height   = q->parser->height;
-avctx->coded_width  = q->parser->coded_width;
-avctx->coded_height = q->parser->coded_height;
+avctx->coded_width  = FFALIGN(q->parser->coded_width, 16);
+avctx->coded_height = FFALIGN(q->parser->coded_height, 16);
 avctx->field_order  = q->parser->field_order;
 avctx->level= q->avctx_internal->level;
 avctx->profile  = q->avctx_internal->profile;
@@ -543,6 +544,15 @@ int ff_qsv_process_data(AVCodecContext *avctx, QSVContext 
*q,
 
 avctx->pix_fmt = ret;
 
+desc = av_pix_fmt_desc_get(avctx->pix_fmt);
+if (!desc)
+goto reinit_fail;
+
+ if (desc->comp[0].depth > 8) {
+avctx->coded_width =  FFALIGN(q->parser->coded_width, 32);
+avctx->coded_height = FFALIGN(q->parser->coded_height, 32);
+}
+
 ret = qsv_decode_init(avctx, q);
 if (ret < 0)
 goto reinit_fail;
-- 
2.14.3 (Apple Git-98)

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

Re: [libav-devel] [PATCH 1/2] lavu/qsv: add log message for libmfx version

2017-12-28 Thread Maxym Dmytrychenko
Just fine as well 

> 28 дек. 2017 г., в 11:59, Luca Barbato  написал(а):
> 
>> On 28/12/2017 10:38, Zhong Li wrote:
>> It is benefit to diagnose issues related to different libmfx version.
>> Signed-off-by: Zhong Li 
>> ---
>>  libavutil/hwcontext_qsv.c | 4 
>>  1 file changed, 4 insertions(+)
> 
> Both patches look fine to me. I'll push them tomorrow if nobody is against it.
> 
> 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

Re: [libav-devel] [PATCH] qsv: Support explicit lookahead downscaling

2017-12-12 Thread Maxym Dmytrychenko
comment:  :)
patch:OK

On Tue, Dec 12, 2017 at 4:04 PM, Diego Biurrun  wrote:

> On Tue, Dec 12, 2017 at 02:27:56PM +, Luca Barbato wrote:
> > ---
> >  libavcodec/qsvenc.c |  4 
> >  libavcodec/qsvenc.h | 13 +
> >  2 files changed, 17 insertions(+)
> >
> > --- a/libavcodec/qsvenc.h
> > +++ b/libavcodec/qsvenc.h
> > @@ -64,6 +71,11 @@
> >  { "unset", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 9 }, INT_MIN, INT_MAX,
>  VE, "la_depth" },  \
> > +{ "la_ds", "Downscaling factor for the frames saved for the lookahead
> analisys", OFFSET(qsv.la_ds), AV_OPT_TYPE_INT, { .i64 = -1 },   -1,
> MFX_LOOKAHEAD_DS_4x, VE, "la_ds" }, \
>
> anal_Y_s_I_s
>
> probably OK
>
> Diego
> ___
> 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 1/6] qsvenc_hevc: Replace ad-hoc VPS writing with CBS implementation

2017-12-11 Thread Maxym Dmytrychenko
if tested - LGTM

On Mon, Dec 11, 2017 at 1:44 AM, Mark Thompson  wrote:

> This copies more information which should be present from the SPS.
> It also fixes the value of vps_temporal_id_nesting_flag, which was
> previously incorrect for a single-layer stream (the standard states
> that it must be 1, and the reference decoder barfs if it isn't).
> ---
>  configure|   2 +-
>  libavcodec/Makefile  |   3 +-
>  libavcodec/qsvenc_hevc.c | 190 +++---
> -
>  3 files changed, 111 insertions(+), 84 deletions(-)
>
> diff --git a/configure b/configure
> index 7f320fee1..3aa61abb8 100755
> --- a/configure
> +++ b/configure
> @@ -2267,7 +2267,7 @@ h264_vaapi_encoder_deps="
> VAEncPictureParameterBufferH264"
>  h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
>  hevc_nvenc_encoder_deps="nvenc"
>  hevc_qsv_decoder_select="hevc_mp4toannexb_bsf hevc_parser
> hevc_qsv_hwaccel qsvdec"
> -hevc_qsv_encoder_select="hevcparse qsvenc"
> +hevc_qsv_encoder_select="cbs_h265 qsvenc"
>  hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
>  hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
>  mjpeg_qsv_encoder_deps="libmfx"
> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
> index d04902be0..9a1a6fec6 100644
> --- a/libavcodec/Makefile
> +++ b/libavcodec/Makefile
> @@ -284,8 +284,7 @@ OBJS-$(CONFIG_HEVC_DECODER)+= hevcdec.o
> hevc_mvs.o hevc_sei.o \
>hevcdsp.o hevc_filter.o
> hevc_data.o
>  OBJS-$(CONFIG_HEVC_NVENC_ENCODER)  += nvenc_hevc.o
>  OBJS-$(CONFIG_HEVC_QSV_DECODER)+= qsvdec_h2645.o
> -OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o hevc_ps_enc.o
>\
> -  hevc_data.o
> +OBJS-$(CONFIG_HEVC_QSV_ENCODER)+= qsvenc_hevc.o
>  OBJS-$(CONFIG_HEVC_VAAPI_ENCODER)  += vaapi_encode_h265.o
>  OBJS-$(CONFIG_HNM4_VIDEO_DECODER)  += hnm4video.o
>  OBJS-$(CONFIG_HQ_HQA_DECODER)  += hq_hqa.o hq_hqadata.o
> hq_hqadsp.o \
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index dbb55e2f1..92066dcb7 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -28,11 +28,11 @@
>  #include "libavutil/opt.h"
>
>  #include "avcodec.h"
> -#include "bytestream.h"
> +#include "cbs.h"
> +#include "cbs_h265.h"
>  #include "get_bits.h"
>  #include "hevc.h"
>  #include "hevcdec.h"
> -#include "h2645_parse.h"
>  #include "internal.h"
>  #include "qsv.h"
>  #include "qsv_internal.h"
> @@ -52,107 +52,135 @@ typedef struct QSVHEVCEncContext {
>
>  static int generate_fake_vps(QSVEncContext *q, AVCodecContext *avctx)
>  {
> -GetByteContext gbc;
> -PutByteContext pbc;
> -
> -GetBitContext gb;
> -H2645NAL sps_nal = { NULL };
> -HEVCSPS sps = { 0 };
> -HEVCVPS vps = { 0 };
> -uint8_t vps_buf[128], vps_rbsp_buf[128];
> -uint8_t *new_extradata;
> -unsigned int sps_id;
> -int ret, i, type, vps_size;
> +CodedBitstreamContext cbc;
> +CodedBitstreamFragment ps;
> +const H265RawSPS *sps;
> +H265RawVPS vps;
> +uint8_t *data = NULL;
> +size_t data_size;
> +int err, sps_pos, i;
>
>  if (!avctx->extradata_size) {
> -av_log(avctx, AV_LOG_ERROR, "No extradata returned from
> libmfx\n");
> +av_log(avctx, AV_LOG_ERROR,
> +   "No parameter sets returned by libmfx.\n");
>  return AVERROR_UNKNOWN;
>  }
>
> -/* parse the SPS */
> -ret = ff_h2645_extract_rbsp(avctx->extradata + 4,
> avctx->extradata_size - 4, _nal);
> -if (ret < 0) {
> -av_log(avctx, AV_LOG_ERROR, "Error unescaping the SPS buffer\n");
> -return ret;
> -}
> +err = ff_cbs_init(, AV_CODEC_ID_HEVC, avctx);
> +if (err < 0)
> +return err;
>
> -ret = init_get_bits8(, sps_nal.data, sps_nal.size);
> -if (ret < 0) {
> -av_freep(_nal.rbsp_buffer);
> -return ret;
> +err = ff_cbs_read(, , avctx->extradata, avctx->extradata_size);
> +if (err < 0) {
> +av_log(avctx, AV_LOG_ERROR,
> +   "Error reading parameter sets returned by libmfx.\n");
> +ff_cbs_close();
> +return err;
>  }
>
> -get_bits(, 1);
> -type = get_bits(, 6);
> -if (type != HEVC_NAL_SPS) {
> -av_log(avctx, AV_LOG_ERROR, "Unexpected NAL type in the
> extradata: %d\n",
> -   type);
> -av_freep(_nal.rbsp_buffer);
> -return AVERROR_INVALIDDATA;
> +sps = NULL;
> +for (sps_pos = 0; sps_pos < ps.nb_units; sps_pos++) {
> +if (ps.units[sps_pos].type == HEVC_NAL_SPS) {
> +sps = ps.units[sps_pos].content;
> +break;
> +}
>  }
> -get_bits(, 9);
> -
> -ret = ff_hevc_parse_sps(, , _id, 0, NULL, avctx);
> -av_freep(_nal.rbsp_buffer);
> -if (ret < 0) {
> -av_log(avctx, AV_LOG_ERROR, "Error parsing the SPS\n");
> -return ret;
> +if (!sps) {
> +

Re: [libav-devel] [PATCH V2] lavc/qsvenc: set HRD buffer size

2017-12-04 Thread Maxym Dmytrychenko
will check it shortly

On Fri, Dec 1, 2017 at 9:48 AM, Zhong Li  wrote:

> Hypothetical Reference Decoding (HRD) model assumes that data flows
> into a buffer of the fixed size BufferSizeInKB with a constant bitrate.
> Smaller BufferSizeInKB means smaller frame size variations,
> but more difficult to maintain HRD.
>
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvenc.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index 57f78c4..96c8fb5 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -495,6 +495,7 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  #if QSV_HAVE_VCM
>  case MFX_RATECONTROL_VCM:
>  #endif
> +q->param.mfx.BufferSizeInKB   = avctx->rc_buffer_size / 8000;
>  q->param.mfx.InitialDelayInKB = avctx->rc_initial_buffer_occupancy
> / 1000;
>  q->param.mfx.TargetKbps   = avctx->bit_rate / 1000;
>  q->param.mfx.MaxKbps  = avctx->rc_max_rate / 1000;
> --
> 1.8.3.1
>
> ___
> 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] lavc/qsvenc: set HRD buffer size

2017-11-29 Thread Maxym Dmytrychenko
good point about CBR... and this would require to get BufferSizeInKB
adjusted at the proper place, with InitialDelayInKB

On Tue, Nov 28, 2017 at 11:41 PM, Mark Thompson  wrote:

> On 01/12/17 20:04, Zhong Li wrote:
> > Hypothetical Reference Decoding (HRD) model assumes that data flows into
> a
> > buffer of the fixed size BufferSizeInKB with a constant bitrate.
> > BufferSizeInKB represents the maximum possible size of any compressed
> frames.
> >
> > Signed-off-by: Zhong Li 
> > ---
> >  libavcodec/qsvenc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> > index 9db9eb3..cdddfd9 100644
> > --- a/libavcodec/qsvenc.c
> > +++ b/libavcodec/qsvenc.c
> > @@ -437,7 +437,7 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
> >  q->param.mfx.NumSlice   = avctx->slices;
> >  q->param.mfx.NumRefFrame= FFMAX(0, avctx->refs);
> >  q->param.mfx.EncodedOrder   = 0;
> > -q->param.mfx.BufferSizeInKB = 0;
> > +q->param.mfx.BufferSizeInKB = (avctx->rc_buffer_size > 0) ?
> avctx->rc_buffer_size / 8000 : 0;
> >
> >  desc = av_pix_fmt_desc_get(sw_format);
> >  if (!desc)
> >
>
> The Intel documentation says "BufferSizeInKB represents the maximum
> possible size of any compressed frames.".  Is that just confused?  Some of
> the surrounding text does suggest that it's the right thing.
>
> Probably fine, but are you sure it should be set when in
> non-bitrate-targetted modes?  (The related HRD parameter InitialDelayInKB
> is set further down in CBR/VBR modes only.)
>
> - Mark
>
>
> Aside:  Please try to avoid sending messages from the future, it's
> confusing when things are sorted by time.  (You probably have the clock set
> wrong on a machine used for git send-email.)
> ___
> 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 v2 2/2] qsv/h264enc: fix cavlc option setting useless issue

2017-11-24 Thread Maxym Dmytrychenko
this looks clear and touches only relevant implementation, will take care
shortly.

On Mon, Nov 27, 2017 at 5:19 PM, Zhong Li  wrote:

> No matter cavlc option is set to 0 or 1, the output bitstream is always
> cabac mode.
> Reproduce: -y -s widthxheight -i widthxheight.yuv -vcodec h264_qsv
> -b:v 2000k -maxrate 2000k -cavlc 1 test.h264
> Then check the entropy_coding_mode_flag of the encoded bitstream.
> It is due to the dulicate option "coder" (which should be deprecated) is
> set to cabac
>
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvenc.c  | 2 +-
>  libavcodec/qsvenc_h264.c | 4 +++-
>  2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c
> index eeccc50..9db9eb3 100644
> --- a/libavcodec/qsvenc.c
> +++ b/libavcodec/qsvenc.c
> @@ -547,7 +547,7 @@ static int init_video_param(AVCodecContext *avctx,
> QSVEncContext *q)
>  if (avctx->codec_id == AV_CODEC_ID_H264) {
>  #if FF_API_CODER_TYPE
>  FF_DISABLE_DEPRECATION_WARNINGS
> -if (avctx->coder_type != 0)
> +if (avctx->coder_type >= 0)
>  q->cavlc = avctx->coder_type == FF_CODER_TYPE_VLC;
>  FF_ENABLE_DEPRECATION_WARNINGS
>  #endif
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index 62f1909..1365fac 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -107,7 +107,9 @@ static const AVCodecDefault qsv_enc_defaults[] = {
>  // same as the x264 default
>  { "g", "250"   },
>  { "bf","3" },
> -{ "coder", "ac"},
> +#if FF_API_CODER_TYPE
> +{ "coder", "-1"},
> +#endif
>
>  { "flags", "+cgop" },
>  #if FF_API_PRIVATE_OPT
> --
> 1.8.3.1
>
> ___
> 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 1/2] qsvenc: move cavlc out of common option

2017-11-21 Thread Maxym Dmytrychenko
Patch is just fine, nothing else required.
Busy days and should be finished these days

> 22 нояб. 2017 г., в 2:56, Li, Zhong <zhong...@intel.com> написал(а):
> 
> Ping? Any dependency to apply this patch?
> I'm glad to update this patch if necessary.
> 
>> -Original Message-
>> From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
>> Diego Biurrun
>> Sent: Tuesday, November 14, 2017 1:40 AM
>> To: libav development <libav-devel@libav.org>
>> Subject: Re: [libav-devel] [PATCH 1/2] qsvenc: move cavlc out of common
>> option
>> 
>>> On Mon, Nov 13, 2017 at 02:03:47PM +0100, Maxym Dmytrychenko wrote:
>>>> On Mon, Nov 13, 2017 at 8:54 AM, Zhong Li <zhong...@intel.com> wrote:
>>>> 
>>>> CAVLC option is only available for h264 encoding.
>>>> CABAC is the only entropy coding way for hevc.
>>>> 
>>>> Signed-off-by: Zhong Li <zhong...@intel.com>
>>>> ---
>>>> libavcodec/qsvenc.h  | 3 +--
>>>> libavcodec/qsvenc_h264.c | 1 +
>>>> 2 files changed, 2 insertions(+), 2 deletions(-)
>>> 
>>> correct fix
>> 
>> Will queue with an updated log message.
>> 
>> Diego
>> ___
>> 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 mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 1/2] qsvenc: move cavlc out of common option

2017-11-15 Thread Maxym Dmytrychenko
I would leave it as it is now

On Wed, Nov 15, 2017 at 4:09 PM, Li, Zhong <zhong...@intel.com> wrote:

> > From: libav-devel [mailto:libav-devel-boun...@libav.org] On Behalf Of
> > Maxym Dmytrychenko
> > Sent: Monday, November 13, 2017 9:04 PM
> > To: libav development <libav-devel@libav.org>
> > Subject: Re: [libav-devel] [PATCH 1/2] qsvenc: move cavlc out of common
> > option
> >
> > correct fix
>
> I have an idea to rename the "calvc" option to be "coder", which can be
> aligned with x264. But I am not sure it will have any compatibility issues
> or not for old version.
> Any comment?
> ___
> 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 1/2] qsvenc: move cavlc out of common option

2017-11-13 Thread Maxym Dmytrychenko
correct fix

On Mon, Nov 13, 2017 at 8:54 AM, Zhong Li  wrote:

> CAVLC option is only available for h264 encoding.
> CABAC is the only entropy coding way for hevc.
>
> Signed-off-by: Zhong Li 
> ---
>  libavcodec/qsvenc.h  | 3 +--
>  libavcodec/qsvenc_h264.c | 1 +
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/qsvenc.h b/libavcodec/qsvenc.h
> index a639904..9b0b84b 100644
> --- a/libavcodec/qsvenc.h
> +++ b/libavcodec/qsvenc.h
> @@ -66,8 +66,7 @@
>  { "extbrc", "Extended bitrate control",
>  OFFSET(qsv.extbrc), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,
> 1, VE }, \
>  { "adaptive_i", "Adaptive I-frame placement",
>  OFFSET(qsv.adaptive_i), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,
> 1, VE }, \
>  { "adaptive_b", "Adaptive B-frame placement",
>  OFFSET(qsv.adaptive_b), AV_OPT_TYPE_INT, { .i64 = -1 }, -1,
> 1, VE }, \
> -{ "b_strategy", "Strategy to choose between I/P/B-frames",
> OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1,
> VE }, \
> -{ "cavlc",  "Enable CAVLC",
>  OFFSET(qsv.cavlc),  AV_OPT_TYPE_INT, { .i64 = 0 },   0,
> 1, VE }, \
> +{ "b_strategy", "Strategy to choose between I/P/B-frames",
> OFFSET(qsv.b_strategy),AV_OPT_TYPE_INT, { .i64 = -1 }, -1,  1,
> VE },
>
>  typedef struct QSVEncContext {
>  AVCodecContext *avctx;
> diff --git a/libavcodec/qsvenc_h264.c b/libavcodec/qsvenc_h264.c
> index a968dcf..62f1909 100644
> --- a/libavcodec/qsvenc_h264.c
> +++ b/libavcodec/qsvenc_h264.c
> @@ -67,6 +67,7 @@ static av_cold int qsv_enc_close(AVCodecContext *avctx)
>  static const AVOption options[] = {
>  QSV_COMMON_OPTS
>
> +{ "cavlc",  "Enable CAVLC",
>  OFFSET(qsv.cavlc),  AV_OPT_TYPE_INT, { .i64 = 0 },   0,
> 1, VE },
>  { "idr_interval", "Distance (in I-frames) between IDR frames",
> OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
>  { "single_sei_nal_unit","Put all the SEI messages into one
> NALU",OFFSET(qsv.single_sei_nal_unit), AV_OPT_TYPE_INT, {
> .i64 = -1 }, -1,  1, VE },
>  { "max_dec_frame_buffering", "Maximum number of frames buffered in
> the DPB", OFFSET(qsv.max_dec_frame_buffering), AV_OPT_TYPE_INT, { .i64 =
> 0 },   0, UINT16_MAX, VE },
> --
> 1.8.3.1
>
> ___
> 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] qsv/hevcdec: Load hw plugin by default on non-windows os

2017-11-10 Thread Maxym Dmytrychenko
agree, will commit it shortly

On Fri, Nov 10, 2017 at 7:43 PM, Luca Barbato  wrote:

> On 10/11/2017 09:03, Zhong Li wrote:
>
>> Software plugin is not available on Linux, Only works on Windows.
>> Similar changes have been applied to qsv hevc encoder by
>> b05128f3c953bd66483e697d60a2e7e45ee9cfa0.
>>
>> Signed-off-by: Zhong Li 
>> ---
>>   libavcodec/qsvdec_h2645.c | 8 +++-
>>   1 file changed, 7 insertions(+), 1 deletion(-)
>>
>>
> Sounds good :)
>
> 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

Re: [libav-devel] [PATCH] qsv: Make the hevc idr_interval consistent with the h264 one

2017-10-18 Thread Maxym Dmytrychenko
technical aspect(s) should be ok

thanks, Luca

On Wed, Oct 18, 2017 at 3:29 AM, Diego Biurrun  wrote:

> On Tue, Oct 17, 2017 at 11:49:57AM +, Luca Barbato wrote:
> > According to the MediaSDK documentation the idr_interval value has
> > a different meaning depending on the codec:
> >
> > 0 in H264 means make every I-frame IDR, in HEVC means to have
> > it only at the beginning.
>
> it means
>
> > 1 in H264 means every other I-frame is not-IDR, in HEVC means
> > that every I-frame is IDR.
>
> it means
>
> > Increase by 1 idr_interval for hevc and support -1 with a constant
> > name to provide a mean to have the only-at-beginning behaviour if
> > really need.
> >
> > Keep the default consistent between the two encoders.
>
> Keep the default consistent between the two encoders. Make 1 the default
> for HEVC and provide a shorthand option to set idr_interval to 0 for HEVC.
>
> > --- a/libavcodec/qsvenc_hevc.c
> > +++ b/libavcodec/qsvenc_hevc.c
> > @@ -220,7 +223,8 @@ static av_cold int qsv_enc_close(AVCodecContext
> *avctx)
> >
> > -{ "idr_interval", "Distance (in I-frames) between IDR frames",
> OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
> > +{ "idr_interval", "Distance (in I-frames) between IDR frames",
> OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT_MAX, VE,
> "idr_interval" },
> > +{ "begin_only", "Output an IDR-frame only at the begin of the
> stream", 0, AV_OPT_TYPE_CONST, { .i64 = -1 }, 0, 0, VE, "idr_interval" },
>
> only at the beginning of the stream
>
> Diego
> ___
> 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] qsv: Expose idr_interval for hevc as well

2017-10-14 Thread Maxym Dmytrychenko
LGTM and helps to have the proper control.

thanks, Luca !

On Sat, Oct 14, 2017 at 1:22 AM, Luca Barbato  wrote:

> ---
>  libavcodec/qsvenc_hevc.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> index efed4d98f4..fb65d58c32 100644
> --- a/libavcodec/qsvenc_hevc.c
> +++ b/libavcodec/qsvenc_hevc.c
> @@ -220,6 +220,7 @@ static av_cold int qsv_enc_close(AVCodecContext *avctx)
>  static const AVOption options[] = {
>  QSV_COMMON_OPTS
>
> +{ "idr_interval", "Distance (in I-frames) between IDR frames",
> OFFSET(qsv.idr_interval), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE },
>  { "load_plugin", "A user plugin to load in an internal session",
> OFFSET(load_plugin), AV_OPT_TYPE_INT, { .i64 = LOAD_PLUGIN_DEFAULT },
> LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_HW, VE, "load_plugin" },
>  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE
> },0, 0, VE, "load_plugin" },
>  { "hevc_sw",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> LOAD_PLUGIN_HEVC_SW }, 0, 0, VE, "load_plugin" },
> --
> 2.11.1
>
> ___
> 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 2/2 V3] libavfilter/vf_vpp: Add common filters of the qsv vpp

2017-09-11 Thread Maxym Dmytrychenko
seems to be fine,
if no other objections will commit shortly

On Wed, Aug 30, 2017 at 3:41 PM, Luca Barbato  wrote:

> On 24/08/2017 04:16, Huang, Zhengxu wrote:
>
>> ---
>> Changes from v2:
>> * Modify the configure file and fix some resources release issues as per
>> Anton's review .
>> * Modify the comments style.
>>---
>> ---
>> Changes from v1:
>> * Add the "deps/select" related to the vpp_qsv in the configure file as
>> per Maxym's review .
>>---
>>
>>
>> ___
>> libav-devel mailing list
>> libav-devel@libav.org
>> https://lists.libav.org/mailman/listinfo/libav-devel
>>
>>
> Maxym, is it fine for you?
>
> 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

Re: [libav-devel] [PATCH] qsv: Load the hw hevc plugin by default on Linux

2017-09-11 Thread Maxym Dmytrychenko
should be so, Luca

On Fri, Sep 8, 2017 at 6:26 AM, Luca Barbato  wrote:

> On 07/09/2017 22:14, Mark Thompson wrote:
>
>> In principle I'm very much in favour, except last time I looked at
>> this there
>> was> ber/080499.html>
>> (and earlier thread).
>>
>> Are you able to test it on Broadwell?  (Or with an older Media SDK
>> version?  Do we care about that?)
>>
>
> On Linux there is only the hw plugin and it gracefully fails (or so I
> remember, Maxym do you confirm? I do not have a pre-broadwell handy due hd
> failure...).
>
> On windows nothing changes since I have that thread in mind :)
>
> 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

Re: [libav-devel] [PATCH] qsv: Load the hw hevc plugin by default on Linux

2017-09-07 Thread Maxym Dmytrychenko
old Media SDK might be considered as outdated, it would be good to support
the latest one, at first.

On Thu, Sep 7, 2017 at 10:14 PM, Mark Thompson  wrote:

> On 06/09/17 14:07, Luca Barbato wrote:
> > Only on Windows the software plugin is available.
> > ---
> >
> >  libavcodec/qsvenc_hevc.c | 8 +++-
> >  1 file changed, 7 insertions(+), 1 deletion(-)
> >
> > diff --git a/libavcodec/qsvenc_hevc.c b/libavcodec/qsvenc_hevc.c
> > index 27ff0c6feb..efed4d98f4 100644
> > --- a/libavcodec/qsvenc_hevc.c
> > +++ b/libavcodec/qsvenc_hevc.c
> > @@ -209,12 +209,18 @@ static av_cold int qsv_enc_close(AVCodecContext
> *avctx)
> >  return ff_qsv_enc_close(avctx, >qsv);
> >  }
> >
> > +#if defined(_WIN32)
> > +#define LOAD_PLUGIN_DEFAULT LOAD_PLUGIN_HEVC_SW
> > +#else
> > +#define LOAD_PLUGIN_DEFAULT LOAD_PLUGIN_HEVC_HW
> > +#endif
> > +
> >  #define OFFSET(x) offsetof(QSVHEVCEncContext, x)
> >  #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> >  static const AVOption options[] = {
> >  QSV_COMMON_OPTS
> >
> > -{ "load_plugin", "A user plugin to load in an internal session",
> OFFSET(load_plugin), AV_OPT_TYPE_INT, { .i64 = LOAD_PLUGIN_HEVC_SW },
> LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_HW, VE, "load_plugin" },
> > +{ "load_plugin", "A user plugin to load in an internal session",
> OFFSET(load_plugin), AV_OPT_TYPE_INT, { .i64 = LOAD_PLUGIN_DEFAULT },
> LOAD_PLUGIN_NONE, LOAD_PLUGIN_HEVC_HW, VE, "load_plugin" },
> >  { "none", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LOAD_PLUGIN_NONE
> },0, 0, VE, "load_plugin" },
> >  { "hevc_sw",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> LOAD_PLUGIN_HEVC_SW }, 0, 0, VE, "load_plugin" },
> >  { "hevc_hw",  NULL, 0, AV_OPT_TYPE_CONST, { .i64 =
> LOAD_PLUGIN_HEVC_HW }, 0, 0, VE, "load_plugin" },
> > --
> > 2.11.1
>
> In principle I'm very much in favour, except last time I looked at this
> there was  November/080499.html> (and earlier thread).
>
> Are you able to test it on Broadwell?  (Or with an older Media SDK
> version?  Do we care about that?)
>
> - Mark
> ___
> 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 08/14] vf_scale_qsv: Support modifying hardware frame pool sizes

2017-09-06 Thread Maxym Dmytrychenko
should be ok,
can try it next week, if you didnt.

On Wed, Sep 6, 2017 at 12:59 AM, Mark Thompson  wrote:

> 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 mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH 2/2] libavfilter/vf_vpp: Add common filters of the qsv vpp

2017-08-03 Thread Maxym Dmytrychenko
ok, it seems that ./configure related deps change are missing.

as you did for overlay:

_filter_deps=

_filter_select=



On Tue, Aug 1, 2017 at 7:58 AM, Huang, Zhengxu <zhengxu.maxw...@gmail.com>
wrote:

>
>
> On 2017/8/1 3:22, Maxym Dmytrychenko wrote:
>
> LGTM, seems to be working just fine
>
>
> Performance will be significantly reduced
>
> if there are performance numbers showing this statement - would be good to
> share it.
>
> The performance comparison between the cascade mode and union mode is blew:
>
>
> As the Libav now only has scale_qsv /interlace_qsv two qsv filters and the
> deinterlace module still has some bug.
> So we use our common filter module to simulate. Though the code is
> different but the result is nearly the same(once we
> make the validation on our patches that 
> framerate/denoise/deinterlace/detail/scale
> filter module are independent).
>
> There are only three filters in the test case but the performance has
> significantly reduced. The more filters in the cascade system
> the more drop on the performance compared with the union mode.
>
>
> On Mon, Jul 31, 2017 at 1:43 PM, Luca Barbato <lu_z...@gentoo.org> 
> <lu_z...@gentoo.org> wrote:
>
>
> On 31/07/2017 03:27, Huang, Zhengxu wrote:
>
>
>  Looks good after a first read, I still need to try it.
>
> Thank you a lot :)
>
> lu
>
> ___
> libav-devel mailing 
> listlibav-devel@libav.orghttps://lists.libav.org/mailman/listinfo/libav-devel
>
> ___
> libav-devel mailing 
> listlibav-devel@libav.orghttps://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 1/2 V3] libavfilter/overlay_qsv: Add QSV overlay vpp filter

2017-08-03 Thread Maxym Dmytrychenko
about configure changes
>+overlay_qsv_filter_deps="libmfx qsv"
why not simply "libmfx" ?

On Thu, Aug 3, 2017 at 11:30 AM, Luca Barbato  wrote:

> On 03/08/2017 04:24, Huang, Zhengxu wrote:
> > ---
> > Changes from v2:
> > * Add "SKIPHEADERS" and modify some comments/typo/coding style as Luca's
> > review .
> >   ---
> > ---
> > Changes from v1:
> > * Replace "enum QSVMemMode" with MFX_MEMTYPE_* type which already have
> > been defined in MSDK header file as per Maxym's review .
> > * Add some comments about the overlay usage.
> >   ---
>
> Seems good to go to me. Thank you a lot!
>
> 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

Re: [libav-devel] [PATCH 1/2] libavfilter/overlay_qsv: Add QSV overlay vpp filter

2017-08-01 Thread Maxym Dmytrychenko
seems to be working.

about:
>enum QSVMemMode
would it be possible to avoid such for the favour of MFX_MEMTYPE_* ?


On Tue, Aug 1, 2017 at 8:10 AM, Huang, Zhengxu 
wrote:

> On 2017/7/31 19:41, Luca Barbato wrote:
>
> On 31/07/2017 03:25, Huang, Zhengxu wrote:
>> After a first quick read I couldn't spot any specific problem, but I'm
>> wondering if at least some of that code couldn't avoided using the
>> device_derive functionality in hwcontext.
>>
> Thanks so much for your review, Luca.
>
> Can you explain in more detail about the "using the device_derive" issue ?
> , ^_^ .
> So I can check and modify the code much better. Thanks.
>
>>
>> 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 mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Re: [libav-devel] [PATCH] lavf/vf_deinterlace_qsv: Enable the qsv deinterlace vpp

2017-07-21 Thread Maxym Dmytrychenko
the same and seems to be working just fine

On Fri, Jul 21, 2017 at 12:36 PM, Luca Barbato  wrote:

> On 21/07/2017 08:35, Huang, Zhengxu wrote:
> >
>
> Looks good. The documentation should be updated as well, but can happen
> on a second time.
>
> 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

Re: [libav-devel] [PATCH V3] libavcodec/mjpeg_qsv: Add QSV MJPEG encoder

2017-07-21 Thread Maxym Dmytrychenko
besides some syntax issues: align the =

It seems to be working with default input as well as from hwaccel qsv:
-hwaccel qsv -c:v h264_qsv -i input_file -vcodec mjpeg_qsv -r 30 -f mjpeg
output

On Fri, Jul 21, 2017 at 6:12 AM, Huang, Zhengxu 
wrote:

> ---
> Changes from v2:
> * modify some coding-style and comments as per Diego's review
>   ---
> ---
> Changes from v1:
> * separate the mjpeg encoder from h264/hevc/mpeg2 as per Luca's review
> * reuse the global_quality option as per Luca's review
> * modify some coding-style and add changlog as per Diego's review
>   ---
>
>
> ___
> 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 6/6] hwaccel: QSV H264 support using libmfx

2014-10-06 Thread Maxym Dmytrychenko
On Mon, Oct 6, 2014 at 4:07 PM, Luca Barbato lu_z...@gentoo.org wrote:

 On 29/09/14 12:35, Luca Barbato wrote:

 On 02/09/14 12:08, Luca Barbato wrote:

 On 02/09/14 11:35, Gwenole Beauchesne wrote:

 I like mfx because this clearly represents the name of the supporting
 library too, so this could help users check it's installed beforehand
 to any complaint that the resulting code does not work. However, cons
 points include (i) probably too similar to MXF, so this could be a
 little confusing, and (ii) in reality, MFX is one legacy codename for
 the original decode block.

  Any name is fine to me.



 I'm rebasing and renaming to:

 files:
 - libmfx*.c

 Structs:
 - Libmfx*Context

 Namespace:
 - mfx_*
 - av_mfx_*

 I'd do this evening, since it is *quite* time consuming I'd like to have
 comments before I do that.


 Maxym advised me to stay with QSV as namespace. Since, using mfx as
 namespace is an headache and he is my contact with the libmfx developer I'd
 tend to side with him.

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


unless other(s) and very good reasons - it looks reasonable.

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


Re: [libav-devel] [PATCH] Intel Media SDK, Quick Sync Video/QSV: Initial add of H.264 decoder infrastructure

2013-02-28 Thread Maxym Dmytrychenko
On Thu, Feb 28, 2013 at 6:27 PM, Diego Biurrun di...@biurrun.de wrote:

 On Thu, Feb 28, 2013 at 05:53:49PM +0100, Max Dm wrote:
  On Thu, Feb 28, 2013 at 3:16 PM, Diego Biurrun di...@biurrun.de wrote:
   On Thu, Feb 28, 2013 at 02:47:39PM +0100, Max Dm wrote:
On Thu, Feb 28, 2013 at 11:38 AM, Diego Biurrun di...@biurrun.de
   wrote:
 On Wed, Feb 27, 2013 at 11:46:45PM +0100, Maxym Dmytrychenko wrote:
  On 13-02-27 19:50:51, Diego Biurrun wrote:
   On Wed, Feb 27, 2013 at 06:39:57PM +0100, maxd wrote:
On 13-02-21 16:03:30, Diego Biurrun wrote:
 On Mon, Feb 04, 2013 at 08:49:35PM +0100, Maxym
 Dmytrychenko
   wrote:
  --- /dev/null
  +++ b/libavcodec/qsv.h
  @@ -0,0 +1,469 @@
 You start the sentence with As ... but then you do not
 say
   what
 follows
 from the ability to use hw acceleration.

  +#ifdef HAVE_AV_CONFIG_H
  +#include config.h
  +#endif

 No such inclusion guard is necessary.
it looks that might help to the final application (
 dependency
   point
 as
it was last time )
I can check more here if needed.
If I will remove it from this file - will be a transparent
 change
for QSV implementation inside libav and final application.
  
   You cannot include config.h in an installed header, with or
   without the
   inclusion guards.
 
  ok, if to move into qsv.c - will it be fine ?
  if so, next patch will move lines:
 
  #ifdef HAVE_AV_CONFIG_H
  #include config.h
  #endif

 Again - no such inclusion guard is necessary.

 right - it was just to show the idea and what is moved,
#ifdef HAVE_AV_CONFIG_H will be dropped while in qsv.c
  
   It has to be and had to be dropped anywhere.
  
Again,  will such move help to solve the question?
  
   Not sure which question you are referring to.
  
   question about having config.h included
  I think we have the agreement : if moved to qsv.c with no
 HAVE_AV_CONFIG_H
  - fine,
  correct?

 Probably yes.

you can have a look on MediaSDK samples and definitions been used
 there,
files like sample_common\include\sample_defs.h
  
   URL?
  
  Homepage of MediaSDK is
  http://software.intel.com/en-us/vcsource/tools/media-sdk
  I can recommend to download and install MediaSDK to see this file.

 I cannot be bothered to be honest.  There is no git/whatever tree directly
 visible online?

 there is only one way to download MediaSDK,
you can see it at provided link,

 please note:
  regardless the fact that this, an initial patch provides QSV-based decode
  only - it has already looking forward structure and implementation.
 
  QSV based acceleration (and MediaSDK API ) goes beyond decode and only,
  it covers filters/VPP cases and encode - meaning: full video transcode
  scenario.
  I would encourage to read more from :
  http://software.intel.com/en-us/vcsource/tools/media-sdk
  and provided together with MediaSDK documentations.
 
  if an application does video transcode or any decode/encode : for best
  performance with QSV - we have to recommend to use not only libav/QSV
  decode but QSV based encode/filters as well.
  Such, fully HW accelerated, approach probably something new for libav but
  provided patch and its definitions and structures is a start to build
 such
  possibility as within libav and up to the final application.
  Note, it goes beyond libav at the level of final application.
  This is what I mean by looking forward.
 
  About possible concern: to have only needed definitions etc - just
 believe
  that it will stay so but just extended in the future.

 Let's add the extra parts when we have a need for them, not earlier.
 We have had a long history of features added for future use and then
 left to rot.


this patch is shared under BSD license,
feel free to adjust it as for libav projects requirements.


 Diego
 ___
 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 2/2] Intel Media SDK, Quick Sync Video/QSV: Initial add of H.264 decoder infrastructure

2013-02-27 Thread Maxym Dmytrychenko
---
 Changelog  |1 +
 configure  |7 +++
 libavcodec/Makefile|2 ++
 libavcodec/allcodecs.c |1 +
 libavcodec/qsv.h   |2 +-
 libavcodec/qsv_h264.c  |9 -
 libavcodec/version.h   |2 +-
 libavutil/pixfmt.h |1 +
 8 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/Changelog b/Changelog
index f56c112..765b87f 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
 version 10:
 - av_strnstr
 - support ID3v2 tags in ASF files
+- QSV decoder hardware acceleration
 
 
 version 9:
diff --git a/configure b/configure
index 1aae93b..dcd0c37 100755
--- a/configure
+++ b/configure
@@ -130,6 +130,7 @@ Component options:
 
 Hardware accelerators:
   --enable-dxva2   enable DXVA2 code
+  --enable-qsv enable QSV code
   --enable-vaapi   enable VAAPI code
   --enable-vda enable VDA code
   --enable-vdpau   enable VDPAU code
@@ -1048,6 +1049,7 @@ EXTERNAL_LIBRARY_LIST=
 
 HWACCEL_LIST=
 dxva2
+qsv
 vaapi
 vda
 vdpau
@@ -1624,6 +1626,8 @@ zmbv_encoder_select=zlib
 
 # hardware accelerators
 dxva2_deps=dxva2api_h
+qsv_deps=mfx_mfxvideo_h
+qsv_extralibs=-lmfx -lstdc++
 vaapi_deps=va_va_h
 vda_deps=VideoDecodeAcceleration_VDADecoder_h pthreads
 vda_extralibs=-framework CoreFoundation -framework VideoDecodeAcceleration 
-framework QuartzCore
@@ -1635,6 +1639,8 @@ h263_vdpau_hwaccel_deps=vdpau
 h263_vdpau_hwaccel_select=h263_decoder
 h264_dxva2_hwaccel_deps=dxva2
 h264_dxva2_hwaccel_select=h264_decoder
+h264_qsv_decoder_deps=qsv
+h264_qsv_decoder_select=h264_decoder
 h264_vaapi_hwaccel_deps=vaapi
 h264_vaapi_hwaccel_select=h264_decoder
 h264_vda_hwaccel_deps=vda
@@ -3468,6 +3474,7 @@ check_header sys/resource.h
 check_header sys/select.h
 check_header sys/time.h
 check_header unistd.h
+check_header mfx/mfxvideo.h
 check_header vdpau/vdpau.h
 check_header vdpau/vdpau_x11.h
 check_header VideoDecodeAcceleration/VDADecoder.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 262d2eb..d0b6166 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -5,6 +5,7 @@ HEADERS = avcodec.h 
\
   avfft.h   \
   dxva2.h   \
   old_codec_ids.h   \
+  qsv.h \
   vaapi.h   \
   vda.h \
   vdpau.h   \
@@ -199,6 +200,7 @@ OBJS-$(CONFIG_H264_DECODER)+= h264.o
   \
   cabac.o h264_sei.o h264_ps.o 
\
   h264_refs.o h264_cavlc.o h264_cabac.o
 OBJS-$(CONFIG_H264_DXVA2_HWACCEL)  += dxva2_h264.o
+OBJS-$(CONFIG_H264_QSV_DECODER)+= qsv.o qsv_h264.o
 OBJS-$(CONFIG_H264_VAAPI_HWACCEL)  += vaapi_h264.o
 OBJS-$(CONFIG_H264_VDA_HWACCEL)+= vda_h264.o
 OBJS-$(CONFIG_H264_VDPAU_HWACCEL)  += vdpau_h264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8bfa603..a4f8643 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -150,6 +150,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(H263I, h263i);
 REGISTER_ENCODER(H263P, h263p);
 REGISTER_DECODER(H264,  h264);
+REGISTER_DECODER(H264_QSV,  h264_qsv);
 REGISTER_DECODER(H264_VDPAU,h264_vdpau);
 REGISTER_ENCDEC (HUFFYUV,   huffyuv);
 REGISTER_DECODER(IDCIN, idcin);
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index cfbf75c..fc16fea 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -335,7 +335,7 @@ typedef struct av_qsv_config {
 
 /**
  * Distance between I- or P- key frames; if it is zero, the GOP structure 
is unspecified.
- * Note: If GopRefDist = 1, there are no B-frames used.
+ * Note: If GopRefDist = 1 no B-frames are used.
  *
  * - encoding: Set by user.
  * - decoding: unused
diff --git a/libavcodec/qsv_h264.c b/libavcodec/qsv_h264.c
index fbd3aa7..51122c2 100644
--- a/libavcodec/qsv_h264.c
+++ b/libavcodec/qsv_h264.c
@@ -267,8 +267,8 @@ int ff_qsv_decode_init(AVCodecContext *avctx)
Using default config for QSV decode\n);
 avctx-hwaccel_context = av_qsv_default_config;
 } else {
-if ((*qsv_config_context)-io_pattern != 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY
- (*qsv_config_context)-io_pattern != 
MFX_IOPATTERN_OUT_SYSTEM_MEMORY) {
+if ((*qsv_config_context)-io_pattern != 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY 
+(*qsv_config_context)-io_pattern != 

[libav-devel] [PATCH 2/2] Intel Media SDK, Quick Sync Video/QSV: Initial add of H.264 decoder infrastructure

2013-02-27 Thread Maxym Dmytrychenko
From: Maxym Dmytrychenko maxim@gmail.com

---
 Changelog  |1 +
 configure  |7 +++
 libavcodec/Makefile|2 ++
 libavcodec/allcodecs.c |1 +
 libavcodec/qsv.h   |2 +-
 libavcodec/qsv_h264.c  |9 -
 libavcodec/version.h   |2 +-
 libavutil/pixfmt.h |1 +
 8 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/Changelog b/Changelog
index f56c112..765b87f 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
 version 10:
 - av_strnstr
 - support ID3v2 tags in ASF files
+- QSV decoder hardware acceleration
 
 
 version 9:
diff --git a/configure b/configure
index 1aae93b..dcd0c37 100755
--- a/configure
+++ b/configure
@@ -130,6 +130,7 @@ Component options:
 
 Hardware accelerators:
   --enable-dxva2   enable DXVA2 code
+  --enable-qsv enable QSV code
   --enable-vaapi   enable VAAPI code
   --enable-vda enable VDA code
   --enable-vdpau   enable VDPAU code
@@ -1048,6 +1049,7 @@ EXTERNAL_LIBRARY_LIST=
 
 HWACCEL_LIST=
 dxva2
+qsv
 vaapi
 vda
 vdpau
@@ -1624,6 +1626,8 @@ zmbv_encoder_select=zlib
 
 # hardware accelerators
 dxva2_deps=dxva2api_h
+qsv_deps=mfx_mfxvideo_h
+qsv_extralibs=-lmfx -lstdc++
 vaapi_deps=va_va_h
 vda_deps=VideoDecodeAcceleration_VDADecoder_h pthreads
 vda_extralibs=-framework CoreFoundation -framework VideoDecodeAcceleration 
-framework QuartzCore
@@ -1635,6 +1639,8 @@ h263_vdpau_hwaccel_deps=vdpau
 h263_vdpau_hwaccel_select=h263_decoder
 h264_dxva2_hwaccel_deps=dxva2
 h264_dxva2_hwaccel_select=h264_decoder
+h264_qsv_decoder_deps=qsv
+h264_qsv_decoder_select=h264_decoder
 h264_vaapi_hwaccel_deps=vaapi
 h264_vaapi_hwaccel_select=h264_decoder
 h264_vda_hwaccel_deps=vda
@@ -3468,6 +3474,7 @@ check_header sys/resource.h
 check_header sys/select.h
 check_header sys/time.h
 check_header unistd.h
+check_header mfx/mfxvideo.h
 check_header vdpau/vdpau.h
 check_header vdpau/vdpau_x11.h
 check_header VideoDecodeAcceleration/VDADecoder.h
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 262d2eb..d0b6166 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -5,6 +5,7 @@ HEADERS = avcodec.h 
\
   avfft.h   \
   dxva2.h   \
   old_codec_ids.h   \
+  qsv.h \
   vaapi.h   \
   vda.h \
   vdpau.h   \
@@ -199,6 +200,7 @@ OBJS-$(CONFIG_H264_DECODER)+= h264.o
   \
   cabac.o h264_sei.o h264_ps.o 
\
   h264_refs.o h264_cavlc.o h264_cabac.o
 OBJS-$(CONFIG_H264_DXVA2_HWACCEL)  += dxva2_h264.o
+OBJS-$(CONFIG_H264_QSV_DECODER)+= qsv.o qsv_h264.o
 OBJS-$(CONFIG_H264_VAAPI_HWACCEL)  += vaapi_h264.o
 OBJS-$(CONFIG_H264_VDA_HWACCEL)+= vda_h264.o
 OBJS-$(CONFIG_H264_VDPAU_HWACCEL)  += vdpau_h264.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 8bfa603..a4f8643 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -150,6 +150,7 @@ void avcodec_register_all(void)
 REGISTER_DECODER(H263I, h263i);
 REGISTER_ENCODER(H263P, h263p);
 REGISTER_DECODER(H264,  h264);
+REGISTER_DECODER(H264_QSV,  h264_qsv);
 REGISTER_DECODER(H264_VDPAU,h264_vdpau);
 REGISTER_ENCDEC (HUFFYUV,   huffyuv);
 REGISTER_DECODER(IDCIN, idcin);
diff --git a/libavcodec/qsv.h b/libavcodec/qsv.h
index cfbf75c..fc16fea 100644
--- a/libavcodec/qsv.h
+++ b/libavcodec/qsv.h
@@ -335,7 +335,7 @@ typedef struct av_qsv_config {
 
 /**
  * Distance between I- or P- key frames; if it is zero, the GOP structure 
is unspecified.
- * Note: If GopRefDist = 1, there are no B-frames used.
+ * Note: If GopRefDist = 1 no B-frames are used.
  *
  * - encoding: Set by user.
  * - decoding: unused
diff --git a/libavcodec/qsv_h264.c b/libavcodec/qsv_h264.c
index fbd3aa7..51122c2 100644
--- a/libavcodec/qsv_h264.c
+++ b/libavcodec/qsv_h264.c
@@ -267,8 +267,8 @@ int ff_qsv_decode_init(AVCodecContext *avctx)
Using default config for QSV decode\n);
 avctx-hwaccel_context = av_qsv_default_config;
 } else {
-if ((*qsv_config_context)-io_pattern != 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY
- (*qsv_config_context)-io_pattern != 
MFX_IOPATTERN_OUT_SYSTEM_MEMORY) {
+if ((*qsv_config_context)-io_pattern != 
MFX_IOPATTERN_OUT_OPAQUE_MEMORY

Re: [libav-devel] [PATCH] Intel Media SDK, Quick Sync Video/QSV: Initial add of H.264 decoder infrastructure

2013-02-27 Thread Maxym Dmytrychenko
On 13-02-27 19:50:51, Diego Biurrun wrote:
 On Wed, Feb 27, 2013 at 06:39:57PM +0100, maxd wrote:
  On 13-02-21 16:03:30, Diego Biurrun wrote:
   On Mon, Feb 04, 2013 at 08:49:35PM +0100, Maxym Dmytrychenko wrote:
From: Maxym Dmytrychenko maxym.dmytryche...@intel.com

   Does your patch pass make check?  I suspect at least the checkheaders
   target will not pass.
  
  my latest patch from
  http://lists.libav.org/pipermail/libav-devel/2013-February/043882.html
  should be fine, 
  including make checkheaders on MinGW and MSVC
 
 It only passes checkheaders if the mxf headers are available.
 Fixed in the changes I sent you.

got it and appriciated!

--- /dev/null
+++ b/libavcodec/qsv.c
@@ -0,0 +1,556 @@
+void av_qsv_stage_clean(av_qsv_stage ** stage)
+{
+
+if ((*stage)-out.p_sync) {
+*(*stage)-out.p_sync = 0;
+(*stage)-out.p_sync = 0;
+}
+av_freep(stage);
   
   Here a variable indirection would make things more readable.
  
  if you have any sample that you can show to follow, I can change it.
 
 av_qsv_stage *stage_ptr = *stage;
 
 Maybe use a better variable name.

ok, will change in the next patch

+av_qsv_stage *av_qsv_get_by_mask(av_qsv_list * list, int mask, 
av_qsv_stage ** prev,
+   av_qsv_list ** this_pipe)
+{
+av_qsv_list *item = 0;
+av_qsv_stage *stage = 0;
+av_qsv_stage *prev_stage = 0;
+int i = 0;
+int a = 0;
+*this_pipe = 0;
+*prev = 0;
+for (i = 0; i  av_qsv_list_count(list); i++) {
+item = av_qsv_list_item(list, i);
+for (a = 0; a  av_qsv_list_count(item); a++) {
+stage = av_qsv_list_item(item, a);
+if (!stage)
+return stage;
+if (stage-type  mask) {
+*prev = prev_stage;
+*this_pipe = item;
+return stage;
+}
+prev_stage = stage;
+}
+}
+return 0;
+}
   
   prev and this_pipe are only used dereferenced, so why not pass them as
   simple pointers?
 
  this way looks to be better for the final application that would use it 
 
 Why?

ok , let's make it easy - I've removed this function completely.

--- /dev/null
+++ b/libavcodec/qsv.h
@@ -0,0 +1,469 @@
   You start the sentence with As ... but then you do not say what follows
   from the ability to use hw acceleration.
   
+#ifdef HAVE_AV_CONFIG_H
+#include config.h
+#endif
   
   No such inclusion guard is necessary.
  it looks that might help to the final application ( dependency point as
  it was last time )
  I can check more here if needed.
  If I will remove it from this file - will be a transparent change
  for QSV implementation inside libav and final application.
 
 You cannot include config.h in an installed header, with or without the
 inclusion guards.

ok, if to move into qsv.c - will it be fine ?
if so, next patch will move lines:

#ifdef HAVE_AV_CONFIG_H
#include config.h
#endif

#if HAVE_THREADS
#if defined (__GNUC__)
#include pthread.h
#define ff_qsv_atomic_inc(ptr) __sync_add_and_fetch(ptr,1)
#define ff_qsv_atomic_dec(ptr) __sync_sub_and_fetch (ptr,1)
#elif HAVE_WINDOWS_H// MSVC case
#include windows.h
#if HAVE_PTHREADS
#include pthread.h
#elif HAVE_W32THREADS
#include w32pthreads.h
#endif
#define ff_qsv_atomic_inc(ptr) InterlockedIncrement(ptr)
#define ff_qsv_atomic_dec(ptr) InterlockedDecrement (ptr)
#else
// targeting only for MinGW or MSVC
#endif

#else
#define ff_qsv_atomic_inc(ptr) ((*ptr)++)
#define ff_qsv_atomic_dec(ptr) ((*ptr)--)
#endif

into qsv.c


+#define AV_QSV_ZERO_MEMORY(VAR){memset(VAR, 0, 
sizeof(VAR));}
+#define AV_QSV_ALIGN32(X)  (((mfxU32)((X)+31))  
(~ (mfxU32)31))
+#define AV_QSV_ALIGN16(value)  (((value + 15)  4)  
4)
+#ifndef AV_QSV_PRINT_RET_MSG
+#define AV_QSV_PRINT_RET_MSG(ERR)  { av_log(NULL, 
AV_LOG_FATAL,Error code %d,\t%s\t%d\n, ERR, __FUNCTION__, __LINE__); }
+#endif
+
+#ifndef AV_QSV_DEBUG_ASSERT
+#define AV_QSV_DEBUG_ASSERT(x,y)   {if ((x)) {av_log(NULL, 
AV_LOG_FATAL,\nASSERT: %s\n,y);};}
+#endif
+
+#define AV_QSV_CHECK_RESULT(P, X, ERR) {if ((X)  (P)) 
{AV_QSV_PRINT_RET_MSG(ERR); return ERR;}}
+#define AV_QSV_CHECK_POINTER(P, ERR)   {if (!(P)) 
{AV_QSV_PRINT_RET_MSG(ERR); return ERR;}}
+#define AV_QSV_IGNORE_MFX_STS(P, X){if ((X) == (P)) {P 
= MFX_ERR_NONE;}}
+
+#define AV_QSV_ID_BUFFER MFX_MAKEFOURCC('B','U','F','F')
+#define AV_QSV_ID_FRAME  MFX_MAKEFOURCC('F','R','M','E')
+
+#define AV_QSV_SURFACE_NUM  80
+#define AV_QSV_SYNC_NUM AV_QSV_SURFACE_NUM*3/4
+#define AV_QSV_BUF_SIZE_DEFAULT 4096