1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/usb.h>
17#include <linux/kernel.h>
18#include <linux/mm.h>
19
20#include "uvcvideo.h"
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39static int isight_decode(struct uvc_video_queue *queue, struct uvc_buffer *buf,
40 const __u8 *data, unsigned int len)
41{
42 static const __u8 hdr[] = {
43 0x11, 0x22, 0x33, 0x44,
44 0xde, 0xad, 0xbe, 0xef,
45 0xde, 0xad, 0xfa, 0xce
46 };
47
48 unsigned int maxlen, nbytes;
49 __u8 *mem;
50 int is_header = 0;
51
52 if (buf == NULL)
53 return 0;
54
55 if ((len >= 14 && memcmp(&data[2], hdr, 12) == 0) ||
56 (len >= 15 && memcmp(&data[3], hdr, 12) == 0)) {
57 uvc_trace(UVC_TRACE_FRAME, "iSight header found\n");
58 is_header = 1;
59 }
60
61
62 if (buf->state != UVC_BUF_STATE_ACTIVE) {
63 if (!is_header) {
64 uvc_trace(UVC_TRACE_FRAME, "Dropping packet (out of "
65 "sync).\n");
66 return 0;
67 }
68
69 buf->state = UVC_BUF_STATE_ACTIVE;
70 }
71
72
73
74
75
76
77 if (is_header && buf->bytesused != 0) {
78 buf->state = UVC_BUF_STATE_DONE;
79 return -EAGAIN;
80 }
81
82
83
84
85 if (!is_header) {
86 maxlen = buf->length - buf->bytesused;
87 mem = buf->mem + buf->bytesused;
88 nbytes = min(len, maxlen);
89 memcpy(mem, data, nbytes);
90 buf->bytesused += nbytes;
91
92 if (len > maxlen || buf->bytesused == buf->length) {
93 uvc_trace(UVC_TRACE_FRAME, "Frame complete "
94 "(overflow).\n");
95 buf->state = UVC_BUF_STATE_DONE;
96 }
97 }
98
99 return 0;
100}
101
102void uvc_video_decode_isight(struct urb *urb, struct uvc_streaming *stream,
103 struct uvc_buffer *buf)
104{
105 int ret, i;
106
107 for (i = 0; i < urb->number_of_packets; ++i) {
108 if (urb->iso_frame_desc[i].status < 0) {
109 uvc_trace(UVC_TRACE_FRAME, "USB isochronous frame "
110 "lost (%d).\n",
111 urb->iso_frame_desc[i].status);
112 }
113
114
115
116
117
118
119
120
121
122 do {
123 ret = isight_decode(&stream->queue, buf,
124 urb->transfer_buffer +
125 urb->iso_frame_desc[i].offset,
126 urb->iso_frame_desc[i].actual_length);
127
128 if (buf == NULL)
129 break;
130
131 if (buf->state == UVC_BUF_STATE_DONE ||
132 buf->state == UVC_BUF_STATE_ERROR)
133 buf = uvc_queue_next_buffer(&stream->queue,
134 buf);
135 } while (ret == -EAGAIN);
136 }
137}
138