summaryrefslogtreecommitdiff
path: root/target/linux/brcm2708/patches-3.10/0141-V4L2-Fix-issue-when-switching-down-JPEG-resolution.patch
blob: ee16189e7761a2ca4be71b678ea4adda2c0d1e32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
From 50a40e8c2a9014c62943b034edefa035c0647519 Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dsteve@broadcom.com>
Date: Mon, 9 Dec 2013 11:24:55 +0000
Subject: [PATCH 141/174] V4L2: Fix issue when switching down JPEG resolution.

JPEG buffer size calculation is based on input resolution.
Input resolution was being configured after output port
format. Caused failures if switching from one JPEG resolution
to a smaller one.

Signed-off-by: Dave Stevenson <dsteve@broadcom.com>
---
 drivers/media/platform/bcm2835/bcm2835-camera.c | 126 ++++++++++++++----------
 1 file changed, 72 insertions(+), 54 deletions(-)

--- a/drivers/media/platform/bcm2835/bcm2835-camera.c
+++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
@@ -955,69 +955,87 @@ static int mmal_setup_components(struct
 			camera_port->current_buffer.num =
 			    camera_port->recommended_buffer.num;
 
-			port->format.encoding = mfmt->mmal;
-			port->format.encoding_variant = 0;
-			/* Set any encoding specific parameters */
-			switch (mfmt->mmal_component) {
-			case MMAL_COMPONENT_VIDEO_ENCODE:
-				port->format.bitrate =
-				    dev->capture.encode_bitrate;
-				break;
-			case MMAL_COMPONENT_IMAGE_ENCODE:
-				/* Could set EXIF parameters here */
-				break;
-			default:
-				break;
-			}
-			ret = vchiq_mmal_port_set_format(dev->instance, port);
-
+			ret =
+			    vchiq_mmal_port_connect_tunnel(
+					dev->instance,
+					camera_port,
+					&encode_component->input[0]);
 			if (ret) {
-				v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
-					 "%s failed to set format\n", __func__);
+				v4l2_dbg(1, bcm2835_v4l2_debug,
+					 &dev->v4l2_dev,
+					 "%s failed to create connection\n",
+					 __func__);
+				/* ensure capture is not going to be tried */
+				dev->capture.port = NULL;
 			} else {
+				port->es.video.width = f->fmt.pix.width;
+				port->es.video.height = f->fmt.pix.height;
+				port->es.video.crop.x = 0;
+				port->es.video.crop.y = 0;
+				port->es.video.crop.width = f->fmt.pix.width;
+				port->es.video.crop.height = f->fmt.pix.height;
+				port->es.video.frame_rate.num =
+					  dev->capture.timeperframe.denominator;
+				port->es.video.frame_rate.den =
+					  dev->capture.timeperframe.numerator;
+
+				port->format.encoding = mfmt->mmal;
+				port->format.encoding_variant = 0;
+				/* Set any encoding specific parameters */
+				switch (mfmt->mmal_component) {
+				case MMAL_COMPONENT_VIDEO_ENCODE:
+					port->format.bitrate =
+					    dev->capture.encode_bitrate;
+					break;
+				case MMAL_COMPONENT_IMAGE_ENCODE:
+					/* Could set EXIF parameters here */
+					break;
+				default:
+					break;
+				}
+				ret = vchiq_mmal_port_set_format(dev->instance,
+								 port);
+				if (ret)
+					v4l2_dbg(1, bcm2835_v4l2_debug,
+						 &dev->v4l2_dev,
+						 "%s failed to set format\n",
+						 __func__);
+			}
+
+			if (!ret) {
 				ret = vchiq_mmal_component_enable(
 						dev->instance,
 						encode_component);
 				if (ret) {
 					v4l2_dbg(1, bcm2835_v4l2_debug,
-						 &dev->v4l2_dev,
-						 "%s Failed to enable encode components\n",
-						 __func__);
-				} else {
-					/* configure buffering */
-					port->current_buffer.num = 1;
-					port->current_buffer.size =
-					    f->fmt.pix.sizeimage;
-					if (port->format.encoding ==
-					    MMAL_ENCODING_JPEG) {
-						v4l2_dbg(1, bcm2835_v4l2_debug,
-							 &dev->v4l2_dev,
-							 "JPEG - fiddle buffer size\n");
-						port->current_buffer.size =
-						    (f->fmt.pix.sizeimage <
-						     (100 << 10))
-						    ? (100 << 10) : f->fmt.pix.
-						    sizeimage;
-					}
+					   &dev->v4l2_dev,
+					   "%s Failed to enable encode components\n",
+					   __func__);
+				}
+			}
+			if (!ret) {
+				/* configure buffering */
+				port->current_buffer.num = 1;
+				port->current_buffer.size =
+				    f->fmt.pix.sizeimage;
+				if (port->format.encoding ==
+				    MMAL_ENCODING_JPEG) {
 					v4l2_dbg(1, bcm2835_v4l2_debug,
-						 &dev->v4l2_dev,
-						 "vid_cap - current_buffer.size being set to %d\n",
-						 f->fmt.pix.sizeimage);
-					port->current_buffer.alignment = 0;
-					ret =
-					    vchiq_mmal_port_connect_tunnel(
-							dev->instance,
-							camera_port,
-							&encode_component->input[0]);
-					if (ret) {
-						v4l2_dbg(1, bcm2835_v4l2_debug,
-							 &dev->v4l2_dev,
-							 "%s failed to create connection\n",
-							 __func__);
-						/* ensure capture is not going to be tried */
-						dev->capture.port = NULL;
-					}
+					    &dev->v4l2_dev,
+					    "JPG - buf size now %d was %d\n",
+					    f->fmt.pix.sizeimage,
+					    port->current_buffer.size);
+					port->current_buffer.size =
+					    (f->fmt.pix.sizeimage <
+					     (100 << 10))
+					    ? (100 << 10) : f->fmt.pix.
+					    sizeimage;
 				}
+				v4l2_dbg(1, bcm2835_v4l2_debug,
+					 &dev->v4l2_dev,
+					 "vid_cap - cur_buf.size set to %d\n",
+					 f->fmt.pix.sizeimage);
+				port->current_buffer.alignment = 0;
 			}
 		} else {
 			/* configure buffering */