|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the Qt Mobility Components. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 //#include <QtGui/qx11info_x11.h> |
|
43 #include <QtMultimedia/qvideosurfaceformat.h> |
|
44 |
|
45 #include "s60videosurface.h" |
|
46 |
|
47 /*struct XvFormatRgb |
|
48 { |
|
49 QVideoFrame::PixelFormat pixelFormat; |
|
50 int bits_per_pixel; |
|
51 int format; |
|
52 int num_planes; |
|
53 |
|
54 int depth; |
|
55 unsigned int red_mask; |
|
56 unsigned int green_mask; |
|
57 unsigned int blue_mask; |
|
58 |
|
59 };*/ |
|
60 /* |
|
61 bool operator ==(const XvImageFormatValues &format, const XvFormatRgb &rgb) |
|
62 { |
|
63 return format.type == XvRGB |
|
64 && format.bits_per_pixel == rgb.bits_per_pixel |
|
65 && format.format == rgb.format |
|
66 && format.num_planes == rgb.num_planes |
|
67 && format.depth == rgb.depth |
|
68 && format.red_mask == rgb.red_mask |
|
69 && format.blue_mask == rgb.blue_mask; |
|
70 } |
|
71 |
|
72 static const XvFormatRgb qt_xvRgbLookup[] = |
|
73 { |
|
74 { QVideoFrame::Format_ARGB32, 32, XvPacked, 1, 32, 0x00FF0000, 0x0000FF00, 0x000000FF }, |
|
75 { QVideoFrame::Format_RGB32 , 32, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, |
|
76 { QVideoFrame::Format_RGB24 , 24, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, |
|
77 { QVideoFrame::Format_RGB565, 16, XvPacked, 1, 16, 0x0000F800, 0x000007E0, 0x0000001F }, |
|
78 { QVideoFrame::Format_BGRA32, 32, XvPacked, 1, 32, 0xFF000000, 0x00FF0000, 0x0000FF00 }, |
|
79 { QVideoFrame::Format_BGR32 , 32, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, |
|
80 { QVideoFrame::Format_BGR24 , 24, XvPacked, 1, 24, 0x00FF0000, 0x0000FF00, 0x000000FF }, |
|
81 { QVideoFrame::Format_BGR565, 16, XvPacked, 1, 16, 0x0000F800, 0x000007E0, 0x0000001F } |
|
82 }; |
|
83 |
|
84 struct XvFormatYuv |
|
85 { |
|
86 QVideoFrame::PixelFormat pixelFormat; |
|
87 int bits_per_pixel; |
|
88 int format; |
|
89 int num_planes; |
|
90 |
|
91 unsigned int y_sample_bits; |
|
92 unsigned int u_sample_bits; |
|
93 unsigned int v_sample_bits; |
|
94 unsigned int horz_y_period; |
|
95 unsigned int horz_u_period; |
|
96 unsigned int horz_v_period; |
|
97 unsigned int vert_y_period; |
|
98 unsigned int vert_u_period; |
|
99 unsigned int vert_v_period; |
|
100 char component_order[32]; |
|
101 }; |
|
102 |
|
103 bool operator ==(const XvImageFormatValues &format, const XvFormatYuv &yuv) |
|
104 { |
|
105 return format.type == XvYUV |
|
106 && format.bits_per_pixel == yuv.bits_per_pixel |
|
107 && format.format == yuv.format |
|
108 && format.num_planes == yuv.num_planes |
|
109 && format.y_sample_bits == yuv.y_sample_bits |
|
110 && format.u_sample_bits == yuv.u_sample_bits |
|
111 && format.v_sample_bits == yuv.v_sample_bits |
|
112 && format.horz_y_period == yuv.horz_y_period |
|
113 && format.horz_u_period == yuv.horz_u_period |
|
114 && format.horz_v_period == yuv.horz_v_period |
|
115 && format.horz_y_period == yuv.vert_y_period |
|
116 && format.vert_u_period == yuv.vert_u_period |
|
117 && format.vert_v_period == yuv.vert_v_period |
|
118 && qstrncmp(format.component_order, yuv.component_order, 32) == 0; |
|
119 } |
|
120 |
|
121 static const XvFormatYuv qt_xvYuvLookup[] = |
|
122 { |
|
123 { QVideoFrame::Format_YUV444 , 24, XvPacked, 1, 8, 8, 8, 1, 1, 1, 1, 1, 1, "YUV" }, |
|
124 { QVideoFrame::Format_YUV420P, 12, XvPlanar, 3, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YUV" }, |
|
125 { QVideoFrame::Format_YV12 , 12, XvPlanar, 3, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YVU" }, |
|
126 { QVideoFrame::Format_UYVY , 16, XvPacked, 1, 8, 8, 8, 1, 2, 2, 1, 1, 1, "UYVY" }, |
|
127 { QVideoFrame::Format_YUYV , 16, XvPacked, 1, 8, 8, 8, 1, 2, 2, 1, 1, 1, "YUYV" }, |
|
128 { QVideoFrame::Format_NV12 , 12, XvPlanar, 2, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YUV" }, |
|
129 { QVideoFrame::Format_NV12 , 12, XvPlanar, 2, 8, 8, 8, 1, 2, 2, 1, 2, 2, "YVU" }, |
|
130 { QVideoFrame::Format_Y8 , 8 , XvPlanar, 1, 8, 0, 0, 1, 0, 0, 1, 0, 0, "Y" } |
|
131 }; |
|
132 */ |
|
133 |
|
134 S60VideoSurface::S60VideoSurface(QObject *parent) |
|
135 : QAbstractVideoSurface(parent) |
|
136 , m_winId(0) |
|
137 //, m_portId(0) |
|
138 //, m_gc(0) |
|
139 //, m_image(0) |
|
140 { |
|
141 } |
|
142 |
|
143 S60VideoSurface::~S60VideoSurface() |
|
144 { |
|
145 /*if (m_gc) |
|
146 XFreeGC(QX11Info::display(), m_gc); |
|
147 |
|
148 if (m_portId != 0) |
|
149 XvUngrabPort(QX11Info::display(), m_portId, 0); |
|
150 */ |
|
151 } |
|
152 |
|
153 WId S60VideoSurface::winId() const |
|
154 { |
|
155 return m_winId; |
|
156 } |
|
157 |
|
158 void S60VideoSurface::setWinId(WId id) |
|
159 { |
|
160 /*if (id == m_winId) |
|
161 return; |
|
162 |
|
163 if (m_image) |
|
164 XFree(m_image); |
|
165 |
|
166 if (m_gc) { |
|
167 XFreeGC(QX11Info::display(), m_gc); |
|
168 m_gc = 0; |
|
169 } |
|
170 |
|
171 if (m_portId != 0) |
|
172 XvUngrabPort(QX11Info::display(), m_portId, 0); |
|
173 |
|
174 m_supportedPixelFormats.clear(); |
|
175 m_formatIds.clear(); |
|
176 |
|
177 m_winId = id; |
|
178 |
|
179 if (m_winId && findPort()) { |
|
180 querySupportedFormats(); |
|
181 |
|
182 m_gc = XCreateGC(QX11Info::display(), m_winId, 0, 0); |
|
183 |
|
184 if (m_image) { |
|
185 m_image = 0; |
|
186 |
|
187 if (!start(surfaceFormat())) |
|
188 QAbstractVideoSurface::stop(); |
|
189 } |
|
190 } else if (m_image) { |
|
191 m_image = 0; |
|
192 |
|
193 QAbstractVideoSurface::stop(); |
|
194 }*/ |
|
195 } |
|
196 |
|
197 QRect S60VideoSurface::displayRect() const |
|
198 { |
|
199 return m_displayRect; |
|
200 } |
|
201 |
|
202 void S60VideoSurface::setDisplayRect(const QRect &rect) |
|
203 { |
|
204 m_displayRect = rect; |
|
205 } |
|
206 |
|
207 int S60VideoSurface::brightness() const |
|
208 { |
|
209 //return getAttribute("XV_BRIGHTNESS", m_brightnessRange.first, m_brightnessRange.second); |
|
210 } |
|
211 |
|
212 void S60VideoSurface::setBrightness(int brightness) |
|
213 { |
|
214 //setAttribute("XV_BRIGHTNESS", brightness, m_brightnessRange.first, m_brightnessRange.second); |
|
215 } |
|
216 |
|
217 int S60VideoSurface::contrast() const |
|
218 { |
|
219 //return getAttribute("XV_CONTRAST", m_contrastRange.first, m_contrastRange.second); |
|
220 } |
|
221 |
|
222 void S60VideoSurface::setContrast(int contrast) |
|
223 { |
|
224 //setAttribute("XV_CONTRAST", contrast, m_contrastRange.first, m_contrastRange.second); |
|
225 } |
|
226 |
|
227 int S60VideoSurface::hue() const |
|
228 { |
|
229 //return getAttribute("XV_HUE", m_hueRange.first, m_hueRange.second); |
|
230 } |
|
231 |
|
232 void S60VideoSurface::setHue(int hue) |
|
233 { |
|
234 // setAttribute("XV_HUE", hue, m_hueRange.first, m_hueRange.second); |
|
235 } |
|
236 |
|
237 int S60VideoSurface::saturation() const |
|
238 { |
|
239 //return getAttribute("XV_SATURATION", m_saturationRange.first, m_saturationRange.second); |
|
240 } |
|
241 |
|
242 void S60VideoSurface::setSaturation(int saturation) |
|
243 { |
|
244 //setAttribute("XV_SATURATION", saturation, m_saturationRange.first, m_saturationRange.second); |
|
245 } |
|
246 |
|
247 int S60VideoSurface::getAttribute(const char *attribute, int minimum, int maximum) const |
|
248 { |
|
249 /*if (m_portId != 0) { |
|
250 Display *display = QX11Info::display(); |
|
251 |
|
252 Atom atom = XInternAtom(display, attribute, True); |
|
253 |
|
254 int value = 0; |
|
255 |
|
256 XvGetPortAttribute(display, m_portId, atom, &value); |
|
257 |
|
258 return redistribute(value, minimum, maximum, -100, 100); |
|
259 } else { |
|
260 return 0; |
|
261 }*/ |
|
262 } |
|
263 |
|
264 void S60VideoSurface::setAttribute(const char *attribute, int value, int minimum, int maximum) |
|
265 { |
|
266 /* if (m_portId != 0) { |
|
267 Display *display = QX11Info::display(); |
|
268 |
|
269 Atom atom = XInternAtom(display, attribute, True); |
|
270 |
|
271 XvSetPortAttribute( |
|
272 display, m_portId, atom, redistribute(value, -100, 100, minimum, maximum)); |
|
273 }*/ |
|
274 } |
|
275 |
|
276 int S60VideoSurface::redistribute( |
|
277 int value, int fromLower, int fromUpper, int toLower, int toUpper) |
|
278 { |
|
279 /*return fromUpper != fromLower |
|
280 ? ((value - fromLower) * (toUpper - toLower) / (fromUpper - fromLower)) + toLower |
|
281 : 0;*/ |
|
282 } |
|
283 |
|
284 QList<QVideoFrame::PixelFormat> S60VideoSurface::supportedPixelFormats( |
|
285 QAbstractVideoBuffer::HandleType handleType) const |
|
286 { |
|
287 /*return handleType == QAbstractVideoBuffer::NoHandle |
|
288 ? m_supportedPixelFormats |
|
289 : QList<QVideoFrame::PixelFormat>();*/ |
|
290 } |
|
291 |
|
292 bool S60VideoSurface::start(const QVideoSurfaceFormat &format) |
|
293 { |
|
294 /*if (m_image) |
|
295 XFree(m_image); |
|
296 |
|
297 int xvFormatId = 0; |
|
298 for (int i = 0; i < m_supportedPixelFormats.count(); ++i) { |
|
299 if (m_supportedPixelFormats.at(i) == format.pixelFormat()) { |
|
300 xvFormatId = m_formatIds.at(i); |
|
301 break; |
|
302 } |
|
303 } |
|
304 |
|
305 if (xvFormatId == 0) { |
|
306 setError(UnsupportedFormatError); |
|
307 } else { |
|
308 XvImage *image = XvCreateImage( |
|
309 QX11Info::display(), |
|
310 m_portId, |
|
311 xvFormatId, |
|
312 0, |
|
313 format.frameWidth(), |
|
314 format.frameHeight()); |
|
315 |
|
316 if (!image) { |
|
317 setError(ResourceError); |
|
318 } else { |
|
319 m_viewport = format.viewport(); |
|
320 m_image = image; |
|
321 |
|
322 return QAbstractVideoSurface::start(format); |
|
323 } |
|
324 } |
|
325 |
|
326 if (m_image) { |
|
327 m_image = 0; |
|
328 |
|
329 QAbstractVideoSurface::stop(); |
|
330 } |
|
331 */ |
|
332 return false; |
|
333 } |
|
334 |
|
335 void S60VideoSurface::stop() |
|
336 {/* |
|
337 if (m_image) { |
|
338 XFree(m_image); |
|
339 m_image = 0; |
|
340 |
|
341 QAbstractVideoSurface::stop(); |
|
342 }*/ |
|
343 } |
|
344 |
|
345 bool S60VideoSurface::present(const QVideoFrame &frame) |
|
346 {/* |
|
347 if (!m_image) { |
|
348 setError(StoppedError); |
|
349 return false; |
|
350 } else if (m_image->width != frame.width() || m_image->height != frame.height()) { |
|
351 setError(IncorrectFormatError); |
|
352 return false; |
|
353 } else { |
|
354 QVideoFrame frameCopy(frame); |
|
355 |
|
356 if (!frameCopy.map(QAbstractVideoBuffer::ReadOnly)) { |
|
357 setError(IncorrectFormatError); |
|
358 return false; |
|
359 } else { |
|
360 bool presented = false; |
|
361 |
|
362 if (m_image->data_size > frame.numBytes()) { |
|
363 qWarning("Insufficient frame buffer size"); |
|
364 setError(IncorrectFormatError); |
|
365 } else if (m_image->num_planes > 0 && m_image->pitches[0] != frame.bytesPerLine()) { |
|
366 qWarning("Incompatible frame pitches"); |
|
367 setError(IncorrectFormatError); |
|
368 } else { |
|
369 m_image->data = reinterpret_cast<char *>(frameCopy.bits()); |
|
370 |
|
371 XvPutImage( |
|
372 QX11Info::display(), |
|
373 m_portId, |
|
374 m_winId, |
|
375 m_gc, |
|
376 m_image, |
|
377 m_viewport.x(), |
|
378 m_viewport.y(), |
|
379 m_viewport.width(), |
|
380 m_viewport.height(), |
|
381 m_displayRect.x(), |
|
382 m_displayRect.y(), |
|
383 m_displayRect.width(), |
|
384 m_displayRect.height()); |
|
385 |
|
386 m_image->data = 0; |
|
387 |
|
388 presented = true; |
|
389 } |
|
390 |
|
391 frameCopy.unmap(); |
|
392 |
|
393 return presented; |
|
394 } |
|
395 }*/ |
|
396 } |
|
397 |
|
398 bool S60VideoSurface::findPort() |
|
399 {/* |
|
400 unsigned int count = 0; |
|
401 XvAdaptorInfo *adaptors = 0; |
|
402 bool portFound = false; |
|
403 |
|
404 if (XvQueryAdaptors(QX11Info::display(), m_winId, &count, &adaptors) == Success) { |
|
405 for (unsigned int i = 0; i < count && !portFound; ++i) { |
|
406 if (adaptors[i].type & XvImageMask) { |
|
407 m_portId = adaptors[i].base_id; |
|
408 |
|
409 for (unsigned int j = 0; j < adaptors[i].num_ports && !portFound; ++j, ++m_portId) |
|
410 portFound = XvGrabPort(QX11Info::display(), m_portId, 0) == Success; |
|
411 } |
|
412 } |
|
413 XvFreeAdaptorInfo(adaptors); |
|
414 } |
|
415 |
|
416 return portFound;*/ |
|
417 } |
|
418 |
|
419 void S60VideoSurface::querySupportedFormats() |
|
420 {/* |
|
421 int count = 0; |
|
422 if (XvImageFormatValues *imageFormats = XvListImageFormats( |
|
423 QX11Info::display(), m_portId, &count)) { |
|
424 const int rgbCount = sizeof(qt_xvRgbLookup) / sizeof(XvFormatRgb); |
|
425 const int yuvCount = sizeof(qt_xvYuvLookup) / sizeof(XvFormatYuv); |
|
426 |
|
427 for (int i = 0; i < count; ++i) { |
|
428 switch (imageFormats[i].type) { |
|
429 case XvRGB: |
|
430 for (int j = 0; j < rgbCount; ++j) { |
|
431 if (imageFormats[i] == qt_xvRgbLookup[j]) { |
|
432 m_supportedPixelFormats.append(qt_xvRgbLookup[j].pixelFormat); |
|
433 m_formatIds.append(imageFormats[i].id); |
|
434 break; |
|
435 } |
|
436 } |
|
437 break; |
|
438 case XvYUV: |
|
439 for (int j = 0; j < yuvCount; ++j) { |
|
440 if (imageFormats[i] == qt_xvYuvLookup[j]) { |
|
441 m_supportedPixelFormats.append(qt_xvYuvLookup[j].pixelFormat); |
|
442 m_formatIds.append(imageFormats[i].id); |
|
443 break; |
|
444 } |
|
445 } |
|
446 break; |
|
447 } |
|
448 } |
|
449 XFree(imageFormats); |
|
450 } |
|
451 |
|
452 m_brightnessRange = qMakePair(0, 0); |
|
453 m_contrastRange = qMakePair(0, 0); |
|
454 m_hueRange = qMakePair(0, 0); |
|
455 m_saturationRange = qMakePair(0, 0); |
|
456 |
|
457 if (XvAttribute *attributes = XvQueryPortAttributes(QX11Info::display(), m_portId, &count)) { |
|
458 for (int i = 0; i < count; ++i) { |
|
459 if (qstrcmp(attributes[i].name, "XV_BRIGHTNESS") == 0) |
|
460 m_brightnessRange = qMakePair(attributes[i].min_value, attributes[i].max_value); |
|
461 else if (qstrcmp(attributes[i].name, "XV_CONTRAST") == 0) |
|
462 m_contrastRange = qMakePair(attributes[i].min_value, attributes[i].max_value); |
|
463 else if (qstrcmp(attributes[i].name, "XV_HUE") == 0) |
|
464 m_hueRange = qMakePair(attributes[i].min_value, attributes[i].max_value); |
|
465 else if (qstrcmp(attributes[i].name, "XV_SATURATION") == 0) |
|
466 m_saturationRange = qMakePair(attributes[i].min_value, attributes[i].max_value); |
|
467 } |
|
468 |
|
469 XFree(attributes); |
|
470 }*/ |
|
471 } |
|
472 |
|
473 bool S60VideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const |
|
474 { |
|
475 } |