summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorGeorge Kiagiadakis <george.kiagiadakis@collabora.co.uk>2011-01-17 18:42:07 +0200
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.co.uk>2011-01-17 18:42:07 +0200
commit7b094779bcea21d5bd5e598c9f5ecd8bd46ae353 (patch)
tree8b1e1debf2e0d05c2ff258a39fb65d14e31dad71 /examples
parentb6a5c5cad363cb78db28c683392784a988e4dcbc (diff)
Add an example that demonstrates the usage of the appsrc and appsink wrappers.
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt1
-rw-r--r--examples/appsink-src/CMakeLists.txt9
-rw-r--r--examples/appsink-src/appsink-src.pro23
-rw-r--r--examples/appsink-src/main.cpp131
4 files changed, 164 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 35bb0fc..fde340f 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,2 +1,3 @@
add_subdirectory(echo)
add_subdirectory(player)
+add_subdirectory(appsink-src)
diff --git a/examples/appsink-src/CMakeLists.txt b/examples/appsink-src/CMakeLists.txt
new file mode 100644
index 0000000..9985a38
--- /dev/null
+++ b/examples/appsink-src/CMakeLists.txt
@@ -0,0 +1,9 @@
+# This file serves as an example of how to use cmake with QtGStreamer.
+# It can be used for building this example either in the QtGStreamer source tree or standalone.
+
+find_package(QtGStreamer REQUIRED)
+include_directories(${QTGSTREAMER_INCLUDES})
+add_definitions(${QTGSTREAMER_DEFINITIONS})
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${QTGSTREAMER_FLAGS}")
+add_executable(appsink-src main.cpp)
+target_link_libraries(appsink-src ${QTGSTREAMER_UTILS_LIBRARIES})
diff --git a/examples/appsink-src/appsink-src.pro b/examples/appsink-src/appsink-src.pro
new file mode 100644
index 0000000..a666cee
--- /dev/null
+++ b/examples/appsink-src/appsink-src.pro
@@ -0,0 +1,23 @@
+# This is a qmake project file, provided as an example on how to use qmake with QtGStreamer.
+
+TEMPLATE = app
+TARGET = appsink-src
+
+# Tell qmake to use pkg-config to find QtGStreamer.
+CONFIG += link_pkgconfig
+
+# Now tell qmake to link to QtGStreamerUtils-0.10 and also use its include path and Cflags.
+PKGCONFIG += QtGStreamerUtils-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
+
+# This example has no GUI
+QT -= gui
+
+# Input
+SOURCES += main.cpp
diff --git a/examples/appsink-src/main.cpp b/examples/appsink-src/main.cpp
new file mode 100644
index 0000000..d15cddc
--- /dev/null
+++ b/examples/appsink-src/main.cpp
@@ -0,0 +1,131 @@
+/*
+ Copyright (C) 2011 Collabora Ltd. <info@collabora.co.uk>
+ @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 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 <iostream>
+#include <QtCore/QCoreApplication>
+#include <QGlib/Error>
+#include <QGlib/Connect>
+#include <QGst/Init>
+#include <QGst/Bus>
+#include <QGst/Pipeline>
+#include <QGst/Parse>
+#include <QGst/Message>
+#include <QGst/Utils/ApplicationSink>
+#include <QGst/Utils/ApplicationSource>
+
+
+class MySink : public QGst::Utils::ApplicationSink
+{
+public:
+ MySink(QGst::Utils::ApplicationSource *src)
+ : QGst::Utils::ApplicationSink(), m_src(src) {}
+
+protected:
+ virtual void eos()
+ {
+ m_src->endOfStream();
+ }
+
+ virtual QGst::FlowReturn newBuffer()
+ {
+ m_src->pushBuffer(pullBuffer());
+ return QGst::FlowOk;
+ }
+
+private:
+ QGst::Utils::ApplicationSource *m_src;
+};
+
+
+class Player : public QCoreApplication
+{
+public:
+ Player(int argc, char **argv);
+ ~Player();
+
+private:
+ void onBusMessage(const QGst::MessagePtr & message);
+
+private:
+ QGst::Utils::ApplicationSource m_src;
+ MySink m_sink;
+ QGst::PipelinePtr pipeline1;
+ QGst::PipelinePtr pipeline2;
+};
+
+Player::Player(int argc, char **argv)
+ : QCoreApplication(argc, argv), m_sink(&m_src)
+{
+ QGst::init(&argc, &argv);
+
+ if (argc <= 1) {
+ std::cerr << "Usage: " << argv[0] << " <audio_file>" << std::endl;
+ std::exit(1);
+ }
+
+ const char *caps = "audio/x-raw-int,channels=1,rate=8000,"
+ "signed=(boolean)true,width=16,depth=16,endianness=1234";
+
+ /* source pipeline */
+ QString pipe1Descr = QString("filesrc location=\"%1\" ! "
+ "decodebin2 ! "
+ "audioconvert ! "
+ "audioresample ! "
+ "appsink name=\"mysink\" caps=\"%2\"").arg(argv[1], caps);
+ pipeline1 = QGst::Parse::launch(pipe1Descr).dynamicCast<QGst::Pipeline>();
+ m_sink.setElement(pipeline1->getElementByName("mysink"));
+ QGlib::connect(pipeline1->bus(), "message::error", this, &Player::onBusMessage);
+ pipeline1->bus()->addSignalWatch();
+
+ /* sink pipeline */
+ QString pipe2Descr = QString("appsrc name=\"mysrc\" caps=\"%1\" ! autoaudiosink").arg(caps);
+ pipeline2 = QGst::Parse::launch(pipe2Descr).dynamicCast<QGst::Pipeline>();
+ m_src.setElement(pipeline2->getElementByName("mysrc"));
+ QGlib::connect(pipeline2->bus(), "message", this, &Player::onBusMessage);
+ pipeline2->bus()->addSignalWatch();
+
+ /* start playing */
+ pipeline1->setState(QGst::StatePlaying);
+ pipeline2->setState(QGst::StatePlaying);
+}
+
+Player::~Player()
+{
+ pipeline1->setState(QGst::StateNull);
+ pipeline2->setState(QGst::StateNull);
+}
+
+void Player::onBusMessage(const QGst::MessagePtr & message)
+{
+ switch (message->type()) {
+ case QGst::MessageEos:
+ quit();
+ break;
+ case QGst::MessageError:
+ qCritical() << message.staticCast<QGst::ErrorMessage>()->error();
+ break;
+ default:
+ break;
+ }
+}
+
+
+int main(int argc, char **argv)
+{
+ Player p(argc, argv);
+ return p.exec();
+}