OpenWrt – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | From d4154a99430bf73bc501bafc26de80cb1498626c Mon Sep 17 00:00:00 2001 |
2 | From: Dave Stevenson <dave.stevenson@raspberrypi.org> |
||
3 | Date: Fri, 10 Mar 2017 17:27:56 +0000 |
||
4 | Subject: [PATCH 393/454] staging: bcm2835-camera: Return early on errors |
||
5 | |||
6 | Fix several instances where it is easier to return |
||
7 | early on error conditions than handle it as an else |
||
8 | clause. |
||
9 | As requested by Mauro. |
||
10 | |||
11 | Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.org> |
||
12 | --- |
||
13 | .../bcm2835-camera/bcm2835-camera.c | 132 +++++++++--------- |
||
14 | 1 file changed, 68 insertions(+), 64 deletions(-) |
||
15 | |||
16 | --- a/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c |
||
17 | +++ b/drivers/staging/vc04_services/bcm2835-camera/bcm2835-camera.c |
||
18 | @@ -342,7 +342,9 @@ static void buffer_cb(struct vchiq_mmal_ |
||
19 | vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); |
||
20 | } |
||
21 | return; |
||
22 | - } else if (length == 0) { |
||
23 | + } |
||
24 | + |
||
25 | + if (length == 0) { |
||
26 | /* stream ended */ |
||
27 | if (buf) { |
||
28 | /* this should only ever happen if the port is |
||
29 | @@ -365,70 +367,72 @@ static void buffer_cb(struct vchiq_mmal_ |
||
30 | /* signal frame completion */ |
||
31 | complete(&dev->capture.frame_cmplt); |
||
32 | } |
||
33 | - } else { |
||
34 | - if (dev->capture.frame_count) { |
||
35 | - if (dev->capture.vc_start_timestamp == -1) { |
||
36 | - buf->vb.vb2_buf.timestamp = ktime_get_ns(); |
||
37 | - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
38 | - "Buffer time set as current time - %lld", |
||
39 | - buf->vb.vb2_buf.timestamp); |
||
40 | - |
||
41 | - } else if(pts != 0) { |
||
42 | - ktime_t timestamp; |
||
43 | - s64 runtime_us = pts - |
||
44 | - dev->capture.vc_start_timestamp; |
||
45 | - timestamp = ktime_add_us(dev->capture.kernel_start_ts, |
||
46 | - runtime_us); |
||
47 | - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
48 | - "Convert start time %llu and %llu with offset %llu to %llu\n", |
||
49 | - ktime_to_ns(dev->capture.kernel_start_ts), |
||
50 | - dev->capture.vc_start_timestamp, pts, |
||
51 | - ktime_to_ns(timestamp)); |
||
52 | - buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp); |
||
53 | - } else { |
||
54 | - if (dev->capture.last_timestamp) { |
||
55 | - buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp; |
||
56 | - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
57 | - "Buffer time set as last timestamp - %lld", |
||
58 | - buf->vb.vb2_buf.timestamp); |
||
59 | - } |
||
60 | - else { |
||
61 | - buf->vb.vb2_buf.timestamp = |
||
62 | - dev->capture.kernel_start_ts.tv_sec * 1000000000ULL + |
||
63 | - dev->capture.kernel_start_ts.tv_usec * 1000ULL; |
||
64 | - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
65 | - "Buffer time set as start timestamp - %lld", |
||
66 | - buf->vb.vb2_buf.timestamp); |
||
67 | - } |
||
68 | - } |
||
69 | - dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp; |
||
70 | + return; |
||
71 | + } |
||
72 | |||
73 | - vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length); |
||
74 | - if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME) |
||
75 | - buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME; |
||
76 | + if (!dev->capture.frame_count) { |
||
77 | + /* signal frame completion */ |
||
78 | + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); |
||
79 | + complete(&dev->capture.frame_cmplt); |
||
80 | + return; |
||
81 | + } |
||
82 | |||
83 | + if (dev->capture.vc_start_timestamp == -1) { |
||
84 | + /* |
||
85 | + * VPU doesn't support MMAL_PARAMETER_SYSTEM_TIME, rely on |
||
86 | + * kernel time, and have no latency compensation. |
||
87 | + */ |
||
88 | + buf->vb.vb2_buf.timestamp = ktime_get_ns(); |
||
89 | + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
90 | + "Buffer time set as current time - %lld", |
||
91 | + buf->vb.vb2_buf.timestamp); |
||
92 | + } else if (pts != 0) { |
||
93 | + ktime_t timestamp; |
||
94 | + s64 runtime_us = pts - |
||
95 | + dev->capture.vc_start_timestamp; |
||
96 | + timestamp = ktime_add_us(dev->capture.kernel_start_ts, |
||
97 | + runtime_us); |
||
98 | + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
99 | + "Convert start time %llu and %llu with offset %llu to %llu\n", |
||
100 | + ktime_to_ns(dev->capture.kernel_start_ts), |
||
101 | + dev->capture.vc_start_timestamp, pts, |
||
102 | + ktime_to_ns(timestamp)); |
||
103 | + buf->vb.vb2_buf.timestamp = ktime_to_ns(timestamp); |
||
104 | + } else { |
||
105 | + if (dev->capture.last_timestamp) { |
||
106 | + buf->vb.vb2_buf.timestamp = dev->capture.last_timestamp; |
||
107 | v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
108 | - "Buffer has ts %llu", |
||
109 | - dev->capture.last_timestamp); |
||
110 | - vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); |
||
111 | - |
||
112 | - if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS && |
||
113 | - is_capturing(dev)) { |
||
114 | - v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
115 | - "Grab another frame as buffer has EOS"); |
||
116 | - vchiq_mmal_port_parameter_set( |
||
117 | - instance, |
||
118 | - dev->capture.camera_port, |
||
119 | - MMAL_PARAMETER_CAPTURE, |
||
120 | - &dev->capture.frame_count, |
||
121 | - sizeof(dev->capture.frame_count)); |
||
122 | - } |
||
123 | + "Buffer time set as last timestamp - %lld", |
||
124 | + buf->vb.vb2_buf.timestamp); |
||
125 | } else { |
||
126 | - /* signal frame completion */ |
||
127 | - vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); |
||
128 | - complete(&dev->capture.frame_cmplt); |
||
129 | + buf->vb.vb2_buf.timestamp = |
||
130 | + ktime_to_ns(dev->capture.kernel_start_ts); |
||
131 | + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
132 | + "Buffer time set as start timestamp - %lld", |
||
133 | + buf->vb.vb2_buf.timestamp); |
||
134 | } |
||
135 | } |
||
136 | + dev->capture.last_timestamp = buf->vb.vb2_buf.timestamp; |
||
137 | + |
||
138 | + vb2_set_plane_payload(&buf->vb.vb2_buf, 0, length); |
||
139 | + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_KEYFRAME) |
||
140 | + buf->vb.flags |= V4L2_BUF_FLAG_KEYFRAME; |
||
141 | + |
||
142 | + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
143 | + "Buffer has ts %llu", |
||
144 | + dev->capture.last_timestamp); |
||
145 | + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); |
||
146 | + |
||
147 | + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS && |
||
148 | + is_capturing(dev)) { |
||
149 | + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, |
||
150 | + "Grab another frame as buffer has EOS"); |
||
151 | + vchiq_mmal_port_parameter_set(instance, |
||
152 | + dev->capture.camera_port, |
||
153 | + MMAL_PARAMETER_CAPTURE, |
||
154 | + &dev->capture.frame_count, |
||
155 | + sizeof(dev->capture.frame_count)); |
||
156 | + } |
||
157 | } |
||
158 | |||
159 | static int enable_camera(struct bm2835_mmal_dev *dev) |
||
160 | @@ -823,27 +827,27 @@ static int vidioc_overlay(struct file *f |
||
161 | |||
162 | ret = vchiq_mmal_port_set_format(dev->instance, src); |
||
163 | if (ret < 0) |
||
164 | - goto error; |
||
165 | + return ret; |
||
166 | |||
167 | ret = set_overlay_params(dev, dst); |
||
168 | if (ret < 0) |
||
169 | - goto error; |
||
170 | + return ret; |
||
171 | |||
172 | if (enable_camera(dev) < 0) |
||
173 | - goto error; |
||
174 | + return ret; |
||
175 | |||
176 | ret = vchiq_mmal_component_enable( |
||
177 | dev->instance, |
||
178 | dev->component[MMAL_COMPONENT_PREVIEW]); |
||
179 | if (ret < 0) |
||
180 | - goto error; |
||
181 | + return ret; |
||
182 | |||
183 | v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n", |
||
184 | src, dst); |
||
185 | ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst); |
||
186 | if (!ret) |
||
187 | ret = vchiq_mmal_port_enable(dev->instance, src, NULL); |
||
188 | -error: |
||
189 | + |
||
190 | return ret; |
||
191 | } |
||
192 |