37 ** |
37 ** |
38 ** $QT_END_LICENSE$ |
38 ** $QT_END_LICENSE$ |
39 ** |
39 ** |
40 ****************************************************************************/ |
40 ****************************************************************************/ |
41 |
41 |
42 //#include <QtGui/qx11info_x11.h> |
42 #include <qvideosurfaceformat.h> |
43 #include <QtMultimedia/qvideosurfaceformat.h> |
|
44 |
43 |
45 #include "s60videosurface.h" |
44 #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 |
45 |
134 S60VideoSurface::S60VideoSurface(QObject *parent) |
46 S60VideoSurface::S60VideoSurface(QObject *parent) |
135 : QAbstractVideoSurface(parent) |
47 : QAbstractVideoSurface(parent) |
136 , m_winId(0) |
48 , m_winId(0) |
137 //, m_portId(0) |
|
138 //, m_gc(0) |
|
139 //, m_image(0) |
|
140 { |
49 { |
141 } |
50 } |
142 |
51 |
143 S60VideoSurface::~S60VideoSurface() |
52 S60VideoSurface::~S60VideoSurface() |
144 { |
53 { |
145 /*if (m_gc) |
|
146 XFreeGC(QX11Info::display(), m_gc); |
|
147 |
54 |
148 if (m_portId != 0) |
|
149 XvUngrabPort(QX11Info::display(), m_portId, 0); |
|
150 */ |
|
151 } |
55 } |
152 |
56 |
153 WId S60VideoSurface::winId() const |
57 WId S60VideoSurface::winId() const |
154 { |
58 { |
155 return m_winId; |
59 return m_winId; |
156 } |
60 } |
157 |
61 |
158 void S60VideoSurface::setWinId(WId id) |
62 void S60VideoSurface::setWinId(WId id) |
159 { |
63 { |
160 /*if (id == m_winId) |
64 Q_UNUSED(id); |
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 } |
65 } |
196 |
66 |
197 QRect S60VideoSurface::displayRect() const |
67 QRect S60VideoSurface::displayRect() const |
198 { |
68 { |
199 return m_displayRect; |
69 return m_displayRect; |
204 m_displayRect = rect; |
74 m_displayRect = rect; |
205 } |
75 } |
206 |
76 |
207 int S60VideoSurface::brightness() const |
77 int S60VideoSurface::brightness() const |
208 { |
78 { |
209 //return getAttribute("XV_BRIGHTNESS", m_brightnessRange.first, m_brightnessRange.second); |
79 return 0; |
210 } |
80 } |
211 |
81 |
212 void S60VideoSurface::setBrightness(int brightness) |
82 void S60VideoSurface::setBrightness(int brightness) |
213 { |
83 { |
214 //setAttribute("XV_BRIGHTNESS", brightness, m_brightnessRange.first, m_brightnessRange.second); |
84 Q_UNUSED(brightness); |
215 } |
85 } |
216 |
86 |
217 int S60VideoSurface::contrast() const |
87 int S60VideoSurface::contrast() const |
218 { |
88 { |
219 //return getAttribute("XV_CONTRAST", m_contrastRange.first, m_contrastRange.second); |
89 return 0; |
220 } |
90 } |
221 |
91 |
222 void S60VideoSurface::setContrast(int contrast) |
92 void S60VideoSurface::setContrast(int contrast) |
223 { |
93 { |
224 //setAttribute("XV_CONTRAST", contrast, m_contrastRange.first, m_contrastRange.second); |
94 Q_UNUSED(contrast); |
225 } |
95 } |
226 |
96 |
227 int S60VideoSurface::hue() const |
97 int S60VideoSurface::hue() const |
228 { |
98 { |
229 //return getAttribute("XV_HUE", m_hueRange.first, m_hueRange.second); |
99 return 0; |
230 } |
100 } |
231 |
101 |
232 void S60VideoSurface::setHue(int hue) |
102 void S60VideoSurface::setHue(int hue) |
233 { |
103 { |
234 // setAttribute("XV_HUE", hue, m_hueRange.first, m_hueRange.second); |
104 Q_UNUSED(hue); |
235 } |
105 } |
236 |
106 |
237 int S60VideoSurface::saturation() const |
107 int S60VideoSurface::saturation() const |
238 { |
108 { |
239 //return getAttribute("XV_SATURATION", m_saturationRange.first, m_saturationRange.second); |
109 return 0; |
240 } |
110 } |
241 |
111 |
242 void S60VideoSurface::setSaturation(int saturation) |
112 void S60VideoSurface::setSaturation(int saturation) |
243 { |
113 { |
244 //setAttribute("XV_SATURATION", saturation, m_saturationRange.first, m_saturationRange.second); |
114 Q_UNUSED(saturation); |
245 } |
115 } |
246 |
116 |
247 int S60VideoSurface::getAttribute(const char *attribute, int minimum, int maximum) const |
117 int S60VideoSurface::getAttribute(const char *attribute, int minimum, int maximum) const |
248 { |
118 { |
249 /*if (m_portId != 0) { |
119 Q_UNUSED(attribute); |
250 Display *display = QX11Info::display(); |
120 Q_UNUSED(minimum); |
251 |
121 Q_UNUSED(maximum); |
252 Atom atom = XInternAtom(display, attribute, True); |
122 return 0; |
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 } |
123 } |
263 |
124 |
264 void S60VideoSurface::setAttribute(const char *attribute, int value, int minimum, int maximum) |
125 void S60VideoSurface::setAttribute(const char *attribute, int value, int minimum, int maximum) |
265 { |
126 { |
266 /* if (m_portId != 0) { |
127 Q_UNUSED(attribute); |
267 Display *display = QX11Info::display(); |
128 Q_UNUSED(value); |
|
129 Q_UNUSED(minimum); |
|
130 Q_UNUSED(maximum); |
268 |
131 |
269 Atom atom = XInternAtom(display, attribute, True); |
|
270 |
|
271 XvSetPortAttribute( |
|
272 display, m_portId, atom, redistribute(value, -100, 100, minimum, maximum)); |
|
273 }*/ |
|
274 } |
132 } |
275 |
133 |
276 int S60VideoSurface::redistribute( |
134 int S60VideoSurface::redistribute( |
277 int value, int fromLower, int fromUpper, int toLower, int toUpper) |
135 int value, int fromLower, int fromUpper, int toLower, int toUpper) |
278 { |
136 { |
279 /*return fromUpper != fromLower |
137 Q_UNUSED(value); |
280 ? ((value - fromLower) * (toUpper - toLower) / (fromUpper - fromLower)) + toLower |
138 Q_UNUSED(fromLower); |
281 : 0;*/ |
139 Q_UNUSED(fromUpper); |
|
140 Q_UNUSED(toLower); |
|
141 Q_UNUSED(toUpper); |
|
142 return 0; |
282 } |
143 } |
283 |
144 |
284 QList<QVideoFrame::PixelFormat> S60VideoSurface::supportedPixelFormats( |
145 QList<QVideoFrame::PixelFormat> S60VideoSurface::supportedPixelFormats( |
285 QAbstractVideoBuffer::HandleType handleType) const |
146 QAbstractVideoBuffer::HandleType handleType) const |
286 { |
147 { |
287 /*return handleType == QAbstractVideoBuffer::NoHandle |
148 Q_UNUSED(handleType); |
288 ? m_supportedPixelFormats |
149 QList<QVideoFrame::PixelFormat> list; |
289 : QList<QVideoFrame::PixelFormat>();*/ |
150 return list; |
290 } |
151 } |
291 |
152 |
292 bool S60VideoSurface::start(const QVideoSurfaceFormat &format) |
153 bool S60VideoSurface::start(const QVideoSurfaceFormat &format) |
293 { |
154 { |
294 /*if (m_image) |
155 Q_UNUSED(format); |
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; |
156 return false; |
333 } |
157 } |
334 |
158 |
335 void S60VideoSurface::stop() |
159 void S60VideoSurface::stop() |
336 {/* |
160 { |
337 if (m_image) { |
|
338 XFree(m_image); |
|
339 m_image = 0; |
|
340 |
|
341 QAbstractVideoSurface::stop(); |
|
342 }*/ |
|
343 } |
161 } |
344 |
162 |
345 bool S60VideoSurface::present(const QVideoFrame &frame) |
163 bool S60VideoSurface::present(const QVideoFrame &frame) |
346 {/* |
164 { |
347 if (!m_image) { |
165 Q_UNUSED(frame); |
348 setError(StoppedError); |
166 return false; |
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 } |
167 } |
397 |
168 |
398 bool S60VideoSurface::findPort() |
169 bool S60VideoSurface::findPort() |
399 {/* |
170 { |
400 unsigned int count = 0; |
171 return false; |
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 } |
172 } |
418 |
173 |
419 void S60VideoSurface::querySupportedFormats() |
174 void S60VideoSurface::querySupportedFormats() |
420 {/* |
175 { |
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 } |
176 } |
472 |
177 |
473 bool S60VideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const |
178 bool S60VideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const |
474 { |
179 { |
|
180 Q_UNUSED(format); |
|
181 return false; |
475 } |
182 } |