|
1 /* |
|
2 * Copyright (c) 2010 ISB. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * ISB - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: USB driver for test |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef WEBCAMERA_UVC_H_ |
|
19 #include "webcamera_uvc.h" |
|
20 #endif |
|
21 |
|
22 #define DP(format...) Kern::Printf(format) |
|
23 |
|
24 //Describe UVC base. |
|
25 |
|
26 /** |
|
27 Constructor. |
|
28 */ |
|
29 DWebCameraUVCDescriptor::DWebCameraUVCDescriptor() |
|
30 { |
|
31 DP("DWebcameraUVCDescriptor::DWebcameraUVCDescriptor construct"); |
|
32 } |
|
33 |
|
34 /** |
|
35 Destructor. |
|
36 */ |
|
37 DWebCameraUVCDescriptor::~DWebCameraUVCDescriptor() |
|
38 { |
|
39 DP("DWebcameraUVCDescriptor::DWebcameraUVCDescriptor destruct"); |
|
40 } |
|
41 |
|
42 /** |
|
43 Describe UVC Descriptor. |
|
44 @param aDataInfo [in] DataInfo from lower layer. |
|
45 @return bDescriptor. |
|
46 */ |
|
47 TWebcameraUVCDescriptor DWebCameraUVCDescriptor::DescribeDescriptor(const TWebcameraDataInfo aDataInfo) |
|
48 { |
|
49 TWebcameraUVCDescriptor bDescriptor; |
|
50 return bDescriptor; |
|
51 } |
|
52 |
|
53 //Describe UVC descriptor YUY2 class. |
|
54 |
|
55 /** |
|
56 Constructor. |
|
57 */ |
|
58 DWebCameraUVCDescribeDescriptorYUY2::DWebCameraUVCDescribeDescriptorYUY2() |
|
59 { |
|
60 DP("DWebCameraUVCDescribeDescriptorYUY2::DWebCameraUVCDescribeDescriptorYUY2 construct"); |
|
61 } |
|
62 |
|
63 /** |
|
64 Destructor. |
|
65 */ |
|
66 DWebCameraUVCDescribeDescriptorYUY2::~DWebCameraUVCDescribeDescriptorYUY2() |
|
67 { |
|
68 DP("DWebCameraUVCDescribeDescriptorYUY2::DWebCameraUVCDescribeDescriptorYUY2 destruct"); |
|
69 } |
|
70 |
|
71 /** |
|
72 Describe UVC Descriptor of YUY2 Format. |
|
73 @param aDataInfo [in] DataInfo from lower layer. |
|
74 @return bDescriptor. |
|
75 */ |
|
76 TWebcameraUVCDescriptor DWebCameraUVCDescribeDescriptorYUY2::DescribeDescriptor(const TWebcameraDataInfo aDataInfo) |
|
77 { |
|
78 DP("DWebcameraUVCDescribeDescriptorYUY2::DescribeDescriptor Start"); |
|
79 //Describe FormatDescriptor Part. |
|
80 TWebcameraUVCDescriptor bDescriptor; |
|
81 |
|
82 bDescriptor.iFormatDescriptor.iLength = 27; |
|
83 bDescriptor.iFormatDescriptor.iDescriptorType = KWebcameraSCVideoStreaming; |
|
84 bDescriptor.iFormatDescriptor.iDescriptorSubType = KWebcameraVSFormatUnconmpressed; |
|
85 |
|
86 //bFormatIndex : First and only format descriptor. |
|
87 //This field is set by the host. |
|
88 bDescriptor.iFormatDescriptor.iFormatIndex = 0x01; |
|
89 |
|
90 bDescriptor.iFormatDescriptor.iNumFrameDescriptor = KWebcameraVSFrameUncompressed; |
|
91 bDescriptor.iFormatDescriptor.iGuid = aDataInfo.iDataFortmat.iSubFormat; |
|
92 bDescriptor.iFormatDescriptor.iBitsPerPixel = aDataInfo.iVideoInfoHeader.iBmiHeader.iBitCount; |
|
93 |
|
94 //bDefaultFrameIndex : Default frame index is 1. |
|
95 bDescriptor.iFormatDescriptor.iDefaultFrameIndex = 0x01; |
|
96 |
|
97 bDescriptor.iFormatDescriptor.iAspectRatioX = 4; |
|
98 |
|
99 bDescriptor.iFormatDescriptor.iAspectRatioY = 3; |
|
100 |
|
101 //InterlaceFlags. //VideoInfoHeader2 dwInterlaceFlags. |
|
102 //No interlaced stream. |
|
103 bDescriptor.iFormatDescriptor.iInterlaceFlags = 0x00; |
|
104 |
|
105 //0: No restrictions. |
|
106 bDescriptor.iFormatDescriptor.iCopyProtect = 0x00; |
|
107 |
|
108 //Describe FrameDescriptor Part. |
|
109 bDescriptor.iFrameDescriptor.iDescriptorType = KWebcameraSCVideoStreaming; |
|
110 bDescriptor.iFrameDescriptor.iDescriptorSubType = KWebcameraVSFrameUncompressed; |
|
111 |
|
112 //First and only frame descriptor. |
|
113 bDescriptor.iFrameDescriptor.iFrameIndex = 0x01; |
|
114 |
|
115 //Still images using capture method 0 are supported at this frame setting.D1: Fixed frame-rate. |
|
116 //D2~D7 reserved. |
|
117 bDescriptor.iFrameDescriptor.iCapabilities = 0x02; |
|
118 |
|
119 bDescriptor.iFrameDescriptor.iWidth = (TUint16)aDataInfo.iVideoInfoHeader.iBmiHeader.iWidth; |
|
120 bDescriptor.iFrameDescriptor.iHeight = (TUint16)aDataInfo.iVideoInfoHeader.iBmiHeader.iHeight; |
|
121 |
|
122 //iDwBitRate = 147456000 = 640 * 480 * 16 * 30(FPS). |
|
123 //bDescriptor.iFrameDescriptor.iMaxBitRate. |
|
124 bDescriptor.iFrameDescriptor.iMaxBitRate = aDataInfo.iVideoInfoHeader.iDwBitRate; |
|
125 //bDescriptor.iFrameDescriptor.iMinBitRate. |
|
126 bDescriptor.iFrameDescriptor.iMinBitRate = aDataInfo.iVideoInfoHeader.iDwBitRate; |
|
127 |
|
128 //bDescriptor.iFrameDescriptor.iMaxVideoFrameBufferSize. |
|
129 //max frame size is 640 * 480 * 2 = 614400. |
|
130 bDescriptor.iFrameDescriptor.iMaxVideoFrameBufferSize = aDataInfo.iVideoInfoHeader.iBmiHeader.iSizeImage; |
|
131 |
|
132 //bDescriptor.iFrameDescriptor.iDefaultFrameInterval. |
|
133 //147456000 / 640 / 480 / 16 = 30(FPS) -> 33.3ms -> 33,333.3ƒÊs -> 333333.3 * 100ns = 333333 = iAvgTimePerFrame. |
|
134 bDescriptor.iFrameDescriptor.iDefaultFrameInterval = (TUint32)aDataInfo.iVideoInfoHeader.iAvgTimePerFrame; |
|
135 |
|
136 //0: Continuous frame interval. |
|
137 bDescriptor.iFrameDescriptor.iFrameIntervalType = 0x00; |
|
138 |
|
139 //bDescriptor.iFrameDescriptor.iLength. |
|
140 if (bDescriptor.iFrameDescriptor.iFrameIntervalType == 0) |
|
141 { |
|
142 bDescriptor.iFrameDescriptor.iFrameInterval.iFrameInterval1 = (TUint32)aDataInfo.iVideoInfoHeader.iAvgTimePerFrame; |
|
143 //highest frame rate. |
|
144 |
|
145 bDescriptor.iFrameDescriptor.iFrameInterval.iFrameInterval2 = (TUint32)aDataInfo.iVideoInfoHeader.iAvgTimePerFrame; |
|
146 //lowest frame rate. |
|
147 |
|
148 bDescriptor.iFrameDescriptor.iFrameInterval.iFrameInterval3 = (TUint32)aDataInfo.iVideoInfoHeader.iAvgTimePerFrame; |
|
149 //Indicates granularity of frame interval range. |
|
150 |
|
151 bDescriptor.iFrameDescriptor.iLength = 38; |
|
152 //iFrameIntervalType = 0 : 38, > 0 : 26+(4*n). |
|
153 } |
|
154 return bDescriptor; |
|
155 } |
|
156 |
|
157 //UVC heder class. |
|
158 |
|
159 /** |
|
160 Constructor. |
|
161 */ |
|
162 DWebCameraUVCHeader::DWebCameraUVCHeader() |
|
163 { |
|
164 DP("DWebCameraUVCHeader::DWebCameraUVCHeader construct"); |
|
165 } |
|
166 |
|
167 /** |
|
168 Destructor. |
|
169 */ |
|
170 DWebCameraUVCHeader::~DWebCameraUVCHeader() |
|
171 { |
|
172 DP("DWebCameraUVCHeader::DWebCameraUVCHeader destruct"); |
|
173 } |
|
174 |
|
175 /** |
|
176 Describe UVC Header. |
|
177 @param aDataInfo [in] Information of data from lower layer. |
|
178 @return bHeader UVC Header descibed. |
|
179 */ |
|
180 TWebcameraUVCHeaderFormat DWebCameraUVCHeader::DescribeHeader(const TWebcameraDataInfo aDataInfo) |
|
181 { |
|
182 TWebcameraDataInfo bDataInfo = aDataInfo; |
|
183 TWebcameraUVCHeaderFormat bHeader; |
|
184 |
|
185 //Describe HeaderInfo to be included UVC Header. |
|
186 bHeader.iHeaderInfo = DescribeHeaderInfo(bDataInfo); |
|
187 |
|
188 //Describe HeaderLength to be included UVC Header if PTS was set. |
|
189 bHeader.iHeaderLength = DescribeHeaderLength(bDataInfo, bHeader.iHeaderInfo); |
|
190 |
|
191 //Describe PresentationTime to be included UVC Header. |
|
192 if ((bHeader.iHeaderInfo & KWebcameraPts) > 0) |
|
193 { |
|
194 bHeader.iPresentationTime = DescribePresentationTime(bDataInfo); |
|
195 } |
|
196 |
|
197 //Describe SourceClockReference to be included UVC Header if SCR was set. |
|
198 if ((bHeader.iHeaderInfo & KWebcameraScr) > 0) |
|
199 { |
|
200 bHeader.iSourceClockReference = DescribeSourceClockReference(bDataInfo); |
|
201 } |
|
202 return bHeader; |
|
203 } |
|
204 |
|
205 /** |
|
206 Describe HeaderInfo of UVC Header. |
|
207 @param aDataInfo [in] DataInfo get from lower layer. |
|
208 @return bHeaderInfo. |
|
209 */ |
|
210 TUint8 DWebCameraUVCHeader::DescribeHeaderInfo(const TWebcameraDataInfo aDataInfo) |
|
211 { |
|
212 TUint8 bHeaderInfo = 0x00; |
|
213 |
|
214 // bHeaderInfo |= KWebcameraEoh; |
|
215 |
|
216 // bHeaderInfo |= KWebcameraErr; |
|
217 |
|
218 // bHeaderInfo |= KWebcameraSti; |
|
219 |
|
220 // bHeaderInfo |= KWebcameraScr; |
|
221 |
|
222 //Case: Set PTS infomation. |
|
223 if (aDataInfo.iVideoInfoHeader.iAvgTimePerFrame != 0) |
|
224 { |
|
225 bHeaderInfo |= KWebcameraPts; |
|
226 } |
|
227 |
|
228 // bHeaderInfo |= KWebcameraEof; |
|
229 |
|
230 //Reversing FID. |
|
231 iFID = ~iFID; |
|
232 iFID &= KWebcameraFid; |
|
233 bHeaderInfo |= iFID; |
|
234 |
|
235 return bHeaderInfo; |
|
236 } |
|
237 |
|
238 /** |
|
239 Describe HeaderLength to be included UVC Header. |
|
240 @param aDataInfo [in] Information of data from lower layer. |
|
241 aHeaderInfo [in] HeaderInfo to be included UVC Header. |
|
242 @return bHeaderLength. |
|
243 */ |
|
244 TUint8 DWebCameraUVCHeader::DescribeHeaderLength(const TWebcameraDataInfo aDataInfo, TUint8 aHeaderInfo) |
|
245 { |
|
246 TUint8 bHeaderLength; |
|
247 bHeaderLength = 2; |
|
248 |
|
249 //Get information of PTS . |
|
250 if ((aHeaderInfo & KWebcameraPts) > 0) |
|
251 { |
|
252 bHeaderLength += 4; |
|
253 } |
|
254 |
|
255 //Get information of SCR. |
|
256 if ((aHeaderInfo & KWebcameraScr) > 0) |
|
257 { |
|
258 bHeaderLength += 6; |
|
259 } |
|
260 |
|
261 return bHeaderLength; |
|
262 } |
|
263 |
|
264 /** |
|
265 Describe PresentationTime to be included UVC Header. |
|
266 @param @param aDataInfo [in] Information of Data from lower layer. |
|
267 @return bPresentationTime. |
|
268 */ |
|
269 TUint32 DWebCameraUVCHeader::DescribePresentationTime(const TWebcameraDataInfo aDataInfo) |
|
270 { |
|
271 TUint32 bPresentationTime; |
|
272 //Substitution information of AvgTimePerFrame for PresentationTime. |
|
273 bPresentationTime = (TUint32)aDataInfo.iVideoInfoHeader.iAvgTimePerFrame; |
|
274 |
|
275 return bPresentationTime; |
|
276 } |
|
277 |
|
278 /** |
|
279 Describe SourceClockReference to be included UVC Header. |
|
280 @param aDataInfo [in] Information of data from lower layer. |
|
281 @return bSourceClockReference. |
|
282 */ |
|
283 TWebcameraUVCSourceClockReference DWebCameraUVCHeader::DescribeSourceClockReference(const TWebcameraDataInfo aDataInfo) |
|
284 { |
|
285 TWebcameraUVCSourceClockReference bSourceClockReference; |
|
286 //Substitute information of TokenCounter for iTokenCounter. |
|
287 bSourceClockReference.iTokenCounter = 0x0000; |
|
288 bSourceClockReference.iTokenCounter &= KWebcameraTokenCounter; |
|
289 |
|
290 //Substitute information of SourceTimeClock for iSourceTimeClock. |
|
291 // bSourceClockReference.iSourceTimeClock = (TUint32) aSourceTimeClock; |
|
292 |
|
293 return bSourceClockReference; |
|
294 } |
|
295 |
|
296 //Describe class. |
|
297 |
|
298 /** |
|
299 Constructor. |
|
300 */ |
|
301 DWebCameraDescribe::DWebCameraDescribe() |
|
302 { |
|
303 DP("DWebCameraDescribe::DWebCameraDescribe construct"); |
|
304 } |
|
305 |
|
306 /** |
|
307 Destructor. |
|
308 */ |
|
309 DWebCameraDescribe::~DWebCameraDescribe() |
|
310 { |
|
311 delete iDescribe; |
|
312 DP("DWebCameraDescribe::DWebCameraDescribe destruct"); |
|
313 } |
|
314 |
|
315 /** |
|
316 Parse iDataInfo from lower layer and describe UVC Header and Descriptor. |
|
317 @param aDataInfo [in] Information of data from lower layer. |
|
318 @return bUVC. |
|
319 */ |
|
320 TWebcameraUVC DWebCameraDescribe::ParseDataInfo(const TWebcameraDataInfo aDataInfo) |
|
321 { |
|
322 TWebcameraDataInfo bDataInfo = aDataInfo; |
|
323 TWebcameraUVC bUvc; |
|
324 |
|
325 //Describe UVC Header. |
|
326 DWebCameraUVCHeader* bHeader; |
|
327 bHeader = new DWebCameraUVCHeader; |
|
328 bUvc.iUVCHeader = bHeader->DescribeHeader(bDataInfo); |
|
329 delete bHeader; |
|
330 |
|
331 //If MajorFormat equal KWebcameraVideoStream, this format is VideoStream. |
|
332 if (bDataInfo.iDataFortmat.iMajorFormat.iData1 == KWebcameraVideoStream) |
|
333 { |
|
334 //Discriminate by SubFormat. |
|
335 switch (bDataInfo.iDataFortmat.iSubFormat.iData1) |
|
336 { |
|
337 //Case of YUY2 Format. |
|
338 case KWebcameraYuy2: |
|
339 iDescribe = new DWebCameraUVCDescribeDescriptorYUY2; |
|
340 break; |
|
341 |
|
342 //Case of default. |
|
343 default: |
|
344 //No format that discriminated. |
|
345 break; |
|
346 } |
|
347 //Describe UVC Descriptor. |
|
348 bUvc.iUVCDescriptor = iDescribe->DescribeDescriptor(bDataInfo); |
|
349 } |
|
350 |
|
351 return bUvc; |
|
352 } |