linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder
@ 2014-12-22 16:00 Philipp Zabel
  2015-01-12 15:03 ` Hans Verkuil
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Philipp Zabel @ 2014-12-22 16:00 UTC (permalink / raw)
  To: Kamil Debski
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel,
	Frédéric Sureau, Jean-Michel Hautbois, Nicolas Dufresne,
	Philipp Zabel

The encoder needs to know the nominal framerate for the constant bitrate
control mechanism to work. Currently the only way to set the framerate is
by using VIDIOC_S_PARM on the output queue.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-common.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 39330a7..63eb510 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -803,6 +803,32 @@ static int coda_decoder_cmd(struct file *file, void *fh,
 	return 0;
 }
 
+static int coda_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
+{
+	struct coda_ctx *ctx = fh_to_ctx(fh);
+
+	a->parm.output.timeperframe.denominator = 1;
+	a->parm.output.timeperframe.numerator = ctx->params.framerate;
+
+	return 0;
+}
+
+static int coda_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
+{
+	struct coda_ctx *ctx = fh_to_ctx(fh);
+
+	if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+	    a->parm.output.timeperframe.numerator != 0) {
+		ctx->params.framerate = a->parm.output.timeperframe.denominator
+				      / a->parm.output.timeperframe.numerator;
+	}
+
+	a->parm.output.timeperframe.denominator = 1;
+	a->parm.output.timeperframe.numerator = ctx->params.framerate;
+
+	return 0;
+}
+
 static int coda_subscribe_event(struct v4l2_fh *fh,
 				const struct v4l2_event_subscription *sub)
 {
@@ -843,6 +869,9 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
 	.vidioc_try_decoder_cmd	= coda_try_decoder_cmd,
 	.vidioc_decoder_cmd	= coda_decoder_cmd,
 
+	.vidioc_g_parm		= coda_g_parm,
+	.vidioc_s_parm		= coda_s_parm,
+
 	.vidioc_subscribe_event = coda_subscribe_event,
 	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
 };
-- 
2.1.4


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder
  2014-12-22 16:00 [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder Philipp Zabel
@ 2015-01-12 15:03 ` Hans Verkuil
  2015-01-12 15:35   ` Philipp Zabel
       [not found] ` <54B7E978.5050505@vodalys.com>
  2015-01-15 16:59 ` Frédéric Sureau
  2 siblings, 1 reply; 6+ messages in thread
From: Hans Verkuil @ 2015-01-12 15:03 UTC (permalink / raw)
  To: Philipp Zabel, Kamil Debski
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel,
	Frédéric Sureau, Jean-Michel Hautbois, Nicolas Dufresne

On 12/22/2014 05:00 PM, Philipp Zabel wrote:
> The encoder needs to know the nominal framerate for the constant bitrate
> control mechanism to work. Currently the only way to set the framerate is
> by using VIDIOC_S_PARM on the output queue.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/media/platform/coda/coda-common.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
> index 39330a7..63eb510 100644
> --- a/drivers/media/platform/coda/coda-common.c
> +++ b/drivers/media/platform/coda/coda-common.c
> @@ -803,6 +803,32 @@ static int coda_decoder_cmd(struct file *file, void *fh,
>  	return 0;
>  }
>  
> +static int coda_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +{
> +	struct coda_ctx *ctx = fh_to_ctx(fh);
> +

If a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT, then return -EINVAL. Ditto for s_parm.

> +	a->parm.output.timeperframe.denominator = 1;
> +	a->parm.output.timeperframe.numerator = ctx->params.framerate;
> +
> +	return 0;
> +}
> +
> +static int coda_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +{
> +	struct coda_ctx *ctx = fh_to_ctx(fh);
> +
> +	if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
> +	    a->parm.output.timeperframe.numerator != 0) {
> +		ctx->params.framerate = a->parm.output.timeperframe.denominator
> +				      / a->parm.output.timeperframe.numerator;

Hmm, what happens if the denominator is 1 and the numerator is 2?
You probably want to clamp ctx->params.framerate to the range of allowed framerates.
And at least ensure a framerate > 0.

Also check with v4l2_compliance! You'd have caught at least the missing a->type check.

> +	}
> +
> +	a->parm.output.timeperframe.denominator = 1;
> +	a->parm.output.timeperframe.numerator = ctx->params.framerate;
> +
> +	return 0;
> +}
> +
>  static int coda_subscribe_event(struct v4l2_fh *fh,
>  				const struct v4l2_event_subscription *sub)
>  {
> @@ -843,6 +869,9 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
>  	.vidioc_try_decoder_cmd	= coda_try_decoder_cmd,
>  	.vidioc_decoder_cmd	= coda_decoder_cmd,
>  
> +	.vidioc_g_parm		= coda_g_parm,
> +	.vidioc_s_parm		= coda_s_parm,
> +
>  	.vidioc_subscribe_event = coda_subscribe_event,
>  	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
>  };
> 

Regards,

	Hans

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder
  2015-01-12 15:03 ` Hans Verkuil
@ 2015-01-12 15:35   ` Philipp Zabel
  2015-01-12 15:38     ` Hans Verkuil
  0 siblings, 1 reply; 6+ messages in thread
From: Philipp Zabel @ 2015-01-12 15:35 UTC (permalink / raw)
  To: Hans Verkuil
  Cc: Kamil Debski, Mauro Carvalho Chehab, linux-media, linux-kernel,
	Frédéric Sureau, Jean-Michel Hautbois, Nicolas Dufresne

Hi Hans,

thank you for the comments!

Am Montag, den 12.01.2015, 16:03 +0100 schrieb Hans Verkuil:
> On 12/22/2014 05:00 PM, Philipp Zabel wrote:
> > The encoder needs to know the nominal framerate for the constant bitrate
> > control mechanism to work. Currently the only way to set the framerate is
> > by using VIDIOC_S_PARM on the output queue.
> > 
> > Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> > ---
> >  drivers/media/platform/coda/coda-common.c | 29 +++++++++++++++++++++++++++++
> >  1 file changed, 29 insertions(+)
> > 
> > diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
> > index 39330a7..63eb510 100644
> > --- a/drivers/media/platform/coda/coda-common.c
> > +++ b/drivers/media/platform/coda/coda-common.c
> > @@ -803,6 +803,32 @@ static int coda_decoder_cmd(struct file *file, void *fh,
> >  	return 0;
> >  }
> >  
> > +static int coda_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> > +{
> > +	struct coda_ctx *ctx = fh_to_ctx(fh);
> > +
> 
> If a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT, then return -EINVAL.

If the decoder can retrieve the framerate from the stream, wouldn't it
make sense to allow G_PARM for a->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?

>  Ditto for s_parm.

Will do.

> > +	a->parm.output.timeperframe.denominator = 1;
> > +	a->parm.output.timeperframe.numerator = ctx->params.framerate;
> > +
> > +	return 0;
> > +}
> > +
> > +static int coda_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> > +{
> > +	struct coda_ctx *ctx = fh_to_ctx(fh);
> > +
> > +	if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
> > +	    a->parm.output.timeperframe.numerator != 0) {
> > +		ctx->params.framerate = a->parm.output.timeperframe.denominator
> > +				      / a->parm.output.timeperframe.numerator;
> 
> Hmm, what happens if the denominator is 1 and the numerator is 2?
> You probably want to clamp ctx->params.framerate to the range of allowed framerates.
> And at least ensure a framerate > 0.
> 
> Also check with v4l2_compliance! You'd have caught at least the missing a->type check.

Oh dear, I need to improve my v4l-utils update habits. I'll fix this
patch and resend it.

regards
Philipp


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder
  2015-01-12 15:35   ` Philipp Zabel
@ 2015-01-12 15:38     ` Hans Verkuil
  0 siblings, 0 replies; 6+ messages in thread
From: Hans Verkuil @ 2015-01-12 15:38 UTC (permalink / raw)
  To: Philipp Zabel
  Cc: Kamil Debski, Mauro Carvalho Chehab, linux-media, linux-kernel,
	Frédéric Sureau, Jean-Michel Hautbois, Nicolas Dufresne

On 01/12/2015 04:35 PM, Philipp Zabel wrote:
> Hi Hans,
> 
> thank you for the comments!
> 
> Am Montag, den 12.01.2015, 16:03 +0100 schrieb Hans Verkuil:
>> On 12/22/2014 05:00 PM, Philipp Zabel wrote:
>>> The encoder needs to know the nominal framerate for the constant bitrate
>>> control mechanism to work. Currently the only way to set the framerate is
>>> by using VIDIOC_S_PARM on the output queue.
>>>
>>> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
>>> ---
>>>  drivers/media/platform/coda/coda-common.c | 29 +++++++++++++++++++++++++++++
>>>  1 file changed, 29 insertions(+)
>>>
>>> diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
>>> index 39330a7..63eb510 100644
>>> --- a/drivers/media/platform/coda/coda-common.c
>>> +++ b/drivers/media/platform/coda/coda-common.c
>>> @@ -803,6 +803,32 @@ static int coda_decoder_cmd(struct file *file, void *fh,
>>>  	return 0;
>>>  }
>>>  
>>> +static int coda_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>>> +{
>>> +	struct coda_ctx *ctx = fh_to_ctx(fh);
>>> +
>>
>> If a->type != V4L2_BUF_TYPE_VIDEO_OUTPUT, then return -EINVAL.
> 
> If the decoder can retrieve the framerate from the stream, wouldn't it
> make sense to allow G_PARM for a->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ?

Certainly. But that wasn't in the patch :-)

Regards,

	Hans

> 
>>  Ditto for s_parm.
> 
> Will do.
> 
>>> +	a->parm.output.timeperframe.denominator = 1;
>>> +	a->parm.output.timeperframe.numerator = ctx->params.framerate;
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +static int coda_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
>>> +{
>>> +	struct coda_ctx *ctx = fh_to_ctx(fh);
>>> +
>>> +	if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
>>> +	    a->parm.output.timeperframe.numerator != 0) {
>>> +		ctx->params.framerate = a->parm.output.timeperframe.denominator
>>> +				      / a->parm.output.timeperframe.numerator;
>>
>> Hmm, what happens if the denominator is 1 and the numerator is 2?
>> You probably want to clamp ctx->params.framerate to the range of allowed framerates.
>> And at least ensure a framerate > 0.
>>
>> Also check with v4l2_compliance! You'd have caught at least the missing a->type check.
> 
> Oh dear, I need to improve my v4l-utils update habits. I'll fix this
> patch and resend it.
> 
> regards
> Philipp
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder
       [not found] ` <54B7E978.5050505@vodalys.com>
@ 2015-01-15 16:51   ` Nicolas Dufresne
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Dufresne @ 2015-01-15 16:51 UTC (permalink / raw)
  To: Frédéric Sureau, Philipp Zabel, Kamil Debski
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel,
	Jean-Michel Hautbois


Le 2015-01-15 11:23, Frédéric Sureau a écrit :
> Maybe a->parm.output.capability should be set to 
> |V4L2_CAP_TIMEPERFRAME| here.
> I think it is required by GStreamer V4L2 plugin.
Looking at this, I think output device is indeed the right place to set 
this, and the capability should indeed be updated. Now for the GStreamer 
side, it will need patching. At the moment, this cap is only checked for 
capture device. It's not a major change to enabled that for output 
device with that capability.

cheers,
Nicolas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder
  2014-12-22 16:00 [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder Philipp Zabel
  2015-01-12 15:03 ` Hans Verkuil
       [not found] ` <54B7E978.5050505@vodalys.com>
@ 2015-01-15 16:59 ` Frédéric Sureau
  2 siblings, 0 replies; 6+ messages in thread
From: Frédéric Sureau @ 2015-01-15 16:59 UTC (permalink / raw)
  To: Philipp Zabel, Kamil Debski
  Cc: Mauro Carvalho Chehab, linux-media, linux-kernel,
	Jean-Michel Hautbois, Nicolas Dufresne

Hi Philipp,

Le 22/12/2014 17:00, Philipp Zabel a écrit :
> The encoder needs to know the nominal framerate for the constant bitrate
> control mechanism to work. Currently the only way to set the framerate is
> by using VIDIOC_S_PARM on the output queue.
>
> Signed-off-by: Philipp Zabel<p.zabel@pengutronix.de>
> ---
>   drivers/media/platform/coda/coda-common.c | 29 +++++++++++++++++++++++++++++
>   1 file changed, 29 insertions(+)
>
> diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
> index 39330a7..63eb510 100644
> --- a/drivers/media/platform/coda/coda-common.c
> +++ b/drivers/media/platform/coda/coda-common.c
> @@ -803,6 +803,32 @@ static int coda_decoder_cmd(struct file *file, void *fh,
>   	return 0;
>   }
>   
> +static int coda_g_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +{
> +	struct coda_ctx *ctx = fh_to_ctx(fh);
> +
> +	a->parm.output.timeperframe.denominator = 1;
> +	a->parm.output.timeperframe.numerator = ctx->params.framerate;
> +
Maybe a->parm.output.capability should be set to V4L2_CAP_TIMEPERFRAME here.
I think it is required by GStreamer V4L2 plugin.
> +	return 0;
> +}
> +
> +static int coda_s_parm(struct file *file, void *fh, struct v4l2_streamparm *a)
> +{
> +	struct coda_ctx *ctx = fh_to_ctx(fh);
> +
> +	if (a->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
> +	    a->parm.output.timeperframe.numerator != 0) {
> +		ctx->params.framerate = a->parm.output.timeperframe.denominator
> +				      / a->parm.output.timeperframe.numerator;
> +	}
> +
> +	a->parm.output.timeperframe.denominator = 1;
> +	a->parm.output.timeperframe.numerator = ctx->params.framerate;
> +
> +	return 0;
> +}
> +
>   static int coda_subscribe_event(struct v4l2_fh *fh,
>   				const struct v4l2_event_subscription *sub)
>   {
> @@ -843,6 +869,9 @@ static const struct v4l2_ioctl_ops coda_ioctl_ops = {
>   	.vidioc_try_decoder_cmd	= coda_try_decoder_cmd,
>   	.vidioc_decoder_cmd	= coda_decoder_cmd,
>   
> +	.vidioc_g_parm		= coda_g_parm,
> +	.vidioc_s_parm		= coda_s_parm,
> +
>   	.vidioc_subscribe_event = coda_subscribe_event,
>   	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
>   };
Thanks for the patch!
Fred

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-15 16:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-22 16:00 [RFC PATCH] [media] coda: Use S_PARM to set nominal framerate for h.264 encoder Philipp Zabel
2015-01-12 15:03 ` Hans Verkuil
2015-01-12 15:35   ` Philipp Zabel
2015-01-12 15:38     ` Hans Verkuil
     [not found] ` <54B7E978.5050505@vodalys.com>
2015-01-15 16:51   ` Nicolas Dufresne
2015-01-15 16:59 ` Frédéric Sureau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).