diff mbox series

[v6,8/9] media: Avoid parsing quantization and huffman tables

Message ID 20201215111843.30269-9-mirela.rabulea@oss.nxp.com
State Superseded
Headers show
Series Add V4L2 driver for i.MX8 JPEG Encoder/Decoder | expand

Commit Message

Mirela Rabulea OSS Dec. 15, 2020, 11:18 a.m. UTC
From: Mirela Rabulea <mirela.rabulea@nxp.com>

These are optional in struct v4l2_jpeg_header, so skip DHT/DQT segment
parsing if huffman_tables/quantization_tables were not requested by user,
to save time.
However, do count them (num_dht/num_dqt).

Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
Changes in v6:
  Call jpeg_skip_segment() instead of jpeg_parse_quantization_table()/jpeg_parse_huffman_tables(),
  when quantization/huffman tables are not requested by user.
  Remove the NULL pointer check in the lower-level function.
  Thanks Philipp & Hans for feedback

 drivers/media/v4l2-core/v4l2-jpeg.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Philipp Zabel Jan. 4, 2021, 5 p.m. UTC | #1
On Tue, 2020-12-15 at 13:18 +0200, Mirela Rabulea (OSS) wrote:
> From: Mirela Rabulea <mirela.rabulea@nxp.com>

> 

> These are optional in struct v4l2_jpeg_header, so skip DHT/DQT segment

> parsing if huffman_tables/quantization_tables were not requested by user,

> to save time.

> However, do count them (num_dht/num_dqt).

> 

> Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>

> ---

> Changes in v6:

>   Call jpeg_skip_segment() instead of jpeg_parse_quantization_table()/jpeg_parse_huffman_tables(),

>   when quantization/huffman tables are not requested by user.

>   Remove the NULL pointer check in the lower-level function.

>   Thanks Philipp & Hans for feedback

> 

>  drivers/media/v4l2-core/v4l2-jpeg.c | 8 ++++++++

>  1 file changed, 8 insertions(+)

> 

> diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c

> index dc9def4c2648..f3d03d39defb 100644

> --- a/drivers/media/v4l2-core/v4l2-jpeg.c

> +++ b/drivers/media/v4l2-core/v4l2-jpeg.c

> @@ -537,6 +537,10 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)

>  					&out->dht[out->num_dht++ % 4]);

>  			if (ret < 0)

>  				return ret;

> +			if (!out->huffman_tables) {

> +				ret = jpeg_skip_segment(&stream);

> +				break;

> +			}

>  			ret = jpeg_parse_huffman_tables(&stream,

>  							out->huffman_tables);

>  			break;

> @@ -545,6 +549,10 @@ int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)

>  					&out->dqt[out->num_dqt++ % 4]);

>  			if (ret < 0)

>  				return ret;

> +			if (!out->quantization_tables) {

> +				ret = jpeg_skip_segment(&stream);

> +				break;

> +			}

>  			ret = jpeg_parse_quantization_tables(&stream,

>  					out->frame.precision,

>  					out->quantization_tables);


Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>


regards
Philipp
diff mbox series

Patch

diff --git a/drivers/media/v4l2-core/v4l2-jpeg.c b/drivers/media/v4l2-core/v4l2-jpeg.c
index dc9def4c2648..f3d03d39defb 100644
--- a/drivers/media/v4l2-core/v4l2-jpeg.c
+++ b/drivers/media/v4l2-core/v4l2-jpeg.c
@@ -537,6 +537,10 @@  int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 					&out->dht[out->num_dht++ % 4]);
 			if (ret < 0)
 				return ret;
+			if (!out->huffman_tables) {
+				ret = jpeg_skip_segment(&stream);
+				break;
+			}
 			ret = jpeg_parse_huffman_tables(&stream,
 							out->huffman_tables);
 			break;
@@ -545,6 +549,10 @@  int v4l2_jpeg_parse_header(void *buf, size_t len, struct v4l2_jpeg_header *out)
 					&out->dqt[out->num_dqt++ % 4]);
 			if (ret < 0)
 				return ret;
+			if (!out->quantization_tables) {
+				ret = jpeg_skip_segment(&stream);
+				break;
+			}
 			ret = jpeg_parse_quantization_tables(&stream,
 					out->frame.precision,
 					out->quantization_tables);