42ab46c1c40f4161406e5c73822810acec4fef7c
[openwrt/staging/adrian.git] /
1 From 90ad47170414e19ed6c6dcc3f3c9a68fbc7ad175 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.org>
3 Date: Wed, 20 Mar 2019 10:06:51 +0000
4 Subject: [PATCH] staging: bcm2835-codec: Refactor default resolution
5 code
6
7 The default resolution code was different for each role
8 as compressed formats need to pass bytesperline as 0 and
9 set up customised buffer sizes.
10 This is common setup, therefore amend get_sizeimage and
11 get_bytesperline to do the correct thing whether compressed
12 or uncompressed.
13
14 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org>
15 ---
16 .../bcm2835-codec/bcm2835-v4l2-codec.c | 103 +++++++-----------
17 1 file changed, 40 insertions(+), 63 deletions(-)
18
19 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
20 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
21 @@ -578,10 +578,17 @@ static void job_abort(void *priv)
22 ctx->aborting = 1;
23 }
24
25 -static inline unsigned int get_sizeimage(int bpl, int height,
26 +static inline unsigned int get_sizeimage(int bpl, int width, int height,
27 struct bcm2835_codec_fmt *fmt)
28 {
29 - return (bpl * height * fmt->size_multiplier_x2) >> 1;
30 + if (fmt->flags & V4L2_FMT_FLAG_COMPRESSED) {
31 + if (width * height > 1280 * 720)
32 + return DEF_COMP_BUF_SIZE_GREATER_720P;
33 + else
34 + return DEF_COMP_BUF_SIZE_720P_OR_LESS;
35 + } else {
36 + return (bpl * height * fmt->size_multiplier_x2) >> 1;
37 + }
38 }
39
40 static inline unsigned int get_bytesperline(int width,
41 @@ -1032,22 +1039,13 @@ static int vidioc_try_fmt(struct v4l2_fo
42 * some of the pixels are active.
43 */
44 f->fmt.pix.height = ALIGN(f->fmt.pix.height, 16);
45 -
46 - f->fmt.pix.bytesperline = get_bytesperline(f->fmt.pix.width,
47 - fmt);
48 - f->fmt.pix.sizeimage = get_sizeimage(f->fmt.pix.bytesperline,
49 - f->fmt.pix.height,
50 - fmt);
51 - } else {
52 - u32 min_size = f->fmt.pix.width > 1280 ||
53 - f->fmt.pix.height > 720 ?
54 - DEF_COMP_BUF_SIZE_GREATER_720P :
55 - DEF_COMP_BUF_SIZE_720P_OR_LESS;
56 -
57 - f->fmt.pix.bytesperline = 0;
58 - if (f->fmt.pix.sizeimage < min_size)
59 - f->fmt.pix.sizeimage = min_size;
60 }
61 + f->fmt.pix.bytesperline = get_bytesperline(f->fmt.pix.width,
62 + fmt);
63 + f->fmt.pix.sizeimage = get_sizeimage(f->fmt.pix.bytesperline,
64 + f->fmt.pix.width,
65 + f->fmt.pix.height,
66 + fmt);
67
68 f->fmt.pix.field = V4L2_FIELD_NONE;
69
70 @@ -1159,6 +1157,7 @@ static int vidioc_s_fmt(struct bcm2835_c
71 q_data_dst->bytesperline =
72 get_bytesperline(f->fmt.pix.width, q_data_dst->fmt);
73 q_data_dst->sizeimage = get_sizeimage(q_data_dst->bytesperline,
74 + q_data_dst->crop_width,
75 q_data_dst->height,
76 q_data_dst->fmt);
77 update_capture_port = true;
78 @@ -2218,52 +2217,30 @@ static int bcm2835_codec_open(struct fil
79
80 ctx->q_data[V4L2_M2M_SRC].fmt = get_default_format(dev, false);
81 ctx->q_data[V4L2_M2M_DST].fmt = get_default_format(dev, true);
82 - switch (dev->role) {
83 - case DECODE:
84 - /*
85 - * Input width and height are irrelevant as they will be defined
86 - * by the bitstream not the format. Required by V4L2 though.
87 - */
88 - ctx->q_data[V4L2_M2M_SRC].crop_width = DEFAULT_WIDTH;
89 - ctx->q_data[V4L2_M2M_SRC].crop_height = DEFAULT_HEIGHT;
90 - ctx->q_data[V4L2_M2M_SRC].height = DEFAULT_HEIGHT;
91 - ctx->q_data[V4L2_M2M_SRC].bytesperline = 0;
92 - ctx->q_data[V4L2_M2M_SRC].sizeimage =
93 - DEF_COMP_BUF_SIZE_720P_OR_LESS;
94 -
95 - ctx->q_data[V4L2_M2M_DST].crop_width = DEFAULT_WIDTH;
96 - ctx->q_data[V4L2_M2M_DST].crop_height = DEFAULT_HEIGHT;
97 - ctx->q_data[V4L2_M2M_DST].height = DEFAULT_HEIGHT;
98 - ctx->q_data[V4L2_M2M_DST].bytesperline =
99 - get_bytesperline(DEFAULT_WIDTH,
100 - ctx->q_data[V4L2_M2M_DST].fmt);
101 - ctx->q_data[V4L2_M2M_DST].sizeimage =
102 - get_sizeimage(ctx->q_data[V4L2_M2M_DST].bytesperline,
103 - ctx->q_data[V4L2_M2M_DST].height,
104 - ctx->q_data[V4L2_M2M_DST].fmt);
105 - break;
106 - case ENCODE:
107 - ctx->q_data[V4L2_M2M_SRC].crop_width = DEFAULT_WIDTH;
108 - ctx->q_data[V4L2_M2M_SRC].crop_height = DEFAULT_HEIGHT;
109 - ctx->q_data[V4L2_M2M_SRC].height = DEFAULT_HEIGHT;
110 - ctx->q_data[V4L2_M2M_SRC].bytesperline =
111 - get_bytesperline(DEFAULT_WIDTH,
112 - ctx->q_data[V4L2_M2M_SRC].fmt);
113 - ctx->q_data[V4L2_M2M_SRC].sizeimage =
114 - get_sizeimage(ctx->q_data[V4L2_M2M_SRC].bytesperline,
115 - ctx->q_data[V4L2_M2M_SRC].height,
116 - ctx->q_data[V4L2_M2M_SRC].fmt);
117 -
118 - ctx->q_data[V4L2_M2M_DST].crop_width = DEFAULT_WIDTH;
119 - ctx->q_data[V4L2_M2M_DST].crop_height = DEFAULT_HEIGHT;
120 - ctx->q_data[V4L2_M2M_DST].bytesperline = 0;
121 - ctx->q_data[V4L2_M2M_DST].height = DEFAULT_HEIGHT;
122 - ctx->q_data[V4L2_M2M_DST].sizeimage =
123 - DEF_COMP_BUF_SIZE_720P_OR_LESS;
124 - break;
125 - case ISP:
126 - break;
127 - }
128 +
129 + ctx->q_data[V4L2_M2M_SRC].crop_width = DEFAULT_WIDTH;
130 + ctx->q_data[V4L2_M2M_SRC].crop_height = DEFAULT_HEIGHT;
131 + ctx->q_data[V4L2_M2M_SRC].height = DEFAULT_HEIGHT;
132 + ctx->q_data[V4L2_M2M_SRC].bytesperline =
133 + get_bytesperline(DEFAULT_WIDTH,
134 + ctx->q_data[V4L2_M2M_SRC].fmt);
135 + ctx->q_data[V4L2_M2M_SRC].sizeimage =
136 + get_sizeimage(ctx->q_data[V4L2_M2M_SRC].bytesperline,
137 + ctx->q_data[V4L2_M2M_SRC].crop_width,
138 + ctx->q_data[V4L2_M2M_SRC].height,
139 + ctx->q_data[V4L2_M2M_SRC].fmt);
140 +
141 + ctx->q_data[V4L2_M2M_DST].crop_width = DEFAULT_WIDTH;
142 + ctx->q_data[V4L2_M2M_DST].crop_height = DEFAULT_HEIGHT;
143 + ctx->q_data[V4L2_M2M_DST].height = DEFAULT_HEIGHT;
144 + ctx->q_data[V4L2_M2M_DST].bytesperline =
145 + get_bytesperline(DEFAULT_WIDTH,
146 + ctx->q_data[V4L2_M2M_DST].fmt);
147 + ctx->q_data[V4L2_M2M_DST].sizeimage =
148 + get_sizeimage(ctx->q_data[V4L2_M2M_DST].bytesperline,
149 + ctx->q_data[V4L2_M2M_DST].crop_width,
150 + ctx->q_data[V4L2_M2M_DST].height,
151 + ctx->q_data[V4L2_M2M_DST].fmt);
152
153 ctx->colorspace = V4L2_COLORSPACE_REC709;
154 ctx->bitrate = 10 * 1000 * 1000;