diff options
| author | Carl Hetherington <cth@carlh.net> | 2021-05-03 11:17:34 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2021-05-03 20:18:04 +0200 |
| commit | 689fa55d1529ad88449ca464e9107c4dcc54d1cb (patch) | |
| tree | edd1264941263f2fa25a98d61f98c87876c5b667 /src/lib | |
| parent | 0aabe4060ea4bad7c7caac633aef0737fccff8c2 (diff) | |
C++11 tidying.
Diffstat (limited to 'src/lib')
85 files changed, 811 insertions, 401 deletions
diff --git a/src/lib/analyse_subtitles_job.cc b/src/lib/analyse_subtitles_job.cc index d95e859db..0b003427c 100644 --- a/src/lib/analyse_subtitles_job.cc +++ b/src/lib/analyse_subtitles_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,18 +18,20 @@ */ + #include "analyse_subtitles_job.h" -#include "playlist.h" -#include "player.h" -#include "subtitle_analysis.h" #include "bitmap_text.h" +#include "image.h" +#include "player.h" +#include "playlist.h" #include "render_text.h" +#include "subtitle_analysis.h" #include "text_content.h" -#include "image.h" #include <iostream> #include "i18n.h" + using std::make_shared; using std::shared_ptr; using std::string; @@ -38,6 +40,7 @@ using std::weak_ptr; using namespace boost::placeholders; #endif + AnalyseSubtitlesJob::AnalyseSubtitlesJob (shared_ptr<const Film> film, shared_ptr<Content> content) : Job (film) , _content (content) diff --git a/src/lib/analyse_subtitles_job.h b/src/lib/analyse_subtitles_job.h index 5ad9dd4a4..daaaf267a 100644 --- a/src/lib/analyse_subtitles_job.h +++ b/src/lib/analyse_subtitles_job.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,21 +18,24 @@ */ + #include "job.h" #include "types.h" #include "player_text.h" + class Film; class Content; + class AnalyseSubtitlesJob : public Job { public: AnalyseSubtitlesJob (std::shared_ptr<const Film> film, std::shared_ptr<Content> content); - std::string name () const; - std::string json_name () const; - void run (); + std::string name () const override; + std::string json_name () const override; + void run () override; boost::filesystem::path path () const { return _path; @@ -43,6 +46,6 @@ private: std::weak_ptr<Content> _content; boost::filesystem::path _path; - boost::optional<dcpomatic::Rect<double> > _bounding_box; + boost::optional<dcpomatic::Rect<double>> _bounding_box; }; diff --git a/src/lib/atmos_content.cc b/src/lib/atmos_content.cc index e69474e01..cc74209e0 100644 --- a/src/lib/atmos_content.cc +++ b/src/lib/atmos_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -27,6 +27,7 @@ DCPOMATIC_DISABLE_WARNINGS DCPOMATIC_ENABLE_WARNINGS +using std::make_shared; using std::string; using std::shared_ptr; @@ -54,10 +55,10 @@ shared_ptr<AtmosContent> AtmosContent::from_xml (Content* parent, cxml::ConstNodePtr node) { if (!node->optional_node_child("AtmosLength")) { - return shared_ptr<AtmosContent>(); + return {}; } - return shared_ptr<AtmosContent> (new AtmosContent(parent, node)); + return make_shared<AtmosContent>(parent, node); } diff --git a/src/lib/atmos_content.h b/src/lib/atmos_content.h index 948c3d3c0..8edab8c31 100644 --- a/src/lib/atmos_content.h +++ b/src/lib/atmos_content.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -35,7 +35,8 @@ public: class AtmosContent : public ContentPart { public: - AtmosContent (Content* parent); + explicit AtmosContent (Content* parent); + AtmosContent (Content* parent, cxml::ConstNodePtr node); static std::shared_ptr<AtmosContent> from_xml (Content* parent, cxml::ConstNodePtr node); @@ -54,8 +55,6 @@ public: } private: - AtmosContent (Content* parent, cxml::ConstNodePtr node); - Frame _length; dcp::Fraction _edit_rate; }; diff --git a/src/lib/atmos_decoder.cc b/src/lib/atmos_decoder.cc index 51ee7f0a4..478c45809 100644 --- a/src/lib/atmos_decoder.cc +++ b/src/lib/atmos_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/atmos_decoder.h b/src/lib/atmos_decoder.h index 935fd9925..1ec1b8a6c 100644 --- a/src/lib/atmos_decoder.h +++ b/src/lib/atmos_decoder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -30,11 +30,11 @@ class AtmosDecoder : public DecoderPart public: AtmosDecoder (Decoder* parent, std::shared_ptr<const Content> content); - boost::optional<dcpomatic::ContentTime> position (std::shared_ptr<const Film>) const { + boost::optional<dcpomatic::ContentTime> position (std::shared_ptr<const Film>) const override { return _position; } - void seek (); + void seek () override; void emit (std::shared_ptr<const Film> film, std::shared_ptr<const dcp::AtmosFrame> data, Frame frame, AtmosMetadata metadata); diff --git a/src/lib/atmos_mxf_content.cc b/src/lib/atmos_mxf_content.cc index 3f41a52a0..82c20e88f 100644 --- a/src/lib/atmos_mxf_content.cc +++ b/src/lib/atmos_mxf_content.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,11 +18,12 @@ */ + #include "atmos_content.h" #include "atmos_mxf_content.h" -#include "job.h" -#include "film.h" #include "compose.hpp" +#include "film.h" +#include "job.h" #include <asdcp/KM_log.h> #include <dcp/atmos_asset.h> #include <dcp/exceptions.h> @@ -31,30 +32,35 @@ #include "i18n.h" + using std::list; +using std::make_shared; using std::string; using std::shared_ptr; using namespace dcpomatic; + AtmosMXFContent::AtmosMXFContent (boost::filesystem::path path) : Content (path) { } + AtmosMXFContent::AtmosMXFContent (cxml::ConstNodePtr node, int) : Content (node) { atmos = AtmosContent::from_xml (this, node); } + bool AtmosMXFContent::valid_mxf (boost::filesystem::path path) { Kumu::DefaultLogSink().UnsetFilterFlag(Kumu::LOG_ALLOW_ALL); try { - shared_ptr<dcp::AtmosAsset> a (new dcp::AtmosAsset (path)); + dcp::AtmosAsset a (path); return true; } catch (dcp::MXFFileError& e) { @@ -67,42 +73,47 @@ AtmosMXFContent::valid_mxf (boost::filesystem::path path) return false; } + void AtmosMXFContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) { job->set_progress_unknown (); Content::examine (film, job); - shared_ptr<dcp::AtmosAsset> a (new dcp::AtmosAsset (path(0))); + auto a = make_shared<dcp::AtmosAsset>(path(0)); { boost::mutex::scoped_lock lm (_mutex); - atmos.reset (new AtmosContent(this)); + atmos = make_shared<AtmosContent>(this); atmos->set_length (a->intrinsic_duration()); atmos->set_edit_rate (a->edit_rate()); } } + string AtmosMXFContent::summary () const { return String::compose (_("%1 [Atmos]"), path_summary()); } + void AtmosMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const { - node->add_child("Type")->add_child_text ("AtmosMXF"); + node->add_child("Type")->add_child_text("AtmosMXF"); Content::as_xml (node, with_paths); atmos->as_xml (node); } + DCPTime AtmosMXFContent::full_length (shared_ptr<const Film> film) const { FrameRateChange const frc (film, shared_from_this()); - return DCPTime::from_frames (llrint (atmos->length() * frc.factor()), film->video_frame_rate()); + return DCPTime::from_frames (llrint(atmos->length() * frc.factor()), film->video_frame_rate()); } + DCPTime AtmosMXFContent::approximate_length () const { diff --git a/src/lib/atmos_mxf_content.h b/src/lib/atmos_mxf_content.h index b485167c5..57f041774 100644 --- a/src/lib/atmos_mxf_content.h +++ b/src/lib/atmos_mxf_content.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -37,11 +37,11 @@ public: return std::dynamic_pointer_cast<const AtmosMXFContent> (Content::shared_from_this()); } - void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job> job); - std::string summary () const; - void as_xml (xmlpp::Node* node, bool with_path) const; - dcpomatic::DCPTime full_length (std::shared_ptr<const Film> film) const; - dcpomatic::DCPTime approximate_length () const; + void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job> job) override; + std::string summary () const override; + void as_xml (xmlpp::Node* node, bool with_path) const override; + dcpomatic::DCPTime full_length (std::shared_ptr<const Film> film) const override; + dcpomatic::DCPTime approximate_length () const override; static bool valid_mxf (boost::filesystem::path path); }; diff --git a/src/lib/atmos_mxf_decoder.cc b/src/lib/atmos_mxf_decoder.cc index 6c7cda61a..9fcd9d2a6 100644 --- a/src/lib/atmos_mxf_decoder.cc +++ b/src/lib/atmos_mxf_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "atmos_content.h" #include "atmos_decoder.h" #include "atmos_mxf_content.h" @@ -26,15 +27,18 @@ #include <dcp/atmos_asset.h> #include <dcp/atmos_asset_reader.h> + +using std::make_shared; using std::shared_ptr; + AtmosMXFDecoder::AtmosMXFDecoder (std::shared_ptr<const Film> film, std::shared_ptr<const AtmosMXFContent> content) : Decoder (film) , _content (content) { - atmos.reset (new AtmosDecoder(this, content)); + atmos = make_shared<AtmosDecoder>(this, content); - shared_ptr<dcp::AtmosAsset> asset (new dcp::AtmosAsset(_content->path(0))); + auto asset = make_shared<dcp::AtmosAsset>(_content->path(0)); _reader = asset->start_read (); _metadata = AtmosMetadata (asset); } @@ -43,8 +47,8 @@ AtmosMXFDecoder::AtmosMXFDecoder (std::shared_ptr<const Film> film, std::shared_ bool AtmosMXFDecoder::pass () { - double const vfr = _content->active_video_frame_rate (film()); - int64_t const frame = _next.frames_round (vfr); + auto const vfr = _content->active_video_frame_rate (film()); + auto const frame = _next.frames_round (vfr); if (frame >= _content->atmos->length()) { return true; diff --git a/src/lib/atmos_mxf_decoder.h b/src/lib/atmos_mxf_decoder.h index 4e7ce5c6f..b8e7fc53d 100644 --- a/src/lib/atmos_mxf_decoder.h +++ b/src/lib/atmos_mxf_decoder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,20 +18,23 @@ */ + #include "atmos_metadata.h" #include "dcpomatic_time.h" #include "decoder.h" #include <dcp/atmos_asset_reader.h> + class AtmosMXFContent; + class AtmosMXFDecoder : public Decoder { public: AtmosMXFDecoder (std::shared_ptr<const Film> film, std::shared_ptr<const AtmosMXFContent>); - bool pass (); - void seek (dcpomatic::ContentTime t, bool accurate); + bool pass () override; + void seek (dcpomatic::ContentTime t, bool accurate) override; private: std::shared_ptr<const AtmosMXFContent> _content; diff --git a/src/lib/audio_buffers.cc b/src/lib/audio_buffers.cc index 5f2d5539d..9f91810e0 100644 --- a/src/lib/audio_buffers.cc +++ b/src/lib/audio_buffers.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "util.h" #include "audio_buffers.h" #include "dcpomatic_assert.h" @@ -26,8 +27,11 @@ #include <cmath> #include <stdexcept> + using std::bad_alloc; using std::shared_ptr; +using std::make_shared; + /** Construct an AudioBuffers. Audio data is undefined after this constructor. * @param channels Number of channels. @@ -38,6 +42,7 @@ AudioBuffers::AudioBuffers (int channels, int32_t frames) allocate (channels, frames); } + /** Copy constructor. * @param other Other AudioBuffers; data is copied. */ @@ -47,18 +52,21 @@ AudioBuffers::AudioBuffers (AudioBuffers const & other) copy_from (&other, other._frames, 0, 0); } + AudioBuffers::AudioBuffers (std::shared_ptr<const AudioBuffers> other) { allocate (other->_channels, other->_frames); copy_from (other.get(), other->_frames, 0, 0); } + AudioBuffers::AudioBuffers (std::shared_ptr<const AudioBuffers> other, int32_t frames_to_copy, int32_t read_offset) { allocate (other->_channels, frames_to_copy); copy_from (other.get(), frames_to_copy, read_offset, 0); } + AudioBuffers & AudioBuffers::operator= (AudioBuffers const & other) { @@ -73,12 +81,14 @@ AudioBuffers::operator= (AudioBuffers const & other) return *this; } + /** AudioBuffers destructor */ AudioBuffers::~AudioBuffers () { deallocate (); } + void AudioBuffers::allocate (int channels, int32_t frames) { @@ -89,19 +99,20 @@ AudioBuffers::allocate (int channels, int32_t frames) _frames = frames; _allocated_frames = frames; - _data = static_cast<float**> (malloc (_channels * sizeof (float *))); + _data = static_cast<float**> (malloc(_channels * sizeof(float *))); if (!_data) { throw bad_alloc (); } for (int i = 0; i < _channels; ++i) { - _data[i] = static_cast<float*> (malloc (frames * sizeof (float))); + _data[i] = static_cast<float*> (malloc(frames * sizeof(float))); if (!_data[i]) { throw bad_alloc (); } } } + void AudioBuffers::deallocate () { @@ -112,6 +123,7 @@ AudioBuffers::deallocate () free (_data); } + /** @param c Channel index. * @return Buffer for this channel. */ @@ -122,6 +134,7 @@ AudioBuffers::data (int c) const return _data[c]; } + /** Set the number of frames that these AudioBuffers will report themselves * as having. If we reduce the number of frames, the `lost' frames will * be silenced. @@ -138,6 +151,7 @@ AudioBuffers::set_frames (int32_t f) _frames = f; } + /** Make all frames silent */ void AudioBuffers::make_silent () @@ -147,6 +161,7 @@ AudioBuffers::make_silent () } } + /** Make all samples on a given channel silent. * @param c Channel. */ @@ -161,6 +176,7 @@ AudioBuffers::make_silent (int c) memset (_data[c], 0, _frames * sizeof(float)); } + /** Make some frames. * @param from Start frame. * @param frames Number of frames to silence. @@ -178,6 +194,7 @@ AudioBuffers::make_silent (int32_t from, int32_t frames) } } + /** Copy data from another AudioBuffers to this one. All channels are copied. * @param from AudioBuffers to copy from; must have the same number of channels as this. * @param frames_to_copy Number of frames to copy. @@ -202,6 +219,7 @@ AudioBuffers::copy_from (AudioBuffers const * from, int32_t frames_to_copy, int3 } } + /** Move audio data around. * @param from Offset to move from. * @param to Offset to move to. @@ -228,6 +246,7 @@ AudioBuffers::move (int32_t frames, int32_t from, int32_t to) } } + /** Add data from from `from', `from_channel' to our channel `to_channel'. * @param from Buffers to copy data from. * @param from_channel Channel index to read in \p from. @@ -241,14 +260,15 @@ AudioBuffers::accumulate_channel (AudioBuffers const * from, int from_channel, i DCPOMATIC_ASSERT (from->frames() == N); DCPOMATIC_ASSERT (to_channel <= _channels); - float* s = from->data (from_channel); - float* d = _data[to_channel]; + auto s = from->data (from_channel); + auto d = _data[to_channel]; for (int i = 0; i < N; ++i) { *d++ += (*s++) * gain; } } + /** Ensure we have space for at least a certain number of frames. If we extend * the buffers, fill the new space with silence. */ @@ -271,19 +291,20 @@ AudioBuffers::ensure_size (int32_t frames) frames++; for (int i = 0; i < _channels; ++i) { - _data[i] = static_cast<float*> (realloc (_data[i], frames * sizeof (float))); + _data[i] = static_cast<float*> (realloc(_data[i], frames * sizeof(float))); if (!_data[i]) { throw bad_alloc (); } } - int32_t const old_allocated = _allocated_frames; + auto const old_allocated = _allocated_frames; _allocated_frames = frames; if (old_allocated < _allocated_frames) { make_silent (old_allocated, _allocated_frames - old_allocated); } } + /** Mix some other buffers with these ones. The AudioBuffers must have the same number of channels. * @param from Audio buffers to get data from. * @param frames Number of frames to mix. @@ -297,7 +318,7 @@ AudioBuffers::accumulate_frames (AudioBuffers const * from, int32_t frames, int3 DCPOMATIC_ASSERT (read_offset >= 0); DCPOMATIC_ASSERT (write_offset >= 0); - float** from_data = from->data (); + auto from_data = from->data (); for (int i = 0; i < _channels; ++i) { for (int j = 0; j < frames; ++j) { _data[i][j + write_offset] += from_data[i][j + read_offset]; @@ -305,11 +326,12 @@ AudioBuffers::accumulate_frames (AudioBuffers const * from, int32_t frames, int3 } } + /** @param dB gain in dB */ void AudioBuffers::apply_gain (float dB) { - float const linear = db_to_linear (dB); + auto const linear = db_to_linear (dB); for (int i = 0; i < _channels; ++i) { for (int j = 0; j < _frames; ++j) { @@ -318,17 +340,19 @@ AudioBuffers::apply_gain (float dB) } } + /** @param c Channel index. * @return AudioBuffers object containing only channel `c' from this AudioBuffers. */ shared_ptr<AudioBuffers> AudioBuffers::channel (int c) const { - shared_ptr<AudioBuffers> o (new AudioBuffers (1, frames ())); + auto o = make_shared<AudioBuffers>(1, frames()); o->copy_channel_from (this, c, 0); return o; } + /** Copy all the samples from a channel on another AudioBuffers to a channel on this one. * @param from AudioBuffers to copy from. * @param from_channel Channel index in `from' to copy from. @@ -341,15 +365,17 @@ AudioBuffers::copy_channel_from (AudioBuffers const * from, int from_channel, in memcpy (data(to_channel), from->data(from_channel), frames() * sizeof (float)); } + /** Make a copy of these AudioBuffers */ shared_ptr<AudioBuffers> AudioBuffers::clone () const { - shared_ptr<AudioBuffers> b (new AudioBuffers (channels (), frames ())); - b->copy_from (this, frames (), 0, 0); + auto b = make_shared<AudioBuffers>(channels(), frames()); + b->copy_from (this, frames(), 0, 0); return b; } + /** Extend these buffers with the data from another. The AudioBuffers must have the same number of channels. */ void AudioBuffers::append (shared_ptr<const AudioBuffers> other) @@ -360,6 +386,7 @@ AudioBuffers::append (shared_ptr<const AudioBuffers> other) _frames += other->frames(); } + /** Remove some frames from the start of these AudioBuffers */ void AudioBuffers::trim_start (int32_t frames) diff --git a/src/lib/audio_buffers.h b/src/lib/audio_buffers.h index 7a02b2b0a..146d5bd3e 100644 --- a/src/lib/audio_buffers.h +++ b/src/lib/audio_buffers.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + /** @file src/lib/audio_buffers.h * @brief AudioBuffers class. */ @@ -98,4 +99,5 @@ private: float** _data; }; + #endif diff --git a/src/lib/butler.cc b/src/lib/butler.cc index b2128efdb..5a8e646aa 100644 --- a/src/lib/butler.cc +++ b/src/lib/butler.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 "butler.h" #include "player.h" #include "util.h" @@ -43,6 +44,7 @@ using namespace dcpomatic; using namespace boost::placeholders; #endif + /** Minimum video readahead in frames */ #define MINIMUM_VIDEO_READAHEAD 10 /** Maximum video readahead in frames; should never be exceeded (by much) unless there are bugs in Player */ @@ -52,6 +54,7 @@ using namespace boost::placeholders; /** Maximum audio readahead in frames; should never be exceeded (by much) unless there are bugs in Player */ #define MAXIMUM_AUDIO_READAHEAD (48000 * MAXIMUM_VIDEO_READAHEAD / 24) + /** @param pixel_format Pixel format functor that will be used when calling ::image on PlayerVideos coming out of this * butler. This will be used (where possible) to prepare the PlayerVideos so that calling image() on them is quick. * @param aligned Same as above for the `aligned' flag. @@ -69,7 +72,7 @@ Butler::Butler ( ) : _film (film) , _player (player) - , _prepare_work (new boost::asio::io_service::work (_prepare_service)) + , _prepare_work (new boost::asio::io_service::work(_prepare_service)) , _pending_seek_accurate (false) , _suspended (0) , _finished (false) @@ -106,6 +109,7 @@ Butler::Butler ( } } + Butler::~Butler () { boost::this_thread::disable_interruption dis; @@ -175,6 +179,7 @@ Butler::should_run () const return (_video.size() < MAXIMUM_VIDEO_READAHEAD) && (_audio.size() < MAXIMUM_AUDIO_READAHEAD); } + void Butler::thread () try @@ -230,6 +235,7 @@ try _arrived.notify_all (); } + /** @param blocking true if we should block until video is available. If blocking is false * and no video is immediately available the method will return a 0 PlayerVideo and the error AGAIN. * @param e if non-0 this is filled with an error code (if an error occurs) or is untouched if no error occurs. @@ -272,6 +278,7 @@ Butler::get_video (bool blocking, Error* e) return r; } + optional<TextRingBuffers::Data> Butler::get_closed_caption () { @@ -279,6 +286,7 @@ Butler::get_closed_caption () return _closed_caption.get (); } + void Butler::seek (DCPTime position, bool accurate) { @@ -287,6 +295,7 @@ Butler::seek (DCPTime position, bool accurate) seek_unlocked (position, accurate); } + void Butler::seek_unlocked (DCPTime position, bool accurate) { @@ -305,6 +314,7 @@ Butler::seek_unlocked (DCPTime position, bool accurate) _summon.notify_all (); } + void Butler::prepare (weak_ptr<PlayerVideo> weak_video) try @@ -331,6 +341,7 @@ catch (...) _died = true; } + void Butler::video (shared_ptr<PlayerVideo> video, DCPTime time) { @@ -341,11 +352,12 @@ Butler::video (shared_ptr<PlayerVideo> video, DCPTime time) return; } - _prepare_service.post (bind (&Butler::prepare, this, weak_ptr<PlayerVideo>(video))); + _prepare_service.post (bind(&Butler::prepare, this, weak_ptr<PlayerVideo>(video))); _video.put (video, time); } + void Butler::audio (shared_ptr<AudioBuffers> audio, DCPTime time, int frame_rate) { @@ -355,9 +367,10 @@ Butler::audio (shared_ptr<AudioBuffers> audio, DCPTime time, int frame_rate) return; } - _audio.put (remap (audio, _audio_channels, _audio_mapping), time, frame_rate); + _audio.put (remap(audio, _audio_channels, _audio_mapping), time, frame_rate); } + /** Try to get `frames' frames of audio and copy it into `out'. Silence * will be filled if no audio is available. * @return time of this audio, or unset if there was a buffer underrun. @@ -370,6 +383,7 @@ Butler::get_audio (float* out, Frame frames) return t; } + void Butler::disable_audio () { @@ -377,6 +391,7 @@ Butler::disable_audio () _disable_audio = true; } + pair<size_t, string> Butler::memory_used () const { @@ -384,6 +399,7 @@ Butler::memory_used () const return _video.memory_used(); } + void Butler::player_change (ChangeType type, int property) { @@ -430,6 +446,7 @@ Butler::player_change (ChangeType type, int property) _summon.notify_all (); } + void Butler::text (PlayerText pt, TextType type, optional<DCPTextTrack> track, DCPTimePeriod period) { @@ -442,6 +459,7 @@ Butler::text (PlayerText pt, TextType type, optional<DCPTextTrack> track, DCPTim _closed_caption.put (pt, *track, period); } + string Butler::Error::summary () const { diff --git a/src/lib/butler.h b/src/lib/butler.h index 29966b956..a231fd099 100644 --- a/src/lib/butler.h +++ b/src/lib/butler.h @@ -18,6 +18,7 @@ */ + #include "audio_mapping.h" #include "audio_ring_buffers.h" #include "change_signaller.h" @@ -29,9 +30,11 @@ #include <boost/thread.hpp> #include <boost/thread/condition.hpp> + class Player; class PlayerVideo; + class Butler : public ExceptionStore { public: diff --git a/src/lib/case_insensitive_sorter.cc b/src/lib/case_insensitive_sorter.cc index c26f1e642..4bf3c2d18 100644 --- a/src/lib/case_insensitive_sorter.cc +++ b/src/lib/case_insensitive_sorter.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,17 +18,19 @@ */ + #include "case_insensitive_sorter.h" #include <boost/filesystem.hpp> -#include <iostream> + using std::string; + bool CaseInsensitiveSorter::operator() (boost::filesystem::path a, boost::filesystem::path b) { - string x = a.string (); - string y = b.string (); + auto x = a.string(); + auto y = b.string(); transform (x.begin(), x.end(), x.begin(), ::tolower); transform (y.begin(), y.end(), y.begin(), ::tolower); return x < y; diff --git a/src/lib/case_insensitive_sorter.h b/src/lib/case_insensitive_sorter.h index 28bd28ee8..7f8186072 100644 --- a/src/lib/case_insensitive_sorter.h +++ b/src/lib/case_insensitive_sorter.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include <boost/filesystem.hpp> + class CaseInsensitiveSorter { public: diff --git a/src/lib/content_part.h b/src/lib/content_part.h index 443c356b1..590be3112 100644 --- a/src/lib/content_part.h +++ b/src/lib/content_part.h @@ -1,6 +1,5 @@ - /* - Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -19,16 +18,20 @@ */ + #ifndef DCPOMATIC_CONTENT_PART_H #define DCPOMATIC_CONTENT_PART_H -#include "content.h" + #include "change_signaller.h" +#include "content.h" #include <boost/thread/mutex.hpp> + class Content; class Film; + class ContentPart { public: @@ -71,4 +74,5 @@ protected: mutable boost::mutex _mutex; }; + #endif diff --git a/src/lib/copy_dcp_details_to_film.cc b/src/lib/copy_dcp_details_to_film.cc index 3e62c96a3..5c3c79638 100644 --- a/src/lib/copy_dcp_details_to_film.cc +++ b/src/lib/copy_dcp_details_to_film.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/copy_dcp_details_to_film.h b/src/lib/copy_dcp_details_to_film.h index 1b5c05811..37507b8da 100644 --- a/src/lib/copy_dcp_details_to_film.h +++ b/src/lib/copy_dcp_details_to_film.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -25,4 +25,5 @@ class DCPContent; class Film; + extern void copy_dcp_details_to_film (std::shared_ptr<const DCPContent> dcp, std::shared_ptr<Film> film); diff --git a/src/lib/create_cli.cc b/src/lib/create_cli.cc index 819f17f6e..2258f8a2e 100644 --- a/src/lib/create_cli.cc +++ b/src/lib/create_cli.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,20 +18,22 @@ */ + +#include "compose.hpp" +#include "config.h" #include "create_cli.h" #include "dcp_content_type.h" #include "ratio.h" -#include "config.h" -#include "compose.hpp" #include <dcp/raw_convert.h> +#include <iostream> #include <string> -#include <iostream> using std::string; using std::cout; using boost::optional; + string CreateCLI::_help = "\nSyntax: %1 [OPTION] <CONTENT> [OPTION] [<CONTENT> ...]\n" " -v, --version show DCP-o-matic version\n" @@ -54,6 +56,7 @@ string CreateCLI::_help = " --left-eye next piece of content is for the left eye\n" " --right-eye next piece of content is for the right eye\n"; + template <class T> void argument_option (int& n, int argc, char* argv[], string short_name, string long_name, bool* claimed, optional<string>* error, T* out) @@ -72,6 +75,7 @@ argument_option (int& n, int argc, char* argv[], string short_name, string long_ *claimed = true; } + CreateCLI::CreateCLI (int argc, char* argv[]) : version (false) , encrypt (false) diff --git a/src/lib/create_cli.h b/src/lib/create_cli.h index 97e091056..3a06c64f8 100644 --- a/src/lib/create_cli.h +++ b/src/lib/create_cli.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,15 +18,18 @@ */ + #include "types.h" #include <dcp/types.h> #include <boost/optional.hpp> #include <boost/filesystem.hpp> #include <vector> + class DCPContentType; class Ratio; + class CreateCLI { public: diff --git a/src/lib/cross_osx.cc b/src/lib/cross_osx.cc index 58ec8e3c4..b9b7796a2 100644 --- a/src/lib/cross_osx.cc +++ b/src/lib/cross_osx.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "cross.h" #include "compose.hpp" #include "log.h" @@ -52,6 +53,7 @@ extern "C" { #include "i18n.h" + using std::pair; using std::list; using std::ifstream; @@ -67,6 +69,7 @@ using std::shared_ptr; using boost::optional; using std::function; + /** @param s Number of seconds to sleep for */ void dcpomatic_sleep_seconds (int s) @@ -74,12 +77,14 @@ dcpomatic_sleep_seconds (int s) sleep (s); } + void dcpomatic_sleep_milliseconds (int ms) { usleep (ms * 1000); } + /** @return A string of CPU information (model name etc.) */ string cpu_info () @@ -88,7 +93,7 @@ cpu_info () char buffer[64]; size_t N = sizeof (buffer); - if (sysctlbyname ("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) { + if (sysctlbyname("machdep.cpu.brand_string", buffer, &N, 0, 0) == 0) { info = buffer; } @@ -127,7 +132,7 @@ tags_path () void run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) { - boost::filesystem::path path = directory_containing_executable () / "ffprobe"; + auto path = directory_containing_executable () / "ffprobe"; string ffprobe = "\"" + path.string() + "\" \"" + content.string() + "\" 2> \"" + out.string() + "\""; LOG_GENERAL (N_("Probing with %1"), ffprobe); @@ -135,13 +140,14 @@ run_ffprobe (boost::filesystem::path content, boost::filesystem::path out) } -list<pair<string, string> > + +list<pair<string, string>> mount_info () { - list<pair<string, string> > m; - return m; + return {}; } + boost::filesystem::path openssl_path () { @@ -158,6 +164,7 @@ disk_writer_path () } #endif + /* Apparently there is no way to create an ofstream using a UTF-8 filename under Windows. We are hence reduced to using fopen with this wrapper. @@ -165,40 +172,45 @@ disk_writer_path () FILE * fopen_boost (boost::filesystem::path p, string t) { - return fopen (p.c_str(), t.c_str ()); + return fopen (p.c_str(), t.c_str()); } + int dcpomatic_fseek (FILE* stream, int64_t offset, int whence) { return fseek (stream, offset, whence); } + void Waker::nudge () { } + Waker::Waker () { boost::mutex::scoped_lock lm (_mutex); IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn, CFSTR ("Encoding DCP"), &_assertion_id); } + Waker::~Waker () { boost::mutex::scoped_lock lm (_mutex); IOPMAssertionRelease (_assertion_id); } + void start_tool (string executable, string app) { - boost::filesystem::path exe_path = directory_containing_executable(); - exe_path = exe_path.parent_path (); // Contents - exe_path = exe_path.parent_path (); // DCP-o-matic 2.app - exe_path = exe_path.parent_path (); // Applications + auto exe_path = directory_containing_executable(); + exe_path = exe_path.parent_path(); // Contents + exe_path = exe_path.parent_path(); // DCP-o-matic 2.app + exe_path = exe_path.parent_path(); // Applications exe_path /= app; exe_path /= "Contents"; exe_path /= "MacOS"; @@ -235,18 +247,21 @@ thread_id () return (uint64_t) pthread_self (); } + int avio_open_boost (AVIOContext** s, boost::filesystem::path file, int flags) { return avio_open (s, file.c_str(), flags); } + boost::filesystem::path home_directory () { - return getenv("HOME"); + return getenv("HOME"); } + /** @return true if this process is a 32-bit one running on a 64-bit-capable OS */ bool running_32_on_64 () @@ -255,6 +270,7 @@ running_32_on_64 () return false; } + static optional<string> get_vendor (CFDictionaryRef& description) { @@ -273,6 +289,7 @@ get_vendor (CFDictionaryRef& description) return s; } + static optional<string> get_model (CFDictionaryRef& description) { @@ -291,12 +308,14 @@ get_model (CFDictionaryRef& description) return s; } + struct MediaPath { bool real; ///< true for a "real" disk, false for a synthesized APFS one std::string prt; ///< "PRT" entry from the media path }; + static optional<MediaPath> analyse_media_path (CFDictionaryRef& description) { @@ -343,6 +362,7 @@ analyse_media_path (CFDictionaryRef& description) return mp; } + static bool is_whole_drive (DADiskRef& disk) { @@ -357,6 +377,7 @@ is_whole_drive (DADiskRef& disk) return whole_media; } + static optional<boost::filesystem::path> mount_point (CFDictionaryRef& description) { @@ -372,6 +393,7 @@ mount_point (CFDictionaryRef& description) return boost::filesystem::path(mount_path_buffer); } + /* Here follows some rather intricate and (probably) fragile code to find the list of available * "real" drives on macOS that we might want to write a DCP to. * @@ -408,6 +430,7 @@ struct Disk unsigned long size; }; + static void disk_appeared (DADiskRef disk, void* context) { @@ -463,19 +486,20 @@ disk_appeared (DADiskRef disk, void* context) reinterpret_cast<vector<Disk>*>(context)->push_back(this_disk); } + vector<Drive> Drive::get () { using namespace boost::algorithm; vector<Disk> disks; - DASessionRef session = DASessionCreate(kCFAllocatorDefault); + auto session = DASessionCreate(kCFAllocatorDefault); if (!session) { return {}; } DARegisterDiskAppearedCallback (session, NULL, disk_appeared, &disks); - CFRunLoopRef run_loop = CFRunLoopGetCurrent (); + auto run_loop = CFRunLoopGetCurrent (); DASessionScheduleWithRunLoop (session, run_loop, kCFRunLoopDefaultMode); CFRunLoopStop (run_loop); CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.05, 0); @@ -496,7 +520,7 @@ Drive::get () } /* Make a map of the PRT codes and mount points of mounted, synthesized disks */ - map<string, vector<boost::filesystem::path> > mounted_synths; + map<string, vector<boost::filesystem::path>> mounted_synths; for (auto& i: disks) { if (!i.real && !i.mount_points.empty()) { LOG_DISK("Found a mounted synth %1 with %2", i.mount_point, i.prt); @@ -559,12 +583,12 @@ Drive::unmount () { LOG_DISK_NC("Unmount operation started"); - DASessionRef session = DASessionCreate(kCFAllocatorDefault); + auto session = DASessionCreate(kCFAllocatorDefault); if (!session) { return false; } - DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, _device.c_str()); + auto disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, _device.c_str()); if (!disk) { return false; } diff --git a/src/lib/crypto.cc b/src/lib/crypto.cc index 494924daa..777969c10 100644 --- a/src/lib/crypto.cc +++ b/src/lib/crypto.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + /* Based on code from https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption */ + #include "crypto.h" #include "exceptions.h" #include <openssl/conf.h> @@ -28,12 +30,15 @@ #include <openssl/rand.h> #include <boost/scoped_array.hpp> + using std::string; using namespace dcpomatic; + /** The cipher that this code uses */ #define CIPHER EVP_aes_256_cbc() + dcp::ArrayData dcpomatic::random_iv () { @@ -43,10 +48,11 @@ dcpomatic::random_iv () return iv; } + dcp::ArrayData dcpomatic::encrypt (string plaintext, dcp::ArrayData key, dcp::ArrayData iv) { - EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new (); + auto ctx = EVP_CIPHER_CTX_new (); if (!ctx) { throw CryptoError ("could not create cipher context"); } @@ -78,10 +84,11 @@ dcpomatic::encrypt (string plaintext, dcp::ArrayData key, dcp::ArrayData iv) return ciphertext; } + string dcpomatic::decrypt (dcp::ArrayData ciphertext, dcp::ArrayData key, dcp::ArrayData iv) { - EVP_CIPHER_CTX* ctx = EVP_CIPHER_CTX_new (); + auto ctx = EVP_CIPHER_CTX_new (); if (!ctx) { throw CryptoError ("could not create cipher context"); } @@ -115,6 +122,7 @@ dcpomatic::decrypt (dcp::ArrayData ciphertext, dcp::ArrayData key, dcp::ArrayDat return string ((char *) plaintext.data()); } + int dcpomatic::crypto_key_length () { diff --git a/src/lib/crypto.h b/src/lib/crypto.h index ee0ff9b55..41a93010d 100644 --- a/src/lib/crypto.h +++ b/src/lib/crypto.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,14 +18,18 @@ */ + #include <dcp/array_data.h> + namespace dcpomatic { + dcp::ArrayData random_iv (); dcp::ArrayData encrypt (std::string plaintext, dcp::ArrayData key, dcp::ArrayData iv); std::string decrypt (dcp::ArrayData ciphertext, dcp::ArrayData key, dcp::ArrayData iv); int crypto_key_length (); + } diff --git a/src/lib/curl_uploader.cc b/src/lib/curl_uploader.cc index 82dca98f8..60835bea7 100644 --- a/src/lib/curl_uploader.cc +++ b/src/lib/curl_uploader.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "curl_uploader.h" #include "exceptions.h" #include "config.h" @@ -27,10 +28,12 @@ #include "i18n.h" + using std::string; using std::cout; using std::function; + static size_t read_callback (void* ptr, size_t size, size_t nmemb, void* object) { @@ -38,11 +41,9 @@ read_callback (void* ptr, size_t size, size_t nmemb, void* object) return u->read_callback (ptr, size, nmemb); } + CurlUploader::CurlUploader (function<void (string)> set_status, function<void (float)> set_progress) : Uploader (set_status, set_progress) - , _file (0) - , _transferred (0) - , _total_size (0) { _curl = curl_easy_init (); if (!_curl) { @@ -54,10 +55,11 @@ CurlUploader::CurlUploader (function<void (string)> set_status, function<void (f curl_easy_setopt (_curl, CURLOPT_UPLOAD, 1L); curl_easy_setopt (_curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1L); curl_easy_setopt (_curl, CURLOPT_READDATA, this); - curl_easy_setopt (_curl, CURLOPT_USERNAME, Config::instance()->tms_user().c_str ()); - curl_easy_setopt (_curl, CURLOPT_PASSWORD, Config::instance()->tms_password().c_str ()); + curl_easy_setopt (_curl, CURLOPT_USERNAME, Config::instance()->tms_user().c_str()); + curl_easy_setopt (_curl, CURLOPT_PASSWORD, Config::instance()->tms_password().c_str()); } + CurlUploader::~CurlUploader () { if (_file) { @@ -66,12 +68,14 @@ CurlUploader::~CurlUploader () curl_easy_cleanup (_curl); } + void CurlUploader::create_directory (boost::filesystem::path) { /* this is done by libcurl */ } + void CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path to, boost::uintmax_t& transferred, boost::uintmax_t total_size) { @@ -88,7 +92,7 @@ CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path _transferred = &transferred; _total_size = total_size; - CURLcode const r = curl_easy_perform (_curl); + auto const r = curl_easy_perform (_curl); if (r != CURLE_OK) { throw NetworkError (String::compose (_("Could not write to remote file (%1)"), curl_easy_strerror (r))); } @@ -97,6 +101,7 @@ CurlUploader::upload_file (boost::filesystem::path from, boost::filesystem::path _file = 0; } + size_t CurlUploader::read_callback (void* ptr, size_t size, size_t nmemb) { diff --git a/src/lib/curl_uploader.h b/src/lib/curl_uploader.h index 14cbce363..a3ef3cb22 100644 --- a/src/lib/curl_uploader.h +++ b/src/lib/curl_uploader.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #include "uploader.h" #include <curl/curl.h> + class CurlUploader : public Uploader { public: @@ -36,7 +38,7 @@ protected: private: CURL* _curl; - FILE* _file; - boost::uintmax_t* _transferred; - boost::uintmax_t _total_size; + FILE* _file = nullptr; + boost::uintmax_t* _transferred = nullptr; + boost::uintmax_t _total_size = 0; }; diff --git a/src/lib/datasat_ap2x.cc b/src/lib/datasat_ap2x.cc index ade750ce1..bfebd5fb3 100644 --- a/src/lib/datasat_ap2x.cc +++ b/src/lib/datasat_ap2x.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,10 +18,12 @@ */ + #include "datasat_ap2x.h" #include "i18n.h" + DatasatAP2x::DatasatAP2x () : CinemaSoundProcessor ("dataset_ap2x", _("Datasat AP20 or AP25"), 3.2f, 20, 5) { diff --git a/src/lib/datasat_ap2x.h b/src/lib/datasat_ap2x.h index 4bbe39521..3fbaad1dc 100644 --- a/src/lib/datasat_ap2x.h +++ b/src/lib/datasat_ap2x.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,12 +18,15 @@ */ + /** @file src/lib/datasat_ap2x.h * @brief DatasatAP2x class. */ + #include "cinema_sound_processor.h" + class DatasatAP2x : public CinemaSoundProcessor { public: diff --git a/src/lib/dcp_content_type.cc b/src/lib/dcp_content_type.cc index e1b05852c..6d7286a48 100644 --- a/src/lib/dcp_content_type.cc +++ b/src/lib/dcp_content_type.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -27,10 +27,14 @@ #include "i18n.h" + +using boost::optional; using namespace std; + vector<DCPContentType const *> DCPContentType::_dcp_content_types; + DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d) : _pretty_name (p) , _libdcp_kind (k) @@ -39,23 +43,27 @@ DCPContentType::DCPContentType (string p, dcp::ContentKind k, string d) } + void DCPContentType::setup_dcp_content_types () { - _dcp_content_types.push_back (new DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR"))); - _dcp_content_types.push_back (new DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR"))); - _dcp_content_types.push_back (new DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR"))); - _dcp_content_types.push_back (new DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST"))); - _dcp_content_types.push_back (new DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN"))); - _dcp_content_types.push_back (new DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG"))); - _dcp_content_types.push_back (new DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR"))); - _dcp_content_types.push_back (new DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL"))); - _dcp_content_types.push_back (new DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA"))); - _dcp_content_types.push_back (new DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV"))); - _dcp_content_types.push_back (new DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS"))); - _dcp_content_types.push_back (new DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO"))); + _dcp_content_types = { + new DCPContentType(_("Feature"), dcp::ContentKind::FEATURE, N_("FTR")), + new DCPContentType(_("Short"), dcp::ContentKind::SHORT, N_("SHR")), + new DCPContentType(_("Trailer"), dcp::ContentKind::TRAILER, N_("TLR")), + new DCPContentType(_("Test"), dcp::ContentKind::TEST, N_("TST")), + new DCPContentType(_("Transitional"), dcp::ContentKind::TRANSITIONAL, N_("XSN")), + new DCPContentType(_("Rating"), dcp::ContentKind::RATING, N_("RTG")), + new DCPContentType(_("Teaser"), dcp::ContentKind::TEASER, N_("TSR")), + new DCPContentType(_("Policy"), dcp::ContentKind::POLICY, N_("POL")), + new DCPContentType(_("Public Service Announcement"), dcp::ContentKind::PUBLIC_SERVICE_ANNOUNCEMENT, N_("PSA")), + new DCPContentType(_("Advertisement"), dcp::ContentKind::ADVERTISEMENT, N_("ADV")), + new DCPContentType(_("Episode"), dcp::ContentKind::EPISODE, N_("EPS")), + new DCPContentType(_("Promo"), dcp::ContentKind::PROMO, N_("PRO")) + }; } + DCPContentType const * DCPContentType::from_isdcf_name (string n) { @@ -68,6 +76,7 @@ DCPContentType::from_isdcf_name (string n) return 0; } + DCPContentType const * DCPContentType::from_libdcp_kind (dcp::ContentKind kind) { @@ -78,18 +87,19 @@ DCPContentType::from_libdcp_kind (dcp::ContentKind kind) } DCPOMATIC_ASSERT (false); - return 0; + return nullptr; } DCPContentType const * DCPContentType::from_index (int n) { - DCPOMATIC_ASSERT (n >= 0 && n < int (_dcp_content_types.size ())); + DCPOMATIC_ASSERT (n >= 0 && n < int(_dcp_content_types.size())); return _dcp_content_types[n]; } -int + +optional<int> DCPContentType::as_index (DCPContentType const * c) { vector<DCPContentType*>::size_type i = 0; @@ -97,13 +107,14 @@ DCPContentType::as_index (DCPContentType const * c) ++i; } - if (i == _dcp_content_types.size ()) { - return -1; + if (i == _dcp_content_types.size()) { + return {}; } return i; } + vector<DCPContentType const *> DCPContentType::all () { diff --git a/src/lib/dcp_content_type.h b/src/lib/dcp_content_type.h index f45bbb9f8..03a52e57c 100644 --- a/src/lib/dcp_content_type.h +++ b/src/lib/dcp_content_type.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -60,7 +60,7 @@ public: static DCPContentType const * from_isdcf_name (std::string); static DCPContentType const * from_libdcp_kind (dcp::ContentKind); static DCPContentType const * from_index (int); - static int as_index (DCPContentType const *); + static boost::optional<int> as_index (DCPContentType const *); static std::vector<DCPContentType const *> all (); static void setup_dcp_content_types (); diff --git a/src/lib/dkdm_recipient.cc b/src/lib/dkdm_recipient.cc index 8704f627a..30c307569 100644 --- a/src/lib/dkdm_recipient.cc +++ b/src/lib/dkdm_recipient.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,15 +18,17 @@ */ + #include "dkdm_recipient.h" #include "kdm_with_metadata.h" #include "film.h" #include <dcp/raw_convert.h> +using std::make_shared; +using std::shared_ptr; using std::string; using std::vector; -using std::shared_ptr; using dcp::raw_convert; @@ -72,7 +74,7 @@ kdm_for_dkdm_recipient ( dcp::LocalTime const begin(valid_from, recipient->utc_offset_hour, recipient->utc_offset_minute); dcp::LocalTime const end (valid_to, recipient->utc_offset_hour, recipient->utc_offset_minute); - dcp::EncryptedKDM const kdm = film->make_kdm ( + auto const kdm = film->make_kdm ( recipient->recipient.get(), vector<string>(), cpl, @@ -89,6 +91,6 @@ kdm_for_dkdm_recipient ( name_values['e'] = end.date() + " " + end.time_of_day(true, false); name_values['i'] = kdm.cpl_id(); - return KDMWithMetadataPtr(new KDMWithMetadata(name_values, 0, recipient->emails, kdm)); + return make_shared<KDMWithMetadata>(name_values, nullptr, recipient->emails, kdm); } diff --git a/src/lib/dkdm_recipient.h b/src/lib/dkdm_recipient.h index 7cf59a495..d08f82daa 100644 --- a/src/lib/dkdm_recipient.h +++ b/src/lib/dkdm_recipient.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,11 +18,14 @@ */ + #include "kdm_recipient.h" #include "kdm_with_metadata.h" + class Film; + class DKDMRecipient : public KDMRecipient { public: diff --git a/src/lib/emailer.cc b/src/lib/emailer.cc index 8a061738b..6ef23c3e0 100644 --- a/src/lib/emailer.cc +++ b/src/lib/emailer.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "compose.hpp" #include "config.h" #include "emailer.h" @@ -28,14 +29,16 @@ #include "i18n.h" -using std::string; -using std::min; -using std::list; + using std::cout; +using std::list; +using std::min; using std::pair; using std::shared_ptr; +using std::string; using dcp::ArrayData; + Emailer::Emailer (string from, list<string> to, string subject, string body) : _from (from) , _to (to) @@ -46,6 +49,7 @@ Emailer::Emailer (string from, list<string> to, string subject, string body) } + string Emailer::fix (string s) const { @@ -54,18 +58,21 @@ Emailer::fix (string s) const return s; } + void Emailer::add_cc (string cc) { _cc.push_back (cc); } + void Emailer::add_bcc (string bcc) { _bcc.push_back (bcc); } + void Emailer::add_attachment (boost::filesystem::path file, string name, string mime_type) { @@ -76,18 +83,21 @@ Emailer::add_attachment (boost::filesystem::path file, string name, string mime_ _attachments.push_back (a); } + static size_t curl_data_shim (void* ptr, size_t size, size_t nmemb, void* userp) { return reinterpret_cast<Emailer*>(userp)->get_data (ptr, size, nmemb); } + static int curl_debug_shim (CURL* curl, curl_infotype type, char* data, size_t size, void* userp) { return reinterpret_cast<Emailer*>(userp)->debug (curl, type, data, size); } + size_t Emailer::get_data (void* ptr, size_t size, size_t nmemb) { @@ -97,28 +107,29 @@ Emailer::get_data (void* ptr, size_t size, size_t nmemb) return t; } + void Emailer::send (string server, int port, EmailProtocol protocol, string user, string password) { char date_buffer[128]; time_t now = time (0); - strftime (date_buffer, sizeof(date_buffer), "%a, %d %b %Y %H:%M:%S ", localtime (&now)); + strftime (date_buffer, sizeof(date_buffer), "%a, %d %b %Y %H:%M:%S ", localtime(&now)); - boost::posix_time::ptime const utc_now = boost::posix_time::second_clock::universal_time (); - boost::posix_time::ptime const local_now = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local (utc_now); - boost::posix_time::time_duration offset = local_now - utc_now; + auto const utc_now = boost::posix_time::second_clock::universal_time (); + auto const local_now = boost::date_time::c_local_adjustor<boost::posix_time::ptime>::utc_to_local (utc_now); + auto offset = local_now - utc_now; sprintf (date_buffer + strlen(date_buffer), "%s%02d%02d", (offset.hours() >= 0 ? "+" : "-"), int(abs(offset.hours())), int(offset.minutes())); _email = "Date: " + string(date_buffer) + "\r\n" "To: " + address_list (_to) + "\r\n" "From: " + _from + "\r\n"; - if (!_cc.empty ()) { - _email += "Cc: " + address_list (_cc) + "\r\n"; + if (!_cc.empty()) { + _email += "Cc: " + address_list(_cc) + "\r\n"; } - if (!_bcc.empty ()) { - _email += "Bcc: " + address_list (_bcc) + "\r\n"; + if (!_bcc.empty()) { + _email += "Bcc: " + address_list(_bcc) + "\r\n"; } string const chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; @@ -149,9 +160,9 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str "Content-Transfer-Encoding: Base64\r\n" "Content-Disposition: attachment; filename=" + i.name + "\r\n\r\n"; - BIO* b64 = BIO_new (BIO_f_base64()); + auto b64 = BIO_new (BIO_f_base64()); - BIO* bio = BIO_new (BIO_s_mem()); + auto bio = BIO_new (BIO_s_mem()); bio = BIO_push (b64, bio); ArrayData data (i.file); @@ -171,7 +182,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str curl_global_init (CURL_GLOBAL_DEFAULT); - CURL* curl = curl_easy_init (); + auto curl = curl_easy_init (); if (!curl) { throw NetworkError ("Could not initialise libcurl"); } @@ -192,7 +203,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str curl_easy_setopt (curl, CURLOPT_MAIL_FROM, _from.c_str()); - struct curl_slist* recipients = 0; + struct curl_slist* recipients = nullptr; for (auto i: _to) { recipients = curl_slist_append (recipients, i.c_str()); } @@ -218,7 +229,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str curl_easy_setopt (curl, CURLOPT_DEBUGFUNCTION, curl_debug_shim); curl_easy_setopt (curl, CURLOPT_DEBUGDATA, this); - CURLcode const r = curl_easy_perform (curl); + auto const r = curl_easy_perform (curl); if (r != CURLE_OK) { throw KDMError (_("Failed to send email"), curl_easy_strerror (r)); } @@ -228,6 +239,7 @@ Emailer::send (string server, int port, EmailProtocol protocol, string user, str curl_global_cleanup (); } + string Emailer::address_list (list<string> addresses) { @@ -239,6 +251,7 @@ Emailer::address_list (list<string> addresses) return o.substr (0, o.length() - 2); } + int Emailer::debug (CURL *, curl_infotype type, char* data, size_t size) { diff --git a/src/lib/emailer.h b/src/lib/emailer.h index 4ceedb9be..fa278e535 100644 --- a/src/lib/emailer.h +++ b/src/lib/emailer.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #include <curl/curl.h> #include <boost/scoped_array.hpp> + class Emailer { public: diff --git a/src/lib/encode_server_finder.cc b/src/lib/encode_server_finder.cc index 2fab210c9..6faab0e63 100644 --- a/src/lib/encode_server_finder.cc +++ b/src/lib/encode_server_finder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "encode_server_finder.h" #include "exceptions.h" #include "util.h" @@ -33,27 +34,32 @@ #include "i18n.h" -using std::string; -using std::list; -using std::vector; + using std::cout; +using std::list; +using std::make_shared; using std::shared_ptr; -using boost::scoped_array; +using std::string; +using std::vector; using std::weak_ptr; using boost::optional; +using boost::scoped_array; #if BOOST_VERSION >= 106100 using namespace boost::placeholders; #endif using dcp::raw_convert; + EncodeServerFinder* EncodeServerFinder::_instance = 0; + EncodeServerFinder::EncodeServerFinder () : _stop (false) { Config::instance()->Changed.connect (boost::bind (&EncodeServerFinder::config_changed, this, _1)); } + void EncodeServerFinder::start () { @@ -71,6 +77,7 @@ EncodeServerFinder::~EncodeServerFinder () stop (); } + void EncodeServerFinder::stop () { @@ -92,6 +99,7 @@ EncodeServerFinder::stop () _servers.clear (); } + void EncodeServerFinder::search_thread () try @@ -106,18 +114,18 @@ try throw NetworkError ("failed to set up broadcast socket"); } - socket.set_option (boost::asio::ip::udp::socket::reuse_address (true)); - socket.set_option (boost::asio::socket_base::broadcast (true)); + socket.set_option (boost::asio::ip::udp::socket::reuse_address(true)); + socket.set_option (boost::asio::socket_base::broadcast(true)); string const data = DCPOMATIC_HELLO; int const interval = 10; while (!_stop) { - if (Config::instance()->use_any_servers ()) { + if (Config::instance()->use_any_servers()) { /* Broadcast to look for servers */ try { boost::asio::ip::udp::endpoint end_point (boost::asio::ip::address_v4::broadcast(), HELLO_PORT); - socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point); + socket.send_to (boost::asio::buffer(data.c_str(), data.size() + 1), end_point); } catch (...) { } @@ -127,9 +135,9 @@ try for (auto const& i: Config::instance()->servers()) { try { boost::asio::ip::udp::resolver resolver (io_service); - boost::asio::ip::udp::resolver::query query (i, raw_convert<string> (HELLO_PORT)); - boost::asio::ip::udp::endpoint end_point (*resolver.resolve (query)); - socket.send_to (boost::asio::buffer (data.c_str(), data.size() + 1), end_point); + boost::asio::ip::udp::resolver::query query (i, raw_convert<string>(HELLO_PORT)); + boost::asio::ip::udp::endpoint end_point (*resolver.resolve(query)); + socket.send_to (boost::asio::buffer(data.c_str(), data.size() + 1), end_point); } catch (...) { } @@ -140,10 +148,10 @@ try { boost::mutex::scoped_lock lm (_servers_mutex); - list<EncodeServerDescription>::iterator i = _servers.begin(); + auto i = _servers.begin(); while (i != _servers.end()) { if (i->last_seen_seconds() > 2 * interval) { - list<EncodeServerDescription>::iterator j = i; + auto j = i; ++j; _servers.erase (i); i = j; @@ -155,11 +163,11 @@ try } if (removed) { - emit (boost::bind (boost::ref (ServersListChanged))); + emit (boost::bind(boost::ref(ServersListChanged))); } boost::mutex::scoped_lock lm (_search_condition_mutex); - _search_condition.timed_wait (lm, boost::get_system_time() + boost::posix_time::seconds (interval)); + _search_condition.timed_wait (lm, boost::get_system_time() + boost::posix_time::seconds(interval)); } } catch (...) @@ -167,6 +175,7 @@ catch (...) store_current (); } + void EncodeServerFinder::listen_thread () try { @@ -176,7 +185,7 @@ try { try { _listen_acceptor.reset ( - new tcp::acceptor (_listen_io_service, tcp::endpoint (tcp::v4(), is_batch_converter ? BATCH_SERVER_PRESENCE_PORT : MAIN_SERVER_PRESENCE_PORT)) + new tcp::acceptor (_listen_io_service, tcp::endpoint(tcp::v4(), is_batch_converter ? BATCH_SERVER_PRESENCE_PORT : MAIN_SERVER_PRESENCE_PORT)) ); } catch (...) { boost::throw_exception (NetworkError (_("Could not listen for remote encode servers. Perhaps another instance of DCP-o-matic is running."))); @@ -190,16 +199,18 @@ catch (...) store_current (); } + void EncodeServerFinder::start_accept () { - shared_ptr<Socket> socket (new Socket ()); + auto socket = make_shared<Socket>(); _listen_acceptor->async_accept ( socket->socket(), - boost::bind (&EncodeServerFinder::handle_accept, this, boost::asio::placeholders::error, socket) + boost::bind(&EncodeServerFinder::handle_accept, this, boost::asio::placeholders::error, socket) ); } + void EncodeServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Socket> socket) { @@ -209,18 +220,18 @@ EncodeServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Sock } uint32_t length; - socket->read (reinterpret_cast<uint8_t*> (&length), sizeof (uint32_t)); + socket->read (reinterpret_cast<uint8_t*>(&length), sizeof(uint32_t)); length = ntohl (length); - scoped_array<char> buffer (new char[length]); - socket->read (reinterpret_cast<uint8_t*> (buffer.get()), length); + scoped_array<char> buffer(new char[length]); + socket->read (reinterpret_cast<uint8_t*>(buffer.get()), length); string s (buffer.get()); - shared_ptr<cxml::Document> xml (new cxml::Document ("ServerAvailable")); + auto xml = make_shared<cxml::Document>("ServerAvailable"); xml->read_string (s); - string const ip = socket->socket().remote_endpoint().address().to_string (); - optional<list<EncodeServerDescription>::iterator> found = server_found (ip); + auto const ip = socket->socket().remote_endpoint().address().to_string(); + auto found = server_found (ip); if (found) { (*found)->set_seen (); } else { @@ -229,17 +240,18 @@ EncodeServerFinder::handle_accept (boost::system::error_code ec, shared_ptr<Sock boost::mutex::scoped_lock lm (_servers_mutex); _servers.push_back (sd); } - emit (boost::bind (boost::ref (ServersListChanged))); + emit (boost::bind(boost::ref (ServersListChanged))); } start_accept (); } + optional<list<EncodeServerDescription>::iterator> EncodeServerFinder::server_found (string ip) { boost::mutex::scoped_lock lm (_servers_mutex); - list<EncodeServerDescription>::iterator i = _servers.begin(); + auto i = _servers.begin(); while (i != _servers.end() && i->host_name() != ip) { ++i; } @@ -248,9 +260,10 @@ EncodeServerFinder::server_found (string ip) return i; } - return optional<list<EncodeServerDescription>::iterator>(); + return {}; } + EncodeServerFinder* EncodeServerFinder::instance () { @@ -262,13 +275,15 @@ EncodeServerFinder::instance () return _instance; } + void EncodeServerFinder::drop () { delete _instance; - _instance = 0; + _instance = nullptr; } + list<EncodeServerDescription> EncodeServerFinder::servers () const { @@ -276,6 +291,7 @@ EncodeServerFinder::servers () const return _servers; } + void EncodeServerFinder::config_changed (Config::Property what) { diff --git a/src/lib/encode_server_finder.h b/src/lib/encode_server_finder.h index a58c75382..533c9219b 100644 --- a/src/lib/encode_server_finder.h +++ b/src/lib/encode_server_finder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,19 +18,23 @@ */ + /** @file src/lib/encode_server_finder.h * @brief EncodeServerFinder class. */ -#include "signaller.h" -#include "encode_server_description.h" + #include "config.h" +#include "encode_server_description.h" #include "exception_store.h" +#include "signaller.h" #include <boost/signals2.hpp> #include <boost/thread/condition.hpp> + class Socket; + /** @class EncodeServerFinder * @brief Locater of encoding servers. * diff --git a/src/lib/encoded_log_entry.cc b/src/lib/encoded_log_entry.cc index 2da84dacd..4e1b98210 100644 --- a/src/lib/encoded_log_entry.cc +++ b/src/lib/encoded_log_entry.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,11 +18,14 @@ */ + #include "encoded_log_entry.h" #include <cstdio> + using std::string; + EncodedLogEntry::EncodedLogEntry (int frame, string ip, double receive, double encode, double send) : LogEntry (LogEntry::TYPE_GENERAL) , _frame (frame) @@ -34,6 +37,7 @@ EncodedLogEntry::EncodedLogEntry (int frame, string ip, double receive, double e } + string EncodedLogEntry::message () const { diff --git a/src/lib/encoded_log_entry.h b/src/lib/encoded_log_entry.h index 54eb9dfae..c4633dbe9 100644 --- a/src/lib/encoded_log_entry.h +++ b/src/lib/encoded_log_entry.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include "log_entry.h" + class EncodedLogEntry : public LogEntry { public: diff --git a/src/lib/event_history.cc b/src/lib/event_history.cc index efe80b243..fca88aaf1 100644 --- a/src/lib/event_history.cc +++ b/src/lib/event_history.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2017-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,24 +18,28 @@ */ + #include "event_history.h" #include "util.h" #include <boost/thread/mutex.hpp> + using boost::optional; + EventHistory::EventHistory (int size) : _size (size) { } + optional<float> EventHistory::rate () const { boost::mutex::scoped_lock lock (_mutex); - if (int (_history.size()) < _size) { - return optional<float>(); + if (int(_history.size()) < _size) { + return {}; } struct timeval now; @@ -44,6 +48,7 @@ EventHistory::rate () const return _size / (seconds (now) - seconds (_history.back ())); } + void EventHistory::event () { @@ -52,7 +57,7 @@ EventHistory::event () struct timeval tv; gettimeofday (&tv, 0); _history.push_front (tv); - if (int (_history.size()) > _size) { + if (int(_history.size()) > _size) { _history.pop_back (); } } diff --git a/src/lib/event_history.h b/src/lib/event_history.h index 4670e7bfe..a98447f42 100644 --- a/src/lib/event_history.h +++ b/src/lib/event_history.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2017-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2017-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ + #ifndef DCPOMATIC_EVENT_HISTORY_H #define DCPOMATIC_EVENT_HISTORY_H + #include <boost/thread/mutex.hpp> #include <boost/optional.hpp> #include <list> + class EventHistory { public: @@ -44,4 +47,5 @@ private: int const _size; }; + #endif diff --git a/src/lib/exceptions.cc b/src/lib/exceptions.cc index 3991c57b9..9350430f9 100644 --- a/src/lib/exceptions.cc +++ b/src/lib/exceptions.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,15 +18,18 @@ */ + #include "exceptions.h" #include "compose.hpp" #include "i18n.h" + using std::string; using std::runtime_error; using boost::optional; + /** @param f File that we were trying to open */ OpenFileError::OpenFileError (boost::filesystem::path f, int error, Mode mode) : FileError ( @@ -41,6 +44,7 @@ OpenFileError::OpenFileError (boost::filesystem::path f, int error, Mode mode) } + FileNotFoundError::FileNotFoundError (boost::filesystem::path f) : runtime_error(String::compose("File %1 not found", f.string())) , _file (f) @@ -48,74 +52,86 @@ FileNotFoundError::FileNotFoundError (boost::filesystem::path f) } + ReadFileError::ReadFileError (boost::filesystem::path f, int e) - : FileError (String::compose (_("could not read from file %1 (%2)"), f.string(), strerror (e)), f) + : FileError (String::compose(_("could not read from file %1 (%2)"), f.string(), strerror(e)), f) { } + WriteFileError::WriteFileError (boost::filesystem::path f, int e) - : FileError (String::compose (_("could not write to file %1 (%2)"), f.string(), strerror (e)), f) + : FileError (String::compose(_("could not write to file %1 (%2)"), f.string(), strerror(e)), f) { } + MissingSettingError::MissingSettingError (string s) - : SettingError (s, String::compose (_("Missing required setting %1"), s)) + : SettingError (s, String::compose(_("Missing required setting %1"), s)) { } + PixelFormatError::PixelFormatError (string o, AVPixelFormat f) - : runtime_error (String::compose (_("Cannot handle pixel format %1 during %2"), (int) f, o)) + : runtime_error (String::compose(_("Cannot handle pixel format %1 during %2"), (int) f, o)) { } + TextSubtitleError::TextSubtitleError (string saw, string expecting, boost::filesystem::path f) - : FileError (String::compose (_("Error in subtitle file: saw %1 while expecting %2"), saw.empty() ? "[nothing]" : saw, expecting), f) + : FileError (String::compose(_("Error in subtitle file: saw %1 while expecting %2"), saw.empty() ? "[nothing]" : saw, expecting), f) { } + InvalidSignerError::InvalidSignerError () : runtime_error (_("The certificate chain for signing is invalid")) { } + InvalidSignerError::InvalidSignerError (string reason) - : runtime_error (String::compose (_("The certificate chain for signing is invalid (%1)"), reason)) + : runtime_error (String::compose(_("The certificate chain for signing is invalid (%1)"), reason)) { } + ProgrammingError::ProgrammingError (string file, int line, string message) - : runtime_error (String::compose (_("Programming error at %1:%2 %3"), file, line, message)) + : runtime_error (String::compose(_("Programming error at %1:%2 %3"), file, line, message)) { } + KDMAsContentError::KDMAsContentError () : runtime_error (_("This file is a KDM. KDMs should be added to DCP content by right-clicking the content and choosing \"Add KDM\".")) { } + KDMError::KDMError (string s, string d) - : runtime_error (String::compose ("%1 (%2)", s, d)) + : runtime_error (String::compose("%1 (%2)", s, d)) , _summary (s) , _detail (d) { } + GLError::GLError (char const * last, int e) : runtime_error (String::compose("%1 failed %2", last, e)) { } + CopyError::CopyError (string m, optional<int> n) : runtime_error (String::compose("%1%2", m, n ? String::compose(" (%1)", *n) : "")) , _message (m) @@ -124,12 +140,14 @@ CopyError::CopyError (string m, optional<int> n) } + CommunicationFailedError::CommunicationFailedError () : CopyError (_("Lost communication between main and writer processes")) { } + VerifyError::VerifyError (string m, int n) : runtime_error (String::compose("%1 (%2)", m, n)) , _message (m) diff --git a/src/lib/exceptions.h b/src/lib/exceptions.h index 5b7baf0e5..93be3999b 100644 --- a/src/lib/exceptions.h +++ b/src/lib/exceptions.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,21 +18,25 @@ */ + /** @file src/lib/exceptions.h * @brief Our exceptions. */ + #ifndef DCPOMATIC_EXCEPTIONS_H #define DCPOMATIC_EXCEPTIONS_H + #include "compose.hpp" extern "C" { #include <libavutil/pixfmt.h> } #include <boost/filesystem.hpp> #include <boost/optional.hpp> -#include <stdexcept> #include <cstring> +#include <stdexcept> + /** @class DecodeError * @brief A low-level problem with the decoder (possibly due to the nature @@ -45,15 +49,16 @@ public: : std::runtime_error (s) {} - explicit DecodeError (std::string function, std::string caller) + DecodeError (std::string function, std::string caller) : std::runtime_error (String::compose("%1 failed [%2", function, caller)) {} - explicit DecodeError (std::string function, std::string caller, int error) + DecodeError (std::string function, std::string caller, int error) : std::runtime_error (String::compose("%1 failed [%2] (%3)", function, caller, error)) {} }; + class CryptoError : public std::runtime_error { public: @@ -109,6 +114,7 @@ private: boost::filesystem::path _file; }; + class JoinError : public std::runtime_error { public: @@ -117,6 +123,7 @@ public: {} }; + /** @class OpenFileError. * @brief Indicates that some error occurred when trying to open a file. */ @@ -136,6 +143,7 @@ public: OpenFileError (boost::filesystem::path f, int error, Mode mode); }; + class FileNotFoundError : public std::runtime_error { public: @@ -152,6 +160,7 @@ private: boost::filesystem::path _file; }; + /** @class ReadFileError. * @brief Indicates that some error occurred when trying to read from a file */ @@ -164,6 +173,7 @@ public: ReadFileError (boost::filesystem::path f, int e = 0); }; + /** @class WriteFileError. * @brief Indicates that some error occurred when trying to write to a file */ @@ -176,6 +186,7 @@ public: WriteFileError (boost::filesystem::path f, int e); }; + /** @class SettingError. * @brief Indicates that something is wrong with a setting. */ @@ -201,6 +212,7 @@ private: std::string _setting; }; + /** @class MissingSettingError. * @brief Indicates that a Film is missing a setting that is required for some operation. */ @@ -211,6 +223,7 @@ public: explicit MissingSettingError (std::string s); }; + /** @class BadSettingError * @brief Indicates that a setting is bad in some way. */ @@ -225,6 +238,7 @@ public: {} }; + /** @class NetworkError * @brief Indicates some problem with communication on the network. */ @@ -236,6 +250,7 @@ public: {} }; + /** @class KDMError * @brief A problem with a KDM. */ @@ -258,6 +273,7 @@ private: std::string _detail; }; + /** @class PixelFormatError * @brief A problem with an unsupported pixel format. */ @@ -267,6 +283,7 @@ public: PixelFormatError (std::string o, AVPixelFormat f); }; + /** @class TextSubtitleError * @brief An error that occurs while parsing a TextSubtitleError file. */ @@ -276,6 +293,7 @@ public: TextSubtitleError (std::string, std::string, boost::filesystem::path); }; + class DCPError : public std::runtime_error { public: @@ -307,11 +325,13 @@ public: }; class ProgrammingError : public std::runtime_error + { public: ProgrammingError (std::string file, int line, std::string message = ""); }; + class TextEncodingError : public std::runtime_error { public: @@ -320,6 +340,7 @@ public: {} }; + class MetadataError : public std::runtime_error { public: @@ -328,6 +349,7 @@ public: {} }; + class OldFormatError : public std::runtime_error { public: @@ -336,18 +358,21 @@ public: {} }; + class KDMAsContentError : public std::runtime_error { public: KDMAsContentError (); }; + class GLError : public std::runtime_error { public: GLError (char const * last, int e); }; + /** @class CopyError * @brief An error which occurs when copying a DCP to a distribution drive. */ @@ -412,4 +437,5 @@ public: {} }; + #endif diff --git a/src/lib/file_log.cc b/src/lib/file_log.cc index 481624c2a..5cc9c5569 100644 --- a/src/lib/file_log.cc +++ b/src/lib/file_log.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "file_log.h" #include "cross.h" #include "config.h" @@ -25,11 +26,13 @@ #include <iostream> #include <cerrno> + using std::cout; using std::string; using std::max; using std::shared_ptr; + /** @param file Filename to write log to */ FileLog::FileLog (boost::filesystem::path file) : _file (file) @@ -37,25 +40,28 @@ FileLog::FileLog (boost::filesystem::path file) set_types (Config::instance()->log_types()); } + FileLog::FileLog (boost::filesystem::path file, int types) : _file (file) { set_types (types); } + void FileLog::do_log (shared_ptr<const LogEntry> entry) { - FILE* f = fopen_boost (_file, "a"); + auto f = fopen_boost (_file, "a"); if (!f) { cout << "(could not log to " << _file.string() << " error " << errno << "): " << entry->get() << "\n"; return; } - fprintf (f, "%s\n", entry->get().c_str ()); + fprintf (f, "%s\n", entry->get().c_str()); fclose (f); } + string FileLog::head_and_tail (int amount) const { @@ -70,14 +76,14 @@ FileLog::head_and_tail (int amount) const tail_amount = 0; } - FILE* f = fopen_boost (_file, "r"); + auto f = fopen_boost (_file, "r"); if (!f) { return ""; } string out; - char* buffer = new char[max(head_amount, tail_amount) + 1]; + auto buffer = new char[max(head_amount, tail_amount) + 1]; int N = fread (buffer, 1, head_amount, f); buffer[N] = '\0'; diff --git a/src/lib/file_log.h b/src/lib/file_log.h index 64e6a2505..d7667f799 100644 --- a/src/lib/file_log.h +++ b/src/lib/file_log.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include "log.h" + class FileLog : public Log { public: diff --git a/src/lib/filter.cc b/src/lib/filter.cc index 6869d26c9..1c1039065 100644 --- a/src/lib/filter.cc +++ b/src/lib/filter.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,10 +18,12 @@ */ + /** @file src/filter.cc * @brief A class to describe one of FFmpeg's video or audio filters. */ + #include "filter.h" extern "C" { #include <libavfilter/avfilter.h> @@ -30,10 +32,13 @@ extern "C" { #include "i18n.h" + using namespace std; + vector<Filter const *> Filter::_filters; + /** @param i Our id. * @param n User-visible name. * @param c User-visible category. @@ -48,6 +53,7 @@ Filter::Filter (string i, string n, string c, string f) } + /** @return All available filters */ vector<Filter const *> Filter::all () @@ -55,6 +61,7 @@ Filter::all () return _filters; } + /** Set up the static _filters vector; must be called before from_* * methods are used. */ @@ -80,6 +87,7 @@ Filter::setup_filters () maybe_add (N_("ow"), _("Overcomplete wavelet denoiser"), _("Noise reduction"), N_("mp=ow")); } + void Filter::maybe_add (string i, string n, string c, string f) { @@ -89,11 +97,12 @@ Filter::maybe_add (string i, string n, string c, string f) check_name = check_name.substr (0, end); } - if (avfilter_get_by_name (check_name.c_str())) { - _filters.push_back (new Filter (i, n, c, f)); + if (avfilter_get_by_name(check_name.c_str())) { + _filters.push_back (new Filter(i, n, c, f)); } } + /** @param filters Set of filters. * @return String to pass to FFmpeg for the video filters. */ @@ -112,19 +121,20 @@ Filter::ffmpeg_string (vector<Filter const *> const & filters) return ff; } + /** @param d Our id. * @return Corresponding Filter, or 0. */ Filter const * Filter::from_id (string d) { - vector<Filter const *>::iterator i = _filters.begin (); + auto i = _filters.begin (); while (i != _filters.end() && (*i)->id() != d) { ++i; } if (i == _filters.end ()) { - return 0; + return nullptr; } return *i; diff --git a/src/lib/filter.h b/src/lib/filter.h index 5fbfd9c23..3c2a49792 100644 --- a/src/lib/filter.h +++ b/src/lib/filter.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/font_data.cc b/src/lib/font_data.cc index f6a61f24a..830b2da34 100644 --- a/src/lib/font_data.cc +++ b/src/lib/font_data.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/font_data.h b/src/lib/font_data.h index 895493ce2..a3389af20 100644 --- a/src/lib/font_data.h +++ b/src/lib/font_data.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/frame_rate_change.cc b/src/lib/frame_rate_change.cc index 7b6d13892..a1ff2ae65 100644 --- a/src/lib/frame_rate_change.cc +++ b/src/lib/frame_rate_change.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "frame_rate_change.h" #include "types.h" #include "content.h" @@ -27,46 +28,28 @@ #include "i18n.h" + using std::string; using std::shared_ptr; -static bool -about_equal (double a, double b) -{ - return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON); -} FrameRateChange::FrameRateChange () - : source (24) - , dcp (24) - , skip (false) - , repeat (1) - , change_speed (false) - , speed_up (1) { } -FrameRateChange::FrameRateChange (double source_, int dcp_) - : skip (false) - , repeat (1) - , change_speed (false) -{ - construct (source_, dcp_); -} -void -FrameRateChange::construct (double source_, int dcp_) +FrameRateChange::FrameRateChange (double source_, int dcp_) { source = source_; dcp = dcp_; - if (fabs (source / 2.0 - dcp) < fabs (source - dcp)) { + if (fabs(source / 2.0 - dcp) < fabs(source - dcp)) { /* The difference between source and DCP frame rate will be lower (i.e. better) if we skip. */ skip = true; - } else if (fabs (source * 2 - dcp) < fabs (source - dcp)) { + } else if (fabs(source * 2 - dcp) < fabs(source - dcp)) { /* The difference between source and DCP frame rate would be better if we repeated each frame once; it may be better still if we repeated more than once. Work out the required repeat. @@ -75,23 +58,29 @@ FrameRateChange::construct (double source_, int dcp_) } speed_up = dcp / (source * factor()); + + auto about_equal = [](double a, double b) { + return (fabs (a - b) < VIDEO_FRAME_RATE_EPSILON); + }; + change_speed = !about_equal (speed_up, 1.0); } + FrameRateChange::FrameRateChange (shared_ptr<const Film> film, shared_ptr<const Content> content) - : skip (false) - , repeat (1) + : FrameRateChange (content->active_video_frame_rate(film), film->video_frame_rate()) { - construct (content->active_video_frame_rate(film), film->video_frame_rate()); + } + FrameRateChange::FrameRateChange (shared_ptr<const Film> film, Content const * content) - : skip (false) - , repeat (1) + : FrameRateChange (content->active_video_frame_rate(film), film->video_frame_rate()) { - construct (content->active_video_frame_rate(film), film->video_frame_rate()); + } + string FrameRateChange::description () const { diff --git a/src/lib/frame_rate_change.h b/src/lib/frame_rate_change.h index d7fed6dd0..c28342e92 100644 --- a/src/lib/frame_rate_change.h +++ b/src/lib/frame_rate_change.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #ifndef DCPOMATIC_FRAME_RATE_CHANGE_H #define DCPOMATIC_FRAME_RATE_CHANGE_H @@ -29,6 +30,7 @@ class Film; class Content; + class FrameRateChange { public: @@ -48,13 +50,13 @@ public: return repeat; } - double source; - int dcp; + double source = 24; + int dcp = 24; /** true to skip every other frame */ - bool skip; + bool skip = false; /** number of times to use each frame (e.g. 1 is normal, 2 means repeat each frame once, and so on) */ - int repeat; + int repeat = 1; /** true if this DCP will run its video faster or slower than the source * without taking into account `repeat' nor `skip'. * (e.g. change_speed will be true if @@ -64,17 +66,15 @@ public: * source is 15.00fps, DCP is 30fps * source is 12.50fps, DCP is 25fps) */ - bool change_speed; + bool change_speed = false; /** Amount by which the video is being sped-up in the DCP; e.g. for a * 24fps source in a 25fps DCP this would be 25/24. */ - double speed_up; + double speed_up = 1.0; std::string description () const; - -private: - void construct (double source_, int dcp_); }; + #endif diff --git a/src/lib/log_entry.cc b/src/lib/log_entry.cc index fc0305340..2980e438b 100644 --- a/src/lib/log_entry.cc +++ b/src/lib/log_entry.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,12 +18,14 @@ */ + #include "log_entry.h" #include <inttypes.h> #include <cstdio> #include "i18n.h" + int const LogEntry::TYPE_GENERAL = 0x001; int const LogEntry::TYPE_WARNING = 0x002; int const LogEntry::TYPE_ERROR = 0x004; @@ -36,21 +38,24 @@ int const LogEntry::TYPE_DISK = 0x100; int const LogEntry::TYPE_DEBUG_PLAYER = 0x200; int const LogEntry::TYPE_DEBUG_AUDIO_ANALYSIS = 0x400; + using std::string; + LogEntry::LogEntry (int type) : _type (type) { gettimeofday (&_time, 0); } + string LogEntry::get () const { string s; if (_type & TYPE_TIMING) { char buffer[64]; - snprintf (buffer, sizeof(buffer), "%" PRId64 ":%" PRId64 " ", static_cast<int64_t> (_time.tv_sec), static_cast<int64_t> (_time.tv_usec)); + snprintf (buffer, sizeof(buffer), "%" PRId64 ":%" PRId64 " ", static_cast<int64_t>(_time.tv_sec), static_cast<int64_t>(_time.tv_usec)); s += buffer; } else { char buffer[64]; @@ -73,6 +78,7 @@ LogEntry::get () const return s; } + double LogEntry::seconds () const { diff --git a/src/lib/log_entry.h b/src/lib/log_entry.h index a2eb5fbac..95c4e4f1f 100644 --- a/src/lib/log_entry.h +++ b/src/lib/log_entry.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,12 +18,15 @@ */ + #ifndef DCPOMATIC_LOG_ENTRY_H #define DCPOMATIC_LOG_ENTRY_H + #include <sys/time.h> #include <string> + class LogEntry { public: @@ -56,4 +59,5 @@ private: int _type; }; + #endif diff --git a/src/lib/mid_side_decoder.cc b/src/lib/mid_side_decoder.cc index eb87d245b..09b528c81 100644 --- a/src/lib/mid_side_decoder.cc +++ b/src/lib/mid_side_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,16 +18,20 @@ */ + #include "mid_side_decoder.h" #include "audio_buffers.h" #include "audio_mapping.h" #include "i18n.h" -using std::string; + +using std::make_shared; using std::min; -using std::vector; using std::shared_ptr; +using std::string; +using std::vector; + string MidSideDecoder::name () const @@ -35,33 +39,37 @@ MidSideDecoder::name () const return _("Mid-side decoder"); } + string MidSideDecoder::id () const { return N_("mid-side-decoder"); } + int MidSideDecoder::out_channels () const { return 3; } + shared_ptr<AudioProcessor> MidSideDecoder::clone (int) const { - return shared_ptr<AudioProcessor> (new MidSideDecoder ()); + return make_shared<MidSideDecoder>(); } + shared_ptr<AudioBuffers> MidSideDecoder::run (shared_ptr<const AudioBuffers> in, int channels) { int const N = min (channels, 3); - shared_ptr<AudioBuffers> out (new AudioBuffers (channels, in->frames ())); + auto out = make_shared<AudioBuffers>(channels, in->frames ()); for (int i = 0; i < in->frames(); ++i) { - float const left = in->data()[0][i]; - float const right = in->data()[1][i]; - float const mid = (left + right) / 2; + auto const left = in->data()[0][i]; + auto const right = in->data()[1][i]; + auto const mid = (left + right) / 2; if (N > 0) { out->data()[0][i] = left - mid; } @@ -80,21 +88,23 @@ MidSideDecoder::run (shared_ptr<const AudioBuffers> in, int channels) return out; } + void MidSideDecoder::make_audio_mapping_default (AudioMapping& mapping) const { /* Just map the first two input channels to our M/S */ mapping.make_zero (); - for (int i = 0; i < min (2, mapping.input_channels()); ++i) { + for (int i = 0; i < min(2, mapping.input_channels()); ++i) { mapping.set (i, i, 1); } } + vector<NamedChannel> MidSideDecoder::input_names () const { - vector<NamedChannel> n; - n.push_back (NamedChannel(_("Left"), 0)); - n.push_back (NamedChannel(_("Right"), 1)); - return n; + return { + NamedChannel(_("Left"), 0), + NamedChannel(_("Right"), 1) + }; } diff --git a/src/lib/mid_side_decoder.h b/src/lib/mid_side_decoder.h index 8be5db67f..99821caa4 100644 --- a/src/lib/mid_side_decoder.h +++ b/src/lib/mid_side_decoder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include "audio_processor.h" + class MidSideDecoder : public AudioProcessor { public: diff --git a/src/lib/overlaps.cc b/src/lib/overlaps.cc index 09e7f63ac..536629b33 100644 --- a/src/lib/overlaps.cc +++ b/src/lib/overlaps.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,14 +18,17 @@ */ + #include "overlaps.h" #include "types.h" #include "content.h" -using std::shared_ptr; + using std::function; +using std::shared_ptr; using namespace dcpomatic; + ContentList overlaps (shared_ptr<const Film> film, ContentList cl, function<bool (shared_ptr<const Content>)> part, DCPTime from, DCPTime to) { ContentList overlaps; diff --git a/src/lib/overlaps.h b/src/lib/overlaps.h index 6c5a85a8b..bce163a57 100644 --- a/src/lib/overlaps.h +++ b/src/lib/overlaps.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,12 +18,15 @@ */ + #include "types.h" #include "dcpomatic_time.h" + class ContentPart; class Film; + /** @return Pieces of content with a given part (video, audio, * subtitle) that overlap a specified time range in the given * ContentList diff --git a/src/lib/raw_image_proxy.cc b/src/lib/raw_image_proxy.cc index 667f25b06..fed40c45e 100644 --- a/src/lib/raw_image_proxy.cc +++ b/src/lib/raw_image_proxy.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "raw_image_proxy.h" #include "image.h" #include "warnings.h" @@ -33,55 +34,63 @@ DCPOMATIC_ENABLE_WARNINGS #include "i18n.h" -using std::string; -using std::pair; + +using std::dynamic_pointer_cast; using std::make_pair; +using std::make_shared; +using std::pair; using std::shared_ptr; -using std::dynamic_pointer_cast; +using std::string; using boost::optional; using dcp::raw_convert; + RawImageProxy::RawImageProxy (shared_ptr<Image> image) : _image (image) { } + RawImageProxy::RawImageProxy (shared_ptr<cxml::Node> xml, shared_ptr<Socket> socket) { dcp::Size size ( - xml->number_child<int> ("Width"), xml->number_child<int> ("Height") + xml->number_child<int>("Width"), xml->number_child<int>("Height") ); - _image.reset (new Image (static_cast<AVPixelFormat> (xml->number_child<int> ("PixelFormat")), size, true)); + _image = make_shared<Image>(static_cast<AVPixelFormat>(xml->number_child<int>("PixelFormat")), size, true); _image->read_from_socket (socket); } + ImageProxy::Result RawImageProxy::image (optional<dcp::Size>) const { return Result (_image, 0); } + void RawImageProxy::add_metadata (xmlpp::Node* node) const { - node->add_child("Type")->add_child_text (N_("Raw")); - node->add_child("Width")->add_child_text (raw_convert<string> (_image->size().width)); - node->add_child("Height")->add_child_text (raw_convert<string> (_image->size().height)); - node->add_child("PixelFormat")->add_child_text (raw_convert<string> (static_cast<int> (_image->pixel_format ()))); + node->add_child("Type")->add_child_text(N_("Raw")); + node->add_child("Width")->add_child_text(raw_convert<string>(_image->size().width)); + node->add_child("Height")->add_child_text(raw_convert<string>(_image->size().height)); + node->add_child("PixelFormat")->add_child_text(raw_convert<string>(static_cast<int>(_image->pixel_format()))); } + void RawImageProxy::write_to_socket (shared_ptr<Socket> socket) const { _image->write_to_socket (socket); } + bool RawImageProxy::same (shared_ptr<const ImageProxy> other) const { - shared_ptr<const RawImageProxy> rp = dynamic_pointer_cast<const RawImageProxy> (other); + auto rp = dynamic_pointer_cast<const RawImageProxy> (other); if (!rp) { return false; } @@ -89,6 +98,7 @@ RawImageProxy::same (shared_ptr<const ImageProxy> other) const return (*_image.get()) == (*rp->image().image.get()); } + size_t RawImageProxy::memory_used () const { diff --git a/src/lib/raw_image_proxy.h b/src/lib/raw_image_proxy.h index 7cd9491fa..ec30f5a29 100644 --- a/src/lib/raw_image_proxy.h +++ b/src/lib/raw_image_proxy.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,11 +18,14 @@ */ + #ifndef DCPOMATIC_RAW_IMAGE_PROXY_H #define DCPOMATIC_RAW_IMAGE_PROXY_H + #include "image_proxy.h" + class RawImageProxy : public ImageProxy { public: @@ -42,4 +45,5 @@ private: std::shared_ptr<Image> _image; }; + #endif diff --git a/src/lib/rng.cc b/src/lib/rng.cc index 3fc41725d..4d82cf721 100644 --- a/src/lib/rng.cc +++ b/src/lib/rng.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/rng.h b/src/lib/rng.h index f3349ce9b..e3dc0c50d 100644 --- a/src/lib/rng.h +++ b/src/lib/rng.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2020-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. diff --git a/src/lib/scoped_temporary.cc b/src/lib/scoped_temporary.cc index ad4f882a2..223100ba5 100644 --- a/src/lib/scoped_temporary.cc +++ b/src/lib/scoped_temporary.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,19 +18,21 @@ */ + #include "scoped_temporary.h" #include "exceptions.h" #include "cross.h" + /** Construct a ScopedTemporary. A temporary filename is decided but the file is not opened * until open() is called. */ ScopedTemporary::ScopedTemporary () - : _open (0) { _file = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path (); } + /** Close and delete the temporary file */ ScopedTemporary::~ScopedTemporary () { @@ -39,13 +41,15 @@ ScopedTemporary::~ScopedTemporary () boost::filesystem::remove (_file, ec); } + /** @return temporary filename */ char const * ScopedTemporary::c_str () const { - return _file.string().c_str (); + return _file.string().c_str(); } + /** Open the temporary file. * @return File's FILE pointer. */ @@ -60,12 +64,13 @@ ScopedTemporary::open (char const * params) return _open; } + /** Close the file */ void ScopedTemporary::close () { if (_open) { fclose (_open); - _open = 0; + _open = nullptr; } } diff --git a/src/lib/scoped_temporary.h b/src/lib/scoped_temporary.h index 8f7416093..75d9a272f 100644 --- a/src/lib/scoped_temporary.h +++ b/src/lib/scoped_temporary.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -46,5 +46,5 @@ public: private: boost::filesystem::path _file; - FILE* _open; + FILE* _open = nullptr; }; diff --git a/src/lib/screen.cc b/src/lib/screen.cc index 8e1e83e36..504504c8c 100644 --- a/src/lib/screen.cc +++ b/src/lib/screen.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "screen.h" #include "kdm_with_metadata.h" #include "film.h" @@ -26,13 +27,16 @@ #include <boost/algorithm/string.hpp> #include <boost/date_time/posix_time/posix_time.hpp> -using std::string; -using std::vector; + using std::list; +using std::make_shared; using std::shared_ptr; +using std::string; +using std::vector; using boost::optional; using namespace dcpomatic; + Screen::Screen (cxml::ConstNodePtr node) : KDMRecipient (node) { @@ -45,6 +49,7 @@ Screen::Screen (cxml::ConstNodePtr node) } } + void Screen::as_xml (xmlpp::Element* parent) const { @@ -54,6 +59,7 @@ Screen::as_xml (xmlpp::Element* parent) const } } + vector<string> Screen::trusted_device_thumbprints () const { @@ -78,14 +84,14 @@ kdm_for_screen ( ) { if (!screen->recipient) { - return KDMWithMetadataPtr(); + return {}; } - shared_ptr<const Cinema> cinema = screen->cinema; + auto cinema = screen->cinema; dcp::LocalTime const begin(valid_from, cinema ? cinema->utc_offset_hour() : 0, cinema ? cinema->utc_offset_minute() : 0); dcp::LocalTime const end (valid_to, cinema ? cinema->utc_offset_hour() : 0, cinema ? cinema->utc_offset_minute() : 0); - dcp::EncryptedKDM const kdm = film->make_kdm ( + auto const kdm = film->make_kdm ( screen->recipient.get(), screen->trusted_device_thumbprints(), cpl, @@ -106,6 +112,6 @@ kdm_for_screen ( name_values['e'] = end.date() + " " + end.time_of_day(true, false); name_values['i'] = kdm.cpl_id(); - return KDMWithMetadataPtr(new KDMWithMetadata(name_values, cinema.get(), cinema ? cinema->emails : list<string>(), kdm)); + return make_shared<KDMWithMetadata>(name_values, cinema.get(), cinema ? cinema->emails : list<string>(), kdm); } diff --git a/src/lib/screen.h b/src/lib/screen.h index 96b0ce764..15a0785d5 100644 --- a/src/lib/screen.h +++ b/src/lib/screen.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #ifndef DCPOMATIC_SCREEN_H #define DCPOMATIC_SCREEN_H + #include "kdm_with_metadata.h" #include "kdm_recipient.h" #include "trusted_device.h" @@ -29,11 +31,14 @@ #include <boost/optional.hpp> #include <string> + class Cinema; class Film; + namespace dcpomatic { + /** @class Screen * @brief A representation of a Screen for KDM generation. * @@ -60,6 +65,7 @@ public: } + KDMWithMetadataPtr kdm_for_screen ( std::shared_ptr<const Film> film, diff --git a/src/lib/send_notification_email_job.cc b/src/lib/send_notification_email_job.cc index e5edc49ee..c4d5a6518 100644 --- a/src/lib/send_notification_email_job.cc +++ b/src/lib/send_notification_email_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "send_notification_email_job.h" #include "exceptions.h" #include "config.h" @@ -27,10 +28,12 @@ #include "i18n.h" + using std::string; using std::list; using std::shared_ptr; + /** @param body Email body */ SendNotificationEmailJob::SendNotificationEmailJob (string body) : Job (shared_ptr<Film>()) @@ -39,27 +42,31 @@ SendNotificationEmailJob::SendNotificationEmailJob (string body) } + SendNotificationEmailJob::~SendNotificationEmailJob () { stop_thread (); } + string SendNotificationEmailJob::name () const { return _("Email notification"); } + string SendNotificationEmailJob::json_name () const { return N_("send_notification_email"); } + void SendNotificationEmailJob::run () { - Config* config = Config::instance (); + auto config = Config::instance (); if (config->mail_server().empty()) { throw NetworkError (_("No mail server configured in preferences")); @@ -67,13 +74,13 @@ SendNotificationEmailJob::run () set_progress_unknown (); list<string> to; - to.push_back (config->notification_to ()); + to.push_back (config->notification_to()); Emailer email (config->notification_from(), to, config->notification_subject(), _body); for (auto i: config->notification_cc()) { email.add_cc (i); } if (!config->notification_bcc().empty()) { - email.add_bcc (config->notification_bcc ()); + email.add_bcc (config->notification_bcc()); } email.send (config->mail_server(), config->mail_port(), config->mail_protocol(), config->mail_user(), config->mail_password()); diff --git a/src/lib/send_notification_email_job.h b/src/lib/send_notification_email_job.h index 5c116f2ee..7c1c3e215 100644 --- a/src/lib/send_notification_email_job.h +++ b/src/lib/send_notification_email_job.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,17 +18,19 @@ */ + #include "job.h" + class SendNotificationEmailJob : public Job { public: explicit SendNotificationEmailJob (std::string body); ~SendNotificationEmailJob (); - std::string name () const; - std::string json_name () const; - void run (); + std::string name () const override; + std::string json_name () const override; + void run () override; private: std::string _body; diff --git a/src/lib/send_problem_report_job.cc b/src/lib/send_problem_report_job.cc index 7f60a3fdc..e7fc02eb0 100644 --- a/src/lib/send_problem_report_job.cc +++ b/src/lib/send_problem_report_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2017 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,6 +18,7 @@ */ + #include "send_problem_report_job.h" #include "compose.hpp" #include "film.h" @@ -31,9 +32,11 @@ #include "i18n.h" -using std::string; + using std::list; using std::shared_ptr; +using std::string; + /** @param film Film thta the problem is with, or 0. * @param from Email address to use for From: @@ -51,11 +54,13 @@ SendProblemReportJob::SendProblemReportJob ( } + SendProblemReportJob::~SendProblemReportJob () { stop_thread (); } + string SendProblemReportJob::name () const { @@ -66,12 +71,14 @@ SendProblemReportJob::name () const return String::compose (_("Email problem report for %1"), _film->name()); } + string SendProblemReportJob::json_name () const { return N_("send_problem_report"); } + void SendProblemReportJob::run () { @@ -108,17 +115,18 @@ SendProblemReportJob::run () set_state (FINISHED_OK); } + void SendProblemReportJob::add_file (string& body, boost::filesystem::path file) const { - FILE* f = fopen_boost (_film->file (file), "r"); + auto f = fopen_boost (_film->file(file), "r"); if (!f) { return; } body += file.string() + ":\n"; body += "---<8----\n"; - uintmax_t const size = boost::filesystem::file_size (_film->file (file)); + auto const size = boost::filesystem::file_size (_film->file(file)); char* buffer = new char[size + 1]; int const N = fread (buffer, 1, size, f); buffer[N] = '\0'; diff --git a/src/lib/send_problem_report_job.h b/src/lib/send_problem_report_job.h index 4e66cb58b..5310010ae 100644 --- a/src/lib/send_problem_report_job.h +++ b/src/lib/send_problem_report_job.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2014-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,10 +18,12 @@ */ + #include "job.h" #include <dcp/types.h> #include <boost/filesystem.hpp> + class SendProblemReportJob : public Job { public: @@ -33,9 +35,9 @@ public: ~SendProblemReportJob (); - std::string name () const; - std::string json_name () const; - void run (); + std::string name () const override; + std::string json_name () const override; + void run () override; private: void add_file (std::string& body, boost::filesystem::path file) const; diff --git a/src/lib/spl_entry.cc b/src/lib/spl_entry.cc index 440f9861b..878bd610f 100644 --- a/src/lib/spl_entry.cc +++ b/src/lib/spl_entry.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,28 +18,25 @@ */ -#include "spl_entry.h" + #include "dcp_content.h" #include "dcpomatic_assert.h" +#include "spl_entry.h" #include "warnings.h" DCPOMATIC_DISABLE_WARNINGS #include <libxml++/libxml++.h> DCPOMATIC_ENABLE_WARNINGS + using std::shared_ptr; using std::dynamic_pointer_cast; -SPLEntry::SPLEntry (shared_ptr<Content> content) -{ - construct (content); -} -void -SPLEntry::construct (shared_ptr<Content> c) +SPLEntry::SPLEntry (shared_ptr<Content> c) + : content (c) + , digest (content->digest()) { - content = c; - shared_ptr<DCPContent> dcp = dynamic_pointer_cast<DCPContent> (content); - digest = content->digest (); + auto dcp = dynamic_pointer_cast<DCPContent> (content); if (dcp) { name = dcp->name (); DCPOMATIC_ASSERT (dcp->cpl()); @@ -52,6 +49,7 @@ SPLEntry::construct (shared_ptr<Content> c) } } + void SPLEntry::as_xml (xmlpp::Element* e) { diff --git a/src/lib/spl_entry.h b/src/lib/spl_entry.h index 2650371c4..b2977c8aa 100644 --- a/src/lib/spl_entry.h +++ b/src/lib/spl_entry.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2018-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,22 +18,26 @@ */ + #ifndef DCPOMATIC_SPL_ENTRY_H #define DCPOMATIC_SPL_ENTRY_H + #include <libcxml/cxml.h> #include <dcp/types.h> + namespace xmlpp { class Element; } class Content; + class SPLEntry { public: - SPLEntry (std::shared_ptr<Content> content); + SPLEntry (std::shared_ptr<Content> c); void as_xml (xmlpp::Element* e); @@ -50,4 +54,5 @@ private: void construct (std::shared_ptr<Content> content); }; + #endif diff --git a/src/lib/stdout_log.cc b/src/lib/stdout_log.cc index f4942a7b4..50278906f 100644 --- a/src/lib/stdout_log.cc +++ b/src/lib/stdout_log.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,24 +18,29 @@ */ + #include "stdout_log.h" #include "config.h" #include <iostream> + using std::cout; using std::string; using std::shared_ptr; + StdoutLog::StdoutLog () { set_types (Config::instance()->log_types()); } + StdoutLog::StdoutLog (int types) { set_types (types); } + void StdoutLog::do_log (shared_ptr<const LogEntry> entry) { diff --git a/src/lib/stdout_log.h b/src/lib/stdout_log.h index f4335e8e5..0dcc243db 100644 --- a/src/lib/stdout_log.h +++ b/src/lib/stdout_log.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include "log.h" + class StdoutLog : public Log { public: diff --git a/src/lib/string_log_entry.cc b/src/lib/string_log_entry.cc index 3ee9b5c4c..3022b4e5b 100644 --- a/src/lib/string_log_entry.cc +++ b/src/lib/string_log_entry.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,12 +18,15 @@ */ + #include "string_log_entry.h" #include "i18n.h" + using std::string; + StringLogEntry::StringLogEntry (int type, string message) : LogEntry (type) , _message (message) diff --git a/src/lib/string_log_entry.h b/src/lib/string_log_entry.h index e3df5fd54..143ada024 100644 --- a/src/lib/string_log_entry.h +++ b/src/lib/string_log_entry.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2015 Carl Hetherington <cth@carlh.net> + Copyright (C) 2015-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,9 +18,11 @@ */ + #include "log_entry.h" #include <string> + class StringLogEntry : public LogEntry { public: diff --git a/src/lib/subtitle_encoder.cc b/src/lib/subtitle_encoder.cc index 66957270f..ba47e1231 100644 --- a/src/lib/subtitle_encoder.cc +++ b/src/lib/subtitle_encoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2019-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,11 +18,12 @@ */ -#include "font_data.h" -#include "subtitle_encoder.h" -#include "player.h" + #include "compose.hpp" +#include "font_data.h" #include "job.h" +#include "player.h" +#include "subtitle_encoder.h" #include <dcp/interop_subtitle_asset.h> #include <dcp/raw_convert.h> #include <dcp/smpte_subtitle_asset.h> @@ -31,6 +32,7 @@ #include "i18n.h" + using std::make_pair; using std::make_shared; using std::pair; @@ -43,6 +45,7 @@ using namespace boost::placeholders; #endif using dcp::raw_convert; + /** @param output Directory, if there will be multiple output files, or a filename. * @param initial_name Hint that may be used to create filenames, if @ref output is a directory. * @param include_font true to refer to and export any font file (for Interop; ignored for SMPTE). @@ -85,6 +88,7 @@ SubtitleEncoder::SubtitleEncoder (shared_ptr<const Film> film, shared_ptr<Job> j _default_font = dcp::ArrayData (default_font_file()); } + void SubtitleEncoder::go () { @@ -99,33 +103,34 @@ SubtitleEncoder::go () while (!_player->pass()) {} int reel = 0; - for (vector<pair<shared_ptr<dcp::SubtitleAsset>, boost::filesystem::path> >::iterator i = _assets.begin(); i != _assets.end(); ++i) { - if (!i->first) { + for (auto& i: _assets) { + if (!i.first) { /* No subtitles arrived for this asset; make an empty one so we write something to the output */ if (_film->interop()) { - shared_ptr<dcp::InteropSubtitleAsset> s (new dcp::InteropSubtitleAsset()); + auto s = make_shared<dcp::InteropSubtitleAsset>(); s->set_movie_title (_film->name()); s->set_reel_number (raw_convert<string>(reel + 1)); - i->first = s; + i.first = s; } else { - shared_ptr<dcp::SMPTESubtitleAsset> s (new dcp::SMPTESubtitleAsset()); + auto s = make_shared<dcp::SMPTESubtitleAsset>(); s->set_content_title_text (_film->name()); s->set_reel_number (reel + 1); - i->first = s; + i.first = s; } } if (!_film->interop() || _include_font) { for (auto j: _player->get_subtitle_fonts()) { - i->first->add_font (j.id, _default_font); + i.first->add_font (j.id, _default_font); } } - i->first->write (i->second); + i.first->write (i.second); ++reel; } } + void SubtitleEncoder::text (PlayerText subs, TextType type, optional<DCPTextTrack> track, dcpomatic::DCPTimePeriod period) { @@ -170,7 +175,7 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional<DCPTextTrack> tr if (_film->interop() && !_include_font) { i.unset_font (); } - _assets[_reel_index].first->add (shared_ptr<dcp::Subtitle>(new dcp::SubtitleString(i))); + _assets[_reel_index].first->add (make_shared<dcp::SubtitleString>(i)); } if (_split_reels && (_reel_index < int(_reels.size()) - 1) && period.from > _reels[_reel_index].from) { @@ -179,12 +184,13 @@ SubtitleEncoder::text (PlayerText subs, TextType type, optional<DCPTextTrack> tr _last = period.from; - shared_ptr<Job> job = _job.lock (); + auto job = _job.lock (); if (job) { job->set_progress (float(period.from.get()) / _length.get()); } } + Frame SubtitleEncoder::frames_done () const { diff --git a/src/lib/subtitle_encoder.h b/src/lib/subtitle_encoder.h index 165d5fcb6..a88c6c5bf 100644 --- a/src/lib/subtitle_encoder.h +++ b/src/lib/subtitle_encoder.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,18 +18,22 @@ */ + #include "types.h" #include "player_text.h" #include "dcp_text_track.h" #include "encoder.h" #include "dcpomatic_time.h" + namespace dcp { class SubtitleAsset; } + class Film; + /** @class SubtitleEncoder. * @brief An `encoder' which extracts a film's subtitles to DCP XML format. */ @@ -38,7 +42,7 @@ class SubtitleEncoder : public Encoder public: SubtitleEncoder (std::shared_ptr<const Film> film, std::shared_ptr<Job> job, boost::filesystem::path output, std::string intial_name, bool split_reels, bool include_font); - void go (); + void go () override; /** @return the number of frames that are done */ Frame frames_done () const; diff --git a/src/lib/transcode_job.cc b/src/lib/transcode_job.cc index 48a2c8114..3502c3346 100644 --- a/src/lib/transcode_job.cc +++ b/src/lib/transcode_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,34 +18,39 @@ */ + /** @file src/transcode_job.cc * @brief A job which transcodes from one format to another. */ + +#include "analytics.h" +#include "compose.hpp" #include "config.h" -#include "transcode_job.h" #include "dcp_encoder.h" -#include "upload_job.h" -#include "job_manager.h" -#include "film.h" +#include "dcpomatic_log.h" #include "encoder.h" +#include "film.h" +#include "job_manager.h" #include "log.h" -#include "dcpomatic_log.h" -#include "compose.hpp" -#include "analytics.h" -#include <iostream> +#include "transcode_job.h" +#include "upload_job.h" #include <iomanip> +#include <iostream> #include "i18n.h" -using std::string; + +using std::cout; using std::fixed; +using std::make_shared; using std::setprecision; -using std::cout; using std::shared_ptr; +using std::string; using boost::optional; using std::dynamic_pointer_cast; + /** @param film Film to use */ TranscodeJob::TranscodeJob (shared_ptr<const Film> film) : Job (film) @@ -53,29 +58,34 @@ TranscodeJob::TranscodeJob (shared_ptr<const Film> film) } + TranscodeJob::~TranscodeJob () { stop_thread (); } + string TranscodeJob::name () const { return String::compose (_("Transcoding %1"), _film->name()); } + string TranscodeJob::json_name () const { return N_("transcode"); } + void TranscodeJob::set_encoder (shared_ptr<Encoder> e) { _encoder = e; } + void TranscodeJob::run () { @@ -103,8 +113,7 @@ TranscodeJob::run () /* XXX: this shouldn't be here */ if (Config::instance()->upload_after_make_dcp() && dynamic_pointer_cast<DCPEncoder>(_encoder)) { - shared_ptr<Job> job (new UploadJob (_film)); - JobManager::instance()->add (job); + JobManager::instance()->add(make_shared<UploadJob>(_film)); } _encoder.reset (); @@ -118,6 +127,7 @@ TranscodeJob::run () } } + string TranscodeJob::status () const { @@ -150,12 +160,13 @@ TranscodeJob::status () const return buffer; } + /** @return Approximate remaining time in seconds */ int TranscodeJob::remaining_time () const { /* _encoder might be destroyed by the job-runner thread */ - shared_ptr<Encoder> e = _encoder; + auto e = _encoder; if (!e || e->finishing()) { /* We aren't doing any actual encoding so just use the job's guess */ @@ -164,7 +175,7 @@ TranscodeJob::remaining_time () const /* We're encoding so guess based on the current encoding rate */ - optional<float> fps = e->current_rate (); + auto fps = e->current_rate (); if (!fps) { return 0; diff --git a/src/lib/transcode_job.h b/src/lib/transcode_job.h index 88f41d655..030e22bef 100644 --- a/src/lib/transcode_job.h +++ b/src/lib/transcode_job.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2012-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,14 +18,18 @@ */ + /** @file src/transcode_job.h * @brief A job which transcodes from one format to another. */ + #include "job.h" + class Encoder; + /** @class TranscodeJob * @brief A job which transcodes a Film to another format. */ @@ -35,15 +39,15 @@ public: explicit TranscodeJob (std::shared_ptr<const Film> film); ~TranscodeJob (); - std::string name () const; - std::string json_name () const; - void run (); - std::string status () const; + std::string name () const override; + std::string json_name () const override; + void run () override; + std::string status () const override; void set_encoder (std::shared_ptr<Encoder> t); private: - int remaining_time () const; + int remaining_time () const override; std::shared_ptr<Encoder> _encoder; }; diff --git a/src/lib/trusted_device.cc b/src/lib/trusted_device.cc index 5849b8fd2..8bfbc34f0 100644 --- a/src/lib/trusted_device.cc +++ b/src/lib/trusted_device.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,22 +18,27 @@ */ + #include "trusted_device.h" + using std::string; + TrustedDevice::TrustedDevice (string thumbprint) : _thumbprint (thumbprint) { } + TrustedDevice::TrustedDevice (dcp::Certificate certificate) : _certificate (certificate) { } + string TrustedDevice::as_string () const { @@ -44,6 +49,7 @@ TrustedDevice::as_string () const return *_thumbprint; } + string TrustedDevice::thumbprint () const { diff --git a/src/lib/trusted_device.h b/src/lib/trusted_device.h index 7c6af3ea8..51b97c297 100644 --- a/src/lib/trusted_device.h +++ b/src/lib/trusted_device.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2013-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,13 +18,16 @@ */ + #ifndef DCPOMATIC_TRUSTED_DEVICE_H #define DCPOMATIC_TRUSTED_DEVICE_H + #include <dcp/certificate.h> #include <boost/optional.hpp> #include <string> + class TrustedDevice { public: @@ -43,4 +46,5 @@ private: boost::optional<std::string> _thumbprint; }; + #endif diff --git a/src/lib/verify_dcp_job.cc b/src/lib/verify_dcp_job.cc index bd5634669..1b30b2112 100644 --- a/src/lib/verify_dcp_job.cc +++ b/src/lib/verify_dcp_job.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2018-2019 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,12 +18,14 @@ */ + #include "cross.h" #include "verify_dcp_job.h" #include "content.h" #include "i18n.h" + using std::string; using std::vector; using std::shared_ptr; @@ -32,6 +34,7 @@ using boost::optional; using namespace boost::placeholders; #endif + VerifyDCPJob::VerifyDCPJob (vector<boost::filesystem::path> directories) : Job (shared_ptr<Film>()) , _directories (directories) @@ -39,23 +42,27 @@ VerifyDCPJob::VerifyDCPJob (vector<boost::filesystem::path> directories) } + VerifyDCPJob::~VerifyDCPJob () { stop_thread (); } + string VerifyDCPJob::name () const { return _("Verify DCP"); } + string VerifyDCPJob::json_name () const { return N_("verify_dcp"); } + void VerifyDCPJob::update_stage (string s, optional<boost::filesystem::path> path) { @@ -65,6 +72,7 @@ VerifyDCPJob::update_stage (string s, optional<boost::filesystem::path> path) sub (s); } + void VerifyDCPJob::run () { diff --git a/src/lib/verify_dcp_job.h b/src/lib/verify_dcp_job.h index 3372cd602..b00f0128b 100644 --- a/src/lib/verify_dcp_job.h +++ b/src/lib/verify_dcp_job.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2018 Carl Hetherington <cth@carlh.net> + Copyright (C) 2018-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,20 +18,23 @@ */ + #include "job.h" #include <dcp/verify.h> + class Content; + class VerifyDCPJob : public Job { public: explicit VerifyDCPJob (std::vector<boost::filesystem::path> directories); ~VerifyDCPJob (); - std::string name () const; - std::string json_name () const; - void run (); + std::string name () const override; + std::string json_name () const override; + void run () override; std::vector<dcp::VerificationNote> notes () const { return _notes; diff --git a/src/lib/video_mxf_content.cc b/src/lib/video_mxf_content.cc index a8a301f22..c7ee69d89 100644 --- a/src/lib/video_mxf_content.cc +++ b/src/lib/video_mxf_content.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 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 "video_mxf_examiner.h" #include "video_mxf_content.h" #include "video_content.h" @@ -32,30 +33,35 @@ #include "i18n.h" + using std::list; using std::string; using std::shared_ptr; +using std::make_shared; using namespace dcpomatic; + VideoMXFContent::VideoMXFContent (boost::filesystem::path path) : Content (path) { } + VideoMXFContent::VideoMXFContent (cxml::ConstNodePtr node, int version) : Content (node) { video = VideoContent::from_xml (this, node, version); } + bool VideoMXFContent::valid_mxf (boost::filesystem::path path) { Kumu::DefaultLogSink().UnsetFilterFlag(Kumu::LOG_ALLOW_ALL); try { - shared_ptr<dcp::MonoPictureAsset> mp (new dcp::MonoPictureAsset (path)); + dcp::MonoPictureAsset mp (path); return true; } catch (dcp::MXFFileError& e) { @@ -65,7 +71,7 @@ VideoMXFContent::valid_mxf (boost::filesystem::path path) try { Kumu::DefaultLogSink().SetFilterFlag(0); - shared_ptr<dcp::StereoPictureAsset> sp (new dcp::StereoPictureAsset (path)); + dcp::StereoPictureAsset sp (path); return true; } catch (dcp::MXFFileError& e) { @@ -78,6 +84,7 @@ VideoMXFContent::valid_mxf (boost::filesystem::path path) return false; } + void VideoMXFContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) { @@ -86,50 +93,57 @@ VideoMXFContent::examine (shared_ptr<const Film> film, shared_ptr<Job> job) Content::examine (film, job); video.reset (new VideoContent (this)); - shared_ptr<VideoMXFExaminer> examiner (new VideoMXFExaminer (shared_from_this ())); + auto examiner = make_shared<VideoMXFExaminer>(shared_from_this()); video->take_from_examiner (examiner); video->unset_colour_conversion (); } + string VideoMXFContent::summary () const { return String::compose (_("%1 [video]"), path_summary()); } + string VideoMXFContent::technical_summary () const { - return Content::technical_summary() + " - " + video->technical_summary (); + return Content::technical_summary() + " - " + video->technical_summary(); } + string VideoMXFContent::identifier () const { return Content::identifier() + "_" + video->identifier(); } + void VideoMXFContent::as_xml (xmlpp::Node* node, bool with_paths) const { - node->add_child("Type")->add_child_text ("VideoMXF"); + node->add_child("Type")->add_child_text("VideoMXF"); Content::as_xml (node, with_paths); video->as_xml (node); } + DCPTime VideoMXFContent::full_length (shared_ptr<const Film> film) const { FrameRateChange const frc (film, shared_from_this()); - return DCPTime::from_frames (llrint (video->length_after_3d_combine() * frc.factor()), film->video_frame_rate()); + return DCPTime::from_frames (llrint(video->length_after_3d_combine() * frc.factor()), film->video_frame_rate()); } + DCPTime VideoMXFContent::approximate_length () const { return DCPTime::from_frames (video->length_after_3d_combine(), 24); } + void VideoMXFContent::add_properties (shared_ptr<const Film> film, list<UserProperty>& p) const { diff --git a/src/lib/video_mxf_content.h b/src/lib/video_mxf_content.h index 6ec2c0e84..5a04c3da9 100644 --- a/src/lib/video_mxf_content.h +++ b/src/lib/video_mxf_content.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2016 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. @@ -18,8 +18,10 @@ */ + #include "content.h" + class VideoMXFContent : public Content { public: @@ -27,21 +29,21 @@ public: VideoMXFContent (cxml::ConstNodePtr node, int version); std::shared_ptr<VideoMXFContent> shared_from_this () { - return std::dynamic_pointer_cast<VideoMXFContent> (Content::shared_from_this ()); + return std::dynamic_pointer_cast<VideoMXFContent>(Content::shared_from_this()); } std::shared_ptr<const VideoMXFContent> shared_from_this () const { - return std::dynamic_pointer_cast<const VideoMXFContent> (Content::shared_from_this ()); + return std::dynamic_pointer_cast<const VideoMXFContent>(Content::shared_from_this()); } - void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job> job); - std::string summary () const; - std::string technical_summary () const; - std::string identifier () const; - void as_xml (xmlpp::Node* node, bool with_paths) const; - dcpomatic::DCPTime full_length (std::shared_ptr<const Film> film) const; - dcpomatic::DCPTime approximate_length () const; - void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty>& p) const; + void examine (std::shared_ptr<const Film> film, std::shared_ptr<Job> job) override; + std::string summary () const override; + std::string technical_summary () const override; + std::string identifier () const override; + void as_xml (xmlpp::Node* node, bool with_paths) const override; + dcpomatic::DCPTime full_length (std::shared_ptr<const Film> film) const override; + dcpomatic::DCPTime approximate_length () const override; + void add_properties (std::shared_ptr<const Film> film, std::list<UserProperty>& p) const override; static bool valid_mxf (boost::filesystem::path path); }; diff --git a/src/lib/video_mxf_decoder.cc b/src/lib/video_mxf_decoder.cc index d3fe2b897..39c4a37fb 100644 --- a/src/lib/video_mxf_decoder.cc +++ b/src/lib/video_mxf_decoder.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2016-2017 Carl Hetherington <cth@carlh.net> + Copyright (C) 2016-2021 Carl Hetherington <cth@carlh.net> This file is part of DCP-o-matic. |
