From 762bce7a06de20d87425a363a83a01bd0be9159a Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 1 Jun 2015 18:09:30 +0200 Subject: [PATCH 01/17] AVFoundation: fix wrong Q_ASSERT. The assert was always triggered, at least on OSX. Change-Id: I9aabb6103b7f5540cff42facc448ffcf6a6de511 Reviewed-by: Timur Pocheptsov --- src/plugins/avfoundation/camera/avfcameraflashcontrol.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm b/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm index 0eef95e9..89c7a2eb 100644 --- a/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm +++ b/src/plugins/avfoundation/camera/avfcameraflashcontrol.mm @@ -157,7 +157,7 @@ void AVFCameraFlashControl::cameraStateChanged(QCamera::State newState) bool AVFCameraFlashControl::applyFlashSettings() { - Q_ASSERT(m_session->state() == QCamera::ActiveState); + Q_ASSERT(m_session->requestedState() == QCamera::ActiveState); AVCaptureDevice *captureDevice = m_session->videoCaptureDevice(); if (!captureDevice) { From 00789e7d4ebbf4adb40a7722db43a03bcf5c3b4d Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 1 Jun 2015 16:13:27 +0300 Subject: [PATCH 02/17] winrt: fix camera preview on Lumia 530 Lumia 530 has the same QTBUG-44838 device bug that gives black frames when blitting to the target texture for image preview. Add it to workaround blacklist. Task-number: QTBUG-45920 Change-Id: Ia411793b90e487fa57b943ed7f01e370bfb84a1f Reviewed-by: Andrew Knight --- src/plugins/winrt/qwinrtcameracontrol.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp index e4a57764..2f71674f 100644 --- a/src/plugins/winrt/qwinrtcameracontrol.cpp +++ b/src/plugins/winrt/qwinrtcameracontrol.cpp @@ -129,6 +129,7 @@ public: hr = deviceInfo->get_SystemSku(deviceModel.GetAddressOf()); Q_ASSERT_SUCCEEDED(hr); m_flags |= bufferLockRequired(L"NOKIA RM-976", deviceModel); + m_flags |= bufferLockRequired(L"NOKIA RM-1019", deviceModel); #endif } From 912b8e56479c815782a0e9877efd675aa9326368 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Tue, 2 Jun 2015 18:12:19 +0200 Subject: [PATCH 03/17] Media asset writer - use the right macro QT_PREPEND_NAMESPACE, not QT_MANGLE_NAMESPACE. Change-Id: I9eb4130b203a5fb8f9f7964a0a642686814d5990 Reviewed-by: Yoann Lopes --- .../avfoundation/camera/avfmediaassetwriter.h | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/plugins/avfoundation/camera/avfmediaassetwriter.h b/src/plugins/avfoundation/camera/avfmediaassetwriter.h index eae70075..4759ae0a 100644 --- a/src/plugins/avfoundation/camera/avfmediaassetwriter.h +++ b/src/plugins/avfoundation/camera/avfmediaassetwriter.h @@ -70,32 +70,32 @@ QT_END_NAMESPACE @private AVFCameraService *m_service; - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_cameraWriterInput; - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_audioInput; - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_audioOutput; - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_audioWriterInput; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_cameraWriterInput; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_audioInput; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_audioOutput; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_audioWriterInput; // High priority serial queue for video output: - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_videoQueue; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_videoQueue; // Serial queue for audio output: - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_audioQueue; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_audioQueue; // Queue to write sample buffers: __weak dispatch_queue_t m_writerQueue; - QT_MANGLE_NAMESPACE(AVFScopedPointer) m_assetWriter; + QT_PREPEND_NAMESPACE(AVFScopedPointer) m_assetWriter; // Delegate's queue. __weak dispatch_queue_t m_delegateQueue; // TODO: QPointer?? QT_PREPEND_NAMESPACE(AVFMediaAssetWriterDelegate) *m_delegate; bool m_setStartTime; - QT_MANGLE_NAMESPACE(AVFAtomicBool) m_stopped; + QT_PREPEND_NAMESPACE(AVFAtomicBool) m_stopped; bool m_stoppedInternal; bool m_aborted; - QT_MANGLE_NAMESPACE(QMutex) m_writerMutex; + QT_PREPEND_NAMESPACE(QMutex) m_writerMutex; @public - QT_MANGLE_NAMESPACE(AVFAtomicInt64) m_durationInMs; + QT_PREPEND_NAMESPACE(AVFAtomicInt64) m_durationInMs; @private CMTime m_startTime; CMTime m_lastTimeStamp; From 2ee7db851978e93490102ee90a93485721a20a85 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Tue, 2 Jun 2015 16:33:11 +0200 Subject: [PATCH 04/17] Add an env var to disable OpenGL texture-based video frames. Right now we will always use GLTextureHandle frames with Quick. This is great in many cases, but not always. Applications that wish to examine the frames (e.g. via video filters) will sometimes prefer frames in system memory, even if this is slower to display. Add QT_QUICK_NO_TEXTURE_VIDEOFRAMES which can be used to disable texture-based video frames. [ChangeLog] The environment variable QT_QUICK_NO_TEXTURE_VIDEOFRAMES can now be used to disable OpenGL texture based video frames. This can be useful in applications that wish to filter and process the video frames and are not GPU based. Change-Id: I5ca6f6d485d5bc6c2da8d47db563cd910c238ac9 Reviewed-by: Yoann Lopes --- .../qdeclarativevideooutput_render.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp index f4efe47e..de4cabfa 100644 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp +++ b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp @@ -420,6 +420,17 @@ QList QSGVideoItemSurface::supportedPixelFormats( { QList formats; + static bool noGLTextures = false; + static bool noGLTexturesChecked = false; + if (handleType == QAbstractVideoBuffer::GLTextureHandle) { + if (!noGLTexturesChecked) { + noGLTexturesChecked = true; + noGLTextures = qEnvironmentVariableIsSet("QT_QUICK_NO_TEXTURE_VIDEOFRAMES"); + } + if (noGLTextures) + return formats; + } + foreach (QSGVideoNodeFactoryInterface* factory, m_backend->m_videoNodeFactories) formats.append(factory->supportedPixelFormats(handleType)); From f93f4e3daab1f9cbebbf663f1119a080cb299b9f Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Wed, 3 Jun 2015 14:43:13 +0200 Subject: [PATCH 05/17] WinRT: fix namespaced build Change-Id: I06b18e2a1318bda826befde52ee1fd874e25dd47 Reviewed-by: Oswald Buddenhagen Reviewed-by: Andrew Knight --- src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp | 4 +++- src/plugins/winrt/qwinrtcameracontrol.cpp | 4 +++- src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp | 4 +++- src/plugins/winrt/qwinrtcamerainfocontrol.cpp | 4 +++- src/plugins/winrt/qwinrtcameraservice.cpp | 4 +++- src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp | 4 +++- src/plugins/winrt/qwinrtmediaplayercontrol.cpp | 4 +++- src/plugins/winrt/qwinrtmediaplayercontrol.h | 4 +++- src/plugins/winrt/qwinrtmediaplayerservice.cpp | 4 +++- src/plugins/winrt/qwinrtplayerrenderercontrol.cpp | 4 +++- src/plugins/winrt/qwinrtserviceplugin.cpp | 4 +++- src/plugins/winrt/qwinrtserviceplugin.h | 4 +++- src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp | 4 +++- 13 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp index 2d0b5413..aa0f721b 100644 --- a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp +++ b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp @@ -56,7 +56,7 @@ using namespace Microsoft::WRL; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE #define BREAK_IF_FAILED(msg) RETURN_IF_FAILED(msg, break) #define CONTINUE_IF_FAILED(msg) RETURN_IF_FAILED(msg, continue) @@ -408,3 +408,5 @@ void QWinRTAbstractVideoRendererControl::present() QVideoFrame frame(d->videoBuffer, d->format.frameSize(), d->format.pixelFormat()); d->surface->present(frame); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp index 2f71674f..12f4fb45 100644 --- a/src/plugins/winrt/qwinrtcameracontrol.cpp +++ b/src/plugins/winrt/qwinrtcameracontrol.cpp @@ -67,7 +67,7 @@ using namespace ABI::Windows::Media::Devices; using namespace ABI::Windows::Media::MediaProperties; using namespace ABI::Windows::Storage::Streams; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE #define RETURN_VOID_AND_EMIT_ERROR(msg) \ if (FAILED(hr)) { \ @@ -833,3 +833,5 @@ HRESULT QWinRTCameraControl::onRecordLimitationExceeded(IMediaCapture *) setState(QCamera::LoadedState); return S_OK; } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp index 104484a6..6bc5eaaf 100644 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp +++ b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp @@ -64,7 +64,7 @@ using namespace ABI::Windows::Media::MediaProperties; using namespace ABI::Windows::Storage::Streams; using namespace ABI::Windows::Graphics::Imaging; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE #define wchar(str) reinterpret_cast(str.utf16()) @@ -273,3 +273,5 @@ HRESULT QWinRTCameraImageCaptureControl::onCaptureCompleted(IAsyncAction *asyncI return S_OK; } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcamerainfocontrol.cpp b/src/plugins/winrt/qwinrtcamerainfocontrol.cpp index 69fc0a9a..3e88fadc 100644 --- a/src/plugins/winrt/qwinrtcamerainfocontrol.cpp +++ b/src/plugins/winrt/qwinrtcamerainfocontrol.cpp @@ -37,7 +37,7 @@ #include "qwinrtcamerainfocontrol.h" #include "qwinrtvideodeviceselectorcontrol.h" -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE QWinRTCameraInfoControl::QWinRTCameraInfoControl(QObject *parent) : QCameraInfoControl(parent) @@ -53,3 +53,5 @@ int QWinRTCameraInfoControl::cameraOrientation(const QString &deviceName) const { return QWinRTVideoDeviceSelectorControl::cameraOrientation(deviceName); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameraservice.cpp b/src/plugins/winrt/qwinrtcameraservice.cpp index 09b56575..a73cddbe 100644 --- a/src/plugins/winrt/qwinrtcameraservice.cpp +++ b/src/plugins/winrt/qwinrtcameraservice.cpp @@ -45,7 +45,7 @@ #include #include -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QWinRTCameraServicePrivate { @@ -97,3 +97,5 @@ void QWinRTCameraService::releaseControl(QMediaControl *control) { Q_UNUSED(control); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp b/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp index 3b8a38bb..4878c55c 100644 --- a/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp +++ b/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp @@ -45,7 +45,7 @@ #include using namespace Microsoft::WRL; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE class D3DVideoBlitter { @@ -210,3 +210,5 @@ void QWinRTCameraVideoRendererControl::discardBuffers() for (ComPtr &buffer : d->buffers) buffer.Reset(); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtmediaplayercontrol.cpp b/src/plugins/winrt/qwinrtmediaplayercontrol.cpp index 0402553d..8954d444 100644 --- a/src/plugins/winrt/qwinrtmediaplayercontrol.cpp +++ b/src/plugins/winrt/qwinrtmediaplayercontrol.cpp @@ -55,7 +55,7 @@ #include using namespace Microsoft::WRL; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE #define QT_WINRT_MEDIAPLAYER_STREAM_ID "__qtmultimedia_winrt_player_stream" @@ -892,3 +892,5 @@ void QWinRTMediaPlayerControl::finishRead() Q_D(QWinRTMediaPlayerControl); d->streamProvider->finishRead(); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtmediaplayercontrol.h b/src/plugins/winrt/qwinrtmediaplayercontrol.h index 34abcc12..54fdcc10 100644 --- a/src/plugins/winrt/qwinrtmediaplayercontrol.h +++ b/src/plugins/winrt/qwinrtmediaplayercontrol.h @@ -41,7 +41,7 @@ struct IMFMediaEngineClassFactory; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QVideoRendererControl; @@ -96,4 +96,6 @@ private: Q_DECLARE_PRIVATE(QWinRTMediaPlayerControl) }; +QT_END_NAMESPACE + #endif // QWINRTMEDIAPLAYERCONTROL_H diff --git a/src/plugins/winrt/qwinrtmediaplayerservice.cpp b/src/plugins/winrt/qwinrtmediaplayerservice.cpp index a6b3d1f3..dd7aaa11 100644 --- a/src/plugins/winrt/qwinrtmediaplayerservice.cpp +++ b/src/plugins/winrt/qwinrtmediaplayerservice.cpp @@ -47,7 +47,7 @@ using namespace Microsoft::WRL; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QWinRTMediaPlayerServicePrivate { @@ -104,3 +104,5 @@ void QWinRTMediaPlayerService::releaseControl(QMediaControl *control) if (control == d->player) d->player->deleteLater(); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp b/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp index 5a8f4b87..c37aac4e 100644 --- a/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp +++ b/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp @@ -54,7 +54,7 @@ #include using namespace Microsoft::WRL; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE template class D3DDeviceLocker @@ -149,3 +149,5 @@ bool QWinRTPlayerRendererControl::render(ID3D11Texture2D *texture) RETURN_FALSE_IF_FAILED("Failed to transfer video frame to DXGI surface"); return true; } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtserviceplugin.cpp b/src/plugins/winrt/qwinrtserviceplugin.cpp index fc0103d1..7237632a 100644 --- a/src/plugins/winrt/qwinrtserviceplugin.cpp +++ b/src/plugins/winrt/qwinrtserviceplugin.cpp @@ -42,7 +42,7 @@ #include "qwinrtcameraservice.h" #include "qwinrtvideodeviceselectorcontrol.h" -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE QMediaService *QWinRTServicePlugin::create(QString const &key) { @@ -102,3 +102,5 @@ QByteArray QWinRTServicePlugin::defaultDevice(const QByteArray &service) const return QByteArray(); } + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtserviceplugin.h b/src/plugins/winrt/qwinrtserviceplugin.h index 5f5cf559..0f76f505 100644 --- a/src/plugins/winrt/qwinrtserviceplugin.h +++ b/src/plugins/winrt/qwinrtserviceplugin.h @@ -39,7 +39,7 @@ #include -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE class QWinRTServicePlugin : public QMediaServiceProviderPlugin , public QMediaServiceFeaturesInterface @@ -68,4 +68,6 @@ public: QByteArray defaultDevice(const QByteArray &service) const Q_DECL_OVERRIDE; }; +QT_END_NAMESPACE + #endif // QWINRTSERVICEPLUGIN_H diff --git a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp b/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp index 582a9fc6..8e806dcb 100644 --- a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp +++ b/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp @@ -55,7 +55,7 @@ typedef ITypedEventHandler DeviceInformati typedef ITypedEventHandler DeviceInformationUpdateHandler; typedef ITypedEventHandler DeviceEnumerationCompletedHandler; -QT_USE_NAMESPACE +QT_BEGIN_NAMESPACE static QString deviceName(IDeviceInformation *device) { @@ -386,3 +386,5 @@ void QWinRTVideoDeviceSelectorControl::setSelectedDevice(int index) emit selectedDeviceChanged(deviceName(d->selectedDevice)); } } + +QT_END_NAMESPACE From 269c64f47a0e356bc91a261b61f4e23f0b08fcfc Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 8 Jun 2015 17:46:10 +0200 Subject: [PATCH 06/17] Support BGR format for OpenGL textures in QPainterVideoSurface. Also, use the correct shader for RGB formats, we should be using the one that does swizzling in that case. Change-Id: I77b6327501f833fb2f7b30411fbe853e975a59c7 Reviewed-by: Laszlo Agocs --- .../qpaintervideosurface.cpp | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/multimediawidgets/qpaintervideosurface.cpp b/src/multimediawidgets/qpaintervideosurface.cpp index 2dfbf341..c9fa206a 100644 --- a/src/multimediawidgets/qpaintervideosurface.cpp +++ b/src/multimediawidgets/qpaintervideosurface.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1) #include @@ -261,6 +262,12 @@ protected: void initYuv420PTextureInfo(const QSize &size); void initYv12TextureInfo(const QSize &size); + bool needsSwizzling(const QVideoSurfaceFormat &format) const { + return !QMediaOpenGLHelper::isANGLE() + && (format.pixelFormat() == QVideoFrame::Format_RGB32 + || format.pixelFormat() == QVideoFrame::Format_ARGB32); + } + #if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC) typedef void (APIENTRY *_glActiveTexture) (GLenum); _glActiveTexture glActiveTexture; @@ -702,7 +709,9 @@ QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QGLContext *context) << QVideoFrame::Format_YUV420P; m_glPixelFormats << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_ARGB32; + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_BGR32 + << QVideoFrame::Format_BGRA32; } QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfaceFormat &format) @@ -766,9 +775,14 @@ QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfac switch (format.pixelFormat()) { case QVideoFrame::Format_RGB32: case QVideoFrame::Format_ARGB32: + case QVideoFrame::Format_BGR32: + case QVideoFrame::Format_BGRA32: m_yuv = false; m_textureCount = 1; - program = qt_arbfp_rgbShaderProgram; + if (needsSwizzling(format)) + program = qt_arbfp_xrgbShaderProgram; + else + program = qt_arbfp_rgbShaderProgram; break; default: break; @@ -1070,7 +1084,9 @@ QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context) << QVideoFrame::Format_YUV420P; m_glPixelFormats << QVideoFrame::Format_RGB32 - << QVideoFrame::Format_ARGB32; + << QVideoFrame::Format_ARGB32 + << QVideoFrame::Format_BGR32 + << QVideoFrame::Format_BGRA32; } QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurfaceFormat &format) @@ -1138,9 +1154,14 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface switch (format.pixelFormat()) { case QVideoFrame::Format_RGB32: case QVideoFrame::Format_ARGB32: + case QVideoFrame::Format_BGR32: + case QVideoFrame::Format_BGRA32: m_yuv = false; m_textureCount = 1; - fragmentProgram = qt_glsl_rgbShaderProgram; + if (needsSwizzling(format)) + fragmentProgram = qt_glsl_xrgbShaderProgram; + else + fragmentProgram = qt_glsl_rgbShaderProgram; break; default: break; From 3cb698c0fcd05334163ac86f1a5a599dae67025b Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 8 Jun 2015 18:09:23 +0200 Subject: [PATCH 07/17] AVFoundation: don't use shared OpenGL contexts unless needed. We were always using shared OpenGL contexts to render media player frames into an OpenGL texture. There's no need to do that when there already is a current context on the current thread. This happens in non-QtQuick cases, when the OpenGL thread is also the main thread. Change-Id: Icb97ed49609c764263007a43b6bb481e23768111 Reviewed-by: Laszlo Agocs --- .../mediaplayer/avfvideoframerenderer.mm | 26 +++++++++++-------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm index fe3389a4..2d6eac54 100644 --- a/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm +++ b/src/plugins/avfoundation/mediaplayer/avfvideoframerenderer.mm @@ -50,19 +50,13 @@ AVFVideoFrameRenderer::AVFVideoFrameRenderer(QAbstractVideoSurface *surface, QOb : QObject(parent) , m_videoLayerRenderer(0) , m_surface(surface) + , m_offscreenSurface(0) , m_glContext(0) , m_currentBuffer(1) , m_isContextShared(true) { m_fbo[0] = 0; m_fbo[1] = 0; - - //Create Hidden QWindow surface to create context in this thread - m_offscreenSurface = new QWindow(); - m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); - //Needs geometry to be a valid surface, but size is not important - m_offscreenSurface->setGeometry(0, 0, 1, 1); - m_offscreenSurface->create(); } AVFVideoFrameRenderer::~AVFVideoFrameRenderer() @@ -94,7 +88,8 @@ GLuint AVFVideoFrameRenderer::renderLayerToTexture(AVPlayerLayer *layer) return 0; renderLayerToFBO(layer, fbo); - m_glContext->doneCurrent(); + if (m_glContext) + m_glContext->doneCurrent(); return fbo->texture(); } @@ -113,7 +108,8 @@ QImage AVFVideoFrameRenderer::renderLayerToImage(AVPlayerLayer *layer) renderLayerToFBO(layer, fbo); QImage fboImage = fbo->toImage(); - m_glContext->doneCurrent(); + if (m_glContext) + m_glContext->doneCurrent(); return fboImage; } @@ -125,7 +121,14 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay m_targetSize = QSize(layer.bounds.size.width, layer.bounds.size.height); //Make sure we have an OpenGL context to make current - if (!m_glContext) { + if (!QOpenGLContext::currentContext() && !m_glContext) { + //Create Hidden QWindow surface to create context in this thread + m_offscreenSurface = new QWindow(); + m_offscreenSurface->setSurfaceType(QWindow::OpenGLSurface); + //Needs geometry to be a valid surface, but size is not important + m_offscreenSurface->setGeometry(0, 0, 1, 1); + m_offscreenSurface->create(); + //Create OpenGL context and set share context from surface QOpenGLContext *shareContext = 0; if (m_surface) { @@ -151,7 +154,8 @@ QOpenGLFramebufferObject *AVFVideoFrameRenderer::initRenderer(AVPlayerLayer *lay } //Need current context - m_glContext->makeCurrent(m_offscreenSurface); + if (m_glContext) + m_glContext->makeCurrent(m_offscreenSurface); //Create the CARenderer if needed if (!m_videoLayerRenderer) { From 7f9beeaf9c1f86268dee8e6f668fbf78313ffd9c Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Tue, 9 Jun 2015 18:30:32 +0200 Subject: [PATCH 08/17] Define QCamera::FrameRateRange as a struct. Instead of an alias for QPair. Task-number: QTBUG-46563 Change-Id: I7e1ac68242810f7e5f7e161571a11f5de7850e29 Reviewed-by: Christian Stromme --- src/imports/multimedia/qdeclarativecamera.cpp | 4 +-- src/multimedia/camera/qcamera.cpp | 26 ++++++++++++++----- src/multimedia/camera/qcamera.h | 24 ++++++++++++++++- .../directshow/camera/dscamerasession.cpp | 6 ++--- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/imports/multimedia/qdeclarativecamera.cpp b/src/imports/multimedia/qdeclarativecamera.cpp index aac873b8..c5d899e9 100644 --- a/src/imports/multimedia/qdeclarativecamera.cpp +++ b/src/imports/multimedia/qdeclarativecamera.cpp @@ -1094,8 +1094,8 @@ QJSValue QDeclarativeCamera::supportedViewfinderFrameRateRanges(const QSize &res int i = 0; Q_FOREACH (const QCamera::FrameRateRange &frameRateRange, frameRateRanges) { QJSValue range = engine->newObject(); - range.setProperty(QStringLiteral("minimumFrameRate"), frameRateRange.first); - range.setProperty(QStringLiteral("maximumFrameRate"), frameRateRange.second); + range.setProperty(QStringLiteral("minimumFrameRate"), frameRateRange.minimumFrameRate); + range.setProperty(QStringLiteral("maximumFrameRate"), frameRateRange.maximumFrameRate); supportedFrameRateRanges.setProperty(i++, range); } diff --git a/src/multimedia/camera/qcamera.cpp b/src/multimedia/camera/qcamera.cpp index daee0a93..e70bed04 100644 --- a/src/multimedia/camera/qcamera.cpp +++ b/src/multimedia/camera/qcamera.cpp @@ -72,7 +72,7 @@ static bool qt_sizeLessThan(const QSize &s1, const QSize &s2) static bool qt_frameRateRangeLessThan(const QCamera::FrameRateRange &s1, const QCamera::FrameRateRange &s2) { - return s1.second < s2.second; + return s1.maximumFrameRate < s2.maximumFrameRate; } /*! @@ -1028,15 +1028,29 @@ void QCamera::unlock() /*! - \typedef QCamera::FrameRateRange + \class QCamera::FrameRateRange + \inmodule QtMultimedia + \ingroup multimedia + \ingroup multimedia_camera + \since 5.5 - This is a typedef for QPair. + \brief A FrameRateRange represents a range of frame rates as minimum and maximum rate. - A frame rate range contains a minimum and a maximum frame rate, respectively the first and - second element of the pair. If the minimum frame rate is equal to the maximum frame rate, the - frame rate is fixed. If not, the actual frame rate fluctuates between the minimum and the maximum. + If the minimum frame rate is equal to the maximum frame rate, the frame rate is fixed. + If not, the actual frame rate fluctuates between the minimum and the maximum. + + \sa QCamera::supportedViewfinderFrameRateRanges(), QCameraViewfinderSettings */ +/*! + \variable QCamera::FrameRateRange::minimumFrameRate + The minimum frame rate supported by the range, in frames per second. +*/ + +/*! + \variable QCamera::FrameRateRange::maximumFrameRate + The maximum frame rate supported by the range, in frames per second. +*/ /*! \enum QCamera::State diff --git a/src/multimedia/camera/qcamera.h b/src/multimedia/camera/qcamera.h index a50c3849..ea81c02c 100644 --- a/src/multimedia/camera/qcamera.h +++ b/src/multimedia/camera/qcamera.h @@ -77,7 +77,21 @@ class Q_MULTIMEDIA_EXPORT QCamera : public QMediaObject Q_ENUMS(LockType) Q_ENUMS(Position) public: - typedef QPair FrameRateRange; + struct FrameRateRange + { + Q_DECL_CONSTEXPR FrameRateRange() Q_DECL_NOTHROW + : minimumFrameRate(0) + , maximumFrameRate(0) + { } + + Q_DECL_CONSTEXPR FrameRateRange(qreal minimum, qreal maximum) Q_DECL_NOTHROW + : minimumFrameRate(minimum) + , maximumFrameRate(maximum) + { } + + qreal minimumFrameRate; + qreal maximumFrameRate; + }; enum Status { UnavailableStatus, @@ -237,6 +251,14 @@ private: Q_DECLARE_OPERATORS_FOR_FLAGS(QCamera::LockTypes) +Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator==(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) Q_DECL_NOTHROW +{ return r1.minimumFrameRate == r2.minimumFrameRate && r1.maximumFrameRate == r2.maximumFrameRate; } + +Q_DECL_CONSTEXPR Q_INLINE_TEMPLATE bool operator!=(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) Q_DECL_NOTHROW +{ return !(r1 == r2); } + +Q_DECLARE_TYPEINFO(QCamera::FrameRateRange, Q_PRIMITIVE_TYPE); + QT_END_NAMESPACE Q_DECLARE_METATYPE(QCamera::State) diff --git a/src/plugins/directshow/camera/dscamerasession.cpp b/src/plugins/directshow/camera/dscamerasession.cpp index 87af9a6e..a2586aa9 100644 --- a/src/plugins/directshow/camera/dscamerasession.cpp +++ b/src/plugins/directshow/camera/dscamerasession.cpp @@ -789,7 +789,7 @@ void DSCameraSession::disconnectGraph() static bool qt_frameRateRangeGreaterThan(const QCamera::FrameRateRange &r1, const QCamera::FrameRateRange &r2) { - return r1.second > r2.second; + return r1.maximumFrameRate > r2.maximumFrameRate; } void DSCameraSession::updateSourceCapabilities() @@ -896,8 +896,8 @@ void DSCameraSession::updateSourceCapabilities() Q_FOREACH (const QCamera::FrameRateRange &frameRateRange, frameRateRanges) { QCameraViewfinderSettings settings; settings.setResolution(resolution); - settings.setMinimumFrameRate(frameRateRange.first); - settings.setMaximumFrameRate(frameRateRange.second); + settings.setMinimumFrameRate(frameRateRange.minimumFrameRate); + settings.setMaximumFrameRate(frameRateRange.maximumFrameRate); settings.setPixelFormat(pixelFormat); m_supportedViewfinderSettings.append(settings); From 36507b71f2a05d8703cfa5437f5d3246be896359 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Wed, 10 Jun 2015 22:37:09 +0200 Subject: [PATCH 09/17] Added 5.5.0 change file. Task-number: QTBUG-45455 Change-Id: I832dcd02215e6ae004b6f1e6cf3905b95a838e4a Reviewed-by: Christian Stromme --- dist/changes-5.5.0 | 118 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 dist/changes-5.5.0 diff --git a/dist/changes-5.5.0 b/dist/changes-5.5.0 new file mode 100644 index 00000000..14b9cc04 --- /dev/null +++ b/dist/changes-5.5.0 @@ -0,0 +1,118 @@ +Qt 5.5 introduces many new features and improvements as well as bugfixes +over the 5.4.x series. For more details, refer to the online documentation +included in this distribution. The documentation is also available online: + + http://doc.qt.io/qt-5.5 + +The Qt version 5.5 series is binary compatible with the 5.4.x series. +Applications compiled for 5.4 will continue to run with 5.5. + +Some of the changes listed in this file include issue tracking numbers +corresponding to tasks in the Qt Bug Tracker: + + http://bugreports.qt.io/ + +Each of these identifiers can be entered in the bug tracker to obtain more +information about a particular change. + +**************************************************************************** +* Library * +**************************************************************************** + +QtMultimedia +------------ + + - Added QAbstractVideoFilter that serves as a base class for QML + video filtering elements that integrate compute, vision, and image + processing frameworks with VideoOutput. + - Added new QCameraViewfinderSettings class. + - [QTBUG-40571] Fixed memory leak in QAudioDecoder. + + - Camera (QML): + * Added imageProcessing.colorFilter, viewfinder.minimumFrameRate and + viewfinder.maximumFrameRate properties. + * Added new supportedViewfinderResolutions() and + supportedViewfinderFrameRateRanges() methods. + * Exposure modes extended to support Action, Landscape, NightPortrait, + Theatre, Sunset, SteadyPhoto, Fireworks, Party, Candlelight, and + Barcode modes + + - QCamera: + * Added support for viewfinder settings. In addition to the getter and + setter, supportedViewfinderSettings(), + supportedViewfinderResolutions(), supportedViewfinderFrameRateRanges() + and supportedViewfinderPixelFormats() can be used to query for + supported values. + * Fixed searchAndLock() and supportedLocks() functions which could not + work at all on some platforms. + + - QCameraExposure: + * Exposure modes extended to support Action, Landscape, NightPortrait, + Theatre, Sunset, SteadyPhoto, Fireworks, Party, Candlelight, and + Barcode modes + + - QCameraImageProcessing: + * Added support for color filters. + +**************************************************************************** +* Platform Specific Changes * +**************************************************************************** + +Android +------- + + - Added support for additional camera exposure modes (see list in + QCameraExposure changes). + +iOS / OS X +---------- + + - Improved camera support: + * Image capture settings, focus, flash, exposure (iOS only) and + zoom (iOS only) APIs are now functional. + * QVideoProbe can now be used with a QCamera. + + - VideoOutput, when used with a MediaPlayer on iOS, can now be displayed + under other elements and supports shader effects and advanced + transformations. + - QMediaRecorder now uses the correct system default audio capture + device. + - [QTBUG-36175] QMediaPlayer and the QML Audio and Mediaplayer types can + now play media files stored in a Qt resource file. + - [QTBUG-37655] Fixed video capture on iOS. + - [QTBUG-39240] QMediaPlayer and the QML Audio and Mediaplayer types now + support volume and mute on iOS 7.0 and later. + - [QTBUG-42035] Fixed crash when capturing an image after changing the + active camera device. + +Linux +----- + + - Added support for GStreamer 1.0. The 0.10 series is still used by default + and Qt needs to be configured with '-gstreamer 1.0' to enable 1.0 + support. If only GStreamer 1.0 is available on the system, the configure + script will automatically configure Qt with GStreamer 1.0 support. + - QCamera now supports exposure and white balance locks. + - Added support for additional camera exposure modes (see list in + QCameraExposure changes). + - Fixed QCameraImageCapture::supportedResolutions(), + QMediaRecorder::supportedResolutions() and + QMediaRecorder::supportedFrameRates() that could return empty lists. + - [QTBUG-46169] QVideoWidget now works with any windowing system. It was + previously only working with X11. + +Windows +------- + + - [QTBUG-45571] QAudioBuffer::startTime() now returns the time in the + correct time scale. + +WinRT +----- + + - [QTBUG-42263] QMediaPlayer and the QML Audio and Mediaplayer types can + now play media files stored in a Qt resource file. + - [QTBUG-44838] Fixed camera preview on Lumia 630. + - [QTBUG-45920] Fixed camera preview on Lumia 530. + - [QTBUG-45667] Fixed crash that could occur when using the camera + preview. From c34cf6131221dac2ea8745a5c93b57c13dd8533c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Jun 2015 13:45:34 +0200 Subject: [PATCH 10/17] QCameraViewFinderSettings: use correct include Change-Id: I71f24922872f64d86d55f420b0e27028a6368097 Reviewed-by: Lars Knoll --- src/multimedia/camera/qcameraviewfindersettings.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/multimedia/camera/qcameraviewfindersettings.h b/src/multimedia/camera/qcameraviewfindersettings.h index bfb3d08d..db9d3d8e 100644 --- a/src/multimedia/camera/qcameraviewfindersettings.h +++ b/src/multimedia/camera/qcameraviewfindersettings.h @@ -34,10 +34,11 @@ #ifndef QCAMERAVIEWFINDERSETTINGS_H #define QCAMERAVIEWFINDERSETTINGS_H -#include #include #include +#include + QT_BEGIN_NAMESPACE class QCameraViewfinderSettingsPrivate; From 99bda08cb1ea14a29deefe9dabe276c38648c899 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Jun 2015 13:55:43 +0200 Subject: [PATCH 11/17] QCameraViewFinderSettings: make op== non-member ...and inline op!=. Mark them as nothrow. More idiomatic C++ (symmetry between lhs and rhs). Change-Id: I65ecbef961383897e4e17325ad62d45e1772fbb0 Reviewed-by: Lars Knoll --- .../camera/qcameraviewfindersettings.cpp | 31 ++++++++++--------- .../camera/qcameraviewfindersettings.h | 7 +++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/multimedia/camera/qcameraviewfindersettings.cpp b/src/multimedia/camera/qcameraviewfindersettings.cpp index a6290cfb..059c93f6 100644 --- a/src/multimedia/camera/qcameraviewfindersettings.cpp +++ b/src/multimedia/camera/qcameraviewfindersettings.cpp @@ -136,32 +136,35 @@ QCameraViewfinderSettings &QCameraViewfinderSettings::operator=(const QCameraVie } /*! - Determines if \a other is of equal value to a viewfinder settings object. + \relates QCameraViewfinderSettings + \since 5.5 + + Determines if \a lhs is of equal value to \a rhs. Returns true if the settings objects are of equal value, and false if they are not of equal value. */ -bool QCameraViewfinderSettings::operator==(const QCameraViewfinderSettings &other) const +bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW { - return (d == other.d) || - (d->isNull == other.d->isNull && - d->resolution == other.d->resolution && - qFuzzyCompare(d->minimumFrameRate, other.d->minimumFrameRate) && - qFuzzyCompare(d->maximumFrameRate, other.d->maximumFrameRate) && - d->pixelFormat == other.d->pixelFormat && - d->pixelAspectRatio == other.d->pixelAspectRatio); + return (lhs.d == rhs.d) || + (lhs.d->isNull == rhs.d->isNull && + lhs.d->resolution == rhs.d->resolution && + qFuzzyCompare(lhs.d->minimumFrameRate, rhs.d->minimumFrameRate) && + qFuzzyCompare(lhs.d->maximumFrameRate, rhs.d->maximumFrameRate) && + lhs.d->pixelFormat == rhs.d->pixelFormat && + lhs.d->pixelAspectRatio == rhs.d->pixelAspectRatio); } /*! - Determines if \a other is of equal value to a viewfinder settings object. + \fn bool operator!=(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) + \relates QCameraViewfinderSettings + \since 5.5 + + Determines if \a lhs is of equal value to \a rhs. Returns true if the settings objects are not of equal value, and false if they are of equal value. */ -bool QCameraViewfinderSettings::operator!=(const QCameraViewfinderSettings &other) const -{ - return !(*this == other); -} /*! Identifies if a viewfinder settings object is uninitalized. diff --git a/src/multimedia/camera/qcameraviewfindersettings.h b/src/multimedia/camera/qcameraviewfindersettings.h index db9d3d8e..dcdf025f 100644 --- a/src/multimedia/camera/qcameraviewfindersettings.h +++ b/src/multimedia/camera/qcameraviewfindersettings.h @@ -52,9 +52,8 @@ public: ~QCameraViewfinderSettings(); QCameraViewfinderSettings& operator=(const QCameraViewfinderSettings &other); - bool operator==(const QCameraViewfinderSettings &other) const; - bool operator!=(const QCameraViewfinderSettings &other) const; + friend Q_MULTIMEDIA_EXPORT bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW; bool isNull() const; QSize resolution() const; @@ -80,6 +79,10 @@ private: QSharedDataPointer d; }; +inline bool operator!=(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW +{ return !operator==(lhs, rhs); } + + QT_END_NAMESPACE Q_DECLARE_METATYPE(QCameraViewfinderSettings) From 12893e382600bf9defaa79e3b22a2f880e2f5a0a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Jun 2015 13:59:19 +0200 Subject: [PATCH 12/17] QCameraViewFinderSettings: declare shared Requires implementing member-swap. Also implemented move assignment operator. Change-Id: I077ee85346a8c542cd344720e45a0795a6947e4c Reviewed-by: Lars Knoll --- src/multimedia/camera/qcameraviewfindersettings.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/multimedia/camera/qcameraviewfindersettings.h b/src/multimedia/camera/qcameraviewfindersettings.h index dcdf025f..31c7329c 100644 --- a/src/multimedia/camera/qcameraviewfindersettings.h +++ b/src/multimedia/camera/qcameraviewfindersettings.h @@ -52,6 +52,12 @@ public: ~QCameraViewfinderSettings(); QCameraViewfinderSettings& operator=(const QCameraViewfinderSettings &other); +#ifdef Q_COMPILER_RVALUE_REFS + QCameraViewfinderSettings &operator=(QCameraViewfinderSettings &&other) Q_DECL_NOTHROW + { swap(other); return *this; } +#endif + + void swap(QCameraViewfinderSettings &other) Q_DECL_NOTHROW { d.swap(other.d); } friend Q_MULTIMEDIA_EXPORT bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW; bool isNull() const; @@ -78,6 +84,7 @@ public: private: QSharedDataPointer d; }; +Q_DECLARE_SHARED(QCameraViewfinderSettings) inline bool operator!=(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSettings &rhs) Q_DECL_NOTHROW { return !operator==(lhs, rhs); } From 62d9398a27a14098e15094b52dd4f0c72bf5cc23 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Jun 2015 14:03:21 +0200 Subject: [PATCH 13/17] QCameraViewFinderSettings: make op== transitive Using qFuzzyCompare in operator== makes it impossible to create a consistent qHash() overload for the class later on (qFuzzyCompare is not transitive). It is unlikely that there will be numerical instability for frame rates. If there is, qFuzzyCompare should be overloaded for either this class or the FrameRateRange class. Change-Id: Id975ea410b373e2987da160504f7618a8c498b5c Reviewed-by: Lars Knoll --- src/multimedia/camera/qcameraviewfindersettings.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multimedia/camera/qcameraviewfindersettings.cpp b/src/multimedia/camera/qcameraviewfindersettings.cpp index 059c93f6..a92ee65a 100644 --- a/src/multimedia/camera/qcameraviewfindersettings.cpp +++ b/src/multimedia/camera/qcameraviewfindersettings.cpp @@ -149,8 +149,8 @@ bool operator==(const QCameraViewfinderSettings &lhs, const QCameraViewfinderSet return (lhs.d == rhs.d) || (lhs.d->isNull == rhs.d->isNull && lhs.d->resolution == rhs.d->resolution && - qFuzzyCompare(lhs.d->minimumFrameRate, rhs.d->minimumFrameRate) && - qFuzzyCompare(lhs.d->maximumFrameRate, rhs.d->maximumFrameRate) && + lhs.d->minimumFrameRate == rhs.d->minimumFrameRate && + lhs.d->maximumFrameRate == rhs.d->maximumFrameRate && lhs.d->pixelFormat == rhs.d->pixelFormat && lhs.d->pixelAspectRatio == rhs.d->pixelAspectRatio); } From 3a18580e230e77e6e340a4a1f3eb2f69b320cda3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Jun 2015 14:14:31 +0200 Subject: [PATCH 14/17] QAbstractVideoFilter: make ctor explicit Change-Id: If091d751c7e164c0480b48301358833705cd4870 Reviewed-by: Lars Knoll --- src/multimedia/video/qabstractvideofilter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/multimedia/video/qabstractvideofilter.h b/src/multimedia/video/qabstractvideofilter.h index f0175be1..77f035e0 100644 --- a/src/multimedia/video/qabstractvideofilter.h +++ b/src/multimedia/video/qabstractvideofilter.h @@ -62,7 +62,7 @@ class Q_MULTIMEDIA_EXPORT QAbstractVideoFilter : public QObject Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged) public: - QAbstractVideoFilter(QObject *parent = 0); + explicit QAbstractVideoFilter(QObject *parent = 0); ~QAbstractVideoFilter(); bool isActive() const; From 04e086e33667ca1a7aa8a7be7427bfba491a72b0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 11 Jun 2015 14:08:07 +0200 Subject: [PATCH 15/17] QCameraViewFinderSettings: add missing include The header should not depend on indirect includes. It uses QSize in inline functions, so include the header. Change-Id: I3a5fca458ded47c98b7f71749ad75660c6e049e9 Reviewed-by: Lars Knoll --- src/multimedia/camera/qcameraviewfindersettings.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/multimedia/camera/qcameraviewfindersettings.h b/src/multimedia/camera/qcameraviewfindersettings.h index 31c7329c..ce10b68a 100644 --- a/src/multimedia/camera/qcameraviewfindersettings.h +++ b/src/multimedia/camera/qcameraviewfindersettings.h @@ -38,6 +38,7 @@ #include #include +#include QT_BEGIN_NAMESPACE From dc9e10d4b7acd9e752a7b094c7178a7ecbe96ff7 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Fri, 12 Jun 2015 13:02:38 +0300 Subject: [PATCH 16/17] winrt: Implement QImageEncoderControl for camera Implement QImageEncoderControl for camera still image capture. It provides the functions to set camera capture resolution and get supported resolutions list. Task-number: QTBUG-46456 Change-Id: Ideb1aa02d420be3a30d588bebf31714fa4fa6415 Reviewed-by: Oliver Wolff --- src/plugins/winrt/qwinrtcameracontrol.cpp | 44 +++++-- src/plugins/winrt/qwinrtcameracontrol.h | 3 +- .../winrt/qwinrtcameraimagecapturecontrol.cpp | 30 ++++- src/plugins/winrt/qwinrtcameraservice.cpp | 6 + .../winrt/qwinrtimageencodercontrol.cpp | 124 ++++++++++++++++++ src/plugins/winrt/qwinrtimageencodercontrol.h | 66 ++++++++++ src/plugins/winrt/winrt.pro | 6 +- 7 files changed, 262 insertions(+), 17 deletions(-) create mode 100644 src/plugins/winrt/qwinrtimageencodercontrol.cpp create mode 100644 src/plugins/winrt/qwinrtimageencodercontrol.h diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp index e4a57764..f5b75d9a 100644 --- a/src/plugins/winrt/qwinrtcameracontrol.cpp +++ b/src/plugins/winrt/qwinrtcameracontrol.cpp @@ -38,6 +38,7 @@ #include "qwinrtcameravideorenderercontrol.h" #include "qwinrtvideodeviceselectorcontrol.h" #include "qwinrtcameraimagecapturecontrol.h" +#include "qwinrtimageencodercontrol.h" #include #include @@ -75,6 +76,10 @@ QT_USE_NAMESPACE RETURN_VOID_IF_FAILED(msg); \ } +inline uint qHash (const QSize &key) { + return key.width() * key.height(); +} + class CriticalSectionLocker { public: @@ -453,6 +458,7 @@ public: QPointer videoRenderer; QPointer videoDeviceSelector; QPointer imageCaptureControl; + QPointer imageEncoderControl; }; QWinRTCameraControl::QWinRTCameraControl(QObject *parent) @@ -470,6 +476,7 @@ QWinRTCameraControl::QWinRTCameraControl(QObject *parent) this, &QWinRTCameraControl::onBufferRequested); d->videoDeviceSelector = new QWinRTVideoDeviceSelectorControl(this); d->imageCaptureControl = new QWinRTCameraImageCaptureControl(this); + d->imageEncoderControl = new QWinRTImageEncoderControl(this); } QWinRTCameraControl::~QWinRTCameraControl() @@ -654,18 +661,18 @@ QCameraImageCaptureControl *QWinRTCameraControl::imageCaptureControl() const return d->imageCaptureControl; } +QImageEncoderControl *QWinRTCameraControl::imageEncoderControl() const +{ + Q_D(const QWinRTCameraControl); + return d->imageEncoderControl; +} + IMediaCapture *QWinRTCameraControl::handle() const { Q_D(const QWinRTCameraControl); return d->capture.Get(); } -QSize QWinRTCameraControl::imageSize() const -{ - Q_D(const QWinRTCameraControl); - return d->size; -} - void QWinRTCameraControl::onBufferRequested() { Q_D(QWinRTCameraControl); @@ -763,10 +770,11 @@ HRESULT QWinRTCameraControl::initialize() Q_ASSERT_SUCCEEDED(hr); d->size = QSize(); - ComPtr videoEncodingProperties; quint32 encodingPropertiesListSize; hr = encodingPropertiesList->get_Size(&encodingPropertiesListSize); Q_ASSERT_SUCCEEDED(hr); + QHash> videoEncodingPropertiesList; + int pixelCount = 0; for (quint32 i = 0; i < encodingPropertiesListSize; ++i) { ComPtr properties; hr = encodingPropertiesList->GetAt(i, &properties); @@ -779,21 +787,33 @@ HRESULT QWinRTCameraControl::initialize() Q_ASSERT_SUCCEEDED(hr); hr = videoProperties->get_Height(&height); Q_ASSERT_SUCCEEDED(hr); - // Choose the highest-quality format - if (int(width * height) > d->size.width() * d->size.height()) { - d->size = QSize(width, height); - videoEncodingProperties = videoProperties; + if (d->captureMode != QCamera::CaptureStillImage && int(width * height) > pixelCount) { + d->size = QSize(width, height);// Choose the Highest-quality format + pixelCount = d->size.width() * d->size.height(); } + videoEncodingPropertiesList.insert(QSize(width, height), videoProperties); } - if (!videoEncodingProperties || d->size.isEmpty()) { + if (videoEncodingPropertiesList.isEmpty()) { hr = MF_E_INVALID_FORMAT; RETURN_HR_IF_FAILED("Failed to find a suitable video format"); } + if (d->captureMode == QCamera::CaptureStillImage) { + d->imageEncoderControl->setSupportedResolutionsList(videoEncodingPropertiesList.keys()); + d->size = d->imageEncoderControl->imageSettings().resolution(); + } + hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_MediaProperties_MediaEncodingProfile).Get(), &d->encodingProfile); Q_ASSERT_SUCCEEDED(hr); + + const ComPtr videoEncodingProperties = videoEncodingPropertiesList[d->size]; + if (!videoEncodingProperties) { + hr = MF_E_INVALID_FORMAT; + RETURN_HR_IF_FAILED("Failed to find a suitable video format properties"); + } + hr = d->encodingProfile->put_Video(videoEncodingProperties.Get()); Q_ASSERT_SUCCEEDED(hr); if (d->videoRenderer) diff --git a/src/plugins/winrt/qwinrtcameracontrol.h b/src/plugins/winrt/qwinrtcameracontrol.h index 95692cbc..307667eb 100644 --- a/src/plugins/winrt/qwinrtcameracontrol.h +++ b/src/plugins/winrt/qwinrtcameracontrol.h @@ -60,6 +60,7 @@ QT_BEGIN_NAMESPACE class QVideoRendererControl; class QVideoDeviceSelectorControl; class QCameraImageCaptureControl; +class QImageEncoderControl; class QWinRTCameraControlPrivate; class QWinRTCameraControl : public QCameraControl @@ -83,9 +84,9 @@ public: QVideoRendererControl *videoRenderer() const; QVideoDeviceSelectorControl *videoDeviceSelector() const; QCameraImageCaptureControl *imageCaptureControl() const; + QImageEncoderControl *imageEncoderControl() const; ABI::Windows::Media::Capture::IMediaCapture *handle() const; - QSize imageSize() const; private slots: void onBufferRequested(); diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp index 104484a6..5a1c27b5 100644 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp +++ b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp @@ -36,6 +36,7 @@ #include "qwinrtcameraimagecapturecontrol.h" #include "qwinrtcameracontrol.h" +#include "qwinrtimageencodercontrol.h" #include #include @@ -166,7 +167,7 @@ int QWinRTCameraImageCaptureControl::capture(const QString &fileName) hr = g->encodingPropertiesFactory->CreateBmp(&request.imageFormat); Q_ASSERT_SUCCEEDED(hr); - const QSize imageSize = d->cameraControl->imageSize(); + const QSize imageSize = static_cast(d->cameraControl->imageEncoderControl())->imageSettings().resolution(); hr = request.imageFormat->put_Width(imageSize.width()); Q_ASSERT_SUCCEEDED(hr); hr = request.imageFormat->put_Height(imageSize.height()); @@ -174,6 +175,10 @@ int QWinRTCameraImageCaptureControl::capture(const QString &fileName) hr = capture->CapturePhotoToStreamAsync(request.imageFormat.Get(), request.stream.Get(), &request.op); Q_ASSERT_SUCCEEDED(hr); + if (!request.op) { + qErrnoWarning("Camera photo capture failed."); + return -1; + } d->requests.insert(request.op.Get(), request); hr = request.op->put_Completed(Callback( @@ -266,7 +271,28 @@ HRESULT QWinRTCameraImageCaptureControl::onCaptureCompleted(IAsyncAction *asyncI const QImage image(pixelData, pixelWidth, pixelHeight, QImage::Format_RGBA8888, reinterpret_cast(&CoTaskMemFree), pixelData); emit imageCaptured(request.id, image); - if (image.save(request.fileName)) + + QWinRTImageEncoderControl *imageEncoderControl = static_cast(d->cameraControl->imageEncoderControl()); + int imageQuality = 100; + switch (imageEncoderControl->imageSettings().quality()) { + case QMultimedia::VeryLowQuality: + imageQuality = 20; + break; + case QMultimedia::LowQuality: + imageQuality = 40; + break; + case QMultimedia::NormalQuality: + imageQuality = 60; + break; + case QMultimedia::HighQuality: + imageQuality = 80; + break; + case QMultimedia::VeryHighQuality: + imageQuality = 100; + break; + } + + if (image.save(request.fileName, imageEncoderControl->imageSettings().codec().toLatin1().data(), imageQuality)) emit imageSaved(request.id, request.fileName); else emit error(request.id, QCameraImageCapture::ResourceError, tr("Image saving failed")); diff --git a/src/plugins/winrt/qwinrtcameraservice.cpp b/src/plugins/winrt/qwinrtcameraservice.cpp index 09b56575..dc9d6ee6 100644 --- a/src/plugins/winrt/qwinrtcameraservice.cpp +++ b/src/plugins/winrt/qwinrtcameraservice.cpp @@ -44,6 +44,7 @@ #include #include #include +#include QT_USE_NAMESPACE @@ -90,6 +91,11 @@ QMediaControl *QWinRTCameraService::requestControl(const char *name) return d->cameraControl->imageCaptureControl(); } + if (qstrcmp(name, QImageEncoderControl_iid) == 0) { + if (d->cameraControl) + return d->cameraControl->imageEncoderControl(); + } + return Q_NULLPTR; } diff --git a/src/plugins/winrt/qwinrtimageencodercontrol.cpp b/src/plugins/winrt/qwinrtimageencodercontrol.cpp new file mode 100644 index 00000000..0ab7a7cf --- /dev/null +++ b/src/plugins/winrt/qwinrtimageencodercontrol.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwinrtimageencodercontrol.h" +QT_BEGIN_NAMESPACE + +class QWinRTImageEncoderControlPrivate +{ +public: + QList supportedResolutions; + QImageEncoderSettings imageEncoderSetting; +}; + +QWinRTImageEncoderControl::QWinRTImageEncoderControl(QObject *parent) + : QImageEncoderControl(parent), d_ptr(new QWinRTImageEncoderControlPrivate) +{ +} + +QStringList QWinRTImageEncoderControl::supportedImageCodecs() const +{ + return QStringList() << QStringLiteral("jpeg"); +} + +QString QWinRTImageEncoderControl::imageCodecDescription(const QString &codecName) const +{ + if (codecName == QStringLiteral("jpeg")) + return tr("JPEG image"); + + return QString(); +} + +QList QWinRTImageEncoderControl::supportedResolutions(const QImageEncoderSettings &settings, bool *continuous) const +{ + Q_UNUSED(settings); + Q_D(const QWinRTImageEncoderControl); + + if (continuous) + *continuous = false; + + return d->supportedResolutions; +} + +QImageEncoderSettings QWinRTImageEncoderControl::imageSettings() const +{ + Q_D(const QWinRTImageEncoderControl); + return d->imageEncoderSetting; +} + +void QWinRTImageEncoderControl::setImageSettings(const QImageEncoderSettings &settings) +{ + Q_D(QWinRTImageEncoderControl); + if (d->imageEncoderSetting == settings) + return; + + d->imageEncoderSetting = settings; + applySettings(); +} + +void QWinRTImageEncoderControl::setSupportedResolutionsList(const QList resolution) +{ + Q_D(QWinRTImageEncoderControl); + d->supportedResolutions = resolution; + applySettings(); +} + +void QWinRTImageEncoderControl::applySettings() +{ + Q_D(QWinRTImageEncoderControl); + d->imageEncoderSetting.setCodec(QStringLiteral("jpeg")); + + QSize requestResolution = d->imageEncoderSetting.resolution(); + if (d->supportedResolutions.isEmpty() || d->supportedResolutions.contains(requestResolution)) + return; + + if (!requestResolution.isValid()) + requestResolution = QSize(0, 0);// Find the minimal available resolution + + // Find closest resolution from the list + const int pixelCount = requestResolution.width() * requestResolution.height(); + int minPixelCountGap = -1; + for (int i = 0; i < d->supportedResolutions.size(); ++i) { + int gap = qAbs(pixelCount - d->supportedResolutions.at(i).width() * d->supportedResolutions.at(i).height()); + if (gap < minPixelCountGap || minPixelCountGap < 0) { + minPixelCountGap = gap; + requestResolution = d->supportedResolutions.at(i); + } + } + d->imageEncoderSetting.setResolution(requestResolution); +} + +QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtimageencodercontrol.h b/src/plugins/winrt/qwinrtimageencodercontrol.h new file mode 100644 index 00000000..7682e762 --- /dev/null +++ b/src/plugins/winrt/qwinrtimageencodercontrol.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd and/or its subsidiary(-ies). +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL3$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPLv3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or later as published by the Free +** Software Foundation and appearing in the file LICENSE.GPL included in +** the packaging of this file. Please review the following information to +** ensure the GNU General Public License version 2.0 requirements will be +** met: http://www.gnu.org/licenses/gpl-2.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWINRTIMAGEENCODERCONTROL_H +#define QWINRTIMAGEENCODERCONTROL_H + +#include + +QT_BEGIN_NAMESPACE + +class QWinRTImageEncoderControlPrivate; +class QWinRTImageEncoderControl : public QImageEncoderControl +{ +public: + explicit QWinRTImageEncoderControl(QObject *parent = 0); + + QStringList supportedImageCodecs() const Q_DECL_OVERRIDE; + QString imageCodecDescription(const QString &codecName) const Q_DECL_OVERRIDE; + QList supportedResolutions(const QImageEncoderSettings &settings, bool *continuous = 0) const Q_DECL_OVERRIDE; + QImageEncoderSettings imageSettings() const Q_DECL_OVERRIDE; + void setImageSettings(const QImageEncoderSettings &settings) Q_DECL_OVERRIDE; + + void setSupportedResolutionsList(const QList resolution); + void applySettings(); + +private: + QScopedPointer d_ptr; + Q_DECLARE_PRIVATE(QWinRTImageEncoderControl) +}; + +QT_END_NAMESPACE + +#endif // QWINRTIMAGEENCODERCONTROL_H diff --git a/src/plugins/winrt/winrt.pro b/src/plugins/winrt/winrt.pro index 04db71e7..58c2371f 100644 --- a/src/plugins/winrt/winrt.pro +++ b/src/plugins/winrt/winrt.pro @@ -18,7 +18,8 @@ HEADERS += \ qwinrtmediaplayerservice.h \ qwinrtplayerrenderercontrol.h \ qwinrtserviceplugin.h \ - qwinrtvideodeviceselectorcontrol.h + qwinrtvideodeviceselectorcontrol.h \ + qwinrtimageencodercontrol.h SOURCES += \ qwinrtabstractvideorenderercontrol.cpp \ @@ -31,7 +32,8 @@ SOURCES += \ qwinrtmediaplayerservice.cpp \ qwinrtplayerrenderercontrol.cpp \ qwinrtserviceplugin.cpp \ - qwinrtvideodeviceselectorcontrol.cpp + qwinrtvideodeviceselectorcontrol.cpp \ + qwinrtimageencodercontrol.cpp OTHER_FILES += \ winrt.json From 9fdc4a3a635f094557c210408a600dde15a00935 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Mon, 29 Jun 2015 10:47:53 +0200 Subject: [PATCH 17/17] Bump version Change-Id: I0dbadc590809bed7a24a8721a3b4a42a207bcc7b --- .qmake.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.qmake.conf b/.qmake.conf index 068da422..fd7c2fa9 100644 --- a/.qmake.conf +++ b/.qmake.conf @@ -1,4 +1,4 @@ load(qt_build_config) CONFIG += qt_example_installs -MODULE_VERSION = 5.5.0 +MODULE_VERSION = 5.5.1