diff mbox

[FFmpeg-devel] lavc/vaapi_encode_vp9: add support for low-power encoding

Message ID 20180206081803.24662-1-haihao.xiang@intel.com
State New
Headers show

Commit Message

Xiang, Haihao Feb. 6, 2018, 8:18 a.m. UTC
Although VAEntrypointEncSliceLP was added in old version of VAAPI, we
never implemented it for VAAPI VP9 encoder before. so it is reasonable
to require VAAPI 1.0

Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
---
 libavcodec/vaapi_encode_vp9.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

Comments

James Almer Feb. 6, 2018, 11:43 a.m. UTC | #1
On 2/6/2018 5:18 AM, Haihao Xiang wrote:
> Although VAEntrypointEncSliceLP was added in old version of VAAPI, we
> never implemented it for VAAPI VP9 encoder before. so it is reasonable
> to require VAAPI 1.0
> 
> Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>
> ---
>  libavcodec/vaapi_encode_vp9.c | 19 ++++++++++++++++++-
>  1 file changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
> index 9108699ac38..30f1edbef4a 100644
> --- a/libavcodec/vaapi_encode_vp9.c
> +++ b/libavcodec/vaapi_encode_vp9.c
> @@ -46,6 +46,7 @@ typedef struct VAAPIEncodeVP9Context {
>  typedef struct VAAPIEncodeVP9Options {
>      int loop_filter_level;
>      int loop_filter_sharpness;
> +    int low_power;
>  } VAAPIEncodeVP9Options;
>  
>  
> @@ -217,6 +218,8 @@ static const VAAPIEncodeType vaapi_encode_type_vp9 = {
>  static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
>  {
>      VAAPIEncodeContext *ctx = avctx->priv_data;
> +    VAAPIEncodeVP9Options *opt =
> +        (VAAPIEncodeVP9Options*)ctx->codec_options_data;
>  
>      ctx->codec = &vaapi_encode_type_vp9;
>  
> @@ -243,7 +246,18 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
>                 avctx->profile);
>          return AVERROR(EINVAL);
>      }
> -    ctx->va_entrypoint = VAEntrypointEncSlice;
> +
> +    if (opt->low_power) {
> +#if VA_CHECK_VERSION(1, 0, 0)
> +        ctx->va_entrypoint = VAEntrypointEncSliceLP;
> +#else
> +        av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "
> +               "supported with this VAAPI version.\n");
> +        return AVERROR(EINVAL);

IMO, this should be AVERROR(ENOSYS) instead. Same with the h265 patch.

> +#endif
> +    } else {
> +        ctx->va_entrypoint = VAEntrypointEncSlice;
> +    }
>  
>      if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
>          ctx->va_rc_mode = VA_RC_CQP;
> @@ -274,6 +288,9 @@ static const AVOption vaapi_encode_vp9_options[] = {
>        OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63, FLAGS },
>      { "loop_filter_sharpness", "Loop filter sharpness",
>        OFFSET(loop_filter_sharpness), AV_OPT_TYPE_INT, { .i64 = 4 }, 0, 15, FLAGS },
> +    { "low_power", "Use low-power encoding mode (experimental: only supported "
> +      "on some platforms, does not support all features)",
> +      OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
>      { NULL },
>  };
>  
>
Xiang, Haihao Feb. 7, 2018, 2:56 a.m. UTC | #2
On Tue, 2018-02-06 at 08:43 -0300, James Almer wrote:
> On 2/6/2018 5:18 AM, Haihao Xiang wrote:

> > Although VAEntrypointEncSliceLP was added in old version of VAAPI, we

> > never implemented it for VAAPI VP9 encoder before. so it is reasonable

> > to require VAAPI 1.0

> > 

> > Signed-off-by: Haihao Xiang <haihao.xiang@intel.com>

> > ---

> >  libavcodec/vaapi_encode_vp9.c | 19 ++++++++++++++++++-

> >  1 file changed, 18 insertions(+), 1 deletion(-)

> > 

> > diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c

> > index 9108699ac38..30f1edbef4a 100644

> > --- a/libavcodec/vaapi_encode_vp9.c

> > +++ b/libavcodec/vaapi_encode_vp9.c

> > @@ -46,6 +46,7 @@ typedef struct VAAPIEncodeVP9Context {

> >  typedef struct VAAPIEncodeVP9Options {

> >      int loop_filter_level;

> >      int loop_filter_sharpness;

> > +    int low_power;

> >  } VAAPIEncodeVP9Options;

> >  

> >  

> > @@ -217,6 +218,8 @@ static const VAAPIEncodeType vaapi_encode_type_vp9 = {

> >  static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)

> >  {

> >      VAAPIEncodeContext *ctx = avctx->priv_data;

> > +    VAAPIEncodeVP9Options *opt =

> > +        (VAAPIEncodeVP9Options*)ctx->codec_options_data;

> >  

> >      ctx->codec = &vaapi_encode_type_vp9;

> >  

> > @@ -243,7 +246,18 @@ static av_cold int vaapi_encode_vp9_init(AVCodecContext

> > *avctx)

> >                 avctx->profile);

> >          return AVERROR(EINVAL);

> >      }

> > -    ctx->va_entrypoint = VAEntrypointEncSlice;

> > +

> > +    if (opt->low_power) {

> > +#if VA_CHECK_VERSION(1, 0, 0)

> > +        ctx->va_entrypoint = VAEntrypointEncSliceLP;

> > +#else

> > +        av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "

> > +               "supported with this VAAPI version.\n");

> > +        return AVERROR(EINVAL);

> 

> IMO, this should be AVERROR(ENOSYS) instead. Same with the h265 patch.

> 


Thanks for the comments. To be honest, I just copied & pasted from VAAP H264
encoder, I will update the two patches and submit another patch to fix VAAPI
H264 encoder.

Thanks
Haihao


> > +#endif

> > +    } else {

> > +        ctx->va_entrypoint = VAEntrypointEncSlice;

> > +    }

> >  

> >      if (avctx->flags & AV_CODEC_FLAG_QSCALE) {

> >          ctx->va_rc_mode = VA_RC_CQP;

> > @@ -274,6 +288,9 @@ static const AVOption vaapi_encode_vp9_options[] = {

> >        OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63,

> > FLAGS },

> >      { "loop_filter_sharpness", "Loop filter sharpness",

> >        OFFSET(loop_filter_sharpness), AV_OPT_TYPE_INT, { .i64 = 4 }, 0, 15,

> > FLAGS },

> > +    { "low_power", "Use low-power encoding mode (experimental: only

> > supported "

> > +      "on some platforms, does not support all features)",

> > +      OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },

> >      { NULL },

> >  };

> >  

> > 

> 

> _______________________________________________

> ffmpeg-devel mailing list

> ffmpeg-devel@ffmpeg.org

> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
diff mbox

Patch

diff --git a/libavcodec/vaapi_encode_vp9.c b/libavcodec/vaapi_encode_vp9.c
index 9108699ac38..30f1edbef4a 100644
--- a/libavcodec/vaapi_encode_vp9.c
+++ b/libavcodec/vaapi_encode_vp9.c
@@ -46,6 +46,7 @@  typedef struct VAAPIEncodeVP9Context {
 typedef struct VAAPIEncodeVP9Options {
     int loop_filter_level;
     int loop_filter_sharpness;
+    int low_power;
 } VAAPIEncodeVP9Options;
 
 
@@ -217,6 +218,8 @@  static const VAAPIEncodeType vaapi_encode_type_vp9 = {
 static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
 {
     VAAPIEncodeContext *ctx = avctx->priv_data;
+    VAAPIEncodeVP9Options *opt =
+        (VAAPIEncodeVP9Options*)ctx->codec_options_data;
 
     ctx->codec = &vaapi_encode_type_vp9;
 
@@ -243,7 +246,18 @@  static av_cold int vaapi_encode_vp9_init(AVCodecContext *avctx)
                avctx->profile);
         return AVERROR(EINVAL);
     }
-    ctx->va_entrypoint = VAEntrypointEncSlice;
+
+    if (opt->low_power) {
+#if VA_CHECK_VERSION(1, 0, 0)
+        ctx->va_entrypoint = VAEntrypointEncSliceLP;
+#else
+        av_log(avctx, AV_LOG_ERROR, "Low-power encoding is not "
+               "supported with this VAAPI version.\n");
+        return AVERROR(EINVAL);
+#endif
+    } else {
+        ctx->va_entrypoint = VAEntrypointEncSlice;
+    }
 
     if (avctx->flags & AV_CODEC_FLAG_QSCALE) {
         ctx->va_rc_mode = VA_RC_CQP;
@@ -274,6 +288,9 @@  static const AVOption vaapi_encode_vp9_options[] = {
       OFFSET(loop_filter_level), AV_OPT_TYPE_INT, { .i64 = 16 }, 0, 63, FLAGS },
     { "loop_filter_sharpness", "Loop filter sharpness",
       OFFSET(loop_filter_sharpness), AV_OPT_TYPE_INT, { .i64 = 4 }, 0, 15, FLAGS },
+    { "low_power", "Use low-power encoding mode (experimental: only supported "
+      "on some platforms, does not support all features)",
+      OFFSET(low_power), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, FLAGS },
     { NULL },
 };