Skip to content

Commit

Permalink
Correct bug : Crash when starting several threads in parallel #3
Browse files Browse the repository at this point in the history
Open one instance of the file per thread, instead of one for all.

Try to correct also bug : big files > 4GB seems overflow in file size #1
Can only be checked at work.
  • Loading branch information
OlivierLeBozec committed Jan 22, 2017
1 parent ddcf3f8 commit 2ac898c
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 132 deletions.
43 changes: 19 additions & 24 deletions qt_tstools/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include "thread.h"

MainWindow::MainWindow() :
m_tsFile(Q_NULLPTR),
m_pthreadPool(QThreadPool::globalInstance()),
m_pcrWorker(Q_NULLPTR), m_ptsWorker(Q_NULLPTR), m_dtsWorker(Q_NULLPTR),
m_pcrDeltaWorker(Q_NULLPTR), m_jitterPcrWorker(Q_NULLPTR), m_bitratePcrWorker(Q_NULLPTR),
Expand All @@ -23,10 +22,6 @@ MainWindow::~MainWindow()

void MainWindow::cleanAll()
{
if (m_tsFile) {
m_tsFile->close();
delete m_tsFile;
}
cleanPcr();
cleanDts();
cleanPts();
Expand Down Expand Up @@ -105,7 +100,8 @@ void MainWindow::about()
QMessageBox::about(this, tr("About Application"),
tr("viewTs version 0.90 for Windows and Linux\n\n"
"Source code : https://github.com/OlivierLeBozec/tstools\n"
"Report issues : https://github.com/OlivierLeBozec/tstools/issues\n"));
"Report issues : https://github.com/OlivierLeBozec/tstools/issues\n"
"Icon made by Madebyoliver from www.flaticon.com"));
}

void MainWindow::updateStatusBar(int percent)
Expand All @@ -128,7 +124,7 @@ void MainWindow::createLayout(QWidget *widget)
QLabel* pcrPidLabel = new QLabel(tr("Pid:"));
m_pcrComboBox = new QComboBox;
m_pcrBox = new QCheckBox(tr("Display Pcr"));
m_deltaPcrBox = new QCheckBox(tr("Display Pcr Delta"));
m_deltaPcrBox = new QCheckBox(tr("Display Pcr Diff"));
m_jitterPcrBox = new QCheckBox(tr("Display Pcr Jitter"));
m_bitratePcrBox = new QCheckBox(tr("Display bitrate"));

Expand All @@ -154,7 +150,7 @@ void MainWindow::createLayout(QWidget *widget)
QLabel* ptsPidLabel = new QLabel(tr("Pid:"));
m_ptsComboBox = new QComboBox;
m_ptsBox = new QCheckBox(tr("Display Pts"));
m_deltaPtsBox = new QCheckBox(tr("Display Pts Delta"));
m_deltaPtsBox = new QCheckBox(tr("Display Pts Diff"));

QGridLayout *ptsGroupBoxLayout = new QGridLayout;
ptsGroupBoxLayout->addWidget(ptsPidLabel, 0, 0);
Expand All @@ -174,7 +170,7 @@ void MainWindow::createLayout(QWidget *widget)
QLabel* dtsPidLabel = new QLabel(tr("Pid:"));
m_dtsComboBox = new QComboBox;
m_dtsBox = new QCheckBox(tr("Display Dts"));
m_deltaDtsBox = new QCheckBox(tr("Display Dts Delta"));
m_deltaDtsBox = new QCheckBox(tr("Display Dts Diff"));

QGridLayout *dtsGroupBoxLayout = new QGridLayout;
dtsGroupBoxLayout->addWidget(dtsPidLabel, 0, 0, Qt::AlignTop);
Expand Down Expand Up @@ -302,16 +298,15 @@ void MainWindow::openFile()
QString fileName = QFileDialog::getOpenFileName(this, tr("Open Ts"), NULL);
if (!fileName.isEmpty())
{
m_tsFileName = fileName.toStdString();

// delete previous allocations
//statusBar()->showMessage(tr("Clean all..."));
//cleanAll();
clearAllSeries();

statusBar()->showMessage(tr("Loading file..."));
m_tsFile = new std::ifstream(fileName.toStdString().c_str(), std::ios::binary);

statusBar()->showMessage(tr("Parsing first 5000 packets..."));
pidmap pm(*m_tsFile);
pidmap pm(&m_tsFileName);
pm.run(5000);

// clear previous value
Expand Down Expand Up @@ -455,7 +450,7 @@ void MainWindow::Pcr(int state)
if (m_pcrWorker == Q_NULLPTR)
{
unsigned int pid = m_pcrComboBox->itemData(m_pcrComboBox->currentIndex()).toInt();
m_pcrWorker = new pcrWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_pcrWorker = new pcrWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_pcrWorker, SIGNAL(finished()), this, SLOT(showPcr()));
buildSeries(m_pcrWorker);
}
Expand All @@ -479,7 +474,7 @@ void MainWindow::Pts(int state)
if (m_ptsWorker == Q_NULLPTR)
{
unsigned int pid = m_ptsComboBox->itemData(m_ptsComboBox->currentIndex()).toInt();
m_ptsWorker = new ptsWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_ptsWorker = new ptsWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_ptsWorker, SIGNAL(finished()), this, SLOT(showPts()));
buildSeries(m_ptsWorker);
}
Expand All @@ -503,7 +498,7 @@ void MainWindow::Dts(int state)
if (m_dtsWorker == Q_NULLPTR)
{
unsigned int pid = m_dtsComboBox->itemData(m_dtsComboBox->currentIndex()).toInt();
m_dtsWorker = new dtsWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_dtsWorker = new dtsWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_dtsWorker, SIGNAL(finished()), this, SLOT(updateDts()));
buildSeries(m_dtsWorker);
}
Expand All @@ -527,7 +522,7 @@ void MainWindow::deltaPcr(int state)
if (m_pcrDeltaWorker == Q_NULLPTR)
{
unsigned int pid = m_pcrComboBox->itemData(m_pcrComboBox->currentIndex()).toInt();
m_pcrDeltaWorker = new pcrDeltaWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_pcrDeltaWorker = new pcrDeltaWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_pcrDeltaWorker, SIGNAL(finished()), this, SLOT(showDeltaPcr()));
buildSeries(m_pcrDeltaWorker);
}
Expand All @@ -551,7 +546,7 @@ void MainWindow::deltaPts(int state)
if (m_ptsDeltaWorker == Q_NULLPTR)
{
unsigned int pid = m_ptsComboBox->itemData(m_ptsComboBox->currentIndex()).toInt();
m_ptsDeltaWorker = new ptsDeltaWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_ptsDeltaWorker = new ptsDeltaWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_ptsDeltaWorker, SIGNAL(finished()), this, SLOT(showPtsDelta()));
buildSeries(m_ptsDeltaWorker);
}
Expand All @@ -576,7 +571,7 @@ void MainWindow::deltaDts(int state)
if (m_dtsDeltaWorker == Q_NULLPTR)
{
unsigned int pid = m_dtsComboBox->itemData(m_dtsComboBox->currentIndex()).toInt();
m_dtsDeltaWorker = new dtsDeltaWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_dtsDeltaWorker = new dtsDeltaWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_dtsDeltaWorker, SIGNAL(finished()), this, SLOT(showDtsDelta()));
buildSeries(m_dtsDeltaWorker);
}
Expand All @@ -600,7 +595,7 @@ void MainWindow::jitterPcr(int state)
if (m_jitterPcrWorker == Q_NULLPTR)
{
unsigned int pid = m_pcrComboBox->itemData(m_pcrComboBox->currentIndex()).toInt();
m_jitterPcrWorker = new pcrJitterWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_jitterPcrWorker = new pcrJitterWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_jitterPcrWorker, SIGNAL(finished()), this, SLOT(showJitterPcr()));
buildSeries(m_jitterPcrWorker);
}
Expand All @@ -624,7 +619,7 @@ void MainWindow::bitratePcr(int state)
if (m_bitratePcrWorker == Q_NULLPTR)
{
unsigned int pid = m_pcrComboBox->itemData(m_pcrComboBox->currentIndex()).toInt();
m_bitratePcrWorker = new pcrBitrateWorker(m_tsFile, pid, (Chart*)m_chartView->chart());
m_bitratePcrWorker = new pcrBitrateWorker(&m_tsFileName, pid, (Chart*)m_chartView->chart());
connect(m_bitratePcrWorker, SIGNAL(finished()), this, SLOT(showBitratePcr()));
buildSeries(m_bitratePcrWorker);
}
Expand All @@ -649,7 +644,7 @@ void MainWindow::diffPcrPts(int state)
{
unsigned int pidPcr = m_pcrComboBox->itemData(m_pcrComboBox->currentIndex()).toInt();
unsigned int pidPts = m_ptsComboBox->itemData(m_ptsComboBox->currentIndex()).toInt();
m_diffPcrPtsWorker = new diffPcrPtsWorker(m_tsFile, pidPcr, pidPts, (Chart*)m_chartView->chart());
m_diffPcrPtsWorker = new diffPcrPtsWorker(&m_tsFileName, pidPcr, pidPts, (Chart*)m_chartView->chart());
connect(m_diffPcrPtsWorker, SIGNAL(finished()), this, SLOT(showDiffPcrPts()));
buildSeries(m_diffPcrPtsWorker);
}
Expand All @@ -675,7 +670,7 @@ void MainWindow::diffPcrDts(int state)
{
unsigned int pidPcr = m_pcrComboBox->itemData(m_pcrComboBox->currentIndex()).toInt();
unsigned int pidDts = m_dtsComboBox->itemData(m_dtsComboBox->currentIndex()).toInt();
m_diffPcrDtsWorker = new diffPcrDtsWorker(m_tsFile, pidPcr, pidDts, (Chart*)m_chartView->chart());
m_diffPcrDtsWorker = new diffPcrDtsWorker(&m_tsFileName, pidPcr, pidDts, (Chart*)m_chartView->chart());
connect(m_diffPcrDtsWorker, SIGNAL(finished()), this, SLOT(showDiffPcrDts()));
buildSeries(m_diffPcrDtsWorker);
}
Expand All @@ -700,7 +695,7 @@ void MainWindow::diffPtsDts(int state)
{
unsigned int pidPts = m_ptsComboBox->itemData(m_ptsComboBox->currentIndex()).toInt();
unsigned int pidDts = m_dtsComboBox->itemData(m_dtsComboBox->currentIndex()).toInt();
m_diffPtsDtsWorker = new diffPtsDtsWorker(m_tsFile, pidPts, pidDts, (Chart*)m_chartView->chart());
m_diffPtsDtsWorker = new diffPtsDtsWorker(&m_tsFileName, pidPts, pidDts, (Chart*)m_chartView->chart());
connect(m_diffPtsDtsWorker, SIGNAL(finished()), this, SLOT(showDiffPtsDts()));
buildSeries(m_diffPtsDtsWorker);
}
Expand Down
2 changes: 1 addition & 1 deletion qt_tstools/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private slots:
void about();

private:
std::ifstream* m_tsFile;
std::string m_tsFileName;

QThreadPool *m_pthreadPool;

Expand Down
63 changes: 33 additions & 30 deletions qt_tstools/thread.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#include "thread.h"

timeStampWorker::timeStampWorker(std::ifstream *tsFile, Chart *chart) :
timeStampWorker::timeStampWorker(std::string *tsFileName, Chart *chart) :
m_nbProgress(0), m_progress(0), m_chart(chart), m_isRunning(false)

{

// new drawing
m_Series = new QLineSeries();

// don't do that otherwise QChart is slow when updating the series
// series must be updated at the end
// series must be updated at the end in parent thread
//m_chart->addSeries(m_Series);

// do not erase series when worker is completed
setAutoDelete (false);

// get file size
tsFile->clear();
tsFile->seekg (0, std::ios::end);
m_fileSize = (unsigned int)tsFile->tellg();
tsFile->seekg (0, std::ios::beg);
std::ifstream* fileIn = new std::ifstream(tsFileName->c_str(), std::ios::binary);
fileIn->seekg (0, std::ios::end);
m_fileSize = (unsigned long long)fileIn->tellg();
fileIn->seekg (0, std::ios::beg);
fileIn->close();
delete fileIn;
}

timeStampWorker::~timeStampWorker()
Expand All @@ -34,9 +37,9 @@ void timeStampWorker::updateProgress()
m_nbProgress += m_WindowPacket;
if (m_fileSize)
{
float tmp = m_nbProgress*188;
tmp /= m_fileSize;
double tmp = m_nbProgress*188;
tmp *= 100;
tmp /= (double)m_fileSize;
emit updated((int)tmp);
}
}
Expand Down Expand Up @@ -85,118 +88,118 @@ void timeStampWorker::run()

////////////////////
// PCR worker
pcrWorker::pcrWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
pcrWorker::pcrWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, pid);
m_timestamp = new timestamp(tsFile, pid);
m_Series->setName(QString("Pcr in seconds"));
m_func = &(m_timestamp->getNextPcr);
}

pcrDeltaWorker::pcrDeltaWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
pcrDeltaWorker::pcrDeltaWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, pid);
m_timestamp = new timestamp(tsFile, pid);
m_Series->setName(QString("Delta Pcr in seconds"));
m_func = &(m_timestamp->getNextDelta);
}

pcrJitterWorker::pcrJitterWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
pcrJitterWorker::pcrJitterWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, pid);
m_timestamp = new timestamp(tsFile, pid);
m_Series->setName(QString("Jitter Pcr in seconds"));
m_func = &(m_timestamp->getNextJitterPcr);
}

pcrBitrateWorker::pcrBitrateWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
pcrBitrateWorker::pcrBitrateWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, pid);
m_timestamp = new timestamp(tsFile, pid);
m_Series->setName(QString("bitrate in bit per seconds"));
m_func = &(m_timestamp->getNextBitrate);
}

////////////////////
// PTS worker
ptsWorker::ptsWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
ptsWorker::ptsWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, TIMESTAMP_NO_PID, pid);
m_timestamp = new timestamp(tsFile, TIMESTAMP_NO_PID, pid);
m_Series->setName(QString("Pts in seconds"));
m_func = &(m_timestamp->getNextPts);
}

ptsDeltaWorker::ptsDeltaWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
ptsDeltaWorker::ptsDeltaWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, TIMESTAMP_NO_PID, pid);
m_timestamp = new timestamp(tsFile, TIMESTAMP_NO_PID, pid);
m_Series->setName(QString("Pts delta in seconds"));
m_func = &(m_timestamp->getNextDelta);
}

////////////////////
// DTS worker
dtsWorker::dtsWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
dtsWorker::dtsWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, TIMESTAMP_NO_PID, TIMESTAMP_NO_PID, pid);
m_timestamp = new timestamp(tsFile, TIMESTAMP_NO_PID, TIMESTAMP_NO_PID, pid);
m_Series->setName(QString("Dts in seconds"));
m_func = &(m_timestamp->getNextDts);
}

dtsDeltaWorker::dtsDeltaWorker(std::ifstream *tsFile, unsigned int pid, Chart *chart) :
dtsDeltaWorker::dtsDeltaWorker(std::string *tsFile, unsigned int pid, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, TIMESTAMP_NO_PID, TIMESTAMP_NO_PID, pid);
m_timestamp = new timestamp(tsFile, TIMESTAMP_NO_PID, TIMESTAMP_NO_PID, pid);
m_Series->setName(QString("Dts delta in seconds"));
m_func = &(m_timestamp->getNextDelta);
}

////////////////
// Diff worker
diffPcrPtsWorker::diffPcrPtsWorker(std::ifstream *tsFile, unsigned int pidPcr, unsigned int pidPts, Chart *chart) :
diffPcrPtsWorker::diffPcrPtsWorker(std::string *tsFile, unsigned int pidPcr, unsigned int pidPts, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, pidPcr, pidPts);
m_timestamp = new timestamp(tsFile, pidPcr, pidPts);
m_Series->setName(QString("Pts-Pcr in seconds"));
m_func = &(m_timestamp->getNextDiff);
}

diffPcrDtsWorker::diffPcrDtsWorker(std::ifstream *tsFile, unsigned int pidPcr, unsigned int pidDts, Chart *chart) :
diffPcrDtsWorker::diffPcrDtsWorker(std::string *tsFile, unsigned int pidPcr, unsigned int pidDts, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, pidPcr, TIMESTAMP_NO_PID, pidDts);
m_timestamp = new timestamp(tsFile, pidPcr, TIMESTAMP_NO_PID, pidDts);
m_Series->setName(QString("Dts-Pcr in seconds"));
m_func = &(m_timestamp->getNextDiff);
}

diffPtsDtsWorker::diffPtsDtsWorker(std::ifstream *tsFile, unsigned int pidPts, unsigned int pidDts, Chart *chart) :
diffPtsDtsWorker::diffPtsDtsWorker(std::string *tsFile, unsigned int pidPts, unsigned int pidDts, Chart *chart) :
timeStampWorker(tsFile, chart)

{
// customize base class
m_timestamp = new timestamp(*tsFile, TIMESTAMP_NO_PID, pidPts, pidDts);
m_timestamp = new timestamp(tsFile, TIMESTAMP_NO_PID, pidPts, pidDts);
m_Series->setName(QString("Dts-Pts in seconds"));
m_func = &(m_timestamp->getNextDiff);
}
Loading

0 comments on commit 2ac898c

Please sign in to comment.