Introduce logger class

GraphManager is now using pipeviz category
Logger class is able to read GST logs.
Ony WARN and ERROR are logged now.
This commit is contained in:
Stéphane Cerveau 2017-05-31 23:13:34 +02:00
parent fc3d259a39
commit 11ab47ffde
15 changed files with 418 additions and 89 deletions

View file

@ -29,7 +29,8 @@ HEADERS += src/PluginsList.h \
src/PipelineIE.h \ src/PipelineIE.h \
src/CustomSettings.h \ src/CustomSettings.h \
src/SeekSlider.h \ src/SeekSlider.h \
src/CustomMenuAction.h src/CustomMenuAction.h \
src/Logger.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/PluginsList.cpp \ src/PluginsList.cpp \
@ -41,4 +42,5 @@ SOURCES += src/main.cpp \
src/PipelineIE.cpp \ src/PipelineIE.cpp \
src/CustomSettings.cpp \ src/CustomSettings.cpp \
src/SeekSlider.cpp \ src/SeekSlider.cpp \
src/CustomMenuAction.cpp src/CustomMenuAction.cpp \
src/Logger.cpp

View file

@ -37,3 +37,22 @@ CustomSettings::mainWindowGeometry ()
QSettings settings (COMPANY_NAME, APPLICATION_NAME); QSettings settings (COMPANY_NAME, APPLICATION_NAME);
return settings.value ("geometry").toByteArray (); 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;
}

View file

@ -9,6 +9,9 @@ namespace CustomSettings
void saveLastIODirectory(const QString &name); void saveLastIODirectory(const QString &name);
QString lastIODirectory(); QString lastIODirectory();
void saveGstDebugString(const QString &name);
QString lastGstDebugString();
void saveMainWindowGeometry(const QByteArray &geometry); void saveMainWindowGeometry(const QByteArray &geometry);
QByteArray mainWindowGeometry(); QByteArray mainWindowGeometry();
} }

View file

@ -1,6 +1,5 @@
#include "ElementProperties.h" #include "ElementProperties.h"
#include <QDebug>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLineEdit> #include <QLineEdit>
#include <QString> #include <QString>
@ -188,7 +187,7 @@ ElementProperties::addParamSimple (GParamSpec *param, GstElement *element,
default: { default: {
skip = true; skip = true;
qDebug () << "property " << propertyName << " not supported"; LOG_INFO("property " + propertyName + " not supported");
break; break;
} }
}; };
@ -283,7 +282,7 @@ ElementProperties::applyClicked ()
G_OBJECT_GET_CLASS (element), itr.key ().toStdString ().c_str ()); G_OBJECT_GET_CLASS (element), itr.key ().toStdString ().c_str ());
if (!param) { if (!param) {
qDebug () << "problem with setting " << itr.key () << " property"; LOG_INFO("problem with setting " + itr.key () + " property");
continue; continue;
} }
@ -373,7 +372,7 @@ ElementProperties::applyClicked ()
break; break;
} }
default: { default: {
qDebug () << "property " << itr.key () << " not supported"; LOG_INFO("property " + itr.key () + " not supported");
break; break;
} }
}; };

View file

@ -11,8 +11,6 @@
#include <QTableWidget> #include <QTableWidget>
#include <QVariant> #include <QVariant>
#include <QDebug>
#include "ElementProperties.h" #include "ElementProperties.h"
#include "PadProperties.h" #include "PadProperties.h"
#include "CustomMenuAction.h" #include "CustomMenuAction.h"
@ -359,15 +357,15 @@ GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
break; break;
} }
if (!infoSrc.m_name.compare (infoDst.m_name)) { 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; goto exit;
} }
assert(srcPad != NULL && dstPad != NULL); assert(srcPad != NULL && dstPad != NULL);
qDebug () << "Connection from " << infoSrc.m_name.c_str () << ":" LOG_INFO("Connection from " + QString(infoSrc.m_name.c_str ()) + ":"
<< srcPad << " to " << infoDst.m_name.c_str () << ":" << dstPad; + srcPad + " to " + QString(infoDst.m_name.c_str ()) + ":" + dstPad);
if (!m_pGraph->Connect (infoSrc.m_name.c_str (), srcPad, if (!m_pGraph->Connect (infoSrc.m_name.c_str (), srcPad,
infoDst.m_name.c_str (), dstPad)) { infoDst.m_name.c_str (), dstPad)) {
@ -385,7 +383,7 @@ GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
updateDisplayInfoIds (); updateDisplayInfoIds ();
if (g_str_has_prefix (infoDst.m_name.c_str (), "decodebin")) { if (g_str_has_prefix (infoDst.m_name.c_str (), "decodebin")) {
m_pGraph->Play (); 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); PadInfo* pad = getPad (elementId, padId);
if (!element || !pad) if (!element || !pad)
qDebug () << "element or pad is unreachable"; LOG_INFO("element or pad is unreachable");
PluginsList* pluginList = new PluginsList (); PluginsList* pluginList = new PluginsList ();
GList* plugins_list = pluginList->getSortedByRank (); 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 () LOG_INFO("Disconnect " + QString(src.c_str ()) + ":" + srcPad.c_str()
<< " <-> " << dst.c_str () << ":" << dstPad.c_str (); + " <-> " + dst.c_str () + ":" + dstPad.c_str ());
if (src.empty () || dst.empty () || srcPad.empty () || dstPad.empty ()) if (src.empty () || dst.empty () || srcPad.empty () || dstPad.empty ())
return; return;

View file

@ -1,7 +1,7 @@
#include "GraphManager.h" #include "GraphManager.h"
#include "PluginsList.h" #include "PluginsList.h"
#include <QDebug>
#include "MainWindow.h"
#include <QString> #include <QString>
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
@ -9,6 +9,9 @@
#include "CustomSettings.h" #include "CustomSettings.h"
GST_DEBUG_CATEGORY_STATIC(pipeviz_debug);
#define GST_CAT_DEFAULT pipeviz_debug
#define MAX_STR_CAPS_SIZE 150 #define MAX_STR_CAPS_SIZE 150
gchar* gchar*
get_str_caps_limited (gchar* str) get_str_caps_limited (gchar* str)
@ -30,8 +33,7 @@ typefind_have_type_callback (GstElement * typefind, guint probability,
{ {
Q_UNUSED(typefind); Q_UNUSED(typefind);
gchar *caps_description = gst_caps_to_string (caps); gchar *caps_description = gst_caps_to_string (caps);
qDebug () << "Found caps " << caps_description << " with probability " GST_DEBUG_OBJECT(thiz, "Found caps %s with probability %d",caps_description, probability);
<< probability;
g_free (caps_description); g_free (caps_description);
thiz->Pause (); thiz->Pause ();
} }
@ -39,7 +41,10 @@ typefind_have_type_callback (GstElement * typefind, guint probability,
GraphManager::GraphManager () GraphManager::GraphManager ()
{ {
m_pGraph = gst_pipeline_new ("pipeline"); m_pGraph = gst_pipeline_new ("pipeline");
GST_DEBUG_CATEGORY_INIT(pipeviz_debug, "pipeviz", 0, "Pipeline vizualizer");
m_pluginsList = new PluginsList (); m_pluginsList = new PluginsList ();
GST_WARNING("init");
} }
GraphManager::~GraphManager () GraphManager::~GraphManager ()
@ -145,7 +150,7 @@ GraphManager::AddPlugin (const char *plugin, const char *name)
gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (),
NULL); NULL);
if (uri) { if (uri) {
qDebug () << "Set uri: " << uri; GST_DEBUG("Set uri: %s", uri);
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL); gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL);
#else #else
@ -162,7 +167,7 @@ GraphManager::AddPlugin (const char *plugin, const char *name)
QString uri = QInputDialog::getText (NULL, "Uri...", "Uri:"); QString uri = QInputDialog::getText (NULL, "Uri...", "Uri:");
if (!uri.isEmpty ()) { if (!uri.isEmpty ()) {
qDebug () << "Set uri: " << uri; GST_DEBUG("Set uri: %s", uri.toStdString ().c_str ());
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL); gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL);
#else #else
@ -430,7 +435,7 @@ GraphManager::Play ()
if (res != GST_STATE_CHANGE_SUCCESS) { if (res != GST_STATE_CHANGE_SUCCESS) {
gst_element_abort_state (m_pGraph); 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; return state == GST_STATE_PLAYING;
@ -446,7 +451,7 @@ GraphManager::Pause ()
res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND); res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND);
if (res != GST_STATE_CHANGE_SUCCESS) { if (res != GST_STATE_CHANGE_SUCCESS) {
gst_element_abort_state (m_pGraph); 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; 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); src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcName);
if (!src) { if (!src) {
qDebug () << "Unable to get the src element: " << srcName; GST_DEBUG("Unable to get the src element: %s",srcName);
goto done; goto done;
} }
srcPad = gst_element_get_static_pad (src, srcPadName); srcPad = gst_element_get_static_pad (src, srcPadName);
if (!srcPad) { if (!srcPad) {
qDebug () << "Unable to get the src pad"; GST_DEBUG("Unable to get the src pad: %s",srcPadName);
goto done; goto done;
} }
srcCaps = gst_pad_get_current_caps (srcPad); srcCaps = gst_pad_get_current_caps (srcPad);
if (!srcCaps) { 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); srcCaps = gst_pad_get_pad_template_caps (srcPad);
if (!srcCaps) { 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; goto done;
} }
} }
dest = gst_element_factory_make (destName, NULL); dest = gst_element_factory_make (destName, NULL);
if (!dest) { if (!dest) {
qDebug () << "Unable to get the dest element: " << destName; GST_DEBUG("Unable to get the dest element: %s",destName);
goto done; goto done;
} }
destFactory = gst_element_get_factory (dest); destFactory = gst_element_get_factory (dest);
if (!destFactory) { if (!destFactory) {
qDebug () << "Unable to get the dest factory"; GST_DEBUG("Unable to get the factory for dest element %s",destName);
goto done; goto done;
} }
if (noANY && gst_element_factory_can_sink_any_caps (destFactory, srcCaps)) { 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; goto done;
} }
if (!gst_element_factory_can_sink_all_caps (destFactory, srcCaps)) { if (!gst_element_factory_can_sink_all_caps (destFactory, srcCaps)) {
gchar* caps_string = gst_caps_to_string (srcCaps); gchar* caps_string = gst_caps_to_string (srcCaps);
qDebug () << "The dest element " << destName << " can not sink this caps: " GST_DEBUG("The dest element %s can not sink this caps %s",destName, caps_string);
<< caps_string;
g_free (caps_string); g_free (caps_string);
goto done; goto done;
} }
added = gst_bin_add (GST_BIN (m_pGraph), dest); added = gst_bin_add (GST_BIN (m_pGraph), dest);
if (!added) { if (!added) {
qDebug () << "Unable to add element to the bin"; GST_DEBUG("Unable to add element %s to the bin", destName);
goto done; goto done;
} }
ret = gst_element_link (src, dest); ret = gst_element_link (src, dest);
if (ret) { if (ret) {
qDebug () << "Can link elements src " << GST_OBJECT_NAME (src) GST_INFO("Can link elements src %s with dest %s", GST_OBJECT_NAME (src), GST_OBJECT_NAME (dest));
<< " with dest " << GST_OBJECT_NAME (dest);
gst_element_unlink (src, dest); gst_element_unlink (src, dest);
} }

View file

@ -1,6 +1,8 @@
#ifndef GRAPH_MANAGER_H_ #ifndef GRAPH_MANAGER_H_
#define GRAPH_MANAGER_H_ #define GRAPH_MANAGER_H_
#include "Logger.h"
#include <gst/gst.h> #include <gst/gst.h>
#include <string> #include <string>

208
src/Logger.cpp Normal file
View file

@ -0,0 +1,208 @@
/*
* Logger.cpp
*
* Created on: 31 mai 2017
* Author: scerveau
*/
#include "Logger.h"
#include "CustomSettings.h"
#include <QDebug>
#include <QStringList>
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);
}

46
src/Logger.h Normal file
View file

@ -0,0 +1,46 @@
/*
* Logger.h
*
* Created on: 31 mai 2017
* Author: scerveau
*/
#ifndef LOGGER_H_
#define LOGGER_H_
#include <QThread>
#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_ */

View file

@ -8,7 +8,6 @@
#include <QFileDialog> #include <QFileDialog>
#include <QMessageBox> #include <QMessageBox>
#include <QScopedArrayPointer> #include <QScopedArrayPointer>
#include <QDebug>
#include <QScrollArea> #include <QScrollArea>
#include <QLabel> #include <QLabel>
#include <QScrollArea> #include <QScrollArea>
@ -21,12 +20,11 @@
#include <QFileDialog> #include <QFileDialog>
#include <QInputDialog> #include <QInputDialog>
#include <QSettings> #include <QSettings>
#include <QDockWidget>
#include <QDebug> #include "CustomSettings.h"
#include "GraphDisplay.h" #include "GraphDisplay.h"
#include "PipelineIE.h" #include "PipelineIE.h"
#include "CustomSettings.h"
#include "SeekSlider.h" #include "SeekSlider.h"
#include "version_info.h" #include "version_info.h"
@ -117,46 +115,46 @@ m_pGraph (new GraphManager)
connect(m_pslider, SIGNAL(valueChanged(int)), SLOT(Seek(int))); connect(m_pslider, SIGNAL(valueChanged(int)), SLOT(Seek(int)));
ptb->addWidget (m_pslider); 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); QKeySequence::Open);
addAction (pactOpen); addAction (pactOpen);
QAction *pactOpenMediaFile = pmenu->addAction ("Open Media File...", this, QAction *pactOpenMediaFile = m_menu->addAction ("Open Media File...", this,
SLOT (OpenMediaFile ()), SLOT (OpenMediaFile ()),
QKeySequence::Open); QKeySequence::Open);
addAction (pactOpenMediaFile); addAction (pactOpenMediaFile);
QAction *pactSave = pmenu->addAction ("Save", this, SLOT (Save ()), QAction *pactSave = m_menu->addAction ("Save", this, SLOT (Save ()),
QKeySequence::Save); QKeySequence::Save);
addAction (pactSave); addAction (pactSave);
QAction *pactSaveAs = pmenu->addAction ("Save As...", this, SLOT (SaveAs ()), QAction *pactSaveAs = m_menu->addAction ("Save As...", this, SLOT (SaveAs ()),
QKeySequence::SaveAs); QKeySequence::SaveAs);
addAction (pactSaveAs); addAction (pactSaveAs);
pmenu->addSeparator (); m_menu->addSeparator ();
pmenu->addAction ("Exit", this, SLOT (close ())); m_menu->addAction ("Exit", this, SLOT (close ()));
pmenu = menuBar ()->addMenu ("&Graph"); m_menu = menuBar ()->addMenu ("&Graph");
pmenu->addAction (pactAdd); m_menu->addAction (pactAdd);
pmenu->addAction (pactOpenMediaFile); m_menu->addAction (pactOpenMediaFile);
pmenu->addAction ("Open Media Uri...", this, SLOT (OpenMediaUri ())); m_menu->addAction ("Open Media Uri...", this, SLOT (OpenMediaUri ()));
pmenu->addSeparator (); m_menu->addSeparator ();
pmenu->addAction (pactPlay); m_menu->addAction (pactPlay);
pmenu->addAction (pactPause); m_menu->addAction (pactPause);
pmenu->addAction (pactStop); m_menu->addAction (pactStop);
pmenu->addAction (pactFlush); m_menu->addAction (pactFlush);
pmenu->addSeparator (); m_menu->addSeparator ();
pmenu->addAction (pactClear); 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; QScrollArea *pscroll = new QScrollArea;
pscroll->setWidget (m_pGraphDisplay); pscroll->setWidget (m_pGraphDisplay);
@ -169,12 +167,54 @@ m_pGraph (new GraphManager)
m_pluginListDlg = new PluginsListDialog (m_pGraph->getPluginsList (), this); m_pluginListDlg = new PluginsListDialog (m_pGraph->getPluginsList (), this);
m_pluginListDlg->setModal (false); m_pluginListDlg->setModal (false);
restoreGeometry (CustomSettings::mainWindowGeometry ()); 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); 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 () MainWindow::~MainWindow ()
{ {
CustomSettings::saveMainWindowGeometry (saveGeometry ()); CustomSettings::saveMainWindowGeometry (saveGeometry ());
Logger::instance().Quit();
delete m_pluginListDlg; delete m_pluginListDlg;
} }
@ -182,6 +222,8 @@ void
MainWindow::AddPlugin () MainWindow::AddPlugin ()
{ {
m_pluginListDlg->setGraph (m_pGraph.data ()); m_pluginListDlg->setGraph (m_pGraph.data ());
m_pluginListDlg->raise ();
m_pluginListDlg->show (); m_pluginListDlg->show ();
std::vector<ElementInfo> info = m_pGraph->GetInfo (); std::vector<ElementInfo> info = m_pGraph->GetInfo ();
m_pGraphDisplay->update (info); m_pGraphDisplay->update (info);
@ -196,7 +238,7 @@ MainWindow::OpenMediaFile ()
if (!path.isEmpty ()) { if (!path.isEmpty ()) {
gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL); gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL);
if (uri) { if (uri) {
qDebug () << "Open Source file: " << path; LOG_INFO("Open Source file: " + path);;
m_pGraph->OpenUri (uri, NULL); m_pGraph->OpenUri (uri, NULL);
g_free (uri); g_free (uri);
@ -216,7 +258,7 @@ MainWindow::OpenMediaUri ()
QString uri = QInputDialog::getText (this, "Open Uri...", "Uri:"); QString uri = QInputDialog::getText (this, "Open Uri...", "Uri:");
if (!uri.isEmpty ()) { if (!uri.isEmpty ()) {
qDebug () << "Open uri: " << uri; LOG_INFO("Open uri: "+ uri);
m_pGraph->OpenUri (uri.toStdString ().c_str (), NULL); m_pGraph->OpenUri (uri.toStdString ().c_str (), NULL);
std::vector<ElementInfo> info = m_pGraph->GetInfo (); std::vector<ElementInfo> info = m_pGraph->GetInfo ();
@ -228,28 +270,28 @@ MainWindow::OpenMediaUri ()
void void
MainWindow::Play () MainWindow::Play ()
{ {
qDebug () << "Play"; LOG_INFO( "Play");
m_pGraph->Play (); m_pGraph->Play ();
} }
void void
MainWindow::Pause () MainWindow::Pause ()
{ {
qDebug () << "Pause"; LOG_INFO("Pause");
m_pGraph->Pause (); m_pGraph->Pause ();
} }
void void
MainWindow::Stop () MainWindow::Stop ()
{ {
qDebug () << "Stop"; LOG_INFO("Stop");
m_pGraph->Stop (); m_pGraph->Stop ();
} }
void void
MainWindow::Flush () MainWindow::Flush ()
{ {
qDebug () << "Flush"; LOG_INFO("Flush");
if (m_pGraph->m_pGraph) { if (m_pGraph->m_pGraph) {
gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph), gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph),
@ -266,7 +308,7 @@ MainWindow::Flush ()
void void
MainWindow::ClearGraph () MainWindow::ClearGraph ()
{ {
qDebug () << "ClearGraph"; LOG_INFO("ClearGraph");
PipelineIE::Clear (m_pGraph); PipelineIE::Clear (m_pGraph);
} }
@ -274,9 +316,9 @@ void
MainWindow::Seek (int val) MainWindow::Seek (int val)
{ {
if (m_pGraph->SetPosition ((double) (val) / m_pslider->maximum ())) if (m_pGraph->SetPosition ((double) (val) / m_pslider->maximum ()))
qDebug () << "Seek to" << val; LOG_INFO("Seek to" + val);
else else
qDebug () << "Seek to" << val << "was FAILED"; LOG_INFO("Seek FAILED");
} }
void void

View file

@ -7,16 +7,19 @@
#include <QStatusBar> #include <QStatusBar>
#include <QAction> #include <QAction>
#include <QSlider> #include <QSlider>
#include <QListWidget>
#include <gst/gstbuffer.h> #include <gst/gstbuffer.h>
#include <gst/gstevent.h> #include <gst/gstevent.h>
#include <gst/gstcaps.h> #include <gst/gstcaps.h>
#include "GraphManager.h" #include "GraphManager.h"
#include "Logger.h"
class GraphDisplay; class GraphDisplay;
class PluginsListDialog; class PluginsListDialog;
class MainWindow: public QMainWindow class MainWindow: public QMainWindow
{ {
Q_OBJECT Q_OBJECT
@ -24,8 +27,14 @@ public:
MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0); MainWindow(QWidget *parent = 0, Qt::WindowFlags flags = 0);
~MainWindow(); ~MainWindow();
static MainWindow& instance();
protected: protected:
void timerEvent(QTimerEvent *); void timerEvent(QTimerEvent *);
void createDockWindows();
public slots:
void InsertLogLine(const QString& line, int category);
private slots: private slots:
void AddPlugin(); void AddPlugin();
@ -46,6 +55,7 @@ private slots:
private: private:
QSharedPointer<GraphManager> m_pGraph; QSharedPointer<GraphManager> m_pGraph;
GraphDisplay *m_pGraphDisplay; GraphDisplay *m_pGraphDisplay;
QStatusBar *m_pstatusBar; QStatusBar *m_pstatusBar;
@ -53,6 +63,8 @@ private:
QString m_fileName; QString m_fileName;
PluginsListDialog *m_pluginListDlg; PluginsListDialog *m_pluginListDlg;
QMenu *m_menu;
QListWidget* m_logList;
}; };
#endif #endif

View file

@ -3,7 +3,6 @@
#include <QGridLayout> #include <QGridLayout>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QLabel> #include <QLabel>
#include <QDebug>
#include <QScrollArea> #include <QScrollArea>
#include <gst/gst.h> #include <gst/gst.h>

View file

@ -7,7 +7,6 @@
#include <vector> #include <vector>
#include <QDebug>
static void static void
clearPipeline (GstElement *pipeline) clearPipeline (GstElement *pipeline)
@ -142,9 +141,8 @@ writeProperties (QXmlStreamWriter &xmlWriter, const GstElement *element)
} }
default: { default: {
gchar *elementName = gst_element_get_name (element); gchar *elementName = gst_element_get_name (element);
LOG_INFO(QString("property `" + propertyName + "` for `"
qDebug () << "property `" << propertyName << "` for `" + elementName + "` not supported"));
<< elementName << "` not supported";
g_free (elementName); g_free (elementName);
skip = true; skip = true;
@ -183,8 +181,8 @@ loadProperties (QDomElement node, GstElement *element)
if (!param) { if (!param) {
gchar *elementName = gst_element_get_name (element); gchar *elementName = gst_element_get_name (element);
qDebug () << "problem with setting property `" << name << "` for `" LOG_INFO(QString("problem with setting property `" + name + "` for `"
<< elementName << "`"; + elementName + "`"));
g_free (elementName); g_free (elementName);
continue; continue;
} }
@ -247,8 +245,8 @@ loadProperties (QDomElement node, GstElement *element)
} }
default: { default: {
gchar *elementName = gst_element_get_name (element); gchar *elementName = gst_element_get_name (element);
qDebug () << "property `" << name << "` for `" LOG_INFO(QString("property `" + name + "` for `"
<< QString (elementName) << "` not supported"; + QString (elementName) + "` not supported"));
g_free (elementName); g_free (elementName);
break; break;
} }
@ -330,8 +328,7 @@ PipelineIE::Export (QSharedPointer<GraphManager> pgraph,
GST_PAD_TEMPLATE_NAME_TEMPLATE (templ)); GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
} }
else { else {
qDebug () << "Unable to find a template for" LOG_INFO(QString("Unable to find a template for") + QString(info[i].m_pads[j].m_name.c_str()));
<< info[i].m_pads[j].m_name.c_str ();
xmlWriter.writeAttribute ("presence", "always"); xmlWriter.writeAttribute ("presence", "always");
xmlWriter.writeAttribute ("template-name", ""); xmlWriter.writeAttribute ("template-name", "");
} }

View file

@ -12,14 +12,12 @@
#include <gst/gst.h> #include <gst/gst.h>
#include <QDebug>
static gint static gint
plugins_sort_cb (gconstpointer a, gconstpointer b) plugins_sort_cb (gconstpointer a, gconstpointer b)
{ {
Plugin* p1 = (Plugin*) a; Plugin* p1 = (Plugin*) a;
Plugin* p2 = (Plugin*) b; 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 ()) if (p1->getRank () > p2->getRank ())
return 1; return 1;
else if (p1->getRank () == p2->getRank ()) { else if (p1->getRank () == p2->getRank ()) {
@ -173,7 +171,7 @@ void
PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous) PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous)
{ {
Q_UNUSED(previous); Q_UNUSED(previous);
qDebug () << "Show Info: " << pitem->text (); LOG_INFO("Show Info: " + pitem->text ());
m_plblInfo->clear (); m_plblInfo->clear ();
QString descr; QString descr;
descr += "<b>Plugin details</b><hr>"; descr += "<b>Plugin details</b><hr>";
@ -181,14 +179,14 @@ PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous)
GstElementFactory *factory = gst_element_factory_find ( GstElementFactory *factory = gst_element_factory_find (
pitem->text ().toStdString ().c_str ()); pitem->text ().toStdString ().c_str ());
if (!factory) { if (!factory) {
qDebug () << "warning: " << pitem->text () << " Not Found"; LOG_INFO("warning: " + pitem->text () + " Not Found");
return; return;
} }
factory = GST_ELEMENT_FACTORY ( factory = GST_ELEMENT_FACTORY (
gst_plugin_feature_load (GST_PLUGIN_FEATURE (factory))); gst_plugin_feature_load (GST_PLUGIN_FEATURE (factory)));
if (!factory) { if (!factory) {
qDebug () << "warning: " << pitem->text () << " Not Found"; LOG_INFO("warning: " + pitem->text () + " Not Found");
return; return;
} }
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
@ -201,7 +199,7 @@ PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous)
GstPlugin* plugin = gst_default_registry_find_plugin (plugin_name); GstPlugin* plugin = gst_default_registry_find_plugin (plugin_name);
#endif #endif
if (!plugin) { if (!plugin) {
qDebug () << "warning: " << pitem->text () << " Not Found"; LOG_INFO("warning: " + pitem->text () + " Not Found");
return; return;
} }
@ -258,17 +256,17 @@ void
PluginsListDialog::insert (QListWidgetItem *pitem) PluginsListDialog::insert (QListWidgetItem *pitem)
{ {
if (!pitem) { if (!pitem) {
qDebug () << "Do not insert null item"; LOG_INFO("Do not insert null item");
return; return;
} }
qDebug () << "Insert: " << pitem->text (); LOG_INFO("Insert: " + pitem->text ());
if (!m_pGraph if (!m_pGraph
|| !m_pGraph->AddPlugin (pitem->text ().toStdString ().c_str (), NULL)) { || !m_pGraph->AddPlugin (pitem->text ().toStdString ().c_str (), NULL)) {
QMessageBox::warning ( QMessageBox::warning (
this, "Plugin addition problem", this, "Plugin addition problem",
"Plugin `" + pitem->text () + "` insertion was FAILED"); "Plugin `" + pitem->text () + "` insertion was FAILED");
qDebug () << "Plugin `" << pitem->text () << "` insertion FAILED"; LOG_INFO("Plugin `" + pitem->text () + "` insertion FAILED");
return; return;
} }
} }

View file

@ -6,6 +6,7 @@
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
Logger::instance().configure_logger ();
gst_init (&argc, &argv); gst_init (&argc, &argv);
GstRegistry *registry; GstRegistry *registry;