Skip to content

Commit 50daebe

Browse files
committed
fix: fix clang-tidy errors
1 parent 8718ce0 commit 50daebe

File tree

8 files changed

+53
-43
lines changed

8 files changed

+53
-43
lines changed

src/graphics/video_renderer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct VideoRendererBackend {
9393
get_encoding_paramaters(u32 fps, shapes::UPoint size, const std::filesystem::path& destination_path);
9494

9595
public:
96-
OOPETRIS_GRAPHICS_EXPORTED explicit VideoRendererBackend(const std::filesystem::path& destination_path);
96+
OOPETRIS_GRAPHICS_EXPORTED explicit VideoRendererBackend(std::filesystem::path destination_path);
9797

9898
OOPETRIS_GRAPHICS_EXPORTED ~VideoRendererBackend();
9999

src/graphics/video_renderer_embedded.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,34 @@ struct Decoder {
4949

5050
// general information and usage from: https://ffmpeg.org//doxygen/trunk/index.html
5151
// and https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/README
52-
VideoRendererBackend::VideoRendererBackend(const std::filesystem::path& destination_path)
53-
: m_destination_path{ destination_path },
52+
VideoRendererBackend::VideoRendererBackend(std::filesystem::path destination_path)
53+
: m_destination_path{ std::move(destination_path) },
5454
m_decoder{ nullptr } { }
5555

5656
VideoRendererBackend::~VideoRendererBackend() = default;
5757

5858
namespace {
5959

60-
constexpr const int READ_END = 0;
61-
constexpr const int WRITE_END = 1;
60+
constexpr const int read_end = 0;
61+
constexpr const int write_end = 1;
6262

63-
constexpr const size_t BUF_LEN = 1024;
63+
constexpr const size_t buf_len = 1024;
6464

6565
std::string av_error_to_string(int errnum) {
66-
auto* buf = new char[BUF_LEN];
67-
auto* buff_res = av_make_error_string(buf, BUF_LEN, errnum);
66+
auto* buf = new char[buf_len]; //NOLINT(cppcoreguidelines-owning-memory)
67+
auto* buff_res = av_make_error_string(buf, buf_len, errnum);
6868
if (buff_res == nullptr) {
6969
return "Unknown error";
7070
}
7171

7272
std::string result{ buff_res };
7373

74-
delete[] buf;
74+
delete[] buf; //NOLINT(cppcoreguidelines-owning-memory)
7575

7676
return result;
7777
}
7878

79-
std::optional<std::string> start_encoding(
79+
std::optional<std::string> start_encoding( //NOLINT(readability-function-cognitive-complexity)
8080
u32 fps,
8181
shapes::UPoint size,
8282
const std::filesystem::path& destination_path,
@@ -150,7 +150,8 @@ namespace {
150150
);
151151
}
152152

153-
AVStream* input_video_stream = input_format_ctx->streams[video_stream_index];
153+
AVStream* input_video_stream =
154+
input_format_ctx->streams[video_stream_index]; //NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
154155

155156
AVCodecContext* input_codec_context = avcodec_alloc_context3(input_decoder);
156157
if (input_codec_context == nullptr) {
@@ -203,7 +204,7 @@ namespace {
203204
return fmt::format("Could not alloc output file {}: {}", destination_path.string(), av_output_ret);
204205
}
205206

206-
std::string encoder_metadata_name = fmt::format(
207+
const std::string encoder_metadata_name = fmt::format(
207208
"{} v{} ({}) {}", constants::program_name.string(), constants::version.string(), utils::git_commit(),
208209
LIBAVFORMAT_IDENT
209210
);
@@ -263,7 +264,7 @@ namespace {
263264

264265
out_stream->time_base = output_codec_context->time_base;
265266

266-
std::string stream_encoder_metadata_name = fmt::format(
267+
const std::string stream_encoder_metadata_name = fmt::format(
267268
"{} v{} ({}) {} {}", constants::program_name.string(), constants::version.string(), utils::git_commit(),
268269
LIBAVCODEC_IDENT, output_encoder->name
269270
);
@@ -354,7 +355,9 @@ namespace {
354355
auto read_frame_ret = av_read_frame(input_format_ctx, pkt);
355356
if (read_frame_ret == AVERROR_EOF) {
356357
break;
357-
} else if (read_frame_ret < 0) {
358+
}
359+
360+
if (read_frame_ret < 0) {
358361
return fmt::format("Receiving a frame from the input failed: {}", av_error_to_string(read_frame_ret));
359362
}
360363

@@ -376,7 +379,9 @@ namespace {
376379
read_ret = avcodec_receive_frame(input_codec_context, decode_frame);
377380
if (read_ret == AVERROR(EAGAIN) || read_ret == AVERROR_EOF) {
378381
break;
379-
} else if (read_ret < 0) {
382+
}
383+
384+
if (read_ret < 0) {
380385
return fmt::format("Receiving a frame from the decoder failed: {}", av_error_to_string(read_ret));
381386
}
382387

@@ -404,7 +409,9 @@ namespace {
404409
write_ret = avcodec_receive_packet(output_codec_context, pkt);
405410
if (write_ret == AVERROR(EAGAIN) || write_ret == AVERROR_EOF) {
406411
break;
407-
} else if (write_ret < 0) {
412+
}
413+
414+
if (write_ret < 0) {
408415
return fmt::format(
409416
"Receiving a packet from the encoder failed: {}", av_error_to_string(write_ret)
410417
);
@@ -474,13 +481,13 @@ std::optional<std::string> VideoRendererBackend::setup(u32 fps, shapes::UPoint s
474481
if (pipe(pipefd.data()) < 0) {
475482
return fmt::format("Could not create a pipe: {}", strerror(errno));
476483
}
477-
int close_fd = pipefd[READ_END];
478-
int input_fd = pipefd[WRITE_END];
479-
std::string input_url = fmt::format("pipe:{}", close_fd);
484+
const int close_fd = pipefd[read_end];
485+
const int input_fd = pipefd[write_end];
486+
const std::string input_url = fmt::format("pipe:{}", close_fd);
480487
#endif
481488

482489
std::future<std::optional<std::string>> encoding_thread =
483-
std::async(std::launch::async, [close_fd, input_url, fps, size, this] -> std::optional<std::string> {
490+
std::async(std::launch::async, [close_fd, input_url, fps, size, this]() -> std::optional<std::string> {
484491
utils::set_thread_name("ffmpeg encoder");
485492
auto result = start_encoding(fps, size, this->m_destination_path, input_url, this->m_decoder);
486493

src/graphics/video_renderer_unix.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ struct Decoder {
1717
};
1818

1919
// inspired by: https://github.com/tsoding/musializer/blob/762a729ff69ba1f984b0f2604e0eac08af46327c/src/ffmpeg_linux.c
20-
VideoRendererBackend::VideoRendererBackend(const std::filesystem::path& destination_path)
21-
: m_destination_path{ destination_path },
20+
VideoRendererBackend::VideoRendererBackend(std::filesystem::path destination_path)
21+
: m_destination_path{ std::move(destination_path) },
2222
m_decoder{ nullptr } { }
2323

2424
VideoRendererBackend::~VideoRendererBackend() = default;
2525

2626
namespace {
2727

28-
constexpr const int READ_END = 0;
29-
constexpr const int WRITE_END = 1;
28+
constexpr const int read_end = 0;
29+
constexpr const int write_end = 1;
3030

3131
} // namespace
3232

@@ -45,17 +45,17 @@ std::optional<std::string> VideoRendererBackend::setup(u32 fps, shapes::UPoint s
4545
return fmt::format("FFMPEG: Could not create a pipe: {}", strerror(errno));
4646
}
4747

48-
pid_t child = fork();
48+
const pid_t child = fork();
4949
if (child < 0) {
5050
return fmt::format("FFMPEG: could not fork a child: {}", strerror(errno));
5151
}
5252

5353
if (child == 0) {
54-
if (dup2(pipefd.at(READ_END), STDIN_FILENO) < 0) {
54+
if (dup2(pipefd.at(read_end), STDIN_FILENO) < 0) {
5555
std::cerr << "FFMPEG CHILD: could not reopen read end of pipe as stdin: " << strerror(errno) << "\n";
5656
std::exit(1);
5757
}
58-
close(pipefd[WRITE_END]);
58+
close(pipefd[write_end]);
5959

6060

6161
auto paramaters = VideoRendererBackend::get_encoding_paramaters(fps, size, m_destination_path);
@@ -67,7 +67,7 @@ std::optional<std::string> VideoRendererBackend::setup(u32 fps, shapes::UPoint s
6767

6868
args.push_back(nullptr);
6969
//TODO(Totto): support audio, that loops the music as in the main game
70-
int ret =
70+
const int ret =
7171
execvp("ffmpeg",
7272
const_cast<char* const*>(args.data())); // NOLINT(cppcoreguidelines-pro-type-const-cast)
7373
if (ret < 0) {
@@ -78,11 +78,11 @@ std::optional<std::string> VideoRendererBackend::setup(u32 fps, shapes::UPoint s
7878
std::exit(1);
7979
}
8080

81-
if (close(pipefd[READ_END]) < 0) {
81+
if (close(pipefd[read_end]) < 0) {
8282
spdlog::error("FFMPEG: could not close read end of the pipe on the parent's end: {}", strerror(errno));
8383
}
8484

85-
m_decoder = std::make_unique<Decoder>(pipefd[WRITE_END], child);
85+
m_decoder = std::make_unique<Decoder>(pipefd[write_end], child);
8686
return std::nullopt;
8787
}
8888

@@ -102,8 +102,9 @@ bool VideoRendererBackend::finish(bool cancel) {
102102
spdlog::warn("FFMPEG: could not close write end of the pipe on the parent's end: {}", strerror(errno));
103103
}
104104

105-
if (cancel)
105+
if (cancel) {
106106
kill(m_decoder->pid, SIGKILL);
107+
}
107108

108109
while (true) {
109110
int wstatus = 0;

src/graphics/video_renderer_windows.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ struct Decoder {
1616
};
1717

1818
// inspired by: https://github.com/tsoding/musializer/blob/762a729ff69ba1f984b0f2604e0eac08af46327c/src/ffmpeg_windows.c
19-
VideoRendererBackend::VideoRendererBackend(const std::filesystem::path& destination_path)
20-
: m_destination_path{ destination_path },
19+
VideoRendererBackend::VideoRendererBackend(std::filesystem::path destination_path)
20+
: m_destination_path{ std::move(destination_path) },
2121
m_decoder{ nullptr } { }
2222

2323
VideoRendererBackend::~VideoRendererBackend() = default;

src/scenes/recording_selector/recording_component.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,14 @@ ui::Widget::EventHandleResult custom_ui::RecordingComponent::handle_event(
117117
if (m_current_focus_id == m_main_layout.focus_id()) {
118118
return {
119119
true,
120-
{ ui::EventHandleType::RequestAction, this, nullptr }
120+
{ .handle_type = ui::EventHandleType::RequestAction, .widget = this, .data = nullptr }
121121
};
122122
}
123123

124124
if (m_current_focus_id == render_button->focus_id()) {
125125
return {
126126
true,
127-
{ ui::EventHandleType::RequestAction, render_button, nullptr }
127+
{ .handle_type = ui::EventHandleType::RequestAction, .widget = render_button, .data = nullptr }
128128
};
129129
}
130130

@@ -162,13 +162,13 @@ ui::Widget::EventHandleResult custom_ui::RecordingComponent::handle_event(
162162
if (not has_focus()) {
163163
return {
164164
true,
165-
{ ui::EventHandleType::RequestFocus, this, nullptr }
165+
{ .handle_type = ui::EventHandleType::RequestFocus, .widget = this, .data = nullptr }
166166
};
167167
}
168168

169169
return {
170170
true,
171-
{ ui::EventHandleType::RequestAction, render_button, this }
171+
{ .handle_type = ui::EventHandleType::RequestAction, .widget = render_button, .data = this }
172172
};
173173
}
174174

@@ -179,7 +179,9 @@ ui::Widget::EventHandleResult custom_ui::RecordingComponent::handle_event(
179179

180180
return {
181181
true,
182-
{ has_focus() ? ui::EventHandleType::RequestAction : ui::EventHandleType::RequestFocus, this, nullptr }
182+
{ .handle_type = has_focus() ? ui::EventHandleType::RequestAction : ui::EventHandleType::RequestFocus,
183+
.widget = this,
184+
.data = nullptr }
183185
};
184186
}
185187
return true;

src/scenes/settings_menu/color_setting_row.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ ui::Widget::EventHandleResult detail::ColorSettingRectangle::handle_event(
6565
if (has_focus() and navigation_event == input::NavigationEvent::OK) {
6666
return {
6767
true,
68-
{ ui::EventHandleType::RequestAction, this, nullptr }
68+
{ .handle_type = ui::EventHandleType::RequestAction, .widget = this, .data = nullptr }
6969
};
7070
}
7171

@@ -74,7 +74,7 @@ ui::Widget::EventHandleResult detail::ColorSettingRectangle::handle_event(
7474
if (hover_result.is(ui::ActionType::Clicked)) {
7575
return {
7676
true,
77-
{ ui::EventHandleType::RequestAction, this, nullptr }
77+
{ .handle_type = ui::EventHandleType::RequestAction, .widget = this, .data = nullptr }
7878
};
7979
}
8080
return true;

src/ui/components/color_picker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ detail::ColorCanvas::handle_event(const std::shared_ptr<input::InputManager>& in
164164
SDL_CaptureMouse(SDL_TRUE);
165165
handled = {
166166
true,
167-
{ ui::EventHandleType::RequestFocus, this, nullptr }
167+
{ .handle_type = ui::EventHandleType::RequestFocus, .widget = this, .data = nullptr }
168168
};
169169
}
170170
} else if (pointer_event == input::PointerEvent::PointerUp) {

src/ui/components/textinput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ ui::Widget::EventHandleResult ui::TextInput::handle_event( //NOLINT(readability-
115115
if (hover_result.is(ActionType::Clicked)) {
116116
return {
117117
true,
118-
{ EventHandleType::RequestFocus, this, nullptr }
118+
{ .handle_type = EventHandleType::RequestFocus, .widget = this, .data = nullptr }
119119
};
120120
}
121121

@@ -129,7 +129,7 @@ ui::Widget::EventHandleResult ui::TextInput::handle_event( //NOLINT(readability-
129129
on_unfocus();
130130
return {
131131
true,
132-
{ EventHandleType::RequestAction, this, nullptr }
132+
{ .handle_type = EventHandleType::RequestAction, .widget = this, .data = nullptr }
133133
};
134134
}
135135
//TODO(Totto): in some cases this is caught before that, and never triggered

0 commit comments

Comments
 (0)