Skip to contentSkip to conversation

media: v4l2: Initialize mpeg slice controls

PATCH In review Boris Brezillon 3 participants 7 messages May 3, 2019 – May 29, 2019 Media (V4L/DVB)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: v4l2: Initialize mpeg slice controls

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +19 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;
+		break;
 	default:
 		idx *= ctrl->elem_size;
 		memset(ptr.p + idx, 0, ctrl->elem_size);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 31 lines · Boris Brezillon

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +8 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;

drivers/media/v4l2-core/v4l2-ctrls.c static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, · line 1505

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;

Oops, this isn't complete. It should still zero the p_mpeg2_slice_params struct first. Right now any fields not explicitly set just have whatever was in memory.

Can you post a patch fixing this?

Regards,

Hans

Quoted 5 lines
drivers/media/v4l2-core/v4l2-ctrls.c +1 -0
+		break;
 	default:
 		idx *= ctrl->elem_size;
 		memset(ptr.p + idx, 0, ctrl->elem_size);
#2 lore raw
Quoted 47 lines · Hans Verkuil
Quoted 31 lines · Boris Brezillon

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +8 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;

drivers/media/v4l2-core/v4l2-ctrls.c static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, · line 1505

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;

Oops, this isn't complete. It should still zero the p_mpeg2_slice_params struct first. Right now any fields not explicitly set just have whatever was in memory.

Quoted 3 lines

Can you post a patch fixing this?

I was wondering if we want to zero all the cases, and not just the struct types ones.

Or a different approach would be to define statically-allocated default structs, and init-assign to them. Although this take more space, and has no benefits, except maybe code clarity.

OTOH, I can push a quick fix if you want, just zeroing this struct.

#3 lore raw
Quoted 48 lines · Ezequiel Garcia
Quoted 47 lines · Hans Verkuil
Quoted 31 lines · Boris Brezillon

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +8 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;

drivers/media/v4l2-core/v4l2-ctrls.c static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, · line 1505

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;

Oops, this isn't complete. It should still zero the p_mpeg2_slice_params struct first. Right now any fields not explicitly set just have whatever was in memory.

Quoted 7 lines
Quoted 3 lines

Can you post a patch fixing this?

I was wondering if we want to zero all the cases, and not just the struct types ones.

The others either overwrite the data with the default_value, or memset the whole control (default case). It's only for these compound controls that something special needs to be done.

The code can be restructured, though: instead of break do return in all the simple type cases.

Then call memset followed by a new switch for the compound types where you need to set some fields to non-zero.

Quoted 7 lines

Or a different approach would be to define statically-allocated default structs, and init-assign to them. Although this take more space, and has no benefits, except maybe code clarity.

OTOH, I can push a quick fix if you want, just zeroing this struct.

A quick fix is fine, but as we add new compound types here we need something along the lines of what I described above. A statically-allocated default struct isn't a bad idea either, but a bit overkill for the simple mpeg2_slice_params.

Regards,

Hans

#4 lore raw
Quoted 40 lines · On Wed, 29 May 2019 17:42:58 +0200 Hans Verkuil <[email protected]> wrote:
Quoted 39 lines · Ezequiel Garcia
Quoted 38 lines · Hans Verkuil
Quoted 37 lines · Boris Brezillon

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +14 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/media/v4l2-core/v4l2-ctrls.c static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, · line 1505

Quoted 4 lines
drivers/media/v4l2-core/v4l2-ctrls.c +4 -0
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;  

Oops, this isn't complete. It should still zero the p_mpeg2_slice_params struct first. Right now any fields not explicitly set just have whatever was in memory.

Oops.

Quoted 13 lines
Quoted 8 lines
Quoted 4 lines

Can you post a patch fixing this?

I was wondering if we want to zero all the cases, and not just the struct types ones.

The others either overwrite the data with the default_value, or memset the whole control (default case). It's only for these compound controls that something special needs to be done.

Quoted 5 lines

The code can be restructured, though: instead of break do return in all the simple type cases.

Then call memset followed by a new switch for the compound types where you need to set some fields to non-zero.

memset(0) will fix the undefined val issue, the question is, is it the default we want? I haven't worked on MPEG2 (just posted patches Ezequiel worked on) so I can't tell.

#5 lore raw
Quoted 68 lines · Boris Brezillon
Quoted 40 lines · On Wed, 29 May 2019 17:42:58 +0200 Hans Verkuil <[email protected]> wrote:
Quoted 39 lines · Ezequiel Garcia
Quoted 38 lines · Hans Verkuil
Quoted 37 lines · Boris Brezillon

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +14 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/media/v4l2-core/v4l2-ctrls.c static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, · line 1505

Quoted 4 lines
drivers/media/v4l2-core/v4l2-ctrls.c +4 -0
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;  

Oops, this isn't complete. It should still zero the p_mpeg2_slice_params struct first. Right now any fields not explicitly set just have whatever was in memory.

Oops.

Quoted 14 lines
Quoted 6 lines
Quoted 3 lines

Can you post a patch fixing this?

I was wondering if we want to zero all the cases, and not just the struct types ones.

The others either overwrite the data with the default_value, or memset the whole control (default case). It's only for these compound controls that something special needs to be done.

The code can be restructured, though: instead of break do return in all the simple type cases.

Quoted 7 lines
Quoted 2 lines

Then call memset followed by a new switch for the compound types where you need to set some fields to non-zero.

memset(0) will fix the undefined val issue, the question is, is it the default we want? I haven't worked on MPEG2 (just posted patches Ezequiel worked on) so I can't tell.

Well, any fields where zero is not a good default, should be assigned here.

#6 lore raw
Quoted 72 lines · On Wed, 29 May 2019 13:59:50 -0300 Ezequiel Garcia <[email protected]>…
Quoted 71 lines · Boris Brezillon
Quoted 40 lines · On Wed, 29 May 2019 17:42:58 +0200 Hans Verkuil <[email protected]> wrote:
Quoted 39 lines · Ezequiel Garcia
Quoted 38 lines · Hans Verkuil
Quoted 37 lines · Boris Brezillon

Make sure the default value at least passes the std_validate() tests.

---
 drivers/media/v4l2-core/v4l2-ctrls.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
drivers/media/v4l2-core/v4l2-ctrls.c +14 -1
index b1ae2e555c68..19d40cc6e565 100644
@@ -1461,7 +1461,14 @@ static bool std_equal(const struct v4l2_ctrl *ctrl, u32 idx,
 static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 		     union v4l2_ctrl_ptr ptr)
 {
-	switch (ctrl->type) {
+	struct v4l2_ctrl_mpeg2_slice_params *p_mpeg2_slice_params;
+
+	/*
+	 * The cast is needed to get rid of a gcc warning complaining that
+	 * V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS is not part of the
+	 * v4l2_ctrl_type enum.
+	 */
+	switch ((u32)ctrl->type) {
 	case V4L2_CTRL_TYPE_STRING:
 		idx *= ctrl->elem_size;
 		memset(ptr.p_char + idx, ' ', ctrl->minimum);
@@ -1486,6 +1493,17 @@ static void std_init(const struct v4l2_ctrl *ctrl, u32 idx,
 	case V4L2_CTRL_TYPE_U32:
 		ptr.p_u32[idx] = ctrl->default_value;
 		break;
+	case V4L2_CTRL_TYPE_MPEG2_SLICE_PARAMS:
+		p_mpeg2_slice_params = ptr.p;
+		/* 4:2:0 */
+		p_mpeg2_slice_params->sequence.chroma_format = 1;
+		/* 8 bits */
+		p_mpeg2_slice_params->picture.intra_dc_precision = 0;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

drivers/media/v4l2-core/v4l2-ctrls.c static void std_init(const struct v4l2_ctrl *ctrl, u32 idx, · line 1505

Quoted 4 lines
drivers/media/v4l2-core/v4l2-ctrls.c +4 -0
+		/* interlaced top field */
+		p_mpeg2_slice_params->picture.picture_structure = 1;
+		p_mpeg2_slice_params->picture.picture_coding_type =
+					V4L2_MPEG2_PICTURE_CODING_TYPE_I;    

Oops, this isn't complete. It should still zero the p_mpeg2_slice_params struct first. Right now any fields not explicitly set just have whatever was in memory.

Oops.

Quoted 16 lines
Quoted 6 lines
Quoted 3 lines

Can you post a patch fixing this?

I was wondering if we want to zero all the cases, and not just the struct types ones.

The others either overwrite the data with the default_value, or memset the whole control (default case). It's only for these compound controls that something special needs to be done.

The code can be restructured, though: instead of break do return in all the simple type cases.

Then call memset followed by a new switch for the compound types where you need to set some fields to non-zero.

Quoted 7 lines
Quoted 4 lines

memset(0) will fix the undefined val issue, the question is, is it the default we want? I haven't worked on MPEG2 (just posted patches Ezequiel worked on) so I can't tell.

Well, any fields where zero is not a good default, should be assigned here.

That's my point: I've only assigned fields that were checked by the core and where 0 is not a valid value. That doesn't necessarily make 0 a good default for the other fields :P. Hence my suggestion to have someone that knows about MPEG2 (you :)) check the other fields.