File: videowidgettest.cpp

package info (click to toggle)
qt-gstreamer 0.10.2-2.1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,012 kB
  • ctags: 2,868
  • sloc: cpp: 17,352; yacc: 156; lex: 125; makefile: 23
file content (111 lines) | stat: -rw-r--r-- 3,189 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*
    Copyright (C) 2010 George Kiagiadakis <kiagiadakis.george@gmail.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 "ui_videowidgettest.h"
#include <QGst/Init>
#include <QGst/Pipeline>
#include <QGst/ElementFactory>
#include <QtGui/QApplication>
#include <QtGui/QMessageBox>
#include <QtGui/QButtonGroup>

class VideoWidgetTest : public QWidget
{
    Q_OBJECT
public:
    VideoWidgetTest(QWidget* parent = 0, Qt::WindowFlags f = 0);

private Q_SLOTS:
    void onButtonClicked(int id);
    void on_forceAspectRatioCheckBox_toggled(bool on);

private:
    Ui::VideoWidgetTest m_ui;
    QGst::PipelinePtr m_pipeline;
    QGst::ElementPtr m_src;
    QGst::ElementPtr m_sink;
};

VideoWidgetTest::VideoWidgetTest(QWidget *parent, Qt::WindowFlags f)
    : QWidget(parent, f)
{
    m_ui.setupUi(this);

    QButtonGroup *group = new QButtonGroup(this);
    group->addButton(m_ui.playingButton, QGst::StatePlaying);
    group->addButton(m_ui.pausedButton, QGst::StatePaused);
    group->addButton(m_ui.readyButton, QGst::StateReady);
    group->addButton(m_ui.nullButton, QGst::StateNull);
    connect(group, SIGNAL(buttonClicked(int)), SLOT(onButtonClicked(int)));

    m_pipeline = QGst::Pipeline::create();
    m_src = QGst::ElementFactory::make("videotestsrc");

    if (!m_src) {
        throw std::runtime_error("Unable to create a videotestsrc");
    }

    m_pipeline->add(m_src);
}

void VideoWidgetTest::onButtonClicked(int id)
{
    QGst::State currentState;
    m_pipeline->getState(&currentState, NULL, 0);

    if (currentState == QGst::StateNull) {
        if (m_sink) {
            m_ui.videoWidget->releaseVideoSink();;
            m_pipeline->remove(m_sink);
        }

        m_sink = QGst::ElementFactory::make(m_ui.elementNameEdit->text());

        if (!m_sink) {
            QMessageBox::critical(this, "Error", "Could not create the specified sink element");
        } else {
            m_pipeline->add(m_sink);
            m_src->link(m_sink);
            m_ui.videoWidget->setVideoSink(m_sink);
        }
    }

    if (m_sink) {
        QGst::State state = static_cast<QGst::State>(id);
        m_pipeline->setState(state);
    }
}

void VideoWidgetTest::on_forceAspectRatioCheckBox_toggled(bool on)
{
    if (m_sink) {
        m_sink->setProperty("force-aspect-ratio", on);
        m_ui.videoWidget->update();
    }
}

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    QGst::init(&argc, &argv);

    VideoWidgetTest test;
    test.show();

    return app.exec();
}

#include "videowidgettest.moc"