From 11ab47ffde6a9501b4cd061679587912d8921233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Cerveau?= Date: Wed, 31 May 2017 23:13:34 +0200 Subject: [PATCH] Introduce logger class GraphManager is now using pipeviz category Logger class is able to read GST logs. Ony WARN and ERROR are logged now. --- pipeviz.pri | 6 +- src/CustomSettings.cpp | 19 ++++ src/CustomSettings.h | 3 + src/ElementProperties.cpp | 7 +- src/GraphDisplay.cpp | 16 ++- src/GraphManager.cpp | 41 ++++---- src/GraphManager.h | 2 + src/Logger.cpp | 208 ++++++++++++++++++++++++++++++++++++++ src/Logger.h | 46 +++++++++ src/MainWindow.cpp | 110 +++++++++++++------- src/MainWindow.h | 12 +++ src/PadProperties.cpp | 1 - src/PipelineIE.cpp | 17 ++-- src/PluginsList.cpp | 18 ++-- src/main.cpp | 1 + 15 files changed, 418 insertions(+), 89 deletions(-) create mode 100644 src/Logger.cpp create mode 100644 src/Logger.h diff --git a/pipeviz.pri b/pipeviz.pri index 63c85ab..d7f5bbf 100644 --- a/pipeviz.pri +++ b/pipeviz.pri @@ -29,7 +29,8 @@ HEADERS += src/PluginsList.h \ src/PipelineIE.h \ src/CustomSettings.h \ src/SeekSlider.h \ - src/CustomMenuAction.h + src/CustomMenuAction.h \ + src/Logger.h SOURCES += src/main.cpp \ src/PluginsList.cpp \ @@ -41,4 +42,5 @@ SOURCES += src/main.cpp \ src/PipelineIE.cpp \ src/CustomSettings.cpp \ src/SeekSlider.cpp \ - src/CustomMenuAction.cpp + src/CustomMenuAction.cpp \ + src/Logger.cpp \ No newline at end of file diff --git a/src/CustomSettings.cpp b/src/CustomSettings.cpp index 2b815fa..f43361d 100644 --- a/src/CustomSettings.cpp +++ b/src/CustomSettings.cpp @@ -37,3 +37,22 @@ CustomSettings::mainWindowGeometry () QSettings settings (COMPANY_NAME, APPLICATION_NAME); return settings.value ("geometry").toByteArray (); } + +void +CustomSettings::saveGstDebugString (const QString &string) +{ + QSettings settings (COMPANY_NAME, APPLICATION_NAME); + settings.setValue ("gst_log_string", string); +} + +QString +CustomSettings::lastGstDebugString () +{ + QSettings settings (COMPANY_NAME, APPLICATION_NAME); + QString res = settings.value ("gst_log_string").toString (); + + if (res.isEmpty ()) + res = "GST_DEBUG=*:5"; + + return res; +} diff --git a/src/CustomSettings.h b/src/CustomSettings.h index 8295f24..3a436c2 100644 --- a/src/CustomSettings.h +++ b/src/CustomSettings.h @@ -9,6 +9,9 @@ namespace CustomSettings void saveLastIODirectory(const QString &name); QString lastIODirectory(); + void saveGstDebugString(const QString &name); + QString lastGstDebugString(); + void saveMainWindowGeometry(const QByteArray &geometry); QByteArray mainWindowGeometry(); } diff --git a/src/ElementProperties.cpp b/src/ElementProperties.cpp index 1419aac..e530ef9 100644 --- a/src/ElementProperties.cpp +++ b/src/ElementProperties.cpp @@ -1,6 +1,5 @@ #include "ElementProperties.h" -#include #include #include #include @@ -188,7 +187,7 @@ ElementProperties::addParamSimple (GParamSpec *param, GstElement *element, default: { skip = true; - qDebug () << "property " << propertyName << " not supported"; + LOG_INFO("property " + propertyName + " not supported"); break; } }; @@ -283,7 +282,7 @@ ElementProperties::applyClicked () G_OBJECT_GET_CLASS (element), itr.key ().toStdString ().c_str ()); if (!param) { - qDebug () << "problem with setting " << itr.key () << " property"; + LOG_INFO("problem with setting " + itr.key () + " property"); continue; } @@ -373,7 +372,7 @@ ElementProperties::applyClicked () break; } default: { - qDebug () << "property " << itr.key () << " not supported"; + LOG_INFO("property " + itr.key () + " not supported"); break; } }; diff --git a/src/GraphDisplay.cpp b/src/GraphDisplay.cpp index 7b2bfca..11be4c1 100644 --- a/src/GraphDisplay.cpp +++ b/src/GraphDisplay.cpp @@ -11,8 +11,6 @@ #include #include -#include - #include "ElementProperties.h" #include "PadProperties.h" #include "CustomMenuAction.h" @@ -359,15 +357,15 @@ GraphDisplay::mouseReleaseEvent (QMouseEvent *event) break; } if (!infoSrc.m_name.compare (infoDst.m_name)) { - qDebug () << "infoSrc == infoDst. No need to connect anything."; + LOG_INFO("infoSrc == infoDst. No need to connect anything"); goto exit; } assert(srcPad != NULL && dstPad != NULL); - qDebug () << "Connection from " << infoSrc.m_name.c_str () << ":" - << srcPad << " to " << infoDst.m_name.c_str () << ":" << dstPad; + LOG_INFO("Connection from " + QString(infoSrc.m_name.c_str ()) + ":" + + srcPad + " to " + QString(infoDst.m_name.c_str ()) + ":" + dstPad); if (!m_pGraph->Connect (infoSrc.m_name.c_str (), srcPad, infoDst.m_name.c_str (), dstPad)) { @@ -385,7 +383,7 @@ GraphDisplay::mouseReleaseEvent (QMouseEvent *event) updateDisplayInfoIds (); if (g_str_has_prefix (infoDst.m_name.c_str (), "decodebin")) { m_pGraph->Play (); - qDebug () << "Launch play to discover the new pad"; + LOG_INFO("Launch play to discover the new pad"); } } } @@ -681,7 +679,7 @@ GraphDisplay::renderPad (std::size_t elementId, std::size_t padId, bool capsAny) PadInfo* pad = getPad (elementId, padId); if (!element || !pad) - qDebug () << "element or pad is unreachable"; + LOG_INFO("element or pad is unreachable"); PluginsList* pluginList = new PluginsList (); GList* plugins_list = pluginList->getSortedByRank (); @@ -750,8 +748,8 @@ GraphDisplay::disconnect (size_t elementId, size_t padId) } } - qDebug () << "Disconnect " << src.c_str () << ":" << srcPad.c_str () - << " <-> " << dst.c_str () << ":" << dstPad.c_str (); + LOG_INFO("Disconnect " + QString(src.c_str ()) + ":" + srcPad.c_str() + + " <-> " + dst.c_str () + ":" + dstPad.c_str ()); if (src.empty () || dst.empty () || srcPad.empty () || dstPad.empty ()) return; diff --git a/src/GraphManager.cpp b/src/GraphManager.cpp index 8eed443..aeaeccb 100644 --- a/src/GraphManager.cpp +++ b/src/GraphManager.cpp @@ -1,7 +1,7 @@ #include "GraphManager.h" #include "PluginsList.h" -#include +#include "MainWindow.h" #include #include #include @@ -9,6 +9,9 @@ #include "CustomSettings.h" +GST_DEBUG_CATEGORY_STATIC(pipeviz_debug); +#define GST_CAT_DEFAULT pipeviz_debug + #define MAX_STR_CAPS_SIZE 150 gchar* get_str_caps_limited (gchar* str) @@ -30,8 +33,7 @@ typefind_have_type_callback (GstElement * typefind, guint probability, { Q_UNUSED(typefind); gchar *caps_description = gst_caps_to_string (caps); - qDebug () << "Found caps " << caps_description << " with probability " - << probability; + GST_DEBUG_OBJECT(thiz, "Found caps %s with probability %d",caps_description, probability); g_free (caps_description); thiz->Pause (); } @@ -39,7 +41,10 @@ typefind_have_type_callback (GstElement * typefind, guint probability, GraphManager::GraphManager () { m_pGraph = gst_pipeline_new ("pipeline"); + GST_DEBUG_CATEGORY_INIT(pipeviz_debug, "pipeviz", 0, "Pipeline vizualizer"); + m_pluginsList = new PluginsList (); + GST_WARNING("init"); } GraphManager::~GraphManager () @@ -145,7 +150,7 @@ GraphManager::AddPlugin (const char *plugin, const char *name) gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL); if (uri) { - qDebug () << "Set uri: " << uri; + GST_DEBUG("Set uri: %s", uri); #if GST_VERSION_MAJOR >= 1 gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL); #else @@ -162,7 +167,7 @@ GraphManager::AddPlugin (const char *plugin, const char *name) QString uri = QInputDialog::getText (NULL, "Uri...", "Uri:"); if (!uri.isEmpty ()) { - qDebug () << "Set uri: " << uri; + GST_DEBUG("Set uri: %s", uri.toStdString ().c_str ()); #if GST_VERSION_MAJOR >= 1 gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL); #else @@ -430,7 +435,7 @@ GraphManager::Play () if (res != GST_STATE_CHANGE_SUCCESS) { gst_element_abort_state (m_pGraph); - qDebug () << "state changing to Play was FAILED"; + GST_WARNING("state changing to Play was FAILED"); } return state == GST_STATE_PLAYING; @@ -446,7 +451,7 @@ GraphManager::Pause () 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"; + GST_WARNING("state changing to Pause was FAILED"); } return state == GST_STATE_PAUSED; @@ -539,60 +544,58 @@ GraphManager::CanConnect (const char *srcName, const char *srcPadName, src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcName); if (!src) { - qDebug () << "Unable to get the src element: " << srcName; + GST_DEBUG("Unable to get the src element: %s",srcName); goto done; } srcPad = gst_element_get_static_pad (src, srcPadName); if (!srcPad) { - qDebug () << "Unable to get the src pad"; + GST_DEBUG("Unable to get the src pad: %s",srcPadName); goto done; } srcCaps = gst_pad_get_current_caps (srcPad); if (!srcCaps) { - qDebug () << "Unable to get the current caps for pad:" << srcPadName; + GST_DEBUG("Unable to get the current caps for pad: %s",srcPadName); srcCaps = gst_pad_get_pad_template_caps (srcPad); if (!srcCaps) { - qDebug () << "Unable to get the template caps for pad:" << srcPadName; + GST_DEBUG("Unable to get the template caps for pad: %s",srcPadName); goto done; } } dest = gst_element_factory_make (destName, NULL); if (!dest) { - qDebug () << "Unable to get the dest element: " << destName; + GST_DEBUG("Unable to get the dest element: %s",destName); goto done; } destFactory = gst_element_get_factory (dest); if (!destFactory) { - qDebug () << "Unable to get the dest factory"; + GST_DEBUG("Unable to get the factory for dest element %s",destName); goto done; } if (noANY && gst_element_factory_can_sink_any_caps (destFactory, srcCaps)) { - qDebug () << "The dest element " << destName << " can sink any caps"; + GST_DEBUG("The dest element %s can sink any caps",destName); 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; + GST_DEBUG("The dest element %s can not sink this caps %s",destName, caps_string); g_free (caps_string); goto done; } added = gst_bin_add (GST_BIN (m_pGraph), dest); if (!added) { - qDebug () << "Unable to add element to the bin"; + GST_DEBUG("Unable to add element %s to the bin", destName); goto done; } ret = gst_element_link (src, dest); if (ret) { - qDebug () << "Can link elements src " << GST_OBJECT_NAME (src) - << " with dest " << GST_OBJECT_NAME (dest); + GST_INFO("Can link elements src %s with dest %s", GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest)); gst_element_unlink (src, dest); } diff --git a/src/GraphManager.h b/src/GraphManager.h index 6f9ac33..3da2127 100644 --- a/src/GraphManager.h +++ b/src/GraphManager.h @@ -1,6 +1,8 @@ #ifndef GRAPH_MANAGER_H_ #define GRAPH_MANAGER_H_ +#include "Logger.h" + #include #include diff --git a/src/Logger.cpp b/src/Logger.cpp new file mode 100644 index 0000000..f8fbf2a --- /dev/null +++ b/src/Logger.cpp @@ -0,0 +1,208 @@ +/* + * Logger.cpp + * + * Created on: 31 mai 2017 + * Author: scerveau + */ +#include "Logger.h" + +#include "CustomSettings.h" + +#include +#include + +void +Logger::configure_logger () +{ + QString lastGstDebugString = CustomSettings::lastGstDebugString (); + setenv (lastGstDebugString.split ("=").at (0).toStdString ().c_str (), lastGstDebugString.split ("=").at (1).toStdString ().c_str (), 1); + setenv ("GST_DEBUG_NO_COLOR", "1", 1); + setenv ("GST_DEBUG_FILE", "/tmp/gst_pipeviz.txt", 1); +} + +Logger::Logger() +: QThread(), +m_fExit(false) +{ +} + +Logger& Logger::instance() +{ + static Logger instance; + return instance; +} + +void Logger::Quit() +{ + m_fExit = true; + wait(); +} + +void Logger::processLog(const QString& line) +{ + emit sendLog(line,eLOG_CATEGORY_INTERNAL); +} + +//#define GST_TIME_FORMAT "u:%02u:%02u.%09u" +#define GST_TIME_FORMAT "%s" +#define PRINT_FMT " "PID_FMT" "PTR_FMT" %s "CAT_FMT" %s\n" + +struct GSTLog { + gchar* date; + gchar* pid; + gchar* level; + gchar* category; + gchar* file; + gchar* line; + gchar* function; + gchar* obj; + gchar* message; +}; + +void Logger::processGstLog(gchar* log) +{ +// GSTLog gstLog; + if(!g_strrstr(log,"WARN") && !g_strrstr(log,"ERROR")) + return; +/* GList* stringList = parseGstLine(log, ' ', 6); + GList* l; + + gstLog.date = g_strdup((gchar*)g_list_nth_data(stringList, 0)); + gstLog.pid = g_strdup((gchar*)g_list_nth_data(stringList, 1)); + gstLog.level = g_strdup((gchar*)g_list_nth_data(stringList, 2)); + gstLog.category = g_strdup((gchar*)g_list_nth_data(stringList, 3)); + + gstLog.file = g_strdup((gchar*)g_list_nth_data(stringList, 4)); + gstLog.line = g_strdup((gchar*)g_list_nth_data(stringList, 5)); + gstLog.function = g_strdup((gchar*)g_list_nth_data(stringList, 6)); + gstLog.obj = g_strdup((gchar*)g_list_nth_data(stringList, 7)); + + QString message = ""; + for (l = stringList; l != NULL; l = l->next) { + message += (gchar*)l->data; + message += " "; + } +*/ + emit sendLog(log,eLOG_CATEGORY_GST); +} + +#define MAX_LINE_LENGTH 128 + +GList* Logger::parseGstLine(gchar* line, gchar delimiter, int max_fields) +{ + int count = 0; + size_t pos = 0; + char *lineBuffer = NULL; + + gboolean new_string=TRUE; + GList* strList = NULL; + gint n_fields = 0; + + int maximumLineLength = MAX_LINE_LENGTH; + + if (line == NULL) + return NULL; + + do { + if (new_string) { + if (line[pos] != delimiter) { + new_string = FALSE; + lineBuffer = (gchar *)malloc(sizeof(char) * maximumLineLength); + count=0; + lineBuffer[count++] = line[pos]; + } + } + else { + if (count == MAX_LINE_LENGTH) { + maximumLineLength += MAX_LINE_LENGTH; + lineBuffer = (gchar*)realloc(lineBuffer, maximumLineLength); + } + if (line[pos] == delimiter || line[pos] == '\0') { + lineBuffer[count] = '\0'; + new_string= TRUE; + strList = g_list_append(strList, g_strdup(lineBuffer)); + g_free(lineBuffer); + n_fields++; + if (max_fields != -1 && n_fields == max_fields) { + pos++; + if (pos < strlen(line)) + strList = g_list_append(strList, g_strdup(&line[pos])); + break; + } + } else { + lineBuffer[count++] = line[pos]; + } + + } + pos++; + } while (pos < strlen(line)); + + + return strList; +} + +gchar *Logger::readGstLine(FILE *file) +{ + int count = 0; + char ch; + char *line = NULL; + gchar *lineBuffer = NULL; + int maximumLineLength = MAX_LINE_LENGTH; + + if (file == NULL) + goto beach; + + lineBuffer = (gchar *)malloc(sizeof(char) * maximumLineLength); + if (lineBuffer == NULL) + goto beach; + + + ch = getc(file); + while ((ch != '\n') && (ch != EOF)) { + if (count == maximumLineLength) { + maximumLineLength += MAX_LINE_LENGTH; + lineBuffer = (gchar*)realloc(lineBuffer, maximumLineLength); + if (lineBuffer == NULL) + goto beach; + } + lineBuffer[count] = ch; + count++; + + ch = getc(file); + } + if(count==0) + goto beach; + + lineBuffer[count] = '\0'; + lineBuffer = (gchar*)realloc(lineBuffer, count + 1); + line = g_strdup(lineBuffer); + //qDebug() << lineBuffer; + //qDebug() << line; +beach: + g_free(lineBuffer); + return line; +} + +void Logger::run() +{ + FILE* file; + gchar* line; + + file = fopen("/tmp/gst_pipeviz.txt", "r"); + if(!file) + return; + + while (!m_fExit) { + line = readGstLine(file); + if (line != NULL) { + processGstLog(line); + g_free(line); + } + //usleep(10); + } + + qDebug() << "Logger closed"; + + fclose(file); + +} diff --git a/src/Logger.h b/src/Logger.h new file mode 100644 index 0000000..64d4183 --- /dev/null +++ b/src/Logger.h @@ -0,0 +1,46 @@ +/* + * Logger.h + * + * Created on: 31 mai 2017 + * Author: scerveau + */ + +#ifndef LOGGER_H_ +#define LOGGER_H_ + +#include +#include "glib.h" + +enum eLogCategory { + eLOG_CATEGORY_INTERNAL, + eLOG_CATEGORY_GST, + eLOG_CATEGORY_EVENTS, +}; + +#define LOG_INFO(x) Logger::instance().processLog(x) + +class Logger : public QThread { + Q_OBJECT +public: + Logger(); + void configure_logger(); + + static Logger& instance(); + void Quit(); + + void processLog(const QString& line); + +protected: + void processGstLog(gchar* line); + gchar* readGstLine(FILE *file); + GList* parseGstLine(gchar* line, gchar ch = ' ', int max_field = -1); + +signals: + void sendLog(const QString& message, int category); + +private: + void run(); + bool m_fExit; +}; + +#endif /* LOGGER_H_ */ diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 31a67b4..9c11cd2 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -21,12 +20,11 @@ #include #include #include +#include -#include - +#include "CustomSettings.h" #include "GraphDisplay.h" #include "PipelineIE.h" -#include "CustomSettings.h" #include "SeekSlider.h" #include "version_info.h" @@ -117,46 +115,46 @@ m_pGraph (new GraphManager) connect(m_pslider, SIGNAL(valueChanged(int)), SLOT(Seek(int))); ptb->addWidget (m_pslider); - QMenu *pmenu = menuBar ()->addMenu ("&File"); + m_menu = menuBar ()->addMenu ("&File"); - QAction *pactOpen = pmenu->addAction ("Open...", this, SLOT (Open ()), + QAction *pactOpen = m_menu->addAction ("Open...", this, SLOT (Open ()), QKeySequence::Open); addAction (pactOpen); - QAction *pactOpenMediaFile = pmenu->addAction ("Open Media File...", this, + QAction *pactOpenMediaFile = m_menu->addAction ("Open Media File...", this, SLOT (OpenMediaFile ()), QKeySequence::Open); addAction (pactOpenMediaFile); - QAction *pactSave = pmenu->addAction ("Save", this, SLOT (Save ()), + QAction *pactSave = m_menu->addAction ("Save", this, SLOT (Save ()), QKeySequence::Save); addAction (pactSave); - QAction *pactSaveAs = pmenu->addAction ("Save As...", this, SLOT (SaveAs ()), + QAction *pactSaveAs = m_menu->addAction ("Save As...", this, SLOT (SaveAs ()), QKeySequence::SaveAs); addAction (pactSaveAs); - pmenu->addSeparator (); - pmenu->addAction ("Exit", this, SLOT (close ())); + m_menu->addSeparator (); + m_menu->addAction ("Exit", this, SLOT (close ())); - pmenu = menuBar ()->addMenu ("&Graph"); + m_menu = 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); + m_menu->addAction (pactAdd); + m_menu->addAction (pactOpenMediaFile); + m_menu->addAction ("Open Media Uri...", this, SLOT (OpenMediaUri ())); + m_menu->addSeparator (); + m_menu->addAction (pactPlay); + m_menu->addAction (pactPause); + m_menu->addAction (pactStop); + m_menu->addAction (pactFlush); + m_menu->addSeparator (); + m_menu->addAction (pactClear); - pmenu = menuBar ()->addMenu ("&Help"); + m_menu = menuBar ()->addMenu ("&Help"); - pmenu->addAction ("About pipeviz...", this, SLOT (About ())); + m_menu->addAction ("About pipeviz...", this, SLOT (About ())); - m_pGraphDisplay = new GraphDisplay; + m_pGraphDisplay = new GraphDisplay(this); QScrollArea *pscroll = new QScrollArea; pscroll->setWidget (m_pGraphDisplay); @@ -169,12 +167,54 @@ m_pGraph (new GraphManager) m_pluginListDlg = new PluginsListDialog (m_pGraph->getPluginsList (), this); m_pluginListDlg->setModal (false); restoreGeometry (CustomSettings::mainWindowGeometry ()); + createDockWindows(); + + Logger::instance().start(); + connect(&Logger::instance(), SIGNAL(sendLog(const QString &, int)), + this, SLOT(InsertLogLine(const QString &, int))); + + LOG_INFO("Mainwindow is now initialized"); + startTimer (100); } +void MainWindow::createDockWindows() +{ + QDockWidget *dock = new QDockWidget(tr("logs"), this); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + m_logList = new QListWidget(dock); + dock->setWidget(m_logList); + addDockWidget(Qt::BottomDockWidgetArea, dock); + m_menu->addAction(dock->toggleViewAction()); + +} + +void MainWindow::InsertLogLine(const QString& line, int category) +{ + QListWidgetItem* pItem =new QListWidgetItem(line); + switch(category) { + case eLOG_CATEGORY_INTERNAL: + pItem->setForeground(Qt::blue); + break; + case eLOG_CATEGORY_GST: + pItem->setForeground(Qt::red); + break; + default: + pItem->setForeground(Qt::black); + } + m_logList->addItem(pItem); +} + +MainWindow& MainWindow::instance() +{ + static MainWindow instance; + return instance; +} + MainWindow::~MainWindow () { CustomSettings::saveMainWindowGeometry (saveGeometry ()); + Logger::instance().Quit(); delete m_pluginListDlg; } @@ -182,6 +222,8 @@ void MainWindow::AddPlugin () { m_pluginListDlg->setGraph (m_pGraph.data ()); + + m_pluginListDlg->raise (); m_pluginListDlg->show (); std::vector info = m_pGraph->GetInfo (); m_pGraphDisplay->update (info); @@ -196,7 +238,7 @@ MainWindow::OpenMediaFile () if (!path.isEmpty ()) { gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL); if (uri) { - qDebug () << "Open Source file: " << path; + LOG_INFO("Open Source file: " + path);; m_pGraph->OpenUri (uri, NULL); g_free (uri); @@ -216,7 +258,7 @@ MainWindow::OpenMediaUri () QString uri = QInputDialog::getText (this, "Open Uri...", "Uri:"); if (!uri.isEmpty ()) { - qDebug () << "Open uri: " << uri; + LOG_INFO("Open uri: "+ uri); m_pGraph->OpenUri (uri.toStdString ().c_str (), NULL); std::vector info = m_pGraph->GetInfo (); @@ -228,28 +270,28 @@ MainWindow::OpenMediaUri () void MainWindow::Play () { - qDebug () << "Play"; + LOG_INFO( "Play"); m_pGraph->Play (); } void MainWindow::Pause () { - qDebug () << "Pause"; + LOG_INFO("Pause"); m_pGraph->Pause (); } void MainWindow::Stop () { - qDebug () << "Stop"; + LOG_INFO("Stop"); m_pGraph->Stop (); } void MainWindow::Flush () { - qDebug () << "Flush"; + LOG_INFO("Flush"); if (m_pGraph->m_pGraph) { gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph), @@ -266,7 +308,7 @@ MainWindow::Flush () void MainWindow::ClearGraph () { - qDebug () << "ClearGraph"; + LOG_INFO("ClearGraph"); PipelineIE::Clear (m_pGraph); } @@ -274,9 +316,9 @@ void MainWindow::Seek (int val) { if (m_pGraph->SetPosition ((double) (val) / m_pslider->maximum ())) - qDebug () << "Seek to" << val; + LOG_INFO("Seek to" + val); else - qDebug () << "Seek to" << val << "was FAILED"; + LOG_INFO("Seek FAILED"); } void diff --git a/src/MainWindow.h b/src/MainWindow.h index bcf314a..f3bb685 100644 --- a/src/MainWindow.h +++ b/src/MainWindow.h @@ -7,16 +7,19 @@ #include #include #include +#include #include #include #include #include "GraphManager.h" +#include "Logger.h" class GraphDisplay; class PluginsListDialog; + class MainWindow: public QMainWindow { Q_OBJECT @@ -24,8 +27,14 @@ public: MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0); ~MainWindow(); + static MainWindow& instance(); + protected: void timerEvent(QTimerEvent *); + void createDockWindows(); + +public slots: + void InsertLogLine(const QString& line, int category); private slots: void AddPlugin(); @@ -46,6 +55,7 @@ private slots: private: QSharedPointer m_pGraph; + GraphDisplay *m_pGraphDisplay; QStatusBar *m_pstatusBar; @@ -53,6 +63,8 @@ private: QString m_fileName; PluginsListDialog *m_pluginListDlg; + QMenu *m_menu; + QListWidget* m_logList; }; #endif diff --git a/src/PadProperties.cpp b/src/PadProperties.cpp index a207565..23cb316 100644 --- a/src/PadProperties.cpp +++ b/src/PadProperties.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include diff --git a/src/PipelineIE.cpp b/src/PipelineIE.cpp index 3b53902..88001a3 100644 --- a/src/PipelineIE.cpp +++ b/src/PipelineIE.cpp @@ -7,7 +7,6 @@ #include -#include static void clearPipeline (GstElement *pipeline) @@ -142,9 +141,8 @@ writeProperties (QXmlStreamWriter &xmlWriter, const GstElement *element) } default: { gchar *elementName = gst_element_get_name (element); - - qDebug () << "property `" << propertyName << "` for `" - << elementName << "` not supported"; + LOG_INFO(QString("property `" + propertyName + "` for `" + + elementName + "` not supported")); g_free (elementName); skip = true; @@ -183,8 +181,8 @@ loadProperties (QDomElement node, GstElement *element) if (!param) { gchar *elementName = gst_element_get_name (element); - qDebug () << "problem with setting property `" << name << "` for `" - << elementName << "`"; + LOG_INFO(QString("problem with setting property `" + name + "` for `" + + elementName + "`")); g_free (elementName); continue; } @@ -247,8 +245,8 @@ loadProperties (QDomElement node, GstElement *element) } default: { gchar *elementName = gst_element_get_name (element); - qDebug () << "property `" << name << "` for `" - << QString (elementName) << "` not supported"; + LOG_INFO(QString("property `" + name + "` for `" + + QString (elementName) + "` not supported")); g_free (elementName); break; } @@ -330,8 +328,7 @@ PipelineIE::Export (QSharedPointer pgraph, GST_PAD_TEMPLATE_NAME_TEMPLATE (templ)); } else { - qDebug () << "Unable to find a template for" - << info[i].m_pads[j].m_name.c_str (); + LOG_INFO(QString("Unable to find a template for") + QString(info[i].m_pads[j].m_name.c_str())); xmlWriter.writeAttribute ("presence", "always"); xmlWriter.writeAttribute ("template-name", ""); } diff --git a/src/PluginsList.cpp b/src/PluginsList.cpp index 11f2d7a..d43f664 100644 --- a/src/PluginsList.cpp +++ b/src/PluginsList.cpp @@ -12,14 +12,12 @@ #include -#include - 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 (); + LOG_INFO("Sort p1: " + p1->getName () + " and p2: " + p2->getName ()); if (p1->getRank () > p2->getRank ()) return 1; else if (p1->getRank () == p2->getRank ()) { @@ -173,7 +171,7 @@ void PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous) { Q_UNUSED(previous); - qDebug () << "Show Info: " << pitem->text (); + LOG_INFO("Show Info: " + pitem->text ()); m_plblInfo->clear (); QString descr; descr += "Plugin details
"; @@ -181,14 +179,14 @@ PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous) GstElementFactory *factory = gst_element_factory_find ( pitem->text ().toStdString ().c_str ()); if (!factory) { - qDebug () << "warning: " << pitem->text () << " Not Found"; + LOG_INFO("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"; + LOG_INFO("warning: " + pitem->text () + " Not Found"); return; } #if GST_VERSION_MAJOR >= 1 @@ -201,7 +199,7 @@ PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous) GstPlugin* plugin = gst_default_registry_find_plugin (plugin_name); #endif if (!plugin) { - qDebug () << "warning: " << pitem->text () << " Not Found"; + LOG_INFO("warning: " + pitem->text () + " Not Found"); return; } @@ -258,17 +256,17 @@ void PluginsListDialog::insert (QListWidgetItem *pitem) { if (!pitem) { - qDebug () << "Do not insert null item"; + LOG_INFO("Do not insert null item"); return; } - qDebug () << "Insert: " << pitem->text (); + LOG_INFO("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"; + LOG_INFO("Plugin `" + pitem->text () + "` insertion FAILED"); return; } } diff --git a/src/main.cpp b/src/main.cpp index 7c4145c..bc24e1f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ int main (int argc, char **argv) { + Logger::instance().configure_logger (); gst_init (&argc, &argv); GstRegistry *registry;