summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2021-04-26 19:38:59 +0200
committerCarl Hetherington <cth@carlh.net>2021-05-07 09:29:59 +0200
commited7e314345934602cf5051a91658dfe2a794e85f (patch)
tree47749e1767f005b13a2f20559ec2c689ee2443f3
parent904edab223a0bc3b5cf2db1c9eb45623106dc9d9 (diff)
C++11 tidying.
-rw-r--r--src/lib/decoder_factory.cc61
-rw-r--r--src/lib/decoder_factory.h3
-rw-r--r--src/lib/ffmpeg_decoder.cc4
-rw-r--r--src/lib/resampler.cc22
-rw-r--r--src/lib/string_text_file_decoder.cc18
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 <cth@carlh.net>
+ Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
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 <class T>
-shared_ptr<T>
-maybe_cast (shared_ptr<Decoder> d)
-{
- if (!d) {
- return shared_ptr<T> ();
- }
- return dynamic_pointer_cast<T> (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>
decoder_factory (shared_ptr<const Film> film, shared_ptr<const Content> content, bool fast, bool tolerant, shared_ptr<Decoder> old_decoder)
{
- shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (content);
- if (fc) {
- return shared_ptr<Decoder> (new FFmpegDecoder(film, fc, fast));
+ if (auto c = dynamic_pointer_cast<const FFmpegContent>(content)) {
+ return make_shared<FFmpegDecoder>(film, c, fast);
}
- shared_ptr<const DCPContent> dc = dynamic_pointer_cast<const DCPContent> (content);
- if (dc) {
+ if (auto c = dynamic_pointer_cast<const DCPContent>(content)) {
try {
- return shared_ptr<Decoder> (new DCPDecoder(film, dc, fast, tolerant, maybe_cast<DCPDecoder>(old_decoder)));
+ return make_shared<DCPDecoder>(film, c, fast, tolerant, dynamic_pointer_cast<DCPDecoder>(old_decoder));
} catch (KDMError& e) {
/* This will be found and reported to the user when the content is examined */
- return shared_ptr<Decoder>();
+ return {};
}
}
- shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (content);
- if (ic) {
- return shared_ptr<Decoder> (new ImageDecoder(film, ic));
+ if (auto c = dynamic_pointer_cast<const ImageContent>(content)) {
+ return make_shared<ImageDecoder>(film, c);
}
- shared_ptr<const StringTextFileContent> rc = dynamic_pointer_cast<const StringTextFileContent> (content);
- if (rc) {
- return shared_ptr<Decoder> (new StringTextFileDecoder(film, rc));
+ if (auto c = dynamic_pointer_cast<const StringTextFileContent>(content)) {
+ return make_shared<StringTextFileDecoder>(film, c);
}
- shared_ptr<const DCPSubtitleContent> dsc = dynamic_pointer_cast<const DCPSubtitleContent> (content);
- if (dsc) {
- return shared_ptr<Decoder> (new DCPSubtitleDecoder(film, dsc));
+ if (auto c = dynamic_pointer_cast<const DCPSubtitleContent>(content)) {
+ return make_shared<DCPSubtitleDecoder>(film, c);
}
- shared_ptr<const VideoMXFContent> vmc = dynamic_pointer_cast<const VideoMXFContent> (content);
- if (vmc) {
- return shared_ptr<Decoder> (new VideoMXFDecoder(film, vmc));
+ if (auto c = dynamic_pointer_cast<const VideoMXFContent>(content)) {
+ return make_shared<VideoMXFDecoder>(film, c);
}
- shared_ptr<const AtmosMXFContent> amc = dynamic_pointer_cast<const AtmosMXFContent> (content);
- if (amc) {
- return shared_ptr<Decoder> (new AtmosMXFDecoder(film, amc));
+ if (auto c = dynamic_pointer_cast<const AtmosMXFContent>(content)) {
+ return make_shared<AtmosMXFDecoder>(film, c);
}
- return shared_ptr<Decoder> ();
+ 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 <cth@carlh.net>
+ Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net>
This file is part of DCP-o-matic.
@@ -18,7 +18,6 @@
*/
-class ImageDecoder;
extern std::shared_ptr<Decoder> decoder_factory (
std::shared_ptr<const Film> 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<const Film> film, shared_ptr<const FFmp
video = make_shared<VideoDecoder>(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<Image>(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<const ImageProxy> (new RawImageProxy (_black_image)), v);
+ video->emit (film(), make_shared<const RawImageProxy>(_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<const AudioBuffers> in)
int in_frames = in->frames ();
int in_offset = 0;
int out_offset = 0;
- shared_ptr<AudioBuffers> resampled (new AudioBuffers (_channels, 0));
+ auto resampled = make_shared<AudioBuffers>(_channels, 0);
while (in_frames > 0) {
@@ -88,8 +92,8 @@ Resampler::run (shared_ptr<const AudioBuffers> 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<const AudioBuffers> 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<const AudioBuffers> in)
shared_ptr<const AudioBuffers>
Resampler::flush ()
{
- shared_ptr<AudioBuffers> out (new AudioBuffers (_channels, 0));
+ auto out = make_shared<AudioBuffers>(_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 <dcp/subtitle_string.h>
#include <iostream>
-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<const Film> film, shared_ptr<const StringTextFileContent> content)
: Decoder (film)
, StringTextFile (content)
@@ -44,7 +48,7 @@ StringTextFileDecoder::StringTextFileDecoder (shared_ptr<const Film> film, share
if (!_subtitles.empty()) {
first = content_time_period(_subtitles[0]).from;
}
- text.push_back (shared_ptr<TextDecoder> (new TextDecoder (this, content->only_text(), first)));
+ text.push_back (make_shared<TextDecoder>(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;