diff options
author | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-06-24 12:47:16 +0200 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-06-25 00:03:36 +0200 |
commit | 2c9a117e49497c55a22621d86d452fa7c22a489b (patch) | |
tree | 7600e779ce48889fe94c1100aae192bba3711531 /src/plugins | |
parent | 6b88fadec90fd82ad1ad87533c59a54baa9df695 (diff) | |
download | qtmultimedia-2c9a117e49497c55a22621d86d452fa7c22a489b.tar.gz |
Remove winrt plugin
WinRT has been removed already
Task-number: QTBUG-74423
Change-Id: Ia1269a52f02a24ba67e08e6cc1f451ba50b55fdd
Reviewed-by: Val Doroshchuk <valentyn.doroshchuk@qt.io>
Diffstat (limited to 'src/plugins')
35 files changed, 1 insertions, 6713 deletions
diff --git a/src/plugins/plugins.pro b/src/plugins/plugins.pro index 8c173cbc4..a087e8182 100644 --- a/src/plugins/plugins.pro +++ b/src/plugins/plugins.pro @@ -26,7 +26,7 @@ qnx { SUBDIRS += qnx-audio } -win32:!winrt { +win32: { SUBDIRS += audiocapture \ windowsaudio @@ -34,12 +34,6 @@ win32:!winrt { qtConfig(wmf): SUBDIRS += wmf } - -winrt { - SUBDIRS += winrt \ - audiocapture -} - qtConfig(gstreamer): SUBDIRS += gstreamer unix:!mac:!android { diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp deleted file mode 100644 index 654d0e605..000000000 --- a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp +++ /dev/null @@ -1,489 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtabstractvideorenderercontrol.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QGlobalStatic> -#include <QtCore/QLoggingCategory> -#include <QtCore/QMetaMethod> -#include <QtCore/QMutexLocker> -#include <QtCore/QPointer> -#include <QtGui/QOpenGLContext> -#include <QtGui/QOpenGLTexture> -#include <QtMultimedia/QAbstractVideoBuffer> -#include <QtMultimedia/QAbstractVideoSurface> -#include <QtMultimedia/QVideoSurfaceFormat> - -#define EGL_EGLEXT_PROTOTYPES -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include <d3d11.h> -#include <mfapi.h> -#include <wrl.h> - -using namespace Microsoft::WRL; - -QT_BEGIN_NAMESPACE - -Q_LOGGING_CATEGORY(lcMMVideoRender, "qt.mm.videorender") - -#define BREAK_IF_FAILED(msg) RETURN_IF_FAILED(msg, break) -#define CONTINUE_IF_FAILED(msg) RETURN_IF_FAILED(msg, continue) - -// Global D3D device to be shared between video surfaces -struct QWinRTVideoRendererControlGlobal -{ - QWinRTVideoRendererControlGlobal() - { - qCDebug(lcMMVideoRender) << __FUNCTION__; - HRESULT hr; - - D3D_FEATURE_LEVEL featureLevels[] = - { - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - D3D_FEATURE_LEVEL_10_1, - D3D_FEATURE_LEVEL_10_0, - D3D_FEATURE_LEVEL_9_3, - D3D_FEATURE_LEVEL_9_2, - D3D_FEATURE_LEVEL_9_1 - }; - - UINT flags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT; -#ifdef _DEBUG - flags |= D3D11_CREATE_DEVICE_DEBUG; -#endif - hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, flags, - featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, - &device, &featureLevel, &context); -#ifdef _DEBUG - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to create D3D device with device debug flag"); - hr = D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_VIDEO_SUPPORT, - featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, - &device, &featureLevel, &context); - } -#endif - if (FAILED(hr)) - qErrnoWarning(hr, "Failed to create D3D device"); - - if (!device || FAILED(hr)) { - hr = D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_WARP, nullptr, flags, - featureLevels, ARRAYSIZE(featureLevels), D3D11_SDK_VERSION, - &device, &featureLevel, &context); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to create software D3D device"); - return; - } - } - - ComPtr<ID3D10Multithread> multithread; - hr = device.As(&multithread); - Q_ASSERT_SUCCEEDED(hr); - hr = multithread->SetMultithreadProtected(true); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IDXGIDevice> dxgiDevice; - hr = device.As(&dxgiDevice); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IDXGIAdapter> adapter; - hr = dxgiDevice->GetAdapter(&adapter); - Q_ASSERT_SUCCEEDED(hr); - hr = adapter->EnumOutputs(0, &output); - Q_ASSERT_SUCCEEDED(hr); - } - - ComPtr<ID3D11Device> device; - ComPtr<ID3D11DeviceContext> context; - D3D_FEATURE_LEVEL featureLevel; - ComPtr<IDXGIOutput> output; -}; -Q_GLOBAL_STATIC(QWinRTVideoRendererControlGlobal, g) - -class QWinRTVideoBuffer : public QAbstractVideoBuffer, public QOpenGLTexture -{ -public: - QWinRTVideoBuffer(const QSize &size, TextureFormat format) - : QAbstractVideoBuffer(QAbstractVideoBuffer::GLTextureHandle) - , QOpenGLTexture(QOpenGLTexture::Target2D) - { - setSize(size.width(), size.height()); - setFormat(format); - create(); - } - - MapMode mapMode() const override - { - return NotMapped; - } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override - { - Q_UNUSED(mode); - Q_UNUSED(numBytes); - Q_UNUSED(bytesPerLine); - return nullptr; - } - - void unmap() override - { - } - - QVariant handle() const override - { - return QVariant::fromValue(textureId()); - } -}; - -enum DirtyState { - NotDirty, // All resources have been created - TextureDirty, // The shared D3D texture needs to be recreated - SurfaceDirty // The shared EGL surface needs to be recreated -}; - -class QWinRTAbstractVideoRendererControlPrivate -{ -public: - QPointer<QAbstractVideoSurface> surface; - QVideoSurfaceFormat format; - - DirtyState dirtyState; - - HANDLE shareHandle; - ComPtr<ID3D11Texture2D> texture; - - EGLDisplay eglDisplay; - EGLConfig eglConfig; - EGLSurface eglSurface; - - QVideoFrame presentFrame; - - QThread renderThread; - bool active; - QWinRTAbstractVideoRendererControl::BlitMode blitMode; - QMutex mutex; -}; - -ID3D11Device *QWinRTAbstractVideoRendererControl::d3dDevice() -{ - return g->device.Get(); -} - -// This is required so that subclasses can stop the render thread before deletion -void QWinRTAbstractVideoRendererControl::shutdown() -{ - qCDebug(lcMMVideoRender) << __FUNCTION__; - Q_D(QWinRTAbstractVideoRendererControl); - if (d->renderThread.isRunning()) { - d->renderThread.requestInterruption(); - d->renderThread.wait(); - } -} - -QWinRTAbstractVideoRendererControl::QWinRTAbstractVideoRendererControl(const QSize &size, QObject *parent) - : QVideoRendererControl(parent), d_ptr(new QWinRTAbstractVideoRendererControlPrivate) -{ - qCDebug(lcMMVideoRender) << __FUNCTION__; - Q_D(QWinRTAbstractVideoRendererControl); - - d->format = QVideoSurfaceFormat(size, QVideoFrame::Format_BGRA32, - QAbstractVideoBuffer::GLTextureHandle); - d->dirtyState = TextureDirty; - d->shareHandle = nullptr; - d->eglDisplay = EGL_NO_DISPLAY; - d->eglConfig = nullptr; - d->eglSurface = EGL_NO_SURFACE; - d->active = false; - d->blitMode = DirectVideo; - - connect(&d->renderThread, &QThread::started, - this, &QWinRTAbstractVideoRendererControl::syncAndRender, - Qt::DirectConnection); -} - -QWinRTAbstractVideoRendererControl::~QWinRTAbstractVideoRendererControl() -{ - qCDebug(lcMMVideoRender) << __FUNCTION__; - Q_D(QWinRTAbstractVideoRendererControl); - QMutexLocker locker(&d->mutex); - shutdown(); - locker.unlock(); - eglDestroySurface(d->eglDisplay, d->eglSurface); -} - -QAbstractVideoSurface *QWinRTAbstractVideoRendererControl::surface() const -{ - Q_D(const QWinRTAbstractVideoRendererControl); - return d->surface; -} - -void QWinRTAbstractVideoRendererControl::setSurface(QAbstractVideoSurface *surface) -{ - Q_D(QWinRTAbstractVideoRendererControl); - d->surface = surface; -} - -void QWinRTAbstractVideoRendererControl::syncAndRender() -{ - qCDebug(lcMMVideoRender) << __FUNCTION__; - Q_D(QWinRTAbstractVideoRendererControl); - - QThread *currentThread = QThread::currentThread(); - const QMetaMethod present = staticMetaObject.method(staticMetaObject.indexOfMethod("present()")); - forever { - if (currentThread->isInterruptionRequested()) - break; - { - QMutexLocker lock(&d->mutex); - HRESULT hr; - if (d->dirtyState == TextureDirty) { - CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, d->format.frameWidth(), d->format.frameHeight(), 1, 1); - desc.BindFlags |= D3D11_BIND_RENDER_TARGET; - desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED; - hr = g->device->CreateTexture2D(&desc, nullptr, d->texture.ReleaseAndGetAddressOf()); - BREAK_IF_FAILED("Failed to get create video texture"); - ComPtr<IDXGIResource> resource; - hr = d->texture.As(&resource); - BREAK_IF_FAILED("Failed to cast texture to resource"); - hr = resource->GetSharedHandle(&d->shareHandle); - BREAK_IF_FAILED("Failed to get texture share handle"); - d->dirtyState = SurfaceDirty; - } - - hr = g->output->WaitForVBlank(); - CONTINUE_IF_FAILED("Failed to wait for vertical blank"); - - bool success = false; - switch (d->blitMode) { - case DirectVideo: - success = render(d->texture.Get()); - break; - case MediaFoundation: - success = dequeueFrame(&d->presentFrame); - break; - default: - success = false; - } - - if (!success) - continue; - - // Queue to the control's thread for presentation - present.invoke(this, Qt::QueuedConnection); - currentThread->eventDispatcher()->processEvents(QEventLoop::AllEvents); - } - } - - // All done, exit render loop - currentThread->quit(); -} - -QSize QWinRTAbstractVideoRendererControl::size() const -{ - Q_D(const QWinRTAbstractVideoRendererControl); - return d->format.frameSize(); -} - -void QWinRTAbstractVideoRendererControl::setSize(const QSize &size) -{ - Q_D(QWinRTAbstractVideoRendererControl); - - if (d->format.frameSize() == size) - return; - - d->format.setFrameSize(size); - d->dirtyState = TextureDirty; -} - -void QWinRTAbstractVideoRendererControl::setScanLineDirection(QVideoSurfaceFormat::Direction scanLineDirection) -{ - Q_D(QWinRTAbstractVideoRendererControl); - - if (d->format.scanLineDirection() == scanLineDirection) - return; - - d->format.setScanLineDirection(scanLineDirection); -} - -void QWinRTAbstractVideoRendererControl::setActive(bool active) -{ - qCDebug(lcMMVideoRender) << __FUNCTION__ << active; - Q_D(QWinRTAbstractVideoRendererControl); - - if (d->active == active) - return; - - d->active = active; - if (d->active) { - if (!d->surface) - return; - - // This only happens for quick restart scenarios, for instance - // when switching cameras. - if (d->renderThread.isRunning() && d->renderThread.isInterruptionRequested()) { - QMutexLocker lock(&d->mutex); - d->renderThread.wait(); - } - - if (!d->surface->isActive()) - d->surface->start(d->format); - - d->renderThread.start(); - return; - } - - d->renderThread.requestInterruption(); - - if (d->surface && d->surface->isActive()) - d->surface->stop(); -} - -QWinRTAbstractVideoRendererControl::BlitMode QWinRTAbstractVideoRendererControl::blitMode() const -{ - Q_D(const QWinRTAbstractVideoRendererControl); - return d->blitMode; -} - -void QWinRTAbstractVideoRendererControl::setBlitMode(QWinRTAbstractVideoRendererControl::BlitMode mode) -{ - Q_D(QWinRTAbstractVideoRendererControl); - QMutexLocker lock(&d->mutex); - - if (d->blitMode == mode) - return; - - d->blitMode = mode; - d->dirtyState = d->blitMode == MediaFoundation ? NotDirty : TextureDirty; - - if (d->blitMode == DirectVideo) - return; - - if (d->texture) { - d->texture.Reset(); - d->shareHandle = nullptr; - } - - if (d->eglSurface) { - eglDestroySurface(d->eglDisplay, d->eglSurface); - d->eglSurface = EGL_NO_SURFACE; - } -} - -bool QWinRTAbstractVideoRendererControl::dequeueFrame(QVideoFrame *frame) -{ - Q_UNUSED(frame) - return false; -} - -void QWinRTAbstractVideoRendererControl::textureToFrame() -{ - Q_D(QWinRTAbstractVideoRendererControl); - - if (d->dirtyState == SurfaceDirty) { - if (!QOpenGLContext::currentContext()) { - qWarning("A valid OpenGL context is required for binding the video texture."); - return; - } - - if (d->eglDisplay == EGL_NO_DISPLAY) - d->eglDisplay = eglGetCurrentDisplay(); - - if (d->eglDisplay == EGL_NO_DISPLAY) { - qWarning("Failed to get the current EGL display for video presentation: 0x%x", eglGetError()); - return; - } - - EGLint configAttributes[] = { - EGL_RED_SIZE, 8, - EGL_GREEN_SIZE, 8, - EGL_BLUE_SIZE, 8, - EGL_ALPHA_SIZE, 8, - EGL_BIND_TO_TEXTURE_RGBA, EGL_TRUE, - EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, - EGL_NONE - }; - EGLint configCount; - if (!eglChooseConfig(d->eglDisplay, configAttributes, &d->eglConfig, 1, &configCount)) { - qWarning("Failed to create the texture EGL configuration for video presentation: 0x%x", eglGetError()); - return; - } - - if (d->eglSurface != EGL_NO_SURFACE) - eglDestroySurface(d->eglDisplay, d->eglSurface); - - EGLint bufferAttributes[] = { - EGL_WIDTH, d->format.frameWidth(), - EGL_HEIGHT, d->format.frameHeight(), - EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, - EGL_TEXTURE_TARGET, EGL_TEXTURE_2D, - EGL_NONE - }; - d->eglSurface = eglCreatePbufferFromClientBuffer(d->eglDisplay, - EGL_D3D_TEXTURE_2D_SHARE_HANDLE_ANGLE, - d->shareHandle, d->eglConfig, bufferAttributes); - if (d->eglSurface == EGL_NO_SURFACE) { - qWarning("Failed to create the EGL configuration for video presentation: 0x%x", eglGetError()); - return; - } - - QWinRTVideoBuffer *videoBuffer = new QWinRTVideoBuffer(d->format.frameSize(), QOpenGLTexture::RGBAFormat); - d->presentFrame = QVideoFrame(videoBuffer, d->format.frameSize(), d->format.pixelFormat()); - - // bind the pbuffer surface to the texture - videoBuffer->bind(); - eglBindTexImage(d->eglDisplay, d->eglSurface, EGL_BACK_BUFFER); - static_cast<QOpenGLTexture *>(videoBuffer)->release(); - - d->dirtyState = NotDirty; - } -} - -void QWinRTAbstractVideoRendererControl::present() -{ - Q_D(QWinRTAbstractVideoRendererControl); - if (d->blitMode == DirectVideo) - textureToFrame(); - - // Present the frame - d->surface->present(d->presentFrame); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h deleted file mode 100644 index 819dd9c3a..000000000 --- a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h +++ /dev/null @@ -1,101 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTABSTRACTVIDEORENDERERCONTROL_H -#define QWINRTABSTRACTVIDEORENDERERCONTROL_H - -#include <QtMultimedia/QVideoRendererControl> -#include <QtMultimedia/QVideoSurfaceFormat> - -#include <qt_windows.h> - -struct ID3D11Device; -struct ID3D11Texture2D; - -QT_BEGIN_NAMESPACE - -class QWinRTAbstractVideoRendererControlPrivate; -class QWinRTAbstractVideoRendererControl : public QVideoRendererControl -{ - Q_OBJECT -public: - explicit QWinRTAbstractVideoRendererControl(const QSize &size, QObject *parent = nullptr); - ~QWinRTAbstractVideoRendererControl() override; - - enum BlitMode { - DirectVideo, - MediaFoundation - }; - - QAbstractVideoSurface *surface() const override; - void setSurface(QAbstractVideoSurface *surface) override; - - QSize size() const; - void setSize(const QSize &size); - - void setScanLineDirection(QVideoSurfaceFormat::Direction direction); - - BlitMode blitMode() const; - void setBlitMode(BlitMode mode); - - virtual bool render(ID3D11Texture2D *texture) = 0; - virtual bool dequeueFrame(QVideoFrame *frame); - - static ID3D11Device *d3dDevice(); - -public slots: - void setActive(bool active); - -protected: - void shutdown(); - -private slots: - void syncAndRender(); - -private: - void textureToFrame(); - Q_INVOKABLE void present(); - - QScopedPointer<QWinRTAbstractVideoRendererControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTAbstractVideoRendererControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTABSTRACTVIDEORENDERERCONTROL_H diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp deleted file mode 100644 index 98dd7c2f7..000000000 --- a/src/plugins/winrt/qwinrtcameracontrol.cpp +++ /dev/null @@ -1,1468 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcameracontrol.h" -#include "qwinrtcameravideorenderercontrol.h" -#include "qwinrtvideodeviceselectorcontrol.h" -#include "qwinrtcameraimagecapturecontrol.h" -#include "qwinrtimageencodercontrol.h" -#include "qwinrtcameraflashcontrol.h" -#include "qwinrtcamerafocuscontrol.h" -#include "qwinrtcameralockscontrol.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QMutex> -#include <QtCore/QPointer> -#include <QtGui/QGuiApplication> -#include <private/qeventdispatcher_winrt_p.h> - -#include <functional> -#include <mfapi.h> -#include <mferror.h> -#include <mfidl.h> -#include <wrl.h> -#include <windows.devices.enumeration.h> -#include <windows.media.capture.h> -#include <windows.storage.streams.h> -#include <windows.media.devices.h> - -#include <algorithm> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Devices::Enumeration; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace ABI::Windows::Media; -using namespace ABI::Windows::Media::Capture; -using namespace ABI::Windows::Media::Devices; -using namespace ABI::Windows::Media::MediaProperties; -using namespace ABI::Windows::Storage::Streams; - -QT_BEGIN_NAMESPACE - -#define RETURN_VOID_AND_EMIT_ERROR(msg) \ - if (FAILED(hr)) { \ - emit error(QCamera::CameraError, qt_error_string(hr)); \ - RETURN_VOID_IF_FAILED(msg); \ - } - -#define FOCUS_RECT_SIZE 0.01f -#define FOCUS_RECT_HALF_SIZE 0.005f // FOCUS_RECT_SIZE / 2 -#define FOCUS_RECT_BOUNDARY 1.0f -#define FOCUS_RECT_POSITION_MIN 0.0f -#define FOCUS_RECT_POSITION_MAX 0.995f // FOCUS_RECT_BOUNDARY - FOCUS_RECT_HALF_SIZE -#define ASPECTRATIO_EPSILON 0.01f - -Q_LOGGING_CATEGORY(lcMMCamera, "qt.mm.camera") - -HRESULT getMediaStreamResolutions(IMediaDeviceController *device, - MediaStreamType type, - IVectorView<IMediaEncodingProperties *> **propertiesList, - QVector<QSize> *resolutions) -{ - HRESULT hr; - hr = device->GetAvailableMediaStreamProperties(type, propertiesList); - Q_ASSERT_SUCCEEDED(hr); - quint32 listSize; - hr = (*propertiesList)->get_Size(&listSize); - Q_ASSERT_SUCCEEDED(hr); - resolutions->reserve(int(listSize)); - for (quint32 index = 0; index < listSize; ++index) { - ComPtr<IMediaEncodingProperties> properties; - hr = (*propertiesList)->GetAt(index, &properties); - Q_ASSERT_SUCCEEDED(hr); - HString propertyType; - hr = properties->get_Type(propertyType.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - const HStringReference videoRef = HString::MakeReference(L"Video"); - const HStringReference imageRef = HString::MakeReference(L"Image"); - if (propertyType == videoRef) { - ComPtr<IVideoEncodingProperties> videoProperties; - hr = properties.As(&videoProperties); - Q_ASSERT_SUCCEEDED(hr); - UINT32 width, height; - hr = videoProperties->get_Width(&width); - Q_ASSERT_SUCCEEDED(hr); - hr = videoProperties->get_Height(&height); - Q_ASSERT_SUCCEEDED(hr); - resolutions->append(QSize(int(width), int(height))); - } else if (propertyType == imageRef) { - ComPtr<IImageEncodingProperties> imageProperties; - hr = properties.As(&imageProperties); - Q_ASSERT_SUCCEEDED(hr); - UINT32 width, height; - hr = imageProperties->get_Width(&width); - Q_ASSERT_SUCCEEDED(hr); - hr = imageProperties->get_Height(&height); - Q_ASSERT_SUCCEEDED(hr); - resolutions->append(QSize(int(width), int(height))); - } - } - return resolutions->isEmpty() ? MF_E_INVALID_FORMAT : hr; -} - -template<typename T, size_t typeSize> struct CustomPropertyValue; - -inline static ComPtr<IPropertyValueStatics> propertyValueStatics() -{ - ComPtr<IPropertyValueStatics> valueStatics; - GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Foundation_PropertyValue).Get(), &valueStatics); - return valueStatics; -} - -template <typename T> -struct CustomPropertyValue<T, 4> -{ - static ComPtr<IReference<T>> create(T value) - { - ComPtr<IInspectable> propertyValueObject; - HRESULT hr = propertyValueStatics()->CreateUInt32(value, &propertyValueObject); - ComPtr<IReference<UINT32>> uint32Object; - Q_ASSERT_SUCCEEDED(hr); - hr = propertyValueObject.As(&uint32Object); - Q_ASSERT_SUCCEEDED(hr); - return reinterpret_cast<IReference<T> *>(uint32Object.Get()); - } -}; - -template <typename T> -struct CustomPropertyValue<T, 8> -{ - static ComPtr<IReference<T>> create(T value) - { - ComPtr<IInspectable> propertyValueObject; - HRESULT hr = propertyValueStatics()->CreateUInt64(value, &propertyValueObject); - ComPtr<IReference<UINT64>> uint64Object; - Q_ASSERT_SUCCEEDED(hr); - hr = propertyValueObject.As(&uint64Object); - Q_ASSERT_SUCCEEDED(hr); - return reinterpret_cast<IReference<T> *>(uint64Object.Get()); - } -}; - -// Required camera point focus -class WindowsRegionOfInterestIterableIterator : public RuntimeClass<IIterator<RegionOfInterest *>> -{ -public: - explicit WindowsRegionOfInterestIterableIterator(const ComPtr<IRegionOfInterest> &item) - { - regionOfInterest = item; - } - HRESULT __stdcall get_Current(IRegionOfInterest **current) - { - *current = regionOfInterest.Detach(); - return S_OK; - } - HRESULT __stdcall get_HasCurrent(boolean *hasCurrent) - { - *hasCurrent = true; - return S_OK; - } - HRESULT __stdcall MoveNext(boolean *hasCurrent) - { - *hasCurrent = false; - return S_OK; - } -private: - ComPtr<IRegionOfInterest> regionOfInterest; -}; - -class WindowsRegionOfInterestIterable : public RuntimeClass<IIterable<RegionOfInterest *>> -{ -public: - explicit WindowsRegionOfInterestIterable(const ComPtr<IRegionOfInterest> &item) - { - regionOfInterest = item; - } - HRESULT __stdcall First(IIterator<RegionOfInterest *> **first) - { - ComPtr<WindowsRegionOfInterestIterableIterator> iterator = Make<WindowsRegionOfInterestIterableIterator>(regionOfInterest); - *first = iterator.Detach(); - return S_OK; - } -private: - ComPtr<IRegionOfInterest> regionOfInterest; -}; - -class MediaStream : public RuntimeClass<RuntimeClassFlags<WinRtClassicComMix>, IMFStreamSink, IMFMediaEventGenerator, IMFMediaTypeHandler> -{ -public: - MediaStream(IMFMediaType *type, IMFMediaSink *mediaSink, QWinRTCameraVideoRendererControl *videoRenderer) - : m_type(type), m_sink(mediaSink), m_videoRenderer(videoRenderer) - { - Q_ASSERT(m_videoRenderer); - - HRESULT hr; - hr = MFCreateEventQueue(&m_eventQueue); - Q_ASSERT_SUCCEEDED(hr); - hr = MFAllocateSerialWorkQueue(MFASYNC_CALLBACK_QUEUE_STANDARD, &m_workQueueId); - Q_ASSERT_SUCCEEDED(hr); - } - - ~MediaStream() override - { - QMutexLocker locker(&m_mutex); - m_eventQueue->Shutdown(); - } - - HRESULT RequestSample() - { - if (m_pendingSamples.load() < 3) { - m_pendingSamples.ref(); - return QueueEvent(MEStreamSinkRequestSample, GUID_NULL, S_OK, nullptr); - } - return S_OK; - } - - HRESULT __stdcall GetEvent(DWORD flags, IMFMediaEvent **event) override - { - QMutexLocker locker(&m_mutex); - // Create an extra reference to avoid deadlock - ComPtr<IMFMediaEventQueue> eventQueue = m_eventQueue; - locker.unlock(); - - return eventQueue->GetEvent(flags, event); - } - - HRESULT __stdcall BeginGetEvent(IMFAsyncCallback *callback, IUnknown *state) override - { - QMutexLocker locker(&m_mutex); - HRESULT hr = m_eventQueue->BeginGetEvent(callback, state); - return hr; - } - - HRESULT __stdcall EndGetEvent(IMFAsyncResult *result, IMFMediaEvent **event) override - { - QMutexLocker locker(&m_mutex); - return m_eventQueue->EndGetEvent(result, event); - } - - HRESULT __stdcall QueueEvent(MediaEventType eventType, const GUID &extendedType, HRESULT status, const PROPVARIANT *value) override - { - QMutexLocker locker(&m_mutex); - return m_eventQueue->QueueEventParamVar(eventType, extendedType, status, value); - } - - HRESULT __stdcall GetMediaSink(IMFMediaSink **mediaSink) override - { - m_sink->AddRef(); - *mediaSink = m_sink; - return S_OK; - } - - HRESULT __stdcall GetIdentifier(DWORD *identifier) override - { - *identifier = 0; - return S_OK; - } - - HRESULT __stdcall GetMediaTypeHandler(IMFMediaTypeHandler **handler) override - { - return QueryInterface(IID_PPV_ARGS(handler)); - } - - HRESULT __stdcall ProcessSample(IMFSample *sample) override - { - ComPtr<IMFMediaBuffer> buffer; - HRESULT hr = sample->GetBufferByIndex(0, &buffer); - RETURN_HR_IF_FAILED("Failed to get buffer from camera sample"); - ComPtr<IMF2DBuffer> buffer2d; - hr = buffer.As(&buffer2d); - RETURN_HR_IF_FAILED("Failed to cast camera sample buffer to 2D buffer"); - - m_pendingSamples.deref(); - m_videoRenderer->queueBuffer(buffer2d.Get()); - - return hr; - } - - HRESULT __stdcall PlaceMarker(MFSTREAMSINK_MARKER_TYPE type, const PROPVARIANT *value, const PROPVARIANT *context) override - { - Q_UNUSED(type); - Q_UNUSED(value); - QueueEvent(MEStreamSinkMarker, GUID_NULL, S_OK, context); - return S_OK; - } - - HRESULT __stdcall Flush() override - { - m_videoRenderer->discardBuffers(); - m_pendingSamples.store(0); - return S_OK; - } - - HRESULT __stdcall IsMediaTypeSupported(IMFMediaType *type, IMFMediaType **) override - { - HRESULT hr; - GUID majorType; - hr = type->GetMajorType(&majorType); - Q_ASSERT_SUCCEEDED(hr); - if (!IsEqualGUID(majorType, MFMediaType_Video)) - return MF_E_INVALIDMEDIATYPE; - return S_OK; - } - - HRESULT __stdcall GetMediaTypeCount(DWORD *typeCount) override - { - *typeCount = 1; - return S_OK; - } - - HRESULT __stdcall GetMediaTypeByIndex(DWORD index, IMFMediaType **type) override - { - if (index == 0) - return m_type.CopyTo(type); - return E_BOUNDS; - } - - HRESULT __stdcall SetCurrentMediaType(IMFMediaType *type) override - { - if (FAILED(IsMediaTypeSupported(type, nullptr))) - return MF_E_INVALIDREQUEST; - - m_type = type; - return S_OK; - } - - HRESULT __stdcall GetCurrentMediaType(IMFMediaType **type) override - { - return m_type.CopyTo(type); - } - - HRESULT __stdcall GetMajorType(GUID *majorType) override - { - return m_type->GetMajorType(majorType); - } - -private: - QMutex m_mutex; - ComPtr<IMFMediaType> m_type; - IMFMediaSink *m_sink; - ComPtr<IMFMediaEventQueue> m_eventQueue; - DWORD m_workQueueId; - - QWinRTCameraVideoRendererControl *m_videoRenderer; - QAtomicInt m_pendingSamples; -}; - -class MediaSink : public RuntimeClass<RuntimeClassFlags<WinRtClassicComMix>, IMediaExtension, IMFMediaSink, IMFClockStateSink> -{ -public: - MediaSink(IMediaEncodingProfile *encodingProfile, QWinRTCameraVideoRendererControl *videoRenderer) - : m_videoRenderer(videoRenderer) - { - HRESULT hr; - ComPtr<IVideoEncodingProperties> videoProperties; - hr = encodingProfile->get_Video(&videoProperties); - RETURN_VOID_IF_FAILED("Failed to get video properties"); - ComPtr<IMFMediaType> videoType; - hr = MFCreateMediaTypeFromProperties(videoProperties.Get(), &videoType); - RETURN_VOID_IF_FAILED("Failed to create video type"); - m_stream = Make<MediaStream>(videoType.Get(), this, videoRenderer); - } - - ~MediaSink() override = default; - - HRESULT RequestSample() - { - return m_stream->RequestSample(); - } - - HRESULT __stdcall SetProperties(Collections::IPropertySet *configuration) override - { - Q_UNUSED(configuration); - return E_NOTIMPL; - } - - HRESULT __stdcall GetCharacteristics(DWORD *characteristics) override - { - *characteristics = MEDIASINK_FIXED_STREAMS | MEDIASINK_RATELESS; - return S_OK; - } - - HRESULT __stdcall AddStreamSink(DWORD streamSinkIdentifier, IMFMediaType *mediaType, IMFStreamSink **streamSink) override - { - Q_UNUSED(streamSinkIdentifier); - Q_UNUSED(mediaType); - Q_UNUSED(streamSink); - return E_NOTIMPL; - } - - HRESULT __stdcall RemoveStreamSink(DWORD streamSinkIdentifier) override - { - Q_UNUSED(streamSinkIdentifier); - return E_NOTIMPL; - } - - HRESULT __stdcall GetStreamSinkCount(DWORD *streamSinkCount) override - { - *streamSinkCount = 1; - return S_OK; - } - - HRESULT __stdcall GetStreamSinkByIndex(DWORD index, IMFStreamSink **streamSink) override - { - if (index == 0) - return m_stream.CopyTo(streamSink); - return MF_E_INVALIDINDEX; - } - - HRESULT __stdcall GetStreamSinkById(DWORD streamSinkIdentifier, IMFStreamSink **streamSink) override - { - // ID and index are always 0 - HRESULT hr = GetStreamSinkByIndex(streamSinkIdentifier, streamSink); - return hr == MF_E_INVALIDINDEX ? MF_E_INVALIDSTREAMNUMBER : hr; - } - - HRESULT __stdcall SetPresentationClock(IMFPresentationClock *presentationClock) override - { - HRESULT hr = S_OK; - m_presentationClock = presentationClock; - if (m_presentationClock) - hr = m_presentationClock->AddClockStateSink(this); - return hr; - } - - HRESULT __stdcall GetPresentationClock(IMFPresentationClock **presentationClock) override - { - return m_presentationClock.CopyTo(presentationClock); - } - - HRESULT __stdcall Shutdown() override - { - m_stream->Flush(); - scheduleSetActive(false); - return m_presentationClock ? m_presentationClock->Stop() : S_OK; - } - - HRESULT __stdcall OnClockStart(MFTIME systemTime, LONGLONG clockStartOffset) override - { - Q_UNUSED(systemTime); - Q_UNUSED(clockStartOffset); - - scheduleSetActive(true); - - return S_OK; - } - - HRESULT __stdcall OnClockStop(MFTIME systemTime) override - { - Q_UNUSED(systemTime); - - scheduleSetActive(false); - - return m_stream->QueueEvent(MEStreamSinkStopped, GUID_NULL, S_OK, nullptr); - } - - HRESULT __stdcall OnClockPause(MFTIME systemTime) override - { - Q_UNUSED(systemTime); - - scheduleSetActive(false); - - return m_stream->QueueEvent(MEStreamSinkPaused, GUID_NULL, S_OK, nullptr); - } - - HRESULT __stdcall OnClockRestart(MFTIME systemTime) override - { - Q_UNUSED(systemTime); - - scheduleSetActive(true); - - return m_stream->QueueEvent(MEStreamSinkStarted, GUID_NULL, S_OK, nullptr); - } - - HRESULT __stdcall OnClockSetRate(MFTIME systemTime, float rate) override - { - Q_UNUSED(systemTime); - Q_UNUSED(rate); - return E_NOTIMPL; - } - -private: - - inline void scheduleSetActive(bool active) - { - QMetaObject::invokeMethod(m_videoRenderer, "setActive", Qt::QueuedConnection, Q_ARG(bool, active)); - } - - ComPtr<MediaStream> m_stream; - ComPtr<IMFPresentationClock> m_presentationClock; - - QWinRTCameraVideoRendererControl *m_videoRenderer; -}; - -class QWinRTCameraControlPrivate -{ -public: - QCamera::State state; - QCamera::Status status; - QCamera::CaptureModes captureMode; - - ComPtr<IMediaCapture> capture; - ComPtr<IMediaCaptureVideoPreview> capturePreview; - EventRegistrationToken captureFailedCookie; - EventRegistrationToken recordLimitationCookie; - - ComPtr<IMediaEncodingProfileStatics> encodingProfileFactory; - - ComPtr<IMediaEncodingProfile> encodingProfile; - ComPtr<MediaSink> mediaSink; - ComPtr<IFocusControl> focusControl; - ComPtr<IRegionsOfInterestControl> regionsOfInterestControl; - ComPtr<IAsyncAction> focusOperation; - - QPointer<QWinRTCameraVideoRendererControl> videoRenderer; - QPointer<QWinRTVideoDeviceSelectorControl> videoDeviceSelector; - QPointer<QWinRTCameraImageCaptureControl> imageCaptureControl; - QPointer<QWinRTImageEncoderControl> imageEncoderControl; - QPointer<QWinRTCameraFlashControl> cameraFlashControl; - QPointer<QWinRTCameraFocusControl> cameraFocusControl; - QPointer<QWinRTCameraLocksControl> cameraLocksControl; - QAtomicInt framesMapped; - QEventLoop *delayClose; - - bool initializing = false; - bool initialized = false; - HANDLE initializationCompleteEvent; -}; - -QWinRTCameraControl::QWinRTCameraControl(QObject *parent) - : QCameraControl(parent), d_ptr(new QWinRTCameraControlPrivate) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << parent; - Q_D(QWinRTCameraControl); - - d->delayClose = nullptr; - d->state = QCamera::UnloadedState; - d->status = QCamera::UnloadedStatus; - d->captureMode = QCamera::CaptureStillImage; - d->captureFailedCookie.value = 0; - d->recordLimitationCookie.value = 0; - d->videoRenderer = new QWinRTCameraVideoRendererControl(QSize(), this); - connect(d->videoRenderer, &QWinRTCameraVideoRendererControl::bufferRequested, - this, &QWinRTCameraControl::onBufferRequested); - d->videoDeviceSelector = new QWinRTVideoDeviceSelectorControl(this); - connect(d->videoDeviceSelector, QOverload<int>::of(&QWinRTVideoDeviceSelectorControl::selectedDeviceChanged), - d->videoRenderer, &QWinRTCameraVideoRendererControl::resetSampleFormat); - d->imageCaptureControl = new QWinRTCameraImageCaptureControl(this); - d->imageEncoderControl = new QWinRTImageEncoderControl(this); - d->cameraFlashControl = new QWinRTCameraFlashControl(this); - d->cameraFocusControl = new QWinRTCameraFocusControl(this); - d->cameraLocksControl = new QWinRTCameraLocksControl(this); - - d->initializationCompleteEvent = CreateEvent(nullptr, false, false, nullptr); - - if (qGuiApp) { - connect(qGuiApp, &QGuiApplication::applicationStateChanged, - this, &QWinRTCameraControl::onApplicationStateChanged); - } -} - -QWinRTCameraControl::~QWinRTCameraControl() -{ - setState(QCamera::UnloadedState); -} - -QCamera::State QWinRTCameraControl::state() const -{ - Q_D(const QWinRTCameraControl); - return d->state; -} - -void QWinRTCameraControl::setState(QCamera::State state) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << state; - Q_D(QWinRTCameraControl); - - if (d->state == state) - return; - - HRESULT hr; - switch (state) { - case QCamera::ActiveState: { - // Capture has not been created or initialized - if (d->state == QCamera::UnloadedState) { - if (!d->initialized) { - if (!d->initializing) { - hr = initialize(); - RETURN_VOID_AND_EMIT_ERROR("Failed to initialize media capture"); - } - DWORD waitResult = WaitForSingleObjectEx(d->initializationCompleteEvent, 30000, FALSE); - if (waitResult != WAIT_OBJECT_0) { - RETURN_VOID_AND_EMIT_ERROR("Failed to initialize camera control."); - return; - } - } - - d->state = QCamera::LoadedState; - emit stateChanged(d->state); - - d->status = QCamera::LoadedStatus; - emit statusChanged(d->status); - } - Q_ASSERT(d->state == QCamera::LoadedState); - - ComPtr<IAsyncAction> op; - hr = QEventDispatcherWinRT::runOnXamlThread([d, &op]() { - d->mediaSink = Make<MediaSink>(d->encodingProfile.Get(), d->videoRenderer); - HRESULT hr = d->capturePreview->StartPreviewToCustomSinkAsync(d->encodingProfile.Get(), d->mediaSink.Get(), &op); - return hr; - }); - RETURN_VOID_AND_EMIT_ERROR("Failed to initiate capture."); - if (d->status != QCamera::StartingStatus) { - d->status = QCamera::StartingStatus; - emit statusChanged(d->status); - } - - hr = QEventDispatcherWinRT::runOnXamlThread([&op]() { - return QWinRTFunctions::await(op); - }); - if (FAILED(hr)) { - emit error(QCamera::CameraError, qt_error_string(hr)); - setState(QCamera::UnloadedState); // Unload everything, as initialize() will need be called again - return; - } - - QCameraFocus::FocusModes focusMode = d->cameraFocusControl->focusMode(); - if (focusMode != 0 && setFocus(focusMode) && focusMode == QCameraFocus::ContinuousFocus) - focus(); - - d->state = QCamera::ActiveState; - emit stateChanged(d->state); - d->status = QCamera::ActiveStatus; - emit statusChanged(d->status); - QEventDispatcherWinRT::runOnXamlThread([d]() { d->mediaSink->RequestSample(); return S_OK;}); - break; - } - case QCamera::LoadedState: { - // If moving from unloaded, initialize the camera - if (d->state == QCamera::UnloadedState) { - if (!d->initialized) { - if (!d->initializing) { - hr = initialize(); - RETURN_VOID_AND_EMIT_ERROR("Failed to initialize media capture"); - } - DWORD waitResult = WaitForSingleObjectEx(d->initializationCompleteEvent, 30000, FALSE); - if (waitResult != WAIT_OBJECT_0) { - RETURN_VOID_AND_EMIT_ERROR("Failed to initialize camera control."); - return; - } - } - - d->state = QCamera::LoadedState; - emit stateChanged(d->state); - - d->status = QCamera::LoadedStatus; - emit statusChanged(d->status); - } - // fall through - } - case QCamera::UnloadedState: { - // Stop the camera if it is running (transition to LoadedState) - if (d->status == QCamera::ActiveStatus) { - HRESULT hr; - if (d->focusOperation) { - hr = QWinRTFunctions::await(d->focusOperation); - Q_ASSERT_SUCCEEDED(hr); - } - if (d->framesMapped > 0) { - qWarning("%d QVideoFrame(s) mapped when closing down camera. Camera will wait for unmap before closing down.", - d->framesMapped); - if (!d->delayClose) - d->delayClose = new QEventLoop(this); - d->delayClose->exec(); - } - - ComPtr<IAsyncAction> op; - hr = QEventDispatcherWinRT::runOnXamlThread([d, &op]() { - HRESULT hr = d->capturePreview->StopPreviewAsync(&op); - return hr; - }); - RETURN_VOID_AND_EMIT_ERROR("Failed to stop camera preview"); - if (d->status != QCamera::StoppingStatus) { - d->status = QCamera::StoppingStatus; - emit statusChanged(d->status); - } - Q_ASSERT_SUCCEEDED(hr); - hr = QEventDispatcherWinRT::runOnXamlThread([&op]() { - return QWinRTFunctions::await(op); // Synchronize unloading - }); - if (FAILED(hr)) - emit error(QCamera::InvalidRequestError, qt_error_string(hr)); - - if (d->mediaSink) { - hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - d->mediaSink->Shutdown(); - d->mediaSink.Reset(); - return S_OK; - }); - } - - d->state = QCamera::LoadedState; - emit stateChanged(d->state); - - d->status = QCamera::LoadedStatus; - emit statusChanged(d->status); - } - // Completely unload if needed - if (state == QCamera::UnloadedState) { - if (!d->capture) // Already unloaded - break; - - if (d->status != QCamera::UnloadingStatus) { - d->status = QCamera::UnloadingStatus; - emit statusChanged(d->status); - } - - hr = QEventDispatcherWinRT::runOnXamlThread([d]() { - HRESULT hr; - if (d->capture && d->captureFailedCookie.value) { - hr = d->capture->remove_Failed(d->captureFailedCookie); - Q_ASSERT_SUCCEEDED(hr); - d->captureFailedCookie.value = 0; - } - if (d->capture && d->recordLimitationCookie.value) { - d->capture->remove_RecordLimitationExceeded(d->recordLimitationCookie); - Q_ASSERT_SUCCEEDED(hr); - d->recordLimitationCookie.value = 0; - } - ComPtr<IClosable> capture; - hr = d->capture.As(&capture); - Q_ASSERT_SUCCEEDED(hr); - hr = capture->Close(); - RETURN_HR_IF_FAILED(""); - d->capture.Reset(); - return hr; - }); - RETURN_VOID_AND_EMIT_ERROR("Failed to close the capture manger"); - if (d->state != QCamera::UnloadedState) { - d->state = QCamera::UnloadedState; - emit stateChanged(d->state); - } - if (d->status != QCamera::UnloadedStatus) { - d->status = QCamera::UnloadedStatus; - emit statusChanged(d->status); - } - d->initialized = false; - } - break; - } - default: - break; - } -} - -QCamera::Status QWinRTCameraControl::status() const -{ - Q_D(const QWinRTCameraControl); - return d->status; -} - -QCamera::CaptureModes QWinRTCameraControl::captureMode() const -{ - Q_D(const QWinRTCameraControl); - return d->captureMode; -} - -void QWinRTCameraControl::setCaptureMode(QCamera::CaptureModes mode) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << mode; - Q_D(QWinRTCameraControl); - - if (d->captureMode == mode) - return; - - if (!isCaptureModeSupported(mode)) { - qWarning("Unsupported capture mode: %d", mode); - return; - } - - d->captureMode = mode; - emit captureModeChanged(d->captureMode); -} - -bool QWinRTCameraControl::isCaptureModeSupported(QCamera::CaptureModes mode) const -{ - return mode >= QCamera::CaptureViewfinder && mode <= QCamera::CaptureStillImage; -} - -bool QWinRTCameraControl::canChangeProperty(QCameraControl::PropertyChangeType changeType, QCamera::Status status) const -{ - Q_UNUSED(changeType); - - return status == QCamera::UnloadedStatus; // For now, assume shutdown is required for all property changes -} - -QVideoRendererControl *QWinRTCameraControl::videoRenderer() const -{ - Q_D(const QWinRTCameraControl); - return d->videoRenderer; -} - -QVideoDeviceSelectorControl *QWinRTCameraControl::videoDeviceSelector() const -{ - Q_D(const QWinRTCameraControl); - return d->videoDeviceSelector; -} - -QCameraImageCaptureControl *QWinRTCameraControl::imageCaptureControl() const -{ - Q_D(const QWinRTCameraControl); - return d->imageCaptureControl; -} - -QImageEncoderControl *QWinRTCameraControl::imageEncoderControl() const -{ - Q_D(const QWinRTCameraControl); - return d->imageEncoderControl; -} - -QCameraFlashControl *QWinRTCameraControl::cameraFlashControl() const -{ - Q_D(const QWinRTCameraControl); - return d->cameraFlashControl; -} - -QCameraFocusControl *QWinRTCameraControl::cameraFocusControl() const -{ - Q_D(const QWinRTCameraControl); - return d->cameraFocusControl; -} - -QCameraLocksControl *QWinRTCameraControl::cameraLocksControl() const -{ - Q_D(const QWinRTCameraControl); - return d->cameraLocksControl; -} - -Microsoft::WRL::ComPtr<ABI::Windows::Media::Capture::IMediaCapture> QWinRTCameraControl::handle() const -{ - Q_D(const QWinRTCameraControl); - return d->capture; -} - -void QWinRTCameraControl::onBufferRequested() -{ - Q_D(QWinRTCameraControl); - - if (d->mediaSink) - d->mediaSink->RequestSample(); -} - -void QWinRTCameraControl::onApplicationStateChanged(Qt::ApplicationState state) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << state; -#ifdef _DEBUG - return; -#else // !_DEBUG - Q_D(QWinRTCameraControl); - static QCamera::State savedState = d->state; - switch (state) { - case Qt::ApplicationInactive: - if (d->state != QCamera::UnloadedState) { - savedState = d->state; - setState(QCamera::UnloadedState); - } - break; - case Qt::ApplicationActive: - setState(QCamera::State(savedState)); - break; - default: - break; - } -#endif // _DEBUG -} - -HRESULT QWinRTCameraControl::initialize() -{ - qCDebug(lcMMCamera) << __FUNCTION__; - Q_D(QWinRTCameraControl); - - if (d->status != QCamera::LoadingStatus) { - d->status = QCamera::LoadingStatus; - emit statusChanged(d->status); - } - - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, d]() { - HRESULT hr; - ComPtr<IInspectable> capture; - hr = RoActivateInstance(Wrappers::HString::MakeReference(RuntimeClass_Windows_Media_Capture_MediaCapture).Get(), - &capture); - Q_ASSERT_SUCCEEDED(hr); - hr = capture.As(&d->capture); - Q_ASSERT_SUCCEEDED(hr); - hr = d->capture.As(&d->capturePreview); - Q_ASSERT_SUCCEEDED(hr); - hr = d->capture->add_Failed(Callback<IMediaCaptureFailedEventHandler>(this, &QWinRTCameraControl::onCaptureFailed).Get(), - &d->captureFailedCookie); - Q_ASSERT_SUCCEEDED(hr); - hr = d->capture->add_RecordLimitationExceeded(Callback<IRecordLimitationExceededEventHandler>(this, &QWinRTCameraControl::onRecordLimitationExceeded).Get(), - &d->recordLimitationCookie); - Q_ASSERT_SUCCEEDED(hr); - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Media_MediaProperties_MediaEncodingProfile).Get(), - IID_PPV_ARGS(&d->encodingProfileFactory)); - Q_ASSERT_SUCCEEDED(hr); - - int deviceIndex = d->videoDeviceSelector->selectedDevice(); - if (deviceIndex < 0) - deviceIndex = d->videoDeviceSelector->defaultDevice(); - - const QString deviceName = d->videoDeviceSelector->deviceName(deviceIndex); - if (deviceName.isEmpty()) { - qWarning("No video device available or selected."); - return E_FAIL; - } - - d->videoRenderer->setScanLineDirection(QVideoSurfaceFormat::TopToBottom); - ComPtr<IMediaCaptureInitializationSettings> settings; - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_Capture_MediaCaptureInitializationSettings).Get(), - &settings); - Q_ASSERT_SUCCEEDED(hr); - HStringReference deviceId(reinterpret_cast<LPCWSTR>(deviceName.utf16()), uint(deviceName.length())); - hr = settings->put_VideoDeviceId(deviceId.Get()); - Q_ASSERT_SUCCEEDED(hr); - - hr = settings->put_StreamingCaptureMode(StreamingCaptureMode_Video); - Q_ASSERT_SUCCEEDED(hr); - - hr = settings->put_PhotoCaptureSource(PhotoCaptureSource_Auto); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncAction> op; - hr = d->capture->InitializeWithSettingsAsync(settings.Get(), &op); - RETURN_HR_IF_FAILED("Failed to begin initialization of media capture manager"); - hr = op.Get()->put_Completed(Callback<IAsyncActionCompletedHandler>( - this, &QWinRTCameraControl::onInitializationCompleted).Get()); - RETURN_HR_IF_FAILED("Failed to register initialization callback"); - return S_OK; - }); - return hr; -} - -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) - -HRESULT QWinRTCameraControl::initializeFocus() -{ - Q_D(QWinRTCameraControl); - ComPtr<IFocusControl2> focusControl2; - HRESULT hr = d->focusControl.As(&focusControl2); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IVectorView<enum FocusMode>> focusModes; - hr = focusControl2->get_SupportedFocusModes(&focusModes); - if (FAILED(hr)) { - d->cameraFocusControl->setSupportedFocusMode(nullptr); - d->cameraFocusControl->setSupportedFocusPointMode(QSet<QCameraFocus::FocusPointMode>()); - qErrnoWarning(hr, "Failed to get camera supported focus mode list"); - return hr; - } - quint32 size; - hr = focusModes->get_Size(&size); - Q_ASSERT_SUCCEEDED(hr); - QCameraFocus::FocusModes supportedModeFlag = nullptr; - for (quint32 i = 0; i < size; ++i) { - FocusMode mode; - hr = focusModes->GetAt(i, &mode); - Q_ASSERT_SUCCEEDED(hr); - switch (mode) { - case FocusMode_Continuous: - supportedModeFlag |= QCameraFocus::ContinuousFocus; - break; - case FocusMode_Single: - supportedModeFlag |= QCameraFocus::AutoFocus; - break; - default: - break; - } - } - - ComPtr<IVectorView<enum AutoFocusRange>> focusRange; - hr = focusControl2->get_SupportedFocusRanges(&focusRange); - if (FAILED(hr)) { - qErrnoWarning(hr, "Failed to get camera supported focus range list"); - } else { - hr = focusRange->get_Size(&size); - Q_ASSERT_SUCCEEDED(hr); - for (quint32 i = 0; i < size; ++i) { - AutoFocusRange range; - hr = focusRange->GetAt(i, &range); - Q_ASSERT_SUCCEEDED(hr); - switch (range) { - case AutoFocusRange_Macro: - supportedModeFlag |= QCameraFocus::MacroFocus; - break; - case AutoFocusRange_FullRange: - supportedModeFlag |= QCameraFocus::InfinityFocus; - break; - default: - break; - } - } - } - d->cameraFocusControl->setSupportedFocusMode(supportedModeFlag); - if (!d->regionsOfInterestControl) { - d->cameraFocusControl->setSupportedFocusPointMode(QSet<QCameraFocus::FocusPointMode>()); - return S_OK; - } - boolean isRegionsfocusSupported = false; - hr = d->regionsOfInterestControl->get_AutoFocusSupported(&isRegionsfocusSupported); - Q_ASSERT_SUCCEEDED(hr); - UINT32 maxRegions; - hr = d->regionsOfInterestControl->get_MaxRegions(&maxRegions); - Q_ASSERT_SUCCEEDED(hr); - if (!isRegionsfocusSupported || maxRegions == 0) { - d->cameraFocusControl->setSupportedFocusPointMode(QSet<QCameraFocus::FocusPointMode>()); - return S_OK; - } - QSet<QCameraFocus::FocusPointMode> supportedFocusPointModes; - supportedFocusPointModes << QCameraFocus::FocusPointCustom - << QCameraFocus::FocusPointCenter - << QCameraFocus::FocusPointAuto; - d->cameraFocusControl->setSupportedFocusPointMode(supportedFocusPointModes); - return S_OK; -} - -bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes) -{ - Q_D(QWinRTCameraControl); - if (d->status == QCamera::UnloadedStatus) - return false; - - bool result = false; - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([modes, &result, d, this]() { - ComPtr<IFocusSettings> focusSettings; - ComPtr<IInspectable> focusSettingsObject; - HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_Devices_FocusSettings).Get(), &focusSettingsObject); - Q_ASSERT_SUCCEEDED(hr); - hr = focusSettingsObject.As(&focusSettings); - Q_ASSERT_SUCCEEDED(hr); - FocusMode mode; - if (modes.testFlag(QCameraFocus::ContinuousFocus)) { - mode = FocusMode_Continuous; - } else if (modes.testFlag(QCameraFocus::AutoFocus) - || modes.testFlag(QCameraFocus::MacroFocus) - || modes.testFlag(QCameraFocus::InfinityFocus)) { - // The Macro and infinity focus modes are only supported in auto focus mode on WinRT. - // QML camera focus doesn't support combined focus flags settings. In the case of macro - // and infinity Focus modes, the auto focus setting is applied. - mode = FocusMode_Single; - } else { - emit error(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera focus modes.")); - result = false; - return S_OK; - } - hr = focusSettings->put_Mode(mode); - Q_ASSERT_SUCCEEDED(hr); - AutoFocusRange range = AutoFocusRange_Normal; - if (modes.testFlag(QCameraFocus::MacroFocus)) - range = AutoFocusRange_Macro; - else if (modes.testFlag(QCameraFocus::InfinityFocus)) - range = AutoFocusRange_FullRange; - hr = focusSettings->put_AutoFocusRange(range); - Q_ASSERT_SUCCEEDED(hr); - hr = focusSettings->put_WaitForFocus(true); - Q_ASSERT_SUCCEEDED(hr); - hr = focusSettings->put_DisableDriverFallback(false); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IFocusControl2> focusControl2; - hr = d->focusControl.As(&focusControl2); - Q_ASSERT_SUCCEEDED(hr); - hr = focusControl2->Configure(focusSettings.Get()); - result = SUCCEEDED(hr); - RETURN_OK_IF_FAILED("Failed to configure camera focus control"); - return S_OK; - }); - Q_ASSERT_SUCCEEDED(hr); - Q_UNUSED(hr); // Silence release build - return result; -} - -bool QWinRTCameraControl::setFocusPoint(const QPointF &focusPoint) -{ - Q_D(QWinRTCameraControl); - if (focusPoint.x() < double(FOCUS_RECT_POSITION_MIN) - || focusPoint.x() > double(FOCUS_RECT_BOUNDARY)) { - emit error(QCamera::CameraError, QStringLiteral("Focus horizontal location should be between 0.0 and 1.0.")); - return false; - } - - if (focusPoint.y() < double(FOCUS_RECT_POSITION_MIN) - || focusPoint.y() > double(FOCUS_RECT_BOUNDARY)) { - emit error(QCamera::CameraError, QStringLiteral("Focus vertical location should be between 0.0 and 1.0.")); - return false; - } - - ABI::Windows::Foundation::Rect rect; - rect.X = qBound<float>(FOCUS_RECT_POSITION_MIN, float(focusPoint.x() - double(FOCUS_RECT_HALF_SIZE)), FOCUS_RECT_POSITION_MAX); - rect.Y = qBound<float>(FOCUS_RECT_POSITION_MIN, float(focusPoint.y() - double(FOCUS_RECT_HALF_SIZE)), FOCUS_RECT_POSITION_MAX); - rect.Width = (rect.X + FOCUS_RECT_SIZE) < FOCUS_RECT_BOUNDARY ? FOCUS_RECT_SIZE : FOCUS_RECT_BOUNDARY - rect.X; - rect.Height = (rect.Y + FOCUS_RECT_SIZE) < FOCUS_RECT_BOUNDARY ? FOCUS_RECT_SIZE : FOCUS_RECT_BOUNDARY - rect.Y; - - ComPtr<IRegionOfInterest> regionOfInterest; - ComPtr<IInspectable> regionOfInterestObject; - HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_Devices_RegionOfInterest).Get(), ®ionOfInterestObject); - Q_ASSERT_SUCCEEDED(hr); - hr = regionOfInterestObject.As(®ionOfInterest); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IRegionOfInterest2> regionOfInterest2; - hr = regionOfInterestObject.As(®ionOfInterest2); - Q_ASSERT_SUCCEEDED(hr); - hr = regionOfInterest2->put_BoundsNormalized(true); - Q_ASSERT_SUCCEEDED(hr); - hr = regionOfInterest2->put_Weight(1); - Q_ASSERT_SUCCEEDED(hr); - hr = regionOfInterest2->put_Type(RegionOfInterestType_Unknown); - Q_ASSERT_SUCCEEDED(hr); - hr = regionOfInterest->put_AutoFocusEnabled(true); - Q_ASSERT_SUCCEEDED(hr); - hr = regionOfInterest->put_Bounds(rect); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<WindowsRegionOfInterestIterable> regionOfInterestIterable = Make<WindowsRegionOfInterestIterable>(regionOfInterest); - ComPtr<IAsyncAction> op; - hr = d->regionsOfInterestControl->SetRegionsAsync(regionOfInterestIterable.Get(), &op); - Q_ASSERT_SUCCEEDED(hr); - return QWinRTFunctions::await(op) == S_OK; -} - -bool QWinRTCameraControl::focus() -{ - Q_D(QWinRTCameraControl); - HRESULT hr; - if (!d->focusControl) - return false; - - QEventDispatcherWinRT::runOnXamlThread([&d, &hr]() { - if (d->focusOperation) { - ComPtr<IAsyncInfo> info; - hr = d->focusOperation.As(&info); - Q_ASSERT_SUCCEEDED(hr); - - AsyncStatus status = AsyncStatus::Completed; - hr = info->get_Status(&status); - Q_ASSERT_SUCCEEDED(hr); - if (status == AsyncStatus::Started) - return E_ASYNC_OPERATION_NOT_STARTED; - } - - hr = d->focusControl->FocusAsync(&d->focusOperation); - Q_ASSERT_SUCCEEDED(hr); - - const long errorCode = HRESULT_CODE(hr); - if (errorCode == ERROR_OPERATION_IN_PROGRESS - || errorCode == ERROR_WRITE_PROTECT) { - return E_ASYNC_OPERATION_NOT_STARTED; - } - Q_ASSERT_SUCCEEDED(hr); - return S_OK; - }); - - return hr == S_OK; -} - -void QWinRTCameraControl::clearFocusPoint() -{ - Q_D(QWinRTCameraControl); - if (!d->focusControl) - return; - ComPtr<IAsyncAction> op; - HRESULT hr = d->regionsOfInterestControl->ClearRegionsAsync(&op); - Q_ASSERT_SUCCEEDED(hr); - hr = QWinRTFunctions::await(op); - Q_ASSERT_SUCCEEDED(hr); -} - -bool QWinRTCameraControl::lockFocus() -{ - Q_D(QWinRTCameraControl); - if (!d->focusControl) - return false; - - bool result = false; - ComPtr<IAsyncAction> op; - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([d, &result, &op]() { - ComPtr<IFocusControl2> focusControl2; - HRESULT hr = d->focusControl.As(&focusControl2); - Q_ASSERT_SUCCEEDED(hr); - hr = focusControl2->LockAsync(&op); - if (HRESULT_CODE(hr) == ERROR_WRITE_PROTECT) - return S_OK; - Q_ASSERT_SUCCEEDED(hr); - result = true; - return hr; - }); - return result ? (QWinRTFunctions::await(op) == S_OK) : false; -} - -bool QWinRTCameraControl::unlockFocus() -{ - Q_D(QWinRTCameraControl); - if (!d->focusControl) - return false; - - bool result = false; - ComPtr<IAsyncAction> op; - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([d, &result, &op]() { - ComPtr<IFocusControl2> focusControl2; - HRESULT hr = d->focusControl.As(&focusControl2); - Q_ASSERT_SUCCEEDED(hr); - hr = focusControl2->UnlockAsync(&op); - if (HRESULT_CODE(hr) == ERROR_WRITE_PROTECT) - return S_OK; - Q_ASSERT_SUCCEEDED(hr); - result = true; - return hr; - }); - return result ? (QWinRTFunctions::await(op) == S_OK) : false; -} - -#else // !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) - -HRESULT QWinRTCameraControl::initializeFocus() -{ - Q_D(QWinRTCameraControl); - d->cameraFocusControl->setSupportedFocusMode(0); - d->cameraFocusControl->setSupportedFocusPointMode(QSet<QCameraFocus::FocusPointMode>()); - return S_OK; -} - -bool QWinRTCameraControl::setFocus(QCameraFocus::FocusModes modes) -{ - Q_UNUSED(modes) - return false; -} - -bool QWinRTCameraControl::setFocusPoint(const QPointF &focusPoint) -{ - Q_UNUSED(focusPoint) - return false; -} - -bool QWinRTCameraControl::focus() -{ - return false; -} - -void QWinRTCameraControl::clearFocusPoint() -{ -} - -bool QWinRTCameraControl::lockFocus() -{ - return false; -} - -bool QWinRTCameraControl::unlockFocus() -{ - return false; -} - -#endif // !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) - -void QWinRTCameraControl::frameMapped() -{ - Q_D(QWinRTCameraControl); - ++d->framesMapped; -} - -void QWinRTCameraControl::frameUnmapped() -{ - Q_D(QWinRTCameraControl); - --d->framesMapped; - Q_ASSERT(d->framesMapped >= 0); - if (!d->framesMapped && d->delayClose && d->delayClose->isRunning()) - d->delayClose->exit(); -} - -HRESULT QWinRTCameraControl::onCaptureFailed(IMediaCapture *, IMediaCaptureFailedEventArgs *args) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << args; - HRESULT hr; - UINT32 code; - hr = args->get_Code(&code); - RETURN_HR_IF_FAILED("Failed to get error code"); - HString message; - args->get_Message(message.GetAddressOf()); - RETURN_HR_IF_FAILED("Failed to get error message"); - quint32 messageLength; - const wchar_t *messageBuffer = message.GetRawBuffer(&messageLength); - emit error(QCamera::CameraError, QString::fromWCharArray(messageBuffer, int(messageLength))); - setState(QCamera::LoadedState); - return S_OK; -} - -HRESULT QWinRTCameraControl::onRecordLimitationExceeded(IMediaCapture *) -{ - qCDebug(lcMMCamera) << __FUNCTION__; - emit error(QCamera::CameraError, QStringLiteral("Recording limit exceeded.")); - setState(QCamera::LoadedState); - return S_OK; -} - -HRESULT QWinRTCameraControl::onInitializationCompleted(IAsyncAction *, AsyncStatus status) -{ - qCDebug(lcMMCamera) << __FUNCTION__; - Q_D(QWinRTCameraControl); - - if (status != Completed) { - d->initializing = false; - d->initialized = false; - return S_OK; - } - - ComPtr<IVideoDeviceController> videoDeviceController; - HRESULT hr = d->capture->get_VideoDeviceController(&videoDeviceController); - ComPtr<IAdvancedVideoCaptureDeviceController2> advancedVideoDeviceController; - hr = videoDeviceController.As(&advancedVideoDeviceController); - Q_ASSERT_SUCCEEDED(hr); - hr = advancedVideoDeviceController->get_FocusControl(&d->focusControl); - Q_ASSERT_SUCCEEDED(hr); - - d->cameraFlashControl->initialize(advancedVideoDeviceController); - - boolean isFocusSupported; - hr = d->focusControl->get_Supported(&isFocusSupported); - Q_ASSERT_SUCCEEDED(hr); - if (isFocusSupported) { - hr = advancedVideoDeviceController->get_RegionsOfInterestControl(&d->regionsOfInterestControl); - if (FAILED(hr)) - qCDebug(lcMMCamera) << "Focus supported, but no control for regions of interest available"; - hr = initializeFocus(); - Q_ASSERT_SUCCEEDED(hr); - } - - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IMediaDeviceController> deviceController; - hr = videoDeviceController.As(&deviceController); - Q_ASSERT_SUCCEEDED(hr); - - // Get preview stream properties. - ComPtr<IVectorView<IMediaEncodingProperties *>> previewPropertiesList; - QVector<QSize> previewResolutions; - hr = getMediaStreamResolutions(deviceController.Get(), - MediaStreamType_VideoPreview, - &previewPropertiesList, - &previewResolutions); - RETURN_HR_IF_FAILED("Failed to find a suitable video format"); - - MediaStreamType mediaStreamType = - d->captureMode == QCamera::CaptureVideo ? MediaStreamType_VideoRecord : MediaStreamType_Photo; - - // Get capture stream properties. - ComPtr<IVectorView<IMediaEncodingProperties *>> capturePropertiesList; - QVector<QSize> captureResolutions; - hr = getMediaStreamResolutions(deviceController.Get(), - mediaStreamType, - &capturePropertiesList, - &captureResolutions); - RETURN_HR_IF_FAILED("Failed to find a suitable video format"); - - std::sort(captureResolutions.begin(), captureResolutions.end(), [](QSize size1, QSize size2) { - return size1.width() * size1.height() < size2.width() * size2.height(); - }); - - // Set capture resolutions. - d->imageEncoderControl->setSupportedResolutionsList(captureResolutions.toList()); - const QSize captureResolution = d->imageEncoderControl->imageSettings().resolution(); - const quint32 captureResolutionIndex = quint32(captureResolutions.indexOf(captureResolution)); - ComPtr<IMediaEncodingProperties> captureProperties; - hr = capturePropertiesList->GetAt(captureResolutionIndex, &captureProperties); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IAsyncAction> op; - hr = deviceController->SetMediaStreamPropertiesAsync(mediaStreamType, captureProperties.Get(), &op); - Q_ASSERT_SUCCEEDED(hr); - hr = QWinRTFunctions::await(op); - Q_ASSERT_SUCCEEDED(hr); - - // Set preview resolution. - QSize maxSize; - const float captureAspectRatio = float(captureResolution.width()) / captureResolution.height(); - for (const QSize &resolution : qAsConst(previewResolutions)) { - const float aspectRatio = float(resolution.width()) / resolution.height(); - if ((qAbs(aspectRatio - captureAspectRatio) <= ASPECTRATIO_EPSILON) - && (maxSize.width() * maxSize.height() < resolution.width() * resolution.height())) { - maxSize = resolution; - } - } - - const QSize &viewfinderResolution = maxSize; - const quint32 viewfinderResolutionIndex = quint32(previewResolutions.indexOf(viewfinderResolution)); - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Media_MediaProperties_MediaEncodingProfile).Get(), - &d->encodingProfile); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IMediaEncodingProperties> previewProperties; - hr = previewPropertiesList->GetAt(viewfinderResolutionIndex, &previewProperties); - Q_ASSERT_SUCCEEDED(hr); - hr = deviceController->SetMediaStreamPropertiesAsync(MediaStreamType_VideoPreview, previewProperties.Get(), &op); - Q_ASSERT_SUCCEEDED(hr); - hr = QWinRTFunctions::await(op); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IVideoEncodingProperties> videoPreviewProperties; - hr = previewProperties.As(&videoPreviewProperties); - Q_ASSERT_SUCCEEDED(hr); - hr = d->encodingProfile->put_Video(videoPreviewProperties.Get()); - Q_ASSERT_SUCCEEDED(hr); - - if (d->videoRenderer) - d->videoRenderer->setSize(viewfinderResolution); - - if (!isFocusSupported) { - d->cameraFocusControl->setSupportedFocusMode(0); - d->cameraFocusControl->setSupportedFocusPointMode(QSet<QCameraFocus::FocusPointMode>()); - } - d->cameraLocksControl->initialize(); - - d->initializing = false; - d->initialized = true; - SetEvent(d->initializationCompleteEvent); - return S_OK; -} - -void QWinRTCameraControl::emitError(int errorCode, const QString &errorString) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << errorString << errorCode; - emit error(errorCode, errorString); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameracontrol.h b/src/plugins/winrt/qwinrtcameracontrol.h deleted file mode 100644 index 3a2125f5b..000000000 --- a/src/plugins/winrt/qwinrtcameracontrol.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERACONTROL_H -#define QWINRTCAMERACONTROL_H - -#include <QtMultimedia/QCameraControl> -#include <QtCore/QLoggingCategory> -#include <QtCore/qt_windows.h> - -#include <wrl.h> - -namespace ABI { - namespace Windows { - namespace Media { - namespace Capture { - struct IMediaCapture; - struct IMediaCaptureFailedEventArgs; - } - } - namespace Foundation { - struct IAsyncAction; - enum class AsyncStatus; - } - } -} - -QT_BEGIN_NAMESPACE - -Q_DECLARE_LOGGING_CATEGORY(lcMMCamera) - -class QVideoRendererControl; -class QVideoDeviceSelectorControl; -class QCameraImageCaptureControl; -class QImageEncoderControl; -class QCameraFlashControl; -class QCameraFocusControl; -class QCameraLocksControl; - -class QWinRTCameraControlPrivate; -class QWinRTCameraControl : public QCameraControl -{ - Q_OBJECT -public: - explicit QWinRTCameraControl(QObject *parent = nullptr); - ~QWinRTCameraControl() override; - - QCamera::State state() const override; - void setState(QCamera::State state) override; - - QCamera::Status status() const override; - - QCamera::CaptureModes captureMode() const override; - void setCaptureMode(QCamera::CaptureModes mode) override; - bool isCaptureModeSupported(QCamera::CaptureModes mode) const override; - - bool canChangeProperty(PropertyChangeType changeType, QCamera::Status status) const override; - - QVideoRendererControl *videoRenderer() const; - QVideoDeviceSelectorControl *videoDeviceSelector() const; - QCameraImageCaptureControl *imageCaptureControl() const; - QImageEncoderControl *imageEncoderControl() const; - QCameraFlashControl *cameraFlashControl() const; - QCameraFocusControl *cameraFocusControl() const; - QCameraLocksControl *cameraLocksControl() const; - - Microsoft::WRL::ComPtr<ABI::Windows::Media::Capture::IMediaCapture> handle() const; - - bool setFocus(QCameraFocus::FocusModes mode); - bool setFocusPoint(const QPointF &point); - bool focus(); - void clearFocusPoint(); - void emitError(int errorCode, const QString &errorString); - bool lockFocus(); - bool unlockFocus(); - void frameMapped(); - void frameUnmapped(); - -private slots: - void onBufferRequested(); - void onApplicationStateChanged(Qt::ApplicationState state); - -private: - HRESULT enumerateDevices(); - HRESULT initialize(); - HRESULT initializeFocus(); - HRESULT onCaptureFailed(ABI::Windows::Media::Capture::IMediaCapture *, - ABI::Windows::Media::Capture::IMediaCaptureFailedEventArgs *); - HRESULT onRecordLimitationExceeded(ABI::Windows::Media::Capture::IMediaCapture *); - HRESULT onInitializationCompleted(ABI::Windows::Foundation::IAsyncAction *, - ABI::Windows::Foundation::AsyncStatus); - - QScopedPointer<QWinRTCameraControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCameraControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTCAMERACONTROL_H diff --git a/src/plugins/winrt/qwinrtcameraflashcontrol.cpp b/src/plugins/winrt/qwinrtcameraflashcontrol.cpp deleted file mode 100644 index 1ea877672..000000000 --- a/src/plugins/winrt/qwinrtcameraflashcontrol.cpp +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 "qwinrtcameraflashcontrol.h" -#include "qwinrtcameracontrol.h" -#include <QtCore/QTimer> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/private/qeventdispatcher_winrt_p.h> - -#include <windows.media.devices.h> -#include <wrl.h> -#include <functional> - -using namespace Microsoft::WRL; -using namespace ABI::Windows::Media::Devices; - -QT_BEGIN_NAMESPACE - -class QWinRTCameraFlashControlPrivate -{ -public: - ComPtr<IFlashControl> flashControl; - - QList<QCameraExposure::FlashModes> supportedModes; - QCameraExposure::FlashModes currentModes; - bool initialized; -}; - -QWinRTCameraFlashControl::QWinRTCameraFlashControl(QWinRTCameraControl *parent) - : QCameraFlashControl(parent), d_ptr(new QWinRTCameraFlashControlPrivate) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << parent; - Q_D(QWinRTCameraFlashControl); - - d->initialized = false; - d->currentModes = QCameraExposure::FlashOff; -} - -void QWinRTCameraFlashControl::initialize(Microsoft::WRL::ComPtr<IAdvancedVideoCaptureDeviceController2> &controller) -{ - qCDebug(lcMMCamera) << __FUNCTION__; - Q_D(QWinRTCameraFlashControl); - - d->initialized = false; - - d->supportedModes.clear(); - HRESULT hr; - hr = QEventDispatcherWinRT::runOnXamlThread([d, controller]() { - HRESULT hr; - hr = controller->get_FlashControl(&d->flashControl); - RETURN_HR_IF_FAILED("Could not access flash control."); - - boolean oldAuto; - boolean oldEnabled; - // IFlashControl::get_Supported() is only valid for additional - // controls (RedEye, etc.) so we have to manually try to set - // and reset flash - if (SUCCEEDED(d->flashControl->get_Auto(&oldAuto))) { - hr = d->flashControl->put_Auto(!oldAuto); - if (SUCCEEDED(hr)) { - d->flashControl->put_Auto(oldAuto); - d->supportedModes.append(QCameraExposure::FlashAuto); - } - } - - if (SUCCEEDED(d->flashControl->get_Enabled(&oldEnabled))) { - hr = d->flashControl->put_Enabled(!oldEnabled); - if (SUCCEEDED(hr)) { - d->flashControl->put_Enabled(oldEnabled); - d->supportedModes.append(QCameraExposure::FlashOff); - d->supportedModes.append(QCameraExposure::FlashOn); - } - } - - boolean val; - hr = d->flashControl->get_Supported(&val); - if (SUCCEEDED(hr) && val) { - hr = d->flashControl->get_RedEyeReductionSupported(&val); - if (SUCCEEDED(hr) && val) - d->supportedModes.append(QCameraExposure::FlashRedEyeReduction); - - // ### There is no Qt API to actually set the power values. - // However query if the camera could theoretically do it - hr = d->flashControl->get_PowerSupported(&val); - if (SUCCEEDED(hr) && val) - d->supportedModes.append(QCameraExposure::FlashManual); - } - - return S_OK; - }); - Q_ASSERT_SUCCEEDED(hr); - d->initialized = true; - setFlashMode(d->currentModes); -} - -QCameraExposure::FlashModes QWinRTCameraFlashControl::flashMode() const -{ - Q_D(const QWinRTCameraFlashControl); - return d->currentModes; -} - -void QWinRTCameraFlashControl::setFlashMode(QCameraExposure::FlashModes mode) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << mode; - Q_D(QWinRTCameraFlashControl); - - if (!d->initialized) { - d->currentModes = mode; - return; - } - - if (!isFlashModeSupported(mode)) - return; - - QEventDispatcherWinRT::runOnXamlThread([d, mode]() { - HRESULT hr; - if (mode.testFlag(QCameraExposure::FlashAuto)) { - hr = d->flashControl->put_Enabled(true); - RETURN_OK_IF_FAILED("Could not set flash mode on."); - hr = d->flashControl->put_Auto(true); - RETURN_OK_IF_FAILED("Could not set flash mode auto."); - d->currentModes = QCameraExposure::FlashAuto; - } else if (mode.testFlag(QCameraExposure::FlashOn)) { - hr = d->flashControl->put_Enabled(true); - RETURN_OK_IF_FAILED("Could not set flash mode on."); - hr = d->flashControl->put_Auto(false); - RETURN_OK_IF_FAILED("Could not disable flash auto mode."); - d->currentModes = QCameraExposure::FlashOn; - } else if (mode.testFlag(QCameraExposure::FlashRedEyeReduction)) { - hr = d->flashControl->put_Enabled(true); - RETURN_OK_IF_FAILED("Could not set flash mode on."); - hr = d->flashControl->put_RedEyeReduction(true); - RETURN_OK_IF_FAILED("Could not set flash mode red eye reduction."); - d->currentModes = QCameraExposure::FlashRedEyeReduction; - } else { - hr = d->flashControl->put_Enabled(false); - RETURN_OK_IF_FAILED("Could not set flash mode off."); - d->currentModes = QCameraExposure::FlashOff; - } - return S_OK; - }); -} - -bool QWinRTCameraFlashControl::isFlashModeSupported(QCameraExposure::FlashModes mode) const -{ - Q_D(const QWinRTCameraFlashControl); - qCDebug(lcMMCamera) << __FUNCTION__ << mode; - return d->initialized ? d->supportedModes.contains(mode) : false; -} - -bool QWinRTCameraFlashControl::isFlashReady() const -{ - qCDebug(lcMMCamera) << __FUNCTION__; - // No native API to query state - return true; -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameraflashcontrol.h b/src/plugins/winrt/qwinrtcameraflashcontrol.h deleted file mode 100644 index b9be69230..000000000 --- a/src/plugins/winrt/qwinrtcameraflashcontrol.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 QWINRTCAMERAFLASHCONTROL_H -#define QWINRTCAMERAFLASHCONTROL_H -#include <qcameraflashcontrol.h> - -#include <wrl.h> - -namespace ABI { - namespace Windows { - namespace Media { - namespace Devices { - struct IAdvancedVideoCaptureDeviceController2; - } - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTCameraControl; -class QWinRTCameraFlashControlPrivate; -class QWinRTCameraFlashControl : public QCameraFlashControl -{ - Q_OBJECT -public: - explicit QWinRTCameraFlashControl(QWinRTCameraControl *parent); - - void initialize(Microsoft::WRL::ComPtr<ABI::Windows::Media::Devices::IAdvancedVideoCaptureDeviceController2> &controller); - - QCameraExposure::FlashModes flashMode() const override; - void setFlashMode(QCameraExposure::FlashModes mode) override; - bool isFlashModeSupported(QCameraExposure::FlashModes mode) const override; - - bool isFlashReady() const override; - -private: - QScopedPointer<QWinRTCameraFlashControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCameraFlashControl) -}; - -#endif // QWINRTCAMERAFLASHCONTROL_H diff --git a/src/plugins/winrt/qwinrtcamerafocuscontrol.cpp b/src/plugins/winrt/qwinrtcamerafocuscontrol.cpp deleted file mode 100644 index afe7017d7..000000000 --- a/src/plugins/winrt/qwinrtcamerafocuscontrol.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcamerafocuscontrol.h" -#include "qwinrtcameraimagecapturecontrol.h" -#include "qwinrtcameracontrol.h" - -QT_BEGIN_NAMESPACE - -class QWinRTCameraFocusControlPrivate -{ -public: - QCameraFocus::FocusModes focusModes; - QCameraFocus::FocusModes supportedFocusModes; - QCameraFocus::FocusPointMode focusPointMode; - QSet<QCameraFocus::FocusPointMode> supportedFocusPointModes; - QPointF focusPoint; - bool focusModeInitialized; - bool focusPointModeInitialized; - bool imageCaptureIdle; -}; - -QWinRTCameraFocusControl::QWinRTCameraFocusControl(QWinRTCameraControl *parent) - : QCameraFocusControl(parent), d_ptr(new QWinRTCameraFocusControlPrivate) -{ - Q_D(QWinRTCameraFocusControl); - d->focusModeInitialized = false; - d->focusPointModeInitialized = false; - d->focusModes = QCameraFocus::ContinuousFocus; - d->focusPointMode = QCameraFocus::FocusPointAuto; - d->imageCaptureIdle = true; - QWinRTCameraImageCaptureControl *imageCaptureControl = static_cast<QWinRTCameraImageCaptureControl *>(parent->imageCaptureControl()); - Q_ASSERT(imageCaptureControl); - connect(imageCaptureControl, &QWinRTCameraImageCaptureControl::captureQueueChanged, - this, &QWinRTCameraFocusControl::imageCaptureQueueChanged, Qt::QueuedConnection); -} - -QCameraFocus::FocusModes QWinRTCameraFocusControl::focusMode() const -{ - Q_D(const QWinRTCameraFocusControl); - return d->focusModes; -} - -void QWinRTCameraFocusControl::setFocusMode(QCameraFocus::FocusModes modes) -{ - Q_D(QWinRTCameraFocusControl); - if (d->focusModes == modes) - return; - QWinRTCameraControl *cameraControl = static_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - if (!modes) { - cameraControl->emitError(QCamera::InvalidRequestError, QStringLiteral("Can't set empty camera focus modes.")); - return; - } - if (!d->focusModeInitialized) { - d->focusModes = modes; - emit focusModeChanged(modes); - return; - } - if (!isFocusModeSupported(modes)) { - cameraControl->emitError(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera focus modes.")); - return; - } - if (modes.testFlag(QCameraFocus::ContinuousFocus)) { - if (QCameraFocus::FocusPointCustom == d->focusPointMode) { - cameraControl->emitError(QCamera::NotSupportedFeatureError, - QStringLiteral("Unsupported camera focus modes: ContinuousFocus with FocusPointCustom.")); - return; - } else if (!d->imageCaptureIdle) { - cameraControl->emitError(QCamera::NotSupportedFeatureError, - QStringLiteral("Can't set ContinuousFocus camera focus mode while capturing image.")); - return; - } - } - if (!cameraControl->setFocus(modes)) - return; - if (modes.testFlag(QCameraFocus::ContinuousFocus) || d->focusModes.testFlag(QCameraFocus::ContinuousFocus)) - cameraControl->focus(); - d->focusModes = modes; - emit focusModeChanged(modes); -} - -bool QWinRTCameraFocusControl::isFocusModeSupported(QCameraFocus::FocusModes modes) const -{ - Q_D(const QWinRTCameraFocusControl); - return (d->focusModeInitialized && modes) ? !((d->supportedFocusModes & modes) ^ modes) : false; -} - -QCameraFocus::FocusPointMode QWinRTCameraFocusControl::focusPointMode() const -{ - Q_D(const QWinRTCameraFocusControl); - return d->focusPointMode; -} - -void QWinRTCameraFocusControl::setFocusPointMode(QCameraFocus::FocusPointMode mode) -{ - Q_D(QWinRTCameraFocusControl); - if (d->focusPointMode == mode) - return; - - if (!d->focusModeInitialized) { - d->focusPointMode = mode; - emit focusPointModeChanged(mode); - return; - } - QWinRTCameraControl *cameraControl = static_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - if (!d->supportedFocusPointModes.contains(mode)) { - cameraControl->emitError(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera point focus mode.")); - return; - } - if (QCameraFocus::FocusPointCenter == mode || QCameraFocus::FocusPointAuto == mode) - d->focusPoint = QPointF(0.5, 0.5); - // Don't apply focus point focus settings if camera is in continuous focus mode - if (!d->focusModes.testFlag(QCameraFocus::ContinuousFocus)) { - changeFocusCustomPoint(d->focusPoint); - } else if (QCameraFocus::FocusPointCustom == mode) { - cameraControl->emitError(QCamera::NotSupportedFeatureError, QStringLiteral("Unsupported camera focus modes: ContinuousFocus with FocusPointCustom.")); - return; - } - d->focusPointMode = mode; - emit focusPointModeChanged(mode); -} - -bool QWinRTCameraFocusControl::isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const -{ - Q_D(const QWinRTCameraFocusControl); - return d->supportedFocusPointModes.contains(mode); -} - -QPointF QWinRTCameraFocusControl::customFocusPoint() const -{ - Q_D(const QWinRTCameraFocusControl); - return d->focusPoint; -} - -void QWinRTCameraFocusControl::setCustomFocusPoint(const QPointF &point) -{ - Q_D(QWinRTCameraFocusControl); - if (d->focusPointMode != QCameraFocus::FocusPointCustom) { - QWinRTCameraControl *cameraControl = static_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - cameraControl->emitError(QCamera::InvalidRequestError, QStringLiteral("Custom focus point can be set only in FocusPointCustom focus mode.")); - return; - } - if (d->focusPoint == point) - return; - if (changeFocusCustomPoint(point)) { - d->focusPoint = point; - emit customFocusPointChanged(point); - } - -} - -QCameraFocusZoneList QWinRTCameraFocusControl::focusZones() const -{ - return QCameraFocusZoneList(); -} - -void QWinRTCameraFocusControl::setSupportedFocusMode(QCameraFocus::FocusModes modes) -{ - Q_D(QWinRTCameraFocusControl); - d->supportedFocusModes = modes; - d->focusModeInitialized = true; - if (isFocusModeSupported(d->focusModes)) - return; - d->focusModes = nullptr; - if (!modes) { - emit focusModeChanged(d->focusModes); - return; - } - if (isFocusModeSupported(QCameraFocus::ContinuousFocus)) - d->focusModes = QCameraFocus::ContinuousFocus; - else if (isFocusModeSupported(QCameraFocus::AutoFocus)) - d->focusModes = QCameraFocus::AutoFocus; - else if (isFocusModeSupported(QCameraFocus::ManualFocus)) - d->focusModes = QCameraFocus::ManualFocus; - emit focusModeChanged(d->focusModes); -} - -void QWinRTCameraFocusControl::setSupportedFocusPointMode(const QSet<QCameraFocus::FocusPointMode> &supportedFocusPointModes) -{ - Q_D(QWinRTCameraFocusControl); - d->supportedFocusPointModes = supportedFocusPointModes; - d->focusPointModeInitialized = true; - - if (supportedFocusPointModes.isEmpty()) { - if (d->focusPointMode != QCameraFocus::FocusPointAuto) { - d->focusPointMode = QCameraFocus::FocusPointAuto; - emit focusPointModeChanged(d->focusPointMode); - } - return; - } - - if (isFocusPointModeSupported(d->focusPointMode)) - return; - - if (isFocusPointModeSupported(QCameraFocus::FocusPointCenter)) - d->focusPointMode = QCameraFocus::FocusPointCenter; - else if (isFocusPointModeSupported(QCameraFocus::FocusPointAuto)) - d->focusPointMode = QCameraFocus::FocusPointAuto; - else if (isFocusPointModeSupported(QCameraFocus::FocusPointCustom)) - d->focusPointMode = QCameraFocus::FocusPointCustom; - else if (isFocusPointModeSupported(QCameraFocus::FocusPointFaceDetection)) - d->focusPointMode = QCameraFocus::FocusPointFaceDetection; - emit focusPointModeChanged(d->focusPointMode); -} - -void QWinRTCameraFocusControl::imageCaptureQueueChanged(bool isEmpty) -{ - Q_D(QWinRTCameraFocusControl); - d->imageCaptureIdle = isEmpty; -} - -bool QWinRTCameraFocusControl::changeFocusCustomPoint(const QPointF &point) -{ - Q_D(QWinRTCameraFocusControl); - if (!d->focusPointModeInitialized || point.isNull()) - return true; - QWinRTCameraControl *cameraControl = static_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - cameraControl->clearFocusPoint(); - return cameraControl->setFocusPoint(point); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcamerafocuscontrol.h b/src/plugins/winrt/qwinrtcamerafocuscontrol.h deleted file mode 100644 index fcfb84edc..000000000 --- a/src/plugins/winrt/qwinrtcamerafocuscontrol.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERAFOCUSCONTROL_H -#define QWINRTCAMERAFOCUSCONTROL_H -#include <qcamerafocuscontrol.h> - -QT_BEGIN_NAMESPACE - -class QWinRTCameraControl; -class QWinRTCameraFocusControlPrivate; -class QWinRTCameraFocusControl : public QCameraFocusControl -{ - Q_OBJECT -public: - explicit QWinRTCameraFocusControl(QWinRTCameraControl *parent); - - QCameraFocus::FocusModes focusMode() const override; - void setFocusMode(QCameraFocus::FocusModes mode) override; - bool isFocusModeSupported(QCameraFocus::FocusModes mode) const override; - QCameraFocus::FocusPointMode focusPointMode() const override; - void setFocusPointMode(QCameraFocus::FocusPointMode mode) override; - bool isFocusPointModeSupported(QCameraFocus::FocusPointMode mode) const override; - QPointF customFocusPoint() const override; - void setCustomFocusPoint(const QPointF &point) override; - QCameraFocusZoneList focusZones() const override; - - void setSupportedFocusMode(QCameraFocus::FocusModes flag); - void setSupportedFocusPointMode(const QSet<QCameraFocus::FocusPointMode> &supportedFocusPointModes); - -private slots: - void imageCaptureQueueChanged(bool isEmpty); - -private: - bool changeFocusCustomPoint(const QPointF &point); - - QScopedPointer<QWinRTCameraFocusControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCameraFocusControl) -}; - -#endif // QWINRTCAMERAFOCUSCONTROL_H diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp deleted file mode 100644 index 4ed208feb..000000000 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcameraimagecapturecontrol.h" -#include "qwinrtcameracontrol.h" -#include "qwinrtimageencodercontrol.h" - -#include <QtCore/QCoreApplication> -#include <QtCore/QDir> -#include <QtCore/QFileInfo> -#include <QtCore/QGlobalStatic> -#include <QtCore/QPointer> -#include <QtCore/QStandardPaths> -#include <QtCore/QVector> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/private/qeventdispatcher_winrt_p.h> -#include <QtMultimedia/private/qmediastoragelocation_p.h> - -#include <functional> -#include <wrl.h> -#include <windows.media.capture.h> -#include <windows.media.devices.h> -#include <windows.media.mediaproperties.h> -#include <windows.storage.streams.h> -#include <windows.graphics.imaging.h> -#include <robuffer.h> - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Media::Capture; -using namespace ABI::Windows::Media::Devices; -using namespace ABI::Windows::Media::MediaProperties; -using namespace ABI::Windows::Storage::Streams; -using namespace ABI::Windows::Graphics::Imaging; - -QT_BEGIN_NAMESPACE - -#define wchar(str) reinterpret_cast<const wchar_t *>(str.utf16()) - -struct QWinRTCameraImageCaptureControlGlobal -{ - QWinRTCameraImageCaptureControlGlobal() - { - HRESULT hr; - hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Media_MediaProperties_ImageEncodingProperties).Get(), - &encodingPropertiesFactory); - Q_ASSERT_SUCCEEDED(hr); - - hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_Buffer).Get(), - &bufferFactory); - Q_ASSERT_SUCCEEDED(hr); - - hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_DataReader).Get(), - &dataReaderFactory); - } - - ComPtr<IImageEncodingPropertiesStatics2> encodingPropertiesFactory; - ComPtr<IBufferFactory> bufferFactory; - ComPtr<IDataReaderFactory> dataReaderFactory; -}; -Q_GLOBAL_STATIC(QWinRTCameraImageCaptureControlGlobal, g) - -struct CaptureRequest -{ - quint16 id; - QString fileName; - ComPtr<IImageEncodingProperties> imageFormat; - ComPtr<IRandomAccessStream> stream; - ComPtr<IAsyncAction> op; -}; - -// Do not use CoTaskMemFree directly for image cleanup as it leads to crashes in release -static void freeImageData(void *data) -{ - CoTaskMemFree(data); -} - -class QWinRTCameraImageCaptureControlPrivate -{ -public: - QWinRTCameraImageCaptureControlPrivate() - : isActive(false) - { - } - - QPointer<QWinRTCameraControl> cameraControl; - QHash<IAsyncAction *, CaptureRequest> requests; - quint16 currentCaptureId; - QMediaStorageLocation location; - bool isActive; -}; - -QWinRTCameraImageCaptureControl::QWinRTCameraImageCaptureControl(QWinRTCameraControl *parent) - : QCameraImageCaptureControl(parent), d_ptr(new QWinRTCameraImageCaptureControlPrivate) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << parent; - Q_D(QWinRTCameraImageCaptureControl); - - d->cameraControl = parent; - connect(d->cameraControl, &QCameraControl::stateChanged, - this, &QWinRTCameraImageCaptureControl::onCameraStateChanged); - d->currentCaptureId = 0; -} - -bool QWinRTCameraImageCaptureControl::isReadyForCapture() const -{ - Q_D(const QWinRTCameraImageCaptureControl); - return d->isActive; -} - -QCameraImageCapture::DriveMode QWinRTCameraImageCaptureControl::driveMode() const -{ - return QCameraImageCapture::SingleImageCapture; -} - -void QWinRTCameraImageCaptureControl::setDriveMode(QCameraImageCapture::DriveMode mode) -{ - Q_UNUSED(mode); -} - -int QWinRTCameraImageCaptureControl::capture(const QString &fileName) -{ - qCDebug(lcMMCamera) << __FUNCTION__ << fileName; - Q_D(QWinRTCameraImageCaptureControl); - - ++d->currentCaptureId; - ComPtr<IMediaCapture> capture = d->cameraControl->handle(); - if (!capture) { - emit error(d->currentCaptureId, QCameraImageCapture::NotReadyError, tr("Camera not ready")); - return -1; - } - - CaptureRequest request = { - d->currentCaptureId, - d->location.generateFileName(fileName, QMediaStorageLocation::Pictures, QStringLiteral("IMG_"), - fileName.isEmpty() ? QStringLiteral("jpg") : QFileInfo(fileName).suffix()), - nullptr, nullptr, nullptr - }; - - HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([this, d, capture, &request]() { - HRESULT hr; - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Storage_Streams_InMemoryRandomAccessStream).Get(), - &request.stream); - Q_ASSERT_SUCCEEDED(hr); - - hr = g->encodingPropertiesFactory->CreateBmp(&request.imageFormat); - Q_ASSERT_SUCCEEDED(hr); - - const QSize imageSize = static_cast<QWinRTImageEncoderControl*>(d->cameraControl->imageEncoderControl())->imageSettings().resolution(); - hr = request.imageFormat->put_Width(UINT32(imageSize.width())); - Q_ASSERT_SUCCEEDED(hr); - hr = request.imageFormat->put_Height(UINT32(imageSize.height())); - Q_ASSERT_SUCCEEDED(hr); - - hr = capture->CapturePhotoToStreamAsync(request.imageFormat.Get(), request.stream.Get(), &request.op); - Q_ASSERT_SUCCEEDED(hr); - if (!request.op) { - qErrnoWarning("Camera photo capture failed."); - return E_FAIL; - } - emit captureQueueChanged(false); - d->requests.insert(request.op.Get(), request); - - hr = request.op->put_Completed(Callback<IAsyncActionCompletedHandler>( - this, &QWinRTCameraImageCaptureControl::onCaptureCompleted).Get()); - Q_ASSERT_SUCCEEDED(hr); - return hr; - }); - if (FAILED(hr)) - return -1; - return request.id; -} - -void QWinRTCameraImageCaptureControl::cancelCapture() -{ - qCDebug(lcMMCamera) << __FUNCTION__; - Q_D(QWinRTCameraImageCaptureControl); - - QHash<IAsyncAction *, CaptureRequest>::iterator it = d->requests.begin(); - while (it != d->requests.end()) { - ComPtr<IAsyncInfo> info; - it->op.As(&info); - info->Cancel(); - it = d->requests.erase(it); - } - emit captureQueueChanged(true); -} - -void QWinRTCameraImageCaptureControl::onCameraStateChanged(QCamera::State state) -{ - Q_D(QWinRTCameraImageCaptureControl); - const bool newActive = state == QCamera::ActiveState; - if (d->isActive == newActive) - return; - - d->isActive = newActive; - emit readyForCaptureChanged(newActive); -} - -HRESULT QWinRTCameraImageCaptureControl::onCaptureCompleted(IAsyncAction *asyncInfo, AsyncStatus status) -{ - qCDebug(lcMMCamera) << __FUNCTION__; - Q_D(QWinRTCameraImageCaptureControl); - - if (status == Canceled || !d->requests.contains(asyncInfo)) - return S_OK; - - CaptureRequest request = d->requests.take(asyncInfo); - emit captureQueueChanged(d->requests.isEmpty()); - HRESULT hr; - if (status == Error) { - hr = asyncInfo->GetResults(); - emit error(request.id, QCameraImageCapture::ResourceError, qt_error_string(hr)); - return S_OK; - } - - quint64 dataLength; - hr = request.stream->get_Size(&dataLength); - Q_ASSERT_SUCCEEDED(hr); - if (dataLength == 0 || dataLength > INT_MAX) { - emit error(request.id, QCameraImageCapture::FormatError, tr("Invalid photo data length.")); - return S_OK; - } - - ComPtr<IBitmapDecoderStatics> bitmapFactory; - hr = GetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Graphics_Imaging_BitmapDecoder).Get(), - &bitmapFactory); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncOperation<BitmapDecoder *>> op; - hr = bitmapFactory->CreateAsync(request.stream.Get(), &op); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IBitmapDecoder> decoder; - hr = QWinRTFunctions::await(op, decoder.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncOperation<BitmapFrame *>> op2; - hr = decoder->GetFrameAsync(0, &op2); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IBitmapFrame> frame; - hr = QWinRTFunctions::await(op2, frame.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IBitmapTransform> transform; - hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Graphics_Imaging_BitmapTransform).Get(), - &transform); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IAsyncOperation<PixelDataProvider *>> op3; - hr = frame->GetPixelDataTransformedAsync(BitmapPixelFormat_Rgba8, BitmapAlphaMode_Straight, - transform.Get(), ExifOrientationMode_IgnoreExifOrientation, - ColorManagementMode_DoNotColorManage, &op3); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IPixelDataProvider> pixelDataProvider; - hr = QWinRTFunctions::await(op3, pixelDataProvider.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - UINT32 pixelDataSize; - BYTE *pixelData; - hr = pixelDataProvider->DetachPixelData(&pixelDataSize, &pixelData); - - UINT32 pixelHeight; - hr = frame->get_PixelHeight(&pixelHeight); - Q_ASSERT_SUCCEEDED(hr); - UINT32 pixelWidth; - hr = frame->get_PixelWidth(&pixelWidth); - Q_ASSERT_SUCCEEDED(hr); - const QImage image(pixelData, int(pixelWidth), int(pixelHeight), - QImage::Format_RGBA8888, - reinterpret_cast<QImageCleanupFunction>(&freeImageData), pixelData); - emit imageCaptured(request.id, image); - - QWinRTImageEncoderControl *imageEncoderControl = static_cast<QWinRTImageEncoderControl*>(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")); - - return S_OK; -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h deleted file mode 100644 index ce1404e1c..000000000 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERAIMAGECAPTURECONTROL_H -#define QWINRTCAMERAIMAGECAPTURECONTROL_H - -#include <QtMultimedia/QCamera> -#include <QtMultimedia/QCameraImageCaptureControl> -#include <QtCore/qt_windows.h> - -namespace ABI { - namespace Windows { - namespace Foundation { - struct IAsyncAction; - enum class AsyncStatus; - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTCameraControl; - -class QWinRTCameraImageCaptureControlPrivate; -class QWinRTCameraImageCaptureControl : public QCameraImageCaptureControl -{ - Q_OBJECT -public: - explicit QWinRTCameraImageCaptureControl(QWinRTCameraControl *parent); - - bool isReadyForCapture() const override; - - QCameraImageCapture::DriveMode driveMode() const override; - void setDriveMode(QCameraImageCapture::DriveMode mode) override; - - int capture(const QString &fileName) override; - void cancelCapture() override; - -private slots: - void onCameraStateChanged(QCamera::State state); - -signals: - void captureQueueChanged(bool isEmpty); - -private: - HRESULT onCaptureCompleted(ABI::Windows::Foundation::IAsyncAction *, - ABI::Windows::Foundation::AsyncStatus); - - QScopedPointer<QWinRTCameraImageCaptureControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCameraImageCaptureControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTCAMERAIMAGECAPTURECONTROL_H diff --git a/src/plugins/winrt/qwinrtcamerainfocontrol.cpp b/src/plugins/winrt/qwinrtcamerainfocontrol.cpp deleted file mode 100644 index 30d526d65..000000000 --- a/src/plugins/winrt/qwinrtcamerainfocontrol.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcamerainfocontrol.h" -#include "qwinrtvideodeviceselectorcontrol.h" - -QT_BEGIN_NAMESPACE - -QWinRTCameraInfoControl::QWinRTCameraInfoControl(QObject *parent) - : QCameraInfoControl(parent) -{ -} - -QCamera::Position QWinRTCameraInfoControl::cameraPosition(const QString &deviceName) const -{ - return QWinRTVideoDeviceSelectorControl::cameraPosition(deviceName); -} - -int QWinRTCameraInfoControl::cameraOrientation(const QString &deviceName) const -{ - return QWinRTVideoDeviceSelectorControl::cameraOrientation(deviceName); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcamerainfocontrol.h b/src/plugins/winrt/qwinrtcamerainfocontrol.h deleted file mode 100644 index 0f49ba244..000000000 --- a/src/plugins/winrt/qwinrtcamerainfocontrol.h +++ /dev/null @@ -1,59 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERAINFOCONTROL_H -#define QWINRTCAMERAINFOCONTROL_H - -#include <QtMultimedia/QCameraInfoControl> - -QT_BEGIN_NAMESPACE - -class QWinRTCameraInfoControl : public QCameraInfoControl -{ - Q_OBJECT -public: - explicit QWinRTCameraInfoControl(QObject *parent = nullptr); - - QCamera::Position cameraPosition(const QString &deviceName) const override; - int cameraOrientation(const QString &deviceName) const override; -}; - -QT_END_NAMESPACE - -#endif // QWINRTCAMERAINFOCONTROL_H diff --git a/src/plugins/winrt/qwinrtcameralockscontrol.cpp b/src/plugins/winrt/qwinrtcameralockscontrol.cpp deleted file mode 100644 index cc3b91bab..000000000 --- a/src/plugins/winrt/qwinrtcameralockscontrol.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include <QCameraFocusControl> - -#include "qwinrtcameralockscontrol.h" -#include "qwinrtcameracontrol.h" - -QT_BEGIN_NAMESPACE - -QWinRTCameraLocksControl::QWinRTCameraLocksControl(QObject *parent) - : QCameraLocksControl(parent) - , m_supportedLocks(QCamera::NoLock) - , m_focusLockStatus(QCamera::Unlocked) -{ -} - -QCamera::LockTypes QWinRTCameraLocksControl::supportedLocks() const -{ - return m_supportedLocks; -} - -QCamera::LockStatus QWinRTCameraLocksControl::lockStatus(QCamera::LockType lock) const -{ - switch (lock) { - case QCamera::LockFocus: - return m_focusLockStatus; - case QCamera::LockExposure: - case QCamera::LockWhiteBalance: - default: - return QCamera::Unlocked; - } -} - -void QWinRTCameraLocksControl::searchAndLock(QCamera::LockTypes locks) -{ - QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - if (cameraControl->state() != QCamera::ActiveState) - return; - else if (locks.testFlag(QCamera::LockFocus)) - QMetaObject::invokeMethod(this, "searchAndLockFocus", Qt::QueuedConnection); - else - cameraControl->emitError(QCamera::InvalidRequestError, QStringLiteral("Unsupported camera lock type.")); -} - -void QWinRTCameraLocksControl::unlock(QCamera::LockTypes locks) -{ - if (locks.testFlag(QCamera::LockFocus)) - QMetaObject::invokeMethod(this, "unlockFocus", Qt::QueuedConnection); -} - -void QWinRTCameraLocksControl::initialize() -{ - QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - QCameraFocusControl *focusControl = cameraControl->cameraFocusControl(); - Q_ASSERT(focusControl); - if (focusControl->isFocusModeSupported(QCameraFocus::AutoFocus)) - m_supportedLocks |= QCamera::LockFocus; -} - -void QWinRTCameraLocksControl::searchAndLockFocus() -{ - if (QCamera::Locked == m_focusLockStatus) - unlockFocus(); - QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - QCameraFocusControl *focusControl = cameraControl->cameraFocusControl(); - Q_ASSERT(focusControl); - if (focusControl->focusMode().testFlag(QCameraFocus::ContinuousFocus)) { - cameraControl->emitError(QCamera::NotSupportedFeatureError, QStringLiteral("Camera can't lock focus in continuous focus mode.")); - } else { - m_focusLockStatus = QCamera::Searching; - emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired); - if (cameraControl->focus()) { - m_focusLockStatus = cameraControl->lockFocus() ? QCamera::Locked : QCamera::Unlocked; - emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::LockAcquired); - } - } -} - -void QWinRTCameraLocksControl::unlockFocus() -{ - if (QCamera::Unlocked == m_focusLockStatus) - return; - QWinRTCameraControl *cameraControl = qobject_cast<QWinRTCameraControl *>(parent()); - Q_ASSERT(cameraControl); - m_focusLockStatus = cameraControl->unlockFocus() ? QCamera::Unlocked : QCamera::Locked; - emit lockStatusChanged(QCamera::LockFocus, m_focusLockStatus, QCamera::UserRequest); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameralockscontrol.h b/src/plugins/winrt/qwinrtcameralockscontrol.h deleted file mode 100644 index 61015fdaa..000000000 --- a/src/plugins/winrt/qwinrtcameralockscontrol.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERALOCKSCONTROL_H -#define QWINRTCAMERALOCKSCONTROL_H - -#include <QCameraLocksControl> - -QT_BEGIN_NAMESPACE - -class QWinRTCameraControl; -class QWinRTCameraLocksControl : public QCameraLocksControl -{ - Q_OBJECT -public: - explicit QWinRTCameraLocksControl(QObject *parent); - - QCamera::LockTypes supportedLocks() const override; - QCamera::LockStatus lockStatus(QCamera::LockType lock) const override; - void searchAndLock(QCamera::LockTypes locks) override; - void unlock(QCamera::LockTypes locks) override; - void initialize(); - -private: - Q_INVOKABLE void searchAndLockFocus(); - Q_INVOKABLE void unlockFocus(); - QCamera::LockTypes m_supportedLocks; - QCamera::LockStatus m_focusLockStatus; -}; - -QT_END_NAMESPACE - -#endif // QWINRTCAMERALOCKSCONTROL_H diff --git a/src/plugins/winrt/qwinrtcameraservice.cpp b/src/plugins/winrt/qwinrtcameraservice.cpp deleted file mode 100644 index d0327a708..000000000 --- a/src/plugins/winrt/qwinrtcameraservice.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcameraservice.h" -#include "qwinrtcameracontrol.h" -#include "qwinrtcamerainfocontrol.h" -#include "qwinrtvideoprobecontrol.h" -#include "qwinrtcameravideorenderercontrol.h" - -#include <QtCore/QCoreApplication> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QPointer> -#include <QtMultimedia/QCameraImageCaptureControl> -#include <QtMultimedia/QVideoRendererControl> -#include <QtMultimedia/QVideoDeviceSelectorControl> -#include <QtMultimedia/QImageEncoderControl> -#include <QtMultimedia/QCameraFlashControl> -#include <QtMultimedia/QCameraFocusControl> -#include <QtMultimedia/QCameraLocksControl> -#include <QtMultimedia/QMediaVideoProbeControl> - -QT_BEGIN_NAMESPACE - -class QWinRTCameraServicePrivate -{ -public: - QPointer<QWinRTCameraControl> cameraControl; - QPointer<QWinRTCameraInfoControl> cameraInfoControl; -}; - -QWinRTCameraService::QWinRTCameraService(QObject *parent) - : QMediaService(parent), d_ptr(new QWinRTCameraServicePrivate) -{ -} - -QMediaControl *QWinRTCameraService::requestControl(const char *name) -{ - Q_D(QWinRTCameraService); - - if (qstrcmp(name, QCameraControl_iid) == 0) { - if (!d->cameraControl) - d->cameraControl = new QWinRTCameraControl(this); - return d->cameraControl; - } - if (qstrcmp(name, QCameraInfoControl_iid) == 0) { - if (!d->cameraInfoControl) - d->cameraInfoControl = new QWinRTCameraInfoControl(this); - return d->cameraInfoControl; - } - - if (!d->cameraControl) - return nullptr; - - if (qstrcmp(name, QVideoRendererControl_iid) == 0) - return d->cameraControl->videoRenderer(); - - if (qstrcmp(name, QVideoDeviceSelectorControl_iid) == 0) - return d->cameraControl->videoDeviceSelector(); - - if (qstrcmp(name, QCameraImageCaptureControl_iid) == 0) - return d->cameraControl->imageCaptureControl(); - - if (qstrcmp(name, QImageEncoderControl_iid) == 0) - return d->cameraControl->imageEncoderControl(); - - if (qstrcmp(name, QCameraFlashControl_iid) == 0) - return d->cameraControl->cameraFlashControl(); - - if (qstrcmp(name, QCameraFocusControl_iid) == 0) - return d->cameraControl->cameraFocusControl(); - - if (qstrcmp(name, QCameraLocksControl_iid) == 0) - return d->cameraControl->cameraLocksControl(); - - if (qstrcmp(name, QMediaVideoProbeControl_iid) == 0) - return new QWinRTVideoProbeControl(qobject_cast<QWinRTCameraVideoRendererControl *>(d->cameraControl->videoRenderer())); - - return nullptr; -} - -void QWinRTCameraService::releaseControl(QMediaControl *control) -{ - Q_ASSERT(control); - if (QWinRTVideoProbeControl *videoProbe = qobject_cast<QWinRTVideoProbeControl *>(control)) - videoProbe->deleteLater(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameraservice.h b/src/plugins/winrt/qwinrtcameraservice.h deleted file mode 100644 index b2d213b87..000000000 --- a/src/plugins/winrt/qwinrtcameraservice.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERASERVICE_H -#define QWINRTCAMERASERVICE_H - -#include <QtMultimedia/QMediaService> - -QT_BEGIN_NAMESPACE - -class QWinRTCameraServicePrivate; -class QWinRTCameraService : public QMediaService -{ - Q_OBJECT -public: - explicit QWinRTCameraService(QObject *parent = nullptr); - - QMediaControl *requestControl(const char *name) override; - void releaseControl(QMediaControl *control) override; - -private: - QScopedPointer<QWinRTCameraServicePrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCameraService) -}; - -QT_END_NAMESPACE - -#endif // QWINRTCAMERASERVICE_H diff --git a/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp b/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp deleted file mode 100644 index 8b757b467..000000000 --- a/src/plugins/winrt/qwinrtcameravideorenderercontrol.cpp +++ /dev/null @@ -1,437 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtcameravideorenderercontrol.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QSize> -#include <QtCore/QPointer> -#include <QtCore/QVector> -#include <QVideoFrame> - -#include <d3d11.h> -#include <d3d11_1.h> -#include <mfapi.h> -#include <wrl.h> - -#include "qwinrtcameracontrol.h" - -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) -#include <windows.security.exchangeactivesyncprovisioning.h> -using namespace ABI::Windows::Security::ExchangeActiveSyncProvisioning; -#endif - -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; - -QT_BEGIN_NAMESPACE - -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) -template <int n> -static bool blacklisted(const wchar_t (&blackListName)[n], const HString &deviceModel) -{ - quint32 deviceNameLength; - const wchar_t *deviceName = deviceModel.GetRawBuffer(&deviceNameLength); - return n - 1 <= deviceNameLength && !wmemcmp(blackListName, deviceName, n - 1); -} -#endif - -class QWinRTCameraVideoBuffer : public QAbstractVideoBuffer -{ -public: - QWinRTCameraVideoBuffer(IMF2DBuffer *buffer, int size, QWinRTCameraControl *control) - : QAbstractVideoBuffer(NoHandle) - , buffer(buffer) - , currentMode(NotMapped) - , size(size) - , control(control) - { - Q_ASSERT(control); - } - - ~QWinRTCameraVideoBuffer() override - { - unmap(); - } - - MapMode mapMode() const override - { - return currentMode; - } - - uchar *map(MapMode mode, int *numBytes, int *bytesPerLine) override - { - if (currentMode != NotMapped || mode == NotMapped || (control && control->state() != QCamera::ActiveState)) - return nullptr; - - BYTE *bytes; - LONG stride; - HRESULT hr = buffer->Lock2D(&bytes, &stride); - RETURN_IF_FAILED("Failed to lock camera frame buffer", return nullptr); - control->frameMapped(); - - if (bytesPerLine) - *bytesPerLine = stride; - if (numBytes) - *numBytes = size; - currentMode = mode; - return bytes; - } - - void unmap() override - { - if (currentMode == NotMapped) - return; - HRESULT hr = buffer->Unlock2D(); - RETURN_VOID_IF_FAILED("Failed to unlock camera frame buffer"); - currentMode = NotMapped; - if (control) - control->frameUnmapped(); - } - -private: - ComPtr<IMF2DBuffer> buffer; - MapMode currentMode; - int size; - QPointer<QWinRTCameraControl> control; -}; - -class D3DVideoBlitter -{ -public: - D3DVideoBlitter(ID3D11Texture2D *target) - : m_target(target) - { - Q_ASSERT(target); - target->GetDevice(&m_d3dDevice); - Q_ASSERT(m_d3dDevice); - HRESULT hr; - hr = m_d3dDevice.As(&m_videoDevice); - Q_ASSERT_SUCCEEDED(hr); - } - - ID3D11Device *device() const - { - return m_d3dDevice.Get(); - } - - ID3D11Texture2D *target() const - { - return m_target; - } - - void blit(ID3D11Texture2D *texture) - { - HRESULT hr; - D3D11_TEXTURE2D_DESC desc; - texture->GetDesc(&desc); - if (!m_videoEnumerator) { - D3D11_VIDEO_PROCESSOR_CONTENT_DESC videoProcessorDesc = { - D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE, - { 0, 0}, desc.Width, desc.Height, - { 0, 0}, desc.Width, desc.Height, - D3D11_VIDEO_USAGE_OPTIMAL_SPEED - }; - hr = m_videoDevice->CreateVideoProcessorEnumerator(&videoProcessorDesc, &m_videoEnumerator); - RETURN_VOID_IF_FAILED("Failed to create video enumerator"); - } - - if (!m_videoProcessor) { - hr = m_videoDevice->CreateVideoProcessor(m_videoEnumerator.Get(), 0, &m_videoProcessor); - RETURN_VOID_IF_FAILED("Failed to create video processor"); - } - - if (!m_outputView) { - D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC outputDesc = { D3D11_VPOV_DIMENSION_TEXTURE2D, {{ 0 }} }; - hr = m_videoDevice->CreateVideoProcessorOutputView( - m_target, m_videoEnumerator.Get(), &outputDesc, &m_outputView); - RETURN_VOID_IF_FAILED("Failed to create video output view"); - } - - ComPtr<IDXGIResource1> sourceResource; - hr = texture->QueryInterface(IID_PPV_ARGS(&sourceResource)); - RETURN_VOID_IF_FAILED("Failed to query interface IDXGIResource1"); - HANDLE sharedHandle = nullptr; - hr = sourceResource->CreateSharedHandle(nullptr, DXGI_SHARED_RESOURCE_READ, nullptr, &sharedHandle); - RETURN_VOID_IF_FAILED("Failed to create shared handle"); - ComPtr<ID3D11Device1> dev; - hr = m_d3dDevice.As(&dev); - RETURN_VOID_IF_FAILED("Failed to cast from ID3D11Device to ID3D11Device1"); - ComPtr<ID3D11Texture2D> sharedTexture; - hr = dev->OpenSharedResource1(sharedHandle, IID_PPV_ARGS(&sharedTexture)); - RETURN_VOID_IF_FAILED("Failed to open shared resource"); - - D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC inputViewDesc = { - 0, D3D11_VPIV_DIMENSION_TEXTURE2D, { 0, 0 } - }; - ComPtr<ID3D11VideoProcessorInputView> inputView; - hr = m_videoDevice->CreateVideoProcessorInputView( - sharedTexture.Get(), m_videoEnumerator.Get(), &inputViewDesc, &inputView); - CloseHandle(sharedHandle); - RETURN_VOID_IF_FAILED("Failed to create video input view"); - - ComPtr<ID3D11DeviceContext> context; - ComPtr<ID3D11VideoContext> videoContext; - m_d3dDevice->GetImmediateContext(&context); - hr = context.As(&videoContext); - RETURN_VOID_IF_FAILED("Failed to get video context"); - - D3D11_VIDEO_PROCESSOR_STREAM stream = { TRUE, 0, 0, 0, 0, nullptr, - nullptr, nullptr, nullptr, - nullptr, nullptr}; - stream.pInputSurface = inputView.Get(); - hr = videoContext->VideoProcessorBlt( - m_videoProcessor.Get(), m_outputView.Get(), 0, 1, &stream); - RETURN_VOID_IF_FAILED("Failed to get blit video frame"); - } - -private: - ComPtr<ID3D11Device> m_d3dDevice; - ID3D11Texture2D *m_target; - ComPtr<ID3D11VideoDevice> m_videoDevice; - ComPtr<ID3D11VideoProcessorEnumerator> m_videoEnumerator; - ComPtr<ID3D11VideoProcessor> m_videoProcessor; - ComPtr<ID3D11VideoProcessorOutputView> m_outputView; -}; - -#define CAMERA_SAMPLE_QUEUE_SIZE 5 -class QWinRTCameraVideoRendererControlPrivate -{ -public: - QScopedPointer<D3DVideoBlitter> blitter; - ComPtr<IMF2DBuffer> buffers[CAMERA_SAMPLE_QUEUE_SIZE]; - QAtomicInteger<quint16> writeIndex; - QAtomicInteger<quint16> readIndex; - QVideoFrame::PixelFormat cameraSampleformat; - int cameraSampleSize; - uint videoProbesCounter; - bool getCameraSampleInfo(const ComPtr<IMF2DBuffer> &buffer, - QWinRTAbstractVideoRendererControl::BlitMode *mode); - ComPtr<IMF2DBuffer> dequeueBuffer(); -}; - -bool QWinRTCameraVideoRendererControlPrivate::getCameraSampleInfo(const ComPtr<IMF2DBuffer> &buffer, - QWinRTAbstractVideoRendererControl::BlitMode *mode) -{ - Q_ASSERT(mode); - ComPtr<ID3D11Texture2D> sourceTexture; - ComPtr<IMFDXGIBuffer> dxgiBuffer; - HRESULT hr = buffer.As(&dxgiBuffer); - Q_ASSERT_SUCCEEDED(hr); - hr = dxgiBuffer->GetResource(IID_PPV_ARGS(&sourceTexture)); - if (FAILED(hr)) { - qErrnoWarning(hr, "The video frame does not support texture output"); - cameraSampleformat = QVideoFrame::Format_Invalid; - return false; - } - D3D11_TEXTURE2D_DESC desc; - sourceTexture->GetDesc(&desc); - - if (!(desc.MiscFlags & D3D11_RESOURCE_MISC_SHARED)) - *mode = QWinRTAbstractVideoRendererControl::MediaFoundation; - - switch (desc.Format) { - case DXGI_FORMAT_R8G8B8A8_TYPELESS: - cameraSampleformat = QVideoFrame::Format_ARGB32; - break; - case DXGI_FORMAT_NV12: - cameraSampleformat = QVideoFrame::Format_NV12; - break; - case DXGI_FORMAT_YUY2: - cameraSampleformat = QVideoFrame::Format_YUYV; - break; - default: - cameraSampleformat = QVideoFrame::Format_Invalid; - qErrnoWarning("Unsupported camera probe format."); - return false; - } - DWORD pcbLength; - hr = buffer->GetContiguousLength(&pcbLength); - Q_ASSERT_SUCCEEDED(hr); - cameraSampleSize = int(pcbLength); - return true; -} - -QWinRTCameraVideoRendererControl::QWinRTCameraVideoRendererControl(const QSize &size, QObject *parent) - : QWinRTAbstractVideoRendererControl(size, parent), d_ptr(new QWinRTCameraVideoRendererControlPrivate) -{ - Q_D(QWinRTCameraVideoRendererControl); - d->cameraSampleformat = QVideoFrame::Format_User; - d->videoProbesCounter = 0; - -#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) - // Workaround for certain devices which fail to blit. - ComPtr<IEasClientDeviceInformation> deviceInfo; - HRESULT hr = RoActivateInstance(HString::MakeReference(RuntimeClass_Windows_Security_ExchangeActiveSyncProvisioning_EasClientDeviceInformation).Get(), - &deviceInfo); - Q_ASSERT_SUCCEEDED(hr); - HString deviceModel; - hr = deviceInfo->get_SystemProductName(deviceModel.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - const bool blacklist = blacklisted(L"RM-1045", deviceModel) // Lumia 930 - || blacklisted(L"RM-937", deviceModel); // Lumia 1520 - setBlitMode(blacklist ? MediaFoundation : DirectVideo); -#endif -} - -QWinRTCameraVideoRendererControl::~QWinRTCameraVideoRendererControl() -{ - shutdown(); -} - -bool QWinRTCameraVideoRendererControl::render(ID3D11Texture2D *target) -{ - Q_D(QWinRTCameraVideoRendererControl); - ComPtr<IMF2DBuffer> buffer = d->dequeueBuffer(); - if (!buffer) { - emit bufferRequested(); - return false; - } - - ComPtr<ID3D11Texture2D> sourceTexture; - ComPtr<IMFDXGIBuffer> dxgiBuffer; - HRESULT hr = buffer.As(&dxgiBuffer); - Q_ASSERT_SUCCEEDED(hr); - hr = dxgiBuffer->GetResource(IID_PPV_ARGS(&sourceTexture)); - if (FAILED(hr)) { - qErrnoWarning(hr, "The video frame does not support texture output; aborting rendering."); - return false; - } - - if (!d->blitter || d->blitter->target() != target) - d->blitter.reset(new D3DVideoBlitter(target)); - - d->blitter->blit(sourceTexture.Get()); - - emit bufferRequested(); - return true; -} - -bool QWinRTCameraVideoRendererControl::dequeueFrame(QVideoFrame *frame) -{ - Q_ASSERT(frame); - Q_D(QWinRTCameraVideoRendererControl); - - ComPtr<IMF2DBuffer> buffer = d->dequeueBuffer(); - if (!buffer || d->cameraSampleformat == QVideoFrame::Format_Invalid) { - emit bufferRequested(); - return false; - } - - QWinRTCameraVideoBuffer *videoBuffer = new QWinRTCameraVideoBuffer(buffer.Get(), - d->cameraSampleSize, - static_cast<QWinRTCameraControl *>(parent())); - *frame = QVideoFrame(videoBuffer, size(), d->cameraSampleformat); - - emit bufferRequested(); - return true; -} - -void QWinRTCameraVideoRendererControl::queueBuffer(IMF2DBuffer *buffer) -{ - Q_D(QWinRTCameraVideoRendererControl); - Q_ASSERT(buffer); - - if (d->cameraSampleformat == QVideoFrame::Format_User) { - BlitMode mode = blitMode(); - d->getCameraSampleInfo(buffer, &mode); - setBlitMode(mode); - } - - if (d->videoProbesCounter > 0 && d->cameraSampleformat != QVideoFrame::Format_Invalid) { - QWinRTCameraVideoBuffer *videoBuffer = new QWinRTCameraVideoBuffer(buffer, - d->cameraSampleSize, - static_cast<QWinRTCameraControl *>(parent())); - QVideoFrame frame(videoBuffer, size(), d->cameraSampleformat); - emit videoFrameProbed(frame); - } - - const quint16 writeIndex = (d->writeIndex + 1) % CAMERA_SAMPLE_QUEUE_SIZE; - if (d->readIndex == writeIndex) // Drop new sample if queue is full - return; - d->buffers[d->writeIndex] = buffer; - d->writeIndex = writeIndex; - - if (!surface()) { - d->dequeueBuffer(); - emit bufferRequested(); - } -} - -ComPtr<IMF2DBuffer> QWinRTCameraVideoRendererControlPrivate::dequeueBuffer() -{ - const quint16 currentReadIndex = readIndex; - if (currentReadIndex == writeIndex) - return nullptr; - - ComPtr<IMF2DBuffer> buffer = buffers[currentReadIndex]; - Q_ASSERT(buffer); - buffers[currentReadIndex].Reset(); - readIndex = (currentReadIndex + 1) % CAMERA_SAMPLE_QUEUE_SIZE; - return buffer; -} - -void QWinRTCameraVideoRendererControl::discardBuffers() -{ - Q_D(QWinRTCameraVideoRendererControl); - d->writeIndex = d->readIndex = 0; - for (ComPtr<IMF2DBuffer> &buffer : d->buffers) - buffer.Reset(); -} - -void QWinRTCameraVideoRendererControl::incrementProbe() -{ - Q_D(QWinRTCameraVideoRendererControl); - ++d->videoProbesCounter; -} - -void QWinRTCameraVideoRendererControl::decrementProbe() -{ - Q_D(QWinRTCameraVideoRendererControl); - Q_ASSERT(d->videoProbesCounter > 0); - --d->videoProbesCounter; -} - -void QWinRTCameraVideoRendererControl::resetSampleFormat() -{ - Q_D(QWinRTCameraVideoRendererControl); - d->cameraSampleformat = QVideoFrame::Format_User; -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtcameravideorenderercontrol.h b/src/plugins/winrt/qwinrtcameravideorenderercontrol.h deleted file mode 100644 index e50bcd2e6..000000000 --- a/src/plugins/winrt/qwinrtcameravideorenderercontrol.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTCAMERAVIDEORENDERERCONTROL_H -#define QWINRTCAMERAVIDEORENDERERCONTROL_H - -#include "qwinrtabstractvideorenderercontrol.h" - -#include <QVideoFrame> - -struct IMF2DBuffer; - -QT_BEGIN_NAMESPACE - -class QWinRTVideoProbeControl; -class QVideoSurfaceFormat; -class QWinRTCameraVideoRendererControlPrivate; -class QWinRTCameraVideoRendererControl : public QWinRTAbstractVideoRendererControl -{ - Q_OBJECT -public: - explicit QWinRTCameraVideoRendererControl(const QSize &size, QObject *parent); - ~QWinRTCameraVideoRendererControl() override; - - bool render(ID3D11Texture2D *texture) override; - bool dequeueFrame(QVideoFrame *frame) override; - void queueBuffer(IMF2DBuffer *buffer); - void discardBuffers(); - void incrementProbe(); - void decrementProbe(); - -signals: - void bufferRequested(); - void videoFrameProbed(const QVideoFrame &frame); - -public slots: - void resetSampleFormat(); - -private: - QScopedPointer<QWinRTCameraVideoRendererControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTCameraVideoRendererControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTCAMERAVIDEORENDERERCONTROL_H diff --git a/src/plugins/winrt/qwinrtimageencodercontrol.cpp b/src/plugins/winrt/qwinrtimageencodercontrol.cpp deleted file mode 100644 index 2aed5f8a6..000000000 --- a/src/plugins/winrt/qwinrtimageencodercontrol.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtimageencodercontrol.h" -QT_BEGIN_NAMESPACE - -class QWinRTImageEncoderControlPrivate -{ -public: - QList<QSize> 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<QSize> 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<QSize> resolution) -{ - Q_D(QWinRTImageEncoderControl); - d->supportedResolutions = resolution; - applySettings(); -} - -void QWinRTImageEncoderControl::applySettings() -{ - Q_D(QWinRTImageEncoderControl); - if (d->imageEncoderSetting.codec().isEmpty()) - d->imageEncoderSetting.setCodec(QStringLiteral("jpeg")); - - if (d->supportedResolutions.isEmpty()) - return; - - QSize requestResolution = d->imageEncoderSetting.resolution(); - if (!requestResolution.isValid()) { - d->imageEncoderSetting.setResolution(d->supportedResolutions.last()); - return; - } - if (d->supportedResolutions.contains(requestResolution)) - return; - - // Find closest resolution from the list - const int pixelCount = requestResolution.width() * requestResolution.height(); - int minimumGap = std::numeric_limits<int>::max(); - for (const QSize &size : qAsConst(d->supportedResolutions)) { - int gap = qAbs(pixelCount - size.width() * size.height()); - if (gap < minimumGap) { - minimumGap = gap; - requestResolution = size; - if (gap == 0) - break; - } - } - d->imageEncoderSetting.setResolution(requestResolution); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtimageencodercontrol.h b/src/plugins/winrt/qwinrtimageencodercontrol.h deleted file mode 100644 index 711e550c7..000000000 --- a/src/plugins/winrt/qwinrtimageencodercontrol.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTIMAGEENCODERCONTROL_H -#define QWINRTIMAGEENCODERCONTROL_H - -#include <qimageencodercontrol.h> - -QT_BEGIN_NAMESPACE - -class QWinRTImageEncoderControlPrivate; -class QWinRTImageEncoderControl : public QImageEncoderControl -{ - Q_OBJECT -public: - explicit QWinRTImageEncoderControl(QObject *parent = nullptr); - - QStringList supportedImageCodecs() const override; - QString imageCodecDescription(const QString &codecName) const override; - QList<QSize> supportedResolutions(const QImageEncoderSettings &settings, bool *continuous = nullptr) const override; - QImageEncoderSettings imageSettings() const override; - void setImageSettings(const QImageEncoderSettings &settings) override; - - void setSupportedResolutionsList(const QList<QSize> resolution); - void applySettings(); - -private: - QScopedPointer<QWinRTImageEncoderControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTImageEncoderControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTIMAGEENCODERCONTROL_H diff --git a/src/plugins/winrt/qwinrtmediaplayercontrol.cpp b/src/plugins/winrt/qwinrtmediaplayercontrol.cpp deleted file mode 100644 index 0ed9f027e..000000000 --- a/src/plugins/winrt/qwinrtmediaplayercontrol.cpp +++ /dev/null @@ -1,900 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtmediaplayercontrol.h" -#include "qwinrtplayerrenderercontrol.h" - -#include <QtCore/QCoreApplication> -#include <QtCore/QFile> -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QSize> -#include <QtCore/QTimerEvent> -#include <QtCore/QUrl> -#include <QtMultimedia/QMediaPlaylist> -#include <QtConcurrent/QtConcurrentRun> - -#include <dxgi.h> -#include <OleAuto.h> -#include <mfapi.h> -#include <mfmediaengine.h> - -#include <wrl.h> -using namespace Microsoft::WRL; - -QT_BEGIN_NAMESPACE - -#define QT_WINRT_MEDIAPLAYER_STREAM_ID "__qtmultimedia_winrt_player_stream" - -class MediaEngineNotify; -class MediaEngineSources; -class MediaEngineByteStream; -class QWinRTMediaPlayerControlPrivate -{ -public: - QMediaPlayer::State state; - QMediaPlayer::MediaStatus mediaStatus; - qint64 duration; - qint64 position; - qreal playbackRate; - int volume; - bool muted; - int bufferStatus; - bool seekable; - bool hasVideo; - bool hasAudio; - - QMediaContent media; - QScopedPointer<QIODevice, QWinRTMediaPlayerControlPrivate> stream; - QWinRTPlayerRendererControl *videoRenderer; - - ComPtr<MediaEngineNotify> notifier; - ComPtr<MediaEngineSources> sources; - ComPtr<MediaEngineByteStream> streamProvider; - ComPtr<IMFAttributes> configuration; - ComPtr<IMFMediaEngineEx> engine; - - quint32 resetToken; - ComPtr<IMFDXGIDeviceManager> manager; - - // Automatically delete streams created by the player - static inline void cleanup(QIODevice *device) - { - if (device && device->property(QT_WINRT_MEDIAPLAYER_STREAM_ID).toBool()) - device->deleteLater(); - } - - // Allows for deferred cleanup of the engine, which tends to block on shutdown - static void cleanup(QWinRTMediaPlayerControlPrivate *d); - static void shutdown(QWinRTMediaPlayerControlPrivate *d); -}; - -class MediaEngineNotify : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IMFMediaEngineNotify> -{ -public: - MediaEngineNotify(QWinRTMediaPlayerControl *q_ptr, QWinRTMediaPlayerControlPrivate *d_ptr) - : q(q_ptr), d(d_ptr) - { - } - - HRESULT __stdcall EventNotify(DWORD event, DWORD_PTR param1, DWORD param2) - { - QMediaPlayer::State newState = d->state; - QMediaPlayer::MediaStatus newStatus = d->mediaStatus; - - switch (event) { - // Media change events - case MF_MEDIA_ENGINE_EVENT_LOADEDMETADATA: { - const bool hasAudio = d->engine->HasAudio(); - if (d->hasAudio != hasAudio) { - d->hasAudio = hasAudio; - emit q->audioAvailableChanged(d->hasAudio); - } - - const bool hasVideo = d->engine->HasVideo(); - if (d->hasVideo != hasVideo) { - d->hasVideo = hasVideo; - emit q->audioAvailableChanged(d->hasAudio); - } - - if (hasVideo) { - HRESULT hr; - DWORD width, height; - hr = d->engine->GetNativeVideoSize(&width, &height); - if (FAILED(hr)) - break; - d->videoRenderer->setSize(QSize(int(width), int(height))); - } - - newStatus = QMediaPlayer::LoadedMedia; - break; - } - case MF_MEDIA_ENGINE_EVENT_LOADSTART: - case MF_MEDIA_ENGINE_EVENT_PROGRESS: { - newStatus = QMediaPlayer::LoadingMedia; - break; - } - case MF_MEDIA_ENGINE_EVENT_CANPLAY: - d->bufferStatus = 100; // Fired when buffering is not used - newStatus = d->state == QMediaPlayer::StoppedState ? QMediaPlayer::LoadedMedia - : QMediaPlayer::BufferedMedia; - break; - case MF_MEDIA_ENGINE_EVENT_BUFFERINGSTARTED: - case MF_MEDIA_ENGINE_EVENT_BUFFERINGENDED: { - PROPVARIANT stat; - HRESULT hr = d->engine->GetStatistics(MF_MEDIA_ENGINE_STATISTIC_BUFFER_PROGRESS, &stat); - if (SUCCEEDED(hr)) { - d->bufferStatus = stat.lVal; - PropVariantClear(&stat); - } - newStatus = d->state == QMediaPlayer::StoppedState ? QMediaPlayer::LoadedMedia - : (d->bufferStatus == 100 ? QMediaPlayer::BufferedMedia : QMediaPlayer::BufferingMedia); - break; - } - //case MF_MEDIA_ENGINE_EVENT_SUSPEND: ??? - //case MF_MEDIA_ENGINE_EVENT_ABORT: ??? - case MF_MEDIA_ENGINE_EVENT_EMPTIED: { - newState = QMediaPlayer::StoppedState; - break; - } - // Transport controls - case MF_MEDIA_ENGINE_EVENT_PLAY: { - // If the media is already loaded, the playing event may not occur after stop - if (d->mediaStatus != QMediaPlayer::LoadedMedia) - break; - Q_FALLTHROUGH(); - } - case MF_MEDIA_ENGINE_EVENT_PLAYING: { - newState = QMediaPlayer::PlayingState; - newStatus = d->bufferStatus < 100 ? QMediaPlayer::BufferingMedia - : QMediaPlayer::BufferedMedia; - break; - } - case MF_MEDIA_ENGINE_EVENT_PAUSE: { - newState = QMediaPlayer::PausedState; - break; - } - case MF_MEDIA_ENGINE_EVENT_STALLED: { - newStatus = QMediaPlayer::StalledMedia; - break; - } - case MF_MEDIA_ENGINE_EVENT_WAITING: { - newStatus = QMediaPlayer::StalledMedia; - break; - } - case MF_MEDIA_ENGINE_EVENT_ENDED: { - newState = QMediaPlayer::StoppedState; - newStatus = QMediaPlayer::EndOfMedia; - break; - } - // Media attributes - case MF_MEDIA_ENGINE_EVENT_DURATIONCHANGE: { - double duration = d->engine->GetDuration() * 1000; - if (!qFuzzyCompare(d->duration, duration)) { - d->duration = qint64(duration); - emit q->durationChanged(d->duration); - } - break; - } - case MF_MEDIA_ENGINE_EVENT_TIMEUPDATE: { - double position = d->engine->GetCurrentTime() * 1000; - if (!qFuzzyCompare(d->position, position)) { - d->position = qint64(position); - emit q->positionChanged(d->position); - } - // Stopped state: paused at beginning - if (qFuzzyIsNull(position) && d->state == QMediaPlayer::PausedState) - newState = QMediaPlayer::StoppedState; - break; - } - case MF_MEDIA_ENGINE_EVENT_RATECHANGE: { - double playbackRate = d->engine->GetPlaybackRate(); - if (!qFuzzyCompare(d->playbackRate, playbackRate)) { - d->playbackRate = playbackRate; - emit q->playbackRateChanged(d->playbackRate); - } - break; - } - // Error handling - case MF_MEDIA_ENGINE_EVENT_ERROR: { - newState = QMediaPlayer::StoppedState; - newStatus = QMediaPlayer::InvalidMedia; - switch (param1) { - default: - case MF_MEDIA_ENGINE_ERR_NOERROR: - newStatus = QMediaPlayer::UnknownMediaStatus; - emit q->error(QMediaPlayer::ResourceError, qt_error_string(int(param2))); - break; - case MF_MEDIA_ENGINE_ERR_ABORTED: - if (d->mediaStatus == QMediaPlayer::StalledMedia || d->mediaStatus == QMediaPlayer::BufferingMedia) - d->mediaStatus = QMediaPlayer::LoadedMedia; - emit q->error(QMediaPlayer::ResourceError, QStringLiteral("The process of fetching the media resource was stopped at the user's request.")); - break; - case MF_MEDIA_ENGINE_ERR_NETWORK: - if (d->mediaStatus == QMediaPlayer::StalledMedia || d->mediaStatus == QMediaPlayer::BufferingMedia) - d->mediaStatus = QMediaPlayer::LoadedMedia; - emit q->error(QMediaPlayer::NetworkError, QStringLiteral("A network error occurred while fetching the media resource.")); - break; - case MF_MEDIA_ENGINE_ERR_DECODE: - emit q->error(QMediaPlayer::FormatError, QStringLiteral("An error occurred while decoding the media resource.")); - break; - case MF_MEDIA_ENGINE_ERR_SRC_NOT_SUPPORTED: - emit q->error(QMediaPlayer::FormatError, QStringLiteral("The media resource is not supported.")); - break; - case MF_MEDIA_ENGINE_ERR_ENCRYPTED: - emit q->error(QMediaPlayer::FormatError, QStringLiteral("An error occurred while encrypting the media resource.")); - break; - } - break; - } - default: - break; - } - - if (d->videoRenderer) - d->videoRenderer->setActive(d->state == QMediaPlayer::PlayingState && - d->videoRenderer->size().isValid()); - - const QMediaPlayer::MediaStatus oldMediaStatus = d->mediaStatus; - const QMediaPlayer::State oldState = d->state; - d->mediaStatus = newStatus; - d->state = newState; - - if (d->mediaStatus != oldMediaStatus) - emit q->mediaStatusChanged(d->mediaStatus); - - if (d->state != oldState) - emit q->stateChanged(d->state); - - return S_OK; - } - -private: - QWinRTMediaPlayerControl *q; - QWinRTMediaPlayerControlPrivate *d; -}; - -class MediaEngineSources : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IMFMediaEngineSrcElements> -{ -public: - MediaEngineSources(QWinRTMediaPlayerControlPrivate *d_ptr) - : d(d_ptr) - { - } - - DWORD __stdcall GetLength() - { - return 1; - } - - HRESULT __stdcall GetURL(DWORD index, BSTR *url) - { - Q_UNUSED(index); - const QString resourceUrl = d->media.request().url().toString(); - *url = SysAllocString((const OLECHAR *)resourceUrl.utf16()); - return S_OK; - } - - HRESULT __stdcall GetType(DWORD index, BSTR *type) - { - Q_UNUSED(index); - *type = SysAllocString(L""); - return S_OK; - } - - HRESULT __stdcall GetMedia(DWORD index, BSTR *media) - { - Q_UNUSED(index); - *media = nullptr; - return S_OK; - } - - HRESULT __stdcall AddElement(BSTR url, BSTR type, BSTR media) - { - Q_UNUSED(url); - Q_UNUSED(type); - Q_UNUSED(media); - return E_NOTIMPL; - } - - HRESULT __stdcall RemoveAllElements() - { - return E_NOTIMPL; - } - -private: - QWinRTMediaPlayerControlPrivate *d; -}; - -class MediaEngineReadResult : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IUnknown> -{ -public: - MediaEngineReadResult(BYTE *bytes, ULONG maxLength) - : bytes(bytes), maxLength(maxLength) { } - - void read(QIODevice *device) - { - bytesRead = ULONG(device->read(reinterpret_cast<char *>(bytes), maxLength)); - } - - BYTE *bytes; - ULONG maxLength; - ULONG bytesRead; -}; - -class MediaEngineByteStream : public RuntimeClass<RuntimeClassFlags<ClassicCom>, IMFByteStream> -{ -public: - MediaEngineByteStream(QWinRTMediaPlayerControlPrivate *d_ptr) - : d(d_ptr) - { - } - - HRESULT __stdcall GetCapabilities(DWORD *capabilities) - { - *capabilities |= MFBYTESTREAM_IS_READABLE; - if (!d->stream->isSequential()) - *capabilities |= MFBYTESTREAM_IS_SEEKABLE; - return S_OK; - } - - HRESULT __stdcall GetLength(QWORD *length) - { - *length = QWORD(d->stream->size()); - return S_OK; - } - - HRESULT __stdcall SetLength(QWORD length) - { - Q_UNUSED(length); - return E_NOTIMPL; - } - - HRESULT __stdcall GetCurrentPosition(QWORD *position) - { - *position = QWORD(d->stream->pos()); - return S_OK; - } - - HRESULT __stdcall SetCurrentPosition(QWORD position) - { - const qint64 pos = qint64(position); - if (pos >= d->stream->size()) { - // MSDN states we should return E_INVALIDARG, but that immediately - // stops playback and does not play remaining buffers in the queue. - // For some formats this can cause losing up to 5 seconds of the - // end of the stream. - return S_FALSE; - } - - const bool ok = d->stream->seek(pos); - return ok ? S_OK : S_FALSE; - } - - HRESULT __stdcall IsEndOfStream(BOOL *endOfStream) - { - *endOfStream = d->stream->atEnd() ? TRUE : FALSE; - return S_OK; - } - - HRESULT __stdcall Read(BYTE *bytes, ULONG maxlen, ULONG *bytesRead) - { - *bytesRead = ULONG(d->stream->read(reinterpret_cast<char *>(bytes), maxlen)); - return S_OK; - } - - HRESULT __stdcall BeginRead(BYTE *bytes, ULONG maxLength, IMFAsyncCallback *callback, IUnknown *state) - { - ComPtr<MediaEngineReadResult> readResult = Make<MediaEngineReadResult>(bytes, maxLength); - HRESULT hr; - hr = MFCreateAsyncResult(readResult.Get(), callback, state, &asyncResult); - RETURN_HR_IF_FAILED("Failed to create read callback result"); - finishRead(); - return S_OK; - } - - HRESULT __stdcall EndRead(IMFAsyncResult *result, ULONG *bytesRead) - { - HRESULT hr; - ComPtr<MediaEngineReadResult> readResult; - hr = result->GetObject(&readResult); - RETURN_HR_IF_FAILED("Failed to get read result"); - - *bytesRead = readResult->bytesRead; - return S_OK; - } - - HRESULT __stdcall Write(const BYTE *bytes, ULONG maxlen, ULONG *bytesWritten) - { - Q_UNUSED(bytes); - Q_UNUSED(maxlen); - Q_UNUSED(bytesWritten); - return E_NOTIMPL; - } - - HRESULT __stdcall BeginWrite(const BYTE *bytes, ULONG maxlen, IMFAsyncCallback *callback, IUnknown *state) - { - Q_UNUSED(bytes); - Q_UNUSED(maxlen); - Q_UNUSED(callback); - Q_UNUSED(state); - return E_NOTIMPL; - } - - HRESULT __stdcall EndWrite(IMFAsyncResult *result, ULONG *bytesWritten) - { - Q_UNUSED(result); - Q_UNUSED(bytesWritten); - return E_NOTIMPL; - } - - HRESULT __stdcall Seek(MFBYTESTREAM_SEEK_ORIGIN origin, LONGLONG offset, DWORD flags, QWORD *position) - { - Q_UNUSED(flags); - - qint64 pos = offset; - if (origin == msoCurrent) - pos += d->stream->pos(); - - const bool ok = d->stream->seek(pos); - *position = QWORD(d->stream->pos()); - - return ok ? S_OK : E_FAIL; - } - - HRESULT __stdcall Flush() - { - return E_NOTIMPL; - } - - HRESULT __stdcall Close() - { - if (asyncResult) - finishRead(); - - if (d->stream->property(QT_WINRT_MEDIAPLAYER_STREAM_ID).toBool()) - d->stream->close(); - - return S_OK; - } - - void finishRead() - { - if (!asyncResult) - return; - - HRESULT hr; - ComPtr<MediaEngineReadResult> readResult; - hr = asyncResult->GetObject(&readResult); - RETURN_VOID_IF_FAILED("Failed to get read result object"); - readResult->read(d->stream.data()); - hr = MFInvokeCallback(asyncResult.Get()); - RETURN_VOID_IF_FAILED("Failed to invoke read callback"); - asyncResult.Reset(); - } - -private: - QWinRTMediaPlayerControlPrivate *d; - - ComPtr<IMFAsyncResult> asyncResult; -}; - -void QWinRTMediaPlayerControlPrivate::cleanup(QWinRTMediaPlayerControlPrivate *d) -{ - QtConcurrent::run(&QWinRTMediaPlayerControlPrivate::shutdown, d); -} - -void QWinRTMediaPlayerControlPrivate::shutdown(QWinRTMediaPlayerControlPrivate *d) -{ - d->engine->Shutdown(); - delete d; -} - -QWinRTMediaPlayerControl::QWinRTMediaPlayerControl(IMFMediaEngineClassFactory *factory, QObject *parent) - : QMediaPlayerControl(parent), d_ptr(new QWinRTMediaPlayerControlPrivate) -{ - Q_D(QWinRTMediaPlayerControl); - - d->state = QMediaPlayer::StoppedState; - d->mediaStatus = QMediaPlayer::NoMedia; - d->duration = 0; - d->position = 0; - d->playbackRate = 1.0; - d->volume = 100; - d->bufferStatus = 0; - d->muted = false; - d->seekable = false; - d->hasAudio = false; - d->hasVideo = false; - d->videoRenderer = nullptr; - d->notifier = Make<MediaEngineNotify>(this, d); - - HRESULT hr; - hr = MFCreateDXGIDeviceManager(&d->resetToken, &d->manager); - RETURN_VOID_IF_FAILED("Failed to create DXGI device manager"); - - hr = MFCreateAttributes(&d->configuration, 1); - Q_ASSERT_SUCCEEDED(hr); - hr = d->configuration->SetUnknown(MF_MEDIA_ENGINE_CALLBACK, d->notifier.Get()); - Q_ASSERT_SUCCEEDED(hr); - hr = d->configuration->SetUnknown(MF_MEDIA_ENGINE_DXGI_MANAGER, d->manager.Get()); - Q_ASSERT_SUCCEEDED(hr); - hr = d->configuration->SetUINT32(MF_MEDIA_ENGINE_VIDEO_OUTPUT_FORMAT, DXGI_FORMAT_B8G8R8A8_UNORM); - Q_ASSERT_SUCCEEDED(hr); - - ComPtr<IMFMediaEngine> engine; - hr = factory->CreateInstance(0, d->configuration.Get(), &engine); - Q_ASSERT_SUCCEEDED(hr); - hr = engine.As(&d->engine); - Q_ASSERT_SUCCEEDED(hr); - - hr = d->engine->SetVolume(1.0); - Q_ASSERT_SUCCEEDED(hr); - - d->sources = Make<MediaEngineSources>(d); - hr = d->engine->SetSourceElements(d->sources.Get()); - Q_ASSERT_SUCCEEDED(hr); - - d->streamProvider = Make<MediaEngineByteStream>(d); -} - -QMediaPlayer::State QWinRTMediaPlayerControl::state() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->state; -} - -QMediaPlayer::MediaStatus QWinRTMediaPlayerControl::mediaStatus() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->mediaStatus; -} - -qint64 QWinRTMediaPlayerControl::duration() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->duration; -} - -qint64 QWinRTMediaPlayerControl::position() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->position; -} - -void QWinRTMediaPlayerControl::setPosition(qint64 position) -{ - Q_D(QWinRTMediaPlayerControl); - - if (d->position == position) - return; - - HRESULT hr; - hr = d->engine->SetCurrentTime(double(position)/1000); - RETURN_VOID_IF_FAILED("Failed to seek to new position"); - - d->position = position; - emit positionChanged(d->position); - - if (d->mediaStatus == QMediaPlayer::EndOfMedia) { - d->mediaStatus = QMediaPlayer::LoadedMedia; - emit mediaStatusChanged(d->mediaStatus); - } -} - -int QWinRTMediaPlayerControl::volume() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->volume; -} - -void QWinRTMediaPlayerControl::setVolume(int volume) -{ - Q_D(QWinRTMediaPlayerControl); - - if (d->volume == volume) - return; - - HRESULT hr; - hr = d->engine->SetVolume(double(volume)/100); - RETURN_VOID_IF_FAILED("Failed to set volume"); - - d->volume = volume; - emit volumeChanged(d->volume); -} - -bool QWinRTMediaPlayerControl::isMuted() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->muted; -} - -void QWinRTMediaPlayerControl::setMuted(bool muted) -{ - Q_D(QWinRTMediaPlayerControl); - - if (d->muted == muted) - return; - - HRESULT hr; - hr = d->engine->SetMuted(muted); - RETURN_VOID_IF_FAILED("Failed to mute volume"); - - d->muted = muted; - emit mutedChanged(d->muted); -} - -int QWinRTMediaPlayerControl::bufferStatus() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->bufferStatus; -} - -bool QWinRTMediaPlayerControl::isAudioAvailable() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->hasAudio; -} - -bool QWinRTMediaPlayerControl::isVideoAvailable() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->hasVideo; -} - -bool QWinRTMediaPlayerControl::isSeekable() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->seekable; -} - -QMediaTimeRange QWinRTMediaPlayerControl::availablePlaybackRanges() const -{ - Q_D(const QWinRTMediaPlayerControl); - return QMediaTimeRange(0, d->duration); -} - -qreal QWinRTMediaPlayerControl::playbackRate() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->playbackRate; -} - -void QWinRTMediaPlayerControl::setPlaybackRate(qreal rate) -{ - Q_D(QWinRTMediaPlayerControl); - - if (qFuzzyCompare(d->playbackRate, rate)) - return; - - HRESULT hr; - hr = d->engine->SetPlaybackRate(rate); - RETURN_VOID_IF_FAILED("Failed to set playback rate"); -} - -QMediaContent QWinRTMediaPlayerControl::media() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->media; -} - -const QIODevice *QWinRTMediaPlayerControl::mediaStream() const -{ - Q_D(const QWinRTMediaPlayerControl); - return d->stream.data(); -} - -void QWinRTMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *stream) -{ - Q_D(QWinRTMediaPlayerControl); - - if (d->media == media && d->stream.data() == stream) - return; - - d->media = media; - d->stream.reset(stream); - if (d->hasAudio != false) { - d->hasAudio = false; - emit audioAvailableChanged(d->hasAudio); - } - if (d->hasVideo != false) { - d->hasVideo = false; - emit videoAvailableChanged(d->hasVideo); - } - if (d->seekable != false) { - d->seekable = false; - emit seekableChanged(d->seekable); - } - if (d->bufferStatus != 0) { - d->bufferStatus = 0; - emit bufferStatusChanged(d->bufferStatus); - } - if (d->position != 0) { - d->position = 0; - emit positionChanged(d->position); - } - if (d->duration != 0) { - d->duration = 0; - emit durationChanged(d->duration); - } - QMediaPlayer::MediaStatus mediaStatus = media.isNull() ? QMediaPlayer::NoMedia - : QMediaPlayer::LoadingMedia; - if (d->mediaStatus != mediaStatus) { - d->mediaStatus = mediaStatus; - emit mediaStatusChanged(d->mediaStatus); - } - emit mediaChanged(media); - - QString urlString = media.request().url().toString(); - if (!d->stream) { - // If we can read the file via Qt, use the byte stream approach - if (media.request().url().isLocalFile()) { - urlString = media.request().url().toLocalFile(); - QScopedPointer<QFile> file(new QFile(urlString)); - if (file->open(QFile::ReadOnly)) { - file->setProperty(QT_WINRT_MEDIAPLAYER_STREAM_ID, true); - d->stream.reset(file.take()); - } - } - } - - HRESULT hr; - if (d->stream) { - hr = d->engine->SetSourceFromByteStream(d->streamProvider.Get(), - reinterpret_cast<BSTR>(urlString.data())); - if (FAILED(hr)) { - emit error(QMediaPlayer::ResourceError, qt_error_string(hr)); - return; - } - if (d->videoRenderer) - d->videoRenderer->ensureReady(); - return; - } - - // Let Windows handle all other URLs - hr = d->engine->SetSource(nullptr); // Resets the byte stream - Q_ASSERT_SUCCEEDED(hr); - hr = d->engine->Load(); - if (FAILED(hr)) - emit error(QMediaPlayer::ResourceError, qt_error_string(hr)); - - if (d->media.isNull() && d->stream.isNull()) - return; - - // Resume play/pause/stop - switch (d->state) { - case QMediaPlayer::StoppedState: - stop(); - break; - case QMediaPlayer::PlayingState: - play(); - break; - case QMediaPlayer::PausedState: - pause(); - break; - } -} - -void QWinRTMediaPlayerControl::play() -{ - Q_D(QWinRTMediaPlayerControl); - - if (d->state != QMediaPlayer::PlayingState) { - d->state = QMediaPlayer::PlayingState; - emit stateChanged(d->state); - } - - if (d->media.isNull() && d->stream.isNull()) - return; - - if (d->videoRenderer) - d->videoRenderer->ensureReady(); - - HRESULT hr = d->engine->Play(); - if (FAILED(hr)) { - emit error(QMediaPlayer::ResourceError, qt_error_string(hr)); - return; - } -} - -void QWinRTMediaPlayerControl::pause() -{ - Q_D(QWinRTMediaPlayerControl); - - if (d->state != QMediaPlayer::PausedState) { - d->state = QMediaPlayer::PausedState; - emit stateChanged(d->state); - } - - if (d->media.isNull() && d->stream.isNull()) - return; - - HRESULT hr; - hr = d->engine->Pause(); - if (FAILED(hr)) { - emit error(QMediaPlayer::ResourceError, qt_error_string(hr)); - return; - } -} - -void QWinRTMediaPlayerControl::stop() -{ - Q_D(QWinRTMediaPlayerControl); - - const QMediaPlayer::MediaStatus oldMediaStatus = d->mediaStatus; - const QMediaPlayer::State oldState = d->state; - - d->state = QMediaPlayer::StoppedState; - - if (d->mediaStatus == QMediaPlayer::BufferedMedia - || d->mediaStatus == QMediaPlayer::BufferingMedia) { - d->mediaStatus = QMediaPlayer::LoadedMedia; - } - - if (d->mediaStatus != oldMediaStatus) - emit mediaStatusChanged(d->mediaStatus); - - if (d->state != oldState) - emit stateChanged(d->state); - - if (d->media.isNull() && d->stream.isNull()) - return; - - setPosition(0); - - HRESULT hr; - hr = d->engine->Pause(); - if (FAILED(hr)) { - emit error(QMediaPlayer::ResourceError, qt_error_string(hr)); - return; - } -} - -QVideoRendererControl *QWinRTMediaPlayerControl::videoRendererControl() -{ - Q_D(QWinRTMediaPlayerControl); - - if (!d->videoRenderer) { - d->videoRenderer = new QWinRTPlayerRendererControl(d->engine.Get(), d->manager.Get(), - d->resetToken, this); - } - - return d->videoRenderer; -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtmediaplayercontrol.h b/src/plugins/winrt/qwinrtmediaplayercontrol.h deleted file mode 100644 index 0075cc954..000000000 --- a/src/plugins/winrt/qwinrtmediaplayercontrol.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTMEDIAPLAYERCONTROL_H -#define QWINRTMEDIAPLAYERCONTROL_H - -#include <QtMultimedia/QMediaPlayerControl> - -struct IMFMediaEngineClassFactory; - -QT_BEGIN_NAMESPACE - -class QVideoRendererControl; - -class QWinRTMediaPlayerControlPrivate; -class QWinRTMediaPlayerControl : public QMediaPlayerControl -{ - Q_OBJECT -public: - QWinRTMediaPlayerControl(IMFMediaEngineClassFactory *factory, QObject *parent = nullptr); - ~QWinRTMediaPlayerControl() override = default; - - QMediaPlayer::State state() const override; - QMediaPlayer::MediaStatus mediaStatus() const override; - - qint64 duration() const override; - - qint64 position() const override; - void setPosition(qint64 position) override; - - int volume() const override; - void setVolume(int volume) override; - - bool isMuted() const override; - void setMuted(bool muted) override; - - int bufferStatus() const override; - - bool isAudioAvailable() const override; - bool isVideoAvailable() const override; - - bool isSeekable() const override; - - QMediaTimeRange availablePlaybackRanges() const override; - - qreal playbackRate() const override; - void setPlaybackRate(qreal rate) override; - - QMediaContent media() const override; - const QIODevice *mediaStream() const override; - void setMedia(const QMediaContent &media, QIODevice *stream) override; - - void play() override; - void pause() override; - void stop() override; - - QVideoRendererControl *videoRendererControl(); - -private: - QScopedPointer<QWinRTMediaPlayerControlPrivate, QWinRTMediaPlayerControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTMediaPlayerControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTMEDIAPLAYERCONTROL_H diff --git a/src/plugins/winrt/qwinrtmediaplayerservice.cpp b/src/plugins/winrt/qwinrtmediaplayerservice.cpp deleted file mode 100644 index 208e7625b..000000000 --- a/src/plugins/winrt/qwinrtmediaplayerservice.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtmediaplayerservice.h" -#include "qwinrtmediaplayercontrol.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QPointer> -#include <QtMultimedia/QVideoRendererControl> - -#include <mfapi.h> -#include <mfmediaengine.h> -#include <wrl.h> - -using namespace Microsoft::WRL; - -QT_BEGIN_NAMESPACE - -class QWinRTMediaPlayerServicePrivate -{ -public: - QPointer<QWinRTMediaPlayerControl> player; - - ComPtr<IMFMediaEngineClassFactory> factory; -}; - -QWinRTMediaPlayerService::QWinRTMediaPlayerService(QObject *parent) - : QMediaService(parent), d_ptr(new QWinRTMediaPlayerServicePrivate) -{ - Q_D(QWinRTMediaPlayerService); - - d->player = nullptr; - - HRESULT hr = MFStartup(MF_VERSION); - Q_ASSERT(SUCCEEDED(hr)); - - MULTI_QI results = { &IID_IUnknown, nullptr, 0 }; - hr = CoCreateInstanceFromApp(CLSID_MFMediaEngineClassFactory, nullptr, - CLSCTX_INPROC_SERVER, nullptr, 1, &results); - Q_ASSERT(SUCCEEDED(hr)); - - hr = results.pItf->QueryInterface(d->factory.GetAddressOf()); - Q_ASSERT(SUCCEEDED(hr)); -} - -QWinRTMediaPlayerService::~QWinRTMediaPlayerService() -{ - MFShutdown(); -} - -QMediaControl *QWinRTMediaPlayerService::requestControl(const char *name) -{ - Q_D(QWinRTMediaPlayerService); - if (qstrcmp(name, QMediaPlayerControl_iid) == 0) { - if (!d->player) - d->player = new QWinRTMediaPlayerControl(d->factory.Get(), this); - return d->player; - } - if (qstrcmp(name, QVideoRendererControl_iid) == 0) { - if (!d->player) - return nullptr; - return d->player->videoRendererControl(); - } - - return nullptr; -} - -void QWinRTMediaPlayerService::releaseControl(QMediaControl *control) -{ - Q_D(QWinRTMediaPlayerService); - if (control == d->player) - d->player->deleteLater(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtmediaplayerservice.h b/src/plugins/winrt/qwinrtmediaplayerservice.h deleted file mode 100644 index 843fc3f77..000000000 --- a/src/plugins/winrt/qwinrtmediaplayerservice.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTMEDIAPLAYERSERVICE_H -#define QWINRTMEDIAPLAYERSERVICE_H - -#include <QtMultimedia/QMediaService> - -QT_BEGIN_NAMESPACE - -class QWinRTMediaPlayerServicePrivate; -class QWinRTMediaPlayerService : public QMediaService -{ - Q_OBJECT -public: - QWinRTMediaPlayerService(QObject *parent); - ~QWinRTMediaPlayerService(); - - QMediaControl *requestControl(const char *name); - void releaseControl(QMediaControl *control); - -private: - QScopedPointer<QWinRTMediaPlayerServicePrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTMediaPlayerService) -}; - -QT_END_NAMESPACE - -#endif // QWINRTMEDIAPLAYERSERVICE_H diff --git a/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp b/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp deleted file mode 100644 index 5952aa638..000000000 --- a/src/plugins/winrt/qwinrtplayerrenderercontrol.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtplayerrenderercontrol.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QGlobalStatic> -#include <QtMultimedia/QAbstractVideoSurface> -#include <QtMultimedia/QVideoSurfaceFormat> -#include <QtGui/QGuiApplication> -#include <QtGui/QOpenGLTexture> -#include <QtGui/QOpenGLContext> - -#define EGL_EGLEXT_PROTOTYPES -#include <EGL/egl.h> -#include <EGL/eglext.h> - -#include <d3d11.h> -#include <mfapi.h> -#include <mfmediaengine.h> -#include <wrl.h> -using namespace Microsoft::WRL; - -QT_BEGIN_NAMESPACE - -template <typename T> -class D3DDeviceLocker -{ -public: - D3DDeviceLocker(IMFDXGIDeviceManager *manager, HANDLE deviceHandle, T **device) - : m_manager(manager), m_deviceHandle(deviceHandle) - { - HRESULT hr = m_manager->LockDevice(m_deviceHandle, IID_PPV_ARGS(device), TRUE); - if (FAILED(hr)) - qErrnoWarning(hr, "Failed to lock the D3D device"); - } - - ~D3DDeviceLocker() - { - HRESULT hr = m_manager->UnlockDevice(m_deviceHandle, FALSE); - if (FAILED(hr)) - qErrnoWarning(hr, "Failed to unlock the D3D device"); - } - -private: - IMFDXGIDeviceManager *m_manager; - HANDLE m_deviceHandle; -}; - -class QWinRTPlayerRendererControlPrivate -{ -public: - ComPtr<IMFMediaEngineEx> engine; - ComPtr<IMFDXGIDeviceManager> manager; - quint32 resetToken; - HANDLE deviceHandle; -}; - -QWinRTPlayerRendererControl::QWinRTPlayerRendererControl(IMFMediaEngineEx *engine, IMFDXGIDeviceManager *manager, quint32 resetToken, QObject *parent) - : QWinRTAbstractVideoRendererControl(QSize(), parent), d_ptr(new QWinRTPlayerRendererControlPrivate) -{ - Q_D(QWinRTPlayerRendererControl); - - d->engine = engine; - d->manager = manager; - d->resetToken = resetToken; - d->deviceHandle = nullptr; -} - -QWinRTPlayerRendererControl::~QWinRTPlayerRendererControl() -{ - shutdown(); -} - -bool QWinRTPlayerRendererControl::ensureReady() -{ - Q_D(QWinRTPlayerRendererControl); - - HRESULT hr; - hr = d->manager->TestDevice(d->deviceHandle); - if (hr == MF_E_DXGI_NEW_VIDEO_DEVICE || FAILED(hr)) { - d->manager->CloseDeviceHandle(d->deviceHandle); - - hr = d->manager->ResetDevice(d3dDevice(), d->resetToken); - RETURN_FALSE_IF_FAILED("Failed to reset the DXGI manager device"); - - hr = d->manager->OpenDeviceHandle(&d->deviceHandle); - RETURN_FALSE_IF_FAILED("Failed to open device handle"); - } - - return SUCCEEDED(hr); -} - -bool QWinRTPlayerRendererControl::render(ID3D11Texture2D *texture) -{ - Q_D(QWinRTPlayerRendererControl); - - if (!ensureReady()) - return false; - - HRESULT hr; - LONGLONG ts; - hr = d->engine->OnVideoStreamTick(&ts); - RETURN_FALSE_IF_FAILED("Failed to obtain video stream tick"); - if (hr == S_FALSE) // Frame not available, nothing to do - return false; - - ComPtr<ID3D11Device> device; - D3DDeviceLocker<ID3D11Device> locker(d->manager.Get(), d->deviceHandle, device.GetAddressOf()); - - MFVideoNormalizedRect sourceRect = { 0, 0, 1, 1 }; - const QSize frameSize = size(); - RECT destRect = { 0, 0, frameSize.width(), frameSize.height() }; - MFARGB borderColor = { 255, 255, 255, 255 }; - hr = d->engine->TransferVideoFrame(texture, &sourceRect, &destRect, &borderColor); - RETURN_FALSE_IF_FAILED("Failed to transfer video frame to DXGI surface"); - return true; -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtplayerrenderercontrol.h b/src/plugins/winrt/qwinrtplayerrenderercontrol.h deleted file mode 100644 index 7653db46f..000000000 --- a/src/plugins/winrt/qwinrtplayerrenderercontrol.h +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTPLAYERRENDERERCONTROL_H -#define QWINRTPLAYERRENDERERCONTROL_H - -#include "qwinrtabstractvideorenderercontrol.h" -#include <QtMultimedia/QMediaPlayer> - -struct IMFMediaEngineEx; -struct IMFDXGIDeviceManager; - -QT_BEGIN_NAMESPACE - -class QWinRTPlayerRendererControlPrivate; -class QWinRTPlayerRendererControl : public QWinRTAbstractVideoRendererControl -{ - Q_OBJECT -public: - explicit QWinRTPlayerRendererControl(IMFMediaEngineEx *engine, IMFDXGIDeviceManager *manager, quint32 resetToken, QObject *parent); - ~QWinRTPlayerRendererControl() override; - - bool ensureReady(); - - bool render(ID3D11Texture2D *texture) override; - -private: - QScopedPointer<QWinRTPlayerRendererControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTPlayerRendererControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTPLAYERRENDERERCONTROL_H diff --git a/src/plugins/winrt/qwinrtserviceplugin.cpp b/src/plugins/winrt/qwinrtserviceplugin.cpp deleted file mode 100644 index 286789e4c..000000000 --- a/src/plugins/winrt/qwinrtserviceplugin.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtCore/QString> -#include <QtCore/QFile> - -#include "qwinrtserviceplugin.h" -#include "qwinrtmediaplayerservice.h" -#include "qwinrtcameraservice.h" -#include "qwinrtvideodeviceselectorcontrol.h" - -QT_BEGIN_NAMESPACE - -QMediaService *QWinRTServicePlugin::create(QString const &key) -{ - if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER)) - return new QWinRTMediaPlayerService(this); - - if (key == QLatin1String(Q_MEDIASERVICE_CAMERA)) - return new QWinRTCameraService(this); - - return nullptr; -} - -void QWinRTServicePlugin::release(QMediaService *service) -{ - delete service; -} - -QMediaServiceProviderHint::Features QWinRTServicePlugin::supportedFeatures( - const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_MEDIAPLAYER) - return QMediaServiceProviderHint::StreamPlayback | QMediaServiceProviderHint::VideoSurface; - - return QMediaServiceProviderHint::Features(); -} - -QCamera::Position QWinRTServicePlugin::cameraPosition(const QByteArray &device) const -{ - return QWinRTVideoDeviceSelectorControl::cameraPosition(device); -} - -int QWinRTServicePlugin::cameraOrientation(const QByteArray &device) const -{ - return QWinRTVideoDeviceSelectorControl::cameraOrientation(device); -} - -QList<QByteArray> QWinRTServicePlugin::devices(const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_CAMERA) - return QWinRTVideoDeviceSelectorControl::deviceNames(); - - return QList<QByteArray>(); -} - -QString QWinRTServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device) -{ - if (service == Q_MEDIASERVICE_CAMERA) - return QWinRTVideoDeviceSelectorControl::deviceDescription(device); - - return QString(); -} - -QByteArray QWinRTServicePlugin::defaultDevice(const QByteArray &service) const -{ - if (service == Q_MEDIASERVICE_CAMERA) - return QWinRTVideoDeviceSelectorControl::defaultDeviceName(); - - return QByteArray(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtserviceplugin.h b/src/plugins/winrt/qwinrtserviceplugin.h deleted file mode 100644 index b0a4e5973..000000000 --- a/src/plugins/winrt/qwinrtserviceplugin.h +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTSERVICEPLUGIN_H -#define QWINRTSERVICEPLUGIN_H - -#include <QtMultimedia/QMediaServiceProviderPlugin> - -QT_BEGIN_NAMESPACE - -class QWinRTServicePlugin : public QMediaServiceProviderPlugin - , public QMediaServiceFeaturesInterface - , public QMediaServiceCameraInfoInterface - , public QMediaServiceSupportedDevicesInterface - , public QMediaServiceDefaultDeviceInterface -{ - Q_OBJECT - Q_INTERFACES(QMediaServiceFeaturesInterface) - Q_INTERFACES(QMediaServiceCameraInfoInterface) - Q_INTERFACES(QMediaServiceSupportedDevicesInterface) - Q_INTERFACES(QMediaServiceDefaultDeviceInterface) - Q_PLUGIN_METADATA(IID "org.qt-project.qt.mediaserviceproviderfactory/5.0" FILE "winrt.json") -public: - QMediaService *create(QString const &key) override; - void release(QMediaService *service) override; - - QMediaServiceProviderHint::Features supportedFeatures(const QByteArray &service) const override; - - QCamera::Position cameraPosition(const QByteArray &device) const override; - int cameraOrientation(const QByteArray &device) const override; - - QList<QByteArray> devices(const QByteArray &service) const override; - QString deviceDescription(const QByteArray &service, const QByteArray &device) override; - - QByteArray defaultDevice(const QByteArray &service) const override; -}; - -QT_END_NAMESPACE - -#endif // QWINRTSERVICEPLUGIN_H diff --git a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp b/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp deleted file mode 100644 index 59aa91b03..000000000 --- a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qwinrtvideodeviceselectorcontrol.h" - -#include <QtCore/qfunctions_winrt.h> -#include <QtCore/QVector> -#include <QtCore/QCoreApplication> -#include <QtCore/QEventLoop> -#include <QtCore/QGlobalStatic> - -#include <wrl.h> -#include <windows.devices.enumeration.h> - -using namespace ABI::Windows::Devices::Enumeration; -using namespace ABI::Windows::Foundation; -using namespace ABI::Windows::Foundation::Collections; -using namespace Microsoft::WRL; -using namespace Microsoft::WRL::Wrappers; - -typedef ITypedEventHandler<DeviceWatcher *, DeviceInformation *> DeviceInformationHandler; -typedef ITypedEventHandler<DeviceWatcher *, DeviceInformationUpdate *> DeviceInformationUpdateHandler; -typedef ITypedEventHandler<DeviceWatcher *, IInspectable *> DeviceEnumerationCompletedHandler; - -QT_BEGIN_NAMESPACE - -static QString deviceName(IDeviceInformation *device) -{ - HRESULT hr; - HString id; - hr = device->get_Id(id.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - quint32 length; - const wchar_t *buffer = id.GetRawBuffer(&length); - return QString::fromWCharArray(buffer, int(length)); -} - -static QString deviceDescription(IDeviceInformation *device) -{ - HRESULT hr; - HString name; - hr = device->get_Name(name.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - quint32 length; - const wchar_t *buffer = name.GetRawBuffer(&length); - return QString::fromWCharArray(buffer, int(length)); -} - -struct QWinRTVideoDeviceSelectorControlGlobal -{ - QWinRTVideoDeviceSelectorControlGlobal() - : defaultDeviceIndex(-1) - { - HRESULT hr; - ComPtr<IDeviceInformationStatics> deviceWatcherFactory; - hr = RoGetActivationFactory(HString::MakeReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation).Get(), - IID_PPV_ARGS(&deviceWatcherFactory)); - Q_ASSERT_SUCCEEDED(hr); - hr = deviceWatcherFactory->CreateWatcherDeviceClass(DeviceClass_VideoCapture, &deviceWatcher); - Q_ASSERT_SUCCEEDED(hr); - - hr = deviceWatcher->add_Added( - Callback<DeviceInformationHandler>(this, &QWinRTVideoDeviceSelectorControlGlobal::onDeviceAdded).Get(), - &deviceAddedToken); - Q_ASSERT_SUCCEEDED(hr); - - hr = deviceWatcher->add_Removed( - Callback<DeviceInformationUpdateHandler>(this, &QWinRTVideoDeviceSelectorControlGlobal::onDeviceRemoved).Get(), - &deviceRemovedToken); - Q_ASSERT_SUCCEEDED(hr); - - hr = deviceWatcher->add_Updated( - Callback<DeviceInformationUpdateHandler>(this, &QWinRTVideoDeviceSelectorControlGlobal::onDeviceUpdated).Get(), - &deviceUpdatedToken); - Q_ASSERT_SUCCEEDED(hr); - - // Synchronously populate the devices on construction - ComPtr<IAsyncOperation<DeviceInformationCollection *>> op; - hr = deviceWatcherFactory->FindAllAsyncDeviceClass(DeviceClass_VideoCapture, &op); - Q_ASSERT_SUCCEEDED(hr); - ComPtr<IVectorView<DeviceInformation *>> deviceList; - hr = QWinRTFunctions::await(op, deviceList.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - quint32 deviceCount; - hr = deviceList->get_Size(&deviceCount); - Q_ASSERT_SUCCEEDED(hr); - for (quint32 i = 0; i < deviceCount; ++i) { - IDeviceInformation *device; - hr = deviceList->GetAt(i, &device); - Q_ASSERT_SUCCEEDED(hr); - onDeviceAdded(nullptr, device); - } - - // If there is no default device provided by the API, choose the first one - if (!devices.isEmpty() && defaultDeviceIndex < 0) - defaultDeviceIndex = 0; - } - - ~QWinRTVideoDeviceSelectorControlGlobal() - { - HRESULT hr; - hr = deviceWatcher->remove_Added(deviceAddedToken); - Q_ASSERT_SUCCEEDED(hr); - hr = deviceWatcher->remove_Removed(deviceRemovedToken); - Q_ASSERT_SUCCEEDED(hr); - hr = deviceWatcher->remove_Updated(deviceUpdatedToken); - Q_ASSERT_SUCCEEDED(hr); - } - -private: - HRESULT onDeviceAdded(IDeviceWatcher *, IDeviceInformation *device) - { - const QString name = deviceName(device); - if (deviceIndex.contains(name)) - return S_OK; - - devices.append(device); - const int index = devices.size() - 1; - deviceIndex.insert(name, index); - - HRESULT hr; - boolean isDefault; - hr = device->get_IsDefault(&isDefault); - Q_ASSERT_SUCCEEDED(hr); - if (isDefault) - defaultDeviceIndex = index; - - for (QWinRTVideoDeviceSelectorControl *watcher : qAsConst(watchers)) - emit watcher->devicesChanged(); - - return S_OK; - } - - HRESULT onDeviceRemoved(IDeviceWatcher *, IDeviceInformationUpdate *device) - { - HRESULT hr; - HString id; - hr = device->get_Id(id.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - - HString name; - hr = device->get_Id(name.GetAddressOf()); - Q_ASSERT_SUCCEEDED(hr); - quint32 nameLength; - const wchar_t *nameString = name.GetRawBuffer(&nameLength); - const int index = deviceIndex.take(QString::fromWCharArray(nameString, int(nameLength))); - if (index >= 0) - devices.remove(index); - - for (QWinRTVideoDeviceSelectorControl *watcher : qAsConst(watchers)) - emit watcher->devicesChanged(); - - return S_OK; - } - - HRESULT onDeviceUpdated(IDeviceWatcher *, IDeviceInformationUpdate *) - { - // A name or description may have changed, so emit devicesChanged - for (QWinRTVideoDeviceSelectorControl *watcher : qAsConst(watchers)) - emit watcher->devicesChanged(); - - return S_OK; - } - -public: - void addWatcher(QWinRTVideoDeviceSelectorControl *control) - { - watchers.append(control); - - HRESULT hr; - DeviceWatcherStatus status; - hr = deviceWatcher->get_Status(&status); - Q_ASSERT_SUCCEEDED(hr); - if (status != DeviceWatcherStatus_Started && - status != DeviceWatcherStatus_EnumerationCompleted) { - // We can't immediately Start() if we have just called Stop() - while (status == DeviceWatcherStatus_Stopping) { - QThread::yieldCurrentThread(); - hr = deviceWatcher->get_Status(&status); - Q_ASSERT_SUCCEEDED(hr); - } - hr = deviceWatcher->Start(); - Q_ASSERT_SUCCEEDED(hr); - } - } - - void removeWatcher(QWinRTVideoDeviceSelectorControl *control) - { - watchers.removeAll(control); - - if (!watchers.isEmpty()) - return; - - HRESULT hr; - DeviceWatcherStatus status; - hr = deviceWatcher->get_Status(&status); - Q_ASSERT_SUCCEEDED(hr); - if (status == DeviceWatcherStatus_Stopped || status == DeviceWatcherStatus_Stopping) - return; - - hr = deviceWatcher->Stop(); - Q_ASSERT_SUCCEEDED(hr); - } - - QVector<ComPtr<IDeviceInformation>> devices; - QHash<QString, int> deviceIndex; - int defaultDeviceIndex; - -private: - ComPtr<IDeviceWatcher> deviceWatcher; - QList<QWinRTVideoDeviceSelectorControl *> watchers; - EventRegistrationToken deviceAddedToken; - EventRegistrationToken deviceRemovedToken; - EventRegistrationToken deviceUpdatedToken; -}; -Q_GLOBAL_STATIC(QWinRTVideoDeviceSelectorControlGlobal, g) - -static ComPtr<IEnclosureLocation> enclosureLocation(const QString &deviceName) -{ - ComPtr<IEnclosureLocation> enclosureLocation; - int deviceIndex = g->deviceIndex.value(deviceName); - IDeviceInformation *deviceInfo = g->devices.value(deviceIndex).Get(); - if (!deviceInfo) - return enclosureLocation; - - HRESULT hr; - hr = deviceInfo->get_EnclosureLocation(&enclosureLocation); - if (FAILED(hr)) - qErrnoWarning(hr, "Failed to get camera enclosure location"); - - return enclosureLocation; -} - -class QWinRTVideoDeviceSelectorControlPrivate -{ -public: - int selectedDevice; -}; - -QWinRTVideoDeviceSelectorControl::QWinRTVideoDeviceSelectorControl(QObject *parent) - : QVideoDeviceSelectorControl(parent), d_ptr(new QWinRTVideoDeviceSelectorControlPrivate) -{ - Q_D(QWinRTVideoDeviceSelectorControl); - d->selectedDevice = -1; - g->addWatcher(this); -} - -QWinRTVideoDeviceSelectorControl::~QWinRTVideoDeviceSelectorControl() -{ - if (g.isDestroyed()) - return; - - g->removeWatcher(this); -} - -int QWinRTVideoDeviceSelectorControl::deviceCount() const -{ - return g->devices.size(); -} - -QString QWinRTVideoDeviceSelectorControl::deviceName(int index) const -{ - if (index < 0 || index >= g->devices.size()) - return QString(); - - return ::deviceName(g->devices.at(index).Get()); -} - -QString QWinRTVideoDeviceSelectorControl::deviceDescription(int index) const -{ - if (index < 0 || index >= g->devices.size()) - return QString(); - - return ::deviceDescription(g->devices.at(index).Get()); -} - -int QWinRTVideoDeviceSelectorControl::defaultDevice() const -{ - return g->defaultDeviceIndex; -} - -int QWinRTVideoDeviceSelectorControl::selectedDevice() const -{ - Q_D(const QWinRTVideoDeviceSelectorControl); - return d->selectedDevice; -} - -QCamera::Position QWinRTVideoDeviceSelectorControl::cameraPosition(const QString &deviceName) -{ - ComPtr<IEnclosureLocation> enclosure = enclosureLocation(deviceName); - if (!enclosure) - return QCamera::UnspecifiedPosition; - - HRESULT hr; - Panel panel; - hr = enclosure->get_Panel(&panel); - RETURN_IF_FAILED("Failed to get camera panel location", return QCamera::UnspecifiedPosition); - - switch (panel) { - case Panel_Front: - return QCamera::FrontFace; - case Panel_Back: - return QCamera::BackFace; - default: - break; - } - return QCamera::UnspecifiedPosition; -} - -int QWinRTVideoDeviceSelectorControl::cameraOrientation(const QString &deviceName) -{ - ComPtr<IEnclosureLocation> enclosure = enclosureLocation(deviceName); - if (!enclosure) - return 0; - - HRESULT hr; - ComPtr<IEnclosureLocation2> enclosure2; - hr = enclosure.As(&enclosure2); - RETURN_IF_FAILED("Failed to cast camera enclosure location", return 0); - quint32 rotation; - hr = enclosure2->get_RotationAngleInDegreesClockwise(&rotation); - RETURN_IF_FAILED("Failed to get camera rotation angle", return 0); - return int(rotation); -} - -QList<QByteArray> QWinRTVideoDeviceSelectorControl::deviceNames() -{ - QList<QByteArray> devices; - devices.reserve(g->deviceIndex.size()); - for (auto it = g->deviceIndex.keyBegin(), end = g->deviceIndex.keyEnd(); it != end; ++it) - devices.append((*it).toUtf8()); - - return devices; -} - -QByteArray QWinRTVideoDeviceSelectorControl::deviceDescription(const QByteArray &deviceName) -{ - int deviceIndex = g->deviceIndex.value(QString::fromUtf8(deviceName), -1); - if (deviceIndex < 0) - return QByteArray(); - - return ::deviceDescription(g->devices.value(deviceIndex).Get()).toUtf8(); -} - -QByteArray QWinRTVideoDeviceSelectorControl::defaultDeviceName() -{ - if (g->defaultDeviceIndex < 0) - return QByteArray(); - - return ::deviceName(g->devices.value(g->defaultDeviceIndex).Get()).toUtf8(); -} - -void QWinRTVideoDeviceSelectorControl::setSelectedDevice(int index) -{ - Q_D(QWinRTVideoDeviceSelectorControl); - - int selectedDevice = index; - if (index < 0 || index >= g->devices.size()) - selectedDevice = -1; - - if (d->selectedDevice != selectedDevice) { - d->selectedDevice = selectedDevice; - emit selectedDeviceChanged(d->selectedDevice); - emit selectedDeviceChanged(deviceName(d->selectedDevice)); - } -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.h b/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.h deleted file mode 100644 index a9ddaf9fd..000000000 --- a/src/plugins/winrt/qwinrtvideodeviceselectorcontrol.h +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QWINRTVIDEODEVICESELECTORCONTROL_H -#define QWINRTVIDEODEVICESELECTORCONTROL_H - -#include <QtMultimedia/QVideoDeviceSelectorControl> -#include <QtMultimedia/QCameraInfoControl> -#include <QtCore/qt_windows.h> - -struct IInspectable; -namespace ABI { - namespace Windows { - namespace Devices { - namespace Enumeration { - struct IDeviceInformation; - } - } - } -} - -QT_BEGIN_NAMESPACE - -class QWinRTVideoDeviceSelectorControlPrivate; -class QWinRTVideoDeviceSelectorControl : public QVideoDeviceSelectorControl -{ - Q_OBJECT -public: - explicit QWinRTVideoDeviceSelectorControl(QObject *parent = nullptr); - ~QWinRTVideoDeviceSelectorControl() override; - - int deviceCount() const override; - - QString deviceName(int index) const override; - QString deviceDescription(int index) const override; - - int defaultDevice() const override; - int selectedDevice() const override; - - static QCamera::Position cameraPosition(const QString &deviceName); - static int cameraOrientation(const QString &deviceName); - static QList<QByteArray> deviceNames(); - static QByteArray deviceDescription(const QByteArray &deviceName); - static QByteArray defaultDeviceName(); - -public slots: - void setSelectedDevice(int index) override; - -private: - QScopedPointer<QWinRTVideoDeviceSelectorControlPrivate> d_ptr; - Q_DECLARE_PRIVATE(QWinRTVideoDeviceSelectorControl) -}; - -QT_END_NAMESPACE - -#endif // QWINRTVIDEODEVICESELECTORCONTROL_H diff --git a/src/plugins/winrt/qwinrtvideoprobecontrol.cpp b/src/plugins/winrt/qwinrtvideoprobecontrol.cpp deleted file mode 100644 index c60fd8896..000000000 --- a/src/plugins/winrt/qwinrtvideoprobecontrol.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "qwinrtvideoprobecontrol.h" -#include "qwinrtcameravideorenderercontrol.h" - -QT_BEGIN_NAMESPACE - -QWinRTVideoProbeControl::QWinRTVideoProbeControl(QWinRTCameraVideoRendererControl *parent) - : QMediaVideoProbeControl(parent) -{ - QObject::connect(parent, &QWinRTCameraVideoRendererControl::videoFrameProbed, - this, &QMediaVideoProbeControl::videoFrameProbed, Qt::QueuedConnection); - parent->incrementProbe(); -} - -QWinRTVideoProbeControl::~QWinRTVideoProbeControl() -{ - if (QWinRTCameraVideoRendererControl *renderer = qobject_cast<QWinRTCameraVideoRendererControl *>(parent())) - renderer->decrementProbe(); -} - -QT_END_NAMESPACE diff --git a/src/plugins/winrt/qwinrtvideoprobecontrol.h b/src/plugins/winrt/qwinrtvideoprobecontrol.h deleted file mode 100644 index 2a79cb91d..000000000 --- a/src/plugins/winrt/qwinrtvideoprobecontrol.h +++ /dev/null @@ -1,57 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd and/or its subsidiary(-ies). -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef QWINRTVIDEOPROBECONTROL_H -#define QWINRTVIDEOPROBECONTROL_H - -#include <qmediavideoprobecontrol.h> - -QT_BEGIN_NAMESPACE - -class QWinRTCameraVideoRendererControl; -class QWinRTVideoProbeControl : public QMediaVideoProbeControl -{ - Q_OBJECT -public: - explicit QWinRTVideoProbeControl(QWinRTCameraVideoRendererControl *parent); - ~QWinRTVideoProbeControl() override; -}; - -QT_END_NAMESPACE - -#endif // QWINRTVIDEOPROBECONTROL_H diff --git a/src/plugins/winrt/winrt.json b/src/plugins/winrt/winrt.json deleted file mode 100644 index 9af79cc37..000000000 --- a/src/plugins/winrt/winrt.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "Keys": ["winrt"], - "Services": ["org.qt-project.qt.mediaplayer", "org.qt-project.qt.camera"] -} diff --git a/src/plugins/winrt/winrt.pro b/src/plugins/winrt/winrt.pro deleted file mode 100644 index 940064f46..000000000 --- a/src/plugins/winrt/winrt.pro +++ /dev/null @@ -1,47 +0,0 @@ -TARGET = winrtengine -QT += multimedia-private - -LIBS += -lmfplat -lmfuuid -loleaut32 -ld3d11 -lruntimeobject - -HEADERS += \ - qwinrtabstractvideorenderercontrol.h \ - qwinrtcameracontrol.h \ - qwinrtcameraflashcontrol.h \ - qwinrtcamerafocuscontrol.h \ - qwinrtcameraimagecapturecontrol.h \ - qwinrtcamerainfocontrol.h \ - qwinrtcameralockscontrol.h \ - qwinrtcameraservice.h \ - qwinrtcameravideorenderercontrol.h \ - qwinrtimageencodercontrol.h \ - qwinrtmediaplayercontrol.h \ - qwinrtmediaplayerservice.h \ - qwinrtplayerrenderercontrol.h \ - qwinrtserviceplugin.h \ - qwinrtvideodeviceselectorcontrol.h \ - qwinrtvideoprobecontrol.h - -SOURCES += \ - qwinrtabstractvideorenderercontrol.cpp \ - qwinrtcameracontrol.cpp \ - qwinrtcameraflashcontrol.cpp \ - qwinrtcamerafocuscontrol.cpp \ - qwinrtcameraimagecapturecontrol.cpp \ - qwinrtcamerainfocontrol.cpp \ - qwinrtcameralockscontrol.cpp \ - qwinrtcameraservice.cpp \ - qwinrtcameravideorenderercontrol.cpp \ - qwinrtimageencodercontrol.cpp \ - qwinrtmediaplayercontrol.cpp \ - qwinrtmediaplayerservice.cpp \ - qwinrtplayerrenderercontrol.cpp \ - qwinrtserviceplugin.cpp \ - qwinrtvideodeviceselectorcontrol.cpp \ - qwinrtvideoprobecontrol.cpp - -OTHER_FILES += \ - winrt.json - -PLUGIN_TYPE = mediaservice -PLUGIN_CLASS_NAME = WinRTServicePlugin -load(qt_plugin) |