diff --git a/YUViewLib/src/parser/AVFormat/AVFormat.cpp b/YUViewLib/src/parser/AVFormat/AVFormat.cpp index c392283b1..765b85549 100644 --- a/YUViewLib/src/parser/AVFormat/AVFormat.cpp +++ b/YUViewLib/src/parser/AVFormat/AVFormat.cpp @@ -68,21 +68,22 @@ QList AVFormat::getStreamInfo() // streamInfoAllStreams containse all the info for all streams. // The first QStringPairList contains the general info, next all infos for each stream follows - QList info; if (this->streamInfoAllStreams.count() == 0) - return info; + return {}; - QStringPairList generalInfo = this->streamInfoAllStreams[0]; - QTreeWidgetItem *general = new QTreeWidgetItem(QStringList() << "General"); - for (QStringPair p : generalInfo) + QList info; + std::unique_lock lock(this->streamInfoMutex); + + auto generalInfo = this->streamInfoAllStreams[0]; + auto general = new QTreeWidgetItem(QStringList() << "General"); + for (auto p : generalInfo) new QTreeWidgetItem(general, QStringList() << p.first << p.second); info.append(general); for (int i = 1; i < this->streamInfoAllStreams.count(); i++) { - QTreeWidgetItem *streamInfo = - new QTreeWidgetItem(QStringList() << QString("Stream %1").arg(i - 1)); - for (QStringPair p : this->streamInfoAllStreams[i]) + auto streamInfo = new QTreeWidgetItem(QStringList() << QString("Stream %1").arg(i - 1)); + for (auto p : this->streamInfoAllStreams[i]) new QTreeWidgetItem(streamInfo, QStringList() << p.first << p.second); info.append(streamInfo); } @@ -606,12 +607,16 @@ bool AVFormat::runParsingOfFile(QString compressedFilePath) return false; } - int max_ts = ffmpegFile->getMaxTS(); - this->videoStreamIndex = ffmpegFile->getVideoStreamIndex(); - this->framerate = ffmpegFile->getFramerate(); - this->streamInfoAllStreams = ffmpegFile->getFileInfoForAllStreams(); - this->timeBaseAllStreams = ffmpegFile->getTimeBaseAllStreams(); - this->shortStreamInfoAllStreams = ffmpegFile->getShortStreamDescriptionAllStreams(); + int max_ts = ffmpegFile->getMaxTS(); + this->videoStreamIndex = ffmpegFile->getVideoStreamIndex(); + this->framerate = ffmpegFile->getFramerate(); + + { + std::unique_lock lock(this->streamInfoMutex); + this->streamInfoAllStreams = ffmpegFile->getFileInfoForAllStreams(); + this->timeBaseAllStreams = ffmpegFile->getTimeBaseAllStreams(); + this->shortStreamInfoAllStreams = ffmpegFile->getShortStreamDescriptionAllStreams(); + } emit streamInfoUpdated(); @@ -677,7 +682,10 @@ bool AVFormat::runParsingOfFile(QString compressedFilePath) if (packetModel) emit modelDataUpdated(); - this->streamInfoAllStreams = ffmpegFile->getFileInfoForAllStreams(); + { + std::unique_lock lock(this->streamInfoMutex); + this->streamInfoAllStreams = ffmpegFile->getFileInfoForAllStreams(); + } emit streamInfoUpdated(); emit backgroundParsingDone(""); diff --git a/YUViewLib/src/parser/AVFormat/AVFormat.h b/YUViewLib/src/parser/AVFormat/AVFormat.h index e6e291295..1a123ee9b 100644 --- a/YUViewLib/src/parser/AVFormat/AVFormat.h +++ b/YUViewLib/src/parser/AVFormat/AVFormat.h @@ -38,6 +38,7 @@ #include #include +#include #include namespace parser @@ -93,6 +94,7 @@ class AVFormat : public Base // When the parser is used in the bitstream analysis window, the runParsingOfFile is used and // we update this list while parsing the file. + std::mutex streamInfoMutex; QList streamInfoAllStreams; QList timeBaseAllStreams; QList shortStreamInfoAllStreams; diff --git a/YUViewLib/src/ui/views/PlotViewWidget.cpp b/YUViewLib/src/ui/views/PlotViewWidget.cpp index 53ab62553..d56242e6c 100644 --- a/YUViewLib/src/ui/views/PlotViewWidget.cpp +++ b/YUViewLib/src/ui/views/PlotViewWidget.cpp @@ -99,7 +99,7 @@ void PlotViewWidget::modelNrStreamsChanged() for (unsigned int i = 0; i < model->getNrStreams(); i++) this->showStreamList.append(i); } - DEBUG_PLOT("PlotViewWidget::updateStreamInfo showStreamList " << this->showStreamList); + DEBUG_PLOT("PlotViewWidget::modelNrStreamsChanged showStreamList " << this->showStreamList); } void PlotViewWidget::zoomToFitInternal()