diff options
author | Kai Köhne <kai.koehne@qt.io> | 2021-07-08 17:42:32 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-12 08:02:27 +0000 |
commit | 2a3181769f44ae1a825e8616474273c6981bf9de (patch) | |
tree | 9438015db20ff9fa878eeb877c616c1fba00c823 | |
parent | 7ad8c4ec613753d823172a7d457a4318e9050f91 (diff) |
Get rid of shared snippets directory
Avoiding code duplication is a noble goal, but the examples need
to be self-contained. E.g. Qt Creator sometimes does copy the example
(and just the example) to a tmp directory, where navigating out of
the source directory will fail.
Change-Id: I009c3f253fea9bf260f9cd58a58f2541a249d3af
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
(cherry picked from commit 8d9ffe8ae68d34b05e6219fd9f1fc5009638e4d6)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
30 files changed, 1134 insertions, 230 deletions
diff --git a/examples/multimedia/video/qmlvideo/CMakeLists.txt b/examples/multimedia/video/qmlvideo/CMakeLists.txt index d2e9e1f4d..dce82772a 100644 --- a/examples/multimedia/video/qmlvideo/CMakeLists.txt +++ b/examples/multimedia/video/qmlvideo/CMakeLists.txt @@ -22,10 +22,10 @@ find_package(Qt6 COMPONENTS Multimedia) find_package(Qt6 COMPONENTS Qml) qt_add_executable(qmlvideo - ../snippets/frequencymonitor/frequencymonitor.cpp ../snippets/frequencymonitor/frequencymonitor.h - ../snippets/frequencymonitor/frequencymonitordeclarative.cpp - ../snippets/performancemonitor/performancemonitor.cpp ../snippets/performancemonitor/performancemonitor.h - ../snippets/performancemonitor/performancemonitordeclarative.cpp ../snippets/performancemonitor/performancemonitordeclarative.h + frequencymonitor.cpp frequencymonitor.h + frequencymonitordeclarative.cpp + performancemonitor.cpp performancemonitor.h + performancemonitordeclarative.cpp performancemonitordeclarative.h main.cpp trace.h ) @@ -34,10 +34,6 @@ set_target_properties(qmlvideo PROPERTIES MACOSX_BUNDLE TRUE MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in ) -target_include_directories(qmlvideo PUBLIC - ../snippets/frequencymonitor - ../snippets/performancemonitor -) target_compile_definitions(qmlvideo PUBLIC FREQUENCYMONITOR_SUPPORT @@ -67,6 +63,8 @@ set(qmlvideo_resource_files "images/folder.png" "images/leaves.jpg" "images/up.png" + "qml/frequencymonitor/FrequencyItem.qml" + "qml/performancemonitor/PerformanceItem.qml" "qml/qmlvideo/Button.qml" "qml/qmlvideo/CameraBasic.qml" "qml/qmlvideo/CameraDrag.qml" @@ -119,30 +117,6 @@ qt6_add_resources(qmlvideo "qmlvideo" FILES ${qmlvideo_resource_files} ) -set(frequencymonitordeclarative_resource_files - "../snippets/frequencymonitor/qml/frequencymonitor/FrequencyItem.qml" -) - -qt6_add_resources(qmlvideo "frequencymonitordeclarative" - PREFIX - "/" - BASE - "../snippets/frequencymonitor" - FILES - ${frequencymonitordeclarative_resource_files} -) -set(performancemonitordeclarative_resource_files - "../snippets/performancemonitor/qml/performancemonitor/PerformanceItem.qml" -) - -qt6_add_resources(qmlvideo "performancemonitordeclarative" - PREFIX - "/" - BASE - "../snippets/performancemonitor" - FILES - ${performancemonitordeclarative_resource_files} -) install(TARGETS qmlvideo RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.cpp b/examples/multimedia/video/qmlvideo/frequencymonitor.cpp index 5f48cd35e..5f48cd35e 100644 --- a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.cpp +++ b/examples/multimedia/video/qmlvideo/frequencymonitor.cpp diff --git a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.h b/examples/multimedia/video/qmlvideo/frequencymonitor.h index efeb78589..efeb78589 100644 --- a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.h +++ b/examples/multimedia/video/qmlvideo/frequencymonitor.h diff --git a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.cpp b/examples/multimedia/video/qmlvideo/frequencymonitordeclarative.cpp index 0994ae213..0994ae213 100644 --- a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.cpp +++ b/examples/multimedia/video/qmlvideo/frequencymonitordeclarative.cpp diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitor.cpp b/examples/multimedia/video/qmlvideo/performancemonitor.cpp index 204eabc5a..204eabc5a 100644 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitor.cpp +++ b/examples/multimedia/video/qmlvideo/performancemonitor.cpp diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitor.h b/examples/multimedia/video/qmlvideo/performancemonitor.h index 97b76caf3..97b76caf3 100644 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitor.h +++ b/examples/multimedia/video/qmlvideo/performancemonitor.h diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.cpp b/examples/multimedia/video/qmlvideo/performancemonitordeclarative.cpp index 0783fdbd9..0783fdbd9 100644 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.cpp +++ b/examples/multimedia/video/qmlvideo/performancemonitordeclarative.cpp diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.h b/examples/multimedia/video/qmlvideo/performancemonitordeclarative.h index ca70657ce..ca70657ce 100644 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.h +++ b/examples/multimedia/video/qmlvideo/performancemonitordeclarative.h diff --git a/examples/multimedia/video/snippets/frequencymonitor/qml/frequencymonitor/FrequencyItem.qml b/examples/multimedia/video/qmlvideo/qml/frequencymonitor/FrequencyItem.qml index ec1bab299..ec1bab299 100644 --- a/examples/multimedia/video/snippets/frequencymonitor/qml/frequencymonitor/FrequencyItem.qml +++ b/examples/multimedia/video/qmlvideo/qml/frequencymonitor/FrequencyItem.qml diff --git a/examples/multimedia/video/snippets/performancemonitor/qml/performancemonitor/PerformanceItem.qml b/examples/multimedia/video/qmlvideo/qml/performancemonitor/PerformanceItem.qml index 5621450cb..5621450cb 100644 --- a/examples/multimedia/video/snippets/performancemonitor/qml/performancemonitor/PerformanceItem.qml +++ b/examples/multimedia/video/qmlvideo/qml/performancemonitor/PerformanceItem.qml diff --git a/examples/multimedia/video/qmlvideo/qmlvideo.pro b/examples/multimedia/video/qmlvideo/qmlvideo.pro index dbd3a42a1..4fa9d2b3b 100644 --- a/examples/multimedia/video/qmlvideo/qmlvideo.pro +++ b/examples/multimedia/video/qmlvideo/qmlvideo.pro @@ -7,15 +7,77 @@ android: qtHaveModule(androidextras) { DEFINES += REQUEST_PERMISSIONS_ON_ANDROID } -LOCAL_SOURCES = main.cpp -LOCAL_HEADERS = trace.h +DEFINES += \ + FREQUENCYMONITOR_SUPPORT \ + PERFORMANCEMONITOR_SUPPORT -SOURCES += $$LOCAL_SOURCES -HEADERS += $$LOCAL_HEADERS -RESOURCES += qmlvideo.qrc +SOURCES += \ + main.cpp \ + frequencymonitor.cpp \ + frequencymonitordeclarative.cpp \ + performancemonitor.cpp \ + performancemonitordeclarative.cpp -SNIPPETS_PATH = ../snippets -include($$SNIPPETS_PATH/performancemonitor/performancemonitordeclarative.pri) +HEADERS += \ + trace.h \ + frequencymonitor.h \ + performancemonitor.h \ + performancemonitordeclarative.h + +resources.files = \ + images/folder.png \ + images/leaves.jpg \ + images/up.png \ + qml/frequencymonitor/FrequencyItem.qml \ + qml/performancemonitor/PerformanceItem.qml \ + qml/qmlvideo/Button.qml \ + qml/qmlvideo/CameraBasic.qml \ + qml/qmlvideo/CameraDrag.qml \ + qml/qmlvideo/CameraDummy.qml \ + qml/qmlvideo/CameraFullScreen.qml \ + qml/qmlvideo/CameraFullScreenInverted.qml \ + qml/qmlvideo/CameraItem.qml \ + qml/qmlvideo/CameraMove.qml \ + qml/qmlvideo/CameraOverlay.qml \ + qml/qmlvideo/CameraResize.qml \ + qml/qmlvideo/CameraRotate.qml \ + qml/qmlvideo/CameraSpin.qml \ + qml/qmlvideo/Content.qml \ + qml/qmlvideo/ErrorDialog.qml \ + qml/qmlvideo/FileBrowser.qml \ + qml/qmlvideo/Scene.qml \ + qml/qmlvideo/SceneBasic.qml \ + qml/qmlvideo/SceneDrag.qml \ + qml/qmlvideo/SceneFullScreen.qml \ + qml/qmlvideo/SceneFullScreenInverted.qml \ + qml/qmlvideo/SceneMove.qml \ + qml/qmlvideo/SceneMulti.qml \ + qml/qmlvideo/SceneOverlay.qml \ + qml/qmlvideo/SceneResize.qml \ + qml/qmlvideo/SceneRotate.qml \ + qml/qmlvideo/SceneSelectionPanel.qml \ + qml/qmlvideo/SceneSpin.qml \ + qml/qmlvideo/SeekControl.qml \ + qml/qmlvideo/VideoBasic.qml \ + qml/qmlvideo/VideoDrag.qml \ + qml/qmlvideo/VideoDummy.qml \ + qml/qmlvideo/VideoFillMode.qml \ + qml/qmlvideo/VideoFullScreen.qml \ + qml/qmlvideo/VideoFullScreenInverted.qml \ + qml/qmlvideo/VideoItem.qml \ + qml/qmlvideo/VideoMetadata.qml \ + qml/qmlvideo/VideoMove.qml \ + qml/qmlvideo/VideoOverlay.qml \ + qml/qmlvideo/VideoPlaybackRate.qml \ + qml/qmlvideo/VideoResize.qml \ + qml/qmlvideo/VideoRotate.qml \ + qml/qmlvideo/VideoSeek.qml \ + qml/qmlvideo/VideoSpin.qml \ + qml/qmlvideo/main.qml + +resources.prefix = / + +RESOURCES += resources target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/video/qmlvideo INSTALLS += target diff --git a/examples/multimedia/video/qmlvideo/qmlvideo.qrc b/examples/multimedia/video/qmlvideo/qmlvideo.qrc deleted file mode 100644 index 6418215d0..000000000 --- a/examples/multimedia/video/qmlvideo/qmlvideo.qrc +++ /dev/null @@ -1,51 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file alias="leaves.jpg">images/leaves.jpg</file> - <file alias="folder.png">images/folder.png</file> - <file alias="up.png">images/up.png</file> - <file>qml/qmlvideo/Button.qml</file> - <file>qml/qmlvideo/CameraBasic.qml</file> - <file>qml/qmlvideo/CameraDrag.qml</file> - <file>qml/qmlvideo/CameraDummy.qml</file> - <file>qml/qmlvideo/CameraFullScreen.qml</file> - <file>qml/qmlvideo/CameraFullScreenInverted.qml</file> - <file>qml/qmlvideo/CameraItem.qml</file> - <file>qml/qmlvideo/CameraMove.qml</file> - <file>qml/qmlvideo/CameraOverlay.qml</file> - <file>qml/qmlvideo/CameraResize.qml</file> - <file>qml/qmlvideo/CameraRotate.qml</file> - <file>qml/qmlvideo/CameraSpin.qml</file> - <file>qml/qmlvideo/Content.qml</file> - <file>qml/qmlvideo/ErrorDialog.qml</file> - <file>qml/qmlvideo/FileBrowser.qml</file> - <file>qml/qmlvideo/main.qml</file> - <file>qml/qmlvideo/Scene.qml</file> - <file>qml/qmlvideo/SceneBasic.qml</file> - <file>qml/qmlvideo/SceneDrag.qml</file> - <file>qml/qmlvideo/SceneFullScreen.qml</file> - <file>qml/qmlvideo/SceneFullScreenInverted.qml</file> - <file>qml/qmlvideo/SceneMove.qml</file> - <file>qml/qmlvideo/SceneMulti.qml</file> - <file>qml/qmlvideo/SceneOverlay.qml</file> - <file>qml/qmlvideo/SceneResize.qml</file> - <file>qml/qmlvideo/SceneRotate.qml</file> - <file>qml/qmlvideo/SceneSelectionPanel.qml</file> - <file>qml/qmlvideo/SceneSpin.qml</file> - <file>qml/qmlvideo/SeekControl.qml</file> - <file>qml/qmlvideo/VideoBasic.qml</file> - <file>qml/qmlvideo/VideoDrag.qml</file> - <file>qml/qmlvideo/VideoDummy.qml</file> - <file>qml/qmlvideo/VideoFillMode.qml</file> - <file>qml/qmlvideo/VideoFullScreen.qml</file> - <file>qml/qmlvideo/VideoFullScreenInverted.qml</file> - <file>qml/qmlvideo/VideoItem.qml</file> - <file>qml/qmlvideo/VideoMetadata.qml</file> - <file>qml/qmlvideo/VideoMove.qml</file> - <file>qml/qmlvideo/VideoOverlay.qml</file> - <file>qml/qmlvideo/VideoPlaybackRate.qml</file> - <file>qml/qmlvideo/VideoResize.qml</file> - <file>qml/qmlvideo/VideoRotate.qml</file> - <file>qml/qmlvideo/VideoSeek.qml</file> - <file>qml/qmlvideo/VideoSpin.qml</file> - </qresource> -</RCC> diff --git a/examples/multimedia/video/qmlvideofx/CMakeLists.txt b/examples/multimedia/video/qmlvideofx/CMakeLists.txt index c833d82f5..853aa2ca7 100644 --- a/examples/multimedia/video/qmlvideofx/CMakeLists.txt +++ b/examples/multimedia/video/qmlvideofx/CMakeLists.txt @@ -22,22 +22,17 @@ find_package(Qt6 COMPONENTS Multimedia) find_package(Qt6 COMPONENTS Qml) qt_add_executable(qmlvideofx - ../snippets/frequencymonitor/frequencymonitor.cpp ../snippets/frequencymonitor/frequencymonitor.h - ../snippets/frequencymonitor/frequencymonitordeclarative.cpp - ../snippets/performancemonitor/performancemonitor.cpp ../snippets/performancemonitor/performancemonitor.h - ../snippets/performancemonitor/performancemonitordeclarative.cpp ../snippets/performancemonitor/performancemonitordeclarative.h - filereader.cpp filereader.h + frequencymonitor.cpp + frequencymonitordeclarative.cpp + performancemonitor.cpp + performancemonitordeclarative.cpp + filereader.cpp main.cpp - trace.h ) set_target_properties(qmlvideofx PROPERTIES WIN32_EXECUTABLE TRUE MACOSX_BUNDLE TRUE ) -target_include_directories(qmlvideofx PUBLIC - ../snippets/frequencymonitor - ../snippets/performancemonitor -) target_compile_definitions(qmlvideofx PUBLIC FREQUENCYMONITOR_SUPPORT @@ -64,6 +59,8 @@ set(qmlvideofx_resource_files "images/icon_Folder.png" "images/icon_Menu.png" "images/qt-logo.png" + "qml/frequencymonitor/FrequencyItem.qml" + "qml/performancemonitor/PerformanceItem.qml" "qml/qmlvideofx/Button.qml" "qml/qmlvideofx/Content.qml" "qml/qmlvideofx/ContentCamera.qml" @@ -130,30 +127,6 @@ qt6_add_resources(qmlvideofx "qmlvideofx" FILES ${qmlvideofx_resource_files} ) -set(frequencymonitordeclarative_resource_files - "../snippets/frequencymonitor/qml/frequencymonitor/FrequencyItem.qml" -) - -qt6_add_resources(qmlvideofx "frequencymonitordeclarative" - PREFIX - "/" - BASE - "../snippets/frequencymonitor" - FILES - ${frequencymonitordeclarative_resource_files} -) -set(performancemonitordeclarative_resource_files - "../snippets/performancemonitor/qml/performancemonitor/PerformanceItem.qml" -) - -qt6_add_resources(qmlvideofx "performancemonitordeclarative" - PREFIX - "/" - BASE - "../snippets/performancemonitor" - FILES - ${performancemonitordeclarative_resource_files} -) install(TARGETS qmlvideofx RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/multimedia/video/qmlvideofx/frequencymonitor.cpp b/examples/multimedia/video/qmlvideofx/frequencymonitor.cpp new file mode 100644 index 000000000..5f48cd35e --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/frequencymonitor.cpp @@ -0,0 +1,254 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "frequencymonitor.h" +#include <QDebug> +#include <QElapsedTimer> +#include <QString> +#include <QTime> +#include <QTimer> + +//#define VERBOSE_TRACE + +inline QDebug qtTrace() { return qDebug() << "[frequencymonitor]"; } +#ifdef VERBOSE_TRACE +inline QDebug qtVerboseTrace() { return qtTrace(); } +#else +inline QNoDebug qtVerboseTrace() { return QNoDebug(); } +#endif + +static const int DefaultSamplingInterval = 100; +static const int DefaultTraceInterval = 0; + +class FrequencyMonitorPrivate : public QObject +{ + Q_OBJECT + +public: + FrequencyMonitorPrivate(FrequencyMonitor *parent); + void calculateInstantaneousFrequency(); + +private slots: + void calculateAverageFrequency(); + void stalled(); + +public: + FrequencyMonitor *const q_ptr; + QString m_label; + bool m_active; + qreal m_instantaneousFrequency; + QElapsedTimer m_instantaneousElapsed; + QTimer *m_averageTimer; + QElapsedTimer m_averageElapsed; + int m_count; + qreal m_averageFrequency; + QTimer *m_traceTimer; + QTimer *m_stalledTimer; +}; + +FrequencyMonitorPrivate::FrequencyMonitorPrivate(FrequencyMonitor *parent) +: QObject(parent) +, q_ptr(parent) +, m_active(false) +, m_instantaneousFrequency(0) +, m_averageTimer(new QTimer(this)) +, m_count(0) +, m_averageFrequency(0) +, m_traceTimer(new QTimer(this)) +, m_stalledTimer(new QTimer(this)) +{ + m_instantaneousElapsed.start(); + connect(m_averageTimer, &QTimer::timeout, + this, &FrequencyMonitorPrivate::calculateAverageFrequency); + if (DefaultSamplingInterval) + m_averageTimer->start(DefaultSamplingInterval); + m_averageElapsed.start(); + connect(m_traceTimer, &QTimer::timeout, + q_ptr, &FrequencyMonitor::trace); + if (DefaultTraceInterval) + m_traceTimer->start(DefaultTraceInterval); + m_stalledTimer->setSingleShot(true); + connect(m_stalledTimer, &QTimer::timeout, + this, &FrequencyMonitorPrivate::stalled); +} + +void FrequencyMonitorPrivate::calculateInstantaneousFrequency() +{ + const qint64 ms = m_instantaneousElapsed.restart(); + m_instantaneousFrequency = ms ? qreal(1000) / ms : 0; + m_stalledTimer->start(3 * ms); + if (m_instantaneousFrequency) + q_ptr->setActive(true); + emit q_ptr->instantaneousFrequencyChanged(m_instantaneousFrequency); + emit q_ptr->frequencyChanged(); +} + +void FrequencyMonitorPrivate::calculateAverageFrequency() +{ + const qint64 ms = m_averageElapsed.restart(); + m_averageFrequency = qreal(m_count * 1000) / ms; + emit q_ptr->averageFrequencyChanged(m_averageFrequency); + emit q_ptr->frequencyChanged(); + m_count = 0; +} + +void FrequencyMonitorPrivate::stalled() +{ + if (m_instantaneousFrequency) { + m_instantaneousFrequency = 0; + emit q_ptr->instantaneousFrequencyChanged(m_instantaneousFrequency); + emit q_ptr->frequencyChanged(); + } +} + +FrequencyMonitor::FrequencyMonitor(QObject *parent) +: QObject(parent) +{ + d_ptr = new FrequencyMonitorPrivate(this); +} + +FrequencyMonitor::~FrequencyMonitor() = default; + +QString FrequencyMonitor::label() const +{ + return d_func()->m_label; +} + +bool FrequencyMonitor::active() const +{ + return d_func()->m_active; +} + +int FrequencyMonitor::samplingInterval() const +{ + return d_ptr->m_averageTimer->isActive() ? d_ptr->m_averageTimer->interval() : 0; +} + +int FrequencyMonitor::traceInterval() const +{ + return d_ptr->m_traceTimer->isActive() ? d_ptr->m_traceTimer->interval() : 0; +} + +qreal FrequencyMonitor::instantaneousFrequency() const +{ + return d_func()->m_instantaneousFrequency; +} + +qreal FrequencyMonitor::averageFrequency() const +{ + return d_func()->m_averageFrequency; +} + +void FrequencyMonitor::notify() +{ + Q_D(FrequencyMonitor); + ++(d->m_count); + d->calculateInstantaneousFrequency(); +} + +void FrequencyMonitor::trace() +{ + Q_D(FrequencyMonitor); + const QString value = QString::fromLatin1("instant %1 average %2") + .arg(d->m_instantaneousFrequency, 0, 'f', 2) + .arg(d->m_averageFrequency, 0, 'f', 2); + if (d->m_label.isEmpty()) + qtTrace() << "FrequencyMonitor::trace" << value; + else + qtTrace() << "FrequencyMonitor::trace" << "label" << d->m_label << value; +} + +void FrequencyMonitor::setLabel(const QString &value) +{ + Q_D(FrequencyMonitor); + if (d->m_label != value) { + d->m_label = value; + emit labelChanged(d->m_label); + } +} + +void FrequencyMonitor::setActive(bool value) +{ + Q_D(FrequencyMonitor); + if (d->m_active != value) { + d->m_active = value; + emit activeChanged(d->m_active); + } +} + +void FrequencyMonitor::setSamplingInterval(int value) +{ + Q_D(FrequencyMonitor); + if (samplingInterval() != value) { + if (value) { + d->m_averageTimer->setInterval(value); + d->m_averageTimer->start(); + } else { + d->m_averageTimer->stop(); + } + emit samplingIntervalChanged(value); + } +} + +void FrequencyMonitor::setTraceInterval(int value) +{ + Q_D(FrequencyMonitor); + if (traceInterval() != value) { + if (value) { + d->m_traceTimer->setInterval(value); + d->m_traceTimer->start(); + } else { + d->m_traceTimer->stop(); + } + emit traceIntervalChanged(value); + } +} + +#include "frequencymonitor.moc" diff --git a/examples/multimedia/video/qmlvideofx/frequencymonitor.h b/examples/multimedia/video/qmlvideofx/frequencymonitor.h new file mode 100644 index 000000000..efeb78589 --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/frequencymonitor.h @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FREQUENCYMONITOR_H +#define FREQUENCYMONITOR_H + +#include <QObject> +#include <QTimer> + +class FrequencyMonitorPrivate; + +/** + * Class for measuring frequency of events + * + * Occurrence of the event is notified by the client via the notify() slot. + * On a regular interval, both an instantaneous and a rolling average + * event frequency are calculated. + */ +class FrequencyMonitor : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(FrequencyMonitor) + Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) + Q_PROPERTY(bool active READ active WRITE setActive NOTIFY activeChanged) + Q_PROPERTY(int samplingInterval READ samplingInterval WRITE setSamplingInterval NOTIFY samplingIntervalChanged) + Q_PROPERTY(int traceInterval READ traceInterval WRITE setTraceInterval NOTIFY traceIntervalChanged) + Q_PROPERTY(qreal instantaneousFrequency READ instantaneousFrequency NOTIFY instantaneousFrequencyChanged) + Q_PROPERTY(qreal averageFrequency READ averageFrequency NOTIFY averageFrequencyChanged) + +public: + FrequencyMonitor(QObject *parent = 0); + ~FrequencyMonitor(); + + static void qmlRegisterType(); + + QString label() const; + bool active() const; + int samplingInterval() const; + int traceInterval() const; + qreal instantaneousFrequency() const; + qreal averageFrequency() const; + +signals: + void labelChanged(const QString &value); + void activeChanged(bool); + void samplingIntervalChanged(int value); + void traceIntervalChanged(int value); + void frequencyChanged(); + void instantaneousFrequencyChanged(qreal value); + void averageFrequencyChanged(qreal value); + +public slots: + Q_INVOKABLE void notify(); + Q_INVOKABLE void trace(); + void setActive(bool value); + void setLabel(const QString &value); + void setSamplingInterval(int value); + void setTraceInterval(int value); + +private: + FrequencyMonitorPrivate *d_ptr; +}; + +#endif // FREQUENCYMONITOR_H diff --git a/examples/multimedia/video/qmlvideofx/frequencymonitordeclarative.cpp b/examples/multimedia/video/qmlvideofx/frequencymonitordeclarative.cpp new file mode 100644 index 000000000..0994ae213 --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/frequencymonitordeclarative.cpp @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "frequencymonitor.h" +#include <QtQml/qqml.h> + +void FrequencyMonitor::qmlRegisterType() +{ + ::qmlRegisterType<FrequencyMonitor>("FrequencyMonitor", 1, 0, "FrequencyMonitor"); +} diff --git a/examples/multimedia/video/qmlvideofx/performancemonitor.cpp b/examples/multimedia/video/qmlvideofx/performancemonitor.cpp new file mode 100644 index 000000000..204eabc5a --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/performancemonitor.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "performancemonitor.h" + +namespace PerformanceMonitor { + +bool State::parseArgument(const QByteArray &arg) +{ + bool result = false; + if (arg == "-log-perf") { + logging = true; + valid = true; + result = true; + } else if (arg == "-no-log-perf") { + logging = false; + valid = true; + result = true; + } else if (arg == "-show-perf") { + visible = true; + valid = true; + result = true; + } else if (arg == "-hide-perf") { + visible = false; + valid = true; + result = true; + } + return result; +} + +} // namespace PerformanceMonitor diff --git a/examples/multimedia/video/qmlvideofx/performancemonitor.h b/examples/multimedia/video/qmlvideofx/performancemonitor.h new file mode 100644 index 000000000..97b76caf3 --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/performancemonitor.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PERFORMANCEMONITOR_H +#define PERFORMANCEMONITOR_H + +#include <QByteArray> + +namespace PerformanceMonitor { + +struct State +{ + State() : valid(true), logging(false), visible(true) { } + State(bool l, bool v) : valid(true), logging(l), visible(v) { } + bool operator==(const State &other) const + { return logging == other.logging && visible == other.visible; } + bool operator!=(const State &other) const + { return logging != other.logging || visible != other.visible; } + + bool parseArgument(const QByteArray &arg); + + bool valid; + bool logging; + bool visible; +}; + +} // namespace PerformanceMonitor + +#endif // PERFORMANCEMONITOR_H + diff --git a/examples/multimedia/video/qmlvideofx/performancemonitordeclarative.cpp b/examples/multimedia/video/qmlvideofx/performancemonitordeclarative.cpp new file mode 100644 index 000000000..0783fdbd9 --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/performancemonitordeclarative.cpp @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "frequencymonitor.h" +#include "performancemonitor.h" + +namespace PerformanceMonitor { + + void qmlRegisterTypes() + { + FrequencyMonitor::qmlRegisterType(); + } +} diff --git a/examples/multimedia/video/qmlvideofx/performancemonitordeclarative.h b/examples/multimedia/video/qmlvideofx/performancemonitordeclarative.h new file mode 100644 index 000000000..ca70657ce --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/performancemonitordeclarative.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PERFORMANCEMONITORDECLARATIVE_H +#define PERFORMANCEMONITORDECLARATIVE_H + +#include "performancemonitor.h" + +namespace PerformanceMonitor { + void qmlRegisterTypes(); +} + +#endif // PERFORMANCEMONITORDECLARATIVE_H diff --git a/examples/multimedia/video/qmlvideofx/qml/frequencymonitor/FrequencyItem.qml b/examples/multimedia/video/qmlvideofx/qml/frequencymonitor/FrequencyItem.qml new file mode 100644 index 000000000..ec1bab299 --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/qml/frequencymonitor/FrequencyItem.qml @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick +import FrequencyMonitor 1.0 + +Rectangle { + id: root + property bool logging: true + property bool displayed: true + property bool enabled: logging || displayed + property alias active: monitor.active + property int samplingInterval: 500 + property color textColor: "yellow" + property int textSize: 20 + property alias label: monitor.label + + border.width: 1 + border.color: "yellow" + width: 5.5 * root.textSize + height: 3.0 * root.textSize + color: "black" + opacity: 0.5 + radius: 10 + visible: displayed && active + + // This should ensure that the monitor is on top of all other content + z: 999 + + function notify() { + monitor.notify() + } + + FrequencyMonitor { + id: monitor + samplingInterval: root.enabled ? root.samplingInterval : 0 + onAverageFrequencyChanged: { + if (root.logging) trace() + averageFrequencyText.text = monitor.averageFrequency.toFixed(2) + } + } + + Text { + id: labelText + anchors { + left: parent.left + top: parent.top + margins: 10 + } + color: root.textColor + font.pixelSize: 0.6 * root.textSize + text: root.label + width: root.width - 2*anchors.margins + elide: Text.ElideRight + } + + Text { + id: averageFrequencyText + anchors { + right: parent.right + bottom: parent.bottom + margins: 10 + } + color: root.textColor + font.pixelSize: root.textSize + } +} diff --git a/examples/multimedia/video/qmlvideofx/qml/performancemonitor/PerformanceItem.qml b/examples/multimedia/video/qmlvideofx/qml/performancemonitor/PerformanceItem.qml new file mode 100644 index 000000000..5621450cb --- /dev/null +++ b/examples/multimedia/video/qmlvideofx/qml/performancemonitor/PerformanceItem.qml @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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 +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick + +Rectangle { + id: root + property bool logging: true + property bool displayed: true + property bool videoActive + property int margins: 5 + property bool enabled: true + + color: "transparent" + + // This should ensure that the monitor is on top of all other content + z: 999 + + Column { + id: column + anchors { + fill: root + margins: 10 + } + spacing: 10 + } + + QtObject { + id: d + property Item qmlFrameRateItem: null + property Item videoFrameRateItem: null + } + + Connections { + id: videoFrameRateActiveConnections + ignoreUnknownSignals: true + function onActiveChanged() { root.videoActive = videoFrameRateActiveConnections.target.active } + } + + states: [ + State { + name: "hidden" + PropertyChanges { + target: root + opacity: 0 + } + } + ] + + transitions: [ + Transition { + from: "*" + to: "*" + NumberAnimation { + properties: "opacity" + easing.type: Easing.OutQuart + duration: 500 + } + } + ] + + state: enabled ? "baseState" : "hidden" + + function createQmlFrameRateItem() { + var component = Qt.createComponent("../frequencymonitor/FrequencyItem.qml") + if (component.status == Component.Ready) + d.qmlFrameRateItem = component.createObject(column, { label: "QML frame rate", + displayed: root.displayed, + logging: root.logging + }) + } + + function createVideoFrameRateItem() { + var component = Qt.createComponent("../frequencymonitor/FrequencyItem.qml") + if (component.status == Component.Ready) + d.videoFrameRateItem = component.createObject(column, { label: "Video frame rate", + displayed: root.displayed, + logging: root.logging + }) + videoFrameRateActiveConnections.target = d.videoFrameRateItem + } + + + function init() { + createQmlFrameRateItem() + createVideoFrameRateItem() + } + + function videoFramePainted() { + if (d.videoFrameRateItem) + d.videoFrameRateItem.notify() + } + + function qmlFramePainted() { + if (d.qmlFrameRateItem) + d.qmlFrameRateItem.notify() + } + + onVideoActiveChanged: { + if (d.videoFrameRateItem) + d.videoFrameRateItem.active = root.videoActive + } +} diff --git a/examples/multimedia/video/qmlvideofx/qmlvideofx.pro b/examples/multimedia/video/qmlvideofx/qmlvideofx.pro index 07047aec8..fd43fb5b5 100644 --- a/examples/multimedia/video/qmlvideofx/qmlvideofx.pro +++ b/examples/multimedia/video/qmlvideofx/qmlvideofx.pro @@ -7,12 +7,99 @@ android: qtHaveModule(androidextras) { DEFINES += REQUEST_PERMISSIONS_ON_ANDROID } -SOURCES += filereader.cpp main.cpp -HEADERS += filereader.h trace.h +DEFINES += \ + FREQUENCYMONITOR_SUPPORT \ + PERFORMANCEMONITOR_SUPPORT -RESOURCES += qmlvideofx.qrc +SOURCES += \ + main.cpp \ + filereader.cpp \ + frequencymonitor.cpp \ + frequencymonitordeclarative.cpp \ + performancemonitor.cpp \ + performancemonitordeclarative.cpp -include($$PWD/../snippets/performancemonitor/performancemonitordeclarative.pri) +HEADERS += \ + filereader.h \ + frequencymonitor.h \ + performancemonitor.h \ + performancemonitordeclarative.h \ + trace.h + +resources.files = \ + images/Dropdown_arrows.png \ + images/Slider_bar.png \ + images/Slider_handle.png \ + images/Triangle_Top.png \ + images/Triangle_bottom.png \ + images/icon_BackArrow.png \ + images/icon_Folder.png \ + images/icon_Menu.png \ + images/qt-logo.png \ + qml/frequencymonitor/FrequencyItem.qml \ + qml/performancemonitor/PerformanceItem.qml \ + qml/qmlvideofx/Button.qml \ + qml/qmlvideofx/Content.qml \ + qml/qmlvideofx/ContentCamera.qml \ + qml/qmlvideofx/ContentImage.qml \ + qml/qmlvideofx/ContentVideo.qml \ + qml/qmlvideofx/Curtain.qml \ + qml/qmlvideofx/Divider.qml \ + qml/qmlvideofx/Effect.qml \ + qml/qmlvideofx/EffectBillboard.qml \ + qml/qmlvideofx/EffectBlackAndWhite.qml \ + qml/qmlvideofx/EffectEmboss.qml \ + qml/qmlvideofx/EffectGaussianBlur.qml \ + qml/qmlvideofx/EffectGlow.qml \ + qml/qmlvideofx/EffectIsolate.qml \ + qml/qmlvideofx/EffectMagnify.qml \ + qml/qmlvideofx/EffectPageCurl.qml \ + qml/qmlvideofx/EffectPassThrough.qml \ + qml/qmlvideofx/EffectPixelate.qml \ + qml/qmlvideofx/EffectPosterize.qml \ + qml/qmlvideofx/EffectRipple.qml \ + qml/qmlvideofx/EffectSelectionList.qml \ + qml/qmlvideofx/EffectSepia.qml \ + qml/qmlvideofx/EffectSharpen.qml \ + qml/qmlvideofx/EffectShockwave.qml \ + qml/qmlvideofx/EffectSobelEdgeDetection1.qml \ + qml/qmlvideofx/EffectTiltShift.qml \ + qml/qmlvideofx/EffectToon.qml \ + qml/qmlvideofx/EffectVignette.qml \ + qml/qmlvideofx/EffectWarhol.qml \ + qml/qmlvideofx/EffectWobble.qml \ + qml/qmlvideofx/FileBrowser.qml \ + qml/qmlvideofx/FileOpen.qml \ + qml/qmlvideofx/HintedMouseArea.qml \ + qml/qmlvideofx/Main.qml \ + qml/qmlvideofx/ParameterPanel.qml \ + qml/qmlvideofx/Slider.qml \ + shaders/billboard.fsh \ + shaders/blackandwhite.fsh \ + shaders/emboss.fsh \ + shaders/gaussianblur_h.fsh \ + shaders/gaussianblur_v.fsh \ + shaders/glow.fsh \ + shaders/isolate.fsh \ + shaders/magnify.fsh \ + shaders/pagecurl.fsh \ + shaders/pixelate.fsh \ + shaders/posterize.fsh \ + shaders/ripple.fsh \ + shaders/selectionpanel.fsh \ + shaders/sepia.fsh \ + shaders/sharpen.fsh \ + shaders/shockwave.fsh \ + shaders/sobeledgedetection1.fsh \ + shaders/tiltshift.fsh \ + shaders/toon.fsh \ + shaders/vignette.fsh \ + shaders/warhol.fsh \ + shaders/wobble.fsh + +resources.prefix = / + +RESOURCES += resources target.path = $$[QT_INSTALL_EXAMPLES]/multimedia/video/qmlvideofx INSTALLS += target diff --git a/examples/multimedia/video/qmlvideofx/qmlvideofx.qrc b/examples/multimedia/video/qmlvideofx/qmlvideofx.qrc deleted file mode 100644 index f3ad27704..000000000 --- a/examples/multimedia/video/qmlvideofx/qmlvideofx.qrc +++ /dev/null @@ -1,71 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>images/qt-logo.png</file> - <file>qml/qmlvideofx/Button.qml</file> - <file>qml/qmlvideofx/Content.qml</file> - <file>qml/qmlvideofx/ContentCamera.qml</file> - <file>qml/qmlvideofx/ContentImage.qml</file> - <file>qml/qmlvideofx/ContentVideo.qml</file> - <file>qml/qmlvideofx/Divider.qml</file> - <file>qml/qmlvideofx/Effect.qml</file> - <file>qml/qmlvideofx/EffectBillboard.qml</file> - <file>qml/qmlvideofx/EffectBlackAndWhite.qml</file> - <file>qml/qmlvideofx/EffectEmboss.qml</file> - <file>qml/qmlvideofx/EffectGaussianBlur.qml</file> - <file>qml/qmlvideofx/EffectGlow.qml</file> - <file>qml/qmlvideofx/EffectIsolate.qml</file> - <file>qml/qmlvideofx/EffectMagnify.qml</file> - <file>qml/qmlvideofx/EffectPageCurl.qml</file> - <file>qml/qmlvideofx/EffectPassThrough.qml</file> - <file>qml/qmlvideofx/EffectPixelate.qml</file> - <file>qml/qmlvideofx/EffectPosterize.qml</file> - <file>qml/qmlvideofx/EffectRipple.qml</file> - <file>qml/qmlvideofx/EffectSepia.qml</file> - <file>qml/qmlvideofx/EffectSharpen.qml</file> - <file>qml/qmlvideofx/EffectShockwave.qml</file> - <file>qml/qmlvideofx/EffectSobelEdgeDetection1.qml</file> - <file>qml/qmlvideofx/EffectTiltShift.qml</file> - <file>qml/qmlvideofx/EffectToon.qml</file> - <file>qml/qmlvideofx/EffectVignette.qml</file> - <file>qml/qmlvideofx/EffectWarhol.qml</file> - <file>qml/qmlvideofx/EffectWobble.qml</file> - <file>qml/qmlvideofx/FileBrowser.qml</file> - <file>qml/qmlvideofx/FileOpen.qml</file> - <file>qml/qmlvideofx/HintedMouseArea.qml</file> - <file>qml/qmlvideofx/ParameterPanel.qml</file> - <file>qml/qmlvideofx/Slider.qml</file> - <file>shaders/billboard.fsh</file> - <file>shaders/blackandwhite.fsh</file> - <file>shaders/emboss.fsh</file> - <file>shaders/gaussianblur_h.fsh</file> - <file>shaders/gaussianblur_v.fsh</file> - <file>shaders/glow.fsh</file> - <file>shaders/isolate.fsh</file> - <file>shaders/magnify.fsh</file> - <file>shaders/pagecurl.fsh</file> - <file>shaders/pixelate.fsh</file> - <file>shaders/posterize.fsh</file> - <file>shaders/ripple.fsh</file> - <file>shaders/selectionpanel.fsh</file> - <file>shaders/sepia.fsh</file> - <file>shaders/sharpen.fsh</file> - <file>shaders/shockwave.fsh</file> - <file>shaders/sobeledgedetection1.fsh</file> - <file>shaders/tiltshift.fsh</file> - <file>shaders/toon.fsh</file> - <file>shaders/vignette.fsh</file> - <file>shaders/warhol.fsh</file> - <file>shaders/wobble.fsh</file> - <file>images/Slider_handle.png</file> - <file>images/Slider_bar.png</file> - <file>qml/qmlvideofx/Curtain.qml</file> - <file>images/Triangle_bottom.png</file> - <file>images/Triangle_Top.png</file> - <file>images/Dropdown_arrows.png</file> - <file>images/icon_Folder.png</file> - <file>images/icon_BackArrow.png</file> - <file>qml/qmlvideofx/Main.qml</file> - <file>images/icon_Menu.png</file> - <file>qml/qmlvideofx/EffectSelectionList.qml</file> - </qresource> -</RCC> diff --git a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.pri b/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.pri deleted file mode 100644 index 3ac8a08c4..000000000 --- a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitor.pri +++ /dev/null @@ -1,5 +0,0 @@ -HEADERS += $$PWD/frequencymonitor.h -SOURCES += $$PWD/frequencymonitor.cpp -INCLUDEPATH += $$PWD -DEFINES += FREQUENCYMONITOR_SUPPORT - diff --git a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.pri b/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.pri deleted file mode 100644 index 071b7286a..000000000 --- a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.pri +++ /dev/null @@ -1,5 +0,0 @@ -include($$PWD/frequencymonitor.pri) -QT += qml - -SOURCES += $$PWD/frequencymonitordeclarative.cpp -RESOURCES += $$PWD/frequencymonitordeclarative.qrc diff --git a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.qrc b/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.qrc deleted file mode 100644 index 48e60cf1e..000000000 --- a/examples/multimedia/video/snippets/frequencymonitor/frequencymonitordeclarative.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/frequencymonitor/FrequencyItem.qml</file> - </qresource> -</RCC> diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitor.pri b/examples/multimedia/video/snippets/performancemonitor/performancemonitor.pri deleted file mode 100644 index 2df3cfb13..000000000 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitor.pri +++ /dev/null @@ -1,5 +0,0 @@ -INCLUDEPATH += $$PWD -HEADERS += $$PWD/performancemonitor.h -SOURCES += $$PWD/performancemonitor.cpp -DEFINES += PERFORMANCEMONITOR_SUPPORT - diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.pri b/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.pri deleted file mode 100644 index 9a18e35e5..000000000 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.pri +++ /dev/null @@ -1,6 +0,0 @@ -include($$PWD/../frequencymonitor/frequencymonitordeclarative.pri) -include($$PWD/performancemonitor.pri) - -HEADERS += $$PWD/performancemonitordeclarative.h -SOURCES += $$PWD/performancemonitordeclarative.cpp -RESOURCES += $$PWD/performancemonitordeclarative.qrc diff --git a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.qrc b/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.qrc deleted file mode 100644 index 9ec54a3e4..000000000 --- a/examples/multimedia/video/snippets/performancemonitor/performancemonitordeclarative.qrc +++ /dev/null @@ -1,5 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>qml/performancemonitor/PerformanceItem.qml</file> - </qresource> -</RCC> |