Skip to content

Commit

Permalink
Use some more std::string and std::vector
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Sep 23, 2023
1 parent 6be262b commit ef5e115
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 51 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
22 changes: 11 additions & 11 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 @@ -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
2 changes: 1 addition & 1 deletion YUViewLib/src/parser/AV1/ParserAV1OBU.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ParserAV1OBU : public Parser
}
vector<QTreeWidgetItem *> getStreamInfo() override { return {}; }
unsigned int getNrStreams() override { return 1; }
QString getShortStreamDescription(int) const override { return "Video"; }
std::string getShortStreamDescription(int) const override { return "Video"; }

protected:
av1::GlobalDecodingValues decValues;
Expand Down
6 changes: 3 additions & 3 deletions YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ vector<QTreeWidgetItem *> ParserAVFormat::getStreamInfo()
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
4 changes: 2 additions & 2 deletions YUViewLib/src/parser/AVFormat/ParserAVFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ParserAVFormat : public Parser
{
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
4 changes: 2 additions & 2 deletions YUViewLib/src/parser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class Parser : public QObject
int getParsingProgressPercent() { return progressPercentValue; }
void setAbortParsing() { cancelBackgroundParser = true; }

virtual int getVideoStreamIndex() { return -1; }
virtual QString getShortStreamDescription(int streamIndex) const = 0;
virtual int getVideoStreamIndex() { return -1; }
virtual std::string getShortStreamDescription(const int streamIndex) const = 0;

void setStreamColorCoding(bool colorCoding) { packetModel->setUseColorCoding(colorCoding); }
void setFilterStreamIndex(int streamIndex)
Expand Down
15 changes: 9 additions & 6 deletions YUViewLib/src/parser/ParserAnnexB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

#include "ParserAnnexB.h"

#include "parser/common/SubByteReaderLogging.h"
#include <common/Formatting.h>
#include <parser/common/SubByteReaderLogging.h>F


#include <QElapsedTimer>
#include <QProgressDialog>
Expand All @@ -49,13 +51,14 @@
namespace parser
{

QString ParserAnnexB::getShortStreamDescription(int) const
std::string ParserAnnexB::getShortStreamDescription(const int) const
{
QString info = "Video";
auto frameSize = this->getSequenceSizeSamples();
std::ostringstream info;
info << "Video";
auto frameSize = this->getSequenceSizeSamples();
if (frameSize.isValid())
info += QString(" (%1x%2)").arg(frameSize.width).arg(frameSize.height);
return info;
info << " " << frameSize;
return info.str();
}

bool ParserAnnexB::addFrameToList(int poc,
Expand Down
2 changes: 1 addition & 1 deletion YUViewLib/src/parser/ParserAnnexB.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class ParserAnnexB : public Parser

vector<QTreeWidgetItem *> getStreamInfo() override { return this->stream_info.getStreamInfo(); }
unsigned int getNrStreams() override { return 1; }
QString getShortStreamDescription(int streamIndex) const override;
std::string getShortStreamDescription(const int streamIndex) const override;

/* Parse the NAL unit and what it contains
*
Expand Down
5 changes: 3 additions & 2 deletions YUViewLib/src/ui/widgets/BitstreamAnalysisWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ void BitstreamAnalysisWidget::updateStreamInfo()
this->ui.showStreamComboBox->addItem("Show all streams");
for (unsigned i = 0; i < this->parser->getNrStreams(); i++)
{
QString info = this->parser->getShortStreamDescription(i);
this->ui.showStreamComboBox->addItem(QString("Stream %1 - ").arg(i) + info);
const auto info = this->parser->getShortStreamDescription(i);
this->ui.showStreamComboBox->addItem(QString("Stream %1 - ").arg(i) +
QString::fromStdString(info));
}
}
}
Expand Down

0 comments on commit ef5e115

Please sign in to comment.