@@ -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
5656VideoRendererBackend::~VideoRendererBackend () = default ;
5757
5858namespace {
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
0 commit comments