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

Feature/479 lib dav1d support #484

Draft
wants to merge 15 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
More work
  • Loading branch information
ChristianFeldmann committed Nov 21, 2022
commit 80a3ccc60746fda531ca1c90dc568198365110e9
25 changes: 25 additions & 0 deletions YUViewLib/src/common/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,31 @@ std::string toLower(std::string str)
return str;
}

std::string vstring(const char *format, va_list vargs)
{
std::string result;
va_list args_copy;

va_copy(args_copy, vargs);

int len = vsnprintf(nullptr, 0, format, vargs);
if (len < 0)
{
va_end(args_copy);
throw std::runtime_error("vsnprintf error");
}

if (len > 0)
{
result.resize(len);
vsnprintf(result.data(), len + 1, format, args_copy);
}

va_end(args_copy);

return result;
}

std::optional<unsigned long> toUnsigned(const std::string &text)
{
try
Expand Down
33 changes: 33 additions & 0 deletions YUViewLib/src/common/Functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ QString formatDataSize(double size, bool isBits = false);
QStringList toQStringList(const std::vector<std::string> &stringVec);
std::string toLower(std::string str);

template <typename T> std::string to_string(std::vector<T> items, std::string seperator = ", ")
{
std::string str;
auto it = items.begin();
while (it != items.end())
{
if (it != items.begin())
str += seperator;
str += std::to_string(*it);
++it;
}
return str;
}

std::string vstring(const char *format, va_list vargs);

std::string formatString(std::string format, std::initializer_list<std::string> arguments)
{
int counter = 0;
for (auto argument : arguments)
{
const auto toReplace = "%" + std::to_string(counter);
auto replacePos = format.find(toReplace);
if (replacePos == std::string::npos)
return format;

format.replace(replacePos, 2, argument);

++counter;
}
return format;
}

inline std::string boolToString(bool b)
{
return b ? "True" : "False";
Expand Down
3 changes: 3 additions & 0 deletions YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
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 Down Expand Up @@ -327,6 +328,8 @@ static std::string to_string(const FileStartEndPos &fileStartEndPos)
return ss.str();
}

using StreamsInfo = std::map<std::string, StringPairVec>;

// A list of value pair lists, where every list has a string (title)
class ValuePairListSets : public QList<QPair<QString, QStringPairList>>
{
Expand Down
15 changes: 9 additions & 6 deletions YUViewLib/src/ffmpeg/AVCodecIDWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ class AVCodecIDWrapper
{
public:
AVCodecIDWrapper() {}
AVCodecIDWrapper(AVCodecID codecID, QString codecName) : codecID(codecID), codecName(codecName) {}
AVCodecIDWrapper(AVCodecID codecID, std::string codecName)
: codecID(codecID), codecName(codecName)
{
}

QString getCodecName() const { return this->codecName; }
AVCodecID getCodecID() const { return this->codecID; }
std::string getCodecName() const { return this->codecName; }
AVCodecID getCodecID() const { return this->codecID; }

void setCodecID(AVCodecID id) { this->codecID = id; }

Expand All @@ -58,15 +61,15 @@ class AVCodecIDWrapper

bool isNone() const
{
return this->codecName.isEmpty() || this->codecName == "unknown_codec" ||
return this->codecName.empty() || this->codecName == "unknown_codec" ||
this->codecName == "none";
}

bool operator==(const AVCodecIDWrapper &a) const { return codecID == a.codecID; }

private:
AVCodecID codecID{AV_CODEC_ID_NONE};
QString codecName;
AVCodecID codecID{AV_CODEC_ID_NONE};
std::string codecName;
};

} // namespace FFmpeg
Loading