diff options
-rw-r--r-- | examples/CMakeLists.txt | 5 | ||||
-rw-r--r-- | examples/qmlplayer/CMakeLists.txt | 2 | ||||
-rw-r--r-- | examples/qmlplayer2/CMakeLists.txt | 30 | ||||
-rw-r--r-- | examples/qmlplayer2/main.cpp | 57 | ||||
-rw-r--r-- | examples/qmlplayer2/player.cpp | 94 | ||||
-rw-r--r-- | examples/qmlplayer2/player.h | 47 | ||||
-rw-r--r-- | examples/qmlplayer2/qmlplayer2.pro | 28 | ||||
-rw-r--r-- | examples/qmlplayer2/qmlplayer2.qml | 79 | ||||
-rw-r--r-- | examples/qmlplayer2/qmlplayer2.qrc | 6 |
9 files changed, 347 insertions, 1 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e983adc..548d84f 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -34,3 +34,8 @@ if (Qt4or5_Quick1_FOUND) add_subdirectory(qmlplayer) example_distcheck(qmlplayer) endif() + +if (Qt4or5_Quick2_FOUND) + add_subdirectory(qmlplayer2) + example_distcheck(qmlplayer2) +endif() diff --git a/examples/qmlplayer/CMakeLists.txt b/examples/qmlplayer/CMakeLists.txt index 7b765b1..7599754 100644 --- a/examples/qmlplayer/CMakeLists.txt +++ b/examples/qmlplayer/CMakeLists.txt @@ -18,7 +18,7 @@ else() # allow the example to run from the build tree without installing QtGStreamer add_definitions( -DQTVIDEOSINK_PATH="${QtGStreamer_BINARY_DIR}/elements/gstqtvideosink" - -DUNINSTALLED_IMPORTS_DIR="${QtGStreamer_BINARY_DIR}/src/qml" + -DUNINSTALLED_IMPORTS_DIR="${QtGStreamer_BINARY_DIR}/src/qml/quick1" ) endif() diff --git a/examples/qmlplayer2/CMakeLists.txt b/examples/qmlplayer2/CMakeLists.txt new file mode 100644 index 0000000..cbd58ee --- /dev/null +++ b/examples/qmlplayer2/CMakeLists.txt @@ -0,0 +1,30 @@ +project(qtgst-example-qmlplayer2) + +if (NOT BUILDING_QTGSTREAMER) + set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/modules) + find_package(Qt4or5 COMPONENTS Core Gui Quick2 Qml REQUIRED) + find_package(Qt5GStreamer REQUIRED) + + set(CMAKE_AUTOMOC ON) + set(CMAKE_INCLUDE_CURRENT_DIR ON) +else() + # allow the example to run from the build tree without installing QtGStreamer + add_definitions( + -DQTVIDEOSINK_PATH="${QtGStreamer_BINARY_DIR}/elements/gstqtvideosink" + -DUNINSTALLED_IMPORTS_DIR="${QtGStreamer_BINARY_DIR}/src/qml/quick2" + ) +endif() + +include_directories(${QTGSTREAMER_INCLUDES}) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QTGSTREAMER_FLAGS}") +add_definitions(${QTGSTREAMER_DEFINITIONS}) + +set(qmlplayer2_SOURCES main.cpp player.cpp) +qt4or5_add_resources(qmlplayer2_rcc_SOURCES qmlplayer2.qrc) + +add_executable(qmlplayer2 + ${qmlplayer2_SOURCES} + ${qmlplayer2_rcc_SOURCES} +) +target_link_libraries(qmlplayer2 ${QTGSTREAMER_QUICK_LIBRARIES}) +qt4or5_use_modules(qmlplayer2 Core Gui Quick2 Qml) diff --git a/examples/qmlplayer2/main.cpp b/examples/qmlplayer2/main.cpp new file mode 100644 index 0000000..022cb62 --- /dev/null +++ b/examples/qmlplayer2/main.cpp @@ -0,0 +1,57 @@ +/* + Copyright (C) 2012-2013 Collabora Ltd. <info@collabora.com> + @author George Kiagiadakis <george.kiagiadakis@collabora.com> + Copyright (C) 2013 basysKom GmbH <info@basyskom.com> + @author Benjamin Federau <benjamin.federau@basyskom.com> + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "player.h" +#include <QtGui/QGuiApplication> +#include <QtQuick/QQuickView> +#include <QtQml/QQmlContext> +#include <QtQml/QQmlEngine> +#include <QGst/Init> +#include <QGst/Quick/VideoSurface> + +int main(int argc, char **argv) +{ +#if defined(QTVIDEOSINK_PATH) + //this allows the example to run from the QtGStreamer build tree without installing QtGStreamer + qputenv("GST_PLUGIN_PATH", QTVIDEOSINK_PATH); +#endif + + QGuiApplication app(argc, argv); + QGst::init(&argc, &argv); + + QQuickView view; + + QGst::Quick::VideoSurface *surface = new QGst::Quick::VideoSurface; + view.rootContext()->setContextProperty(QLatin1String("videoSurface1"), surface); + + Player *player = new Player(&view); + player->setVideoSink(surface->videoSink()); + player->setUri(QLatin1Literal("http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi")); + view.rootContext()->setContextProperty(QLatin1String("player"), player); + +#if defined(UNINSTALLED_IMPORTS_DIR) + //this allows the example to run from the QtGStreamer build tree without installing QtGStreamer + view.engine()->addImportPath(QLatin1String(UNINSTALLED_IMPORTS_DIR)); +#endif + + view.setSource(QUrl(QLatin1String("qrc:///qmlplayer2.qml"))); + view.show(); + + return app.exec(); +} diff --git a/examples/qmlplayer2/player.cpp b/examples/qmlplayer2/player.cpp new file mode 100644 index 0000000..58863b4 --- /dev/null +++ b/examples/qmlplayer2/player.cpp @@ -0,0 +1,94 @@ +/* + Copyright (C) 2010 Marco Ballesio <gibrovacco@gmail.com> + Copyright (C) 2011-2013 Collabora Ltd. + @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk> + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "player.h" +#include <QUrl> +#include <QDebug> +#include <QGlib/Connect> +#include <QGlib/Error> +#include <QGst/ElementFactory> +#include <QGst/Bus> + +Player::Player(QObject *parent) + : QObject(parent) +{ +} + +void Player::setVideoSink(const QGst::ElementPtr & sink) +{ + m_videoSink = sink; +} + +void Player::play() +{ + if (m_pipeline) { + m_pipeline->setState(QGst::StatePlaying); + } +} + +void Player::pause() +{ + if (m_pipeline) { + m_pipeline->setState(QGst::StatePaused); + } +} + +void Player::stop() +{ + if (m_pipeline) { + m_pipeline->setState(QGst::StateNull); + } +} + +void Player::setUri(const QString & uri) +{ + if (!m_pipeline) { + m_pipeline = QGst::ElementFactory::make("playbin2").dynamicCast<QGst::Pipeline>(); + if (m_pipeline) { + m_pipeline->setProperty("video-sink", m_videoSink); + + //watch the bus for messages + QGst::BusPtr bus = m_pipeline->bus(); + bus->addSignalWatch(); + QGlib::connect(bus, "message", this, &Player::onBusMessage); + } else { + qCritical() << "Failed to create the pipeline"; + } + } + + if (m_pipeline) { + m_pipeline->setProperty("uri", uri); + } +} + +void Player::onBusMessage(const QGst::MessagePtr & message) +{ + switch (message->type()) { + case QGst::MessageEos: //End of stream. We reached the end of the file. + stop(); + break; + case QGst::MessageError: //Some error occurred. + qCritical() << message.staticCast<QGst::ErrorMessage>()->error(); + stop(); + break; + default: + break; + } +} + +#include "moc_player.cpp" diff --git a/examples/qmlplayer2/player.h b/examples/qmlplayer2/player.h new file mode 100644 index 0000000..a3188e8 --- /dev/null +++ b/examples/qmlplayer2/player.h @@ -0,0 +1,47 @@ +/* + Copyright (C) 2010 Marco Ballesio <gibrovacco@gmail.com> + Copyright (C) 2011-2013 Collabora Ltd. + @author George Kiagiadakis <george.kiagiadakis@collabora.co.uk> + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef PLAYER_H +#define PLAYER_H + +#include <QObject> +#include <QGst/Pipeline> +#include <QGst/Message> + +class Player : public QObject +{ + Q_OBJECT +public: + explicit Player(QObject *parent = 0); + + void setVideoSink(const QGst::ElementPtr & sink); + +public Q_SLOTS: + void play(); + void pause(); + void stop(); + void setUri(const QString & uri); + +private: + void onBusMessage(const QGst::MessagePtr & message); + + QGst::PipelinePtr m_pipeline; + QGst::ElementPtr m_videoSink; +}; + +#endif // PLAYER_H diff --git a/examples/qmlplayer2/qmlplayer2.pro b/examples/qmlplayer2/qmlplayer2.pro new file mode 100644 index 0000000..ee858c0 --- /dev/null +++ b/examples/qmlplayer2/qmlplayer2.pro @@ -0,0 +1,28 @@ +# This is a qmake project file, provided as an example on how to use qmake with QtGStreamer. + +TEMPLATE = app +TARGET = qmlplayer2 + +# produce nice compilation output +CONFIG += silent + +# Tell qmake to use pkg-config to find QtGStreamer. +CONFIG += link_pkgconfig + +# Now tell qmake to link to QtGStreamer and also use its include path and Cflags. +PKGCONFIG += QtGStreamer-0.10 QtGStreamerUi-0.10 + +# Recommended if you are using g++ 4.5 or later. Must be removed for other compilers. +#QMAKE_CXXFLAGS += -std=c++0x + +# Recommended, to avoid possible issues with the "emit" keyword +# You can otherwise also define QT_NO_EMIT, but notice that this is not a documented Qt macro. +DEFINES += QT_NO_KEYWORDS + +# link against QtDeclarative and QtOpenGL +QT += declarative opengl + +# Input +HEADERS += player.h +SOURCES += main.cpp player.cpp +RESOURCES += qmlplayer2.qrc diff --git a/examples/qmlplayer2/qmlplayer2.qml b/examples/qmlplayer2/qmlplayer2.qml new file mode 100644 index 0000000..071096b --- /dev/null +++ b/examples/qmlplayer2/qmlplayer2.qml @@ -0,0 +1,79 @@ +/* + Copyright (C) 2012-2013 Collabora Ltd. <info@collabora.com> + @author George Kiagiadakis <george.kiagiadakis@collabora.com> + Copyright (C) 2013 basysKom GmbH <info@basyskom.com> + @author Benjamin Federau <benjamin.federau@basyskom.com> + + This library is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation; either version 2.1 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ +import QtQuick 2.0 +import QtGStreamer 0.10 + +Rectangle { + id: window + width: 600 + height: 300 + + Column { + + VideoItem { + id: video + + width: window.width + height: 260 + surface: videoSurface1 //bound on the context from main() + } + + Row { + id: buttons + + width: window.width + height: 35 + spacing: 5 + + Rectangle { + id: playButton + color: "black" + + width: 60 + height: 30 + + Text { text: "Play"; color: "white"; anchors.centerIn: parent } + MouseArea { anchors.fill: parent; onClicked: player.play() } + } + + Rectangle { + id: pauseButton + color: "black" + + width: 60 + height: 30 + + Text { text: "Pause"; color: "white"; anchors.centerIn: parent } + MouseArea { anchors.fill: parent; onClicked: { player.pause(); } } + } + + Rectangle { + id: stopButton + color: "black" + + width: 60 + height: 30 + + Text { text: "Stop"; color: "white"; anchors.centerIn: parent } + MouseArea { anchors.fill: parent; onClicked: player.stop() } + } + } + } +} diff --git a/examples/qmlplayer2/qmlplayer2.qrc b/examples/qmlplayer2/qmlplayer2.qrc new file mode 100644 index 0000000..fa5e55a --- /dev/null +++ b/examples/qmlplayer2/qmlplayer2.qrc @@ -0,0 +1,6 @@ +<!DOCTYPE RCC> +<RCC version="1.0"> + <qresource> + <file>qmlplayer2.qml</file> + </qresource> +</RCC> |