From 5b42ce74199671f88ee82c971ebff70f87c018db Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Thu, 26 Oct 2017 11:42:11 +0200 Subject: Don't discard the surface format when creating a video node All relevant properties from the surface are now copied Task-number: QTBUG-53268 Change-Id: I7f18f0e6a623c8c7c5be68e912b298e0b4b130b7 Reviewed-by: Christian Stromme --- src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp index 412694cc3..f1b7662b5 100644 --- a/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp +++ b/src/qtmultimediaquicktools/qdeclarativevideooutput_render.cpp @@ -335,7 +335,14 @@ QSGNode *QDeclarativeVideoRendererBackend::updatePaintNode(QSGNode *oldNode, for (QSGVideoNodeFactoryInterface* factory : qAsConst(m_videoNodeFactories)) { // Get a node that supports our frame. The surface is irrelevant, our // QSGVideoItemSurface supports (logically) anything. - videoNode = factory->createNode(QVideoSurfaceFormat(m_frame.size(), m_frame.pixelFormat(), m_frame.handleType())); + QVideoSurfaceFormat nodeFormat(m_frame.size(), m_frame.pixelFormat(), m_frame.handleType()); + const QVideoSurfaceFormat surfaceFormat = m_surface->surfaceFormat(); + nodeFormat.setYCbCrColorSpace(surfaceFormat.yCbCrColorSpace()); + nodeFormat.setPixelAspectRatio(surfaceFormat.pixelAspectRatio()); + nodeFormat.setScanLineDirection(surfaceFormat.scanLineDirection()); + nodeFormat.setViewport(surfaceFormat.viewport()); + nodeFormat.setFrameRate(surfaceFormat.frameRate()); + videoNode = factory->createNode(nodeFormat); if (videoNode) { qCDebug(qLcVideo) << "updatePaintNode: Video node created. Handle type:" << m_frame.handleType() << " Supported formats for the handle by this node:" -- cgit v1.2.1 From c3c6b7d0987b90e4a987ee84b2f31adf06568a0d Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Thu, 28 Sep 2017 13:37:13 +0200 Subject: Gstreamer: Fix memory leak in QGstreamerAudioDecoderSession The memory in the GstMapInfo should be unmapped with gst_buffer_unmap() after usage. Task-number: QTBUG-62789 Change-Id: Iee080e597abc80aa28fd068e6f582a97987677e0 Reviewed-by: Christian Stromme --- src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp index 779978e70..d6b8ad759 100644 --- a/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp +++ b/src/plugins/gstreamer/audiodecoder/qgstreameraudiodecodersession.cpp @@ -478,6 +478,7 @@ QAudioBuffer QGstreamerAudioDecoderSession::read() } } #if GST_CHECK_VERSION(1,0,0) + gst_buffer_unmap(buffer, &mapInfo); gst_sample_unref(sample); #else gst_buffer_unref(buffer); -- cgit v1.2.1 From b42659eb8baa384e329e6af6afea89bb4005fb46 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Fri, 27 Oct 2017 14:20:51 +0200 Subject: Gstreamer: Fix memory leak in CameraBinSession Created GstElement objects m_cameraSrc and m_videoSrc should be unrefed. Task-number: QTBUG-53204 Change-Id: Ibbfd37d928fe87ea899549da7c12fa2386e214cc Reviewed-by: Christian Stromme --- src/plugins/gstreamer/camerabin/camerabinsession.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/gstreamer/camerabin/camerabinsession.cpp b/src/plugins/gstreamer/camerabin/camerabinsession.cpp index ab0bea24a..4941c6ef6 100644 --- a/src/plugins/gstreamer/camerabin/camerabinsession.cpp +++ b/src/plugins/gstreamer/camerabin/camerabinsession.cpp @@ -212,6 +212,12 @@ CameraBinSession::~CameraBinSession() if (m_sourceFactory) gst_object_unref(GST_OBJECT(m_sourceFactory)); + + if (m_cameraSrc) + gst_object_unref(GST_OBJECT(m_cameraSrc)); + + if (m_videoSrc) + gst_object_unref(GST_OBJECT(m_videoSrc)); } #if QT_CONFIG(gstreamer_photography) @@ -538,11 +544,12 @@ GstElement *CameraBinSession::buildCameraSource() } } - if (m_cameraSrc != camSrc) + if (m_cameraSrc != camSrc) { g_object_set(G_OBJECT(m_camerabin), CAMERA_SOURCE_PROPERTY, m_cameraSrc, NULL); - - if (camSrc) - gst_object_unref(GST_OBJECT(camSrc)); + // Unref only if camSrc is not m_cameraSrc to prevent double unrefing. + if (camSrc) + gst_object_unref(GST_OBJECT(camSrc)); + } return m_cameraSrc; } -- cgit v1.2.1 From e3cf8e4da46302039d5c5eabb7baa2ffcfe3374d Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Tue, 7 Nov 2017 16:59:24 +0100 Subject: Convert ARGB32 to premultiplied Do not render into ARGB32 images using QPainter. Using premultiplied version is significantly faster. Task-number: QTBUG-52114 Change-Id: Ia057788d5af0fb303a69310a7c7a197ec7f76516 Reviewed-by: Allan Sandfeld Jensen Reviewed-by: Christian Stromme --- src/multimediawidgets/qpaintervideosurface.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/multimediawidgets/qpaintervideosurface.cpp b/src/multimediawidgets/qpaintervideosurface.cpp index 214e5ec7e..6e93e150d 100644 --- a/src/multimediawidgets/qpaintervideosurface.cpp +++ b/src/multimediawidgets/qpaintervideosurface.cpp @@ -191,6 +191,10 @@ QAbstractVideoSurface::Error QVideoSurfaceGenericPainter::paint( m_imageSize.height(), m_frame.bytesPerLine(), m_imageFormat); + // Do not render into ARGB32 images using QPainter. + // Using QImage::Format_ARGB32_Premultiplied is significantly faster. + if (m_imageFormat == QImage::Format_ARGB32) + image = image.convertToFormat(QImage::Format_ARGB32_Premultiplied); const QTransform oldTransform = painter->transform(); QTransform transform = oldTransform; -- cgit v1.2.1 From b0c352054e64b0fc64e547bf54dad1bdeaee283a Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Thu, 9 Nov 2017 15:26:49 +0100 Subject: Fix crash when an app is sent to background while capturing an image Since the native notify* methods for QtCameraListener.java are executed on different thread, there is a potential for a race condition when the applicationStateChanged is received before the notify* signals, which leads to the camera being release before the slots are executed. Task-number: QTBUG-52366 Change-Id: Ifc82f3a75a7e88e4e76fac3edbf16bb9f138fde7 Reviewed-by: Christian Stromme --- src/plugins/android/src/mediacapture/qandroidcamerasession.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp index a7f0254ee..15aa027e4 100644 --- a/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp +++ b/src/plugins/android/src/mediacapture/qandroidcamerasession.cpp @@ -697,7 +697,7 @@ void QAndroidCameraSession::onCameraTakePictureFailed() void QAndroidCameraSession::onCameraPictureExposed() { - if (m_captureCanceled) + if (m_captureCanceled || !m_camera) return; emit imageExposed(m_currentImageCaptureId); @@ -706,7 +706,7 @@ void QAndroidCameraSession::onCameraPictureExposed() void QAndroidCameraSession::onLastPreviewFrameFetched(const QVideoFrame &frame) { - if (m_captureCanceled) + if (m_captureCanceled || !m_camera) return; QtConcurrent::run(this, &QAndroidCameraSession::processPreviewImage, @@ -730,6 +730,9 @@ void QAndroidCameraSession::processPreviewImage(int id, const QVideoFrame &frame void QAndroidCameraSession::onNewPreviewFrame(const QVideoFrame &frame) { + if (!m_camera) + return; + m_videoProbesMutex.lock(); for (QAndroidMediaVideoProbeControl *probe : qAsConst(m_videoProbes)) @@ -756,7 +759,8 @@ void QAndroidCameraSession::onCameraPictureCaptured(const QByteArray &data) m_captureCanceled = false; // Preview needs to be restarted after taking a picture - m_camera->startPreview(); + if (m_camera) + m_camera->startPreview(); } void QAndroidCameraSession::onCameraPreviewStarted() -- cgit v1.2.1 From 4a214b199337a02e8cab77aa0cdca0c2805fb6a2 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Wed, 11 Oct 2017 17:05:53 +0200 Subject: Fix deadlock when a new url is set in loading state Setting a new url while QMediaPlayer is in loading state can result in a deadlock between the GUI and worker thread. Because main thread is waiting when worker realeses m_graph but worker cleared all pending tasks and is waiting for new tasks from main thread. Task-number: QTBUG-53534 Change-Id: I296ecdf866c5d85efc7121d3e7936334d6b700fd Reviewed-by: Timur Pocheptsov Reviewed-by: Maurice Kalinowski Reviewed-by: Christian Stromme --- src/plugins/directshow/player/directshowplayerservice.cpp | 3 --- .../qmediaplayerbackend/tst_qmediaplayerbackend.cpp | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp index 9cbb62969..8ee5d67a1 100644 --- a/src/plugins/directshow/player/directshowplayerservice.cpp +++ b/src/plugins/directshow/player/directshowplayerservice.cpp @@ -402,7 +402,6 @@ void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) } else if (!m_resources.isEmpty()) { m_pendingTasks |= SetUrlSource; } else { - m_pendingTasks = 0; m_graphStatus = InvalidMedia; switch (hr) { @@ -1688,8 +1687,6 @@ void DirectShowPlayerService::run() QMutexLocker locker(&m_mutex); for (;;) { - ::ResetEvent(m_taskHandle); - while (m_pendingTasks == 0) { DWORD result = 0; diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp index 5a703f2e1..9fe0a39ec 100644 --- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp +++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp @@ -59,6 +59,7 @@ private slots: void construction(); void loadMedia(); void unloadMedia(); + void loadMediaInLoadingState(); void playPauseStop(); void processEOS(); void deleteLaterAtEOS(); @@ -325,6 +326,16 @@ void tst_QMediaPlayerBackend::unloadMedia() QVERIFY(!positionSpy.isEmpty()); } +void tst_QMediaPlayerBackend::loadMediaInLoadingState() +{ + const QUrl url("http://unavailable.media/"); + QMediaPlayer player; + player.setMedia(QMediaContent(url)); + player.play(); + // Sets new media while old has not been finished. + player.setMedia(QMediaContent(url)); + QTRY_COMPARE(player.mediaStatus(), QMediaPlayer::InvalidMedia); +} void tst_QMediaPlayerBackend::playPauseStop() { -- cgit v1.2.1 From cf4cc30da4566c1b8a86ee5688383f90eaf0e967 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Tue, 10 Oct 2017 09:03:48 +0200 Subject: wasapi: Initialize COM before use The COM library was not initialized on the calling thread before the COM library calls were made. Task-number: QTBUG-62598 Change-Id: Id6f4fc093a1ef72b6e0a3cd3a22c05cec7eaafa8 Reviewed-by: Oliver Wolff --- src/plugins/wasapi/qwasapiutils.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/plugins/wasapi/qwasapiutils.cpp b/src/plugins/wasapi/qwasapiutils.cpp index 727c94c23..0d03982de 100644 --- a/src/plugins/wasapi/qwasapiutils.cpp +++ b/src/plugins/wasapi/qwasapiutils.cpp @@ -90,6 +90,26 @@ struct DeviceMapping { Q_GLOBAL_STATIC(DeviceMapping, gMapping) } +struct CoInitializer +{ + CoInitializer() + { + const bool isGuiThread = QCoreApplication::instance() && + QThread::currentThread() == QCoreApplication::instance()->thread(); + CoInitializeEx(NULL, isGuiThread ? COINIT_APARTMENTTHREADED : COINIT_MULTITHREADED); + } + + ~CoInitializer() + { + CoUninitialize(); + } +}; + +static void CoInitIfNeeded() +{ + static CoInitializer initializer; +} + AudioInterface::AudioInterface() { qCDebug(lcMmAudioInterface) << __FUNCTION__; @@ -182,6 +202,7 @@ QByteArray QWasapiUtils::defaultDevice(QAudio::Mode mode) { qCDebug(lcMmUtils) << __FUNCTION__ << mode; + CoInitIfNeeded(); QList &deviceNames = mode == QAudio::AudioInput ? gMapping->inputDeviceNames : gMapping->outputDeviceNames; QList &deviceIds = mode == QAudio::AudioInput ? gMapping->inputDeviceIds : gMapping->outputDeviceIds; if (deviceNames.isEmpty() || deviceIds.isEmpty()) // Initialize @@ -214,6 +235,7 @@ QList QWasapiUtils::availableDevices(QAudio::Mode mode) { qCDebug(lcMmUtils) << __FUNCTION__ << mode; + CoInitIfNeeded(); ComPtr statics; HRESULT hr; @@ -290,6 +312,7 @@ Microsoft::WRL::ComPtr QWasapiUtils::createOrGetInterface(const { qCDebug(lcMmUtils) << __FUNCTION__ << dev << mode; Q_ASSERT((mode == QAudio::AudioInput ? gMapping->inputDeviceNames.indexOf(dev) : gMapping->outputDeviceNames.indexOf(dev)) != -1); + CoInitIfNeeded(); Microsoft::WRL::ComPtr result; HRESULT hr = QEventDispatcherWinRT::runOnXamlThread([dev, mode, &result]() { -- cgit v1.2.1 From 5af70385a0b1a04e10d088f655ee33338ec014c5 Mon Sep 17 00:00:00 2001 From: Liang Qi Date: Thu, 16 Nov 2017 08:53:02 +0100 Subject: Fix outdated BSD license header Change-Id: I5b952a41be87f250810419674f52486acad34e07 Reviewed-by: Kai Koehne --- examples/multimedia/declarative-radio/Button.qml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/multimedia/declarative-radio/Button.qml b/examples/multimedia/declarative-radio/Button.qml index c01c9d388..c579795e7 100644 --- a/examples/multimedia/declarative-radio/Button.qml +++ b/examples/multimedia/declarative-radio/Button.qml @@ -1,12 +1,22 @@ /**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ +** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ -** You may use this file under the terms of the BSD license as follows: +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are -- cgit v1.2.1