aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorFrank Schaefer <fschaefer.oss@googlemail.com>2012-12-08 09:31:32 -0500
committerMauro Carvalho Chehab <mchehab@redhat.com>2012-12-22 18:09:45 -0500
commit36016a351d6245b2753138dff3022efba822e5e2 (patch)
tree9e85e2f1871fb9872f71681fddcf91e4085e012c /drivers/media
parent227b7c90671624e0d143e324a3015726282981df (diff)
[media] em28xx: clean up and unify functions em28xx_copy_vbi() em28xx_copy_video()
The code in em28xx_vbi_copy can be simplified a lot. Also rename some variables to something more meaningful and fix+add the function descriptions. Signed-off-by: Frank Schäfer <fschaefer.oss@googlemail.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c67
1 files changed, 21 insertions, 46 deletions
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index 133e6b0a5c7d..4c1726d43374 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -168,28 +168,27 @@ static inline void finish_buffer(struct em28xx *dev,
168} 168}
169 169
170/* 170/*
171 * Identify the buffer header type and properly handles 171 * Copy picture data from USB buffer to videobuf buffer
172 */ 172 */
173static void em28xx_copy_video(struct em28xx *dev, 173static void em28xx_copy_video(struct em28xx *dev,
174 struct em28xx_buffer *buf, 174 struct em28xx_buffer *buf,
175 unsigned char *p, 175 unsigned char *usb_buf,
176 unsigned long len) 176 unsigned long len)
177{ 177{
178 void *fieldstart, *startwrite, *startread; 178 void *fieldstart, *startwrite, *startread;
179 int linesdone, currlinedone, offset, lencopy, remain; 179 int linesdone, currlinedone, offset, lencopy, remain;
180 int bytesperline = dev->width << 1; 180 int bytesperline = dev->width << 1;
181 unsigned char *outp = buf->vb_buf;
182 181
183 if (buf->pos + len > buf->vb.size) 182 if (buf->pos + len > buf->vb.size)
184 len = buf->vb.size - buf->pos; 183 len = buf->vb.size - buf->pos;
185 184
186 startread = p; 185 startread = usb_buf;
187 remain = len; 186 remain = len;
188 187
189 if (dev->progressive || buf->top_field) 188 if (dev->progressive || buf->top_field)
190 fieldstart = outp; 189 fieldstart = buf->vb_buf;
191 else /* interlaced mode, even nr. of lines */ 190 else /* interlaced mode, even nr. of lines */
192 fieldstart = outp + bytesperline; 191 fieldstart = buf->vb_buf + bytesperline;
193 192
194 linesdone = buf->pos / bytesperline; 193 linesdone = buf->pos / bytesperline;
195 currlinedone = buf->pos % bytesperline; 194 currlinedone = buf->pos % bytesperline;
@@ -203,11 +202,12 @@ static void em28xx_copy_video(struct em28xx *dev,
203 lencopy = bytesperline - currlinedone; 202 lencopy = bytesperline - currlinedone;
204 lencopy = lencopy > remain ? remain : lencopy; 203 lencopy = lencopy > remain ? remain : lencopy;
205 204
206 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { 205 if ((char *)startwrite + lencopy > (char *)buf->vb_buf + buf->vb.size) {
207 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n", 206 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
208 ((char *)startwrite + lencopy) - 207 ((char *)startwrite + lencopy) -
209 ((char *)outp + buf->vb.size)); 208 ((char *)buf->vb_buf + buf->vb.size));
210 remain = (char *)outp + buf->vb.size - (char *)startwrite; 209 remain = (char *)buf->vb_buf + buf->vb.size -
210 (char *)startwrite;
211 lencopy = remain; 211 lencopy = remain;
212 } 212 }
213 if (lencopy <= 0) 213 if (lencopy <= 0)
@@ -227,13 +227,13 @@ static void em28xx_copy_video(struct em28xx *dev,
227 else 227 else
228 lencopy = bytesperline; 228 lencopy = bytesperline;
229 229
230 if ((char *)startwrite + lencopy > (char *)outp + 230 if ((char *)startwrite + lencopy > (char *)buf->vb_buf +
231 buf->vb.size) { 231 buf->vb.size) {
232 em28xx_isocdbg("Overflow of %zi bytes past buffer end" 232 em28xx_isocdbg("Overflow of %zi bytes past buffer end"
233 "(2)\n", 233 "(2)\n",
234 ((char *)startwrite + lencopy) - 234 ((char *)startwrite + lencopy) -
235 ((char *)outp + buf->vb.size)); 235 ((char *)buf->vb_buf + buf->vb.size));
236 lencopy = remain = (char *)outp + buf->vb.size - 236 lencopy = remain = (char *)buf->vb_buf + buf->vb.size -
237 (char *)startwrite; 237 (char *)startwrite;
238 } 238 }
239 if (lencopy <= 0) 239 if (lencopy <= 0)
@@ -247,50 +247,25 @@ static void em28xx_copy_video(struct em28xx *dev,
247 buf->pos += len; 247 buf->pos += len;
248} 248}
249 249
250/*
251 * Copy VBI data from USB buffer to videobuf buffer
252 */
250static void em28xx_copy_vbi(struct em28xx *dev, 253static void em28xx_copy_vbi(struct em28xx *dev,
251 struct em28xx_buffer *buf, 254 struct em28xx_buffer *buf,
252 unsigned char *p, 255 unsigned char *usb_buf,
253 unsigned long len) 256 unsigned long len)
254{ 257{
255 void *startwrite, *startread; 258 unsigned int offset;
256 int offset;
257 int bytesperline;
258 unsigned char *outp;
259
260 if (dev == NULL) {
261 em28xx_isocdbg("dev is null\n");
262 return;
263 }
264 bytesperline = dev->vbi_width;
265
266 if (buf == NULL) {
267 return;
268 }
269 if (p == NULL) {
270 em28xx_isocdbg("p is null\n");
271 return;
272 }
273 outp = buf->vb_buf;
274 if (outp == NULL) {
275 em28xx_isocdbg("outp is null\n");
276 return;
277 }
278 259
279 if (buf->pos + len > buf->vb.size) 260 if (buf->pos + len > buf->vb.size)
280 len = buf->vb.size - buf->pos; 261 len = buf->vb.size - buf->pos;
281 262
282 startread = p;
283
284 startwrite = outp + buf->pos;
285 offset = buf->pos; 263 offset = buf->pos;
286
287 /* Make sure the bottom field populates the second half of the frame */ 264 /* Make sure the bottom field populates the second half of the frame */
288 if (buf->top_field == 0) { 265 if (buf->top_field == 0)
289 startwrite += bytesperline * dev->vbi_height; 266 offset += dev->vbi_width * dev->vbi_height;
290 offset += bytesperline * dev->vbi_height;
291 }
292 267
293 memcpy(startwrite, startread, len); 268 memcpy(buf->vb_buf + offset, usb_buf, len);
294 buf->pos += len; 269 buf->pos += len;
295} 270}
296 271