diff options
author | Laurent Pinchart <laurent.pinchart@skynet.be> | 2009-06-28 07:37:50 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-09-12 11:18:32 -0400 |
commit | 35f02a681b72ece756cf005e17f305a72329c140 (patch) | |
tree | ce566b9875213470d355a50bd8c6f9edeb1dd8dd /drivers/media/video/uvc/uvc_video.c | |
parent | 6c428b578b15a1dbf40832d3aeed43761940b81f (diff) |
V4L/DVB (12378): uvcvideo: Restructure the driver to support multiple simultaneous streams.
As a first step towards multiple streaming interfaces support, reorganize the
driver's data structures to cleanly separate video control and video streaming
data.
Signed-off-by: Laurent Pinchart <laurent.pinchart@skynet.be>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/uvc/uvc_video.c')
-rw-r--r-- | drivers/media/video/uvc/uvc_video.c | 415 |
1 files changed, 214 insertions, 201 deletions
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c index 68468309932d..acbd73ac6bf4 100644 --- a/drivers/media/video/uvc/uvc_video.c +++ b/drivers/media/video/uvc/uvc_video.c | |||
@@ -61,7 +61,7 @@ int uvc_query_ctrl(struct uvc_device *dev, __u8 query, __u8 unit, | |||
61 | return 0; | 61 | return 0; |
62 | } | 62 | } |
63 | 63 | ||
64 | static void uvc_fixup_video_ctrl(struct uvc_video_device *video, | 64 | static void uvc_fixup_video_ctrl(struct uvc_streaming *stream, |
65 | struct uvc_streaming_control *ctrl) | 65 | struct uvc_streaming_control *ctrl) |
66 | { | 66 | { |
67 | struct uvc_format *format; | 67 | struct uvc_format *format; |
@@ -69,10 +69,10 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video, | |||
69 | unsigned int i; | 69 | unsigned int i; |
70 | 70 | ||
71 | if (ctrl->bFormatIndex <= 0 || | 71 | if (ctrl->bFormatIndex <= 0 || |
72 | ctrl->bFormatIndex > video->streaming->nformats) | 72 | ctrl->bFormatIndex > stream->nformats) |
73 | return; | 73 | return; |
74 | 74 | ||
75 | format = &video->streaming->format[ctrl->bFormatIndex - 1]; | 75 | format = &stream->format[ctrl->bFormatIndex - 1]; |
76 | 76 | ||
77 | for (i = 0; i < format->nframes; ++i) { | 77 | for (i = 0; i < format->nframes; ++i) { |
78 | if (format->frame[i].bFrameIndex == ctrl->bFrameIndex) { | 78 | if (format->frame[i].bFrameIndex == ctrl->bFrameIndex) { |
@@ -86,12 +86,12 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video, | |||
86 | 86 | ||
87 | if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) || | 87 | if (!(format->flags & UVC_FMT_FLAG_COMPRESSED) || |
88 | (ctrl->dwMaxVideoFrameSize == 0 && | 88 | (ctrl->dwMaxVideoFrameSize == 0 && |
89 | video->dev->uvc_version < 0x0110)) | 89 | stream->dev->uvc_version < 0x0110)) |
90 | ctrl->dwMaxVideoFrameSize = | 90 | ctrl->dwMaxVideoFrameSize = |
91 | frame->dwMaxVideoFrameBufferSize; | 91 | frame->dwMaxVideoFrameBufferSize; |
92 | 92 | ||
93 | if (video->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && | 93 | if (stream->dev->quirks & UVC_QUIRK_FIX_BANDWIDTH && |
94 | video->streaming->intf->num_altsetting > 1) { | 94 | stream->intf->num_altsetting > 1) { |
95 | u32 interval; | 95 | u32 interval; |
96 | u32 bandwidth; | 96 | u32 bandwidth; |
97 | 97 | ||
@@ -108,7 +108,7 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video, | |||
108 | bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp; | 108 | bandwidth = frame->wWidth * frame->wHeight / 8 * format->bpp; |
109 | bandwidth *= 10000000 / interval + 1; | 109 | bandwidth *= 10000000 / interval + 1; |
110 | bandwidth /= 1000; | 110 | bandwidth /= 1000; |
111 | if (video->dev->udev->speed == USB_SPEED_HIGH) | 111 | if (stream->dev->udev->speed == USB_SPEED_HIGH) |
112 | bandwidth /= 8; | 112 | bandwidth /= 8; |
113 | bandwidth += 12; | 113 | bandwidth += 12; |
114 | 114 | ||
@@ -116,14 +116,14 @@ static void uvc_fixup_video_ctrl(struct uvc_video_device *video, | |||
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | static int uvc_get_video_ctrl(struct uvc_video_device *video, | 119 | static int uvc_get_video_ctrl(struct uvc_streaming *stream, |
120 | struct uvc_streaming_control *ctrl, int probe, __u8 query) | 120 | struct uvc_streaming_control *ctrl, int probe, __u8 query) |
121 | { | 121 | { |
122 | __u8 *data; | 122 | __u8 *data; |
123 | __u16 size; | 123 | __u16 size; |
124 | int ret; | 124 | int ret; |
125 | 125 | ||
126 | size = video->dev->uvc_version >= 0x0110 ? 34 : 26; | 126 | size = stream->dev->uvc_version >= 0x0110 ? 34 : 26; |
127 | data = kmalloc(size, GFP_KERNEL); | 127 | data = kmalloc(size, GFP_KERNEL); |
128 | if (data == NULL) | 128 | if (data == NULL) |
129 | return -ENOMEM; | 129 | return -ENOMEM; |
@@ -131,7 +131,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video, | |||
131 | if ((video->dev->quirks & UVC_QUIRK_PROBE_DEF) && query == UVC_GET_DEF) | 131 | if ((video->dev->quirks & UVC_QUIRK_PROBE_DEF) && query == UVC_GET_DEF) |
132 | return -EIO; | 132 | return -EIO; |
133 | 133 | ||
134 | ret = __uvc_query_ctrl(video->dev, query, 0, video->streaming->intfnum, | 134 | ret = __uvc_query_ctrl(stream->dev, query, 0, stream->intfnum, |
135 | probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data, | 135 | probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data, |
136 | size, UVC_CTRL_STREAMING_TIMEOUT); | 136 | size, UVC_CTRL_STREAMING_TIMEOUT); |
137 | 137 | ||
@@ -140,7 +140,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video, | |||
140 | * answer a GET_MIN or GET_MAX request with the wCompQuality | 140 | * answer a GET_MIN or GET_MAX request with the wCompQuality |
141 | * field only. | 141 | * field only. |
142 | */ | 142 | */ |
143 | uvc_warn_once(video->dev, UVC_WARN_MINMAX, "UVC non " | 143 | uvc_warn_once(stream->dev, UVC_WARN_MINMAX, "UVC non " |
144 | "compliance - GET_MIN/MAX(PROBE) incorrectly " | 144 | "compliance - GET_MIN/MAX(PROBE) incorrectly " |
145 | "supported. Enabling workaround.\n"); | 145 | "supported. Enabling workaround.\n"); |
146 | memset(ctrl, 0, sizeof ctrl); | 146 | memset(ctrl, 0, sizeof ctrl); |
@@ -152,7 +152,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video, | |||
152 | * video probe control. Warn once and return, the caller will | 152 | * video probe control. Warn once and return, the caller will |
153 | * fall back to GET_CUR. | 153 | * fall back to GET_CUR. |
154 | */ | 154 | */ |
155 | uvc_warn_once(video->dev, UVC_WARN_PROBE_DEF, "UVC non " | 155 | uvc_warn_once(stream->dev, UVC_WARN_PROBE_DEF, "UVC non " |
156 | "compliance - GET_DEF(PROBE) not supported. " | 156 | "compliance - GET_DEF(PROBE) not supported. " |
157 | "Enabling workaround.\n"); | 157 | "Enabling workaround.\n"); |
158 | ret = -EIO; | 158 | ret = -EIO; |
@@ -184,7 +184,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video, | |||
184 | ctrl->bMinVersion = data[32]; | 184 | ctrl->bMinVersion = data[32]; |
185 | ctrl->bMaxVersion = data[33]; | 185 | ctrl->bMaxVersion = data[33]; |
186 | } else { | 186 | } else { |
187 | ctrl->dwClockFrequency = video->dev->clock_frequency; | 187 | ctrl->dwClockFrequency = stream->dev->clock_frequency; |
188 | ctrl->bmFramingInfo = 0; | 188 | ctrl->bmFramingInfo = 0; |
189 | ctrl->bPreferedVersion = 0; | 189 | ctrl->bPreferedVersion = 0; |
190 | ctrl->bMinVersion = 0; | 190 | ctrl->bMinVersion = 0; |
@@ -195,7 +195,7 @@ static int uvc_get_video_ctrl(struct uvc_video_device *video, | |||
195 | * dwMaxPayloadTransferSize fields. Try to get the value from the | 195 | * dwMaxPayloadTransferSize fields. Try to get the value from the |
196 | * format and frame descriptors. | 196 | * format and frame descriptors. |
197 | */ | 197 | */ |
198 | uvc_fixup_video_ctrl(video, ctrl); | 198 | uvc_fixup_video_ctrl(stream, ctrl); |
199 | ret = 0; | 199 | ret = 0; |
200 | 200 | ||
201 | out: | 201 | out: |
@@ -203,14 +203,14 @@ out: | |||
203 | return ret; | 203 | return ret; |
204 | } | 204 | } |
205 | 205 | ||
206 | static int uvc_set_video_ctrl(struct uvc_video_device *video, | 206 | static int uvc_set_video_ctrl(struct uvc_streaming *stream, |
207 | struct uvc_streaming_control *ctrl, int probe) | 207 | struct uvc_streaming_control *ctrl, int probe) |
208 | { | 208 | { |
209 | __u8 *data; | 209 | __u8 *data; |
210 | __u16 size; | 210 | __u16 size; |
211 | int ret; | 211 | int ret; |
212 | 212 | ||
213 | size = video->dev->uvc_version >= 0x0110 ? 34 : 26; | 213 | size = stream->dev->uvc_version >= 0x0110 ? 34 : 26; |
214 | data = kzalloc(size, GFP_KERNEL); | 214 | data = kzalloc(size, GFP_KERNEL); |
215 | if (data == NULL) | 215 | if (data == NULL) |
216 | return -ENOMEM; | 216 | return -ENOMEM; |
@@ -235,8 +235,7 @@ static int uvc_set_video_ctrl(struct uvc_video_device *video, | |||
235 | data[33] = ctrl->bMaxVersion; | 235 | data[33] = ctrl->bMaxVersion; |
236 | } | 236 | } |
237 | 237 | ||
238 | ret = __uvc_query_ctrl(video->dev, UVC_SET_CUR, 0, | 238 | ret = __uvc_query_ctrl(stream->dev, UVC_SET_CUR, 0, stream->intfnum, |
239 | video->streaming->intfnum, | ||
240 | probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data, | 239 | probe ? UVC_VS_PROBE_CONTROL : UVC_VS_COMMIT_CONTROL, data, |
241 | size, UVC_CTRL_STREAMING_TIMEOUT); | 240 | size, UVC_CTRL_STREAMING_TIMEOUT); |
242 | if (ret != size) { | 241 | if (ret != size) { |
@@ -250,7 +249,7 @@ static int uvc_set_video_ctrl(struct uvc_video_device *video, | |||
250 | return ret; | 249 | return ret; |
251 | } | 250 | } |
252 | 251 | ||
253 | int uvc_probe_video(struct uvc_video_device *video, | 252 | int uvc_probe_video(struct uvc_streaming *stream, |
254 | struct uvc_streaming_control *probe) | 253 | struct uvc_streaming_control *probe) |
255 | { | 254 | { |
256 | struct uvc_streaming_control probe_min, probe_max; | 255 | struct uvc_streaming_control probe_min, probe_max; |
@@ -258,7 +257,7 @@ int uvc_probe_video(struct uvc_video_device *video, | |||
258 | unsigned int i; | 257 | unsigned int i; |
259 | int ret; | 258 | int ret; |
260 | 259 | ||
261 | mutex_lock(&video->streaming->mutex); | 260 | mutex_lock(&stream->mutex); |
262 | 261 | ||
263 | /* Perform probing. The device should adjust the requested values | 262 | /* Perform probing. The device should adjust the requested values |
264 | * according to its capabilities. However, some devices, namely the | 263 | * according to its capabilities. However, some devices, namely the |
@@ -267,15 +266,16 @@ int uvc_probe_video(struct uvc_video_device *video, | |||
267 | * that reason, if the needed bandwidth exceeds the maximum available | 266 | * that reason, if the needed bandwidth exceeds the maximum available |
268 | * bandwidth, try to lower the quality. | 267 | * bandwidth, try to lower the quality. |
269 | */ | 268 | */ |
270 | if ((ret = uvc_set_video_ctrl(video, probe, 1)) < 0) | 269 | ret = uvc_set_video_ctrl(stream, probe, 1); |
270 | if (ret < 0) | ||
271 | goto done; | 271 | goto done; |
272 | 272 | ||
273 | /* Get the minimum and maximum values for compression settings. */ | 273 | /* Get the minimum and maximum values for compression settings. */ |
274 | if (!(video->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { | 274 | if (!(stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX)) { |
275 | ret = uvc_get_video_ctrl(video, &probe_min, 1, UVC_GET_MIN); | 275 | ret = uvc_get_video_ctrl(stream, &probe_min, 1, UVC_GET_MIN); |
276 | if (ret < 0) | 276 | if (ret < 0) |
277 | goto done; | 277 | goto done; |
278 | ret = uvc_get_video_ctrl(video, &probe_max, 1, UVC_GET_MAX); | 278 | ret = uvc_get_video_ctrl(stream, &probe_max, 1, UVC_GET_MAX); |
279 | if (ret < 0) | 279 | if (ret < 0) |
280 | goto done; | 280 | goto done; |
281 | 281 | ||
@@ -283,21 +283,21 @@ int uvc_probe_video(struct uvc_video_device *video, | |||
283 | } | 283 | } |
284 | 284 | ||
285 | for (i = 0; i < 2; ++i) { | 285 | for (i = 0; i < 2; ++i) { |
286 | ret = uvc_set_video_ctrl(video, probe, 1); | 286 | ret = uvc_set_video_ctrl(stream, probe, 1); |
287 | if (ret < 0) | 287 | if (ret < 0) |
288 | goto done; | 288 | goto done; |
289 | ret = uvc_get_video_ctrl(video, probe, 1, UVC_GET_CUR); | 289 | ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); |
290 | if (ret < 0) | 290 | if (ret < 0) |
291 | goto done; | 291 | goto done; |
292 | 292 | ||
293 | if (video->streaming->intf->num_altsetting == 1) | 293 | if (stream->intf->num_altsetting == 1) |
294 | break; | 294 | break; |
295 | 295 | ||
296 | bandwidth = probe->dwMaxPayloadTransferSize; | 296 | bandwidth = probe->dwMaxPayloadTransferSize; |
297 | if (bandwidth <= video->streaming->maxpsize) | 297 | if (bandwidth <= stream->maxpsize) |
298 | break; | 298 | break; |
299 | 299 | ||
300 | if (video->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { | 300 | if (stream->dev->quirks & UVC_QUIRK_PROBE_MINMAX) { |
301 | ret = -ENOSPC; | 301 | ret = -ENOSPC; |
302 | goto done; | 302 | goto done; |
303 | } | 303 | } |
@@ -310,14 +310,14 @@ int uvc_probe_video(struct uvc_video_device *video, | |||
310 | } | 310 | } |
311 | 311 | ||
312 | done: | 312 | done: |
313 | mutex_unlock(&video->streaming->mutex); | 313 | mutex_unlock(&stream->mutex); |
314 | return ret; | 314 | return ret; |
315 | } | 315 | } |
316 | 316 | ||
317 | int uvc_commit_video(struct uvc_video_device *video, | 317 | int uvc_commit_video(struct uvc_streaming *stream, |
318 | struct uvc_streaming_control *probe) | 318 | struct uvc_streaming_control *probe) |
319 | { | 319 | { |
320 | return uvc_set_video_ctrl(video, probe, 0); | 320 | return uvc_set_video_ctrl(stream, probe, 0); |
321 | } | 321 | } |
322 | 322 | ||
323 | /* ------------------------------------------------------------------------ | 323 | /* ------------------------------------------------------------------------ |
@@ -369,7 +369,7 @@ int uvc_commit_video(struct uvc_video_device *video, | |||
369 | * to be called with a NULL buf parameter. uvc_video_decode_data and | 369 | * to be called with a NULL buf parameter. uvc_video_decode_data and |
370 | * uvc_video_decode_end will never be called with a NULL buffer. | 370 | * uvc_video_decode_end will never be called with a NULL buffer. |
371 | */ | 371 | */ |
372 | static int uvc_video_decode_start(struct uvc_video_device *video, | 372 | static int uvc_video_decode_start(struct uvc_streaming *stream, |
373 | struct uvc_buffer *buf, const __u8 *data, int len) | 373 | struct uvc_buffer *buf, const __u8 *data, int len) |
374 | { | 374 | { |
375 | __u8 fid; | 375 | __u8 fid; |
@@ -395,25 +395,25 @@ static int uvc_video_decode_start(struct uvc_video_device *video, | |||
395 | * NULL. | 395 | * NULL. |
396 | */ | 396 | */ |
397 | if (buf == NULL) { | 397 | if (buf == NULL) { |
398 | video->last_fid = fid; | 398 | stream->last_fid = fid; |
399 | return -ENODATA; | 399 | return -ENODATA; |
400 | } | 400 | } |
401 | 401 | ||
402 | /* Synchronize to the input stream by waiting for the FID bit to be | 402 | /* Synchronize to the input stream by waiting for the FID bit to be |
403 | * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE. | 403 | * toggled when the the buffer state is not UVC_BUF_STATE_ACTIVE. |
404 | * video->last_fid is initialized to -1, so the first isochronous | 404 | * stream->last_fid is initialized to -1, so the first isochronous |
405 | * frame will always be in sync. | 405 | * frame will always be in sync. |
406 | * | 406 | * |
407 | * If the device doesn't toggle the FID bit, invert video->last_fid | 407 | * If the device doesn't toggle the FID bit, invert stream->last_fid |
408 | * when the EOF bit is set to force synchronisation on the next packet. | 408 | * when the EOF bit is set to force synchronisation on the next packet. |
409 | */ | 409 | */ |
410 | if (buf->state != UVC_BUF_STATE_ACTIVE) { | 410 | if (buf->state != UVC_BUF_STATE_ACTIVE) { |
411 | if (fid == video->last_fid) { | 411 | if (fid == stream->last_fid) { |
412 | uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of " | 412 | uvc_trace(UVC_TRACE_FRAME, "Dropping payload (out of " |
413 | "sync).\n"); | 413 | "sync).\n"); |
414 | if ((video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && | 414 | if ((stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) && |
415 | (data[1] & UVC_STREAM_EOF)) | 415 | (data[1] & UVC_STREAM_EOF)) |
416 | video->last_fid ^= UVC_STREAM_FID; | 416 | stream->last_fid ^= UVC_STREAM_FID; |
417 | return -ENODATA; | 417 | return -ENODATA; |
418 | } | 418 | } |
419 | 419 | ||
@@ -428,7 +428,7 @@ static int uvc_video_decode_start(struct uvc_video_device *video, | |||
428 | * last payload can be lost anyway). We thus must check if the FID has | 428 | * last payload can be lost anyway). We thus must check if the FID has |
429 | * been toggled. | 429 | * been toggled. |
430 | * | 430 | * |
431 | * video->last_fid is initialized to -1, so the first isochronous | 431 | * stream->last_fid is initialized to -1, so the first isochronous |
432 | * frame will never trigger an end of frame detection. | 432 | * frame will never trigger an end of frame detection. |
433 | * | 433 | * |
434 | * Empty buffers (bytesused == 0) don't trigger end of frame detection | 434 | * Empty buffers (bytesused == 0) don't trigger end of frame detection |
@@ -436,22 +436,22 @@ static int uvc_video_decode_start(struct uvc_video_device *video, | |||
436 | * avoids detecting end of frame conditions at FID toggling if the | 436 | * avoids detecting end of frame conditions at FID toggling if the |
437 | * previous payload had the EOF bit set. | 437 | * previous payload had the EOF bit set. |
438 | */ | 438 | */ |
439 | if (fid != video->last_fid && buf->buf.bytesused != 0) { | 439 | if (fid != stream->last_fid && buf->buf.bytesused != 0) { |
440 | uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit " | 440 | uvc_trace(UVC_TRACE_FRAME, "Frame complete (FID bit " |
441 | "toggled).\n"); | 441 | "toggled).\n"); |
442 | buf->state = UVC_BUF_STATE_DONE; | 442 | buf->state = UVC_BUF_STATE_DONE; |
443 | return -EAGAIN; | 443 | return -EAGAIN; |
444 | } | 444 | } |
445 | 445 | ||
446 | video->last_fid = fid; | 446 | stream->last_fid = fid; |
447 | 447 | ||
448 | return data[0]; | 448 | return data[0]; |
449 | } | 449 | } |
450 | 450 | ||
451 | static void uvc_video_decode_data(struct uvc_video_device *video, | 451 | static void uvc_video_decode_data(struct uvc_streaming *stream, |
452 | struct uvc_buffer *buf, const __u8 *data, int len) | 452 | struct uvc_buffer *buf, const __u8 *data, int len) |
453 | { | 453 | { |
454 | struct uvc_video_queue *queue = &video->queue; | 454 | struct uvc_video_queue *queue = &stream->queue; |
455 | unsigned int maxlen, nbytes; | 455 | unsigned int maxlen, nbytes; |
456 | void *mem; | 456 | void *mem; |
457 | 457 | ||
@@ -472,7 +472,7 @@ static void uvc_video_decode_data(struct uvc_video_device *video, | |||
472 | } | 472 | } |
473 | } | 473 | } |
474 | 474 | ||
475 | static void uvc_video_decode_end(struct uvc_video_device *video, | 475 | static void uvc_video_decode_end(struct uvc_streaming *stream, |
476 | struct uvc_buffer *buf, const __u8 *data, int len) | 476 | struct uvc_buffer *buf, const __u8 *data, int len) |
477 | { | 477 | { |
478 | /* Mark the buffer as done if the EOF marker is set. */ | 478 | /* Mark the buffer as done if the EOF marker is set. */ |
@@ -481,8 +481,8 @@ static void uvc_video_decode_end(struct uvc_video_device *video, | |||
481 | if (data[0] == len) | 481 | if (data[0] == len) |
482 | uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n"); | 482 | uvc_trace(UVC_TRACE_FRAME, "EOF in empty payload.\n"); |
483 | buf->state = UVC_BUF_STATE_DONE; | 483 | buf->state = UVC_BUF_STATE_DONE; |
484 | if (video->dev->quirks & UVC_QUIRK_STREAM_NO_FID) | 484 | if (stream->dev->quirks & UVC_QUIRK_STREAM_NO_FID) |
485 | video->last_fid ^= UVC_STREAM_FID; | 485 | stream->last_fid ^= UVC_STREAM_FID; |
486 | } | 486 | } |
487 | } | 487 | } |
488 | 488 | ||
@@ -497,26 +497,26 @@ static void uvc_video_decode_end(struct uvc_video_device *video, | |||
497 | * uvc_video_encode_data is called for every URB and copies the data from the | 497 | * uvc_video_encode_data is called for every URB and copies the data from the |
498 | * video buffer to the transfer buffer. | 498 | * video buffer to the transfer buffer. |
499 | */ | 499 | */ |
500 | static int uvc_video_encode_header(struct uvc_video_device *video, | 500 | static int uvc_video_encode_header(struct uvc_streaming *stream, |
501 | struct uvc_buffer *buf, __u8 *data, int len) | 501 | struct uvc_buffer *buf, __u8 *data, int len) |
502 | { | 502 | { |
503 | data[0] = 2; /* Header length */ | 503 | data[0] = 2; /* Header length */ |
504 | data[1] = UVC_STREAM_EOH | UVC_STREAM_EOF | 504 | data[1] = UVC_STREAM_EOH | UVC_STREAM_EOF |
505 | | (video->last_fid & UVC_STREAM_FID); | 505 | | (stream->last_fid & UVC_STREAM_FID); |
506 | return 2; | 506 | return 2; |
507 | } | 507 | } |
508 | 508 | ||
509 | static int uvc_video_encode_data(struct uvc_video_device *video, | 509 | static int uvc_video_encode_data(struct uvc_streaming *stream, |
510 | struct uvc_buffer *buf, __u8 *data, int len) | 510 | struct uvc_buffer *buf, __u8 *data, int len) |
511 | { | 511 | { |
512 | struct uvc_video_queue *queue = &video->queue; | 512 | struct uvc_video_queue *queue = &stream->queue; |
513 | unsigned int nbytes; | 513 | unsigned int nbytes; |
514 | void *mem; | 514 | void *mem; |
515 | 515 | ||
516 | /* Copy video data to the URB buffer. */ | 516 | /* Copy video data to the URB buffer. */ |
517 | mem = queue->mem + buf->buf.m.offset + queue->buf_used; | 517 | mem = queue->mem + buf->buf.m.offset + queue->buf_used; |
518 | nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used); | 518 | nbytes = min((unsigned int)len, buf->buf.bytesused - queue->buf_used); |
519 | nbytes = min(video->bulk.max_payload_size - video->bulk.payload_size, | 519 | nbytes = min(stream->bulk.max_payload_size - stream->bulk.payload_size, |
520 | nbytes); | 520 | nbytes); |
521 | memcpy(data, mem, nbytes); | 521 | memcpy(data, mem, nbytes); |
522 | 522 | ||
@@ -532,8 +532,8 @@ static int uvc_video_encode_data(struct uvc_video_device *video, | |||
532 | /* | 532 | /* |
533 | * Completion handler for video URBs. | 533 | * Completion handler for video URBs. |
534 | */ | 534 | */ |
535 | static void uvc_video_decode_isoc(struct urb *urb, | 535 | static void uvc_video_decode_isoc(struct urb *urb, struct uvc_streaming *stream, |
536 | struct uvc_video_device *video, struct uvc_buffer *buf) | 536 | struct uvc_buffer *buf) |
537 | { | 537 | { |
538 | u8 *mem; | 538 | u8 *mem; |
539 | int ret, i; | 539 | int ret, i; |
@@ -548,31 +548,32 @@ static void uvc_video_decode_isoc(struct urb *urb, | |||
548 | /* Decode the payload header. */ | 548 | /* Decode the payload header. */ |
549 | mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; | 549 | mem = urb->transfer_buffer + urb->iso_frame_desc[i].offset; |
550 | do { | 550 | do { |
551 | ret = uvc_video_decode_start(video, buf, mem, | 551 | ret = uvc_video_decode_start(stream, buf, mem, |
552 | urb->iso_frame_desc[i].actual_length); | 552 | urb->iso_frame_desc[i].actual_length); |
553 | if (ret == -EAGAIN) | 553 | if (ret == -EAGAIN) |
554 | buf = uvc_queue_next_buffer(&video->queue, buf); | 554 | buf = uvc_queue_next_buffer(&stream->queue, |
555 | buf); | ||
555 | } while (ret == -EAGAIN); | 556 | } while (ret == -EAGAIN); |
556 | 557 | ||
557 | if (ret < 0) | 558 | if (ret < 0) |
558 | continue; | 559 | continue; |
559 | 560 | ||
560 | /* Decode the payload data. */ | 561 | /* Decode the payload data. */ |
561 | uvc_video_decode_data(video, buf, mem + ret, | 562 | uvc_video_decode_data(stream, buf, mem + ret, |
562 | urb->iso_frame_desc[i].actual_length - ret); | 563 | urb->iso_frame_desc[i].actual_length - ret); |
563 | 564 | ||
564 | /* Process the header again. */ | 565 | /* Process the header again. */ |
565 | uvc_video_decode_end(video, buf, mem, | 566 | uvc_video_decode_end(stream, buf, mem, |
566 | urb->iso_frame_desc[i].actual_length); | 567 | urb->iso_frame_desc[i].actual_length); |
567 | 568 | ||
568 | if (buf->state == UVC_BUF_STATE_DONE || | 569 | if (buf->state == UVC_BUF_STATE_DONE || |
569 | buf->state == UVC_BUF_STATE_ERROR) | 570 | buf->state == UVC_BUF_STATE_ERROR) |
570 | buf = uvc_queue_next_buffer(&video->queue, buf); | 571 | buf = uvc_queue_next_buffer(&stream->queue, buf); |
571 | } | 572 | } |
572 | } | 573 | } |
573 | 574 | ||
574 | static void uvc_video_decode_bulk(struct urb *urb, | 575 | static void uvc_video_decode_bulk(struct urb *urb, struct uvc_streaming *stream, |
575 | struct uvc_video_device *video, struct uvc_buffer *buf) | 576 | struct uvc_buffer *buf) |
576 | { | 577 | { |
577 | u8 *mem; | 578 | u8 *mem; |
578 | int len, ret; | 579 | int len, ret; |
@@ -582,24 +583,25 @@ static void uvc_video_decode_bulk(struct urb *urb, | |||
582 | 583 | ||
583 | mem = urb->transfer_buffer; | 584 | mem = urb->transfer_buffer; |
584 | len = urb->actual_length; | 585 | len = urb->actual_length; |
585 | video->bulk.payload_size += len; | 586 | stream->bulk.payload_size += len; |
586 | 587 | ||
587 | /* If the URB is the first of its payload, decode and save the | 588 | /* If the URB is the first of its payload, decode and save the |
588 | * header. | 589 | * header. |
589 | */ | 590 | */ |
590 | if (video->bulk.header_size == 0 && !video->bulk.skip_payload) { | 591 | if (stream->bulk.header_size == 0 && !stream->bulk.skip_payload) { |
591 | do { | 592 | do { |
592 | ret = uvc_video_decode_start(video, buf, mem, len); | 593 | ret = uvc_video_decode_start(stream, buf, mem, len); |
593 | if (ret == -EAGAIN) | 594 | if (ret == -EAGAIN) |
594 | buf = uvc_queue_next_buffer(&video->queue, buf); | 595 | buf = uvc_queue_next_buffer(&stream->queue, |
596 | buf); | ||
595 | } while (ret == -EAGAIN); | 597 | } while (ret == -EAGAIN); |
596 | 598 | ||
597 | /* If an error occured skip the rest of the payload. */ | 599 | /* If an error occured skip the rest of the payload. */ |
598 | if (ret < 0 || buf == NULL) { | 600 | if (ret < 0 || buf == NULL) { |
599 | video->bulk.skip_payload = 1; | 601 | stream->bulk.skip_payload = 1; |
600 | } else { | 602 | } else { |
601 | memcpy(video->bulk.header, mem, ret); | 603 | memcpy(stream->bulk.header, mem, ret); |
602 | video->bulk.header_size = ret; | 604 | stream->bulk.header_size = ret; |
603 | 605 | ||
604 | mem += ret; | 606 | mem += ret; |
605 | len -= ret; | 607 | len -= ret; |
@@ -612,33 +614,34 @@ static void uvc_video_decode_bulk(struct urb *urb, | |||
612 | */ | 614 | */ |
613 | 615 | ||
614 | /* Process video data. */ | 616 | /* Process video data. */ |
615 | if (!video->bulk.skip_payload && buf != NULL) | 617 | if (!stream->bulk.skip_payload && buf != NULL) |
616 | uvc_video_decode_data(video, buf, mem, len); | 618 | uvc_video_decode_data(stream, buf, mem, len); |
617 | 619 | ||
618 | /* Detect the payload end by a URB smaller than the maximum size (or | 620 | /* Detect the payload end by a URB smaller than the maximum size (or |
619 | * a payload size equal to the maximum) and process the header again. | 621 | * a payload size equal to the maximum) and process the header again. |
620 | */ | 622 | */ |
621 | if (urb->actual_length < urb->transfer_buffer_length || | 623 | if (urb->actual_length < urb->transfer_buffer_length || |
622 | video->bulk.payload_size >= video->bulk.max_payload_size) { | 624 | stream->bulk.payload_size >= stream->bulk.max_payload_size) { |
623 | if (!video->bulk.skip_payload && buf != NULL) { | 625 | if (!stream->bulk.skip_payload && buf != NULL) { |
624 | uvc_video_decode_end(video, buf, video->bulk.header, | 626 | uvc_video_decode_end(stream, buf, stream->bulk.header, |
625 | video->bulk.payload_size); | 627 | stream->bulk.payload_size); |
626 | if (buf->state == UVC_BUF_STATE_DONE || | 628 | if (buf->state == UVC_BUF_STATE_DONE || |
627 | buf->state == UVC_BUF_STATE_ERROR) | 629 | buf->state == UVC_BUF_STATE_ERROR) |
628 | buf = uvc_queue_next_buffer(&video->queue, buf); | 630 | buf = uvc_queue_next_buffer(&stream->queue, |
631 | buf); | ||
629 | } | 632 | } |
630 | 633 | ||
631 | video->bulk.header_size = 0; | 634 | stream->bulk.header_size = 0; |
632 | video->bulk.skip_payload = 0; | 635 | stream->bulk.skip_payload = 0; |
633 | video->bulk.payload_size = 0; | 636 | stream->bulk.payload_size = 0; |
634 | } | 637 | } |
635 | } | 638 | } |
636 | 639 | ||
637 | static void uvc_video_encode_bulk(struct urb *urb, | 640 | static void uvc_video_encode_bulk(struct urb *urb, struct uvc_streaming *stream, |
638 | struct uvc_video_device *video, struct uvc_buffer *buf) | 641 | struct uvc_buffer *buf) |
639 | { | 642 | { |
640 | u8 *mem = urb->transfer_buffer; | 643 | u8 *mem = urb->transfer_buffer; |
641 | int len = video->urb_size, ret; | 644 | int len = stream->urb_size, ret; |
642 | 645 | ||
643 | if (buf == NULL) { | 646 | if (buf == NULL) { |
644 | urb->transfer_buffer_length = 0; | 647 | urb->transfer_buffer_length = 0; |
@@ -646,40 +649,40 @@ static void uvc_video_encode_bulk(struct urb *urb, | |||
646 | } | 649 | } |
647 | 650 | ||
648 | /* If the URB is the first of its payload, add the header. */ | 651 | /* If the URB is the first of its payload, add the header. */ |
649 | if (video->bulk.header_size == 0) { | 652 | if (stream->bulk.header_size == 0) { |
650 | ret = uvc_video_encode_header(video, buf, mem, len); | 653 | ret = uvc_video_encode_header(stream, buf, mem, len); |
651 | video->bulk.header_size = ret; | 654 | stream->bulk.header_size = ret; |
652 | video->bulk.payload_size += ret; | 655 | stream->bulk.payload_size += ret; |
653 | mem += ret; | 656 | mem += ret; |
654 | len -= ret; | 657 | len -= ret; |
655 | } | 658 | } |
656 | 659 | ||
657 | /* Process video data. */ | 660 | /* Process video data. */ |
658 | ret = uvc_video_encode_data(video, buf, mem, len); | 661 | ret = uvc_video_encode_data(stream, buf, mem, len); |
659 | 662 | ||
660 | video->bulk.payload_size += ret; | 663 | stream->bulk.payload_size += ret; |
661 | len -= ret; | 664 | len -= ret; |
662 | 665 | ||
663 | if (buf->buf.bytesused == video->queue.buf_used || | 666 | if (buf->buf.bytesused == stream->queue.buf_used || |
664 | video->bulk.payload_size == video->bulk.max_payload_size) { | 667 | stream->bulk.payload_size == stream->bulk.max_payload_size) { |
665 | if (buf->buf.bytesused == video->queue.buf_used) { | 668 | if (buf->buf.bytesused == stream->queue.buf_used) { |
666 | video->queue.buf_used = 0; | 669 | stream->queue.buf_used = 0; |
667 | buf->state = UVC_BUF_STATE_DONE; | 670 | buf->state = UVC_BUF_STATE_DONE; |
668 | uvc_queue_next_buffer(&video->queue, buf); | 671 | uvc_queue_next_buffer(&stream->queue, buf); |
669 | video->last_fid ^= UVC_STREAM_FID; | 672 | stream->last_fid ^= UVC_STREAM_FID; |
670 | } | 673 | } |
671 | 674 | ||
672 | video->bulk.header_size = 0; | 675 | stream->bulk.header_size = 0; |
673 | video->bulk.payload_size = 0; | 676 | stream->bulk.payload_size = 0; |
674 | } | 677 | } |
675 | 678 | ||
676 | urb->transfer_buffer_length = video->urb_size - len; | 679 | urb->transfer_buffer_length = stream->urb_size - len; |
677 | } | 680 | } |
678 | 681 | ||
679 | static void uvc_video_complete(struct urb *urb) | 682 | static void uvc_video_complete(struct urb *urb) |
680 | { | 683 | { |
681 | struct uvc_video_device *video = urb->context; | 684 | struct uvc_streaming *stream = urb->context; |
682 | struct uvc_video_queue *queue = &video->queue; | 685 | struct uvc_video_queue *queue = &stream->queue; |
683 | struct uvc_buffer *buf = NULL; | 686 | struct uvc_buffer *buf = NULL; |
684 | unsigned long flags; | 687 | unsigned long flags; |
685 | int ret; | 688 | int ret; |
@@ -693,7 +696,7 @@ static void uvc_video_complete(struct urb *urb) | |||
693 | "completion handler.\n", urb->status); | 696 | "completion handler.\n", urb->status); |
694 | 697 | ||
695 | case -ENOENT: /* usb_kill_urb() called. */ | 698 | case -ENOENT: /* usb_kill_urb() called. */ |
696 | if (video->frozen) | 699 | if (stream->frozen) |
697 | return; | 700 | return; |
698 | 701 | ||
699 | case -ECONNRESET: /* usb_unlink_urb() called. */ | 702 | case -ECONNRESET: /* usb_unlink_urb() called. */ |
@@ -708,7 +711,7 @@ static void uvc_video_complete(struct urb *urb) | |||
708 | queue); | 711 | queue); |
709 | spin_unlock_irqrestore(&queue->irqlock, flags); | 712 | spin_unlock_irqrestore(&queue->irqlock, flags); |
710 | 713 | ||
711 | video->decode(urb, video, buf); | 714 | stream->decode(urb, stream, buf); |
712 | 715 | ||
713 | if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { | 716 | if ((ret = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { |
714 | uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n", | 717 | uvc_printk(KERN_ERR, "Failed to resubmit video URB (%d).\n", |
@@ -719,19 +722,19 @@ static void uvc_video_complete(struct urb *urb) | |||
719 | /* | 722 | /* |
720 | * Free transfer buffers. | 723 | * Free transfer buffers. |
721 | */ | 724 | */ |
722 | static void uvc_free_urb_buffers(struct uvc_video_device *video) | 725 | static void uvc_free_urb_buffers(struct uvc_streaming *stream) |
723 | { | 726 | { |
724 | unsigned int i; | 727 | unsigned int i; |
725 | 728 | ||
726 | for (i = 0; i < UVC_URBS; ++i) { | 729 | for (i = 0; i < UVC_URBS; ++i) { |
727 | if (video->urb_buffer[i]) { | 730 | if (stream->urb_buffer[i]) { |
728 | usb_buffer_free(video->dev->udev, video->urb_size, | 731 | usb_buffer_free(stream->dev->udev, stream->urb_size, |
729 | video->urb_buffer[i], video->urb_dma[i]); | 732 | stream->urb_buffer[i], stream->urb_dma[i]); |
730 | video->urb_buffer[i] = NULL; | 733 | stream->urb_buffer[i] = NULL; |
731 | } | 734 | } |
732 | } | 735 | } |
733 | 736 | ||
734 | video->urb_size = 0; | 737 | stream->urb_size = 0; |
735 | } | 738 | } |
736 | 739 | ||
737 | /* | 740 | /* |
@@ -745,15 +748,15 @@ static void uvc_free_urb_buffers(struct uvc_video_device *video) | |||
745 | * | 748 | * |
746 | * Return the number of allocated packets on success or 0 when out of memory. | 749 | * Return the number of allocated packets on success or 0 when out of memory. |
747 | */ | 750 | */ |
748 | static int uvc_alloc_urb_buffers(struct uvc_video_device *video, | 751 | static int uvc_alloc_urb_buffers(struct uvc_streaming *stream, |
749 | unsigned int size, unsigned int psize, gfp_t gfp_flags) | 752 | unsigned int size, unsigned int psize, gfp_t gfp_flags) |
750 | { | 753 | { |
751 | unsigned int npackets; | 754 | unsigned int npackets; |
752 | unsigned int i; | 755 | unsigned int i; |
753 | 756 | ||
754 | /* Buffers are already allocated, bail out. */ | 757 | /* Buffers are already allocated, bail out. */ |
755 | if (video->urb_size) | 758 | if (stream->urb_size) |
756 | return video->urb_size / psize; | 759 | return stream->urb_size / psize; |
757 | 760 | ||
758 | /* Compute the number of packets. Bulk endpoints might transfer UVC | 761 | /* Compute the number of packets. Bulk endpoints might transfer UVC |
759 | * payloads accross multiple URBs. | 762 | * payloads accross multiple URBs. |
@@ -765,17 +768,17 @@ static int uvc_alloc_urb_buffers(struct uvc_video_device *video, | |||
765 | /* Retry allocations until one succeed. */ | 768 | /* Retry allocations until one succeed. */ |
766 | for (; npackets > 1; npackets /= 2) { | 769 | for (; npackets > 1; npackets /= 2) { |
767 | for (i = 0; i < UVC_URBS; ++i) { | 770 | for (i = 0; i < UVC_URBS; ++i) { |
768 | video->urb_buffer[i] = usb_buffer_alloc( | 771 | stream->urb_buffer[i] = usb_buffer_alloc( |
769 | video->dev->udev, psize * npackets, | 772 | stream->dev->udev, psize * npackets, |
770 | gfp_flags | __GFP_NOWARN, &video->urb_dma[i]); | 773 | gfp_flags | __GFP_NOWARN, &stream->urb_dma[i]); |
771 | if (!video->urb_buffer[i]) { | 774 | if (!stream->urb_buffer[i]) { |
772 | uvc_free_urb_buffers(video); | 775 | uvc_free_urb_buffers(stream); |
773 | break; | 776 | break; |
774 | } | 777 | } |
775 | } | 778 | } |
776 | 779 | ||
777 | if (i == UVC_URBS) { | 780 | if (i == UVC_URBS) { |
778 | video->urb_size = psize * npackets; | 781 | stream->urb_size = psize * npackets; |
779 | return npackets; | 782 | return npackets; |
780 | } | 783 | } |
781 | } | 784 | } |
@@ -786,29 +789,30 @@ static int uvc_alloc_urb_buffers(struct uvc_video_device *video, | |||
786 | /* | 789 | /* |
787 | * Uninitialize isochronous/bulk URBs and free transfer buffers. | 790 | * Uninitialize isochronous/bulk URBs and free transfer buffers. |
788 | */ | 791 | */ |
789 | static void uvc_uninit_video(struct uvc_video_device *video, int free_buffers) | 792 | static void uvc_uninit_video(struct uvc_streaming *stream, int free_buffers) |
790 | { | 793 | { |
791 | struct urb *urb; | 794 | struct urb *urb; |
792 | unsigned int i; | 795 | unsigned int i; |
793 | 796 | ||
794 | for (i = 0; i < UVC_URBS; ++i) { | 797 | for (i = 0; i < UVC_URBS; ++i) { |
795 | if ((urb = video->urb[i]) == NULL) | 798 | urb = stream->urb[i]; |
799 | if (urb == NULL) | ||
796 | continue; | 800 | continue; |
797 | 801 | ||
798 | usb_kill_urb(urb); | 802 | usb_kill_urb(urb); |
799 | usb_free_urb(urb); | 803 | usb_free_urb(urb); |
800 | video->urb[i] = NULL; | 804 | stream->urb[i] = NULL; |
801 | } | 805 | } |
802 | 806 | ||
803 | if (free_buffers) | 807 | if (free_buffers) |
804 | uvc_free_urb_buffers(video); | 808 | uvc_free_urb_buffers(stream); |
805 | } | 809 | } |
806 | 810 | ||
807 | /* | 811 | /* |
808 | * Initialize isochronous URBs and allocate transfer buffers. The packet size | 812 | * Initialize isochronous URBs and allocate transfer buffers. The packet size |
809 | * is given by the endpoint. | 813 | * is given by the endpoint. |
810 | */ | 814 | */ |
811 | static int uvc_init_video_isoc(struct uvc_video_device *video, | 815 | static int uvc_init_video_isoc(struct uvc_streaming *stream, |
812 | struct usb_host_endpoint *ep, gfp_t gfp_flags) | 816 | struct usb_host_endpoint *ep, gfp_t gfp_flags) |
813 | { | 817 | { |
814 | struct urb *urb; | 818 | struct urb *urb; |
@@ -818,9 +822,9 @@ static int uvc_init_video_isoc(struct uvc_video_device *video, | |||
818 | 822 | ||
819 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); | 823 | psize = le16_to_cpu(ep->desc.wMaxPacketSize); |
820 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); | 824 | psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); |
821 | size = video->streaming->ctrl.dwMaxVideoFrameSize; | 825 | size = stream->ctrl.dwMaxVideoFrameSize; |
822 | 826 | ||
823 | npackets = uvc_alloc_urb_buffers(video, size, psize, gfp_flags); | 827 | npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); |
824 | if (npackets == 0) | 828 | if (npackets == 0) |
825 | return -ENOMEM; | 829 | return -ENOMEM; |
826 | 830 | ||
@@ -829,18 +833,18 @@ static int uvc_init_video_isoc(struct uvc_video_device *video, | |||
829 | for (i = 0; i < UVC_URBS; ++i) { | 833 | for (i = 0; i < UVC_URBS; ++i) { |
830 | urb = usb_alloc_urb(npackets, gfp_flags); | 834 | urb = usb_alloc_urb(npackets, gfp_flags); |
831 | if (urb == NULL) { | 835 | if (urb == NULL) { |
832 | uvc_uninit_video(video, 1); | 836 | uvc_uninit_video(stream, 1); |
833 | return -ENOMEM; | 837 | return -ENOMEM; |
834 | } | 838 | } |
835 | 839 | ||
836 | urb->dev = video->dev->udev; | 840 | urb->dev = stream->dev->udev; |
837 | urb->context = video; | 841 | urb->context = stream; |
838 | urb->pipe = usb_rcvisocpipe(video->dev->udev, | 842 | urb->pipe = usb_rcvisocpipe(stream->dev->udev, |
839 | ep->desc.bEndpointAddress); | 843 | ep->desc.bEndpointAddress); |
840 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; | 844 | urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; |
841 | urb->interval = ep->desc.bInterval; | 845 | urb->interval = ep->desc.bInterval; |
842 | urb->transfer_buffer = video->urb_buffer[i]; | 846 | urb->transfer_buffer = stream->urb_buffer[i]; |
843 | urb->transfer_dma = video->urb_dma[i]; | 847 | urb->transfer_dma = stream->urb_dma[i]; |
844 | urb->complete = uvc_video_complete; | 848 | urb->complete = uvc_video_complete; |
845 | urb->number_of_packets = npackets; | 849 | urb->number_of_packets = npackets; |
846 | urb->transfer_buffer_length = size; | 850 | urb->transfer_buffer_length = size; |
@@ -850,7 +854,7 @@ static int uvc_init_video_isoc(struct uvc_video_device *video, | |||
850 | urb->iso_frame_desc[j].length = psize; | 854 | urb->iso_frame_desc[j].length = psize; |
851 | } | 855 | } |
852 | 856 | ||
853 | video->urb[i] = urb; | 857 | stream->urb[i] = urb; |
854 | } | 858 | } |
855 | 859 | ||
856 | return 0; | 860 | return 0; |
@@ -860,7 +864,7 @@ static int uvc_init_video_isoc(struct uvc_video_device *video, | |||
860 | * Initialize bulk URBs and allocate transfer buffers. The packet size is | 864 | * Initialize bulk URBs and allocate transfer buffers. The packet size is |
861 | * given by the endpoint. | 865 | * given by the endpoint. |
862 | */ | 866 | */ |
863 | static int uvc_init_video_bulk(struct uvc_video_device *video, | 867 | static int uvc_init_video_bulk(struct uvc_streaming *stream, |
864 | struct usb_host_endpoint *ep, gfp_t gfp_flags) | 868 | struct usb_host_endpoint *ep, gfp_t gfp_flags) |
865 | { | 869 | { |
866 | struct urb *urb; | 870 | struct urb *urb; |
@@ -869,39 +873,39 @@ static int uvc_init_video_bulk(struct uvc_video_device *video, | |||
869 | u32 size; | 873 | u32 size; |
870 | 874 | ||
871 | psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff; | 875 | psize = le16_to_cpu(ep->desc.wMaxPacketSize) & 0x07ff; |
872 | size = video->streaming->ctrl.dwMaxPayloadTransferSize; | 876 | size = stream->ctrl.dwMaxPayloadTransferSize; |
873 | video->bulk.max_payload_size = size; | 877 | stream->bulk.max_payload_size = size; |
874 | 878 | ||
875 | npackets = uvc_alloc_urb_buffers(video, size, psize, gfp_flags); | 879 | npackets = uvc_alloc_urb_buffers(stream, size, psize, gfp_flags); |
876 | if (npackets == 0) | 880 | if (npackets == 0) |
877 | return -ENOMEM; | 881 | return -ENOMEM; |
878 | 882 | ||
879 | size = npackets * psize; | 883 | size = npackets * psize; |
880 | 884 | ||
881 | if (usb_endpoint_dir_in(&ep->desc)) | 885 | if (usb_endpoint_dir_in(&ep->desc)) |
882 | pipe = usb_rcvbulkpipe(video->dev->udev, | 886 | pipe = usb_rcvbulkpipe(stream->dev->udev, |
883 | ep->desc.bEndpointAddress); | 887 | ep->desc.bEndpointAddress); |
884 | else | 888 | else |
885 | pipe = usb_sndbulkpipe(video->dev->udev, | 889 | pipe = usb_sndbulkpipe(stream->dev->udev, |
886 | ep->desc.bEndpointAddress); | 890 | ep->desc.bEndpointAddress); |
887 | 891 | ||
888 | if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) | 892 | if (stream->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) |
889 | size = 0; | 893 | size = 0; |
890 | 894 | ||
891 | for (i = 0; i < UVC_URBS; ++i) { | 895 | for (i = 0; i < UVC_URBS; ++i) { |
892 | urb = usb_alloc_urb(0, gfp_flags); | 896 | urb = usb_alloc_urb(0, gfp_flags); |
893 | if (urb == NULL) { | 897 | if (urb == NULL) { |
894 | uvc_uninit_video(video, 1); | 898 | uvc_uninit_video(stream, 1); |
895 | return -ENOMEM; | 899 | return -ENOMEM; |
896 | } | 900 | } |
897 | 901 | ||
898 | usb_fill_bulk_urb(urb, video->dev->udev, pipe, | 902 | usb_fill_bulk_urb(urb, stream->dev->udev, pipe, |
899 | video->urb_buffer[i], size, uvc_video_complete, | 903 | stream->urb_buffer[i], size, uvc_video_complete, |
900 | video); | 904 | stream); |
901 | urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; | 905 | urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP; |
902 | urb->transfer_dma = video->urb_dma[i]; | 906 | urb->transfer_dma = stream->urb_dma[i]; |
903 | 907 | ||
904 | video->urb[i] = urb; | 908 | stream->urb[i] = urb; |
905 | } | 909 | } |
906 | 910 | ||
907 | return 0; | 911 | return 0; |
@@ -910,35 +914,35 @@ static int uvc_init_video_bulk(struct uvc_video_device *video, | |||
910 | /* | 914 | /* |
911 | * Initialize isochronous/bulk URBs and allocate transfer buffers. | 915 | * Initialize isochronous/bulk URBs and allocate transfer buffers. |
912 | */ | 916 | */ |
913 | static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags) | 917 | static int uvc_init_video(struct uvc_streaming *stream, gfp_t gfp_flags) |
914 | { | 918 | { |
915 | struct usb_interface *intf = video->streaming->intf; | 919 | struct usb_interface *intf = stream->intf; |
916 | struct usb_host_interface *alts; | 920 | struct usb_host_interface *alts; |
917 | struct usb_host_endpoint *ep = NULL; | 921 | struct usb_host_endpoint *ep = NULL; |
918 | int intfnum = video->streaming->intfnum; | 922 | int intfnum = stream->intfnum; |
919 | unsigned int bandwidth, psize, i; | 923 | unsigned int bandwidth, psize, i; |
920 | int ret; | 924 | int ret; |
921 | 925 | ||
922 | video->last_fid = -1; | 926 | stream->last_fid = -1; |
923 | video->bulk.header_size = 0; | 927 | stream->bulk.header_size = 0; |
924 | video->bulk.skip_payload = 0; | 928 | stream->bulk.skip_payload = 0; |
925 | video->bulk.payload_size = 0; | 929 | stream->bulk.payload_size = 0; |
926 | 930 | ||
927 | if (intf->num_altsetting > 1) { | 931 | if (intf->num_altsetting > 1) { |
928 | /* Isochronous endpoint, select the alternate setting. */ | 932 | /* Isochronous endpoint, select the alternate setting. */ |
929 | bandwidth = video->streaming->ctrl.dwMaxPayloadTransferSize; | 933 | bandwidth = stream->ctrl.dwMaxPayloadTransferSize; |
930 | 934 | ||
931 | if (bandwidth == 0) { | 935 | if (bandwidth == 0) { |
932 | uvc_printk(KERN_WARNING, "device %s requested null " | 936 | uvc_printk(KERN_WARNING, "device %s requested null " |
933 | "bandwidth, defaulting to lowest.\n", | 937 | "bandwidth, defaulting to lowest.\n", |
934 | video->vdev->name); | 938 | stream->dev->name); |
935 | bandwidth = 1; | 939 | bandwidth = 1; |
936 | } | 940 | } |
937 | 941 | ||
938 | for (i = 0; i < intf->num_altsetting; ++i) { | 942 | for (i = 0; i < intf->num_altsetting; ++i) { |
939 | alts = &intf->altsetting[i]; | 943 | alts = &intf->altsetting[i]; |
940 | ep = uvc_find_endpoint(alts, | 944 | ep = uvc_find_endpoint(alts, |
941 | video->streaming->header.bEndpointAddress); | 945 | stream->header.bEndpointAddress); |
942 | if (ep == NULL) | 946 | if (ep == NULL) |
943 | continue; | 947 | continue; |
944 | 948 | ||
@@ -952,18 +956,19 @@ static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags) | |||
952 | if (i >= intf->num_altsetting) | 956 | if (i >= intf->num_altsetting) |
953 | return -EIO; | 957 | return -EIO; |
954 | 958 | ||
955 | if ((ret = usb_set_interface(video->dev->udev, intfnum, i)) < 0) | 959 | ret = usb_set_interface(stream->dev->udev, intfnum, i); |
960 | if (ret < 0) | ||
956 | return ret; | 961 | return ret; |
957 | 962 | ||
958 | ret = uvc_init_video_isoc(video, ep, gfp_flags); | 963 | ret = uvc_init_video_isoc(stream, ep, gfp_flags); |
959 | } else { | 964 | } else { |
960 | /* Bulk endpoint, proceed to URB initialization. */ | 965 | /* Bulk endpoint, proceed to URB initialization. */ |
961 | ep = uvc_find_endpoint(&intf->altsetting[0], | 966 | ep = uvc_find_endpoint(&intf->altsetting[0], |
962 | video->streaming->header.bEndpointAddress); | 967 | stream->header.bEndpointAddress); |
963 | if (ep == NULL) | 968 | if (ep == NULL) |
964 | return -EIO; | 969 | return -EIO; |
965 | 970 | ||
966 | ret = uvc_init_video_bulk(video, ep, gfp_flags); | 971 | ret = uvc_init_video_bulk(stream, ep, gfp_flags); |
967 | } | 972 | } |
968 | 973 | ||
969 | if (ret < 0) | 974 | if (ret < 0) |
@@ -971,10 +976,11 @@ static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags) | |||
971 | 976 | ||
972 | /* Submit the URBs. */ | 977 | /* Submit the URBs. */ |
973 | for (i = 0; i < UVC_URBS; ++i) { | 978 | for (i = 0; i < UVC_URBS; ++i) { |
974 | if ((ret = usb_submit_urb(video->urb[i], gfp_flags)) < 0) { | 979 | ret = usb_submit_urb(stream->urb[i], gfp_flags); |
980 | if (ret < 0) { | ||
975 | uvc_printk(KERN_ERR, "Failed to submit URB %u " | 981 | uvc_printk(KERN_ERR, "Failed to submit URB %u " |
976 | "(%d).\n", i, ret); | 982 | "(%d).\n", i, ret); |
977 | uvc_uninit_video(video, 1); | 983 | uvc_uninit_video(stream, 1); |
978 | return ret; | 984 | return ret; |
979 | } | 985 | } |
980 | } | 986 | } |
@@ -993,14 +999,14 @@ static int uvc_init_video(struct uvc_video_device *video, gfp_t gfp_flags) | |||
993 | * video buffers in any way. We mark the device as frozen to make sure the URB | 999 | * video buffers in any way. We mark the device as frozen to make sure the URB |
994 | * completion handler won't try to cancel the queue when we kill the URBs. | 1000 | * completion handler won't try to cancel the queue when we kill the URBs. |
995 | */ | 1001 | */ |
996 | int uvc_video_suspend(struct uvc_video_device *video) | 1002 | int uvc_video_suspend(struct uvc_streaming *stream) |
997 | { | 1003 | { |
998 | if (!uvc_queue_streaming(&video->queue)) | 1004 | if (!uvc_queue_streaming(&stream->queue)) |
999 | return 0; | 1005 | return 0; |
1000 | 1006 | ||
1001 | video->frozen = 1; | 1007 | stream->frozen = 1; |
1002 | uvc_uninit_video(video, 0); | 1008 | uvc_uninit_video(stream, 0); |
1003 | usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); | 1009 | usb_set_interface(stream->dev->udev, stream->intfnum, 0); |
1004 | return 0; | 1010 | return 0; |
1005 | } | 1011 | } |
1006 | 1012 | ||
@@ -1012,22 +1018,24 @@ int uvc_video_suspend(struct uvc_video_device *video) | |||
1012 | * buffers, making sure userspace applications are notified of the problem | 1018 | * buffers, making sure userspace applications are notified of the problem |
1013 | * instead of waiting forever. | 1019 | * instead of waiting forever. |
1014 | */ | 1020 | */ |
1015 | int uvc_video_resume(struct uvc_video_device *video) | 1021 | int uvc_video_resume(struct uvc_streaming *stream) |
1016 | { | 1022 | { |
1017 | int ret; | 1023 | int ret; |
1018 | 1024 | ||
1019 | video->frozen = 0; | 1025 | stream->frozen = 0; |
1020 | 1026 | ||
1021 | if ((ret = uvc_commit_video(video, &video->streaming->ctrl)) < 0) { | 1027 | ret = uvc_commit_video(stream, &stream->ctrl); |
1022 | uvc_queue_enable(&video->queue, 0); | 1028 | if (ret < 0) { |
1029 | uvc_queue_enable(&stream->queue, 0); | ||
1023 | return ret; | 1030 | return ret; |
1024 | } | 1031 | } |
1025 | 1032 | ||
1026 | if (!uvc_queue_streaming(&video->queue)) | 1033 | if (!uvc_queue_streaming(&stream->queue)) |
1027 | return 0; | 1034 | return 0; |
1028 | 1035 | ||
1029 | if ((ret = uvc_init_video(video, GFP_NOIO)) < 0) | 1036 | ret = uvc_init_video(stream, GFP_NOIO); |
1030 | uvc_queue_enable(&video->queue, 0); | 1037 | if (ret < 0) |
1038 | uvc_queue_enable(&stream->queue, 0); | ||
1031 | 1039 | ||
1032 | return ret; | 1040 | return ret; |
1033 | } | 1041 | } |
@@ -1046,48 +1054,53 @@ int uvc_video_resume(struct uvc_video_device *video) | |||
1046 | * | 1054 | * |
1047 | * This function is called before registering the device with V4L. | 1055 | * This function is called before registering the device with V4L. |
1048 | */ | 1056 | */ |
1049 | int uvc_video_init(struct uvc_video_device *video) | 1057 | int uvc_video_init(struct uvc_streaming *stream) |
1050 | { | 1058 | { |
1051 | struct uvc_streaming_control *probe = &video->streaming->ctrl; | 1059 | struct uvc_streaming_control *probe = &stream->ctrl; |
1052 | struct uvc_format *format = NULL; | 1060 | struct uvc_format *format = NULL; |
1053 | struct uvc_frame *frame = NULL; | 1061 | struct uvc_frame *frame = NULL; |
1054 | unsigned int i; | 1062 | unsigned int i; |
1055 | int ret; | 1063 | int ret; |
1056 | 1064 | ||
1057 | if (video->streaming->nformats == 0) { | 1065 | if (stream->nformats == 0) { |
1058 | uvc_printk(KERN_INFO, "No supported video formats found.\n"); | 1066 | uvc_printk(KERN_INFO, "No supported video formats found.\n"); |
1059 | return -EINVAL; | 1067 | return -EINVAL; |
1060 | } | 1068 | } |
1061 | 1069 | ||
1070 | atomic_set(&stream->active, 0); | ||
1071 | |||
1072 | /* Initialize the video buffers queue. */ | ||
1073 | uvc_queue_init(&stream->queue, stream->type); | ||
1074 | |||
1062 | /* Alternate setting 0 should be the default, yet the XBox Live Vision | 1075 | /* Alternate setting 0 should be the default, yet the XBox Live Vision |
1063 | * Cam (and possibly other devices) crash or otherwise misbehave if | 1076 | * Cam (and possibly other devices) crash or otherwise misbehave if |
1064 | * they don't receive a SET_INTERFACE request before any other video | 1077 | * they don't receive a SET_INTERFACE request before any other video |
1065 | * control request. | 1078 | * control request. |
1066 | */ | 1079 | */ |
1067 | usb_set_interface(video->dev->udev, video->streaming->intfnum, 0); | 1080 | usb_set_interface(stream->dev->udev, stream->intfnum, 0); |
1068 | 1081 | ||
1069 | /* Set the streaming probe control with default streaming parameters | 1082 | /* Set the streaming probe control with default streaming parameters |
1070 | * retrieved from the device. Webcams that don't suport GET_DEF | 1083 | * retrieved from the device. Webcams that don't suport GET_DEF |
1071 | * requests on the probe control will just keep their current streaming | 1084 | * requests on the probe control will just keep their current streaming |
1072 | * parameters. | 1085 | * parameters. |
1073 | */ | 1086 | */ |
1074 | if (uvc_get_video_ctrl(video, probe, 1, UVC_GET_DEF) == 0) | 1087 | if (uvc_get_video_ctrl(stream, probe, 1, UVC_GET_DEF) == 0) |
1075 | uvc_set_video_ctrl(video, probe, 1); | 1088 | uvc_set_video_ctrl(stream, probe, 1); |
1076 | 1089 | ||
1077 | /* Initialize the streaming parameters with the probe control current | 1090 | /* Initialize the streaming parameters with the probe control current |
1078 | * value. This makes sure SET_CUR requests on the streaming commit | 1091 | * value. This makes sure SET_CUR requests on the streaming commit |
1079 | * control will always use values retrieved from a successful GET_CUR | 1092 | * control will always use values retrieved from a successful GET_CUR |
1080 | * request on the probe control, as required by the UVC specification. | 1093 | * request on the probe control, as required by the UVC specification. |
1081 | */ | 1094 | */ |
1082 | ret = uvc_get_video_ctrl(video, probe, 1, UVC_GET_CUR); | 1095 | ret = uvc_get_video_ctrl(stream, probe, 1, UVC_GET_CUR); |
1083 | if (ret < 0) | 1096 | if (ret < 0) |
1084 | return ret; | 1097 | return ret; |
1085 | 1098 | ||
1086 | /* Check if the default format descriptor exists. Use the first | 1099 | /* Check if the default format descriptor exists. Use the first |
1087 | * available format otherwise. | 1100 | * available format otherwise. |
1088 | */ | 1101 | */ |
1089 | for (i = video->streaming->nformats; i > 0; --i) { | 1102 | for (i = stream->nformats; i > 0; --i) { |
1090 | format = &video->streaming->format[i-1]; | 1103 | format = &stream->format[i-1]; |
1091 | if (format->index == probe->bFormatIndex) | 1104 | if (format->index == probe->bFormatIndex) |
1092 | break; | 1105 | break; |
1093 | } | 1106 | } |
@@ -1112,21 +1125,20 @@ int uvc_video_init(struct uvc_video_device *video) | |||
1112 | probe->bFormatIndex = format->index; | 1125 | probe->bFormatIndex = format->index; |
1113 | probe->bFrameIndex = frame->bFrameIndex; | 1126 | probe->bFrameIndex = frame->bFrameIndex; |
1114 | 1127 | ||
1115 | video->streaming->cur_format = format; | 1128 | stream->cur_format = format; |
1116 | video->streaming->cur_frame = frame; | 1129 | stream->cur_frame = frame; |
1117 | atomic_set(&video->active, 0); | ||
1118 | 1130 | ||
1119 | /* Select the video decoding function */ | 1131 | /* Select the video decoding function */ |
1120 | if (video->streaming->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { | 1132 | if (stream->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) { |
1121 | if (video->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) | 1133 | if (stream->dev->quirks & UVC_QUIRK_BUILTIN_ISIGHT) |
1122 | video->decode = uvc_video_decode_isight; | 1134 | stream->decode = uvc_video_decode_isight; |
1123 | else if (video->streaming->intf->num_altsetting > 1) | 1135 | else if (stream->intf->num_altsetting > 1) |
1124 | video->decode = uvc_video_decode_isoc; | 1136 | stream->decode = uvc_video_decode_isoc; |
1125 | else | 1137 | else |
1126 | video->decode = uvc_video_decode_bulk; | 1138 | stream->decode = uvc_video_decode_bulk; |
1127 | } else { | 1139 | } else { |
1128 | if (video->streaming->intf->num_altsetting == 1) | 1140 | if (stream->intf->num_altsetting == 1) |
1129 | video->decode = uvc_video_encode_bulk; | 1141 | stream->decode = uvc_video_encode_bulk; |
1130 | else { | 1142 | else { |
1131 | uvc_printk(KERN_INFO, "Isochronous endpoints are not " | 1143 | uvc_printk(KERN_INFO, "Isochronous endpoints are not " |
1132 | "supported for video output devices.\n"); | 1144 | "supported for video output devices.\n"); |
@@ -1140,31 +1152,32 @@ int uvc_video_init(struct uvc_video_device *video) | |||
1140 | /* | 1152 | /* |
1141 | * Enable or disable the video stream. | 1153 | * Enable or disable the video stream. |
1142 | */ | 1154 | */ |
1143 | int uvc_video_enable(struct uvc_video_device *video, int enable) | 1155 | int uvc_video_enable(struct uvc_streaming *stream, int enable) |
1144 | { | 1156 | { |
1145 | int ret; | 1157 | int ret; |
1146 | 1158 | ||
1147 | if (!enable) { | 1159 | if (!enable) { |
1148 | uvc_uninit_video(video, 1); | 1160 | uvc_uninit_video(stream, 1); |
1149 | usb_set_interface(video->dev->udev, | 1161 | usb_set_interface(stream->dev->udev, stream->intfnum, 0); |
1150 | video->streaming->intfnum, 0); | 1162 | uvc_queue_enable(&stream->queue, 0); |
1151 | uvc_queue_enable(&video->queue, 0); | ||
1152 | return 0; | 1163 | return 0; |
1153 | } | 1164 | } |
1154 | 1165 | ||
1155 | if ((video->streaming->cur_format->flags & UVC_FMT_FLAG_COMPRESSED) || | 1166 | if ((stream->cur_format->flags & UVC_FMT_FLAG_COMPRESSED) || |
1156 | uvc_no_drop_param) | 1167 | uvc_no_drop_param) |
1157 | video->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE; | 1168 | stream->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE; |
1158 | else | 1169 | else |
1159 | video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE; | 1170 | stream->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE; |
1160 | 1171 | ||
1161 | if ((ret = uvc_queue_enable(&video->queue, 1)) < 0) | 1172 | ret = uvc_queue_enable(&stream->queue, 1); |
1173 | if (ret < 0) | ||
1162 | return ret; | 1174 | return ret; |
1163 | 1175 | ||
1164 | /* Commit the streaming parameters. */ | 1176 | /* Commit the streaming parameters. */ |
1165 | if ((ret = uvc_commit_video(video, &video->streaming->ctrl)) < 0) | 1177 | ret = uvc_commit_video(stream, &stream->ctrl); |
1178 | if (ret < 0) | ||
1166 | return ret; | 1179 | return ret; |
1167 | 1180 | ||
1168 | return uvc_init_video(video, GFP_KERNEL); | 1181 | return uvc_init_video(stream, GFP_KERNEL); |
1169 | } | 1182 | } |
1170 | 1183 | ||