From ed7e314345934602cf5051a91658dfe2a794e85f Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 26 Apr 2021 19:38:59 +0200 Subject: C++11 tidying. --- src/lib/decoder_factory.cc | 61 ++++++++++++++----------------------- src/lib/decoder_factory.h | 3 +- src/lib/ffmpeg_decoder.cc | 4 +-- src/lib/resampler.cc | 22 +++++++------ src/lib/string_text_file_decoder.cc | 18 ++++++----- 5 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src/lib/decoder_factory.cc b/src/lib/decoder_factory.cc index 1acef6f4f..b360eabf3 100644 --- a/src/lib/decoder_factory.cc +++ b/src/lib/decoder_factory.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2020 Carl Hetherington + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "atmos_mxf_content.h" #include "atmos_mxf_decoder.h" #include "ffmpeg_content.h" @@ -34,66 +35,50 @@ #include "video_mxf_decoder.h" #include "timer.h" -using std::list; + +using std::make_shared; using std::shared_ptr; using std::dynamic_pointer_cast; -template -shared_ptr -maybe_cast (shared_ptr d) -{ - if (!d) { - return shared_ptr (); - } - return dynamic_pointer_cast (d); -} -/** - @param tolerant true to proceed in the face of `survivable' errors, otherwise false. - @param old_decoder A `used' decoder that has been previously made for this piece of content, or 0 -*/ +/** @param tolerant true to proceed in the face of `survivable' errors, otherwise false + * @param old_decoder A `used' decoder that has been previously made for this piece of content, or nullptr + */ shared_ptr decoder_factory (shared_ptr film, shared_ptr content, bool fast, bool tolerant, shared_ptr old_decoder) { - shared_ptr fc = dynamic_pointer_cast (content); - if (fc) { - return shared_ptr (new FFmpegDecoder(film, fc, fast)); + if (auto c = dynamic_pointer_cast(content)) { + return make_shared(film, c, fast); } - shared_ptr dc = dynamic_pointer_cast (content); - if (dc) { + if (auto c = dynamic_pointer_cast(content)) { try { - return shared_ptr (new DCPDecoder(film, dc, fast, tolerant, maybe_cast(old_decoder))); + return make_shared(film, c, fast, tolerant, dynamic_pointer_cast(old_decoder)); } catch (KDMError& e) { /* This will be found and reported to the user when the content is examined */ - return shared_ptr(); + return {}; } } - shared_ptr ic = dynamic_pointer_cast (content); - if (ic) { - return shared_ptr (new ImageDecoder(film, ic)); + if (auto c = dynamic_pointer_cast(content)) { + return make_shared(film, c); } - shared_ptr rc = dynamic_pointer_cast (content); - if (rc) { - return shared_ptr (new StringTextFileDecoder(film, rc)); + if (auto c = dynamic_pointer_cast(content)) { + return make_shared(film, c); } - shared_ptr dsc = dynamic_pointer_cast (content); - if (dsc) { - return shared_ptr (new DCPSubtitleDecoder(film, dsc)); + if (auto c = dynamic_pointer_cast(content)) { + return make_shared(film, c); } - shared_ptr vmc = dynamic_pointer_cast (content); - if (vmc) { - return shared_ptr (new VideoMXFDecoder(film, vmc)); + if (auto c = dynamic_pointer_cast(content)) { + return make_shared(film, c); } - shared_ptr amc = dynamic_pointer_cast (content); - if (amc) { - return shared_ptr (new AtmosMXFDecoder(film, amc)); + if (auto c = dynamic_pointer_cast(content)) { + return make_shared(film, c); } - return shared_ptr (); + return {}; } diff --git a/src/lib/decoder_factory.h b/src/lib/decoder_factory.h index 1a39f37e2..46991d873 100644 --- a/src/lib/decoder_factory.h +++ b/src/lib/decoder_factory.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2019 Carl Hetherington + Copyright (C) 2016-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,7 +18,6 @@ */ -class ImageDecoder; extern std::shared_ptr decoder_factory ( std::shared_ptr film, diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 41728ee06..401d26f1f 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -86,7 +86,7 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr film, shared_ptr(this, c); _pts_offset = pts_offset (c->ffmpeg_audio_streams(), c->first_video(), c->active_video_frame_rate(film)); /* It doesn't matter what size or pixel format this is, it just needs to be black */ - _black_image.reset (new Image (AV_PIX_FMT_RGB24, dcp::Size (128, 128), true)); + _black_image = make_shared(AV_PIX_FMT_RGB24, dcp::Size (128, 128), true); _black_image->make_black (); } else { _pts_offset = {}; @@ -148,7 +148,7 @@ FFmpegDecoder::flush () auto const f = full_length.frames_round (vfr); auto v = video->position(film()).get_value_or(ContentTime()).frames_round(vfr) + 1; while (v < f) { - video->emit (film(), shared_ptr (new RawImageProxy (_black_image)), v); + video->emit (film(), make_shared(_black_image), v); ++v; } } diff --git a/src/lib/resampler.cc b/src/lib/resampler.cc index 60eb7f505..378b447f6 100644 --- a/src/lib/resampler.cc +++ b/src/lib/resampler.cc @@ -18,6 +18,7 @@ */ + #include "resampler.h" #include "audio_buffers.h" #include "exceptions.h" @@ -29,11 +30,14 @@ #include "i18n.h" + using std::cout; using std::pair; using std::make_pair; using std::runtime_error; using std::shared_ptr; +using std::make_shared; + /** @param in Input sampling rate (Hz) * @param out Output sampling rate (Hz) @@ -77,7 +81,7 @@ Resampler::run (shared_ptr in) int in_frames = in->frames (); int in_offset = 0; int out_offset = 0; - shared_ptr resampled (new AudioBuffers (_channels, 0)); + auto resampled = make_shared(_channels, 0); while (in_frames > 0) { @@ -88,8 +92,8 @@ Resampler::run (shared_ptr in) float* in_buffer = new float[in_frames * _channels]; { - float** p = in->data (); - float* q = in_buffer; + auto p = in->data (); + auto q = in_buffer; for (int i = 0; i < in_frames; ++i) { for (int j = 0; j < _channels; ++j) { *q++ = p[j][in_offset + i]; @@ -131,8 +135,8 @@ Resampler::run (shared_ptr in) resampled->set_frames (out_offset + data.output_frames_gen); { - float* p = data.data_out; - float** q = resampled->data (); + auto p = data.data_out; + auto q = resampled->data (); for (int i = 0; i < data.output_frames_gen; ++i) { for (int j = 0; j < _channels; ++j) { q[j][out_offset + i] = *p++; @@ -154,12 +158,12 @@ Resampler::run (shared_ptr in) shared_ptr Resampler::flush () { - shared_ptr out (new AudioBuffers (_channels, 0)); + auto out = make_shared(_channels, 0); int out_offset = 0; int64_t const output_size = 65536; float dummy[1]; - float* buffer = new float[output_size]; + auto buffer = new float[output_size]; SRC_DATA data; data.data_in = dummy; @@ -177,8 +181,8 @@ Resampler::flush () out->ensure_size (out_offset + data.output_frames_gen); - float* p = data.data_out; - float** q = out->data (); + auto p = data.data_out; + auto q = out->data (); for (int i = 0; i < data.output_frames_gen; ++i) { for (int j = 0; j < _channels; ++j) { q[j][out_offset + i] = *p++; diff --git a/src/lib/string_text_file_decoder.cc b/src/lib/string_text_file_decoder.cc index f24147851..86f732133 100644 --- a/src/lib/string_text_file_decoder.cc +++ b/src/lib/string_text_file_decoder.cc @@ -18,23 +18,27 @@ */ -#include "string_text_file_decoder.h" + #include "string_text_file_content.h" +#include "string_text_file_decoder.h" #include "text_content.h" #include "text_decoder.h" #include #include -using std::list; -using std::vector; -using std::string; + using std::cout; +using std::dynamic_pointer_cast; +using std::list; +using std::make_shared; using std::max; using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; -using std::dynamic_pointer_cast; using namespace dcpomatic; + StringTextFileDecoder::StringTextFileDecoder (shared_ptr film, shared_ptr content) : Decoder (film) , StringTextFile (content) @@ -44,7 +48,7 @@ StringTextFileDecoder::StringTextFileDecoder (shared_ptr film, share if (!_subtitles.empty()) { first = content_time_period(_subtitles[0]).from; } - text.push_back (shared_ptr (new TextDecoder (this, content->only_text(), first))); + text.push_back (make_shared(this, content->only_text(), first)); } void @@ -73,7 +77,7 @@ StringTextFileDecoder::pass () return true; } - ContentTimePeriod const p = content_time_period (_subtitles[_next]); + auto const p = content_time_period (_subtitles[_next]); only_text()->emit_plain (p, _subtitles[_next]); ++_next; -- cgit v1.2.3