From 2d75a32dd0e8fe5bdd6547cb4a95223e120e83f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 31 May 2017 21:35:10 +0200 Subject: [PATCH] Code cleanup Use GNU formatter from Eclipse. --- src/CustomMenuAction.cpp | 14 +- src/CustomMenuAction.h | 12 +- src/CustomSettings.cpp | 37 +- src/CustomSettings.h | 11 +- src/ElementProperties.cpp | 645 ++++++++-------- src/ElementProperties.h | 26 +- src/GraphDisplay.cpp | 1524 ++++++++++++++++++------------------- src/GraphDisplay.h | 115 ++- src/GraphManager.cpp | 995 ++++++++++++------------ src/GraphManager.h | 3 +- src/MainWindow.cpp | 485 ++++++------ src/MainWindow.h | 55 +- src/PadProperties.cpp | 143 ++-- src/PadProperties.h | 5 +- src/PipelineIE.cpp | 991 ++++++++++++------------ src/PipelineIE.h | 6 +- src/PluginsList.cpp | 358 ++++----- src/PluginsList.h | 52 +- src/SeekSlider.cpp | 25 +- src/SeekSlider.h | 7 +- src/main.cpp | 21 +- 21 files changed, 2718 insertions(+), 2812 deletions(-) diff --git a/src/CustomMenuAction.cpp b/src/CustomMenuAction.cpp index 6f4e1e2..725110d 100644 --- a/src/CustomMenuAction.cpp +++ b/src/CustomMenuAction.cpp @@ -1,13 +1,15 @@ #include "CustomMenuAction.h" -CustomMenuAction::CustomMenuAction(const QString& displayName, QObject * parent) -:QAction(displayName, parent) -, m_name(displayName) +CustomMenuAction::CustomMenuAction (const QString& displayName, + QObject * parent) +: QAction (displayName, parent), +m_name (displayName) { } -CustomMenuAction::CustomMenuAction(const QString& displayName, const QString& name, QObject * parent) -:QAction(displayName, parent) -, m_name(name) +CustomMenuAction::CustomMenuAction (const QString& displayName, + const QString& name, QObject * parent) +: QAction (displayName, parent), +m_name (name) { } diff --git a/src/CustomMenuAction.h b/src/CustomMenuAction.h index f230f49..2e5528e 100644 --- a/src/CustomMenuAction.h +++ b/src/CustomMenuAction.h @@ -1,22 +1,18 @@ #ifndef CUSTOM_MENU_ACTION_H_ #define CUSTOM_MENU_ACTION_H_ - #include class CustomMenuAction: public QAction { public: - CustomMenuAction(const QString& displayName, QObject * parent); + CustomMenuAction(const QString& displayName, QObject * parent); + CustomMenuAction(const QString& displayName, const QString& name, QObject * parent); - CustomMenuAction(const QString& displayName, const QString& name, QObject * parent); - - QString getName() { return m_name;} + QString getName() {return m_name;} private: - QString m_name; + QString m_name; }; - - #endif //CUSTOM_MENU_ACTION_H_ diff --git a/src/CustomSettings.cpp b/src/CustomSettings.cpp index 7fdbc86..2b815fa 100644 --- a/src/CustomSettings.cpp +++ b/src/CustomSettings.cpp @@ -5,34 +5,35 @@ #define COMPANY_NAME "virinext" #define APPLICATION_NAME "pipeviz" -void CustomSettings::saveLastIODirectory(const QString &name) +void +CustomSettings::saveLastIODirectory (const QString &name) { - QSettings settings(COMPANY_NAME, APPLICATION_NAME); - settings.setValue("last_directory", name); + QSettings settings (COMPANY_NAME, APPLICATION_NAME); + settings.setValue ("last_directory", name); } - -QString CustomSettings::lastIODirectory() +QString +CustomSettings::lastIODirectory () { - QSettings settings(COMPANY_NAME, APPLICATION_NAME); - QString res = settings.value("last_directory").toString(); + QSettings settings (COMPANY_NAME, APPLICATION_NAME); + QString res = settings.value ("last_directory").toString (); - if(res.isEmpty()) - res = "./"; + if (res.isEmpty ()) + res = "./"; - return res; + return res; } - -void CustomSettings::saveMainWindowGeometry(const QByteArray &geometry) +void +CustomSettings::saveMainWindowGeometry (const QByteArray &geometry) { - QSettings settings(COMPANY_NAME, APPLICATION_NAME); - settings.setValue("geometry", geometry); + QSettings settings (COMPANY_NAME, APPLICATION_NAME); + settings.setValue ("geometry", geometry); } - -QByteArray CustomSettings::mainWindowGeometry() +QByteArray +CustomSettings::mainWindowGeometry () { - QSettings settings(COMPANY_NAME, APPLICATION_NAME); - return settings.value("geometry").toByteArray(); + QSettings settings (COMPANY_NAME, APPLICATION_NAME); + return settings.value ("geometry").toByteArray (); } diff --git a/src/CustomSettings.h b/src/CustomSettings.h index 8c0729f..8295f24 100644 --- a/src/CustomSettings.h +++ b/src/CustomSettings.h @@ -4,16 +4,13 @@ #include #include - namespace CustomSettings { - void saveLastIODirectory(const QString &name); - QString lastIODirectory(); + void saveLastIODirectory(const QString &name); + QString lastIODirectory(); - void saveMainWindowGeometry(const QByteArray &geometry); - QByteArray mainWindowGeometry(); + void saveMainWindowGeometry(const QByteArray &geometry); + QByteArray mainWindowGeometry(); } - - #endif diff --git a/src/ElementProperties.cpp b/src/ElementProperties.cpp index cef6ecd..7742f58 100644 --- a/src/ElementProperties.cpp +++ b/src/ElementProperties.cpp @@ -11,428 +11,387 @@ #include -ElementProperties::ElementProperties(QSharedPointer pGraph, const char *name, - QWidget *parent, Qt::WindowFlags flags): -QWidget(parent, flags), -m_pGraphManager(pGraph), -m_name(name) +ElementProperties::ElementProperties (QSharedPointer pGraph, + const char *name, QWidget *parent, + Qt::WindowFlags flags) +: QWidget (parent, flags), +m_pGraphManager (pGraph), +m_name (name) { - setWindowTitle(QString(name) + " properties"); + setWindowTitle (QString (name) + " properties"); - create(); + create (); } - -void ElementProperties::addParamEnum(GParamSpec *param, GstElement *element, QGridLayout *play) +void +ElementProperties::addParamEnum (GParamSpec *param, GstElement *element, + QGridLayout *play) { - GValue value = { 0 }; + GValue value = { 0 }; - g_value_init (&value, param -> value_type); - if(param -> flags & G_PARAM_READABLE) - g_object_get_property (G_OBJECT(element), param -> name, &value); - else - { - const GValue *valueDef = g_param_spec_get_default_value(param); - g_value_copy(valueDef, &value); - } + g_value_init (&value, param->value_type); + if (param->flags & G_PARAM_READABLE) + g_object_get_property (G_OBJECT (element), param->name, &value); + else { + const GValue *valueDef = g_param_spec_get_default_value (param); + g_value_copy (valueDef, &value); + } + QString propertyName = g_param_spec_get_name (param); + int propertyValue; - QString propertyName = g_param_spec_get_name (param); - int propertyValue; + propertyValue = g_value_get_enum (&value); - propertyValue = g_value_get_enum(&value); + GParamSpecEnum *penumSpec = G_PARAM_SPEC_ENUM (param); - GParamSpecEnum *penumSpec = G_PARAM_SPEC_ENUM(param); + if (!penumSpec) + return; - if(!penumSpec) - return; + QComboBox *pcomBox = new QComboBox; - QComboBox *pcomBox = new QComboBox; + for (std::size_t i = 0; i < penumSpec->enum_class->n_values; i++) { + QVariant var (penumSpec->enum_class->values[i].value); + QString valueName = penumSpec->enum_class->values[i].value_name; - for(std::size_t i=0; i enum_class -> n_values; i++) - { - QVariant var(penumSpec -> enum_class -> values[i].value); - QString valueName = penumSpec -> enum_class -> values[i].value_name; + pcomBox->addItem (valueName, var); - pcomBox -> addItem(valueName, var); + if (penumSpec->enum_class->values[i].value == propertyValue) + pcomBox->setCurrentIndex (i); + } - if(penumSpec -> enum_class -> values[i].value == propertyValue) - pcomBox -> setCurrentIndex(i); - } - - - int row = play -> rowCount(); - - play -> addWidget(new QLabel(propertyName), row, 0); - - play -> addWidget(pcomBox, row, 1); - - m_values.insert(propertyName, pcomBox); + int row = play->rowCount (); + play->addWidget (new QLabel (propertyName), row, 0); + play->addWidget (pcomBox, row, 1); + m_values.insert (propertyName, pcomBox); } - -void ElementProperties::addParamFlags(GParamSpec *param, GstElement *element, QGridLayout *play) +void +ElementProperties::addParamFlags (GParamSpec *param, GstElement *element, + QGridLayout *play) { - GValue value = { 0 }; + GValue value = { 0 }; - g_value_init (&value, param -> value_type); - if(param -> flags & G_PARAM_READABLE) - g_object_get_property (G_OBJECT(element), param -> name, &value); - else - { - const GValue *valueDef = g_param_spec_get_default_value(param); - g_value_copy(valueDef, &value); - } + g_value_init (&value, param->value_type); + if (param->flags & G_PARAM_READABLE) + g_object_get_property (G_OBJECT (element), param->name, &value); + else { + const GValue *valueDef = g_param_spec_get_default_value (param); + g_value_copy (valueDef, &value); + } + QString propertyName = g_param_spec_get_name (param); + int propertyValue; - QString propertyName = g_param_spec_get_name (param); - int propertyValue; + propertyValue = g_value_get_flags (&value); - propertyValue = g_value_get_flags(&value); + GParamSpecFlags *pflagsSpec = G_PARAM_SPEC_FLAGS (param); - GParamSpecFlags *pflagsSpec = G_PARAM_SPEC_FLAGS(param); + if (!pflagsSpec) + return; - if(!pflagsSpec) - return; + QComboBox *pcomBox = new QComboBox; - QComboBox *pcomBox = new QComboBox; + for (std::size_t i = 0; i < pflagsSpec->flags_class->n_values; i++) { + QVariant var (pflagsSpec->flags_class->values[i].value); + QString valueName = pflagsSpec->flags_class->values[i].value_name; - for(std::size_t i=0; i flags_class -> n_values; i++) - { - QVariant var(pflagsSpec -> flags_class -> values[i].value); - QString valueName = pflagsSpec -> flags_class -> values[i].value_name; + pcomBox->addItem (valueName, var); - pcomBox -> addItem(valueName, var); + if (pflagsSpec->flags_class->values[i].value == propertyValue) + pcomBox->setCurrentIndex (i); + } - if(pflagsSpec -> flags_class -> values[i].value == propertyValue) - pcomBox -> setCurrentIndex(i); - } - + int row = play->rowCount (); - int row = play -> rowCount(); + play->addWidget (new QLabel (propertyName), row, 0); - play -> addWidget(new QLabel(propertyName), row, 0); + play->addWidget (pcomBox, row, 1); - play -> addWidget(pcomBox, row, 1); - - m_values.insert(propertyName, pcomBox); + m_values.insert (propertyName, pcomBox); } - - -void ElementProperties::addParamSimple(GParamSpec *param, GstElement *element, QGridLayout *play) +void +ElementProperties::addParamSimple (GParamSpec *param, GstElement *element, + QGridLayout *play) { - bool readOnly = true; + bool readOnly = true; - if(param->flags & G_PARAM_WRITABLE) - readOnly = false; - - GValue value = { 0 }; + if (param->flags & G_PARAM_WRITABLE) + readOnly = false; - g_value_init (&value, param -> value_type); - if(param -> flags & G_PARAM_READABLE) - g_object_get_property (G_OBJECT(element), param -> name, &value); - else - { - const GValue *valueDef = g_param_spec_get_default_value(param); - g_value_copy(valueDef, &value); - } + GValue value = { 0 }; + g_value_init (&value, param->value_type); + if (param->flags & G_PARAM_READABLE) + g_object_get_property (G_OBJECT (element), param->name, &value); + else { + const GValue *valueDef = g_param_spec_get_default_value (param); + g_value_copy (valueDef, &value); + } - QString propertyName = g_param_spec_get_name (param); - QString propertyValue; + QString propertyName = g_param_spec_get_name (param); + QString propertyValue; - bool skip = false; + bool skip = false; - switch (G_VALUE_TYPE (&value)) - { - case G_TYPE_STRING: - { - const char *string_val = g_value_get_string (&value); - propertyValue = string_val; - break; - } - case G_TYPE_BOOLEAN: - { - gboolean bool_val = g_value_get_boolean (&value); - propertyValue = QString::number(bool_val); - break; - } - case G_TYPE_ULONG: - { - propertyValue = QString::number(g_value_get_ulong(&value)); - break; - } - case G_TYPE_LONG: - { - propertyValue = QString::number(g_value_get_long(&value)); - break; - } - case G_TYPE_UINT: - { - propertyValue = QString::number(g_value_get_uint(&value)); - break; - } - case G_TYPE_INT: - { - propertyValue = QString::number(g_value_get_int(&value)); - break; - } - case G_TYPE_UINT64: - { - propertyValue = QString::number(g_value_get_uint64(&value)); - break; - } - case G_TYPE_INT64: - { - propertyValue = QString::number(g_value_get_int64(&value)); - break; - } - case G_TYPE_FLOAT: - { - propertyValue = QString::number(g_value_get_float(&value)); - break; - } - case G_TYPE_DOUBLE: - { - propertyValue = QString::number(g_value_get_double(&value)); - break; - } - case G_TYPE_CHAR: - { - propertyValue = QString::number(g_value_get_char(&value)); - break; - } - case G_TYPE_UCHAR: - { - propertyValue = QString::number(g_value_get_uchar(&value)); - break; - } + switch (G_VALUE_TYPE (&value)) { + case G_TYPE_STRING: { + const char *string_val = g_value_get_string (&value); + propertyValue = string_val; + break; + } + case G_TYPE_BOOLEAN: { + gboolean bool_val = g_value_get_boolean (&value); + propertyValue = QString::number (bool_val); + break; + } + case G_TYPE_ULONG: { + propertyValue = QString::number (g_value_get_ulong (&value)); + break; + } + case G_TYPE_LONG: { + propertyValue = QString::number (g_value_get_long (&value)); + break; + } + case G_TYPE_UINT: { + propertyValue = QString::number (g_value_get_uint (&value)); + break; + } + case G_TYPE_INT: { + propertyValue = QString::number (g_value_get_int (&value)); + break; + } + case G_TYPE_UINT64: { + propertyValue = QString::number (g_value_get_uint64 (&value)); + break; + } + case G_TYPE_INT64: { + propertyValue = QString::number (g_value_get_int64 (&value)); + break; + } + case G_TYPE_FLOAT: { + propertyValue = QString::number (g_value_get_float (&value)); + break; + } + case G_TYPE_DOUBLE: { + propertyValue = QString::number (g_value_get_double (&value)); + break; + } + case G_TYPE_CHAR: { + propertyValue = QString::number (g_value_get_char (&value)); + break; + } + case G_TYPE_UCHAR: { + propertyValue = QString::number (g_value_get_uchar (&value)); + break; + } - default: - { - skip = true; - qDebug() << "property " << propertyName << " not supported"; - break; - } - }; + default: { + skip = true; + qDebug () << "property " << propertyName << " not supported"; + break; + } + }; - int row = play -> rowCount(); + int row = play->rowCount (); - play -> addWidget(new QLabel(propertyName), row, 0); + play->addWidget (new QLabel (propertyName), row, 0); - QLineEdit *ple = new QLineEdit(propertyValue); - ple -> setReadOnly(readOnly); - play -> addWidget(ple, row, 1); - if(!skip) - m_values.insert(propertyName, ple); - else - ple -> setReadOnly(true); + QLineEdit *ple = new QLineEdit (propertyValue); + ple->setReadOnly (readOnly); + play->addWidget (ple, row, 1); + if (!skip) + m_values.insert (propertyName, ple); + else + ple->setReadOnly (true); } - -void ElementProperties::create() +void +ElementProperties::create () { - GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraphManager -> m_pGraph), m_name.toStdString().c_str()); + GstElement *element = gst_bin_get_by_name ( + GST_BIN (m_pGraphManager->m_pGraph), m_name.toStdString ().c_str ()); - if(!element) - return; + if (!element) + return; - QGridLayout *play = new QGridLayout; + QGridLayout *play = new QGridLayout; - GParamSpec **prop_specs; - guint num_props; + GParamSpec **prop_specs; + guint num_props; - prop_specs = g_object_class_list_properties(G_OBJECT_GET_CLASS (element), - &num_props); + prop_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), + &num_props); - for(std::size_t i = 0; i setLayout(play); - QScrollArea *pscroll = new QScrollArea(this); - pscroll -> setWidget(pwgt); + QVBoxLayout *pvblay = new QVBoxLayout; + QWidget *pwgt = new QWidget (this); + pwgt->setLayout (play); + QScrollArea *pscroll = new QScrollArea (this); + pscroll->setWidget (pwgt); - pvblay -> addWidget(pscroll); + pvblay->addWidget (pscroll); - QHBoxLayout *phblay = new QHBoxLayout; + QHBoxLayout *phblay = new QHBoxLayout; - QPushButton *pcmdApply = new QPushButton("Apply"); - QPushButton *pcmdOk = new QPushButton("OK"); - QPushButton *pcmdCancel = new QPushButton("Cancel"); + QPushButton *pcmdApply = new QPushButton ("Apply"); + QPushButton *pcmdOk = new QPushButton ("OK"); + QPushButton *pcmdCancel = new QPushButton ("Cancel"); + phblay->addStretch (1); + phblay->addWidget (pcmdApply); + phblay->addWidget (pcmdCancel); + phblay->addWidget (pcmdOk); - phblay -> addStretch(1); - phblay -> addWidget(pcmdApply); - phblay -> addWidget(pcmdCancel); - phblay -> addWidget(pcmdOk); + pvblay->addLayout (phblay); - pvblay -> addLayout(phblay); + QObject::connect (pcmdApply, SIGNAL (clicked ()), this, + SLOT (applyClicked ())); + QObject::connect (pcmdCancel, SIGNAL (clicked ()), this, SLOT (close ())); + QObject::connect (pcmdOk, SIGNAL (clicked ()), this, SLOT (okClicked ())); - QObject::connect(pcmdApply, SIGNAL(clicked()), this, SLOT(applyClicked())); - QObject::connect(pcmdCancel, SIGNAL(clicked()), this, SLOT(close())); - QObject::connect(pcmdOk, SIGNAL(clicked()), this, SLOT(okClicked())); + setLayout (pvblay); - setLayout(pvblay); - - g_free(prop_specs); - gst_object_unref(element); + g_free (prop_specs); + gst_object_unref (element); } -void ElementProperties::applyClicked() +void +ElementProperties::applyClicked () { - GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraphManager -> m_pGraph), - m_name.toStdString().c_str()); + GstElement *element = gst_bin_get_by_name ( + GST_BIN (m_pGraphManager->m_pGraph), m_name.toStdString ().c_str ()); - if(!element) - return; + if (!element) + return; - QMap::iterator itr = m_values.begin(); + QMap::iterator itr = m_values.begin (); - for(;itr != m_values.end(); itr++) - { - GParamSpec *param = g_object_class_find_property(G_OBJECT_GET_CLASS (element), - itr.key().toStdString().c_str()); + for (; itr != m_values.end (); itr++) { + GParamSpec *param = g_object_class_find_property ( + G_OBJECT_GET_CLASS (element), itr.key ().toStdString ().c_str ()); - if(!param) - { - qDebug() << "problem with setting " << itr.key() << " property"; - continue; - } + if (!param) { + qDebug () << "problem with setting " << itr.key () << " property"; + continue; + } - if(!(param -> flags & G_PARAM_WRITABLE)) - continue; + if (!(param->flags & G_PARAM_WRITABLE)) + continue; - QString valStr; + QString valStr; - if(dynamic_cast(itr.value())) - valStr = ((QLineEdit *) itr.value()) -> text(); - else if(dynamic_cast(itr.value())) - { - QComboBox *pcomBox = (QComboBox *) itr.value(); - int val = pcomBox -> itemData(pcomBox -> currentIndex()).toInt(); - valStr = QString::number(val); - } + if (dynamic_cast (itr.value ())) + valStr = ((QLineEdit *) itr.value ())->text (); + else if (dynamic_cast (itr.value ())) { + QComboBox *pcomBox = (QComboBox *) itr.value (); + int val = pcomBox->itemData (pcomBox->currentIndex ()).toInt (); + valStr = QString::number (val); + } - std::string tmpStr = itr.key().toStdString(); - const char *propName = tmpStr.c_str(); + std::string tmpStr = itr.key ().toStdString (); + const char *propName = tmpStr.c_str (); - if(G_IS_PARAM_SPEC_ENUM(param) || G_IS_PARAM_SPEC_FLAGS(param)) - { - if(dynamic_cast(itr.value())) - { - QComboBox *pcomBox = (QComboBox *) itr.value(); - int val = pcomBox -> itemData(pcomBox -> currentIndex()).toInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - } - } - else - { - switch (param -> value_type) - { - case G_TYPE_STRING: - { - g_object_set(G_OBJECT(element), propName, valStr.toStdString().c_str(), NULL); - break; - } - case G_TYPE_BOOLEAN: - { - gboolean val = valStr.toInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_ULONG: - { - gulong val = valStr.toULong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_LONG: - { - glong val = valStr.toLong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_UINT: - { - guint val = valStr.toUInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_INT: - { - gint val = valStr.toInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_UINT64: - { - guint64 val = valStr.toULongLong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_INT64: - { - gint64 val = valStr.toLongLong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_FLOAT: - { - gfloat val = valStr.toFloat(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_DOUBLE: - { - gdouble val = valStr.toDouble(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_CHAR: - { - gchar val = valStr.toInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_UCHAR: - { - guchar val = valStr.toUInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - default: - { - qDebug() << "property " << itr.key() << " not supported"; - break; - } - }; - } - } + if (G_IS_PARAM_SPEC_ENUM (param) || G_IS_PARAM_SPEC_FLAGS (param)) { + if (dynamic_cast (itr.value ())) { + QComboBox *pcomBox = (QComboBox *) itr.value (); + int val = pcomBox->itemData (pcomBox->currentIndex ()).toInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + } + } + else { + switch (param->value_type) { + case G_TYPE_STRING: { + g_object_set (G_OBJECT (element), propName, + valStr.toStdString ().c_str (), NULL); + break; + } + case G_TYPE_BOOLEAN: { + gboolean val = valStr.toInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_ULONG: { + gulong val = valStr.toULong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_LONG: { + glong val = valStr.toLong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_UINT: { + guint val = valStr.toUInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_INT: { + gint val = valStr.toInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_UINT64: { + guint64 val = valStr.toULongLong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_INT64: { + gint64 val = valStr.toLongLong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_FLOAT: { + gfloat val = valStr.toFloat (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_DOUBLE: { + gdouble val = valStr.toDouble (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_CHAR: { + gchar val = valStr.toInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_UCHAR: { + guchar val = valStr.toUInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + default: { + qDebug () << "property " << itr.key () << " not supported"; + break; + } + }; + } + } - gst_object_unref(element); + gst_object_unref (element); - delete layout(); - qDeleteAll(children()); + delete layout (); + qDeleteAll ( + children ()); - - create(); +create (); } -void ElementProperties::okClicked() +void +ElementProperties::okClicked () { - applyClicked(); - close(); + applyClicked (); + close (); } diff --git a/src/ElementProperties.h b/src/ElementProperties.h index 6ddc89a..7025aa7 100644 --- a/src/ElementProperties.h +++ b/src/ElementProperties.h @@ -12,26 +12,24 @@ class ElementProperties: public QWidget { -Q_OBJECT + Q_OBJECT public: - ElementProperties(QSharedPointer pGraphManager, const char *name, - QWidget *parent = 0, Qt::WindowFlags flags = 0); - + ElementProperties(QSharedPointer pGraphManager, const char *name, + QWidget *parent = 0, Qt::WindowFlags flags = 0); private slots: - void applyClicked(); - void okClicked(); + void applyClicked(); + void okClicked(); private: - QSharedPointer m_pGraphManager; - QMap m_values; - QString m_name; + QSharedPointer m_pGraphManager; + QMap m_values; + QString m_name; - void create(); - void addParamSimple(GParamSpec *value, GstElement *element, QGridLayout *play); - void addParamEnum(GParamSpec *value, GstElement *element, QGridLayout *play); - void addParamFlags(GParamSpec *value, GstElement *element, QGridLayout *play); + void create(); + void addParamSimple(GParamSpec *value, GstElement *element, QGridLayout *play); + void addParamEnum(GParamSpec *value, GstElement *element, QGridLayout *play); + void addParamFlags(GParamSpec *value, GstElement *element, QGridLayout *play); }; - #endif diff --git a/src/GraphDisplay.cpp b/src/GraphDisplay.cpp index 4770513..29fd073 100644 --- a/src/GraphDisplay.cpp +++ b/src/GraphDisplay.cpp @@ -21,988 +21,944 @@ #define PAD_SIZE 8 #define PAD_SIZE_ACTION 16 - -GraphDisplay::GraphDisplay(QWidget *parent, Qt::WindowFlags f): -QWidget(parent, f) +GraphDisplay::GraphDisplay (QWidget *parent, Qt::WindowFlags f) +: QWidget (parent, f) { - setFocusPolicy(Qt::WheelFocus); - setMouseTracking(true); + setFocusPolicy (Qt::WheelFocus); + setMouseTracking (true); } -ElementInfo* GraphDisplay::getElement(std::size_t elementId) +ElementInfo* +GraphDisplay::getElement (std::size_t elementId) { - ElementInfo* element = NULL; - std::size_t i=0; - for(; im_pads.size(); j++) - if(element->m_pads[j].m_id == padId) { - pad = &element->m_pads[j]; - break; - } + return NULL; + std::size_t j = 0; + for (; j < element->m_pads.size (); j++) + if (element->m_pads[j].m_id == padId) { + pad = &element->m_pads[j]; + break; + } return pad; } -void GraphDisplay::updateDisplayInfoIds() +void +GraphDisplay::updateDisplayInfoIds () { - for(std::size_t i=0; i &info) +void +GraphDisplay::update (const std::vector &info) { - bool needUpdate = false; + bool needUpdate = false; - if(m_info.size() != info.size()) - needUpdate = true; + if (m_info.size () != info.size ()) + needUpdate = true; - if(!needUpdate) - { - for(std::size_t i=0; i= 1) - height += (std::max(numInPads, numOutPads) - 1) * 25; + if (std::max (numInPads, numOutPads) >= 1) + height += (std::max (numInPads, numOutPads) - 1) * 25; - int curX, curY; - curX = curY = 10; + int curX, curY; + curX = curY = 10; - QRect rect(curX, curY, width, height); + QRect rect (curX, curY, width, height); - while(true) - { - rect = QRect(curX, curY, width, height); - QRect rectTest(curX, curY - 15, width + 15, height + 15); - bool noIntersects = true; - for(std::size_t i=0; i= m_displayInfo.size()) - break; - } + if (i >= m_displayInfo.size ()) + break; + } + std::size_t i = 0; + for (; i < m_info.size (); i++) { + std::size_t j = 0; + for (; j < m_displayInfo.size (); j++) { + if (m_displayInfo[j].m_id == m_info[i].m_id) + break; + } - std::size_t i=0; - for(; i reorderedDisplayInfo (m_info.size ()); + for (std::size_t i = 0; i < m_info.size (); i++) { + for (std::size_t j = 0; j < m_displayInfo.size (); j++) { + if (m_displayInfo[j].m_id == m_info[i].m_id) { + reorderedDisplayInfo[i] = m_displayInfo[j]; + break; + } + } + } - std::vector reorderedDisplayInfo(m_info.size()); - for(std::size_t i=0; i pos(), elementId, padId); + std::size_t elementId, padId; + getIdByPosition (event->pos (), elementId, padId); + if (event->buttons () & Qt::RightButton) { + showContextMenu (event); + } + else { + if (padId != ((size_t) -1)) { + m_moveInfo.m_padId = padId; + m_moveInfo.m_elementId = elementId; + m_moveInfo.m_position = event->pos (); + m_moveInfo.m_action = MakeConnect; + m_moveInfo.m_startPosition = event->pos (); + } + else if (elementId != ((size_t) -1)) { + m_moveInfo.m_elementId = elementId; + m_moveInfo.m_padId = -1; + m_moveInfo.m_position = event->pos (); + m_moveInfo.m_action = MoveComponent; + m_moveInfo.m_startPosition = event->pos (); + } + else { + m_moveInfo.m_startPosition = event->pos (); + m_moveInfo.m_action = Select; + m_moveInfo.m_position = QPoint (); + } + } - if(event -> buttons() & Qt::RightButton) - { - showContextMenu(event); - } - else - { - if(padId != ((size_t)-1)) - { - m_moveInfo.m_padId = padId; - m_moveInfo.m_elementId = elementId; - m_moveInfo.m_position = event -> pos(); - m_moveInfo.m_action = MakeConnect; - m_moveInfo.m_startPosition = event -> pos(); - } - else if(elementId != ((size_t)-1)) - { - m_moveInfo.m_elementId = elementId; - m_moveInfo.m_padId = -1; - m_moveInfo.m_position = event -> pos(); - m_moveInfo.m_action = MoveComponent; - m_moveInfo.m_startPosition = event -> pos(); - } - else - { - m_moveInfo.m_startPosition = event -> pos(); - m_moveInfo.m_action = Select; - m_moveInfo.m_position = QPoint(); - } - } - - for(std::size_t i=0; i pos(), elementId, padId); - - if(elementId != ((size_t)-1) && padId != ((size_t)-1)) - { - ElementInfo infoSrc, infoDst; - const char *srcPad, *dstPad; - srcPad = NULL; - dstPad = NULL; + if (m_moveInfo.m_action == MakeConnect) { + std::size_t elementId, padId; + getIdByPosition (event->pos (), elementId, padId); - for(std::size_t i=0; i Connect(infoSrc.m_name.c_str(), srcPad, infoDst.m_name.c_str(), dstPad)) - { - QString msg; - msg = "Connection "; - msg += QString(infoSrc.m_name.c_str()) + ":" + srcPad; - msg += " => "; - msg += QString(infoDst.m_name.c_str()) + ":" + dstPad; - msg += " was FAILED"; + qDebug () << "Connection from " << infoSrc.m_name.c_str () << ":" + << srcPad << " to " << infoDst.m_name.c_str () << ":" << dstPad; - QMessageBox::warning(this, "Connection failed", msg); - } + if (!m_pGraph->Connect (infoSrc.m_name.c_str (), srcPad, + infoDst.m_name.c_str (), dstPad)) { + QString msg; + msg = "Connection "; + msg += QString (infoSrc.m_name.c_str ()) + ":" + srcPad; + msg += " => "; + msg += QString (infoDst.m_name.c_str ()) + ":" + dstPad; + msg += " was FAILED"; - m_info = m_pGraph -> GetInfo(); - updateDisplayInfoIds(); - if(g_str_has_prefix(infoDst.m_name.c_str(),"decodebin")) { - m_pGraph->Play(); - qDebug() << "Launch play to discover the new pad"; - } - } - } - else if(m_moveInfo.m_action == Select) - { - std::size_t width = std::abs(m_moveInfo.m_position.x() - m_moveInfo.m_startPosition.x()); - std::size_t height = std::abs(m_moveInfo.m_position.y() - m_moveInfo.m_startPosition.y()); + QMessageBox::warning (this, "Connection failed", msg); + } - if(!m_moveInfo.m_position.isNull() && width * height > 5) - { - QRect selectionRect(m_moveInfo.m_startPosition, m_moveInfo.m_position); - for(std::size_t i=0; iGetInfo (); + updateDisplayInfoIds (); + if (g_str_has_prefix (infoDst.m_name.c_str (), "decodebin")) { + m_pGraph->Play (); + qDebug () << "Launch play to discover the new pad"; + } + } + } + else if (m_moveInfo.m_action == Select) { + std::size_t width = std::abs ( + m_moveInfo.m_position.x () - m_moveInfo.m_startPosition.x ()); + std::size_t height = std::abs ( + m_moveInfo.m_position.y () - m_moveInfo.m_startPosition.y ()); - repaint(); - } - else if(m_moveInfo.m_action == MoveComponent) - { - int dx = event -> x() - m_moveInfo.m_startPosition.x(); - int dy = event -> y() - m_moveInfo.m_startPosition.y(); + if (!m_moveInfo.m_position.isNull () && width * height > 5) { + QRect selectionRect (m_moveInfo.m_startPosition, m_moveInfo.m_position); + for (std::size_t i = 0; i < m_displayInfo.size (); i++) { + if (selectionRect.intersects (m_displayInfo[i].m_rect)) + m_displayInfo[i].m_isSelected = true; + } + } - if(dx == dy && dy == 0) - { - for(std::size_t i=0; ix () - m_moveInfo.m_startPosition.x (); + int dy = event->y () - m_moveInfo.m_startPosition.y (); - } -exit: - m_moveInfo.m_action = None; - m_moveInfo.m_elementId = -1; - m_moveInfo.m_padId = -1; - m_moveInfo.m_startPosition = QPoint(); - m_moveInfo.m_position = QPoint(); - repaint(); + if (dx == dy && dy == 0) { + for (std::size_t i = 0; i < m_displayInfo.size (); i++) { + if (m_displayInfo[i].m_id == m_moveInfo.m_elementId) { + m_displayInfo[i].m_isSelected = true; + repaint (); + break; + } + } + } + + } + exit: m_moveInfo.m_action = None; + m_moveInfo.m_elementId = -1; + m_moveInfo.m_padId = -1; + m_moveInfo.m_startPosition = QPoint (); + m_moveInfo.m_position = QPoint (); + repaint (); } -void GraphDisplay::mouseMoveEvent(QMouseEvent *event) +void +GraphDisplay::mouseMoveEvent (QMouseEvent *event) { - if(m_moveInfo.m_action == MoveComponent) - { - int dx = event -> x() - m_moveInfo.m_position.x(); - int dy = event -> y() - m_moveInfo.m_position.y(); + if (m_moveInfo.m_action == MoveComponent) { + int dx = event->x () - m_moveInfo.m_position.x (); + int dy = event->y () - m_moveInfo.m_position.y (); - for(std::size_t i=0; i pos(); - repaint(); - } else { - std::size_t elementId, padId; - getIdByPosition(event -> pos(), elementId, padId); - if (padId != ((size_t)-1)) { - ElementInfo* element = getElement(elementId); - PadInfo* pad = getPad(elementId, padId); - QString caps = m_pGraph->getPadCaps(element,pad,PAD_CAPS_ALL,true); - setToolTip(caps); - } - else - setToolTip(""); - } + if (m_moveInfo.m_action != None) { + m_moveInfo.m_position = event->pos (); + repaint (); + } + else { + std::size_t elementId, padId; + getIdByPosition (event->pos (), elementId, padId); + if (padId != ((size_t) -1)) { + ElementInfo* element = getElement (elementId); + PadInfo* pad = getPad (elementId, padId); + QString caps = m_pGraph->getPadCaps (element, pad, PAD_CAPS_ALL, true); + setToolTip (caps); + } + else + setToolTip (""); + } } -void GraphDisplay::keyPressEvent(QKeyEvent* event) +void +GraphDisplay::keyPressEvent (QKeyEvent* event) { - if(event -> key() == Qt::Key_Delete) - removeSelected(); + if (event->key () == Qt::Key_Delete) + removeSelected (); - return QWidget::keyPressEvent(event); + return QWidget::keyPressEvent (event); } - -void GraphDisplay::showContextMenu(QMouseEvent *event) +void +GraphDisplay::showContextMenu (QMouseEvent *event) { - QMenu menu; + QMenu menu; - std::size_t elementId, padId; - getIdByPosition(event -> pos(), elementId, padId); + std::size_t elementId, padId; + getIdByPosition (event->pos (), elementId, padId); - GstState state; - GstStateChangeReturn res = gst_element_get_state (m_pGraph -> m_pGraph, &state, NULL, GST_MSECOND); + GstState state; + GstStateChangeReturn res = gst_element_get_state (m_pGraph->m_pGraph, &state, + NULL, + GST_MSECOND); - bool isActive = false; + bool isActive = false; - if(res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED || state == GST_STATE_PLAYING) - isActive = true; + if (res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED + || state == GST_STATE_PLAYING) + isActive = true; - int selectedCount = 0; - for(std::size_t i=0; i 1) - { - CustomMenuAction *pact = new CustomMenuAction("Remove selected", &menu); - menu.addAction(pact); - if(isActive) - pact -> setDisabled(true); + if (selectedCount > 1) { + CustomMenuAction *pact = new CustomMenuAction ("Remove selected", &menu); + menu.addAction (pact); + if (isActive) + pact->setDisabled (true); - } - else if(padId != ((size_t)-1)) { - menu.addAction(new CustomMenuAction("Render", &menu)); - menu.addAction(new CustomMenuAction("Render anyway", &menu)); - menu.addAction(new CustomMenuAction("Pad properties", &menu)); - menu.addAction(new CustomMenuAction("typefind", "ElementName", &menu)); - } - else if(elementId != ((size_t)-1)) - { - menu.addAction(new CustomMenuAction("Element properties", &menu)); - QAction *pact = new CustomMenuAction("Remove", &menu); - menu.addAction(pact); + } + else if (padId != ((size_t) -1)) { + menu.addAction (new CustomMenuAction ("Render", &menu)); + menu.addAction (new CustomMenuAction ("Render anyway", &menu)); + menu.addAction (new CustomMenuAction ("Pad properties", &menu)); + menu.addAction (new CustomMenuAction ("typefind", "ElementName", &menu)); + } + else if (elementId != ((size_t) -1)) { + menu.addAction (new CustomMenuAction ("Element properties", &menu)); + QAction *pact = new CustomMenuAction ("Remove", &menu); + menu.addAction (pact); - if(isActive) - pact -> setDisabled(true); + if (isActive) + pact->setDisabled (true); - pact = new CustomMenuAction("Request pad...", &menu); - menu.addAction(pact); - } - else - { - for(std::size_t i=0; i pos().x(); - double y0 = event -> pos().y(); + double x0 = event->pos ().x (); + double y0 = event->pos ().y (); - double distance = std::abs((int)(dy * x0 - dx * y0 + x2 * y1 - y2 * x1)); - distance = distance / sqrt(dy * dy + dx * dx); + double distance = std::abs ( + (int) (dy * x0 - dx * y0 + x2 * y1 - y2 * x1)); + distance = distance / sqrt (dy * dy + dx * dx); - if (distance < 5) { - elementId = m_info[i].m_id; - padId = m_info[i].m_pads[j].m_id; + if (distance < 5) { + elementId = m_info[i].m_id; + padId = m_info[i].m_pads[j].m_id; - QAction *pact = new CustomMenuAction("Disconnect", &menu); - menu.addAction(pact); + QAction *pact = new CustomMenuAction ("Disconnect", &menu); + menu.addAction (pact); + if (isActive) + pact->setDisabled (true); + break; + } + } + } + if (!menu.isEmpty ()) + break; + } + } - if(isActive) - pact -> setDisabled(true); - break; - } - } - } - if(!menu.isEmpty()) - break; - } - } - - if(!menu.isEmpty()) - { - CustomMenuAction *pact = (CustomMenuAction*)menu.exec(event -> globalPos()); - if (pact) { - if (pact -> getName() == "Remove") - removePlugin(elementId); - else if (pact -> getName() == "Element properties") - showElementProperties(elementId); - else if (pact -> getName() == "Pad properties") - showPadProperties(elementId, padId); - else if (pact -> getName() == "Render") - renderPad(elementId, padId, true); - else if (pact -> getName() == "Render anyway") - renderPad(elementId, padId, false); - else if (pact -> getName() == "Disconnect") - disconnect(elementId, padId); - else if (pact -> getName() == "Request pad...") - requestPad(elementId); - else if (pact -> getName() == "Remove selected") - removeSelected(); - else if (pact->getName() == "ElementName") - connectPlugin(elementId, pact->text()); - } - } + if (!menu.isEmpty ()) { + CustomMenuAction *pact = (CustomMenuAction*) menu.exec ( + event->globalPos ()); + if (pact) { + if (pact->getName () == "Remove") + removePlugin (elementId); + else if (pact->getName () == "Element properties") + showElementProperties (elementId); + else if (pact->getName () == "Pad properties") + showPadProperties (elementId, padId); + else if (pact->getName () == "Render") + renderPad (elementId, padId, true); + else if (pact->getName () == "Render anyway") + renderPad (elementId, padId, false); + else if (pact->getName () == "Disconnect") + disconnect (elementId, padId); + else if (pact->getName () == "Request pad...") + requestPad (elementId); + else if (pact->getName () == "Remove selected") + removeSelected (); + else if (pact->getName () == "ElementName") + connectPlugin (elementId, pact->text ()); + } + } } -void GraphDisplay::removeSelected() +void +GraphDisplay::removeSelected () { - GstState state; - GstStateChangeReturn res = gst_element_get_state (m_pGraph -> m_pGraph, &state, NULL, GST_MSECOND); + GstState state; + GstStateChangeReturn res = gst_element_get_state (m_pGraph->m_pGraph, &state, + NULL, + GST_MSECOND); - if(res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED || state == GST_STATE_PLAYING) - return; + if (res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED + || state == GST_STATE_PLAYING) + return; - while(true) - { - std::size_t i=0; - for(; i RemovePlugin(element->m_name.c_str())) - { - std::vector info = m_pGraph -> GetInfo(); - update(info); - } - else - QMessageBox::warning(this, "Element removing problem", "Element `" + QString(element->m_name.c_str()) + "` remowing was FAILED"); - } + ElementInfo* element = getElement (id); + if (element) { + if (m_pGraph->RemovePlugin (element->m_name.c_str ())) { + std::vector info = m_pGraph->GetInfo (); + update (info); + } + else + QMessageBox::warning ( + this, + "Element removing problem", + "Element `" + QString (element->m_name.c_str ()) + + "` remowing was FAILED"); + } } -void GraphDisplay::connectPlugin(std::size_t elementId, const QString& name) +void +GraphDisplay::connectPlugin (std::size_t elementId, const QString& name) { - ElementInfo* element = getElement(elementId); - gchar* pluginName = m_pGraph->AddPlugin(name.toStdString().c_str(), NULL); - m_pGraph->Connect(element->m_name.c_str(), pluginName); - g_free(pluginName); + ElementInfo* element = getElement (elementId); + gchar* pluginName = m_pGraph->AddPlugin (name.toStdString ().c_str (), NULL); + m_pGraph->Connect (element->m_name.c_str (), pluginName); + g_free (pluginName); } -void GraphDisplay::showElementProperties(std::size_t id) +void +GraphDisplay::showElementProperties (std::size_t id) { - ElementInfo* element = getElement(id); - if (element) { - ElementProperties *pprops = new ElementProperties(m_pGraph,element->m_name.c_str()); - pprops -> setAttribute(Qt::WA_QuitOnClose, false); - pprops -> show(); - } + ElementInfo* element = getElement (id); + if (element) { + ElementProperties *pprops = new ElementProperties ( + m_pGraph, element->m_name.c_str ()); + pprops->setAttribute (Qt::WA_QuitOnClose, false); + pprops->show (); + } } -void GraphDisplay::showPadProperties(std::size_t elementId, std::size_t padId) +void +GraphDisplay::showPadProperties (std::size_t elementId, std::size_t padId) { - ElementInfo* element = getElement(elementId); - PadInfo* pad = getPad(elementId, padId); - if (pad) { - PadProperties *pprops = new PadProperties(m_pGraph, element->m_name.c_str(), pad->m_name.c_str()); - pprops -> setAttribute(Qt::WA_QuitOnClose, false); - pprops -> show(); - } + ElementInfo* element = getElement (elementId); + PadInfo* pad = getPad (elementId, padId); + if (pad) { + PadProperties *pprops = new PadProperties (m_pGraph, + element->m_name.c_str (), + pad->m_name.c_str ()); + pprops->setAttribute (Qt::WA_QuitOnClose, false); + pprops->show (); + } } -void GraphDisplay::renderPad(std::size_t elementId, std::size_t padId, bool capsAny) +void +GraphDisplay::renderPad (std::size_t elementId, std::size_t padId, bool capsAny) { - ElementInfo* element = getElement(elementId); - PadInfo* pad = getPad(elementId, padId); + ElementInfo* element = getElement (elementId); + PadInfo* pad = getPad (elementId, padId); - if(!element || !pad) - qDebug() << "element or pad is unreachable"; + if (!element || !pad) + qDebug () << "element or pad is unreachable"; - PluginsList* pluginList = new PluginsList(); - GList* plugins_list = pluginList->getSortedByRank(); - GList* l; + PluginsList* pluginList = new PluginsList (); + GList* plugins_list = pluginList->getSortedByRank (); + GList* l; - for (l = plugins_list; l != NULL; l = l->next) { - Plugin* plugin = (Plugin*)(l->data); - if (m_pGraph->CanConnect(element->m_name.c_str(), pad->m_name.c_str() , plugin->getName().toStdString().c_str(), capsAny)) { - gchar* pluginName = m_pGraph->AddPlugin(plugin->getName().toStdString().c_str(), NULL); - m_pGraph->Connect(element->m_name.c_str(), pluginName); - g_free(pluginName); - break; - } - } - delete pluginList; + for (l = plugins_list; l != NULL; l = l->next) { + Plugin* plugin = (Plugin*) (l->data); + if (m_pGraph->CanConnect (element->m_name.c_str (), pad->m_name.c_str (), + plugin->getName ().toStdString ().c_str (), + capsAny)) { + gchar* pluginName = m_pGraph->AddPlugin ( + plugin->getName ().toStdString ().c_str (), NULL); + m_pGraph->Connect (element->m_name.c_str (), pluginName); + g_free (pluginName); + break; + } + } + delete pluginList; } -void GraphDisplay::disconnect(size_t elementId, size_t padId) +void +GraphDisplay::disconnect (size_t elementId, size_t padId) { - std::string src, dst, srcPad, dstPad; + std::string src, dst, srcPad, dstPad; - for(std::size_t i=0; i " << dst.c_str() << ":" << dstPad.c_str(); + qDebug () << "Disconnect " << src.c_str () << ":" << srcPad.c_str () + << " <-> " << dst.c_str () << ":" << dstPad.c_str (); - if(src.empty() || dst.empty() || srcPad.empty() || dstPad.empty()) - return; + if (src.empty () || dst.empty () || srcPad.empty () || dstPad.empty ()) + return; + m_pGraph->Disconnect (src.c_str (), srcPad.c_str (), dst.c_str (), + dstPad.c_str ()); - m_pGraph->Disconnect(src.c_str(), srcPad.c_str(), dst.c_str(), dstPad.c_str()); - - m_info = m_pGraph -> GetInfo(); - updateDisplayInfoIds(); - repaint(); + m_info = m_pGraph->GetInfo (); + updateDisplayInfoIds (); + repaint (); } -void GraphDisplay::requestPad(std::size_t elementId) +void +GraphDisplay::requestPad (std::size_t elementId) { - QStringList labels; - labels.push_back("Template name"); - labels.push_back("Caps"); - labels.push_back("Direction"); + QStringList labels; + labels.push_back ("Template name"); + labels.push_back ("Caps"); + labels.push_back ("Direction"); - QTableWidget *ptwgt = new QTableWidget(); - ptwgt -> setColumnCount(3); - ptwgt -> setHorizontalHeaderLabels(labels); - ptwgt -> setSelectionBehavior(QAbstractItemView::SelectRows); - ptwgt -> setEditTriggers(QAbstractItemView::NoEditTriggers); + QTableWidget *ptwgt = new QTableWidget (); + ptwgt->setColumnCount (3); + ptwgt->setHorizontalHeaderLabels (labels); + ptwgt->setSelectionBehavior (QAbstractItemView::SelectRows); + ptwgt->setEditTriggers (QAbstractItemView::NoEditTriggers); - ElementInfo* elementInfo = getElement(elementId); - GstElement *element = NULL; - if(elementInfo) - element = gst_bin_get_by_name(GST_BIN(m_pGraph -> m_pGraph),elementInfo->m_name.c_str()); + ElementInfo* elementInfo = getElement (elementId); + GstElement *element = NULL; + if (elementInfo) + element = gst_bin_get_by_name (GST_BIN (m_pGraph->m_pGraph), + elementInfo->m_name.c_str ()); - if(!element) - { - QMessageBox::warning(this, "Request pad failed", "Request pad list obtaining was failed"); - return; - } + if (!element) { + QMessageBox::warning (this, "Request pad failed", + "Request pad list obtaining was failed"); + return; + } - GstElementClass *klass; - klass = GST_ELEMENT_GET_CLASS(element); + GstElementClass *klass; + klass = GST_ELEMENT_GET_CLASS (element); - GList *lst = gst_element_class_get_pad_template_list(klass); + GList *lst = gst_element_class_get_pad_template_list (klass); - std::size_t k = 0; - while (lst != NULL) - { - GstPadTemplate *templ; - templ = (GstPadTemplate *) lst -> data; + std::size_t k = 0; + while (lst != NULL) { + GstPadTemplate *templ; + templ = (GstPadTemplate *) lst->data; - if(GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_REQUEST) - { - ptwgt -> setRowCount(k + 1); - ptwgt -> setItem(k, 0, new QTableWidgetItem(GST_PAD_TEMPLATE_NAME_TEMPLATE(templ))); + if (GST_PAD_TEMPLATE_PRESENCE (templ) == GST_PAD_REQUEST) { + ptwgt->setRowCount (k + 1); + ptwgt->setItem ( + k, 0, new QTableWidgetItem (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ))); - GstCaps *caps = gst_pad_template_get_caps(templ); - gchar *capsStr = gst_caps_to_string(caps); - ptwgt -> setItem(k, 1, new QTableWidgetItem(capsStr)); - g_free(capsStr); - gst_caps_unref(caps); + GstCaps *caps = gst_pad_template_get_caps (templ); + gchar *capsStr = gst_caps_to_string (caps); + ptwgt->setItem (k, 1, new QTableWidgetItem (capsStr)); + g_free (capsStr); + gst_caps_unref (caps); - const char *directionSrc = "SRC"; - const char *directionSink = "SINK"; - const char *directionUnknown = "UNKNOWN"; + const char *directionSrc = "SRC"; + const char *directionSink = "SINK"; + const char *directionUnknown = "UNKNOWN"; - QString direction; - switch(GST_PAD_TEMPLATE_DIRECTION(templ)) - { - case GST_PAD_UNKNOWN: - direction = directionUnknown; - break; + QString direction; + switch (GST_PAD_TEMPLATE_DIRECTION (templ)) { + case GST_PAD_UNKNOWN: + direction = directionUnknown; + break; - case GST_PAD_SRC: - direction = directionSrc; - break; + case GST_PAD_SRC: + direction = directionSrc; + break; - case GST_PAD_SINK: - direction = directionSink; - break; - }; + case GST_PAD_SINK: + direction = directionSink; + break; + }; - ptwgt -> setItem(k, 2, new QTableWidgetItem(direction)); - k++; - } + ptwgt->setItem (k, 2, new QTableWidgetItem (direction)); + k++; + } - lst = g_list_next(lst); - } + lst = g_list_next (lst); + } - qulonglong v((qulonglong)element); - ptwgt -> setProperty("element", v); + qulonglong v ((qulonglong) element); + ptwgt->setProperty ("element", v); - connect(ptwgt, SIGNAL(cellActivated(int, int)), SLOT(addRequestPad(int, int))); + connect(ptwgt, SIGNAL(cellActivated(int, int)), SLOT(addRequestPad(int, int))); - ptwgt -> setAttribute(Qt::WA_QuitOnClose, false); - ptwgt -> show(); + ptwgt->setAttribute (Qt::WA_QuitOnClose, false); + ptwgt->show (); } -void GraphDisplay::addRequestPad(int row, int collumn) +void +GraphDisplay::addRequestPad (int row, int collumn) { - QTableWidget *ptwgt = dynamic_cast (QObject::sender()); + QTableWidget *ptwgt = dynamic_cast (QObject::sender ()); - qulonglong v = ptwgt -> property("element").toULongLong(); - GstElement *element = (GstElement *) v; - GstElementClass *klass = GST_ELEMENT_GET_CLASS(element); + qulonglong v = ptwgt->property ("element").toULongLong (); + GstElement *element = (GstElement *) v; + GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); - GstPadTemplate *templ = gst_element_class_get_pad_template(klass, ptwgt -> itemAt(row, 0) -> text().toStdString().c_str()); + GstPadTemplate *templ = gst_element_class_get_pad_template ( + klass, ptwgt->itemAt (row, 0)->text ().toStdString ().c_str ()); - gst_element_request_pad(element, templ, NULL, NULL); + gst_element_request_pad (element, templ, NULL, NULL); - gst_object_unref(element); - ptwgt -> close(); + gst_object_unref (element); + ptwgt->close (); - std::vector info = m_pGraph -> GetInfo(); - update(info); + std::vector info = m_pGraph->GetInfo (); + update (info); } -void GraphDisplay::getIdByPosition(const QPoint &pos, std::size_t &elementId, std::size_t &padId) +void +GraphDisplay::getIdByPosition (const QPoint &pos, std::size_t &elementId, + std::size_t &padId) { - std::size_t i=0; - elementId = padId = -1; - for(; i #include - #include "GraphManager.h" #include - - - class GraphDisplay: public QWidget { -Q_OBJECT + Q_OBJECT public: - GraphDisplay(QWidget *parent=0, Qt::WindowFlags f=0); - void update(const std::vector &info); - void paintEvent(QPaintEvent *event); - void mousePressEvent(QMouseEvent *event); - void mouseReleaseEvent(QMouseEvent *event); - void mouseMoveEvent(QMouseEvent *event); + GraphDisplay(QWidget *parent=0, Qt::WindowFlags f=0); + void update(const std::vector &info); + void paintEvent(QPaintEvent *event); + void mousePressEvent(QMouseEvent *event); + void mouseReleaseEvent(QMouseEvent *event); + void mouseMoveEvent(QMouseEvent *event); - void keyPressEvent(QKeyEvent* event); + void keyPressEvent(QKeyEvent* event); - - QSharedPointer m_pGraph; + QSharedPointer m_pGraph; private slots: - void addRequestPad(int row, int collumn); + void addRequestPad(int row, int collumn); private: - enum MoveAction - { - None = 0, - MoveComponent, - MakeConnect, - Select - }; + enum MoveAction + { + None = 0, + MoveComponent, + MakeConnect, + Select + }; - struct MoveInfo - { - MoveInfo(): m_action(None) - { - } + struct MoveInfo + { + MoveInfo(): m_action(None) + { + } - MoveAction m_action; - size_t m_elementId; - size_t m_padId; - QPoint m_position; - QPoint m_startPosition; - }; + MoveAction m_action; + size_t m_elementId; + size_t m_padId; + QPoint m_position; + QPoint m_startPosition; + }; + struct ElementDisplayInfo + { + QRect m_rect; + size_t m_id; + std::string m_name; + bool m_isSelected; + }; - struct ElementDisplayInfo - { - QRect m_rect; - size_t m_id; - std::string m_name; - bool m_isSelected; - }; + void calculatePositions(); + void updateDisplayInfoIds(); + ElementDisplayInfo calculateOnePosition(const ElementInfo &info); + void showContextMenu(QMouseEvent *event); + void showElementProperties(std::size_t id); + void showPadProperties(std::size_t elementId, std::size_t padId); + void renderPad(std::size_t elementId, std::size_t padId, bool capsAny); + void removePlugin(std::size_t id); + void removeSelected(); + void getIdByPosition(const QPoint &pos, std::size_t &elementId, std::size_t &padId); + QPoint getPadPosition(std::size_t elementId, std::size_t padId); + void disconnect(std::size_t elementId, std::size_t padId); + void requestPad(std::size_t elementId); + void connectPlugin(std::size_t elementId, const QString& destElementName); - void calculatePositions(); - void updateDisplayInfoIds(); - ElementDisplayInfo calculateOnePosition(const ElementInfo &info); - void showContextMenu(QMouseEvent *event); - void showElementProperties(std::size_t id); - void showPadProperties(std::size_t elementId, std::size_t padId); - void renderPad(std::size_t elementId, std::size_t padId, bool capsAny); - void removePlugin(std::size_t id); - void removeSelected(); - void getIdByPosition(const QPoint &pos, std::size_t &elementId, std::size_t &padId); - QPoint getPadPosition(std::size_t elementId, std::size_t padId); - void disconnect(std::size_t elementId, std::size_t padId); - void requestPad(std::size_t elementId); - void connectPlugin(std::size_t elementId, const QString& destElementName); + ElementInfo* getElement(std::size_t elementId); + PadInfo* getPad(std::size_t elementId, std::size_t padId); - ElementInfo* getElement(std::size_t elementId); - PadInfo* getPad(std::size_t elementId, std::size_t padId); + std::vector m_info; + std::vector m_displayInfo; - std::vector m_info; - std::vector m_displayInfo; - - MoveInfo m_moveInfo; + MoveInfo m_moveInfo; }; - #endif diff --git a/src/GraphManager.cpp b/src/GraphManager.cpp index 57c8af8..1f5a87d 100644 --- a/src/GraphManager.cpp +++ b/src/GraphManager.cpp @@ -10,524 +10,524 @@ #include "CustomSettings.h" #define MAX_STR_CAPS_SIZE 150 -gchar* get_str_caps_limited(gchar* str) +gchar* +get_str_caps_limited (gchar* str) { gchar* result; - if(strlen(str) > MAX_STR_CAPS_SIZE) { - result = g_strndup(str, MAX_STR_CAPS_SIZE); - for(int i = strlen(result)-1;i > strlen(result)-4 ;i--) - result[i] = '.'; - } else - result = g_strdup(str); + if (strlen (str) > MAX_STR_CAPS_SIZE) { + result = g_strndup (str, MAX_STR_CAPS_SIZE); + for (int i = strlen (result) - 1; i > strlen (result) - 4; i--) + result[i] = '.'; + } + else + result = g_strdup (str); return result; } static void -typefind_have_type_callback (GstElement * typefind, - guint probability, GstCaps * caps, GraphManager * thiz) +typefind_have_type_callback (GstElement * typefind, guint probability, + GstCaps * caps, GraphManager * thiz) { gchar *caps_description = gst_caps_to_string (caps); - qDebug() << "Found caps " << caps_description << " with probability " << probability; - g_free(caps_description); - thiz->Pause(); + qDebug () << "Found caps " << caps_description << " with probability " + << probability; + g_free (caps_description); + thiz->Pause (); } -GraphManager::GraphManager() +GraphManager::GraphManager () { - m_pGraph = gst_pipeline_new ("pipeline"); - m_pluginsList = new PluginsList(); + m_pGraph = gst_pipeline_new ("pipeline"); + m_pluginsList = new PluginsList (); } -GraphManager::~GraphManager() +GraphManager::~GraphManager () { delete m_pluginsList; } -QString GraphManager::getPadCaps(ElementInfo* elementInfo, PadInfo* padInfo, ePadCapsSubset subset, bool afTruncated) +QString +GraphManager::getPadCaps (ElementInfo* elementInfo, PadInfo* padInfo, + ePadCapsSubset subset, bool afTruncated) { - QString padCaps = ""; - if(!elementInfo || !padInfo) - return padCaps; + QString padCaps = ""; + if (!elementInfo || !padInfo) + return padCaps; - GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraph), elementInfo->m_name.c_str()); + GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph), + elementInfo->m_name.c_str ()); - if(!element) - return padCaps; - GstPad *pad = gst_element_get_static_pad(GST_ELEMENT(element), padInfo->m_name.c_str()); - if(!pad) { - gst_object_unref(element); - return padCaps; - } - GstCaps *caps; - switch(subset) - { - case PAD_CAPS_ALLOWED: - caps = gst_pad_get_allowed_caps(pad); - break; - case PAD_CAPS_NEGOCIATED: + if (!element) + return padCaps; + GstPad *pad = gst_element_get_static_pad (GST_ELEMENT (element), + padInfo->m_name.c_str ()); + if (!pad) { + gst_object_unref (element); + return padCaps; + } + GstCaps *caps; + switch (subset) { + case PAD_CAPS_ALLOWED: + caps = gst_pad_get_allowed_caps (pad); + break; + case PAD_CAPS_NEGOCIATED: #if GST_VERSION_MAJOR >= 1 - caps = gst_pad_get_current_caps(pad); + caps = gst_pad_get_current_caps(pad); #else - caps = gst_pad_get_negotiated_caps(pad); + caps = gst_pad_get_negotiated_caps (pad); #endif - break; - case PAD_CAPS_ALL: - default: + break; + case PAD_CAPS_ALL: + default: #if GST_VERSION_MAJOR >= 1 - caps = gst_pad_query_caps(pad, NULL); + caps = gst_pad_query_caps(pad, NULL); #else - caps = gst_pad_get_caps(pad); + caps = gst_pad_get_caps (pad); #endif - } + } #if GST_VERSION_MAJOR >= 1 - caps = gst_pad_query_caps(pad, NULL); + caps = gst_pad_query_caps(pad, NULL); #else - caps = gst_pad_get_caps(pad); + caps = gst_pad_get_caps (pad); #endif - if(caps) { - gchar* str = gst_caps_to_string(caps); - if (afTruncated) { - gchar* str_limited = get_str_caps_limited(str); - g_free(str); - padCaps = str_limited; - g_free(str_limited); - } else { - padCaps = str; - g_free(str); - } + if (caps) { + gchar* str = gst_caps_to_string (caps); + if (afTruncated) { + gchar* str_limited = get_str_caps_limited (str); + g_free (str); + padCaps = str_limited; + g_free (str_limited); + } + else { + padCaps = str; + g_free (str); + } - } - - gst_object_unref(element); - gst_object_unref (pad); - return padCaps; -} - -gchar* GraphManager::AddPlugin(const char *plugin, const char *name) -{ - GstElement *pel = gst_element_factory_make(plugin, name); - if(!pel) - return NULL; - - if(GST_IS_URI_HANDLER(pel)) - { - static const gchar *const *protocols; - protocols = gst_uri_handler_get_protocols(GST_URI_HANDLER(pel)); - - bool isFile = false; - - for(std::size_t i=0; protocols[i] != NULL; i++) - { - if(strcmp("file", protocols[i]) == 0) - { - isFile = true; - break; - } - } - - if(isFile) - { - QString path; - QString dir = CustomSettings::lastIODirectory(); - - if(gst_uri_handler_get_uri_type(GST_URI_HANDLER(pel)) == GST_URI_SRC) - path = QFileDialog::getOpenFileName(NULL, "Open Media Source File...", dir); - else - path = QFileDialog::getSaveFileName(NULL, "Open Sink File...", dir); - - if(!path.isEmpty()) - { - gchar *uri = gst_filename_to_uri(path.toStdString().c_str(), NULL); - if(uri) - { - qDebug() << "Set uri: " << uri; -#if GST_VERSION_MAJOR >= 1 - gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL); -#else - gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri); -#endif - g_free(uri); - - QString dir = QFileInfo(path).absoluteDir().absolutePath(); - CustomSettings::saveLastIODirectory(dir); - } - } - } - else - { - QString uri = QInputDialog::getText(NULL, "Uri...", "Uri:"); - - if(!uri.isEmpty()) - { - qDebug() << "Set uri: " << uri; -#if GST_VERSION_MAJOR >= 1 - gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL); -#else - gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str()); -#endif - } - } - } - - bool res = gst_bin_add(GST_BIN(m_pGraph), pel); - if (res) - gst_element_sync_state_with_parent(pel); - else { - gst_object_unref(pel); - return NULL; - } - - return gst_element_get_name(pel); -} - - -bool GraphManager::RemovePlugin(const char *name) -{ - GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraph), name); - - if(!element) - return false; - - bool res = gst_bin_remove (GST_BIN(m_pGraph), element); - gst_object_unref(element); - - return res; -} - - -bool GraphManager::OpenUri(const char *uri, const char *name) -{ -#if GST_VERSION_MAJOR >= 1 - GstElement *element = gst_element_make_from_uri(GST_URI_SRC, uri, name, NULL); -#else - GstElement *element = gst_element_make_from_uri(GST_URI_SRC, uri, name); -#endif - if(!element) - return false; - - bool res = gst_bin_add(GST_BIN(m_pGraph), element); - if(res) - gst_element_sync_state_with_parent(element); - - return res; -} - -bool GraphManager::Connect(const char *srcElement, const char *srcPad, - const char *dstElement, const char *dstPad) -{ - GstElement *src = gst_bin_get_by_name (GST_BIN(m_pGraph), srcElement); - GstElement *dst = gst_bin_get_by_name (GST_BIN(m_pGraph), dstElement); - - bool res = gst_element_link_pads(src, srcPad, dst, dstPad); - - gboolean seekRes = gst_element_seek_simple(m_pGraph, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, 0); - - gst_object_unref(src); - gst_object_unref(dst); - - return res; -} - -bool GraphManager::Connect(const char *srcElement, const char *dstElement) -{ - GstElement *src = gst_bin_get_by_name (GST_BIN(m_pGraph), srcElement); - GstElement *dst = gst_bin_get_by_name (GST_BIN(m_pGraph), dstElement); - - bool res = gst_element_link(src, dst); - - gboolean seekRes = gst_element_seek_simple(m_pGraph, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, 0); - - /* add a callback to handle have-type signal */ - if (g_str_has_prefix(dstElement,"typefindelement")) { - g_signal_connect (dst, "have-type", - G_CALLBACK (typefind_have_type_callback), - this); - Play(); } - gst_object_unref(src); - gst_object_unref(dst); + gst_object_unref (element); + gst_object_unref (pad); + return padCaps; +} + +gchar* +GraphManager::AddPlugin (const char *plugin, const char *name) +{ + GstElement *pel = gst_element_factory_make (plugin, name); + if (!pel) + return NULL; + + if (GST_IS_URI_HANDLER (pel)) { + static const gchar * const *protocols; + protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (pel)); + + bool isFile = false; + + for (std::size_t i = 0; protocols[i] != NULL; i++) { + if (strcmp ("file", protocols[i]) == 0) { + isFile = true; + break; + } + } + + if (isFile) { + QString path; + QString dir = CustomSettings::lastIODirectory (); + + if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (pel)) == GST_URI_SRC) + path = QFileDialog::getOpenFileName (NULL, "Open Media Source File...", + dir); + else + path = QFileDialog::getSaveFileName (NULL, "Open Sink File...", dir); + + if (!path.isEmpty ()) { + gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), + NULL); + if (uri) { + qDebug () << "Set uri: " << uri; +#if GST_VERSION_MAJOR >= 1 + gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL); +#else + gst_uri_handler_set_uri (GST_URI_HANDLER (pel), uri); +#endif + g_free (uri); + + QString dir = QFileInfo (path).absoluteDir ().absolutePath (); + CustomSettings::saveLastIODirectory (dir); + } + } + } + else { + QString uri = QInputDialog::getText (NULL, "Uri...", "Uri:"); + + if (!uri.isEmpty ()) { + qDebug () << "Set uri: " << uri; +#if GST_VERSION_MAJOR >= 1 + gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL); +#else + gst_uri_handler_set_uri (GST_URI_HANDLER (pel), + uri.toStdString ().c_str ()); +#endif + } + } + } + + bool res = gst_bin_add (GST_BIN (m_pGraph), pel); + if (res) + gst_element_sync_state_with_parent (pel); + else { + gst_object_unref (pel); + return NULL; + } + + return gst_element_get_name (pel); +} + +bool +GraphManager::RemovePlugin (const char *name) +{ + GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph), name); + + if (!element) + return false; + + bool res = gst_bin_remove (GST_BIN (m_pGraph), element); + gst_object_unref (element); return res; } -bool GraphManager::Disconnect(const char *srcElement, const char *srcPad, - const char *dstElement, const char *dstPad) +bool +GraphManager::OpenUri (const char *uri, const char *name) { - GstElement *src = gst_bin_get_by_name (GST_BIN(m_pGraph), srcElement); - GstElement *dst = gst_bin_get_by_name (GST_BIN(m_pGraph), dstElement); - - - gst_element_unlink_pads(src, srcPad, dst, dstPad); - - gst_object_unref(src); - gst_object_unref(dst); - - return true; -} - -std::vector GraphManager::GetInfo() -{ - std::vector res; - - GstIterator *iter; - iter = gst_bin_iterate_elements (GST_BIN (m_pGraph)); - GstElement* element = NULL; - bool done = false; - size_t id = 0; - while (!done) - { #if GST_VERSION_MAJOR >= 1 - GValue value = { 0 }; - switch (gst_iterator_next (iter, &value)) - { - case GST_ITERATOR_OK: - { - element = GST_ELEMENT(g_value_get_object(&value)); + GstElement *element = gst_element_make_from_uri(GST_URI_SRC, uri, name, NULL); #else - switch (gst_iterator_next (iter, (gpointer *)&element)) - { - case GST_ITERATOR_OK: - { + GstElement *element = gst_element_make_from_uri (GST_URI_SRC, uri, name); #endif - ElementInfo elementInfo; - elementInfo.m_id = id; - id++; + if (!element) + return false; - gchar *name = gst_element_get_name(element); - elementInfo.m_name = name; - g_free(name); + bool res = gst_bin_add (GST_BIN (m_pGraph), element); + if (res) + gst_element_sync_state_with_parent (element); - GstElementFactory *pfactory = - gst_element_get_factory(element); + return res; +} - elementInfo.m_pluginName = - gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(pfactory)); +bool +GraphManager::Connect (const char *srcElement, const char *srcPad, + const char *dstElement, const char *dstPad) +{ + GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement); + GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement); - GstIterator *padItr = gst_element_iterate_pads (element); - bool padDone = FALSE; - std::size_t padId = 0; - GstPad *pad; - while (!padDone) - { + bool res = gst_element_link_pads (src, srcPad, dst, dstPad); + + gboolean seekRes = gst_element_seek_simple (m_pGraph, GST_FORMAT_TIME, + GST_SEEK_FLAG_FLUSH, 0); + + gst_object_unref (src); + gst_object_unref (dst); + + return res; +} + +bool +GraphManager::Connect (const char *srcElement, const char *dstElement) +{ + GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement); + GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement); + + bool res = gst_element_link (src, dst); + + gboolean seekRes = gst_element_seek_simple (m_pGraph, GST_FORMAT_TIME, + GST_SEEK_FLAG_FLUSH, 0); + + /* add a callback to handle have-type signal */ + if (g_str_has_prefix (dstElement, "typefindelement")) { + g_signal_connect (dst, "have-type", + G_CALLBACK (typefind_have_type_callback), this); + Play (); + } + + gst_object_unref (src); + gst_object_unref (dst); + + return res; +} + +bool +GraphManager::Disconnect (const char *srcElement, const char *srcPad, + const char *dstElement, const char *dstPad) +{ + GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement); + GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement); + + gst_element_unlink_pads (src, srcPad, dst, dstPad); + + gst_object_unref (src); + gst_object_unref (dst); + + return true; +} + +std::vector +GraphManager::GetInfo () +{ + std::vector res; + + GstIterator *iter; + iter = gst_bin_iterate_elements (GST_BIN (m_pGraph)); + GstElement* element = NULL; + bool done = false; + size_t id = 0; + while (!done) { #if GST_VERSION_MAJOR >= 1 - GValue padVal = { 0 }; - switch (gst_iterator_next (padItr, &padVal)) - { - case GST_ITERATOR_OK: - { - pad = GST_PAD(g_value_get_object(&padVal)); + GValue value = + { 0}; + switch (gst_iterator_next (iter, &value)) + { + case GST_ITERATOR_OK: + { + element = GST_ELEMENT(g_value_get_object(&value)); #else - switch (gst_iterator_next (padItr, (gpointer *)&pad)) - { - case GST_ITERATOR_OK: - { + switch (gst_iterator_next (iter, (gpointer *) &element)) { + case GST_ITERATOR_OK: { #endif - PadInfo padInfo; - padInfo.m_id = padId; + ElementInfo elementInfo; + elementInfo.m_id = id; + id++; - gchar *pad_name = gst_pad_get_name(pad); - padInfo.m_name = pad_name; - g_free(pad_name); + gchar *name = gst_element_get_name (element); + elementInfo.m_name = name; + g_free (name); - GstPadDirection direction = gst_pad_get_direction(pad); - if(direction == GST_PAD_SRC) - padInfo.m_type = PadInfo::Out; - else if(direction == GST_PAD_SINK) - padInfo.m_type = PadInfo::In; - else - padInfo.m_type = PadInfo::None; + GstElementFactory *pfactory = gst_element_get_factory (element); - elementInfo.m_pads.push_back(padInfo); + elementInfo.m_pluginName = gst_plugin_feature_get_name ( + GST_PLUGIN_FEATURE (pfactory)); + + GstIterator *padItr = gst_element_iterate_pads (element); + bool padDone = FALSE; + std::size_t padId = 0; + GstPad *pad; + while (!padDone) { #if GST_VERSION_MAJOR >= 1 - g_value_reset (&padVal); -#endif - break; - } - case GST_ITERATOR_RESYNC: - case GST_ITERATOR_ERROR: - case GST_ITERATOR_DONE: - padDone = TRUE; - break; - }; - padId++; - } -#if GST_VERSION_MAJOR >= 1 - g_value_reset (&value); -#endif - res.push_back(elementInfo); - break; - } - case GST_ITERATOR_DONE: - case GST_ITERATOR_RESYNC: - case GST_ITERATOR_ERROR: - { - done = true; - break; - } - }; - } - - gst_iterator_free (iter); - - for(std::size_t i=0; i= 1 - if(!gst_element_query_position(m_pGraph, fmt, ¤t)) - return 0; + GValue padVal = + { 0}; + switch (gst_iterator_next (padItr, &padVal)) + { + case GST_ITERATOR_OK: + { + pad = GST_PAD(g_value_get_object(&padVal)); #else - if(!gst_element_query_position(m_pGraph, &fmt, ¤t)) - return 0; + switch (gst_iterator_next (padItr, (gpointer *) &pad)) { + case GST_ITERATOR_OK: { #endif + PadInfo padInfo; + padInfo.m_id = padId; + gchar *pad_name = gst_pad_get_name (pad); + padInfo.m_name = pad_name; + g_free (pad_name); + + GstPadDirection direction = gst_pad_get_direction (pad); + if (direction == GST_PAD_SRC) + padInfo.m_type = PadInfo::Out; + else if (direction == GST_PAD_SINK) + padInfo.m_type = PadInfo::In; + else + padInfo.m_type = PadInfo::None; + + elementInfo.m_pads.push_back (padInfo); #if GST_VERSION_MAJOR >= 1 - if(!gst_element_query_duration(m_pGraph, fmt, &duration)) - return 0; -#else - if(!gst_element_query_duration(m_pGraph, &fmt, &duration)) - return 0; + g_value_reset (&padVal); #endif + break; + } + case GST_ITERATOR_RESYNC: + case GST_ITERATOR_ERROR: + case GST_ITERATOR_DONE: + padDone = TRUE; + break; + }; + padId++; + } +#if GST_VERSION_MAJOR >= 1 + g_value_reset (&value); +#endif + res.push_back (elementInfo); + break; + } + case GST_ITERATOR_DONE: + case GST_ITERATOR_RESYNC: + case GST_ITERATOR_ERROR: { + done = true; + break; + } + }; + } - if(duration < 0 || current < 0) - return 0; + gst_iterator_free (iter); - return (double) current / duration; + for (std::size_t i = 0; i < res.size (); i++) { + res[i].m_connections.resize (res[i].m_pads.size ()); + + GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph), + res[i].m_name.c_str ()); + + for (std::size_t j = 0; j < res[i].m_pads.size (); j++) { + res[i].m_connections[j].m_elementId = -1; + res[i].m_connections[j].m_padId = -1; + + GstPad *pad = gst_element_get_static_pad ( + element, res[i].m_pads[j].m_name.c_str ()); + GstPad *peerPad = gst_pad_get_peer (pad); + + if (peerPad) { + GstElement *peerElement = GST_ELEMENT (gst_pad_get_parent (peerPad)); + + gchar *peerName = gst_element_get_name (peerElement); + gchar *peerPadName = gst_pad_get_name (peerPad); + + for (std::size_t k = 0; k < res.size (); k++) { + if (res[k].m_name == peerName) { + for (std::size_t l = 0; l < res[k].m_pads.size (); l++) { + if (res[k].m_pads[l].m_name == peerPadName) { + res[i].m_connections[j].m_elementId = res[k].m_id; + res[i].m_connections[j].m_padId = res[k].m_pads[l].m_id; + break; + } + } + } + } + + g_free (peerName); + g_free (peerPadName); + + gst_object_unref (peerPad); + gst_object_unref (peerElement); + } + + gst_object_unref (pad); + } + gst_object_unref (element); + + } + + return res; } - -bool GraphManager::SetPosition(double pos) +bool +GraphManager::Play () { - GstQuery *query = gst_query_new_seeking(GST_FORMAT_TIME); - GstFormat fmt = GST_FORMAT_TIME; - if(!query) - return false; + GstStateChangeReturn res; + gst_element_set_state (m_pGraph, GST_STATE_PLAYING); - if(!gst_element_query(m_pGraph, query)) - return false; + GstState state; + res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND); - gboolean seekable; - gst_query_parse_seeking(query, NULL, &seekable, NULL, NULL); + if (res != GST_STATE_CHANGE_SUCCESS) { + gst_element_abort_state (m_pGraph); + qDebug () << "state changing to Play was FAILED"; + } - gst_query_unref(query); - - if(!seekable) - return false; - - gint64 duration; - -#if GST_VERSION_MAJOR >= 1 - if(!gst_element_query_duration(m_pGraph, fmt, &duration)) - return 0; -#else - if(!gst_element_query_duration(m_pGraph, &fmt, &duration)) - return 0; -#endif - - if(duration < 0) - return 0; - - gboolean seekRes = gst_element_seek_simple(m_pGraph, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, duration * pos); - - return seekRes; + return state == GST_STATE_PLAYING; } -bool GraphManager::CanConnect(const char *srcName, const char *srcPadName, const char *destName, bool noANY) +bool +GraphManager::Pause () +{ + GstStateChangeReturn res; + + GstState state; + gst_element_set_state (m_pGraph, GST_STATE_PAUSED); + res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND); + if (res != GST_STATE_CHANGE_SUCCESS) { + gst_element_abort_state (m_pGraph); + qDebug () << "state changing to Pause was FAILED"; + } + + return state == GST_STATE_PAUSED; +} + +bool +GraphManager::Stop () +{ + GstStateChangeReturn res = gst_element_set_state (m_pGraph, GST_STATE_READY); + return res == GST_STATE_CHANGE_SUCCESS; +} + +double +GraphManager::GetPosition () +{ + gint64 current, duration; + GstFormat fmt = GST_FORMAT_TIME; +#if GST_VERSION_MAJOR >= 1 + if(!gst_element_query_position(m_pGraph, fmt, ¤t)) + return 0; +#else + if (!gst_element_query_position (m_pGraph, &fmt, ¤t)) + return 0; +#endif + +#if GST_VERSION_MAJOR >= 1 + if(!gst_element_query_duration(m_pGraph, fmt, &duration)) + return 0; +#else + if (!gst_element_query_duration (m_pGraph, &fmt, &duration)) + return 0; +#endif + + if (duration < 0 || current < 0) + return 0; + + return (double) current / duration; +} + +bool +GraphManager::SetPosition (double pos) +{ + GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME); + GstFormat fmt = GST_FORMAT_TIME; + if (!query) + return false; + + if (!gst_element_query (m_pGraph, query)) + return false; + + gboolean seekable; + gst_query_parse_seeking (query, NULL, &seekable, NULL, NULL); + + gst_query_unref (query); + + if (!seekable) + return false; + + gint64 duration; + +#if GST_VERSION_MAJOR >= 1 + if(!gst_element_query_duration(m_pGraph, fmt, &duration)) + return 0; +#else + if (!gst_element_query_duration (m_pGraph, &fmt, &duration)) + return 0; +#endif + + if (duration < 0) + return 0; + + gboolean seekRes = gst_element_seek_simple (m_pGraph, GST_FORMAT_TIME, + GST_SEEK_FLAG_FLUSH, + duration * pos); + + return seekRes; +} + +bool +GraphManager::CanConnect (const char *srcName, const char *srcPadName, + const char *destName, bool noANY) { bool ret = false; bool added = false; @@ -537,73 +537,74 @@ bool GraphManager::CanConnect(const char *srcName, const char *srcPadName, const GstCaps* srcCaps = NULL; GstElementFactory *destFactory = NULL; - src = gst_bin_get_by_name (GST_BIN(m_pGraph), srcName); + src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcName); if (!src) { - qDebug() << "Unable to get the src element: " << srcName; + qDebug () << "Unable to get the src element: " << srcName; goto done; } - srcPad = gst_element_get_static_pad(src, srcPadName); + srcPad = gst_element_get_static_pad (src, srcPadName); if (!srcPad) { - qDebug() << "Unable to get the src pad"; - goto done; - } - - srcCaps = gst_pad_get_current_caps(srcPad); - if (!srcCaps) { - qDebug() << "Unable to get the current caps for pad:" << srcPadName; - srcCaps =gst_pad_get_pad_template_caps(srcPad); - if (!srcCaps) { - qDebug() << "Unable to get the template caps for pad:" << srcPadName; - goto done; - } - } - - dest = gst_element_factory_make(destName, NULL); - if (!dest) { - qDebug() << "Unable to get the dest element: " << destName; - goto done; - } - - destFactory = gst_element_get_factory(dest); - if (!destFactory) { - qDebug() << "Unable to get the dest factory"; - goto done; - } - if (noANY && gst_element_factory_can_sink_any_caps(destFactory, srcCaps)) { - qDebug() << "The dest element " << destName << " can sink any caps"; + qDebug () << "Unable to get the src pad"; goto done; } - if(!gst_element_factory_can_sink_all_caps(destFactory, srcCaps)) { - gchar* caps_string = gst_caps_to_string(srcCaps); - qDebug() << "The dest element " << destName << " can not sink this caps: " << caps_string; + srcCaps = gst_pad_get_current_caps (srcPad); + if (!srcCaps) { + qDebug () << "Unable to get the current caps for pad:" << srcPadName; + srcCaps = gst_pad_get_pad_template_caps (srcPad); + if (!srcCaps) { + qDebug () << "Unable to get the template caps for pad:" << srcPadName; + goto done; + } + } + + dest = gst_element_factory_make (destName, NULL); + if (!dest) { + qDebug () << "Unable to get the dest element: " << destName; + goto done; + } + + destFactory = gst_element_get_factory (dest); + if (!destFactory) { + qDebug () << "Unable to get the dest factory"; + goto done; + } + if (noANY && gst_element_factory_can_sink_any_caps (destFactory, srcCaps)) { + qDebug () << "The dest element " << destName << " can sink any caps"; + goto done; + } + + if (!gst_element_factory_can_sink_all_caps (destFactory, srcCaps)) { + gchar* caps_string = gst_caps_to_string (srcCaps); + qDebug () << "The dest element " << destName << " can not sink this caps: " + << caps_string; g_free (caps_string); goto done; } - added = gst_bin_add(GST_BIN(m_pGraph), dest); + added = gst_bin_add (GST_BIN (m_pGraph), dest); if (!added) { - qDebug() << "Unable to add element to the bin"; - goto done; + qDebug () << "Unable to add element to the bin"; + goto done; } - ret = gst_element_link(src,dest); + ret = gst_element_link (src, dest); if (ret) { - qDebug() << "Can link elements src " << GST_OBJECT_NAME(src) << " with dest " << GST_OBJECT_NAME(dest); - gst_element_unlink(src,dest); + qDebug () << "Can link elements src " << GST_OBJECT_NAME (src) + << " with dest " << GST_OBJECT_NAME (dest); + gst_element_unlink (src, dest); } -done: - if (added) { - gst_bin_remove(GST_BIN(m_pGraph), dest); + done: if (added) { + gst_bin_remove (GST_BIN (m_pGraph), dest); dest = NULL; } if (src) - gst_object_unref(src); + gst_object_unref (src); if (srcPad) - gst_object_unref(srcPad); + gst_object_unref (srcPad); if (dest) - gst_object_unref(dest); + gst_object_unref (dest); return ret; } diff --git a/src/GraphManager.h b/src/GraphManager.h index cf4c53b..6f9ac33 100644 --- a/src/GraphManager.h +++ b/src/GraphManager.h @@ -81,6 +81,7 @@ struct ElementInfo class GraphManager { + public: GraphManager(); ~GraphManager(); @@ -111,8 +112,6 @@ public: GstElement *m_pGraph; PluginsList *m_pluginsList; - }; - #endif diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 13e9317..31a67b4 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -33,345 +33,356 @@ #include -MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags): - QMainWindow(parent, flags) - ,m_pGraph(new GraphManager) +MainWindow::MainWindow (QWidget *parent, Qt::WindowFlags flags) +: QMainWindow (parent, flags), +m_pGraph (new GraphManager) { - QToolBar *ptb = addToolBar("Menu"); + QToolBar *ptb = addToolBar ("Menu"); - QAction *pactAdd = ptb -> addAction("Add..."); - pactAdd -> setShortcut(QKeySequence("Ctrl+F")); - connect(pactAdd, SIGNAL(triggered()), SLOT(AddPlugin())); + QAction *pactAdd = ptb->addAction ("Add..."); + pactAdd->setShortcut (QKeySequence ("Ctrl+F")); + connect (pactAdd, SIGNAL (triggered ()), SLOT (AddPlugin ())); + QAction *pactOpenFile = ptb->addAction ("Open Media File..."); + connect (pactOpenFile, SIGNAL (triggered ()), SLOT (OpenMediaFile ())); - QAction *pactOpenFile = ptb -> addAction("Open Media File..."); - connect(pactOpenFile, SIGNAL(triggered()), SLOT(OpenMediaFile())); + ptb->addSeparator (); - ptb -> addSeparator(); + QPixmap pxPlay (24, 24); + pxPlay.fill (QColor (0, 0, 0, 0)); + QPainter pntrPlay (&pxPlay); + pntrPlay.setPen (Qt::darkGreen); + pntrPlay.setBrush (QBrush (Qt::darkGreen)); - QPixmap pxPlay(24, 24); - pxPlay.fill(QColor(0, 0, 0, 0)); - QPainter pntrPlay(&pxPlay); - pntrPlay.setPen(Qt::darkGreen); - pntrPlay.setBrush(QBrush(Qt::darkGreen)); + QPolygon polygon (3); + polygon.setPoint (0, 4, 4); + polygon.setPoint (1, 4, 20); + polygon.setPoint (2, 20, 12); - QPolygon polygon(3); - polygon.setPoint(0, 4, 4); - polygon.setPoint(1, 4, 20); - polygon.setPoint(2, 20, 12); + pntrPlay.drawPolygon (polygon, Qt::WindingFill); - pntrPlay.drawPolygon(polygon, Qt::WindingFill); - - QAction *pactPlay = ptb -> addAction(QIcon(pxPlay), "Play"); - connect(pactPlay, SIGNAL(triggered()), SLOT(Play())); + QAction *pactPlay = ptb->addAction (QIcon (pxPlay), "Play"); + connect (pactPlay, SIGNAL (triggered ()), SLOT (Play ())); - QPixmap pxPause(24, 24); - pxPause.fill(QColor(0, 0, 0, 0)); - QPainter pntrPause(&pxPause); - pntrPause.setPen(Qt::darkGray); - pntrPause.setBrush(QBrush(Qt::darkGray)); + QPixmap pxPause (24, 24); + pxPause.fill (QColor (0, 0, 0, 0)); + QPainter pntrPause (&pxPause); + pntrPause.setPen (Qt::darkGray); + pntrPause.setBrush (QBrush (Qt::darkGray)); - pntrPause.drawRect(8, 4, 3, 16); - pntrPause.drawRect(13, 4, 3, 16); + pntrPause.drawRect (8, 4, 3, 16); + pntrPause.drawRect (13, 4, 3, 16); - QAction *pactPause = ptb -> addAction(QIcon(pxPause), "Pause"); - connect(pactPause, SIGNAL(triggered()), SLOT(Pause())); + QAction *pactPause = ptb->addAction (QIcon (pxPause), "Pause"); + connect (pactPause, SIGNAL (triggered ()), SLOT (Pause ())); - QPixmap pxStop(24, 24); - pxStop.fill(QColor(0, 0, 0, 0)); - QPainter pntrStop(&pxStop); - pntrStop.setPen(Qt::darkRed); - pntrStop.setBrush(QBrush(Qt::darkRed)); + QPixmap pxStop (24, 24); + pxStop.fill (QColor (0, 0, 0, 0)); + QPainter pntrStop (&pxStop); + pntrStop.setPen (Qt::darkRed); + pntrStop.setBrush (QBrush (Qt::darkRed)); - pntrStop.drawRect(6, 6, 12, 12); + pntrStop.drawRect (6, 6, 12, 12); - QAction *pactStop = ptb -> addAction(QIcon(pxStop), "Stop"); - connect(pactStop, SIGNAL(triggered()), SLOT(Stop())); + QAction *pactStop = ptb->addAction (QIcon (pxStop), "Stop"); + connect (pactStop, SIGNAL (triggered ()), SLOT (Stop ())); - QPixmap pxFulsh(24, 24); - pxFulsh.fill(QColor(0, 0, 0, 0)); - QPainter pntrFlush(&pxFulsh); - pntrFlush.setPen(Qt::darkGreen); - pntrFlush.setBrush(QBrush(Qt::darkGreen)); + QPixmap pxFulsh (24, 24); + pxFulsh.fill (QColor (0, 0, 0, 0)); + QPainter pntrFlush (&pxFulsh); + pntrFlush.setPen (Qt::darkGreen); + pntrFlush.setBrush (QBrush (Qt::darkGreen)); - pntrFlush.drawRect(3, 4, 3, 16); + pntrFlush.drawRect (3, 4, 3, 16); - polygon = QPolygon(3); - polygon.setPoint(0, 9, 4); - polygon.setPoint(1, 9, 20); - polygon.setPoint(2, 21, 12); + polygon = QPolygon (3); + polygon.setPoint (0, 9, 4); + polygon.setPoint (1, 9, 20); + polygon.setPoint (2, 21, 12); - pntrFlush.drawPolygon(polygon, Qt::WindingFill); + pntrFlush.drawPolygon (polygon, Qt::WindingFill); - QAction *pactFlush = ptb -> addAction(QIcon(pxFulsh), "Flush"); - connect(pactFlush, SIGNAL(triggered()), SLOT(Flush())); + QAction *pactFlush = ptb->addAction (QIcon (pxFulsh), "Flush"); + connect (pactFlush, SIGNAL (triggered ()), SLOT (Flush ())); - QAction *pactClear = ptb -> addAction("Clear"); - connect(pactClear, SIGNAL(triggered()), SLOT(ClearGraph())); - ptb -> addSeparator(); + QAction *pactClear = ptb->addAction ("Clear"); + connect (pactClear, SIGNAL (triggered ()), SLOT (ClearGraph ())); + ptb->addSeparator (); - m_pslider = new SeekSlider(); - m_pslider -> setOrientation(Qt::Horizontal); - m_pslider -> setRange(0, 10000); - m_pslider -> setTracking(false); + m_pslider = new SeekSlider (); + m_pslider->setOrientation (Qt::Horizontal); + m_pslider->setRange (0, 10000); + m_pslider->setTracking (false); - connect(m_pslider, SIGNAL(valueChanged(int)), SLOT(Seek(int))); - ptb -> addWidget(m_pslider); + connect(m_pslider, SIGNAL(valueChanged(int)), SLOT(Seek(int))); + ptb->addWidget (m_pslider); - QMenu *pmenu = menuBar() -> addMenu("&File"); + QMenu *pmenu = menuBar ()->addMenu ("&File"); - QAction *pactOpen = pmenu -> addAction ("Open...", this, SLOT(Open()), QKeySequence::Open); - addAction (pactOpen); - - QAction *pactOpenMediaFile = pmenu -> addAction ("Open Media File...", this, SLOT(OpenMediaFile()), QKeySequence::Open); - addAction (pactOpenMediaFile); + QAction *pactOpen = pmenu->addAction ("Open...", this, SLOT (Open ()), + QKeySequence::Open); + addAction (pactOpen); - QAction *pactSave = pmenu -> addAction ("Save", this, SLOT(Save()), QKeySequence::Save); - addAction (pactSave); + QAction *pactOpenMediaFile = pmenu->addAction ("Open Media File...", this, + SLOT (OpenMediaFile ()), + QKeySequence::Open); + addAction (pactOpenMediaFile); - QAction *pactSaveAs = pmenu -> addAction ("Save As...", this, SLOT(SaveAs()), QKeySequence::SaveAs); - addAction (pactSaveAs); + QAction *pactSave = pmenu->addAction ("Save", this, SLOT (Save ()), + QKeySequence::Save); + addAction (pactSave); - pmenu -> addSeparator(); - pmenu -> addAction("Exit", this, SLOT(close())); + QAction *pactSaveAs = pmenu->addAction ("Save As...", this, SLOT (SaveAs ()), + QKeySequence::SaveAs); + addAction (pactSaveAs); + pmenu->addSeparator (); + pmenu->addAction ("Exit", this, SLOT (close ())); - pmenu = menuBar() -> addMenu("&Graph"); + pmenu = menuBar ()->addMenu ("&Graph"); - pmenu -> addAction(pactAdd); - pmenu -> addAction(pactOpenMediaFile); - pmenu -> addAction ("Open Media Uri...", this, SLOT(OpenMediaUri())); - pmenu -> addSeparator(); - pmenu -> addAction(pactPlay); - pmenu -> addAction(pactPause); - pmenu -> addAction(pactStop); - pmenu -> addAction(pactFlush); - pmenu -> addSeparator(); - pmenu -> addAction(pactClear); + pmenu->addAction (pactAdd); + pmenu->addAction (pactOpenMediaFile); + pmenu->addAction ("Open Media Uri...", this, SLOT (OpenMediaUri ())); + pmenu->addSeparator (); + pmenu->addAction (pactPlay); + pmenu->addAction (pactPause); + pmenu->addAction (pactStop); + pmenu->addAction (pactFlush); + pmenu->addSeparator (); + pmenu->addAction (pactClear); + pmenu = menuBar ()->addMenu ("&Help"); - pmenu = menuBar() -> addMenu("&Help"); + pmenu->addAction ("About pipeviz...", this, SLOT (About ())); - pmenu -> addAction ("About pipeviz...", this, SLOT(About())); + m_pGraphDisplay = new GraphDisplay; - - m_pGraphDisplay = new GraphDisplay; - - QScrollArea *pscroll = new QScrollArea; - pscroll -> setWidget(m_pGraphDisplay); - pscroll -> setWidgetResizable(false); - m_pGraphDisplay -> resize(10000, 10000); - m_pGraphDisplay -> m_pGraph = m_pGraph; - setCentralWidget(pscroll); - m_pstatusBar = new QStatusBar; - setStatusBar(m_pstatusBar); - m_pluginListDlg = new PluginsListDialog(m_pGraph->getPluginsList(), this); - m_pluginListDlg->setModal(false); - restoreGeometry(CustomSettings::mainWindowGeometry()); - startTimer(100); + QScrollArea *pscroll = new QScrollArea; + pscroll->setWidget (m_pGraphDisplay); + pscroll->setWidgetResizable (false); + m_pGraphDisplay->resize (10000, 10000); + m_pGraphDisplay->m_pGraph = m_pGraph; + setCentralWidget (pscroll); + m_pstatusBar = new QStatusBar; + setStatusBar (m_pstatusBar); + m_pluginListDlg = new PluginsListDialog (m_pGraph->getPluginsList (), this); + m_pluginListDlg->setModal (false); + restoreGeometry (CustomSettings::mainWindowGeometry ()); + startTimer (100); } -MainWindow::~MainWindow() +MainWindow::~MainWindow () { - CustomSettings::saveMainWindowGeometry(saveGeometry()); - delete m_pluginListDlg; + CustomSettings::saveMainWindowGeometry (saveGeometry ()); + delete m_pluginListDlg; } -void MainWindow::AddPlugin() +void +MainWindow::AddPlugin () { - m_pluginListDlg->setGraph(m_pGraph.data()); - m_pluginListDlg->show(); - std::vector info = m_pGraph -> GetInfo(); - m_pGraphDisplay -> update(info); + m_pluginListDlg->setGraph (m_pGraph.data ()); + m_pluginListDlg->show (); + std::vector info = m_pGraph->GetInfo (); + m_pGraphDisplay->update (info); } -void MainWindow::OpenMediaFile() +void +MainWindow::OpenMediaFile () { - QString dir = CustomSettings::lastIODirectory(); + QString dir = CustomSettings::lastIODirectory (); - QString path = QFileDialog::getOpenFileName(this, "Open File...", dir); - if(!path.isEmpty()) - { - gchar *uri = gst_filename_to_uri(path.toStdString().c_str(), NULL); - if(uri) - { - qDebug() << "Open Source file: " << path; + QString path = QFileDialog::getOpenFileName (this, "Open File...", dir); + if (!path.isEmpty ()) { + gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL); + if (uri) { + qDebug () << "Open Source file: " << path; - m_pGraph -> OpenUri(uri, NULL); - g_free(uri); + m_pGraph->OpenUri (uri, NULL); + g_free (uri); - std::vector info = m_pGraph -> GetInfo(); - m_pGraphDisplay -> update(info); + std::vector info = m_pGraph->GetInfo (); + m_pGraphDisplay->update (info); - QString dir = QFileInfo(path).absoluteDir().absolutePath(); - CustomSettings::saveLastIODirectory(dir); - } - } + QString dir = QFileInfo (path).absoluteDir ().absolutePath (); + CustomSettings::saveLastIODirectory (dir); + } + } } - -void MainWindow::OpenMediaUri() +void +MainWindow::OpenMediaUri () { - QString uri = QInputDialog::getText(this, "Open Uri...", "Uri:"); + QString uri = QInputDialog::getText (this, "Open Uri...", "Uri:"); - if(!uri.isEmpty()) - { - qDebug() << "Open uri: " << uri; - m_pGraph -> OpenUri(uri.toStdString().c_str(), NULL); + if (!uri.isEmpty ()) { + qDebug () << "Open uri: " << uri; + m_pGraph->OpenUri (uri.toStdString ().c_str (), NULL); - std::vector info = m_pGraph -> GetInfo(); - m_pGraphDisplay -> update(info); - } + std::vector info = m_pGraph->GetInfo (); + m_pGraphDisplay->update (info); + } } -void MainWindow::Play() +void +MainWindow::Play () { - qDebug() << "Play"; - m_pGraph -> Play(); + qDebug () << "Play"; + m_pGraph->Play (); } -void MainWindow::Pause() +void +MainWindow::Pause () { - qDebug() << "Pause"; - m_pGraph -> Pause(); + qDebug () << "Pause"; + m_pGraph->Pause (); } -void MainWindow::Stop() +void +MainWindow::Stop () { - qDebug() << "Stop"; - m_pGraph -> Stop(); + qDebug () << "Stop"; + m_pGraph->Stop (); } -void MainWindow::Flush() +void +MainWindow::Flush () { - qDebug() << "Flush"; + qDebug () << "Flush"; - if(m_pGraph -> m_pGraph) - { - gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_start()); + if (m_pGraph->m_pGraph) { + gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph), + gst_event_new_flush_start ()); #if GST_VERSION_MAJOR >= 1 - gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_stop(true)); + gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_stop(true)); #else - gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_stop()); + gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph), + gst_event_new_flush_stop ()); #endif - } + } } -void MainWindow::ClearGraph() +void +MainWindow::ClearGraph () { - qDebug() << "ClearGraph"; - PipelineIE::Clear(m_pGraph); + qDebug () << "ClearGraph"; + PipelineIE::Clear (m_pGraph); } -void MainWindow::Seek(int val) +void +MainWindow::Seek (int val) { - if(m_pGraph -> SetPosition((double)(val) / m_pslider -> maximum())) - qDebug() << "Seek to" << val; - else - qDebug() << "Seek to" << val << "was FAILED"; + if (m_pGraph->SetPosition ((double) (val) / m_pslider->maximum ())) + qDebug () << "Seek to" << val; + else + qDebug () << "Seek to" << val << "was FAILED"; } -void MainWindow::timerEvent(QTimerEvent *) +void +MainWindow::timerEvent (QTimerEvent *) { - GstState state; - GstStateChangeReturn res = gst_element_get_state (m_pGraph -> m_pGraph, &state, NULL, GST_MSECOND); + GstState state; + GstStateChangeReturn res = gst_element_get_state (m_pGraph->m_pGraph, &state, + NULL, + GST_MSECOND); - if(res == GST_STATE_CHANGE_SUCCESS) - { - QString str; - switch(state) - { - case GST_STATE_VOID_PENDING: - str = "Pending"; - break; - case GST_STATE_NULL: - str = "Null"; - break; - case GST_STATE_READY: - str = "Ready"; - break; - case GST_STATE_PAUSED: - str = "Paused"; - break; - case GST_STATE_PLAYING: - str = "Playing"; - break; - }; + if (res == GST_STATE_CHANGE_SUCCESS) { + QString str; + switch (state) { + case GST_STATE_VOID_PENDING: + str = "Pending"; + break; + case GST_STATE_NULL: + str = "Null"; + break; + case GST_STATE_READY: + str = "Ready"; + break; + case GST_STATE_PAUSED: + str = "Paused"; + break; + case GST_STATE_PLAYING: + str = "Playing"; + break; + }; - m_pstatusBar -> showMessage(str); - } - else - { - m_pstatusBar -> showMessage(QString(gst_element_state_change_return_get_name(res))); - } + m_pstatusBar->showMessage (str); + } + else { + m_pstatusBar->showMessage ( + QString (gst_element_state_change_return_get_name (res))); + } - double pos = m_pGraph -> GetPosition(); + double pos = m_pGraph->GetPosition (); - if(m_pslider -> value() != (int)(m_pslider -> maximum() * pos)) - m_pslider -> setSliderPosition(m_pslider -> maximum() * pos); + if (m_pslider->value () != (int) (m_pslider->maximum () * pos)) + m_pslider->setSliderPosition (m_pslider->maximum () * pos); - - m_pGraphDisplay -> update(m_pGraph -> GetInfo()); + m_pGraphDisplay->update (m_pGraph->GetInfo ()); } -void MainWindow::Save() +void +MainWindow::Save () { - if(m_fileName.isEmpty()) - SaveAs(); - else { - QFileInfo fileInfo(m_fileName); - if (fileInfo.completeSuffix().isEmpty() || fileInfo.completeSuffix() != "gpi") - m_fileName = m_fileName + ".gpi"; + if (m_fileName.isEmpty ()) + SaveAs (); + else { + QFileInfo fileInfo (m_fileName); + if (fileInfo.completeSuffix ().isEmpty () + || fileInfo.completeSuffix () != "gpi") + m_fileName = m_fileName + ".gpi"; + PipelineIE::Export (m_pGraph, m_fileName); - PipelineIE::Export(m_pGraph, m_fileName); - - } + } } -void MainWindow::SaveAs() +void +MainWindow::SaveAs () { - QString dir = CustomSettings::lastIODirectory(); + QString dir = CustomSettings::lastIODirectory (); - QString path = QFileDialog::getSaveFileName(this, "Save As...", dir, tr("*.gpi")); + QString path = QFileDialog::getSaveFileName (this, "Save As...", dir, + tr ("*.gpi")); - if(!path.isEmpty()) - { - m_fileName = path; - Save(); + if (!path.isEmpty ()) { + m_fileName = path; + Save (); - QString dir = QFileInfo(path).absoluteDir().absolutePath(); - CustomSettings::saveLastIODirectory(dir); - } + QString dir = QFileInfo (path).absoluteDir ().absolutePath (); + CustomSettings::saveLastIODirectory (dir); + } } -void MainWindow::Open() +void +MainWindow::Open () { - QString dir = CustomSettings::lastIODirectory(); + QString dir = CustomSettings::lastIODirectory (); - QString path = QFileDialog::getOpenFileName(this, "Open...", dir, tr("GPI (*.gpi *.xpm);;All files (*.*)")); + QString path = QFileDialog::getOpenFileName ( + this, "Open...", dir, tr ("GPI (*.gpi *.xpm);;All files (*.*)")); - if(!path.isEmpty()) - { - if(PipelineIE::Import(m_pGraph, path)) - m_fileName = path; + if (!path.isEmpty ()) { + if (PipelineIE::Import (m_pGraph, path)) + m_fileName = path; - QString dir = QFileInfo(path).absoluteDir().absolutePath(); - CustomSettings::saveLastIODirectory(dir); - } + QString dir = QFileInfo (path).absoluteDir ().absolutePath (); + CustomSettings::saveLastIODirectory (dir); + } } -void MainWindow::About() +void +MainWindow::About () { - QString message; - message = "
pipeviz

"; - message = "
virinext@gmail.com

"; - message += QString("
Version: ") + VERSION_STR + "

"; - message += "
GUI Based on Qt
"; - message += "
using "; - message += gst_version_string(); - message += "
"; + QString message; + message = "
pipeviz

"; + message = "
virinext@gmail.com

"; + message += QString ("
Version: ") + VERSION_STR + "

"; + message += "
GUI Based on Qt
"; + message += "
using "; + message += gst_version_string (); + message += "
"; - QMessageBox::about(this, "About", message); + QMessageBox::about (this, "About", message); } diff --git a/src/MainWindow.h b/src/MainWindow.h index 8c4ada2..bcf314a 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -19,41 +19,40 @@ class PluginsListDialog; class MainWindow: public QMainWindow { - Q_OBJECT - public: - MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0); - ~MainWindow(); + Q_OBJECT +public: + MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0); + ~MainWindow(); - protected: - void timerEvent(QTimerEvent *); +protected: + void timerEvent(QTimerEvent *); - private slots: - void AddPlugin(); - void OpenMediaFile(); - void OpenMediaUri(); - void Play(); - void Pause(); - void Stop(); - void Flush(); - void Seek(int); +private slots: + void AddPlugin(); + void OpenMediaFile(); + void OpenMediaUri(); + void Play(); + void Pause(); + void Stop(); + void Flush(); + void Seek(int); - void Save(); - void SaveAs(); - void Open(); + void Save(); + void SaveAs(); + void Open(); - void ClearGraph(); - void About(); + void ClearGraph(); + void About(); - private: - QSharedPointer m_pGraph; - GraphDisplay *m_pGraphDisplay; +private: + QSharedPointer m_pGraph; + GraphDisplay *m_pGraphDisplay; - QStatusBar *m_pstatusBar; - QSlider *m_pslider; + QStatusBar *m_pstatusBar; + QSlider *m_pslider; - QString m_fileName; - PluginsListDialog *m_pluginListDlg; + QString m_fileName; + PluginsListDialog *m_pluginListDlg; }; - #endif diff --git a/src/PadProperties.cpp b/src/PadProperties.cpp index 666cb95..a207565 100644 --- a/src/PadProperties.cpp +++ b/src/PadProperties.cpp @@ -8,96 +8,99 @@ #include -PadProperties::PadProperties(QSharedPointer pGraphManager, const char *elementName, const char *padName, - QWidget *parent, Qt::WindowFlags flags): -QWidget(parent, flags) +PadProperties::PadProperties (QSharedPointer pGraphManager, + const char *elementName, const char *padName, + QWidget *parent, Qt::WindowFlags flags) +: QWidget (parent, flags) { - setWindowTitle(QString(elementName) + "::" + padName + " properties"); - GstElement *element = gst_bin_get_by_name (GST_BIN(pGraphManager -> m_pGraph), elementName); + setWindowTitle (QString (elementName) + "::" + padName + " properties"); + GstElement *element = gst_bin_get_by_name (GST_BIN (pGraphManager->m_pGraph), + elementName); - if(!element) - return; + if (!element) + return; - GstPad *pad = gst_element_get_static_pad(GST_ELEMENT(element), padName); + GstPad *pad = gst_element_get_static_pad (GST_ELEMENT (element), padName); - QGridLayout *play = new QGridLayout; + QGridLayout *play = new QGridLayout; - play -> addWidget(new QLabel("Name"), 0, 0); + play->addWidget (new QLabel ("Name"), 0, 0); - QLabel *plbl = new QLabel(padName); - plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); - play -> addWidget(plbl, 0, 1); + QLabel *plbl = new QLabel (padName); + plbl->setTextInteractionFlags ( + Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); + play->addWidget (plbl, 0, 1); - play -> addWidget(new QLabel("All caps:"), 1, 0); + play->addWidget (new QLabel ("All caps:"), 1, 0); #if GST_VERSION_MAJOR >= 1 - GstCaps *caps = gst_pad_query_caps(pad, NULL); + GstCaps *caps = gst_pad_query_caps(pad, NULL); #else - GstCaps *caps = gst_pad_get_caps(pad); + GstCaps *caps = gst_pad_get_caps (pad); #endif - gchar *str; - gchar *noSpecified = (gchar *)"not specified"; - if(caps) - str = gst_caps_to_string(caps); - else - str = noSpecified; + gchar *str; + gchar *noSpecified = (gchar *) "not specified"; + if (caps) + str = gst_caps_to_string (caps); + else + str = noSpecified; - plbl = new QLabel(QString(str)); - plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); - play -> addWidget(plbl, 1, 1); - if(caps) - { - g_free(str); - gst_caps_unref(caps); - } + plbl = new QLabel (QString (str)); + plbl->setTextInteractionFlags ( + Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); + play->addWidget (plbl, 1, 1); + if (caps) { + g_free (str); + gst_caps_unref (caps); + } - play -> addWidget(new QLabel("Allowed caps:"), 2, 0); - caps = gst_pad_get_allowed_caps(pad); - str = NULL; - if(caps) - str = gst_caps_to_string(caps); - else - str = noSpecified; + play->addWidget (new QLabel ("Allowed caps:"), 2, 0); + caps = gst_pad_get_allowed_caps (pad); + str = NULL; + if (caps) + str = gst_caps_to_string (caps); + else + str = noSpecified; - plbl = new QLabel(QString(str)); - plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); - play -> addWidget(plbl, 2, 1); - if(caps) - { - g_free(str); - gst_caps_unref(caps); - } + plbl = new QLabel (QString (str)); + plbl->setTextInteractionFlags ( + Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); + play->addWidget (plbl, 2, 1); + if (caps) { + g_free (str); + gst_caps_unref (caps); + } - play -> addWidget(new QLabel("Current caps"), 3, 0); + play->addWidget (new QLabel ("Current caps"), 3, 0); #if GST_VERSION_MAJOR >= 1 - caps = gst_pad_get_current_caps(pad); + caps = gst_pad_get_current_caps(pad); #else - caps = gst_pad_get_negotiated_caps(pad); + caps = gst_pad_get_negotiated_caps (pad); #endif - str = NULL; - if(caps) - str = gst_caps_to_string(caps); - else - str = noSpecified; + str = NULL; + if (caps) + str = gst_caps_to_string (caps); + else + str = noSpecified; - plbl = new QLabel(QString(str)); - plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); - play -> addWidget(plbl, 3, 1); - if(caps) - { - g_free(str); - gst_caps_unref(caps); - } + plbl = new QLabel (QString (str)); + plbl->setTextInteractionFlags ( + Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); + play->addWidget (plbl, 3, 1); + if (caps) { + g_free (str); + gst_caps_unref (caps); + } - gst_object_unref(element); - gst_object_unref (pad); + gst_object_unref (element); + gst_object_unref (pad); - QVBoxLayout *pvblay = new QVBoxLayout; - QWidget *pwgt = new QWidget(this); - pwgt -> setLayout(play); - QScrollArea *pscroll = new QScrollArea(this); - pscroll -> setWidget(pwgt); + QVBoxLayout *pvblay = new QVBoxLayout; + QWidget *pwgt = new QWidget (this); + pwgt->setLayout (play); + QScrollArea *pscroll = new QScrollArea (this); + pscroll->setWidget (pwgt); - pvblay -> addWidget(pscroll); + pvblay->addWidget (pscroll); - setLayout(pvblay); + setLayout (pvblay); } diff --git a/src/PadProperties.h b/src/PadProperties.h index a0d08cc..df25139 100644 --- a/src/PadProperties.h +++ b/src/PadProperties.h @@ -9,9 +9,8 @@ class PadProperties: public QWidget { public: - PadProperties(QSharedPointer pGraphManager, const char *element, const char *pad - , QWidget *parent = 0, Qt::WindowFlags flags = 0); + PadProperties(QSharedPointer pGraphManager, const char *element, const char *pad + , QWidget *parent = 0, Qt::WindowFlags flags = 0); }; - #endif diff --git a/src/PipelineIE.cpp b/src/PipelineIE.cpp index 6ba3d74..bd02e99 100644 --- a/src/PipelineIE.cpp +++ b/src/PipelineIE.cpp @@ -9,621 +9,600 @@ #include -static void clearPipeline(GstElement *pipeline) +static void +clearPipeline (GstElement *pipeline) { - if(!pipeline) - return; + if (!pipeline) + return; - GstIterator *iter; - iter = gst_bin_iterate_elements (GST_BIN (pipeline)); - GstElement *element = NULL; - bool done = false; - while (!done) - { + GstIterator *iter; + iter = gst_bin_iterate_elements (GST_BIN (pipeline)); + GstElement *element = NULL; + bool done = false; + while (!done) { #if GST_VERSION_MAJOR >= 1 - GValue value = { 0 }; - switch (gst_iterator_next (iter, &value)) - { - case GST_ITERATOR_OK: - { - element = GST_ELEMENT(g_value_get_object(&value)); + GValue value = + { 0}; + switch (gst_iterator_next (iter, &value)) + { + case GST_ITERATOR_OK: + { + element = GST_ELEMENT(g_value_get_object(&value)); #else - switch (gst_iterator_next (iter, (gpointer *)&element)) - { - case GST_ITERATOR_OK: - { + switch (gst_iterator_next (iter, (gpointer *) &element)) { + case GST_ITERATOR_OK: { #endif - gst_bin_remove(GST_BIN(pipeline), element); + gst_bin_remove (GST_BIN (pipeline), element); #if GST_VERSION_MAJOR >= 1 - g_value_reset (&value); + g_value_reset (&value); #endif - iter = gst_bin_iterate_elements (GST_BIN (pipeline)); - if(!iter) - done = true; + iter = gst_bin_iterate_elements (GST_BIN (pipeline)); + if (!iter) + done = true; - break; - } - case GST_ITERATOR_DONE: - case GST_ITERATOR_RESYNC: - case GST_ITERATOR_ERROR: - { - done = true; - break; - } - }; - } + break; + } + case GST_ITERATOR_DONE: + case GST_ITERATOR_RESYNC: + case GST_ITERATOR_ERROR: { + done = true; + break; + } + }; + } - gst_iterator_free (iter); + gst_iterator_free (iter); } -namespace +namespace { - struct Connection - { - std::string element1; - std::string pad1; - std::string element2; - std::string pad2; - }; + struct Connection + { + std::string element1; + std::string pad1; + std::string element2; + std::string pad2; + }; } - -static void writeProperties(QXmlStreamWriter &xmlWriter, const GstElement *element) +static void +writeProperties (QXmlStreamWriter &xmlWriter, const GstElement *element) { - GParamSpec **prop_specs; - guint num_props; + GParamSpec **prop_specs; + guint num_props; - prop_specs = g_object_class_list_properties(G_OBJECT_GET_CLASS (element), - &num_props); + prop_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), + &num_props); - if(!num_props) - return; + if (!num_props) + return; - xmlWriter.writeStartElement("properties"); + xmlWriter.writeStartElement ("properties"); - for(std::size_t i = 0; i flags & G_PARAM_READABLE) && (param -> flags & G_PARAM_WRITABLE)) - { - GValue value = { 0 }; - g_value_init (&value, param -> value_type); + if ((param->flags & G_PARAM_READABLE) + && (param->flags & G_PARAM_WRITABLE)) { + GValue value = { 0 }; + g_value_init (&value, param->value_type); - g_object_get_property (G_OBJECT(element), param -> name, &value); + g_object_get_property (G_OBJECT (element), param->name, &value); - if(!g_param_value_defaults(param, &value)) - { - bool skip = false; - QString propertyName = g_param_spec_get_name (param); - QString propertyValue; + if (!g_param_value_defaults (param, &value)) { + bool skip = false; + QString propertyName = g_param_spec_get_name (param); + QString propertyValue; + switch (G_VALUE_TYPE (&value)) { + case G_TYPE_STRING: { - switch (G_VALUE_TYPE (&value)) - { - case G_TYPE_STRING: - { + const char *string_val = g_value_get_string (&value); + if (string_val) + propertyValue = string_val; + else + skip = true; + break; + } + case G_TYPE_BOOLEAN: { + gboolean bool_val = g_value_get_boolean (&value); + propertyValue = QString::number (bool_val); + break; + } + case G_TYPE_ULONG: { + propertyValue = QString::number (g_value_get_ulong (&value)); + break; + } + case G_TYPE_LONG: { + propertyValue = QString::number (g_value_get_long (&value)); + break; + } + case G_TYPE_UINT: { + propertyValue = QString::number (g_value_get_uint (&value)); + break; + } + case G_TYPE_INT: { + propertyValue = QString::number (g_value_get_int (&value)); + break; + } + case G_TYPE_UINT64: { + propertyValue = QString::number (g_value_get_uint64 (&value)); + break; + } + case G_TYPE_INT64: { + propertyValue = QString::number (g_value_get_int64 (&value)); + break; + } + case G_TYPE_FLOAT: { + propertyValue = QString::number (g_value_get_float (&value)); + break; + } + case G_TYPE_DOUBLE: { + propertyValue = QString::number (g_value_get_double (&value)); + break; + } + default: { + gchar *elementName = gst_element_get_name (element); - const char *string_val = g_value_get_string (&value); - if(string_val) - propertyValue = string_val; - else - skip = true; - break; - } - case G_TYPE_BOOLEAN: - { - gboolean bool_val = g_value_get_boolean (&value); - propertyValue = QString::number(bool_val); - break; - } - case G_TYPE_ULONG: - { - propertyValue = QString::number(g_value_get_ulong(&value)); - break; - } - case G_TYPE_LONG: - { - propertyValue = QString::number(g_value_get_long(&value)); - break; - } - case G_TYPE_UINT: - { - propertyValue = QString::number(g_value_get_uint(&value)); - break; - } - case G_TYPE_INT: - { - propertyValue = QString::number(g_value_get_int(&value)); - break; - } - case G_TYPE_UINT64: - { - propertyValue = QString::number(g_value_get_uint64(&value)); - break; - } - case G_TYPE_INT64: - { - propertyValue = QString::number(g_value_get_int64(&value)); - break; - } - case G_TYPE_FLOAT: - { - propertyValue = QString::number(g_value_get_float(&value)); - break; - } - case G_TYPE_DOUBLE: - { - propertyValue = QString::number(g_value_get_double(&value)); - break; - } - default: - { - gchar *elementName = gst_element_get_name(element); + qDebug () << "property `" << propertyName << "` for `" + << elementName << "` not supported"; + g_free (elementName); - qDebug() << "property `" << propertyName << "` for `" - << elementName << "` not supported"; - g_free(elementName); + skip = true; + break; + } + }; - skip = true; - break; - } - }; + if (!skip) { + xmlWriter.writeStartElement ("property"); + xmlWriter.writeAttribute ("name", propertyName); + xmlWriter.writeAttribute ("value", propertyValue); + xmlWriter.writeEndElement (); + } + g_value_reset (&value); - if(!skip) - { - xmlWriter.writeStartElement("property"); - xmlWriter.writeAttribute("name", propertyName); - xmlWriter.writeAttribute("value", propertyValue); - xmlWriter.writeEndElement(); - } - g_value_reset(&value); + } + } + } - } - } - } + xmlWriter.writeEndElement (); - xmlWriter.writeEndElement(); - - g_free(prop_specs); + g_free (prop_specs); } - - -static void loadProperties(QDomElement node, GstElement *element) +static void +loadProperties (QDomElement node, GstElement *element) { - QDomNode child = node.firstChild(); - while(!child.isNull()) - { - if(child.toElement().tagName() == "property") - { - QString name = child.toElement().attribute("name"); - QString value = child.toElement().attribute("value"); + QDomNode child = node.firstChild (); + while (!child.isNull ()) { + if (child.toElement ().tagName () == "property") { + QString name = child.toElement ().attribute ("name"); + QString value = child.toElement ().attribute ("value"); - GParamSpec *param = g_object_class_find_property(G_OBJECT_GET_CLASS (element), - name.toStdString().c_str()); + GParamSpec *param = g_object_class_find_property ( + G_OBJECT_GET_CLASS (element), name.toStdString ().c_str ()); - if(!param) - { - gchar *elementName = gst_element_get_name(element); - qDebug() << "problem with setting property `" << name << "` for `" << elementName << "`"; - g_free(elementName); - continue; - } + if (!param) { + gchar *elementName = gst_element_get_name (element); + qDebug () << "problem with setting property `" << name << "` for `" + << elementName << "`"; + g_free (elementName); + continue; + } - if(!(param -> flags & G_PARAM_WRITABLE)) - continue; + if (!(param->flags & G_PARAM_WRITABLE)) + continue; - std::string tmpStr = name.toStdString(); - const char *propName = tmpStr.c_str(); - switch (param -> value_type) - { - case G_TYPE_STRING: - { - g_object_set(G_OBJECT(element), propName, value.toStdString().c_str(), NULL); - break; - } - case G_TYPE_BOOLEAN: - { - gboolean val = value.toInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_ULONG: - { - gulong val = value.toULong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_LONG: - { - glong val = value.toLong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_UINT: - { - guint val = value.toUInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_INT: - { - gint val = value.toInt(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_UINT64: - { - guint64 val = value.toULongLong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_INT64: - { - gint64 val = value.toLongLong(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_FLOAT: - { - gfloat val = value.toFloat(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - case G_TYPE_DOUBLE: - { - gdouble val = value.toDouble(); - g_object_set(G_OBJECT(element), propName, val, NULL); - break; - } - default: - { - gchar *elementName = gst_element_get_name(element); - qDebug() << "property `" << name << "` for `" << QString(elementName) << "` not supported"; - g_free(elementName); - break; - } - }; - } + std::string tmpStr = name.toStdString (); + const char *propName = tmpStr.c_str (); + switch (param->value_type) { + case G_TYPE_STRING: { + g_object_set (G_OBJECT (element), propName, + value.toStdString ().c_str (), NULL); + break; + } + case G_TYPE_BOOLEAN: { + gboolean val = value.toInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_ULONG: { + gulong val = value.toULong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_LONG: { + glong val = value.toLong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_UINT: { + guint val = value.toUInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_INT: { + gint val = value.toInt (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_UINT64: { + guint64 val = value.toULongLong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_INT64: { + gint64 val = value.toLongLong (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_FLOAT: { + gfloat val = value.toFloat (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + case G_TYPE_DOUBLE: { + gdouble val = value.toDouble (); + g_object_set (G_OBJECT (element), propName, val, NULL); + break; + } + default: { + gchar *elementName = gst_element_get_name (element); + qDebug () << "property `" << name << "` for `" + << QString (elementName) << "` not supported"; + g_free (elementName); + break; + } + }; + } - child = child.nextSibling(); - } + child = child.nextSibling (); + } } - -static void create_requst_pad(GstElement *element, const QString &templateName, const QString &padName) +static void +create_requst_pad (GstElement *element, const QString &templateName, + const QString &padName) { - GstElementClass *klass = GST_ELEMENT_GET_CLASS(element); + GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); - GstPadTemplate *templ = gst_element_class_get_pad_template(klass, templateName.toStdString().c_str()); + GstPadTemplate *templ = gst_element_class_get_pad_template ( + klass, templateName.toStdString ().c_str ()); - gst_element_request_pad(element, templ, padName.toStdString().c_str(), NULL); + gst_element_request_pad (element, templ, padName.toStdString ().c_str (), + NULL); } -bool PipelineIE::Export(QSharedPointer pgraph, const QString &fileName) +bool +PipelineIE::Export (QSharedPointer pgraph, + const QString &fileName) { - QFile file(fileName); - - if (!file.open(QIODevice::WriteOnly)) - { - QMessageBox::warning(0, "Read only", "The file is in read only mode"); - return false; - } + QFile file (fileName); - std::vector info = pgraph -> GetInfo(); + if (!file.open (QIODevice::WriteOnly)) { + QMessageBox::warning (0, "Read only", "The file is in read only mode"); + return false; + } - QXmlStreamWriter xmlWriter; - xmlWriter.setDevice(&file); - xmlWriter.writeStartDocument(); - xmlWriter.writeStartElement("pipeline"); + std::vector info = pgraph->GetInfo (); - for(std::size_t i=0; i m_pGraph), info[i].m_name.c_str()); + xmlWriter.writeAttribute ("name", info[i].m_name.c_str ()); + xmlWriter.writeAttribute ("plugin-name", info[i].m_pluginName.c_str ()); - for(std::size_t j=0; jm_pGraph), + info[i].m_name.c_str ()); - xmlWriter.writeAttribute("name", info[i].m_pads[j].m_name.c_str()); + for (std::size_t j = 0; j < info[i].m_pads.size (); j++) { + xmlWriter.writeStartElement ("pad"); - GstPad *pad = gst_element_get_static_pad(element, info[i].m_pads[j].m_name.c_str()); + xmlWriter.writeAttribute ("name", info[i].m_pads[j].m_name.c_str ()); - GstPadTemplate *templ = gst_pad_get_pad_template(pad); - if (templ) { - QString presence; - switch(GST_PAD_TEMPLATE_PRESENCE(templ)) - { - case GST_PAD_ALWAYS: - presence = "always"; - break; + GstPad *pad = gst_element_get_static_pad ( + element, info[i].m_pads[j].m_name.c_str ()); - case GST_PAD_SOMETIMES: - presence = "sometimes"; - break; + GstPadTemplate *templ = gst_pad_get_pad_template (pad); + if (templ) { + QString presence; + switch (GST_PAD_TEMPLATE_PRESENCE (templ)) { + case GST_PAD_ALWAYS: + presence = "always"; + break; - case GST_PAD_REQUEST: - presence = "request"; - break; - }; + case GST_PAD_SOMETIMES: + presence = "sometimes"; + break; - xmlWriter.writeAttribute("presence", presence); - xmlWriter.writeAttribute("template-name", GST_PAD_TEMPLATE_NAME_TEMPLATE(templ)); - } else { - qDebug() << "Unable to find a template for" << info[i].m_pads[j].m_name.c_str(); - xmlWriter.writeAttribute("presence", "always"); - xmlWriter.writeAttribute("template-name", ""); - } - gst_object_unref(pad); + case GST_PAD_REQUEST: + presence = "request"; + break; + }; - if(info[i].m_connections[j].m_elementId != (size_t)-1 && - info[i].m_connections[j].m_padId != (size_t)-1) - { - std::size_t elementPos, padPos; - for(elementPos = 0; elementPos < info.size(); elementPos++) - { - if(info[elementPos].m_id == info[i].m_connections[j].m_elementId) - { - for(padPos = 0; padPos < info[elementPos].m_pads.size(); padPos++) - if(info[elementPos].m_pads[padPos].m_id == info[i].m_connections[j].m_padId) - break; + xmlWriter.writeAttribute ("presence", presence); + xmlWriter.writeAttribute ("template-name", + GST_PAD_TEMPLATE_NAME_TEMPLATE (templ)); + } + else { + qDebug () << "Unable to find a template for" + << info[i].m_pads[j].m_name.c_str (); + xmlWriter.writeAttribute ("presence", "always"); + xmlWriter.writeAttribute ("template-name", ""); + } + gst_object_unref (pad); - if(padPos < info[elementPos].m_pads.size()) - break; - } - } - if(elementPos < info.size() && padPos < info[elementPos].m_pads.size()) - { - xmlWriter.writeStartElement("connected-to"); - xmlWriter.writeAttribute("element-name", info[elementPos].m_name.c_str()); - xmlWriter.writeAttribute("pad-name", info[elementPos].m_pads[padPos].m_name.c_str()); - xmlWriter.writeEndElement(); - } - } + if (info[i].m_connections[j].m_elementId != (size_t) -1 + && info[i].m_connections[j].m_padId != (size_t) -1) { + std::size_t elementPos, padPos; + for (elementPos = 0; elementPos < info.size (); elementPos++) { + if (info[elementPos].m_id == info[i].m_connections[j].m_elementId) { + for (padPos = 0; padPos < info[elementPos].m_pads.size (); padPos++) + if (info[elementPos].m_pads[padPos].m_id + == info[i].m_connections[j].m_padId) + break; - xmlWriter.writeEndElement(); - } + if (padPos < info[elementPos].m_pads.size ()) + break; + } + } + if (elementPos < info.size () + && padPos < info[elementPos].m_pads.size ()) { + xmlWriter.writeStartElement ("connected-to"); + xmlWriter.writeAttribute ("element-name", + info[elementPos].m_name.c_str ()); + xmlWriter.writeAttribute ( + "pad-name", info[elementPos].m_pads[padPos].m_name.c_str ()); + xmlWriter.writeEndElement (); + } + } - writeProperties(xmlWriter, element); - gst_object_unref(element); + xmlWriter.writeEndElement (); + } - xmlWriter.writeEndElement(); - } + writeProperties (xmlWriter, element); + gst_object_unref (element); - xmlWriter.writeEndElement(); - xmlWriter.writeEndDocument(); + xmlWriter.writeEndElement (); + } - return true; + xmlWriter.writeEndElement (); + xmlWriter.writeEndDocument (); + + return true; } - -bool PipelineIE::Import(QSharedPointer pgraph, const QString &fileName) +bool +PipelineIE::Import (QSharedPointer pgraph, + const QString &fileName) { - GstElement *pipeline = pgraph -> m_pGraph; - QFile file(fileName); - if(!file.open(QFile::ReadOnly | QFile::Text)) - { - QMessageBox::warning(0, "Open failed", - QString("Cannot read file ") + fileName + - ": " + file.errorString()); + GstElement *pipeline = pgraph->m_pGraph; + QFile file (fileName); + if (!file.open (QFile::ReadOnly | QFile::Text)) { + QMessageBox::warning ( + 0, "Open failed", + QString ("Cannot read file ") + fileName + ": " + file.errorString ()); - return false; - } + return false; + } - QString errorStr; - int errorLine; - int errorColumn; + QString errorStr; + int errorLine; + int errorColumn; - QDomDocument doc; - if(!doc.setContent(&file, false, &errorStr, &errorLine, &errorColumn)) - { - QMessageBox::warning(0, "Xml parsing failed", - QString("Parse error at line ") + QString::number(errorLine) + ", " - "column " + QString::number(errorColumn) + ": " + errorStr); - return false; - } + QDomDocument doc; + if (!doc.setContent (&file, false, &errorStr, &errorLine, &errorColumn)) { + QMessageBox::warning ( + 0, "Xml parsing failed", + QString ("Parse error at line ") + QString::number (errorLine) + ", " + "column " + QString::number (errorColumn) + ": " + errorStr); + return false; + } - clearPipeline(pipeline); + clearPipeline (pipeline); - QDomElement root = doc.documentElement(); + QDomElement root = doc.documentElement (); - if(root.tagName() != "pipeline") - { - QMessageBox::warning(0, "Parsing failed", "Is invalid pipeline file"); - return false; - } + if (root.tagName () != "pipeline") { + QMessageBox::warning (0, "Parsing failed", "Is invalid pipeline file"); + return false; + } - QDomNode child = root.firstChild(); + QDomNode child = root.firstChild (); - std::vector connections; - while(!child.isNull()) - { - if(child.toElement().tagName() == "element") - { - QDomElement elNode = child.toElement(); - + std::vector connections; + while (!child.isNull ()) { + if (child.toElement ().tagName () == "element") { + QDomElement elNode = child.toElement (); - GstElement *pel = gst_element_factory_make(elNode.attribute("plugin-name").toStdString().c_str(), - elNode.attribute("name").toStdString().c_str()); + GstElement *pel = gst_element_factory_make ( + elNode.attribute ("plugin-name").toStdString ().c_str (), + elNode.attribute ("name").toStdString ().c_str ()); - if(!pel) - { - QMessageBox::warning(0, "Element creation failed", - QString("Could not create element of `") + - elNode.attribute("plugin-name") + "` with name `" + - elNode.attribute("name") + "`"); + if (!pel) { + QMessageBox::warning ( + 0, + "Element creation failed", + QString ("Could not create element of `") + + elNode.attribute ("plugin-name") + "` with name `" + + elNode.attribute ("name") + "`"); - child = child.nextSibling(); - continue; - } + child = child.nextSibling (); + continue; + } - bool res = gst_bin_add(GST_BIN(pipeline), pel); + bool res = gst_bin_add (GST_BIN (pipeline), pel); - if(!res) - { - QMessageBox::warning(0, "Element insertion failed", - QString("Could not insert element `") + - elNode.attribute("name") + "` to pipeline"); + if (!res) { + QMessageBox::warning ( + 0, + "Element insertion failed", + QString ("Could not insert element `") + elNode.attribute ("name") + + "` to pipeline"); - child = child.nextSibling(); - continue; - } + child = child.nextSibling (); + continue; + } - gst_element_sync_state_with_parent(pel); + gst_element_sync_state_with_parent (pel); - - QDomNode elementChild = elNode.firstChild(); - while(!elementChild.isNull()) - { - if(elementChild.toElement().tagName() == "pad") - { - QDomNode padChild = elementChild.firstChild(); - QDomElement elPad = elementChild.toElement(); + QDomNode elementChild = elNode.firstChild (); + while (!elementChild.isNull ()) { + if (elementChild.toElement ().tagName () == "pad") { + QDomNode padChild = elementChild.firstChild (); + QDomElement elPad = elementChild.toElement (); // GstPadPresence presence = GST_PAD_ALWAYS; - QString templaneName; - if(elPad.attribute("presence") == "request") - create_requst_pad(pel, elPad.attribute("template-name"), elPad.attribute("name")); + QString templaneName; + if (elPad.attribute ("presence") == "request") + create_requst_pad (pel, elPad.attribute ("template-name"), + elPad.attribute ("name")); - while(!padChild.isNull()) - { - if(padChild.toElement().tagName() == "connected-to") - { - bool isExists = false; - QDomElement elCoonnectedTo = padChild.toElement(); + while (!padChild.isNull ()) { + if (padChild.toElement ().tagName () == "connected-to") { + bool isExists = false; + QDomElement elCoonnectedTo = padChild.toElement (); - for(std::size_t i=0; i 0) - setReady = false; + std::size_t maxStarts = 5; + bool setReady = true; + for (std::size_t k = 0; k < maxStarts; k++) { + if (connections.empty ()) + break; - while(true) - { - std::size_t i=0; - for(; i 0) + setReady = false; - if(!el1 || !el2) - { - QMessageBox::warning(0, "Internal error", - QString("Could not find one of elements `") + - QString(connections[i].element1.c_str()) + "`, `" + - QString(connections[i].element2.c_str()) + "`"); + while (true) { + std::size_t i = 0; + for (; i < connections.size (); i++) { + GstElement *el1 = gst_bin_get_by_name ( + GST_BIN (pipeline), connections[i].element1.c_str ()); + GstElement *el2 = gst_bin_get_by_name ( + GST_BIN (pipeline), connections[i].element2.c_str ()); - gst_object_unref(el1); - gst_object_unref(el2); + if (!el1 || !el2) { + QMessageBox::warning ( + 0, + "Internal error", + QString ("Could not find one of elements `") + + QString (connections[i].element1.c_str ()) + "`, `" + + QString (connections[i].element2.c_str ()) + "`"); - return false; - } - - GstPad *pad1 = gst_element_get_static_pad(el1, connections[i].pad1.c_str()); - GstPad *pad2 = gst_element_get_static_pad(el2, connections[i].pad2.c_str()); + gst_object_unref (el1); + gst_object_unref (el2); - if(pad1 && pad2) - { - if(GST_PAD_IS_SRC(pad1)) - gst_element_link_pads(el1, connections[i].pad1.c_str(), el2, connections[i].pad2.c_str()); - else - gst_element_link_pads(el2, connections[i].pad2.c_str(), el1, connections[i].pad1.c_str()); + return false; + } - gst_object_unref(pad1); - gst_object_unref(pad2); - connections.erase(connections.begin() + i); + GstPad *pad1 = gst_element_get_static_pad ( + el1, connections[i].pad1.c_str ()); + GstPad *pad2 = gst_element_get_static_pad ( + el2, connections[i].pad2.c_str ()); - gst_object_unref(el1); - gst_object_unref(el2); + if (pad1 && pad2) { + if (GST_PAD_IS_SRC (pad1)) + gst_element_link_pads (el1, connections[i].pad1.c_str (), el2, + connections[i].pad2.c_str ()); + else + gst_element_link_pads (el2, connections[i].pad2.c_str (), el1, + connections[i].pad1.c_str ()); - break; - } + gst_object_unref (pad1); + gst_object_unref (pad2); + connections.erase (connections.begin () + i); - if(pad1) - gst_object_unref(pad1); - - if(pad2) - gst_object_unref(pad2); + gst_object_unref (el1); + gst_object_unref (el2); - gst_object_unref(el1); - gst_object_unref(el2); - } + break; + } - if(i == connections.size()) - break; - } + if (pad1) + gst_object_unref (pad1); - if(!connections.empty()) - { - gst_element_set_state(pipeline, GST_STATE_PAUSED); + if (pad2) + gst_object_unref (pad2); - GstState state; - gst_element_get_state (pipeline, &state, NULL, GST_MSECOND * 2500); - } + gst_object_unref (el1); + gst_object_unref (el2); + } - } + if (i == connections.size ()) + break; + } - if(setReady) - gst_element_set_state(pipeline, GST_STATE_READY); + if (!connections.empty ()) { + gst_element_set_state (pipeline, GST_STATE_PAUSED); - return true; + GstState state; + gst_element_get_state (pipeline, &state, NULL, GST_MSECOND * 2500); + } + + } + + if (setReady) + gst_element_set_state (pipeline, GST_STATE_READY); + + return true; } -bool PipelineIE::Clear(QSharedPointer pgraph) +bool +PipelineIE::Clear (QSharedPointer pgraph) { - GstElement *pipeline = pgraph -> m_pGraph; - clearPipeline(pipeline); - return true; + GstElement *pipeline = pgraph->m_pGraph; + clearPipeline (pipeline); + return true; } diff --git a/src/PipelineIE.h b/src/PipelineIE.h index 33c8769..84ad35f 100644 --- a/src/PipelineIE.h +++ b/src/PipelineIE.h @@ -8,9 +8,9 @@ namespace PipelineIE { - bool Export(QSharedPointer pgraph, const QString &fileName); - bool Import(QSharedPointer pgraph, const QString &fileName); - bool Clear(QSharedPointer pgraph); + bool Export(QSharedPointer pgraph, const QString &fileName); + bool Import(QSharedPointer pgraph, const QString &fileName); + bool Clear(QSharedPointer pgraph); }; #endif diff --git a/src/PluginsList.cpp b/src/PluginsList.cpp index 8306870..24c2323 100644 --- a/src/PluginsList.cpp +++ b/src/PluginsList.cpp @@ -14,31 +14,34 @@ #include -static gint plugins_sort_cb (gconstpointer a, gconstpointer b) +static gint +plugins_sort_cb (gconstpointer a, gconstpointer b) { - Plugin* p1 = (Plugin*)a; - Plugin* p2 = (Plugin*)b; - qDebug() << "Sort p1: " << p1 -> getName() << " and p2: " << p2 -> getName(); - if (p1->getRank() > p2->getRank()) - return 1; - else if (p1->getRank() == p2->getRank()) { + Plugin* p1 = (Plugin*) a; + Plugin* p2 = (Plugin*) b; + qDebug () << "Sort p1: " << p1->getName () << " and p2: " << p2->getName (); + if (p1->getRank () > p2->getRank ()) + return 1; + else if (p1->getRank () == p2->getRank ()) { return 0; - } else { - return -1; + } + else { + return -1; } } -PluginsList::PluginsList() +PluginsList::PluginsList () { - init(); + init (); } -PluginsList::~PluginsList() +PluginsList::~PluginsList () { //g_list_free(m_pluginsList); } -void PluginsList::init() +void +PluginsList::init () { std::size_t num = 0; GList *plugins; @@ -47,33 +50,30 @@ void PluginsList::init() #if GST_VERSION_MAJOR >= 1 registry = gst_registry_get(); #else - registry = gst_registry_get_default(); + registry = gst_registry_get_default (); #endif - plugins = gst_registry_get_plugin_list(registry); - while(plugins) - { + plugins = gst_registry_get_plugin_list (registry); + while (plugins) { GstPlugin *plugin; plugin = (GstPlugin *) (plugins->data); plugins = g_list_next (plugins); #if GST_VERSION_MAJOR >= 1 registry = gst_registry_get(); #else - registry = gst_registry_get_default(); + registry = gst_registry_get_default (); #endif - GList *features = gst_registry_get_feature_list_by_plugin (registry, - gst_plugin_get_name (plugin)); + GList *features = gst_registry_get_feature_list_by_plugin ( + registry, gst_plugin_get_name (plugin)); - while(features) - { + while (features) { GstPluginFeature *feature; feature = GST_PLUGIN_FEATURE (features->data); - if(GST_IS_ELEMENT_FACTORY (feature)) - { + if (GST_IS_ELEMENT_FACTORY (feature)) { GstElementFactory *factory; factory = GST_ELEMENT_FACTORY (feature); - int rank = gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory)); - Plugin* p = new Plugin(GST_OBJECT_NAME (factory), rank); - m_pluginsList = g_list_append(m_pluginsList, p); + int rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)); + Plugin* p = new Plugin (GST_OBJECT_NAME (factory), rank); + m_pluginsList = g_list_append (m_pluginsList, p); num++; } @@ -82,220 +82,238 @@ void PluginsList::init() } } -GList* PluginsList::getSortedByRank() +GList* +PluginsList::getSortedByRank () { - GList* sorted_list = g_list_sort(m_pluginsList, plugins_sort_cb); + GList* sorted_list = g_list_sort (m_pluginsList, plugins_sort_cb); return sorted_list; } -GList* PluginsList::getPluginListByCaps(GstPadDirection direction, GstCaps* caps) +GList* +PluginsList::getPluginListByCaps (GstPadDirection direction, GstCaps* caps) { GList * caps_plugins_list = NULL; - GList *l,*p; + GList *l, *p; for (l = m_pluginsList; l != NULL; l = l->next) { - Plugin* plugin = (Plugin*)(l->data); - GstElementFactory* factory = gst_element_factory_find(plugin->getName().toStdString().c_str()); - if (factory) { - const GList* pads = gst_element_factory_get_static_pad_templates(factory); - for (p = (GList*)pads; p != NULL; p = p->next) { - GstStaticPadTemplate* padTemplate = (GstStaticPadTemplate*)(p->data); - if (padTemplate->direction == direction && gst_caps_can_intersect(caps, padTemplate->static_caps.caps)) - caps_plugins_list = g_list_append(caps_plugins_list, plugin); - } + Plugin* plugin = (Plugin*) (l->data); + GstElementFactory* factory = gst_element_factory_find ( + plugin->getName ().toStdString ().c_str ()); + if (factory) { + const GList* pads = gst_element_factory_get_static_pad_templates ( + factory); + for (p = (GList*) pads; p != NULL; p = p->next) { + GstStaticPadTemplate* padTemplate = (GstStaticPadTemplate*) (p->data); + if (padTemplate->direction == direction + && gst_caps_can_intersect (caps, padTemplate->static_caps.caps)) + caps_plugins_list = g_list_append (caps_plugins_list, plugin); } + } } return caps_plugins_list; } -PluginsListDialog::PluginsListDialog(PluginsList* pluginList, QWidget *pwgt, Qt::WindowFlags f): -QDialog(pwgt, f) -, m_pPluginsList(pluginList) -, m_pGraph(NULL) +PluginsListDialog::PluginsListDialog (PluginsList* pluginList, QWidget *pwgt, + Qt::WindowFlags f) +: QDialog (pwgt, f), +m_pPluginsList (pluginList), +m_pGraph (NULL) { - m_pPlugins = new QListWidget; - m_pPlugins->setSortingEnabled(true); - m_plblInfo = new QLabel; + m_pPlugins = new QListWidget; + m_pPlugins->setSortingEnabled (true); + m_plblInfo = new QLabel; - m_plblInfo -> setTextInteractionFlags(Qt::TextSelectableByMouse); - m_plblInfo -> setAlignment(Qt::AlignLeft | Qt::AlignTop); - QScrollArea *pscroll = new QScrollArea; - pscroll -> setWidget(m_plblInfo); - m_plblInfo -> resize(pscroll -> size()); + m_plblInfo->setTextInteractionFlags (Qt::TextSelectableByMouse); + m_plblInfo->setAlignment (Qt::AlignLeft | Qt::AlignTop); + QScrollArea *pscroll = new QScrollArea; + pscroll->setWidget (m_plblInfo); + m_plblInfo->resize (pscroll->size ()); - QHBoxLayout *phblay = new QHBoxLayout; + QHBoxLayout *phblay = new QHBoxLayout; - phblay -> addWidget(m_pPlugins, 1); - phblay -> addWidget(pscroll, 2); + phblay->addWidget (m_pPlugins, 1); + phblay->addWidget (pscroll, 2); - InitPluginsList(); + InitPluginsList (); - QHBoxLayout *phblayFind = new QHBoxLayout; + QHBoxLayout *phblayFind = new QHBoxLayout; - QLineEdit *ple = new QLineEdit; - phblayFind -> addWidget(ple); - phblayFind -> addStretch(1); + QLineEdit *ple = new QLineEdit; + phblayFind->addWidget (ple); + phblayFind->addStretch (1); - ple -> setPlaceholderText("Search..."); + ple->setPlaceholderText ("Search..."); - QVBoxLayout *pvblay = new QVBoxLayout; - pvblay -> addLayout(phblayFind); - pvblay -> addLayout(phblay); + QVBoxLayout *pvblay = new QVBoxLayout; + pvblay->addLayout (phblayFind); + pvblay->addLayout (phblay); - setLayout(pvblay); + setLayout (pvblay); - setWindowTitle("Add plugin"); + setWindowTitle ("Add plugin"); - QObject::connect(m_pPlugins, SIGNAL(currentItemChanged (QListWidgetItem *, QListWidgetItem *)), - this, SLOT(showInfo(QListWidgetItem *, QListWidgetItem *))); + QObject::connect(m_pPlugins, SIGNAL(currentItemChanged (QListWidgetItem *, QListWidgetItem *)), + this, SLOT(showInfo(QListWidgetItem *, QListWidgetItem *))); - QObject::connect(m_pPlugins, SIGNAL(itemDoubleClicked (QListWidgetItem *)), - this, SLOT(insert(QListWidgetItem *))); + QObject::connect(m_pPlugins, SIGNAL(itemDoubleClicked (QListWidgetItem *)), + this, SLOT(insert(QListWidgetItem *))); - QObject::connect(ple, SIGNAL(textChanged(const QString &)), this, SLOT(filterPlagins(const QString &))); + QObject::connect(ple, SIGNAL(textChanged(const QString &)), this, SLOT(filterPlagins(const QString &))); - installEventFilter(this); + installEventFilter (this); } -PluginsListDialog::~PluginsListDialog() +PluginsListDialog::~PluginsListDialog () { if (m_pPluginsList) delete m_pPluginsList; } -void PluginsListDialog::showInfo(QListWidgetItem *pitem, QListWidgetItem *previous) +void +PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous) { - qDebug() << "Show Info: " << pitem -> text(); - m_plblInfo -> clear(); - QString descr; - descr += "Plugin details
"; + qDebug () << "Show Info: " << pitem->text (); + m_plblInfo->clear (); + QString descr; + descr += "Plugin details
"; - GstElementFactory *factory = gst_element_factory_find(pitem -> text().toStdString().c_str()); - if(!factory) - { - qDebug() << "warning: " << pitem -> text() << " Not Found"; - return; - } + GstElementFactory *factory = gst_element_factory_find ( + pitem->text ().toStdString ().c_str ()); + if (!factory) { + qDebug () << "warning: " << pitem->text () << " Not Found"; + return; + } - factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE(factory))); - if(!factory) - { - qDebug() << "warning: " << pitem -> text() << " Not Found"; - return; - } + factory = GST_ELEMENT_FACTORY ( + gst_plugin_feature_load (GST_PLUGIN_FEATURE (factory))); + if (!factory) { + qDebug () << "warning: " << pitem->text () << " Not Found"; + return; + } #if GST_VERSION_MAJOR >= 1 - GstPlugin *plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory)); + GstPlugin *plugin = gst_plugin_feature_get_plugin (GST_PLUGIN_FEATURE (factory)); #else - const gchar* plugin_name = GST_PLUGIN_FEATURE(factory)->plugin_name; - if (!plugin_name) { - return; - } - GstPlugin* plugin = gst_default_registry_find_plugin(plugin_name); + const gchar* plugin_name = GST_PLUGIN_FEATURE (factory)->plugin_name; + if (!plugin_name) { + return; + } + GstPlugin* plugin = gst_default_registry_find_plugin (plugin_name); #endif - if(!plugin) - { - qDebug() << "warning: " << pitem -> text() << " Not Found"; - return; - } + if (!plugin) { + qDebug () << "warning: " << pitem->text () << " Not Found"; + return; + } #if GST_VERSION_MAJOR >= 1 - const gchar *release_date = gst_plugin_get_release_date_string (plugin); + const gchar *release_date = gst_plugin_get_release_date_string (plugin); #else - const gchar *release_date = (plugin->desc.release_datetime) ? plugin->desc.release_datetime : ""; + const gchar *release_date = + (plugin->desc.release_datetime) ? plugin->desc.release_datetime : ""; #endif - const gchar *filename = gst_plugin_get_filename(plugin); + const gchar *filename = gst_plugin_get_filename (plugin); - descr += "Name: " + QString(gst_plugin_get_name(plugin)) + "
"; - descr += "Description: " + QString(gst_plugin_get_description(plugin)) + "
"; - descr += "Filename: " + QString((filename != NULL) ? filename : "(null)") + "
"; - descr += "Version: " + QString(gst_plugin_get_version (plugin)) + "
"; - descr += "License: " + QString(gst_plugin_get_license (plugin)) + "
"; - descr += "Source module: " + QString(gst_plugin_get_source (plugin)) + "
"; + descr += "Name: " + QString (gst_plugin_get_name (plugin)) + "
"; + descr += "Description: " + + QString (gst_plugin_get_description (plugin)) + "
"; + descr += "Filename: " + + QString ((filename != NULL) ? filename : "(null)") + "
"; + descr += "Version: " + QString (gst_plugin_get_version (plugin)) + + "
"; + descr += "License: " + QString (gst_plugin_get_license (plugin)) + + "
"; + descr += "Source module: " + QString (gst_plugin_get_source (plugin)) + + "
"; - if (release_date != NULL) - { - const gchar *tz = "(UTC)"; - gchar *str, *sep; + if (release_date != NULL) { + const gchar *tz = "(UTC)"; + gchar *str, *sep; - str = g_strdup (release_date); - sep = strstr (str, "T"); - if (sep != NULL) - { - *sep = ' '; - sep = strstr (sep + 1, "Z"); - if (sep != NULL) - *sep = ' '; - } - else - { - tz = ""; - } - descr += "Source release date: " + QString(str) + " " + QString(tz) + "
"; - g_free (str); - } - descr += "Binary package: " + QString(gst_plugin_get_package (plugin)) + "
"; - descr += "Origin URL: " + QString(gst_plugin_get_origin (plugin)) + "
"; - descr += "Rank: " + QString::number(gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory))); - m_plblInfo -> setText(descr); + str = g_strdup (release_date); + sep = strstr (str, "T"); + if (sep != NULL) { + *sep = ' '; + sep = strstr (sep + 1, "Z"); + if (sep != NULL) + *sep = ' '; + } + else { + tz = ""; + } + descr += "Source release date: " + QString (str) + " " + QString (tz) + + "
"; + g_free (str); + } + descr += "Binary package: " + QString (gst_plugin_get_package (plugin)) + + "
"; + descr += "Origin URL: " + QString (gst_plugin_get_origin (plugin)) + + "
"; + descr += "Rank: " + + QString::number ( + gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory))); + m_plblInfo->setText (descr); } -void PluginsListDialog::insert(QListWidgetItem *pitem) +void +PluginsListDialog::insert (QListWidgetItem *pitem) { - if(!pitem) { - qDebug() << "Do not insert null item"; - return; - } - qDebug() << "Insert: " << pitem -> text(); + if (!pitem) { + qDebug () << "Do not insert null item"; + return; + } + qDebug () << "Insert: " << pitem->text (); - if(!m_pGraph || !m_pGraph -> AddPlugin(pitem -> text().toStdString().c_str(), NULL)) - { - QMessageBox::warning(this, "Plugin addition problem", "Plugin `" + pitem -> text() + "` insertion was FAILED"); - qDebug() << "Plugin `" << pitem -> text() << "` insertion FAILED"; - return; - } + if (!m_pGraph + || !m_pGraph->AddPlugin (pitem->text ().toStdString ().c_str (), NULL)) { + QMessageBox::warning ( + this, "Plugin addition problem", + "Plugin `" + pitem->text () + "` insertion was FAILED"); + qDebug () << "Plugin `" << pitem->text () << "` insertion FAILED"; + return; + } } -bool PluginsListDialog::eventFilter(QObject *obj, QEvent *event) +bool +PluginsListDialog::eventFilter (QObject *obj, QEvent *event) { - if (event -> type() == QEvent::KeyPress) - { - QKeyEvent *key = static_cast(event); + if (event->type () == QEvent::KeyPress) { + QKeyEvent *key = static_cast (event); - if((key -> key() == Qt::Key_Enter) || (key -> key() == Qt::Key_Return) && m_pPlugins -> currentItem()) - { - insert(m_pPlugins -> currentItem()); - return true; - } - } + if ((key->key () == Qt::Key_Enter) + || (key->key () == Qt::Key_Return) && m_pPlugins->currentItem ()) { + insert (m_pPlugins->currentItem ()); + return true; + } + } - return QDialog::eventFilter(obj, event); + return QDialog::eventFilter (obj, event); } -void PluginsListDialog::filterPlagins(const QString &text) +void +PluginsListDialog::filterPlagins (const QString &text) { - for(std::size_t i=0; i count(); i++) - { - QListWidgetItem *pitem = m_pPlugins -> item(i); + for (std::size_t i = 0; i < m_pPlugins->count (); i++) { + QListWidgetItem *pitem = m_pPlugins->item (i); - if(pitem -> text().contains(text)) - pitem -> setHidden(false); - else - pitem -> setHidden(true); - } + if (pitem->text ().contains (text)) + pitem->setHidden (false); + else + pitem->setHidden (true); + } } -void PluginsListDialog::InitPluginsList() +void +PluginsListDialog::InitPluginsList () { if (!m_pPluginsList) m_pPluginsList = new PluginsList (); - GList* plugins_list = m_pPluginsList->getList(); + GList* plugins_list = m_pPluginsList->getList (); GList* l; std::size_t num = 0; for (l = plugins_list; l != NULL; l = l->next) { - Plugin* plugin = (Plugin*)(l->data); - m_pPlugins->addItem(plugin->getName()); + Plugin* plugin = (Plugin*) (l->data); + m_pPlugins->addItem (plugin->getName ()); num++; } } diff --git a/src/PluginsList.h b/src/PluginsList.h index 1730796..197b204 100644 --- a/src/PluginsList.h +++ b/src/PluginsList.h @@ -5,24 +5,22 @@ #include #include - #include "GraphManager.h" - class Plugin { public: - Plugin(const QString& name, int rank): - m_name(name), - m_rank(rank) - { - } - const QString getName() { return m_name;} - int getRank() { return m_rank;} + Plugin(const QString& name, int rank): + m_name(name), + m_rank(rank) + { + } + const QString getName() {return m_name;} + int getRank() {return m_rank;} private: - const QString m_name; - int m_rank; + const QString m_name; + int m_rank; }; @@ -32,47 +30,43 @@ public: PluginsList(); ~PluginsList(); - GList* getList() { return m_pluginsList;} + GList* getList() {return m_pluginsList;} GList* getSortedByRank(); GList* getPluginListByCaps(GstPadDirection direction, GstCaps* caps); private: void init(); -GList* m_pluginsList; + GList* m_pluginsList; }; - class PluginsListDialog: public QDialog { -Q_OBJECT + Q_OBJECT public: - PluginsListDialog(PluginsList* pluginList, QWidget *pwgt = NULL, Qt::WindowFlags f = Qt::Window); + PluginsListDialog(PluginsList* pluginList, QWidget *pwgt = NULL, Qt::WindowFlags f = Qt::Window); ~PluginsListDialog(); - void setGraph(GraphManager* graph) { m_pGraph = graph;} + void setGraph(GraphManager* graph) {m_pGraph = graph;} protected: - bool eventFilter(QObject *obj, QEvent *ev); + bool eventFilter(QObject *obj, QEvent *ev); private: - void InitPluginsList(); + void InitPluginsList(); public slots: - void showInfo(QListWidgetItem *current, QListWidgetItem *previous); - void insert(QListWidgetItem *); + void showInfo(QListWidgetItem *current, QListWidgetItem *previous); + void insert(QListWidgetItem *); private slots: - void filterPlagins(const QString &text); + void filterPlagins(const QString &text); private: - QLabel *m_plblInfo; - QListWidget *m_pPlugins; - PluginsList *m_pPluginsList; - GraphManager *m_pGraph; + QLabel *m_plblInfo; + QListWidget *m_pPlugins; + PluginsList *m_pPluginsList; + GraphManager *m_pGraph; }; - - - #endif diff --git a/src/SeekSlider.cpp b/src/SeekSlider.cpp index 5636c5b..35511e9 100644 --- a/src/SeekSlider.cpp +++ b/src/SeekSlider.cpp @@ -1,16 +1,19 @@ #include "SeekSlider.h" -void SeekSlider::mousePressEvent(QMouseEvent *event) +void +SeekSlider::mousePressEvent (QMouseEvent *event) { - if(event->button() == Qt::LeftButton) - { - if(orientation() == Qt::Vertical) - setValue(minimum() + ((maximum()-minimum()) * (height()-event->y())) / height() ) ; - else - setValue(minimum() + ((maximum()-minimum()) * event->x()) / width() ) ; + if (event->button () == Qt::LeftButton) { + if (orientation () == Qt::Vertical) + setValue (minimum () + + ((maximum () - minimum ()) * (height () - event->y ())) / height ()); + else + setValue (minimum () + + ((maximum () - minimum ()) * event->x ()) / width ()); - event->accept(); - } + event->accept (); + } - QSlider::mousePressEvent(event); -}; + QSlider::mousePressEvent (event); +} +; diff --git a/src/SeekSlider.h b/src/SeekSlider.h index ae3f7ba..3e60f4c 100644 --- a/src/SeekSlider.h +++ b/src/SeekSlider.h @@ -1,16 +1,13 @@ #ifndef SEEK_SLIDER_H_ #define SEEK_SLIDER_H_ - #include #include class SeekSlider: public QSlider { - protected: - void mousePressEvent(QMouseEvent *); +protected: + void mousePressEvent(QMouseEvent *); }; - - #endif diff --git a/src/main.cpp b/src/main.cpp index d6c6831..7c4145c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,22 +3,23 @@ #include -int main(int argc, char **argv) +int +main (int argc, char **argv) { - gst_init (&argc, &argv); + gst_init (&argc, &argv); - GstRegistry *registry; + GstRegistry *registry; #if GST_VERSION_MAJOR >= 1 - registry = gst_registry_get(); + registry = gst_registry_get(); #else - registry = gst_registry_get_default(); + registry = gst_registry_get_default (); #endif - gst_registry_scan_path(registry, "./plugins"); + gst_registry_scan_path (registry, "./plugins"); - QApplication app(argc, argv); + QApplication app (argc, argv); - MainWindow wgt; - wgt.show(); + MainWindow wgt; + wgt.show (); - return app.exec(); + return app.exec (); }