Skip to contentSkip to conversation

media: venus: add support for selection rectangles

PATCH Superseded Malathi Gottam 3 participants 6 messages Oct 9, 2018 – Nov 9, 2018

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: venus: add support for selection rectangles

Handles target type crop by setting the new active rectangle to hardware. The new rectangle should be within YUV size.

---
 drivers/media/platform/qcom/venus/venc.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +17 -2
index 3f50cd0..754c19a 100644
@@ -478,16 +478,31 @@ static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
 venc_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
 {
 	struct venus_inst *inst = to_inst(file);
+	int ret;
+	u32 buftype;
 
 	if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
 		return -EINVAL;
 
 	switch (s->target) {
 	case V4L2_SEL_TGT_CROP:
-		if (s->r.width != inst->out_width ||
-		    s->r.height != inst->out_height ||
+		if (s->r.width > inst->out_width ||
+		    s->r.height > inst->out_height ||
 		    s->r.top != 0 || s->r.left != 0)
 			return -EINVAL;
+		if (s->r.width != inst->width ||
+		    s->r.height != inst->height) {
+			buftype = HFI_BUFFER_OUTPUT;
+			ret = venus_helper_set_output_resolution(inst,
+								 s->r.width,
+								 s->r.height,
+								 buftype);
+			if (ret)
+				return ret;
+
+			inst->width = s->r.width;
+			inst->height = s->r.height;
+		}
 		break;
 	default:
 		return -EINVAL;
Signature · 1 line
1.9.1
#1 lore raw

Hi Malathi,

Quoted 27 lines · Malathi Gottam

Handles target type crop by setting the new active rectangle to hardware. The new rectangle should be within YUV size.

---
 drivers/media/platform/qcom/venus/venc.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +3 -2
index 3f50cd0..754c19a 100644
@@ -478,16 +478,31 @@ static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
 venc_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
 {
 	struct venus_inst *inst = to_inst(file);
+	int ret;
+	u32 buftype;
 
 	if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
 		return -EINVAL;
 
 	switch (s->target) {
 	case V4L2_SEL_TGT_CROP:
-		if (s->r.width != inst->out_width ||
-		    s->r.height != inst->out_height ||
+		if (s->r.width > inst->out_width ||

drivers/media/platform/qcom/venus/venc.c static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f) · line 499

Quoted 10 lines
drivers/media/platform/qcom/venus/venc.c +8 -0
+		    s->r.height > inst->out_height ||
 		    s->r.top != 0 || s->r.left != 0)
 			return -EINVAL;
+		if (s->r.width != inst->width ||
+		    s->r.height != inst->height) {
+			buftype = HFI_BUFFER_OUTPUT;
+			ret = venus_helper_set_output_resolution(inst,
+								 s->r.width,
+								 s->r.height,
+								 buftype);

I'm afraid that set_output_resolution cannot be called at any time. Do you think we can set it after start_session?

Signature · 2 lines
regards,
Stan
#2 lore raw
Quoted 37 lines · Stanimir Varbanov

Hi Malathi,

Quoted 34 lines · Malathi Gottam

Handles target type crop by setting the new active rectangle to hardware. The new rectangle should be within YUV size.

---
 drivers/media/platform/qcom/venus/venc.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +6 -2
index 3f50cd0..754c19a 100644
@@ -478,16 +478,31 @@ static int venc_g_fmt(struct file *file, void 
 *fh, struct v4l2_format *f)
 venc_s_selection(struct file *file, void *fh, struct v4l2_selection 
 *s)
 {
 	struct venus_inst *inst = to_inst(file);
+	int ret;
+	u32 buftype;
 
 	if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
 		return -EINVAL;
 
 	switch (s->target) {
 	case V4L2_SEL_TGT_CROP:
-		if (s->r.width != inst->out_width ||
-		    s->r.height != inst->out_height ||
+		if (s->r.width > inst->out_width ||
+		    s->r.height > inst->out_height ||
 		    s->r.top != 0 || s->r.left != 0)
 			return -EINVAL;
+		if (s->r.width != inst->width ||
+		    s->r.height != inst->height) {
Quoted 8 lines

drivers/media/platform/qcom/venus/venc.c static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f) · line 499

Quoted 5 lines
drivers/media/platform/qcom/venus/venc.c +5 -0
+			buftype = HFI_BUFFER_OUTPUT;
+			ret = venus_helper_set_output_resolution(inst,
+								 s->r.width,
+								 s->r.height,
+								 buftype);

I'm afraid that set_output_resolution cannot be called at any time. Do you think we can set it after start_session?

Yes Stan, we can set output_resolution after the session has been initialization. As per the spec, this call s_selection is an optional step under Initialization procedure of encoder even before we request buffers.

So I think setting output resolution in this api shouldn't cause any issue once we are confident on the instance state.

#3 lore raw

Hi Malathi,

Quoted 47 lines · On 11/1/18 3:10 PM, [email protected] wrote:
Quoted 37 lines · Stanimir Varbanov

Hi Malathi,

Quoted 34 lines · Malathi Gottam

Handles target type crop by setting the new active rectangle to hardware. The new rectangle should be within YUV size.

---
 drivers/media/platform/qcom/venus/venc.c | 19 +++++++++++++++++--

 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +2 -0
index 3f50cd0..754c19a 100644
@@ -478,16 +478,31 @@ static int venc_g_fmt(struct file *file, void
 *fh, struct v4l2_format *f)
  venc_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
  {
      struct venus_inst *inst = to_inst(file);
+    int ret;
+    u32 buftype;
 
      if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
          return -EINVAL;
 
      switch (s->target) {

     case V4L2_SEL_TGT_CROP:
-        if (s->r.width != inst->out_width ||
-            s->r.height != inst->out_height ||
+        if (s->r.width > inst->out_width ||
+            s->r.height > inst->out_height ||
             s->r.top != 0 || s->r.left != 0)
             return -EINVAL;
+        if (s->r.width != inst->width ||
+            s->r.height != inst->height) {

Quoted 8 lines
Quoted 5 lines

+            buftype = HFI_BUFFER_OUTPUT;
+            ret = venus_helper_set_output_resolution(inst, +                                 s->r.width,
+                                 s->r.height,
+                                 buftype);

I'm afraid that set_output_resolution cannot be called at any time. Do you think we can set it after start_session?

Quoted 5 lines

Yes Stan, we can set output_resolution after the session has been initialization.
As per the spec, this call s_selection is an optional step under Initialization
procedure of encoder even before we request buffers.

What spec you are referring to? The spec for the encoders [1] or something else.

Quoted 4 lines

So I think setting output resolution in this api shouldn't cause any issue once
we are confident on the instance state.

OK, but I want to test that on v1 and v3 as well (usually the behavior differs between versions).

Signature · 4 lines
regards,
Stan

[1] https://patchwork.linuxtv.org/patch/52624/
#4 lore raw
Quoted 32 lines · Stanimir Varbanov

Hi Malathi,

Quoted 28 lines · On 11/1/18 3:10 PM, [email protected] wrote:
Quoted 27 lines · Stanimir Varbanov

Hi Malathi,

Quoted 24 lines · Malathi Gottam

Handles target type crop by setting the new active rectangle to hardware. The new rectangle should be within YUV size.

---
 drivers/media/platform/qcom/venus/venc.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +2 -0
index 3f50cd0..754c19a 100644
@@ -478,16 +478,31 @@ static int venc_g_fmt(struct file *file, void
 *fh, struct v4l2_format *f)
 venc_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
 {
     struct venus_inst *inst = to_inst(file);
+    int ret;
+    u32 buftype;
 
     if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
         return -EINVAL;
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/media/platform/qcom/venus/venc.c static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f) · line 492

Quoted 8 lines
drivers/media/platform/qcom/venus/venc.c +2 -2
     switch (s->target) {
     case V4L2_SEL_TGT_CROP:
-        if (s->r.width != inst->out_width ||
-            s->r.height != inst->out_height ||
+        if (s->r.width > inst->out_width ||
+            s->r.height > inst->out_height ||
             s->r.top != 0 || s->r.left != 0)
             return -EINVAL;

Note that returning -EINVAL is not what VIDIOC_S_SELECTION should do here.

As per the general V4L2 spec [1], VIDIOC_S_SELECTION is expected to adjust the crop rectangle "as close as possible to the requested one". In this case that would likely mean something like this:

if (s->r.left != 0) {
    s->r.width += s->r.left;
    s->r.left = 0;
}
if (s->r.top != 0) {
    s->r.height += s->r.top;
    s->r.top = 0;
}

if (s->r.width > inst->out_width)

    s->r.width = inst->out_width;

if (s->r.height > inst->out_height)

    s->r.height = inst->out_height;

[1] https://www.kernel.org/doc/html/latest/media/uapi/v4l/vidioc-g-selection.html

Quoted 11 lines
Quoted 11 lines
Quoted 10 lines

drivers/media/platform/qcom/venus/venc.c static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f) · line 499

Quoted 7 lines
drivers/media/platform/qcom/venus/venc.c +7 -0
+        if (s->r.width != inst->width ||
+            s->r.height != inst->height) {
+            buftype = HFI_BUFFER_OUTPUT;
+            ret = venus_helper_set_output_resolution(inst,
+                                 s->r.width,
+                                 s->r.height,
+                                 buftype);

I'm afraid that set_output_resolution cannot be called at any time. Do you think we can set it after start_session?

Quoted 8 lines
Quoted 5 lines

Yes Stan, we can set output_resolution after the session has been initialization.
As per the spec, this call s_selection is an optional step under Initialization
procedure of encoder even before we request buffers.

What spec you are referring to? The spec for the encoders [1] or something else.

For our convenience, Hans was nice enough to host a compiled version at:
https://hverkuil.home.xs4all.nl/request-api/uapi/v4l/dev-encoder.html

Best regards,
Tomasz

#5 lore raw
Quoted 59 lines · Tomasz Figa
Quoted 32 lines · Stanimir Varbanov

Hi Malathi,

Quoted 28 lines · On 11/1/18 3:10 PM, [email protected] wrote:
Quoted 27 lines · Stanimir Varbanov

Hi Malathi,

Quoted 24 lines · Malathi Gottam

Handles target type crop by setting the new active rectangle to hardware. The new rectangle should be within YUV size.

---
 drivers/media/platform/qcom/venus/venc.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
drivers/media/platform/qcom/venus/venc.c +2 -0
index 3f50cd0..754c19a 100644
@@ -478,16 +478,31 @@ static int venc_g_fmt(struct file *file, void
 *fh, struct v4l2_format *f)
 venc_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
 {
     struct venus_inst *inst = to_inst(file);
+    int ret;
+    u32 buftype;
 
     if (s->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
         return -EINVAL;
 
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/media/platform/qcom/venus/venc.c static int venc_g_fmt(struct file *file, void *fh, struct v4l2_format *f) · line 492

Quoted 8 lines
drivers/media/platform/qcom/venus/venc.c +2 -2
     switch (s->target) {
     case V4L2_SEL_TGT_CROP:
-        if (s->r.width != inst->out_width ||
-            s->r.height != inst->out_height ||
+        if (s->r.width > inst->out_width ||
+            s->r.height > inst->out_height ||
             s->r.top != 0 || s->r.left != 0)
             return -EINVAL;

Note that returning -EINVAL is not what VIDIOC_S_SELECTION should do here.

As per the general V4L2 spec [1], VIDIOC_S_SELECTION is expected to adjust the crop rectangle "as close as possible to the requested one". In this case that would likely mean something like this:

if (s->r.left != 0) {
    s->r.width += s->r.left;
    s->r.left = 0;
}
if (s->r.top != 0) {
    s->r.height += s->r.top;
    s->r.top = 0;
}
Quoted 9 lines

if (s->r.width > inst->out_width)

    s->r.width = inst->out_width;

if (s->r.height > inst->out_height)

    s->r.height = inst->out_height;

[1]
https://www.kernel.org/doc/html/latest/media/uapi/v4l/vidioc-g-selection.html

Yes Tomasz, I overlooked the spec that we cannot return EINVAL in this case.

I will make the necessary changes and update the new patch.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/media/platform/qcom/venus/venc.c +7 -0
+        if (s->r.width != inst->width ||
+            s->r.height != inst->height) {
+            buftype = HFI_BUFFER_OUTPUT;
+            ret = venus_helper_set_output_resolution(inst,
+                                 s->r.width,
+                                 s->r.height,
+                                 buftype);
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

I'm afraid that set_output_resolution cannot be called at any time. Do you think we can set it after start_session?

Yes Stan, we can set output_resolution after the session has been initialization.
As per the spec, this call s_selection is an optional step under Initialization
procedure of encoder even before we request buffers.

Setting this output resolution here I feel it as a repetition as we have this width and height set to firmware as a part of VIDIOC_REQBUFS(). So updating the selection rectangle would be sufficient in this case.

Quoted 9 lines
Quoted 3 lines

What spec you are referring to? The spec for the encoders [1] or something else.

For our convenience, Hans was nice enough to host a compiled version at:
https://hverkuil.home.xs4all.nl/request-api/uapi/v4l/dev-encoder.html

Best regards,
Tomasz