From 9acced47f663e4add8374321c5d67c02d52c1447 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Thu, 19 Feb 2026 17:30:35 +0100 Subject: [PATCH 1/4] Add clang-tidy file --- .clang-tidy | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 0000000..06eceb4 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,35 @@ +--- +Checks: '-clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type' +WarningsAsErrors: true +HeaderFilterRegex: '.*' +FormatStyle: google +CheckOptions: + - key: cert-dcl16-c.NewSuffixes + value: 'L;LL;LU;LLU' + - key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField + value: '0' + - key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors + value: '1' + - key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic + value: '1' + - key: google-readability-braces-around-statements.ShortStatementLines + value: '1' + - key: google-readability-function-size.StatementThreshold + value: '800' + - key: google-readability-namespace-comments.ShortNamespaceLines + value: '10' + - key: google-readability-namespace-comments.SpacesBeforeComments + value: '2' + - key: modernize-loop-convert.MaxCopySize + value: '16' + - key: modernize-loop-convert.MinConfidence + value: reasonable + - key: modernize-loop-convert.NamingStyle + value: CamelCase + - key: modernize-pass-by-value.IncludeStyle + value: llvm + - key: modernize-replace-auto-ptr.IncludeStyle + value: llvm + - key: modernize-use-nullptr.NullMacros + value: 'NULL' +... From cb09f4e1f4c18e118e1affee431c1328fcea1166 Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Thu, 19 Feb 2026 17:32:38 +0100 Subject: [PATCH 2/4] Bunch of clang-tidy things --- src/app/FilePacketComparer.cpp | 18 +- .../AVCodec/wrappers/AVChannelInternal.cpp | 6 +- .../wrappers/AVCodecContextWrapper.cpp | 36 +-- .../AVCodec/wrappers/AVCodecContextWrapper.h | 18 +- .../wrappers/AVCodecContextWrapperInternal.h | 284 ++++++++++-------- .../wrappers/AVCodecDescriptorConversion.cpp | 6 +- .../AVCodecDescriptorConversionInternal.h | 26 +- .../wrappers/AVCodecParametersWrapper.cpp | 30 +- .../wrappers/AVCodecParametersWrapper.h | 18 +- .../AVCodecParametersWrapperInternal.h | 272 ++++++++--------- src/lib/AVCodec/wrappers/AVCodecWrapper.cpp | 22 +- src/lib/AVCodec/wrappers/AVCodecWrapper.h | 28 +- .../AVCodec/wrappers/AVCodecWrapperInternal.h | 112 +++---- src/lib/AVCodec/wrappers/AVPacketWrapper.cpp | 20 +- src/lib/AVCodec/wrappers/AVPacketWrapper.h | 28 +- .../wrappers/AVPacketWrapperInternal.h | 26 +- .../wrappers/AVFormatContextWrapper.cpp | 22 +- .../wrappers/AVFormatContextWrapper.h | 22 +- .../wrappers/AVFormatContextWrapperInternal.h | 108 +++---- .../AVFormat/wrappers/AVIOContextWrapper.cpp | 3 - .../AVFormat/wrappers/AVIOContextWrapper.h | 10 +- .../AVFormat/wrappers/AVInputFormatWrapper.h | 10 +- .../wrappers/AVInputFormatWrapperInternal.h | 22 +- src/lib/AVFormat/wrappers/AVStreamWrapper.cpp | 11 +- src/lib/AVFormat/wrappers/AVStreamWrapper.h | 28 +- .../wrappers/AVStreamWrapperInternal.h | 132 ++++---- src/lib/AVUtil/wrappers/AVDictionaryWrapper.h | 8 +- .../wrappers/AVFrameSideDataWrapper.cpp | 8 +- .../AVUtil/wrappers/AVFrameSideDataWrapper.h | 2 +- .../wrappers/AVFrameSideDataWrapperInternal.h | 22 +- src/lib/AVUtil/wrappers/AVFrameWrapper.cpp | 39 ++- src/lib/AVUtil/wrappers/AVFrameWrapper.h | 27 +- .../AVUtil/wrappers/AVFrameWrapperInternal.h | 56 ++-- .../AVPixFmtDescriptorConversionInternal.h | 22 +- src/lib/Decoder.cpp | 2 +- src/lib/Decoder.h | 2 +- src/lib/Demuxer.cpp | 12 +- src/lib/Demuxer.h | 9 +- src/lib/common/EnumMapper.h | 38 +-- src/lib/common/Error.cpp | 14 +- src/lib/common/Formatting.cpp | 14 +- src/lib/common/Functions.h | 7 +- src/lib/common/InternalTypes.h | 3 +- src/lib/common/Version.h | 75 ++--- src/lib/libHandling/FFmpegLibraries.cpp | 48 ++- src/lib/libHandling/FFmpegLibraries.h | 15 +- .../libHandling/FFmpegLibrariesBuilder.cpp | 6 +- src/lib/libHandling/IFFmpegLibraries.h | 7 +- src/lib/libHandling/SharedLibraryLoader.h | 6 +- src/lib/libHandling/StaticCallbacks.cpp | 2 +- test/integration/DemuxingTest.cpp | 2 - test/integration/LibrariesWithLogging.h | 7 +- test/unit/libHandling/FFmpegLibrariesMoc.h | 16 +- .../wrappers/AVCodec/AVPacketWrapperTest.cpp | 14 +- .../AVFormat/AVFormatContextWrapperTest.cpp | 124 ++++---- .../AVUtil/AVFrameSideDataWrapperTest.cpp | 6 +- test/unit/wrappers/TestHelper.h | 2 +- 57 files changed, 1007 insertions(+), 926 deletions(-) diff --git a/src/app/FilePacketComparer.cpp b/src/app/FilePacketComparer.cpp index 6c5c497..47c3f35 100644 --- a/src/app/FilePacketComparer.cpp +++ b/src/app/FilePacketComparer.cpp @@ -106,8 +106,8 @@ Demuxer openInput(std::shared_ptr ffmpegLibraries, const std:: return demuxer; } -ComparisonMode checkStreamsAndGetComparMode(Demuxer & demuxer1, - Demuxer & demuxer2, +ComparisonMode checkStreamsAndGetComparMode(Demuxer &demuxer1, + Demuxer &demuxer2, const int streamIndex1, const int streamIndex2) { @@ -138,14 +138,14 @@ ComparisonMode checkStreamsAndGetComparMode(Demuxer & demuxer1, codecDescriptor1->codecName + " and name 2 " + codecDescriptor2->codecName); - if (codecDescriptor1->codecName.find("pcm") == 0) + if (codecDescriptor1->codecName.starts_with("pcm")) return ComparisonMode::Data; return ComparisonMode::Packets; } bool compareData(const ByteVector &data1, const ByteVector &data2) { - return std::equal(data1.begin(), data1.end(), data2.begin(), data2.end()); + return std::ranges::equal(data1, data2); } void compareQueuePacketsAndDrain(PacketQueue &queue1, PacketQueue &queue2) @@ -158,9 +158,6 @@ void compareQueuePacketsAndDrain(PacketQueue &queue1, PacketQueue &queue2) queue1.pop(); queue2.pop(); - const auto streamIndex1 = packet1.getStreamIndex(); - const auto streamIndex2 = packet2.getStreamIndex(); - static int packetCount = -1; ++packetCount; @@ -333,12 +330,13 @@ int main(int argc, char const *argv[]) const auto compareMode = checkStreamsAndGetComparMode( demuxer1, demuxer2, settings->file1.streamIndex, settings->file2.streamIndex); - PacketQueue packetQueue[2]; - DataQueue dataQueue[2]; + std::array packetQueue; + std::array dataQueue; auto addPacketToQueue = [&packetQueue, &dataQueue, compareMode](avcodec::AVPacketWrapper &&packet, const int streamIndex, - const int queueIndex) { + const int queueIndex) + { const auto packetStreamIndex = packet.getStreamIndex(); if (packetStreamIndex != streamIndex) return; diff --git a/src/lib/AVCodec/wrappers/AVChannelInternal.cpp b/src/lib/AVCodec/wrappers/AVChannelInternal.cpp index 550b784..1566448 100644 --- a/src/lib/AVCodec/wrappers/AVChannelInternal.cpp +++ b/src/lib/AVCodec/wrappers/AVChannelInternal.cpp @@ -146,8 +146,10 @@ ChannelLayout bitMaskToChannelLayout(const uint64_t mask, const bool isAmbisonic { ChannelLayout layout; - std::bitset<64> bits(mask); - for (int bitPosition = 0; bitPosition < 64; ++bitPosition) + constexpr auto MAX_CHANNELS = 64; + + std::bitset bits(mask); + for (int bitPosition = 0; bitPosition < MAX_CHANNELS; ++bitPosition) { if (bits.test(bitPosition)) { diff --git a/src/lib/AVCodec/wrappers/AVCodecContextWrapper.cpp b/src/lib/AVCodec/wrappers/AVCodecContextWrapper.cpp index 8646b29..852b89c 100644 --- a/src/lib/AVCodec/wrappers/AVCodecContextWrapper.cpp +++ b/src/lib/AVCodec/wrappers/AVCodecContextWrapper.cpp @@ -36,7 +36,7 @@ namespace internal } // namespace internal -AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContext * codecContext, +AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContext *codecContext, std::shared_ptr ffmpegLibraries) : codecContext(codecContext), ffmpegLibraries(ffmpegLibraries) { @@ -53,7 +53,8 @@ AVCodecContextWrapper::AVCodecContextWrapper(std::shared_ptr f throw std::runtime_error("Provided ffmpeg libraries pointer must not be null"); } -AVCodecContextWrapper &AVCodecContextWrapper::operator=(AVCodecContextWrapper &&codecContextWrapper) +AVCodecContextWrapper & +AVCodecContextWrapper::operator=(AVCodecContextWrapper &&codecContextWrapper) noexcept { this->codecContext = codecContextWrapper.codecContext; this->codecContextOwnership = codecContextWrapper.codecContextOwnership; @@ -62,12 +63,11 @@ AVCodecContextWrapper &AVCodecContextWrapper::operator=(AVCodecContextWrapper && return *this; } -AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContextWrapper &&codecContextWrapper) +AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContextWrapper &&codecContextWrapper) noexcept + : codecContext(codecContextWrapper.codecContext), + codecContextOwnership(codecContextWrapper.codecContextOwnership), + ffmpegLibraries(std::move(codecContextWrapper.ffmpegLibraries)) { - this->codecContext = codecContextWrapper.codecContext; - this->codecContextOwnership = codecContextWrapper.codecContextOwnership; - codecContextWrapper.codecContext = nullptr; - this->ffmpegLibraries = std::move(codecContextWrapper.ffmpegLibraries); } AVCodecContextWrapper::~AVCodecContextWrapper() @@ -173,56 +173,56 @@ AVCodecContextWrapper::decodeVideo2(const avcodec::AVPacketWrapper &packet) avutil::MediaType AVCodecContextWrapper::getCodecType() const { - AVMediaType type; + AVMediaType type{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, type, codec_type); return avutil::toMediaType(type); } AVCodecID AVCodecContextWrapper::getCodecID() const { - AVCodecID id; + AVCodecID id{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, id, codec_id); return id; } avutil::PixelFormatDescriptor AVCodecContextWrapper::getPixelFormat() const { - AVPixelFormat avPixelFormat; + AVPixelFormat avPixelFormat{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, avPixelFormat, pix_fmt); return avutil::convertAVPixFmtDescriptor(avPixelFormat, this->ffmpegLibraries); } Size AVCodecContextWrapper::getSize() const { - int width; + int width{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, width, width); - int height; + int height{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, height, height); - return {width, height}; + return {.width = width, .height = height}; } avutil::ColorSpace AVCodecContextWrapper::getColorspace() const { - AVColorSpace avColorspace; + AVColorSpace avColorspace{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, avColorspace, colorspace); return avutil::toColorspace(avColorspace); } Rational AVCodecContextWrapper::getTimeBase() const { - AVRational timebase; + AVRational timebase{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, timebase, time_base); - return Rational({timebase.num, timebase.den}); + return fromAVRational(timebase); } ByteVector AVCodecContextWrapper::getExtradata() const { - uint8_t *extradata; + uint8_t *extradata{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, extradata, extradata); - int extradataSize; + int extradataSize{}; CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, extradataSize, extradata_size); return copyDataFromRawArray(extradata, extradataSize); diff --git a/src/lib/AVCodec/wrappers/AVCodecContextWrapper.h b/src/lib/AVCodec/wrappers/AVCodecContextWrapper.h index 86d2a66..d77c6e1 100644 --- a/src/lib/AVCodec/wrappers/AVCodecContextWrapper.h +++ b/src/lib/AVCodec/wrappers/AVCodecContextWrapper.h @@ -26,9 +26,9 @@ class AVCodecContextWrapper AVCodecContextWrapper(libffmpeg::internal::AVCodecContext *codecContext, std::shared_ptr ffmpegLibraries); AVCodecContextWrapper(const AVCodecContextWrapper &) = delete; - AVCodecContextWrapper &operator =(AVCodecContextWrapper &&); + AVCodecContextWrapper &operator=(AVCodecContextWrapper &&) noexcept; AVCodecContextWrapper &operator=(const AVCodecContextWrapper &) = delete; - AVCodecContextWrapper(AVCodecContextWrapper &&wrapper); + AVCodecContextWrapper(AVCodecContextWrapper &&wrapper) noexcept; ~AVCodecContextWrapper(); bool openContextForDecoding(const avcodec::AVCodecParametersWrapper &codecParameters); @@ -47,13 +47,13 @@ class AVCodecContextWrapper // This is the old FFMpeg 2 interface before pushPacket/pullFrame. DecodeResult decodeVideo2(const avcodec::AVPacketWrapper &packet); - avutil::MediaType getCodecType() const; - libffmpeg::internal::AVCodecID getCodecID() const; - avutil::PixelFormatDescriptor getPixelFormat() const; - Size getSize() const; - avutil::ColorSpace getColorspace() const; - Rational getTimeBase() const; - ByteVector getExtradata() const; + [[nodiscard]] avutil::MediaType getCodecType() const; + [[nodiscard]] libffmpeg::internal::AVCodecID getCodecID() const; + [[nodiscard]] avutil::PixelFormatDescriptor getPixelFormat() const; + [[nodiscard]] Size getSize() const; + [[nodiscard]] avutil::ColorSpace getColorspace() const; + [[nodiscard]] Rational getTimeBase() const; + [[nodiscard]] ByteVector getExtradata() const; private: /* It depends on how the wrapper is created who has ownership of this. diff --git a/src/lib/AVCodec/wrappers/AVCodecContextWrapperInternal.h b/src/lib/AVCodec/wrappers/AVCodecContextWrapperInternal.h index c147733..28be687 100644 --- a/src/lib/AVCodec/wrappers/AVCodecContextWrapperInternal.h +++ b/src/lib/AVCodec/wrappers/AVCodecContextWrapperInternal.h @@ -11,43 +11,45 @@ namespace libffmpeg::internal::avcodec { +constexpr auto CODEC_NAME_LENGTH = 32; + struct AVCodecContext_56 { const AVClass *av_class{}; int log_level_offset{}; AVMediaType codec_type{}; - const AVCodec * codec{}; - char codec_name[32]{}; + const AVCodec *codec{}; + char codec_name[CODEC_NAME_LENGTH]{}; AVCodecID codec_id{}; unsigned int codec_tag{}; unsigned int stream_codec_tag{}; - void * priv_data{}; + void *priv_data{}; AVCodecInternal *internal{}; - void * opaque{}; + void *opaque{}; int bit_rate{}; int bit_rate_tolerance{}; int global_quality{}; int compression_level{}; int flags{}; int flags2{}; - uint8_t * extradata{}; + uint8_t *extradata{}; int extradata_size{}; AVRational time_base{}; int ticks_per_frame{}; int delay{}; - int width, height{}; - int coded_width, coded_height{}; + int width{}, height{}; + int coded_width{}, coded_height{}; int gop_size{}; AVPixelFormat pix_fmt{}; int me_method{}; void (*draw_horiz_band)(AVCodecContext *s, - const AVFrame * src, + const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, - int height); - AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt); + int height){}; + AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt){}; int max_b_frames{}; float b_quant_factor{}; int rc_strategy{}; @@ -64,7 +66,7 @@ struct AVCodecContext_56 float dark_masking{}; int slice_count{}; int prediction_method{}; - int * slice_offset{}; + int *slice_offset{}; AVRational sample_aspect_ratio{}; int me_cmp{}; int me_sub_cmp{}; @@ -83,8 +85,8 @@ struct AVCodecContext_56 int slice_flags{}; int xvmc_acceleration{}; int mb_decision{}; - uint16_t * intra_matrix{}; - uint16_t * inter_matrix{}; + uint16_t *intra_matrix{}; + uint16_t *inter_matrix{}; int scenechange_threshold{}; int noise_reduction{}; int me_threshold{}; @@ -115,40 +117,40 @@ struct AVCodecContext_56 struct AVCodecContext_57 { - const AVClass * av_class{}; + const AVClass *av_class{}; int log_level_offset{}; AVMediaType codec_type{}; - const AVCodec * codec{}; - char codec_name[32]{}; + const AVCodec *codec{}; + char codec_name[CODEC_NAME_LENGTH]{}; AVCodecID codec_id{}; unsigned int codec_tag{}; unsigned int stream_codec_tag{}; - void * priv_data{}; + void *priv_data{}; AVCodecInternal *internal{}; - void * opaque{}; + void *opaque{}; int64_t bit_rate{}; int bit_rate_tolerance{}; int global_quality{}; int compression_level{}; int flags{}; int flags2{}; - uint8_t * extradata{}; + uint8_t *extradata{}; int extradata_size{}; AVRational time_base{}; int ticks_per_frame{}; int delay{}; - int width, height{}; - int coded_width, coded_height{}; + int width{}, height{}; + int coded_width{}, coded_height{}; int gop_size{}; AVPixelFormat pix_fmt{}; int me_method{}; void (*draw_horiz_band)(AVCodecContext *s, - const AVFrame * src, + const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, - int height); - AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt); + int height){}; + AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt){}; int max_b_frames{}; float b_quant_factor{}; int rc_strategy{}; @@ -165,7 +167,7 @@ struct AVCodecContext_57 float dark_masking{}; int slice_count{}; int prediction_method{}; - int * slice_offset{}; + int *slice_offset{}; AVRational sample_aspect_ratio{}; int me_cmp{}; int me_sub_cmp{}; @@ -184,8 +186,8 @@ struct AVCodecContext_57 int slice_flags{}; int xvmc_acceleration{}; int mb_decision{}; - uint16_t * intra_matrix{}; - uint16_t * inter_matrix{}; + uint16_t *intra_matrix{}; + uint16_t *inter_matrix{}; int scenechange_threshold{}; int noise_reduction{}; int me_threshold{}; @@ -216,37 +218,37 @@ struct AVCodecContext_57 struct AVCodecContext_58 { - const AVClass * av_class{}; + const AVClass *av_class{}; int log_level_offset{}; AVMediaType codec_type{}; - const AVCodec * codec{}; + const AVCodec *codec{}; AVCodecID codec_id{}; unsigned int codec_tag{}; - void * priv_data{}; + void *priv_data{}; AVCodecInternal *internal{}; - void * opaque{}; + void *opaque{}; int64_t bit_rate{}; int bit_rate_tolerance{}; int global_quality{}; int compression_level{}; int flags{}; int flags2{}; - uint8_t * extradata{}; + uint8_t *extradata{}; int extradata_size{}; AVRational time_base{}; int ticks_per_frame{}; int delay{}; - int width, height{}; - int coded_width, coded_height{}; + int width{}, height{}; + int coded_width{}, coded_height{}; int gop_size{}; AVPixelFormat pix_fmt{}; void (*draw_horiz_band)(AVCodecContext *s, - const AVFrame * src, + const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, - int height); - AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt); + int height){}; + AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt){}; int max_b_frames{}; float b_quant_factor{}; int b_frame_strategy{}; @@ -262,7 +264,7 @@ struct AVCodecContext_58 float dark_masking{}; int slice_count{}; int prediction_method{}; - int * slice_offset{}; + int *slice_offset{}; AVRational sample_aspect_ratio{}; int me_cmp{}; int me_sub_cmp{}; @@ -277,8 +279,8 @@ struct AVCodecContext_58 int me_range{}; int slice_flags{}; int mb_decision{}; - uint16_t * intra_matrix{}; - uint16_t * inter_matrix{}; + uint16_t *intra_matrix{}; + uint16_t *inter_matrix{}; int scenechange_threshold{}; int noise_reduction{}; int intra_dc_precision{}; @@ -306,37 +308,37 @@ struct AVCodecContext_58 struct AVCodecContext_59 { - const AVClass * av_class{}; + const AVClass *av_class{}; int log_level_offset{}; AVMediaType codec_type{}; - const AVCodec * codec{}; + const AVCodec *codec{}; AVCodecID codec_id{}; unsigned int codec_tag{}; - void * priv_data{}; + void *priv_data{}; AVCodecInternal *internal{}; - void * opaque{}; + void *opaque{}; int64_t bit_rate{}; int bit_rate_tolerance{}; int global_quality{}; int compression_level{}; int flags{}; int flags2{}; - uint8_t * extradata{}; + uint8_t *extradata{}; int extradata_size{}; AVRational time_base{}; int ticks_per_frame{}; int delay{}; - int width, height{}; - int coded_width, coded_height{}; + int width{}, height{}; + int coded_width{}, coded_height{}; int gop_size{}; AVPixelFormat pix_fmt{}; void (*draw_horiz_band)(AVCodecContext *s, - const AVFrame * src, + const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, - int height); - AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt); + int height){}; + AVPixelFormat (*get_format)(AVCodecContext *s, const AVPixelFormat *fmt){}; int max_b_frames{}; float b_quant_factor{}; float b_quant_offset{}; @@ -349,7 +351,7 @@ struct AVCodecContext_59 float p_masking{}; float dark_masking{}; int slice_count{}; - int * slice_offset{}; + int *slice_offset{}; AVRational sample_aspect_ratio{}; int me_cmp{}; int me_sub_cmp{}; @@ -363,8 +365,8 @@ struct AVCodecContext_59 int me_range{}; int slice_flags{}; int mb_decision{}; - uint16_t * intra_matrix{}; - uint16_t * inter_matrix{}; + uint16_t *intra_matrix{}; + uint16_t *inter_matrix{}; int intra_dc_precision{}; int skip_top{}; int skip_bottom{}; @@ -384,95 +386,127 @@ struct AVCodecContext_59 // Actually, there is more here, but the variables above are the only we need. }; -typedef AVCodecContext_59 AVCodecContext_60; +using AVCodecContext_60 = AVCodecContext_59; struct AVCodecContext_61 { - const AVClass * av_class{}; - int log_level_offset{}; - AVMediaType codec_type{}; - const AVCodec * codec{}; - AVCodecID codec_id{}; - unsigned int codec_tag{}; - void * priv_data{}; - AVCodecInternal * internal{}; - void * opaque{}; - int64_t bit_rate; - int flags; - int flags2; - uint8_t * extradata; - int extradata_size; - AVRational time_base; - AVRational pkt_timebase; - AVRational framerate; - int ticks_per_frame; - int delay; - int width, height; - int coded_width, coded_height; - AVRational sample_aspect_ratio; - enum AVPixelFormat pix_fmt; - enum AVPixelFormat sw_pix_fmt; - enum AVColorPrimaries color_primaries; - enum AVColorTransferCharacteristic color_trc; - enum AVColorSpace colorspace; - enum AVColorRange color_range; - enum AVChromaLocation chroma_sample_location; - enum AVFieldOrder field_order; - int refs; - int has_b_frames; - int slice_flags; + const AVClass *av_class{}; + int log_level_offset{}; + AVMediaType codec_type{}; + const AVCodec *codec{}; + AVCodecID codec_id{}; + unsigned int codec_tag{}; + void *priv_data{}; + AVCodecInternal *internal{}; + void *opaque{}; + int64_t bit_rate{}; + int flags{}; + int flags2{}; + uint8_t *extradata{}; + int extradata_size{}; + AVRational time_base{}; + AVRational pkt_timebase{}; + AVRational framerate{}; + int ticks_per_frame{}; + int delay{}; + int width{}, height{}; + int coded_width{}, coded_height{}; + AVRational sample_aspect_ratio{}; + enum AVPixelFormat pix_fmt + { + }; + enum AVPixelFormat sw_pix_fmt + { + }; + enum AVColorPrimaries color_primaries + { + }; + enum AVColorTransferCharacteristic color_trc + { + }; + enum AVColorSpace colorspace + { + }; + enum AVColorRange color_range + { + }; + enum AVChromaLocation chroma_sample_location + { + }; + enum AVFieldOrder field_order + { + }; + int refs{}; + int has_b_frames{}; + int slice_flags{}; void (*draw_horiz_band)(struct AVCodecContext *s, - const AVFrame * src, + const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, - int height); - enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt); + int height){}; + enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt){}; // Actually, there is more here, but the variables above are the only we need. }; struct AVCodecContext_62 { - const AVClass * av_class{}; - int log_level_offset{}; - AVMediaType codec_type{}; - const AVCodec * codec{}; - AVCodecID codec_id{}; - unsigned int codec_tag{}; - void * priv_data{}; - AVCodecInternal * internal{}; - void * opaque{}; - int64_t bit_rate; - int flags; - int flags2; - uint8_t * extradata; - int extradata_size; - AVRational time_base; - AVRational pkt_timebase; - AVRational framerate; - int delay; - int width, height; - int coded_width, coded_height; - AVRational sample_aspect_ratio; - enum AVPixelFormat pix_fmt; - enum AVPixelFormat sw_pix_fmt; - enum AVColorPrimaries color_primaries; - enum AVColorTransferCharacteristic color_trc; - enum AVColorSpace colorspace; - enum AVColorRange color_range; - enum AVChromaLocation chroma_sample_location; - enum AVFieldOrder field_order; - int refs; - int has_b_frames; - int slice_flags; + const AVClass *av_class{}; + int log_level_offset{}; + AVMediaType codec_type{}; + const AVCodec *codec{}; + AVCodecID codec_id{}; + unsigned int codec_tag{}; + void *priv_data{}; + AVCodecInternal *internal{}; + void *opaque{}; + int64_t bit_rate{}; + int flags{}; + int flags2{}; + uint8_t *extradata{}; + int extradata_size{}; + AVRational time_base{}; + AVRational pkt_timebase{}; + AVRational framerate{}; + int delay{}; + int width{}, height{}; + int coded_width{}, coded_height{}; + AVRational sample_aspect_ratio{}; + enum AVPixelFormat pix_fmt + { + }; + enum AVPixelFormat sw_pix_fmt + { + }; + enum AVColorPrimaries color_primaries + { + }; + enum AVColorTransferCharacteristic color_trc + { + }; + enum AVColorSpace colorspace + { + }; + enum AVColorRange color_range + { + }; + enum AVChromaLocation chroma_sample_location + { + }; + enum AVFieldOrder field_order + { + }; + int refs{}; + int has_b_frames{}; + int slice_flags{}; void (*draw_horiz_band)(struct AVCodecContext *s, - const AVFrame * src, + const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, - int height); - enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt); + int height){}; + enum AVPixelFormat (*get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt){}; // Actually, there is more here, but the variables above are the only we need. }; diff --git a/src/lib/AVCodec/wrappers/AVCodecDescriptorConversion.cpp b/src/lib/AVCodec/wrappers/AVCodecDescriptorConversion.cpp index 9678e9a..36c22d8 100644 --- a/src/lib/AVCodec/wrappers/AVCodecDescriptorConversion.cpp +++ b/src/lib/AVCodec/wrappers/AVCodecDescriptorConversion.cpp @@ -63,7 +63,7 @@ std::vector parseMimeTypes(const char *const *mime_types) int i = 0; while (mime_types[i] != nullptr) - mimeTypes.push_back(std::string(mime_types[i++])); + mimeTypes.emplace_back(mime_types[i++]); return mimeTypes; } @@ -77,13 +77,13 @@ std::vector parseProfiles(const struct AVProfile_57 *profiles) int i = 0; while (profiles[i].profile != FF_PROFILE_UNKNOWN) - parsedProfiles.push_back(std::string(profiles[i++].name)); + parsedProfiles.emplace_back(profiles[i++].name); return parsedProfiles; } CodecDescriptor convertAVCodecDescriptor(const internal::AVCodecDescriptor *avCodecDescriptor, - const Version & avCodecVersion) + const Version &avCodecVersion) { if (avCodecDescriptor == nullptr) throw std::runtime_error("Invalid avCodecDescriptor given"); diff --git a/src/lib/AVCodec/wrappers/AVCodecDescriptorConversionInternal.h b/src/lib/AVCodec/wrappers/AVCodecDescriptorConversionInternal.h index 8593d50..f8d7b9c 100644 --- a/src/lib/AVCodec/wrappers/AVCodecDescriptorConversionInternal.h +++ b/src/lib/AVCodec/wrappers/AVCodecDescriptorConversionInternal.h @@ -17,16 +17,16 @@ struct AVProfile_57 const char *name; }; -typedef AVProfile_57 AVProfile_58; -typedef AVProfile_57 AVProfile_59; -typedef AVProfile_57 AVProfile_60; +using AVProfile_58 = AVProfile_57; +using AVProfile_59 = AVProfile_57; +using AVProfile_60 = AVProfile_57; struct AVCodecDescriptor_56 { AVCodecID id; AVMediaType type; - const char * name; - const char * long_name; + const char *name; + const char *long_name; int props; const char *const *mime_types; }; @@ -35,17 +35,17 @@ struct AVCodecDescriptor_57 { AVCodecID id; AVMediaType type; - const char * name; - const char * long_name; + const char *name; + const char *long_name; int props; - const char *const * mime_types; + const char *const *mime_types; const struct AVProfile_57 *profiles; }; -typedef AVCodecDescriptor_57 AVCodecDescriptor_58; -typedef AVCodecDescriptor_57 AVCodecDescriptor_59; -typedef AVCodecDescriptor_57 AVCodecDescriptor_60; -typedef AVCodecDescriptor_57 AVCodecDescriptor_61; -typedef AVCodecDescriptor_57 AVCodecDescriptor_62; +using AVCodecDescriptor_58 = AVCodecDescriptor_57; +using AVCodecDescriptor_59 = AVCodecDescriptor_57; +using AVCodecDescriptor_60 = AVCodecDescriptor_57; +using AVCodecDescriptor_61 = AVCodecDescriptor_57; +using AVCodecDescriptor_62 = AVCodecDescriptor_57; } // namespace libffmpeg::internal::avcodec diff --git a/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.cpp b/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.cpp index 38aed9a..f6fcfb6 100644 --- a/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.cpp +++ b/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.cpp @@ -57,7 +57,7 @@ avutil::MediaType AVCodecParametersWrapper::getCodecType() const { RETURN_IF_VERSION_TOO_OLD(avutil::MediaType::Unknown); - AVMediaType mediaType; + AVMediaType mediaType{}; CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, mediaType, codec_type); return libffmpeg::avutil::toMediaType(mediaType); } @@ -66,7 +66,7 @@ AVCodecID AVCodecParametersWrapper::getCodecID() const { RETURN_IF_VERSION_TOO_OLD(libffmpeg::internal::AV_CODEC_ID_NONE); - AVCodecID codecID; + AVCodecID codecID{}; CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, codecID, codec_id); return codecID; } @@ -75,10 +75,10 @@ ByteVector AVCodecParametersWrapper::getExtradata() const { RETURN_IF_VERSION_TOO_OLD({}); - uint8_t *extradata; + uint8_t *extradata{}; CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, extradata, extradata); - int extradataSize; + int extradataSize{}; CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, extradataSize, extradata_size); return copyDataFromRawArray(extradata, extradataSize); @@ -88,18 +88,18 @@ Size AVCodecParametersWrapper::getSize() const { RETURN_IF_VERSION_TOO_OLD({}); - int width, height; - CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, width, width); - CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, height, height); + Size size{}; + CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, size.width, width); + CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, size.height, height); - return {width, height}; + return size; } avutil::ColorSpace AVCodecParametersWrapper::getColorspace() const { RETURN_IF_VERSION_TOO_OLD(avutil::ColorSpace::UNSPECIFIED); - internal::AVColorSpace avColorspace; + internal::AVColorSpace avColorspace{}; CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, avColorspace, color_space); return avutil::toColorspace(avColorspace); @@ -109,7 +109,7 @@ avutil::PixelFormatDescriptor AVCodecParametersWrapper::getPixelFormat() const { RETURN_IF_VERSION_TOO_OLD({}); - int pixelFormatIndex; + int pixelFormatIndex{}; CAST_AVCODEC_GET_MEMBER(AVCodecParameters, this->codecParameters, pixelFormatIndex, format); const auto avPixelFormat = static_cast(pixelFormatIndex); @@ -121,10 +121,10 @@ Rational AVCodecParametersWrapper::getSampleAspectRatio() const { RETURN_IF_VERSION_TOO_OLD({}); - AVRational sampleAspectRatio; + AVRational sampleAspectRatio{}; CAST_AVCODEC_GET_MEMBER( AVCodecParameters, this->codecParameters, sampleAspectRatio, sample_aspect_ratio); - return {sampleAspectRatio.num, sampleAspectRatio.den}; + return fromAVRational(sampleAspectRatio); } ChannelLayout AVCodecParametersWrapper::getChannelLayout() const @@ -180,7 +180,7 @@ void AVCodecParametersWrapper::setClearValues() p->width = 0; p->height = 0; { - AVRational ratio; + AVRational ratio{}; ratio.num = 1; ratio.den = 1; p->sample_aspect_ratio = ratio; @@ -212,7 +212,7 @@ void AVCodecParametersWrapper::setClearValues() p->width = 0; p->height = 0; { - AVRational ratio; + AVRational ratio{}; ratio.num = 1; ratio.den = 1; p->sample_aspect_ratio = ratio; @@ -285,7 +285,7 @@ void AVCodecParametersWrapper::setProfileLevel(int profile, int level) void AVCodecParametersWrapper::setSampleAspectRatio(int num, int den) { - AVRational ratio; + AVRational ratio{}; ratio.num = num; ratio.den = den; CAST_AVCODEC_SET_MEMBER(AVCodecParameters, this->codecParameters, sample_aspect_ratio, ratio); diff --git a/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.h b/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.h index c3a2108..91e4b09 100644 --- a/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.h +++ b/src/lib/AVCodec/wrappers/AVCodecParametersWrapper.h @@ -24,14 +24,14 @@ class AVCodecParametersWrapper AVCodecParametersWrapper(libffmpeg::internal::AVCodecParameters *p, std::shared_ptr libraries); - avutil::MediaType getCodecType() const; - libffmpeg::internal::AVCodecID getCodecID() const; - ByteVector getExtradata() const; - Size getSize() const; - avutil::ColorSpace getColorspace() const; - avutil::PixelFormatDescriptor getPixelFormat() const; - Rational getSampleAspectRatio() const; - ChannelLayout getChannelLayout() const; + [[nodiscard]] avutil::MediaType getCodecType() const; + [[nodiscard]] libffmpeg::internal::AVCodecID getCodecID() const; + [[nodiscard]] ByteVector getExtradata() const; + [[nodiscard]] Size getSize() const; + [[nodiscard]] avutil::ColorSpace getColorspace() const; + [[nodiscard]] avutil::PixelFormatDescriptor getPixelFormat() const; + [[nodiscard]] Rational getSampleAspectRatio() const; + [[nodiscard]] ChannelLayout getChannelLayout() const; // Set a default set of (unknown) values void setClearValues(); @@ -44,7 +44,7 @@ class AVCodecParametersWrapper void setProfileLevel(int profile, int level); void setSampleAspectRatio(int num, int den); - libffmpeg::internal::AVCodecParameters *getCodecParameters() const + [[nodiscard]] libffmpeg::internal::AVCodecParameters *getCodecParameters() const { return this->codecParameters; } diff --git a/src/lib/AVCodec/wrappers/AVCodecParametersWrapperInternal.h b/src/lib/AVCodec/wrappers/AVCodecParametersWrapperInternal.h index 4935fd6..b679750 100644 --- a/src/lib/AVCodec/wrappers/AVCodecParametersWrapperInternal.h +++ b/src/lib/AVCodec/wrappers/AVCodecParametersWrapperInternal.h @@ -20,160 +20,160 @@ namespace libffmpeg::internal::avcodec */ struct AVCodecParameters_56 { - AVMediaType codec_type; - AVCodecID codec_id; - uint8_t *extradata; - int extradata_size; - int format; - int profile; - int level; - int width; - int height; - AVRational sample_aspect_ratio; - AVColorSpace color_space; + AVMediaType codec_type{}; + AVCodecID codec_id{}; + uint8_t *extradata{}; + int extradata_size{}; + int format{}; + int profile{}; + int level{}; + int width{}; + int height{}; + AVRational sample_aspect_ratio{}; + AVColorSpace color_space{}; }; struct AVCodecParameters_57 { - AVMediaType codec_type; - AVCodecID codec_id; - uint32_t codec_tag; - uint8_t *extradata; - int extradata_size; - int format; - int64_t bit_rate; - int bits_per_coded_sample; - int bits_per_raw_sample; - int profile; - int level; - int width; - int height; - AVRational sample_aspect_ratio; - AVFieldOrder field_order; - AVColorRange color_range; - AVColorPrimaries color_primaries; - AVColorTransferCharacteristic color_trc; - AVColorSpace color_space; - AVChromaLocation chroma_location; - int video_delay; - uint64_t channel_layout; - int channels; - int sample_rate; - int block_align; - int frame_size; - int initial_padding; - int trailing_padding; - int seek_preroll; + AVMediaType codec_type{}; + AVCodecID codec_id{}; + uint32_t codec_tag{}; + uint8_t *extradata{}; + int extradata_size{}; + int format{}; + int64_t bit_rate{}; + int bits_per_coded_sample{}; + int bits_per_raw_sample{}; + int profile{}; + int level{}; + int width{}; + int height{}; + AVRational sample_aspect_ratio{}; + AVFieldOrder field_order{}; + AVColorRange color_range{}; + AVColorPrimaries color_primaries{}; + AVColorTransferCharacteristic color_trc{}; + AVColorSpace color_space{}; + AVChromaLocation chroma_location{}; + int video_delay{}; + uint64_t channel_layout{}; + int channels{}; + int sample_rate{}; + int block_align{}; + int frame_size{}; + int initial_padding{}; + int trailing_padding{}; + int seek_preroll{}; }; -typedef AVCodecParameters_57 AVCodecParameters_58; +using AVCodecParameters_58 = AVCodecParameters_57; struct AVCodecParameters_59 { - AVMediaType codec_type; - AVCodecID codec_id; - uint32_t codec_tag; - uint8_t *extradata; - int extradata_size; - int format; - int64_t bit_rate; - int bits_per_coded_sample; - int bits_per_raw_sample; - int profile; - int level; - int width; - int height; - AVRational sample_aspect_ratio; - AVFieldOrder field_order; - AVColorRange color_range; - AVColorPrimaries color_primaries; - AVColorTransferCharacteristic color_trc; - AVColorSpace color_space; - AVChromaLocation chroma_location; - int video_delay; - uint64_t channel_layout; - int channels; - int sample_rate; - int block_align; - int frame_size; - int initial_padding; - int trailing_padding; - int seek_preroll; - AVChannelLayout ch_layout; + AVMediaType codec_type{}; + AVCodecID codec_id{}; + uint32_t codec_tag{}; + uint8_t *extradata{}; + int extradata_size{}; + int format{}; + int64_t bit_rate{}; + int bits_per_coded_sample{}; + int bits_per_raw_sample{}; + int profile{}; + int level{}; + int width{}; + int height{}; + AVRational sample_aspect_ratio{}; + AVFieldOrder field_order{}; + AVColorRange color_range{}; + AVColorPrimaries color_primaries{}; + AVColorTransferCharacteristic color_trc{}; + AVColorSpace color_space{}; + AVChromaLocation chroma_location{}; + int video_delay{}; + uint64_t channel_layout{}; + int channels{}; + int sample_rate{}; + int block_align{}; + int frame_size{}; + int initial_padding{}; + int trailing_padding{}; + int seek_preroll{}; + AVChannelLayout ch_layout{}; }; struct AVCodecParameters_60 { - AVMediaType codec_type; - AVCodecID codec_id; - uint32_t codec_tag; - uint8_t *extradata; - int extradata_size; - int format; - int64_t bit_rate; - int bits_per_coded_sample; - int bits_per_raw_sample; - int profile; - int level; - int width; - int height; - AVRational sample_aspect_ratio; - AVFieldOrder field_order; - AVColorRange color_range; - AVColorPrimaries color_primaries; - AVColorTransferCharacteristic color_trc; - AVColorSpace color_space; - AVChromaLocation chroma_location; - int video_delay; - uint64_t channel_layout; - int channels; - int sample_rate; - int block_align; - int frame_size; - int initial_padding; - int trailing_padding; - int seek_preroll; - AVChannelLayout ch_layout; - AVRational framerate; - AVPacketSideData *coded_side_data; - int nb_coded_side_data; + AVMediaType codec_type{}; + AVCodecID codec_id{}; + uint32_t codec_tag{}; + uint8_t *extradata{}; + int extradata_size{}; + int format{}; + int64_t bit_rate{}; + int bits_per_coded_sample{}; + int bits_per_raw_sample{}; + int profile{}; + int level{}; + int width{}; + int height{}; + AVRational sample_aspect_ratio{}; + AVFieldOrder field_order{}; + AVColorRange color_range{}; + AVColorPrimaries color_primaries{}; + AVColorTransferCharacteristic color_trc{}; + AVColorSpace color_space{}; + AVChromaLocation chroma_location{}; + int video_delay{}; + uint64_t channel_layout{}; + int channels{}; + int sample_rate{}; + int block_align{}; + int frame_size{}; + int initial_padding{}; + int trailing_padding{}; + int seek_preroll{}; + AVChannelLayout ch_layout{}; + AVRational framerate{}; + AVPacketSideData *coded_side_data{}; + int nb_coded_side_data{}; }; struct AVCodecParameters_61 { - AVMediaType codec_type; - AVCodecID codec_id; - uint32_t codec_tag; - uint8_t *extradata; - int extradata_size; - AVPacketSideData *coded_side_data; - int nb_coded_side_data; - int format; - int64_t bit_rate; - int bits_per_coded_sample; - int bits_per_raw_sample; - int profile; - int level; - int width; - int height; - AVRational sample_aspect_ratio; - AVRational framerate; - AVFieldOrder field_order; - AVColorRange color_range; - AVColorPrimaries color_primaries; - AVColorTransferCharacteristic color_trc; - AVColorSpace color_space; - AVChromaLocation chroma_location; - int video_delay; - AVChannelLayout ch_layout; - int sample_rate; - int block_align; - int frame_size; - int initial_padding; - int trailing_padding; - int seek_preroll; + AVMediaType codec_type{}; + AVCodecID codec_id{}; + uint32_t codec_tag{}; + uint8_t *extradata{}; + int extradata_size{}; + AVPacketSideData *coded_side_data{}; + int nb_coded_side_data{}; + int format{}; + int64_t bit_rate{}; + int bits_per_coded_sample{}; + int bits_per_raw_sample{}; + int profile{}; + int level{}; + int width{}; + int height{}; + AVRational sample_aspect_ratio{}; + AVRational framerate{}; + AVFieldOrder field_order{}; + AVColorRange color_range{}; + AVColorPrimaries color_primaries{}; + AVColorTransferCharacteristic color_trc{}; + AVColorSpace color_space{}; + AVChromaLocation chroma_location{}; + int video_delay{}; + AVChannelLayout ch_layout{}; + int sample_rate{}; + int block_align{}; + int frame_size{}; + int initial_padding{}; + int trailing_padding{}; + int seek_preroll{}; }; -typedef AVCodecParameters_61 AVCodecParameters_62; +using AVCodecParameters_62 = AVCodecParameters_61; } // namespace libffmpeg::internal::avcodec diff --git a/src/lib/AVCodec/wrappers/AVCodecWrapper.cpp b/src/lib/AVCodec/wrappers/AVCodecWrapper.cpp index 4d0a74a..1205223 100644 --- a/src/lib/AVCodec/wrappers/AVCodecWrapper.cpp +++ b/src/lib/AVCodec/wrappers/AVCodecWrapper.cpp @@ -65,35 +65,35 @@ AVCodecWrapper::AVCodecWrapper(AVCodec *codec, std::shared_ptr std::string AVCodecWrapper::getName() const { - const char *name; + const char *name{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, name, name); - return std::string(name); + return {name}; } std::string AVCodecWrapper::getLongName() const { - const char *longName; + const char *longName{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, longName, long_name); - return std::string(longName); + return {longName}; } avutil::MediaType AVCodecWrapper::getMediaType() const { - AVMediaType mediaType; + AVMediaType mediaType{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, mediaType, type); return libffmpeg::avutil::toMediaType(mediaType); } AVCodecID AVCodecWrapper::getCodecID() const { - AVCodecID codecID; + AVCodecID codecID{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, codecID, id); return codecID; } int AVCodecWrapper::getCapabilities() const { - int capabilities; + int capabilities{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, capabilities, capabilities); return capabilities; } @@ -117,7 +117,7 @@ std::vector AVCodecWrapper::getSupportedFramerates() const std::vector AVCodecWrapper::getPixelFormats() const { - const AVPixelFormat *formatsPointer; + const AVPixelFormat *formatsPointer{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, formatsPointer, pix_fmts); std::vector formats; @@ -135,14 +135,14 @@ std::vector AVCodecWrapper::getPixelFormats() con std::vector AVCodecWrapper::getSupportedSamplerates() const { - const int *rates; + const int *rates{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, rates, supported_samplerates); return convertRawListToVec(rates, 0); } std::vector AVCodecWrapper::getSampleFormats() const { - const AVSampleFormat *formats; + const AVSampleFormat *formats{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, formats, sample_fmts); return convertRawListToVec(formats, AVSampleFormat(-1)); } @@ -191,7 +191,7 @@ std::vector AVCodecWrapper::getSupportedChannelLayouts() const uint8_t AVCodecWrapper::getMaxLowres() const { - uint8_t maxLowres; + uint8_t maxLowres{}; CAST_AVCODEC_GET_MEMBER(AVCodec, this->codec, maxLowres, max_lowres); return maxLowres; } diff --git a/src/lib/AVCodec/wrappers/AVCodecWrapper.h b/src/lib/AVCodec/wrappers/AVCodecWrapper.h index adeab19..3c91fa5 100644 --- a/src/lib/AVCodec/wrappers/AVCodecWrapper.h +++ b/src/lib/AVCodec/wrappers/AVCodecWrapper.h @@ -25,20 +25,20 @@ class AVCodecWrapper AVCodecWrapper(libffmpeg::internal::AVCodec *codec, std::shared_ptr ffmpegLibraries); - explicit operator bool() const { return this->codec != nullptr; } - libffmpeg::internal::AVCodec *getAVCodec() const { return this->codec; } - - std::string getName() const; - std::string getLongName() const; - avutil::MediaType getMediaType() const; - libffmpeg::internal::AVCodecID getCodecID() const; - int getCapabilities() const; - std::vector getSupportedFramerates() const; - std::vector getPixelFormats() const; - std::vector getSupportedSamplerates() const; - std::vector getSampleFormats() const; - std::vector getSupportedChannelLayouts() const; - uint8_t getMaxLowres() const; + explicit operator bool() const { return this->codec != nullptr; } + [[nodiscard]] libffmpeg::internal::AVCodec *getAVCodec() const { return this->codec; } + + [[nodiscard]] std::string getName() const; + [[nodiscard]] std::string getLongName() const; + [[nodiscard]] avutil::MediaType getMediaType() const; + [[nodiscard]] libffmpeg::internal::AVCodecID getCodecID() const; + [[nodiscard]] int getCapabilities() const; + [[nodiscard]] std::vector getSupportedFramerates() const; + [[nodiscard]] std::vector getPixelFormats() const; + [[nodiscard]] std::vector getSupportedSamplerates() const; + [[nodiscard]] std::vector getSampleFormats() const; + [[nodiscard]] std::vector getSupportedChannelLayouts() const; + [[nodiscard]] uint8_t getMaxLowres() const; private: libffmpeg::internal::AVCodec *codec{}; diff --git a/src/lib/AVCodec/wrappers/AVCodecWrapperInternal.h b/src/lib/AVCodec/wrappers/AVCodecWrapperInternal.h index 1d581e2..f313f21 100644 --- a/src/lib/AVCodec/wrappers/AVCodecWrapperInternal.h +++ b/src/lib/AVCodec/wrappers/AVCodecWrapperInternal.h @@ -15,80 +15,80 @@ namespace libffmpeg::internal::avcodec struct AVCodec_56 { - const char *name; - const char *long_name; - AVMediaType type; - AVCodecID id; - int capabilities; - const AVRational *supported_framerates; - const AVPixelFormat *pix_fmts; - const int *supported_samplerates; - const AVSampleFormat *sample_fmts; - const uint64_t *channel_layouts; - uint8_t max_lowres; - const AVClass *priv_class; + const char *name{}; + const char *long_name{}; + AVMediaType type{}; + AVCodecID id{}; + int capabilities{}; + const AVRational *supported_framerates{}; + const AVPixelFormat *pix_fmts{}; + const int *supported_samplerates{}; + const AVSampleFormat *sample_fmts{}; + const uint64_t *channel_layouts{}; + uint8_t max_lowres{}; + const AVClass *priv_class{}; // Actually, there is more here, but nothing more of the public API }; -typedef AVCodec_56 AVCodec_57; -typedef AVCodec_56 AVCodec_58; +using AVCodec_57 = AVCodec_56; +using AVCodec_58 = AVCodec_56; struct AVCodec_59 { - const char *name; - const char *long_name; - AVMediaType type; - AVCodecID id; - int capabilities; - uint8_t max_lowres; - const AVRational *supported_framerates; - const AVPixelFormat *pix_fmts; - const int *supported_samplerates; - const AVSampleFormat *sample_fmts; - const uint64_t *channel_layouts; - const AVClass *priv_class; + const char *name{}; + const char *long_name{}; + AVMediaType type{}; + AVCodecID id{}; + int capabilities{}; + uint8_t max_lowres{}; + const AVRational *supported_framerates{}; + const AVPixelFormat *pix_fmts{}; + const int *supported_samplerates{}; + const AVSampleFormat *sample_fmts{}; + const uint64_t *channel_layouts{}; + const AVClass *priv_class{}; // Actually, there is more here, but nothing more of the public API }; struct AVCodec_60 { - const char *name; - const char *long_name; - AVMediaType type; - AVCodecID id; - int capabilities; - uint8_t max_lowres; - const AVRational *supported_framerates; - const AVPixelFormat *pix_fmts; - const int *supported_samplerates; - const AVSampleFormat *sample_fmts; - const uint64_t *deprecated_channel_layouts; // Actually named channel_layouts - const AVClass *priv_class; - const AVProfile *profiles; - const char *wrapper_name; - const AVChannelLayout *channel_layouts; // Actual name ch_layouts + const char *name{}; + const char *long_name{}; + AVMediaType type{}; + AVCodecID id{}; + int capabilities{}; + uint8_t max_lowres{}; + const AVRational *supported_framerates{}; + const AVPixelFormat *pix_fmts{}; + const int *supported_samplerates{}; + const AVSampleFormat *sample_fmts{}; + const uint64_t *deprecated_channel_layouts{}; // Actually named channel_layouts + const AVClass *priv_class{}; + const AVProfile *profiles{}; + const char *wrapper_name{}; + const AVChannelLayout *channel_layouts{}; // Actual name ch_layouts }; struct AVCodec_61 { - const char *name; - const char *long_name; - AVMediaType type; - AVCodecID id; - int capabilities; - uint8_t max_lowres; - const AVRational *supported_framerates; - const AVPixelFormat *pix_fmts; - const int *supported_samplerates; - const AVSampleFormat *sample_fmts; - const AVClass *priv_class; - const AVProfile *profiles; - const char *wrapper_name; - const AVChannelLayout *channel_layouts; + const char *name{}; + const char *long_name{}; + AVMediaType type{}; + AVCodecID id{}; + int capabilities{}; + uint8_t max_lowres{}; + const AVRational *supported_framerates{}; + const AVPixelFormat *pix_fmts{}; + const int *supported_samplerates{}; + const AVSampleFormat *sample_fmts{}; + const AVClass *priv_class{}; + const AVProfile *profiles{}; + const char *wrapper_name{}; + const AVChannelLayout *channel_layouts{}; }; -typedef AVCodec_61 AVCodec_62; +using AVCodec_62 = AVCodec_61; } // namespace libffmpeg::internal::avcodec diff --git a/src/lib/AVCodec/wrappers/AVPacketWrapper.cpp b/src/lib/AVCodec/wrappers/AVPacketWrapper.cpp index c3abc37..5ec4a0e 100644 --- a/src/lib/AVCodec/wrappers/AVPacketWrapper.cpp +++ b/src/lib/AVCodec/wrappers/AVPacketWrapper.cpp @@ -7,6 +7,7 @@ #include "AVPacketWrapper.h" #include +#include #include "AVPacketWrapperInternal.h" #include "CastCodecClasses.h" @@ -42,7 +43,7 @@ AVPacketWrapper::AVPacketWrapper(std::shared_ptr ffmpegLibrari this->allocateNewPacket(); } -AVPacketWrapper::AVPacketWrapper(const ByteVector & data, +AVPacketWrapper::AVPacketWrapper(const ByteVector &data, std::shared_ptr ffmpegLibraries) : ffmpegLibraries(ffmpegLibraries) { @@ -55,7 +56,7 @@ AVPacketWrapper::AVPacketWrapper(const ByteVector & data, if (ret > 0) throw std::runtime_error("Error calling av_new_packet"); - uint8_t *dataPointer; + uint8_t *dataPointer{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), dataPointer, data); std::memcpy(dataPointer, data.data(), data.size()); } @@ -84,39 +85,38 @@ void AVPacketWrapper::setTimestamps(const int64_t dts, const int64_t pts) int AVPacketWrapper::getStreamIndex() const { - int index; + int index{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), index, stream_index); return index; } std::optional AVPacketWrapper::getPTS() const { - int64_t pts; + int64_t pts{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), pts, pts); - constexpr int64_t AV_NOPTS_VALUE = 0x8000000000000000; - if (pts == AV_NOPTS_VALUE) + if (pts == internal::AV_NOPTS_VALUE) return {}; return pts; } int64_t AVPacketWrapper::getDTS() const { - int64_t dts; + int64_t dts{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), dts, dts); return dts; } int64_t AVPacketWrapper::getDuration() const { - int64_t duration; + int64_t duration{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), duration, duration); return duration; } AVPacketWrapper::Flags AVPacketWrapper::getFlags() const { - int flagsAsInt; + int flagsAsInt{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), flagsAsInt, flags); Flags flags; @@ -133,7 +133,7 @@ AVPacketWrapper::Flags AVPacketWrapper::getFlags() const int AVPacketWrapper::getDataSize() const { - int dataSize; + int dataSize{}; CAST_AVCODEC_GET_MEMBER(AVPacket, this->packet.get(), dataSize, size); return dataSize; } diff --git a/src/lib/AVCodec/wrappers/AVPacketWrapper.h b/src/lib/AVCodec/wrappers/AVPacketWrapper.h index cb59211..f07094e 100644 --- a/src/lib/AVCodec/wrappers/AVPacketWrapper.h +++ b/src/lib/AVCodec/wrappers/AVPacketWrapper.h @@ -16,17 +16,21 @@ namespace libffmpeg::avcodec class AVPacketWrapper { public: - AVPacketWrapper() = delete; - AVPacketWrapper(AVPacketWrapper &&packet) = default; + AVPacketWrapper() = delete; + AVPacketWrapper(const AVPacketWrapper &) = delete; + AVPacketWrapper &operator=(const AVPacketWrapper &) = delete; + AVPacketWrapper(AVPacketWrapper &&packet) noexcept = default; + AVPacketWrapper &operator=(AVPacketWrapper &&) noexcept = default; AVPacketWrapper(std::shared_ptr ffmpegLibraries); AVPacketWrapper(const ByteVector &data, std::shared_ptr ffmpegLibraries); + ~AVPacketWrapper() = default; // Todo: Needs to be tested - std::optional clone() const; + [[nodiscard]] std::optional clone() const; void setTimestamps(const int64_t dts, const int64_t pts); - libffmpeg::internal::AVPacket *getPacket() const { return this->packet.get(); } + [[nodiscard]] libffmpeg::internal::AVPacket *getPacket() const { return this->packet.get(); } struct Flags { @@ -35,13 +39,13 @@ class AVPacketWrapper bool discard{}; }; - int getStreamIndex() const; - std::optional getPTS() const; - int64_t getDTS() const; - int64_t getDuration() const; - Flags getFlags() const; - int getDataSize() const; - ByteVector getData() const; + [[nodiscard]] int getStreamIndex() const; + [[nodiscard]] std::optional getPTS() const; + [[nodiscard]] int64_t getDTS() const; + [[nodiscard]] int64_t getDuration() const; + [[nodiscard]] Flags getFlags() const; + [[nodiscard]] int getDataSize() const; + [[nodiscard]] ByteVector getData() const; explicit operator bool() const { return this->packet != nullptr; }; @@ -53,7 +57,7 @@ class AVPacketWrapper public: AVPacketDeleter() = default; AVPacketDeleter(const std::shared_ptr &ffmpegLibraries) - : ffmpegLibraries(ffmpegLibraries){}; + : ffmpegLibraries(ffmpegLibraries) {}; void operator()(libffmpeg::internal::AVPacket *packet) const noexcept; private: diff --git a/src/lib/AVCodec/wrappers/AVPacketWrapperInternal.h b/src/lib/AVCodec/wrappers/AVPacketWrapperInternal.h index 55525c0..14a429e 100644 --- a/src/lib/AVCodec/wrappers/AVPacketWrapperInternal.h +++ b/src/lib/AVCodec/wrappers/AVPacketWrapperInternal.h @@ -17,10 +17,10 @@ namespace libffmpeg::internal::avcodec // since its size is used in other structures (e.g. AVStream). struct AVPacket_56 { - AVBufferRef * buf; + AVBufferRef *buf; int64_t pts; int64_t dts; - uint8_t * data; + uint8_t *data; int size; int stream_index; int flags; @@ -28,17 +28,17 @@ struct AVPacket_56 int side_data_elems; int duration; void (*destruct)(AVPacket *); - void * priv; + void *priv; int64_t pos; int64_t convergence_duration; }; struct AVPacket_57 { - AVBufferRef * buf; + AVBufferRef *buf; int64_t pts; int64_t dts; - uint8_t * data; + uint8_t *data; int size; int stream_index; int flags; @@ -49,14 +49,14 @@ struct AVPacket_57 int64_t convergence_duration; }; -typedef AVPacket_57 AVPacket_58; +using AVPacket_58 = AVPacket_57; struct AVPacket_59 { - AVBufferRef * buf; + AVBufferRef *buf; int64_t pts; int64_t dts; - uint8_t * data; + uint8_t *data; int size; int stream_index; int flags; @@ -64,13 +64,13 @@ struct AVPacket_59 int side_data_elems; int64_t duration; int64_t pos; - void * opaque; - AVBufferRef * opaque_ref; + void *opaque; + AVBufferRef *opaque_ref; AVRational time_base; }; -typedef AVPacket_59 AVPacket_60; -typedef AVPacket_59 AVPacket_61; -typedef AVPacket_59 AVPacket_62; +using AVPacket_60 = AVPacket_59; +using AVPacket_61 = AVPacket_59; +using AVPacket_62 = AVPacket_59; } // namespace libffmpeg::internal::avcodec diff --git a/src/lib/AVFormat/wrappers/AVFormatContextWrapper.cpp b/src/lib/AVFormat/wrappers/AVFormatContextWrapper.cpp index ba7469b..660408a 100644 --- a/src/lib/AVFormat/wrappers/AVFormatContextWrapper.cpp +++ b/src/lib/AVFormat/wrappers/AVFormatContextWrapper.cpp @@ -31,11 +31,19 @@ AVFormatContextWrapper::AVFormatContextWrapper(std::shared_ptr this->ffmpegLibraries = ffmpegLibraries; } -AVFormatContextWrapper::AVFormatContextWrapper(AVFormatContextWrapper &&wrapper) +AVFormatContextWrapper::AVFormatContextWrapper(AVFormatContextWrapper &&wrapper) noexcept + : formatContext(wrapper.formatContext), ffmpegLibraries(std::move(wrapper.ffmpegLibraries)) { - this->formatContext = wrapper.formatContext; - wrapper.formatContext = nullptr; - this->ffmpegLibraries = std::move(wrapper.ffmpegLibraries); +} + +AVFormatContextWrapper &AVFormatContextWrapper::operator=(AVFormatContextWrapper &&wrapper) noexcept +{ + if (this != &wrapper) + { + this->formatContext = wrapper.formatContext; + this->ffmpegLibraries = std::move(wrapper.ffmpegLibraries); + } + return *this; } AVFormatContextWrapper::~AVFormatContextWrapper() @@ -113,14 +121,14 @@ AVStreamWrapper AVFormatContextWrapper::getStream(int idx) const AVStream *streamPointer{}; CAST_AVFORMAT_GET_MEMBER(AVFormatContext, this->formatContext, streamPointer, streams[idx]); - return AVStreamWrapper(streamPointer, this->ffmpegLibraries); + return {streamPointer, this->ffmpegLibraries}; } AVInputFormatWrapper AVFormatContextWrapper::getInputFormat() const { AVInputFormat *inputFormatPointer{}; CAST_AVFORMAT_GET_MEMBER(AVFormatContext, this->formatContext, inputFormatPointer, iformat); - return AVInputFormatWrapper(inputFormatPointer, this->ffmpegLibraries); + return {inputFormatPointer, this->ffmpegLibraries}; } int64_t AVFormatContextWrapper::getStartTime() const @@ -141,7 +149,7 @@ avutil::AVDictionaryWrapper AVFormatContextWrapper::getMetadata() const { AVDictionary *metadata{}; CAST_AVFORMAT_GET_MEMBER(AVFormatContext, this->formatContext, metadata, metadata); - return avutil::AVDictionaryWrapper(metadata, this->ffmpegLibraries); + return {metadata, this->ffmpegLibraries}; } bool AVFormatContextWrapper::getNextPacket(avcodec::AVPacketWrapper &packet) diff --git a/src/lib/AVFormat/wrappers/AVFormatContextWrapper.h b/src/lib/AVFormat/wrappers/AVFormatContextWrapper.h index 07ff00d..062f19d 100644 --- a/src/lib/AVFormat/wrappers/AVFormatContextWrapper.h +++ b/src/lib/AVFormat/wrappers/AVFormatContextWrapper.h @@ -21,9 +21,11 @@ namespace libffmpeg::avformat class AVFormatContextWrapper { public: - AVFormatContextWrapper() = delete; - AVFormatContextWrapper(const AVFormatContextWrapper &) = delete; - AVFormatContextWrapper(AVFormatContextWrapper &&wrapper); + AVFormatContextWrapper() = delete; + AVFormatContextWrapper(const AVFormatContextWrapper &) = delete; + AVFormatContextWrapper &operator=(const AVFormatContextWrapper &) = delete; + AVFormatContextWrapper(AVFormatContextWrapper &&wrapper) noexcept; + AVFormatContextWrapper &operator=(AVFormatContextWrapper &&) noexcept; AVFormatContextWrapper(std::shared_ptr ffmpegLibraries); ~AVFormatContextWrapper(); @@ -32,13 +34,13 @@ class AVFormatContextWrapper explicit operator bool() const; - std::vector getStreams() const; - int getNumberStreams() const; - AVStreamWrapper getStream(int idx) const; - AVInputFormatWrapper getInputFormat() const; - int64_t getStartTime() const; - int64_t getDuration() const; - avutil::AVDictionaryWrapper getMetadata() const; + [[nodiscard]] std::vector getStreams() const; + [[nodiscard]] int getNumberStreams() const; + [[nodiscard]] AVStreamWrapper getStream(int idx) const; + [[nodiscard]] AVInputFormatWrapper getInputFormat() const; + [[nodiscard]] int64_t getStartTime() const; + [[nodiscard]] int64_t getDuration() const; + [[nodiscard]] avutil::AVDictionaryWrapper getMetadata() const; bool getNextPacket(avcodec::AVPacketWrapper &packet); diff --git a/src/lib/AVFormat/wrappers/AVFormatContextWrapperInternal.h b/src/lib/AVFormat/wrappers/AVFormatContextWrapperInternal.h index 3f53a83..d7436cd 100644 --- a/src/lib/AVFormat/wrappers/AVFormatContextWrapperInternal.h +++ b/src/lib/AVFormat/wrappers/AVFormatContextWrapperInternal.h @@ -11,19 +11,21 @@ namespace libffmpeg::internal::avformat { +constexpr int MAX_FILENAME_SIZE = 1024; + // AVFormatContext is part of avformat. // These functions give us version independent access to the structs. struct AVFormatContext_56 { - const AVClass * av_class; - AVInputFormat * iformat; + const AVClass *av_class; + AVInputFormat *iformat; AVOutputFormat *oformat; - void * priv_data; - AVIOContext * pb; + void *priv_data; + AVIOContext *pb; int ctx_flags; unsigned int nb_streams; - AVStream ** streams; - char filename[1024]; + AVStream **streams; + char filename[MAX_FILENAME_SIZE]; int64_t start_time; int64_t duration; int bit_rate; @@ -32,33 +34,33 @@ struct AVFormatContext_56 int flags; unsigned int probesize; int max_analyze_duration; - const uint8_t * key; + const uint8_t *key; int keylen; unsigned int nb_programs; - AVProgram ** programs; + AVProgram **programs; AVCodecID video_codec_id; AVCodecID audio_codec_id; AVCodecID subtitle_codec_id; unsigned int max_index_size; unsigned int max_picture_buffer; unsigned int nb_chapters; - AVChapter ** chapters; - AVDictionary * metadata; + AVChapter **chapters; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; struct AVFormatContext_57 { - const AVClass * av_class; - AVInputFormat * iformat; + const AVClass *av_class; + AVInputFormat *iformat; AVOutputFormat *oformat; - void * priv_data; - AVIOContext * pb; + void *priv_data; + AVIOContext *pb; int ctx_flags; unsigned int nb_streams; - AVStream ** streams; - char filename[1024]; + AVStream **streams; + char filename[MAX_FILENAME_SIZE]; int64_t start_time; int64_t duration; int64_t bit_rate; @@ -67,34 +69,34 @@ struct AVFormatContext_57 int flags; int64_t probesize; int64_t max_analyze_duration; - const uint8_t * key; + const uint8_t *key; int keylen; unsigned int nb_programs; - AVProgram ** programs; + AVProgram **programs; AVCodecID video_codec_id; AVCodecID audio_codec_id; AVCodecID subtitle_codec_id; unsigned int max_index_size; unsigned int max_picture_buffer; unsigned int nb_chapters; - AVChapter ** chapters; - AVDictionary * metadata; + AVChapter **chapters; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; struct AVFormatContext_58 { - const AVClass * av_class; - AVInputFormat * iformat; + const AVClass *av_class; + AVInputFormat *iformat; AVOutputFormat *oformat; - void * priv_data; - AVIOContext * pb; + void *priv_data; + AVIOContext *pb; int ctx_flags; unsigned int nb_streams; - AVStream ** streams; - char filename[1024]; - char * url; + AVStream **streams; + char filename[MAX_FILENAME_SIZE]; + char *url; int64_t start_time; int64_t duration; int64_t bit_rate; @@ -103,33 +105,33 @@ struct AVFormatContext_58 int flags; int64_t probesize; int64_t max_analyze_duration; - const uint8_t * key; + const uint8_t *key; int keylen; unsigned int nb_programs; - AVProgram ** programs; + AVProgram **programs; AVCodecID video_codec_id; AVCodecID audio_codec_id; AVCodecID subtitle_codec_id; unsigned int max_index_size; unsigned int max_picture_buffer; unsigned int nb_chapters; - AVChapter ** chapters; - AVDictionary * metadata; + AVChapter **chapters; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; struct AVFormatContext_59 { - const AVClass * av_class; - AVInputFormat * iformat; + const AVClass *av_class; + AVInputFormat *iformat; AVOutputFormat *oformat; - void * priv_data; - AVIOContext * pb; + void *priv_data; + AVIOContext *pb; int ctx_flags; unsigned int nb_streams; - AVStream ** streams; - char * url; + AVStream **streams; + char *url; int64_t start_time; int64_t duration; int64_t bit_rate; @@ -138,39 +140,39 @@ struct AVFormatContext_59 int flags; int64_t probesize; int64_t max_analyze_duration; - const uint8_t * key; + const uint8_t *key; int keylen; unsigned int nb_programs; - AVProgram ** programs; + AVProgram **programs; AVCodecID video_codec_id; AVCodecID audio_codec_id; AVCodecID subtitle_codec_id; unsigned int max_index_size; unsigned int max_picture_buffer; unsigned int nb_chapters; - AVChapter ** chapters; - AVDictionary * metadata; + AVChapter **chapters; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; -typedef AVFormatContext_59 AVFormatContext_60; +using AVFormatContext_60 = AVFormatContext_59; struct AVFormatContext_61 { - const AVClass * av_class; - AVInputFormat * iformat; + const AVClass *av_class; + AVInputFormat *iformat; AVOutputFormat *oformat; - void * priv_data; - AVIOContext * pb; + void *priv_data; + AVIOContext *pb; int ctx_flags; unsigned int nb_streams; - AVStream ** streams; + AVStream **streams; unsigned int nb_stream_groups; // Added in 61 AVStreamGroup **stream_groups; // Added in 61 unsigned int nb_chapters; // Moved in 61 - AVChapter ** chapters; // Moved in 61 - char * url; + AVChapter **chapters; // Moved in 61 + char *url; int64_t start_time; int64_t duration; int64_t bit_rate; @@ -179,19 +181,19 @@ struct AVFormatContext_61 int flags; int64_t probesize; int64_t max_analyze_duration; - const uint8_t * key; + const uint8_t *key; int keylen; unsigned int nb_programs; - AVProgram ** programs; + AVProgram **programs; AVCodecID video_codec_id; AVCodecID audio_codec_id; AVCodecID subtitle_codec_id; AVCodecID data_codec_id; // Added in 61 - AVDictionary * metadata; // Moved in 61 + AVDictionary *metadata; // Moved in 61 // Actually, there is more here, but the variables above are the only we need. }; -typedef AVFormatContext_61 AVFormatContext_62; +using AVFormatContext_62 = AVFormatContext_61; } // namespace libffmpeg::internal::avformat diff --git a/src/lib/AVFormat/wrappers/AVIOContextWrapper.cpp b/src/lib/AVFormat/wrappers/AVIOContextWrapper.cpp index 7b18975..30498be 100644 --- a/src/lib/AVFormat/wrappers/AVIOContextWrapper.cpp +++ b/src/lib/AVFormat/wrappers/AVIOContextWrapper.cpp @@ -50,9 +50,6 @@ int64_t seekCallback(void *opaque, int64_t offset, int whence) } // namespace -AVIOContextWrapper::~AVIOContextWrapper() -{ -} AVIOContext *AVIOContextWrapper::getAVIOContext() const { diff --git a/src/lib/AVFormat/wrappers/AVIOContextWrapper.h b/src/lib/AVFormat/wrappers/AVIOContextWrapper.h index 348c00a..ae312f1 100644 --- a/src/lib/AVFormat/wrappers/AVIOContextWrapper.h +++ b/src/lib/AVFormat/wrappers/AVIOContextWrapper.h @@ -18,9 +18,9 @@ class AVIOContextWrapper { public: AVIOContextWrapper() = default; - virtual ~AVIOContextWrapper() = 0; + virtual ~AVIOContextWrapper() = default; - internal::AVIOContext *getAVIOContext() const; + [[nodiscard]] internal::AVIOContext *getAVIOContext() const; explicit operator bool() const { return !!this->ioContext; }; @@ -47,9 +47,9 @@ class AVIOInputContext : public AVIOContextWrapper AVIOInputContext(std::shared_ptr ffmpegLibraries); virtual ~AVIOInputContext() = default; - virtual std::optional readData(uint8_t *buf, int buf_size) = 0; - virtual std::optional getFileSize() const = 0; - virtual bool seek(int64_t offset) = 0; + virtual std::optional readData(uint8_t *buf, int buf_size) = 0; + [[nodiscard]] virtual std::optional getFileSize() const = 0; + virtual bool seek(int64_t offset) = 0; }; } // namespace libffmpeg::avformat diff --git a/src/lib/AVFormat/wrappers/AVInputFormatWrapper.h b/src/lib/AVFormat/wrappers/AVInputFormatWrapper.h index 98658a2..1bb5bfa 100644 --- a/src/lib/AVFormat/wrappers/AVInputFormatWrapper.h +++ b/src/lib/AVFormat/wrappers/AVInputFormatWrapper.h @@ -43,11 +43,11 @@ class AVInputFormatWrapper AVInputFormatWrapper(libffmpeg::internal::AVInputFormat *inputFormat, std::shared_ptr ffmpegLibraries); - std::string getName() const; - std::string getLongName() const; - AVInputFormatFlags getFlags() const; - std::string getExtensions() const; - std::string getMimeType() const; + [[nodiscard]] std::string getName() const; + [[nodiscard]] std::string getLongName() const; + [[nodiscard]] AVInputFormatFlags getFlags() const; + [[nodiscard]] std::string getExtensions() const; + [[nodiscard]] std::string getMimeType() const; explicit operator bool() const { return this->inputFormat != nullptr; }; diff --git a/src/lib/AVFormat/wrappers/AVInputFormatWrapperInternal.h b/src/lib/AVFormat/wrappers/AVInputFormatWrapperInternal.h index aa960e7..7f0bd88 100644 --- a/src/lib/AVFormat/wrappers/AVInputFormatWrapperInternal.h +++ b/src/lib/AVFormat/wrappers/AVInputFormatWrapperInternal.h @@ -30,22 +30,22 @@ constexpr auto AVFMT_SEEK_TO_PTS = 0x4000000; struct AVInputFormat_56 { - const char * name; - const char * long_name; + const char *name; + const char *long_name; int flags; - const char * extensions; + const char *extensions; const struct AVCodecTag *const *codec_tag; - const AVClass * priv_class; - const char * mime_type; + const AVClass *priv_class; + const char *mime_type; // There is more but it is not part of the public ABI }; -typedef AVInputFormat_56 AVInputFormat_57; -typedef AVInputFormat_56 AVInputFormat_58; -typedef AVInputFormat_56 AVInputFormat_59; -typedef AVInputFormat_56 AVInputFormat_60; -typedef AVInputFormat_56 AVInputFormat_61; -typedef AVInputFormat_56 AVInputFormat_62; +using AVInputFormat_57 = AVInputFormat_56; +using AVInputFormat_58 = AVInputFormat_56; +using AVInputFormat_59 = AVInputFormat_56; +using AVInputFormat_60 = AVInputFormat_56; +using AVInputFormat_61 = AVInputFormat_56; +using AVInputFormat_62 = AVInputFormat_56; } // namespace libffmpeg::internal::avformat diff --git a/src/lib/AVFormat/wrappers/AVStreamWrapper.cpp b/src/lib/AVFormat/wrappers/AVStreamWrapper.cpp index b83a829..67935ec 100644 --- a/src/lib/AVFormat/wrappers/AVStreamWrapper.cpp +++ b/src/lib/AVFormat/wrappers/AVStreamWrapper.cpp @@ -7,6 +7,7 @@ #include "AVStreamWrapper.h" #include +#include #include "AVStreamWrapperInternal.h" #include "CastFormatClasses.h" @@ -45,7 +46,7 @@ AVStreamWrapper::AVStreamWrapper(AVStream *stream, int AVStreamWrapper::getIndex() const { - int index; + int index{}; CAST_AVFORMAT_GET_MEMBER(AVStream, this->stream, index, index); return index; } @@ -74,18 +75,18 @@ AVCodecID AVStreamWrapper::getCodecID() const Rational AVStreamWrapper::getAverageFrameRate() const { - AVRational frameRate; + AVRational frameRate{}; CAST_AVFORMAT_GET_MEMBER(AVStream, this->stream, frameRate, avg_frame_rate); - return {frameRate.num, frameRate.den}; + return fromAVRational(frameRate); } Rational AVStreamWrapper::getTimeBase() const { - AVRational timebase; + AVRational timebase{}; CAST_AVFORMAT_GET_MEMBER(AVStream, this->stream, timebase, time_base); if (timebase.den != 0 && timebase.num != 0) - return {timebase.num, timebase.den}; + return fromAVRational(timebase); // The stream time_base seems not to be set. Try the time_base in the codec. if (const auto codecContext = this->getCodecContext()) diff --git a/src/lib/AVFormat/wrappers/AVStreamWrapper.h b/src/lib/AVFormat/wrappers/AVStreamWrapper.h index e682e9c..63d278d 100644 --- a/src/lib/AVFormat/wrappers/AVStreamWrapper.h +++ b/src/lib/AVFormat/wrappers/AVStreamWrapper.h @@ -22,27 +22,27 @@ class AVStreamWrapper { public: AVStreamWrapper() = delete; - AVStreamWrapper(libffmpeg::internal::AVStream * stream, + AVStreamWrapper(libffmpeg::internal::AVStream *stream, std::shared_ptr ffmpegLibraries); explicit operator bool() const { return this->stream != nullptr; }; - int getIndex() const; - avutil::MediaType getCodecType() const; - libffmpeg::internal::AVCodecID getCodecID() const; - Rational getAverageFrameRate() const; - Rational getTimeBase() const; - Size getFrameSize() const; - avutil::ColorSpace getColorspace() const; - avutil::PixelFormatDescriptor getPixelFormat() const; - ByteVector getExtradata() const; + [[nodiscard]] int getIndex() const; + [[nodiscard]] avutil::MediaType getCodecType() const; + [[nodiscard]] libffmpeg::internal::AVCodecID getCodecID() const; + [[nodiscard]] Rational getAverageFrameRate() const; + [[nodiscard]] Rational getTimeBase() const; + [[nodiscard]] Size getFrameSize() const; + [[nodiscard]] avutil::ColorSpace getColorspace() const; + [[nodiscard]] avutil::PixelFormatDescriptor getPixelFormat() const; + [[nodiscard]] ByteVector getExtradata() const; - std::optional getCodecDescriptor() const; - std::optional getCodecParameters() const; - std::optional getCodecContext() const; + [[nodiscard]] std::optional getCodecDescriptor() const; + [[nodiscard]] std::optional getCodecParameters() const; + [[nodiscard]] std::optional getCodecContext() const; private: - libffmpeg::internal::AVStream * stream{}; + libffmpeg::internal::AVStream *stream{}; std::shared_ptr ffmpegLibraries{}; }; diff --git a/src/lib/AVFormat/wrappers/AVStreamWrapperInternal.h b/src/lib/AVFormat/wrappers/AVStreamWrapperInternal.h index bf7fe52..51cda49 100644 --- a/src/lib/AVFormat/wrappers/AVStreamWrapperInternal.h +++ b/src/lib/AVFormat/wrappers/AVStreamWrapperInternal.h @@ -20,8 +20,8 @@ struct AVStream_56 { int index{}; int id{}; - AVCodecContext * codec{}; - void * priv_data{}; + AVCodecContext *codec{}; + void *priv_data{}; AVFrac pts{}; AVRational time_base{}; int64_t start_time{}; @@ -30,28 +30,31 @@ struct AVStream_56 int disposition{}; AVDiscard discard{}; AVRational sample_aspect_ratio{}; - AVDictionary * metadata{}; + AVDictionary *metadata{}; AVRational avg_frame_rate{}; avcodec::AVPacket_56 attached_pic{}; - AVPacketSideData * side_data{}; + AVPacketSideData *side_data{}; int nb_side_data{}; int event_flags{}; }; struct AVProbeData_57 { - const char * filename{}; + const char *filename{}; unsigned char *buf{}; int buf_size{}; - const char * mime_type{}; + const char *mime_type{}; }; +constexpr int MAX_REORDER_DELAY = 16; +constexpr int MAX_STD_TIMEBASES = (30 * 12 + 30 + 3 + 6); + struct AVStream_57 { int index{}; int id{}; - AVCodecContext * codec{}; // Deprecated. - void * priv_data{}; + AVCodecContext *codec{}; // Deprecated. + void *priv_data{}; AVFrac pts{}; // Deprecated. AVRational time_base{}; int64_t start_time{}; @@ -60,17 +63,16 @@ struct AVStream_57 int disposition{}; AVDiscard discard{}; AVRational sample_aspect_ratio{}; - AVDictionary * metadata{}; + AVDictionary *metadata{}; AVRational avg_frame_rate{}; avcodec::AVPacket_57 attached_pic{}; - AVPacketSideData * side_data{}; + AVPacketSideData *side_data{}; int nb_side_data{}; int event_flags{}; // All field following this line are not part of the public API and may change/be removed. - // However, we still need them here because further below some fields which are part of the public - // API will follow. I really don't understand who thought up this idiotic scheme... -#define MAX_STD_TIMEBASES (30 * 12 + 30 + 3 + 6) - struct + // However, we still need them here because further below some fields which are part of the + // public API will follow. I really don't understand who thought up this idiotic scheme... + struct Info { int64_t last_dts{}; int64_t duration_gcd{}; @@ -85,7 +87,8 @@ struct AVStream_57 int fps_first_dts_idx{}; int64_t fps_last_dts{}; int fps_last_dts_idx{}; - } * info; + }; + Info *info{}; int pts_wrap_bits{}; int64_t first_dts{}; int64_t cur_dts{}; @@ -95,40 +98,39 @@ struct AVStream_57 int codec_info_nb_frames{}; AVStreamParseType need_parsing{}; struct AVCodecParserContext *parser{}; - struct AVPacketList * last_in_packet_buffer{}; + struct AVPacketList *last_in_packet_buffer{}; AVProbeData_57 probe_data{}; -#define MAX_REORDER_DELAY 16 - int64_t pts_buffer[MAX_REORDER_DELAY + 1]{}; - AVIndexEntry *index_entries{}; - int nb_index_entries{}; - unsigned int index_entries_allocated_size{}; - AVRational r_frame_rate{}; - int stream_identifier{}; - int64_t interleaver_chunk_size{}; - int64_t interleaver_chunk_duration{}; - int request_probe{}; - int skip_to_keyframe{}; - int skip_samples{}; - int64_t start_skip_samples{}; - int64_t first_discard_sample{}; - int64_t last_discard_sample{}; - int nb_decoded_frames{}; - int64_t mux_ts_offset{}; - int64_t pts_wrap_reference{}; - int pts_wrap_behavior{}; - int update_initial_durations_done{}; - int64_t pts_reorder_error[MAX_REORDER_DELAY + 1]{}; - uint8_t pts_reorder_error_count[MAX_REORDER_DELAY + 1]{}; - int64_t last_dts_for_order_check{}; - uint8_t dts_ordered{}; - uint8_t dts_misordered{}; - int inject_global_side_data{}; + int64_t pts_buffer[MAX_REORDER_DELAY + 1]{}; + AVIndexEntry *index_entries{}; + int nb_index_entries{}; + unsigned int index_entries_allocated_size{}; + AVRational r_frame_rate{}; + int stream_identifier{}; + int64_t interleaver_chunk_size{}; + int64_t interleaver_chunk_duration{}; + int request_probe{}; + int skip_to_keyframe{}; + int skip_samples{}; + int64_t start_skip_samples{}; + int64_t first_discard_sample{}; + int64_t last_discard_sample{}; + int nb_decoded_frames{}; + int64_t mux_ts_offset{}; + int64_t pts_wrap_reference{}; + int pts_wrap_behavior{}; + int update_initial_durations_done{}; + int64_t pts_reorder_error[MAX_REORDER_DELAY + 1]{}; + uint8_t pts_reorder_error_count[MAX_REORDER_DELAY + 1]{}; + int64_t last_dts_for_order_check{}; + uint8_t dts_ordered{}; + uint8_t dts_misordered{}; + int inject_global_side_data{}; // All fields above this line are not part of the public API. // All fields below are part of the public API and ABI again. - char * recommended_encoder_configuration{}; + char *recommended_encoder_configuration{}; AVRational display_aspect_ratio{}; - struct FFFrac * priv_pts{}; - AVStreamInternal * internal{}; + struct FFFrac *priv_pts{}; + AVStreamInternal *internal{}; AVCodecParameters *codecpar{}; }; @@ -136,8 +138,8 @@ struct AVStream_58 { int index{}; int id{}; - AVCodecContext * codec{}; - void * priv_data{}; + AVCodecContext *codec{}; + void *priv_data{}; AVRational time_base{}; int64_t start_time{}; int64_t duration{}; @@ -145,15 +147,15 @@ struct AVStream_58 int disposition{}; AVDiscard discard{}; AVRational sample_aspect_ratio{}; - AVDictionary * metadata{}; + AVDictionary *metadata{}; AVRational avg_frame_rate{}; avcodec::AVPacket_58 attached_pic{}; - AVPacketSideData * side_data{}; + AVPacketSideData *side_data{}; int nb_side_data{}; int event_flags{}; AVRational r_frame_rate{}; - char * recommended_encoder_configuration{}; - AVCodecParameters * codecpar{}; + char *recommended_encoder_configuration{}; + AVCodecParameters *codecpar{}; // All field following this line are not part of the public API and may change/be removed. }; @@ -162,7 +164,7 @@ struct AVStream_59 { int index{}; int id{}; - void * priv_data{}; + void *priv_data{}; AVRational time_base{}; int64_t start_time{}; int64_t duration{}; @@ -170,24 +172,24 @@ struct AVStream_59 int disposition{}; AVDiscard discard{}; AVRational sample_aspect_ratio{}; - AVDictionary * metadata{}; + AVDictionary *metadata{}; AVRational avg_frame_rate{}; avcodec::AVPacket_59 attached_pic{}; - AVPacketSideData * side_data{}; + AVPacketSideData *side_data{}; int nb_side_data{}; int event_flags{}; AVRational r_frame_rate{}; - AVCodecParameters * codecpar{}; + AVCodecParameters *codecpar{}; int pts_wrap_bits{}; }; struct AVStream_60 { - const AVClass * av_class{}; + const AVClass *av_class{}; int index{}; int id{}; - AVCodecParameters * codecpar{}; - void * priv_data{}; + AVCodecParameters *codecpar{}; + void *priv_data{}; AVRational time_base{}; int64_t start_time{}; int64_t duration{}; @@ -195,25 +197,25 @@ struct AVStream_60 int disposition{}; AVDiscard discard{}; AVRational sample_aspect_ratio{}; - AVDictionary * metadata{}; + AVDictionary *metadata{}; AVRational avg_frame_rate{}; avcodec::AVPacket_60 attached_pic{}; - AVPacketSideData * side_data{}; + AVPacketSideData *side_data{}; int nb_side_data{}; int event_flags{}; AVRational r_frame_rate{}; int pts_wrap_bits{}; }; -typedef AVStream_60 AVStream_61; +using AVStream_61 = AVStream_60; struct AVStream_62 { - const AVClass * av_class{}; + const AVClass *av_class{}; int index{}; int id{}; - AVCodecParameters * codecpar{}; - void * priv_data{}; + AVCodecParameters *codecpar{}; + void *priv_data{}; AVRational time_base{}; int64_t start_time{}; int64_t duration{}; @@ -221,7 +223,7 @@ struct AVStream_62 int disposition{}; AVDiscard discard{}; AVRational sample_aspect_ratio{}; - AVDictionary * metadata{}; + AVDictionary *metadata{}; AVRational avg_frame_rate{}; avcodec::AVPacket_62 attached_pic{}; int event_flags{}; diff --git a/src/lib/AVUtil/wrappers/AVDictionaryWrapper.h b/src/lib/AVUtil/wrappers/AVDictionaryWrapper.h index 6b77e94..b291961 100644 --- a/src/lib/AVUtil/wrappers/AVDictionaryWrapper.h +++ b/src/lib/AVUtil/wrappers/AVDictionaryWrapper.h @@ -22,13 +22,13 @@ class AVDictionaryWrapper AVDictionaryWrapper() = delete; AVDictionaryWrapper(AVDictionary *dictionary, std::shared_ptr ffmpegLibraries); - explicit operator bool() const { return this->dictionary != nullptr; } - AVDictionary *getDictionary() const { return this->dictionary; } + explicit operator bool() const { return this->dictionary != nullptr; } + [[nodiscard]] AVDictionary *getDictionary() const { return this->dictionary; } - DictionaryMap toMap() const; + [[nodiscard]] DictionaryMap toMap() const; private: - AVDictionary * dictionary{}; + AVDictionary *dictionary{}; std::shared_ptr ffmpegLibraries{}; }; diff --git a/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.cpp b/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.cpp index 33988ab..1fe6735 100644 --- a/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.cpp +++ b/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.cpp @@ -22,7 +22,7 @@ using libffmpeg::internal::AVFrameSideDataType; } // namespace -AVFrameSideDataWrapper::AVFrameSideDataWrapper(AVFrameSideData * sideData, +AVFrameSideDataWrapper::AVFrameSideDataWrapper(AVFrameSideData *sideData, std::shared_ptr ffmpegLibraries) : sideData(sideData), ffmpegLibraries(ffmpegLibraries) { @@ -35,16 +35,16 @@ std::vector AVFrameSideDataWrapper::getMotionVectors() const if (this->sideData == nullptr) return {}; - AVFrameSideDataType type; + AVFrameSideDataType type{}; CAST_AVUTIL_GET_MEMBER(AVFrameSideData, this->sideData, type, type); if (type != libffmpeg::internal::AV_FRAME_DATA_MOTION_VECTORS) return {}; - uint8_t *data; + uint8_t *data{}; CAST_AVUTIL_GET_MEMBER(AVFrameSideData, this->sideData, data, data); - int size; + int size{}; CAST_AVUTIL_GET_MEMBER(AVFrameSideData, this->sideData, size, size); return parseMotionData(this->ffmpegLibraries->getLibrariesVersion(), data, size); diff --git a/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.h b/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.h index 3fc2680..5bb1e18 100644 --- a/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.h +++ b/src/lib/AVUtil/wrappers/AVFrameSideDataWrapper.h @@ -22,7 +22,7 @@ class AVFrameSideDataWrapper AVFrameSideDataWrapper(libffmpeg::internal::AVFrameSideData *sideData, std::shared_ptr ffmpegLibraries); - std::vector getMotionVectors() const; + [[nodiscard]] std::vector getMotionVectors() const; explicit operator bool() const { return sideData != nullptr; } diff --git a/src/lib/AVUtil/wrappers/AVFrameSideDataWrapperInternal.h b/src/lib/AVUtil/wrappers/AVFrameSideDataWrapperInternal.h index fb99ecd..669acf9 100644 --- a/src/lib/AVUtil/wrappers/AVFrameSideDataWrapperInternal.h +++ b/src/lib/AVUtil/wrappers/AVFrameSideDataWrapperInternal.h @@ -14,26 +14,26 @@ namespace libffmpeg::internal::avutil struct AVFrameSideData_54 { AVFrameSideDataType type; - uint8_t * data; + uint8_t *data; int size; - AVDictionary * metadata; - AVBufferRef * buf; + AVDictionary *metadata; + AVBufferRef *buf; }; -typedef AVFrameSideData_54 AVFrameSideData_55; -typedef AVFrameSideData_54 AVFrameSideData_56; +using AVFrameSideData_55 = AVFrameSideData_54; +using AVFrameSideData_56 = AVFrameSideData_54; struct AVFrameSideData_57 { AVFrameSideDataType type; - uint8_t * data; + uint8_t *data; size_t size; - AVDictionary * metadata; - AVBufferRef * buf; + AVDictionary *metadata; + AVBufferRef *buf; }; -typedef AVFrameSideData_57 AVFrameSideData_58; -typedef AVFrameSideData_57 AVFrameSideData_59; -typedef AVFrameSideData_57 AVFrameSideData_60; +using AVFrameSideData_58 = AVFrameSideData_57; +using AVFrameSideData_59 = AVFrameSideData_57; +using AVFrameSideData_60 = AVFrameSideData_57; } // namespace libffmpeg::internal::avutil diff --git a/src/lib/AVUtil/wrappers/AVFrameWrapper.cpp b/src/lib/AVUtil/wrappers/AVFrameWrapper.cpp index 720dab1..8aa8d3a 100644 --- a/src/lib/AVUtil/wrappers/AVFrameWrapper.cpp +++ b/src/lib/AVUtil/wrappers/AVFrameWrapper.cpp @@ -9,6 +9,7 @@ #include "AVFrameWrapperInternal.h" #include "CastUtilClasses.h" +#include #include #include @@ -58,28 +59,27 @@ AVFrameWrapper::AVFrameWrapper(std::shared_ptr ffmpegLibraries throw std::runtime_error("Error allocating AVFrame"); } -AVFrameWrapper::AVFrameWrapper(AVFrameWrapper &&other) +AVFrameWrapper::AVFrameWrapper(AVFrameWrapper &&other) noexcept + : frame(std::move(other.frame)), ffmpegLibraries(std::move(other.ffmpegLibraries)) { - this->frame = std::move(other.frame); - this->ffmpegLibraries = std::move(other.ffmpegLibraries); } -AVFrameWrapper &AVFrameWrapper::operator=(AVFrameWrapper &&other) +AVFrameWrapper &AVFrameWrapper::operator=(AVFrameWrapper &&other) noexcept { this->frame = std::move(other.frame); this->ffmpegLibraries = std::move(other.ffmpegLibraries); return *this; } -ByteVector AVFrameWrapper::getData(int component) const +ByteVector AVFrameWrapper::getData(const int component) const { - if (component < 0 || component > AV_NUM_DATA_POINTERS) + if (component < 0 || component > internal::AV_NUM_DATA_POINTERS) return {}; - uint8_t *dataPointer; + uint8_t *dataPointer{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), dataPointer, data[component]); - int linesize; + int linesize{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), linesize, linesize[component]); const auto componentSize = @@ -89,22 +89,22 @@ ByteVector AVFrameWrapper::getData(int component) const return copyFrameDataFromRawArray(dataPointer, componentSize, linesize); } -int AVFrameWrapper::getLineSize(int component) const +int AVFrameWrapper::getLineSize(const int component) const { - if (component < 0 || component > AV_NUM_DATA_POINTERS) + if (component < 0 || component > internal::AV_NUM_DATA_POINTERS) return {}; - int linesize; + int linesize{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), linesize, linesize[component]); return linesize; } Size AVFrameWrapper::getSize() const { - int width; + int width{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), width, width); - int height; + int height{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), height, height); return {width, height}; @@ -112,18 +112,17 @@ Size AVFrameWrapper::getSize() const std::optional AVFrameWrapper::getPTS() const { - int64_t pts; + int64_t pts{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), pts, pts); - constexpr int64_t AV_NOPTS_VALUE = 0x8000000000000000; - if (pts == AV_NOPTS_VALUE) + if (pts == internal::AV_NOPTS_VALUE) return {}; return pts; } avutil::PictureType AVFrameWrapper::getPictType() const { - AVPictureType pictureType; + AVPictureType pictureType{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), pictureType, pict_type); return libffmpeg::avutil::toPictureType(pictureType); } @@ -186,7 +185,7 @@ std::optional AVFrameWrapper::getMetadata() const PixelFormatDescriptor AVFrameWrapper::getPixelFormatDescriptor() const { - int format; + int format{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), format, format); return convertAVPixFmtDescriptor(static_cast(format), @@ -195,10 +194,10 @@ PixelFormatDescriptor AVFrameWrapper::getPixelFormatDescriptor() const Rational AVFrameWrapper::getSampleAspectRatio() const { - AVRational sampleAspectRatio; + AVRational sampleAspectRatio{}; CAST_AVUTIL_GET_MEMBER(AVFrame, this->frame.get(), sampleAspectRatio, sample_aspect_ratio); - return Rational({sampleAspectRatio.num, sampleAspectRatio.den}); + return fromAVRational(sampleAspectRatio); } void AVFrameWrapper::AVFrameDeleter::operator()(AVFrame *frame) const noexcept diff --git a/src/lib/AVUtil/wrappers/AVFrameWrapper.h b/src/lib/AVUtil/wrappers/AVFrameWrapper.h index 82f30ad..0dade27 100644 --- a/src/lib/AVUtil/wrappers/AVFrameWrapper.h +++ b/src/lib/AVUtil/wrappers/AVFrameWrapper.h @@ -21,24 +21,25 @@ class AVFrameWrapper { public: AVFrameWrapper() = delete; + ~AVFrameWrapper() = default; AVFrameWrapper(const AVFrameWrapper &) = delete; - AVFrameWrapper(AVFrameWrapper &&frame); + AVFrameWrapper(AVFrameWrapper &&frame) noexcept; AVFrameWrapper(std::shared_ptr ffmpegLibraries); - AVFrameWrapper &operator=(AVFrameWrapper &&); + AVFrameWrapper &operator=(AVFrameWrapper &&) noexcept; AVFrameWrapper &operator=(const AVFrameWrapper &) = delete; - libffmpeg::internal::AVFrame *getFrame() const { return this->frame.get(); } + [[nodiscard]] libffmpeg::internal::AVFrame *getFrame() const { return this->frame.get(); } - ByteVector getData(int component) const; - int getLineSize(int component) const; - Size getSize() const; - std::optional getPTS() const; - avutil::PictureType getPictType() const; - bool isKeyFrame() const; - std::optional getMetadata() const; - PixelFormatDescriptor getPixelFormatDescriptor() const; - Rational getSampleAspectRatio() const; + [[nodiscard]] ByteVector getData(int component) const; + [[nodiscard]] int getLineSize(int component) const; + [[nodiscard]] Size getSize() const; + [[nodiscard]] std::optional getPTS() const; + [[nodiscard]] avutil::PictureType getPictType() const; + [[nodiscard]] bool isKeyFrame() const; + [[nodiscard]] std::optional getMetadata() const; + [[nodiscard]] PixelFormatDescriptor getPixelFormatDescriptor() const; + [[nodiscard]] Rational getSampleAspectRatio() const; explicit operator bool() const { return this->frame != nullptr; } @@ -48,7 +49,7 @@ class AVFrameWrapper public: AVFrameDeleter() = default; AVFrameDeleter(const std::shared_ptr &ffmpegLibraries) - : ffmpegLibraries(ffmpegLibraries){}; + : ffmpegLibraries(ffmpegLibraries) {}; void operator()(libffmpeg::internal::AVFrame *frame) const noexcept; private: diff --git a/src/lib/AVUtil/wrappers/AVFrameWrapperInternal.h b/src/lib/AVUtil/wrappers/AVFrameWrapperInternal.h index a63a8c2..d9b7bd2 100644 --- a/src/lib/AVUtil/wrappers/AVFrameWrapperInternal.h +++ b/src/lib/AVUtil/wrappers/AVFrameWrapperInternal.h @@ -13,15 +13,15 @@ namespace libffmpeg::internal::avutil struct AVFrame_54 { - uint8_t * data[AV_NUM_DATA_POINTERS]; + uint8_t *data[AV_NUM_DATA_POINTERS]; int linesize[AV_NUM_DATA_POINTERS]; - uint8_t ** extended_data; + uint8_t **extended_data; int width, height; int nb_samples; int format; int key_frame; AVPictureType pict_type; - uint8_t * base[AV_NUM_DATA_POINTERS]; + uint8_t *base[AV_NUM_DATA_POINTERS]; AVRational sample_aspect_ratio; int64_t pts; int64_t pkt_pts; @@ -34,9 +34,9 @@ struct AVFrame_54 struct AVFrame_55 { - uint8_t * data[AV_NUM_DATA_POINTERS]; + uint8_t *data[AV_NUM_DATA_POINTERS]; int linesize[AV_NUM_DATA_POINTERS]; - uint8_t ** extended_data; + uint8_t **extended_data; int width, height; int nb_samples; int format; @@ -52,13 +52,13 @@ struct AVFrame_55 // Actually, there is more here, but the variables above are the only we need. }; -typedef AVFrame_55 AVFrame_56; +using AVFrame_56 = AVFrame_55; struct AVFrame_57 { - uint8_t * data[AV_NUM_DATA_POINTERS]; + uint8_t *data[AV_NUM_DATA_POINTERS]; int linesize[AV_NUM_DATA_POINTERS]; - uint8_t ** extended_data; + uint8_t **extended_data; int width, height; int nb_samples; int format; @@ -71,7 +71,7 @@ struct AVFrame_57 int coded_picture_number; // Deprecated int display_picture_number; // Deprecated int quality; - void * opaque; + void *opaque; int repeat_pict; int interlaced_frame; int top_field_first; @@ -79,10 +79,10 @@ struct AVFrame_57 int64_t reordered_opaque; int sample_rate; uint64_t channel_layout; - AVBufferRef * buf[AV_NUM_DATA_POINTERS]; - AVBufferRef ** extended_buf; + AVBufferRef *buf[AV_NUM_DATA_POINTERS]; + AVBufferRef **extended_buf; int nb_extended_buf; - AVFrameSideData ** side_data; + AVFrameSideData **side_data; int nb_side_data; int flags; AVColorRange color_range; @@ -93,18 +93,18 @@ struct AVFrame_57 int64_t best_effort_timestamp; int64_t pkt_pos; int64_t pkt_duration; - AVDictionary * metadata; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; -typedef AVFrame_57 AVFrame_58; +using AVFrame_58 = AVFrame_57; struct AVFrame_59 { - uint8_t * data[AV_NUM_DATA_POINTERS]; + uint8_t *data[AV_NUM_DATA_POINTERS]; int linesize[AV_NUM_DATA_POINTERS]; - uint8_t ** extended_data; + uint8_t **extended_data; int width, height; int nb_samples; int format; @@ -115,17 +115,17 @@ struct AVFrame_59 int64_t pkt_dts; AVRational time_base; int quality; - void * opaque; + void *opaque; int repeat_pict; int interlaced_frame; // Deprecated int top_field_first; // Deprecated int palette_has_changed; // Deprecated int64_t reordered_opaque; int sample_rate; - AVBufferRef * buf[AV_NUM_DATA_POINTERS]; - AVBufferRef ** extended_buf; + AVBufferRef *buf[AV_NUM_DATA_POINTERS]; + AVBufferRef **extended_buf; int nb_extended_buf; - AVFrameSideData ** side_data; + AVFrameSideData **side_data; int nb_side_data; int flags; AVColorRange color_range; @@ -135,16 +135,16 @@ struct AVFrame_59 AVChromaLocation chroma_location; int64_t best_effort_timestamp; int64_t pkt_pos; // Deprecated - AVDictionary * metadata; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; struct AVFrame_60 { - uint8_t * data[AV_NUM_DATA_POINTERS]; + uint8_t *data[AV_NUM_DATA_POINTERS]; int linesize[AV_NUM_DATA_POINTERS]; - uint8_t ** extended_data; + uint8_t **extended_data; int width, height; int nb_samples; int format; @@ -154,13 +154,13 @@ struct AVFrame_60 int64_t pkt_dts; AVRational time_base; int quality; - void * opaque; + void *opaque; int repeat_pict; int sample_rate; - AVBufferRef * buf[AV_NUM_DATA_POINTERS]; - AVBufferRef ** extended_buf; + AVBufferRef *buf[AV_NUM_DATA_POINTERS]; + AVBufferRef **extended_buf; int nb_extended_buf; - AVFrameSideData ** side_data; + AVFrameSideData **side_data; int nb_side_data; int flags; AVColorRange color_range; @@ -169,7 +169,7 @@ struct AVFrame_60 AVColorSpace colorspace; AVChromaLocation chroma_location; int64_t best_effort_timestamp; - AVDictionary * metadata; + AVDictionary *metadata; // Actually, there is more here, but the variables above are the only we need. }; diff --git a/src/lib/AVUtil/wrappers/AVPixFmtDescriptorConversionInternal.h b/src/lib/AVUtil/wrappers/AVPixFmtDescriptorConversionInternal.h index 2e44d5a..ac512bb 100644 --- a/src/lib/AVUtil/wrappers/AVPixFmtDescriptorConversionInternal.h +++ b/src/lib/AVUtil/wrappers/AVPixFmtDescriptorConversionInternal.h @@ -22,13 +22,13 @@ struct AVComponentDescriptor_54 struct AVPixFmtDescriptor_54 { - const char * name; + const char *name; uint8_t nb_components; uint8_t log2_chroma_w; uint8_t log2_chroma_h; uint8_t flags; AVComponentDescriptor_54 comp[4]; - const char * alias; + const char *alias; }; struct AVComponentDescriptor_55 @@ -45,20 +45,20 @@ struct AVComponentDescriptor_55 int offset_plus1; }; -typedef AVComponentDescriptor_55 AVComponentDescriptor_56; +using AVComponentDescriptor_56 = AVComponentDescriptor_55; struct AVPixFmtDescriptor_55 { - const char * name; + const char *name; uint8_t nb_components; uint8_t log2_chroma_w; uint8_t log2_chroma_h; uint64_t flags; AVComponentDescriptor_55 comp[4]; - const char * alias; + const char *alias; }; -typedef AVPixFmtDescriptor_55 AVPixFmtDescriptor_56; +using AVPixFmtDescriptor_56 = AVPixFmtDescriptor_55; struct AVComponentDescriptor_57 { @@ -71,17 +71,17 @@ struct AVComponentDescriptor_57 struct AVPixFmtDescriptor_57 { - const char * name; + const char *name; uint8_t nb_components; uint8_t log2_chroma_w; uint8_t log2_chroma_h; uint64_t flags; AVComponentDescriptor_57 comp[4]; - const char * alias; + const char *alias; }; -typedef AVPixFmtDescriptor_57 AVPixFmtDescriptor_58; -typedef AVPixFmtDescriptor_57 AVPixFmtDescriptor_59; -typedef AVPixFmtDescriptor_57 AVPixFmtDescriptor_60; +using AVPixFmtDescriptor_58 = AVPixFmtDescriptor_57; +using AVPixFmtDescriptor_59 = AVPixFmtDescriptor_57; +using AVPixFmtDescriptor_60 = AVPixFmtDescriptor_57; } // namespace libffmpeg::internal::avutil diff --git a/src/lib/Decoder.cpp b/src/lib/Decoder.cpp index d138277..564a63d 100644 --- a/src/lib/Decoder.cpp +++ b/src/lib/Decoder.cpp @@ -78,7 +78,7 @@ Decoder::SendPacketResult Decoder::sendPacket(const avcodec::AVPacketWrapper &pa return SendPacketResult::NotSentPullFramesFirst; } - ReturnCode returnCode; + ReturnCode returnCode{}; if (this->ffmpegLibraries->getLibrariesVersion().avcodec.major == 56) { // In the old interface there is no pushPacket/pullFrame so we have diff --git a/src/lib/Decoder.h b/src/lib/Decoder.h index 65050ea..4f86500 100644 --- a/src/lib/Decoder.h +++ b/src/lib/Decoder.h @@ -32,7 +32,7 @@ class Decoder EndOfBitstream, Error }; - State getDecoderState() const { return this->decoderState; } + [[nodiscard]] State getDecoderState() const { return this->decoderState; } enum class SendPacketResult { diff --git a/src/lib/Demuxer.cpp b/src/lib/Demuxer.cpp index 026f87f..22058a6 100644 --- a/src/lib/Demuxer.cpp +++ b/src/lib/Demuxer.cpp @@ -39,12 +39,22 @@ Demuxer::Demuxer(std::shared_ptr ffmpegLibraries) this->ffmpegLibraries = ffmpegLibraries; } -Demuxer::Demuxer(Demuxer &&demuxer) +Demuxer::Demuxer(Demuxer &&demuxer) noexcept : ffmpegLibraries(std::move(demuxer.ffmpegLibraries)), formatContext(std::move(demuxer.formatContext)) { } +Demuxer &Demuxer::operator=(Demuxer &&demuxer) noexcept +{ + if (this != &demuxer) + { + this->ffmpegLibraries = std::move(demuxer.ffmpegLibraries); + this->formatContext = std::move(demuxer.formatContext); + } + return *this; +} + bool Demuxer::openFile(const Path &path) { return this->formatContext.openFile(path); diff --git a/src/lib/Demuxer.h b/src/lib/Demuxer.h index 7c5f4f3..e936330 100644 --- a/src/lib/Demuxer.h +++ b/src/lib/Demuxer.h @@ -17,9 +17,12 @@ namespace libffmpeg class Demuxer { public: - Demuxer() = delete; - Demuxer(const Demuxer &) = delete; - Demuxer(Demuxer &&demuxer); + Demuxer() = delete; + ~Demuxer() = default; + Demuxer(const Demuxer &) = delete; + Demuxer &operator=(const Demuxer &) = delete; + Demuxer(Demuxer &&demuxer) noexcept; + Demuxer &operator=(Demuxer &&) noexcept; Demuxer(std::shared_ptr ffmpegLibraries); bool openFile(const Path &path); diff --git a/src/lib/common/EnumMapper.h b/src/lib/common/EnumMapper.h index fd53102..1d16047 100644 --- a/src/lib/common/EnumMapper.h +++ b/src/lib/common/EnumMapper.h @@ -57,7 +57,7 @@ std::optional toUnsigned(const std::string &text) std::string toLower(std::string str) { - std::transform( + std::ranges::transform( str.begin(), str.end(), str.begin(), [](unsigned char c) { return std::tolower(c); }); return str; } @@ -77,9 +77,12 @@ template class EnumMapper }; struct Entry { - Entry(const T &value, const std::string &name) : value(value), name(name) {} - Entry(const T &value, const std::string &name, std::string text) - : value(value), name(name), text(text) + Entry(const T &&value, const std::string &&name) + : value(std::move(value)), name(std::move(name)) + { + } + Entry(const T &&value, const std::string &&name, const std::string &&text) + : value(std::move(value)), name(std::move(name)), text(std::move(text)) { } T value{}; @@ -90,9 +93,10 @@ template class EnumMapper using EntryVector = std::vector; EnumMapper() = default; - EnumMapper(const EntryVector &entryVector) : entryVector(entryVector){}; + EnumMapper(const EntryVector &&entryVector) : entryVector(std::move(entryVector)) {}; - std::optional getValue(const std::string &name, StringType stringType = StringType::Name) const + [[nodiscard]] std::optional getValue(const std::string &name, + StringType stringType = StringType::Name) const { if (stringType == StringType::NameOrIndex) if (auto index = toUnsigned(name)) @@ -108,8 +112,8 @@ template class EnumMapper return {}; } - std::optional getValueCaseInsensitive(const std::string &name, - StringType stringType = StringType::Name) const + [[nodiscard]] std::optional + getValueCaseInsensitive(const std::string &name, StringType stringType = StringType::Name) const { if (stringType == StringType::NameOrIndex) if (auto index = toUnsigned(name)) @@ -126,7 +130,7 @@ template class EnumMapper return {}; } - std::string getName(const T &value) const + [[nodiscard]] std::string getName(const T &value) const { for (const auto &entry : this->entryVector) if (entry.value == value) @@ -135,7 +139,7 @@ template class EnumMapper "The given type T was not registered in the mapper. All possible enums must be mapped."); } - std::string getText(const T &value) const + [[nodiscard]] std::string getText(const T &value) const { for (const auto &entry : this->entryVector) if (entry.value == value) @@ -144,7 +148,7 @@ template class EnumMapper "The given type T was not registered in the mapper. All possible enums must be mapped."); } - size_t indexOf(const T &value) const + [[nodiscard]] size_t indexOf(const T &value) const { for (size_t i = 0; i < this->entryVector.size(); i++) if (this->entryVector.at(i).value == value) @@ -153,14 +157,14 @@ template class EnumMapper "The given type T was not registered in the mapper. All possible enums must be mapped."); } - std::optional at(const size_t index) const + [[nodiscard]] std::optional at(const size_t index) const { if (index >= this->entryVector.size()) return {}; return this->entryVector.at(index).value; } - std::vector getEnums() const + [[nodiscard]] std::vector getEnums() const { std::vector m; for (const auto &entry : this->entryVector) @@ -168,7 +172,7 @@ template class EnumMapper return m; } - std::vector getNames() const + [[nodiscard]] std::vector getNames() const { std::vector l; for (const auto &entry : this->entryVector) @@ -176,7 +180,7 @@ template class EnumMapper return l; } - std::vector getTextEntries() const + [[nodiscard]] std::vector getTextEntries() const { std::vector l; for (const auto &entry : this->entryVector) @@ -184,9 +188,9 @@ template class EnumMapper return l; } - size_t size() const { return this->entryVector.size(); } + [[nodiscard]] size_t size() const { return this->entryVector.size(); } - const EntryVector &entries() const { return this->entryVector; } + [[nodiscard]] const EntryVector &entries() const { return this->entryVector; } private: EntryVector entryVector; diff --git a/src/lib/common/Error.cpp b/src/lib/common/Error.cpp index 269761c..3abe072 100644 --- a/src/lib/common/Error.cpp +++ b/src/lib/common/Error.cpp @@ -60,10 +60,9 @@ ReturnCode toReturnCode(const int returnValue) if (returnValue >= 0) return ReturnCode::Ok; - const auto result = std::find_if(AVERRORToReturnCodeMap.begin(), - AVERRORToReturnCodeMap.end(), - [returnValue](AVErrorToReturnCode errorToReturnCode) - { return errorToReturnCode.first == returnValue; }); + const auto result = std::ranges::find_if(AVERRORToReturnCodeMap, + [returnValue](AVErrorToReturnCode errorToReturnCode) + { return errorToReturnCode.first == returnValue; }); if (result != AVERRORToReturnCodeMap.end()) return result->second; @@ -75,10 +74,9 @@ int toAVError(const ReturnCode returnCode) if (returnCode == ReturnCode::Ok) return 0; - const auto result = std::find_if(AVERRORToReturnCodeMap.begin(), - AVERRORToReturnCodeMap.end(), - [returnCode](AVErrorToReturnCode errorToReturnCode) - { return errorToReturnCode.second == returnCode; }); + const auto result = std::ranges::find_if(AVERRORToReturnCodeMap, + [returnCode](AVErrorToReturnCode errorToReturnCode) + { return errorToReturnCode.second == returnCode; }); if (result != AVERRORToReturnCodeMap.end()) return result->first; diff --git a/src/lib/common/Formatting.cpp b/src/lib/common/Formatting.cpp index 544c534..3906ed5 100644 --- a/src/lib/common/Formatting.cpp +++ b/src/lib/common/Formatting.cpp @@ -18,16 +18,20 @@ std::string to_string(int64_t timestamp, Rational timebase) auto absolutSeconds = static_cast(timestamp) * static_cast(timebase.numerator) / static_cast(timebase.denominator); - const auto hours = static_cast(absolutSeconds / 60 / 60); - absolutSeconds -= hours * 60 * 60; + constexpr auto secondsPerHour = 60 * 60; + constexpr auto secondsPerMinute = 60; - const auto minutes = static_cast(absolutSeconds / 60); - absolutSeconds -= minutes * 60; + const auto hours = static_cast(absolutSeconds / secondsPerHour); + absolutSeconds -= hours * secondsPerHour; + + const auto minutes = static_cast(absolutSeconds / secondsPerMinute); + absolutSeconds -= minutes * secondsPerMinute; const auto seconds = static_cast(absolutSeconds); absolutSeconds -= seconds; - auto milliseconds = static_cast(absolutSeconds * 1000); + constexpr auto millisecondsPerSecond = 1000; + auto milliseconds = static_cast(absolutSeconds * millisecondsPerSecond); std::ostringstream stream; stream << std::setfill('0') << std::setw(2) << hours << ":"; diff --git a/src/lib/common/Functions.h b/src/lib/common/Functions.h index 257dbea..697e9cb 100644 --- a/src/lib/common/Functions.h +++ b/src/lib/common/Functions.h @@ -6,7 +6,7 @@ #pragma once -#include +#include #include #include @@ -28,4 +28,9 @@ inline ByteVector copyDataFromRawArray(const uint8_t *inputData, const int input return data; } +inline Rational fromAVRational(const internal::AVRational &avRational) +{ + return Rational({.numerator = avRational.num, .denominator = avRational.den}); +} + } // namespace libffmpeg diff --git a/src/lib/common/InternalTypes.h b/src/lib/common/InternalTypes.h index 3853fa5..d362273 100644 --- a/src/lib/common/InternalTypes.h +++ b/src/lib/common/InternalTypes.h @@ -37,7 +37,8 @@ class AVStreamGroup; struct AVCodecContext; -#define AV_NUM_DATA_POINTERS 8 +constexpr int AV_NUM_DATA_POINTERS = 8; +constexpr int64_t AV_NOPTS_VALUE = 0x8000000000000000; /* These enums are only used internally. So far, these enums did not change between the FFmpeg * versions. If they ever do change, we will have to add a wrapper around them. diff --git a/src/lib/common/Version.h b/src/lib/common/Version.h index 8c40b99..8b3a824 100644 --- a/src/lib/common/Version.h +++ b/src/lib/common/Version.h @@ -22,8 +22,8 @@ struct Version bool operator!=(const Version &other) const; - std::string toString() const; - std::ostream &operator<<(std::ostream &stream) const; + [[nodiscard]] std::string toString() const; + [[nodiscard]] std::ostream &operator<<(std::ostream &stream) const; static Version fromFFmpegVersion(const unsigned ffmpegVersion); @@ -68,40 +68,41 @@ using VersionSwresample = Version; // These FFmpeg versions are supported. The numbers indicate the major versions. // The versions are sorted from newest to oldest, so that we try to open the newest ones first. -constexpr auto SupportedFFmpegVersions = {LibraryVersions({FFmpegVersion::FFmpeg_8x, - VersionAVFormat(62), - VersionAVCodec(62), - VersionAVUtil(60), - VersionSwresample(6)}), - LibraryVersions({FFmpegVersion::FFmpeg_7x, - VersionAVFormat(61), - VersionAVCodec(61), - VersionAVUtil(59), - VersionSwresample(5)}), - LibraryVersions({FFmpegVersion::FFmpeg_6x, - VersionAVFormat(60), - VersionAVCodec(60), - VersionAVUtil(58), - VersionSwresample(4)}), - LibraryVersions({FFmpegVersion::FFmpeg_5x, - VersionAVFormat(59), - VersionAVCodec(59), - VersionAVUtil(57), - VersionSwresample(4)}), - LibraryVersions({FFmpegVersion::FFmpeg_4x, - VersionAVFormat(58), - VersionAVCodec(58), - VersionAVUtil(56), - VersionSwresample(3)}), - LibraryVersions({FFmpegVersion::FFmpeg_3x, - VersionAVFormat(57), - VersionAVCodec(57), - VersionAVUtil(55), - VersionSwresample(2)}), - LibraryVersions({FFmpegVersion::FFmpeg_2x, - VersionAVFormat(56), - VersionAVCodec(56), - VersionAVUtil(54), - VersionSwresample(1)})}; +constexpr auto SupportedFFmpegVersions = { + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_8x, + .avformat = VersionAVFormat(62), + .avcodec = VersionAVCodec(62), + .avutil = VersionAVUtil(60), + .swresample = VersionSwresample(6)}), + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_7x, + .avformat = VersionAVFormat(61), + .avcodec = VersionAVCodec(61), + .avutil = VersionAVUtil(59), + .swresample = VersionSwresample(5)}), + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_6x, + .avformat = VersionAVFormat(60), + .avcodec = VersionAVCodec(60), + .avutil = VersionAVUtil(58), + .swresample = VersionSwresample(4)}), + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_5x, + .avformat = VersionAVFormat(59), + .avcodec = VersionAVCodec(59), + .avutil = VersionAVUtil(57), + .swresample = VersionSwresample(4)}), + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_4x, + .avformat = VersionAVFormat(58), + .avcodec = VersionAVCodec(58), + .avutil = VersionAVUtil(56), + .swresample = VersionSwresample(3)}), + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_3x, + .avformat = VersionAVFormat(57), + .avcodec = VersionAVCodec(57), + .avutil = VersionAVUtil(55), + .swresample = VersionSwresample(2)}), + LibraryVersions({.ffmpegVersion = FFmpegVersion::FFmpeg_2x, + .avformat = VersionAVFormat(56), + .avcodec = VersionAVCodec(56), + .avutil = VersionAVUtil(54), + .swresample = VersionSwresample(1)})}; } // namespace libffmpeg diff --git a/src/lib/libHandling/FFmpegLibraries.cpp b/src/lib/libHandling/FFmpegLibraries.cpp index fc6dfd5..39422b1 100644 --- a/src/lib/libHandling/FFmpegLibraries.cpp +++ b/src/lib/libHandling/FFmpegLibraries.cpp @@ -36,9 +36,9 @@ std::vector getPossibleLibraryNames(std::string libraryName, int ve return {}; } -bool checkLibraryVersion(const std::string & libName, +bool checkLibraryVersion(const std::string &libName, unsigned ffmpegVersionOfLoadedLibrary, - const Version & expectedVersion, + const Version &expectedVersion, const LoggingFunction &log) { const auto loadedVersion = Version::fromFFmpegVersion(ffmpegVersionOfLoadedLibrary); @@ -68,13 +68,16 @@ Path getAbsolutePath(const Path &path) FFmpegLibraries::FFmpegLibraries() { - std::lock_guard lock(this->loggingMutex); + std::scoped_lock lock(this->loggingMutex); this->loggingFunction = [](const LogLevel, const std::string &) {}; } FFmpegLibraries::~FFmpegLibraries() { - this->disconnectAVLoggingCallback(); + std::scoped_lock lock(this->loggingMutex); + + if (this->loggingFunctionIndex) + unsetStaticLoggingCallback(this->avutil, this->loggingFunctionIndex.value()); } bool FFmpegLibraries::tryLoadFFmpegLibrariesInPath(const Path &path) @@ -193,9 +196,9 @@ bool FFmpegLibraries::tryLoadBindAndCheckAVFormat(const Path &directory, const V } bool FFmpegLibraries::tryLoadLibraryInPath(SharedLibraryLoader &lib, - const Path & directory, - const std::string & libName, - const Version & version) + const Path &directory, + const std::string &libName, + const Version &version) { this->log(LogLevel::Info, "Trying to load library " + libName + " in path " + directory.string()); @@ -249,12 +252,13 @@ std::vector FFmpegLibraries::getLibrariesInfo() const std::vector infoPerLIbrary; auto addLibraryInfo = - [&infoPerLIbrary](const char *name, const Path &path, const unsigned ffmpegVersion) { - const auto libraryVersion = Version::fromFFmpegVersion(ffmpegVersion); - const auto version = libraryVersion.toString(); + [&infoPerLIbrary](const char *name, const Path &path, const unsigned ffmpegVersion) + { + const auto libraryVersion = Version::fromFFmpegVersion(ffmpegVersion); + const auto version = libraryVersion.toString(); - infoPerLIbrary.push_back(LibraryInfo({name, path, version})); - }; + infoPerLIbrary.push_back(LibraryInfo({.name = name, .path = path, .version = version})); + }; addLibraryInfo("AVFormat", this->libAvformat.getLibraryPath(), this->avformat.avformat_version()); addLibraryInfo("AVCodec", this->libAvcodec.getLibraryPath(), this->avcodec.avcodec_version()); @@ -269,9 +273,10 @@ void FFmpegLibraries::setLoggingFunction(const LoggingFunction function, const LogLevel minimumLogLevel) { { - std::lock_guard lock(this->loggingMutex); - this->loggingFunction = [this, function, minimumLogLevel](const LogLevel logLevel, - const std::string &message) { + std::scoped_lock lock(this->loggingMutex); + this->loggingFunction = + [this, function, minimumLogLevel](const LogLevel logLevel, const std::string &message) + { if (function && logLevel >= minimumLogLevel) function(logLevel, message); }; @@ -282,7 +287,7 @@ void FFmpegLibraries::setLoggingFunction(const LoggingFunction function, void FFmpegLibraries::log(const LogLevel logLevel, const std::string &message) const { - std::lock_guard lock(this->loggingMutex); + std::scoped_lock lock(this->loggingMutex); this->loggingFunction(logLevel, message); } @@ -298,18 +303,9 @@ void FFmpegLibraries::getLibraryVersionsFromLoadedLibraries() void FFmpegLibraries::connectAVLoggingCallback() { this->log(LogLevel::Info, "Setting up av logging callback"); - std::lock_guard lock(this->loggingMutex); + std::scoped_lock lock(this->loggingMutex); this->loggingFunctionIndex = setStaticLoggingCallback(this->avutil, this->loggingFunction); } -void FFmpegLibraries::disconnectAVLoggingCallback() -{ - this->log(LogLevel::Info, "Disconnectiong av logging callback"); - std::lock_guard lock(this->loggingMutex); - - if (this->loggingFunctionIndex) - unsetStaticLoggingCallback(this->avutil, this->loggingFunctionIndex.value()); -} - } // namespace libffmpeg diff --git a/src/lib/libHandling/FFmpegLibraries.h b/src/lib/libHandling/FFmpegLibraries.h index 0c18377..c7f2c22 100644 --- a/src/lib/libHandling/FFmpegLibraries.h +++ b/src/lib/libHandling/FFmpegLibraries.h @@ -20,7 +20,11 @@ class FFmpegLibraries : public IFFmpegLibraries { public: FFmpegLibraries(); - ~FFmpegLibraries(); + ~FFmpegLibraries() override; + FFmpegLibraries(const FFmpegLibraries &) = delete; + FFmpegLibraries &operator=(const FFmpegLibraries &) = delete; + FFmpegLibraries(FFmpegLibraries &&) = delete; + FFmpegLibraries &operator=(FFmpegLibraries &&) = delete; std::vector getLibrariesInfo() const override; LibraryVersions getLibrariesVersion() const override { return this->libraryVersions; } @@ -33,7 +37,7 @@ class FFmpegLibraries : public IFFmpegLibraries [[nodiscard]] bool tryLoadFFmpegLibrariesInPath(const Path &path); [[nodiscard]] bool - tryLoadLibrariesBindFunctionsAndCheckVersions(const Path & directory, + tryLoadLibrariesBindFunctionsAndCheckVersions(const Path &directory, const LibraryVersions &libraryVersions); [[nodiscard]] bool tryLoadBindAndCheckAVUtil(const Path &directory, const Version version); [[nodiscard]] bool tryLoadBindAndCheckSWResample(const Path &directory, const Version version); @@ -41,9 +45,9 @@ class FFmpegLibraries : public IFFmpegLibraries [[nodiscard]] bool tryLoadBindAndCheckAVFormat(const Path &directory, const Version version); [[nodiscard]] bool tryLoadLibraryInPath(SharedLibraryLoader &lib, - const Path & directory, - const std::string & libName, - const Version & version); + const Path &directory, + const std::string &libName, + const Version &version); void unloadAllLibraries(); @@ -56,7 +60,6 @@ class FFmpegLibraries : public IFFmpegLibraries void getLibraryVersionsFromLoadedLibraries(); void connectAVLoggingCallback(); - void disconnectAVLoggingCallback(); mutable std::mutex loggingMutex; LoggingFunction loggingFunction; diff --git a/src/lib/libHandling/FFmpegLibrariesBuilder.cpp b/src/lib/libHandling/FFmpegLibrariesBuilder.cpp index 3715f49..94e8569 100644 --- a/src/lib/libHandling/FFmpegLibrariesBuilder.cpp +++ b/src/lib/libHandling/FFmpegLibrariesBuilder.cpp @@ -40,19 +40,19 @@ LibrariesLoadingResult FFmpegLibrariesBuilder::tryLoadingOfLibraries() if (paths.empty()) { lib->log(LogLevel::Info, "No search paths specified. We will only try the default empty path."); - paths.push_back(""); + paths.emplace_back(""); } #if (defined(__APPLE__) && defined(__arm64__)) // On apple silicone, the libraries that were installed through homebrew are not automatically // in the library search path. We will search the homebrew library path manually. // Issue: https://github.com/Homebrew/brew/issues/13481 - paths.push_back("/opt/homebrew/lib"); + paths.emplace_back("/opt/homebrew/lib"); #elif (defined(__APPLE__) && !defined(__arm64__)) // On macos on Intel, it can also happen that the default directory that homebrew libraries // are installed in is not in the search path. // https://apple.stackexchange.com/questions/40704/homebrew-installed-libraries-how-do-i-use-them - paths.push_back("/usr/local/lib"); + paths.emplace_back("/usr/local/lib"); #endif for (const auto &path : paths) diff --git a/src/lib/libHandling/IFFmpegLibraries.h b/src/lib/libHandling/IFFmpegLibraries.h index 4c5266c..9b78bd7 100644 --- a/src/lib/libHandling/IFFmpegLibraries.h +++ b/src/lib/libHandling/IFFmpegLibraries.h @@ -30,10 +30,11 @@ struct LibraryInfo class IFFmpegLibraries { public: - virtual ~IFFmpegLibraries(){}; + IFFmpegLibraries() = default; + virtual ~IFFmpegLibraries() = default; - virtual std::vector getLibrariesInfo() const = 0; - virtual LibraryVersions getLibrariesVersion() const = 0; + [[nodiscard]] virtual std::vector getLibrariesInfo() const = 0; + [[nodiscard]] virtual LibraryVersions getLibrariesVersion() const = 0; virtual void log(const LogLevel logLevel, const std::string &message) const = 0; diff --git a/src/lib/libHandling/SharedLibraryLoader.h b/src/lib/libHandling/SharedLibraryLoader.h index 3392f09..9c4c7d4 100644 --- a/src/lib/libHandling/SharedLibraryLoader.h +++ b/src/lib/libHandling/SharedLibraryLoader.h @@ -37,10 +37,10 @@ class SharedLibraryLoader bool load(const std::string &libraryName); bool load(const Path &absolutePathToLibraryFile); - auto getLibraryPath() const { return this->libraryPath; } + [[nodiscard]] auto getLibraryPath() const { return this->libraryPath; } - bool isLoaded() const { return this->libHandle != nullptr; } - operator bool() const { return this->isLoaded(); } + [[nodiscard]] bool isLoaded() const { return this->libHandle != nullptr; } + operator bool() const { return this->isLoaded(); } template void tryResolveFunction(std::function &function, const std::string_view functionName) const diff --git a/src/lib/libHandling/StaticCallbacks.cpp b/src/lib/libHandling/StaticCallbacks.cpp index bcca029..6083857 100644 --- a/src/lib/libHandling/StaticCallbacks.cpp +++ b/src/lib/libHandling/StaticCallbacks.cpp @@ -30,7 +30,7 @@ void logToLoggingFunction( std::string message; va_list vargs_copy; va_copy(vargs_copy, vargs); - const auto len = vsnprintf(0, 0, fmt, vargs_copy); + const auto len = vsnprintf(nullptr, 0, fmt, vargs_copy); message.resize(len); vsnprintf(&message[0], len + 1, fmt, vargs); diff --git a/test/integration/DemuxingTest.cpp b/test/integration/DemuxingTest.cpp index 27120da..da1ecaf 100644 --- a/test/integration/DemuxingTest.cpp +++ b/test/integration/DemuxingTest.cpp @@ -173,7 +173,6 @@ TEST(Demuxing, OpenTestFileAndDemuxPackets_ShouldReturnCorrectPackets) auto libsAndLogs = LibrariesWithLogging(); auto demuxer = libsAndLogs.openTestFileInDemuxer(); - const auto formatContext = demuxer.getFormatContext(); constexpr std::array expectedDataSizesVideo = {3827, 499, 90, 46, 29, 439, 82, 36, 40, 461, 56, 36, 25, 419, 54, 29, 23, 339, @@ -215,7 +214,6 @@ TEST(Demuxing, OpenTestFileAndDemuxPackets_ShouldLogDemuxingEventsCorrectly) auto libsAndLogs = LibrariesWithLogging(); auto demuxer = libsAndLogs.openTestFileInDemuxer(); - const auto formatContext = demuxer.getFormatContext(); while (auto packet = demuxer.getNextPacket()) { diff --git a/test/integration/LibrariesWithLogging.h b/test/integration/LibrariesWithLogging.h index 9b60d4c..a6093fb 100644 --- a/test/integration/LibrariesWithLogging.h +++ b/test/integration/LibrariesWithLogging.h @@ -4,9 +4,9 @@ * For a copy, see . */ -#include #include #include +#include #include @@ -53,12 +53,11 @@ class LibrariesWithLogging bool containsLogEntry(const LogEntry &logEntry) { - return std::find(this->logEntries.begin(), this->logEntries.end(), logEntry) != - this->logEntries.end(); + return std::ranges::find(this->logEntries, logEntry) != this->logEntries.end(); } std::vector logEntries{}; std::shared_ptr libraries; }; -} +} // namespace libffmpeg::test::integration diff --git a/test/unit/libHandling/FFmpegLibrariesMoc.h b/test/unit/libHandling/FFmpegLibrariesMoc.h index f3ff36c..4497707 100644 --- a/test/unit/libHandling/FFmpegLibrariesMoc.h +++ b/test/unit/libHandling/FFmpegLibrariesMoc.h @@ -23,7 +23,11 @@ class FFmpegLibrariesMock : public IFFmpegLibraries { public: FFmpegLibrariesMock(); - ~FFmpegLibrariesMock(); + ~FFmpegLibrariesMock() override; + FFmpegLibrariesMock(const FFmpegLibrariesMock &) = delete; + FFmpegLibrariesMock &operator=(const FFmpegLibrariesMock &) = delete; + FFmpegLibrariesMock(FFmpegLibrariesMock &&) = delete; + FFmpegLibrariesMock &operator=(FFmpegLibrariesMock &&) = delete; MOCK_METHOD(std::vector, getLibrariesInfo, (), (const, override)); MOCK_METHOD(LibraryVersions, getLibrariesVersion, (), (const, override)); @@ -69,11 +73,11 @@ class FFmpegLibrariesMock : public IFFmpegLibraries AVDummy avDummy; // AVUtil - internal::AVFrame * av_frame_alloc_mock(); + internal::AVFrame *av_frame_alloc_mock(); void av_frame_free_mock(internal::AVFrame **frame); const internal::AVPixFmtDescriptor *av_pix_fmt_desc_get_mock(internal::AVPixelFormat pix_fmt); - internal::AVDictionaryEntry * av_dict_get_moc(internal::AVDictionary * dictionary, - const char * key, + internal::AVDictionaryEntry *av_dict_get_moc(internal::AVDictionary *dictionary, + const char *key, const internal::AVDictionaryEntry *prev, int flags); @@ -85,8 +89,8 @@ class FFmpegLibrariesMock : public IFFmpegLibraries int avcodec_receive_frame_mock(internal::AVCodecContext *context, internal::AVFrame *frame); int avcodec_send_packet_mock(internal::AVCodecContext *context, const internal::AVPacket *packet); const internal::AVCodecDescriptor *avcodec_descriptor_get_mock(internal::AVCodecID codecID); - internal::AVCodec * avcodec_find_decoder_mock(internal::AVCodecID codecID); - internal::AVCodecContext * avcodec_alloc_context3_mock(const internal::AVCodec *codec); + internal::AVCodec *avcodec_find_decoder_mock(internal::AVCodecID codecID); + internal::AVCodecContext *avcodec_alloc_context3_mock(const internal::AVCodec *codec); void avcodec_free_context_mock(internal::AVCodecContext **codecContext); int avcodec_parameters_to_context_mock(internal::AVCodecContext *, const internal::AVCodecParameters *); diff --git a/test/unit/wrappers/AVCodec/AVPacketWrapperTest.cpp b/test/unit/wrappers/AVCodec/AVPacketWrapperTest.cpp index cf0ed0e..eb3438c 100644 --- a/test/unit/wrappers/AVCodec/AVPacketWrapperTest.cpp +++ b/test/unit/wrappers/AVCodec/AVPacketWrapperTest.cpp @@ -51,9 +51,8 @@ class FFmpegLibrariesMockWithPacketAllocation : public FFmpegLibrariesMock { this->avcodec.av_packet_alloc = [this]() { return this->allocatePacket(); }; this->avcodec.av_packet_free = [this](AVPacket **packet) { this->freePacket(packet); }; - this->avcodec.av_new_packet = [this](AVPacket *packet, int dataSize) { - return this->newPacket(packet, dataSize); - }; + this->avcodec.av_new_packet = [this](AVPacket *packet, int dataSize) + { return this->newPacket(packet, dataSize); }; if constexpr (std::is_same_v) { this->avcodec.av_init_packet = [this](AVPacket *packet) { this->initPacket(packet); }; @@ -112,7 +111,7 @@ class FFmpegLibrariesMockWithPacketAllocation : public FFmpegLibrariesMock // AVCodec major version 56 only void initPacket(AVPacket *packet) { - auto castPacket = reinterpret_cast(packet); + auto castPacket = reinterpret_cast(packet); castPacket->stream_index = TEST_STREAM_INDEX; castPacket->pts = TEST_PTS; castPacket->dts = TEST_DTS; @@ -212,15 +211,14 @@ template void runTimestampTest() AVPacketWrapper packet(ffmpegLibraries); checkPacketForExpectedDefaultValues(packet); - constexpr int64_t PTS_TEST = 890; - constexpr int64_t AV_NOPTS_VALUE = 0x8000000000000000; - constexpr int64_t DTS_TEST = 8200; + constexpr int64_t PTS_TEST = 890; + constexpr int64_t DTS_TEST = 8200; packet.setTimestamps(DTS_TEST, PTS_TEST); EXPECT_EQ(packet.getPTS(), PTS_TEST); EXPECT_EQ(packet.getDTS(), DTS_TEST); - packet.setTimestamps(DTS_TEST, AV_NOPTS_VALUE); + packet.setTimestamps(DTS_TEST, internal::AV_NOPTS_VALUE); EXPECT_FALSE(packet.getPTS()); } diff --git a/test/unit/wrappers/AVFormat/AVFormatContextWrapperTest.cpp b/test/unit/wrappers/AVFormat/AVFormatContextWrapperTest.cpp index 0f0ca43..0a43361 100644 --- a/test/unit/wrappers/AVFormat/AVFormatContextWrapperTest.cpp +++ b/test/unit/wrappers/AVFormat/AVFormatContextWrapperTest.cpp @@ -49,87 +49,91 @@ template void runAVFormatContextWrapperTest() int formatOpenInputCount = 0; ffmpegLibraries->avformat.avformat_open_input = - [&](AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options) { - EXPECT_EQ(std::string(url), "dummyFilePath"); + [&](AVFormatContext **ps, const char *url, AVInputFormat *fmt, AVDictionary **options) + { + EXPECT_EQ(std::string(url), "dummyFilePath"); - auto format = new AVFormatContextType; - format->nb_streams = 2; - format->streams = new AVStream *[format->nb_streams]; - *ps = reinterpret_cast(format); + auto format = new AVFormatContextType; + format->nb_streams = 2; + format->streams = new AVStream *[format->nb_streams]; + *ps = reinterpret_cast(format); - auto inputFormat = new AVInputFormatType; - inputFormat->name = TEST_INPUT_FORMAT_NAME; - format->iformat = reinterpret_cast(inputFormat); + auto inputFormat = new AVInputFormatType; + inputFormat->name = TEST_INPUT_FORMAT_NAME; + format->iformat = reinterpret_cast(inputFormat); - format->start_time = TEST_START_TIME; - format->duration = TEST_DURATION; - format->metadata = reinterpret_cast(TEST_METADATA_ENTRIES.data()); + format->start_time = TEST_START_TIME; + format->duration = TEST_DURATION; + format->metadata = reinterpret_cast(TEST_METADATA_ENTRIES.data()); - formatOpenInputCount++; + formatOpenInputCount++; - return toAVError(ReturnCode::Ok); - }; + return toAVError(ReturnCode::Ok); + }; int formatCloseInputCount = 0; int streamsFreed = 0; ffmpegLibraries->avformat.avformat_close_input = - [&formatCloseInputCount, &streamsFreed](AVFormatContext **formatContext) { - auto castFormatContext = reinterpret_cast *>(*formatContext); + [&formatCloseInputCount, &streamsFreed](AVFormatContext **formatContext) + { + auto castFormatContext = reinterpret_cast *>(*formatContext); - if (castFormatContext->streams) + if (castFormatContext->streams) + { + for (int i = 0; i < static_cast(castFormatContext->nb_streams); ++i) + { + auto castStream = reinterpret_cast *>(castFormatContext->streams[i]); + if (castStream) { - for (int i = 0; i < static_cast(castFormatContext->nb_streams); ++i) - { - auto castStream = reinterpret_cast *>(castFormatContext->streams[i]); - if (castStream) - { - ++streamsFreed; - delete castStream; - } - } - - delete[] castFormatContext->streams; - castFormatContext->streams = nullptr; + ++streamsFreed; + delete castStream; } + } - if (castFormatContext->iformat) - { - auto castInputFormatType = - reinterpret_cast *>(castFormatContext->iformat); - delete castInputFormatType; - castFormatContext->iformat = nullptr; - } + delete[] castFormatContext->streams; + castFormatContext->streams = nullptr; + } + + if (castFormatContext->iformat) + { + auto castInputFormatType = + reinterpret_cast *>(castFormatContext->iformat); + delete castInputFormatType; + castFormatContext->iformat = nullptr; + } - delete castFormatContext; - formatContext = nullptr; + delete castFormatContext; + formatContext = nullptr; - formatCloseInputCount++; - }; + formatCloseInputCount++; + }; int findStreamInfoCount = 0; int streamsAllocated = 0; ffmpegLibraries->avformat.avformat_find_stream_info = [&findStreamInfoCount, &streamsAllocated](AVFormatContext *formatContext, - AVDictionary ** options) { - auto videoStream = new AVStreamType; - videoStream->index = 0; + AVDictionary **options) + { + auto videoStream = new AVStreamType; + videoStream->index = 0; - auto audioStream = new AVStreamType; - audioStream->index = 1; + auto audioStream = new AVStreamType; + audioStream->index = 1; - auto concreteFormatContext = reinterpret_cast *>(formatContext); - concreteFormatContext->streams[0] = reinterpret_cast(videoStream); - concreteFormatContext->streams[1] = reinterpret_cast(audioStream); - concreteFormatContext->nb_streams = 2; + auto concreteFormatContext = reinterpret_cast *>(formatContext); + concreteFormatContext->streams[0] = reinterpret_cast(videoStream); + concreteFormatContext->streams[1] = reinterpret_cast(audioStream); + concreteFormatContext->nb_streams = 2; - streamsAllocated += 2; - findStreamInfoCount++; + streamsAllocated += 2; + findStreamInfoCount++; - return toAVError(ReturnCode::Ok); - }; + return toAVError(ReturnCode::Ok); + }; int readFrameCount = 0; - ffmpegLibraries->avformat.av_read_frame = [&readFrameCount](AVFormatContext *s, AVPacket *pkt) { + ffmpegLibraries->avformat.av_read_frame = [&readFrameCount](AVFormatContext *s, AVPacket *pkt) + { readFrameCount++; if (readFrameCount > TEST_EXPECTED_NR_PACKETS) @@ -141,14 +145,16 @@ template void runAVFormatContextWrapperTest() return toAVError(ReturnCode::Ok); }; - ffmpegLibraries->avcodec.av_packet_alloc = []() { + ffmpegLibraries->avcodec.av_packet_alloc = []() + { auto packet = new AVPacketType; packet->pts = 0; packet->dts = 0; return reinterpret_cast(packet); }; - ffmpegLibraries->avcodec.av_packet_free = [](AVPacket **pkt) { + ffmpegLibraries->avcodec.av_packet_free = [](AVPacket **pkt) + { auto actualPacket = reinterpret_cast *>(*pkt); delete actualPacket; pkt = nullptr; @@ -174,8 +180,8 @@ template void runAVFormatContextWrapperTest() constexpr auto INVALID_STREAM_INDEX_NEGATIVE = -8; constexpr auto INVALID_STREAM_INDEX_TOO_LARGE = 8; - EXPECT_THROW(format.getStream(INVALID_STREAM_INDEX_NEGATIVE), std::runtime_error); - EXPECT_THROW(format.getStream(INVALID_STREAM_INDEX_TOO_LARGE), std::runtime_error); + EXPECT_THROW((void)format.getStream(INVALID_STREAM_INDEX_NEGATIVE), std::runtime_error); + EXPECT_THROW((void)format.getStream(INVALID_STREAM_INDEX_TOO_LARGE), std::runtime_error); int streamCounter = 0; for (const auto &stream : format.getStreams()) diff --git a/test/unit/wrappers/AVUtil/AVFrameSideDataWrapperTest.cpp b/test/unit/wrappers/AVUtil/AVFrameSideDataWrapperTest.cpp index ecf032a..2008f99 100644 --- a/test/unit/wrappers/AVUtil/AVFrameSideDataWrapperTest.cpp +++ b/test/unit/wrappers/AVUtil/AVFrameSideDataWrapperTest.cpp @@ -20,11 +20,11 @@ namespace libffmpeg::avutil namespace { +using internal::avutil::AVMotionVector_54; +using internal::avutil::AVMotionVector_55_56_57_58_59_60; using libffmpeg::internal::AV_FRAME_DATA_DOWNMIX_INFO; using libffmpeg::internal::AV_FRAME_DATA_MOTION_VECTORS; using libffmpeg::internal::AVFrameSideData; -using internal::avutil::AVMotionVector_54; -using internal::avutil::AVMotionVector_55_56_57_58_59_60; using ::testing::Return; @@ -33,7 +33,7 @@ template std::array createDummy static_assert(std::is_same_v || std::is_same_v); - std::array array; + std::array array{}; for (int i = 0; i < 5; ++i) { array[i].source = i; diff --git a/test/unit/wrappers/TestHelper.h b/test/unit/wrappers/TestHelper.h index 5c810ac..20ed666 100644 --- a/test/unit/wrappers/TestHelper.h +++ b/test/unit/wrappers/TestHelper.h @@ -20,7 +20,7 @@ static std::string getNameWithFFmpegVersion(const testing::TestParamInfo Date: Thu, 19 Feb 2026 22:34:56 +0100 Subject: [PATCH 3/4] Missing header for windows --- src/app/FilePacketComparer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/app/FilePacketComparer.cpp b/src/app/FilePacketComparer.cpp index 47c3f35..b130dca 100644 --- a/src/app/FilePacketComparer.cpp +++ b/src/app/FilePacketComparer.cpp @@ -10,6 +10,7 @@ #include "Formatting.h" +#include #include #include #include @@ -80,7 +81,7 @@ std::optional parseFileNameAndStreamIndex(const std::string &variab { file.streamIndex = std::stoi(variable.substr(columnPos + 1)); } - catch (const std::exception &e) + catch (const std::exception &) { return {}; } From c3fa95b04f219362545309b6d0ca870721f8b3ef Mon Sep 17 00:00:00 2001 From: Christian Feldmann Date: Thu, 19 Feb 2026 22:52:07 +0100 Subject: [PATCH 4/4] Re-add log line. --- src/lib/libHandling/FFmpegLibraries.cpp | 1 + test/integration/LibrariesLoadingTest.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/libHandling/FFmpegLibraries.cpp b/src/lib/libHandling/FFmpegLibraries.cpp index 39422b1..0ade409 100644 --- a/src/lib/libHandling/FFmpegLibraries.cpp +++ b/src/lib/libHandling/FFmpegLibraries.cpp @@ -74,6 +74,7 @@ FFmpegLibraries::FFmpegLibraries() FFmpegLibraries::~FFmpegLibraries() { + this->log(LogLevel::Info, "Disconnecting av logging callback"); std::scoped_lock lock(this->loggingMutex); if (this->loggingFunctionIndex) diff --git a/test/integration/LibrariesLoadingTest.cpp b/test/integration/LibrariesLoadingTest.cpp index bf0790f..bb242d6 100644 --- a/test/integration/LibrariesLoadingTest.cpp +++ b/test/integration/LibrariesLoadingTest.cpp @@ -38,11 +38,11 @@ TEST(LibrariesLoading, LoadLibrariesAndCheckLoggingCallback) "Loading of ffmpeg libraries successfully finished. FFmpeg is ready to be used."})); EXPECT_FALSE( - libsAndLogs.containsLogEntry({LogLevel::Info, "Disconnectiong av logging callback"})); + libsAndLogs.containsLogEntry({LogLevel::Info, "Disconnecting av logging callback"})); libsAndLogs.libraries.reset(); - EXPECT_TRUE(libsAndLogs.containsLogEntry({LogLevel::Info, "Disconnectiong av logging callback"})); + EXPECT_TRUE(libsAndLogs.containsLogEntry({LogLevel::Info, "Disconnecting av logging callback"})); } } // namespace libffmpeg::test::integration