Skip to content

Commit

Permalink
Reworking log handling in ffmpeg library loading without Qt
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianFeldmann committed Sep 26, 2023
1 parent b2109c8 commit c71dc95
Show file tree
Hide file tree
Showing 16 changed files with 2,872 additions and 328 deletions.
2,444 changes: 2,444 additions & 0 deletions YUViewLib/src/common/Expected.h

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions YUViewLib/src/common/FileInfo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* 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/>.
*/

#include "FileInfo.h"

std::vector<InfoItem> InfoItem::fromFFmpegLibraryPaths(const FFmpeg::LibraryPaths &paths)
{
std::vector<InfoItem> items;

auto addItem = [&items](QString name, const std::filesystem::path &path) {
const auto text = QString::fromStdString(path.filename().string());
const auto tooltip = QString::fromStdString(path.string());
items.push_back(InfoItem(name, text, tooltip));
};

addItem("AVFormat", paths.avFormat);
addItem("AVCodec", paths.avCodec);
addItem("AVUtil", paths.avUtil);
addItem("SWResample", paths.swResample);

return items;
}
5 changes: 5 additions & 0 deletions YUViewLib/src/common/FileInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#pragma once

#include <ffmpeg/FFmpegLibraryFunctions.h>

#include <QList>
#include <QMetaType>
#include <QString>
Expand All @@ -52,6 +54,9 @@ struct InfoItem
: name(name), text(text), button(button), buttonID(buttonID), toolTip(toolTip)
{
}

static std::vector<InfoItem> fromFFmpegLibraryPaths(const FFmpeg::LibraryPaths &paths);

QString name{};
QString text{};
bool button{};
Expand Down
18 changes: 11 additions & 7 deletions YUViewLib/src/common/Functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,18 @@ std::vector<std::filesystem::path> getDefaultLibrarySearchPaths()
{
std::vector<std::filesystem::path> paths;

{
QSettings settings;
auto decoderSearchPath = settings.value("SearchPath", "").toString().toStdString();
if (!decoderSearchPath.empty())
paths.push_back(decoderSearchPath);
}
QSettings settings;

const auto decoderSearchPath = settings.value("SearchPath", "").toString().toStdString();
if (!decoderSearchPath.empty())
paths.push_back(decoderSearchPath);

settings.beginGroup("Decoders");
const auto ffmpegPath = settings.value("FFmpeg.path", "").toString().toStdString();
if (!ffmpegPath.empty())
paths.push_back(ffmpegPath);
settings.endGroup();

paths.push_back(std::filesystem::current_path());
paths.push_back(std::filesystem::current_path() / "ffmpeg");
paths.push_back(std::filesystem::current_path() / "decoder");

Expand Down
15 changes: 0 additions & 15 deletions YUViewLib/src/common/Typedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,6 @@ template <typename T> struct Range
}
};

class SuccessOrErrorMessage
{
public:
SuccessOrErrorMessage() = default;
SuccessOrErrorMessage(bool success) { this->success = success; }
SuccessOrErrorMessage(std::string errorMessage)
{
this->success = false;
this->errorMessage = errorMessage;
}
explicit operator bool() const { return this->success; };
bool success{false};
std::string errorMessage;
};

struct Ratio
{
int num{};
Expand Down
19 changes: 5 additions & 14 deletions YUViewLib/src/decoder/decoderFFmpeg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ decoderFFmpeg::decoderFFmpeg(FFmpeg::AVCodecIDWrapper codecID,
{
// The libraries are only loaded on demand. This way a FFmpegLibraries instance can exist without
// loading the libraries which is slow and uses a lot of memory.
this->ff.loadFFmpegLibraries(functions::getDefaultLibrarySearchPaths());
if (!this->ff.loadingSuccessfull())
const auto result = this->ff.loadFFmpegLibraries(functions::getDefaultLibrarySearchPaths());
if (!result.success)
return;

// Create the cofiguration parameters
Expand Down Expand Up @@ -99,8 +99,8 @@ decoderFFmpeg::decoderFFmpeg(FFmpeg::AVCodecParametersWrapper codecpar, bool cac
{
// The libraries are only loaded on demand. This way a FFmpegLibraries instance can exist without
// loading the libraries which is slow and uses a lot of memory.
this->ff.loadFFmpegLibraries(functions::getDefaultLibrarySearchPaths());
if (!this->ff.loadingSuccessfull())
const auto result = this->ff.loadFFmpegLibraries(functions::getDefaultLibrarySearchPaths());
if (!result.success)
return;

auto codecID = this->ff.getCodecIDWrapper(codecpar.getCodecID());
Expand Down Expand Up @@ -322,16 +322,7 @@ bool decoderFFmpeg::pushData(QByteArray &data)
std::vector<InfoItem> decoderFFmpeg::getDecoderInfo() const
{
const auto libraryPaths = this->ff.getLibraryPaths();

const auto avformatPath = QString::fromStdString(libraryPaths.avFormatPath);
const auto avcodecPath = QString::fromStdString(libraryPaths.avCodecPath);
const auto avutilPath = QString::fromStdString(libraryPaths.avUtilPath);
const auto swresamplePath = QString::fromStdString(libraryPaths.swResamplePath);

return {InfoItem("AVFormat", avformatPath),
InfoItem("AVCodec", avcodecPath),
InfoItem("AVUtil", avutilPath),
InfoItem("SWResample", swresamplePath)};
return InfoItem::fromFFmpegLibraryPaths(libraryPaths);
}

bool decoderFFmpeg::pushAVPacket(FFmpeg::AVPacketWrapper &pkt)
Expand Down
21 changes: 14 additions & 7 deletions YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@
namespace FFmpeg
{

struct LibraryLoadingResult
{
explicit operator bool() const { return this->success; };
bool success{false};
std::string errorMessage;
std::string loadingLog;

void addLogLine(std::string line) { this->loadingLog.append(line + "\n"); }
};

// Some structs/enums which actual definition does not interest us.
struct AVFormatContext;
struct AVClass;
Expand Down Expand Up @@ -380,18 +390,15 @@ enum AVSampleFormat

struct Version
{
unsigned major{};
std::optional<unsigned> minor{};
std::optional<unsigned> micro{};
int major{};
std::optional<int> minor{};
std::optional<int> micro{};
};

struct LibraryVersion
{
LibraryVersion() = default;
LibraryVersion(unsigned avutilMajor,
unsigned avcodecMajor,
unsigned avformatMajor,
unsigned swresampleMajor)
LibraryVersion(int avutilMajor, int avcodecMajor, int avformatMajor, int swresampleMajor)
{
this->avutil.major = avutilMajor;
this->avcodec.major = avcodecMajor;
Expand Down
Loading

0 comments on commit c71dc95

Please sign in to comment.