From 22fb303809bb30636e6a31e77fc4acae79b5bfe6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 28 Sep 2023 22:28:34 +0200 Subject: [PATCH] Fix compilation ubuntu and fix warnings --- .../src/ffmpeg/AVCodecParametersWrapper.cpp | 6 ++-- YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.cpp | 28 ++++++++++++++++++ YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.h | 29 ++----------------- YUViewLib/src/ffmpeg/LibraryLoader.cpp | 2 +- YUViewLib/src/ffmpeg/LibraryLoader.h | 8 +++-- YUViewLib/src/ffmpeg/MotionVector.cpp | 4 +-- .../src/parser/AVFormat/ParserAVFormat.cpp | 10 ++++--- 7 files changed, 48 insertions(+), 39 deletions(-) diff --git a/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.cpp b/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.cpp index b38dc0e45..2b2e2870f 100644 --- a/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.cpp +++ b/YUViewLib/src/ffmpeg/AVCodecParametersWrapper.cpp @@ -45,7 +45,7 @@ typedef struct AVCodecParameters_57_58_59_60 AVMediaType codec_type; AVCodecID codec_id; uint32_t codec_tag; - uint8_t * extradata; + uint8_t *extradata; int extradata_size; int format; int64_t bit_rate; @@ -69,8 +69,8 @@ typedef struct AVCodecParameters_57_58_59_60 } // namespace -AVCodecParametersWrapper::AVCodecParametersWrapper(AVCodecParameters * p, - const LibraryVersions &libraryVersionsv) +AVCodecParametersWrapper::AVCodecParametersWrapper(AVCodecParameters *p, + const LibraryVersions &libraryVersions) { this->param = p; this->libraryVersions = libraryVersions; diff --git a/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.cpp b/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.cpp index b6d46af7b..35db05f10 100644 --- a/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.cpp +++ b/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.cpp @@ -53,4 +53,32 @@ QString timestampToString(int64_t timestamp, AVRational timebase) .arg(milliseconds, 3, 10, QChar('0')); } +Version Version::fromFFmpegVersion(const unsigned ffmpegVersion) +{ + Version v; + v.major = AV_VERSION_MAJOR(ffmpegVersion); + v.minor = AV_VERSION_MINOR(ffmpegVersion); + v.micro = AV_VERSION_MICRO(ffmpegVersion); + return v; +} + +std::string to_string(const Version &version) +{ + std::ostringstream stream; + stream << "v" << version.major; + if (version.minor) + { + stream << "." << version.minor.value(); + if (version.micro) + stream << "." << version.micro.value(); + } + return stream.str(); +} + +std::ostream &operator<<(std::ostream &stream, const Version &version) +{ + stream << to_string(version); + return stream; +} + } // namespace FFmpeg diff --git a/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.h b/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.h index 08d312afc..2ca510866 100644 --- a/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.h +++ b/YUViewLib/src/ffmpeg/FFMpegLibrariesTypes.h @@ -406,38 +406,15 @@ struct Version return false; } - static Version fromFFmpegVersion(const unsigned ffmpegVersion) - { - Version v; - v.major = AV_VERSION_MAJOR(ffmpegVersion); - v.minor = AV_VERSION_MINOR(ffmpegVersion); - v.micro = AV_VERSION_MICRO(ffmpegVersion); - return v; - } + static Version fromFFmpegVersion(const unsigned ffmpegVersion); int major{}; std::optional minor{}; std::optional micro{}; }; -inline std::string to_string(const Version &version) -{ - std::ostringstream stream; - stream << "v" << version.major; - if (version.minor) - { - stream << "." << version.minor.value(); - if (version.micro) - stream << "." << version.micro.value(); - } - return stream.str(); -} - -static std::ostream &operator<<(std::ostream &stream, const Version &version) -{ - stream << to_string(version); - return stream; -} +std::string to_string(const Version &version); +std::ostream &operator<<(std::ostream &stream, const Version &version); struct LibraryVersions { diff --git a/YUViewLib/src/ffmpeg/LibraryLoader.cpp b/YUViewLib/src/ffmpeg/LibraryLoader.cpp index 5b36ad334..be0496cda 100644 --- a/YUViewLib/src/ffmpeg/LibraryLoader.cpp +++ b/YUViewLib/src/ffmpeg/LibraryLoader.cpp @@ -51,7 +51,7 @@ bool LibraryLoader::load(std::filesystem::path pathToLib) return success; }; -void *LibraryLoader::resolve(std::string functionName) +FunctionPointer LibraryLoader::resolve(std::string functionName) { auto functionPointer = this->library.resolve(functionName.c_str()); return functionPointer; diff --git a/YUViewLib/src/ffmpeg/LibraryLoader.h b/YUViewLib/src/ffmpeg/LibraryLoader.h index 9cab5c5e2..8e60318ff 100644 --- a/YUViewLib/src/ffmpeg/LibraryLoader.h +++ b/YUViewLib/src/ffmpeg/LibraryLoader.h @@ -35,6 +35,8 @@ #include #include +typedef void (*FunctionPointer)(); + namespace FFmpeg { @@ -43,9 +45,9 @@ class LibraryLoader public: LibraryLoader(/* args */) = default; - void unload(); - bool load(std::filesystem::path pathToLib); - void *resolve(std::string functionName); + void unload(); + bool load(std::filesystem::path pathToLib); + FunctionPointer resolve(std::string functionName); auto getLibraryPath() const { return this->libraryPath; } diff --git a/YUViewLib/src/ffmpeg/MotionVector.cpp b/YUViewLib/src/ffmpeg/MotionVector.cpp index ca6b54054..8130a4656 100644 --- a/YUViewLib/src/ffmpeg/MotionVector.cpp +++ b/YUViewLib/src/ffmpeg/MotionVector.cpp @@ -68,7 +68,7 @@ parseMotionData(const LibraryVersions &libraryVersions, const uint8_t *data, con if (libraryVersions.avutil.major == 54) { const auto nrMotionVectors = dataSize / sizeof(AVMotionVector_54); - for (int index = 0; index < nrMotionVectors; ++index) + for (size_t index = 0; index < nrMotionVectors; ++index) { const auto byteOffset = sizeof(AVMotionVector_54) * index; const auto p = reinterpret_cast(data + byteOffset); @@ -94,7 +94,7 @@ parseMotionData(const LibraryVersions &libraryVersions, const uint8_t *data, con libraryVersions.avutil.major == 57) { const auto nrMotionVectors = dataSize / sizeof(AVMotionVector_55_56_57); - for (int index = 0; index < nrMotionVectors; ++index) + for (size_t index = 0; index < nrMotionVectors; ++index) { const auto byteOffset = sizeof(AVMotionVector_55_56_57) * index; const auto p = reinterpret_cast(data + byteOffset); diff --git a/YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp b/YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp index 4cb464025..e3c88ab2c 100644 --- a/YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp +++ b/YUViewLib/src/parser/AVFormat/ParserAVFormat.cpp @@ -93,7 +93,7 @@ vector ParserAVFormat::getStreamInfo() std::string ParserAVFormat::getShortStreamDescription(const int streamIndex) const { - if (streamIndex >= this->shortStreamInfoAllStreams.size()) + if (streamIndex < 0 || streamIndex >= static_cast(this->shortStreamInfoAllStreams.size())) return {}; return this->shortStreamInfoAllStreams.at(streamIndex); } @@ -245,7 +245,7 @@ bool ParserAVFormat::parseExtradata_mpeg2(ByteVector &extradata) } std::map -ParserAVFormat::parseByteVectorAnnexBStartCodes(ByteVector & data, +ParserAVFormat::parseByteVectorAnnexBStartCodes(ByteVector &data, PacketDataFormat dataFormat, BitratePlotModel::BitrateEntry packetBitrateEntry, std::shared_ptr item) @@ -256,7 +256,8 @@ ParserAVFormat::parseByteVectorAnnexBStartCodes(ByteVector & d return {}; } - auto getNextNalStart = [&data, &dataFormat](ByteVector::iterator searchStart) { + auto getNextNalStart = [&data, &dataFormat](ByteVector::iterator searchStart) + { if (dataFormat == PacketDataFormat::RawNAL) { if (std::distance(searchStart, data.end()) <= 3) @@ -343,7 +344,8 @@ bool ParserAVFormat::parseAVPacket(unsigned packetID, auto timeBase = timeBaseAllStreams[packet.getStreamIndex()]; - auto formatTimestamp = [](int64_t timestamp, AVRational timebase) -> std::string { + auto formatTimestamp = [](int64_t timestamp, AVRational timebase) -> std::string + { std::ostringstream ss; ss << timestamp << " ("; if (timestamp < 0)