diff mbox series

[FFmpeg-devel,v5] avcodec/v4l2_m2m_enc: Support changing qmin/qmax

Message ID 20200428170636.3624-1-andriy.gelman@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,v5] avcodec/v4l2_m2m_enc: Support changing qmin/qmax | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andriy Gelman April 28, 2020, 5:06 p.m. UTC
From: Andriy Gelman <andriy.gelman@gmail.com>

Hard coded parameters for qmin and qmax are currently used to initialize
v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
are set.

Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
---

 Changes in v5:
    - Check that qmin does not exceed qmax (thanks for feedback from Ming Qian)

 libavcodec/v4l2_m2m_enc.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

Comments

Ming Qian April 29, 2020, 2:45 a.m. UTC | #1
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Andriy
> Gelman
> Sent: Wednesday, April 29, 2020 1:07 AM
> To: ffmpeg-devel@ffmpeg.org
> Cc: Andriy Gelman <andriy.gelman@gmail.com>
> Subject: [EXT] [FFmpeg-devel] [PATCH v5] avcodec/v4l2_m2m_enc: Support
> changing qmin/qmax
> 
> Caution: EXT Email
> 
> From: Andriy Gelman <andriy.gelman@gmail.com>
> 
> Hard coded parameters for qmin and qmax are currently used to initialize
> v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
> are set.
> 
> Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> ---
> 
>  Changes in v5:
>     - Check that qmin does not exceed qmax (thanks for feedback from Ming
> Qian)
> 
>  libavcodec/v4l2_m2m_enc.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index
> 8454e2326c..b22cfc61fb 100644
> --- a/libavcodec/v4l2_m2m_enc.c
> +++ b/libavcodec/v4l2_m2m_enc.c
> @@ -31,6 +31,7 @@
>  #include "v4l2_context.h"
>  #include "v4l2_m2m.h"
>  #include "v4l2_fmt.h"
> +#include "internal.h"
> 
>  #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x  #define MPEG_VIDEO(x)
> V4L2_MPEG_VIDEO_##x @@ -252,11 +253,18 @@ static int
> v4l2_prepare_encoder(V4L2m2mContext *s)
>          return 0;
>      }
> 
> -    if (qmin != avctx->qmin || qmax != avctx->qmax)
> -        av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d),
> qmax (%d)\n", qmin, qmax);
> +    if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax)
> {
> +        av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin
> should not "
> +                                      "exceed qmax\n", avctx->qmin,
> avctx->qmax);
> +    } else {
> +        qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
> +        qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
> +    }
> 
> -    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
> -    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> 0);
> +    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
> +                      avctx->qmin >= 0);
> +    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> +                      avctx->qmax >= 0);
> 
>      return 0;
>  }
> @@ -369,6 +377,12 @@ static const AVOption options[] = {
>      { NULL },
>  };
> 
> +static const AVCodecDefault v4l2_m2m_defaults[] = {
> +    { "qmin", "-1" },
> +    { "qmax", "-1" },
> +    { NULL },
> +};
> +
>  #define M2MENC_CLASS(NAME) \
>      static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
>          .class_name = #NAME "_v4l2m2m_encoder", \ @@ -390,6 +404,7
> @@ static const AVOption options[] = {
>          .send_frame     = v4l2_send_frame, \
>          .receive_packet = v4l2_receive_packet, \
>          .close          = v4l2_encode_close, \
> +        .defaults       = v4l2_m2m_defaults, \
>          .capabilities   = AV_CODEC_CAP_HARDWARE |
> AV_CODEC_CAP_DELAY, \
>          .wrapper_name   = "v4l2m2m", \
>      };
> --
> 2.25.1
> 

Lgtm

> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fffmpeg.
> org%2Fmailman%2Flistinfo%2Fffmpeg-devel&amp;data=02%7C01%7Cming.qi
> an%40nxp.com%7C6099a33995ec46afc18108d7eb9fe706%7C686ea1d3bc2b
> 4c6fa92cd99c5c301635%7C0%7C0%7C637236944315491657&amp;sdata=Se
> kEbzvEj1ro7fgFnt%2FhLWqZ1A%2BrrNNinmsFi%2FuUlRs%3D&amp;reserved=
> 0
> 
> To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org
> with subject "unsubscribe".
Andriy Gelman April 30, 2020, 4 p.m. UTC | #2
On Wed, 29. Apr 02:45, Ming Qian wrote:
> > -----Original Message-----
> > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Andriy
> > Gelman
> > Sent: Wednesday, April 29, 2020 1:07 AM
> > To: ffmpeg-devel@ffmpeg.org
> > Cc: Andriy Gelman <andriy.gelman@gmail.com>
> > Subject: [EXT] [FFmpeg-devel] [PATCH v5] avcodec/v4l2_m2m_enc: Support
> > changing qmin/qmax
> > 
> > Caution: EXT Email
> > 
> > From: Andriy Gelman <andriy.gelman@gmail.com>
> > 
> > Hard coded parameters for qmin and qmax are currently used to initialize
> > v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
> > are set.
> > 
> > Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> > ---
> > 
> >  Changes in v5:
> >     - Check that qmin does not exceed qmax (thanks for feedback from Ming
> > Qian)
> > 
> >  libavcodec/v4l2_m2m_enc.c | 23 +++++++++++++++++++----
> >  1 file changed, 19 insertions(+), 4 deletions(-)
> > 
> > diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index
> > 8454e2326c..b22cfc61fb 100644
> > --- a/libavcodec/v4l2_m2m_enc.c
> > +++ b/libavcodec/v4l2_m2m_enc.c
> > @@ -31,6 +31,7 @@
> >  #include "v4l2_context.h"
> >  #include "v4l2_m2m.h"
> >  #include "v4l2_fmt.h"
> > +#include "internal.h"
> > 
> >  #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x  #define MPEG_VIDEO(x)
> > V4L2_MPEG_VIDEO_##x @@ -252,11 +253,18 @@ static int
> > v4l2_prepare_encoder(V4L2m2mContext *s)
> >          return 0;
> >      }
> > 
> > -    if (qmin != avctx->qmin || qmax != avctx->qmax)
> > -        av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d),
> > qmax (%d)\n", qmin, qmax);
> > +    if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax)
> > {
> > +        av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin
> > should not "
> > +                                      "exceed qmax\n", avctx->qmin,
> > avctx->qmax);
> > +    } else {
> > +        qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
> > +        qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
> > +    }
> > 
> > -    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
> > -    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> > 0);
> > +    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
> > +                      avctx->qmin >= 0);
> > +    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> > +                      avctx->qmax >= 0);
> > 
> >      return 0;
> >  }
> > @@ -369,6 +377,12 @@ static const AVOption options[] = {
> >      { NULL },
> >  };
> > 
> > +static const AVCodecDefault v4l2_m2m_defaults[] = {
> > +    { "qmin", "-1" },
> > +    { "qmax", "-1" },
> > +    { NULL },
> > +};
> > +
> >  #define M2MENC_CLASS(NAME) \
> >      static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
> >          .class_name = #NAME "_v4l2m2m_encoder", \ @@ -390,6 +404,7
> > @@ static const AVOption options[] = {
> >          .send_frame     = v4l2_send_frame, \
> >          .receive_packet = v4l2_receive_packet, \
> >          .close          = v4l2_encode_close, \
> > +        .defaults       = v4l2_m2m_defaults, \
> >          .capabilities   = AV_CODEC_CAP_HARDWARE |
> > AV_CODEC_CAP_DELAY, \
> >          .wrapper_name   = "v4l2m2m", \
> >      };
> > --
> > 2.25.1
> > 

> 
> Lgtm
> 

Thanks, I also locally put internal.h header in the correct alphabetical order.

Will apply Sunday if no one objects.
Andriy Gelman May 5, 2020, 5:28 a.m. UTC | #3
On Thu, 30. Apr 12:00, Andriy Gelman wrote:
> On Wed, 29. Apr 02:45, Ming Qian wrote:
> > > -----Original Message-----
> > > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Andriy
> > > Gelman
> > > Sent: Wednesday, April 29, 2020 1:07 AM
> > > To: ffmpeg-devel@ffmpeg.org
> > > Cc: Andriy Gelman <andriy.gelman@gmail.com>
> > > Subject: [EXT] [FFmpeg-devel] [PATCH v5] avcodec/v4l2_m2m_enc: Support
> > > changing qmin/qmax
> > > 
> > > Caution: EXT Email
> > > 
> > > From: Andriy Gelman <andriy.gelman@gmail.com>
> > > 
> > > Hard coded parameters for qmin and qmax are currently used to initialize
> > > v4l2_m2m device. This commit uses values from avctx->{qmin,qmax} if they
> > > are set.
> > > 
> > > Signed-off-by: Andriy Gelman <andriy.gelman@gmail.com>
> > > ---
> > > 
> > >  Changes in v5:
> > >     - Check that qmin does not exceed qmax (thanks for feedback from Ming
> > > Qian)
> > > 
> > >  libavcodec/v4l2_m2m_enc.c | 23 +++++++++++++++++++----
> > >  1 file changed, 19 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c index
> > > 8454e2326c..b22cfc61fb 100644
> > > --- a/libavcodec/v4l2_m2m_enc.c
> > > +++ b/libavcodec/v4l2_m2m_enc.c
> > > @@ -31,6 +31,7 @@
> > >  #include "v4l2_context.h"
> > >  #include "v4l2_m2m.h"
> > >  #include "v4l2_fmt.h"
> > > +#include "internal.h"
> > > 
> > >  #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x  #define MPEG_VIDEO(x)
> > > V4L2_MPEG_VIDEO_##x @@ -252,11 +253,18 @@ static int
> > > v4l2_prepare_encoder(V4L2m2mContext *s)
> > >          return 0;
> > >      }
> > > 
> > > -    if (qmin != avctx->qmin || qmax != avctx->qmax)
> > > -        av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d),
> > > qmax (%d)\n", qmin, qmax);
> > > +    if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax)
> > > {
> > > +        av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin
> > > should not "
> > > +                                      "exceed qmax\n", avctx->qmin,
> > > avctx->qmax);
> > > +    } else {
> > > +        qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
> > > +        qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
> > > +    }
> > > 
> > > -    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
> > > -    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> > > 0);
> > > +    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
> > > +                      avctx->qmin >= 0);
> > > +    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
> > > +                      avctx->qmax >= 0);
> > > 
> > >      return 0;
> > >  }
> > > @@ -369,6 +377,12 @@ static const AVOption options[] = {
> > >      { NULL },
> > >  };
> > > 
> > > +static const AVCodecDefault v4l2_m2m_defaults[] = {
> > > +    { "qmin", "-1" },
> > > +    { "qmax", "-1" },
> > > +    { NULL },
> > > +};
> > > +
> > >  #define M2MENC_CLASS(NAME) \
> > >      static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
> > >          .class_name = #NAME "_v4l2m2m_encoder", \ @@ -390,6 +404,7
> > > @@ static const AVOption options[] = {
> > >          .send_frame     = v4l2_send_frame, \
> > >          .receive_packet = v4l2_receive_packet, \
> > >          .close          = v4l2_encode_close, \
> > > +        .defaults       = v4l2_m2m_defaults, \
> > >          .capabilities   = AV_CODEC_CAP_HARDWARE |
> > > AV_CODEC_CAP_DELAY, \
> > >          .wrapper_name   = "v4l2m2m", \
> > >      };
> > > --
> > > 2.25.1
> > > 
> 
> > 
> > Lgtm
> > 
> 
> Thanks, I also locally put internal.h header in the correct alphabetical order.
> 
> Will apply Sunday if no one objects. 

Applied. 

Thanks,
diff mbox series

Patch

diff --git a/libavcodec/v4l2_m2m_enc.c b/libavcodec/v4l2_m2m_enc.c
index 8454e2326c..b22cfc61fb 100644
--- a/libavcodec/v4l2_m2m_enc.c
+++ b/libavcodec/v4l2_m2m_enc.c
@@ -31,6 +31,7 @@ 
 #include "v4l2_context.h"
 #include "v4l2_m2m.h"
 #include "v4l2_fmt.h"
+#include "internal.h"
 
 #define MPEG_CID(x) V4L2_CID_MPEG_VIDEO_##x
 #define MPEG_VIDEO(x) V4L2_MPEG_VIDEO_##x
@@ -252,11 +253,18 @@  static int v4l2_prepare_encoder(V4L2m2mContext *s)
         return 0;
     }
 
-    if (qmin != avctx->qmin || qmax != avctx->qmax)
-        av_log(avctx, AV_LOG_WARNING, "Encoder adjusted: qmin (%d), qmax (%d)\n", qmin, qmax);
+    if (avctx->qmin >= 0 && avctx->qmax >= 0 && avctx->qmin > avctx->qmax) {
+        av_log(avctx, AV_LOG_WARNING, "Invalid qmin:%d qmax:%d. qmin should not "
+                                      "exceed qmax\n", avctx->qmin, avctx->qmax);
+    } else {
+        qmin = avctx->qmin >= 0 ? avctx->qmin : qmin;
+        qmax = avctx->qmax >= 0 ? avctx->qmax : qmax;
+    }
 
-    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale", 0);
-    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale", 0);
+    v4l2_set_ext_ctrl(s, qmin_cid, qmin, "minimum video quantizer scale",
+                      avctx->qmin >= 0);
+    v4l2_set_ext_ctrl(s, qmax_cid, qmax, "maximum video quantizer scale",
+                      avctx->qmax >= 0);
 
     return 0;
 }
@@ -369,6 +377,12 @@  static const AVOption options[] = {
     { NULL },
 };
 
+static const AVCodecDefault v4l2_m2m_defaults[] = {
+    { "qmin", "-1" },
+    { "qmax", "-1" },
+    { NULL },
+};
+
 #define M2MENC_CLASS(NAME) \
     static const AVClass v4l2_m2m_ ## NAME ## _enc_class = { \
         .class_name = #NAME "_v4l2m2m_encoder", \
@@ -390,6 +404,7 @@  static const AVOption options[] = {
         .send_frame     = v4l2_send_frame, \
         .receive_packet = v4l2_receive_packet, \
         .close          = v4l2_encode_close, \
+        .defaults       = v4l2_m2m_defaults, \
         .capabilities   = AV_CODEC_CAP_HARDWARE | AV_CODEC_CAP_DELAY, \
         .wrapper_name   = "v4l2m2m", \
     };