Skip to content

Commit 5da0d76

Browse files
Merge pull request #17 from ChristianFeldmann/feature/clang-tidy
Feature/clang tidy
2 parents 2cfd343 + c3fa95b commit 5da0d76

59 files changed

Lines changed: 1047 additions & 929 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-tidy

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
Checks: '-clang-diagnostic-*,clang-analyzer-*,cppcoreguidelines-*,modernize-*,-modernize-use-trailing-return-type'
3+
WarningsAsErrors: true
4+
HeaderFilterRegex: '.*'
5+
FormatStyle: google
6+
CheckOptions:
7+
- key: cert-dcl16-c.NewSuffixes
8+
value: 'L;LL;LU;LLU'
9+
- key: cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField
10+
value: '0'
11+
- key: cppcoreguidelines-explicit-virtual-functions.IgnoreDestructors
12+
value: '1'
13+
- key: cppcoreguidelines-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
14+
value: '1'
15+
- key: google-readability-braces-around-statements.ShortStatementLines
16+
value: '1'
17+
- key: google-readability-function-size.StatementThreshold
18+
value: '800'
19+
- key: google-readability-namespace-comments.ShortNamespaceLines
20+
value: '10'
21+
- key: google-readability-namespace-comments.SpacesBeforeComments
22+
value: '2'
23+
- key: modernize-loop-convert.MaxCopySize
24+
value: '16'
25+
- key: modernize-loop-convert.MinConfidence
26+
value: reasonable
27+
- key: modernize-loop-convert.NamingStyle
28+
value: CamelCase
29+
- key: modernize-pass-by-value.IncludeStyle
30+
value: llvm
31+
- key: modernize-replace-auto-ptr.IncludeStyle
32+
value: llvm
33+
- key: modernize-use-nullptr.NullMacros
34+
value: 'NULL'
35+
...

src/app/FilePacketComparer.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include "Formatting.h"
1212

13+
#include <array>
1314
#include <cstddef>
1415
#include <filesystem>
1516
#include <iomanip>
@@ -80,7 +81,7 @@ std::optional<CompareFile> parseFileNameAndStreamIndex(const std::string &variab
8081
{
8182
file.streamIndex = std::stoi(variable.substr(columnPos + 1));
8283
}
83-
catch (const std::exception &e)
84+
catch (const std::exception &)
8485
{
8586
return {};
8687
}
@@ -106,8 +107,8 @@ Demuxer openInput(std::shared_ptr<IFFmpegLibraries> ffmpegLibraries, const std::
106107
return demuxer;
107108
}
108109

109-
ComparisonMode checkStreamsAndGetComparMode(Demuxer & demuxer1,
110-
Demuxer & demuxer2,
110+
ComparisonMode checkStreamsAndGetComparMode(Demuxer &demuxer1,
111+
Demuxer &demuxer2,
111112
const int streamIndex1,
112113
const int streamIndex2)
113114
{
@@ -138,14 +139,14 @@ ComparisonMode checkStreamsAndGetComparMode(Demuxer & demuxer1,
138139
codecDescriptor1->codecName + " and name 2 " +
139140
codecDescriptor2->codecName);
140141

141-
if (codecDescriptor1->codecName.find("pcm") == 0)
142+
if (codecDescriptor1->codecName.starts_with("pcm"))
142143
return ComparisonMode::Data;
143144
return ComparisonMode::Packets;
144145
}
145146

146147
bool compareData(const ByteVector &data1, const ByteVector &data2)
147148
{
148-
return std::equal(data1.begin(), data1.end(), data2.begin(), data2.end());
149+
return std::ranges::equal(data1, data2);
149150
}
150151

151152
void compareQueuePacketsAndDrain(PacketQueue &queue1, PacketQueue &queue2)
@@ -158,9 +159,6 @@ void compareQueuePacketsAndDrain(PacketQueue &queue1, PacketQueue &queue2)
158159
queue1.pop();
159160
queue2.pop();
160161

161-
const auto streamIndex1 = packet1.getStreamIndex();
162-
const auto streamIndex2 = packet2.getStreamIndex();
163-
164162
static int packetCount = -1;
165163
++packetCount;
166164

@@ -333,12 +331,13 @@ int main(int argc, char const *argv[])
333331
const auto compareMode = checkStreamsAndGetComparMode(
334332
demuxer1, demuxer2, settings->file1.streamIndex, settings->file2.streamIndex);
335333

336-
PacketQueue packetQueue[2];
337-
DataQueue dataQueue[2];
334+
std::array<PacketQueue, 2> packetQueue;
335+
std::array<DataQueue, 2> dataQueue;
338336

339337
auto addPacketToQueue = [&packetQueue, &dataQueue, compareMode](avcodec::AVPacketWrapper &&packet,
340338
const int streamIndex,
341-
const int queueIndex) {
339+
const int queueIndex)
340+
{
342341
const auto packetStreamIndex = packet.getStreamIndex();
343342
if (packetStreamIndex != streamIndex)
344343
return;

src/lib/AVCodec/wrappers/AVChannelInternal.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ ChannelLayout bitMaskToChannelLayout(const uint64_t mask, const bool isAmbisonic
146146
{
147147
ChannelLayout layout;
148148

149-
std::bitset<64> bits(mask);
150-
for (int bitPosition = 0; bitPosition < 64; ++bitPosition)
149+
constexpr auto MAX_CHANNELS = 64;
150+
151+
std::bitset<MAX_CHANNELS> bits(mask);
152+
for (int bitPosition = 0; bitPosition < MAX_CHANNELS; ++bitPosition)
151153
{
152154
if (bits.test(bitPosition))
153155
{

src/lib/AVCodec/wrappers/AVCodecContextWrapper.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ namespace internal
3636

3737
} // namespace internal
3838

39-
AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContext * codecContext,
39+
AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContext *codecContext,
4040
std::shared_ptr<IFFmpegLibraries> ffmpegLibraries)
4141
: codecContext(codecContext), ffmpegLibraries(ffmpegLibraries)
4242
{
@@ -53,7 +53,8 @@ AVCodecContextWrapper::AVCodecContextWrapper(std::shared_ptr<IFFmpegLibraries> f
5353
throw std::runtime_error("Provided ffmpeg libraries pointer must not be null");
5454
}
5555

56-
AVCodecContextWrapper &AVCodecContextWrapper::operator=(AVCodecContextWrapper &&codecContextWrapper)
56+
AVCodecContextWrapper &
57+
AVCodecContextWrapper::operator=(AVCodecContextWrapper &&codecContextWrapper) noexcept
5758
{
5859
this->codecContext = codecContextWrapper.codecContext;
5960
this->codecContextOwnership = codecContextWrapper.codecContextOwnership;
@@ -62,12 +63,11 @@ AVCodecContextWrapper &AVCodecContextWrapper::operator=(AVCodecContextWrapper &&
6263
return *this;
6364
}
6465

65-
AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContextWrapper &&codecContextWrapper)
66+
AVCodecContextWrapper::AVCodecContextWrapper(AVCodecContextWrapper &&codecContextWrapper) noexcept
67+
: codecContext(codecContextWrapper.codecContext),
68+
codecContextOwnership(codecContextWrapper.codecContextOwnership),
69+
ffmpegLibraries(std::move(codecContextWrapper.ffmpegLibraries))
6670
{
67-
this->codecContext = codecContextWrapper.codecContext;
68-
this->codecContextOwnership = codecContextWrapper.codecContextOwnership;
69-
codecContextWrapper.codecContext = nullptr;
70-
this->ffmpegLibraries = std::move(codecContextWrapper.ffmpegLibraries);
7171
}
7272

7373
AVCodecContextWrapper::~AVCodecContextWrapper()
@@ -173,56 +173,56 @@ AVCodecContextWrapper::decodeVideo2(const avcodec::AVPacketWrapper &packet)
173173

174174
avutil::MediaType AVCodecContextWrapper::getCodecType() const
175175
{
176-
AVMediaType type;
176+
AVMediaType type{};
177177
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, type, codec_type);
178178
return avutil::toMediaType(type);
179179
}
180180

181181
AVCodecID AVCodecContextWrapper::getCodecID() const
182182
{
183-
AVCodecID id;
183+
AVCodecID id{};
184184
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, id, codec_id);
185185
return id;
186186
}
187187

188188
avutil::PixelFormatDescriptor AVCodecContextWrapper::getPixelFormat() const
189189
{
190-
AVPixelFormat avPixelFormat;
190+
AVPixelFormat avPixelFormat{};
191191
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, avPixelFormat, pix_fmt);
192192
return avutil::convertAVPixFmtDescriptor(avPixelFormat, this->ffmpegLibraries);
193193
}
194194

195195
Size AVCodecContextWrapper::getSize() const
196196
{
197-
int width;
197+
int width{};
198198
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, width, width);
199199

200-
int height;
200+
int height{};
201201
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, height, height);
202202

203-
return {width, height};
203+
return {.width = width, .height = height};
204204
}
205205

206206
avutil::ColorSpace AVCodecContextWrapper::getColorspace() const
207207
{
208-
AVColorSpace avColorspace;
208+
AVColorSpace avColorspace{};
209209
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, avColorspace, colorspace);
210210
return avutil::toColorspace(avColorspace);
211211
}
212212

213213
Rational AVCodecContextWrapper::getTimeBase() const
214214
{
215-
AVRational timebase;
215+
AVRational timebase{};
216216
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, timebase, time_base);
217-
return Rational({timebase.num, timebase.den});
217+
return fromAVRational(timebase);
218218
}
219219

220220
ByteVector AVCodecContextWrapper::getExtradata() const
221221
{
222-
uint8_t *extradata;
222+
uint8_t *extradata{};
223223
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, extradata, extradata);
224224

225-
int extradataSize;
225+
int extradataSize{};
226226
CAST_AVCODEC_GET_MEMBER(AVCodecContext, this->codecContext, extradataSize, extradata_size);
227227

228228
return copyDataFromRawArray(extradata, extradataSize);

src/lib/AVCodec/wrappers/AVCodecContextWrapper.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class AVCodecContextWrapper
2626
AVCodecContextWrapper(libffmpeg::internal::AVCodecContext *codecContext,
2727
std::shared_ptr<IFFmpegLibraries> ffmpegLibraries);
2828
AVCodecContextWrapper(const AVCodecContextWrapper &) = delete;
29-
AVCodecContextWrapper &operator =(AVCodecContextWrapper &&);
29+
AVCodecContextWrapper &operator=(AVCodecContextWrapper &&) noexcept;
3030
AVCodecContextWrapper &operator=(const AVCodecContextWrapper &) = delete;
31-
AVCodecContextWrapper(AVCodecContextWrapper &&wrapper);
31+
AVCodecContextWrapper(AVCodecContextWrapper &&wrapper) noexcept;
3232
~AVCodecContextWrapper();
3333

3434
bool openContextForDecoding(const avcodec::AVCodecParametersWrapper &codecParameters);
@@ -47,13 +47,13 @@ class AVCodecContextWrapper
4747
// This is the old FFMpeg 2 interface before pushPacket/pullFrame.
4848
DecodeResult decodeVideo2(const avcodec::AVPacketWrapper &packet);
4949

50-
avutil::MediaType getCodecType() const;
51-
libffmpeg::internal::AVCodecID getCodecID() const;
52-
avutil::PixelFormatDescriptor getPixelFormat() const;
53-
Size getSize() const;
54-
avutil::ColorSpace getColorspace() const;
55-
Rational getTimeBase() const;
56-
ByteVector getExtradata() const;
50+
[[nodiscard]] avutil::MediaType getCodecType() const;
51+
[[nodiscard]] libffmpeg::internal::AVCodecID getCodecID() const;
52+
[[nodiscard]] avutil::PixelFormatDescriptor getPixelFormat() const;
53+
[[nodiscard]] Size getSize() const;
54+
[[nodiscard]] avutil::ColorSpace getColorspace() const;
55+
[[nodiscard]] Rational getTimeBase() const;
56+
[[nodiscard]] ByteVector getExtradata() const;
5757

5858
private:
5959
/* It depends on how the wrapper is created who has ownership of this.

0 commit comments

Comments
 (0)