Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a mutex to the streamInfo list #506

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions YUViewLib/src/parser/AVFormat/AVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,22 @@ QList<QTreeWidgetItem *> 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<QTreeWidgetItem *> 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<QTreeWidgetItem *> 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);
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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("");

Expand Down
2 changes: 2 additions & 0 deletions YUViewLib/src/parser/AVFormat/AVFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <ffmpeg/FFmpegVersionHandler.h>
#include <filesource/FileSourceFFmpegFile.h>

#include <mutex>
#include <queue>

namespace parser
Expand Down Expand Up @@ -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<QStringPairList> streamInfoAllStreams;
QList<FFmpeg::AVRational> timeBaseAllStreams;
QList<QString> shortStreamInfoAllStreams;
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/ui/views/PlotViewWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down