Skip to content

Commit

Permalink
Merge pull request #541 from IENT/feature/removeUseOfQScopedPointer
Browse files Browse the repository at this point in the history
Remove Qt dependencies from parser
  • Loading branch information
ChristianFeldmann authored Sep 24, 2023
2 parents f5c03c9 + e10b8c6 commit 5881fbf
Show file tree
Hide file tree
Showing 27 changed files with 244 additions and 179 deletions.
85 changes: 85 additions & 0 deletions YUViewLib/src/common/Formatting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/* This file is part of YUView - The YUV player with advanced analytics toolset
* <https://github.com/IENT/YUView>
* Copyright (C) 2015 Institut für Nachrichtentechnik, RWTH Aachen University, GERMANY
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* In addition, as a special exception, the copyright holders give
* permission to link the code of portions of this program with the
* OpenSSL library under certain conditions as described in each
* individual source file, and distribute linked combinations including
* the two.
*
* You must obey the GNU General Public License in all respects for all
* of the code used other than OpenSSL. If you modify file(s) with this
* exception, you may extend this exception to your version of the
* file(s), but you are not obligated to do so. If you do not wish to do
* so, delete this exception statement from your version. If you delete
* this exception statement from all source files in the program, then
* also delete it here.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

#include "Typedef.h"

#include <sstream>
#include <vector>

template <typename T>
std::ostream &operator<<(std::ostream &stream, const std::pair<T, T> &typePair)
{
stream << "(" << typePair.first << ", " << typePair.second << ")";
return stream;
}

template <typename T> std::string to_string(const std::pair<T, T> &typePair)
{
std::ostringstream stream;
stream << typePair;
return stream.str();
}

template <typename T> std::ostream &operator<<(std::ostream &stream, const std::vector<T> vec)
{
stream << "[";
for (auto it = vec.begin(); it != vec.end(); it++)
{
if (it != vec.begin())
stream << ", ";
stream << (*it);
}
stream << "]";
return stream;
}

template <typename T> std::string to_string(const std::vector<T> vec)
{
std::ostringstream stream;
stream << vec;
return stream.str();
}

static std::ostream &operator<<(std::ostream &stream, const Size &size)
{
stream << "(" << size.width << "x" << size.height << ")";
return stream;
}

static std::string to_string(const Size &size)
{
std::ostringstream stream;
stream << size;
return stream.str();
}
25 changes: 3 additions & 22 deletions YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
#ifdef Q_OS_MAC
const bool is_Q_OS_MAC = true;
#else
const bool is_Q_OS_MAC = false;
const bool is_Q_OS_MAC = false;
#endif

#ifdef Q_OS_WIN
const bool is_Q_OS_WIN = true;
#else
const bool is_Q_OS_WIN = false;
const bool is_Q_OS_WIN = false;
#endif

#ifdef Q_OS_LINUX
Expand Down Expand Up @@ -207,6 +207,7 @@ typedef std::pair<int, int> IntPair;
typedef std::pair<unsigned, unsigned> UIntPair;
typedef std::pair<std::string, std::string> StringPair;
typedef std::vector<StringPair> StringPairVec;
typedef std::vector<std::string> StringVec;

/// ---- Legacy types that will be replaced
typedef QPair<QString, QString> QStringPair;
Expand All @@ -226,26 +227,6 @@ template <typename T> using vector4d = std::vector<vector3d<T>>;
template <typename T, size_t N> using array = std::array<T, N>;
template <typename T, size_t N1, size_t N2> using array2d = std::array<std::array<T, N2>, N1>;

template <typename T> std::string to_string(const std::pair<T, T> typePair)
{
std::ostringstream ss;
ss << "(" << typePair.first << ", " << typePair.second << ")";
return ss.str();
}

template <typename T> std::string to_string(const std::vector<T> vec)
{
std::ostringstream ss;
ss << "[";
for (auto it = vec.begin(); it != vec.end(); it++)
{
if (it != vec.begin())
ss << ", ";
ss << (*it);
}
ss << "]";
return ss.str();
}

template <typename T> int indexInVec(const std::vector<T> &vec, const T &item)
{
Expand Down
26 changes: 13 additions & 13 deletions YUViewLib/src/filesource/FileSourceFFmpegFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <QProgressDialog>
#include <QSettings>

#include <common/Formatting.h>
#include <ffmpeg/AVCodecContextWrapper.h>
#include <parser/AV1/obu_header.h>
#include <parser/common/SubByteReaderLogging.h>
Expand Down Expand Up @@ -425,8 +426,8 @@ bool FileSourceFFmpegFile::scanBitstream(QWidget *mainWindow)
// Create the dialog (if the given pointer is not null)
auto maxPTS = this->getMaxTS();
// Updating the dialog (setValue) is quite slow. Only do this if the percent value changes.
int curPercentValue = 0;
QScopedPointer<QProgressDialog> progress;
int curPercentValue = 0;
std::unique_ptr<QProgressDialog> progress;
if (mainWindow != nullptr)
{
progress.reset(
Expand Down Expand Up @@ -659,7 +660,7 @@ QList<QStringPairList> FileSourceFFmpegFile::getFileInfoForAllStreams()
{
QList<QStringPairList> info;

info += formatCtx.getInfoText();
info += this->formatCtx.getInfoText();
for (unsigned i = 0; i < this->formatCtx.getNbStreams(); i++)
{
auto stream = this->formatCtx.getStream(i);
Expand All @@ -683,23 +684,22 @@ QList<AVRational> FileSourceFFmpegFile::getTimeBaseAllStreams()
return timeBaseList;
}

QList<QString> FileSourceFFmpegFile::getShortStreamDescriptionAllStreams()
StringVec FileSourceFFmpegFile::getShortStreamDescriptionAllStreams()
{
QList<QString> descriptions;
StringVec descriptions;

for (unsigned i = 0; i < formatCtx.getNbStreams(); i++)
for (unsigned i = 0; i < this->formatCtx.getNbStreams(); i++)
{
QString description;
auto stream = this->formatCtx.getStream(i);
description = stream.getCodecTypeName();
std::ostringstream description;
auto stream = this->formatCtx.getStream(i);
description << stream.getCodecTypeName().toStdString();

auto codecID = this->ff.getCodecIDWrapper(stream.getCodecID());
description += " " + codecID.getCodecName();
description << " " << codecID.getCodecName().toStdString() << " ";

description +=
QString(" (%1x%2)").arg(stream.getFrameSize().width).arg(stream.getFrameSize().height);
description << std::pair{stream.getFrameSize().width, stream.getFrameSize().height};

descriptions.append(description);
descriptions.push_back(description.str());
}

return descriptions;
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/filesource/FileSourceFFmpegFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class FileSourceFFmpegFile : public QObject
int getVideoStreamIndex() { return video_stream.getIndex(); }
QList<QStringPairList> getFileInfoForAllStreams();
QList<FFmpeg::AVRational> getTimeBaseAllStreams();
QList<QString> getShortStreamDescriptionAllStreams();
StringVec getShortStreamDescriptionAllStreams();

// Look through the keyframes and find the closest one before (or equal)
// the given frameIdx where we can start decoding
Expand Down
6 changes: 3 additions & 3 deletions YUViewLib/src/parser/AV1/ParserAV1OBU.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class ParserAV1OBU : public Parser
assert(false);
return false;
}
QList<QTreeWidgetItem *> getStreamInfo() override { return {}; }
unsigned int getNrStreams() override { return 1; }
QString getShortStreamDescription(int) const override { return "Video"; }
vector<QTreeWidgetItem *> getStreamInfo() override { return {}; }
unsigned int getNrStreams() override { return 1; }
std::string getShortStreamDescription(int) const override { return "Video"; }

protected:
av1::GlobalDecodingValues decValues;
Expand Down
55 changes: 28 additions & 27 deletions YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,38 +63,39 @@ const ByteVector startCode({0, 0, 1});

using namespace reader;

QList<QTreeWidgetItem *> ParserAVFormat::getStreamInfo()
vector<QTreeWidgetItem *> ParserAVFormat::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");
auto generalInfo = this->streamInfoAllStreams[0];
auto general = new QTreeWidgetItem(QStringList() << "General");
for (QStringPair p : generalInfo)
new QTreeWidgetItem(general, QStringList() << p.first << p.second);
info.append(general);

vector<QTreeWidgetItem *> info;
info.push_back(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])
new QTreeWidgetItem(streamInfo, QStringList() << p.first << p.second);
info.append(streamInfo);
info.push_back(streamInfo);
}

return info;
}

QString ParserAVFormat::getShortStreamDescription(int streamIndex) const
std::string ParserAVFormat::getShortStreamDescription(const int streamIndex) const
{
if (streamIndex >= this->shortStreamInfoAllStreams.count())
if (streamIndex >= this->shortStreamInfoAllStreams.size())
return {};
return this->shortStreamInfoAllStreams[streamIndex];
return this->shortStreamInfoAllStreams.at(streamIndex);
}

bool ParserAVFormat::parseExtradata(ByteVector &extradata)
Expand Down Expand Up @@ -200,7 +201,7 @@ bool ParserAVFormat::parseExtradata_hevc(ByteVector &extradata)
try
{
avformat::HVCC hvcc;
hvcc.parse(extradata, packetModel->rootItem, hevcParser, this->bitratePlotModel.data());
hvcc.parse(extradata, packetModel->rootItem, hevcParser, this->bitratePlotModel.get());
}
catch (...)
{
Expand Down Expand Up @@ -567,14 +568,14 @@ bool ParserAVFormat::parseAVPacket(unsigned packetID,
bool ParserAVFormat::runParsingOfFile(QString compressedFilePath)
{
// Open the file but don't parse it yet.
QScopedPointer<FileSourceFFmpegFile> ffmpegFile(new FileSourceFFmpegFile());
if (!ffmpegFile->openFile(compressedFilePath, nullptr, nullptr, false))
FileSourceFFmpegFile ffmpegFile;
if (!ffmpegFile.openFile(compressedFilePath, nullptr, nullptr, false))
{
emit backgroundParsingDone("Error opening the ffmpeg file.");
return false;
}

this->codecID = ffmpegFile->getVideoStreamCodecID();
this->codecID = ffmpegFile.getVideoStreamCodecID();
if (this->codecID.isAVC())
this->annexBParser.reset(new ParserAnnexBAVC());
else if (this->codecID.isHEVC())
Expand All @@ -600,7 +601,7 @@ bool ParserAVFormat::runParsingOfFile(QString compressedFilePath)
// First get the extradata and push it to the parser
try
{
auto extradata = SubByteReaderLogging::convertToByteVector(ffmpegFile->getExtradata());
auto extradata = SubByteReaderLogging::convertToByteVector(ffmpegFile.getExtradata());
this->parseExtradata(extradata);
}
catch (...)
Expand All @@ -610,7 +611,7 @@ bool ParserAVFormat::runParsingOfFile(QString compressedFilePath)
}
try
{
auto metadata = ffmpegFile->getMetadata();
auto metadata = ffmpegFile.getMetadata();
this->parseMetadata(metadata);
}
catch (...)
Expand All @@ -619,17 +620,17 @@ bool ParserAVFormat::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();
this->streamInfoAllStreams = ffmpegFile.getFileInfoForAllStreams();
this->timeBaseAllStreams = ffmpegFile.getTimeBaseAllStreams();
this->shortStreamInfoAllStreams = ffmpegFile.getShortStreamDescriptionAllStreams();

emit streamInfoUpdated();

// Now iterate over all packets and send them to the parser
AVPacketWrapper packet = ffmpegFile->getNextPacket(false, false);
AVPacketWrapper packet = ffmpegFile.getNextPacket(false, false);
int64_t start_ts = packet.getDTS();

unsigned packetID{};
Expand All @@ -639,7 +640,7 @@ bool ParserAVFormat::runParsingOfFile(QString compressedFilePath)
bool abortParsing = false;
QElapsedTimer signalEmitTimer;
signalEmitTimer.start();
while (!ffmpegFile->atEnd() && !abortParsing)
while (!ffmpegFile.atEnd() && !abortParsing)
{
if (packet.getPacketType() == PacketType::VIDEO)
{
Expand All @@ -661,7 +662,7 @@ bool ParserAVFormat::runParsingOfFile(QString compressedFilePath)

packetID++;
packetCounterPerStream[packet.getStreamIndex()]++;
packet = ffmpegFile->getNextPacket(false, false);
packet = ffmpegFile.getNextPacket(false, false);

// For signal slot debugging purposes, sleep
// QThread::msleep(200);
Expand All @@ -686,12 +687,12 @@ bool ParserAVFormat::runParsingOfFile(QString compressedFilePath)
}

// Seek back to the beginning of the stream.
ffmpegFile->seekFileToBeginning();
ffmpegFile.seekFileToBeginning();

if (packetModel)
emit modelDataUpdated();

this->streamInfoAllStreams = ffmpegFile->getFileInfoForAllStreams();
this->streamInfoAllStreams = ffmpegFile.getFileInfoForAllStreams();
emit streamInfoUpdated();
emit backgroundParsingDone("");

Expand Down
8 changes: 4 additions & 4 deletions YUViewLib/src/parser/AVFormat/ParserAVFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ class ParserAVFormat : public Parser
ParserAVFormat(QObject *parent = nullptr) : Parser(parent) {}
~ParserAVFormat() {}

QList<QTreeWidgetItem *> getStreamInfo() override;
unsigned int getNrStreams() override
vector<QTreeWidgetItem *> getStreamInfo() override;
unsigned int getNrStreams() override
{
return streamInfoAllStreams.empty() ? 0 : streamInfoAllStreams.length() - 1;
}
QString getShortStreamDescription(int streamIndex) const override;
std::string getShortStreamDescription(const int streamIndex) const override;

// This function can run in a separate thread
bool runParsingOfFile(QString compressedFilePath) override;
Expand Down Expand Up @@ -95,7 +95,7 @@ class ParserAVFormat : public Parser
// we update this list while parsing the file.
QList<QStringPairList> streamInfoAllStreams;
QList<FFmpeg::AVRational> timeBaseAllStreams;
QList<QString> shortStreamInfoAllStreams;
StringVec shortStreamInfoAllStreams;

int videoStreamIndex{-1};
double framerate{-1.0};
Expand Down
Loading

0 comments on commit 5881fbf

Please sign in to comment.